@devtable/dashboard 10.34.7 → 10.35.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/components/panel/panel-render/full-screen-render/use-panel-full-screen.d.ts +8 -0
- package/dist/components/plugins/plugin-context.d.ts +8 -0
- package/dist/contexts/panel-context.d.ts +16 -0
- package/dist/dashboard-editor/model/panels/panel.d.ts +4 -0
- package/dist/dashboard-editor/model/panels/panels.d.ts +32 -0
- package/dist/dashboard-editor/model/queries/index.d.ts +14 -0
- package/dist/dashboard.es.js +2836 -2812
- package/dist/dashboard.umd.js +66 -66
- package/dist/model/meta-model/dashboard/content/types.d.ts +4 -0
- package/dist/model/render-model/dashboard/content/panels/panel.d.ts +4 -0
- package/dist/model/render-model/dashboard/content/panels/panels.d.ts +28 -0
- package/dist/model/render-model/dashboard/content/queries/queries.d.ts +10 -0
- package/dist/model/render-model/dashboard/content/queries/query.d.ts +2 -0
- package/dist/stats.html +1 -1
- package/dist/utils/dashboard-state.d.ts +2 -0
- package/dist/utils/http-query.d.ts +2 -2
- package/dist/utils/sql.d.ts +2 -2
- package/package.json +1 -1
package/dist/dashboard.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(I,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("react"),require("@mantine/core"),require("@mantine/modals"),require("ahooks"),require("mobx"),require("mobx-react-lite"),require("crypto-js"),require("dayjs"),require("lodash"),require("numbro"),require("d3-array"),require("mathjs"),require("@faker-js/faker"),require("axios"),require("eventemitter2"),require("chroma-js"),require("echarts-for-react/lib/core"),require("echarts-gl"),require("echarts/components"),require("echarts/core"),require("echarts/renderers"),require("react-hook-form"),require("tabler-icons-react"),require("echarts/charts"),require("@tabler/icons-react"),require("@mantine/hooks"),require("@mantine/notifications"),require("@mantine/tiptap"),require("@tiptap/extension-color"),require("@tiptap/extension-highlight"),require("@tiptap/extension-placeholder"),require("@tiptap/extension-subscript"),require("@tiptap/extension-superscript"),require("@tiptap/extension-text-align"),require("@tiptap/extension-text-style"),require("@tiptap/extension-table"),require("@tiptap/extension-table-cell"),require("@tiptap/extension-table-header"),require("@tiptap/extension-table-row"),require("@tiptap/extension-underline"),require("@tiptap/react"),require("@tiptap/starter-kit"),require("prosemirror-keymap"),require("prosemirror-commands"),require("prosemirror-schema-list"),require("@monaco-editor/react"),require("popmotion"),require("d3-regression"),require("@mantine/prism"),require("@tanstack/react-table"),require("react-virtual"),require("@mantine/dates"),require("rc-select"),require("rc-tree-select"),require("react-grid-layout"),require("mobx-state-tree"),require("performant-array-to-tree"),require("@json2csv/whatwg"),require("file-saver"),require("jszip"),require("dom-to-image-more"),require("react-router-dom"),require("reactflow")):typeof define=="function"&&define.amd?define(["exports","react","@mantine/core","@mantine/modals","ahooks","mobx","mobx-react-lite","crypto-js","dayjs","lodash","numbro","d3-array","mathjs","@faker-js/faker","axios","eventemitter2","chroma-js","echarts-for-react/lib/core","echarts-gl","echarts/components","echarts/core","echarts/renderers","react-hook-form","tabler-icons-react","echarts/charts","@tabler/icons-react","@mantine/hooks","@mantine/notifications","@mantine/tiptap","@tiptap/extension-color","@tiptap/extension-highlight","@tiptap/extension-placeholder","@tiptap/extension-subscript","@tiptap/extension-superscript","@tiptap/extension-text-align","@tiptap/extension-text-style","@tiptap/extension-table","@tiptap/extension-table-cell","@tiptap/extension-table-header","@tiptap/extension-table-row","@tiptap/extension-underline","@tiptap/react","@tiptap/starter-kit","prosemirror-keymap","prosemirror-commands","prosemirror-schema-list","@monaco-editor/react","popmotion","d3-regression","@mantine/prism","@tanstack/react-table","react-virtual","@mantine/dates","rc-select","rc-tree-select","react-grid-layout","mobx-state-tree","performant-array-to-tree","@json2csv/whatwg","file-saver","jszip","dom-to-image-more","react-router-dom","reactflow"],y):(I=typeof globalThis<"u"?globalThis:I||self,y(I.dashboard={},I.react,I["@mantine/core"],I["@mantine/modals"],I.ahooks,I.mobx,I["mobx-react-lite"],I.CryptoJS,I.dayjs,I._,I.numbro,I["d3-array"],I.mathjs,I["@faker-js/faker"],I.axios,I.eventemitter2,I["chroma-js"],I["echarts-for-react/lib/core"],I["echarts-gl"],I["echarts/components"],I["echarts/core"],I["echarts/renderers"],I["react-hook-form"],I["tabler-icons-react"],I["echarts/charts"],I["@tabler/icons-react"],I["@mantine/hooks"],I["@mantine/notifications"],I["@mantine/tiptap"],I["@tiptap/extension-color"],I["@tiptap/extension-highlight"],I["@tiptap/extension-placeholder"],I["@tiptap/extension-subscript"],I["@tiptap/extension-superscript"],I["@tiptap/extension-text-align"],I["@tiptap/extension-text-style"],I["@tiptap/extension-table"],I["@tiptap/extension-table-cell"],I["@tiptap/extension-table-header"],I["@tiptap/extension-table-row"],I["@tiptap/extension-underline"],I["@tiptap/react"],I["@tiptap/starter-kit"],I["prosemirror-keymap"],I["prosemirror-commands"],I["prosemirror-schema-list"],I["@monaco-editor/react"],I.popmotion,I["d3-regression"],I["@mantine/prism"],I["@tanstack/react-table"],I["react-virtual"],I["@mantine/dates"],I["rc-select"],I["rc-tree-select"],I["react-grid-layout"],I["mobx-state-tree"],I["performant-array-to-tree"],I["@json2csv/whatwg"],I["file-saver"],I.jszip,I["dom-to-image-more"],I["react-router-dom"],I.reactflow))})(this,function(I,y,s,Ge,Q,te,k,$a,U,x,Z,en,
|
|
1
|
+
(function(I,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("react"),require("@mantine/core"),require("@mantine/modals"),require("ahooks"),require("mobx"),require("mobx-react-lite"),require("crypto-js"),require("dayjs"),require("lodash"),require("numbro"),require("d3-array"),require("mathjs"),require("@faker-js/faker"),require("axios"),require("eventemitter2"),require("chroma-js"),require("echarts-for-react/lib/core"),require("echarts-gl"),require("echarts/components"),require("echarts/core"),require("echarts/renderers"),require("react-hook-form"),require("tabler-icons-react"),require("echarts/charts"),require("@tabler/icons-react"),require("@mantine/hooks"),require("@mantine/notifications"),require("@mantine/tiptap"),require("@tiptap/extension-color"),require("@tiptap/extension-highlight"),require("@tiptap/extension-placeholder"),require("@tiptap/extension-subscript"),require("@tiptap/extension-superscript"),require("@tiptap/extension-text-align"),require("@tiptap/extension-text-style"),require("@tiptap/extension-table"),require("@tiptap/extension-table-cell"),require("@tiptap/extension-table-header"),require("@tiptap/extension-table-row"),require("@tiptap/extension-underline"),require("@tiptap/react"),require("@tiptap/starter-kit"),require("prosemirror-keymap"),require("prosemirror-commands"),require("prosemirror-schema-list"),require("@monaco-editor/react"),require("popmotion"),require("d3-regression"),require("@mantine/prism"),require("@tanstack/react-table"),require("react-virtual"),require("@mantine/dates"),require("rc-select"),require("rc-tree-select"),require("react-grid-layout"),require("mobx-state-tree"),require("performant-array-to-tree"),require("@json2csv/whatwg"),require("file-saver"),require("jszip"),require("dom-to-image-more"),require("react-router-dom"),require("reactflow")):typeof define=="function"&&define.amd?define(["exports","react","@mantine/core","@mantine/modals","ahooks","mobx","mobx-react-lite","crypto-js","dayjs","lodash","numbro","d3-array","mathjs","@faker-js/faker","axios","eventemitter2","chroma-js","echarts-for-react/lib/core","echarts-gl","echarts/components","echarts/core","echarts/renderers","react-hook-form","tabler-icons-react","echarts/charts","@tabler/icons-react","@mantine/hooks","@mantine/notifications","@mantine/tiptap","@tiptap/extension-color","@tiptap/extension-highlight","@tiptap/extension-placeholder","@tiptap/extension-subscript","@tiptap/extension-superscript","@tiptap/extension-text-align","@tiptap/extension-text-style","@tiptap/extension-table","@tiptap/extension-table-cell","@tiptap/extension-table-header","@tiptap/extension-table-row","@tiptap/extension-underline","@tiptap/react","@tiptap/starter-kit","prosemirror-keymap","prosemirror-commands","prosemirror-schema-list","@monaco-editor/react","popmotion","d3-regression","@mantine/prism","@tanstack/react-table","react-virtual","@mantine/dates","rc-select","rc-tree-select","react-grid-layout","mobx-state-tree","performant-array-to-tree","@json2csv/whatwg","file-saver","jszip","dom-to-image-more","react-router-dom","reactflow"],y):(I=typeof globalThis<"u"?globalThis:I||self,y(I.dashboard={},I.react,I["@mantine/core"],I["@mantine/modals"],I.ahooks,I.mobx,I["mobx-react-lite"],I.CryptoJS,I.dayjs,I._,I.numbro,I["d3-array"],I.mathjs,I["@faker-js/faker"],I.axios,I.eventemitter2,I["chroma-js"],I["echarts-for-react/lib/core"],I["echarts-gl"],I["echarts/components"],I["echarts/core"],I["echarts/renderers"],I["react-hook-form"],I["tabler-icons-react"],I["echarts/charts"],I["@tabler/icons-react"],I["@mantine/hooks"],I["@mantine/notifications"],I["@mantine/tiptap"],I["@tiptap/extension-color"],I["@tiptap/extension-highlight"],I["@tiptap/extension-placeholder"],I["@tiptap/extension-subscript"],I["@tiptap/extension-superscript"],I["@tiptap/extension-text-align"],I["@tiptap/extension-text-style"],I["@tiptap/extension-table"],I["@tiptap/extension-table-cell"],I["@tiptap/extension-table-header"],I["@tiptap/extension-table-row"],I["@tiptap/extension-underline"],I["@tiptap/react"],I["@tiptap/starter-kit"],I["prosemirror-keymap"],I["prosemirror-commands"],I["prosemirror-schema-list"],I["@monaco-editor/react"],I.popmotion,I["d3-regression"],I["@mantine/prism"],I["@tanstack/react-table"],I["react-virtual"],I["@mantine/dates"],I["rc-select"],I["rc-tree-select"],I["react-grid-layout"],I["mobx-state-tree"],I["performant-array-to-tree"],I["@json2csv/whatwg"],I["file-saver"],I.jszip,I["dom-to-image-more"],I["react-router-dom"],I.reactflow))})(this,function(I,y,s,Ge,Q,te,k,$a,U,x,Z,en,Eu,$u,xt,La,pt,ze,rM,F,Lu,Ee,v,D,he,E,ke,_n,J,Oa,Pa,Ba,Va,Na,qa,Fa,Ga,Wa,ja,Ra,Ya,Qa,Ua,iM,Te,yr,De,It,Ou,Mt,et,Pu,Bu,Ka,Xa,kn,b,Vu,Nu,br,qu,Ja,Fu,Me){"use strict";var tM=Object.defineProperty;var nM=(I,y,s)=>y in I?tM(I,y,{enumerable:!0,configurable:!0,writable:!0,value:s}):I[y]=s;var q=(I,y,s)=>(nM(I,typeof y!="symbol"?y+"":y,s),s);function Tn(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const Gu=Tn(en),Dn=Tn(Eu),ie=Tn(Lu),wt=Tn(Ou);var re=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},tn={},Wu={get exports(){return tn},set exports(e){tn=e}},nn={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var Za;function
|
|
9
|
+
*/var Za;function ju(){if(Za)return nn;Za=1;var e=y,t=Symbol.for("react.element"),n=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,a=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function l(u,c,d){var f,h={},g=null,m=null;d!==void 0&&(g=""+d),c.key!==void 0&&(g=""+c.key),c.ref!==void 0&&(m=c.ref);for(f in c)r.call(c,f)&&!o.hasOwnProperty(f)&&(h[f]=c[f]);if(u&&u.defaultProps)for(f in c=u.defaultProps,c)h[f]===void 0&&(h[f]=c[f]);return{$$typeof:t,type:u,key:g,ref:m,props:h,_owner:a.current}}return nn.Fragment=n,nn.jsx=l,nn.jsxs=l,nn}var rn={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,17 +14,17 @@
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var Ha;function
|
|
17
|
+
*/var Ha;function Ru(){return Ha||(Ha=1,process.env.NODE_ENV!=="production"&&function(){var e=y,t=Symbol.for("react.element"),n=Symbol.for("react.portal"),r=Symbol.for("react.fragment"),a=Symbol.for("react.strict_mode"),o=Symbol.for("react.profiler"),l=Symbol.for("react.provider"),u=Symbol.for("react.context"),c=Symbol.for("react.forward_ref"),d=Symbol.for("react.suspense"),f=Symbol.for("react.suspense_list"),h=Symbol.for("react.memo"),g=Symbol.for("react.lazy"),m=Symbol.for("react.offscreen"),C=Symbol.iterator,w="@@iterator";function _(S){if(S===null||typeof S!="object")return null;var z=C&&S[C]||S[w];return typeof z=="function"?z:null}var T=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function M(S){{for(var z=arguments.length,V=new Array(z>1?z-1:0),X=1;X<z;X++)V[X-1]=arguments[X];P("error",S,V)}}function P(S,z,V){{var X=T.ReactDebugCurrentFrame,oe=X.getStackAddendum();oe!==""&&(z+="%s",V=V.concat([oe]));var pe=V.map(function(ne){return String(ne)});pe.unshift("Warning: "+z),Function.prototype.apply.call(console[S],console,pe)}}var G=!1,$=!1,L=!1,A=!1,N=!1,K;K=Symbol.for("react.module.reference");function Y(S){return!!(typeof S=="string"||typeof S=="function"||S===r||S===o||N||S===a||S===d||S===f||A||S===m||G||$||L||typeof S=="object"&&S!==null&&(S.$$typeof===g||S.$$typeof===h||S.$$typeof===l||S.$$typeof===u||S.$$typeof===c||S.$$typeof===K||S.getModuleId!==void 0))}function H(S,z,V){var X=S.displayName;if(X)return X;var oe=z.displayName||z.name||"";return oe!==""?V+"("+oe+")":V}function se(S){return S.displayName||"Context"}function de(S){if(S==null)return null;if(typeof S.tag=="number"&&M("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof S=="function")return S.displayName||S.name||null;if(typeof S=="string")return S;switch(S){case r:return"Fragment";case n:return"Portal";case o:return"Profiler";case a:return"StrictMode";case d:return"Suspense";case f:return"SuspenseList"}if(typeof S=="object")switch(S.$$typeof){case u:var z=S;return se(z)+".Consumer";case l:var V=S;return se(V._context)+".Provider";case c:return H(S,S.render,"ForwardRef");case h:var X=S.displayName||null;return X!==null?X:de(S.type)||"Memo";case g:{var oe=S,pe=oe._payload,ne=oe._init;try{return de(ne(pe))}catch{return null}}}return null}var we=Object.assign,Le=0,yt,Qe,dt,Fe,bt,Bt,fr;function gr(){}gr.__reactDisabledLog=!0;function Ta(){{if(Le===0){yt=console.log,Qe=console.info,dt=console.warn,Fe=console.error,bt=console.group,Bt=console.groupCollapsed,fr=console.groupEnd;var S={configurable:!0,enumerable:!0,value:gr,writable:!0};Object.defineProperties(console,{info:S,log:S,warn:S,error:S,group:S,groupCollapsed:S,groupEnd:S})}Le++}}function Da(){{if(Le--,Le===0){var S={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:we({},S,{value:yt}),info:we({},S,{value:Qe}),warn:we({},S,{value:dt}),error:we({},S,{value:Fe}),group:we({},S,{value:bt}),groupCollapsed:we({},S,{value:Bt}),groupEnd:we({},S,{value:fr})})}Le<0&&M("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var vn=T.ReactCurrentDispatcher,Kt;function kt(S,z,V){{if(Kt===void 0)try{throw Error()}catch(oe){var X=oe.stack.trim().match(/\n( *(at )?)/);Kt=X&&X[1]||""}return`
|
|
18
18
|
`+Kt+S}}var Vt=!1,Tt;{var Xt=typeof WeakMap=="function"?WeakMap:Map;Tt=new Xt}function Jt(S,z){if(!S||Vt)return"";{var V=Tt.get(S);if(V!==void 0)return V}var X;Vt=!0;var oe=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var pe;pe=vn.current,vn.current=null,Ta();try{if(z){var ne=function(){throw Error()};if(Object.defineProperty(ne.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(ne,[])}catch(vt){X=vt}Reflect.construct(S,[],ne)}else{try{ne.call()}catch(vt){X=vt}S.call(ne.prototype)}}else{try{throw Error()}catch(vt){X=vt}S()}}catch(vt){if(vt&&X&&typeof vt.stack=="string"){for(var ee=vt.stack.split(`
|
|
19
19
|
`),Oe=X.stack.split(`
|
|
20
20
|
`),me=ee.length-1,Ce=Oe.length-1;me>=1&&Ce>=0&&ee[me]!==Oe[Ce];)Ce--;for(;me>=1&&Ce>=0;me--,Ce--)if(ee[me]!==Oe[Ce]){if(me!==1||Ce!==1)do if(me--,Ce--,Ce<0||ee[me]!==Oe[Ce]){var He=`
|
|
21
|
-
`+ee[me].replace(" at new "," at ");return S.displayName&&He.includes("<anonymous>")&&(He=He.replace("<anonymous>",S.displayName)),typeof S=="function"&&Tt.set(S,He),He}while(me>=1&&Ce>=0);break}}}finally{Vt=!1,vn.current=pe,Da(),Error.prepareStackTrace=oe}var Ht=S?S.displayName||S.name:"",
|
|
21
|
+
`+ee[me].replace(" at new "," at ");return S.displayName&&He.includes("<anonymous>")&&(He=He.replace("<anonymous>",S.displayName)),typeof S=="function"&&Tt.set(S,He),He}while(me>=1&&Ce>=0);break}}}finally{Vt=!1,vn.current=pe,Da(),Error.prepareStackTrace=oe}var Ht=S?S.displayName||S.name:"",zu=Ht?kt(Ht):"";return typeof S=="function"&&Tt.set(S,zu),zu}function xn(S,z,V){return Jt(S,!1)}function wn(S){var z=S.prototype;return!!(z&&z.isReactComponent)}function Dt(S,z,V){if(S==null)return"";if(typeof S=="function")return Jt(S,wn(S));if(typeof S=="string")return kt(S);switch(S){case d:return kt("Suspense");case f:return kt("SuspenseList")}if(typeof S=="object")switch(S.$$typeof){case c:return xn(S.render);case h:return Dt(S.type,z,V);case g:{var X=S,oe=X._payload,pe=X._init;try{return Dt(pe(oe),z,V)}catch{}}}return""}var Cn=Object.prototype.hasOwnProperty,vu={},xu=T.ReactDebugCurrentFrame;function mr(S){if(S){var z=S._owner,V=Dt(S.type,S._source,z?z.type:null);xu.setExtraStackFrame(V)}else xu.setExtraStackFrame(null)}function OI(S,z,V,X,oe){{var pe=Function.call.bind(Cn);for(var ne in S)if(pe(S,ne)){var ee=void 0;try{if(typeof S[ne]!="function"){var Oe=Error((X||"React class")+": "+V+" type `"+ne+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof S[ne]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw Oe.name="Invariant Violation",Oe}ee=S[ne](z,ne,X,V,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(me){ee=me}ee&&!(ee instanceof Error)&&(mr(oe),M("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",X||"React class",V,ne,typeof ee),mr(null)),ee instanceof Error&&!(ee.message in vu)&&(vu[ee.message]=!0,mr(oe),M("Failed %s type: %s",V,ee.message),mr(null))}}}var PI=Array.isArray;function Ia(S){return PI(S)}function BI(S){{var z=typeof Symbol=="function"&&Symbol.toStringTag,V=z&&S[Symbol.toStringTag]||S.constructor.name||"Object";return V}}function VI(S){try{return wu(S),!1}catch{return!0}}function wu(S){return""+S}function Cu(S){if(VI(S))return M("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",BI(S)),wu(S)}var Sn=T.ReactCurrentOwner,NI={key:!0,ref:!0,__self:!0,__source:!0},Su,_u,Ma;Ma={};function qI(S){if(Cn.call(S,"ref")){var z=Object.getOwnPropertyDescriptor(S,"ref").get;if(z&&z.isReactWarning)return!1}return S.ref!==void 0}function FI(S){if(Cn.call(S,"key")){var z=Object.getOwnPropertyDescriptor(S,"key").get;if(z&&z.isReactWarning)return!1}return S.key!==void 0}function GI(S,z){if(typeof S.ref=="string"&&Sn.current&&z&&Sn.current.stateNode!==z){var V=de(Sn.current.type);Ma[V]||(M('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',de(Sn.current.type),S.ref),Ma[V]=!0)}}function WI(S,z){{var V=function(){Su||(Su=!0,M("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",z))};V.isReactWarning=!0,Object.defineProperty(S,"key",{get:V,configurable:!0})}}function jI(S,z){{var V=function(){_u||(_u=!0,M("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",z))};V.isReactWarning=!0,Object.defineProperty(S,"ref",{get:V,configurable:!0})}}var RI=function(S,z,V,X,oe,pe,ne){var ee={$$typeof:t,type:S,key:z,ref:V,props:ne,_owner:pe};return ee._store={},Object.defineProperty(ee._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(ee,"_self",{configurable:!1,enumerable:!1,writable:!1,value:X}),Object.defineProperty(ee,"_source",{configurable:!1,enumerable:!1,writable:!1,value:oe}),Object.freeze&&(Object.freeze(ee.props),Object.freeze(ee)),ee};function YI(S,z,V,X,oe){{var pe,ne={},ee=null,Oe=null;V!==void 0&&(Cu(V),ee=""+V),FI(z)&&(Cu(z.key),ee=""+z.key),qI(z)&&(Oe=z.ref,GI(z,oe));for(pe in z)Cn.call(z,pe)&&!NI.hasOwnProperty(pe)&&(ne[pe]=z[pe]);if(S&&S.defaultProps){var me=S.defaultProps;for(pe in me)ne[pe]===void 0&&(ne[pe]=me[pe])}if(ee||Oe){var Ce=typeof S=="function"?S.displayName||S.name||"Unknown":S;ee&&WI(ne,Ce),Oe&&jI(ne,Ce)}return RI(S,ee,Oe,oe,X,Sn.current,ne)}}var Aa=T.ReactCurrentOwner,ku=T.ReactDebugCurrentFrame;function Zt(S){if(S){var z=S._owner,V=Dt(S.type,S._source,z?z.type:null);ku.setExtraStackFrame(V)}else ku.setExtraStackFrame(null)}var za;za=!1;function Ea(S){return typeof S=="object"&&S!==null&&S.$$typeof===t}function Tu(){{if(Aa.current){var S=de(Aa.current.type);if(S)return`
|
|
22
22
|
|
|
23
|
-
Check the render method of \``+S+"`."}return""}}function
|
|
23
|
+
Check the render method of \``+S+"`."}return""}}function QI(S){{if(S!==void 0){var z=S.fileName.replace(/^.*[\\\/]/,""),V=S.lineNumber;return`
|
|
24
24
|
|
|
25
|
-
Check your code at `+z+":"+V+"."}return""}}var
|
|
25
|
+
Check your code at `+z+":"+V+"."}return""}}var Du={};function UI(S){{var z=Tu();if(!z){var V=typeof S=="string"?S:S.displayName||S.name;V&&(z=`
|
|
26
26
|
|
|
27
|
-
Check the top-level render call using <`+V+">.")}return z}}function
|
|
27
|
+
Check the top-level render call using <`+V+">.")}return z}}function Iu(S,z){{if(!S._store||S._store.validated||S.key!=null)return;S._store.validated=!0;var V=UI(z);if(Du[V])return;Du[V]=!0;var X="";S&&S._owner&&S._owner!==Aa.current&&(X=" It was passed a child from "+de(S._owner.type)+"."),Zt(S),M('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',V,X),Zt(null)}}function Mu(S,z){{if(typeof S!="object")return;if(Ia(S))for(var V=0;V<S.length;V++){var X=S[V];Ea(X)&&Iu(X,z)}else if(Ea(S))S._store&&(S._store.validated=!0);else if(S){var oe=_(S);if(typeof oe=="function"&&oe!==S.entries)for(var pe=oe.call(S),ne;!(ne=pe.next()).done;)Ea(ne.value)&&Iu(ne.value,z)}}}function KI(S){{var z=S.type;if(z==null||typeof z=="string")return;var V;if(typeof z=="function")V=z.propTypes;else if(typeof z=="object"&&(z.$$typeof===c||z.$$typeof===h))V=z.propTypes;else return;if(V){var X=de(z);OI(V,S.props,"prop",X,S)}else if(z.PropTypes!==void 0&&!za){za=!0;var oe=de(z);M("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",oe||"Unknown")}typeof z.getDefaultProps=="function"&&!z.getDefaultProps.isReactClassApproved&&M("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function XI(S){{for(var z=Object.keys(S.props),V=0;V<z.length;V++){var X=z[V];if(X!=="children"&&X!=="key"){Zt(S),M("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",X),Zt(null);break}}S.ref!==null&&(Zt(S),M("Invalid attribute `ref` supplied to `React.Fragment`."),Zt(null))}}function Au(S,z,V,X,oe,pe){{var ne=Y(S);if(!ne){var ee="";(S===void 0||typeof S=="object"&&S!==null&&Object.keys(S).length===0)&&(ee+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var Oe=QI(oe);Oe?ee+=Oe:ee+=Tu();var me;S===null?me="null":Ia(S)?me="array":S!==void 0&&S.$$typeof===t?(me="<"+(de(S.type)||"Unknown")+" />",ee=" Did you accidentally export a JSX literal instead of a component?"):me=typeof S,M("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",me,ee)}var Ce=YI(S,z,V,oe,pe);if(Ce==null)return Ce;if(ne){var He=z.children;if(He!==void 0)if(X)if(Ia(He)){for(var Ht=0;Ht<He.length;Ht++)Mu(He[Ht],S);Object.freeze&&Object.freeze(He)}else M("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Mu(He,S)}return S===r?XI(Ce):KI(Ce),Ce}}function JI(S,z,V){return Au(S,z,V,!0)}function ZI(S,z,V){return Au(S,z,V,!1)}var HI=ZI,eM=JI;rn.Fragment=r,rn.jsx=HI,rn.jsxs=eM}()),rn}(function(e){process.env.NODE_ENV==="production"?e.exports=ju():e.exports=Ru()})(Wu);const B=tn.Fragment,i=tn.jsx,p=tn.jsxs,At={CryptoJS:$a,d3Array:Gu,dayjs:U,lodash:x,numbro:Z,mathjs:Dn,faker:$u.faker},Yu=[{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"}],Qu=e=>`
|
|
28
28
|
<tr>
|
|
29
29
|
<td><code>${e.name}</code></td>
|
|
30
30
|
<td>
|
|
@@ -36,7 +36,7 @@ Check the top-level render call using <`+V+">.")}return z}}function Tu(S,z){{if(
|
|
|
36
36
|
>
|
|
37
37
|
</td>
|
|
38
38
|
</tr>
|
|
39
|
-
`,
|
|
39
|
+
`,Uu=`
|
|
40
40
|
<p>
|
|
41
41
|
Parameter <code>utils</code> is <code>functionUtils</code>, which contains:
|
|
42
42
|
</p>
|
|
@@ -48,30 +48,30 @@ Check the top-level render call using <`+V+">.")}return z}}function Tu(S,z){{if(
|
|
|
48
48
|
</tr>
|
|
49
49
|
</thead>
|
|
50
50
|
<tbody>
|
|
51
|
-
${
|
|
51
|
+
${Yu.map(Qu).join("")}
|
|
52
52
|
</tbody>
|
|
53
53
|
</table>
|
|
54
|
-
`;function vr(e,t){const n=Object.keys(t),r=Object.values(t);try{return new Function(...n,`return \`${e}\`;`)(...r)}catch(a){throw n.length===0&&e.includes("$")?new Error("[formatSQL] insufficient payload"):a}}function xr(e,t){try{return vr(e,t)}catch(n){return console.error(n),n.message}}function Qu({sql:e,pre_process:t}){if(!t.trim())return e;try{return new Function(`return ${t}`)()({sql:e},At)}catch(n){return console.error(n),e}}function Uu(e,t){if(!e.trim())return t;try{return new Function(`return ${e}`)()(t,At)}catch(n){return console.error(n),t}}function Ku(e){e=e||{};const t=Object.keys(e).sort(),n=[];for(let r=0;r<t.length;r++){const a=t[r];if(a!="authentication"&&e[a])n.push(t[r]+"="+(typeof e[a]=="object"?JSON.stringify(e[a]):e[a]));else{const o=Object.keys(e[a]).sort();for(let l=0;l<o.length;l++){const u=o[l];u!="sign"&&e[a][u]&&n.push(o[l]+"="+(typeof e[a][u]=="object"?JSON.stringify(e[a][u]):e[a][u]))}}}return n.sort().join("&")}function Xu(e,t){let n=Ku(e);return n+="&key="+t,$a.MD5(n).toString().toUpperCase()}const Pe={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:Xu({app_id:this.app_id,nonce_str:t,...e},this.app_secret)}},getRequest(e,t){return(n,r,a={})=>{const o=window.localStorage.getItem("token"),l={"X-Requested-With":"XMLHttpRequest","Content-Type":a.string?"application/x-www-form-urlencoded":"application/json",authorization:o?`bearer ${o}`:"",...a.headers},u={baseURL:this.baseURL,method:e,url:n,params:e==="GET"?r:a.params,headers:l,signal:t};return["POST","PUT"].includes(e)&&(u.data=a.string?JSON.stringify(r):r,u.data.authentication=this.getAuthentication(u.data)),xt(u).then(c=>c.data).catch(c=>Promise.reject(c))}},makeQueryENV:null,query(e){return async(t,n={})=>{var r;return t.env||(t.env=((r=this.makeQueryENV)==null?void 0:r.call(this))??{error:"failed to run makeQueryENV"}),this.getRequest("POST",e)("/query",t,n)}}};function es(e){Pe.baseURL!==e.apiBaseURL&&(Pe.baseURL=e.apiBaseURL),e.app_id&&(Pe.app_id=e.app_id),e.app_secret&&(Pe.app_secret=e.app_secret),e.makeQueryENV&&(Pe.makeQueryENV=e.makeQueryENV)}async function Ju({query:e,name:t,payload:n},r){if(!e.sql)return[];const{type:a,key:o,sql:l,pre_process:u,post_process:c}=e,d=vr(l,n),f=Qu({sql:d,pre_process:u});let h=await Pe.query(r)({type:a,key:o,query:f},{params:{name:t}});return h=Uu(c,h),h}async function Zu({type:e,key:t,configString:n,name:r},a){return await Pe.query(a)({type:e,key:t,query:n},{params:{name:r}})}async function wr(){try{return(await Pe.getRequest("POST")("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}})).data}catch(e){return console.error(e),[]}}async function ts(){try{return(await Pe.getRequest("POST")("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}})).data}catch(e){return console.error(e),[]}}class ns{constructor(t){q(this,"rootRef");this.rootRef=te.observable({current:t})}async deleteItem(t){te.runInAction(()=>{x.unset(this.rootRef.current,[t])})}getItem(t){const n=this.getValueFromRoot(t);return Promise.resolve(n)}getValueFromRoot(t){return t===null?te.toJS(this.rootRef.current):x.get(this.rootRef.current,[t])}setItem(t,n){if(t===null)if(x.isObject(n))te.runInAction(()=>{this.rootRef.current=n});else throw new Error("Cannot set root value to non-object");else te.runInAction(()=>{x.set(this.rootRef.current,[t],n)});return Promise.resolve(this.getItem(t))}watchItem(t,n,r){return te.reaction(()=>this.getValueFromRoot(t),(a,o)=>{n(a,o)},{requiresObservable:!0,fireImmediately:x.get(r,"fireImmediately",!1)})}}class Hu{constructor(){q(this,"channels",new Map);q(this,"globalChannel",new La)}getChannel(t){const n=this.channels.get(t);if(n)return n;const r=new La;return this.channels.set(t,r),r}}class ec{constructor(t){q(this,"instances",new Map);this.pluginManager=t}get availableVizList(){return this.pluginManager.installedPlugins.flatMap(t=>t.manifest.viz)}resolveComponent(t){return this.pluginManager.factory.viz(t)}getOrCreateInstance(t){const n=this.instances.get(t.id);if(n)return n;const r={id:t.id,name:t.viz.type,type:t.viz.type,messageChannels:new Hu,instanceData:new ns(t.viz.conf)};return this.instances.set(t.id,r),r}}function rs(e,t,n,r){return{vizManager:n,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new ns({}),colorPalette:{getColor(){return()=>""}},data:t,variables:r}}const tc=e=>{const{panel:t,vizManager:n,data:r,variables:a}=e,o=n.resolveComponent(t.viz.type),l=n.getOrCreateInstance(t),u={...rs(l,r,n,a),viewport:{width:t.layout.w,height:t.layout.h}},c=o.viewRender;return i(c,{context:u,instance:l,...x.omit(e,["panel","vizManager","data"])})},nc=e=>{const{vizManager:t,panel:n,panelInfoEditor:r,data:a,variables:o}=e,l=t.resolveComponent(n.viz.type),u=t.getOrCreateInstance(n),c={...rs(u,a,t,o),panelInfoEditor:r},d=l.configRender;return i(d,{context:c,instance:u,...x.omit(e,["panel","vizManager","data","panelInfoEditor"])})},is=(e,t)=>{const n=pt.bezier(e),r=pt.bezier(t);return function(a){return a<50?n(a*2/100).hex():r((a-50)*2/100).hex()}},In=e=>{const t=pt.bezier(e);return function(n){return t(n/100).hex()}},rc={type:"interpolation",displayName:"Red / Green",getColor:is(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},ic={type:"interpolation",displayName:"Yellow / Blue",getColor:is(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},ac={type:"interpolation",displayName:"Red",getColor:In(["#fff7f1","darkred"]),name:"red",category:"sequential"},sc={type:"interpolation",displayName:"Green",getColor:In(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},oc={type:"interpolation",displayName:"Blue",getColor:In(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},lc={type:"interpolation",displayName:"Orange",getColor:In(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class uc{constructor(t){q(this,"symbol");this.symbol=Symbol(t)}}function ht(e){return new uc(e)}class Cr{constructor(){q(this,"parent");q(this,"factoryRegistry",new Map);q(this,"instanceRegistry",new Map)}createScoped(){const t=new Cr;return t.parent=this,t}getRequired(t){return this.get(t)}get(t){if(this.instanceRegistry.has(t.symbol))return this.instanceRegistry.get(t.symbol);const n=this.factoryRegistry.get(t.symbol);if(n){const r=n(this);return this.instanceRegistry.set(t.symbol,r),r}if(this.parent)return this.parent.get(t)}provideFactory(t,n){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,n),this}provideValue(t,n){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,()=>n),this}dispose(){this.instanceRegistry.forEach(t=>{const n=x.get(t,"dispose");x.isFunction(n)&&n.bind(t)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}const as="10.34.7",cc=Object.freeze(Object.defineProperty({__proto__:null,version:as},Symbol.toStringTag,{value:"Module"}));class dc{constructor(t){q(this,"staticColors",new Map);q(this,"interpolations",new Map);t.installedPlugins.forEach(n=>{n.manifest.color.forEach(r=>{this.register(r)})})}getStaticColors(){return Array.from(this.staticColors.values())}register(t){const n=this.encodeColor(t);t.type==="single"?(this.staticColors.has(n)&&console.warn(`the color '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.staticColors.set(n,t)):t.type==="interpolation"&&(this.interpolations.has(n)&&console.warn(`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`,`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.interpolations.set(n,t))}decodeStaticColor(t){return this.staticColors.get(t)}encodeColor(t){return`\${${t.category}}.{${t.name}}`}decodeInterpolation(t){return this.interpolations.get(t)}getColorInterpolations(){return Array.from(this.interpolations.values())}}class pc{constructor(){q(this,"plugins",new Map);q(this,"vizComponents",new Map);q(this,"factory",{viz:t=>{const n=this.vizComponents.get(t);if(n)return n;throw new Error(`Viz Component (${t}) not found`)}})}install(t){if(this.plugins.has(t.id))throw new Error(`Plugin (${t.id}) has been installed before`);this.plugins.set(t.id,t);for(const n of t.manifest.viz){if(this.vizComponents.has(n.name))throw new Error(`Viz Component (${n.name}) has been installed before`);this.vizComponents.set(n.name,n)}}get installedPlugins(){return Array.from(this.plugins.values())}}class hc{constructor(){q(this,"migrations",[])}version(t,n){return this.migrations.push({version:t,handler:n}),this}run(t,n,r){var l;if(t.from===t.to)return n;if(t.from>t.to)throw new Error(`Can not downgrade from version '${t.from}' to (${t.to})`);const a=this.migrations.filter(u=>u.version>t.from&&u.version<=t.to),o=x.orderBy(a,"version","asc");if(((l=x.last(o))==null?void 0:l.version)!==t.to)throw new Error(`Migration to version ${t.to} not found`);return o.reduce((u,c)=>c.handler(u,r),n)}}class ge extends hc{constructor(){super(),this.configVersions()}version(t,n){return super.version(t,(r,a)=>({version:t,...n(r,a)}))}async migrate({configData:t,panelModel:n}){const r=await t.getItem(null),a=x.get(r,"version",0),o=this.run({from:a,to:this.VERSION},r,{panelModel:n});await t.setItem(null,o)}async needMigration({configData:t}){const n=await t.getItem(null);return x.get(n,"version",0)<this.VERSION}}const R=(e,t)=>{const[n,{setFalse:r}]=Q.useBoolean(!0),[a,o]=y.useState();y.useEffect(()=>(e.getItem(t).then(u=>{o(u),r()}),e.watchItem(t,u=>{o(u)})));const l=y.useCallback(async u=>{await e.setItem(t,u),o(u)},[e,t]);return{loading:n,value:a,set:l}},Be={top:16,right:16,bottom:16,left:16},tt=e=>Math.max(0,e-Be.left-Be.right),nt=e=>Math.max(0,e-Be.top-Be.bottom),an=(e,t)=>({width:tt(e),height:nt(t)}),Ve=({width:e,height:t,children:n})=>i(s.Box,{pt:Be.top,pr:Be.right,pb:Be.bottom,pl:Be.left,sx:{width:e,height:t,overflow:"hidden",position:"relative"},children:n});function O(e){const[t,n]=e.split(".");return{queryID:t,columnKey:n}}function fc(e){return e.includes(".")?O(e):{queryID:"",columnKey:e}}function ft(e,t){var a;const{queryID:n,columnKey:r}=O(t);return n?r?((a=e[n])==null?void 0:a.map(o=>o[r]))??[]:e[n]:[]}function sn(e,t){const{queryID:n}=O(t);return n?e[n]:[]}function gc(e){return Object.values(e)[0]}function Mn(e,t){const{queryID:n,columnKey:r}=O(t);return e[r]}const Sr={x_axis_data_key:"",y_axis_data_key:"",z_axis_data_key:"",xAxis3D:{type:"value",name:"X Axis Name"},yAxis3D:{type:"value",name:"Y Axis Name"},zAxis3D:{type:"value",name:"Z Axis Name"}};ie.use([F.GridComponent,F.VisualMapComponent,F.LegendComponent,F.TooltipComponent,Ee.CanvasRenderer]);function mc({context:e}){const{value:t}=R(e.instanceData,"config"),n=e.data,{width:r,height:a}=e.viewport,{x_axis_data_key:o,y_axis_data_key:l,z_axis_data_key:u,xAxis3D:c,yAxis3D:d,zAxis3D:f}=x.defaults({},t,Sr),h=y.useMemo(()=>sn(n,o),[n,o]),{x:g,y:m,z:C}=y.useMemo(()=>({x:O(o),y:O(l),z:O(u)}),[o,l,u]),{min:w,max:_}=y.useMemo(()=>{const M=x.minBy(h,G=>G[C.columnKey]),P=x.maxBy(h,G=>G[C.columnKey]);return{min:x.get(M,C.columnKey),max:x.get(P,C.columnKey)}},[h,C]),T={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:w,max:_,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:c,yAxis3D:d,zAxis3D:f,grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}},series:[{type:"bar3D",wireframe:{},data:h.map(M=>[M[g.columnKey],M[m.columnKey],M[C.columnKey]])}]};return t?i(Ve,{width:r,height:a,children:i(ze,{echarts:ie,option:T,style:an(r,a),notMerge:!0,theme:"merico-light"})}):null}const ss=y.createContext(null),_r=ss.Provider;function kr(){const e=y.useContext(ss);if(!e)throw new Error("Please use DashboardModelContextProvider");return e}const ue=()=>kr(),Tr=()=>kr(),os=y.createContext(null),Dr=os.Provider;function ls(){const e=y.useContext(os);if(!e)throw new Error("Please use ContentModelContextProvider");return e}const le=()=>ls(),ye=()=>ls(),yc={inEditMode:!1},An=y.createContext(yc),us=y.createContext({panel:null,data:{},loading:!1,errors:[],downloadPanelScreenshot:()=>{}}),Ir=us.Provider;function cs(){const e=y.useContext(us);if(!e.panel)throw new Error("Please use PanelContextProvider");return e}const Ct=()=>cs(),rt=()=>cs(),bc={fullScreenPanelID:"",setFullScreenPanelID:x.noop},Mr=y.createContext(bc);function ds(){const e=y.useContext(Mr);if(!e)throw new Error("Please use FullScreenPanelContext.Provider");return e}const W=k.observer(y.forwardRef(({label:e,required:t,value:n,onChange:r,clearable:a=!1,sx:o,...l},u)=>{const{panel:c}=rt(),d=y.useMemo(()=>{const f=[...c.dataFieldOptions];return a&&f.unshift({label:"unset",value:"",group:""}),f},[c.dataFieldOptions]);return i(s.Select,{ref:u,label:e,data:d,value:n,onChange:r,required:t,sx:o,maxDropdownHeight:500,...l})}));function vc({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=x.defaults({},t,Sr),{control:a,handleSubmit:o,reset:l}=v.useForm({defaultValues:r});return y.useEffect(()=>{l(r)},[t]),t?i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[i(s.Text,{children:"X Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"x_axis_data_key",control:a,render:({field:u})=>i(W,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"xAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Text,{mt:"lg",children:"Y Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"y_axis_data_key",control:a,render:({field:u})=>i(W,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"yAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Text,{mt:"lg",children:"Z Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"z_axis_data_key",control:a,render:({field:u})=>i(W,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"zAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:p(s.Button,{color:"blue",type:"submit",children:[i(D.DeviceFloppy,{size:20}),i(s.Text,{ml:"md",children:"Save"})]})})]})}):null}function xc(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis_data_key:a,y_axis_data_key:o,z_axis_data_key:l,...u}=e;return{...u,x_axis_data_key:r(a),y_axis_data_key:r(o),z_axis_data_key:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class wc extends ge{constructor(){super(...arguments);q(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:a}=n;return{...n,version:2,config:xc(a,r)}})}}const Cc={displayName:"Bar Chart (3D)",displayGroup:"ECharts-based charts",migrator:new wc,name:"bar-3d",viewRender:mc,configRender:vc,createConfig(){return{version:2,config:x.cloneDeep(Sr)}}};class Ne extends y.Component{constructor(t){super(t),this.state={error:null}}componentDidCatch(t){this.setState({error:t})}render(){var t;if(this.state.error){const n=()=>{this.setState({error:null})};return p(s.Box,{children:[i(s.Text,{size:"xs",children:(t=this.state.error)==null?void 0:t.message}),i(s.Button,{variant:"subtle",size:"xs",mx:"auto",compact:!0,sx:{display:"block"},onClick:n,children:"Retry"})]})}return this.props.children}}const Ie={mantissa:0,output:"number",trimMantissa:!1,average:!1};function Sc({value:e,onChange:t},n){const r=u=>{t({...e,output:u})},a=u=>{const c=u===0?!1:e.trimMantissa;t({...e,mantissa:u,trimMantissa:c})},o=u=>{t({...e,trimMantissa:u.currentTarget.checked})},l=u=>{t({...e,average:u.currentTarget.checked})};return p(s.Stack,{ref:n,children:[p(s.Group,{grow:!0,children:[i(s.Select,{label:"Format",data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:e.output,onChange:r,sx:{flexGrow:1}}),i(s.Switch,{label:p(s.Stack,{spacing:0,children:[i(s.Text,{children:"Average"}),i(s.Text,{size:12,color:"gray",children:"like 1.234k, 1.234m"})]}),checked:e.average,onChange:l,disabled:e.output!=="number",sx:{flexGrow:1},styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}}})]}),p(s.Group,{grow:!0,children:[i(s.NumberInput,{label:"Mantissa",defaultValue:0,min:0,step:1,max:4,value:e.mantissa,onChange:a}),i(s.Switch,{label:"Trim mantissa",checked:e.trimMantissa,onChange:o,disabled:e.mantissa===0,styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"}}})]}),p(s.Stack,{spacing:0,children:[i(s.Text,{weight:"bold",children:"Preview"}),i(Ne,{children:p(s.Group,{position:"apart",children:[p(s.Text,{size:12,color:"gray",children:["123456789 ",i(D.ArrowRight,{size:9})," ",Z(123456789).format(e)]}),p(s.Text,{size:12,color:"gray",children:["1234 ",i(D.ArrowRight,{size:9})," ",Z(1234).format(e)]}),p(s.Text,{size:12,color:"gray",children:["0.1234 ",i(D.ArrowRight,{size:9})," ",Z(.1234).format(e)]})]})})]})]})}const We=y.forwardRef(Sc),Ue={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
55
|
-
`)},
|
|
54
|
+
`;function vr(e,t){const n=Object.keys(t),r=Object.values(t);try{return new Function(...n,`return \`${e}\`;`)(...r)}catch(a){throw n.length===0&&e.includes("$")?new Error("[formatSQL] insufficient payload"):a}}function xr(e,t){try{return vr(e,t)}catch(n){return console.error(n),n.message}}function Ku({sql:e,pre_process:t}){if(!t.trim())return e;try{return new Function(`return ${t}`)()({sql:e},At)}catch(n){return console.error(n),e}}function Xu(e,t,n){if(!e.trim())return t;try{return new Function(`return ${e}`)()(t,At,n)}catch(r){return console.error(r),t}}function Ju(e){e=e||{};const t=Object.keys(e).sort(),n=[];for(let r=0;r<t.length;r++){const a=t[r];if(a!="authentication"&&e[a])n.push(t[r]+"="+(typeof e[a]=="object"?JSON.stringify(e[a]):e[a]));else{const o=Object.keys(e[a]).sort();for(let l=0;l<o.length;l++){const u=o[l];u!="sign"&&e[a][u]&&n.push(o[l]+"="+(typeof e[a][u]=="object"?JSON.stringify(e[a][u]):e[a][u]))}}}return n.sort().join("&")}function Zu(e,t){let n=Ju(e);return n+="&key="+t,$a.MD5(n).toString().toUpperCase()}const Pe={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:Zu({app_id:this.app_id,nonce_str:t,...e},this.app_secret)}},getRequest(e,t){return(n,r,a={})=>{const o=window.localStorage.getItem("token"),l={"X-Requested-With":"XMLHttpRequest","Content-Type":a.string?"application/x-www-form-urlencoded":"application/json",authorization:o?`bearer ${o}`:"",...a.headers},u={baseURL:this.baseURL,method:e,url:n,params:e==="GET"?r:a.params,headers:l,signal:t};return["POST","PUT"].includes(e)&&(u.data=a.string?JSON.stringify(r):r,u.data.authentication=this.getAuthentication(u.data)),xt(u).then(c=>c.data).catch(c=>Promise.reject(c))}},makeQueryENV:null,query(e){return async(t,n={})=>{var r;return t.env||(t.env=((r=this.makeQueryENV)==null?void 0:r.call(this))??{error:"failed to run makeQueryENV"}),this.getRequest("POST",e)("/query",t,n)}}};function es(e){Pe.baseURL!==e.apiBaseURL&&(Pe.baseURL=e.apiBaseURL),e.app_id&&(Pe.app_id=e.app_id),e.app_secret&&(Pe.app_secret=e.app_secret),e.makeQueryENV&&(Pe.makeQueryENV=e.makeQueryENV)}function ts(){return{filters:{},context:{}}}function ns(e){const t=ts();if(!e)return ts();const{filters:n=t.filters,context:r=t.context}=e;return{filters:n,context:r}}async function Hu({query:e,name:t,payload:n},r){if(!e.sql)return[];const{type:a,key:o,sql:l,pre_process:u,post_process:c}=e,d=vr(l,n),f=Ku({sql:d,pre_process:u});let h=await Pe.query(r)({type:a,key:o,query:f},{params:{name:t}});return h=Xu(c,h,ns(n)),h}async function ec({type:e,key:t,configString:n,name:r},a){return await Pe.query(a)({type:e,key:t,query:n},{params:{name:r}})}async function wr(){try{return(await Pe.getRequest("POST")("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}})).data}catch(e){return console.error(e),[]}}async function rs(){try{return(await Pe.getRequest("POST")("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}})).data}catch(e){return console.error(e),[]}}class is{constructor(t){q(this,"rootRef");this.rootRef=te.observable({current:t})}async deleteItem(t){te.runInAction(()=>{x.unset(this.rootRef.current,[t])})}getItem(t){const n=this.getValueFromRoot(t);return Promise.resolve(n)}getValueFromRoot(t){return t===null?te.toJS(this.rootRef.current):x.get(this.rootRef.current,[t])}setItem(t,n){if(t===null)if(x.isObject(n))te.runInAction(()=>{this.rootRef.current=n});else throw new Error("Cannot set root value to non-object");else te.runInAction(()=>{x.set(this.rootRef.current,[t],n)});return Promise.resolve(this.getItem(t))}watchItem(t,n,r){return te.reaction(()=>this.getValueFromRoot(t),(a,o)=>{n(a,o)},{requiresObservable:!0,fireImmediately:x.get(r,"fireImmediately",!1)})}}class tc{constructor(){q(this,"channels",new Map);q(this,"globalChannel",new La)}getChannel(t){const n=this.channels.get(t);if(n)return n;const r=new La;return this.channels.set(t,r),r}}class nc{constructor(t){q(this,"instances",new Map);this.pluginManager=t}get availableVizList(){return this.pluginManager.installedPlugins.flatMap(t=>t.manifest.viz)}resolveComponent(t){return this.pluginManager.factory.viz(t)}getOrCreateInstance(t){const n=this.instances.get(t.id);if(n)return n;const r={id:t.id,name:t.viz.type,type:t.viz.type,messageChannels:new tc,instanceData:new is(t.viz.conf)};return this.instances.set(t.id,r),r}}function as(e,t,n,r){return{vizManager:n,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new is({}),colorPalette:{getColor(){return()=>""}},data:t,variables:r}}const rc=e=>{const{panel:t,vizManager:n,data:r,variables:a}=e,o=n.resolveComponent(t.viz.type),l=n.getOrCreateInstance(t),u={...as(l,r,n,a),viewport:{width:t.layout.w,height:t.layout.h}},c=o.viewRender;return i(c,{context:u,instance:l,...x.omit(e,["panel","vizManager","data"])})},ic=e=>{const{vizManager:t,panel:n,panelInfoEditor:r,data:a,variables:o}=e,l=t.resolveComponent(n.viz.type),u=t.getOrCreateInstance(n),c={...as(u,a,t,o),panelInfoEditor:r},d=l.configRender;return i(d,{context:c,instance:u,...x.omit(e,["panel","vizManager","data","panelInfoEditor"])})},ss=(e,t)=>{const n=pt.bezier(e),r=pt.bezier(t);return function(a){return a<50?n(a*2/100).hex():r((a-50)*2/100).hex()}},In=e=>{const t=pt.bezier(e);return function(n){return t(n/100).hex()}},ac={type:"interpolation",displayName:"Red / Green",getColor:ss(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},sc={type:"interpolation",displayName:"Yellow / Blue",getColor:ss(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},oc={type:"interpolation",displayName:"Red",getColor:In(["#fff7f1","darkred"]),name:"red",category:"sequential"},lc={type:"interpolation",displayName:"Green",getColor:In(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},uc={type:"interpolation",displayName:"Blue",getColor:In(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},cc={type:"interpolation",displayName:"Orange",getColor:In(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class dc{constructor(t){q(this,"symbol");this.symbol=Symbol(t)}}function ht(e){return new dc(e)}class Cr{constructor(){q(this,"parent");q(this,"factoryRegistry",new Map);q(this,"instanceRegistry",new Map)}createScoped(){const t=new Cr;return t.parent=this,t}getRequired(t){return this.get(t)}get(t){if(this.instanceRegistry.has(t.symbol))return this.instanceRegistry.get(t.symbol);const n=this.factoryRegistry.get(t.symbol);if(n){const r=n(this);return this.instanceRegistry.set(t.symbol,r),r}if(this.parent)return this.parent.get(t)}provideFactory(t,n){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,n),this}provideValue(t,n){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,()=>n),this}dispose(){this.instanceRegistry.forEach(t=>{const n=x.get(t,"dispose");x.isFunction(n)&&n.bind(t)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}const os="10.35.0",pc=Object.freeze(Object.defineProperty({__proto__:null,version:os},Symbol.toStringTag,{value:"Module"}));class hc{constructor(t){q(this,"staticColors",new Map);q(this,"interpolations",new Map);t.installedPlugins.forEach(n=>{n.manifest.color.forEach(r=>{this.register(r)})})}getStaticColors(){return Array.from(this.staticColors.values())}register(t){const n=this.encodeColor(t);t.type==="single"?(this.staticColors.has(n)&&console.warn(`the color '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.staticColors.set(n,t)):t.type==="interpolation"&&(this.interpolations.has(n)&&console.warn(`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`,`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.interpolations.set(n,t))}decodeStaticColor(t){return this.staticColors.get(t)}encodeColor(t){return`\${${t.category}}.{${t.name}}`}decodeInterpolation(t){return this.interpolations.get(t)}getColorInterpolations(){return Array.from(this.interpolations.values())}}class fc{constructor(){q(this,"plugins",new Map);q(this,"vizComponents",new Map);q(this,"factory",{viz:t=>{const n=this.vizComponents.get(t);if(n)return n;throw new Error(`Viz Component (${t}) not found`)}})}install(t){if(this.plugins.has(t.id))throw new Error(`Plugin (${t.id}) has been installed before`);this.plugins.set(t.id,t);for(const n of t.manifest.viz){if(this.vizComponents.has(n.name))throw new Error(`Viz Component (${n.name}) has been installed before`);this.vizComponents.set(n.name,n)}}get installedPlugins(){return Array.from(this.plugins.values())}}class gc{constructor(){q(this,"migrations",[])}version(t,n){return this.migrations.push({version:t,handler:n}),this}run(t,n,r){var l;if(t.from===t.to)return n;if(t.from>t.to)throw new Error(`Can not downgrade from version '${t.from}' to (${t.to})`);const a=this.migrations.filter(u=>u.version>t.from&&u.version<=t.to),o=x.orderBy(a,"version","asc");if(((l=x.last(o))==null?void 0:l.version)!==t.to)throw new Error(`Migration to version ${t.to} not found`);return o.reduce((u,c)=>c.handler(u,r),n)}}class ge extends gc{constructor(){super(),this.configVersions()}version(t,n){return super.version(t,(r,a)=>({version:t,...n(r,a)}))}async migrate({configData:t,panelModel:n}){const r=await t.getItem(null),a=x.get(r,"version",0),o=this.run({from:a,to:this.VERSION},r,{panelModel:n});await t.setItem(null,o)}async needMigration({configData:t}){const n=await t.getItem(null);return x.get(n,"version",0)<this.VERSION}}const R=(e,t)=>{const[n,{setFalse:r}]=Q.useBoolean(!0),[a,o]=y.useState();y.useEffect(()=>(e.getItem(t).then(u=>{o(u),r()}),e.watchItem(t,u=>{o(u)})));const l=y.useCallback(async u=>{await e.setItem(t,u),o(u)},[e,t]);return{loading:n,value:a,set:l}},Be={top:16,right:16,bottom:16,left:16},tt=e=>Math.max(0,e-Be.left-Be.right),nt=e=>Math.max(0,e-Be.top-Be.bottom),an=(e,t)=>({width:tt(e),height:nt(t)}),Ve=({width:e,height:t,children:n})=>i(s.Box,{pt:Be.top,pr:Be.right,pb:Be.bottom,pl:Be.left,sx:{width:e,height:t,overflow:"hidden",position:"relative"},children:n});function O(e){const[t,n]=e.split(".");return{queryID:t,columnKey:n}}function mc(e){return e.includes(".")?O(e):{queryID:"",columnKey:e}}function ft(e,t){var a;const{queryID:n,columnKey:r}=O(t);return n?r?((a=e[n])==null?void 0:a.map(o=>o[r]))??[]:e[n]:[]}function sn(e,t){const{queryID:n}=O(t);return n?e[n]:[]}function yc(e){return Object.values(e)[0]}function Mn(e,t){const{queryID:n,columnKey:r}=O(t);return e[r]}const Sr={x_axis_data_key:"",y_axis_data_key:"",z_axis_data_key:"",xAxis3D:{type:"value",name:"X Axis Name"},yAxis3D:{type:"value",name:"Y Axis Name"},zAxis3D:{type:"value",name:"Z Axis Name"}};ie.use([F.GridComponent,F.VisualMapComponent,F.LegendComponent,F.TooltipComponent,Ee.CanvasRenderer]);function bc({context:e}){const{value:t}=R(e.instanceData,"config"),n=e.data,{width:r,height:a}=e.viewport,{x_axis_data_key:o,y_axis_data_key:l,z_axis_data_key:u,xAxis3D:c,yAxis3D:d,zAxis3D:f}=x.defaults({},t,Sr),h=y.useMemo(()=>sn(n,o),[n,o]),{x:g,y:m,z:C}=y.useMemo(()=>({x:O(o),y:O(l),z:O(u)}),[o,l,u]),{min:w,max:_}=y.useMemo(()=>{const M=x.minBy(h,G=>G[C.columnKey]),P=x.maxBy(h,G=>G[C.columnKey]);return{min:x.get(M,C.columnKey),max:x.get(P,C.columnKey)}},[h,C]),T={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:w,max:_,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:c,yAxis3D:d,zAxis3D:f,grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}},series:[{type:"bar3D",wireframe:{},data:h.map(M=>[M[g.columnKey],M[m.columnKey],M[C.columnKey]])}]};return t?i(Ve,{width:r,height:a,children:i(ze,{echarts:ie,option:T,style:an(r,a),notMerge:!0,theme:"merico-light"})}):null}const ls=y.createContext(null),_r=ls.Provider;function kr(){const e=y.useContext(ls);if(!e)throw new Error("Please use DashboardModelContextProvider");return e}const ue=()=>kr(),Tr=()=>kr(),us=y.createContext(null),Dr=us.Provider;function cs(){const e=y.useContext(us);if(!e)throw new Error("Please use ContentModelContextProvider");return e}const le=()=>cs(),ye=()=>cs(),vc={inEditMode:!1},An=y.createContext(vc),ds=y.createContext({panel:null,data:{},loading:!1,errors:[],downloadPanelScreenshot:()=>{}}),Ir=ds.Provider;function ps(){const e=y.useContext(ds);if(!e.panel)throw new Error("Please use PanelContextProvider");return e}const Ct=()=>ps(),rt=()=>ps(),xc={fullScreenPanelID:"",setFullScreenPanelID:x.noop},Mr=y.createContext(xc);function hs(){const e=y.useContext(Mr);if(!e)throw new Error("Please use FullScreenPanelContext.Provider");return e}const W=k.observer(y.forwardRef(({label:e,required:t,value:n,onChange:r,clearable:a=!1,sx:o,...l},u)=>{const{panel:c}=rt(),d=y.useMemo(()=>{const f=[...c.dataFieldOptions];return a&&f.unshift({label:"unset",value:"",group:""}),f},[c.dataFieldOptions]);return i(s.Select,{ref:u,label:e,data:d,value:n,onChange:r,required:t,sx:o,maxDropdownHeight:500,...l})}));function wc({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=x.defaults({},t,Sr),{control:a,handleSubmit:o,reset:l}=v.useForm({defaultValues:r});return y.useEffect(()=>{l(r)},[t]),t?i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[i(s.Text,{children:"X Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"x_axis_data_key",control:a,render:({field:u})=>i(W,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"xAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Text,{mt:"lg",children:"Y Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"y_axis_data_key",control:a,render:({field:u})=>i(W,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"yAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Text,{mt:"lg",children:"Z Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"z_axis_data_key",control:a,render:({field:u})=>i(W,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"zAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:p(s.Button,{color:"blue",type:"submit",children:[i(D.DeviceFloppy,{size:20}),i(s.Text,{ml:"md",children:"Save"})]})})]})}):null}function Cc(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis_data_key:a,y_axis_data_key:o,z_axis_data_key:l,...u}=e;return{...u,x_axis_data_key:r(a),y_axis_data_key:r(o),z_axis_data_key:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class Sc extends ge{constructor(){super(...arguments);q(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:a}=n;return{...n,version:2,config:Cc(a,r)}})}}const _c={displayName:"Bar Chart (3D)",displayGroup:"ECharts-based charts",migrator:new Sc,name:"bar-3d",viewRender:bc,configRender:wc,createConfig(){return{version:2,config:x.cloneDeep(Sr)}}};class Ne extends y.Component{constructor(t){super(t),this.state={error:null}}componentDidCatch(t){this.setState({error:t})}render(){var t;if(this.state.error){const n=()=>{this.setState({error:null})};return p(s.Box,{children:[i(s.Text,{size:"xs",children:(t=this.state.error)==null?void 0:t.message}),i(s.Button,{variant:"subtle",size:"xs",mx:"auto",compact:!0,sx:{display:"block"},onClick:n,children:"Retry"})]})}return this.props.children}}const Ie={mantissa:0,output:"number",trimMantissa:!1,average:!1};function kc({value:e,onChange:t},n){const r=u=>{t({...e,output:u})},a=u=>{const c=u===0?!1:e.trimMantissa;t({...e,mantissa:u,trimMantissa:c})},o=u=>{t({...e,trimMantissa:u.currentTarget.checked})},l=u=>{t({...e,average:u.currentTarget.checked})};return p(s.Stack,{ref:n,children:[p(s.Group,{grow:!0,children:[i(s.Select,{label:"Format",data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:e.output,onChange:r,sx:{flexGrow:1}}),i(s.Switch,{label:p(s.Stack,{spacing:0,children:[i(s.Text,{children:"Average"}),i(s.Text,{size:12,color:"gray",children:"like 1.234k, 1.234m"})]}),checked:e.average,onChange:l,disabled:e.output!=="number",sx:{flexGrow:1},styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}}})]}),p(s.Group,{grow:!0,children:[i(s.NumberInput,{label:"Mantissa",defaultValue:0,min:0,step:1,max:4,value:e.mantissa,onChange:a}),i(s.Switch,{label:"Trim mantissa",checked:e.trimMantissa,onChange:o,disabled:e.mantissa===0,styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"}}})]}),p(s.Stack,{spacing:0,children:[i(s.Text,{weight:"bold",children:"Preview"}),i(Ne,{children:p(s.Group,{position:"apart",children:[p(s.Text,{size:12,color:"gray",children:["123456789 ",i(D.ArrowRight,{size:9})," ",Z(123456789).format(e)]}),p(s.Text,{size:12,color:"gray",children:["1234 ",i(D.ArrowRight,{size:9})," ",Z(1234).format(e)]}),p(s.Text,{size:12,color:"gray",children:["0.1234 ",i(D.ArrowRight,{size:9})," ",Z(.1234).format(e)]})]})})]})]})}const We=y.forwardRef(kc),Ue={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
55
|
+
`)},fs={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:Dc,configRender:Tc,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 Tc(e){return i(B,{})}function Dc(e){return i(s.Text,{children:"Click chart's series"})}const Ic=[{label:"Truncate",value:"truncate"},{label:"Break Line",value:"break"},{label:"Break Word",value:"breakAll"}],zn=y.forwardRef(({sectionTitle:e,value:t,onChange:n},r)=>{const a=o=>l=>{const u=x.cloneDeep(t);x.set(u,o,l),n(u)};return p(s.Stack,{spacing:0,children:[e&&i(s.Divider,{mb:-5,mt:5,variant:"dotted",label:e,labelPosition:"right",labelProps:{color:"dimmed"}}),p(s.Group,{grow:!0,noWrap:!0,children:[i(s.NumberInput,{label:"Max Width",hideControls:!0,value:t.width,onChange:a("width")}),i(s.Select,{label:"Overflow",data:Ic,value:t.overflow,onChange:a("overflow")}),i(s.TextInput,{label:"Ellipsis",value:t.ellipsis,disabled:!0})]})]})}),st=y.forwardRef(({value:e,onChange:t},n)=>{const r=o=>{t({...e,on_axis:o})},a=o=>{t({...e,in_tooltip:o})};return p(s.Stack,{ref:n,spacing:0,children:[i(zn,{sectionTitle:"Overflow on Axis",value:e.on_axis,onChange:r}),i(zn,{sectionTitle:"Overflow in Tooltip",value:e.in_tooltip,onChange:a})]})}),je={on_axis:{width:80,overflow:"truncate",ellipsis:"..."},in_tooltip:{width:200,overflow:"break",ellipsis:"..."}};function ot({overflow:e,width:t}){const n={truncate:"initial",break:"break-all",breakAll:"break-word"}[e],r=e==="truncate"?"nowrap":"initial",a={truncate:"ellipsis",break:"clip",breakAll:"clip"}[e];return`
|
|
56
56
|
max-width: ${t}px;
|
|
57
57
|
word-break: ${n};
|
|
58
58
|
white-space: ${r};
|
|
59
59
|
overflow: hidden;
|
|
60
60
|
text-overflow: ${a};
|
|
61
|
-
`}function it(e){return{width:e.width,overflow:e.overflow,ellipsis:e.ellipsis}}const Ar={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...Ue},overflow:je}},y_axis:{name:"Y Axis",data_key:"value",label_formatter:Ie},tooltip:{metrics:[]},color:"#228be6",reference_lines:[],legend:{show:!0,top:"10",right:"0",left:"auto",bottom:"auto",orient:"vertical",type:"scroll"}};function zt(e,t){return y.useMemo(()=>{const{queryID:n,columnKey:r}=O(t);return x.keyBy(e[n],r)},[e,t])}const Ke=(e,t)=>{const[n,r]=y.useState([]);return y.useEffect(()=>e.watchTriggerSnapshotList(a=>r(a.filter(o=>o.schemaRef===t))),[]),n};class Nt{constructor(t,n){this.root=t,this.path=n}async deleteItem(t){t===null&&await this.root.deleteItem(this.path);const n=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,x.omit(n,t))}async getItem(t){const n=await this.root.getItem(this.path);return t===null?n:x.get(n,t)}async setItem(t,n){if(t===null)await this.root.setItem(this.path,n);else{const r=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,{...r,[t]:n})}return await this.getItem(t)}watchItem(t,n,r){return t===null?this.root.watchItem(this.path,(a,o)=>{n(a,o)},r):this.root.watchItem(this.path,(a,o)=>{const l=x.get(a,t),u=x.get(o,t);l!==u&&n(l,u)},r)}}class zr{constructor(t,n,r){q(this,"attachmentStorage");this.instance=t,this.attachmentKey=n,this.constructInstance=r,this.attachmentStorage=new Nt(t.instanceData,n)}async getInstance(t){if(await this.attachmentStorage.getItem(t))return this.constructInstance(new Nt(this.attachmentStorage,t))}async create(t,n){return await this.attachmentStorage.setItem(t,n),this.constructInstance(new Nt(this.attachmentStorage,t))}async remove(t){await this.attachmentStorage.deleteItem(t)}async list(){const t=await this.attachmentStorage.getItem(null);return Promise.all(x.values(t).map(n=>this.constructInstance(new Nt(this.attachmentStorage,n.id))))}}function Dc(e,t){const{value:n,set:r}=R(e.operation.operationData,"config"),[a,o]=y.useState(x.defaults({},n,t)),l=async()=>{await r(a)};return y.useEffect(()=>{o(x.defaults({},n,t))},[n]),{config:a,setConfig:o,commit:l}}function Ic(e){const{config:t,setConfig:n,commit:r}=Dc(e,{urlTemplate:"",openInNewTab:!0});async function a(){await r()}async function o(u){n({...t,openInNewTab:u}),await r()}const l=u=>n({...t,urlTemplate:u.currentTarget.value});return p(s.Stack,{children:[i(s.TextInput,{label:"Url",value:t.urlTemplate,onChange:l,onBlur:a}),i(s.Switch,{label:"Open in new Tab",checked:t.openInNewTab,onChange:u=>o(u.currentTarget.checked)})]})}async function Mc(e,t){const{urlTemplate:n,openInNewTab:r}=await t.operationData.getItem("config");window.dispatchEvent(new CustomEvent("open-link",{detail:{urlTemplate:n,openInNewTab:r,payload:e}}))}class Ac extends ge{constructor(){super(...arguments);q(this,"VERSION",1)}configVersions(){this.version(1,n=>n)}}const zc={displayName:"Open Link",id:"builtin:op:open-link",configRender:Ic,run:Mc,migrator:new Ac,createDefaultConfig:()=>({version:1,config:{urlTemplate:"",openInNewTab:!0}})};function Ec(e){const{value:t,set:n}=R(e.operationData,"config"),r=a=>void n({template:a});return[(t==null?void 0:t.template)||"",r]}function $c(e){const[t,n]=Ec(e.operation);return i(s.TextInput,{defaultValue:t,onBlur:r=>n(r.currentTarget.value),label:"console.log"})}async function Lc(e,t){const n=await t.operationData.getItem("config"),r=x.template(n.template||"");console.log("run with payload",e),console.log(r(e))}const Oc={displayName:"console.log (debug)",id:"builtin:op:debug",configRender:$c,run:Lc},Pc=k.observer(e=>{const t=le(),{value:n,set:r}=R(e.operation.operationData,"config");console.log({value:n,viewID:n==null?void 0:n.viewID});const a=(n==null?void 0:n.viewID)||"",o=l=>void r({viewID:l});return i(s.Select,{defaultValue:a,value:a,onChange:o,label:"View",data:t.views.options,withinPortal:!0,zIndex:340,maxDropdownHeight:500})});async function Bc(e,t){const r=(await t.operationData.getItem("config")).viewID;window.dispatchEvent(new CustomEvent("open-view",{detail:{viewID:r}}))}const Vc={displayName:"Open View",id:"builtin:op:open_view",configRender:Pc,run:Bc},Nc={"tbody tr":{opacity:.5,transition:"opacity 200ms ease"},"tr[data-affected=true]":{opacity:1}},qc=({value:e="",onChange:t})=>{const[n,r]=y.useState(e);y.useEffect(()=>{r(e)},[e]);const a=()=>{t(n)};return i(s.TextInput,{size:"xs",label:"",value:n,onChange:o=>r(o.currentTarget.value),sx:{flexGrow:1},rightSection:i(s.ActionIcon,{color:"green",size:"xs",onClick:a,disabled:n===e,children:i(E.IconDeviceFloppy,{})})})},Fc={dictionary:{}},Gc=k.observer(e=>{const t=le(),{value:n=Fc,set:r}=R(e.operation.operationData,"config"),{dictionary:a={}}=n;console.log({value:{...n},dictionary:{...a},filters:[...t.filters.keyLabelOptions]});const o=(l,u)=>{if(u===""){const c={...a};delete c[l],r({dictionary:c});return}r({dictionary:{...a,[l]:u}})};return p(s.Table,{sx:Nc,children:[i("thead",{children:p("tr",{children:[i("th",{children:"Set filter"}),i("th",{children:"with"})]})}),i("tbody",{children:[...t.filters.keyLabelOptions].map(l=>{const u=l.value in a;return p("tr",{"data-affected":u,children:[i("td",{children:l.label}),i("td",{children:i(qc,{value:a[l.value],onChange:c=>o(l.value,c)})})]},l.value)})})]})});async function Wc(e,t){const r=(await t.operationData.getItem("config")).dictionary;window.dispatchEvent(new CustomEvent("set-filter-values",{detail:{dictionary:r,payload:e}}))}const jc={displayName:"Set Filter Values",id:"builtin:op:set_filter_values",configRender:Gc,run:Wc},Rc={filter_keys:[]},Yc=k.observer(e=>{const t=le(),{value:n=Rc,set:r}=R(e.operation.operationData,"config"),{filter_keys:a=[]}=n,o=u=>{r({filter_keys:[...u]})},l=y.useMemo(()=>t.filters.current.map(u=>({label:u.label,value:u.key})),[t.filters.values]);return i(s.Stack,{spacing:10,children:i(s.MultiSelect,{label:"Select Filters to Clear",data:l,value:a,onChange:o})})});async function Qc(e,t){const r=(await t.operationData.getItem("config")).filter_keys;window.dispatchEvent(new CustomEvent("clear-filter-values",{detail:{filter_keys:r,payload:e}}))}const En=[Oc,zc,Vc,jc,{displayName:"Clear Filter Values",id:"builtin:op:clear_filter_values",configRender:Yc,run:Qc}];class Uc{constructor(t,n=En){q(this,"attachments");this.operations=n;const r=async a=>{const{id:o,schemaRef:l}=await a.getItem(null);return{id:o,schemaRef:l,operationData:new Nt(a,"data")}};this.attachments=new zr(t,"__OPERATIONS",r)}async runOperation(t,n){const r=await this.attachments.getInstance(t);if(!r){console.warn(`Operation '${t}' is not defined`);return}const a=this.tryGetSchema(r.schemaRef);if(!a){console.warn(`Operation schema '${r.schemaRef}' is not defined`);return}await a.run(n,r)}tryGetSchema(t){return this.operations.find(n=>n.id===t)}async needMigration(){const n=(await this.attachments.list()).map(async r=>{const a={configData:r.operationData},o=this.tryGetSchema(r.schemaRef),l=o==null?void 0:o.migrator;return l&&await l.needMigration(a)});return(await Promise.all(n)).some(r=>r)}async runMigration(){const n=(await this.attachments.list()).map(async r=>{const a={configData:r.operationData},o=this.tryGetSchema(r.schemaRef),l=o==null?void 0:o.migrator;l&&await l.needMigration(a)&&await l.migrate(a)});await Promise.all(n)}async createOrGetOperation(t,n){var l;if(!this.getOperationSchemaList().some(u=>u.id===n.id))throw new Error(`Operation schema '${n.id}' is not defined`);const a=await this.attachments.getInstance(t);return!a||a.schemaRef!==n.id?await this.attachments.create(t,{id:t,schemaRef:n.id,data:((l=n.createDefaultConfig)==null?void 0:l.call(n))??{}}):a}getOperationList(){return this.attachments.list()}getOperationSchemaList(){return this.operations}removeOperation(t){return this.attachments.remove(t)}async retrieveTrigger(t){return await this.attachments.getInstance(t)}}const hs="__TRIGGERS";class Kc{constructor(t,n){q(this,"attachments");this.instance=t,this.component=n;const r=async a=>{const{id:o,schemaRef:l}=await a.getItem(null);return{id:o,schemaRef:l,triggerData:new Nt(a,"data")}};this.attachments=new zr(t,hs,r)}watchTriggerSnapshotList(t){return this.instance.instanceData.watchItem(hs,n=>{const r=x.values(n).map(a=>({id:x.get(a,"id"),schemaRef:x.get(a,"schemaRef"),config:te.toJS(x.get(a,"data.config"))}));t(r)},{fireImmediately:!0})}async createOrGetTrigger(t,n,r={recreate:!1}){var u;if(!this.getTriggerSchemaList().some(c=>c.id===n.id))throw new Error(`Trigger schema '${n.id}' is not defined in component '${this.component.name}'`);const o=await this.attachments.getInstance(t);return!o||r.recreate||o.schemaRef!==n.id?await this.attachments.create(t,{id:t,schemaRef:n.id,data:((u=n==null?void 0:n.createDefaultConfig)==null?void 0:u.call(n))||{}}):o}async getTriggerList(){return await this.attachments.list()}getTriggerSchemaList(){return this.component.triggers||[]}async removeTrigger(t){await this.attachments.remove(t)}async retrieveTrigger(t){return await this.attachments.getInstance(t)}async getMigrationTasks(){const n=(await this.getTriggerList()).map(async r=>{const a=this.getTriggerSchemaList().find(u=>u.id===r.schemaRef),o=a==null?void 0:a.migrator,l={configData:r.triggerData};return o&&await o.needMigration(l)?()=>o.migrate(l):null});return Promise.all(n).then(r=>r.filter(a=>a))}async needMigration(){return(await this.getMigrationTasks()).length>0}async runMigration(){const t=await this.getMigrationTasks();await Promise.all(t.map(n=>n()))}}class Er{constructor(t,n,r){q(this,"operationManager");q(this,"triggerManager");q(this,"attachments");this.operationManager=new Uc(t,r),this.triggerManager=new Kc(t,n);const a=async o=>{const{id:l,triggerRef:u,operationRef:c}=await o.getItem(null);return{id:l,triggerRef:u,operationRef:c}};this.attachments=new zr(t,"__INTERACTIONS",a)}async addInteraction(t,n){const r=t.id,a=n.id,o=`[${r}]:[${a}]`;await this.attachments.create(o,{id:o,triggerRef:r,operationRef:a})}getInteractionList(){return this.attachments.list()}async removeInteraction(t){const n=await this.attachments.getInstance(t);if(!n)return;const{triggerRef:r,operationRef:a}=n;await this.getTriggerRefCount(r)<=1&&await this.triggerManager.removeTrigger(r),await this.getOperationRefCount(a)<=1&&await this.operationManager.removeOperation(a),await this.attachments.remove(t)}async getOperationRefCount(t){return(await this.getInteractionList()).filter(r=>r.operationRef===t).length}async getTriggerRefCount(t){return(await this.getInteractionList()).filter(r=>r.triggerRef===t).length}async runInteraction(t,n){const a=(await this.getInteractionList()).filter(o=>o.triggerRef===t);await Promise.all(a.map(async o=>{try{return await this.operationManager.runOperation(o.operationRef,n)}catch(l){console.warn(`Failed to run operation '${o.operationRef}'`,l)}}))}}const Xe=({vizManager:e,instance:t})=>Q.useCreation(()=>new Er(t,e.resolveComponent(t.type),En),[t,e]),fs=e=>{const{title:t="Variables",variables:n}=e,r=ke.useClipboard(),a=o=>{r.copy(o),_n.showNotification({color:"green",message:"Copied to clipboard"})};return p(s.Paper,{withBorder:!0,p:"sm",children:[i(s.Text,{size:"xs",color:"dimmed",mb:"sm",children:t}),i(s.Stack,{style:{maxHeight:"500px"},children:n.map(o=>p(s.Text,{size:"sm",children:[p(s.Code,{color:"teal",children:["// ",o.description]}),i("br",{}),p(s.Code,{onClick:()=>a(o.name),style:{cursor:"pointer"},children:[o.name," : ",o.valueType]})]},o.name))})]})};class Xc{constructor(t,n){q(this,"operationId");q(this,"operation");q(this,"operationSchema");q(this,"variables",[]);this.operationManager=t,this.instance=n,te.makeAutoObservable(this)}get schemaList(){return this.operationManager.getOperationSchemaList()}async configOperation(t,n){const r=await this.operationManager.retrieveTrigger(t),a=this.operationManager.getOperationSchemaList().find(o=>o.id===(r==null?void 0:r.schemaRef));te.runInAction(()=>{this.operationId=t,this.operation=r,this.operationSchema=a,this.variables=n})}async changeSchema(t){this.operationId&&(await this.operationManager.createOrGetOperation(this.operationId,t),await this.configOperation(this.operationId,this.variables))}}function Jc(e){return!!e.operationId}const Zc=k.observer(({model:e,onClick:t})=>{var r;const n=(r=e.operationSchema)==null?void 0:r.displayName;return i(s.Button,{variant:"outline",onClick:t,children:n})}),Hc=k.observer(({model:e})=>{const t={operation:e.operation,instance:e.instance,variables:[]};return y.createElement(e.operationSchema.configRender,t)}),ed=k.observer(({model:e})=>{const t=e.schemaList,n=t.map(a=>({label:a.displayName,value:a.id}));async function r(a){await e.changeSchema(t.find(o=>o.id===a))}return i(s.Select,{label:"Operation",data:n,onChange:r,value:e.operationSchema.id,withinPortal:!0,zIndex:340})}),td=k.observer(e=>{const[t,{setTrue:n,setFalse:r}]=Q.useBoolean(!1),{operationManager:a,operationId:o,instance:l,variables:u}=e,c=Q.useCreation(()=>new Xc(a,l),[a,l]);return Q.useAsyncEffect(async()=>{await c.configOperation(o,u)},[o,c]),Jc(c)?p(B,{children:[i(Zc,{model:c,onClick:n}),i(s.Modal,{size:600,opened:t,onClose:r,title:"Operation Settings",zIndex:320,children:p(s.Stack,{children:[i(ed,{model:c}),p(s.Tabs,{defaultValue:"settings",children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"settings",children:"Settings"}),i(s.Tabs.Tab,{value:"variables",children:"Variables"})]}),i(s.Tabs.Panel,{value:"settings",pt:10,children:i(Hc,{model:c})}),i(s.Tabs.Panel,{value:"variables",pt:10,children:i(fs,{title:"Variables",variables:c.variables})})]})]})})]}):null});class nd{constructor(t,n){q(this,"triggerId");q(this,"trigger");q(this,"triggerSchema");q(this,"sampleData");this.triggerManager=t,this.instance=n,te.makeAutoObservable(this)}get schemaList(){return this.triggerManager.getTriggerSchemaList()}async configTrigger(t,n){const r=await this.triggerManager.retrieveTrigger(t),a=this.triggerManager.getTriggerSchemaList().find(o=>o.id===(r==null?void 0:r.schemaRef));te.runInAction(()=>{this.triggerId=t,this.trigger=r,this.triggerSchema=a,this.sampleData=n})}async changeSchema(t){this.triggerId&&(await this.triggerManager.createOrGetTrigger(this.triggerId,t),await this.configTrigger(this.triggerId,this.sampleData))}isReady(){return rd(this)}}function rd(e){return!!e.triggerId&&!!e.triggerSchema}function id(e,t){return Q.useCreation(()=>new nd(e,t),[e,t])}const ad=k.observer(({model:e,onClick:t})=>{const n=e.triggerSchema.nameRender,r={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return i(s.Button,{variant:"outline",onClick:t,children:y.createElement(n,r)})}),sd=k.observer(({model:e})=>{const t=e.schemaList,n=t.map(a=>({label:a.displayName,value:a.id}));async function r(a){await e.changeSchema(t.find(o=>o.id===a))}return i(s.Select,{label:"Trigger",data:n,value:e.triggerSchema.id,onChange:r})}),od=k.observer(({model:e})=>{const t={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return y.createElement(e.triggerSchema.configRender,t)}),ld=k.observer(e=>{const[t,{setTrue:n,setFalse:r}]=Q.useBoolean(!1),a=e.model;return p(B,{children:[i(s.Modal,{opened:t,onClose:r,title:"Setup Trigger",zIndex:320,children:p(s.Stack,{children:[i(sd,{model:a}),i(od,{model:a}),i(fs,{title:"Payload",variables:a.triggerSchema.payload})]})}),i(ad,{onClick:n,model:a})]})});function ud(e,t){const[n,r]=y.useState([]);return Q.useAsyncEffect(async()=>{const a=await e.getInteractionList();r(a)},[t,e]),n}const cd=k.observer(({item:e,manager:t,instance:n,sampleData:r,variables:a,onRemove:o})=>{const{triggerRef:l,operationRef:u}=e,c=id(t.triggerManager,n);if(Q.useAsyncEffect(async()=>{await c.configTrigger(l,r)},[c,l,r]),c.isReady()){const d=[...c.triggerSchema.payload,...a];return p(s.Group,{children:[i(ld,{model:c}),i(td,{instance:n,operationId:u,variables:d,operationManager:t.operationManager}),i(s.ActionIcon,{"aria-label":"delete-interaction",variant:"filled",color:"red",onClick:()=>o(e),children:i(D.Trash,{size:16})})]})}return null}),dd=e=>{const[t,n]=y.useState(0),{interactionManager:r,instance:a,sampleData:o,variables:l}=e,u=ud(r,t),c=async()=>{const g=await r.triggerManager.createOrGetTrigger(ke.randomId(),r.triggerManager.getTriggerSchemaList()[0]),m=await r.operationManager.createOrGetOperation(ke.randomId(),r.operationManager.getOperationSchemaList()[0]);await r.addInteraction(g,m),n(C=>C+1)};async function d(g){await r.removeInteraction(g.id),n(m=>m+1)}const{data:f=0,loading:h}=Q.useRequest(async()=>{try{return(await r.triggerManager.getTriggerSchemaList()).length}catch{return 0}});return p(s.Stack,{children:[i(s.LoadingOverlay,{visible:h}),f===0&&i(s.Alert,{icon:i(D.AlertCircle,{size:16}),title:"Unavailable",color:"gray",children:"This visualization does not have available interactions to choose from"}),u.map(g=>i(cd,{onRemove:d,instance:a,sampleData:o,variables:l,item:g,manager:e.interactionManager},g.id)),i(s.Button,{style:{width:"fit-content"},onClick:()=>c(),disabled:f===0,children:"Add interaction"})]})},pd=()=>{const{panel:e,data:t}=Ct(),n=e.viz,{vizManager:r}=y.useContext(ct),a=e.json,o=Q.useCreation(()=>r.getOrCreateInstance(a),[r,a]),l=Q.useCreation(()=>new Er(o,r.resolveComponent(n.type),En),[o,n.type]);return y.useEffect(()=>o.instanceData.watchItem(null,x.throttle(u=>{e.viz.setConf(u)},100,{leading:!1,trailing:!0})),[o]),{instance:o,vizManager:r,interactionManager:l,sampleData:t,variables:[]}},hd=()=>{const e=pd();return i(dd,{...e})};function qt({enabled:e,func_content:t}){return(n,r)=>{if(!e)return n;try{return new Function(`return ${t}`)()(n,r)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function fd(e,t){return Object.entries(e).map(([r,a])=>{const o=a.map(_=>_[t]).sort((_,T)=>_-T),l=en.quantile(o,.25)??0,u=en.quantile(o,.5)??0,c=en.quantile(o,.75)??0,d=c-l,f=l-1.5*d,h=c+1.5*d,g=Math.max(o[0],f),m=Math.min(x.last(o)??0,h),C=a.filter(_=>{const T=_[t];return T<g||T>m}).map(_=>[r,_[t],_]);return{name:r,min:g,q1:l,median:u,q3:c,max:m,outliers:C}})}function gd(e,t){const{x_axis:n,y_axis:r}=e;if(!n.data_key||!r.data_key)return[];const a=O(n.data_key),o=O(r.data_key);if(a.queryID!==o.queryID)throw new Error("Please use the same query for X & Y axis");const l=x.groupBy(t[a.queryID],a.columnKey),u=fd(l,o.columnKey),c=u.map(d=>d.outliers).flat();return[{source:u},{source:c}]}function md({config:e}){return{...e.legend,data:[{name:"Box",icon:"roundRect",itemStyle:{color:e.color}},{name:"Outlier",icon:"circle",itemStyle:{color:"#2F8CC0"}}]}}const $r=["max","q3","median","q1","min"];function yd(e){const{color:t}=e;return[{name:"Box",type:"boxplot",itemStyle:{color:t,borderColor:"#2F8CC0",borderWidth:2},emphasis:{disabled:!0},boxWidth:[10,40],datasetIndex:0,encode:{y:$r,x:"name",itemName:["name"],tooltip:$r}},{name:"Outlier",type:"scatter",symbolSize:5,itemStyle:{color:"#2F8CC0"},emphasis:{scale:2},datasetIndex:1}]}function bd(e){const{outliers:t,min:n,max:r}=e,a=t.filter(u=>u[1]<n).length,o=t.filter(u=>u[1]>r).length,l=(u,c)=>`
|
|
61
|
+
`}function it(e){return{width:e.width,overflow:e.overflow,ellipsis:e.ellipsis}}const Ar={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...Ue},overflow:je}},y_axis:{name:"Y Axis",data_key:"value",label_formatter:Ie},tooltip:{metrics:[]},color:"#228be6",reference_lines:[],legend:{show:!0,top:"10",right:"0",left:"auto",bottom:"auto",orient:"vertical",type:"scroll"}};function zt(e,t){return y.useMemo(()=>{const{queryID:n,columnKey:r}=O(t);return x.keyBy(e[n],r)},[e,t])}const Ke=(e,t)=>{const[n,r]=y.useState([]);return y.useEffect(()=>e.watchTriggerSnapshotList(a=>r(a.filter(o=>o.schemaRef===t))),[]),n};class Nt{constructor(t,n){this.root=t,this.path=n}async deleteItem(t){t===null&&await this.root.deleteItem(this.path);const n=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,x.omit(n,t))}async getItem(t){const n=await this.root.getItem(this.path);return t===null?n:x.get(n,t)}async setItem(t,n){if(t===null)await this.root.setItem(this.path,n);else{const r=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,{...r,[t]:n})}return await this.getItem(t)}watchItem(t,n,r){return t===null?this.root.watchItem(this.path,(a,o)=>{n(a,o)},r):this.root.watchItem(this.path,(a,o)=>{const l=x.get(a,t),u=x.get(o,t);l!==u&&n(l,u)},r)}}class zr{constructor(t,n,r){q(this,"attachmentStorage");this.instance=t,this.attachmentKey=n,this.constructInstance=r,this.attachmentStorage=new Nt(t.instanceData,n)}async getInstance(t){if(await this.attachmentStorage.getItem(t))return this.constructInstance(new Nt(this.attachmentStorage,t))}async create(t,n){return await this.attachmentStorage.setItem(t,n),this.constructInstance(new Nt(this.attachmentStorage,t))}async remove(t){await this.attachmentStorage.deleteItem(t)}async list(){const t=await this.attachmentStorage.getItem(null);return Promise.all(x.values(t).map(n=>this.constructInstance(new Nt(this.attachmentStorage,n.id))))}}function Mc(e,t){const{value:n,set:r}=R(e.operation.operationData,"config"),[a,o]=y.useState(x.defaults({},n,t)),l=async()=>{await r(a)};return y.useEffect(()=>{o(x.defaults({},n,t))},[n]),{config:a,setConfig:o,commit:l}}function Ac(e){const{config:t,setConfig:n,commit:r}=Mc(e,{urlTemplate:"",openInNewTab:!0});async function a(){await r()}async function o(u){n({...t,openInNewTab:u}),await r()}const l=u=>n({...t,urlTemplate:u.currentTarget.value});return p(s.Stack,{children:[i(s.TextInput,{label:"Url",value:t.urlTemplate,onChange:l,onBlur:a}),i(s.Switch,{label:"Open in new Tab",checked:t.openInNewTab,onChange:u=>o(u.currentTarget.checked)})]})}async function zc(e,t){const{urlTemplate:n,openInNewTab:r}=await t.operationData.getItem("config");window.dispatchEvent(new CustomEvent("open-link",{detail:{urlTemplate:n,openInNewTab:r,payload:e}}))}class Ec extends ge{constructor(){super(...arguments);q(this,"VERSION",1)}configVersions(){this.version(1,n=>n)}}const $c={displayName:"Open Link",id:"builtin:op:open-link",configRender:Ac,run:zc,migrator:new Ec,createDefaultConfig:()=>({version:1,config:{urlTemplate:"",openInNewTab:!0}})};function Lc(e){const{value:t,set:n}=R(e.operationData,"config"),r=a=>void n({template:a});return[(t==null?void 0:t.template)||"",r]}function Oc(e){const[t,n]=Lc(e.operation);return i(s.TextInput,{defaultValue:t,onBlur:r=>n(r.currentTarget.value),label:"console.log"})}async function Pc(e,t){const n=await t.operationData.getItem("config"),r=x.template(n.template||"");console.log("run with payload",e),console.log(r(e))}const Bc={displayName:"console.log (debug)",id:"builtin:op:debug",configRender:Oc,run:Pc},Vc=k.observer(e=>{const t=le(),{value:n,set:r}=R(e.operation.operationData,"config");console.log({value:n,viewID:n==null?void 0:n.viewID});const a=(n==null?void 0:n.viewID)||"",o=l=>void r({viewID:l});return i(s.Select,{defaultValue:a,value:a,onChange:o,label:"View",data:t.views.options,withinPortal:!0,zIndex:340,maxDropdownHeight:500})});async function Nc(e,t){const r=(await t.operationData.getItem("config")).viewID;window.dispatchEvent(new CustomEvent("open-view",{detail:{viewID:r}}))}const qc={displayName:"Open View",id:"builtin:op:open_view",configRender:Vc,run:Nc},Fc={"tbody tr":{opacity:.5,transition:"opacity 200ms ease"},"tr[data-affected=true]":{opacity:1}},Gc=({value:e="",onChange:t})=>{const[n,r]=y.useState(e);y.useEffect(()=>{r(e)},[e]);const a=()=>{t(n)};return i(s.TextInput,{size:"xs",label:"",value:n,onChange:o=>r(o.currentTarget.value),sx:{flexGrow:1},rightSection:i(s.ActionIcon,{color:"green",size:"xs",onClick:a,disabled:n===e,children:i(E.IconDeviceFloppy,{})})})},Wc={dictionary:{}},jc=k.observer(e=>{const t=le(),{value:n=Wc,set:r}=R(e.operation.operationData,"config"),{dictionary:a={}}=n;console.log({value:{...n},dictionary:{...a},filters:[...t.filters.keyLabelOptions]});const o=(l,u)=>{if(u===""){const c={...a};delete c[l],r({dictionary:c});return}r({dictionary:{...a,[l]:u}})};return p(s.Table,{sx:Fc,children:[i("thead",{children:p("tr",{children:[i("th",{children:"Set filter"}),i("th",{children:"with"})]})}),i("tbody",{children:[...t.filters.keyLabelOptions].map(l=>{const u=l.value in a;return p("tr",{"data-affected":u,children:[i("td",{children:l.label}),i("td",{children:i(Gc,{value:a[l.value],onChange:c=>o(l.value,c)})})]},l.value)})})]})});async function Rc(e,t){const r=(await t.operationData.getItem("config")).dictionary;window.dispatchEvent(new CustomEvent("set-filter-values",{detail:{dictionary:r,payload:e}}))}const Yc={displayName:"Set Filter Values",id:"builtin:op:set_filter_values",configRender:jc,run:Rc},Qc={filter_keys:[]},Uc=k.observer(e=>{const t=le(),{value:n=Qc,set:r}=R(e.operation.operationData,"config"),{filter_keys:a=[]}=n,o=u=>{r({filter_keys:[...u]})},l=y.useMemo(()=>t.filters.current.map(u=>({label:u.label,value:u.key})),[t.filters.values]);return i(s.Stack,{spacing:10,children:i(s.MultiSelect,{label:"Select Filters to Clear",data:l,value:a,onChange:o})})});async function Kc(e,t){const r=(await t.operationData.getItem("config")).filter_keys;window.dispatchEvent(new CustomEvent("clear-filter-values",{detail:{filter_keys:r,payload:e}}))}const En=[Bc,$c,qc,Yc,{displayName:"Clear Filter Values",id:"builtin:op:clear_filter_values",configRender:Uc,run:Kc}];class Xc{constructor(t,n=En){q(this,"attachments");this.operations=n;const r=async a=>{const{id:o,schemaRef:l}=await a.getItem(null);return{id:o,schemaRef:l,operationData:new Nt(a,"data")}};this.attachments=new zr(t,"__OPERATIONS",r)}async runOperation(t,n){const r=await this.attachments.getInstance(t);if(!r){console.warn(`Operation '${t}' is not defined`);return}const a=this.tryGetSchema(r.schemaRef);if(!a){console.warn(`Operation schema '${r.schemaRef}' is not defined`);return}await a.run(n,r)}tryGetSchema(t){return this.operations.find(n=>n.id===t)}async needMigration(){const n=(await this.attachments.list()).map(async r=>{const a={configData:r.operationData},o=this.tryGetSchema(r.schemaRef),l=o==null?void 0:o.migrator;return l&&await l.needMigration(a)});return(await Promise.all(n)).some(r=>r)}async runMigration(){const n=(await this.attachments.list()).map(async r=>{const a={configData:r.operationData},o=this.tryGetSchema(r.schemaRef),l=o==null?void 0:o.migrator;l&&await l.needMigration(a)&&await l.migrate(a)});await Promise.all(n)}async createOrGetOperation(t,n){var l;if(!this.getOperationSchemaList().some(u=>u.id===n.id))throw new Error(`Operation schema '${n.id}' is not defined`);const a=await this.attachments.getInstance(t);return!a||a.schemaRef!==n.id?await this.attachments.create(t,{id:t,schemaRef:n.id,data:((l=n.createDefaultConfig)==null?void 0:l.call(n))??{}}):a}getOperationList(){return this.attachments.list()}getOperationSchemaList(){return this.operations}removeOperation(t){return this.attachments.remove(t)}async retrieveTrigger(t){return await this.attachments.getInstance(t)}}const gs="__TRIGGERS";class Jc{constructor(t,n){q(this,"attachments");this.instance=t,this.component=n;const r=async a=>{const{id:o,schemaRef:l}=await a.getItem(null);return{id:o,schemaRef:l,triggerData:new Nt(a,"data")}};this.attachments=new zr(t,gs,r)}watchTriggerSnapshotList(t){return this.instance.instanceData.watchItem(gs,n=>{const r=x.values(n).map(a=>({id:x.get(a,"id"),schemaRef:x.get(a,"schemaRef"),config:te.toJS(x.get(a,"data.config"))}));t(r)},{fireImmediately:!0})}async createOrGetTrigger(t,n,r={recreate:!1}){var u;if(!this.getTriggerSchemaList().some(c=>c.id===n.id))throw new Error(`Trigger schema '${n.id}' is not defined in component '${this.component.name}'`);const o=await this.attachments.getInstance(t);return!o||r.recreate||o.schemaRef!==n.id?await this.attachments.create(t,{id:t,schemaRef:n.id,data:((u=n==null?void 0:n.createDefaultConfig)==null?void 0:u.call(n))||{}}):o}async getTriggerList(){return await this.attachments.list()}getTriggerSchemaList(){return this.component.triggers||[]}async removeTrigger(t){await this.attachments.remove(t)}async retrieveTrigger(t){return await this.attachments.getInstance(t)}async getMigrationTasks(){const n=(await this.getTriggerList()).map(async r=>{const a=this.getTriggerSchemaList().find(u=>u.id===r.schemaRef),o=a==null?void 0:a.migrator,l={configData:r.triggerData};return o&&await o.needMigration(l)?()=>o.migrate(l):null});return Promise.all(n).then(r=>r.filter(a=>a))}async needMigration(){return(await this.getMigrationTasks()).length>0}async runMigration(){const t=await this.getMigrationTasks();await Promise.all(t.map(n=>n()))}}class Er{constructor(t,n,r){q(this,"operationManager");q(this,"triggerManager");q(this,"attachments");this.operationManager=new Xc(t,r),this.triggerManager=new Jc(t,n);const a=async o=>{const{id:l,triggerRef:u,operationRef:c}=await o.getItem(null);return{id:l,triggerRef:u,operationRef:c}};this.attachments=new zr(t,"__INTERACTIONS",a)}async addInteraction(t,n){const r=t.id,a=n.id,o=`[${r}]:[${a}]`;await this.attachments.create(o,{id:o,triggerRef:r,operationRef:a})}getInteractionList(){return this.attachments.list()}async removeInteraction(t){const n=await this.attachments.getInstance(t);if(!n)return;const{triggerRef:r,operationRef:a}=n;await this.getTriggerRefCount(r)<=1&&await this.triggerManager.removeTrigger(r),await this.getOperationRefCount(a)<=1&&await this.operationManager.removeOperation(a),await this.attachments.remove(t)}async getOperationRefCount(t){return(await this.getInteractionList()).filter(r=>r.operationRef===t).length}async getTriggerRefCount(t){return(await this.getInteractionList()).filter(r=>r.triggerRef===t).length}async runInteraction(t,n){const a=(await this.getInteractionList()).filter(o=>o.triggerRef===t);await Promise.all(a.map(async o=>{try{return await this.operationManager.runOperation(o.operationRef,n)}catch(l){console.warn(`Failed to run operation '${o.operationRef}'`,l)}}))}}const Xe=({vizManager:e,instance:t})=>Q.useCreation(()=>new Er(t,e.resolveComponent(t.type),En),[t,e]),ms=e=>{const{title:t="Variables",variables:n}=e,r=ke.useClipboard(),a=o=>{r.copy(o),_n.showNotification({color:"green",message:"Copied to clipboard"})};return p(s.Paper,{withBorder:!0,p:"sm",children:[i(s.Text,{size:"xs",color:"dimmed",mb:"sm",children:t}),i(s.Stack,{style:{maxHeight:"500px"},children:n.map(o=>p(s.Text,{size:"sm",children:[p(s.Code,{color:"teal",children:["// ",o.description]}),i("br",{}),p(s.Code,{onClick:()=>a(o.name),style:{cursor:"pointer"},children:[o.name," : ",o.valueType]})]},o.name))})]})};class Zc{constructor(t,n){q(this,"operationId");q(this,"operation");q(this,"operationSchema");q(this,"variables",[]);this.operationManager=t,this.instance=n,te.makeAutoObservable(this)}get schemaList(){return this.operationManager.getOperationSchemaList()}async configOperation(t,n){const r=await this.operationManager.retrieveTrigger(t),a=this.operationManager.getOperationSchemaList().find(o=>o.id===(r==null?void 0:r.schemaRef));te.runInAction(()=>{this.operationId=t,this.operation=r,this.operationSchema=a,this.variables=n})}async changeSchema(t){this.operationId&&(await this.operationManager.createOrGetOperation(this.operationId,t),await this.configOperation(this.operationId,this.variables))}}function Hc(e){return!!e.operationId}const ed=k.observer(({model:e,onClick:t})=>{var r;const n=(r=e.operationSchema)==null?void 0:r.displayName;return i(s.Button,{variant:"outline",onClick:t,children:n})}),td=k.observer(({model:e})=>{const t={operation:e.operation,instance:e.instance,variables:[]};return y.createElement(e.operationSchema.configRender,t)}),nd=k.observer(({model:e})=>{const t=e.schemaList,n=t.map(a=>({label:a.displayName,value:a.id}));async function r(a){await e.changeSchema(t.find(o=>o.id===a))}return i(s.Select,{label:"Operation",data:n,onChange:r,value:e.operationSchema.id,withinPortal:!0,zIndex:340})}),rd=k.observer(e=>{const[t,{setTrue:n,setFalse:r}]=Q.useBoolean(!1),{operationManager:a,operationId:o,instance:l,variables:u}=e,c=Q.useCreation(()=>new Zc(a,l),[a,l]);return Q.useAsyncEffect(async()=>{await c.configOperation(o,u)},[o,c]),Hc(c)?p(B,{children:[i(ed,{model:c,onClick:n}),i(s.Modal,{size:600,opened:t,onClose:r,title:"Operation Settings",zIndex:320,children:p(s.Stack,{children:[i(nd,{model:c}),p(s.Tabs,{defaultValue:"settings",children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"settings",children:"Settings"}),i(s.Tabs.Tab,{value:"variables",children:"Variables"})]}),i(s.Tabs.Panel,{value:"settings",pt:10,children:i(td,{model:c})}),i(s.Tabs.Panel,{value:"variables",pt:10,children:i(ms,{title:"Variables",variables:c.variables})})]})]})})]}):null});class id{constructor(t,n){q(this,"triggerId");q(this,"trigger");q(this,"triggerSchema");q(this,"sampleData");this.triggerManager=t,this.instance=n,te.makeAutoObservable(this)}get schemaList(){return this.triggerManager.getTriggerSchemaList()}async configTrigger(t,n){const r=await this.triggerManager.retrieveTrigger(t),a=this.triggerManager.getTriggerSchemaList().find(o=>o.id===(r==null?void 0:r.schemaRef));te.runInAction(()=>{this.triggerId=t,this.trigger=r,this.triggerSchema=a,this.sampleData=n})}async changeSchema(t){this.triggerId&&(await this.triggerManager.createOrGetTrigger(this.triggerId,t),await this.configTrigger(this.triggerId,this.sampleData))}isReady(){return ad(this)}}function ad(e){return!!e.triggerId&&!!e.triggerSchema}function sd(e,t){return Q.useCreation(()=>new id(e,t),[e,t])}const od=k.observer(({model:e,onClick:t})=>{const n=e.triggerSchema.nameRender,r={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return i(s.Button,{variant:"outline",onClick:t,children:y.createElement(n,r)})}),ld=k.observer(({model:e})=>{const t=e.schemaList,n=t.map(a=>({label:a.displayName,value:a.id}));async function r(a){await e.changeSchema(t.find(o=>o.id===a))}return i(s.Select,{label:"Trigger",data:n,value:e.triggerSchema.id,onChange:r})}),ud=k.observer(({model:e})=>{const t={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return y.createElement(e.triggerSchema.configRender,t)}),cd=k.observer(e=>{const[t,{setTrue:n,setFalse:r}]=Q.useBoolean(!1),a=e.model;return p(B,{children:[i(s.Modal,{opened:t,onClose:r,title:"Setup Trigger",zIndex:320,children:p(s.Stack,{children:[i(ld,{model:a}),i(ud,{model:a}),i(ms,{title:"Payload",variables:a.triggerSchema.payload})]})}),i(od,{onClick:n,model:a})]})});function dd(e,t){const[n,r]=y.useState([]);return Q.useAsyncEffect(async()=>{const a=await e.getInteractionList();r(a)},[t,e]),n}const pd=k.observer(({item:e,manager:t,instance:n,sampleData:r,variables:a,onRemove:o})=>{const{triggerRef:l,operationRef:u}=e,c=sd(t.triggerManager,n);if(Q.useAsyncEffect(async()=>{await c.configTrigger(l,r)},[c,l,r]),c.isReady()){const d=[...c.triggerSchema.payload,...a];return p(s.Group,{children:[i(cd,{model:c}),i(rd,{instance:n,operationId:u,variables:d,operationManager:t.operationManager}),i(s.ActionIcon,{"aria-label":"delete-interaction",variant:"filled",color:"red",onClick:()=>o(e),children:i(D.Trash,{size:16})})]})}return null}),hd=e=>{const[t,n]=y.useState(0),{interactionManager:r,instance:a,sampleData:o,variables:l}=e,u=dd(r,t),c=async()=>{const g=await r.triggerManager.createOrGetTrigger(ke.randomId(),r.triggerManager.getTriggerSchemaList()[0]),m=await r.operationManager.createOrGetOperation(ke.randomId(),r.operationManager.getOperationSchemaList()[0]);await r.addInteraction(g,m),n(C=>C+1)};async function d(g){await r.removeInteraction(g.id),n(m=>m+1)}const{data:f=0,loading:h}=Q.useRequest(async()=>{try{return(await r.triggerManager.getTriggerSchemaList()).length}catch{return 0}});return p(s.Stack,{children:[i(s.LoadingOverlay,{visible:h}),f===0&&i(s.Alert,{icon:i(D.AlertCircle,{size:16}),title:"Unavailable",color:"gray",children:"This visualization does not have available interactions to choose from"}),u.map(g=>i(pd,{onRemove:d,instance:a,sampleData:o,variables:l,item:g,manager:e.interactionManager},g.id)),i(s.Button,{style:{width:"fit-content"},onClick:()=>c(),disabled:f===0,children:"Add interaction"})]})},fd=()=>{const{panel:e,data:t}=Ct(),n=e.viz,{vizManager:r}=y.useContext(ct),a=e.json,o=Q.useCreation(()=>r.getOrCreateInstance(a),[r,a]),l=Q.useCreation(()=>new Er(o,r.resolveComponent(n.type),En),[o,n.type]);return y.useEffect(()=>o.instanceData.watchItem(null,x.throttle(u=>{e.viz.setConf(u)},100,{leading:!1,trailing:!0})),[o]),{instance:o,vizManager:r,interactionManager:l,sampleData:t,variables:[]}},gd=()=>{const e=fd();return i(hd,{...e})};function qt({enabled:e,func_content:t}){return(n,r)=>{if(!e)return n;try{return new Function(`return ${t}`)()(n,r)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function md(e,t){return Object.entries(e).map(([r,a])=>{const o=a.map(_=>_[t]).sort((_,T)=>_-T),l=en.quantile(o,.25)??0,u=en.quantile(o,.5)??0,c=en.quantile(o,.75)??0,d=c-l,f=l-1.5*d,h=c+1.5*d,g=Math.max(o[0],f),m=Math.min(x.last(o)??0,h),C=a.filter(_=>{const T=_[t];return T<g||T>m}).map(_=>[r,_[t],_]);return{name:r,min:g,q1:l,median:u,q3:c,max:m,outliers:C}})}function yd(e,t){const{x_axis:n,y_axis:r}=e;if(!n.data_key||!r.data_key)return[];const a=O(n.data_key),o=O(r.data_key);if(a.queryID!==o.queryID)throw new Error("Please use the same query for X & Y axis");const l=x.groupBy(t[a.queryID],a.columnKey),u=md(l,o.columnKey),c=u.map(d=>d.outliers).flat();return[{source:u},{source:c}]}function bd({config:e}){return{...e.legend,data:[{name:"Box",icon:"roundRect",itemStyle:{color:e.color}},{name:"Outlier",icon:"circle",itemStyle:{color:"#2F8CC0"}}]}}const $r=["max","q3","median","q1","min"];function vd(e){const{color:t}=e;return[{name:"Box",type:"boxplot",itemStyle:{color:t,borderColor:"#2F8CC0",borderWidth:2},emphasis:{disabled:!0},boxWidth:[10,40],datasetIndex:0,encode:{y:$r,x:"name",itemName:["name"],tooltip:$r}},{name:"Outlier",type:"scatter",symbolSize:5,itemStyle:{color:"#2F8CC0"},emphasis:{scale:2},datasetIndex:1}]}function xd(e){const{outliers:t,min:n,max:r}=e,a=t.filter(u=>u[1]<n).length,o=t.filter(u=>u[1]>r).length,l=(u,c)=>`
|
|
62
62
|
<tr>
|
|
63
63
|
<th style="text-align: right; padding: 0 1em;">${u}</th>
|
|
64
64
|
<td style="text-align: left; padding: 0 1em;">
|
|
65
65
|
${c}
|
|
66
66
|
</td>
|
|
67
67
|
</tr>
|
|
68
|
-
`;return{greater:l("Outliers ⬆",o),less:l("Outliers ⬇",a)}}const
|
|
68
|
+
`;return{greater:l("Outliers ⬆",o),less:l("Outliers ⬇",a)}}const wd=(e,t)=>{const n=$r.map(l=>`
|
|
69
69
|
<tr>
|
|
70
70
|
<th style="text-align: right; padding: 0 1em;">${x.capitalize(l)}</th>
|
|
71
71
|
<td style="text-align: left; padding: 0 1em;">
|
|
72
72
|
${Z(t[l]).format(e.y_axis.label_formatter)}
|
|
73
73
|
</td>
|
|
74
|
-
</tr>`),r=
|
|
74
|
+
</tr>`),r=xd(t);return n.unshift(r.greater),n.push(r.less),`
|
|
75
75
|
<div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
|
|
76
76
|
<div style="${ot(e.x_axis.axisLabel.overflow.in_tooltip)}">${t.name}</div>
|
|
77
77
|
</div>
|
|
@@ -80,14 +80,14 @@ Check the top-level render call using <`+V+">.")}return z}}function Tu(S,z){{if(
|
|
|
80
80
|
${n.join("")}
|
|
81
81
|
</tbody>
|
|
82
82
|
</table>
|
|
83
|
-
`},
|
|
83
|
+
`},Cd=e=>{try{return Z(e).format({trimMantissa:!0,mantissa:2})}catch{return e}};function Sd(e,t){const n=ot(e.x_axis.axisLabel.overflow.in_tooltip),r=[`<tr>
|
|
84
84
|
<th style="text-align: right; padding: 0 1em;">Outlier</th>
|
|
85
85
|
<td style="text-align: left; padding: 0 1em;">${t[1]}</td>
|
|
86
86
|
</tr>
|
|
87
87
|
`],a=e.tooltip.metrics.map(l=>{const u=O(l.data_key);return`
|
|
88
88
|
<tr>
|
|
89
89
|
<th style="text-align: right; padding: 0 1em;">${l.name}</th>
|
|
90
|
-
<td style="text-align: left; padding: 0 1em;">${
|
|
90
|
+
<td style="text-align: left; padding: 0 1em;">${Cd(t[2][u.columnKey])}</td>
|
|
91
91
|
</tr>`});return r.push(...a),`
|
|
92
92
|
<div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
|
|
93
93
|
<div style="${n}">${t[0]}</div>
|
|
@@ -97,19 +97,19 @@ Check the top-level render call using <`+V+">.")}return z}}function Tu(S,z){{if(
|
|
|
97
97
|
${r.join("")}
|
|
98
98
|
</tbody>
|
|
99
99
|
</table>
|
|
100
|
-
`}const Cd=e=>t=>{const{componentSubType:n,value:r}=t;return n==="scatter"?wd(e,r):vd(e,r)};function Sd({config:e}){return{trigger:"item",confine:!0,formatter:Cd(e)}}const on=y.forwardRef(function({value:t,onChange:n,...r},a){return i(s.TextInput,{ref:a,value:t,onChange:n,...r})}),Lr={fontSize:"14px",lineHeight:"32px",color:"#3D3E45",ul:{paddingLeft:"2em",margin:"6px 0 0"},p:{margin:0},a:{WebkitTapHighlightColor:"transparent",color:"rgb(34, 139, 230)",textDecoration:"none","&:hover":{textDecoration:"underline"},"&:active, &:hover":{outlineWidth:0}},table:{tr:{"th, td":{padding:"0 .5em"}}},"table.rich-text-table-render, div.tableWrapper table":{"th, td":{border:"1px solid #eaeaea"},"tr:last-of-type td":{borderBottom:"1px solid #eaeaea"}},".resize-cursor":{cursor:"col-resize"},details:{summary:{listStyle:"none",cursor:"pointer",transition:"color 300ms ease",userSelect:"none"},"summary::-webkit-details-marker":{display:"none"},"summary:hover":{color:"black","&::before":{opacity:1}},"summary::before":{content:'"►"',fontSize:"10px",margin:"0px 5px",opacity:.5,display:"inline-block",transition:"opacity 300ms ease, transform 300ms ease"}},"details[open] summary::before":{transform:"rotate(90deg)"},"details + details":{marginTop:"10px"},blockquote:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45",margin:"0 0 14px"}};function gs(e,t,n){for(let r=0;;r++){if(r==e.childCount||r==t.childCount)return e.childCount==t.childCount?null:n;let a=e.child(r),o=t.child(r);if(a==o){n+=a.nodeSize;continue}if(!a.sameMarkup(o))return n;if(a.isText&&a.text!=o.text){for(let l=0;a.text[l]==o.text[l];l++)n++;return n}if(a.content.size||o.content.size){let l=gs(a.content,o.content,n+1);if(l!=null)return l}n+=a.nodeSize}}function ms(e,t,n,r){for(let a=e.childCount,o=t.childCount;;){if(a==0||o==0)return a==o?null:{a:n,b:r};let l=e.child(--a),u=t.child(--o),c=l.nodeSize;if(l==u){n-=c,r-=c;continue}if(!l.sameMarkup(u))return{a:n,b:r};if(l.isText&&l.text!=u.text){let d=0,f=Math.min(l.text.length,u.text.length);for(;d<f&&l.text[l.text.length-d-1]==u.text[u.text.length-d-1];)d++,n--,r--;return{a:n,b:r}}if(l.content.size||u.content.size){let d=ms(l.content,u.content,n-1,r-1);if(d)return d}n-=c,r-=c}}class ae{constructor(t,n){if(this.content=t,this.size=n||0,n==null)for(let r=0;r<t.length;r++)this.size+=t[r].nodeSize}nodesBetween(t,n,r,a=0,o){for(let l=0,u=0;u<n;l++){let c=this.content[l],d=u+c.nodeSize;if(d>t&&r(c,a+u,o||null,l)!==!1&&c.content.size){let f=u+1;c.nodesBetween(Math.max(0,t-f),Math.min(c.content.size,n-f),r,a+f)}u=d}}descendants(t){this.nodesBetween(0,this.size,t)}textBetween(t,n,r,a){let o="",l=!0;return this.nodesBetween(t,n,(u,c)=>{u.isText?(o+=u.text.slice(Math.max(t,c)-c,n-c),l=!r):u.isLeaf?(a?o+=typeof a=="function"?a(u):a:u.type.spec.leafText&&(o+=u.type.spec.leafText(u)),l=!r):!l&&u.isBlock&&(o+=r,l=!0)},0),o}append(t){if(!t.size)return this;if(!this.size)return t;let n=this.lastChild,r=t.firstChild,a=this.content.slice(),o=0;for(n.isText&&n.sameMarkup(r)&&(a[a.length-1]=n.withText(n.text+r.text),o=1);o<t.content.length;o++)a.push(t.content[o]);return new ae(a,this.size+t.size)}cut(t,n=this.size){if(t==0&&n==this.size)return this;let r=[],a=0;if(n>t)for(let o=0,l=0;l<n;o++){let u=this.content[o],c=l+u.nodeSize;c>t&&((l<t||c>n)&&(u.isText?u=u.cut(Math.max(0,t-l),Math.min(u.text.length,n-l)):u=u.cut(Math.max(0,t-l-1),Math.min(u.content.size,n-l-1))),r.push(u),a+=u.nodeSize),l=c}return new ae(r,a)}cutByIndex(t,n){return t==n?ae.empty:t==0&&n==this.content.length?this:new ae(this.content.slice(t,n))}replaceChild(t,n){let r=this.content[t];if(r==n)return this;let a=this.content.slice(),o=this.size+n.nodeSize-r.nodeSize;return a[t]=n,new ae(a,o)}addToStart(t){return new ae([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new ae(this.content.concat(t),this.size+t.nodeSize)}eq(t){if(this.content.length!=t.content.length)return!1;for(let n=0;n<this.content.length;n++)if(!this.content[n].eq(t.content[n]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(t){let n=this.content[t];if(!n)throw new RangeError("Index "+t+" out of range for "+this);return n}maybeChild(t){return this.content[t]||null}forEach(t){for(let n=0,r=0;n<this.content.length;n++){let a=this.content[n];t(a,r,n),r+=a.nodeSize}}findDiffStart(t,n=0){return gs(this,t,n)}findDiffEnd(t,n=this.size,r=t.size){return ms(this,t,n,r)}findIndex(t,n=-1){if(t==0)return $n(0,t);if(t==this.size)return $n(this.content.length,t);if(t>this.size||t<0)throw new RangeError(`Position ${t} outside of fragment (${this})`);for(let r=0,a=0;;r++){let o=this.child(r),l=a+o.nodeSize;if(l>=t)return l==t||n>0?$n(r+1,l):$n(r,a);a=l}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(t=>t.toJSON()):null}static fromJSON(t,n){if(!n)return ae.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new ae(n.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return ae.empty;let n,r=0;for(let a=0;a<t.length;a++){let o=t[a];r+=o.nodeSize,a&&o.isText&&t[a-1].sameMarkup(o)?(n||(n=t.slice(0,a)),n[n.length-1]=o.withText(n[n.length-1].text+o.text)):n&&n.push(o)}return new ae(n||t,r)}static from(t){if(!t)return ae.empty;if(t instanceof ae)return t;if(Array.isArray(t))return this.fromArray(t);if(t.attrs)return new ae([t],t.nodeSize);throw new RangeError("Can not convert "+t+" to a Fragment"+(t.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}ae.empty=new ae([],0);const Or={index:0,offset:0};function $n(e,t){return Or.index=e,Or.offset=t,Or}function Pr(e,t){if(e===t)return!0;if(!(e&&typeof e=="object")||!(t&&typeof t=="object"))return!1;let n=Array.isArray(e);if(Array.isArray(t)!=n)return!1;if(n){if(e.length!=t.length)return!1;for(let r=0;r<e.length;r++)if(!Pr(e[r],t[r]))return!1}else{for(let r in e)if(!(r in t)||!Pr(e[r],t[r]))return!1;for(let r in t)if(!(r in e))return!1}return!0}class Re{constructor(t,n){this.type=t,this.attrs=n}addToSet(t){let n,r=!1;for(let a=0;a<t.length;a++){let o=t[a];if(this.eq(o))return t;if(this.type.excludes(o.type))n||(n=t.slice(0,a));else{if(o.type.excludes(this.type))return t;!r&&o.type.rank>this.type.rank&&(n||(n=t.slice(0,a)),n.push(this),r=!0),n&&n.push(o)}}return n||(n=t.slice()),r||n.push(this),n}removeFromSet(t){for(let n=0;n<t.length;n++)if(this.eq(t[n]))return t.slice(0,n).concat(t.slice(n+1));return t}isInSet(t){for(let n=0;n<t.length;n++)if(this.eq(t[n]))return!0;return!1}eq(t){return this==t||this.type==t.type&&Pr(this.attrs,t.attrs)}toJSON(){let t={type:this.type.name};for(let n in this.attrs){t.attrs=this.attrs;break}return t}static fromJSON(t,n){if(!n)throw new RangeError("Invalid input for Mark.fromJSON");let r=t.marks[n.type];if(!r)throw new RangeError(`There is no mark type ${n.type} in this schema`);return r.create(n.attrs)}static sameSet(t,n){if(t==n)return!0;if(t.length!=n.length)return!1;for(let r=0;r<t.length;r++)if(!t[r].eq(n[r]))return!1;return!0}static setFrom(t){if(!t||Array.isArray(t)&&t.length==0)return Re.none;if(t instanceof Re)return[t];let n=t.slice();return n.sort((r,a)=>r.type.rank-a.type.rank),n}}Re.none=[];class _d extends Error{}class ce{constructor(t,n,r){this.content=t,this.openStart=n,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,n){let r=bs(this.content,t+this.openStart,n);return r&&new ce(r,this.openStart,this.openEnd)}removeBetween(t,n){return new ce(ys(this.content,t+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(t){return this.content.eq(t.content)&&this.openStart==t.openStart&&this.openEnd==t.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let t={content:this.content.toJSON()};return this.openStart>0&&(t.openStart=this.openStart),this.openEnd>0&&(t.openEnd=this.openEnd),t}static fromJSON(t,n){if(!n)return ce.empty;let r=n.openStart||0,a=n.openEnd||0;if(typeof r!="number"||typeof a!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new ce(ae.fromJSON(t,n.content),r,a)}static maxOpen(t,n=!0){let r=0,a=0;for(let o=t.firstChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=t.lastChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.lastChild)a++;return new ce(t,r,a)}}ce.empty=new ce(ae.empty,0,0);function ys(e,t,n){let{index:r,offset:a}=e.findIndex(t),o=e.maybeChild(r),{index:l,offset:u}=e.findIndex(n);if(a==t||o.isText){if(u!=n&&!e.child(l).isText)throw new RangeError("Removing non-flat range");return e.cut(0,t).append(e.cut(n))}if(r!=l)throw new RangeError("Removing non-flat range");return e.replaceChild(r,o.copy(ys(o.content,t-a-1,n-a-1)))}function bs(e,t,n,r){let{index:a,offset:o}=e.findIndex(t),l=e.maybeChild(a);if(o==t||l.isText)return r&&!r.canReplace(a,a,n)?null:e.cut(0,t).append(n).append(e.cut(t));let u=bs(l.content,t-o-1,n);return u&&e.replaceChild(a,l.copy(u))}class Ln{constructor(t,n){this.schema=t,this.rules=n,this.tags=[],this.styles=[],n.forEach(r=>{r.tag?this.tags.push(r):r.style&&this.styles.push(r)}),this.normalizeLists=!this.tags.some(r=>{if(!/^(ul|ol)\b/.test(r.tag)||!r.node)return!1;let a=t.nodes[r.node];return a.contentMatch.matchType(a)})}parse(t,n={}){let r=new Cs(this,n,!1);return r.addAll(t,n.from,n.to),r.finish()}parseSlice(t,n={}){let r=new Cs(this,n,!0);return r.addAll(t,n.from,n.to),ce.maxOpen(r.finish())}matchTag(t,n,r){for(let a=r?this.tags.indexOf(r)+1:0;a<this.tags.length;a++){let o=this.tags[a];if(Dd(t,o.tag)&&(o.namespace===void 0||t.namespaceURI==o.namespace)&&(!o.context||n.matchesContext(o.context))){if(o.getAttrs){let l=o.getAttrs(t);if(l===!1)continue;o.attrs=l||void 0}return o}}}matchStyle(t,n,r,a){for(let o=a?this.styles.indexOf(a)+1:0;o<this.styles.length;o++){let l=this.styles[o],u=l.style;if(!(u.indexOf(t)!=0||l.context&&!r.matchesContext(l.context)||u.length>t.length&&(u.charCodeAt(t.length)!=61||u.slice(t.length+1)!=n))){if(l.getAttrs){let c=l.getAttrs(n);if(c===!1)continue;l.attrs=c||void 0}return l}}}static schemaRules(t){let n=[];function r(a){let o=a.priority==null?50:a.priority,l=0;for(;l<n.length;l++){let u=n[l];if((u.priority==null?50:u.priority)<o)break}n.splice(l,0,a)}for(let a in t.marks){let o=t.marks[a].spec.parseDOM;o&&o.forEach(l=>{r(l=Ss(l)),l.mark||l.ignore||l.clearMark||(l.mark=a)})}for(let a in t.nodes){let o=t.nodes[a].spec.parseDOM;o&&o.forEach(l=>{r(l=Ss(l)),l.node||l.ignore||l.mark||(l.node=a)})}return n}static fromSchema(t){return t.cached.domParser||(t.cached.domParser=new Ln(t,Ln.schemaRules(t)))}}const vs={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},kd={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},xs={ol:!0,ul:!0},On=1,Pn=2,ln=4;function ws(e,t,n){return t!=null?(t?On:0)|(t==="full"?Pn:0):e&&e.whitespace=="pre"?On|Pn:n&~ln}class Bn{constructor(t,n,r,a,o,l,u){this.type=t,this.attrs=n,this.marks=r,this.pendingMarks=a,this.solid=o,this.options=u,this.content=[],this.activeMarks=Re.none,this.stashMarks=[],this.match=l||(u&ln?null:t.contentMatch)}findWrapping(t){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(ae.from(t));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let r=this.type.contentMatch,a;return(a=r.findWrapping(t.type))?(this.match=r,a):null}}return this.match.findWrapping(t.type)}finish(t){if(!(this.options&On)){let r=this.content[this.content.length-1],a;if(r&&r.isText&&(a=/[ \t\r\n\u000c]+$/.exec(r.text))){let o=r;r.text.length==a[0].length?this.content.pop():this.content[this.content.length-1]=o.withText(o.text.slice(0,o.text.length-a[0].length))}}let n=ae.from(this.content);return!t&&this.match&&(n=n.append(this.match.fillBefore(ae.empty,!0))),this.type?this.type.create(this.attrs,n,this.marks):n}popFromStashMark(t){for(let n=this.stashMarks.length-1;n>=0;n--)if(t.eq(this.stashMarks[n]))return this.stashMarks.splice(n,1)[0]}applyPending(t){for(let n=0,r=this.pendingMarks;n<r.length;n++){let a=r[n];(this.type?this.type.allowsMarkType(a.type):Md(a.type,t))&&!a.isInSet(this.activeMarks)&&(this.activeMarks=a.addToSet(this.activeMarks),this.pendingMarks=a.removeFromSet(this.pendingMarks))}}inlineContext(t){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:t.parentNode&&!vs.hasOwnProperty(t.parentNode.nodeName.toLowerCase())}}class Cs{constructor(t,n,r){this.parser=t,this.options=n,this.isOpen=r,this.open=0;let a=n.topNode,o,l=ws(null,n.preserveWhitespace,0)|(r?ln:0);a?o=new Bn(a.type,a.attrs,Re.none,Re.none,!0,n.topMatch||a.type.contentMatch,l):r?o=new Bn(null,null,Re.none,Re.none,!0,null,l):o=new Bn(t.schema.topNodeType,null,Re.none,Re.none,!0,null,l),this.nodes=[o],this.find=n.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(t){if(t.nodeType==3)this.addTextNode(t);else if(t.nodeType==1){let n=t.getAttribute("style");if(!n)this.addElement(t);else{let r=this.readStyles(Id(n));if(!r)return;let[a,o]=r,l=this.top;for(let u=0;u<o.length;u++)this.removePendingMark(o[u],l);for(let u=0;u<a.length;u++)this.addPendingMark(a[u]);this.addElement(t);for(let u=0;u<a.length;u++)this.removePendingMark(a[u],l);for(let u=0;u<o.length;u++)this.addPendingMark(o[u])}}}addTextNode(t){let n=t.nodeValue,r=this.top;if(r.options&Pn||r.inlineContext(t)||/[^ \t\r\n\u000c]/.test(n)){if(r.options&On)r.options&Pn?n=n.replace(/\r\n?/g,`
|
|
101
|
-
`):n=n.replace(/\r?\n|\r/g," ");else if(n=n.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let a=r.content[r.content.length-1],o=t.previousSibling;(!a||o&&o.nodeName=="BR"||a.isText&&/[ \t\r\n\u000c]$/.test(a.text))&&(n=n.slice(1))}n&&this.insertNode(this.parser.schema.text(n)),this.findInText(t)}else this.findInside(t)}addElement(t,n){let r=t.nodeName.toLowerCase(),a;
|
|
102
|
-
`))}ignoreFallback(t){t.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"))}readStyles(t){let n=Re.none,r=Re.none;for(let a=0;a<t.length;a+=2)for(let o=void 0;;){let l=this.parser.matchStyle(t[a],t[a+1],this,o);if(!l)break;if(l.ignore)return null;if(l.clearMark?this.top.pendingMarks.concat(this.top.activeMarks).forEach(u=>{l.clearMark(u)&&(r=u.addToSet(r))}):n=this.parser.schema.marks[l.mark].create(l.attrs).addToSet(n),l.consuming===!1)o=l;else break}return[n,r]}addElementByRule(t,n,r){let a,o,l;n.node?(o=this.parser.schema.nodes[n.node],o.isLeaf?this.insertNode(o.create(n.attrs))||this.leafFallback(t):a=this.enter(o,n.attrs||null,n.preserveWhitespace)):(l=this.parser.schema.marks[n.mark].create(n.attrs),this.addPendingMark(l));let u=this.top;if(o&&o.isLeaf)this.findInside(t);else if(r)this.addElement(t,r);else if(n.getContent)this.findInside(t),n.getContent(t,this.parser.schema).forEach(c=>this.insertNode(c));else{let c=t;typeof n.contentElement=="string"?c=t.querySelector(n.contentElement):typeof n.contentElement=="function"?c=n.contentElement(t):n.contentElement&&(c=n.contentElement),this.findAround(t,c,!0),this.addAll(c)}a&&this.sync(u)&&this.open--,l&&this.removePendingMark(l,u)}addAll(t,n,r){let a=n||0;for(let o=n?t.childNodes[n]:t.firstChild,l=r==null?null:t.childNodes[r];o!=l;o=o.nextSibling,++a)this.findAtPoint(t,a),this.addDOM(o);this.findAtPoint(t,a)}findPlace(t){let n,r;for(let a=this.open;a>=0;a--){let o=this.nodes[a],l=o.findWrapping(t);if(l&&(!n||n.length>l.length)&&(n=l,r=o,!l.length)||o.solid)break}if(!n)return!1;this.sync(r);for(let a=0;a<n.length;a++)this.enterInner(n[a],null,!1);return!0}insertNode(t){if(t.isInline&&this.needsBlock&&!this.top.type){let n=this.textblockFromContext();n&&this.enterInner(n)}if(this.findPlace(t)){this.closeExtra();let n=this.top;n.applyPending(t.type),n.match&&(n.match=n.match.matchType(t.type));let r=n.activeMarks;for(let a=0;a<t.marks.length;a++)(!n.type||n.type.allowsMarkType(t.marks[a].type))&&(r=t.marks[a].addToSet(r));return n.content.push(t.mark(r)),!0}return!1}enter(t,n,r){let a=this.findPlace(t.create(n));return a&&this.enterInner(t,n,!0,r),a}enterInner(t,n=null,r=!1,a){this.closeExtra();let o=this.top;o.applyPending(t),o.match=o.match&&o.match.matchType(t);let l=ws(t,a,o.options);o.options&ln&&o.content.length==0&&(l|=ln),this.nodes.push(new Bn(t,n,o.activeMarks,o.pendingMarks,r,null,l)),this.open++}closeExtra(t=!1){let n=this.nodes.length-1;if(n>this.open){for(;n>this.open;n--)this.nodes[n-1].content.push(this.nodes[n].finish(t));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(t){for(let n=this.open;n>=0;n--)if(this.nodes[n]==t)return this.open=n,!0;return!1}get currentPos(){this.closeExtra();let t=0;for(let n=this.open;n>=0;n--){let r=this.nodes[n].content;for(let a=r.length-1;a>=0;a--)t+=r[a].nodeSize;n&&t++}return t}findAtPoint(t,n){if(this.find)for(let r=0;r<this.find.length;r++)this.find[r].node==t&&this.find[r].offset==n&&(this.find[r].pos=this.currentPos)}findInside(t){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].pos==null&&t.nodeType==1&&t.contains(this.find[n].node)&&(this.find[n].pos=this.currentPos)}findAround(t,n,r){if(t!=n&&this.find)for(let a=0;a<this.find.length;a++)this.find[a].pos==null&&t.nodeType==1&&t.contains(this.find[a].node)&&n.compareDocumentPosition(this.find[a].node)&(r?2:4)&&(this.find[a].pos=this.currentPos)}findInText(t){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==t&&(this.find[n].pos=this.currentPos-(t.nodeValue.length-this.find[n].offset))}matchesContext(t){if(t.indexOf("|")>-1)return t.split(/\s*\|\s*/).some(this.matchesContext,this);let n=t.split("/"),r=this.options.context,a=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),o=-(r?r.depth+1:0)+(a?0:1),l=(u,c)=>{for(;u>=0;u--){let d=n[u];if(d==""){if(u==n.length-1||u==0)continue;for(;c>=o;c--)if(l(u-1,c))return!0;return!1}else{let f=c>0||c==0&&a?this.nodes[c].type:r&&c>=o?r.node(c-o).type:null;if(!f||f.name!=d&&f.groups.indexOf(d)==-1)return!1;c--}}return!0};return l(n.length-1,this.open)}textblockFromContext(){let t=this.options.context;if(t)for(let n=t.depth;n>=0;n--){let r=t.node(n).contentMatchAt(t.indexAfter(n)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let n in this.parser.schema.nodes){let r=this.parser.schema.nodes[n];if(r.isTextblock&&r.defaultAttrs)return r}}addPendingMark(t){let n=Ad(t,this.top.pendingMarks);n&&this.top.stashMarks.push(n),this.top.pendingMarks=t.addToSet(this.top.pendingMarks)}removePendingMark(t,n){for(let r=this.open;r>=0;r--){let a=this.nodes[r];if(a.pendingMarks.lastIndexOf(t)>-1)a.pendingMarks=t.removeFromSet(a.pendingMarks);else{a.activeMarks=t.removeFromSet(a.activeMarks);let l=a.popFromStashMark(t);l&&a.type&&a.type.allowsMarkType(l.type)&&(a.activeMarks=l.addToSet(a.activeMarks))}if(a==n)break}}}function Td(e){for(let t=e.firstChild,n=null;t;t=t.nextSibling){let r=t.nodeType==1?t.nodeName.toLowerCase():null;r&&xs.hasOwnProperty(r)&&n?(n.appendChild(t),t=n):r=="li"?n=t:r&&(n=null)}}function Dd(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function Id(e){let t=/\s*([\w-]+)\s*:\s*([^;]+)/g,n,r=[];for(;n=t.exec(e);)r.push(n[1],n[2].trim());return r}function Ss(e){let t={};for(let n in e)t[n]=e[n];return t}function Md(e,t){let n=t.schema.nodes;for(let r in n){let a=n[r];if(!a.allowsMarkType(e))continue;let o=[],l=u=>{o.push(u);for(let c=0;c<u.edgeCount;c++){let{type:d,next:f}=u.edge(c);if(d==t||o.indexOf(f)<0&&l(f))return!0}};if(l(a.contentMatch))return!0}}function Ad(e,t){for(let n=0;n<t.length;n++)if(e.eq(t[n]))return t[n]}const _s=65535,ks=Math.pow(2,16);function zd(e,t){return e+t*ks}function Ts(e){return e&_s}function Ed(e){return(e-(e&_s))/ks}const Ds=1,Is=2,Vn=4,Ms=8;class As{constructor(t,n,r){this.pos=t,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&Ms)>0}get deletedBefore(){return(this.delInfo&(Ds|Vn))>0}get deletedAfter(){return(this.delInfo&(Is|Vn))>0}get deletedAcross(){return(this.delInfo&Vn)>0}}class Je{constructor(t,n=!1){if(this.ranges=t,this.inverted=n,!t.length&&Je.empty)return Je.empty}recover(t){let n=0,r=Ts(t);if(!this.inverted)for(let a=0;a<r;a++)n+=this.ranges[a*3+2]-this.ranges[a*3+1];return this.ranges[r*3]+n+Ed(t)}mapResult(t,n=1){return this._map(t,n,!1)}map(t,n=1){return this._map(t,n,!0)}_map(t,n,r){let a=0,o=this.inverted?2:1,l=this.inverted?1:2;for(let u=0;u<this.ranges.length;u+=3){let c=this.ranges[u]-(this.inverted?a:0);if(c>t)break;let d=this.ranges[u+o],f=this.ranges[u+l],h=c+d;if(t<=h){let g=d?t==c?-1:t==h?1:n:n,m=c+a+(g<0?0:f);if(r)return m;let C=t==(n<0?c:h)?null:zd(u/3,t-c),w=t==c?Is:t==h?Ds:Vn;return(n<0?t!=c:t!=h)&&(w|=Ms),new As(m,w,C)}a+=f-d}return r?t+a:new As(t+a,0,null)}touches(t,n){let r=0,a=Ts(n),o=this.inverted?2:1,l=this.inverted?1:2;for(let u=0;u<this.ranges.length;u+=3){let c=this.ranges[u]-(this.inverted?r:0);if(c>t)break;let d=this.ranges[u+o],f=c+d;if(t<=f&&u==a*3)return!0;r+=this.ranges[u+l]-d}return!1}forEach(t){let n=this.inverted?2:1,r=this.inverted?1:2;for(let a=0,o=0;a<this.ranges.length;a+=3){let l=this.ranges[a],u=l-(this.inverted?o:0),c=l+(this.inverted?0:o),d=this.ranges[a+n],f=this.ranges[a+r];t(u,u+d,c,c+f),o+=f-d}}invert(){return new Je(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(t){return t==0?Je.empty:new Je(t<0?[0,-t,0]:[0,0,t])}}Je.empty=new Je([]);const Br=Object.create(null);class qe{getMap(){return Je.empty}merge(t){return null}static fromJSON(t,n){if(!n||!n.stepType)throw new RangeError("Invalid input for Step.fromJSON");let r=Br[n.stepType];if(!r)throw new RangeError(`No step type ${n.stepType} defined`);return r.fromJSON(t,n)}static jsonID(t,n){if(t in Br)throw new RangeError("Duplicate use of step JSON ID "+t);return Br[t]=n,n.prototype.jsonID=t,n}}class Se{constructor(t,n){this.doc=t,this.failed=n}static ok(t){return new Se(t,null)}static fail(t){return new Se(null,t)}static fromReplace(t,n,r,a){try{return Se.ok(t.replace(n,r,a))}catch(o){if(o instanceof _d)return Se.fail(o.message);throw o}}}function Vr(e,t,n){let r=[];for(let a=0;a<e.childCount;a++){let o=e.child(a);o.content.size&&(o=o.copy(Vr(o.content,t,o))),o.isInline&&(o=t(o,n,a)),r.push(o)}return ae.fromArray(r)}class Et extends qe{constructor(t,n,r){super(),this.from=t,this.to=n,this.mark=r}apply(t){let n=t.slice(this.from,this.to),r=t.resolve(this.from),a=r.node(r.sharedDepth(this.to)),o=new ce(Vr(n.content,(l,u)=>!l.isAtom||!u.type.allowsMarkType(this.mark.type)?l:l.mark(this.mark.addToSet(l.marks)),a),n.openStart,n.openEnd);return Se.fromReplace(t,this.from,this.to,o)}invert(){return new $t(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new Et(n.pos,r.pos,this.mark)}merge(t){return t instanceof Et&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new Et(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new Et(n.from,n.to,t.markFromJSON(n.mark))}}qe.jsonID("addMark",Et);class $t extends qe{constructor(t,n,r){super(),this.from=t,this.to=n,this.mark=r}apply(t){let n=t.slice(this.from,this.to),r=new ce(Vr(n.content,a=>a.mark(this.mark.removeFromSet(a.marks)),t),n.openStart,n.openEnd);return Se.fromReplace(t,this.from,this.to,r)}invert(){return new Et(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new $t(n.pos,r.pos,this.mark)}merge(t){return t instanceof $t&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new $t(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new $t(n.from,n.to,t.markFromJSON(n.mark))}}qe.jsonID("removeMark",$t);class Lt extends qe{constructor(t,n){super(),this.pos=t,this.mark=n}apply(t){let n=t.nodeAt(this.pos);if(!n)return Se.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return Se.fromReplace(t,this.pos,this.pos+1,new ce(ae.from(r),0,n.isLeaf?0:1))}invert(t){let n=t.nodeAt(this.pos);if(n){let r=this.mark.addToSet(n.marks);if(r.length==n.marks.length){for(let a=0;a<n.marks.length;a++)if(!n.marks[a].isInSet(r))return new Lt(this.pos,n.marks[a]);return new Lt(this.pos,this.mark)}}return new un(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new Lt(n.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new Lt(n.pos,t.markFromJSON(n.mark))}}qe.jsonID("addNodeMark",Lt);class un extends qe{constructor(t,n){super(),this.pos=t,this.mark=n}apply(t){let n=t.nodeAt(this.pos);if(!n)return Se.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.removeFromSet(n.marks));return Se.fromReplace(t,this.pos,this.pos+1,new ce(ae.from(r),0,n.isLeaf?0:1))}invert(t){let n=t.nodeAt(this.pos);return!n||!this.mark.isInSet(n.marks)?this:new Lt(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new un(n.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new un(n.pos,t.markFromJSON(n.mark))}}qe.jsonID("removeNodeMark",un);class lt extends qe{constructor(t,n,r,a=!1){super(),this.from=t,this.to=n,this.slice=r,this.structure=a}apply(t){return this.structure&&Nr(t,this.from,this.to)?Se.fail("Structure replace would overwrite content"):Se.fromReplace(t,this.from,this.to,this.slice)}getMap(){return new Je([this.from,this.to-this.from,this.slice.size])}invert(t){return new lt(this.from,this.from+this.slice.size,t.slice(this.from,this.to))}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deletedAcross&&r.deletedAcross?null:new lt(n.pos,Math.max(n.pos,r.pos),this.slice)}merge(t){if(!(t instanceof lt)||t.structure||this.structure)return null;if(this.from+this.slice.size==t.from&&!this.slice.openEnd&&!t.slice.openStart){let n=this.slice.size+t.slice.size==0?ce.empty:new ce(this.slice.content.append(t.slice.content),this.slice.openStart,t.slice.openEnd);return new lt(this.from,this.to+(t.to-t.from),n,this.structure)}else if(t.to==this.from&&!this.slice.openStart&&!t.slice.openEnd){let n=this.slice.size+t.slice.size==0?ce.empty:new ce(t.slice.content.append(this.slice.content),t.slice.openStart,this.slice.openEnd);return new lt(t.from,this.to,n,this.structure)}else return null}toJSON(){let t={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(t.slice=this.slice.toJSON()),this.structure&&(t.structure=!0),t}static fromJSON(t,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new lt(n.from,n.to,ce.fromJSON(t,n.slice),!!n.structure)}}qe.jsonID("replace",lt);class Ot extends qe{constructor(t,n,r,a,o,l,u=!1){super(),this.from=t,this.to=n,this.gapFrom=r,this.gapTo=a,this.slice=o,this.insert=l,this.structure=u}apply(t){if(this.structure&&(Nr(t,this.from,this.gapFrom)||Nr(t,this.gapTo,this.to)))return Se.fail("Structure gap-replace would overwrite content");let n=t.slice(this.gapFrom,this.gapTo);if(n.openStart||n.openEnd)return Se.fail("Gap is not a flat range");let r=this.slice.insertAt(this.insert,n.content);return r?Se.fromReplace(t,this.from,this.to,r):Se.fail("Content does not fit in gap")}getMap(){return new Je([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(t){let n=this.gapTo-this.gapFrom;return new Ot(this.from,this.from+this.slice.size+n,this.from+this.insert,this.from+this.insert+n,t.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1),a=t.map(this.gapFrom,-1),o=t.map(this.gapTo,1);return n.deletedAcross&&r.deletedAcross||a<n.pos||o>r.pos?null:new Ot(n.pos,r.pos,a,o,this.slice,this.insert,this.structure)}toJSON(){let t={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(t.slice=this.slice.toJSON()),this.structure&&(t.structure=!0),t}static fromJSON(t,n){if(typeof n.from!="number"||typeof n.to!="number"||typeof n.gapFrom!="number"||typeof n.gapTo!="number"||typeof n.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Ot(n.from,n.to,n.gapFrom,n.gapTo,ce.fromJSON(t,n.slice),n.insert,!!n.structure)}}qe.jsonID("replaceAround",Ot);function Nr(e,t,n){let r=e.resolve(t),a=n-t,o=r.depth;for(;a>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,a--;if(a>0){let l=r.node(o).maybeChild(r.indexAfter(o));for(;a>0;){if(!l||l.isLeaf)return!0;l=l.firstChild,a--}}return!1}function $d(e,t,n){return(t==0||e.canReplace(t,e.childCount))&&(n==e.childCount||e.canReplace(0,n))}function Ld(e){let n=e.parent.content.cutByIndex(e.startIndex,e.endIndex);for(let r=e.depth;;--r){let a=e.$from.node(r),o=e.$from.index(r),l=e.$to.indexAfter(r);if(r<e.depth&&a.canReplace(o,l,n))return r;if(r==0||a.type.spec.isolating||!$d(a,o,l))break}return null}function Nn(e,t,n=1,r){let a=e.resolve(t),o=a.depth-n,l=r&&r[r.length-1]||a.parent;if(o<0||a.parent.type.spec.isolating||!a.parent.canReplace(a.index(),a.parent.childCount)||!l.type.validContent(a.parent.content.cutByIndex(a.index(),a.parent.childCount)))return!1;for(let d=a.depth-1,f=n-2;d>o;d--,f--){let h=a.node(d),g=a.index(d);if(h.type.spec.isolating)return!1;let m=h.content.cutByIndex(g,h.childCount),C=r&&r[f+1];C&&(m=m.replaceChild(0,C.type.create(C.attrs)));let w=r&&r[f]||h;if(!h.canReplace(g+1,h.childCount)||!w.type.validContent(m))return!1}let u=a.indexAfter(o),c=r&&r[0];return a.node(o).canReplaceWith(u,u,c?c.type:a.node(o+1).type)}function zs(e,t){let n=e.resolve(t),r=n.index();return Od(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function Od(e,t){return!!(e&&t&&!e.isLeaf&&e.canAppend(t))}class cn extends qe{constructor(t,n,r){super(),this.pos=t,this.attr=n,this.value=r}apply(t){let n=t.nodeAt(this.pos);if(!n)return Se.fail("No node at attribute step's position");let r=Object.create(null);for(let o in n.attrs)r[o]=n.attrs[o];r[this.attr]=this.value;let a=n.type.create(r,null,n.marks);return Se.fromReplace(t,this.pos,this.pos+1,new ce(ae.from(a),0,n.isLeaf?0:1))}getMap(){return Je.empty}invert(t){return new cn(this.pos,this.attr,t.nodeAt(this.pos).attrs[this.attr])}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new cn(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(t,n){if(typeof n.pos!="number"||typeof n.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new cn(n.pos,n.attr,n.value)}}qe.jsonID("attr",cn);let dn=class extends Error{};dn=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n},dn.prototype=Object.create(Error.prototype),dn.prototype.constructor=dn,dn.prototype.name="TransformError";const qr=Object.create(null);class fe{constructor(t,n,r){this.$anchor=t,this.$head=n,this.ranges=r||[new Pd(t.min(n),t.max(n))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let t=this.ranges;for(let n=0;n<t.length;n++)if(t[n].$from.pos!=t[n].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(t,n=ce.empty){let r=n.content.lastChild,a=null;for(let u=0;u<n.openEnd;u++)a=r,r=r.lastChild;let o=t.steps.length,l=this.ranges;for(let u=0;u<l.length;u++){let{$from:c,$to:d}=l[u],f=t.mapping.slice(o);t.replaceRange(f.map(c.pos),f.map(d.pos),u?ce.empty:n),u==0&&Ls(t,o,(r?r.isInline:a&&a.isTextblock)?-1:1)}}replaceWith(t,n){let r=t.steps.length,a=this.ranges;for(let o=0;o<a.length;o++){let{$from:l,$to:u}=a[o],c=t.mapping.slice(r),d=c.map(l.pos),f=c.map(u.pos);o?t.deleteRange(d,f):(t.replaceRangeWith(d,f,n),Ls(t,r,n.isInline?-1:1))}}static findFrom(t,n,r=!1){let a=t.parent.inlineContent?new _e(t):Ft(t.node(0),t.parent,t.pos,t.index(),n,r);if(a)return a;for(let o=t.depth-1;o>=0;o--){let l=n<0?Ft(t.node(0),t.node(o),t.before(o+1),t.index(o),n,r):Ft(t.node(0),t.node(o),t.after(o+1),t.index(o)+1,n,r);if(l)return l}return null}static near(t,n=1){return this.findFrom(t,n)||this.findFrom(t,-n)||new gt(t.node(0))}static atStart(t){return Ft(t,t,0,0,1)||new gt(t)}static atEnd(t){return Ft(t,t,t.content.size,t.childCount,-1)||new gt(t)}static fromJSON(t,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=qr[n.type];if(!r)throw new RangeError(`No selection type ${n.type} defined`);return r.fromJSON(t,n)}static jsonID(t,n){if(t in qr)throw new RangeError("Duplicate use of selection JSON ID "+t);return qr[t]=n,n.prototype.jsonID=t,n}getBookmark(){return _e.between(this.$anchor,this.$head).getBookmark()}}fe.prototype.visible=!0;class Pd{constructor(t,n){this.$from=t,this.$to=n}}let Es=!1;function $s(e){!Es&&!e.parent.inlineContent&&(Es=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+e.parent.type.name+")"))}class _e extends fe{constructor(t,n=t){$s(t),$s(n),super(t,n)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(t,n){let r=t.resolve(n.map(this.head));if(!r.parent.inlineContent)return fe.near(r);let a=t.resolve(n.map(this.anchor));return new _e(a.parent.inlineContent?a:r,r)}replace(t,n=ce.empty){if(super.replace(t,n),n==ce.empty){let r=this.$from.marksAcross(this.$to);r&&t.ensureMarks(r)}}eq(t){return t instanceof _e&&t.anchor==this.anchor&&t.head==this.head}getBookmark(){return new qn(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(t,n){if(typeof n.anchor!="number"||typeof n.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new _e(t.resolve(n.anchor),t.resolve(n.head))}static create(t,n,r=n){let a=t.resolve(n);return new this(a,r==n?a:t.resolve(r))}static between(t,n,r){let a=t.pos-n.pos;if((!r||a)&&(r=a>=0?1:-1),!n.parent.inlineContent){let o=fe.findFrom(n,r,!0)||fe.findFrom(n,-r,!0);if(o)n=o.$head;else return fe.near(n,r)}return t.parent.inlineContent||(a==0?t=n:(t=(fe.findFrom(t,-r,!0)||fe.findFrom(t,r,!0)).$anchor,t.pos<n.pos!=a<0&&(t=n))),new _e(t,n)}}fe.jsonID("text",_e);class qn{constructor(t,n){this.anchor=t,this.head=n}map(t){return new qn(t.map(this.anchor),t.map(this.head))}resolve(t){return _e.between(t.resolve(this.anchor),t.resolve(this.head))}}class Ye extends fe{constructor(t){let n=t.nodeAfter,r=t.node(0).resolve(t.pos+n.nodeSize);super(t,r),this.node=n}map(t,n){let{deleted:r,pos:a}=n.mapResult(this.anchor),o=t.resolve(a);return r?fe.near(o):new Ye(o)}content(){return new ce(ae.from(this.node),0,0)}eq(t){return t instanceof Ye&&t.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new Fr(this.anchor)}static fromJSON(t,n){if(typeof n.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new Ye(t.resolve(n.anchor))}static create(t,n){return new Ye(t.resolve(n))}static isSelectable(t){return!t.isText&&t.type.spec.selectable!==!1}}Ye.prototype.visible=!1,fe.jsonID("node",Ye);class Fr{constructor(t){this.anchor=t}map(t){let{deleted:n,pos:r}=t.mapResult(this.anchor);return n?new qn(r,r):new Fr(r)}resolve(t){let n=t.resolve(this.anchor),r=n.nodeAfter;return r&&Ye.isSelectable(r)?new Ye(n):fe.near(n)}}class gt extends fe{constructor(t){super(t.resolve(0),t.resolve(t.content.size))}replace(t,n=ce.empty){if(n==ce.empty){t.delete(0,t.doc.content.size);let r=fe.atStart(t.doc);r.eq(t.selection)||t.setSelection(r)}else super.replace(t,n)}toJSON(){return{type:"all"}}static fromJSON(t){return new gt(t)}map(t){return new gt(t)}eq(t){return t instanceof gt}getBookmark(){return Bd}}fe.jsonID("all",gt);const Bd={map(){return this},resolve(e){return new gt(e)}};function Ft(e,t,n,r,a,o=!1){if(t.inlineContent)return _e.create(e,n);for(let l=r-(a>0?0:1);a>0?l<t.childCount:l>=0;l+=a){let u=t.child(l);if(u.isAtom){if(!o&&Ye.isSelectable(u))return Ye.create(e,n-(a<0?u.nodeSize:0))}else{let c=Ft(e,u,n+a,a<0?u.childCount:0,a,o);if(c)return c}n+=u.nodeSize*a}return null}function Ls(e,t,n){let r=e.steps.length-1;if(r<t)return;let a=e.steps[r];if(!(a instanceof lt||a instanceof Ot))return;let o=e.mapping.maps[r],l;o.forEach((u,c,d,f)=>{l==null&&(l=f)}),e.setSelection(fe.near(e.doc.resolve(l),n))}function Os(e,t){return!t||!e?e:e.bind(t)}class Fn{constructor(t,n,r){this.name=t,this.init=Os(n.init,r),this.apply=Os(n.apply,r)}}new Fn("doc",{init(e){return e.doc||e.schema.topNodeType.createAndFill()},apply(e){return e.doc}}),new Fn("selection",{init(e,t){return e.selection||fe.atStart(t.doc)},apply(e){return e.selection}}),new Fn("storedMarks",{init(e){return e.storedMarks||null},apply(e,t,n,r){return r.selection.$cursor?e.storedMarks:null}}),new Fn("scrollToSelection",{init(){return 0},apply(e,t){return e.scrolledIntoView?t+1:t}});function Ps(e,t,n){for(let r in e){let a=e[r];a instanceof Function?a=a.bind(t):r=="handleDOMEvents"&&(a=Ps(a,t,{})),n[r]=a}return n}class pn{constructor(t){this.spec=t,this.props={},t.props&&Ps(t.props,this,this.props),this.key=t.key?t.key.key:Bs("plugin")}getState(t){return t[this.key]}}const Gr=Object.create(null);function Bs(e){return e in Gr?e+"$"+ ++Gr[e]:(Gr[e]=0,e+"$")}class hn{constructor(t="key"){this.key=Bs(t)}get(t){return t.config.pluginsByKey[this.key]}getState(t){return t[this.key]}}function Vs(e){const{state:t,transaction:n}=e;let{selection:r}=n,{doc:a}=n,{storedMarks:o}=n;return{...t,apply:t.apply.bind(t),applyTransaction:t.applyTransaction.bind(t),filterTransaction:t.filterTransaction,plugins:t.plugins,schema:t.schema,reconfigure:t.reconfigure.bind(t),toJSON:t.toJSON.bind(t),get storedMarks(){return o},get selection(){return r},get doc(){return a},get tr(){return r=n.selection,a=n.doc,o=n.storedMarks,n}}}class Vd{constructor(t){this.editor=t.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=t.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){const{rawCommands:t,editor:n,state:r}=this,{view:a}=n,{tr:o}=r,l=this.buildProps(o);return Object.fromEntries(Object.entries(t).map(([u,c])=>[u,(...f)=>{const h=c(...f)(l);return!o.getMeta("preventDispatch")&&!this.hasCustomState&&a.dispatch(o),h}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(t,n=!0){const{rawCommands:r,editor:a,state:o}=this,{view:l}=a,u=[],c=!!t,d=t||o.tr,f=()=>(!c&&n&&!d.getMeta("preventDispatch")&&!this.hasCustomState&&l.dispatch(d),u.every(g=>g===!0)),h={...Object.fromEntries(Object.entries(r).map(([g,m])=>[g,(...w)=>{const _=this.buildProps(d,n),T=m(...w)(_);return u.push(T),h}])),run:f};return h}createCan(t){const{rawCommands:n,state:r}=this,a=!1,o=t||r.tr,l=this.buildProps(o,a);return{...Object.fromEntries(Object.entries(n).map(([c,d])=>[c,(...f)=>d(...f)({...l,dispatch:void 0})])),chain:()=>this.createChain(o,a)}}buildProps(t,n=!0){const{rawCommands:r,editor:a,state:o}=this,{view:l}=a;o.storedMarks&&t.setStoredMarks(o.storedMarks);const u={tr:t,editor:a,view:l,state:Vs({state:o,transaction:t}),dispatch:n?()=>{}:void 0,chain:()=>this.createChain(t),can:()=>this.createCan(t),get commands(){return Object.fromEntries(Object.entries(r).map(([c,d])=>[c,(...f)=>d(...f)(u)]))}};return u}}function St(e,t,n){return e.config[t]===void 0&&e.parent?St(e.parent,t,n):typeof e.config[t]=="function"?e.config[t].bind({...n,parent:e.parent?St(e.parent,t,n):null}):e.config[t]}function Nd(e){const t=e.filter(a=>a.type==="extension"),n=e.filter(a=>a.type==="node"),r=e.filter(a=>a.type==="mark");return{baseExtensions:t,nodeExtensions:n,markExtensions:r}}function Ae(e,t){if(typeof e=="string"){if(!t.nodes[e])throw Error(`There is no node type named '${e}'. Maybe you forgot to add the extension?`);return t.nodes[e]}return e}function qd(e){return typeof e=="function"}function Gt(e,t=void 0,...n){return qd(e)?t?e.bind(t)(...n):e(...n):e}function Fd(e){return Object.prototype.toString.call(e)==="[object RegExp]"}function Gd(e){return Object.prototype.toString.call(e).slice(8,-1)}function Wr(e){return Gd(e)!=="Object"?!1:e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype}function Ns(e,t){const n={...e};return Wr(e)&&Wr(t)&&Object.keys(t).forEach(r=>{Wr(t[r])?r in e?n[r]=Ns(e[r],t[r]):Object.assign(n,{[r]:t[r]}):Object.assign(n,{[r]:t[r]})}),n}class ut{constructor(t={}){this.type="extension",this.name="extension",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...t},this.name=this.config.name,t.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=Gt(St(this,"addOptions",{name:this.name}))),this.storage=Gt(St(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(t={}){return new ut(t)}configure(t={}){const n=this.extend();return n.options=Ns(this.options,t),n.storage=Gt(St(n,"addStorage",{name:n.name,options:n.options})),n}extend(t={}){const n=new ut(t);return n.parent=this,this.child=n,n.name=t.name?t.name:n.parent.name,t.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${n.name}".`),n.options=Gt(St(n,"addOptions",{name:n.name})),n.storage=Gt(St(n,"addStorage",{name:n.name,options:n.options})),n}}function Wd(e,t,n){const{from:r,to:a}=t,{blockSeparator:o=`
|
|
100
|
+
`}const _d=e=>t=>{const{componentSubType:n,value:r}=t;return n==="scatter"?Sd(e,r):wd(e,r)};function kd({config:e}){return{trigger:"item",confine:!0,formatter:_d(e)}}const on=y.forwardRef(function({value:t,onChange:n,...r},a){return i(s.TextInput,{ref:a,value:t,onChange:n,...r})}),Lr={fontSize:"14px",lineHeight:"32px",color:"#3D3E45",ul:{paddingLeft:"2em",margin:"6px 0 0"},p:{margin:0},a:{WebkitTapHighlightColor:"transparent",color:"rgb(34, 139, 230)",textDecoration:"none","&:hover":{textDecoration:"underline"},"&:active, &:hover":{outlineWidth:0}},table:{tr:{"th, td":{padding:"0 .5em"}}},"table.rich-text-table-render, div.tableWrapper table":{"th, td":{border:"1px solid #eaeaea"},"tr:last-of-type td":{borderBottom:"1px solid #eaeaea"}},".resize-cursor":{cursor:"col-resize"},details:{summary:{listStyle:"none",cursor:"pointer",transition:"color 300ms ease",userSelect:"none"},"summary::-webkit-details-marker":{display:"none"},"summary:hover":{color:"black","&::before":{opacity:1}},"summary::before":{content:'"►"',fontSize:"10px",margin:"0px 5px",opacity:.5,display:"inline-block",transition:"opacity 300ms ease, transform 300ms ease"}},"details[open] summary::before":{transform:"rotate(90deg)"},"details + details":{marginTop:"10px"},blockquote:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45",margin:"0 0 14px"}};function ys(e,t,n){for(let r=0;;r++){if(r==e.childCount||r==t.childCount)return e.childCount==t.childCount?null:n;let a=e.child(r),o=t.child(r);if(a==o){n+=a.nodeSize;continue}if(!a.sameMarkup(o))return n;if(a.isText&&a.text!=o.text){for(let l=0;a.text[l]==o.text[l];l++)n++;return n}if(a.content.size||o.content.size){let l=ys(a.content,o.content,n+1);if(l!=null)return l}n+=a.nodeSize}}function bs(e,t,n,r){for(let a=e.childCount,o=t.childCount;;){if(a==0||o==0)return a==o?null:{a:n,b:r};let l=e.child(--a),u=t.child(--o),c=l.nodeSize;if(l==u){n-=c,r-=c;continue}if(!l.sameMarkup(u))return{a:n,b:r};if(l.isText&&l.text!=u.text){let d=0,f=Math.min(l.text.length,u.text.length);for(;d<f&&l.text[l.text.length-d-1]==u.text[u.text.length-d-1];)d++,n--,r--;return{a:n,b:r}}if(l.content.size||u.content.size){let d=bs(l.content,u.content,n-1,r-1);if(d)return d}n-=c,r-=c}}class ae{constructor(t,n){if(this.content=t,this.size=n||0,n==null)for(let r=0;r<t.length;r++)this.size+=t[r].nodeSize}nodesBetween(t,n,r,a=0,o){for(let l=0,u=0;u<n;l++){let c=this.content[l],d=u+c.nodeSize;if(d>t&&r(c,a+u,o||null,l)!==!1&&c.content.size){let f=u+1;c.nodesBetween(Math.max(0,t-f),Math.min(c.content.size,n-f),r,a+f)}u=d}}descendants(t){this.nodesBetween(0,this.size,t)}textBetween(t,n,r,a){let o="",l=!0;return this.nodesBetween(t,n,(u,c)=>{u.isText?(o+=u.text.slice(Math.max(t,c)-c,n-c),l=!r):u.isLeaf?(a?o+=typeof a=="function"?a(u):a:u.type.spec.leafText&&(o+=u.type.spec.leafText(u)),l=!r):!l&&u.isBlock&&(o+=r,l=!0)},0),o}append(t){if(!t.size)return this;if(!this.size)return t;let n=this.lastChild,r=t.firstChild,a=this.content.slice(),o=0;for(n.isText&&n.sameMarkup(r)&&(a[a.length-1]=n.withText(n.text+r.text),o=1);o<t.content.length;o++)a.push(t.content[o]);return new ae(a,this.size+t.size)}cut(t,n=this.size){if(t==0&&n==this.size)return this;let r=[],a=0;if(n>t)for(let o=0,l=0;l<n;o++){let u=this.content[o],c=l+u.nodeSize;c>t&&((l<t||c>n)&&(u.isText?u=u.cut(Math.max(0,t-l),Math.min(u.text.length,n-l)):u=u.cut(Math.max(0,t-l-1),Math.min(u.content.size,n-l-1))),r.push(u),a+=u.nodeSize),l=c}return new ae(r,a)}cutByIndex(t,n){return t==n?ae.empty:t==0&&n==this.content.length?this:new ae(this.content.slice(t,n))}replaceChild(t,n){let r=this.content[t];if(r==n)return this;let a=this.content.slice(),o=this.size+n.nodeSize-r.nodeSize;return a[t]=n,new ae(a,o)}addToStart(t){return new ae([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new ae(this.content.concat(t),this.size+t.nodeSize)}eq(t){if(this.content.length!=t.content.length)return!1;for(let n=0;n<this.content.length;n++)if(!this.content[n].eq(t.content[n]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(t){let n=this.content[t];if(!n)throw new RangeError("Index "+t+" out of range for "+this);return n}maybeChild(t){return this.content[t]||null}forEach(t){for(let n=0,r=0;n<this.content.length;n++){let a=this.content[n];t(a,r,n),r+=a.nodeSize}}findDiffStart(t,n=0){return ys(this,t,n)}findDiffEnd(t,n=this.size,r=t.size){return bs(this,t,n,r)}findIndex(t,n=-1){if(t==0)return $n(0,t);if(t==this.size)return $n(this.content.length,t);if(t>this.size||t<0)throw new RangeError(`Position ${t} outside of fragment (${this})`);for(let r=0,a=0;;r++){let o=this.child(r),l=a+o.nodeSize;if(l>=t)return l==t||n>0?$n(r+1,l):$n(r,a);a=l}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(t=>t.toJSON()):null}static fromJSON(t,n){if(!n)return ae.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new ae(n.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return ae.empty;let n,r=0;for(let a=0;a<t.length;a++){let o=t[a];r+=o.nodeSize,a&&o.isText&&t[a-1].sameMarkup(o)?(n||(n=t.slice(0,a)),n[n.length-1]=o.withText(n[n.length-1].text+o.text)):n&&n.push(o)}return new ae(n||t,r)}static from(t){if(!t)return ae.empty;if(t instanceof ae)return t;if(Array.isArray(t))return this.fromArray(t);if(t.attrs)return new ae([t],t.nodeSize);throw new RangeError("Can not convert "+t+" to a Fragment"+(t.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}ae.empty=new ae([],0);const Or={index:0,offset:0};function $n(e,t){return Or.index=e,Or.offset=t,Or}function Pr(e,t){if(e===t)return!0;if(!(e&&typeof e=="object")||!(t&&typeof t=="object"))return!1;let n=Array.isArray(e);if(Array.isArray(t)!=n)return!1;if(n){if(e.length!=t.length)return!1;for(let r=0;r<e.length;r++)if(!Pr(e[r],t[r]))return!1}else{for(let r in e)if(!(r in t)||!Pr(e[r],t[r]))return!1;for(let r in t)if(!(r in e))return!1}return!0}class Re{constructor(t,n){this.type=t,this.attrs=n}addToSet(t){let n,r=!1;for(let a=0;a<t.length;a++){let o=t[a];if(this.eq(o))return t;if(this.type.excludes(o.type))n||(n=t.slice(0,a));else{if(o.type.excludes(this.type))return t;!r&&o.type.rank>this.type.rank&&(n||(n=t.slice(0,a)),n.push(this),r=!0),n&&n.push(o)}}return n||(n=t.slice()),r||n.push(this),n}removeFromSet(t){for(let n=0;n<t.length;n++)if(this.eq(t[n]))return t.slice(0,n).concat(t.slice(n+1));return t}isInSet(t){for(let n=0;n<t.length;n++)if(this.eq(t[n]))return!0;return!1}eq(t){return this==t||this.type==t.type&&Pr(this.attrs,t.attrs)}toJSON(){let t={type:this.type.name};for(let n in this.attrs){t.attrs=this.attrs;break}return t}static fromJSON(t,n){if(!n)throw new RangeError("Invalid input for Mark.fromJSON");let r=t.marks[n.type];if(!r)throw new RangeError(`There is no mark type ${n.type} in this schema`);return r.create(n.attrs)}static sameSet(t,n){if(t==n)return!0;if(t.length!=n.length)return!1;for(let r=0;r<t.length;r++)if(!t[r].eq(n[r]))return!1;return!0}static setFrom(t){if(!t||Array.isArray(t)&&t.length==0)return Re.none;if(t instanceof Re)return[t];let n=t.slice();return n.sort((r,a)=>r.type.rank-a.type.rank),n}}Re.none=[];class Td extends Error{}class ce{constructor(t,n,r){this.content=t,this.openStart=n,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,n){let r=xs(this.content,t+this.openStart,n);return r&&new ce(r,this.openStart,this.openEnd)}removeBetween(t,n){return new ce(vs(this.content,t+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(t){return this.content.eq(t.content)&&this.openStart==t.openStart&&this.openEnd==t.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let t={content:this.content.toJSON()};return this.openStart>0&&(t.openStart=this.openStart),this.openEnd>0&&(t.openEnd=this.openEnd),t}static fromJSON(t,n){if(!n)return ce.empty;let r=n.openStart||0,a=n.openEnd||0;if(typeof r!="number"||typeof a!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new ce(ae.fromJSON(t,n.content),r,a)}static maxOpen(t,n=!0){let r=0,a=0;for(let o=t.firstChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=t.lastChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.lastChild)a++;return new ce(t,r,a)}}ce.empty=new ce(ae.empty,0,0);function vs(e,t,n){let{index:r,offset:a}=e.findIndex(t),o=e.maybeChild(r),{index:l,offset:u}=e.findIndex(n);if(a==t||o.isText){if(u!=n&&!e.child(l).isText)throw new RangeError("Removing non-flat range");return e.cut(0,t).append(e.cut(n))}if(r!=l)throw new RangeError("Removing non-flat range");return e.replaceChild(r,o.copy(vs(o.content,t-a-1,n-a-1)))}function xs(e,t,n,r){let{index:a,offset:o}=e.findIndex(t),l=e.maybeChild(a);if(o==t||l.isText)return r&&!r.canReplace(a,a,n)?null:e.cut(0,t).append(n).append(e.cut(t));let u=xs(l.content,t-o-1,n);return u&&e.replaceChild(a,l.copy(u))}class Ln{constructor(t,n){this.schema=t,this.rules=n,this.tags=[],this.styles=[],n.forEach(r=>{r.tag?this.tags.push(r):r.style&&this.styles.push(r)}),this.normalizeLists=!this.tags.some(r=>{if(!/^(ul|ol)\b/.test(r.tag)||!r.node)return!1;let a=t.nodes[r.node];return a.contentMatch.matchType(a)})}parse(t,n={}){let r=new _s(this,n,!1);return r.addAll(t,n.from,n.to),r.finish()}parseSlice(t,n={}){let r=new _s(this,n,!0);return r.addAll(t,n.from,n.to),ce.maxOpen(r.finish())}matchTag(t,n,r){for(let a=r?this.tags.indexOf(r)+1:0;a<this.tags.length;a++){let o=this.tags[a];if(Md(t,o.tag)&&(o.namespace===void 0||t.namespaceURI==o.namespace)&&(!o.context||n.matchesContext(o.context))){if(o.getAttrs){let l=o.getAttrs(t);if(l===!1)continue;o.attrs=l||void 0}return o}}}matchStyle(t,n,r,a){for(let o=a?this.styles.indexOf(a)+1:0;o<this.styles.length;o++){let l=this.styles[o],u=l.style;if(!(u.indexOf(t)!=0||l.context&&!r.matchesContext(l.context)||u.length>t.length&&(u.charCodeAt(t.length)!=61||u.slice(t.length+1)!=n))){if(l.getAttrs){let c=l.getAttrs(n);if(c===!1)continue;l.attrs=c||void 0}return l}}}static schemaRules(t){let n=[];function r(a){let o=a.priority==null?50:a.priority,l=0;for(;l<n.length;l++){let u=n[l];if((u.priority==null?50:u.priority)<o)break}n.splice(l,0,a)}for(let a in t.marks){let o=t.marks[a].spec.parseDOM;o&&o.forEach(l=>{r(l=ks(l)),l.mark||l.ignore||l.clearMark||(l.mark=a)})}for(let a in t.nodes){let o=t.nodes[a].spec.parseDOM;o&&o.forEach(l=>{r(l=ks(l)),l.node||l.ignore||l.mark||(l.node=a)})}return n}static fromSchema(t){return t.cached.domParser||(t.cached.domParser=new Ln(t,Ln.schemaRules(t)))}}const ws={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},Dd={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Cs={ol:!0,ul:!0},On=1,Pn=2,ln=4;function Ss(e,t,n){return t!=null?(t?On:0)|(t==="full"?Pn:0):e&&e.whitespace=="pre"?On|Pn:n&~ln}class Bn{constructor(t,n,r,a,o,l,u){this.type=t,this.attrs=n,this.marks=r,this.pendingMarks=a,this.solid=o,this.options=u,this.content=[],this.activeMarks=Re.none,this.stashMarks=[],this.match=l||(u&ln?null:t.contentMatch)}findWrapping(t){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(ae.from(t));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let r=this.type.contentMatch,a;return(a=r.findWrapping(t.type))?(this.match=r,a):null}}return this.match.findWrapping(t.type)}finish(t){if(!(this.options&On)){let r=this.content[this.content.length-1],a;if(r&&r.isText&&(a=/[ \t\r\n\u000c]+$/.exec(r.text))){let o=r;r.text.length==a[0].length?this.content.pop():this.content[this.content.length-1]=o.withText(o.text.slice(0,o.text.length-a[0].length))}}let n=ae.from(this.content);return!t&&this.match&&(n=n.append(this.match.fillBefore(ae.empty,!0))),this.type?this.type.create(this.attrs,n,this.marks):n}popFromStashMark(t){for(let n=this.stashMarks.length-1;n>=0;n--)if(t.eq(this.stashMarks[n]))return this.stashMarks.splice(n,1)[0]}applyPending(t){for(let n=0,r=this.pendingMarks;n<r.length;n++){let a=r[n];(this.type?this.type.allowsMarkType(a.type):zd(a.type,t))&&!a.isInSet(this.activeMarks)&&(this.activeMarks=a.addToSet(this.activeMarks),this.pendingMarks=a.removeFromSet(this.pendingMarks))}}inlineContext(t){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:t.parentNode&&!ws.hasOwnProperty(t.parentNode.nodeName.toLowerCase())}}class _s{constructor(t,n,r){this.parser=t,this.options=n,this.isOpen=r,this.open=0;let a=n.topNode,o,l=Ss(null,n.preserveWhitespace,0)|(r?ln:0);a?o=new Bn(a.type,a.attrs,Re.none,Re.none,!0,n.topMatch||a.type.contentMatch,l):r?o=new Bn(null,null,Re.none,Re.none,!0,null,l):o=new Bn(t.schema.topNodeType,null,Re.none,Re.none,!0,null,l),this.nodes=[o],this.find=n.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(t){if(t.nodeType==3)this.addTextNode(t);else if(t.nodeType==1){let n=t.getAttribute("style");if(!n)this.addElement(t);else{let r=this.readStyles(Ad(n));if(!r)return;let[a,o]=r,l=this.top;for(let u=0;u<o.length;u++)this.removePendingMark(o[u],l);for(let u=0;u<a.length;u++)this.addPendingMark(a[u]);this.addElement(t);for(let u=0;u<a.length;u++)this.removePendingMark(a[u],l);for(let u=0;u<o.length;u++)this.addPendingMark(o[u])}}}addTextNode(t){let n=t.nodeValue,r=this.top;if(r.options&Pn||r.inlineContext(t)||/[^ \t\r\n\u000c]/.test(n)){if(r.options&On)r.options&Pn?n=n.replace(/\r\n?/g,`
|
|
101
|
+
`):n=n.replace(/\r?\n|\r/g," ");else if(n=n.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let a=r.content[r.content.length-1],o=t.previousSibling;(!a||o&&o.nodeName=="BR"||a.isText&&/[ \t\r\n\u000c]$/.test(a.text))&&(n=n.slice(1))}n&&this.insertNode(this.parser.schema.text(n)),this.findInText(t)}else this.findInside(t)}addElement(t,n){let r=t.nodeName.toLowerCase(),a;Cs.hasOwnProperty(r)&&this.parser.normalizeLists&&Id(t);let o=this.options.ruleFromNode&&this.options.ruleFromNode(t)||(a=this.parser.matchTag(t,this,n));if(o?o.ignore:Dd.hasOwnProperty(r))this.findInside(t),this.ignoreFallback(t);else if(!o||o.skip||o.closeParent){o&&o.closeParent?this.open=Math.max(0,this.open-1):o&&o.skip.nodeType&&(t=o.skip);let l,u=this.top,c=this.needsBlock;if(ws.hasOwnProperty(r))u.content.length&&u.content[0].isInline&&this.open&&(this.open--,u=this.top),l=!0,u.type||(this.needsBlock=!0);else if(!t.firstChild){this.leafFallback(t);return}this.addAll(t),l&&this.sync(u),this.needsBlock=c}else this.addElementByRule(t,o,o.consuming===!1?a:void 0)}leafFallback(t){t.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(t.ownerDocument.createTextNode(`
|
|
102
|
+
`))}ignoreFallback(t){t.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"))}readStyles(t){let n=Re.none,r=Re.none;for(let a=0;a<t.length;a+=2)for(let o=void 0;;){let l=this.parser.matchStyle(t[a],t[a+1],this,o);if(!l)break;if(l.ignore)return null;if(l.clearMark?this.top.pendingMarks.concat(this.top.activeMarks).forEach(u=>{l.clearMark(u)&&(r=u.addToSet(r))}):n=this.parser.schema.marks[l.mark].create(l.attrs).addToSet(n),l.consuming===!1)o=l;else break}return[n,r]}addElementByRule(t,n,r){let a,o,l;n.node?(o=this.parser.schema.nodes[n.node],o.isLeaf?this.insertNode(o.create(n.attrs))||this.leafFallback(t):a=this.enter(o,n.attrs||null,n.preserveWhitespace)):(l=this.parser.schema.marks[n.mark].create(n.attrs),this.addPendingMark(l));let u=this.top;if(o&&o.isLeaf)this.findInside(t);else if(r)this.addElement(t,r);else if(n.getContent)this.findInside(t),n.getContent(t,this.parser.schema).forEach(c=>this.insertNode(c));else{let c=t;typeof n.contentElement=="string"?c=t.querySelector(n.contentElement):typeof n.contentElement=="function"?c=n.contentElement(t):n.contentElement&&(c=n.contentElement),this.findAround(t,c,!0),this.addAll(c)}a&&this.sync(u)&&this.open--,l&&this.removePendingMark(l,u)}addAll(t,n,r){let a=n||0;for(let o=n?t.childNodes[n]:t.firstChild,l=r==null?null:t.childNodes[r];o!=l;o=o.nextSibling,++a)this.findAtPoint(t,a),this.addDOM(o);this.findAtPoint(t,a)}findPlace(t){let n,r;for(let a=this.open;a>=0;a--){let o=this.nodes[a],l=o.findWrapping(t);if(l&&(!n||n.length>l.length)&&(n=l,r=o,!l.length)||o.solid)break}if(!n)return!1;this.sync(r);for(let a=0;a<n.length;a++)this.enterInner(n[a],null,!1);return!0}insertNode(t){if(t.isInline&&this.needsBlock&&!this.top.type){let n=this.textblockFromContext();n&&this.enterInner(n)}if(this.findPlace(t)){this.closeExtra();let n=this.top;n.applyPending(t.type),n.match&&(n.match=n.match.matchType(t.type));let r=n.activeMarks;for(let a=0;a<t.marks.length;a++)(!n.type||n.type.allowsMarkType(t.marks[a].type))&&(r=t.marks[a].addToSet(r));return n.content.push(t.mark(r)),!0}return!1}enter(t,n,r){let a=this.findPlace(t.create(n));return a&&this.enterInner(t,n,!0,r),a}enterInner(t,n=null,r=!1,a){this.closeExtra();let o=this.top;o.applyPending(t),o.match=o.match&&o.match.matchType(t);let l=Ss(t,a,o.options);o.options&ln&&o.content.length==0&&(l|=ln),this.nodes.push(new Bn(t,n,o.activeMarks,o.pendingMarks,r,null,l)),this.open++}closeExtra(t=!1){let n=this.nodes.length-1;if(n>this.open){for(;n>this.open;n--)this.nodes[n-1].content.push(this.nodes[n].finish(t));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(t){for(let n=this.open;n>=0;n--)if(this.nodes[n]==t)return this.open=n,!0;return!1}get currentPos(){this.closeExtra();let t=0;for(let n=this.open;n>=0;n--){let r=this.nodes[n].content;for(let a=r.length-1;a>=0;a--)t+=r[a].nodeSize;n&&t++}return t}findAtPoint(t,n){if(this.find)for(let r=0;r<this.find.length;r++)this.find[r].node==t&&this.find[r].offset==n&&(this.find[r].pos=this.currentPos)}findInside(t){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].pos==null&&t.nodeType==1&&t.contains(this.find[n].node)&&(this.find[n].pos=this.currentPos)}findAround(t,n,r){if(t!=n&&this.find)for(let a=0;a<this.find.length;a++)this.find[a].pos==null&&t.nodeType==1&&t.contains(this.find[a].node)&&n.compareDocumentPosition(this.find[a].node)&(r?2:4)&&(this.find[a].pos=this.currentPos)}findInText(t){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==t&&(this.find[n].pos=this.currentPos-(t.nodeValue.length-this.find[n].offset))}matchesContext(t){if(t.indexOf("|")>-1)return t.split(/\s*\|\s*/).some(this.matchesContext,this);let n=t.split("/"),r=this.options.context,a=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),o=-(r?r.depth+1:0)+(a?0:1),l=(u,c)=>{for(;u>=0;u--){let d=n[u];if(d==""){if(u==n.length-1||u==0)continue;for(;c>=o;c--)if(l(u-1,c))return!0;return!1}else{let f=c>0||c==0&&a?this.nodes[c].type:r&&c>=o?r.node(c-o).type:null;if(!f||f.name!=d&&f.groups.indexOf(d)==-1)return!1;c--}}return!0};return l(n.length-1,this.open)}textblockFromContext(){let t=this.options.context;if(t)for(let n=t.depth;n>=0;n--){let r=t.node(n).contentMatchAt(t.indexAfter(n)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let n in this.parser.schema.nodes){let r=this.parser.schema.nodes[n];if(r.isTextblock&&r.defaultAttrs)return r}}addPendingMark(t){let n=Ed(t,this.top.pendingMarks);n&&this.top.stashMarks.push(n),this.top.pendingMarks=t.addToSet(this.top.pendingMarks)}removePendingMark(t,n){for(let r=this.open;r>=0;r--){let a=this.nodes[r];if(a.pendingMarks.lastIndexOf(t)>-1)a.pendingMarks=t.removeFromSet(a.pendingMarks);else{a.activeMarks=t.removeFromSet(a.activeMarks);let l=a.popFromStashMark(t);l&&a.type&&a.type.allowsMarkType(l.type)&&(a.activeMarks=l.addToSet(a.activeMarks))}if(a==n)break}}}function Id(e){for(let t=e.firstChild,n=null;t;t=t.nextSibling){let r=t.nodeType==1?t.nodeName.toLowerCase():null;r&&Cs.hasOwnProperty(r)&&n?(n.appendChild(t),t=n):r=="li"?n=t:r&&(n=null)}}function Md(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function Ad(e){let t=/\s*([\w-]+)\s*:\s*([^;]+)/g,n,r=[];for(;n=t.exec(e);)r.push(n[1],n[2].trim());return r}function ks(e){let t={};for(let n in e)t[n]=e[n];return t}function zd(e,t){let n=t.schema.nodes;for(let r in n){let a=n[r];if(!a.allowsMarkType(e))continue;let o=[],l=u=>{o.push(u);for(let c=0;c<u.edgeCount;c++){let{type:d,next:f}=u.edge(c);if(d==t||o.indexOf(f)<0&&l(f))return!0}};if(l(a.contentMatch))return!0}}function Ed(e,t){for(let n=0;n<t.length;n++)if(e.eq(t[n]))return t[n]}const Ts=65535,Ds=Math.pow(2,16);function $d(e,t){return e+t*Ds}function Is(e){return e&Ts}function Ld(e){return(e-(e&Ts))/Ds}const Ms=1,As=2,Vn=4,zs=8;class Es{constructor(t,n,r){this.pos=t,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&zs)>0}get deletedBefore(){return(this.delInfo&(Ms|Vn))>0}get deletedAfter(){return(this.delInfo&(As|Vn))>0}get deletedAcross(){return(this.delInfo&Vn)>0}}class Je{constructor(t,n=!1){if(this.ranges=t,this.inverted=n,!t.length&&Je.empty)return Je.empty}recover(t){let n=0,r=Is(t);if(!this.inverted)for(let a=0;a<r;a++)n+=this.ranges[a*3+2]-this.ranges[a*3+1];return this.ranges[r*3]+n+Ld(t)}mapResult(t,n=1){return this._map(t,n,!1)}map(t,n=1){return this._map(t,n,!0)}_map(t,n,r){let a=0,o=this.inverted?2:1,l=this.inverted?1:2;for(let u=0;u<this.ranges.length;u+=3){let c=this.ranges[u]-(this.inverted?a:0);if(c>t)break;let d=this.ranges[u+o],f=this.ranges[u+l],h=c+d;if(t<=h){let g=d?t==c?-1:t==h?1:n:n,m=c+a+(g<0?0:f);if(r)return m;let C=t==(n<0?c:h)?null:$d(u/3,t-c),w=t==c?As:t==h?Ms:Vn;return(n<0?t!=c:t!=h)&&(w|=zs),new Es(m,w,C)}a+=f-d}return r?t+a:new Es(t+a,0,null)}touches(t,n){let r=0,a=Is(n),o=this.inverted?2:1,l=this.inverted?1:2;for(let u=0;u<this.ranges.length;u+=3){let c=this.ranges[u]-(this.inverted?r:0);if(c>t)break;let d=this.ranges[u+o],f=c+d;if(t<=f&&u==a*3)return!0;r+=this.ranges[u+l]-d}return!1}forEach(t){let n=this.inverted?2:1,r=this.inverted?1:2;for(let a=0,o=0;a<this.ranges.length;a+=3){let l=this.ranges[a],u=l-(this.inverted?o:0),c=l+(this.inverted?0:o),d=this.ranges[a+n],f=this.ranges[a+r];t(u,u+d,c,c+f),o+=f-d}}invert(){return new Je(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(t){return t==0?Je.empty:new Je(t<0?[0,-t,0]:[0,0,t])}}Je.empty=new Je([]);const Br=Object.create(null);class qe{getMap(){return Je.empty}merge(t){return null}static fromJSON(t,n){if(!n||!n.stepType)throw new RangeError("Invalid input for Step.fromJSON");let r=Br[n.stepType];if(!r)throw new RangeError(`No step type ${n.stepType} defined`);return r.fromJSON(t,n)}static jsonID(t,n){if(t in Br)throw new RangeError("Duplicate use of step JSON ID "+t);return Br[t]=n,n.prototype.jsonID=t,n}}class Se{constructor(t,n){this.doc=t,this.failed=n}static ok(t){return new Se(t,null)}static fail(t){return new Se(null,t)}static fromReplace(t,n,r,a){try{return Se.ok(t.replace(n,r,a))}catch(o){if(o instanceof Td)return Se.fail(o.message);throw o}}}function Vr(e,t,n){let r=[];for(let a=0;a<e.childCount;a++){let o=e.child(a);o.content.size&&(o=o.copy(Vr(o.content,t,o))),o.isInline&&(o=t(o,n,a)),r.push(o)}return ae.fromArray(r)}class Et extends qe{constructor(t,n,r){super(),this.from=t,this.to=n,this.mark=r}apply(t){let n=t.slice(this.from,this.to),r=t.resolve(this.from),a=r.node(r.sharedDepth(this.to)),o=new ce(Vr(n.content,(l,u)=>!l.isAtom||!u.type.allowsMarkType(this.mark.type)?l:l.mark(this.mark.addToSet(l.marks)),a),n.openStart,n.openEnd);return Se.fromReplace(t,this.from,this.to,o)}invert(){return new $t(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new Et(n.pos,r.pos,this.mark)}merge(t){return t instanceof Et&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new Et(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new Et(n.from,n.to,t.markFromJSON(n.mark))}}qe.jsonID("addMark",Et);class $t extends qe{constructor(t,n,r){super(),this.from=t,this.to=n,this.mark=r}apply(t){let n=t.slice(this.from,this.to),r=new ce(Vr(n.content,a=>a.mark(this.mark.removeFromSet(a.marks)),t),n.openStart,n.openEnd);return Se.fromReplace(t,this.from,this.to,r)}invert(){return new Et(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new $t(n.pos,r.pos,this.mark)}merge(t){return t instanceof $t&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new $t(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new $t(n.from,n.to,t.markFromJSON(n.mark))}}qe.jsonID("removeMark",$t);class Lt extends qe{constructor(t,n){super(),this.pos=t,this.mark=n}apply(t){let n=t.nodeAt(this.pos);if(!n)return Se.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return Se.fromReplace(t,this.pos,this.pos+1,new ce(ae.from(r),0,n.isLeaf?0:1))}invert(t){let n=t.nodeAt(this.pos);if(n){let r=this.mark.addToSet(n.marks);if(r.length==n.marks.length){for(let a=0;a<n.marks.length;a++)if(!n.marks[a].isInSet(r))return new Lt(this.pos,n.marks[a]);return new Lt(this.pos,this.mark)}}return new un(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new Lt(n.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new Lt(n.pos,t.markFromJSON(n.mark))}}qe.jsonID("addNodeMark",Lt);class un extends qe{constructor(t,n){super(),this.pos=t,this.mark=n}apply(t){let n=t.nodeAt(this.pos);if(!n)return Se.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.removeFromSet(n.marks));return Se.fromReplace(t,this.pos,this.pos+1,new ce(ae.from(r),0,n.isLeaf?0:1))}invert(t){let n=t.nodeAt(this.pos);return!n||!this.mark.isInSet(n.marks)?this:new Lt(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new un(n.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new un(n.pos,t.markFromJSON(n.mark))}}qe.jsonID("removeNodeMark",un);class lt extends qe{constructor(t,n,r,a=!1){super(),this.from=t,this.to=n,this.slice=r,this.structure=a}apply(t){return this.structure&&Nr(t,this.from,this.to)?Se.fail("Structure replace would overwrite content"):Se.fromReplace(t,this.from,this.to,this.slice)}getMap(){return new Je([this.from,this.to-this.from,this.slice.size])}invert(t){return new lt(this.from,this.from+this.slice.size,t.slice(this.from,this.to))}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deletedAcross&&r.deletedAcross?null:new lt(n.pos,Math.max(n.pos,r.pos),this.slice)}merge(t){if(!(t instanceof lt)||t.structure||this.structure)return null;if(this.from+this.slice.size==t.from&&!this.slice.openEnd&&!t.slice.openStart){let n=this.slice.size+t.slice.size==0?ce.empty:new ce(this.slice.content.append(t.slice.content),this.slice.openStart,t.slice.openEnd);return new lt(this.from,this.to+(t.to-t.from),n,this.structure)}else if(t.to==this.from&&!this.slice.openStart&&!t.slice.openEnd){let n=this.slice.size+t.slice.size==0?ce.empty:new ce(t.slice.content.append(this.slice.content),t.slice.openStart,this.slice.openEnd);return new lt(t.from,this.to,n,this.structure)}else return null}toJSON(){let t={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(t.slice=this.slice.toJSON()),this.structure&&(t.structure=!0),t}static fromJSON(t,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new lt(n.from,n.to,ce.fromJSON(t,n.slice),!!n.structure)}}qe.jsonID("replace",lt);class Ot extends qe{constructor(t,n,r,a,o,l,u=!1){super(),this.from=t,this.to=n,this.gapFrom=r,this.gapTo=a,this.slice=o,this.insert=l,this.structure=u}apply(t){if(this.structure&&(Nr(t,this.from,this.gapFrom)||Nr(t,this.gapTo,this.to)))return Se.fail("Structure gap-replace would overwrite content");let n=t.slice(this.gapFrom,this.gapTo);if(n.openStart||n.openEnd)return Se.fail("Gap is not a flat range");let r=this.slice.insertAt(this.insert,n.content);return r?Se.fromReplace(t,this.from,this.to,r):Se.fail("Content does not fit in gap")}getMap(){return new Je([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(t){let n=this.gapTo-this.gapFrom;return new Ot(this.from,this.from+this.slice.size+n,this.from+this.insert,this.from+this.insert+n,t.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1),a=t.map(this.gapFrom,-1),o=t.map(this.gapTo,1);return n.deletedAcross&&r.deletedAcross||a<n.pos||o>r.pos?null:new Ot(n.pos,r.pos,a,o,this.slice,this.insert,this.structure)}toJSON(){let t={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(t.slice=this.slice.toJSON()),this.structure&&(t.structure=!0),t}static fromJSON(t,n){if(typeof n.from!="number"||typeof n.to!="number"||typeof n.gapFrom!="number"||typeof n.gapTo!="number"||typeof n.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Ot(n.from,n.to,n.gapFrom,n.gapTo,ce.fromJSON(t,n.slice),n.insert,!!n.structure)}}qe.jsonID("replaceAround",Ot);function Nr(e,t,n){let r=e.resolve(t),a=n-t,o=r.depth;for(;a>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,a--;if(a>0){let l=r.node(o).maybeChild(r.indexAfter(o));for(;a>0;){if(!l||l.isLeaf)return!0;l=l.firstChild,a--}}return!1}function Od(e,t,n){return(t==0||e.canReplace(t,e.childCount))&&(n==e.childCount||e.canReplace(0,n))}function Pd(e){let n=e.parent.content.cutByIndex(e.startIndex,e.endIndex);for(let r=e.depth;;--r){let a=e.$from.node(r),o=e.$from.index(r),l=e.$to.indexAfter(r);if(r<e.depth&&a.canReplace(o,l,n))return r;if(r==0||a.type.spec.isolating||!Od(a,o,l))break}return null}function Nn(e,t,n=1,r){let a=e.resolve(t),o=a.depth-n,l=r&&r[r.length-1]||a.parent;if(o<0||a.parent.type.spec.isolating||!a.parent.canReplace(a.index(),a.parent.childCount)||!l.type.validContent(a.parent.content.cutByIndex(a.index(),a.parent.childCount)))return!1;for(let d=a.depth-1,f=n-2;d>o;d--,f--){let h=a.node(d),g=a.index(d);if(h.type.spec.isolating)return!1;let m=h.content.cutByIndex(g,h.childCount),C=r&&r[f+1];C&&(m=m.replaceChild(0,C.type.create(C.attrs)));let w=r&&r[f]||h;if(!h.canReplace(g+1,h.childCount)||!w.type.validContent(m))return!1}let u=a.indexAfter(o),c=r&&r[0];return a.node(o).canReplaceWith(u,u,c?c.type:a.node(o+1).type)}function $s(e,t){let n=e.resolve(t),r=n.index();return Bd(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function Bd(e,t){return!!(e&&t&&!e.isLeaf&&e.canAppend(t))}class cn extends qe{constructor(t,n,r){super(),this.pos=t,this.attr=n,this.value=r}apply(t){let n=t.nodeAt(this.pos);if(!n)return Se.fail("No node at attribute step's position");let r=Object.create(null);for(let o in n.attrs)r[o]=n.attrs[o];r[this.attr]=this.value;let a=n.type.create(r,null,n.marks);return Se.fromReplace(t,this.pos,this.pos+1,new ce(ae.from(a),0,n.isLeaf?0:1))}getMap(){return Je.empty}invert(t){return new cn(this.pos,this.attr,t.nodeAt(this.pos).attrs[this.attr])}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new cn(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(t,n){if(typeof n.pos!="number"||typeof n.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new cn(n.pos,n.attr,n.value)}}qe.jsonID("attr",cn);let dn=class extends Error{};dn=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n},dn.prototype=Object.create(Error.prototype),dn.prototype.constructor=dn,dn.prototype.name="TransformError";const qr=Object.create(null);class fe{constructor(t,n,r){this.$anchor=t,this.$head=n,this.ranges=r||[new Vd(t.min(n),t.max(n))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let t=this.ranges;for(let n=0;n<t.length;n++)if(t[n].$from.pos!=t[n].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(t,n=ce.empty){let r=n.content.lastChild,a=null;for(let u=0;u<n.openEnd;u++)a=r,r=r.lastChild;let o=t.steps.length,l=this.ranges;for(let u=0;u<l.length;u++){let{$from:c,$to:d}=l[u],f=t.mapping.slice(o);t.replaceRange(f.map(c.pos),f.map(d.pos),u?ce.empty:n),u==0&&Ps(t,o,(r?r.isInline:a&&a.isTextblock)?-1:1)}}replaceWith(t,n){let r=t.steps.length,a=this.ranges;for(let o=0;o<a.length;o++){let{$from:l,$to:u}=a[o],c=t.mapping.slice(r),d=c.map(l.pos),f=c.map(u.pos);o?t.deleteRange(d,f):(t.replaceRangeWith(d,f,n),Ps(t,r,n.isInline?-1:1))}}static findFrom(t,n,r=!1){let a=t.parent.inlineContent?new _e(t):Ft(t.node(0),t.parent,t.pos,t.index(),n,r);if(a)return a;for(let o=t.depth-1;o>=0;o--){let l=n<0?Ft(t.node(0),t.node(o),t.before(o+1),t.index(o),n,r):Ft(t.node(0),t.node(o),t.after(o+1),t.index(o)+1,n,r);if(l)return l}return null}static near(t,n=1){return this.findFrom(t,n)||this.findFrom(t,-n)||new gt(t.node(0))}static atStart(t){return Ft(t,t,0,0,1)||new gt(t)}static atEnd(t){return Ft(t,t,t.content.size,t.childCount,-1)||new gt(t)}static fromJSON(t,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=qr[n.type];if(!r)throw new RangeError(`No selection type ${n.type} defined`);return r.fromJSON(t,n)}static jsonID(t,n){if(t in qr)throw new RangeError("Duplicate use of selection JSON ID "+t);return qr[t]=n,n.prototype.jsonID=t,n}getBookmark(){return _e.between(this.$anchor,this.$head).getBookmark()}}fe.prototype.visible=!0;class Vd{constructor(t,n){this.$from=t,this.$to=n}}let Ls=!1;function Os(e){!Ls&&!e.parent.inlineContent&&(Ls=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+e.parent.type.name+")"))}class _e extends fe{constructor(t,n=t){Os(t),Os(n),super(t,n)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(t,n){let r=t.resolve(n.map(this.head));if(!r.parent.inlineContent)return fe.near(r);let a=t.resolve(n.map(this.anchor));return new _e(a.parent.inlineContent?a:r,r)}replace(t,n=ce.empty){if(super.replace(t,n),n==ce.empty){let r=this.$from.marksAcross(this.$to);r&&t.ensureMarks(r)}}eq(t){return t instanceof _e&&t.anchor==this.anchor&&t.head==this.head}getBookmark(){return new qn(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(t,n){if(typeof n.anchor!="number"||typeof n.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new _e(t.resolve(n.anchor),t.resolve(n.head))}static create(t,n,r=n){let a=t.resolve(n);return new this(a,r==n?a:t.resolve(r))}static between(t,n,r){let a=t.pos-n.pos;if((!r||a)&&(r=a>=0?1:-1),!n.parent.inlineContent){let o=fe.findFrom(n,r,!0)||fe.findFrom(n,-r,!0);if(o)n=o.$head;else return fe.near(n,r)}return t.parent.inlineContent||(a==0?t=n:(t=(fe.findFrom(t,-r,!0)||fe.findFrom(t,r,!0)).$anchor,t.pos<n.pos!=a<0&&(t=n))),new _e(t,n)}}fe.jsonID("text",_e);class qn{constructor(t,n){this.anchor=t,this.head=n}map(t){return new qn(t.map(this.anchor),t.map(this.head))}resolve(t){return _e.between(t.resolve(this.anchor),t.resolve(this.head))}}class Ye extends fe{constructor(t){let n=t.nodeAfter,r=t.node(0).resolve(t.pos+n.nodeSize);super(t,r),this.node=n}map(t,n){let{deleted:r,pos:a}=n.mapResult(this.anchor),o=t.resolve(a);return r?fe.near(o):new Ye(o)}content(){return new ce(ae.from(this.node),0,0)}eq(t){return t instanceof Ye&&t.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new Fr(this.anchor)}static fromJSON(t,n){if(typeof n.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new Ye(t.resolve(n.anchor))}static create(t,n){return new Ye(t.resolve(n))}static isSelectable(t){return!t.isText&&t.type.spec.selectable!==!1}}Ye.prototype.visible=!1,fe.jsonID("node",Ye);class Fr{constructor(t){this.anchor=t}map(t){let{deleted:n,pos:r}=t.mapResult(this.anchor);return n?new qn(r,r):new Fr(r)}resolve(t){let n=t.resolve(this.anchor),r=n.nodeAfter;return r&&Ye.isSelectable(r)?new Ye(n):fe.near(n)}}class gt extends fe{constructor(t){super(t.resolve(0),t.resolve(t.content.size))}replace(t,n=ce.empty){if(n==ce.empty){t.delete(0,t.doc.content.size);let r=fe.atStart(t.doc);r.eq(t.selection)||t.setSelection(r)}else super.replace(t,n)}toJSON(){return{type:"all"}}static fromJSON(t){return new gt(t)}map(t){return new gt(t)}eq(t){return t instanceof gt}getBookmark(){return Nd}}fe.jsonID("all",gt);const Nd={map(){return this},resolve(e){return new gt(e)}};function Ft(e,t,n,r,a,o=!1){if(t.inlineContent)return _e.create(e,n);for(let l=r-(a>0?0:1);a>0?l<t.childCount:l>=0;l+=a){let u=t.child(l);if(u.isAtom){if(!o&&Ye.isSelectable(u))return Ye.create(e,n-(a<0?u.nodeSize:0))}else{let c=Ft(e,u,n+a,a<0?u.childCount:0,a,o);if(c)return c}n+=u.nodeSize*a}return null}function Ps(e,t,n){let r=e.steps.length-1;if(r<t)return;let a=e.steps[r];if(!(a instanceof lt||a instanceof Ot))return;let o=e.mapping.maps[r],l;o.forEach((u,c,d,f)=>{l==null&&(l=f)}),e.setSelection(fe.near(e.doc.resolve(l),n))}function Bs(e,t){return!t||!e?e:e.bind(t)}class Fn{constructor(t,n,r){this.name=t,this.init=Bs(n.init,r),this.apply=Bs(n.apply,r)}}new Fn("doc",{init(e){return e.doc||e.schema.topNodeType.createAndFill()},apply(e){return e.doc}}),new Fn("selection",{init(e,t){return e.selection||fe.atStart(t.doc)},apply(e){return e.selection}}),new Fn("storedMarks",{init(e){return e.storedMarks||null},apply(e,t,n,r){return r.selection.$cursor?e.storedMarks:null}}),new Fn("scrollToSelection",{init(){return 0},apply(e,t){return e.scrolledIntoView?t+1:t}});function Vs(e,t,n){for(let r in e){let a=e[r];a instanceof Function?a=a.bind(t):r=="handleDOMEvents"&&(a=Vs(a,t,{})),n[r]=a}return n}class pn{constructor(t){this.spec=t,this.props={},t.props&&Vs(t.props,this,this.props),this.key=t.key?t.key.key:Ns("plugin")}getState(t){return t[this.key]}}const Gr=Object.create(null);function Ns(e){return e in Gr?e+"$"+ ++Gr[e]:(Gr[e]=0,e+"$")}class hn{constructor(t="key"){this.key=Ns(t)}get(t){return t.config.pluginsByKey[this.key]}getState(t){return t[this.key]}}function qs(e){const{state:t,transaction:n}=e;let{selection:r}=n,{doc:a}=n,{storedMarks:o}=n;return{...t,apply:t.apply.bind(t),applyTransaction:t.applyTransaction.bind(t),filterTransaction:t.filterTransaction,plugins:t.plugins,schema:t.schema,reconfigure:t.reconfigure.bind(t),toJSON:t.toJSON.bind(t),get storedMarks(){return o},get selection(){return r},get doc(){return a},get tr(){return r=n.selection,a=n.doc,o=n.storedMarks,n}}}class qd{constructor(t){this.editor=t.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=t.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){const{rawCommands:t,editor:n,state:r}=this,{view:a}=n,{tr:o}=r,l=this.buildProps(o);return Object.fromEntries(Object.entries(t).map(([u,c])=>[u,(...f)=>{const h=c(...f)(l);return!o.getMeta("preventDispatch")&&!this.hasCustomState&&a.dispatch(o),h}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(t,n=!0){const{rawCommands:r,editor:a,state:o}=this,{view:l}=a,u=[],c=!!t,d=t||o.tr,f=()=>(!c&&n&&!d.getMeta("preventDispatch")&&!this.hasCustomState&&l.dispatch(d),u.every(g=>g===!0)),h={...Object.fromEntries(Object.entries(r).map(([g,m])=>[g,(...w)=>{const _=this.buildProps(d,n),T=m(...w)(_);return u.push(T),h}])),run:f};return h}createCan(t){const{rawCommands:n,state:r}=this,a=!1,o=t||r.tr,l=this.buildProps(o,a);return{...Object.fromEntries(Object.entries(n).map(([c,d])=>[c,(...f)=>d(...f)({...l,dispatch:void 0})])),chain:()=>this.createChain(o,a)}}buildProps(t,n=!0){const{rawCommands:r,editor:a,state:o}=this,{view:l}=a;o.storedMarks&&t.setStoredMarks(o.storedMarks);const u={tr:t,editor:a,view:l,state:qs({state:o,transaction:t}),dispatch:n?()=>{}:void 0,chain:()=>this.createChain(t),can:()=>this.createCan(t),get commands(){return Object.fromEntries(Object.entries(r).map(([c,d])=>[c,(...f)=>d(...f)(u)]))}};return u}}function St(e,t,n){return e.config[t]===void 0&&e.parent?St(e.parent,t,n):typeof e.config[t]=="function"?e.config[t].bind({...n,parent:e.parent?St(e.parent,t,n):null}):e.config[t]}function Fd(e){const t=e.filter(a=>a.type==="extension"),n=e.filter(a=>a.type==="node"),r=e.filter(a=>a.type==="mark");return{baseExtensions:t,nodeExtensions:n,markExtensions:r}}function Ae(e,t){if(typeof e=="string"){if(!t.nodes[e])throw Error(`There is no node type named '${e}'. Maybe you forgot to add the extension?`);return t.nodes[e]}return e}function Gd(e){return typeof e=="function"}function Gt(e,t=void 0,...n){return Gd(e)?t?e.bind(t)(...n):e(...n):e}function Wd(e){return Object.prototype.toString.call(e)==="[object RegExp]"}function jd(e){return Object.prototype.toString.call(e).slice(8,-1)}function Wr(e){return jd(e)!=="Object"?!1:e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype}function Fs(e,t){const n={...e};return Wr(e)&&Wr(t)&&Object.keys(t).forEach(r=>{Wr(t[r])?r in e?n[r]=Fs(e[r],t[r]):Object.assign(n,{[r]:t[r]}):Object.assign(n,{[r]:t[r]})}),n}class ut{constructor(t={}){this.type="extension",this.name="extension",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...t},this.name=this.config.name,t.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=Gt(St(this,"addOptions",{name:this.name}))),this.storage=Gt(St(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(t={}){return new ut(t)}configure(t={}){const n=this.extend();return n.options=Fs(this.options,t),n.storage=Gt(St(n,"addStorage",{name:n.name,options:n.options})),n}extend(t={}){const n=new ut(t);return n.parent=this,this.child=n,n.name=t.name?t.name:n.parent.name,t.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${n.name}".`),n.options=Gt(St(n,"addOptions",{name:n.name})),n.storage=Gt(St(n,"addStorage",{name:n.name,options:n.options})),n}}function Rd(e,t,n){const{from:r,to:a}=t,{blockSeparator:o=`
|
|
103
103
|
|
|
104
|
-
`,textSerializers:l={}}=n||{};let u="",c=!0;return e.nodesBetween(r,a,(d,f,h,g)=>{var m;const C=l==null?void 0:l[d.type.name];C?(d.isBlock&&!c&&(u+=o,c=!0),h&&(u+=C({node:d,pos:f,parent:h,index:g,range:t}))):d.isText?(u+=(m=d==null?void 0:d.text)===null||m===void 0?void 0:m.slice(Math.max(r,f)-f,a-f),c=!1):d.isBlock&&!c&&(u+=o,c=!0)}),u}function jd(e){return Object.fromEntries(Object.entries(e.nodes).filter(([,t])=>t.spec.toText).map(([t,n])=>[t,n.spec.toText]))}ut.create({name:"clipboardTextSerializer",addProseMirrorPlugins(){return[new pn({key:new hn("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:e}=this,{state:t,schema:n}=e,{doc:r,selection:a}=t,{ranges:o}=a,l=Math.min(...o.map(f=>f.$from.pos)),u=Math.max(...o.map(f=>f.$to.pos)),c=jd(n);return Wd(r,{from:l,to:u},{textSerializers:c})}}})]}});const Rd=()=>({editor:e,view:t})=>(requestAnimationFrame(()=>{var n;e.isDestroyed||(t.dom.blur(),(n=window==null?void 0:window.getSelection())===null||n===void 0||n.removeAllRanges())}),!0),Yd=(e=!1)=>({commands:t})=>t.setContent("",e),Qd=()=>({state:e,tr:t,dispatch:n})=>{const{selection:r}=t,{ranges:a}=r;return n&&a.forEach(({$from:o,$to:l})=>{e.doc.nodesBetween(o.pos,l.pos,(u,c)=>{if(u.type.isText)return;const{doc:d,mapping:f}=t,h=d.resolve(f.map(c)),g=d.resolve(f.map(c+u.nodeSize)),m=h.blockRange(g);if(!m)return;const C=Ld(m);if(u.type.isTextblock){const{defaultType:w}=h.parent.contentMatchAt(h.index());t.setNodeMarkup(m.start,w)}(C||C===0)&&t.lift(m,C)})}),!0},Ud=e=>t=>e(t),Kd=()=>({state:e,dispatch:t})=>Te.createParagraphNear(e,t),Xd=()=>({tr:e,dispatch:t})=>{const{selection:n}=e,r=n.$anchor.node();if(r.content.size>0)return!1;const a=e.selection.$anchor;for(let o=a.depth;o>0;o-=1)if(a.node(o).type===r.type){if(t){const u=a.before(o),c=a.after(o);e.delete(u,c).scrollIntoView()}return!0}return!1},Jd=e=>({tr:t,state:n,dispatch:r})=>{const a=Ae(e,n.schema),o=t.selection.$anchor;for(let l=o.depth;l>0;l-=1)if(o.node(l).type===a){if(r){const c=o.before(l),d=o.after(l);t.delete(c,d).scrollIntoView()}return!0}return!1},Zd=e=>({tr:t,dispatch:n})=>{const{from:r,to:a}=e;return n&&t.delete(r,a),!0},Hd=()=>({state:e,dispatch:t})=>Te.deleteSelection(e,t),ep=()=>({commands:e})=>e.keyboardShortcut("Enter"),tp=()=>({state:e,dispatch:t})=>Te.exitCode(e,t);function Gn(e,t,n={strict:!0}){const r=Object.keys(t);return r.length?r.every(a=>n.strict?t[a]===e[a]:Fd(t[a])?t[a].test(e[a]):t[a]===e[a]):!0}function jr(e,t,n={}){return e.find(r=>r.type===t&&Gn(r.attrs,n))}function np(e,t,n={}){return!!jr(e,t,n)}function qs(e,t,n={}){if(!e||!t)return;let r=e.parent.childAfter(e.parentOffset);if(e.parentOffset===r.offset&&r.offset!==0&&(r=e.parent.childBefore(e.parentOffset)),!r.node)return;const a=jr([...r.node.marks],t,n);if(!a)return;let o=r.index,l=e.start()+r.offset,u=o+1,c=l+r.node.nodeSize;for(jr([...r.node.marks],t,n);o>0&&a.isInSet(e.parent.child(o-1).marks);)o-=1,l-=e.parent.child(o).nodeSize;for(;u<e.parent.childCount&&np([...e.parent.child(u).marks],t,n);)c+=e.parent.child(u).nodeSize,u+=1;return{from:l,to:c}}function _t(e,t){if(typeof e=="string"){if(!t.marks[e])throw Error(`There is no mark type named '${e}'. Maybe you forgot to add the extension?`);return t.marks[e]}return e}const rp=(e,t={})=>({tr:n,state:r,dispatch:a})=>{const o=_t(e,r.schema),{doc:l,selection:u}=n,{$from:c,from:d,to:f}=u;if(a){const h=qs(c,o,t);if(h&&h.from<=d&&h.to>=f){const g=_e.create(l,h.from,h.to);n.setSelection(g)}}return!0},ip=e=>t=>{const n=typeof e=="function"?e(t):e;for(let r=0;r<n.length;r+=1)if(n[r](t))return!0;return!1};function Fs(e){return e instanceof _e}function Pt(e=0,t=0,n=0){return Math.min(Math.max(e,t),n)}function ap(e,t=null){if(!t)return null;const n=fe.atStart(e),r=fe.atEnd(e);if(t==="start"||t===!0)return n;if(t==="end")return r;const a=n.from,o=r.to;return t==="all"?_e.create(e,Pt(0,a,o),Pt(e.content.size,a,o)):_e.create(e,Pt(t,a,o),Pt(t,a,o))}function Rr(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}const sp=(e=null,t={})=>({editor:n,view:r,tr:a,dispatch:o})=>{t={scrollIntoView:!0,...t};const l=()=>{Rr()&&r.dom.focus(),requestAnimationFrame(()=>{n.isDestroyed||(r.focus(),t!=null&&t.scrollIntoView&&n.commands.scrollIntoView())})};if(r.hasFocus()&&e===null||e===!1)return!0;if(o&&e===null&&!Fs(n.state.selection))return l(),!0;const u=ap(a.doc,e)||n.state.selection,c=n.state.selection.eq(u);return o&&(c||a.setSelection(u),c&&a.storedMarks&&a.setStoredMarks(a.storedMarks),l()),!0},op=(e,t)=>n=>e.every((r,a)=>t(r,{...n,index:a})),lp=(e,t)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},e,t);function Gs(e){const t=`<body>${e}</body>`;return new window.DOMParser().parseFromString(t,"text/html").body}function Wn(e,t,n){if(n={slice:!0,parseOptions:{},...n},typeof e=="object"&&e!==null)try{return Array.isArray(e)&&e.length>0?ae.fromArray(e.map(r=>t.nodeFromJSON(r))):t.nodeFromJSON(e)}catch(r){return console.warn("[tiptap warn]: Invalid content.","Passed value:",e,"Error:",r),Wn("",t,n)}if(typeof e=="string"){const r=Ln.fromSchema(t);return n.slice?r.parseSlice(Gs(e),n.parseOptions).content:r.parse(Gs(e),n.parseOptions)}return Wn("",t,n)}function up(e,t,n){const r=e.steps.length-1;if(r<t)return;const a=e.steps[r];if(!(a instanceof lt||a instanceof Ot))return;const o=e.mapping.maps[r];let l=0;o.forEach((u,c,d,f)=>{l===0&&(l=f)}),e.setSelection(fe.near(e.doc.resolve(l),n))}const cp=e=>e.toString().startsWith("<"),dp=(e,t,n)=>({tr:r,dispatch:a,editor:o})=>{if(a){n={parseOptions:{},updateSelection:!0,...n};const l=Wn(t,o.schema,{parseOptions:{preserveWhitespace:"full",...n.parseOptions}});if(l.toString()==="<>")return!0;let{from:u,to:c}=typeof e=="number"?{from:e,to:e}:e,d=!0,f=!0;if((cp(l)?l:[l]).forEach(g=>{g.check(),d=d?g.isText&&g.marks.length===0:!1,f=f?g.isBlock:!1}),u===c&&f){const{parent:g}=r.doc.resolve(u);g.isTextblock&&!g.type.spec.code&&!g.childCount&&(u-=1,c+=1)}d?Array.isArray(t)?r.insertText(t.map(g=>g.text||"").join(""),u,c):typeof t=="object"&&t&&t.text?r.insertText(t.text,u,c):r.insertText(t,u,c):r.replaceWith(u,c,l),n.updateSelection&&up(r,r.steps.length-1,-1)}return!0},pp=()=>({state:e,dispatch:t})=>Te.joinUp(e,t),hp=()=>({state:e,dispatch:t})=>Te.joinDown(e,t),fp=()=>({state:e,dispatch:t})=>Te.joinBackward(e,t),gp=()=>({state:e,dispatch:t})=>Te.joinForward(e,t);function Ws(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function mp(e){const t=e.split(/-(?!$)/);let n=t[t.length-1];n==="Space"&&(n=" ");let r,a,o,l;for(let u=0;u<t.length-1;u+=1){const c=t[u];if(/^(cmd|meta|m)$/i.test(c))l=!0;else if(/^a(lt)?$/i.test(c))r=!0;else if(/^(c|ctrl|control)$/i.test(c))a=!0;else if(/^s(hift)?$/i.test(c))o=!0;else if(/^mod$/i.test(c))Rr()||Ws()?l=!0:a=!0;else throw new Error(`Unrecognized modifier name: ${c}`)}return r&&(n=`Alt-${n}`),a&&(n=`Ctrl-${n}`),l&&(n=`Meta-${n}`),o&&(n=`Shift-${n}`),n}const yp=e=>({editor:t,view:n,tr:r,dispatch:a})=>{const o=mp(e).split(/-(?!$)/),l=o.find(d=>!["Alt","Ctrl","Meta","Shift"].includes(d)),u=new KeyboardEvent("keydown",{key:l==="Space"?" ":l,altKey:o.includes("Alt"),ctrlKey:o.includes("Ctrl"),metaKey:o.includes("Meta"),shiftKey:o.includes("Shift"),bubbles:!0,cancelable:!0}),c=t.captureTransaction(()=>{n.someProp("handleKeyDown",d=>d(n,u))});return c==null||c.steps.forEach(d=>{const f=d.map(r.mapping);f&&a&&r.maybeStep(f)}),!0};function Yr(e,t,n={}){const{from:r,to:a,empty:o}=e.selection,l=t?Ae(t,e.schema):null,u=[];e.doc.nodesBetween(r,a,(h,g)=>{if(h.isText)return;const m=Math.max(r,g),C=Math.min(a,g+h.nodeSize);u.push({node:h,from:m,to:C})});const c=a-r,d=u.filter(h=>l?l.name===h.node.type.name:!0).filter(h=>Gn(h.node.attrs,n,{strict:!1}));return o?!!d.length:d.reduce((h,g)=>h+g.to-g.from,0)>=c}const bp=(e,t={})=>({state:n,dispatch:r})=>{const a=Ae(e,n.schema);return Yr(n,a,t)?Te.lift(n,r):!1},vp=()=>({state:e,dispatch:t})=>Te.liftEmptyBlock(e,t),xp=e=>({state:t,dispatch:n})=>{const r=Ae(e,t.schema);return yr.liftListItem(r)(t,n)},wp=()=>({state:e,dispatch:t})=>Te.newlineInCode(e,t);function js(e,t){return t.nodes[e]?"node":t.marks[e]?"mark":null}function Rs(e,t){const n=typeof t=="string"?[t]:t;return Object.keys(e).reduce((r,a)=>(n.includes(a)||(r[a]=e[a]),r),{})}const Cp=(e,t)=>({tr:n,state:r,dispatch:a})=>{let o=null,l=null;const u=js(typeof e=="string"?e:e.name,r.schema);return u?(u==="node"&&(o=Ae(e,r.schema)),u==="mark"&&(l=_t(e,r.schema)),a&&n.selection.ranges.forEach(c=>{r.doc.nodesBetween(c.$from.pos,c.$to.pos,(d,f)=>{o&&o===d.type&&n.setNodeMarkup(f,void 0,Rs(d.attrs,t)),l&&d.marks.length&&d.marks.forEach(h=>{l===h.type&&n.addMark(f,f+d.nodeSize,l.create(Rs(h.attrs,t)))})})}),!0):!1},Sp=()=>({tr:e,dispatch:t})=>(t&&e.scrollIntoView(),!0),_p=()=>({tr:e,commands:t})=>t.setTextSelection({from:0,to:e.doc.content.size}),kp=()=>({state:e,dispatch:t})=>Te.selectNodeBackward(e,t),Tp=()=>({state:e,dispatch:t})=>Te.selectNodeForward(e,t),Dp=()=>({state:e,dispatch:t})=>Te.selectParentNode(e,t),Ip=()=>({state:e,dispatch:t})=>Te.selectTextblockEnd(e,t),Mp=()=>({state:e,dispatch:t})=>Te.selectTextblockStart(e,t);function Ap(e,t,n={}){return Wn(e,t,{slice:!1,parseOptions:n})}const zp=(e,t=!1,n={})=>({tr:r,editor:a,dispatch:o})=>{const{doc:l}=r,u=Ap(e,a.schema,n);return o&&r.replaceWith(0,l.content.size,u).setMeta("preventUpdate",!t),!0};function Ep(e){for(let t=0;t<e.edgeCount;t+=1){const{type:n}=e.edge(t);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}function $p(e,t){for(let n=e.depth;n>0;n-=1){const r=e.node(n);if(t(r))return{pos:n>0?e.before(n):0,start:e.start(n),depth:n,node:r}}}function Qr(e){return t=>$p(t.$from,e)}function Lp(e,t){const n=_t(t,e.schema),{from:r,to:a,empty:o}=e.selection,l=[];o?(e.storedMarks&&l.push(...e.storedMarks),l.push(...e.selection.$head.marks())):e.doc.nodesBetween(r,a,c=>{l.push(...c.marks)});const u=l.find(c=>c.type.name===n.name);return u?{...u.attrs}:{}}function jn(e,t,n){return Object.fromEntries(Object.entries(n).filter(([r])=>{const a=e.find(o=>o.type===t&&o.name===r);return a?a.attribute.keepOnSplit:!1}))}function Op(e,t,n={}){const{empty:r,ranges:a}=e.selection,o=t?_t(t,e.schema):null;if(r)return!!(e.storedMarks||e.selection.$from.marks()).filter(h=>o?o.name===h.type.name:!0).find(h=>Gn(h.attrs,n,{strict:!1}));let l=0;const u=[];if(a.forEach(({$from:h,$to:g})=>{const m=h.pos,C=g.pos;e.doc.nodesBetween(m,C,(w,_)=>{if(!w.isText&&!w.marks.length)return;const T=Math.max(m,_),M=Math.min(C,_+w.nodeSize),P=M-T;l+=P,u.push(...w.marks.map(G=>({mark:G,from:T,to:M})))})}),l===0)return!1;const c=u.filter(h=>o?o.name===h.mark.type.name:!0).filter(h=>Gn(h.mark.attrs,n,{strict:!1})).reduce((h,g)=>h+g.to-g.from,0),d=u.filter(h=>o?h.mark.type!==o&&h.mark.type.excludes(o):!0).reduce((h,g)=>h+g.to-g.from,0);return(c>0?c+d:c)>=l}function Ys(e,t){const{nodeExtensions:n}=Nd(t),r=n.find(l=>l.name===e);if(!r)return!1;const a={name:r.name,options:r.options,storage:r.storage},o=Gt(St(r,"group",a));return typeof o!="string"?!1:o.split(" ").includes("list")}function Pp(e,t,n){var r;const{selection:a}=t;let o=null;if(Fs(a)&&(o=a.$cursor),o){const u=(r=e.storedMarks)!==null&&r!==void 0?r:o.marks();return!!n.isInSet(u)||!u.some(c=>c.type.excludes(n))}const{ranges:l}=a;return l.some(({$from:u,$to:c})=>{let d=u.depth===0?e.doc.inlineContent&&e.doc.type.allowsMarkType(n):!1;return e.doc.nodesBetween(u.pos,c.pos,(f,h,g)=>{if(d)return!1;if(f.isInline){const m=!g||g.type.allowsMarkType(n),C=!!n.isInSet(f.marks)||!f.marks.some(w=>w.type.excludes(n));d=m&&C}return!d}),d})}const Bp=(e,t={})=>({tr:n,state:r,dispatch:a})=>{const{selection:o}=n,{empty:l,ranges:u}=o,c=_t(e,r.schema);if(a)if(l){const d=Lp(r,c);n.addStoredMark(c.create({...d,...t}))}else u.forEach(d=>{const f=d.$from.pos,h=d.$to.pos;r.doc.nodesBetween(f,h,(g,m)=>{const C=Math.max(m,f),w=Math.min(m+g.nodeSize,h);g.marks.find(T=>T.type===c)?g.marks.forEach(T=>{c===T.type&&n.addMark(C,w,c.create({...T.attrs,...t}))}):n.addMark(C,w,c.create(t))})});return Pp(r,n,c)},Vp=(e,t)=>({tr:n})=>(n.setMeta(e,t),!0),Np=(e,t={})=>({state:n,dispatch:r,chain:a})=>{const o=Ae(e,n.schema);return o.isTextblock?a().command(({commands:l})=>Te.setBlockType(o,t)(n)?!0:l.clearNodes()).command(({state:l})=>Te.setBlockType(o,t)(l,r)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},qp=e=>({tr:t,dispatch:n})=>{if(n){const{doc:r}=t,a=Pt(e,0,r.content.size),o=Ye.create(r,a);t.setSelection(o)}return!0},Fp=e=>({tr:t,dispatch:n})=>{if(n){const{doc:r}=t,{from:a,to:o}=typeof e=="number"?{from:e,to:e}:e,l=_e.atStart(r).from,u=_e.atEnd(r).to,c=Pt(a,l,u),d=Pt(o,l,u),f=_e.create(r,c,d);t.setSelection(f)}return!0},Gp=e=>({state:t,dispatch:n})=>{const r=Ae(e,t.schema);return yr.sinkListItem(r)(t,n)};function Qs(e,t){const n=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();if(n){const r=n.filter(a=>t==null?void 0:t.includes(a.type.name));e.tr.ensureMarks(r)}}const Wp=({keepMarks:e=!0}={})=>({tr:t,state:n,dispatch:r,editor:a})=>{const{selection:o,doc:l}=t,{$from:u,$to:c}=o,d=a.extensionManager.attributes,f=jn(d,u.node().type.name,u.node().attrs);if(o instanceof Ye&&o.node.isBlock)return!u.parentOffset||!Nn(l,u.pos)?!1:(r&&(e&&Qs(n,a.extensionManager.splittableMarks),t.split(u.pos).scrollIntoView()),!0);if(!u.parent.isBlock)return!1;if(r){const h=c.parentOffset===c.parent.content.size;o instanceof _e&&t.deleteSelection();const g=u.depth===0?void 0:Ep(u.node(-1).contentMatchAt(u.indexAfter(-1)));let m=h&&g?[{type:g,attrs:f}]:void 0,C=Nn(t.doc,t.mapping.map(u.pos),1,m);if(!m&&!C&&Nn(t.doc,t.mapping.map(u.pos),1,g?[{type:g}]:void 0)&&(C=!0,m=g?[{type:g,attrs:f}]:void 0),C&&(t.split(t.mapping.map(u.pos),1,m),g&&!h&&!u.parentOffset&&u.parent.type!==g)){const w=t.mapping.map(u.before()),_=t.doc.resolve(w);u.node(-1).canReplaceWith(_.index(),_.index()+1,g)&&t.setNodeMarkup(t.mapping.map(u.before()),g)}e&&Qs(n,a.extensionManager.splittableMarks),t.scrollIntoView()}return!0},jp=e=>({tr:t,state:n,dispatch:r,editor:a})=>{var o;const l=Ae(e,n.schema),{$from:u,$to:c}=n.selection,d=n.selection.node;if(d&&d.isBlock||u.depth<2||!u.sameParent(c))return!1;const f=u.node(-1);if(f.type!==l)return!1;const h=a.extensionManager.attributes;if(u.parent.content.size===0&&u.node(-1).childCount===u.indexAfter(-1)){if(u.depth===2||u.node(-3).type!==l||u.index(-2)!==u.node(-2).childCount-1)return!1;if(r){let _=ae.empty;const T=u.index(-1)?1:u.index(-2)?2:3;for(let A=u.depth-T;A>=u.depth-3;A-=1)_=ae.from(u.node(A).copy(_));const M=u.indexAfter(-1)<u.node(-2).childCount?1:u.indexAfter(-2)<u.node(-3).childCount?2:3,P=jn(h,u.node().type.name,u.node().attrs),G=((o=l.contentMatch.defaultType)===null||o===void 0?void 0:o.createAndFill(P))||void 0;_=_.append(ae.from(l.createAndFill(null,G)||void 0));const $=u.before(u.depth-(T-1));t.replace($,u.after(-M),new ce(_,4-T,0));let L=-1;t.doc.nodesBetween($,t.doc.content.size,(A,N)=>{if(L>-1)return!1;A.isTextblock&&A.content.size===0&&(L=N+1)}),L>-1&&t.setSelection(_e.near(t.doc.resolve(L))),t.scrollIntoView()}return!0}const g=c.pos===u.end()?f.contentMatchAt(0).defaultType:null,m=jn(h,f.type.name,f.attrs),C=jn(h,u.node().type.name,u.node().attrs);t.delete(u.pos,c.pos);const w=g?[{type:l,attrs:m},{type:g,attrs:C}]:[{type:l,attrs:m}];if(!Nn(t.doc,u.pos,2))return!1;if(r){const{selection:_,storedMarks:T}=n,{splittableMarks:M}=a.extensionManager,P=T||_.$to.parentOffset&&_.$from.marks();if(t.split(u.pos,2,w).scrollIntoView(),!P||!r)return!0;const G=P.filter($=>M.includes($.type.name));t.ensureMarks(G)}return!0},Ur=(e,t)=>{const n=Qr(l=>l.type===t)(e.selection);if(!n)return!0;const r=e.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(r===void 0)return!0;const a=e.doc.nodeAt(r);return n.node.type===(a==null?void 0:a.type)&&zs(e.doc,n.pos)&&e.join(n.pos),!0},Kr=(e,t)=>{const n=Qr(l=>l.type===t)(e.selection);if(!n)return!0;const r=e.doc.resolve(n.start).after(n.depth);if(r===void 0)return!0;const a=e.doc.nodeAt(r);return n.node.type===(a==null?void 0:a.type)&&zs(e.doc,r)&&e.join(r),!0};var Rp=Object.freeze({__proto__:null,blur:Rd,clearContent:Yd,clearNodes:Qd,command:Ud,createParagraphNear:Kd,deleteCurrentNode:Xd,deleteNode:Jd,deleteRange:Zd,deleteSelection:Hd,enter:ep,exitCode:tp,extendMarkRange:rp,first:ip,focus:sp,forEach:op,insertContent:lp,insertContentAt:dp,joinUp:pp,joinDown:hp,joinBackward:fp,joinForward:gp,keyboardShortcut:yp,lift:bp,liftEmptyBlock:vp,liftListItem:xp,newlineInCode:wp,resetAttributes:Cp,scrollIntoView:Sp,selectAll:_p,selectNodeBackward:kp,selectNodeForward:Tp,selectParentNode:Dp,selectTextblockEnd:Ip,selectTextblockStart:Mp,setContent:zp,setMark:Bp,setMeta:Vp,setNode:Np,setNodeSelection:qp,setTextSelection:Fp,sinkListItem:Gp,splitBlock:Wp,splitListItem:jp,toggleList:(e,t,n,r={})=>({editor:a,tr:o,state:l,dispatch:u,chain:c,commands:d,can:f})=>{const{extensions:h,splittableMarks:g}=a.extensionManager,m=Ae(e,l.schema),C=Ae(t,l.schema),{selection:w,storedMarks:_}=l,{$from:T,$to:M}=w,P=T.blockRange(M),G=_||w.$to.parentOffset&&w.$from.marks();if(!P)return!1;const $=Qr(L=>Ys(L.type.name,h))(w);if(P.depth>=1&&$&&P.depth-$.depth<=1){if($.node.type===m)return d.liftListItem(C);if(Ys($.node.type.name,h)&&m.validContent($.node.content)&&u)return c().command(()=>(o.setNodeMarkup($.pos,m),!0)).command(()=>Ur(o,m)).command(()=>Kr(o,m)).run()}return!n||!G||!u?c().command(()=>f().wrapInList(m,r)?!0:d.clearNodes()).wrapInList(m,r).command(()=>Ur(o,m)).command(()=>Kr(o,m)).run():c().command(()=>{const L=f().wrapInList(m,r),A=G.filter(N=>g.includes(N.type.name));return o.ensureMarks(A),L?!0:d.clearNodes()}).wrapInList(m,r).command(()=>Ur(o,m)).command(()=>Kr(o,m)).run()},toggleMark:(e,t={},n={})=>({state:r,commands:a})=>{const{extendEmptyMarkRange:o=!1}=n,l=_t(e,r.schema);return Op(r,l,t)?a.unsetMark(l,{extendEmptyMarkRange:o}):a.setMark(l,t)},toggleNode:(e,t,n={})=>({state:r,commands:a})=>{const o=Ae(e,r.schema),l=Ae(t,r.schema);return Yr(r,o,n)?a.setNode(l):a.setNode(o,n)},toggleWrap:(e,t={})=>({state:n,commands:r})=>{const a=Ae(e,n.schema);return Yr(n,a,t)?r.lift(a):r.wrapIn(a,t)},undoInputRule:()=>({state:e,dispatch:t})=>{const n=e.plugins;for(let r=0;r<n.length;r+=1){const a=n[r];let o;if(a.spec.isInputRules&&(o=a.getState(e))){if(t){const l=e.tr,u=o.transform;for(let c=u.steps.length-1;c>=0;c-=1)l.step(u.steps[c].invert(u.docs[c]));if(o.text){const c=l.doc.resolve(o.from).marks();l.replaceWith(o.from,o.to,e.schema.text(o.text,c))}else l.delete(o.from,o.to)}return!0}}return!1},unsetAllMarks:()=>({tr:e,dispatch:t})=>{const{selection:n}=e,{empty:r,ranges:a}=n;return r||t&&a.forEach(o=>{e.removeMark(o.$from.pos,o.$to.pos)}),!0},unsetMark:(e,t={})=>({tr:n,state:r,dispatch:a})=>{var o;const{extendEmptyMarkRange:l=!1}=t,{selection:u}=n,c=_t(e,r.schema),{$from:d,empty:f,ranges:h}=u;if(!a)return!0;if(f&&l){let{from:g,to:m}=u;const C=(o=d.marks().find(_=>_.type===c))===null||o===void 0?void 0:o.attrs,w=qs(d,c,C);w&&(g=w.from,m=w.to),n.removeMark(g,m,c)}else h.forEach(g=>{n.removeMark(g.$from.pos,g.$to.pos,c)});return n.removeStoredMark(c),!0},updateAttributes:(e,t={})=>({tr:n,state:r,dispatch:a})=>{let o=null,l=null;const u=js(typeof e=="string"?e:e.name,r.schema);return u?(u==="node"&&(o=Ae(e,r.schema)),u==="mark"&&(l=_t(e,r.schema)),a&&n.selection.ranges.forEach(c=>{const d=c.$from.pos,f=c.$to.pos;r.doc.nodesBetween(d,f,(h,g)=>{o&&o===h.type&&n.setNodeMarkup(g,void 0,{...h.attrs,...t}),l&&h.marks.length&&h.marks.forEach(m=>{if(l===m.type){const C=Math.max(g,d),w=Math.min(g+h.nodeSize,f);n.addMark(C,w,l.create({...m.attrs,...t}))}})})}),!0):!1},wrapIn:(e,t={})=>({state:n,dispatch:r})=>{const a=Ae(e,n.schema);return Te.wrapIn(a,t)(n,r)},wrapInList:(e,t={})=>({state:n,dispatch:r})=>{const a=Ae(e,n.schema);return yr.wrapInList(a,t)(n,r)}});ut.create({name:"commands",addCommands(){return{...Rp}}}),ut.create({name:"editable",addProseMirrorPlugins(){return[new pn({key:new hn("editable"),props:{editable:()=>this.editor.options.editable}})]}}),ut.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:e}=this;return[new pn({key:new hn("focusEvents"),props:{handleDOMEvents:{focus:(t,n)=>{e.isFocused=!0;const r=e.state.tr.setMeta("focus",{event:n}).setMeta("addToHistory",!1);return t.dispatch(r),!1},blur:(t,n)=>{e.isFocused=!1;const r=e.state.tr.setMeta("blur",{event:n}).setMeta("addToHistory",!1);return t.dispatch(r),!1}}}})]}}),ut.create({name:"keymap",addKeyboardShortcuts(){const e=()=>this.editor.commands.first(({commands:l})=>[()=>l.undoInputRule(),()=>l.command(({tr:u})=>{const{selection:c,doc:d}=u,{empty:f,$anchor:h}=c,{pos:g,parent:m}=h,C=fe.atStart(d).from===g;return!f||!C||!m.type.isTextblock||m.textContent.length?!1:l.clearNodes()}),()=>l.deleteSelection(),()=>l.joinBackward(),()=>l.selectNodeBackward()]),t=()=>this.editor.commands.first(({commands:l})=>[()=>l.deleteSelection(),()=>l.deleteCurrentNode(),()=>l.joinForward(),()=>l.selectNodeForward()]),r={Enter:()=>this.editor.commands.first(({commands:l})=>[()=>l.newlineInCode(),()=>l.createParagraphNear(),()=>l.liftEmptyBlock(),()=>l.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:e,"Mod-Backspace":e,"Shift-Backspace":e,Delete:t,"Mod-Delete":t,"Mod-a":()=>this.editor.commands.selectAll()},a={...r},o={...r,"Ctrl-h":e,"Alt-Backspace":e,"Ctrl-d":t,"Ctrl-Alt-Backspace":t,"Alt-Delete":t,"Alt-d":t,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return Rr()||Ws()?o:a},addProseMirrorPlugins(){return[new pn({key:new hn("clearDocument"),appendTransaction:(e,t,n)=>{if(!(e.some(C=>C.docChanged)&&!t.doc.eq(n.doc)))return;const{empty:a,from:o,to:l}=t.selection,u=fe.atStart(t.doc).from,c=fe.atEnd(t.doc).to;if(a||!(o===u&&l===c)||!(n.doc.textBetween(0,n.doc.content.size," "," ").length===0))return;const h=n.tr,g=Vs({state:n,transaction:h}),{commands:m}=new Vd({editor:this.editor,state:g});if(m.clearNodes(),!!h.steps.length)return h}})]}}),ut.create({name:"tabindex",addProseMirrorPlugins(){return[new pn({key:new hn("tabindex"),props:{attributes:this.editor.isEditable?{tabindex:"0"}:{}}})]}});const Us=ut.create({name:"fontSize",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{fontSize:{default:null,parseHTML:e=>e.style.fontSize.replace(/['"]+/g,""),renderHTML:e=>e.fontSize?{style:`font-size: ${e.fontSize}`}:{}}}}]},addCommands(){return{setFontSize:e=>({chain:t})=>t().setMark("textStyle",{fontSize:e}).run(),unsetFontSize:()=>({chain:e})=>e().setMark("textStyle",{fontSize:null}).removeEmptyTextStyle().run()}}}),Yp=["8","10","12","14","16","18","20","24","30","36","48","60","72"].map(e=>`${e}px`),Qp=[{label:"auto",value:""}].concat(Yp.map(e=>({label:e,value:e}))),Up={input:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important"}},Kp=({editor:e})=>{const t=e.getAttributes("textStyle").fontSize;return i(J.RichTextEditor.ControlsGroup,{children:i(s.NativeSelect,{size:"xs",icon:i(E.IconTextSize,{stroke:1.5,size:16}),data:Qp,styles:Up,value:t||"",onChange:n=>{const r=n.currentTarget.value;r?e.chain().focus().setFontSize(r).run():e.chain().focus().unsetFontSize().run()}})})},Rn=({value:e,styles:t={}})=>{const n=Qa.useEditor({extensions:[Ua,Ya,J.Link,Na,Va,Pa,Ga.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),Ra,ja,Wa,qa.configure({types:["heading","paragraph"]}),Ba.configure({placeholder:"This is placeholder"}),Fa,Oa.Color,Us],content:e,editable:!1});y.useEffect(()=>{n==null||n.commands.setContent(e)},[e,n]);const r=y.useMemo(()=>x.defaultsDeep({},{content:Lr},t),[t]);return i(J.RichTextEditor,{editor:n,styles:r,children:i(J.RichTextEditor.Content,{})})};function Xp(){const[e,{open:t,close:n}]=ke.useDisclosure(!1);return p(B,{children:[i(s.Modal,{opened:e,onClose:n,title:"About FunctionUtils",zIndex:330,withinPortal:!0,children:i(Rn,{value:Yu,styles:{root:{border:"none"},content:{padding:0,table:{marginBottom:0}}}})}),i(s.Button,{variant:"light",color:"violet",size:"xs",onClick:t,leftIcon:i(E.IconInfoCircle,{size:16}),children:"About parameter 'utils'"})]})}const Jp=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return i(s.Box,{sx:{position:"relative",flexGrow:1},children:i(De,{className:"function-editor",height:"100%",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1}}})})},fn=y.forwardRef(({value:e,onChange:t,label:n,defaultValue:r},a)=>{const[o,l]=y.useState(e),u=()=>{t(o)},c=()=>{l(e)},d=()=>{l(r)};y.useEffect(()=>{l(e)},[e]);const f=o!==e;return p(s.Stack,{spacing:4,sx:{height:"100%"},children:[p(s.Group,{mb:6,position:"apart",sx:{flexShrink:0,flexGrow:0},children:[i(s.Group,{position:"left",children:i(Xp,{})}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,size:"xs",variant:"default",leftIcon:i(E.IconPlayerSkipBack,{size:16}),children:"Reset to default"}),i(s.Button,{onClick:c,color:"red",size:"xs",disabled:!f,leftIcon:i(E.IconRecycle,{size:16}),children:"Revert Changes"}),i(s.Button,{size:"xs",onClick:u,disabled:!f,leftIcon:i(E.IconDeviceFloppy,{size:16}),children:"Confirm Changes"})]})]}),i(s.Text,{size:14,children:n}),i(Jp,{value:o,onChange:l})]})}),Zp=y.forwardRef(({value:e,onChange:t,label:n,triggerLabel:r="Edit",triggerButtonProps:a={},defaultValue:o},l)=>{const[u,{open:c,close:d}]=ke.useDisclosure(!1);return p(B,{children:[i(s.Modal,{opened:u,onClose:d,title:"Authentication",withinPortal:!0,zIndex:320,size:"900px",children:i(s.Box,{h:600,children:i(fn,{value:e,onChange:t,defaultValue:o,label:n})})}),i(s.Button,{onClick:c,...a,children:r})]})}),Ks=["function aggregation({ queryData }, utils) {",' return "Aggregation Result";',"}"].join(`
|
|
105
|
-
`),Wt={type:"none",config:{}};function
|
|
106
|
-
`,"<br/>").split("<br/>");return n.map((a,o)=>{const l=[gh(a)];return o!==n.length-1&&l.push(i("br",{},`br-${o}`)),l}).flat().filter(a=>a!==void 0)}function Jr(e){return mh(e)}function gn(e,t,n){const r=fh(t,n),a=/^\{(.+)\}(.*)$/;return e.split("$").map((o,l)=>{const u=a.exec(o);if(!u)return Jr(o);const c=r[u[1]];if(!c)return Jr(o);const d=u[2]??"";return p(y.Fragment,{children:[c,Jr(d)]},`${o}-${l}`)})}function yh(e,t){const n={};return e.forEach(r=>{const{name:a,data_field:o,aggregation:l}=r,u=Yn(t,o,l);n[a]=Ze(r,u)}),n}function Kn(e,t,n){const r=yh(t,n),a=/^\{(.+)\}(.*)$/;return e.split("$").map(o=>{const l=a.exec(o);if(!l)return o;const u=r[l[1]];if(!u)return o;const c=l[2]??"";return`${u}${c}`}).join("")}function bh(e,t,n){const r=t.reduce((a,o)=>{const l=mt(o,n);return a[o.name]=Ze(o,l),a},{});return e.map(a=>({name:"refs",type:"scatter",data:[],markLine:{data:[{name:a.name,yAxis:Number(r[a.variable_key])}],silent:!0,symbol:["none","none"],label:{formatter:function(){return Kn(a.template,t,n)},position:"insideEndTop"}}}))}function vh(e){const t={top:30,left:20,right:15,bottom:25,containLabel:!0};return e.legend.orient==="vertical"&&(t.right=80),t}function xh({config:e,data:t,variables:n}){const{x_axis:r,y_axis:a,reference_lines:o}=e,l=gd(e,t),u=it(r.axisLabel.overflow.on_axis),c=yd(e);return{grid:vh(e),dataset:l,legend:md({config:e}),tooltip:Sd({config:e}),xAxis:[{type:"category",name:r.name,nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold",align:"center"},axisTick:{show:!0,alignWithLabel:!0},axisLabel:{...r.axisLabel,...u,formatter:qt(r.axisLabel.formatter)}}],yAxis:[{name:a.name,minInterval:1,nameTextStyle:{fontWeight:"bold"},axisLine:{show:!0},axisLabel:{formatter:function(d){return Z(d).format(a.label_formatter)}}}],series:[...c,...bh(o,n,t)]}}ie.use([F.DataZoomComponent,he.BoxplotChart,F.MarkLineComponent,F.GridComponent,F.LegendComponent,F.TooltipComponent,Ee.CanvasRenderer]);function wh({context:e,instance:t}){const{value:n}=R(e.instanceData,"config"),{variables:r}=e,a=e.data,{width:o,height:l}=e.viewport,u=x.defaults({},n,Ar),c=Xe({vizManager:e.vizManager,instance:t}),d=Ke(c.triggerManager,ps.id),f=zt(a,u.x_axis.data_key),h=y.useCallback(C=>{const w=x.get(f,C.name,{error:"rowData is not found"});d.forEach(_=>{c.runInteraction(_.id,{...C,rowData:w})})},[f,d,c]),g=y.useMemo(()=>({click:h}),[h]),m=y.useMemo(()=>xh({config:u,data:a,variables:r}),[u,a,r]);return!n||!o||!l?null:i(Ve,{width:o,height:l,children:i(ze,{echarts:ie,option:m,style:an(o,l),onEvents:g,notMerge:!0,theme:"merico-light"})})}function Ch({control:e,index:t,remove:n,variableOptions:r}){return p(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:a})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:a})=>i(s.Select,{label:"Value",required:!0,data:r,sx:{flex:1},...a})})]}),i(v.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:a})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",required:!0,sx:{flex:1},...a})}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(t),sx:{position:"absolute",top:15,right:5},children:i(D.Trash,{size:16})})]},t)}function Sh({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=r.map((f,h)=>({...f,...l[h]})),c=()=>a({name:"",template:"",variable_key:""}),d=y.useMemo(()=>n.map(f=>({label:f.name,value:f.name})),[n]);return p(s.Stack,{children:[u.map((f,h)=>i(Ch,{control:e,index:h,remove:o,variableOptions:d},f.id)),i(s.Group,{position:"center",mt:"xs",children:i(s.Button,{onClick:c,children:"Add a Reference Line"})})]})}const _h=({disabled:e,value:t,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[e&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(De,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},Xn=y.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:a,setFalse:o}]=Q.useBoolean(),[l,u]=y.useState(e);y.useEffect(()=>{u(e)},[e]);const c=m=>{u({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:C}=l,w={enabled:m,func_content:C};u(w),t(w)},f=()=>{o(),u(e)},h=m=>{u(C=>({...C,func_content:m}))},g=()=>{h(Ue.func_content)};return p(B,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Customize Label"}),i(s.Modal,{size:800,title:"Customize label content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:m=>c(m.currentTarget.checked)}),i(_h,{value:l.func_content,onChange:h,disabled:!l.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:g,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:d,children:"OK"})]})]})]})})]})}),kh=({control:e,watch:t})=>(t(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"X Axis Name",sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>i(W,{label:"X Axis Data Field",required:!0,sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>i(Xn,{...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>i(st,{...n})})]})),Th=({control:e,watch:t})=>(t(["y_axis"]),p(B,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"Y Axis Name",sx:{flex:1},...n})}),i(v.Controller,{name:"y_axis.data_key",control:e,render:({field:n})=>i(W,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:"y_axis.label_formatter",control:e,render:({field:n})=>i(We,{...n})})]})]})),Dh=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),Ih=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(B,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(D.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Set additional metrics to show in scatter's tooltip"})]}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(Dh,{control:e,index:g,remove:a},h.id)},h.id))]})]})};function Mh({control:e,watch:t}){return i(s.Stack,{children:i(Ih,{control:e,watch:t})})}const Ah=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}],zh=({control:e,watch:t})=>{const n=t("legend"),r=(a,o)=>{const l={...n,orient:a};a==="horizontal"?(l.top="0",l.left="auto",l.right="10",l.bottom="auto"):(l.top="10",l.left="auto",l.right="0",l.bottom="auto"),o(l)};return p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,mt:20,children:i(v.Controller,{name:"legend.show",control:e,render:({field:a})=>i(s.Switch,{label:"Show Legend",sx:{flex:1},checked:a.value,onChange:o=>a.onChange(o.currentTarget.checked)})})}),i(s.Group,{children:i(v.Controller,{name:"legend",control:e,render:({field:a})=>i(s.Select,{label:"Orientation",data:Ah,sx:{flex:1},value:a.value.orient,onChange:o=>{r(o,a.onChange)},disabled:!n.show})})})]})};function Eh({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),{variables:r}=e,a=y.useMemo(()=>x.defaults({},t,Ar),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]),u(["x_axis","y_axis","reference_lines","color"]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,t),[f,t]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),i(s.Tabs.Tab,{value:"Legend",children:"Legend"}),i(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"}),i(s.Tabs.Tab,{value:"Style",children:"Style"}),i(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(kh,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(Th,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Legend",children:i(zh,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(Mh,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Style",children:p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:"color",control:o,render:({field:g})=>i($e,{...g})})]})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(Sh,{variables:r,control:o,watch:u})})]})]})})}function $h(e){return x.omit(e,"variables")}function Lh(e){const{label_formatter:t=Ie,...n}=e.y_axis;return{...e,y_axis:{...n,label_formatter:t}}}function Oh(e){const t={rotate:0,formatter:{...Ue}},{axisLabel:n=t,...r}=e.x_axis;return{...e,x_axis:{...r,axisLabel:n}}}function Ph(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return x.defaultsDeep(t,e)}function Bh(e){delete e.config;const{x_axis:t,tooltip:n}=e.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:t,in_tooltip:n}}}};return x.defaultsDeep(r,e)}function Vh(e){const t={tooltip:{metrics:[]}};return x.defaultsDeep(t,e)}function Nh(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,y_axis:o,tooltip:l,...u}=e;return{...u,x_axis:{...a,data_key:r(a.data_key)},y_axis:{...o,data_key:r(o.data_key)},tooltip:{...l,metrics:l.metrics.map(c=>({...c,data_key:r(c.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}function qh(e){const t={legend:{show:!0,top:"0",right:"10",left:"auto",bottom:"auto",orient:"horizontal",type:"scroll"}};return x.defaultsDeep(t,e)}class Fh extends ge{constructor(){super(...arguments);q(this,"VERSION",9)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,{panelModel:r})=>{const{config:a}=n;return(a.variables||[]).forEach(l=>{r.variables.find(u=>u.name===l.name)||r.addVariable(l)}),{...n,version:2,config:$h(a)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:Lh(r)}}),this.version(4,n=>{const{config:r}=n;return{...n,version:4,config:Oh(r)}}),this.version(5,n=>{const{config:r}=n;return{...n,version:5,config:Ph(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:Bh(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:Vh(r)}}),this.version(8,(n,r)=>{const{config:a}=n;return{...n,version:8,config:Nh(a,r)}}),this.version(9,n=>{const{config:r}=n;return{...n,version:9,config:qh(r)}})}}const Gh={displayName:"Boxplot Chart",displayGroup:"ECharts-based charts",migrator:new Fh,name:"boxplot",viewRender:wh,configRender:Eh,createConfig(){return{version:9,config:x.cloneDeep(Ar)}},triggers:[ps]},Hs={id:"builtin:button:click-button",displayName:"Click Button",nameRender:jh,configRender:Wh,payload:[]};function Wh(e){return i(B,{})}function jh(e){return i(s.Text,{children:"Click this button"})}const Zr={content:"Button",variant:"filled",color:"blue",size:"xs",compact:!1,horizontal_align:"left",vertical_align:"center"},Rh={left:"flex-start",center:"center",right:"flex-end"},Yh={top:"flex-start",center:"center",bottom:"flex-end"},Qh=k.observer(({context:e,instance:t})=>{const n=Xe({vizManager:e.vizManager,instance:t}),r=Ke(n.triggerManager,Hs.id),a=ye(),{value:o}=R(e.instanceData,"config"),l=y.useMemo(()=>x.defaultsDeep({},o,Zr),[o]),{content:u,horizontal_align:c,vertical_align:d,...f}=l,{width:h,height:g}=e.viewport,m=a.payloadForSQL,C=()=>{r.forEach(w=>{n.runInteraction(w.id,{})})};return i(s.Center,{sx:{width:h,height:g,justifyContent:Rh[c],alignItems:Yh[d]},children:i(s.Button,{...f,onClick:C,children:x.template(u)(m)})})}),Uh=({value:e,onChange:t,label:n})=>{const r=s.useMantineTheme(),a=y.useCallback(l=>()=>t(l),[t]),o=l=>e===l;return p(s.Stack,{spacing:2,children:[i(s.Text,{size:14,sx:{fontWeight:500},children:n}),i(s.Group,{position:"left",spacing:"xs",children:Object.keys(r.colors).map(l=>{const u=r.colors[l][6];return i(s.ColorSwatch,{color:u,onClick:a(l),radius:4,size:26,sx:{cursor:"pointer"},children:o(l)&&i(s.CheckIcon,{width:10,color:"white"})},l)})})]})},Kh=s.MANTINE_SIZES.map(e=>({label:e.toUpperCase(),value:e})),Xh=({label:e,value:t,onChange:n})=>i(s.Select,{data:Kh,label:e,value:t,onChange:n}),Jh=[{label:"Filled",value:"filled"},{label:"Outline",value:"outline"},{label:"Light",value:"light"},{label:"White",value:"white"},{label:"Default",value:"default"},{label:"Subtle",value:"subtle"},{label:"Gradient",value:"gradient",disabled:!0}],Zh=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Hh=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function ef({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},t,Zr),[t]),a=r;y.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return u(["content","variant","color","size","compact","horizontal_align","vertical_align"]),p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Stack,{children:[i(v.Controller,{control:o,name:"content",render:({field:g})=>i(s.TextInput,{label:"Content Template",description:"Filter values & context entries are supported",...g,required:!0})}),i(s.Divider,{mt:"xs",mb:0,label:"Styles",labelPosition:"center",variant:"dashed"}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{control:o,name:"variant",render:({field:g})=>i(s.Select,{label:"Variant",data:Jh,...g})}),i(v.Controller,{control:o,name:"color",render:({field:g})=>i(Uh,{label:"Theme",...g})})]}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{control:o,name:"size",render:({field:g})=>i(Xh,{label:"Size",...g})}),i(v.Controller,{control:o,name:"compact",render:({field:g})=>i(s.Checkbox,{label:"Compact",checked:g.value,onChange:m=>g.onChange(m.currentTarget.checked),mt:26})})]}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{control:o,name:"horizontal_align",render:({field:g})=>i(s.Select,{label:"Horizontal Alignment",data:Zh,...g})}),i(v.Controller,{control:o,name:"vertical_align",render:({field:g})=>i(s.Select,{label:"Vertical Alignment",data:Hh,...g})})]})]})]})}class tf extends ge{constructor(){super(...arguments);q(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{horizontal_align:r="left",vertical_align:a="center",...o}=n.config;return{...n,version:2,config:{...o,horizontal_align:r,vertical_align:a}}})}}const nf={displayName:"Button",displayGroup:"Others",migrator:new tf,name:"button",viewRender:Qh,configRender:ef,createConfig(){return{version:2,config:x.cloneDeep(Zr)}},triggers:[Hs]},Hr={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:af,configRender:rf,payload:[{name:"seriesType",description:"'line' | 'scatter' | 'bar'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function rf(e){return i(B,{})}function af(e){return i(s.Text,{children:"Click chart's series"})}const jt={x_axis_scroll:!1,y_axis_scroll:!1,x_axis_slider:!1,y_axis_slider:!1},ei={regressions:[],series:[],stats:{templates:{bottom:"",top:""}},x_axis:{type:"category",axisLabel:{rotate:0,formatter:{...Ue},overflow:je}},x_axis_data_key:"",x_axis_name:"",y_axes:[{min:"",max:"",name:"Y Axis",show:!0,position:"left",nameAlignment:"center",label_formatter:Ie}],reference_lines:[],reference_areas:[],dataZoom:jt};function ti(e){const t=[];return e.x_axis_scroll&&t.push({type:"inside",xAxisIndex:[0],filterMode:"none",minSpan:1}),e.y_axis_scroll&&t.push({type:"inside",yAxisIndex:[0],filterMode:"none",minSpan:1}),e.x_axis_slider&&t.push({type:"slider",xAxisIndex:[0],filterMode:"none",bottom:"auto",top:0,height:15,moveHandleSize:0,showDataShadow:!1,minSpan:1}),t}function sf(e){const t=e.y_axes.some(a=>!!a.name);let n=15;t&&(n+=20),e.dataZoom.x_axis_slider&&(n+=20);let r=5;return e.x_axis_name&&(r+=15),e.series.some(a=>!a.hide_in_legend)&&(r+=20),{top:n,right:15,bottom:r,left:20,containLabel:!0}}function of(e){return e!=="line"?{}:{itemStyle:{opacity:0}}}function lf(e){switch(e){case"line":return;case"bar":return"roundRect";case"scatter":return"circle"}}function uf(e){const t={show:!0,bottom:0,left:"center",type:"scroll"};return t.data=e.filter(n=>!n.hide_in_legend).map(({name:n,type:r})=>({name:n,icon:lf(r),...of(r)})),t}function Jn(e,t){switch(e.config.method){case"linear":return[...wt.regressionLinear()(t)];case"exponential":return[...wt.regressionExp()(t)];case"logarithmic":return[...wt.regressionLog()(t)];case"polynomial":return[...wt.regressionPoly().order(e.config.order)(t)];default:return[]}}function cf(e,t,n,r){const{transform:a,plot:o}=e,l={...o,name:t,data:Jn(a,r),showSymbol:!1,tooltip:{show:!1},smooth:!1,custom:{}};return n&&(l.custom={type:"regression-line",targetSeries:n}),l}function df({regressions:e=[],x_axis_data_key:t},n){const r=[];if(Object.keys(n).length===0)return r;function a(o,l,u,c){const d=cf(o,l,u,c);r.push(d)}return e.forEach(o=>{const{name:l,group_by_key:u}=o;if(!u||u===t){const h=ft(n,o.y_axis_data_key).map((g,m)=>[m,Number(g)]);a(o,l,"",h);return}const{columnKey:c}=O(o.y_axis_data_key),d=x.groupBy(sn(n,o.y_axis_data_key),u);Object.entries(d).forEach(([f,h])=>{const g=h.map((C,w)=>[w,Number(C[c])]);a(o,f,f,g)})}),r}function pf(e,t){return e.map(n=>({name:"",type:"line",hide_in_legend:!0,data:[],markArea:{itemStyle:{color:n.color},data:[[{yAxis:t[n.y_keys.upper]},{yAxis:t[n.y_keys.lower]}]],silent:!0}}))}function hf(e,t,n,r,a){return e.map(o=>{const l=n[o.variable_key],u=o.orientation==="horizontal",c=u?"yAxis":"xAxis",d=u?"insideEndTop":"end",f=u?[a[0],l]:[];return{name:o.name,type:"scatter",hide_in_legend:!o.show_in_legend,yAxisIndex:o.yAxisIndex,data:f,symbol:"none",silent:!0,tooltip:{show:!1},markLine:{data:[{name:o.name,[c]:l}],silent:!0,symbol:["none","none"],lineStyle:o.lineStyle,label:{formatter:function(){return o.template?Kn(o.template,t,r):""},position:d}}}})}function ff({type:e,...t},n,r,a){if(!e)return 10;if(e==="static"){const{size:d}=t;return d}const{func_content:o}=t,{queryID:l,columnKey:u}=O(r),c=x.keyBy(sn(n,l),u);return(d,f)=>{let h;f.name?h=c[f.name]:h=n[f.dataIndex];try{return new Function(`return ${o}`)()({rowData:h,params:f,variables:a},{lodash:x,interpolate:It.interpolate})}catch(g){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${g.message}`),10}}}function ni(e,t,n){const r=ft(e,t),a=ft(e,n);return x.zip(r,a)}function gf(e,t,n,r){const a=ni(t,n,r);return x.unionBy(a,e,0)}function mf({dataTemplate:e,data:t,x_axis_data_key:n,y_axis_data_key:r,valueTypedXAxis:a}){return a?gf(e,t,n,r):ft(t,r)}function yf({dataTemplate:e,data:t,aggregation_on_value:n,x_axis_data_key:r,y_axis_data_key:a,valueTypedXAxis:o}){if(!n||n.type==="none")return mf({dataTemplate:e,data:t,x_axis_data_key:r,y_axis_data_key:a,valueTypedXAxis:o});const l=ni(t,r,a),u=x.groupBy(l,"0");return e.map(([d])=>{const h=u[d].map(m=>m[1]),g=Xr(h,n);return[d,g]})}function bf({group_by_key:e,data:t,x_axis_data_key:n,y_axis_data_key:r}){const{queryID:a,columnKey:o}=O(e),l=x.groupBy(t[a],o);return Object.entries(l).forEach(([u,c])=>{l[u]=ni({[a]:c},n,r)}),l}function vf({x_axis_data_key:e,x_axis:t},{y_axis_data_key:n,yAxisIndex:r,label_position:a,name:o,group_by_key:l,aggregation_on_value:u,stack:c,color:d,display_name_on_line:f,symbolSize:h,hide_in_legend:g,...m},C,w,_,T){const M=t.type!=="category",P={label:{show:!!a,position:a,formatter:T[r??"default"]},name:o,xAxisId:"main-x-axis",yAxisIndex:r,stack:c,color:d,symbolSize:ff(h,w,e,_),hide_in_legend:g,labelLayout:{hideOverlap:!0},...m};if(f&&(P.endLabel={show:!0,formatter:o,offset:[-12,12],align:"right"}),!l||l===e)return P.data=yf({dataTemplate:C,data:w,aggregation_on_value:u,x_axis_data_key:e,y_axis_data_key:n,valueTypedXAxis:M}),P;const G=bf({group_by_key:l,data:w,x_axis_data_key:e,y_axis_data_key:n});return Object.entries(G).map(([$,L])=>{const A=x.cloneDeep(P);return A.name=$,A.color=void 0,A.data=L,A})}function xf(e,t,n,r,a,o){const l=t.map(c=>[c,0]);return e.series.map(c=>vf(e,c,l,n,o,r)).flat().concat(hf(e.reference_lines,a,o,n,t)).concat(pf(e.reference_areas,o))}function wf(e,t){const n=e.find(o=>o.axisDim==="x"&&o.axisId==="main-x-axis");if(!n)return"";const{axisValue:r,axisIndex:a}=n;return qt(t.x_axis.axisLabel.formatter)(r,a)}function Cf(e,t,n){const r=t.reduce((a,{yAxisIndex:o,name:l})=>(a[l]=o,a),{});return{trigger:"axis",confine:!0,formatter:function(a){const o=Array.isArray(a)?a:[a];if(o.length===0)return"";const l=o.map(({seriesName:d,marker:f,value:h})=>{if(Array.isArray(h)&&h.length===2&&(h=h[1]),!d)return h;const g=r[d],m=n[g]??n.default;return`
|
|
104
|
+
`,textSerializers:l={}}=n||{};let u="",c=!0;return e.nodesBetween(r,a,(d,f,h,g)=>{var m;const C=l==null?void 0:l[d.type.name];C?(d.isBlock&&!c&&(u+=o,c=!0),h&&(u+=C({node:d,pos:f,parent:h,index:g,range:t}))):d.isText?(u+=(m=d==null?void 0:d.text)===null||m===void 0?void 0:m.slice(Math.max(r,f)-f,a-f),c=!1):d.isBlock&&!c&&(u+=o,c=!0)}),u}function Yd(e){return Object.fromEntries(Object.entries(e.nodes).filter(([,t])=>t.spec.toText).map(([t,n])=>[t,n.spec.toText]))}ut.create({name:"clipboardTextSerializer",addProseMirrorPlugins(){return[new pn({key:new hn("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:e}=this,{state:t,schema:n}=e,{doc:r,selection:a}=t,{ranges:o}=a,l=Math.min(...o.map(f=>f.$from.pos)),u=Math.max(...o.map(f=>f.$to.pos)),c=Yd(n);return Rd(r,{from:l,to:u},{textSerializers:c})}}})]}});const Qd=()=>({editor:e,view:t})=>(requestAnimationFrame(()=>{var n;e.isDestroyed||(t.dom.blur(),(n=window==null?void 0:window.getSelection())===null||n===void 0||n.removeAllRanges())}),!0),Ud=(e=!1)=>({commands:t})=>t.setContent("",e),Kd=()=>({state:e,tr:t,dispatch:n})=>{const{selection:r}=t,{ranges:a}=r;return n&&a.forEach(({$from:o,$to:l})=>{e.doc.nodesBetween(o.pos,l.pos,(u,c)=>{if(u.type.isText)return;const{doc:d,mapping:f}=t,h=d.resolve(f.map(c)),g=d.resolve(f.map(c+u.nodeSize)),m=h.blockRange(g);if(!m)return;const C=Pd(m);if(u.type.isTextblock){const{defaultType:w}=h.parent.contentMatchAt(h.index());t.setNodeMarkup(m.start,w)}(C||C===0)&&t.lift(m,C)})}),!0},Xd=e=>t=>e(t),Jd=()=>({state:e,dispatch:t})=>Te.createParagraphNear(e,t),Zd=()=>({tr:e,dispatch:t})=>{const{selection:n}=e,r=n.$anchor.node();if(r.content.size>0)return!1;const a=e.selection.$anchor;for(let o=a.depth;o>0;o-=1)if(a.node(o).type===r.type){if(t){const u=a.before(o),c=a.after(o);e.delete(u,c).scrollIntoView()}return!0}return!1},Hd=e=>({tr:t,state:n,dispatch:r})=>{const a=Ae(e,n.schema),o=t.selection.$anchor;for(let l=o.depth;l>0;l-=1)if(o.node(l).type===a){if(r){const c=o.before(l),d=o.after(l);t.delete(c,d).scrollIntoView()}return!0}return!1},ep=e=>({tr:t,dispatch:n})=>{const{from:r,to:a}=e;return n&&t.delete(r,a),!0},tp=()=>({state:e,dispatch:t})=>Te.deleteSelection(e,t),np=()=>({commands:e})=>e.keyboardShortcut("Enter"),rp=()=>({state:e,dispatch:t})=>Te.exitCode(e,t);function Gn(e,t,n={strict:!0}){const r=Object.keys(t);return r.length?r.every(a=>n.strict?t[a]===e[a]:Wd(t[a])?t[a].test(e[a]):t[a]===e[a]):!0}function jr(e,t,n={}){return e.find(r=>r.type===t&&Gn(r.attrs,n))}function ip(e,t,n={}){return!!jr(e,t,n)}function Gs(e,t,n={}){if(!e||!t)return;let r=e.parent.childAfter(e.parentOffset);if(e.parentOffset===r.offset&&r.offset!==0&&(r=e.parent.childBefore(e.parentOffset)),!r.node)return;const a=jr([...r.node.marks],t,n);if(!a)return;let o=r.index,l=e.start()+r.offset,u=o+1,c=l+r.node.nodeSize;for(jr([...r.node.marks],t,n);o>0&&a.isInSet(e.parent.child(o-1).marks);)o-=1,l-=e.parent.child(o).nodeSize;for(;u<e.parent.childCount&&ip([...e.parent.child(u).marks],t,n);)c+=e.parent.child(u).nodeSize,u+=1;return{from:l,to:c}}function _t(e,t){if(typeof e=="string"){if(!t.marks[e])throw Error(`There is no mark type named '${e}'. Maybe you forgot to add the extension?`);return t.marks[e]}return e}const ap=(e,t={})=>({tr:n,state:r,dispatch:a})=>{const o=_t(e,r.schema),{doc:l,selection:u}=n,{$from:c,from:d,to:f}=u;if(a){const h=Gs(c,o,t);if(h&&h.from<=d&&h.to>=f){const g=_e.create(l,h.from,h.to);n.setSelection(g)}}return!0},sp=e=>t=>{const n=typeof e=="function"?e(t):e;for(let r=0;r<n.length;r+=1)if(n[r](t))return!0;return!1};function Ws(e){return e instanceof _e}function Pt(e=0,t=0,n=0){return Math.min(Math.max(e,t),n)}function op(e,t=null){if(!t)return null;const n=fe.atStart(e),r=fe.atEnd(e);if(t==="start"||t===!0)return n;if(t==="end")return r;const a=n.from,o=r.to;return t==="all"?_e.create(e,Pt(0,a,o),Pt(e.content.size,a,o)):_e.create(e,Pt(t,a,o),Pt(t,a,o))}function Rr(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}const lp=(e=null,t={})=>({editor:n,view:r,tr:a,dispatch:o})=>{t={scrollIntoView:!0,...t};const l=()=>{Rr()&&r.dom.focus(),requestAnimationFrame(()=>{n.isDestroyed||(r.focus(),t!=null&&t.scrollIntoView&&n.commands.scrollIntoView())})};if(r.hasFocus()&&e===null||e===!1)return!0;if(o&&e===null&&!Ws(n.state.selection))return l(),!0;const u=op(a.doc,e)||n.state.selection,c=n.state.selection.eq(u);return o&&(c||a.setSelection(u),c&&a.storedMarks&&a.setStoredMarks(a.storedMarks),l()),!0},up=(e,t)=>n=>e.every((r,a)=>t(r,{...n,index:a})),cp=(e,t)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},e,t);function js(e){const t=`<body>${e}</body>`;return new window.DOMParser().parseFromString(t,"text/html").body}function Wn(e,t,n){if(n={slice:!0,parseOptions:{},...n},typeof e=="object"&&e!==null)try{return Array.isArray(e)&&e.length>0?ae.fromArray(e.map(r=>t.nodeFromJSON(r))):t.nodeFromJSON(e)}catch(r){return console.warn("[tiptap warn]: Invalid content.","Passed value:",e,"Error:",r),Wn("",t,n)}if(typeof e=="string"){const r=Ln.fromSchema(t);return n.slice?r.parseSlice(js(e),n.parseOptions).content:r.parse(js(e),n.parseOptions)}return Wn("",t,n)}function dp(e,t,n){const r=e.steps.length-1;if(r<t)return;const a=e.steps[r];if(!(a instanceof lt||a instanceof Ot))return;const o=e.mapping.maps[r];let l=0;o.forEach((u,c,d,f)=>{l===0&&(l=f)}),e.setSelection(fe.near(e.doc.resolve(l),n))}const pp=e=>e.toString().startsWith("<"),hp=(e,t,n)=>({tr:r,dispatch:a,editor:o})=>{if(a){n={parseOptions:{},updateSelection:!0,...n};const l=Wn(t,o.schema,{parseOptions:{preserveWhitespace:"full",...n.parseOptions}});if(l.toString()==="<>")return!0;let{from:u,to:c}=typeof e=="number"?{from:e,to:e}:e,d=!0,f=!0;if((pp(l)?l:[l]).forEach(g=>{g.check(),d=d?g.isText&&g.marks.length===0:!1,f=f?g.isBlock:!1}),u===c&&f){const{parent:g}=r.doc.resolve(u);g.isTextblock&&!g.type.spec.code&&!g.childCount&&(u-=1,c+=1)}d?Array.isArray(t)?r.insertText(t.map(g=>g.text||"").join(""),u,c):typeof t=="object"&&t&&t.text?r.insertText(t.text,u,c):r.insertText(t,u,c):r.replaceWith(u,c,l),n.updateSelection&&dp(r,r.steps.length-1,-1)}return!0},fp=()=>({state:e,dispatch:t})=>Te.joinUp(e,t),gp=()=>({state:e,dispatch:t})=>Te.joinDown(e,t),mp=()=>({state:e,dispatch:t})=>Te.joinBackward(e,t),yp=()=>({state:e,dispatch:t})=>Te.joinForward(e,t);function Rs(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function bp(e){const t=e.split(/-(?!$)/);let n=t[t.length-1];n==="Space"&&(n=" ");let r,a,o,l;for(let u=0;u<t.length-1;u+=1){const c=t[u];if(/^(cmd|meta|m)$/i.test(c))l=!0;else if(/^a(lt)?$/i.test(c))r=!0;else if(/^(c|ctrl|control)$/i.test(c))a=!0;else if(/^s(hift)?$/i.test(c))o=!0;else if(/^mod$/i.test(c))Rr()||Rs()?l=!0:a=!0;else throw new Error(`Unrecognized modifier name: ${c}`)}return r&&(n=`Alt-${n}`),a&&(n=`Ctrl-${n}`),l&&(n=`Meta-${n}`),o&&(n=`Shift-${n}`),n}const vp=e=>({editor:t,view:n,tr:r,dispatch:a})=>{const o=bp(e).split(/-(?!$)/),l=o.find(d=>!["Alt","Ctrl","Meta","Shift"].includes(d)),u=new KeyboardEvent("keydown",{key:l==="Space"?" ":l,altKey:o.includes("Alt"),ctrlKey:o.includes("Ctrl"),metaKey:o.includes("Meta"),shiftKey:o.includes("Shift"),bubbles:!0,cancelable:!0}),c=t.captureTransaction(()=>{n.someProp("handleKeyDown",d=>d(n,u))});return c==null||c.steps.forEach(d=>{const f=d.map(r.mapping);f&&a&&r.maybeStep(f)}),!0};function Yr(e,t,n={}){const{from:r,to:a,empty:o}=e.selection,l=t?Ae(t,e.schema):null,u=[];e.doc.nodesBetween(r,a,(h,g)=>{if(h.isText)return;const m=Math.max(r,g),C=Math.min(a,g+h.nodeSize);u.push({node:h,from:m,to:C})});const c=a-r,d=u.filter(h=>l?l.name===h.node.type.name:!0).filter(h=>Gn(h.node.attrs,n,{strict:!1}));return o?!!d.length:d.reduce((h,g)=>h+g.to-g.from,0)>=c}const xp=(e,t={})=>({state:n,dispatch:r})=>{const a=Ae(e,n.schema);return Yr(n,a,t)?Te.lift(n,r):!1},wp=()=>({state:e,dispatch:t})=>Te.liftEmptyBlock(e,t),Cp=e=>({state:t,dispatch:n})=>{const r=Ae(e,t.schema);return yr.liftListItem(r)(t,n)},Sp=()=>({state:e,dispatch:t})=>Te.newlineInCode(e,t);function Ys(e,t){return t.nodes[e]?"node":t.marks[e]?"mark":null}function Qs(e,t){const n=typeof t=="string"?[t]:t;return Object.keys(e).reduce((r,a)=>(n.includes(a)||(r[a]=e[a]),r),{})}const _p=(e,t)=>({tr:n,state:r,dispatch:a})=>{let o=null,l=null;const u=Ys(typeof e=="string"?e:e.name,r.schema);return u?(u==="node"&&(o=Ae(e,r.schema)),u==="mark"&&(l=_t(e,r.schema)),a&&n.selection.ranges.forEach(c=>{r.doc.nodesBetween(c.$from.pos,c.$to.pos,(d,f)=>{o&&o===d.type&&n.setNodeMarkup(f,void 0,Qs(d.attrs,t)),l&&d.marks.length&&d.marks.forEach(h=>{l===h.type&&n.addMark(f,f+d.nodeSize,l.create(Qs(h.attrs,t)))})})}),!0):!1},kp=()=>({tr:e,dispatch:t})=>(t&&e.scrollIntoView(),!0),Tp=()=>({tr:e,commands:t})=>t.setTextSelection({from:0,to:e.doc.content.size}),Dp=()=>({state:e,dispatch:t})=>Te.selectNodeBackward(e,t),Ip=()=>({state:e,dispatch:t})=>Te.selectNodeForward(e,t),Mp=()=>({state:e,dispatch:t})=>Te.selectParentNode(e,t),Ap=()=>({state:e,dispatch:t})=>Te.selectTextblockEnd(e,t),zp=()=>({state:e,dispatch:t})=>Te.selectTextblockStart(e,t);function Ep(e,t,n={}){return Wn(e,t,{slice:!1,parseOptions:n})}const $p=(e,t=!1,n={})=>({tr:r,editor:a,dispatch:o})=>{const{doc:l}=r,u=Ep(e,a.schema,n);return o&&r.replaceWith(0,l.content.size,u).setMeta("preventUpdate",!t),!0};function Lp(e){for(let t=0;t<e.edgeCount;t+=1){const{type:n}=e.edge(t);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}function Op(e,t){for(let n=e.depth;n>0;n-=1){const r=e.node(n);if(t(r))return{pos:n>0?e.before(n):0,start:e.start(n),depth:n,node:r}}}function Qr(e){return t=>Op(t.$from,e)}function Pp(e,t){const n=_t(t,e.schema),{from:r,to:a,empty:o}=e.selection,l=[];o?(e.storedMarks&&l.push(...e.storedMarks),l.push(...e.selection.$head.marks())):e.doc.nodesBetween(r,a,c=>{l.push(...c.marks)});const u=l.find(c=>c.type.name===n.name);return u?{...u.attrs}:{}}function jn(e,t,n){return Object.fromEntries(Object.entries(n).filter(([r])=>{const a=e.find(o=>o.type===t&&o.name===r);return a?a.attribute.keepOnSplit:!1}))}function Bp(e,t,n={}){const{empty:r,ranges:a}=e.selection,o=t?_t(t,e.schema):null;if(r)return!!(e.storedMarks||e.selection.$from.marks()).filter(h=>o?o.name===h.type.name:!0).find(h=>Gn(h.attrs,n,{strict:!1}));let l=0;const u=[];if(a.forEach(({$from:h,$to:g})=>{const m=h.pos,C=g.pos;e.doc.nodesBetween(m,C,(w,_)=>{if(!w.isText&&!w.marks.length)return;const T=Math.max(m,_),M=Math.min(C,_+w.nodeSize),P=M-T;l+=P,u.push(...w.marks.map(G=>({mark:G,from:T,to:M})))})}),l===0)return!1;const c=u.filter(h=>o?o.name===h.mark.type.name:!0).filter(h=>Gn(h.mark.attrs,n,{strict:!1})).reduce((h,g)=>h+g.to-g.from,0),d=u.filter(h=>o?h.mark.type!==o&&h.mark.type.excludes(o):!0).reduce((h,g)=>h+g.to-g.from,0);return(c>0?c+d:c)>=l}function Us(e,t){const{nodeExtensions:n}=Fd(t),r=n.find(l=>l.name===e);if(!r)return!1;const a={name:r.name,options:r.options,storage:r.storage},o=Gt(St(r,"group",a));return typeof o!="string"?!1:o.split(" ").includes("list")}function Vp(e,t,n){var r;const{selection:a}=t;let o=null;if(Ws(a)&&(o=a.$cursor),o){const u=(r=e.storedMarks)!==null&&r!==void 0?r:o.marks();return!!n.isInSet(u)||!u.some(c=>c.type.excludes(n))}const{ranges:l}=a;return l.some(({$from:u,$to:c})=>{let d=u.depth===0?e.doc.inlineContent&&e.doc.type.allowsMarkType(n):!1;return e.doc.nodesBetween(u.pos,c.pos,(f,h,g)=>{if(d)return!1;if(f.isInline){const m=!g||g.type.allowsMarkType(n),C=!!n.isInSet(f.marks)||!f.marks.some(w=>w.type.excludes(n));d=m&&C}return!d}),d})}const Np=(e,t={})=>({tr:n,state:r,dispatch:a})=>{const{selection:o}=n,{empty:l,ranges:u}=o,c=_t(e,r.schema);if(a)if(l){const d=Pp(r,c);n.addStoredMark(c.create({...d,...t}))}else u.forEach(d=>{const f=d.$from.pos,h=d.$to.pos;r.doc.nodesBetween(f,h,(g,m)=>{const C=Math.max(m,f),w=Math.min(m+g.nodeSize,h);g.marks.find(T=>T.type===c)?g.marks.forEach(T=>{c===T.type&&n.addMark(C,w,c.create({...T.attrs,...t}))}):n.addMark(C,w,c.create(t))})});return Vp(r,n,c)},qp=(e,t)=>({tr:n})=>(n.setMeta(e,t),!0),Fp=(e,t={})=>({state:n,dispatch:r,chain:a})=>{const o=Ae(e,n.schema);return o.isTextblock?a().command(({commands:l})=>Te.setBlockType(o,t)(n)?!0:l.clearNodes()).command(({state:l})=>Te.setBlockType(o,t)(l,r)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},Gp=e=>({tr:t,dispatch:n})=>{if(n){const{doc:r}=t,a=Pt(e,0,r.content.size),o=Ye.create(r,a);t.setSelection(o)}return!0},Wp=e=>({tr:t,dispatch:n})=>{if(n){const{doc:r}=t,{from:a,to:o}=typeof e=="number"?{from:e,to:e}:e,l=_e.atStart(r).from,u=_e.atEnd(r).to,c=Pt(a,l,u),d=Pt(o,l,u),f=_e.create(r,c,d);t.setSelection(f)}return!0},jp=e=>({state:t,dispatch:n})=>{const r=Ae(e,t.schema);return yr.sinkListItem(r)(t,n)};function Ks(e,t){const n=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();if(n){const r=n.filter(a=>t==null?void 0:t.includes(a.type.name));e.tr.ensureMarks(r)}}const Rp=({keepMarks:e=!0}={})=>({tr:t,state:n,dispatch:r,editor:a})=>{const{selection:o,doc:l}=t,{$from:u,$to:c}=o,d=a.extensionManager.attributes,f=jn(d,u.node().type.name,u.node().attrs);if(o instanceof Ye&&o.node.isBlock)return!u.parentOffset||!Nn(l,u.pos)?!1:(r&&(e&&Ks(n,a.extensionManager.splittableMarks),t.split(u.pos).scrollIntoView()),!0);if(!u.parent.isBlock)return!1;if(r){const h=c.parentOffset===c.parent.content.size;o instanceof _e&&t.deleteSelection();const g=u.depth===0?void 0:Lp(u.node(-1).contentMatchAt(u.indexAfter(-1)));let m=h&&g?[{type:g,attrs:f}]:void 0,C=Nn(t.doc,t.mapping.map(u.pos),1,m);if(!m&&!C&&Nn(t.doc,t.mapping.map(u.pos),1,g?[{type:g}]:void 0)&&(C=!0,m=g?[{type:g,attrs:f}]:void 0),C&&(t.split(t.mapping.map(u.pos),1,m),g&&!h&&!u.parentOffset&&u.parent.type!==g)){const w=t.mapping.map(u.before()),_=t.doc.resolve(w);u.node(-1).canReplaceWith(_.index(),_.index()+1,g)&&t.setNodeMarkup(t.mapping.map(u.before()),g)}e&&Ks(n,a.extensionManager.splittableMarks),t.scrollIntoView()}return!0},Yp=e=>({tr:t,state:n,dispatch:r,editor:a})=>{var o;const l=Ae(e,n.schema),{$from:u,$to:c}=n.selection,d=n.selection.node;if(d&&d.isBlock||u.depth<2||!u.sameParent(c))return!1;const f=u.node(-1);if(f.type!==l)return!1;const h=a.extensionManager.attributes;if(u.parent.content.size===0&&u.node(-1).childCount===u.indexAfter(-1)){if(u.depth===2||u.node(-3).type!==l||u.index(-2)!==u.node(-2).childCount-1)return!1;if(r){let _=ae.empty;const T=u.index(-1)?1:u.index(-2)?2:3;for(let A=u.depth-T;A>=u.depth-3;A-=1)_=ae.from(u.node(A).copy(_));const M=u.indexAfter(-1)<u.node(-2).childCount?1:u.indexAfter(-2)<u.node(-3).childCount?2:3,P=jn(h,u.node().type.name,u.node().attrs),G=((o=l.contentMatch.defaultType)===null||o===void 0?void 0:o.createAndFill(P))||void 0;_=_.append(ae.from(l.createAndFill(null,G)||void 0));const $=u.before(u.depth-(T-1));t.replace($,u.after(-M),new ce(_,4-T,0));let L=-1;t.doc.nodesBetween($,t.doc.content.size,(A,N)=>{if(L>-1)return!1;A.isTextblock&&A.content.size===0&&(L=N+1)}),L>-1&&t.setSelection(_e.near(t.doc.resolve(L))),t.scrollIntoView()}return!0}const g=c.pos===u.end()?f.contentMatchAt(0).defaultType:null,m=jn(h,f.type.name,f.attrs),C=jn(h,u.node().type.name,u.node().attrs);t.delete(u.pos,c.pos);const w=g?[{type:l,attrs:m},{type:g,attrs:C}]:[{type:l,attrs:m}];if(!Nn(t.doc,u.pos,2))return!1;if(r){const{selection:_,storedMarks:T}=n,{splittableMarks:M}=a.extensionManager,P=T||_.$to.parentOffset&&_.$from.marks();if(t.split(u.pos,2,w).scrollIntoView(),!P||!r)return!0;const G=P.filter($=>M.includes($.type.name));t.ensureMarks(G)}return!0},Ur=(e,t)=>{const n=Qr(l=>l.type===t)(e.selection);if(!n)return!0;const r=e.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(r===void 0)return!0;const a=e.doc.nodeAt(r);return n.node.type===(a==null?void 0:a.type)&&$s(e.doc,n.pos)&&e.join(n.pos),!0},Kr=(e,t)=>{const n=Qr(l=>l.type===t)(e.selection);if(!n)return!0;const r=e.doc.resolve(n.start).after(n.depth);if(r===void 0)return!0;const a=e.doc.nodeAt(r);return n.node.type===(a==null?void 0:a.type)&&$s(e.doc,r)&&e.join(r),!0};var Qp=Object.freeze({__proto__:null,blur:Qd,clearContent:Ud,clearNodes:Kd,command:Xd,createParagraphNear:Jd,deleteCurrentNode:Zd,deleteNode:Hd,deleteRange:ep,deleteSelection:tp,enter:np,exitCode:rp,extendMarkRange:ap,first:sp,focus:lp,forEach:up,insertContent:cp,insertContentAt:hp,joinUp:fp,joinDown:gp,joinBackward:mp,joinForward:yp,keyboardShortcut:vp,lift:xp,liftEmptyBlock:wp,liftListItem:Cp,newlineInCode:Sp,resetAttributes:_p,scrollIntoView:kp,selectAll:Tp,selectNodeBackward:Dp,selectNodeForward:Ip,selectParentNode:Mp,selectTextblockEnd:Ap,selectTextblockStart:zp,setContent:$p,setMark:Np,setMeta:qp,setNode:Fp,setNodeSelection:Gp,setTextSelection:Wp,sinkListItem:jp,splitBlock:Rp,splitListItem:Yp,toggleList:(e,t,n,r={})=>({editor:a,tr:o,state:l,dispatch:u,chain:c,commands:d,can:f})=>{const{extensions:h,splittableMarks:g}=a.extensionManager,m=Ae(e,l.schema),C=Ae(t,l.schema),{selection:w,storedMarks:_}=l,{$from:T,$to:M}=w,P=T.blockRange(M),G=_||w.$to.parentOffset&&w.$from.marks();if(!P)return!1;const $=Qr(L=>Us(L.type.name,h))(w);if(P.depth>=1&&$&&P.depth-$.depth<=1){if($.node.type===m)return d.liftListItem(C);if(Us($.node.type.name,h)&&m.validContent($.node.content)&&u)return c().command(()=>(o.setNodeMarkup($.pos,m),!0)).command(()=>Ur(o,m)).command(()=>Kr(o,m)).run()}return!n||!G||!u?c().command(()=>f().wrapInList(m,r)?!0:d.clearNodes()).wrapInList(m,r).command(()=>Ur(o,m)).command(()=>Kr(o,m)).run():c().command(()=>{const L=f().wrapInList(m,r),A=G.filter(N=>g.includes(N.type.name));return o.ensureMarks(A),L?!0:d.clearNodes()}).wrapInList(m,r).command(()=>Ur(o,m)).command(()=>Kr(o,m)).run()},toggleMark:(e,t={},n={})=>({state:r,commands:a})=>{const{extendEmptyMarkRange:o=!1}=n,l=_t(e,r.schema);return Bp(r,l,t)?a.unsetMark(l,{extendEmptyMarkRange:o}):a.setMark(l,t)},toggleNode:(e,t,n={})=>({state:r,commands:a})=>{const o=Ae(e,r.schema),l=Ae(t,r.schema);return Yr(r,o,n)?a.setNode(l):a.setNode(o,n)},toggleWrap:(e,t={})=>({state:n,commands:r})=>{const a=Ae(e,n.schema);return Yr(n,a,t)?r.lift(a):r.wrapIn(a,t)},undoInputRule:()=>({state:e,dispatch:t})=>{const n=e.plugins;for(let r=0;r<n.length;r+=1){const a=n[r];let o;if(a.spec.isInputRules&&(o=a.getState(e))){if(t){const l=e.tr,u=o.transform;for(let c=u.steps.length-1;c>=0;c-=1)l.step(u.steps[c].invert(u.docs[c]));if(o.text){const c=l.doc.resolve(o.from).marks();l.replaceWith(o.from,o.to,e.schema.text(o.text,c))}else l.delete(o.from,o.to)}return!0}}return!1},unsetAllMarks:()=>({tr:e,dispatch:t})=>{const{selection:n}=e,{empty:r,ranges:a}=n;return r||t&&a.forEach(o=>{e.removeMark(o.$from.pos,o.$to.pos)}),!0},unsetMark:(e,t={})=>({tr:n,state:r,dispatch:a})=>{var o;const{extendEmptyMarkRange:l=!1}=t,{selection:u}=n,c=_t(e,r.schema),{$from:d,empty:f,ranges:h}=u;if(!a)return!0;if(f&&l){let{from:g,to:m}=u;const C=(o=d.marks().find(_=>_.type===c))===null||o===void 0?void 0:o.attrs,w=Gs(d,c,C);w&&(g=w.from,m=w.to),n.removeMark(g,m,c)}else h.forEach(g=>{n.removeMark(g.$from.pos,g.$to.pos,c)});return n.removeStoredMark(c),!0},updateAttributes:(e,t={})=>({tr:n,state:r,dispatch:a})=>{let o=null,l=null;const u=Ys(typeof e=="string"?e:e.name,r.schema);return u?(u==="node"&&(o=Ae(e,r.schema)),u==="mark"&&(l=_t(e,r.schema)),a&&n.selection.ranges.forEach(c=>{const d=c.$from.pos,f=c.$to.pos;r.doc.nodesBetween(d,f,(h,g)=>{o&&o===h.type&&n.setNodeMarkup(g,void 0,{...h.attrs,...t}),l&&h.marks.length&&h.marks.forEach(m=>{if(l===m.type){const C=Math.max(g,d),w=Math.min(g+h.nodeSize,f);n.addMark(C,w,l.create({...m.attrs,...t}))}})})}),!0):!1},wrapIn:(e,t={})=>({state:n,dispatch:r})=>{const a=Ae(e,n.schema);return Te.wrapIn(a,t)(n,r)},wrapInList:(e,t={})=>({state:n,dispatch:r})=>{const a=Ae(e,n.schema);return yr.wrapInList(a,t)(n,r)}});ut.create({name:"commands",addCommands(){return{...Qp}}}),ut.create({name:"editable",addProseMirrorPlugins(){return[new pn({key:new hn("editable"),props:{editable:()=>this.editor.options.editable}})]}}),ut.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:e}=this;return[new pn({key:new hn("focusEvents"),props:{handleDOMEvents:{focus:(t,n)=>{e.isFocused=!0;const r=e.state.tr.setMeta("focus",{event:n}).setMeta("addToHistory",!1);return t.dispatch(r),!1},blur:(t,n)=>{e.isFocused=!1;const r=e.state.tr.setMeta("blur",{event:n}).setMeta("addToHistory",!1);return t.dispatch(r),!1}}}})]}}),ut.create({name:"keymap",addKeyboardShortcuts(){const e=()=>this.editor.commands.first(({commands:l})=>[()=>l.undoInputRule(),()=>l.command(({tr:u})=>{const{selection:c,doc:d}=u,{empty:f,$anchor:h}=c,{pos:g,parent:m}=h,C=fe.atStart(d).from===g;return!f||!C||!m.type.isTextblock||m.textContent.length?!1:l.clearNodes()}),()=>l.deleteSelection(),()=>l.joinBackward(),()=>l.selectNodeBackward()]),t=()=>this.editor.commands.first(({commands:l})=>[()=>l.deleteSelection(),()=>l.deleteCurrentNode(),()=>l.joinForward(),()=>l.selectNodeForward()]),r={Enter:()=>this.editor.commands.first(({commands:l})=>[()=>l.newlineInCode(),()=>l.createParagraphNear(),()=>l.liftEmptyBlock(),()=>l.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:e,"Mod-Backspace":e,"Shift-Backspace":e,Delete:t,"Mod-Delete":t,"Mod-a":()=>this.editor.commands.selectAll()},a={...r},o={...r,"Ctrl-h":e,"Alt-Backspace":e,"Ctrl-d":t,"Ctrl-Alt-Backspace":t,"Alt-Delete":t,"Alt-d":t,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return Rr()||Rs()?o:a},addProseMirrorPlugins(){return[new pn({key:new hn("clearDocument"),appendTransaction:(e,t,n)=>{if(!(e.some(C=>C.docChanged)&&!t.doc.eq(n.doc)))return;const{empty:a,from:o,to:l}=t.selection,u=fe.atStart(t.doc).from,c=fe.atEnd(t.doc).to;if(a||!(o===u&&l===c)||!(n.doc.textBetween(0,n.doc.content.size," "," ").length===0))return;const h=n.tr,g=qs({state:n,transaction:h}),{commands:m}=new qd({editor:this.editor,state:g});if(m.clearNodes(),!!h.steps.length)return h}})]}}),ut.create({name:"tabindex",addProseMirrorPlugins(){return[new pn({key:new hn("tabindex"),props:{attributes:this.editor.isEditable?{tabindex:"0"}:{}}})]}});const Xs=ut.create({name:"fontSize",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{fontSize:{default:null,parseHTML:e=>e.style.fontSize.replace(/['"]+/g,""),renderHTML:e=>e.fontSize?{style:`font-size: ${e.fontSize}`}:{}}}}]},addCommands(){return{setFontSize:e=>({chain:t})=>t().setMark("textStyle",{fontSize:e}).run(),unsetFontSize:()=>({chain:e})=>e().setMark("textStyle",{fontSize:null}).removeEmptyTextStyle().run()}}}),Up=["8","10","12","14","16","18","20","24","30","36","48","60","72"].map(e=>`${e}px`),Kp=[{label:"auto",value:""}].concat(Up.map(e=>({label:e,value:e}))),Xp={input:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important"}},Jp=({editor:e})=>{const t=e.getAttributes("textStyle").fontSize;return i(J.RichTextEditor.ControlsGroup,{children:i(s.NativeSelect,{size:"xs",icon:i(E.IconTextSize,{stroke:1.5,size:16}),data:Kp,styles:Xp,value:t||"",onChange:n=>{const r=n.currentTarget.value;r?e.chain().focus().setFontSize(r).run():e.chain().focus().unsetFontSize().run()}})})},Rn=({value:e,styles:t={}})=>{const n=Qa.useEditor({extensions:[Ua,Ya,J.Link,Na,Va,Pa,Ga.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),Ra,ja,Wa,qa.configure({types:["heading","paragraph"]}),Ba.configure({placeholder:"This is placeholder"}),Fa,Oa.Color,Xs],content:e,editable:!1});y.useEffect(()=>{n==null||n.commands.setContent(e)},[e,n]);const r=y.useMemo(()=>x.defaultsDeep({},{content:Lr},t),[t]);return i(J.RichTextEditor,{editor:n,styles:r,children:i(J.RichTextEditor.Content,{})})};function Zp(){const[e,{open:t,close:n}]=ke.useDisclosure(!1);return p(B,{children:[i(s.Modal,{opened:e,onClose:n,title:"About FunctionUtils",zIndex:330,withinPortal:!0,children:i(Rn,{value:Uu,styles:{root:{border:"none"},content:{padding:0,table:{marginBottom:0}}}})}),i(s.Button,{variant:"light",color:"violet",size:"xs",onClick:t,leftIcon:i(E.IconInfoCircle,{size:16}),children:"About parameter 'utils'"})]})}const Hp=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return i(s.Box,{sx:{position:"relative",flexGrow:1},children:i(De,{className:"function-editor",height:"100%",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1}}})})},fn=y.forwardRef(({value:e,onChange:t,label:n,defaultValue:r},a)=>{const[o,l]=y.useState(e),u=()=>{t(o)},c=()=>{l(e)},d=()=>{l(r)};y.useEffect(()=>{l(e)},[e]);const f=o!==e;return p(s.Stack,{spacing:4,sx:{height:"100%"},children:[p(s.Group,{mb:6,position:"apart",sx:{flexShrink:0,flexGrow:0},children:[i(s.Group,{position:"left",children:i(Zp,{})}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,size:"xs",variant:"default",leftIcon:i(E.IconPlayerSkipBack,{size:16}),children:"Reset to default"}),i(s.Button,{onClick:c,color:"red",size:"xs",disabled:!f,leftIcon:i(E.IconRecycle,{size:16}),children:"Revert Changes"}),i(s.Button,{size:"xs",onClick:u,disabled:!f,leftIcon:i(E.IconDeviceFloppy,{size:16}),children:"Confirm Changes"})]})]}),i(s.Text,{size:14,children:n}),i(Hp,{value:o,onChange:l})]})}),eh=y.forwardRef(({value:e,onChange:t,label:n,triggerLabel:r="Edit",triggerButtonProps:a={},defaultValue:o},l)=>{const[u,{open:c,close:d}]=ke.useDisclosure(!1);return p(B,{children:[i(s.Modal,{opened:u,onClose:d,title:"Authentication",withinPortal:!0,zIndex:320,size:"900px",children:i(s.Box,{h:600,children:i(fn,{value:e,onChange:t,defaultValue:o,label:n})})}),i(s.Button,{onClick:c,...a,children:r})]})}),Js=["function aggregation({ queryData }, utils) {",' return "Aggregation Result";',"}"].join(`
|
|
105
|
+
`),Wt={type:"none",config:{}};function th(e){const t=Array.from(e).sort((r,a)=>r-a),n=Math.floor(t.length/2);return t.length%2===0?(t[n-1]+t[n])/2:t[n]}function nh(e){const t=Number(e);return isFinite(t)?t:0}function rh(e,t){switch(t.type){case"sum":return x.sum(e);case"mean":return x.mean(e);case"median":return th(e);case"max":return x.max(e)??0;case"min":return x.min(e)??0;case"quantile":return en.quantile(e,t.config.p)??0;case"CV":const n=Dn.std(...e),r=Dn.mean(...e);return r?n/r:"N/A";case"std":return Dn.std(...e);default:return e}}function Xr(e,t){const n=e.map(nh);return rh(n,t)}function ih(e,t,n){try{const r=sn(e,t);return new Function(`return ${n.config.func}`)()({queryData:r},At)}catch(r){return console.error(r),r.message}}function Yn(e,t,n){try{return n.type==="custom"?ih(e,t,n):Xr(ft(e,t),n)}catch(r){return console.error(r),null}}const ah=[{label:"None",value:"none"},{label:"Sum",value:"sum"},{label:"Mean",value:"mean"},{label:"Median",value:"median"},{label:"Max",value:"max"},{label:"Min",value:"min"},{label:"Coefficient of Variation",value:"CV"},{label:"Standard Variation",value:"std"},{label:"Quantile(99%, 95%, ...)",value:"quantile"},{label:"Custom",value:"custom"}];function sh({label:e,value:t,onChange:n,pt:r="sm"},a){y.useEffect(()=>{typeof t=="string"&&n({type:t,config:{}})},[t,n]);const o=c=>{n(c==="quantile"?{type:"quantile",config:{p:.99}}:c==="custom"?{type:"custom",config:{func:Js}}:{type:c,config:{}})},l=c=>{n({type:"quantile",config:{p:c}})},u=c=>{n({type:"custom",config:{func:c}})};return p(s.Group,{grow:!0,noWrap:!0,pt:r,children:[i(s.Select,{ref:a,label:e,data:ah,value:t.type,onChange:o}),t.type==="quantile"&&i(s.NumberInput,{label:"p",value:t.config.p,onChange:l,precision:2,min:.05,step:.05,max:1}),t.type==="custom"&&i(eh,{label:"",triggerLabel:"Edit Function",value:t.config.func,onChange:u,defaultValue:Js,triggerButtonProps:{size:"xs",sx:{flexGrow:0,alignSelf:"center",marginTop:"22px"},leftIcon:i(E.IconMathFunction,{size:16})}})]})}const Qn=y.forwardRef(sh);function oh({label:e,value:t,onChange:n},r){const[a,o]=y.useState(Array.isArray(t)?[...t]:[]),l=y.useCallback(()=>{o(g=>[...g,""])},[o]),u=y.useCallback(g=>{o(m=>(m.splice(g,1),[...m]))},[o]),c=y.useMemo(()=>!x.isEqual(a,t),[a,t]),d=()=>{n(a.map(g=>g.toString()))},f=s.useMantineTheme(),h=y.useMemo(()=>Object.entries(f.colors).map(([g,m])=>m[6]),[f]);return p(B,{children:[p(s.Group,{position:"left",ref:r,children:[i(s.Text,{children:e}),i(s.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!c,onClick:d,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Group,{children:[a.map((g,m)=>i(s.ColorInput,{value:g,onChange:C=>{o(w=>(w.splice(m,1,C),[...w]))},swatches:h,rightSection:i(s.ActionIcon,{onClick:()=>u(m),color:"red",children:i(D.Trash,{size:14})}),sx:{width:"45%"}})),i(s.ActionIcon,{onClick:l,color:"blue",variant:"outline",children:i(D.PlaylistAdd,{size:20})})]})]})}const lh=y.forwardRef(oh);function uh({value:e,onChange:t},n){const{colorManager:r}=y.useContext(ct),a=y.useMemo(()=>r.getStaticColors().map(u=>({label:u.name,group:u.category,value:u.value})),[r]),o=y.useMemo(()=>a.some(l=>l.value===e),[e,a]);return p(s.Group,{position:"apart",spacing:4,ref:n,children:[i(s.TextInput,{placeholder:"Set any color",value:o?"":e,onChange:l=>t(l.currentTarget.value),rightSection:i(s.ColorSwatch,{color:o?"transparent":e,radius:4}),variant:o?"filled":"default",sx:{maxWidth:"46%",flexGrow:1}}),i(s.Text,{sx:{flexGrow:0},children:"or"}),i(s.Select,{data:a,value:e,onChange:t,variant:o?"default":"filled",placeholder:"Pick a theme color",icon:i(s.ColorSwatch,{color:o?e:"transparent",radius:4}),sx:{maxWidth:"46%",flexGrow:1}})]})}const $e=y.forwardRef(uh),Un=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function ch({label:e,value:t,onChange:n},r){var l;const[a,o]=y.useState(((l=Un.find(u=>u.label===t))==null?void 0:l.value)??Un[0].value);return y.useEffect(()=>{const u=Un.find(c=>c.value===a);u&&n(u.label)},[a]),p(s.Stack,{spacing:0,mt:"sm",mb:"lg",children:[i(s.Text,{size:"sm",children:e}),i(s.Slider,{label:null,marks:Un,value:a,onChange:o,step:25,placeholder:"Pick a font size",px:"1em",ref:r})]})}const Zs=y.forwardRef(ch);function dh({label:e,value:t,onChange:n,type:r},a){const[o,l]=y.useState(Array.isArray(t)?[...t]:[]),u=y.useCallback(()=>{l(h=>[...h,""])},[l]),c=y.useCallback(h=>{l(g=>(g.splice(h,1),[...g]))},[l]),d=y.useMemo(()=>!x.isEqual(o.map(String),t.map(String)),[o,t]),f=()=>{n(o.map(h=>r==="number"?Number(h):h.toString()))};return p(B,{children:[p(s.Group,{position:"left",ref:a,children:[i(s.Text,{children:e}),i(s.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!d,onClick:f,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Group,{children:[o.map((h,g)=>i(s.TextInput,{type:r,value:h,onChange:m=>{const C=m.currentTarget.value;l(w=>(w.splice(g,1,C),[...w]))},rightSection:i(s.ActionIcon,{onClick:()=>c(g),color:"red",children:i(D.Trash,{size:14})}),sx:{width:"45%"}})),i(s.ActionIcon,{onClick:u,color:"blue",variant:"outline",children:i(D.PlaylistAdd,{size:20})})]})]})}const ph=y.forwardRef(dh),Hs=y.forwardRef(function({value:t,onChange:n},r){const a=t.color.type,o=(u,c)=>{const d=x.cloneDeep(t);x.set(d,u,c),n(d)},l=u=>{if(u==="static"){n({...t,color:{type:"static",staticColor:"#25262B"}});return}n({...t,color:{type:"continuous",colorRange:[],valueRange:[]}})};return p(B,{children:[i(s.Divider,{my:"xs",label:"Typography",labelPosition:"center"}),i(s.Stack,{children:i(s.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1},value:t.size,onChange:u=>o("size",u.currentTarget.value)})}),i(s.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:i(Zs,{label:"Font Weight",value:t.weight,onChange:u=>o("weight",u)})}),i(s.Divider,{my:"xs",label:"Style",labelPosition:"center"}),p(s.Stack,{children:[i(s.Select,{label:"Color Type",data:[{label:"Static Color",value:"static"},{label:"Continuous Color",value:"continuous"}],value:t.color.type,onChange:l}),a==="static"&&i($e,{value:t.color.staticColor,onChange:u=>o("color.staticColor",u)}),a==="continuous"&&p(B,{children:[i(ph,{label:"Value Range",value:t.color.valueRange,type:"number",onChange:u=>o("color.valueRange",u)}),i(lh,{label:"Color Range",value:t.color.colorRange,onChange:u=>o("color.colorRange",u)})]})]})]})});y.forwardRef(function({value:t,onChange:n,withStyle:r=!0},a){const o=(l,u)=>{const c=x.cloneDeep(t);x.set(c,l,u),n(c)};return p(s.Box,{px:"sm",py:"md",ref:a,children:[i(s.Text,{weight:"bold",pb:0,children:t.name}),i(s.Divider,{my:"xs",label:"Data",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(s.TextInput,{label:"Name",required:!0,value:t.name,onChange:l=>o("name",l.currentTarget.value)}),i(W,{label:"Data Field",required:!0,value:t.data_field,onChange:l=>o("data_field",l)})]}),i(Qn,{label:"Aggregation",value:t.aggregation,onChange:l=>o("aggregation",l)}),i(s.Divider,{my:"xs",label:"Format",labelPosition:"center"}),t.aggregation.type!=="custom"&&i(We,{value:t.formatter,onChange:l=>o("formatter",l)}),r&&i(Hs,{value:t,onChange:n})]})});class hh{constructor({valueRange:t,colorRange:n}){q(this,"mapper");this.mapper=It.interpolate(t,n)}getColor(t){return this.mapper(t)}}function fh(e){return e===null?"null":e===void 0?"undefined":Array.isArray(e)?`Array(${e.length})`:e.toString()}function mt({data_field:e,aggregation:t},n){return Yn(n,e,t)}function Ze({formatter:e,aggregation:t},n){if(!["string","number"].includes(typeof n))return fh(n);if(t.type==="custom")return n;try{return Z(n).format(e)}catch(r){return console.error(r),n}}function gh(e,t){if(e.type==="static")return e.staticColor;if(e.type==="continuous")try{if(typeof t!="number")throw new Error(`[getColorByColorConf] Invalid type of aggregated value: ${t}`);return new hh(e).getColor(t)}catch(n){return console.error(n),"black"}return"black"}function eo(e,t){const{color:n,data_field:r,aggregation:a,size:o,weight:l}=e,u=Yn(t,r,a),c=Ze(e,u);return i(s.Text,{sx:{fontSize:o,display:"inline"},color:gh(n,u),weight:l,children:c})}function mh(e,t){const n={};return e.forEach(r=>{const a=r.name;n[a]=eo(r,t)}),n}function yh(e){return e.split(" ").map((t,n)=>p(y.Fragment,{children:[t," "]},n))}function bh(e){const n=e.replaceAll("<br />","<br/>").replaceAll(`
|
|
106
|
+
`,"<br/>").split("<br/>");return n.map((a,o)=>{const l=[yh(a)];return o!==n.length-1&&l.push(i("br",{},`br-${o}`)),l}).flat().filter(a=>a!==void 0)}function Jr(e){return bh(e)}function gn(e,t,n){const r=mh(t,n),a=/^\{(.+)\}(.*)$/;return e.split("$").map((o,l)=>{const u=a.exec(o);if(!u)return Jr(o);const c=r[u[1]];if(!c)return Jr(o);const d=u[2]??"";return p(y.Fragment,{children:[c,Jr(d)]},`${o}-${l}`)})}function vh(e,t){const n={};return e.forEach(r=>{const{name:a,data_field:o,aggregation:l}=r,u=Yn(t,o,l);n[a]=Ze(r,u)}),n}function Kn(e,t,n){const r=vh(t,n),a=/^\{(.+)\}(.*)$/;return e.split("$").map(o=>{const l=a.exec(o);if(!l)return o;const u=r[l[1]];if(!u)return o;const c=l[2]??"";return`${u}${c}`}).join("")}function xh(e,t,n){const r=t.reduce((a,o)=>{const l=mt(o,n);return a[o.name]=Ze(o,l),a},{});return e.map(a=>({name:"refs",type:"scatter",data:[],markLine:{data:[{name:a.name,yAxis:Number(r[a.variable_key])}],silent:!0,symbol:["none","none"],label:{formatter:function(){return Kn(a.template,t,n)},position:"insideEndTop"}}}))}function wh(e){const t={top:30,left:20,right:15,bottom:25,containLabel:!0};return e.legend.orient==="vertical"&&(t.right=80),t}function Ch({config:e,data:t,variables:n}){const{x_axis:r,y_axis:a,reference_lines:o}=e,l=yd(e,t),u=it(r.axisLabel.overflow.on_axis),c=vd(e);return{grid:wh(e),dataset:l,legend:bd({config:e}),tooltip:kd({config:e}),xAxis:[{type:"category",name:r.name,nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold",align:"center"},axisTick:{show:!0,alignWithLabel:!0},axisLabel:{...r.axisLabel,...u,formatter:qt(r.axisLabel.formatter)}}],yAxis:[{name:a.name,minInterval:1,nameTextStyle:{fontWeight:"bold"},axisLine:{show:!0},axisLabel:{formatter:function(d){return Z(d).format(a.label_formatter)}}}],series:[...c,...xh(o,n,t)]}}ie.use([F.DataZoomComponent,he.BoxplotChart,F.MarkLineComponent,F.GridComponent,F.LegendComponent,F.TooltipComponent,Ee.CanvasRenderer]);function Sh({context:e,instance:t}){const{value:n}=R(e.instanceData,"config"),{variables:r}=e,a=e.data,{width:o,height:l}=e.viewport,u=x.defaults({},n,Ar),c=Xe({vizManager:e.vizManager,instance:t}),d=Ke(c.triggerManager,fs.id),f=zt(a,u.x_axis.data_key),h=y.useCallback(C=>{const w=x.get(f,C.name,{error:"rowData is not found"});d.forEach(_=>{c.runInteraction(_.id,{...C,rowData:w})})},[f,d,c]),g=y.useMemo(()=>({click:h}),[h]),m=y.useMemo(()=>Ch({config:u,data:a,variables:r}),[u,a,r]);return!n||!o||!l?null:i(Ve,{width:o,height:l,children:i(ze,{echarts:ie,option:m,style:an(o,l),onEvents:g,notMerge:!0,theme:"merico-light"})})}function _h({control:e,index:t,remove:n,variableOptions:r}){return p(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:a})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:a})=>i(s.Select,{label:"Value",required:!0,data:r,sx:{flex:1},...a})})]}),i(v.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:a})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",required:!0,sx:{flex:1},...a})}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(t),sx:{position:"absolute",top:15,right:5},children:i(D.Trash,{size:16})})]},t)}function kh({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=r.map((f,h)=>({...f,...l[h]})),c=()=>a({name:"",template:"",variable_key:""}),d=y.useMemo(()=>n.map(f=>({label:f.name,value:f.name})),[n]);return p(s.Stack,{children:[u.map((f,h)=>i(_h,{control:e,index:h,remove:o,variableOptions:d},f.id)),i(s.Group,{position:"center",mt:"xs",children:i(s.Button,{onClick:c,children:"Add a Reference Line"})})]})}const Th=({disabled:e,value:t,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[e&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(De,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},Xn=y.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:a,setFalse:o}]=Q.useBoolean(),[l,u]=y.useState(e);y.useEffect(()=>{u(e)},[e]);const c=m=>{u({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:C}=l,w={enabled:m,func_content:C};u(w),t(w)},f=()=>{o(),u(e)},h=m=>{u(C=>({...C,func_content:m}))},g=()=>{h(Ue.func_content)};return p(B,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Customize Label"}),i(s.Modal,{size:800,title:"Customize label content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:m=>c(m.currentTarget.checked)}),i(Th,{value:l.func_content,onChange:h,disabled:!l.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:g,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:d,children:"OK"})]})]})]})})]})}),Dh=({control:e,watch:t})=>(t(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"X Axis Name",sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>i(W,{label:"X Axis Data Field",required:!0,sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>i(Xn,{...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>i(st,{...n})})]})),Ih=({control:e,watch:t})=>(t(["y_axis"]),p(B,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"Y Axis Name",sx:{flex:1},...n})}),i(v.Controller,{name:"y_axis.data_key",control:e,render:({field:n})=>i(W,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:"y_axis.label_formatter",control:e,render:({field:n})=>i(We,{...n})})]})]})),Mh=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),Ah=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(B,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(D.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Set additional metrics to show in scatter's tooltip"})]}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(Mh,{control:e,index:g,remove:a},h.id)},h.id))]})]})};function zh({control:e,watch:t}){return i(s.Stack,{children:i(Ah,{control:e,watch:t})})}const Eh=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}],$h=({control:e,watch:t})=>{const n=t("legend"),r=(a,o)=>{const l={...n,orient:a};a==="horizontal"?(l.top="0",l.left="auto",l.right="10",l.bottom="auto"):(l.top="10",l.left="auto",l.right="0",l.bottom="auto"),o(l)};return p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,mt:20,children:i(v.Controller,{name:"legend.show",control:e,render:({field:a})=>i(s.Switch,{label:"Show Legend",sx:{flex:1},checked:a.value,onChange:o=>a.onChange(o.currentTarget.checked)})})}),i(s.Group,{children:i(v.Controller,{name:"legend",control:e,render:({field:a})=>i(s.Select,{label:"Orientation",data:Eh,sx:{flex:1},value:a.value.orient,onChange:o=>{r(o,a.onChange)},disabled:!n.show})})})]})};function Lh({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),{variables:r}=e,a=y.useMemo(()=>x.defaults({},t,Ar),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]),u(["x_axis","y_axis","reference_lines","color"]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,t),[f,t]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),i(s.Tabs.Tab,{value:"Legend",children:"Legend"}),i(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"}),i(s.Tabs.Tab,{value:"Style",children:"Style"}),i(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(Dh,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(Ih,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Legend",children:i($h,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(zh,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Style",children:p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:"color",control:o,render:({field:g})=>i($e,{...g})})]})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(kh,{variables:r,control:o,watch:u})})]})]})})}function Oh(e){return x.omit(e,"variables")}function Ph(e){const{label_formatter:t=Ie,...n}=e.y_axis;return{...e,y_axis:{...n,label_formatter:t}}}function Bh(e){const t={rotate:0,formatter:{...Ue}},{axisLabel:n=t,...r}=e.x_axis;return{...e,x_axis:{...r,axisLabel:n}}}function Vh(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return x.defaultsDeep(t,e)}function Nh(e){delete e.config;const{x_axis:t,tooltip:n}=e.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:t,in_tooltip:n}}}};return x.defaultsDeep(r,e)}function qh(e){const t={tooltip:{metrics:[]}};return x.defaultsDeep(t,e)}function Fh(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,y_axis:o,tooltip:l,...u}=e;return{...u,x_axis:{...a,data_key:r(a.data_key)},y_axis:{...o,data_key:r(o.data_key)},tooltip:{...l,metrics:l.metrics.map(c=>({...c,data_key:r(c.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}function Gh(e){const t={legend:{show:!0,top:"0",right:"10",left:"auto",bottom:"auto",orient:"horizontal",type:"scroll"}};return x.defaultsDeep(t,e)}class Wh extends ge{constructor(){super(...arguments);q(this,"VERSION",9)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,{panelModel:r})=>{const{config:a}=n;return(a.variables||[]).forEach(l=>{r.variables.find(u=>u.name===l.name)||r.addVariable(l)}),{...n,version:2,config:Oh(a)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:Ph(r)}}),this.version(4,n=>{const{config:r}=n;return{...n,version:4,config:Bh(r)}}),this.version(5,n=>{const{config:r}=n;return{...n,version:5,config:Vh(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:Nh(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:qh(r)}}),this.version(8,(n,r)=>{const{config:a}=n;return{...n,version:8,config:Fh(a,r)}}),this.version(9,n=>{const{config:r}=n;return{...n,version:9,config:Gh(r)}})}}const jh={displayName:"Boxplot Chart",displayGroup:"ECharts-based charts",migrator:new Wh,name:"boxplot",viewRender:Sh,configRender:Lh,createConfig(){return{version:9,config:x.cloneDeep(Ar)}},triggers:[fs]},to={id:"builtin:button:click-button",displayName:"Click Button",nameRender:Yh,configRender:Rh,payload:[]};function Rh(e){return i(B,{})}function Yh(e){return i(s.Text,{children:"Click this button"})}const Zr={content:"Button",variant:"filled",color:"blue",size:"xs",compact:!1,horizontal_align:"left",vertical_align:"center"},Qh={left:"flex-start",center:"center",right:"flex-end"},Uh={top:"flex-start",center:"center",bottom:"flex-end"},Kh=k.observer(({context:e,instance:t})=>{const n=Xe({vizManager:e.vizManager,instance:t}),r=Ke(n.triggerManager,to.id),a=ye(),{value:o}=R(e.instanceData,"config"),l=y.useMemo(()=>x.defaultsDeep({},o,Zr),[o]),{content:u,horizontal_align:c,vertical_align:d,...f}=l,{width:h,height:g}=e.viewport,m=a.payloadForSQL,C=()=>{r.forEach(w=>{n.runInteraction(w.id,{})})};return i(s.Center,{sx:{width:h,height:g,justifyContent:Qh[c],alignItems:Uh[d]},children:i(s.Button,{...f,onClick:C,children:x.template(u)(m)})})}),Xh=({value:e,onChange:t,label:n})=>{const r=s.useMantineTheme(),a=y.useCallback(l=>()=>t(l),[t]),o=l=>e===l;return p(s.Stack,{spacing:2,children:[i(s.Text,{size:14,sx:{fontWeight:500},children:n}),i(s.Group,{position:"left",spacing:"xs",children:Object.keys(r.colors).map(l=>{const u=r.colors[l][6];return i(s.ColorSwatch,{color:u,onClick:a(l),radius:4,size:26,sx:{cursor:"pointer"},children:o(l)&&i(s.CheckIcon,{width:10,color:"white"})},l)})})]})},Jh=s.MANTINE_SIZES.map(e=>({label:e.toUpperCase(),value:e})),Zh=({label:e,value:t,onChange:n})=>i(s.Select,{data:Jh,label:e,value:t,onChange:n}),Hh=[{label:"Filled",value:"filled"},{label:"Outline",value:"outline"},{label:"Light",value:"light"},{label:"White",value:"white"},{label:"Default",value:"default"},{label:"Subtle",value:"subtle"},{label:"Gradient",value:"gradient",disabled:!0}],ef=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],tf=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function nf({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},t,Zr),[t]),a=r;y.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return u(["content","variant","color","size","compact","horizontal_align","vertical_align"]),p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Stack,{children:[i(v.Controller,{control:o,name:"content",render:({field:g})=>i(s.TextInput,{label:"Content Template",description:"Filter values & context entries are supported",...g,required:!0})}),i(s.Divider,{mt:"xs",mb:0,label:"Styles",labelPosition:"center",variant:"dashed"}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{control:o,name:"variant",render:({field:g})=>i(s.Select,{label:"Variant",data:Hh,...g})}),i(v.Controller,{control:o,name:"color",render:({field:g})=>i(Xh,{label:"Theme",...g})})]}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{control:o,name:"size",render:({field:g})=>i(Zh,{label:"Size",...g})}),i(v.Controller,{control:o,name:"compact",render:({field:g})=>i(s.Checkbox,{label:"Compact",checked:g.value,onChange:m=>g.onChange(m.currentTarget.checked),mt:26})})]}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{control:o,name:"horizontal_align",render:({field:g})=>i(s.Select,{label:"Horizontal Alignment",data:ef,...g})}),i(v.Controller,{control:o,name:"vertical_align",render:({field:g})=>i(s.Select,{label:"Vertical Alignment",data:tf,...g})})]})]})]})}class rf extends ge{constructor(){super(...arguments);q(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{horizontal_align:r="left",vertical_align:a="center",...o}=n.config;return{...n,version:2,config:{...o,horizontal_align:r,vertical_align:a}}})}}const af={displayName:"Button",displayGroup:"Others",migrator:new rf,name:"button",viewRender:Kh,configRender:nf,createConfig(){return{version:2,config:x.cloneDeep(Zr)}},triggers:[to]},Hr={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:of,configRender:sf,payload:[{name:"seriesType",description:"'line' | 'scatter' | 'bar'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function sf(e){return i(B,{})}function of(e){return i(s.Text,{children:"Click chart's series"})}const jt={x_axis_scroll:!1,y_axis_scroll:!1,x_axis_slider:!1,y_axis_slider:!1},ei={regressions:[],series:[],stats:{templates:{bottom:"",top:""}},x_axis:{type:"category",axisLabel:{rotate:0,formatter:{...Ue},overflow:je}},x_axis_data_key:"",x_axis_name:"",y_axes:[{min:"",max:"",name:"Y Axis",show:!0,position:"left",nameAlignment:"center",label_formatter:Ie}],reference_lines:[],reference_areas:[],dataZoom:jt};function ti(e){const t=[];return e.x_axis_scroll&&t.push({type:"inside",xAxisIndex:[0],filterMode:"none",minSpan:1}),e.y_axis_scroll&&t.push({type:"inside",yAxisIndex:[0],filterMode:"none",minSpan:1}),e.x_axis_slider&&t.push({type:"slider",xAxisIndex:[0],filterMode:"none",bottom:"auto",top:0,height:15,moveHandleSize:0,showDataShadow:!1,minSpan:1}),t}function lf(e){const t=e.y_axes.some(a=>!!a.name);let n=15;t&&(n+=20),e.dataZoom.x_axis_slider&&(n+=20);let r=5;return e.x_axis_name&&(r+=15),e.series.some(a=>!a.hide_in_legend)&&(r+=20),{top:n,right:15,bottom:r,left:20,containLabel:!0}}function uf(e){return e!=="line"?{}:{itemStyle:{opacity:0}}}function cf(e){switch(e){case"line":return;case"bar":return"roundRect";case"scatter":return"circle"}}function df(e){const t={show:!0,bottom:0,left:"center",type:"scroll"};return t.data=e.filter(n=>!n.hide_in_legend).map(({name:n,type:r})=>({name:n,icon:cf(r),...uf(r)})),t}function Jn(e,t){switch(e.config.method){case"linear":return[...wt.regressionLinear()(t)];case"exponential":return[...wt.regressionExp()(t)];case"logarithmic":return[...wt.regressionLog()(t)];case"polynomial":return[...wt.regressionPoly().order(e.config.order)(t)];default:return[]}}function pf(e,t,n,r){const{transform:a,plot:o}=e,l={...o,name:t,data:Jn(a,r),showSymbol:!1,tooltip:{show:!1},smooth:!1,custom:{}};return n&&(l.custom={type:"regression-line",targetSeries:n}),l}function hf({regressions:e=[],x_axis_data_key:t},n){const r=[];if(Object.keys(n).length===0)return r;function a(o,l,u,c){const d=pf(o,l,u,c);r.push(d)}return e.forEach(o=>{const{name:l,group_by_key:u}=o;if(!u||u===t){const h=ft(n,o.y_axis_data_key).map((g,m)=>[m,Number(g)]);a(o,l,"",h);return}const{columnKey:c}=O(o.y_axis_data_key),d=x.groupBy(sn(n,o.y_axis_data_key),u);Object.entries(d).forEach(([f,h])=>{const g=h.map((C,w)=>[w,Number(C[c])]);a(o,f,f,g)})}),r}function ff(e,t){return e.map(n=>({name:"",type:"line",hide_in_legend:!0,data:[],markArea:{itemStyle:{color:n.color},data:[[{yAxis:t[n.y_keys.upper]},{yAxis:t[n.y_keys.lower]}]],silent:!0}}))}function gf(e,t,n,r,a){return e.map(o=>{const l=n[o.variable_key],u=o.orientation==="horizontal",c=u?"yAxis":"xAxis",d=u?"insideEndTop":"end",f=u?[a[0],l]:[];return{name:o.name,type:"scatter",hide_in_legend:!o.show_in_legend,yAxisIndex:o.yAxisIndex,data:f,symbol:"none",silent:!0,tooltip:{show:!1},markLine:{data:[{name:o.name,[c]:l}],silent:!0,symbol:["none","none"],lineStyle:o.lineStyle,label:{formatter:function(){return o.template?Kn(o.template,t,r):""},position:d}}}})}function mf({type:e,...t},n,r,a){if(!e)return 10;if(e==="static"){const{size:d}=t;return d}const{func_content:o}=t,{queryID:l,columnKey:u}=O(r),c=x.keyBy(sn(n,l),u);return(d,f)=>{let h;f.name?h=c[f.name]:h=n[f.dataIndex];try{return new Function(`return ${o}`)()({rowData:h,params:f,variables:a},{lodash:x,interpolate:It.interpolate})}catch(g){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${g.message}`),10}}}function ni(e,t,n){const r=ft(e,t),a=ft(e,n);return x.zip(r,a)}function yf(e,t,n,r){const a=ni(t,n,r);return x.unionBy(a,e,0)}function bf({dataTemplate:e,data:t,x_axis_data_key:n,y_axis_data_key:r,valueTypedXAxis:a}){return a?yf(e,t,n,r):ft(t,r)}function vf({dataTemplate:e,data:t,aggregation_on_value:n,x_axis_data_key:r,y_axis_data_key:a,valueTypedXAxis:o}){if(!n||n.type==="none")return bf({dataTemplate:e,data:t,x_axis_data_key:r,y_axis_data_key:a,valueTypedXAxis:o});const l=ni(t,r,a),u=x.groupBy(l,"0");return e.map(([d])=>{const h=u[d].map(m=>m[1]),g=Xr(h,n);return[d,g]})}function xf({group_by_key:e,data:t,x_axis_data_key:n,y_axis_data_key:r}){const{queryID:a,columnKey:o}=O(e),l=x.groupBy(t[a],o);return Object.entries(l).forEach(([u,c])=>{l[u]=ni({[a]:c},n,r)}),l}function wf({x_axis_data_key:e,x_axis:t},{y_axis_data_key:n,yAxisIndex:r,label_position:a,name:o,group_by_key:l,aggregation_on_value:u,stack:c,color:d,display_name_on_line:f,symbolSize:h,hide_in_legend:g,...m},C,w,_,T){const M=t.type!=="category",P={label:{show:!!a,position:a,formatter:T[r??"default"]},name:o,xAxisId:"main-x-axis",yAxisIndex:r,stack:c,color:d,symbolSize:mf(h,w,e,_),hide_in_legend:g,labelLayout:{hideOverlap:!0},...m};if(f&&(P.endLabel={show:!0,formatter:o,offset:[-12,12],align:"right"}),!l||l===e)return P.data=vf({dataTemplate:C,data:w,aggregation_on_value:u,x_axis_data_key:e,y_axis_data_key:n,valueTypedXAxis:M}),P;const G=xf({group_by_key:l,data:w,x_axis_data_key:e,y_axis_data_key:n});return Object.entries(G).map(([$,L])=>{const A=x.cloneDeep(P);return A.name=$,A.color=void 0,A.data=L,A})}function Cf(e,t,n,r,a,o){const l=t.map(c=>[c,0]);return e.series.map(c=>wf(e,c,l,n,o,r)).flat().concat(gf(e.reference_lines,a,o,n,t)).concat(ff(e.reference_areas,o))}function Sf(e,t){const n=e.find(o=>o.axisDim==="x"&&o.axisId==="main-x-axis");if(!n)return"";const{axisValue:r,axisIndex:a}=n;return qt(t.x_axis.axisLabel.formatter)(r,a)}function _f(e,t,n){const r=t.reduce((a,{yAxisIndex:o,name:l})=>(a[l]=o,a),{});return{trigger:"axis",confine:!0,formatter:function(a){const o=Array.isArray(a)?a:[a];if(o.length===0)return"";const l=o.map(({seriesName:d,marker:f,value:h})=>{if(Array.isArray(h)&&h.length===2&&(h=h[1]),!d)return h;const g=r[d],m=n[g]??n.default;return`
|
|
107
107
|
<tr>
|
|
108
108
|
<td>${f}</td>
|
|
109
109
|
<th style="text-align: right; padding: 0 1em;">${d}</th>
|
|
110
110
|
<td style="text-align: left; padding: 0 1em;">${m({value:h})}</td>
|
|
111
111
|
</tr>
|
|
112
|
-
`}),u=ot(e.x_axis.axisLabel.overflow.in_tooltip),c=
|
|
112
|
+
`}),u=ot(e.x_axis.axisLabel.overflow.in_tooltip),c=Sf(o,e);return`
|
|
113
113
|
<div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
|
|
114
114
|
<div style="${u}">${c}</div>
|
|
115
115
|
</div>
|
|
@@ -118,8 +118,8 @@ Check the top-level render call using <`+V+">.")}return z}}function Tu(S,z){{if(
|
|
|
118
118
|
${l.join("")}
|
|
119
119
|
</tbody>
|
|
120
120
|
</table>
|
|
121
|
-
`}}}function Sf(e){return e.y_axes.reduce((n,{label_formatter:r},a)=>(n[a]=function(l){let u=l;if(typeof l=="object"&&(Array.isArray(l.value)&&l.value.length===2?u=l.value[1]:u=l.value),!r)return u;try{return Z(u).format(r)}catch(c){return console.error(c),u}},n),{default:({value:n})=>n})}function eo(e,t){const n={};return t.map(r=>{const a=mt(r,e);n[r.name]=Ze(r,a)}),n}function _f(e,t){const{overflow:n,...r}=e.x_axis.axisLabel,a=it(n.on_axis);return[{data:t,name:e.x_axis_name??"",id:"main-x-axis",axisTick:{show:!0,alignWithLabel:!0},type:e.x_axis.type,axisLabel:{...r,...a,formatter:qt(r.formatter)}}]}function kf(e){var t;try{return Array.isArray(e[0])&&((t=e[0])==null?void 0:t.length)>=2?e.map(r=>Number(r[1])):[...e]}catch(n){return console.error(n),[...e]}}function Tf(e){if(e.length===0)return{};const t={},n={};return e.forEach(r=>{const a=kf(r.data);if(!n[r.yAxisIndex]){n[r.yAxisIndex]=a;return}n[r.yAxisIndex]=n[r.yAxisIndex].concat(a)}),Object.entries(n).forEach(([r,a])=>{const o=x.minBy(a)??0,l=x.maxBy(a)??0;o===0&&l===0&&(t[r]=1)}),t}function Df(e,t,n){const r=Tf(n);return e.y_axes.map(({nameAlignment:a,min:o,max:l,show:u,...c},d)=>{let f=c.position;return f||(f=d>0?"right":"left"),{...c,minInterval:r[d]??0,show:u,min:o||void 0,max:l||void 0,position:f,axisLabel:{show:u,formatter:t[d]??t.default},axisLine:{show:u},nameTextStyle:{fontWeight:"bold",align:a},nameLocation:"end",nameGap:u?15:0,splitLine:{show:!1}}})}const If={xAxis:[{type:"category",nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0}}]};function Mf(e,t,n){const r=eo(t,n),a=Sf(e),o=x.uniq(ft(t,e.x_axis_data_key)),l=xf(e,o,t,a,n,r),u=df(e,t),c={xAxis:_f(e,o),yAxis:Df(e,a,l),series:[...l,...u],tooltip:Cf(e,l,a),grid:sf(e),legend:uf(l),dataZoom:ti(e.dataZoom)};return x.defaultsDeep({},c,If)}function to(e){const t=e.getModel(),n=t.getSeries().map(r=>{if(!r.option.custom)return r.option;const a=t.getColorFromPalette(r.option.custom.targetSeries,null);return r.option.color=a,r.option});e.setOption({...e.getOption(),series:n})}ie.use([F.DataZoomComponent,he.BarChart,he.LineChart,he.ScatterChart,F.GridComponent,F.LegendComponent,F.TooltipComponent,Ee.CanvasRenderer,F.MarkLineComponent,F.MarkAreaComponent]);function no(e){return e.trim().length>0}function Af({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=zt(t,e.x_axis_data_key),u=Ke(a.triggerManager,Hr.id),c=y.useCallback(m=>{const C=x.get(l,m.name,{error:"rowData is not found"});u.forEach(w=>{a.runInteraction(w.id,{...m,rowData:C})})},[l,u,a]),d=y.useMemo(()=>Mf(e,t,o),[e,t]),f=y.useRef(),h=y.useMemo(()=>({click:c}),[c]),g=m=>{f.current=m,to(m)};return y.useEffect(()=>{f.current&&to(f.current)},[d]),!n||!r?null:i(ze,{echarts:ie,option:d,style:{width:n,height:r},onEvents:h,onChartReady:g,notMerge:!0,theme:"merico-light"})}function zf({context:e,instance:t}){const n=Xe({vizManager:e.vizManager,instance:t}),{value:r}=R(e.instanceData,"config"),{variables:a}=e,o=y.useMemo(()=>x.defaults({},r,ei),[r]),l=e.data,{width:u,height:c}=e.viewport,{ref:d,height:f}=ke.useElementSize(),{ref:h,height:g}=ke.useElementSize(),m=y.useMemo(()=>{const{stats:{templates:_}}=o;return{top:gn(_.top,a,l),bottom:gn(_.bottom,a,l)}},[o,l]),C=Math.max(0,nt(c)-f-g),w=tt(u);return p(Ve,{width:u,height:c,children:[i(s.Text,{ref:d,align:"left",size:"xs",pl:"sm",sx:{display:no(o.stats.templates.top)?"block":"none"},children:Object.values(m.top).map((_,T)=>i(y.Fragment,{children:_},T))}),i(Af,{variables:a,width:w,height:C,data:l,conf:o,interactionManager:n}),i(s.Text,{ref:h,align:"left",size:"xs",pl:"sm",sx:{display:no(o.stats.templates.bottom)?"block":"none"},children:Object.values(m.bottom).map((_,T)=>i(y.Fragment,{children:_},T))})]})}const ri=y.forwardRef(({value:e,onChange:t},n)=>{const r=a=>o=>{t({...e,[a]:o})};return p(s.Stack,{children:[i(s.Divider,{variant:"dashed",label:"Scroll to Zoom",labelPosition:"center"}),p(s.Group,{children:[i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Enable on X Axis",checked:e.x_axis_scroll,onChange:a=>r("x_axis_scroll")(a.currentTarget.checked)})}),i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Enable on Y Axis",checked:e.y_axis_scroll,onChange:a=>r("y_axis_scroll")(a.currentTarget.checked)})})]}),i(s.Divider,{variant:"dashed",label:"Slider for Zooming",labelPosition:"center"}),p(s.Group,{children:[i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Slider for X Axis",checked:e.x_axis_slider,onChange:a=>r("x_axis_slider")(a.currentTarget.checked)})}),i(s.Tooltip,{label:"Not available for now, will overlap y-axis's label",children:i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Slider for Y Axis",disabled:!e.y_axis_slider,checked:e.y_axis_slider,onChange:a=>r("y_axis_slider")(a.currentTarget.checked)})})})]})]})}),Ef=[{label:"Rectangle",value:"rectangle"}],$f=[{label:"Horizontal",value:"horizontal"}];function Lf({control:e,index:t,remove:n,variableOptions:r}){return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_areas.${t}.name`,control:e,render:({field:a})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_areas.${t}.color`,control:e,render:({field:a})=>i(s.TextInput,{label:"Color",required:!0,sx:{flex:1},...a})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_areas.${t}.type`,control:e,render:({field:a})=>i(s.Select,{label:"Type",required:!0,data:Ef,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_areas.${t}.direction`,control:e,render:({field:a})=>i(s.Select,{label:"Direction",required:!0,data:$f,sx:{flex:1},...a})})]}),i(s.Divider,{variant:"dashed",label:"Data",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_areas.${t}.y_keys.upper`,control:e,render:({field:a})=>i(s.Select,{label:"Upper Boundary",required:!0,data:r,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_areas.${t}.y_keys.lower`,control:e,render:({field:a})=>i(s.Select,{label:"Lower Boundary",required:!0,data:r,sx:{flex:1},...a})})]}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Area"})]},t)}function Of({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_areas"}),l=t("reference_areas"),u=r.map((f,h)=>({...f,...l[h]})),c=()=>a({name:"",color:"rgba(0,0,0,0.1)",type:"rectangle",direction:"horizontal",y_keys:{upper:"",lower:""}}),d=y.useMemo(()=>n.map(f=>({label:f.name,value:f.name})),[n]);return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"6px 0px 0px"}},children:[p(s.Tabs.List,{children:[u.map((f,h)=>i(s.Tabs.Tab,{value:h.toString(),children:h+1},h)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),u.map((f,h)=>i(s.Tabs.Panel,{value:h.toString(),children:i(Lf,{control:e,index:h,remove:o,variableOptions:d})},h))]})}const Pf=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Bf=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Vf({control:e,index:t,remove:n,watch:r,variableOptions:a,yAxisOptions:o}){const l=r(`reference_lines.${t}.orientation`);return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:u})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:u})=>i(s.Select,{label:"Value",required:!0,data:a,sx:{flex:1},...u})})]}),i(v.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:u})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...u})}),p(s.Group,{grow:!0,children:[p(s.Stack,{children:[i(v.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:u})=>i(s.Select,{label:"Orientation",data:Bf,required:!0,sx:{flex:1},...u})}),l==="vertical"&&i(s.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&i(v.Controller,{name:`reference_lines.${t}.yAxisIndex`,control:e,render:({field:{value:u,onChange:c,...d}})=>i(s.Select,{label:"Y Axis",data:o,disabled:o.length===0,...d,value:(u==null?void 0:u.toString())??"",onChange:f=>{if(!f){c(0);return}c(Number(f))},sx:{flex:1}})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:u})=>i(s.Select,{label:"Line Type",data:Pf,sx:{flexGrow:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:u})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...u})})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:u})=>i($e,{...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`reference_lines.${t}.show_in_legend`,control:e,render:({field:u})=>i(s.Checkbox,{label:"Show in legend",checked:u.value,onChange:c=>u.onChange(c.currentTarget.checked)})}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]},t)}function Nf({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=r.map((g,m)=>({...g,...l[m]})),c=()=>{a({name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,yAxisIndex:0})},d=y.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=t("y_axes"),h=y.useMemo(()=>f.map(({name:g},m)=>({label:g,value:m.toString()})),[f]);return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[u.map((g,m)=>i(s.Tabs.Tab,{value:m.toString(),children:m+1},m)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),u.map((g,m)=>i(s.Tabs.Panel,{value:m.toString(),children:i(Vf,{control:e,index:m,remove:o,watch:t,variableOptions:d,yAxisOptions:h})},m))]})}const qf=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}],Ff=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function Gf({control:e,regressionItem:t,index:n,remove:r,yAxisOptions:a}){const o=t.transform.config.method;return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,children:[i(v.Controller,{name:`regressions.${n}.name`,control:e,render:({field:l})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`regressions.${n}.group_by_key`,control:e,render:({field:l})=>i(W,{label:"Split into multiple regression lines by this key...",clearable:!0,sx:{flex:1},...l})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`regressions.${n}.y_axis_data_key`,control:e,render:({field:l})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`regressions.${n}.plot.yAxisIndex`,control:e,render:({field:{value:l,onChange:u,...c}})=>i(s.Select,{label:"Y Axis",data:a,disabled:a.length===0,...c,value:(l==null?void 0:l.toString())??"",onChange:d=>{if(!d){u(0);return}u(Number(d))},sx:{flex:1}})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`regressions.${n}.transform.config.method`,control:e,render:({field:l})=>i(s.Select,{label:"Method",data:qf,sx:{flex:1},...l})}),o==="polynomial"&&i(v.Controller,{name:`regressions.${n}.transform.config.order`,control:e,render:({field:l})=>i(s.NumberInput,{label:"Order",sx:{flex:1},...l})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Line Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`regressions.${n}.plot.lineStyle.type`,control:e,render:({field:l})=>i(s.Select,{label:"Line Type",data:Ff,sx:{flexGrow:1},...l})}),i(v.Controller,{name:`regressions.${n}.plot.lineStyle.width`,control:e,render:({field:l})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...l})})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`regressions.${n}.plot.color`,control:e,render:({field:l})=>i($e,{...l})})]}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(n),sx:{top:15,right:5},children:"Delete this Regression Line"})]},n)}function Wf({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"regressions"}),o=t("regressions"),l=n.map((f,h)=>({...f,...o[h]})),u=t("y_axes"),c=y.useMemo(()=>u.map(({name:f},h)=>({label:f,value:h.toString()})),[u]),d=()=>r({transform:{type:"ecStat:regression",config:{method:"linear",order:1,formulaOn:"end"}},group_by_key:"",name:"",y_axis_data_key:"",plot:{type:"line",yAxisIndex:0,color:"#666666",lineStyle:{type:"solid",width:1}}});return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((f,h)=>i(s.Tabs.Tab,{value:h.toString(),children:h+1},h)),i(s.Tabs.Tab,{onClick:d,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((f,h)=>i(s.Tabs.Panel,{value:h.toString(),children:i(Gf,{regressionItem:f,control:e,index:h,remove:a,yAxisOptions:c},h)},h))]})}const ii={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
|
|
122
|
-
`)}},jf=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function Rf({control:e,index:t,seriesItem:n}){const r=!!n.barWidth.trim();return p(B,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.stack`,control:e,render:({field:a})=>i(s.TextInput,{label:"Stack",placeholder:"Stack bars by this ID",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barGap`,control:e,render:({field:a})=>i(s.Select,{label:"Bar Gap",data:jf,sx:{flexGrow:1},...a})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.barMinWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Min)",disabled:r,sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barMaxWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Max)",disabled:r,sx:{flexGrow:1},...a})})]})]})}const Yf=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return i(s.Box,{children:i(De,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Qf=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:a}]=Q.useBoolean(),[o,l]=y.useState(e),u=()=>{a();const{type:h,func_content:g}=o,m={type:h,func_content:g};l(m),t(m)},c=()=>{a(),l(e)},d=h=>{l(g=>({...g,func_content:h}))},f=()=>{d(ii.dynamic.func_content)};return p(B,{children:[i(s.Box,{sx:{width:"50%"},children:i(s.Button,{variant:"filled",mt:24,onClick:r,sx:{flexGrow:0},children:"Setup"})}),i(s.Modal,{size:800,title:"Setup dynamic size",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&p(s.Stack,{children:[i(s.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),i(Yf,{value:o.func_content,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:c,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:u,children:"OK"})]})]})]})})]})},Uf=({value:e,onChange:t})=>e.type!=="dynamic"?null:i(Qf,{value:e,onChange:t}),Kf=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=r=>{t({...e,size:r})};return i(B,{children:i(s.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:e.size,onChange:n})})},Xf=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],ro=y.forwardRef(({label:e="Size",value:t,onChange:n},r)=>{const a=o=>{n({...ii[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:e,data:Xf,value:t.type,onChange:a,sx:{flexGrow:1}}),i(Kf,{value:t,onChange:n}),i(Uf,{value:t,onChange:n})]})}),Jf=[{label:"off",value:"false"},{label:"start",value:"start"},{label:"middle",value:"middle"},{label:"end",value:"end"}],Zf=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function Hf({control:e,index:t,seriesItem:n}){const r=n.showSymbol;return p(B,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Line Settings",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`series.${t}.lineStyle.type`,control:e,render:({field:a})=>i(s.Select,{label:"Line Type",data:Zf,sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.lineStyle.width`,control:e,render:({field:a})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...a})})]}),p(s.Group,{grow:!0,align:"center",children:[i(v.Controller,{name:`series.${t}.step`,control:e,render:({field:a})=>i(s.Select,{label:"Step",data:Jf,sx:{flexGrow:1,maxWidth:"48%"},...a,value:String(a.value),onChange:o=>{const l=o==="false"?!1:o;a.onChange(l)}})}),p(s.Stack,{children:[i(v.Controller,{name:`series.${t}.smooth`,control:e,render:({field:a})=>i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Smooth Line",checked:a.value,onChange:o=>a.onChange(o.currentTarget.checked)})})}),i(v.Controller,{name:`series.${t}.display_name_on_line`,control:e,render:({field:a})=>i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Display Name on Line",checked:a.value??!1,onChange:o=>a.onChange(o.currentTarget.checked)})})})]})]}),p(s.Stack,{children:[i(v.Controller,{name:`series.${t}.showSymbol`,control:e,render:({field:a})=>i(s.Box,{mt:10,mb:-10,sx:{flexGrow:1},children:i(s.Switch,{label:"Show Symbol on Line",checked:a.value,onChange:o=>a.onChange(o.currentTarget.checked)})})}),r&&i(v.Controller,{name:`series.${t}.symbolSize`,control:e,render:({field:a})=>i(ro,{label:"Symbol Size",...a})})]})]})}function eg({control:e,index:t}){return i(v.Controller,{name:`series.${t}.symbolSize`,control:e,render:({field:n})=>i(ro,{label:"Size",...n})})}const tg=[{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 ng({control:e,index:t,remove:n,seriesItem:r,yAxisOptions:a}){const o=r.type;return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[i(s.Stack,{children:i(v.Controller,{name:`series.${t}.type`,control:e,render:({field:l})=>i(s.SegmentedControl,{data:[{label:"Line",value:"line"},{label:"Bar",value:"bar"},{label:"Scatter",value:"scatter"}],...l})})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.name`,control:e,render:({field:l})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`series.${t}.yAxisIndex`,control:e,render:({field:{value:l,onChange:u,...c}})=>i(s.Select,{label:"Y Axis",data:a,disabled:a.length===0,...c,value:(l==null?void 0:l.toString())??"",onChange:d=>{if(!d){u(0);return}u(Number(d))},sx:{flex:1}})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.y_axis_data_key`,control:e,render:({field:l})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`series.${t}.aggregation_on_value`,control:e,render:({field:l})=>i(Qn,{label:"Aggregation on Value",value:l.value??Wt,onChange:l.onChange,pt:0})})]}),i(s.Group,{grow:!0,children:i(v.Controller,{name:`series.${t}.group_by_key`,control:e,render:({field:l})=>i(W,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...l})})}),o==="line"&&i(Hf,{index:t,control:e,seriesItem:r}),o==="bar"&&i(Rf,{index:t,control:e,seriesItem:r}),o==="scatter"&&i(eg,{index:t,control:e}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),i(v.Controller,{name:`series.${t}.label_position`,control:e,render:({field:l})=>i(s.Select,{label:"Label Position",data:tg,...l})}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`series.${t}.color`,control:e,render:({field:l})=>i($e,{...l})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`series.${t}.hide_in_legend`,control:e,render:({field:l})=>i(s.Checkbox,{label:"Hide in legend",checked:l.value,onChange:u=>l.onChange(u.currentTarget.checked)})}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Series"})]},t)}function rg({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"series"}),o=t("series"),l=n.map((f,h)=>({...f,...o[h]})),u=()=>{const f={type:"bar",name:ke.randomId(),showSymbol:!1,symbolSize:ii.static,y_axis_data_key:"value",yAxisIndex:0,label_position:"top",display_name_on_line:!1,stack:"",color:"#000",step:!1,smooth:!1,barMinWidth:"1",barWidth:"10%",barMaxWidth:"10",barGap:"0%",lineStyle:{type:"solid",width:1},hide_in_legend:!1,group_by_key:""};r(f)},c=t("y_axes"),d=y.useMemo(()=>c.map(({name:f},h)=>({label:f,value:h.toString()})),[c]);return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((f,h)=>i(s.Tabs.Tab,{value:h.toString(),children:h+1},f.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((f,h)=>i(s.Tabs.Panel,{value:h.toString(),children:i(ng,{control:e,index:h,remove:a,seriesItem:f,yAxisOptions:d},f.id)},f.id))]})}function ig({control:e,watch:t}){return t("stats"),i(s.Stack,{children:p(s.Stack,{spacing:0,children:[i(v.Controller,{name:"stats.templates.top",control:e,render:({field:n})=>i(on,{label:"Template for stats above the chart",py:"md",sx:{flexGrow:1},...n})}),i(v.Controller,{name:"stats.templates.bottom",control:e,render:({field:n})=>i(on,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const ag=()=>p(s.Group,{sx:{display:"inline-flex"},spacing:6,mr:14,children:[i(s.Text,{children:"X Axis Data Type"}),p(s.HoverCard,{width:340,shadow:"md",position:"top",children:[i(s.HoverCard.Target,{children:i(s.ActionIcon,{size:"xs",sx:{transform:"none !important"},children:i(E.IconInfoCircle,{})})}),i(s.HoverCard.Dropdown,{children:p(s.Text,{size:"sm",children:["Click",i(s.Anchor,{href:"https://echarts.apache.org/en/option.html#xAxis.type",target:"_blank",mx:4,children:"here"}),"to learn more about these options"]})})]})]}),sg=[{label:"Value",value:"value"},{label:"Category",value:"category"},{label:"Time",value:"time"},{label:"Log",value:"log"}];function og({control:e,watch:t}){return t(["x_axis_data_key","x_axis_name","x_axis"]),p(s.Stack,{children:[i(v.Controller,{name:"x_axis_name",control:e,render:({field:n})=>i(s.TextInput,{label:"X Axis Name",sx:{flex:1},...n})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis_data_key",control:e,render:({field:n})=>i(W,{label:"X Axis Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.type",control:e,render:({field:n})=>i(s.Select,{label:i(ag,{}),required:!0,data:sg,sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>i(Xn,{...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>i(st,{...n})})]})}const lg=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],ug=[{label:"left",value:"left"},{label:"right",value:"right"}];function cg({control:e,index:t,remove:n}){return p(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[i(s.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`y_axes.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`y_axes.${t}.nameAlignment`,control:e,render:({field:r})=>i(s.Select,{label:"Name Anchor",required:!0,data:lg,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`y_axes.${t}.position`,control:e,render:({field:r})=>i(s.Select,{label:"Position",required:!0,data:ug,sx:{flex:1},...r})})}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:`y_axes.${t}.label_formatter`,control:e,render:({field:r})=>i(We,{...r})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`y_axes.${t}.min`,control:e,render:({field:r})=>i(s.TextInput,{label:"Min",...r})}),i(v.Controller,{name:`y_axes.${t}.max`,control:e,render:({field:r})=>i(s.TextInput,{label:"Max",...r})})]})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`y_axes.${t}.show`,control:e,render:({field:r})=>i(s.Checkbox,{label:"Visible",checked:r.value,onChange:a=>r.onChange(a.currentTarget.checked)})}),i(s.Button,{mt:20,leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this YAxis"})]})}function dg({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"y_axes"}),o=t("y_axes"),l=n.map((c,d)=>({...c,...o[d]})),u=()=>r({name:"",position:"left",nameAlignment:"left",label_formatter:Ie,min:"",max:"",show:!0});return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[l.map((c,d)=>i(s.Tabs.Tab,{value:d.toString(),children:d+1},d)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((c,d)=>i(s.Tabs.Panel,{value:d.toString(),children:i(cg,{control:e,index:d,remove:a})},d))]})}function pg({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),{variables:r}=e,a=y.useMemo(()=>x.defaultsDeep({},t,ei),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,a),[f,a]);return u(["dataZoom"]),i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"Series",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axes",children:"Y Axes"}),i(s.Tabs.Tab,{value:"Series",children:"Series"}),i(s.Tabs.Tab,{value:"Regression Lines",children:"Regression Lines"}),i(s.Tabs.Tab,{value:"Stats",children:"Stats"}),i(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"}),i(s.Tabs.Tab,{value:"Reference Areas",children:"Reference Areas"}),i(s.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(og,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axes",children:i(dg,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Series",children:i(rg,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Regression Lines",children:i(Wf,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Stats",children:i(ig,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(Nf,{variables:r,control:o,watch:u})}),i(s.Tabs.Panel,{value:"Reference Areas",children:i(Of,{variables:r,control:o,watch:u})}),i(s.Tabs.Panel,{value:"Zooming",children:i(v.Controller,{name:"dataZoom",control:o,render:({field:g})=>i(ri,{...g})})})]})]})})}function hg(e){const t=x.cloneDeep(x.omit(e,"variables"));return t.stats=x.omit(t.stats,"variables"),t}function fg(e){const{rotate:t,formatter:n=Ue}=e.x_axis.axisLabel;return{...e,x_axis:{...e.x_axis,axisLabel:{rotate:t,formatter:n}}}}function gg(e){const{dataZoom:t=jt,...n}=e;return{...n,dataZoom:t}}function mg(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return x.defaultsDeep(t,e)}function yg(e){const t=e.reference_lines.map(n=>{const{lineStyle:r={type:"dashed",width:1,color:pt.random().css()},show_in_legend:a=!1}=n;return{...n,lineStyle:r,show_in_legend:a}});return{...e,reference_lines:t}}function bg(e){const t=e.reference_lines.map(n=>{const{yAxisIndex:r=0}=n;return{...n,yAxisIndex:r}});return{...e,reference_lines:t}}function vg(e){const t=e.series.map(n=>{const{aggregation_on_group:r=Wt}=n;return{...n,aggregation_on_group:r}});return{...e,series:t}}function xg(e){const t=e.series.map(n=>{const{aggregation_on_value:r=Wt}=n;return{...n,aggregation_on_value:r}});return{...e,series:t}}function wg(e){delete e.config;const{x_axis:t,tooltip:n}=e.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:t,in_tooltip:n}}}};return x.defaultsDeep(r,e)}function Cg(e){const{series:t,...n}=e;return{...n,series:t.map(r=>{const{barMinWidth:a,barWidth:o,barMaxWidth:l}=r;return a?{...r,barMinWidth:a,barWidth:"",barMaxWidth:l??o}:{...r,barMinWidth:"",barWidth:o,barMaxWidth:""}})}}function Sg(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(r=>{const{min:a="",max:o=""}=r;return{...r,min:a,max:o}})}}function _g(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(r=>{const{nameAlignment:a="left"}=r;return{...r,nameAlignment:a}})}}function kg(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(r=>{const{show:a=!0}=r;return{...r,show:a}})}}function Tg(e){const{regressions:t,...n}=e;return{...n,regressions:t.map(r=>{const{group_by_key:a=""}=r;return{...r,group_by_key:a}})}}function Dg(e){const{series:t,y_axes:n,...r}=e;return{...r,series:t.map(a=>{const{hide_in_legend:o=!1,aggregation_on_value:l=Wt}=a;return{...a,hide_in_legend:o,aggregation_on_value:l}}),y_axes:n.map(a=>{const{min:o="",max:l="",show:u=!0}=a;return{...a,min:o,max:l,show:u}})}}function Ig(e){const{type:t="category",...n}=e.x_axis;return{...e,x_axis:{...n,type:t}}}function Mg(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis_data_key:a,series:o,regressions:l,...u}=e;return{...u,x_axis_data_key:r(a),series:o.map(c=>({...c,y_axis_data_key:r(c.y_axis_data_key),group_by_key:r(c.group_by_key)})),regressions:l.map(c=>({...c,y_axis_data_key:r(c.y_axis_data_key),group_by_key:r(c.group_by_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class Ag extends ge{constructor(){super(...arguments);q(this,"VERSION",18)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,{panelModel:r})=>{const{config:a}=n;return(a.variables||[]).forEach(u=>{r.variables.find(c=>c.name===u.name)||r.addVariable(u)}),(x.get(a,"stats.variables")||[]).forEach(u=>{r.variables.find(c=>c.name===u.name)||r.addVariable(u)}),{...n,version:2,config:hg(a)}}),this.version(3,n=>({...n,version:3,config:fg(n.config)})),this.version(4,n=>({...n,version:4,config:gg(n.config)})),this.version(5,n=>({...n,version:5,config:mg(n.config)})),this.version(6,n=>({...n,version:6,config:yg(n.config)})),this.version(7,n=>({...n,version:7,config:bg(n.config)})),this.version(8,n=>({...n,version:8,config:vg(n.config)})),this.version(9,n=>({...n,version:9,config:xg(n.config)})),this.version(10,n=>({...n,version:10,config:wg(n.config)})),this.version(11,n=>({...n,version:11,config:Cg(n.config)})),this.version(12,n=>({...n,version:12,config:Sg(n.config)})),this.version(13,n=>({...n,version:13,config:_g(n.config)})),this.version(14,n=>({...n,version:14,config:kg(n.config)})),this.version(15,n=>({...n,version:15,config:Tg(n.config)})),this.version(16,n=>({...n,version:16,config:Dg(n.config)})),this.version(17,n=>({...n,version:17,config:Ig(n.config)})),this.version(18,(n,r)=>({...n,version:18,config:Mg(n.config,r)}))}}const zg={displayName:"Cartesian Chart",displayGroup:"ECharts-based charts",migrator:new Ag,name:"cartesian",viewRender:zf,configRender:pg,createConfig(){return{version:18,config:x.cloneDeep(ei)}},triggers:[Hr]};function Eg(e){if(e.enable_value)return e.value}function $g(e){if(e.enable_value)return e.value}function Lg(e){const t=e.axisLabel.overflow.on_axis.width,n=e.axisLabel.position,r={top:5,left:5,right:5,bottom:5};return e.orient==="vertical"&&x.get(r,n)&&n===e.funnelAlign&&x.set(r,n,t),r}function Og(e,t){return e.series.map(n=>{const{level_name_data_key:r,level_value_data_key:a,axisLabel:o,min:l,max:u,funnelAlign:c,orient:d,...f}=n;if(!r||!a)return{};const h=O(r),g=O(a),m=t[h.queryID].map(w=>({name:w[h.columnKey],value:w[g.columnKey]})),C=it(o.overflow.on_axis);return{type:"funnel",...Lg(n),min:Eg(l),max:$g(u),minSize:l.size,maxSize:u.size,...f,label:{show:!0,position:o.position,...C},orient:d,funnelAlign:d==="horizontal"?"center":c,data:m}})}function Pg({conf:e,params:t,max:n}){const{name:r,value:a}=t.data,o=Z(a/n).format({output:"percent",mantissa:2,trimMantissa:!0});return[{label:`${t.marker} ${r}`,value:`${a} (${o})`,style:{label:"",value:""}}]}function Bg(e,t){var o;const n=O(e.series[0].level_name_data_key),r=O(e.series[0].level_value_data_key),a=(o=x.maxBy(t[n.queryID],r.columnKey))==null?void 0:o[r.columnKey];return l=>{const c=Pg({conf:e,params:l,max:a}).map(f=>`
|
|
121
|
+
`}}}function kf(e){return e.y_axes.reduce((n,{label_formatter:r},a)=>(n[a]=function(l){let u=l;if(typeof l=="object"&&(Array.isArray(l.value)&&l.value.length===2?u=l.value[1]:u=l.value),!r)return u;try{return Z(u).format(r)}catch(c){return console.error(c),u}},n),{default:({value:n})=>n})}function no(e,t){const n={};return t.map(r=>{const a=mt(r,e);n[r.name]=Ze(r,a)}),n}function Tf(e,t){const{overflow:n,...r}=e.x_axis.axisLabel,a=it(n.on_axis);return[{data:t,name:e.x_axis_name??"",id:"main-x-axis",axisTick:{show:!0,alignWithLabel:!0},type:e.x_axis.type,axisLabel:{...r,...a,formatter:qt(r.formatter)}}]}function Df(e){var t;try{return Array.isArray(e[0])&&((t=e[0])==null?void 0:t.length)>=2?e.map(r=>Number(r[1])):[...e]}catch(n){return console.error(n),[...e]}}function If(e){if(e.length===0)return{};const t={},n={};return e.forEach(r=>{const a=Df(r.data);if(!n[r.yAxisIndex]){n[r.yAxisIndex]=a;return}n[r.yAxisIndex]=n[r.yAxisIndex].concat(a)}),Object.entries(n).forEach(([r,a])=>{const o=x.minBy(a)??0,l=x.maxBy(a)??0;o==0&&l==0&&(t[r]=1)}),t}function Mf(e,t,n){const r=If(n);return e.y_axes.map(({nameAlignment:a,min:o,max:l,show:u,...c},d)=>{let f=c.position;return f||(f=d>0?"right":"left"),{...c,minInterval:r[d]??0,show:u,min:o||void 0,max:l||void 0,position:f,axisLabel:{show:u,formatter:t[d]??t.default},axisLine:{show:u},nameTextStyle:{fontWeight:"bold",align:a},nameLocation:"end",nameGap:u?15:0,splitLine:{show:!1}}})}const Af={xAxis:[{type:"category",nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0}}]};function zf(e,t,n){const r=no(t,n),a=kf(e),o=x.uniq(ft(t,e.x_axis_data_key)),l=Cf(e,o,t,a,n,r),u=hf(e,t),c={xAxis:Tf(e,o),yAxis:Mf(e,a,l),series:[...l,...u],tooltip:_f(e,l,a),grid:lf(e),legend:df(l),dataZoom:ti(e.dataZoom)};return x.defaultsDeep({},c,Af)}function ro(e){const t=e.getModel(),n=t.getSeries().map(r=>{if(!r.option.custom)return r.option;const a=t.getColorFromPalette(r.option.custom.targetSeries,null);return r.option.color=a,r.option});e.setOption({...e.getOption(),series:n})}ie.use([F.DataZoomComponent,he.BarChart,he.LineChart,he.ScatterChart,F.GridComponent,F.LegendComponent,F.TooltipComponent,Ee.CanvasRenderer,F.MarkLineComponent,F.MarkAreaComponent]);function io(e){return e.trim().length>0}function Ef({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=zt(t,e.x_axis_data_key),u=Ke(a.triggerManager,Hr.id),c=y.useCallback(m=>{const C=x.get(l,m.name,{error:"rowData is not found"});u.forEach(w=>{a.runInteraction(w.id,{...m,rowData:C})})},[l,u,a]),d=y.useMemo(()=>zf(e,t,o),[e,t]),f=y.useRef(),h=y.useMemo(()=>({click:c}),[c]),g=m=>{f.current=m,ro(m)};return y.useEffect(()=>{f.current&&ro(f.current)},[d]),!n||!r?null:i(ze,{echarts:ie,option:d,style:{width:n,height:r},onEvents:h,onChartReady:g,notMerge:!0,theme:"merico-light"})}function $f({context:e,instance:t}){const n=Xe({vizManager:e.vizManager,instance:t}),{value:r}=R(e.instanceData,"config"),{variables:a}=e,o=y.useMemo(()=>x.defaults({},r,ei),[r]),l=e.data,{width:u,height:c}=e.viewport,{ref:d,height:f}=ke.useElementSize(),{ref:h,height:g}=ke.useElementSize(),m=y.useMemo(()=>{const{stats:{templates:_}}=o;return{top:gn(_.top,a,l),bottom:gn(_.bottom,a,l)}},[o,l]),C=Math.max(0,nt(c)-f-g),w=tt(u);return p(Ve,{width:u,height:c,children:[i(s.Text,{ref:d,align:"left",size:"xs",pl:"sm",sx:{display:io(o.stats.templates.top)?"block":"none"},children:Object.values(m.top).map((_,T)=>i(y.Fragment,{children:_},T))}),i(Ef,{variables:a,width:w,height:C,data:l,conf:o,interactionManager:n}),i(s.Text,{ref:h,align:"left",size:"xs",pl:"sm",sx:{display:io(o.stats.templates.bottom)?"block":"none"},children:Object.values(m.bottom).map((_,T)=>i(y.Fragment,{children:_},T))})]})}const ri=y.forwardRef(({value:e,onChange:t},n)=>{const r=a=>o=>{t({...e,[a]:o})};return p(s.Stack,{children:[i(s.Divider,{variant:"dashed",label:"Scroll to Zoom",labelPosition:"center"}),p(s.Group,{children:[i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Enable on X Axis",checked:e.x_axis_scroll,onChange:a=>r("x_axis_scroll")(a.currentTarget.checked)})}),i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Enable on Y Axis",checked:e.y_axis_scroll,onChange:a=>r("y_axis_scroll")(a.currentTarget.checked)})})]}),i(s.Divider,{variant:"dashed",label:"Slider for Zooming",labelPosition:"center"}),p(s.Group,{children:[i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Slider for X Axis",checked:e.x_axis_slider,onChange:a=>r("x_axis_slider")(a.currentTarget.checked)})}),i(s.Tooltip,{label:"Not available for now, will overlap y-axis's label",children:i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Slider for Y Axis",disabled:!e.y_axis_slider,checked:e.y_axis_slider,onChange:a=>r("y_axis_slider")(a.currentTarget.checked)})})})]})]})}),Lf=[{label:"Rectangle",value:"rectangle"}],Of=[{label:"Horizontal",value:"horizontal"}];function Pf({control:e,index:t,remove:n,variableOptions:r}){return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_areas.${t}.name`,control:e,render:({field:a})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_areas.${t}.color`,control:e,render:({field:a})=>i(s.TextInput,{label:"Color",required:!0,sx:{flex:1},...a})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_areas.${t}.type`,control:e,render:({field:a})=>i(s.Select,{label:"Type",required:!0,data:Lf,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_areas.${t}.direction`,control:e,render:({field:a})=>i(s.Select,{label:"Direction",required:!0,data:Of,sx:{flex:1},...a})})]}),i(s.Divider,{variant:"dashed",label:"Data",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_areas.${t}.y_keys.upper`,control:e,render:({field:a})=>i(s.Select,{label:"Upper Boundary",required:!0,data:r,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_areas.${t}.y_keys.lower`,control:e,render:({field:a})=>i(s.Select,{label:"Lower Boundary",required:!0,data:r,sx:{flex:1},...a})})]}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Area"})]},t)}function Bf({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_areas"}),l=t("reference_areas"),u=r.map((f,h)=>({...f,...l[h]})),c=()=>a({name:"",color:"rgba(0,0,0,0.1)",type:"rectangle",direction:"horizontal",y_keys:{upper:"",lower:""}}),d=y.useMemo(()=>n.map(f=>({label:f.name,value:f.name})),[n]);return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"6px 0px 0px"}},children:[p(s.Tabs.List,{children:[u.map((f,h)=>i(s.Tabs.Tab,{value:h.toString(),children:h+1},h)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),u.map((f,h)=>i(s.Tabs.Panel,{value:h.toString(),children:i(Pf,{control:e,index:h,remove:o,variableOptions:d})},h))]})}const Vf=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Nf=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function qf({control:e,index:t,remove:n,watch:r,variableOptions:a,yAxisOptions:o}){const l=r(`reference_lines.${t}.orientation`);return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:u})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:u})=>i(s.Select,{label:"Value",required:!0,data:a,sx:{flex:1},...u})})]}),i(v.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:u})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...u})}),p(s.Group,{grow:!0,children:[p(s.Stack,{children:[i(v.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:u})=>i(s.Select,{label:"Orientation",data:Nf,required:!0,sx:{flex:1},...u})}),l==="vertical"&&i(s.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&i(v.Controller,{name:`reference_lines.${t}.yAxisIndex`,control:e,render:({field:{value:u,onChange:c,...d}})=>i(s.Select,{label:"Y Axis",data:o,disabled:o.length===0,...d,value:(u==null?void 0:u.toString())??"",onChange:f=>{if(!f){c(0);return}c(Number(f))},sx:{flex:1}})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:u})=>i(s.Select,{label:"Line Type",data:Vf,sx:{flexGrow:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:u})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...u})})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:u})=>i($e,{...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`reference_lines.${t}.show_in_legend`,control:e,render:({field:u})=>i(s.Checkbox,{label:"Show in legend",checked:u.value,onChange:c=>u.onChange(c.currentTarget.checked)})}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]},t)}function Ff({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=r.map((g,m)=>({...g,...l[m]})),c=()=>{a({name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,yAxisIndex:0})},d=y.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=t("y_axes"),h=y.useMemo(()=>f.map(({name:g},m)=>({label:g,value:m.toString()})),[f]);return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[u.map((g,m)=>i(s.Tabs.Tab,{value:m.toString(),children:m+1},m)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),u.map((g,m)=>i(s.Tabs.Panel,{value:m.toString(),children:i(qf,{control:e,index:m,remove:o,watch:t,variableOptions:d,yAxisOptions:h})},m))]})}const Gf=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}],Wf=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function jf({control:e,regressionItem:t,index:n,remove:r,yAxisOptions:a}){const o=t.transform.config.method;return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,children:[i(v.Controller,{name:`regressions.${n}.name`,control:e,render:({field:l})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`regressions.${n}.group_by_key`,control:e,render:({field:l})=>i(W,{label:"Split into multiple regression lines by this key...",clearable:!0,sx:{flex:1},...l})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`regressions.${n}.y_axis_data_key`,control:e,render:({field:l})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`regressions.${n}.plot.yAxisIndex`,control:e,render:({field:{value:l,onChange:u,...c}})=>i(s.Select,{label:"Y Axis",data:a,disabled:a.length===0,...c,value:(l==null?void 0:l.toString())??"",onChange:d=>{if(!d){u(0);return}u(Number(d))},sx:{flex:1}})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`regressions.${n}.transform.config.method`,control:e,render:({field:l})=>i(s.Select,{label:"Method",data:Gf,sx:{flex:1},...l})}),o==="polynomial"&&i(v.Controller,{name:`regressions.${n}.transform.config.order`,control:e,render:({field:l})=>i(s.NumberInput,{label:"Order",sx:{flex:1},...l})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Line Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`regressions.${n}.plot.lineStyle.type`,control:e,render:({field:l})=>i(s.Select,{label:"Line Type",data:Wf,sx:{flexGrow:1},...l})}),i(v.Controller,{name:`regressions.${n}.plot.lineStyle.width`,control:e,render:({field:l})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...l})})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`regressions.${n}.plot.color`,control:e,render:({field:l})=>i($e,{...l})})]}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(n),sx:{top:15,right:5},children:"Delete this Regression Line"})]},n)}function Rf({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"regressions"}),o=t("regressions"),l=n.map((f,h)=>({...f,...o[h]})),u=t("y_axes"),c=y.useMemo(()=>u.map(({name:f},h)=>({label:f,value:h.toString()})),[u]),d=()=>r({transform:{type:"ecStat:regression",config:{method:"linear",order:1,formulaOn:"end"}},group_by_key:"",name:"",y_axis_data_key:"",plot:{type:"line",yAxisIndex:0,color:"#666666",lineStyle:{type:"solid",width:1}}});return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((f,h)=>i(s.Tabs.Tab,{value:h.toString(),children:h+1},h)),i(s.Tabs.Tab,{onClick:d,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((f,h)=>i(s.Tabs.Panel,{value:h.toString(),children:i(jf,{regressionItem:f,control:e,index:h,remove:a,yAxisOptions:c},h)},h))]})}const ii={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
|
|
122
|
+
`)}},Yf=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function Qf({control:e,index:t,seriesItem:n}){const r=!!n.barWidth.trim();return p(B,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.stack`,control:e,render:({field:a})=>i(s.TextInput,{label:"Stack",placeholder:"Stack bars by this ID",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barGap`,control:e,render:({field:a})=>i(s.Select,{label:"Bar Gap",data:Yf,sx:{flexGrow:1},...a})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.barMinWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Min)",disabled:r,sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barMaxWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Max)",disabled:r,sx:{flexGrow:1},...a})})]})]})}const Uf=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return i(s.Box,{children:i(De,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Kf=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:a}]=Q.useBoolean(),[o,l]=y.useState(e),u=()=>{a();const{type:h,func_content:g}=o,m={type:h,func_content:g};l(m),t(m)},c=()=>{a(),l(e)},d=h=>{l(g=>({...g,func_content:h}))},f=()=>{d(ii.dynamic.func_content)};return p(B,{children:[i(s.Box,{sx:{width:"50%"},children:i(s.Button,{variant:"filled",mt:24,onClick:r,sx:{flexGrow:0},children:"Setup"})}),i(s.Modal,{size:800,title:"Setup dynamic size",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&p(s.Stack,{children:[i(s.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),i(Uf,{value:o.func_content,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:c,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:u,children:"OK"})]})]})]})})]})},Xf=({value:e,onChange:t})=>e.type!=="dynamic"?null:i(Kf,{value:e,onChange:t}),Jf=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=r=>{t({...e,size:r})};return i(B,{children:i(s.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:e.size,onChange:n})})},Zf=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],ao=y.forwardRef(({label:e="Size",value:t,onChange:n},r)=>{const a=o=>{n({...ii[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:e,data:Zf,value:t.type,onChange:a,sx:{flexGrow:1}}),i(Jf,{value:t,onChange:n}),i(Xf,{value:t,onChange:n})]})}),Hf=[{label:"off",value:"false"},{label:"start",value:"start"},{label:"middle",value:"middle"},{label:"end",value:"end"}],eg=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function tg({control:e,index:t,seriesItem:n}){const r=n.showSymbol;return p(B,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Line Settings",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`series.${t}.lineStyle.type`,control:e,render:({field:a})=>i(s.Select,{label:"Line Type",data:eg,sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.lineStyle.width`,control:e,render:({field:a})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...a})})]}),p(s.Group,{grow:!0,align:"center",children:[i(v.Controller,{name:`series.${t}.step`,control:e,render:({field:a})=>i(s.Select,{label:"Step",data:Hf,sx:{flexGrow:1,maxWidth:"48%"},...a,value:String(a.value),onChange:o=>{const l=o==="false"?!1:o;a.onChange(l)}})}),p(s.Stack,{children:[i(v.Controller,{name:`series.${t}.smooth`,control:e,render:({field:a})=>i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Smooth Line",checked:a.value,onChange:o=>a.onChange(o.currentTarget.checked)})})}),i(v.Controller,{name:`series.${t}.display_name_on_line`,control:e,render:({field:a})=>i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Display Name on Line",checked:a.value??!1,onChange:o=>a.onChange(o.currentTarget.checked)})})})]})]}),p(s.Stack,{children:[i(v.Controller,{name:`series.${t}.showSymbol`,control:e,render:({field:a})=>i(s.Box,{mt:10,mb:-10,sx:{flexGrow:1},children:i(s.Switch,{label:"Show Symbol on Line",checked:a.value,onChange:o=>a.onChange(o.currentTarget.checked)})})}),r&&i(v.Controller,{name:`series.${t}.symbolSize`,control:e,render:({field:a})=>i(ao,{label:"Symbol Size",...a})})]})]})}function ng({control:e,index:t}){return i(v.Controller,{name:`series.${t}.symbolSize`,control:e,render:({field:n})=>i(ao,{label:"Size",...n})})}const rg=[{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 ig({control:e,index:t,remove:n,seriesItem:r,yAxisOptions:a}){const o=r.type;return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[i(s.Stack,{children:i(v.Controller,{name:`series.${t}.type`,control:e,render:({field:l})=>i(s.SegmentedControl,{data:[{label:"Line",value:"line"},{label:"Bar",value:"bar"},{label:"Scatter",value:"scatter"}],...l})})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.name`,control:e,render:({field:l})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`series.${t}.yAxisIndex`,control:e,render:({field:{value:l,onChange:u,...c}})=>i(s.Select,{label:"Y Axis",data:a,disabled:a.length===0,...c,value:(l==null?void 0:l.toString())??"",onChange:d=>{if(!d){u(0);return}u(Number(d))},sx:{flex:1}})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.y_axis_data_key`,control:e,render:({field:l})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`series.${t}.aggregation_on_value`,control:e,render:({field:l})=>i(Qn,{label:"Aggregation on Value",value:l.value??Wt,onChange:l.onChange,pt:0})})]}),i(s.Group,{grow:!0,children:i(v.Controller,{name:`series.${t}.group_by_key`,control:e,render:({field:l})=>i(W,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...l})})}),o==="line"&&i(tg,{index:t,control:e,seriesItem:r}),o==="bar"&&i(Qf,{index:t,control:e,seriesItem:r}),o==="scatter"&&i(ng,{index:t,control:e}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),i(v.Controller,{name:`series.${t}.label_position`,control:e,render:({field:l})=>i(s.Select,{label:"Label Position",data:rg,...l})}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`series.${t}.color`,control:e,render:({field:l})=>i($e,{...l})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`series.${t}.hide_in_legend`,control:e,render:({field:l})=>i(s.Checkbox,{label:"Hide in legend",checked:l.value,onChange:u=>l.onChange(u.currentTarget.checked)})}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Series"})]},t)}function ag({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"series"}),o=t("series"),l=n.map((f,h)=>({...f,...o[h]})),u=()=>{const f={type:"bar",name:ke.randomId(),showSymbol:!1,symbolSize:ii.static,y_axis_data_key:"value",yAxisIndex:0,label_position:"top",display_name_on_line:!1,stack:"",color:"#000",step:!1,smooth:!1,barMinWidth:"1",barWidth:"10%",barMaxWidth:"10",barGap:"0%",lineStyle:{type:"solid",width:1},hide_in_legend:!1,group_by_key:""};r(f)},c=t("y_axes"),d=y.useMemo(()=>c.map(({name:f},h)=>({label:f,value:h.toString()})),[c]);return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((f,h)=>i(s.Tabs.Tab,{value:h.toString(),children:h+1},f.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((f,h)=>i(s.Tabs.Panel,{value:h.toString(),children:i(ig,{control:e,index:h,remove:a,seriesItem:f,yAxisOptions:d},f.id)},f.id))]})}function sg({control:e,watch:t}){return t("stats"),i(s.Stack,{children:p(s.Stack,{spacing:0,children:[i(v.Controller,{name:"stats.templates.top",control:e,render:({field:n})=>i(on,{label:"Template for stats above the chart",py:"md",sx:{flexGrow:1},...n})}),i(v.Controller,{name:"stats.templates.bottom",control:e,render:({field:n})=>i(on,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const og=()=>p(s.Group,{sx:{display:"inline-flex"},spacing:6,mr:14,children:[i(s.Text,{children:"X Axis Data Type"}),p(s.HoverCard,{width:340,shadow:"md",position:"top",children:[i(s.HoverCard.Target,{children:i(s.ActionIcon,{size:"xs",sx:{transform:"none !important"},children:i(E.IconInfoCircle,{})})}),i(s.HoverCard.Dropdown,{children:p(s.Text,{size:"sm",children:["Click",i(s.Anchor,{href:"https://echarts.apache.org/en/option.html#xAxis.type",target:"_blank",mx:4,children:"here"}),"to learn more about these options"]})})]})]}),lg=[{label:"Value",value:"value"},{label:"Category",value:"category"},{label:"Time",value:"time"},{label:"Log",value:"log"}];function ug({control:e,watch:t}){return t(["x_axis_data_key","x_axis_name","x_axis"]),p(s.Stack,{children:[i(v.Controller,{name:"x_axis_name",control:e,render:({field:n})=>i(s.TextInput,{label:"X Axis Name",sx:{flex:1},...n})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis_data_key",control:e,render:({field:n})=>i(W,{label:"X Axis Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.type",control:e,render:({field:n})=>i(s.Select,{label:i(og,{}),required:!0,data:lg,sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>i(Xn,{...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>i(st,{...n})})]})}const cg=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],dg=[{label:"left",value:"left"},{label:"right",value:"right"}];function pg({control:e,index:t,remove:n}){return p(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[i(s.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`y_axes.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`y_axes.${t}.nameAlignment`,control:e,render:({field:r})=>i(s.Select,{label:"Name Anchor",required:!0,data:cg,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`y_axes.${t}.position`,control:e,render:({field:r})=>i(s.Select,{label:"Position",required:!0,data:dg,sx:{flex:1},...r})})}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:`y_axes.${t}.label_formatter`,control:e,render:({field:r})=>i(We,{...r})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`y_axes.${t}.min`,control:e,render:({field:r})=>i(s.TextInput,{label:"Min",...r})}),i(v.Controller,{name:`y_axes.${t}.max`,control:e,render:({field:r})=>i(s.TextInput,{label:"Max",...r})})]})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`y_axes.${t}.show`,control:e,render:({field:r})=>i(s.Checkbox,{label:"Visible",checked:r.value,onChange:a=>r.onChange(a.currentTarget.checked)})}),i(s.Button,{mt:20,leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this YAxis"})]})}function hg({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"y_axes"}),o=t("y_axes"),l=n.map((c,d)=>({...c,...o[d]})),u=()=>r({name:"",position:"left",nameAlignment:"left",label_formatter:Ie,min:"",max:"",show:!0});return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[l.map((c,d)=>i(s.Tabs.Tab,{value:d.toString(),children:d+1},d)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((c,d)=>i(s.Tabs.Panel,{value:d.toString(),children:i(pg,{control:e,index:d,remove:a})},d))]})}function fg({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),{variables:r}=e,a=y.useMemo(()=>x.defaultsDeep({},t,ei),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,a),[f,a]);return u(["dataZoom"]),i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"Series",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axes",children:"Y Axes"}),i(s.Tabs.Tab,{value:"Series",children:"Series"}),i(s.Tabs.Tab,{value:"Regression Lines",children:"Regression Lines"}),i(s.Tabs.Tab,{value:"Stats",children:"Stats"}),i(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"}),i(s.Tabs.Tab,{value:"Reference Areas",children:"Reference Areas"}),i(s.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(ug,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axes",children:i(hg,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Series",children:i(ag,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Regression Lines",children:i(Rf,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Stats",children:i(sg,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(Ff,{variables:r,control:o,watch:u})}),i(s.Tabs.Panel,{value:"Reference Areas",children:i(Bf,{variables:r,control:o,watch:u})}),i(s.Tabs.Panel,{value:"Zooming",children:i(v.Controller,{name:"dataZoom",control:o,render:({field:g})=>i(ri,{...g})})})]})]})})}function gg(e){const t=x.cloneDeep(x.omit(e,"variables"));return t.stats=x.omit(t.stats,"variables"),t}function mg(e){const{rotate:t,formatter:n=Ue}=e.x_axis.axisLabel;return{...e,x_axis:{...e.x_axis,axisLabel:{rotate:t,formatter:n}}}}function yg(e){const{dataZoom:t=jt,...n}=e;return{...n,dataZoom:t}}function bg(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return x.defaultsDeep(t,e)}function vg(e){const t=e.reference_lines.map(n=>{const{lineStyle:r={type:"dashed",width:1,color:pt.random().css()},show_in_legend:a=!1}=n;return{...n,lineStyle:r,show_in_legend:a}});return{...e,reference_lines:t}}function xg(e){const t=e.reference_lines.map(n=>{const{yAxisIndex:r=0}=n;return{...n,yAxisIndex:r}});return{...e,reference_lines:t}}function wg(e){const t=e.series.map(n=>{const{aggregation_on_group:r=Wt}=n;return{...n,aggregation_on_group:r}});return{...e,series:t}}function Cg(e){const t=e.series.map(n=>{const{aggregation_on_value:r=Wt}=n;return{...n,aggregation_on_value:r}});return{...e,series:t}}function Sg(e){delete e.config;const{x_axis:t,tooltip:n}=e.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:t,in_tooltip:n}}}};return x.defaultsDeep(r,e)}function _g(e){const{series:t,...n}=e;return{...n,series:t.map(r=>{const{barMinWidth:a,barWidth:o,barMaxWidth:l}=r;return a?{...r,barMinWidth:a,barWidth:"",barMaxWidth:l??o}:{...r,barMinWidth:"",barWidth:o,barMaxWidth:""}})}}function kg(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(r=>{const{min:a="",max:o=""}=r;return{...r,min:a,max:o}})}}function Tg(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(r=>{const{nameAlignment:a="left"}=r;return{...r,nameAlignment:a}})}}function Dg(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(r=>{const{show:a=!0}=r;return{...r,show:a}})}}function Ig(e){const{regressions:t,...n}=e;return{...n,regressions:t.map(r=>{const{group_by_key:a=""}=r;return{...r,group_by_key:a}})}}function Mg(e){const{series:t,y_axes:n,...r}=e;return{...r,series:t.map(a=>{const{hide_in_legend:o=!1,aggregation_on_value:l=Wt}=a;return{...a,hide_in_legend:o,aggregation_on_value:l}}),y_axes:n.map(a=>{const{min:o="",max:l="",show:u=!0}=a;return{...a,min:o,max:l,show:u}})}}function Ag(e){const{type:t="category",...n}=e.x_axis;return{...e,x_axis:{...n,type:t}}}function zg(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis_data_key:a,series:o,regressions:l,...u}=e;return{...u,x_axis_data_key:r(a),series:o.map(c=>({...c,y_axis_data_key:r(c.y_axis_data_key),group_by_key:r(c.group_by_key)})),regressions:l.map(c=>({...c,y_axis_data_key:r(c.y_axis_data_key),group_by_key:r(c.group_by_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class Eg extends ge{constructor(){super(...arguments);q(this,"VERSION",18)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,{panelModel:r})=>{const{config:a}=n;return(a.variables||[]).forEach(u=>{r.variables.find(c=>c.name===u.name)||r.addVariable(u)}),(x.get(a,"stats.variables")||[]).forEach(u=>{r.variables.find(c=>c.name===u.name)||r.addVariable(u)}),{...n,version:2,config:gg(a)}}),this.version(3,n=>({...n,version:3,config:mg(n.config)})),this.version(4,n=>({...n,version:4,config:yg(n.config)})),this.version(5,n=>({...n,version:5,config:bg(n.config)})),this.version(6,n=>({...n,version:6,config:vg(n.config)})),this.version(7,n=>({...n,version:7,config:xg(n.config)})),this.version(8,n=>({...n,version:8,config:wg(n.config)})),this.version(9,n=>({...n,version:9,config:Cg(n.config)})),this.version(10,n=>({...n,version:10,config:Sg(n.config)})),this.version(11,n=>({...n,version:11,config:_g(n.config)})),this.version(12,n=>({...n,version:12,config:kg(n.config)})),this.version(13,n=>({...n,version:13,config:Tg(n.config)})),this.version(14,n=>({...n,version:14,config:Dg(n.config)})),this.version(15,n=>({...n,version:15,config:Ig(n.config)})),this.version(16,n=>({...n,version:16,config:Mg(n.config)})),this.version(17,n=>({...n,version:17,config:Ag(n.config)})),this.version(18,(n,r)=>({...n,version:18,config:zg(n.config,r)}))}}const $g={displayName:"Cartesian Chart",displayGroup:"ECharts-based charts",migrator:new Eg,name:"cartesian",viewRender:$f,configRender:fg,createConfig(){return{version:18,config:x.cloneDeep(ei)}},triggers:[Hr]};function Lg(e){if(e.enable_value)return e.value}function Og(e){if(e.enable_value)return e.value}function Pg(e){const t=e.axisLabel.overflow.on_axis.width,n=e.axisLabel.position,r={top:5,left:5,right:5,bottom:5};return e.orient==="vertical"&&x.get(r,n)&&n===e.funnelAlign&&x.set(r,n,t),r}function Bg(e,t){return e.series.map(n=>{const{level_name_data_key:r,level_value_data_key:a,axisLabel:o,min:l,max:u,funnelAlign:c,orient:d,...f}=n;if(!r||!a)return{};const h=O(r),g=O(a),m=t[h.queryID].map(w=>({name:w[h.columnKey],value:w[g.columnKey]})),C=it(o.overflow.on_axis);return{type:"funnel",...Pg(n),min:Lg(l),max:Og(u),minSize:l.size,maxSize:u.size,...f,label:{show:!0,position:o.position,...C},orient:d,funnelAlign:d==="horizontal"?"center":c,data:m}})}function Vg({conf:e,params:t,max:n}){const{name:r,value:a}=t.data,o=Z(a/n).format({output:"percent",mantissa:2,trimMantissa:!0});return[{label:`${t.marker} ${r}`,value:`${a} (${o})`,style:{label:"",value:""}}]}function Ng(e,t){var o;const n=O(e.series[0].level_name_data_key),r=O(e.series[0].level_value_data_key),a=(o=x.maxBy(t[n.queryID],r.columnKey))==null?void 0:o[r.columnKey];return l=>{const c=Vg({conf:e,params:l,max:a}).map(f=>`
|
|
123
123
|
<tr>
|
|
124
124
|
<th style="text-align: right;">
|
|
125
125
|
<div style="${f.style.label}">${f.label}</div>
|
|
@@ -135,7 +135,7 @@ Check the top-level render call using <`+V+">.")}return z}}function Tu(S,z){{if(
|
|
|
135
135
|
<table style="width: auto">
|
|
136
136
|
<tbody>${c.join("")}</tbody>
|
|
137
137
|
</table>
|
|
138
|
-
`}}function
|
|
138
|
+
`}}function qg(e,t){return{trigger:"item",confine:!0,formatter:Ng(e,t)}}function Fg(e,t){return{grid:{top:0,left:0,right:0,bottom:0},tooltip:qg(e,t),series:Bg(e,t)}}function Gg(e){return e||(e=Date.now().toString()),{id:e,name:e,level_name_data_key:"",level_value_data_key:"",min:{value:0,enable_value:!1,size:"0%"},max:{value:0,enable_value:!1,size:"100%"},gap:2,axisLabel:{show:!0,position:"inside",overflow:je},sort:"descending",orient:"vertical",funnelAlign:"center"}}const ai={series:[Gg("Funnel")]};ie.use([he.FunnelChart,F.DataZoomComponent,F.GridComponent,F.LegendComponent,F.TooltipComponent,Ee.CanvasRenderer]);function Wg({conf:e,data:t,width:n,height:r}){const a=y.useMemo(()=>Fg(e,t),[e,t]);return i(ze,{echarts:ie,option:a,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})}function jg({context:e}){const{value:t}=R(e.instanceData,"config"),n=y.useMemo(()=>x.defaults({},t,ai),[t]),r=e.data,{width:a,height:o}=e.viewport;return!a||!o?null:i(Ve,{width:a,height:o,children:i(Wg,{width:tt(a),height:nt(o),data:r,conf:n})})}const Rg=[{label:"Top",value:"top"},{label:"Left",value:"left"},{label:"Right",value:"right"},{label:"Bottom",value:"bottom"},{label:"Outside",value:"outside"},{label:"Inside",value:"inside"},{label:"InsideLeft",value:"insideLeft"},{label:"InsideRight",value:"insideRight"},{label:"InsideTop",value:"insideTop"},{label:"InsideBottom",value:"insideBottom"},{label:"InsideTopLeft",value:"insideTopLeft"},{label:"InsideBottomLeft",value:"insideBottomLeft"},{label:"InsideTopRight",value:"insideTopRight"},{label:"InsideBottomRight",value:"insideBottomRight"}],si=y.forwardRef(({label:e,value:t,onChange:n,options:r=Rg},a)=>i(s.Select,{ref:a,label:e,data:r,value:t,onChange:n})),Yg=[{label:"Ascending",value:"ascending"},{label:"Descending",value:"descending"},{label:"Use original data order",value:"0"}],Qg=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Ug=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}],Kg={horizontal:[{label:"Top",value:"top"},{label:"Inside Center",value:"inside"},{label:"Bottom",value:"bottom"}],vertical:[{label:"Left",value:"left"},{label:"Inside Left",value:"insideLeft"},{label:"Inside Center",value:"inside"},{label:"Inside Right",value:"insideRight"},{label:"Right",value:"right"}]},Xg=({item:e,control:t,index:n,remove:r})=>{const a=e.min.enable_value,o=e.max.enable_value,{orient:l}=e;return p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`series.${n}.name`,control:t,render:({field:u})=>i(s.TextInput,{label:"Series Name",...u})})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.level_name_data_key`,control:t,render:({field:u})=>i(W,{label:"Level Name Field",...u})}),i(v.Controller,{name:`series.${n}.level_value_data_key`,control:t,render:({field:u})=>i(W,{label:"Level Value Field",...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Funnel Style",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.min.value`,control:t,render:({field:u})=>i(s.NumberInput,{disabled:!a,labelProps:{display:"block"},label:p(s.Group,{position:"apart",pr:6,sx:{width:"100%"},children:[i(s.Text,{children:"Min Value"}),i(s.Tooltip,{label:"Check to enable specific min value",children:i(s.Box,{children:i(v.Controller,{name:`series.${n}.min.enable_value`,control:t,render:({field:c})=>i(s.Checkbox,{size:"xs",checked:c.value,onChange:d=>c.onChange(d.currentTarget.checked)})})})})]}),...u})}),i(v.Controller,{name:`series.${n}.min.size`,control:t,render:({field:u})=>i(s.TextInput,{placeholder:"0%",label:"Min Size",...u})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.max.value`,control:t,render:({field:u})=>i(s.NumberInput,{disabled:!o,labelProps:{display:"block"},label:p(s.Group,{position:"apart",pr:6,sx:{width:"100%"},children:[i(s.Text,{children:"Max Value"}),i(s.Tooltip,{label:"Check to enable specific max value",children:i(s.Box,{children:i(v.Controller,{name:`series.${n}.max.enable_value`,control:t,render:({field:c})=>i(s.Checkbox,{size:"xs",checked:c.value,onChange:d=>c.onChange(d.currentTarget.checked)})})})})]}),...u})}),i(v.Controller,{name:`series.${n}.max.size`,control:t,render:({field:u})=>i(s.TextInput,{placeholder:"100%",label:"Max Size",...u})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.orient`,control:t,render:({field:u})=>i(s.Select,{label:"Orientation",data:Ug,...u})}),i(v.Controller,{name:`series.${n}.sort`,control:t,render:({field:u})=>i(s.Select,{label:"Sort",data:Yg,...u})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.funnelAlign`,control:t,render:({field:u})=>i(s.Select,{label:"Align",disabled:l==="horizontal",data:Qg,...u})}),i(v.Controller,{name:`series.${n}.gap`,control:t,render:({field:u})=>i(s.NumberInput,{placeholder:"0, 5, 10...",label:"Gap",...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Label Style",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.axisLabel.position`,control:t,render:({field:u})=>i(si,{label:"Position",options:Kg[l],...u})}),i(s.Box,{})]}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`series.${n}.axisLabel.overflow`,control:t,render:({field:u})=>i(st,{...u})})})]})},Jg=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"series"}),o=t("series"),l=n.map((f,h)=>({...f,...o[h]})),u=x.get(l,"0.id"),[c,d]=y.useState(u??null);return y.useEffect(()=>{u&&d(f=>f!==null?f:u)},[u]),p(s.Tabs,{value:c,onTabChange:f=>d(f),styles:{panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((f,h)=>i(s.Tabs.Tab,{value:f.id,children:f.name},f.id)),i(s.Tabs.Tab,{value:"add",disabled:!0,children:i(s.Tooltip,{label:"TODO",children:i(s.Center,{children:i(E.IconPlus,{size:18,color:"#228be6"})})})})]}),l.map((f,h)=>i(s.Tabs.Panel,{value:f.id,children:i(Xg,{item:f,control:e,index:h,remove:a})},f.id))]})};function Zg({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},t,ai),[t]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l([]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,r),[d,r]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Funnel Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(D.DeviceFloppy,{size:20})})]}),i(Jg,{control:a,watch:l})]})})}function Hg(e){return{series:e.series.map(t=>{const{min:n,minSize:r,max:a,maxSize:o,...l}=t;return{...l,min:{value:n,use_data_min:!1,size:r},max:{value:a,use_data_max:!1,size:o}}})}}function em(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=l=>l&&`${n}.${l}`,{series:a,...o}=e;return{...o,series:a.map(l=>({...l,level_name_data_key:r(l.level_name_data_key),level_value_data_key:r(l.level_value_data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class tm extends ge{constructor(){super(...arguments);q(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{config:r}=n;return{...n,version:2,config:Hg(r)}}),this.version(3,(n,r)=>{const{config:a}=n;return{...n,version:3,config:em(a,r)}})}}const nm={displayName:"Funnel Chart",displayGroup:"ECharts-based charts",migrator:new tm,name:"funnel",viewRender:jg,configRender:Zg,createConfig:()=>({version:3,config:ai})};function so({enabled:e,func_content:t}){return(n,r)=>{if(!e)return n;try{return new Function(`return ${t}`)()(n,r)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function rm(e){const t=so(e.x_axis.axisLabel.formatter),n=so(e.y_axis.axisLabel.formatter);return{x_axis:t,y_axis:n}}function im(e){return{heat_block:function(r){if(!e.heat_block.value_formatter)return r;try{return Z(r).format(e.heat_block.value_formatter)}catch(a){return console.error(a),r}}}}function am(e){let t=0;return e.x_axis.name&&(t+=20),{top:45,left:5,right:5,bottom:t,containLabel:!0}}function sm(e,t,n){const{heat_block:r}=e;return{type:"heatmap",name:r.name,xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{borderColor:"white",borderWidth:n},data:t,label:r.label,labelLayout:{hideOverlap:!0}}}const om=e=>{try{return Z(e).format({trimMantissa:!0,mantissa:2})}catch{return e}};function lm({conf:e,labelFormatters:t,valueFormatters:n,dataDict:r,params:a}){const{value:o,dataIndex:l}=a,[u,c,d]=o,f={label:e.x_axis.name?e.x_axis.name:"X Axis",value:t.x_axis(u,l),style:{label:"",value:ot(e.x_axis.axisLabel.overflow.in_tooltip)}},h={label:e.y_axis.name?e.y_axis.name:"Y Axis",value:t.y_axis(c,l),style:{label:"",value:ot(e.y_axis.axisLabel.overflow.in_tooltip)}},g={label:e.heat_block.name,value:n.heat_block(d),style:{label:"",value:""}},m=[f,h,g],C=r[`${u}---${c}`];return C&&e.tooltip.metrics.forEach(w=>{const _=O(w.data_key);m.push({label:w.name,value:om(x.get(C,_.columnKey,"")),style:{label:"",value:""}})}),m}function um(e,t,n,r){const{x_axis:a,y_axis:o,heat_block:l}=e,u=O(a.data_key),c=O(o.data_key);O(l.data_key);const d=x.keyBy(t[u.queryID],f=>`${f[u.columnKey]}---${f[c.columnKey]}`);return{confine:!0,formatter:function(f){const g=lm({conf:e,labelFormatters:n,valueFormatters:r,dataDict:d,params:f}).map(C=>`
|
|
139
139
|
<tr>
|
|
140
140
|
<th style="text-align: right;">
|
|
141
141
|
<div style="${C.style.label}">${C.label}</div>
|
|
@@ -156,9 +156,9 @@ Check the top-level render call using <`+V+">.")}return z}}function Tu(S,z){{if(
|
|
|
156
156
|
</thead>
|
|
157
157
|
<tbody>${g.join("")}</tbody>
|
|
158
158
|
</table>
|
|
159
|
-
`}}}const
|
|
160
|
-
`)}},
|
|
161
|
-
`)},
|
|
159
|
+
`}}}const cm=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return i(s.Box,{children:i(De,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},oo={static:{type:"static",value:10},dynamic:{type:"dynamic",value:["function getValue({ variables }, { lodash, interpolate }) {"," // your code goes here"," return 100;","}"].join(`
|
|
160
|
+
`)}},dm=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:a}]=Q.useBoolean(),[o,l]=y.useState(e),u=()=>{a();const{type:h,value:g}=o,m={type:h,value:g};l(m),t(m)},c=()=>{a(),l(e)},d=h=>{l(g=>({...g,value:h}))},f=()=>{d(oo.dynamic.value)};return p(B,{children:[i(s.Box,{sx:{width:"50%"},children:i(s.Button,{variant:"filled",mt:24,onClick:r,sx:{flexGrow:0},children:"Setup"})}),i(s.Modal,{size:800,title:"Setup dynamic value",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&p(s.Stack,{children:[i(s.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),i(cm,{value:o.value,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:c,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:u,children:"OK"})]})]})]})})]})},pm=({value:e,onChange:t})=>e.type!=="dynamic"?null:i(dm,{value:e,onChange:t}),hm=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=r=>{t({...e,value:r})};return i(s.NumberInput,{defaultValue:18,label:" ",hideControls:!0,value:e.value,onChange:n})},fm=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Rt=y.forwardRef(({label:e="Value",value:t,onChange:n},r)=>{const a=o=>{n({...oo[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:e,data:fm,value:t.type,onChange:a,sx:{flexGrow:1}}),i(hm,{value:t,onChange:n}),i(pm,{value:t,onChange:n})]})});function Yt(e,t,n){if(!e.type)return n;if(e.type==="static"){const{value:a}=e;return a}const{value:r}=e;try{return new Function(`return ${r}`)()({variables:t},{lodash:x,interpolate:It.interpolate})}catch(a){return console.error(`[getNumberOrDynamicValue] failed parsing custom function, error: ${a.message}`),10}}function gm(e,t){const n=Yt(e.heat_block.min,t),r=Yt(e.heat_block.max,t);return{min:n,max:r,calculable:!0,orient:"horizontal",left:"center",top:0,itemWidth:15}}function mm(e,t,n){const{overflow:r,rotate:a}=e.x_axis.axisLabel,o=it(r.on_axis);return{id:"main-x-axis",type:"category",data:t,name:e.x_axis.name??"",align:"center",axisTick:{show:!0,alignWithLabel:!0},axisLabel:{rotate:a,...o,formatter:n},splitArea:{show:!0},nameLocation:"center",nameGap:25,nameTextStyle:{fontWeight:"bold",align:"center"},z:2}}function ym(e,t,n){const{nameAlignment:r,data_key:a,...o}=e.y_axis,{overflow:l,rotate:u}=e.y_axis.axisLabel,c=it(l.on_axis);return{...o,type:"category",data:t,axisLabel:{rotate:u,...c,formatter:n},axisLine:{show:!0,color:"blue"},axisTick:{show:!0,alignWithLabel:!0},splitArea:{show:!0},nameTextStyle:{fontWeight:"bold",align:r},nameLocation:"end",nameGap:15,z:2}}const bm={tooltip:{confine:!0}};function vm(e,t,n,r){return n<e*10||r<t*10?0:n<e*20||r<t*20?1:2}function xm(e,t,n,r,a){if(!e.x_axis.data_key||!e.y_axis.data_key||!e.heat_block.data_key)return{};const o=n.reduce((_,T)=>{const M=mt(T,t);return _[T.name]=Ze(T,M),_},{}),l=rm(e),u=im(e),c=O(e.x_axis.data_key),d=O(e.y_axis.data_key),f=O(e.heat_block.data_key),h=x.uniq(t[c.queryID].map(_=>_[c.columnKey])),g=x.uniq(t[c.queryID].map(_=>_[d.columnKey])),m=t[c.queryID].map(_=>[x.get(_,c.columnKey),x.get(_,d.columnKey),x.get(_,f.columnKey)]),C=vm(h.length,g.length,r,a),w={xAxis:mm(e,h,l.x_axis),yAxis:ym(e,g,l.y_axis),series:sm(e,m,C),tooltip:um(e,t,l,u),grid:am(e),visualMap:gm(e,o)};return x.defaultsDeep({},w,bm)}function wm(e){return i(B,{})}function Cm(e){return i(s.Text,{children:"Click heat block"})}const lo={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:Cm,configRender:wm,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"}]},oi={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,overflow:je,formatter:{...Ue}}},y_axis:{name:"Y Axis",data_key:"",nameAlignment:"center",axisLabel:{rotate:0,overflow:je,formatter:{...Ue}}},heat_block:{min:{type:"static",value:0},max:{type:"static",value:100},name:"Value",data_key:"",value_formatter:Ie,label:{show:!1,fontSize:10}},tooltip:{metrics:[]}};ie.use([F.DataZoomComponent,he.HeatmapChart,F.GridComponent,F.LegendComponent,F.TooltipComponent,F.VisualMapComponent,Ee.CanvasRenderer]);function Sm({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=y.useMemo(()=>{const h=O(e.x_axis.data_key),g=O(e.y_axis.data_key);return x.keyBy(t[h.queryID],m=>`${m[h.columnKey]}---${m[g.columnKey]}`)},[t,e.x_axis.data_key,e.y_axis.data_key]),u=Ke(a.triggerManager,lo.id),c=y.useCallback(h=>{const[g,m]=h.value,C=x.get(l,`${g}---${m}`,{error:"rowData is not found"});u.forEach(w=>{a.runInteraction(w.id,{...h,rowData:C})})},[l,u,a]),d=y.useMemo(()=>({click:c}),[c]),f=y.useMemo(()=>xm(e,t,o,n,r),[e,t,n,r]);return i(ze,{echarts:ie,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function _m({context:e,instance:t}){const n=Xe({vizManager:e.vizManager,instance:t}),{value:r}=R(e.instanceData,"config"),{variables:a}=e,o=y.useMemo(()=>x.defaults({},r,oi),[r]),l=e.data,{width:u,height:c}=e.viewport;return!u||!c?null:i(Ve,{width:u,height:c,children:i(Sm,{variables:a,width:tt(u),height:nt(c),data:l,conf:o,interactionManager:n})})}function km({control:e,watch:t}){t(["heat_block"]);const n=t("heat_block.label.show");return p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.data_key",control:e,render:({field:r})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:"heat_block.name",control:e,render:({field:r})=>i(s.TextInput,{label:"Name",sx:{flex:1},...r})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.min",control:e,render:({field:r})=>i(Rt,{label:"Min Value",...r})}),i(v.Controller,{name:"heat_block.max",control:e,render:({field:r})=>i(Rt,{label:"Max Value",...r})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Value Format",labelPosition:"center"}),i(v.Controller,{name:"heat_block.value_formatter",control:e,render:({field:r})=>i(We,{...r})}),i(s.Divider,{mb:-5,variant:"dashed",label:"Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.label.show",control:e,render:({field:r})=>i(s.Switch,{label:"Show label",checked:r.value,onChange:a=>r.onChange(a.currentTarget.checked),sx:{flexGrow:1}})}),i(v.Controller,{name:"heat_block.label.fontSize",control:e,render:({field:r})=>i(s.NumberInput,{size:"xs",icon:i(E.IconTextSize,{size:16}),disabled:!n,...r})})]})]})}const Tm=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),Dm=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(B,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(D.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),i(s.Divider,{variant:"dashed",my:10}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(Tm,{control:e,index:g,remove:a},h.id)},h.id))]})]})};function Im({control:e,watch:t}){return i(Dm,{control:e,watch:t})}const Mm=({disabled:e,value:t,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[e&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(De,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},Am={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
161
|
+
`)},uo=y.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:a,setFalse:o}]=Q.useBoolean(),[l,u]=y.useState(e);y.useEffect(()=>{u(e)},[e]);const c=m=>{u({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:C}=l,w={enabled:m,func_content:C};u(w),t(w)},f=()=>{o(),u(e)},h=m=>{u(C=>({...C,func_content:m}))},g=()=>{h(Am.func_content)};return p(B,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Customize Label"}),i(s.Modal,{size:800,title:"Customize label content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:m=>c(m.currentTarget.checked)}),i(Mm,{value:l.func_content,onChange:h,disabled:!l.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:g,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:d,children:"OK"})]})]})]})})]})});function zm({control:e,watch:t}){return t(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Tick Label",labelPosition:"center"}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>i(st,{...n})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>i(uo,{...n})})]})]})}const Em=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function $m({control:e,watch:t}){return t(["y_axis"]),p(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.data_key",control:e,render:({field:n})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"y_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...n})})]}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"y_axis.nameAlignment",control:e,render:({field:n})=>i(s.Select,{label:"Name Alignment",required:!0,data:Em,sx:{flex:1},...n})})}),i(s.Divider,{mb:-15,variant:"dashed",label:"Tick Label",labelPosition:"center"}),i(v.Controller,{name:"y_axis.axisLabel.overflow",control:e,render:({field:n})=>i(st,{...n})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.axisLabel.rotate",control:e,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"y_axis.axisLabel.formatter",control:e,render:({field:n})=>i(uo,{...n})})]})]})}function Lm({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},t,oi),[t]),a=y.useMemo(()=>x.cloneDeep(r),[r]);y.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return i("form",{onSubmit:l(n),style:{flexGrow:1},children:p(s.Stack,{spacing:"xs",sx:{height:"100%"},children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{root:{flexGrow:1},tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),i(s.Tabs.Tab,{value:"Heat Block",children:"Heat Block"}),i(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(zm,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axis",children:i($m,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Heat Block",children:i(km,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(Im,{control:o,watch:u})})]})]})})}function Om(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=d=>d&&`${n}.${d}`,{x_axis:a,y_axis:o,heat_block:l,tooltip:u,...c}=e;return{...c,x_axis:{...a,data_key:r(a.data_key)},y_axis:{...o,data_key:r(o.data_key)},heat_block:{...l,data_key:r(l.data_key)},tooltip:{...u,metrics:u.metrics.map(d=>({...d,data_key:r(d.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}function Pm(e){return x.defaultsDeep({},e,{heat_block:{label:{show:!1,fontSize:10}}})}function Bm(e){const{heat_block:t}=e;let{min:n,max:r}=t;return typeof n!="number"&&(n=0),typeof r!="number"&&(r=100),{...e,heat_block:{...t,min:{type:"static",value:n},max:{type:"static",value:r}}}}class Vm extends ge{constructor(){super(...arguments);q(this,"VERSION",4)}configVersions(){this.version(1,n=>(console.log("🟥 unexpected calling"),{version:1,config:n})),this.version(2,(n,r)=>({...n,version:2,config:Om(n.config,r)})),this.version(3,n=>({...n,version:3,config:Pm(n.config)})),this.version(4,n=>({...n,version:4,config:Bm(n.config)}))}}const Nm={displayName:"Heatmap",displayGroup:"ECharts-based charts",migrator:new Vm,name:"heatmap",viewRender:_m,configRender:Lm,createConfig:()=>({version:4,config:oi}),triggers:[lo]},co={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:Fm,configRender:qm,payload:[{name:"type",description:"Always 'click'",valueType:"string"},{name:"seriesType",description:"'line' | 'bar'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function qm(e){return i(B,{})}function Fm(e){return i(s.Text,{children:"Click chart's series"})}const po={label_template:"${percentage.x} of ${x_axis.name} causes ${percentage.y} of ${bar.name}",color:"rgba(0,0,0,0.3)"},li={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...Ue},overflow:je}},data_key:"value",bar:{name:"Value",nameAlignment:"left",color:"#228be6",label_formatter:Ie},line:{name:"Value",nameAlignment:"right",color:"red"},dataZoom:jt,markLine:po};function Zn(e){return Z(e).format({output:"percent",mantissa:0})}function Gm(e){const t=e.value[1];try{return Zn(t)}catch(n){return console.error(n),t}}function Wm(e){function t(n){let r=n;if(typeof n=="object"&&(Array.isArray(n.value)&&n.value.length===2?r=n.value[1]:r=n.value),!e.bar.label_formatter)return r;try{return Z(r).format(e.bar.label_formatter)}catch(a){return console.error(a),r}}return{bar:t,line:Gm,lineValue:Zn}}function jm(e,t,n){const{label_template:r}=e.markLine;if(!r)return"";const a={...e,percentage:t,count:n},o=Object.keys(a),l=Object.values(a);return new Function(...o,`return \`${r}\`;`)(...l)}function Rm(e,t){if(t.length===0)return{};const n=t.findIndex(u=>u[1]>=.8);if(n===-1)return{};const r=t[n],a={x:Zn((n+1)/t.length),y:Zn(r[1])},o={left:n+1,right:t.length-n-1},l=r[0];return l?{name:"",silent:!0,symbol:"triangle",symbolRotate:180,symbolSize:[10,8],data:[{name:"",symbol:"none",xAxis:l,lineStyle:{color:e.markLine.color},label:{formatter:jm(e,a,o)}}]}:{}}function Ym(e,t,n){const{x_axis:r,data_key:a}=e;if(!r.data_key||!a)return[];const o=O(r.data_key),l=O(a);if(o.queryID!==l.queryID)throw new Error("Please use the same query for X & Y axis");const u=t[o.queryID].map(h=>[h[o.columnKey],Number(h[l.columnKey])]).sort((h,g)=>g[1]-h[1]),c=u.reduce((h,g)=>h+g[1],0),d=u.reduce((h,g,m)=>{const C=m===0?0:h[m-1][1];return h.push([g[0],C+g[1]]),h},[]).map(h=>[h[0],h[1]/c]),f=Rm(e,d);return[{name:e.bar.name,type:"bar",barMaxWidth:20,itemStyle:{color:e.bar.color},label:{show:!1,position:"top",formatter:n.bar},yAxisIndex:0,data:u},{name:e.line.name,type:"line",itemStyle:{color:e.line.color},symbolSize:2,lineStyle:{width:1},label:{show:!1,position:"top",formatter:n.line},yAxisIndex:1,data:d,markLine:f}]}const Qm=(e,t)=>n=>{const r=Array.isArray(n)?n:[n];if(r.length===0)return"";const a=r.map((u,c)=>{const d=u.seriesName,[f,h]=u.value;if(!d)return h;const g=c===0?t.bar:t.lineValue;return`
|
|
162
162
|
<tr>
|
|
163
163
|
<th style="text-align: right; padding: 0 1em;">${d}</th>
|
|
164
164
|
<td style="text-align: left; padding: 0 1em;">${g(h)}</td>
|
|
@@ -172,7 +172,7 @@ Check the top-level render call using <`+V+">.")}return z}}function Tu(S,z){{if(
|
|
|
172
172
|
${a.join("")}
|
|
173
173
|
</tbody>
|
|
174
174
|
</table>
|
|
175
|
-
`};function
|
|
175
|
+
`};function Um(e,t){return{trigger:"axis",formatter:Qm(e,t)}}function Km(e){const{name:t,axisLabel:n}=e.x_axis,r=it(n.overflow.on_axis);return[{type:"category",name:t,nameLocation:"middle",nameGap:30,nameTextStyle:{fontWeight:"bold",align:"right"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0},axisLabel:{...n,...r,formatter:qt(n.formatter)}}]}function Xm(e,t){return[{name:e.bar.name,nameGap:20,minInterval:1,nameTextStyle:{fontWeight:"bold",align:e.bar.nameAlignment},position:"left",axisLine:{show:!0},axisLabel:{show:!0,formatter:t.bar},splitLine:{show:!1}},{name:e.line.name,nameGap:20,nameTextStyle:{fontWeight:"bold",align:e.line.nameAlignment},position:"right",axisLine:{show:!0},axisLabel:{show:!0,formatter:t.lineValue},splitLine:{show:!1}}]}function Jm(e,t,n){const r=Wm(e);return{dataZoom:ti(e.dataZoom),tooltip:Um(e,r),xAxis:Km(e),yAxis:Xm(e,r),series:Ym(e,t,r),grid:{top:50,left:30,right:15,bottom:5,containLabel:!0}}}ie.use([he.BarChart,he.LineChart,F.DataZoomComponent,F.GridComponent,F.LegendComponent,F.TooltipComponent,Ee.CanvasRenderer]);function Zm({context:e,instance:t}){const{value:n}=R(e.instanceData,"config"),r=e.data,{width:a,height:o}=e.viewport,l=x.defaults({},n,li),u=Jm(l,r),c=Xe({vizManager:e.vizManager,instance:t}),d=Ke(c.triggerManager,co.id),f=zt(r,l.x_axis.data_key),h=y.useCallback(m=>{const C=x.get(f,m.name,{error:"rowData is not found"});d.forEach(w=>{c.runInteraction(w.id,{...m,rowData:C})})},[f,d,c]),g=y.useMemo(()=>({click:h}),[h]);return!l||!a||!o?null:i(Ve,{width:a,height:o,children:i(ze,{echarts:ie,option:u,style:an(a,o),onEvents:g,notMerge:!0,theme:"merico-light"})})}const Hm=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function ey({control:e,watch:t}){return t(["bar"]),p(s.Stack,{children:[p(s.Group,{grow:!0,children:[i(v.Controller,{name:"bar.name",control:e,render:({field:n})=>i(s.TextInput,{label:"Bar Name",sx:{flex:1},...n})}),i(v.Controller,{name:"bar.nameAlignment",control:e,render:({field:n})=>i(s.Select,{label:"Align",required:!0,data:Hm,sx:{flex:1},...n})})]}),p(s.Stack,{spacing:2,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:"bar.color",control:e,render:({field:n})=>i($e,{...n})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:"bar.label_formatter",control:e,render:({field:n})=>i(We,{...n})})]})]})}const ty=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function ny({control:e,watch:t}){return t(["line"]),p(s.Stack,{children:[p(s.Group,{grow:!0,children:[i(v.Controller,{name:"line.name",control:e,render:({field:n})=>i(s.TextInput,{label:"Line Name",sx:{flex:1},...n})}),i(v.Controller,{name:"line.nameAlignment",control:e,render:({field:n})=>i(s.Select,{label:"Align",required:!0,data:ty,sx:{flex:1},...n})})]}),p(s.Stack,{spacing:2,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:"line.color",control:e,render:({field:n})=>i($e,{...n})})]})]})}const ry=`
|
|
176
176
|
{
|
|
177
177
|
// 80-20 line stuff
|
|
178
178
|
percentage: {
|
|
@@ -195,8 +195,8 @@ Check the top-level render call using <`+V+">.")}return z}}function Tu(S,z){{if(
|
|
|
195
195
|
name: string;
|
|
196
196
|
};
|
|
197
197
|
}
|
|
198
|
-
`,
|
|
199
|
-
{percentage|{d}%}`,minMargin:5,edgeDistance:10,lineHeight:15,rich:{percentage:{color:"#999"}},margin:20},labelLine:{length:15,length2:0,maxSurfaceAngle:80,showAbove:!0},labelLayout:function(h){const g=h.labelRect.x<n/2,m=h.labelLinePoints;return x.set(m,[2,0],g?h.labelRect.x:h.labelRect.x+h.labelRect.width),{labelLinePoints:m}},data:d,top:10,bottom:10,left:10,right:10}}function
|
|
198
|
+
`,iy=()=>{const[e,t]=y.useState(!1);return p(B,{children:[i(s.Button,{variant:"subtle",compact:!0,onClick:()=>t(n=>!n),children:e?"Close":"Click to see params for Label Template"}),i(s.Collapse,{in:e,children:i(Mt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:ry})})]})};function ay({control:e,watch:t}){return t(["markLine"]),p(s.Stack,{children:[p(s.Stack,{spacing:2,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:"markLine.color",control:e,render:({field:n})=>i($e,{...n})})]}),p(s.Stack,{spacing:4,children:[i(v.Controller,{name:"markLine.label_template",control:e,render:({field:n})=>i(s.Textarea,{autosize:!0,minRows:2,maxRows:4,label:"Label Template",sx:{flex:1},...n})}),i(iy,{})]})]})}function sy({control:e,watch:t}){return t(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>i(Xn,{...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>i(st,{...n})})]})}function oy({control:e,watch:t}){return t(["data_key"]),i(s.Stack,{children:i(v.Controller,{name:"data_key",control:e,render:({field:n})=>i(W,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})})})}function ly({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=y.useMemo(()=>x.defaults({},t,li),[t]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l(["x_axis","data_key","bar","line","dataZoom"]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,t),[d,t]);return p("form",{onSubmit:o(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),i(s.Tabs.Tab,{value:"Bar",children:"Bar"}),i(s.Tabs.Tab,{value:"Line",children:"Line"}),i(s.Tabs.Tab,{value:"80-20 Line",children:"80-20 Line"}),i(s.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(sy,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(oy,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Bar",children:i(ey,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Line",children:i(ny,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"80-20 Line",children:i(ay,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Zooming",children:i(v.Controller,{name:"dataZoom",control:a,render:({field:h})=>i(ri,{...h})})})]})]})}function uy(e){const{dataZoom:t=jt,...n}=e;return{...n,dataZoom:t}}function cy(e){const{markLine:t=po,...n}=e;return{...n,markLine:t}}function dy(e){const t=x.defaultsDeep({},e.x_axis.axisLabel,{rotate:0,formatter:{...Ue}});return{...e,x_axis:{...e.x_axis,axisLabel:t}}}function py(e){const{label_formatter:t=Ie}=e.bar;return{...e,bar:{...e.bar,label_formatter:t}}}function hy(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return x.defaultsDeep(t,e)}function fy(e){const t={bar:{nameAlignment:"left"},line:{nameAlignment:"right"}};return x.defaultsDeep(t,e)}function gy(e){console.log(e);const{x_axis:t,tooltip:n}=e.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:t,in_tooltip:n}}}};return x.defaultsDeep(r,e)}function my(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis:a,data_key:o,...l}=e;return{...l,x_axis:{...a,data_key:r(a.data_key)},data_key:r(o)}}catch(n){throw console.error("[Migration failed]",n),n}}class yy extends ge{constructor(){super(...arguments);q(this,"VERSION",9)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:uy(n.config)})),this.version(3,n=>({...n,version:3,config:cy(n.config)})),this.version(4,n=>({...n,version:4,config:dy(n.config)})),this.version(5,n=>({...n,version:5,config:py(n.config)})),this.version(6,n=>({...n,version:6,config:hy(n.config)})),this.version(7,n=>({...n,version:7,config:fy(n.config)})),this.version(8,n=>({...n,version:8,config:gy(n.config)})),this.version(9,(n,r)=>({...n,version:9,config:my(n.config,r)}))}}const by={displayName:"Pareto Chart",displayGroup:"ECharts-based charts",migrator:new yy,name:"paretoChart",viewRender:Zm,configRender:ly,createConfig(){return{version:9,config:x.cloneDeep(li)}},triggers:[co]},ui={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 vy(){ie.registerTheme("merico-light",{color:Object.values(ui.graphics.multiple),visualMap:{color:Object.values(ui.graphics.depth).reverse()}})}function ho(){vy()}function*xy(e){const t=ui.graphics[e];if(!t)throw new Error("Invalid palette key provided");const n=Object.values(t);let r=0;for(;;)yield n[r%n.length],r++}function wy(e,t,n){const{label_field:r,value_field:a,color_field:o}=e;if(!r||!a)return{};const l=O(r),u=O(a),c=O(o),d=t[l.queryID].map(h=>({name:h[l.columnKey],value:Number(h[u.columnKey]),color:c.columnKey?h[c.columnKey]:void 0})),f=xy("multiple");return{type:"pie",name:"pie",radius:["50%","80%"],itemStyle:{color:({data:h})=>h.color?h.color:f.next().value},label:{position:"outer",alignTo:"edge",formatter:`{name|{b}}
|
|
199
|
+
{percentage|{d}%}`,minMargin:5,edgeDistance:10,lineHeight:15,rich:{percentage:{color:"#999"}},margin:20},labelLine:{length:15,length2:0,maxSurfaceAngle:80,showAbove:!0},labelLayout:function(h){const g=h.labelRect.x<n/2,m=h.labelLinePoints;return x.set(m,[2,0],g?h.labelRect.x:h.labelRect.x+h.labelRect.width),{labelLinePoints:m}},data:d,top:10,bottom:10,left:10,right:10}}function Cy(e,t,n){return{tooltip:{show:!0,confine:!0},series:wy(e,t,n)}}const fo={id:"builtin:echarts:click-pie-chart:series",displayName:"Click Pie Series",nameRender:_y,configRender:Sy,payload:[{name:"seriesType",description:"'line' | 'scatter' | 'bar'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"Value of the series clicked",valueType:"number"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function Sy(e){return i(B,{})}function _y(e){return i(s.Text,{children:"Click chart's series"})}const ci={label_field:"",value_field:"",color_field:""};ie.use([he.PieChart,Ee.CanvasRenderer]);function ky({conf:e,data:t,width:n,height:r,interactionManager:a}){const o=zt(t,e.label_field),l=Ke(a.triggerManager,fo.id),u=y.useCallback(f=>{const h=x.get(o,f.name,{error:"rowData is not found"});l.forEach(g=>{a.runInteraction(g.id,{...f,rowData:h})})},[o,l,a]),c=y.useMemo(()=>Cy(e,t,n),[e,t,n]),d=y.useMemo(()=>({click:u}),[u]);return!n||!r||!c.series.name?null:i(ze,{echarts:ie,option:c,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function Ty({context:e,instance:t}){const n=Xe({vizManager:e.vizManager,instance:t}),{value:r}=R(e.instanceData,"config"),a=y.useMemo(()=>x.defaults({},r,ci),[r]),o=e.data,{width:l,height:u}=e.viewport;return!l||!u?null:i(Ve,{width:l,height:u,children:i(ky,{conf:a,width:tt(l),height:nt(u),data:o,interactionManager:n})})}function Dy({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},t,ci),[t]),a=y.useMemo(()=>x.clone(r),[r]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return u(["label_field","value_field","color_field"]),i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Pie Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Stack,{mt:"md",spacing:"xs",p:"md",mb:"sm",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[i(v.Controller,{control:o,name:"label_field",render:({field:g})=>i(W,{label:"Label Key",required:!0,...g})}),i(v.Controller,{control:o,name:"value_field",render:({field:g})=>i(W,{label:"Value Key",required:!0,...g})}),i(v.Controller,{control:o,name:"color_field",render:({field:g})=>i(W,{label:"Color Key",clearable:!0,...g})})]})]})})}function Iy(e){const{color_field:t="",...n}=e;return{...n,color_field:t}}function My(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{label_field:a,value_field:o,color_field:l}=e;return{label_field:r(a),value_field:r(o),color_field:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class Ay extends ge{constructor(){super(...arguments);q(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:Iy(n.config)})),this.version(3,(n,r)=>({...n,version:3,config:My(n.config,r)}))}}const zy={displayName:"Pie Chart",displayGroup:"ECharts-based charts",migrator:new Ay,name:"pie",viewRender:Ty,configRender:Dy,createConfig(){return{version:3,config:x.cloneDeep(ci)}},triggers:[fo]};function Ey(e){return i(B,{})}function $y(e){return i(s.Text,{children:"Click heat block"})}const go={id:"builtin:echarts:click-radar-chart:series",displayName:"Click radar chart series",nameRender:$y,configRender:Ey,payload:[{name:"seriesType",description:"'radar'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]},Hn={series_name_key:"",additional_series:[],background:{enabled:!0},label:{enabled:!0},dimensions:[]};function mo(e){return e?t=>{try{return Z(t).format(e)}catch(n){return console.error(n),t}}:t=>t}function yo(e){return{show:e.label.enabled,formatter:({dimensionIndex:t,value:n})=>mo(e.dimensions[t].formatter)(n)}}function bo(e,t){return t.map(({data_key:n})=>{const r=O(n);return e[r.columnKey]})}function Ly(e,t,n){const r=O(t);return e[r.queryID].map(a=>({value:bo(a,n),name:a[r.columnKey]}))}function Oy(e,t){const{series_name_key:n,dimensions:r}=t;return[{type:"radar",name:"main-radar",data:Ly(e,n,r),symbolSize:4,lineStyle:{width:1},emphasis:{lineStyle:{width:4}},areaStyle:t.background.enabled?{opacity:.4}:void 0,label:yo(t)}]}function Py(e,t){const{additional_series:n,dimensions:r}=t;return n.map(o=>{const l=O(o.name_key),u=O(o.color_key);return{type:"radar",colorBy:"data",data:e[l.queryID].map(f=>{const h=f[l.columnKey],g=f[u.columnKey];return{name:h,value:bo(f,r),itemStyle:{color:g}}}),symbolSize:4,lineStyle:{width:1},emphasis:{lineStyle:{width:4}},areaStyle:t.background.enabled?{opacity:.4}:void 0,label:yo(t)}}).flat()}function By(e,t){const n=[...Oy(e,t),...Py(e,t)];return console.log(n),n}function Vy(e){return({name:t,marker:n,value:r})=>{if(r.length===0)return"";const a=r.map((o,l)=>{const u=e.dimensions[l],c=mo(u.formatter);return`
|
|
200
200
|
<tr>
|
|
201
201
|
<td style="padding-left: 18px;">${u.name}</td>
|
|
202
202
|
<td style="text-align: right; "><strong>${c(o)}</strong></td>
|
|
@@ -224,7 +224,7 @@ Check the top-level render call using <`+V+">.")}return z}}function Tu(S,z){{if(
|
|
|
224
224
|
${a.join("")}
|
|
225
225
|
</tbody>
|
|
226
226
|
</table>
|
|
227
|
-
`}}const By={legend:{show:!0,bottom:0,left:0},tooltip:{trigger:"item"}},Vy=["#66B4DB","#39BFA2","#E46464","#33A678","#EEBA00","#9D88CB","#939943","#E49792","#09A2B8","#AF5F6B","#6CA157","#09A2B8","#6398C7","#E692BA","#97B566","#8CACE2","#CA79AC","#6DBC80","#B08F4B","#826BAF"];function Ny(e,t){const{series_name_key:n,dimensions:r,additional_series:a}=e;if(!n||r.length===0)return{};const l={radar:{indicator:r.map(({name:u,max:c})=>({name:u,max:c})),splitArea:{show:!1}},tooltip:{confine:!0,backgroundColor:"rgba(255,255,255,0.6)",formatter:Py(e)},legend:{show:!0,bottom:0,left:"center",type:"scroll"},series:Oy(t,e),color:Vy};return x.merge({},By,l)}ie.use([he.RadarChart,F.GridComponent,F.LegendComponent,F.TooltipComponent,Ee.CanvasRenderer]);function qy({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=y.useMemo(()=>{const{queryID:h,columnKey:g}=O(e.series_name_key),m=x.keyBy(t[h],g),C=e.additional_series.reduce((w,_)=>{const T=O(_.name_key),M=x.keyBy(t[T.queryID],T.columnKey);return{...w,...M}},m);return{...m,...C}},[t,e.series_name_key,e.additional_series]),u=Ke(a.triggerManager,ho.id),c=y.useCallback(h=>{const g=x.get(l,h.name,{error:"rowData is not found"});u.forEach(m=>{a.runInteraction(m.id,{...h,rowData:g})})},[l,u,a]),d=y.useMemo(()=>({click:c}),[c]),f=y.useMemo(()=>Ny(x.defaultsDeep({},e,Hn),t),[e,t]);return!n||!r?null:i(ze,{echarts:ie,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function Fy({context:e,instance:t}){const n=Xe({vizManager:e.vizManager,instance:t}),{value:r}=R(e.instanceData,"config"),{variables:a}=e,o=y.useMemo(()=>x.defaults({},r,Hn),[r]),l=e.data,{width:u,height:c}=e.viewport;return!u||!c||!o||x.isEmpty(o==null?void 0:o.dimensions)?null:i(Ve,{width:u,height:c,children:i(qy,{variables:a,width:tt(u),height:nt(c),data:l,conf:o,interactionManager:n})})}function Gy({control:e,index:t,remove:n}){return p(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`additional_series.${t}.name_key`,control:e,render:({field:r})=>i(W,{label:"Series Name Key",required:!0,sx:{flex:1},...r})})}),i(s.Stack,{children:i(v.Controller,{name:`additional_series.${t}.color_key`,control:e,render:({field:r})=>i(W,{label:"Color Key",required:!0,clearable:!0,sx:{flex:1},...r})})}),i(s.Button,{mt:20,leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),children:"Delete"})]},t)}function Wy({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"additional_series"}),o=t("additional_series"),l=n.map((g,m)=>({...g,...o[m]})),u=()=>{const g=new Date().getTime().toString();r({id:g,name_key:"",color_key:""})},c=x.get(l,"0.id",null),[d,f]=y.useState(c);y.useEffect(()=>{f(g=>g||c)},[c]);const h=g=>{a(g);const m=x.get(l,"0.id",null);f(m)};return p(B,{children:[p(s.Alert,{icon:i(E.IconInfoCircle,{size:16}),title:"Additional Series",children:["By setting ",i(s.Mark,{children:"Series Name Key"}),", you may add series from more queries to the chart."]}),p(s.Tabs,{value:d,onTabChange:f,styles:{tab:{paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[l.map((g,m)=>i(s.Tabs.Tab,{value:g.id,children:m+1},g.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(E.IconPlus,{size:18,color:"#228be6"})})]}),l.map((g,m)=>i(s.Tabs.Panel,{value:g.id,children:i(Gy,{control:e,index:m,remove:h})},m))]})]})}function jy({control:e,index:t,remove:n}){return p(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,align:"top",children:[i(v.Controller,{name:`dimensions.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`dimensions.${t}.data_key`,control:e,render:({field:r})=>i(W,{label:"Data Key",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`dimensions.${t}.max`,control:e,rules:{validate:r=>{if(Number.isNaN(Number(r)))return"A number is required"}},render:({field:r,fieldState:a})=>{var o;return i(s.TextInput,{label:"Max",required:!0,sx:{flex:1},...r,error:(o=a.error)==null?void 0:o.message})}})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Formatter",labelPosition:"center"}),i(v.Controller,{name:`dimensions.${t}.formatter`,control:e,render:({field:r})=>i(We,{...r})})]}),i(s.Button,{mt:20,leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this Metric"})]},t)}function Ry({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"dimensions"}),o=t("dimensions"),l=n.map((g,m)=>({...g,...o[m]})),u=()=>{const g=new Date().getTime().toString();r({id:g,name:g,data_key:"",max:"100",formatter:Ie})},c=x.get(l,"0.id",null),[d,f]=y.useState(c);y.useEffect(()=>{f(g=>g||c)},[c]);const h=g=>{a(g);const m=x.get(l,"0.id",null);f(m)};return i(B,{children:p(s.Tabs,{value:d,onTabChange:f,styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[l.map((g,m)=>i(s.Tabs.Tab,{value:g.id,children:g.name?g.name:m+1},m)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(E.IconPlus,{size:18,color:"#228be6"})})]}),l.map((g,m)=>i(s.Tabs.Panel,{value:g.id,children:i(jy,{control:e,index:m,remove:h})},m))]})})}function Yy({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},t,Hn),[t]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c,formState:d}=v.useForm({defaultValues:r,mode:"all"});y.useEffect(()=>{c(r)},[r]),l(["series_name_key","background","label"]);const f=u(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return i("form",{onSubmit:o(n),children:p(s.Stack,{spacing:"xs",children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Radar Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h||!d.isValid,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"series",children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"series",children:"Series"}),i(s.Tabs.Tab,{value:"metrics",children:"Metrics"}),i(s.Tabs.Tab,{value:"style",children:"Style"}),i(s.Tabs.Tab,{value:"additional_series",ml:"auto",children:"Additional Series"})]}),i(s.Tabs.Panel,{value:"series",p:"md",children:i(v.Controller,{name:"series_name_key",control:a,render:({field:g})=>i(W,{label:"Series Name Field",required:!0,sx:{flex:1},...g})})}),i(s.Tabs.Panel,{value:"metrics",p:"md",children:i(Ry,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"style",p:"md",children:p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"background.enabled",control:a,render:({field:g})=>i(s.Checkbox,{label:"Show background",checked:g.value,onChange:m=>g.onChange(m.currentTarget.checked)})}),i(v.Controller,{name:"label.enabled",control:a,render:({field:g})=>i(s.Checkbox,{label:"Show value label",checked:g.value,onChange:m=>g.onChange(m.currentTarget.checked)})})]})}),i(s.Tabs.Panel,{value:"additional_series",p:"md",children:i(Wy,{control:a,watch:l})})]})]})})}function Qy(e){const{dimensions:t=[],...n}=e;function r({name:a="",data_key:o="",max:l=10,formatter:u=Ie}){return{name:a,data_key:o,max:l,formatter:u}}return{...n,dimensions:t.map(r)}}function Uy(e){const{dimensions:t=[],...n}=e;return{...n,dimensions:t.map(r=>({...r,id:r.id??r.name}))}}function Ky(e){const t={background:{enabled:!0},label:{enabled:!0}};return x.defaultsDeep(t,e)}function Xy(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{series_name_key:a,dimensions:o,...l}=e;return{...l,series_name_key:r(a),dimensions:o.map(u=>({...u,data_key:r(u.data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}function Jy(e){const t={additional_series:[]};return x.defaultsDeep(t,e)}function Zy(e){const t={...e,dimensions:e.dimensions.map(n=>({...n,max:String(n.max)}))};return delete t.additionalSeries,t}class Hy extends ge{constructor(){super(...arguments);q(this,"VERSION",7)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{config:r}=n;return{...n,version:2,config:Qy(r)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:Uy(r)}}),this.version(4,n=>{const{config:r}=n;return{...n,version:4,config:Ky(r)}}),this.version(5,(n,r)=>{const{config:a}=n;return{...n,version:5,config:Xy(a,r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:Jy(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:Zy(r)}})}}const eb={displayName:"Radar Chart",displayGroup:"ECharts-based charts",migrator:new Hy,name:"radar",viewRender:Fy,configRender:Yy,createConfig:()=>({version:7,config:Hn}),triggers:[ho]};function tb(e,t){const{plot:n,transform:r}=e.regression;return t.map(a=>({...n,id:`reg-for-${a.name}`,name:a.name,data:Jn(r,a.data),color:a.color,showSymbol:!1,smooth:!0,tooltip:{show:!1},custom:{type:"regression-line",targetSeries:a.name}}))}function yo(e,t){const n=O(e.x_axis.data_key),r=O(e.regression.y_axis_data_key);return x.uniqBy(t.map(a=>[a[n.columnKey],a[r.columnKey]]),0)}function nb(e,t){const{plot:n,transform:r}=e.regression,a=yo(e,t);return[{type:"scatter",name:e.y_axis.name,data:a,symbolSize:4,color:"red",markLine:{...n,data:[Jn(r,a)],color:"blue",smooth:!0,silent:!0,symbol:["none","none"]}}]}function rb(e,t){const{plot:n,transform:r,group_by_key:a}=e.regression,o=O(a),l=x.groupBy(t,o.columnKey);return Object.entries(l).map(([u,c])=>{const d=yo(e,c);return{type:"scatter",name:u,data:d,symbolSize:4,markLine:{...n,data:[Jn(r,d)],smooth:!0,silent:!0,symbol:["none","none"]}}})}function ib(e,t){if(t.length===0)return[];const{group_by_key:n}=e.regression;return n?rb(e,t):nb(e,t)}function ab(e){return Array.isArray(e)||(e=[e]),e.map(t=>({marker:t.marker,label:t.seriesName,x:t.value[0],y:t.value[1]}))}function sb(e){return{confine:!0,trigger:"axis",formatter:t=>{const n=ab(t);return n.length===0?"":`
|
|
227
|
+
`}}const Ny={legend:{show:!0,bottom:0,left:0},tooltip:{trigger:"item"}},qy=["#66B4DB","#39BFA2","#E46464","#33A678","#EEBA00","#9D88CB","#939943","#E49792","#09A2B8","#AF5F6B","#6CA157","#09A2B8","#6398C7","#E692BA","#97B566","#8CACE2","#CA79AC","#6DBC80","#B08F4B","#826BAF"];function Fy(e,t){const{series_name_key:n,dimensions:r,additional_series:a}=e;if(!n||r.length===0)return{};const l={radar:{indicator:r.map(({name:u,max:c})=>({name:u,max:c})),splitArea:{show:!1}},tooltip:{confine:!0,backgroundColor:"rgba(255,255,255,0.6)",formatter:Vy(e)},legend:{show:!0,bottom:0,left:"center",type:"scroll"},series:By(t,e),color:qy};return x.merge({},Ny,l)}ie.use([he.RadarChart,F.GridComponent,F.LegendComponent,F.TooltipComponent,Ee.CanvasRenderer]);function Gy({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=y.useMemo(()=>{const{queryID:h,columnKey:g}=O(e.series_name_key),m=x.keyBy(t[h],g),C=e.additional_series.reduce((w,_)=>{const T=O(_.name_key),M=x.keyBy(t[T.queryID],T.columnKey);return{...w,...M}},m);return{...m,...C}},[t,e.series_name_key,e.additional_series]),u=Ke(a.triggerManager,go.id),c=y.useCallback(h=>{const g=x.get(l,h.name,{error:"rowData is not found"});u.forEach(m=>{a.runInteraction(m.id,{...h,rowData:g})})},[l,u,a]),d=y.useMemo(()=>({click:c}),[c]),f=y.useMemo(()=>Fy(x.defaultsDeep({},e,Hn),t),[e,t]);return!n||!r?null:i(ze,{echarts:ie,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function Wy({context:e,instance:t}){const n=Xe({vizManager:e.vizManager,instance:t}),{value:r}=R(e.instanceData,"config"),{variables:a}=e,o=y.useMemo(()=>x.defaults({},r,Hn),[r]),l=e.data,{width:u,height:c}=e.viewport;return!u||!c||!o||x.isEmpty(o==null?void 0:o.dimensions)?null:i(Ve,{width:u,height:c,children:i(Gy,{variables:a,width:tt(u),height:nt(c),data:l,conf:o,interactionManager:n})})}function jy({control:e,index:t,remove:n}){return p(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`additional_series.${t}.name_key`,control:e,render:({field:r})=>i(W,{label:"Series Name Key",required:!0,sx:{flex:1},...r})})}),i(s.Stack,{children:i(v.Controller,{name:`additional_series.${t}.color_key`,control:e,render:({field:r})=>i(W,{label:"Color Key",required:!0,clearable:!0,sx:{flex:1},...r})})}),i(s.Button,{mt:20,leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),children:"Delete"})]},t)}function Ry({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"additional_series"}),o=t("additional_series"),l=n.map((g,m)=>({...g,...o[m]})),u=()=>{const g=new Date().getTime().toString();r({id:g,name_key:"",color_key:""})},c=x.get(l,"0.id",null),[d,f]=y.useState(c);y.useEffect(()=>{f(g=>g||c)},[c]);const h=g=>{a(g);const m=x.get(l,"0.id",null);f(m)};return p(B,{children:[p(s.Alert,{icon:i(E.IconInfoCircle,{size:16}),title:"Additional Series",children:["By setting ",i(s.Mark,{children:"Series Name Key"}),", you may add series from more queries to the chart."]}),p(s.Tabs,{value:d,onTabChange:f,styles:{tab:{paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[l.map((g,m)=>i(s.Tabs.Tab,{value:g.id,children:m+1},g.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(E.IconPlus,{size:18,color:"#228be6"})})]}),l.map((g,m)=>i(s.Tabs.Panel,{value:g.id,children:i(jy,{control:e,index:m,remove:h})},m))]})]})}function Yy({control:e,index:t,remove:n}){return p(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,align:"top",children:[i(v.Controller,{name:`dimensions.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`dimensions.${t}.data_key`,control:e,render:({field:r})=>i(W,{label:"Data Key",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`dimensions.${t}.max`,control:e,rules:{validate:r=>{if(Number.isNaN(Number(r)))return"A number is required"}},render:({field:r,fieldState:a})=>{var o;return i(s.TextInput,{label:"Max",required:!0,sx:{flex:1},...r,error:(o=a.error)==null?void 0:o.message})}})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Formatter",labelPosition:"center"}),i(v.Controller,{name:`dimensions.${t}.formatter`,control:e,render:({field:r})=>i(We,{...r})})]}),i(s.Button,{mt:20,leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this Metric"})]},t)}function Qy({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"dimensions"}),o=t("dimensions"),l=n.map((g,m)=>({...g,...o[m]})),u=()=>{const g=new Date().getTime().toString();r({id:g,name:g,data_key:"",max:"100",formatter:Ie})},c=x.get(l,"0.id",null),[d,f]=y.useState(c);y.useEffect(()=>{f(g=>g||c)},[c]);const h=g=>{a(g);const m=x.get(l,"0.id",null);f(m)};return i(B,{children:p(s.Tabs,{value:d,onTabChange:f,styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[l.map((g,m)=>i(s.Tabs.Tab,{value:g.id,children:g.name?g.name:m+1},m)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(E.IconPlus,{size:18,color:"#228be6"})})]}),l.map((g,m)=>i(s.Tabs.Panel,{value:g.id,children:i(Yy,{control:e,index:m,remove:h})},m))]})})}function Uy({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},t,Hn),[t]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c,formState:d}=v.useForm({defaultValues:r,mode:"all"});y.useEffect(()=>{c(r)},[r]),l(["series_name_key","background","label"]);const f=u(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return i("form",{onSubmit:o(n),children:p(s.Stack,{spacing:"xs",children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Radar Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h||!d.isValid,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"series",children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"series",children:"Series"}),i(s.Tabs.Tab,{value:"metrics",children:"Metrics"}),i(s.Tabs.Tab,{value:"style",children:"Style"}),i(s.Tabs.Tab,{value:"additional_series",ml:"auto",children:"Additional Series"})]}),i(s.Tabs.Panel,{value:"series",p:"md",children:i(v.Controller,{name:"series_name_key",control:a,render:({field:g})=>i(W,{label:"Series Name Field",required:!0,sx:{flex:1},...g})})}),i(s.Tabs.Panel,{value:"metrics",p:"md",children:i(Qy,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"style",p:"md",children:p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"background.enabled",control:a,render:({field:g})=>i(s.Checkbox,{label:"Show background",checked:g.value,onChange:m=>g.onChange(m.currentTarget.checked)})}),i(v.Controller,{name:"label.enabled",control:a,render:({field:g})=>i(s.Checkbox,{label:"Show value label",checked:g.value,onChange:m=>g.onChange(m.currentTarget.checked)})})]})}),i(s.Tabs.Panel,{value:"additional_series",p:"md",children:i(Ry,{control:a,watch:l})})]})]})})}function Ky(e){const{dimensions:t=[],...n}=e;function r({name:a="",data_key:o="",max:l=10,formatter:u=Ie}){return{name:a,data_key:o,max:l,formatter:u}}return{...n,dimensions:t.map(r)}}function Xy(e){const{dimensions:t=[],...n}=e;return{...n,dimensions:t.map(r=>({...r,id:r.id??r.name}))}}function Jy(e){const t={background:{enabled:!0},label:{enabled:!0}};return x.defaultsDeep(t,e)}function Zy(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{series_name_key:a,dimensions:o,...l}=e;return{...l,series_name_key:r(a),dimensions:o.map(u=>({...u,data_key:r(u.data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}function Hy(e){const t={additional_series:[]};return x.defaultsDeep(t,e)}function eb(e){const t={...e,dimensions:e.dimensions.map(n=>({...n,max:String(n.max)}))};return delete t.additionalSeries,t}class tb extends ge{constructor(){super(...arguments);q(this,"VERSION",7)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{config:r}=n;return{...n,version:2,config:Ky(r)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:Xy(r)}}),this.version(4,n=>{const{config:r}=n;return{...n,version:4,config:Jy(r)}}),this.version(5,(n,r)=>{const{config:a}=n;return{...n,version:5,config:Zy(a,r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:Hy(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:eb(r)}})}}const nb={displayName:"Radar Chart",displayGroup:"ECharts-based charts",migrator:new tb,name:"radar",viewRender:Wy,configRender:Uy,createConfig:()=>({version:7,config:Hn}),triggers:[go]};function rb(e,t){const{plot:n,transform:r}=e.regression;return t.map(a=>({...n,id:`reg-for-${a.name}`,name:a.name,data:Jn(r,a.data),color:a.color,showSymbol:!1,smooth:!0,tooltip:{show:!1},custom:{type:"regression-line",targetSeries:a.name}}))}function vo(e,t){const n=O(e.x_axis.data_key),r=O(e.regression.y_axis_data_key);return x.uniqBy(t.map(a=>[a[n.columnKey],a[r.columnKey]]),0)}function ib(e,t){const{plot:n,transform:r}=e.regression,a=vo(e,t);return[{type:"scatter",name:e.y_axis.name,data:a,symbolSize:4,color:"red",markLine:{...n,data:[Jn(r,a)],color:"blue",smooth:!0,silent:!0,symbol:["none","none"]}}]}function ab(e,t){const{plot:n,transform:r,group_by_key:a}=e.regression,o=O(a),l=x.groupBy(t,o.columnKey);return Object.entries(l).map(([u,c])=>{const d=vo(e,c);return{type:"scatter",name:u,data:d,symbolSize:4,markLine:{...n,data:[Jn(r,d)],smooth:!0,silent:!0,symbol:["none","none"]}}})}function sb(e,t){if(t.length===0)return[];const{group_by_key:n}=e.regression;return n?ab(e,t):ib(e,t)}function ob(e){return Array.isArray(e)||(e=[e]),e.map(t=>({marker:t.marker,label:t.seriesName,x:t.value[0],y:t.value[1]}))}function lb(e){return{confine:!0,trigger:"axis",formatter:t=>{const n=ob(t);return n.length===0?"":`
|
|
228
228
|
<table style="width: auto">
|
|
229
229
|
<thead>
|
|
230
230
|
<tr>
|
|
@@ -243,16 +243,16 @@ Check the top-level render call using <`+V+">.")}return z}}function Tu(S,z){{if(
|
|
|
243
243
|
</tr>
|
|
244
244
|
</tbody>
|
|
245
245
|
</table>
|
|
246
|
-
`}}}function
|
|
247
|
-
`)},di={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,format:Ie,overflow:je,formatter:{...tr}}},y_axis:{name:"Y Axis"},regression:{transform:{type:"ecStat:regression",config:{method:"linear",order:1,formulaOn:"end"}},plot:{type:"line",yAxisIndex:0,color:"#228be6",lineStyle:{type:"solid",width:1}},name:"regression",group_by_key:"",y_axis_data_key:"value"}};ie.use([F.DataZoomComponent,he.ScatterChart,F.GridComponent,F.LegendComponent,F.TooltipComponent,Ee.CanvasRenderer]);function
|
|
246
|
+
`}}}function xo({enabled:e,func_content:t}){return(n,r)=>{if(!e)return n;try{return new Function(`return ${t}`)()(n,r)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function ub(e){const{overflow:t,format:n,formatter:r,...a}=e.x_axis.axisLabel,o=it(t.on_axis);return{type:"value",name:e.x_axis.name??"",nameLocation:"middle",nameGap:25,axisTick:{show:!0,alignWithLabel:!0},axisLabel:{...a,...o,formatter:(l,u)=>{let c=l;try{c=Z(l).format(n)}catch{}return xo(r)(c,u)}}}}const cb={tooltip:{trigger:"axis"},grid:{top:50,left:5,right:10,bottom:20,containLabel:!0},dataZoom:[{type:"inside",xAxisIndex:[0]},{type:"inside",yAxisIndex:[0]}]};function db(e,t){const n=sb(e,t),r=rb(e,n),a={xAxis:ub(e),yAxis:{name:e.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"left"},nameGap:5,axisLine:{show:!0}},series:[...n,...r],tooltip:lb(e),legend:{show:!0,type:"scroll",orient:"horizontal",align:"left",right:0,top:0,left:"auto",itemGap:20,padding:[4,8,0,140],data:n.map(o=>o.name)}};return x.defaultsDeep({},a,cb)}function er(e,t,n){return 1-(1-e)*(t-1)/(t-n-1)}function pb(e,t,n,r){const{x_axis:a,y_axis:o}=r,l=wt.regressionLinear()(n),{a:u,b:c,rSquared:d}=l;return{name:e,expression:p(s.Group,{position:"center",noWrap:!0,spacing:10,children:[i(s.Text,{children:o.name}),i(s.Text,{children:"="}),i(s.Text,{weight:"bold",color:"red",children:Z(c).format({mantissa:2,trimMantissa:!0})}),i(s.Text,{children:"+"}),i(s.Text,{weight:"bold",color:"red",children:Z(u).format({mantissa:2,trimMantissa:!0})}),i(s.Text,{children:"×"}),i(s.Text,{children:a.name})]}),rSquared:d,adjustedRSquared:er(d,t.length,1)}}function hb(e,t,n,r){const{x_axis:a,y_axis:o}=r,{a:l,b:u,rSquared:c}=wt.regressionExp()(n);return{name:e,expression:p(s.Group,{position:"center",noWrap:!0,spacing:10,children:[i(s.Text,{children:o.name}),i(s.Text,{children:"="}),i(s.Text,{weight:"bold",color:"gray",children:l}),i(s.Text,{children:"×"}),p(s.Group,{position:"left",noWrap:!0,spacing:2,children:[i(s.Text,{children:"Math.exp("}),i(s.Text,{weight:"bold",color:"gray",children:u}),i(s.Text,{children:"×"}),i(s.Text,{children:a.name}),i(s.Text,{children:")"})]})]}),rSquared:c,adjustedRSquared:er(c,t.length,1)}}function fb(e,t,n,r){const{x_axis:a,y_axis:o}=r,{a:l,b:u,rSquared:c}=wt.regressionLog()(n);return{name:e,expression:p(s.Group,{position:"center",noWrap:!0,spacing:10,children:[i(s.Text,{children:o.name}),i(s.Text,{children:"="}),i(s.Text,{weight:"bold",color:"gray",children:l}),i(s.Text,{children:"×"}),p(s.Group,{position:"left",noWrap:!0,spacing:2,children:[i(s.Text,{children:"Math.log("}),i(s.Text,{children:a.name}),i(s.Text,{children:")"}),i(s.Text,{children:"+"}),i(s.Text,{weight:"bold",color:"gray",children:u})]})]}),rSquared:c,adjustedRSquared:er(c,t.length,1)}}function gb(e,t,n,r){const{x_axis:a,y_axis:o,regression:l}=r,u=wt.regressionPoly().order(l.transform.config.order)(n),{rSquared:c}=u;return console.log(u),{name:e,expression:"",rSquared:c,adjustedRSquared:er(c,t.length,1)}}function wo(e,t,n){const{regression:r,x_axis:a}=n,o=O(a.data_key),l=O(r.y_axis_data_key),u=t.map(c=>[c[o.columnKey],c[l.columnKey]]);return r.transform.config.method==="linear"?pb(e,t,u,n):r.transform.config.method==="exponential"?hb(e,t,u,n):r.transform.config.method==="logarithmic"?fb(e,t,u,n):r.transform.config.method==="polynomial"?gb(e,t,u,n):{name:e,expression:"",rSquared:0,adjustedRSquared:0}}function mb(e,t){if(!t)return[{name:"",expression:"",rSquared:0,adjustedRSquared:0}];if(!t.regression.group_by_key)return[wo("",e,t)];const n=O(t.regression.group_by_key),r=x.groupBy(e,n.columnKey);return Object.entries(r).map(([a,o])=>wo(a,o,t))}const yb={marginTop:"10px","tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function Co({desc:e}){const{expression:t,rSquared:n,adjustedRSquared:r}=e;return t?i(s.Table,{fontSize:14,sx:yb,children:p("tbody",{children:[i("tr",{children:i("td",{colSpan:2,children:i(s.Text,{align:"center",children:t})})}),p("tr",{children:[i("td",{children:"R-Sq"}),i("td",{style:{textAlign:"right"},children:Z(n).format({output:"percent",mantissa:1})})]}),p("tr",{children:[i("td",{children:"R-Sq(Adjusted)"}),i("td",{style:{textAlign:"right"},children:Z(r).format({output:"percent",mantissa:1})})]})]})}):i(s.Text,{children:"Unavailable for this regression method"})}function bb({conf:e,queryData:t}){var r;const n=y.useMemo(()=>mb(t,e),[e,t]);return e.regression.group_by_key?(console.log(n),p(s.Tabs,{defaultValue:(r=n[0])==null?void 0:r.name,color:"gray",children:[i(s.Tabs.List,{grow:!0,children:n.map(a=>i(s.Tabs.Tab,{value:a.name,children:a.name},a.name))}),n.map(a=>i(s.Tabs.Panel,{value:a.name,children:i(Co,{desc:a})},a.name))]})):i(Co,{desc:n[0]})}function vb({conf:e,queryData:t}){return p(s.HoverCard,{shadow:"md",withinPortal:!0,zIndex:320,children:[i(s.HoverCard.Target,{children:i(s.Button,{size:"xs",variant:"subtle",compact:!0,leftIcon:i(E.IconInfoCircle,{size:14}),children:"Regression Info"})}),i(s.HoverCard.Dropdown,{children:i(Ne,{children:i(bb,{conf:e,queryData:t})})})]})}function xb(e){return i(s.Group,{position:"apart",sx:{position:"absolute",top:0,left:Be.left,right:Be.right,height:"22px",zIndex:1},children:i(vb,{...e})})}const tr={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
247
|
+
`)},di={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,format:Ie,overflow:je,formatter:{...tr}}},y_axis:{name:"Y Axis"},regression:{transform:{type:"ecStat:regression",config:{method:"linear",order:1,formulaOn:"end"}},plot:{type:"line",yAxisIndex:0,color:"#228be6",lineStyle:{type:"solid",width:1}},name:"regression",group_by_key:"",y_axis_data_key:"value"}};ie.use([F.DataZoomComponent,he.ScatterChart,F.GridComponent,F.LegendComponent,F.TooltipComponent,Ee.CanvasRenderer]);function wb({context:e}){const{value:t}=R(e.instanceData,"config"),{width:n,height:r}=e.viewport,a=y.useMemo(()=>{var m;const c=e.data,d=t==null?void 0:t.x_axis.data_key,f=(m=t==null?void 0:t.regression)==null?void 0:m.y_axis_data_key;if(!d||!f)return[];const h=O(d),g=O(f);return c[h.queryID].map(C=>typeof C[g.columnKey]=="number"?C:{...C,[g.columnKey]:Number(C[g.columnKey])})},[e.data,t==null?void 0:t.regression.y_axis_data_key]),o=y.useMemo(()=>db(x.defaultsDeep({},t,di),a),[t,a]),l=y.useRef(null),u=c=>{l.current=c};return!n||!r||!t?null:p(Ve,{width:n,height:r,children:[i(xb,{conf:t,queryData:a}),i(ze,{echarts:ie,onChartReady:u,option:o,style:an(n,r),notMerge:!0,theme:"merico-light"})]})}const Cb=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}];function Sb({control:e,watch:t}){t("regression");const n=t("regression.transform.config.method"),r=t("regression.group_by_key");return p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"regression.name",control:e,render:({field:a})=>i(s.TextInput,{label:"回归线名称",sx:{flex:1},...a})})}),i(v.Controller,{name:"regression.group_by_key",control:e,render:({field:a})=>i(W,{label:"按此字段将数据分为多个系列",clearable:!0,sx:{flex:1},...a})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"regression.transform.config.method",control:e,render:({field:a})=>i(s.Select,{label:"回归方法",data:Cb,sx:{flex:1},...a})}),n==="polynomial"&&i(v.Controller,{name:"regression.transform.config.order",control:e,render:({field:a})=>i(s.NumberInput,{label:"次",sx:{flex:1},...a})})]}),!r&&p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"颜色"}),i(v.Controller,{name:"regression.plot.color",control:e,render:({field:a})=>i($e,{...a})})]})]})}const _b=({disabled:e,value:t,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[e&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(De,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},So=y.forwardRef(({value:e,onChange:t,triggerButtonText:n="Customize Label"},r)=>{const[a,{setTrue:o,setFalse:l}]=Q.useBoolean(),[u,c]=y.useState(e);y.useEffect(()=>{c(e)},[e]);const d=C=>{c({...u,enabled:C})},f=()=>{l();const{enabled:C,func_content:w}=u,_={enabled:C,func_content:w};c(_),t(_)},h=()=>{l(),c(e)},g=C=>{c(w=>({...w,func_content:C}))},m=()=>{g(tr.func_content)};return p(B,{children:[i(s.Button,{variant:"filled",mt:24,onClick:o,sx:{flexGrow:0},children:n}),i(s.Modal,{size:800,title:"Customize label content",opened:a,onClose:l,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:a&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:u.enabled,onChange:C=>d(C.currentTarget.checked)}),i(_b,{value:u.func_content,onChange:g,disabled:!u.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:m,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:h,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:f,children:"OK"})]})]})]})})]})});function kb({control:e,watch:t}){return t(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"X轴名称",sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>i(W,{label:"X轴数据字段",required:!0,sx:{flex:1},...n})})]}),i(s.Divider,{variant:"dashed",labelPosition:"center",label:"格式化数据"}),i(s.Stack,{children:i(v.Controller,{name:"x_axis.axisLabel.format",control:e,render:({field:n})=>i(We,{...n})})}),i(s.Divider,{variant:"dashed",labelPosition:"center",label:"标签文案样式"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>i(s.NumberInput,{label:"旋转",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"度"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>i(So,{triggerButtonText:"自定义标签文案内容",...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>i(st,{...n})})]})}function Tb({control:e,watch:t}){return t(["y_axis","regression.y_axis_data_key"]),i(s.Stack,{children:p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"Y轴名称",sx:{flex:1},...n})}),i(v.Controller,{name:"regression.y_axis_data_key",control:e,render:({field:n})=>i(W,{label:"Y轴数据字段",required:!0,sx:{flex:1},...n})})]})})}function Db({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=y.useMemo(()=>x.defaults({},t,di),[t]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l(["x_axis","y_axis","regression"]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,t),[d,t]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X轴",orientation:"vertical",styles:{panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X轴",children:"X轴"}),i(s.Tabs.Tab,{value:"Y轴",children:"Y轴"}),i(s.Tabs.Tab,{value:"回归",children:"回归"})]}),i(s.Tabs.Panel,{value:"X轴",children:i(kb,{watch:l,control:a})}),i(s.Tabs.Panel,{value:"Y轴",children:i(Tb,{watch:l,control:a})}),i(s.Tabs.Panel,{value:"回归",children:i(Sb,{control:a,watch:l})})]})]})})}function Ib(e){const t={x_axis:{axisLabel:{rotate:0,format:Ie,overflow:je,formatter:tr}},regression:{group_by_key:""}};return x.defaultsDeep(t,e)}function Mb(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis:a,regression:o,...l}=e;return{...l,x_axis:{...a,data_key:r(a.data_key)},regression:{...o,group_by_key:r(o.group_by_key),y_axis_data_key:r(o.y_axis_data_key)}}}catch(n){throw console.error("[Migration failed]",n),n}}class Ab extends ge{constructor(){super(...arguments);q(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:Ib(n.config)})),this.version(3,(n,r)=>{const{config:a}=n;return{...n,version:3,config:Mb(a,r)}})}}const zb={displayName:"Regression Chart",displayGroup:"Merico suite",migrator:new Ab,name:"regressionChart",viewRender:wb,configRender:Db,createConfig(){return{version:3,config:x.cloneDeep(di)}}},nr={content:""};function Eb(e,t){const n={};return e.forEach(r=>{const{name:a,data_field:o,aggregation:l}=r,u=Yn(t,o,l);n[a]=Ze(r,u)}),n}function $b(e){const t=document.createElement("span");return t.innerHTML=e,t.innerText}function Lb(e,t,n){try{return new Function("payload",`
|
|
248
248
|
const filters = payload.filters;
|
|
249
249
|
const context = payload.context;
|
|
250
250
|
${Object.entries(t).map(([r,a])=>`const ${r} = '${a}';`).join(`
|
|
251
251
|
`)}
|
|
252
252
|
return ${e};
|
|
253
|
-
`)(n)}catch(r){return console.error(r),console.log(e),e}}function
|
|
254
|
-
`)}},
|
|
255
|
-
`)},
|
|
253
|
+
`)(n)}catch(r){return console.error(r),console.log(e),e}}function Ob(e,t,n,r){const a=Eb(t,r),o=/^(.+)\}\}(.*)$/;return e.split("{{").map(l=>{const u=o.exec(l);if(!u)return l;const c=a[u[1]];if(c){const f=u[2]??"";return`${c}${f}`}const d=$b(u[1]);return`${Lb(d,a,n)}${u[2]}`}).join("")}const Pb=k.observer(({context:e})=>{const t=ye(),{value:n}=R(e.instanceData,"config"),{variables:r,data:a}=e,o=y.useMemo(()=>{const l=x.defaults({},n,nr);return l.content?Ob(l.content,r,t.payloadForViz,a):""},[n,r,t.payloadForViz]);return o?i(Rn,{value:o,styles:{root:{border:"none",height:"100%"},content:{padding:0}}}):null});function Bb(){const{editor:e}=J.useRichTextEditorContext();return i(J.RichTextEditor.Control,{onClick:()=>e==null?void 0:e.commands.insertTable({rows:3,cols:3,withHeaderRow:!0}),"aria-label":"Insert table",title:"Insert table",children:i(E.IconBorderAll,{stroke:1.5,size:16})})}const pi=y.forwardRef(({value:e,onChange:t,styles:n={},label:r,onSubmit:a},o)=>{const[l,u]=y.useState(e),c=Qa.useEditor({extensions:[Ua,Ya,J.Link,Na,Va,Pa,Ga.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),Ra,ja,Wa,qa.configure({types:["heading","paragraph"]}),Ba.configure({placeholder:"This is placeholder"}),Fa,Oa.Color,Xs],content:l,onUpdate:({editor:g})=>{u(g.getHTML())}});y.useEffect(()=>{u(e),c==null||c.commands.setContent(e)},[e]);const d=()=>{t(l),a==null||a()},f=e!==l,h=y.useMemo(()=>x.defaultsDeep({},{content:Lr},n),[n]);return c?p(s.Stack,{spacing:4,sx:{flexGrow:1,position:"relative"},children:[p(s.Group,{align:"center",children:[i(s.Text,{size:14,fw:500,children:r}),i(s.ActionIcon,{color:"blue",disabled:!f,onClick:d,children:i(E.IconDeviceFloppy,{size:18})})]}),p(J.RichTextEditor,{editor:c,styles:h,children:[p(J.RichTextEditor.Toolbar,{sticky:!0,stickyOffset:0,children:[i(J.RichTextEditor.ControlsGroup,{children:i(J.RichTextEditor.ColorPicker,{colors:["#25262b","#868e96","#fa5252","#e64980","#be4bdb","#7950f2","#4c6ef5","#228be6","#15aabf","#12b886","#40c057","#82c91e","#fab005","#fd7e14"],popoverProps:{zIndex:320}})}),p(J.RichTextEditor.ControlsGroup,{children:[i(J.RichTextEditor.Bold,{}),i(J.RichTextEditor.Italic,{}),i(J.RichTextEditor.Underline,{}),i(J.RichTextEditor.ClearFormatting,{}),i(J.RichTextEditor.Highlight,{}),i(J.RichTextEditor.Code,{})]}),p(J.RichTextEditor.ControlsGroup,{children:[i(J.RichTextEditor.H1,{}),i(J.RichTextEditor.H2,{}),i(J.RichTextEditor.H3,{}),i(J.RichTextEditor.H4,{})]}),p(J.RichTextEditor.ControlsGroup,{children:[i(J.RichTextEditor.Blockquote,{}),i(J.RichTextEditor.Hr,{}),i(J.RichTextEditor.BulletList,{}),i(J.RichTextEditor.OrderedList,{}),i(J.RichTextEditor.Subscript,{}),i(J.RichTextEditor.Superscript,{})]}),p(J.RichTextEditor.ControlsGroup,{children:[i(J.RichTextEditor.Link,{}),i(J.RichTextEditor.Unlink,{})]}),p(J.RichTextEditor.ControlsGroup,{children:[i(J.RichTextEditor.AlignLeft,{}),i(J.RichTextEditor.AlignCenter,{}),i(J.RichTextEditor.AlignJustify,{}),i(J.RichTextEditor.AlignRight,{})]}),i(J.RichTextEditor.ControlsGroup,{children:i(Bb,{})}),i(Jp,{editor:c})]}),i(J.RichTextEditor.Content,{})]})]}):null});function Vb({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=y.useMemo(()=>x.defaults({},t,nr),[t]),{control:a,handleSubmit:o,watch:l,reset:u}=v.useForm({defaultValues:r});l("content"),y.useEffect(()=>{u(r)},[r]);const c=y.useRef(null),d=()=>{var f;return(f=c.current)==null?void 0:f.click()};return i("form",{onSubmit:o(n),style:{flexGrow:1,display:"flex",flexDirection:"column"},children:p(s.Stack,{spacing:"xs",sx:{flexGrow:1},children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",display:"none"},children:[i(s.Text,{children:"Content"}),i(s.ActionIcon,{ref:c,type:"submit",mr:5,variant:"filled",color:"blue",children:i(D.DeviceFloppy,{size:20})})]}),i(v.Controller,{name:"content",control:a,render:({field:f})=>i(pi,{...f,styles:{root:{flexGrow:1}},label:"Content",onSubmit:d})})]})})}class Nb extends ge{constructor(){super(...arguments);q(this,"VERSION",1)}fixMalformedConfig(n){return x.defaults({},n,nr)}configVersions(){this.version(1,n=>({version:1,config:this.fixMalformedConfig(n)}))}}const qb={displayName:"Rich Text",displayGroup:"Others",migrator:new Nb,name:"richText",viewRender:Pb,configRender:Vb,createConfig(){return{version:1,config:x.cloneDeep(nr)}}},mn={static:{type:"static",color:pt.random().css()},dynamic:{type:"dynamic",func_content:["function getColor({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here",' // return "blue"',"}"].join(`
|
|
254
|
+
`)}},_o={id:"builtin:echarts:click-scatter-chart:series",displayName:"Click Scatter",nameRender:Gb,configRender:Fb,payload:[{name:"seriesType",description:"'scatter'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function Fb(e){return i(B,{})}function Gb(e){return i(s.Text,{children:"Click scatter"})}const ko={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
255
|
+
`)},To={label:je.on_axis,tooltip:je.in_tooltip},hi={scatter:{y_data_key:"",name_data_key:"",symbolSize:{type:"static",size:10},color:mn.static,label_position:"right",label_overflow:To},stats:{templates:{top:"",bottom:""}},x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...ko}}},y_axes:[{name:"Y Axis",position:"left",nameAlignment:"center",label_formatter:Ie,min:"",max:"",show:!0}],tooltip:{trigger:"item",metrics:[]},reference_lines:[],reference_areas:[],dataZoom:jt};function Wb(e,t){if(!e.x_axis.data_key)return[];const n=O(e.x_axis.data_key);return[{source:t[n.queryID]}]}function jb(e){const t=e.y_axes.some(a=>!!a.name);let n=15;t&&(n+=20),e.dataZoom.x_axis_slider&&(n+=20);let r=5;return e.x_axis.name&&(r+=15),{top:n,bottom:r}}function Rb(){return{show:!1,bottom:0,left:"center",type:"scroll"}}function rr(e,t){if(e)return t[e]??void 0}function Yb({reference_areas:e,variableValueMap:t}){const n=e.map(r=>[{name:r.content.text,value:r.content.text,itemStyle:r.itemStyle,label:r.label,xAxis:rr(r.leftBottomPoint.x_data_key,t),yAxis:rr(r.leftBottomPoint.y_data_key,t)},{xAxis:rr(r.rightTopPoint.x_data_key,t),yAxis:rr(r.rightTopPoint.y_data_key,t)}]);return{type:"scatter",name:"ref_areas",silent:!0,data:[],markArea:{data:n}}}function Qb({type:e,...t},n){if(!e)return 10;if(e==="static"){const{size:a}=t;return a}const{func_content:r}=t;return(a,o)=>{const l=o.data;try{return new Function(`return ${r}`)()({rowData:l,params:o,variables:n},{lodash:x,interpolate:It.interpolate})}catch(u){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${u.message}`),10}}}function Ub({type:e,...t},n){if(!e)return mn.static.color;if(e==="static"){const{color:a}=t;return a}const{func_content:r}=t;return({value:a})=>{try{return new Function(`return ${r}`)()({rowData:a,variables:n},{lodash:x,interpolate:It.interpolate})}catch(o){return console.error(`[getSeriesColor] failed parsing custom function, error: ${o.message}`),10}}}function Kb(e,t,n,r){return e.map(a=>{const o=a.orientation==="horizontal",l=o?"yAxis":"xAxis",u=o?"insideEndTop":"end";return{name:a.name,type:"line",hide_in_legend:!a.show_in_legend,yAxisIndex:a.yAxisIndex,data:[],lineStyle:a.lineStyle,markLine:{data:[{name:a.name,[l]:Number(n[a.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:a.lineStyle,label:{formatter:function(){return a.template?Kn(a.template,t,r):""},position:u}}}})}function Xb({x_axis:e,scatter:t},n){const r=O(e.data_key),a=O(t.y_data_key),o=O(t.name_data_key);return{label:{show:!!t.label_position,position:t.label_position,...it(t.label_overflow.label),formatter:({value:l})=>l[o.columnKey]},type:"scatter",name:"",xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{color:Ub(t.color,n)},symbolSize:Qb(t.symbolSize,n),encode:{x:r.columnKey,y:a.columnKey}}}function Jb(e,t,n,r){return[Xb(e,r)].concat(Kb(e.reference_lines,n,r,t)).concat(Yb({reference_areas:e.reference_areas,variableValueMap:r}))}function Do({enabled:e,func_content:t}){return(n,r)=>{if(!e)return n;try{return new Function(`return ${t}`)()(n,r)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function Io(e,t,n){const{x_axis:r}=n;return r.axisLabel.formatter.enabled?Do(r.axisLabel.formatter)(e,t):e}function Zb(e,t){const{x_axis:n,tooltip:r}=t;if(r.trigger==="item"){const u=Mn(e[0].data,n.data_key);return Io(u,0,t)}const a=e.find(u=>u.axisDim==="x"&&u.axisId==="main-x-axis");if(!a)return"";const{axisValue:o,axisIndex:l}=a;return Io(o,l,t)}const Hb=e=>{try{return Z(e).format({trimMantissa:!0,mantissa:2})}catch{return e}};function ev(e,t){const{scatter:n,tooltip:r}=e;return{confine:!0,trigger:r.trigger,formatter:function(a){const o=t[0]??t.default,l=Array.isArray(a)?a:[a];if(l.length===0)return"";const u=Zb(l,e),c=ot(e.scatter.label_overflow.tooltip),d=l.map(({value:m})=>`
|
|
256
256
|
<th style="text-align: right; padding-right: 1em">
|
|
257
257
|
<div style="${c}">${Mn(m,n.name_data_key)}</div>
|
|
258
258
|
</th>
|
|
@@ -267,14 +267,14 @@ Check the top-level render call using <`+V+">.")}return z}}function Tu(S,z){{if(
|
|
|
267
267
|
</td>`).join("")}
|
|
268
268
|
</tr>`],h=e.tooltip.metrics.map(m=>`<tr>
|
|
269
269
|
<th style="text-align: right;">${m.name}</th>
|
|
270
|
-
${l.map(({value:C})=>`<td style="text-align: right; padding: 0 1em;">${
|
|
270
|
+
${l.map(({value:C})=>`<td style="text-align: right; padding: 0 1em;">${Hb(Mn(C,m.data_key))}</td>`).join("")}
|
|
271
271
|
</tr>`);return f.push(...h),`
|
|
272
272
|
<table style="width: auto">
|
|
273
273
|
<thead><tr>${d.join("")}</tr></thead>
|
|
274
274
|
<tbody>${f.join("")}</tbody>
|
|
275
275
|
</table>
|
|
276
|
-
`}}}function Hb(e,t){const n=t.every(a=>!Number.isNaN(Number(a))),{axisLabel:r}=e.x_axis;return[{data:t,name:e.x_axis.name??"",id:"main-x-axis",axisTick:{show:!0,alignWithLabel:!0},type:n?"value":"category",axisLabel:{...r,formatter:ko(r.formatter)}}]}function ev(e,t){return e.y_axes.map(({nameAlignment:n,min:r,max:a,...o},l)=>{let u=o.position;return u||(u=l>0?"right":"left"),{...o,minInterval:1,min:r||void 0,max:a||void 0,position:u,axisLabel:{show:!0,formatter:t[l]??t.default},axisLine:{show:!0},nameTextStyle:{fontWeight:"bold",align:n},nameLocation:"end",nameGap:15,splitLine:{show:!1}}})}const tv={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 nv(e,t,n){const r=n.reduce((c,d)=>{const f=mt(d,t);return c[d.name]=Ze(d,f),c},{}),a=e.y_axes.reduce((c,{label_formatter:d},f)=>(c[f]=function(g){let m=g;if(typeof g=="object"&&(Array.isArray(g.value)&&g.value.length===2?m=g.value[1]:m=g.value),!d)return m;try{return Z(m).format(d)}catch(C){return console.error(C),m}},c),{default:({value:c})=>c}),o=x.uniq(ft(t,e.x_axis.data_key)),l=Kb(e,t,n,r),u={xAxis:Hb(e,o),yAxis:ev(e,a),series:l,dataset:Fb(e,t),tooltip:Zb(e,a),grid:Gb(e),legend:Wb(),dataZoom:ti(e.dataZoom)};return x.defaultsDeep({},u,tv)}ie.use([F.DataZoomComponent,he.BarChart,he.LineChart,he.ScatterChart,F.GridComponent,F.LegendComponent,F.TooltipComponent,Ee.CanvasRenderer,F.MarkLineComponent,F.MarkAreaComponent]);function Do(e){return e.trim().length>0}function rv({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=zt(t,e.x_axis.data_key),u=Ke(a.triggerManager,Co.id),c=y.useCallback(h=>{const g=h.data;u.forEach(m=>{a.runInteraction(m.id,{...h,rowData:g})})},[l,u,a]),d=y.useMemo(()=>({click:c}),[c]),f=y.useMemo(()=>nv(e,t,o),[e,t]);return i(ze,{echarts:ie,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function iv({context:e,instance:t}){const n=Xe({vizManager:e.vizManager,instance:t}),{value:r}=R(e.instanceData,"config"),{variables:a}=e,o=y.useMemo(()=>x.defaults({},r,hi),[r]),l=e.data,{width:u,height:c}=e.viewport,{ref:d,height:f}=ke.useElementSize(),{ref:h,height:g}=ke.useElementSize(),m=y.useMemo(()=>{const{stats:{templates:w}}=o;return{top:gn(w.top,a,l),bottom:gn(w.bottom,a,l)}},[o,l]),C=Math.max(0,nt(c)-f-g);return!u||!c?null:p(Ve,{width:u,height:c,children:[i(s.Text,{ref:d,align:"left",size:"xs",pl:"sm",sx:{display:Do(o.stats.templates.top)?"block":"none"},children:Object.values(m.top).map(w=>w)}),i(rv,{variables:a,width:tt(u),height:C,data:l,conf:o,interactionManager:n}),i(s.Text,{ref:h,align:"left",size:"xs",pl:"sm",sx:{display:Do(o.stats.templates.bottom)?"block":"none"},children:Object.values(m.bottom).map(w=>w)})]})}const av=y.forwardRef(({value:e,onChange:t,xAxisOptions:n,yAxisOptions:r,variableOptions:a},o)=>{const l=(u,c)=>{const d=x.cloneDeep(e);x.set(d,u,c),t(d)};return p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Content",labelPosition:"right"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(s.TextInput,{label:"Content Text",value:e.content.text,onChange:u=>l("content.text",u.currentTarget.value)}),i(si,{label:"Text Position",value:e.label.position,onChange:u=>l("label.position",u)})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Endpoints",labelPosition:"right"}),p(s.Group,{grow:!0,noWrap:!0,children:[n&&i(s.Select,{label:"X Axis",data:n,value:e.xAxisIndex,onChange:u=>l("xAxisIndex",u)}),r&&i(s.Select,{label:"Y Axis",data:r,value:e.yAxisIndex,onChange:u=>l("xAxisIndex",u)})]}),p(s.Stack,{spacing:0,children:[i(s.Text,{size:14,color:"#212529",fw:500,children:"Left-Bottom Point"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(s.Select,{icon:i(s.Text,{children:"x"}),data:a,value:e.leftBottomPoint.x_data_key,onChange:u=>l("leftBottomPoint.x_data_key",u??""),clearable:!0}),i(s.Select,{icon:i(s.Text,{children:"y"}),data:a,value:e.leftBottomPoint.y_data_key,onChange:u=>l("leftBottomPoint.y_data_key",u??""),clearable:!0})]})]}),p(s.Stack,{spacing:0,children:[i(s.Text,{size:14,color:"#212529",fw:500,children:"Right-Top Point"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(s.Select,{icon:i(s.Text,{children:"x"}),data:a,value:e.rightTopPoint.x_data_key,onChange:u=>l("rightTopPoint.x_data_key",u??""),clearable:!0}),i(s.Select,{icon:i(s.Text,{children:"y"}),data:a,value:e.rightTopPoint.y_data_key,onChange:u=>l("rightTopPoint.y_data_key",u??""),clearable:!0})]})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Style",labelPosition:"right"}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:14,children:"Background Color"}),i($e,{value:e.itemStyle.color,onChange:u=>l("itemStyle.color",u)})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:14,children:"Text Color"}),i($e,{value:e.label.color,onChange:u=>l("label.color",u)})]})]})});function sv(){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 ov({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_areas"}),l=t("reference_areas"),u=r.map((g,m)=>({...g,...l[m]})),c=()=>{const g=sv();a(g)},d=y.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=t("y_axes"),h=y.useMemo(()=>f.map(({name:g},m)=>({label:g,value:m.toString()})),[f]);return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[u.map((g,m)=>i(s.Tabs.Tab,{value:m.toString(),children:m+1},m)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),u.map((g,m)=>i(s.Tabs.Panel,{value:m.toString(),children:i(v.Controller,{name:`reference_areas.${m}`,control:e,render:({field:C})=>p(s.Stack,{children:[i(av,{variableOptions:d,yAxisOptions:h,...C}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(E.IconTrash,{size:16}),color:"red",variant:"light",onClick:()=>o(m),children:"Delete this Reference Area"})]})})},m))]})}const lv=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],uv=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function cv({control:e,index:t,remove:n,watch:r,variableOptions:a,yAxisOptions:o}){const l=r(`reference_lines.${t}.orientation`);return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:u})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:u})=>i(s.Select,{label:"Value",required:!0,data:a,sx:{flex:1},...u})})]}),i(v.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:u})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...u})}),p(s.Group,{grow:!0,children:[p(s.Stack,{children:[i(v.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:u})=>i(s.Select,{label:"Orientation",data:uv,required:!0,sx:{flex:1},...u})}),l==="vertical"&&i(s.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&i(v.Controller,{name:`reference_lines.${t}.yAxisIndex`,control:e,render:({field:{value:u,onChange:c,...d}})=>i(s.Select,{label:"Y Axis",data:o,disabled:o.length===0,...d,value:(u==null?void 0:u.toString())??"",onChange:f=>{if(!f){c(0);return}c(Number(f))},sx:{flex:1}})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:u})=>i(s.Select,{label:"Line Type",data:lv,sx:{flexGrow:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:u})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...u})})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:u})=>i($e,{...u})})]}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]},t)}function dv({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=r.map((g,m)=>({...g,...l[m]})),c=()=>{const g={name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:pt.random().css()},show_in_legend:!1,yAxisIndex:0};a(g)},d=y.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=t("y_axes"),h=y.useMemo(()=>f.map(({name:g},m)=>({label:g,value:m.toString()})),[f]);return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[u.map((g,m)=>i(s.Tabs.Tab,{value:m.toString(),children:m+1},m)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),u.map((g,m)=>i(s.Tabs.Panel,{value:m.toString(),children:i(cv,{control:e,index:m,remove:o,watch:t,variableOptions:d,yAxisOptions:h})},m))]})}const pv=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return i(s.Box,{children:i(De,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},hv=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:a}]=Q.useBoolean(),[o,l]=y.useState(e),u=()=>{a();const{type:h,func_content:g}=o,m={type:h,func_content:g};l(m),t(m)},c=()=>{a(),l(e)},d=h=>{l(g=>({...g,func_content:h}))},f=()=>{d(mn.dynamic.func_content)};return p(B,{children:[i(s.Box,{sx:{width:"50%"},children:i(s.Button,{variant:"filled",mt:24,onClick:r,sx:{flexGrow:0},children:"Setup"})}),i(s.Modal,{size:800,title:"Setup dynamic color",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&p(s.Stack,{children:[i(s.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),i(pv,{value:o.func_content,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:c,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:u,children:"OK"})]})]})]})})]})},fv=({value:e,onChange:t})=>e.type!=="dynamic"?null:i(hv,{value:e,onChange:t}),gv=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=r=>{t({...e,color:r})};return i(s.ColorInput,{label:" ",format:"rgb",value:e.color,onChange:n})},mv=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],yv=y.forwardRef(({label:e="Color",value:t,onChange:n},r)=>{const a=o=>{n({...mn[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:e,data:mv,value:t.type,onChange:a,sx:{flexGrow:1}}),i(gv,{value:t,onChange:n}),i(fv,{value:t,onChange:n})]})}),bv=y.forwardRef(({value:e,onChange:t},n)=>{const r=o=>{t({...e,label:o})},a=o=>{t({...e,tooltip:o})};return p(s.Stack,{ref:n,spacing:0,children:[i(zn,{sectionTitle:"Overflow on Chart",value:e.label,onChange:r}),i(zn,{sectionTitle:"Overflow in Tooltip",value:e.tooltip,onChange:a})]})}),vv=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return i(s.Box,{children:i(De,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Io={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
|
|
277
|
-
`)}},xv=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:a}]=Q.useBoolean(),[o,l]=y.useState(e),u=()=>{a();const{type:h,func_content:g}=o,m={type:h,func_content:g};l(m),t(m)},c=()=>{a(),l(e)},d=h=>{l(g=>({...g,func_content:h}))},f=()=>{d(Io.dynamic.func_content)};return p(B,{children:[i(s.Box,{sx:{width:"50%"},children:i(s.Button,{variant:"filled",mt:24,onClick:r,sx:{flexGrow:0},children:"Setup"})}),i(s.Modal,{size:800,title:"Setup dynamic size",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&p(s.Stack,{children:[i(s.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),i(vv,{value:o.func_content,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:c,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:u,children:"OK"})]})]})]})})]})},wv=({value:e,onChange:t})=>e.type!=="dynamic"?null:i(xv,{value:e,onChange:t}),Cv=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=r=>{t({...e,size:r})};return i(B,{children:i(s.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:e.size,onChange:n})})},Sv=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],_v=y.forwardRef(({label:e="Size",value:t,onChange:n},r)=>{const a=o=>{n({...Io[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:e,data:Sv,value:t.type,onChange:a,sx:{flexGrow:1}}),i(Cv,{value:t,onChange:n}),i(wv,{value:t,onChange:n})]})}),kv=[{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 Tv({control:e,watch:t}){return t(["scatter"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"scatter.name_data_key",control:e,render:({field:n})=>i(W,{label:"Name Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"scatter.y_data_key",control:e,render:({field:n})=>i(W,{label:"Value Data Field",required:!0,sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Style",labelPosition:"center"}),i(v.Controller,{name:"scatter.symbolSize",control:e,render:({field:n})=>i(_v,{label:"Size",...n})}),i(v.Controller,{name:"scatter.color",control:e,render:({field:n})=>i(yv,{...n})}),i(s.Divider,{mb:-15,label:"Label",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"scatter.label_position",control:e,render:({field:n})=>i(s.Select,{label:"Label Position",data:kv,...n})})}),i(v.Controller,{name:"scatter.label_overflow",control:e,render:({field:n})=>i(bv,{...n})})]})}function Dv({control:e,watch:t}){return t("stats"),i(s.Stack,{children:p(s.Stack,{spacing:0,children:[i(v.Controller,{name:"stats.templates.top",control:e,render:({field:n})=>i(on,{label:"Template for stats above the chart",py:"md",sx:{flexGrow:1},...n})}),i(v.Controller,{name:"stats.templates.bottom",control:e,render:({field:n})=>i(on,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const Iv=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),Mv=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(B,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(D.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(Iv,{control:e,index:g,remove:a},h.id)},h.id))]})]})},Av=[{label:"Scatter Point",value:"item"},{label:"X Axis",value:"axis"}];function zv({control:e,watch:t}){return t("tooltip.trigger"),p(s.Stack,{children:[i(v.Controller,{name:"tooltip.trigger",control:e,render:({field:n})=>i(s.Select,{label:"Trigger",data:Av,sx:{flexGrow:1},...n})}),i(s.Divider,{variant:"dashed"}),i(Mv,{control:e,watch:t})]})}const Ev=({disabled:e,value:t,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[e&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(De,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},$v=y.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:a,setFalse:o}]=Q.useBoolean(),[l,u]=y.useState(e);y.useEffect(()=>{u(e)},[e]);const c=m=>{u({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:C}=l,w={enabled:m,func_content:C};u(w),t(w)},f=()=>{o(),u(e)},h=m=>{u(C=>({...C,func_content:m}))},g=()=>{h(So.func_content)};return p(B,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Customize Label"}),i(s.Modal,{size:800,title:"Customize label content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:m=>c(m.currentTarget.checked)}),i(Ev,{value:l.func_content,onChange:h,disabled:!l.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:g,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:d,children:"OK"})]})]})]})})]})});function Lv({control:e,watch:t}){return t(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>i($v,{...n})})]})]})}const Ov=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],Pv=[{label:"left",value:"left"},{label:"right",value:"right"}];function Bv({control:e,index:t,remove:n}){return p(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[i(s.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`y_axes.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`y_axes.${t}.nameAlignment`,control:e,render:({field:r})=>i(s.Select,{label:"Align",required:!0,data:Ov,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`y_axes.${t}.position`,control:e,render:({field:r})=>i(s.Select,{label:"Position",required:!0,data:Pv,sx:{flex:1},...r})})}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:`y_axes.${t}.label_formatter`,control:e,render:({field:r})=>i(We,{...r})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`y_axes.${t}.min`,control:e,render:({field:r})=>i(s.TextInput,{label:"Min",...r})}),i(v.Controller,{name:`y_axes.${t}.max`,control:e,render:({field:r})=>i(s.TextInput,{label:"Max",...r})})]})]}),i(s.Button,{mt:20,leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this YAxis"})]})}function Vv({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"y_axes"}),o=t("y_axes"),l=n.map((c,d)=>({...c,...o[d]})),u=()=>r({name:"",label_formatter:Ie,min:"",max:"",show:!0,position:"right",nameAlignment:"right"});return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[l.map((c,d)=>i(s.Tabs.Tab,{value:d.toString(),children:d+1},d)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((c,d)=>i(s.Tabs.Panel,{value:d.toString(),children:i(Bv,{control:e,index:d,remove:a})},d))]})}function Nv(e){return e||{templates:{top:"",bottom:""}}}function qv({reference_lines:e=[],stats:t,...n}){return{reference_lines:e,stats:Nv(t),...n}}function Fv({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),{variables:r}=e,a=y.useMemo(()=>x.defaultsDeep({},t,hi),[t]),o=y.useMemo(()=>qv(a),[a]);y.useEffect(()=>{!x.isEqual(a,o)&&(console.log("config malformed, resetting to defaults",a,o),n(o))},[a,o]);const{control:l,handleSubmit:u,watch:c,getValues:d,reset:f}=v.useForm({defaultValues:o});y.useEffect(()=>{f(o)},[o]);const h=d(),g=y.useMemo(()=>!x.isEqual(h,a),[h,a]);return c(["dataZoom"]),i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:u(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!g,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axes",children:"Y Axes"}),i(s.Tabs.Tab,{value:"Scatter",children:"Scatter"}),i(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"}),i(s.Tabs.Tab,{value:"Stats",children:"Stats"}),i(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"}),i(s.Tabs.Tab,{value:"Reference Areas",children:"Reference Areas"}),i(s.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(Lv,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Y Axes",children:i(Vv,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Scatter",children:i(Tv,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(zv,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Stats",children:i(Dv,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(dv,{variables:r,control:l,watch:c})}),i(s.Tabs.Panel,{value:"Reference Areas",children:i(ov,{variables:r,control:l,watch:c})}),i(s.Tabs.Panel,{value:"Zooming",children:i(v.Controller,{name:"dataZoom",control:l,render:({field:m})=>i(ri,{...m})})})]})]})})}function Gv(e){const{dataZoom:t=jt,...n}=e;return{...n,dataZoom:t}}function Wv(e){const t={scatter:{label_overflow:_o}};return x.defaultsDeep(t,e)}function jv(e){const{color:t}=e.scatter;return typeof t=="string"?{...e,scatter:{...e.scatter,color:{...mn.static,color:t}}}:e}function Rv(e){const t=e.reference_lines.map(n=>{const{lineStyle:r={type:"dashed",width:1,color:pt.random().css()},show_in_legend:a=!1,yAxisIndex:o=0}=n;return{...n,lineStyle:r,show_in_legend:a,yAxisIndex:o}});return{...e,reference_lines:t}}function Yv(e){const t={tooltip:{trigger:"item"}};return x.defaultsDeep({},e,t)}function Qv(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,scatter:o,tooltip:l,...u}=e;return{...u,x_axis:{...a,data_key:r(a.data_key)},scatter:{...o,y_data_key:r(o.y_data_key),name_data_key:r(o.name_data_key)},tooltip:{...l,metrics:l.metrics.map(c=>({...c,data_key:r(c.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}class Uv extends ge{constructor(){super(...arguments);q(this,"VERSION",9)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{tooltip:r={metrics:[]},...a}=n.config;return{...n,version:2,config:{...a,tooltip:r}}}),this.version(3,n=>({...n,version:3,config:Gv(n.config)})),this.version(4,n=>{const{config:r}=n;return{...n,version:5,config:Wv(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:jv(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:Rv(r)}}),this.version(8,n=>{const{config:r}=n;return{...n,version:8,config:Yv(r)}}),this.version(9,(n,r)=>{const{config:a}=n;return{...n,version:9,config:Qv(a,r)}})}}const Kv={displayName:"Scatter Chart",displayGroup:"ECharts-based charts",migrator:new Uv,name:"scatterChart",viewRender:iv,configRender:Fv,createConfig(){return{version:9,config:x.cloneDeep(hi)}},triggers:[Co]},fi={template:"The variable ${value} is defined in Variables section",vertical_align:"center",horizontal_align:"left"};function Xv(e){if("variables"in e)return e;const{align:t,size:n,weight:r,color:a,content:{prefix:o="",data_field:l="value",formatter:u={output:"number",mantissa:0},postfix:c=""}={}}=e;return{align:t,template:`${o} \${value} ${c}`,variables:[{name:"value",data_field:l,aggregation:{type:"none",config:{}},formatter:u,color:a,weight:r,size:n}]}}function Jv(e){return x.omit(e,["variables"])}function Zv(e){const{align:t,...n}=e;return{horizontal_align:t,vertical_align:"center",...n}}function Hv(e){const t=x.cloneDeep(e),n=x.get(t,"color.valueRange");return n!==void 0&&x.set(t,"color.valueRange",n.map(r=>Number(r))),t}class ex extends ge{constructor(){super(...arguments);q(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:Xv(n)})),this.version(2,(n,{panelModel:r})=>{const{config:a}=n;return(a.variables||[]).forEach(l=>{r.variables.find(u=>u.name===l.name)||r.addVariable(Hv(l))}),{...n,version:2,config:Jv(a)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:Zv(r)}})}}const tx={left:"flex-start",center:"center",right:"flex-end"},nx={top:"flex-start",center:"center",bottom:"flex-end"},rx=k.observer(({context:e})=>{const t=ye(),{value:n=fi}=R(e.instanceData,"config"),{variables:r}=e,{template:a,horizontal_align:o,vertical_align:l}=n,{width:u,height:c}=e.viewport,d=y.useMemo(()=>{try{return x.template(a)(t.payloadForSQL)}catch{return a}},[t.payloadForSQL,a]),f=y.useMemo(()=>gn(d,r,e.data),[d,r,e.data,e]);return i(s.Center,{sx:{width:u,height:c,justifyContent:tx[o],alignItems:nx[l]},children:i(s.Box,{children:Object.values(f).map((h,g)=>i(y.Fragment,{children:h},g))})})}),ix=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],ax=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function sx({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},t,fi),[t]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l(["template","horizontal_align","vertical_align"]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,t),[d,t]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{weight:500,children:"Stats Configurations"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(D.DeviceFloppy,{size:20})})]}),i(v.Controller,{name:"template",control:a,render:({field:h})=>i(on,{label:"Template",py:"md",sx:{flexGrow:1},...h})}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{name:"horizontal_align",control:a,render:({field:h})=>i(s.Select,{label:"Horizontal Alignment",data:ix,...h})}),i(v.Controller,{control:a,name:"vertical_align",render:({field:h})=>i(s.Select,{label:"Vertical Alignment",data:ax,...h})})]})]})})}const ox={createConfig(){return{version:3,config:fi}},displayName:"Stats",displayGroup:"Others",migrator:new ex,name:"stats",viewRender:rx,configRender:sx},gi={label_key:"",value_key:"",group_key:"",levels:[]};function lx(e){const t=new Set(e.map(r=>r.parent_id)),n=new Set(e.map(r=>r.id));return t.forEach(r=>{r===null||n.has(r)||e.push({id:r,name:r,parent_id:null})}),e}function ux(e){const t=lx(e).map(a=>({...a,children:[]})),n=x.keyBy(t,a=>a.id),r=[];return t.forEach(a=>{if(!a.parent_id||!n[a.parent_id]){r.push(a);return}n[a.parent_id].children.push(a)}),r}function cx(e,t){const{label_key:n,value_key:r,group_key:a}=e;if(!n||!r)return[];const o=O(n),l=O(r),u=O(a),c=t[o.queryID].map(d=>({...d,id:d[o.columnKey],parent_id:d[u.columnKey],name:d[o.columnKey],value:d[l.columnKey]?Number(d[l.columnKey]):d[l.columnKey]}));return a?ux(c):c}const dx=e=>({treePathInfo:t,name:n,value:r})=>{if(t.length===1||!e)return n;try{const a=t[t.length-2].value;if(r/a<e)return" "}catch{return n}};function px(e){const{levels:t}=e;return t.map(n=>{const{show_label_tolerance:r,...a}=n.label;return{...n,label:{...a,formatter:dx(r)}}})}function hx(){return({treePathInfo:e,name:t,value:n,color:r,marker:a,...o})=>{const l=e.slice(0,e.length-1),u=[`<tr>
|
|
276
|
+
`}}}function tv(e,t){const n=t.every(a=>!Number.isNaN(Number(a))),{axisLabel:r}=e.x_axis;return[{data:t,name:e.x_axis.name??"",id:"main-x-axis",axisTick:{show:!0,alignWithLabel:!0},type:n?"value":"category",axisLabel:{...r,formatter:Do(r.formatter)}}]}function nv(e,t){return e.y_axes.map(({nameAlignment:n,min:r,max:a,...o},l)=>{let u=o.position;return u||(u=l>0?"right":"left"),{...o,minInterval:1,min:r||void 0,max:a||void 0,position:u,axisLabel:{show:!0,formatter:t[l]??t.default},axisLine:{show:!0},nameTextStyle:{fontWeight:"bold",align:n},nameLocation:"end",nameGap:15,splitLine:{show:!1}}})}const rv={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 iv(e,t,n){const r=n.reduce((c,d)=>{const f=mt(d,t);return c[d.name]=Ze(d,f),c},{}),a=e.y_axes.reduce((c,{label_formatter:d},f)=>(c[f]=function(g){let m=g;if(typeof g=="object"&&(Array.isArray(g.value)&&g.value.length===2?m=g.value[1]:m=g.value),!d)return m;try{return Z(m).format(d)}catch(C){return console.error(C),m}},c),{default:({value:c})=>c}),o=x.uniq(ft(t,e.x_axis.data_key)),l=Jb(e,t,n,r),u={xAxis:tv(e,o),yAxis:nv(e,a),series:l,dataset:Wb(e,t),tooltip:ev(e,a),grid:jb(e),legend:Rb(),dataZoom:ti(e.dataZoom)};return x.defaultsDeep({},u,rv)}ie.use([F.DataZoomComponent,he.BarChart,he.LineChart,he.ScatterChart,F.GridComponent,F.LegendComponent,F.TooltipComponent,Ee.CanvasRenderer,F.MarkLineComponent,F.MarkAreaComponent]);function Mo(e){return e.trim().length>0}function av({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=zt(t,e.x_axis.data_key),u=Ke(a.triggerManager,_o.id),c=y.useCallback(h=>{const g=h.data;u.forEach(m=>{a.runInteraction(m.id,{...h,rowData:g})})},[l,u,a]),d=y.useMemo(()=>({click:c}),[c]),f=y.useMemo(()=>iv(e,t,o),[e,t]);return i(ze,{echarts:ie,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function sv({context:e,instance:t}){const n=Xe({vizManager:e.vizManager,instance:t}),{value:r}=R(e.instanceData,"config"),{variables:a}=e,o=y.useMemo(()=>x.defaults({},r,hi),[r]),l=e.data,{width:u,height:c}=e.viewport,{ref:d,height:f}=ke.useElementSize(),{ref:h,height:g}=ke.useElementSize(),m=y.useMemo(()=>{const{stats:{templates:w}}=o;return{top:gn(w.top,a,l),bottom:gn(w.bottom,a,l)}},[o,l]),C=Math.max(0,nt(c)-f-g);return!u||!c?null:p(Ve,{width:u,height:c,children:[i(s.Text,{ref:d,align:"left",size:"xs",pl:"sm",sx:{display:Mo(o.stats.templates.top)?"block":"none"},children:Object.values(m.top).map(w=>w)}),i(av,{variables:a,width:tt(u),height:C,data:l,conf:o,interactionManager:n}),i(s.Text,{ref:h,align:"left",size:"xs",pl:"sm",sx:{display:Mo(o.stats.templates.bottom)?"block":"none"},children:Object.values(m.bottom).map(w=>w)})]})}const ov=y.forwardRef(({value:e,onChange:t,xAxisOptions:n,yAxisOptions:r,variableOptions:a},o)=>{const l=(u,c)=>{const d=x.cloneDeep(e);x.set(d,u,c),t(d)};return p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Content",labelPosition:"right"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(s.TextInput,{label:"Content Text",value:e.content.text,onChange:u=>l("content.text",u.currentTarget.value)}),i(si,{label:"Text Position",value:e.label.position,onChange:u=>l("label.position",u)})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Endpoints",labelPosition:"right"}),p(s.Group,{grow:!0,noWrap:!0,children:[n&&i(s.Select,{label:"X Axis",data:n,value:e.xAxisIndex,onChange:u=>l("xAxisIndex",u)}),r&&i(s.Select,{label:"Y Axis",data:r,value:e.yAxisIndex,onChange:u=>l("xAxisIndex",u)})]}),p(s.Stack,{spacing:0,children:[i(s.Text,{size:14,color:"#212529",fw:500,children:"Left-Bottom Point"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(s.Select,{icon:i(s.Text,{children:"x"}),data:a,value:e.leftBottomPoint.x_data_key,onChange:u=>l("leftBottomPoint.x_data_key",u??""),clearable:!0}),i(s.Select,{icon:i(s.Text,{children:"y"}),data:a,value:e.leftBottomPoint.y_data_key,onChange:u=>l("leftBottomPoint.y_data_key",u??""),clearable:!0})]})]}),p(s.Stack,{spacing:0,children:[i(s.Text,{size:14,color:"#212529",fw:500,children:"Right-Top Point"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(s.Select,{icon:i(s.Text,{children:"x"}),data:a,value:e.rightTopPoint.x_data_key,onChange:u=>l("rightTopPoint.x_data_key",u??""),clearable:!0}),i(s.Select,{icon:i(s.Text,{children:"y"}),data:a,value:e.rightTopPoint.y_data_key,onChange:u=>l("rightTopPoint.y_data_key",u??""),clearable:!0})]})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Style",labelPosition:"right"}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:14,children:"Background Color"}),i($e,{value:e.itemStyle.color,onChange:u=>l("itemStyle.color",u)})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:14,children:"Text Color"}),i($e,{value:e.label.color,onChange:u=>l("label.color",u)})]})]})});function lv(){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 uv({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_areas"}),l=t("reference_areas"),u=r.map((g,m)=>({...g,...l[m]})),c=()=>{const g=lv();a(g)},d=y.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=t("y_axes"),h=y.useMemo(()=>f.map(({name:g},m)=>({label:g,value:m.toString()})),[f]);return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[u.map((g,m)=>i(s.Tabs.Tab,{value:m.toString(),children:m+1},m)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),u.map((g,m)=>i(s.Tabs.Panel,{value:m.toString(),children:i(v.Controller,{name:`reference_areas.${m}`,control:e,render:({field:C})=>p(s.Stack,{children:[i(ov,{variableOptions:d,yAxisOptions:h,...C}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(E.IconTrash,{size:16}),color:"red",variant:"light",onClick:()=>o(m),children:"Delete this Reference Area"})]})})},m))]})}const cv=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],dv=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function pv({control:e,index:t,remove:n,watch:r,variableOptions:a,yAxisOptions:o}){const l=r(`reference_lines.${t}.orientation`);return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:u})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:u})=>i(s.Select,{label:"Value",required:!0,data:a,sx:{flex:1},...u})})]}),i(v.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:u})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...u})}),p(s.Group,{grow:!0,children:[p(s.Stack,{children:[i(v.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:u})=>i(s.Select,{label:"Orientation",data:dv,required:!0,sx:{flex:1},...u})}),l==="vertical"&&i(s.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&i(v.Controller,{name:`reference_lines.${t}.yAxisIndex`,control:e,render:({field:{value:u,onChange:c,...d}})=>i(s.Select,{label:"Y Axis",data:o,disabled:o.length===0,...d,value:(u==null?void 0:u.toString())??"",onChange:f=>{if(!f){c(0);return}c(Number(f))},sx:{flex:1}})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:u})=>i(s.Select,{label:"Line Type",data:cv,sx:{flexGrow:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:u})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...u})})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:u})=>i($e,{...u})})]}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]},t)}function hv({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=r.map((g,m)=>({...g,...l[m]})),c=()=>{const g={name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:pt.random().css()},show_in_legend:!1,yAxisIndex:0};a(g)},d=y.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=t("y_axes"),h=y.useMemo(()=>f.map(({name:g},m)=>({label:g,value:m.toString()})),[f]);return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[u.map((g,m)=>i(s.Tabs.Tab,{value:m.toString(),children:m+1},m)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),u.map((g,m)=>i(s.Tabs.Panel,{value:m.toString(),children:i(pv,{control:e,index:m,remove:o,watch:t,variableOptions:d,yAxisOptions:h})},m))]})}const fv=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return i(s.Box,{children:i(De,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},gv=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:a}]=Q.useBoolean(),[o,l]=y.useState(e),u=()=>{a();const{type:h,func_content:g}=o,m={type:h,func_content:g};l(m),t(m)},c=()=>{a(),l(e)},d=h=>{l(g=>({...g,func_content:h}))},f=()=>{d(mn.dynamic.func_content)};return p(B,{children:[i(s.Box,{sx:{width:"50%"},children:i(s.Button,{variant:"filled",mt:24,onClick:r,sx:{flexGrow:0},children:"Setup"})}),i(s.Modal,{size:800,title:"Setup dynamic color",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&p(s.Stack,{children:[i(s.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),i(fv,{value:o.func_content,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:c,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:u,children:"OK"})]})]})]})})]})},mv=({value:e,onChange:t})=>e.type!=="dynamic"?null:i(gv,{value:e,onChange:t}),yv=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=r=>{t({...e,color:r})};return i(s.ColorInput,{label:" ",format:"rgb",value:e.color,onChange:n})},bv=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],vv=y.forwardRef(({label:e="Color",value:t,onChange:n},r)=>{const a=o=>{n({...mn[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:e,data:bv,value:t.type,onChange:a,sx:{flexGrow:1}}),i(yv,{value:t,onChange:n}),i(mv,{value:t,onChange:n})]})}),xv=y.forwardRef(({value:e,onChange:t},n)=>{const r=o=>{t({...e,label:o})},a=o=>{t({...e,tooltip:o})};return p(s.Stack,{ref:n,spacing:0,children:[i(zn,{sectionTitle:"Overflow on Chart",value:e.label,onChange:r}),i(zn,{sectionTitle:"Overflow in Tooltip",value:e.tooltip,onChange:a})]})}),wv=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return i(s.Box,{children:i(De,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Ao={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
|
|
277
|
+
`)}},Cv=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:a}]=Q.useBoolean(),[o,l]=y.useState(e),u=()=>{a();const{type:h,func_content:g}=o,m={type:h,func_content:g};l(m),t(m)},c=()=>{a(),l(e)},d=h=>{l(g=>({...g,func_content:h}))},f=()=>{d(Ao.dynamic.func_content)};return p(B,{children:[i(s.Box,{sx:{width:"50%"},children:i(s.Button,{variant:"filled",mt:24,onClick:r,sx:{flexGrow:0},children:"Setup"})}),i(s.Modal,{size:800,title:"Setup dynamic size",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&p(s.Stack,{children:[i(s.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),i(wv,{value:o.func_content,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:c,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:u,children:"OK"})]})]})]})})]})},Sv=({value:e,onChange:t})=>e.type!=="dynamic"?null:i(Cv,{value:e,onChange:t}),_v=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=r=>{t({...e,size:r})};return i(B,{children:i(s.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:e.size,onChange:n})})},kv=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Tv=y.forwardRef(({label:e="Size",value:t,onChange:n},r)=>{const a=o=>{n({...Ao[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:e,data:kv,value:t.type,onChange:a,sx:{flexGrow:1}}),i(_v,{value:t,onChange:n}),i(Sv,{value:t,onChange:n})]})}),Dv=[{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 Iv({control:e,watch:t}){return t(["scatter"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"scatter.name_data_key",control:e,render:({field:n})=>i(W,{label:"Name Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"scatter.y_data_key",control:e,render:({field:n})=>i(W,{label:"Value Data Field",required:!0,sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Style",labelPosition:"center"}),i(v.Controller,{name:"scatter.symbolSize",control:e,render:({field:n})=>i(Tv,{label:"Size",...n})}),i(v.Controller,{name:"scatter.color",control:e,render:({field:n})=>i(vv,{...n})}),i(s.Divider,{mb:-15,label:"Label",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"scatter.label_position",control:e,render:({field:n})=>i(s.Select,{label:"Label Position",data:Dv,...n})})}),i(v.Controller,{name:"scatter.label_overflow",control:e,render:({field:n})=>i(xv,{...n})})]})}function Mv({control:e,watch:t}){return t("stats"),i(s.Stack,{children:p(s.Stack,{spacing:0,children:[i(v.Controller,{name:"stats.templates.top",control:e,render:({field:n})=>i(on,{label:"Template for stats above the chart",py:"md",sx:{flexGrow:1},...n})}),i(v.Controller,{name:"stats.templates.bottom",control:e,render:({field:n})=>i(on,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const Av=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),zv=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(B,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(D.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(Av,{control:e,index:g,remove:a},h.id)},h.id))]})]})},Ev=[{label:"Scatter Point",value:"item"},{label:"X Axis",value:"axis"}];function $v({control:e,watch:t}){return t("tooltip.trigger"),p(s.Stack,{children:[i(v.Controller,{name:"tooltip.trigger",control:e,render:({field:n})=>i(s.Select,{label:"Trigger",data:Ev,sx:{flexGrow:1},...n})}),i(s.Divider,{variant:"dashed"}),i(zv,{control:e,watch:t})]})}const Lv=({disabled:e,value:t,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[e&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(De,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},Ov=y.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:a,setFalse:o}]=Q.useBoolean(),[l,u]=y.useState(e);y.useEffect(()=>{u(e)},[e]);const c=m=>{u({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:C}=l,w={enabled:m,func_content:C};u(w),t(w)},f=()=>{o(),u(e)},h=m=>{u(C=>({...C,func_content:m}))},g=()=>{h(ko.func_content)};return p(B,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Customize Label"}),i(s.Modal,{size:800,title:"Customize label content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:m=>c(m.currentTarget.checked)}),i(Lv,{value:l.func_content,onChange:h,disabled:!l.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:g,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:d,children:"OK"})]})]})]})})]})});function Pv({control:e,watch:t}){return t(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>i(Ov,{...n})})]})]})}const Bv=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],Vv=[{label:"left",value:"left"},{label:"right",value:"right"}];function Nv({control:e,index:t,remove:n}){return p(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[i(s.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`y_axes.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`y_axes.${t}.nameAlignment`,control:e,render:({field:r})=>i(s.Select,{label:"Align",required:!0,data:Bv,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`y_axes.${t}.position`,control:e,render:({field:r})=>i(s.Select,{label:"Position",required:!0,data:Vv,sx:{flex:1},...r})})}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:`y_axes.${t}.label_formatter`,control:e,render:({field:r})=>i(We,{...r})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`y_axes.${t}.min`,control:e,render:({field:r})=>i(s.TextInput,{label:"Min",...r})}),i(v.Controller,{name:`y_axes.${t}.max`,control:e,render:({field:r})=>i(s.TextInput,{label:"Max",...r})})]})]}),i(s.Button,{mt:20,leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this YAxis"})]})}function qv({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"y_axes"}),o=t("y_axes"),l=n.map((c,d)=>({...c,...o[d]})),u=()=>r({name:"",label_formatter:Ie,min:"",max:"",show:!0,position:"right",nameAlignment:"right"});return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[l.map((c,d)=>i(s.Tabs.Tab,{value:d.toString(),children:d+1},d)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((c,d)=>i(s.Tabs.Panel,{value:d.toString(),children:i(Nv,{control:e,index:d,remove:a})},d))]})}function Fv(e){return e||{templates:{top:"",bottom:""}}}function Gv({reference_lines:e=[],stats:t,...n}){return{reference_lines:e,stats:Fv(t),...n}}function Wv({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),{variables:r}=e,a=y.useMemo(()=>x.defaultsDeep({},t,hi),[t]),o=y.useMemo(()=>Gv(a),[a]);y.useEffect(()=>{!x.isEqual(a,o)&&(console.log("config malformed, resetting to defaults",a,o),n(o))},[a,o]);const{control:l,handleSubmit:u,watch:c,getValues:d,reset:f}=v.useForm({defaultValues:o});y.useEffect(()=>{f(o)},[o]);const h=d(),g=y.useMemo(()=>!x.isEqual(h,a),[h,a]);return c(["dataZoom"]),i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:u(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!g,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axes",children:"Y Axes"}),i(s.Tabs.Tab,{value:"Scatter",children:"Scatter"}),i(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"}),i(s.Tabs.Tab,{value:"Stats",children:"Stats"}),i(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"}),i(s.Tabs.Tab,{value:"Reference Areas",children:"Reference Areas"}),i(s.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(Pv,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Y Axes",children:i(qv,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Scatter",children:i(Iv,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Tooltip",children:i($v,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Stats",children:i(Mv,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(hv,{variables:r,control:l,watch:c})}),i(s.Tabs.Panel,{value:"Reference Areas",children:i(uv,{variables:r,control:l,watch:c})}),i(s.Tabs.Panel,{value:"Zooming",children:i(v.Controller,{name:"dataZoom",control:l,render:({field:m})=>i(ri,{...m})})})]})]})})}function jv(e){const{dataZoom:t=jt,...n}=e;return{...n,dataZoom:t}}function Rv(e){const t={scatter:{label_overflow:To}};return x.defaultsDeep(t,e)}function Yv(e){const{color:t}=e.scatter;return typeof t=="string"?{...e,scatter:{...e.scatter,color:{...mn.static,color:t}}}:e}function Qv(e){const t=e.reference_lines.map(n=>{const{lineStyle:r={type:"dashed",width:1,color:pt.random().css()},show_in_legend:a=!1,yAxisIndex:o=0}=n;return{...n,lineStyle:r,show_in_legend:a,yAxisIndex:o}});return{...e,reference_lines:t}}function Uv(e){const t={tooltip:{trigger:"item"}};return x.defaultsDeep({},e,t)}function Kv(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,scatter:o,tooltip:l,...u}=e;return{...u,x_axis:{...a,data_key:r(a.data_key)},scatter:{...o,y_data_key:r(o.y_data_key),name_data_key:r(o.name_data_key)},tooltip:{...l,metrics:l.metrics.map(c=>({...c,data_key:r(c.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}class Xv extends ge{constructor(){super(...arguments);q(this,"VERSION",9)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{tooltip:r={metrics:[]},...a}=n.config;return{...n,version:2,config:{...a,tooltip:r}}}),this.version(3,n=>({...n,version:3,config:jv(n.config)})),this.version(4,n=>{const{config:r}=n;return{...n,version:5,config:Rv(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:Yv(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:Qv(r)}}),this.version(8,n=>{const{config:r}=n;return{...n,version:8,config:Uv(r)}}),this.version(9,(n,r)=>{const{config:a}=n;return{...n,version:9,config:Kv(a,r)}})}}const Jv={displayName:"Scatter Chart",displayGroup:"ECharts-based charts",migrator:new Xv,name:"scatterChart",viewRender:sv,configRender:Wv,createConfig(){return{version:9,config:x.cloneDeep(hi)}},triggers:[_o]},fi={template:"The variable ${value} is defined in Variables section",vertical_align:"center",horizontal_align:"left"};function Zv(e){if("variables"in e)return e;const{align:t,size:n,weight:r,color:a,content:{prefix:o="",data_field:l="value",formatter:u={output:"number",mantissa:0},postfix:c=""}={}}=e;return{align:t,template:`${o} \${value} ${c}`,variables:[{name:"value",data_field:l,aggregation:{type:"none",config:{}},formatter:u,color:a,weight:r,size:n}]}}function Hv(e){return x.omit(e,["variables"])}function ex(e){const{align:t,...n}=e;return{horizontal_align:t,vertical_align:"center",...n}}function tx(e){const t=x.cloneDeep(e),n=x.get(t,"color.valueRange");return n!==void 0&&x.set(t,"color.valueRange",n.map(r=>Number(r))),t}class nx extends ge{constructor(){super(...arguments);q(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:Zv(n)})),this.version(2,(n,{panelModel:r})=>{const{config:a}=n;return(a.variables||[]).forEach(l=>{r.variables.find(u=>u.name===l.name)||r.addVariable(tx(l))}),{...n,version:2,config:Hv(a)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:ex(r)}})}}const rx={left:"flex-start",center:"center",right:"flex-end"},ix={top:"flex-start",center:"center",bottom:"flex-end"},ax=k.observer(({context:e})=>{const t=ye(),{value:n=fi}=R(e.instanceData,"config"),{variables:r}=e,{template:a,horizontal_align:o,vertical_align:l}=n,{width:u,height:c}=e.viewport,d=y.useMemo(()=>{try{return x.template(a)(t.payloadForSQL)}catch{return a}},[t.payloadForSQL,a]),f=y.useMemo(()=>gn(d,r,e.data),[d,r,e.data,e]);return i(s.Center,{sx:{width:u,height:c,justifyContent:rx[o],alignItems:ix[l]},children:i(s.Box,{children:Object.values(f).map((h,g)=>i(y.Fragment,{children:h},g))})})}),sx=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],ox=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function lx({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},t,fi),[t]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l(["template","horizontal_align","vertical_align"]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,t),[d,t]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{weight:500,children:"Stats Configurations"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(D.DeviceFloppy,{size:20})})]}),i(v.Controller,{name:"template",control:a,render:({field:h})=>i(on,{label:"Template",py:"md",sx:{flexGrow:1},...h})}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{name:"horizontal_align",control:a,render:({field:h})=>i(s.Select,{label:"Horizontal Alignment",data:sx,...h})}),i(v.Controller,{control:a,name:"vertical_align",render:({field:h})=>i(s.Select,{label:"Vertical Alignment",data:ox,...h})})]})]})})}const ux={createConfig(){return{version:3,config:fi}},displayName:"Stats",displayGroup:"Others",migrator:new nx,name:"stats",viewRender:ax,configRender:lx},gi={label_key:"",value_key:"",group_key:"",levels:[]};function cx(e){const t=new Set(e.map(r=>r.parent_id)),n=new Set(e.map(r=>r.id));return t.forEach(r=>{r===null||n.has(r)||e.push({id:r,name:r,parent_id:null})}),e}function dx(e){const t=cx(e).map(a=>({...a,children:[]})),n=x.keyBy(t,a=>a.id),r=[];return t.forEach(a=>{if(!a.parent_id||!n[a.parent_id]){r.push(a);return}n[a.parent_id].children.push(a)}),r}function px(e,t){const{label_key:n,value_key:r,group_key:a}=e;if(!n||!r)return[];const o=O(n),l=O(r),u=O(a),c=t[o.queryID].map(d=>({...d,id:d[o.columnKey],parent_id:d[u.columnKey],name:d[o.columnKey],value:d[l.columnKey]?Number(d[l.columnKey]):d[l.columnKey]}));return a?dx(c):c}const hx=e=>({treePathInfo:t,name:n,value:r})=>{if(t.length===1||!e)return n;try{const a=t[t.length-2].value;if(r/a<e)return" "}catch{return n}};function fx(e){const{levels:t}=e;return t.map(n=>{const{show_label_tolerance:r,...a}=n.label;return{...n,label:{...a,formatter:hx(r)}}})}function gx(){return({treePathInfo:e,name:t,value:n,color:r,marker:a,...o})=>{const l=e.slice(0,e.length-1),u=[`<tr>
|
|
278
278
|
<th style="text-align: right; padding: 0 1em;">Value</th>
|
|
279
279
|
<td style="text-align: left; padding: 0 1em;">${n}</td>
|
|
280
280
|
</tr>
|
|
@@ -292,9 +292,9 @@ Check the top-level render call using <`+V+">.")}return z}}function Tu(S,z){{if(
|
|
|
292
292
|
<table style="width: auto">
|
|
293
293
|
<tbody>${u.join("")}</tbody>
|
|
294
294
|
</table>
|
|
295
|
-
`}}function
|
|
296
|
-
`),Ao={columns:[],fontSize:"14px",highlightOnHover:!0,horizontalSpacing:"14px",id_field:"",striped:!0,use_raw_columns:!0,verticalSpacing:"14px"},zo={left:"flex-start",center:"center",right:"flex-end"},Ax=({header:e,cx:t})=>{const n=x.get(e.column.columnDef.meta,"align","left");return p(s.Text,{className:t("table-head-cell",{"table-head-cell--sortable":e.column.getCanSort()}),onClick:e.column.getToggleSortingHandler(),align:n,sx:{justifyContent:zo[n]},children:[e.isPlaceholder?null:et.flexRender(e.column.columnDef.header,e.getContext()),i(zx,{direction:e.column.getIsSorted()})]})},zx=({direction:e})=>{switch(e){case"asc":return i(E.IconArrowUp,{size:16});case"desc":return i(E.IconArrowDown,{size:"1em"});default:return null}},Ex=s.createStyles(e=>({root:{overflow:"auto",position:"relative","& .table-head-cell":{display:"flex",flexFlow:"row nowrap",alignItems:"center",whiteSpace:"nowrap","&.table-head-cell--sortable":{cursor:"pointer",userSelect:"none"}},"&.table-highlight-on-hover tr":{transition:"background-color 0.2s","&:hover":{backgroundColor:e.colorScheme==="dark"?e.colors.dark[5]:e.colors.gray[0]}}},thead:{background:e.colorScheme==="dark"?e.colors.dark[7]:e.white,position:"sticky",top:24,transform:"translateY(-1px)",zIndex:10},info_bar:{position:"sticky",top:0,left:0,right:0,zIndex:10,background:"white"}})),$x={tableLayout:"fixed","thead, tbody":{tr:{"th, td":{padding:"2px 10px",div:{overflow:"hidden",textOverflow:"ellipsis"},"&:first-of-type":{paddingLeft:2,paddingRight:2}}}}},Lx=s.createStyles((e,t)=>({content:{display:"flex",alignItems:"center",justifyContent:zo[t.align],".table-cell-text":{whiteSpace:"nowrap",cursor:t.clickable?"pointer":"default",textDecoration:t.clickable?"underline":"none"}}}));function Ox(e){return e?pt(e).oklch()[0]>.7?"black":"white":"inherit"}function Px(e){const t=e.tableCellContext.bgColor;return{backgroundColor:t,color:Ox(t)}}function Qt(e){const t=e.tableCellContext.isClickable(),n=Lx({clickable:t,align:e.align});return i("div",{className:n.classes.content,style:{...Px(e)},children:i(s.Text,{className:"table-cell-text",onClick:e.tableCellContext.getClickHandler(),children:i("span",{title:e.children,children:e.children})})})}function Bx(e){return i(Qt,{...e,children:e.value})}function Vx(e){const t=Z(e.value).format({average:!0,mantissa:2,trimMantissa:!0});return i(Qt,{...e,children:t})}function Nx(e){const t=Z(e.value).format({thousandSeparated:!0});return i(Qt,{...e,children:t})}function qx(e){const t=Z(e.value).format({output:"percent",mantissa:3,trimMantissa:!0});return i(Qt,{...e,children:t})}function Fx(e){const t=e.value,n=e.func_content;if(!n)return i(Qt,{...e,children:t});const r=new Function(`return ${n}`)()({value:t});return i(Qt,{...e,children:r})}function Gx(e){switch(e.type){case at.string:return i(Bx,{...e});case at.eloc:return i(Vx,{...e});case at.number:return i(Nx,{...e});case at.percentage:return i(qx,{...e});case at.custom:return i(Fx,{...e})}}function Wx({tableContainerRef:e,rows:t}){var u,c;const n=Lu.useVirtual({parentRef:e,size:t.length,estimateSize:y.useCallback(()=>28,[]),overscan:20}),{virtualItems:r,totalSize:a}=n,o=r.length>0&&((u=r==null?void 0:r[0])==null?void 0:u.start)||0,l=r.length>0?a-(((c=r==null?void 0:r[r.length-1])==null?void 0:c.end)||0):0;return Q.useWhyDidYouUpdate("TableBody",{tableContainerRef:e,rows:t}),p("tbody",{children:[o>0&&i("tr",{children:i("td",{style:{height:`${o}px`}})}),r.map(d=>{const f=t[d.index];return i("tr",{children:f.getVisibleCells().map(h=>i("td",{children:et.flexRender(h.column.columnDef.cell,h.getContext())},h.id))},f.id)}),l>0&&i("tr",{children:i("td",{style:{height:`${l}px`}})})]})}const mi={id:"builtin:table:click-cell-content",displayName:"Click Cell Content",nameRender:Qx,configRender:Rx,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"}]},jx={column:""};function Eo(e,t){const{value:n}=R(e.instanceData,"config"),r={columnsFromConfig:[],columnsFromData:[]};if(n&&(r.columnsFromConfig=n.columns.map((a,o)=>({label:a.label,value:o.toString()}))),!t)return r;if(n!=null&&n.id_field){const a=sn(t,n.id_field);(a==null?void 0:a.length)>0&&(r.columnsFromData=Object.keys(a[0]).map(o=>({label:o,value:o})))}return r}function Rx(e){const{columnsFromConfig:t,columnsFromData:n}=Eo(e.instance,e.sampleData),r=t.length>0?t:n,{value:a,set:o}=R(e.trigger.triggerData,"config"),{column:l}=x.defaults({},a,jx),u=c=>{isNaN(+c)?o({column:c}):o({column:+c})};return i(s.Select,{clearable:!1,data:r,label:"Choose a column",value:l.toString(),onChange:u})}function Yx(e,t){return e?x.isNumber(e.column)?`Click cell of ${t[e.column].label}`:`Click cell of ${e.column}`:"Click cell content (click to config)"}function Qx(e){const{columnsFromConfig:t}=Eo(e.instance),{value:n}=R(e.trigger.triggerData,"config");return i(s.Text,{children:Yx(n,t)})}function $o(e,t,n){return Math.min(Math.max(e,t),n)}class Ux{constructor(t){this.steps=t;const n=[],r=new Set;for(const a of t)r.has(a.to)||(n.push(a),r.add(a.to));if(n.sort((a,o)=>a.from-o.from),n.length<2)throw new Error("MultiStepValueMapper requires at least 2 steps");this.steps=n}getLinearFunction(t,n){const r=(n.to-t.to)/(n.from-t.from),a=t.to-r*t.from;return o=>r*o+a}getStepFunctionForValue(t){let n=x.findLastIndex(this.steps,r=>r.from<=t);return n=$o(n,0,this.steps.length-2),this.getLinearFunction(this.steps[n],this.steps[n+1])}mapValue(t){return $o(this.getStepFunctionForValue(t)(t),0,100)}}class Kx{constructor(t,n,r,a,o){this.getColIndex=t,this.cell=n,this.triggers=r,this.interactionManager=a,this.colorManager=o}getClickHandler(){const t=this.getRelatedTrigger();if(t.length!==0)return()=>{const n={row_data:this.cell.row.original,row_index:this.cell.row.index,col_index:this.getColIndex(this.cell)};for(const r of t)this.interactionManager.runInteraction(r.id,n)}}getRelatedTrigger(){return this.triggers.filter(n=>n.schemaRef===mi.id).filter(n=>{const r=this.getColIndex(this.cell),a=x.get(this.cell.column.columnDef.meta,"value_field"),o=x.get(n.config,"column");return o==r||o==a})}isClickable(){return this.getRelatedTrigger().length>0}get columnConf(){return this.cell.column.columnDef.meta}get bgColor(){const t=this.columnConf.cellBackgroundColor;if(!t||t==="none")return;if(x.isString(t))return t;const n=+this.cell.getValue();if(isFinite(n)){const r=this.colorManager.decodeInterpolation(t.interpolation),o=new Ux(t.steps).mapValue(n);return r==null?void 0:r.getColor(o)}}}const Xx=e=>{const t=Xe(e),n=Ke(t.triggerManager,mi.id),{colorManager:r}=y.useContext(ct);return y.useCallback(a=>new Kx(e.getColIndex,a,n,t,r),[n,t,e.getColIndex])};function Jx({queryData:e,width:t,height:n,conf:r,context:a,instance:o}){const{id_field:l,use_raw_columns:u,columns:c,...d}=r,{classes:f,cx:h}=Ex(),g=y.useMemo(()=>u?!Array.isArray(e)||e.length===0?[]:Object.keys(e[0]).map(N=>({id:N,label:N,value_field:N,value_type:at.string,align:"left",width:"",cellBackgroundColor:""})):c,[u,c,e]),m=Xx({getColIndex:y.useCallback(N=>g.indexOf(N.column.columnDef.meta),[g]),vizManager:a.vizManager,instance:o}),C=y.useMemo(()=>{const N=et.createColumnHelper();return g.map(Y=>{const H=fc(Y.value_field);return N.accessor(H.columnKey,{cell:se=>i(Gx,{tableCellContext:m(se.cell),value:se.getValue(),type:Y.value_type,...Y}),header:Y.label,enableSorting:!0,meta:Y,size:typeof Y.width=="number"?Y.width:void 0,minSize:typeof Y.width=="number"?Y.width:void 0})})},[g,m]),[w,_]=y.useState([]),T=et.useReactTable({data:e,state:{sorting:w},onSortingChange:_,columns:C,getCoreRowModel:et.getCoreRowModel(),getSortedRowModel:et.getSortedRowModel()}),{rows:M}=T.getRowModel(),P=y.useRef(null),G=M.length,$=G>0,L=$?n-22:n,A=$?22:0;return Q.useWhyDidYouUpdate("VizTableComponent",{queryData:e,width:t,height:n,conf:r,context:a,instance:o,finalColumns:g,getCellContext:m,tableColumns:C,table:T,rows:M,tableContainerRef:P}),p("div",{ref:P,style:{height:n,width:t,padding:"0 5px"},"data-enable-scrollbar":!0,className:h(f.root,{"table-highlight-on-hover":r.highlightOnHover}),children:[G>0&&i(s.Box,{className:f.info_bar,sx:{height:22},children:p(s.Text,{align:"right",pr:6,size:14,color:"dimmed",fw:"normal",children:["Total: ",G]})}),p(s.Table,{sx:{...$x,maxHeight:L},...d,striped:r.striped,children:[i("thead",{className:f.thead,style:{top:A},children:T.getHeaderGroups().map(N=>i("tr",{children:N.headers.map(K=>i("th",{style:{width:K.getSize()},children:i(Ax,{header:K,cx:h})},K.id))},N.id))}),i(Wx,{tableContainerRef:P,rows:M})]})]})}function Zx({data:e,width:t,height:n,conf:r,context:a,instance:o}){const{id_field:l,use_raw_columns:u,columns:c}=r,d=y.useMemo(()=>{if(!l)return[];const f=O(l);return e[f.queryID]},[e,l]);return!Array.isArray(d)||d.length===0?i(s.Text,{color:"gray",align:"center",children:"Empty Data"}):i(Jx,{queryData:d,width:t,height:n,conf:r,context:a,instance:o})}function Hx({context:e,instance:t}){const n=e.data,{height:r,width:a}=e.viewport,{value:o}=R(e.instanceData,"config");return o?o.id_field?i(Zx,{data:n,width:a,height:r,conf:o,context:e,instance:t}):i(s.Text,{color:"red",align:"center",children:"ID Field is not set, can't render a table without it"}):null}const Lo=s.createStyles(()=>({palette:{display:"flex",flexFlow:"row nowrap"},paletteItem:{".palette-value":{height:24,overflow:"visible",width:36},".palette-item":{width:"36px",height:36*.618,cursor:"pointer",transition:"transform 100ms ease-in-out","&:hover":{boxShadow:"0 0 0 2px var(--shadow-color)",borderRadius:2,transform:"scale(1.2)"}}}})),ew=[{from:0,to:0},{from:100,to:100}];class tw{constructor(){q(this,"steps",new Map);q(this,"interpolation");q(this,"onChange");te.makeAutoObservable(this,{steps:te.observable},{deep:!1}),te.reaction(()=>te.toJS(this.steps),()=>{this.notifyStepChange()})}setSteps(t){for(const n of t)this.steps.set(n.to,n.from)}notifyStepChange(){var t;(t=this.onChange)==null||t.call(this,Array.from(this.steps.entries()).map(([n,r])=>({to:n,from:r})).sort((n,r)=>n.to-r.to||n.from-r.from))}fromProps(t){t.steps.length<2?this.setSteps(ew):this.setSteps(t.steps),this.interpolation=t.interpolation,this.onChange=t.onChange}changeStep(t,n){t==null?this.steps.delete(n):this.steps.set(n,t)}getStepFromValue(t){return this.steps.get(t)}}function nw(e){const{onChange:t,color:n,index:r,value:a}=e,{classes:o}=Lo(),[l,u]=y.useState(a),[c,{setTrue:d,setFalse:f}]=Q.useBoolean(!1),h=r%2===1,g=h&&a!=null,m=!h&&a!=null,C=`map ${a} to color ${r}`,w=()=>{u(a),f()},_=()=>{f(),t==null||t(l)},T=Z(a).format({average:!0});return p("div",{"data-testid":`palette-item-${r}`,className:o.paletteItem,children:[i(s.Text,{title:C,style:{opacity:g?1:0},color:"dimmed",size:"sm",className:"palette-value--up palette-value",children:T}),p(s.Popover,{width:200,trapFocus:!0,opened:c,onClose:f,children:[i(s.Popover.Target,{children:i("div",{"data-testid":"palette-item-target",className:"palette-item",onClick:d,style:{"--shadow-color":pt(n).alpha(.5).hex(),backgroundColor:n}})}),i(s.Popover.Dropdown,{children:p(s.Stack,{children:[i(s.NumberInput,{size:"xs",label:"Map a value to this color",value:l,onChange:u}),p(s.Group,{position:"right",children:[i(s.Button,{variant:"subtle",size:"xs",onClick:w,children:"Cancel"}),i(s.Button,{"data-testid":"palette-item-ok",size:"xs",onClick:_,children:"OK"})]})]})})]}),i(s.Text,{title:C,style:{opacity:m?1:0},color:"dimmed",size:"sm",className:"palette-value--bottom palette-value",children:T})]})}const rw=k.observer(({model:e})=>{const{classes:t}=Lo(),n=x.range(0,13,1).map(r=>100/12*r).map(r=>[e.interpolation.getColor(r),r]);return i("div",{className:t.palette,children:n.map(([r,a],o)=>i(nw,{index:o,color:r,value:e.getStepFromValue(a),onChange:l=>e.changeStep(l,a)},r))})}),iw=k.observer(function(t){const n=Q.useCreation(()=>new tw,[]);return y.useEffect(()=>{n.fromProps(t)}),n.interpolation==null?null:i(rw,{model:n})}),aw=e=>{const{value:t,onChange:n,colorManager:r}=e,a=r.getColorInterpolations(),[o,l]=y.useState(t),u=r.decodeInterpolation(o.interpolation)||a[0],[c,{setTrue:d,setFalse:f}]=Q.useBoolean(),h=a.map(_=>({label:_.displayName,value:r.encodeColor(_),group:_.category}));function g(_){_&&l(T=>({...T,interpolation:_}))}const m=()=>{f(),n==null||n(te.toJS(o))};function C(_){l(T=>({...T,steps:_}))}const w=()=>{f(),l(t)};return p(B,{children:[i(s.Button,{variant:"outline",onClick:d,children:u==null?void 0:u.displayName}),i(s.Modal,{size:508,title:"Setup color interpolation",opened:c,onClose:f,zIndex:320,children:c&&p(s.Stack,{"data-testid":"color-interpolation-modal",children:[i(s.Select,{label:"Color style",value:o.interpolation,data:h,onChange:g,withinPortal:!0,zIndex:340,maxDropdownHeight:500}),i(iw,{steps:o.steps,interpolation:u,onChange:C}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:w,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:m,children:"OK"})]})]})})]})},sw=["static","interpolation","none"].map(e=>({label:x.capitalize(e),value:e})),ow=[{from:0,to:0},{from:100,to:100}];function Oo(e){return e?x.isString(e)?e==="none"?"none":"static":"interpolation":"none"}function lw(e,t){var n;return Oo(t)==="static"?t:(n=e.getStaticColors()[0])==null?void 0:n.value}function uw(e,t){return x.isObject(t)?t:{steps:ow,interpolation:e.encodeColor(e.getColorInterpolations()[0])}}const cw=y.forwardRef((e,t)=>{const{colorManager:n}=y.useContext(ct),[r,a]=y.useState(Oo(e.value)),[o,l]=y.useState(lw(n,e.value)),u=Q.useLatest(o),[c,d]=y.useState(uw(n,e.value)),f=Q.useLatest(c),h=C=>{var w,_,T;a(C||"none"),C==="static"?(w=e.onChange)==null||w.call(e,u.current):C==="none"||!C?(_=e.onChange)==null||_.call(e,"none"):(T=e.onChange)==null||T.call(e,f.current)},g=C=>{var w;l(C),(w=e.onChange)==null||w.call(e,C)},m=C=>{var w;d(C),(w=e.onChange)==null||w.call(e,C)};return p(s.Stack,{align:"stretch",children:[i(s.Select,{label:"Cell background",value:r||"none",onChange:h,data:sw}),r==="static"&&i($e,{value:o,onChange:g}),r==="interpolation"&&i(aw,{colorManager:n,value:c,onChange:m})]})}),dw={[at.eloc]:"ELOC"},pw=Object.values(at).map(e=>({label:x.get(dw,e,x.capitalize(e)),value:e})),hw=y.forwardRef(({label:e,value:t,onChange:n,sx:r},a)=>i(s.Select,{ref:a,label:e,data:pw,value:t,onChange:n,sx:r})),fw=y.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:a,setFalse:o}]=Q.useBoolean(),[l,u]=y.useState(e),c=()=>{o(),t(l)},d=()=>{o(),u(e)},f=()=>{u(Mo)};return y.useEffect(()=>{u(e)},[e]),p(B,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Custom Cell Content"}),i(s.Modal,{size:800,title:"Custom cell content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(s.Box,{sx:{position:"relative"},children:i(De,{height:"500px",defaultLanguage:"javascript",value:l,onChange:h=>u(h??""),theme:"vs-dark",options:{minimap:{enabled:!1}}})}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:c,children:"OK"})]})]})]})})]})}),gw=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],yi=()=>i(s.Text,{color:"dimmed",size:12,children:"px"}),mw=({control:e,index:t,watch:n,remove:r,column:a})=>{const o=n(`columns.${t}.value_type`);return p(s.Stack,{my:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,children:[i(v.Controller,{name:`columns.${t}.label`,control:e,render:({field:l})=>i(s.TextInput,{label:"Label",required:!0,id:`col-label-${t}`,sx:{flex:1},...l})}),i(v.Controller,{name:`columns.${t}.value_field`,control:e,render:({field:l})=>i(W,{label:"Value Field",required:!0,...l})})]}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`columns.${t}.value_type`,control:e,render:({field:l})=>i(hw,{label:"Value Type",sx:{flex:1},...l})}),o===at.custom&&i(v.Controller,{name:`columns.${t}.func_content`,control:e,render:({field:l})=>i(fw,{value:l.value??Mo,onChange:u=>l.onChange(u??"")})})]}),i(s.Divider,{mb:-10,variant:"dashed",label:"Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(s.NumberInput,{hideControls:!0,label:"Min Width",rightSection:i(yi,{}),disabled:!0}),i(v.Controller,{name:`columns.${t}.width`,control:e,render:({field:l})=>i(s.NumberInput,{hideControls:!0,label:"Width",rightSection:i(yi,{}),...l})}),i(s.NumberInput,{hideControls:!0,label:"Max Width",rightSection:i(yi,{}),disabled:!0})]}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`columns.${t}.align`,control:e,render:({field:l})=>i(s.Select,{label:"Alignment",data:gw,...l})})}),i(v.Controller,{name:`columns.${t}.cellBackgroundColor`,control:e,render:({field:l})=>i(cw,{...l})}),i(s.Divider,{mb:4,mt:12,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(t),children:"Delete this column"})]})},yw=({control:e,watch:t})=>{const{fields:n,append:r,remove:a,update:o}=v.useFieldArray({control:e,name:"columns"}),l=()=>{const c=ke.randomId();r({id:c,label:c,align:"center",value_field:"",value_type:at.string,width:""})};t("columns");const u=t("use_raw_columns");return p(B,{children:[i(v.Controller,{name:"use_raw_columns",control:e,render:({field:c})=>i(s.Switch,{mt:20,mb:20,label:"Use Original Data Columns",checked:c.value,onChange:d=>c.onChange(d.currentTarget.checked)})}),!u&&i(s.Stack,{children:p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[n.map((c,d)=>i(s.Tabs.Tab,{value:d.toString(),children:d+1},c.id)),i(s.Tabs.Tab,{onClick:l,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),n.map((c,d)=>i(s.Tabs.Panel,{value:d.toString(),children:i(mw,{control:e,watch:t,index:d,column:c,remove:a},d)},c.id))]})})]})};function bw({control:e,watch:t}){return t(["horizontalSpacing","verticalSpacing","fontSize","striped","highlightOnHover"]),p(s.Stack,{spacing:"xs",children:[p(s.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:[i(v.Controller,{name:"horizontalSpacing",control:e,render:({field:n})=>i(s.TextInput,{label:"Horizontal Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"verticalSpacing",control:e,render:({field:n})=>i(s.TextInput,{label:"Vertical Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})})]}),i(s.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:i(v.Controller,{name:"fontSize",control:e,render:({field:n})=>i(s.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})})}),p(s.Group,{position:"apart",grow:!0,children:[i(v.Controller,{name:"striped",control:e,render:({field:n})=>i(s.Switch,{label:"Striped",checked:n.value,onChange:r=>n.onChange(r.currentTarget.checked)})}),i(v.Controller,{name:"highlightOnHover",control:e,render:({field:n})=>i(s.Switch,{label:"Highlight on hover",checked:n.value,onChange:r=>n.onChange(r.currentTarget.checked)})})]})]})}function vw({columns:e,...t}){return{...t,columns:e.map(({id:n,...r})=>({id:n??ke.randomId(),...r}))}}function xw({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},t,Ao),[t]),a=y.useMemo(()=>vw(r),[r]);y.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return u(["id_field"]),p("form",{onSubmit:l(n),children:[p(s.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Table Config"}),i(s.ActionIcon,{type:"submit","aria-label":"save config",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"Columns",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Columns",children:"Columns"}),i(s.Tabs.Tab,{value:"Style",children:"Style"})]}),p(s.Tabs.Panel,{value:"Columns",children:[i(v.Controller,{name:"id_field",control:o,render:({field:g})=>i(W,{label:"ID Field",required:!0,...g})}),i(s.Divider,{mt:20,mb:10,variant:"dashed"}),i(yw,{control:o,watch:u})]}),i(s.Tabs.Panel,{value:"Style",children:i(bw,{control:o,watch:u})})]})]})}function ww(e){const{columns:t,...n}=e;return{...e,columns:t.map(r=>({...r,align:r.align??"left"}))}}function Cw(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{id_field:a,columns:o,...l}=e;return{...l,id_field:r(a),columns:o.map(u=>({...u,value_field:r(u.value_field)}))}}catch(n){throw console.error("[Migration failed]",n),n}}function Sw(e){const{columns:t,...n}=e;return{...n,columns:t.map(r=>({...r,align:r.align??"left",cellBackgroundColor:r.cellBackgroundColor??"",width:r.width??""}))}}class _w extends ge{constructor(){super(...arguments);q(this,"VERSION",5)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{columns:r,...a}=n.config;return{...n,version:2,config:{...a,columns:r.map(({id:o,...l})=>({id:o??ke.randomId(),...l}))}}}),this.version(3,n=>({...n,version:3,config:ww(n.config)})),this.version(4,(n,r)=>({...n,version:4,config:Cw(n.config,r)})),this.version(5,n=>({...n,version:5,config:Sw(n.config)}))}}const bi={createConfig(){return{version:5,config:x.cloneDeep(Ao)}},displayName:"Table",displayGroup:"Others",migrator:new _w,name:"table",viewRender:Hx,configRender:xw,triggers:[mi]},Po=["function text({ data, variables, filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
|
|
297
|
-
`),vi={func_content:Po,horizontal_align:"left",font_size:"14px",font_weight:"normal"},kw=k.observer(({context:e})=>{const t=ye(),{value:n=vi}=R(e.instanceData,"config"),{variables:r}=e,a=e.data,{func_content:o,horizontal_align:l,font_size:u,font_weight:c}=n,d=y.useMemo(()=>r.reduce((h,g)=>{const m=mt(g,a);return h[g.name]=Ze(g,m),h},{}),[r,a]),f=y.useMemo(()=>new Function(`return ${o}`)()({data:a,variables:d,filters:t.payloadForSQL.filters,context:t.payloadForSQL.context}),[o,a,d,t.payloadForSQL]);return i(s.Text,{align:l,weight:c,sx:{fontSize:u},children:f})}),Tw=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return i(s.Box,{sx:{position:"relative"},children:i(De,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Dw=y.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:a,setFalse:o}]=Q.useBoolean(),[l,u]=y.useState(e),c=()=>{o(),t(l)},d=()=>{o(),u(e)},f=()=>{u(Po)};return y.useEffect(()=>{u(e)},[e]),p(B,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Edit Content"}),i(s.Modal,{size:800,title:"Text content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(Tw,{value:l,onChange:u}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:c,children:"OK"})]})]})]})})]})}),Iw=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}];function Mw({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},t,vi),[t]),a=y.useMemo(()=>{const{func_content:g,horizontal_align:m,font_size:C,font_weight:w}=r;return{func_content:g,horizontal_align:m,font_size:C,font_weight:w}},[r]);y.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]),u(["func_content","horizontal_align","font_size","font_weight"]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{weight:500,children:"Configurations"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Stack,{spacing:10,children:[i(v.Controller,{name:"func_content",control:o,render:({field:g})=>i(Dw,{...g})}),i(s.Divider,{mt:10,mb:-10,variant:"dashed",label:"Style",labelPosition:"center"}),i(v.Controller,{name:"horizontal_align",control:o,render:({field:g})=>i(s.Select,{label:"Horizontal Alignment",data:Iw,...g})}),i(v.Controller,{name:"font_size",control:o,render:({field:g})=>i(s.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1},...g})}),i(s.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:i(v.Controller,{name:"font_weight",control:o,render:({field:g})=>i(Xs,{label:"Font Weight",...g})})})]})]})})}class Aw extends ge{constructor(){super(...arguments);q(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const zw={displayName:"Text",displayGroup:"Others",migrator:new Aw,name:"text",viewRender:kw,configRender:Mw,createConfig(){return{version:1,config:x.cloneDeep(vi)}}},Ew=()=>p("svg",{width:"64",height:"64",viewBox:"0 0 64 64",fill:"none",children:[i("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M22.49 27.79H14.47C13.55 27.79 12.81 28.53 12.81 29.45C12.81 30.37 13.55 31.11 14.47 31.11H22.49C23.41 31.11 24.15 30.37 24.15 29.45C24.15 28.54 23.41 27.79 22.49 27.79ZM34.32 31.28C35.22 31.32 35.7 31.82 35.74 32.76C35.78 33.54 35.37 34.3 34.51 35.04C33.52 35.9 33.03 36.95 33.03 38.19V38.81H34.82V38.25C34.78 37.59 35.07 37.02 35.68 36.52C37.12 35.41 37.82 34.15 37.78 32.75C37.66 30.53 36.5 29.35 34.32 29.23C32.3 29.23 31.05 30.46 30.55 32.93L32.53 33.55C32.82 32.04 33.42 31.28 34.32 31.28ZM35 39.93H32.84V42.21H35V39.93ZM14.83 36.42H18.54C19.46 36.42 20.2 37.17 20.2 38.08C20.2 39 19.46 39.74 18.54 39.74H10.52C9.6 39.74 8.86 39 8.86 38.08C8.86 37.61 9.06 37.19 9.37 36.89H5.66C4.74 36.89 4 36.15 4 35.23C4 34.31 4.74 33.57 5.66 33.57H13.68C14.6 33.57 15.34 34.31 15.34 35.23C15.34 35.7 15.14 36.12 14.83 36.42ZM50.94 36.85H58.74C59.66 36.85 60.4 37.59 60.41 38.51C60.41 39.43 59.67 40.17 58.75 40.17H54.26C54.56 40.47 54.74 40.88 54.74 41.34C54.74 42.26 54 43 53.08 43H50.94V36.85Z",fill:"#B8C0CC"}),i("path",{d:"M18.39 32.28H16.51V35.02H18.39V32.28Z",fill:"#9399A5"}),i("path",{d:"M46.87 15H20.69C18.38 15 16.5 16.88 16.5 19.19V26.22H18.38V23.45H49.18V47.68H18.38V41.07H16.5V49.55H51.05V19.19C51.06 16.88 49.18 15 46.87 15ZM39.46 20.73C38.81 20.73 38.29 20.2 38.29 19.56C38.29 18.92 38.82 18.39 39.46 18.39C40.11 18.39 40.63 18.92 40.63 19.56C40.63 20.2 40.11 20.73 39.46 20.73ZM43.22 20.73C42.57 20.73 42.05 20.2 42.05 19.56C42.05 18.92 42.58 18.39 43.22 18.39C43.87 18.39 44.39 18.92 44.39 19.56C44.39 20.2 43.87 20.73 43.22 20.73ZM46.97 20.73C46.32 20.73 45.8 20.2 45.8 19.56C45.8 18.92 46.33 18.39 46.97 18.39C47.62 18.39 48.14 18.92 48.14 19.56C48.14 20.2 47.62 20.73 46.97 20.73Z",fill:"#9399A5"})]});function Bo(e,t){const n=x.get(e,t,"");if(n)throw new Error(n)}async function $w(e,t,n,r={}){const a={"X-Requested-With":"XMLHttpRequest","Content-Type":r.string?"application/x-www-form-urlencoded":"application/json",...r.headers},o={baseURL:e,method:"POST",url:t,params:r.params,headers:a};return o.data=r.string?JSON.stringify(n):n,xt(o).then(l=>l.data).catch(l=>Promise.reject(l))}const Lw=({conf:e,panelData:t})=>async()=>{const{expertSystemURL:n,path:r,goal:a,question:o}=e;if(!r||!a||!o)return;const l=gc(t);if(!l)return;const u={dashboard:a,panel:o,data:l};try{const c=n.startsWith("http")?n:window.location.origin;return await $w(c,`/expert/v3/devtable/${r}`,u,{})}catch(c){throw Bo(c,"response.data.detail"),Bo(c,"response.data.error"),console.error(c),c}},xi={expertSystemURL:"",path:"",goal:"",question:""},wi={height:"100%",overflowY:"auto",...Lr},Vo=({message:e})=>i(s.Box,{sx:wi,children:i("div",{dangerouslySetInnerHTML:{__html:e},style:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45"}})}),Ow=({error:e,width:t,height:n})=>{const r=e.message;if(r.startsWith("<"))return i(Vo,{message:r});const o=n-25-20-30;return i(s.Center,{sx:{width:"100%",height:o},children:p(s.Stack,{align:"center",spacing:20,children:[i(Ew,{}),i(Vo,{message:r})]})})};function Pw({context:e}){const{value:t}=R(e.instanceData,"config"),n=y.useMemo(()=>x.defaultsDeep({},t,xi),[t]),{width:r,height:a}=e.viewport,o=e.data,{data:l,error:u,loading:c}=Q.useRequest(Lw({conf:n,panelData:o}),{refreshDeps:[o,n]});return!r||!a||!n?null:c?i(s.Box,{sx:{position:"relative",height:a},children:i(s.LoadingOverlay,{visible:!0})}):u?i(s.Box,{sx:wi,"data-enable-scrollbar":!0,children:i(Ow,{error:u,width:r,height:a})}):!l||!Array.isArray(l.replies)||l.replies.length===0?null:i(s.Box,{sx:wi,"data-enable-scrollbar":!0,children:l.replies.map((d,f)=>i("div",{dangerouslySetInnerHTML:{__html:d.interpretation.html}},f))})}function Bw({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},t,xi),[t]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l(["expertSystemURL","goal","path","question"]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,r),[d,r]);return i("form",{onSubmit:o(n),children:p(s.Stack,{children:[p(s.Group,{grow:!0,children:[i(v.Controller,{name:"expertSystemURL",control:a,render:({field:h})=>i(s.TextInput,{label:"Expert System URL",...h})}),i(v.Controller,{name:"path",control:a,render:({field:h})=>i(s.TextInput,{label:"Path",required:!0,...h})})]}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:"goal",control:a,render:({field:h})=>i(s.TextInput,{label:"Goal",required:!0,...h})}),i(v.Controller,{name:"question",control:a,render:({field:h})=>i(s.TextInput,{label:"Question",required:!0,...h})})]}),i(s.Divider,{variant:"dashed",mt:16,mb:8}),i(s.Button,{type:"submit",variant:"filled",color:"blue",leftIcon:i(D.DeviceFloppy,{size:20}),disabled:!f,sx:{alignSelf:"flex-end"},children:"Submit Changes"})]})})}class Vw extends ge{constructor(){super(...arguments);q(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const Nw={displayName:"Merico GQM",displayGroup:"Merico suite",migrator:new Vw,name:"mericoGQM",viewRender:Pw,configRender:Bw,createConfig(){return{version:1,config:x.cloneDeep(xi)}}};function qw(e,t,n){if(!e)return n[0];try{return[t,U(t).add(1,"year").subtract(1,"day").valueOf()]}catch(r){return console.error(r),n[0]}}function Fw(e,t,n){const r=qw(e,t,n);return{top:50,left:25,right:5,cellSize:["auto",13],range:r,itemStyle:{borderColor:"#eee"},splitLine:{show:!0},dayLabel:{firstDay:1},monthLabel:{position:"end"},yearLabel:{show:!0}}}function Gw(e){return{heat_block:function(r){if(!e.heat_block.value_formatter)return r;try{return Z(r).format(e.heat_block.value_formatter)}catch(a){return console.error(a),r}}}}function Ww(e,t){return{show:!e,selectedMode:"single",top:5,right:5,data:t.map(n=>({name:n,icon:"circle"}))}}function jw(e,t,n,r){const{calendar:a,heat_block:o}=e,l=O(a.data_key),u=O(o.data_key);return t?{type:"heatmap",name:"heatmap",coordinateSystem:"calendar",calendarIndex:0,data:r[l.queryID].map(c=>[x.get(c,l.columnKey),x.get(c,u.columnKey)])}:Object.entries(n).map(([c,d])=>({type:"heatmap",name:c,coordinateSystem:"calendar",calendarIndex:0,data:d.map(f=>[x.get(f,l.columnKey),x.get(f,u.columnKey)])}))}const Rw=e=>{try{return Z(e).format({trimMantissa:!0,mantissa:2})}catch{return e}};function Yw({conf:e,valueFormatters:t,dataDict:n,params:r}){const{value:a}=r,[o,l]=a,c=[{label:e.heat_block.name,value:t.heat_block(l),style:{label:"",value:""}}],d=n[o];return d&&e.tooltip.metrics.forEach(f=>{const h=O(f.data_key);c.push({label:f.name,value:Rw(x.get(d,h.columnKey,"")),style:{label:"",value:""}})}),c}function Qw(e,t,n){const r=O(e.calendar.data_key),a=x.keyBy(t[r.queryID],r.columnKey);return{confine:!0,formatter:function(o){const u=Yw({conf:e,valueFormatters:n,dataDict:a,params:o}).map(f=>`
|
|
295
|
+
`}}function mx(){return{show:!0,trigger:"item",confine:!0,formatter:gx()}}const yx={tooltip:{show:!0},series:{type:"sunburst",radius:[0,"90%"],emphasis:{focus:"ancestor"}}};function bx(e,t,n){n.reduce((o,l)=>{const u=mt(l,t);return o[l.name]=Ze(l,u),o},{});const a={series:{data:px(e,t),levels:fx(e)},tooltip:mx()};return x.defaultsDeep({},a,yx)}ie.use([he.SunburstChart,Ee.CanvasRenderer]);function vx({context:e}){const{variables:t}=e,{value:n}=R(e.instanceData,"config"),r=y.useMemo(()=>x.defaults({},n,gi),[n]),a=e.data,{width:o,height:l}=e.viewport,u=y.useMemo(()=>bx(r,a,t),[r,a,t]);return!o||!l?null:i(Ve,{width:o,height:l,children:i(ze,{echarts:ie,option:u,style:an(o,l),notMerge:!0,theme:"merico-light"})})}function xx({control:e,watch:t}){return t(["label_key","value_key","group_key"]),p(s.Stack,{children:[i(v.Controller,{name:"label_key",control:e,render:({field:n})=>i(W,{label:"Label Key",required:!0,...n})}),i(v.Controller,{name:"value_key",control:e,render:({field:n})=>i(W,{label:"Value Key",required:!0,...n})}),i(v.Controller,{name:"group_key",control:e,render:({field:n})=>i(W,{label:"Group Key",clearable:!0,...n})})]})}const wx=[{label:"Radial",value:"radial"},{label:"Tangential",value:"tangential"},{label:"None",value:"0"}],Cx=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Sx=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`levels.${t}.r0`,control:e,render:({field:r})=>i(s.TextInput,{label:"Inside Radius",placeholder:"0%",...r})}),i(v.Controller,{name:`levels.${t}.r`,control:e,render:({field:r})=>i(s.TextInput,{label:"Outside Radius",placeholder:"50%",...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Label Style",labelPosition:"center"}),i(v.Controller,{name:`levels.${t}.label.show_label_tolerance`,control:e,render:({field:r})=>i(s.NumberInput,{label:"Hide label when its percentage is less than...",precision:4,step:5e-4,min:0,max:1,...r})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`levels.${t}.label.rotate`,control:e,render:({field:r})=>i(s.Select,{label:"Rotate",data:wx,...r})}),i(v.Controller,{name:`levels.${t}.label.align`,control:e,render:({field:r})=>i(s.Select,{label:"Align",data:Cx,...r})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`levels.${t}.label.position`,control:e,render:({field:r})=>i(si,{label:"Position",...r})}),i(v.Controller,{name:`levels.${t}.label.padding`,control:e,render:({field:r})=>i(s.NumberInput,{label:"Padding",min:0,hideControls:!0,...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Level"})]}),_x=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"levels"}),o=t("levels"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),r0:"",r:"",label:{show_label_tolerance:.001,rotate:"0",align:"center",position:"inside",padding:0}}),c=t("levels.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(B,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(D.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Configure ring style on each level"})]}),i(s.Divider,{variant:"dashed",my:10}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(Sx,{control:e,index:g,remove:a},h.id)},h.id))]})]})};function kx({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},t,gi),[t]),a=y.useMemo(()=>x.clone(r),[r]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);u(["label_key","value_key","group_key","levels"]);const[g,m]=y.useState("Data");return i("form",{onSubmit:l(n),children:p(s.Stack,{spacing:"xs",children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Sunburst Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{value:g,onTabChange:m,orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Data",children:"Data"}),i(s.Tabs.Tab,{value:"Levels",children:"Levels"})]}),i(s.Tabs.Panel,{value:"Data",children:i(xx,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Levels",children:i(_x,{control:o,watch:u})})]})]})})}function Tx(e){const{label_field:t,value_field:n,...r}=e;return{...r,label_key:t,value_key:n}}function Dx(e){const{group_key:t="",...n}=e;return{...n,group_key:t}}function Ix(e){const{levels:t=[],...n}=e;return{...n,levels:t}}function Mx(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{label_key:a,value_key:o,group_key:l,...u}=e;return{...u,label_key:r(a),value_key:r(o),group_key:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class Ax extends ge{constructor(){super(...arguments);q(this,"VERSION",5)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:Tx(n.config)})),this.version(3,n=>({...n,version:3,config:Dx(n.config)})),this.version(4,n=>({...n,version:4,config:Ix(n.config)})),this.version(5,(n,r)=>({...n,version:5,config:Mx(n.config,r)}))}}const zx={displayName:"Sunburst Chart",displayGroup:"ECharts-based charts",migrator:new Ax,name:"sunburst",viewRender:vx,configRender:kx,createConfig(){return{version:5,config:x.cloneDeep(gi)}}};var at=(e=>(e.string="string",e.number="number",e.eloc="eloc",e.percentage="percentage",e.custom="custom",e))(at||{});const zo=["function text({ value }) {"," // your code goes here"," return value","}"].join(`
|
|
296
|
+
`),Eo={columns:[],fontSize:"14px",highlightOnHover:!0,horizontalSpacing:"14px",id_field:"",striped:!0,use_raw_columns:!0,verticalSpacing:"14px"},$o={left:"flex-start",center:"center",right:"flex-end"},Ex=({header:e,cx:t})=>{const n=x.get(e.column.columnDef.meta,"align","left");return p(s.Text,{className:t("table-head-cell",{"table-head-cell--sortable":e.column.getCanSort()}),onClick:e.column.getToggleSortingHandler(),align:n,sx:{justifyContent:$o[n]},children:[e.isPlaceholder?null:et.flexRender(e.column.columnDef.header,e.getContext()),i($x,{direction:e.column.getIsSorted()})]})},$x=({direction:e})=>{switch(e){case"asc":return i(E.IconArrowUp,{size:16});case"desc":return i(E.IconArrowDown,{size:"1em"});default:return null}},Lx=s.createStyles(e=>({root:{overflow:"auto",position:"relative","& .table-head-cell":{display:"flex",flexFlow:"row nowrap",alignItems:"center",whiteSpace:"nowrap","&.table-head-cell--sortable":{cursor:"pointer",userSelect:"none"}},"&.table-highlight-on-hover tr":{transition:"background-color 0.2s","&:hover":{backgroundColor:e.colorScheme==="dark"?e.colors.dark[5]:e.colors.gray[0]}}},thead:{background:e.colorScheme==="dark"?e.colors.dark[7]:e.white,position:"sticky",top:24,transform:"translateY(-1px)",zIndex:10},info_bar:{position:"sticky",top:0,left:0,right:0,zIndex:10,background:"white"}})),Ox={tableLayout:"fixed","thead, tbody":{tr:{"th, td":{padding:"2px 10px",div:{overflow:"hidden",textOverflow:"ellipsis"},"&:first-of-type":{paddingLeft:2,paddingRight:2}}}}},Px=s.createStyles((e,t)=>({content:{display:"flex",alignItems:"center",justifyContent:$o[t.align],".table-cell-text":{whiteSpace:"nowrap",cursor:t.clickable?"pointer":"default",textDecoration:t.clickable?"underline":"none"}}}));function Bx(e){return e?pt(e).oklch()[0]>.7?"black":"white":"inherit"}function Vx(e){const t=e.tableCellContext.bgColor;return{backgroundColor:t,color:Bx(t)}}function Qt(e){const t=e.tableCellContext.isClickable(),n=Px({clickable:t,align:e.align});return i("div",{className:n.classes.content,style:{...Vx(e)},children:i(s.Text,{className:"table-cell-text",onClick:e.tableCellContext.getClickHandler(),children:i("span",{title:e.children,children:e.children})})})}function Nx(e){return i(Qt,{...e,children:e.value})}function qx(e){const t=Z(e.value).format({average:!0,mantissa:2,trimMantissa:!0});return i(Qt,{...e,children:t})}function Fx(e){const t=Z(e.value).format({thousandSeparated:!0});return i(Qt,{...e,children:t})}function Gx(e){const t=Z(e.value).format({output:"percent",mantissa:3,trimMantissa:!0});return i(Qt,{...e,children:t})}function Wx(e){const t=e.value,n=e.func_content;if(!n)return i(Qt,{...e,children:t});const r=new Function(`return ${n}`)()({value:t});return i(Qt,{...e,children:r})}function jx(e){switch(e.type){case at.string:return i(Nx,{...e});case at.eloc:return i(qx,{...e});case at.number:return i(Fx,{...e});case at.percentage:return i(Gx,{...e});case at.custom:return i(Wx,{...e})}}function Rx({tableContainerRef:e,rows:t}){var u,c;const n=Pu.useVirtual({parentRef:e,size:t.length,estimateSize:y.useCallback(()=>28,[]),overscan:20}),{virtualItems:r,totalSize:a}=n,o=r.length>0&&((u=r==null?void 0:r[0])==null?void 0:u.start)||0,l=r.length>0?a-(((c=r==null?void 0:r[r.length-1])==null?void 0:c.end)||0):0;return Q.useWhyDidYouUpdate("TableBody",{tableContainerRef:e,rows:t}),p("tbody",{children:[o>0&&i("tr",{children:i("td",{style:{height:`${o}px`}})}),r.map(d=>{const f=t[d.index];return i("tr",{children:f.getVisibleCells().map(h=>i("td",{children:et.flexRender(h.column.columnDef.cell,h.getContext())},h.id))},f.id)}),l>0&&i("tr",{children:i("td",{style:{height:`${l}px`}})})]})}const mi={id:"builtin:table:click-cell-content",displayName:"Click Cell Content",nameRender:Kx,configRender:Qx,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"}]},Yx={column:""};function Lo(e,t){const{value:n}=R(e.instanceData,"config"),r={columnsFromConfig:[],columnsFromData:[]};if(n&&(r.columnsFromConfig=n.columns.map((a,o)=>({label:a.label,value:o.toString()}))),!t)return r;if(n!=null&&n.id_field){const a=sn(t,n.id_field);(a==null?void 0:a.length)>0&&(r.columnsFromData=Object.keys(a[0]).map(o=>({label:o,value:o})))}return r}function Qx(e){const{columnsFromConfig:t,columnsFromData:n}=Lo(e.instance,e.sampleData),r=t.length>0?t:n,{value:a,set:o}=R(e.trigger.triggerData,"config"),{column:l}=x.defaults({},a,Yx),u=c=>{isNaN(+c)?o({column:c}):o({column:+c})};return i(s.Select,{clearable:!1,data:r,label:"Choose a column",value:l.toString(),onChange:u})}function Ux(e,t){return e?x.isNumber(e.column)?`Click cell of ${t[e.column].label}`:`Click cell of ${e.column}`:"Click cell content (click to config)"}function Kx(e){const{columnsFromConfig:t}=Lo(e.instance),{value:n}=R(e.trigger.triggerData,"config");return i(s.Text,{children:Ux(n,t)})}function Oo(e,t,n){return Math.min(Math.max(e,t),n)}class Xx{constructor(t){this.steps=t;const n=[],r=new Set;for(const a of t)r.has(a.to)||(n.push(a),r.add(a.to));if(n.sort((a,o)=>a.from-o.from),n.length<2)throw new Error("MultiStepValueMapper requires at least 2 steps");this.steps=n}getLinearFunction(t,n){const r=(n.to-t.to)/(n.from-t.from),a=t.to-r*t.from;return o=>r*o+a}getStepFunctionForValue(t){let n=x.findLastIndex(this.steps,r=>r.from<=t);return n=Oo(n,0,this.steps.length-2),this.getLinearFunction(this.steps[n],this.steps[n+1])}mapValue(t){return Oo(this.getStepFunctionForValue(t)(t),0,100)}}class Jx{constructor(t,n,r,a,o){this.getColIndex=t,this.cell=n,this.triggers=r,this.interactionManager=a,this.colorManager=o}getClickHandler(){const t=this.getRelatedTrigger();if(t.length!==0)return()=>{const n={row_data:this.cell.row.original,row_index:this.cell.row.index,col_index:this.getColIndex(this.cell)};for(const r of t)this.interactionManager.runInteraction(r.id,n)}}getRelatedTrigger(){return this.triggers.filter(n=>n.schemaRef===mi.id).filter(n=>{const r=this.getColIndex(this.cell),a=x.get(this.cell.column.columnDef.meta,"value_field"),o=x.get(n.config,"column");return o==r||o==a})}isClickable(){return this.getRelatedTrigger().length>0}get columnConf(){return this.cell.column.columnDef.meta}get bgColor(){const t=this.columnConf.cellBackgroundColor;if(!t||t==="none")return;if(x.isString(t))return t;const n=+this.cell.getValue();if(isFinite(n)){const r=this.colorManager.decodeInterpolation(t.interpolation),o=new Xx(t.steps).mapValue(n);return r==null?void 0:r.getColor(o)}}}const Zx=e=>{const t=Xe(e),n=Ke(t.triggerManager,mi.id),{colorManager:r}=y.useContext(ct);return y.useCallback(a=>new Jx(e.getColIndex,a,n,t,r),[n,t,e.getColIndex])};function Hx({queryData:e,width:t,height:n,conf:r,context:a,instance:o}){const{id_field:l,use_raw_columns:u,columns:c,...d}=r,{classes:f,cx:h}=Lx(),g=y.useMemo(()=>u?!Array.isArray(e)||e.length===0?[]:Object.keys(e[0]).map(N=>({id:N,label:N,value_field:N,value_type:at.string,align:"left",width:"",cellBackgroundColor:""})):c,[u,c,e]),m=Zx({getColIndex:y.useCallback(N=>g.indexOf(N.column.columnDef.meta),[g]),vizManager:a.vizManager,instance:o}),C=y.useMemo(()=>{const N=et.createColumnHelper();return g.map(Y=>{const H=mc(Y.value_field);return N.accessor(H.columnKey,{cell:se=>i(jx,{tableCellContext:m(se.cell),value:se.getValue(),type:Y.value_type,...Y}),header:Y.label,enableSorting:!0,meta:Y,size:typeof Y.width=="number"?Y.width:void 0,minSize:typeof Y.width=="number"?Y.width:void 0})})},[g,m]),[w,_]=y.useState([]),T=et.useReactTable({data:e,state:{sorting:w},onSortingChange:_,columns:C,getCoreRowModel:et.getCoreRowModel(),getSortedRowModel:et.getSortedRowModel()}),{rows:M}=T.getRowModel(),P=y.useRef(null),G=M.length,$=G>0,L=$?n-22:n,A=$?22:0;return Q.useWhyDidYouUpdate("VizTableComponent",{queryData:e,width:t,height:n,conf:r,context:a,instance:o,finalColumns:g,getCellContext:m,tableColumns:C,table:T,rows:M,tableContainerRef:P}),p("div",{ref:P,style:{height:n,width:t,padding:"0 5px"},"data-enable-scrollbar":!0,className:h(f.root,{"table-highlight-on-hover":r.highlightOnHover}),children:[G>0&&i(s.Box,{className:f.info_bar,sx:{height:22},children:p(s.Text,{align:"right",pr:6,size:14,color:"dimmed",fw:"normal",children:["Total: ",G]})}),p(s.Table,{sx:{...Ox,maxHeight:L},...d,striped:r.striped,children:[i("thead",{className:f.thead,style:{top:A},children:T.getHeaderGroups().map(N=>i("tr",{children:N.headers.map(K=>i("th",{style:{width:K.getSize()},children:i(Ex,{header:K,cx:h})},K.id))},N.id))}),i(Rx,{tableContainerRef:P,rows:M})]})]})}function ew({data:e,width:t,height:n,conf:r,context:a,instance:o}){const{id_field:l,use_raw_columns:u,columns:c}=r,d=y.useMemo(()=>{if(!l)return[];const f=O(l);return e[f.queryID]},[e,l]);return!Array.isArray(d)||d.length===0?i(s.Text,{color:"gray",align:"center",children:"Empty Data"}):i(Hx,{queryData:d,width:t,height:n,conf:r,context:a,instance:o})}function tw({context:e,instance:t}){const n=e.data,{height:r,width:a}=e.viewport,{value:o}=R(e.instanceData,"config");return o?o.id_field?i(ew,{data:n,width:a,height:r,conf:o,context:e,instance:t}):i(s.Text,{color:"red",align:"center",children:"ID Field is not set, can't render a table without it"}):null}const Po=s.createStyles(()=>({palette:{display:"flex",flexFlow:"row nowrap"},paletteItem:{".palette-value":{height:24,overflow:"visible",width:36},".palette-item":{width:"36px",height:36*.618,cursor:"pointer",transition:"transform 100ms ease-in-out","&:hover":{boxShadow:"0 0 0 2px var(--shadow-color)",borderRadius:2,transform:"scale(1.2)"}}}})),nw=[{from:0,to:0},{from:100,to:100}];class rw{constructor(){q(this,"steps",new Map);q(this,"interpolation");q(this,"onChange");te.makeAutoObservable(this,{steps:te.observable},{deep:!1}),te.reaction(()=>te.toJS(this.steps),()=>{this.notifyStepChange()})}setSteps(t){for(const n of t)this.steps.set(n.to,n.from)}notifyStepChange(){var t;(t=this.onChange)==null||t.call(this,Array.from(this.steps.entries()).map(([n,r])=>({to:n,from:r})).sort((n,r)=>n.to-r.to||n.from-r.from))}fromProps(t){t.steps.length<2?this.setSteps(nw):this.setSteps(t.steps),this.interpolation=t.interpolation,this.onChange=t.onChange}changeStep(t,n){t==null?this.steps.delete(n):this.steps.set(n,t)}getStepFromValue(t){return this.steps.get(t)}}function iw(e){const{onChange:t,color:n,index:r,value:a}=e,{classes:o}=Po(),[l,u]=y.useState(a),[c,{setTrue:d,setFalse:f}]=Q.useBoolean(!1),h=r%2===1,g=h&&a!=null,m=!h&&a!=null,C=`map ${a} to color ${r}`,w=()=>{u(a),f()},_=()=>{f(),t==null||t(l)},T=Z(a).format({average:!0});return p("div",{"data-testid":`palette-item-${r}`,className:o.paletteItem,children:[i(s.Text,{title:C,style:{opacity:g?1:0},color:"dimmed",size:"sm",className:"palette-value--up palette-value",children:T}),p(s.Popover,{width:200,trapFocus:!0,opened:c,onClose:f,children:[i(s.Popover.Target,{children:i("div",{"data-testid":"palette-item-target",className:"palette-item",onClick:d,style:{"--shadow-color":pt(n).alpha(.5).hex(),backgroundColor:n}})}),i(s.Popover.Dropdown,{children:p(s.Stack,{children:[i(s.NumberInput,{size:"xs",label:"Map a value to this color",value:l,onChange:u}),p(s.Group,{position:"right",children:[i(s.Button,{variant:"subtle",size:"xs",onClick:w,children:"Cancel"}),i(s.Button,{"data-testid":"palette-item-ok",size:"xs",onClick:_,children:"OK"})]})]})})]}),i(s.Text,{title:C,style:{opacity:m?1:0},color:"dimmed",size:"sm",className:"palette-value--bottom palette-value",children:T})]})}const aw=k.observer(({model:e})=>{const{classes:t}=Po(),n=x.range(0,13,1).map(r=>100/12*r).map(r=>[e.interpolation.getColor(r),r]);return i("div",{className:t.palette,children:n.map(([r,a],o)=>i(iw,{index:o,color:r,value:e.getStepFromValue(a),onChange:l=>e.changeStep(l,a)},r))})}),sw=k.observer(function(t){const n=Q.useCreation(()=>new rw,[]);return y.useEffect(()=>{n.fromProps(t)}),n.interpolation==null?null:i(aw,{model:n})}),ow=e=>{const{value:t,onChange:n,colorManager:r}=e,a=r.getColorInterpolations(),[o,l]=y.useState(t),u=r.decodeInterpolation(o.interpolation)||a[0],[c,{setTrue:d,setFalse:f}]=Q.useBoolean(),h=a.map(_=>({label:_.displayName,value:r.encodeColor(_),group:_.category}));function g(_){_&&l(T=>({...T,interpolation:_}))}const m=()=>{f(),n==null||n(te.toJS(o))};function C(_){l(T=>({...T,steps:_}))}const w=()=>{f(),l(t)};return p(B,{children:[i(s.Button,{variant:"outline",onClick:d,children:u==null?void 0:u.displayName}),i(s.Modal,{size:508,title:"Setup color interpolation",opened:c,onClose:f,zIndex:320,children:c&&p(s.Stack,{"data-testid":"color-interpolation-modal",children:[i(s.Select,{label:"Color style",value:o.interpolation,data:h,onChange:g,withinPortal:!0,zIndex:340,maxDropdownHeight:500}),i(sw,{steps:o.steps,interpolation:u,onChange:C}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:w,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:m,children:"OK"})]})]})})]})},lw=["static","interpolation","none"].map(e=>({label:x.capitalize(e),value:e})),uw=[{from:0,to:0},{from:100,to:100}];function Bo(e){return e?x.isString(e)?e==="none"?"none":"static":"interpolation":"none"}function cw(e,t){var n;return Bo(t)==="static"?t:(n=e.getStaticColors()[0])==null?void 0:n.value}function dw(e,t){return x.isObject(t)?t:{steps:uw,interpolation:e.encodeColor(e.getColorInterpolations()[0])}}const pw=y.forwardRef((e,t)=>{const{colorManager:n}=y.useContext(ct),[r,a]=y.useState(Bo(e.value)),[o,l]=y.useState(cw(n,e.value)),u=Q.useLatest(o),[c,d]=y.useState(dw(n,e.value)),f=Q.useLatest(c),h=C=>{var w,_,T;a(C||"none"),C==="static"?(w=e.onChange)==null||w.call(e,u.current):C==="none"||!C?(_=e.onChange)==null||_.call(e,"none"):(T=e.onChange)==null||T.call(e,f.current)},g=C=>{var w;l(C),(w=e.onChange)==null||w.call(e,C)},m=C=>{var w;d(C),(w=e.onChange)==null||w.call(e,C)};return p(s.Stack,{align:"stretch",children:[i(s.Select,{label:"Cell background",value:r||"none",onChange:h,data:lw}),r==="static"&&i($e,{value:o,onChange:g}),r==="interpolation"&&i(ow,{colorManager:n,value:c,onChange:m})]})}),hw={[at.eloc]:"ELOC"},fw=Object.values(at).map(e=>({label:x.get(hw,e,x.capitalize(e)),value:e})),gw=y.forwardRef(({label:e,value:t,onChange:n,sx:r},a)=>i(s.Select,{ref:a,label:e,data:fw,value:t,onChange:n,sx:r})),mw=y.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:a,setFalse:o}]=Q.useBoolean(),[l,u]=y.useState(e),c=()=>{o(),t(l)},d=()=>{o(),u(e)},f=()=>{u(zo)};return y.useEffect(()=>{u(e)},[e]),p(B,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Custom Cell Content"}),i(s.Modal,{size:800,title:"Custom cell content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(s.Box,{sx:{position:"relative"},children:i(De,{height:"500px",defaultLanguage:"javascript",value:l,onChange:h=>u(h??""),theme:"vs-dark",options:{minimap:{enabled:!1}}})}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:c,children:"OK"})]})]})]})})]})}),yw=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],yi=()=>i(s.Text,{color:"dimmed",size:12,children:"px"}),bw=({control:e,index:t,watch:n,remove:r,column:a})=>{const o=n(`columns.${t}.value_type`);return p(s.Stack,{my:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,children:[i(v.Controller,{name:`columns.${t}.label`,control:e,render:({field:l})=>i(s.TextInput,{label:"Label",required:!0,id:`col-label-${t}`,sx:{flex:1},...l})}),i(v.Controller,{name:`columns.${t}.value_field`,control:e,render:({field:l})=>i(W,{label:"Value Field",required:!0,...l})})]}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`columns.${t}.value_type`,control:e,render:({field:l})=>i(gw,{label:"Value Type",sx:{flex:1},...l})}),o===at.custom&&i(v.Controller,{name:`columns.${t}.func_content`,control:e,render:({field:l})=>i(mw,{value:l.value??zo,onChange:u=>l.onChange(u??"")})})]}),i(s.Divider,{mb:-10,variant:"dashed",label:"Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(s.NumberInput,{hideControls:!0,label:"Min Width",rightSection:i(yi,{}),disabled:!0}),i(v.Controller,{name:`columns.${t}.width`,control:e,render:({field:l})=>i(s.NumberInput,{hideControls:!0,label:"Width",rightSection:i(yi,{}),...l})}),i(s.NumberInput,{hideControls:!0,label:"Max Width",rightSection:i(yi,{}),disabled:!0})]}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`columns.${t}.align`,control:e,render:({field:l})=>i(s.Select,{label:"Alignment",data:yw,...l})})}),i(v.Controller,{name:`columns.${t}.cellBackgroundColor`,control:e,render:({field:l})=>i(pw,{...l})}),i(s.Divider,{mb:4,mt:12,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(t),children:"Delete this column"})]})},vw=({control:e,watch:t})=>{const{fields:n,append:r,remove:a,update:o}=v.useFieldArray({control:e,name:"columns"}),l=()=>{const c=ke.randomId();r({id:c,label:c,align:"center",value_field:"",value_type:at.string,width:""})};t("columns");const u=t("use_raw_columns");return p(B,{children:[i(v.Controller,{name:"use_raw_columns",control:e,render:({field:c})=>i(s.Switch,{mt:20,mb:20,label:"Use Original Data Columns",checked:c.value,onChange:d=>c.onChange(d.currentTarget.checked)})}),!u&&i(s.Stack,{children:p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[n.map((c,d)=>i(s.Tabs.Tab,{value:d.toString(),children:d+1},c.id)),i(s.Tabs.Tab,{onClick:l,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),n.map((c,d)=>i(s.Tabs.Panel,{value:d.toString(),children:i(bw,{control:e,watch:t,index:d,column:c,remove:a},d)},c.id))]})})]})};function xw({control:e,watch:t}){return t(["horizontalSpacing","verticalSpacing","fontSize","striped","highlightOnHover"]),p(s.Stack,{spacing:"xs",children:[p(s.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:[i(v.Controller,{name:"horizontalSpacing",control:e,render:({field:n})=>i(s.TextInput,{label:"Horizontal Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"verticalSpacing",control:e,render:({field:n})=>i(s.TextInput,{label:"Vertical Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})})]}),i(s.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:i(v.Controller,{name:"fontSize",control:e,render:({field:n})=>i(s.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})})}),p(s.Group,{position:"apart",grow:!0,children:[i(v.Controller,{name:"striped",control:e,render:({field:n})=>i(s.Switch,{label:"Striped",checked:n.value,onChange:r=>n.onChange(r.currentTarget.checked)})}),i(v.Controller,{name:"highlightOnHover",control:e,render:({field:n})=>i(s.Switch,{label:"Highlight on hover",checked:n.value,onChange:r=>n.onChange(r.currentTarget.checked)})})]})]})}function ww({columns:e,...t}){return{...t,columns:e.map(({id:n,...r})=>({id:n??ke.randomId(),...r}))}}function Cw({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},t,Eo),[t]),a=y.useMemo(()=>ww(r),[r]);y.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return u(["id_field"]),p("form",{onSubmit:l(n),children:[p(s.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Table Config"}),i(s.ActionIcon,{type:"submit","aria-label":"save config",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"Columns",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Columns",children:"Columns"}),i(s.Tabs.Tab,{value:"Style",children:"Style"})]}),p(s.Tabs.Panel,{value:"Columns",children:[i(v.Controller,{name:"id_field",control:o,render:({field:g})=>i(W,{label:"ID Field",required:!0,...g})}),i(s.Divider,{mt:20,mb:10,variant:"dashed"}),i(vw,{control:o,watch:u})]}),i(s.Tabs.Panel,{value:"Style",children:i(xw,{control:o,watch:u})})]})]})}function Sw(e){const{columns:t,...n}=e;return{...e,columns:t.map(r=>({...r,align:r.align??"left"}))}}function _w(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{id_field:a,columns:o,...l}=e;return{...l,id_field:r(a),columns:o.map(u=>({...u,value_field:r(u.value_field)}))}}catch(n){throw console.error("[Migration failed]",n),n}}function kw(e){const{columns:t,...n}=e;return{...n,columns:t.map(r=>({...r,align:r.align??"left",cellBackgroundColor:r.cellBackgroundColor??"",width:r.width??""}))}}class Tw extends ge{constructor(){super(...arguments);q(this,"VERSION",5)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{columns:r,...a}=n.config;return{...n,version:2,config:{...a,columns:r.map(({id:o,...l})=>({id:o??ke.randomId(),...l}))}}}),this.version(3,n=>({...n,version:3,config:Sw(n.config)})),this.version(4,(n,r)=>({...n,version:4,config:_w(n.config,r)})),this.version(5,n=>({...n,version:5,config:kw(n.config)}))}}const bi={createConfig(){return{version:5,config:x.cloneDeep(Eo)}},displayName:"Table",displayGroup:"Others",migrator:new Tw,name:"table",viewRender:tw,configRender:Cw,triggers:[mi]},Vo=["function text({ data, variables, filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
|
|
297
|
+
`),vi={func_content:Vo,horizontal_align:"left",font_size:"14px",font_weight:"normal"},Dw=k.observer(({context:e})=>{const t=ye(),{value:n=vi}=R(e.instanceData,"config"),{variables:r}=e,a=e.data,{func_content:o,horizontal_align:l,font_size:u,font_weight:c}=n,d=y.useMemo(()=>r.reduce((h,g)=>{const m=mt(g,a);return h[g.name]=Ze(g,m),h},{}),[r,a]),f=y.useMemo(()=>new Function(`return ${o}`)()({data:a,variables:d,filters:t.payloadForSQL.filters,context:t.payloadForSQL.context}),[o,a,d,t.payloadForSQL]);return i(s.Text,{align:l,weight:c,sx:{fontSize:u},children:f})}),Iw=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return i(s.Box,{sx:{position:"relative"},children:i(De,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Mw=y.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:a,setFalse:o}]=Q.useBoolean(),[l,u]=y.useState(e),c=()=>{o(),t(l)},d=()=>{o(),u(e)},f=()=>{u(Vo)};return y.useEffect(()=>{u(e)},[e]),p(B,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Edit Content"}),i(s.Modal,{size:800,title:"Text content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(Iw,{value:l,onChange:u}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:c,children:"OK"})]})]})]})})]})}),Aw=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}];function zw({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},t,vi),[t]),a=y.useMemo(()=>{const{func_content:g,horizontal_align:m,font_size:C,font_weight:w}=r;return{func_content:g,horizontal_align:m,font_size:C,font_weight:w}},[r]);y.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]),u(["func_content","horizontal_align","font_size","font_weight"]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{weight:500,children:"Configurations"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Stack,{spacing:10,children:[i(v.Controller,{name:"func_content",control:o,render:({field:g})=>i(Mw,{...g})}),i(s.Divider,{mt:10,mb:-10,variant:"dashed",label:"Style",labelPosition:"center"}),i(v.Controller,{name:"horizontal_align",control:o,render:({field:g})=>i(s.Select,{label:"Horizontal Alignment",data:Aw,...g})}),i(v.Controller,{name:"font_size",control:o,render:({field:g})=>i(s.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1},...g})}),i(s.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:i(v.Controller,{name:"font_weight",control:o,render:({field:g})=>i(Zs,{label:"Font Weight",...g})})})]})]})})}class Ew extends ge{constructor(){super(...arguments);q(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const $w={displayName:"Text",displayGroup:"Others",migrator:new Ew,name:"text",viewRender:Dw,configRender:zw,createConfig(){return{version:1,config:x.cloneDeep(vi)}}},Lw=()=>p("svg",{width:"64",height:"64",viewBox:"0 0 64 64",fill:"none",children:[i("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M22.49 27.79H14.47C13.55 27.79 12.81 28.53 12.81 29.45C12.81 30.37 13.55 31.11 14.47 31.11H22.49C23.41 31.11 24.15 30.37 24.15 29.45C24.15 28.54 23.41 27.79 22.49 27.79ZM34.32 31.28C35.22 31.32 35.7 31.82 35.74 32.76C35.78 33.54 35.37 34.3 34.51 35.04C33.52 35.9 33.03 36.95 33.03 38.19V38.81H34.82V38.25C34.78 37.59 35.07 37.02 35.68 36.52C37.12 35.41 37.82 34.15 37.78 32.75C37.66 30.53 36.5 29.35 34.32 29.23C32.3 29.23 31.05 30.46 30.55 32.93L32.53 33.55C32.82 32.04 33.42 31.28 34.32 31.28ZM35 39.93H32.84V42.21H35V39.93ZM14.83 36.42H18.54C19.46 36.42 20.2 37.17 20.2 38.08C20.2 39 19.46 39.74 18.54 39.74H10.52C9.6 39.74 8.86 39 8.86 38.08C8.86 37.61 9.06 37.19 9.37 36.89H5.66C4.74 36.89 4 36.15 4 35.23C4 34.31 4.74 33.57 5.66 33.57H13.68C14.6 33.57 15.34 34.31 15.34 35.23C15.34 35.7 15.14 36.12 14.83 36.42ZM50.94 36.85H58.74C59.66 36.85 60.4 37.59 60.41 38.51C60.41 39.43 59.67 40.17 58.75 40.17H54.26C54.56 40.47 54.74 40.88 54.74 41.34C54.74 42.26 54 43 53.08 43H50.94V36.85Z",fill:"#B8C0CC"}),i("path",{d:"M18.39 32.28H16.51V35.02H18.39V32.28Z",fill:"#9399A5"}),i("path",{d:"M46.87 15H20.69C18.38 15 16.5 16.88 16.5 19.19V26.22H18.38V23.45H49.18V47.68H18.38V41.07H16.5V49.55H51.05V19.19C51.06 16.88 49.18 15 46.87 15ZM39.46 20.73C38.81 20.73 38.29 20.2 38.29 19.56C38.29 18.92 38.82 18.39 39.46 18.39C40.11 18.39 40.63 18.92 40.63 19.56C40.63 20.2 40.11 20.73 39.46 20.73ZM43.22 20.73C42.57 20.73 42.05 20.2 42.05 19.56C42.05 18.92 42.58 18.39 43.22 18.39C43.87 18.39 44.39 18.92 44.39 19.56C44.39 20.2 43.87 20.73 43.22 20.73ZM46.97 20.73C46.32 20.73 45.8 20.2 45.8 19.56C45.8 18.92 46.33 18.39 46.97 18.39C47.62 18.39 48.14 18.92 48.14 19.56C48.14 20.2 47.62 20.73 46.97 20.73Z",fill:"#9399A5"})]});function No(e,t){const n=x.get(e,t,"");if(n)throw new Error(n)}async function Ow(e,t,n,r={}){const a={"X-Requested-With":"XMLHttpRequest","Content-Type":r.string?"application/x-www-form-urlencoded":"application/json",...r.headers},o={baseURL:e,method:"POST",url:t,params:r.params,headers:a};return o.data=r.string?JSON.stringify(n):n,xt(o).then(l=>l.data).catch(l=>Promise.reject(l))}const Pw=({conf:e,panelData:t})=>async()=>{const{expertSystemURL:n,path:r,goal:a,question:o}=e;if(!r||!a||!o)return;const l=yc(t);if(!l)return;const u={dashboard:a,panel:o,data:l};try{const c=n.startsWith("http")?n:window.location.origin;return await Ow(c,`/expert/v3/devtable/${r}`,u,{})}catch(c){throw No(c,"response.data.detail"),No(c,"response.data.error"),console.error(c),c}},xi={expertSystemURL:"",path:"",goal:"",question:""},wi={height:"100%",overflowY:"auto",...Lr},qo=({message:e})=>i(s.Box,{sx:wi,children:i("div",{dangerouslySetInnerHTML:{__html:e},style:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45"}})}),Bw=({error:e,width:t,height:n})=>{const r=e.message;if(r.startsWith("<"))return i(qo,{message:r});const o=n-25-20-30;return i(s.Center,{sx:{width:"100%",height:o},children:p(s.Stack,{align:"center",spacing:20,children:[i(Lw,{}),i(qo,{message:r})]})})};function Vw({context:e}){const{value:t}=R(e.instanceData,"config"),n=y.useMemo(()=>x.defaultsDeep({},t,xi),[t]),{width:r,height:a}=e.viewport,o=e.data,{data:l,error:u,loading:c}=Q.useRequest(Pw({conf:n,panelData:o}),{refreshDeps:[o,n]});return!r||!a||!n?null:c?i(s.Box,{sx:{position:"relative",height:a},children:i(s.LoadingOverlay,{visible:!0})}):u?i(s.Box,{sx:wi,"data-enable-scrollbar":!0,children:i(Bw,{error:u,width:r,height:a})}):!l||!Array.isArray(l.replies)||l.replies.length===0?null:i(s.Box,{sx:wi,"data-enable-scrollbar":!0,children:l.replies.map((d,f)=>i("div",{dangerouslySetInnerHTML:{__html:d.interpretation.html}},f))})}function Nw({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},t,xi),[t]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l(["expertSystemURL","goal","path","question"]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,r),[d,r]);return i("form",{onSubmit:o(n),children:p(s.Stack,{children:[p(s.Group,{grow:!0,children:[i(v.Controller,{name:"expertSystemURL",control:a,render:({field:h})=>i(s.TextInput,{label:"Expert System URL",...h})}),i(v.Controller,{name:"path",control:a,render:({field:h})=>i(s.TextInput,{label:"Path",required:!0,...h})})]}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:"goal",control:a,render:({field:h})=>i(s.TextInput,{label:"Goal",required:!0,...h})}),i(v.Controller,{name:"question",control:a,render:({field:h})=>i(s.TextInput,{label:"Question",required:!0,...h})})]}),i(s.Divider,{variant:"dashed",mt:16,mb:8}),i(s.Button,{type:"submit",variant:"filled",color:"blue",leftIcon:i(D.DeviceFloppy,{size:20}),disabled:!f,sx:{alignSelf:"flex-end"},children:"Submit Changes"})]})})}class qw extends ge{constructor(){super(...arguments);q(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const Fw={displayName:"Merico GQM",displayGroup:"Merico suite",migrator:new qw,name:"mericoGQM",viewRender:Vw,configRender:Nw,createConfig(){return{version:1,config:x.cloneDeep(xi)}}};function Gw(e,t,n){if(!e)return n[0];try{return[t,U(t).add(1,"year").subtract(1,"day").valueOf()]}catch(r){return console.error(r),n[0]}}function Ww(e,t,n){const r=Gw(e,t,n);return{top:50,left:25,right:5,cellSize:["auto",13],range:r,itemStyle:{borderColor:"#eee"},splitLine:{show:!0},dayLabel:{firstDay:1},monthLabel:{position:"end"},yearLabel:{show:!0}}}function jw(e){return{heat_block:function(r){if(!e.heat_block.value_formatter)return r;try{return Z(r).format(e.heat_block.value_formatter)}catch(a){return console.error(a),r}}}}function Rw(e,t){return{show:!e,selectedMode:"single",top:5,right:5,data:t.map(n=>({name:n,icon:"circle"}))}}function Yw(e,t,n,r){const{calendar:a,heat_block:o}=e,l=O(a.data_key),u=O(o.data_key);return t?{type:"heatmap",name:"heatmap",coordinateSystem:"calendar",calendarIndex:0,data:r[l.queryID].map(c=>[x.get(c,l.columnKey),x.get(c,u.columnKey)])}:Object.entries(n).map(([c,d])=>({type:"heatmap",name:c,coordinateSystem:"calendar",calendarIndex:0,data:d.map(f=>[x.get(f,l.columnKey),x.get(f,u.columnKey)])}))}const Qw=e=>{try{return Z(e).format({trimMantissa:!0,mantissa:2})}catch{return e}};function Uw({conf:e,valueFormatters:t,dataDict:n,params:r}){const{value:a}=r,[o,l]=a,c=[{label:e.heat_block.name,value:t.heat_block(l),style:{label:"",value:""}}],d=n[o];return d&&e.tooltip.metrics.forEach(f=>{const h=O(f.data_key);c.push({label:f.name,value:Qw(x.get(d,h.columnKey,"")),style:{label:"",value:""}})}),c}function Kw(e,t,n){const r=O(e.calendar.data_key),a=x.keyBy(t[r.queryID],r.columnKey);return{confine:!0,formatter:function(o){const u=Uw({conf:e,valueFormatters:n,dataDict:a,params:o}).map(f=>`
|
|
298
298
|
<tr>
|
|
299
299
|
<th style="text-align: right;">
|
|
300
300
|
<div style="${f.style.label}">${f.label}</div>
|
|
@@ -320,13 +320,13 @@ Check the top-level render call using <`+V+">.")}return z}}function Tu(S,z){{if(
|
|
|
320
320
|
</thead>
|
|
321
321
|
<tbody>${u.join("")}</tbody>
|
|
322
322
|
</table>
|
|
323
|
-
`}}}function Uw(e,t,n){const r=Yt(e.heat_block.min,n),a=Yt(e.heat_block.max,n);return{min:r,max:a,calculable:!0,orient:"horizontal",left:t?"center":5,top:0,itemWidth:15}}const Kw={tooltip:{confine:!0},grid:{containLabel:!0}},Xw=e=>U(e).get("year");function Jw(e,t){const n=O(e.calendar.data_key),r=t[n.queryID],a=x.groupBy(r,d=>Xw(d[n.columnKey])),o=Object.keys(a),l=r.map(d=>U(d[n.columnKey]).valueOf()),u=x.min(l),c=x.max(l);return{minDate:u??0,maxDate:c??0,dateSpan:U(c).diff(u,"day"),dataByYear:a,years:o}}function Zw(e,t,n){const r=n.reduce((h,g)=>{const m=mt(g,t);return h[g.name]=Ze(g,m),h},{}),a=Gw(e),{dateSpan:o,minDate:l,dataByYear:u,years:c}=Jw(e,t),d=o<=366,f={calendar:Fw(d,l,c),series:jw(e,d,u,t),tooltip:Qw(e,t,a),visualMap:Uw(e,d,r),legend:Ww(d,c)};return x.defaultsDeep({},f,Kw)}function Hw(e){return i(B,{})}function e0(e){return i(s.Text,{children:"Click heat block"})}const No={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:e0,configRender:Hw,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"}]},Ci={calendar:{data_key:"",locale:"EN"},heat_block:{min:{type:"static",value:0},max:{type:"static",value:100},name:"Value",data_key:"",value_formatter:Ie},tooltip:{metrics:[]}};ie.use([F.DataZoomComponent,he.BarChart,he.LineChart,he.HeatmapChart,F.CalendarComponent,F.GridComponent,F.LegendComponent,F.TooltipComponent,F.VisualMapComponent,Ee.CanvasRenderer]);function t0({name:e},t){const n=t.getOption();n.calendar.forEach(r=>{r.range=e}),t.setOption(n)}function n0({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=zt(t,e.calendar.data_key),u=Ke(a.triggerManager,No.id),c=y.useCallback(h=>{const[g,m]=h.value,C=x.get(l,g,{error:"rowData is not found"});u.forEach(w=>{a.runInteraction(w.id,{...h,rowData:C})})},[l,u,a]),d=y.useMemo(()=>({click:c,legendselectchanged:t0}),[c]),f=y.useMemo(()=>Zw(e,t,o),[e,t]);return i(ze,{echarts:ie,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,opts:{locale:e.calendar.locale},theme:"merico-light"})}function r0({context:e,instance:t}){const n=Xe({vizManager:e.vizManager,instance:t}),{value:r}=R(e.instanceData,"config"),{variables:a}=e,o=y.useMemo(()=>x.defaults({},r,Ci),[r]),l=e.data,{width:u,height:c}=e.viewport;return!o.calendar.data_key||!o.heat_block.data_key||!u||!c?null:i(Ve,{width:u,height:c,children:i(n0,{variables:a,width:tt(u),height:nt(c),data:l,conf:o,interactionManager:n})})}function i0({control:e,watch:t}){return t(["heat_block"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.data_key",control:e,render:({field:n})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"heat_block.name",control:e,render:({field:n})=>i(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.min",control:e,render:({field:n})=>i(Rt,{label:"Min Value",...n})}),i(v.Controller,{name:"heat_block.max",control:e,render:({field:n})=>i(Rt,{label:"Max Value",...n})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Value Format",labelPosition:"center"}),i(v.Controller,{name:"heat_block.value_formatter",control:e,render:({field:n})=>i(We,{...n})})]})}const a0=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),s0=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(B,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(D.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),i(s.Divider,{variant:"dashed",my:10}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(a0,{control:e,index:g,remove:a},h.id)},h.id))]})]})};function o0({control:e,watch:t}){return i(s0,{control:e,watch:t})}const l0=[{label:"Chinese",value:"ZH"},{label:"English",value:"EN"}];function u0({control:e,watch:t}){return t(["calendar"]),p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"calendar.data_key",control:e,render:({field:n})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...n})})}),i(v.Controller,{name:"calendar.locale",control:e,render:({field:n})=>i(s.Select,{label:"Language",required:!0,data:l0,sx:{flex:1},...n})})]})}function c0({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},t,Ci),[t]),a=y.useMemo(()=>x.cloneDeep(r),[r]);y.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Calendar Heatmap Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"Calendar",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Calendar",children:"Calendar"}),i(s.Tabs.Tab,{value:"Heat Block",children:"Heat Block"}),i(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"})]}),i(s.Tabs.Panel,{value:"Calendar",children:i(u0,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Heat Block",children:i(i0,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(o0,{control:o,watch:u})})]})]})})}function d0(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{calendar:a,heat_block:o,tooltip:l,...u}=e;return{...u,calendar:{...a,data_key:r(a.data_key)},heat_block:{...o,data_key:r(o.data_key)},tooltip:{...l,metrics:l.metrics.map(c=>({...c,data_key:r(c.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}function p0(e){const{heat_block:t}=e;let{min:n,max:r}=t;return typeof n!="number"&&(n=0),typeof r!="number"&&(r=100),{...e,heat_block:{...t,min:{type:"static",value:n},max:{type:"static",value:r}}}}class h0 extends ge{constructor(){super(...arguments);q(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>({...n,version:2,config:d0(n.config,r)})),this.version(3,n=>({...n,version:3,config:p0(n.config)}))}}const f0={displayName:"Heatmap(Calendar)",displayGroup:"ECharts-based charts",migrator:new h0,name:"calendarHeatmap",viewRender:r0,configRender:c0,createConfig:()=>({version:3,config:Ci}),triggers:[No]},Si={x_axes:[{id:"initial-x",min:"",max:"",name:"X Axis",data_key:"",position:"bottom",label_formatter:Ie,show:!0}],y_axis:{name:"Y Axis",data_key:"",axisLabel:{formatter:{...Ue},overflow:je},nameAlignment:"center"},series:[],tooltip:{metrics:[]},reference_lines:[]};function g0(){const e=new Date().getTime().toString();return{id:e,min:"",max:"",name:e,data_key:"",position:"bottom",label_formatter:Ie,show:!0}}function m0(){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:Wt,xAxisIndex:"0"}}function y0(){const e=new Date().getTime().toString();return{id:e,name:e,template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,xAxisIndex:"0"}}function b0(e){const t=e.x_axes.some(o=>o.position==="top"&&!!o.name&&o.show);let n=0;t&&(n+=15);const r=e.x_axes.some(o=>o.position==="bottom"&&!!o.name&&o.show);let a=0;return r&&(a+=15),e.series.some(o=>!o.hide_in_legend)&&(a+=20),{top:n,right:5,bottom:a,left:5,containLabel:!0}}function v0(e){switch(e){case"bar":return"roundRect";case"scatter":return"circle"}}function x0(e){const t={show:!0,bottom:0,left:"center",type:"scroll"};return t.data=e.filter(n=>!n.hide_in_legend).map(({name:n,type:r})=>({name:n,icon:v0(r)})),t}function w0(e,t,n,r){return e.map(a=>{const o=a.orientation==="horizontal",l=o?"yAxis":"xAxis",u=o?"insideEndTop":"end";return{name:a.name,type:"line",hide_in_legend:!a.show_in_legend,xAxisIndex:a.xAxisIndex,data:[],lineStyle:a.lineStyle,markLine:{data:[{name:a.name,[l]:Number(n[a.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:a.lineStyle,label:{formatter:function(){return a.template?Kn(a.template,t,r):""},position:u}}}})}function ir(e,t,n){const r=ft(e,t),a=ft(e,n);return x.zip(a,r)}function C0(e,t,n,r){const a=ir(t,n,r);return x.unionBy(a,e,0)}function S0({dataTemplate:e,data:t,name_data_key:n,value_data_key:r,valueTypedXAxis:a}){return a?C0(e,t,n,r):ir(t,n,r)}function _0({dataTemplate:e,data:t,aggregation_on_value:n,name_data_key:r,value_data_key:a,valueTypedXAxis:o}){if(!n||n.type==="none")return S0({dataTemplate:e,data:t,name_data_key:r,value_data_key:a,valueTypedXAxis:o});const l=ir(t,r,a),u=x.groupBy(l,"0");return e.map(([d])=>{const h=u[d].map(m=>m[1]),g=Xr(h,n);return[d,g]})}function k0({group_by_key:e,data:t,value_data_key:n,name_data_key:r}){const{queryID:a,columnKey:o}=O(e),l=x.groupBy(t[a],o);return Object.entries(l).forEach(([u,c])=>{l[u]=ir({[a]:c},r,n)}),l}function T0({y_axis:e},{data_key:t,xAxisIndex:n,label_position:r,name:a,group_by_key:o,aggregation_on_value:l,stack:u,color:c,hide_in_legend:d,invisible:f,id:h,...g},m,C,w,_,T){const M={label:{show:!!r,position:r,formatter:T[n??"default"]},name:a,yAxisId:"main-y-axis",xAxisIndex:n,stack:u,color:f?"transparent":c,hide_in_legend:d,labelLayout:{hideOverlap:!0},emphasis:{disabled:!0},...g};if(!o||o===e.data_key)return M.data=_0({dataTemplate:m,data:w,aggregation_on_value:l,name_data_key:e.data_key,value_data_key:t,valueTypedXAxis:C}),M;const P=k0({group_by_key:o,data:w,name_data_key:e.data_key,value_data_key:t});return Object.entries(P).map(([G,$])=>{const L=x.cloneDeep(M);return L.name=G,L.color=void 0,L.data=$,L})}function D0(e,t,n,r,a,o,l){const u=t.map(d=>[d,0]);return e.series.map(d=>T0(e,d,u,n,r,l,a)).flat().concat(w0(e.reference_lines,o,l,r))}function I0(e,t){const n=e.find(u=>u.axisDim==="y"&&u.axisId==="main-y-axis");if(!n)return"";const{name:r,axisType:a,axisValue:o,axisIndex:l}=n;return a==="yAxis.category"?r:qt(t.y_axis.axisLabel.formatter)(o,l)}function M0(e,t,n){const r=t.reduce((a,{xAxisIndex:o,name:l})=>(a[l]=o,a),{});return{trigger:"axis",axisPointer:{type:"shadow"},formatter:function(a){const o=Array.isArray(a)?a:[a];if(o.length===0)return"";const l=o.map(({seriesName:d,marker:f,value:h})=>{if(Array.isArray(h)&&h.length===2&&(h=h[0]),!d)return h;const g=r[d],m=n[g]??n.default;return`
|
|
323
|
+
`}}}function Xw(e,t,n){const r=Yt(e.heat_block.min,n),a=Yt(e.heat_block.max,n);return{min:r,max:a,calculable:!0,orient:"horizontal",left:t?"center":5,top:0,itemWidth:15}}const Jw={tooltip:{confine:!0},grid:{containLabel:!0}},Zw=e=>U(e).get("year");function Hw(e,t){const n=O(e.calendar.data_key),r=t[n.queryID],a=x.groupBy(r,d=>Zw(d[n.columnKey])),o=Object.keys(a),l=r.map(d=>U(d[n.columnKey]).valueOf()),u=x.min(l),c=x.max(l);return{minDate:u??0,maxDate:c??0,dateSpan:U(c).diff(u,"day"),dataByYear:a,years:o}}function e0(e,t,n){const r=n.reduce((h,g)=>{const m=mt(g,t);return h[g.name]=Ze(g,m),h},{}),a=jw(e),{dateSpan:o,minDate:l,dataByYear:u,years:c}=Hw(e,t),d=o<=366,f={calendar:Ww(d,l,c),series:Yw(e,d,u,t),tooltip:Kw(e,t,a),visualMap:Xw(e,d,r),legend:Rw(d,c)};return x.defaultsDeep({},f,Jw)}function t0(e){return i(B,{})}function n0(e){return i(s.Text,{children:"Click heat block"})}const Fo={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:n0,configRender:t0,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"}]},Ci={calendar:{data_key:"",locale:"EN"},heat_block:{min:{type:"static",value:0},max:{type:"static",value:100},name:"Value",data_key:"",value_formatter:Ie},tooltip:{metrics:[]}};ie.use([F.DataZoomComponent,he.BarChart,he.LineChart,he.HeatmapChart,F.CalendarComponent,F.GridComponent,F.LegendComponent,F.TooltipComponent,F.VisualMapComponent,Ee.CanvasRenderer]);function r0({name:e},t){const n=t.getOption();n.calendar.forEach(r=>{r.range=e}),t.setOption(n)}function i0({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=zt(t,e.calendar.data_key),u=Ke(a.triggerManager,Fo.id),c=y.useCallback(h=>{const[g,m]=h.value,C=x.get(l,g,{error:"rowData is not found"});u.forEach(w=>{a.runInteraction(w.id,{...h,rowData:C})})},[l,u,a]),d=y.useMemo(()=>({click:c,legendselectchanged:r0}),[c]),f=y.useMemo(()=>e0(e,t,o),[e,t]);return i(ze,{echarts:ie,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,opts:{locale:e.calendar.locale},theme:"merico-light"})}function a0({context:e,instance:t}){const n=Xe({vizManager:e.vizManager,instance:t}),{value:r}=R(e.instanceData,"config"),{variables:a}=e,o=y.useMemo(()=>x.defaults({},r,Ci),[r]),l=e.data,{width:u,height:c}=e.viewport;return!o.calendar.data_key||!o.heat_block.data_key||!u||!c?null:i(Ve,{width:u,height:c,children:i(i0,{variables:a,width:tt(u),height:nt(c),data:l,conf:o,interactionManager:n})})}function s0({control:e,watch:t}){return t(["heat_block"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.data_key",control:e,render:({field:n})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"heat_block.name",control:e,render:({field:n})=>i(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.min",control:e,render:({field:n})=>i(Rt,{label:"Min Value",...n})}),i(v.Controller,{name:"heat_block.max",control:e,render:({field:n})=>i(Rt,{label:"Max Value",...n})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Value Format",labelPosition:"center"}),i(v.Controller,{name:"heat_block.value_formatter",control:e,render:({field:n})=>i(We,{...n})})]})}const o0=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),l0=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(B,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(D.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),i(s.Divider,{variant:"dashed",my:10}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(o0,{control:e,index:g,remove:a},h.id)},h.id))]})]})};function u0({control:e,watch:t}){return i(l0,{control:e,watch:t})}const c0=[{label:"Chinese",value:"ZH"},{label:"English",value:"EN"}];function d0({control:e,watch:t}){return t(["calendar"]),p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"calendar.data_key",control:e,render:({field:n})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...n})})}),i(v.Controller,{name:"calendar.locale",control:e,render:({field:n})=>i(s.Select,{label:"Language",required:!0,data:c0,sx:{flex:1},...n})})]})}function p0({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},t,Ci),[t]),a=y.useMemo(()=>x.cloneDeep(r),[r]);y.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Calendar Heatmap Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"Calendar",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Calendar",children:"Calendar"}),i(s.Tabs.Tab,{value:"Heat Block",children:"Heat Block"}),i(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"})]}),i(s.Tabs.Panel,{value:"Calendar",children:i(d0,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Heat Block",children:i(s0,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(u0,{control:o,watch:u})})]})]})})}function h0(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{calendar:a,heat_block:o,tooltip:l,...u}=e;return{...u,calendar:{...a,data_key:r(a.data_key)},heat_block:{...o,data_key:r(o.data_key)},tooltip:{...l,metrics:l.metrics.map(c=>({...c,data_key:r(c.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}function f0(e){const{heat_block:t}=e;let{min:n,max:r}=t;return typeof n!="number"&&(n=0),typeof r!="number"&&(r=100),{...e,heat_block:{...t,min:{type:"static",value:n},max:{type:"static",value:r}}}}class g0 extends ge{constructor(){super(...arguments);q(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>({...n,version:2,config:h0(n.config,r)})),this.version(3,n=>({...n,version:3,config:f0(n.config)}))}}const m0={displayName:"Heatmap(Calendar)",displayGroup:"ECharts-based charts",migrator:new g0,name:"calendarHeatmap",viewRender:a0,configRender:p0,createConfig:()=>({version:3,config:Ci}),triggers:[Fo]},Si={x_axes:[{id:"initial-x",min:"",max:"",name:"X Axis",data_key:"",position:"bottom",label_formatter:Ie,show:!0}],y_axis:{name:"Y Axis",data_key:"",axisLabel:{formatter:{...Ue},overflow:je},nameAlignment:"center"},series:[],tooltip:{metrics:[]},reference_lines:[]};function y0(){const e=new Date().getTime().toString();return{id:e,min:"",max:"",name:e,data_key:"",position:"bottom",label_formatter:Ie,show:!0}}function b0(){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:Wt,xAxisIndex:"0"}}function v0(){const e=new Date().getTime().toString();return{id:e,name:e,template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,xAxisIndex:"0"}}function x0(e){const t=e.x_axes.some(o=>o.position==="top"&&!!o.name&&o.show);let n=0;t&&(n+=15);const r=e.x_axes.some(o=>o.position==="bottom"&&!!o.name&&o.show);let a=0;return r&&(a+=15),e.series.some(o=>!o.hide_in_legend)&&(a+=20),{top:n,right:5,bottom:a,left:5,containLabel:!0}}function w0(e){switch(e){case"bar":return"roundRect";case"scatter":return"circle"}}function C0(e){const t={show:!0,bottom:0,left:"center",type:"scroll"};return t.data=e.filter(n=>!n.hide_in_legend).map(({name:n,type:r})=>({name:n,icon:w0(r)})),t}function S0(e,t,n,r){return e.map(a=>{const o=a.orientation==="horizontal",l=o?"yAxis":"xAxis",u=o?"insideEndTop":"end";return{name:a.name,type:"line",hide_in_legend:!a.show_in_legend,xAxisIndex:a.xAxisIndex,data:[],lineStyle:a.lineStyle,markLine:{data:[{name:a.name,[l]:Number(n[a.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:a.lineStyle,label:{formatter:function(){return a.template?Kn(a.template,t,r):""},position:u}}}})}function ir(e,t,n){const r=ft(e,t),a=ft(e,n);return x.zip(a,r)}function _0(e,t,n,r){const a=ir(t,n,r);return x.unionBy(a,e,0)}function k0({dataTemplate:e,data:t,name_data_key:n,value_data_key:r,valueTypedXAxis:a}){return a?_0(e,t,n,r):ir(t,n,r)}function T0({dataTemplate:e,data:t,aggregation_on_value:n,name_data_key:r,value_data_key:a,valueTypedXAxis:o}){if(!n||n.type==="none")return k0({dataTemplate:e,data:t,name_data_key:r,value_data_key:a,valueTypedXAxis:o});const l=ir(t,r,a),u=x.groupBy(l,"0");return e.map(([d])=>{const h=u[d].map(m=>m[1]),g=Xr(h,n);return[d,g]})}function D0({group_by_key:e,data:t,value_data_key:n,name_data_key:r}){const{queryID:a,columnKey:o}=O(e),l=x.groupBy(t[a],o);return Object.entries(l).forEach(([u,c])=>{l[u]=ir({[a]:c},r,n)}),l}function I0({y_axis:e},{data_key:t,xAxisIndex:n,label_position:r,name:a,group_by_key:o,aggregation_on_value:l,stack:u,color:c,hide_in_legend:d,invisible:f,id:h,...g},m,C,w,_,T){const M={label:{show:!!r,position:r,formatter:T[n??"default"]},name:a,yAxisId:"main-y-axis",xAxisIndex:n,stack:u,color:f?"transparent":c,hide_in_legend:d,labelLayout:{hideOverlap:!0},emphasis:{disabled:!0},...g};if(!o||o===e.data_key)return M.data=T0({dataTemplate:m,data:w,aggregation_on_value:l,name_data_key:e.data_key,value_data_key:t,valueTypedXAxis:C}),M;const P=D0({group_by_key:o,data:w,name_data_key:e.data_key,value_data_key:t});return Object.entries(P).map(([G,$])=>{const L=x.cloneDeep(M);return L.name=G,L.color=void 0,L.data=$,L})}function M0(e,t,n,r,a,o,l){const u=t.map(d=>[d,0]);return e.series.map(d=>I0(e,d,u,n,r,l,a)).flat().concat(S0(e.reference_lines,o,l,r))}function A0(e,t){const n=e.find(u=>u.axisDim==="y"&&u.axisId==="main-y-axis");if(!n)return"";const{name:r,axisType:a,axisValue:o,axisIndex:l}=n;return a==="yAxis.category"?r:qt(t.y_axis.axisLabel.formatter)(o,l)}function z0(e,t,n){const r=t.reduce((a,{xAxisIndex:o,name:l})=>(a[l]=o,a),{});return{trigger:"axis",axisPointer:{type:"shadow"},formatter:function(a){const o=Array.isArray(a)?a:[a];if(o.length===0)return"";const l=o.map(({seriesName:d,marker:f,value:h})=>{if(Array.isArray(h)&&h.length===2&&(h=h[0]),!d)return h;const g=r[d],m=n[g]??n.default;return`
|
|
324
324
|
<tr>
|
|
325
325
|
<td>${f}</td>
|
|
326
326
|
<th style="text-align: right; padding: 0 1em;">${d}</th>
|
|
327
327
|
<td style="text-align: left; padding: 0 1em;">${m({value:h})}</td>
|
|
328
328
|
</tr>
|
|
329
|
-
`}),u=ot(e.y_axis.axisLabel.overflow.in_tooltip),c=
|
|
329
|
+
`}),u=ot(e.y_axis.axisLabel.overflow.in_tooltip),c=A0(o,e);return`
|
|
330
330
|
<div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
|
|
331
331
|
<div style="${u}">${c}</div>
|
|
332
332
|
</div>
|
|
@@ -335,7 +335,7 @@ Check the top-level render call using <`+V+">.")}return z}}function Tu(S,z){{if(
|
|
|
335
335
|
${l.join("")}
|
|
336
336
|
</tbody>
|
|
337
337
|
</table>
|
|
338
|
-
`}}}function A0(e){return e.x_axes.reduce((n,{label_formatter:r},a)=>(n[a]=function(l){let u=l;if(typeof l=="object"&&(Array.isArray(l.value)&&l.value.length===2?u=l.value[0]:u=l.value),!r)return u;try{return Z(u).format(r)}catch(c){return console.error(c),u}},n),{default:({value:n})=>n})}function z0(e,t){const n={};return t.map(r=>{const a=mt(r,e);n[r.name]=Ze(r,a)}),n}function E0(e,t){return e.x_axes.map(({min:n,max:r,...a},o)=>{let l=a.position;return l||(l=o>0?"bottom":"top"),{...a,type:"value",min:n||void 0,max:r||void 0,position:l,axisLabel:{show:!0,margin:2,formatter:t[o]??t.default},axisLine:{show:!0},axisTick:{show:!1},splitLine:{show:!0},nameTextStyle:{fontWeight:"bold"},nameLocation:"center",nameGap:15}})}function $0(e,t){const n=t.every(l=>!Number.isNaN(Number(l))),{overflow:r,...a}=e.y_axis.axisLabel,o=it(r.on_axis);return[{data:t,name:e.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"center",fontWeight:"bold"},id:"main-y-axis",axisTick:{show:!0,alignWithLabel:!0},type:n?"value":"category",axisLabel:{...a,...o,formatter:qt(a.formatter)},z:5}]}function L0(e,t,n){if(!e.y_axis.data_key)return{};const r=z0(t,n),a=A0(e),o=O(e.y_axis.data_key),l=x.uniq(t[o.queryID].map(f=>f[o.columnKey])),u=l.every(f=>!Number.isNaN(Number(f))),c=D0(e,l,u,t,a,n,r);return{xAxis:E0(e,a),yAxis:$0(e,l),series:c,tooltip:M0(e,c,a),grid:b0(e),legend:x0(c)}}ie.use([F.DataZoomComponent,he.BarChart,he.LineChart,he.ScatterChart,F.GridComponent,F.LegendComponent,F.TooltipComponent,Ee.CanvasRenderer,F.MarkLineComponent,F.MarkAreaComponent]);function O0({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=zt(t,e.y_axis.data_key),u=Ke(a.triggerManager,Hr.id),c=y.useCallback(h=>{const g=x.get(l,h.name,{error:"rowData is not found"});u.forEach(m=>{a.runInteraction(m.id,{...h,rowData:g})})},[l,u,a]),d=y.useMemo(()=>({click:c}),[c]),f=y.useMemo(()=>L0(e,t,o),[e,t]);return i(ze,{echarts:ie,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function P0({context:e,instance:t}){const n=Xe({vizManager:e.vizManager,instance:t}),{value:r}=R(e.instanceData,"config"),{variables:a}=e,o=y.useMemo(()=>x.defaults({},r,Si),[r]),l=e.data,{width:u,height:c}=e.viewport;return!u||!c?null:i(Ve,{width:u,height:c,children:i(O0,{variables:a,width:tt(u),height:nt(c),data:l,conf:o,interactionManager:n})})}const B0=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],V0=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function N0({control:e,index:t,remove:n,watch:r,variableOptions:a,xAxisOptions:o}){const l=r(`reference_lines.${t}.orientation`);return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:u})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:u})=>i(s.Select,{label:"Value",required:!0,data:a,sx:{flex:1},...u})})]}),i(v.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:u})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...u})}),p(s.Group,{grow:!0,children:[p(s.Stack,{children:[i(v.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:u})=>i(s.Select,{label:"Orientation",data:V0,required:!0,sx:{flex:1},...u})}),l==="vertical"&&i(s.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&i(v.Controller,{name:`reference_lines.${t}.xAxisIndex`,control:e,render:({field:u})=>i(s.Select,{label:"X Axis",data:o,disabled:o.length===0,sx:{flex:1},...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:u})=>i(s.Select,{label:"Line Type",data:B0,sx:{flexGrow:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:u})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...u})})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:u})=>i($e,{...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`reference_lines.${t}.show_in_legend`,control:e,render:({field:u})=>i(s.Checkbox,{label:"Show in legend",checked:u.value,onChange:c=>u.onChange(c.currentTarget.checked)})}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]},t)}function q0({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=r.map((m,C)=>({...m,...l[C]})),c=()=>{const m=y0();a(m)},d=y.useMemo(()=>n.map(m=>({label:m.name,value:m.name})),[n]),f=t("x_axes"),h=y.useMemo(()=>f.map(({name:m},C)=>({label:m,value:C.toString()})),[f]),g=u.length>0?u[0].id:"0";return p(s.Tabs,{defaultValue:g,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[u.map((m,C)=>i(s.Tabs.Tab,{value:m.id,children:m.name},C)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),u.map((m,C)=>i(s.Tabs.Panel,{value:m.id,children:i(N0,{control:e,index:C,remove:o,watch:t,variableOptions:d,xAxisOptions:h})},C))]})}function F0(e){const[t,n]=y.useState(e);return y.useEffect(()=>{n(e)},[e]),{tab:t,setTab:n}}const G0=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function W0({control:e,index:t,seriesItem:n}){const r=!!n.barWidth.trim();return p(B,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.stack`,control:e,render:({field:a})=>i(s.TextInput,{label:"Stack",placeholder:"Stack bars by this ID",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barGap`,control:e,render:({field:a})=>i(s.Select,{label:"Bar Gap",data:G0,sx:{flexGrow:1},...a})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.barMinWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Min)",disabled:r,sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barMaxWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Max)",disabled:r,sx:{flexGrow:1},...a})})]})]})}const j0=[{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 R0({control:e,index:t,remove:n,seriesItem:r,xAxisOptions:a}){return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.name`,control:e,render:({field:o})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...o})}),i(v.Controller,{name:`series.${t}.xAxisIndex`,control:e,render:({field:o})=>i(s.Select,{label:"X Axis",data:a,disabled:a.length===0,sx:{flex:1},...o})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.data_key`,control:e,render:({field:o})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...o})}),i(v.Controller,{name:`series.${t}.aggregation_on_value`,control:e,render:({field:o})=>i(Qn,{label:"Aggregation on Value",value:o.value??Wt,onChange:o.onChange,pt:0})})]}),i(s.Group,{grow:!0,children:i(v.Controller,{name:`series.${t}.group_by_key`,control:e,render:({field:o})=>i(W,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...o})})}),i(W0,{index:t,control:e,seriesItem:r}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),i(v.Controller,{name:`series.${t}.label_position`,control:e,render:({field:o})=>i(s.Select,{label:"Label Position",data:j0,...o})}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`series.${t}.color`,control:e,render:({field:o})=>i($e,{...o})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`series.${t}.hide_in_legend`,control:e,render:({field:o})=>i(s.Checkbox,{label:"Hide in legend",checked:o.value,onChange:l=>o.onChange(l.currentTarget.checked)})}),i(v.Controller,{name:`series.${t}.invisible`,control:e,render:({field:o})=>i(s.Checkbox,{label:"Invisible",checked:o.value,onChange:l=>o.onChange(l.currentTarget.checked)})}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Series"})]},t)}function Y0({control:e,watch:t}){var g;const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"series"}),o=t("series"),l=n.map((m,C)=>({...m,...o[C]})),u=()=>{const m=m0();r(m)},c=t("x_axes"),d=y.useMemo(()=>c.map(({name:m},C)=>({label:m,value:C.toString()})),[c]),{tab:f,setTab:h}=F0((g=l[0])==null?void 0:g.id);return p(s.Tabs,{value:f,onTabChange:h,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map(m=>i(s.Tabs.Tab,{value:m.id,children:m.name},m.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((m,C)=>i(s.Tabs.Panel,{value:m.id,children:i(R0,{control:e,index:C,remove:a,seriesItem:m,xAxisOptions:d},m.id)},m.id))]})}const Q0=[{label:"Top",value:"top"},{label:"Bottom",value:"bottom"}];function U0({control:e,index:t,remove:n}){return p(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[i(s.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`x_axes.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})})}),i(s.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`x_axes.${t}.position`,control:e,render:({field:r})=>i(s.Select,{label:"Position",required:!0,data:Q0,sx:{flex:1},...r})})}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:`x_axes.${t}.label_formatter`,control:e,render:({field:r})=>i(We,{...r})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`x_axes.${t}.min`,control:e,render:({field:r})=>i(s.TextInput,{label:"Min",...r})}),i(v.Controller,{name:`x_axes.${t}.max`,control:e,render:({field:r})=>i(s.TextInput,{label:"Max",...r})})]})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`x_axes.${t}.show`,control:e,render:({field:r})=>i(s.Checkbox,{label:"Visible",checked:r.value,onChange:a=>r.onChange(a.currentTarget.checked)})}),i(s.Button,{mt:20,leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this X Axis"})]})}function K0({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"x_axes"}),o=t("x_axes"),l=n.map((d,f)=>({...d,...o[f]})),u=()=>{const d=g0();r(d)},c=l.length>0?l[0].id:"0";return p(s.Tabs,{defaultValue:c,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[l.map(d=>i(s.Tabs.Tab,{value:d.id,children:d.name},d.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((d,f)=>i(s.Tabs.Panel,{value:d.id,children:i(U0,{control:e,index:f,remove:a})},d.id))]})}function X0({control:e,watch:t}){return t(["y_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.data_key",control:e,render:({field:n})=>i(W,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"y_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"X Axis Name",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"y_axis.axisLabel.formatter",control:e,render:({field:n})=>i(Xn,{...n})})}),i(v.Controller,{name:"y_axis.axisLabel.overflow",control:e,render:({field:n})=>i(st,{...n})})]})}function J0({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),{variables:r}=e,a=y.useMemo(()=>x.defaultsDeep({},t,Si),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]),u([]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,a),[f,a]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Horizontal Bar Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"Series",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axes",children:"X Axes"}),i(s.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),i(s.Tabs.Tab,{value:"Series",children:"Series"}),i(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"})]}),i(s.Tabs.Panel,{value:"X Axes",children:i(K0,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(X0,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Series",children:i(Y0,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(q0,{variables:r,control:o,watch:u})})]})]})})}function Z0(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,y_axis:o,series:l,...u}=e;return{...u,x_axis:{...a,data_key:r(a.data_key)},y_axis:{...o,data_key:r(o.data_key)},series:l.map(c=>({...c,data_key:r(c.data_key),group_by_key:r(c.group_by_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class H0 extends ge{constructor(){super(...arguments);q(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:a}=n;return{...n,version:2,config:Z0(a,r)}})}}const eC={displayName:"Horizontal Bar Chart",displayGroup:"ECharts-based charts",migrator:new H0,name:"horizontalBarChart",viewRender:P0,configRender:J0,createConfig:()=>({version:2,config:Si})},_i={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...tr}}},deviation:{name:"",data_keys:{estimated_value:"",actual_value:""}},metrics:[]};function tC(){return[{top:20,left:30,right:60,height:40,containLabel:!0,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0},{top:70,left:30,right:60,height:100,containLabel:!0,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0},{top:180,left:30,right:60,bottom:130,containLabel:!0,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0},{left:30,right:60,bottom:20,height:100,containLabel:!1,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0}]}const qo=({value:e})=>{try{return Z(e[2]).format({output:"percent",mantissa:0})}catch(t){return console.error(t),e}};function nC(e,t,n){return{type:"heatmap",name:"准确估算比例",xAxisIndex:0,yAxisIndex:0,data:t.map(a=>{const o=n[a].length,c=(x.countBy(n[a],d=>d.level.diff===0).true??0)/o;return[a,"_y",c]}),label:{show:!0,formatter:qo},labelLayout:{hideOverlap:!0},visualMapIndex:0,tooltip:{trigger:"item",formatter:({color:a,value:o})=>`
|
|
338
|
+
`}}}function E0(e){return e.x_axes.reduce((n,{label_formatter:r},a)=>(n[a]=function(l){let u=l;if(typeof l=="object"&&(Array.isArray(l.value)&&l.value.length===2?u=l.value[0]:u=l.value),!r)return u;try{return Z(u).format(r)}catch(c){return console.error(c),u}},n),{default:({value:n})=>n})}function $0(e,t){const n={};return t.map(r=>{const a=mt(r,e);n[r.name]=Ze(r,a)}),n}function L0(e,t){return e.x_axes.map(({min:n,max:r,...a},o)=>{let l=a.position;return l||(l=o>0?"bottom":"top"),{...a,type:"value",min:n||void 0,max:r||void 0,position:l,axisLabel:{show:!0,margin:2,formatter:t[o]??t.default},axisLine:{show:!0},axisTick:{show:!1},splitLine:{show:!0},nameTextStyle:{fontWeight:"bold"},nameLocation:"center",nameGap:15}})}function O0(e,t){const n=t.every(l=>!Number.isNaN(Number(l))),{overflow:r,...a}=e.y_axis.axisLabel,o=it(r.on_axis);return[{data:t,name:e.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"center",fontWeight:"bold"},id:"main-y-axis",axisTick:{show:!0,alignWithLabel:!0},type:n?"value":"category",axisLabel:{...a,...o,formatter:qt(a.formatter)},z:5}]}function P0(e,t,n){if(!e.y_axis.data_key)return{};const r=$0(t,n),a=E0(e),o=O(e.y_axis.data_key),l=x.uniq(t[o.queryID].map(f=>f[o.columnKey])),u=l.every(f=>!Number.isNaN(Number(f))),c=M0(e,l,u,t,a,n,r);return{xAxis:L0(e,a),yAxis:O0(e,l),series:c,tooltip:z0(e,c,a),grid:x0(e),legend:C0(c)}}ie.use([F.DataZoomComponent,he.BarChart,he.LineChart,he.ScatterChart,F.GridComponent,F.LegendComponent,F.TooltipComponent,Ee.CanvasRenderer,F.MarkLineComponent,F.MarkAreaComponent]);function B0({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=zt(t,e.y_axis.data_key),u=Ke(a.triggerManager,Hr.id),c=y.useCallback(h=>{const g=x.get(l,h.name,{error:"rowData is not found"});u.forEach(m=>{a.runInteraction(m.id,{...h,rowData:g})})},[l,u,a]),d=y.useMemo(()=>({click:c}),[c]),f=y.useMemo(()=>P0(e,t,o),[e,t]);return i(ze,{echarts:ie,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function V0({context:e,instance:t}){const n=Xe({vizManager:e.vizManager,instance:t}),{value:r}=R(e.instanceData,"config"),{variables:a}=e,o=y.useMemo(()=>x.defaults({},r,Si),[r]),l=e.data,{width:u,height:c}=e.viewport;return!u||!c?null:i(Ve,{width:u,height:c,children:i(B0,{variables:a,width:tt(u),height:nt(c),data:l,conf:o,interactionManager:n})})}const N0=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],q0=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function F0({control:e,index:t,remove:n,watch:r,variableOptions:a,xAxisOptions:o}){const l=r(`reference_lines.${t}.orientation`);return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:u})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:u})=>i(s.Select,{label:"Value",required:!0,data:a,sx:{flex:1},...u})})]}),i(v.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:u})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...u})}),p(s.Group,{grow:!0,children:[p(s.Stack,{children:[i(v.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:u})=>i(s.Select,{label:"Orientation",data:q0,required:!0,sx:{flex:1},...u})}),l==="vertical"&&i(s.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&i(v.Controller,{name:`reference_lines.${t}.xAxisIndex`,control:e,render:({field:u})=>i(s.Select,{label:"X Axis",data:o,disabled:o.length===0,sx:{flex:1},...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:u})=>i(s.Select,{label:"Line Type",data:N0,sx:{flexGrow:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:u})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...u})})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:u})=>i($e,{...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`reference_lines.${t}.show_in_legend`,control:e,render:({field:u})=>i(s.Checkbox,{label:"Show in legend",checked:u.value,onChange:c=>u.onChange(c.currentTarget.checked)})}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]},t)}function G0({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=r.map((m,C)=>({...m,...l[C]})),c=()=>{const m=v0();a(m)},d=y.useMemo(()=>n.map(m=>({label:m.name,value:m.name})),[n]),f=t("x_axes"),h=y.useMemo(()=>f.map(({name:m},C)=>({label:m,value:C.toString()})),[f]),g=u.length>0?u[0].id:"0";return p(s.Tabs,{defaultValue:g,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[u.map((m,C)=>i(s.Tabs.Tab,{value:m.id,children:m.name},C)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),u.map((m,C)=>i(s.Tabs.Panel,{value:m.id,children:i(F0,{control:e,index:C,remove:o,watch:t,variableOptions:d,xAxisOptions:h})},C))]})}function W0(e){const[t,n]=y.useState(e);return y.useEffect(()=>{n(e)},[e]),{tab:t,setTab:n}}const j0=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function R0({control:e,index:t,seriesItem:n}){const r=!!n.barWidth.trim();return p(B,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.stack`,control:e,render:({field:a})=>i(s.TextInput,{label:"Stack",placeholder:"Stack bars by this ID",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barGap`,control:e,render:({field:a})=>i(s.Select,{label:"Bar Gap",data:j0,sx:{flexGrow:1},...a})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.barMinWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Min)",disabled:r,sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barMaxWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Max)",disabled:r,sx:{flexGrow:1},...a})})]})]})}const Y0=[{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 Q0({control:e,index:t,remove:n,seriesItem:r,xAxisOptions:a}){return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.name`,control:e,render:({field:o})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...o})}),i(v.Controller,{name:`series.${t}.xAxisIndex`,control:e,render:({field:o})=>i(s.Select,{label:"X Axis",data:a,disabled:a.length===0,sx:{flex:1},...o})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.data_key`,control:e,render:({field:o})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...o})}),i(v.Controller,{name:`series.${t}.aggregation_on_value`,control:e,render:({field:o})=>i(Qn,{label:"Aggregation on Value",value:o.value??Wt,onChange:o.onChange,pt:0})})]}),i(s.Group,{grow:!0,children:i(v.Controller,{name:`series.${t}.group_by_key`,control:e,render:({field:o})=>i(W,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...o})})}),i(R0,{index:t,control:e,seriesItem:r}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),i(v.Controller,{name:`series.${t}.label_position`,control:e,render:({field:o})=>i(s.Select,{label:"Label Position",data:Y0,...o})}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`series.${t}.color`,control:e,render:({field:o})=>i($e,{...o})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`series.${t}.hide_in_legend`,control:e,render:({field:o})=>i(s.Checkbox,{label:"Hide in legend",checked:o.value,onChange:l=>o.onChange(l.currentTarget.checked)})}),i(v.Controller,{name:`series.${t}.invisible`,control:e,render:({field:o})=>i(s.Checkbox,{label:"Invisible",checked:o.value,onChange:l=>o.onChange(l.currentTarget.checked)})}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Series"})]},t)}function U0({control:e,watch:t}){var g;const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"series"}),o=t("series"),l=n.map((m,C)=>({...m,...o[C]})),u=()=>{const m=b0();r(m)},c=t("x_axes"),d=y.useMemo(()=>c.map(({name:m},C)=>({label:m,value:C.toString()})),[c]),{tab:f,setTab:h}=W0((g=l[0])==null?void 0:g.id);return p(s.Tabs,{value:f,onTabChange:h,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map(m=>i(s.Tabs.Tab,{value:m.id,children:m.name},m.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((m,C)=>i(s.Tabs.Panel,{value:m.id,children:i(Q0,{control:e,index:C,remove:a,seriesItem:m,xAxisOptions:d},m.id)},m.id))]})}const K0=[{label:"Top",value:"top"},{label:"Bottom",value:"bottom"}];function X0({control:e,index:t,remove:n}){return p(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[i(s.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`x_axes.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})})}),i(s.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`x_axes.${t}.position`,control:e,render:({field:r})=>i(s.Select,{label:"Position",required:!0,data:K0,sx:{flex:1},...r})})}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:`x_axes.${t}.label_formatter`,control:e,render:({field:r})=>i(We,{...r})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`x_axes.${t}.min`,control:e,render:({field:r})=>i(s.TextInput,{label:"Min",...r})}),i(v.Controller,{name:`x_axes.${t}.max`,control:e,render:({field:r})=>i(s.TextInput,{label:"Max",...r})})]})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`x_axes.${t}.show`,control:e,render:({field:r})=>i(s.Checkbox,{label:"Visible",checked:r.value,onChange:a=>r.onChange(a.currentTarget.checked)})}),i(s.Button,{mt:20,leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this X Axis"})]})}function J0({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"x_axes"}),o=t("x_axes"),l=n.map((d,f)=>({...d,...o[f]})),u=()=>{const d=y0();r(d)},c=l.length>0?l[0].id:"0";return p(s.Tabs,{defaultValue:c,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[l.map(d=>i(s.Tabs.Tab,{value:d.id,children:d.name},d.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((d,f)=>i(s.Tabs.Panel,{value:d.id,children:i(X0,{control:e,index:f,remove:a})},d.id))]})}function Z0({control:e,watch:t}){return t(["y_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.data_key",control:e,render:({field:n})=>i(W,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"y_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"X Axis Name",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"y_axis.axisLabel.formatter",control:e,render:({field:n})=>i(Xn,{...n})})}),i(v.Controller,{name:"y_axis.axisLabel.overflow",control:e,render:({field:n})=>i(st,{...n})})]})}function H0({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),{variables:r}=e,a=y.useMemo(()=>x.defaultsDeep({},t,Si),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]),u([]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,a),[f,a]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Horizontal Bar Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"Series",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axes",children:"X Axes"}),i(s.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),i(s.Tabs.Tab,{value:"Series",children:"Series"}),i(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"})]}),i(s.Tabs.Panel,{value:"X Axes",children:i(J0,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(Z0,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Series",children:i(U0,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(G0,{variables:r,control:o,watch:u})})]})]})})}function eC(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,y_axis:o,series:l,...u}=e;return{...u,x_axis:{...a,data_key:r(a.data_key)},y_axis:{...o,data_key:r(o.data_key)},series:l.map(c=>({...c,data_key:r(c.data_key),group_by_key:r(c.group_by_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class tC extends ge{constructor(){super(...arguments);q(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:a}=n;return{...n,version:2,config:eC(a,r)}})}}const nC={displayName:"Horizontal Bar Chart",displayGroup:"ECharts-based charts",migrator:new tC,name:"horizontalBarChart",viewRender:V0,configRender:H0,createConfig:()=>({version:2,config:Si})},_i={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...tr}}},deviation:{name:"",data_keys:{estimated_value:"",actual_value:""}},metrics:[]};function rC(){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 Go=({value:e})=>{try{return Z(e[2]).format({output:"percent",mantissa:0})}catch(t){return console.error(t),e}};function iC(e,t,n){return{type:"heatmap",name:"准确估算比例",xAxisIndex:0,yAxisIndex:0,data:t.map(a=>{const o=n[a].length,c=(x.countBy(n[a],d=>d.level.diff===0).true??0)/o;return[a,"_y",c]}),label:{show:!0,formatter:Go},labelLayout:{hideOverlap:!0},visualMapIndex:0,tooltip:{trigger:"item",formatter:({color:a,value:o})=>`
|
|
339
339
|
<table style="width: auto">
|
|
340
340
|
<thead>
|
|
341
341
|
<tr colspan="2">
|
|
@@ -353,17 +353,17 @@ Check the top-level render call using <`+V+">.")}return z}}function Tu(S,z){{if(
|
|
|
353
353
|
<tbody>
|
|
354
354
|
<tr>
|
|
355
355
|
<th style="text-align: right;">准确估算比例</th>
|
|
356
|
-
<td style="text-align: left; padding: 0 1em;">${
|
|
356
|
+
<td style="text-align: left; padding: 0 1em;">${Go({value:o})}</td>
|
|
357
357
|
</tr>
|
|
358
358
|
</tbody>
|
|
359
359
|
</table>
|
|
360
|
-
`},show_in_legend:!1}}function
|
|
360
|
+
`},show_in_legend:!1}}function Wo(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 aC([e,t]){const n={x:e,v:`${t}`};try{n.v=Z(t).format({output:"number",mantissa:2,trimMantissa:!0})}catch{}return n}function sC(e,t,n,r){var c,d;const a=t.map(f=>{const h=n[f],g=x.sumBy(h,m=>m.level.diff);return[f,g/h.length]}),o=Number(((c=x.maxBy(a,f=>f[1]))==null?void 0:c[1])??0),l=Number(((d=x.minBy(a,f=>f[1]))==null?void 0:d[1])??0),u=It.interpolate([o,0,l],["#D15A40","#FFF","#418AAF"]);return{type:"bar",name:"平均偏差",xAxisIndex:1,yAxisIndex:1,...r,data:a,itemStyle:{color:({value:f})=>{try{return u(f[1])}catch{return"#FFF"}}},label:{position:"outside",show:!0,formatter:({value:f})=>{try{return Z(f[1]).format({output:"number",mantissa:1,trimMantissa:!0})}catch{return f[1]}}},tooltip:{trigger:"item",formatter:({color:f,value:h})=>{const{x:g,v:m}=aC(h);return`
|
|
361
361
|
<table style="width: auto">
|
|
362
362
|
<thead>
|
|
363
363
|
<tr colspan="2">
|
|
364
364
|
<div style="
|
|
365
365
|
width: 100%; height: 4px; border-radius: 2px; margin-bottom: 6px;
|
|
366
|
-
${
|
|
366
|
+
${Wo(f)}
|
|
367
367
|
"/>
|
|
368
368
|
</tr>
|
|
369
369
|
<tr>
|
|
@@ -379,13 +379,13 @@ Check the top-level render call using <`+V+">.")}return z}}function Tu(S,z){{if(
|
|
|
379
379
|
</tr>
|
|
380
380
|
</tbody>
|
|
381
381
|
</table>
|
|
382
|
-
`}},show_in_legend:!1}}function
|
|
382
|
+
`}},show_in_legend:!1}}function oC([e,t,n,r]){const a={x:e,percentage:`${t}`,count:n,sum:r};try{a.percentage=Z(t).format({output:"percent",mantissa:2,trimMantissa:!0})}catch{}return a}function lC(e,t,n,r){const a={};t.forEach(f=>{const h=x.countBy(n[f],m=>m.level.diff),g=x.sum(Object.values(h));Object.entries(h).forEach(([m,C])=>{a[m]||(a[m]=[]);const w=C/g;a[m].push([f,w,C,g])})});const o=Object.entries(a).map(([f])=>Number(f)).sort((f,h)=>f-h),l=Math.max(...o),u=Math.min(...o),c=It.interpolate([l,0,u],["#D15A40","#FFF","#418AAF"]);return o.map(f=>({type:"bar",name:f,xAxisIndex:2,yAxisIndex:2,stack:1,...r,color:c(f),data:a[f],tooltip:{trigger:"item",formatter:({color:h,value:g})=>{const{x:m,percentage:C,count:w,sum:_}=oC(g);return`
|
|
383
383
|
<table style="width: auto">
|
|
384
384
|
<thead>
|
|
385
385
|
<tr colspan="2">
|
|
386
386
|
<div style="
|
|
387
387
|
width: 100%; height: 4px; border-radius: 2px; margin-bottom: 6px;
|
|
388
|
-
${
|
|
388
|
+
${Wo(h)}
|
|
389
389
|
"
|
|
390
390
|
/>
|
|
391
391
|
</tr>
|
|
@@ -414,8 +414,8 @@ Check the top-level render call using <`+V+">.")}return z}}function Tu(S,z){{if(
|
|
|
414
414
|
</tr>
|
|
415
415
|
</tbody>
|
|
416
416
|
</table>
|
|
417
|
-
`}},show_in_legend:!0}))}function oC(e,t,n,r){const a=O(t.data_key),o=t.name,l=n.map(u=>{const c=x.sumBy(r[u],a.columnKey);return[u,c]});return{type:"line",name:o,xAxisIndex:3,yAxisIndex:3,color:"#b41529",data:l,show_in_legend:!1}}function lC(e,t,n,r){const l={barMinWidth:5,barMaxWidth:20};return[nC(e,n,r),iC(e,n,r,l),...sC(e,n,r,l),oC(e,t,n,r)]}function uC(e,t){const{axisLabel:n}=e.x_axis;return[{data:t,id:"准确估算比例",gridIndex:0,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:t,id:"平均偏差",gridIndex:1,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!0,lineStyle:{color:"#FFFFFF",width:2}},type:"category"},{data:t,id:"数量占比",gridIndex:2,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:t,id:"代码当量",gridIndex:3,axisTick:{show:!1},type:"category",axisLabel:{...n,formatter:bo(n.formatter)},axisLine:{show:!1}}]}function cC(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 ki(e){return e==1||e==2?1:ki(e-2)+ki(e-1)}const dC=Array.from(new Array(20),(e,t)=>ki(t+1));function Go(e){return e<=1?e:dC.findIndex(t=>e<=t)-1}function pC(e,t){const{x_axis:n,deviation:r}=e,a=O(n.data_key),o=O(r.data_keys.estimated_value),l=O(r.data_keys.actual_value);return t[a.queryID].map(u=>{const c=Go(u[o.columnKey]),d=Go(u[l.columnKey]),f=c-d;return{...u,level:{estimated:c,actual:d,diff:f}}})}function hC(e){return e==="rgba(255, 255, 255, 1)"?{borderColor:"rgba(0,0,0,.1)",borderWidth:1}:{}}function fC(e){return{show:!0,orient:"vertical",top:"middle",right:0,data:e.filter(n=>n.show_in_legend).reverse().map(n=>({name:`${n.name}`,color:n.color,itemStyle:hC(n.color)})),tooltip:{show:!0,formatter:"档位偏差:{a}"}}}const gC={tooltip:{trigger:"axis"}};function mC(e,t){const{deviation:n,metrics:r}=e,a=r.find(l=>l.data_key===t);if(a)return a;const o=n.data_keys.actual_value;return{id:o,name:n.name,data_key:o}}function yC(e,t,n){const r=pC(e,n),a=O(e.x_axis.data_key),o=x.uniqBy(n[a.queryID],a.columnKey).map(f=>f[a.columnKey]),l=x.groupBy(r,a.columnKey),u=mC(e,t),c=lC(e,u,o,l),d={xAxis:uC(e,o),yAxis:cC(u),series:c,grid:tC(),visualMap:[{min:0,max:1,calculable:!0,show:!1,seriesIndex:0,color:["#F0F0F0","#418AAF"]}],legend:fC(c)};return x.defaultsDeep({},d,gC)}const bC={input:{border:"none !important",paddingLeft:0,lineHeight:"1.55 !important"}},vC=({conf:e,metricKey:t,setMetricKey:n})=>{const{deviation:r,metrics:a}=e,o=y.useMemo(()=>{const l=a.map(u=>({label:u.name,value:u.data_key}));return l.push({label:r.name?r.name:r.data_keys.actual_value,value:r.data_keys.actual_value}),l},[r,a]);return p(s.Group,{spacing:1,children:[i(s.Text,{size:12,color:"dimmed",sx:{cursor:"default",userSelect:"none"},children:"基线指标"}),i(s.NativeSelect,{size:"xs",data:o,value:t,onChange:l=>n(l.currentTarget.value),styles:bC})]})},xC={"tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function wC(){return p(s.HoverCard,{width:400,shadow:"md",children:[i(s.HoverCard.Target,{children:i(s.Button,{size:"xs",variant:"subtle",compact:!0,leftIcon:i(E.IconInfoCircle,{size:14}),children:"指标说明"})}),i(s.HoverCard.Dropdown,{children:i(s.Table,{fontSize:14,sx:xC,children:p("tbody",{children:[p("tr",{children:[i("th",{children:"估算偏差"}),i("td",{children:"使用斐波那契数列(1,2,3,5,8,13)估算故事点,每个数位为一个档位,计算issue实际故事点与估算故事点的档位偏差,即为估算偏差。如估算故事点为5,实际故事点为8,则估算偏差为-1。"})]}),p("tr",{children:[i("th",{children:"准确估算比例"}),i("td",{children:"偏差在 ± 1 档位内的 issue 均为准确估算,以此计算准确估算的比例。"})]})]})})})]})}function CC(e){return p(s.Group,{position:"apart",children:[i(wC,{}),i(vC,{...e})]})}ie.use([he.BarChart,he.LineChart,he.HeatmapChart,F.GridComponent,F.LegendComponent,F.TooltipComponent,Ee.CanvasRenderer,F.VisualMapComponent]);function SC({conf:e,data:t,width:n,height:r,metricKey:a}){const o=y.useMemo(()=>yC(e,a,t),[e,t,a]);return i(ze,{echarts:ie,option:o,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})}function _C({context:e}){const{value:t}=R(e.instanceData,"config"),n=y.useMemo(()=>x.defaults({},t,_i),[t]),r=e.data,{width:a,height:o}=e.viewport,{x_axis:l,deviation:u}=n,{estimated_value:c,actual_value:d}=u.data_keys,[f,h]=y.useState(d);if(y.useEffect(()=>{h(C=>C||d)},[d]),!l.data_key||!c||!d||!a||!o)return null;const g=Math.max(tt(a),300),m=Math.max(nt(o),370);return p(s.Box,{pt:Be.top,pr:Be.right,pb:Be.bottom,pl:Be.left,sx:{overflow:"hidden",height:o,width:a},children:[i(CC,{conf:n,metricKey:f,setMetricKey:h}),i(SC,{width:g,height:m-30,data:r,conf:n,metricKey:f})]})}function kC({control:e,watch:t}){return t(["deviation"]),p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"deviation.name",control:e,render:({field:n})=>i(s.TextInput,{label:"指标名称",sx:{flex:1},...n})})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"deviation.data_keys.estimated_value",control:e,render:({field:n})=>i(W,{label:"估算值字段",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"deviation.data_keys.actual_value",control:e,render:({field:n})=>i(W,{label:"实际值字段",required:!0,sx:{flex:1},...n})})]})]})}const TC=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`metrics.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`metrics.${t}.data_key`,control:e,render:({field:r})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),DC=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"metrics"}),o=t("metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("metrics.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(B,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(D.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"设置可以展示在基线图的指标,例如代码当量"})]}),i(s.Divider,{variant:"dashed",my:10}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(TC,{control:e,index:g,remove:a},h.id)},h.id))]})]})};function IC({control:e,watch:t}){return t(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>i(W,{label:"数据字段",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"X轴名称",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"点位文案",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>i(s.NumberInput,{label:"旋转",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"度"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>i(wo,{...n})})]})]})}function MC({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},t,_i),[t]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l([]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,r),[d,r]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Merico Estimation Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"12px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X 轴"}),i(s.Tabs.Tab,{value:"Deviation",children:"偏差"}),i(s.Tabs.Tab,{value:"Additional Metrics",children:"指标"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(IC,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Deviation",children:i(kC,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Additional Metrics",children:i(DC,{control:a,watch:l})})]})]})})}function AC(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,deviation:o,metrics:l,...u}=e;return{...u,x_axis:{...a,data_key:r(a.data_key)},deviation:{...o,data_keys:{estimated_value:r(o.data_keys.estimated_value),actual_value:r(o.data_keys.actual_value)}},metrics:l.map(c=>({...c,data_key:r(c.data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class zC extends ge{constructor(){super(...arguments);q(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:a}=n;return{...n,version:2,config:AC(a,r)}})}}const EC={displayName:"Merico Estimation Chart",displayGroup:"Merico suite",migrator:new zC,name:"mericoEstimationChart",viewRender:_C,configRender:MC,createConfig:()=>({version:2,config:_i})},Ti={styles:{justify:"space-around",align:"start"},metrics:[]};function $C(){return{id:new Date().getTime().toString(),names:{value:"Value",basis:"Basis"},data_keys:{value:"",basis:""},formatter:Ie,postfix:{type:"text",value:""}}}const Wo=({postfix:e})=>e?p(B,{children:[i(s.Text,{size:"12px",color:"#818388",sx:{lineHeight:1},children:"/"}),i(s.Text,{size:"12px",color:"#818388",sx:{lineHeight:1},children:e})]}):null,LC=k.observer(({metric:e,variableValueMap:t})=>{const{names:n,data_keys:r,formatter:a,postfix:o}=e,l=ye(),u=y.useMemo(()=>{if(o.type==="text"&&o.value)return o.value;if(o.type==="filter-option-label"&&o.value){const c=l.filters.getSelectOption(o.value);return c?c.label:null}return null},[o,l]);return p(s.Stack,{spacing:18,children:[p(s.Stack,{spacing:12,children:[i(s.Text,{size:"14px",color:"#818388",children:n.value}),p(s.Group,{spacing:"2px",align:"baseline",children:[i(s.Text,{size:"24px",fw:"bold",color:"#3D3E45",sx:{lineHeight:1},children:Z(t[r.value]).format(a)}),i(Wo,{postfix:u})]})]}),p(s.Stack,{spacing:12,children:[i(s.Text,{size:"14px",color:"#818388",children:n.basis}),p(s.Group,{spacing:"2px",align:"baseline",children:[i(s.Text,{size:"12px",color:"#3D3E45",sx:{lineHeight:1},children:Z(t[r.basis]).format(a)}),i(Wo,{postfix:u})]})]})]})}),OC=k.observer(({context:e,instance:t})=>{const{value:n}=R(e.instanceData,"config"),{variables:r}=e,a=y.useMemo(()=>x.defaults({},n,Ti),[n]),o=e.data,l=y.useMemo(()=>eo(o,r),[r,o]),{width:u,height:c}=e.viewport;return!u||!c||!a?null:i(s.Flex,{w:`${u}px`,h:`${c}px`,justify:a.styles.justify,align:a.styles.align,direction:"row",wrap:"nowrap",sx:{overflow:"hidden"},children:a.metrics.map(d=>i(LC,{metric:d,variableValueMap:l},d.id))})}),PC=[{label:"Text",value:"text"},{label:"Filter Option Label",value:"filter-option-label"}],BC=k.observer(y.forwardRef(({value:e,onChange:t},n)=>{const a=le().filters.selects,o=u=>{t({type:u,value:e.value})},l=u=>{t({type:e.type,value:u})};return p(s.Group,{grow:!0,noWrap:!0,children:[i(s.Select,{label:"Postfix Type",data:PC,value:e.type,onChange:o}),e.type==="text"&&i(s.TextInput,{label:"Postfix Content",value:e.value,onChange:u=>{l(u.currentTarget.value)}}),e.type==="filter-option-label"&&i(s.Select,{label:"Filter",value:e.value,onChange:l,data:a})]})}));function VC({control:e,index:t,remove:n,watch:r,variableOptions:a}){return r(`metrics.${t}.postfix`),p(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`metrics.${t}.names.value`,control:e,render:({field:o})=>i(s.TextInput,{label:"Metric Name",required:!0,sx:{flex:1},...o})}),i(v.Controller,{name:`metrics.${t}.data_keys.value`,control:e,render:({field:o})=>i(s.Select,{label:"Metric Data",required:!0,data:a,sx:{flex:1},...o})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`metrics.${t}.names.basis`,control:e,render:({field:o})=>i(s.TextInput,{label:"Basis Name",required:!0,sx:{flex:1},...o})}),i(v.Controller,{name:`metrics.${t}.data_keys.basis`,control:e,render:({field:o})=>i(s.Select,{label:"Basis Data",required:!0,data:a,sx:{flex:1},...o})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Format",labelPosition:"center"}),i(v.Controller,{name:`metrics.${t}.formatter`,control:e,render:({field:o})=>i(We,{...o})}),i(s.Divider,{mb:-15,variant:"dashed",label:"Others",labelPosition:"center"}),i(v.Controller,{name:`metrics.${t}.postfix`,control:e,render:({field:o})=>i(BC,{...o})}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(t),sx:{position:"absolute",top:15,right:5},disabled:t===0,children:i(D.Trash,{size:16})})]},t)}const NC=({control:e,watch:t,variables:n})=>{const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"metrics"}),l=t("metrics"),u=r.map((C,w)=>({...C,...l[w]})),c=()=>{a($C())},d=y.useMemo(()=>n.map(C=>({label:C.name,value:C.name})),[n]),f=x.get(u,"0.id",null),[h,g]=y.useState(f);y.useEffect(()=>{g(C=>C||f)},[f]);const m=C=>{o(C);const w=x.get(u,"0.id",null);g(w)};return p(B,{children:[i(s.Divider,{mt:15,variant:"dashed",label:"Metrics",labelPosition:"center"}),p(s.Tabs,{value:h,onTabChange:g,styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[u.map((C,w)=>i(s.Tabs.Tab,{value:C.id,children:C.names.value?C.names.value:w+1},w)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(E.IconPlus,{size:18,color:"#228be6"})})]}),u.map((C,w)=>i(s.Tabs.Panel,{value:C.id,children:i(VC,{control:e,index:w,remove:m,variableOptions:d,watch:t})},w))]})]})},qC=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"},{label:"Space Between",value:"space-between"},{label:"Space Around",value:"space-around"},{label:"Space Evenly",value:"space-evenly"}],FC=[{label:"Start",value:"start"},{label:"Center",value:"center"},{label:"End",value:"end"},{label:"Stretch",value:"stretch"}];function GC({control:e,watch:t}){return t("styles"),p(B,{children:[i(s.Divider,{mt:15,variant:"dashed",label:"Styles",labelPosition:"center"}),p(s.Group,{children:[i(v.Controller,{name:"styles.justify",control:e,render:({field:n})=>i(s.Select,{label:"Justify Content",required:!0,data:qC,sx:{flex:1},...n})}),i(v.Controller,{name:"styles.align",control:e,render:({field:n})=>i(s.Select,{label:"Align",required:!0,data:FC,sx:{flex:1},...n})})]})]})}function WC({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),{variables:r}=e,a=y.useMemo(()=>x.defaultsDeep({},t,Ti),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,a),[f,a]);return i("form",{onSubmit:l(n),children:p(s.Stack,{spacing:"xs",children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Merico Stats Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),i(GC,{control:o,watch:u}),i(NC,{control:o,watch:u,variables:r})]})})}function jC(e){const{metrics:t,...n}=e;return{...n,metrics:t.map(r=>({...r,postfix:r.postfix??{type:"text",value:""}}))}}class RC extends ge{constructor(){super(...arguments);q(this,"VERSION",2)}configVersions(){this.version(1,n=>({...n,version:1,config:n.config})),this.version(2,n=>({...n,version:2,config:jC(n.config)}))}}const YC={displayName:"Merico Stats",displayGroup:"Merico suite",migrator:new RC,name:"merico-stats",viewRender:OC,configRender:WC,createConfig:()=>({version:2,config:Ti})};function QC({control:e,watch:t}){t(["heat_block"]);const n=t("heat_block.label.show");return p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.data_key",control:e,render:({field:r})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:"heat_block.name",control:e,render:({field:r})=>i(s.TextInput,{label:"Name",sx:{flex:1},...r})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.min",control:e,render:({field:r})=>i(Rt,{label:"Min Value",...r})}),i(v.Controller,{name:"heat_block.max",control:e,render:({field:r})=>i(Rt,{label:"Max Value",...r})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Value Format",labelPosition:"center"}),i(v.Controller,{name:"heat_block.value_formatter",control:e,render:({field:r})=>i(We,{...r})}),i(s.Divider,{mb:-5,variant:"dashed",label:"Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.label.show",control:e,render:({field:r})=>i(s.Switch,{label:"Show label",checked:r.value,onChange:a=>r.onChange(a.currentTarget.checked),sx:{flexGrow:1}})}),i(v.Controller,{name:"heat_block.label.fontSize",control:e,render:({field:r})=>i(s.NumberInput,{size:"xs",icon:i(E.IconTextSize,{size:16}),disabled:!n,...r})})]})]})}const UC=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),KC=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(B,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(D.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),i(s.Divider,{variant:"dashed",my:10}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(UC,{control:e,index:g,remove:a},h.id)},h.id))]})]})};function XC({control:e,watch:t}){return i(KC,{control:e,watch:t})}const JC=({disabled:e,value:t,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[e&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(De,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},ZC={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
418
|
-
`)},
|
|
417
|
+
`}},show_in_legend:!0}))}function uC(e,t,n,r){const a=O(t.data_key),o=t.name,l=n.map(u=>{const c=x.sumBy(r[u],a.columnKey);return[u,c]});return{type:"line",name:o,xAxisIndex:3,yAxisIndex:3,color:"#b41529",data:l,show_in_legend:!1}}function cC(e,t,n,r){const l={barMinWidth:5,barMaxWidth:20};return[iC(e,n,r),sC(e,n,r,l),...lC(e,n,r,l),uC(e,t,n,r)]}function dC(e,t){const{axisLabel:n}=e.x_axis;return[{data:t,id:"准确估算比例",gridIndex:0,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:t,id:"平均偏差",gridIndex:1,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!0,lineStyle:{color:"#FFFFFF",width:2}},type:"category"},{data:t,id:"数量占比",gridIndex:2,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:t,id:"代码当量",gridIndex:3,axisTick:{show:!1},type:"category",axisLabel:{...n,formatter:xo(n.formatter)},axisLine:{show:!1}}]}function pC(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 ki(e){return e==1||e==2?1:ki(e-2)+ki(e-1)}const hC=Array.from(new Array(20),(e,t)=>ki(t+1));function jo(e){return e<=1?e:hC.findIndex(t=>e<=t)-1}function fC(e,t){const{x_axis:n,deviation:r}=e,a=O(n.data_key),o=O(r.data_keys.estimated_value),l=O(r.data_keys.actual_value);return t[a.queryID].map(u=>{const c=jo(u[o.columnKey]),d=jo(u[l.columnKey]),f=c-d;return{...u,level:{estimated:c,actual:d,diff:f}}})}function gC(e){return e==="rgba(255, 255, 255, 1)"?{borderColor:"rgba(0,0,0,.1)",borderWidth:1}:{}}function mC(e){return{show:!0,orient:"vertical",top:"middle",right:0,data:e.filter(n=>n.show_in_legend).reverse().map(n=>({name:`${n.name}`,color:n.color,itemStyle:gC(n.color)})),tooltip:{show:!0,formatter:"档位偏差:{a}"}}}const yC={tooltip:{trigger:"axis"}};function bC(e,t){const{deviation:n,metrics:r}=e,a=r.find(l=>l.data_key===t);if(a)return a;const o=n.data_keys.actual_value;return{id:o,name:n.name,data_key:o}}function vC(e,t,n){const r=fC(e,n),a=O(e.x_axis.data_key),o=x.uniqBy(n[a.queryID],a.columnKey).map(f=>f[a.columnKey]),l=x.groupBy(r,a.columnKey),u=bC(e,t),c=cC(e,u,o,l),d={xAxis:dC(e,o),yAxis:pC(u),series:c,grid:rC(),visualMap:[{min:0,max:1,calculable:!0,show:!1,seriesIndex:0,color:["#F0F0F0","#418AAF"]}],legend:mC(c)};return x.defaultsDeep({},d,yC)}const xC={input:{border:"none !important",paddingLeft:0,lineHeight:"1.55 !important"}},wC=({conf:e,metricKey:t,setMetricKey:n})=>{const{deviation:r,metrics:a}=e,o=y.useMemo(()=>{const l=a.map(u=>({label:u.name,value:u.data_key}));return l.push({label:r.name?r.name:r.data_keys.actual_value,value:r.data_keys.actual_value}),l},[r,a]);return p(s.Group,{spacing:1,children:[i(s.Text,{size:12,color:"dimmed",sx:{cursor:"default",userSelect:"none"},children:"基线指标"}),i(s.NativeSelect,{size:"xs",data:o,value:t,onChange:l=>n(l.currentTarget.value),styles:xC})]})},CC={"tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function SC(){return p(s.HoverCard,{width:400,shadow:"md",children:[i(s.HoverCard.Target,{children:i(s.Button,{size:"xs",variant:"subtle",compact:!0,leftIcon:i(E.IconInfoCircle,{size:14}),children:"指标说明"})}),i(s.HoverCard.Dropdown,{children:i(s.Table,{fontSize:14,sx:CC,children:p("tbody",{children:[p("tr",{children:[i("th",{children:"估算偏差"}),i("td",{children:"使用斐波那契数列(1,2,3,5,8,13)估算故事点,每个数位为一个档位,计算issue实际故事点与估算故事点的档位偏差,即为估算偏差。如估算故事点为5,实际故事点为8,则估算偏差为-1。"})]}),p("tr",{children:[i("th",{children:"准确估算比例"}),i("td",{children:"偏差在 ± 1 档位内的 issue 均为准确估算,以此计算准确估算的比例。"})]})]})})})]})}function _C(e){return p(s.Group,{position:"apart",children:[i(SC,{}),i(wC,{...e})]})}ie.use([he.BarChart,he.LineChart,he.HeatmapChart,F.GridComponent,F.LegendComponent,F.TooltipComponent,Ee.CanvasRenderer,F.VisualMapComponent]);function kC({conf:e,data:t,width:n,height:r,metricKey:a}){const o=y.useMemo(()=>vC(e,a,t),[e,t,a]);return i(ze,{echarts:ie,option:o,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})}function TC({context:e}){const{value:t}=R(e.instanceData,"config"),n=y.useMemo(()=>x.defaults({},t,_i),[t]),r=e.data,{width:a,height:o}=e.viewport,{x_axis:l,deviation:u}=n,{estimated_value:c,actual_value:d}=u.data_keys,[f,h]=y.useState(d);if(y.useEffect(()=>{h(C=>C||d)},[d]),!l.data_key||!c||!d||!a||!o)return null;const g=Math.max(tt(a),300),m=Math.max(nt(o),370);return p(s.Box,{pt:Be.top,pr:Be.right,pb:Be.bottom,pl:Be.left,sx:{overflow:"hidden",height:o,width:a},children:[i(_C,{conf:n,metricKey:f,setMetricKey:h}),i(kC,{width:g,height:m-30,data:r,conf:n,metricKey:f})]})}function DC({control:e,watch:t}){return t(["deviation"]),p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"deviation.name",control:e,render:({field:n})=>i(s.TextInput,{label:"指标名称",sx:{flex:1},...n})})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"deviation.data_keys.estimated_value",control:e,render:({field:n})=>i(W,{label:"估算值字段",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"deviation.data_keys.actual_value",control:e,render:({field:n})=>i(W,{label:"实际值字段",required:!0,sx:{flex:1},...n})})]})]})}const IC=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`metrics.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`metrics.${t}.data_key`,control:e,render:({field:r})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),MC=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"metrics"}),o=t("metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("metrics.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(B,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(D.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"设置可以展示在基线图的指标,例如代码当量"})]}),i(s.Divider,{variant:"dashed",my:10}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(IC,{control:e,index:g,remove:a},h.id)},h.id))]})]})};function AC({control:e,watch:t}){return t(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>i(W,{label:"数据字段",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"X轴名称",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"点位文案",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>i(s.NumberInput,{label:"旋转",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"度"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>i(So,{...n})})]})]})}function zC({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},t,_i),[t]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l([]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,r),[d,r]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Merico Estimation Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"12px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X 轴"}),i(s.Tabs.Tab,{value:"Deviation",children:"偏差"}),i(s.Tabs.Tab,{value:"Additional Metrics",children:"指标"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(AC,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Deviation",children:i(DC,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Additional Metrics",children:i(MC,{control:a,watch:l})})]})]})})}function EC(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,deviation:o,metrics:l,...u}=e;return{...u,x_axis:{...a,data_key:r(a.data_key)},deviation:{...o,data_keys:{estimated_value:r(o.data_keys.estimated_value),actual_value:r(o.data_keys.actual_value)}},metrics:l.map(c=>({...c,data_key:r(c.data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class $C extends ge{constructor(){super(...arguments);q(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:a}=n;return{...n,version:2,config:EC(a,r)}})}}const LC={displayName:"Merico Estimation Chart",displayGroup:"Merico suite",migrator:new $C,name:"mericoEstimationChart",viewRender:TC,configRender:zC,createConfig:()=>({version:2,config:_i})},Ti={styles:{justify:"space-around",align:"start"},metrics:[]};function OC(){return{id:new Date().getTime().toString(),names:{value:"Value",basis:"Basis"},data_keys:{value:"",basis:""},formatter:Ie,postfix:{type:"text",value:""}}}const Ro=({postfix:e})=>e?p(B,{children:[i(s.Text,{size:"12px",color:"#818388",sx:{lineHeight:1},children:"/"}),i(s.Text,{size:"12px",color:"#818388",sx:{lineHeight:1},children:e})]}):null,PC=k.observer(({metric:e,variableValueMap:t})=>{const{names:n,data_keys:r,formatter:a,postfix:o}=e,l=ye(),u=y.useMemo(()=>{if(o.type==="text"&&o.value)return o.value;if(o.type==="filter-option-label"&&o.value){const c=l.filters.getSelectOption(o.value);return c?c.label:null}return null},[o,l]);return p(s.Stack,{spacing:18,children:[p(s.Stack,{spacing:12,children:[i(s.Text,{size:"14px",color:"#818388",children:n.value}),p(s.Group,{spacing:"2px",align:"baseline",children:[i(s.Text,{size:"24px",fw:"bold",color:"#3D3E45",sx:{lineHeight:1},children:Z(t[r.value]).format(a)}),i(Ro,{postfix:u})]})]}),p(s.Stack,{spacing:12,children:[i(s.Text,{size:"14px",color:"#818388",children:n.basis}),p(s.Group,{spacing:"2px",align:"baseline",children:[i(s.Text,{size:"12px",color:"#3D3E45",sx:{lineHeight:1},children:Z(t[r.basis]).format(a)}),i(Ro,{postfix:u})]})]})]})}),BC=k.observer(({context:e,instance:t})=>{const{value:n}=R(e.instanceData,"config"),{variables:r}=e,a=y.useMemo(()=>x.defaults({},n,Ti),[n]),o=e.data,l=y.useMemo(()=>no(o,r),[r,o]),{width:u,height:c}=e.viewport;return!u||!c||!a?null:i(s.Flex,{w:`${u}px`,h:`${c}px`,justify:a.styles.justify,align:a.styles.align,direction:"row",wrap:"nowrap",sx:{overflow:"hidden"},children:a.metrics.map(d=>i(PC,{metric:d,variableValueMap:l},d.id))})}),VC=[{label:"Text",value:"text"},{label:"Filter Option Label",value:"filter-option-label"}],NC=k.observer(y.forwardRef(({value:e,onChange:t},n)=>{const a=le().filters.selects,o=u=>{t({type:u,value:e.value})},l=u=>{t({type:e.type,value:u})};return p(s.Group,{grow:!0,noWrap:!0,children:[i(s.Select,{label:"Postfix Type",data:VC,value:e.type,onChange:o}),e.type==="text"&&i(s.TextInput,{label:"Postfix Content",value:e.value,onChange:u=>{l(u.currentTarget.value)}}),e.type==="filter-option-label"&&i(s.Select,{label:"Filter",value:e.value,onChange:l,data:a})]})}));function qC({control:e,index:t,remove:n,watch:r,variableOptions:a}){return r(`metrics.${t}.postfix`),p(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`metrics.${t}.names.value`,control:e,render:({field:o})=>i(s.TextInput,{label:"Metric Name",required:!0,sx:{flex:1},...o})}),i(v.Controller,{name:`metrics.${t}.data_keys.value`,control:e,render:({field:o})=>i(s.Select,{label:"Metric Data",required:!0,data:a,sx:{flex:1},...o})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`metrics.${t}.names.basis`,control:e,render:({field:o})=>i(s.TextInput,{label:"Basis Name",required:!0,sx:{flex:1},...o})}),i(v.Controller,{name:`metrics.${t}.data_keys.basis`,control:e,render:({field:o})=>i(s.Select,{label:"Basis Data",required:!0,data:a,sx:{flex:1},...o})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Format",labelPosition:"center"}),i(v.Controller,{name:`metrics.${t}.formatter`,control:e,render:({field:o})=>i(We,{...o})}),i(s.Divider,{mb:-15,variant:"dashed",label:"Others",labelPosition:"center"}),i(v.Controller,{name:`metrics.${t}.postfix`,control:e,render:({field:o})=>i(NC,{...o})}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(t),sx:{position:"absolute",top:15,right:5},disabled:t===0,children:i(D.Trash,{size:16})})]},t)}const FC=({control:e,watch:t,variables:n})=>{const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"metrics"}),l=t("metrics"),u=r.map((C,w)=>({...C,...l[w]})),c=()=>{a(OC())},d=y.useMemo(()=>n.map(C=>({label:C.name,value:C.name})),[n]),f=x.get(u,"0.id",null),[h,g]=y.useState(f);y.useEffect(()=>{g(C=>C||f)},[f]);const m=C=>{o(C);const w=x.get(u,"0.id",null);g(w)};return p(B,{children:[i(s.Divider,{mt:15,variant:"dashed",label:"Metrics",labelPosition:"center"}),p(s.Tabs,{value:h,onTabChange:g,styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[u.map((C,w)=>i(s.Tabs.Tab,{value:C.id,children:C.names.value?C.names.value:w+1},w)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(E.IconPlus,{size:18,color:"#228be6"})})]}),u.map((C,w)=>i(s.Tabs.Panel,{value:C.id,children:i(qC,{control:e,index:w,remove:m,variableOptions:d,watch:t})},w))]})]})},GC=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"},{label:"Space Between",value:"space-between"},{label:"Space Around",value:"space-around"},{label:"Space Evenly",value:"space-evenly"}],WC=[{label:"Start",value:"start"},{label:"Center",value:"center"},{label:"End",value:"end"},{label:"Stretch",value:"stretch"}];function jC({control:e,watch:t}){return t("styles"),p(B,{children:[i(s.Divider,{mt:15,variant:"dashed",label:"Styles",labelPosition:"center"}),p(s.Group,{children:[i(v.Controller,{name:"styles.justify",control:e,render:({field:n})=>i(s.Select,{label:"Justify Content",required:!0,data:GC,sx:{flex:1},...n})}),i(v.Controller,{name:"styles.align",control:e,render:({field:n})=>i(s.Select,{label:"Align",required:!0,data:WC,sx:{flex:1},...n})})]})]})}function RC({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),{variables:r}=e,a=y.useMemo(()=>x.defaultsDeep({},t,Ti),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,a),[f,a]);return i("form",{onSubmit:l(n),children:p(s.Stack,{spacing:"xs",children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Merico Stats Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),i(jC,{control:o,watch:u}),i(FC,{control:o,watch:u,variables:r})]})})}function YC(e){const{metrics:t,...n}=e;return{...n,metrics:t.map(r=>({...r,postfix:r.postfix??{type:"text",value:""}}))}}class QC extends ge{constructor(){super(...arguments);q(this,"VERSION",2)}configVersions(){this.version(1,n=>({...n,version:1,config:n.config})),this.version(2,n=>({...n,version:2,config:YC(n.config)}))}}const UC={displayName:"Merico Stats",displayGroup:"Merico suite",migrator:new QC,name:"merico-stats",viewRender:BC,configRender:RC,createConfig:()=>({version:2,config:Ti})};function KC({control:e,watch:t}){t(["heat_block"]);const n=t("heat_block.label.show");return p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.data_key",control:e,render:({field:r})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:"heat_block.name",control:e,render:({field:r})=>i(s.TextInput,{label:"Name",sx:{flex:1},...r})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.min",control:e,render:({field:r})=>i(Rt,{label:"Min Value",...r})}),i(v.Controller,{name:"heat_block.max",control:e,render:({field:r})=>i(Rt,{label:"Max Value",...r})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Value Format",labelPosition:"center"}),i(v.Controller,{name:"heat_block.value_formatter",control:e,render:({field:r})=>i(We,{...r})}),i(s.Divider,{mb:-5,variant:"dashed",label:"Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.label.show",control:e,render:({field:r})=>i(s.Switch,{label:"Show label",checked:r.value,onChange:a=>r.onChange(a.currentTarget.checked),sx:{flexGrow:1}})}),i(v.Controller,{name:"heat_block.label.fontSize",control:e,render:({field:r})=>i(s.NumberInput,{size:"xs",icon:i(E.IconTextSize,{size:16}),disabled:!n,...r})})]})]})}const XC=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),JC=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(B,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(D.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),i(s.Divider,{variant:"dashed",my:10}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(XC,{control:e,index:g,remove:a},h.id)},h.id))]})]})};function ZC({control:e,watch:t}){return i(JC,{control:e,watch:t})}const HC=({disabled:e,value:t,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[e&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(De,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},e1={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
418
|
+
`)},Yo=y.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:a,setFalse:o}]=Q.useBoolean(),[l,u]=y.useState(e);y.useEffect(()=>{u(e)},[e]);const c=m=>{u({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:C}=l,w={enabled:m,func_content:C};u(w),t(w)},f=()=>{o(),u(e)},h=m=>{u(C=>({...C,func_content:m}))},g=()=>{h(e1.func_content)};return p(B,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Customize Label"}),i(s.Modal,{size:800,title:"Customize label content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:m=>c(m.currentTarget.checked)}),i(HC,{value:l.func_content,onChange:h,disabled:!l.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:g,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:d,children:"OK"})]})]})]})})]})});function t1({control:e,watch:t}){return t(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Tick Label",labelPosition:"center"}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>i(st,{...n})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>i(Yo,{...n})})]})]})}const n1=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function r1({control:e,watch:t}){return t(["y_axis"]),p(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.data_key",control:e,render:({field:n})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"y_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...n})})]}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"y_axis.nameAlignment",control:e,render:({field:n})=>i(s.Select,{label:"Name Alignment",required:!0,data:n1,sx:{flex:1},...n})})}),i(s.Divider,{mb:-15,variant:"dashed",label:"Tick Label",labelPosition:"center"}),i(v.Controller,{name:"y_axis.axisLabel.overflow",control:e,render:({field:n})=>i(st,{...n})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.axisLabel.rotate",control:e,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"y_axis.axisLabel.formatter",control:e,render:({field:n})=>i(Yo,{...n})})]})]})}const Di={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,overflow:je,formatter:{...Ue}}},y_axis:{name:"Y Axis",data_key:"",nameAlignment:"center",axisLabel:{rotate:0,overflow:je,formatter:{...Ue}}},heat_block:{min:{type:"static",value:0},max:{type:"static",value:100},name:"Value",data_key:"",value_formatter:Ie,label:{show:!1,fontSize:10}},tooltip:{metrics:[]}};function i1({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},t,Di),[t]),a=y.useMemo(()=>x.cloneDeep(r),[r]);y.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return i("form",{onSubmit:l(n),style:{flexGrow:1},children:p(s.Stack,{spacing:"xs",sx:{height:"100%"},children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{root:{flexGrow:1},tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),i(s.Tabs.Tab,{value:"Heat Block",children:"Heat Block"}),i(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(t1,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(r1,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Heat Block",children:i(KC,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(ZC,{control:o,watch:u})})]})]})})}function a1(e){return i(B,{})}function s1(e){return i(s.Text,{children:"Click heat block"})}const Qo={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:s1,configRender:a1,payload:[{name:"seriesType",description:"'heatmap'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function Uo({enabled:e,func_content:t}){return(n,r)=>{if(!e)return n;try{return new Function(`return ${t}`)()(n,r)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function o1(e){const t=Uo(e.x_axis.axisLabel.formatter),n=Uo(e.y_axis.axisLabel.formatter);return{x_axis:t,y_axis:n}}function l1(e){return{heat_block:function(r){if(!e.heat_block.value_formatter)return r;try{return Z(r).format(e.heat_block.value_formatter)}catch(a){return console.error(a),r}}}}function u1(e){let t=0;return e.x_axis.name&&(t+=20),{top:45,left:5,right:5,bottom:t,containLabel:!0}}function c1(e,t){const{x_axis:n,y_axis:r,heat_block:a}=e,o=O(n.data_key),l=O(r.data_key),u=O(a.data_key),c=t[o.queryID].map(d=>[x.get(d,o.columnKey),x.get(d,l.columnKey),x.get(d,u.columnKey)]);return{type:"heatmap",name:a.name,xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{borderWidth:0},data:c,label:a.label,labelLayout:{hideOverlap:!0}}}const d1=e=>{try{return Z(e).format({trimMantissa:!0,mantissa:2})}catch{return e}};function p1({conf:e,labelFormatters:t,valueFormatters:n,dataDict:r,params:a}){const{value:o,dataIndex:l}=a,[u,c,d]=o,f={label:e.x_axis.name?e.x_axis.name:"X Axis",value:t.x_axis(u,l),style:{label:"",value:ot(e.x_axis.axisLabel.overflow.in_tooltip)}},h={label:e.y_axis.name?e.y_axis.name:"Y Axis",value:t.y_axis(c,l),style:{label:"",value:ot(e.y_axis.axisLabel.overflow.in_tooltip)}},g={label:e.heat_block.name,value:n.heat_block(d),style:{label:"",value:""}},m=[f,h,g],C=r[`${u}---${c}`];return C&&e.tooltip.metrics.forEach(w=>{const _=O(w.data_key);m.push({label:w.name,value:d1(x.get(C,_.columnKey,"")),style:{label:"",value:""}})}),m}function h1(e,t,n,r){const{x_axis:a,y_axis:o,heat_block:l}=e,u=O(a.data_key),c=O(o.data_key);O(l.data_key);const d=x.keyBy(t[u.queryID],f=>`${f[u.columnKey]}---${f[c.columnKey]}`);return{confine:!0,formatter:function(f){const g=p1({conf:e,labelFormatters:n,valueFormatters:r,dataDict:d,params:f}).map(C=>`
|
|
419
419
|
<tr>
|
|
420
420
|
<th style="text-align: right;">
|
|
421
421
|
<div style="${C.style.label}">${C.label}</div>
|
|
@@ -436,8 +436,8 @@ Check the top-level render call using <`+V+">.")}return z}}function Tu(S,z){{if(
|
|
|
436
436
|
</thead>
|
|
437
437
|
<tbody>${g.join("")}</tbody>
|
|
438
438
|
</table>
|
|
439
|
-
`}}}function p1(e,t){const n=Yt(e.heat_block.min,t),r=Yt(e.heat_block.max,t);return{min:n,max:r,calculable:!0,orient:"horizontal",left:"center",top:0,itemWidth:15}}function h1(e,t,n){const r=O(e.x_axis.data_key),a=x.uniq(t[r.queryID].map(c=>c[r.columnKey])),{overflow:o,rotate:l}=e.x_axis.axisLabel,u=it(o.on_axis);return{id:"main-x-axis",type:"category",data:a,name:e.x_axis.name??"",align:"center",axisTick:{show:!0,alignWithLabel:!0},axisLabel:{rotate:l,...u,formatter:n},splitArea:{show:!0},nameLocation:"center",nameGap:25,nameTextStyle:{fontWeight:"bold",align:"center"},z:2}}function f1(e,t,n){const r=O(e.x_axis.data_key),a=O(e.y_axis.data_key),{nameAlignment:o,data_key:l,...u}=e.y_axis,c=x.uniq(t[r.queryID].map(g=>g[a.columnKey])),{overflow:d,rotate:f}=e.y_axis.axisLabel,h=it(d.on_axis);return{...u,type:"category",data:c,axisLabel:{rotate:f,...h,formatter:n},axisLine:{show:!0,color:"blue"},axisTick:{show:!0,alignWithLabel:!0},splitArea:{show:!0},nameTextStyle:{fontWeight:"bold",align:o},nameLocation:"end",nameGap:15,z:2}}const g1={tooltip:{confine:!0}};function m1(e,t,n){if(!e.x_axis.data_key||!e.y_axis.data_key||!e.heat_block.data_key)return{};const r=n.reduce((u,c)=>{const d=mt(c,t);return u[c.name]=Ze(c,d),u},{}),a=a1(e),o=s1(e),l={xAxis:h1(e,t,a.x_axis),yAxis:f1(e,t,a.y_axis),series:l1(e,t),tooltip:d1(e,t,a,o),grid:o1(e),visualMap:p1(e,r)};return x.defaultsDeep({},l,g1)}ie.use([F.DataZoomComponent,he.HeatmapChart,F.GridComponent,F.LegendComponent,F.TooltipComponent,F.VisualMapComponent,Ee.CanvasRenderer]);function y1({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=y.useMemo(()=>{const h=O(e.x_axis.data_key),g=O(e.y_axis.data_key);return x.keyBy(t[h.queryID],m=>`${m[h.columnKey]}---${m[g.columnKey]}`)},[t,e.x_axis.data_key,e.y_axis.data_key]),u=Ke(a.triggerManager,Ro.id),c=y.useCallback(h=>{const[g,m]=h.value,C=x.get(l,`${g}---${m}`,{error:"rowData is not found"});u.forEach(w=>{a.runInteraction(w.id,{...h,rowData:C})})},[l,u,a]),d=y.useMemo(()=>({click:c}),[c]),f=y.useMemo(()=>m1(e,t,o),[e,t]);return i(ze,{echarts:ie,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function b1({context:e,instance:t}){const n=Xe({vizManager:e.vizManager,instance:t}),{value:r}=R(e.instanceData,"config"),{variables:a}=e,o=y.useMemo(()=>x.defaults({},r,Di),[r]),l=e.data,{width:u,height:c}=e.viewport;return!u||!c?null:i(Ve,{width:u,height:c,children:i(y1,{variables:a,width:tt(u),height:nt(c),data:l,conf:o,interactionManager:n})})}class v1 extends ge{constructor(){super(...arguments);q(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const x1={displayName:"Merico Heatmap",displayGroup:"Merico suite",migrator:new v1,name:"merico-heatmap",viewRender:b1,configRender:n1,createConfig:()=>({version:1,config:Di}),triggers:[Ro]},w1=[{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"})),C1=[rc,ic,oc,sc,ac,lc],Qo=()=>({id:"dashboard",version:as,manifest:{viz:[bi,ox,zw,Vb,Mx,My,eC,Cc,Gh,em,Bm,f0,my,zg,Kv,eb,Mb,Nw,EC,x1,YC,nf],color:[...w1,...C1]}}),yn=new pc,be={pluginManager:ht("pluginManager"),vizManager:ht("vizManager"),colorManager:ht("colorManager"),instanceScope:{panelModel:ht("panelModel"),vizInstance:ht("vizInstance"),interactionManager:ht("interactionManager"),migrator:ht("migrator"),operationManager:ht("operationManager"),triggerManager:ht("triggerManager")}},Ii=()=>{try{yn.install(Qo())}catch{}const e=new ec(yn),t=new dc(yn);return{pluginManager:yn,vizManager:e,colorManager:t}},ct=y.createContext(Ii());try{yn.install(Qo())}catch{}const Mi=y.createContext(null);function ar(e){const t=y.useContext(Mi),n=Q.useCreation(()=>e.configure(t||new Cr),[e.configure]),r=Q.usePrevious(n);return r&&r!==n&&r.dispose(),i(Mi.Provider,{value:n,children:e.children})}function Uo(){return y.useContext(Mi)}const S1=({description:e,isDescriptionEmpty:t})=>t?null:i(s.Tooltip,{color:"white",label:i(Rn,{value:e,styles:{root:{border:"none"},content:{padding:0}}}),styles:{tooltip:{border:"0.0625rem solid rgb(233, 236, 239)",boxShadow:"rgb(0 0 0 / 5%) 0px 0.0625rem 0.1875rem, rgb(0 0 0 / 5%) 0px 1.25rem 1.5625rem -0.3125rem, rgb(0 0 0 / 4%) 0px 0.625rem 0.625rem -0.3125rem"}},withArrow:!0,children:i(s.Box,{sx:{height:"16px",alignSelf:"center"},children:i(E.IconInfoCircle,{size:16,color:"gray"})})}),_1=k.observer(({label:e,config:{default_value:t,description:n,isDescriptionEmpty:r,...a},value:o,onChange:l})=>p(s.Box,{children:[i(s.Text,{children:" "}),i(s.Checkbox,{label:p(s.Group,{noWrap:!0,position:"apart",align:"middle",spacing:6,children:[i(s.Box,{sx:{flexGrow:1},children:e}),i(S1,{description:n,isDescriptionEmpty:r})]}),checked:o||!1,onChange:u=>l(u.currentTarget.checked),...a,pt:".4em",styles:{input:{borderColor:"#e9ecef"}}})]})),Ko=k.observer(({label:e,config:t,value:n=[null,null],onChange:r})=>{const{inputFormat:a,...o}=t,l=Array.isArray(n)?n.map(f=>f?U(f).toDate():null):[null,null],u=f=>{r(f.map(h=>h&&U(h).format(a)))},c=t.getMinDate(l[0]),d=t.getMaxDate(l[0]);return i(Ou.DatePickerInput,{type:"range",label:e,value:l,onChange:u,icon:i(D.Calendar,{size:16}),sx:{minWidth:"16em"},minDate:c,maxDate:d,valueFormat:a,styles:{input:{borderColor:"#e9ecef"}},...o})}),k1=s.createStyles((e,{radius:t=4})=>({root:{borderRadius:e.fn.radius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-select.rc-select-open":{borderColor:"#228be6 !important",".rc-select-selection-overflow-item-rest":{display:"none"},".rc-select-selection-overflow-item-suffix":{display:"block"}},".rc-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-select-selection-search-mirror":{display:"none"},".rc-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},required:{color:"#fa5252",paddingLeft:"3px"},dropdown:{fontSize:e.fontSizes.xs,zIndex:300,backgroundColor:"#fff",border:"1px solid #e9ecef",marginTop:6,padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px","&.rc-select-dropdown-slide-up-leave-active":{display:"none"},".rc-select-item-empty":{padding:"8px 12px"},".rc-select-item-option":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"8px 12px 8px 2px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},flexDirection:"row-reverse",".rc-select-item-option-state":{flexGrow:0,flexShrink:0,width:"30px",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},".rc-select-item-option-content":{width:"calc(100% - 30px)",overflow:"hidden",'div[data-role="label"]':{overflowWrap:"break-word"}}},".rc-virtual-list-holder-inner":{alignItems:"flex-start"}}})),Xo=({errorMessage:e})=>e?i(s.Text,{color:"red",size:12,children:e}):i(s.Text,{color:"dimmed",size:12,children:"Not found"}),T1=({disabled:e,classNames:t,styles:n,unstyled:r,radius:a,style:o,label:l,value:u,onChange:c,options:d,errorMessage:f,required:h})=>{const{classes:g,cx:m}=k1({radius:a},{name:"MultiSelectWidget",classNames:t,styles:n,unstyled:r}),[C,w]=y.useState(!1),_=$=>{w($)},T=C&&(u==null?void 0:u.length)>0,[M,P]=y.useState(""),G=y.useMemo(()=>{if(!M)return d;const $=M.toLowerCase(),L=A=>{var N;return((N=A.description)==null?void 0:N.toLowerCase().includes($))||A.label.toLowerCase().includes($)};return d.filter(L)},[M,d]);return p(s.Stack,{spacing:3,children:[p(s.Group,{position:"apart",children:[p(s.Text,{className:g.label,children:[l,h&&i("span",{className:g.required,"aria-hidden":"true",children:"*"})]}),T&&i(s.Tooltip,{label:`${u.length} selected`,children:i(s.Badge,{children:u.length})})]}),i(Ka,{disabled:e,allowClear:!0,className:m(g.root,"check-select"),dropdownClassName:m(g.dropdown,""),onDropdownVisibleChange:_,transitionName:"rc-select-dropdown-slide-up",choiceTransitionName:"rc-select-selection__choice-zoom",style:o,clearIcon:()=>i(s.CloseButton,{}),value:u,onChange:c,onSelect:console.log,mode:"multiple",maxTagCount:0,notFoundContent:i(Xo,{errorMessage:f}),maxTagTextLength:10,maxTagPlaceholder:$=>`${$.length} selected`,searchValue:M,onSearch:P,filterOption:!1,children:G.map($=>p(Ka.Option,{title:$.label,children:[i(s.Text,{size:"sm","data-role":"label",children:$.label}),$.description&&i(s.Text,{size:"xs",color:"dimmed","data-role":"description",children:$.description})]},$.value))})]})},D1=k.observer(({label:e,config:t,value:n,onChange:r})=>{const a=ye(),o=!!t.options_query_id,{state:l,error:u}=a.getDataStuffByID(t.options_query_id),c=l==="loading",d=t.min_width?t.min_width:"200px",f=o?c:!1,h=g=>r(g,!1);return i(T1,{label:e,options:t.options,style:{minWidth:"160px",width:d,maxWidth:f?d:"unset",borderColor:"#e9ecef"},disabled:f,value:n,onChange:h,errorMessage:u,required:t.required})}),I1=y.forwardRef(({label:e,description:t,...n},r)=>i("div",{ref:r,...n,children:i(s.Group,{noWrap:!0,children:p("div",{children:[i(s.Text,{size:"sm","data-role":"label",children:e}),i(s.Text,{size:"xs",color:"dimmed","data-role":"description",children:t})]})})})),M1=k.observer(({label:e,config:t,value:n,onChange:r})=>{const a=ye(),o=!!t.options_query_id,{state:l,error:u}=a.getDataStuffByID(t.options_query_id),c=l==="loading";return i(s.Select,{label:e,data:t.options,disabled:o?c:!1,value:n,onChange:r,error:!!u,placeholder:u,maxDropdownHeight:500,styles:{root:{width:t.width?t.width:"200px"},input:{borderColor:"#e9ecef"}},sx:{".mantine-Select-item[data-selected] .mantine-Text-root[data-role=description]":{color:"rgba(255,255,255,.7)"}},itemComponent:I1})});function A1({label:e,config:t,value:n,onChange:r}){return i(s.TextInput,{label:e,value:n||"",onChange:a=>r(a.currentTarget.value),...t,styles:{input:{borderColor:"#e9ecef"}}})}const z1=({rotate:e,onClick:t})=>i("svg",{onClick:t,className:"caret-icon",viewBox:"0 0 1024 1024",focusable:"false","data-icon":"caret-down",width:"14px",height:"14px",fill:"currentColor","aria-hidden":"true",transform:`rotate(${e})`,children:i("path",{d:"M840.4 300H183.6c-19.7 0-30.7 20.8-18.5 35l328.4 380.8c9.4 10.9 27.5 10.9 37 0L858.9 335c12.2-14.2 1.2-35-18.5-35z"})}),E1=({expanded:e,isLeaf:t,value:n,onClick:r,...a})=>(n==="0-0-value"&&console.log(a),t?i("span",{style:{width:"14px",display:"inline-block"}}):i(z1,{rotate:e?"0":"-90",onClick:r,...a})),$1=({onClick:e})=>p("svg",{onClick:e,className:"checkbox-icon",width:"16",height:"16",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[i("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),i("rect",{className:"border",x:"4",y:"4",width:"16",height:"16",rx:"2"}),i("rect",{className:"checkmark-indeterminate",x:"8",y:"8",width:"8",height:"8",rx:"2",stroke:"none"}),i("path",{className:"checkmark-checked",d:"M9 12l2 2l4 -4"})]}),L1=({onClick:e,...t})=>i($1,{onClick:e,...t}),O1=s.createStyles((e,{radius:t=4})=>({root:{borderRadius:e.fn.radius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-tree-select.rc-tree-select-open":{borderColor:"#228be6 !important",".rc-tree-select-selection-overflow-item-rest":{display:"none"},".rc-tree-select-selection-overflow-item-suffix":{display:"block"}},".rc-tree-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-tree-select-selection-search-mirror":{display:"none"},".rc-tree-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-tree-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-tree-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-tree-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-tree-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-tree-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-tree-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-tree-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},required:{color:"#fa5252",paddingLeft:"3px"},dropdown:{fontSize:e.fontSizes.xs,zIndex:300,paddingTop:"6px","&.rc-tree-select-dropdown-slide-up-leave-active":{display:"none"},".rc-tree-select-tree-list .rc-tree-select-tree-list-holder":{},".rc-tree-select-tree-list, .rc-tree-select-empty":{backgroundColor:"#fff",border:"1px solid #e9ecef",padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px"},".rc-tree-select-empty":{padding:"8px 12px"},".rc-tree-select-tree-treenode":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"8px 12px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},"&.rc-tree-select-tree-treenode-checkbox-checked":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-checked":{stroke:"rgb(64, 192, 87)",animation:"check 200ms linear forwards"}},"&.rc-tree-select-tree-treenode-checkbox-indeterminate":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-indeterminate":{fill:"rgb(64, 192, 87)"}},".rc-tree-select-tree-switcher":{height:"16px",alignSelf:"center",paddingRight:"2px",transition:"color 200ms ease","&:hover":{color:"#228be6","svg.caret-icon":{color:"#228be6"}},"svg.caret-icon":{color:"#ced4da",transition:"all 200ms ease"}},".rc-tree-select-tree-node-content-wrapper":{display:"flex",flexWrap:"nowrap",overflow:"hidden",alignItems:"center",gap:"8px",transition:"color 200ms ease","&:hover":{color:"#228be6"}},".rc-tree-select-tree-iconEle":{height:"16px","svg .border":{stroke:"#ced4da"},".checkbox-icon .checkmark-indeterminate":{fill:"transparent",transition:"fill 200ms ease"},".checkbox-icon .checkmark-checked":{transform:"scale(1.2)",transformOrigin:"center center",strokeDasharray:10,strokeDashoffset:-10},"@keyframes check":{"0%":{strokeDashoffset:10},"100%":{strokeDashoffset:0}}},".rc-tree-select-tree-title":{textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden",".rc-tree-select-tree-title-desc":{fontSize:"12px",maxWidth:"100%",textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden"}},".rc-tree-select-tree-indent":{flexGrow:0,height:0,verticalAlign:"bottom"},".rc-tree-select-tree-indent-unit":{display:"inline-block",width:"1em"}}}})),P1=({disabled:e,classNames:t,styles:n,unstyled:r,radius:a,style:o,label:l,value:u,onChange:c,treeData:d,errorMessage:f,required:h,treeCheckStrictly:g})=>{const{classes:m,cx:C}=O1({radius:a},{name:"FilterTreeSelectWidget",classNames:t,styles:n,unstyled:r}),[w,_]=y.useState(!1),T=P=>{_(P)},M=w&&(u==null?void 0:u.length)>0;return p(s.Stack,{spacing:3,children:[p(s.Group,{position:"apart",children:[p(s.Text,{className:m.label,children:[l,h&&i("span",{className:m.required,"aria-hidden":"true",children:"*"})]}),M&&i(s.Tooltip,{label:`${u.length} selected`,children:i(s.Badge,{children:u.length})})]}),i(Xa,{disabled:e,allowClear:!0,treeCheckStrictly:g,className:C(m.root,"check-select"),dropdownClassName:C(m.dropdown,""),onDropdownVisibleChange:T,transitionName:"rc-tree-select-dropdown-slide-up",choiceTransitionName:"rc-tree-select-selection__choice-zoom",style:o,treeLine:!0,clearIcon:()=>i(s.CloseButton,{}),switcherIcon:E1,treeIcon:L1,maxTagTextLength:10,value:u,treeData:d,notFoundContent:i(Xo,{errorMessage:f}),treeNodeFilterProp:"filterBasis",treeCheckable:!0,showCheckedStrategy:Xa.SHOW_PARENT,onChange:c,onSelect:console.log,maxTagCount:0,maxTagPlaceholder:P=>`${P.length} selected`})]})},B1=k.observer(({label:e,config:t,value:n,onChange:r})=>{const{treeData:a,treeDataLoading:o,errorMessage:l}=t,u=t.min_width?t.min_width:"200px",d=!!t.options_query_id?o:!1;return i(P1,{disabled:d,style:{minWidth:"160px",width:u,maxWidth:d?u:"unset",borderColor:"#e9ecef"},value:n,onChange:f=>r(f,!1),treeData:a,errorMessage:l,label:e,required:t.required,treeCheckStrictly:t.treeCheckStrictly})}),V1=k.observer(({filter:{type:e,config:t,key:n,...r},formFieldProps:a})=>{switch(e){case"select":return i(M1,{...r,...a,config:t});case"multi-select":return i(D1,{...r,...a,config:t});case"tree-select":return i(B1,{...r,...a,config:t});case"text-input":return i(A1,{...r,...a,config:t});case"date-range":return i(Ko,{...r,...a,config:t});case"checkbox":return i(_1,{...r,...a,config:t});default:return null}}),N1=k.observer(y.forwardRef(({filter:e,...t},n)=>i("div",{className:"filter-root",ref:n,children:i(Ne,{children:i(V1,{filter:e,formFieldProps:t})})})));function q1(e){const t=le();y.useEffect(()=>{var n,r;(r=(n=t.filters).updatePreviewValues)==null||r.call(n,e)},[e])}const Jo=k.observer(function({view:t}){const n=ye(),{control:r,handleSubmit:a,reset:o}=v.useForm({defaultValues:n.filters.values,reValidateMode:"onBlur"}),l=v.useWatch({control:r});y.useEffect(()=>{o(n.filters.values)},[n.filters.values,o]),q1(l);const u=n.filters.visibleInView(t.id),c=y.useMemo(()=>u.every(g=>g.should_auto_submit),[u]),d=y.useMemo(()=>u.filter(g=>x.get(g,"config.required",!1)),[u]),f=y.useMemo(()=>d.length===0?!1:d.some(g=>!g.requiredAndPass(l[g.key])),[l,d]);if(u.length===0)return null;const h=(g,m)=>(C,w)=>{m(C),(g.should_auto_submit||w)&&n.filters.setValueByKey(g.key,C)};return i("form",{onSubmit:a(n.filters.setValues),children:p(s.Group,{className:"dashboard-filters",position:"apart",noWrap:!0,sx:c?{}:{border:"1px solid #e9ecef",borderRadius:"4px",padding:"16px"},children:[i(s.Group,{align:"flex-start",children:u.map(g=>i(v.Controller,{name:g.key,control:r,render:({field:m})=>i(N1,{filter:g,value:m.value,onChange:h(g,m.onChange)})},g.id))}),!c&&i(s.Group,{sx:{alignSelf:"flex-end"},children:i(s.Button,{color:"blue",size:"sm",type:"submit",disabled:f,children:"Search"})})]})})}),F1={viewPanelInFullScreen:x.noop,inFullScreen:!1},sr=y.createContext(F1),Zo=b.types.model("MockContextMeta",{current:b.types.optional(b.types.frozen(),{})}).views(e=>({get keys(){return Object.keys(e.current)},get entries(){return Object.entries(e.current)}})).actions(e=>({replace(t){e.current=t},get(t){return e.current[t]},set(t,n){e.current[t]=n}}));function Ho(e){return{current:e}}const G1=b.types.model("PanelLayoutMeta",{x:b.types.number,y:b.types.maybeNull(b.types.number),w:b.types.number,h:b.types.number,moved:b.types.optional(b.types.boolean,!1),static:b.types.optional(b.types.boolean,!1)}).views(e=>({get json(){const{x:t,y:n,w:r,h:a,moved:o}=e;return{h:a,w:r,x:t,y:n===null?0:n,moved:o,static:e.static}}})).actions(e=>({set(t){const{x:n,y:r,w:a,h:o,moved:l}=t;e.x=n,e.y=r,e.w=a,e.h=o,e.moved=!!l,e.static=!!t.static},setWidth(t){e.w=t},setHeight(t){e.h=t}})),W1=b.types.model("PanelStyleBorderMeta",{enabled:b.types.boolean}).views(e=>({get json(){const{enabled:t}=e;return{enabled:t}}})).actions(e=>({setEnabled(t){e.enabled=t}})),j1=b.types.model("PanelStyleMeta",{border:W1}).views(e=>({get json(){const{border:t}=e;return{border:t.json}}})).actions(e=>({})),R1=b.types.model("VariableMeta",{name:b.types.string,size:b.types.string,weight:b.types.string,color:b.types.union(b.types.model({type:b.types.literal("static"),staticColor:b.types.string}),b.types.model({type:b.types.literal("continuous"),valueRange:b.types.array(b.types.number),colorRange:b.types.array(b.types.string)}),b.types.model({type:b.types.literal("piecewise")})),formatter:b.types.model({output:b.types.enumeration("Output",["number","percent"]),average:b.types.optional(b.types.boolean,!1),mantissa:b.types.number,trimMantissa:b.types.optional(b.types.boolean,!1)}),data_field:b.types.string,aggregation:b.types.union(b.types.model({type:b.types.enumeration(["none","sum","mean","median","min","max","CV","std"]),config:b.types.frozen()}),b.types.model({type:b.types.literal("quantile"),config:b.types.model({p:b.types.number})}),b.types.model({type:b.types.literal("custom"),config:b.types.model({func:b.types.string})}))}).views(e=>({get json(){const{name:t,size:n,weight:r,color:a,formatter:o,data_field:l,aggregation:u}=e;return x.cloneDeep({name:t,size:n,color:a,weight:r,formatter:o,data_field:l,aggregation:u})}})),Y1=b.types.model("PanelVizMeta",{type:b.types.string,conf:b.types.frozen()}).views(e=>({get json(){return{conf:e.conf,type:e.type}}})).actions(e=>({setType(t){e.type=t},setConf(t){e.conf=t}})),Q1=b.types.model({id:b.types.string,title:b.types.string,description:b.types.string,layout:G1,queryIDs:b.types.array(b.types.string),viz:Y1,style:j1,variables:b.types.optional(b.types.array(R1),[])}).views(e=>({get json(){const{id:t,title:n,description:r,queryIDs:a}=e;return{id:t,viz:e.viz.json,style:e.style.json,title:n,layout:e.layout.json,queryIDs:[...a],variables:e.variables.map(o=>o.json),description:r}},get queryIDSet(){return new Set(e.queryIDs)}})).actions(e=>({setID(t){e.id=t},setTitle(t){e.title=t},setDescription(t){e.description=t},addQueryID(t){e.queryIDSet.has(t)||e.queryIDs.push(t)},removeQueryID(t){if(!e.queryIDSet.has(t))return;const n=new Set(e.queryIDSet);n.delete(t),e.queryIDs=b.cast(Array.from(n))},setQueryIDs(t){e.queryIDs=b.cast(t)},addVariable(t){e.variables.push(t)},removeVariable(t){e.variables.remove(t)}})),or=e=>x.cloneDeepWith(e,(t,n)=>{if(n!==void 0&&t)return te.toJS(t)});var ve=(e=>(e.Postgresql="postgresql",e.MySQL="mysql",e.HTTP="http",e))(ve||{});const U1=b.types.model("QueryMeta",{id:b.types.string,name:b.types.string,type:b.types.enumeration("DataSourceType",[ve.Postgresql,ve.MySQL,ve.HTTP]),key:b.types.string,sql:b.types.string,pre_process:b.types.optional(b.types.string,""),post_process:b.types.optional(b.types.string,""),run_by:b.types.optional(b.types.array(b.types.string),[]),react_to:b.types.optional(b.types.array(b.types.string),[])}).views(e=>({get valid(){return e.id&&e.type&&e.key&&e.name?e.type===ve.HTTP?!!e.pre_process:!!e.sql:!1},get json(){const{id:t,name:n,type:r,key:a,sql:o,run_by:l,react_to:u,pre_process:c,post_process:d}=e;return or({id:t,key:a,sql:o,name:n,type:r,run_by:l,react_to:u,pre_process:c,post_process:d})}})).actions(e=>({setName(t){e.name=t},setKey(t){e.key=t},setType(t){e.type=t},setSQL(t){e.sql=t},setRunBy(t){e.run_by.length=0,e.run_by.push(...t)},setReactTo(t){e.react_to.length=0,e.react_to.push(...t)},setPreProcess(t){e.pre_process=t},setPostProcess(t){e.post_process=t}})),K1=b.types.model("SQLSnippetMeta",{key:b.types.string,value:b.types.string}).views(e=>({get json(){const{key:t,value:n}=e;return{key:t,value:n}}})).actions(e=>({setKey(t){e.key=t},setValue(t){e.value=t}}));var xe=(e=>(e.Select="select",e.MultiSelect="multi-select",e.TreeSelect="tree-select",e.TextInput="text-input",e.Checkbox="checkbox",e.DateRange="date-range",e))(xe||{});const el=b.types.model("FilterCheckboxConfigMeta",{_name:b.types.literal("checkbox"),description:b.types.optional(b.types.string,""),default_value:b.types.boolean}).views(e=>({get json(){const{_name:t,description:n,default_value:r}=e;return{_name:t,description:n,default_value:r}},get isDescriptionEmpty(){const{description:t}=e;return t===""||t==="<p></p>"}})).actions(e=>({setDefaultValue(t){e.default_value=t},setDescription(t){e.description=t}})),X1=()=>el.create({_name:"checkbox",description:"",default_value:!1});function tl(e,t){return e.map(n=>{try{return n?U.tz(n,"UTC").format(t):null}catch{return console.log(`[date-range] failed parsing ${n}`),null}})}const J1=b.types.model("FilterDateRangeConfigMeta",{_name:b.types.literal("date-range"),required:b.types.boolean,inputFormat:b.types.enumeration("DateRangeInputFormat",["YYYY","YYYYMM","YYYYMMDD","YYYY-MM","YYYY-MM-DD"]),default_value:b.types.optional(b.types.array(b.types.union(b.types.string,b.types.null)),[null,null]),clearable:b.types.boolean,max_days:b.types.optional(b.types.number,0),allowSingleDateInRange:b.types.optional(b.types.boolean,!1)}).views(e=>({get json(){const{_name:t,max_days:n,required:r,clearable:a,inputFormat:o,default_value:l,allowSingleDateInRange:u}=e;return{_name:t,max_days:n,required:r,clearable:a,inputFormat:o,default_value:tl(l,o),allowSingleDateInRange:u}},truthy(t){return Array.isArray(t)&&t.length===2&&t.every(n=>!!n)}})).views(e=>({getMaxDate(t){const{max_days:n}=e;if(!(!n||!t))return U(t).startOf("day").add(n,"days").toDate()},getMinDate(t){const{max_days:n}=e;if(!(!n||!t))return U(t).startOf("day").subtract(n,"days").toDate()}})).actions(e=>({setFilterValue(t){try{const n=b.getParent(e);b.getRoot(e).filters.setValueByKey(n.key,t)}catch(n){console.error(n)}}})).actions(e=>({setRequired(t){e.required=t},setClearable(t){e.clearable=t},setInputFormat(t){e.inputFormat=t},setDefaultValue(t){e.default_value.length=0,e.default_value.push(...t),e.setFilterValue(t)},setMaxDays(t){e.max_days=t,t>0&&(e.clearable=!0)},setAllowSingleDateInRange(t){e.allowSingleDateInRange=t}})),nl=b.types.snapshotProcessor(J1,{preProcessor({default_value:e,...t}){return{...t,default_value:e.map(n=>n===null?null:U.tz(n,"UTC").toISOString())}},postProcessor(e){const{default_value:t,...n}=e;return{...n,default_value:tl(t,n.inputFormat)}}}),Z1=()=>nl.create({_name:"date-range",required:!1,inputFormat:"YYYY-MM-DD",clearable:!1,default_value:[null,null]}),H1=b.types.model({label:b.types.string,value:b.types.string}).actions(e=>({setLabel(t){e.label=t},setValue(t){e.value=t}})),Ai=b.types.model("FilterConfigModel_BaseSelect",{static_options:b.types.optional(b.types.array(H1),[]),options_query_id:b.types.optional(b.types.string,""),default_selection_count:b.types.optional(b.types.number,0),required:b.types.optional(b.types.boolean,!1)}).views(e=>({get usingQuery(){return!!e.options_query_id}})).views(e=>({get options(){if(!e.usingQuery)return e.static_options;const{data:t,state:n,error:r}=b.getRoot(e).content.getDataStuffByID(e.options_query_id);return n==="idle"?t:[]}})).actions(e=>({setRequired(t){e.required=t},addStaticOption(t){e.static_options.push(t)},removeStaticOption(t){e.static_options.splice(t,1)},setDefaultSelectionCount(t){e.default_selection_count=t},setOptionsQueryID(t){e.options_query_id=t??""}})),rl=b.types.compose("FilterMultiSelectConfigMeta",b.types.model({_name:b.types.literal("multi-select"),min_width:b.types.optional(b.types.string,""),default_value:b.types.optional(b.types.array(b.types.string),[])}),Ai).views(e=>({get json(){const{_name:t,default_value:n,required:r,min_width:a,static_options:o,options_query_id:l,default_selection_count:u}=e;return or({_name:t,required:!!r,min_width:a,default_value:n,static_options:o,options_query_id:l,default_selection_count:u})},get default_selection(){return e.usingQuery?e.options.slice(0,e.default_selection_count).map(t=>t.value):e.default_value},truthy(t){return Array.isArray(t)&&t.length>0}})).actions(e=>({setDefaultValue(t){e.default_value=b.cast(t)},setMinWidth(t){e.min_width=t},setDefaultSelection(){const t=b.getRoot(e).content.filters,n=b.getParent(e).key;t.setValueByKey(n,e.default_selection)}})).actions(e=>({afterCreate(){b.addDisposer(e,te.reaction(()=>te.toJS(e.default_selection),e.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),eS=()=>rl.create({_name:"multi-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),il=b.types.compose("FilterConfigModel_Select",b.types.model({_name:b.types.literal("select"),default_value:b.types.string,width:b.types.optional(b.types.string,"")}),Ai).views(e=>({get json(){const{_name:t,default_value:n,required:r,width:a,static_options:o,options_query_id:l,default_selection_count:u}=e;return or({_name:t,width:a,required:r,default_value:n,static_options:o,options_query_id:l,default_selection_count:u})},truthy(t){return!!t},getSelectOption(t){return e.options.find(n=>n.value===t)},get default_selection(){return e.usingQuery?e.default_selection_count>0&&e.options.length>0?e.options[0].value:"":e.default_value}})).actions(e=>({setDefaultValue(t){e.default_value=t},setWidth(t){e.width=t},setDefaultSelection(){const t=b.getRoot(e).content.filters,n=b.getParent(e).key;t.setValueByKey(n,e.default_selection)}})).actions(e=>({afterCreate(){b.addDisposer(e,te.reaction(()=>te.toJS(e.default_selection),e.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),tS=()=>il.create({_name:"select",required:!1,default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),al=b.types.model("FilterTextInputConfigMeta",{_name:b.types.literal("text-input"),required:b.types.boolean,default_value:b.types.string}).views(e=>({get json(){const{_name:t,required:n,default_value:r}=e;return{_name:t,required:n,default_value:r}},truthy(t){return typeof t!="string"?!1:!!t.trim()}})).actions(e=>({setRequired(t){e.required=t},setDefaultValue(t){e.default_value=t}})),sl=()=>al.create({_name:"text-input",required:!1,default_value:""});function nS(e){return Pu.arrayToTree(e,{id:"value",parentId:"parent_value",childrenField:"children",dataField:null})}function rS(e){return e.map(t=>{const{label:n,description:r,...a}=t,o={...a,filterBasis:`${n}___${r??""}`,description:r,label:n};return r&&(o.label=y.createElement("div",{},[y.createElement(s.Text,{key:0,title:t.label},t.label),y.createElement(s.Text,{key:1,className:"rc-tree-select-tree-title-desc",color:"dimmed",title:t.description},t.description)])),o})}const ol=b.types.compose("FilterTreeSelectConfigMeta",b.types.model({_name:b.types.literal("tree-select"),min_width:b.types.optional(b.types.string,""),default_value:b.types.optional(b.types.array(b.types.string),[]),treeCheckStrictly:b.types.optional(b.types.boolean,!1)}),Ai).views(e=>({get json(){const{_name:t,default_value:n,required:r,min_width:a,static_options:o,options_query_id:l,default_selection_count:u,treeCheckStrictly:c}=e;return{_name:t,required:!!r,min_width:a,default_value:n,static_options:o,options_query_id:l,treeCheckStrictly:c,default_selection_count:u}},get treeData(){const{data:t}=b.getRoot(e).content.getDataStuffByID(e.options_query_id),n=rS(t);return nS(n)},get errorMessage(){const{error:t}=b.getRoot(e).content.getDataStuffByID(e.options_query_id);return t},get treeDataLoading(){const{state:t}=b.getRoot(e).content.getDataStuffByID(e.options_query_id);return t==="loading"},get defaultSelection(){const{default_selection_count:t}=e;return t?this.treeData.slice(0,t).map(r=>r.value):[]},truthy(t){return Array.isArray(t)&&t.length>0}})).actions(e=>({setDefaultValue(t){e.default_value=b.cast(t)},setMinWidth(t){e.min_width=t},setTreeCheckStrictly(t){e.treeCheckStrictly=t},applyDefaultSelection(){const t=b.getParent(e,1).key;b.getRoot(e).content.filters.setValueByKey(t,e.defaultSelection)},afterCreate(){b.addDisposer(e,te.reaction(()=>JSON.stringify(e.defaultSelection),this.applyDefaultSelection,{fireImmediately:!0,delay:0}))}})),iS=()=>ol.create({_name:"tree-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),ll=b.types.model("FilterMeta",{id:b.types.identifier,key:b.types.string,label:b.types.string,order:b.types.number,visibleInViewsIDs:b.types.array(b.types.string),auto_submit:b.types.optional(b.types.boolean,!1),type:b.types.enumeration("DashboardFilterType",[xe.Select,xe.MultiSelect,xe.TreeSelect,xe.TextInput,xe.Checkbox,xe.DateRange]),config:b.types.union(il,rl,ol,al,el,nl)}).views(e=>({get plainDefaultValue(){const t=e.config.default_value;return Array.isArray(t)?[...t]:t},get usingDefaultValue(){return e.type!==xe.TreeSelect},get auto_submit_supported(){return[xe.Select,xe.Checkbox,xe.DateRange].includes(e.type)}})).views(e=>({get json(){const{id:t,key:n,label:r,order:a,visibleInViewsIDs:o,auto_submit:l,type:u,config:c}=e;return{id:t,key:n,type:u,label:r,order:a,config:c.json,auto_submit:l,visibleInViewsIDs:te.toJS(o)}},get visibleInViewsIDSet(){return new Set(e.visibleInViewsIDs)},get should_auto_submit(){return e.auto_submit_supported&&e.auto_submit},requiredAndPass(t){return x.get(e.config,"required",!1)?x.get(e.config,"truthy",()=>!0)(t):!1}})).actions(e=>({setKey(t){e.key=t},setLabel(t){e.label=t},setOrder(t){e.order=t},setType(t){switch(t){case xe.Select:e.config=tS();break;case xe.MultiSelect:e.config=eS();break;case xe.TreeSelect:e.config=iS();break;case xe.TextInput:e.config=sl();break;case xe.Checkbox:e.config=X1();break;case xe.DateRange:e.config=Z1();break}e.type=t},setVisibleInViewsIDs(t){e.visibleInViewsIDs.length=0,e.visibleInViewsIDs.push(...t)},setAutoSubmit(t){e.auto_submit=e.auto_submit_supported&&t}}));var j=(e=>(e.Division="div",e.Modal="modal",e.Tabs="tabs",e))(j||{});const ul=b.types.model("ViewDivisionConfig",{_name:b.types.literal(j.Division)}).views(e=>({get json(){const{_name:t}=e;return{_name:t}}})),aS=()=>ul.create({_name:j.Division}),sS=b.types.model("CustomModalTitleModel",{enabled:b.types.optional(b.types.boolean,!1),func_content:b.types.optional(b.types.string,"")}).views(e=>({get json(){const{enabled:t,func_content:n}=e;return{enabled:t,func_content:n}},get value(){const{enabled:t,func_content:n}=e,r=b.getParent(e,2),a=b.getRoot(e);if(!t)return r.name;try{const o={filters:a.content.filters.values,context:a.context.current};return new Function(`return ${n}`)()(o)}catch(o){return console.error(o),r.name}}})).actions(e=>({setEnabled(t){e.enabled=t},setFuncContent(t){e.func_content=t},replace({enabled:t,func_content:n}){e.enabled=t,e.func_content=n}})),zi={enabled:!1,func_content:["function text({ filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
|
|
440
|
-
`)},cl=b.types.model("ViewModalConfig",{_name:b.types.literal(j.Modal),width:b.types.string,height:b.types.string,custom_modal_title:b.types.optional(sS,zi)}).views(e=>({get json(){const{_name:t,width:n,height:r,custom_modal_title:a}=e;return{_name:t,width:n,height:r,custom_modal_title:a.json}}})).actions(e=>({setWidth(t){e.width=t},setHeight(t){e.height=t}})),oS=()=>cl.create({_name:j.Modal,width:"90vw",height:"90vh"}),lS=b.types.model("ViewTabsTabModel",{id:b.types.identifier,name:b.types.string,view_id:b.types.string,color:b.types.optional(b.types.string,"")}).views(e=>({get json(){const{id:t,name:n,view_id:r,color:a}=e;return{id:t,name:n,color:a,view_id:r}}})).actions(e=>({setName(t){e.name=t},setViewID(t){e.view_id=t},setColor(t){e.color=t}})),dl=b.types.model("ViewTabsConfig",{_name:b.types.literal(j.Modal),tabs:b.types.optional(b.types.array(lS),[]),variant:b.types.optional(b.types.enumeration("variant",["default","outline","pills"]),"default"),orientation:b.types.optional(b.types.enumeration("orientation",["horizontal","vertical"]),"horizontal"),grow:b.types.optional(b.types.boolean,!1)}).views(e=>({get json(){const{_name:t,variant:n,orientation:r,tabs:a,grow:o}=e;return{grow:o,tabs:a.map(l=>l.json),_name:t,variant:n,orientation:r}}})).actions(e=>({setVariant(t){e.variant=t},setOrientation(t){e.orientation=t},setGrow(t){e.grow=t},setTabs(t){e.tabs.length=0,e.tabs=b.cast(t)},addTab(){const t=ke.randomId(),n={id:t,name:t,view_id:""};e.tabs.push(n)},removeTab(t){e.tabs.splice(t,1)}})),uS=()=>dl.create({_name:j.Modal,tabs:[]}),cS=b.types.model({id:b.types.identifier,name:b.types.string,type:b.types.enumeration("EViewComponentType",[j.Division,j.Modal,j.Tabs]),config:b.types.union(ul,cl,dl),panelIDs:b.types.optional(b.types.array(b.types.string),[])}).views(e=>({get json(){const{id:t,name:n,type:r,config:a}=e;return{id:t,name:n,type:r,config:a.json,panelIDs:e.panelIDs}}})).actions(e=>({setName(t){e.name=t},setType(t){if(e.type!==t){switch(t){case j.Division:e.config=aS();break;case j.Modal:e.config=oS();break;case j.Tabs:e.config=uS();break}e.type=t}},appendPanelID(t){e.panelIDs.push(t)},removePanelID(t){const n=e.panelIDs.filter(r=>r!==t);e.panelIDs.length=0,e.panelIDs.push(...n)}})),pl=b.types.model("DataSourceMetaModel",{id:b.types.string,type:b.types.enumeration("DataSourceType",[ve.HTTP,ve.MySQL,ve.Postgresql]),key:b.types.string,config:b.types.frozen()}),dS=b.types.model("DataSourcesMetaModel",{list:b.types.optional(b.types.array(pl),[])}).views(e=>({find({type:t,key:n}){return e.list.find(r=>r.key===n&&r.type===t)},get options(){return e.list.map(t=>({value:t.key,label:t.key}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}})),pS=b.types.model({id:b.types.string,content:b.types.string,create_time:b.types.string,update_time:b.types.string,is_preset:b.types.boolean}),hl=b.types.model("GlobalSQLSnippetsMeta",{list:b.types.optional(b.types.array(pS),[])}).views(e=>({find(t){return e.list.find(n=>n.id===t)},get options(){return e.list.map(t=>({value:t.id,label:t.id}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}})),Ei=b.types.model("ContextMeta",{current:b.types.optional(b.types.frozen(),{})}).views(e=>({get keys(){return Object.keys(e.current)},get entries(){return Object.entries(e.current)}})).actions(e=>({replace(t){e.current=t},get(t){return e.current[t]},set(t,n){e.current[t]=n}}));function fl(e){return Ei.create({current:e})}const hS=b.types.compose("ViewRenderModel",cS,b.types.model({tab:b.types.optional(b.types.string,"")})).views(e=>({get defaultTab(){if(e.type!==j.Tabs)return"";const t=e.config;return t.tabs.length>0?t.tabs[0].id:""},get tabViewID(){var n;return e.type!==j.Tabs?"":((n=e.config.tabs.find(r=>r.id===e.tab))==null?void 0:n.view_id)??""},get contentModel(){return b.getParent(e,3)},get panels(){if(e.type!==j.Tabs)return this.contentModel.panels.panelsByIDs(e.panelIDs).panels;const t=this.tabViewID;return this.contentModel.views.findByID(t).panels},get renderViewIDs(){const t=[e.id];return e.type===j.Tabs&&t.push(this.tabViewID),t}})).actions(e=>({setTab(t){e.tab=t??""},afterCreate(){b.addDisposer(e,te.reaction(()=>e.defaultTab,t=>this.setTab(t),{fireImmediately:!0,delay:0}))}})),gl=b.types.model("ViewsRenderModel",{current:b.types.optional(b.types.array(hS),[]),visibleViewIDs:b.types.array(b.types.string)}).views(e=>({get json(){return e.current.map(t=>or(t.json))},get idMap(){const t=new Map;return e.current.forEach(n=>{t.set(n.id,n)}),t},findByID(t){return e.current.find(n=>n.id===t)},get firstVisibleView(){const[t]=e.visibleViewIDs;return e.current.find(({id:n})=>n===t)},get visibleViews(){const t=new Set(e.visibleViewIDs);return e.current.filter(({id:n})=>t.has(n))}})).actions(e=>({appendToVisibles(t){new Set(e.visibleViewIDs.map(r=>r)).has(t)||e.visibleViewIDs.push(t)},rmVisibleViewID(t){const n=e.visibleViewIDs.findIndex(r=>r===t);n!==-1&&e.visibleViewIDs.splice(n,1)}}));function fS(e){const t=e.length>0?[e[0].id]:[];return{current:e.map(r=>{const{_name:a=r.type}=r.config;return{...r,config:{...r.config,_name:a},panelIDs:r.panelIDs}}),visibleViewIDs:t}}const ml=Q1.views(e=>({get contentModel(){return b.getRoot(e).content}})).views(e=>({get queries(){return e.contentModel.queries.findByIDSet(e.queryIDSet)},get data(){return this.queries.reduce((t,n)=>(t[n.id]=n.data,t),{})},get dataLoading(){return this.queries.some(t=>t.state==="loading")},get queryStateMessages(){const t=this.queries.filter(o=>!o.runByConditionsMet);if(t.length===0)return"";const n=new Set,r=new Set;t.forEach(o=>{const l=o.conditionNames;l.context.forEach(u=>n.add(u)),l.filters.forEach(u=>r.add(u))});const a=[];return n.size>0&&(console.log(n),a.push(`context: ${Array.from(n).join(", ")}`)),r.size>0&&a.push(`filter${r.size>1?"s":""}: ${Array.from(r).join(", ")}`),a.length===2&&a.splice(1,0,"and"),a.unshift("Waiting for"),a.join(" ")},get queryErrors(){return this.queries.map(t=>t.error).filter(t=>!!t)},get canRenderViz(){return this.queryErrors.length===0&&this.queryStateMessages===""&&!this.dataLoading}})).actions(e=>({refreshData(){e.queries.forEach(t=>t.fetchData(!0))},downloadData(){b.getRoot(e).content.queries.downloadDataByQueryIDs(e.queryIDs)}}));function gS(e){return{id:e,layout:{x:0,y:1/0,w:18,h:300},title:e,description:"<p></p>",queryIDs:[],viz:{type:bi.name,conf:bi.createConfig()},style:{border:{enabled:!0}}}}const yl=b.types.model("PanelsRenderModel",{list:b.types.optional(b.types.array(ml),[])}).views(e=>({get json(){return e.list.map(t=>t.json)},findByID(t){return e.list.find(n=>n.id===t)},get idMap(){const t=new Map;return e.list.forEach(n=>{t.set(n.id,n)}),t}})).views(e=>({panelsByIDs(t){const n=[];t.forEach(a=>{const o=e.idMap.get(a);o?n.push(o):console.warn(`Panel is not found, id:${a}`)});const r=n.map(a=>({...a.layout.json,i:a.id}));return{panels:n,layouts:r}}}));function bl(e,t){if(e===void 0)return e;if(t._name==="date-range")try{const[...n]=e;return n.map(r=>r===null?r:U.tz(r,"UTC").format(t.inputFormat)??r)}catch(n){return console.error(n),e}return e}function mS(e){return e.reduce((t,n)=>(t[n.key]=bl(n.config.default_value,n.config),t),{})}const vl=b.types.model("FiltersRenderModel",{current:b.types.optional(b.types.array(ll),[]),values:b.types.optional(b.types.frozen(),{})}).views(e=>({get json(){return e.current.map(t=>t.json)},get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(n=>n.id===t)},get inOrder(){return x.sortBy(e.current,"order")},get empty(){return e.current.length===0},visibleInView(t){return x.sortBy(e.current.filter(n=>n.visibleInViewsIDSet.has(t)),"order")},get firstFilterValueKey(){return Object.keys(e.values)[0]??""},get keyLabelMap(){return e.current.reduce((t,n)=>(t[n.key]=n.label,t),{})},getSelectOption(t){const n=this.findByID(t);if(!n||!("getSelectOption"in n.config))return null;const r=e.values[n.key];return n.config.getSelectOption(r)}})).actions(e=>({setValues(t){e.values=t},setValueByKey(t,n){e.values={...e.values,[t]:n}},getValueByKey(t){return e.values[t]}}));function xl(e){return{current:e,values:mS(e)}}const yS=new Bu.AsyncParser({withBOM:!0});async function wl(e){return!Array.isArray(e)||e.length===0?"":await yS.parse(e).promise()}async function bS(e,t){const n=await wl(t),r=new Blob([n],{type:"text/csv"});br.saveAs(r,`${e}.csv`)}function Cl(e){const t=new Vu;e.forEach(({id:n,data:r})=>{t.file(`${n}.csv`,wl(r))}),t.generateAsync({type:"blob"}).then(n=>{br.saveAs(n,"dashboard_data.zip")})}function Sl(e,t){const n=new Blob([t],{type:"application/json"});br.saveAs(n,`${e}.json`)}const vS=U1.views(e=>({get conditionOptions(){if(!b.isAlive(e))return[];const t=b.getRoot(e).content,{context:n}=t.payloadForSQL,r=Object.keys(n).map(o=>({group:"Context",label:o,value:`context.${o}`,description:void 0})),a=t.filters.keyLabelOptions.map(o=>({group:"Filters",label:o.label,value:`filters.${o.value}`,description:o.value}));return[...r,...a]},get unmetRunByConditions(){if(!b.isAlive(e))return[];const{run_by:t}=e;if(t.length===0)return[];const n=b.getRoot(e).content.payloadForSQL;return t.filter(r=>{const a=x.get(n,r);return Array.isArray(a)?a.length===0:typeof a=="number"?Number.isNaN(a):!a})}})).views(e=>({get reQueryKey(){const{react_to:t=[]}=e;if(t.length===0)return"";const n=b.getRoot(e).content.payloadForSQL,r=[...t].reduce((a,o)=>(a[o]=x.get(n,o),a),{});return JSON.stringify(r)},get runByConditionsMet(){return e.unmetRunByConditions.length===0},get conditionNames(){if(e.unmetRunByConditions.length===0)return{context:[],filters:[]};const{keyLabelMap:t}=b.getRoot(e).content.filters,n=e.unmetRunByConditions.filter(a=>a.startsWith("context.")).map(a=>a.split("context.")[0]),r=e.unmetRunByConditions.filter(a=>a.startsWith("filters.")).map(a=>x.get({filters:t},a)).filter(a=>!!a);return{context:n,filters:r}},get queries(){return b.getParent(e,2)},get inUse(){return this.queries.isQueryInUse(e.id)}}));function xS(e,t){return new Function(`return ${e}`)()(t,At)}function wS(e,t,n){return xS(e,{context:t,filters:n})}function CS(e,t){try{return new Function(`return ${e.config.processing.pre}`)()(t,At)}catch(n){return console.error(n),t}}function SS(e,t){return new Function(`return ${e.config.processing.post}`)()(t,At)}function _S(e,t){return e?new Function(`return ${e}`)()(t,At):t}const kS=b.types.compose("QueryRenderModel",vS,b.types.model({state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),data:b.types.optional(b.types.frozen([]),[]),error:b.types.frozen()})).views(e=>({get rootModel(){return b.getRoot(e)},get contentModel(){return this.rootModel.content},get formattedSQL(){const t=this.contentModel.payloadForSQL;return xr(e.sql,t)},get typedAsSQL(){return[ve.Postgresql,ve.MySQL].includes(e.type)},get typedAsHTTP(){return[ve.HTTP].includes(e.type)},get datasource(){const{key:t,type:n}=e;return this.rootModel.datasources.find({type:n,key:t})},get httpConfigString(){const{context:t,filters:n}=this.contentModel.payloadForSQL,{name:r,pre_process:a}=e.json,o=wS(a,t,n);return console.groupCollapsed(`Request config for: ${r}`),console.log(o),console.groupEnd(),JSON.stringify(o)}})).views(e=>({get stateMessage(){if(e.state!=="idle")return"";if(!e.runByConditionsMet){const{context:t,filters:n}=e.conditionNames;if(t.length===0&&n.length===0)return"Waiting";const r=[];return t.length>0&&r.push(`context: ${t.join(", ")}`),n.length>0&&r.push(`filter${n.length>1?"s":""}: ${n.join(", ")}`),r.length===2&&r.splice(1,0,"and"),r.unshift("Waiting for"),r.join(" ")}return e.data.length>0?"":"Empty Data"}})).volatile(()=>({controller:new AbortController})).actions(e=>({runSQL:b.flow(function*(){var t;if(e.valid&&((t=e.controller)==null||t.abort(),!!e.runByConditionsMet)){e.controller=new AbortController,e.state="loading";try{const n=e.contentModel.payloadForSQL;e.data=yield*b.toGenerator(Ju({payload:n,name:e.name,query:e.json},e.controller.signal)),e.state="idle",e.error=null}catch(n){if(!xt.isCancel(n)){e.data=[];const r=x.get(n,"message","unkown error");e.error=x.get(n,"response.data.detail.message",r),e.state="error"}}}}),runHTTP:b.flow(function*(){var t;if(!(!e.valid||!e.datasource)&&((t=e.controller)==null||t.abort(),!!e.runByConditionsMet)){e.controller=new AbortController,e.state="loading";try{const{type:n,key:r,post_process:a}=e.json;let o=JSON.parse(e.httpConfigString);o=CS(e.datasource,o);const l=yield*b.toGenerator(Zu({type:n,key:r,configString:JSON.stringify(o),name:e.name},e.controller.signal));let u=SS(e.datasource,l);u=_S(a,u),e.data=u,e.state="idle",e.error=null}catch(n){if(console.error(n),!xt.isCancel(n)){e.data=[];const r=x.get(n,"message","unkown error");e.error=x.get(n,"response.data.detail.message",r),e.state="error"}}}})})).actions(e=>({fetchData:t=>{if(!e.inUse&&!t){console.debug(`Skipping query[${e.name}]`);return}return e.typedAsHTTP?e.runHTTP():e.runSQL()},beforeDestroy(){var t;(t=e.controller)==null||t.abort()}})).actions(e=>({afterCreate(){b.addDisposer(e,te.reaction(()=>{var n;return e.typedAsHTTP?`${e.inUse}--${e.id}--${e.key}--${e.reQueryKey}--${(n=e.datasource)==null?void 0:n.id}`:[e.inUse,e.id,e.key,e.formattedSQL,e.pre_process,e.post_process].join("--")},()=>e.fetchData(!1),{fireImmediately:!0,delay:0}))}})),_l=b.types.model("QueriesRenderModel",{current:b.types.optional(b.types.array(kS),[])}).views(e=>({get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(n=>n.id===t)},findByIDSet(t){return e.current.filter(n=>t.has(n.id))},get json(){return e.current.filter(t=>t.id&&t.key).map(t=>t.json)},get contentModel(){return b.getParent(e,1)},get visibleQueryIDSet(){const{views:t,filters:n}=this.contentModel,r=[];t.visibleViews.forEach(l=>{l.panels.forEach(u=>{r.push(...u.queryIDs)})});const a=x.uniq(t.visibleViews.map(l=>l.renderViewIDs).flat());n.current.forEach(l=>{const u=x.get(l,"config.options_query_id");if(!u)return;a.some(d=>l.visibleInViewsIDSet.has(d))&&r.push(u)});const o=new Set(r);return console.debug("QueryIDs:",o),o},isQueryInUse(t){return this.visibleQueryIDSet.has(t)}})).actions(e=>({downloadAllData(){const t=e.current.map(({name:n,data:r})=>({id:n,data:r}));Cl(t)},downloadDataByQueryIDs(t){const n=new Set(t),r=e.current.filter(a=>n.has(a.id)).map(({name:a,data:o})=>({id:a,data:o}));Cl(r)},downloadDataByQueryID(t){const n=e.findByID(t);if(!n){console.log("[downloadDataByQueryID] query not found");return}const{name:r,data:a}=n;bS(r,a)},refetchDataByQueryID(t){const n=e.findByID(t);if(!n){console.error(new Error(`[downloadDataByQueryID] query by ID[${t}] not found`));return}return n.fetchData(!0)}}));function TS(e){return{current:e}}const DS=K1.views(e=>({isADuplicatedKey(t){return!t||t===e.key?!1:!!b.getParent(e,2).findByKey(t)}})),kl=b.types.model("SQLSnippetsRenderModel",{current:b.types.optional(b.types.array(DS),[])}).views(e=>({get json(){return e.current.map(t=>t.json)},get record(){return e.current.reduce((t,n)=>(t[n.key]=n.value,t),{})},get firstKey(){if(e.current.length!==0)return e.current[0].key},findByKey(t){return e.current.find(n=>n.key===t)}}));function IS(e){return{current:e}}function lr(e,t,n,r){return e.reduce((a,o)=>{try{a[o[t]]=vr(o[n],r)}catch(l){a[o[t]]=l.message}return a},{})}class MS{constructor(t){q(this,"origin");q(this,"copy");this.origin=t,this.copy=b.clone(t),te.makeAutoObservable(this,{},{autoBind:!0,deep:!1})}get changed(){return!x.isEqual(b.getSnapshot(this.origin),b.getSnapshot(this.copy))}commit(){b.applySnapshot(this.origin,b.getSnapshot(this.copy))}update(t){b.applySnapshot(this.copy,t)}}const AS=e=>new MS(e),zS=k.observer(({view:e})=>{const t=ue(),n=le(),r=Ge.useModals(),{panel:a,downloadPanelScreenshot:o}=rt(),{id:l}=a,{viewPanelInFullScreen:u,inFullScreen:c}=y.useContext(sr),d=()=>{n.duplicatePanelByID(l,e.id)},f=()=>{t.editor.open(["_VIEWS_",e.id,"_PANELS_",l])},h=()=>r.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>n.removePanelByID(l,e.id),confirmProps:{color:"red"},zIndex:320}),g=y.useCallback(()=>{u(l)},[l,u]),m=!c&&e.type!==j.Modal;return i(B,{children:i(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:p(s.Menu,{withinPortal:!0,children:[i(s.Menu.Target,{children:i(s.Box,{className:"panel-dropdown-target",sx:{width:"100%"}})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{onClick:a.refreshData,icon:i(D.Refresh,{size:14}),children:"Refresh"}),i(s.Menu.Item,{onClick:a.downloadData,icon:i(D.Download,{size:14}),children:"Download Data"}),i(s.Menu.Item,{onClick:o,icon:i(E.IconCamera,{size:14}),children:"Screenshot"}),m&&i(s.Menu.Item,{onClick:g,icon:i(D.ArrowsMaximize,{size:14}),disabled:!0,children:"Full Screen"}),i(s.Divider,{label:"Edit",labelPosition:"center"}),i(s.Menu.Item,{onClick:f,icon:i(D.Settings,{size:14}),children:"Settings"}),i(s.Menu.Item,{onClick:d,icon:i(D.Copy,{size:14}),children:"Duplicate"}),i(s.Menu.Item,{color:"red",onClick:h,icon:i(D.Trash,{size:14}),children:"Delete"})]})]})})})});function ES(e){return e?["<p><br></p>","<p></p>"].includes(e):!0}const $i=k.observer(()=>{const[e,t]=y.useState(!1),{panel:n}=Ct();return ES(n.description)?null:p(B,{children:[i(s.Modal,{opened:e,onClose:()=>t(!1),title:n.title,withCloseButton:!1,withinPortal:!0,zIndex:310,children:i(Rn,{value:n.description,styles:{root:{border:"none"},content:{padding:0}}})}),i(s.Tooltip,{label:"Click to see description",position:"top-start",withinPortal:!0,children:i(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>t(r=>!r),sx:{verticalAlign:"baseline",cursor:"pointer"},children:i(D.InfoCircle,{size:20})})})]})}),fM="",$S=k.observer(function(){const{panel:t}=Ct(),{title:n}=t;return n?i(s.Group,{grow:!0,position:"center",className:"panel-title-wrapper",sx:{flexGrow:1},children:i(s.Text,{align:"center",lineClamp:1,className:"panel-title-text",children:n})}):null});function LS(e){const t=y.useRef(null);return{ref:t,downloadPanelScreenshot:()=>{const r=t.current;if(!r)return;const a=r.offsetWidth*2,o=r.offsetHeight*2;Ja.toBlob(t.current,{bgcolor:"white",width:a,height:o,style:{border:"none",borderRadius:0,transformOrigin:"0 0",transform:"scale(2)"}}).then(l=>{window.saveAs(l,`${e.title?e.title:e.viz.type}.png`)})}}}var Tl=(e=>(e.migrated="migrated",e.nothingToMigrate="nothingToMigrate",e.checkFailed="checkFailed",e.migrationFailed="migrationFailed",e))(Tl||{}),ur=(e=>(e.notStarted="notStarted",e.inProgress="inProgress",e.done="done",e))(ur||{});class OS{constructor(t){q(this,"vizInstance");q(this,"operationManager");q(this,"triggerManager");q(this,"vizManager");q(this,"runningMigration");q(this,"panelModel");q(this,"status","notStarted");this.panelModel=t.getRequired(be.instanceScope.panelModel),this.vizInstance=t.getRequired(be.instanceScope.vizInstance),this.operationManager=t.getRequired(be.instanceScope.operationManager),this.triggerManager=t.getRequired(be.instanceScope.triggerManager),this.vizManager=t.getRequired(be.vizManager)}async createMigrationTask(){const t=[];try{await this.instanceNeedMigration()&&t.push(()=>this.runInstanceMigration()),await this.interactionNeedMigration()&&t.push(()=>this.runInteractionMigration())}catch(n){return console.warn("check migration failed",n),"checkFailed"}if(t.length===0)return"nothingToMigrate";try{return await Promise.all(t.map(n=>n())),"migrated"}catch(n){return console.warn("migration failed",n),"migrationFailed"}}async runMigration(){return this.runningMigration||(this.status="inProgress",this.runningMigration=this.createMigrationTask().then(t=>(this.status="done",t))),this.runningMigration}async runInteractionMigration(){await this.operationManager.runMigration(),await this.triggerManager.runMigration()}async runInstanceMigration(){const t=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData,panelModel:this.panelModel};await t.migrator.migrate(n)}async instanceNeedMigration(){const t=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData};return t.migrator.needMigration(n)}async interactionNeedMigration(){return await this.operationManager.needMigration()||await this.triggerManager.needMigration()}}function Dl(e){const{panel:t}=Ct();return y.useCallback(n=>{const r=n.getRequired(be.vizManager),a=r.resolveComponent(e.viz.type);return n.createScoped().provideFactory(be.instanceScope.vizInstance,()=>r.getOrCreateInstance(e)).provideFactory(be.instanceScope.interactionManager,o=>{const l=o.getRequired(be.instanceScope.vizInstance);return new Er(l,a,En)}).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 OS(o))},[e.viz.type,e.viz.conf])}function Il(e){const[t,n]=y.useState(!1),r=Uo().getRequired(be.instanceScope.migrator);return Q.useAsyncEffect(async()=>{const a=r.status===ur.notStarted;n(r.status===ur.done),r.status===ur.notStarted&&r.runMigration().then(o=>{o===Tl.migrated&&a&&(e==null||e())}).finally(()=>{n(!0)})},[r]),t}function Ml(e,t){const n=Uo().getRequired(be.instanceScope.vizInstance);return y.useEffect(()=>(n.instanceData.setItem(null,t.viz.conf),n.instanceData.watchItem(null,r=>{e(r)})),[e,t.viz.type]),n}function PS({setVizConf:e,...t}){const{panel:n}=t,r=Ml(e,n),a=Il(()=>{_n.showNotification({title:`${n.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})});return Q.useAsyncEffect(async()=>{await r.instanceData.setItem(null,n.viz.conf)},[r,n.viz.type]),a?i(nc,{...t}):i(s.Text,{children:"Checking update..."})}function BS(e){const{panel:t,setVizConf:n}=e;Ml(n,t);const{inEditMode:r}=y.useContext(An);return Il(()=>{r&&_n.showNotification({title:`${t.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?i(tc,{...e}):i(s.Text,{children:"Checking update"})}const gM="";function VS(e,t){const{vizManager:n}=y.useContext(ct),{panel:{viz:r,title:a,id:o,description:l,queryIDs:u,variables:c}}=Ct(),d={title:a,id:o,description:l,queryIDs:u,viz:r,layout:t},f=Dl(d);try{return n.resolveComponent(r.type),i(ar,{configure:f,children:i(BS,{setVizConf:r.setConf,panel:d,data:e,variables:c,vizManager:n})})}catch(h){return console.info(x.get(h,"message")),null}}const Al=k.observer(function({data:t}){const{ref:n,width:r,height:a}=ke.useElementSize(),o=VS(t,{w:r,h:a}),l=r>0&&a>0;return i("div",{className:"viz-root",ref:n,children:i(s.Box,{sx:{width:r,height:a,overflow:"hidden"},children:l&&i(Ne,{children:o})})})}),zl=k.observer(({panel:e})=>p(s.Stack,{children:[e.queryErrors.map((t,n)=>i(s.Text,{color:"red",size:"sm",align:"center",sx:{fontFamily:"monospace"},children:t},`${n}-${t}`)),i(s.Text,{color:"gray",align:"center",size:"sm",children:e.queryStateMessages})]})),Li=k.observer(({panel:e})=>p(s.Flex,{className:"panel-viz-section",direction:"column",sx:{position:"relative",width:"100%"},children:[i(s.LoadingOverlay,{visible:e.dataLoading,exitTransitionDuration:0}),!e.canRenderViz&&i(zl,{panel:e}),e.canRenderViz&&i(Al,{data:e.data})]})),NS={border:"1px solid #e9ecef"},El=k.observer(({panel:e,panelStyle:t,dropdownContent:n})=>{const{ref:r,downloadPanelScreenshot:a}=LS(e),o=!!e.title,l=o?"60px":"28px";return e.title&&`${l}`,i(Ir,{value:{panel:e,data:e.data,loading:e.dataLoading,errors:e.queryErrors,downloadPanelScreenshot:a},children:p(s.Box,{className:`panel-root ${o?"panel-root--show-title":""}`,ref:r,p:0,sx:{...NS,...t},children:[i(s.Box,{className:"panel-description-popover-wrapper",children:i($i,{})}),n,i($S,{}),i(Li,{panel:e})]})})}),qS={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function FS(e){return e.style.border.enabled?{}:qS}const $l=k.observer(function({panel:t,view:n}){const r=FS(t);return i(El,{panel:t,panelStyle:r,dropdownContent:i(zS,{view:n})})});function GS(e){return!["richText","button"].includes(e)}const WS=k.observer(({view:e})=>{const{panel:t,downloadPanelScreenshot:n}=Ct(),{id:r}=t,{viewPanelInFullScreen:a,inFullScreen:o}=y.useContext(sr),l=y.useCallback(()=>{a(r)},[r,a]),u=!o&&e.type!==j.Modal;return GS(t.viz.type)?i(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:p(s.Menu,{withinPortal:!0,children:[i(s.Menu.Target,{children:i(s.Box,{className:"panel-dropdown-target"})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{onClick:t.refreshData,icon:i(D.Refresh,{size:14}),children:"Refresh"}),i(s.Menu.Item,{onClick:t.downloadData,icon:i(D.Download,{size:14}),children:"Download Data"}),i(s.Menu.Item,{onClick:n,icon:i(E.IconCamera,{size:14}),children:"Screenshot"}),u&&i(s.Menu.Item,{onClick:l,icon:i(D.ArrowsMaximize,{size:14}),children:"Full Screen"})]})]})}):null});function jS(e){return e.style.border.enabled?{}:{border:"1px dashed transparent"}}const Oi=k.observer(({panel:e,view:t})=>{const n=jS(e);return i(El,{panel:e,panelStyle:n,dropdownContent:i(WS,{view:t})})}),RS={modal:{display:"flex",flexDirection:"column",flexWrap:"nowrap"},body:{display:"flex",height:"calc(100vh - 88px)"}},Ll=k.observer(function({view:t,panel:n,exitFullScreen:r}){return i(s.Modal,{opened:!0,fullScreen:!0,onClose:r,title:i(s.Button,{color:"blue",size:"xs",onClick:r,leftIcon:i(D.ArrowLeft,{size:20}),children:"Exit fullscreen"}),styles:RS,children:i(s.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:i(Oi,{view:t,panel:n})})})});function Ol(e,t,n){const{panels:r}=ye(),a=e.id==="Main",[o,l]=y.useState(()=>a&&r.findByID(t)?t:null),u=y.useCallback(h=>{l(h),a&&n(h)},[a,n]),c=y.useCallback(()=>{l(null),a&&n("")},[a,n]),d=o?r.findByID(o):null;return{viewPanelInFullScreen:u,exitFullScreen:c,inFullScreen:!!d,fullScreenPanel:d}}const mM="",YS=y.forwardRef(({h:e},t)=>i(s.ActionIcon,{ref:t,className:"react-grid-customDragHandle",sx:{userSelect:"none",cursor:"grab",position:"absolute",top:5,right:e>38?5:20,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",children:i(D.ArrowsMove,{size:16})})),QS=y.forwardRef(({handleAxis:e,...t},n)=>i(s.ActionIcon,{ref:n,className:"react-grid-customResizeHandle",sx:{userSelect:"none",cursor:"nwse-resize",position:"absolute",bottom:0,right:0,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",...t,children:i(D.ChevronDownRight,{size:16})})),US=kn.WidthProvider(kn),KS=k.observer(({view:e,className:t="layout"})=>{const n=ye(),{panels:r,layouts:a}=n.panels.panelsByIDs(e.panelIDs),o=y.useCallback(u=>{u.forEach(({i:c,...d})=>{const f=n.panels.findByID(c);f&&f.layout.set(d)})},[n]),l=(u,c,d,f)=>{d.h<30&&(d.h=30,f.h=30),d.w<4&&(d.w=4,f.w=4)};return i(US,{onLayoutChange:o,className:`dashboard-layout ${t}`,rowHeight:1,cols:36,margin:[0,0],isBounded:!0,isDraggable:!0,isResizable:!0,layout:a,draggableHandle:".react-grid-customDragHandle",resizeHandle:i(QS,{}),onResize:l,children:r.map((u,c)=>p("div",{"data-grid":{...u.layout},className:"panel-grid-item",children:[i(YS,{h:u.layout.h}),i($l,{view:e,panel:u})]},u.id))})}),XS=kn.WidthProvider(kn),JS=k.observer(function({view:t,className:n="layout"}){const{panels:r,layouts:a}=ye().panels.panelsByIDs(t.panelIDs);return i(XS,{className:`dashboard-layout ${n}`,cols:36,rowHeight:1,margin:[0,0],isDraggable:!1,isResizable:!1,layout:a,children:r.map(o=>i("div",{"data-grid":{...o.layout},className:"panel-grid-item",children:i(Oi,{view:t,panel:o})},o.id))})});function Pi(e){const t=y.useRef(null);return{ref:t,downloadScreenshot:()=>{var l;const r=(l=t.current)==null?void 0:l.querySelector(".react-grid-layout");if(!r)return;const a=r.offsetWidth*2+10,o=r.offsetHeight*2+10;Ja.toBlob(r,{bgcolor:"white",width:a,height:o,style:{transformOrigin:"0 0",transform:"scale(2)"}}).then(u=>{window.saveAs(u,`${e.name}.png`)})}}}const ZS=k.observer(({downloadScreenShot:e})=>{const[t,{setTrue:n,setFalse:r}]=Q.useBoolean(!1),a=Tr(),o=ye(),l=()=>{const u=JSON.stringify(o.json,null,2),c=`${a.name}__${o.name}`;Sl(c,u)};return p(s.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:200,closeDelay:400,withinPortal:!0,position:"bottom-end",children:[i(s.Menu.Target,{children:i(s.Affix,{position:{bottom:"20px",right:"10px"},zIndex:1,children:i(s.ActionIcon,{size:"md",variant:"gradient",gradient:{from:"indigo",to:"cyan"},onMouseEnter:n,onMouseLeave:r,sx:{opacity:t?1:.6,transform:`translateX(${t?0:"2px"})`,transition:"all ease 300ms",borderRadius:"50%"},children:i(E.IconShare3,{size:"1rem"})})})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{icon:i(E.IconCamera,{size:14}),onClick:e,children:"Screenshot"}),i(s.Menu.Divider,{}),i(s.Menu.Item,{icon:i(E.IconDownload,{size:14}),onClick:o.queries.downloadAllData,children:"Download Data"}),i(s.Menu.Item,{icon:i(E.IconCode,{size:14}),onClick:l,children:"Download Schema"})]})]})}),Pl=k.observer(({children:e,view:t,sx:n={}})=>{const{ref:r,downloadScreenshot:a}=Pi(t);return p(B,{children:[i(s.Box,{ref:r,sx:n,children:e}),i(ZS,{downloadScreenShot:a})]})}),Bl=k.observer(({downloadScreenshot:e})=>i(s.ActionIcon,{className:"download-screenshot-button",color:"blue",onClick:e,children:i(E.IconCamera,{size:14})})),HS=k.observer(({children:e,view:t})=>{const n=ye(),r=t.config,a=n.views.visibleViewIDs.includes(t.id),o=()=>n.views.rmVisibleViewID(t.id),{ref:l,downloadScreenshot:u}=Pi(t);return i(s.Modal,{size:r.width,centered:!0,opened:a,onClose:o,withCloseButton:!1,title:p(s.Group,{position:"apart",px:"1rem",h:"48px",children:[i(s.Box,{children:r.custom_modal_title.value}),i(Bl,{downloadScreenshot:u})]}),trapFocus:!0,onDragStart:c=>{c.stopPropagation()},styles:{root:{position:"fixed",zIndex:200,inset:0},overlay:{zIndex:"unset"},inner:{zIndex:"unset",padding:"0 !important"},content:{border:"1px solid #efefef",maxHeight:"unset !important",overflow:"hidden"},body:{maxHeight:r.height,overflow:"auto",position:"relative"},header:{padding:0},title:{flexGrow:1}},transitionProps:{duration:0},children:i(s.Box,{ref:l,children:e})})}),e_=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},t_=k.observer(({view:e})=>{const t=ye(),n=e.config;return p(s.Tabs,{className:"render-view-tabs",variant:n.variant,orientation:n.orientation,value:e.tab,onTabChange:e.setTab,styles:{root:{height:"100%",overflow:n.orientation==="horizontal"?"hidden":"auto"},panel:{padding:n.orientation==="horizontal"?"8px 0px 8px":"0",height:"100%",overflow:"auto"}},keepMounted:!1,children:[i(s.Tabs.List,{grow:n.grow,children:n.tabs.map(r=>i(s.Tabs.Tab,{value:r.id,sx:e_(r),disabled:!r.view_id,children:r.name??r.id},r.id))}),n.tabs.map(r=>{const a=t.views.findByID(r.view_id);return a?i(s.Tabs.Panel,{value:r.id,children:i(cr,{view:a})},r.id):null})]})}),n_=k.observer(({view:e,children:t})=>{switch(e.type){case j.Modal:return i(HS,{view:e,children:t});case j.Tabs:return i(t_,{view:e});case j.Division:default:return i(Pl,{view:e,children:t})}}),r_=k.observer(({children:e,view:t})=>i(Pl,{sx:{paddingTop:"10px",paddingBottom:"100px"},view:t,children:e}));function Vl(e){return e.replace(/(vw|vh)/,"%")}const i_=k.observer(({children:e,view:t})=>{const n=t.config,{width:r,height:a}=y.useMemo(()=>({width:Vl(n.width),height:Vl(n.height)}),[n.width,n.height]),{ref:o,downloadScreenshot:l}=Pi(t);return i(s.Box,{sx:{height:"100%","> div:not(.mantine-Modal-root)":{height:"100%"}},children:i(s.Modal,{size:n.width,opened:!0,onClose:x.noop,withCloseButton:!1,title:p(s.Group,{position:"apart",px:"1rem",h:"48px",children:[i(s.Box,{children:n.custom_modal_title.value}),i(Bl,{downloadScreenshot:l})]}),trapFocus:!0,onDragStart:u=>{u.stopPropagation()},styles:{root:{position:"relative",height:"100%"},overlay:{position:"absolute !important"},inner:{position:"relative",top:"50%",left:"50%",right:"unset",bottom:"unset",transform:"translate(-50%, -50%)",padding:"0 !important",width:r,height:a,maxHeight:a},content:{border:"1px solid #efefef",height:"100%"},body:{maxHeight:"calc(100% - 48px)",overflow:"auto"},header:{padding:0},title:{flexGrow:1}},withinPortal:!1,transitionProps:{duration:0},children:i(s.Box,{ref:o,children:e})})})}),a_=({variant:e,orientation:t})=>{const n={root:{height:"100%",overflow:"hidden"},tab:{},panel:{padding:"16px"}};return e==="pills"&&t==="horizontal"&&(n.tab.paddingTop="6px",n.tab.paddingBottom="6px"),t==="vertical"&&(n.tab["&.add-a-tab"]={paddingTop:"1px",paddingBottom:"1px"},n.tab["&.add-a-tab .mantine-Tabs-tabLabel"]={marginLeft:"auto",marginRight:"auto"}),n},s_=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},o_=k.observer(({view:e})=>{const t=Ge.useModals(),n=le(),r=y.useMemo(()=>n.views.options.filter(u=>u.type===j.Division),[e.id,n.views.options]),a=e.config,o=u=>t.openConfirmModal({title:"Delete this tab?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{a.removeTab(u)},confirmProps:{color:"red"},zIndex:320}),l=a.tabs.length===0;return p(s.Tabs,{className:"preview-view-tabs",variant:a.variant,orientation:a.orientation,value:e.tab,onTabChange:e.setTab,styles:a_(a),children:[p(s.Tabs.List,{grow:a.grow,children:[a.tabs.map(u=>i(s.Tabs.Tab,{value:u.id,sx:s_(u),children:u.name??u.id},u.id)),i(s.Tabs.Tab,{onClick:a.addTab,value:"add",className:"add-a-tab",children:i(D.Plus,{size:18,color:"#228be6"})})]}),a.tabs.map((u,c)=>{const d=n.views.findByID(u.view_id);return p(s.Tabs.Panel,{value:u.id,sx:{position:"relative"},children:[p(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:200},children:[i(s.Overlay,{opacity:.8,color:"#FFF",blur:10,zIndex:100}),p(s.Stack,{mx:"auto",mt:100,sx:{width:"300px",position:"relative",zIndex:200},children:[i(s.TextInput,{label:"Tab Name",value:u.name,onChange:f=>u.setName(f.currentTarget.value)}),i(s.Select,{label:"View",value:u.view_id,onChange:u.setViewID,data:r}),i(s.ColorInput,{label:"Color",value:u.color,onChange:u.setColor,disabled:a.variant!=="default"}),d&&p(s.Button,{mt:20,variant:"gradient",leftIcon:i(E.IconArrowsLeftRight,{size:18}),gradient:{from:"cyan",to:"indigo"},onClick:()=>n.views.setIDOfVIE(d.id),children:["Swith to View: ",d.name]}),i(s.Button,{mt:20,variant:"subtle",color:"red",onClick:()=>o(c),disabled:l,leftIcon:i(E.IconTrash,{size:14}),children:"Delete This Tab"})]})]}),d&&i(cr,{view:d})]},u.id)})]})}),l_=k.observer(({view:e,children:t})=>{switch(e.type){case j.Modal:return i(i_,{view:e,children:t});case j.Tabs:return i(o_,{view:e});case j.Division:default:return i(r_,{view:e,children:t})}}),Nl=k.observer(function({view:t}){return i(sr.Provider,{value:{viewPanelInFullScreen:x.noop,inFullScreen:!1},children:i(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:i(l_,{view:t,children:p(s.Box,{sx:{position:"relative"},children:[i(s.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:i(Jo,{view:t})}),i(KS,{view:t})]})})})})}),cr=k.observer(function({view:t}){const{fullScreenPanelID:n,setFullScreenPanelID:r}=ds(),{viewPanelInFullScreen:a,exitFullScreen:o,inFullScreen:l,fullScreenPanel:u}=Ol(t,n,r);return i(sr.Provider,{value:{viewPanelInFullScreen:a,inFullScreen:l},children:p(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,sx:{height:t.type===j.Modal?"0 !important":"100%"},children:[l&&i(Ll,{view:t,panel:u,exitFullScreen:o}),i(n_,{view:t,children:p(s.Box,{sx:{position:"relative"},children:[!l&&i(s.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:i(Jo,{view:t})}),!l&&i(JS,{view:t})]})})]})})});var ql=(e=>(e.Use="use",e.Edit="edit",e))(ql||{});const u_={[j.Division]:"Division",[j.Tabs]:"Tabs",[j.Modal]:"Modal"},Fl={[j.Division]:"rgba(255, 0, 0, 0.2)",[j.Modal]:"rgba(0, 0, 0, 0.2)",[j.Tabs]:"rgba(255, 200, 100, 0.4)"},c_={[j.Division]:"#ff4000",[j.Modal]:"#000",[j.Tabs]:"#ffad18"},d_={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:j.Division,config:{},panelIDs:[]}],panels:[],filters:[],version:"9.19.0"};function p_(e,t,n){b.addDisposer(e,b.addMiddleware(e,(r,a)=>{a(r,()=>{b.getType(r.context)===t&&r.type==="action"&&n(r.name,r.context)})}))}const Gl=b.types.compose("FiltersModel",vl,b.types.model("FiltersModel",{previewValues:b.types.optional(b.types.frozen(),{})})).views(e=>({get options(){return e.current.map(t=>({label:t.label??t.id,value:t.id,_type:"filter"}))},get selects(){return e.current.filter(t=>t.type===xe.Select).map(t=>({label:t.label??t.id,value:t.id}))},get keyLabelOptions(){return e.current.map(t=>({label:t.label??t.key,value:t.key}))}})).actions(e=>({replace(t){e.current=b.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByID(t){const n=e.current.findIndex(r=>r.id===t);n>=0&&e.current.splice(n,1)},updatePreviewValues(t){e.previewValues=t}})).actions(e=>{function t(){p_(e.current,ll,(n,r)=>{if(n==="setType"){const a=bl(r.config.default_value,r.config);e.setValueByKey(r.key,a),e.updatePreviewValues({...e.previewValues,[r.key]:a})}})}return{afterCreate(){t()}}}),Wl=_l.views(e=>({get options(){const t=e.current.map(n=>({value:n.id,label:n.name,_type:"query"}));return x.sortBy(t,n=>n.label.toLowerCase())},get sortedList(){return x.sortBy(e.current,t=>t.name.toLowerCase())}})).actions(e=>({replace(t){e.current=b.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},replaceByIndex(t,n){e.current.splice(t,1,n)},removeQuery(t){const n=e.current.find(r=>r.id===t);n&&(b.detach(n),e.current.remove(n))},removeQueries(t){const n=new Set(t);e.current.forEach(a=>{n.has(a.id)&&b.detach(a)});const r=[...e.current];x.remove(r,a=>n.has(a.id)),e.current=b.cast(r)}})),jl=kl.views(e=>({get sortedList(){return x.sortBy(e.current,t=>t.key.toLowerCase())},get options(){const t=e.current.map(n=>({label:n.key,value:n.key,_type:"sql_snippet"}));return x.sortBy(t,n=>n.label.toLowerCase())}})).actions(e=>({replace(t){e.current=b.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByKey(t){const n=e.current.findIndex(r=>r.key===t);n>=0&&e.current.splice(n,1)},removeByKeys(t){const n=new Set(t);e.current.forEach(a=>{n.has(a.key)&&b.detach(a)});const r=[...e.current];x.remove(r,a=>n.has(a.key)),e.current=b.cast(r)},replaceByIndex(t,n){e.current.splice(t,1,n)}})),h_=b.types.model({data:b.types.optional(b.types.frozen(),[]),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0},get sql(){const t=b.getParent(e,1),{type:n,table_name:r,table_schema:a}=t;if(n===ve.MySQL)return`
|
|
439
|
+
`}}}function f1(e,t){const n=Yt(e.heat_block.min,t),r=Yt(e.heat_block.max,t);return{min:n,max:r,calculable:!0,orient:"horizontal",left:"center",top:0,itemWidth:15}}function g1(e,t,n){const r=O(e.x_axis.data_key),a=x.uniq(t[r.queryID].map(c=>c[r.columnKey])),{overflow:o,rotate:l}=e.x_axis.axisLabel,u=it(o.on_axis);return{id:"main-x-axis",type:"category",data:a,name:e.x_axis.name??"",align:"center",axisTick:{show:!0,alignWithLabel:!0},axisLabel:{rotate:l,...u,formatter:n},splitArea:{show:!0},nameLocation:"center",nameGap:25,nameTextStyle:{fontWeight:"bold",align:"center"},z:2}}function m1(e,t,n){const r=O(e.x_axis.data_key),a=O(e.y_axis.data_key),{nameAlignment:o,data_key:l,...u}=e.y_axis,c=x.uniq(t[r.queryID].map(g=>g[a.columnKey])),{overflow:d,rotate:f}=e.y_axis.axisLabel,h=it(d.on_axis);return{...u,type:"category",data:c,axisLabel:{rotate:f,...h,formatter:n},axisLine:{show:!0,color:"blue"},axisTick:{show:!0,alignWithLabel:!0},splitArea:{show:!0},nameTextStyle:{fontWeight:"bold",align:o},nameLocation:"end",nameGap:15,z:2}}const y1={tooltip:{confine:!0}};function b1(e,t,n){if(!e.x_axis.data_key||!e.y_axis.data_key||!e.heat_block.data_key)return{};const r=n.reduce((u,c)=>{const d=mt(c,t);return u[c.name]=Ze(c,d),u},{}),a=o1(e),o=l1(e),l={xAxis:g1(e,t,a.x_axis),yAxis:m1(e,t,a.y_axis),series:c1(e,t),tooltip:h1(e,t,a,o),grid:u1(e),visualMap:f1(e,r)};return x.defaultsDeep({},l,y1)}ie.use([F.DataZoomComponent,he.HeatmapChart,F.GridComponent,F.LegendComponent,F.TooltipComponent,F.VisualMapComponent,Ee.CanvasRenderer]);function v1({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=y.useMemo(()=>{const h=O(e.x_axis.data_key),g=O(e.y_axis.data_key);return x.keyBy(t[h.queryID],m=>`${m[h.columnKey]}---${m[g.columnKey]}`)},[t,e.x_axis.data_key,e.y_axis.data_key]),u=Ke(a.triggerManager,Qo.id),c=y.useCallback(h=>{const[g,m]=h.value,C=x.get(l,`${g}---${m}`,{error:"rowData is not found"});u.forEach(w=>{a.runInteraction(w.id,{...h,rowData:C})})},[l,u,a]),d=y.useMemo(()=>({click:c}),[c]),f=y.useMemo(()=>b1(e,t,o),[e,t]);return i(ze,{echarts:ie,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function x1({context:e,instance:t}){const n=Xe({vizManager:e.vizManager,instance:t}),{value:r}=R(e.instanceData,"config"),{variables:a}=e,o=y.useMemo(()=>x.defaults({},r,Di),[r]),l=e.data,{width:u,height:c}=e.viewport;return!u||!c?null:i(Ve,{width:u,height:c,children:i(v1,{variables:a,width:tt(u),height:nt(c),data:l,conf:o,interactionManager:n})})}class w1 extends ge{constructor(){super(...arguments);q(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const C1={displayName:"Merico Heatmap",displayGroup:"Merico suite",migrator:new w1,name:"merico-heatmap",viewRender:x1,configRender:i1,createConfig:()=>({version:1,config:Di}),triggers:[Qo]},S1=[{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"})),_1=[ac,sc,uc,lc,oc,cc],Ko=()=>({id:"dashboard",version:os,manifest:{viz:[bi,ux,$w,qb,zx,zy,nC,_c,jh,nm,Nm,m0,by,$g,Jv,nb,zb,Fw,LC,C1,UC,af],color:[...S1,..._1]}}),yn=new fc,be={pluginManager:ht("pluginManager"),vizManager:ht("vizManager"),colorManager:ht("colorManager"),instanceScope:{panelModel:ht("panelModel"),vizInstance:ht("vizInstance"),interactionManager:ht("interactionManager"),migrator:ht("migrator"),operationManager:ht("operationManager"),triggerManager:ht("triggerManager")}},Ii=()=>{try{yn.install(Ko())}catch{}const e=new nc(yn),t=new hc(yn);return{pluginManager:yn,vizManager:e,colorManager:t}},ct=y.createContext(Ii());try{yn.install(Ko())}catch{}const Mi=y.createContext(null);function ar(e){const t=y.useContext(Mi),n=Q.useCreation(()=>e.configure(t||new Cr),[e.configure]),r=Q.usePrevious(n);return r&&r!==n&&r.dispose(),i(Mi.Provider,{value:n,children:e.children})}function Xo(){return y.useContext(Mi)}const k1=({description:e,isDescriptionEmpty:t})=>t?null:i(s.Tooltip,{color:"white",label:i(Rn,{value:e,styles:{root:{border:"none"},content:{padding:0}}}),styles:{tooltip:{border:"0.0625rem solid rgb(233, 236, 239)",boxShadow:"rgb(0 0 0 / 5%) 0px 0.0625rem 0.1875rem, rgb(0 0 0 / 5%) 0px 1.25rem 1.5625rem -0.3125rem, rgb(0 0 0 / 4%) 0px 0.625rem 0.625rem -0.3125rem"}},withArrow:!0,children:i(s.Box,{sx:{height:"16px",alignSelf:"center"},children:i(E.IconInfoCircle,{size:16,color:"gray"})})}),T1=k.observer(({label:e,config:{default_value:t,description:n,isDescriptionEmpty:r,...a},value:o,onChange:l})=>p(s.Box,{children:[i(s.Text,{children:" "}),i(s.Checkbox,{label:p(s.Group,{noWrap:!0,position:"apart",align:"middle",spacing:6,children:[i(s.Box,{sx:{flexGrow:1},children:e}),i(k1,{description:n,isDescriptionEmpty:r})]}),checked:o||!1,onChange:u=>l(u.currentTarget.checked),...a,pt:".4em",styles:{input:{borderColor:"#e9ecef"}}})]})),Jo=k.observer(({label:e,config:t,value:n=[null,null],onChange:r})=>{const{inputFormat:a,...o}=t,l=Array.isArray(n)?n.map(f=>f?U(f).toDate():null):[null,null],u=f=>{r(f.map(h=>h&&U(h).format(a)))},c=t.getMinDate(l[0]),d=t.getMaxDate(l[0]);return i(Bu.DatePickerInput,{type:"range",label:e,value:l,onChange:u,icon:i(D.Calendar,{size:16}),sx:{minWidth:"16em"},minDate:c,maxDate:d,valueFormat:a,styles:{input:{borderColor:"#e9ecef"}},...o})}),D1=s.createStyles((e,{radius:t=4})=>({root:{borderRadius:e.fn.radius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-select.rc-select-open":{borderColor:"#228be6 !important",".rc-select-selection-overflow-item-rest":{display:"none"},".rc-select-selection-overflow-item-suffix":{display:"block"}},".rc-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-select-selection-search-mirror":{display:"none"},".rc-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},required:{color:"#fa5252",paddingLeft:"3px"},dropdown:{fontSize:e.fontSizes.xs,zIndex:300,backgroundColor:"#fff",border:"1px solid #e9ecef",marginTop:6,padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px","&.rc-select-dropdown-slide-up-leave-active":{display:"none"},".rc-select-item-empty":{padding:"8px 12px"},".rc-select-item-option":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"8px 12px 8px 2px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},flexDirection:"row-reverse",".rc-select-item-option-state":{flexGrow:0,flexShrink:0,width:"30px",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},".rc-select-item-option-content":{width:"calc(100% - 30px)",overflow:"hidden",'div[data-role="label"]':{overflowWrap:"break-word"}}},".rc-virtual-list-holder-inner":{alignItems:"flex-start"}}})),Zo=({errorMessage:e})=>e?i(s.Text,{color:"red",size:12,children:e}):i(s.Text,{color:"dimmed",size:12,children:"Not found"}),I1=({disabled:e,classNames:t,styles:n,unstyled:r,radius:a,style:o,label:l,value:u,onChange:c,options:d,errorMessage:f,required:h})=>{const{classes:g,cx:m}=D1({radius:a},{name:"MultiSelectWidget",classNames:t,styles:n,unstyled:r}),[C,w]=y.useState(!1),_=$=>{w($)},T=C&&(u==null?void 0:u.length)>0,[M,P]=y.useState(""),G=y.useMemo(()=>{if(!M)return d;const $=M.toLowerCase(),L=A=>{var N;return((N=A.description)==null?void 0:N.toLowerCase().includes($))||A.label.toLowerCase().includes($)};return d.filter(L)},[M,d]);return p(s.Stack,{spacing:3,children:[p(s.Group,{position:"apart",children:[p(s.Text,{className:g.label,children:[l,h&&i("span",{className:g.required,"aria-hidden":"true",children:"*"})]}),T&&i(s.Tooltip,{label:`${u.length} selected`,children:i(s.Badge,{children:u.length})})]}),i(Ka,{disabled:e,allowClear:!0,className:m(g.root,"check-select"),dropdownClassName:m(g.dropdown,""),onDropdownVisibleChange:_,transitionName:"rc-select-dropdown-slide-up",choiceTransitionName:"rc-select-selection__choice-zoom",style:o,clearIcon:()=>i(s.CloseButton,{}),value:u,onChange:c,onSelect:console.log,mode:"multiple",maxTagCount:0,notFoundContent:i(Zo,{errorMessage:f}),maxTagTextLength:10,maxTagPlaceholder:$=>`${$.length} selected`,searchValue:M,onSearch:P,filterOption:!1,children:G.map($=>p(Ka.Option,{title:$.label,children:[i(s.Text,{size:"sm","data-role":"label",children:$.label}),$.description&&i(s.Text,{size:"xs",color:"dimmed","data-role":"description",children:$.description})]},$.value))})]})},M1=k.observer(({label:e,config:t,value:n,onChange:r})=>{const a=ye(),o=!!t.options_query_id,{state:l,error:u}=a.getDataStuffByID(t.options_query_id),c=l==="loading",d=t.min_width?t.min_width:"200px",f=o?c:!1,h=g=>r(g,!1);return i(I1,{label:e,options:t.options,style:{minWidth:"160px",width:d,maxWidth:f?d:"unset",borderColor:"#e9ecef"},disabled:f,value:n,onChange:h,errorMessage:u,required:t.required})}),A1=y.forwardRef(({label:e,description:t,...n},r)=>i("div",{ref:r,...n,children:i(s.Group,{noWrap:!0,children:p("div",{children:[i(s.Text,{size:"sm","data-role":"label",children:e}),i(s.Text,{size:"xs",color:"dimmed","data-role":"description",children:t})]})})})),z1=k.observer(({label:e,config:t,value:n,onChange:r})=>{const a=ye(),o=!!t.options_query_id,{state:l,error:u}=a.getDataStuffByID(t.options_query_id),c=l==="loading";return i(s.Select,{label:e,data:t.options,disabled:o?c:!1,value:n,onChange:r,error:!!u,placeholder:u,maxDropdownHeight:500,styles:{root:{width:t.width?t.width:"200px"},input:{borderColor:"#e9ecef"}},sx:{".mantine-Select-item[data-selected] .mantine-Text-root[data-role=description]":{color:"rgba(255,255,255,.7)"}},itemComponent:A1})});function E1({label:e,config:t,value:n,onChange:r}){return i(s.TextInput,{label:e,value:n||"",onChange:a=>r(a.currentTarget.value),...t,styles:{input:{borderColor:"#e9ecef"}}})}const $1=({rotate:e,onClick:t})=>i("svg",{onClick:t,className:"caret-icon",viewBox:"0 0 1024 1024",focusable:"false","data-icon":"caret-down",width:"14px",height:"14px",fill:"currentColor","aria-hidden":"true",transform:`rotate(${e})`,children:i("path",{d:"M840.4 300H183.6c-19.7 0-30.7 20.8-18.5 35l328.4 380.8c9.4 10.9 27.5 10.9 37 0L858.9 335c12.2-14.2 1.2-35-18.5-35z"})}),L1=({expanded:e,isLeaf:t,value:n,onClick:r,...a})=>(n==="0-0-value"&&console.log(a),t?i("span",{style:{width:"14px",display:"inline-block"}}):i($1,{rotate:e?"0":"-90",onClick:r,...a})),O1=({onClick:e})=>p("svg",{onClick:e,className:"checkbox-icon",width:"16",height:"16",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[i("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),i("rect",{className:"border",x:"4",y:"4",width:"16",height:"16",rx:"2"}),i("rect",{className:"checkmark-indeterminate",x:"8",y:"8",width:"8",height:"8",rx:"2",stroke:"none"}),i("path",{className:"checkmark-checked",d:"M9 12l2 2l4 -4"})]}),P1=({onClick:e,...t})=>i(O1,{onClick:e,...t}),B1=s.createStyles((e,{radius:t=4})=>({root:{borderRadius:e.fn.radius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-tree-select.rc-tree-select-open":{borderColor:"#228be6 !important",".rc-tree-select-selection-overflow-item-rest":{display:"none"},".rc-tree-select-selection-overflow-item-suffix":{display:"block"}},".rc-tree-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-tree-select-selection-search-mirror":{display:"none"},".rc-tree-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-tree-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-tree-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-tree-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-tree-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-tree-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-tree-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-tree-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},required:{color:"#fa5252",paddingLeft:"3px"},dropdown:{fontSize:e.fontSizes.xs,zIndex:300,paddingTop:"6px","&.rc-tree-select-dropdown-slide-up-leave-active":{display:"none"},".rc-tree-select-tree-list .rc-tree-select-tree-list-holder":{},".rc-tree-select-tree-list, .rc-tree-select-empty":{backgroundColor:"#fff",border:"1px solid #e9ecef",padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px"},".rc-tree-select-empty":{padding:"8px 12px"},".rc-tree-select-tree-treenode":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"8px 12px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},"&.rc-tree-select-tree-treenode-checkbox-checked":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-checked":{stroke:"rgb(64, 192, 87)",animation:"check 200ms linear forwards"}},"&.rc-tree-select-tree-treenode-checkbox-indeterminate":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-indeterminate":{fill:"rgb(64, 192, 87)"}},".rc-tree-select-tree-switcher":{height:"16px",alignSelf:"center",paddingRight:"2px",transition:"color 200ms ease","&:hover":{color:"#228be6","svg.caret-icon":{color:"#228be6"}},"svg.caret-icon":{color:"#ced4da",transition:"all 200ms ease"}},".rc-tree-select-tree-node-content-wrapper":{display:"flex",flexWrap:"nowrap",overflow:"hidden",alignItems:"center",gap:"8px",transition:"color 200ms ease","&:hover":{color:"#228be6"}},".rc-tree-select-tree-iconEle":{height:"16px","svg .border":{stroke:"#ced4da"},".checkbox-icon .checkmark-indeterminate":{fill:"transparent",transition:"fill 200ms ease"},".checkbox-icon .checkmark-checked":{transform:"scale(1.2)",transformOrigin:"center center",strokeDasharray:10,strokeDashoffset:-10},"@keyframes check":{"0%":{strokeDashoffset:10},"100%":{strokeDashoffset:0}}},".rc-tree-select-tree-title":{textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden",".rc-tree-select-tree-title-desc":{fontSize:"12px",maxWidth:"100%",textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden"}},".rc-tree-select-tree-indent":{flexGrow:0,height:0,verticalAlign:"bottom"},".rc-tree-select-tree-indent-unit":{display:"inline-block",width:"1em"}}}})),V1=({disabled:e,classNames:t,styles:n,unstyled:r,radius:a,style:o,label:l,value:u,onChange:c,treeData:d,errorMessage:f,required:h,treeCheckStrictly:g})=>{const{classes:m,cx:C}=B1({radius:a},{name:"FilterTreeSelectWidget",classNames:t,styles:n,unstyled:r}),[w,_]=y.useState(!1),T=P=>{_(P)},M=w&&(u==null?void 0:u.length)>0;return p(s.Stack,{spacing:3,children:[p(s.Group,{position:"apart",children:[p(s.Text,{className:m.label,children:[l,h&&i("span",{className:m.required,"aria-hidden":"true",children:"*"})]}),M&&i(s.Tooltip,{label:`${u.length} selected`,children:i(s.Badge,{children:u.length})})]}),i(Xa,{disabled:e,allowClear:!0,treeCheckStrictly:g,className:C(m.root,"check-select"),dropdownClassName:C(m.dropdown,""),onDropdownVisibleChange:T,transitionName:"rc-tree-select-dropdown-slide-up",choiceTransitionName:"rc-tree-select-selection__choice-zoom",style:o,treeLine:!0,clearIcon:()=>i(s.CloseButton,{}),switcherIcon:L1,treeIcon:P1,maxTagTextLength:10,value:u,treeData:d,notFoundContent:i(Zo,{errorMessage:f}),treeNodeFilterProp:"filterBasis",treeCheckable:!0,showCheckedStrategy:Xa.SHOW_PARENT,onChange:c,onSelect:console.log,maxTagCount:0,maxTagPlaceholder:P=>`${P.length} selected`})]})},N1=k.observer(({label:e,config:t,value:n,onChange:r})=>{const{treeData:a,treeDataLoading:o,errorMessage:l}=t,u=t.min_width?t.min_width:"200px",d=!!t.options_query_id?o:!1;return i(V1,{disabled:d,style:{minWidth:"160px",width:u,maxWidth:d?u:"unset",borderColor:"#e9ecef"},value:n,onChange:f=>r(f,!1),treeData:a,errorMessage:l,label:e,required:t.required,treeCheckStrictly:t.treeCheckStrictly})}),q1=k.observer(({filter:{type:e,config:t,key:n,...r},formFieldProps:a})=>{switch(e){case"select":return i(z1,{...r,...a,config:t});case"multi-select":return i(M1,{...r,...a,config:t});case"tree-select":return i(N1,{...r,...a,config:t});case"text-input":return i(E1,{...r,...a,config:t});case"date-range":return i(Jo,{...r,...a,config:t});case"checkbox":return i(T1,{...r,...a,config:t});default:return null}}),F1=k.observer(y.forwardRef(({filter:e,...t},n)=>i("div",{className:"filter-root",ref:n,children:i(Ne,{children:i(q1,{filter:e,formFieldProps:t})})})));function G1(e){const t=le();y.useEffect(()=>{var n,r;(r=(n=t.filters).updatePreviewValues)==null||r.call(n,e)},[e])}const Ho=k.observer(function({view:t}){const n=ye(),{control:r,handleSubmit:a,reset:o}=v.useForm({defaultValues:n.filters.values,reValidateMode:"onBlur"}),l=v.useWatch({control:r});y.useEffect(()=>{o(n.filters.values)},[n.filters.values,o]),G1(l);const u=n.filters.visibleInView(t.id),c=y.useMemo(()=>u.every(g=>g.should_auto_submit),[u]),d=y.useMemo(()=>u.filter(g=>x.get(g,"config.required",!1)),[u]),f=y.useMemo(()=>d.length===0?!1:d.some(g=>!g.requiredAndPass(l[g.key])),[l,d]);if(u.length===0)return null;const h=(g,m)=>(C,w)=>{m(C),(g.should_auto_submit||w)&&n.filters.setValueByKey(g.key,C)};return i("form",{onSubmit:a(n.filters.setValues),children:p(s.Group,{className:"dashboard-filters",position:"apart",noWrap:!0,sx:c?{}:{border:"1px solid #e9ecef",borderRadius:"4px",padding:"16px"},children:[i(s.Group,{align:"flex-start",children:u.map(g=>i(v.Controller,{name:g.key,control:r,render:({field:m})=>i(F1,{filter:g,value:m.value,onChange:h(g,m.onChange)})},g.id))}),!c&&i(s.Group,{sx:{alignSelf:"flex-end"},children:i(s.Button,{color:"blue",size:"sm",type:"submit",disabled:f,children:"Search"})})]})})}),W1={viewPanelInFullScreen:x.noop,inFullScreen:!1},sr=y.createContext(W1),el=b.types.model("MockContextMeta",{current:b.types.optional(b.types.frozen(),{})}).views(e=>({get keys(){return Object.keys(e.current)},get entries(){return Object.entries(e.current)}})).actions(e=>({replace(t){e.current=t},get(t){return e.current[t]},set(t,n){e.current[t]=n}}));function tl(e){return{current:e}}const j1=b.types.model("PanelLayoutMeta",{x:b.types.number,y:b.types.maybeNull(b.types.number),w:b.types.number,h:b.types.number,moved:b.types.optional(b.types.boolean,!1),static:b.types.optional(b.types.boolean,!1)}).views(e=>({get json(){const{x:t,y:n,w:r,h:a,moved:o}=e;return{h:a,w:r,x:t,y:n===null?0:n,moved:o,static:e.static}}})).actions(e=>({set(t){const{x:n,y:r,w:a,h:o,moved:l}=t;e.x=n,e.y=r,e.w=a,e.h=o,e.moved=!!l,e.static=!!t.static},setWidth(t){e.w=t},setHeight(t){e.h=t}})),R1=b.types.model("PanelStyleBorderMeta",{enabled:b.types.boolean}).views(e=>({get json(){const{enabled:t}=e;return{enabled:t}}})).actions(e=>({setEnabled(t){e.enabled=t}})),Y1=b.types.model("PanelStyleMeta",{border:R1}).views(e=>({get json(){const{border:t}=e;return{border:t.json}}})).actions(e=>({})),Q1=b.types.model("VariableMeta",{name:b.types.string,size:b.types.string,weight:b.types.string,color:b.types.union(b.types.model({type:b.types.literal("static"),staticColor:b.types.string}),b.types.model({type:b.types.literal("continuous"),valueRange:b.types.array(b.types.number),colorRange:b.types.array(b.types.string)}),b.types.model({type:b.types.literal("piecewise")})),formatter:b.types.model({output:b.types.enumeration("Output",["number","percent"]),average:b.types.optional(b.types.boolean,!1),mantissa:b.types.number,trimMantissa:b.types.optional(b.types.boolean,!1)}),data_field:b.types.string,aggregation:b.types.union(b.types.model({type:b.types.enumeration(["none","sum","mean","median","min","max","CV","std"]),config:b.types.frozen()}),b.types.model({type:b.types.literal("quantile"),config:b.types.model({p:b.types.number})}),b.types.model({type:b.types.literal("custom"),config:b.types.model({func:b.types.string})}))}).views(e=>({get json(){const{name:t,size:n,weight:r,color:a,formatter:o,data_field:l,aggregation:u}=e;return x.cloneDeep({name:t,size:n,color:a,weight:r,formatter:o,data_field:l,aggregation:u})}})),U1=b.types.model("PanelVizMeta",{type:b.types.string,conf:b.types.frozen()}).views(e=>({get json(){return{conf:e.conf,type:e.type}}})).actions(e=>({setType(t){e.type=t},setConf(t){e.conf=t}})),K1=b.types.model({id:b.types.string,title:b.types.string,description:b.types.string,layout:j1,queryIDs:b.types.array(b.types.string),viz:U1,style:Y1,variables:b.types.optional(b.types.array(Q1),[])}).views(e=>({get json(){const{id:t,title:n,description:r,queryIDs:a}=e;return{id:t,viz:e.viz.json,style:e.style.json,title:n,layout:e.layout.json,queryIDs:[...a],variables:e.variables.map(o=>o.json),description:r}},get queryIDSet(){return new Set(e.queryIDs)}})).actions(e=>({setID(t){e.id=t},setTitle(t){e.title=t},setDescription(t){e.description=t},addQueryID(t){e.queryIDSet.has(t)||e.queryIDs.push(t)},removeQueryID(t){if(!e.queryIDSet.has(t))return;const n=new Set(e.queryIDSet);n.delete(t),e.queryIDs=b.cast(Array.from(n))},setQueryIDs(t){e.queryIDs=b.cast(t)},addVariable(t){e.variables.push(t)},removeVariable(t){e.variables.remove(t)}})),or=e=>x.cloneDeepWith(e,(t,n)=>{if(n!==void 0&&t)return te.toJS(t)});var ve=(e=>(e.Postgresql="postgresql",e.MySQL="mysql",e.HTTP="http",e))(ve||{});const X1=b.types.model("QueryMeta",{id:b.types.string,name:b.types.string,type:b.types.enumeration("DataSourceType",[ve.Postgresql,ve.MySQL,ve.HTTP]),key:b.types.string,sql:b.types.string,pre_process:b.types.optional(b.types.string,""),post_process:b.types.optional(b.types.string,""),run_by:b.types.optional(b.types.array(b.types.string),[]),react_to:b.types.optional(b.types.array(b.types.string),[])}).views(e=>({get valid(){return e.id&&e.type&&e.key&&e.name?e.type===ve.HTTP?!!e.pre_process:!!e.sql:!1},get json(){const{id:t,name:n,type:r,key:a,sql:o,run_by:l,react_to:u,pre_process:c,post_process:d}=e;return or({id:t,key:a,sql:o,name:n,type:r,run_by:l,react_to:u,pre_process:c,post_process:d})}})).actions(e=>({setName(t){e.name=t},setKey(t){e.key=t},setType(t){e.type=t},setSQL(t){e.sql=t},setRunBy(t){e.run_by.length=0,e.run_by.push(...t)},setReactTo(t){e.react_to.length=0,e.react_to.push(...t)},setPreProcess(t){e.pre_process=t},setPostProcess(t){e.post_process=t}})),J1=b.types.model("SQLSnippetMeta",{key:b.types.string,value:b.types.string}).views(e=>({get json(){const{key:t,value:n}=e;return{key:t,value:n}}})).actions(e=>({setKey(t){e.key=t},setValue(t){e.value=t}}));var xe=(e=>(e.Select="select",e.MultiSelect="multi-select",e.TreeSelect="tree-select",e.TextInput="text-input",e.Checkbox="checkbox",e.DateRange="date-range",e))(xe||{});const nl=b.types.model("FilterCheckboxConfigMeta",{_name:b.types.literal("checkbox"),description:b.types.optional(b.types.string,""),default_value:b.types.boolean}).views(e=>({get json(){const{_name:t,description:n,default_value:r}=e;return{_name:t,description:n,default_value:r}},get isDescriptionEmpty(){const{description:t}=e;return t===""||t==="<p></p>"}})).actions(e=>({setDefaultValue(t){e.default_value=t},setDescription(t){e.description=t}})),Z1=()=>nl.create({_name:"checkbox",description:"",default_value:!1});function rl(e,t){return e.map(n=>{try{return n?U.tz(n,"UTC").format(t):null}catch{return console.log(`[date-range] failed parsing ${n}`),null}})}const H1=b.types.model("FilterDateRangeConfigMeta",{_name:b.types.literal("date-range"),required:b.types.boolean,inputFormat:b.types.enumeration("DateRangeInputFormat",["YYYY","YYYYMM","YYYYMMDD","YYYY-MM","YYYY-MM-DD"]),default_value:b.types.optional(b.types.array(b.types.union(b.types.string,b.types.null)),[null,null]),clearable:b.types.boolean,max_days:b.types.optional(b.types.number,0),allowSingleDateInRange:b.types.optional(b.types.boolean,!1)}).views(e=>({get json(){const{_name:t,max_days:n,required:r,clearable:a,inputFormat:o,default_value:l,allowSingleDateInRange:u}=e;return{_name:t,max_days:n,required:r,clearable:a,inputFormat:o,default_value:rl(l,o),allowSingleDateInRange:u}},truthy(t){return Array.isArray(t)&&t.length===2&&t.every(n=>!!n)}})).views(e=>({getMaxDate(t){const{max_days:n}=e;if(!(!n||!t))return U(t).startOf("day").add(n,"days").toDate()},getMinDate(t){const{max_days:n}=e;if(!(!n||!t))return U(t).startOf("day").subtract(n,"days").toDate()}})).actions(e=>({setFilterValue(t){try{const n=b.getParent(e);b.getRoot(e).filters.setValueByKey(n.key,t)}catch(n){console.error(n)}}})).actions(e=>({setRequired(t){e.required=t},setClearable(t){e.clearable=t},setInputFormat(t){e.inputFormat=t},setDefaultValue(t){e.default_value.length=0,e.default_value.push(...t),e.setFilterValue(t)},setMaxDays(t){e.max_days=t,t>0&&(e.clearable=!0)},setAllowSingleDateInRange(t){e.allowSingleDateInRange=t}})),il=b.types.snapshotProcessor(H1,{preProcessor({default_value:e,...t}){return{...t,default_value:e.map(n=>n===null?null:U.tz(n,"UTC").toISOString())}},postProcessor(e){const{default_value:t,...n}=e;return{...n,default_value:rl(t,n.inputFormat)}}}),eS=()=>il.create({_name:"date-range",required:!1,inputFormat:"YYYY-MM-DD",clearable:!1,default_value:[null,null]}),tS=b.types.model({label:b.types.string,value:b.types.string}).actions(e=>({setLabel(t){e.label=t},setValue(t){e.value=t}})),Ai=b.types.model("FilterConfigModel_BaseSelect",{static_options:b.types.optional(b.types.array(tS),[]),options_query_id:b.types.optional(b.types.string,""),default_selection_count:b.types.optional(b.types.number,0),required:b.types.optional(b.types.boolean,!1)}).views(e=>({get usingQuery(){return!!e.options_query_id}})).views(e=>({get options(){if(!e.usingQuery)return e.static_options;const{data:t,state:n,error:r}=b.getRoot(e).content.getDataStuffByID(e.options_query_id);return n==="idle"?t:[]}})).actions(e=>({setRequired(t){e.required=t},addStaticOption(t){e.static_options.push(t)},removeStaticOption(t){e.static_options.splice(t,1)},setDefaultSelectionCount(t){e.default_selection_count=t},setOptionsQueryID(t){e.options_query_id=t??""}})),al=b.types.compose("FilterMultiSelectConfigMeta",b.types.model({_name:b.types.literal("multi-select"),min_width:b.types.optional(b.types.string,""),default_value:b.types.optional(b.types.array(b.types.string),[])}),Ai).views(e=>({get json(){const{_name:t,default_value:n,required:r,min_width:a,static_options:o,options_query_id:l,default_selection_count:u}=e;return or({_name:t,required:!!r,min_width:a,default_value:n,static_options:o,options_query_id:l,default_selection_count:u})},get default_selection(){return e.usingQuery?e.options.slice(0,e.default_selection_count).map(t=>t.value):e.default_value},truthy(t){return Array.isArray(t)&&t.length>0}})).actions(e=>({setDefaultValue(t){e.default_value=b.cast(t)},setMinWidth(t){e.min_width=t},setDefaultSelection(){const t=b.getRoot(e).content.filters,n=b.getParent(e).key;t.setValueByKey(n,e.default_selection)}})).actions(e=>({afterCreate(){b.addDisposer(e,te.reaction(()=>te.toJS(e.default_selection),e.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),nS=()=>al.create({_name:"multi-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),sl=b.types.compose("FilterConfigModel_Select",b.types.model({_name:b.types.literal("select"),default_value:b.types.string,width:b.types.optional(b.types.string,"")}),Ai).views(e=>({get json(){const{_name:t,default_value:n,required:r,width:a,static_options:o,options_query_id:l,default_selection_count:u}=e;return or({_name:t,width:a,required:r,default_value:n,static_options:o,options_query_id:l,default_selection_count:u})},truthy(t){return!!t},getSelectOption(t){return e.options.find(n=>n.value===t)},get default_selection(){return e.usingQuery?e.default_selection_count>0&&e.options.length>0?e.options[0].value:"":e.default_value}})).actions(e=>({setDefaultValue(t){e.default_value=t},setWidth(t){e.width=t},setDefaultSelection(){const t=b.getRoot(e).content.filters,n=b.getParent(e).key;t.setValueByKey(n,e.default_selection)}})).actions(e=>({afterCreate(){b.addDisposer(e,te.reaction(()=>te.toJS(e.default_selection),e.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),rS=()=>sl.create({_name:"select",required:!1,default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),ol=b.types.model("FilterTextInputConfigMeta",{_name:b.types.literal("text-input"),required:b.types.boolean,default_value:b.types.string}).views(e=>({get json(){const{_name:t,required:n,default_value:r}=e;return{_name:t,required:n,default_value:r}},truthy(t){return typeof t!="string"?!1:!!t.trim()}})).actions(e=>({setRequired(t){e.required=t},setDefaultValue(t){e.default_value=t}})),ll=()=>ol.create({_name:"text-input",required:!1,default_value:""});function iS(e){return Vu.arrayToTree(e,{id:"value",parentId:"parent_value",childrenField:"children",dataField:null})}function aS(e){return e.map(t=>{const{label:n,description:r,...a}=t,o={...a,filterBasis:`${n}___${r??""}`,description:r,label:n};return r&&(o.label=y.createElement("div",{},[y.createElement(s.Text,{key:0,title:t.label},t.label),y.createElement(s.Text,{key:1,className:"rc-tree-select-tree-title-desc",color:"dimmed",title:t.description},t.description)])),o})}const ul=b.types.compose("FilterTreeSelectConfigMeta",b.types.model({_name:b.types.literal("tree-select"),min_width:b.types.optional(b.types.string,""),default_value:b.types.optional(b.types.array(b.types.string),[]),treeCheckStrictly:b.types.optional(b.types.boolean,!1)}),Ai).views(e=>({get json(){const{_name:t,default_value:n,required:r,min_width:a,static_options:o,options_query_id:l,default_selection_count:u,treeCheckStrictly:c}=e;return{_name:t,required:!!r,min_width:a,default_value:n,static_options:o,options_query_id:l,treeCheckStrictly:c,default_selection_count:u}},get treeData(){const{data:t}=b.getRoot(e).content.getDataStuffByID(e.options_query_id),n=aS(t);return iS(n)},get errorMessage(){const{error:t}=b.getRoot(e).content.getDataStuffByID(e.options_query_id);return t},get treeDataLoading(){const{state:t}=b.getRoot(e).content.getDataStuffByID(e.options_query_id);return t==="loading"},get defaultSelection(){const{default_selection_count:t}=e;return t?this.treeData.slice(0,t).map(r=>r.value):[]},truthy(t){return Array.isArray(t)&&t.length>0}})).actions(e=>({setDefaultValue(t){e.default_value=b.cast(t)},setMinWidth(t){e.min_width=t},setTreeCheckStrictly(t){e.treeCheckStrictly=t},applyDefaultSelection(){const t=b.getParent(e,1).key;b.getRoot(e).content.filters.setValueByKey(t,e.defaultSelection)},afterCreate(){b.addDisposer(e,te.reaction(()=>JSON.stringify(e.defaultSelection),this.applyDefaultSelection,{fireImmediately:!0,delay:0}))}})),sS=()=>ul.create({_name:"tree-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),cl=b.types.model("FilterMeta",{id:b.types.identifier,key:b.types.string,label:b.types.string,order:b.types.number,visibleInViewsIDs:b.types.array(b.types.string),auto_submit:b.types.optional(b.types.boolean,!1),type:b.types.enumeration("DashboardFilterType",[xe.Select,xe.MultiSelect,xe.TreeSelect,xe.TextInput,xe.Checkbox,xe.DateRange]),config:b.types.union(sl,al,ul,ol,nl,il)}).views(e=>({get plainDefaultValue(){const t=e.config.default_value;return Array.isArray(t)?[...t]:t},get usingDefaultValue(){return e.type!==xe.TreeSelect},get auto_submit_supported(){return[xe.Select,xe.Checkbox,xe.DateRange].includes(e.type)}})).views(e=>({get json(){const{id:t,key:n,label:r,order:a,visibleInViewsIDs:o,auto_submit:l,type:u,config:c}=e;return{id:t,key:n,type:u,label:r,order:a,config:c.json,auto_submit:l,visibleInViewsIDs:te.toJS(o)}},get visibleInViewsIDSet(){return new Set(e.visibleInViewsIDs)},get should_auto_submit(){return e.auto_submit_supported&&e.auto_submit},requiredAndPass(t){return x.get(e.config,"required",!1)?x.get(e.config,"truthy",()=>!0)(t):!1}})).actions(e=>({setKey(t){e.key=t},setLabel(t){e.label=t},setOrder(t){e.order=t},setType(t){switch(t){case xe.Select:e.config=rS();break;case xe.MultiSelect:e.config=nS();break;case xe.TreeSelect:e.config=sS();break;case xe.TextInput:e.config=ll();break;case xe.Checkbox:e.config=Z1();break;case xe.DateRange:e.config=eS();break}e.type=t},setVisibleInViewsIDs(t){e.visibleInViewsIDs.length=0,e.visibleInViewsIDs.push(...t)},setAutoSubmit(t){e.auto_submit=e.auto_submit_supported&&t}}));var j=(e=>(e.Division="div",e.Modal="modal",e.Tabs="tabs",e))(j||{});const dl=b.types.model("ViewDivisionConfig",{_name:b.types.literal(j.Division)}).views(e=>({get json(){const{_name:t}=e;return{_name:t}}})),oS=()=>dl.create({_name:j.Division}),lS=b.types.model("CustomModalTitleModel",{enabled:b.types.optional(b.types.boolean,!1),func_content:b.types.optional(b.types.string,"")}).views(e=>({get json(){const{enabled:t,func_content:n}=e;return{enabled:t,func_content:n}},get value(){const{enabled:t,func_content:n}=e,r=b.getParent(e,2),a=b.getRoot(e);if(!t)return r.name;try{const o={filters:a.content.filters.values,context:a.context.current};return new Function(`return ${n}`)()(o)}catch(o){return console.error(o),r.name}}})).actions(e=>({setEnabled(t){e.enabled=t},setFuncContent(t){e.func_content=t},replace({enabled:t,func_content:n}){e.enabled=t,e.func_content=n}})),zi={enabled:!1,func_content:["function text({ filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
|
|
440
|
+
`)},pl=b.types.model("ViewModalConfig",{_name:b.types.literal(j.Modal),width:b.types.string,height:b.types.string,custom_modal_title:b.types.optional(lS,zi)}).views(e=>({get json(){const{_name:t,width:n,height:r,custom_modal_title:a}=e;return{_name:t,width:n,height:r,custom_modal_title:a.json}}})).actions(e=>({setWidth(t){e.width=t},setHeight(t){e.height=t}})),uS=()=>pl.create({_name:j.Modal,width:"90vw",height:"90vh"}),cS=b.types.model("ViewTabsTabModel",{id:b.types.identifier,name:b.types.string,view_id:b.types.string,color:b.types.optional(b.types.string,"")}).views(e=>({get json(){const{id:t,name:n,view_id:r,color:a}=e;return{id:t,name:n,color:a,view_id:r}}})).actions(e=>({setName(t){e.name=t},setViewID(t){e.view_id=t},setColor(t){e.color=t}})),hl=b.types.model("ViewTabsConfig",{_name:b.types.literal(j.Modal),tabs:b.types.optional(b.types.array(cS),[]),variant:b.types.optional(b.types.enumeration("variant",["default","outline","pills"]),"default"),orientation:b.types.optional(b.types.enumeration("orientation",["horizontal","vertical"]),"horizontal"),grow:b.types.optional(b.types.boolean,!1)}).views(e=>({get json(){const{_name:t,variant:n,orientation:r,tabs:a,grow:o}=e;return{grow:o,tabs:a.map(l=>l.json),_name:t,variant:n,orientation:r}}})).actions(e=>({setVariant(t){e.variant=t},setOrientation(t){e.orientation=t},setGrow(t){e.grow=t},setTabs(t){e.tabs.length=0,e.tabs=b.cast(t)},addTab(){const t=ke.randomId(),n={id:t,name:t,view_id:""};e.tabs.push(n)},removeTab(t){e.tabs.splice(t,1)}})),dS=()=>hl.create({_name:j.Modal,tabs:[]}),pS=b.types.model({id:b.types.identifier,name:b.types.string,type:b.types.enumeration("EViewComponentType",[j.Division,j.Modal,j.Tabs]),config:b.types.union(dl,pl,hl),panelIDs:b.types.optional(b.types.array(b.types.string),[])}).views(e=>({get json(){const{id:t,name:n,type:r,config:a}=e;return{id:t,name:n,type:r,config:a.json,panelIDs:e.panelIDs}}})).actions(e=>({setName(t){e.name=t},setType(t){if(e.type!==t){switch(t){case j.Division:e.config=oS();break;case j.Modal:e.config=uS();break;case j.Tabs:e.config=dS();break}e.type=t}},appendPanelID(t){e.panelIDs.push(t)},removePanelID(t){const n=e.panelIDs.filter(r=>r!==t);e.panelIDs.length=0,e.panelIDs.push(...n)}})),fl=b.types.model("DataSourceMetaModel",{id:b.types.string,type:b.types.enumeration("DataSourceType",[ve.HTTP,ve.MySQL,ve.Postgresql]),key:b.types.string,config:b.types.frozen()}),hS=b.types.model("DataSourcesMetaModel",{list:b.types.optional(b.types.array(fl),[])}).views(e=>({find({type:t,key:n}){return e.list.find(r=>r.key===n&&r.type===t)},get options(){return e.list.map(t=>({value:t.key,label:t.key}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}})),fS=b.types.model({id:b.types.string,content:b.types.string,create_time:b.types.string,update_time:b.types.string,is_preset:b.types.boolean}),gl=b.types.model("GlobalSQLSnippetsMeta",{list:b.types.optional(b.types.array(fS),[])}).views(e=>({find(t){return e.list.find(n=>n.id===t)},get options(){return e.list.map(t=>({value:t.id,label:t.id}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}})),Ei=b.types.model("ContextMeta",{current:b.types.optional(b.types.frozen(),{})}).views(e=>({get keys(){return Object.keys(e.current)},get entries(){return Object.entries(e.current)}})).actions(e=>({replace(t){e.current=t},get(t){return e.current[t]},set(t,n){e.current[t]=n}}));function ml(e){return Ei.create({current:e})}const gS=b.types.compose("ViewRenderModel",pS,b.types.model({tab:b.types.optional(b.types.string,"")})).views(e=>({get defaultTab(){if(e.type!==j.Tabs)return"";const t=e.config;return t.tabs.length>0?t.tabs[0].id:""},get tabViewID(){var n;return e.type!==j.Tabs?"":((n=e.config.tabs.find(r=>r.id===e.tab))==null?void 0:n.view_id)??""},get contentModel(){return b.getParent(e,3)},get panels(){if(e.type!==j.Tabs)return this.contentModel.panels.panelsByIDs(e.panelIDs).panels;const t=this.tabViewID;return this.contentModel.views.findByID(t).panels},get renderViewIDs(){const t=[e.id];return e.type===j.Tabs&&t.push(this.tabViewID),t}})).actions(e=>({setTab(t){e.tab=t??""},afterCreate(){b.addDisposer(e,te.reaction(()=>e.defaultTab,t=>this.setTab(t),{fireImmediately:!0,delay:0}))}})),yl=b.types.model("ViewsRenderModel",{current:b.types.optional(b.types.array(gS),[]),visibleViewIDs:b.types.array(b.types.string)}).views(e=>({get json(){return e.current.map(t=>or(t.json))},get idMap(){const t=new Map;return e.current.forEach(n=>{t.set(n.id,n)}),t},findByID(t){return e.current.find(n=>n.id===t)},get firstVisibleView(){const[t]=e.visibleViewIDs;return e.current.find(({id:n})=>n===t)},get visibleViews(){const t=new Set(e.visibleViewIDs);return e.current.filter(({id:n})=>t.has(n))}})).actions(e=>({appendToVisibles(t){new Set(e.visibleViewIDs.map(r=>r)).has(t)||e.visibleViewIDs.push(t)},rmVisibleViewID(t){const n=e.visibleViewIDs.findIndex(r=>r===t);n!==-1&&e.visibleViewIDs.splice(n,1)}}));function mS(e){const t=e.length>0?[e[0].id]:[];return{current:e.map(r=>{const{_name:a=r.type}=r.config;return{...r,config:{...r.config,_name:a},panelIDs:r.panelIDs}}),visibleViewIDs:t}}const bl=K1.views(e=>({get contentModel(){return b.getRoot(e).content}})).views(e=>({get queries(){return e.contentModel.queries.findByIDSet(e.queryIDSet)},get data(){return this.queries.reduce((t,n)=>(t[n.id]=n.data,t),{})},get dataLoading(){return this.queries.some(t=>t.state==="loading")},get queryStateMessages(){const t=this.queries.filter(o=>!o.runByConditionsMet);if(t.length===0)return"";const n=new Set,r=new Set;t.forEach(o=>{const l=o.conditionNames;l.context.forEach(u=>n.add(u)),l.filters.forEach(u=>r.add(u))});const a=[];return n.size>0&&(console.log(n),a.push(`context: ${Array.from(n).join(", ")}`)),r.size>0&&a.push(`filter${r.size>1?"s":""}: ${Array.from(r).join(", ")}`),a.length===2&&a.splice(1,0,"and"),a.unshift("Waiting for"),a.join(" ")},get queryErrors(){return this.queries.map(t=>t.error).filter(t=>!!t)},get canRenderViz(){return this.queryErrors.length===0&&this.queryStateMessages===""&&!this.dataLoading}})).actions(e=>({refreshData(){e.queries.forEach(t=>t.fetchData(!0))},downloadData(){b.getRoot(e).content.queries.downloadDataByQueryIDs(e.queryIDs)}}));function yS(e){return{id:e,layout:{x:0,y:1/0,w:18,h:300},title:e,description:"<p></p>",queryIDs:[],viz:{type:bi.name,conf:bi.createConfig()},style:{border:{enabled:!0}}}}const vl=b.types.model("PanelsRenderModel",{list:b.types.optional(b.types.array(bl),[])}).views(e=>({get json(){return e.list.map(t=>t.json)},findByID(t){return e.list.find(n=>n.id===t)},get idMap(){const t=new Map;return e.list.forEach(n=>{t.set(n.id,n)}),t}})).views(e=>({panelsByIDs(t){const n=[];t.forEach(a=>{const o=e.idMap.get(a);o?n.push(o):console.warn(`Panel is not found, id:${a}`)});const r=n.map(a=>({...a.layout.json,i:a.id}));return{panels:n,layouts:r}}}));function xl(e,t){if(e===void 0)return e;if(t._name==="date-range")try{const[...n]=e;return n.map(r=>r===null?r:U.tz(r,"UTC").format(t.inputFormat)??r)}catch(n){return console.error(n),e}return e}function bS(e){return e.reduce((t,n)=>(t[n.key]=xl(n.config.default_value,n.config),t),{})}const wl=b.types.model("FiltersRenderModel",{current:b.types.optional(b.types.array(cl),[]),values:b.types.optional(b.types.frozen(),{})}).views(e=>({get json(){return e.current.map(t=>t.json)},get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(n=>n.id===t)},get inOrder(){return x.sortBy(e.current,"order")},get empty(){return e.current.length===0},visibleInView(t){return x.sortBy(e.current.filter(n=>n.visibleInViewsIDSet.has(t)),"order")},get firstFilterValueKey(){return Object.keys(e.values)[0]??""},get keyLabelMap(){return e.current.reduce((t,n)=>(t[n.key]=n.label,t),{})},getSelectOption(t){const n=this.findByID(t);if(!n||!("getSelectOption"in n.config))return null;const r=e.values[n.key];return n.config.getSelectOption(r)}})).actions(e=>({setValues(t){e.values=t},setValueByKey(t,n){e.values={...e.values,[t]:n}},getValueByKey(t){return e.values[t]}}));function Cl(e){return{current:e,values:bS(e)}}const vS=new Nu.AsyncParser({withBOM:!0});async function Sl(e){return!Array.isArray(e)||e.length===0?"":await vS.parse(e).promise()}async function xS(e,t){const n=await Sl(t),r=new Blob([n],{type:"text/csv"});br.saveAs(r,`${e}.csv`)}function _l(e){const t=new qu;e.forEach(({id:n,data:r})=>{t.file(`${n}.csv`,Sl(r))}),t.generateAsync({type:"blob"}).then(n=>{br.saveAs(n,"dashboard_data.zip")})}function kl(e,t){const n=new Blob([t],{type:"application/json"});br.saveAs(n,`${e}.json`)}const wS=X1.views(e=>({get conditionOptions(){if(!b.isAlive(e))return[];const t=b.getRoot(e).content,{context:n}=t.payloadForSQL,r=Object.keys(n).map(o=>({group:"Context",label:o,value:`context.${o}`,description:void 0})),a=t.filters.keyLabelOptions.map(o=>({group:"Filters",label:o.label,value:`filters.${o.value}`,description:o.value}));return[...r,...a]},get unmetRunByConditions(){if(!b.isAlive(e))return[];const{run_by:t}=e;if(t.length===0)return[];const n=b.getRoot(e).content.payloadForSQL;return t.filter(r=>{const a=x.get(n,r);return Array.isArray(a)?a.length===0:typeof a=="number"?Number.isNaN(a):!a})}})).views(e=>({get reQueryKey(){const{react_to:t=[]}=e;if(t.length===0)return"";const n=b.getRoot(e).content.payloadForSQL,r=[...t].reduce((a,o)=>(a[o]=x.get(n,o),a),{});return JSON.stringify(r)},get runByConditionsMet(){return e.unmetRunByConditions.length===0},get conditionNames(){if(e.unmetRunByConditions.length===0)return{context:[],filters:[]};const{keyLabelMap:t}=b.getRoot(e).content.filters,n=e.unmetRunByConditions.filter(a=>a.startsWith("context.")).map(a=>a.split("context.")[0]),r=e.unmetRunByConditions.filter(a=>a.startsWith("filters.")).map(a=>x.get({filters:t},a)).filter(a=>!!a);return{context:n,filters:r}},get queries(){return b.getParent(e,2)},get inUse(){return this.queries.isQueryInUse(e.id)}}));function CS(e,t){return new Function(`return ${e}`)()(t,At)}function SS(e,t,n){return CS(e,{context:t,filters:n})}function _S(e,t){try{return new Function(`return ${e.config.processing.pre}`)()(t,At)}catch(n){return console.error(n),t}}function kS(e,t){return new Function(`return ${e.config.processing.post}`)()(t,At)}function TS(e,t,n){return e?new Function(`return ${e}`)()(t,At,n):t}const DS=b.types.compose("QueryRenderModel",wS,b.types.model({state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),data:b.types.optional(b.types.frozen([]),[]),error:b.types.frozen()})).views(e=>({get rootModel(){return b.getRoot(e)},get contentModel(){return this.rootModel.content},get payload(){return this.contentModel.payloadForSQL},get dashboardState(){return ns(this.payload)},get formattedSQL(){return xr(e.sql,this.payload)},get typedAsSQL(){return[ve.Postgresql,ve.MySQL].includes(e.type)},get typedAsHTTP(){return[ve.HTTP].includes(e.type)},get datasource(){const{key:t,type:n}=e;return this.rootModel.datasources.find({type:n,key:t})},get httpConfigString(){const{context:t,filters:n}=this.payload,{name:r,pre_process:a}=e.json,o=SS(a,t,n);return console.groupCollapsed(`Request config for: ${r}`),console.log(o),console.groupEnd(),JSON.stringify(o)}})).views(e=>({get stateMessage(){if(e.state!=="idle")return"";if(!e.runByConditionsMet){const{context:t,filters:n}=e.conditionNames;if(t.length===0&&n.length===0)return"Waiting";const r=[];return t.length>0&&r.push(`context: ${t.join(", ")}`),n.length>0&&r.push(`filter${n.length>1?"s":""}: ${n.join(", ")}`),r.length===2&&r.splice(1,0,"and"),r.unshift("Waiting for"),r.join(" ")}return e.data.length>0?"":"Empty Data"}})).volatile(()=>({controller:new AbortController})).actions(e=>({runSQL:b.flow(function*(){var t;if(e.valid&&((t=e.controller)==null||t.abort(),!!e.runByConditionsMet)){e.controller=new AbortController,e.state="loading";try{const n=e.payload;e.data=yield*b.toGenerator(Hu({payload:n,name:e.name,query:e.json},e.controller.signal)),e.state="idle",e.error=null}catch(n){if(!xt.isCancel(n)){e.data=[];const r=x.get(n,"message","unkown error");e.error=x.get(n,"response.data.detail.message",r),e.state="error"}}}}),runHTTP:b.flow(function*(){var t;if(!(!e.valid||!e.datasource)&&((t=e.controller)==null||t.abort(),!!e.runByConditionsMet)){e.controller=new AbortController,e.state="loading";try{const{type:n,key:r,post_process:a}=e.json;let o=JSON.parse(e.httpConfigString);o=_S(e.datasource,o);const l=yield*b.toGenerator(ec({type:n,key:r,configString:JSON.stringify(o),name:e.name},e.controller.signal));let u=kS(e.datasource,l);u=TS(a,u,e.dashboardState),e.data=u,e.state="idle",e.error=null}catch(n){if(console.error(n),!xt.isCancel(n)){e.data=[];const r=x.get(n,"message","unkown error");e.error=x.get(n,"response.data.detail.message",r),e.state="error"}}}})})).actions(e=>({fetchData:t=>{if(!e.inUse&&!t){console.debug(`Skipping query[${e.name}]`);return}return e.typedAsHTTP?e.runHTTP():e.runSQL()},beforeDestroy(){var t;(t=e.controller)==null||t.abort()}})).actions(e=>({afterCreate(){b.addDisposer(e,te.reaction(()=>{var n;return e.typedAsHTTP?`${e.inUse}--${e.id}--${e.key}--${e.reQueryKey}--${(n=e.datasource)==null?void 0:n.id}`:[e.inUse,e.id,e.key,e.formattedSQL,e.pre_process,e.post_process].join("--")},()=>e.fetchData(!1),{fireImmediately:!0,delay:0}))}})),Tl=b.types.model("QueriesRenderModel",{current:b.types.optional(b.types.array(DS),[])}).views(e=>({get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(n=>n.id===t)},findByIDSet(t){return e.current.filter(n=>t.has(n.id))},get json(){return e.current.filter(t=>t.id&&t.key).map(t=>t.json)},get contentModel(){return b.getParent(e,1)},get visibleQueryIDSet(){const{views:t,filters:n}=this.contentModel,r=[];t.visibleViews.forEach(l=>{l.panels.forEach(u=>{r.push(...u.queryIDs)})});const a=x.uniq(t.visibleViews.map(l=>l.renderViewIDs).flat());n.current.forEach(l=>{const u=x.get(l,"config.options_query_id");if(!u)return;a.some(d=>l.visibleInViewsIDSet.has(d))&&r.push(u)});const o=new Set(r);return console.debug("QueryIDs:",o),o},isQueryInUse(t){return this.visibleQueryIDSet.has(t)}})).actions(e=>({downloadAllData(){const t=e.current.map(({name:n,data:r})=>({id:n,data:r}));_l(t)},downloadDataByQueryIDs(t){const n=new Set(t),r=e.current.filter(a=>n.has(a.id)).map(({name:a,data:o})=>({id:a,data:o}));_l(r)},downloadDataByQueryID(t){const n=e.findByID(t);if(!n){console.log("[downloadDataByQueryID] query not found");return}const{name:r,data:a}=n;xS(r,a)},refetchDataByQueryID(t){const n=e.findByID(t);if(!n){console.error(new Error(`[downloadDataByQueryID] query by ID[${t}] not found`));return}return n.fetchData(!0)}}));function IS(e){return{current:e}}const MS=J1.views(e=>({isADuplicatedKey(t){return!t||t===e.key?!1:!!b.getParent(e,2).findByKey(t)}})),Dl=b.types.model("SQLSnippetsRenderModel",{current:b.types.optional(b.types.array(MS),[])}).views(e=>({get json(){return e.current.map(t=>t.json)},get record(){return e.current.reduce((t,n)=>(t[n.key]=n.value,t),{})},get firstKey(){if(e.current.length!==0)return e.current[0].key},findByKey(t){return e.current.find(n=>n.key===t)}}));function AS(e){return{current:e}}function lr(e,t,n,r){return e.reduce((a,o)=>{try{a[o[t]]=vr(o[n],r)}catch(l){a[o[t]]=l.message}return a},{})}class zS{constructor(t){q(this,"origin");q(this,"copy");this.origin=t,this.copy=b.clone(t),te.makeAutoObservable(this,{},{autoBind:!0,deep:!1})}get changed(){return!x.isEqual(b.getSnapshot(this.origin),b.getSnapshot(this.copy))}commit(){b.applySnapshot(this.origin,b.getSnapshot(this.copy))}update(t){b.applySnapshot(this.copy,t)}}const ES=e=>new zS(e),$S=k.observer(({view:e})=>{const t=ue(),n=le(),r=Ge.useModals(),{panel:a,downloadPanelScreenshot:o}=rt(),{id:l}=a,{viewPanelInFullScreen:u,inFullScreen:c}=y.useContext(sr),d=()=>{n.duplicatePanelByID(l,e.id)},f=()=>{t.editor.open(["_VIEWS_",e.id,"_PANELS_",l])},h=()=>r.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>n.removePanelByID(l,e.id),confirmProps:{color:"red"},zIndex:320}),g=y.useCallback(()=>{u(l)},[l,u]),m=!c&&e.type!==j.Modal;return i(B,{children:i(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:p(s.Menu,{withinPortal:!0,children:[i(s.Menu.Target,{children:i(s.Box,{className:"panel-dropdown-target",sx:{width:"100%"}})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{onClick:a.refreshData,icon:i(D.Refresh,{size:14}),children:"Refresh"}),i(s.Menu.Item,{onClick:a.downloadData,icon:i(D.Download,{size:14}),children:"Download Data"}),i(s.Menu.Item,{onClick:o,icon:i(E.IconCamera,{size:14}),children:"Screenshot"}),m&&i(s.Menu.Item,{onClick:g,icon:i(D.ArrowsMaximize,{size:14}),disabled:!0,children:"Full Screen"}),i(s.Divider,{label:"Edit",labelPosition:"center"}),i(s.Menu.Item,{onClick:f,icon:i(D.Settings,{size:14}),children:"Settings"}),i(s.Menu.Item,{onClick:d,icon:i(D.Copy,{size:14}),children:"Duplicate"}),i(s.Menu.Item,{color:"red",onClick:h,icon:i(D.Trash,{size:14}),children:"Delete"})]})]})})})});function LS(e){return e?["<p><br></p>","<p></p>"].includes(e):!0}const $i=k.observer(()=>{const[e,t]=y.useState(!1),{panel:n}=Ct();return LS(n.description)?null:p(B,{children:[i(s.Modal,{opened:e,onClose:()=>t(!1),title:n.title,withCloseButton:!1,withinPortal:!0,zIndex:310,children:i(Rn,{value:n.description,styles:{root:{border:"none"},content:{padding:0}}})}),i(s.Tooltip,{label:"Click to see description",position:"top-start",withinPortal:!0,children:i(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>t(r=>!r),sx:{verticalAlign:"baseline",cursor:"pointer"},children:i(D.InfoCircle,{size:20})})})]})}),mM="",OS=k.observer(function(){const{panel:t}=Ct(),{title:n}=t;return n?i(s.Group,{grow:!0,position:"center",className:"panel-title-wrapper",sx:{flexGrow:1},children:i(s.Text,{align:"center",lineClamp:1,className:"panel-title-text",children:n})}):null});function PS(e){const t=y.useRef(null);return{ref:t,downloadPanelScreenshot:()=>{const r=t.current;if(!r)return;const a=r.offsetWidth*2,o=r.offsetHeight*2;Ja.toBlob(t.current,{bgcolor:"white",width:a,height:o,style:{border:"none",borderRadius:0,transformOrigin:"0 0",transform:"scale(2)"}}).then(l=>{window.saveAs(l,`${e.title?e.title:e.viz.type}.png`)})}}}var Il=(e=>(e.migrated="migrated",e.nothingToMigrate="nothingToMigrate",e.checkFailed="checkFailed",e.migrationFailed="migrationFailed",e))(Il||{}),ur=(e=>(e.notStarted="notStarted",e.inProgress="inProgress",e.done="done",e))(ur||{});class BS{constructor(t){q(this,"vizInstance");q(this,"operationManager");q(this,"triggerManager");q(this,"vizManager");q(this,"runningMigration");q(this,"panelModel");q(this,"status","notStarted");this.panelModel=t.getRequired(be.instanceScope.panelModel),this.vizInstance=t.getRequired(be.instanceScope.vizInstance),this.operationManager=t.getRequired(be.instanceScope.operationManager),this.triggerManager=t.getRequired(be.instanceScope.triggerManager),this.vizManager=t.getRequired(be.vizManager)}async createMigrationTask(){const t=[];try{await this.instanceNeedMigration()&&t.push(()=>this.runInstanceMigration()),await this.interactionNeedMigration()&&t.push(()=>this.runInteractionMigration())}catch(n){return console.warn("check migration failed",n),"checkFailed"}if(t.length===0)return"nothingToMigrate";try{return await Promise.all(t.map(n=>n())),"migrated"}catch(n){return console.warn("migration failed",n),"migrationFailed"}}async runMigration(){return this.runningMigration||(this.status="inProgress",this.runningMigration=this.createMigrationTask().then(t=>(this.status="done",t))),this.runningMigration}async runInteractionMigration(){await this.operationManager.runMigration(),await this.triggerManager.runMigration()}async runInstanceMigration(){const t=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData,panelModel:this.panelModel};await t.migrator.migrate(n)}async instanceNeedMigration(){const t=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData};return t.migrator.needMigration(n)}async interactionNeedMigration(){return await this.operationManager.needMigration()||await this.triggerManager.needMigration()}}function Ml(e){const{panel:t}=Ct();return y.useCallback(n=>{const r=n.getRequired(be.vizManager),a=r.resolveComponent(e.viz.type);return n.createScoped().provideFactory(be.instanceScope.vizInstance,()=>r.getOrCreateInstance(e)).provideFactory(be.instanceScope.interactionManager,o=>{const l=o.getRequired(be.instanceScope.vizInstance);return new Er(l,a,En)}).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 BS(o))},[e.viz.type,e.viz.conf])}function Al(e){const[t,n]=y.useState(!1),r=Xo().getRequired(be.instanceScope.migrator);return Q.useAsyncEffect(async()=>{const a=r.status===ur.notStarted;n(r.status===ur.done),r.status===ur.notStarted&&r.runMigration().then(o=>{o===Il.migrated&&a&&(e==null||e())}).finally(()=>{n(!0)})},[r]),t}function zl(e,t){const n=Xo().getRequired(be.instanceScope.vizInstance);return y.useEffect(()=>(n.instanceData.setItem(null,t.viz.conf),n.instanceData.watchItem(null,r=>{e(r)})),[e,t.viz.type]),n}function VS({setVizConf:e,...t}){const{panel:n}=t,r=zl(e,n),a=Al(()=>{_n.showNotification({title:`${n.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})});return Q.useAsyncEffect(async()=>{await r.instanceData.setItem(null,n.viz.conf)},[r,n.viz.type]),a?i(ic,{...t}):i(s.Text,{children:"Checking update..."})}function NS(e){const{panel:t,setVizConf:n}=e;zl(n,t);const{inEditMode:r}=y.useContext(An);return Al(()=>{r&&_n.showNotification({title:`${t.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?i(rc,{...e}):i(s.Text,{children:"Checking update"})}const yM="";function qS(e,t){const{vizManager:n}=y.useContext(ct),{panel:{viz:r,title:a,id:o,description:l,queryIDs:u,variables:c}}=Ct(),d={title:a,id:o,description:l,queryIDs:u,viz:r,layout:t},f=Ml(d);try{return n.resolveComponent(r.type),i(ar,{configure:f,children:i(NS,{setVizConf:r.setConf,panel:d,data:e,variables:c,vizManager:n})})}catch(h){return console.info(x.get(h,"message")),null}}const El=k.observer(function({data:t}){const{ref:n,width:r,height:a}=ke.useElementSize(),o=qS(t,{w:r,h:a}),l=r>0&&a>0;return i("div",{className:"viz-root",ref:n,children:i(s.Box,{sx:{width:r,height:a,overflow:"hidden"},children:l&&i(Ne,{children:o})})})}),$l=k.observer(({panel:e})=>p(s.Stack,{children:[e.queryErrors.map((t,n)=>i(s.Text,{color:"red",size:"sm",align:"center",sx:{fontFamily:"monospace"},children:t},`${n}-${t}`)),i(s.Text,{color:"gray",align:"center",size:"sm",children:e.queryStateMessages})]})),Li=k.observer(({panel:e})=>p(s.Flex,{className:"panel-viz-section",direction:"column",sx:{position:"relative",width:"100%"},children:[i(s.LoadingOverlay,{visible:e.dataLoading,exitTransitionDuration:0}),!e.canRenderViz&&i($l,{panel:e}),e.canRenderViz&&i(El,{data:e.data})]})),FS={border:"1px solid #e9ecef"},Ll=k.observer(({panel:e,panelStyle:t,dropdownContent:n})=>{const{ref:r,downloadPanelScreenshot:a}=PS(e),o=!!e.title,l=o?"60px":"28px";return e.title&&`${l}`,i(Ir,{value:{panel:e,data:e.data,loading:e.dataLoading,errors:e.queryErrors,downloadPanelScreenshot:a},children:p(s.Box,{className:`panel-root ${o?"panel-root--show-title":""}`,ref:r,p:0,sx:{...FS,...t},children:[i(s.Box,{className:"panel-description-popover-wrapper",children:i($i,{})}),n,i(OS,{}),i(Li,{panel:e})]})})}),GS={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function WS(e){return e.style.border.enabled?{}:GS}const Ol=k.observer(function({panel:t,view:n}){const r=WS(t);return i(Ll,{panel:t,panelStyle:r,dropdownContent:i($S,{view:n})})});function jS(e){return!["richText","button"].includes(e)}const RS=k.observer(({view:e})=>{const{panel:t,downloadPanelScreenshot:n}=Ct(),{id:r}=t,{viewPanelInFullScreen:a,inFullScreen:o}=y.useContext(sr),l=y.useCallback(()=>{a(r)},[r,a]),u=!o&&e.type!==j.Modal;return jS(t.viz.type)?i(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:p(s.Menu,{withinPortal:!0,children:[i(s.Menu.Target,{children:i(s.Box,{className:"panel-dropdown-target"})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{onClick:t.refreshData,icon:i(D.Refresh,{size:14}),children:"Refresh"}),i(s.Menu.Item,{onClick:t.downloadData,icon:i(D.Download,{size:14}),children:"Download Data"}),i(s.Menu.Item,{onClick:n,icon:i(E.IconCamera,{size:14}),children:"Screenshot"}),u&&i(s.Menu.Item,{onClick:l,icon:i(D.ArrowsMaximize,{size:14}),children:"Full Screen"})]})]})}):null});function YS(e){return e.style.border.enabled?{}:{border:"1px dashed transparent"}}const Oi=k.observer(({panel:e,view:t})=>{const n=YS(e);return i(Ll,{panel:e,panelStyle:n,dropdownContent:i(RS,{view:t})})}),QS={modal:{display:"flex",flexDirection:"column",flexWrap:"nowrap"},body:{display:"flex",height:"calc(100vh - 88px)"}},Pl=k.observer(function({view:t,panel:n,exitFullScreen:r}){return i(s.Modal,{opened:!0,fullScreen:!0,onClose:r,title:i(s.Button,{color:"blue",size:"xs",onClick:r,leftIcon:i(D.ArrowLeft,{size:20}),children:"Exit fullscreen"}),styles:QS,children:i(s.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:i(Oi,{view:t,panel:n})})})});function Bl(e,t,n){const{panels:r}=ye(),a=e.id==="Main",[o,l]=y.useState(()=>a&&r.findByID(t)?t:null),u=y.useCallback(h=>{l(h),a&&n(h)},[a,n]),c=y.useCallback(()=>{l(null),a&&n("")},[a,n]),d=o?r.findByID(o):null;return{viewPanelInFullScreen:u,exitFullScreen:c,inFullScreen:!!d,fullScreenPanel:d}}const bM="",US=y.forwardRef(({h:e},t)=>i(s.ActionIcon,{ref:t,className:"react-grid-customDragHandle",sx:{userSelect:"none",cursor:"grab",position:"absolute",top:5,right:e>38?5:20,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",children:i(D.ArrowsMove,{size:16})})),KS=y.forwardRef(({handleAxis:e,...t},n)=>i(s.ActionIcon,{ref:n,className:"react-grid-customResizeHandle",sx:{userSelect:"none",cursor:"nwse-resize",position:"absolute",bottom:0,right:0,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",...t,children:i(D.ChevronDownRight,{size:16})})),XS=kn.WidthProvider(kn),JS=k.observer(({view:e,className:t="layout"})=>{const n=ye(),{panels:r,layouts:a}=n.panels.panelsByIDs(e.panelIDs),o=y.useCallback(u=>{u.forEach(({i:c,...d})=>{const f=n.panels.findByID(c);f&&f.layout.set(d)})},[n]),l=(u,c,d,f)=>{d.h<30&&(d.h=30,f.h=30),d.w<4&&(d.w=4,f.w=4)};return i(XS,{onLayoutChange:o,className:`dashboard-layout ${t}`,rowHeight:1,cols:36,margin:[0,0],isBounded:!0,isDraggable:!0,isResizable:!0,layout:a,draggableHandle:".react-grid-customDragHandle",resizeHandle:i(KS,{}),onResize:l,children:r.map((u,c)=>p("div",{"data-grid":{...u.layout},className:"panel-grid-item",children:[i(US,{h:u.layout.h}),i(Ol,{view:e,panel:u})]},u.id))})}),ZS=kn.WidthProvider(kn),HS=k.observer(function({view:t,className:n="layout"}){const{panels:r,layouts:a}=ye().panels.panelsByIDs(t.panelIDs);return i(ZS,{className:`dashboard-layout ${n}`,cols:36,rowHeight:1,margin:[0,0],isDraggable:!1,isResizable:!1,layout:a,children:r.map(o=>i("div",{"data-grid":{...o.layout},className:"panel-grid-item",children:i(Oi,{view:t,panel:o})},o.id))})});function Pi(e){const t=y.useRef(null);return{ref:t,downloadScreenshot:()=>{var l;const r=(l=t.current)==null?void 0:l.querySelector(".react-grid-layout");if(!r)return;const a=r.offsetWidth*2+10,o=r.offsetHeight*2+10;Ja.toBlob(r,{bgcolor:"white",width:a,height:o,style:{transformOrigin:"0 0",transform:"scale(2)"}}).then(u=>{window.saveAs(u,`${e.name}.png`)})}}}const e_=k.observer(({downloadScreenShot:e})=>{const[t,{setTrue:n,setFalse:r}]=Q.useBoolean(!1),a=Tr(),o=ye(),l=()=>{const u=JSON.stringify(o.json,null,2),c=`${a.name}__${o.name}`;kl(c,u)};return p(s.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:200,closeDelay:400,withinPortal:!0,position:"bottom-end",children:[i(s.Menu.Target,{children:i(s.Affix,{position:{bottom:"20px",right:"10px"},zIndex:1,children:i(s.ActionIcon,{size:"md",variant:"gradient",gradient:{from:"indigo",to:"cyan"},onMouseEnter:n,onMouseLeave:r,sx:{opacity:t?1:.6,transform:`translateX(${t?0:"2px"})`,transition:"all ease 300ms",borderRadius:"50%"},children:i(E.IconShare3,{size:"1rem"})})})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{icon:i(E.IconCamera,{size:14}),onClick:e,children:"Screenshot"}),i(s.Menu.Divider,{}),i(s.Menu.Item,{icon:i(E.IconDownload,{size:14}),onClick:o.queries.downloadAllData,children:"Download Data"}),i(s.Menu.Item,{icon:i(E.IconCode,{size:14}),onClick:l,children:"Download Schema"})]})]})}),Vl=k.observer(({children:e,view:t,sx:n={}})=>{const{ref:r,downloadScreenshot:a}=Pi(t);return p(B,{children:[i(s.Box,{ref:r,sx:n,children:e}),i(e_,{downloadScreenShot:a})]})}),Nl=k.observer(({downloadScreenshot:e})=>i(s.ActionIcon,{className:"download-screenshot-button",color:"blue",onClick:e,children:i(E.IconCamera,{size:14})})),t_=k.observer(({children:e,view:t})=>{const n=ye(),r=t.config,a=n.views.visibleViewIDs.includes(t.id),o=()=>n.views.rmVisibleViewID(t.id),{ref:l,downloadScreenshot:u}=Pi(t);return i(s.Modal,{size:r.width,centered:!0,opened:a,onClose:o,withCloseButton:!1,title:p(s.Group,{position:"apart",px:"1rem",h:"48px",children:[i(s.Box,{children:r.custom_modal_title.value}),i(Nl,{downloadScreenshot:u})]}),trapFocus:!0,onDragStart:c=>{c.stopPropagation()},styles:{root:{position:"fixed",zIndex:200,inset:0},overlay:{zIndex:"unset"},inner:{zIndex:"unset",padding:"0 !important"},content:{border:"1px solid #efefef",maxHeight:"unset !important",overflow:"hidden"},body:{maxHeight:r.height,overflow:"auto",position:"relative"},header:{padding:0},title:{flexGrow:1}},transitionProps:{duration:0},children:i(s.Box,{ref:l,children:e})})}),n_=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},r_=k.observer(({view:e})=>{const t=ye(),n=e.config;return p(s.Tabs,{className:"render-view-tabs",variant:n.variant,orientation:n.orientation,value:e.tab,onTabChange:e.setTab,styles:{root:{height:"100%",overflow:n.orientation==="horizontal"?"hidden":"auto"},panel:{padding:n.orientation==="horizontal"?"8px 0px 8px":"0",height:"100%",overflow:"auto"}},keepMounted:!1,children:[i(s.Tabs.List,{grow:n.grow,children:n.tabs.map(r=>i(s.Tabs.Tab,{value:r.id,sx:n_(r),disabled:!r.view_id,children:r.name??r.id},r.id))}),n.tabs.map(r=>{const a=t.views.findByID(r.view_id);return a?i(s.Tabs.Panel,{value:r.id,children:i(cr,{view:a})},r.id):null})]})}),i_=k.observer(({view:e,children:t})=>{switch(e.type){case j.Modal:return i(t_,{view:e,children:t});case j.Tabs:return i(r_,{view:e});case j.Division:default:return i(Vl,{view:e,children:t})}}),a_=k.observer(({children:e,view:t})=>i(Vl,{sx:{paddingTop:"10px",paddingBottom:"100px"},view:t,children:e}));function ql(e){return e.replace(/(vw|vh)/,"%")}const s_=k.observer(({children:e,view:t})=>{const n=t.config,{width:r,height:a}=y.useMemo(()=>({width:ql(n.width),height:ql(n.height)}),[n.width,n.height]),{ref:o,downloadScreenshot:l}=Pi(t);return i(s.Box,{sx:{height:"100%","> div:not(.mantine-Modal-root)":{height:"100%"}},children:i(s.Modal,{size:n.width,opened:!0,onClose:x.noop,withCloseButton:!1,title:p(s.Group,{position:"apart",px:"1rem",h:"48px",children:[i(s.Box,{children:n.custom_modal_title.value}),i(Nl,{downloadScreenshot:l})]}),trapFocus:!0,onDragStart:u=>{u.stopPropagation()},styles:{root:{position:"relative",height:"100%"},overlay:{position:"absolute !important"},inner:{position:"relative",top:"50%",left:"50%",right:"unset",bottom:"unset",transform:"translate(-50%, -50%)",padding:"0 !important",width:r,height:a,maxHeight:a},content:{border:"1px solid #efefef",height:"100%"},body:{maxHeight:"calc(100% - 48px)",overflow:"auto"},header:{padding:0},title:{flexGrow:1}},withinPortal:!1,transitionProps:{duration:0},children:i(s.Box,{ref:o,children:e})})})}),o_=({variant:e,orientation:t})=>{const n={root:{height:"100%",overflow:"hidden"},tab:{},panel:{padding:"16px"}};return e==="pills"&&t==="horizontal"&&(n.tab.paddingTop="6px",n.tab.paddingBottom="6px"),t==="vertical"&&(n.tab["&.add-a-tab"]={paddingTop:"1px",paddingBottom:"1px"},n.tab["&.add-a-tab .mantine-Tabs-tabLabel"]={marginLeft:"auto",marginRight:"auto"}),n},l_=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},u_=k.observer(({view:e})=>{const t=Ge.useModals(),n=le(),r=y.useMemo(()=>n.views.options.filter(u=>u.type===j.Division),[e.id,n.views.options]),a=e.config,o=u=>t.openConfirmModal({title:"Delete this tab?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{a.removeTab(u)},confirmProps:{color:"red"},zIndex:320}),l=a.tabs.length===0;return p(s.Tabs,{className:"preview-view-tabs",variant:a.variant,orientation:a.orientation,value:e.tab,onTabChange:e.setTab,styles:o_(a),children:[p(s.Tabs.List,{grow:a.grow,children:[a.tabs.map(u=>i(s.Tabs.Tab,{value:u.id,sx:l_(u),children:u.name??u.id},u.id)),i(s.Tabs.Tab,{onClick:a.addTab,value:"add",className:"add-a-tab",children:i(D.Plus,{size:18,color:"#228be6"})})]}),a.tabs.map((u,c)=>{const d=n.views.findByID(u.view_id);return p(s.Tabs.Panel,{value:u.id,sx:{position:"relative"},children:[p(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:200},children:[i(s.Overlay,{opacity:.8,color:"#FFF",blur:10,zIndex:100}),p(s.Stack,{mx:"auto",mt:100,sx:{width:"300px",position:"relative",zIndex:200},children:[i(s.TextInput,{label:"Tab Name",value:u.name,onChange:f=>u.setName(f.currentTarget.value)}),i(s.Select,{label:"View",value:u.view_id,onChange:u.setViewID,data:r}),i(s.ColorInput,{label:"Color",value:u.color,onChange:u.setColor,disabled:a.variant!=="default"}),d&&p(s.Button,{mt:20,variant:"gradient",leftIcon:i(E.IconArrowsLeftRight,{size:18}),gradient:{from:"cyan",to:"indigo"},onClick:()=>n.views.setIDOfVIE(d.id),children:["Swith to View: ",d.name]}),i(s.Button,{mt:20,variant:"subtle",color:"red",onClick:()=>o(c),disabled:l,leftIcon:i(E.IconTrash,{size:14}),children:"Delete This Tab"})]})]}),d&&i(cr,{view:d})]},u.id)})]})}),c_=k.observer(({view:e,children:t})=>{switch(e.type){case j.Modal:return i(s_,{view:e,children:t});case j.Tabs:return i(u_,{view:e});case j.Division:default:return i(a_,{view:e,children:t})}}),Fl=k.observer(function({view:t}){return i(sr.Provider,{value:{viewPanelInFullScreen:x.noop,inFullScreen:!1},children:i(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:i(c_,{view:t,children:p(s.Box,{sx:{position:"relative"},children:[i(s.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:i(Ho,{view:t})}),i(JS,{view:t})]})})})})}),cr=k.observer(function({view:t}){const{fullScreenPanelID:n,setFullScreenPanelID:r}=hs(),{viewPanelInFullScreen:a,exitFullScreen:o,inFullScreen:l,fullScreenPanel:u}=Bl(t,n,r);return i(sr.Provider,{value:{viewPanelInFullScreen:a,inFullScreen:l},children:p(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,sx:{height:t.type===j.Modal?"0 !important":"100%"},children:[l&&i(Pl,{view:t,panel:u,exitFullScreen:o}),i(i_,{view:t,children:p(s.Box,{sx:{position:"relative"},children:[!l&&i(s.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:i(Ho,{view:t})}),!l&&i(HS,{view:t})]})})]})})});var Gl=(e=>(e.Use="use",e.Edit="edit",e))(Gl||{});const d_={[j.Division]:"Division",[j.Tabs]:"Tabs",[j.Modal]:"Modal"},Wl={[j.Division]:"rgba(255, 0, 0, 0.2)",[j.Modal]:"rgba(0, 0, 0, 0.2)",[j.Tabs]:"rgba(255, 200, 100, 0.4)"},p_={[j.Division]:"#ff4000",[j.Modal]:"#000",[j.Tabs]:"#ffad18"},h_={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:j.Division,config:{},panelIDs:[]}],panels:[],filters:[],version:"9.19.0"};function f_(e,t,n){b.addDisposer(e,b.addMiddleware(e,(r,a)=>{a(r,()=>{b.getType(r.context)===t&&r.type==="action"&&n(r.name,r.context)})}))}const jl=b.types.compose("FiltersModel",wl,b.types.model("FiltersModel",{previewValues:b.types.optional(b.types.frozen(),{})})).views(e=>({get options(){return e.current.map(t=>({label:t.label??t.id,value:t.id,_type:"filter"}))},get selects(){return e.current.filter(t=>t.type===xe.Select).map(t=>({label:t.label??t.id,value:t.id}))},get keyLabelOptions(){return e.current.map(t=>({label:t.label??t.key,value:t.key}))}})).actions(e=>({replace(t){e.current=b.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByID(t){const n=e.current.findIndex(r=>r.id===t);n>=0&&e.current.splice(n,1)},updatePreviewValues(t){e.previewValues=t}})).actions(e=>{function t(){f_(e.current,cl,(n,r)=>{if(n==="setType"){const a=xl(r.config.default_value,r.config);e.setValueByKey(r.key,a),e.updatePreviewValues({...e.previewValues,[r.key]:a})}})}return{afterCreate(){t()}}}),Rl=Tl.views(e=>({get options(){const t=e.current.map(n=>({value:n.id,label:n.name,_type:"query"}));return x.sortBy(t,n=>n.label.toLowerCase())},get sortedList(){return x.sortBy(e.current,t=>t.name.toLowerCase())}})).actions(e=>({replace(t){e.current=b.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},replaceByIndex(t,n){e.current.splice(t,1,n)},removeQuery(t){const n=e.current.find(r=>r.id===t);n&&(b.detach(n),e.current.remove(n))},removeQueries(t){const n=new Set(t);e.current.forEach(a=>{n.has(a.id)&&b.detach(a)});const r=[...e.current];x.remove(r,a=>n.has(a.id)),e.current=b.cast(r)}})),Yl=Dl.views(e=>({get sortedList(){return x.sortBy(e.current,t=>t.key.toLowerCase())},get options(){const t=e.current.map(n=>({label:n.key,value:n.key,_type:"sql_snippet"}));return x.sortBy(t,n=>n.label.toLowerCase())}})).actions(e=>({replace(t){e.current=b.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByKey(t){const n=e.current.findIndex(r=>r.key===t);n>=0&&e.current.splice(n,1)},removeByKeys(t){const n=new Set(t);e.current.forEach(a=>{n.has(a.key)&&b.detach(a)});const r=[...e.current];x.remove(r,a=>n.has(a.key)),e.current=b.cast(r)},replaceByIndex(t,n){e.current.splice(t,1,n)}})),g_=b.types.model({data:b.types.optional(b.types.frozen(),[]),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0},get sql(){const t=b.getParent(e,1),{type:n,table_name:r,table_schema:a}=t;if(n===ve.MySQL)return`
|
|
441
441
|
SELECT ordinal_position, column_key, column_name, column_type, is_nullable, column_default, column_comment
|
|
442
442
|
FROM information_schema.columns
|
|
443
443
|
WHERE table_name = '${r}' AND table_schema = '${a}'
|
|
@@ -458,7 +458,7 @@ Check the top-level render call using <`+V+">.")}return z}}function Tu(S,z){{if(
|
|
|
458
458
|
LEFT JOIN pg_constraint pc ON pc.conrelid = ${o} AND ordinal_position = any(pc.conkey)
|
|
459
459
|
WHERE
|
|
460
460
|
table_name = '${r}' AND table_schema = '${a}';
|
|
461
|
-
`}return""}})),
|
|
461
|
+
`}return""}})),m_=b.types.model({data:b.types.optional(b.types.frozen(),[]),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0},get sql(){const t=b.getParent(e,1),{type:n,table_name:r,table_schema:a}=t;return n===ve.MySQL?`
|
|
462
462
|
SELECT
|
|
463
463
|
sub_part AS index_length,
|
|
464
464
|
index_name AS index_name,
|
|
@@ -493,21 +493,21 @@ Check the top-level render call using <`+V+">.")}return z}}function Tu(S,z){{if(
|
|
|
493
493
|
JOIN pg_am AS am ON ix.relam = am.oid
|
|
494
494
|
WHERE
|
|
495
495
|
t.relname = '${r}' AND n.nspname = '${a}';
|
|
496
|
-
`:""}})),
|
|
496
|
+
`:""}})),y_=b.types.model({page:b.types.optional(b.types.number,1),limit:b.types.optional(b.types.number,20),data:b.types.optional(b.types.frozen(),[]),total:b.types.optional(b.types.number,0),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(e=>({get keywords(){return b.getParent(e,1)},get keywordString(){const{table_name:t,table_schema:n}=b.getParent(e,1);return`${n}||${t}`}})).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0},get maxPage(){return Math.ceil(e.total/e.limit)},get sql(){const t=b.getParent(e,1),{table_name:n,table_schema:r}=t;return`
|
|
497
497
|
SELECT *
|
|
498
498
|
FROM ${r}.${n}
|
|
499
499
|
LIMIT ${e.limit} OFFSET ${(e.page-1)*e.limit}
|
|
500
500
|
`},get countSql(){const{table_name:t,table_schema:n}=e.keywords;return`
|
|
501
501
|
SELECT count(*) AS total
|
|
502
502
|
FROM ${n}.${t}
|
|
503
|
-
`}})).actions(e=>({setPage(t){e.page=t},resetPage(){e.page=1},setLimit(t){e.limit=t}})).actions(e=>({afterCreate(){b.addDisposer(e,te.reaction(()=>e.keywordString,e.resetPage,{fireImmediately:!1,delay:0})),b.addDisposer(e,te.reaction(()=>e.limit,e.resetPage,{fireImmediately:!1,delay:0}))}})),m_=b.types.model({data:b.types.optional(b.types.frozen(),{}),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return Object.keys(e.data).length===0},get sql(){const t=b.getParent(e,1).type;return t===ve.MySQL||t===ve.Postgresql?"SELECT table_schema, table_name, table_type FROM information_schema.tables ORDER BY table_schema, table_name":""}})),y_=b.types.compose("DataSourceModel",pl,b.types.model({tables:b.types.optional(m_,{}),columns:b.types.optional(h_,{}),tableData:b.types.optional(g_,{}),indexes:b.types.optional(f_,{}),table_schema:b.types.optional(b.types.string,""),table_name:b.types.optional(b.types.string,"")})).volatile(()=>({controllers:{tables:new AbortController,columns:new AbortController,indexes:new AbortController,tableData:new AbortController}})).actions(e=>({setKeywords(t,n){e.table_schema=t,e.table_name=n}})).actions(e=>({initKeywords(){if(e.tables.empty)return;const t=Object.keys(e.tables.data)[0],n=e.tables.data[t][0].table_name;e.setKeywords(t,n)}})).actions(e=>{const t=b.flow(function*(){var n;(n=e.controllers.tables)==null||n.abort(),e.controllers.tables=new AbortController,e.tables.state="loading";try{const r=yield*b.toGenerator(Pe.query(e.controllers.tables.signal)({type:e.type,key:e.key,query:e.tables.sql},{}));e.tables.data=x.groupBy(r,"table_schema"),e.tables.state="idle",e.tables.error=null,e.initKeywords()}catch(r){if(!xt.isCancel(r)){e.tables.data={};const a=x.get(r,"message","unkown error");e.tables.error=x.get(r,"response.data.detail.message",a),e.tables.state="error"}}});return{loadTables:t,loadTablesIfEmpty(){e.tables.empty&&t()},loadColumns:b.flow(function*(){var n;(n=e.controllers.columns)==null||n.abort(),e.controllers.columns=new AbortController,e.columns.state="loading";try{e.columns.data=yield*b.toGenerator(Pe.query(e.controllers.columns.signal)({type:e.type,key:e.key,query:e.columns.sql},{})),e.columns.state="idle",e.columns.error=null}catch(r){if(xt.isCancel(r))e.columns.state="idle",e.columns.error=null;else{e.columns.data=[];const a=x.get(r,"message","unkown error");e.columns.error=x.get(r,"response.data.detail.message",a),e.columns.state="error"}}}),loadIndexes:b.flow(function*(){var n;(n=e.controllers.indexes)==null||n.abort(),e.controllers.indexes=new AbortController,e.indexes.state="loading";try{e.indexes.data=yield*b.toGenerator(Pe.query(e.controllers.indexes.signal)({type:e.type,key:e.key,query:e.indexes.sql},{})),e.indexes.state="idle",e.indexes.error=null}catch(r){if(xt.isCancel(r))e.indexes.state="idle",e.indexes.error=null;else{e.indexes.data=[];const a=x.get(r,"message","unkown error");e.indexes.error=x.get(r,"response.data.detail.message",a),e.indexes.state="error"}}}),loadTableData:b.flow(function*(){var r;(r=e.controllers.tableData)==null||r.abort(),e.controllers.tableData=new AbortController;const n=e.tableData;n.state="loading";try{n.data=yield*b.toGenerator(Pe.query(e.controllers.tableData.signal)({type:e.type,key:e.key,query:n.sql},{}));const[{total:a}]=yield*b.toGenerator(Pe.query(e.controllers.tableData.signal)({type:e.type,key:e.key,query:n.countSql},{}));n.total=Number(a),n.state="idle",n.error=null}catch(a){if(xt.isCancel(a))n.state="idle",n.error=null;else{n.data=[];const o=x.get(a,"message","unkown error");n.error=x.get(a,"response.data.detail.message",o),n.state="error"}}})}}).actions(e=>({afterCreate(){b.addDisposer(e,te.reaction(()=>e.columns.sql,e.loadColumns,{fireImmediately:!1,delay:500}))}})).actions(e=>({afterCreate(){b.addDisposer(e,te.reaction(()=>e.indexes.sql,e.loadIndexes,{fireImmediately:!1,delay:500})),b.addDisposer(e,te.reaction(()=>e.tableData.sql,e.loadTableData,{fireImmediately:!1,delay:0}))}})),b_=b.types.model("DataSourcesModel",{list:b.types.optional(b.types.array(y_),[])}).views(e=>({find({type:t,key:n}){return e.list.find(r=>r.key===n&&r.type===t)},get options(){return e.list.map(t=>({value:t.key,label:t.key}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}}));function Ut(e){return{label:e,value:e,_type:"ACTION",_action_type:e,Icon:null,children:null}}function v_(e){switch(e._type){case"GROUP":case"ACTION":return null;case"query_variables":return["_QUERY_VARS_"];case"mock_context":return["_MOCK_CONTEXT_"];case"filter":return["_FILTERS_",e.value];case"sql_snippet":return["_SQL_SNIPPETS_",e.value];case"query":return["_QUERIES_",e.value];case"view":return["_VIEWS_",e.value];case"panel":return e.parentID?["_VIEWS_",e.parentID,"_PANELS_",e.value]:(console.error("[getPathFromOption] parentID is required"),null)}}const x_=b.types.model("EditorModel",{path:b.types.optional(b.types.frozen(),[]),settings_open:b.types.optional(b.types.boolean,!1)}).views(e=>({get navOptions(){const{content:t}=b.getRoot(e),{filters:n,views:r,sqlSnippets:a,queries:o}=t;return[{label:"Query Variables",value:"_QUERY_VARS_",_type:"query_variables",Icon:E.IconVariable},{label:"Mock Context",value:"_MOCK_CONTEXT_",Icon:E.IconCodeDots,_type:"mock_context"},{label:"Filters",value:"_FILTERS_",Icon:E.IconFilter,children:[...n.options,Ut("_Add_A_Filter_")],_type:"GROUP"},{label:"SQL Snippets",value:"_SQL_SNIPPETS_",Icon:E.IconCopy,children:[Ut("_SQL_SNIPPETS_SETTINGS_"),...a.options,Ut("_Add_A_SQL_SNIPPET_")],_type:"GROUP"},{label:"Queries",value:"_QUERIES_",Icon:E.IconDatabase,children:[Ut("_QUERIES_SETTINGS_"),...o.options,Ut("_Add_A_QUERY_")],_type:"GROUP"},{label:"Views",value:"_VIEWS_",Icon:E.IconBoxMultiple,children:[...r.editorOptions,Ut("_Add_A_VIEW_")],_type:"GROUP"}]},isOptionActive(t,n){return t.length===0?!1:t[t.length-1]===n.value},isOptionOpened(t){const{path:n}=e;return n.length===0||!t.children||t.children.length===0?!1:n.includes(t.value)}})).actions(e=>({setPath(t){e.path=t},setSettingsOpen(t){e.settings_open=t}})).actions(e=>({open(t){e.setPath(t),e.setSettingsOpen(!0)},close(){e.setSettingsOpen(!1)},navigate(t){const n=v_(t);n&&e.setPath(n)}})),Rl=ml.views(e=>({get dataFieldOptions(){return e.queryIDs.length===0?[]:e.queries.map(t=>{const n=t.data;return n.length===0?[]:Object.keys(n[0]).map(a=>({label:a,value:`${t.id}.${a}`,group:t.name}))}).flat()}})).actions(e=>({removeSelf(){b.getParent(e,2).removeByID(e.id)}})).actions(e=>({moveToView(t,n){b.getRoot(e).content.views.findByID(t).removePanelID(e.id),b.getRoot(e).content.views.findByID(n).appendPanelID(e.id),b.getRoot(e).editor.setPath(["_VIEWS_",n,"_PANELS_",e.id])}})),Yl=b.types.compose("PanelsModel",yl,b.types.model({list:b.types.optional(b.types.array(Rl),[])})).views(e=>({editorOptions(t,n){const{panels:r}=e.panelsByIDs(n);r.length!==n.length&&console.warn(`Unfulfilled panels for View[${t}]`);const a=r.map(l=>({label:l.title?l.title:x.capitalize(l.viz.type),value:l.id,_type:"panel",parentID:t})),o="_Add_A_PANEL_";return a.push({label:o,value:o,_type:"ACTION",_action_type:o,parentID:t,Icon:null,children:null}),a}})).actions(e=>({replace(t){e.list=b.castToSnapshot(t)},append(t){e.list.push(t)},remove(t){e.list.splice(t,1)},removeByID(t){const n=e.list.findIndex(r=>r.id===t);n!==-1&&e.list.splice(n,1)},removeByIDs(t){t.forEach(n=>{this.removeByID(n)})},duplicateByID(t){const n=e.list.find(a=>a.id===t);if(!n){console.error(new Error(`[duplicate panel] Can't find a panel by id[${t}]`));return}const r=new Date().getTime().toString();return e.list.push({...n.json,id:r,layout:{...n.layout,y:1/0,moved:!1}}),r},replaceByIndex(t,n){e.list.splice(t,1,n)}})),Ql=b.types.compose("ViewsModel",gl,b.types.model({idOfVIE:b.types.string})).views(e=>({get isVIETheFirstView(){return e.current.length===0||!e.idOfVIE?!1:e.current[0].id===e.idOfVIE},get VIE(){return e.current.find(({id:t})=>t===e.idOfVIE)},get options(){return e.current.map(t=>({label:t.name,value:t.id,type:t.type}))},get editorOptions(){const t=b.getRoot(e).content.panels;return e.current.map(n=>({label:n.name,value:n.id,_type:"view",children:t.editorOptions(n.id,n.panelIDs)}))}})).actions(e=>({setIDOfVIE(t){e.idOfVIE=t,e.visibleViewIDs.length=0,e.visibleViewIDs.push(t)},replace(t){e.current.replace(t)},addANewView(t,n,r,a){e.current.push({id:t,name:n,type:r,config:a,panelIDs:[]})},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByID(t){const n=e.current.findIndex(o=>o.id===t);if(n===-1)return;const r=e.current[n];b.getRoot(e).content.panels.removeByIDs(r.panelIDs),e.current.splice(n,1)},replaceByIndex(t,n){e.current.splice(t,1,n)},addARandomNewView(){const t=new Date().getTime().toString();this.addANewView(t,j.Division,j.Division,{_name:j.Division}),this.setIDOfVIE(t)},removeVIE(){e.current.length!==1&&(this.removeByID(e.idOfVIE),this.setIDOfVIE(e.current[0].id))}}));function Bi(e){const t=e.length>0?[e[0].id]:[],n=e.length>0?e[0].id:"";return{current:e.map(a=>{const{_name:o=a.type}=a.config;return{...a,config:{...a.config,_name:o},panelIDs:a.panelIDs}}),visibleViewIDs:t,idOfVIE:n}}const w_=b.types.model({id:b.types.string,name:b.types.string,dashboard_id:b.types.string,create_time:b.types.string,update_time:b.types.string,version:b.types.string,filters:Gl,queries:Wl,sqlSnippets:jl,views:Ql,panels:Yl,mock_context:Zo,origin:b.types.maybe(b.types.frozen())}).views(e=>({get json(){return{id:e.id,name:e.name,create_time:e.create_time,update_time:e.update_time,dashboard_id:e.dashboard_id,content:{views:e.views.json,panels:e.panels.json,filters:e.filters.json,version:e.version,definition:{queries:e.queries.json,sqlSnippets:e.sqlSnippets.json,mock_context:e.mock_context.current}}}},get filtersChanged(){const t="filters.current";return!x.isEqual(b.getSnapshot(x.get(e,t)),x.get(e.origin,t))},get queriesChanged(){const t="queries.current",n=b.getSnapshot(x.get(e,t)).map(r=>x.pick(r,["id","name","key","type","sql","run_by","react_to","pre_process","post_process"]));return!x.isEqual(n,x.get(e.origin,t))},get sqlSnippetsChanged(){const t="sqlSnippets.current";return!x.isEqual(b.getSnapshot(x.get(e,t)),x.get(e.origin,t))},get viewsChanged(){const t="views.current";return!x.isEqual(e.views.json,x.get(e.origin,t))},get panelsChanged(){const t="panels.list";return!x.isEqual(b.getSnapshot(x.get(e,t)),x.get(e.origin,t))},get mockContextChanged(){const t="mock_context.current";return!x.isEqual(x.get(e,t),x.get(e.origin,t))},get payloadForSQL(){const t=b.getParent(e).context.current,n=b.getParent(e).globalSQLSnippets,r={context:{...e.mock_context.current,...t},filters:e.filters.values};return{...r,sql_snippets:lr(e.sqlSnippets.current,"key","value",r),global_sql_snippets:lr(n.list,"id","content",r)}},get payloadForViz(){const t=b.getParent(e).context.current;return{context:{...e.mock_context.current,...t},filters:e.filters.values}},get changed(){return this.filtersChanged||this.queriesChanged||this.sqlSnippetsChanged||this.viewsChanged||this.panelsChanged||this.mockContextChanged},get data(){return e.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(t){const n=e.queries.findByID(t);return n?{data:n.data,len:n.data.length,state:n.state,error:n.error}:{data:[],len:0,state:"idle",error:void 0}}})).views(e=>({get queriesUsage(){const t=e.panels.idMap,n=[];e.views.current.forEach(a=>{a.panelIDs.forEach(o=>{const l=t.get(o);if(!l)return;const u="panel",c=l.title?l.title:l.viz.type,d=[{id:a.id,label:a.name}];l.queryIDs.forEach(f=>{n.push({id:o,queryID:f,type:u,label:c,views:d})})})});const r=e.views.idMap;return e.filters.current.filter(a=>!!x.get(a,"config.options_query_id")).map(a=>({type:"filter",id:a.id,queryID:x.get(a,"config.options_query_id"),label:a.label,views:a.visibleInViewsIDs.map(o=>{var l;return{id:o,label:((l=r.get(o))==null?void 0:l.name)??o}})})),x.groupBy(n,"queryID")},get hasUnusedQueries(){return e.queries.current.length>Object.keys(this.queriesUsage).length},findQueryUsage(t){return this.queriesUsage[t]??[]},get sqlSnippetsUsage(){const t=[],n=new RegExp("(?<=sql_snippets\\.)([^}.]+)","gm");return e.queries.current.forEach(r=>{if(!r.typedAsSQL)return;x.uniq(r.sql.match(n)).forEach(o=>{t.push({queryID:r.id,sqlSnippetKey:o,queryName:r.name})})}),x.groupBy(t,"sqlSnippetKey")},get hasUnusedSQLSnippets(){return e.sqlSnippets.current.length>Object.keys(this.sqlSnippetsUsage).length},findSQLSnippetUsage(t){return this.sqlSnippetsUsage[t]??[]}})).actions(e=>({removeUnusedQueries(){const t=new Set(Object.keys(e.queriesUsage)),n=e.queries.current.filter(r=>!t.has(r.id)).map(r=>r.id);e.queries.removeQueries(n)},removeUnusedSQLSnippets(){const t=new Set(Object.keys(e.sqlSnippetsUsage)),n=e.sqlSnippets.current.filter(r=>!t.has(r.key)).map(r=>r.key);e.sqlSnippets.removeByKeys(n)},duplicatePanelByID(t,n){var a;const r=e.panels.duplicateByID(t);r&&((a=e.views.findByID(n))==null||a.appendPanelID(r))},removePanelByID(t,n){var r;e.panels.removeByID(t),(r=e.views.findByID(n))==null||r.removePanelID(t)},addANewPanel(t){var r;const n=new Date().getTime().toString();e.panels.append(gS(n)),(r=e.views.findByID(t))==null||r.appendPanelID(n)}})).actions(e=>({reset(){b.applySnapshot(e.filters.current,e.origin.filters.current),b.applySnapshot(e.queries.current,e.origin.queries.current),b.applySnapshot(e.sqlSnippets.current,e.origin.sqlSnippets.current),b.applySnapshot(e.views.current,e.origin.views.current),b.applySnapshot(e.panels.list,e.origin.panels.list),e.mock_context.current=e.origin.mock_context.current},resetFilters(){b.applySnapshot(e.filters.current,e.origin.filters.current)},updateCurrent(t){const{id:n,name:r,content:a}=t;if(!a)throw new Error("unexpected null content when updating a content model");const{version:o,filters:l,views:u,panels:c,definition:{queries:d,sqlSnippets:f,mock_context:h={}}}=a;e.id=n,e.name=r,e.version=o,b.applySnapshot(e.filters.current,l),b.applySnapshot(e.views.current,Bi(u).current),b.applySnapshot(e.panels.list,c),b.applySnapshot(e.queries.current,d),b.applySnapshot(e.sqlSnippets.current,f),e.mock_context.current=h}})),Vi=b.types.snapshotProcessor(w_,{preProcessor(e){return{...e,origin:e}},postProcessor(e){delete e.origin;const t=b.castToSnapshot(e.queries.current.map(n=>x.pick(n,["id","key","type","sql"])));return x.defaults({},{queries:{current:t}},e)}});function C_(e,t){t.filters&&b.applySnapshot(e.filters.current,t.filters)}function Ul({id:e,name:t,dashboard_id:n,create_time:r,update_time:a,content:o}){if(!o)throw new Error("unexpected null content when creating a content model");const{version:l,filters:u,views:c,panels:d,definition:{queries:f,sqlSnippets:h,mock_context:g={}}}=o;return Vi.create({id:e,name:t,dashboard_id:n,create_time:r,update_time:a,version:l,filters:xl(u),queries:{current:f},sqlSnippets:{current:h},mock_context:Ho(g),views:Bi(c),panels:{list:d}})}const Kl=b.types.model({id:b.types.identifier,name:b.types.string,group:b.types.string,content:Vi,content_id:b.types.string,datasources:b_,globalSQLSnippets:hl,context:Ei,editor:x_}).views(e=>({get json(){return{id:e.id,name:e.name,group:e.group,content_id:e.content_id}}})).actions(e=>({updateCurrentContent(t){e.content.updateCurrent(t)},updateCurrent(t,n){const{id:r,name:a,group:o,content_id:l}=t;e.id=r,e.name=a,e.group=o,e.content_id=l,this.updateCurrentContent(n)}}));function Xl({id:e,name:t,group:n,content_id:r},a,o,l,u){return Kl.create({id:e,name:t,group:n,content_id:r,content:Ul(a),datasources:{list:o},globalSQLSnippets:{list:l},context:fl(u),editor:{}})}function Jl(e,t){y.useEffect(()=>{const n=r=>{console.log(r);const{viewID:a}=r.detail;if(!a){console.error(new Error("[Open View] Needs to pick a view first"));return}e.views.appendToVisibles(a),t&&e.views.setIDOfVIE(a)};return window.addEventListener("open-view",n),()=>{window.removeEventListener("open-view",n)}},[e,t]),y.useEffect(()=>{const n=r=>{console.log(r);const{dictionary:a,payload:o}=r.detail;if(!o||Object.keys(o).length===0){console.error(new Error("[Set Filter Values] payload is empty"));return}Object.entries(a).forEach(([l,u])=>{e.filters.setValueByKey(l,x.get(o,u))})};return window.addEventListener("set-filter-values",n),()=>{window.removeEventListener("set-filter-values",n)}},[e]),y.useEffect(()=>{function n(a){return Array.isArray(a)?[]:typeof a=="object"?{}:typeof a=="boolean"?!1:typeof a=="string"?"":typeof a=="number"?0:a}const r=a=>{console.log(a);const{filter_keys:o}=a.detail;o.forEach(l=>{const u=x.get(e.filters.values,l),c=n(u);console.log(`${l}: ${c}`),e.filters.setValueByKey(l,c)})};return window.addEventListener("clear-filter-values",r),()=>{window.removeEventListener("clear-filter-values",r)}},[e]),y.useEffect(()=>{const n=r=>{console.log(r);const{urlTemplate:a,openInNewTab:o,enableEncoding:l=!1,payload:u}=r.detail;if(!a){console.error(new Error("[Open Link] URL is empty"));return}function c(h){return x.cloneDeepWith(h,m=>{if(l&&typeof m=="string")return encodeURIComponent(m)})}const f=x.template(a||"")(c({...u,filters:e.payloadForSQL.filters,context:e.payloadForSQL.context}));window.open(f,o?"_blank":"_self","noopener")};return window.addEventListener("open-link",n),()=>{window.removeEventListener("open-link",n)}},[e])}function Zl(e){return y.useCallback(t=>t.provideValue(be.pluginManager,e.pluginManager).provideValue(be.vizManager,e.vizManager).provideValue(be.colorManager,e.colorManager),[])}const yM="",S_=k.observer(()=>{const e=Tr(),t=le(),n=()=>{const r=JSON.stringify(t.json,null,2),a=`${e.name}__${t.name}`;Sl(a,r)};return p(s.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:310,children:[i(s.Menu.Target,{children:i(s.ActionIcon,{variant:"light",color:"blue",children:i(E.IconMenu2,{size:14})})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{icon:i(E.IconDownload,{size:14}),onClick:t.queries.downloadAllData,children:"Download Data"}),i(s.Menu.Item,{icon:i(E.IconCode,{size:14}),onClick:n,children:"Download Schema"})]})]})}),__=k.observer(({saveDashboardChanges:e})=>{const t=Ge.useModals(),n=le(),r=()=>{t.openConfirmModal({title:p(s.Group,{position:"left",children:[i(E.IconAlertTriangle,{size:18,color:"red"}),i(s.Text,{children:"You are reverting changes"})]}),labels:{confirm:"Confirm",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:()=>n.reset(),zIndex:320,withCloseButton:!1})},a=n.changed;return p(s.Group,{spacing:0,children:[i(s.Button,{color:"green",variant:"filled",size:"xs",leftIcon:i(E.IconDeviceFloppy,{size:18}),onClick:e,disabled:!a,sx:{borderTopRightRadius:0,borderBottomRightRadius:0},children:"Save Changes"}),p(s.Menu,{width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:320,disabled:!a,children:[i(s.Menu.Target,{children:i(s.ActionIcon,{variant:"default",disabled:!a,sx:{height:"30px",borderTopLeftRadius:0,borderBottomLeftRadius:0,svg:{fill:"rgb(173, 181, 189)",stroke:"none"}},children:i(E.IconCaretDown,{size:18})})}),i(s.Menu.Dropdown,{children:i(s.Menu.Item,{icon:i(E.IconRecycle,{size:14,color:"red"}),disabled:!a,onClick:r,children:"Revert Changes"})})]})]})}),k_=k.observer(({saveDashboardChanges:e,headerSlot:t=null})=>{const n=Nu.useNavigate(),r=ue(),a=()=>{n(`/dashboard/${r.id}`)},o=Ge.useModals(),l=()=>{o.openConfirmModal({title:p(s.Group,{position:"left",children:[i(E.IconAlertTriangle,{size:18,color:"red"}),i(s.Text,{children:"There are unsaved changes"})]}),labels:{confirm:"Discard",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:a,zIndex:320,withCloseButton:!1})},u=r.content.changed;return i(s.Header,{height:60,px:"md",py:0,sx:{zIndex:299},children:p(s.Group,{position:"apart",sx:{height:60,minWidth:"1000px",position:"relative"},children:[p(s.Group,{children:[i(s.Button,{size:"xs",color:u?"red":"green",leftIcon:i(E.IconArrowLeft,{size:20}),onClick:u?l:a,children:p(s.Group,{spacing:4,children:["End Editing",i(s.Text,{td:"underline",children:r.name})]})}),i(__,{saveDashboardChanges:e})]}),p(s.Group,{position:"right",sx:{flexGrow:1},children:[t,i(S_,{})]})]})})}),T_={position:"fixed",top:60,left:0,right:0,height:30,zIndex:299,borderBottom:"1px solid #e9ecef",background:"rgba(233,236,239, 0.15)"},D_=k.observer(()=>{var n;const e=le(),t=((n=e.views.VIE)==null?void 0:n.type)===j.Tabs;return i(s.Box,{sx:T_,pl:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},children:p(s.Group,{position:"apart",align:"center",sx:{height:"30px"},pr:16,children:[i(s.Button,{variant:"outline",color:"blue",radius:0,size:"xs",disabled:!e.views.VIE||t,onClick:()=>e.addANewPanel(e.views.idOfVIE),leftIcon:i(E.IconPlaylistAdd,{size:20}),sx:{height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef",background:"rgb(231, 245, 255)"},children:"Add a Panel"}),i(s.Box,{}),i(s.Box,{})]})})}),I_=k.observer(e=>p(B,{children:[i(k_,{...e}),i(D_,{})]})),bM="";function M_(e,t,n){const r=[];return e.filter(a=>"__INTERACTIONS"in a.viz.conf).forEach((a,o)=>{const l=t[a.id];l.data.interactions=x.get(l,"data.interactions",[]);const{__INTERACTIONS:u,__OPERATIONS:c,__TRIGGERS:d}=a.viz.conf;Object.entries(c).forEach(([f,h])=>{const{schemaRef:g,data:m}=h,{config:C}=m;switch(g){case"builtin:op:open-link":let w=C.urlTemplate.substring(0,100);C.urlTemplate.length>=20&&(w+="..."),l.type="interaction",l.data.interactions.push({schemaRef:g,urlTemplate:C.urlTemplate,shortURLTemplate:w});return;case"builtin:op:open_view":r.push({id:`OPERATION--${f}`,source:a.id,target:C.viewID,label:"Open View",style:{stroke:"rgba(0,0,0,0.8)"},type:"default"});return;case"builtin:op:set_filter_values":l.type="interaction",l.data.interactions.push({schemaRef:g,filters:Object.keys(C.dictionary).map(_=>({key:_,label:n[_]}))});return;case"builtin:op:clear_filter_values":l.type="interaction",l.data.interactions.push({schemaRef:g,filters:C.filter_keys.map(_=>({key:_,label:n[_]}))});return;default:return}})}),r}function A_(e,t){const n=e.filters.keyLabelMap;return{edges:M_(e.panels.list,t,n),edgeNodes:[]}}function Hl(e,t,n){return e*t+e*n}function z_(e,t,n){return e*t+(e-1)*n}const dr=25,Ni=40,eu=25,qi=350,E_=150,$_=150,tu=150,nu=300,pr=40,ru=25,L_=300;function O_(e,t){const n=x.keyBy(t,a=>a.id),r=[];return e.current.forEach((a,o)=>{a.panelIDs.forEach((l,u)=>{const c=Hl(u,pr,ru)+Ni,d=n[l];if(!d){r.push({id:l,_node_type:"panel",parentNode:a.id,data:{label:`!: ${l}`},position:{x:dr,y:c},sourcePosition:Me.Position.Right,targetPosition:Me.Position.Left,style:{width:nu,height:pr}});return}const f=d.title.trim()?`${d.title}`:d.viz.type;r.push({id:d.id,_node_type:"panel",parentNode:a.id,data:{label:f},position:{x:dr,y:c},sourcePosition:Me.Position.Right,targetPosition:Me.Position.Left,style:{width:nu,height:pr}})})}),r}const P_={[j.Division]:"Div",[j.Modal]:"Modal",[j.Tabs]:"Tabs"},B_=Fl;function V_(e){return e.current.map((n,r)=>{const a=z_(n.panelIDs.length,pr,ru)+Ni+eu;let o=[];return n.type===j.Tabs&&(o=n.config.tabs.map(u=>u.view_id)),{id:n.id,_node_type:"view-root",_view_type:n.type,_view_level:0,_sub_view_ids:[],_tab_view_ids:o,data:{label:`${P_[n.type]}:${n.name}`},position:{x:0,y:0},sourcePosition:Me.Position.Right,targetPosition:Me.Position.Left,className:"light",style:{backgroundColor:B_[n.type],width:qi,height:a}}})}function N_(e){const t=x.keyBy(e,n=>n.id);e.forEach(n=>{n._node_type!=="view-root"||n._view_type!==j.Tabs||n._tab_view_ids.forEach(r=>{t[r].parentNode=n.id})})}function q_(e){const t=V_(e.views);N_(t);const n=O_(e.views,e.panels.list);return[...t,...n]}function F_({nodeMap:e,nodes:t,edges:n}){t.forEach(r=>{r._node_type!=="view-root"||r._view_type!==j.Tabs||(r.sourcePosition=Me.Position.Bottom,r.style.width=qi+dr*2,r.style.height=eu+r._tab_view_ids.reduce((a,o)=>{const l=e[o];l.position.y=a,l.position.x=dr;const u=l.style.height;return a+u+20},Ni))})}function G_({nodeMap:e,nodes:t,edges:n}){n.filter(r=>r.label==="Open View").forEach(r=>{const a=e[r.source],o=e[r.target];if(!a||!o||!a.parentNode)return;const l=e[a.parentNode];l._node_type!=="view-root"||o._node_type!=="view-root"||(o._view_level+=1+l._view_level,l._sub_view_ids.push(o.id))}),t.sort((r,a)=>r._node_type==="view-root"&&a._node_type==="view-root"?r._view_level-a._view_level:r._node_type!=="view-root"&&a._node_type!=="view-root"?0:r._node_type==="view-root"?-1:1)}function W_({nodeMap:e,nodes:t,edges:n}){const r={};n.forEach(a=>{if(a.label!=="Open View")return;const o=e[a.source],l=e[a.target];if(o&&l&&o.parentNode){const u=e[o.parentNode],c=u.position.x,d=Number(x.get(l,"style.height",0)),f=Number(u.style.width);l.position.x=c+f+L_,u._view_level===0&&l._sub_view_ids.length===0&&(o.sourcePosition=Me.Position.Left,l.targetPosition=Me.Position.Right,l.position.x*=-1);const g=l.position.x,m=x.get(r,g,0);l.position.y=m,r[g]=m+d+tu}})}function j_({nodeMap:e,nodes:t,edges:n}){const r=new Set,a=new Set;n.forEach(l=>{r.add(l.source),a.add(l.target)}),t.filter(l=>l._node_type!=="view-root"||l.id==="Main"||l.parentNode?!1:!r.has(l.id)&&!a.has(l.id)).forEach((l,u)=>{l.position.x=Hl(u,qi,$_),l.position.y=0-E_-tu})}function R_({nodeMap:e,nodes:t,edges:n}){const r={nodeMap:e,nodes:t,edges:n};return j_(r),G_(r),F_(r),W_(r),{nodes:t,edges:n}}function Y_(e){const t=q_(e),n=x.keyBy(t,c=>c.id),{edges:r,edgeNodes:a}=A_(e,n),o=[...t,...a],l=x.keyBy(o,c=>c.id),u={edges:x.uniqBy(r,c=>c.id),nodes:o,nodeMap:l};return R_(u)}const vM="",Fi={"builtin:op:open-link":i(s.ThemeIcon,{color:"blue",size:20,radius:"xl",children:i(E.IconCircleDashed,{size:14})}),"builtin:op:set_filter_values":i(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:i(E.IconCircleDot,{size:14})}),"builtin:op:clear_filter_values":i(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:i(E.IconCircleOff,{size:14})})};function Q_(e){const t=[];return e.forEach(n=>{switch(n.schemaRef){case"builtin:op:open-link":t.push({key:n.urlTemplate,icon:Fi[n.schemaRef],text:p(s.Group,{spacing:4,children:[i(s.Text,{children:"Open: "}),i(s.Text,{color:"dimmed",children:n.shortURLTemplate})]})});return;case"builtin:op:set_filter_values":n.filters.forEach(({key:r,label:a})=>{t.push({key:n.schemaRef+r,icon:Fi[n.schemaRef],text:i(s.Group,{spacing:4,children:p(s.Text,{children:["Set Filter: ",a]})})})});return;case"builtin:op:clear_filter_values":n.filters.forEach(({key:r,label:a})=>{t.push({key:n.schemaRef+r,icon:Fi[n.schemaRef],text:i(s.Group,{spacing:4,children:p(s.Text,{children:["Clear Filter: ",a]})})})});return}}),t}const U_=y.memo(({data:e,isConnectable:t,sourcePosition:n=Me.Position.Right,targetPosition:r=Me.Position.Left,...a})=>{const o=y.useMemo(()=>Q_(e.interactions),[e.interactions]);return p(B,{children:[i(Me.Handle,{type:"target",position:r,isConnectable:t}),i(s.Box,{sx:{position:"absolute",top:0,right:0},children:i(D.ChevronsUpRight,{size:12})}),p(s.HoverCard,{shadow:"xl",withinPortal:!0,children:[i(s.HoverCard.Target,{children:i(s.Text,{children:e.label})}),i(s.HoverCard.Dropdown,{children:i(s.List,{spacing:"xs",size:"sm",center:!0,children:o.map(l=>i(s.List.Item,{icon:l.icon,children:l.text},l.key))})})]}),i(Me.Handle,{type:"source",position:n,isConnectable:t})]})}),xM="",K_={interaction:U_},X_=k.observer(()=>{const e=ye(),{edges:t,nodes:n}=Y_(e);return p(Me,{nodes:n,edges:t,onNodesChange:x.noop,onEdgesChange:x.noop,onConnect:x.noop,className:"interactions-viewer",fitView:!0,nodeTypes:K_,children:[i(Me.MiniMap,{}),i(Me.Controls,{}),i(Me.Background,{})]})}),J_=k.observer(({opened:e,close:t})=>i(s.Modal,{size:"96vw",opened:e,onClose:t,title:"Interactions",trapFocus:!0,onDragStart:n=>{n.stopPropagation()},styles:{body:{height:"90vh"},content:{transform:"none !important"}},zIndex:300,children:i(X_,{})})),Z_={"> 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 H_({onClick:e,name:t,active:n,openSettings:r}){return p(s.Box,{sx:{position:"relative"},children:[i(s.UnstyledButton,{sx:a=>({display:"block",width:"100%",padding:a.spacing.xs,borderRadius:0,position:"relative",color:a.black,"&:hover":{backgroundColor:a.colors.gray[0]},backgroundColor:n?a.colors.gray[2]:"transparent"}),children:i(s.Group,{sx:{width:"calc(100% - 28px)"},onClick:e,children:i(s.Text,{size:"sm",children:t})})}),n&&i(s.Tooltip,{label:"Edit",position:"right",withinPortal:!0,children:i(s.ActionIcon,{onClick:r,variant:"light",color:"blue",sx:{position:"absolute",top:0,bottom:0,height:"100%",right:0,zIndex:0,borderRadius:0},children:i(E.IconAdjustments,{size:16})})})]})}const ek=k.observer(()=>{const e=ue(),t=le(),n=y.useCallback(a=>()=>t.views.setIDOfVIE(a),[t]),r=a=>{e.editor.open(["_VIEWS_",a])};return p(s.Box,{sx:{position:"relative"},children:[t.views.options.map(a=>i(H_,{active:t.views.idOfVIE===a.value,name:a.label,onClick:n(a.value),openSettings:()=>r(a.value)},a.value)),i(s.Divider,{variant:"dashed"}),i(s.Button,{variant:"subtle",rightIcon:i(E.IconPlus,{size:14}),size:"sm",px:"xs",color:"blue",onClick:t.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"space-between"}},children:"Add a View"})]})}),tk=k.observer(()=>{const e=ue(),t=le(),n=()=>{if(!t.queries.firstID){e.editor.open(["_QUERIES_",""]);return}e.editor.open(["_QUERIES_",t.queries.firstID])},r=()=>{if(!t.filters.firstID){e.editor.open(["_FILTERS_",""]);return}e.editor.open(["_FILTERS_",t.filters.firstID])},[a,o]=y.useState(!1),l=()=>o(!0),u=()=>o(!1);return p(s.Navbar,{p:0,width:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},zIndex:299,children:[p(s.Navbar.Section,{children:[p(s.Group,{grow:!0,spacing:0,sx:{...Z_,button:{borderWidth:0,borderBottomWidth:1,borderColor:"#e9ecef"}},children:[i(s.Tooltip,{label:"Filters",withinPortal:!0,children:i(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:r,children:i(E.IconFilter,{size:18})})}),i(s.Tooltip,{label:"Queries",withinPortal:!0,children:i(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:n,children:i(E.IconDatabase,{size:18})})}),i(s.Tooltip,{label:"Interactions Viewer",withinPortal:!0,children:i(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:l,children:i(E.IconLink,{size:18})})})]}),i(J_,{opened:a,close:u})]}),i(s.Navbar.Section,{py:5,sx:{borderBottom:"1px solid #eee"},children:i(s.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Views"})}),i(s.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:i(ek,{})}),i(s.Navbar.Section,{children:i(s.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:i(s.Button,{size:"xs",leftIcon:i(E.IconSettings,{size:20}),onClick:()=>e.editor.open([]),children:"Settings"})})})]})}),nk=k.observer(function({config:t}){return p(B,{children:[i(s.Checkbox,{checked:t.default_value,onChange:n=>t.setDefaultValue(n.currentTarget.checked),label:"Default Checked"}),i(pi,{label:"Description",value:t.description,onChange:t.setDescription,styles:{root:{flexGrow:1,minHeight:"400px"}}})]})}),rk=[{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"}],ik=k.observer(function({config:t}){return p(B,{children:[p(s.Group,{children:[i(s.Checkbox,{checked:t.required,onChange:n=>t.setRequired(n.currentTarget.checked),label:"Required"}),i(s.Checkbox,{checked:t.clearable,onChange:n=>t.setClearable(n.currentTarget.checked),disabled:t.max_days>0,label:"Clearable"}),i(s.Checkbox,{checked:t.allowSingleDateInRange,onChange:n=>t.setAllowSingleDateInRange(n.currentTarget.checked),label:"Allow choosing 1 day"})]}),i(s.Select,{data:rk,label:"Display Format",value:t.inputFormat,onChange:t.setInputFormat}),i(Ko,{label:"Default Value",config:t,value:t.default_value,onChange:t.setDefaultValue}),i(s.NumberInput,{label:"Max Days",description:p(s.Group,{position:"apart",children:[i(s.Text,{children:"Set 0 to disable."}),p(s.Group,{spacing:4,children:[i(s.Text,{children:"This feature requires"}),i(s.Text,{color:"blue",children:"Clearable"}),i(s.Text,{children:"to be checked"})]})]}),min:0,value:t.max_days,onChange:t.setMaxDays,hideControls:!0})]})}),Gi=k.observer(({value:e,onChange:t})=>{const n=ue(),r=le(),a=y.useMemo(()=>r.queries.options,[r.queries.current]),o=a.length===0,l=u=>{n.editor.setPath(["_QUERIES_",u])};return i(s.Select,{label:p(s.Group,{position:"apart",children:[i(s.Text,{children:"Use query data as options"}),e&&i(s.Button,{size:"xs",leftIcon:i(E.IconArrowCurveRight,{size:16}),variant:"subtle",color:"blue",onClick:()=>l(e),children:"Open this query"})]}),data:a,value:e,onChange:t,allowDeselect:!1,clearable:!0,sx:{flexGrow:1},disabled:o,error:o?"You need to add a query in Data Settings":void 0,styles:{label:{display:"block"}}})}),ak=`
|
|
503
|
+
`}})).actions(e=>({setPage(t){e.page=t},resetPage(){e.page=1},setLimit(t){e.limit=t}})).actions(e=>({afterCreate(){b.addDisposer(e,te.reaction(()=>e.keywordString,e.resetPage,{fireImmediately:!1,delay:0})),b.addDisposer(e,te.reaction(()=>e.limit,e.resetPage,{fireImmediately:!1,delay:0}))}})),b_=b.types.model({data:b.types.optional(b.types.frozen(),{}),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return Object.keys(e.data).length===0},get sql(){const t=b.getParent(e,1).type;return t===ve.MySQL||t===ve.Postgresql?"SELECT table_schema, table_name, table_type FROM information_schema.tables ORDER BY table_schema, table_name":""}})),v_=b.types.compose("DataSourceModel",fl,b.types.model({tables:b.types.optional(b_,{}),columns:b.types.optional(g_,{}),tableData:b.types.optional(y_,{}),indexes:b.types.optional(m_,{}),table_schema:b.types.optional(b.types.string,""),table_name:b.types.optional(b.types.string,"")})).volatile(()=>({controllers:{tables:new AbortController,columns:new AbortController,indexes:new AbortController,tableData:new AbortController}})).actions(e=>({setKeywords(t,n){e.table_schema=t,e.table_name=n}})).actions(e=>({initKeywords(){if(e.tables.empty)return;const t=Object.keys(e.tables.data)[0],n=e.tables.data[t][0].table_name;e.setKeywords(t,n)}})).actions(e=>{const t=b.flow(function*(){var n;(n=e.controllers.tables)==null||n.abort(),e.controllers.tables=new AbortController,e.tables.state="loading";try{const r=yield*b.toGenerator(Pe.query(e.controllers.tables.signal)({type:e.type,key:e.key,query:e.tables.sql},{}));e.tables.data=x.groupBy(r,"table_schema"),e.tables.state="idle",e.tables.error=null,e.initKeywords()}catch(r){if(!xt.isCancel(r)){e.tables.data={};const a=x.get(r,"message","unkown error");e.tables.error=x.get(r,"response.data.detail.message",a),e.tables.state="error"}}});return{loadTables:t,loadTablesIfEmpty(){e.tables.empty&&t()},loadColumns:b.flow(function*(){var n;(n=e.controllers.columns)==null||n.abort(),e.controllers.columns=new AbortController,e.columns.state="loading";try{e.columns.data=yield*b.toGenerator(Pe.query(e.controllers.columns.signal)({type:e.type,key:e.key,query:e.columns.sql},{})),e.columns.state="idle",e.columns.error=null}catch(r){if(xt.isCancel(r))e.columns.state="idle",e.columns.error=null;else{e.columns.data=[];const a=x.get(r,"message","unkown error");e.columns.error=x.get(r,"response.data.detail.message",a),e.columns.state="error"}}}),loadIndexes:b.flow(function*(){var n;(n=e.controllers.indexes)==null||n.abort(),e.controllers.indexes=new AbortController,e.indexes.state="loading";try{e.indexes.data=yield*b.toGenerator(Pe.query(e.controllers.indexes.signal)({type:e.type,key:e.key,query:e.indexes.sql},{})),e.indexes.state="idle",e.indexes.error=null}catch(r){if(xt.isCancel(r))e.indexes.state="idle",e.indexes.error=null;else{e.indexes.data=[];const a=x.get(r,"message","unkown error");e.indexes.error=x.get(r,"response.data.detail.message",a),e.indexes.state="error"}}}),loadTableData:b.flow(function*(){var r;(r=e.controllers.tableData)==null||r.abort(),e.controllers.tableData=new AbortController;const n=e.tableData;n.state="loading";try{n.data=yield*b.toGenerator(Pe.query(e.controllers.tableData.signal)({type:e.type,key:e.key,query:n.sql},{}));const[{total:a}]=yield*b.toGenerator(Pe.query(e.controllers.tableData.signal)({type:e.type,key:e.key,query:n.countSql},{}));n.total=Number(a),n.state="idle",n.error=null}catch(a){if(xt.isCancel(a))n.state="idle",n.error=null;else{n.data=[];const o=x.get(a,"message","unkown error");n.error=x.get(a,"response.data.detail.message",o),n.state="error"}}})}}).actions(e=>({afterCreate(){b.addDisposer(e,te.reaction(()=>e.columns.sql,e.loadColumns,{fireImmediately:!1,delay:500}))}})).actions(e=>({afterCreate(){b.addDisposer(e,te.reaction(()=>e.indexes.sql,e.loadIndexes,{fireImmediately:!1,delay:500})),b.addDisposer(e,te.reaction(()=>e.tableData.sql,e.loadTableData,{fireImmediately:!1,delay:0}))}})),x_=b.types.model("DataSourcesModel",{list:b.types.optional(b.types.array(v_),[])}).views(e=>({find({type:t,key:n}){return e.list.find(r=>r.key===n&&r.type===t)},get options(){return e.list.map(t=>({value:t.key,label:t.key}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}}));function Ut(e){return{label:e,value:e,_type:"ACTION",_action_type:e,Icon:null,children:null}}function w_(e){switch(e._type){case"GROUP":case"ACTION":return null;case"query_variables":return["_QUERY_VARS_"];case"mock_context":return["_MOCK_CONTEXT_"];case"filter":return["_FILTERS_",e.value];case"sql_snippet":return["_SQL_SNIPPETS_",e.value];case"query":return["_QUERIES_",e.value];case"view":return["_VIEWS_",e.value];case"panel":return e.parentID?["_VIEWS_",e.parentID,"_PANELS_",e.value]:(console.error("[getPathFromOption] parentID is required"),null)}}const C_=b.types.model("EditorModel",{path:b.types.optional(b.types.frozen(),[]),settings_open:b.types.optional(b.types.boolean,!1)}).views(e=>({get navOptions(){const{content:t}=b.getRoot(e),{filters:n,views:r,sqlSnippets:a,queries:o}=t;return[{label:"Query Variables",value:"_QUERY_VARS_",_type:"query_variables",Icon:E.IconVariable},{label:"Mock Context",value:"_MOCK_CONTEXT_",Icon:E.IconCodeDots,_type:"mock_context"},{label:"Filters",value:"_FILTERS_",Icon:E.IconFilter,children:[...n.options,Ut("_Add_A_Filter_")],_type:"GROUP"},{label:"SQL Snippets",value:"_SQL_SNIPPETS_",Icon:E.IconCopy,children:[Ut("_SQL_SNIPPETS_SETTINGS_"),...a.options,Ut("_Add_A_SQL_SNIPPET_")],_type:"GROUP"},{label:"Queries",value:"_QUERIES_",Icon:E.IconDatabase,children:[Ut("_QUERIES_SETTINGS_"),...o.options,Ut("_Add_A_QUERY_")],_type:"GROUP"},{label:"Views",value:"_VIEWS_",Icon:E.IconBoxMultiple,children:[...r.editorOptions,Ut("_Add_A_VIEW_")],_type:"GROUP"}]},isOptionActive(t,n){return t.length===0?!1:t[t.length-1]===n.value},isOptionOpened(t){const{path:n}=e;return n.length===0||!t.children||t.children.length===0?!1:n.includes(t.value)}})).actions(e=>({setPath(t){e.path=t},setSettingsOpen(t){e.settings_open=t}})).actions(e=>({open(t){e.setPath(t),e.setSettingsOpen(!0)},close(){e.setSettingsOpen(!1)},navigate(t){const n=w_(t);n&&e.setPath(n)}})),Ql=bl.views(e=>({get dataFieldOptions(){return e.queryIDs.length===0?[]:e.queries.map(t=>{const n=t.data;return n.length===0?[]:Object.keys(n[0]).map(a=>({label:a,value:`${t.id}.${a}`,group:t.name}))}).flat()}})).actions(e=>({removeSelf(){b.getParent(e,2).removeByID(e.id)}})).actions(e=>({moveToView(t,n){b.getRoot(e).content.views.findByID(t).removePanelID(e.id),b.getRoot(e).content.views.findByID(n).appendPanelID(e.id),b.getRoot(e).editor.setPath(["_VIEWS_",n,"_PANELS_",e.id])}})),Ul=b.types.compose("PanelsModel",vl,b.types.model({list:b.types.optional(b.types.array(Ql),[])})).views(e=>({editorOptions(t,n){const{panels:r}=e.panelsByIDs(n);r.length!==n.length&&console.warn(`Unfulfilled panels for View[${t}]`);const a=r.map(l=>({label:l.title?l.title:x.capitalize(l.viz.type),value:l.id,_type:"panel",parentID:t})),o="_Add_A_PANEL_";return a.push({label:o,value:o,_type:"ACTION",_action_type:o,parentID:t,Icon:null,children:null}),a}})).actions(e=>({replace(t){e.list=b.castToSnapshot(t)},append(t){e.list.push(t)},remove(t){e.list.splice(t,1)},removeByID(t){const n=e.list.findIndex(r=>r.id===t);n!==-1&&e.list.splice(n,1)},removeByIDs(t){t.forEach(n=>{this.removeByID(n)})},duplicateByID(t){const n=e.list.find(a=>a.id===t);if(!n){console.error(new Error(`[duplicate panel] Can't find a panel by id[${t}]`));return}const r=new Date().getTime().toString();return e.list.push({...n.json,id:r,layout:{...n.layout,y:1/0,moved:!1}}),r},replaceByIndex(t,n){e.list.splice(t,1,n)}})),Kl=b.types.compose("ViewsModel",yl,b.types.model({idOfVIE:b.types.string})).views(e=>({get isVIETheFirstView(){return e.current.length===0||!e.idOfVIE?!1:e.current[0].id===e.idOfVIE},get VIE(){return e.current.find(({id:t})=>t===e.idOfVIE)},get options(){return e.current.map(t=>({label:t.name,value:t.id,type:t.type}))},get editorOptions(){const t=b.getRoot(e).content.panels;return e.current.map(n=>({label:n.name,value:n.id,_type:"view",children:t.editorOptions(n.id,n.panelIDs)}))}})).actions(e=>({setIDOfVIE(t){e.idOfVIE=t,e.visibleViewIDs.length=0,e.visibleViewIDs.push(t)},replace(t){e.current.replace(t)},addANewView(t,n,r,a){e.current.push({id:t,name:n,type:r,config:a,panelIDs:[]})},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByID(t){const n=e.current.findIndex(o=>o.id===t);if(n===-1)return;const r=e.current[n];b.getRoot(e).content.panels.removeByIDs(r.panelIDs),e.current.splice(n,1)},replaceByIndex(t,n){e.current.splice(t,1,n)},addARandomNewView(){const t=new Date().getTime().toString();this.addANewView(t,j.Division,j.Division,{_name:j.Division}),this.setIDOfVIE(t)},removeVIE(){e.current.length!==1&&(this.removeByID(e.idOfVIE),this.setIDOfVIE(e.current[0].id))}}));function Bi(e){const t=e.length>0?[e[0].id]:[],n=e.length>0?e[0].id:"";return{current:e.map(a=>{const{_name:o=a.type}=a.config;return{...a,config:{...a.config,_name:o},panelIDs:a.panelIDs}}),visibleViewIDs:t,idOfVIE:n}}const S_=b.types.model({id:b.types.string,name:b.types.string,dashboard_id:b.types.string,create_time:b.types.string,update_time:b.types.string,version:b.types.string,filters:jl,queries:Rl,sqlSnippets:Yl,views:Kl,panels:Ul,mock_context:el,origin:b.types.maybe(b.types.frozen())}).views(e=>({get json(){return{id:e.id,name:e.name,create_time:e.create_time,update_time:e.update_time,dashboard_id:e.dashboard_id,content:{views:e.views.json,panels:e.panels.json,filters:e.filters.json,version:e.version,definition:{queries:e.queries.json,sqlSnippets:e.sqlSnippets.json,mock_context:e.mock_context.current}}}},get filtersChanged(){const t="filters.current";return!x.isEqual(b.getSnapshot(x.get(e,t)),x.get(e.origin,t))},get queriesChanged(){const t="queries.current",n=b.getSnapshot(x.get(e,t)).map(r=>x.pick(r,["id","name","key","type","sql","run_by","react_to","pre_process","post_process"]));return!x.isEqual(n,x.get(e.origin,t))},get sqlSnippetsChanged(){const t="sqlSnippets.current";return!x.isEqual(b.getSnapshot(x.get(e,t)),x.get(e.origin,t))},get viewsChanged(){const t="views.current";return!x.isEqual(e.views.json,x.get(e.origin,t))},get panelsChanged(){const t="panels.list";return!x.isEqual(b.getSnapshot(x.get(e,t)),x.get(e.origin,t))},get mockContextChanged(){const t="mock_context.current";return!x.isEqual(x.get(e,t),x.get(e.origin,t))},get payloadForSQL(){const t=b.getParent(e).context.current,n=b.getParent(e).globalSQLSnippets,r={context:{...e.mock_context.current,...t},filters:e.filters.values};return{...r,sql_snippets:lr(e.sqlSnippets.current,"key","value",r),global_sql_snippets:lr(n.list,"id","content",r)}},get payloadForViz(){const t=b.getParent(e).context.current;return{context:{...e.mock_context.current,...t},filters:e.filters.values}},get changed(){return this.filtersChanged||this.queriesChanged||this.sqlSnippetsChanged||this.viewsChanged||this.panelsChanged||this.mockContextChanged},get data(){return e.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(t){const n=e.queries.findByID(t);return n?{data:n.data,len:n.data.length,state:n.state,error:n.error}:{data:[],len:0,state:"idle",error:void 0}}})).views(e=>({get queriesUsage(){const t=e.panels.idMap,n=[];e.views.current.forEach(a=>{a.panelIDs.forEach(o=>{const l=t.get(o);if(!l)return;const u="panel",c=l.title?l.title:l.viz.type,d=[{id:a.id,label:a.name}];l.queryIDs.forEach(f=>{n.push({id:o,queryID:f,type:u,label:c,views:d})})})});const r=e.views.idMap;return e.filters.current.filter(a=>!!x.get(a,"config.options_query_id")).map(a=>({type:"filter",id:a.id,queryID:x.get(a,"config.options_query_id"),label:a.label,views:a.visibleInViewsIDs.map(o=>{var l;return{id:o,label:((l=r.get(o))==null?void 0:l.name)??o}})})),x.groupBy(n,"queryID")},get hasUnusedQueries(){return e.queries.current.length>Object.keys(this.queriesUsage).length},findQueryUsage(t){return this.queriesUsage[t]??[]},get sqlSnippetsUsage(){const t=[],n=new RegExp("(?<=sql_snippets\\.)([^}.]+)","gm");return e.queries.current.forEach(r=>{if(!r.typedAsSQL)return;x.uniq(r.sql.match(n)).forEach(o=>{t.push({queryID:r.id,sqlSnippetKey:o,queryName:r.name})})}),x.groupBy(t,"sqlSnippetKey")},get hasUnusedSQLSnippets(){return e.sqlSnippets.current.length>Object.keys(this.sqlSnippetsUsage).length},findSQLSnippetUsage(t){return this.sqlSnippetsUsage[t]??[]}})).actions(e=>({removeUnusedQueries(){const t=new Set(Object.keys(e.queriesUsage)),n=e.queries.current.filter(r=>!t.has(r.id)).map(r=>r.id);e.queries.removeQueries(n)},removeUnusedSQLSnippets(){const t=new Set(Object.keys(e.sqlSnippetsUsage)),n=e.sqlSnippets.current.filter(r=>!t.has(r.key)).map(r=>r.key);e.sqlSnippets.removeByKeys(n)},duplicatePanelByID(t,n){var a;const r=e.panels.duplicateByID(t);r&&((a=e.views.findByID(n))==null||a.appendPanelID(r))},removePanelByID(t,n){var r;e.panels.removeByID(t),(r=e.views.findByID(n))==null||r.removePanelID(t)},addANewPanel(t){var r;const n=new Date().getTime().toString();e.panels.append(yS(n)),(r=e.views.findByID(t))==null||r.appendPanelID(n)}})).actions(e=>({reset(){b.applySnapshot(e.filters.current,e.origin.filters.current),b.applySnapshot(e.queries.current,e.origin.queries.current),b.applySnapshot(e.sqlSnippets.current,e.origin.sqlSnippets.current),b.applySnapshot(e.views.current,e.origin.views.current),b.applySnapshot(e.panels.list,e.origin.panels.list),e.mock_context.current=e.origin.mock_context.current},resetFilters(){b.applySnapshot(e.filters.current,e.origin.filters.current)},updateCurrent(t){const{id:n,name:r,content:a}=t;if(!a)throw new Error("unexpected null content when updating a content model");const{version:o,filters:l,views:u,panels:c,definition:{queries:d,sqlSnippets:f,mock_context:h={}}}=a;e.id=n,e.name=r,e.version=o,b.applySnapshot(e.filters.current,l),b.applySnapshot(e.views.current,Bi(u).current),b.applySnapshot(e.panels.list,c),b.applySnapshot(e.queries.current,d),b.applySnapshot(e.sqlSnippets.current,f),e.mock_context.current=h}})),Vi=b.types.snapshotProcessor(S_,{preProcessor(e){return{...e,origin:e}},postProcessor(e){delete e.origin;const t=b.castToSnapshot(e.queries.current.map(n=>x.pick(n,["id","key","type","sql"])));return x.defaults({},{queries:{current:t}},e)}});function __(e,t){t.filters&&b.applySnapshot(e.filters.current,t.filters)}function Xl({id:e,name:t,dashboard_id:n,create_time:r,update_time:a,content:o}){if(!o)throw new Error("unexpected null content when creating a content model");const{version:l,filters:u,views:c,panels:d,definition:{queries:f,sqlSnippets:h,mock_context:g={}}}=o;return Vi.create({id:e,name:t,dashboard_id:n,create_time:r,update_time:a,version:l,filters:Cl(u),queries:{current:f},sqlSnippets:{current:h},mock_context:tl(g),views:Bi(c),panels:{list:d}})}const Jl=b.types.model({id:b.types.identifier,name:b.types.string,group:b.types.string,content:Vi,content_id:b.types.string,datasources:x_,globalSQLSnippets:gl,context:Ei,editor:C_}).views(e=>({get json(){return{id:e.id,name:e.name,group:e.group,content_id:e.content_id}}})).actions(e=>({updateCurrentContent(t){e.content.updateCurrent(t)},updateCurrent(t,n){const{id:r,name:a,group:o,content_id:l}=t;e.id=r,e.name=a,e.group=o,e.content_id=l,this.updateCurrentContent(n)}}));function Zl({id:e,name:t,group:n,content_id:r},a,o,l,u){return Jl.create({id:e,name:t,group:n,content_id:r,content:Xl(a),datasources:{list:o},globalSQLSnippets:{list:l},context:ml(u),editor:{}})}function Hl(e,t){y.useEffect(()=>{const n=r=>{console.log(r);const{viewID:a}=r.detail;if(!a){console.error(new Error("[Open View] Needs to pick a view first"));return}e.views.appendToVisibles(a),t&&e.views.setIDOfVIE(a)};return window.addEventListener("open-view",n),()=>{window.removeEventListener("open-view",n)}},[e,t]),y.useEffect(()=>{const n=r=>{console.log(r);const{dictionary:a,payload:o}=r.detail;if(!o||Object.keys(o).length===0){console.error(new Error("[Set Filter Values] payload is empty"));return}Object.entries(a).forEach(([l,u])=>{e.filters.setValueByKey(l,x.get(o,u))})};return window.addEventListener("set-filter-values",n),()=>{window.removeEventListener("set-filter-values",n)}},[e]),y.useEffect(()=>{function n(a){return Array.isArray(a)?[]:typeof a=="object"?{}:typeof a=="boolean"?!1:typeof a=="string"?"":typeof a=="number"?0:a}const r=a=>{console.log(a);const{filter_keys:o}=a.detail;o.forEach(l=>{const u=x.get(e.filters.values,l),c=n(u);console.log(`${l}: ${c}`),e.filters.setValueByKey(l,c)})};return window.addEventListener("clear-filter-values",r),()=>{window.removeEventListener("clear-filter-values",r)}},[e]),y.useEffect(()=>{const n=r=>{console.log(r);const{urlTemplate:a,openInNewTab:o,enableEncoding:l=!1,payload:u}=r.detail;if(!a){console.error(new Error("[Open Link] URL is empty"));return}function c(h){return x.cloneDeepWith(h,m=>{if(l&&typeof m=="string")return encodeURIComponent(m)})}const f=x.template(a||"")(c({...u,filters:e.payloadForSQL.filters,context:e.payloadForSQL.context}));window.open(f,o?"_blank":"_self","noopener")};return window.addEventListener("open-link",n),()=>{window.removeEventListener("open-link",n)}},[e])}function eu(e){return y.useCallback(t=>t.provideValue(be.pluginManager,e.pluginManager).provideValue(be.vizManager,e.vizManager).provideValue(be.colorManager,e.colorManager),[])}const vM="",k_=k.observer(()=>{const e=Tr(),t=le(),n=()=>{const r=JSON.stringify(t.json,null,2),a=`${e.name}__${t.name}`;kl(a,r)};return p(s.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:310,children:[i(s.Menu.Target,{children:i(s.ActionIcon,{variant:"light",color:"blue",children:i(E.IconMenu2,{size:14})})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{icon:i(E.IconDownload,{size:14}),onClick:t.queries.downloadAllData,children:"Download Data"}),i(s.Menu.Item,{icon:i(E.IconCode,{size:14}),onClick:n,children:"Download Schema"})]})]})}),T_=k.observer(({saveDashboardChanges:e})=>{const t=Ge.useModals(),n=le(),r=()=>{t.openConfirmModal({title:p(s.Group,{position:"left",children:[i(E.IconAlertTriangle,{size:18,color:"red"}),i(s.Text,{children:"You are reverting changes"})]}),labels:{confirm:"Confirm",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:()=>n.reset(),zIndex:320,withCloseButton:!1})},a=n.changed;return p(s.Group,{spacing:0,children:[i(s.Button,{color:"green",variant:"filled",size:"xs",leftIcon:i(E.IconDeviceFloppy,{size:18}),onClick:e,disabled:!a,sx:{borderTopRightRadius:0,borderBottomRightRadius:0},children:"Save Changes"}),p(s.Menu,{width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:320,disabled:!a,children:[i(s.Menu.Target,{children:i(s.ActionIcon,{variant:"default",disabled:!a,sx:{height:"30px",borderTopLeftRadius:0,borderBottomLeftRadius:0,svg:{fill:"rgb(173, 181, 189)",stroke:"none"}},children:i(E.IconCaretDown,{size:18})})}),i(s.Menu.Dropdown,{children:i(s.Menu.Item,{icon:i(E.IconRecycle,{size:14,color:"red"}),disabled:!a,onClick:r,children:"Revert Changes"})})]})]})}),D_=k.observer(({saveDashboardChanges:e,headerSlot:t=null})=>{const n=Fu.useNavigate(),r=ue(),a=()=>{n(`/dashboard/${r.id}`)},o=Ge.useModals(),l=()=>{o.openConfirmModal({title:p(s.Group,{position:"left",children:[i(E.IconAlertTriangle,{size:18,color:"red"}),i(s.Text,{children:"There are unsaved changes"})]}),labels:{confirm:"Discard",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:a,zIndex:320,withCloseButton:!1})},u=r.content.changed;return i(s.Header,{height:60,px:"md",py:0,sx:{zIndex:299},children:p(s.Group,{position:"apart",sx:{height:60,minWidth:"1000px",position:"relative"},children:[p(s.Group,{children:[i(s.Button,{size:"xs",color:u?"red":"green",leftIcon:i(E.IconArrowLeft,{size:20}),onClick:u?l:a,children:p(s.Group,{spacing:4,children:["End Editing",i(s.Text,{td:"underline",children:r.name})]})}),i(T_,{saveDashboardChanges:e})]}),p(s.Group,{position:"right",sx:{flexGrow:1},children:[t,i(k_,{})]})]})})}),I_={position:"fixed",top:60,left:0,right:0,height:30,zIndex:299,borderBottom:"1px solid #e9ecef",background:"rgba(233,236,239, 0.15)"},M_=k.observer(()=>{var n;const e=le(),t=((n=e.views.VIE)==null?void 0:n.type)===j.Tabs;return i(s.Box,{sx:I_,pl:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},children:p(s.Group,{position:"apart",align:"center",sx:{height:"30px"},pr:16,children:[i(s.Button,{variant:"outline",color:"blue",radius:0,size:"xs",disabled:!e.views.VIE||t,onClick:()=>e.addANewPanel(e.views.idOfVIE),leftIcon:i(E.IconPlaylistAdd,{size:20}),sx:{height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef",background:"rgb(231, 245, 255)"},children:"Add a Panel"}),i(s.Box,{}),i(s.Box,{})]})})}),A_=k.observer(e=>p(B,{children:[i(D_,{...e}),i(M_,{})]})),xM="";function z_(e,t,n){const r=[];return e.filter(a=>"__INTERACTIONS"in a.viz.conf).forEach((a,o)=>{const l=t[a.id];l.data.interactions=x.get(l,"data.interactions",[]);const{__INTERACTIONS:u,__OPERATIONS:c,__TRIGGERS:d}=a.viz.conf;Object.entries(c).forEach(([f,h])=>{const{schemaRef:g,data:m}=h,{config:C}=m;switch(g){case"builtin:op:open-link":let w=C.urlTemplate.substring(0,100);C.urlTemplate.length>=20&&(w+="..."),l.type="interaction",l.data.interactions.push({schemaRef:g,urlTemplate:C.urlTemplate,shortURLTemplate:w});return;case"builtin:op:open_view":r.push({id:`OPERATION--${f}`,source:a.id,target:C.viewID,label:"Open View",style:{stroke:"rgba(0,0,0,0.8)"},type:"default"});return;case"builtin:op:set_filter_values":l.type="interaction",l.data.interactions.push({schemaRef:g,filters:Object.keys(C.dictionary).map(_=>({key:_,label:n[_]}))});return;case"builtin:op:clear_filter_values":l.type="interaction",l.data.interactions.push({schemaRef:g,filters:C.filter_keys.map(_=>({key:_,label:n[_]}))});return;default:return}})}),r}function E_(e,t){const n=e.filters.keyLabelMap;return{edges:z_(e.panels.list,t,n),edgeNodes:[]}}function tu(e,t,n){return e*t+e*n}function $_(e,t,n){return e*t+(e-1)*n}const dr=25,Ni=40,nu=25,qi=350,L_=150,O_=150,ru=150,iu=300,pr=40,au=25,P_=300;function B_(e,t){const n=x.keyBy(t,a=>a.id),r=[];return e.current.forEach((a,o)=>{a.panelIDs.forEach((l,u)=>{const c=tu(u,pr,au)+Ni,d=n[l];if(!d){r.push({id:l,_node_type:"panel",parentNode:a.id,data:{label:`!: ${l}`},position:{x:dr,y:c},sourcePosition:Me.Position.Right,targetPosition:Me.Position.Left,style:{width:iu,height:pr}});return}const f=d.title.trim()?`${d.title}`:d.viz.type;r.push({id:d.id,_node_type:"panel",parentNode:a.id,data:{label:f},position:{x:dr,y:c},sourcePosition:Me.Position.Right,targetPosition:Me.Position.Left,style:{width:iu,height:pr}})})}),r}const V_={[j.Division]:"Div",[j.Modal]:"Modal",[j.Tabs]:"Tabs"},N_=Wl;function q_(e){return e.current.map((n,r)=>{const a=$_(n.panelIDs.length,pr,au)+Ni+nu;let o=[];return n.type===j.Tabs&&(o=n.config.tabs.map(u=>u.view_id)),{id:n.id,_node_type:"view-root",_view_type:n.type,_view_level:0,_sub_view_ids:[],_tab_view_ids:o,data:{label:`${V_[n.type]}:${n.name}`},position:{x:0,y:0},sourcePosition:Me.Position.Right,targetPosition:Me.Position.Left,className:"light",style:{backgroundColor:N_[n.type],width:qi,height:a}}})}function F_(e){const t=x.keyBy(e,n=>n.id);e.forEach(n=>{n._node_type!=="view-root"||n._view_type!==j.Tabs||n._tab_view_ids.forEach(r=>{t[r].parentNode=n.id})})}function G_(e){const t=q_(e.views);F_(t);const n=B_(e.views,e.panels.list);return[...t,...n]}function W_({nodeMap:e,nodes:t,edges:n}){t.forEach(r=>{r._node_type!=="view-root"||r._view_type!==j.Tabs||(r.sourcePosition=Me.Position.Bottom,r.style.width=qi+dr*2,r.style.height=nu+r._tab_view_ids.reduce((a,o)=>{const l=e[o];l.position.y=a,l.position.x=dr;const u=l.style.height;return a+u+20},Ni))})}function j_({nodeMap:e,nodes:t,edges:n}){n.filter(r=>r.label==="Open View").forEach(r=>{const a=e[r.source],o=e[r.target];if(!a||!o||!a.parentNode)return;const l=e[a.parentNode];l._node_type!=="view-root"||o._node_type!=="view-root"||(o._view_level+=1+l._view_level,l._sub_view_ids.push(o.id))}),t.sort((r,a)=>r._node_type==="view-root"&&a._node_type==="view-root"?r._view_level-a._view_level:r._node_type!=="view-root"&&a._node_type!=="view-root"?0:r._node_type==="view-root"?-1:1)}function R_({nodeMap:e,nodes:t,edges:n}){const r={};n.forEach(a=>{if(a.label!=="Open View")return;const o=e[a.source],l=e[a.target];if(o&&l&&o.parentNode){const u=e[o.parentNode],c=u.position.x,d=Number(x.get(l,"style.height",0)),f=Number(u.style.width);l.position.x=c+f+P_,u._view_level===0&&l._sub_view_ids.length===0&&(o.sourcePosition=Me.Position.Left,l.targetPosition=Me.Position.Right,l.position.x*=-1);const g=l.position.x,m=x.get(r,g,0);l.position.y=m,r[g]=m+d+ru}})}function Y_({nodeMap:e,nodes:t,edges:n}){const r=new Set,a=new Set;n.forEach(l=>{r.add(l.source),a.add(l.target)}),t.filter(l=>l._node_type!=="view-root"||l.id==="Main"||l.parentNode?!1:!r.has(l.id)&&!a.has(l.id)).forEach((l,u)=>{l.position.x=tu(u,qi,O_),l.position.y=0-L_-ru})}function Q_({nodeMap:e,nodes:t,edges:n}){const r={nodeMap:e,nodes:t,edges:n};return Y_(r),j_(r),W_(r),R_(r),{nodes:t,edges:n}}function U_(e){const t=G_(e),n=x.keyBy(t,c=>c.id),{edges:r,edgeNodes:a}=E_(e,n),o=[...t,...a],l=x.keyBy(o,c=>c.id),u={edges:x.uniqBy(r,c=>c.id),nodes:o,nodeMap:l};return Q_(u)}const wM="",Fi={"builtin:op:open-link":i(s.ThemeIcon,{color:"blue",size:20,radius:"xl",children:i(E.IconCircleDashed,{size:14})}),"builtin:op:set_filter_values":i(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:i(E.IconCircleDot,{size:14})}),"builtin:op:clear_filter_values":i(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:i(E.IconCircleOff,{size:14})})};function K_(e){const t=[];return e.forEach(n=>{switch(n.schemaRef){case"builtin:op:open-link":t.push({key:n.urlTemplate,icon:Fi[n.schemaRef],text:p(s.Group,{spacing:4,children:[i(s.Text,{children:"Open: "}),i(s.Text,{color:"dimmed",children:n.shortURLTemplate})]})});return;case"builtin:op:set_filter_values":n.filters.forEach(({key:r,label:a})=>{t.push({key:n.schemaRef+r,icon:Fi[n.schemaRef],text:i(s.Group,{spacing:4,children:p(s.Text,{children:["Set Filter: ",a]})})})});return;case"builtin:op:clear_filter_values":n.filters.forEach(({key:r,label:a})=>{t.push({key:n.schemaRef+r,icon:Fi[n.schemaRef],text:i(s.Group,{spacing:4,children:p(s.Text,{children:["Clear Filter: ",a]})})})});return}}),t}const X_=y.memo(({data:e,isConnectable:t,sourcePosition:n=Me.Position.Right,targetPosition:r=Me.Position.Left,...a})=>{const o=y.useMemo(()=>K_(e.interactions),[e.interactions]);return p(B,{children:[i(Me.Handle,{type:"target",position:r,isConnectable:t}),i(s.Box,{sx:{position:"absolute",top:0,right:0},children:i(D.ChevronsUpRight,{size:12})}),p(s.HoverCard,{shadow:"xl",withinPortal:!0,children:[i(s.HoverCard.Target,{children:i(s.Text,{children:e.label})}),i(s.HoverCard.Dropdown,{children:i(s.List,{spacing:"xs",size:"sm",center:!0,children:o.map(l=>i(s.List.Item,{icon:l.icon,children:l.text},l.key))})})]}),i(Me.Handle,{type:"source",position:n,isConnectable:t})]})}),CM="",J_={interaction:X_},Z_=k.observer(()=>{const e=ye(),{edges:t,nodes:n}=U_(e);return p(Me,{nodes:n,edges:t,onNodesChange:x.noop,onEdgesChange:x.noop,onConnect:x.noop,className:"interactions-viewer",fitView:!0,nodeTypes:J_,children:[i(Me.MiniMap,{}),i(Me.Controls,{}),i(Me.Background,{})]})}),H_=k.observer(({opened:e,close:t})=>i(s.Modal,{size:"96vw",opened:e,onClose:t,title:"Interactions",trapFocus:!0,onDragStart:n=>{n.stopPropagation()},styles:{body:{height:"90vh"},content:{transform:"none !important"}},zIndex:300,children:i(Z_,{})})),ek={"> 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 tk({onClick:e,name:t,active:n,openSettings:r}){return p(s.Box,{sx:{position:"relative"},children:[i(s.UnstyledButton,{sx:a=>({display:"block",width:"100%",padding:a.spacing.xs,borderRadius:0,position:"relative",color:a.black,"&:hover":{backgroundColor:a.colors.gray[0]},backgroundColor:n?a.colors.gray[2]:"transparent"}),children:i(s.Group,{sx:{width:"calc(100% - 28px)"},onClick:e,children:i(s.Text,{size:"sm",children:t})})}),n&&i(s.Tooltip,{label:"Edit",position:"right",withinPortal:!0,children:i(s.ActionIcon,{onClick:r,variant:"light",color:"blue",sx:{position:"absolute",top:0,bottom:0,height:"100%",right:0,zIndex:0,borderRadius:0},children:i(E.IconAdjustments,{size:16})})})]})}const nk=k.observer(()=>{const e=ue(),t=le(),n=y.useCallback(a=>()=>t.views.setIDOfVIE(a),[t]),r=a=>{e.editor.open(["_VIEWS_",a])};return p(s.Box,{sx:{position:"relative"},children:[t.views.options.map(a=>i(tk,{active:t.views.idOfVIE===a.value,name:a.label,onClick:n(a.value),openSettings:()=>r(a.value)},a.value)),i(s.Divider,{variant:"dashed"}),i(s.Button,{variant:"subtle",rightIcon:i(E.IconPlus,{size:14}),size:"sm",px:"xs",color:"blue",onClick:t.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"space-between"}},children:"Add a View"})]})}),rk=k.observer(()=>{const e=ue(),t=le(),n=()=>{if(!t.queries.firstID){e.editor.open(["_QUERIES_",""]);return}e.editor.open(["_QUERIES_",t.queries.firstID])},r=()=>{if(!t.filters.firstID){e.editor.open(["_FILTERS_",""]);return}e.editor.open(["_FILTERS_",t.filters.firstID])},[a,o]=y.useState(!1),l=()=>o(!0),u=()=>o(!1);return p(s.Navbar,{p:0,width:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},zIndex:299,children:[p(s.Navbar.Section,{children:[p(s.Group,{grow:!0,spacing:0,sx:{...ek,button:{borderWidth:0,borderBottomWidth:1,borderColor:"#e9ecef"}},children:[i(s.Tooltip,{label:"Filters",withinPortal:!0,children:i(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:r,children:i(E.IconFilter,{size:18})})}),i(s.Tooltip,{label:"Queries",withinPortal:!0,children:i(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:n,children:i(E.IconDatabase,{size:18})})}),i(s.Tooltip,{label:"Interactions Viewer",withinPortal:!0,children:i(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:l,children:i(E.IconLink,{size:18})})})]}),i(H_,{opened:a,close:u})]}),i(s.Navbar.Section,{py:5,sx:{borderBottom:"1px solid #eee"},children:i(s.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Views"})}),i(s.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:i(nk,{})}),i(s.Navbar.Section,{children:i(s.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:i(s.Button,{size:"xs",leftIcon:i(E.IconSettings,{size:20}),onClick:()=>e.editor.open([]),children:"Settings"})})})]})}),ik=k.observer(function({config:t}){return p(B,{children:[i(s.Checkbox,{checked:t.default_value,onChange:n=>t.setDefaultValue(n.currentTarget.checked),label:"Default Checked"}),i(pi,{label:"Description",value:t.description,onChange:t.setDescription,styles:{root:{flexGrow:1,minHeight:"400px"}}})]})}),ak=[{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"}],sk=k.observer(function({config:t}){return p(B,{children:[p(s.Group,{children:[i(s.Checkbox,{checked:t.required,onChange:n=>t.setRequired(n.currentTarget.checked),label:"Required"}),i(s.Checkbox,{checked:t.clearable,onChange:n=>t.setClearable(n.currentTarget.checked),disabled:t.max_days>0,label:"Clearable"}),i(s.Checkbox,{checked:t.allowSingleDateInRange,onChange:n=>t.setAllowSingleDateInRange(n.currentTarget.checked),label:"Allow choosing 1 day"})]}),i(s.Select,{data:ak,label:"Display Format",value:t.inputFormat,onChange:t.setInputFormat}),i(Jo,{label:"Default Value",config:t,value:t.default_value,onChange:t.setDefaultValue}),i(s.NumberInput,{label:"Max Days",description:p(s.Group,{position:"apart",children:[i(s.Text,{children:"Set 0 to disable."}),p(s.Group,{spacing:4,children:[i(s.Text,{children:"This feature requires"}),i(s.Text,{color:"blue",children:"Clearable"}),i(s.Text,{children:"to be checked"})]})]}),min:0,value:t.max_days,onChange:t.setMaxDays,hideControls:!0})]})}),Gi=k.observer(({value:e,onChange:t})=>{const n=ue(),r=le(),a=y.useMemo(()=>r.queries.options,[r.queries.current]),o=a.length===0,l=u=>{n.editor.setPath(["_QUERIES_",u])};return i(s.Select,{label:p(s.Group,{position:"apart",children:[i(s.Text,{children:"Use query data as options"}),e&&i(s.Button,{size:"xs",leftIcon:i(E.IconArrowCurveRight,{size:16}),variant:"subtle",color:"blue",onClick:()=>l(e),children:"Open this query"})]}),data:a,value:e,onChange:t,allowDeselect:!1,clearable:!0,sx:{flexGrow:1},disabled:o,error:o?"You need to add a query in Data Settings":void 0,styles:{label:{display:"block"}}})}),ok=`
|
|
504
504
|
// row
|
|
505
505
|
{
|
|
506
506
|
label: string;
|
|
507
507
|
value: string;
|
|
508
508
|
description?: string; // optional
|
|
509
509
|
}
|
|
510
|
-
`,
|
|
510
|
+
`,su=()=>{const[e,t]=y.useState(!1);return p(B,{children:[i(s.Button,{variant:"subtle",compact:!0,onClick:()=>t(n=>!n),children:e?"Close":"Click to see expected data structure"}),i(s.Collapse,{in:e,children:i(Mt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:ok})})]})},lk=k.observer(function({config:t}){const n=()=>{t.addStaticOption({label:"",value:""})},r=t.static_options,a=[...r];return p(B,{children:[i(s.Checkbox,{checked:t.required,onChange:o=>t.setRequired(o.currentTarget.checked),label:"Required"}),i(s.TextInput,{label:"Width",description:"At least 160px",value:t.min_width,onChange:o=>t.setMinWidth(o.currentTarget.value),placeholder:"default: 200px"}),i(s.Divider,{label:"Configure options",labelPosition:"center"}),p(s.Stack,{spacing:10,sx:{position:"relative",minHeight:"50px"},children:[t.usingQuery&&p(B,{children:[i(s.Overlay,{opacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),i(s.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:i(s.Text,{color:"white",size:16,children:"Using query"})})]}),r.length>0&&i(s.MultiSelect,{label:"Default Selection",data:a,value:[...t.default_value],onChange:t.setDefaultValue}),r.map((o,l)=>p(s.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[i(s.TextInput,{label:"Label",required:!0,value:t.static_options[l].label,onChange:u=>{t.static_options[l].setLabel(u.currentTarget.value)},sx:{flexGrow:1}}),i(s.TextInput,{label:"Value",required:!0,value:t.static_options[l].value,onChange:u=>{t.static_options[l].setValue(u.currentTarget.value)},sx:{flexGrow:1}}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>t.removeStaticOption(l),sx:{position:"absolute",top:28,right:5},children:i(D.Trash,{size:16})})]},l)),i(s.Button,{mt:10,size:"xs",color:"blue",leftIcon:i(D.PlaylistAdd,{size:20}),onClick:n,sx:{width:"50%"},mx:"auto",children:"Add an Option"})]}),i(s.Divider,{label:"Or fetch options from database",labelPosition:"center"}),i(s.NumberInput,{value:t.default_selection_count,onChange:t.setDefaultSelectionCount,label:"Select first N options by default"}),i(Gi,{value:t.options_query_id,onChange:t.setOptionsQueryID}),i(su,{})]})}),uk=k.observer(function({config:t}){const n=()=>{t.addStaticOption({label:"",value:""})},r=t.static_options,a=[{label:"No default selection",value:""},...r];return p(B,{children:[i(s.Checkbox,{checked:t.required,onChange:o=>t.setRequired(o.currentTarget.checked),label:"Required"}),i(s.TextInput,{label:"Width",value:t.width,onChange:o=>t.setWidth(o.currentTarget.value),placeholder:"200px"}),i(s.Divider,{label:"Configure options",labelPosition:"center"}),p(s.Stack,{spacing:10,sx:{position:"relative",minHeight:"50px"},children:[t.usingQuery&&p(B,{children:[i(s.Overlay,{opacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),i(s.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:i(s.Text,{color:"white",size:16,children:"Using query"})})]}),r.length>0&&i(s.Select,{label:"Default Selection",data:a,value:t.default_value,onChange:t.setDefaultValue}),r.map((o,l)=>p(s.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[i(s.TextInput,{label:"Label",required:!0,value:t.static_options[l].label,onChange:u=>{t.static_options[l].setLabel(u.currentTarget.value)},sx:{flexGrow:1}}),i(s.TextInput,{label:"Value",required:!0,value:t.static_options[l].value,onChange:u=>{t.static_options[l].setValue(u.currentTarget.value)},sx:{flexGrow:1}}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>t.removeStaticOption(l),sx:{position:"absolute",top:28,right:5},children:i(D.Trash,{size:16})})]},l)),i(s.Button,{size:"xs",color:"blue",leftIcon:i(D.PlaylistAdd,{size:20}),onClick:n,sx:{width:"50%"},mx:"auto",children:"Add an Option"})]}),i(s.Divider,{label:"Or fetch options from database",labelPosition:"center"}),i(s.Checkbox,{checked:t.default_selection_count===1,onChange:o=>t.setDefaultSelectionCount(o.currentTarget.checked?1:0),label:"Select the first option by default"}),i(Gi,{value:t.options_query_id,onChange:t.setOptionsQueryID}),i(su,{})]})}),ck=k.observer(function({config:t}){return p(B,{children:[i(s.TextInput,{label:"Default Value",value:t.default_value,onChange:n=>{t.setDefaultValue(n.currentTarget.value)}}),i(s.Checkbox,{checked:t.required,onChange:n=>t.setRequired(n.currentTarget.checked),label:"Required"})]})}),dk=`
|
|
511
511
|
// row
|
|
512
512
|
{
|
|
513
513
|
label: string;
|
|
@@ -515,7 +515,7 @@ Check the top-level render call using <`+V+">.")}return z}}function Tu(S,z){{if(
|
|
|
515
515
|
parent_value: string;
|
|
516
516
|
description?: string;
|
|
517
517
|
}
|
|
518
|
-
`,ck=()=>{const[e,t]=y.useState(!1);return p(B,{children:[i(s.Button,{variant:"subtle",compact:!0,onClick:()=>t(n=>!n),children:e?"Close":"Click to see expected data structure"}),i(s.Collapse,{in:e,children:i(Mt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:uk})})]})},dk=k.observer(function({config:t}){return p(B,{children:[i(s.Checkbox,{checked:t.required,onChange:n=>t.setRequired(n.currentTarget.checked),label:"Required"}),i(s.TextInput,{label:"Min-width",value:t.min_width,onChange:n=>t.setMinWidth(n.currentTarget.value),placeholder:"200px"}),i(s.Divider,{label:"Fetch options from database",labelPosition:"center"}),i(s.Checkbox,{checked:t.treeCheckStrictly,onChange:n=>t.setTreeCheckStrictly(n.currentTarget.checked),label:"Parent and children nodes are not associated"}),i(s.NumberInput,{value:t.default_selection_count,onChange:t.setDefaultSelectionCount,label:"Select first N options by default"}),i(Gi,{value:t.options_query_id,onChange:t.setOptionsQueryID}),i(ck,{})]})}),pk=k.observer(function({filter:t}){return p(s.Box,{sx:{maxWidth:"480px"},children:[i(s.Text,{pt:"0",pb:"md",color:"gray",children:"Config"}),i(Mt.Prism,{mt:22,language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(t,null,4)})]})}),hk={select:ok,"multi-select":sk,"tree-select":dk,"text-input":lk,checkbox:nk,"date-range":ik},fk=[{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"}],gk=k.observer(function({filter:t}){const n=le(),r=y.useMemo(()=>hk[t.type],[t.type]);return p(s.Group,{grow:!0,spacing:20,align:"top",children:[p(s.Box,{sx:{maxWidth:"600px"},children:[i(s.Text,{pb:"md",color:"gray",children:"Edit"}),p(s.Stack,{children:[p(s.Group,{noWrap:!0,children:[i(s.NumberInput,{label:"Placement Order",required:!0,value:t.order,onChange:t.setOrder,hideControls:!0,sx:{flexGrow:"1 !important"}}),t.auto_submit_supported&&i(s.Checkbox,{label:"Submit automatically",checked:t.auto_submit,onChange:a=>t.setAutoSubmit(a.currentTarget.checked),mt:22})]}),i(s.MultiSelect,{label:"Visible in...",data:n.views.options,value:[...t.visibleInViewsIDs],onChange:t.setVisibleInViewsIDs}),i(s.TextInput,{label:"Key",placeholder:"A unique key to refer",required:!0,value:t.key,onChange:a=>{t.setKey(a.currentTarget.value)}}),i(s.TextInput,{label:"Label",placeholder:"Label for this field",required:!0,value:t.label,onChange:a=>{t.setLabel(a.currentTarget.value)}}),i(s.Select,{label:"Widget",data:fk,required:!0,value:t.type,onChange:t.setType}),i(r,{config:t.config})]})]}),i(pk,{filter:t})]})}),mk=k.observer(({id:e})=>{const t=Ge.useModals(),n=ue(),r=le();if(e==="")return null;const a=r.filters.findByID(e);if(!a)return p(s.Text,{size:14,children:["Filter by ID[",e,"] is not found"]});const o=()=>{n.editor.setPath(["_FILTERS_",""])},l=()=>{t.openConfirmModal({title:"Delete this filter?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.filters.removeByID(e),o()},confirmProps:{color:"red"},zIndex:320})};return p(s.Stack,{sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",pb:30,children:[i(s.Group,{position:"right",pt:10,children:i(s.Button,{size:"xs",color:"red",leftIcon:i(D.Trash,{size:16}),onClick:l,children:"Delete this filter"})}),i(s.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:i(gk,{filter:a})})]})}),yk=k.observer(()=>{const e=le(),[t,n]=y.useState(()=>JSON.stringify(e.mock_context.current,null,4)),r=()=>{try{e.mock_context.replace(JSON.parse(t))}catch(o){_n.showNotification({title:"Failed",message:o.message,color:"red"})}},a=y.useMemo(()=>{try{return JSON.stringify(JSON.parse(t))!==JSON.stringify(e.mock_context.current)}catch{return!1}},[t,e.mock_context.current]);return p(s.Stack,{sx:{border:"1px solid #eee",borderLeft:"none",borderRight:"none",flexGrow:1,maxWidth:"unset"},children:[i(s.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:i(s.Text,{weight:500,children:"Mock Context"})}),p(s.Group,{grow:!0,px:"md",pb:"md",pt:0,sx:{flexGrow:1,position:"relative",alignItems:"flex-start"},children:[p(s.Stack,{spacing:10,sx:{maxWidth:"unset !important"},children:[i(s.Text,{children:"A valid json string is required"}),i(s.JsonInput,{validationError:"Invalid json",formatOnBlur:!0,autosize:!0,minRows:30,value:t,onChange:n,sx:{flexGrow:1}})]}),i(s.ActionIcon,{mr:5,variant:"filled",color:"blue",sx:{position:"absolute",right:12,top:0},disabled:!a,onClick:r,children:i(D.DeviceFloppy,{size:20})})]})]})}),bk=k.observer(()=>{const{panel:e}=rt();return i(pi,{label:"Description",value:e.description,onChange:e.setDescription,styles:{root:{flexGrow:1}}})}),vk=k.observer(()=>{const{panel:e}=rt(),{style:t}=e;return p(B,{children:[i(s.Divider,{mb:-10,label:"Style",labelPosition:"center",variant:"dashed"}),p(s.Stack,{spacing:20,children:[p(s.Group,{grow:!0,align:"top",children:[i(s.NumberInput,{label:"Width",min:1,max:36,step:1,precision:0,rightSection:i(s.Text,{size:12,children:"of 36 columns"}),styles:{rightSection:{width:"110px"}},value:e.layout.w,onChange:n=>{n&&e.layout.setWidth(n)}}),i(s.NumberInput,{label:"Height",rightSection:i(s.Text,{size:12,children:"px"}),styles:{rightSection:{width:"40px"}},value:e.layout.h,onChange:n=>{n&&e.layout.setHeight(n)}})]}),i(s.Switch,{label:"Border",checked:t.border.enabled,onChange:n=>t.border.setEnabled(n.currentTarget.checked)})]})]})}),xk=k.observer(()=>{const{panel:e}=rt(),{title:t,setTitle:n}=e,[r,a]=ke.useInputState(t),o=t!==r,l=y.useCallback(()=>{o&&n(r)},[o,r]);return y.useEffect(()=>{a(t)},[t]),i(s.TextInput,{value:r,onChange:a,label:p(s.Group,{children:[i(s.Text,{children:"Panel Title"}),i(s.ActionIcon,{variant:"subtle",color:"blue",disabled:!o,onClick:l,children:i(D.DeviceFloppy,{size:20})})]}),styles:{label:{display:"block",paddingBottom:"4px"}}})});function wk(){return p(s.Stack,{sx:{height:"100%"},children:[i(vk,{}),i(s.Divider,{label:"Info",labelPosition:"center",variant:"dashed"}),i(xk,{}),i(bk,{})]})}const Ck={width:"fit-content",minWidth:"100%",tableLayout:"fixed",tr:{width:"fit-content"},th:{position:"relative"},"th, td":{wordBreak:"break-word"},".resizer":{position:"absolute",right:0,top:"50%",transform:"translateY(-50%)",cursor:"col-resize",userSelect:"none",touchAction:"none"},".resizer.isResizing":{color:"#228be6",opacity:"1"},"@media (hover: hover)":{".resizer":{opacity:"0"},"*:hover > .resizer":{color:"#228be6",opacity:"1"}}};function au({data:e}){const t=y.useMemo(()=>{if(!Array.isArray(e)||e.length===0)return[];const r=et.createColumnHelper();return Object.keys(e[0]).map(a=>r.accessor(a,{cell:o=>o.getValue()}))},[e]),n=et.useReactTable({data:e,columns:t,columnResizeMode:"onChange",getCoreRowModel:et.getCoreRowModel()});return e.length===0?i(s.Box,{sx:{height:"5em"}}):i(Ne,{children:p(s.Table,{sx:Ck,children:[i("thead",{children:n.getHeaderGroups().map(r=>i("tr",{children:r.headers.map(a=>p("th",{style:{width:a.getSize()},children:[a.isPlaceholder?null:et.flexRender(a.column.columnDef.header,a.getContext()),i(s.ActionIcon,{onMouseDown:a.getResizeHandler(),onTouchStart:a.getResizeHandler(),className:`resizer ${a.column.getIsResizing()?"isResizing":""}`,children:i(D.ArrowBarToRight,{})})]},a.id))},r.id))}),i("tbody",{children:n.getRowModel().rows.map(r=>i("tr",{children:r.getVisibleCells().map(a=>i("td",{children:i(Ne,{children:et.flexRender(a.column.columnDef.cell,a.getContext())})},a.id))},r.id))})]})})}const Sk=({queryID:e})=>{const t=ye(),{state:n,error:r}=t.getDataStuffByID(e),a=y.useMemo(()=>t.queries.findByID(e),[t,e]);return n==="loading"?null:r?i(s.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:r}):a!=null&&a.stateMessage?i(s.Text,{color:"gray",align:"center",children:a.stateMessage}):null},Wi=k.observer(function({id:t,moreActions:n=null}){const r=ye(),{data:a,state:o}=r.getDataStuffByID(t),l=o==="loading",u=()=>{r.queries.refetchDataByQueryID(t)},c=()=>{r.queries.downloadDataByQueryID(t)},d=y.useMemo(()=>Array.isArray(a)?a.slice(0,10):[],[a]),f=!Array.isArray(a)||a.length===0;return p(s.Stack,{sx:{border:"1px solid #eee"},children:[p(s.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[p(s.Group,{position:"left",children:[i(s.Text,{weight:500,children:"Preview Data"}),a.length>10&&p(s.Text,{size:"sm",color:"gray",children:["Showing 10 rows of ",a.length]})]}),p(s.Group,{pr:15,children:[n,i(s.ActionIcon,{variant:"subtle",color:"blue",disabled:l,onClick:u,children:i(D.Refresh,{size:16})}),i(s.ActionIcon,{variant:"subtle",color:"blue",disabled:l||f,onClick:c,children:i(D.Download,{size:16})})]})]}),p(s.Box,{sx:{position:"relative",overflow:"auto"},children:[i(s.LoadingOverlay,{visible:l}),i(Sk,{queryID:t}),i(au,{data:d})]})]})}),_k=k.observer(function(){const t=ue(),n=le(),{panel:r}=rt(),[a,o]=y.useState(!1),l=u=>{t.editor.setPath(["_QUERIES_",u])};return p(B,{children:[i(s.Drawer,{opened:a,onClose:()=>o(!1),title:"Choose queries",padding:"xl",size:500,zIndex:320,children:i(s.Checkbox.Group,{value:[...r.queryIDs],onChange:r.setQueryIDs,children:i(s.Stack,{spacing:"lg",children:n.queries.options.map(u=>i(s.Checkbox,{label:u.label,value:u.value},u.value))})})}),p(s.Stack,{spacing:6,children:[i(s.Group,{position:"right",children:i(s.Button,{variant:"light",size:"sm",leftIcon:i(E.IconLine,{size:16}),onClick:()=>o(!0),children:"Click me to choose queries for this panel"})}),r.queryIDs.length===1&&i(Wi,{id:r.queryIDs[0],moreActions:i(s.Tooltip,{label:"Open this query",children:i(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>l(r.queryIDs[0]),children:i(E.IconArrowCurveRight,{size:16})})})}),r.queryIDs.length>1&&p(s.Tabs,{defaultValue:r.queryIDs[0],children:[i(s.Tabs.List,{children:r.queries.map(u=>i(s.Tabs.Tab,{value:u.id,children:u.name},u.id))}),r.queries.map(u=>i(s.Tabs.Panel,{value:u.id,children:i(Wi,{id:u.id,moreActions:i(s.Tooltip,{label:"Open this query",children:i(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>l(u.id),children:i(E.IconArrowCurveRight,{size:16})})})})},u.id))]})]})]})}),kk=k.observer(()=>{const{panel:e}=Ct();return i(Ne,{children:i(s.Box,{sx:{height:"100%",flexGrow:0,flexShrink:0,width:"600px"},children:p(s.Stack,{mt:24,spacing:5,sx:{width:"600px",height:"450px",background:"transparent",borderRadius:"5px",border:"1px solid #e9ecef",borderWidth:e.style.border.enabled?"1px":"0px"},children:[p(s.Group,{position:"apart",noWrap:!0,sx:{flexGrow:0,flexShrink:0},children:[i(s.Group,{children:i($i,{})}),i(s.Group,{grow:!0,position:"center",children:i(s.Text,{lineClamp:1,weight:"bold",children:e.title})}),i(s.Group,{position:"right",spacing:0,sx:{height:"28px"}})]}),i(s.Group,{px:5,pb:5,sx:{flexGrow:1,".panel-viz-section":{height:"calc(100% - 28px)"}},children:i(Li,{panel:e})})]})})})}),ji={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 Tk{constructor(t){q(this,"panel");q(this,"selected");this.panel=t,te.makeAutoObservable(this,{},{deep:!1,autoBind:!0})}get variables(){return this.panel.variables}addNew(){const t=this.panel.variables.filter(n=>n.name.startsWith(ji.name)).length;this.panel.addVariable(x.cloneDeep({...ji,name:`${ji.name}${t||""}`})),this.selected=x.last(this.panel.variables)}select(t){this.selected=t}remove(t){this.selected===t&&(this.selected=void 0);const n=this.panel.variables.indexOf(t);if(this.panel.removeVariable(t),!this.selected&&!x.isEmpty(this.panel.variables)){const r=Math.min(this.panel.variables.length-1,n);this.selected=this.panel.variables[r]}}}function Dk(){const{panel:e}=rt();return Q.useCreation(()=>new Tk(e),[e])}const su=s.createStyles(e=>({root:{height:"100%",overflow:"hidden",".var-list-container":{"& > *":{height:"100%"},width:250,height:"100%"},".var-list-actions":{height:"fit-content",flexShrink:0,width:"100%"},".var-list":{flex:"1 1 auto",overflow:"auto",minHeight:0,"& > *":{flex:"0 0 auto"}}},config:{height:"100%",overflow:"auto",paddingRight:10}})),Ik=y.forwardRef(function({value:t,onChange:n,data:r,withStyle:a=!0},o){const l=(u,c)=>{const d=x.cloneDeep(t);x.set(d,u,c),n(d)};return p(s.Box,{px:"sm",py:"md",ref:o,children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(s.TextInput,{label:"Name",required:!0,value:t.name,onChange:u=>l("name",u.currentTarget.value)}),i(W,{label:"Data Field",required:!0,value:t.data_field,onChange:u=>l("data_field",u)})]}),i(Qn,{label:"Aggregation",value:t.aggregation,onChange:u=>l("aggregation",u)}),t.aggregation.type!=="custom"&&p(B,{children:[i(s.Divider,{my:"xs",label:"Format",labelPosition:"center"}),i(We,{value:t.formatter,onChange:u=>l("formatter",u)})]}),a&&i(Js,{value:t,onChange:n})]})}),Mk=e=>{const{uiModel:t}=e;return i(s.Stack,{className:"var-list",children:t.variables.map(n=>i(s.Button,{variant:t.selected===n?"filled":"subtle",color:"gray",onClick:()=>t.select(n),children:n.name},n.name))})},Ak=k.observer(Mk),zk=({variable:e,data:t})=>i(s.Group,{style:{minHeight:0,height:"calc(100% - 68px)"},children:i(s.Paper,{withBorder:!0,p:"md",children:Zs(e,t)})}),Ek=k.observer(zk),$k=e=>{const t=Q.useCreation(()=>AS(e.variable),[e.variable]),{classes:n}=su(),{data:r}=rt();return p(s.Group,{style:{height:"100%"},align:"start",children:[p(s.Stack,{"data-testid":"variable-editor",align:"stretch",className:n.config,children:[p(s.Group,{position:"right",children:[i(s.ActionIcon,{variant:"filled",disabled:!t.changed,color:"primary",onClick:t.commit,children:i(E.IconDeviceFloppy,{size:18})}),i(s.ActionIcon,{color:"red",onClick:()=>e.uiModel.remove(e.variable),children:i(E.IconTrash,{size:18})})]}),i(Ik,{value:b.getSnapshot(t.copy),onChange:t.update,data:r})]}),i(Ek,{variable:b.getSnapshot(t.copy),data:r})]})},Lk=k.observer($k),Ok=()=>{const e=Dk(),{classes:t}=su();return p(s.Group,{className:t.root,noWrap:!0,align:"start",children:[i(s.Paper,{withBorder:!0,p:"md",className:"var-list-container",children:p(s.Stack,{justify:"space-between",children:[i(s.Box,{className:"var-list-actions",children:i(s.Button,{variant:"light",size:"sm",onClick:e.addNew,fullWidth:!0,children:"Add Variable"})}),i(Ak,{uiModel:e})]})}),e.selected?i(B,{children:i(Lk,{uiModel:e,variable:e.selected})}):i("span",{children:"Select or create a new variable on right side"})]})},Pk=k.observer(Ok);function Bk(){const{vizManager:e}=y.useContext(ct);return y.useMemo(()=>{const t=e.availableVizList.map(n=>({value:n.name,label:n.displayName??n.name,group:n.displayGroup??""}));return x.orderBy(t,[n=>n.group,n=>n.label],["asc","asc"])},[e])}const Vk=k.observer(({value:e,submit:t})=>{const[n,r]=ke.useInputState(e);y.useEffect(()=>{r(e)},[e]);const a=Bk(),o=e!==n;return i(s.Select,{label:"Visualization",value:n,searchable:!0,onChange:r,data:a,rightSection:i(s.ActionIcon,{disabled:!o,onClick:()=>t(n),children:i(D.DeviceFloppy,{size:20})}),maxDropdownHeight:600})}),ou=[];function Nk(e,t){try{return e.resolveComponent(t).createConfig()}catch{return null}}function qk(){const{data:e,panel:{variables:t,viz:n,title:r,queryIDs:a,description:o,setDescription:l,setTitle:u,addQueryID:c,removeQueryID:d,id:f}}=rt(),{vizManager:h}=y.useContext(ct),g={title:r,description:o,viz:n,queryIDs:a,id:f},m={setDescription:l,addQueryID:c,removeQueryID:d,setTitle:u},C=Dl(g);try{return h.resolveComponent(g.viz.type),i(ar,{configure:C,children:i(PS,{variables:t,setVizConf:n.setConf,panel:g,panelInfoEditor:m,vizManager:h,data:e})})}catch(w){return console.info(x.get(w,"message")),null}}const Fk=k.observer(()=>{const{data:e,panel:{viz:t}}=rt(),{vizManager:n}=y.useContext(ct),r=y.useCallback(d=>{if(d===t.type)return;const f=Nk(n,d);t.setType(d),t.setConf(f||{})},[t.type]),a=d=>{try{t.setConf(JSON.parse(d))}catch(f){console.error(f)}},o=y.useMemo(()=>{var d;return(d=ou.find(f=>f.value===t.type))==null?void 0:d.Panel},[t.type,ou]),l=qk(),u=o?y.createElement(o,{data:e,conf:t.conf,setConf:t.setConf}):null,c=l||u;return p(s.Stack,{align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[i(Vk,{submit:r,value:t.type}),p(Ne,{children:[i(s.Stack,{pb:10,sx:{flexGrow:1,maxHeight:"100%",overflow:"auto"},children:c}),!c&&i(s.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(t.conf,null,2),onChange:a})]})]})}),Gk=k.observer(({panel:e,sourceViewID:t})=>{const n=le(),[r,a]=y.useState(t);y.useEffect(()=>{a(t)},[t]);const[o,{open:l,close:u}]=ke.useDisclosure(!1),c=()=>{e.moveToView(t,r),u()};return p(B,{children:[i(s.Button,{size:"xs",variant:"subtle",color:"blue",onClick:l,leftIcon:i(E.IconBoxMultiple,{size:14}),children:"Move into Another View"}),i(s.Modal,{opened:o,onClose:u,title:"Move panel into another view",zIndex:320,children:p(s.Stack,{sx:{maxHeight:"calc(100vh - 185px)",overflow:"hidden"},children:[i(s.Radio.Group,{value:r,onChange:a,pb:10,sx:{flexGrow:1,maxHeight:"calc(100vh - 185px - 30px)",overflow:"auto"},children:i(s.Stack,{spacing:"xs",children:n.views.options.map(d=>i(s.Radio,{value:d.value,label:d.label},d.value))})}),p(s.Group,{noWrap:!0,position:"apart",sx:{flexGrow:0,flexShrink:0},children:[i(s.Button,{size:"xs",color:"red",leftIcon:i(E.IconX,{size:14}),onClick:u,children:"Cancel"}),i(s.Button,{size:"xs",color:"blue",leftIcon:i(E.IconDeviceFloppy,{size:14}),onClick:c,disabled:r===t,children:"Confirm"})]})]})})]})}),Wk={root:{flexGrow:1,width:"100%",overflow:"hidden"},panel:{width:"100%",height:"calc(100% - 44px)",padding:10,overflow:"scroll"}},lu=({children:e})=>p(s.Group,{noWrap:!0,grow:!0,position:"left",spacing:20,sx:{width:"100%",height:"100%"},children:[i(s.Box,{sx:{maxWidth:"calc(100% - 610px - 10px)",height:"100%",overflow:"auto"},children:e}),i(kk,{})]});function jk(e){return!["richText","button"].includes(e)}const Rk=k.observer(({panel:e})=>{const t=Ge.useModals(),n=ue(),r=le(),[a,o]=y.useState("Data"),l=e.queries,c=jk(e.viz.type)&&e.dataLoading,d=c||e.queryErrors.length>0||e.queryStateMessages!==""||l.length===0,f=n.editor.path[1];y.useEffect(()=>{o(m=>d&&m==="Visualization"?"Data":m)},[e.id,d]);const h=()=>{n.editor.setPath(["_VIEWS_",f])},g=()=>t.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.removePanelByID(e.id,f),h()},confirmProps:{color:"red"},zIndex:320});return p(Ir,{value:{panel:e,data:e.data,loading:c,errors:e.queryErrors,downloadPanelScreenshot:()=>{}},children:[p(s.Group,{px:16,position:"apart",sx:{borderBottom:"1px solid #eee"},children:[p(s.Text,{pt:9,pb:8,children:[e.title?e.title:e.viz.type," "]}),p(s.Group,{position:"right",noWrap:!0,children:[i(Gk,{panel:e,sourceViewID:f}),i(s.Button,{size:"xs",variant:"subtle",color:"red",onClick:g,leftIcon:i(E.IconTrash,{size:14}),children:"Delete This Panel"})]})]}),p(s.Tabs,{value:a,onTabChange:o,keepMounted:!1,styles:Wk,children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Data",disabled:c,children:"Data"}),i(s.Tabs.Tab,{value:"Panel",children:"Panel"}),i(s.Tabs.Tab,{value:"Variables",disabled:d,children:i(s.Tooltip,{label:"Requires data",disabled:!d,withinPortal:!0,zIndex:310,children:i(s.Text,{children:"Variables"})})}),i(s.Tabs.Tab,{value:"Visualization",disabled:d,children:i(s.Tooltip,{label:"Requires data",disabled:!d,withinPortal:!0,zIndex:310,children:i(s.Text,{children:"Visualization"})})}),i(s.Tabs.Tab,{value:"Interactions",children:"Interactions"})]}),p(s.Tabs.Panel,{value:"Data",children:[i(s.LoadingOverlay,{visible:c,exitTransitionDuration:0}),i(_k,{})]}),i(s.Tabs.Panel,{value:"Panel",children:i(lu,{children:i(wk,{})})}),i(s.Tabs.Panel,{value:"Variables",children:i(Pk,{})}),i(s.Tabs.Panel,{value:"Visualization",children:i(Ne,{children:i(lu,{children:i(Fk,{})})})}),i(s.Tabs.Panel,{value:"Interactions",children:i(Ne,{children:i(hd,{})})})]})]})}),Yk=k.observer(({viewID:e,panelID:t})=>{const n=le();if(!n.views.findByID(e))return p(s.Text,{size:14,children:["View by ID[",e,"] is not found"]});const a=n.panels.findByID(t);return a?i(Rk,{panel:a}):p(s.Text,{size:14,children:["Panel by ID[",t,"] is not found"]})}),Qk=e=>{const{queryModel:t}=e,n=ue(),r=le(),o=r.findQueryUsage(t.id).length>0,l=Ge.useModals(),u=()=>{l.openConfirmModal({title:"Delete this query?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.queries.removeQuery(t.id),n.editor.setPath(["_QUERIES_",""])},confirmProps:{color:"red"},zIndex:320})};return o?i(s.Tooltip,{label:"Can't delete this query for it's being used, check out Usage tab for details",withArrow:!0,events:{hover:!0,focus:!1,touch:!1},withinPortal:!0,children:i(s.Button,{color:"gray",size:"xs",leftIcon:i(E.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})}):i(s.Button,{color:"red",size:"xs",onClick:u,leftIcon:i(E.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})},Uk=k.observer(Qk),uu=({width:e="calc(100% - 32px)",lastWidth:t="50%",height:n,count:r,spacing:a=16,pl:o=0})=>p(s.Stack,{spacing:a,mt:6,pl:o,children:[Array.from(new Array(r-1),(l,u)=>i(s.Skeleton,{width:e,height:n,radius:"xs"},u)),i(s.Skeleton,{width:t,height:n,radius:"xs"})]}),bn=({value:e})=>e===null||e===""?null:i(s.Tooltip,{label:e,disabled:!e,multiline:!0,children:i(s.ActionIcon,{children:i(E.IconInfoCircle,{size:14})})}),Kk=({column:e})=>{const{column_key:t,column_key_text:n}=e;return t?i(s.Tooltip,{label:n,disabled:!n,children:i(s.Badge,{children:t})}):null},Xk=k.observer(({dataSource:e})=>{const{columns:t}=e;return t.loading?i(uu,{height:"24px",width:"100%",lastWidth:"100%",count:20,pl:6}):t.empty?null:p(s.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"1000px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[i("col",{style:{width:50}}),i("col",{style:{minWidth:300}}),i("col",{style:{width:30}}),i("col",{style:{width:70}}),i("col",{style:{minWidth:300}}),i("col",{style:{minWidth:80,width:80}}),i("col",{style:{minWidth:120,width:120}})]}),i("thead",{children:p("tr",{children:[i("th",{children:"#"}),i("th",{children:"Column Name"}),i("th",{}),i("th",{}),i("th",{children:"Type"}),i("th",{children:"Nullable"}),i("th",{children:"Default Value"})]})}),i("tbody",{children:t.data.map(n=>p("tr",{children:[i("td",{children:n.ordinal_position}),i("td",{children:n.column_name}),i("td",{children:i(bn,{value:n.column_comment})}),i("td",{children:i(Kk,{column:n})}),i("td",{children:n.column_type}),i("td",{children:n.is_nullable}),i("td",{children:i(bn,{value:n.column_default})})]},n.column_name))})]})}),Jk=k.observer(({dataSource:e})=>{const{indexes:t}=e,n=t.data;return p(s.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"950px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[i("col",{style:{width:100}}),i("col",{style:{minWidth:300}}),i("col",{style:{width:150}}),i("col",{style:{width:150}}),i("col",{style:{width:250}})]}),i("thead",{children:p("tr",{children:[i("th",{children:"Index Length"}),i("th",{children:"Index Name"}),i("th",{children:"Index Algorithm"}),i("th",{children:"Unique"}),i("th",{children:"Column Name"})]})}),i("tbody",{children:n.map(r=>p("tr",{children:[i("td",{children:r.index_length}),i("td",{children:r.index_name}),i("td",{children:r.index_algorithm}),i("td",{children:r.is_unique?"YES":"NO"}),i("td",{children:r.column_name})]},r.index_name))})]})}),Zk=k.observer(({dataSource:e})=>{const{indexes:t}=e,n=t.data;return p(s.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"850px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[i("col",{style:{minWidth:300}}),i("col",{style:{width:150}}),i("col",{style:{width:100}}),i("col",{style:{width:100}}),i("col",{style:{width:100}}),i("col",{style:{width:100}})]}),i("thead",{children:p("tr",{children:[i("th",{children:"Index Name"}),i("th",{children:"Index Algorithm"}),i("th",{children:"Unique"}),i("th",{children:"Definition"}),i("th",{children:"Condition"}),i("th",{children:"Comment"})]})}),i("tbody",{children:n.map(r=>p("tr",{children:[i("td",{children:r.index_name}),i("td",{children:r.index_algorithm}),i("td",{children:r.is_unique?"YES":"NO"}),i("td",{children:i(bn,{value:r.index_definition})}),i("td",{children:i(bn,{value:r.condition})}),i("td",{children:i(bn,{value:r.comment})})]},r.index_name))})]})}),Hk=k.observer(({dataSource:e})=>{const{indexes:t}=e;return t.loading||t.empty?null:e.type===ve.MySQL?i(Jk,{dataSource:e}):e.type===ve.Postgresql?i(Zk,{dataSource:e}):null}),eT=k.observer(({dataSource:e})=>p(s.Stack,{spacing:40,pt:10,sx:{flexGrow:1,overflow:"auto",position:"relative"},children:[i(Ne,{children:i(Xk,{dataSource:e})}),i(Ne,{children:i(Hk,{dataSource:e})})]}));function tT({table_type:e}){return e==="VIEW"?i(E.IconEye,{size:14}):e==="BASE TABLE"?i(E.IconTable,{size:14}):null}const nT=k.observer(({dataSource:e})=>{const{tables:t}=e;return t.loading?i(uu,{height:"24px",lastWidth:"50%",count:15}):i(s.Box,{h:"100%",sx:{overflow:"auto",".mantine-NavLink-label":{fontFamily:"monospace"}},children:Object.entries(t.data).map(([n,r])=>i(s.NavLink,{label:n,icon:i(E.IconDatabase,{size:14}),defaultOpened:e.table_schema===n,pl:0,childrenOffset:14,children:r.map(a=>i(s.NavLink,{label:a.table_name,icon:i(tT,{table_type:a.table_type}),onClick:()=>{e.setKeywords(n,a.table_name)},active:e.table_name===a.table_name},a.table_name))},n))})}),rT=({visible:e})=>i(s.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:i(s.LoadingOverlay,{visible:e})}),iT=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],aT={icon:{width:"50px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"50px"}}},sT=k.observer(({dataSource:e})=>{const{tableData:t}=e;return p(s.Group,{pt:10,px:10,position:"apart",children:[p(s.Group,{position:"left",children:[t.maxPage>1&&i(s.Pagination,{size:"sm",value:t.page,onChange:t.setPage,total:t.maxPage,withEdges:t.maxPage>7,styles:{control:{height:"30px"}}}),i(s.Select,{icon:i(s.Text,{ta:"center",color:"dimmed",size:14,children:"Limit"}),size:"xs",styles:aT,data:iT,value:String(t.limit),onChange:n=>t.setLimit(Number(n))})]}),i(s.Group,{position:"right",children:p(s.Text,{color:"dimmed",my:0,size:14,children:["Total ",t.total," rows"]})})]})}),oT=k.observer(({dataSource:e})=>{const t=e.tableData;return t.maxPage===0?i(s.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:"This table is empty"}):t.error?i(s.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:t.error}):t.page===1&&t.loading?i(rT,{visible:!0}):p(Ne,{children:[i(sT,{dataSource:e}),p(s.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[i(s.LoadingOverlay,{visible:t.loading,overlayBlur:2}),i(au,{data:t.data})]})]})}),lT={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},uT=k.observer(({dataSource:e})=>(y.useEffect(()=>{e.loadTablesIfEmpty()},[e]),e.tables.error?i(s.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:e.tables.error}):p(s.Flex,{sx:{height:"100%"},children:[i(s.Box,{w:300,sx:{flexGrow:0,flexShrink:0,position:"relative"},children:i(Ne,{children:i(nT,{dataSource:e})})}),p(s.Tabs,{defaultValue:"structure",styles:lT,children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"structure",icon:i(E.IconColumns,{size:14}),children:"Structure"}),i(s.Tabs.Tab,{value:"data",icon:i(E.IconDatabase,{size:14}),children:"Data"})]}),i(s.Tabs.Panel,{value:"structure",children:i(eT,{dataSource:e})}),i(s.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:i(oT,{dataSource:e})})]})]}))),cT={modal:{paddingLeft:"0px !important",paddingRight:"0px !important"},header:{marginBottom:0,padding:"20px 20px 10px",borderBottom:"1px solid #efefef",gap:"20px"},title:{flexGrow:1},body:{padding:"0 0 0 20px"}},cu=k.observer(({dataSource:e,triggerButtonProps:t={}})=>{const[n,r]=y.useState(!1);return e.type==="http"?null:p(B,{children:[i(s.Modal,{opened:n,onClose:()=>r(!1),title:p(s.Group,{position:"apart",sx:{flexGrow:1},children:[i(s.Text,{fw:500,children:"Explorer Data Source"}),p(s.Group,{spacing:7,children:[i(s.Badge,{variant:"gradient",gradient:{from:"indigo",to:"cyan"},children:e.key}),i(s.Badge,{variant:"gradient",gradient:{from:"orange",to:"red"},children:e.type})]})]}),zIndex:320,size:"96vw",styles:cT,children:i(s.Box,{sx:{height:"calc(100vh - 220px)"},children:i(uT,{dataSource:e})})}),i(s.Button,{variant:"subtle",onClick:()=>r(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},...t,children:"See Table Structure"})]})}),dT=y.forwardRef(({label:e,type:t,...n},r)=>p(s.Group,{position:"apart",ref:r,...n,children:[i(s.Text,{children:e}),i(s.Text,{children:t})]})),pT=k.observer(({value:e,onChange:t})=>{const n=ue(),{data:r=[],loading:a}=Q.useRequest(wr,{refreshDeps:[]},[]),o=y.useMemo(()=>r.map(d=>({label:d.key,value:d.key,type:d.type})),[r]),l=y.useMemo(()=>o.reduce((d,f)=>(d[f.value]=f.type,d),{}),[o]),u=d=>{d!==null&&t({key:d,type:l[d]})},c=y.useMemo(()=>n.datasources.find(e),[n,e]);return i(s.Select,{data:o,label:p(s.Group,{position:"apart",children:[i(s.Box,{children:"Data Source"}),c&&i(cu,{dataSource:c,triggerButtonProps:{compact:!0,size:"xs",px:10}})]}),itemComponent:dT,rightSection:c?i(s.Text,{size:"xs",color:"dimmed",children:c.type}):void 0,rightSectionWidth:85,maxDropdownHeight:280,styles:{root:{flex:1},label:{display:"block"},rightSection:{pointerEvents:"none",justifyContent:"flex-end",paddingRight:"10px",".mantine-Text-root":{userSelect:"none"}}},disabled:a,value:e.key,onChange:u})}),du=y.forwardRef((e,t)=>{const{label:n,description:r,...a}=e;return i("div",{ref:t,...a,children:p(s.Group,{position:"apart",noWrap:!0,children:[i(s.Text,{children:n}),i(s.Text,{size:"xs",color:"dimmed",children:r})]})})}),hT=k.observer(({queryModel:e})=>{const[t,n]=y.useState(e.name);return y.useEffect(()=>{n(e.name)},[e.name]),i(s.Center,{ml:20,mt:20,sx:{maxWidth:"600px"},children:p(s.Stack,{spacing:10,sx:{width:"100%"},children:[i(s.Divider,{mb:-10,variant:"dashed",label:"Basics",labelPosition:"center"}),i(s.TextInput,{placeholder:"A unique name",label:"Name",required:!0,sx:{flex:1},value:t,onChange:r=>{n(r.currentTarget.value)},rightSection:i(s.ActionIcon,{variant:"filled",color:"blue",size:"sm",onClick:()=>e.setName(t),disabled:t===e.name,children:i(E.IconDeviceFloppy,{size:16})}),onBlur:()=>{e.setName(t)}}),i(pT,{value:{type:e.type,key:e.key},onChange:({type:r,key:a})=>{e.setKey(a),e.setType(r)}}),i(s.Divider,{mt:10,mb:-10,variant:"dashed",label:"Conditions",labelPosition:"center"}),i(s.MultiSelect,{label:"Run query when these are truthy",placeholder:"Always run this query on load",data:e.conditionOptions,value:[...e.run_by],onChange:e.setRunBy,itemComponent:du,maxDropdownHeight:500}),e.typedAsHTTP&&i(s.MultiSelect,{label:"Re-run query when these changed",placeholder:"Leave it empty to never re-run this query",data:e.conditionOptions,value:[...e.react_to],onChange:e.setReactTo,itemComponent:du,maxDropdownHeight:500}),i(s.Divider,{mt:20,mb:10,variant:"dashed"}),i(Uk,{queryModel:e})]})})});function fT({content:e}){return p(s.HoverCard,{width:"60vw",shadow:"md",children:[i(s.HoverCard.Target,{children:i(s.ActionIcon,{size:16,color:"blue",children:i(E.IconEye,{})})}),i(s.HoverCard.Dropdown,{children:i(Mt.Prism,{language:"sql",noCopy:!0,withLineNumbers:!0,children:e})})]})}const gT=k.observer(()=>{const t=[...ue().globalSQLSnippets.list];return t.length===0?null:p(s.Table,{horizontalSpacing:"xs",verticalSpacing:"xs",fontSize:"sm",highlightOnHover:!0,children:[i("thead",{children:p("tr",{children:[i("th",{children:"Key"}),i("th",{children:"Value"})]})}),i("tbody",{children:t.map(n=>{const{id:r,content:a}=n;return p("tr",{children:[i("td",{children:r}),i("td",{width:200,children:i(fT,{content:a})})]},r)})})]})}),mT=`
|
|
518
|
+
`,pk=()=>{const[e,t]=y.useState(!1);return p(B,{children:[i(s.Button,{variant:"subtle",compact:!0,onClick:()=>t(n=>!n),children:e?"Close":"Click to see expected data structure"}),i(s.Collapse,{in:e,children:i(Mt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:dk})})]})},hk=k.observer(function({config:t}){return p(B,{children:[i(s.Checkbox,{checked:t.required,onChange:n=>t.setRequired(n.currentTarget.checked),label:"Required"}),i(s.TextInput,{label:"Min-width",value:t.min_width,onChange:n=>t.setMinWidth(n.currentTarget.value),placeholder:"200px"}),i(s.Divider,{label:"Fetch options from database",labelPosition:"center"}),i(s.Checkbox,{checked:t.treeCheckStrictly,onChange:n=>t.setTreeCheckStrictly(n.currentTarget.checked),label:"Parent and children nodes are not associated"}),i(s.NumberInput,{value:t.default_selection_count,onChange:t.setDefaultSelectionCount,label:"Select first N options by default"}),i(Gi,{value:t.options_query_id,onChange:t.setOptionsQueryID}),i(pk,{})]})}),fk=k.observer(function({filter:t}){return p(s.Box,{sx:{maxWidth:"480px"},children:[i(s.Text,{pt:"0",pb:"md",color:"gray",children:"Config"}),i(Mt.Prism,{mt:22,language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(t,null,4)})]})}),gk={select:uk,"multi-select":lk,"tree-select":hk,"text-input":ck,checkbox:ik,"date-range":sk},mk=[{label:"Select",value:"select"},{label:"Multi Select",value:"multi-select"},{label:"Tree Select",value:"tree-select"},{label:"Text Input",value:"text-input"},{label:"Checkbox",value:"checkbox"},{label:"Date Range",value:"date-range"}],yk=k.observer(function({filter:t}){const n=le(),r=y.useMemo(()=>gk[t.type],[t.type]);return p(s.Group,{grow:!0,spacing:20,align:"top",children:[p(s.Box,{sx:{maxWidth:"600px"},children:[i(s.Text,{pb:"md",color:"gray",children:"Edit"}),p(s.Stack,{children:[p(s.Group,{noWrap:!0,children:[i(s.NumberInput,{label:"Placement Order",required:!0,value:t.order,onChange:t.setOrder,hideControls:!0,sx:{flexGrow:"1 !important"}}),t.auto_submit_supported&&i(s.Checkbox,{label:"Submit automatically",checked:t.auto_submit,onChange:a=>t.setAutoSubmit(a.currentTarget.checked),mt:22})]}),i(s.MultiSelect,{label:"Visible in...",data:n.views.options,value:[...t.visibleInViewsIDs],onChange:t.setVisibleInViewsIDs}),i(s.TextInput,{label:"Key",placeholder:"A unique key to refer",required:!0,value:t.key,onChange:a=>{t.setKey(a.currentTarget.value)}}),i(s.TextInput,{label:"Label",placeholder:"Label for this field",required:!0,value:t.label,onChange:a=>{t.setLabel(a.currentTarget.value)}}),i(s.Select,{label:"Widget",data:mk,required:!0,value:t.type,onChange:t.setType}),i(r,{config:t.config})]})]}),i(fk,{filter:t})]})}),bk=k.observer(({id:e})=>{const t=Ge.useModals(),n=ue(),r=le();if(e==="")return null;const a=r.filters.findByID(e);if(!a)return p(s.Text,{size:14,children:["Filter by ID[",e,"] is not found"]});const o=()=>{n.editor.setPath(["_FILTERS_",""])},l=()=>{t.openConfirmModal({title:"Delete this filter?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.filters.removeByID(e),o()},confirmProps:{color:"red"},zIndex:320})};return p(s.Stack,{sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",pb:30,children:[i(s.Group,{position:"right",pt:10,children:i(s.Button,{size:"xs",color:"red",leftIcon:i(D.Trash,{size:16}),onClick:l,children:"Delete this filter"})}),i(s.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:i(yk,{filter:a})})]})}),vk=k.observer(()=>{const e=le(),[t,n]=y.useState(()=>JSON.stringify(e.mock_context.current,null,4)),r=()=>{try{e.mock_context.replace(JSON.parse(t))}catch(o){_n.showNotification({title:"Failed",message:o.message,color:"red"})}},a=y.useMemo(()=>{try{return JSON.stringify(JSON.parse(t))!==JSON.stringify(e.mock_context.current)}catch{return!1}},[t,e.mock_context.current]);return p(s.Stack,{sx:{border:"1px solid #eee",borderLeft:"none",borderRight:"none",flexGrow:1,maxWidth:"unset"},children:[i(s.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:i(s.Text,{weight:500,children:"Mock Context"})}),p(s.Group,{grow:!0,px:"md",pb:"md",pt:0,sx:{flexGrow:1,position:"relative",alignItems:"flex-start"},children:[p(s.Stack,{spacing:10,sx:{maxWidth:"unset !important"},children:[i(s.Text,{children:"A valid json string is required"}),i(s.JsonInput,{validationError:"Invalid json",formatOnBlur:!0,autosize:!0,minRows:30,value:t,onChange:n,sx:{flexGrow:1}})]}),i(s.ActionIcon,{mr:5,variant:"filled",color:"blue",sx:{position:"absolute",right:12,top:0},disabled:!a,onClick:r,children:i(D.DeviceFloppy,{size:20})})]})]})}),xk=k.observer(()=>{const{panel:e}=rt();return i(pi,{label:"Description",value:e.description,onChange:e.setDescription,styles:{root:{flexGrow:1}}})}),wk=k.observer(()=>{const{panel:e}=rt(),{style:t}=e;return p(B,{children:[i(s.Divider,{mb:-10,label:"Style",labelPosition:"center",variant:"dashed"}),p(s.Stack,{spacing:20,children:[p(s.Group,{grow:!0,align:"top",children:[i(s.NumberInput,{label:"Width",min:1,max:36,step:1,precision:0,rightSection:i(s.Text,{size:12,children:"of 36 columns"}),styles:{rightSection:{width:"110px"}},value:e.layout.w,onChange:n=>{n&&e.layout.setWidth(n)}}),i(s.NumberInput,{label:"Height",rightSection:i(s.Text,{size:12,children:"px"}),styles:{rightSection:{width:"40px"}},value:e.layout.h,onChange:n=>{n&&e.layout.setHeight(n)}})]}),i(s.Switch,{label:"Border",checked:t.border.enabled,onChange:n=>t.border.setEnabled(n.currentTarget.checked)})]})]})}),Ck=k.observer(()=>{const{panel:e}=rt(),{title:t,setTitle:n}=e,[r,a]=ke.useInputState(t),o=t!==r,l=y.useCallback(()=>{o&&n(r)},[o,r]);return y.useEffect(()=>{a(t)},[t]),i(s.TextInput,{value:r,onChange:a,label:p(s.Group,{children:[i(s.Text,{children:"Panel Title"}),i(s.ActionIcon,{variant:"subtle",color:"blue",disabled:!o,onClick:l,children:i(D.DeviceFloppy,{size:20})})]}),styles:{label:{display:"block",paddingBottom:"4px"}}})});function Sk(){return p(s.Stack,{sx:{height:"100%"},children:[i(wk,{}),i(s.Divider,{label:"Info",labelPosition:"center",variant:"dashed"}),i(Ck,{}),i(xk,{})]})}const _k={width:"fit-content",minWidth:"100%",tableLayout:"fixed",tr:{width:"fit-content"},th:{position:"relative"},"th, td":{wordBreak:"break-word"},".resizer":{position:"absolute",right:0,top:"50%",transform:"translateY(-50%)",cursor:"col-resize",userSelect:"none",touchAction:"none"},".resizer.isResizing":{color:"#228be6",opacity:"1"},"@media (hover: hover)":{".resizer":{opacity:"0"},"*:hover > .resizer":{color:"#228be6",opacity:"1"}}};function ou({data:e}){const t=y.useMemo(()=>{if(!Array.isArray(e)||e.length===0)return[];const r=et.createColumnHelper();return Object.keys(e[0]).map(a=>r.accessor(a,{cell:o=>o.getValue()}))},[e]),n=et.useReactTable({data:e,columns:t,columnResizeMode:"onChange",getCoreRowModel:et.getCoreRowModel()});return e.length===0?i(s.Box,{sx:{height:"5em"}}):i(Ne,{children:p(s.Table,{sx:_k,children:[i("thead",{children:n.getHeaderGroups().map(r=>i("tr",{children:r.headers.map(a=>p("th",{style:{width:a.getSize()},children:[a.isPlaceholder?null:et.flexRender(a.column.columnDef.header,a.getContext()),i(s.ActionIcon,{onMouseDown:a.getResizeHandler(),onTouchStart:a.getResizeHandler(),className:`resizer ${a.column.getIsResizing()?"isResizing":""}`,children:i(D.ArrowBarToRight,{})})]},a.id))},r.id))}),i("tbody",{children:n.getRowModel().rows.map(r=>i("tr",{children:r.getVisibleCells().map(a=>i("td",{children:i(Ne,{children:et.flexRender(a.column.columnDef.cell,a.getContext())})},a.id))},r.id))})]})})}const kk=({queryID:e})=>{const t=ye(),{state:n,error:r}=t.getDataStuffByID(e),a=y.useMemo(()=>t.queries.findByID(e),[t,e]);return n==="loading"?null:r?i(s.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:r}):a!=null&&a.stateMessage?i(s.Text,{color:"gray",align:"center",children:a.stateMessage}):null},Wi=k.observer(function({id:t,moreActions:n=null}){const r=ye(),{data:a,state:o}=r.getDataStuffByID(t),l=o==="loading",u=()=>{r.queries.refetchDataByQueryID(t)},c=()=>{r.queries.downloadDataByQueryID(t)},d=y.useMemo(()=>Array.isArray(a)?a.slice(0,10):[],[a]),f=!Array.isArray(a)||a.length===0;return p(s.Stack,{sx:{border:"1px solid #eee"},children:[p(s.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[p(s.Group,{position:"left",children:[i(s.Text,{weight:500,children:"Preview Data"}),a.length>10&&p(s.Text,{size:"sm",color:"gray",children:["Showing 10 rows of ",a.length]})]}),p(s.Group,{pr:15,children:[n,i(s.ActionIcon,{variant:"subtle",color:"blue",disabled:l,onClick:u,children:i(D.Refresh,{size:16})}),i(s.ActionIcon,{variant:"subtle",color:"blue",disabled:l||f,onClick:c,children:i(D.Download,{size:16})})]})]}),p(s.Box,{sx:{position:"relative",overflow:"auto"},children:[i(s.LoadingOverlay,{visible:l}),i(kk,{queryID:t}),i(ou,{data:d})]})]})}),Tk=k.observer(function(){const t=ue(),n=le(),{panel:r}=rt(),[a,o]=y.useState(!1),l=u=>{t.editor.setPath(["_QUERIES_",u])};return p(B,{children:[i(s.Drawer,{opened:a,onClose:()=>o(!1),title:"Choose queries",padding:"xl",size:500,zIndex:320,children:i(s.Checkbox.Group,{value:[...r.queryIDs],onChange:r.setQueryIDs,children:i(s.Stack,{spacing:"lg",children:n.queries.options.map(u=>i(s.Checkbox,{label:u.label,value:u.value},u.value))})})}),p(s.Stack,{spacing:6,children:[i(s.Group,{position:"right",children:i(s.Button,{variant:"light",size:"sm",leftIcon:i(E.IconLine,{size:16}),onClick:()=>o(!0),children:"Click me to choose queries for this panel"})}),r.queryIDs.length===1&&i(Wi,{id:r.queryIDs[0],moreActions:i(s.Tooltip,{label:"Open this query",children:i(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>l(r.queryIDs[0]),children:i(E.IconArrowCurveRight,{size:16})})})}),r.queryIDs.length>1&&p(s.Tabs,{defaultValue:r.queryIDs[0],children:[i(s.Tabs.List,{children:r.queries.map(u=>i(s.Tabs.Tab,{value:u.id,children:u.name},u.id))}),r.queries.map(u=>i(s.Tabs.Panel,{value:u.id,children:i(Wi,{id:u.id,moreActions:i(s.Tooltip,{label:"Open this query",children:i(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>l(u.id),children:i(E.IconArrowCurveRight,{size:16})})})})},u.id))]})]})]})}),Dk=k.observer(()=>{const{panel:e}=Ct();return i(Ne,{children:i(s.Box,{sx:{height:"100%",flexGrow:0,flexShrink:0,width:"600px"},children:p(s.Stack,{mt:24,spacing:5,sx:{width:"600px",height:"450px",background:"transparent",borderRadius:"5px",border:"1px solid #e9ecef",borderWidth:e.style.border.enabled?"1px":"0px"},children:[p(s.Group,{position:"apart",noWrap:!0,sx:{flexGrow:0,flexShrink:0},children:[i(s.Group,{children:i($i,{})}),i(s.Group,{grow:!0,position:"center",children:i(s.Text,{lineClamp:1,weight:"bold",children:e.title})}),i(s.Group,{position:"right",spacing:0,sx:{height:"28px"}})]}),i(s.Group,{px:5,pb:5,sx:{flexGrow:1,".panel-viz-section":{height:"calc(100% - 28px)"}},children:i(Li,{panel:e})})]})})})}),ji={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 Ik{constructor(t){q(this,"panel");q(this,"selected");this.panel=t,te.makeAutoObservable(this,{},{deep:!1,autoBind:!0})}get variables(){return this.panel.variables}addNew(){const t=this.panel.variables.filter(n=>n.name.startsWith(ji.name)).length;this.panel.addVariable(x.cloneDeep({...ji,name:`${ji.name}${t||""}`})),this.selected=x.last(this.panel.variables)}select(t){this.selected=t}remove(t){this.selected===t&&(this.selected=void 0);const n=this.panel.variables.indexOf(t);if(this.panel.removeVariable(t),!this.selected&&!x.isEmpty(this.panel.variables)){const r=Math.min(this.panel.variables.length-1,n);this.selected=this.panel.variables[r]}}}function Mk(){const{panel:e}=rt();return Q.useCreation(()=>new Ik(e),[e])}const lu=s.createStyles(e=>({root:{height:"100%",overflow:"hidden",".var-list-container":{"& > *":{height:"100%"},width:250,height:"100%"},".var-list-actions":{height:"fit-content",flexShrink:0,width:"100%"},".var-list":{flex:"1 1 auto",overflow:"auto",minHeight:0,"& > *":{flex:"0 0 auto"}}},config:{height:"100%",overflow:"auto",paddingRight:10}})),Ak=y.forwardRef(function({value:t,onChange:n,data:r,withStyle:a=!0},o){const l=(u,c)=>{const d=x.cloneDeep(t);x.set(d,u,c),n(d)};return p(s.Box,{px:"sm",py:"md",ref:o,children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(s.TextInput,{label:"Name",required:!0,value:t.name,onChange:u=>l("name",u.currentTarget.value)}),i(W,{label:"Data Field",required:!0,value:t.data_field,onChange:u=>l("data_field",u)})]}),i(Qn,{label:"Aggregation",value:t.aggregation,onChange:u=>l("aggregation",u)}),t.aggregation.type!=="custom"&&p(B,{children:[i(s.Divider,{my:"xs",label:"Format",labelPosition:"center"}),i(We,{value:t.formatter,onChange:u=>l("formatter",u)})]}),a&&i(Hs,{value:t,onChange:n})]})}),zk=e=>{const{uiModel:t}=e;return i(s.Stack,{className:"var-list",children:t.variables.map(n=>i(s.Button,{variant:t.selected===n?"filled":"subtle",color:"gray",onClick:()=>t.select(n),children:n.name},n.name))})},Ek=k.observer(zk),$k=({variable:e,data:t})=>i(s.Group,{style:{minHeight:0,height:"calc(100% - 68px)"},children:i(s.Paper,{withBorder:!0,p:"md",children:eo(e,t)})}),Lk=k.observer($k),Ok=e=>{const t=Q.useCreation(()=>ES(e.variable),[e.variable]),{classes:n}=lu(),{data:r}=rt();return p(s.Group,{style:{height:"100%"},align:"start",children:[p(s.Stack,{"data-testid":"variable-editor",align:"stretch",className:n.config,children:[p(s.Group,{position:"right",children:[i(s.ActionIcon,{variant:"filled",disabled:!t.changed,color:"primary",onClick:t.commit,children:i(E.IconDeviceFloppy,{size:18})}),i(s.ActionIcon,{color:"red",onClick:()=>e.uiModel.remove(e.variable),children:i(E.IconTrash,{size:18})})]}),i(Ak,{value:b.getSnapshot(t.copy),onChange:t.update,data:r})]}),i(Lk,{variable:b.getSnapshot(t.copy),data:r})]})},Pk=k.observer(Ok),Bk=()=>{const e=Mk(),{classes:t}=lu();return p(s.Group,{className:t.root,noWrap:!0,align:"start",children:[i(s.Paper,{withBorder:!0,p:"md",className:"var-list-container",children:p(s.Stack,{justify:"space-between",children:[i(s.Box,{className:"var-list-actions",children:i(s.Button,{variant:"light",size:"sm",onClick:e.addNew,fullWidth:!0,children:"Add Variable"})}),i(Ek,{uiModel:e})]})}),e.selected?i(B,{children:i(Pk,{uiModel:e,variable:e.selected})}):i("span",{children:"Select or create a new variable on right side"})]})},Vk=k.observer(Bk);function Nk(){const{vizManager:e}=y.useContext(ct);return y.useMemo(()=>{const t=e.availableVizList.map(n=>({value:n.name,label:n.displayName??n.name,group:n.displayGroup??""}));return x.orderBy(t,[n=>n.group,n=>n.label],["asc","asc"])},[e])}const qk=k.observer(({value:e,submit:t})=>{const[n,r]=ke.useInputState(e);y.useEffect(()=>{r(e)},[e]);const a=Nk(),o=e!==n;return i(s.Select,{label:"Visualization",value:n,searchable:!0,onChange:r,data:a,rightSection:i(s.ActionIcon,{disabled:!o,onClick:()=>t(n),children:i(D.DeviceFloppy,{size:20})}),maxDropdownHeight:600})}),uu=[];function Fk(e,t){try{return e.resolveComponent(t).createConfig()}catch{return null}}function Gk(){const{data:e,panel:{variables:t,viz:n,title:r,queryIDs:a,description:o,setDescription:l,setTitle:u,addQueryID:c,removeQueryID:d,id:f}}=rt(),{vizManager:h}=y.useContext(ct),g={title:r,description:o,viz:n,queryIDs:a,id:f},m={setDescription:l,addQueryID:c,removeQueryID:d,setTitle:u},C=Ml(g);try{return h.resolveComponent(g.viz.type),i(ar,{configure:C,children:i(VS,{variables:t,setVizConf:n.setConf,panel:g,panelInfoEditor:m,vizManager:h,data:e})})}catch(w){return console.info(x.get(w,"message")),null}}const Wk=k.observer(()=>{const{data:e,panel:{viz:t}}=rt(),{vizManager:n}=y.useContext(ct),r=y.useCallback(d=>{if(d===t.type)return;const f=Fk(n,d);t.setType(d),t.setConf(f||{})},[t.type]),a=d=>{try{t.setConf(JSON.parse(d))}catch(f){console.error(f)}},o=y.useMemo(()=>{var d;return(d=uu.find(f=>f.value===t.type))==null?void 0:d.Panel},[t.type,uu]),l=Gk(),u=o?y.createElement(o,{data:e,conf:t.conf,setConf:t.setConf}):null,c=l||u;return p(s.Stack,{align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[i(qk,{submit:r,value:t.type}),p(Ne,{children:[i(s.Stack,{pb:10,sx:{flexGrow:1,maxHeight:"100%",overflow:"auto"},children:c}),!c&&i(s.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(t.conf,null,2),onChange:a})]})]})}),jk=k.observer(({panel:e,sourceViewID:t})=>{const n=le(),[r,a]=y.useState(t);y.useEffect(()=>{a(t)},[t]);const[o,{open:l,close:u}]=ke.useDisclosure(!1),c=()=>{e.moveToView(t,r),u()};return p(B,{children:[i(s.Button,{size:"xs",variant:"subtle",color:"blue",onClick:l,leftIcon:i(E.IconBoxMultiple,{size:14}),children:"Move into Another View"}),i(s.Modal,{opened:o,onClose:u,title:"Move panel into another view",zIndex:320,children:p(s.Stack,{sx:{maxHeight:"calc(100vh - 185px)",overflow:"hidden"},children:[i(s.Radio.Group,{value:r,onChange:a,pb:10,sx:{flexGrow:1,maxHeight:"calc(100vh - 185px - 30px)",overflow:"auto"},children:i(s.Stack,{spacing:"xs",children:n.views.options.map(d=>i(s.Radio,{value:d.value,label:d.label},d.value))})}),p(s.Group,{noWrap:!0,position:"apart",sx:{flexGrow:0,flexShrink:0},children:[i(s.Button,{size:"xs",color:"red",leftIcon:i(E.IconX,{size:14}),onClick:u,children:"Cancel"}),i(s.Button,{size:"xs",color:"blue",leftIcon:i(E.IconDeviceFloppy,{size:14}),onClick:c,disabled:r===t,children:"Confirm"})]})]})})]})}),Rk={root:{flexGrow:1,width:"100%",overflow:"hidden"},panel:{width:"100%",height:"calc(100% - 44px)",padding:10,overflow:"scroll"}},cu=({children:e})=>p(s.Group,{noWrap:!0,grow:!0,position:"left",spacing:20,sx:{width:"100%",height:"100%"},children:[i(s.Box,{sx:{maxWidth:"calc(100% - 610px - 10px)",height:"100%",overflow:"auto"},children:e}),i(Dk,{})]});function Yk(e){return!["richText","button"].includes(e)}const Qk=k.observer(({panel:e})=>{const t=Ge.useModals(),n=ue(),r=le(),[a,o]=y.useState("Data"),l=e.queries,c=Yk(e.viz.type)&&e.dataLoading,d=c||e.queryErrors.length>0||e.queryStateMessages!==""||l.length===0,f=n.editor.path[1];y.useEffect(()=>{o(m=>d&&m==="Visualization"?"Data":m)},[e.id,d]);const h=()=>{n.editor.setPath(["_VIEWS_",f])},g=()=>t.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.removePanelByID(e.id,f),h()},confirmProps:{color:"red"},zIndex:320});return p(Ir,{value:{panel:e,data:e.data,loading:c,errors:e.queryErrors,downloadPanelScreenshot:()=>{}},children:[p(s.Group,{px:16,position:"apart",sx:{borderBottom:"1px solid #eee"},children:[p(s.Text,{pt:9,pb:8,children:[e.title?e.title:e.viz.type," "]}),p(s.Group,{position:"right",noWrap:!0,children:[i(jk,{panel:e,sourceViewID:f}),i(s.Button,{size:"xs",variant:"subtle",color:"red",onClick:g,leftIcon:i(E.IconTrash,{size:14}),children:"Delete This Panel"})]})]}),p(s.Tabs,{value:a,onTabChange:o,keepMounted:!1,styles:Rk,children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Data",disabled:c,children:"Data"}),i(s.Tabs.Tab,{value:"Panel",children:"Panel"}),i(s.Tabs.Tab,{value:"Variables",disabled:d,children:i(s.Tooltip,{label:"Requires data",disabled:!d,withinPortal:!0,zIndex:310,children:i(s.Text,{children:"Variables"})})}),i(s.Tabs.Tab,{value:"Visualization",disabled:d,children:i(s.Tooltip,{label:"Requires data",disabled:!d,withinPortal:!0,zIndex:310,children:i(s.Text,{children:"Visualization"})})}),i(s.Tabs.Tab,{value:"Interactions",children:"Interactions"})]}),p(s.Tabs.Panel,{value:"Data",children:[i(s.LoadingOverlay,{visible:c,exitTransitionDuration:0}),i(Tk,{})]}),i(s.Tabs.Panel,{value:"Panel",children:i(cu,{children:i(Sk,{})})}),i(s.Tabs.Panel,{value:"Variables",children:i(Vk,{})}),i(s.Tabs.Panel,{value:"Visualization",children:i(Ne,{children:i(cu,{children:i(Wk,{})})})}),i(s.Tabs.Panel,{value:"Interactions",children:i(Ne,{children:i(gd,{})})})]})]})}),Uk=k.observer(({viewID:e,panelID:t})=>{const n=le();if(!n.views.findByID(e))return p(s.Text,{size:14,children:["View by ID[",e,"] is not found"]});const a=n.panels.findByID(t);return a?i(Qk,{panel:a}):p(s.Text,{size:14,children:["Panel by ID[",t,"] is not found"]})}),Kk=e=>{const{queryModel:t}=e,n=ue(),r=le(),o=r.findQueryUsage(t.id).length>0,l=Ge.useModals(),u=()=>{l.openConfirmModal({title:"Delete this query?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.queries.removeQuery(t.id),n.editor.setPath(["_QUERIES_",""])},confirmProps:{color:"red"},zIndex:320})};return o?i(s.Tooltip,{label:"Can't delete this query for it's being used, check out Usage tab for details",withArrow:!0,events:{hover:!0,focus:!1,touch:!1},withinPortal:!0,children:i(s.Button,{color:"gray",size:"xs",leftIcon:i(E.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})}):i(s.Button,{color:"red",size:"xs",onClick:u,leftIcon:i(E.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})},Xk=k.observer(Kk),du=({width:e="calc(100% - 32px)",lastWidth:t="50%",height:n,count:r,spacing:a=16,pl:o=0})=>p(s.Stack,{spacing:a,mt:6,pl:o,children:[Array.from(new Array(r-1),(l,u)=>i(s.Skeleton,{width:e,height:n,radius:"xs"},u)),i(s.Skeleton,{width:t,height:n,radius:"xs"})]}),bn=({value:e})=>e===null||e===""?null:i(s.Tooltip,{label:e,disabled:!e,multiline:!0,children:i(s.ActionIcon,{children:i(E.IconInfoCircle,{size:14})})}),Jk=({column:e})=>{const{column_key:t,column_key_text:n}=e;return t?i(s.Tooltip,{label:n,disabled:!n,children:i(s.Badge,{children:t})}):null},Zk=k.observer(({dataSource:e})=>{const{columns:t}=e;return t.loading?i(du,{height:"24px",width:"100%",lastWidth:"100%",count:20,pl:6}):t.empty?null:p(s.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"1000px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[i("col",{style:{width:50}}),i("col",{style:{minWidth:300}}),i("col",{style:{width:30}}),i("col",{style:{width:70}}),i("col",{style:{minWidth:300}}),i("col",{style:{minWidth:80,width:80}}),i("col",{style:{minWidth:120,width:120}})]}),i("thead",{children:p("tr",{children:[i("th",{children:"#"}),i("th",{children:"Column Name"}),i("th",{}),i("th",{}),i("th",{children:"Type"}),i("th",{children:"Nullable"}),i("th",{children:"Default Value"})]})}),i("tbody",{children:t.data.map(n=>p("tr",{children:[i("td",{children:n.ordinal_position}),i("td",{children:n.column_name}),i("td",{children:i(bn,{value:n.column_comment})}),i("td",{children:i(Jk,{column:n})}),i("td",{children:n.column_type}),i("td",{children:n.is_nullable}),i("td",{children:i(bn,{value:n.column_default})})]},n.column_name))})]})}),Hk=k.observer(({dataSource:e})=>{const{indexes:t}=e,n=t.data;return p(s.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"950px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[i("col",{style:{width:100}}),i("col",{style:{minWidth:300}}),i("col",{style:{width:150}}),i("col",{style:{width:150}}),i("col",{style:{width:250}})]}),i("thead",{children:p("tr",{children:[i("th",{children:"Index Length"}),i("th",{children:"Index Name"}),i("th",{children:"Index Algorithm"}),i("th",{children:"Unique"}),i("th",{children:"Column Name"})]})}),i("tbody",{children:n.map(r=>p("tr",{children:[i("td",{children:r.index_length}),i("td",{children:r.index_name}),i("td",{children:r.index_algorithm}),i("td",{children:r.is_unique?"YES":"NO"}),i("td",{children:r.column_name})]},r.index_name))})]})}),eT=k.observer(({dataSource:e})=>{const{indexes:t}=e,n=t.data;return p(s.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"850px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[i("col",{style:{minWidth:300}}),i("col",{style:{width:150}}),i("col",{style:{width:100}}),i("col",{style:{width:100}}),i("col",{style:{width:100}}),i("col",{style:{width:100}})]}),i("thead",{children:p("tr",{children:[i("th",{children:"Index Name"}),i("th",{children:"Index Algorithm"}),i("th",{children:"Unique"}),i("th",{children:"Definition"}),i("th",{children:"Condition"}),i("th",{children:"Comment"})]})}),i("tbody",{children:n.map(r=>p("tr",{children:[i("td",{children:r.index_name}),i("td",{children:r.index_algorithm}),i("td",{children:r.is_unique?"YES":"NO"}),i("td",{children:i(bn,{value:r.index_definition})}),i("td",{children:i(bn,{value:r.condition})}),i("td",{children:i(bn,{value:r.comment})})]},r.index_name))})]})}),tT=k.observer(({dataSource:e})=>{const{indexes:t}=e;return t.loading||t.empty?null:e.type===ve.MySQL?i(Hk,{dataSource:e}):e.type===ve.Postgresql?i(eT,{dataSource:e}):null}),nT=k.observer(({dataSource:e})=>p(s.Stack,{spacing:40,pt:10,sx:{flexGrow:1,overflow:"auto",position:"relative"},children:[i(Ne,{children:i(Zk,{dataSource:e})}),i(Ne,{children:i(tT,{dataSource:e})})]}));function rT({table_type:e}){return e==="VIEW"?i(E.IconEye,{size:14}):e==="BASE TABLE"?i(E.IconTable,{size:14}):null}const iT=k.observer(({dataSource:e})=>{const{tables:t}=e;return t.loading?i(du,{height:"24px",lastWidth:"50%",count:15}):i(s.Box,{h:"100%",sx:{overflow:"auto",".mantine-NavLink-label":{fontFamily:"monospace"}},children:Object.entries(t.data).map(([n,r])=>i(s.NavLink,{label:n,icon:i(E.IconDatabase,{size:14}),defaultOpened:e.table_schema===n,pl:0,childrenOffset:14,children:r.map(a=>i(s.NavLink,{label:a.table_name,icon:i(rT,{table_type:a.table_type}),onClick:()=>{e.setKeywords(n,a.table_name)},active:e.table_name===a.table_name},a.table_name))},n))})}),aT=({visible:e})=>i(s.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:i(s.LoadingOverlay,{visible:e})}),sT=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],oT={icon:{width:"50px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"50px"}}},lT=k.observer(({dataSource:e})=>{const{tableData:t}=e;return p(s.Group,{pt:10,px:10,position:"apart",children:[p(s.Group,{position:"left",children:[t.maxPage>1&&i(s.Pagination,{size:"sm",value:t.page,onChange:t.setPage,total:t.maxPage,withEdges:t.maxPage>7,styles:{control:{height:"30px"}}}),i(s.Select,{icon:i(s.Text,{ta:"center",color:"dimmed",size:14,children:"Limit"}),size:"xs",styles:oT,data:sT,value:String(t.limit),onChange:n=>t.setLimit(Number(n))})]}),i(s.Group,{position:"right",children:p(s.Text,{color:"dimmed",my:0,size:14,children:["Total ",t.total," rows"]})})]})}),uT=k.observer(({dataSource:e})=>{const t=e.tableData;return t.maxPage===0?i(s.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:"This table is empty"}):t.error?i(s.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:t.error}):t.page===1&&t.loading?i(aT,{visible:!0}):p(Ne,{children:[i(lT,{dataSource:e}),p(s.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[i(s.LoadingOverlay,{visible:t.loading,overlayBlur:2}),i(ou,{data:t.data})]})]})}),cT={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},dT=k.observer(({dataSource:e})=>(y.useEffect(()=>{e.loadTablesIfEmpty()},[e]),e.tables.error?i(s.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:e.tables.error}):p(s.Flex,{sx:{height:"100%"},children:[i(s.Box,{w:300,sx:{flexGrow:0,flexShrink:0,position:"relative"},children:i(Ne,{children:i(iT,{dataSource:e})})}),p(s.Tabs,{defaultValue:"structure",styles:cT,children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"structure",icon:i(E.IconColumns,{size:14}),children:"Structure"}),i(s.Tabs.Tab,{value:"data",icon:i(E.IconDatabase,{size:14}),children:"Data"})]}),i(s.Tabs.Panel,{value:"structure",children:i(nT,{dataSource:e})}),i(s.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:i(uT,{dataSource:e})})]})]}))),pT={modal:{paddingLeft:"0px !important",paddingRight:"0px !important"},header:{marginBottom:0,padding:"20px 20px 10px",borderBottom:"1px solid #efefef",gap:"20px"},title:{flexGrow:1},body:{padding:"0 0 0 20px"}},pu=k.observer(({dataSource:e,triggerButtonProps:t={}})=>{const[n,r]=y.useState(!1);return e.type==="http"?null:p(B,{children:[i(s.Modal,{opened:n,onClose:()=>r(!1),title:p(s.Group,{position:"apart",sx:{flexGrow:1},children:[i(s.Text,{fw:500,children:"Explorer Data Source"}),p(s.Group,{spacing:7,children:[i(s.Badge,{variant:"gradient",gradient:{from:"indigo",to:"cyan"},children:e.key}),i(s.Badge,{variant:"gradient",gradient:{from:"orange",to:"red"},children:e.type})]})]}),zIndex:320,size:"96vw",styles:pT,children:i(s.Box,{sx:{height:"calc(100vh - 220px)"},children:i(dT,{dataSource:e})})}),i(s.Button,{variant:"subtle",onClick:()=>r(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},...t,children:"See Table Structure"})]})}),hT=y.forwardRef(({label:e,type:t,...n},r)=>p(s.Group,{position:"apart",ref:r,...n,children:[i(s.Text,{children:e}),i(s.Text,{children:t})]})),fT=k.observer(({value:e,onChange:t})=>{const n=ue(),{data:r=[],loading:a}=Q.useRequest(wr,{refreshDeps:[]},[]),o=y.useMemo(()=>r.map(d=>({label:d.key,value:d.key,type:d.type})),[r]),l=y.useMemo(()=>o.reduce((d,f)=>(d[f.value]=f.type,d),{}),[o]),u=d=>{d!==null&&t({key:d,type:l[d]})},c=y.useMemo(()=>n.datasources.find(e),[n,e]);return i(s.Select,{data:o,label:p(s.Group,{position:"apart",children:[i(s.Box,{children:"Data Source"}),c&&i(pu,{dataSource:c,triggerButtonProps:{compact:!0,size:"xs",px:10}})]}),itemComponent:hT,rightSection:c?i(s.Text,{size:"xs",color:"dimmed",children:c.type}):void 0,rightSectionWidth:85,maxDropdownHeight:280,styles:{root:{flex:1},label:{display:"block"},rightSection:{pointerEvents:"none",justifyContent:"flex-end",paddingRight:"10px",".mantine-Text-root":{userSelect:"none"}}},disabled:a,value:e.key,onChange:u})}),hu=y.forwardRef((e,t)=>{const{label:n,description:r,...a}=e;return i("div",{ref:t,...a,children:p(s.Group,{position:"apart",noWrap:!0,children:[i(s.Text,{children:n}),i(s.Text,{size:"xs",color:"dimmed",children:r})]})})}),gT=k.observer(({queryModel:e})=>{const[t,n]=y.useState(e.name);return y.useEffect(()=>{n(e.name)},[e.name]),i(s.Center,{ml:20,mt:20,sx:{maxWidth:"600px"},children:p(s.Stack,{spacing:10,sx:{width:"100%"},children:[i(s.Divider,{mb:-10,variant:"dashed",label:"Basics",labelPosition:"center"}),i(s.TextInput,{placeholder:"A unique name",label:"Name",required:!0,sx:{flex:1},value:t,onChange:r=>{n(r.currentTarget.value)},rightSection:i(s.ActionIcon,{variant:"filled",color:"blue",size:"sm",onClick:()=>e.setName(t),disabled:t===e.name,children:i(E.IconDeviceFloppy,{size:16})}),onBlur:()=>{e.setName(t)}}),i(fT,{value:{type:e.type,key:e.key},onChange:({type:r,key:a})=>{e.setKey(a),e.setType(r)}}),i(s.Divider,{mt:10,mb:-10,variant:"dashed",label:"Conditions",labelPosition:"center"}),i(s.MultiSelect,{label:"Run query when these are truthy",placeholder:"Always run this query on load",data:e.conditionOptions,value:[...e.run_by],onChange:e.setRunBy,itemComponent:hu,maxDropdownHeight:500}),e.typedAsHTTP&&i(s.MultiSelect,{label:"Re-run query when these changed",placeholder:"Leave it empty to never re-run this query",data:e.conditionOptions,value:[...e.react_to],onChange:e.setReactTo,itemComponent:hu,maxDropdownHeight:500}),i(s.Divider,{mt:20,mb:10,variant:"dashed"}),i(Xk,{queryModel:e})]})})});function mT({content:e}){return p(s.HoverCard,{width:"60vw",shadow:"md",children:[i(s.HoverCard.Target,{children:i(s.ActionIcon,{size:16,color:"blue",children:i(E.IconEye,{})})}),i(s.HoverCard.Dropdown,{children:i(Mt.Prism,{language:"sql",noCopy:!0,withLineNumbers:!0,children:e})})]})}const yT=k.observer(()=>{const t=[...ue().globalSQLSnippets.list];return t.length===0?null:p(s.Table,{horizontalSpacing:"xs",verticalSpacing:"xs",fontSize:"sm",highlightOnHover:!0,children:[i("thead",{children:p("tr",{children:[i("th",{children:"Key"}),i("th",{children:"Value"})]})}),i("tbody",{children:t.map(n=>{const{id:r,content:a}=n;return p("tr",{children:[i("td",{children:r}),i("td",{width:200,children:i(mT,{content:a})})]},r)})})]})}),bT=`
|
|
519
519
|
-- You may reference query variables in SQL or VizConfig.
|
|
520
520
|
SELECT *
|
|
521
521
|
FROM commit
|
|
@@ -528,8 +528,8 @@ WHERE
|
|
|
528
528
|
AND \${sql_snippets.author_email_condition}
|
|
529
529
|
-- Global SQL snippets (shared between dashboards)
|
|
530
530
|
AND \${global_sql_snippets.account_condition}
|
|
531
|
-
`,
|
|
532
|
-
`),post:["function process_result(res, utils) {"," // your code goes here"," return data","}"].join(`
|
|
533
|
-
`)},
|
|
534
|
-
`),post:["function process_result(data, utils) {"," // process data and return the result"," return data","}"].join(`
|
|
535
|
-
`)},CT=k.observer(({queryModel:e})=>e.typedAsSQL?p(s.Tabs,{defaultValue:"Edit",orientation:"vertical",sx:{flexGrow:1},styles:{tabLabel:{width:"100%",height:"28px",lineHeight:"28px"}},keepMounted:!1,children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Edit",children:i(s.Group,{spacing:14,position:"apart",children:"Edit SQL"})}),i(s.Tabs.Tab,{value:"Preview",children:"Preview SQL"}),i(s.Tabs.Tab,{value:"pre_process",children:"Process Request"}),i(s.Tabs.Tab,{value:"post_process",children:"Process Result"}),i(Ri,{}),e.datasource&&i(cu,{dataSource:e.datasource})]}),i(s.Tabs.Panel,{value:"Edit",sx:{position:"relative"},p:"sm",children:i(vT,{value:e.sql,onChange:e.setSQL,defaultValue:"SELECT 1"})}),i(s.Tabs.Panel,{value:"Preview",p:0,pl:4,children:i(wT,{value:e.sql})}),i(s.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:i(fn,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:fu.pre})}),i(s.Tabs.Panel,{value:"post_process",p:"sm",children:i(fn,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:fu.post})})]}):null),hr={height:"calc(100% - 44px)",padding:0},ST=k.observer(({queryModel:e})=>{const t=le(),n=y.useMemo(()=>e.datasource?e.typedAsHTTP?"HTTP":"SQL":"Configurations",[e.datasource,e.typedAsHTTP]),[r,a]=y.useState(n);y.useEffect(()=>{a(u=>u!=="Configurations"&&n==="Configurations"?"Configurations":u)},[n]);const o=t.findQueryUsage(e.id),l=o.length===0;return i(s.Stack,{sx:{flexGrow:1},my:0,p:0,children:p(s.Tabs,{value:r,onTabChange:a,defaultValue:n,orientation:"horizontal",keepMounted:!1,sx:{flexGrow:1},children:[p(s.Tabs.List,{grow:!0,children:[i(s.Tabs.Tab,{value:"Configurations",children:"Configurations"}),e.typedAsSQL&&i(s.Tabs.Tab,{value:"SQL",children:"Request"}),e.typedAsHTTP&&i(s.Tabs.Tab,{value:"HTTP",children:"Request"}),i(s.Tabs.Tab,{value:"Data",disabled:!e.datasource,children:i(s.Tooltip,{label:"Need to pick a Data Source first",disabled:e.datasource,withinPortal:!0,children:i(s.Text,{children:"Data"})})}),i(s.Tabs.Tab,{value:"Usage",disabled:l,children:i(s.Tooltip,{label:"This query is not used for any filter or panel",disabled:!l,withinPortal:!0,children:i(s.Text,{children:"Usage"})})})]}),i(s.Tabs.Panel,{value:"Configurations",pt:0,p:0,children:i(hT,{queryModel:e})}),e.typedAsSQL&&i(s.Tabs.Panel,{value:"SQL",sx:hr,children:i(s.Stack,{sx:{height:"100%"},children:i(CT,{queryModel:e})})}),e.typedAsHTTP&&i(s.Tabs.Panel,{value:"HTTP",sx:hr,children:i(s.Stack,{sx:{height:"100%"},children:i(yT,{queryModel:e})})}),i(s.Tabs.Panel,{value:"Data",sx:{...hr,overflow:"hidden"},children:i(Wi,{id:e.id})}),i(s.Tabs.Panel,{value:"Usage",sx:{...hr,overflow:"hidden"},children:i(bT,{queryID:e.id,usage:o})})]})})}),_T=k.observer(({id:e})=>{const n=le().queries.findByID(e);return e===""?null:n?i(s.Stack,{sx:{height:"100%"},spacing:"sm",children:i(ST,{queryModel:n})}):i(s.Text,{size:14,color:"red",children:"Invalid Query ID"})}),kT=k.observer(({value:e})=>{const n=ye().payloadForSQL,r=y.useMemo(()=>xr(e,n),[e,n]);return i(Yi,{height:"100%",value:r})}),TT=k.observer(({item:e,remove:t,onKeyChanged:n})=>{const[r,a]=y.useState("SQL"),[o,l]=y.useState(e.key),u=()=>{e.setKey(o),n(o)},c=o!==e.key,d=e.isADuplicatedKey(o),[f,h]=y.useState(e.value),g=()=>{e.setValue(f)};y.useEffect(()=>{l(e.key),h(e.value)},[e]);const m=f!==e.value,C=Ge.useModals(),w=()=>{C.openConfirmModal({title:"Delete this SQL snippet?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:t,confirmProps:{color:"red"},zIndex:320})};return p(s.Stack,{p:20,sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",children:[p(s.Group,{sx:{alignItems:"end"},spacing:40,children:[i(s.TextInput,{label:d?"This key is occupied by another snippet":"Key",value:o,onChange:_=>{l(_.currentTarget.value)},sx:{flexGrow:"1 !important"},rightSection:i(s.ActionIcon,{color:"blue",variant:"subtle",onClick:u,disabled:!c||d,children:i(D.DeviceFloppy,{size:16})}),error:d}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:w,children:"Delete this SQL Snippet"})]}),p(s.Tabs,{value:r,onTabChange:a,sx:{flexGrow:1},styles:{panel:{height:"calc(100% - 50px)"}},children:[p(s.Tabs.List,{sx:{position:"relative"},children:[i(s.Tabs.Tab,{value:"SQL",children:"SQL"}),i(s.Tabs.Tab,{value:"Preview",children:"Preview"}),i(Ri,{}),i(s.ActionIcon,{color:"blue",variant:"filled",onClick:g,disabled:!m,sx:{position:"absolute",top:0,right:10},children:i(D.DeviceFloppy,{size:18})})]}),i(s.Tabs.Panel,{value:"SQL",pt:"sm",children:i(Yi,{height:"100%",value:f,onChange:h,defaultLanguage:"sql",theme:"sql-dark"})}),i(s.Tabs.Panel,{value:"Preview",pt:"sm",children:i(kT,{value:f})})]})]})}),DT=k.observer(({id:e})=>{const t=ue(),n=le(),r=y.useMemo(()=>n.sqlSnippets.findByKey(e),[e]);if(!e)return null;if(!r)return p(s.Text,{size:14,children:["SQL Snippet by key[",e,"] is not found"]});const a=()=>{t.editor.setPath(["_SQL_SNIPPETS_",""])};return i(TT,{item:r,remove:()=>{n.sqlSnippets.removeByKey(e),a()},onKeyChanged:u=>{t.editor.setPath(["_SQL_SNIPPETS_",u])}})}),IT=k.observer(({view:e})=>!e||e.type!==j.Division?null:p(s.Stack,{children:[i(s.Divider,{mt:8,mb:0,label:"Division settings",labelPosition:"center"}),i(s.Text,{align:"center",size:"xs",color:"dimmed",children:"Under construction"})]})),MT=[{value:"default",label:"Default"},{value:"outline",label:"Outline"},{value:"pills",label:"Pills"}],AT=[{value:"horizontal",label:"Horizontal"},{value:"vertical",label:"Vertical"}],zT=k.observer(({view:e})=>{if(!e||e.type!==j.Tabs)return null;const t=e.config;return p(s.Stack,{children:[i(s.Divider,{mt:8,mb:0,label:"Tabs settings",labelPosition:"center"}),i(s.Select,{label:"Variant",value:t.variant,onChange:t.setVariant,data:MT}),i(s.Select,{label:"Orientation",value:t.orientation,onChange:t.setOrientation,data:AT}),i(s.Switch,{label:"Grow Tabs",checked:t.grow,onChange:n=>t.setGrow(n.currentTarget.checked)})]})}),ET=({disabled:e,value:t,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[e&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(De,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},$T=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:a}]=Q.useBoolean(),[o,l]=y.useState(e??zi),u=g=>{l({...o,enabled:g})},c=()=>{a();const{enabled:g,func_content:m}=o,C={enabled:g,func_content:m};l(C),t(C)},d=()=>{a(),l(e)},f=g=>{l(m=>({...m,func_content:g}))},h=()=>{f(zi.func_content)};return p(B,{children:[i(s.ActionIcon,{size:"lg",color:"blue",variant:"filled",mt:26,onClick:r,sx:{flexGrow:0},children:i(D.Settings,{size:14})}),i(s.Modal,{size:800,title:"Customize modal title",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:o.enabled,onChange:g=>u(g.currentTarget.checked)}),i(ET,{value:o.func_content,onChange:f,disabled:!o.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:h,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:c,children:"OK"})]})]})]})})]})},LT=k.observer(({view:e})=>{if(!e||e.type!==j.Modal)return null;const t=e.config,n=t.custom_modal_title.value;return p(s.Stack,{children:[i(s.Divider,{mt:8,label:"Modal settings",labelPosition:"center"}),p(s.Flex,{gap:10,children:[i(s.TextInput,{label:"Modal Title",value:n,onChange:x.noop,disabled:!0,sx:{flexGrow:1}}),i($T,{value:t.custom_modal_title,onChange:t.custom_modal_title.replace})]}),p(s.Group,{grow:!0,children:[i(s.TextInput,{label:"Width",value:t.width,onChange:r=>t.setWidth(r.currentTarget.value),placeholder:"600px / 50vw"}),i(s.TextInput,{label:"Height",value:t.height,onChange:r=>t.setHeight(r.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),OT=k.observer(({view:e})=>p(B,{children:[i(IT,{view:e}),i(LT,{view:e}),i(zT,{view:e})]})),PT=[{label:"Division",value:j.Division},{label:"Modal",value:j.Modal},{label:"Tabs",value:j.Tabs}],BT=k.observer(({view:e})=>e?p(s.Stack,{sx:{position:"relative"},children:[i(s.TextInput,{label:"Name",value:e.name,onChange:t=>{e.setName(t.currentTarget.value)}}),i(s.Select,{label:"Type",withinPortal:!0,zIndex:320,value:e.type,onChange:e.setType,data:PT}),i(OT,{view:e})]}):null),VT=k.observer(({id:e})=>{const t=Ge.useModals(),n=ue(),r=le();if(e==="")return null;const a=r.views.findByID(e);if(!a)return p(s.Text,{size:14,children:["View by ID[",e,"] is not found"]});const o=()=>{n.editor.setPath(["_VIEWS_",""])},l=()=>{t.openConfirmModal({title:"Delete this view?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.views.removeByID(e),o()},zIndex:320})};return p(s.Stack,{sx:{maxWidth:"600px",height:"100%"},spacing:"sm",children:[i(s.Group,{position:"right",pt:10,children:i(s.Button,{size:"xs",color:"red",leftIcon:i(D.Trash,{size:16}),onClick:l,children:"Delete this view"})}),i(s.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:i(BT,{view:a})})]})});function NT(e){return e.length===1&&e[0]==="_QUERY_VARS_"}function qT(e){return e.length===1&&e[0]==="_MOCK_CONTEXT_"}function FT(e){return e.length===2&&e[0]==="_FILTERS_"}function GT(e){return e.length===1&&e[0]==="_SQL_SNIPPETS_"}function WT(e){return e.length===2&&e[0]==="_SQL_SNIPPETS_"}function jT(e){return e.length===2&&e[0]==="_QUERIES_"}function RT(e){return e.length===1&&e[0]==="_QUERIES_"}function YT(e){return e.length===2&&e[0]==="_VIEWS_"}function QT(e){return e.length===4&&e[0]==="_VIEWS_"&&e[2]==="_PANELS_"}const UT=k.observer(()=>i(s.Stack,{sx:{height:"100%"},p:"sm",children:i(pu,{})})),KT=k.observer(()=>{const e=Ge.useModals(),t=ue(),n=o=>{t.editor.setPath(["_QUERIES_",o])},r=()=>{e.openConfirmModal({title:"Delete ununsed queries?",children:i(s.Text,{size:"sm",children:"This action cannot be undone."}),labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>t.content.removeUnusedQueries(),confirmProps:{color:"red"},zIndex:320})},a=t.content.queriesUsage;return p(s.Stack,{sx:{height:"100%"},spacing:"sm",pb:"59px",children:[i(s.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:i(s.Text,{px:"md",align:"left",sx:{userSelect:"none",cursor:"default"},children:"Manage Queries"})}),i(s.Flex,{justify:"flex-end",align:"center",px:12,children:i(s.Button,{variant:"subtle",size:"xs",color:"red",leftIcon:i(E.IconTrash,{size:14}),disabled:!t.content.hasUnusedQueries,onClick:r,children:"Delete unused queries"})}),i(s.Box,{sx:{flexGrow:1,overflow:"auto"},children:p(s.Table,{fontSize:"sm",highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[i("thead",{children:p("tr",{children:[i("th",{children:"Name"}),i("th",{style:{width:"200px"},children:"Data Source"}),i("th",{style:{width:"100px",textAlign:"right"},children:"Type"}),i("th",{style:{width:"100px",textAlign:"center"},children:"Usage"}),i("th",{style:{width:"300px",paddingLeft:"24px"},children:"Action"})]})}),i("tbody",{children:t.content.queries.sortedList.map(o=>{var u;const l=((u=a[o.id])==null?void 0:u.length)??0;return p("tr",{children:[i("td",{children:o.name}),i("td",{children:o.key}),i("td",{style:{textAlign:"right"},children:o.type}),i("td",{style:{color:l===0?"#ff0000":"#000",fontWeight:l===0?"bold":"normal",textAlign:"center"},children:l}),i("td",{children:i(s.Button,{variant:"subtle",size:"xs",onClick:()=>n(o.id),children:"Open"})})]},o.id)})})]})})]})}),XT=k.observer(()=>{const e=Ge.useModals(),t=ue(),n=o=>{t.editor.setPath(["_SQL_SNIPPETS_",o])},r=()=>{e.openConfirmModal({title:"Delete ununsed SQL snippets?",children:i(s.Text,{size:"sm",children:"This action cannot be undone."}),labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>t.content.removeUnusedSQLSnippets(),confirmProps:{color:"red"},zIndex:320})},a=t.content.sqlSnippetsUsage;return p(s.Stack,{sx:{height:"100%"},spacing:"sm",pb:"59px",children:[i(s.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:i(s.Text,{px:"md",align:"left",sx:{userSelect:"none",cursor:"default"},children:"Manage SQL Snippets"})}),i(s.Flex,{justify:"flex-end",align:"center",px:12,children:i(s.Button,{variant:"subtle",size:"xs",color:"red",leftIcon:i(E.IconTrash,{size:14}),disabled:!t.content.hasUnusedSQLSnippets,onClick:r,children:"Delete unused SQL snippets"})}),i(s.Box,{sx:{flexGrow:1,overflow:"auto"},children:p(s.Table,{fontSize:"sm",highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[i("thead",{children:p("tr",{children:[i("th",{children:"Key"}),i("th",{style:{width:"100px",textAlign:"center"},children:"Usage"}),i("th",{style:{width:"300px",paddingLeft:"24px"},children:"Action"})]})}),i("tbody",{children:t.content.sqlSnippets.sortedList.map(o=>{var u;const l=((u=a[o.key])==null?void 0:u.length)??0;return p("tr",{children:[i("td",{children:o.key}),i("td",{style:{color:l===0?"#ff0000":"#000",fontWeight:l===0?"bold":"normal",textAlign:"center"},children:l}),i("td",{children:i(s.Button,{variant:"subtle",size:"xs",onClick:()=>n(o.key),children:"Open"})})]},o.key)})})]})})]})}),JT=k.observer(()=>{const e=ue().editor,t=e.path;return NT(t)?i(UT,{}):qT(t)?i(yk,{}):FT(t)?i(s.Box,{p:"xs",pl:20,children:i(mk,{id:t[1]})}):GT(t)?i(XT,{}):WT(t)?i(DT,{id:t[1]}):RT(t)?i(KT,{}):jT(t)?i(_T,{id:t[1]}):YT(t)?i(s.Box,{p:"xs",pl:20,children:i(VT,{id:t[1]})}):QT(t)?i(Yk,{viewID:t[1],panelID:t[3]}):i(s.Box,{children:e.path})}),ZT=k.observer(()=>i(JT,{})),HT=k.observer(()=>{const e=ue(),t=()=>{const n=new Date().getTime().toString(),r={id:n,key:n,label:n,order:e.content.filters.current.length+1,type:xe.TextInput,config:sl(),visibleInViewsIDs:["Main"],auto_submit:!1};e.content.filters.append(r),e.editor.setPath(["_FILTERS_",n])};return i(s.Button,{variant:"subtle",leftIcon:i(E.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Filter"})}),eD=k.observer(({parentID:e})=>{const t=le();if(!e)return null;const n=t.views.findByID(e);return!n||n.type===j.Tabs?null:i(s.Button,{variant:"subtle",leftIcon:i(E.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:()=>t.addANewPanel(n.id),sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Panel"})}),tD=k.observer(()=>{const e=ue(),t=()=>{const n=new Date().getTime().toString(),r={id:n,name:n,type:ve.Postgresql,key:"",sql:""};e.content.queries.append(r),e.editor.setPath(["_QUERIES_",n])};return i(s.Button,{variant:"subtle",leftIcon:i(E.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Query"})}),nD=k.observer(()=>{const e=ue(),t=()=>{const n=new Date().getTime().toString(),r={key:n,value:""};e.content.sqlSnippets.append(r),e.editor.setPath(["_SQL_SNIPPETS_",n])};return i(s.Button,{variant:"subtle",leftIcon:i(E.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a SQL Snippet"})}),rD=k.observer(()=>{const e=le();return i(s.Button,{variant:"subtle",leftIcon:i(E.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:e.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a View"})}),iD=k.observer(()=>{const e=ue();return i(s.Button,{variant:"subtle",rightIcon:i(E.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>e.editor.setPath(["_QUERIES_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:"Manage Queries"})}),aD=k.observer(()=>{const e=ue();return i(s.Button,{variant:"subtle",rightIcon:i(E.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>e.editor.setPath(["_SQL_SNIPPETS_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:"Manage SQL Snippets"})}),sD=k.observer(({action_type:e,parentID:t})=>e==="_Add_A_Filter_"?i(HT,{}):e==="_Add_A_SQL_SNIPPET_"?i(nD,{}):e==="_Add_A_QUERY_"?i(tD,{}):e==="_Add_A_VIEW_"?i(rD,{}):e==="_Add_A_PANEL_"?i(eD,{parentID:t}):e==="_QUERIES_SETTINGS_"?i(iD,{}):e==="_SQL_SNIPPETS_SETTINGS_"?i(aD,{}):null),gu=k.observer(({option:e})=>{var d;const t=ue().editor,n=t.isOptionActive,r=n(t.path,e),a=t.isOptionOpened,o=t.navigate,l=a(e),[u,c]=y.useState(l);return y.useEffect(()=>{c(l)},[l]),i(s.NavLink,{active:r,defaultOpened:l,opened:u,onChange:c,label:e.label,onClick:()=>o(e),icon:e.Icon?i(e.Icon,{size:18}):null,children:(d=e.children)==null?void 0:d.map(f=>f._type==="ACTION"?i(sD,{action_type:f._action_type,parentID:f.parentID},`_ADD_${f.value}_`):i(gu,{option:f},f.value))},e.label)}),oD=k.observer(()=>{const e=ue();return i(s.Box,{sx:{position:"relative"},children:e.editor.navOptions.map(t=>i(gu,{option:t},t.value))})}),lD=k.observer(()=>{const e=ue();return p(s.Navbar,{p:0,width:{base:220,xs:220,sm:240,md:260,lg:300,xl:320},sx:{height:"100vh - 60px - 60px"},children:[i(s.Navbar.Section,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:i(s.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Settings"})}),i(s.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:i(oD,{})}),i(s.Navbar.Section,{children:i(s.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:i(s.Button,{size:"xs",color:"red",leftIcon:i(E.IconX,{size:18}),onClick:()=>e.editor.close(),children:"Close"})})})]})}),uD={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"}},cD=k.observer(()=>{const e=ue().editor;return i(s.Modal,{onClose:()=>e.setSettingsOpen(!1),closeOnEscape:!1,closeOnClickOutside:!1,opened:e.settings_open,fullScreen:!0,title:null,transitionProps:{duration:0},withCloseButton:!1,withinPortal:!0,zIndex:300,styles:{body:{padding:"0 !important"}},children:i(s.AppShell,{padding:0,navbar:i(lD,{}),styles:uD,children:i(ZT,{})})})}),dD=e=>e.replace(/([^:])(\/\/+)/g,"$1/");function pD(e){y.useEffect(()=>{if(De.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const n=dD(e);De.loader.config({paths:{vs:n}}),De.loader.init().then(r=>console.log("monaco instance:",r))},[])}co();const hD={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:60+30,height:"100vh"}},fD=({context:e,dashboard:t,content:n,update:r,className:a="dashboard",config:o,onChange:l,headerSlot:u},c)=>{pD(o.monacoPath),es(o);const{data:d=[]}=Q.useRequest(wr),{data:f=[]}=Q.useRequest(ts),h=y.useMemo(()=>Xl(t,n,d,f,e),[t,n]);y.useImperativeHandle(c,()=>h,[h]),Jl(h.content,!0),y.useEffect(()=>{h.context.replace(e)},[e]),y.useEffect(()=>{h.datasources.replace(d)},[d]),y.useEffect(()=>{h.globalSQLSnippets.replace(f)},[f]),y.useEffect(()=>te.reaction(()=>te.toJS(h.json),w=>{l==null||l(w)}),[h]);const g=async()=>{await r(h.json,h.content.json)},m=Q.useCreation(Ii,[]),C=Zl(m);return i(Ge.ModalsProvider,{children:i(_r,{value:h,children:i(Dr,{value:h.content,children:i(An.Provider,{value:{inEditMode:!0},children:i(ct.Provider,{value:m,children:p(ar,{configure:C,children:[i(s.AppShell,{padding:0,header:i(I_,{saveDashboardChanges:g,headerSlot:u}),navbar:i(tk,{}),styles:hD,children:i(s.Box,{className:`${a} dashboard-root`,sx:{position:"relative"},children:h.content.views.visibleViews.map(w=>i(Nl,{view:w},w.id))})}),i(cD,{})]})})})})})})},gD=k.observer(y.forwardRef(fD)),wM="",mu=b.types.model({id:b.types.string,name:b.types.string,dashboard_id:b.types.string,create_time:b.types.string,update_time:b.types.string,version:b.types.string,filters:vl,queries:_l,sqlSnippets:kl,views:gl,panels:yl,mock_context:Zo}).views(e=>({get json(){return{id:e.id,name:e.name,create_time:e.create_time,update_time:e.update_time,dashboard_id:e.dashboard_id,content:{views:e.views.json,panels:e.panels.json,filters:e.filters.json,version:e.version,definition:{queries:e.queries.json,sqlSnippets:e.sqlSnippets.json,mock_context:e.mock_context.current}}}},get payloadForSQL(){const t=b.getParent(e).context.current,n=b.getParent(e).globalSQLSnippets,r={context:{...e.mock_context.current,...t},filters:e.filters.values};return{...r,sql_snippets:lr(e.sqlSnippets.current,"key","value",r),global_sql_snippets:lr(n.list,"id","content",r)}},get payloadForViz(){const t=b.getParent(e).context.current;return{context:{...e.mock_context.current,...t},filters:e.filters.values}},get data(){return e.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(t){const n=e.queries.findByID(t);return n?{data:n.data,len:n.data.length,state:n.state,error:n.error}:{data:[],len:0,state:"idle",error:void 0}}})).actions(e=>({}));function mD({id:e,name:t,dashboard_id:n,create_time:r,update_time:a,content:o}){if(!o)throw new Error("unexpected null content when creating a content model");const{version:l,filters:u,views:c,panels:d,definition:{queries:f,sqlSnippets:h,mock_context:g={}}}=o;return mu.create({id:e,name:t,dashboard_id:n,create_time:r,update_time:a,version:l,filters:xl(u),queries:TS(f),sqlSnippets:IS(h),mock_context:Ho(g),views:fS(c),panels:{list:d}})}const yD=b.types.model({id:b.types.identifier,name:b.types.string,group:b.types.string,content:mu,content_id:b.types.string,datasources:dS,globalSQLSnippets:hl,context:Ei});function bD({id:e,name:t,group:n,content_id:r},a,o,l,u){return yD.create({id:e,name:t,group:n,content_id:r,content:mD(a),datasources:{list:o},globalSQLSnippets:{list:l},context:fl(u)})}co();const vD=k.observer(({context:e,dashboard:t,content:n,className:r="dashboard",config:a,fullScreenPanelID:o,setFullScreenPanelID:l})=>{es(a);const{data:u=[]}=Q.useRequest(wr),{data:c=[]}=Q.useRequest(ts),d=y.useMemo(()=>bD(t,n,u,c,e),[t,n]);Jl(d.content,!1),y.useEffect(()=>{d.context.replace(e)},[e]),y.useEffect(()=>{d.datasources.replace(u)},[u]),y.useEffect(()=>{d.globalSQLSnippets.replace(c)},[c]);const f=Q.useCreation(Ii,[]),h=Zl(f);return i(Ge.ModalsProvider,{children:i(_r,{value:d,children:i(Dr,{value:d.content,children:i(Mr.Provider,{value:{fullScreenPanelID:o,setFullScreenPanelID:l},children:i(An.Provider,{value:{inEditMode:!1},children:i(s.Box,{className:`${r} dashboard-root`,children:i(ct.Provider,{value:f,children:i(ar,{configure:h,children:d.content.views.visibleViews.map(g=>i(cr,{view:g},g.id))})})})})})})})})});var Qi={},xD={get exports(){return Qi},set exports(e){Qi=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){var a=r.prototype,o=a.format;a.format=function(l){var u=this,c=this.$locale();if(!this.isValid())return o.bind(this)(l);var d=this.$utils(),f=(l||"YYYY-MM-DDTHH:mm:ssZ").replace(/\[([^\]]+)]|Q|wo|ww|w|WW|W|zzz|z|gggg|GGGG|Do|X|x|k{1,2}|S/g,function(h){switch(h){case"Q":return Math.ceil((u.$M+1)/3);case"Do":return c.ordinal(u.$D);case"gggg":return u.weekYear();case"GGGG":return u.isoWeekYear();case"wo":return c.ordinal(u.week(),"W");case"w":case"ww":return d.s(u.week(),h==="w"?1:2,"0");case"W":case"WW":return d.s(u.isoWeek(),h==="W"?1:2,"0");case"k":case"kk":return d.s(String(u.$H===0?24:u.$H),h==="k"?1:2,"0");case"X":return Math.floor(u.$d.getTime()/1e3);case"x":return u.$d.getTime();case"z":return"["+u.offsetName()+"]";case"zzz":return"["+u.offsetName("long")+"]";default:return h}});return o.bind(this)(f)}}})})(xD);const wD=Qi;var Ui={},CD={get exports(){return Ui},set exports(e){Ui=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){var o=r.prototype,l=function(c){var d=c.date,f=c.utc;return Array.isArray(d)?f?d.length?new Date(Date.UTC.apply(null,d)):new Date:d.length===1?a(String(d[0])).toDate():new(Function.prototype.bind.apply(Date,[null].concat(d))):d},u=o.parse;o.parse=function(c){c.date=l.bind(this)(c),u.bind(this)(c)}}})})(CD);const SD=Ui;var Ki={},_D={get exports(){return Ki},set exports(e){Ki=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){var a=r.prototype,o=a.format;a.format=function(l){var u=this,c=(l||"YYYY-MM-DDTHH:mm:ssZ").replace(/(\[[^\]]+])|BBBB|BB/g,function(d,f){var h,g=String(u.$y+543),m=d==="BB"?[g.slice(-2),2]:[g,4];return f||(h=u.$utils()).s.apply(h,m.concat(["0"]))});return o.bind(this)(c)}}})})(_D);const kD=Ki;var Xi={},TD={get exports(){return Xi},set exports(e){Xi=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){var o="h:mm A",l={lastDay:"[Yesterday at] "+o,sameDay:"[Today at] "+o,nextDay:"[Tomorrow at] "+o,nextWeek:"dddd [at] "+o,lastWeek:"[Last] dddd [at] "+o,sameElse:"MM/DD/YYYY"};r.prototype.calendar=function(u,c){var d=c||this.$locale().calendar||l,f=a(u||void 0).startOf("d"),h=this.diff(f,"d",!0),g="sameElse",m=h<-6?g:h<-1?"lastWeek":h<0?"lastDay":h<1?"sameDay":h<2?"nextDay":h<7?"nextWeek":g,C=d[m]||l[m];return typeof C=="function"?C.call(this,a()):this.format(C)}}})})(TD);const DD=Xi;var Ji={},ID={get exports(){return Ji},set exports(e){Ji=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){var n={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"},r=/(\[[^[]*\])|([-_:/.,()\s]+)|(A|a|YYYY|YY?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g,a=/\d\d/,o=/\d\d?/,l=/\d*[^-_:/,()\s\d]+/,u={},c=function(w){return(w=+w)+(w>68?1900:2e3)},d=function(w){return function(_){this[w]=+_}},f=[/[+-]\d\d:?(\d\d)?|Z/,function(w){(this.zone||(this.zone={})).offset=function(_){if(!_||_==="Z")return 0;var T=_.match(/([+-]|\d\d)/g),M=60*T[1]+(+T[2]||0);return M===0?0:T[0]==="+"?-M:M}(w)}],h=function(w){var _=u[w];return _&&(_.indexOf?_:_.s.concat(_.f))},g=function(w,_){var T,M=u.meridiem;if(M){for(var P=1;P<=24;P+=1)if(w.indexOf(M(P,0,_))>-1){T=P>12;break}}else T=w===(_?"pm":"PM");return T},m={A:[l,function(w){this.afternoon=g(w,!1)}],a:[l,function(w){this.afternoon=g(w,!0)}],S:[/\d/,function(w){this.milliseconds=100*+w}],SS:[a,function(w){this.milliseconds=10*+w}],SSS:[/\d{3}/,function(w){this.milliseconds=+w}],s:[o,d("seconds")],ss:[o,d("seconds")],m:[o,d("minutes")],mm:[o,d("minutes")],H:[o,d("hours")],h:[o,d("hours")],HH:[o,d("hours")],hh:[o,d("hours")],D:[o,d("day")],DD:[a,d("day")],Do:[l,function(w){var _=u.ordinal,T=w.match(/\d+/);if(this.day=T[0],_)for(var M=1;M<=31;M+=1)_(M).replace(/\[|\]/g,"")===w&&(this.day=M)}],M:[o,d("month")],MM:[a,d("month")],MMM:[l,function(w){var _=h("months"),T=(h("monthsShort")||_.map(function(M){return M.slice(0,3)})).indexOf(w)+1;if(T<1)throw new Error;this.month=T%12||T}],MMMM:[l,function(w){var _=h("months").indexOf(w)+1;if(_<1)throw new Error;this.month=_%12||_}],Y:[/[+-]?\d+/,d("year")],YY:[a,function(w){this.year=c(w)}],YYYY:[/\d{4}/,d("year")],Z:f,ZZ:f};function C(w){var _,T;_=w,T=u&&u.formats;for(var M=(w=_.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(K,Y,H){var se=H&&H.toUpperCase();return Y||T[H]||n[H]||T[se].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(de,we,Le){return we||Le.slice(1)})})).match(r),P=M.length,G=0;G<P;G+=1){var $=M[G],L=m[$],A=L&&L[0],N=L&&L[1];M[G]=N?{regex:A,parser:N}:$.replace(/^\[|\]$/g,"")}return function(K){for(var Y={},H=0,se=0;H<P;H+=1){var de=M[H];if(typeof de=="string")se+=de.length;else{var we=de.regex,Le=de.parser,yt=K.slice(se),Qe=we.exec(yt)[0];Le.call(Y,Qe),K=K.replace(Qe,"")}}return function(dt){var Fe=dt.afternoon;if(Fe!==void 0){var bt=dt.hours;Fe?bt<12&&(dt.hours+=12):bt===12&&(dt.hours=0),delete dt.afternoon}}(Y),Y}}return function(w,_,T){T.p.customParseFormat=!0,w&&w.parseTwoDigitYear&&(c=w.parseTwoDigitYear);var M=_.prototype,P=M.parse;M.parse=function(G){var $=G.date,L=G.utc,A=G.args;this.$u=L;var N=A[1];if(typeof N=="string"){var K=A[2]===!0,Y=A[3]===!0,H=K||Y,se=A[2];Y&&(se=A[2]),u=this.$locale(),!K&&se&&(u=T.Ls[se]),this.$d=function(yt,Qe,dt){try{if(["x","X"].indexOf(Qe)>-1)return new Date((Qe==="X"?1e3:1)*yt);var Fe=C(Qe)(yt),bt=Fe.year,Bt=Fe.month,fr=Fe.day,gr=Fe.hours,Ta=Fe.minutes,Da=Fe.seconds,vn=Fe.milliseconds,Kt=Fe.zone,kt=new Date,Vt=fr||(bt||Bt?1:kt.getDate()),Tt=bt||kt.getFullYear(),Xt=0;bt&&!Bt||(Xt=Bt>0?Bt-1:kt.getMonth());var Jt=gr||0,xn=Ta||0,wn=Da||0,Dt=vn||0;return Kt?new Date(Date.UTC(Tt,Xt,Vt,Jt,xn,wn,Dt+60*Kt.offset*1e3)):dt?new Date(Date.UTC(Tt,Xt,Vt,Jt,xn,wn,Dt)):new Date(Tt,Xt,Vt,Jt,xn,wn,Dt)}catch{return new Date("")}}($,N,L),this.init(),se&&se!==!0&&(this.$L=this.locale(se).$L),H&&$!=this.format(N)&&(this.$d=new Date("")),u={}}else if(N instanceof Array)for(var de=N.length,we=1;we<=de;we+=1){A[1]=N[we-1];var Le=T.apply(this,A);if(Le.isValid()){this.$d=Le.$d,this.$L=Le.$L,this.init();break}we===de&&(this.$d=new Date(""))}else P.call(this,G)}}})})(ID);const MD=Ji;var Zi={},AD={get exports(){return Zi},set exports(e){Zi=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){r.prototype.dayOfYear=function(o){var l=Math.round((a(this).startOf("day")-a(this).startOf("year"))/864e5)+1;return o==null?l:this.add(o-l,"day")}}})})(AD);const zD=Zi;var Hi={},ED={get exports(){return Hi},set exports(e){Hi=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){var n,r,a=1e3,o=6e4,l=36e5,u=864e5,c=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,d=31536e6,f=2592e6,h=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/,g={years:d,months:f,days:u,hours:l,minutes:o,seconds:a,milliseconds:1,weeks:6048e5},m=function($){return $ instanceof G},C=function($,L,A){return new G($,A,L.$l)},w=function($){return r.p($)+"s"},_=function($){return $<0},T=function($){return _($)?Math.ceil($):Math.floor($)},M=function($){return Math.abs($)},P=function($,L){return $?_($)?{negative:!0,format:""+M($)+L}:{negative:!1,format:""+$+L}:{negative:!1,format:""}},G=function(){function $(A,N,K){var Y=this;if(this.$d={},this.$l=K,A===void 0&&(this.$ms=0,this.parseFromMilliseconds()),N)return C(A*g[w(N)],this);if(typeof A=="number")return this.$ms=A,this.parseFromMilliseconds(),this;if(typeof A=="object")return Object.keys(A).forEach(function(de){Y.$d[w(de)]=A[de]}),this.calMilliseconds(),this;if(typeof A=="string"){var H=A.match(h);if(H){var se=H.slice(2).map(function(de){return de!=null?Number(de):0});return this.$d.years=se[0],this.$d.months=se[1],this.$d.weeks=se[2],this.$d.days=se[3],this.$d.hours=se[4],this.$d.minutes=se[5],this.$d.seconds=se[6],this.calMilliseconds(),this}}return this}var L=$.prototype;return L.calMilliseconds=function(){var A=this;this.$ms=Object.keys(this.$d).reduce(function(N,K){return N+(A.$d[K]||0)*g[K]},0)},L.parseFromMilliseconds=function(){var A=this.$ms;this.$d.years=T(A/d),A%=d,this.$d.months=T(A/f),A%=f,this.$d.days=T(A/u),A%=u,this.$d.hours=T(A/l),A%=l,this.$d.minutes=T(A/o),A%=o,this.$d.seconds=T(A/a),A%=a,this.$d.milliseconds=A},L.toISOString=function(){var A=P(this.$d.years,"Y"),N=P(this.$d.months,"M"),K=+this.$d.days||0;this.$d.weeks&&(K+=7*this.$d.weeks);var Y=P(K,"D"),H=P(this.$d.hours,"H"),se=P(this.$d.minutes,"M"),de=this.$d.seconds||0;this.$d.milliseconds&&(de+=this.$d.milliseconds/1e3);var we=P(de,"S"),Le=A.negative||N.negative||Y.negative||H.negative||se.negative||we.negative,yt=H.format||se.format||we.format?"T":"",Qe=(Le?"-":"")+"P"+A.format+N.format+Y.format+yt+H.format+se.format+we.format;return Qe==="P"||Qe==="-P"?"P0D":Qe},L.toJSON=function(){return this.toISOString()},L.format=function(A){var N=A||"YYYY-MM-DDTHH:mm:ss",K={Y:this.$d.years,YY:r.s(this.$d.years,2,"0"),YYYY:r.s(this.$d.years,4,"0"),M:this.$d.months,MM:r.s(this.$d.months,2,"0"),D:this.$d.days,DD:r.s(this.$d.days,2,"0"),H:this.$d.hours,HH:r.s(this.$d.hours,2,"0"),m:this.$d.minutes,mm:r.s(this.$d.minutes,2,"0"),s:this.$d.seconds,ss:r.s(this.$d.seconds,2,"0"),SSS:r.s(this.$d.milliseconds,3,"0")};return N.replace(c,function(Y,H){return H||String(K[Y])})},L.as=function(A){return this.$ms/g[w(A)]},L.get=function(A){var N=this.$ms,K=w(A);return K==="milliseconds"?N%=1e3:N=K==="weeks"?T(N/g[K]):this.$d[K],N===0?0:N},L.add=function(A,N,K){var Y;return Y=N?A*g[w(N)]:m(A)?A.$ms:C(A,this).$ms,C(this.$ms+Y*(K?-1:1),this)},L.subtract=function(A,N){return this.add(A,N,!0)},L.locale=function(A){var N=this.clone();return N.$l=A,N},L.clone=function(){return C(this.$ms,this)},L.humanize=function(A){return n().add(this.$ms,"ms").locale(this.$l).fromNow(!A)},L.milliseconds=function(){return this.get("milliseconds")},L.asMilliseconds=function(){return this.as("milliseconds")},L.seconds=function(){return this.get("seconds")},L.asSeconds=function(){return this.as("seconds")},L.minutes=function(){return this.get("minutes")},L.asMinutes=function(){return this.as("minutes")},L.hours=function(){return this.get("hours")},L.asHours=function(){return this.as("hours")},L.days=function(){return this.get("days")},L.asDays=function(){return this.as("days")},L.weeks=function(){return this.get("weeks")},L.asWeeks=function(){return this.as("weeks")},L.months=function(){return this.get("months")},L.asMonths=function(){return this.as("months")},L.years=function(){return this.get("years")},L.asYears=function(){return this.as("years")},$}();return function($,L,A){n=A,r=A().$utils(),A.duration=function(Y,H){var se=A.locale();return C(Y,{$l:se},H)},A.isDuration=m;var N=L.prototype.add,K=L.prototype.subtract;L.prototype.add=function(Y,H){return m(Y)&&(Y=Y.asMilliseconds()),N.bind(this)(Y,H)},L.prototype.subtract=function(Y,H){return m(Y)&&(Y=Y.asMilliseconds()),K.bind(this)(Y,H)}}})})(ED);const $D=Hi;var ea={},LD={get exports(){return ea},set exports(e){ea=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){r.prototype.isBetween=function(o,l,u,c){var d=a(o),f=a(l),h=(c=c||"()")[0]==="(",g=c[1]===")";return(h?this.isAfter(d,u):!this.isBefore(d,u))&&(g?this.isBefore(f,u):!this.isAfter(f,u))||(h?this.isBefore(d,u):!this.isAfter(d,u))&&(g?this.isAfter(f,u):!this.isBefore(f,u))}}})})(LD);const OD=ea;var ta={},PD={get exports(){return ta},set exports(e){ta=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){r.prototype.isLeapYear=function(){return this.$y%4==0&&this.$y%100!=0||this.$y%400==0}}})})(PD);const BD=ta;var na={},VD={get exports(){return na},set exports(e){na=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){a.isMoment=function(o){return a.isDayjs(o)}}})})(VD);const ND=na;var ra={},qD={get exports(){return ra},set exports(e){ra=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){var n="day";return function(r,a,o){var l=function(d){return d.add(4-d.isoWeekday(),n)},u=a.prototype;u.isoWeekYear=function(){return l(this).year()},u.isoWeek=function(d){if(!this.$utils().u(d))return this.add(7*(d-this.isoWeek()),n);var f,h,g,m,C=l(this),w=(f=this.isoWeekYear(),h=this.$u,g=(h?o.utc:o)().year(f).startOf("year"),m=4-g.isoWeekday(),g.isoWeekday()>4&&(m+=7),g.add(m,n));return C.diff(w,"week")+1},u.isoWeekday=function(d){return this.$utils().u(d)?this.day()||7:this.day(this.day()%7?d:d-7)};var c=u.startOf;u.startOf=function(d,f){var h=this.$utils(),g=!!h.u(f)||f;return h.p(d)==="isoweek"?g?this.date(this.date()-(this.isoWeekday()-1)).startOf("day"):this.date(this.date()-1-(this.isoWeekday()-1)+7).endOf("day"):c.bind(this)(d,f)}}})})(qD);const FD=ra;var ia={},GD={get exports(){return ia},set exports(e){ia=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){r.prototype.isoWeeksInYear=function(){var a=this.isLeapYear(),o=this.endOf("y").day();return o===4||a&&o===5?53:52}}})})(GD);const WD=ia;var aa={},jD={get exports(){return aa},set exports(e){aa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){r.prototype.isSameOrAfter=function(a,o){return this.isSame(a,o)||this.isAfter(a,o)}}})})(jD);const RD=aa;var sa={},YD={get exports(){return sa},set exports(e){sa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){r.prototype.isSameOrBefore=function(a,o){return this.isSame(a,o)||this.isBefore(a,o)}}})})(YD);const QD=sa;var oa={},UD={get exports(){return oa},set exports(e){oa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){r.prototype.isToday=function(){var o="YYYY-MM-DD",l=a();return this.format(o)===l.format(o)}}})})(UD);const KD=oa;var la={},XD={get exports(){return la},set exports(e){la=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){r.prototype.isTomorrow=function(){var o="YYYY-MM-DD",l=a().add(1,"day");return this.format(o)===l.format(o)}}})})(XD);const JD=la;var ua={},ZD={get exports(){return ua},set exports(e){ua=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){r.prototype.isYesterday=function(){var o="YYYY-MM-DD",l=a().subtract(1,"day");return this.format(o)===l.format(o)}}})})(ZD);const HD=ua;var ca={},eI={get exports(){return ca},set exports(e){ca=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){var o=r.prototype,l=function(h){return h&&(h.indexOf?h:h.s)},u=function(h,g,m,C,w){var _=h.name?h:h.$locale(),T=l(_[g]),M=l(_[m]),P=T||M.map(function($){return $.slice(0,C)});if(!w)return P;var G=_.weekStart;return P.map(function($,L){return P[(L+(G||0))%7]})},c=function(){return a.Ls[a.locale()]},d=function(h,g){return h.formats[g]||function(m){return m.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(C,w,_){return w||_.slice(1)})}(h.formats[g.toUpperCase()])},f=function(){var h=this;return{months:function(g){return g?g.format("MMMM"):u(h,"months")},monthsShort:function(g){return g?g.format("MMM"):u(h,"monthsShort","months",3)},firstDayOfWeek:function(){return h.$locale().weekStart||0},weekdays:function(g){return g?g.format("dddd"):u(h,"weekdays")},weekdaysMin:function(g){return g?g.format("dd"):u(h,"weekdaysMin","weekdays",2)},weekdaysShort:function(g){return g?g.format("ddd"):u(h,"weekdaysShort","weekdays",3)},longDateFormat:function(g){return d(h.$locale(),g)},meridiem:this.$locale().meridiem,ordinal:this.$locale().ordinal}};o.localeData=function(){return f.bind(this)()},a.localeData=function(){var h=c();return{firstDayOfWeek:function(){return h.weekStart||0},weekdays:function(){return a.weekdays()},weekdaysShort:function(){return a.weekdaysShort()},weekdaysMin:function(){return a.weekdaysMin()},months:function(){return a.months()},monthsShort:function(){return a.monthsShort()},longDateFormat:function(g){return d(h,g)},meridiem:h.meridiem,ordinal:h.ordinal}},a.months=function(){return u(c(),"months")},a.monthsShort=function(){return u(c(),"monthsShort","months",3)},a.weekdays=function(h){return u(c(),"weekdays",null,null,h)},a.weekdaysShort=function(h){return u(c(),"weekdaysShort","weekdays",3,h)},a.weekdaysMin=function(h){return u(c(),"weekdaysMin","weekdays",2,h)}}})})(eI);const tI=ca;var da={},nI={get exports(){return da},set exports(e){da=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){var n={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"};return function(r,a,o){var l=a.prototype,u=l.format;o.en.formats=n,l.format=function(c){c===void 0&&(c="YYYY-MM-DDTHH:mm:ssZ");var d=this.$locale().formats,f=function(h,g){return h.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(m,C,w){var _=w&&w.toUpperCase();return C||g[w]||n[w]||g[_].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(T,M,P){return M||P.slice(1)})})}(c,d===void 0?{}:d);return u.call(this,f)}}})})(nI);const rI=da;var pa={},iI={get exports(){return pa},set exports(e){pa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){var o=function(l,u){if(!u||!u.length||!u[0]||u.length===1&&!u[0].length)return null;var c;u.length===1&&u[0].length>0&&(u=u[0]),c=u[0];for(var d=1;d<u.length;d+=1)u[d].isValid()&&!u[d][l](c)||(c=u[d]);return c};a.max=function(){var l=[].slice.call(arguments,0);return o("isAfter",l)},a.min=function(){var l=[].slice.call(arguments,0);return o("isBefore",l)}}})})(iI);const aI=pa;var ha={},sI={get exports(){return ha},set exports(e){ha=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){var o=r.prototype,l=function(g){var m,C=g.date,w=g.utc,_={};if(!((m=C)instanceof Date||m instanceof Array||o.$utils().u(m)||m.constructor.name!=="Object")){if(!Object.keys(C).length)return new Date;var T=w?a.utc():a();Object.keys(C).forEach(function(K){var Y,H;_[Y=K,H=o.$utils().p(Y),H==="date"?"day":H]=C[K]});var M=_.day||(_.year||_.month>=0?1:T.date()),P=_.year||T.year(),G=_.month>=0?_.month:_.year||_.day?0:T.month(),$=_.hour||0,L=_.minute||0,A=_.second||0,N=_.millisecond||0;return w?new Date(Date.UTC(P,G,M,$,L,A,N)):new Date(P,G,M,$,L,A,N)}return C},u=o.parse;o.parse=function(g){g.date=l.bind(this)(g),u.bind(this)(g)};var c=o.set,d=o.add,f=o.subtract,h=function(g,m,C,w){w===void 0&&(w=1);var _=Object.keys(m),T=this;return _.forEach(function(M){T=g.bind(T)(m[M]*w,M)}),T};o.set=function(g,m){return m=m===void 0?g:m,g.constructor.name==="Object"?h.bind(this)(function(C,w){return c.bind(this)(w,C)},m,g):c.bind(this)(g,m)},o.add=function(g,m){return g.constructor.name==="Object"?h.bind(this)(d,g,m):d.bind(this)(g,m)},o.subtract=function(g,m){return g.constructor.name==="Object"?h.bind(this)(d,g,m,-1):f.bind(this)(g,m)}}})})(sI);const oI=ha;var fa={},lI={get exports(){return fa},set exports(e){fa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){var a=r.prototype;["milliseconds","seconds","minutes","hours","days","weeks","isoWeeks","months","quarters","years","dates"].forEach(function(o){a[o]=a[o.replace(/s$/,"")]})}})})(lI);const uI=fa;var ga={},cI={get exports(){return ga},set exports(e){ga=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){var a=r.prototype.parse;r.prototype.parse=function(u){if(typeof u.date=="string"){var c=this.$locale();u.date=c&&c.preparse?c.preparse(u.date):u.date}return a.bind(this)(u)};var o=r.prototype.format;r.prototype.format=function(){for(var u=arguments.length,c=new Array(u),d=0;d<u;d++)c[d]=arguments[d];var f=o.call.apply(o,[this].concat(c)),h=this.$locale();return h&&h.postformat?h.postformat(f):f};var l=r.prototype.fromToBase;l&&(r.prototype.fromToBase=function(u,c,d,f){var h=this.$locale()||d.$locale();return l.call(this,u,c,d,f,h&&h.postformat)})}})})(cI);const dI=ga;var ma={},pI={get exports(){return ma},set exports(e){ma=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){var n="month",r="quarter";return function(a,o){var l=o.prototype;l.quarter=function(d){return this.$utils().u(d)?Math.ceil((this.month()+1)/3):this.month(this.month()%3+3*(d-1))};var u=l.add;l.add=function(d,f){return d=Number(d),this.$utils().p(f)===r?this.add(3*d,n):u.bind(this)(d,f)};var c=l.startOf;l.startOf=function(d,f){var h=this.$utils(),g=!!h.u(f)||f;if(h.p(d)===r){var m=this.quarter()-1;return g?this.month(3*m).startOf(n).startOf("day"):this.month(3*m+2).endOf(n).endOf("day")}return c.bind(this)(d,f)}}})})(pI);const hI=ma;var ya={},fI={get exports(){return ya},set exports(e){ya=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){n=n||{};var o=r.prototype,l={future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"};function u(d,f,h,g){return o.fromToBase(d,f,h,g)}a.en.relativeTime=l,o.fromToBase=function(d,f,h,g,m){for(var C,w,_,T=h.$locale().relativeTime||l,M=n.thresholds||[{l:"s",r:44,d:"second"},{l:"m",r:89},{l:"mm",r:44,d:"minute"},{l:"h",r:89},{l:"hh",r:21,d:"hour"},{l:"d",r:35},{l:"dd",r:25,d:"day"},{l:"M",r:45},{l:"MM",r:10,d:"month"},{l:"y",r:17},{l:"yy",d:"year"}],P=M.length,G=0;G<P;G+=1){var $=M[G];$.d&&(C=g?a(d).diff(h,$.d,!0):h.diff(d,$.d,!0));var L=(n.rounding||Math.round)(Math.abs(C));if(_=C>0,L<=$.r||!$.r){L<=1&&G>0&&($=M[G-1]);var A=T[$.l];m&&(L=m(""+L)),w=typeof A=="string"?A.replace("%d",L):A(L,f,$.l,_);break}}if(f)return w;var N=_?T.future:T.past;return typeof N=="function"?N(w):N.replace("%s",w)},o.to=function(d,f){return u(d,f,this,!0)},o.from=function(d,f){return u(d,f,this)};var c=function(d){return d.$u?a.utc():a()};o.toNow=function(d){return this.to(c(this),d)},o.fromNow=function(d){return this.from(c(this),d)}}})})(fI);const gI=ya;var ba={},mI={get exports(){return ba},set exports(e){ba=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){var n={year:0,month:1,day:2,hour:3,minute:4,second:5},r={};return function(a,o,l){var u,c=function(g,m,C){C===void 0&&(C={});var w=new Date(g),_=function(T,M){M===void 0&&(M={});var P=M.timeZoneName||"short",G=T+"|"+P,$=r[G];return $||($=new Intl.DateTimeFormat("en-US",{hour12:!1,timeZone:T,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:P}),r[G]=$),$}(m,C);return _.formatToParts(w)},d=function(g,m){for(var C=c(g,m),w=[],_=0;_<C.length;_+=1){var T=C[_],M=T.type,P=T.value,G=n[M];G>=0&&(w[G]=parseInt(P,10))}var $=w[3],L=$===24?0:$,A=w[0]+"-"+w[1]+"-"+w[2]+" "+L+":"+w[4]+":"+w[5]+":000",N=+g;return(l.utc(A).valueOf()-(N-=N%1e3))/6e4},f=o.prototype;f.tz=function(g,m){g===void 0&&(g=u);var C=this.utcOffset(),w=this.toDate(),_=w.toLocaleString("en-US",{timeZone:g}),T=Math.round((w-new Date(_))/1e3/60),M=l(_).$set("millisecond",this.$ms).utcOffset(15*-Math.round(w.getTimezoneOffset()/15)-T,!0);if(m){var P=M.utcOffset();M=M.add(C-P,"minute")}return M.$x.$timezone=g,M},f.offsetName=function(g){var m=this.$x.$timezone||l.tz.guess(),C=c(this.valueOf(),m,{timeZoneName:g}).find(function(w){return w.type.toLowerCase()==="timezonename"});return C&&C.value};var h=f.startOf;f.startOf=function(g,m){if(!this.$x||!this.$x.$timezone)return h.call(this,g,m);var C=l(this.format("YYYY-MM-DD HH:mm:ss:SSS"));return h.call(C,g,m).tz(this.$x.$timezone,!0)},l.tz=function(g,m,C){var w=C&&m,_=C||m||u,T=d(+l(),_);if(typeof g!="string")return l(g).tz(_);var M=function(L,A,N){var K=L-60*A*1e3,Y=d(K,N);if(A===Y)return[K,A];var H=d(K-=60*(Y-A)*1e3,N);return Y===H?[K,Y]:[L-60*Math.min(Y,H)*1e3,Math.max(Y,H)]}(l.utc(g,w).valueOf(),T,_),P=M[0],G=M[1],$=l(P).utcOffset(G);return $.$x.$timezone=_,$},l.tz.guess=function(){return Intl.DateTimeFormat().resolvedOptions().timeZone},l.tz.setDefault=function(g){u=g}}})})(mI);const yI=ba;var va={},bI={get exports(){return va},set exports(e){va=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){r.prototype.toArray=function(){return[this.$y,this.$M,this.$D,this.$H,this.$m,this.$s,this.$ms]}}})})(bI);const vI=va;var xa={},xI={get exports(){return xa},set exports(e){xa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){r.prototype.toObject=function(){return{years:this.$y,months:this.$M,date:this.$D,hours:this.$H,minutes:this.$m,seconds:this.$s,milliseconds:this.$ms}}}})})(xI);const wI=xa;var wa={},CI={get exports(){return wa},set exports(e){wa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){a.updateLocale=function(o,l){var u=a.Ls[o];if(u)return(l?Object.keys(l):[]).forEach(function(c){u[c]=l[c]}),u}}})})(CI);const SI=wa;var Ca={},_I={get exports(){return Ca},set exports(e){Ca=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){var n="minute",r=/[+-]\d\d(?::?\d\d)?/g,a=/([+-]|\d\d)/g;return function(o,l,u){var c=l.prototype;u.utc=function(w){var _={date:w,utc:!0,args:arguments};return new l(_)},c.utc=function(w){var _=u(this.toDate(),{locale:this.$L,utc:!0});return w?_.add(this.utcOffset(),n):_},c.local=function(){return u(this.toDate(),{locale:this.$L,utc:!1})};var d=c.parse;c.parse=function(w){w.utc&&(this.$u=!0),this.$utils().u(w.$offset)||(this.$offset=w.$offset),d.call(this,w)};var f=c.init;c.init=function(){if(this.$u){var w=this.$d;this.$y=w.getUTCFullYear(),this.$M=w.getUTCMonth(),this.$D=w.getUTCDate(),this.$W=w.getUTCDay(),this.$H=w.getUTCHours(),this.$m=w.getUTCMinutes(),this.$s=w.getUTCSeconds(),this.$ms=w.getUTCMilliseconds()}else f.call(this)};var h=c.utcOffset;c.utcOffset=function(w,_){var T=this.$utils().u;if(T(w))return this.$u?0:T(this.$offset)?h.call(this):this.$offset;if(typeof w=="string"&&(w=function($){$===void 0&&($="");var L=$.match(r);if(!L)return null;var A=(""+L[0]).match(a)||["-",0,0],N=A[0],K=60*+A[1]+ +A[2];return K===0?0:N==="+"?K:-K}(w),w===null))return this;var M=Math.abs(w)<=16?60*w:w,P=this;if(_)return P.$offset=M,P.$u=w===0,P;if(w!==0){var G=this.$u?this.toDate().getTimezoneOffset():-1*this.utcOffset();(P=this.local().add(M+G,n)).$offset=M,P.$x.$localOffset=G}else P=this.utc();return P};var g=c.format;c.format=function(w){var _=w||(this.$u?"YYYY-MM-DDTHH:mm:ss[Z]":"");return g.call(this,_)},c.valueOf=function(){var w=this.$utils().u(this.$offset)?0:this.$offset+(this.$x.$localOffset||this.$d.getTimezoneOffset());return this.$d.valueOf()-6e4*w},c.isUTC=function(){return!!this.$u},c.toISOString=function(){return this.toDate().toISOString()},c.toString=function(){return this.toDate().toUTCString()};var m=c.toDate;c.toDate=function(w){return w==="s"&&this.$offset?u(this.format("YYYY-MM-DD HH:mm:ss:SSS")).toDate():m.call(this)};var C=c.diff;c.diff=function(w,_,T){if(w&&this.$u===w.$u)return C.call(this,w,_,T);var M=this.local(),P=u(w).local();return C.call(M,P,_,T)}}})})(_I);const kI=Ca;var Sa={},TI={get exports(){return Sa},set exports(e){Sa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){r.prototype.weekday=function(a){var o=this.$locale().weekStart||0,l=this.$W,u=(l<o?l+7:l)-o;return this.$utils().u(a)?u:this.subtract(u,"day").add(a,"day")}}})})(TI);const DI=Sa;var _a={},II={get exports(){return _a},set exports(e){_a=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){var n="week",r="year";return function(a,o,l){var u=o.prototype;u.week=function(c){if(c===void 0&&(c=null),c!==null)return this.add(7*(c-this.week()),"day");var d=this.$locale().yearStart||1;if(this.month()===11&&this.date()>25){var f=l(this).startOf(r).add(1,r).date(d),h=l(this).endOf(n);if(f.isBefore(h))return 1}var g=l(this).startOf(r).date(d).startOf(n).subtract(1,"millisecond"),m=this.diff(g,n,!0);return m<0?l(this).startOf("week").week():Math.ceil(m)},u.weeks=function(c){return c===void 0&&(c=null),this.week(c)}}})})(II);const MI=_a;var ka={},AI={get exports(){return ka},set exports(e){ka=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){r.prototype.weekYear=function(){var a=this.month(),o=this.week(),l=this.year();return o===1&&a===11?l+1:a===0&&o>=52?l-1:l}}})})(AI);const zI=ka;U.extend(wD),U.extend(SD),U.extend(kD),U.extend(DD),U.extend(MD),U.extend(zD),U.extend($D),U.extend(OD),U.extend(BD),U.extend(ND),U.extend(RD),U.extend(QD),U.extend(KD),U.extend(JD),U.extend(HD),U.extend(FD),U.extend(WD),U.extend(tI),U.extend(rI),U.extend(aI),U.extend(oI),U.extend(uI),U.extend(dI),U.extend(hI),U.extend(gI),U.extend(yI),U.extend(vI),U.extend(wI),U.extend(SI),U.extend(kI),U.extend(MI),U.extend(zI),U.extend(DI),U.tz.setDefault("UTC");const EI=()=>Promise.resolve().then(()=>cc).then(({version:e})=>(console.log(`[@devtable/dashboard] version: ${e}`),e));I.ContentModel=Vi,I.ContentModelContextProvider=Dr,I.DashboardEditor=gD,I.DashboardFilterType=xe,I.DashboardMode=ql,I.DashboardModel=Kl,I.DashboardModelContextProvider=_r,I.DashboardViewEditor=Nl,I.DashboardViewRender=cr,I.DescriptionPopover=$i,I.FiltersModel=Gl,I.FullScreenPanel=Ll,I.FullScreenPanelContext=Mr,I.LayoutStateContext=An,I.Panel=$l,I.PanelContextProvider=Ir,I.PanelErrorOrStateMessage=zl,I.PanelModel=Rl,I.PanelRender=Oi,I.PanelVizSection=Li,I.PanelsModel=Yl,I.QueriesModel=Wl,I.ReadOnlyDashboard=vD,I.SQLSnippetsModel=jl,I.ViewComponentTypeBackground=Fl,I.ViewComponentTypeColor=c_,I.ViewComponentTypeName=u_,I.ViewsModel=Ql,I.Viz=Al,I.applyPartialDashboard=C_,I.createContentModel=Ul,I.createDashboardModel=Xl,I.getInitialDashboardViewsModel=Bi,I.getVersion=EI,I.initialDashboardContent=d_,I.useDashboardContext=kr,I.useEditContentModelContext=le,I.useEditDashboardContext=ue,I.useEditPanelContext=rt,I.useFullScreenPanelContext=ds,I.usePanelFullScreen=Ol,I.useRenderContentModelContext=ye,I.useRenderDashboardContext=Tr,I.useRenderPanelContext=Ct,Object.defineProperty(I,Symbol.toStringTag,{value:"Module"})});
|
|
531
|
+
`,fu=k.observer(function({showSQLSnippets:t=!0,sx:n={}}){const r=ue(),a=le(),o=r.context.current,l=(()=>{const u={context:{...a.mock_context.current,...o},filters:a.filters.previewValues};return t&&(u.sql_snippets=a.sqlSnippets.record),JSON.stringify(u,null,2)})();return i(s.Stack,{sx:{overflow:"hidden",...n},children:p(s.Tabs,{defaultValue:"guide",keepMounted:!1,children:[p(s.Tabs.List,{grow:!0,children:[i(s.Tabs.Tab,{value:"guide",icon:i(E.IconAlertCircle,{size:14}),children:"Guide"}),i(s.Tabs.Tab,{value:"local_query_vars",icon:i(E.IconVariable,{size:14}),children:"Variables in this dashboard"}),i(s.Tabs.Tab,{value:"global_sql_snippets",icon:i(E.IconVariablePlus,{size:14}),children:"Global SQL Snippets"})]}),i(s.Tabs.Panel,{value:"guide",pt:"xs",children:i(Mt.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:bT})}),i(s.Tabs.Panel,{value:"local_query_vars",pt:"xs",children:i(Mt.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:l})}),i(s.Tabs.Panel,{value:"global_sql_snippets",pt:"xs",children:p(s.Stack,{spacing:10,children:[i(s.Alert,{icon:i(E.IconAlertCircle,{size:16}),title:"Global SQL Snippets",children:"SQL snippets worth sharing between dashboards are managed in System Settings by admins."}),i(yT,{})]})})]})})}),Ri=k.observer(()=>{const[e,t]=y.useState(!1);return p(B,{children:[i(s.Modal,{opened:e,onClose:()=>t(!1),title:"Query Variables",zIndex:320,size:"800px",children:i(fu,{})}),i(s.Button,{variant:"subtle",onClick:()=>t(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},children:"See Query Variables"})]})}),gu={pre:["function build_request({ context, filters }, utils) {"," // build the quest"," return { method: 'POST', url: '/', params: {}, headers: {}, data: {} }","}"].join(`
|
|
532
|
+
`),post:["function process_result(res, utils, state) {"," // your code goes here"," return data","}"].join(`
|
|
533
|
+
`)},vT=k.observer(({queryModel:e})=>e.typedAsHTTP?p(s.Tabs,{defaultValue:"pre_process",orientation:"vertical",sx:{flexGrow:1},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"pre_process",children:"Build Request"}),i(s.Tabs.Tab,{value:"post_process",children:"Process Result"}),i(Ri,{})]}),i(s.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:i(fn,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:gu.pre})}),i(s.Tabs.Panel,{value:"post_process",p:"sm",children:i(fn,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:gu.post})})]}):null),xT=k.observer(({queryID:e,usage:t})=>{const n=ue().editor,r=o=>{if(o.type==="filter"){n.setPath(["_FILTERS_",o.id]);return}if(o.type==="panel"){const l=o.views[0].id;n.setPath(["_VIEWS_",l,"_PANELS_",o.id]);return}},a=o=>{n.setPath(["_VIEWS_",o])};return i(s.Stack,{py:"sm",px:"md",children:p(s.Table,{highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[i("thead",{children:p("tr",{children:[i("th",{style:{width:100},children:"Type"}),i("th",{style:{width:"calc(50% - 50px)"},children:"Name"}),i("th",{children:"In View(s)"})]})}),i("tbody",{children:t.map(o=>p("tr",{children:[i("td",{children:x.capitalize(o.type)}),i("td",{children:i(s.Anchor,{component:"button",type:"button",onClick:()=>r(o),children:o.label})}),i("td",{children:p(s.Stack,{align:"flex-start",justify:"flex-start",spacing:2,children:[o.views.map(l=>i(s.Anchor,{component:"button",type:"button",onClick:()=>a(l.id),children:i(s.Box,{children:l.label})})),o.views.length===0&&i(s.Box,{children:"--"})]})})]},o.id))})]})})}),Yi=({value:e,onChange:t,height:n="200px",defaultLanguage:r="sql",theme:a="vs-dark"})=>{const o=u=>{t==null||t(u??"")},l=!t;return i(De,{className:"minimal-monaco-editor",height:n,defaultLanguage:r,value:e,onChange:l?void 0:o,theme:a,options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1},readOnly:l||!t,"semanticHighlighting.enabled":!0}})},wT=({value:e,onChange:t,defaultValue:n})=>{const[r,a]=y.useState(e),o=()=>{t(r)},l=()=>{a(e)},u=()=>{a(n)};y.useEffect(()=>{a(e)},[e]);const c=r!==e;return p(s.Stack,{spacing:4,sx:{height:"100%"},children:[p(s.Group,{mb:6,position:"apart",sx:{flexShrink:0,flexGrow:0},children:[i(s.Group,{position:"left",children:i(s.Button,{onClick:u,size:"xs",variant:"default",leftIcon:i(E.IconPlayerSkipBack,{size:16}),children:"Reset to default"})}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:l,color:"red",size:"xs",disabled:!c,leftIcon:i(E.IconRecycle,{size:16}),children:"Revert Changes"}),i(s.Button,{size:"xs",onClick:o,disabled:!c,leftIcon:i(E.IconDeviceFloppy,{size:16}),children:"Confirm Changes"})]})]}),i(Yi,{height:"100%",value:r,onChange:a,theme:"sql-dark",defaultLanguage:"sql"})]})},CT=({value:e,height:t="200px",defaultLanguage:n="sql"})=>i(De,{className:"preview-sql-in-monaco-editor",height:t,defaultLanguage:n,value:e,onChange:void 0,theme:"vs-light",options:{lineNumbers:"on",folding:!0,lineDecorationsWidth:20,wordWrap:"on",minimap:{enabled:!1},readOnly:!0}}),ST=k.observer(({value:e})=>{const n=ye().payloadForSQL,r=y.useMemo(()=>xr(e,n),[e,n]);return i(CT,{height:"100%",value:r})}),mu={pre:["function process_request({ context, filters, sql }, utils) {"," // modify and return sql"," return sql","}"].join(`
|
|
534
|
+
`),post:["function process_result(data, utils, state) {"," // process data and return the result"," return data","}"].join(`
|
|
535
|
+
`)},_T=k.observer(({queryModel:e})=>e.typedAsSQL?p(s.Tabs,{defaultValue:"Edit",orientation:"vertical",sx:{flexGrow:1},styles:{tabLabel:{width:"100%",height:"28px",lineHeight:"28px"}},keepMounted:!1,children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Edit",children:i(s.Group,{spacing:14,position:"apart",children:"Edit SQL"})}),i(s.Tabs.Tab,{value:"Preview",children:"Preview SQL"}),i(s.Tabs.Tab,{value:"pre_process",children:"Process Request"}),i(s.Tabs.Tab,{value:"post_process",children:"Process Result"}),i(Ri,{}),e.datasource&&i(pu,{dataSource:e.datasource})]}),i(s.Tabs.Panel,{value:"Edit",sx:{position:"relative"},p:"sm",children:i(wT,{value:e.sql,onChange:e.setSQL,defaultValue:"SELECT 1"})}),i(s.Tabs.Panel,{value:"Preview",p:0,pl:4,children:i(ST,{value:e.sql})}),i(s.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:i(fn,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:mu.pre})}),i(s.Tabs.Panel,{value:"post_process",p:"sm",children:i(fn,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:mu.post})})]}):null),hr={height:"calc(100% - 44px)",padding:0},kT=k.observer(({queryModel:e})=>{const t=le(),n=y.useMemo(()=>e.datasource?e.typedAsHTTP?"HTTP":"SQL":"Configurations",[e.datasource,e.typedAsHTTP]),[r,a]=y.useState(n);y.useEffect(()=>{a(u=>u!=="Configurations"&&n==="Configurations"?"Configurations":u)},[n]);const o=t.findQueryUsage(e.id),l=o.length===0;return i(s.Stack,{sx:{flexGrow:1},my:0,p:0,children:p(s.Tabs,{value:r,onTabChange:a,defaultValue:n,orientation:"horizontal",keepMounted:!1,sx:{flexGrow:1},children:[p(s.Tabs.List,{grow:!0,children:[i(s.Tabs.Tab,{value:"Configurations",children:"Configurations"}),e.typedAsSQL&&i(s.Tabs.Tab,{value:"SQL",children:"Request"}),e.typedAsHTTP&&i(s.Tabs.Tab,{value:"HTTP",children:"Request"}),i(s.Tabs.Tab,{value:"Data",disabled:!e.datasource,children:i(s.Tooltip,{label:"Need to pick a Data Source first",disabled:e.datasource,withinPortal:!0,children:i(s.Text,{children:"Data"})})}),i(s.Tabs.Tab,{value:"Usage",disabled:l,children:i(s.Tooltip,{label:"This query is not used for any filter or panel",disabled:!l,withinPortal:!0,children:i(s.Text,{children:"Usage"})})})]}),i(s.Tabs.Panel,{value:"Configurations",pt:0,p:0,children:i(gT,{queryModel:e})}),e.typedAsSQL&&i(s.Tabs.Panel,{value:"SQL",sx:hr,children:i(s.Stack,{sx:{height:"100%"},children:i(_T,{queryModel:e})})}),e.typedAsHTTP&&i(s.Tabs.Panel,{value:"HTTP",sx:hr,children:i(s.Stack,{sx:{height:"100%"},children:i(vT,{queryModel:e})})}),i(s.Tabs.Panel,{value:"Data",sx:{...hr,overflow:"hidden"},children:i(Wi,{id:e.id})}),i(s.Tabs.Panel,{value:"Usage",sx:{...hr,overflow:"hidden"},children:i(xT,{queryID:e.id,usage:o})})]})})}),TT=k.observer(({id:e})=>{const n=le().queries.findByID(e);return e===""?null:n?i(s.Stack,{sx:{height:"100%"},spacing:"sm",children:i(kT,{queryModel:n})}):i(s.Text,{size:14,color:"red",children:"Invalid Query ID"})}),DT=k.observer(({value:e})=>{const n=ye().payloadForSQL,r=y.useMemo(()=>xr(e,n),[e,n]);return i(Yi,{height:"100%",value:r})}),IT=k.observer(({item:e,remove:t,onKeyChanged:n})=>{const[r,a]=y.useState("SQL"),[o,l]=y.useState(e.key),u=()=>{e.setKey(o),n(o)},c=o!==e.key,d=e.isADuplicatedKey(o),[f,h]=y.useState(e.value),g=()=>{e.setValue(f)};y.useEffect(()=>{l(e.key),h(e.value)},[e]);const m=f!==e.value,C=Ge.useModals(),w=()=>{C.openConfirmModal({title:"Delete this SQL snippet?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:t,confirmProps:{color:"red"},zIndex:320})};return p(s.Stack,{p:20,sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",children:[p(s.Group,{sx:{alignItems:"end"},spacing:40,children:[i(s.TextInput,{label:d?"This key is occupied by another snippet":"Key",value:o,onChange:_=>{l(_.currentTarget.value)},sx:{flexGrow:"1 !important"},rightSection:i(s.ActionIcon,{color:"blue",variant:"subtle",onClick:u,disabled:!c||d,children:i(D.DeviceFloppy,{size:16})}),error:d}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:w,children:"Delete this SQL Snippet"})]}),p(s.Tabs,{value:r,onTabChange:a,sx:{flexGrow:1},styles:{panel:{height:"calc(100% - 50px)"}},children:[p(s.Tabs.List,{sx:{position:"relative"},children:[i(s.Tabs.Tab,{value:"SQL",children:"SQL"}),i(s.Tabs.Tab,{value:"Preview",children:"Preview"}),i(Ri,{}),i(s.ActionIcon,{color:"blue",variant:"filled",onClick:g,disabled:!m,sx:{position:"absolute",top:0,right:10},children:i(D.DeviceFloppy,{size:18})})]}),i(s.Tabs.Panel,{value:"SQL",pt:"sm",children:i(Yi,{height:"100%",value:f,onChange:h,defaultLanguage:"sql",theme:"sql-dark"})}),i(s.Tabs.Panel,{value:"Preview",pt:"sm",children:i(DT,{value:f})})]})]})}),MT=k.observer(({id:e})=>{const t=ue(),n=le(),r=y.useMemo(()=>n.sqlSnippets.findByKey(e),[e]);if(!e)return null;if(!r)return p(s.Text,{size:14,children:["SQL Snippet by key[",e,"] is not found"]});const a=()=>{t.editor.setPath(["_SQL_SNIPPETS_",""])};return i(IT,{item:r,remove:()=>{n.sqlSnippets.removeByKey(e),a()},onKeyChanged:u=>{t.editor.setPath(["_SQL_SNIPPETS_",u])}})}),AT=k.observer(({view:e})=>!e||e.type!==j.Division?null:p(s.Stack,{children:[i(s.Divider,{mt:8,mb:0,label:"Division settings",labelPosition:"center"}),i(s.Text,{align:"center",size:"xs",color:"dimmed",children:"Under construction"})]})),zT=[{value:"default",label:"Default"},{value:"outline",label:"Outline"},{value:"pills",label:"Pills"}],ET=[{value:"horizontal",label:"Horizontal"},{value:"vertical",label:"Vertical"}],$T=k.observer(({view:e})=>{if(!e||e.type!==j.Tabs)return null;const t=e.config;return p(s.Stack,{children:[i(s.Divider,{mt:8,mb:0,label:"Tabs settings",labelPosition:"center"}),i(s.Select,{label:"Variant",value:t.variant,onChange:t.setVariant,data:zT}),i(s.Select,{label:"Orientation",value:t.orientation,onChange:t.setOrientation,data:ET}),i(s.Switch,{label:"Grow Tabs",checked:t.grow,onChange:n=>t.setGrow(n.currentTarget.checked)})]})}),LT=({disabled:e,value:t,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[e&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(De,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},OT=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:a}]=Q.useBoolean(),[o,l]=y.useState(e??zi),u=g=>{l({...o,enabled:g})},c=()=>{a();const{enabled:g,func_content:m}=o,C={enabled:g,func_content:m};l(C),t(C)},d=()=>{a(),l(e)},f=g=>{l(m=>({...m,func_content:g}))},h=()=>{f(zi.func_content)};return p(B,{children:[i(s.ActionIcon,{size:"lg",color:"blue",variant:"filled",mt:26,onClick:r,sx:{flexGrow:0},children:i(D.Settings,{size:14})}),i(s.Modal,{size:800,title:"Customize modal title",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:o.enabled,onChange:g=>u(g.currentTarget.checked)}),i(LT,{value:o.func_content,onChange:f,disabled:!o.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:h,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:c,children:"OK"})]})]})]})})]})},PT=k.observer(({view:e})=>{if(!e||e.type!==j.Modal)return null;const t=e.config,n=t.custom_modal_title.value;return p(s.Stack,{children:[i(s.Divider,{mt:8,label:"Modal settings",labelPosition:"center"}),p(s.Flex,{gap:10,children:[i(s.TextInput,{label:"Modal Title",value:n,onChange:x.noop,disabled:!0,sx:{flexGrow:1}}),i(OT,{value:t.custom_modal_title,onChange:t.custom_modal_title.replace})]}),p(s.Group,{grow:!0,children:[i(s.TextInput,{label:"Width",value:t.width,onChange:r=>t.setWidth(r.currentTarget.value),placeholder:"600px / 50vw"}),i(s.TextInput,{label:"Height",value:t.height,onChange:r=>t.setHeight(r.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),BT=k.observer(({view:e})=>p(B,{children:[i(AT,{view:e}),i(PT,{view:e}),i($T,{view:e})]})),VT=[{label:"Division",value:j.Division},{label:"Modal",value:j.Modal},{label:"Tabs",value:j.Tabs}],NT=k.observer(({view:e})=>e?p(s.Stack,{sx:{position:"relative"},children:[i(s.TextInput,{label:"Name",value:e.name,onChange:t=>{e.setName(t.currentTarget.value)}}),i(s.Select,{label:"Type",withinPortal:!0,zIndex:320,value:e.type,onChange:e.setType,data:VT}),i(BT,{view:e})]}):null),qT=k.observer(({id:e})=>{const t=Ge.useModals(),n=ue(),r=le();if(e==="")return null;const a=r.views.findByID(e);if(!a)return p(s.Text,{size:14,children:["View by ID[",e,"] is not found"]});const o=()=>{n.editor.setPath(["_VIEWS_",""])},l=()=>{t.openConfirmModal({title:"Delete this view?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.views.removeByID(e),o()},zIndex:320})};return p(s.Stack,{sx:{maxWidth:"600px",height:"100%"},spacing:"sm",children:[i(s.Group,{position:"right",pt:10,children:i(s.Button,{size:"xs",color:"red",leftIcon:i(D.Trash,{size:16}),onClick:l,children:"Delete this view"})}),i(s.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:i(NT,{view:a})})]})});function FT(e){return e.length===1&&e[0]==="_QUERY_VARS_"}function GT(e){return e.length===1&&e[0]==="_MOCK_CONTEXT_"}function WT(e){return e.length===2&&e[0]==="_FILTERS_"}function jT(e){return e.length===1&&e[0]==="_SQL_SNIPPETS_"}function RT(e){return e.length===2&&e[0]==="_SQL_SNIPPETS_"}function YT(e){return e.length===2&&e[0]==="_QUERIES_"}function QT(e){return e.length===1&&e[0]==="_QUERIES_"}function UT(e){return e.length===2&&e[0]==="_VIEWS_"}function KT(e){return e.length===4&&e[0]==="_VIEWS_"&&e[2]==="_PANELS_"}const XT=k.observer(()=>i(s.Stack,{sx:{height:"100%"},p:"sm",children:i(fu,{})})),JT=k.observer(()=>{const e=Ge.useModals(),t=ue(),n=o=>{t.editor.setPath(["_QUERIES_",o])},r=()=>{e.openConfirmModal({title:"Delete ununsed queries?",children:i(s.Text,{size:"sm",children:"This action cannot be undone."}),labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>t.content.removeUnusedQueries(),confirmProps:{color:"red"},zIndex:320})},a=t.content.queriesUsage;return p(s.Stack,{sx:{height:"100%"},spacing:"sm",pb:"59px",children:[i(s.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:i(s.Text,{px:"md",align:"left",sx:{userSelect:"none",cursor:"default"},children:"Manage Queries"})}),i(s.Flex,{justify:"flex-end",align:"center",px:12,children:i(s.Button,{variant:"subtle",size:"xs",color:"red",leftIcon:i(E.IconTrash,{size:14}),disabled:!t.content.hasUnusedQueries,onClick:r,children:"Delete unused queries"})}),i(s.Box,{sx:{flexGrow:1,overflow:"auto"},children:p(s.Table,{fontSize:"sm",highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[i("thead",{children:p("tr",{children:[i("th",{children:"Name"}),i("th",{style:{width:"200px"},children:"Data Source"}),i("th",{style:{width:"100px",textAlign:"right"},children:"Type"}),i("th",{style:{width:"100px",textAlign:"center"},children:"Usage"}),i("th",{style:{width:"300px",paddingLeft:"24px"},children:"Action"})]})}),i("tbody",{children:t.content.queries.sortedList.map(o=>{var u;const l=((u=a[o.id])==null?void 0:u.length)??0;return p("tr",{children:[i("td",{children:o.name}),i("td",{children:o.key}),i("td",{style:{textAlign:"right"},children:o.type}),i("td",{style:{color:l===0?"#ff0000":"#000",fontWeight:l===0?"bold":"normal",textAlign:"center"},children:l}),i("td",{children:i(s.Button,{variant:"subtle",size:"xs",onClick:()=>n(o.id),children:"Open"})})]},o.id)})})]})})]})}),ZT=k.observer(()=>{const e=Ge.useModals(),t=ue(),n=o=>{t.editor.setPath(["_SQL_SNIPPETS_",o])},r=()=>{e.openConfirmModal({title:"Delete ununsed SQL snippets?",children:i(s.Text,{size:"sm",children:"This action cannot be undone."}),labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>t.content.removeUnusedSQLSnippets(),confirmProps:{color:"red"},zIndex:320})},a=t.content.sqlSnippetsUsage;return p(s.Stack,{sx:{height:"100%"},spacing:"sm",pb:"59px",children:[i(s.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:i(s.Text,{px:"md",align:"left",sx:{userSelect:"none",cursor:"default"},children:"Manage SQL Snippets"})}),i(s.Flex,{justify:"flex-end",align:"center",px:12,children:i(s.Button,{variant:"subtle",size:"xs",color:"red",leftIcon:i(E.IconTrash,{size:14}),disabled:!t.content.hasUnusedSQLSnippets,onClick:r,children:"Delete unused SQL snippets"})}),i(s.Box,{sx:{flexGrow:1,overflow:"auto"},children:p(s.Table,{fontSize:"sm",highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[i("thead",{children:p("tr",{children:[i("th",{children:"Key"}),i("th",{style:{width:"100px",textAlign:"center"},children:"Usage"}),i("th",{style:{width:"300px",paddingLeft:"24px"},children:"Action"})]})}),i("tbody",{children:t.content.sqlSnippets.sortedList.map(o=>{var u;const l=((u=a[o.key])==null?void 0:u.length)??0;return p("tr",{children:[i("td",{children:o.key}),i("td",{style:{color:l===0?"#ff0000":"#000",fontWeight:l===0?"bold":"normal",textAlign:"center"},children:l}),i("td",{children:i(s.Button,{variant:"subtle",size:"xs",onClick:()=>n(o.key),children:"Open"})})]},o.key)})})]})})]})}),HT=k.observer(()=>{const e=ue().editor,t=e.path;return FT(t)?i(XT,{}):GT(t)?i(vk,{}):WT(t)?i(s.Box,{p:"xs",pl:20,children:i(bk,{id:t[1]})}):jT(t)?i(ZT,{}):RT(t)?i(MT,{id:t[1]}):QT(t)?i(JT,{}):YT(t)?i(TT,{id:t[1]}):UT(t)?i(s.Box,{p:"xs",pl:20,children:i(qT,{id:t[1]})}):KT(t)?i(Uk,{viewID:t[1],panelID:t[3]}):i(s.Box,{children:e.path})}),eD=k.observer(()=>i(HT,{})),tD=k.observer(()=>{const e=ue(),t=()=>{const n=new Date().getTime().toString(),r={id:n,key:n,label:n,order:e.content.filters.current.length+1,type:xe.TextInput,config:ll(),visibleInViewsIDs:["Main"],auto_submit:!1};e.content.filters.append(r),e.editor.setPath(["_FILTERS_",n])};return i(s.Button,{variant:"subtle",leftIcon:i(E.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Filter"})}),nD=k.observer(({parentID:e})=>{const t=le();if(!e)return null;const n=t.views.findByID(e);return!n||n.type===j.Tabs?null:i(s.Button,{variant:"subtle",leftIcon:i(E.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:()=>t.addANewPanel(n.id),sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Panel"})}),rD=k.observer(()=>{const e=ue(),t=()=>{const n=new Date().getTime().toString(),r={id:n,name:n,type:ve.Postgresql,key:"",sql:""};e.content.queries.append(r),e.editor.setPath(["_QUERIES_",n])};return i(s.Button,{variant:"subtle",leftIcon:i(E.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Query"})}),iD=k.observer(()=>{const e=ue(),t=()=>{const n=new Date().getTime().toString(),r={key:n,value:""};e.content.sqlSnippets.append(r),e.editor.setPath(["_SQL_SNIPPETS_",n])};return i(s.Button,{variant:"subtle",leftIcon:i(E.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a SQL Snippet"})}),aD=k.observer(()=>{const e=le();return i(s.Button,{variant:"subtle",leftIcon:i(E.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:e.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a View"})}),sD=k.observer(()=>{const e=ue();return i(s.Button,{variant:"subtle",rightIcon:i(E.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>e.editor.setPath(["_QUERIES_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:"Manage Queries"})}),oD=k.observer(()=>{const e=ue();return i(s.Button,{variant:"subtle",rightIcon:i(E.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>e.editor.setPath(["_SQL_SNIPPETS_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:"Manage SQL Snippets"})}),lD=k.observer(({action_type:e,parentID:t})=>e==="_Add_A_Filter_"?i(tD,{}):e==="_Add_A_SQL_SNIPPET_"?i(iD,{}):e==="_Add_A_QUERY_"?i(rD,{}):e==="_Add_A_VIEW_"?i(aD,{}):e==="_Add_A_PANEL_"?i(nD,{parentID:t}):e==="_QUERIES_SETTINGS_"?i(sD,{}):e==="_SQL_SNIPPETS_SETTINGS_"?i(oD,{}):null),yu=k.observer(({option:e})=>{var d;const t=ue().editor,n=t.isOptionActive,r=n(t.path,e),a=t.isOptionOpened,o=t.navigate,l=a(e),[u,c]=y.useState(l);return y.useEffect(()=>{c(l)},[l]),i(s.NavLink,{active:r,defaultOpened:l,opened:u,onChange:c,label:e.label,onClick:()=>o(e),icon:e.Icon?i(e.Icon,{size:18}):null,children:(d=e.children)==null?void 0:d.map(f=>f._type==="ACTION"?i(lD,{action_type:f._action_type,parentID:f.parentID},`_ADD_${f.value}_`):i(yu,{option:f},f.value))},e.label)}),uD=k.observer(()=>{const e=ue();return i(s.Box,{sx:{position:"relative"},children:e.editor.navOptions.map(t=>i(yu,{option:t},t.value))})}),cD=k.observer(()=>{const e=ue();return p(s.Navbar,{p:0,width:{base:220,xs:220,sm:240,md:260,lg:300,xl:320},sx:{height:"100vh - 60px - 60px"},children:[i(s.Navbar.Section,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:i(s.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Settings"})}),i(s.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:i(uD,{})}),i(s.Navbar.Section,{children:i(s.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:i(s.Button,{size:"xs",color:"red",leftIcon:i(E.IconX,{size:18}),onClick:()=>e.editor.close(),children:"Close"})})})]})}),dD={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"}},pD=k.observer(()=>{const e=ue().editor;return i(s.Modal,{onClose:()=>e.setSettingsOpen(!1),closeOnEscape:!1,closeOnClickOutside:!1,opened:e.settings_open,fullScreen:!0,title:null,transitionProps:{duration:0},withCloseButton:!1,withinPortal:!0,zIndex:300,styles:{body:{padding:"0 !important"}},children:i(s.AppShell,{padding:0,navbar:i(cD,{}),styles:dD,children:i(eD,{})})})}),hD=e=>e.replace(/([^:])(\/\/+)/g,"$1/");function fD(e){y.useEffect(()=>{if(De.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const n=hD(e);De.loader.config({paths:{vs:n}}),De.loader.init().then(r=>console.log("monaco instance:",r))},[])}ho();const gD={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:60+30,height:"100vh"}},mD=({context:e,dashboard:t,content:n,update:r,className:a="dashboard",config:o,onChange:l,headerSlot:u},c)=>{fD(o.monacoPath),es(o);const{data:d=[]}=Q.useRequest(wr),{data:f=[]}=Q.useRequest(rs),h=y.useMemo(()=>Zl(t,n,d,f,e),[t,n]);y.useImperativeHandle(c,()=>h,[h]),Hl(h.content,!0),y.useEffect(()=>{h.context.replace(e)},[e]),y.useEffect(()=>{h.datasources.replace(d)},[d]),y.useEffect(()=>{h.globalSQLSnippets.replace(f)},[f]),y.useEffect(()=>te.reaction(()=>te.toJS(h.json),w=>{l==null||l(w)}),[h]);const g=async()=>{await r(h.json,h.content.json)},m=Q.useCreation(Ii,[]),C=eu(m);return i(Ge.ModalsProvider,{children:i(_r,{value:h,children:i(Dr,{value:h.content,children:i(An.Provider,{value:{inEditMode:!0},children:i(ct.Provider,{value:m,children:p(ar,{configure:C,children:[i(s.AppShell,{padding:0,header:i(A_,{saveDashboardChanges:g,headerSlot:u}),navbar:i(rk,{}),styles:gD,children:i(s.Box,{className:`${a} dashboard-root`,sx:{position:"relative"},children:h.content.views.visibleViews.map(w=>i(Fl,{view:w},w.id))})}),i(pD,{})]})})})})})})},yD=k.observer(y.forwardRef(mD)),SM="",bu=b.types.model({id:b.types.string,name:b.types.string,dashboard_id:b.types.string,create_time:b.types.string,update_time:b.types.string,version:b.types.string,filters:wl,queries:Tl,sqlSnippets:Dl,views:yl,panels:vl,mock_context:el}).views(e=>({get json(){return{id:e.id,name:e.name,create_time:e.create_time,update_time:e.update_time,dashboard_id:e.dashboard_id,content:{views:e.views.json,panels:e.panels.json,filters:e.filters.json,version:e.version,definition:{queries:e.queries.json,sqlSnippets:e.sqlSnippets.json,mock_context:e.mock_context.current}}}},get payloadForSQL(){const t=b.getParent(e).context.current,n=b.getParent(e).globalSQLSnippets,r={context:{...e.mock_context.current,...t},filters:e.filters.values};return{...r,sql_snippets:lr(e.sqlSnippets.current,"key","value",r),global_sql_snippets:lr(n.list,"id","content",r)}},get payloadForViz(){const t=b.getParent(e).context.current;return{context:{...e.mock_context.current,...t},filters:e.filters.values}},get data(){return e.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(t){const n=e.queries.findByID(t);return n?{data:n.data,len:n.data.length,state:n.state,error:n.error}:{data:[],len:0,state:"idle",error:void 0}}})).actions(e=>({}));function bD({id:e,name:t,dashboard_id:n,create_time:r,update_time:a,content:o}){if(!o)throw new Error("unexpected null content when creating a content model");const{version:l,filters:u,views:c,panels:d,definition:{queries:f,sqlSnippets:h,mock_context:g={}}}=o;return bu.create({id:e,name:t,dashboard_id:n,create_time:r,update_time:a,version:l,filters:Cl(u),queries:IS(f),sqlSnippets:AS(h),mock_context:tl(g),views:mS(c),panels:{list:d}})}const vD=b.types.model({id:b.types.identifier,name:b.types.string,group:b.types.string,content:bu,content_id:b.types.string,datasources:hS,globalSQLSnippets:gl,context:Ei});function xD({id:e,name:t,group:n,content_id:r},a,o,l,u){return vD.create({id:e,name:t,group:n,content_id:r,content:bD(a),datasources:{list:o},globalSQLSnippets:{list:l},context:ml(u)})}ho();const wD=k.observer(({context:e,dashboard:t,content:n,className:r="dashboard",config:a,fullScreenPanelID:o,setFullScreenPanelID:l})=>{es(a);const{data:u=[]}=Q.useRequest(wr),{data:c=[]}=Q.useRequest(rs),d=y.useMemo(()=>xD(t,n,u,c,e),[t,n]);Hl(d.content,!1),y.useEffect(()=>{d.context.replace(e)},[e]),y.useEffect(()=>{d.datasources.replace(u)},[u]),y.useEffect(()=>{d.globalSQLSnippets.replace(c)},[c]);const f=Q.useCreation(Ii,[]),h=eu(f);return i(Ge.ModalsProvider,{children:i(_r,{value:d,children:i(Dr,{value:d.content,children:i(Mr.Provider,{value:{fullScreenPanelID:o,setFullScreenPanelID:l},children:i(An.Provider,{value:{inEditMode:!1},children:i(s.Box,{className:`${r} dashboard-root`,children:i(ct.Provider,{value:f,children:i(ar,{configure:h,children:d.content.views.visibleViews.map(g=>i(cr,{view:g},g.id))})})})})})})})})});var Qi={},CD={get exports(){return Qi},set exports(e){Qi=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){var a=r.prototype,o=a.format;a.format=function(l){var u=this,c=this.$locale();if(!this.isValid())return o.bind(this)(l);var d=this.$utils(),f=(l||"YYYY-MM-DDTHH:mm:ssZ").replace(/\[([^\]]+)]|Q|wo|ww|w|WW|W|zzz|z|gggg|GGGG|Do|X|x|k{1,2}|S/g,function(h){switch(h){case"Q":return Math.ceil((u.$M+1)/3);case"Do":return c.ordinal(u.$D);case"gggg":return u.weekYear();case"GGGG":return u.isoWeekYear();case"wo":return c.ordinal(u.week(),"W");case"w":case"ww":return d.s(u.week(),h==="w"?1:2,"0");case"W":case"WW":return d.s(u.isoWeek(),h==="W"?1:2,"0");case"k":case"kk":return d.s(String(u.$H===0?24:u.$H),h==="k"?1:2,"0");case"X":return Math.floor(u.$d.getTime()/1e3);case"x":return u.$d.getTime();case"z":return"["+u.offsetName()+"]";case"zzz":return"["+u.offsetName("long")+"]";default:return h}});return o.bind(this)(f)}}})})(CD);const SD=Qi;var Ui={},_D={get exports(){return Ui},set exports(e){Ui=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){var o=r.prototype,l=function(c){var d=c.date,f=c.utc;return Array.isArray(d)?f?d.length?new Date(Date.UTC.apply(null,d)):new Date:d.length===1?a(String(d[0])).toDate():new(Function.prototype.bind.apply(Date,[null].concat(d))):d},u=o.parse;o.parse=function(c){c.date=l.bind(this)(c),u.bind(this)(c)}}})})(_D);const kD=Ui;var Ki={},TD={get exports(){return Ki},set exports(e){Ki=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){var a=r.prototype,o=a.format;a.format=function(l){var u=this,c=(l||"YYYY-MM-DDTHH:mm:ssZ").replace(/(\[[^\]]+])|BBBB|BB/g,function(d,f){var h,g=String(u.$y+543),m=d==="BB"?[g.slice(-2),2]:[g,4];return f||(h=u.$utils()).s.apply(h,m.concat(["0"]))});return o.bind(this)(c)}}})})(TD);const DD=Ki;var Xi={},ID={get exports(){return Xi},set exports(e){Xi=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){var o="h:mm A",l={lastDay:"[Yesterday at] "+o,sameDay:"[Today at] "+o,nextDay:"[Tomorrow at] "+o,nextWeek:"dddd [at] "+o,lastWeek:"[Last] dddd [at] "+o,sameElse:"MM/DD/YYYY"};r.prototype.calendar=function(u,c){var d=c||this.$locale().calendar||l,f=a(u||void 0).startOf("d"),h=this.diff(f,"d",!0),g="sameElse",m=h<-6?g:h<-1?"lastWeek":h<0?"lastDay":h<1?"sameDay":h<2?"nextDay":h<7?"nextWeek":g,C=d[m]||l[m];return typeof C=="function"?C.call(this,a()):this.format(C)}}})})(ID);const MD=Xi;var Ji={},AD={get exports(){return Ji},set exports(e){Ji=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){var n={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"},r=/(\[[^[]*\])|([-_:/.,()\s]+)|(A|a|YYYY|YY?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g,a=/\d\d/,o=/\d\d?/,l=/\d*[^-_:/,()\s\d]+/,u={},c=function(w){return(w=+w)+(w>68?1900:2e3)},d=function(w){return function(_){this[w]=+_}},f=[/[+-]\d\d:?(\d\d)?|Z/,function(w){(this.zone||(this.zone={})).offset=function(_){if(!_||_==="Z")return 0;var T=_.match(/([+-]|\d\d)/g),M=60*T[1]+(+T[2]||0);return M===0?0:T[0]==="+"?-M:M}(w)}],h=function(w){var _=u[w];return _&&(_.indexOf?_:_.s.concat(_.f))},g=function(w,_){var T,M=u.meridiem;if(M){for(var P=1;P<=24;P+=1)if(w.indexOf(M(P,0,_))>-1){T=P>12;break}}else T=w===(_?"pm":"PM");return T},m={A:[l,function(w){this.afternoon=g(w,!1)}],a:[l,function(w){this.afternoon=g(w,!0)}],S:[/\d/,function(w){this.milliseconds=100*+w}],SS:[a,function(w){this.milliseconds=10*+w}],SSS:[/\d{3}/,function(w){this.milliseconds=+w}],s:[o,d("seconds")],ss:[o,d("seconds")],m:[o,d("minutes")],mm:[o,d("minutes")],H:[o,d("hours")],h:[o,d("hours")],HH:[o,d("hours")],hh:[o,d("hours")],D:[o,d("day")],DD:[a,d("day")],Do:[l,function(w){var _=u.ordinal,T=w.match(/\d+/);if(this.day=T[0],_)for(var M=1;M<=31;M+=1)_(M).replace(/\[|\]/g,"")===w&&(this.day=M)}],M:[o,d("month")],MM:[a,d("month")],MMM:[l,function(w){var _=h("months"),T=(h("monthsShort")||_.map(function(M){return M.slice(0,3)})).indexOf(w)+1;if(T<1)throw new Error;this.month=T%12||T}],MMMM:[l,function(w){var _=h("months").indexOf(w)+1;if(_<1)throw new Error;this.month=_%12||_}],Y:[/[+-]?\d+/,d("year")],YY:[a,function(w){this.year=c(w)}],YYYY:[/\d{4}/,d("year")],Z:f,ZZ:f};function C(w){var _,T;_=w,T=u&&u.formats;for(var M=(w=_.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(K,Y,H){var se=H&&H.toUpperCase();return Y||T[H]||n[H]||T[se].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(de,we,Le){return we||Le.slice(1)})})).match(r),P=M.length,G=0;G<P;G+=1){var $=M[G],L=m[$],A=L&&L[0],N=L&&L[1];M[G]=N?{regex:A,parser:N}:$.replace(/^\[|\]$/g,"")}return function(K){for(var Y={},H=0,se=0;H<P;H+=1){var de=M[H];if(typeof de=="string")se+=de.length;else{var we=de.regex,Le=de.parser,yt=K.slice(se),Qe=we.exec(yt)[0];Le.call(Y,Qe),K=K.replace(Qe,"")}}return function(dt){var Fe=dt.afternoon;if(Fe!==void 0){var bt=dt.hours;Fe?bt<12&&(dt.hours+=12):bt===12&&(dt.hours=0),delete dt.afternoon}}(Y),Y}}return function(w,_,T){T.p.customParseFormat=!0,w&&w.parseTwoDigitYear&&(c=w.parseTwoDigitYear);var M=_.prototype,P=M.parse;M.parse=function(G){var $=G.date,L=G.utc,A=G.args;this.$u=L;var N=A[1];if(typeof N=="string"){var K=A[2]===!0,Y=A[3]===!0,H=K||Y,se=A[2];Y&&(se=A[2]),u=this.$locale(),!K&&se&&(u=T.Ls[se]),this.$d=function(yt,Qe,dt){try{if(["x","X"].indexOf(Qe)>-1)return new Date((Qe==="X"?1e3:1)*yt);var Fe=C(Qe)(yt),bt=Fe.year,Bt=Fe.month,fr=Fe.day,gr=Fe.hours,Ta=Fe.minutes,Da=Fe.seconds,vn=Fe.milliseconds,Kt=Fe.zone,kt=new Date,Vt=fr||(bt||Bt?1:kt.getDate()),Tt=bt||kt.getFullYear(),Xt=0;bt&&!Bt||(Xt=Bt>0?Bt-1:kt.getMonth());var Jt=gr||0,xn=Ta||0,wn=Da||0,Dt=vn||0;return Kt?new Date(Date.UTC(Tt,Xt,Vt,Jt,xn,wn,Dt+60*Kt.offset*1e3)):dt?new Date(Date.UTC(Tt,Xt,Vt,Jt,xn,wn,Dt)):new Date(Tt,Xt,Vt,Jt,xn,wn,Dt)}catch{return new Date("")}}($,N,L),this.init(),se&&se!==!0&&(this.$L=this.locale(se).$L),H&&$!=this.format(N)&&(this.$d=new Date("")),u={}}else if(N instanceof Array)for(var de=N.length,we=1;we<=de;we+=1){A[1]=N[we-1];var Le=T.apply(this,A);if(Le.isValid()){this.$d=Le.$d,this.$L=Le.$L,this.init();break}we===de&&(this.$d=new Date(""))}else P.call(this,G)}}})})(AD);const zD=Ji;var Zi={},ED={get exports(){return Zi},set exports(e){Zi=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){r.prototype.dayOfYear=function(o){var l=Math.round((a(this).startOf("day")-a(this).startOf("year"))/864e5)+1;return o==null?l:this.add(o-l,"day")}}})})(ED);const $D=Zi;var Hi={},LD={get exports(){return Hi},set exports(e){Hi=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){var n,r,a=1e3,o=6e4,l=36e5,u=864e5,c=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,d=31536e6,f=2592e6,h=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/,g={years:d,months:f,days:u,hours:l,minutes:o,seconds:a,milliseconds:1,weeks:6048e5},m=function($){return $ instanceof G},C=function($,L,A){return new G($,A,L.$l)},w=function($){return r.p($)+"s"},_=function($){return $<0},T=function($){return _($)?Math.ceil($):Math.floor($)},M=function($){return Math.abs($)},P=function($,L){return $?_($)?{negative:!0,format:""+M($)+L}:{negative:!1,format:""+$+L}:{negative:!1,format:""}},G=function(){function $(A,N,K){var Y=this;if(this.$d={},this.$l=K,A===void 0&&(this.$ms=0,this.parseFromMilliseconds()),N)return C(A*g[w(N)],this);if(typeof A=="number")return this.$ms=A,this.parseFromMilliseconds(),this;if(typeof A=="object")return Object.keys(A).forEach(function(de){Y.$d[w(de)]=A[de]}),this.calMilliseconds(),this;if(typeof A=="string"){var H=A.match(h);if(H){var se=H.slice(2).map(function(de){return de!=null?Number(de):0});return this.$d.years=se[0],this.$d.months=se[1],this.$d.weeks=se[2],this.$d.days=se[3],this.$d.hours=se[4],this.$d.minutes=se[5],this.$d.seconds=se[6],this.calMilliseconds(),this}}return this}var L=$.prototype;return L.calMilliseconds=function(){var A=this;this.$ms=Object.keys(this.$d).reduce(function(N,K){return N+(A.$d[K]||0)*g[K]},0)},L.parseFromMilliseconds=function(){var A=this.$ms;this.$d.years=T(A/d),A%=d,this.$d.months=T(A/f),A%=f,this.$d.days=T(A/u),A%=u,this.$d.hours=T(A/l),A%=l,this.$d.minutes=T(A/o),A%=o,this.$d.seconds=T(A/a),A%=a,this.$d.milliseconds=A},L.toISOString=function(){var A=P(this.$d.years,"Y"),N=P(this.$d.months,"M"),K=+this.$d.days||0;this.$d.weeks&&(K+=7*this.$d.weeks);var Y=P(K,"D"),H=P(this.$d.hours,"H"),se=P(this.$d.minutes,"M"),de=this.$d.seconds||0;this.$d.milliseconds&&(de+=this.$d.milliseconds/1e3);var we=P(de,"S"),Le=A.negative||N.negative||Y.negative||H.negative||se.negative||we.negative,yt=H.format||se.format||we.format?"T":"",Qe=(Le?"-":"")+"P"+A.format+N.format+Y.format+yt+H.format+se.format+we.format;return Qe==="P"||Qe==="-P"?"P0D":Qe},L.toJSON=function(){return this.toISOString()},L.format=function(A){var N=A||"YYYY-MM-DDTHH:mm:ss",K={Y:this.$d.years,YY:r.s(this.$d.years,2,"0"),YYYY:r.s(this.$d.years,4,"0"),M:this.$d.months,MM:r.s(this.$d.months,2,"0"),D:this.$d.days,DD:r.s(this.$d.days,2,"0"),H:this.$d.hours,HH:r.s(this.$d.hours,2,"0"),m:this.$d.minutes,mm:r.s(this.$d.minutes,2,"0"),s:this.$d.seconds,ss:r.s(this.$d.seconds,2,"0"),SSS:r.s(this.$d.milliseconds,3,"0")};return N.replace(c,function(Y,H){return H||String(K[Y])})},L.as=function(A){return this.$ms/g[w(A)]},L.get=function(A){var N=this.$ms,K=w(A);return K==="milliseconds"?N%=1e3:N=K==="weeks"?T(N/g[K]):this.$d[K],N===0?0:N},L.add=function(A,N,K){var Y;return Y=N?A*g[w(N)]:m(A)?A.$ms:C(A,this).$ms,C(this.$ms+Y*(K?-1:1),this)},L.subtract=function(A,N){return this.add(A,N,!0)},L.locale=function(A){var N=this.clone();return N.$l=A,N},L.clone=function(){return C(this.$ms,this)},L.humanize=function(A){return n().add(this.$ms,"ms").locale(this.$l).fromNow(!A)},L.milliseconds=function(){return this.get("milliseconds")},L.asMilliseconds=function(){return this.as("milliseconds")},L.seconds=function(){return this.get("seconds")},L.asSeconds=function(){return this.as("seconds")},L.minutes=function(){return this.get("minutes")},L.asMinutes=function(){return this.as("minutes")},L.hours=function(){return this.get("hours")},L.asHours=function(){return this.as("hours")},L.days=function(){return this.get("days")},L.asDays=function(){return this.as("days")},L.weeks=function(){return this.get("weeks")},L.asWeeks=function(){return this.as("weeks")},L.months=function(){return this.get("months")},L.asMonths=function(){return this.as("months")},L.years=function(){return this.get("years")},L.asYears=function(){return this.as("years")},$}();return function($,L,A){n=A,r=A().$utils(),A.duration=function(Y,H){var se=A.locale();return C(Y,{$l:se},H)},A.isDuration=m;var N=L.prototype.add,K=L.prototype.subtract;L.prototype.add=function(Y,H){return m(Y)&&(Y=Y.asMilliseconds()),N.bind(this)(Y,H)},L.prototype.subtract=function(Y,H){return m(Y)&&(Y=Y.asMilliseconds()),K.bind(this)(Y,H)}}})})(LD);const OD=Hi;var ea={},PD={get exports(){return ea},set exports(e){ea=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){r.prototype.isBetween=function(o,l,u,c){var d=a(o),f=a(l),h=(c=c||"()")[0]==="(",g=c[1]===")";return(h?this.isAfter(d,u):!this.isBefore(d,u))&&(g?this.isBefore(f,u):!this.isAfter(f,u))||(h?this.isBefore(d,u):!this.isAfter(d,u))&&(g?this.isAfter(f,u):!this.isBefore(f,u))}}})})(PD);const BD=ea;var ta={},VD={get exports(){return ta},set exports(e){ta=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){r.prototype.isLeapYear=function(){return this.$y%4==0&&this.$y%100!=0||this.$y%400==0}}})})(VD);const ND=ta;var na={},qD={get exports(){return na},set exports(e){na=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){a.isMoment=function(o){return a.isDayjs(o)}}})})(qD);const FD=na;var ra={},GD={get exports(){return ra},set exports(e){ra=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){var n="day";return function(r,a,o){var l=function(d){return d.add(4-d.isoWeekday(),n)},u=a.prototype;u.isoWeekYear=function(){return l(this).year()},u.isoWeek=function(d){if(!this.$utils().u(d))return this.add(7*(d-this.isoWeek()),n);var f,h,g,m,C=l(this),w=(f=this.isoWeekYear(),h=this.$u,g=(h?o.utc:o)().year(f).startOf("year"),m=4-g.isoWeekday(),g.isoWeekday()>4&&(m+=7),g.add(m,n));return C.diff(w,"week")+1},u.isoWeekday=function(d){return this.$utils().u(d)?this.day()||7:this.day(this.day()%7?d:d-7)};var c=u.startOf;u.startOf=function(d,f){var h=this.$utils(),g=!!h.u(f)||f;return h.p(d)==="isoweek"?g?this.date(this.date()-(this.isoWeekday()-1)).startOf("day"):this.date(this.date()-1-(this.isoWeekday()-1)+7).endOf("day"):c.bind(this)(d,f)}}})})(GD);const WD=ra;var ia={},jD={get exports(){return ia},set exports(e){ia=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){r.prototype.isoWeeksInYear=function(){var a=this.isLeapYear(),o=this.endOf("y").day();return o===4||a&&o===5?53:52}}})})(jD);const RD=ia;var aa={},YD={get exports(){return aa},set exports(e){aa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){r.prototype.isSameOrAfter=function(a,o){return this.isSame(a,o)||this.isAfter(a,o)}}})})(YD);const QD=aa;var sa={},UD={get exports(){return sa},set exports(e){sa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){r.prototype.isSameOrBefore=function(a,o){return this.isSame(a,o)||this.isBefore(a,o)}}})})(UD);const KD=sa;var oa={},XD={get exports(){return oa},set exports(e){oa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){r.prototype.isToday=function(){var o="YYYY-MM-DD",l=a();return this.format(o)===l.format(o)}}})})(XD);const JD=oa;var la={},ZD={get exports(){return la},set exports(e){la=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){r.prototype.isTomorrow=function(){var o="YYYY-MM-DD",l=a().add(1,"day");return this.format(o)===l.format(o)}}})})(ZD);const HD=la;var ua={},eI={get exports(){return ua},set exports(e){ua=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){r.prototype.isYesterday=function(){var o="YYYY-MM-DD",l=a().subtract(1,"day");return this.format(o)===l.format(o)}}})})(eI);const tI=ua;var ca={},nI={get exports(){return ca},set exports(e){ca=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){var o=r.prototype,l=function(h){return h&&(h.indexOf?h:h.s)},u=function(h,g,m,C,w){var _=h.name?h:h.$locale(),T=l(_[g]),M=l(_[m]),P=T||M.map(function($){return $.slice(0,C)});if(!w)return P;var G=_.weekStart;return P.map(function($,L){return P[(L+(G||0))%7]})},c=function(){return a.Ls[a.locale()]},d=function(h,g){return h.formats[g]||function(m){return m.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(C,w,_){return w||_.slice(1)})}(h.formats[g.toUpperCase()])},f=function(){var h=this;return{months:function(g){return g?g.format("MMMM"):u(h,"months")},monthsShort:function(g){return g?g.format("MMM"):u(h,"monthsShort","months",3)},firstDayOfWeek:function(){return h.$locale().weekStart||0},weekdays:function(g){return g?g.format("dddd"):u(h,"weekdays")},weekdaysMin:function(g){return g?g.format("dd"):u(h,"weekdaysMin","weekdays",2)},weekdaysShort:function(g){return g?g.format("ddd"):u(h,"weekdaysShort","weekdays",3)},longDateFormat:function(g){return d(h.$locale(),g)},meridiem:this.$locale().meridiem,ordinal:this.$locale().ordinal}};o.localeData=function(){return f.bind(this)()},a.localeData=function(){var h=c();return{firstDayOfWeek:function(){return h.weekStart||0},weekdays:function(){return a.weekdays()},weekdaysShort:function(){return a.weekdaysShort()},weekdaysMin:function(){return a.weekdaysMin()},months:function(){return a.months()},monthsShort:function(){return a.monthsShort()},longDateFormat:function(g){return d(h,g)},meridiem:h.meridiem,ordinal:h.ordinal}},a.months=function(){return u(c(),"months")},a.monthsShort=function(){return u(c(),"monthsShort","months",3)},a.weekdays=function(h){return u(c(),"weekdays",null,null,h)},a.weekdaysShort=function(h){return u(c(),"weekdaysShort","weekdays",3,h)},a.weekdaysMin=function(h){return u(c(),"weekdaysMin","weekdays",2,h)}}})})(nI);const rI=ca;var da={},iI={get exports(){return da},set exports(e){da=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){var n={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"};return function(r,a,o){var l=a.prototype,u=l.format;o.en.formats=n,l.format=function(c){c===void 0&&(c="YYYY-MM-DDTHH:mm:ssZ");var d=this.$locale().formats,f=function(h,g){return h.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(m,C,w){var _=w&&w.toUpperCase();return C||g[w]||n[w]||g[_].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(T,M,P){return M||P.slice(1)})})}(c,d===void 0?{}:d);return u.call(this,f)}}})})(iI);const aI=da;var pa={},sI={get exports(){return pa},set exports(e){pa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){var o=function(l,u){if(!u||!u.length||!u[0]||u.length===1&&!u[0].length)return null;var c;u.length===1&&u[0].length>0&&(u=u[0]),c=u[0];for(var d=1;d<u.length;d+=1)u[d].isValid()&&!u[d][l](c)||(c=u[d]);return c};a.max=function(){var l=[].slice.call(arguments,0);return o("isAfter",l)},a.min=function(){var l=[].slice.call(arguments,0);return o("isBefore",l)}}})})(sI);const oI=pa;var ha={},lI={get exports(){return ha},set exports(e){ha=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){var o=r.prototype,l=function(g){var m,C=g.date,w=g.utc,_={};if(!((m=C)instanceof Date||m instanceof Array||o.$utils().u(m)||m.constructor.name!=="Object")){if(!Object.keys(C).length)return new Date;var T=w?a.utc():a();Object.keys(C).forEach(function(K){var Y,H;_[Y=K,H=o.$utils().p(Y),H==="date"?"day":H]=C[K]});var M=_.day||(_.year||_.month>=0?1:T.date()),P=_.year||T.year(),G=_.month>=0?_.month:_.year||_.day?0:T.month(),$=_.hour||0,L=_.minute||0,A=_.second||0,N=_.millisecond||0;return w?new Date(Date.UTC(P,G,M,$,L,A,N)):new Date(P,G,M,$,L,A,N)}return C},u=o.parse;o.parse=function(g){g.date=l.bind(this)(g),u.bind(this)(g)};var c=o.set,d=o.add,f=o.subtract,h=function(g,m,C,w){w===void 0&&(w=1);var _=Object.keys(m),T=this;return _.forEach(function(M){T=g.bind(T)(m[M]*w,M)}),T};o.set=function(g,m){return m=m===void 0?g:m,g.constructor.name==="Object"?h.bind(this)(function(C,w){return c.bind(this)(w,C)},m,g):c.bind(this)(g,m)},o.add=function(g,m){return g.constructor.name==="Object"?h.bind(this)(d,g,m):d.bind(this)(g,m)},o.subtract=function(g,m){return g.constructor.name==="Object"?h.bind(this)(d,g,m,-1):f.bind(this)(g,m)}}})})(lI);const uI=ha;var fa={},cI={get exports(){return fa},set exports(e){fa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){var a=r.prototype;["milliseconds","seconds","minutes","hours","days","weeks","isoWeeks","months","quarters","years","dates"].forEach(function(o){a[o]=a[o.replace(/s$/,"")]})}})})(cI);const dI=fa;var ga={},pI={get exports(){return ga},set exports(e){ga=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){var a=r.prototype.parse;r.prototype.parse=function(u){if(typeof u.date=="string"){var c=this.$locale();u.date=c&&c.preparse?c.preparse(u.date):u.date}return a.bind(this)(u)};var o=r.prototype.format;r.prototype.format=function(){for(var u=arguments.length,c=new Array(u),d=0;d<u;d++)c[d]=arguments[d];var f=o.call.apply(o,[this].concat(c)),h=this.$locale();return h&&h.postformat?h.postformat(f):f};var l=r.prototype.fromToBase;l&&(r.prototype.fromToBase=function(u,c,d,f){var h=this.$locale()||d.$locale();return l.call(this,u,c,d,f,h&&h.postformat)})}})})(pI);const hI=ga;var ma={},fI={get exports(){return ma},set exports(e){ma=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){var n="month",r="quarter";return function(a,o){var l=o.prototype;l.quarter=function(d){return this.$utils().u(d)?Math.ceil((this.month()+1)/3):this.month(this.month()%3+3*(d-1))};var u=l.add;l.add=function(d,f){return d=Number(d),this.$utils().p(f)===r?this.add(3*d,n):u.bind(this)(d,f)};var c=l.startOf;l.startOf=function(d,f){var h=this.$utils(),g=!!h.u(f)||f;if(h.p(d)===r){var m=this.quarter()-1;return g?this.month(3*m).startOf(n).startOf("day"):this.month(3*m+2).endOf(n).endOf("day")}return c.bind(this)(d,f)}}})})(fI);const gI=ma;var ya={},mI={get exports(){return ya},set exports(e){ya=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){n=n||{};var o=r.prototype,l={future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"};function u(d,f,h,g){return o.fromToBase(d,f,h,g)}a.en.relativeTime=l,o.fromToBase=function(d,f,h,g,m){for(var C,w,_,T=h.$locale().relativeTime||l,M=n.thresholds||[{l:"s",r:44,d:"second"},{l:"m",r:89},{l:"mm",r:44,d:"minute"},{l:"h",r:89},{l:"hh",r:21,d:"hour"},{l:"d",r:35},{l:"dd",r:25,d:"day"},{l:"M",r:45},{l:"MM",r:10,d:"month"},{l:"y",r:17},{l:"yy",d:"year"}],P=M.length,G=0;G<P;G+=1){var $=M[G];$.d&&(C=g?a(d).diff(h,$.d,!0):h.diff(d,$.d,!0));var L=(n.rounding||Math.round)(Math.abs(C));if(_=C>0,L<=$.r||!$.r){L<=1&&G>0&&($=M[G-1]);var A=T[$.l];m&&(L=m(""+L)),w=typeof A=="string"?A.replace("%d",L):A(L,f,$.l,_);break}}if(f)return w;var N=_?T.future:T.past;return typeof N=="function"?N(w):N.replace("%s",w)},o.to=function(d,f){return u(d,f,this,!0)},o.from=function(d,f){return u(d,f,this)};var c=function(d){return d.$u?a.utc():a()};o.toNow=function(d){return this.to(c(this),d)},o.fromNow=function(d){return this.from(c(this),d)}}})})(mI);const yI=ya;var ba={},bI={get exports(){return ba},set exports(e){ba=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){var n={year:0,month:1,day:2,hour:3,minute:4,second:5},r={};return function(a,o,l){var u,c=function(g,m,C){C===void 0&&(C={});var w=new Date(g),_=function(T,M){M===void 0&&(M={});var P=M.timeZoneName||"short",G=T+"|"+P,$=r[G];return $||($=new Intl.DateTimeFormat("en-US",{hour12:!1,timeZone:T,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:P}),r[G]=$),$}(m,C);return _.formatToParts(w)},d=function(g,m){for(var C=c(g,m),w=[],_=0;_<C.length;_+=1){var T=C[_],M=T.type,P=T.value,G=n[M];G>=0&&(w[G]=parseInt(P,10))}var $=w[3],L=$===24?0:$,A=w[0]+"-"+w[1]+"-"+w[2]+" "+L+":"+w[4]+":"+w[5]+":000",N=+g;return(l.utc(A).valueOf()-(N-=N%1e3))/6e4},f=o.prototype;f.tz=function(g,m){g===void 0&&(g=u);var C=this.utcOffset(),w=this.toDate(),_=w.toLocaleString("en-US",{timeZone:g}),T=Math.round((w-new Date(_))/1e3/60),M=l(_).$set("millisecond",this.$ms).utcOffset(15*-Math.round(w.getTimezoneOffset()/15)-T,!0);if(m){var P=M.utcOffset();M=M.add(C-P,"minute")}return M.$x.$timezone=g,M},f.offsetName=function(g){var m=this.$x.$timezone||l.tz.guess(),C=c(this.valueOf(),m,{timeZoneName:g}).find(function(w){return w.type.toLowerCase()==="timezonename"});return C&&C.value};var h=f.startOf;f.startOf=function(g,m){if(!this.$x||!this.$x.$timezone)return h.call(this,g,m);var C=l(this.format("YYYY-MM-DD HH:mm:ss:SSS"));return h.call(C,g,m).tz(this.$x.$timezone,!0)},l.tz=function(g,m,C){var w=C&&m,_=C||m||u,T=d(+l(),_);if(typeof g!="string")return l(g).tz(_);var M=function(L,A,N){var K=L-60*A*1e3,Y=d(K,N);if(A===Y)return[K,A];var H=d(K-=60*(Y-A)*1e3,N);return Y===H?[K,Y]:[L-60*Math.min(Y,H)*1e3,Math.max(Y,H)]}(l.utc(g,w).valueOf(),T,_),P=M[0],G=M[1],$=l(P).utcOffset(G);return $.$x.$timezone=_,$},l.tz.guess=function(){return Intl.DateTimeFormat().resolvedOptions().timeZone},l.tz.setDefault=function(g){u=g}}})})(bI);const vI=ba;var va={},xI={get exports(){return va},set exports(e){va=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){r.prototype.toArray=function(){return[this.$y,this.$M,this.$D,this.$H,this.$m,this.$s,this.$ms]}}})})(xI);const wI=va;var xa={},CI={get exports(){return xa},set exports(e){xa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){r.prototype.toObject=function(){return{years:this.$y,months:this.$M,date:this.$D,hours:this.$H,minutes:this.$m,seconds:this.$s,milliseconds:this.$ms}}}})})(CI);const SI=xa;var wa={},_I={get exports(){return wa},set exports(e){wa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){a.updateLocale=function(o,l){var u=a.Ls[o];if(u)return(l?Object.keys(l):[]).forEach(function(c){u[c]=l[c]}),u}}})})(_I);const kI=wa;var Ca={},TI={get exports(){return Ca},set exports(e){Ca=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){var n="minute",r=/[+-]\d\d(?::?\d\d)?/g,a=/([+-]|\d\d)/g;return function(o,l,u){var c=l.prototype;u.utc=function(w){var _={date:w,utc:!0,args:arguments};return new l(_)},c.utc=function(w){var _=u(this.toDate(),{locale:this.$L,utc:!0});return w?_.add(this.utcOffset(),n):_},c.local=function(){return u(this.toDate(),{locale:this.$L,utc:!1})};var d=c.parse;c.parse=function(w){w.utc&&(this.$u=!0),this.$utils().u(w.$offset)||(this.$offset=w.$offset),d.call(this,w)};var f=c.init;c.init=function(){if(this.$u){var w=this.$d;this.$y=w.getUTCFullYear(),this.$M=w.getUTCMonth(),this.$D=w.getUTCDate(),this.$W=w.getUTCDay(),this.$H=w.getUTCHours(),this.$m=w.getUTCMinutes(),this.$s=w.getUTCSeconds(),this.$ms=w.getUTCMilliseconds()}else f.call(this)};var h=c.utcOffset;c.utcOffset=function(w,_){var T=this.$utils().u;if(T(w))return this.$u?0:T(this.$offset)?h.call(this):this.$offset;if(typeof w=="string"&&(w=function($){$===void 0&&($="");var L=$.match(r);if(!L)return null;var A=(""+L[0]).match(a)||["-",0,0],N=A[0],K=60*+A[1]+ +A[2];return K===0?0:N==="+"?K:-K}(w),w===null))return this;var M=Math.abs(w)<=16?60*w:w,P=this;if(_)return P.$offset=M,P.$u=w===0,P;if(w!==0){var G=this.$u?this.toDate().getTimezoneOffset():-1*this.utcOffset();(P=this.local().add(M+G,n)).$offset=M,P.$x.$localOffset=G}else P=this.utc();return P};var g=c.format;c.format=function(w){var _=w||(this.$u?"YYYY-MM-DDTHH:mm:ss[Z]":"");return g.call(this,_)},c.valueOf=function(){var w=this.$utils().u(this.$offset)?0:this.$offset+(this.$x.$localOffset||this.$d.getTimezoneOffset());return this.$d.valueOf()-6e4*w},c.isUTC=function(){return!!this.$u},c.toISOString=function(){return this.toDate().toISOString()},c.toString=function(){return this.toDate().toUTCString()};var m=c.toDate;c.toDate=function(w){return w==="s"&&this.$offset?u(this.format("YYYY-MM-DD HH:mm:ss:SSS")).toDate():m.call(this)};var C=c.diff;c.diff=function(w,_,T){if(w&&this.$u===w.$u)return C.call(this,w,_,T);var M=this.local(),P=u(w).local();return C.call(M,P,_,T)}}})})(TI);const DI=Ca;var Sa={},II={get exports(){return Sa},set exports(e){Sa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){r.prototype.weekday=function(a){var o=this.$locale().weekStart||0,l=this.$W,u=(l<o?l+7:l)-o;return this.$utils().u(a)?u:this.subtract(u,"day").add(a,"day")}}})})(II);const MI=Sa;var _a={},AI={get exports(){return _a},set exports(e){_a=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){var n="week",r="year";return function(a,o,l){var u=o.prototype;u.week=function(c){if(c===void 0&&(c=null),c!==null)return this.add(7*(c-this.week()),"day");var d=this.$locale().yearStart||1;if(this.month()===11&&this.date()>25){var f=l(this).startOf(r).add(1,r).date(d),h=l(this).endOf(n);if(f.isBefore(h))return 1}var g=l(this).startOf(r).date(d).startOf(n).subtract(1,"millisecond"),m=this.diff(g,n,!0);return m<0?l(this).startOf("week").week():Math.ceil(m)},u.weeks=function(c){return c===void 0&&(c=null),this.week(c)}}})})(AI);const zI=_a;var ka={},EI={get exports(){return ka},set exports(e){ka=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){r.prototype.weekYear=function(){var a=this.month(),o=this.week(),l=this.year();return o===1&&a===11?l+1:a===0&&o>=52?l-1:l}}})})(EI);const $I=ka;U.extend(SD),U.extend(kD),U.extend(DD),U.extend(MD),U.extend(zD),U.extend($D),U.extend(OD),U.extend(BD),U.extend(ND),U.extend(FD),U.extend(QD),U.extend(KD),U.extend(JD),U.extend(HD),U.extend(tI),U.extend(WD),U.extend(RD),U.extend(rI),U.extend(aI),U.extend(oI),U.extend(uI),U.extend(dI),U.extend(hI),U.extend(gI),U.extend(yI),U.extend(vI),U.extend(wI),U.extend(SI),U.extend(kI),U.extend(DI),U.extend(zI),U.extend($I),U.extend(MI),U.tz.setDefault("UTC");const LI=()=>Promise.resolve().then(()=>pc).then(({version:e})=>(console.log(`[@devtable/dashboard] version: ${e}`),e));I.ContentModel=Vi,I.ContentModelContextProvider=Dr,I.DashboardEditor=yD,I.DashboardFilterType=xe,I.DashboardMode=Gl,I.DashboardModel=Jl,I.DashboardModelContextProvider=_r,I.DashboardViewEditor=Fl,I.DashboardViewRender=cr,I.DescriptionPopover=$i,I.FiltersModel=jl,I.FullScreenPanel=Pl,I.FullScreenPanelContext=Mr,I.LayoutStateContext=An,I.Panel=Ol,I.PanelContextProvider=Ir,I.PanelErrorOrStateMessage=$l,I.PanelModel=Ql,I.PanelRender=Oi,I.PanelVizSection=Li,I.PanelsModel=Ul,I.QueriesModel=Rl,I.ReadOnlyDashboard=wD,I.SQLSnippetsModel=Yl,I.ViewComponentTypeBackground=Wl,I.ViewComponentTypeColor=p_,I.ViewComponentTypeName=d_,I.ViewsModel=Kl,I.Viz=El,I.applyPartialDashboard=__,I.createContentModel=Xl,I.createDashboardModel=Zl,I.getInitialDashboardViewsModel=Bi,I.getVersion=LI,I.initialDashboardContent=h_,I.useDashboardContext=kr,I.useEditContentModelContext=le,I.useEditDashboardContext=ue,I.useEditPanelContext=rt,I.useFullScreenPanelContext=hs,I.usePanelFullScreen=Bl,I.useRenderContentModelContext=ye,I.useRenderDashboardContext=Tr,I.useRenderPanelContext=Ct,Object.defineProperty(I,Symbol.toStringTag,{value:"Module"})});
|