@devtable/dashboard 10.4.1 → 10.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dashboard.es.js +3811 -3768
- package/dist/dashboard.umd.js +79 -79
- package/dist/main/dashboard-editor/settings/content/edit-view/edit-view-form/index.d.ts +8 -8
- package/dist/model/editor/index.d.ts +2 -2
- package/dist/model/views/index.d.ts +43 -43
- package/dist/model/views/view/index.d.ts +2 -2
- package/dist/model/views/view/tabs.d.ts +4 -4
- package/dist/plugins/viz-components/button/type.d.ts +2 -2
- package/dist/stats.html +1 -1
- package/package.json +17 -17
package/dist/dashboard.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(D,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("react"),require("@mantine/core"),require("@mantine/modals"),require("ahooks"),require("mobx"),require("mobx-react-lite"),require("crypto-js"),require("dayjs"),require("lodash"),require("numbro"),require("d3-array"),require("mathjs"),require("@faker-js/faker"),require("axios"),require("mobx-state-tree"),require("performant-array-to-tree"),require("jszip"),require("file-saver"),require("@tabler/icons"),require("@mantine/hooks"),require("@tanstack/react-table"),require("react-virtual"),require("eventemitter2"),require("chroma-js"),require("echarts-gl"),require("echarts/core"),require("echarts/components"),require("echarts/renderers"),require("echarts-for-react/lib/core"),require("react-hook-form"),require("tabler-icons-react"),require("echarts/charts"),require("@mantine/notifications"),require("popmotion"),require("@monaco-editor/react"),require("d3-regression"),require("@mantine/prism"),require("@mantine/tiptap"),require("@tiptap/extension-color"),require("@tiptap/extension-highlight"),require("@tiptap/extension-placeholder"),require("@tiptap/extension-subscript"),require("@tiptap/extension-superscript"),require("@tiptap/extension-text-align"),require("@tiptap/extension-text-style"),require("@tiptap/extension-table"),require("@tiptap/extension-table-cell"),require("@tiptap/extension-table-header"),require("@tiptap/extension-table-row"),require("@tiptap/extension-underline"),require("@tiptap/react"),require("@tiptap/starter-kit"),require("prosemirror-keymap"),require("prosemirror-commands"),require("prosemirror-schema-list"),require("@mantine/dates"),require("rc-select"),require("rc-tree-select"),require("react-grid-layout"),require("react-router-dom"),require("reactflow")):typeof define=="function"&&define.amd?define(["exports","react","@mantine/core","@mantine/modals","ahooks","mobx","mobx-react-lite","crypto-js","dayjs","lodash","numbro","d3-array","mathjs","@faker-js/faker","axios","mobx-state-tree","performant-array-to-tree","jszip","file-saver","@tabler/icons","@mantine/hooks","@tanstack/react-table","react-virtual","eventemitter2","chroma-js","echarts-gl","echarts/core","echarts/components","echarts/renderers","echarts-for-react/lib/core","react-hook-form","tabler-icons-react","echarts/charts","@mantine/notifications","popmotion","@monaco-editor/react","d3-regression","@mantine/prism","@mantine/tiptap","@tiptap/extension-color","@tiptap/extension-highlight","@tiptap/extension-placeholder","@tiptap/extension-subscript","@tiptap/extension-superscript","@tiptap/extension-text-align","@tiptap/extension-text-style","@tiptap/extension-table","@tiptap/extension-table-cell","@tiptap/extension-table-header","@tiptap/extension-table-row","@tiptap/extension-underline","@tiptap/react","@tiptap/starter-kit","prosemirror-keymap","prosemirror-commands","prosemirror-schema-list","@mantine/dates","rc-select","rc-tree-select","react-grid-layout","react-router-dom","reactflow"],y):(D=typeof globalThis<"u"?globalThis:D||self,y(D.dashboard={},D.react,D["@mantine/core"],D["@mantine/modals"],D.ahooks,D.mobx,D["mobx-react-lite"],D.CryptoJS,D.dayjs,D._,D.numbro,D["d3-array"],D.mathjs,D["@faker-js/faker"],D.axios,D["mobx-state-tree"],D["performant-array-to-tree"],D.jszip,D["file-saver"],D["@tabler/icons"],D["@mantine/hooks"],D["@tanstack/react-table"],D["react-virtual"],D.eventemitter2,D["chroma-js"],D["echarts-gl"],D["echarts/core"],D["echarts/components"],D["echarts/renderers"],D["echarts-for-react/lib/core"],D["react-hook-form"],D["tabler-icons-react"],D["echarts/charts"],D["@mantine/notifications"],D.popmotion,D["@monaco-editor/react"],D["d3-regression"],D["@mantine/prism"],D["@mantine/tiptap"],D["@tiptap/extension-color"],D["@tiptap/extension-highlight"],D["@tiptap/extension-placeholder"],D["@tiptap/extension-subscript"],D["@tiptap/extension-superscript"],D["@tiptap/extension-text-align"],D["@tiptap/extension-text-style"],D["@tiptap/extension-table"],D["@tiptap/extension-table-cell"],D["@tiptap/extension-table-header"],D["@tiptap/extension-table-row"],D["@tiptap/extension-underline"],D["@tiptap/react"],D["@tiptap/starter-kit"],D["prosemirror-keymap"],D["prosemirror-commands"],D["prosemirror-schema-list"],D["@mantine/dates"],D["rc-select"],D["rc-tree-select"],D["react-grid-layout"],D["react-router-dom"],D.reactflow))})(this,function(D,y,s,Ke,J,ae,k,wa,Y,x,te,Yt,
|
|
1
|
+
(function(D,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("react"),require("@mantine/core"),require("@mantine/modals"),require("ahooks"),require("mobx"),require("mobx-react-lite"),require("crypto-js"),require("dayjs"),require("lodash"),require("numbro"),require("d3-array"),require("mathjs"),require("@faker-js/faker"),require("axios"),require("mobx-state-tree"),require("performant-array-to-tree"),require("jszip"),require("file-saver"),require("@tabler/icons-react"),require("@mantine/hooks"),require("@tanstack/react-table"),require("react-virtual"),require("eventemitter2"),require("chroma-js"),require("echarts-gl"),require("echarts/core"),require("echarts/components"),require("echarts/renderers"),require("echarts-for-react/lib/core"),require("react-hook-form"),require("tabler-icons-react"),require("echarts/charts"),require("@mantine/notifications"),require("popmotion"),require("@monaco-editor/react"),require("d3-regression"),require("@mantine/prism"),require("@mantine/tiptap"),require("@tiptap/extension-color"),require("@tiptap/extension-highlight"),require("@tiptap/extension-placeholder"),require("@tiptap/extension-subscript"),require("@tiptap/extension-superscript"),require("@tiptap/extension-text-align"),require("@tiptap/extension-text-style"),require("@tiptap/extension-table"),require("@tiptap/extension-table-cell"),require("@tiptap/extension-table-header"),require("@tiptap/extension-table-row"),require("@tiptap/extension-underline"),require("@tiptap/react"),require("@tiptap/starter-kit"),require("prosemirror-keymap"),require("prosemirror-commands"),require("prosemirror-schema-list"),require("@mantine/dates"),require("rc-select"),require("rc-tree-select"),require("react-grid-layout"),require("react-router-dom"),require("reactflow")):typeof define=="function"&&define.amd?define(["exports","react","@mantine/core","@mantine/modals","ahooks","mobx","mobx-react-lite","crypto-js","dayjs","lodash","numbro","d3-array","mathjs","@faker-js/faker","axios","mobx-state-tree","performant-array-to-tree","jszip","file-saver","@tabler/icons-react","@mantine/hooks","@tanstack/react-table","react-virtual","eventemitter2","chroma-js","echarts-gl","echarts/core","echarts/components","echarts/renderers","echarts-for-react/lib/core","react-hook-form","tabler-icons-react","echarts/charts","@mantine/notifications","popmotion","@monaco-editor/react","d3-regression","@mantine/prism","@mantine/tiptap","@tiptap/extension-color","@tiptap/extension-highlight","@tiptap/extension-placeholder","@tiptap/extension-subscript","@tiptap/extension-superscript","@tiptap/extension-text-align","@tiptap/extension-text-style","@tiptap/extension-table","@tiptap/extension-table-cell","@tiptap/extension-table-header","@tiptap/extension-table-row","@tiptap/extension-underline","@tiptap/react","@tiptap/starter-kit","prosemirror-keymap","prosemirror-commands","prosemirror-schema-list","@mantine/dates","rc-select","rc-tree-select","react-grid-layout","react-router-dom","reactflow"],y):(D=typeof globalThis<"u"?globalThis:D||self,y(D.dashboard={},D.react,D["@mantine/core"],D["@mantine/modals"],D.ahooks,D.mobx,D["mobx-react-lite"],D.CryptoJS,D.dayjs,D._,D.numbro,D["d3-array"],D.mathjs,D["@faker-js/faker"],D.axios,D["mobx-state-tree"],D["performant-array-to-tree"],D.jszip,D["file-saver"],D["@tabler/icons-react"],D["@mantine/hooks"],D["@tanstack/react-table"],D["react-virtual"],D.eventemitter2,D["chroma-js"],D["echarts-gl"],D["echarts/core"],D["echarts/components"],D["echarts/renderers"],D["echarts-for-react/lib/core"],D["react-hook-form"],D["tabler-icons-react"],D["echarts/charts"],D["@mantine/notifications"],D.popmotion,D["@monaco-editor/react"],D["d3-regression"],D["@mantine/prism"],D["@mantine/tiptap"],D["@tiptap/extension-color"],D["@tiptap/extension-highlight"],D["@tiptap/extension-placeholder"],D["@tiptap/extension-subscript"],D["@tiptap/extension-superscript"],D["@tiptap/extension-text-align"],D["@tiptap/extension-text-style"],D["@tiptap/extension-table"],D["@tiptap/extension-table-cell"],D["@tiptap/extension-table-header"],D["@tiptap/extension-table-row"],D["@tiptap/extension-underline"],D["@tiptap/react"],D["@tiptap/starter-kit"],D["prosemirror-keymap"],D["prosemirror-commands"],D["prosemirror-schema-list"],D["@mantine/dates"],D["rc-select"],D["rc-tree-select"],D["react-grid-layout"],D["react-router-dom"],D.reactflow))})(this,function(D,y,s,Ke,J,ae,k,wa,Y,x,te,Yt,jl,Yl,pt,b,Ql,Kl,lr,L,Ie,Ue,Ul,Ca,at,OT,Xl,G,Ve,Ne,v,I,he,hn,At,ze,Jl,St,Z,Sa,_a,ka,Ta,Da,Ia,Ma,Ea,Aa,za,$a,La,Oa,Pa,PT,De,ur,Zl,Ba,Va,fn,Hl,Me){"use strict";var $T=Object.defineProperty;var LT=(D,y,s)=>y in D?$T(D,y,{enumerable:!0,configurable:!0,writable:!0,value:s}):D[y]=s;var V=(D,y,s)=>(LT(D,typeof y!="symbol"?y+"":y,s),s);function gn(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:()=>t[n]})}}return e.default=t,Object.freeze(e)}const eu=gn(Yt),mn=gn(jl),ue=gn(Xl),ht=gn(Jl);var ne=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},Qt={},tu={get exports(){return Qt},set exports(t){Qt=t}},Kt={};/**
|
|
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 Na;function
|
|
9
|
+
*/var Na;function nu(){if(Na)return Kt;Na=1;var t=y,e=Symbol.for("react.element"),n=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,a=t.__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,p={},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)&&(p[f]=c[f]);if(u&&u.defaultProps)for(f in c=u.defaultProps,c)p[f]===void 0&&(p[f]=c[f]);return{$$typeof:e,type:u,key:g,ref:m,props:p,_owner:a.current}}return Kt.Fragment=n,Kt.jsx=l,Kt.jsxs=l,Kt}var Ut={};/**
|
|
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 qa;function
|
|
17
|
+
*/var qa;function ru(){return qa||(qa=1,process.env.NODE_ENV!=="production"&&function(){var t=y,e=Symbol.for("react.element"),n=Symbol.for("react.portal"),r=Symbol.for("react.fragment"),a=Symbol.for("react.strict_mode"),o=Symbol.for("react.profiler"),l=Symbol.for("react.provider"),u=Symbol.for("react.context"),c=Symbol.for("react.forward_ref"),d=Symbol.for("react.suspense"),f=Symbol.for("react.suspense_list"),p=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 A=C&&S[C]||S[w];return typeof A=="function"?A:null}var T=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function M(S){{for(var A=arguments.length,P=new Array(A>1?A-1:0),Q=1;Q<A;Q++)P[Q-1]=arguments[Q];O("error",S,P)}}function O(S,A,P){{var Q=T.ReactDebugCurrentFrame,le=Q.getStackAddendum();le!==""&&(A+="%s",P=P.concat([le]));var pe=P.map(function(ie){return String(ie)});pe.unshift("Warning: "+A),Function.prototype.apply.call(console[S],console,pe)}}var B=!1,F=!1,$=!1,E=!1,z=!1,W;W=Symbol.for("react.module.reference");function U(S){return!!(typeof S=="string"||typeof S=="function"||S===r||S===o||z||S===a||S===d||S===f||E||S===m||B||F||$||typeof S=="object"&&S!==null&&(S.$$typeof===g||S.$$typeof===p||S.$$typeof===l||S.$$typeof===u||S.$$typeof===c||S.$$typeof===W||S.getModuleId!==void 0))}function X(S,A,P){var Q=S.displayName;if(Q)return Q;var le=A.displayName||A.name||"";return le!==""?P+"("+le+")":P}function oe(S){return S.displayName||"Context"}function re(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 A=S;return oe(A)+".Consumer";case l:var P=S;return oe(P._context)+".Provider";case c:return X(S,S.render,"ForwardRef");case p:var Q=S.displayName||null;return Q!==null?Q:re(S.type)||"Memo";case g:{var le=S,pe=le._payload,ie=le._init;try{return re(ie(pe))}catch{return null}}}return null}var de=Object.assign,Ce=0,ye,Te,fe,Oe,Ye,Mt,ar;function sr(){}sr.__reactDisabledLog=!0;function fa(){{if(Ce===0){ye=console.log,Te=console.info,fe=console.warn,Oe=console.error,Ye=console.group,Mt=console.groupCollapsed,ar=console.groupEnd;var S={configurable:!0,enumerable:!0,value:sr,writable:!0};Object.defineProperties(console,{info:S,log:S,warn:S,error:S,group:S,groupCollapsed:S,groupEnd:S})}Ce++}}function ga(){{if(Ce--,Ce===0){var S={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:de({},S,{value:ye}),info:de({},S,{value:Te}),warn:de({},S,{value:fe}),error:de({},S,{value:Oe}),group:de({},S,{value:Ye}),groupCollapsed:de({},S,{value:Mt}),groupEnd:de({},S,{value:ar})})}Ce<0&&M("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var ln=T.ReactCurrentDispatcher,Ft;function xt(S,A,P){{if(Ft===void 0)try{throw Error()}catch(le){var Q=le.stack.trim().match(/\n( *(at )?)/);Ft=Q&&Q[1]||""}return`
|
|
18
18
|
`+Ft+S}}var Et=!1,wt;{var Gt=typeof WeakMap=="function"?WeakMap:Map;wt=new Gt}function Wt(S,A){if(!S||Et)return"";{var P=wt.get(S);if(P!==void 0)return P}var Q;Et=!0;var le=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var pe;pe=ln.current,ln.current=null,fa();try{if(A){var ie=function(){throw Error()};if(Object.defineProperty(ie.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(ie,[])}catch(dt){Q=dt}Reflect.construct(S,[],ie)}else{try{ie.call()}catch(dt){Q=dt}S.call(ie.prototype)}}else{try{throw Error()}catch(dt){Q=dt}S()}}catch(dt){if(dt&&Q&&typeof dt.stack=="string"){for(var ee=dt.stack.split(`
|
|
19
19
|
`),Be=Q.stack.split(`
|
|
20
20
|
`),xe=ee.length-1,Se=Be.length-1;xe>=1&&Se>=0&&ee[xe]!==Be[Se];)Se--;for(;xe>=1&&Se>=0;xe--,Se--)if(ee[xe]!==Be[Se]){if(xe!==1||Se!==1)do if(xe--,Se--,Se<0||ee[xe]!==Be[Se]){var Qe=`
|
|
21
|
-
`+ee[xe].replace(" at new "," at ");return S.displayName&&Qe.includes("<anonymous>")&&(Qe=Qe.replace("<anonymous>",S.displayName)),typeof S=="function"&&wt.set(S,Qe),Qe}while(xe>=1&&Se>=0);break}}}finally{Et=!1,ln.current=pe,ga(),Error.prepareStackTrace=le}var jt=S?S.displayName||S.name:"",
|
|
21
|
+
`+ee[xe].replace(" at new "," at ");return S.displayName&&Qe.includes("<anonymous>")&&(Qe=Qe.replace("<anonymous>",S.displayName)),typeof S=="function"&&wt.set(S,Qe),Qe}while(xe>=1&&Se>=0);break}}}finally{Et=!1,ln.current=pe,ga(),Error.prepareStackTrace=le}var jt=S?S.displayName||S.name:"",Rl=jt?xt(jt):"";return typeof S=="function"&&wt.set(S,Rl),Rl}function un(S,A,P){return Wt(S,!1)}function cn(S){var A=S.prototype;return!!(A&&A.isReactComponent)}function Ct(S,A,P){if(S==null)return"";if(typeof S=="function")return Wt(S,cn(S));if(typeof S=="string")return xt(S);switch(S){case d:return xt("Suspense");case f:return xt("SuspenseList")}if(typeof S=="object")switch(S.$$typeof){case c:return un(S.render);case p:return Ct(S.type,A,P);case g:{var Q=S,le=Q._payload,pe=Q._init;try{return Ct(pe(le),A,P)}catch{}}}return""}var dn=Object.prototype.hasOwnProperty,zl={},$l=T.ReactDebugCurrentFrame;function or(S){if(S){var A=S._owner,P=Ct(S.type,S._source,A?A.type:null);$l.setExtraStackFrame(P)}else $l.setExtraStackFrame(null)}function hT(S,A,P,Q,le){{var pe=Function.call.bind(dn);for(var ie in S)if(pe(S,ie)){var ee=void 0;try{if(typeof S[ie]!="function"){var Be=Error((Q||"React class")+": "+P+" type `"+ie+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof S[ie]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw Be.name="Invariant Violation",Be}ee=S[ie](A,ie,Q,P,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(xe){ee=xe}ee&&!(ee instanceof Error)&&(or(le),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).",Q||"React class",P,ie,typeof ee),or(null)),ee instanceof Error&&!(ee.message in zl)&&(zl[ee.message]=!0,or(le),M("Failed %s type: %s",P,ee.message),or(null))}}}var fT=Array.isArray;function ma(S){return fT(S)}function gT(S){{var A=typeof Symbol=="function"&&Symbol.toStringTag,P=A&&S[Symbol.toStringTag]||S.constructor.name||"Object";return P}}function mT(S){try{return Ll(S),!1}catch{return!0}}function Ll(S){return""+S}function Ol(S){if(mT(S))return M("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",gT(S)),Ll(S)}var pn=T.ReactCurrentOwner,yT={key:!0,ref:!0,__self:!0,__source:!0},Pl,Bl,ya;ya={};function bT(S){if(dn.call(S,"ref")){var A=Object.getOwnPropertyDescriptor(S,"ref").get;if(A&&A.isReactWarning)return!1}return S.ref!==void 0}function vT(S){if(dn.call(S,"key")){var A=Object.getOwnPropertyDescriptor(S,"key").get;if(A&&A.isReactWarning)return!1}return S.key!==void 0}function xT(S,A){if(typeof S.ref=="string"&&pn.current&&A&&pn.current.stateNode!==A){var P=re(pn.current.type);ya[P]||(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',re(pn.current.type),S.ref),ya[P]=!0)}}function wT(S,A){{var P=function(){Pl||(Pl=!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)",A))};P.isReactWarning=!0,Object.defineProperty(S,"key",{get:P,configurable:!0})}}function CT(S,A){{var P=function(){Bl||(Bl=!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)",A))};P.isReactWarning=!0,Object.defineProperty(S,"ref",{get:P,configurable:!0})}}var ST=function(S,A,P,Q,le,pe,ie){var ee={$$typeof:e,type:S,key:A,ref:P,props:ie,_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:Q}),Object.defineProperty(ee,"_source",{configurable:!1,enumerable:!1,writable:!1,value:le}),Object.freeze&&(Object.freeze(ee.props),Object.freeze(ee)),ee};function _T(S,A,P,Q,le){{var pe,ie={},ee=null,Be=null;P!==void 0&&(Ol(P),ee=""+P),vT(A)&&(Ol(A.key),ee=""+A.key),bT(A)&&(Be=A.ref,xT(A,le));for(pe in A)dn.call(A,pe)&&!yT.hasOwnProperty(pe)&&(ie[pe]=A[pe]);if(S&&S.defaultProps){var xe=S.defaultProps;for(pe in xe)ie[pe]===void 0&&(ie[pe]=xe[pe])}if(ee||Be){var Se=typeof S=="function"?S.displayName||S.name||"Unknown":S;ee&&wT(ie,Se),Be&&CT(ie,Se)}return ST(S,ee,Be,le,Q,pn.current,ie)}}var ba=T.ReactCurrentOwner,Vl=T.ReactDebugCurrentFrame;function Rt(S){if(S){var A=S._owner,P=Ct(S.type,S._source,A?A.type:null);Vl.setExtraStackFrame(P)}else Vl.setExtraStackFrame(null)}var va;va=!1;function xa(S){return typeof S=="object"&&S!==null&&S.$$typeof===e}function Nl(){{if(ba.current){var S=re(ba.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 kT(S){{if(S!==void 0){var A=S.fileName.replace(/^.*[\\\/]/,""),P=S.lineNumber;return`
|
|
24
24
|
|
|
25
|
-
Check your code at `+A+":"+P+"."}return""}}var
|
|
25
|
+
Check your code at `+A+":"+P+"."}return""}}var ql={};function TT(S){{var A=Nl();if(!A){var P=typeof S=="string"?S:S.displayName||S.name;P&&(A=`
|
|
26
26
|
|
|
27
|
-
Check the top-level render call using <`+P+">.")}return A}}function
|
|
27
|
+
Check the top-level render call using <`+P+">.")}return A}}function Fl(S,A){{if(!S._store||S._store.validated||S.key!=null)return;S._store.validated=!0;var P=TT(A);if(ql[P])return;ql[P]=!0;var Q="";S&&S._owner&&S._owner!==ba.current&&(Q=" It was passed a child from "+re(S._owner.type)+"."),Rt(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.',P,Q),Rt(null)}}function Gl(S,A){{if(typeof S!="object")return;if(ma(S))for(var P=0;P<S.length;P++){var Q=S[P];xa(Q)&&Fl(Q,A)}else if(xa(S))S._store&&(S._store.validated=!0);else if(S){var le=_(S);if(typeof le=="function"&&le!==S.entries)for(var pe=le.call(S),ie;!(ie=pe.next()).done;)xa(ie.value)&&Fl(ie.value,A)}}}function DT(S){{var A=S.type;if(A==null||typeof A=="string")return;var P;if(typeof A=="function")P=A.propTypes;else if(typeof A=="object"&&(A.$$typeof===c||A.$$typeof===p))P=A.propTypes;else return;if(P){var Q=re(A);hT(P,S.props,"prop",Q,S)}else if(A.PropTypes!==void 0&&!va){va=!0;var le=re(A);M("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",le||"Unknown")}typeof A.getDefaultProps=="function"&&!A.getDefaultProps.isReactClassApproved&&M("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function IT(S){{for(var A=Object.keys(S.props),P=0;P<A.length;P++){var Q=A[P];if(Q!=="children"&&Q!=="key"){Rt(S),M("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",Q),Rt(null);break}}S.ref!==null&&(Rt(S),M("Invalid attribute `ref` supplied to `React.Fragment`."),Rt(null))}}function Wl(S,A,P,Q,le,pe){{var ie=U(S);if(!ie){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 Be=kT(le);Be?ee+=Be:ee+=Nl();var xe;S===null?xe="null":ma(S)?xe="array":S!==void 0&&S.$$typeof===e?(xe="<"+(re(S.type)||"Unknown")+" />",ee=" Did you accidentally export a JSX literal instead of a component?"):xe=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",xe,ee)}var Se=_T(S,A,P,le,pe);if(Se==null)return Se;if(ie){var Qe=A.children;if(Qe!==void 0)if(Q)if(ma(Qe)){for(var jt=0;jt<Qe.length;jt++)Gl(Qe[jt],S);Object.freeze&&Object.freeze(Qe)}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 Gl(Qe,S)}return S===r?IT(Se):DT(Se),Se}}function MT(S,A,P){return Wl(S,A,P,!0)}function ET(S,A,P){return Wl(S,A,P,!1)}var AT=ET,zT=MT;Ut.Fragment=r,Ut.jsx=AT,Ut.jsxs=zT}()),Ut}(function(t){process.env.NODE_ENV==="production"?t.exports=nu():t.exports=ru()})(tu);const N=Qt.Fragment,i=Qt.jsx,h=Qt.jsxs,zt={CryptoJS:wa,d3Array:eu,dayjs:Y,lodash:x,numbro:te,mathjs:mn,faker:Yl.faker},iu=[{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"}],au=t=>`
|
|
28
28
|
<tr>
|
|
29
29
|
<td><code>${t.name}</code></td>
|
|
30
30
|
<td>
|
|
@@ -36,7 +36,7 @@ Check the top-level render call using <`+P+">.")}return A}}function ql(S,A){{if(
|
|
|
36
36
|
>
|
|
37
37
|
</td>
|
|
38
38
|
</tr>
|
|
39
|
-
`,
|
|
39
|
+
`,su=`
|
|
40
40
|
<p>
|
|
41
41
|
Parameter <code>utils</code> is <code>functionUtils</code>, which contains:
|
|
42
42
|
</p>
|
|
@@ -48,11 +48,11 @@ Check the top-level render call using <`+P+">.")}return A}}function ql(S,A){{if(
|
|
|
48
48
|
</tr>
|
|
49
49
|
</thead>
|
|
50
50
|
<tbody>
|
|
51
|
-
${
|
|
51
|
+
${iu.map(au).join("")}
|
|
52
52
|
</tbody>
|
|
53
53
|
</table>
|
|
54
|
-
`;function ur(t,e){const n=Object.keys(e),r=Object.values(e);try{return new Function(...n,`return \`${t}\`;`)(...r)}catch(a){throw n.length===0&&t.includes("$")?new Error("[formatSQL] insufficient payload"):a}}function dr(t,e){try{return ur(t,e)}catch(n){return console.error(n),n.message}}function sc({sql:t,pre_process:e}){if(!e.trim())return t;try{return new Function(`return ${e}`)()({sql:t},zt)}catch(n){return console.error(n),t}}function oc(t,e){if(!t.trim())return e;try{return new Function(`return ${t}`)()(e,zt)}catch(n){return console.error(n),e}}function lc(t){t=t||{};const e=Object.keys(t).sort(),n=[];for(let r=0;r<e.length;r++){const a=e[r];if(a!="authentication"&&t[a])n.push(e[r]+"="+(typeof t[a]=="object"?JSON.stringify(t[a]):t[a]));else{const o=Object.keys(t[a]).sort();for(let l=0;l<o.length;l++){const c=o[l];c!="sign"&&t[a][c]&&n.push(o[l]+"="+(typeof t[a][c]=="object"?JSON.stringify(t[a][c]):t[a][c]))}}}return n.sort().join("&")}function cc(t,e){let n=lc(t);return n+="&key="+e,wa.MD5(n).toString().toUpperCase()}const qe={baseURL:"http://localhost:31200",app_id:"",app_secret:"",getAuthentication(t){if(!this.app_id||!this.app_secret)return;const e=new Date().getTime().toString();return{app_id:this.app_id,nonce_str:e,sign:cc({app_id:this.app_id,nonce_str:e,...t},this.app_secret)}},getRequest(t,e){return(n,r,a={})=>{const o=window.localStorage.getItem("token"),l={"X-Requested-With":"XMLHttpRequest","Content-Type":a.string?"application/x-www-form-urlencoded":"application/json",authorization:o?`bearer ${o}`:"",...a.headers},c={baseURL:this.baseURL,method:t,url:n,params:t==="GET"?r:a.params,headers:l,signal:e};return["POST","PUT"].includes(t)&&(c.data=a.string?JSON.stringify(r):r,c.data.authentication=this.getAuthentication(c.data)),pt(c).then(u=>u.data).catch(u=>Promise.reject(u))}},makeQueryENV:null,query(t){return async(e,n={})=>{var r;return e.env||(e.env=((r=this.makeQueryENV)==null?void 0:r.call(this))??{error:"failed to run makeQueryENV"}),this.getRequest("POST",t)("/query",e,n)}}};function Fa(t){qe.baseURL!==t.apiBaseURL&&(qe.baseURL=t.apiBaseURL),t.app_id&&(qe.app_id=t.app_id),t.app_secret&&(qe.app_secret=t.app_secret),t.makeQueryENV&&(qe.makeQueryENV=t.makeQueryENV)}async function uc({query:t,payload:e},n){if(!t.sql)return[];const{type:r,key:a,sql:o,pre_process:l,post_process:c}=t,u=ur(o,e),d=sc({sql:u,pre_process:l});let f=await qe.query(n)({type:r,key:a,query:d},{});return f=oc(c,f),f}async function dc({type:t,key:e,configString:n},r){return await qe.query(r)({type:t,key:e,query:n},{})}async function pr(){try{return(await qe.getRequest("POST")("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}})).data}catch(t){return console.error(t),[]}}async function Ga(){try{return(await qe.getRequest("POST")("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}})).data}catch(t){return console.error(t),[]}}const Wa=y.createContext(null),hr=Wa.Provider;function K(){const t=y.useContext(Wa);if(!t)throw new Error("Please use ContentModelContextProvider");return t}const pc={layoutFrozen:!1,freezeLayout:x.noop,inEditMode:!1},ft=y.createContext(pc),Ra=y.createContext(null),fr=Ra.Provider;function ge(){const t=y.useContext(Ra);if(!t)throw new Error("Please use ModelContextProvider");return t}function ja(t,e){y.useEffect(()=>{const n=r=>{console.log(r);const{viewID:a}=r.detail;if(!a){console.error(new Error("[Open View] Needs to pick a view first"));return}t.views.appendToVisibles(a),e&&t.views.setIDOfVIE(a)};return window.addEventListener("open-view",n),()=>{window.removeEventListener("open-view",n)}},[t,e]),y.useEffect(()=>{const n=r=>{console.log(r);const{dictionary:a,payload:o}=r.detail;if(!o||Object.keys(o).length===0){console.error(new Error("[Set Filter Values] payload is empty"));return}Object.entries(a).forEach(([l,c])=>{t.filters.setValueByKey(l,x.get(o,c))})};return window.addEventListener("set-filter-values",n),()=>{window.removeEventListener("set-filter-values",n)}},[t]),y.useEffect(()=>{function n(a){return Array.isArray(a)?[]:typeof a=="object"?{}:typeof a=="boolean"?!1:typeof a=="string"?"":typeof a=="number"?0:a}const r=a=>{console.log(a);const{filter_keys:o}=a.detail;o.forEach(l=>{const c=x.get(t.filters.values,l),u=n(c);console.log(`${l}: ${u}`),t.filters.setValueByKey(l,u)})};return window.addEventListener("clear-filter-values",r),()=>{window.removeEventListener("clear-filter-values",r)}},[t]),y.useEffect(()=>{const n=r=>{console.log(r);const{urlTemplate:a,openInNewTab:o,enableEncoding:l=!1,payload:c}=r.detail;if(!a){console.error(new Error("[Open Link] URL is empty"));return}function u(h){return x.cloneDeepWith(h,m=>{if(l&&typeof m=="string")return encodeURIComponent(m)})}const f=x.template(a||"")(u({...c,filters:t.payloadForSQL.filters,context:t.payloadForSQL.context}));window.open(f,o?"_blank":"_self","noopener")};return window.addEventListener("open-link",n),()=>{window.removeEventListener("open-link",n)}},[t])}const Ya=b.types.model("FilterConfigModel_Checkbox",{_name:b.types.literal("checkbox"),description:b.types.optional(b.types.string,""),default_value:b.types.boolean}).views(t=>({get json(){const{_name:e,description:n,default_value:r}=t;return{_name:e,description:n,default_value:r}},get isDescriptionEmpty(){const{description:e}=t;return e===""||e==="<p></p>"}})).actions(t=>({setDefaultValue(e){t.default_value=e},setDescription(e){t.description=e}})),hc=()=>Ya.create({_name:"checkbox",description:"",default_value:!1});var be=(t=>(t.Postgresql="postgresql",t.MySQL="mysql",t.HTTP="http",t))(be||{}),Ee=(t=>(t.Select="select",t.MultiSelect="multi-select",t.TreeSelect="tree-select",t.TextInput="text-input",t.Checkbox="checkbox",t.DateRange="date-range",t))(Ee||{});b.types.model({type:b.types.enumeration("DataSourceType",[be.Postgresql,be.MySQL,be.HTTP]),key:b.types.string,sql:b.types.string});function Qa(t,e){return t.map(n=>{try{return n?Y.tz(n,"UTC").format(e):null}catch{return console.log(`[date-range] failed parsing ${n}`),null}})}const fc=b.types.model("FilterConfigModel_DateRange",{_name:b.types.literal("date-range"),required:b.types.boolean,inputFormat:b.types.enumeration("DateRangeInputFormat",["YYYY","YYYYMM","YYYYMMDD","YYYY-MM","YYYY-MM-DD"]),default_value:b.types.optional(b.types.array(b.types.union(b.types.string,b.types.null)),[null,null]),clearable:b.types.boolean,max_days:b.types.optional(b.types.number,0),allowSingleDateInRange:b.types.optional(b.types.boolean,!1)}).views(t=>({get json(){const{_name:e,max_days:n,required:r,clearable:a,inputFormat:o,default_value:l,allowSingleDateInRange:c}=t;return{_name:e,max_days:n,required:r,clearable:a,inputFormat:o,default_value:Qa(l,o),allowSingleDateInRange:c}},truthy(e){return Array.isArray(e)&&e.length===2&&e.every(n=>!!n)}})).views(t=>({getMaxDate(e){const{max_days:n}=t;if(!(!n||!e))return Y(e).startOf("day").add(n,"days").toDate()},getMinDate(e){const{max_days:n}=t;if(!(!n||!e))return Y(e).startOf("day").subtract(n,"days").toDate()}})).actions(t=>({setFilterValue(e){try{const n=b.getParent(t);b.getRoot(t).filters.setValueByKey(n.key,e)}catch(n){console.error(n)}}})).actions(t=>({setRequired(e){t.required=e},setClearable(e){t.clearable=e},setInputFormat(e){t.inputFormat=e},setDefaultValue(e){t.default_value.length=0,t.default_value.push(...e),t.setFilterValue(e)},setMaxDays(e){t.max_days=e,e>0&&(t.clearable=!0)},setAllowSingleDateInRange(e){t.allowSingleDateInRange=e}})),Ka=b.types.snapshotProcessor(fc,{preProcessor({default_value:t,...e}){return{...e,default_value:t.map(n=>n===null?null:Y.tz(n,"UTC").toISOString())}},postProcessor(t){const{default_value:e,...n}=t;return{...n,default_value:Qa(e,n.inputFormat)}}}),gc=()=>Ka.create({_name:"date-range",required:!1,inputFormat:"YYYY-MM-DD",clearable:!1,default_value:[null,null]}),mc=b.types.model({label:b.types.string,value:b.types.string}).actions(t=>({setLabel(e){t.label=e},setValue(e){t.value=e}})),gr=b.types.model("FilterConfigModel_BaseSelect",{static_options:b.types.optional(b.types.array(mc),[]),options_query_id:b.types.optional(b.types.string,""),default_selection_count:b.types.optional(b.types.number,0)}).views(t=>({get usingQuery(){return!!t.options_query_id}})).views(t=>({get options(){if(!t.usingQuery)return t.static_options;const{data:e,state:n,error:r}=b.getRoot(t).content.getDataStuffByID(t.options_query_id);return n==="idle"?e:[]}})).actions(t=>({addStaticOption(e){t.static_options.push(e)},removeStaticOption(e){t.static_options.splice(e,1)},setDefaultSelectionCount(e){t.default_selection_count=e},setOptionsQueryID(e){t.options_query_id=e??""}})),yn=t=>x.cloneDeepWith(t,(e,n)=>{if(n!==void 0&&e)return ae.toJS(e)}),Ua=b.types.compose("FilterConfigModel_MultiSelect",b.types.model({_name:b.types.literal("multi-select"),min_width:b.types.optional(b.types.string,""),default_value:b.types.optional(b.types.array(b.types.string),[])}),gr).views(t=>({get json(){const{_name:e,default_value:n,min_width:r,static_options:a,options_query_id:o,default_selection_count:l}=t;return yn({_name:e,min_width:r,default_value:n,static_options:a,options_query_id:o,default_selection_count:l})},get default_selection(){return t.usingQuery?t.options.slice(0,t.default_selection_count).map(e=>e.value):t.default_value}})).actions(t=>({setDefaultValue(e){t.default_value=b.cast(e)},setMinWidth(e){t.min_width=e},setDefaultSelection(){const e=b.getRoot(t).content.filters,n=b.getParent(t).key;e.setValueByKey(n,t.default_selection)}})).actions(t=>({afterCreate(){b.addDisposer(t,ae.reaction(()=>ae.toJS(t.default_selection),t.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),yc=()=>Ua.create({_name:"multi-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0});function bc(t){return Yl.arrayToTree(t,{id:"value",parentId:"parent_value",childrenField:"children",dataField:null})}function vc(t){return t.map(e=>{const{label:n,description:r,...a}=e,o={...a,filterBasis:`${n}___${r??""}`,description:r,label:n};return r&&(o.label=y.createElement("div",{},[y.createElement(s.Text,{key:0,title:e.label},e.label),y.createElement(s.Text,{key:1,className:"rc-tree-select-tree-title-desc",color:"dimmed",title:e.description},e.description)])),o})}const Xa=b.types.compose("FilterConfigModel_TreeSelect",b.types.model({_name:b.types.literal("tree-select"),min_width:b.types.optional(b.types.string,""),default_value:b.types.optional(b.types.array(b.types.string),[])}),gr).views(t=>({get json(){const{_name:e,default_value:n,min_width:r,static_options:a,options_query_id:o,default_selection_count:l}=t;return{_name:e,min_width:r,default_value:n,static_options:a,options_query_id:o,default_selection_count:l}},get treeData(){const{data:e}=b.getRoot(t).content.getDataStuffByID(t.options_query_id),n=vc(e);return bc(n)},get errorMessage(){const{error:e}=b.getRoot(t).content.getDataStuffByID(t.options_query_id);return e},get treeDataLoading(){const{state:e}=b.getRoot(t).content.getDataStuffByID(t.options_query_id);return e==="loading"},get defaultSelection(){const{default_selection_count:e}=t;return e?this.treeData.slice(0,e).map(r=>r.value):[]}})).actions(t=>({setDefaultValue(e){t.default_value=b.cast(e)},setMinWidth(e){t.min_width=e},applyDefaultSelection(){const e=b.getParent(t,1).key;b.getRoot(t).content.filters.setValueByKey(e,t.defaultSelection)},afterCreate(){b.addDisposer(t,ae.reaction(()=>JSON.stringify(t.defaultSelection),this.applyDefaultSelection,{fireImmediately:!0,delay:0}))}})),xc=()=>Xa.create({_name:"tree-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),Ja=b.types.compose("FilterConfigModel_Select",b.types.model({_name:b.types.literal("select"),default_value:b.types.string,required:b.types.boolean,width:b.types.optional(b.types.string,"")}),gr).views(t=>({get json(){const{_name:e,default_value:n,required:r,width:a,static_options:o,options_query_id:l,default_selection_count:c}=t;return yn({_name:e,width:a,required:r,default_value:n,static_options:o,options_query_id:l,default_selection_count:c})},truthy(e){return!!e}})).actions(t=>({setRequired(e){t.required=e},setDefaultValue(e){t.default_value=e},setWidth(e){t.width=e}})),wc=()=>Ja.create({_name:"select",required:!1,default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),Za=b.types.model("FilterConfigModel_TextInput",{_name:b.types.literal("text-input"),required:b.types.boolean,default_value:b.types.string}).views(t=>({get json(){const{_name:e,required:n,default_value:r}=t;return{_name:e,required:n,default_value:r}},truthy(e){return typeof e!="string"?!1:!!e.trim()}})).actions(t=>({setRequired(e){t.required=e},setDefaultValue(e){t.default_value=e}})),Ha=()=>Za.create({_name:"text-input",required:!1,default_value:""}),mr=b.types.model("FilterModel",{id:b.types.identifier,key:b.types.string,label:b.types.string,order:b.types.number,visibleInViewsIDs:b.types.array(b.types.string),auto_submit:b.types.optional(b.types.boolean,!1),type:b.types.enumeration("DashboardFilterType",[Ee.Select,Ee.MultiSelect,Ee.TreeSelect,Ee.TextInput,Ee.Checkbox,Ee.DateRange]),config:b.types.union(Ja,Ua,Xa,Za,Ya,Ka)}).views(t=>({get plainDefaultValue(){const e=t.config.default_value;return Array.isArray(e)?[...e]:e},get usingDefaultValue(){return t.type!==Ee.TreeSelect},get auto_submit_supported(){return[Ee.Select,Ee.Checkbox,Ee.DateRange].includes(t.type)}})).views(t=>({get json(){const{id:e,key:n,label:r,order:a,visibleInViewsIDs:o,auto_submit:l,type:c,config:u}=t;return{id:e,key:n,type:c,label:r,order:a,config:u.json,auto_submit:l,visibleInViewsIDs:ae.toJS(o)}},get should_auto_submit(){return t.auto_submit_supported&&t.auto_submit},requiredAndPass(e){return x.get(t.config,"required",!1)?x.get(t.config,"truthy",()=>!0)(e):!1}})).actions(t=>({setKey(e){t.key=e},setLabel(e){t.label=e},setOrder(e){t.order=e},setType(e){switch(e){case Ee.Select:t.config=wc();break;case Ee.MultiSelect:t.config=yc();break;case Ee.TreeSelect:t.config=xc();break;case Ee.TextInput:t.config=Ha();break;case Ee.Checkbox:t.config=hc();break;case Ee.DateRange:t.config=gc();break}t.type=e},setVisibleInViewsIDs(e){t.visibleInViewsIDs.length=0,t.visibleInViewsIDs.push(...e)},setAutoSubmit(e){t.auto_submit=t.auto_submit_supported&&e}}));function es(t,e){if(t===void 0)return t;if(e._name==="date-range")try{const[...n]=t;return n.map(r=>r===null?r:Y.tz(r,"UTC").format(e.inputFormat)??r)}catch(n){return console.error(n),t}return t}function Cc(t){return t.reduce((e,n)=>(e[n.key]=es(n.config.default_value,n.config),e),{})}function Sc(t,e,n){b.addDisposer(t,b.addMiddleware(t,(r,a)=>{a(r,()=>{b.getType(r.context)===e&&r.type==="action"&&n(r.name,r.context)})}))}const ts=b.types.model("FiltersModel",{current:b.types.optional(b.types.array(mr),[]),values:b.types.optional(b.types.frozen(),{}),previewValues:b.types.optional(b.types.frozen(),{})}).views(t=>({get json(){return t.current.map(e=>e.json)},get firstID(){if(t.current.length!==0)return t.current[0].id},findByID(e){return t.current.find(n=>n.id===e)},get inOrder(){return x.sortBy(t.current,"order")},get options(){return t.current.map(e=>({label:e.label??e.id,value:e.id,_type:"filter"}))},get keyLabelOptions(){return t.current.map(e=>({label:e.label??e.key,value:e.key}))},get empty(){return t.current.length===0},visibleInView(e){return x.sortBy(t.current.filter(n=>n.visibleInViewsIDs.includes(e)),"order")},get firstFilterValueKey(){return Object.keys(t.values)[0]??""},get keyLabelMap(){return t.current.reduce((e,n)=>(e[n.key]=n.label,e),{})}})).actions(t=>({replace(e){t.current=b.cast(e)},append(e){t.current.push(e)},remove(e){t.current.splice(e,1)},removeByID(e){const n=t.current.findIndex(r=>r.id===e);n>=0&&t.current.splice(n,1)},setValues(e){t.values=e},setValueByKey(e,n){t.values={...t.values,[e]:n}},getValueByKey(e){return t.values[e]},updatePreviewValues(e){t.previewValues=e}})).actions(t=>{function e(){Sc(t.current,mr,(n,r)=>{if(n==="setType"){const a=es(r.config.default_value,r.config);t.setValueByKey(r.key,a),t.updatePreviewValues({...t.previewValues,[r.key]:a})}})}return{afterCreate(){e()}}});function ns(t){return{current:t,values:Cc(t)}}const rs="\uFEFF";function _c(t,e){const n=new Blob([rs+e],{type:"text/csv"});lr.saveAs(n,`${t}.csv`)}function kc(t,e){const n=new Blob([e],{type:"application/json"});lr.saveAs(n,`${t}.json`)}function is(t){const e=new Ql;t.forEach(({id:n,data:r})=>{e.file(`${n}.csv`,ss(r))}),e.generateAsync({type:"blob"}).then(n=>{lr.saveAs(n,"dashboard_data.zip")})}function as(t){return typeof t=="string"&&t.includes(",")?`"${t}"`:t}function ss(t){if(!Array.isArray(t)||t.length===0)return"";const e=[],n=Object.keys(t[0]).map(as);return e.push(n.join(",")),t.forEach(r=>{const a=Object.values(r).map(as).join(",");e.push(a)}),rs+e.join(`
|
|
55
|
-
`)}const
|
|
54
|
+
`;function cr(t,e){const n=Object.keys(e),r=Object.values(e);try{return new Function(...n,`return \`${t}\`;`)(...r)}catch(a){throw n.length===0&&t.includes("$")?new Error("[formatSQL] insufficient payload"):a}}function dr(t,e){try{return cr(t,e)}catch(n){return console.error(n),n.message}}function ou({sql:t,pre_process:e}){if(!e.trim())return t;try{return new Function(`return ${e}`)()({sql:t},zt)}catch(n){return console.error(n),t}}function lu(t,e){if(!t.trim())return e;try{return new Function(`return ${t}`)()(e,zt)}catch(n){return console.error(n),e}}function uu(t){t=t||{};const e=Object.keys(t).sort(),n=[];for(let r=0;r<e.length;r++){const a=e[r];if(a!="authentication"&&t[a])n.push(e[r]+"="+(typeof t[a]=="object"?JSON.stringify(t[a]):t[a]));else{const o=Object.keys(t[a]).sort();for(let l=0;l<o.length;l++){const u=o[l];u!="sign"&&t[a][u]&&n.push(o[l]+"="+(typeof t[a][u]=="object"?JSON.stringify(t[a][u]):t[a][u]))}}}return n.sort().join("&")}function cu(t,e){let n=uu(t);return n+="&key="+e,wa.MD5(n).toString().toUpperCase()}const qe={baseURL:"http://localhost:31200",app_id:"",app_secret:"",getAuthentication(t){if(!this.app_id||!this.app_secret)return;const e=new Date().getTime().toString();return{app_id:this.app_id,nonce_str:e,sign:cu({app_id:this.app_id,nonce_str:e,...t},this.app_secret)}},getRequest(t,e){return(n,r,a={})=>{const o=window.localStorage.getItem("token"),l={"X-Requested-With":"XMLHttpRequest","Content-Type":a.string?"application/x-www-form-urlencoded":"application/json",authorization:o?`bearer ${o}`:"",...a.headers},u={baseURL:this.baseURL,method:t,url:n,params:t==="GET"?r:a.params,headers:l,signal:e};return["POST","PUT"].includes(t)&&(u.data=a.string?JSON.stringify(r):r,u.data.authentication=this.getAuthentication(u.data)),pt(u).then(c=>c.data).catch(c=>Promise.reject(c))}},makeQueryENV:null,query(t){return async(e,n={})=>{var r;return e.env||(e.env=((r=this.makeQueryENV)==null?void 0:r.call(this))??{error:"failed to run makeQueryENV"}),this.getRequest("POST",t)("/query",e,n)}}};function Fa(t){qe.baseURL!==t.apiBaseURL&&(qe.baseURL=t.apiBaseURL),t.app_id&&(qe.app_id=t.app_id),t.app_secret&&(qe.app_secret=t.app_secret),t.makeQueryENV&&(qe.makeQueryENV=t.makeQueryENV)}async function du({query:t,payload:e},n){if(!t.sql)return[];const{type:r,key:a,sql:o,pre_process:l,post_process:u}=t,c=cr(o,e),d=ou({sql:c,pre_process:l});let f=await qe.query(n)({type:r,key:a,query:d},{});return f=lu(u,f),f}async function pu({type:t,key:e,configString:n},r){return await qe.query(r)({type:t,key:e,query:n},{})}async function pr(){try{return(await qe.getRequest("POST")("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}})).data}catch(t){return console.error(t),[]}}async function Ga(){try{return(await qe.getRequest("POST")("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}})).data}catch(t){return console.error(t),[]}}const Wa=y.createContext(null),hr=Wa.Provider;function K(){const t=y.useContext(Wa);if(!t)throw new Error("Please use ContentModelContextProvider");return t}const hu={layoutFrozen:!1,freezeLayout:x.noop,inEditMode:!1},ft=y.createContext(hu),Ra=y.createContext(null),fr=Ra.Provider;function ge(){const t=y.useContext(Ra);if(!t)throw new Error("Please use ModelContextProvider");return t}function ja(t,e){y.useEffect(()=>{const n=r=>{console.log(r);const{viewID:a}=r.detail;if(!a){console.error(new Error("[Open View] Needs to pick a view first"));return}t.views.appendToVisibles(a),e&&t.views.setIDOfVIE(a)};return window.addEventListener("open-view",n),()=>{window.removeEventListener("open-view",n)}},[t,e]),y.useEffect(()=>{const n=r=>{console.log(r);const{dictionary:a,payload:o}=r.detail;if(!o||Object.keys(o).length===0){console.error(new Error("[Set Filter Values] payload is empty"));return}Object.entries(a).forEach(([l,u])=>{t.filters.setValueByKey(l,x.get(o,u))})};return window.addEventListener("set-filter-values",n),()=>{window.removeEventListener("set-filter-values",n)}},[t]),y.useEffect(()=>{function n(a){return Array.isArray(a)?[]:typeof a=="object"?{}:typeof a=="boolean"?!1:typeof a=="string"?"":typeof a=="number"?0:a}const r=a=>{console.log(a);const{filter_keys:o}=a.detail;o.forEach(l=>{const u=x.get(t.filters.values,l),c=n(u);console.log(`${l}: ${c}`),t.filters.setValueByKey(l,c)})};return window.addEventListener("clear-filter-values",r),()=>{window.removeEventListener("clear-filter-values",r)}},[t]),y.useEffect(()=>{const n=r=>{console.log(r);const{urlTemplate:a,openInNewTab:o,enableEncoding:l=!1,payload:u}=r.detail;if(!a){console.error(new Error("[Open Link] URL is empty"));return}function c(p){return x.cloneDeepWith(p,m=>{if(l&&typeof m=="string")return encodeURIComponent(m)})}const f=x.template(a||"")(c({...u,filters:t.payloadForSQL.filters,context:t.payloadForSQL.context}));window.open(f,o?"_blank":"_self","noopener")};return window.addEventListener("open-link",n),()=>{window.removeEventListener("open-link",n)}},[t])}const Ya=b.types.model("FilterConfigModel_Checkbox",{_name:b.types.literal("checkbox"),description:b.types.optional(b.types.string,""),default_value:b.types.boolean}).views(t=>({get json(){const{_name:e,description:n,default_value:r}=t;return{_name:e,description:n,default_value:r}},get isDescriptionEmpty(){const{description:e}=t;return e===""||e==="<p></p>"}})).actions(t=>({setDefaultValue(e){t.default_value=e},setDescription(e){t.description=e}})),fu=()=>Ya.create({_name:"checkbox",description:"",default_value:!1});var be=(t=>(t.Postgresql="postgresql",t.MySQL="mysql",t.HTTP="http",t))(be||{}),Ee=(t=>(t.Select="select",t.MultiSelect="multi-select",t.TreeSelect="tree-select",t.TextInput="text-input",t.Checkbox="checkbox",t.DateRange="date-range",t))(Ee||{});b.types.model({type:b.types.enumeration("DataSourceType",[be.Postgresql,be.MySQL,be.HTTP]),key:b.types.string,sql:b.types.string});function Qa(t,e){return t.map(n=>{try{return n?Y.tz(n,"UTC").format(e):null}catch{return console.log(`[date-range] failed parsing ${n}`),null}})}const gu=b.types.model("FilterConfigModel_DateRange",{_name:b.types.literal("date-range"),required:b.types.boolean,inputFormat:b.types.enumeration("DateRangeInputFormat",["YYYY","YYYYMM","YYYYMMDD","YYYY-MM","YYYY-MM-DD"]),default_value:b.types.optional(b.types.array(b.types.union(b.types.string,b.types.null)),[null,null]),clearable:b.types.boolean,max_days:b.types.optional(b.types.number,0),allowSingleDateInRange:b.types.optional(b.types.boolean,!1)}).views(t=>({get json(){const{_name:e,max_days:n,required:r,clearable:a,inputFormat:o,default_value:l,allowSingleDateInRange:u}=t;return{_name:e,max_days:n,required:r,clearable:a,inputFormat:o,default_value:Qa(l,o),allowSingleDateInRange:u}},truthy(e){return Array.isArray(e)&&e.length===2&&e.every(n=>!!n)}})).views(t=>({getMaxDate(e){const{max_days:n}=t;if(!(!n||!e))return Y(e).startOf("day").add(n,"days").toDate()},getMinDate(e){const{max_days:n}=t;if(!(!n||!e))return Y(e).startOf("day").subtract(n,"days").toDate()}})).actions(t=>({setFilterValue(e){try{const n=b.getParent(t);b.getRoot(t).filters.setValueByKey(n.key,e)}catch(n){console.error(n)}}})).actions(t=>({setRequired(e){t.required=e},setClearable(e){t.clearable=e},setInputFormat(e){t.inputFormat=e},setDefaultValue(e){t.default_value.length=0,t.default_value.push(...e),t.setFilterValue(e)},setMaxDays(e){t.max_days=e,e>0&&(t.clearable=!0)},setAllowSingleDateInRange(e){t.allowSingleDateInRange=e}})),Ka=b.types.snapshotProcessor(gu,{preProcessor({default_value:t,...e}){return{...e,default_value:t.map(n=>n===null?null:Y.tz(n,"UTC").toISOString())}},postProcessor(t){const{default_value:e,...n}=t;return{...n,default_value:Qa(e,n.inputFormat)}}}),mu=()=>Ka.create({_name:"date-range",required:!1,inputFormat:"YYYY-MM-DD",clearable:!1,default_value:[null,null]}),yu=b.types.model({label:b.types.string,value:b.types.string}).actions(t=>({setLabel(e){t.label=e},setValue(e){t.value=e}})),gr=b.types.model("FilterConfigModel_BaseSelect",{static_options:b.types.optional(b.types.array(yu),[]),options_query_id:b.types.optional(b.types.string,""),default_selection_count:b.types.optional(b.types.number,0)}).views(t=>({get usingQuery(){return!!t.options_query_id}})).views(t=>({get options(){if(!t.usingQuery)return t.static_options;const{data:e,state:n,error:r}=b.getRoot(t).content.getDataStuffByID(t.options_query_id);return n==="idle"?e:[]}})).actions(t=>({addStaticOption(e){t.static_options.push(e)},removeStaticOption(e){t.static_options.splice(e,1)},setDefaultSelectionCount(e){t.default_selection_count=e},setOptionsQueryID(e){t.options_query_id=e??""}})),yn=t=>x.cloneDeepWith(t,(e,n)=>{if(n!==void 0&&e)return ae.toJS(e)}),Ua=b.types.compose("FilterConfigModel_MultiSelect",b.types.model({_name:b.types.literal("multi-select"),min_width:b.types.optional(b.types.string,""),default_value:b.types.optional(b.types.array(b.types.string),[])}),gr).views(t=>({get json(){const{_name:e,default_value:n,min_width:r,static_options:a,options_query_id:o,default_selection_count:l}=t;return yn({_name:e,min_width:r,default_value:n,static_options:a,options_query_id:o,default_selection_count:l})},get default_selection(){return t.usingQuery?t.options.slice(0,t.default_selection_count).map(e=>e.value):t.default_value}})).actions(t=>({setDefaultValue(e){t.default_value=b.cast(e)},setMinWidth(e){t.min_width=e},setDefaultSelection(){const e=b.getRoot(t).content.filters,n=b.getParent(t).key;e.setValueByKey(n,t.default_selection)}})).actions(t=>({afterCreate(){b.addDisposer(t,ae.reaction(()=>ae.toJS(t.default_selection),t.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),bu=()=>Ua.create({_name:"multi-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0});function vu(t){return Ql.arrayToTree(t,{id:"value",parentId:"parent_value",childrenField:"children",dataField:null})}function xu(t){return t.map(e=>{const{label:n,description:r,...a}=e,o={...a,filterBasis:`${n}___${r??""}`,description:r,label:n};return r&&(o.label=y.createElement("div",{},[y.createElement(s.Text,{key:0,title:e.label},e.label),y.createElement(s.Text,{key:1,className:"rc-tree-select-tree-title-desc",color:"dimmed",title:e.description},e.description)])),o})}const Xa=b.types.compose("FilterConfigModel_TreeSelect",b.types.model({_name:b.types.literal("tree-select"),min_width:b.types.optional(b.types.string,""),default_value:b.types.optional(b.types.array(b.types.string),[])}),gr).views(t=>({get json(){const{_name:e,default_value:n,min_width:r,static_options:a,options_query_id:o,default_selection_count:l}=t;return{_name:e,min_width:r,default_value:n,static_options:a,options_query_id:o,default_selection_count:l}},get treeData(){const{data:e}=b.getRoot(t).content.getDataStuffByID(t.options_query_id),n=xu(e);return vu(n)},get errorMessage(){const{error:e}=b.getRoot(t).content.getDataStuffByID(t.options_query_id);return e},get treeDataLoading(){const{state:e}=b.getRoot(t).content.getDataStuffByID(t.options_query_id);return e==="loading"},get defaultSelection(){const{default_selection_count:e}=t;return e?this.treeData.slice(0,e).map(r=>r.value):[]}})).actions(t=>({setDefaultValue(e){t.default_value=b.cast(e)},setMinWidth(e){t.min_width=e},applyDefaultSelection(){const e=b.getParent(t,1).key;b.getRoot(t).content.filters.setValueByKey(e,t.defaultSelection)},afterCreate(){b.addDisposer(t,ae.reaction(()=>JSON.stringify(t.defaultSelection),this.applyDefaultSelection,{fireImmediately:!0,delay:0}))}})),wu=()=>Xa.create({_name:"tree-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),Ja=b.types.compose("FilterConfigModel_Select",b.types.model({_name:b.types.literal("select"),default_value:b.types.string,required:b.types.boolean,width:b.types.optional(b.types.string,"")}),gr).views(t=>({get json(){const{_name:e,default_value:n,required:r,width:a,static_options:o,options_query_id:l,default_selection_count:u}=t;return yn({_name:e,width:a,required:r,default_value:n,static_options:o,options_query_id:l,default_selection_count:u})},truthy(e){return!!e}})).actions(t=>({setRequired(e){t.required=e},setDefaultValue(e){t.default_value=e},setWidth(e){t.width=e}})),Cu=()=>Ja.create({_name:"select",required:!1,default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),Za=b.types.model("FilterConfigModel_TextInput",{_name:b.types.literal("text-input"),required:b.types.boolean,default_value:b.types.string}).views(t=>({get json(){const{_name:e,required:n,default_value:r}=t;return{_name:e,required:n,default_value:r}},truthy(e){return typeof e!="string"?!1:!!e.trim()}})).actions(t=>({setRequired(e){t.required=e},setDefaultValue(e){t.default_value=e}})),Ha=()=>Za.create({_name:"text-input",required:!1,default_value:""}),mr=b.types.model("FilterModel",{id:b.types.identifier,key:b.types.string,label:b.types.string,order:b.types.number,visibleInViewsIDs:b.types.array(b.types.string),auto_submit:b.types.optional(b.types.boolean,!1),type:b.types.enumeration("DashboardFilterType",[Ee.Select,Ee.MultiSelect,Ee.TreeSelect,Ee.TextInput,Ee.Checkbox,Ee.DateRange]),config:b.types.union(Ja,Ua,Xa,Za,Ya,Ka)}).views(t=>({get plainDefaultValue(){const e=t.config.default_value;return Array.isArray(e)?[...e]:e},get usingDefaultValue(){return t.type!==Ee.TreeSelect},get auto_submit_supported(){return[Ee.Select,Ee.Checkbox,Ee.DateRange].includes(t.type)}})).views(t=>({get json(){const{id:e,key:n,label:r,order:a,visibleInViewsIDs:o,auto_submit:l,type:u,config:c}=t;return{id:e,key:n,type:u,label:r,order:a,config:c.json,auto_submit:l,visibleInViewsIDs:ae.toJS(o)}},get should_auto_submit(){return t.auto_submit_supported&&t.auto_submit},requiredAndPass(e){return x.get(t.config,"required",!1)?x.get(t.config,"truthy",()=>!0)(e):!1}})).actions(t=>({setKey(e){t.key=e},setLabel(e){t.label=e},setOrder(e){t.order=e},setType(e){switch(e){case Ee.Select:t.config=Cu();break;case Ee.MultiSelect:t.config=bu();break;case Ee.TreeSelect:t.config=wu();break;case Ee.TextInput:t.config=Ha();break;case Ee.Checkbox:t.config=fu();break;case Ee.DateRange:t.config=mu();break}t.type=e},setVisibleInViewsIDs(e){t.visibleInViewsIDs.length=0,t.visibleInViewsIDs.push(...e)},setAutoSubmit(e){t.auto_submit=t.auto_submit_supported&&e}}));function es(t,e){if(t===void 0)return t;if(e._name==="date-range")try{const[...n]=t;return n.map(r=>r===null?r:Y.tz(r,"UTC").format(e.inputFormat)??r)}catch(n){return console.error(n),t}return t}function Su(t){return t.reduce((e,n)=>(e[n.key]=es(n.config.default_value,n.config),e),{})}function _u(t,e,n){b.addDisposer(t,b.addMiddleware(t,(r,a)=>{a(r,()=>{b.getType(r.context)===e&&r.type==="action"&&n(r.name,r.context)})}))}const ts=b.types.model("FiltersModel",{current:b.types.optional(b.types.array(mr),[]),values:b.types.optional(b.types.frozen(),{}),previewValues:b.types.optional(b.types.frozen(),{})}).views(t=>({get json(){return t.current.map(e=>e.json)},get firstID(){if(t.current.length!==0)return t.current[0].id},findByID(e){return t.current.find(n=>n.id===e)},get inOrder(){return x.sortBy(t.current,"order")},get options(){return t.current.map(e=>({label:e.label??e.id,value:e.id,_type:"filter"}))},get keyLabelOptions(){return t.current.map(e=>({label:e.label??e.key,value:e.key}))},get empty(){return t.current.length===0},visibleInView(e){return x.sortBy(t.current.filter(n=>n.visibleInViewsIDs.includes(e)),"order")},get firstFilterValueKey(){return Object.keys(t.values)[0]??""},get keyLabelMap(){return t.current.reduce((e,n)=>(e[n.key]=n.label,e),{})}})).actions(t=>({replace(e){t.current=b.cast(e)},append(e){t.current.push(e)},remove(e){t.current.splice(e,1)},removeByID(e){const n=t.current.findIndex(r=>r.id===e);n>=0&&t.current.splice(n,1)},setValues(e){t.values=e},setValueByKey(e,n){t.values={...t.values,[e]:n}},getValueByKey(e){return t.values[e]},updatePreviewValues(e){t.previewValues=e}})).actions(t=>{function e(){_u(t.current,mr,(n,r)=>{if(n==="setType"){const a=es(r.config.default_value,r.config);t.setValueByKey(r.key,a),t.updatePreviewValues({...t.previewValues,[r.key]:a})}})}return{afterCreate(){e()}}});function ns(t){return{current:t,values:Su(t)}}const rs="\uFEFF";function ku(t,e){const n=new Blob([rs+e],{type:"text/csv"});lr.saveAs(n,`${t}.csv`)}function Tu(t,e){const n=new Blob([e],{type:"application/json"});lr.saveAs(n,`${t}.json`)}function is(t){const e=new Kl;t.forEach(({id:n,data:r})=>{e.file(`${n}.csv`,ss(r))}),e.generateAsync({type:"blob"}).then(n=>{lr.saveAs(n,"dashboard_data.zip")})}function as(t){return typeof t=="string"&&t.includes(",")?`"${t}"`:t}function ss(t){if(!Array.isArray(t)||t.length===0)return"";const e=[],n=Object.keys(t[0]).map(as);return e.push(n.join(",")),t.forEach(r=>{const a=Object.values(r).map(as).join(",");e.push(a)}),rs+e.join(`
|
|
55
|
+
`)}const Du=b.types.model("QueryModel",{id:b.types.string,name:b.types.string,type:b.types.enumeration("DataSourceType",[be.Postgresql,be.MySQL,be.HTTP]),key:b.types.string,sql:b.types.string,pre_process:b.types.optional(b.types.string,""),post_process:b.types.optional(b.types.string,""),run_by:b.types.optional(b.types.array(b.types.string),[]),react_to:b.types.optional(b.types.array(b.types.string),[])}).views(t=>({get valid(){return t.id&&t.type&&t.key&&t.name?t.type===be.HTTP?!!t.pre_process:!!t.sql:!1},get json(){const{id:e,name:n,type:r,key:a,sql:o,run_by:l,react_to:u,pre_process:c,post_process:d}=t;return yn({id:e,key:a,sql:o,name:n,type:r,run_by:l,react_to:u,pre_process:c,post_process:d})},get conditionOptions(){if(!b.isAlive(t))return[];const{context:e,filters:n}=b.getRoot(t).content.payloadForSQL,r=Object.keys({...e}).map(l=>`context.${l}`),a=Object.keys(n).map(l=>`filters.${l}`);return[...r,...a].map(l=>({label:l.split(".")[1],value:l,group:x.capitalize(l.split(".")[0])}))},get unmetRunByConditions(){if(!b.isAlive(t))return[];const{run_by:e}=t;if(e.length===0)return[];const n=b.getRoot(t).content.payloadForSQL;return e.filter(r=>{const a=x.get(n,r);return Array.isArray(a)?a.length===0:typeof a=="number"?Number.isNaN(a):!a})}})).views(t=>({get reQueryKey(){const{react_to:e=[]}=t;if(e.length===0)return"";const n=b.getRoot(t).content.payloadForSQL,r=[...e].reduce((a,o)=>(a[o]=x.get(n,o),a),{});return JSON.stringify(r)},get runByConditionsMet(){return t.unmetRunByConditions.length===0},get conditionNames(){if(t.unmetRunByConditions.length===0)return{context:[],filters:[]};const{keyLabelMap:e}=b.getRoot(t).content.filters,n=t.unmetRunByConditions.filter(a=>a.startsWith("context.")).map(a=>a.split("context.")[0]),r=t.unmetRunByConditions.filter(a=>a.startsWith("filters.")).map(a=>x.get({filters:e},a)).filter(a=>!!a);return{context:n,filters:r}}})).actions(t=>({setName(e){t.name=e},setKey(e){t.key=e},setType(e){t.type=e},setSQL(e){t.sql=e},setRunBy(e){t.run_by.length=0,t.run_by.push(...e)},setReactTo(e){t.react_to.length=0,t.react_to.push(...e)},setPreProcess(e){t.pre_process=e},setPostProcess(e){t.post_process=e}}));function Iu(t,e){return new Function(`return ${t}`)()(e,zt)}function Mu(t,e,n){return Iu(t,{context:e,filters:n})}function Eu(t,e){try{return new Function(`return ${t.config.processing.pre}`)()(e,zt)}catch(n){return console.error(n),e}}function Au(t,e){return new Function(`return ${t.config.processing.post}`)()(e,zt)}function zu(t,e){return t?new Function(`return ${t}`)()(e,zt):e}const os=b.types.compose("QueryModel",Du,b.types.model({state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),data:b.types.optional(b.types.array(b.types.frozen()),[]),error:b.types.frozen()})).views(t=>({get formattedSQL(){const e=b.getRoot(t).content.payloadForSQL;return dr(t.sql,e)},get typedAsSQL(){return[be.Postgresql,be.MySQL].includes(t.type)},get typedAsHTTP(){return[be.HTTP].includes(t.type)},get datasource(){const{key:e,type:n}=t;return b.getRoot(t).datasources.find({type:n,key:e})},get httpConfigString(){const{context:e,filters:n}=b.getRoot(t).content.payloadForSQL,{name:r,pre_process:a}=t.json,o=Mu(a,e,n);return console.groupCollapsed(`Request config for: ${r}`),console.log(o),console.groupEnd(),JSON.stringify(o)}})).views(t=>({get stateMessage(){if(t.state!=="idle")return"";if(!t.runByConditionsMet){const{context:e,filters:n}=t.conditionNames;if(e.length===0&&n.length===0)return"Waiting";const r=[];return e.length>0&&r.push(`context: ${e.join(", ")}`),n.length>0&&r.push(`filter${n.length>1?"s":""}: ${n.join(", ")}`),r.length===2&&r.splice(1,0,"and"),r.unshift("Waiting for"),r.join(" ")}return t.data.length>0?"":"Empty Data"}})).volatile(()=>({controller:new AbortController})).actions(t=>({runSQL:b.flow(function*(){var e;if(t.valid&&((e=t.controller)==null||e.abort(),!!t.runByConditionsMet)){t.controller=new AbortController,t.state="loading";try{const n=b.getRoot(t).content.payloadForSQL;t.data=yield*b.toGenerator(du({payload:n,title:t.name,query:t.json},t.controller.signal)),t.state="idle",t.error=null}catch(n){if(!pt.isCancel(n)){t.data.length=0;const r=x.get(n,"message","unkown error");t.error=x.get(n,"response.data.detail.message",r),t.state="error"}}}}),runHTTP:b.flow(function*(){var e;if(!(!t.valid||!t.datasource)&&((e=t.controller)==null||e.abort(),!!t.runByConditionsMet)){t.controller=new AbortController,t.state="loading";try{const{type:n,key:r,post_process:a}=t.json;let o=JSON.parse(t.httpConfigString);o=Eu(t.datasource,o);const l=yield*b.toGenerator(pu({type:n,key:r,configString:JSON.stringify(o)},t.controller.signal));let u=Au(t.datasource,l);u=zu(a,u),t.data=u,t.state="idle",t.error=null}catch(n){if(console.error(n),!pt.isCancel(n)){t.data.length=0;const r=x.get(n,"message","unkown error");t.error=x.get(n,"response.data.detail.message",r),t.state="error"}}}})})).actions(t=>({fetchData:()=>t.typedAsHTTP?t.runHTTP():t.runSQL(),beforeDestroy(){var e;(e=t.controller)==null||e.abort()}})).actions(t=>({afterCreate(){b.addDisposer(t,ae.reaction(()=>{var e,n;return t.typedAsHTTP?`${t.id}--${t.key}--${t.reQueryKey}--${(e=t.datasource)==null?void 0:e.id}`:`${t.id}--${t.key}--${t.formattedSQL}--${t.pre_process}--${t.post_process}--${(n=t.datasource)==null?void 0:n.id}`},t.fetchData,{fireImmediately:!0,delay:0}))}})),ls=b.types.model("QueriesModel",{current:b.types.optional(b.types.array(os),[])}).views(t=>({get firstID(){if(t.current.length!==0)return t.current[0].id},findByID(e){return t.current.find(n=>n.id===e)},findByIDSet(e){return t.current.filter(n=>e.has(n.id))},get options(){const e=t.current.map(n=>({value:n.id,label:n.name,_type:"query"}));return x.sortBy(e,n=>n.label.toLowerCase())}})).views(t=>({get json(){return t.current.filter(e=>e.id).map(e=>e.json)}})).actions(t=>({replace(e){t.current=b.cast(e)},append(e){t.current.push(e)},remove(e){t.current.splice(e,1)},replaceByIndex(e,n){t.current.splice(e,1,n)},downloadAllData(){const e=t.current.map(({name:n,data:r})=>({id:n,data:r.toJSON()}));is(e)},downloadDataByQueryIDs(e){const n=new Set(e),r=t.current.filter(a=>n.has(a.id)).map(({name:a,data:o})=>({id:a,data:o.toJSON()}));is(r)},downloadDataByQueryID(e){const n=t.findByID(e);if(!n){console.log("[downloadDataByQueryID] query not found");return}const{name:r,data:a}=n,o=ss(a);ku(r,o)},refetchDataByQueryID(e){const n=t.findByID(e);if(!n){console.error(new Error(`[downloadDataByQueryID] query by ID[${e}] not found`));return}return n.fetchData()},removeQuery(e){const n=t.current.find(r=>r.id===e);n&&(b.detach(n),t.current.remove(n))}})),us=b.types.model("SQLSnippetModel",{key:b.types.string,value:b.types.string}).views(t=>({get json(){const{key:e,value:n}=t;return{key:e,value:n}},isADuplicatedKey(e){return!e||e===t.key?!1:!!b.getParent(t,2).findByKey(e)}})).actions(t=>({setKey(e){t.key=e},setValue(e){t.value=e}})),cs=b.types.model("SQLSnippetsModel",{current:b.types.optional(b.types.array(us),[])}).views(t=>({get json(){return t.current.map(e=>e.json)},get options(){const e=t.current.map(n=>({label:n.key,value:n.key,_type:"sql_snippet"}));return x.sortBy(e,n=>n.label.toLowerCase())},get record(){return t.current.reduce((e,n)=>(e[n.key]=n.value,e),{})},get firstKey(){if(t.current.length!==0)return t.current[0].key},findByKey(e){return t.current.find(n=>n.key===e)}})).actions(t=>({replace(e){t.current=b.cast(e)},append(e){t.current.push(e)},remove(e){t.current.splice(e,1)},removeByKey(e){const n=t.current.findIndex(r=>r.key===e);n>=0&&t.current.splice(n,1)},replaceByIndex(e,n){t.current.splice(e,1,n)}})),ds=b.types.model("ContextModel",{current:b.types.optional(b.types.frozen(),{})}).views(t=>({get keys(){return Object.keys(t.current)},get entries(){return Object.entries(t.current)}})).actions(t=>({replace(e){t.current=e},get(e){return t.current[e]},set(e,n){t.current[e]=n}})),$u=b.types.model({data:b.types.optional(b.types.frozen(),[]),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(t=>({get loading(){return t.state==="loading"},get empty(){return t.data.length===0},get sql(){const e=b.getParent(t,1),{type:n,table_name:r,table_schema:a}=e;if(n===be.MySQL)return`
|
|
56
56
|
SELECT ordinal_position, column_key, column_name, column_type, is_nullable, column_default, column_comment
|
|
57
57
|
FROM information_schema.columns
|
|
58
58
|
WHERE table_name = '${r}' AND table_schema = '${a}'
|
|
@@ -73,7 +73,7 @@ Check the top-level render call using <`+P+">.")}return A}}function ql(S,A){{if(
|
|
|
73
73
|
LEFT JOIN pg_constraint pc ON pc.conrelid = ${o} AND ordinal_position = any(pc.conkey)
|
|
74
74
|
WHERE
|
|
75
75
|
table_name = '${r}' AND table_schema = '${a}';
|
|
76
|
-
`}return""}}))
|
|
76
|
+
`}return""}})),Lu=b.types.model({data:b.types.optional(b.types.frozen(),[]),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(t=>({get loading(){return t.state==="loading"},get empty(){return t.data.length===0},get sql(){const e=b.getParent(t,1),{type:n,table_name:r,table_schema:a}=e;return n===be.MySQL?`
|
|
77
77
|
SELECT
|
|
78
78
|
sub_part AS index_length,
|
|
79
79
|
index_name AS index_name,
|
|
@@ -108,35 +108,35 @@ Check the top-level render call using <`+P+">.")}return A}}function ql(S,A){{if(
|
|
|
108
108
|
JOIN pg_am AS am ON ix.relam = am.oid
|
|
109
109
|
WHERE
|
|
110
110
|
t.relname = '${r}' AND n.nspname = '${a}';
|
|
111
|
-
`:""}})),
|
|
111
|
+
`:""}})),Ou=b.types.model({data:b.types.optional(b.types.frozen(),{}),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(t=>({get loading(){return t.state==="loading"},get empty(){return Object.keys(t.data).length===0},get sql(){const e=b.getParent(t,1).type;return e===be.MySQL||e===be.Postgresql?"SELECT table_schema, table_name, table_type FROM information_schema.tables ORDER BY table_schema, table_name":""}})),Pu=b.types.model({page:b.types.optional(b.types.number,1),limit:b.types.optional(b.types.number,20),data:b.types.optional(b.types.frozen(),[]),total:b.types.optional(b.types.number,0),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(t=>({get keywords(){return b.getParent(t,1)},get keywordString(){const{table_name:e,table_schema:n}=b.getParent(t,1);return`${n}||${e}`}})).views(t=>({get loading(){return t.state==="loading"},get empty(){return t.data.length===0},get maxPage(){return Math.ceil(t.total/t.limit)},get sql(){const e=b.getParent(t,1),{table_name:n,table_schema:r}=e;return`
|
|
112
112
|
SELECT *
|
|
113
113
|
FROM ${r}.${n}
|
|
114
114
|
LIMIT ${t.limit} OFFSET ${(t.page-1)*t.limit}
|
|
115
115
|
`},get countSql(){const{table_name:e,table_schema:n}=t.keywords;return`
|
|
116
116
|
SELECT count(*) AS total
|
|
117
117
|
FROM ${n}.${e}
|
|
118
|
-
`}})).actions(t=>({setPage(e){t.page=e},resetPage(){t.page=1},setLimit(e){t.limit=e}})).actions(t=>({afterCreate(){b.addDisposer(t,ae.reaction(()=>t.keywordString,t.resetPage,{fireImmediately:!1,delay:0})),b.addDisposer(t,ae.reaction(()=>t.limit,t.resetPage,{fireImmediately:!1,delay:0}))}})),
|
|
119
|
-
`),yr={columns:[],fontSize:"14px",highlightOnHover:!0,horizontalSpacing:"14px",id_field:"",striped:!0,use_raw_columns:!0,verticalSpacing:"14px"};class $t{constructor(e,n){this.root=e,this.path=n}async deleteItem(e){e===null&&await this.root.deleteItem(this.path);const n=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,x.omit(n,e))}async getItem(e){const n=await this.root.getItem(this.path);return e===null?n:x.get(n,e)}async setItem(e,n){if(e===null)await this.root.setItem(this.path,n);else{const r=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,{...r,[e]:n})}return await this.getItem(e)}watchItem(e,n,r){return e===null?this.root.watchItem(this.path,(a,o)=>{n(a,o)},r):this.root.watchItem(this.path,(a,o)=>{const l=x.get(a,e),c=x.get(o,e);l!==c&&n(l,c)},r)}}class br{constructor(e,n,r){V(this,"attachmentStorage");this.instance=e,this.attachmentKey=n,this.constructInstance=r,this.attachmentStorage=new $t(e.instanceData,n)}async getInstance(e){if(await this.attachmentStorage.getItem(e))return this.constructInstance(new $t(this.attachmentStorage,e))}async create(e,n){return await this.attachmentStorage.setItem(e,n),this.constructInstance(new $t(this.attachmentStorage,e))}async remove(e){await this.attachmentStorage.deleteItem(e)}async list(){const e=await this.attachmentStorage.getItem(null);return Promise.all(x.values(e).map(n=>this.constructInstance(new $t(this.attachmentStorage,n.id))))}}class hs{constructor(e){V(this,"rootRef");this.rootRef=ae.observable({current:e})}async deleteItem(e){ae.runInAction(()=>{x.unset(this.rootRef.current,[e])})}getItem(e){const n=this.getValueFromRoot(e);return Promise.resolve(n)}getValueFromRoot(e){return e===null?ae.toJS(this.rootRef.current):x.get(this.rootRef.current,[e])}setItem(e,n){if(e===null)if(x.isObject(n))ae.runInAction(()=>{this.rootRef.current=n});else throw new Error("Cannot set root value to non-object");else ae.runInAction(()=>{x.set(this.rootRef.current,[e],n)});return Promise.resolve(this.getItem(e))}watchItem(e,n,r){return ae.reaction(()=>this.getValueFromRoot(e),(a,o)=>{n(a,o)},{requiresObservable:!0,fireImmediately:x.get(r,"fireImmediately",!1)})}}class jc{constructor(){V(this,"channels",new Map);V(this,"globalChannel",new Ca)}getChannel(e){const n=this.channels.get(e);if(n)return n;const r=new Ca;return this.channels.set(e,r),r}}class Yc{constructor(e){V(this,"instances",new Map);this.pluginManager=e}get availableVizList(){return this.pluginManager.installedPlugins.flatMap(e=>e.manifest.viz)}resolveComponent(e){return this.pluginManager.factory.viz(e)}getOrCreateInstance(e){const n=this.instances.get(e.id);if(n)return n;const r={id:e.id,name:e.viz.type,type:e.viz.type,messageChannels:new jc,instanceData:new hs(e.viz.conf)};return this.instances.set(e.id,r),r}}function fs(t,e,n,r){return{vizManager:n,locale:"zh",msgChannels:t.messageChannels,instanceData:t.instanceData,pluginData:new hs({}),colorPalette:{getColor(){return()=>""}},data:e,variables:r}}const Qc=t=>{const{panel:e,vizManager:n,data:r,variables:a}=t,o=n.resolveComponent(e.viz.type),l=n.getOrCreateInstance(e),c={...fs(l,r,n,a),viewport:{width:e.layout.w,height:e.layout.h}},u=o.viewRender;return i(u,{context:c,instance:l,...x.omit(t,["panel","vizManager","data"])})},Kc=t=>{const{vizManager:e,panel:n,panelInfoEditor:r,data:a,variables:o}=t,l=e.resolveComponent(n.viz.type),c=e.getOrCreateInstance(n),u={...fs(c,a,e,o),panelInfoEditor:r},d=l.configRender;return i(d,{context:u,instance:c,...x.omit(t,["panel","vizManager","data","panelInfoEditor"])})},gs=(t,e)=>{const n=at.bezier(t),r=at.bezier(e);return function(a){return a<50?n(a*2/100).hex():r((a-50)*2/100).hex()}},vn=t=>{const e=at.bezier(t);return function(n){return e(n/100).hex()}},Uc={type:"interpolation",displayName:"Red / Green",getColor:gs(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},Xc={type:"interpolation",displayName:"Yellow / Blue",getColor:gs(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},Jc={type:"interpolation",displayName:"Red",getColor:vn(["#fff7f1","darkred"]),name:"red",category:"sequential"},Zc={type:"interpolation",displayName:"Green",getColor:vn(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},Hc={type:"interpolation",displayName:"Blue",getColor:vn(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},eu={type:"interpolation",displayName:"Orange",getColor:vn(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class tu{constructor(e){V(this,"symbol");this.symbol=Symbol(e)}}function st(t){return new tu(t)}class vr{constructor(){V(this,"parent");V(this,"factoryRegistry",new Map);V(this,"instanceRegistry",new Map)}createScoped(){const e=new vr;return e.parent=this,e}getRequired(e){return this.get(e)}get(e){if(this.instanceRegistry.has(e.symbol))return this.instanceRegistry.get(e.symbol);const n=this.factoryRegistry.get(e.symbol);if(n){const r=n(this);return this.instanceRegistry.set(e.symbol,r),r}if(this.parent)return this.parent.get(e)}provideFactory(e,n){return this.factoryRegistry.has(e.symbol)?console.warn(`Token ${e.symbol.toString()} is already registered`):this.factoryRegistry.set(e.symbol,n),this}provideValue(e,n){return this.factoryRegistry.has(e.symbol)?console.warn(`Token ${e.symbol.toString()} is already registered`):this.factoryRegistry.set(e.symbol,()=>n),this}dispose(){this.instanceRegistry.forEach(e=>{const n=x.get(e,"dispose");x.isFunction(n)&&n.bind(e)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}const ms="10.4.1",nu=Object.freeze(Object.defineProperty({__proto__:null,version:ms},Symbol.toStringTag,{value:"Module"}));class ru{constructor(e){V(this,"staticColors",new Map);V(this,"interpolations",new Map);e.installedPlugins.forEach(n=>{n.manifest.color.forEach(r=>{this.register(r)})})}getStaticColors(){return Array.from(this.staticColors.values())}register(e){const n=this.encodeColor(e);e.type==="single"?(this.staticColors.has(n)&&console.warn(`the color '${e.name}' has been registered under '${e.category}', previous registered value will be overridden`),this.staticColors.set(n,e)):e.type==="interpolation"&&(this.interpolations.has(n)&&console.warn(`the interpolation '${e.name}' has been registered under '${e.category}', previous registered value will be overridden`,`the interpolation '${e.name}' has been registered under '${e.category}', previous registered value will be overridden`),this.interpolations.set(n,e))}decodeStaticColor(e){return this.staticColors.get(e)}encodeColor(e){return`\${${e.category}}.{${e.name}}`}decodeInterpolation(e){return this.interpolations.get(e)}getColorInterpolations(){return Array.from(this.interpolations.values())}}class iu{constructor(){V(this,"plugins",new Map);V(this,"vizComponents",new Map);V(this,"factory",{viz:e=>{const n=this.vizComponents.get(e);if(n)return n;throw new Error(`Viz Component (${e}) not found`)}})}install(e){if(this.plugins.has(e.id))throw new Error(`Plugin (${e.id}) has been installed before`);this.plugins.set(e.id,e);for(const n of e.manifest.viz){if(this.vizComponents.has(n.name))throw new Error(`Viz Component (${n.name}) has been installed before`);this.vizComponents.set(n.name,n)}}get installedPlugins(){return Array.from(this.plugins.values())}}const R=(t,e)=>{const[n,{setFalse:r}]=J.useBoolean(!0),[a,o]=y.useState();y.useEffect(()=>(t.getItem(e).then(c=>{o(c),r()}),t.watchItem(e,c=>{o(c)})));const l=y.useCallback(async c=>{await t.setItem(e,c),o(c)},[t,e]);return{loading:n,value:a,set:l}},xr={x_axis_data_key:"",y_axis_data_key:"",z_axis_data_key:"",xAxis3D:{type:"value",name:"X Axis Name"},yAxis3D:{type:"value",name:"Y Axis Name"},zAxis3D:{type:"value",name:"Z Axis Name"}};function q(t){const[e,n]=t.split(".");return{queryID:e,columnKey:n}}function ot(t,e){var a;const{queryID:n,columnKey:r}=q(e);return n?r?((a=t[n])==null?void 0:a.map(o=>o[r]))??[]:t[n]:[]}function xn(t,e){const{queryID:n}=q(e);return n?t[n]:[]}function au(t){return Object.values(t)[0]}function wn(t,e){const{queryID:n,columnKey:r}=q(e);return t[r]}ce.use([G.GridComponent,G.VisualMapComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer]);function su({context:t}){const{value:e}=R(t.instanceData,"config"),n=t.data,{width:r,height:a}=t.viewport,{x_axis_data_key:o,y_axis_data_key:l,z_axis_data_key:c,xAxis3D:u,yAxis3D:d,zAxis3D:f}=x.defaults({},e,xr),h=y.useMemo(()=>xn(n,o),[n,o]),{x:g,y:m,z:C}=y.useMemo(()=>({x:q(o),y:q(l),z:q(c)}),[o,l,c]),{min:w,max:_}=y.useMemo(()=>{const M=x.minBy(h,B=>B[C.columnKey]),O=x.maxBy(h,B=>B[C.columnKey]);return{min:x.get(M,C.columnKey),max:x.get(O,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:u,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 e?i(Ne,{echarts:ce,option:T,style:{width:r,height:a},notMerge:!0,theme:"merico-light"}):null}const ys=y.createContext({panel:null,data:{},loading:!1,errors:[]}),wr=ys.Provider;function Ae(){const t=y.useContext(ys);if(!t.panel)throw new Error("Please use PanelContextProvider");return t}const ou={fullScreenPanelID:"",setFullScreenPanelID:x.noop},Cr=y.createContext(ou);function bs(){const t=y.useContext(Cr);if(!t)throw new Error("Please use FullScreenPanelContext.Provider");return t}const j=k.observer(y.forwardRef(({label:t,required:e,value:n,onChange:r,clearable:a=!1,sx:o,...l},c)=>{const{panel:u}=Ae(),d=y.useMemo(()=>{const f=[...u.dataFieldOptions];return a&&f.unshift({label:"unset",value:"",group:""}),f},[u.dataFieldOptions]);return i(s.Select,{ref:c,label:t,data:d,value:n,onChange:r,required:e,sx:o,...l})}));function lu({context:t}){const{value:e,set:n}=R(t.instanceData,"config"),r=x.defaults({},e,xr),{control:a,handleSubmit:o,reset:l}=v.useForm({defaultValues:r});return y.useEffect(()=>{l(r)},[e]),e?i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[i(s.Text,{children:"X Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"x_axis_data_key",control:a,render:({field:c})=>i(j,{label:"Data Field",required:!0,...c})}),i(v.Controller,{name:"xAxis3D.name",control:a,render:({field:c})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...c})})]}),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:c})=>i(j,{label:"Data Field",required:!0,...c})}),i(v.Controller,{name:"yAxis3D.name",control:a,render:({field:c})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...c})})]}),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:c})=>i(j,{label:"Data Field",required:!0,...c})}),i(v.Controller,{name:"zAxis3D.name",control:a,render:({field:c})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...c})})]}),i(s.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:p(s.Button,{color:"blue",type:"submit",children:[i(I.DeviceFloppy,{size:20}),i(s.Text,{ml:"md",children:"Save"})]})})]})}):null}function cu(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis_data_key:a,y_axis_data_key:o,z_axis_data_key:l,...c}=t;return{...c,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 uu extends ve{constructor(){super(...arguments);V(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:cu(a,r)}})}}const du={displayName:"Bar Chart (3D)",displayGroup:"ECharts-based charts",migrator:new uu,name:"bar-3d",viewRender:su,configRender:lu,createConfig(){return{version:2,config:x.cloneDeep(xr)}}};class Fe extends y.Component{constructor(e){super(e),this.state={error:null}}componentDidCatch(e){this.setState({error:e})}render(){var e;if(this.state.error){const n=()=>{this.setState({error:null})};return p(s.Box,{children:[i(s.Text,{size:"xs",children:(e=this.state.error)==null?void 0:e.message}),i(s.Button,{variant:"subtle",size:"xs",mx:"auto",compact:!0,sx:{display:"block"},onClick:n,children:"Retry"})]})}return this.props.children}}const $e={mantissa:0,output:"number",trimMantissa:!1,average:!1};function pu({value:t,onChange:e},n){const r=c=>{e({...t,output:c})},a=c=>{const u=c===0?!1:t.trimMantissa;e({...t,mantissa:c,trimMantissa:u})},o=c=>{e({...t,trimMantissa:c.currentTarget.checked})},l=c=>{e({...t,average:c.currentTarget.checked})};return p(s.Stack,{ref:n,children:[p(s.Group,{grow:!0,children:[i(s.Select,{label:"Format",data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:t.output,onChange:r,sx:{flexGrow:1}}),i(s.Switch,{label:p(s.Stack,{spacing:0,children:[i(s.Text,{children:"Average"}),i(s.Text,{size:12,color:"gray",children:"like 1.234k, 1.234m"})]}),checked:t.average,onChange:l,disabled:t.output!=="number",sx:{flexGrow:1},styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}}})]}),p(s.Group,{grow:!0,children:[i(s.NumberInput,{label:"Mantissa",defaultValue:0,min:0,step:1,max:4,value:t.mantissa,onChange:a}),i(s.Switch,{label:"Trim mantissa",checked:t.trimMantissa,onChange:o,disabled:t.mantissa===0,styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"}}})]}),p(s.Stack,{spacing:0,children:[i(s.Text,{weight:"bold",children:"Preview"}),i(Fe,{children:p(s.Group,{position:"apart",children:[p(s.Text,{size:12,color:"gray",children:["123456789 ",i(I.ArrowRight,{size:9})," ",te(123456789).format(t)]}),p(s.Text,{size:12,color:"gray",children:["1234 ",i(I.ArrowRight,{size:9})," ",te(1234).format(t)]}),p(s.Text,{size:12,color:"gray",children:["0.1234 ",i(I.ArrowRight,{size:9})," ",te(.1234).format(t)]})]})})]})]})}const Je=y.forwardRef(pu),tt={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
120
|
-
`)},vs={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:
|
|
118
|
+
`}})).actions(t=>({setPage(e){t.page=e},resetPage(){t.page=1},setLimit(e){t.limit=e}})).actions(t=>({afterCreate(){b.addDisposer(t,ae.reaction(()=>t.keywordString,t.resetPage,{fireImmediately:!1,delay:0})),b.addDisposer(t,ae.reaction(()=>t.limit,t.resetPage,{fireImmediately:!1,delay:0}))}})),Bu=b.types.model("DataSourceModel",{id:b.types.string,type:b.types.enumeration("DataSourceType",[be.HTTP,be.MySQL,be.Postgresql]),key:b.types.string,config:b.types.frozen(),tables:b.types.optional(Ou,{}),columns:b.types.optional($u,{}),tableData:b.types.optional(Pu,{}),indexes:b.types.optional(Lu,{}),table_schema:b.types.optional(b.types.string,""),table_name:b.types.optional(b.types.string,"")}).volatile(()=>({controllers:{tables:new AbortController,columns:new AbortController,indexes:new AbortController,tableData:new AbortController}})).actions(t=>({setKeywords(e,n){t.table_schema=e,t.table_name=n}})).actions(t=>({initKeywords(){if(t.tables.empty)return;const e=Object.keys(t.tables.data)[0],n=t.tables.data[e][0].table_name;t.setKeywords(e,n)}})).actions(t=>{const e=b.flow(function*(){var n;(n=t.controllers.tables)==null||n.abort(),t.controllers.tables=new AbortController,t.tables.state="loading";try{const r=yield*b.toGenerator(qe.query(t.controllers.tables.signal)({type:t.type,key:t.key,query:t.tables.sql},{}));t.tables.data=x.groupBy(r,"table_schema"),t.tables.state="idle",t.tables.error=null,t.initKeywords()}catch(r){if(!pt.isCancel(r)){t.tables.data={};const a=x.get(r,"message","unkown error");t.tables.error=x.get(r,"response.data.detail.message",a),t.tables.state="error"}}});return{loadTables:e,loadTablesIfEmpty(){t.tables.empty&&e()},loadColumns:b.flow(function*(){var n;(n=t.controllers.columns)==null||n.abort(),t.controllers.columns=new AbortController,t.columns.state="loading";try{t.columns.data=yield*b.toGenerator(qe.query(t.controllers.columns.signal)({type:t.type,key:t.key,query:t.columns.sql},{})),t.columns.state="idle",t.columns.error=null}catch(r){if(pt.isCancel(r))t.columns.state="idle",t.columns.error=null;else{t.columns.data=[];const a=x.get(r,"message","unkown error");t.columns.error=x.get(r,"response.data.detail.message",a),t.columns.state="error"}}}),loadIndexes:b.flow(function*(){var n;(n=t.controllers.indexes)==null||n.abort(),t.controllers.indexes=new AbortController,t.indexes.state="loading";try{t.indexes.data=yield*b.toGenerator(qe.query(t.controllers.indexes.signal)({type:t.type,key:t.key,query:t.indexes.sql},{})),t.indexes.state="idle",t.indexes.error=null}catch(r){if(pt.isCancel(r))t.indexes.state="idle",t.indexes.error=null;else{t.indexes.data=[];const a=x.get(r,"message","unkown error");t.indexes.error=x.get(r,"response.data.detail.message",a),t.indexes.state="error"}}}),loadTableData:b.flow(function*(){var r;(r=t.controllers.tableData)==null||r.abort(),t.controllers.tableData=new AbortController;const n=t.tableData;n.state="loading";try{n.data=yield*b.toGenerator(qe.query(t.controllers.tableData.signal)({type:t.type,key:t.key,query:n.sql},{}));const[{total:a}]=yield*b.toGenerator(qe.query(t.controllers.tableData.signal)({type:t.type,key:t.key,query:n.countSql},{}));n.total=Number(a),n.state="idle",n.error=null}catch(a){if(pt.isCancel(a))n.state="idle",n.error=null;else{n.data=[];const o=x.get(a,"message","unkown error");n.error=x.get(a,"response.data.detail.message",o),n.state="error"}}})}}).actions(t=>({afterCreate(){b.addDisposer(t,ae.reaction(()=>t.columns.sql,t.loadColumns,{fireImmediately:!1,delay:500}))}})).actions(t=>({afterCreate(){b.addDisposer(t,ae.reaction(()=>t.indexes.sql,t.loadIndexes,{fireImmediately:!1,delay:500})),b.addDisposer(t,ae.reaction(()=>t.tableData.sql,t.loadTableData,{fireImmediately:!1,delay:0}))}})),Vu=b.types.model("DataSourcesModel",{list:b.types.optional(b.types.array(Bu),[])}).views(t=>({find({type:e,key:n}){return t.list.find(r=>r.key===n&&r.type===e)},get options(){return t.list.map(e=>({value:e.key,label:e.key}))}})).actions(t=>({replace(e){t.list.length=0,t.list.push(...e)}}));function bn(t){return{label:t,value:t,_type:"ACTION",_action_type:t,Icon:null,children:null}}function Nu(t){switch(t._type){case"GROUP":case"ACTION":return null;case"query_variables":return["_QUERY_VARS_"];case"mock_context":return["_MOCK_CONTEXT_"];case"filter":return["_FILTERS_",t.value];case"sql_snippet":return["_SQL_SNIPPETS_",t.value];case"query":return["_QUERIES_",t.value];case"view":return["_VIEWS_",t.value];case"panel":return t.parentID?["_VIEWS_",t.parentID,"_PANELS_",t.value]:(console.error("[getPathFromOption] parentID is required"),null)}}const qu=b.types.model("EditorModel",{path:b.types.optional(b.types.frozen(),[]),settings_open:b.types.optional(b.types.boolean,!1)}).views(t=>({get navOptions(){const{content:e}=b.getRoot(t),{filters:n,views:r,sqlSnippets:a,queries:o}=e;return[{label:"Query Variables",value:"_QUERY_VARS_",_type:"query_variables",Icon:L.IconVariable},{label:"Mock Context",value:"_MOCK_CONTEXT_",Icon:L.IconCodeDots,_type:"mock_context"},{label:"Filters",value:"_FILTERS_",Icon:L.IconFilter,children:[...n.options,bn("_Add_A_Filter_")],_type:"GROUP"},{label:"SQL Snippets",value:"_SQL_SNIPPETS_",Icon:L.IconCopy,children:[...a.options,bn("_Add_A_SQL_SNIPPET_")],_type:"GROUP"},{label:"Queries",value:"_QUERIES_",Icon:L.IconDatabase,children:[...o.options,bn("_Add_A_QUERY_")],_type:"GROUP"},{label:"Views",value:"_VIEWS_",Icon:L.IconBoxMultiple,children:[...r.editorOptions,bn("_Add_A_VIEW_")],_type:"GROUP"}]},isOptionActive(e,n){return e.length===0?!1:e[e.length-1]===n.value},isOptionOpened(e){const{path:n}=t;return n.length===0||!e.children||e.children.length===0?!1:n.includes(e.value)}})).actions(t=>({setPath(e){t.path=e},setSettingsOpen(e){t.settings_open=e}})).actions(t=>({open(e){t.setPath(e),t.setSettingsOpen(!0)},close(){t.setSettingsOpen(!1)},navigate(e){const n=Nu(e);n&&t.setPath(n)}})),Fu=b.types.model("MockContextModel",{current:b.types.optional(b.types.frozen(),{})}).views(t=>({get keys(){return Object.keys(t.current)},get entries(){return Object.entries(t.current)}})).actions(t=>({replace(e){t.current=e},get(e){return t.current[e]},set(e,n){t.current[e]=n}})),Gu=b.types.model("VariableModel",{name:b.types.string,size:b.types.string,weight:b.types.string,color:b.types.union(b.types.model({type:b.types.literal("static"),staticColor:b.types.string}),b.types.model({type:b.types.literal("continuous"),valueRange:b.types.array(b.types.number),colorRange:b.types.array(b.types.string)}),b.types.model({type:b.types.literal("piecewise")})),formatter:b.types.model({output:b.types.enumeration("Output",["number","percent"]),average:b.types.optional(b.types.boolean,!1),mantissa:b.types.number,trimMantissa:b.types.optional(b.types.boolean,!1)}),data_field:b.types.string,aggregation:b.types.union(b.types.model({type:b.types.enumeration(["none","sum","mean","median","min","max","CV","std"]),config:b.types.frozen()}),b.types.model({type:b.types.literal("quantile"),config:b.types.model({p:b.types.number})}))}).views(t=>({get json(){const{name:e,size:n,weight:r,color:a,formatter:o,data_field:l,aggregation:u}=t;return x.cloneDeep({name:e,size:n,color:a,weight:r,formatter:o,data_field:l,aggregation:u})}}));class Wu{constructor(e){V(this,"origin");V(this,"copy");this.origin=e,this.copy=b.clone(e),ae.makeAutoObservable(this,{},{autoBind:!0,deep:!1})}get changed(){return!x.isEqual(b.getSnapshot(this.origin),b.getSnapshot(this.copy))}commit(){b.applySnapshot(this.origin,b.getSnapshot(this.copy))}update(e){b.applySnapshot(this.copy,e)}}const Ru=t=>new Wu(t);class ju{constructor(){V(this,"migrations",[])}version(e,n){return this.migrations.push({version:e,handler:n}),this}run(e,n,r){var l;if(e.from===e.to)return n;if(e.from>e.to)throw new Error(`Can not downgrade from version '${e.from}' to (${e.to})`);const a=this.migrations.filter(u=>u.version>e.from&&u.version<=e.to),o=x.orderBy(a,"version","asc");if(((l=x.last(o))==null?void 0:l.version)!==e.to)throw new Error(`Migration to version ${e.to} not found`);return o.reduce((u,c)=>c.handler(u,r),n)}}class ve extends ju{constructor(){super(),this.configVersions()}version(e,n){return super.version(e,(r,a)=>({version:e,...n(r,a)}))}async migrate({configData:e,panelModel:n}){const r=await e.getItem(null),a=x.get(r,"version",0),o=this.run({from:a,to:this.VERSION},r,{panelModel:n});await e.setItem(null,o)}async needMigration({configData:e}){const n=await e.getItem(null);return x.get(n,"version",0)<this.VERSION}}var Xe=(t=>(t.string="string",t.number="number",t.eloc="eloc",t.percentage="percentage",t.custom="custom",t))(Xe||{});const ps=["function text({ value }) {"," // your code goes here"," return value","}"].join(`
|
|
119
|
+
`),yr={columns:[],fontSize:"14px",highlightOnHover:!0,horizontalSpacing:"14px",id_field:"",striped:!0,use_raw_columns:!0,verticalSpacing:"14px"};class $t{constructor(e,n){this.root=e,this.path=n}async deleteItem(e){e===null&&await this.root.deleteItem(this.path);const n=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,x.omit(n,e))}async getItem(e){const n=await this.root.getItem(this.path);return e===null?n:x.get(n,e)}async setItem(e,n){if(e===null)await this.root.setItem(this.path,n);else{const r=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,{...r,[e]:n})}return await this.getItem(e)}watchItem(e,n,r){return e===null?this.root.watchItem(this.path,(a,o)=>{n(a,o)},r):this.root.watchItem(this.path,(a,o)=>{const l=x.get(a,e),u=x.get(o,e);l!==u&&n(l,u)},r)}}class br{constructor(e,n,r){V(this,"attachmentStorage");this.instance=e,this.attachmentKey=n,this.constructInstance=r,this.attachmentStorage=new $t(e.instanceData,n)}async getInstance(e){if(await this.attachmentStorage.getItem(e))return this.constructInstance(new $t(this.attachmentStorage,e))}async create(e,n){return await this.attachmentStorage.setItem(e,n),this.constructInstance(new $t(this.attachmentStorage,e))}async remove(e){await this.attachmentStorage.deleteItem(e)}async list(){const e=await this.attachmentStorage.getItem(null);return Promise.all(x.values(e).map(n=>this.constructInstance(new $t(this.attachmentStorage,n.id))))}}class hs{constructor(e){V(this,"rootRef");this.rootRef=ae.observable({current:e})}async deleteItem(e){ae.runInAction(()=>{x.unset(this.rootRef.current,[e])})}getItem(e){const n=this.getValueFromRoot(e);return Promise.resolve(n)}getValueFromRoot(e){return e===null?ae.toJS(this.rootRef.current):x.get(this.rootRef.current,[e])}setItem(e,n){if(e===null)if(x.isObject(n))ae.runInAction(()=>{this.rootRef.current=n});else throw new Error("Cannot set root value to non-object");else ae.runInAction(()=>{x.set(this.rootRef.current,[e],n)});return Promise.resolve(this.getItem(e))}watchItem(e,n,r){return ae.reaction(()=>this.getValueFromRoot(e),(a,o)=>{n(a,o)},{requiresObservable:!0,fireImmediately:x.get(r,"fireImmediately",!1)})}}class Yu{constructor(){V(this,"channels",new Map);V(this,"globalChannel",new Ca)}getChannel(e){const n=this.channels.get(e);if(n)return n;const r=new Ca;return this.channels.set(e,r),r}}class Qu{constructor(e){V(this,"instances",new Map);this.pluginManager=e}get availableVizList(){return this.pluginManager.installedPlugins.flatMap(e=>e.manifest.viz)}resolveComponent(e){return this.pluginManager.factory.viz(e)}getOrCreateInstance(e){const n=this.instances.get(e.id);if(n)return n;const r={id:e.id,name:e.viz.type,type:e.viz.type,messageChannels:new Yu,instanceData:new hs(e.viz.conf)};return this.instances.set(e.id,r),r}}function fs(t,e,n,r){return{vizManager:n,locale:"zh",msgChannels:t.messageChannels,instanceData:t.instanceData,pluginData:new hs({}),colorPalette:{getColor(){return()=>""}},data:e,variables:r}}const Ku=t=>{const{panel:e,vizManager:n,data:r,variables:a}=t,o=n.resolveComponent(e.viz.type),l=n.getOrCreateInstance(e),u={...fs(l,r,n,a),viewport:{width:e.layout.w,height:e.layout.h}},c=o.viewRender;return i(c,{context:u,instance:l,...x.omit(t,["panel","vizManager","data"])})},Uu=t=>{const{vizManager:e,panel:n,panelInfoEditor:r,data:a,variables:o}=t,l=e.resolveComponent(n.viz.type),u=e.getOrCreateInstance(n),c={...fs(u,a,e,o),panelInfoEditor:r},d=l.configRender;return i(d,{context:c,instance:u,...x.omit(t,["panel","vizManager","data","panelInfoEditor"])})},gs=(t,e)=>{const n=at.bezier(t),r=at.bezier(e);return function(a){return a<50?n(a*2/100).hex():r((a-50)*2/100).hex()}},vn=t=>{const e=at.bezier(t);return function(n){return e(n/100).hex()}},Xu={type:"interpolation",displayName:"Red / Green",getColor:gs(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},Ju={type:"interpolation",displayName:"Yellow / Blue",getColor:gs(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},Zu={type:"interpolation",displayName:"Red",getColor:vn(["#fff7f1","darkred"]),name:"red",category:"sequential"},Hu={type:"interpolation",displayName:"Green",getColor:vn(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},ec={type:"interpolation",displayName:"Blue",getColor:vn(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},tc={type:"interpolation",displayName:"Orange",getColor:vn(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class nc{constructor(e){V(this,"symbol");this.symbol=Symbol(e)}}function st(t){return new nc(t)}class vr{constructor(){V(this,"parent");V(this,"factoryRegistry",new Map);V(this,"instanceRegistry",new Map)}createScoped(){const e=new vr;return e.parent=this,e}getRequired(e){return this.get(e)}get(e){if(this.instanceRegistry.has(e.symbol))return this.instanceRegistry.get(e.symbol);const n=this.factoryRegistry.get(e.symbol);if(n){const r=n(this);return this.instanceRegistry.set(e.symbol,r),r}if(this.parent)return this.parent.get(e)}provideFactory(e,n){return this.factoryRegistry.has(e.symbol)?console.warn(`Token ${e.symbol.toString()} is already registered`):this.factoryRegistry.set(e.symbol,n),this}provideValue(e,n){return this.factoryRegistry.has(e.symbol)?console.warn(`Token ${e.symbol.toString()} is already registered`):this.factoryRegistry.set(e.symbol,()=>n),this}dispose(){this.instanceRegistry.forEach(e=>{const n=x.get(e,"dispose");x.isFunction(n)&&n.bind(e)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}const ms="10.5.1",rc=Object.freeze(Object.defineProperty({__proto__:null,version:ms},Symbol.toStringTag,{value:"Module"}));class ic{constructor(e){V(this,"staticColors",new Map);V(this,"interpolations",new Map);e.installedPlugins.forEach(n=>{n.manifest.color.forEach(r=>{this.register(r)})})}getStaticColors(){return Array.from(this.staticColors.values())}register(e){const n=this.encodeColor(e);e.type==="single"?(this.staticColors.has(n)&&console.warn(`the color '${e.name}' has been registered under '${e.category}', previous registered value will be overridden`),this.staticColors.set(n,e)):e.type==="interpolation"&&(this.interpolations.has(n)&&console.warn(`the interpolation '${e.name}' has been registered under '${e.category}', previous registered value will be overridden`,`the interpolation '${e.name}' has been registered under '${e.category}', previous registered value will be overridden`),this.interpolations.set(n,e))}decodeStaticColor(e){return this.staticColors.get(e)}encodeColor(e){return`\${${e.category}}.{${e.name}}`}decodeInterpolation(e){return this.interpolations.get(e)}getColorInterpolations(){return Array.from(this.interpolations.values())}}class ac{constructor(){V(this,"plugins",new Map);V(this,"vizComponents",new Map);V(this,"factory",{viz:e=>{const n=this.vizComponents.get(e);if(n)return n;throw new Error(`Viz Component (${e}) not found`)}})}install(e){if(this.plugins.has(e.id))throw new Error(`Plugin (${e.id}) has been installed before`);this.plugins.set(e.id,e);for(const n of e.manifest.viz){if(this.vizComponents.has(n.name))throw new Error(`Viz Component (${n.name}) has been installed before`);this.vizComponents.set(n.name,n)}}get installedPlugins(){return Array.from(this.plugins.values())}}const R=(t,e)=>{const[n,{setFalse:r}]=J.useBoolean(!0),[a,o]=y.useState();y.useEffect(()=>(t.getItem(e).then(u=>{o(u),r()}),t.watchItem(e,u=>{o(u)})));const l=y.useCallback(async u=>{await t.setItem(e,u),o(u)},[t,e]);return{loading:n,value:a,set:l}},xr={x_axis_data_key:"",y_axis_data_key:"",z_axis_data_key:"",xAxis3D:{type:"value",name:"X Axis Name"},yAxis3D:{type:"value",name:"Y Axis Name"},zAxis3D:{type:"value",name:"Z Axis Name"}};function q(t){const[e,n]=t.split(".");return{queryID:e,columnKey:n}}function ot(t,e){var a;const{queryID:n,columnKey:r}=q(e);return n?r?((a=t[n])==null?void 0:a.map(o=>o[r]))??[]:t[n]:[]}function xn(t,e){const{queryID:n}=q(e);return n?t[n]:[]}function sc(t){return Object.values(t)[0]}function wn(t,e){const{queryID:n,columnKey:r}=q(e);return t[r]}ue.use([G.GridComponent,G.VisualMapComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer]);function oc({context:t}){const{value:e}=R(t.instanceData,"config"),n=t.data,{width:r,height:a}=t.viewport,{x_axis_data_key:o,y_axis_data_key:l,z_axis_data_key:u,xAxis3D:c,yAxis3D:d,zAxis3D:f}=x.defaults({},e,xr),p=y.useMemo(()=>xn(n,o),[n,o]),{x:g,y:m,z:C}=y.useMemo(()=>({x:q(o),y:q(l),z:q(u)}),[o,l,u]),{min:w,max:_}=y.useMemo(()=>{const M=x.minBy(p,B=>B[C.columnKey]),O=x.maxBy(p,B=>B[C.columnKey]);return{min:x.get(M,C.columnKey),max:x.get(O,C.columnKey)}},[p,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:p.map(M=>[M[g.columnKey],M[m.columnKey],M[C.columnKey]])}]};return e?i(Ne,{echarts:ue,option:T,style:{width:r,height:a},notMerge:!0,theme:"merico-light"}):null}const ys=y.createContext({panel:null,data:{},loading:!1,errors:[]}),wr=ys.Provider;function Ae(){const t=y.useContext(ys);if(!t.panel)throw new Error("Please use PanelContextProvider");return t}const lc={fullScreenPanelID:"",setFullScreenPanelID:x.noop},Cr=y.createContext(lc);function bs(){const t=y.useContext(Cr);if(!t)throw new Error("Please use FullScreenPanelContext.Provider");return t}const j=k.observer(y.forwardRef(({label:t,required:e,value:n,onChange:r,clearable:a=!1,sx:o,...l},u)=>{const{panel:c}=Ae(),d=y.useMemo(()=>{const f=[...c.dataFieldOptions];return a&&f.unshift({label:"unset",value:"",group:""}),f},[c.dataFieldOptions]);return i(s.Select,{ref:u,label:t,data:d,value:n,onChange:r,required:e,sx:o,...l})}));function uc({context:t}){const{value:e,set:n}=R(t.instanceData,"config"),r=x.defaults({},e,xr),{control:a,handleSubmit:o,reset:l}=v.useForm({defaultValues:r});return y.useEffect(()=>{l(r)},[e]),e?i(s.Stack,{spacing:"xs",children:h("form",{onSubmit:o(n),children:[i(s.Text,{children:"X Axis"}),h(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"x_axis_data_key",control:a,render:({field:u})=>i(j,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"xAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Text,{mt:"lg",children:"Y Axis"}),h(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"y_axis_data_key",control:a,render:({field:u})=>i(j,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"yAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Text,{mt:"lg",children:"Z Axis"}),h(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"z_axis_data_key",control:a,render:({field:u})=>i(j,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"zAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:h(s.Button,{color:"blue",type:"submit",children:[i(I.DeviceFloppy,{size:20}),i(s.Text,{ml:"md",children:"Save"})]})})]})}):null}function cc(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis_data_key:a,y_axis_data_key:o,z_axis_data_key:l,...u}=t;return{...u,x_axis_data_key:r(a),y_axis_data_key:r(o),z_axis_data_key:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class dc extends ve{constructor(){super(...arguments);V(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 pc={displayName:"Bar Chart (3D)",displayGroup:"ECharts-based charts",migrator:new dc,name:"bar-3d",viewRender:oc,configRender:uc,createConfig(){return{version:2,config:x.cloneDeep(xr)}}};class Fe extends y.Component{constructor(e){super(e),this.state={error:null}}componentDidCatch(e){this.setState({error:e})}render(){var e;if(this.state.error){const n=()=>{this.setState({error:null})};return h(s.Box,{children:[i(s.Text,{size:"xs",children:(e=this.state.error)==null?void 0:e.message}),i(s.Button,{variant:"subtle",size:"xs",mx:"auto",compact:!0,sx:{display:"block"},onClick:n,children:"Retry"})]})}return this.props.children}}const $e={mantissa:0,output:"number",trimMantissa:!1,average:!1};function hc({value:t,onChange:e},n){const r=u=>{e({...t,output:u})},a=u=>{const c=u===0?!1:t.trimMantissa;e({...t,mantissa:u,trimMantissa:c})},o=u=>{e({...t,trimMantissa:u.currentTarget.checked})},l=u=>{e({...t,average:u.currentTarget.checked})};return h(s.Stack,{ref:n,children:[h(s.Group,{grow:!0,children:[i(s.Select,{label:"Format",data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:t.output,onChange:r,sx:{flexGrow:1}}),i(s.Switch,{label:h(s.Stack,{spacing:0,children:[i(s.Text,{children:"Average"}),i(s.Text,{size:12,color:"gray",children:"like 1.234k, 1.234m"})]}),checked:t.average,onChange:l,disabled:t.output!=="number",sx:{flexGrow:1},styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}}})]}),h(s.Group,{grow:!0,children:[i(s.NumberInput,{label:"Mantissa",defaultValue:0,min:0,step:1,max:4,value:t.mantissa,onChange:a}),i(s.Switch,{label:"Trim mantissa",checked:t.trimMantissa,onChange:o,disabled:t.mantissa===0,styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"}}})]}),h(s.Stack,{spacing:0,children:[i(s.Text,{weight:"bold",children:"Preview"}),i(Fe,{children:h(s.Group,{position:"apart",children:[h(s.Text,{size:12,color:"gray",children:["123456789 ",i(I.ArrowRight,{size:9})," ",te(123456789).format(t)]}),h(s.Text,{size:12,color:"gray",children:["1234 ",i(I.ArrowRight,{size:9})," ",te(1234).format(t)]}),h(s.Text,{size:12,color:"gray",children:["0.1234 ",i(I.ArrowRight,{size:9})," ",te(.1234).format(t)]})]})})]})]})}const Je=y.forwardRef(hc),tt={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
120
|
+
`)},vs={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:gc,configRender:fc,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 fc(t){return i(N,{})}function gc(t){return i(s.Text,{children:"Click chart's series"})}const mc=[{label:"Truncate",value:"truncate"},{label:"Break Line",value:"break"},{label:"Break Word",value:"breakAll"}],Cn=y.forwardRef(({sectionTitle:t,value:e,onChange:n},r)=>{const a=o=>l=>{const u=x.cloneDeep(e);x.set(u,o,l),n(u)};return h(s.Stack,{spacing:0,children:[t&&i(s.Divider,{mb:-5,mt:5,variant:"dotted",label:t,labelPosition:"right",labelProps:{color:"dimmed"}}),h(s.Group,{grow:!0,noWrap:!0,children:[i(s.NumberInput,{label:"Max Width",hideControls:!0,value:e.width,onChange:a("width")}),i(s.Select,{label:"Overflow",data:mc,value:e.overflow,onChange:a("overflow")}),i(s.TextInput,{label:"Ellipsis",value:e.ellipsis,disabled:!0})]})]})}),gt=y.forwardRef(({value:t,onChange:e},n)=>{const r=o=>{e({...t,on_axis:o})},a=o=>{e({...t,in_tooltip:o})};return h(s.Stack,{ref:n,spacing:0,children:[i(Cn,{sectionTitle:"Overflow on Axis",value:t.on_axis,onChange:r}),i(Cn,{sectionTitle:"Overflow in Tooltip",value:t.in_tooltip,onChange:a})]})}),Ze={on_axis:{width:80,overflow:"truncate",ellipsis:"..."},in_tooltip:{width:200,overflow:"break",ellipsis:"..."}};function mt({overflow:t,width:e}){const n={truncate:"initial",break:"break-all",breakAll:"break-word"}[t],r=t==="truncate"?"nowrap":"initial",a={truncate:"ellipsis",break:"clip",breakAll:"clip"}[t];return`
|
|
121
121
|
max-width: ${e}px;
|
|
122
122
|
word-break: ${n};
|
|
123
123
|
white-space: ${r};
|
|
124
124
|
overflow: hidden;
|
|
125
125
|
text-overflow: ${a};
|
|
126
|
-
`}function lt(t){return{width:t.width,overflow:t.overflow,ellipsis:t.ellipsis}}const Sr={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...tt},overflow:Ze}},y_axis:{name:"Y Axis",data_key:"value",label_formatter:$e},tooltip:{metrics:[]},color:"#228be6",reference_lines:[]},He=(t,e)=>{const[n,r]=y.useState([]);return y.useEffect(()=>t.watchTriggerSnapshotList(a=>r(a.filter(o=>o.schemaRef===e))),[]),n},xs=t=>{const{title:e="Variables",variables:n}=t,r=Ie.useClipboard(),a=o=>{r.copy(o),hn.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:e}),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 mu{constructor(e,n){V(this,"operationId");V(this,"operation");V(this,"operationSchema");V(this,"variables",[]);this.operationManager=e,this.instance=n,ae.makeAutoObservable(this)}get schemaList(){return this.operationManager.getOperationSchemaList()}async configOperation(e,n){const r=await this.operationManager.retrieveTrigger(e),a=this.operationManager.getOperationSchemaList().find(o=>o.id===(r==null?void 0:r.schemaRef));ae.runInAction(()=>{this.operationId=e,this.operation=r,this.operationSchema=a,this.variables=n})}async changeSchema(e){this.operationId&&(await this.operationManager.createOrGetOperation(this.operationId,e),await this.configOperation(this.operationId,this.variables))}}function yu(t){return!!t.operationId}const bu=k.observer(({model:t,onClick:e})=>{var r;const n=(r=t.operationSchema)==null?void 0:r.displayName;return i(s.Button,{variant:"outline",onClick:e,children:n})}),vu=k.observer(({model:t})=>{const e={operation:t.operation,instance:t.instance,variables:[]};return y.createElement(t.operationSchema.configRender,e)});function xu({model:t}){const e=t.schemaList,n=e.map(a=>({label:a.displayName,value:a.id}));async function r(a){await t.changeSchema(e.find(o=>o.id===a))}return i(s.Select,{label:"Operation",data:n,onChange:r,value:t.operationSchema.id})}const wu=k.observer(t=>{const[e,{setTrue:n,setFalse:r}]=J.useBoolean(!1),{operationManager:a,operationId:o,instance:l,variables:c}=t,u=J.useCreation(()=>new mu(a,l),[a,l]);return J.useAsyncEffect(async()=>{await u.configOperation(o,c)},[o,u]),yu(u)?p(N,{children:[i(bu,{model:u,onClick:n}),i(s.Modal,{size:600,opened:e,onClose:r,title:"Operation Settings",closeButtonLabel:"close",zIndex:320,children:p(s.Stack,{children:[i(xu,{model:u}),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(vu,{model:u})}),i(s.Tabs.Panel,{value:"variables",pt:10,children:i(xs,{title:"Variables",variables:u.variables})})]})]})})]}):null});class Cu{constructor(e,n){V(this,"triggerId");V(this,"trigger");V(this,"triggerSchema");V(this,"sampleData");this.triggerManager=e,this.instance=n,ae.makeAutoObservable(this)}get schemaList(){return this.triggerManager.getTriggerSchemaList()}async configTrigger(e,n){const r=await this.triggerManager.retrieveTrigger(e),a=this.triggerManager.getTriggerSchemaList().find(o=>o.id===(r==null?void 0:r.schemaRef));ae.runInAction(()=>{this.triggerId=e,this.trigger=r,this.triggerSchema=a,this.sampleData=n})}async changeSchema(e){this.triggerId&&(await this.triggerManager.createOrGetTrigger(this.triggerId,e),await this.configTrigger(this.triggerId,this.sampleData))}isReady(){return Su(this)}}function Su(t){return!!t.triggerId&&!!t.triggerSchema}function _u(t,e){return J.useCreation(()=>new Cu(t,e),[t,e])}const ku=k.observer(({model:t,onClick:e})=>{const n=t.triggerSchema.nameRender,r={trigger:t.trigger,instance:t.instance,sampleData:t.sampleData};return i(s.Button,{variant:"outline",onClick:e,children:y.createElement(n,r)})}),Tu=k.observer(({model:t})=>{const e=t.schemaList,n=e.map(a=>({label:a.displayName,value:a.id}));async function r(a){await t.changeSchema(e.find(o=>o.id===a))}return i(s.Select,{label:"Trigger",data:n,value:t.triggerSchema.id,onChange:r})}),Du=k.observer(({model:t})=>{const e={trigger:t.trigger,instance:t.instance,sampleData:t.sampleData};return y.createElement(t.triggerSchema.configRender,e)}),Iu=k.observer(t=>{const[e,{setTrue:n,setFalse:r}]=J.useBoolean(!1),a=t.model;return p(N,{children:[i(s.Modal,{opened:e,onClose:r,title:"Setup Trigger",closeButtonLabel:"close setup",zIndex:320,children:p(s.Stack,{children:[i(Tu,{model:a}),i(Du,{model:a}),i(xs,{title:"Payload",variables:a.triggerSchema.payload})]})}),i(ku,{onClick:n,model:a})]})});function Mu(t,e){const[n,r]=y.useState([]);return J.useAsyncEffect(async()=>{const a=await t.getInteractionList();r(a)},[e,t]),n}const Eu=k.observer(({item:t,manager:e,instance:n,sampleData:r,variables:a,onRemove:o})=>{const{triggerRef:l,operationRef:c}=t,u=_u(e.triggerManager,n);if(J.useAsyncEffect(async()=>{await u.configTrigger(l,r)},[u,l,r]),u.isReady()){const d=[...u.triggerSchema.payload,...a];return p(s.Group,{children:[i(Iu,{model:u}),i(wu,{instance:n,operationId:c,variables:d,operationManager:e.operationManager}),i(s.ActionIcon,{"aria-label":"delete-interaction",variant:"filled",color:"red",onClick:()=>o(t),children:i(I.Trash,{size:16})})]})}return null}),Au=t=>{const[e,n]=y.useState(0),{interactionManager:r,instance:a,sampleData:o,variables:l}=t,c=Mu(r,e),u=async()=>{const g=await r.triggerManager.createOrGetTrigger(Ie.randomId(),r.triggerManager.getTriggerSchemaList()[0]),m=await r.operationManager.createOrGetOperation(Ie.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}=J.useRequest(async()=>{try{return(await r.triggerManager.getTriggerSchemaList()).length}catch{return 0}});return p(s.Stack,{children:[i(s.LoadingOverlay,{visible:h}),f===0&&i(s.Alert,{icon:i(I.AlertCircle,{size:16}),title:"Unavailable",color:"gray",children:"This visualization does not have available interactions to choose from"}),c.map(g=>i(Eu,{onRemove:d,instance:a,sampleData:o,variables:l,item:g,manager:t.interactionManager},g.id)),i(s.Button,{style:{width:"fit-content"},onClick:()=>u(),disabled:f===0,children:"Add interaction"})]})},zu=()=>{const{panel:t,data:e}=Ae(),n=t.viz,{vizManager:r}=y.useContext(it),a=t.json,o=J.useCreation(()=>r.getOrCreateInstance(a),[r,a]),l=J.useCreation(()=>new gi(o,r.resolveComponent(n.type),Un),[o,n.type]);return y.useEffect(()=>o.instanceData.watchItem(null,x.throttle(c=>{t.viz.setConf(c)},100,{leading:!1,trailing:!0})),[o]),{instance:o,vizManager:r,interactionManager:l,sampleData:e,variables:[]}},$u=()=>{const t=zu();return i(Au,{...t})},ws="__TRIGGERS";class Lu{constructor(e,n){V(this,"attachments");this.instance=e,this.component=n;const r=async a=>{const{id:o,schemaRef:l}=await a.getItem(null);return{id:o,schemaRef:l,triggerData:new $t(a,"data")}};this.attachments=new br(e,ws,r)}watchTriggerSnapshotList(e){return this.instance.instanceData.watchItem(ws,n=>{const r=x.values(n).map(a=>({id:x.get(a,"id"),schemaRef:x.get(a,"schemaRef"),config:ae.toJS(x.get(a,"data.config"))}));e(r)},{fireImmediately:!0})}async createOrGetTrigger(e,n,r={recreate:!1}){var c;if(!this.getTriggerSchemaList().some(u=>u.id===n.id))throw new Error(`Trigger schema '${n.id}' is not defined in component '${this.component.name}'`);const o=await this.attachments.getInstance(e);return!o||r.recreate||o.schemaRef!==n.id?await this.attachments.create(e,{id:e,schemaRef:n.id,data:((c=n==null?void 0:n.createDefaultConfig)==null?void 0:c.call(n))||{}}):o}async getTriggerList(){return await this.attachments.list()}getTriggerSchemaList(){return this.component.triggers||[]}async removeTrigger(e){await this.attachments.remove(e)}async retrieveTrigger(e){return await this.attachments.getInstance(e)}async getMigrationTasks(){const n=(await this.getTriggerList()).map(async r=>{const a=this.getTriggerSchemaList().find(c=>c.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 e=await this.getMigrationTasks();await Promise.all(e.map(n=>n()))}}function Lt({enabled:t,func_content:e}){return(n,r)=>{if(!t)return n;try{return new Function(`return ${e}`)()(n,r)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function Ou(t,e){return Object.entries(t).map(([r,a])=>{const o=a.map(_=>_[e]).sort((_,T)=>_-T),l=Yt.quantile(o,.25)??0,c=Yt.quantile(o,.5)??0,u=Yt.quantile(o,.75)??0,d=u-l,f=l-1.5*d,h=u+1.5*d,g=Math.max(o[0],f),m=Math.min(x.last(o)??0,h),C=a.filter(_=>{const T=_[e];return T<g||T>m}).map(_=>[r,_[e],_]);return{name:r,min:g,q1:l,median:c,q3:u,max:m,outliers:C}})}function Pu(t,e){const{x_axis:n,y_axis:r}=t;if(!n.data_key||!r.data_key)return[];const a=q(n.data_key),o=q(r.data_key);if(a.queryID!==o.queryID)throw new Error("Please use the same query for X & Y axis");const l=x.groupBy(e[a.queryID],a.columnKey),c=Ou(l,o.columnKey),u=c.map(d=>d.outliers).flat();return[{source:c},{source:u}]}function Bu({config:t}){return{show:!0,top:0,right:10,type:"scroll",data:[{name:"Box",icon:"roundRect",itemStyle:{color:t.color}},{name:"Outlier",icon:"circle",itemStyle:{color:"#2F8CC0"}}]}}const _r=["max","q3","median","q1","min"];function Vu(t){const{color:e}=t;return[{name:"Box",type:"boxplot",itemStyle:{color:e,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 Nu(t){const{outliers:e,min:n,max:r}=t,a=e.filter(c=>c[1]<n).length,o=e.filter(c=>c[1]>r).length,l=(c,u)=>`
|
|
126
|
+
`}function lt(t){return{width:t.width,overflow:t.overflow,ellipsis:t.ellipsis}}const Sr={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...tt},overflow:Ze}},y_axis:{name:"Y Axis",data_key:"value",label_formatter:$e},tooltip:{metrics:[]},color:"#228be6",reference_lines:[]},He=(t,e)=>{const[n,r]=y.useState([]);return y.useEffect(()=>t.watchTriggerSnapshotList(a=>r(a.filter(o=>o.schemaRef===e))),[]),n},xs=t=>{const{title:e="Variables",variables:n}=t,r=Ie.useClipboard(),a=o=>{r.copy(o),hn.showNotification({color:"green",message:"Copied to clipboard"})};return h(s.Paper,{withBorder:!0,p:"sm",children:[i(s.Text,{size:"xs",color:"dimmed",mb:"sm",children:e}),i(s.Stack,{style:{maxHeight:"500px"},children:n.map(o=>h(s.Text,{size:"sm",children:[h(s.Code,{color:"teal",children:["// ",o.description]}),i("br",{}),h(s.Code,{onClick:()=>a(o.name),style:{cursor:"pointer"},children:[o.name," : ",o.valueType]})]},o.name))})]})};class yc{constructor(e,n){V(this,"operationId");V(this,"operation");V(this,"operationSchema");V(this,"variables",[]);this.operationManager=e,this.instance=n,ae.makeAutoObservable(this)}get schemaList(){return this.operationManager.getOperationSchemaList()}async configOperation(e,n){const r=await this.operationManager.retrieveTrigger(e),a=this.operationManager.getOperationSchemaList().find(o=>o.id===(r==null?void 0:r.schemaRef));ae.runInAction(()=>{this.operationId=e,this.operation=r,this.operationSchema=a,this.variables=n})}async changeSchema(e){this.operationId&&(await this.operationManager.createOrGetOperation(this.operationId,e),await this.configOperation(this.operationId,this.variables))}}function bc(t){return!!t.operationId}const vc=k.observer(({model:t,onClick:e})=>{var r;const n=(r=t.operationSchema)==null?void 0:r.displayName;return i(s.Button,{variant:"outline",onClick:e,children:n})}),xc=k.observer(({model:t})=>{const e={operation:t.operation,instance:t.instance,variables:[]};return y.createElement(t.operationSchema.configRender,e)});function wc({model:t}){const e=t.schemaList,n=e.map(a=>({label:a.displayName,value:a.id}));async function r(a){await t.changeSchema(e.find(o=>o.id===a))}return i(s.Select,{label:"Operation",data:n,onChange:r,value:t.operationSchema.id})}const Cc=k.observer(t=>{const[e,{setTrue:n,setFalse:r}]=J.useBoolean(!1),{operationManager:a,operationId:o,instance:l,variables:u}=t,c=J.useCreation(()=>new yc(a,l),[a,l]);return J.useAsyncEffect(async()=>{await c.configOperation(o,u)},[o,c]),bc(c)?h(N,{children:[i(vc,{model:c,onClick:n}),i(s.Modal,{size:600,opened:e,onClose:r,title:"Operation Settings",zIndex:320,children:h(s.Stack,{children:[i(wc,{model:c}),h(s.Tabs,{defaultValue:"settings",children:[h(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(xc,{model:c})}),i(s.Tabs.Panel,{value:"variables",pt:10,children:i(xs,{title:"Variables",variables:c.variables})})]})]})})]}):null});class Sc{constructor(e,n){V(this,"triggerId");V(this,"trigger");V(this,"triggerSchema");V(this,"sampleData");this.triggerManager=e,this.instance=n,ae.makeAutoObservable(this)}get schemaList(){return this.triggerManager.getTriggerSchemaList()}async configTrigger(e,n){const r=await this.triggerManager.retrieveTrigger(e),a=this.triggerManager.getTriggerSchemaList().find(o=>o.id===(r==null?void 0:r.schemaRef));ae.runInAction(()=>{this.triggerId=e,this.trigger=r,this.triggerSchema=a,this.sampleData=n})}async changeSchema(e){this.triggerId&&(await this.triggerManager.createOrGetTrigger(this.triggerId,e),await this.configTrigger(this.triggerId,this.sampleData))}isReady(){return _c(this)}}function _c(t){return!!t.triggerId&&!!t.triggerSchema}function kc(t,e){return J.useCreation(()=>new Sc(t,e),[t,e])}const Tc=k.observer(({model:t,onClick:e})=>{const n=t.triggerSchema.nameRender,r={trigger:t.trigger,instance:t.instance,sampleData:t.sampleData};return i(s.Button,{variant:"outline",onClick:e,children:y.createElement(n,r)})}),Dc=k.observer(({model:t})=>{const e=t.schemaList,n=e.map(a=>({label:a.displayName,value:a.id}));async function r(a){await t.changeSchema(e.find(o=>o.id===a))}return i(s.Select,{label:"Trigger",data:n,value:t.triggerSchema.id,onChange:r})}),Ic=k.observer(({model:t})=>{const e={trigger:t.trigger,instance:t.instance,sampleData:t.sampleData};return y.createElement(t.triggerSchema.configRender,e)}),Mc=k.observer(t=>{const[e,{setTrue:n,setFalse:r}]=J.useBoolean(!1),a=t.model;return h(N,{children:[i(s.Modal,{opened:e,onClose:r,title:"Setup Trigger",zIndex:320,children:h(s.Stack,{children:[i(Dc,{model:a}),i(Ic,{model:a}),i(xs,{title:"Payload",variables:a.triggerSchema.payload})]})}),i(Tc,{onClick:n,model:a})]})});function Ec(t,e){const[n,r]=y.useState([]);return J.useAsyncEffect(async()=>{const a=await t.getInteractionList();r(a)},[e,t]),n}const Ac=k.observer(({item:t,manager:e,instance:n,sampleData:r,variables:a,onRemove:o})=>{const{triggerRef:l,operationRef:u}=t,c=kc(e.triggerManager,n);if(J.useAsyncEffect(async()=>{await c.configTrigger(l,r)},[c,l,r]),c.isReady()){const d=[...c.triggerSchema.payload,...a];return h(s.Group,{children:[i(Mc,{model:c}),i(Cc,{instance:n,operationId:u,variables:d,operationManager:e.operationManager}),i(s.ActionIcon,{"aria-label":"delete-interaction",variant:"filled",color:"red",onClick:()=>o(t),children:i(I.Trash,{size:16})})]})}return null}),zc=t=>{const[e,n]=y.useState(0),{interactionManager:r,instance:a,sampleData:o,variables:l}=t,u=Ec(r,e),c=async()=>{const g=await r.triggerManager.createOrGetTrigger(Ie.randomId(),r.triggerManager.getTriggerSchemaList()[0]),m=await r.operationManager.createOrGetOperation(Ie.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:p}=J.useRequest(async()=>{try{return(await r.triggerManager.getTriggerSchemaList()).length}catch{return 0}});return h(s.Stack,{children:[i(s.LoadingOverlay,{visible:p}),f===0&&i(s.Alert,{icon:i(I.AlertCircle,{size:16}),title:"Unavailable",color:"gray",children:"This visualization does not have available interactions to choose from"}),u.map(g=>i(Ac,{onRemove:d,instance:a,sampleData:o,variables:l,item:g,manager:t.interactionManager},g.id)),i(s.Button,{style:{width:"fit-content"},onClick:()=>c(),disabled:f===0,children:"Add interaction"})]})},$c=()=>{const{panel:t,data:e}=Ae(),n=t.viz,{vizManager:r}=y.useContext(it),a=t.json,o=J.useCreation(()=>r.getOrCreateInstance(a),[r,a]),l=J.useCreation(()=>new gi(o,r.resolveComponent(n.type),Un),[o,n.type]);return y.useEffect(()=>o.instanceData.watchItem(null,x.throttle(u=>{t.viz.setConf(u)},100,{leading:!1,trailing:!0})),[o]),{instance:o,vizManager:r,interactionManager:l,sampleData:e,variables:[]}},Lc=()=>{const t=$c();return i(zc,{...t})},ws="__TRIGGERS";class Oc{constructor(e,n){V(this,"attachments");this.instance=e,this.component=n;const r=async a=>{const{id:o,schemaRef:l}=await a.getItem(null);return{id:o,schemaRef:l,triggerData:new $t(a,"data")}};this.attachments=new br(e,ws,r)}watchTriggerSnapshotList(e){return this.instance.instanceData.watchItem(ws,n=>{const r=x.values(n).map(a=>({id:x.get(a,"id"),schemaRef:x.get(a,"schemaRef"),config:ae.toJS(x.get(a,"data.config"))}));e(r)},{fireImmediately:!0})}async createOrGetTrigger(e,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(e);return!o||r.recreate||o.schemaRef!==n.id?await this.attachments.create(e,{id:e,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(e){await this.attachments.remove(e)}async retrieveTrigger(e){return await this.attachments.getInstance(e)}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 e=await this.getMigrationTasks();await Promise.all(e.map(n=>n()))}}function Lt({enabled:t,func_content:e}){return(n,r)=>{if(!t)return n;try{return new Function(`return ${e}`)()(n,r)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function Pc(t,e){return Object.entries(t).map(([r,a])=>{const o=a.map(_=>_[e]).sort((_,T)=>_-T),l=Yt.quantile(o,.25)??0,u=Yt.quantile(o,.5)??0,c=Yt.quantile(o,.75)??0,d=c-l,f=l-1.5*d,p=c+1.5*d,g=Math.max(o[0],f),m=Math.min(x.last(o)??0,p),C=a.filter(_=>{const T=_[e];return T<g||T>m}).map(_=>[r,_[e],_]);return{name:r,min:g,q1:l,median:u,q3:c,max:m,outliers:C}})}function Bc(t,e){const{x_axis:n,y_axis:r}=t;if(!n.data_key||!r.data_key)return[];const a=q(n.data_key),o=q(r.data_key);if(a.queryID!==o.queryID)throw new Error("Please use the same query for X & Y axis");const l=x.groupBy(e[a.queryID],a.columnKey),u=Pc(l,o.columnKey),c=u.map(d=>d.outliers).flat();return[{source:u},{source:c}]}function Vc({config:t}){return{show:!0,top:0,right:10,type:"scroll",data:[{name:"Box",icon:"roundRect",itemStyle:{color:t.color}},{name:"Outlier",icon:"circle",itemStyle:{color:"#2F8CC0"}}]}}const _r=["max","q3","median","q1","min"];function Nc(t){const{color:e}=t;return[{name:"Box",type:"boxplot",itemStyle:{color:e,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 qc(t){const{outliers:e,min:n,max:r}=t,a=e.filter(u=>u[1]<n).length,o=e.filter(u=>u[1]>r).length,l=(u,c)=>`
|
|
127
127
|
<tr>
|
|
128
|
-
<th style="text-align: right; padding: 0 1em;">${
|
|
128
|
+
<th style="text-align: right; padding: 0 1em;">${u}</th>
|
|
129
129
|
<td style="text-align: left; padding: 0 1em;">
|
|
130
|
-
${
|
|
130
|
+
${c}
|
|
131
131
|
</td>
|
|
132
132
|
</tr>
|
|
133
|
-
`;return{greater:l("Outliers ⬆",o),less:l("Outliers ⬇",a)}}const
|
|
133
|
+
`;return{greater:l("Outliers ⬆",o),less:l("Outliers ⬇",a)}}const Fc=(t,e)=>{const n=_r.map(l=>`
|
|
134
134
|
<tr>
|
|
135
135
|
<th style="text-align: right; padding: 0 1em;">${x.capitalize(l)}</th>
|
|
136
136
|
<td style="text-align: left; padding: 0 1em;">
|
|
137
137
|
${te(e[l]).format(t.y_axis.label_formatter)}
|
|
138
138
|
</td>
|
|
139
|
-
</tr>`),r=
|
|
139
|
+
</tr>`),r=qc(e);return n.unshift(r.greater),n.push(r.less),`
|
|
140
140
|
<div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
|
|
141
141
|
<div style="${mt(t.x_axis.axisLabel.overflow.in_tooltip)}">${e.name}</div>
|
|
142
142
|
</div>
|
|
@@ -145,14 +145,14 @@ Check the top-level render call using <`+P+">.")}return A}}function ql(S,A){{if(
|
|
|
145
145
|
${n.join("")}
|
|
146
146
|
</tbody>
|
|
147
147
|
</table>
|
|
148
|
-
`},
|
|
148
|
+
`},Gc=t=>{try{return te(t).format({trimMantissa:!0,mantissa:2})}catch{return t}};function Wc(t,e){const n=mt(t.x_axis.axisLabel.overflow.in_tooltip),r=[`<tr>
|
|
149
149
|
<th style="text-align: right; padding: 0 1em;">Outlier</th>
|
|
150
150
|
<td style="text-align: left; padding: 0 1em;">${e[1]}</td>
|
|
151
151
|
</tr>
|
|
152
|
-
`],a=t.tooltip.metrics.map(l=>{const
|
|
152
|
+
`],a=t.tooltip.metrics.map(l=>{const u=q(l.data_key);return`
|
|
153
153
|
<tr>
|
|
154
154
|
<th style="text-align: right; padding: 0 1em;">${l.name}</th>
|
|
155
|
-
<td style="text-align: left; padding: 0 1em;">${
|
|
155
|
+
<td style="text-align: left; padding: 0 1em;">${Gc(e[2][u.columnKey])}</td>
|
|
156
156
|
</tr>`});return r.push(...a),`
|
|
157
157
|
<div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
|
|
158
158
|
<div style="${n}">${e[0]}</div>
|
|
@@ -162,24 +162,24 @@ Check the top-level render call using <`+P+">.")}return A}}function ql(S,A){{if(
|
|
|
162
162
|
${r.join("")}
|
|
163
163
|
</tbody>
|
|
164
164
|
</table>
|
|
165
|
-
`}const
|
|
166
|
-
`,"<br/>").split("<br/>");return n.map((a,o)=>{const l=[sd(a)];return o!==n.length-1&&l.push(i("br",{},`br-${o}`)),l}).flat().filter(a=>a!==void 0)}function Tr(t){return od(t)}function Jt(t,e,n){const r=ad(e,n),a=/^\{(.+)\}(.*)$/;return t.split("$").map((o,l)=>{const c=a.exec(o);if(!c)return Tr(o);const u=r[c[1]];if(!u)return Tr(o);const d=c[2]??"";return p(y.Fragment,{children:[u,Tr(d)]},`${o}-${l}`)})}function ld(t,e){const n={};return t.forEach(r=>{const{name:a,data_field:o,aggregation:l}=r,c=kn(e,o,l);n[a]=ct(r,c)}),n}function Tn(t,e,n){const r=ld(e,n),a=/^\{(.+)\}(.*)$/;return t.split("$").map(o=>{const l=a.exec(o);if(!l)return o;const c=r[l[1]];if(!c)return o;const u=l[2]??"";return`${c}${u}`}).join("")}function cd(t,e,n){const r=e.reduce((a,o)=>{const l=Pt(o,n);return a[o.name]=ct(o,l),a},{});return t.map(a=>({name:"refs",type:"scatter",data:[],markLine:{data:[{name:a.name,yAxis:Number(r[a.variable_key])}],silent:!0,symbol:["none","none"],label:{formatter:function(){return Tn(a.template,e,n)},position:"insideEndTop"}}}))}function ud({config:t,data:e,variables:n}){const{x_axis:r,y_axis:a,reference_lines:o}=t,l=Pu(t,e),c=lt(r.axisLabel.overflow.on_axis),u=Vu(t);return{grid:{top:30,left:20,right:15,bottom:25,containLabel:!0},dataset:l,legend:Bu({config:t}),tooltip:Ru({config:t}),xAxis:[{type:"category",name:r.name,nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold",align:"center"},axisTick:{show:!0,alignWithLabel:!0},axisLabel:{...r.axisLabel,...c,formatter:Lt(r.axisLabel.formatter)}}],yAxis:[{name:a.name,nameTextStyle:{fontWeight:"bold"},axisLine:{show:!0},axisLabel:{formatter:function(d){return te(d).format(a.label_formatter)}}}],series:[...u,...cd(o,n,e)]}}function yt(t,e){return y.useMemo(()=>{const{queryID:n,columnKey:r}=q(e);return x.keyBy(t[n],r)},[t,e])}ce.use([G.DataZoomComponent,he.BoxplotChart,G.MarkLineComponent,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer]);function dd({context:t,instance:e}){const{value:n}=R(t.instanceData,"config"),{variables:r}=t,a=t.data,{width:o,height:l}=t.viewport,c=x.defaults({},n,Sr),u=et({vizManager:t.vizManager,instance:e}),d=He(u.triggerManager,vs.id),f=yt(a,c.x_axis.data_key),h=y.useCallback(C=>{const w=x.get(f,C.name,{error:"rowData is not found"});d.forEach(_=>{u.runInteraction(_.id,{...C,rowData:w})})},[f,d,u]),g=y.useMemo(()=>({click:h}),[h]),m=y.useMemo(()=>ud({config:c,data:a,variables:r}),[c,a,r]);return!n||!o||!l?null:i(Ne,{echarts:ce,option:m,style:{width:o,height:l},onEvents:g,notMerge:!0,theme:"merico-light"})}function pd({control:t,index:e,remove:n,variableOptions:r}){return p(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${e}.name`,control:t,render:({field:a})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_lines.${e}.variable_key`,control:t,render:({field:a})=>i(s.Select,{label:"Value",required:!0,data:r,sx:{flex:1},...a})})]}),i(v.Controller,{name:`reference_lines.${e}.template`,control:t,render:({field:a})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",required:!0,sx:{flex:1},...a})}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(e),sx:{position:"absolute",top:15,right:5},children:i(I.Trash,{size:16})})]},e)}function hd({control:t,watch:e,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:t,name:"reference_lines"}),l=e("reference_lines"),c=r.map((f,h)=>({...f,...l[h]})),u=()=>a({name:"",template:"",variable_key:""}),d=y.useMemo(()=>n.map(f=>({label:f.name,value:f.name})),[n]);return p(s.Stack,{children:[c.map((f,h)=>i(pd,{control:t,index:h,remove:o,variableOptions:d},f.id)),i(s.Group,{position:"center",mt:"xs",children:i(s.Button,{onClick:u,children:"Add a Reference Line"})})]})}const fd=({disabled:t,value:e,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[t&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(ze,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},Dn=y.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:a,setFalse:o}]=J.useBoolean(),[l,c]=y.useState(t);y.useEffect(()=>{c(t)},[t]);const u=m=>{c({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:C}=l,w={enabled:m,func_content:C};c(w),e(w)},f=()=>{o(),c(t)},h=m=>{c(C=>({...C,func_content:m}))},g=()=>{h(tt.func_content)};return p(N,{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=>u(m.currentTarget.checked)}),i(fd,{value:l.func_content,onChange:h,disabled:!l.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:g,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:d,children:"OK"})]})]})]})})]})}),gd=({control:t,watch:e})=>(e(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"X Axis Name",sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>i(j,{label:"X Axis Data Field",required:!0,sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Dn,{...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>i(gt,{...n})})]})),md=({control:t,watch:e})=>(e(["y_axis"]),p(N,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Y Axis Name",sx:{flex:1},...n})}),i(v.Controller,{name:"y_axis.data_key",control:t,render:({field:n})=>i(j,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:"y_axis.label_formatter",control:t,render:({field:n})=>i(Je,{...n})})]})]})),yd=({control:t,index:e,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${e}.data_key`,control:t,render:({field:r})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),bd=({control:t,watch:e})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"tooltip.metrics"}),o=e("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),c=()=>r({id:Date.now().toString(),data_key:"",name:""}),u=e("tooltip.metrics.0.id"),[d,f]=y.useState(()=>u??null);return y.useEffect(()=>{u&&f(h=>h!==null?h:u)},[u]),p(N,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(I.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Set additional metrics to show in scatter's tooltip"})]}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(yd,{control:t,index:g,remove:a},h.id)},h.id))]})]})};function vd({control:t,watch:e}){return i(s.Stack,{children:i(bd,{control:t,watch:e})})}function xd({context:t}){const{value:e,set:n}=R(t.instanceData,"config"),{variables:r}=t,a=y.useMemo(()=>x.defaults({},e,Sr),[e]),{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]),c(["x_axis","y_axis","reference_lines","color"]);const f=u(),h=y.useMemo(()=>!x.isEqual(f,e),[f,e]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(I.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),i(s.Tabs.Tab,{value:"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(gd,{control:o,watch:c})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(md,{control:o,watch:c})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(vd,{control:o,watch:c})}),i(s.Tabs.Panel,{value:"Style",children:p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:"color",control:o,render:({field:g})=>i(Pe,{...g})})]})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(hd,{variables:r,control:o,watch:c})})]})]})})}function wd(t){return x.omit(t,"variables")}function Cd(t){const{label_formatter:e=$e,...n}=t.y_axis;return{...t,y_axis:{...n,label_formatter:e}}}function Sd(t){const e={rotate:0,formatter:{...tt}},{axisLabel:n=e,...r}=t.x_axis;return{...t,x_axis:{...r,axisLabel:n}}}function _d(t){const e={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return x.defaultsDeep(e,t)}function kd(t){delete t.config;const{x_axis:e,tooltip:n}=t.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:e,in_tooltip:n}}}};return x.defaultsDeep(r,t)}function Td(t){const e={tooltip:{metrics:[]}};return x.defaultsDeep(e,t)}function Dd(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis:a,y_axis:o,tooltip:l,...c}=t;return{...c,x_axis:{...a,data_key:r(a.data_key)},y_axis:{...o,data_key:r(o.data_key)},tooltip:{...l,metrics:l.metrics.map(u=>({...u,data_key:r(u.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}class Id extends ve{constructor(){super(...arguments);V(this,"VERSION",8)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,{panelModel:r})=>{const{config:a}=n;return(a.variables||[]).forEach(l=>{r.variables.find(c=>c.name===l.name)||r.addVariable(l)}),{...n,version:2,config:wd(a)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:Cd(r)}}),this.version(4,n=>{const{config:r}=n;return{...n,version:4,config:Sd(r)}}),this.version(5,n=>{const{config:r}=n;return{...n,version:5,config:_d(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:kd(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:Td(r)}}),this.version(8,(n,r)=>{const{config:a}=n;return{...n,version:8,config:Dd(a,r)}})}}const Md={displayName:"Boxplot Chart",displayGroup:"ECharts-based charts",migrator:new Id,name:"boxplot",viewRender:dd,configRender:xd,createConfig(){return{version:8,config:x.cloneDeep(Sr)}},triggers:[vs]},ks={id:"builtin:button:click-button",displayName:"Click Button",nameRender:Ad,configRender:Ed,payload:[]};function Ed(t){return i(N,{})}function Ad(t){return i(s.Text,{children:"Click this button"})}const Dr={content:"Button",variant:"filled",color:"blue",size:"xs",compact:!1,horizontal_align:"left",vertical_align:"center"},zd={left:"flex-start",center:"center",right:"flex-end"},$d={top:"flex-start",center:"center",bottom:"flex-end"},Ld=k.observer(({context:t,instance:e})=>{const n=et({vizManager:t.vizManager,instance:e}),r=He(n.triggerManager,ks.id),a=K(),{value:o}=R(t.instanceData,"config"),l=y.useMemo(()=>x.defaultsDeep({},o,Dr),[o]),{content:c,horizontal_align:u,vertical_align:d,...f}=l,{width:h,height:g}=t.viewport,m=a.payloadForSQL,C=()=>{r.forEach(w=>{n.runInteraction(w.id,{})})};return i(s.Center,{sx:{width:h,height:g,justifyContent:zd[u],alignItems:$d[d]},children:i(s.Button,{...f,onClick:C,children:x.template(c)(m)})})}),Od=({value:t,onChange:e,label:n})=>{const r=s.useMantineTheme(),a=y.useCallback(l=>()=>e(l),[e]),o=l=>t===l;return p(s.Stack,{spacing:2,children:[i(s.Text,{size:14,sx:{fontWeight:500},children:n}),i(s.Group,{position:"left",spacing:"xs",children:Object.keys(r.colors).map(l=>{const c=r.colors[l][6];return i(s.ColorSwatch,{color:c,onClick:a(l),radius:4,size:26,sx:{cursor:"pointer"},children:o(l)&&i(s.CheckIcon,{width:10,color:"white"})},l)})})]})},Pd=s.MANTINE_SIZES.map(t=>({label:t.toUpperCase(),value:t})),Bd=({label:t,value:e,onChange:n})=>i(s.Select,{data:Pd,label:t,value:e,onChange:n}),Vd=[{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}],Nd=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],qd=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function Fd({context:t}){const{value:e,set:n}=R(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,Dr),[e]),a=r;y.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=u(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return c(["content","variant","color","size","compact","horizontal_align","vertical_align"]),p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(I.DeviceFloppy,{size:20})})]}),p(s.Stack,{children:[i(v.Controller,{control:o,name:"content",render:({field:g})=>i(s.TextInput,{label:"Content Template",description:"Filter values & context entries are supported",...g,required:!0})}),i(s.Divider,{mt:"xs",mb:0,label:"Styles",labelPosition:"center",variant:"dashed"}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{control:o,name:"variant",render:({field:g})=>i(s.Select,{label:"Variant",data:Vd,...g})}),i(v.Controller,{control:o,name:"color",render:({field:g})=>i(Od,{label:"Theme",...g})})]}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{control:o,name:"size",render:({field:g})=>i(Bd,{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:Nd,...g})}),i(v.Controller,{control:o,name:"vertical_align",render:({field:g})=>i(s.Select,{label:"Vertical Alignment",data:qd,...g})})]})]})]})}class Gd extends ve{constructor(){super(...arguments);V(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 Wd={displayName:"Button",displayGroup:"Others",migrator:new Gd,name:"button",viewRender:Ld,configRender:Fd,createConfig(){return{version:2,config:x.cloneDeep(Dr)}},triggers:[ks]},Ir={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:jd,configRender:Rd,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 Rd(t){return i(N,{})}function jd(t){return i(s.Text,{children:"Click chart's series"})}const Bt={x_axis_scroll:!1,y_axis_scroll:!1,x_axis_slider:!1,y_axis_slider:!1},Mr={regressions:[],series:[],stats:{templates:{bottom:"",top:""}},x_axis:{type:"category",axisLabel:{rotate:0,formatter:{...tt},overflow:Ze}},x_axis_data_key:"",x_axis_name:"",y_axes:[{min:"",max:"",name:"Y Axis",show:!0,position:"left",nameAlignment:"center",label_formatter:$e}],reference_lines:[],reference_areas:[],dataZoom:Bt};function Er(t){const e=[];return t.x_axis_scroll&&e.push({type:"inside",xAxisIndex:[0],filterMode:"none",minSpan:1}),t.y_axis_scroll&&e.push({type:"inside",yAxisIndex:[0],filterMode:"none",minSpan:1}),t.x_axis_slider&&e.push({type:"slider",xAxisIndex:[0],filterMode:"none",bottom:"auto",top:0,height:15,moveHandleSize:0,showDataShadow:!1,minSpan:1}),e}function Yd(t){const e=t.y_axes.some(a=>!!a.name);let n=15;e&&(n+=20),t.dataZoom.x_axis_slider&&(n+=20);let r=5;return t.x_axis_name&&(r+=15),t.series.some(a=>!a.hide_in_legend)&&(r+=20),{top:n,right:15,bottom:r,left:20,containLabel:!0}}function Qd(t){return t!=="line"?{}:{itemStyle:{opacity:0}}}function Kd(t){switch(t){case"line":return;case"bar":return"roundRect";case"scatter":return"circle"}}function Ud(t){const e={show:!0,bottom:0,left:"center",type:"scroll"};return e.data=t.filter(n=>!n.hide_in_legend).map(({name:n,type:r})=>({name:n,icon:Kd(r),...Qd(r)})),e}function In(t,e){switch(t.config.method){case"linear":return[...ht.regressionLinear()(e)];case"exponential":return[...ht.regressionExp()(e)];case"logarithmic":return[...ht.regressionLog()(e)];case"polynomial":return[...ht.regressionPoly().order(t.config.order)(e)];default:return[]}}function Xd(t,e,n,r){const{transform:a,plot:o}=t,l={...o,name:e,data:In(a,r),showSymbol:!1,tooltip:{show:!1},smooth:!1,custom:{}};return n&&(l.custom={type:"regression-line",targetSeries:n}),l}function Jd({regressions:t=[],x_axis_data_key:e},n){const r=[];if(Object.keys(n).length===0)return r;function a(o,l,c,u){const d=Xd(o,l,c,u);r.push(d)}return t.forEach(o=>{const{name:l,group_by_key:c}=o;if(!c||c===e){const h=ot(n,o.y_axis_data_key).map((g,m)=>[m,Number(g)]);a(o,l,"",h);return}const{columnKey:u}=q(o.y_axis_data_key),d=x.groupBy(xn(n,o.y_axis_data_key),c);Object.entries(d).forEach(([f,h])=>{const g=h.map((C,w)=>[w,Number(C[u])]);a(o,f,f,g)})}),r}function Zd(t,e){return t.map(n=>({name:"",type:"line",hide_in_legend:!0,data:[],markArea:{itemStyle:{color:n.color},data:[[{yAxis:e[n.y_keys.upper]},{yAxis:e[n.y_keys.lower]}]],silent:!0}}))}function Hd(t,e,n,r){return t.map(a=>{const o=a.orientation==="horizontal",l=o?"yAxis":"xAxis",c=o?"insideEndTop":"end";return{name:a.name,type:"line",hide_in_legend:!a.show_in_legend,yAxisIndex:a.yAxisIndex,data:[],lineStyle:a.lineStyle,markLine:{data:[{name:a.name,[l]:Number(n[a.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:a.lineStyle,label:{formatter:function(){return a.template?Tn(a.template,e,r):""},position:c}}}})}function ep({type:t,...e},n,r,a){if(!t)return 10;if(t==="static"){const{size:d}=e;return d}const{func_content:o}=e,{queryID:l,columnKey:c}=q(r),u=x.keyBy(xn(n,l),c);return(d,f)=>{let h;f.name?h=u[f.name]:h=n[f.dataIndex];try{return new Function(`return ${o}`)()({rowData:h,params:f,variables:a},{lodash:x,interpolate:At.interpolate})}catch(g){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${g.message}`),10}}}function Ar(t,e,n){const r=ot(t,e),a=ot(t,n);return x.zip(r,a)}function tp(t,e,n,r){const a=Ar(e,n,r);return x.unionBy(a,t,0)}function np({dataTemplate:t,data:e,x_axis_data_key:n,y_axis_data_key:r,valueTypedXAxis:a}){return a?tp(t,e,n,r):ot(e,r)}function rp({dataTemplate:t,data:e,aggregation_on_value:n,x_axis_data_key:r,y_axis_data_key:a,valueTypedXAxis:o}){if(!n||n.type==="none")return np({dataTemplate:t,data:e,x_axis_data_key:r,y_axis_data_key:a,valueTypedXAxis:o});const l=Ar(e,r,a),c=x.groupBy(l,"0");return t.map(([d])=>{const h=c[d].map(m=>m[1]),g=kr(h,n);return[d,g]})}function ip({group_by_key:t,data:e,x_axis_data_key:n,y_axis_data_key:r}){const{queryID:a,columnKey:o}=q(t),l=x.groupBy(e[a],o);return Object.entries(l).forEach(([c,u])=>{l[c]=Ar({[a]:u},n,r)}),l}function ap({x_axis_data_key:t,x_axis:e},{y_axis_data_key:n,yAxisIndex:r,label_position:a,name:o,group_by_key:l,aggregation_on_value:c,stack:u,color:d,display_name_on_line:f,symbolSize:h,hide_in_legend:g,...m},C,w,_,T){const M=e.type!=="category",O={label:{show:!!a,position:a,formatter:T[r??"default"]},name:o,xAxisId:"main-x-axis",yAxisIndex:r,stack:u,color:d,symbolSize:ep(h,w,t,_),hide_in_legend:g,labelLayout:{hideOverlap:!0},...m};if(f&&(O.endLabel={show:!0,formatter:o,offset:[-12,12],align:"right"}),!l||l===t)return O.data=rp({dataTemplate:C,data:w,aggregation_on_value:c,x_axis_data_key:t,y_axis_data_key:n,valueTypedXAxis:M}),O;const B=ip({group_by_key:l,data:w,x_axis_data_key:t,y_axis_data_key:n});return Object.entries(B).map(([F,$])=>{const E=x.cloneDeep(O);return E.name=F,E.color=void 0,E.data=$,E})}function sp(t,e,n,r,a,o){const l=e.map(u=>[u,0]);return t.series.map(u=>ap(t,u,l,n,o,r)).flat().concat(Hd(t.reference_lines,a,o,n)).concat(Zd(t.reference_areas,o))}function op(t,e){const n=t.find(o=>o.axisDim==="x"&&o.axisId==="main-x-axis");if(!n)return"";const{axisValue:r,axisIndex:a}=n;return Lt(e.x_axis.axisLabel.formatter)(r,a)}function lp(t,e,n){const r=e.reduce((a,{yAxisIndex:o,name:l})=>(a[l]=o,a),{});return{trigger:"axis",confine:!0,formatter:function(a){const o=Array.isArray(a)?a:[a];if(o.length===0)return"";const l=o.map(({seriesName:d,marker:f,value:h})=>{if(Array.isArray(h)&&h.length===2&&(h=h[1]),!d)return h;const g=r[d],m=n[g]??n.default;return`
|
|
165
|
+
`}const Rc=t=>e=>{const{componentSubType:n,value:r}=e;return n==="scatter"?Wc(t,r):Fc(t,r)};function jc({config:t}){return{trigger:"item",confine:!0,formatter:Rc(t)}}const Xt=y.forwardRef(function({value:e,onChange:n,...r},a){return i(s.TextInput,{ref:a,value:e,onChange:n,...r})}),Yc=[{label:"None",value:"none"},{label:"Sum",value:"sum"},{label:"Mean",value:"mean"},{label:"Median",value:"median"},{label:"Max",value:"max"},{label:"Min",value:"min"},{label:"Coefficient of Variation",value:"CV"},{label:"Standard Variation",value:"std"},{label:"Quantile(99%, 95%, ...)",value:"quantile"}];function Qc({label:t,value:e,onChange:n,pt:r="sm"},a){y.useEffect(()=>{typeof e=="string"&&(console.log(e),n({type:e,config:{}}))},[e,n]);const o=u=>{n(u==="quantile"?{type:"quantile",config:{p:.99}}:{type:u,config:{}})},l=u=>{n({type:"quantile",config:{p:u}})};return h(s.Group,{grow:!0,noWrap:!0,pt:r,children:[i(s.Select,{ref:a,label:t,data:Yc,value:e.type,onChange:o}),e.type==="quantile"&&i(s.NumberInput,{label:"p",value:e.config.p,onChange:l,precision:2,min:.05,step:.05,max:1})]})}const Sn=y.forwardRef(Qc);function Kc({label:t,value:e,onChange:n},r){const[a,o]=y.useState(Array.isArray(e)?[...e]:[]),l=y.useCallback(()=>{o(g=>[...g,""])},[o]),u=y.useCallback(g=>{o(m=>(m.splice(g,1),[...m]))},[o]),c=y.useMemo(()=>!x.isEqual(a,e),[a,e]),d=()=>{n(a.map(g=>g.toString()))},f=s.useMantineTheme(),p=y.useMemo(()=>Object.entries(f.colors).map(([g,m])=>m[6]),[f]);return h(N,{children:[h(s.Group,{position:"left",ref:r,children:[i(s.Text,{children:t}),i(s.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!c,onClick:d,children:i(I.DeviceFloppy,{size:20})})]}),h(s.Group,{children:[a.map((g,m)=>i(s.ColorInput,{value:g,onChange:C=>{o(w=>(w.splice(m,1,C),[...w]))},swatches:p,rightSection:i(s.ActionIcon,{onClick:()=>u(m),color:"red",children:i(I.Trash,{size:14})}),sx:{width:"45%"}})),i(s.ActionIcon,{onClick:l,color:"blue",variant:"outline",children:i(I.PlaylistAdd,{size:20})})]})]})}const Uc=y.forwardRef(Kc);function Xc({value:t,onChange:e},n){const{colorManager:r}=y.useContext(it),a=y.useMemo(()=>r.getStaticColors().map(u=>({label:u.name,group:u.category,value:u.value})),[r]),o=y.useMemo(()=>a.some(l=>l.value===t),[t,a]);return h(s.Group,{position:"apart",spacing:4,ref:n,children:[i(s.TextInput,{placeholder:"Set any color",value:o?"":t,onChange:l=>e(l.currentTarget.value),rightSection:i(s.ColorSwatch,{color:o?"transparent":t,radius:4}),variant:o?"filled":"default",sx:{maxWidth:"46%",flexGrow:1}}),i(s.Text,{sx:{flexGrow:0},children:"or"}),i(s.Select,{data:a,value:t,onChange:e,variant:o?"default":"filled",placeholder:"Pick a theme color",icon:i(s.ColorSwatch,{color:o?t:"transparent",radius:4}),sx:{maxWidth:"46%",flexGrow:1}})]})}const Pe=y.forwardRef(Xc),_n=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function Jc({label:t,value:e,onChange:n},r){var l;const[a,o]=y.useState(((l=_n.find(u=>u.label===e))==null?void 0:l.value)??_n[0].value);return y.useEffect(()=>{const u=_n.find(c=>c.value===a);u&&n(u.label)},[a]),h(s.Stack,{spacing:0,mt:"sm",mb:"lg",children:[i(s.Text,{size:"sm",children:t}),i(s.Slider,{label:null,marks:_n,value:a,onChange:o,step:25,placeholder:"Pick a font size",px:"1em",ref:r})]})}const Cs=y.forwardRef(Jc);function Zc({label:t,value:e,onChange:n,type:r},a){const[o,l]=y.useState(Array.isArray(e)?[...e]:[]),u=y.useCallback(()=>{l(p=>[...p,""])},[l]),c=y.useCallback(p=>{l(g=>(g.splice(p,1),[...g]))},[l]),d=y.useMemo(()=>!x.isEqual(o.map(String),e.map(String)),[o,e]),f=()=>{n(o.map(p=>r==="number"?Number(p):p.toString()))};return h(N,{children:[h(s.Group,{position:"left",ref:a,children:[i(s.Text,{children:t}),i(s.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!d,onClick:f,children:i(I.DeviceFloppy,{size:20})})]}),h(s.Group,{children:[o.map((p,g)=>i(s.TextInput,{type:r,value:p,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(I.Trash,{size:14})}),sx:{width:"45%"}})),i(s.ActionIcon,{onClick:u,color:"blue",variant:"outline",children:i(I.PlaylistAdd,{size:20})})]})]})}const Hc=y.forwardRef(Zc),Ss=y.forwardRef(function({value:e,onChange:n},r){const a=e.color.type,o=(l,u)=>{const c=x.cloneDeep(e);x.set(c,l,u),n(c)};return h(N,{children:[i(s.Divider,{my:"xs",label:"Typography",labelPosition:"center"}),i(s.Stack,{children:i(s.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1},value:e.size,onChange:l=>o("size",l.currentTarget.value)})}),i(s.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:i(Cs,{label:"Font Weight",value:e.weight,onChange:l=>o("weight",l)})}),i(s.Divider,{my:"xs",label:"Style",labelPosition:"center"}),h(s.Stack,{children:[i(s.Select,{label:"Color Type",data:[{label:"Static Color",value:"static"},{label:"Continuous Color",value:"continuous"}],value:e.color.type,onChange:l=>o("color.type",l)}),a==="static"&&i(Pe,{value:e.color.staticColor,onChange:l=>o("color.staticColor",l)}),a==="continuous"&&h(N,{children:[i(Hc,{label:"Value Range",value:e.color.valueRange,type:"number",onChange:l=>o("color.valueRange",l)}),i(Uc,{label:"Color Range",value:e.color.colorRange,onChange:l=>o("color.colorRange",l)})]})]})]})});y.forwardRef(function({value:e,onChange:n,withStyle:r=!0},a){const o=(l,u)=>{const c=x.cloneDeep(e);x.set(c,l,u),n(c)};return h(s.Box,{px:"sm",py:"md",ref:a,children:[i(s.Text,{weight:"bold",pb:0,children:e.name}),i(s.Divider,{my:"xs",label:"Data",labelPosition:"center"}),h(s.Group,{grow:!0,noWrap:!0,children:[i(s.TextInput,{label:"Name",required:!0,value:e.name,onChange:l=>o("name",l.currentTarget.value)}),i(j,{label:"Data Field",required:!0,value:e.data_field,onChange:l=>o("data_field",l)})]}),i(Sn,{label:"Aggregation",value:e.aggregation,onChange:l=>o("aggregation",l)}),i(s.Divider,{my:"xs",label:"Format",labelPosition:"center"}),i(Je,{value:e.formatter,onChange:l=>o("formatter",l)}),r&&i(Ss,{value:e,onChange:n})]})});const Ot={type:"none",config:{}};function ed(t){const e=Array.from(t).sort((r,a)=>r-a),n=Math.floor(e.length/2);return e.length%2===0?(e[n-1]+e[n])/2:e[n]}function td(t){const e=Number(t);return isFinite(e)?e:0}function nd(t,e){switch(e.type){case"sum":return x.sum(t);case"mean":return x.mean(t);case"median":return ed(t);case"max":return x.max(t)??0;case"min":return x.min(t)??0;case"quantile":return Yt.quantile(t,e.config.p)??0;case"CV":const n=mn.std(...t),r=mn.mean(...t);return r?n/r:"N/A";case"std":return mn.std(...t);default:return t}}function kr(t,e){const n=t.map(td);return nd(n,e)}function kn(t,e,n){try{return kr(ot(t,e),n)}catch(r){return console.error(r),null}}class rd{constructor({valueRange:e,colorRange:n}){V(this,"mapper");this.mapper=At.interpolate(e,n)}getColor(e){return this.mapper(e)}}function id(t){return t===null?"null":t===void 0?"undefined":Array.isArray(t)?`Array(${t.length})`:t.toString()}function Pt({data_field:t,aggregation:e},n){return kn(n,t,e)}function ut({formatter:t},e){if(!["string","number"].includes(typeof e))return id(e);try{return te(e).format(t)}catch(n){return console.error(n),e}}function ad(t,e){if(t.type==="static")return t.staticColor;if(t.type==="continuous")try{if(typeof e!="number")throw new Error(`[getColorByColorConf] Invalid type of aggregated value: ${e}`);return new rd(t).getColor(e)}catch(n){return console.error(n),"black"}return"black"}function _s(t,e){const{color:n,data_field:r,aggregation:a,size:o,weight:l}=t,u=kn(e,r,a),c=ut(t,u);return i(s.Text,{sx:{fontSize:o,display:"inline"},color:ad(n,u),weight:l,children:c})}function sd(t,e){const n={};return t.forEach(r=>{const a=r.name;n[a]=_s(r,e)}),n}function od(t){return t.split(" ").map((e,n)=>h(y.Fragment,{children:[e," "]},n))}function ld(t){const n=t.replaceAll("<br />","<br/>").replaceAll(`
|
|
166
|
+
`,"<br/>").split("<br/>");return n.map((a,o)=>{const l=[od(a)];return o!==n.length-1&&l.push(i("br",{},`br-${o}`)),l}).flat().filter(a=>a!==void 0)}function Tr(t){return ld(t)}function Jt(t,e,n){const r=sd(e,n),a=/^\{(.+)\}(.*)$/;return t.split("$").map((o,l)=>{const u=a.exec(o);if(!u)return Tr(o);const c=r[u[1]];if(!c)return Tr(o);const d=u[2]??"";return h(y.Fragment,{children:[c,Tr(d)]},`${o}-${l}`)})}function ud(t,e){const n={};return t.forEach(r=>{const{name:a,data_field:o,aggregation:l}=r,u=kn(e,o,l);n[a]=ut(r,u)}),n}function Tn(t,e,n){const r=ud(e,n),a=/^\{(.+)\}(.*)$/;return t.split("$").map(o=>{const l=a.exec(o);if(!l)return o;const u=r[l[1]];if(!u)return o;const c=l[2]??"";return`${u}${c}`}).join("")}function cd(t,e,n){const r=e.reduce((a,o)=>{const l=Pt(o,n);return a[o.name]=ut(o,l),a},{});return t.map(a=>({name:"refs",type:"scatter",data:[],markLine:{data:[{name:a.name,yAxis:Number(r[a.variable_key])}],silent:!0,symbol:["none","none"],label:{formatter:function(){return Tn(a.template,e,n)},position:"insideEndTop"}}}))}function dd({config:t,data:e,variables:n}){const{x_axis:r,y_axis:a,reference_lines:o}=t,l=Bc(t,e),u=lt(r.axisLabel.overflow.on_axis),c=Nc(t);return{grid:{top:30,left:20,right:15,bottom:25,containLabel:!0},dataset:l,legend:Vc({config:t}),tooltip:jc({config:t}),xAxis:[{type:"category",name:r.name,nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold",align:"center"},axisTick:{show:!0,alignWithLabel:!0},axisLabel:{...r.axisLabel,...u,formatter:Lt(r.axisLabel.formatter)}}],yAxis:[{name:a.name,nameTextStyle:{fontWeight:"bold"},axisLine:{show:!0},axisLabel:{formatter:function(d){return te(d).format(a.label_formatter)}}}],series:[...c,...cd(o,n,e)]}}function yt(t,e){return y.useMemo(()=>{const{queryID:n,columnKey:r}=q(e);return x.keyBy(t[n],r)},[t,e])}ue.use([G.DataZoomComponent,he.BoxplotChart,G.MarkLineComponent,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer]);function pd({context:t,instance:e}){const{value:n}=R(t.instanceData,"config"),{variables:r}=t,a=t.data,{width:o,height:l}=t.viewport,u=x.defaults({},n,Sr),c=et({vizManager:t.vizManager,instance:e}),d=He(c.triggerManager,vs.id),f=yt(a,u.x_axis.data_key),p=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:p}),[p]),m=y.useMemo(()=>dd({config:u,data:a,variables:r}),[u,a,r]);return!n||!o||!l?null:i(Ne,{echarts:ue,option:m,style:{width:o,height:l},onEvents:g,notMerge:!0,theme:"merico-light"})}function hd({control:t,index:e,remove:n,variableOptions:r}){return h(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${e}.name`,control:t,render:({field:a})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_lines.${e}.variable_key`,control:t,render:({field:a})=>i(s.Select,{label:"Value",required:!0,data:r,sx:{flex:1},...a})})]}),i(v.Controller,{name:`reference_lines.${e}.template`,control:t,render:({field:a})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",required:!0,sx:{flex:1},...a})}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(e),sx:{position:"absolute",top:15,right:5},children:i(I.Trash,{size:16})})]},e)}function fd({control:t,watch:e,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:t,name:"reference_lines"}),l=e("reference_lines"),u=r.map((f,p)=>({...f,...l[p]})),c=()=>a({name:"",template:"",variable_key:""}),d=y.useMemo(()=>n.map(f=>({label:f.name,value:f.name})),[n]);return h(s.Stack,{children:[u.map((f,p)=>i(hd,{control:t,index:p,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 gd=({disabled:t,value:e,onChange:n})=>{const r=a=>{a&&n(a)};return h(s.Box,{sx:{position:"relative"},children:[t&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(ze,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},Dn=y.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:a,setFalse:o}]=J.useBoolean(),[l,u]=y.useState(t);y.useEffect(()=>{u(t)},[t]);const c=m=>{u({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:C}=l,w={enabled:m,func_content:C};u(w),e(w)},f=()=>{o(),u(t)},p=m=>{u(C=>({...C,func_content:m}))},g=()=>{p(tt.func_content)};return h(N,{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&&h(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:m=>c(m.currentTarget.checked)}),i(gd,{value:l.func_content,onChange:p,disabled:!l.enabled}),h(s.Group,{position:"apart",children:[i(s.Button,{onClick:g,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Rest"}),h(s.Group,{position:"right",children:[i(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:d,children:"OK"})]})]})]})})]})}),md=({control:t,watch:e})=>(e(["x_axis"]),h(s.Stack,{children:[h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"X Axis Name",sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>i(j,{label:"X Axis Data Field",required:!0,sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Dn,{...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>i(gt,{...n})})]})),yd=({control:t,watch:e})=>(e(["y_axis"]),h(N,{children:[h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Y Axis Name",sx:{flex:1},...n})}),i(v.Controller,{name:"y_axis.data_key",control:t,render:({field:n})=>i(j,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})})]}),h(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:"y_axis.label_formatter",control:t,render:({field:n})=>i(Je,{...n})})]})]})),bd=({control:t,index:e,remove:n})=>h(s.Stack,{children:[h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${e}.data_key`,control:t,render:({field:r})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),vd=({control:t,watch:e})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"tooltip.metrics"}),o=e("tooltip.metrics"),l=n.map((p,g)=>({...p,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=e("tooltip.metrics.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(p=>p!==null?p:c)},[c]),h(N,{children:[h(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(I.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Set additional metrics to show in scatter's tooltip"})]}),h(s.Tabs,{value:d,onTabChange:p=>f(p),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[h(s.Tabs.List,{children:[l.map((p,g)=>i(s.Tabs.Tab,{value:p.id,children:p.name?p.name:g},p.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((p,g)=>i(s.Tabs.Panel,{value:p.id,children:i(bd,{control:t,index:g,remove:a},p.id)},p.id))]})]})};function xd({control:t,watch:e}){return i(s.Stack,{children:i(vd,{control:t,watch:e})})}function wd({context:t}){const{value:e,set:n}=R(t.instanceData,"config"),{variables:r}=t,a=y.useMemo(()=>x.defaults({},e,Sr),[e]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]),u(["x_axis","y_axis","reference_lines","color"]);const f=c(),p=y.useMemo(()=>!x.isEqual(f,e),[f,e]);return i(s.Stack,{spacing:"xs",children:h("form",{onSubmit:l(n),children:[h(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:!p,children:i(I.DeviceFloppy,{size:20})})]}),h(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[h(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),i(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"}),i(s.Tabs.Tab,{value:"Style",children:"Style"}),i(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(md,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(yd,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(xd,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Style",children:h(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:"color",control:o,render:({field:g})=>i(Pe,{...g})})]})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(fd,{variables:r,control:o,watch:u})})]})]})})}function Cd(t){return x.omit(t,"variables")}function Sd(t){const{label_formatter:e=$e,...n}=t.y_axis;return{...t,y_axis:{...n,label_formatter:e}}}function _d(t){const e={rotate:0,formatter:{...tt}},{axisLabel:n=e,...r}=t.x_axis;return{...t,x_axis:{...r,axisLabel:n}}}function kd(t){const e={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return x.defaultsDeep(e,t)}function Td(t){delete t.config;const{x_axis:e,tooltip:n}=t.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:e,in_tooltip:n}}}};return x.defaultsDeep(r,t)}function Dd(t){const e={tooltip:{metrics:[]}};return x.defaultsDeep(e,t)}function Id(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,y_axis:o,tooltip:l,...u}=t;return{...u,x_axis:{...a,data_key:r(a.data_key)},y_axis:{...o,data_key:r(o.data_key)},tooltip:{...l,metrics:l.metrics.map(c=>({...c,data_key:r(c.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}class Md extends ve{constructor(){super(...arguments);V(this,"VERSION",8)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,{panelModel:r})=>{const{config:a}=n;return(a.variables||[]).forEach(l=>{r.variables.find(u=>u.name===l.name)||r.addVariable(l)}),{...n,version:2,config:Cd(a)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:Sd(r)}}),this.version(4,n=>{const{config:r}=n;return{...n,version:4,config:_d(r)}}),this.version(5,n=>{const{config:r}=n;return{...n,version:5,config:kd(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:Td(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:Dd(r)}}),this.version(8,(n,r)=>{const{config:a}=n;return{...n,version:8,config:Id(a,r)}})}}const Ed={displayName:"Boxplot Chart",displayGroup:"ECharts-based charts",migrator:new Md,name:"boxplot",viewRender:pd,configRender:wd,createConfig(){return{version:8,config:x.cloneDeep(Sr)}},triggers:[vs]},ks={id:"builtin:button:click-button",displayName:"Click Button",nameRender:zd,configRender:Ad,payload:[]};function Ad(t){return i(N,{})}function zd(t){return i(s.Text,{children:"Click this button"})}const Dr={content:"Button",variant:"filled",color:"blue",size:"xs",compact:!1,horizontal_align:"left",vertical_align:"center"},$d={left:"flex-start",center:"center",right:"flex-end"},Ld={top:"flex-start",center:"center",bottom:"flex-end"},Od=k.observer(({context:t,instance:e})=>{const n=et({vizManager:t.vizManager,instance:e}),r=He(n.triggerManager,ks.id),a=K(),{value:o}=R(t.instanceData,"config"),l=y.useMemo(()=>x.defaultsDeep({},o,Dr),[o]),{content:u,horizontal_align:c,vertical_align:d,...f}=l,{width:p,height:g}=t.viewport,m=a.payloadForSQL,C=()=>{r.forEach(w=>{n.runInteraction(w.id,{})})};return i(s.Center,{sx:{width:p,height:g,justifyContent:$d[c],alignItems:Ld[d]},children:i(s.Button,{...f,onClick:C,children:x.template(u)(m)})})}),Pd=({value:t,onChange:e,label:n})=>{const r=s.useMantineTheme(),a=y.useCallback(l=>()=>e(l),[e]),o=l=>t===l;return h(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)})})]})},Bd=s.MANTINE_SIZES.map(t=>({label:t.toUpperCase(),value:t})),Vd=({label:t,value:e,onChange:n})=>i(s.Select,{data:Bd,label:t,value:e,onChange:n}),Nd=[{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}],qd=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Fd=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function Gd({context:t}){const{value:e,set:n}=R(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,Dr),[e]),a=r;y.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),p=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return u(["content","variant","color","size","compact","horizontal_align","vertical_align"]),h("form",{onSubmit:l(n),children:[h(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:!p,children:i(I.DeviceFloppy,{size:20})})]}),h(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"}),h(s.SimpleGrid,{cols:2,children:[i(v.Controller,{control:o,name:"variant",render:({field:g})=>i(s.Select,{label:"Variant",data:Nd,...g})}),i(v.Controller,{control:o,name:"color",render:({field:g})=>i(Pd,{label:"Theme",...g})})]}),h(s.SimpleGrid,{cols:2,children:[i(v.Controller,{control:o,name:"size",render:({field:g})=>i(Vd,{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})})]}),h(s.SimpleGrid,{cols:2,children:[i(v.Controller,{control:o,name:"horizontal_align",render:({field:g})=>i(s.Select,{label:"Horizontal Alignment",data:qd,...g})}),i(v.Controller,{control:o,name:"vertical_align",render:({field:g})=>i(s.Select,{label:"Vertical Alignment",data:Fd,...g})})]})]})]})}class Wd extends ve{constructor(){super(...arguments);V(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 Rd={displayName:"Button",displayGroup:"Others",migrator:new Wd,name:"button",viewRender:Od,configRender:Gd,createConfig(){return{version:2,config:x.cloneDeep(Dr)}},triggers:[ks]},Ir={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:Yd,configRender:jd,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 jd(t){return i(N,{})}function Yd(t){return i(s.Text,{children:"Click chart's series"})}const Bt={x_axis_scroll:!1,y_axis_scroll:!1,x_axis_slider:!1,y_axis_slider:!1},Mr={regressions:[],series:[],stats:{templates:{bottom:"",top:""}},x_axis:{type:"category",axisLabel:{rotate:0,formatter:{...tt},overflow:Ze}},x_axis_data_key:"",x_axis_name:"",y_axes:[{min:"",max:"",name:"Y Axis",show:!0,position:"left",nameAlignment:"center",label_formatter:$e}],reference_lines:[],reference_areas:[],dataZoom:Bt};function Er(t){const e=[];return t.x_axis_scroll&&e.push({type:"inside",xAxisIndex:[0],filterMode:"none",minSpan:1}),t.y_axis_scroll&&e.push({type:"inside",yAxisIndex:[0],filterMode:"none",minSpan:1}),t.x_axis_slider&&e.push({type:"slider",xAxisIndex:[0],filterMode:"none",bottom:"auto",top:0,height:15,moveHandleSize:0,showDataShadow:!1,minSpan:1}),e}function Qd(t){const e=t.y_axes.some(a=>!!a.name);let n=15;e&&(n+=20),t.dataZoom.x_axis_slider&&(n+=20);let r=5;return t.x_axis_name&&(r+=15),t.series.some(a=>!a.hide_in_legend)&&(r+=20),{top:n,right:15,bottom:r,left:20,containLabel:!0}}function Kd(t){return t!=="line"?{}:{itemStyle:{opacity:0}}}function Ud(t){switch(t){case"line":return;case"bar":return"roundRect";case"scatter":return"circle"}}function Xd(t){const e={show:!0,bottom:0,left:"center",type:"scroll"};return e.data=t.filter(n=>!n.hide_in_legend).map(({name:n,type:r})=>({name:n,icon:Ud(r),...Kd(r)})),e}function In(t,e){switch(t.config.method){case"linear":return[...ht.regressionLinear()(e)];case"exponential":return[...ht.regressionExp()(e)];case"logarithmic":return[...ht.regressionLog()(e)];case"polynomial":return[...ht.regressionPoly().order(t.config.order)(e)];default:return[]}}function Jd(t,e,n,r){const{transform:a,plot:o}=t,l={...o,name:e,data:In(a,r),showSymbol:!1,tooltip:{show:!1},smooth:!1,custom:{}};return n&&(l.custom={type:"regression-line",targetSeries:n}),l}function Zd({regressions:t=[],x_axis_data_key:e},n){const r=[];if(Object.keys(n).length===0)return r;function a(o,l,u,c){const d=Jd(o,l,u,c);r.push(d)}return t.forEach(o=>{const{name:l,group_by_key:u}=o;if(!u||u===e){const p=ot(n,o.y_axis_data_key).map((g,m)=>[m,Number(g)]);a(o,l,"",p);return}const{columnKey:c}=q(o.y_axis_data_key),d=x.groupBy(xn(n,o.y_axis_data_key),u);Object.entries(d).forEach(([f,p])=>{const g=p.map((C,w)=>[w,Number(C[c])]);a(o,f,f,g)})}),r}function Hd(t,e){return t.map(n=>({name:"",type:"line",hide_in_legend:!0,data:[],markArea:{itemStyle:{color:n.color},data:[[{yAxis:e[n.y_keys.upper]},{yAxis:e[n.y_keys.lower]}]],silent:!0}}))}function ep(t,e,n,r){return t.map(a=>{const o=a.orientation==="horizontal",l=o?"yAxis":"xAxis",u=o?"insideEndTop":"end";return{name:a.name,type:"line",hide_in_legend:!a.show_in_legend,yAxisIndex:a.yAxisIndex,data:[],lineStyle:a.lineStyle,markLine:{data:[{name:a.name,[l]:Number(n[a.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:a.lineStyle,label:{formatter:function(){return a.template?Tn(a.template,e,r):""},position:u}}}})}function tp({type:t,...e},n,r,a){if(!t)return 10;if(t==="static"){const{size:d}=e;return d}const{func_content:o}=e,{queryID:l,columnKey:u}=q(r),c=x.keyBy(xn(n,l),u);return(d,f)=>{let p;f.name?p=c[f.name]:p=n[f.dataIndex];try{return new Function(`return ${o}`)()({rowData:p,params:f,variables:a},{lodash:x,interpolate:At.interpolate})}catch(g){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${g.message}`),10}}}function Ar(t,e,n){const r=ot(t,e),a=ot(t,n);return x.zip(r,a)}function np(t,e,n,r){const a=Ar(e,n,r);return x.unionBy(a,t,0)}function rp({dataTemplate:t,data:e,x_axis_data_key:n,y_axis_data_key:r,valueTypedXAxis:a}){return a?np(t,e,n,r):ot(e,r)}function ip({dataTemplate:t,data:e,aggregation_on_value:n,x_axis_data_key:r,y_axis_data_key:a,valueTypedXAxis:o}){if(!n||n.type==="none")return rp({dataTemplate:t,data:e,x_axis_data_key:r,y_axis_data_key:a,valueTypedXAxis:o});const l=Ar(e,r,a),u=x.groupBy(l,"0");return t.map(([d])=>{const p=u[d].map(m=>m[1]),g=kr(p,n);return[d,g]})}function ap({group_by_key:t,data:e,x_axis_data_key:n,y_axis_data_key:r}){const{queryID:a,columnKey:o}=q(t),l=x.groupBy(e[a],o);return Object.entries(l).forEach(([u,c])=>{l[u]=Ar({[a]:c},n,r)}),l}function sp({x_axis_data_key:t,x_axis:e},{y_axis_data_key:n,yAxisIndex:r,label_position:a,name:o,group_by_key:l,aggregation_on_value:u,stack:c,color:d,display_name_on_line:f,symbolSize:p,hide_in_legend:g,...m},C,w,_,T){const M=e.type!=="category",O={label:{show:!!a,position:a,formatter:T[r??"default"]},name:o,xAxisId:"main-x-axis",yAxisIndex:r,stack:c,color:d,symbolSize:tp(p,w,t,_),hide_in_legend:g,labelLayout:{hideOverlap:!0},...m};if(f&&(O.endLabel={show:!0,formatter:o,offset:[-12,12],align:"right"}),!l||l===t)return O.data=ip({dataTemplate:C,data:w,aggregation_on_value:u,x_axis_data_key:t,y_axis_data_key:n,valueTypedXAxis:M}),O;const B=ap({group_by_key:l,data:w,x_axis_data_key:t,y_axis_data_key:n});return Object.entries(B).map(([F,$])=>{const E=x.cloneDeep(O);return E.name=F,E.color=void 0,E.data=$,E})}function op(t,e,n,r,a,o){const l=e.map(c=>[c,0]);return t.series.map(c=>sp(t,c,l,n,o,r)).flat().concat(ep(t.reference_lines,a,o,n)).concat(Hd(t.reference_areas,o))}function lp(t,e){const n=t.find(o=>o.axisDim==="x"&&o.axisId==="main-x-axis");if(!n)return"";const{axisValue:r,axisIndex:a}=n;return Lt(e.x_axis.axisLabel.formatter)(r,a)}function up(t,e,n){const r=e.reduce((a,{yAxisIndex:o,name:l})=>(a[l]=o,a),{});return{trigger:"axis",confine:!0,formatter:function(a){const o=Array.isArray(a)?a:[a];if(o.length===0)return"";const l=o.map(({seriesName:d,marker:f,value:p})=>{if(Array.isArray(p)&&p.length===2&&(p=p[1]),!d)return p;const g=r[d],m=n[g]??n.default;return`
|
|
167
167
|
<tr>
|
|
168
168
|
<td>${f}</td>
|
|
169
169
|
<th style="text-align: right; padding: 0 1em;">${d}</th>
|
|
170
|
-
<td style="text-align: left; padding: 0 1em;">${m({value:
|
|
170
|
+
<td style="text-align: left; padding: 0 1em;">${m({value:p})}</td>
|
|
171
171
|
</tr>
|
|
172
|
-
`}),
|
|
172
|
+
`}),u=mt(t.x_axis.axisLabel.overflow.in_tooltip),c=lp(o,t);return`
|
|
173
173
|
<div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
|
|
174
|
-
<div style="${
|
|
174
|
+
<div style="${u}">${c}</div>
|
|
175
175
|
</div>
|
|
176
176
|
<table style="width: auto">
|
|
177
177
|
<tbody>
|
|
178
178
|
${l.join("")}
|
|
179
179
|
</tbody>
|
|
180
180
|
</table>
|
|
181
|
-
`}}}function cp(t){return t.y_axes.reduce((n,{label_formatter:r},a)=>(n[a]=function(l){let c=l;if(typeof l=="object"&&(Array.isArray(l.value)&&l.value.length===2?c=l.value[1]:c=l.value),!r)return c;try{return te(c).format(r)}catch(u){return console.error(u),c}},n),{default:({value:n})=>n})}function up(t,e){const n={};return e.map(r=>{const a=Pt(r,t);n[r.name]=ct(r,a)}),n}function dp(t,e){const{overflow:n,...r}=t.x_axis.axisLabel,a=lt(n.on_axis);return[{data:e,name:t.x_axis_name??"",id:"main-x-axis",axisTick:{show:!0,alignWithLabel:!0},type:t.x_axis.type,axisLabel:{...r,...a,formatter:Lt(r.formatter)}}]}function pp(t,e){return t.y_axes.map(({nameAlignment:n,min:r,max:a,show:o,...l},c)=>{let u=l.position;return u||(u=c>0?"right":"left"),{...l,show:o,min:r||void 0,max:a||void 0,position:u,axisLabel:{show:o,formatter:e[c]??e.default},axisLine:{show:o},nameTextStyle:{fontWeight:"bold",align:n},nameLocation:"end",nameGap:o?15:0,splitLine:{show:!1}}})}const hp={xAxis:[{type:"category",nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0}}]};function fp(t,e,n){const r=up(e,n),a=cp(t),o=x.uniq(ot(e,t.x_axis_data_key)),l=sp(t,o,e,a,n,r),c=Jd(t,e),u={xAxis:dp(t,o),yAxis:pp(t,a),series:[...l,...c],tooltip:lp(t,l,a),grid:Yd(t),legend:Ud(l),dataZoom:Er(t.dataZoom)};return x.defaultsDeep({},u,hp)}function Ts(t){const e=t.getModel(),n=e.getSeries().map(r=>{if(!r.option.custom)return r.option;const a=e.getColorFromPalette(r.option.custom.targetSeries,null);return r.option.color=a,r.option});t.setOption({...t.getOption(),series:n})}ce.use([G.DataZoomComponent,he.BarChart,he.LineChart,he.ScatterChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer,G.MarkLineComponent,G.MarkAreaComponent]);function Ds(t){return t.trim().length>0}function gp({conf:t,data:e,width:n,height:r,interactionManager:a,variables:o}){const l=yt(e,t.x_axis_data_key),c=He(a.triggerManager,Ir.id),u=y.useCallback(m=>{const C=x.get(l,m.name,{error:"rowData is not found"});c.forEach(w=>{a.runInteraction(w.id,{...m,rowData:C})})},[l,c,a]),d=y.useMemo(()=>fp(t,e,o),[t,e]),f=y.useRef(),h=y.useMemo(()=>({click:u}),[u]),g=m=>{f.current=m,Ts(m)};return y.useEffect(()=>{f.current&&Ts(f.current)},[d]),!n||!r?null:i(Ne,{echarts:ce,option:d,style:{width:n,height:r},onEvents:h,onChartReady:g,notMerge:!0,theme:"merico-light"})}function mp({context:t,instance:e}){const n=et({vizManager:t.vizManager,instance:e}),{value:r}=R(t.instanceData,"config"),{variables:a}=t,o=y.useMemo(()=>x.defaults({},r,Mr),[r]),l=t.data,{width:c,height:u}=t.viewport,{ref:d,height:f}=Ie.useElementSize(),{ref:h,height:g}=Ie.useElementSize(),m=y.useMemo(()=>{const{stats:{templates:w}}=o;return{top:Jt(w.top,a,l),bottom:Jt(w.bottom,a,l)}},[o,l]),C=Math.max(0,u-f-g);return p(s.Box,{children:[i(s.Text,{ref:d,align:"left",size:"xs",pl:"sm",sx:{display:Ds(o.stats.templates.top)?"block":"none"},children:Object.values(m.top).map((w,_)=>i(y.Fragment,{children:w},_))}),i(gp,{variables:a,width:c,height:C,data:l,conf:o,interactionManager:n}),i(s.Text,{ref:h,align:"left",size:"xs",pl:"sm",sx:{display:Ds(o.stats.templates.bottom)?"block":"none"},children:Object.values(m.bottom).map((w,_)=>i(y.Fragment,{children:w},_))})]})}const zr=y.forwardRef(({value:t,onChange:e},n)=>{const r=a=>o=>{e({...t,[a]:o})};return p(s.Stack,{children:[i(s.Divider,{variant:"dashed",label:"Scroll to Zoom",labelPosition:"center"}),p(s.Group,{children:[i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Enable on X Axis",checked:t.x_axis_scroll,onChange:a=>r("x_axis_scroll")(a.currentTarget.checked)})}),i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Enable on Y Axis",checked:t.y_axis_scroll,onChange:a=>r("y_axis_scroll")(a.currentTarget.checked)})})]}),i(s.Divider,{variant:"dashed",label:"Slider for Zooming",labelPosition:"center"}),p(s.Group,{children:[i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Slider for X Axis",checked:t.x_axis_slider,onChange:a=>r("x_axis_slider")(a.currentTarget.checked)})}),i(s.Tooltip,{label:"Not available for now, will overlap y-axis's label",children:i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Slider for Y Axis",disabled:!t.y_axis_slider,checked:t.y_axis_slider,onChange:a=>r("y_axis_slider")(a.currentTarget.checked)})})})]})]})}),yp=[{label:"Rectangle",value:"rectangle"}],bp=[{label:"Horizontal",value:"horizontal"}];function vp({control:t,index:e,remove:n,variableOptions:r}){return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_areas.${e}.name`,control:t,render:({field:a})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_areas.${e}.color`,control:t,render:({field:a})=>i(s.TextInput,{label:"Color",required:!0,sx:{flex:1},...a})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_areas.${e}.type`,control:t,render:({field:a})=>i(s.Select,{label:"Type",required:!0,data:yp,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_areas.${e}.direction`,control:t,render:({field:a})=>i(s.Select,{label:"Direction",required:!0,data:bp,sx:{flex:1},...a})})]}),i(s.Divider,{variant:"dashed",label:"Data",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_areas.${e}.y_keys.upper`,control:t,render:({field:a})=>i(s.Select,{label:"Upper Boundary",required:!0,data:r,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_areas.${e}.y_keys.lower`,control:t,render:({field:a})=>i(s.Select,{label:"Lower Boundary",required:!0,data:r,sx:{flex:1},...a})})]}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Reference Area"})]},e)}function xp({control:t,watch:e,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:t,name:"reference_areas"}),l=e("reference_areas"),c=r.map((f,h)=>({...f,...l[h]})),u=()=>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:[c.map((f,h)=>i(s.Tabs.Tab,{value:h.toString(),children:h+1},h)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),c.map((f,h)=>i(s.Tabs.Panel,{value:h.toString(),children:i(vp,{control:t,index:h,remove:o,variableOptions:d})},h))]})}const wp=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Cp=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Sp({control:t,index:e,remove:n,watch:r,variableOptions:a,yAxisOptions:o}){const l=r(`reference_lines.${e}.orientation`);return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${e}.name`,control:t,render:({field:c})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...c})}),i(v.Controller,{name:`reference_lines.${e}.variable_key`,control:t,render:({field:c})=>i(s.Select,{label:"Value",required:!0,data:a,sx:{flex:1},...c})})]}),i(v.Controller,{name:`reference_lines.${e}.template`,control:t,render:({field:c})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...c})}),p(s.Group,{grow:!0,children:[p(s.Stack,{children:[i(v.Controller,{name:`reference_lines.${e}.orientation`,control:t,render:({field:c})=>i(s.Select,{label:"Orientation",data:Cp,required:!0,sx:{flex:1},...c})}),l==="vertical"&&i(s.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&i(v.Controller,{name:`reference_lines.${e}.yAxisIndex`,control:t,render:({field:{value:c,onChange:u,...d}})=>i(s.Select,{label:"Y Axis",data:o,disabled:o.length===0,...d,value:(c==null?void 0:c.toString())??"",onChange:f=>{if(!f){u(0);return}u(Number(f))},sx:{flex:1}})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`reference_lines.${e}.lineStyle.type`,control:t,render:({field:c})=>i(s.Select,{label:"Line Type",data:wp,sx:{flexGrow:1},...c})}),i(v.Controller,{name:`reference_lines.${e}.lineStyle.width`,control:t,render:({field:c})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...c})})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`reference_lines.${e}.lineStyle.color`,control:t,render:({field:c})=>i(Pe,{...c})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`reference_lines.${e}.show_in_legend`,control:t,render:({field:c})=>i(s.Checkbox,{label:"Show in legend",checked:c.value,onChange:u=>c.onChange(u.currentTarget.checked)})}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Reference Line"})]},e)}function _p({control:t,watch:e,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:t,name:"reference_lines"}),l=e("reference_lines"),c=r.map((g,m)=>({...g,...l[m]})),u=()=>{a({name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,yAxisIndex:0})},d=y.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=e("y_axes"),h=y.useMemo(()=>f.map(({name:g},m)=>({label:g,value:m.toString()})),[f]);return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[c.map((g,m)=>i(s.Tabs.Tab,{value:m.toString(),children:m+1},m)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),c.map((g,m)=>i(s.Tabs.Panel,{value:m.toString(),children:i(Sp,{control:t,index:m,remove:o,watch:e,variableOptions:d,yAxisOptions:h})},m))]})}const kp=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}],Tp=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function Dp({control:t,regressionItem:e,index:n,remove:r,yAxisOptions:a}){const o=e.transform.config.method;return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,children:[i(v.Controller,{name:`regressions.${n}.name`,control:t,render:({field:l})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`regressions.${n}.group_by_key`,control:t,render:({field:l})=>i(j,{label:"Split into multiple regression lines by this key...",clearable:!0,sx:{flex:1},...l})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`regressions.${n}.y_axis_data_key`,control:t,render:({field:l})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`regressions.${n}.plot.yAxisIndex`,control:t,render:({field:{value:l,onChange:c,...u}})=>i(s.Select,{label:"Y Axis",data:a,disabled:a.length===0,...u,value:(l==null?void 0:l.toString())??"",onChange:d=>{if(!d){c(0);return}c(Number(d))},sx:{flex:1}})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`regressions.${n}.transform.config.method`,control:t,render:({field:l})=>i(s.Select,{label:"Method",data:kp,sx:{flex:1},...l})}),o==="polynomial"&&i(v.Controller,{name:`regressions.${n}.transform.config.order`,control:t,render:({field:l})=>i(s.NumberInput,{label:"Order",sx:{flex:1},...l})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Line Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`regressions.${n}.plot.lineStyle.type`,control:t,render:({field:l})=>i(s.Select,{label:"Line Type",data:Tp,sx:{flexGrow:1},...l})}),i(v.Controller,{name:`regressions.${n}.plot.lineStyle.width`,control:t,render:({field:l})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...l})})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`regressions.${n}.plot.color`,control:t,render:({field:l})=>i(Pe,{...l})})]}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(n),sx:{top:15,right:5},children:"Delete this Regression Line"})]},n)}function Ip({control:t,watch:e}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"regressions"}),o=e("regressions"),l=n.map((f,h)=>({...f,...o[h]})),c=e("y_axes"),u=y.useMemo(()=>c.map(({name:f},h)=>({label:f,value:h.toString()})),[c]),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(I.Plus,{size:18,color:"#228be6"})})]}),l.map((f,h)=>i(s.Tabs.Panel,{value:h.toString(),children:i(Dp,{regressionItem:f,control:t,index:h,remove:a,yAxisOptions:u},h)},h))]})}const $r={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
|
|
182
|
-
`)}},Mp=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function Ep({control:t,index:e,seriesItem:n}){const r=!!n.barWidth.trim();return p(N,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.stack`,control:t,render:({field:a})=>i(s.TextInput,{label:"Stack",placeholder:"Stack bars by this ID",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.barGap`,control:t,render:({field:a})=>i(s.Select,{label:"Bar Gap",data:Mp,sx:{flexGrow:1},...a})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.barMinWidth`,control:t,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Min)",disabled:r,sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.barWidth`,control:t,render:({field:a})=>i(s.TextInput,{label:"Bar Width",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.barMaxWidth`,control:t,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Max)",disabled:r,sx:{flexGrow:1},...a})})]})]})}const Ap=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return i(s.Box,{children:i(ze,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},zp=({value:t,onChange:e})=>{const[n,{setTrue:r,setFalse:a}]=J.useBoolean(),[o,l]=y.useState(t),c=()=>{a();const{type:h,func_content:g}=o,m={type:h,func_content:g};l(m),e(m)},u=()=>{a(),l(t)},d=h=>{l(g=>({...g,func_content:h}))},f=()=>{d($r.dynamic.func_content)};return p(N,{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(Ap,{value:o.func_content,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:u,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:c,children:"OK"})]})]})]})})]})},$p=({value:t,onChange:e})=>t.type!=="dynamic"?null:i(zp,{value:t,onChange:e}),Lp=({value:t,onChange:e})=>{if(t.type!=="static")return null;const n=r=>{e({...t,size:r})};return i(N,{children:i(s.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:t.size,onChange:n})})},Op=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Is=y.forwardRef(({label:t="Size",value:e,onChange:n},r)=>{const a=o=>{n({...$r[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:t,data:Op,value:e.type,onChange:a,sx:{flexGrow:1}}),i(Lp,{value:e,onChange:n}),i($p,{value:e,onChange:n})]})}),Pp=[{label:"off",value:"false"},{label:"start",value:"start"},{label:"middle",value:"middle"},{label:"end",value:"end"}],Bp=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function Vp({control:t,index:e,seriesItem:n}){const r=n.showSymbol;return p(N,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Line Settings",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`series.${e}.lineStyle.type`,control:t,render:({field:a})=>i(s.Select,{label:"Line Type",data:Bp,sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.lineStyle.width`,control:t,render:({field:a})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...a})})]}),p(s.Group,{grow:!0,align:"center",children:[i(v.Controller,{name:`series.${e}.step`,control:t,render:({field:a})=>i(s.Select,{label:"Step",data:Pp,sx:{flexGrow:1,maxWidth:"48%"},...a,value:String(a.value),onChange:o=>{const l=o==="false"?!1:o;a.onChange(l)}})}),p(s.Stack,{children:[i(v.Controller,{name:`series.${e}.smooth`,control:t,render:({field:a})=>i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Smooth Line",checked:a.value,onChange:o=>a.onChange(o.currentTarget.checked)})})}),i(v.Controller,{name:`series.${e}.display_name_on_line`,control:t,render:({field:a})=>i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Display Name on Line",checked:a.value??!1,onChange:o=>a.onChange(o.currentTarget.checked)})})})]})]}),p(s.Stack,{children:[i(v.Controller,{name:`series.${e}.showSymbol`,control:t,render:({field:a})=>i(s.Box,{mt:10,mb:-10,sx:{flexGrow:1},children:i(s.Switch,{label:"Show Symbol on Line",checked:a.value,onChange:o=>a.onChange(o.currentTarget.checked)})})}),r&&i(v.Controller,{name:`series.${e}.symbolSize`,control:t,render:({field:a})=>i(Is,{label:"Symbol Size",...a})})]})]})}function Np({control:t,index:e}){return i(v.Controller,{name:`series.${e}.symbolSize`,control:t,render:({field:n})=>i(Is,{label:"Size",...n})})}const qp=[{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 Fp({control:t,index:e,remove:n,seriesItem:r,yAxisOptions:a}){const o=r.type;return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[i(s.Stack,{children:i(v.Controller,{name:`series.${e}.type`,control:t,render:({field:l})=>i(s.SegmentedControl,{data:[{label:"Line",value:"line"},{label:"Bar",value:"bar"},{label:"Scatter",value:"scatter"}],...l})})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.name`,control:t,render:({field:l})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`series.${e}.yAxisIndex`,control:t,render:({field:{value:l,onChange:c,...u}})=>i(s.Select,{label:"Y Axis",data:a,disabled:a.length===0,...u,value:(l==null?void 0:l.toString())??"",onChange:d=>{if(!d){c(0);return}c(Number(d))},sx:{flex:1}})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.y_axis_data_key`,control:t,render:({field:l})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`series.${e}.aggregation_on_value`,control:t,render:({field:l})=>i(Sn,{label:"Aggregation on Value",value:l.value??Ot,onChange:l.onChange,pt:0})})]}),i(s.Group,{grow:!0,children:i(v.Controller,{name:`series.${e}.group_by_key`,control:t,render:({field:l})=>i(j,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...l})})}),o==="line"&&i(Vp,{index:e,control:t,seriesItem:r}),o==="bar"&&i(Ep,{index:e,control:t,seriesItem:r}),o==="scatter"&&i(Np,{index:e,control:t}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),i(v.Controller,{name:`series.${e}.label_position`,control:t,render:({field:l})=>i(s.Select,{label:"Label Position",data:qp,...l})}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`series.${e}.color`,control:t,render:({field:l})=>i(Pe,{...l})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`series.${e}.hide_in_legend`,control:t,render:({field:l})=>i(s.Checkbox,{label:"Hide in legend",checked:l.value,onChange:c=>l.onChange(c.currentTarget.checked)})}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Series"})]},e)}function Gp({control:t,watch:e}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"series"}),o=e("series"),l=n.map((f,h)=>({...f,...o[h]})),c=()=>{const f={type:"bar",name:Ie.randomId(),showSymbol:!1,symbolSize:$r.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)},u=e("y_axes"),d=y.useMemo(()=>u.map(({name:f},h)=>({label:f,value:h.toString()})),[u]);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:c,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((f,h)=>i(s.Tabs.Panel,{value:h.toString(),children:i(Fp,{control:t,index:h,remove:a,seriesItem:f,yAxisOptions:d},f.id)},f.id))]})}function Wp({control:t,watch:e}){return e("stats"),i(s.Stack,{children:p(s.Stack,{spacing:0,children:[i(v.Controller,{name:"stats.templates.top",control:t,render:({field:n})=>i(Xt,{label:"Template for stats above the chart",py:"md",sx:{flexGrow:1},...n})}),i(v.Controller,{name:"stats.templates.bottom",control:t,render:({field:n})=>i(Xt,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const Rp=()=>p(s.Group,{sx:{display:"inline-flex"},spacing:6,mr:14,children:[i(s.Text,{children:"X Axis Data Type"}),p(s.HoverCard,{width:340,shadow:"md",position:"top",children:[i(s.HoverCard.Target,{children:i(s.ActionIcon,{size:"xs",sx:{transform:"none !important"},children:i(L.IconInfoCircle,{})})}),i(s.HoverCard.Dropdown,{children:p(s.Text,{size:"sm",children:["Click",i(s.Anchor,{href:"https://echarts.apache.org/en/option.html#xAxis.type",target:"_blank",mx:4,children:"here"}),"to learn more about these options"]})})]})]}),jp=[{label:"Value",value:"value"},{label:"Category",value:"category"},{label:"Time",value:"time"},{label:"Log",value:"log"}];function Yp({control:t,watch:e}){return e(["x_axis_data_key","x_axis_name","x_axis"]),p(s.Stack,{children:[i(v.Controller,{name:"x_axis_name",control:t,render:({field:n})=>i(s.TextInput,{label:"X Axis Name",sx:{flex:1},...n})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis_data_key",control:t,render:({field:n})=>i(j,{label:"X Axis Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.type",control:t,render:({field:n})=>i(s.Select,{label:i(Rp,{}),required:!0,data:jp,sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Dn,{...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>i(gt,{...n})})]})}const Qp=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],Kp=[{label:"left",value:"left"},{label:"right",value:"right"}];function Up({control:t,index:e,remove:n}){return p(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[i(s.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`y_axes.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`y_axes.${e}.nameAlignment`,control:t,render:({field:r})=>i(s.Select,{label:"Align",required:!0,data:Qp,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`y_axes.${e}.position`,control:t,render:({field:r})=>i(s.Select,{label:"Position",required:!0,data:Kp,sx:{flex:1},...r})})}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:`y_axes.${e}.label_formatter`,control:t,render:({field:r})=>i(Je,{...r})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`y_axes.${e}.min`,control:t,render:({field:r})=>i(s.TextInput,{label:"Min",...r})}),i(v.Controller,{name:`y_axes.${e}.max`,control:t,render:({field:r})=>i(s.TextInput,{label:"Max",...r})})]})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`y_axes.${e}.show`,control:t,render:({field:r})=>i(s.Checkbox,{label:"Visible",checked:r.value,onChange:a=>r.onChange(a.currentTarget.checked)})}),i(s.Button,{mt:20,leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),disabled:e===0,children:"Delete this YAxis"})]})}function Xp({control:t,watch:e}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"y_axes"}),o=e("y_axes"),l=n.map((u,d)=>({...u,...o[d]})),c=()=>r({name:"",position:"left",nameAlignment:"left",label_formatter:$e,min:"",max:"",show:!0});return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[l.map((u,d)=>i(s.Tabs.Tab,{value:d.toString(),children:d+1},d)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((u,d)=>i(s.Tabs.Panel,{value:d.toString(),children:i(Up,{control:t,index:d,remove:a})},d))]})}function Jp({context:t}){const{value:e,set:n}=R(t.instanceData,"config"),{variables:r}=t,a=y.useMemo(()=>x.defaultsDeep({},e,Mr),[e]),{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=u(),h=y.useMemo(()=>!x.isEqual(f,a),[f,a]);return c(["dataZoom"]),i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(I.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"Series",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axes",children:"Y Axes"}),i(s.Tabs.Tab,{value:"Series",children:"Series"}),i(s.Tabs.Tab,{value:"Regression Lines",children:"Regression Lines"}),i(s.Tabs.Tab,{value:"Stats",children:"Stats"}),i(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"}),i(s.Tabs.Tab,{value:"Reference Areas",children:"Reference Areas"}),i(s.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(Yp,{control:o,watch:c})}),i(s.Tabs.Panel,{value:"Y Axes",children:i(Xp,{control:o,watch:c})}),i(s.Tabs.Panel,{value:"Series",children:i(Gp,{control:o,watch:c})}),i(s.Tabs.Panel,{value:"Regression Lines",children:i(Ip,{control:o,watch:c})}),i(s.Tabs.Panel,{value:"Stats",children:i(Wp,{control:o,watch:c})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(_p,{variables:r,control:o,watch:c})}),i(s.Tabs.Panel,{value:"Reference Areas",children:i(xp,{variables:r,control:o,watch:c})}),i(s.Tabs.Panel,{value:"Zooming",children:i(v.Controller,{name:"dataZoom",control:o,render:({field:g})=>i(zr,{...g})})})]})]})})}function Zp(t){const e=x.cloneDeep(x.omit(t,"variables"));return e.stats=x.omit(e.stats,"variables"),e}function Hp(t){const{rotate:e,formatter:n=tt}=t.x_axis.axisLabel;return{...t,x_axis:{...t.x_axis,axisLabel:{rotate:e,formatter:n}}}}function eh(t){const{dataZoom:e=Bt,...n}=t;return{...n,dataZoom:e}}function th(t){const e={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return x.defaultsDeep(e,t)}function nh(t){const e=t.reference_lines.map(n=>{const{lineStyle:r={type:"dashed",width:1,color:at.random().css()},show_in_legend:a=!1}=n;return{...n,lineStyle:r,show_in_legend:a}});return{...t,reference_lines:e}}function rh(t){const e=t.reference_lines.map(n=>{const{yAxisIndex:r=0}=n;return{...n,yAxisIndex:r}});return{...t,reference_lines:e}}function ih(t){const e=t.series.map(n=>{const{aggregation_on_group:r=Ot}=n;return{...n,aggregation_on_group:r}});return{...t,series:e}}function ah(t){const e=t.series.map(n=>{const{aggregation_on_value:r=Ot}=n;return{...n,aggregation_on_value:r}});return{...t,series:e}}function sh(t){delete t.config;const{x_axis:e,tooltip:n}=t.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:e,in_tooltip:n}}}};return x.defaultsDeep(r,t)}function oh(t){const{series:e,...n}=t;return{...n,series:e.map(r=>{const{barMinWidth:a,barWidth:o,barMaxWidth:l}=r;return a?{...r,barMinWidth:a,barWidth:"",barMaxWidth:l??o}:{...r,barMinWidth:"",barWidth:o,barMaxWidth:""}})}}function lh(t){const{y_axes:e,...n}=t;return{...n,y_axes:e.map(r=>{const{min:a="",max:o=""}=r;return{...r,min:a,max:o}})}}function ch(t){const{y_axes:e,...n}=t;return{...n,y_axes:e.map(r=>{const{nameAlignment:a="left"}=r;return{...r,nameAlignment:a}})}}function uh(t){const{y_axes:e,...n}=t;return{...n,y_axes:e.map(r=>{const{show:a=!0}=r;return{...r,show:a}})}}function dh(t){const{regressions:e,...n}=t;return{...n,regressions:e.map(r=>{const{group_by_key:a=""}=r;return{...r,group_by_key:a}})}}function ph(t){const{series:e,y_axes:n,...r}=t;return{...r,series:e.map(a=>{const{hide_in_legend:o=!1,aggregation_on_value:l=Ot}=a;return{...a,hide_in_legend:o,aggregation_on_value:l}}),y_axes:n.map(a=>{const{min:o="",max:l="",show:c=!0}=a;return{...a,min:o,max:l,show:c}})}}function hh(t){const{type:e="category",...n}=t.x_axis;return{...t,x_axis:{...n,type:e}}}function fh(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis_data_key:a,series:o,regressions:l,...c}=t;return{...c,x_axis_data_key:r(a),series:o.map(u=>({...u,y_axis_data_key:r(u.y_axis_data_key),group_by_key:r(u.group_by_key)})),regressions:l.map(u=>({...u,y_axis_data_key:r(u.y_axis_data_key),group_by_key:r(u.group_by_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class gh extends ve{constructor(){super(...arguments);V(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(c=>{r.variables.find(u=>u.name===c.name)||r.addVariable(c)}),(x.get(a,"stats.variables")||[]).forEach(c=>{r.variables.find(u=>u.name===c.name)||r.addVariable(c)}),{...n,version:2,config:Zp(a)}}),this.version(3,n=>({...n,version:3,config:Hp(n.config)})),this.version(4,n=>({...n,version:4,config:eh(n.config)})),this.version(5,n=>({...n,version:5,config:th(n.config)})),this.version(6,n=>({...n,version:6,config:nh(n.config)})),this.version(7,n=>({...n,version:7,config:rh(n.config)})),this.version(8,n=>({...n,version:8,config:ih(n.config)})),this.version(9,n=>({...n,version:9,config:ah(n.config)})),this.version(10,n=>({...n,version:10,config:sh(n.config)})),this.version(11,n=>({...n,version:11,config:oh(n.config)})),this.version(12,n=>({...n,version:12,config:lh(n.config)})),this.version(13,n=>({...n,version:13,config:ch(n.config)})),this.version(14,n=>({...n,version:14,config:uh(n.config)})),this.version(15,n=>({...n,version:15,config:dh(n.config)})),this.version(16,n=>({...n,version:16,config:ph(n.config)})),this.version(17,n=>({...n,version:17,config:hh(n.config)})),this.version(18,(n,r)=>({...n,version:18,config:fh(n.config,r)}))}}const mh={displayName:"Cartesian Chart",displayGroup:"ECharts-based charts",migrator:new gh,name:"cartesian",viewRender:mp,configRender:Jp,createConfig(){return{version:18,config:x.cloneDeep(Mr)}},triggers:[Ir]};function yh(t){if(t.enable_value)return t.value}function bh(t){if(t.enable_value)return t.value}function vh(t){const e=t.axisLabel.overflow.on_axis.width,n=t.axisLabel.position,r={top:5,left:5,right:5,bottom:5};return t.orient==="vertical"&&x.get(r,n)&&n===t.funnelAlign&&x.set(r,n,e),r}function xh(t,e){return t.series.map(n=>{const{level_name_data_key:r,level_value_data_key:a,axisLabel:o,min:l,max:c,funnelAlign:u,orient:d,...f}=n;if(!r||!a)return{};const h=q(r),g=q(a),m=e[h.queryID].map(w=>({name:w[h.columnKey],value:w[g.columnKey]})),C=lt(o.overflow.on_axis);return{type:"funnel",...vh(n),min:yh(l),max:bh(c),minSize:l.size,maxSize:c.size,...f,label:{show:!0,position:o.position,...C},orient:d,funnelAlign:d==="horizontal"?"center":u,data:m}})}function wh({conf:t,params:e,max:n}){const{name:r,value:a}=e.data,o=te(a/n).format({output:"percent",mantissa:2,trimMantissa:!0});return[{label:`${e.marker} ${r}`,value:`${a} (${o})`,style:{label:"",value:""}}]}function Ch(t,e){var o;const n=q(t.series[0].level_name_data_key),r=q(t.series[0].level_value_data_key),a=(o=x.maxBy(e[n.queryID],r.columnKey))==null?void 0:o[r.columnKey];return l=>{const u=wh({conf:t,params:l,max:a}).map(f=>`
|
|
181
|
+
`}}}function cp(t){return t.y_axes.reduce((n,{label_formatter:r},a)=>(n[a]=function(l){let u=l;if(typeof l=="object"&&(Array.isArray(l.value)&&l.value.length===2?u=l.value[1]:u=l.value),!r)return u;try{return te(u).format(r)}catch(c){return console.error(c),u}},n),{default:({value:n})=>n})}function dp(t,e){const n={};return e.map(r=>{const a=Pt(r,t);n[r.name]=ut(r,a)}),n}function pp(t,e){const{overflow:n,...r}=t.x_axis.axisLabel,a=lt(n.on_axis);return[{data:e,name:t.x_axis_name??"",id:"main-x-axis",axisTick:{show:!0,alignWithLabel:!0},type:t.x_axis.type,axisLabel:{...r,...a,formatter:Lt(r.formatter)}}]}function hp(t,e){return t.y_axes.map(({nameAlignment:n,min:r,max:a,show:o,...l},u)=>{let c=l.position;return c||(c=u>0?"right":"left"),{...l,show:o,min:r||void 0,max:a||void 0,position:c,axisLabel:{show:o,formatter:e[u]??e.default},axisLine:{show:o},nameTextStyle:{fontWeight:"bold",align:n},nameLocation:"end",nameGap:o?15:0,splitLine:{show:!1}}})}const fp={xAxis:[{type:"category",nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0}}]};function gp(t,e,n){const r=dp(e,n),a=cp(t),o=x.uniq(ot(e,t.x_axis_data_key)),l=op(t,o,e,a,n,r),u=Zd(t,e),c={xAxis:pp(t,o),yAxis:hp(t,a),series:[...l,...u],tooltip:up(t,l,a),grid:Qd(t),legend:Xd(l),dataZoom:Er(t.dataZoom)};return x.defaultsDeep({},c,fp)}function Ts(t){const e=t.getModel(),n=e.getSeries().map(r=>{if(!r.option.custom)return r.option;const a=e.getColorFromPalette(r.option.custom.targetSeries,null);return r.option.color=a,r.option});t.setOption({...t.getOption(),series:n})}ue.use([G.DataZoomComponent,he.BarChart,he.LineChart,he.ScatterChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer,G.MarkLineComponent,G.MarkAreaComponent]);function Ds(t){return t.trim().length>0}function mp({conf:t,data:e,width:n,height:r,interactionManager:a,variables:o}){const l=yt(e,t.x_axis_data_key),u=He(a.triggerManager,Ir.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(()=>gp(t,e,o),[t,e]),f=y.useRef(),p=y.useMemo(()=>({click:c}),[c]),g=m=>{f.current=m,Ts(m)};return y.useEffect(()=>{f.current&&Ts(f.current)},[d]),!n||!r?null:i(Ne,{echarts:ue,option:d,style:{width:n,height:r},onEvents:p,onChartReady:g,notMerge:!0,theme:"merico-light"})}function yp({context:t,instance:e}){const n=et({vizManager:t.vizManager,instance:e}),{value:r}=R(t.instanceData,"config"),{variables:a}=t,o=y.useMemo(()=>x.defaults({},r,Mr),[r]),l=t.data,{width:u,height:c}=t.viewport,{ref:d,height:f}=Ie.useElementSize(),{ref:p,height:g}=Ie.useElementSize(),m=y.useMemo(()=>{const{stats:{templates:w}}=o;return{top:Jt(w.top,a,l),bottom:Jt(w.bottom,a,l)}},[o,l]),C=Math.max(0,c-f-g);return h(s.Box,{children:[i(s.Text,{ref:d,align:"left",size:"xs",pl:"sm",sx:{display:Ds(o.stats.templates.top)?"block":"none"},children:Object.values(m.top).map((w,_)=>i(y.Fragment,{children:w},_))}),i(mp,{variables:a,width:u,height:C,data:l,conf:o,interactionManager:n}),i(s.Text,{ref:p,align:"left",size:"xs",pl:"sm",sx:{display:Ds(o.stats.templates.bottom)?"block":"none"},children:Object.values(m.bottom).map((w,_)=>i(y.Fragment,{children:w},_))})]})}const zr=y.forwardRef(({value:t,onChange:e},n)=>{const r=a=>o=>{e({...t,[a]:o})};return h(s.Stack,{children:[i(s.Divider,{variant:"dashed",label:"Scroll to Zoom",labelPosition:"center"}),h(s.Group,{children:[i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Enable on X Axis",checked:t.x_axis_scroll,onChange:a=>r("x_axis_scroll")(a.currentTarget.checked)})}),i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Enable on Y Axis",checked:t.y_axis_scroll,onChange:a=>r("y_axis_scroll")(a.currentTarget.checked)})})]}),i(s.Divider,{variant:"dashed",label:"Slider for Zooming",labelPosition:"center"}),h(s.Group,{children:[i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Slider for X Axis",checked:t.x_axis_slider,onChange:a=>r("x_axis_slider")(a.currentTarget.checked)})}),i(s.Tooltip,{label:"Not available for now, will overlap y-axis's label",children:i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Slider for Y Axis",disabled:!t.y_axis_slider,checked:t.y_axis_slider,onChange:a=>r("y_axis_slider")(a.currentTarget.checked)})})})]})]})}),bp=[{label:"Rectangle",value:"rectangle"}],vp=[{label:"Horizontal",value:"horizontal"}];function xp({control:t,index:e,remove:n,variableOptions:r}){return h(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_areas.${e}.name`,control:t,render:({field:a})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_areas.${e}.color`,control:t,render:({field:a})=>i(s.TextInput,{label:"Color",required:!0,sx:{flex:1},...a})})]}),h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_areas.${e}.type`,control:t,render:({field:a})=>i(s.Select,{label:"Type",required:!0,data:bp,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_areas.${e}.direction`,control:t,render:({field:a})=>i(s.Select,{label:"Direction",required:!0,data:vp,sx:{flex:1},...a})})]}),i(s.Divider,{variant:"dashed",label:"Data",labelPosition:"center"}),h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_areas.${e}.y_keys.upper`,control:t,render:({field:a})=>i(s.Select,{label:"Upper Boundary",required:!0,data:r,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_areas.${e}.y_keys.lower`,control:t,render:({field:a})=>i(s.Select,{label:"Lower Boundary",required:!0,data:r,sx:{flex:1},...a})})]}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Reference Area"})]},e)}function wp({control:t,watch:e,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:t,name:"reference_areas"}),l=e("reference_areas"),u=r.map((f,p)=>({...f,...l[p]})),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 h(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"6px 0px 0px"}},children:[h(s.Tabs.List,{children:[u.map((f,p)=>i(s.Tabs.Tab,{value:p.toString(),children:p+1},p)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),u.map((f,p)=>i(s.Tabs.Panel,{value:p.toString(),children:i(xp,{control:t,index:p,remove:o,variableOptions:d})},p))]})}const Cp=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Sp=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function _p({control:t,index:e,remove:n,watch:r,variableOptions:a,yAxisOptions:o}){const l=r(`reference_lines.${e}.orientation`);return h(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${e}.name`,control:t,render:({field:u})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),i(v.Controller,{name:`reference_lines.${e}.variable_key`,control:t,render:({field:u})=>i(s.Select,{label:"Value",required:!0,data:a,sx:{flex:1},...u})})]}),i(v.Controller,{name:`reference_lines.${e}.template`,control:t,render:({field:u})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...u})}),h(s.Group,{grow:!0,children:[h(s.Stack,{children:[i(v.Controller,{name:`reference_lines.${e}.orientation`,control:t,render:({field:u})=>i(s.Select,{label:"Orientation",data:Sp,required:!0,sx:{flex:1},...u})}),l==="vertical"&&i(s.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&i(v.Controller,{name:`reference_lines.${e}.yAxisIndex`,control:t,render:({field:{value:u,onChange:c,...d}})=>i(s.Select,{label:"Y Axis",data:o,disabled:o.length===0,...d,value:(u==null?void 0:u.toString())??"",onChange:f=>{if(!f){c(0);return}c(Number(f))},sx:{flex:1}})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),h(s.Group,{grow:!0,children:[i(v.Controller,{name:`reference_lines.${e}.lineStyle.type`,control:t,render:({field:u})=>i(s.Select,{label:"Line Type",data:Cp,sx:{flexGrow:1},...u})}),i(v.Controller,{name:`reference_lines.${e}.lineStyle.width`,control:t,render:({field:u})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...u})})]}),h(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`reference_lines.${e}.lineStyle.color`,control:t,render:({field:u})=>i(Pe,{...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`reference_lines.${e}.show_in_legend`,control:t,render:({field:u})=>i(s.Checkbox,{label:"Show in legend",checked:u.value,onChange:c=>u.onChange(c.currentTarget.checked)})}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Reference Line"})]},e)}function kp({control:t,watch:e,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:t,name:"reference_lines"}),l=e("reference_lines"),u=r.map((g,m)=>({...g,...l[m]})),c=()=>{a({name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,yAxisIndex:0})},d=y.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=e("y_axes"),p=y.useMemo(()=>f.map(({name:g},m)=>({label:g,value:m.toString()})),[f]);return h(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[h(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(I.Plus,{size:18,color:"#228be6"})})]}),u.map((g,m)=>i(s.Tabs.Panel,{value:m.toString(),children:i(_p,{control:t,index:m,remove:o,watch:e,variableOptions:d,yAxisOptions:p})},m))]})}const Tp=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}],Dp=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function Ip({control:t,regressionItem:e,index:n,remove:r,yAxisOptions:a}){const o=e.transform.config.method;return h(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[h(s.Group,{grow:!0,children:[i(v.Controller,{name:`regressions.${n}.name`,control:t,render:({field:l})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`regressions.${n}.group_by_key`,control:t,render:({field:l})=>i(j,{label:"Split into multiple regression lines by this key...",clearable:!0,sx:{flex:1},...l})})]}),h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`regressions.${n}.y_axis_data_key`,control:t,render:({field:l})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`regressions.${n}.plot.yAxisIndex`,control:t,render:({field:{value:l,onChange:u,...c}})=>i(s.Select,{label:"Y Axis",data:a,disabled:a.length===0,...c,value:(l==null?void 0:l.toString())??"",onChange:d=>{if(!d){u(0);return}u(Number(d))},sx:{flex:1}})})]}),h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`regressions.${n}.transform.config.method`,control:t,render:({field:l})=>i(s.Select,{label:"Method",data:Tp,sx:{flex:1},...l})}),o==="polynomial"&&i(v.Controller,{name:`regressions.${n}.transform.config.order`,control:t,render:({field:l})=>i(s.NumberInput,{label:"Order",sx:{flex:1},...l})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Line Style",labelPosition:"center"}),h(s.Group,{grow:!0,children:[i(v.Controller,{name:`regressions.${n}.plot.lineStyle.type`,control:t,render:({field:l})=>i(s.Select,{label:"Line Type",data:Dp,sx:{flexGrow:1},...l})}),i(v.Controller,{name:`regressions.${n}.plot.lineStyle.width`,control:t,render:({field:l})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...l})})]}),h(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`regressions.${n}.plot.color`,control:t,render:({field:l})=>i(Pe,{...l})})]}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(n),sx:{top:15,right:5},children:"Delete this Regression Line"})]},n)}function Mp({control:t,watch:e}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"regressions"}),o=e("regressions"),l=n.map((f,p)=>({...f,...o[p]})),u=e("y_axes"),c=y.useMemo(()=>u.map(({name:f},p)=>({label:f,value:p.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 h(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[h(s.Tabs.List,{children:[l.map((f,p)=>i(s.Tabs.Tab,{value:p.toString(),children:p+1},p)),i(s.Tabs.Tab,{onClick:d,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((f,p)=>i(s.Tabs.Panel,{value:p.toString(),children:i(Ip,{regressionItem:f,control:t,index:p,remove:a,yAxisOptions:c},p)},p))]})}const $r={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
|
|
182
|
+
`)}},Ep=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function Ap({control:t,index:e,seriesItem:n}){const r=!!n.barWidth.trim();return h(N,{children:[h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.stack`,control:t,render:({field:a})=>i(s.TextInput,{label:"Stack",placeholder:"Stack bars by this ID",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.barGap`,control:t,render:({field:a})=>i(s.Select,{label:"Bar Gap",data:Ep,sx:{flexGrow:1},...a})})]}),h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.barMinWidth`,control:t,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Min)",disabled:r,sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.barWidth`,control:t,render:({field:a})=>i(s.TextInput,{label:"Bar Width",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.barMaxWidth`,control:t,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Max)",disabled:r,sx:{flexGrow:1},...a})})]})]})}const zp=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return i(s.Box,{children:i(ze,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},$p=({value:t,onChange:e})=>{const[n,{setTrue:r,setFalse:a}]=J.useBoolean(),[o,l]=y.useState(t),u=()=>{a();const{type:p,func_content:g}=o,m={type:p,func_content:g};l(m),e(m)},c=()=>{a(),l(t)},d=p=>{l(g=>({...g,func_content:p}))},f=()=>{d($r.dynamic.func_content)};return h(N,{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&&h(s.Stack,{children:[i(s.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),i(zp,{value:o.func_content,onChange:d}),h(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Rest"}),h(s.Group,{position:"right",children:[i(s.Button,{onClick:c,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:u,children:"OK"})]})]})]})})]})},Lp=({value:t,onChange:e})=>t.type!=="dynamic"?null:i($p,{value:t,onChange:e}),Op=({value:t,onChange:e})=>{if(t.type!=="static")return null;const n=r=>{e({...t,size:r})};return i(N,{children:i(s.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:t.size,onChange:n})})},Pp=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Is=y.forwardRef(({label:t="Size",value:e,onChange:n},r)=>{const a=o=>{n({...$r[o]})};return h(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:t,data:Pp,value:e.type,onChange:a,sx:{flexGrow:1}}),i(Op,{value:e,onChange:n}),i(Lp,{value:e,onChange:n})]})}),Bp=[{label:"off",value:"false"},{label:"start",value:"start"},{label:"middle",value:"middle"},{label:"end",value:"end"}],Vp=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function Np({control:t,index:e,seriesItem:n}){const r=n.showSymbol;return h(N,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Line Settings",labelPosition:"center"}),h(s.Group,{grow:!0,children:[i(v.Controller,{name:`series.${e}.lineStyle.type`,control:t,render:({field:a})=>i(s.Select,{label:"Line Type",data:Vp,sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.lineStyle.width`,control:t,render:({field:a})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...a})})]}),h(s.Group,{grow:!0,align:"center",children:[i(v.Controller,{name:`series.${e}.step`,control:t,render:({field:a})=>i(s.Select,{label:"Step",data:Bp,sx:{flexGrow:1,maxWidth:"48%"},...a,value:String(a.value),onChange:o=>{const l=o==="false"?!1:o;a.onChange(l)}})}),h(s.Stack,{children:[i(v.Controller,{name:`series.${e}.smooth`,control:t,render:({field:a})=>i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Smooth Line",checked:a.value,onChange:o=>a.onChange(o.currentTarget.checked)})})}),i(v.Controller,{name:`series.${e}.display_name_on_line`,control:t,render:({field:a})=>i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Display Name on Line",checked:a.value??!1,onChange:o=>a.onChange(o.currentTarget.checked)})})})]})]}),h(s.Stack,{children:[i(v.Controller,{name:`series.${e}.showSymbol`,control:t,render:({field:a})=>i(s.Box,{mt:10,mb:-10,sx:{flexGrow:1},children:i(s.Switch,{label:"Show Symbol on Line",checked:a.value,onChange:o=>a.onChange(o.currentTarget.checked)})})}),r&&i(v.Controller,{name:`series.${e}.symbolSize`,control:t,render:({field:a})=>i(Is,{label:"Symbol Size",...a})})]})]})}function qp({control:t,index:e}){return i(v.Controller,{name:`series.${e}.symbolSize`,control:t,render:({field:n})=>i(Is,{label:"Size",...n})})}const Fp=[{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 Gp({control:t,index:e,remove:n,seriesItem:r,yAxisOptions:a}){const o=r.type;return h(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[i(s.Stack,{children:i(v.Controller,{name:`series.${e}.type`,control:t,render:({field:l})=>i(s.SegmentedControl,{data:[{label:"Line",value:"line"},{label:"Bar",value:"bar"},{label:"Scatter",value:"scatter"}],...l})})}),h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.name`,control:t,render:({field:l})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`series.${e}.yAxisIndex`,control:t,render:({field:{value:l,onChange:u,...c}})=>i(s.Select,{label:"Y Axis",data:a,disabled:a.length===0,...c,value:(l==null?void 0:l.toString())??"",onChange:d=>{if(!d){u(0);return}u(Number(d))},sx:{flex:1}})})]}),h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.y_axis_data_key`,control:t,render:({field:l})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`series.${e}.aggregation_on_value`,control:t,render:({field:l})=>i(Sn,{label:"Aggregation on Value",value:l.value??Ot,onChange:l.onChange,pt:0})})]}),i(s.Group,{grow:!0,children:i(v.Controller,{name:`series.${e}.group_by_key`,control:t,render:({field:l})=>i(j,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...l})})}),o==="line"&&i(Np,{index:e,control:t,seriesItem:r}),o==="bar"&&i(Ap,{index:e,control:t,seriesItem:r}),o==="scatter"&&i(qp,{index:e,control:t}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),i(v.Controller,{name:`series.${e}.label_position`,control:t,render:({field:l})=>i(s.Select,{label:"Label Position",data:Fp,...l})}),h(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`series.${e}.color`,control:t,render:({field:l})=>i(Pe,{...l})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`series.${e}.hide_in_legend`,control:t,render:({field:l})=>i(s.Checkbox,{label:"Hide in legend",checked:l.value,onChange:u=>l.onChange(u.currentTarget.checked)})}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Series"})]},e)}function Wp({control:t,watch:e}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"series"}),o=e("series"),l=n.map((f,p)=>({...f,...o[p]})),u=()=>{const f={type:"bar",name:Ie.randomId(),showSymbol:!1,symbolSize:$r.static,y_axis_data_key:"value",yAxisIndex:0,label_position:"top",display_name_on_line:!1,stack:"",color:"#000",step:!1,smooth:!1,barMinWidth:"1",barWidth:"10%",barMaxWidth:"10",barGap:"0%",lineStyle:{type:"solid",width:1},hide_in_legend:!1,group_by_key:""};r(f)},c=e("y_axes"),d=y.useMemo(()=>c.map(({name:f},p)=>({label:f,value:p.toString()})),[c]);return h(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[h(s.Tabs.List,{children:[l.map((f,p)=>i(s.Tabs.Tab,{value:p.toString(),children:p+1},f.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((f,p)=>i(s.Tabs.Panel,{value:p.toString(),children:i(Gp,{control:t,index:p,remove:a,seriesItem:f,yAxisOptions:d},f.id)},f.id))]})}function Rp({control:t,watch:e}){return e("stats"),i(s.Stack,{children:h(s.Stack,{spacing:0,children:[i(v.Controller,{name:"stats.templates.top",control:t,render:({field:n})=>i(Xt,{label:"Template for stats above the chart",py:"md",sx:{flexGrow:1},...n})}),i(v.Controller,{name:"stats.templates.bottom",control:t,render:({field:n})=>i(Xt,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const jp=()=>h(s.Group,{sx:{display:"inline-flex"},spacing:6,mr:14,children:[i(s.Text,{children:"X Axis Data Type"}),h(s.HoverCard,{width:340,shadow:"md",position:"top",children:[i(s.HoverCard.Target,{children:i(s.ActionIcon,{size:"xs",sx:{transform:"none !important"},children:i(L.IconInfoCircle,{})})}),i(s.HoverCard.Dropdown,{children:h(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"]})})]})]}),Yp=[{label:"Value",value:"value"},{label:"Category",value:"category"},{label:"Time",value:"time"},{label:"Log",value:"log"}];function Qp({control:t,watch:e}){return e(["x_axis_data_key","x_axis_name","x_axis"]),h(s.Stack,{children:[i(v.Controller,{name:"x_axis_name",control:t,render:({field:n})=>i(s.TextInput,{label:"X Axis Name",sx:{flex:1},...n})}),h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis_data_key",control:t,render:({field:n})=>i(j,{label:"X Axis Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.type",control:t,render:({field:n})=>i(s.Select,{label:i(jp,{}),required:!0,data:Yp,sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Dn,{...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>i(gt,{...n})})]})}const Kp=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],Up=[{label:"left",value:"left"},{label:"right",value:"right"}];function Xp({control:t,index:e,remove:n}){return h(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[i(s.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`y_axes.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`y_axes.${e}.nameAlignment`,control:t,render:({field:r})=>i(s.Select,{label:"Align",required:!0,data:Kp,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`y_axes.${e}.position`,control:t,render:({field:r})=>i(s.Select,{label:"Position",required:!0,data:Up,sx:{flex:1},...r})})}),h(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:`y_axes.${e}.label_formatter`,control:t,render:({field:r})=>i(Je,{...r})})]}),h(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),h(s.Group,{grow:!0,children:[i(v.Controller,{name:`y_axes.${e}.min`,control:t,render:({field:r})=>i(s.TextInput,{label:"Min",...r})}),i(v.Controller,{name:`y_axes.${e}.max`,control:t,render:({field:r})=>i(s.TextInput,{label:"Max",...r})})]})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`y_axes.${e}.show`,control:t,render:({field:r})=>i(s.Checkbox,{label:"Visible",checked:r.value,onChange:a=>r.onChange(a.currentTarget.checked)})}),i(s.Button,{mt:20,leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),disabled:e===0,children:"Delete this YAxis"})]})}function Jp({control:t,watch:e}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"y_axes"}),o=e("y_axes"),l=n.map((c,d)=>({...c,...o[d]})),u=()=>r({name:"",position:"left",nameAlignment:"left",label_formatter:$e,min:"",max:"",show:!0});return h(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[h(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(I.Plus,{size:18,color:"#228be6"})})]}),l.map((c,d)=>i(s.Tabs.Panel,{value:d.toString(),children:i(Xp,{control:t,index:d,remove:a})},d))]})}function Zp({context:t}){const{value:e,set:n}=R(t.instanceData,"config"),{variables:r}=t,a=y.useMemo(()=>x.defaultsDeep({},e,Mr),[e]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),p=y.useMemo(()=>!x.isEqual(f,a),[f,a]);return u(["dataZoom"]),i(s.Stack,{spacing:"xs",children:h("form",{onSubmit:l(n),children:[h(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:!p,children:i(I.DeviceFloppy,{size:20})})]}),h(s.Tabs,{defaultValue:"Series",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[h(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(Qp,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axes",children:i(Jp,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Series",children:i(Wp,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Regression Lines",children:i(Mp,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Stats",children:i(Rp,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(kp,{variables:r,control:o,watch:u})}),i(s.Tabs.Panel,{value:"Reference Areas",children:i(wp,{variables:r,control:o,watch:u})}),i(s.Tabs.Panel,{value:"Zooming",children:i(v.Controller,{name:"dataZoom",control:o,render:({field:g})=>i(zr,{...g})})})]})]})})}function Hp(t){const e=x.cloneDeep(x.omit(t,"variables"));return e.stats=x.omit(e.stats,"variables"),e}function eh(t){const{rotate:e,formatter:n=tt}=t.x_axis.axisLabel;return{...t,x_axis:{...t.x_axis,axisLabel:{rotate:e,formatter:n}}}}function th(t){const{dataZoom:e=Bt,...n}=t;return{...n,dataZoom:e}}function nh(t){const e={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return x.defaultsDeep(e,t)}function rh(t){const e=t.reference_lines.map(n=>{const{lineStyle:r={type:"dashed",width:1,color:at.random().css()},show_in_legend:a=!1}=n;return{...n,lineStyle:r,show_in_legend:a}});return{...t,reference_lines:e}}function ih(t){const e=t.reference_lines.map(n=>{const{yAxisIndex:r=0}=n;return{...n,yAxisIndex:r}});return{...t,reference_lines:e}}function ah(t){const e=t.series.map(n=>{const{aggregation_on_group:r=Ot}=n;return{...n,aggregation_on_group:r}});return{...t,series:e}}function sh(t){const e=t.series.map(n=>{const{aggregation_on_value:r=Ot}=n;return{...n,aggregation_on_value:r}});return{...t,series:e}}function oh(t){delete t.config;const{x_axis:e,tooltip:n}=t.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:e,in_tooltip:n}}}};return x.defaultsDeep(r,t)}function lh(t){const{series:e,...n}=t;return{...n,series:e.map(r=>{const{barMinWidth:a,barWidth:o,barMaxWidth:l}=r;return a?{...r,barMinWidth:a,barWidth:"",barMaxWidth:l??o}:{...r,barMinWidth:"",barWidth:o,barMaxWidth:""}})}}function uh(t){const{y_axes:e,...n}=t;return{...n,y_axes:e.map(r=>{const{min:a="",max:o=""}=r;return{...r,min:a,max:o}})}}function ch(t){const{y_axes:e,...n}=t;return{...n,y_axes:e.map(r=>{const{nameAlignment:a="left"}=r;return{...r,nameAlignment:a}})}}function dh(t){const{y_axes:e,...n}=t;return{...n,y_axes:e.map(r=>{const{show:a=!0}=r;return{...r,show:a}})}}function ph(t){const{regressions:e,...n}=t;return{...n,regressions:e.map(r=>{const{group_by_key:a=""}=r;return{...r,group_by_key:a}})}}function hh(t){const{series:e,y_axes:n,...r}=t;return{...r,series:e.map(a=>{const{hide_in_legend:o=!1,aggregation_on_value:l=Ot}=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 fh(t){const{type:e="category",...n}=t.x_axis;return{...t,x_axis:{...n,type:e}}}function gh(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis_data_key:a,series:o,regressions:l,...u}=t;return{...u,x_axis_data_key:r(a),series:o.map(c=>({...c,y_axis_data_key:r(c.y_axis_data_key),group_by_key:r(c.group_by_key)})),regressions:l.map(c=>({...c,y_axis_data_key:r(c.y_axis_data_key),group_by_key:r(c.group_by_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class mh extends ve{constructor(){super(...arguments);V(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:Hp(a)}}),this.version(3,n=>({...n,version:3,config:eh(n.config)})),this.version(4,n=>({...n,version:4,config:th(n.config)})),this.version(5,n=>({...n,version:5,config:nh(n.config)})),this.version(6,n=>({...n,version:6,config:rh(n.config)})),this.version(7,n=>({...n,version:7,config:ih(n.config)})),this.version(8,n=>({...n,version:8,config:ah(n.config)})),this.version(9,n=>({...n,version:9,config:sh(n.config)})),this.version(10,n=>({...n,version:10,config:oh(n.config)})),this.version(11,n=>({...n,version:11,config:lh(n.config)})),this.version(12,n=>({...n,version:12,config:uh(n.config)})),this.version(13,n=>({...n,version:13,config:ch(n.config)})),this.version(14,n=>({...n,version:14,config:dh(n.config)})),this.version(15,n=>({...n,version:15,config:ph(n.config)})),this.version(16,n=>({...n,version:16,config:hh(n.config)})),this.version(17,n=>({...n,version:17,config:fh(n.config)})),this.version(18,(n,r)=>({...n,version:18,config:gh(n.config,r)}))}}const yh={displayName:"Cartesian Chart",displayGroup:"ECharts-based charts",migrator:new mh,name:"cartesian",viewRender:yp,configRender:Zp,createConfig(){return{version:18,config:x.cloneDeep(Mr)}},triggers:[Ir]};function bh(t){if(t.enable_value)return t.value}function vh(t){if(t.enable_value)return t.value}function xh(t){const e=t.axisLabel.overflow.on_axis.width,n=t.axisLabel.position,r={top:5,left:5,right:5,bottom:5};return t.orient==="vertical"&&x.get(r,n)&&n===t.funnelAlign&&x.set(r,n,e),r}function wh(t,e){return t.series.map(n=>{const{level_name_data_key:r,level_value_data_key:a,axisLabel:o,min:l,max:u,funnelAlign:c,orient:d,...f}=n;if(!r||!a)return{};const p=q(r),g=q(a),m=e[p.queryID].map(w=>({name:w[p.columnKey],value:w[g.columnKey]})),C=lt(o.overflow.on_axis);return{type:"funnel",...xh(n),min:bh(l),max:vh(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 Ch({conf:t,params:e,max:n}){const{name:r,value:a}=e.data,o=te(a/n).format({output:"percent",mantissa:2,trimMantissa:!0});return[{label:`${e.marker} ${r}`,value:`${a} (${o})`,style:{label:"",value:""}}]}function Sh(t,e){var o;const n=q(t.series[0].level_name_data_key),r=q(t.series[0].level_value_data_key),a=(o=x.maxBy(e[n.queryID],r.columnKey))==null?void 0:o[r.columnKey];return l=>{const c=Ch({conf:t,params:l,max:a}).map(f=>`
|
|
183
183
|
<tr>
|
|
184
184
|
<th style="text-align: right;">
|
|
185
185
|
<div style="${f.style.label}">${f.label}</div>
|
|
@@ -193,9 +193,9 @@ Check the top-level render call using <`+P+">.")}return A}}function ql(S,A){{if(
|
|
|
193
193
|
${l.seriesName}
|
|
194
194
|
</div>
|
|
195
195
|
<table style="width: auto">
|
|
196
|
-
<tbody>${
|
|
196
|
+
<tbody>${c.join("")}</tbody>
|
|
197
197
|
</table>
|
|
198
|
-
`}}function
|
|
198
|
+
`}}function _h(t,e){return{trigger:"item",confine:!0,formatter:Sh(t,e)}}function kh(t,e){return{grid:{top:0,left:0,right:0,bottom:0},tooltip:_h(t,e),series:wh(t,e)}}function Th(t){return t||(t=Date.now().toString()),{id:t,name:t,level_name_data_key:"",level_value_data_key:"",min:{value:0,enable_value:!1,size:"0%"},max:{value:0,enable_value:!1,size:"100%"},gap:2,axisLabel:{show:!0,position:"inside",overflow:Ze},sort:"descending",orient:"vertical",funnelAlign:"center"}}const Lr={series:[Th("Funnel")]};ue.use([he.FunnelChart,G.DataZoomComponent,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer]);function Dh({conf:t,data:e,width:n,height:r}){const a=y.useMemo(()=>kh(t,e),[t,e]);return!n||!r?null:i(Ne,{echarts:ue,option:a,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})}function Ih({context:t}){const{value:e}=R(t.instanceData,"config"),n=y.useMemo(()=>x.defaults({},e,Lr),[e]),r=t.data,{width:a,height:o}=t.viewport;return i(s.Box,{children:i(Dh,{width:a,height:o,data:r,conf:n})})}const Mh=[{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"}],Or=y.forwardRef(({label:t,value:e,onChange:n,options:r=Mh},a)=>i(s.Select,{ref:a,label:t,data:r,value:e,onChange:n})),Eh=[{label:"Ascending",value:"ascending"},{label:"Descending",value:"descending"},{label:"Use original data order",value:"0"}],Ah=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],zh=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}],$h={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"}]},Lh=({item:t,control:e,index:n,remove:r})=>{const a=t.min.enable_value,o=t.max.enable_value,{orient:l}=t;return h(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`series.${n}.name`,control:e,render:({field:u})=>i(s.TextInput,{label:"Series Name",...u})})}),h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.level_name_data_key`,control:e,render:({field:u})=>i(j,{label:"Level Name Field",...u})}),i(v.Controller,{name:`series.${n}.level_value_data_key`,control:e,render:({field:u})=>i(j,{label:"Level Value Field",...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Funnel Style",labelPosition:"center"}),h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.min.value`,control:e,render:({field:u})=>i(s.NumberInput,{disabled:!a,labelProps:{display:"block"},label:h(s.Group,{position:"apart",pr:6,sx:{width:"100%"},children:[i(s.Text,{children:"Min Value"}),i(s.Tooltip,{label:"Check to enable specific min value",children:i(s.Box,{children:i(v.Controller,{name:`series.${n}.min.enable_value`,control:e,render:({field:c})=>i(s.Checkbox,{size:"xs",checked:c.value,onChange:d=>c.onChange(d.currentTarget.checked)})})})})]}),...u})}),i(v.Controller,{name:`series.${n}.min.size`,control:e,render:({field:u})=>i(s.TextInput,{placeholder:"0%",label:"Min Size",...u})})]}),h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.max.value`,control:e,render:({field:u})=>i(s.NumberInput,{disabled:!o,labelProps:{display:"block"},label:h(s.Group,{position:"apart",pr:6,sx:{width:"100%"},children:[i(s.Text,{children:"Max Value"}),i(s.Tooltip,{label:"Check to enable specific max value",children:i(s.Box,{children:i(v.Controller,{name:`series.${n}.max.enable_value`,control:e,render:({field:c})=>i(s.Checkbox,{size:"xs",checked:c.value,onChange:d=>c.onChange(d.currentTarget.checked)})})})})]}),...u})}),i(v.Controller,{name:`series.${n}.max.size`,control:e,render:({field:u})=>i(s.TextInput,{placeholder:"100%",label:"Max Size",...u})})]}),h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.orient`,control:e,render:({field:u})=>i(s.Select,{label:"Orientation",data:zh,...u})}),i(v.Controller,{name:`series.${n}.sort`,control:e,render:({field:u})=>i(s.Select,{label:"Sort",data:Eh,...u})})]}),h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.funnelAlign`,control:e,render:({field:u})=>i(s.Select,{label:"Align",disabled:l==="horizontal",data:Ah,...u})}),i(v.Controller,{name:`series.${n}.gap`,control:e,render:({field:u})=>i(s.NumberInput,{placeholder:"0, 5, 10...",label:"Gap",...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Label Style",labelPosition:"center"}),h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.axisLabel.position`,control:e,render:({field:u})=>i(Or,{label:"Position",options:$h[l],...u})}),i(s.Box,{})]}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`series.${n}.axisLabel.overflow`,control:e,render:({field:u})=>i(gt,{...u})})})]})},Oh=({control:t,watch:e})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"series"}),o=e("series"),l=n.map((f,p)=>({...f,...o[p]})),u=x.get(l,"0.id"),[c,d]=y.useState(u??null);return y.useEffect(()=>{u&&d(f=>f!==null?f:u)},[u]),h(s.Tabs,{value:c,onTabChange:f=>d(f),styles:{panel:{padding:"0px",paddingTop:"6px"}},children:[h(s.Tabs.List,{children:[l.map((f,p)=>i(s.Tabs.Tab,{value:f.id,children:f.name},f.id)),i(s.Tabs.Tab,{value:"add",disabled:!0,children:i(s.Tooltip,{label:"TODO",children:i(s.Center,{children:i(L.IconPlus,{size:18,color:"#228be6"})})})})]}),l.map((f,p)=>i(s.Tabs.Panel,{value:f.id,children:i(Lh,{item:f,control:t,index:p,remove:a})},f.id))]})};function Ph({context:t}){const{value:e,set:n}=R(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,Lr),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l([]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,r),[d,r]);return i(s.Stack,{spacing:"xs",children:h("form",{onSubmit:o(n),children:[h(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Funnel Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(I.DeviceFloppy,{size:20})})]}),i(Oh,{control:a,watch:l})]})})}function Bh(t){return{series:t.series.map(e=>{const{min:n,minSize:r,max:a,maxSize:o,...l}=e;return{...l,min:{value:n,use_data_min:!1,size:r},max:{value:a,use_data_max:!1,size:o}}})}}function Vh(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=l=>l&&`${n}.${l}`,{series:a,...o}=t;return{...o,series:a.map(l=>({...l,level_name_data_key:r(l.level_name_data_key),level_value_data_key:r(l.level_value_data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class Nh extends ve{constructor(){super(...arguments);V(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:Bh(r)}}),this.version(3,(n,r)=>{const{config:a}=n;return{...n,version:3,config:Vh(a,r)}})}}const qh={displayName:"Funnel Chart",displayGroup:"ECharts-based charts",migrator:new Nh,name:"funnel",viewRender:Ih,configRender:Ph,createConfig:()=>({version:3,config:Lr})};function Ms({enabled:t,func_content:e}){return(n,r)=>{if(!t)return n;try{return new Function(`return ${e}`)()(n,r)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function Fh(t){const e=Ms(t.x_axis.axisLabel.formatter),n=Ms(t.y_axis.axisLabel.formatter);return{x_axis:e,y_axis:n}}function Gh(t){return{heat_block:function(r){if(!t.heat_block.value_formatter)return r;try{return te(r).format(t.heat_block.value_formatter)}catch(a){return console.error(a),r}}}}function Wh(t){let e=0;return t.x_axis.name&&(e+=20),{top:45,left:5,right:5,bottom:e,containLabel:!0}}function Rh(t,e){const{x_axis:n,y_axis:r,heat_block:a}=t,o=q(n.data_key),l=q(r.data_key),u=q(a.data_key),c=e[o.queryID].map(d=>[x.get(d,o.columnKey),x.get(d,l.columnKey),x.get(d,u.columnKey)]);return{type:"heatmap",name:a.name,xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{borderColor:"white",borderWidth:2},data:c,label:a.label,labelLayout:{hideOverlap:!0}}}const jh=t=>{try{return te(t).format({trimMantissa:!0,mantissa:2})}catch{return t}};function Yh({conf:t,labelFormatters:e,valueFormatters:n,dataDict:r,params:a}){const{value:o,dataIndex:l}=a,[u,c,d]=o,f={label:t.x_axis.name?t.x_axis.name:"X Axis",value:e.x_axis(u,l),style:{label:"",value:mt(t.x_axis.axisLabel.overflow.in_tooltip)}},p={label:t.y_axis.name?t.y_axis.name:"Y Axis",value:e.y_axis(c,l),style:{label:"",value:mt(t.y_axis.axisLabel.overflow.in_tooltip)}},g={label:t.heat_block.name,value:n.heat_block(d),style:{label:"",value:""}},m=[f,p,g],C=r[`${u}---${c}`];return C&&t.tooltip.metrics.forEach(w=>{const _=q(w.data_key);m.push({label:w.name,value:jh(x.get(C,_.columnKey,"")),style:{label:"",value:""}})}),m}function Qh(t,e,n,r){const{x_axis:a,y_axis:o,heat_block:l}=t,u=q(a.data_key),c=q(o.data_key);q(l.data_key);const d=x.keyBy(e[u.queryID],f=>`${f[u.columnKey]}---${f[c.columnKey]}`);return{confine:!0,formatter:function(f){const g=Yh({conf:t,labelFormatters:n,valueFormatters:r,dataDict:d,params:f}).map(C=>`
|
|
199
199
|
<tr>
|
|
200
200
|
<th style="text-align: right;">
|
|
201
201
|
<div style="${C.style.label}">${C.label}</div>
|
|
@@ -216,11 +216,11 @@ Check the top-level render call using <`+P+">.")}return A}}function ql(S,A){{if(
|
|
|
216
216
|
</thead>
|
|
217
217
|
<tbody>${g.join("")}</tbody>
|
|
218
218
|
</table>
|
|
219
|
-
`}}}function
|
|
220
|
-
`)},As=y.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:a,setFalse:o}]=J.useBoolean(),[l,
|
|
219
|
+
`}}}function Kh(t){return{min:t.heat_block.min??0,max:t.heat_block.max??100,calculable:!0,orient:"horizontal",left:"center",top:0,itemWidth:15}}function Uh(t,e,n){const r=q(t.x_axis.data_key),a=x.uniq(e[r.queryID].map(c=>c[r.columnKey])),{overflow:o,rotate:l}=t.x_axis.axisLabel,u=lt(o.on_axis);return{id:"main-x-axis",type:"category",data:a,name:t.x_axis.name??"",align:"center",axisTick:{show:!0,alignWithLabel:!0},axisLabel:{rotate:l,...u,formatter:n},splitArea:{show:!0},nameLocation:"center",nameGap:25,nameTextStyle:{fontWeight:"bold",align:"center"},z:1}}function Xh(t,e,n){const r=q(t.x_axis.data_key),a=q(t.y_axis.data_key),{nameAlignment:o,data_key:l,...u}=t.y_axis,c=x.uniq(e[r.queryID].map(g=>g[a.columnKey])),{overflow:d,rotate:f}=t.y_axis.axisLabel,p=lt(d.on_axis);return{...u,type:"category",data:c,axisLabel:{rotate:f,...p,formatter:n},axisLine:{show:!0,color:"blue"},axisTick:{show:!0,alignWithLabel:!0},splitArea:{show:!0},nameTextStyle:{fontWeight:"bold",align:o},nameLocation:"end",nameGap:15,z:1}}const Jh={tooltip:{confine:!0}};function Zh(t,e,n){if(!t.x_axis.data_key||!t.y_axis.data_key||!t.heat_block.data_key)return{};const r=Fh(t),a=Gh(t),o={xAxis:Uh(t,e,r.x_axis),yAxis:Xh(t,e,r.y_axis),series:Rh(t,e),dataset:[{source:e}],tooltip:Qh(t,e,r,a),grid:Wh(t),visualMap:Kh(t)};return x.defaultsDeep({},o,Jh)}function Hh(t){return i(N,{})}function ef(t){return i(s.Text,{children:"Click heat block"})}const Es={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:ef,configRender:Hh,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"}]},Pr={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,overflow:Ze,formatter:{...tt}}},y_axis:{name:"Y Axis",data_key:"",nameAlignment:"center",axisLabel:{rotate:0,overflow:Ze,formatter:{...tt}}},heat_block:{min:0,max:1e3,name:"Value",data_key:"",value_formatter:$e,label:{show:!1,fontSize:10}},tooltip:{metrics:[]}};ue.use([G.DataZoomComponent,he.BarChart,he.LineChart,he.HeatmapChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,G.VisualMapComponent,Ve.CanvasRenderer]);function tf({conf:t,data:e,width:n,height:r,interactionManager:a,variables:o}){const l=y.useMemo(()=>{const p=q(t.x_axis.data_key),g=q(t.y_axis.data_key);return x.keyBy(e[p.queryID],m=>`${m[p.columnKey]}---${m[g.columnKey]}`)},[e,t.x_axis.data_key,t.y_axis.data_key]),u=He(a.triggerManager,Es.id),c=y.useCallback(p=>{const[g,m]=p.value,C=x.get(l,`${g}---${m}`,{error:"rowData is not found"});u.forEach(w=>{a.runInteraction(w.id,{...p,rowData:C})})},[l,u,a]),d=y.useMemo(()=>({click:c}),[c]),f=y.useMemo(()=>Zh(t,e),[t,e]);return!n||!r?null:i(Ne,{echarts:ue,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function nf({context:t,instance:e}){const n=et({vizManager:t.vizManager,instance:e}),{value:r}=R(t.instanceData,"config"),{variables:a}=t,o=y.useMemo(()=>x.defaults({},r,Pr),[r]),l=t.data,{width:u,height:c}=t.viewport;return i(s.Box,{children:i(tf,{variables:a,width:u,height:c,data:l,conf:o,interactionManager:n})})}function rf({control:t,watch:e}){e(["heat_block"]);const n=e("heat_block.label.show");return h(s.Stack,{children:[h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.data_key",control:t,render:({field:r})=>i(j,{label:"Data Field",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:"heat_block.name",control:t,render:({field:r})=>i(s.TextInput,{label:"Name",sx:{flex:1},...r})})]}),h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.min",control:t,render:({field:r})=>i(s.NumberInput,{label:"Min Value",...r})}),i(v.Controller,{name:"heat_block.max",control:t,render:({field:r})=>i(s.NumberInput,{label:"Max Value",...r})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Value Format",labelPosition:"center"}),i(v.Controller,{name:"heat_block.value_formatter",control:t,render:({field:r})=>i(Je,{...r})}),i(s.Divider,{mb:-5,variant:"dashed",label:"Label",labelPosition:"center"}),h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.label.show",control:t,render:({field:r})=>i(s.Switch,{label:"Show label",checked:r.value,onChange:a=>r.onChange(a.currentTarget.checked),sx:{flexGrow:1}})}),i(v.Controller,{name:"heat_block.label.fontSize",control:t,render:({field:r})=>i(s.NumberInput,{size:"xs",icon:i(L.IconTextSize,{size:16}),disabled:!n,...r})})]})]})}const af=({control:t,index:e,remove:n})=>h(s.Stack,{children:[h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${e}.data_key`,control:t,render:({field:r})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),sf=({control:t,watch:e})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"tooltip.metrics"}),o=e("tooltip.metrics"),l=n.map((p,g)=>({...p,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=e("tooltip.metrics.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(p=>p!==null?p:c)},[c]),h(N,{children:[h(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(I.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),i(s.Divider,{variant:"dashed",my:10}),h(s.Tabs,{value:d,onTabChange:p=>f(p),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[h(s.Tabs.List,{children:[l.map((p,g)=>i(s.Tabs.Tab,{value:p.id,children:p.name?p.name:g},p.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((p,g)=>i(s.Tabs.Panel,{value:p.id,children:i(af,{control:t,index:g,remove:a},p.id)},p.id))]})]})};function of({control:t,watch:e}){return i(sf,{control:t,watch:e})}const lf=({disabled:t,value:e,onChange:n})=>{const r=a=>{a&&n(a)};return h(s.Box,{sx:{position:"relative"},children:[t&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(ze,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},uf={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
220
|
+
`)},As=y.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:a,setFalse:o}]=J.useBoolean(),[l,u]=y.useState(t);y.useEffect(()=>{u(t)},[t]);const c=m=>{u({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:C}=l,w={enabled:m,func_content:C};u(w),e(w)},f=()=>{o(),u(t)},p=m=>{u(C=>({...C,func_content:m}))},g=()=>{p(uf.func_content)};return h(N,{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&&h(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:m=>c(m.currentTarget.checked)}),i(lf,{value:l.func_content,onChange:p,disabled:!l.enabled}),h(s.Group,{position:"apart",children:[i(s.Button,{onClick:g,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Rest"}),h(s.Group,{position:"right",children:[i(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:d,children:"OK"})]})]})]})})]})});function cf({control:t,watch:e}){return e(["x_axis"]),h(s.Stack,{children:[h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>i(j,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Tick Label",labelPosition:"center"}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>i(gt,{...n})}),h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>i(As,{...n})})]})]})}const df=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function pf({control:t,watch:e}){return e(["y_axis"]),h(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.data_key",control:t,render:({field:n})=>i(j,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"y_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...n})})]}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"y_axis.nameAlignment",control:t,render:({field:n})=>i(s.Select,{label:"Name Alignment",required:!0,data:df,sx:{flex:1},...n})})}),i(s.Divider,{mb:-15,variant:"dashed",label:"Tick Label",labelPosition:"center"}),i(v.Controller,{name:"y_axis.axisLabel.overflow",control:t,render:({field:n})=>i(gt,{...n})}),h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"y_axis.axisLabel.formatter",control:t,render:({field:n})=>i(As,{...n})})]})]})}function hf({context:t}){const{value:e,set:n}=R(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,Pr),[e]),a=y.useMemo(()=>x.cloneDeep(r),[r]);y.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),p=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return i(s.Stack,{spacing:"xs",children:h("form",{onSubmit:l(n),children:[h(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:!p,children:i(I.DeviceFloppy,{size:20})})]}),h(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[h(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(cf,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(pf,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Heat Block",children:i(rf,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(of,{control:o,watch:u})})]})]})})}function ff(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=d=>d&&`${n}.${d}`,{x_axis:a,y_axis:o,heat_block:l,tooltip:u,...c}=t;return{...c,x_axis:{...a,data_key:r(a.data_key)},y_axis:{...o,data_key:r(o.data_key)},heat_block:{...l,data_key:r(l.data_key)},tooltip:{...u,metrics:u.metrics.map(d=>({...d,data_key:r(d.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}function gf(t){return x.defaultsDeep({},t,{heat_block:{label:{show:!1,fontSize:10}}})}class mf extends ve{constructor(){super(...arguments);V(this,"VERSION",3)}configVersions(){this.version(1,n=>(console.log("🟥 unexpected calling"),{version:1,config:n})),this.version(2,(n,r)=>({...n,version:2,config:ff(n.config,r)})),this.version(3,n=>({...n,version:3,config:gf(n.config)}))}}const yf={displayName:"Heatmap",displayGroup:"ECharts-based charts",migrator:new mf,name:"heatmap",viewRender:nf,configRender:hf,createConfig:()=>({version:3,config:Pr}),triggers:[Es]},zs={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:vf,configRender:bf,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 bf(t){return i(N,{})}function vf(t){return i(s.Text,{children:"Click chart's series"})}const $s={label_template:"${percentage.x} of ${x_axis.name} causes ${percentage.y} of ${bar.name}",color:"rgba(0,0,0,0.3)"},Br={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...tt},overflow:Ze}},data_key:"value",bar:{name:"Value",nameAlignment:"left",color:"#228be6",label_formatter:$e},line:{name:"Value",nameAlignment:"right",color:"red"},dataZoom:Bt,markLine:$s};function Mn(t){return te(t).format({output:"percent",mantissa:0})}function xf(t){const e=t.value[1];try{return Mn(e)}catch(n){return console.error(n),e}}function wf(t){function e(n){let r=n;if(typeof n=="object"&&(Array.isArray(n.value)&&n.value.length===2?r=n.value[1]:r=n.value),!t.bar.label_formatter)return r;try{return te(r).format(t.bar.label_formatter)}catch(a){return console.error(a),r}}return{bar:e,line:xf,lineValue:Mn}}function Cf(t,e,n){const{label_template:r}=t.markLine;if(!r)return"";const a={...t,percentage:e,count:n},o=Object.keys(a),l=Object.values(a);return new Function(...o,`return \`${r}\`;`)(...l)}function Sf(t,e){if(e.length===0)return{};const n=e.findIndex(u=>u[1]>=.8);if(n===-1)return{};const r=e[n],a={x:Mn((n+1)/e.length),y:Mn(r[1])},o={left:n+1,right:e.length-n-1},l=r[0];return l?{name:"",silent:!0,symbol:"triangle",symbolRotate:180,symbolSize:[10,8],data:[{name:"",symbol:"none",xAxis:l,lineStyle:{color:t.markLine.color},label:{formatter:Cf(t,a,o)}}]}:{}}function _f(t,e,n){const{x_axis:r,data_key:a}=t;if(!r.data_key||!a)return[];const o=q(r.data_key),l=q(a);if(o.queryID!==l.queryID)throw new Error("Please use the same query for X & Y axis");const u=e[o.queryID].map(p=>[p[o.columnKey],Number(p[l.columnKey])]).sort((p,g)=>g[1]-p[1]),c=u.reduce((p,g)=>p+g[1],0),d=u.reduce((p,g,m)=>{const C=m===0?0:p[m-1][1];return p.push([g[0],C+g[1]]),p},[]).map(p=>[p[0],p[1]/c]),f=Sf(t,d);return[{name:t.bar.name,type:"bar",barMaxWidth:20,itemStyle:{color:t.bar.color},label:{show:!1,position:"top",formatter:n.bar},yAxisIndex:0,data:u},{name:t.line.name,type:"line",itemStyle:{color:t.line.color},symbolSize:2,lineStyle:{width:1},label:{show:!1,position:"top",formatter:n.line},yAxisIndex:1,data:d,markLine:f}]}const kf=(t,e)=>n=>{const r=Array.isArray(n)?n:[n];if(r.length===0)return"";const a=r.map((u,c)=>{const d=u.seriesName,[f,p]=u.value;if(!d)return p;const g=c===0?e.bar:e.lineValue;return`
|
|
221
221
|
<tr>
|
|
222
222
|
<th style="text-align: right; padding: 0 1em;">${d}</th>
|
|
223
|
-
<td style="text-align: left; padding: 0 1em;">${g(
|
|
223
|
+
<td style="text-align: left; padding: 0 1em;">${g(p)}</td>
|
|
224
224
|
</tr>
|
|
225
225
|
`}),o=mt(t.x_axis.axisLabel.overflow.in_tooltip),l=r[0].name;return`
|
|
226
226
|
<div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
|
|
@@ -231,7 +231,7 @@ Check the top-level render call using <`+P+">.")}return A}}function ql(S,A){{if(
|
|
|
231
231
|
${a.join("")}
|
|
232
232
|
</tbody>
|
|
233
233
|
</table>
|
|
234
|
-
`};function
|
|
234
|
+
`};function Tf(t,e){return{trigger:"axis",formatter:kf(t,e)}}function Df(t){const{name:e,axisLabel:n}=t.x_axis,r=lt(n.overflow.on_axis);return[{type:"category",name:e,nameLocation:"middle",nameGap:30,nameTextStyle:{fontWeight:"bold",align:"right"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0},axisLabel:{...n,...r,formatter:Lt(n.formatter)}}]}function If(t,e){return[{name:t.bar.name,nameGap:20,nameTextStyle:{fontWeight:"bold",align:t.bar.nameAlignment},position:"left",axisLine:{show:!0},axisLabel:{show:!0,formatter:e.bar},splitLine:{show:!1}},{name:t.line.name,nameGap:20,nameTextStyle:{fontWeight:"bold",align:t.line.nameAlignment},position:"right",axisLine:{show:!0},axisLabel:{show:!0,formatter:e.lineValue},splitLine:{show:!1}}]}function Mf(t,e,n){const r=wf(t);return{dataZoom:Er(t.dataZoom),tooltip:Tf(t,r),xAxis:Df(t),yAxis:If(t,r),series:_f(t,e,r),grid:{top:50,left:30,right:15,bottom:5,containLabel:!0}}}ue.use([he.BarChart,he.LineChart,G.DataZoomComponent,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer]);function Ef({context:t,instance:e}){const{value:n}=R(t.instanceData,"config"),r=t.data,{width:a,height:o}=t.viewport,l=x.defaults({},n,Br),u=Mf(l,r),c=et({vizManager:t.vizManager,instance:e}),d=He(c.triggerManager,zs.id),f=yt(r,l.x_axis.data_key),p=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:p}),[p]);return!l||!a||!o?null:i(Ne,{echarts:ue,option:u,style:{width:a,height:o},onEvents:g,notMerge:!0,theme:"merico-light"})}const Af=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function zf({control:t,watch:e}){return e(["bar"]),h(s.Stack,{children:[h(s.Group,{grow:!0,children:[i(v.Controller,{name:"bar.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Bar Name",sx:{flex:1},...n})}),i(v.Controller,{name:"bar.nameAlignment",control:t,render:({field:n})=>i(s.Select,{label:"Align",required:!0,data:Af,sx:{flex:1},...n})})]}),h(s.Stack,{spacing:2,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:"bar.color",control:t,render:({field:n})=>i(Pe,{...n})})]}),h(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:"bar.label_formatter",control:t,render:({field:n})=>i(Je,{...n})})]})]})}const $f=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function Lf({control:t,watch:e}){return e(["line"]),h(s.Stack,{children:[h(s.Group,{grow:!0,children:[i(v.Controller,{name:"line.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Line Name",sx:{flex:1},...n})}),i(v.Controller,{name:"line.nameAlignment",control:t,render:({field:n})=>i(s.Select,{label:"Align",required:!0,data:$f,sx:{flex:1},...n})})]}),h(s.Stack,{spacing:2,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:"line.color",control:t,render:({field:n})=>i(Pe,{...n})})]})]})}const Of=`
|
|
235
235
|
{
|
|
236
236
|
// 80-20 line stuff
|
|
237
237
|
percentage: {
|
|
@@ -254,11 +254,11 @@ Check the top-level render call using <`+P+">.")}return A}}function ql(S,A){{if(
|
|
|
254
254
|
name: string;
|
|
255
255
|
};
|
|
256
256
|
}
|
|
257
|
-
`,
|
|
258
|
-
{percentage|{d}%}`,minMargin:5,edgeDistance:10,lineHeight:15,rich:{percentage:{color:"#999"}},margin:20},labelLine:{length:15,length2:0,maxSurfaceAngle:80,showAbove:!0},labelLayout:function(
|
|
257
|
+
`,Pf=()=>{const[t,e]=y.useState(!1);return h(N,{children:[i(s.Button,{variant:"subtle",compact:!0,onClick:()=>e(n=>!n),children:t?"Close":"Click to see params for Label Template"}),i(s.Collapse,{in:t,children:i(St.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:Of})})]})};function Bf({control:t,watch:e}){return e(["markLine"]),h(s.Stack,{children:[h(s.Stack,{spacing:2,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:"markLine.color",control:t,render:({field:n})=>i(Pe,{...n})})]}),h(s.Stack,{spacing:4,children:[i(v.Controller,{name:"markLine.label_template",control:t,render:({field:n})=>i(s.Textarea,{autosize:!0,minRows:2,maxRows:4,label:"Label Template",sx:{flex:1},...n})}),i(Pf,{})]})]})}function Vf({control:t,watch:e}){return e(["x_axis"]),h(s.Stack,{children:[h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>i(j,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Dn,{...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>i(gt,{...n})})]})}function Nf({control:t,watch:e}){return e(["data_key"]),i(s.Stack,{children:i(v.Controller,{name:"data_key",control:t,render:({field:n})=>i(j,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})})})}function qf({context:t}){const{value:e,set:n}=R(t.instanceData,"config"),r=y.useMemo(()=>x.defaults({},e,Br),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l(["x_axis","data_key","bar","line","dataZoom"]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,e),[d,e]);return h("form",{onSubmit:o(n),children:[h(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(I.DeviceFloppy,{size:20})})]}),h(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[h(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(Vf,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(Nf,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Bar",children:i(zf,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Line",children:i(Lf,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"80-20 Line",children:i(Bf,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Zooming",children:i(v.Controller,{name:"dataZoom",control:a,render:({field:p})=>i(zr,{...p})})})]})]})}function Ff(t){const{dataZoom:e=Bt,...n}=t;return{...n,dataZoom:e}}function Gf(t){const{markLine:e=$s,...n}=t;return{...n,markLine:e}}function Wf(t){const e=x.defaultsDeep({},t.x_axis.axisLabel,{rotate:0,formatter:{...tt}});return{...t,x_axis:{...t.x_axis,axisLabel:e}}}function Rf(t){const{label_formatter:e=$e}=t.bar;return{...t,bar:{...t.bar,label_formatter:e}}}function jf(t){const e={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return x.defaultsDeep(e,t)}function Yf(t){const e={bar:{nameAlignment:"left"},line:{nameAlignment:"right"}};return x.defaultsDeep(e,t)}function Qf(t){console.log(t);const{x_axis:e,tooltip:n}=t.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:e,in_tooltip:n}}}};return x.defaultsDeep(r,t)}function Kf(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis:a,data_key:o,...l}=t;return{...l,x_axis:{...a,data_key:r(a.data_key)},data_key:r(o)}}catch(n){throw console.error("[Migration failed]",n),n}}class Uf extends ve{constructor(){super(...arguments);V(this,"VERSION",9)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:Ff(n.config)})),this.version(3,n=>({...n,version:3,config:Gf(n.config)})),this.version(4,n=>({...n,version:4,config:Wf(n.config)})),this.version(5,n=>({...n,version:5,config:Rf(n.config)})),this.version(6,n=>({...n,version:6,config:jf(n.config)})),this.version(7,n=>({...n,version:7,config:Yf(n.config)})),this.version(8,n=>({...n,version:8,config:Qf(n.config)})),this.version(9,(n,r)=>({...n,version:9,config:Kf(n.config,r)}))}}const Xf={displayName:"Pareto Chart",displayGroup:"ECharts-based charts",migrator:new Uf,name:"paretoChart",viewRender:Ef,configRender:qf,createConfig(){return{version:9,config:x.cloneDeep(Br)}},triggers:[zs]},Vr={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 Jf(){ue.registerTheme("merico-light",{color:Object.values(Vr.graphics.multiple),visualMap:{color:Object.values(Vr.graphics.depth).reverse()}})}function Ls(){Jf()}function*Zf(t){const e=Vr.graphics[t];if(!e)throw new Error("Invalid palette key provided");const n=Object.values(e);let r=0;for(;;)yield n[r%n.length],r++}function Hf(t,e,n){const{label_field:r,value_field:a,color_field:o}=t;if(!r||!a||!o)return{};const l=q(r),u=q(a),c=q(o),d=e[l.queryID].map(p=>({name:p[l.columnKey],value:Number(p[u.columnKey]),color:p[c.columnKey]})),f=Zf("multiple");return{type:"pie",radius:["50%","80%"],itemStyle:{color:({data:p})=>p.color?p.color:f.next().value},label:{position:"outer",alignTo:"edge",formatter:`{name|{b}}
|
|
258
|
+
{percentage|{d}%}`,minMargin:5,edgeDistance:10,lineHeight:15,rich:{percentage:{color:"#999"}},margin:20},labelLine:{length:15,length2:0,maxSurfaceAngle:80,showAbove:!0},labelLayout:function(p){const g=p.labelRect.x<n/2,m=p.labelLinePoints;return x.set(m,[2,0],g?p.labelRect.x:p.labelRect.x+p.labelRect.width),{labelLinePoints:m}},data:d,top:10,bottom:10,left:10,right:10}}function eg(t,e,n){return{tooltip:{show:!0,confine:!0},series:Hf(t,e,n)}}const Os={id:"builtin:echarts:click-pie-chart:series",displayName:"Click Pie Series",nameRender:ng,configRender:tg,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 tg(t){return i(N,{})}function ng(t){return i(s.Text,{children:"Click chart's series"})}const Nr={label_field:"",value_field:"",color_field:""};ue.use([he.PieChart,Ve.CanvasRenderer]);function rg({conf:t,data:e,width:n,height:r,interactionManager:a}){const o=yt(e,t.label_field),l=He(a.triggerManager,Os.id),u=y.useCallback(f=>{const p=x.get(o,f.name,{error:"rowData is not found"});l.forEach(g=>{a.runInteraction(g.id,{...f,rowData:p})})},[o,l,a]),c=y.useMemo(()=>eg(t,e,n),[t,e,n]),d=y.useMemo(()=>({click:u}),[u]);return!n||!r?null:i(Ne,{echarts:ue,option:c,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function ig({context:t,instance:e}){const n=et({vizManager:t.vizManager,instance:e}),{value:r}=R(t.instanceData,"config"),a=y.useMemo(()=>x.defaults({},r,Nr),[r]),o=t.data,{width:l,height:u}=t.viewport;return!l||!u?null:i(rg,{conf:a,width:l,height:u,data:o,interactionManager:n})}function ag({context:t}){const{value:e,set:n}=R(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,Nr),[e]),a=y.useMemo(()=>x.clone(r),[r]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),p=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return u(["label_field","value_field","color_field"]),i(s.Stack,{spacing:"xs",children:h("form",{onSubmit:l(n),children:[h(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:!p,children:i(I.DeviceFloppy,{size:20})})]}),h(s.Stack,{mt:"md",spacing:"xs",p:"md",mb:"sm",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[i(v.Controller,{control:o,name:"label_field",render:({field:g})=>i(j,{label:"Label Key",required:!0,...g})}),i(v.Controller,{control:o,name:"value_field",render:({field:g})=>i(j,{label:"Value Key",required:!0,...g})}),i(v.Controller,{control:o,name:"color_field",render:({field:g})=>i(j,{label:"Color Key",clearable:!0,...g})})]})]})})}function sg(t){const{color_field:e="",...n}=t;return{...n,color_field:e}}function og(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{label_field:a,value_field:o,color_field:l}=t;return{label_field:r(a),value_field:r(o),color_field:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class lg extends ve{constructor(){super(...arguments);V(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:sg(n.config)})),this.version(3,(n,r)=>({...n,version:3,config:og(n.config,r)}))}}const ug={displayName:"Pie Chart",displayGroup:"ECharts-based charts",migrator:new lg,name:"pie",viewRender:ig,configRender:ag,createConfig(){return{version:3,config:x.cloneDeep(Nr)}},triggers:[Os]};function cg(t){return i(N,{})}function dg(t){return i(s.Text,{children:"Click heat block"})}const Ps={id:"builtin:echarts:click-radar-chart:series",displayName:"Click radar chart series",nameRender:dg,configRender:cg,payload:[{name:"seriesType",description:"'radar'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]},En={series_name_key:"",background:{enabled:!0},label:{enabled:!0},dimensions:[]};function Bs(t){return t?e=>{try{return te(e).format(t)}catch(n){return console.error(n),e}}:e=>e}function pg(t){return{show:t.label.enabled,formatter:({dimensionIndex:e,value:n})=>Bs(t.dimensions[e].formatter)(n)}}function hg(t){return({name:e,marker:n,value:r})=>{if(r.length===0)return"";const a=r.map((o,l)=>{const u=t.dimensions[l],c=Bs(u.formatter);return`
|
|
259
259
|
<tr>
|
|
260
|
-
<td style="padding-left: 18px;">${
|
|
261
|
-
<td style="text-align: right; "><strong>${
|
|
260
|
+
<td style="padding-left: 18px;">${u.name}</td>
|
|
261
|
+
<td style="text-align: right; "><strong>${c(o)}</strong></td>
|
|
262
262
|
</tr>
|
|
263
263
|
`});return`
|
|
264
264
|
<table>
|
|
@@ -283,7 +283,7 @@ Check the top-level render call using <`+P+">.")}return A}}function ql(S,A){{if(
|
|
|
283
283
|
${a.join("")}
|
|
284
284
|
</tbody>
|
|
285
285
|
</table>
|
|
286
|
-
`}}const
|
|
286
|
+
`}}const fg={legend:{show:!0,bottom:0,left:0},tooltip:{trigger:"item"}},gg=["#66B4DB","#39BFA2","#E46464","#33A678","#EEBA00","#9D88CB","#939943","#E49792","#09A2B8","#AF5F6B","#6CA157","#09A2B8","#6398C7","#E692BA","#97B566","#8CACE2","#CA79AC","#6DBC80","#B08F4B","#826BAF"];function mg(t,e){const{series_name_key:n,dimensions:r}=t;if(!n||r.length===0)return{};const a=r.map(({name:c,max:d})=>({name:c,max:d})),o=q(n),l=e[o.queryID].map(c=>({value:r.map(({data_key:d})=>{const f=q(d);return c[f.columnKey]}),name:c[o.columnKey]})),u={radar:{indicator:a,splitArea:{show:!1}},tooltip:{confine:!0,backgroundColor:"rgba(255,255,255,0.6)",formatter:hg(t)},legend:{show:!0,bottom:0,left:"center",type:"scroll"},series:{type:"radar",data:l,symbolSize:4,lineStyle:{width:1},emphasis:{lineStyle:{width:4}},areaStyle:t.background.enabled?{opacity:.4}:void 0,label:pg(t)},color:gg};return x.merge({},fg,u)}ue.use([he.RadarChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer]);function yg({conf:t,data:e,width:n,height:r,interactionManager:a,variables:o}){const l=yt(e,t.series_name_key),u=He(a.triggerManager,Ps.id),c=y.useCallback(p=>{const g=x.get(l,p.name,{error:"rowData is not found"});u.forEach(m=>{a.runInteraction(m.id,{...p,rowData:g})})},[l,u,a]),d=y.useMemo(()=>({click:c}),[c]),f=y.useMemo(()=>mg(x.defaultsDeep({},t,En),e),[t,e]);return!n||!r?null:i(Ne,{echarts:ue,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function bg({context:t,instance:e}){const n=et({vizManager:t.vizManager,instance:e}),{value:r}=R(t.instanceData,"config"),{variables:a}=t,o=y.useMemo(()=>x.defaults({},r,En),[r]),l=t.data,{width:u,height:c}=t.viewport;return!u||!c||!o||x.isEmpty(o==null?void 0:o.dimensions)?null:i(s.Box,{children:i(yg,{variables:a,width:u,height:c,data:l,conf:o,interactionManager:n})})}function vg({control:t,index:e,remove:n}){return h(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`dimensions.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`dimensions.${e}.data_key`,control:t,render:({field:r})=>i(j,{label:"Data Key",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`dimensions.${e}.max`,control:t,render:({field:r})=>i(s.NumberInput,{label:"Max",hideControls:!0,required:!0,sx:{flex:1},...r})})]}),h(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Formatter",labelPosition:"center"}),i(v.Controller,{name:`dimensions.${e}.formatter`,control:t,render:({field:r})=>i(Je,{...r})})]}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(e),sx:{position:"absolute",top:15,right:5},disabled:e===0,children:i(I.Trash,{size:16})})]},e)}function xg({control:t,watch:e}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"dimensions"}),o=e("dimensions"),l=n.map((g,m)=>({...g,...o[m]})),u=()=>{const g=new Date().getTime().toString();r({id:g,name:g,data_key:"",max:100,formatter:$e})},c=x.get(l,"0.id",null),[d,f]=y.useState(c);y.useEffect(()=>{f(g=>g||c)},[c]);const p=g=>{a(g);const m=x.get(l,"0.id",null);f(m)};return h(N,{children:[i(s.Divider,{mt:15,variant:"dashed",label:"Metrics",labelPosition:"center"}),h(s.Tabs,{value:d,onTabChange:f,styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[h(s.Tabs.List,{children:[l.map((g,m)=>i(s.Tabs.Tab,{value:g.id,children:g.name?g.name:m+1},m)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(L.IconPlus,{size:18,color:"#228be6"})})]}),l.map((g,m)=>i(s.Tabs.Panel,{value:g.id,children:i(vg,{control:t,index:m,remove:p})},m))]})]})}function wg({context:t}){const{value:e,set:n}=R(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,En),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l(["series_name_key","background","label"]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,r),[d,r]);return i("form",{onSubmit:o(n),children:h(s.Stack,{spacing:"xs",children:[h(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Radar Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(I.DeviceFloppy,{size:20})})]}),i(s.Divider,{mt:15,variant:"dashed",label:"Basics",labelPosition:"center"}),i(v.Controller,{name:"series_name_key",control:a,render:({field:p})=>i(j,{label:"Series Name Field",required:!0,sx:{flex:1},...p})}),h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"background.enabled",control:a,render:({field:p})=>i(s.Checkbox,{label:"Show background",checked:p.value,onChange:g=>p.onChange(g.currentTarget.checked)})}),i(v.Controller,{name:"label.enabled",control:a,render:({field:p})=>i(s.Checkbox,{label:"Show value label",checked:p.value,onChange:g=>p.onChange(g.currentTarget.checked)})})]}),i(xg,{control:a,watch:l})]})})}function Cg(t){const{dimensions:e=[],...n}=t;function r({name:a="",data_key:o="",max:l=10,formatter:u=$e}){return{name:a,data_key:o,max:l,formatter:u}}return{...n,dimensions:e.map(r)}}function Sg(t){const{dimensions:e=[],...n}=t;return{...n,dimensions:e.map(r=>({...r,id:r.id??r.name}))}}function _g(t){const e={background:{enabled:!0},label:{enabled:!0}};return x.defaultsDeep(e,t)}function kg(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{series_name_key:a,dimensions:o,...l}=t;return{...l,series_name_key:r(a),dimensions:o.map(u=>({...u,data_key:r(u.data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class Tg extends ve{constructor(){super(...arguments);V(this,"VERSION",5)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{config:r}=n;return{...n,version:2,config:Cg(r)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:Sg(r)}}),this.version(4,n=>{const{config:r}=n;return{...n,version:4,config:_g(r)}}),this.version(5,(n,r)=>{const{config:a}=n;return{...n,version:5,config:kg(a,r)}})}}const Dg={displayName:"Radar Chart",displayGroup:"ECharts-based charts",migrator:new Tg,name:"radar",viewRender:bg,configRender:wg,createConfig:()=>({version:5,config:En}),triggers:[Ps]};function Ig(t,e){const{plot:n,transform:r}=t.regression;return e.map(a=>({...n,id:`reg-for-${a.name}`,name:a.name,data:In(r,a.data),color:a.color,showSymbol:!1,smooth:!0,tooltip:{show:!1},custom:{type:"regression-line",targetSeries:a.name}}))}function Vs(t,e){const n=q(t.x_axis.data_key),r=q(t.regression.y_axis_data_key);return x.uniqBy(e.map(a=>[a[n.columnKey],a[r.columnKey]]),0)}function Mg(t,e){const{plot:n,transform:r}=t.regression,a=Vs(t,e);return[{type:"scatter",name:t.y_axis.name,data:a,symbolSize:4,color:"red",markLine:{...n,data:[In(r,a)],color:"blue",smooth:!0,silent:!0,symbol:["none","none"]}}]}function Eg(t,e){const{plot:n,transform:r,group_by_key:a}=t.regression,o=q(a),l=x.groupBy(e,o.columnKey);return Object.entries(l).map(([u,c])=>{const d=Vs(t,c);return{type:"scatter",name:u,data:d,symbolSize:4,markLine:{...n,data:[In(r,d)],smooth:!0,silent:!0,symbol:["none","none"]}}})}function Ag(t,e){if(e.length===0)return[];const{group_by_key:n}=t.regression;return n?Eg(t,e):Mg(t,e)}function zg(t){return Array.isArray(t)||(t=[t]),t.map(e=>({marker:e.marker,label:e.seriesName,x:e.value[0],y:e.value[1]}))}function $g(t){return{confine:!0,trigger:"axis",formatter:e=>{const n=zg(e);return n.length===0?"":`
|
|
287
287
|
<table style="width: auto">
|
|
288
288
|
<thead>
|
|
289
289
|
<tr>
|
|
@@ -302,46 +302,46 @@ Check the top-level render call using <`+P+">.")}return A}}function ql(S,A){{if(
|
|
|
302
302
|
</tr>
|
|
303
303
|
</tbody>
|
|
304
304
|
</table>
|
|
305
|
-
`}}}function Ns({enabled:t,func_content:e}){return(n,r)=>{if(!t)return n;try{return new Function(`return ${e}`)()(n,r)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function
|
|
306
|
-
`)},qr={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,format:$e,overflow:Ze,formatter:{...zn}}},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"}};ce.use([G.DataZoomComponent,he.ScatterChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer]);function jg({context:t}){const{value:e}=R(t.instanceData,"config"),{width:n,height:r}=t.viewport,a=y.useMemo(()=>{var m;const u=t.data,d=e==null?void 0:e.x_axis.data_key,f=(m=e==null?void 0:e.regression)==null?void 0:m.y_axis_data_key;if(!d||!f)return[];const h=q(d),g=q(f);return u[h.queryID].map(C=>typeof C[g.columnKey]=="number"?C:{...C,[g.columnKey]:Number(C[g.columnKey])})},[t.data,e==null?void 0:e.regression.y_axis_data_key]),o=y.useMemo(()=>Og(x.defaultsDeep({},e,qr),a),[e,a]),l=y.useRef(null),c=u=>{l.current=u};return!n||!r||!e?null:p(s.Box,{sx:{position:"relative"},children:[i(Rg,{conf:e,queryData:a}),i(Ne,{echarts:ce,onChartReady:c,option:o,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})]})}const Yg=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}];function Qg({control:t,watch:e}){e("regression");const n=e("regression.transform.config.method"),r=e("regression.group_by_key");return p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"regression.name",control:t,render:({field:a})=>i(s.TextInput,{label:"回归线名称",sx:{flex:1},...a})})}),i(v.Controller,{name:"regression.group_by_key",control:t,render:({field:a})=>i(j,{label:"按此字段将数据分为多个系列",clearable:!0,sx:{flex:1},...a})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"regression.transform.config.method",control:t,render:({field:a})=>i(s.Select,{label:"回归方法",data:Yg,sx:{flex:1},...a})}),n==="polynomial"&&i(v.Controller,{name:"regression.transform.config.order",control:t,render:({field:a})=>i(s.NumberInput,{label:"次",sx:{flex:1},...a})})]}),!r&&p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"颜色"}),i(v.Controller,{name:"regression.plot.color",control:t,render:({field:a})=>i(Pe,{...a})})]})]})}const Kg=({disabled:t,value:e,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[t&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(ze,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},Gs=y.forwardRef(({value:t,onChange:e,triggerButtonText:n="Customize Label"},r)=>{const[a,{setTrue:o,setFalse:l}]=J.useBoolean(),[c,u]=y.useState(t);y.useEffect(()=>{u(t)},[t]);const d=C=>{u({...c,enabled:C})},f=()=>{l();const{enabled:C,func_content:w}=c,_={enabled:C,func_content:w};u(_),e(_)},h=()=>{l(),u(t)},g=C=>{u(w=>({...w,func_content:C}))},m=()=>{g(zn.func_content)};return p(N,{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:c.enabled,onChange:C=>d(C.currentTarget.checked)}),i(Kg,{value:c.func_content,onChange:g,disabled:!c.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:m,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:h,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:f,children:"OK"})]})]})]})})]})});function Ug({control:t,watch:e}){return e(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"X轴名称",sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>i(j,{label:"X轴数据字段",required:!0,sx:{flex:1},...n})})]}),i(s.Divider,{variant:"dashed",labelPosition:"center",label:"格式化数据"}),i(s.Stack,{children:i(v.Controller,{name:"x_axis.axisLabel.format",control:t,render:({field:n})=>i(Je,{...n})})}),i(s.Divider,{variant:"dashed",labelPosition:"center",label:"标签文案样式"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"旋转",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"度"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Gs,{triggerButtonText:"自定义标签文案内容",...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>i(gt,{...n})})]})}function Xg({control:t,watch:e}){return e(["y_axis","regression.y_axis_data_key"]),i(s.Stack,{children:p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Y轴名称",sx:{flex:1},...n})}),i(v.Controller,{name:"regression.y_axis_data_key",control:t,render:({field:n})=>i(j,{label:"Y轴数据字段",required:!0,sx:{flex:1},...n})})]})})}function Jg({context:t}){const{value:e,set:n}=R(t.instanceData,"config"),r=y.useMemo(()=>x.defaults({},e,qr),[e]),{control:a,handleSubmit:o,watch:l,getValues:c,reset:u}=v.useForm({defaultValues:r});y.useEffect(()=>{u(r)},[r]),l(["x_axis","y_axis","regression"]);const d=c(),f=y.useMemo(()=>!x.isEqual(d,e),[d,e]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(I.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X轴",orientation:"vertical",styles:{panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X轴",children:"X轴"}),i(s.Tabs.Tab,{value:"Y轴",children:"Y轴"}),i(s.Tabs.Tab,{value:"回归",children:"回归"})]}),i(s.Tabs.Panel,{value:"X轴",children:i(Ug,{watch:l,control:a})}),i(s.Tabs.Panel,{value:"Y轴",children:i(Xg,{watch:l,control:a})}),i(s.Tabs.Panel,{value:"回归",children:i(Qg,{control:a,watch:l})})]})]})})}function Zg(t){const e={x_axis:{axisLabel:{rotate:0,format:$e,overflow:Ze,formatter:zn}},regression:{group_by_key:""}};return x.defaultsDeep(e,t)}function Hg(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,regression:o,...l}=t;return{...l,x_axis:{...a,data_key:r(a.data_key)},regression:{...o,group_by_key:r(o.group_by_key),y_axis_data_key:r(o.y_axis_data_key)}}}catch(n){throw console.error("[Migration failed]",n),n}}class em extends ve{constructor(){super(...arguments);V(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:Zg(n.config)})),this.version(3,(n,r)=>{const{config:a}=n;return{...n,version:3,config:Hg(a,r)}})}}const tm={displayName:"Regression Chart",displayGroup:"Merico suite",migrator:new em,name:"regressionChart",viewRender:jg,configRender:Jg,createConfig(){return{version:3,config:x.cloneDeep(qr)}}},$n={content:""},Fr={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 Ws(t,e,n){for(let r=0;;r++){if(r==t.childCount||r==e.childCount)return t.childCount==e.childCount?null:n;let a=t.child(r),o=e.child(r);if(a==o){n+=a.nodeSize;continue}if(!a.sameMarkup(o))return n;if(a.isText&&a.text!=o.text){for(let l=0;a.text[l]==o.text[l];l++)n++;return n}if(a.content.size||o.content.size){let l=Ws(a.content,o.content,n+1);if(l!=null)return l}n+=a.nodeSize}}function Rs(t,e,n,r){for(let a=t.childCount,o=e.childCount;;){if(a==0||o==0)return a==o?null:{a:n,b:r};let l=t.child(--a),c=e.child(--o),u=l.nodeSize;if(l==c){n-=u,r-=u;continue}if(!l.sameMarkup(c))return{a:n,b:r};if(l.isText&&l.text!=c.text){let d=0,f=Math.min(l.text.length,c.text.length);for(;d<f&&l.text[l.text.length-d-1]==c.text[c.text.length-d-1];)d++,n--,r--;return{a:n,b:r}}if(l.content.size||c.content.size){let d=Rs(l.content,c.content,n-1,r-1);if(d)return d}n-=u,r-=u}}class se{constructor(e,n){if(this.content=e,this.size=n||0,n==null)for(let r=0;r<e.length;r++)this.size+=e[r].nodeSize}nodesBetween(e,n,r,a=0,o){for(let l=0,c=0;c<n;l++){let u=this.content[l],d=c+u.nodeSize;if(d>e&&r(u,a+c,o||null,l)!==!1&&u.content.size){let f=c+1;u.nodesBetween(Math.max(0,e-f),Math.min(u.content.size,n-f),r,a+f)}c=d}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,n,r,a){let o="",l=!0;return this.nodesBetween(e,n,(c,u)=>{c.isText?(o+=c.text.slice(Math.max(e,u)-u,n-u),l=!r):c.isLeaf?(a?o+=typeof a=="function"?a(c):a:c.type.spec.leafText&&(o+=c.type.spec.leafText(c)),l=!r):!l&&c.isBlock&&(o+=r,l=!0)},0),o}append(e){if(!e.size)return this;if(!this.size)return e;let n=this.lastChild,r=e.firstChild,a=this.content.slice(),o=0;for(n.isText&&n.sameMarkup(r)&&(a[a.length-1]=n.withText(n.text+r.text),o=1);o<e.content.length;o++)a.push(e.content[o]);return new se(a,this.size+e.size)}cut(e,n=this.size){if(e==0&&n==this.size)return this;let r=[],a=0;if(n>e)for(let o=0,l=0;l<n;o++){let c=this.content[o],u=l+c.nodeSize;u>e&&((l<e||u>n)&&(c.isText?c=c.cut(Math.max(0,e-l),Math.min(c.text.length,n-l)):c=c.cut(Math.max(0,e-l-1),Math.min(c.content.size,n-l-1))),r.push(c),a+=c.nodeSize),l=u}return new se(r,a)}cutByIndex(e,n){return e==n?se.empty:e==0&&n==this.content.length?this:new se(this.content.slice(e,n))}replaceChild(e,n){let r=this.content[e];if(r==n)return this;let a=this.content.slice(),o=this.size+n.nodeSize-r.nodeSize;return a[e]=n,new se(a,o)}addToStart(e){return new se([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new se(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let n=0;n<this.content.length;n++)if(!this.content[n].eq(e.content[n]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let n=this.content[e];if(!n)throw new RangeError("Index "+e+" out of range for "+this);return n}maybeChild(e){return this.content[e]||null}forEach(e){for(let n=0,r=0;n<this.content.length;n++){let a=this.content[n];e(a,r,n),r+=a.nodeSize}}findDiffStart(e,n=0){return Ws(this,e,n)}findDiffEnd(e,n=this.size,r=e.size){return Rs(this,e,n,r)}findIndex(e,n=-1){if(e==0)return Ln(0,e);if(e==this.size)return Ln(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,a=0;;r++){let o=this.child(r),l=a+o.nodeSize;if(l>=e)return l==e||n>0?Ln(r+1,l):Ln(r,a);a=l}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,n){if(!n)return se.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new se(n.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return se.empty;let n,r=0;for(let a=0;a<e.length;a++){let o=e[a];r+=o.nodeSize,a&&o.isText&&e[a-1].sameMarkup(o)?(n||(n=e.slice(0,a)),n[n.length-1]=o.withText(n[n.length-1].text+o.text)):n&&n.push(o)}return new se(n||e,r)}static from(e){if(!e)return se.empty;if(e instanceof se)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new se([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}se.empty=new se([],0);const Gr={index:0,offset:0};function Ln(t,e){return Gr.index=t,Gr.offset=e,Gr}function Wr(t,e){if(t===e)return!0;if(!(t&&typeof t=="object")||!(e&&typeof e=="object"))return!1;let n=Array.isArray(t);if(Array.isArray(e)!=n)return!1;if(n){if(t.length!=e.length)return!1;for(let r=0;r<t.length;r++)if(!Wr(t[r],e[r]))return!1}else{for(let r in t)if(!(r in e)||!Wr(t[r],e[r]))return!1;for(let r in e)if(!(r in t))return!1}return!0}class We{constructor(e,n){this.type=e,this.attrs=n}addToSet(e){let n,r=!1;for(let a=0;a<e.length;a++){let o=e[a];if(this.eq(o))return e;if(this.type.excludes(o.type))n||(n=e.slice(0,a));else{if(o.type.excludes(this.type))return e;!r&&o.type.rank>this.type.rank&&(n||(n=e.slice(0,a)),n.push(this),r=!0),n&&n.push(o)}}return n||(n=e.slice()),r||n.push(this),n}removeFromSet(e){for(let n=0;n<e.length;n++)if(this.eq(e[n]))return e.slice(0,n).concat(e.slice(n+1));return e}isInSet(e){for(let n=0;n<e.length;n++)if(this.eq(e[n]))return!0;return!1}eq(e){return this==e||this.type==e.type&&Wr(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let n in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Mark.fromJSON");let r=e.marks[n.type];if(!r)throw new RangeError(`There is no mark type ${n.type} in this schema`);return r.create(n.attrs)}static sameSet(e,n){if(e==n)return!0;if(e.length!=n.length)return!1;for(let r=0;r<e.length;r++)if(!e[r].eq(n[r]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&e.length==0)return We.none;if(e instanceof We)return[e];let n=e.slice();return n.sort((r,a)=>r.type.rank-a.type.rank),n}}We.none=[];class nm extends Error{}class ue{constructor(e,n,r){this.content=e,this.openStart=n,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,n){let r=Ys(this.content,e+this.openStart,n);return r&&new ue(r,this.openStart,this.openEnd)}removeBetween(e,n){return new ue(js(this.content,e+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,n){if(!n)return ue.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 ue(se.fromJSON(e,n.content),r,a)}static maxOpen(e,n=!0){let r=0,a=0;for(let o=e.firstChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=e.lastChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.lastChild)a++;return new ue(e,r,a)}}ue.empty=new ue(se.empty,0,0);function js(t,e,n){let{index:r,offset:a}=t.findIndex(e),o=t.maybeChild(r),{index:l,offset:c}=t.findIndex(n);if(a==e||o.isText){if(c!=n&&!t.child(l).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(n))}if(r!=l)throw new RangeError("Removing non-flat range");return t.replaceChild(r,o.copy(js(o.content,e-a-1,n-a-1)))}function Ys(t,e,n,r){let{index:a,offset:o}=t.findIndex(e),l=t.maybeChild(a);if(o==e||l.isText)return r&&!r.canReplace(a,a,n)?null:t.cut(0,e).append(n).append(t.cut(e));let c=Ys(l.content,e-o-1,n);return c&&t.replaceChild(a,l.copy(c))}class On{constructor(e,n){this.schema=e,this.rules=n,this.tags=[],this.styles=[],n.forEach(r=>{r.tag?this.tags.push(r):r.style&&this.styles.push(r)}),this.normalizeLists=!this.tags.some(r=>{if(!/^(ul|ol)\b/.test(r.tag)||!r.node)return!1;let a=e.nodes[r.node];return a.contentMatch.matchType(a)})}parse(e,n={}){let r=new Xs(this,n,!1);return r.addAll(e,n.from,n.to),r.finish()}parseSlice(e,n={}){let r=new Xs(this,n,!0);return r.addAll(e,n.from,n.to),ue.maxOpen(r.finish())}matchTag(e,n,r){for(let a=r?this.tags.indexOf(r)+1:0;a<this.tags.length;a++){let o=this.tags[a];if(am(e,o.tag)&&(o.namespace===void 0||e.namespaceURI==o.namespace)&&(!o.context||n.matchesContext(o.context))){if(o.getAttrs){let l=o.getAttrs(e);if(l===!1)continue;o.attrs=l||void 0}return o}}}matchStyle(e,n,r,a){for(let o=a?this.styles.indexOf(a)+1:0;o<this.styles.length;o++){let l=this.styles[o],c=l.style;if(!(c.indexOf(e)!=0||l.context&&!r.matchesContext(l.context)||c.length>e.length&&(c.charCodeAt(e.length)!=61||c.slice(e.length+1)!=n))){if(l.getAttrs){let u=l.getAttrs(n);if(u===!1)continue;l.attrs=u||void 0}return l}}}static schemaRules(e){let n=[];function r(a){let o=a.priority==null?50:a.priority,l=0;for(;l<n.length;l++){let c=n[l];if((c.priority==null?50:c.priority)<o)break}n.splice(l,0,a)}for(let a in e.marks){let o=e.marks[a].spec.parseDOM;o&&o.forEach(l=>{r(l=Js(l)),l.mark||l.ignore||l.clearMark||(l.mark=a)})}for(let a in e.nodes){let o=e.nodes[a].spec.parseDOM;o&&o.forEach(l=>{r(l=Js(l)),l.node||l.ignore||l.mark||(l.node=a)})}return n}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new On(e,On.schemaRules(e)))}}const Qs={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},rm={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Ks={ol:!0,ul:!0},Pn=1,Bn=2,Zt=4;function Us(t,e,n){return e!=null?(e?Pn:0)|(e==="full"?Bn:0):t&&t.whitespace=="pre"?Pn|Bn:n&~Zt}class Vn{constructor(e,n,r,a,o,l,c){this.type=e,this.attrs=n,this.marks=r,this.pendingMarks=a,this.solid=o,this.options=c,this.content=[],this.activeMarks=We.none,this.stashMarks=[],this.match=l||(c&Zt?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(se.from(e));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let r=this.type.contentMatch,a;return(a=r.findWrapping(e.type))?(this.match=r,a):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&Pn)){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=se.from(this.content);return!e&&this.match&&(n=n.append(this.match.fillBefore(se.empty,!0))),this.type?this.type.create(this.attrs,n,this.marks):n}popFromStashMark(e){for(let n=this.stashMarks.length-1;n>=0;n--)if(e.eq(this.stashMarks[n]))return this.stashMarks.splice(n,1)[0]}applyPending(e){for(let n=0,r=this.pendingMarks;n<r.length;n++){let a=r[n];(this.type?this.type.allowsMarkType(a.type):om(a.type,e))&&!a.isInSet(this.activeMarks)&&(this.activeMarks=a.addToSet(this.activeMarks),this.pendingMarks=a.removeFromSet(this.pendingMarks))}}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!Qs.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class Xs{constructor(e,n,r){this.parser=e,this.options=n,this.isOpen=r,this.open=0;let a=n.topNode,o,l=Us(null,n.preserveWhitespace,0)|(r?Zt:0);a?o=new Vn(a.type,a.attrs,We.none,We.none,!0,n.topMatch||a.type.contentMatch,l):r?o=new Vn(null,null,We.none,We.none,!0,null,l):o=new Vn(e.schema.topNodeType,null,We.none,We.none,!0,null,l),this.nodes=[o],this.find=n.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e){if(e.nodeType==3)this.addTextNode(e);else if(e.nodeType==1){let n=e.getAttribute("style");if(!n)this.addElement(e);else{let r=this.readStyles(sm(n));if(!r)return;let[a,o]=r,l=this.top;for(let c=0;c<o.length;c++)this.removePendingMark(o[c],l);for(let c=0;c<a.length;c++)this.addPendingMark(a[c]);this.addElement(e);for(let c=0;c<a.length;c++)this.removePendingMark(a[c],l);for(let c=0;c<o.length;c++)this.addPendingMark(o[c])}}}addTextNode(e){let n=e.nodeValue,r=this.top;if(r.options&Bn||r.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(r.options&Pn)r.options&Bn?n=n.replace(/\r\n?/g,`
|
|
307
|
-
`):n=n.replace(/\r?\n|\r/g," ");else if(n=n.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let a=r.content[r.content.length-1],o=e.previousSibling;(!a||o&&o.nodeName=="BR"||a.isText&&/[ \t\r\n\u000c]$/.test(a.text))&&(n=n.slice(1))}n&&this.insertNode(this.parser.schema.text(n)),this.findInText(e)}else this.findInside(e)}addElement(e,n){let r=e.nodeName.toLowerCase(),a;Ks.hasOwnProperty(r)&&this.parser.normalizeLists&&
|
|
308
|
-
`))}ignoreFallback(e){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"))}readStyles(e){let n=We.none,r=We.none;for(let a=0;a<e.length;a+=2)for(let o=void 0;;){let l=this.parser.matchStyle(e[a],e[a+1],this,o);if(!l)break;if(l.ignore)return null;if(l.clearMark?this.top.pendingMarks.concat(this.top.activeMarks).forEach(c=>{l.clearMark(c)&&(r=c.addToSet(r))}):n=this.parser.schema.marks[l.mark].create(l.attrs).addToSet(n),l.consuming===!1)o=l;else break}return[n,r]}addElementByRule(e,n,r){let a,o,l;n.node?(o=this.parser.schema.nodes[n.node],o.isLeaf?this.insertNode(o.create(n.attrs))||this.leafFallback(e):a=this.enter(o,n.attrs||null,n.preserveWhitespace)):(l=this.parser.schema.marks[n.mark].create(n.attrs),this.addPendingMark(l));let c=this.top;if(o&&o.isLeaf)this.findInside(e);else if(r)this.addElement(e,r);else if(n.getContent)this.findInside(e),n.getContent(e,this.parser.schema).forEach(u=>this.insertNode(u));else{let u=e;typeof n.contentElement=="string"?u=e.querySelector(n.contentElement):typeof n.contentElement=="function"?u=n.contentElement(e):n.contentElement&&(u=n.contentElement),this.findAround(e,u,!0),this.addAll(u)}a&&this.sync(c)&&this.open--,l&&this.removePendingMark(l,c)}addAll(e,n,r){let a=n||0;for(let o=n?e.childNodes[n]:e.firstChild,l=r==null?null:e.childNodes[r];o!=l;o=o.nextSibling,++a)this.findAtPoint(e,a),this.addDOM(o);this.findAtPoint(e,a)}findPlace(e){let n,r;for(let a=this.open;a>=0;a--){let o=this.nodes[a],l=o.findWrapping(e);if(l&&(!n||n.length>l.length)&&(n=l,r=o,!l.length)||o.solid)break}if(!n)return!1;this.sync(r);for(let a=0;a<n.length;a++)this.enterInner(n[a],null,!1);return!0}insertNode(e){if(e.isInline&&this.needsBlock&&!this.top.type){let n=this.textblockFromContext();n&&this.enterInner(n)}if(this.findPlace(e)){this.closeExtra();let n=this.top;n.applyPending(e.type),n.match&&(n.match=n.match.matchType(e.type));let r=n.activeMarks;for(let a=0;a<e.marks.length;a++)(!n.type||n.type.allowsMarkType(e.marks[a].type))&&(r=e.marks[a].addToSet(r));return n.content.push(e.mark(r)),!0}return!1}enter(e,n,r){let a=this.findPlace(e.create(n));return a&&this.enterInner(e,n,!0,r),a}enterInner(e,n=null,r=!1,a){this.closeExtra();let o=this.top;o.applyPending(e),o.match=o.match&&o.match.matchType(e);let l=Us(e,a,o.options);o.options&Zt&&o.content.length==0&&(l|=Zt),this.nodes.push(new Vn(e,n,o.activeMarks,o.pendingMarks,r,null,l)),this.open++}closeExtra(e=!1){let n=this.nodes.length-1;if(n>this.open){for(;n>this.open;n--)this.nodes[n-1].content.push(this.nodes[n].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(e){for(let n=this.open;n>=0;n--)if(this.nodes[n]==e)return this.open=n,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let n=this.open;n>=0;n--){let r=this.nodes[n].content;for(let a=r.length-1;a>=0;a--)e+=r[a].nodeSize;n&&e++}return e}findAtPoint(e,n){if(this.find)for(let r=0;r<this.find.length;r++)this.find[r].node==e&&this.find[r].offset==n&&(this.find[r].pos=this.currentPos)}findInside(e){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].pos==null&&e.nodeType==1&&e.contains(this.find[n].node)&&(this.find[n].pos=this.currentPos)}findAround(e,n,r){if(e!=n&&this.find)for(let a=0;a<this.find.length;a++)this.find[a].pos==null&&e.nodeType==1&&e.contains(this.find[a].node)&&n.compareDocumentPosition(this.find[a].node)&(r?2:4)&&(this.find[a].pos=this.currentPos)}findInText(e){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==e&&(this.find[n].pos=this.currentPos-(e.nodeValue.length-this.find[n].offset))}matchesContext(e){if(e.indexOf("|")>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let n=e.split("/"),r=this.options.context,a=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),o=-(r?r.depth+1:0)+(a?0:1),l=(c,u)=>{for(;c>=0;c--){let d=n[c];if(d==""){if(c==n.length-1||c==0)continue;for(;u>=o;u--)if(l(c-1,u))return!0;return!1}else{let f=u>0||u==0&&a?this.nodes[u].type:r&&u>=o?r.node(u-o).type:null;if(!f||f.name!=d&&f.groups.indexOf(d)==-1)return!1;u--}}return!0};return l(n.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let n=e.depth;n>=0;n--){let r=e.node(n).contentMatchAt(e.indexAfter(n)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let n in this.parser.schema.nodes){let r=this.parser.schema.nodes[n];if(r.isTextblock&&r.defaultAttrs)return r}}addPendingMark(e){let n=lm(e,this.top.pendingMarks);n&&this.top.stashMarks.push(n),this.top.pendingMarks=e.addToSet(this.top.pendingMarks)}removePendingMark(e,n){for(let r=this.open;r>=0;r--){let a=this.nodes[r];if(a.pendingMarks.lastIndexOf(e)>-1)a.pendingMarks=e.removeFromSet(a.pendingMarks);else{a.activeMarks=e.removeFromSet(a.activeMarks);let l=a.popFromStashMark(e);l&&a.type&&a.type.allowsMarkType(l.type)&&(a.activeMarks=l.addToSet(a.activeMarks))}if(a==n)break}}}function im(t){for(let e=t.firstChild,n=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&Ks.hasOwnProperty(r)&&n?(n.appendChild(e),e=n):r=="li"?n=e:r&&(n=null)}}function am(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function sm(t){let e=/\s*([\w-]+)\s*:\s*([^;]+)/g,n,r=[];for(;n=e.exec(t);)r.push(n[1],n[2].trim());return r}function Js(t){let e={};for(let n in t)e[n]=t[n];return e}function om(t,e){let n=e.schema.nodes;for(let r in n){let a=n[r];if(!a.allowsMarkType(t))continue;let o=[],l=c=>{o.push(c);for(let u=0;u<c.edgeCount;u++){let{type:d,next:f}=c.edge(u);if(d==e||o.indexOf(f)<0&&l(f))return!0}};if(l(a.contentMatch))return!0}}function lm(t,e){for(let n=0;n<e.length;n++)if(t.eq(e[n]))return e[n]}const Zs=65535,Hs=Math.pow(2,16);function cm(t,e){return t+e*Hs}function eo(t){return t&Zs}function um(t){return(t-(t&Zs))/Hs}const to=1,no=2,Nn=4,ro=8;class io{constructor(e,n,r){this.pos=e,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&ro)>0}get deletedBefore(){return(this.delInfo&(to|Nn))>0}get deletedAfter(){return(this.delInfo&(no|Nn))>0}get deletedAcross(){return(this.delInfo&Nn)>0}}class je{constructor(e,n=!1){if(this.ranges=e,this.inverted=n,!e.length&&je.empty)return je.empty}recover(e){let n=0,r=eo(e);if(!this.inverted)for(let a=0;a<r;a++)n+=this.ranges[a*3+2]-this.ranges[a*3+1];return this.ranges[r*3]+n+um(e)}mapResult(e,n=1){return this._map(e,n,!1)}map(e,n=1){return this._map(e,n,!0)}_map(e,n,r){let a=0,o=this.inverted?2:1,l=this.inverted?1:2;for(let c=0;c<this.ranges.length;c+=3){let u=this.ranges[c]-(this.inverted?a:0);if(u>e)break;let d=this.ranges[c+o],f=this.ranges[c+l],h=u+d;if(e<=h){let g=d?e==u?-1:e==h?1:n:n,m=u+a+(g<0?0:f);if(r)return m;let C=e==(n<0?u:h)?null:cm(c/3,e-u),w=e==u?no:e==h?to:Nn;return(n<0?e!=u:e!=h)&&(w|=ro),new io(m,w,C)}a+=f-d}return r?e+a:new io(e+a,0,null)}touches(e,n){let r=0,a=eo(n),o=this.inverted?2:1,l=this.inverted?1:2;for(let c=0;c<this.ranges.length;c+=3){let u=this.ranges[c]-(this.inverted?r:0);if(u>e)break;let d=this.ranges[c+o],f=u+d;if(e<=f&&c==a*3)return!0;r+=this.ranges[c+l]-d}return!1}forEach(e){let n=this.inverted?2:1,r=this.inverted?1:2;for(let a=0,o=0;a<this.ranges.length;a+=3){let l=this.ranges[a],c=l-(this.inverted?o:0),u=l+(this.inverted?0:o),d=this.ranges[a+n],f=this.ranges[a+r];e(c,c+d,u,u+f),o+=f-d}}invert(){return new je(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?je.empty:new je(e<0?[0,-e,0]:[0,0,e])}}je.empty=new je([]);const Rr=Object.create(null);class Ge{getMap(){return je.empty}merge(e){return null}static fromJSON(e,n){if(!n||!n.stepType)throw new RangeError("Invalid input for Step.fromJSON");let r=Rr[n.stepType];if(!r)throw new RangeError(`No step type ${n.stepType} defined`);return r.fromJSON(e,n)}static jsonID(e,n){if(e in Rr)throw new RangeError("Duplicate use of step JSON ID "+e);return Rr[e]=n,n.prototype.jsonID=e,n}}class _e{constructor(e,n){this.doc=e,this.failed=n}static ok(e){return new _e(e,null)}static fail(e){return new _e(null,e)}static fromReplace(e,n,r,a){try{return _e.ok(e.replace(n,r,a))}catch(o){if(o instanceof nm)return _e.fail(o.message);throw o}}}function jr(t,e,n){let r=[];for(let a=0;a<t.childCount;a++){let o=t.child(a);o.content.size&&(o=o.copy(jr(o.content,e,o))),o.isInline&&(o=e(o,n,a)),r.push(o)}return se.fromArray(r)}class _t extends Ge{constructor(e,n,r){super(),this.from=e,this.to=n,this.mark=r}apply(e){let n=e.slice(this.from,this.to),r=e.resolve(this.from),a=r.node(r.sharedDepth(this.to)),o=new ue(jr(n.content,(l,c)=>!l.isAtom||!c.type.allowsMarkType(this.mark.type)?l:l.mark(this.mark.addToSet(l.marks)),a),n.openStart,n.openEnd);return _e.fromReplace(e,this.from,this.to,o)}invert(){return new kt(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new _t(n.pos,r.pos,this.mark)}merge(e){return e instanceof _t&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new _t(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new _t(n.from,n.to,e.markFromJSON(n.mark))}}Ge.jsonID("addMark",_t);class kt extends Ge{constructor(e,n,r){super(),this.from=e,this.to=n,this.mark=r}apply(e){let n=e.slice(this.from,this.to),r=new ue(jr(n.content,a=>a.mark(this.mark.removeFromSet(a.marks)),e),n.openStart,n.openEnd);return _e.fromReplace(e,this.from,this.to,r)}invert(){return new _t(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new kt(n.pos,r.pos,this.mark)}merge(e){return e instanceof kt&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new kt(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new kt(n.from,n.to,e.markFromJSON(n.mark))}}Ge.jsonID("removeMark",kt);class Tt extends Ge{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return _e.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return _e.fromReplace(e,this.pos,this.pos+1,new ue(se.from(r),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);if(n){let r=this.mark.addToSet(n.marks);if(r.length==n.marks.length){for(let a=0;a<n.marks.length;a++)if(!n.marks[a].isInSet(r))return new Tt(this.pos,n.marks[a]);return new Tt(this.pos,this.mark)}}return new Ht(this.pos,this.mark)}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new Tt(n.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new Tt(n.pos,e.markFromJSON(n.mark))}}Ge.jsonID("addNodeMark",Tt);class Ht extends Ge{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return _e.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.removeFromSet(n.marks));return _e.fromReplace(e,this.pos,this.pos+1,new ue(se.from(r),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);return!n||!this.mark.isInSet(n.marks)?this:new Tt(this.pos,this.mark)}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new Ht(n.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new Ht(n.pos,e.markFromJSON(n.mark))}}Ge.jsonID("removeNodeMark",Ht);class nt extends Ge{constructor(e,n,r,a=!1){super(),this.from=e,this.to=n,this.slice=r,this.structure=a}apply(e){return this.structure&&Yr(e,this.from,this.to)?_e.fail("Structure replace would overwrite content"):_e.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new je([this.from,this.to-this.from,this.slice.size])}invert(e){return new nt(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deletedAcross&&r.deletedAcross?null:new nt(n.pos,Math.max(n.pos,r.pos),this.slice)}merge(e){if(!(e instanceof nt)||e.structure||this.structure)return null;if(this.from+this.slice.size==e.from&&!this.slice.openEnd&&!e.slice.openStart){let n=this.slice.size+e.slice.size==0?ue.empty:new ue(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new nt(this.from,this.to+(e.to-e.from),n,this.structure)}else if(e.to==this.from&&!this.slice.openStart&&!e.slice.openEnd){let n=this.slice.size+e.slice.size==0?ue.empty:new ue(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new nt(e.from,this.to,n,this.structure)}else return null}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new nt(n.from,n.to,ue.fromJSON(e,n.slice),!!n.structure)}}Ge.jsonID("replace",nt);class Dt extends Ge{constructor(e,n,r,a,o,l,c=!1){super(),this.from=e,this.to=n,this.gapFrom=r,this.gapTo=a,this.slice=o,this.insert=l,this.structure=c}apply(e){if(this.structure&&(Yr(e,this.from,this.gapFrom)||Yr(e,this.gapTo,this.to)))return _e.fail("Structure gap-replace would overwrite content");let n=e.slice(this.gapFrom,this.gapTo);if(n.openStart||n.openEnd)return _e.fail("Gap is not a flat range");let r=this.slice.insertAt(this.insert,n.content);return r?_e.fromReplace(e,this.from,this.to,r):_e.fail("Content does not fit in gap")}getMap(){return new je([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let n=this.gapTo-this.gapFrom;return new Dt(this.from,this.from+this.slice.size+n,this.from+this.insert,this.from+this.insert+n,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1),a=e.map(this.gapFrom,-1),o=e.map(this.gapTo,1);return n.deletedAcross&&r.deletedAcross||a<n.pos||o>r.pos?null:new Dt(n.pos,r.pos,a,o,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number"||typeof n.gapFrom!="number"||typeof n.gapTo!="number"||typeof n.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Dt(n.from,n.to,n.gapFrom,n.gapTo,ue.fromJSON(e,n.slice),n.insert,!!n.structure)}}Ge.jsonID("replaceAround",Dt);function Yr(t,e,n){let r=t.resolve(e),a=n-e,o=r.depth;for(;a>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,a--;if(a>0){let l=r.node(o).maybeChild(r.indexAfter(o));for(;a>0;){if(!l||l.isLeaf)return!0;l=l.firstChild,a--}}return!1}function dm(t,e,n){return(e==0||t.canReplace(e,t.childCount))&&(n==t.childCount||t.canReplace(0,n))}function pm(t){let n=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let r=t.depth;;--r){let a=t.$from.node(r),o=t.$from.index(r),l=t.$to.indexAfter(r);if(r<t.depth&&a.canReplace(o,l,n))return r;if(r==0||a.type.spec.isolating||!dm(a,o,l))break}return null}function qn(t,e,n=1,r){let a=t.resolve(e),o=a.depth-n,l=r&&r[r.length-1]||a.parent;if(o<0||a.parent.type.spec.isolating||!a.parent.canReplace(a.index(),a.parent.childCount)||!l.type.validContent(a.parent.content.cutByIndex(a.index(),a.parent.childCount)))return!1;for(let d=a.depth-1,f=n-2;d>o;d--,f--){let h=a.node(d),g=a.index(d);if(h.type.spec.isolating)return!1;let m=h.content.cutByIndex(g,h.childCount),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 c=a.indexAfter(o),u=r&&r[0];return a.node(o).canReplaceWith(c,c,u?u.type:a.node(o+1).type)}function ao(t,e){let n=t.resolve(e),r=n.index();return hm(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function hm(t,e){return!!(t&&e&&!t.isLeaf&&t.canAppend(e))}class en extends Ge{constructor(e,n,r){super(),this.pos=e,this.attr=n,this.value=r}apply(e){let n=e.nodeAt(this.pos);if(!n)return _e.fail("No node at attribute step's position");let r=Object.create(null);for(let o in n.attrs)r[o]=n.attrs[o];r[this.attr]=this.value;let a=n.type.create(r,null,n.marks);return _e.fromReplace(e,this.pos,this.pos+1,new ue(se.from(a),0,n.isLeaf?0:1))}getMap(){return je.empty}invert(e){return new en(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new en(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.pos!="number"||typeof n.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new en(n.pos,n.attr,n.value)}}Ge.jsonID("attr",en);let tn=class extends Error{};tn=function t(e){let n=Error.call(this,e);return n.__proto__=t.prototype,n},tn.prototype=Object.create(Error.prototype),tn.prototype.constructor=tn,tn.prototype.name="TransformError";const Qr=Object.create(null);class me{constructor(e,n,r){this.$anchor=e,this.$head=n,this.ranges=r||[new fm(e.min(n),e.max(n))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let n=0;n<e.length;n++)if(e[n].$from.pos!=e[n].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(e,n=ue.empty){let r=n.content.lastChild,a=null;for(let c=0;c<n.openEnd;c++)a=r,r=r.lastChild;let o=e.steps.length,l=this.ranges;for(let c=0;c<l.length;c++){let{$from:u,$to:d}=l[c],f=e.mapping.slice(o);e.replaceRange(f.map(u.pos),f.map(d.pos),c?ue.empty:n),c==0&&lo(e,o,(r?r.isInline:a&&a.isTextblock)?-1:1)}}replaceWith(e,n){let r=e.steps.length,a=this.ranges;for(let o=0;o<a.length;o++){let{$from:l,$to:c}=a[o],u=e.mapping.slice(r),d=u.map(l.pos),f=u.map(c.pos);o?e.deleteRange(d,f):(e.replaceRangeWith(d,f,n),lo(e,r,n.isInline?-1:1))}}static findFrom(e,n,r=!1){let a=e.parent.inlineContent?new ke(e):Vt(e.node(0),e.parent,e.pos,e.index(),n,r);if(a)return a;for(let o=e.depth-1;o>=0;o--){let l=n<0?Vt(e.node(0),e.node(o),e.before(o+1),e.index(o),n,r):Vt(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,n,r);if(l)return l}return null}static near(e,n=1){return this.findFrom(e,n)||this.findFrom(e,-n)||new ut(e.node(0))}static atStart(e){return Vt(e,e,0,0,1)||new ut(e)}static atEnd(e){return Vt(e,e,e.content.size,e.childCount,-1)||new ut(e)}static fromJSON(e,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(e,n)}static jsonID(e,n){if(e in Qr)throw new RangeError("Duplicate use of selection JSON ID "+e);return Qr[e]=n,n.prototype.jsonID=e,n}getBookmark(){return ke.between(this.$anchor,this.$head).getBookmark()}}me.prototype.visible=!0;class fm{constructor(e,n){this.$from=e,this.$to=n}}let so=!1;function oo(t){!so&&!t.parent.inlineContent&&(so=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")"))}class ke extends me{constructor(e,n=e){oo(e),oo(n),super(e,n)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,n){let r=e.resolve(n.map(this.head));if(!r.parent.inlineContent)return me.near(r);let a=e.resolve(n.map(this.anchor));return new ke(a.parent.inlineContent?a:r,r)}replace(e,n=ue.empty){if(super.replace(e,n),n==ue.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof ke&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Fn(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,n){if(typeof n.anchor!="number"||typeof n.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new ke(e.resolve(n.anchor),e.resolve(n.head))}static create(e,n,r=n){let a=e.resolve(n);return new this(a,r==n?a:e.resolve(r))}static between(e,n,r){let a=e.pos-n.pos;if((!r||a)&&(r=a>=0?1:-1),!n.parent.inlineContent){let o=me.findFrom(n,r,!0)||me.findFrom(n,-r,!0);if(o)n=o.$head;else return me.near(n,r)}return e.parent.inlineContent||(a==0?e=n:(e=(me.findFrom(e,-r,!0)||me.findFrom(e,r,!0)).$anchor,e.pos<n.pos!=a<0&&(e=n))),new ke(e,n)}}me.jsonID("text",ke);class Fn{constructor(e,n){this.anchor=e,this.head=n}map(e){return new Fn(e.map(this.anchor),e.map(this.head))}resolve(e){return ke.between(e.resolve(this.anchor),e.resolve(this.head))}}class Re extends me{constructor(e){let n=e.nodeAfter,r=e.node(0).resolve(e.pos+n.nodeSize);super(e,r),this.node=n}map(e,n){let{deleted:r,pos:a}=n.mapResult(this.anchor),o=e.resolve(a);return r?me.near(o):new Re(o)}content(){return new ue(se.from(this.node),0,0)}eq(e){return e instanceof Re&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new Kr(this.anchor)}static fromJSON(e,n){if(typeof n.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new Re(e.resolve(n.anchor))}static create(e,n){return new Re(e.resolve(n))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}}Re.prototype.visible=!1,me.jsonID("node",Re);class Kr{constructor(e){this.anchor=e}map(e){let{deleted:n,pos:r}=e.mapResult(this.anchor);return n?new Fn(r,r):new Kr(r)}resolve(e){let n=e.resolve(this.anchor),r=n.nodeAfter;return r&&Re.isSelectable(r)?new Re(n):me.near(n)}}class ut extends me{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,n=ue.empty){if(n==ue.empty){e.delete(0,e.doc.content.size);let r=me.atStart(e.doc);r.eq(e.selection)||e.setSelection(r)}else super.replace(e,n)}toJSON(){return{type:"all"}}static fromJSON(e){return new ut(e)}map(e){return new ut(e)}eq(e){return e instanceof ut}getBookmark(){return gm}}me.jsonID("all",ut);const gm={map(){return this},resolve(t){return new ut(t)}};function Vt(t,e,n,r,a,o=!1){if(e.inlineContent)return ke.create(t,n);for(let l=r-(a>0?0:1);a>0?l<e.childCount:l>=0;l+=a){let c=e.child(l);if(c.isAtom){if(!o&&Re.isSelectable(c))return Re.create(t,n-(a<0?c.nodeSize:0))}else{let u=Vt(t,c,n+a,a<0?c.childCount:0,a,o);if(u)return u}n+=c.nodeSize*a}return null}function lo(t,e,n){let r=t.steps.length-1;if(r<e)return;let a=t.steps[r];if(!(a instanceof nt||a instanceof Dt))return;let o=t.mapping.maps[r],l;o.forEach((c,u,d,f)=>{l==null&&(l=f)}),t.setSelection(me.near(t.doc.resolve(l),n))}function co(t,e){return!e||!t?t:t.bind(e)}class Gn{constructor(e,n,r){this.name=e,this.init=co(n.init,r),this.apply=co(n.apply,r)}}new Gn("doc",{init(t){return t.doc||t.schema.topNodeType.createAndFill()},apply(t){return t.doc}}),new Gn("selection",{init(t,e){return t.selection||me.atStart(e.doc)},apply(t){return t.selection}}),new Gn("storedMarks",{init(t){return t.storedMarks||null},apply(t,e,n,r){return r.selection.$cursor?t.storedMarks:null}}),new Gn("scrollToSelection",{init(){return 0},apply(t,e){return t.scrolledIntoView?e+1:e}});function uo(t,e,n){for(let r in t){let a=t[r];a instanceof Function?a=a.bind(e):r=="handleDOMEvents"&&(a=uo(a,e,{})),n[r]=a}return n}class nn{constructor(e){this.spec=e,this.props={},e.props&&uo(e.props,this,this.props),this.key=e.key?e.key.key:po("plugin")}getState(e){return e[this.key]}}const Ur=Object.create(null);function po(t){return t in Ur?t+"$"+ ++Ur[t]:(Ur[t]=0,t+"$")}class rn{constructor(e="key"){this.key=po(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}function ho(t){const{state:e,transaction:n}=t;let{selection:r}=n,{doc:a}=n,{storedMarks:o}=n;return{...e,apply:e.apply.bind(e),applyTransaction:e.applyTransaction.bind(e),filterTransaction:e.filterTransaction,plugins:e.plugins,schema:e.schema,reconfigure:e.reconfigure.bind(e),toJSON:e.toJSON.bind(e),get storedMarks(){return o},get selection(){return r},get doc(){return a},get tr(){return r=n.selection,a=n.doc,o=n.storedMarks,n}}}class mm{constructor(e){this.editor=e.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=e.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){const{rawCommands:e,editor:n,state:r}=this,{view:a}=n,{tr:o}=r,l=this.buildProps(o);return Object.fromEntries(Object.entries(e).map(([c,u])=>[c,(...f)=>{const h=u(...f)(l);return!o.getMeta("preventDispatch")&&!this.hasCustomState&&a.dispatch(o),h}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,n=!0){const{rawCommands:r,editor:a,state:o}=this,{view:l}=a,c=[],u=!!e,d=e||o.tr,f=()=>(!u&&n&&!d.getMeta("preventDispatch")&&!this.hasCustomState&&l.dispatch(d),c.every(g=>g===!0)),h={...Object.fromEntries(Object.entries(r).map(([g,m])=>[g,(...w)=>{const _=this.buildProps(d,n),T=m(...w)(_);return c.push(T),h}])),run:f};return h}createCan(e){const{rawCommands:n,state:r}=this,a=!1,o=e||r.tr,l=this.buildProps(o,a);return{...Object.fromEntries(Object.entries(n).map(([u,d])=>[u,(...f)=>d(...f)({...l,dispatch:void 0})])),chain:()=>this.createChain(o,a)}}buildProps(e,n=!0){const{rawCommands:r,editor:a,state:o}=this,{view:l}=a;o.storedMarks&&e.setStoredMarks(o.storedMarks);const c={tr:e,editor:a,view:l,state:ho({state:o,transaction:e}),dispatch:n?()=>{}:void 0,chain:()=>this.createChain(e),can:()=>this.createCan(e),get commands(){return Object.fromEntries(Object.entries(r).map(([u,d])=>[u,(...f)=>d(...f)(c)]))}};return c}}function bt(t,e,n){return t.config[e]===void 0&&t.parent?bt(t.parent,e,n):typeof t.config[e]=="function"?t.config[e].bind({...n,parent:t.parent?bt(t.parent,e,n):null}):t.config[e]}function ym(t){const e=t.filter(a=>a.type==="extension"),n=t.filter(a=>a.type==="node"),r=t.filter(a=>a.type==="mark");return{baseExtensions:e,nodeExtensions:n,markExtensions:r}}function Le(t,e){if(typeof t=="string"){if(!e.nodes[t])throw Error(`There is no node type named '${t}'. Maybe you forgot to add the extension?`);return e.nodes[t]}return t}function bm(t){return typeof t=="function"}function Nt(t,e=void 0,...n){return bm(t)?e?t.bind(e)(...n):t(...n):t}function vm(t){return Object.prototype.toString.call(t)==="[object RegExp]"}function xm(t){return Object.prototype.toString.call(t).slice(8,-1)}function Xr(t){return xm(t)!=="Object"?!1:t.constructor===Object&&Object.getPrototypeOf(t)===Object.prototype}function fo(t,e){const n={...t};return Xr(t)&&Xr(e)&&Object.keys(e).forEach(r=>{Xr(e[r])?r in t?n[r]=fo(t[r],e[r]):Object.assign(n,{[r]:e[r]}):Object.assign(n,{[r]:e[r]})}),n}class rt{constructor(e={}){this.type="extension",this.name="extension",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=Nt(bt(this,"addOptions",{name:this.name}))),this.storage=Nt(bt(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new rt(e)}configure(e={}){const n=this.extend();return n.options=fo(this.options,e),n.storage=Nt(bt(n,"addStorage",{name:n.name,options:n.options})),n}extend(e={}){const n=new rt(e);return n.parent=this,this.child=n,n.name=e.name?e.name:n.parent.name,e.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${n.name}".`),n.options=Nt(bt(n,"addOptions",{name:n.name})),n.storage=Nt(bt(n,"addStorage",{name:n.name,options:n.options})),n}}function wm(t,e,n){const{from:r,to:a}=e,{blockSeparator:o=`
|
|
305
|
+
`}}}function Ns({enabled:t,func_content:e}){return(n,r)=>{if(!t)return n;try{return new Function(`return ${e}`)()(n,r)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function Lg(t){const{overflow:e,format:n,formatter:r,...a}=t.x_axis.axisLabel,o=lt(e.on_axis);return{type:"value",name:t.x_axis.name??"",nameLocation:"middle",nameGap:25,axisTick:{show:!0,alignWithLabel:!0},axisLabel:{...a,...o,formatter:(l,u)=>{let c=l;try{c=te(l).format(n)}catch{}return Ns(r)(c,u)}}}}const Og={tooltip:{trigger:"axis"},grid:{top:50,left:5,right:10,bottom:20,containLabel:!0},dataZoom:[{type:"inside",xAxisIndex:[0]},{type:"inside",yAxisIndex:[0]}]};function Pg(t,e){const n=Ag(t,e),r=Ig(t,n),a={xAxis:Lg(t),yAxis:{name:t.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"left"},nameGap:5,axisLine:{show:!0}},series:[...n,...r],tooltip:$g(t),legend:{show:!0,type:"scroll",orient:"horizontal",align:"left",right:0,top:0,left:"auto",itemGap:20,padding:[4,8,0,140],data:n.map(o=>o.name)}};return x.defaultsDeep({},a,Og)}function An(t,e,n){return 1-(1-t)*(e-1)/(e-n-1)}function Bg(t,e,n,r){const{x_axis:a,y_axis:o}=r,l=ht.regressionLinear()(n),{a:u,b:c,rSquared:d}=l;return{name:t,expression:h(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:te(c).format({mantissa:2,trimMantissa:!0})}),i(s.Text,{children:"+"}),i(s.Text,{weight:"bold",color:"red",children:te(u).format({mantissa:2,trimMantissa:!0})}),i(s.Text,{children:"×"}),i(s.Text,{children:a.name})]}),rSquared:d,adjustedRSquared:An(d,e.length,1)}}function Vg(t,e,n,r){const{x_axis:a,y_axis:o}=r,{a:l,b:u,rSquared:c}=ht.regressionExp()(n);return{name:t,expression:h(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:"×"}),h(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:An(c,e.length,1)}}function Ng(t,e,n,r){const{x_axis:a,y_axis:o}=r,{a:l,b:u,rSquared:c}=ht.regressionLog()(n);return{name:t,expression:h(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:"×"}),h(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:An(c,e.length,1)}}function qg(t,e,n,r){const{x_axis:a,y_axis:o,regression:l}=r,u=ht.regressionPoly().order(l.transform.config.order)(n),{rSquared:c}=u;return console.log(u),{name:t,expression:"",rSquared:c,adjustedRSquared:An(c,e.length,1)}}function qs(t,e,n){const{regression:r,x_axis:a}=n,o=q(a.data_key),l=q(r.y_axis_data_key),u=e.map(c=>[c[o.columnKey],c[l.columnKey]]);return r.transform.config.method==="linear"?Bg(t,e,u,n):r.transform.config.method==="exponential"?Vg(t,e,u,n):r.transform.config.method==="logarithmic"?Ng(t,e,u,n):r.transform.config.method==="polynomial"?qg(t,e,u,n):{name:t,expression:"",rSquared:0,adjustedRSquared:0}}function Fg(t,e){if(!e)return[{name:"",expression:"",rSquared:0,adjustedRSquared:0}];if(!e.regression.group_by_key)return[qs("",t,e)];const n=q(e.regression.group_by_key),r=x.groupBy(t,n.columnKey);return Object.entries(r).map(([a,o])=>qs(a,o,e))}const Gg={marginTop:"10px","tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function Fs({desc:t}){const{expression:e,rSquared:n,adjustedRSquared:r}=t;return e?i(s.Table,{fontSize:14,sx:Gg,children:h("tbody",{children:[i("tr",{children:i("td",{colSpan:2,children:i(s.Text,{align:"center",children:e})})}),h("tr",{children:[i("td",{children:"R-Sq"}),i("td",{style:{textAlign:"right"},children:te(n).format({output:"percent",mantissa:1})})]}),h("tr",{children:[i("td",{children:"R-Sq(Adjusted)"}),i("td",{style:{textAlign:"right"},children:te(r).format({output:"percent",mantissa:1})})]})]})}):i(s.Text,{children:"Unavailable for this regression method"})}function Wg({conf:t,queryData:e}){var r;const n=y.useMemo(()=>Fg(e,t),[t,e]);return t.regression.group_by_key?(console.log(n),h(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(Fs,{desc:a})},a.name))]})):i(Fs,{desc:n[0]})}function Rg({conf:t,queryData:e}){return h(s.HoverCard,{shadow:"md",withinPortal:!0,zIndex:320,children:[i(s.HoverCard.Target,{children:i(s.Button,{size:"xs",variant:"subtle",compact:!0,leftIcon:i(L.IconInfoCircle,{size:14}),children:"Regression Info"})}),i(s.HoverCard.Dropdown,{children:i(Fe,{children:i(Wg,{conf:t,queryData:e})})})]})}function jg(t){return i(s.Group,{position:"apart",sx:{position:"absolute",top:0,left:0,height:"22px",zIndex:1},children:i(Rg,{...t})})}const zn={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
306
|
+
`)},qr={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,format:$e,overflow:Ze,formatter:{...zn}}},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"}};ue.use([G.DataZoomComponent,he.ScatterChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer]);function Yg({context:t}){const{value:e}=R(t.instanceData,"config"),{width:n,height:r}=t.viewport,a=y.useMemo(()=>{var m;const c=t.data,d=e==null?void 0:e.x_axis.data_key,f=(m=e==null?void 0:e.regression)==null?void 0:m.y_axis_data_key;if(!d||!f)return[];const p=q(d),g=q(f);return c[p.queryID].map(C=>typeof C[g.columnKey]=="number"?C:{...C,[g.columnKey]:Number(C[g.columnKey])})},[t.data,e==null?void 0:e.regression.y_axis_data_key]),o=y.useMemo(()=>Pg(x.defaultsDeep({},e,qr),a),[e,a]),l=y.useRef(null),u=c=>{l.current=c};return!n||!r||!e?null:h(s.Box,{sx:{position:"relative"},children:[i(jg,{conf:e,queryData:a}),i(Ne,{echarts:ue,onChartReady:u,option:o,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})]})}const Qg=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}];function Kg({control:t,watch:e}){e("regression");const n=e("regression.transform.config.method"),r=e("regression.group_by_key");return h(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"regression.name",control:t,render:({field:a})=>i(s.TextInput,{label:"回归线名称",sx:{flex:1},...a})})}),i(v.Controller,{name:"regression.group_by_key",control:t,render:({field:a})=>i(j,{label:"按此字段将数据分为多个系列",clearable:!0,sx:{flex:1},...a})}),h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"regression.transform.config.method",control:t,render:({field:a})=>i(s.Select,{label:"回归方法",data:Qg,sx:{flex:1},...a})}),n==="polynomial"&&i(v.Controller,{name:"regression.transform.config.order",control:t,render:({field:a})=>i(s.NumberInput,{label:"次",sx:{flex:1},...a})})]}),!r&&h(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"颜色"}),i(v.Controller,{name:"regression.plot.color",control:t,render:({field:a})=>i(Pe,{...a})})]})]})}const Ug=({disabled:t,value:e,onChange:n})=>{const r=a=>{a&&n(a)};return h(s.Box,{sx:{position:"relative"},children:[t&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(ze,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},Gs=y.forwardRef(({value:t,onChange:e,triggerButtonText:n="Customize Label"},r)=>{const[a,{setTrue:o,setFalse:l}]=J.useBoolean(),[u,c]=y.useState(t);y.useEffect(()=>{c(t)},[t]);const d=C=>{c({...u,enabled:C})},f=()=>{l();const{enabled:C,func_content:w}=u,_={enabled:C,func_content:w};c(_),e(_)},p=()=>{l(),c(t)},g=C=>{c(w=>({...w,func_content:C}))},m=()=>{g(zn.func_content)};return h(N,{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&&h(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:u.enabled,onChange:C=>d(C.currentTarget.checked)}),i(Ug,{value:u.func_content,onChange:g,disabled:!u.enabled}),h(s.Group,{position:"apart",children:[i(s.Button,{onClick:m,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Rest"}),h(s.Group,{position:"right",children:[i(s.Button,{onClick:p,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:f,children:"OK"})]})]})]})})]})});function Xg({control:t,watch:e}){return e(["x_axis"]),h(s.Stack,{children:[h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"X轴名称",sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>i(j,{label:"X轴数据字段",required:!0,sx:{flex:1},...n})})]}),i(s.Divider,{variant:"dashed",labelPosition:"center",label:"格式化数据"}),i(s.Stack,{children:i(v.Controller,{name:"x_axis.axisLabel.format",control:t,render:({field:n})=>i(Je,{...n})})}),i(s.Divider,{variant:"dashed",labelPosition:"center",label:"标签文案样式"}),h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"旋转",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"度"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Gs,{triggerButtonText:"自定义标签文案内容",...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>i(gt,{...n})})]})}function Jg({control:t,watch:e}){return e(["y_axis","regression.y_axis_data_key"]),i(s.Stack,{children:h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Y轴名称",sx:{flex:1},...n})}),i(v.Controller,{name:"regression.y_axis_data_key",control:t,render:({field:n})=>i(j,{label:"Y轴数据字段",required:!0,sx:{flex:1},...n})})]})})}function Zg({context:t}){const{value:e,set:n}=R(t.instanceData,"config"),r=y.useMemo(()=>x.defaults({},e,qr),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l(["x_axis","y_axis","regression"]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,e),[d,e]);return i(s.Stack,{spacing:"xs",children:h("form",{onSubmit:o(n),children:[h(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(I.DeviceFloppy,{size:20})})]}),h(s.Tabs,{defaultValue:"X轴",orientation:"vertical",styles:{panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[h(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(Xg,{watch:l,control:a})}),i(s.Tabs.Panel,{value:"Y轴",children:i(Jg,{watch:l,control:a})}),i(s.Tabs.Panel,{value:"回归",children:i(Kg,{control:a,watch:l})})]})]})})}function Hg(t){const e={x_axis:{axisLabel:{rotate:0,format:$e,overflow:Ze,formatter:zn}},regression:{group_by_key:""}};return x.defaultsDeep(e,t)}function em(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis:a,regression:o,...l}=t;return{...l,x_axis:{...a,data_key:r(a.data_key)},regression:{...o,group_by_key:r(o.group_by_key),y_axis_data_key:r(o.y_axis_data_key)}}}catch(n){throw console.error("[Migration failed]",n),n}}class tm extends ve{constructor(){super(...arguments);V(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:Hg(n.config)})),this.version(3,(n,r)=>{const{config:a}=n;return{...n,version:3,config:em(a,r)}})}}const nm={displayName:"Regression Chart",displayGroup:"Merico suite",migrator:new tm,name:"regressionChart",viewRender:Yg,configRender:Zg,createConfig(){return{version:3,config:x.cloneDeep(qr)}}},$n={content:""},Fr={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 Ws(t,e,n){for(let r=0;;r++){if(r==t.childCount||r==e.childCount)return t.childCount==e.childCount?null:n;let a=t.child(r),o=e.child(r);if(a==o){n+=a.nodeSize;continue}if(!a.sameMarkup(o))return n;if(a.isText&&a.text!=o.text){for(let l=0;a.text[l]==o.text[l];l++)n++;return n}if(a.content.size||o.content.size){let l=Ws(a.content,o.content,n+1);if(l!=null)return l}n+=a.nodeSize}}function Rs(t,e,n,r){for(let a=t.childCount,o=e.childCount;;){if(a==0||o==0)return a==o?null:{a:n,b:r};let l=t.child(--a),u=e.child(--o),c=l.nodeSize;if(l==u){n-=c,r-=c;continue}if(!l.sameMarkup(u))return{a:n,b:r};if(l.isText&&l.text!=u.text){let d=0,f=Math.min(l.text.length,u.text.length);for(;d<f&&l.text[l.text.length-d-1]==u.text[u.text.length-d-1];)d++,n--,r--;return{a:n,b:r}}if(l.content.size||u.content.size){let d=Rs(l.content,u.content,n-1,r-1);if(d)return d}n-=c,r-=c}}class se{constructor(e,n){if(this.content=e,this.size=n||0,n==null)for(let r=0;r<e.length;r++)this.size+=e[r].nodeSize}nodesBetween(e,n,r,a=0,o){for(let l=0,u=0;u<n;l++){let c=this.content[l],d=u+c.nodeSize;if(d>e&&r(c,a+u,o||null,l)!==!1&&c.content.size){let f=u+1;c.nodesBetween(Math.max(0,e-f),Math.min(c.content.size,n-f),r,a+f)}u=d}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,n,r,a){let o="",l=!0;return this.nodesBetween(e,n,(u,c)=>{u.isText?(o+=u.text.slice(Math.max(e,c)-c,n-c),l=!r):u.isLeaf?(a?o+=typeof a=="function"?a(u):a:u.type.spec.leafText&&(o+=u.type.spec.leafText(u)),l=!r):!l&&u.isBlock&&(o+=r,l=!0)},0),o}append(e){if(!e.size)return this;if(!this.size)return e;let n=this.lastChild,r=e.firstChild,a=this.content.slice(),o=0;for(n.isText&&n.sameMarkup(r)&&(a[a.length-1]=n.withText(n.text+r.text),o=1);o<e.content.length;o++)a.push(e.content[o]);return new se(a,this.size+e.size)}cut(e,n=this.size){if(e==0&&n==this.size)return this;let r=[],a=0;if(n>e)for(let o=0,l=0;l<n;o++){let u=this.content[o],c=l+u.nodeSize;c>e&&((l<e||c>n)&&(u.isText?u=u.cut(Math.max(0,e-l),Math.min(u.text.length,n-l)):u=u.cut(Math.max(0,e-l-1),Math.min(u.content.size,n-l-1))),r.push(u),a+=u.nodeSize),l=c}return new se(r,a)}cutByIndex(e,n){return e==n?se.empty:e==0&&n==this.content.length?this:new se(this.content.slice(e,n))}replaceChild(e,n){let r=this.content[e];if(r==n)return this;let a=this.content.slice(),o=this.size+n.nodeSize-r.nodeSize;return a[e]=n,new se(a,o)}addToStart(e){return new se([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new se(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let n=0;n<this.content.length;n++)if(!this.content[n].eq(e.content[n]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let n=this.content[e];if(!n)throw new RangeError("Index "+e+" out of range for "+this);return n}maybeChild(e){return this.content[e]||null}forEach(e){for(let n=0,r=0;n<this.content.length;n++){let a=this.content[n];e(a,r,n),r+=a.nodeSize}}findDiffStart(e,n=0){return Ws(this,e,n)}findDiffEnd(e,n=this.size,r=e.size){return Rs(this,e,n,r)}findIndex(e,n=-1){if(e==0)return Ln(0,e);if(e==this.size)return Ln(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,a=0;;r++){let o=this.child(r),l=a+o.nodeSize;if(l>=e)return l==e||n>0?Ln(r+1,l):Ln(r,a);a=l}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,n){if(!n)return se.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new se(n.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return se.empty;let n,r=0;for(let a=0;a<e.length;a++){let o=e[a];r+=o.nodeSize,a&&o.isText&&e[a-1].sameMarkup(o)?(n||(n=e.slice(0,a)),n[n.length-1]=o.withText(n[n.length-1].text+o.text)):n&&n.push(o)}return new se(n||e,r)}static from(e){if(!e)return se.empty;if(e instanceof se)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new se([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}se.empty=new se([],0);const Gr={index:0,offset:0};function Ln(t,e){return Gr.index=t,Gr.offset=e,Gr}function Wr(t,e){if(t===e)return!0;if(!(t&&typeof t=="object")||!(e&&typeof e=="object"))return!1;let n=Array.isArray(t);if(Array.isArray(e)!=n)return!1;if(n){if(t.length!=e.length)return!1;for(let r=0;r<t.length;r++)if(!Wr(t[r],e[r]))return!1}else{for(let r in t)if(!(r in e)||!Wr(t[r],e[r]))return!1;for(let r in e)if(!(r in t))return!1}return!0}class We{constructor(e,n){this.type=e,this.attrs=n}addToSet(e){let n,r=!1;for(let a=0;a<e.length;a++){let o=e[a];if(this.eq(o))return e;if(this.type.excludes(o.type))n||(n=e.slice(0,a));else{if(o.type.excludes(this.type))return e;!r&&o.type.rank>this.type.rank&&(n||(n=e.slice(0,a)),n.push(this),r=!0),n&&n.push(o)}}return n||(n=e.slice()),r||n.push(this),n}removeFromSet(e){for(let n=0;n<e.length;n++)if(this.eq(e[n]))return e.slice(0,n).concat(e.slice(n+1));return e}isInSet(e){for(let n=0;n<e.length;n++)if(this.eq(e[n]))return!0;return!1}eq(e){return this==e||this.type==e.type&&Wr(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let n in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Mark.fromJSON");let r=e.marks[n.type];if(!r)throw new RangeError(`There is no mark type ${n.type} in this schema`);return r.create(n.attrs)}static sameSet(e,n){if(e==n)return!0;if(e.length!=n.length)return!1;for(let r=0;r<e.length;r++)if(!e[r].eq(n[r]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&e.length==0)return We.none;if(e instanceof We)return[e];let n=e.slice();return n.sort((r,a)=>r.type.rank-a.type.rank),n}}We.none=[];class rm extends Error{}class ce{constructor(e,n,r){this.content=e,this.openStart=n,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,n){let r=Ys(this.content,e+this.openStart,n);return r&&new ce(r,this.openStart,this.openEnd)}removeBetween(e,n){return new ce(js(this.content,e+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,n){if(!n)return ce.empty;let r=n.openStart||0,a=n.openEnd||0;if(typeof r!="number"||typeof a!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new ce(se.fromJSON(e,n.content),r,a)}static maxOpen(e,n=!0){let r=0,a=0;for(let o=e.firstChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=e.lastChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.lastChild)a++;return new ce(e,r,a)}}ce.empty=new ce(se.empty,0,0);function js(t,e,n){let{index:r,offset:a}=t.findIndex(e),o=t.maybeChild(r),{index:l,offset:u}=t.findIndex(n);if(a==e||o.isText){if(u!=n&&!t.child(l).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(n))}if(r!=l)throw new RangeError("Removing non-flat range");return t.replaceChild(r,o.copy(js(o.content,e-a-1,n-a-1)))}function Ys(t,e,n,r){let{index:a,offset:o}=t.findIndex(e),l=t.maybeChild(a);if(o==e||l.isText)return r&&!r.canReplace(a,a,n)?null:t.cut(0,e).append(n).append(t.cut(e));let u=Ys(l.content,e-o-1,n);return u&&t.replaceChild(a,l.copy(u))}class On{constructor(e,n){this.schema=e,this.rules=n,this.tags=[],this.styles=[],n.forEach(r=>{r.tag?this.tags.push(r):r.style&&this.styles.push(r)}),this.normalizeLists=!this.tags.some(r=>{if(!/^(ul|ol)\b/.test(r.tag)||!r.node)return!1;let a=e.nodes[r.node];return a.contentMatch.matchType(a)})}parse(e,n={}){let r=new Xs(this,n,!1);return r.addAll(e,n.from,n.to),r.finish()}parseSlice(e,n={}){let r=new Xs(this,n,!0);return r.addAll(e,n.from,n.to),ce.maxOpen(r.finish())}matchTag(e,n,r){for(let a=r?this.tags.indexOf(r)+1:0;a<this.tags.length;a++){let o=this.tags[a];if(sm(e,o.tag)&&(o.namespace===void 0||e.namespaceURI==o.namespace)&&(!o.context||n.matchesContext(o.context))){if(o.getAttrs){let l=o.getAttrs(e);if(l===!1)continue;o.attrs=l||void 0}return o}}}matchStyle(e,n,r,a){for(let o=a?this.styles.indexOf(a)+1:0;o<this.styles.length;o++){let l=this.styles[o],u=l.style;if(!(u.indexOf(e)!=0||l.context&&!r.matchesContext(l.context)||u.length>e.length&&(u.charCodeAt(e.length)!=61||u.slice(e.length+1)!=n))){if(l.getAttrs){let c=l.getAttrs(n);if(c===!1)continue;l.attrs=c||void 0}return l}}}static schemaRules(e){let n=[];function r(a){let o=a.priority==null?50:a.priority,l=0;for(;l<n.length;l++){let u=n[l];if((u.priority==null?50:u.priority)<o)break}n.splice(l,0,a)}for(let a in e.marks){let o=e.marks[a].spec.parseDOM;o&&o.forEach(l=>{r(l=Js(l)),l.mark||l.ignore||l.clearMark||(l.mark=a)})}for(let a in e.nodes){let o=e.nodes[a].spec.parseDOM;o&&o.forEach(l=>{r(l=Js(l)),l.node||l.ignore||l.mark||(l.node=a)})}return n}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new On(e,On.schemaRules(e)))}}const Qs={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},im={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Ks={ol:!0,ul:!0},Pn=1,Bn=2,Zt=4;function Us(t,e,n){return e!=null?(e?Pn:0)|(e==="full"?Bn:0):t&&t.whitespace=="pre"?Pn|Bn:n&~Zt}class Vn{constructor(e,n,r,a,o,l,u){this.type=e,this.attrs=n,this.marks=r,this.pendingMarks=a,this.solid=o,this.options=u,this.content=[],this.activeMarks=We.none,this.stashMarks=[],this.match=l||(u&Zt?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(se.from(e));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let r=this.type.contentMatch,a;return(a=r.findWrapping(e.type))?(this.match=r,a):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&Pn)){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=se.from(this.content);return!e&&this.match&&(n=n.append(this.match.fillBefore(se.empty,!0))),this.type?this.type.create(this.attrs,n,this.marks):n}popFromStashMark(e){for(let n=this.stashMarks.length-1;n>=0;n--)if(e.eq(this.stashMarks[n]))return this.stashMarks.splice(n,1)[0]}applyPending(e){for(let n=0,r=this.pendingMarks;n<r.length;n++){let a=r[n];(this.type?this.type.allowsMarkType(a.type):lm(a.type,e))&&!a.isInSet(this.activeMarks)&&(this.activeMarks=a.addToSet(this.activeMarks),this.pendingMarks=a.removeFromSet(this.pendingMarks))}}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!Qs.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class Xs{constructor(e,n,r){this.parser=e,this.options=n,this.isOpen=r,this.open=0;let a=n.topNode,o,l=Us(null,n.preserveWhitespace,0)|(r?Zt:0);a?o=new Vn(a.type,a.attrs,We.none,We.none,!0,n.topMatch||a.type.contentMatch,l):r?o=new Vn(null,null,We.none,We.none,!0,null,l):o=new Vn(e.schema.topNodeType,null,We.none,We.none,!0,null,l),this.nodes=[o],this.find=n.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e){if(e.nodeType==3)this.addTextNode(e);else if(e.nodeType==1){let n=e.getAttribute("style");if(!n)this.addElement(e);else{let r=this.readStyles(om(n));if(!r)return;let[a,o]=r,l=this.top;for(let u=0;u<o.length;u++)this.removePendingMark(o[u],l);for(let u=0;u<a.length;u++)this.addPendingMark(a[u]);this.addElement(e);for(let u=0;u<a.length;u++)this.removePendingMark(a[u],l);for(let u=0;u<o.length;u++)this.addPendingMark(o[u])}}}addTextNode(e){let n=e.nodeValue,r=this.top;if(r.options&Bn||r.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(r.options&Pn)r.options&Bn?n=n.replace(/\r\n?/g,`
|
|
307
|
+
`):n=n.replace(/\r?\n|\r/g," ");else if(n=n.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let a=r.content[r.content.length-1],o=e.previousSibling;(!a||o&&o.nodeName=="BR"||a.isText&&/[ \t\r\n\u000c]$/.test(a.text))&&(n=n.slice(1))}n&&this.insertNode(this.parser.schema.text(n)),this.findInText(e)}else this.findInside(e)}addElement(e,n){let r=e.nodeName.toLowerCase(),a;Ks.hasOwnProperty(r)&&this.parser.normalizeLists&&am(e);let o=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(a=this.parser.matchTag(e,this,n));if(o?o.ignore:im.hasOwnProperty(r))this.findInside(e),this.ignoreFallback(e);else if(!o||o.skip||o.closeParent){o&&o.closeParent?this.open=Math.max(0,this.open-1):o&&o.skip.nodeType&&(e=o.skip);let l,u=this.top,c=this.needsBlock;if(Qs.hasOwnProperty(r))u.content.length&&u.content[0].isInline&&this.open&&(this.open--,u=this.top),l=!0,u.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e);return}this.addAll(e),l&&this.sync(u),this.needsBlock=c}else this.addElementByRule(e,o,o.consuming===!1?a:void 0)}leafFallback(e){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(`
|
|
308
|
+
`))}ignoreFallback(e){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"))}readStyles(e){let n=We.none,r=We.none;for(let a=0;a<e.length;a+=2)for(let o=void 0;;){let l=this.parser.matchStyle(e[a],e[a+1],this,o);if(!l)break;if(l.ignore)return null;if(l.clearMark?this.top.pendingMarks.concat(this.top.activeMarks).forEach(u=>{l.clearMark(u)&&(r=u.addToSet(r))}):n=this.parser.schema.marks[l.mark].create(l.attrs).addToSet(n),l.consuming===!1)o=l;else break}return[n,r]}addElementByRule(e,n,r){let a,o,l;n.node?(o=this.parser.schema.nodes[n.node],o.isLeaf?this.insertNode(o.create(n.attrs))||this.leafFallback(e):a=this.enter(o,n.attrs||null,n.preserveWhitespace)):(l=this.parser.schema.marks[n.mark].create(n.attrs),this.addPendingMark(l));let u=this.top;if(o&&o.isLeaf)this.findInside(e);else if(r)this.addElement(e,r);else if(n.getContent)this.findInside(e),n.getContent(e,this.parser.schema).forEach(c=>this.insertNode(c));else{let c=e;typeof n.contentElement=="string"?c=e.querySelector(n.contentElement):typeof n.contentElement=="function"?c=n.contentElement(e):n.contentElement&&(c=n.contentElement),this.findAround(e,c,!0),this.addAll(c)}a&&this.sync(u)&&this.open--,l&&this.removePendingMark(l,u)}addAll(e,n,r){let a=n||0;for(let o=n?e.childNodes[n]:e.firstChild,l=r==null?null:e.childNodes[r];o!=l;o=o.nextSibling,++a)this.findAtPoint(e,a),this.addDOM(o);this.findAtPoint(e,a)}findPlace(e){let n,r;for(let a=this.open;a>=0;a--){let o=this.nodes[a],l=o.findWrapping(e);if(l&&(!n||n.length>l.length)&&(n=l,r=o,!l.length)||o.solid)break}if(!n)return!1;this.sync(r);for(let a=0;a<n.length;a++)this.enterInner(n[a],null,!1);return!0}insertNode(e){if(e.isInline&&this.needsBlock&&!this.top.type){let n=this.textblockFromContext();n&&this.enterInner(n)}if(this.findPlace(e)){this.closeExtra();let n=this.top;n.applyPending(e.type),n.match&&(n.match=n.match.matchType(e.type));let r=n.activeMarks;for(let a=0;a<e.marks.length;a++)(!n.type||n.type.allowsMarkType(e.marks[a].type))&&(r=e.marks[a].addToSet(r));return n.content.push(e.mark(r)),!0}return!1}enter(e,n,r){let a=this.findPlace(e.create(n));return a&&this.enterInner(e,n,!0,r),a}enterInner(e,n=null,r=!1,a){this.closeExtra();let o=this.top;o.applyPending(e),o.match=o.match&&o.match.matchType(e);let l=Us(e,a,o.options);o.options&Zt&&o.content.length==0&&(l|=Zt),this.nodes.push(new Vn(e,n,o.activeMarks,o.pendingMarks,r,null,l)),this.open++}closeExtra(e=!1){let n=this.nodes.length-1;if(n>this.open){for(;n>this.open;n--)this.nodes[n-1].content.push(this.nodes[n].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(e){for(let n=this.open;n>=0;n--)if(this.nodes[n]==e)return this.open=n,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let n=this.open;n>=0;n--){let r=this.nodes[n].content;for(let a=r.length-1;a>=0;a--)e+=r[a].nodeSize;n&&e++}return e}findAtPoint(e,n){if(this.find)for(let r=0;r<this.find.length;r++)this.find[r].node==e&&this.find[r].offset==n&&(this.find[r].pos=this.currentPos)}findInside(e){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].pos==null&&e.nodeType==1&&e.contains(this.find[n].node)&&(this.find[n].pos=this.currentPos)}findAround(e,n,r){if(e!=n&&this.find)for(let a=0;a<this.find.length;a++)this.find[a].pos==null&&e.nodeType==1&&e.contains(this.find[a].node)&&n.compareDocumentPosition(this.find[a].node)&(r?2:4)&&(this.find[a].pos=this.currentPos)}findInText(e){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==e&&(this.find[n].pos=this.currentPos-(e.nodeValue.length-this.find[n].offset))}matchesContext(e){if(e.indexOf("|")>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let n=e.split("/"),r=this.options.context,a=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),o=-(r?r.depth+1:0)+(a?0:1),l=(u,c)=>{for(;u>=0;u--){let d=n[u];if(d==""){if(u==n.length-1||u==0)continue;for(;c>=o;c--)if(l(u-1,c))return!0;return!1}else{let f=c>0||c==0&&a?this.nodes[c].type:r&&c>=o?r.node(c-o).type:null;if(!f||f.name!=d&&f.groups.indexOf(d)==-1)return!1;c--}}return!0};return l(n.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let n=e.depth;n>=0;n--){let r=e.node(n).contentMatchAt(e.indexAfter(n)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let n in this.parser.schema.nodes){let r=this.parser.schema.nodes[n];if(r.isTextblock&&r.defaultAttrs)return r}}addPendingMark(e){let n=um(e,this.top.pendingMarks);n&&this.top.stashMarks.push(n),this.top.pendingMarks=e.addToSet(this.top.pendingMarks)}removePendingMark(e,n){for(let r=this.open;r>=0;r--){let a=this.nodes[r];if(a.pendingMarks.lastIndexOf(e)>-1)a.pendingMarks=e.removeFromSet(a.pendingMarks);else{a.activeMarks=e.removeFromSet(a.activeMarks);let l=a.popFromStashMark(e);l&&a.type&&a.type.allowsMarkType(l.type)&&(a.activeMarks=l.addToSet(a.activeMarks))}if(a==n)break}}}function am(t){for(let e=t.firstChild,n=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&Ks.hasOwnProperty(r)&&n?(n.appendChild(e),e=n):r=="li"?n=e:r&&(n=null)}}function sm(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function om(t){let e=/\s*([\w-]+)\s*:\s*([^;]+)/g,n,r=[];for(;n=e.exec(t);)r.push(n[1],n[2].trim());return r}function Js(t){let e={};for(let n in t)e[n]=t[n];return e}function lm(t,e){let n=e.schema.nodes;for(let r in n){let a=n[r];if(!a.allowsMarkType(t))continue;let o=[],l=u=>{o.push(u);for(let c=0;c<u.edgeCount;c++){let{type:d,next:f}=u.edge(c);if(d==e||o.indexOf(f)<0&&l(f))return!0}};if(l(a.contentMatch))return!0}}function um(t,e){for(let n=0;n<e.length;n++)if(t.eq(e[n]))return e[n]}const Zs=65535,Hs=Math.pow(2,16);function cm(t,e){return t+e*Hs}function eo(t){return t&Zs}function dm(t){return(t-(t&Zs))/Hs}const to=1,no=2,Nn=4,ro=8;class io{constructor(e,n,r){this.pos=e,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&ro)>0}get deletedBefore(){return(this.delInfo&(to|Nn))>0}get deletedAfter(){return(this.delInfo&(no|Nn))>0}get deletedAcross(){return(this.delInfo&Nn)>0}}class je{constructor(e,n=!1){if(this.ranges=e,this.inverted=n,!e.length&&je.empty)return je.empty}recover(e){let n=0,r=eo(e);if(!this.inverted)for(let a=0;a<r;a++)n+=this.ranges[a*3+2]-this.ranges[a*3+1];return this.ranges[r*3]+n+dm(e)}mapResult(e,n=1){return this._map(e,n,!1)}map(e,n=1){return this._map(e,n,!0)}_map(e,n,r){let a=0,o=this.inverted?2:1,l=this.inverted?1:2;for(let u=0;u<this.ranges.length;u+=3){let c=this.ranges[u]-(this.inverted?a:0);if(c>e)break;let d=this.ranges[u+o],f=this.ranges[u+l],p=c+d;if(e<=p){let g=d?e==c?-1:e==p?1:n:n,m=c+a+(g<0?0:f);if(r)return m;let C=e==(n<0?c:p)?null:cm(u/3,e-c),w=e==c?no:e==p?to:Nn;return(n<0?e!=c:e!=p)&&(w|=ro),new io(m,w,C)}a+=f-d}return r?e+a:new io(e+a,0,null)}touches(e,n){let r=0,a=eo(n),o=this.inverted?2:1,l=this.inverted?1:2;for(let u=0;u<this.ranges.length;u+=3){let c=this.ranges[u]-(this.inverted?r:0);if(c>e)break;let d=this.ranges[u+o],f=c+d;if(e<=f&&u==a*3)return!0;r+=this.ranges[u+l]-d}return!1}forEach(e){let n=this.inverted?2:1,r=this.inverted?1:2;for(let a=0,o=0;a<this.ranges.length;a+=3){let l=this.ranges[a],u=l-(this.inverted?o:0),c=l+(this.inverted?0:o),d=this.ranges[a+n],f=this.ranges[a+r];e(u,u+d,c,c+f),o+=f-d}}invert(){return new je(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?je.empty:new je(e<0?[0,-e,0]:[0,0,e])}}je.empty=new je([]);const Rr=Object.create(null);class Ge{getMap(){return je.empty}merge(e){return null}static fromJSON(e,n){if(!n||!n.stepType)throw new RangeError("Invalid input for Step.fromJSON");let r=Rr[n.stepType];if(!r)throw new RangeError(`No step type ${n.stepType} defined`);return r.fromJSON(e,n)}static jsonID(e,n){if(e in Rr)throw new RangeError("Duplicate use of step JSON ID "+e);return Rr[e]=n,n.prototype.jsonID=e,n}}class _e{constructor(e,n){this.doc=e,this.failed=n}static ok(e){return new _e(e,null)}static fail(e){return new _e(null,e)}static fromReplace(e,n,r,a){try{return _e.ok(e.replace(n,r,a))}catch(o){if(o instanceof rm)return _e.fail(o.message);throw o}}}function jr(t,e,n){let r=[];for(let a=0;a<t.childCount;a++){let o=t.child(a);o.content.size&&(o=o.copy(jr(o.content,e,o))),o.isInline&&(o=e(o,n,a)),r.push(o)}return se.fromArray(r)}class _t extends Ge{constructor(e,n,r){super(),this.from=e,this.to=n,this.mark=r}apply(e){let n=e.slice(this.from,this.to),r=e.resolve(this.from),a=r.node(r.sharedDepth(this.to)),o=new ce(jr(n.content,(l,u)=>!l.isAtom||!u.type.allowsMarkType(this.mark.type)?l:l.mark(this.mark.addToSet(l.marks)),a),n.openStart,n.openEnd);return _e.fromReplace(e,this.from,this.to,o)}invert(){return new kt(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new _t(n.pos,r.pos,this.mark)}merge(e){return e instanceof _t&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new _t(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new _t(n.from,n.to,e.markFromJSON(n.mark))}}Ge.jsonID("addMark",_t);class kt extends Ge{constructor(e,n,r){super(),this.from=e,this.to=n,this.mark=r}apply(e){let n=e.slice(this.from,this.to),r=new ce(jr(n.content,a=>a.mark(this.mark.removeFromSet(a.marks)),e),n.openStart,n.openEnd);return _e.fromReplace(e,this.from,this.to,r)}invert(){return new _t(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new kt(n.pos,r.pos,this.mark)}merge(e){return e instanceof kt&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new kt(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new kt(n.from,n.to,e.markFromJSON(n.mark))}}Ge.jsonID("removeMark",kt);class Tt extends Ge{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return _e.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return _e.fromReplace(e,this.pos,this.pos+1,new ce(se.from(r),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);if(n){let r=this.mark.addToSet(n.marks);if(r.length==n.marks.length){for(let a=0;a<n.marks.length;a++)if(!n.marks[a].isInSet(r))return new Tt(this.pos,n.marks[a]);return new Tt(this.pos,this.mark)}}return new Ht(this.pos,this.mark)}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new Tt(n.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new Tt(n.pos,e.markFromJSON(n.mark))}}Ge.jsonID("addNodeMark",Tt);class Ht extends Ge{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return _e.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.removeFromSet(n.marks));return _e.fromReplace(e,this.pos,this.pos+1,new ce(se.from(r),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);return!n||!this.mark.isInSet(n.marks)?this:new Tt(this.pos,this.mark)}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new Ht(n.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new Ht(n.pos,e.markFromJSON(n.mark))}}Ge.jsonID("removeNodeMark",Ht);class nt extends Ge{constructor(e,n,r,a=!1){super(),this.from=e,this.to=n,this.slice=r,this.structure=a}apply(e){return this.structure&&Yr(e,this.from,this.to)?_e.fail("Structure replace would overwrite content"):_e.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new je([this.from,this.to-this.from,this.slice.size])}invert(e){return new nt(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deletedAcross&&r.deletedAcross?null:new nt(n.pos,Math.max(n.pos,r.pos),this.slice)}merge(e){if(!(e instanceof nt)||e.structure||this.structure)return null;if(this.from+this.slice.size==e.from&&!this.slice.openEnd&&!e.slice.openStart){let n=this.slice.size+e.slice.size==0?ce.empty:new ce(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new nt(this.from,this.to+(e.to-e.from),n,this.structure)}else if(e.to==this.from&&!this.slice.openStart&&!e.slice.openEnd){let n=this.slice.size+e.slice.size==0?ce.empty:new ce(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new nt(e.from,this.to,n,this.structure)}else return null}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new nt(n.from,n.to,ce.fromJSON(e,n.slice),!!n.structure)}}Ge.jsonID("replace",nt);class Dt extends Ge{constructor(e,n,r,a,o,l,u=!1){super(),this.from=e,this.to=n,this.gapFrom=r,this.gapTo=a,this.slice=o,this.insert=l,this.structure=u}apply(e){if(this.structure&&(Yr(e,this.from,this.gapFrom)||Yr(e,this.gapTo,this.to)))return _e.fail("Structure gap-replace would overwrite content");let n=e.slice(this.gapFrom,this.gapTo);if(n.openStart||n.openEnd)return _e.fail("Gap is not a flat range");let r=this.slice.insertAt(this.insert,n.content);return r?_e.fromReplace(e,this.from,this.to,r):_e.fail("Content does not fit in gap")}getMap(){return new je([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let n=this.gapTo-this.gapFrom;return new Dt(this.from,this.from+this.slice.size+n,this.from+this.insert,this.from+this.insert+n,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1),a=e.map(this.gapFrom,-1),o=e.map(this.gapTo,1);return n.deletedAcross&&r.deletedAcross||a<n.pos||o>r.pos?null:new Dt(n.pos,r.pos,a,o,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number"||typeof n.gapFrom!="number"||typeof n.gapTo!="number"||typeof n.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Dt(n.from,n.to,n.gapFrom,n.gapTo,ce.fromJSON(e,n.slice),n.insert,!!n.structure)}}Ge.jsonID("replaceAround",Dt);function Yr(t,e,n){let r=t.resolve(e),a=n-e,o=r.depth;for(;a>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,a--;if(a>0){let l=r.node(o).maybeChild(r.indexAfter(o));for(;a>0;){if(!l||l.isLeaf)return!0;l=l.firstChild,a--}}return!1}function pm(t,e,n){return(e==0||t.canReplace(e,t.childCount))&&(n==t.childCount||t.canReplace(0,n))}function hm(t){let n=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let r=t.depth;;--r){let a=t.$from.node(r),o=t.$from.index(r),l=t.$to.indexAfter(r);if(r<t.depth&&a.canReplace(o,l,n))return r;if(r==0||a.type.spec.isolating||!pm(a,o,l))break}return null}function qn(t,e,n=1,r){let a=t.resolve(e),o=a.depth-n,l=r&&r[r.length-1]||a.parent;if(o<0||a.parent.type.spec.isolating||!a.parent.canReplace(a.index(),a.parent.childCount)||!l.type.validContent(a.parent.content.cutByIndex(a.index(),a.parent.childCount)))return!1;for(let d=a.depth-1,f=n-2;d>o;d--,f--){let p=a.node(d),g=a.index(d);if(p.type.spec.isolating)return!1;let m=p.content.cutByIndex(g,p.childCount),C=r&&r[f+1];C&&(m=m.replaceChild(0,C.type.create(C.attrs)));let w=r&&r[f]||p;if(!p.canReplace(g+1,p.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 ao(t,e){let n=t.resolve(e),r=n.index();return fm(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function fm(t,e){return!!(t&&e&&!t.isLeaf&&t.canAppend(e))}class en extends Ge{constructor(e,n,r){super(),this.pos=e,this.attr=n,this.value=r}apply(e){let n=e.nodeAt(this.pos);if(!n)return _e.fail("No node at attribute step's position");let r=Object.create(null);for(let o in n.attrs)r[o]=n.attrs[o];r[this.attr]=this.value;let a=n.type.create(r,null,n.marks);return _e.fromReplace(e,this.pos,this.pos+1,new ce(se.from(a),0,n.isLeaf?0:1))}getMap(){return je.empty}invert(e){return new en(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new en(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.pos!="number"||typeof n.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new en(n.pos,n.attr,n.value)}}Ge.jsonID("attr",en);let tn=class extends Error{};tn=function t(e){let n=Error.call(this,e);return n.__proto__=t.prototype,n},tn.prototype=Object.create(Error.prototype),tn.prototype.constructor=tn,tn.prototype.name="TransformError";const Qr=Object.create(null);class me{constructor(e,n,r){this.$anchor=e,this.$head=n,this.ranges=r||[new gm(e.min(n),e.max(n))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let n=0;n<e.length;n++)if(e[n].$from.pos!=e[n].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(e,n=ce.empty){let r=n.content.lastChild,a=null;for(let u=0;u<n.openEnd;u++)a=r,r=r.lastChild;let o=e.steps.length,l=this.ranges;for(let u=0;u<l.length;u++){let{$from:c,$to:d}=l[u],f=e.mapping.slice(o);e.replaceRange(f.map(c.pos),f.map(d.pos),u?ce.empty:n),u==0&&lo(e,o,(r?r.isInline:a&&a.isTextblock)?-1:1)}}replaceWith(e,n){let r=e.steps.length,a=this.ranges;for(let o=0;o<a.length;o++){let{$from:l,$to:u}=a[o],c=e.mapping.slice(r),d=c.map(l.pos),f=c.map(u.pos);o?e.deleteRange(d,f):(e.replaceRangeWith(d,f,n),lo(e,r,n.isInline?-1:1))}}static findFrom(e,n,r=!1){let a=e.parent.inlineContent?new ke(e):Vt(e.node(0),e.parent,e.pos,e.index(),n,r);if(a)return a;for(let o=e.depth-1;o>=0;o--){let l=n<0?Vt(e.node(0),e.node(o),e.before(o+1),e.index(o),n,r):Vt(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,n,r);if(l)return l}return null}static near(e,n=1){return this.findFrom(e,n)||this.findFrom(e,-n)||new ct(e.node(0))}static atStart(e){return Vt(e,e,0,0,1)||new ct(e)}static atEnd(e){return Vt(e,e,e.content.size,e.childCount,-1)||new ct(e)}static fromJSON(e,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=Qr[n.type];if(!r)throw new RangeError(`No selection type ${n.type} defined`);return r.fromJSON(e,n)}static jsonID(e,n){if(e in Qr)throw new RangeError("Duplicate use of selection JSON ID "+e);return Qr[e]=n,n.prototype.jsonID=e,n}getBookmark(){return ke.between(this.$anchor,this.$head).getBookmark()}}me.prototype.visible=!0;class gm{constructor(e,n){this.$from=e,this.$to=n}}let so=!1;function oo(t){!so&&!t.parent.inlineContent&&(so=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")"))}class ke extends me{constructor(e,n=e){oo(e),oo(n),super(e,n)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,n){let r=e.resolve(n.map(this.head));if(!r.parent.inlineContent)return me.near(r);let a=e.resolve(n.map(this.anchor));return new ke(a.parent.inlineContent?a:r,r)}replace(e,n=ce.empty){if(super.replace(e,n),n==ce.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof ke&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Fn(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,n){if(typeof n.anchor!="number"||typeof n.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new ke(e.resolve(n.anchor),e.resolve(n.head))}static create(e,n,r=n){let a=e.resolve(n);return new this(a,r==n?a:e.resolve(r))}static between(e,n,r){let a=e.pos-n.pos;if((!r||a)&&(r=a>=0?1:-1),!n.parent.inlineContent){let o=me.findFrom(n,r,!0)||me.findFrom(n,-r,!0);if(o)n=o.$head;else return me.near(n,r)}return e.parent.inlineContent||(a==0?e=n:(e=(me.findFrom(e,-r,!0)||me.findFrom(e,r,!0)).$anchor,e.pos<n.pos!=a<0&&(e=n))),new ke(e,n)}}me.jsonID("text",ke);class Fn{constructor(e,n){this.anchor=e,this.head=n}map(e){return new Fn(e.map(this.anchor),e.map(this.head))}resolve(e){return ke.between(e.resolve(this.anchor),e.resolve(this.head))}}class Re extends me{constructor(e){let n=e.nodeAfter,r=e.node(0).resolve(e.pos+n.nodeSize);super(e,r),this.node=n}map(e,n){let{deleted:r,pos:a}=n.mapResult(this.anchor),o=e.resolve(a);return r?me.near(o):new Re(o)}content(){return new ce(se.from(this.node),0,0)}eq(e){return e instanceof Re&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new Kr(this.anchor)}static fromJSON(e,n){if(typeof n.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new Re(e.resolve(n.anchor))}static create(e,n){return new Re(e.resolve(n))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}}Re.prototype.visible=!1,me.jsonID("node",Re);class Kr{constructor(e){this.anchor=e}map(e){let{deleted:n,pos:r}=e.mapResult(this.anchor);return n?new Fn(r,r):new Kr(r)}resolve(e){let n=e.resolve(this.anchor),r=n.nodeAfter;return r&&Re.isSelectable(r)?new Re(n):me.near(n)}}class ct extends me{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,n=ce.empty){if(n==ce.empty){e.delete(0,e.doc.content.size);let r=me.atStart(e.doc);r.eq(e.selection)||e.setSelection(r)}else super.replace(e,n)}toJSON(){return{type:"all"}}static fromJSON(e){return new ct(e)}map(e){return new ct(e)}eq(e){return e instanceof ct}getBookmark(){return mm}}me.jsonID("all",ct);const mm={map(){return this},resolve(t){return new ct(t)}};function Vt(t,e,n,r,a,o=!1){if(e.inlineContent)return ke.create(t,n);for(let l=r-(a>0?0:1);a>0?l<e.childCount:l>=0;l+=a){let u=e.child(l);if(u.isAtom){if(!o&&Re.isSelectable(u))return Re.create(t,n-(a<0?u.nodeSize:0))}else{let c=Vt(t,u,n+a,a<0?u.childCount:0,a,o);if(c)return c}n+=u.nodeSize*a}return null}function lo(t,e,n){let r=t.steps.length-1;if(r<e)return;let a=t.steps[r];if(!(a instanceof nt||a instanceof Dt))return;let o=t.mapping.maps[r],l;o.forEach((u,c,d,f)=>{l==null&&(l=f)}),t.setSelection(me.near(t.doc.resolve(l),n))}function uo(t,e){return!e||!t?t:t.bind(e)}class Gn{constructor(e,n,r){this.name=e,this.init=uo(n.init,r),this.apply=uo(n.apply,r)}}new Gn("doc",{init(t){return t.doc||t.schema.topNodeType.createAndFill()},apply(t){return t.doc}}),new Gn("selection",{init(t,e){return t.selection||me.atStart(e.doc)},apply(t){return t.selection}}),new Gn("storedMarks",{init(t){return t.storedMarks||null},apply(t,e,n,r){return r.selection.$cursor?t.storedMarks:null}}),new Gn("scrollToSelection",{init(){return 0},apply(t,e){return t.scrolledIntoView?e+1:e}});function co(t,e,n){for(let r in t){let a=t[r];a instanceof Function?a=a.bind(e):r=="handleDOMEvents"&&(a=co(a,e,{})),n[r]=a}return n}class nn{constructor(e){this.spec=e,this.props={},e.props&&co(e.props,this,this.props),this.key=e.key?e.key.key:po("plugin")}getState(e){return e[this.key]}}const Ur=Object.create(null);function po(t){return t in Ur?t+"$"+ ++Ur[t]:(Ur[t]=0,t+"$")}class rn{constructor(e="key"){this.key=po(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}function ho(t){const{state:e,transaction:n}=t;let{selection:r}=n,{doc:a}=n,{storedMarks:o}=n;return{...e,apply:e.apply.bind(e),applyTransaction:e.applyTransaction.bind(e),filterTransaction:e.filterTransaction,plugins:e.plugins,schema:e.schema,reconfigure:e.reconfigure.bind(e),toJSON:e.toJSON.bind(e),get storedMarks(){return o},get selection(){return r},get doc(){return a},get tr(){return r=n.selection,a=n.doc,o=n.storedMarks,n}}}class ym{constructor(e){this.editor=e.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=e.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){const{rawCommands:e,editor:n,state:r}=this,{view:a}=n,{tr:o}=r,l=this.buildProps(o);return Object.fromEntries(Object.entries(e).map(([u,c])=>[u,(...f)=>{const p=c(...f)(l);return!o.getMeta("preventDispatch")&&!this.hasCustomState&&a.dispatch(o),p}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,n=!0){const{rawCommands:r,editor:a,state:o}=this,{view:l}=a,u=[],c=!!e,d=e||o.tr,f=()=>(!c&&n&&!d.getMeta("preventDispatch")&&!this.hasCustomState&&l.dispatch(d),u.every(g=>g===!0)),p={...Object.fromEntries(Object.entries(r).map(([g,m])=>[g,(...w)=>{const _=this.buildProps(d,n),T=m(...w)(_);return u.push(T),p}])),run:f};return p}createCan(e){const{rawCommands:n,state:r}=this,a=!1,o=e||r.tr,l=this.buildProps(o,a);return{...Object.fromEntries(Object.entries(n).map(([c,d])=>[c,(...f)=>d(...f)({...l,dispatch:void 0})])),chain:()=>this.createChain(o,a)}}buildProps(e,n=!0){const{rawCommands:r,editor:a,state:o}=this,{view:l}=a;o.storedMarks&&e.setStoredMarks(o.storedMarks);const u={tr:e,editor:a,view:l,state:ho({state:o,transaction:e}),dispatch:n?()=>{}:void 0,chain:()=>this.createChain(e),can:()=>this.createCan(e),get commands(){return Object.fromEntries(Object.entries(r).map(([c,d])=>[c,(...f)=>d(...f)(u)]))}};return u}}function bt(t,e,n){return t.config[e]===void 0&&t.parent?bt(t.parent,e,n):typeof t.config[e]=="function"?t.config[e].bind({...n,parent:t.parent?bt(t.parent,e,n):null}):t.config[e]}function bm(t){const e=t.filter(a=>a.type==="extension"),n=t.filter(a=>a.type==="node"),r=t.filter(a=>a.type==="mark");return{baseExtensions:e,nodeExtensions:n,markExtensions:r}}function Le(t,e){if(typeof t=="string"){if(!e.nodes[t])throw Error(`There is no node type named '${t}'. Maybe you forgot to add the extension?`);return e.nodes[t]}return t}function vm(t){return typeof t=="function"}function Nt(t,e=void 0,...n){return vm(t)?e?t.bind(e)(...n):t(...n):t}function xm(t){return Object.prototype.toString.call(t)==="[object RegExp]"}function wm(t){return Object.prototype.toString.call(t).slice(8,-1)}function Xr(t){return wm(t)!=="Object"?!1:t.constructor===Object&&Object.getPrototypeOf(t)===Object.prototype}function fo(t,e){const n={...t};return Xr(t)&&Xr(e)&&Object.keys(e).forEach(r=>{Xr(e[r])?r in t?n[r]=fo(t[r],e[r]):Object.assign(n,{[r]:e[r]}):Object.assign(n,{[r]:e[r]})}),n}class rt{constructor(e={}){this.type="extension",this.name="extension",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=Nt(bt(this,"addOptions",{name:this.name}))),this.storage=Nt(bt(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new rt(e)}configure(e={}){const n=this.extend();return n.options=fo(this.options,e),n.storage=Nt(bt(n,"addStorage",{name:n.name,options:n.options})),n}extend(e={}){const n=new rt(e);return n.parent=this,this.child=n,n.name=e.name?e.name:n.parent.name,e.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${n.name}".`),n.options=Nt(bt(n,"addOptions",{name:n.name})),n.storage=Nt(bt(n,"addStorage",{name:n.name,options:n.options})),n}}function Cm(t,e,n){const{from:r,to:a}=e,{blockSeparator:o=`
|
|
309
309
|
|
|
310
|
-
`,textSerializers:l={}}=n||{};let c="",u=!0;return t.nodesBetween(r,a,(d,f,h,g)=>{var m;const C=l==null?void 0:l[d.type.name];C?(d.isBlock&&!u&&(c+=o,u=!0),h&&(c+=C({node:d,pos:f,parent:h,index:g,range:e}))):d.isText?(c+=(m=d==null?void 0:d.text)===null||m===void 0?void 0:m.slice(Math.max(r,f)-f,a-f),u=!1):d.isBlock&&!u&&(c+=o,u=!0)}),c}function Cm(t){return Object.fromEntries(Object.entries(t.nodes).filter(([,e])=>e.spec.toText).map(([e,n])=>[e,n.spec.toText]))}rt.create({name:"clipboardTextSerializer",addProseMirrorPlugins(){return[new nn({key:new rn("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:t}=this,{state:e,schema:n}=t,{doc:r,selection:a}=e,{ranges:o}=a,l=Math.min(...o.map(f=>f.$from.pos)),c=Math.max(...o.map(f=>f.$to.pos)),u=Cm(n);return wm(r,{from:l,to:c},{textSerializers:u})}}})]}});const Sm=()=>({editor:t,view:e})=>(requestAnimationFrame(()=>{var n;t.isDestroyed||(e.dom.blur(),(n=window==null?void 0:window.getSelection())===null||n===void 0||n.removeAllRanges())}),!0),_m=(t=!1)=>({commands:e})=>e.setContent("",t),km=()=>({state:t,tr:e,dispatch:n})=>{const{selection:r}=e,{ranges:a}=r;return n&&a.forEach(({$from:o,$to:l})=>{t.doc.nodesBetween(o.pos,l.pos,(c,u)=>{if(c.type.isText)return;const{doc:d,mapping:f}=e,h=d.resolve(f.map(u)),g=d.resolve(f.map(u+c.nodeSize)),m=h.blockRange(g);if(!m)return;const C=pm(m);if(c.type.isTextblock){const{defaultType:w}=h.parent.contentMatchAt(h.index());e.setNodeMarkup(m.start,w)}(C||C===0)&&e.lift(m,C)})}),!0},Tm=t=>e=>t(e),Dm=()=>({state:t,dispatch:e})=>De.createParagraphNear(t,e),Im=()=>({tr:t,dispatch:e})=>{const{selection:n}=t,r=n.$anchor.node();if(r.content.size>0)return!1;const a=t.selection.$anchor;for(let o=a.depth;o>0;o-=1)if(a.node(o).type===r.type){if(e){const c=a.before(o),u=a.after(o);t.delete(c,u).scrollIntoView()}return!0}return!1},Mm=t=>({tr:e,state:n,dispatch:r})=>{const a=Le(t,n.schema),o=e.selection.$anchor;for(let l=o.depth;l>0;l-=1)if(o.node(l).type===a){if(r){const u=o.before(l),d=o.after(l);e.delete(u,d).scrollIntoView()}return!0}return!1},Em=t=>({tr:e,dispatch:n})=>{const{from:r,to:a}=t;return n&&e.delete(r,a),!0},Am=()=>({state:t,dispatch:e})=>De.deleteSelection(t,e),zm=()=>({commands:t})=>t.keyboardShortcut("Enter"),$m=()=>({state:t,dispatch:e})=>De.exitCode(t,e);function Wn(t,e,n={strict:!0}){const r=Object.keys(e);return r.length?r.every(a=>n.strict?e[a]===t[a]:vm(e[a])?e[a].test(t[a]):e[a]===t[a]):!0}function Jr(t,e,n={}){return t.find(r=>r.type===e&&Wn(r.attrs,n))}function Lm(t,e,n={}){return!!Jr(t,e,n)}function go(t,e,n={}){if(!t||!e)return;let r=t.parent.childAfter(t.parentOffset);if(t.parentOffset===r.offset&&r.offset!==0&&(r=t.parent.childBefore(t.parentOffset)),!r.node)return;const a=Jr([...r.node.marks],e,n);if(!a)return;let o=r.index,l=t.start()+r.offset,c=o+1,u=l+r.node.nodeSize;for(Jr([...r.node.marks],e,n);o>0&&a.isInSet(t.parent.child(o-1).marks);)o-=1,l-=t.parent.child(o).nodeSize;for(;c<t.parent.childCount&&Lm([...t.parent.child(c).marks],e,n);)u+=t.parent.child(c).nodeSize,c+=1;return{from:l,to:u}}function vt(t,e){if(typeof t=="string"){if(!e.marks[t])throw Error(`There is no mark type named '${t}'. Maybe you forgot to add the extension?`);return e.marks[t]}return t}const Om=(t,e={})=>({tr:n,state:r,dispatch:a})=>{const o=vt(t,r.schema),{doc:l,selection:c}=n,{$from:u,from:d,to:f}=c;if(a){const h=go(u,o,e);if(h&&h.from<=d&&h.to>=f){const g=ke.create(l,h.from,h.to);n.setSelection(g)}}return!0},Pm=t=>e=>{const n=typeof t=="function"?t(e):t;for(let r=0;r<n.length;r+=1)if(n[r](e))return!0;return!1};function mo(t){return t instanceof ke}function It(t=0,e=0,n=0){return Math.min(Math.max(t,e),n)}function Bm(t,e=null){if(!e)return null;const n=me.atStart(t),r=me.atEnd(t);if(e==="start"||e===!0)return n;if(e==="end")return r;const a=n.from,o=r.to;return e==="all"?ke.create(t,It(0,a,o),It(t.content.size,a,o)):ke.create(t,It(e,a,o),It(e,a,o))}function Zr(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}const Vm=(t=null,e={})=>({editor:n,view:r,tr:a,dispatch:o})=>{e={scrollIntoView:!0,...e};const l=()=>{Zr()&&r.dom.focus(),requestAnimationFrame(()=>{n.isDestroyed||(r.focus(),e!=null&&e.scrollIntoView&&n.commands.scrollIntoView())})};if(r.hasFocus()&&t===null||t===!1)return!0;if(o&&t===null&&!mo(n.state.selection))return l(),!0;const c=Bm(a.doc,t)||n.state.selection,u=n.state.selection.eq(c);return o&&(u||a.setSelection(c),u&&a.storedMarks&&a.setStoredMarks(a.storedMarks),l()),!0},Nm=(t,e)=>n=>t.every((r,a)=>e(r,{...n,index:a})),qm=(t,e)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},t,e);function yo(t){const e=`<body>${t}</body>`;return new window.DOMParser().parseFromString(e,"text/html").body}function Rn(t,e,n){if(n={slice:!0,parseOptions:{},...n},typeof t=="object"&&t!==null)try{return Array.isArray(t)&&t.length>0?se.fromArray(t.map(r=>e.nodeFromJSON(r))):e.nodeFromJSON(t)}catch(r){return console.warn("[tiptap warn]: Invalid content.","Passed value:",t,"Error:",r),Rn("",e,n)}if(typeof t=="string"){const r=On.fromSchema(e);return n.slice?r.parseSlice(yo(t),n.parseOptions).content:r.parse(yo(t),n.parseOptions)}return Rn("",e,n)}function Fm(t,e,n){const r=t.steps.length-1;if(r<e)return;const a=t.steps[r];if(!(a instanceof nt||a instanceof Dt))return;const o=t.mapping.maps[r];let l=0;o.forEach((c,u,d,f)=>{l===0&&(l=f)}),t.setSelection(me.near(t.doc.resolve(l),n))}const Gm=t=>t.toString().startsWith("<"),Wm=(t,e,n)=>({tr:r,dispatch:a,editor:o})=>{if(a){n={parseOptions:{},updateSelection:!0,...n};const l=Rn(e,o.schema,{parseOptions:{preserveWhitespace:"full",...n.parseOptions}});if(l.toString()==="<>")return!0;let{from:c,to:u}=typeof t=="number"?{from:t,to:t}:t,d=!0,f=!0;if((Gm(l)?l:[l]).forEach(g=>{g.check(),d=d?g.isText&&g.marks.length===0:!1,f=f?g.isBlock:!1}),c===u&&f){const{parent:g}=r.doc.resolve(c);g.isTextblock&&!g.type.spec.code&&!g.childCount&&(c-=1,u+=1)}d?Array.isArray(e)?r.insertText(e.map(g=>g.text||"").join(""),c,u):typeof e=="object"&&e&&e.text?r.insertText(e.text,c,u):r.insertText(e,c,u):r.replaceWith(c,u,l),n.updateSelection&&Fm(r,r.steps.length-1,-1)}return!0},Rm=()=>({state:t,dispatch:e})=>De.joinUp(t,e),jm=()=>({state:t,dispatch:e})=>De.joinDown(t,e),Ym=()=>({state:t,dispatch:e})=>De.joinBackward(t,e),Qm=()=>({state:t,dispatch:e})=>De.joinForward(t,e);function bo(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function Km(t){const e=t.split(/-(?!$)/);let n=e[e.length-1];n==="Space"&&(n=" ");let r,a,o,l;for(let c=0;c<e.length-1;c+=1){const u=e[c];if(/^(cmd|meta|m)$/i.test(u))l=!0;else if(/^a(lt)?$/i.test(u))r=!0;else if(/^(c|ctrl|control)$/i.test(u))a=!0;else if(/^s(hift)?$/i.test(u))o=!0;else if(/^mod$/i.test(u))Zr()||bo()?l=!0:a=!0;else throw new Error(`Unrecognized modifier name: ${u}`)}return r&&(n=`Alt-${n}`),a&&(n=`Ctrl-${n}`),l&&(n=`Meta-${n}`),o&&(n=`Shift-${n}`),n}const Um=t=>({editor:e,view:n,tr:r,dispatch:a})=>{const o=Km(t).split(/-(?!$)/),l=o.find(d=>!["Alt","Ctrl","Meta","Shift"].includes(d)),c=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}),u=e.captureTransaction(()=>{n.someProp("handleKeyDown",d=>d(n,c))});return u==null||u.steps.forEach(d=>{const f=d.map(r.mapping);f&&a&&r.maybeStep(f)}),!0};function Hr(t,e,n={}){const{from:r,to:a,empty:o}=t.selection,l=e?Le(e,t.schema):null,c=[];t.doc.nodesBetween(r,a,(h,g)=>{if(h.isText)return;const m=Math.max(r,g),C=Math.min(a,g+h.nodeSize);c.push({node:h,from:m,to:C})});const u=a-r,d=c.filter(h=>l?l.name===h.node.type.name:!0).filter(h=>Wn(h.node.attrs,n,{strict:!1}));return o?!!d.length:d.reduce((h,g)=>h+g.to-g.from,0)>=u}const Xm=(t,e={})=>({state:n,dispatch:r})=>{const a=Le(t,n.schema);return Hr(n,a,e)?De.lift(n,r):!1},Jm=()=>({state:t,dispatch:e})=>De.liftEmptyBlock(t,e),Zm=t=>({state:e,dispatch:n})=>{const r=Le(t,e.schema);return cr.liftListItem(r)(e,n)},Hm=()=>({state:t,dispatch:e})=>De.newlineInCode(t,e);function vo(t,e){return e.nodes[t]?"node":e.marks[t]?"mark":null}function xo(t,e){const n=typeof e=="string"?[e]:e;return Object.keys(t).reduce((r,a)=>(n.includes(a)||(r[a]=t[a]),r),{})}const ey=(t,e)=>({tr:n,state:r,dispatch:a})=>{let o=null,l=null;const c=vo(typeof t=="string"?t:t.name,r.schema);return c?(c==="node"&&(o=Le(t,r.schema)),c==="mark"&&(l=vt(t,r.schema)),a&&n.selection.ranges.forEach(u=>{r.doc.nodesBetween(u.$from.pos,u.$to.pos,(d,f)=>{o&&o===d.type&&n.setNodeMarkup(f,void 0,xo(d.attrs,e)),l&&d.marks.length&&d.marks.forEach(h=>{l===h.type&&n.addMark(f,f+d.nodeSize,l.create(xo(h.attrs,e)))})})}),!0):!1},ty=()=>({tr:t,dispatch:e})=>(e&&t.scrollIntoView(),!0),ny=()=>({tr:t,commands:e})=>e.setTextSelection({from:0,to:t.doc.content.size}),ry=()=>({state:t,dispatch:e})=>De.selectNodeBackward(t,e),iy=()=>({state:t,dispatch:e})=>De.selectNodeForward(t,e),ay=()=>({state:t,dispatch:e})=>De.selectParentNode(t,e),sy=()=>({state:t,dispatch:e})=>De.selectTextblockEnd(t,e),oy=()=>({state:t,dispatch:e})=>De.selectTextblockStart(t,e);function ly(t,e,n={}){return Rn(t,e,{slice:!1,parseOptions:n})}const cy=(t,e=!1,n={})=>({tr:r,editor:a,dispatch:o})=>{const{doc:l}=r,c=ly(t,a.schema,n);return o&&r.replaceWith(0,l.content.size,c).setMeta("preventUpdate",!e),!0};function uy(t){for(let e=0;e<t.edgeCount;e+=1){const{type:n}=t.edge(e);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}function dy(t,e){for(let n=t.depth;n>0;n-=1){const r=t.node(n);if(e(r))return{pos:n>0?t.before(n):0,start:t.start(n),depth:n,node:r}}}function ei(t){return e=>dy(e.$from,t)}function py(t,e){const n=vt(e,t.schema),{from:r,to:a,empty:o}=t.selection,l=[];o?(t.storedMarks&&l.push(...t.storedMarks),l.push(...t.selection.$head.marks())):t.doc.nodesBetween(r,a,u=>{l.push(...u.marks)});const c=l.find(u=>u.type.name===n.name);return c?{...c.attrs}:{}}function jn(t,e,n){return Object.fromEntries(Object.entries(n).filter(([r])=>{const a=t.find(o=>o.type===e&&o.name===r);return a?a.attribute.keepOnSplit:!1}))}function hy(t,e,n={}){const{empty:r,ranges:a}=t.selection,o=e?vt(e,t.schema):null;if(r)return!!(t.storedMarks||t.selection.$from.marks()).filter(h=>o?o.name===h.type.name:!0).find(h=>Wn(h.attrs,n,{strict:!1}));let l=0;const c=[];if(a.forEach(({$from:h,$to:g})=>{const m=h.pos,C=g.pos;t.doc.nodesBetween(m,C,(w,_)=>{if(!w.isText&&!w.marks.length)return;const T=Math.max(m,_),M=Math.min(C,_+w.nodeSize),O=M-T;l+=O,c.push(...w.marks.map(B=>({mark:B,from:T,to:M})))})}),l===0)return!1;const u=c.filter(h=>o?o.name===h.mark.type.name:!0).filter(h=>Wn(h.mark.attrs,n,{strict:!1})).reduce((h,g)=>h+g.to-g.from,0),d=c.filter(h=>o?h.mark.type!==o&&h.mark.type.excludes(o):!0).reduce((h,g)=>h+g.to-g.from,0);return(u>0?u+d:u)>=l}function wo(t,e){const{nodeExtensions:n}=ym(e),r=n.find(l=>l.name===t);if(!r)return!1;const a={name:r.name,options:r.options,storage:r.storage},o=Nt(bt(r,"group",a));return typeof o!="string"?!1:o.split(" ").includes("list")}function fy(t,e,n){var r;const{selection:a}=e;let o=null;if(mo(a)&&(o=a.$cursor),o){const c=(r=t.storedMarks)!==null&&r!==void 0?r:o.marks();return!!n.isInSet(c)||!c.some(u=>u.type.excludes(n))}const{ranges:l}=a;return l.some(({$from:c,$to:u})=>{let d=c.depth===0?t.doc.inlineContent&&t.doc.type.allowsMarkType(n):!1;return t.doc.nodesBetween(c.pos,u.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 gy=(t,e={})=>({tr:n,state:r,dispatch:a})=>{const{selection:o}=n,{empty:l,ranges:c}=o,u=vt(t,r.schema);if(a)if(l){const d=py(r,u);n.addStoredMark(u.create({...d,...e}))}else c.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===u)?g.marks.forEach(T=>{u===T.type&&n.addMark(C,w,u.create({...T.attrs,...e}))}):n.addMark(C,w,u.create(e))})});return fy(r,n,u)},my=(t,e)=>({tr:n})=>(n.setMeta(t,e),!0),yy=(t,e={})=>({state:n,dispatch:r,chain:a})=>{const o=Le(t,n.schema);return o.isTextblock?a().command(({commands:l})=>De.setBlockType(o,e)(n)?!0:l.clearNodes()).command(({state:l})=>De.setBlockType(o,e)(l,r)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},by=t=>({tr:e,dispatch:n})=>{if(n){const{doc:r}=e,a=It(t,0,r.content.size),o=Re.create(r,a);e.setSelection(o)}return!0},vy=t=>({tr:e,dispatch:n})=>{if(n){const{doc:r}=e,{from:a,to:o}=typeof t=="number"?{from:t,to:t}:t,l=ke.atStart(r).from,c=ke.atEnd(r).to,u=It(a,l,c),d=It(o,l,c),f=ke.create(r,u,d);e.setSelection(f)}return!0},xy=t=>({state:e,dispatch:n})=>{const r=Le(t,e.schema);return cr.sinkListItem(r)(e,n)};function Co(t,e){const n=t.storedMarks||t.selection.$to.parentOffset&&t.selection.$from.marks();if(n){const r=n.filter(a=>e==null?void 0:e.includes(a.type.name));t.tr.ensureMarks(r)}}const wy=({keepMarks:t=!0}={})=>({tr:e,state:n,dispatch:r,editor:a})=>{const{selection:o,doc:l}=e,{$from:c,$to:u}=o,d=a.extensionManager.attributes,f=jn(d,c.node().type.name,c.node().attrs);if(o instanceof Re&&o.node.isBlock)return!c.parentOffset||!qn(l,c.pos)?!1:(r&&(t&&Co(n,a.extensionManager.splittableMarks),e.split(c.pos).scrollIntoView()),!0);if(!c.parent.isBlock)return!1;if(r){const h=u.parentOffset===u.parent.content.size;o instanceof ke&&e.deleteSelection();const g=c.depth===0?void 0:uy(c.node(-1).contentMatchAt(c.indexAfter(-1)));let m=h&&g?[{type:g,attrs:f}]:void 0,C=qn(e.doc,e.mapping.map(c.pos),1,m);if(!m&&!C&&qn(e.doc,e.mapping.map(c.pos),1,g?[{type:g}]:void 0)&&(C=!0,m=g?[{type:g,attrs:f}]:void 0),C&&(e.split(e.mapping.map(c.pos),1,m),g&&!h&&!c.parentOffset&&c.parent.type!==g)){const w=e.mapping.map(c.before()),_=e.doc.resolve(w);c.node(-1).canReplaceWith(_.index(),_.index()+1,g)&&e.setNodeMarkup(e.mapping.map(c.before()),g)}t&&Co(n,a.extensionManager.splittableMarks),e.scrollIntoView()}return!0},Cy=t=>({tr:e,state:n,dispatch:r,editor:a})=>{var o;const l=Le(t,n.schema),{$from:c,$to:u}=n.selection,d=n.selection.node;if(d&&d.isBlock||c.depth<2||!c.sameParent(u))return!1;const f=c.node(-1);if(f.type!==l)return!1;const h=a.extensionManager.attributes;if(c.parent.content.size===0&&c.node(-1).childCount===c.indexAfter(-1)){if(c.depth===2||c.node(-3).type!==l||c.index(-2)!==c.node(-2).childCount-1)return!1;if(r){let _=se.empty;const T=c.index(-1)?1:c.index(-2)?2:3;for(let E=c.depth-T;E>=c.depth-3;E-=1)_=se.from(c.node(E).copy(_));const M=c.indexAfter(-1)<c.node(-2).childCount?1:c.indexAfter(-2)<c.node(-3).childCount?2:3,O=jn(h,c.node().type.name,c.node().attrs),B=((o=l.contentMatch.defaultType)===null||o===void 0?void 0:o.createAndFill(O))||void 0;_=_.append(se.from(l.createAndFill(null,B)||void 0));const F=c.before(c.depth-(T-1));e.replace(F,c.after(-M),new ue(_,4-T,0));let $=-1;e.doc.nodesBetween(F,e.doc.content.size,(E,z)=>{if($>-1)return!1;E.isTextblock&&E.content.size===0&&($=z+1)}),$>-1&&e.setSelection(ke.near(e.doc.resolve($))),e.scrollIntoView()}return!0}const g=u.pos===c.end()?f.contentMatchAt(0).defaultType:null,m=jn(h,f.type.name,f.attrs),C=jn(h,c.node().type.name,c.node().attrs);e.delete(c.pos,u.pos);const w=g?[{type:l,attrs:m},{type:g,attrs:C}]:[{type:l,attrs:m}];if(!qn(e.doc,c.pos,2))return!1;if(r){const{selection:_,storedMarks:T}=n,{splittableMarks:M}=a.extensionManager,O=T||_.$to.parentOffset&&_.$from.marks();if(e.split(c.pos,2,w).scrollIntoView(),!O||!r)return!0;const B=O.filter(F=>M.includes(F.type.name));e.ensureMarks(B)}return!0},ti=(t,e)=>{const n=ei(l=>l.type===e)(t.selection);if(!n)return!0;const r=t.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(r===void 0)return!0;const a=t.doc.nodeAt(r);return n.node.type===(a==null?void 0:a.type)&&ao(t.doc,n.pos)&&t.join(n.pos),!0},ni=(t,e)=>{const n=ei(l=>l.type===e)(t.selection);if(!n)return!0;const r=t.doc.resolve(n.start).after(n.depth);if(r===void 0)return!0;const a=t.doc.nodeAt(r);return n.node.type===(a==null?void 0:a.type)&&ao(t.doc,r)&&t.join(r),!0};var Sy=Object.freeze({__proto__:null,blur:Sm,clearContent:_m,clearNodes:km,command:Tm,createParagraphNear:Dm,deleteCurrentNode:Im,deleteNode:Mm,deleteRange:Em,deleteSelection:Am,enter:zm,exitCode:$m,extendMarkRange:Om,first:Pm,focus:Vm,forEach:Nm,insertContent:qm,insertContentAt:Wm,joinUp:Rm,joinDown:jm,joinBackward:Ym,joinForward:Qm,keyboardShortcut:Um,lift:Xm,liftEmptyBlock:Jm,liftListItem:Zm,newlineInCode:Hm,resetAttributes:ey,scrollIntoView:ty,selectAll:ny,selectNodeBackward:ry,selectNodeForward:iy,selectParentNode:ay,selectTextblockEnd:sy,selectTextblockStart:oy,setContent:cy,setMark:gy,setMeta:my,setNode:yy,setNodeSelection:by,setTextSelection:vy,sinkListItem:xy,splitBlock:wy,splitListItem:Cy,toggleList:(t,e,n,r={})=>({editor:a,tr:o,state:l,dispatch:c,chain:u,commands:d,can:f})=>{const{extensions:h,splittableMarks:g}=a.extensionManager,m=Le(t,l.schema),C=Le(e,l.schema),{selection:w,storedMarks:_}=l,{$from:T,$to:M}=w,O=T.blockRange(M),B=_||w.$to.parentOffset&&w.$from.marks();if(!O)return!1;const F=ei($=>wo($.type.name,h))(w);if(O.depth>=1&&F&&O.depth-F.depth<=1){if(F.node.type===m)return d.liftListItem(C);if(wo(F.node.type.name,h)&&m.validContent(F.node.content)&&c)return u().command(()=>(o.setNodeMarkup(F.pos,m),!0)).command(()=>ti(o,m)).command(()=>ni(o,m)).run()}return!n||!B||!c?u().command(()=>f().wrapInList(m,r)?!0:d.clearNodes()).wrapInList(m,r).command(()=>ti(o,m)).command(()=>ni(o,m)).run():u().command(()=>{const $=f().wrapInList(m,r),E=B.filter(z=>g.includes(z.type.name));return o.ensureMarks(E),$?!0:d.clearNodes()}).wrapInList(m,r).command(()=>ti(o,m)).command(()=>ni(o,m)).run()},toggleMark:(t,e={},n={})=>({state:r,commands:a})=>{const{extendEmptyMarkRange:o=!1}=n,l=vt(t,r.schema);return hy(r,l,e)?a.unsetMark(l,{extendEmptyMarkRange:o}):a.setMark(l,e)},toggleNode:(t,e,n={})=>({state:r,commands:a})=>{const o=Le(t,r.schema),l=Le(e,r.schema);return Hr(r,o,n)?a.setNode(l):a.setNode(o,n)},toggleWrap:(t,e={})=>({state:n,commands:r})=>{const a=Le(t,n.schema);return Hr(n,a,e)?r.lift(a):r.wrapIn(a,e)},undoInputRule:()=>({state:t,dispatch:e})=>{const n=t.plugins;for(let r=0;r<n.length;r+=1){const a=n[r];let o;if(a.spec.isInputRules&&(o=a.getState(t))){if(e){const l=t.tr,c=o.transform;for(let u=c.steps.length-1;u>=0;u-=1)l.step(c.steps[u].invert(c.docs[u]));if(o.text){const u=l.doc.resolve(o.from).marks();l.replaceWith(o.from,o.to,t.schema.text(o.text,u))}else l.delete(o.from,o.to)}return!0}}return!1},unsetAllMarks:()=>({tr:t,dispatch:e})=>{const{selection:n}=t,{empty:r,ranges:a}=n;return r||e&&a.forEach(o=>{t.removeMark(o.$from.pos,o.$to.pos)}),!0},unsetMark:(t,e={})=>({tr:n,state:r,dispatch:a})=>{var o;const{extendEmptyMarkRange:l=!1}=e,{selection:c}=n,u=vt(t,r.schema),{$from:d,empty:f,ranges:h}=c;if(!a)return!0;if(f&&l){let{from:g,to:m}=c;const C=(o=d.marks().find(_=>_.type===u))===null||o===void 0?void 0:o.attrs,w=go(d,u,C);w&&(g=w.from,m=w.to),n.removeMark(g,m,u)}else h.forEach(g=>{n.removeMark(g.$from.pos,g.$to.pos,u)});return n.removeStoredMark(u),!0},updateAttributes:(t,e={})=>({tr:n,state:r,dispatch:a})=>{let o=null,l=null;const c=vo(typeof t=="string"?t:t.name,r.schema);return c?(c==="node"&&(o=Le(t,r.schema)),c==="mark"&&(l=vt(t,r.schema)),a&&n.selection.ranges.forEach(u=>{const d=u.$from.pos,f=u.$to.pos;r.doc.nodesBetween(d,f,(h,g)=>{o&&o===h.type&&n.setNodeMarkup(g,void 0,{...h.attrs,...e}),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,...e}))}})})}),!0):!1},wrapIn:(t,e={})=>({state:n,dispatch:r})=>{const a=Le(t,n.schema);return De.wrapIn(a,e)(n,r)},wrapInList:(t,e={})=>({state:n,dispatch:r})=>{const a=Le(t,n.schema);return cr.wrapInList(a,e)(n,r)}});rt.create({name:"commands",addCommands(){return{...Sy}}}),rt.create({name:"editable",addProseMirrorPlugins(){return[new nn({key:new rn("editable"),props:{editable:()=>this.editor.options.editable}})]}}),rt.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:t}=this;return[new nn({key:new rn("focusEvents"),props:{handleDOMEvents:{focus:(e,n)=>{t.isFocused=!0;const r=t.state.tr.setMeta("focus",{event:n}).setMeta("addToHistory",!1);return e.dispatch(r),!1},blur:(e,n)=>{t.isFocused=!1;const r=t.state.tr.setMeta("blur",{event:n}).setMeta("addToHistory",!1);return e.dispatch(r),!1}}}})]}}),rt.create({name:"keymap",addKeyboardShortcuts(){const t=()=>this.editor.commands.first(({commands:l})=>[()=>l.undoInputRule(),()=>l.command(({tr:c})=>{const{selection:u,doc:d}=c,{empty:f,$anchor:h}=u,{pos:g,parent:m}=h,C=me.atStart(d).from===g;return!f||!C||!m.type.isTextblock||m.textContent.length?!1:l.clearNodes()}),()=>l.deleteSelection(),()=>l.joinBackward(),()=>l.selectNodeBackward()]),e=()=>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:t,"Mod-Backspace":t,"Shift-Backspace":t,Delete:e,"Mod-Delete":e,"Mod-a":()=>this.editor.commands.selectAll()},a={...r},o={...r,"Ctrl-h":t,"Alt-Backspace":t,"Ctrl-d":e,"Ctrl-Alt-Backspace":e,"Alt-Delete":e,"Alt-d":e,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return Zr()||bo()?o:a},addProseMirrorPlugins(){return[new nn({key:new rn("clearDocument"),appendTransaction:(t,e,n)=>{if(!(t.some(C=>C.docChanged)&&!e.doc.eq(n.doc)))return;const{empty:a,from:o,to:l}=e.selection,c=me.atStart(e.doc).from,u=me.atEnd(e.doc).to;if(a||!(o===c&&l===u)||!(n.doc.textBetween(0,n.doc.content.size," "," ").length===0))return;const h=n.tr,g=ho({state:n,transaction:h}),{commands:m}=new mm({editor:this.editor,state:g});if(m.clearNodes(),!!h.steps.length)return h}})]}}),rt.create({name:"tabindex",addProseMirrorPlugins(){return[new nn({key:new rn("tabindex"),props:{attributes:this.editor.isEditable?{tabindex:"0"}:{}}})]}});const So=rt.create({name:"fontSize",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{fontSize:{default:null,parseHTML:t=>t.style.fontSize.replace(/['"]+/g,""),renderHTML:t=>t.fontSize?{style:`font-size: ${t.fontSize}`}:{}}}}]},addCommands(){return{setFontSize:t=>({chain:e})=>e().setMark("textStyle",{fontSize:t}).run(),unsetFontSize:()=>({chain:t})=>t().setMark("textStyle",{fontSize:null}).removeEmptyTextStyle().run()}}}),_y=["8","10","12","14","16","18","20","24","30","36","48","60","72"].map(t=>`${t}px`),ky=[{label:"auto",value:""}].concat(_y.map(t=>({label:t,value:t}))),Ty={input:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important"}},Dy=({editor:t})=>{const e=t.getAttributes("textStyle").fontSize;return i(Z.RichTextEditor.ControlsGroup,{children:i(s.NativeSelect,{size:"xs",icon:i(L.IconTextSize,{stroke:1.5,size:16}),data:ky,styles:Ty,value:e||"",onChange:n=>{const r=n.currentTarget.value;r?t.chain().focus().setFontSize(r).run():t.chain().focus().unsetFontSize().run()}})})},Yn=({value:t,styles:e={}})=>{const n=Oa.useEditor({extensions:[Pa,La,Z.Link,Da,Ta,_a,Ea.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),$a,za,Aa,Ia.configure({types:["heading","paragraph"]}),ka.configure({placeholder:"This is placeholder"}),Ma,Sa.Color,So],content:t,editable:!1});y.useEffect(()=>{n==null||n.commands.setContent(t)},[t,n]);const r=y.useMemo(()=>x.defaultsDeep({},{content:Fr},e),[e]);return i(Z.RichTextEditor,{editor:n,styles:r,children:i(Z.RichTextEditor.Content,{})})};function Iy(t,e){const n={};return t.forEach(r=>{const{name:a,data_field:o,aggregation:l}=r,c=kn(e,o,l);n[a]=ct(r,c)}),n}function My(t){const e=document.createElement("span");return e.innerHTML=t,e.innerText}function Ey(t,e,n){try{return new Function("payload",`
|
|
310
|
+
`,textSerializers:l={}}=n||{};let u="",c=!0;return t.nodesBetween(r,a,(d,f,p,g)=>{var m;const C=l==null?void 0:l[d.type.name];C?(d.isBlock&&!c&&(u+=o,c=!0),p&&(u+=C({node:d,pos:f,parent:p,index:g,range:e}))):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 Sm(t){return Object.fromEntries(Object.entries(t.nodes).filter(([,e])=>e.spec.toText).map(([e,n])=>[e,n.spec.toText]))}rt.create({name:"clipboardTextSerializer",addProseMirrorPlugins(){return[new nn({key:new rn("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:t}=this,{state:e,schema:n}=t,{doc:r,selection:a}=e,{ranges:o}=a,l=Math.min(...o.map(f=>f.$from.pos)),u=Math.max(...o.map(f=>f.$to.pos)),c=Sm(n);return Cm(r,{from:l,to:u},{textSerializers:c})}}})]}});const _m=()=>({editor:t,view:e})=>(requestAnimationFrame(()=>{var n;t.isDestroyed||(e.dom.blur(),(n=window==null?void 0:window.getSelection())===null||n===void 0||n.removeAllRanges())}),!0),km=(t=!1)=>({commands:e})=>e.setContent("",t),Tm=()=>({state:t,tr:e,dispatch:n})=>{const{selection:r}=e,{ranges:a}=r;return n&&a.forEach(({$from:o,$to:l})=>{t.doc.nodesBetween(o.pos,l.pos,(u,c)=>{if(u.type.isText)return;const{doc:d,mapping:f}=e,p=d.resolve(f.map(c)),g=d.resolve(f.map(c+u.nodeSize)),m=p.blockRange(g);if(!m)return;const C=hm(m);if(u.type.isTextblock){const{defaultType:w}=p.parent.contentMatchAt(p.index());e.setNodeMarkup(m.start,w)}(C||C===0)&&e.lift(m,C)})}),!0},Dm=t=>e=>t(e),Im=()=>({state:t,dispatch:e})=>De.createParagraphNear(t,e),Mm=()=>({tr:t,dispatch:e})=>{const{selection:n}=t,r=n.$anchor.node();if(r.content.size>0)return!1;const a=t.selection.$anchor;for(let o=a.depth;o>0;o-=1)if(a.node(o).type===r.type){if(e){const u=a.before(o),c=a.after(o);t.delete(u,c).scrollIntoView()}return!0}return!1},Em=t=>({tr:e,state:n,dispatch:r})=>{const a=Le(t,n.schema),o=e.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);e.delete(c,d).scrollIntoView()}return!0}return!1},Am=t=>({tr:e,dispatch:n})=>{const{from:r,to:a}=t;return n&&e.delete(r,a),!0},zm=()=>({state:t,dispatch:e})=>De.deleteSelection(t,e),$m=()=>({commands:t})=>t.keyboardShortcut("Enter"),Lm=()=>({state:t,dispatch:e})=>De.exitCode(t,e);function Wn(t,e,n={strict:!0}){const r=Object.keys(e);return r.length?r.every(a=>n.strict?e[a]===t[a]:xm(e[a])?e[a].test(t[a]):e[a]===t[a]):!0}function Jr(t,e,n={}){return t.find(r=>r.type===e&&Wn(r.attrs,n))}function Om(t,e,n={}){return!!Jr(t,e,n)}function go(t,e,n={}){if(!t||!e)return;let r=t.parent.childAfter(t.parentOffset);if(t.parentOffset===r.offset&&r.offset!==0&&(r=t.parent.childBefore(t.parentOffset)),!r.node)return;const a=Jr([...r.node.marks],e,n);if(!a)return;let o=r.index,l=t.start()+r.offset,u=o+1,c=l+r.node.nodeSize;for(Jr([...r.node.marks],e,n);o>0&&a.isInSet(t.parent.child(o-1).marks);)o-=1,l-=t.parent.child(o).nodeSize;for(;u<t.parent.childCount&&Om([...t.parent.child(u).marks],e,n);)c+=t.parent.child(u).nodeSize,u+=1;return{from:l,to:c}}function vt(t,e){if(typeof t=="string"){if(!e.marks[t])throw Error(`There is no mark type named '${t}'. Maybe you forgot to add the extension?`);return e.marks[t]}return t}const Pm=(t,e={})=>({tr:n,state:r,dispatch:a})=>{const o=vt(t,r.schema),{doc:l,selection:u}=n,{$from:c,from:d,to:f}=u;if(a){const p=go(c,o,e);if(p&&p.from<=d&&p.to>=f){const g=ke.create(l,p.from,p.to);n.setSelection(g)}}return!0},Bm=t=>e=>{const n=typeof t=="function"?t(e):t;for(let r=0;r<n.length;r+=1)if(n[r](e))return!0;return!1};function mo(t){return t instanceof ke}function It(t=0,e=0,n=0){return Math.min(Math.max(t,e),n)}function Vm(t,e=null){if(!e)return null;const n=me.atStart(t),r=me.atEnd(t);if(e==="start"||e===!0)return n;if(e==="end")return r;const a=n.from,o=r.to;return e==="all"?ke.create(t,It(0,a,o),It(t.content.size,a,o)):ke.create(t,It(e,a,o),It(e,a,o))}function Zr(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}const Nm=(t=null,e={})=>({editor:n,view:r,tr:a,dispatch:o})=>{e={scrollIntoView:!0,...e};const l=()=>{Zr()&&r.dom.focus(),requestAnimationFrame(()=>{n.isDestroyed||(r.focus(),e!=null&&e.scrollIntoView&&n.commands.scrollIntoView())})};if(r.hasFocus()&&t===null||t===!1)return!0;if(o&&t===null&&!mo(n.state.selection))return l(),!0;const u=Vm(a.doc,t)||n.state.selection,c=n.state.selection.eq(u);return o&&(c||a.setSelection(u),c&&a.storedMarks&&a.setStoredMarks(a.storedMarks),l()),!0},qm=(t,e)=>n=>t.every((r,a)=>e(r,{...n,index:a})),Fm=(t,e)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},t,e);function yo(t){const e=`<body>${t}</body>`;return new window.DOMParser().parseFromString(e,"text/html").body}function Rn(t,e,n){if(n={slice:!0,parseOptions:{},...n},typeof t=="object"&&t!==null)try{return Array.isArray(t)&&t.length>0?se.fromArray(t.map(r=>e.nodeFromJSON(r))):e.nodeFromJSON(t)}catch(r){return console.warn("[tiptap warn]: Invalid content.","Passed value:",t,"Error:",r),Rn("",e,n)}if(typeof t=="string"){const r=On.fromSchema(e);return n.slice?r.parseSlice(yo(t),n.parseOptions).content:r.parse(yo(t),n.parseOptions)}return Rn("",e,n)}function Gm(t,e,n){const r=t.steps.length-1;if(r<e)return;const a=t.steps[r];if(!(a instanceof nt||a instanceof Dt))return;const o=t.mapping.maps[r];let l=0;o.forEach((u,c,d,f)=>{l===0&&(l=f)}),t.setSelection(me.near(t.doc.resolve(l),n))}const Wm=t=>t.toString().startsWith("<"),Rm=(t,e,n)=>({tr:r,dispatch:a,editor:o})=>{if(a){n={parseOptions:{},updateSelection:!0,...n};const l=Rn(e,o.schema,{parseOptions:{preserveWhitespace:"full",...n.parseOptions}});if(l.toString()==="<>")return!0;let{from:u,to:c}=typeof t=="number"?{from:t,to:t}:t,d=!0,f=!0;if((Wm(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(e)?r.insertText(e.map(g=>g.text||"").join(""),u,c):typeof e=="object"&&e&&e.text?r.insertText(e.text,u,c):r.insertText(e,u,c):r.replaceWith(u,c,l),n.updateSelection&&Gm(r,r.steps.length-1,-1)}return!0},jm=()=>({state:t,dispatch:e})=>De.joinUp(t,e),Ym=()=>({state:t,dispatch:e})=>De.joinDown(t,e),Qm=()=>({state:t,dispatch:e})=>De.joinBackward(t,e),Km=()=>({state:t,dispatch:e})=>De.joinForward(t,e);function bo(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function Um(t){const e=t.split(/-(?!$)/);let n=e[e.length-1];n==="Space"&&(n=" ");let r,a,o,l;for(let u=0;u<e.length-1;u+=1){const c=e[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))Zr()||bo()?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 Xm=t=>({editor:e,view:n,tr:r,dispatch:a})=>{const o=Um(t).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=e.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 Hr(t,e,n={}){const{from:r,to:a,empty:o}=t.selection,l=e?Le(e,t.schema):null,u=[];t.doc.nodesBetween(r,a,(p,g)=>{if(p.isText)return;const m=Math.max(r,g),C=Math.min(a,g+p.nodeSize);u.push({node:p,from:m,to:C})});const c=a-r,d=u.filter(p=>l?l.name===p.node.type.name:!0).filter(p=>Wn(p.node.attrs,n,{strict:!1}));return o?!!d.length:d.reduce((p,g)=>p+g.to-g.from,0)>=c}const Jm=(t,e={})=>({state:n,dispatch:r})=>{const a=Le(t,n.schema);return Hr(n,a,e)?De.lift(n,r):!1},Zm=()=>({state:t,dispatch:e})=>De.liftEmptyBlock(t,e),Hm=t=>({state:e,dispatch:n})=>{const r=Le(t,e.schema);return ur.liftListItem(r)(e,n)},ey=()=>({state:t,dispatch:e})=>De.newlineInCode(t,e);function vo(t,e){return e.nodes[t]?"node":e.marks[t]?"mark":null}function xo(t,e){const n=typeof e=="string"?[e]:e;return Object.keys(t).reduce((r,a)=>(n.includes(a)||(r[a]=t[a]),r),{})}const ty=(t,e)=>({tr:n,state:r,dispatch:a})=>{let o=null,l=null;const u=vo(typeof t=="string"?t:t.name,r.schema);return u?(u==="node"&&(o=Le(t,r.schema)),u==="mark"&&(l=vt(t,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,xo(d.attrs,e)),l&&d.marks.length&&d.marks.forEach(p=>{l===p.type&&n.addMark(f,f+d.nodeSize,l.create(xo(p.attrs,e)))})})}),!0):!1},ny=()=>({tr:t,dispatch:e})=>(e&&t.scrollIntoView(),!0),ry=()=>({tr:t,commands:e})=>e.setTextSelection({from:0,to:t.doc.content.size}),iy=()=>({state:t,dispatch:e})=>De.selectNodeBackward(t,e),ay=()=>({state:t,dispatch:e})=>De.selectNodeForward(t,e),sy=()=>({state:t,dispatch:e})=>De.selectParentNode(t,e),oy=()=>({state:t,dispatch:e})=>De.selectTextblockEnd(t,e),ly=()=>({state:t,dispatch:e})=>De.selectTextblockStart(t,e);function uy(t,e,n={}){return Rn(t,e,{slice:!1,parseOptions:n})}const cy=(t,e=!1,n={})=>({tr:r,editor:a,dispatch:o})=>{const{doc:l}=r,u=uy(t,a.schema,n);return o&&r.replaceWith(0,l.content.size,u).setMeta("preventUpdate",!e),!0};function dy(t){for(let e=0;e<t.edgeCount;e+=1){const{type:n}=t.edge(e);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}function py(t,e){for(let n=t.depth;n>0;n-=1){const r=t.node(n);if(e(r))return{pos:n>0?t.before(n):0,start:t.start(n),depth:n,node:r}}}function ei(t){return e=>py(e.$from,t)}function hy(t,e){const n=vt(e,t.schema),{from:r,to:a,empty:o}=t.selection,l=[];o?(t.storedMarks&&l.push(...t.storedMarks),l.push(...t.selection.$head.marks())):t.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(t,e,n){return Object.fromEntries(Object.entries(n).filter(([r])=>{const a=t.find(o=>o.type===e&&o.name===r);return a?a.attribute.keepOnSplit:!1}))}function fy(t,e,n={}){const{empty:r,ranges:a}=t.selection,o=e?vt(e,t.schema):null;if(r)return!!(t.storedMarks||t.selection.$from.marks()).filter(p=>o?o.name===p.type.name:!0).find(p=>Wn(p.attrs,n,{strict:!1}));let l=0;const u=[];if(a.forEach(({$from:p,$to:g})=>{const m=p.pos,C=g.pos;t.doc.nodesBetween(m,C,(w,_)=>{if(!w.isText&&!w.marks.length)return;const T=Math.max(m,_),M=Math.min(C,_+w.nodeSize),O=M-T;l+=O,u.push(...w.marks.map(B=>({mark:B,from:T,to:M})))})}),l===0)return!1;const c=u.filter(p=>o?o.name===p.mark.type.name:!0).filter(p=>Wn(p.mark.attrs,n,{strict:!1})).reduce((p,g)=>p+g.to-g.from,0),d=u.filter(p=>o?p.mark.type!==o&&p.mark.type.excludes(o):!0).reduce((p,g)=>p+g.to-g.from,0);return(c>0?c+d:c)>=l}function wo(t,e){const{nodeExtensions:n}=bm(e),r=n.find(l=>l.name===t);if(!r)return!1;const a={name:r.name,options:r.options,storage:r.storage},o=Nt(bt(r,"group",a));return typeof o!="string"?!1:o.split(" ").includes("list")}function gy(t,e,n){var r;const{selection:a}=e;let o=null;if(mo(a)&&(o=a.$cursor),o){const u=(r=t.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?t.doc.inlineContent&&t.doc.type.allowsMarkType(n):!1;return t.doc.nodesBetween(u.pos,c.pos,(f,p,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 my=(t,e={})=>({tr:n,state:r,dispatch:a})=>{const{selection:o}=n,{empty:l,ranges:u}=o,c=vt(t,r.schema);if(a)if(l){const d=hy(r,c);n.addStoredMark(c.create({...d,...e}))}else u.forEach(d=>{const f=d.$from.pos,p=d.$to.pos;r.doc.nodesBetween(f,p,(g,m)=>{const C=Math.max(m,f),w=Math.min(m+g.nodeSize,p);g.marks.find(T=>T.type===c)?g.marks.forEach(T=>{c===T.type&&n.addMark(C,w,c.create({...T.attrs,...e}))}):n.addMark(C,w,c.create(e))})});return gy(r,n,c)},yy=(t,e)=>({tr:n})=>(n.setMeta(t,e),!0),by=(t,e={})=>({state:n,dispatch:r,chain:a})=>{const o=Le(t,n.schema);return o.isTextblock?a().command(({commands:l})=>De.setBlockType(o,e)(n)?!0:l.clearNodes()).command(({state:l})=>De.setBlockType(o,e)(l,r)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},vy=t=>({tr:e,dispatch:n})=>{if(n){const{doc:r}=e,a=It(t,0,r.content.size),o=Re.create(r,a);e.setSelection(o)}return!0},xy=t=>({tr:e,dispatch:n})=>{if(n){const{doc:r}=e,{from:a,to:o}=typeof t=="number"?{from:t,to:t}:t,l=ke.atStart(r).from,u=ke.atEnd(r).to,c=It(a,l,u),d=It(o,l,u),f=ke.create(r,c,d);e.setSelection(f)}return!0},wy=t=>({state:e,dispatch:n})=>{const r=Le(t,e.schema);return ur.sinkListItem(r)(e,n)};function Co(t,e){const n=t.storedMarks||t.selection.$to.parentOffset&&t.selection.$from.marks();if(n){const r=n.filter(a=>e==null?void 0:e.includes(a.type.name));t.tr.ensureMarks(r)}}const Cy=({keepMarks:t=!0}={})=>({tr:e,state:n,dispatch:r,editor:a})=>{const{selection:o,doc:l}=e,{$from:u,$to:c}=o,d=a.extensionManager.attributes,f=jn(d,u.node().type.name,u.node().attrs);if(o instanceof Re&&o.node.isBlock)return!u.parentOffset||!qn(l,u.pos)?!1:(r&&(t&&Co(n,a.extensionManager.splittableMarks),e.split(u.pos).scrollIntoView()),!0);if(!u.parent.isBlock)return!1;if(r){const p=c.parentOffset===c.parent.content.size;o instanceof ke&&e.deleteSelection();const g=u.depth===0?void 0:dy(u.node(-1).contentMatchAt(u.indexAfter(-1)));let m=p&&g?[{type:g,attrs:f}]:void 0,C=qn(e.doc,e.mapping.map(u.pos),1,m);if(!m&&!C&&qn(e.doc,e.mapping.map(u.pos),1,g?[{type:g}]:void 0)&&(C=!0,m=g?[{type:g,attrs:f}]:void 0),C&&(e.split(e.mapping.map(u.pos),1,m),g&&!p&&!u.parentOffset&&u.parent.type!==g)){const w=e.mapping.map(u.before()),_=e.doc.resolve(w);u.node(-1).canReplaceWith(_.index(),_.index()+1,g)&&e.setNodeMarkup(e.mapping.map(u.before()),g)}t&&Co(n,a.extensionManager.splittableMarks),e.scrollIntoView()}return!0},Sy=t=>({tr:e,state:n,dispatch:r,editor:a})=>{var o;const l=Le(t,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 p=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 _=se.empty;const T=u.index(-1)?1:u.index(-2)?2:3;for(let E=u.depth-T;E>=u.depth-3;E-=1)_=se.from(u.node(E).copy(_));const M=u.indexAfter(-1)<u.node(-2).childCount?1:u.indexAfter(-2)<u.node(-3).childCount?2:3,O=jn(p,u.node().type.name,u.node().attrs),B=((o=l.contentMatch.defaultType)===null||o===void 0?void 0:o.createAndFill(O))||void 0;_=_.append(se.from(l.createAndFill(null,B)||void 0));const F=u.before(u.depth-(T-1));e.replace(F,u.after(-M),new ce(_,4-T,0));let $=-1;e.doc.nodesBetween(F,e.doc.content.size,(E,z)=>{if($>-1)return!1;E.isTextblock&&E.content.size===0&&($=z+1)}),$>-1&&e.setSelection(ke.near(e.doc.resolve($))),e.scrollIntoView()}return!0}const g=c.pos===u.end()?f.contentMatchAt(0).defaultType:null,m=jn(p,f.type.name,f.attrs),C=jn(p,u.node().type.name,u.node().attrs);e.delete(u.pos,c.pos);const w=g?[{type:l,attrs:m},{type:g,attrs:C}]:[{type:l,attrs:m}];if(!qn(e.doc,u.pos,2))return!1;if(r){const{selection:_,storedMarks:T}=n,{splittableMarks:M}=a.extensionManager,O=T||_.$to.parentOffset&&_.$from.marks();if(e.split(u.pos,2,w).scrollIntoView(),!O||!r)return!0;const B=O.filter(F=>M.includes(F.type.name));e.ensureMarks(B)}return!0},ti=(t,e)=>{const n=ei(l=>l.type===e)(t.selection);if(!n)return!0;const r=t.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(r===void 0)return!0;const a=t.doc.nodeAt(r);return n.node.type===(a==null?void 0:a.type)&&ao(t.doc,n.pos)&&t.join(n.pos),!0},ni=(t,e)=>{const n=ei(l=>l.type===e)(t.selection);if(!n)return!0;const r=t.doc.resolve(n.start).after(n.depth);if(r===void 0)return!0;const a=t.doc.nodeAt(r);return n.node.type===(a==null?void 0:a.type)&&ao(t.doc,r)&&t.join(r),!0};var _y=Object.freeze({__proto__:null,blur:_m,clearContent:km,clearNodes:Tm,command:Dm,createParagraphNear:Im,deleteCurrentNode:Mm,deleteNode:Em,deleteRange:Am,deleteSelection:zm,enter:$m,exitCode:Lm,extendMarkRange:Pm,first:Bm,focus:Nm,forEach:qm,insertContent:Fm,insertContentAt:Rm,joinUp:jm,joinDown:Ym,joinBackward:Qm,joinForward:Km,keyboardShortcut:Xm,lift:Jm,liftEmptyBlock:Zm,liftListItem:Hm,newlineInCode:ey,resetAttributes:ty,scrollIntoView:ny,selectAll:ry,selectNodeBackward:iy,selectNodeForward:ay,selectParentNode:sy,selectTextblockEnd:oy,selectTextblockStart:ly,setContent:cy,setMark:my,setMeta:yy,setNode:by,setNodeSelection:vy,setTextSelection:xy,sinkListItem:wy,splitBlock:Cy,splitListItem:Sy,toggleList:(t,e,n,r={})=>({editor:a,tr:o,state:l,dispatch:u,chain:c,commands:d,can:f})=>{const{extensions:p,splittableMarks:g}=a.extensionManager,m=Le(t,l.schema),C=Le(e,l.schema),{selection:w,storedMarks:_}=l,{$from:T,$to:M}=w,O=T.blockRange(M),B=_||w.$to.parentOffset&&w.$from.marks();if(!O)return!1;const F=ei($=>wo($.type.name,p))(w);if(O.depth>=1&&F&&O.depth-F.depth<=1){if(F.node.type===m)return d.liftListItem(C);if(wo(F.node.type.name,p)&&m.validContent(F.node.content)&&u)return c().command(()=>(o.setNodeMarkup(F.pos,m),!0)).command(()=>ti(o,m)).command(()=>ni(o,m)).run()}return!n||!B||!u?c().command(()=>f().wrapInList(m,r)?!0:d.clearNodes()).wrapInList(m,r).command(()=>ti(o,m)).command(()=>ni(o,m)).run():c().command(()=>{const $=f().wrapInList(m,r),E=B.filter(z=>g.includes(z.type.name));return o.ensureMarks(E),$?!0:d.clearNodes()}).wrapInList(m,r).command(()=>ti(o,m)).command(()=>ni(o,m)).run()},toggleMark:(t,e={},n={})=>({state:r,commands:a})=>{const{extendEmptyMarkRange:o=!1}=n,l=vt(t,r.schema);return fy(r,l,e)?a.unsetMark(l,{extendEmptyMarkRange:o}):a.setMark(l,e)},toggleNode:(t,e,n={})=>({state:r,commands:a})=>{const o=Le(t,r.schema),l=Le(e,r.schema);return Hr(r,o,n)?a.setNode(l):a.setNode(o,n)},toggleWrap:(t,e={})=>({state:n,commands:r})=>{const a=Le(t,n.schema);return Hr(n,a,e)?r.lift(a):r.wrapIn(a,e)},undoInputRule:()=>({state:t,dispatch:e})=>{const n=t.plugins;for(let r=0;r<n.length;r+=1){const a=n[r];let o;if(a.spec.isInputRules&&(o=a.getState(t))){if(e){const l=t.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,t.schema.text(o.text,c))}else l.delete(o.from,o.to)}return!0}}return!1},unsetAllMarks:()=>({tr:t,dispatch:e})=>{const{selection:n}=t,{empty:r,ranges:a}=n;return r||e&&a.forEach(o=>{t.removeMark(o.$from.pos,o.$to.pos)}),!0},unsetMark:(t,e={})=>({tr:n,state:r,dispatch:a})=>{var o;const{extendEmptyMarkRange:l=!1}=e,{selection:u}=n,c=vt(t,r.schema),{$from:d,empty:f,ranges:p}=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=go(d,c,C);w&&(g=w.from,m=w.to),n.removeMark(g,m,c)}else p.forEach(g=>{n.removeMark(g.$from.pos,g.$to.pos,c)});return n.removeStoredMark(c),!0},updateAttributes:(t,e={})=>({tr:n,state:r,dispatch:a})=>{let o=null,l=null;const u=vo(typeof t=="string"?t:t.name,r.schema);return u?(u==="node"&&(o=Le(t,r.schema)),u==="mark"&&(l=vt(t,r.schema)),a&&n.selection.ranges.forEach(c=>{const d=c.$from.pos,f=c.$to.pos;r.doc.nodesBetween(d,f,(p,g)=>{o&&o===p.type&&n.setNodeMarkup(g,void 0,{...p.attrs,...e}),l&&p.marks.length&&p.marks.forEach(m=>{if(l===m.type){const C=Math.max(g,d),w=Math.min(g+p.nodeSize,f);n.addMark(C,w,l.create({...m.attrs,...e}))}})})}),!0):!1},wrapIn:(t,e={})=>({state:n,dispatch:r})=>{const a=Le(t,n.schema);return De.wrapIn(a,e)(n,r)},wrapInList:(t,e={})=>({state:n,dispatch:r})=>{const a=Le(t,n.schema);return ur.wrapInList(a,e)(n,r)}});rt.create({name:"commands",addCommands(){return{..._y}}}),rt.create({name:"editable",addProseMirrorPlugins(){return[new nn({key:new rn("editable"),props:{editable:()=>this.editor.options.editable}})]}}),rt.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:t}=this;return[new nn({key:new rn("focusEvents"),props:{handleDOMEvents:{focus:(e,n)=>{t.isFocused=!0;const r=t.state.tr.setMeta("focus",{event:n}).setMeta("addToHistory",!1);return e.dispatch(r),!1},blur:(e,n)=>{t.isFocused=!1;const r=t.state.tr.setMeta("blur",{event:n}).setMeta("addToHistory",!1);return e.dispatch(r),!1}}}})]}}),rt.create({name:"keymap",addKeyboardShortcuts(){const t=()=>this.editor.commands.first(({commands:l})=>[()=>l.undoInputRule(),()=>l.command(({tr:u})=>{const{selection:c,doc:d}=u,{empty:f,$anchor:p}=c,{pos:g,parent:m}=p,C=me.atStart(d).from===g;return!f||!C||!m.type.isTextblock||m.textContent.length?!1:l.clearNodes()}),()=>l.deleteSelection(),()=>l.joinBackward(),()=>l.selectNodeBackward()]),e=()=>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:t,"Mod-Backspace":t,"Shift-Backspace":t,Delete:e,"Mod-Delete":e,"Mod-a":()=>this.editor.commands.selectAll()},a={...r},o={...r,"Ctrl-h":t,"Alt-Backspace":t,"Ctrl-d":e,"Ctrl-Alt-Backspace":e,"Alt-Delete":e,"Alt-d":e,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return Zr()||bo()?o:a},addProseMirrorPlugins(){return[new nn({key:new rn("clearDocument"),appendTransaction:(t,e,n)=>{if(!(t.some(C=>C.docChanged)&&!e.doc.eq(n.doc)))return;const{empty:a,from:o,to:l}=e.selection,u=me.atStart(e.doc).from,c=me.atEnd(e.doc).to;if(a||!(o===u&&l===c)||!(n.doc.textBetween(0,n.doc.content.size," "," ").length===0))return;const p=n.tr,g=ho({state:n,transaction:p}),{commands:m}=new ym({editor:this.editor,state:g});if(m.clearNodes(),!!p.steps.length)return p}})]}}),rt.create({name:"tabindex",addProseMirrorPlugins(){return[new nn({key:new rn("tabindex"),props:{attributes:this.editor.isEditable?{tabindex:"0"}:{}}})]}});const So=rt.create({name:"fontSize",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{fontSize:{default:null,parseHTML:t=>t.style.fontSize.replace(/['"]+/g,""),renderHTML:t=>t.fontSize?{style:`font-size: ${t.fontSize}`}:{}}}}]},addCommands(){return{setFontSize:t=>({chain:e})=>e().setMark("textStyle",{fontSize:t}).run(),unsetFontSize:()=>({chain:t})=>t().setMark("textStyle",{fontSize:null}).removeEmptyTextStyle().run()}}}),ky=["8","10","12","14","16","18","20","24","30","36","48","60","72"].map(t=>`${t}px`),Ty=[{label:"auto",value:""}].concat(ky.map(t=>({label:t,value:t}))),Dy={input:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important"}},Iy=({editor:t})=>{const e=t.getAttributes("textStyle").fontSize;return i(Z.RichTextEditor.ControlsGroup,{children:i(s.NativeSelect,{size:"xs",icon:i(L.IconTextSize,{stroke:1.5,size:16}),data:Ty,styles:Dy,value:e||"",onChange:n=>{const r=n.currentTarget.value;r?t.chain().focus().setFontSize(r).run():t.chain().focus().unsetFontSize().run()}})})},Yn=({value:t,styles:e={}})=>{const n=Oa.useEditor({extensions:[Pa,La,Z.Link,Da,Ta,_a,Ea.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),$a,za,Aa,Ia.configure({types:["heading","paragraph"]}),ka.configure({placeholder:"This is placeholder"}),Ma,Sa.Color,So],content:t,editable:!1});y.useEffect(()=>{n==null||n.commands.setContent(t)},[t,n]);const r=y.useMemo(()=>x.defaultsDeep({},{content:Fr},e),[e]);return i(Z.RichTextEditor,{editor:n,styles:r,children:i(Z.RichTextEditor.Content,{})})};function My(t,e){const n={};return t.forEach(r=>{const{name:a,data_field:o,aggregation:l}=r,u=kn(e,o,l);n[a]=ut(r,u)}),n}function Ey(t){const e=document.createElement("span");return e.innerHTML=t,e.innerText}function Ay(t,e,n){try{return new Function("payload",`
|
|
311
311
|
const filters = payload.filters;
|
|
312
312
|
const context = payload.context;
|
|
313
313
|
${Object.entries(e).map(([r,a])=>`const ${r} = '${a}';`).join(`
|
|
314
314
|
`)}
|
|
315
315
|
return ${t};
|
|
316
|
-
`)(n)}catch(r){return console.error(r),console.log(t),t}}function
|
|
317
|
-
`)}},_o={id:"builtin:echarts:click-scatter-chart:series",displayName:"Click Scatter",nameRender:
|
|
318
|
-
`)},To={label:Ze.on_axis,tooltip:Ze.in_tooltip},ii={scatter:{y_data_key:"",name_data_key:"",symbolSize:{type:"static",size:10},color:an.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:$e,min:"",max:"",show:!0}],tooltip:{trigger:"item",metrics:[]},reference_lines:[],reference_areas:[],dataZoom:Bt};function
|
|
316
|
+
`)(n)}catch(r){return console.error(r),console.log(t),t}}function zy(t,e,n,r){const a=My(e,r),o=/^(.+)\}\}(.*)$/;return t.split("{{").map(l=>{const u=o.exec(l);if(!u)return l;const c=a[u[1]];if(c){const f=u[2]??"";return`${c}${f}`}const d=Ey(u[1]);return`${Ay(d,a,n)}${u[2]}`}).join("")}const $y=k.observer(({context:t})=>{const e=K(),{value:n}=R(t.instanceData,"config"),{variables:r,data:a}=t,o=y.useMemo(()=>{const l=x.defaults({},n,$n);return l.content?zy(l.content,r,e.payloadForViz,a):""},[n,r,e.payloadForViz]);return o?i(Yn,{value:o,styles:{root:{border:"none",height:"100%"},content:{padding:0}}}):null});function Ly(){const{editor:t}=Z.useRichTextEditorContext();return i(Z.RichTextEditor.Control,{onClick:()=>t==null?void 0:t.commands.insertTable({rows:3,cols:3,withHeaderRow:!0}),"aria-label":"Insert table",title:"Insert table",children:i(L.IconBorderAll,{stroke:1.5,size:16})})}const ri=y.forwardRef(({value:t,onChange:e,styles:n={},label:r,onSubmit:a},o)=>{const[l,u]=y.useState(t),c=Oa.useEditor({extensions:[Pa,La,Z.Link,Da,Ta,_a,Ea.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),$a,za,Aa,Ia.configure({types:["heading","paragraph"]}),ka.configure({placeholder:"This is placeholder"}),Ma,Sa.Color,So],content:l,onUpdate:({editor:g})=>{u(g.getHTML())}});y.useEffect(()=>{u(t),c==null||c.commands.setContent(t)},[t]);const d=()=>{e(l),a==null||a()},f=t!==l,p=y.useMemo(()=>x.defaultsDeep({},{content:Fr},n),[n]);return c?h(s.Stack,{spacing:4,sx:{flexGrow:1,position:"relative"},children:[h(s.Group,{align:"center",children:[i(s.Text,{size:14,fw:500,children:r}),i(s.ActionIcon,{color:"blue",disabled:!f,onClick:d,children:i(L.IconDeviceFloppy,{size:18})})]}),h(Z.RichTextEditor,{editor:c,styles:p,children:[h(Z.RichTextEditor.Toolbar,{sticky:!0,stickyOffset:0,children:[i(Z.RichTextEditor.ControlsGroup,{children:i(Z.RichTextEditor.ColorPicker,{colors:["#25262b","#868e96","#fa5252","#e64980","#be4bdb","#7950f2","#4c6ef5","#228be6","#15aabf","#12b886","#40c057","#82c91e","#fab005","#fd7e14"]})}),h(Z.RichTextEditor.ControlsGroup,{children:[i(Z.RichTextEditor.Bold,{}),i(Z.RichTextEditor.Italic,{}),i(Z.RichTextEditor.Underline,{}),i(Z.RichTextEditor.Strikethrough,{}),i(Z.RichTextEditor.ClearFormatting,{}),i(Z.RichTextEditor.Highlight,{}),i(Z.RichTextEditor.Code,{})]}),h(Z.RichTextEditor.ControlsGroup,{children:[i(Z.RichTextEditor.H1,{}),i(Z.RichTextEditor.H2,{}),i(Z.RichTextEditor.H3,{}),i(Z.RichTextEditor.H4,{})]}),h(Z.RichTextEditor.ControlsGroup,{children:[i(Z.RichTextEditor.Blockquote,{}),i(Z.RichTextEditor.Hr,{}),i(Z.RichTextEditor.BulletList,{}),i(Z.RichTextEditor.OrderedList,{}),i(Z.RichTextEditor.Subscript,{}),i(Z.RichTextEditor.Superscript,{})]}),h(Z.RichTextEditor.ControlsGroup,{children:[i(Z.RichTextEditor.Link,{}),i(Z.RichTextEditor.Unlink,{})]}),h(Z.RichTextEditor.ControlsGroup,{children:[i(Z.RichTextEditor.AlignLeft,{}),i(Z.RichTextEditor.AlignCenter,{}),i(Z.RichTextEditor.AlignJustify,{}),i(Z.RichTextEditor.AlignRight,{})]}),i(Z.RichTextEditor.ControlsGroup,{children:i(Ly,{})}),i(Iy,{editor:c})]}),i(Z.RichTextEditor.Content,{})]})]}):null});function Oy({context:t}){const{value:e,set:n}=R(t.instanceData,"config"),r=y.useMemo(()=>x.defaults({},e,$n),[e]),{control:a,handleSubmit:o,watch:l,reset:u}=v.useForm({defaultValues:r});l("content"),y.useEffect(()=>{u(r)},[r]);const c=y.useRef(null),d=()=>{var f;return(f=c.current)==null?void 0:f.click()};return i("form",{onSubmit:o(n),style:{flexGrow:1,display:"flex",flexDirection:"column"},children:h(s.Stack,{spacing:"xs",sx:{flexGrow:1},children:[h(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",display:"none"},children:[i(s.Text,{children:"Content"}),i(s.ActionIcon,{ref:c,type:"submit",mr:5,variant:"filled",color:"blue",children:i(I.DeviceFloppy,{size:20})})]}),i(v.Controller,{name:"content",control:a,render:({field:f})=>i(ri,{...f,styles:{root:{flexGrow:1}},label:"Content",onSubmit:d})})]})})}class Py extends ve{constructor(){super(...arguments);V(this,"VERSION",1)}fixMalformedConfig(n){return x.defaults({},n,$n)}configVersions(){this.version(1,n=>({version:1,config:this.fixMalformedConfig(n)}))}}const By={displayName:"Rich Text",displayGroup:"Others",migrator:new Py,name:"richText",viewRender:$y,configRender:Oy,createConfig(){return{version:1,config:x.cloneDeep($n)}}},an={static:{type:"static",color:at.random().css()},dynamic:{type:"dynamic",func_content:["function getColor({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here",' // return "blue"',"}"].join(`
|
|
317
|
+
`)}},_o={id:"builtin:echarts:click-scatter-chart:series",displayName:"Click Scatter",nameRender:Ny,configRender:Vy,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 Vy(t){return i(N,{})}function Ny(t){return i(s.Text,{children:"Click scatter"})}const ko={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
318
|
+
`)},To={label:Ze.on_axis,tooltip:Ze.in_tooltip},ii={scatter:{y_data_key:"",name_data_key:"",symbolSize:{type:"static",size:10},color:an.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:$e,min:"",max:"",show:!0}],tooltip:{trigger:"item",metrics:[]},reference_lines:[],reference_areas:[],dataZoom:Bt};function qy(t,e){if(!t.x_axis.data_key)return[];const n=q(t.x_axis.data_key);return[{source:e[n.queryID]}]}function Fy(t){const e=t.y_axes.some(a=>!!a.name);let n=15;e&&(n+=20),t.dataZoom.x_axis_slider&&(n+=20);let r=5;return t.x_axis.name&&(r+=15),{top:n,bottom:r}}function Gy(){return{show:!1,bottom:0,left:"center",type:"scroll"}}function Qn(t,e){if(t)return e[t]??void 0}function Wy({reference_areas:t,variableValueMap:e}){const n=t.map(r=>[{name:r.content.text,value:r.content.text,itemStyle:r.itemStyle,label:r.label,xAxis:Qn(r.leftBottomPoint.x_data_key,e),yAxis:Qn(r.leftBottomPoint.y_data_key,e)},{xAxis:Qn(r.rightTopPoint.x_data_key,e),yAxis:Qn(r.rightTopPoint.y_data_key,e)}]);return{type:"scatter",name:"ref_areas",silent:!0,data:[],markArea:{data:n}}}function Ry({type:t,...e},n){if(!t)return 10;if(t==="static"){const{size:a}=e;return a}const{func_content:r}=e;return(a,o)=>{const l=o.data;try{return new Function(`return ${r}`)()({rowData:l,params:o,variables:n},{lodash:x,interpolate:At.interpolate})}catch(u){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${u.message}`),10}}}function jy({type:t,...e},n){if(!t)return an.static.color;if(t==="static"){const{color:a}=e;return a}const{func_content:r}=e;return({value:a})=>{try{return new Function(`return ${r}`)()({rowData:a,variables:n},{lodash:x,interpolate:At.interpolate})}catch(o){return console.error(`[getSeriesColor] failed parsing custom function, error: ${o.message}`),10}}}function Yy(t,e,n,r){return t.map(a=>{const o=a.orientation==="horizontal",l=o?"yAxis":"xAxis",u=o?"insideEndTop":"end";return{name:a.name,type:"line",hide_in_legend:!a.show_in_legend,yAxisIndex:a.yAxisIndex,data:[],lineStyle:a.lineStyle,markLine:{data:[{name:a.name,[l]:Number(n[a.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:a.lineStyle,label:{formatter:function(){return a.template?Tn(a.template,e,r):""},position:u}}}})}function Qy({x_axis:t,scatter:e},n){const r=q(t.data_key),a=q(e.y_data_key);return{label:{show:!!e.label_position,position:e.label_position,...lt(e.label_overflow.label),formatter:({value:o})=>o[e.name_data_key]},type:"scatter",name:"",xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{color:jy(e.color,n)},symbolSize:Ry(e.symbolSize,n),encode:{x:r.columnKey,y:a.columnKey}}}function Ky(t,e,n,r){return[Qy(t,r)].concat(Yy(t.reference_lines,n,r,e)).concat(Wy({reference_areas:t.reference_areas,variableValueMap:r}))}function Do({enabled:t,func_content:e}){return(n,r)=>{if(!t)return n;try{return new Function(`return ${e}`)()(n,r)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function Io(t,e,n){const{x_axis:r}=n;return r.axisLabel.formatter.enabled?Do(r.axisLabel.formatter)(t,e):t}function Uy(t,e){const{x_axis:n,tooltip:r}=e;if(r.trigger==="item"){const u=wn(t[0].data,n.data_key);return Io(u,0,e)}const a=t.find(u=>u.axisDim==="x"&&u.axisId==="main-x-axis");if(!a)return"";const{axisValue:o,axisIndex:l}=a;return Io(o,l,e)}const Xy=t=>{try{return te(t).format({trimMantissa:!0,mantissa:2})}catch{return t}};function Jy(t,e){const{scatter:n,tooltip:r}=t;return{confine:!0,trigger:r.trigger,formatter:function(a){const o=e[0]??e.default,l=Array.isArray(a)?a:[a];if(l.length===0)return"";const u=Uy(l,t),c=mt(t.scatter.label_overflow.tooltip),d=l.map(({value:m})=>`
|
|
319
319
|
<th style="text-align: right; padding-right: 1em">
|
|
320
|
-
<div style="${
|
|
320
|
+
<div style="${c}">${wn(m,n.name_data_key)}</div>
|
|
321
321
|
</th>
|
|
322
322
|
`);d.unshift("<th></th>");const f=[`<tr>
|
|
323
323
|
<th style="text-align: right;">${t.x_axis.name}</th>
|
|
324
|
-
${l.map(m=>`<td style="text-align: right; padding: 0 1em;">${
|
|
324
|
+
${l.map(m=>`<td style="text-align: right; padding: 0 1em;">${u}</td>`).join("")}
|
|
325
325
|
</tr>`,`<tr>
|
|
326
326
|
<th style="text-align: right;">${t.y_axes[0].name}</th>
|
|
327
327
|
${l.map(({value:m})=>`
|
|
328
328
|
<td style="text-align: right; padding: 0 1em;">
|
|
329
329
|
${o(wn(m,n.y_data_key))}
|
|
330
330
|
</td>`).join("")}
|
|
331
|
-
</tr>`],
|
|
331
|
+
</tr>`],p=t.tooltip.metrics.map(m=>`<tr>
|
|
332
332
|
<th style="text-align: right;">${m.name}</th>
|
|
333
|
-
${l.map(({value:C})=>`<td style="text-align: right; padding: 0 1em;">${
|
|
334
|
-
</tr>`);return f.push(...
|
|
333
|
+
${l.map(({value:C})=>`<td style="text-align: right; padding: 0 1em;">${Xy(wn(C,m.data_key))}</td>`).join("")}
|
|
334
|
+
</tr>`);return f.push(...p),`
|
|
335
335
|
<table style="width: auto">
|
|
336
336
|
<thead><tr>${d.join("")}</tr></thead>
|
|
337
337
|
<tbody>${f.join("")}</tbody>
|
|
338
338
|
</table>
|
|
339
|
-
`}}}function Jy(t,e){const n=e.every(a=>!Number.isNaN(Number(a))),{axisLabel:r}=t.x_axis;return[{data:e,name:t.x_axis.name??"",id:"main-x-axis",axisTick:{show:!0,alignWithLabel:!0},type:n?"value":"category",axisLabel:{...r,formatter:Do(r.formatter)}}]}function Zy(t,e){return t.y_axes.map(({nameAlignment:n,min:r,max:a,...o},l)=>{let c=o.position;return c||(c=l>0?"right":"left"),{...o,min:r||void 0,max:a||void 0,position:c,axisLabel:{show:!0,formatter:e[l]??e.default},axisLine:{show:!0},nameTextStyle:{fontWeight:"bold",align:n},nameLocation:"end",nameGap:15,splitLine:{show:!1}}})}const Hy={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 eb(t,e,n){const r=n.reduce((u,d)=>{const f=Pt(d,e);return u[d.name]=ct(d,f),u},{}),a=t.y_axes.reduce((u,{label_formatter:d},f)=>(u[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 te(m).format(d)}catch(C){return console.error(C),m}},u),{default:({value:u})=>u}),o=x.uniq(ot(e,t.x_axis.data_key)),l=Qy(t,e,n,r),c={xAxis:Jy(t,o),yAxis:Zy(t,a),series:l,dataset:Ny(t,e),tooltip:Xy(t,a),grid:qy(t),legend:Fy(),dataZoom:Er(t.dataZoom)};return x.defaultsDeep({},c,Hy)}ce.use([G.DataZoomComponent,he.BarChart,he.LineChart,he.ScatterChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer,G.MarkLineComponent,G.MarkAreaComponent]);function Mo(t){return t.trim().length>0}function tb({conf:t,data:e,width:n,height:r,interactionManager:a,variables:o}){const l=yt(e,t.x_axis.data_key),c=He(a.triggerManager,_o.id),u=y.useCallback(h=>{const g=h.data;c.forEach(m=>{a.runInteraction(m.id,{...h,rowData:g})})},[l,c,a]),d=y.useMemo(()=>({click:u}),[u]),f=y.useMemo(()=>eb(t,e,o),[t,e]);return i(Ne,{echarts:ce,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function nb({context:t,instance:e}){const n=et({vizManager:t.vizManager,instance:e}),{value:r}=R(t.instanceData,"config"),{variables:a}=t,o=y.useMemo(()=>x.defaults({},r,ii),[r]),l=t.data,{width:c,height:u}=t.viewport,{ref:d,height:f}=Ie.useElementSize(),{ref:h,height:g}=Ie.useElementSize(),m=y.useMemo(()=>{const{stats:{templates:w}}=o;return{top:Jt(w.top,a,l),bottom:Jt(w.bottom,a,l)}},[o,l]),C=Math.max(0,u-f-g);return!c||!u?null:p(s.Box,{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(tb,{variables:a,width:c,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 rb=y.forwardRef(({value:t,onChange:e,xAxisOptions:n,yAxisOptions:r,variableOptions:a},o)=>{const l=(c,u)=>{const d=x.cloneDeep(t);x.set(d,c,u),e(d)};return p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Content",labelPosition:"right"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(s.TextInput,{label:"Content Text",value:t.content.text,onChange:c=>l("content.text",c.currentTarget.value)}),i(Or,{label:"Text Position",value:t.label.position,onChange:c=>l("label.position",c)})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Endpoints",labelPosition:"right"}),p(s.Group,{grow:!0,noWrap:!0,children:[n&&i(s.Select,{label:"X Axis",data:n,value:t.xAxisIndex,onChange:c=>l("xAxisIndex",c)}),r&&i(s.Select,{label:"Y Axis",data:r,value:t.yAxisIndex,onChange:c=>l("xAxisIndex",c)})]}),p(s.Stack,{spacing:0,children:[i(s.Text,{size:14,color:"#212529",fw:500,children:"Left-Bottom Point"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(s.Select,{icon:i(s.Text,{children:"x"}),data:a,value:t.leftBottomPoint.x_data_key,onChange:c=>l("leftBottomPoint.x_data_key",c??""),clearable:!0}),i(s.Select,{icon:i(s.Text,{children:"y"}),data:a,value:t.leftBottomPoint.y_data_key,onChange:c=>l("leftBottomPoint.y_data_key",c??""),clearable:!0})]})]}),p(s.Stack,{spacing:0,children:[i(s.Text,{size:14,color:"#212529",fw:500,children:"Right-Top Point"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(s.Select,{icon:i(s.Text,{children:"x"}),data:a,value:t.rightTopPoint.x_data_key,onChange:c=>l("rightTopPoint.x_data_key",c??""),clearable:!0}),i(s.Select,{icon:i(s.Text,{children:"y"}),data:a,value:t.rightTopPoint.y_data_key,onChange:c=>l("rightTopPoint.y_data_key",c??""),clearable:!0})]})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Style",labelPosition:"right"}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:14,children:"Background Color"}),i(Pe,{value:t.itemStyle.color,onChange:c=>l("itemStyle.color",c)})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:14,children:"Text Color"}),i(Pe,{value:t.label.color,onChange:c=>l("label.color",c)})]})]})});function ib(){const t=new Date().getTime().toString();return{id:t,content:{text:t},itemStyle:{color:"rgba(0,0,0,0.05)"},label:{position:"inside",color:"rgba(0,0,0,0.5)"},leftBottomPoint:{x_data_key:"",y_data_key:""},rightTopPoint:{x_data_key:"",y_data_key:""},xAxisIndex:"0",yAxisIndex:"0"}}function ab({control:t,watch:e,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:t,name:"reference_areas"}),l=e("reference_areas"),c=r.map((g,m)=>({...g,...l[m]})),u=()=>{const g=ib();a(g)},d=y.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=e("y_axes"),h=y.useMemo(()=>f.map(({name:g},m)=>({label:g,value:m.toString()})),[f]);return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[c.map((g,m)=>i(s.Tabs.Tab,{value:m.toString(),children:m+1},m)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),c.map((g,m)=>i(s.Tabs.Panel,{value:m.toString(),children:i(v.Controller,{name:`reference_areas.${m}`,control:t,render:({field:C})=>p(s.Stack,{children:[i(rb,{variableOptions:d,yAxisOptions:h,...C}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(L.IconTrash,{size:16}),color:"red",variant:"light",onClick:()=>o(m),children:"Delete this Reference Area"})]})})},m))]})}const sb=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],ob=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function lb({control:t,index:e,remove:n,watch:r,variableOptions:a,yAxisOptions:o}){const l=r(`reference_lines.${e}.orientation`);return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${e}.name`,control:t,render:({field:c})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...c})}),i(v.Controller,{name:`reference_lines.${e}.variable_key`,control:t,render:({field:c})=>i(s.Select,{label:"Value",required:!0,data:a,sx:{flex:1},...c})})]}),i(v.Controller,{name:`reference_lines.${e}.template`,control:t,render:({field:c})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...c})}),p(s.Group,{grow:!0,children:[p(s.Stack,{children:[i(v.Controller,{name:`reference_lines.${e}.orientation`,control:t,render:({field:c})=>i(s.Select,{label:"Orientation",data:ob,required:!0,sx:{flex:1},...c})}),l==="vertical"&&i(s.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&i(v.Controller,{name:`reference_lines.${e}.yAxisIndex`,control:t,render:({field:{value:c,onChange:u,...d}})=>i(s.Select,{label:"Y Axis",data:o,disabled:o.length===0,...d,value:(c==null?void 0:c.toString())??"",onChange:f=>{if(!f){u(0);return}u(Number(f))},sx:{flex:1}})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`reference_lines.${e}.lineStyle.type`,control:t,render:({field:c})=>i(s.Select,{label:"Line Type",data:sb,sx:{flexGrow:1},...c})}),i(v.Controller,{name:`reference_lines.${e}.lineStyle.width`,control:t,render:({field:c})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...c})})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`reference_lines.${e}.lineStyle.color`,control:t,render:({field:c})=>i(Pe,{...c})})]}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Reference Line"})]},e)}function cb({control:t,watch:e,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:t,name:"reference_lines"}),l=e("reference_lines"),c=r.map((g,m)=>({...g,...l[m]})),u=()=>{const g={name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:at.random().css()},show_in_legend:!1,yAxisIndex:0};a(g)},d=y.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=e("y_axes"),h=y.useMemo(()=>f.map(({name:g},m)=>({label:g,value:m.toString()})),[f]);return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[c.map((g,m)=>i(s.Tabs.Tab,{value:m.toString(),children:m+1},m)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),c.map((g,m)=>i(s.Tabs.Panel,{value:m.toString(),children:i(lb,{control:t,index:m,remove:o,watch:e,variableOptions:d,yAxisOptions:h})},m))]})}const ub=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return i(s.Box,{children:i(ze,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},db=({value:t,onChange:e})=>{const[n,{setTrue:r,setFalse:a}]=J.useBoolean(),[o,l]=y.useState(t),c=()=>{a();const{type:h,func_content:g}=o,m={type:h,func_content:g};l(m),e(m)},u=()=>{a(),l(t)},d=h=>{l(g=>({...g,func_content:h}))},f=()=>{d(an.dynamic.func_content)};return p(N,{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(ub,{value:o.func_content,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:u,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:c,children:"OK"})]})]})]})})]})},pb=({value:t,onChange:e})=>t.type!=="dynamic"?null:i(db,{value:t,onChange:e}),hb=({value:t,onChange:e})=>{if(t.type!=="static")return null;const n=r=>{e({...t,color:r})};return i(s.ColorInput,{label:" ",format:"rgb",value:t.color,onChange:n})},fb=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],gb=y.forwardRef(({label:t="Color",value:e,onChange:n},r)=>{const a=o=>{n({...an[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:t,data:fb,value:e.type,onChange:a,sx:{flexGrow:1}}),i(hb,{value:e,onChange:n}),i(pb,{value:e,onChange:n})]})}),mb=y.forwardRef(({value:t,onChange:e},n)=>{const r=o=>{e({...t,label:o})},a=o=>{e({...t,tooltip:o})};return p(s.Stack,{ref:n,spacing:0,children:[i(Cn,{sectionTitle:"Overflow on Chart",value:t.label,onChange:r}),i(Cn,{sectionTitle:"Overflow in Tooltip",value:t.tooltip,onChange:a})]})}),yb=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return i(s.Box,{children:i(ze,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Eo={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
|
|
340
|
-
`)}},bb=({value:t,onChange:e})=>{const[n,{setTrue:r,setFalse:a}]=J.useBoolean(),[o,l]=y.useState(t),c=()=>{a();const{type:h,func_content:g}=o,m={type:h,func_content:g};l(m),e(m)},u=()=>{a(),l(t)},d=h=>{l(g=>({...g,func_content:h}))},f=()=>{d(Eo.dynamic.func_content)};return p(N,{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(yb,{value:o.func_content,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:u,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:c,children:"OK"})]})]})]})})]})},vb=({value:t,onChange:e})=>t.type!=="dynamic"?null:i(bb,{value:t,onChange:e}),xb=({value:t,onChange:e})=>{if(t.type!=="static")return null;const n=r=>{e({...t,size:r})};return i(N,{children:i(s.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:t.size,onChange:n})})},wb=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Cb=y.forwardRef(({label:t="Size",value:e,onChange:n},r)=>{const a=o=>{n({...Eo[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:t,data:wb,value:e.type,onChange:a,sx:{flexGrow:1}}),i(xb,{value:e,onChange:n}),i(vb,{value:e,onChange:n})]})}),Sb=[{label:"off",value:""},{label:"top",value:"top"},{label:"left",value:"left"},{label:"right",value:"right"},{label:"bottom",value:"bottom"},{label:"inside",value:"inside"},{label:"insideLeft",value:"insideLeft"},{label:"insideRight",value:"insideRight"},{label:"insideTop",value:"insideTop"},{label:"insideBottom",value:"insideBottom"},{label:"insideTopLeft",value:"insideTopLeft"},{label:"insideBottomLeft",value:"insideBottomLeft"},{label:"insideTopRight",value:"insideTopRight"},{label:"insideBottomRight",value:"insideBottomRight"}];function _b({control:t,watch:e}){return e(["scatter"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"scatter.name_data_key",control:t,render:({field:n})=>i(j,{label:"Name Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"scatter.y_data_key",control:t,render:({field:n})=>i(j,{label:"Value Data Field",required:!0,sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Style",labelPosition:"center"}),i(v.Controller,{name:"scatter.symbolSize",control:t,render:({field:n})=>i(Cb,{label:"Size",...n})}),i(v.Controller,{name:"scatter.color",control:t,render:({field:n})=>i(gb,{...n})}),i(s.Divider,{mb:-15,label:"Label",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"scatter.label_position",control:t,render:({field:n})=>i(s.Select,{label:"Label Position",data:Sb,...n})})}),i(v.Controller,{name:"scatter.label_overflow",control:t,render:({field:n})=>i(mb,{...n})})]})}function kb({control:t,watch:e}){return e("stats"),i(s.Stack,{children:p(s.Stack,{spacing:0,children:[i(v.Controller,{name:"stats.templates.top",control:t,render:({field:n})=>i(Xt,{label:"Template for stats above the chart",py:"md",sx:{flexGrow:1},...n})}),i(v.Controller,{name:"stats.templates.bottom",control:t,render:({field:n})=>i(Xt,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const Tb=({control:t,index:e,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${e}.data_key`,control:t,render:({field:r})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),Db=({control:t,watch:e})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"tooltip.metrics"}),o=e("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),c=()=>r({id:Date.now().toString(),data_key:"",name:""}),u=e("tooltip.metrics.0.id"),[d,f]=y.useState(()=>u??null);return y.useEffect(()=>{u&&f(h=>h!==null?h:u)},[u]),p(N,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(I.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(Tb,{control:t,index:g,remove:a},h.id)},h.id))]})]})},Ib=[{label:"Scatter Point",value:"item"},{label:"X Axis",value:"axis"}];function Mb({control:t,watch:e}){return e("tooltip.trigger"),p(s.Stack,{children:[i(v.Controller,{name:"tooltip.trigger",control:t,render:({field:n})=>i(s.Select,{label:"Trigger",data:Ib,sx:{flexGrow:1},...n})}),i(s.Divider,{variant:"dashed"}),i(Db,{control:t,watch:e})]})}const Eb=({disabled:t,value:e,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[t&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(ze,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},Ab=y.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:a,setFalse:o}]=J.useBoolean(),[l,c]=y.useState(t);y.useEffect(()=>{c(t)},[t]);const u=m=>{c({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:C}=l,w={enabled:m,func_content:C};c(w),e(w)},f=()=>{o(),c(t)},h=m=>{c(C=>({...C,func_content:m}))},g=()=>{h(ko.func_content)};return p(N,{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=>u(m.currentTarget.checked)}),i(Eb,{value:l.func_content,onChange:h,disabled:!l.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:g,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:d,children:"OK"})]})]})]})})]})});function zb({control:t,watch:e}){return e(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>i(j,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Ab,{...n})})]})]})}const $b=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],Lb=[{label:"left",value:"left"},{label:"right",value:"right"}];function Ob({control:t,index:e,remove:n}){return p(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[i(s.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`y_axes.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`y_axes.${e}.nameAlignment`,control:t,render:({field:r})=>i(s.Select,{label:"Align",required:!0,data:$b,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`y_axes.${e}.position`,control:t,render:({field:r})=>i(s.Select,{label:"Position",required:!0,data:Lb,sx:{flex:1},...r})})}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:`y_axes.${e}.label_formatter`,control:t,render:({field:r})=>i(Je,{...r})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`y_axes.${e}.min`,control:t,render:({field:r})=>i(s.TextInput,{label:"Min",...r})}),i(v.Controller,{name:`y_axes.${e}.max`,control:t,render:({field:r})=>i(s.TextInput,{label:"Max",...r})})]})]}),i(s.Button,{mt:20,leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),disabled:e===0,children:"Delete this YAxis"})]})}function Pb({control:t,watch:e}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"y_axes"}),o=e("y_axes"),l=n.map((u,d)=>({...u,...o[d]})),c=()=>r({name:"",label_formatter:$e,min:"",max:"",show:!0,position:"right",nameAlignment:"right"});return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[l.map((u,d)=>i(s.Tabs.Tab,{value:d.toString(),children:d+1},d)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((u,d)=>i(s.Tabs.Panel,{value:d.toString(),children:i(Ob,{control:t,index:d,remove:a})},d))]})}function Bb(t){return t||{templates:{top:"",bottom:""}}}function Vb({reference_lines:t=[],stats:e,...n}){return{reference_lines:t,stats:Bb(e),...n}}function Nb({context:t}){const{value:e,set:n}=R(t.instanceData,"config"),{variables:r}=t,a=y.useMemo(()=>x.defaultsDeep({},e,ii),[e]),o=y.useMemo(()=>Vb(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:c,watch:u,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 u(["dataZoom"]),i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:c(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!g,children:i(I.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axes",children:"Y Axes"}),i(s.Tabs.Tab,{value:"Scatter",children:"Scatter"}),i(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"}),i(s.Tabs.Tab,{value:"Stats",children:"Stats"}),i(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"}),i(s.Tabs.Tab,{value:"Reference Areas",children:"Reference Areas"}),i(s.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(zb,{control:l,watch:u})}),i(s.Tabs.Panel,{value:"Y Axes",children:i(Pb,{control:l,watch:u})}),i(s.Tabs.Panel,{value:"Scatter",children:i(_b,{control:l,watch:u})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(Mb,{control:l,watch:u})}),i(s.Tabs.Panel,{value:"Stats",children:i(kb,{control:l,watch:u})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(cb,{variables:r,control:l,watch:u})}),i(s.Tabs.Panel,{value:"Reference Areas",children:i(ab,{variables:r,control:l,watch:u})}),i(s.Tabs.Panel,{value:"Zooming",children:i(v.Controller,{name:"dataZoom",control:l,render:({field:m})=>i(zr,{...m})})})]})]})})}function qb(t){const{dataZoom:e=Bt,...n}=t;return{...n,dataZoom:e}}function Fb(t){const e={scatter:{label_overflow:To}};return x.defaultsDeep(e,t)}function Gb(t){const{color:e}=t.scatter;return typeof e=="string"?{...t,scatter:{...t.scatter,color:{...an.static,color:e}}}:t}function Wb(t){const e=t.reference_lines.map(n=>{const{lineStyle:r={type:"dashed",width:1,color:at.random().css()},show_in_legend:a=!1,yAxisIndex:o=0}=n;return{...n,lineStyle:r,show_in_legend:a,yAxisIndex:o}});return{...t,reference_lines:e}}function Rb(t){const e={tooltip:{trigger:"item"}};return x.defaultsDeep({},t,e)}function jb(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis:a,scatter:o,tooltip:l,...c}=t;return{...c,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(u=>({...u,data_key:r(u.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}class Yb extends ve{constructor(){super(...arguments);V(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:qb(n.config)})),this.version(4,n=>{const{config:r}=n;return{...n,version:5,config:Fb(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:Gb(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:Wb(r)}}),this.version(8,n=>{const{config:r}=n;return{...n,version:8,config:Rb(r)}}),this.version(9,(n,r)=>{const{config:a}=n;return{...n,version:9,config:jb(a,r)}})}}const Qb={displayName:"Scatter Chart",displayGroup:"ECharts-based charts",migrator:new Yb,name:"scatterChart",viewRender:nb,configRender:Nb,createConfig(){return{version:9,config:x.cloneDeep(ii)}},triggers:[_o]},ai={template:"The variable ${value} is defined in Variables section",vertical_align:"center",horizontal_align:"left"};function Kb(t){if("variables"in t)return t;const{align:e,size:n,weight:r,color:a,content:{prefix:o="",data_field:l="value",formatter:c={output:"number",mantissa:0},postfix:u=""}={}}=t;return{align:e,template:`${o} \${value} ${u}`,variables:[{name:"value",data_field:l,aggregation:{type:"none",config:{}},formatter:c,color:a,weight:r,size:n}]}}function Ub(t){return x.omit(t,["variables"])}function Xb(t){const{align:e,...n}=t;return{horizontal_align:e,vertical_align:"center",...n}}function Jb(t){const e=x.cloneDeep(t),n=x.get(e,"color.valueRange");return n!==void 0&&x.set(e,"color.valueRange",n.map(r=>Number(r))),e}class Zb extends ve{constructor(){super(...arguments);V(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:Kb(n)})),this.version(2,(n,{panelModel:r})=>{const{config:a}=n;return(a.variables||[]).forEach(l=>{r.variables.find(c=>c.name===l.name)||r.addVariable(Jb(l))}),{...n,version:2,config:Ub(a)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:Xb(r)}})}}const Hb={left:"flex-start",center:"center",right:"flex-end"},ev={top:"flex-start",center:"center",bottom:"flex-end"},tv=k.observer(({context:t})=>{const e=K(),{value:n=ai}=R(t.instanceData,"config"),{variables:r}=t,{template:a,horizontal_align:o,vertical_align:l}=n,{width:c,height:u}=t.viewport,d=y.useMemo(()=>{try{return x.template(a)(e.payloadForSQL)}catch{return a}},[e.payloadForSQL,a]),f=y.useMemo(()=>Jt(d,r,t.data),[d,r,t.data,t]);return i(s.Center,{sx:{width:c,height:u,justifyContent:Hb[o],alignItems:ev[l]},children:i(s.Box,{children:Object.values(f).map((h,g)=>i(y.Fragment,{children:h},g))})})}),nv=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],rv=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function iv({context:t}){const{value:e,set:n}=R(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,ai),[e]),{control:a,handleSubmit:o,watch:l,getValues:c,reset:u}=v.useForm({defaultValues:r});y.useEffect(()=>{u(r)},[r]),l(["template","horizontal_align","vertical_align"]);const d=c(),f=y.useMemo(()=>!x.isEqual(d,e),[d,e]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{weight:500,children:"Stats Configurations"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(I.DeviceFloppy,{size:20})})]}),i(v.Controller,{name:"template",control:a,render:({field:h})=>i(Xt,{label:"Template",py:"md",sx:{flexGrow:1},...h})}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{name:"horizontal_align",control:a,render:({field:h})=>i(s.Select,{label:"Horizontal Alignment",data:nv,...h})}),i(v.Controller,{control:a,name:"vertical_align",render:({field:h})=>i(s.Select,{label:"Vertical Alignment",data:rv,...h})})]})]})})}const av={createConfig(){return{version:3,config:ai}},displayName:"Stats",displayGroup:"Others",migrator:new Zb,name:"stats",viewRender:tv,configRender:iv},si={label_key:"",value_key:"",group_key:"",levels:[]};function sv(t){const e=new Set(t.map(r=>r.parent_id)),n=new Set(t.map(r=>r.id));return e.forEach(r=>{r===null||n.has(r)||t.push({id:r,name:r,parent_id:null})}),t}function ov(t){const e=sv(t).map(a=>({...a,children:[]})),n=x.keyBy(e,a=>a.id),r=[];return e.forEach(a=>{if(!a.parent_id||!n[a.parent_id]){r.push(a);return}n[a.parent_id].children.push(a)}),r}function lv(t,e){const{label_key:n,value_key:r,group_key:a}=t;if(!n||!r)return[];const o=q(n),l=q(r),c=q(a),u=e[o.queryID].map(d=>({...d,id:d[o.columnKey],parent_id:d[c.columnKey],name:d[o.columnKey],value:d[l.columnKey]?Number(d[l.columnKey]):d[l.columnKey]}));return a?ov(u):u}const cv=t=>({treePathInfo:e,name:n,value:r})=>{if(e.length===1||!t)return n;try{const a=e[e.length-2].value;if(r/a<t)return" "}catch{return n}};function uv(t){const{levels:e}=t;return e.map(n=>{const{show_label_tolerance:r,...a}=n.label;return{...n,label:{...a,formatter:cv(r)}}})}function dv(){return({treePathInfo:t,name:e,value:n,color:r,marker:a,...o})=>{const l=t.slice(0,t.length-1),c=[`<tr>
|
|
339
|
+
`}}}function Zy(t,e){const n=e.every(a=>!Number.isNaN(Number(a))),{axisLabel:r}=t.x_axis;return[{data:e,name:t.x_axis.name??"",id:"main-x-axis",axisTick:{show:!0,alignWithLabel:!0},type:n?"value":"category",axisLabel:{...r,formatter:Do(r.formatter)}}]}function Hy(t,e){return t.y_axes.map(({nameAlignment:n,min:r,max:a,...o},l)=>{let u=o.position;return u||(u=l>0?"right":"left"),{...o,min:r||void 0,max:a||void 0,position:u,axisLabel:{show:!0,formatter:e[l]??e.default},axisLine:{show:!0},nameTextStyle:{fontWeight:"bold",align:n},nameLocation:"end",nameGap:15,splitLine:{show:!1}}})}const eb={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 tb(t,e,n){const r=n.reduce((c,d)=>{const f=Pt(d,e);return c[d.name]=ut(d,f),c},{}),a=t.y_axes.reduce((c,{label_formatter:d},f)=>(c[f]=function(g){let m=g;if(typeof g=="object"&&(Array.isArray(g.value)&&g.value.length===2?m=g.value[1]:m=g.value),!d)return m;try{return te(m).format(d)}catch(C){return console.error(C),m}},c),{default:({value:c})=>c}),o=x.uniq(ot(e,t.x_axis.data_key)),l=Ky(t,e,n,r),u={xAxis:Zy(t,o),yAxis:Hy(t,a),series:l,dataset:qy(t,e),tooltip:Jy(t,a),grid:Fy(t),legend:Gy(),dataZoom:Er(t.dataZoom)};return x.defaultsDeep({},u,eb)}ue.use([G.DataZoomComponent,he.BarChart,he.LineChart,he.ScatterChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer,G.MarkLineComponent,G.MarkAreaComponent]);function Mo(t){return t.trim().length>0}function nb({conf:t,data:e,width:n,height:r,interactionManager:a,variables:o}){const l=yt(e,t.x_axis.data_key),u=He(a.triggerManager,_o.id),c=y.useCallback(p=>{const g=p.data;u.forEach(m=>{a.runInteraction(m.id,{...p,rowData:g})})},[l,u,a]),d=y.useMemo(()=>({click:c}),[c]),f=y.useMemo(()=>tb(t,e,o),[t,e]);return i(Ne,{echarts:ue,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function rb({context:t,instance:e}){const n=et({vizManager:t.vizManager,instance:e}),{value:r}=R(t.instanceData,"config"),{variables:a}=t,o=y.useMemo(()=>x.defaults({},r,ii),[r]),l=t.data,{width:u,height:c}=t.viewport,{ref:d,height:f}=Ie.useElementSize(),{ref:p,height:g}=Ie.useElementSize(),m=y.useMemo(()=>{const{stats:{templates:w}}=o;return{top:Jt(w.top,a,l),bottom:Jt(w.bottom,a,l)}},[o,l]),C=Math.max(0,c-f-g);return!u||!c?null:h(s.Box,{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(nb,{variables:a,width:u,height:C,data:l,conf:o,interactionManager:n}),i(s.Text,{ref:p,align:"left",size:"xs",pl:"sm",sx:{display:Mo(o.stats.templates.bottom)?"block":"none"},children:Object.values(m.bottom).map(w=>w)})]})}const ib=y.forwardRef(({value:t,onChange:e,xAxisOptions:n,yAxisOptions:r,variableOptions:a},o)=>{const l=(u,c)=>{const d=x.cloneDeep(t);x.set(d,u,c),e(d)};return h(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Content",labelPosition:"right"}),h(s.Group,{grow:!0,noWrap:!0,children:[i(s.TextInput,{label:"Content Text",value:t.content.text,onChange:u=>l("content.text",u.currentTarget.value)}),i(Or,{label:"Text Position",value:t.label.position,onChange:u=>l("label.position",u)})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Endpoints",labelPosition:"right"}),h(s.Group,{grow:!0,noWrap:!0,children:[n&&i(s.Select,{label:"X Axis",data:n,value:t.xAxisIndex,onChange:u=>l("xAxisIndex",u)}),r&&i(s.Select,{label:"Y Axis",data:r,value:t.yAxisIndex,onChange:u=>l("xAxisIndex",u)})]}),h(s.Stack,{spacing:0,children:[i(s.Text,{size:14,color:"#212529",fw:500,children:"Left-Bottom Point"}),h(s.Group,{grow:!0,noWrap:!0,children:[i(s.Select,{icon:i(s.Text,{children:"x"}),data:a,value:t.leftBottomPoint.x_data_key,onChange:u=>l("leftBottomPoint.x_data_key",u??""),clearable:!0}),i(s.Select,{icon:i(s.Text,{children:"y"}),data:a,value:t.leftBottomPoint.y_data_key,onChange:u=>l("leftBottomPoint.y_data_key",u??""),clearable:!0})]})]}),h(s.Stack,{spacing:0,children:[i(s.Text,{size:14,color:"#212529",fw:500,children:"Right-Top Point"}),h(s.Group,{grow:!0,noWrap:!0,children:[i(s.Select,{icon:i(s.Text,{children:"x"}),data:a,value:t.rightTopPoint.x_data_key,onChange:u=>l("rightTopPoint.x_data_key",u??""),clearable:!0}),i(s.Select,{icon:i(s.Text,{children:"y"}),data:a,value:t.rightTopPoint.y_data_key,onChange:u=>l("rightTopPoint.y_data_key",u??""),clearable:!0})]})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Style",labelPosition:"right"}),h(s.Stack,{spacing:4,children:[i(s.Text,{size:14,children:"Background Color"}),i(Pe,{value:t.itemStyle.color,onChange:u=>l("itemStyle.color",u)})]}),h(s.Stack,{spacing:4,children:[i(s.Text,{size:14,children:"Text Color"}),i(Pe,{value:t.label.color,onChange:u=>l("label.color",u)})]})]})});function ab(){const t=new Date().getTime().toString();return{id:t,content:{text:t},itemStyle:{color:"rgba(0,0,0,0.05)"},label:{position:"inside",color:"rgba(0,0,0,0.5)"},leftBottomPoint:{x_data_key:"",y_data_key:""},rightTopPoint:{x_data_key:"",y_data_key:""},xAxisIndex:"0",yAxisIndex:"0"}}function sb({control:t,watch:e,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:t,name:"reference_areas"}),l=e("reference_areas"),u=r.map((g,m)=>({...g,...l[m]})),c=()=>{const g=ab();a(g)},d=y.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=e("y_axes"),p=y.useMemo(()=>f.map(({name:g},m)=>({label:g,value:m.toString()})),[f]);return h(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[h(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(I.Plus,{size:18,color:"#228be6"})})]}),u.map((g,m)=>i(s.Tabs.Panel,{value:m.toString(),children:i(v.Controller,{name:`reference_areas.${m}`,control:t,render:({field:C})=>h(s.Stack,{children:[i(ib,{variableOptions:d,yAxisOptions:p,...C}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(L.IconTrash,{size:16}),color:"red",variant:"light",onClick:()=>o(m),children:"Delete this Reference Area"})]})})},m))]})}const ob=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],lb=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function ub({control:t,index:e,remove:n,watch:r,variableOptions:a,yAxisOptions:o}){const l=r(`reference_lines.${e}.orientation`);return h(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${e}.name`,control:t,render:({field:u})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),i(v.Controller,{name:`reference_lines.${e}.variable_key`,control:t,render:({field:u})=>i(s.Select,{label:"Value",required:!0,data:a,sx:{flex:1},...u})})]}),i(v.Controller,{name:`reference_lines.${e}.template`,control:t,render:({field:u})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...u})}),h(s.Group,{grow:!0,children:[h(s.Stack,{children:[i(v.Controller,{name:`reference_lines.${e}.orientation`,control:t,render:({field:u})=>i(s.Select,{label:"Orientation",data:lb,required:!0,sx:{flex:1},...u})}),l==="vertical"&&i(s.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&i(v.Controller,{name:`reference_lines.${e}.yAxisIndex`,control:t,render:({field:{value:u,onChange:c,...d}})=>i(s.Select,{label:"Y Axis",data:o,disabled:o.length===0,...d,value:(u==null?void 0:u.toString())??"",onChange:f=>{if(!f){c(0);return}c(Number(f))},sx:{flex:1}})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),h(s.Group,{grow:!0,children:[i(v.Controller,{name:`reference_lines.${e}.lineStyle.type`,control:t,render:({field:u})=>i(s.Select,{label:"Line Type",data:ob,sx:{flexGrow:1},...u})}),i(v.Controller,{name:`reference_lines.${e}.lineStyle.width`,control:t,render:({field:u})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...u})})]}),h(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`reference_lines.${e}.lineStyle.color`,control:t,render:({field:u})=>i(Pe,{...u})})]}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Reference Line"})]},e)}function cb({control:t,watch:e,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:t,name:"reference_lines"}),l=e("reference_lines"),u=r.map((g,m)=>({...g,...l[m]})),c=()=>{const g={name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:at.random().css()},show_in_legend:!1,yAxisIndex:0};a(g)},d=y.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=e("y_axes"),p=y.useMemo(()=>f.map(({name:g},m)=>({label:g,value:m.toString()})),[f]);return h(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[h(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(I.Plus,{size:18,color:"#228be6"})})]}),u.map((g,m)=>i(s.Tabs.Panel,{value:m.toString(),children:i(ub,{control:t,index:m,remove:o,watch:e,variableOptions:d,yAxisOptions:p})},m))]})}const db=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return i(s.Box,{children:i(ze,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},pb=({value:t,onChange:e})=>{const[n,{setTrue:r,setFalse:a}]=J.useBoolean(),[o,l]=y.useState(t),u=()=>{a();const{type:p,func_content:g}=o,m={type:p,func_content:g};l(m),e(m)},c=()=>{a(),l(t)},d=p=>{l(g=>({...g,func_content:p}))},f=()=>{d(an.dynamic.func_content)};return h(N,{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&&h(s.Stack,{children:[i(s.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),i(db,{value:o.func_content,onChange:d}),h(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Reset"}),h(s.Group,{position:"right",children:[i(s.Button,{onClick:c,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:u,children:"OK"})]})]})]})})]})},hb=({value:t,onChange:e})=>t.type!=="dynamic"?null:i(pb,{value:t,onChange:e}),fb=({value:t,onChange:e})=>{if(t.type!=="static")return null;const n=r=>{e({...t,color:r})};return i(s.ColorInput,{label:" ",format:"rgb",value:t.color,onChange:n})},gb=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],mb=y.forwardRef(({label:t="Color",value:e,onChange:n},r)=>{const a=o=>{n({...an[o]})};return h(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:t,data:gb,value:e.type,onChange:a,sx:{flexGrow:1}}),i(fb,{value:e,onChange:n}),i(hb,{value:e,onChange:n})]})}),yb=y.forwardRef(({value:t,onChange:e},n)=>{const r=o=>{e({...t,label:o})},a=o=>{e({...t,tooltip:o})};return h(s.Stack,{ref:n,spacing:0,children:[i(Cn,{sectionTitle:"Overflow on Chart",value:t.label,onChange:r}),i(Cn,{sectionTitle:"Overflow in Tooltip",value:t.tooltip,onChange:a})]})}),bb=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return i(s.Box,{children:i(ze,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Eo={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
|
|
340
|
+
`)}},vb=({value:t,onChange:e})=>{const[n,{setTrue:r,setFalse:a}]=J.useBoolean(),[o,l]=y.useState(t),u=()=>{a();const{type:p,func_content:g}=o,m={type:p,func_content:g};l(m),e(m)},c=()=>{a(),l(t)},d=p=>{l(g=>({...g,func_content:p}))},f=()=>{d(Eo.dynamic.func_content)};return h(N,{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&&h(s.Stack,{children:[i(s.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),i(bb,{value:o.func_content,onChange:d}),h(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Rest"}),h(s.Group,{position:"right",children:[i(s.Button,{onClick:c,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:u,children:"OK"})]})]})]})})]})},xb=({value:t,onChange:e})=>t.type!=="dynamic"?null:i(vb,{value:t,onChange:e}),wb=({value:t,onChange:e})=>{if(t.type!=="static")return null;const n=r=>{e({...t,size:r})};return i(N,{children:i(s.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:t.size,onChange:n})})},Cb=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Sb=y.forwardRef(({label:t="Size",value:e,onChange:n},r)=>{const a=o=>{n({...Eo[o]})};return h(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:t,data:Cb,value:e.type,onChange:a,sx:{flexGrow:1}}),i(wb,{value:e,onChange:n}),i(xb,{value:e,onChange:n})]})}),_b=[{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 kb({control:t,watch:e}){return e(["scatter"]),h(s.Stack,{children:[h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"scatter.name_data_key",control:t,render:({field:n})=>i(j,{label:"Name Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"scatter.y_data_key",control:t,render:({field:n})=>i(j,{label:"Value Data Field",required:!0,sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Style",labelPosition:"center"}),i(v.Controller,{name:"scatter.symbolSize",control:t,render:({field:n})=>i(Sb,{label:"Size",...n})}),i(v.Controller,{name:"scatter.color",control:t,render:({field:n})=>i(mb,{...n})}),i(s.Divider,{mb:-15,label:"Label",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"scatter.label_position",control:t,render:({field:n})=>i(s.Select,{label:"Label Position",data:_b,...n})})}),i(v.Controller,{name:"scatter.label_overflow",control:t,render:({field:n})=>i(yb,{...n})})]})}function Tb({control:t,watch:e}){return e("stats"),i(s.Stack,{children:h(s.Stack,{spacing:0,children:[i(v.Controller,{name:"stats.templates.top",control:t,render:({field:n})=>i(Xt,{label:"Template for stats above the chart",py:"md",sx:{flexGrow:1},...n})}),i(v.Controller,{name:"stats.templates.bottom",control:t,render:({field:n})=>i(Xt,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const Db=({control:t,index:e,remove:n})=>h(s.Stack,{children:[h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${e}.data_key`,control:t,render:({field:r})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),Ib=({control:t,watch:e})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"tooltip.metrics"}),o=e("tooltip.metrics"),l=n.map((p,g)=>({...p,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=e("tooltip.metrics.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(p=>p!==null?p:c)},[c]),h(N,{children:[h(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(I.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),h(s.Tabs,{value:d,onTabChange:p=>f(p),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[h(s.Tabs.List,{children:[l.map((p,g)=>i(s.Tabs.Tab,{value:p.id,children:p.name?p.name:g},p.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((p,g)=>i(s.Tabs.Panel,{value:p.id,children:i(Db,{control:t,index:g,remove:a},p.id)},p.id))]})]})},Mb=[{label:"Scatter Point",value:"item"},{label:"X Axis",value:"axis"}];function Eb({control:t,watch:e}){return e("tooltip.trigger"),h(s.Stack,{children:[i(v.Controller,{name:"tooltip.trigger",control:t,render:({field:n})=>i(s.Select,{label:"Trigger",data:Mb,sx:{flexGrow:1},...n})}),i(s.Divider,{variant:"dashed"}),i(Ib,{control:t,watch:e})]})}const Ab=({disabled:t,value:e,onChange:n})=>{const r=a=>{a&&n(a)};return h(s.Box,{sx:{position:"relative"},children:[t&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(ze,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},zb=y.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:a,setFalse:o}]=J.useBoolean(),[l,u]=y.useState(t);y.useEffect(()=>{u(t)},[t]);const c=m=>{u({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:C}=l,w={enabled:m,func_content:C};u(w),e(w)},f=()=>{o(),u(t)},p=m=>{u(C=>({...C,func_content:m}))},g=()=>{p(ko.func_content)};return h(N,{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&&h(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:m=>c(m.currentTarget.checked)}),i(Ab,{value:l.func_content,onChange:p,disabled:!l.enabled}),h(s.Group,{position:"apart",children:[i(s.Button,{onClick:g,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Rest"}),h(s.Group,{position:"right",children:[i(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:d,children:"OK"})]})]})]})})]})});function $b({control:t,watch:e}){return e(["x_axis"]),h(s.Stack,{children:[h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>i(j,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>i(zb,{...n})})]})]})}const Lb=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],Ob=[{label:"left",value:"left"},{label:"right",value:"right"}];function Pb({control:t,index:e,remove:n}){return h(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[i(s.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`y_axes.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`y_axes.${e}.nameAlignment`,control:t,render:({field:r})=>i(s.Select,{label:"Align",required:!0,data:Lb,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`y_axes.${e}.position`,control:t,render:({field:r})=>i(s.Select,{label:"Position",required:!0,data:Ob,sx:{flex:1},...r})})}),h(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:`y_axes.${e}.label_formatter`,control:t,render:({field:r})=>i(Je,{...r})})]}),h(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),h(s.Group,{grow:!0,children:[i(v.Controller,{name:`y_axes.${e}.min`,control:t,render:({field:r})=>i(s.TextInput,{label:"Min",...r})}),i(v.Controller,{name:`y_axes.${e}.max`,control:t,render:({field:r})=>i(s.TextInput,{label:"Max",...r})})]})]}),i(s.Button,{mt:20,leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),disabled:e===0,children:"Delete this YAxis"})]})}function Bb({control:t,watch:e}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"y_axes"}),o=e("y_axes"),l=n.map((c,d)=>({...c,...o[d]})),u=()=>r({name:"",label_formatter:$e,min:"",max:"",show:!0,position:"right",nameAlignment:"right"});return h(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[h(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(I.Plus,{size:18,color:"#228be6"})})]}),l.map((c,d)=>i(s.Tabs.Panel,{value:d.toString(),children:i(Pb,{control:t,index:d,remove:a})},d))]})}function Vb(t){return t||{templates:{top:"",bottom:""}}}function Nb({reference_lines:t=[],stats:e,...n}){return{reference_lines:t,stats:Vb(e),...n}}function qb({context:t}){const{value:e,set:n}=R(t.instanceData,"config"),{variables:r}=t,a=y.useMemo(()=>x.defaultsDeep({},e,ii),[e]),o=y.useMemo(()=>Nb(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 p=d(),g=y.useMemo(()=>!x.isEqual(p,a),[p,a]);return c(["dataZoom"]),i(s.Stack,{spacing:"xs",children:h("form",{onSubmit:u(n),children:[h(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!g,children:i(I.DeviceFloppy,{size:20})})]}),h(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[h(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($b,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Y Axes",children:i(Bb,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Scatter",children:i(kb,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(Eb,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Stats",children:i(Tb,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(cb,{variables:r,control:l,watch:c})}),i(s.Tabs.Panel,{value:"Reference Areas",children:i(sb,{variables:r,control:l,watch:c})}),i(s.Tabs.Panel,{value:"Zooming",children:i(v.Controller,{name:"dataZoom",control:l,render:({field:m})=>i(zr,{...m})})})]})]})})}function Fb(t){const{dataZoom:e=Bt,...n}=t;return{...n,dataZoom:e}}function Gb(t){const e={scatter:{label_overflow:To}};return x.defaultsDeep(e,t)}function Wb(t){const{color:e}=t.scatter;return typeof e=="string"?{...t,scatter:{...t.scatter,color:{...an.static,color:e}}}:t}function Rb(t){const e=t.reference_lines.map(n=>{const{lineStyle:r={type:"dashed",width:1,color:at.random().css()},show_in_legend:a=!1,yAxisIndex:o=0}=n;return{...n,lineStyle:r,show_in_legend:a,yAxisIndex:o}});return{...t,reference_lines:e}}function jb(t){const e={tooltip:{trigger:"item"}};return x.defaultsDeep({},t,e)}function Yb(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,scatter:o,tooltip:l,...u}=t;return{...u,x_axis:{...a,data_key:r(a.data_key)},scatter:{...o,y_data_key:r(o.y_data_key),name_data_key:r(o.name_data_key)},tooltip:{...l,metrics:l.metrics.map(c=>({...c,data_key:r(c.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}class Qb extends ve{constructor(){super(...arguments);V(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:Fb(n.config)})),this.version(4,n=>{const{config:r}=n;return{...n,version:5,config:Gb(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:Wb(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:Rb(r)}}),this.version(8,n=>{const{config:r}=n;return{...n,version:8,config:jb(r)}}),this.version(9,(n,r)=>{const{config:a}=n;return{...n,version:9,config:Yb(a,r)}})}}const Kb={displayName:"Scatter Chart",displayGroup:"ECharts-based charts",migrator:new Qb,name:"scatterChart",viewRender:rb,configRender:qb,createConfig(){return{version:9,config:x.cloneDeep(ii)}},triggers:[_o]},ai={template:"The variable ${value} is defined in Variables section",vertical_align:"center",horizontal_align:"left"};function Ub(t){if("variables"in t)return t;const{align:e,size:n,weight:r,color:a,content:{prefix:o="",data_field:l="value",formatter:u={output:"number",mantissa:0},postfix:c=""}={}}=t;return{align:e,template:`${o} \${value} ${c}`,variables:[{name:"value",data_field:l,aggregation:{type:"none",config:{}},formatter:u,color:a,weight:r,size:n}]}}function Xb(t){return x.omit(t,["variables"])}function Jb(t){const{align:e,...n}=t;return{horizontal_align:e,vertical_align:"center",...n}}function Zb(t){const e=x.cloneDeep(t),n=x.get(e,"color.valueRange");return n!==void 0&&x.set(e,"color.valueRange",n.map(r=>Number(r))),e}class Hb extends ve{constructor(){super(...arguments);V(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:Ub(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(Zb(l))}),{...n,version:2,config:Xb(a)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:Jb(r)}})}}const ev={left:"flex-start",center:"center",right:"flex-end"},tv={top:"flex-start",center:"center",bottom:"flex-end"},nv=k.observer(({context:t})=>{const e=K(),{value:n=ai}=R(t.instanceData,"config"),{variables:r}=t,{template:a,horizontal_align:o,vertical_align:l}=n,{width:u,height:c}=t.viewport,d=y.useMemo(()=>{try{return x.template(a)(e.payloadForSQL)}catch{return a}},[e.payloadForSQL,a]),f=y.useMemo(()=>Jt(d,r,t.data),[d,r,t.data,t]);return i(s.Center,{sx:{width:u,height:c,justifyContent:ev[o],alignItems:tv[l]},children:i(s.Box,{children:Object.values(f).map((p,g)=>i(y.Fragment,{children:p},g))})})}),rv=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],iv=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function av({context:t}){const{value:e,set:n}=R(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,ai),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l(["template","horizontal_align","vertical_align"]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,e),[d,e]);return i(s.Stack,{spacing:"xs",children:h("form",{onSubmit:o(n),children:[h(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{weight:500,children:"Stats Configurations"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(I.DeviceFloppy,{size:20})})]}),i(v.Controller,{name:"template",control:a,render:({field:p})=>i(Xt,{label:"Template",py:"md",sx:{flexGrow:1},...p})}),h(s.SimpleGrid,{cols:2,children:[i(v.Controller,{name:"horizontal_align",control:a,render:({field:p})=>i(s.Select,{label:"Horizontal Alignment",data:rv,...p})}),i(v.Controller,{control:a,name:"vertical_align",render:({field:p})=>i(s.Select,{label:"Vertical Alignment",data:iv,...p})})]})]})})}const sv={createConfig(){return{version:3,config:ai}},displayName:"Stats",displayGroup:"Others",migrator:new Hb,name:"stats",viewRender:nv,configRender:av},si={label_key:"",value_key:"",group_key:"",levels:[]};function ov(t){const e=new Set(t.map(r=>r.parent_id)),n=new Set(t.map(r=>r.id));return e.forEach(r=>{r===null||n.has(r)||t.push({id:r,name:r,parent_id:null})}),t}function lv(t){const e=ov(t).map(a=>({...a,children:[]})),n=x.keyBy(e,a=>a.id),r=[];return e.forEach(a=>{if(!a.parent_id||!n[a.parent_id]){r.push(a);return}n[a.parent_id].children.push(a)}),r}function uv(t,e){const{label_key:n,value_key:r,group_key:a}=t;if(!n||!r)return[];const o=q(n),l=q(r),u=q(a),c=e[o.queryID].map(d=>({...d,id:d[o.columnKey],parent_id:d[u.columnKey],name:d[o.columnKey],value:d[l.columnKey]?Number(d[l.columnKey]):d[l.columnKey]}));return a?lv(c):c}const cv=t=>({treePathInfo:e,name:n,value:r})=>{if(e.length===1||!t)return n;try{const a=e[e.length-2].value;if(r/a<t)return" "}catch{return n}};function dv(t){const{levels:e}=t;return e.map(n=>{const{show_label_tolerance:r,...a}=n.label;return{...n,label:{...a,formatter:cv(r)}}})}function pv(){return({treePathInfo:t,name:e,value:n,color:r,marker:a,...o})=>{const l=t.slice(0,t.length-1),u=[`<tr>
|
|
341
341
|
<th style="text-align: right; padding: 0 1em;">Value</th>
|
|
342
342
|
<td style="text-align: left; padding: 0 1em;">${n}</td>
|
|
343
343
|
</tr>
|
|
344
|
-
`];return l.reverse().forEach(({value:d,name:f})=>{
|
|
344
|
+
`];return l.reverse().forEach(({value:d,name:f})=>{u.push(`
|
|
345
345
|
<tr>
|
|
346
346
|
<th style="text-align: right; padding: 0 1em;">${f||"Total"}</th>
|
|
347
347
|
<td style="text-align: left; padding: 0 1em;">
|
|
@@ -353,10 +353,10 @@ Check the top-level render call using <`+P+">.")}return A}}function ql(S,A){{if(
|
|
|
353
353
|
<div>${a} ${e}</div>
|
|
354
354
|
</div>
|
|
355
355
|
<table style="width: auto">
|
|
356
|
-
<tbody>${
|
|
356
|
+
<tbody>${u.join("")}</tbody>
|
|
357
357
|
</table>
|
|
358
|
-
`}}function
|
|
359
|
-
`),oi={func_content:Ao,horizontal_align:"left",font_size:"14px",font_weight:"normal"},Iv=k.observer(({context:t})=>{const e=K(),{value:n=oi}=R(t.instanceData,"config"),{variables:r}=t,a=t.data,{func_content:o,horizontal_align:l,font_size:c,font_weight:u}=n,d=y.useMemo(()=>r.reduce((h,g)=>{const m=Pt(g,a);return h[g.name]=ct(g,m),h},{}),[r,a]),f=y.useMemo(()=>new Function(`return ${o}`)()({data:a,variables:d,filters:e.payloadForSQL.filters,context:e.payloadForSQL.context}),[o,a,d,e.payloadForSQL]);return i(s.Text,{align:l,weight:u,sx:{fontSize:c},children:f})}),Mv=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return i(s.Box,{sx:{position:"relative"},children:i(ze,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Ev=y.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:a,setFalse:o}]=J.useBoolean(),[l,c]=y.useState(t),u=()=>{o(),e(l)},d=()=>{o(),c(t)},f=()=>{c(Ao)};return y.useEffect(()=>{c(t)},[t]),p(N,{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(Mv,{value:l,onChange:c}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:u,children:"OK"})]})]})]})})]})}),Av=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}];function zv({context:t}){const{value:e,set:n}=R(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,oi),[e]),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:c,getValues:u,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]),c(["func_content","horizontal_align","font_size","font_weight"]);const f=u(),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(I.DeviceFloppy,{size:20})})]}),p(s.Stack,{spacing:10,children:[i(v.Controller,{name:"func_content",control:o,render:({field:g})=>i(Ev,{...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:Av,...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(Cs,{label:"Font Weight",...g})})})]})]})})}class $v extends ve{constructor(){super(...arguments);V(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const Lv={displayName:"Text",displayGroup:"Others",migrator:new $v,name:"text",viewRender:Iv,configRender:zv,createConfig(){return{version:1,config:x.cloneDeep(oi)}}},Ov=()=>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 zo(t,e){const n=x.get(t,e,"");if(n)throw new Error(n)}async function Pv(t,e,n,r={}){const a={"X-Requested-With":"XMLHttpRequest","Content-Type":r.string?"application/x-www-form-urlencoded":"application/json",...r.headers},o={baseURL:t,method:"POST",url:e,params:r.params,headers:a};return o.data=r.string?JSON.stringify(n):n,pt(o).then(l=>l.data).catch(l=>Promise.reject(l))}const Bv=({conf:t,panelData:e})=>async()=>{const{expertSystemURL:n,path:r,goal:a,question:o}=t;if(!r||!a||!o)return;const l=au(e);if(!l)return;const c={dashboard:a,panel:o,data:l};try{const u=n.startsWith("http")?n:window.location.origin;return await Pv(u,`/expert/v3/devtable/${r}`,c,{})}catch(u){throw zo(u,"response.data.detail"),zo(u,"response.data.error"),console.error(u),u}},li={expertSystemURL:"",path:"",goal:"",question:""},ci={height:"100%",overflowY:"auto",...Fr},$o=({message:t})=>i(s.Box,{sx:ci,children:i("div",{dangerouslySetInnerHTML:{__html:t},style:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45"}})}),Vv=({error:t,width:e,height:n})=>{const r=t.message;if(r.startsWith("<"))return i($o,{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(Ov,{}),i($o,{message:r})]})})};function Nv({context:t}){const{value:e}=R(t.instanceData,"config"),n=y.useMemo(()=>x.defaultsDeep({},e,li),[e]),{width:r,height:a}=t.viewport,o=t.data,{data:l,error:c,loading:u}=J.useRequest(Bv({conf:n,panelData:o}),{refreshDeps:[o,n]});return!r||!a||!n?null:u?i(s.Box,{sx:{position:"relative",height:a},children:i(s.LoadingOverlay,{visible:!0})}):c?i(s.Box,{sx:ci,"data-enable-scrollbar":!0,children:i(Vv,{error:c,width:r,height:a})}):!l||!Array.isArray(l.replies)||l.replies.length===0?null:i(s.Box,{sx:ci,"data-enable-scrollbar":!0,children:l.replies.map((d,f)=>i("div",{dangerouslySetInnerHTML:{__html:d.interpretation.html}},f))})}function qv({context:t}){const{value:e,set:n}=R(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,li),[e]),{control:a,handleSubmit:o,watch:l,getValues:c,reset:u}=v.useForm({defaultValues:r});y.useEffect(()=>{u(r)},[r]),l(["expertSystemURL","goal","path","question"]);const d=c(),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(I.DeviceFloppy,{size:20}),disabled:!f,sx:{alignSelf:"flex-end"},children:"Submit Changes"})]})})}class Fv extends ve{constructor(){super(...arguments);V(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const Gv={displayName:"Merico GQM",displayGroup:"Merico suite",migrator:new Fv,name:"mericoGQM",viewRender:Nv,configRender:qv,createConfig(){return{version:1,config:x.cloneDeep(li)}}};function Wv(t,e,n){if(!t)return n[0];try{return[e,Y(e).add(1,"year").subtract(1,"day").valueOf()]}catch(r){return console.error(r),n[0]}}function Rv(t,e,n){const r=Wv(t,e,n);return{top:50,left:25,right:5,cellSize:["auto",13],range:r,itemStyle:{borderColor:"#eee"},splitLine:{show:!0},dayLabel:{firstDay:1},monthLabel:{position:"end"},yearLabel:{show:!0}}}function jv(t){return{heat_block:function(r){if(!t.heat_block.value_formatter)return r;try{return te(r).format(t.heat_block.value_formatter)}catch(a){return console.error(a),r}}}}function Yv(t,e){return{show:!t,selectedMode:"single",top:5,right:5,data:e.map(n=>({name:n,icon:"circle"}))}}function Qv(t,e,n,r){const{calendar:a,heat_block:o}=t,l=q(a.data_key),c=q(o.data_key);return e?{type:"heatmap",name:"heatmap",coordinateSystem:"calendar",calendarIndex:0,data:r[l.queryID].map(u=>[x.get(u,l.columnKey),x.get(u,c.columnKey)])}:Object.entries(n).map(([u,d])=>({type:"heatmap",name:u,coordinateSystem:"calendar",calendarIndex:0,data:d.map(f=>[x.get(f,l.columnKey),x.get(f,c.columnKey)])}))}const Kv=t=>{try{return te(t).format({trimMantissa:!0,mantissa:2})}catch{return t}};function Uv({conf:t,valueFormatters:e,dataDict:n,params:r}){const{value:a}=r,[o,l]=a,u=[{label:t.heat_block.name,value:e.heat_block(l),style:{label:"",value:""}}],d=n[o];return d&&t.tooltip.metrics.forEach(f=>{const h=q(f.data_key);u.push({label:f.name,value:Kv(x.get(d,h.columnKey,"")),style:{label:"",value:""}})}),u}function Xv(t,e,n){const r=q(t.calendar.data_key),a=x.keyBy(e[r.queryID],r.columnKey);return{confine:!0,formatter:function(o){const c=Uv({conf:t,valueFormatters:n,dataDict:a,params:o}).map(f=>`
|
|
358
|
+
`}}function hv(){return{show:!0,trigger:"item",confine:!0,formatter:pv()}}const fv={tooltip:{show:!0},series:{type:"sunburst",radius:[0,"90%"],emphasis:{focus:"ancestor"}}};function gv(t,e,n){n.reduce((o,l)=>{const u=Pt(l,e);return o[l.name]=ut(l,u),o},{});const a={series:{data:uv(t,e),levels:dv(t)},tooltip:hv()};return x.defaultsDeep({},a,fv)}ue.use([he.SunburstChart,Ve.CanvasRenderer]);function mv({context:t}){const{variables:e}=t,{value:n}=R(t.instanceData,"config"),r=y.useMemo(()=>x.defaults({},n,si),[n]),a=t.data,{width:o,height:l}=t.viewport,u=y.useMemo(()=>gv(r,a,e),[r,a,e]);return!o||!l?null:i(Ne,{echarts:ue,option:u,style:{width:o,height:l},notMerge:!0,theme:"merico-light"})}function yv({control:t,watch:e}){return e(["label_key","value_key","group_key"]),h(s.Stack,{children:[i(v.Controller,{name:"label_key",control:t,render:({field:n})=>i(j,{label:"Label Key",required:!0,...n})}),i(v.Controller,{name:"value_key",control:t,render:({field:n})=>i(j,{label:"Value Key",required:!0,...n})}),i(v.Controller,{name:"group_key",control:t,render:({field:n})=>i(j,{label:"Group Key",clearable:!0,...n})})]})}const bv=[{label:"Radial",value:"radial"},{label:"Tangential",value:"tangential"},{label:"None",value:"0"}],vv=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],xv=({control:t,index:e,remove:n})=>h(s.Stack,{children:[h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`levels.${e}.r0`,control:t,render:({field:r})=>i(s.TextInput,{label:"Inside Radius",placeholder:"0%",...r})}),i(v.Controller,{name:`levels.${e}.r`,control:t,render:({field:r})=>i(s.TextInput,{label:"Outside Radius",placeholder:"50%",...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Label Style",labelPosition:"center"}),i(v.Controller,{name:`levels.${e}.label.show_label_tolerance`,control:t,render:({field:r})=>i(s.NumberInput,{label:"Hide label when its percentage is less than...",precision:4,step:5e-4,min:0,max:1,...r})}),h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`levels.${e}.label.rotate`,control:t,render:({field:r})=>i(s.Select,{label:"Rotate",data:bv,...r})}),i(v.Controller,{name:`levels.${e}.label.align`,control:t,render:({field:r})=>i(s.Select,{label:"Align",data:vv,...r})})]}),h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`levels.${e}.label.position`,control:t,render:({field:r})=>i(Or,{label:"Position",...r})}),i(v.Controller,{name:`levels.${e}.label.padding`,control:t,render:({field:r})=>i(s.NumberInput,{label:"Padding",min:0,hideControls:!0,...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Level"})]}),wv=({control:t,watch:e})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"levels"}),o=e("levels"),l=n.map((p,g)=>({...p,...o[g]})),u=()=>r({id:Date.now().toString(),r0:"",r:"",label:{show_label_tolerance:.001,rotate:"0",align:"center",position:"inside",padding:0}}),c=e("levels.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(p=>p!==null?p:c)},[c]),h(N,{children:[h(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(I.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Configure ring style on each level"})]}),i(s.Divider,{variant:"dashed",my:10}),h(s.Tabs,{value:d,onTabChange:p=>f(p),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[h(s.Tabs.List,{children:[l.map((p,g)=>i(s.Tabs.Tab,{value:p.id,children:g},p.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((p,g)=>i(s.Tabs.Panel,{value:p.id,children:i(xv,{control:t,index:g,remove:a},p.id)},p.id))]})]})};function Cv({context:t}){const{value:e,set:n}=R(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,si),[e]),a=y.useMemo(()=>x.clone(r),[r]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),p=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:h(s.Stack,{spacing:"xs",children:[h(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:!p,children:i(I.DeviceFloppy,{size:20})})]}),h(s.Tabs,{value:g,onTabChange:m,orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[h(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(yv,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Levels",children:i(wv,{control:o,watch:u})})]})]})})}function Sv(t){const{label_field:e,value_field:n,...r}=t;return{...r,label_key:e,value_key:n}}function _v(t){const{group_key:e="",...n}=t;return{...n,group_key:e}}function kv(t){const{levels:e=[],...n}=t;return{...n,levels:e}}function Tv(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{label_key:a,value_key:o,group_key:l,...u}=t;return{...u,label_key:r(a),value_key:r(o),group_key:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class Dv extends ve{constructor(){super(...arguments);V(this,"VERSION",5)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:Sv(n.config)})),this.version(3,n=>({...n,version:3,config:_v(n.config)})),this.version(4,n=>({...n,version:4,config:kv(n.config)})),this.version(5,(n,r)=>({...n,version:5,config:Tv(n.config,r)}))}}const Iv={displayName:"Sunburst Chart",displayGroup:"ECharts-based charts",migrator:new Dv,name:"sunburst",viewRender:mv,configRender:Cv,createConfig(){return{version:5,config:x.cloneDeep(si)}}},Ao=["function text({ data, variables, filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
|
|
359
|
+
`),oi={func_content:Ao,horizontal_align:"left",font_size:"14px",font_weight:"normal"},Mv=k.observer(({context:t})=>{const e=K(),{value:n=oi}=R(t.instanceData,"config"),{variables:r}=t,a=t.data,{func_content:o,horizontal_align:l,font_size:u,font_weight:c}=n,d=y.useMemo(()=>r.reduce((p,g)=>{const m=Pt(g,a);return p[g.name]=ut(g,m),p},{}),[r,a]),f=y.useMemo(()=>new Function(`return ${o}`)()({data:a,variables:d,filters:e.payloadForSQL.filters,context:e.payloadForSQL.context}),[o,a,d,e.payloadForSQL]);return i(s.Text,{align:l,weight:c,sx:{fontSize:u},children:f})}),Ev=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return i(s.Box,{sx:{position:"relative"},children:i(ze,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Av=y.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:a,setFalse:o}]=J.useBoolean(),[l,u]=y.useState(t),c=()=>{o(),e(l)},d=()=>{o(),u(t)},f=()=>{u(Ao)};return y.useEffect(()=>{u(t)},[t]),h(N,{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&&h(s.Stack,{children:[i(Ev,{value:l,onChange:u}),h(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Rest"}),h(s.Group,{position:"right",children:[i(s.Button,{onClick:d,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:c,children:"OK"})]})]})]})})]})}),zv=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}];function $v({context:t}){const{value:e,set:n}=R(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,oi),[e]),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(),p=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return i(s.Stack,{spacing:"xs",children:h("form",{onSubmit:l(n),children:[h(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:!p,children:i(I.DeviceFloppy,{size:20})})]}),h(s.Stack,{spacing:10,children:[i(v.Controller,{name:"func_content",control:o,render:({field:g})=>i(Av,{...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:zv,...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(Cs,{label:"Font Weight",...g})})})]})]})})}class Lv extends ve{constructor(){super(...arguments);V(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const Ov={displayName:"Text",displayGroup:"Others",migrator:new Lv,name:"text",viewRender:Mv,configRender:$v,createConfig(){return{version:1,config:x.cloneDeep(oi)}}},Pv=()=>h("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 zo(t,e){const n=x.get(t,e,"");if(n)throw new Error(n)}async function Bv(t,e,n,r={}){const a={"X-Requested-With":"XMLHttpRequest","Content-Type":r.string?"application/x-www-form-urlencoded":"application/json",...r.headers},o={baseURL:t,method:"POST",url:e,params:r.params,headers:a};return o.data=r.string?JSON.stringify(n):n,pt(o).then(l=>l.data).catch(l=>Promise.reject(l))}const Vv=({conf:t,panelData:e})=>async()=>{const{expertSystemURL:n,path:r,goal:a,question:o}=t;if(!r||!a||!o)return;const l=sc(e);if(!l)return;const u={dashboard:a,panel:o,data:l};try{const c=n.startsWith("http")?n:window.location.origin;return await Bv(c,`/expert/v3/devtable/${r}`,u,{})}catch(c){throw zo(c,"response.data.detail"),zo(c,"response.data.error"),console.error(c),c}},li={expertSystemURL:"",path:"",goal:"",question:""},ui={height:"100%",overflowY:"auto",...Fr},$o=({message:t})=>i(s.Box,{sx:ui,children:i("div",{dangerouslySetInnerHTML:{__html:t},style:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45"}})}),Nv=({error:t,width:e,height:n})=>{const r=t.message;if(r.startsWith("<"))return i($o,{message:r});const o=n-25-20-30;return i(s.Center,{sx:{width:"100%",height:o},children:h(s.Stack,{align:"center",spacing:20,children:[i(Pv,{}),i($o,{message:r})]})})};function qv({context:t}){const{value:e}=R(t.instanceData,"config"),n=y.useMemo(()=>x.defaultsDeep({},e,li),[e]),{width:r,height:a}=t.viewport,o=t.data,{data:l,error:u,loading:c}=J.useRequest(Vv({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:ui,"data-enable-scrollbar":!0,children:i(Nv,{error:u,width:r,height:a})}):!l||!Array.isArray(l.replies)||l.replies.length===0?null:i(s.Box,{sx:ui,"data-enable-scrollbar":!0,children:l.replies.map((d,f)=>i("div",{dangerouslySetInnerHTML:{__html:d.interpretation.html}},f))})}function Fv({context:t}){const{value:e,set:n}=R(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,li),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l(["expertSystemURL","goal","path","question"]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,r),[d,r]);return i("form",{onSubmit:o(n),children:h(s.Stack,{children:[h(s.Group,{grow:!0,children:[i(v.Controller,{name:"expertSystemURL",control:a,render:({field:p})=>i(s.TextInput,{label:"Expert System URL",...p})}),i(v.Controller,{name:"path",control:a,render:({field:p})=>i(s.TextInput,{label:"Path",required:!0,...p})})]}),h(s.Group,{grow:!0,children:[i(v.Controller,{name:"goal",control:a,render:({field:p})=>i(s.TextInput,{label:"Goal",required:!0,...p})}),i(v.Controller,{name:"question",control:a,render:({field:p})=>i(s.TextInput,{label:"Question",required:!0,...p})})]}),i(s.Divider,{variant:"dashed",mt:16,mb:8}),i(s.Button,{type:"submit",variant:"filled",color:"blue",leftIcon:i(I.DeviceFloppy,{size:20}),disabled:!f,sx:{alignSelf:"flex-end"},children:"Submit Changes"})]})})}class Gv extends ve{constructor(){super(...arguments);V(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const Wv={displayName:"Merico GQM",displayGroup:"Merico suite",migrator:new Gv,name:"mericoGQM",viewRender:qv,configRender:Fv,createConfig(){return{version:1,config:x.cloneDeep(li)}}};function Rv(t,e,n){if(!t)return n[0];try{return[e,Y(e).add(1,"year").subtract(1,"day").valueOf()]}catch(r){return console.error(r),n[0]}}function jv(t,e,n){const r=Rv(t,e,n);return{top:50,left:25,right:5,cellSize:["auto",13],range:r,itemStyle:{borderColor:"#eee"},splitLine:{show:!0},dayLabel:{firstDay:1},monthLabel:{position:"end"},yearLabel:{show:!0}}}function Yv(t){return{heat_block:function(r){if(!t.heat_block.value_formatter)return r;try{return te(r).format(t.heat_block.value_formatter)}catch(a){return console.error(a),r}}}}function Qv(t,e){return{show:!t,selectedMode:"single",top:5,right:5,data:e.map(n=>({name:n,icon:"circle"}))}}function Kv(t,e,n,r){const{calendar:a,heat_block:o}=t,l=q(a.data_key),u=q(o.data_key);return e?{type:"heatmap",name:"heatmap",coordinateSystem:"calendar",calendarIndex:0,data:r[l.queryID].map(c=>[x.get(c,l.columnKey),x.get(c,u.columnKey)])}:Object.entries(n).map(([c,d])=>({type:"heatmap",name:c,coordinateSystem:"calendar",calendarIndex:0,data:d.map(f=>[x.get(f,l.columnKey),x.get(f,u.columnKey)])}))}const Uv=t=>{try{return te(t).format({trimMantissa:!0,mantissa:2})}catch{return t}};function Xv({conf:t,valueFormatters:e,dataDict:n,params:r}){const{value:a}=r,[o,l]=a,c=[{label:t.heat_block.name,value:e.heat_block(l),style:{label:"",value:""}}],d=n[o];return d&&t.tooltip.metrics.forEach(f=>{const p=q(f.data_key);c.push({label:f.name,value:Uv(x.get(d,p.columnKey,"")),style:{label:"",value:""}})}),c}function Jv(t,e,n){const r=q(t.calendar.data_key),a=x.keyBy(e[r.queryID],r.columnKey);return{confine:!0,formatter:function(o){const u=Xv({conf:t,valueFormatters:n,dataDict:a,params:o}).map(f=>`
|
|
360
360
|
<tr>
|
|
361
361
|
<th style="text-align: right;">
|
|
362
362
|
<div style="${f.style.label}">${f.label}</div>
|
|
@@ -365,7 +365,7 @@ Check the top-level render call using <`+P+">.")}return A}}function ql(S,A){{if(
|
|
|
365
365
|
<div style="${f.style.value}">${f.value}
|
|
366
366
|
</td>
|
|
367
367
|
</tr>
|
|
368
|
-
`),
|
|
368
|
+
`),c=x.get(o.value,0);return`
|
|
369
369
|
<table style="width: auto">
|
|
370
370
|
<thead>
|
|
371
371
|
<tr colspan="2">
|
|
@@ -376,28 +376,28 @@ Check the top-level render call using <`+P+">.")}return A}}function ql(S,A){{if(
|
|
|
376
376
|
</tr>
|
|
377
377
|
<tr>
|
|
378
378
|
<th colspan="2" style="text-align: center;">
|
|
379
|
-
<div>${
|
|
379
|
+
<div>${c}</div>
|
|
380
380
|
</th>
|
|
381
381
|
</tr>
|
|
382
382
|
</thead>
|
|
383
|
-
<tbody>${
|
|
383
|
+
<tbody>${u.join("")}</tbody>
|
|
384
384
|
</table>
|
|
385
|
-
`}}}function Jv(t,e){return{min:t.heat_block.min??0,max:t.heat_block.max??100,calculable:!0,orient:"horizontal",left:e?"center":5,top:0,itemWidth:15}}const Zv={tooltip:{confine:!0},grid:{containLabel:!0}},Hv=t=>Y(t).get("year");function ex(t,e){const n=q(t.calendar.data_key),r=e[n.queryID],a=x.groupBy(r,d=>Hv(d[n.columnKey])),o=Object.keys(a),l=r.map(d=>Y(d[n.columnKey]).valueOf()),c=x.min(l),u=x.max(l);return{minDate:c??0,maxDate:u??0,dateSpan:Y(u).diff(c,"day"),dataByYear:a,years:o}}function tx(t,e,n){const r=jv(t),{dateSpan:a,minDate:o,dataByYear:l,years:c}=ex(t,e),u=a<=366,d={calendar:Rv(u,o,c),series:Qv(t,u,l,e),tooltip:Xv(t,e,r),visualMap:Jv(t,u),legend:Yv(u,c)};return x.defaultsDeep({},d,Zv)}function nx(t){return i(N,{})}function rx(t){return i(s.Text,{children:"Click heat block"})}const Lo={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:rx,configRender:nx,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"}]},ui={calendar:{data_key:"",locale:"EN"},heat_block:{min:0,max:1e3,name:"Value",data_key:"",value_formatter:$e},tooltip:{metrics:[]}};ce.use([G.DataZoomComponent,he.BarChart,he.LineChart,he.HeatmapChart,G.CalendarComponent,G.GridComponent,G.LegendComponent,G.TooltipComponent,G.VisualMapComponent,Ve.CanvasRenderer]);function ix({name:t},e){const n=e.getOption();n.calendar.forEach(r=>{r.range=t}),e.setOption(n)}function ax({conf:t,data:e,width:n,height:r,interactionManager:a,variables:o}){const l=yt(e,t.calendar.data_key),c=He(a.triggerManager,Lo.id),u=y.useCallback(h=>{const[g,m]=h.value,C=x.get(l,g,{error:"rowData is not found"});c.forEach(w=>{a.runInteraction(w.id,{...h,rowData:C})})},[l,c,a]),d=y.useMemo(()=>({click:u,legendselectchanged:ix}),[u]),f=y.useMemo(()=>tx(t,e),[t,e]);return!n||!r?null:i(Ne,{echarts:ce,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,opts:{locale:t.calendar.locale},theme:"merico-light"})}function sx({context:t,instance:e}){const n=et({vizManager:t.vizManager,instance:e}),{value:r}=R(t.instanceData,"config"),{variables:a}=t,o=y.useMemo(()=>x.defaults({},r,ui),[r]),l=t.data,{width:c,height:u}=t.viewport;return!o.calendar.data_key||!o.heat_block.data_key?null:i(s.Box,{children:i(ax,{variables:a,width:c,height:u,data:l,conf:o,interactionManager:n})})}function ox({control:t,watch:e}){return e(["heat_block"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.data_key",control:t,render:({field:n})=>i(j,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"heat_block.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.min",control:t,render:({field:n})=>i(s.NumberInput,{label:"Min Value",...n})}),i(v.Controller,{name:"heat_block.max",control:t,render:({field:n})=>i(s.NumberInput,{label:"Max Value",...n})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Value Format",labelPosition:"center"}),i(v.Controller,{name:"heat_block.value_formatter",control:t,render:({field:n})=>i(Je,{...n})})]})}const lx=({control:t,index:e,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${e}.data_key`,control:t,render:({field:r})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),cx=({control:t,watch:e})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"tooltip.metrics"}),o=e("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),c=()=>r({id:Date.now().toString(),data_key:"",name:""}),u=e("tooltip.metrics.0.id"),[d,f]=y.useState(()=>u??null);return y.useEffect(()=>{u&&f(h=>h!==null?h:u)},[u]),p(N,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(I.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),i(s.Divider,{variant:"dashed",my:10}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(lx,{control:t,index:g,remove:a},h.id)},h.id))]})]})};function ux({control:t,watch:e}){return i(cx,{control:t,watch:e})}const dx=[{label:"Chinese",value:"ZH"},{label:"English",value:"EN"}];function px({control:t,watch:e}){return e(["calendar"]),p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"calendar.data_key",control:t,render:({field:n})=>i(j,{label:"Data Field",required:!0,sx:{flex:1},...n})})}),i(v.Controller,{name:"calendar.locale",control:t,render:({field:n})=>i(s.Select,{label:"Language",required:!0,data:dx,sx:{flex:1},...n})})]})}function hx({context:t}){const{value:e,set:n}=R(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,ui),[e]),a=y.useMemo(()=>x.cloneDeep(r),[r]);y.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=u(),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(I.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"Calendar",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Calendar",children:"Calendar"}),i(s.Tabs.Tab,{value:"Heat Block",children:"Heat Block"}),i(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"})]}),i(s.Tabs.Panel,{value:"Calendar",children:i(px,{control:o,watch:c})}),i(s.Tabs.Panel,{value:"Heat Block",children:i(ox,{control:o,watch:c})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(ux,{control:o,watch:c})})]})]})})}function fx(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{calendar:a,heat_block:o,tooltip:l,...c}=t;return{...c,calendar:{...a,data_key:r(a.data_key)},heat_block:{...o,data_key:r(o.data_key)},tooltip:{...l,metrics:l.metrics.map(u=>({...u,data_key:r(u.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}class gx extends ve{constructor(){super(...arguments);V(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>({...n,version:2,config:fx(n.config,r)}))}}const mx={displayName:"Heatmap(Calendar)",displayGroup:"ECharts-based charts",migrator:new gx,name:"calendarHeatmap",viewRender:sx,configRender:hx,createConfig:()=>({version:1,config:ui}),triggers:[Lo]},di={x_axes:[{id:"initial-x",min:"",max:"",name:"X Axis",data_key:"",position:"bottom",label_formatter:$e,show:!0}],y_axis:{name:"Y Axis",data_key:"",axisLabel:{formatter:{...tt},overflow:Ze},nameAlignment:"center"},series:[],tooltip:{metrics:[]},reference_lines:[]};function yx(){const t=new Date().getTime().toString();return{id:t,min:"",max:"",name:t,data_key:"",position:"bottom",label_formatter:$e,show:!0}}function bx(){const t=new Date().getTime().toString();return{id:t,type:"bar",name:t,stack:"",color:"",barGap:"0%",data_key:"",barWidth:"",barMinWidth:"1",barMaxWidth:"10",group_by_key:"",hide_in_legend:!1,invisible:!1,label_position:"right",aggregation_on_value:Ot,xAxisIndex:"0"}}function vx(){const t=new Date().getTime().toString();return{id:t,name:t,template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,xAxisIndex:"0"}}function xx(t){const e=t.x_axes.some(o=>o.position==="top"&&!!o.name&&o.show);let n=0;e&&(n+=15);const r=t.x_axes.some(o=>o.position==="bottom"&&!!o.name&&o.show);let a=0;return r&&(a+=15),t.series.some(o=>!o.hide_in_legend)&&(a+=20),{top:n,right:5,bottom:a,left:5,containLabel:!0}}function wx(t){switch(t){case"bar":return"roundRect";case"scatter":return"circle"}}function Cx(t){const e={show:!0,bottom:0,left:"center",type:"scroll"};return e.data=t.filter(n=>!n.hide_in_legend).map(({name:n,type:r})=>({name:n,icon:wx(r)})),e}function Sx(t,e,n,r){return t.map(a=>{const o=a.orientation==="horizontal",l=o?"yAxis":"xAxis",c=o?"insideEndTop":"end";return{name:a.name,type:"line",hide_in_legend:!a.show_in_legend,xAxisIndex:a.xAxisIndex,data:[],lineStyle:a.lineStyle,markLine:{data:[{name:a.name,[l]:Number(n[a.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:a.lineStyle,label:{formatter:function(){return a.template?Tn(a.template,e,r):""},position:c}}}})}function Kn(t,e,n){const r=ot(t,e),a=ot(t,n);return x.zip(a,r)}function _x(t,e,n,r){const a=Kn(e,n,r);return x.unionBy(a,t,0)}function kx({dataTemplate:t,data:e,name_data_key:n,value_data_key:r,valueTypedXAxis:a}){return a?_x(t,e,n,r):Kn(e,n,r)}function Tx({dataTemplate:t,data:e,aggregation_on_value:n,name_data_key:r,value_data_key:a,valueTypedXAxis:o}){if(!n||n.type==="none")return kx({dataTemplate:t,data:e,name_data_key:r,value_data_key:a,valueTypedXAxis:o});const l=Kn(e,r,a),c=x.groupBy(l,"0");return t.map(([d])=>{const h=c[d].map(m=>m[1]),g=kr(h,n);return[d,g]})}function Dx({group_by_key:t,data:e,value_data_key:n,name_data_key:r}){const{queryID:a,columnKey:o}=q(t),l=x.groupBy(e[a],o);return Object.entries(l).forEach(([c,u])=>{l[c]=Kn({[a]:u},r,n)}),l}function Ix({y_axis:t},{data_key:e,xAxisIndex:n,label_position:r,name:a,group_by_key:o,aggregation_on_value:l,stack:c,color:u,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:c,color:f?"transparent":u,hide_in_legend:d,labelLayout:{hideOverlap:!0},emphasis:{disabled:!0},...g};if(!o||o===t.data_key)return M.data=Tx({dataTemplate:m,data:w,aggregation_on_value:l,name_data_key:t.data_key,value_data_key:e,valueTypedXAxis:C}),M;const O=Dx({group_by_key:o,data:w,name_data_key:t.data_key,value_data_key:e});return Object.entries(O).map(([B,F])=>{const $=x.cloneDeep(M);return $.name=B,$.color=void 0,$.data=F,$})}function Mx(t,e,n,r,a,o,l){const c=e.map(d=>[d,0]);return t.series.map(d=>Ix(t,d,c,n,r,l,a)).flat().concat(Sx(t.reference_lines,o,l,r))}function Ex(t,e){const n=t.find(c=>c.axisDim==="y"&&c.axisId==="main-y-axis");if(!n)return"";const{name:r,axisType:a,axisValue:o,axisIndex:l}=n;return a==="yAxis.category"?r:Lt(e.y_axis.axisLabel.formatter)(o,l)}function Ax(t,e,n){const r=e.reduce((a,{xAxisIndex:o,name:l})=>(a[l]=o,a),{});return{trigger:"axis",axisPointer:{type:"shadow"},formatter:function(a){const o=Array.isArray(a)?a:[a];if(o.length===0)return"";const l=o.map(({seriesName:d,marker:f,value:h})=>{if(Array.isArray(h)&&h.length===2&&(h=h[0]),!d)return h;const g=r[d],m=n[g]??n.default;return`
|
|
385
|
+
`}}}function Zv(t,e){return{min:t.heat_block.min??0,max:t.heat_block.max??100,calculable:!0,orient:"horizontal",left:e?"center":5,top:0,itemWidth:15}}const Hv={tooltip:{confine:!0},grid:{containLabel:!0}},ex=t=>Y(t).get("year");function tx(t,e){const n=q(t.calendar.data_key),r=e[n.queryID],a=x.groupBy(r,d=>ex(d[n.columnKey])),o=Object.keys(a),l=r.map(d=>Y(d[n.columnKey]).valueOf()),u=x.min(l),c=x.max(l);return{minDate:u??0,maxDate:c??0,dateSpan:Y(c).diff(u,"day"),dataByYear:a,years:o}}function nx(t,e,n){const r=Yv(t),{dateSpan:a,minDate:o,dataByYear:l,years:u}=tx(t,e),c=a<=366,d={calendar:jv(c,o,u),series:Kv(t,c,l,e),tooltip:Jv(t,e,r),visualMap:Zv(t,c),legend:Qv(c,u)};return x.defaultsDeep({},d,Hv)}function rx(t){return i(N,{})}function ix(t){return i(s.Text,{children:"Click heat block"})}const Lo={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:ix,configRender:rx,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:0,max:1e3,name:"Value",data_key:"",value_formatter:$e},tooltip:{metrics:[]}};ue.use([G.DataZoomComponent,he.BarChart,he.LineChart,he.HeatmapChart,G.CalendarComponent,G.GridComponent,G.LegendComponent,G.TooltipComponent,G.VisualMapComponent,Ve.CanvasRenderer]);function ax({name:t},e){const n=e.getOption();n.calendar.forEach(r=>{r.range=t}),e.setOption(n)}function sx({conf:t,data:e,width:n,height:r,interactionManager:a,variables:o}){const l=yt(e,t.calendar.data_key),u=He(a.triggerManager,Lo.id),c=y.useCallback(p=>{const[g,m]=p.value,C=x.get(l,g,{error:"rowData is not found"});u.forEach(w=>{a.runInteraction(w.id,{...p,rowData:C})})},[l,u,a]),d=y.useMemo(()=>({click:c,legendselectchanged:ax}),[c]),f=y.useMemo(()=>nx(t,e),[t,e]);return!n||!r?null:i(Ne,{echarts:ue,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,opts:{locale:t.calendar.locale},theme:"merico-light"})}function ox({context:t,instance:e}){const n=et({vizManager:t.vizManager,instance:e}),{value:r}=R(t.instanceData,"config"),{variables:a}=t,o=y.useMemo(()=>x.defaults({},r,ci),[r]),l=t.data,{width:u,height:c}=t.viewport;return!o.calendar.data_key||!o.heat_block.data_key?null:i(s.Box,{children:i(sx,{variables:a,width:u,height:c,data:l,conf:o,interactionManager:n})})}function lx({control:t,watch:e}){return e(["heat_block"]),h(s.Stack,{children:[h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.data_key",control:t,render:({field:n})=>i(j,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"heat_block.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.min",control:t,render:({field:n})=>i(s.NumberInput,{label:"Min Value",...n})}),i(v.Controller,{name:"heat_block.max",control:t,render:({field:n})=>i(s.NumberInput,{label:"Max Value",...n})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Value Format",labelPosition:"center"}),i(v.Controller,{name:"heat_block.value_formatter",control:t,render:({field:n})=>i(Je,{...n})})]})}const ux=({control:t,index:e,remove:n})=>h(s.Stack,{children:[h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${e}.data_key`,control:t,render:({field:r})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),cx=({control:t,watch:e})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"tooltip.metrics"}),o=e("tooltip.metrics"),l=n.map((p,g)=>({...p,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=e("tooltip.metrics.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(p=>p!==null?p:c)},[c]),h(N,{children:[h(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(I.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),i(s.Divider,{variant:"dashed",my:10}),h(s.Tabs,{value:d,onTabChange:p=>f(p),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[h(s.Tabs.List,{children:[l.map((p,g)=>i(s.Tabs.Tab,{value:p.id,children:p.name?p.name:g},p.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((p,g)=>i(s.Tabs.Panel,{value:p.id,children:i(ux,{control:t,index:g,remove:a},p.id)},p.id))]})]})};function dx({control:t,watch:e}){return i(cx,{control:t,watch:e})}const px=[{label:"Chinese",value:"ZH"},{label:"English",value:"EN"}];function hx({control:t,watch:e}){return e(["calendar"]),h(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"calendar.data_key",control:t,render:({field:n})=>i(j,{label:"Data Field",required:!0,sx:{flex:1},...n})})}),i(v.Controller,{name:"calendar.locale",control:t,render:({field:n})=>i(s.Select,{label:"Language",required:!0,data:px,sx:{flex:1},...n})})]})}function fx({context:t}){const{value:e,set:n}=R(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,ci),[e]),a=y.useMemo(()=>x.cloneDeep(r),[r]);y.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),p=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return i(s.Stack,{spacing:"xs",children:h("form",{onSubmit:l(n),children:[h(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:!p,children:i(I.DeviceFloppy,{size:20})})]}),h(s.Tabs,{defaultValue:"Calendar",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[h(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(hx,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Heat Block",children:i(lx,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(dx,{control:o,watch:u})})]})]})})}function gx(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{calendar:a,heat_block:o,tooltip:l,...u}=t;return{...u,calendar:{...a,data_key:r(a.data_key)},heat_block:{...o,data_key:r(o.data_key)},tooltip:{...l,metrics:l.metrics.map(c=>({...c,data_key:r(c.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}class mx extends ve{constructor(){super(...arguments);V(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>({...n,version:2,config:gx(n.config,r)}))}}const yx={displayName:"Heatmap(Calendar)",displayGroup:"ECharts-based charts",migrator:new mx,name:"calendarHeatmap",viewRender:ox,configRender:fx,createConfig:()=>({version:1,config:ci}),triggers:[Lo]},di={x_axes:[{id:"initial-x",min:"",max:"",name:"X Axis",data_key:"",position:"bottom",label_formatter:$e,show:!0}],y_axis:{name:"Y Axis",data_key:"",axisLabel:{formatter:{...tt},overflow:Ze},nameAlignment:"center"},series:[],tooltip:{metrics:[]},reference_lines:[]};function bx(){const t=new Date().getTime().toString();return{id:t,min:"",max:"",name:t,data_key:"",position:"bottom",label_formatter:$e,show:!0}}function vx(){const t=new Date().getTime().toString();return{id:t,type:"bar",name:t,stack:"",color:"",barGap:"0%",data_key:"",barWidth:"",barMinWidth:"1",barMaxWidth:"10",group_by_key:"",hide_in_legend:!1,invisible:!1,label_position:"right",aggregation_on_value:Ot,xAxisIndex:"0"}}function xx(){const t=new Date().getTime().toString();return{id:t,name:t,template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,xAxisIndex:"0"}}function wx(t){const e=t.x_axes.some(o=>o.position==="top"&&!!o.name&&o.show);let n=0;e&&(n+=15);const r=t.x_axes.some(o=>o.position==="bottom"&&!!o.name&&o.show);let a=0;return r&&(a+=15),t.series.some(o=>!o.hide_in_legend)&&(a+=20),{top:n,right:5,bottom:a,left:5,containLabel:!0}}function Cx(t){switch(t){case"bar":return"roundRect";case"scatter":return"circle"}}function Sx(t){const e={show:!0,bottom:0,left:"center",type:"scroll"};return e.data=t.filter(n=>!n.hide_in_legend).map(({name:n,type:r})=>({name:n,icon:Cx(r)})),e}function _x(t,e,n,r){return t.map(a=>{const o=a.orientation==="horizontal",l=o?"yAxis":"xAxis",u=o?"insideEndTop":"end";return{name:a.name,type:"line",hide_in_legend:!a.show_in_legend,xAxisIndex:a.xAxisIndex,data:[],lineStyle:a.lineStyle,markLine:{data:[{name:a.name,[l]:Number(n[a.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:a.lineStyle,label:{formatter:function(){return a.template?Tn(a.template,e,r):""},position:u}}}})}function Kn(t,e,n){const r=ot(t,e),a=ot(t,n);return x.zip(a,r)}function kx(t,e,n,r){const a=Kn(e,n,r);return x.unionBy(a,t,0)}function Tx({dataTemplate:t,data:e,name_data_key:n,value_data_key:r,valueTypedXAxis:a}){return a?kx(t,e,n,r):Kn(e,n,r)}function Dx({dataTemplate:t,data:e,aggregation_on_value:n,name_data_key:r,value_data_key:a,valueTypedXAxis:o}){if(!n||n.type==="none")return Tx({dataTemplate:t,data:e,name_data_key:r,value_data_key:a,valueTypedXAxis:o});const l=Kn(e,r,a),u=x.groupBy(l,"0");return t.map(([d])=>{const p=u[d].map(m=>m[1]),g=kr(p,n);return[d,g]})}function Ix({group_by_key:t,data:e,value_data_key:n,name_data_key:r}){const{queryID:a,columnKey:o}=q(t),l=x.groupBy(e[a],o);return Object.entries(l).forEach(([u,c])=>{l[u]=Kn({[a]:c},r,n)}),l}function Mx({y_axis:t},{data_key:e,xAxisIndex:n,label_position:r,name:a,group_by_key:o,aggregation_on_value:l,stack:u,color:c,hide_in_legend:d,invisible:f,id:p,...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===t.data_key)return M.data=Dx({dataTemplate:m,data:w,aggregation_on_value:l,name_data_key:t.data_key,value_data_key:e,valueTypedXAxis:C}),M;const O=Ix({group_by_key:o,data:w,name_data_key:t.data_key,value_data_key:e});return Object.entries(O).map(([B,F])=>{const $=x.cloneDeep(M);return $.name=B,$.color=void 0,$.data=F,$})}function Ex(t,e,n,r,a,o,l){const u=e.map(d=>[d,0]);return t.series.map(d=>Mx(t,d,u,n,r,l,a)).flat().concat(_x(t.reference_lines,o,l,r))}function Ax(t,e){const n=t.find(u=>u.axisDim==="y"&&u.axisId==="main-y-axis");if(!n)return"";const{name:r,axisType:a,axisValue:o,axisIndex:l}=n;return a==="yAxis.category"?r:Lt(e.y_axis.axisLabel.formatter)(o,l)}function zx(t,e,n){const r=e.reduce((a,{xAxisIndex:o,name:l})=>(a[l]=o,a),{});return{trigger:"axis",axisPointer:{type:"shadow"},formatter:function(a){const o=Array.isArray(a)?a:[a];if(o.length===0)return"";const l=o.map(({seriesName:d,marker:f,value:p})=>{if(Array.isArray(p)&&p.length===2&&(p=p[0]),!d)return p;const g=r[d],m=n[g]??n.default;return`
|
|
386
386
|
<tr>
|
|
387
387
|
<td>${f}</td>
|
|
388
388
|
<th style="text-align: right; padding: 0 1em;">${d}</th>
|
|
389
|
-
<td style="text-align: left; padding: 0 1em;">${m({value:
|
|
389
|
+
<td style="text-align: left; padding: 0 1em;">${m({value:p})}</td>
|
|
390
390
|
</tr>
|
|
391
|
-
`}),
|
|
391
|
+
`}),u=mt(t.y_axis.axisLabel.overflow.in_tooltip),c=Ax(o,t);return`
|
|
392
392
|
<div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
|
|
393
|
-
<div style="${
|
|
393
|
+
<div style="${u}">${c}</div>
|
|
394
394
|
</div>
|
|
395
395
|
<table style="width: auto">
|
|
396
396
|
<tbody>
|
|
397
397
|
${l.join("")}
|
|
398
398
|
</tbody>
|
|
399
399
|
</table>
|
|
400
|
-
`}}}function zx(t){return t.x_axes.reduce((n,{label_formatter:r},a)=>(n[a]=function(l){let c=l;if(typeof l=="object"&&(Array.isArray(l.value)&&l.value.length===2?c=l.value[0]:c=l.value),!r)return c;try{return te(c).format(r)}catch(u){return console.error(u),c}},n),{default:({value:n})=>n})}function $x(t,e){const n={};return e.map(r=>{const a=Pt(r,t);n[r.name]=ct(r,a)}),n}function Lx(t,e){return t.x_axes.map(({min:n,max:r,...a},o)=>{let l=a.position;return l||(l=o>0?"bottom":"top"),{...a,type:"value",min:n||void 0,max:r||void 0,position:l,axisLabel:{show:!0,margin:2,formatter:e[o]??e.default},axisLine:{show:!0},axisTick:{show:!1},splitLine:{show:!0},nameTextStyle:{fontWeight:"bold"},nameLocation:"center",nameGap:15}})}function Ox(t,e){const n=e.every(l=>!Number.isNaN(Number(l))),{overflow:r,...a}=t.y_axis.axisLabel,o=lt(r.on_axis);return[{data:e,name:t.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"center",fontWeight:"bold"},id:"main-y-axis",axisTick:{show:!0,alignWithLabel:!0},type:n?"value":"category",axisLabel:{...a,...o,formatter:Lt(a.formatter)},z:5}]}function Px(t,e,n){if(!t.y_axis.data_key)return{};const r=$x(e,n),a=zx(t),o=q(t.y_axis.data_key),l=x.uniq(e[o.queryID].map(f=>f[o.columnKey])),c=l.every(f=>!Number.isNaN(Number(f))),u=Mx(t,l,c,e,a,n,r);return{xAxis:Lx(t,a),yAxis:Ox(t,l),series:u,tooltip:Ax(t,u,a),grid:xx(t),legend:Cx(u)}}ce.use([G.DataZoomComponent,he.BarChart,he.LineChart,he.ScatterChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer,G.MarkLineComponent,G.MarkAreaComponent]);function Bx({conf:t,data:e,width:n,height:r,interactionManager:a,variables:o}){const l=yt(e,t.y_axis.data_key),c=He(a.triggerManager,Ir.id),u=y.useCallback(h=>{const g=x.get(l,h.name,{error:"rowData is not found"});c.forEach(m=>{a.runInteraction(m.id,{...h,rowData:g})})},[l,c,a]),d=y.useMemo(()=>({click:u}),[u]),f=y.useMemo(()=>Px(t,e,o),[t,e]);return!n||!r?null:i(Ne,{echarts:ce,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function Vx({context:t,instance:e}){const n=et({vizManager:t.vizManager,instance:e}),{value:r}=R(t.instanceData,"config"),{variables:a}=t,o=y.useMemo(()=>x.defaults({},r,di),[r]),l=t.data,{width:c,height:u}=t.viewport;return i(s.Box,{children:i(Bx,{variables:a,width:c,height:u,data:l,conf:o,interactionManager:n})})}const Nx=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],qx=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Fx({control:t,index:e,remove:n,watch:r,variableOptions:a,xAxisOptions:o}){const l=r(`reference_lines.${e}.orientation`);return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${e}.name`,control:t,render:({field:c})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...c})}),i(v.Controller,{name:`reference_lines.${e}.variable_key`,control:t,render:({field:c})=>i(s.Select,{label:"Value",required:!0,data:a,sx:{flex:1},...c})})]}),i(v.Controller,{name:`reference_lines.${e}.template`,control:t,render:({field:c})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...c})}),p(s.Group,{grow:!0,children:[p(s.Stack,{children:[i(v.Controller,{name:`reference_lines.${e}.orientation`,control:t,render:({field:c})=>i(s.Select,{label:"Orientation",data:qx,required:!0,sx:{flex:1},...c})}),l==="vertical"&&i(s.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&i(v.Controller,{name:`reference_lines.${e}.xAxisIndex`,control:t,render:({field:c})=>i(s.Select,{label:"X Axis",data:o,disabled:o.length===0,sx:{flex:1},...c})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`reference_lines.${e}.lineStyle.type`,control:t,render:({field:c})=>i(s.Select,{label:"Line Type",data:Nx,sx:{flexGrow:1},...c})}),i(v.Controller,{name:`reference_lines.${e}.lineStyle.width`,control:t,render:({field:c})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...c})})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`reference_lines.${e}.lineStyle.color`,control:t,render:({field:c})=>i(Pe,{...c})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`reference_lines.${e}.show_in_legend`,control:t,render:({field:c})=>i(s.Checkbox,{label:"Show in legend",checked:c.value,onChange:u=>c.onChange(u.currentTarget.checked)})}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Reference Line"})]},e)}function Gx({control:t,watch:e,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:t,name:"reference_lines"}),l=e("reference_lines"),c=r.map((m,C)=>({...m,...l[C]})),u=()=>{const m=vx();a(m)},d=y.useMemo(()=>n.map(m=>({label:m.name,value:m.name})),[n]),f=e("x_axes"),h=y.useMemo(()=>f.map(({name:m},C)=>({label:m,value:C.toString()})),[f]),g=c.length>0?c[0].id:"0";return p(s.Tabs,{defaultValue:g,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[c.map((m,C)=>i(s.Tabs.Tab,{value:m.id,children:m.name},C)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),c.map((m,C)=>i(s.Tabs.Panel,{value:m.id,children:i(Fx,{control:t,index:C,remove:o,watch:e,variableOptions:d,xAxisOptions:h})},C))]})}function Wx(t){const[e,n]=y.useState(t);return y.useEffect(()=>{n(t)},[t]),{tab:e,setTab:n}}const Rx=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function jx({control:t,index:e,seriesItem:n}){const r=!!n.barWidth.trim();return p(N,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.stack`,control:t,render:({field:a})=>i(s.TextInput,{label:"Stack",placeholder:"Stack bars by this ID",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.barGap`,control:t,render:({field:a})=>i(s.Select,{label:"Bar Gap",data:Rx,sx:{flexGrow:1},...a})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.barMinWidth`,control:t,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Min)",disabled:r,sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.barWidth`,control:t,render:({field:a})=>i(s.TextInput,{label:"Bar Width",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.barMaxWidth`,control:t,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Max)",disabled:r,sx:{flexGrow:1},...a})})]})]})}const Yx=[{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 Qx({control:t,index:e,remove:n,seriesItem:r,xAxisOptions:a}){return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.name`,control:t,render:({field:o})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...o})}),i(v.Controller,{name:`series.${e}.xAxisIndex`,control:t,render:({field:o})=>i(s.Select,{label:"X Axis",data:a,disabled:a.length===0,sx:{flex:1},...o})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.data_key`,control:t,render:({field:o})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...o})}),i(v.Controller,{name:`series.${e}.aggregation_on_value`,control:t,render:({field:o})=>i(Sn,{label:"Aggregation on Value",value:o.value??Ot,onChange:o.onChange,pt:0})})]}),i(s.Group,{grow:!0,children:i(v.Controller,{name:`series.${e}.group_by_key`,control:t,render:({field:o})=>i(j,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...o})})}),i(jx,{index:e,control:t,seriesItem:r}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),i(v.Controller,{name:`series.${e}.label_position`,control:t,render:({field:o})=>i(s.Select,{label:"Label Position",data:Yx,...o})}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`series.${e}.color`,control:t,render:({field:o})=>i(Pe,{...o})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`series.${e}.hide_in_legend`,control:t,render:({field:o})=>i(s.Checkbox,{label:"Hide in legend",checked:o.value,onChange:l=>o.onChange(l.currentTarget.checked)})}),i(v.Controller,{name:`series.${e}.invisible`,control:t,render:({field:o})=>i(s.Checkbox,{label:"Invisible",checked:o.value,onChange:l=>o.onChange(l.currentTarget.checked)})}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Series"})]},e)}function Kx({control:t,watch:e}){var g;const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"series"}),o=e("series"),l=n.map((m,C)=>({...m,...o[C]})),c=()=>{const m=bx();r(m)},u=e("x_axes"),d=y.useMemo(()=>u.map(({name:m},C)=>({label:m,value:C.toString()})),[u]),{tab:f,setTab:h}=Wx((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:c,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((m,C)=>i(s.Tabs.Panel,{value:m.id,children:i(Qx,{control:t,index:C,remove:a,seriesItem:m,xAxisOptions:d},m.id)},m.id))]})}const Ux=[{label:"Top",value:"top"},{label:"Bottom",value:"bottom"}];function Xx({control:t,index:e,remove:n}){return p(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[i(s.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`x_axes.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})})}),i(s.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`x_axes.${e}.position`,control:t,render:({field:r})=>i(s.Select,{label:"Position",required:!0,data:Ux,sx:{flex:1},...r})})}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:`x_axes.${e}.label_formatter`,control:t,render:({field:r})=>i(Je,{...r})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`x_axes.${e}.min`,control:t,render:({field:r})=>i(s.TextInput,{label:"Min",...r})}),i(v.Controller,{name:`x_axes.${e}.max`,control:t,render:({field:r})=>i(s.TextInput,{label:"Max",...r})})]})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`x_axes.${e}.show`,control:t,render:({field:r})=>i(s.Checkbox,{label:"Visible",checked:r.value,onChange:a=>r.onChange(a.currentTarget.checked)})}),i(s.Button,{mt:20,leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),disabled:e===0,children:"Delete this X Axis"})]})}function Jx({control:t,watch:e}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"x_axes"}),o=e("x_axes"),l=n.map((d,f)=>({...d,...o[f]})),c=()=>{const d=yx();r(d)},u=l.length>0?l[0].id:"0";return p(s.Tabs,{defaultValue:u,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:c,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((d,f)=>i(s.Tabs.Panel,{value:d.id,children:i(Xx,{control:t,index:f,remove:a})},d.id))]})}function Zx({control:t,watch:e}){return e(["y_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.data_key",control:t,render:({field:n})=>i(j,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"y_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"X Axis Name",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"y_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Dn,{...n})})}),i(v.Controller,{name:"y_axis.axisLabel.overflow",control:t,render:({field:n})=>i(gt,{...n})})]})}function Hx({context:t}){const{value:e,set:n}=R(t.instanceData,"config"),{variables:r}=t,a=y.useMemo(()=>x.defaultsDeep({},e,di),[e]),{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]),c([]);const f=u(),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(I.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"Series",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axes",children:"X Axes"}),i(s.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),i(s.Tabs.Tab,{value:"Series",children:"Series"}),i(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"})]}),i(s.Tabs.Panel,{value:"X Axes",children:i(Jx,{control:o,watch:c})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(Zx,{control:o,watch:c})}),i(s.Tabs.Panel,{value:"Series",children:i(Kx,{control:o,watch:c})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(Gx,{variables:r,control:o,watch:c})})]})]})})}function e0(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis:a,y_axis:o,series:l,...c}=t;return{...c,x_axis:{...a,data_key:r(a.data_key)},y_axis:{...o,data_key:r(o.data_key)},series:l.map(u=>({...u,data_key:r(u.data_key),group_by_key:r(u.group_by_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class t0 extends ve{constructor(){super(...arguments);V(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:e0(a,r)}})}}const n0={displayName:"Horizontal Bar Chart",displayGroup:"ECharts-based charts",migrator:new t0,name:"horizontalBarChart",viewRender:Vx,configRender:Hx,createConfig:()=>({version:2,config:di})},pi={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...zn}}},deviation:{name:"",data_keys:{estimated_value:"",actual_value:""}},metrics:[]};function r0(){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 Oo=({value:t})=>{try{return te(t[2]).format({output:"percent",mantissa:0})}catch(e){return console.error(e),t}};function i0(t,e,n){return{type:"heatmap",name:"准确估算比例",xAxisIndex:0,yAxisIndex:0,data:e.map(a=>{const o=n[a].length,u=(x.countBy(n[a],d=>d.level.diff===0).true??0)/o;return[a,"_y",u]}),label:{show:!0,formatter:Oo},labelLayout:{hideOverlap:!0},visualMapIndex:0,tooltip:{trigger:"item",formatter:({color:a,value:o})=>`
|
|
400
|
+
`}}}function $x(t){return t.x_axes.reduce((n,{label_formatter:r},a)=>(n[a]=function(l){let u=l;if(typeof l=="object"&&(Array.isArray(l.value)&&l.value.length===2?u=l.value[0]:u=l.value),!r)return u;try{return te(u).format(r)}catch(c){return console.error(c),u}},n),{default:({value:n})=>n})}function Lx(t,e){const n={};return e.map(r=>{const a=Pt(r,t);n[r.name]=ut(r,a)}),n}function Ox(t,e){return t.x_axes.map(({min:n,max:r,...a},o)=>{let l=a.position;return l||(l=o>0?"bottom":"top"),{...a,type:"value",min:n||void 0,max:r||void 0,position:l,axisLabel:{show:!0,margin:2,formatter:e[o]??e.default},axisLine:{show:!0},axisTick:{show:!1},splitLine:{show:!0},nameTextStyle:{fontWeight:"bold"},nameLocation:"center",nameGap:15}})}function Px(t,e){const n=e.every(l=>!Number.isNaN(Number(l))),{overflow:r,...a}=t.y_axis.axisLabel,o=lt(r.on_axis);return[{data:e,name:t.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"center",fontWeight:"bold"},id:"main-y-axis",axisTick:{show:!0,alignWithLabel:!0},type:n?"value":"category",axisLabel:{...a,...o,formatter:Lt(a.formatter)},z:5}]}function Bx(t,e,n){if(!t.y_axis.data_key)return{};const r=Lx(e,n),a=$x(t),o=q(t.y_axis.data_key),l=x.uniq(e[o.queryID].map(f=>f[o.columnKey])),u=l.every(f=>!Number.isNaN(Number(f))),c=Ex(t,l,u,e,a,n,r);return{xAxis:Ox(t,a),yAxis:Px(t,l),series:c,tooltip:zx(t,c,a),grid:wx(t),legend:Sx(c)}}ue.use([G.DataZoomComponent,he.BarChart,he.LineChart,he.ScatterChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer,G.MarkLineComponent,G.MarkAreaComponent]);function Vx({conf:t,data:e,width:n,height:r,interactionManager:a,variables:o}){const l=yt(e,t.y_axis.data_key),u=He(a.triggerManager,Ir.id),c=y.useCallback(p=>{const g=x.get(l,p.name,{error:"rowData is not found"});u.forEach(m=>{a.runInteraction(m.id,{...p,rowData:g})})},[l,u,a]),d=y.useMemo(()=>({click:c}),[c]),f=y.useMemo(()=>Bx(t,e,o),[t,e]);return!n||!r?null:i(Ne,{echarts:ue,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function Nx({context:t,instance:e}){const n=et({vizManager:t.vizManager,instance:e}),{value:r}=R(t.instanceData,"config"),{variables:a}=t,o=y.useMemo(()=>x.defaults({},r,di),[r]),l=t.data,{width:u,height:c}=t.viewport;return i(s.Box,{children:i(Vx,{variables:a,width:u,height:c,data:l,conf:o,interactionManager:n})})}const qx=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Fx=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Gx({control:t,index:e,remove:n,watch:r,variableOptions:a,xAxisOptions:o}){const l=r(`reference_lines.${e}.orientation`);return h(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${e}.name`,control:t,render:({field:u})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),i(v.Controller,{name:`reference_lines.${e}.variable_key`,control:t,render:({field:u})=>i(s.Select,{label:"Value",required:!0,data:a,sx:{flex:1},...u})})]}),i(v.Controller,{name:`reference_lines.${e}.template`,control:t,render:({field:u})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...u})}),h(s.Group,{grow:!0,children:[h(s.Stack,{children:[i(v.Controller,{name:`reference_lines.${e}.orientation`,control:t,render:({field:u})=>i(s.Select,{label:"Orientation",data:Fx,required:!0,sx:{flex:1},...u})}),l==="vertical"&&i(s.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&i(v.Controller,{name:`reference_lines.${e}.xAxisIndex`,control:t,render:({field:u})=>i(s.Select,{label:"X Axis",data:o,disabled:o.length===0,sx:{flex:1},...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),h(s.Group,{grow:!0,children:[i(v.Controller,{name:`reference_lines.${e}.lineStyle.type`,control:t,render:({field:u})=>i(s.Select,{label:"Line Type",data:qx,sx:{flexGrow:1},...u})}),i(v.Controller,{name:`reference_lines.${e}.lineStyle.width`,control:t,render:({field:u})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...u})})]}),h(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`reference_lines.${e}.lineStyle.color`,control:t,render:({field:u})=>i(Pe,{...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`reference_lines.${e}.show_in_legend`,control:t,render:({field:u})=>i(s.Checkbox,{label:"Show in legend",checked:u.value,onChange:c=>u.onChange(c.currentTarget.checked)})}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Reference Line"})]},e)}function Wx({control:t,watch:e,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:t,name:"reference_lines"}),l=e("reference_lines"),u=r.map((m,C)=>({...m,...l[C]})),c=()=>{const m=xx();a(m)},d=y.useMemo(()=>n.map(m=>({label:m.name,value:m.name})),[n]),f=e("x_axes"),p=y.useMemo(()=>f.map(({name:m},C)=>({label:m,value:C.toString()})),[f]),g=u.length>0?u[0].id:"0";return h(s.Tabs,{defaultValue:g,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},children:[h(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(I.Plus,{size:18,color:"#228be6"})})]}),u.map((m,C)=>i(s.Tabs.Panel,{value:m.id,children:i(Gx,{control:t,index:C,remove:o,watch:e,variableOptions:d,xAxisOptions:p})},C))]})}function Rx(t){const[e,n]=y.useState(t);return y.useEffect(()=>{n(t)},[t]),{tab:e,setTab:n}}const jx=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function Yx({control:t,index:e,seriesItem:n}){const r=!!n.barWidth.trim();return h(N,{children:[h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.stack`,control:t,render:({field:a})=>i(s.TextInput,{label:"Stack",placeholder:"Stack bars by this ID",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.barGap`,control:t,render:({field:a})=>i(s.Select,{label:"Bar Gap",data:jx,sx:{flexGrow:1},...a})})]}),h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.barMinWidth`,control:t,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Min)",disabled:r,sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.barWidth`,control:t,render:({field:a})=>i(s.TextInput,{label:"Bar Width",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.barMaxWidth`,control:t,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Max)",disabled:r,sx:{flexGrow:1},...a})})]})]})}const Qx=[{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 Kx({control:t,index:e,remove:n,seriesItem:r,xAxisOptions:a}){return h(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.name`,control:t,render:({field:o})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...o})}),i(v.Controller,{name:`series.${e}.xAxisIndex`,control:t,render:({field:o})=>i(s.Select,{label:"X Axis",data:a,disabled:a.length===0,sx:{flex:1},...o})})]}),h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.data_key`,control:t,render:({field:o})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...o})}),i(v.Controller,{name:`series.${e}.aggregation_on_value`,control:t,render:({field:o})=>i(Sn,{label:"Aggregation on Value",value:o.value??Ot,onChange:o.onChange,pt:0})})]}),i(s.Group,{grow:!0,children:i(v.Controller,{name:`series.${e}.group_by_key`,control:t,render:({field:o})=>i(j,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...o})})}),i(Yx,{index:e,control:t,seriesItem:r}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),i(v.Controller,{name:`series.${e}.label_position`,control:t,render:({field:o})=>i(s.Select,{label:"Label Position",data:Qx,...o})}),h(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`series.${e}.color`,control:t,render:({field:o})=>i(Pe,{...o})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`series.${e}.hide_in_legend`,control:t,render:({field:o})=>i(s.Checkbox,{label:"Hide in legend",checked:o.value,onChange:l=>o.onChange(l.currentTarget.checked)})}),i(v.Controller,{name:`series.${e}.invisible`,control:t,render:({field:o})=>i(s.Checkbox,{label:"Invisible",checked:o.value,onChange:l=>o.onChange(l.currentTarget.checked)})}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Series"})]},e)}function Ux({control:t,watch:e}){var g;const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"series"}),o=e("series"),l=n.map((m,C)=>({...m,...o[C]})),u=()=>{const m=vx();r(m)},c=e("x_axes"),d=y.useMemo(()=>c.map(({name:m},C)=>({label:m,value:C.toString()})),[c]),{tab:f,setTab:p}=Rx((g=l[0])==null?void 0:g.id);return h(s.Tabs,{value:f,onTabChange:p,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px",paddingTop:"6px"}},children:[h(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(I.Plus,{size:18,color:"#228be6"})})]}),l.map((m,C)=>i(s.Tabs.Panel,{value:m.id,children:i(Kx,{control:t,index:C,remove:a,seriesItem:m,xAxisOptions:d},m.id)},m.id))]})}const Xx=[{label:"Top",value:"top"},{label:"Bottom",value:"bottom"}];function Jx({control:t,index:e,remove:n}){return h(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[i(s.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`x_axes.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})})}),i(s.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`x_axes.${e}.position`,control:t,render:({field:r})=>i(s.Select,{label:"Position",required:!0,data:Xx,sx:{flex:1},...r})})}),h(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:`x_axes.${e}.label_formatter`,control:t,render:({field:r})=>i(Je,{...r})})]}),h(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),h(s.Group,{grow:!0,children:[i(v.Controller,{name:`x_axes.${e}.min`,control:t,render:({field:r})=>i(s.TextInput,{label:"Min",...r})}),i(v.Controller,{name:`x_axes.${e}.max`,control:t,render:({field:r})=>i(s.TextInput,{label:"Max",...r})})]})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`x_axes.${e}.show`,control:t,render:({field:r})=>i(s.Checkbox,{label:"Visible",checked:r.value,onChange:a=>r.onChange(a.currentTarget.checked)})}),i(s.Button,{mt:20,leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),disabled:e===0,children:"Delete this X Axis"})]})}function Zx({control:t,watch:e}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"x_axes"}),o=e("x_axes"),l=n.map((d,f)=>({...d,...o[f]})),u=()=>{const d=bx();r(d)},c=l.length>0?l[0].id:"0";return h(s.Tabs,{defaultValue:c,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},children:[h(s.Tabs.List,{children:[l.map(d=>i(s.Tabs.Tab,{value:d.id,children:d.name},d.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((d,f)=>i(s.Tabs.Panel,{value:d.id,children:i(Jx,{control:t,index:f,remove:a})},d.id))]})}function Hx({control:t,watch:e}){return e(["y_axis"]),h(s.Stack,{children:[h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.data_key",control:t,render:({field:n})=>i(j,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"y_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"X Axis Name",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"y_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Dn,{...n})})}),i(v.Controller,{name:"y_axis.axisLabel.overflow",control:t,render:({field:n})=>i(gt,{...n})})]})}function e0({context:t}){const{value:e,set:n}=R(t.instanceData,"config"),{variables:r}=t,a=y.useMemo(()=>x.defaultsDeep({},e,di),[e]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]),u([]);const f=c(),p=y.useMemo(()=>!x.isEqual(f,a),[f,a]);return i(s.Stack,{spacing:"xs",children:h("form",{onSubmit:l(n),children:[h(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:!p,children:i(I.DeviceFloppy,{size:20})})]}),h(s.Tabs,{defaultValue:"Series",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[h(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(Zx,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(Hx,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Series",children:i(Ux,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(Wx,{variables:r,control:o,watch:u})})]})]})})}function t0(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,y_axis:o,series:l,...u}=t;return{...u,x_axis:{...a,data_key:r(a.data_key)},y_axis:{...o,data_key:r(o.data_key)},series:l.map(c=>({...c,data_key:r(c.data_key),group_by_key:r(c.group_by_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class n0 extends ve{constructor(){super(...arguments);V(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:t0(a,r)}})}}const r0={displayName:"Horizontal Bar Chart",displayGroup:"ECharts-based charts",migrator:new n0,name:"horizontalBarChart",viewRender:Nx,configRender:e0,createConfig:()=>({version:2,config:di})},pi={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...zn}}},deviation:{name:"",data_keys:{estimated_value:"",actual_value:""}},metrics:[]};function i0(){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 Oo=({value:t})=>{try{return te(t[2]).format({output:"percent",mantissa:0})}catch(e){return console.error(e),t}};function a0(t,e,n){return{type:"heatmap",name:"准确估算比例",xAxisIndex:0,yAxisIndex:0,data:e.map(a=>{const o=n[a].length,c=(x.countBy(n[a],d=>d.level.diff===0).true??0)/o;return[a,"_y",c]}),label:{show:!0,formatter:Oo},labelLayout:{hideOverlap:!0},visualMapIndex:0,tooltip:{trigger:"item",formatter:({color:a,value:o})=>`
|
|
401
401
|
<table style="width: auto">
|
|
402
402
|
<thead>
|
|
403
403
|
<tr colspan="2">
|
|
@@ -419,7 +419,7 @@ Check the top-level render call using <`+P+">.")}return A}}function ql(S,A){{if(
|
|
|
419
419
|
</tr>
|
|
420
420
|
</tbody>
|
|
421
421
|
</table>
|
|
422
|
-
`},show_in_legend:!1}}function Po(t){const e=[`background-color: ${t}`];return t==="rgba(255, 255, 255, 1)"&&e.push("box-shadow: 0px 0px 1px 0px rgba(0,0,0,.5)"),e.join(";")}function
|
|
422
|
+
`},show_in_legend:!1}}function Po(t){const e=[`background-color: ${t}`];return t==="rgba(255, 255, 255, 1)"&&e.push("box-shadow: 0px 0px 1px 0px rgba(0,0,0,.5)"),e.join(";")}function s0([t,e]){const n={x:t,v:`${e}`};try{n.v=te(e).format({output:"number",mantissa:2,trimMantissa:!0})}catch{}return n}function o0(t,e,n,r){var c,d;const a=e.map(f=>{const p=n[f],g=x.sumBy(p,m=>m.level.diff);return[f,g/p.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=At.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 te(f[1]).format({output:"number",mantissa:1,trimMantissa:!0})}catch{return f[1]}}},tooltip:{trigger:"item",formatter:({color:f,value:p})=>{const{x:g,v:m}=s0(p);return`
|
|
423
423
|
<table style="width: auto">
|
|
424
424
|
<thead>
|
|
425
425
|
<tr colspan="2">
|
|
@@ -441,13 +441,13 @@ Check the top-level render call using <`+P+">.")}return A}}function ql(S,A){{if(
|
|
|
441
441
|
</tr>
|
|
442
442
|
</tbody>
|
|
443
443
|
</table>
|
|
444
|
-
`}},show_in_legend:!1}}function
|
|
444
|
+
`}},show_in_legend:!1}}function l0([t,e,n,r]){const a={x:t,percentage:`${e}`,count:n,sum:r};try{a.percentage=te(e).format({output:"percent",mantissa:2,trimMantissa:!0})}catch{}return a}function u0(t,e,n,r){const a={};e.forEach(f=>{const p=x.countBy(n[f],m=>m.level.diff),g=x.sum(Object.values(p));Object.entries(p).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,p)=>f-p),l=Math.max(...o),u=Math.min(...o),c=At.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:p,value:g})=>{const{x:m,percentage:C,count:w,sum:_}=l0(g);return`
|
|
445
445
|
<table style="width: auto">
|
|
446
446
|
<thead>
|
|
447
447
|
<tr colspan="2">
|
|
448
448
|
<div style="
|
|
449
449
|
width: 100%; height: 4px; border-radius: 2px; margin-bottom: 6px;
|
|
450
|
-
${Po(
|
|
450
|
+
${Po(p)}
|
|
451
451
|
"
|
|
452
452
|
/>
|
|
453
453
|
</tr>
|
|
@@ -476,15 +476,15 @@ Check the top-level render call using <`+P+">.")}return A}}function ql(S,A){{if(
|
|
|
476
476
|
</tr>
|
|
477
477
|
</tbody>
|
|
478
478
|
</table>
|
|
479
|
-
`}},show_in_legend:!0}))}function c0(t,e,n,r){const a=q(e.data_key),o=e.name,l=n.map(c=>{const u=x.sumBy(r[c],a.columnKey);return[c,u]});return{type:"line",name:o,xAxisIndex:3,yAxisIndex:3,color:"#b41529",data:l,show_in_legend:!1}}function u0(t,e,n,r){const l={barMinWidth:5,barMaxWidth:20};return[i0(t,n,r),s0(t,n,r,l),...l0(t,n,r,l),c0(t,e,n,r)]}function d0(t,e){const{axisLabel:n}=t.x_axis;return[{data:e,id:"准确估算比例",gridIndex:0,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:e,id:"平均偏差",gridIndex:1,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!0,lineStyle:{color:"#FFFFFF",width:2}},type:"category"},{data:e,id:"数量占比",gridIndex:2,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:e,id:"代码当量",gridIndex:3,axisTick:{show:!1},type:"category",axisLabel:{...n,formatter:Ns(n.formatter)},axisLine:{show:!1}}]}function p0(t){return[{type:"category",name:"准确估算比例",nameRotate:0,nameGap:5,nameLocation:"end",nameTextStyle:{align:"left"},gridIndex:0,axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:"平均偏差",nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:1,boundaryGap:[1,1],axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:"数量占比",nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:2,axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1},min:0,max:1},{type:"value",gridIndex:3,position:"right",splitNumber:3,axisLabel:{show:!0,verticalAlign:"top",showMinLabel:!1,lineHeight:14},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:t.name,nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:3,position:"left",axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}}]}function hi(t){return t==1||t==2?1:hi(t-2)+hi(t-1)}const h0=Array.from(new Array(20),(t,e)=>hi(e+1));function Bo(t){return t<=1?t:h0.findIndex(e=>t<=e)-1}function f0(t,e){const{x_axis:n,deviation:r}=t,a=q(n.data_key),o=q(r.data_keys.estimated_value),l=q(r.data_keys.actual_value);return e[a.queryID].map(c=>{const u=Bo(c[o.columnKey]),d=Bo(c[l.columnKey]),f=u-d;return{...c,level:{estimated:u,actual:d,diff:f}}})}function g0(t){return t==="rgba(255, 255, 255, 1)"?{borderColor:"rgba(0,0,0,.1)",borderWidth:1}:{}}function m0(t){return{show:!0,orient:"vertical",top:"middle",right:0,data:t.filter(n=>n.show_in_legend).reverse().map(n=>({name:`${n.name}`,color:n.color,itemStyle:g0(n.color)})),tooltip:{show:!0,formatter:"档位偏差:{a}"}}}const y0={tooltip:{trigger:"axis"}};function b0(t,e){const{deviation:n,metrics:r}=t,a=r.find(l=>l.data_key===e);if(a)return a;const o=n.data_keys.actual_value;return{id:o,name:n.name,data_key:o}}function v0(t,e,n){const r=f0(t,n),a=q(t.x_axis.data_key),o=x.uniqBy(n[a.queryID],a.columnKey).map(f=>f[a.columnKey]),l=x.groupBy(r,a.columnKey),c=b0(t,e),u=u0(t,c,o,l),d={xAxis:d0(t,o),yAxis:p0(c),series:u,grid:r0(),visualMap:[{min:0,max:1,calculable:!0,show:!1,seriesIndex:0,color:["#F0F0F0","#418AAF"]}],legend:m0(u)};return x.defaultsDeep({},d,y0)}const x0={input:{border:"none !important",paddingLeft:0,lineHeight:"1.55 !important"}},w0=({conf:t,metricKey:e,setMetricKey:n})=>{const{deviation:r,metrics:a}=t,o=y.useMemo(()=>{const l=a.map(c=>({label:c.name,value:c.data_key}));return l.push({label:r.name?r.name:r.data_keys.actual_value,value:r.data_keys.actual_value}),l},[r,a]);return p(s.Group,{spacing:1,children:[i(s.Text,{size:12,color:"dimmed",sx:{cursor:"default",userSelect:"none"},children:"基线指标"}),i(s.NativeSelect,{size:"xs",data:o,value:e,onChange:l=>n(l.currentTarget.value),styles:x0})]})},C0={"tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function S0(){return p(s.HoverCard,{width:400,shadow:"md",children:[i(s.HoverCard.Target,{children:i(s.Button,{size:"xs",variant:"subtle",compact:!0,leftIcon:i(L.IconInfoCircle,{size:14}),children:"指标说明"})}),i(s.HoverCard.Dropdown,{children:i(s.Table,{fontSize:14,sx:C0,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 _0(t){return p(s.Group,{position:"apart",children:[i(S0,{}),i(w0,{...t})]})}ce.use([he.BarChart,he.LineChart,he.HeatmapChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer,G.VisualMapComponent]);function k0({conf:t,data:e,width:n,height:r,metricKey:a}){const o=y.useMemo(()=>v0(t,a,e),[t,e,a]);return i(Ne,{echarts:ce,option:o,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})}function T0({context:t}){const{value:e}=R(t.instanceData,"config"),n=y.useMemo(()=>x.defaults({},e,pi),[e]),r=t.data,{width:a,height:o}=t.viewport,{x_axis:l,deviation:c}=n,{estimated_value:u,actual_value:d}=c.data_keys,[f,h]=y.useState(d);if(y.useEffect(()=>{h(C=>C||d)},[d]),!l.data_key||!u||!d||!a||!o)return null;const g=Math.max(a,300),m=Math.max(o,370);return p(s.Box,{sx:{overflow:"hidden",height:m,width:g},children:[i(_0,{conf:n,metricKey:f,setMetricKey:h}),i(k0,{width:g,height:m-30,data:r,conf:n,metricKey:f})]})}function D0({control:t,watch:e}){return e(["deviation"]),p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"deviation.name",control:t,render:({field:n})=>i(s.TextInput,{label:"指标名称",sx:{flex:1},...n})})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"deviation.data_keys.estimated_value",control:t,render:({field:n})=>i(j,{label:"估算值字段",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"deviation.data_keys.actual_value",control:t,render:({field:n})=>i(j,{label:"实际值字段",required:!0,sx:{flex:1},...n})})]})]})}const I0=({control:t,index:e,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`metrics.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`metrics.${e}.data_key`,control:t,render:({field:r})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),M0=({control:t,watch:e})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"metrics"}),o=e("metrics"),l=n.map((h,g)=>({...h,...o[g]})),c=()=>r({id:Date.now().toString(),data_key:"",name:""}),u=e("metrics.0.id"),[d,f]=y.useState(()=>u??null);return y.useEffect(()=>{u&&f(h=>h!==null?h:u)},[u]),p(N,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(I.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"设置可以展示在基线图的指标,例如代码当量"})]}),i(s.Divider,{variant:"dashed",my:10}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(I0,{control:t,index:g,remove:a},h.id)},h.id))]})]})};function E0({control:t,watch:e}){return e(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>i(j,{label:"数据字段",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"X轴名称",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"点位文案",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"旋转",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"度"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Gs,{...n})})]})]})}function A0({context:t}){const{value:e,set:n}=R(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,pi),[e]),{control:a,handleSubmit:o,watch:l,getValues:c,reset:u}=v.useForm({defaultValues:r});y.useEffect(()=>{u(r)},[r]),l([]);const d=c(),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(I.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"12px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X 轴"}),i(s.Tabs.Tab,{value:"Deviation",children:"偏差"}),i(s.Tabs.Tab,{value:"Additional Metrics",children:"指标"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(E0,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Deviation",children:i(D0,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Additional Metrics",children:i(M0,{control:a,watch:l})})]})]})})}function z0(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis:a,deviation:o,metrics:l,...c}=t;return{...c,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(u=>({...u,data_key:r(u.data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class $0 extends ve{constructor(){super(...arguments);V(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 L0={displayName:"Merico Estimation Chart",displayGroup:"Merico suite",migrator:new $0,name:"mericoEstimationChart",viewRender:T0,configRender:A0,createConfig:()=>({version:2,config:pi})},O0=[{value:"#25262B",name:"Dark"},{value:"#868E96",name:"Gray"},{value:"#FA5252",name:"Red"},{value:"#E64980",name:"Pink"},{value:"#BE4BDB",name:"Grape"},{value:"#7950F2",name:"Violet"},{value:"#4C6EF5",name:"Indigo"},{value:"#228BE6",name:"Blue"},{value:"#15AABF",name:"Cyan"},{value:"#12B886",name:"Teal"},{value:"#40C057",name:"Green"},{value:"#82C91E",name:"Lime"},{value:"#FAB005",name:"Yellow"},{value:"#FD7E14",name:"Orange"}].map(t=>({name:t.name,value:t.value,type:"single",category:"basic"})),P0=[Uc,Xc,Hc,Zc,Jc,eu],Vo=()=>({id:"dashboard",version:ms,manifest:{viz:[bi,av,Lv,Py,Dv,lg,n0,du,Md,Nh,mf,mx,Uf,mh,Qb,Tg,tm,Gv,L0,Wd],color:[...O0,...P0]}}),sn=new iu,we={pluginManager:st("pluginManager"),vizManager:st("vizManager"),colorManager:st("colorManager"),instanceScope:{panelModel:st("panelModel"),vizInstance:st("vizInstance"),interactionManager:st("interactionManager"),migrator:st("migrator"),operationManager:st("operationManager"),triggerManager:st("triggerManager")}},fi=()=>{try{sn.install(Vo())}catch{}const t=new Yc(sn),e=new ru(sn);return{pluginManager:sn,vizManager:t,colorManager:e}},it=y.createContext(fi());try{sn.install(Vo())}catch{}function B0(t,e){const{value:n,set:r}=R(t.operation.operationData,"config"),[a,o]=y.useState(x.defaults({},n,e)),l=async()=>{await r(a)};return y.useEffect(()=>{o(x.defaults({},n,e))},[n]),{config:a,setConfig:o,commit:l}}function V0(t){const{config:e,setConfig:n,commit:r}=B0(t,{urlTemplate:"",openInNewTab:!0});async function a(){await r()}async function o(c){n({...e,openInNewTab:c}),await r()}const l=c=>n({...e,urlTemplate:c.currentTarget.value});return p(s.Stack,{children:[i(s.TextInput,{label:"Url",value:e.urlTemplate,onChange:l,onBlur:a}),i(s.Switch,{label:"Open in new Tab",checked:e.openInNewTab,onChange:c=>o(c.currentTarget.checked)})]})}async function N0(t,e){const{urlTemplate:n,openInNewTab:r}=await e.operationData.getItem("config");window.dispatchEvent(new CustomEvent("open-link",{detail:{urlTemplate:n,openInNewTab:r,payload:t}}))}class q0 extends ve{constructor(){super(...arguments);V(this,"VERSION",1)}configVersions(){this.version(1,n=>n)}}const F0={displayName:"Open Link",id:"builtin:op:open-link",configRender:V0,run:N0,migrator:new q0,createDefaultConfig:()=>({version:1,config:{urlTemplate:"",openInNewTab:!0}})};function G0(t){const{value:e,set:n}=R(t.operationData,"config"),r=a=>void n({template:a});return[(e==null?void 0:e.template)||"",r]}function W0(t){const[e,n]=G0(t.operation);return i(s.TextInput,{defaultValue:e,onBlur:r=>n(r.currentTarget.value),label:"console.log"})}async function R0(t,e){const n=await e.operationData.getItem("config"),r=x.template(n.template||"");console.log("run with payload",t),console.log(r(t))}const j0={displayName:"console.log (debug)",id:"builtin:op:debug",configRender:W0,run:R0},Y0=k.observer(t=>{const e=K(),{value:n,set:r}=R(t.operation.operationData,"config");console.log({value:n,viewID:n==null?void 0:n.viewID});const a=(n==null?void 0:n.viewID)||"",o=l=>void r({viewID:l});return i(s.Select,{defaultValue:a,value:a,onChange:o,label:"View",data:e.views.options})});async function Q0(t,e){const r=(await e.operationData.getItem("config")).viewID;window.dispatchEvent(new CustomEvent("open-view",{detail:{viewID:r}}))}const K0={displayName:"Open View",id:"builtin:op:open_view",configRender:Y0,run:Q0},U0={"tbody tr":{opacity:.5,transition:"opacity 200ms ease"},"tr[data-affected=true]":{opacity:1}},X0=({value:t="",onChange:e})=>{const[n,r]=y.useState(t);y.useEffect(()=>{r(t)},[t]);const a=()=>{e(n)};return i(s.TextInput,{size:"xs",label:"",value:n,onChange:o=>r(o.currentTarget.value),sx:{flexGrow:1},rightSection:i(s.ActionIcon,{color:"green",size:"xs",onClick:a,disabled:n===t,children:i(L.IconDeviceFloppy,{})})})},J0={dictionary:{}},Z0=k.observer(t=>{const e=K(),{value:n=J0,set:r}=R(t.operation.operationData,"config"),{dictionary:a={}}=n;console.log({value:{...n},dictionary:{...a},filters:[...e.filters.keyLabelOptions]});const o=(l,c)=>{if(c===""){const u={...a};delete u[l],r({dictionary:u});return}r({dictionary:{...a,[l]:c}})};return p(s.Table,{sx:U0,children:[i("thead",{children:p("tr",{children:[i("th",{children:"Set filter"}),i("th",{children:"with"})]})}),i("tbody",{children:[...e.filters.keyLabelOptions].map(l=>{const c=l.value in a;return p("tr",{"data-affected":c,children:[i("td",{children:l.label}),i("td",{children:i(X0,{value:a[l.value],onChange:u=>o(l.value,u)})})]},l.value)})})]})});async function H0(t,e){const r=(await e.operationData.getItem("config")).dictionary;window.dispatchEvent(new CustomEvent("set-filter-values",{detail:{dictionary:r,payload:t}}))}const ew={displayName:"Set Filter Values",id:"builtin:op:set_filter_values",configRender:Z0,run:H0},tw={filter_keys:[]},nw=k.observer(t=>{const e=K(),{value:n=tw,set:r}=R(t.operation.operationData,"config"),{filter_keys:a=[]}=n,o=c=>{r({filter_keys:[...c]})},l=y.useMemo(()=>e.filters.current.map(c=>({label:c.label,value:c.key})),[e.filters.values]);return i(s.Stack,{spacing:10,children:i(s.MultiSelect,{label:"Select Filters to Clear",data:l,value:a,onChange:o})})});async function rw(t,e){const r=(await e.operationData.getItem("config")).filter_keys;window.dispatchEvent(new CustomEvent("clear-filter-values",{detail:{filter_keys:r,payload:t}}))}const Un=[j0,F0,K0,ew,{displayName:"Clear Filter Values",id:"builtin:op:clear_filter_values",configRender:nw,run:rw}];class iw{constructor(e,n=Un){V(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 $t(a,"data")}};this.attachments=new br(e,"__OPERATIONS",r)}async runOperation(e,n){const r=await this.attachments.getInstance(e);if(!r){console.warn(`Operation '${e}' is not defined`);return}const a=this.tryGetSchema(r.schemaRef);if(!a){console.warn(`Operation schema '${r.schemaRef}' is not defined`);return}await a.run(n,r)}tryGetSchema(e){return this.operations.find(n=>n.id===e)}async needMigration(){const n=(await this.attachments.list()).map(async r=>{const a={configData:r.operationData},o=this.tryGetSchema(r.schemaRef),l=o==null?void 0:o.migrator;return l&&await l.needMigration(a)});return(await Promise.all(n)).some(r=>r)}async runMigration(){const n=(await this.attachments.list()).map(async r=>{const a={configData:r.operationData},o=this.tryGetSchema(r.schemaRef),l=o==null?void 0:o.migrator;l&&await l.needMigration(a)&&await l.migrate(a)});await Promise.all(n)}async createOrGetOperation(e,n){var l;if(!this.getOperationSchemaList().some(c=>c.id===n.id))throw new Error(`Operation schema '${n.id}' is not defined`);const a=await this.attachments.getInstance(e);return!a||a.schemaRef!==n.id?await this.attachments.create(e,{id:e,schemaRef:n.id,data:((l=n.createDefaultConfig)==null?void 0:l.call(n))??{}}):a}getOperationList(){return this.attachments.list()}getOperationSchemaList(){return this.operations}removeOperation(e){return this.attachments.remove(e)}async retrieveTrigger(e){return await this.attachments.getInstance(e)}}class gi{constructor(e,n,r){V(this,"operationManager");V(this,"triggerManager");V(this,"attachments");this.operationManager=new iw(e,r),this.triggerManager=new Lu(e,n);const a=async o=>{const{id:l,triggerRef:c,operationRef:u}=await o.getItem(null);return{id:l,triggerRef:c,operationRef:u}};this.attachments=new br(e,"__INTERACTIONS",a)}async addInteraction(e,n){const r=e.id,a=n.id,o=`[${r}]:[${a}]`;await this.attachments.create(o,{id:o,triggerRef:r,operationRef:a})}getInteractionList(){return this.attachments.list()}async removeInteraction(e){const n=await this.attachments.getInstance(e);if(!n)return;const{triggerRef:r,operationRef:a}=n;await this.getTriggerRefCount(r)<=1&&await this.triggerManager.removeTrigger(r),await this.getOperationRefCount(a)<=1&&await this.operationManager.removeOperation(a),await this.attachments.remove(e)}async getOperationRefCount(e){return(await this.getInteractionList()).filter(r=>r.operationRef===e).length}async getTriggerRefCount(e){return(await this.getInteractionList()).filter(r=>r.triggerRef===e).length}async runInteraction(e,n){const a=(await this.getInteractionList()).filter(o=>o.triggerRef===e);await Promise.all(a.map(async o=>{try{return await this.operationManager.runOperation(o.operationRef,n)}catch(l){console.warn(`Failed to run operation '${o.operationRef}'`,l)}}))}}const et=({vizManager:t,instance:e})=>J.useCreation(()=>new gi(e,t.resolveComponent(e.type),Un),[e,t]),No={left:"flex-start",center:"center",right:"flex-end"},aw=({header:t,cx:e})=>{const n=x.get(t.column.columnDef.meta,"align","left");return p(s.Text,{className:e("table-head-cell",{"table-head-cell--sortable":t.column.getCanSort()}),onClick:t.column.getToggleSortingHandler(),align:n,sx:{justifyContent:No[n]},children:[t.isPlaceholder?null:Ue.flexRender(t.column.columnDef.header,t.getContext()),i(sw,{direction:t.column.getIsSorted()})]})},sw=({direction:t})=>{switch(t){case"asc":return i(L.IconArrowUp,{size:16});case"desc":return i(L.IconArrowDown,{size:"1em"});default:return null}},mi={id:"builtin:table:click-cell-content",displayName:"Click Cell Content",nameRender:uw,configRender:lw,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"}]},ow={column:""};function qo(t,e){const{value:n}=R(t.instanceData,"config"),r={columnsFromConfig:[],columnsFromData:[]};if(n&&(r.columnsFromConfig=n.columns.map((a,o)=>({label:a.label,value:o.toString()}))),!e)return r;if(n!=null&&n.id_field){const a=xn(e,n.id_field);(a==null?void 0:a.length)>0&&(r.columnsFromData=Object.keys(a[0]).map(o=>({label:o,value:o})))}return r}function lw(t){const{columnsFromConfig:e,columnsFromData:n}=qo(t.instance,t.sampleData),r=e.length>0?e:n,{value:a,set:o}=R(t.trigger.triggerData,"config"),{column:l}=x.defaults({},a,ow),c=u=>{isNaN(+u)?o({column:u}):o({column:+u})};return i(s.Select,{clearable:!1,data:r,label:"Choose a column",value:l.toString(),onChange:c})}function cw(t,e){return t?x.isNumber(t.column)?`Click cell of ${e[t.column].label}`:`Click cell of ${t.column}`:"Click cell content (click to config)"}function uw(t){const{columnsFromConfig:e}=qo(t.instance),{value:n}=R(t.trigger.triggerData,"config");return i(s.Text,{children:cw(n,e)})}const dw=s.createStyles(t=>({root:{overflow:"auto",position:"relative","& .table-head-cell":{display:"flex",flexFlow:"row nowrap",alignItems:"center",whiteSpace:"nowrap","&.table-head-cell--sortable":{cursor:"pointer",userSelect:"none"}},"&.table-highlight-on-hover tr":{transition:"background-color 0.2s","&:hover":{backgroundColor:t.colorScheme==="dark"?t.colors.dark[5]:t.colors.gray[0]}}},thead:{background:t.colorScheme==="dark"?t.colors.dark[7]:t.white,position:"sticky",top:24,transform:"translateY(-1px)",zIndex:10},info_bar:{position:"sticky",top:0,left:0,right:0,zIndex:10,background:"white"}})),pw={tableLayout:"fixed","th, td":{padding:"2px 10px",div:{overflow:"hidden",textOverflow:"ellipsis"},"&:first-of-type":{paddingLeft:2,paddingRight:2}}};function Fo(t,e,n){return Math.min(Math.max(t,e),n)}class hw{constructor(e){this.steps=e;const n=[],r=new Set;for(const a of e)r.has(a.to)||(n.push(a),r.add(a.to));if(n.sort((a,o)=>a.from-o.from),n.length<2)throw new Error("MultiStepValueMapper requires at least 2 steps");this.steps=n}getLinearFunction(e,n){const r=(n.to-e.to)/(n.from-e.from),a=e.to-r*e.from;return o=>r*o+a}getStepFunctionForValue(e){let n=x.findLastIndex(this.steps,r=>r.from<=e);return n=Fo(n,0,this.steps.length-2),this.getLinearFunction(this.steps[n],this.steps[n+1])}mapValue(e){return Fo(this.getStepFunctionForValue(e)(e),0,100)}}class fw{constructor(e,n,r,a,o){this.getColIndex=e,this.cell=n,this.triggers=r,this.interactionManager=a,this.colorManager=o}getClickHandler(){const e=this.getRelatedTrigger();if(e.length!==0)return()=>{const n={row_data:this.cell.row.original,row_index:this.cell.row.index,col_index:this.getColIndex(this.cell)};for(const r of e)this.interactionManager.runInteraction(r.id,n)}}getRelatedTrigger(){return this.triggers.filter(n=>n.schemaRef===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 e=this.columnConf.cellBackgroundColor;if(!e||e==="none")return;if(x.isString(e))return e;const n=+this.cell.getValue();if(isFinite(n)){const r=this.colorManager.decodeInterpolation(e.interpolation),o=new hw(e.steps).mapValue(n);return r==null?void 0:r.getColor(o)}}}const gw=s.createStyles((t,e)=>({content:{display:"flex",alignItems:"center",justifyContent:No[e.align],".table-cell-text":{whiteSpace:"nowrap",cursor:e.clickable?"pointer":"default",textDecoration:e.clickable?"underline":"none"}}}));function mw(t){return t?at(t).oklch()[0]>.7?"black":"white":"inherit"}function yw(t){const e=t.tableCellContext.bgColor;return{backgroundColor:e,color:mw(e)}}function qt(t){const e=t.tableCellContext.isClickable(),n=gw({clickable:e,align:t.align});return i("div",{className:n.classes.content,style:{...yw(t)},children:i(s.Text,{className:"table-cell-text",onClick:t.tableCellContext.getClickHandler(),children:i("span",{title:t.children,children:t.children})})})}function bw(t){return i(qt,{...t,children:t.value})}function vw(t){const e=te(t.value).format({average:!0,mantissa:2,trimMantissa:!0});return i(qt,{...t,children:e})}function xw(t){const e=te(t.value).format({thousandSeparated:!0});return i(qt,{...t,children:e})}function ww(t){const e=te(t.value).format({output:"percent",mantissa:3});return i(qt,{...t,children:e})}function Cw(t){const e=t.value,n=t.func_content;if(!n)return i(qt,{...t,children:e});const r=new Function(`return ${n}`)()({value:e});return i(qt,{...t,children:r})}function Sw(t){switch(t.type){case Xe.string:return i(bw,{...t});case Xe.eloc:return i(vw,{...t});case Xe.number:return i(xw,{...t});case Xe.percentage:return i(ww,{...t});case Xe.custom:return i(Cw,{...t})}}const _w=t=>{const e=et(t),n=He(e.triggerManager,mi.id),{colorManager:r}=y.useContext(it);return y.useCallback(a=>new fw(t.getColIndex,a,n,e,r),[n,e,t.getColIndex])};function kw({context:t,instance:e}){var de,Ce;const n=t.data,{height:r,width:a}=t.viewport,{value:o=yr}=R(t.instanceData,"config"),{id_field:l,use_raw_columns:c,columns:u,...d}=o,{classes:f,cx:h}=dw(),g=y.useMemo(()=>{if(!l)return[];const ye=q(l);return n[ye.queryID]},[n,l]),m=y.useMemo(()=>c?!Array.isArray(g)||g.length===0?[]:Object.keys(g[0]).map(ye=>({id:ye,label:ye,value_field:ye,value_type:Xe.string,align:"left"})):u,[c,u,g]),C=_w({getColIndex:y.useCallback(ye=>m.indexOf(ye.column.columnDef.meta),[m]),vizManager:t.vizManager,instance:e}),w=y.useMemo(()=>{const ye=Ue.createColumnHelper();return m.map(fe=>{const Oe=q(fe.value_field);return ye.accessor(Oe.columnKey,{cell:Ye=>i(Sw,{tableCellContext:C(Ye.cell),value:Ye.getValue(),type:fe.value_type,...fe}),header:fe.label,enableSorting:!0,meta:fe,size:fe.width,minSize:fe.width})})},[m,C]),[_,T]=y.useState([]),M=Ue.useReactTable({data:g,state:{sorting:_},onSortingChange:T,columns:w,getCoreRowModel:Ue.getCoreRowModel(),getSortedRowModel:Ue.getSortedRowModel()}),{rows:O}=M.getRowModel(),B=y.useRef(null),F=Kl.useVirtual({parentRef:B,size:O.length,estimateSize:y.useCallback(()=>28,[]),overscan:20}),{virtualItems:$,totalSize:E}=F,z=$.length>0&&((de=$==null?void 0:$[0])==null?void 0:de.start)||0,W=$.length>0?E-(((Ce=$==null?void 0:$[$.length-1])==null?void 0:Ce.end)||0):0,U=O.length,X=U>0,oe=X?r-22:r,re=X?22:0;return!Array.isArray(g)||g.length===0?i(s.Text,{color:"gray",align:"center",children:"Empty Data"}):p("div",{ref:B,style:{height:r,width:a},"data-enable-scrollbar":!0,className:h(f.root,{"table-highlight-on-hover":o.highlightOnHover}),children:[U>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: ",U]})}),p(s.Table,{sx:{...pw,maxHeight:oe},...d,striped:o.striped,children:[i("thead",{className:f.thead,style:{top:re},children:M.getHeaderGroups().map(ye=>i("tr",{children:ye.headers.map(Te=>i("th",{style:{width:Te.getSize()},children:i(aw,{header:Te,cx:h})},Te.id))},ye.id))}),p("tbody",{children:[z>0&&i("tr",{children:i("td",{style:{height:`${z}px`}})}),$.map(ye=>{const Te=O[ye.index];return i("tr",{children:Te.getVisibleCells().map(fe=>i("td",{children:Ue.flexRender(fe.column.columnDef.cell,fe.getContext())},fe.id))},Te.id)}),W>0&&i("tr",{children:i("td",{style:{height:`${W}px`}})})]})]})]})}const Go=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)"}}}})),Tw=[{from:0,to:0},{from:100,to:100}];class Dw{constructor(){V(this,"steps",new Map);V(this,"interpolation");V(this,"onChange");ae.makeAutoObservable(this,{steps:ae.observable},{deep:!1}),ae.reaction(()=>ae.toJS(this.steps),()=>{this.notifyStepChange()})}setSteps(e){for(const n of e)this.steps.set(n.to,n.from)}notifyStepChange(){var e;(e=this.onChange)==null||e.call(this,Array.from(this.steps.entries()).map(([n,r])=>({to:n,from:r})).sort((n,r)=>n.to-r.to||n.from-r.from))}fromProps(e){e.steps.length<2?this.setSteps(Tw):this.setSteps(e.steps),this.interpolation=e.interpolation,this.onChange=e.onChange}changeStep(e,n){e==null?this.steps.delete(n):this.steps.set(n,e)}getStepFromValue(e){return this.steps.get(e)}}function Iw(t){const{onChange:e,color:n,index:r,value:a}=t,{classes:o}=Go(),[l,c]=y.useState(a),[u,{setTrue:d,setFalse:f}]=J.useBoolean(!1),h=r%2===1,g=h&&a!=null,m=!h&&a!=null,C=`map ${a} to color ${r}`,w=()=>{c(a),f()},_=()=>{f(),e==null||e(l)},T=te(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:u,onClose:f,children:[i(s.Popover.Target,{children:i("div",{"data-testid":"palette-item-target",className:"palette-item",onClick:d,style:{"--shadow-color":at(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:c}),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 Mw=k.observer(({model:t})=>{const{classes:e}=Go(),n=x.range(0,13,1).map(r=>100/12*r).map(r=>[t.interpolation.getColor(r),r]);return i("div",{className:e.palette,children:n.map(([r,a],o)=>i(Iw,{index:o,color:r,value:t.getStepFromValue(a),onChange:l=>t.changeStep(l,a)},r))})}),Ew=k.observer(function(e){const n=J.useCreation(()=>new Dw,[]);return y.useEffect(()=>{n.fromProps(e)}),n.interpolation==null?null:i(Mw,{model:n})}),Aw=t=>{const{value:e,onChange:n,colorManager:r}=t,a=r.getColorInterpolations(),[o,l]=y.useState(e),c=r.decodeInterpolation(o.interpolation)||a[0],[u,{setTrue:d,setFalse:f}]=J.useBoolean(),h=a.map(_=>({label:_.displayName,value:r.encodeColor(_),group:_.category}));function g(_){_&&l(T=>({...T,interpolation:_}))}const m=()=>{f(),n==null||n(ae.toJS(o))};function C(_){l(T=>({...T,steps:_}))}const w=()=>{f(),l(e)};return p(N,{children:[i(s.Button,{variant:"outline",onClick:d,children:c==null?void 0:c.displayName}),i(s.Modal,{size:508,title:"Setup color interpolation",opened:u,onClose:f,zIndex:320,children:u&&p(s.Stack,{"data-testid":"color-interpolation-modal",children:[i(s.Select,{label:"Color style",value:o.interpolation,data:h,onChange:g}),i(Ew,{steps:o.steps,interpolation:c,onChange:C}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:w,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:m,children:"OK"})]})]})})]})},zw=["static","interpolation","none"].map(t=>({label:x.capitalize(t),value:t})),$w=[{from:0,to:0},{from:100,to:100}];function Wo(t){return t?x.isString(t)?t==="none"?"none":"static":"interpolation":"none"}function Lw(t,e){var n;return Wo(e)==="static"?e:(n=t.getStaticColors()[0])==null?void 0:n.value}function Ow(t,e){return x.isObject(e)?e:{steps:$w,interpolation:t.encodeColor(t.getColorInterpolations()[0])}}const Pw=y.forwardRef((t,e)=>{const{colorManager:n}=y.useContext(it),[r,a]=y.useState(Wo(t.value)),[o,l]=y.useState(Lw(n,t.value)),c=J.useLatest(o),[u,d]=y.useState(Ow(n,t.value)),f=J.useLatest(u),h=C=>{var w,_,T;a(C||"none"),C==="static"?(w=t.onChange)==null||w.call(t,c.current):C==="none"||!C?(_=t.onChange)==null||_.call(t,"none"):(T=t.onChange)==null||T.call(t,f.current)},g=C=>{var w;l(C),(w=t.onChange)==null||w.call(t,C)},m=C=>{var w;d(C),(w=t.onChange)==null||w.call(t,C)};return p(s.Stack,{align:"stretch",children:[i(s.Select,{label:"Cell background",value:r||"none",onChange:h,data:zw}),r==="static"&&i(Pe,{value:o,onChange:g}),r==="interpolation"&&i(Aw,{colorManager:n,value:u,onChange:m})]})}),Bw={[Xe.eloc]:"ELOC"},Vw=Object.values(Xe).map(t=>({label:x.get(Bw,t,x.capitalize(t)),value:t})),Nw=y.forwardRef(({label:t,value:e,onChange:n,sx:r},a)=>i(s.Select,{ref:a,label:t,data:Vw,value:e,onChange:n,sx:r})),qw=y.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:a,setFalse:o}]=J.useBoolean(),[l,c]=y.useState(t),u=()=>{o(),e(l)},d=()=>{o(),c(t)},f=()=>{c(ps)};return y.useEffect(()=>{c(t)},[t]),p(N,{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(ze,{height:"500px",defaultLanguage:"javascript",value:l,onChange:h=>c(h??""),theme:"vs-dark",options:{minimap:{enabled:!1}}})}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:u,children:"OK"})]})]})]})})]})}),Fw=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],yi=()=>i(s.Text,{color:"dimmed",size:12,children:"px"}),Gw=({control:t,index:e,watch:n,remove:r,column:a})=>{const o=n(`columns.${e}.value_type`);return p(s.Stack,{my:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,children:[i(v.Controller,{name:`columns.${e}.label`,control:t,render:({field:l})=>i(s.TextInput,{label:"Label",required:!0,id:`col-label-${e}`,sx:{flex:1},...l})}),i(v.Controller,{name:`columns.${e}.value_field`,control:t,render:({field:l})=>i(j,{label:"Value Field",required:!0,...l})})]}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`columns.${e}.value_type`,control:t,render:({field:l})=>i(Nw,{label:"Value Type",sx:{flex:1},...l})}),o===Xe.custom&&i(v.Controller,{name:`columns.${e}.func_content`,control:t,render:({field:l})=>i(qw,{value:l.value??ps,onChange:c=>l.onChange(c??"")})})]}),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.${e}.width`,control:t,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.${e}.align`,control:t,render:({field:l})=>i(s.Select,{label:"Alignment",data:Fw,...l})})}),i(v.Controller,{name:`columns.${e}.cellBackgroundColor`,control:t,render:({field:l})=>i(Pw,{...l})}),i(s.Divider,{mb:4,mt:12,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(e),children:"Delete this column"})]})},Ww=({control:t,watch:e})=>{const{fields:n,append:r,remove:a,update:o}=v.useFieldArray({control:t,name:"columns"}),l=()=>{const u=Ie.randomId();r({id:u,label:u,align:"center",value_field:"",value_type:Xe.string})};e("columns");const c=e("use_raw_columns");return p(N,{children:[i(v.Controller,{name:"use_raw_columns",control:t,render:({field:u})=>i(s.Switch,{mt:20,label:"Use Original Data Columns",checked:u.value,onChange:d=>u.onChange(d.currentTarget.checked)})}),i(s.Divider,{mt:20,mb:10,variant:"dashed"}),!c&&p(s.Stack,{children:[i(s.Text,{my:0,children:"Custom Columns"}),p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[n.map((u,d)=>i(s.Tabs.Tab,{value:d.toString(),children:d+1},u.id)),i(s.Tabs.Tab,{onClick:l,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),n.map((u,d)=>i(s.Tabs.Panel,{value:d.toString(),children:i(Gw,{control:t,watch:e,index:d,column:u,remove:a},d)},u.id))]})]})]})};function Rw({control:t,watch:e}){return e(["horizontalSpacing","verticalSpacing","fontSize","striped","highlightOnHover"]),p(s.Stack,{spacing:"xs",children:[p(s.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:[i(v.Controller,{name:"horizontalSpacing",control:t,render:({field:n})=>i(s.TextInput,{label:"Horizontal Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"verticalSpacing",control:t,render:({field:n})=>i(s.TextInput,{label:"Vertical Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})})]}),i(s.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:i(v.Controller,{name:"fontSize",control:t,render:({field:n})=>i(s.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})})}),p(s.Group,{position:"apart",grow:!0,children:[i(v.Controller,{name:"striped",control:t,render:({field:n})=>i(s.Switch,{label:"Striped",checked:n.value,onChange:r=>n.onChange(r.currentTarget.checked)})}),i(v.Controller,{name:"highlightOnHover",control:t,render:({field:n})=>i(s.Switch,{label:"Highlight on hover",checked:n.value,onChange:r=>n.onChange(r.currentTarget.checked)})})]})]})}function jw({columns:t,...e}){return{...e,columns:t.map(({id:n,...r})=>({id:n??Ie.randomId(),...r}))}}function Yw({context:t}){const{value:e,set:n}=R(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,yr),[e]),a=y.useMemo(()=>jw(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:c,getValues:u,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=u(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return c(["id_field"]),p("form",{onSubmit:l(n),children:[p(s.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Table Config"}),i(s.ActionIcon,{type:"submit","aria-label":"save config",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(I.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"Columns",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Data",children:"Data"}),i(s.Tabs.Tab,{value:"Style",children:"Style"}),i(s.Tabs.Tab,{value:"Columns",children:"Columns"})]}),i(s.Tabs.Panel,{value:"Data",children:i(v.Controller,{name:"id_field",control:o,render:({field:g})=>i(j,{label:"ID Field",required:!0,...g})})}),i(s.Tabs.Panel,{value:"Style",children:i(Rw,{control:o,watch:c})}),i(s.Tabs.Panel,{value:"Columns",children:i(Ww,{control:o,watch:c})})]})]})}function Qw(t){const{columns:e,...n}=t;return{...t,columns:e.map(r=>({...r,align:r.align??"left"}))}}function Kw(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{id_field:a,columns:o,...l}=t;return{...l,id_field:r(a),columns:o.map(c=>({...c,value_field:r(c.value_field)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class Uw extends ve{constructor(){super(...arguments);V(this,"VERSION",4)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{columns:r,...a}=n.config;return{...n,version:2,config:{...a,columns:r.map(({id:o,...l})=>({id:o??Ie.randomId(),...l}))}}}),this.version(3,n=>({...n,version:3,config:Qw(n.config)})),this.version(4,(n,r)=>({...n,version:4,config:Kw(n.config,r)}))}}const bi={createConfig(){return{version:4,config:x.cloneDeep(yr)}},displayName:"Table",displayGroup:"Others",migrator:new Uw,name:"table",viewRender:kw,configRender:Yw,triggers:[mi]},Xw=b.types.model("PanelLayoutModel",{x:b.types.number,y:b.types.maybeNull(b.types.number),w:b.types.number,h:b.types.number,moved:b.types.optional(b.types.boolean,!1),static:b.types.optional(b.types.boolean,!1)}).views(t=>({get json(){const{x:e,y:n,w:r,h:a,moved:o}=t;return{h:a,w:r,x:e,y:n===null?0:n,moved:o,static:t.static}}})).actions(t=>({set(e){const{x:n,y:r,w:a,h:o,moved:l}=e;t.x=n,t.y=r,t.w=a,t.h=o,t.moved=!!l,t.static=!!e.static}})),Jw=b.types.model("PanelStyleBorderModel",{enabled:b.types.boolean}).views(t=>({get json(){const{enabled:e}=t;return{enabled:e}}})).actions(t=>({setEnabled(e){t.enabled=e}})),Zw=b.types.model("PanelStyleModel",{border:Jw}).views(t=>({get json(){const{border:e}=t;return{border:e.json}}})).actions(t=>({})),Hw=b.types.model("PanelVizModel",{type:b.types.string,conf:b.types.frozen()}).views(t=>({get json(){return{conf:t.conf,type:t.type}}})).actions(t=>({setType(e){t.type=e},setConf(e){t.conf=e}})),Ro=b.types.model({id:b.types.string,title:b.types.string,description:b.types.string,layout:Xw,queryIDs:b.types.array(b.types.string),viz:Hw,style:Zw,variables:b.types.optional(b.types.array(Fc),[])}).views(t=>({get contentModel(){return b.getParentOfType(t,Xn)}})).views(t=>({get queryIDSet(){return new Set(t.queryIDs)},get queries(){return t.contentModel.queries.findByIDSet(this.queryIDSet)},get data(){return this.queries.reduce((e,n)=>(e[n.id]=n.data.toJSON(),e),{})},get dataLoading(){return this.queries.some(e=>e.state==="loading")},get queryStateMessages(){return this.queries.map(e=>e.stateMessage).filter(e=>!!e)},get queryErrors(){return this.queries.map(e=>e.error).filter(e=>!!e)},get canRenderViz(){return this.queryErrors.length===0&&this.queryStateMessages.length===0&&!this.dataLoading},get json(){const{id:e,title:n,description:r,queryIDs:a}=t;return{id:e,viz:t.viz.json,style:t.style.json,title:n,layout:t.layout.json,queryIDs:[...a],variables:t.variables.map(o=>o.json),description:r}},get dataFieldOptions(){return t.queryIDs.length===0?[]:this.queries.map(e=>{const n=e.data;return n.length===0?[]:Object.keys(n[0]).map(a=>({label:a,value:`${e.id}.${a}`,group:e.name}))}).flat()}})).actions(t=>({setID(e){t.id=e},setTitle(e){t.title=e},setDescription(e){t.description=e},addQueryID(e){t.queryIDSet.has(e)||t.queryIDs.push(e)},removeQueryID(e){if(!t.queryIDSet.has(e))return;const n=new Set(t.queryIDSet);n.delete(e),t.queryIDs=b.cast(Array.from(n))},setQueryIDs(e){t.queryIDs=b.cast(e)},addVariable(e){t.variables.push(e)},removeVariable(e){t.variables.remove(e)},removeSelf(){b.getParent(t,2).removeByID(t.id)}})).actions(t=>({moveToView(e,n){b.getRoot(t).content.views.findByID(e).removePanelID(t.id),b.getRoot(t).content.views.findByID(n).appendPanelID(t.id),b.getRoot(t).editor.setPath(["_VIEWS_",n,"_PANELS_",t.id])},refreshData(){t.queries.forEach(e=>e.fetchData())},downloadData(){b.getRoot(t).content.queries.downloadDataByQueryIDs(t.queryIDs)}}));function jo(t){return{id:t,layout:{x:0,y:1/0,w:18,h:300},title:t,description:"<p></p>",queryIDs:[],viz:{type:bi.name,conf:bi.createConfig()},style:{border:{enabled:!0}}}}const Yo=b.types.model("PanelsModel",{list:b.types.optional(b.types.array(Ro),[])}).views(t=>({get json(){return t.list.map(e=>e.json)},findByID(e){return t.list.find(n=>n.id===e)},get idMap(){const e=new Map;return t.list.forEach(n=>{e.set(n.id,n)}),e}})).views(t=>({panelsByIDs(e){const n=[];e.forEach(a=>{const o=t.idMap.get(a);o?n.push(o):console.warn(`Panel is not found, id:${a}`)});const r=n.map(a=>({...a.layout.json,i:a.id}));return{panels:n,layouts:r}}})).views(t=>({editorOptions(e,n){const{panels:r}=t.panelsByIDs(n);r.length!==n.length&&console.warn(`Unfulfilled panels for View[${e}]`);const a=r.map(l=>({label:l.title?l.title:x.capitalize(l.viz.type),value:l.id,_type:"panel",parentID:e})),o="_Add_A_PANEL_";return a.push({label:o,value:o,_type:"ACTION",_action_type:o,parentID:e,Icon:null,children:null}),a}})).actions(t=>({replace(e){t.list=b.castToSnapshot(e)},append(e){t.list.push(e)},remove(e){t.list.splice(e,1)},removeByID(e){const n=t.list.findIndex(r=>r.id===e);n!==-1&&t.list.splice(n,1)},duplicateByID(e){const n=t.list.find(a=>a.id===e);if(!n){console.error(new Error(`[duplicate panel] Can't find a panel by id[${e}]`));return}const r=new Date().getTime().toString();return t.list.push({...n.json,id:r,layout:{...n.layout,y:1/0,moved:!1}}),r},replaceByIndex(e,n){t.list.splice(e,1,n)}}));var Qo=(t=>(t.Use="use",t.Edit="edit",t))(Qo||{}),H=(t=>(t.Division="div",t.Modal="modal",t.Tabs="tabs",t))(H||{});const eC={div:"Division",tabs:"Tabs",modal:"Modal"},Ko={div:"rgba(255, 0, 0, 0.2)",modal:"rgba(0, 0, 0, 0.2)",tabs:"rgba(255, 200, 100, 0.4)"},tC={div:"#ff4000",modal:"#000",tabs:"#ffad18"},nC={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:"div",config:{},panelIDs:[]}],panels:[],filters:[],version:"9.19.0"};var vi=(t=>(t.Select="select",t.TreeSelect="tree-select",t.MultiSelect="multi-select",t.TextInput="text-input",t.Checkbox="checkbox",t.DateRange="date-range",t))(vi||{});const Uo=b.types.model("ViewModel_Division",{_name:b.types.literal(H.Division)}).views(t=>({get json(){const{_name:e}=t;return{_name:e}}})).actions(t=>({})),rC=()=>Uo.create({_name:H.Division}),xi={enabled:!1,func_content:["function text({ filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
|
|
480
|
-
`)},iC=b.types.model("CustomModalTitleModel",{enabled:b.types.optional(b.types.boolean,!1),func_content:b.types.optional(b.types.string,"")}).views(t=>({get json(){const{enabled:e,func_content:n}=t;return{enabled:e,func_content:n}},get value(){const{enabled:e,func_content:n}=t,r=b.getParent(t,2),a=b.getRoot(t);if(!e)return r.name;try{const o={filters:a.content.filters.values,context:a.context.current};return new Function(`return ${n}`)()(o)}catch(o){return console.error(o),r.name}}})).actions(t=>({setEnabled(e){t.enabled=e},setFuncContent(e){t.func_content=e},replace({enabled:e,func_content:n}){t.enabled=e,t.func_content=n}})),Xo=b.types.model("ViewModel_Modal",{_name:b.types.literal(H.Modal),width:b.types.string,height:b.types.string,custom_modal_title:b.types.optional(iC,xi)}).views(t=>({get json(){const{_name:e,width:n,height:r,custom_modal_title:a}=t;return{_name:e,width:n,height:r,custom_modal_title:a.json}}})).actions(t=>({setWidth(e){t.width=e},setHeight(e){t.height=e}})),aC=()=>Xo.create({_name:H.Modal,width:"90vw",height:"90vh"}),sC=b.types.model("ViewModel_Tabs_Tab",{id:b.types.identifier,name:b.types.string,view_id:b.types.string,color:b.types.optional(b.types.string,"")}).views(t=>({get json(){const{id:e,name:n,view_id:r,color:a}=t;return{id:e,name:n,color:a,view_id:r}}})).actions(t=>({setName(e){t.name=e},setViewID(e){t.view_id=e},setColor(e){t.color=e}})),Jo=b.types.model("ViewModel_Tabs",{_name:b.types.literal(H.Modal),tabs:b.types.optional(b.types.array(sC),[]),variant:b.types.optional(b.types.enumeration("variant",["default","outline","pills"]),"default"),orientation:b.types.optional(b.types.enumeration("orientation",["horizontal","vertical"]),"horizontal"),grow:b.types.optional(b.types.boolean,!1)}).views(t=>({get json(){const{_name:e,variant:n,orientation:r,tabs:a,grow:o}=t;return{grow:o,tabs:a.map(l=>l.json),_name:e,variant:n,orientation:r}}})).actions(t=>({setVariant(e){t.variant=e},setOrientation(e){t.orientation=e},setGrow(e){t.grow=e},setTabs(e){t.tabs.length=0,t.tabs=b.cast(e)},addTab(){const e=Ie.randomId(),n={id:e,name:e,view_id:""};t.tabs.push(n)},removeTab(e){t.tabs.splice(e,1)}})),oC=()=>Jo.create({_name:H.Modal,tabs:[]}),Zo=b.types.model({id:b.types.identifier,name:b.types.string,type:b.types.enumeration("EViewComponentType",[H.Division,H.Modal,H.Tabs]),config:b.types.union(Uo,Xo,Jo),panelIDs:b.types.optional(b.types.array(b.types.string),[])}).views(t=>({get json(){const{id:e,name:n,type:r,config:a}=t;return{id:e,name:n,type:r,config:a.json,panelIDs:t.panelIDs}}})).actions(t=>({setName(e){t.name=e},setType(e){if(t.type!==e){switch(e){case H.Division:t.config=rC();break;case H.Modal:t.config=aC();break;case H.Tabs:t.config=oC();break}t.type=e}},appendPanelID(e){t.panelIDs.push(e)},removePanelID(e){const n=t.panelIDs.filter(r=>r!==e);t.panelIDs.length=0,t.panelIDs.push(...n)}})).actions(t=>({})),Ho=b.types.model("ViewsModel",{current:b.types.optional(b.types.array(Zo),[]),visibleViewIDs:b.types.array(b.types.string),idOfVIE:b.types.string}).views(t=>({get json(){return t.current.map(e=>yn(e.json))},get idMap(){const e=new Map;return t.current.forEach(n=>{e.set(n.id,n)}),e},findByID(e){return t.current.find(n=>n.id===e)},get isVIETheFirstView(){return t.current.length===0||!t.idOfVIE?!1:t.current[0].id===t.idOfVIE},get firstVisibleView(){const[e]=t.visibleViewIDs;return t.current.find(({id:n})=>n===e)},get visibleViews(){const e=new Set(t.visibleViewIDs);return t.current.filter(({id:n})=>e.has(n))},get VIE(){return t.current.find(({id:e})=>e===t.idOfVIE)},get options(){return t.current.map(e=>({label:e.name,value:e.id,type:e.type}))},get editorOptions(){const e=b.getRoot(t).content.panels;return t.current.map(n=>({label:n.name,value:n.id,_type:"view",children:e.editorOptions(n.id,n.panelIDs)}))}})).actions(t=>({replace(e){t.current.replace(e)},addANewView(e,n,r,a){t.current.push({id:e,name:n,type:r,config:a,panelIDs:[]})},append(e){t.current.push(e)},remove(e){t.current.splice(e,1)},removeByID(e){const n=t.current.findIndex(r=>r.id===e);n!==-1&&t.current.splice(n,1)},replaceByIndex(e,n){t.current.splice(e,1,n)},setIDOfVIE(e){t.idOfVIE=e,t.visibleViewIDs.length=0,t.visibleViewIDs.push(e)},appendToVisibles(e){new Set(t.visibleViewIDs.map(r=>r)).has(e)||t.visibleViewIDs.push(e)}})).actions(t=>({addARandomNewView(){const e=new Date().getTime().toString();t.addANewView(e,H.Division,H.Division,{_name:H.Division}),t.setIDOfVIE(e)},removeVIE(){t.current.length!==1&&(t.removeByID(t.idOfVIE),t.setIDOfVIE(t.current[0].id))},rmVisibleViewID(e){const n=t.visibleViewIDs.findIndex(r=>r===e);n!==-1&&t.visibleViewIDs.splice(n,1)}}));function wi(t){const e=t.length>0?[t[0].id]:[],n=t.length>0?t[0].id:"";return{current:t.map(a=>{const{_name:o=a.type}=a.config;return{...a,config:{...a.config,_name:o},panelIDs:a.panelIDs}}),visibleViewIDs:e,idOfVIE:n}}function el(t,e,n,r){return t.reduce((a,o)=>(a[o[e]]=ur(o[n],r),a),{})}const lC=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:ts,queries:ls,sqlSnippets:us,views:Ho,panels:Yo,mock_context:qc,origin:b.types.maybe(b.types.frozen())}).views(t=>({get json(){return{id:t.id,name:t.name,create_time:t.create_time,update_time:t.update_time,dashboard_id:t.dashboard_id,content:{views:t.views.json,panels:t.panels.json,filters:t.filters.json,version:t.version,definition:{queries:t.queries.json,sqlSnippets:t.sqlSnippets.json,mock_context:t.mock_context.current}}}},get filtersChanged(){const e="filters.current";return!x.isEqual(b.getSnapshot(x.get(t,e)),x.get(t.origin,e))},get queriesChanged(){const e="queries.current",n=b.getSnapshot(x.get(t,e)).map(r=>x.pick(r,["id","name","key","type","sql","run_by","react_to","pre_process","post_process"]));return!x.isEqual(n,x.get(t.origin,e))},get sqlSnippetsChanged(){const e="sqlSnippets.current";return!x.isEqual(b.getSnapshot(x.get(t,e)),x.get(t.origin,e))},get viewsChanged(){const e="views.current";return!x.isEqual(b.getSnapshot(x.get(t,e)),x.get(t.origin,e))},get panelsChanged(){const e="panels.list";return!x.isEqual(b.getSnapshot(x.get(t,e)),x.get(t.origin,e))},get mockContextChanged(){const e="mock_context.current";return!x.isEqual(x.get(t,e),x.get(t.origin,e))},get payloadForSQL(){const e=b.getParent(t).context.current,n=b.getParent(t).globalSQLSnippets,r={context:{...t.mock_context.current,...e},filters:t.filters.values};return{...r,sql_snippets:el(t.sqlSnippets.current,"key","value",r),global_sql_snippets:el(n.list,"id","content",r)}},get payloadForViz(){const e=b.getParent(t).context.current;return{context:{...t.mock_context.current,...e},filters:t.filters.values}},get changed(){return this.filtersChanged||this.queriesChanged||this.sqlSnippetsChanged||this.viewsChanged||this.panelsChanged||this.mockContextChanged},get data(){return t.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(e){const n=t.queries.findByID(e);return n?{data:n.data.toJSON(),len:n.data.length,state:n.state,error:n.error}:{data:[],len:0,state:"idle",error:void 0}}})).views(t=>({findQueryUsage(e){const n=t.panels.idMap,r=t.views.current.flatMap(l=>l.panelIDs.map(c=>n.get(c)).filter(c=>(c==null?void 0:c.queryIDSet.has(e))??!1).map(c=>({type:"panel",id:c.id,label:c.title?c.title:c.viz.type,views:[{id:l.id,label:l.name}]}))),a=t.views.idMap,o=t.filters.current.filter(l=>x.get(l,"config.options_query_id")===e).map(l=>({type:"filter",id:l.id,label:l.label,views:l.visibleInViewsIDs.map(c=>{var u;return{id:c,label:((u=a.get(c))==null?void 0:u.name)??c}})}));return r.concat(o)}})).actions(t=>({duplicatePanelByID(e,n){var a;const r=t.panels.duplicateByID(e);r&&((a=t.views.findByID(n))==null||a.appendPanelID(r))},removePanelByID(e,n){var r;t.panels.removeByID(e),(r=t.views.findByID(n))==null||r.removePanelID(e)},addANewPanel(e){var r;const n=new Date().getTime().toString();t.panels.append(jo(n)),(r=t.views.findByID(e))==null||r.appendPanelID(n)}})).actions(t=>({reset(){b.applySnapshot(t.filters.current,t.origin.filters.current),b.applySnapshot(t.queries.current,t.origin.queries.current),b.applySnapshot(t.sqlSnippets.current,t.origin.sqlSnippets.current),b.applySnapshot(t.views.current,t.origin.views.current),b.applySnapshot(t.panels.list,t.origin.panels.list),t.mock_context.current=t.origin.mock_context.current},resetFilters(){b.applySnapshot(t.filters.current,t.origin.filters.current)},updateCurrent(e){const{id:n,name:r,content:a}=e;if(!a)throw new Error("unexpected null content when updating a content model");const{version:o,filters:l,views:c,panels:u,definition:{queries:d,sqlSnippets:f,mock_context:h={}}}=a;t.id=n,t.name=r,t.version=o,b.applySnapshot(t.filters.current,l),b.applySnapshot(t.views.current,wi(c).current),b.applySnapshot(t.panels.list,u),b.applySnapshot(t.queries.current,d),b.applySnapshot(t.sqlSnippets.current,f),t.mock_context.current=h}})),Xn=b.types.snapshotProcessor(lC,{preProcessor(t){return{...t,origin:t}},postProcessor(t){delete t.origin;const e=b.castToSnapshot(t.queries.current.map(n=>x.pick(n,["id","key","type","sql"])));return x.defaults({},{queries:{current:e}},t)}});function cC(t,e){e.filters&&b.applySnapshot(t.filters.current,e.filters)}function tl({id:t,name:e,dashboard_id:n,create_time:r,update_time:a,content:o}){if(!o)throw new Error("unexpected null content when creating a content model");const{version:l,filters:c,views:u,panels:d,definition:{queries:f,sqlSnippets:h,mock_context:g={}}}=o;return Xn.create({id:t,name:e,dashboard_id:n,create_time:r,update_time:a,version:l,filters:ns(c),queries:{current:f},sqlSnippets:{current:h},mock_context:{current:g},views:wi(u),panels:{list:d}})}const uC=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}),dC=b.types.model("GlobalSQLSnippetsModel",{list:b.types.optional(b.types.array(uC),[])}).views(t=>({find(e){return t.list.find(n=>n.id===e)},get options(){return t.list.map(e=>({value:e.id,label:e.id}))}})).actions(t=>({replace(e){t.list.length=0,t.list.push(...e)}})),nl=b.types.model({id:b.types.identifier,name:b.types.string,group:b.types.string,content:Xn,content_id:b.types.string,datasources:Bc,globalSQLSnippets:dC,context:ds,editor:Nc}).views(t=>({get json(){return{id:t.id,name:t.name,group:t.group,content_id:t.content_id}}})).actions(t=>({updateCurrentContent(e){t.content.updateCurrent(e)},updateCurrent(e,n){const{id:r,name:a,group:o,content_id:l}=e;t.id=r,t.name=a,t.group=o,t.content_id=l,this.updateCurrentContent(n)}}));function Ci({id:t,name:e,group:n,content_id:r},a,o,l,c){return nl.create({id:t,name:e,group:n,content_id:r,content:tl(a),datasources:{list:o},globalSQLSnippets:{list:l},context:{current:c},editor:{}})}const Si=y.createContext(null);function Jn(t){const e=y.useContext(Si),n=J.useCreation(()=>t.configure(e||new vr),[t.configure]),r=J.usePrevious(n);return r&&r!==n&&r.dispose(),i(Si.Provider,{value:n,children:t.children})}function rl(){return y.useContext(Si)}const pC={viewPanelInFullScreen:x.noop,inFullScreen:!1},_i=y.createContext(pC),hC=({description:t,isDescriptionEmpty:e})=>e?null:i(s.Tooltip,{color:"white",label:i(Yn,{value:t,styles:{root:{border:"none"},content:{padding:0}}}),styles:{tooltip:{border:"0.0625rem solid rgb(233, 236, 239)",boxShadow:"rgb(0 0 0 / 5%) 0px 0.0625rem 0.1875rem, rgb(0 0 0 / 5%) 0px 1.25rem 1.5625rem -0.3125rem, rgb(0 0 0 / 4%) 0px 0.625rem 0.625rem -0.3125rem"}},withArrow:!0,children:i(s.Box,{sx:{height:"16px",alignSelf:"center"},children:i(L.IconInfoCircle,{size:16,color:"gray"})})}),fC=k.observer(({label:t,config:{default_value:e,description:n,isDescriptionEmpty:r,...a},value:o,onChange:l})=>p(s.Box,{children:[i(s.Text,{children:" "}),i(s.Checkbox,{label:p(s.Group,{noWrap:!0,position:"apart",align:"middle",spacing:6,children:[i(s.Box,{sx:{flexGrow:1},children:t}),i(hC,{description:n,isDescriptionEmpty:r})]}),checked:o||!1,onChange:c=>l(c.currentTarget.checked),...a,pt:".4em",styles:{input:{borderColor:"#e9ecef"}}})]})),il=k.observer(({label:t,config:e,value:n=[null,null],onChange:r})=>{const a=Array.isArray(n)?n.map(u=>u?Y(u).toDate():null):[null,null],o=u=>{r(u.map(d=>d&&Y(d).format(e.inputFormat)))},l=e.getMinDate(a[0]),c=e.getMaxDate(a[0]);return i(Jl.DateRangePicker,{label:t,value:a,onChange:o,icon:i(I.Calendar,{size:16}),sx:{minWidth:"16em"},minDate:l,maxDate:c,styles:{input:{borderColor:"#e9ecef"}},...e})}),gC=s.createStyles((t,{radius:e=4})=>({root:{borderRadius:t.fn.radius(e),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-select.rc-select-open":{borderColor:"#228be6 !important",".rc-select-selection-overflow-item-rest":{display:"none"},".rc-select-selection-overflow-item-suffix":{display:"block"}},".rc-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-select-selection-search-mirror":{display:"none"},".rc-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:t.fontSizes.sm,fontWeight:500,color:"#212529"},dropdown:{fontSize:t.fontSizes.xs,zIndex:300,backgroundColor:"#fff",border:"1px solid #e9ecef",marginTop:6,padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px","&.rc-select-dropdown-slide-up-leave-active":{display:"none"},".rc-select-item-empty":{padding:"8px 12px"},".rc-select-item-option":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"8px 12px 8px 2px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},flexDirection:"row-reverse",".rc-select-item-option-state":{flexGrow:0,flexShrink:0,width:"30px",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},".rc-select-item-option-content":{flexGrow:1}}}})),al=({errorMessage:t})=>t?i(s.Text,{color:"red",size:12,children:t}):i(s.Text,{color:"dimmed",size:12,children:"Not found"}),mC=({disabled:t,classNames:e,styles:n,unstyled:r,radius:a,style:o,label:l,value:c,onChange:u,options:d,errorMessage:f})=>{const{classes:h,cx:g}=gC({radius:a},{name:"MultiSelectWidget",classNames:e,styles:n,unstyled:r}),[m,C]=y.useState(!1),w=B=>{C(B)},_=m&&(c==null?void 0:c.length)>0,[T,M]=y.useState(""),O=y.useMemo(()=>{if(!T)return d;const B=T.toLowerCase(),F=$=>{var E;return((E=$.description)==null?void 0:E.toLowerCase().includes(B))||$.label.toLowerCase().includes(B)};return d.filter(F)},[T,d]);return p(s.Stack,{spacing:3,children:[p(s.Group,{position:"apart",children:[i(s.Text,{className:h.label,children:l}),_&&i(s.Tooltip,{label:`${c.length} selected`,children:i(s.Badge,{children:c.length})})]}),i(Ba,{disabled:t,allowClear:!0,className:g(h.root,"check-select"),dropdownClassName:g(h.dropdown,""),onDropdownVisibleChange:w,transitionName:"rc-select-dropdown-slide-up",choiceTransitionName:"rc-select-selection__choice-zoom",style:o,clearIcon:()=>i(s.CloseButton,{}),value:c,onChange:u,onSelect:console.log,mode:"multiple",maxTagCount:0,notFoundContent:i(al,{errorMessage:f}),maxTagTextLength:10,maxTagPlaceholder:B=>`${B.length} selected`,searchValue:T,onSearch:M,filterOption:!1,children:O.map(B=>i(Ba.Option,{children:i(s.Group,{noWrap:!0,children:p("div",{children:[i(s.Text,{size:"sm","data-role":"label",children:B.label}),B.description&&i(s.Text,{size:"xs",color:"dimmed","data-role":"description",children:B.description})]})})},B.value))})]})},yC=k.observer(({label:t,config:e,value:n,onChange:r})=>{const a=K(),o=!!e.options_query_id,{state:l,error:c}=a.getDataStuffByID(e.options_query_id),u=l==="loading",d=e.min_width?e.min_width:"200px",f=o?u:!1,h=g=>r(g,!1);return i(mC,{label:t,options:e.options,style:{minWidth:"160px",width:d,maxWidth:f?d:"unset",borderColor:"#e9ecef"},disabled:f,value:n,onChange:h,errorMessage:c})}),bC=y.forwardRef(({label:t,description:e,...n},r)=>i("div",{ref:r,...n,children:i(s.Group,{noWrap:!0,children:p("div",{children:[i(s.Text,{size:"sm","data-role":"label",children:t}),i(s.Text,{size:"xs",color:"dimmed","data-role":"description",children:e})]})})})),vC=k.observer(({label:t,config:e,value:n,onChange:r})=>{const a=K(),o=!!e.options_query_id,{state:l,error:c}=a.getDataStuffByID(e.options_query_id),u=l==="loading";return y.useEffect(()=>{var h;const{default_selection_count:d}=e;if(!d)return;const f=((h=e.options[0])==null?void 0:h.value)??"";console.log("Selecting the first option by default. New value: ",f),r(f,!0)},[e.default_selection_count,e.options]),i(s.Select,{label:t,data:e.options,disabled:o?u:!1,value:n,onChange:r,error:!!c,placeholder:c,maxDropdownHeight:500,styles:{root:{width:e.width?e.width:"200px"},input:{borderColor:"#e9ecef"}},sx:{".mantine-Select-item[data-selected] .mantine-Text-root[data-role=description]":{color:"rgba(255,255,255,.7)"}},itemComponent:bC})});function xC({label:t,config:e,value:n,onChange:r}){return i(s.TextInput,{label:t,value:n||"",onChange:a=>r(a.currentTarget.value),...e,styles:{input:{borderColor:"#e9ecef"}}})}const wC=({rotate:t,onClick:e})=>i("svg",{onClick:e,className:"caret-icon",viewBox:"0 0 1024 1024",focusable:"false","data-icon":"caret-down",width:"14px",height:"14px",fill:"currentColor","aria-hidden":"true",transform:`rotate(${t})`,children:i("path",{d:"M840.4 300H183.6c-19.7 0-30.7 20.8-18.5 35l328.4 380.8c9.4 10.9 27.5 10.9 37 0L858.9 335c12.2-14.2 1.2-35-18.5-35z"})}),CC=({expanded:t,isLeaf:e,value:n,onClick:r,...a})=>(n==="0-0-value"&&console.log(a),e?i("span",{style:{width:"14px",display:"inline-block"}}):i(wC,{rotate:t?"0":"-90",onClick:r,...a})),SC=({onClick:t})=>p("svg",{onClick:t,className:"checkbox-icon",width:"16",height:"16",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[i("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),i("rect",{className:"border",x:"4",y:"4",width:"16",height:"16",rx:"2"}),i("rect",{className:"checkmark-indeterminate",x:"8",y:"8",width:"8",height:"8",rx:"2",stroke:"none"}),i("path",{className:"checkmark-checked",d:"M9 12l2 2l4 -4"})]}),_C=({onClick:t,...e})=>i(SC,{onClick:t,...e}),kC=s.createStyles((t,{radius:e=4})=>({root:{borderRadius:t.fn.radius(e),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-tree-select.rc-tree-select-open":{borderColor:"#228be6 !important",".rc-tree-select-selection-overflow-item-rest":{display:"none"},".rc-tree-select-selection-overflow-item-suffix":{display:"block"}},".rc-tree-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-tree-select-selection-search-mirror":{display:"none"},".rc-tree-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-tree-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-tree-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-tree-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-tree-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-tree-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-tree-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-tree-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:t.fontSizes.sm,fontWeight:500,color:"#212529"},dropdown:{fontSize:t.fontSizes.xs,zIndex:300,paddingTop:"6px","&.rc-tree-select-dropdown-slide-up-leave-active":{display:"none"},".rc-tree-select-tree-list .rc-tree-select-tree-list-holder":{},".rc-tree-select-tree-list, .rc-tree-select-empty":{backgroundColor:"#fff",border:"1px solid #e9ecef",padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px"},".rc-tree-select-empty":{padding:"8px 12px"},".rc-tree-select-tree-treenode":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"8px 12px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},"&.rc-tree-select-tree-treenode-checkbox-checked":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-checked":{stroke:"rgb(64, 192, 87)",animation:"check 200ms linear forwards"}},"&.rc-tree-select-tree-treenode-checkbox-indeterminate":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-indeterminate":{fill:"rgb(64, 192, 87)"}},".rc-tree-select-tree-switcher":{height:"16px",alignSelf:"center",paddingRight:"2px",transition:"color 200ms ease","&:hover":{color:"#228be6","svg.caret-icon":{color:"#228be6"}},"svg.caret-icon":{color:"#ced4da",transition:"all 200ms ease"}},".rc-tree-select-tree-node-content-wrapper":{display:"flex",flexWrap:"nowrap",overflow:"hidden",alignItems:"center",gap:"8px",transition:"color 200ms ease","&:hover":{color:"#228be6"}},".rc-tree-select-tree-iconEle":{height:"16px","svg .border":{stroke:"#ced4da"},".checkbox-icon .checkmark-indeterminate":{fill:"transparent",transition:"fill 200ms ease"},".checkbox-icon .checkmark-checked":{transform:"scale(1.2)",transformOrigin:"center center",strokeDasharray:10,strokeDashoffset:-10},"@keyframes check":{"0%":{strokeDashoffset:10},"100%":{strokeDashoffset:0}}},".rc-tree-select-tree-title":{textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden",".rc-tree-select-tree-title-desc":{fontSize:"12px",maxWidth:"100%",textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden"}},".rc-tree-select-tree-indent":{flexGrow:0,height:0,verticalAlign:"bottom"},".rc-tree-select-tree-indent-unit":{display:"inline-block",width:"1em"}}}})),TC=({disabled:t,classNames:e,styles:n,unstyled:r,radius:a,style:o,label:l,value:c,onChange:u,treeData:d,errorMessage:f})=>{const{classes:h,cx:g}=kC({radius:a},{name:"FilterTreeSelectWidget",classNames:e,styles:n,unstyled:r}),[m,C]=y.useState(!1),w=T=>{C(T)},_=m&&(c==null?void 0:c.length)>0;return p(s.Stack,{spacing:3,children:[p(s.Group,{position:"apart",children:[i(s.Text,{className:h.label,children:l}),_&&i(s.Tooltip,{label:`${c.length} selected`,children:i(s.Badge,{children:c.length})})]}),i(Va,{disabled:t,allowClear:!0,className:g(h.root,"check-select"),dropdownClassName:g(h.dropdown,""),onDropdownVisibleChange:w,transitionName:"rc-tree-select-dropdown-slide-up",choiceTransitionName:"rc-tree-select-selection__choice-zoom",style:o,treeLine:!0,clearIcon:()=>i(s.CloseButton,{}),switcherIcon:CC,treeIcon:_C,maxTagTextLength:10,value:c,treeData:d,notFoundContent:i(al,{errorMessage:f}),treeNodeFilterProp:"filterBasis",treeCheckable:!0,showCheckedStrategy:Va.SHOW_PARENT,onChange:u,onSelect:console.log,maxTagCount:0,maxTagPlaceholder:T=>`${T.length} selected`})]})},DC=k.observer(({label:t,config:e,value:n,onChange:r})=>{const{treeData:a,treeDataLoading:o,errorMessage:l}=e,c=e.min_width?e.min_width:"200px",d=!!e.options_query_id?o:!1;return i(TC,{disabled:d,style:{minWidth:"160px",width:c,maxWidth:d?c:"unset",borderColor:"#e9ecef"},value:n,onChange:f=>r(f,!1),treeData:a,errorMessage:l,label:t})}),IC=k.observer(({filter:{type:t,config:e,key:n,...r},formFieldProps:a})=>{switch(t){case"select":return i(vC,{...r,...a,config:e});case"multi-select":return i(yC,{...r,...a,config:e});case"tree-select":return i(DC,{...r,...a,config:e});case"text-input":return i(xC,{...r,...a,config:e});case"date-range":return i(il,{...r,...a,config:e});case"checkbox":return i(fC,{...r,...a,config:e});default:return null}}),sl=k.observer(y.forwardRef(({filter:t,...e},n)=>i("div",{className:"filter-root",ref:n,children:i(Fe,{children:i(IC,{filter:t,formFieldProps:e})})}))),ol=k.observer(function({view:e}){const n=K(),{control:r,handleSubmit:a,reset:o}=v.useForm({defaultValues:n.filters.values,reValidateMode:"onBlur"}),l=v.useWatch({control:r});y.useEffect(()=>{o(n.filters.values)},[n.filters.values,o]),y.useEffect(()=>{n.filters.updatePreviewValues(l)},[l]);const c=n.filters.visibleInView(e.id),u=y.useMemo(()=>c.every(g=>g.should_auto_submit),[c]),d=y.useMemo(()=>c.filter(g=>x.get(g,"config.required",!1)),[c]),f=y.useMemo(()=>d.length===0?!1:d.some(g=>!g.requiredAndPass(l[g.key])),[l,d]);if(c.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:u?{}:{border:"1px solid #e9ecef",borderRadius:"4px",padding:"16px"},children:[i(s.Group,{align:"flex-start",children:c.map(g=>i(v.Controller,{name:g.key,control:r,render:({field:m})=>i(sl,{filter:g,value:m.value,onChange:h(g,m.onChange)})},g.id))}),!u&&i(s.Group,{sx:{alignSelf:"flex-end"},children:i(s.Button,{color:"blue",size:"sm",type:"submit",disabled:f,children:"Search"})})]})})}),QT="";function MC(t){return t?["<p><br></p>","<p></p>"].includes(t):!0}const ll=k.observer(()=>{const{freezeLayout:t}=y.useContext(ft),[e,n]=y.useState(!1),{panel:r}=Ae();return y.useEffect(()=>{t(e)},[e]),MC(r.description)?null:p(N,{children:[i(s.Modal,{opened:e,onClose:()=>n(!1),title:r.title,withCloseButton:!1,withinPortal:!0,zIndex:310,children:i(Yn,{value:r.description,styles:{root:{border:"none"},content:{padding:0}}})}),i(s.Tooltip,{label:"Click to see description",position:"top-start",withinPortal:!0,children:i(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>n(a=>!a),sx:{verticalAlign:"baseline",cursor:"pointer"},children:i(I.InfoCircle,{size:20})})})]})}),EC=k.observer(({view:t})=>{const e=ge(),n=K(),r=Ke.useModals(),{panel:a}=Ae(),{id:o}=a,{inEditMode:l}=y.useContext(ft),{viewPanelInFullScreen:c,inFullScreen:u}=y.useContext(_i),d=()=>{n.duplicatePanelByID(o,t.id)},f=()=>{e.editor.open(["_VIEWS_",t.id,"_PANELS_",o])},h=()=>r.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>n.removePanelByID(o,t.id),confirmProps:{color:"red"},zIndex:320}),g=y.useCallback(()=>{c(o)},[o,c]),m=!u&&t.type!==H.Modal;return i(N,{children:i(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:p(s.Menu,{withinPortal:!0,children:[i(s.Menu.Target,{children:i(s.Box,{className:"panel-dropdown-target",sx:{width:"100%",height:"25px"}})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{onClick:a.refreshData,icon:i(I.Refresh,{size:14}),children:"Refresh"}),i(s.Menu.Item,{onClick:a.downloadData,icon:i(I.Download,{size:14}),children:"Download Data"}),m&&i(s.Menu.Item,{onClick:g,icon:i(I.ArrowsMaximize,{size:14}),disabled:l,children:"Full Screen"}),l&&p(N,{children:[i(s.Divider,{label:"Edit",labelPosition:"center"}),i(s.Menu.Item,{onClick:f,icon:i(I.Settings,{size:14}),children:"Settings"}),i(s.Menu.Item,{onClick:d,icon:i(I.Copy,{size:14}),children:"Duplicate"}),i(s.Menu.Item,{color:"red",onClick:h,icon:i(I.Trash,{size:14}),children:"Delete"})]})]})]})})})}),AC=k.observer(({panel:t})=>p(s.Stack,{children:[t.queryErrors.map((e,n)=>i(s.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:e},`${n}-${e}`)),t.queryStateMessages.map((e,n)=>i(s.Text,{color:"gray",align:"center",children:e},`${n}-${e}`))]}));var cl=(t=>(t.migrated="migrated",t.nothingToMigrate="nothingToMigrate",t.checkFailed="checkFailed",t.migrationFailed="migrationFailed",t))(cl||{}),Zn=(t=>(t.notStarted="notStarted",t.inProgress="inProgress",t.done="done",t))(Zn||{});class zC{constructor(e){V(this,"vizInstance");V(this,"operationManager");V(this,"triggerManager");V(this,"vizManager");V(this,"runningMigration");V(this,"panelModel");V(this,"status","notStarted");this.panelModel=e.getRequired(we.instanceScope.panelModel),this.vizInstance=e.getRequired(we.instanceScope.vizInstance),this.operationManager=e.getRequired(we.instanceScope.operationManager),this.triggerManager=e.getRequired(we.instanceScope.triggerManager),this.vizManager=e.getRequired(we.vizManager)}async createMigrationTask(){const e=[];try{await this.instanceNeedMigration()&&e.push(()=>this.runInstanceMigration()),await this.interactionNeedMigration()&&e.push(()=>this.runInteractionMigration())}catch(n){return console.warn("check migration failed",n),"checkFailed"}if(e.length===0)return"nothingToMigrate";try{return await Promise.all(e.map(n=>n())),"migrated"}catch(n){return console.warn("migration failed",n),"migrationFailed"}}async runMigration(){return this.runningMigration||(this.status="inProgress",this.runningMigration=this.createMigrationTask().then(e=>(this.status="done",e))),this.runningMigration}async runInteractionMigration(){await this.operationManager.runMigration(),await this.triggerManager.runMigration()}async runInstanceMigration(){const e=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData,panelModel:this.panelModel};await e.migrator.migrate(n)}async instanceNeedMigration(){const e=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData};return e.migrator.needMigration(n)}async interactionNeedMigration(){return await this.operationManager.needMigration()||await this.triggerManager.needMigration()}}function ul(t){const{panel:e}=Ae();return y.useCallback(n=>{const r=n.getRequired(we.vizManager),a=r.resolveComponent(t.viz.type);return n.createScoped().provideFactory(we.instanceScope.vizInstance,()=>r.getOrCreateInstance(t)).provideFactory(we.instanceScope.interactionManager,o=>{const l=o.getRequired(we.instanceScope.vizInstance);return new gi(l,a,Un)}).provideFactory(we.instanceScope.operationManager,o=>o.getRequired(we.instanceScope.interactionManager).operationManager).provideFactory(we.instanceScope.triggerManager,o=>o.getRequired(we.instanceScope.interactionManager).triggerManager).provideValue(we.instanceScope.panelModel,e).provideFactory(we.instanceScope.migrator,o=>new zC(o))},[t.viz.type,t.viz.conf])}function dl(t){const[e,n]=y.useState(!1),r=rl().getRequired(we.instanceScope.migrator);return J.useAsyncEffect(async()=>{const a=r.status===Zn.notStarted;n(r.status===Zn.done),r.status===Zn.notStarted&&r.runMigration().then(o=>{o===cl.migrated&&a&&(t==null||t())}).finally(()=>{n(!0)})},[r]),e}function pl(t,e){const n=rl().getRequired(we.instanceScope.vizInstance);return y.useEffect(()=>(n.instanceData.setItem(null,e.viz.conf),n.instanceData.watchItem(null,r=>{t(r)})),[t,e.viz.type]),n}function $C({setVizConf:t,...e}){const{panel:n}=e,r=pl(t,n),a=dl(()=>{hn.showNotification({title:`${n.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})});return J.useAsyncEffect(async()=>{await r.instanceData.setItem(null,n.viz.conf)},[r,n.viz.type]),a?i(Kc,{...e}):i(s.Text,{children:"Checking update..."})}function LC(t){const{panel:e,setVizConf:n}=t;pl(n,e);const{inEditMode:r}=y.useContext(ft);return dl(()=>{r&&hn.showNotification({title:`${e.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?i(Qc,{...t}):i(s.Text,{children:"Checking update"})}const KT="";function OC(t,e){const{vizManager:n}=y.useContext(it),{panel:{viz:r,title:a,id:o,description:l,queryIDs:c,variables:u}}=Ae(),d={title:a,id:o,description:l,queryIDs:c,viz:r,layout:e},f=ul(d);try{return n.resolveComponent(r.type),i(Jn,{configure:f,children:i(LC,{setVizConf:r.setConf,panel:d,data:t,variables:u,vizManager:n})})}catch(h){return console.info(x.get(h,"message")),null}}const PC=k.observer(function({data:e}){const{ref:n,width:r,height:a}=Ie.useElementSize(),o=OC(e,{w:r,h:a});return i("div",{className:"viz-root",ref:n,children:r&&a&&i(Fe,{children:o})})}),hl=k.observer(({panel:t,height:e})=>p(s.Flex,{direction:"column",sx:{height:e,position:"relative",width:"100%"},children:[i(s.LoadingOverlay,{visible:t.dataLoading,exitTransitionDuration:0}),!t.canRenderViz&&i(AC,{panel:t}),t.canRenderViz&&i(PC,{data:t.data})]})),UT="",BC=k.observer(function(){const{panel:e}=Ae(),{title:n}=e;return n?i(s.Group,{grow:!0,position:"center",px:20,className:"panel-title-wrapper",sx:{flexGrow:1},children:i(s.Text,{align:"center",lineClamp:1,weight:"bold",children:n})}):null});function VC(t){return!["richText","button"].includes(t)}const NC={border:"1px solid #e9ecef"},qC={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function FC(t,e){return t.style.border.enabled?NC:e?qC:{border:"1px dashed transparent"}}const Hn=k.observer(function({panel:e,view:n}){const{inEditMode:r}=y.useContext(ft),a=e.title?"calc(100% - 25px - 5px)":"100%",o=FC(e,r),c=VC(e.viz.type)||r;return i(wr,{value:{panel:e,data:e.data,loading:e.dataLoading,errors:e.queryErrors},children:p(s.Box,{className:"panel-root",p:5,pt:0,sx:{...o},children:[i(s.Box,{sx:{position:"absolute",left:0,top:0,height:28,zIndex:310},children:i(ll,{})}),c&&i(EC,{view:n}),i(BC,{}),i(hl,{panel:e,height:a})]})})}),XT="",GC=y.forwardRef(({h:t},e)=>i(s.ActionIcon,{ref:e,className:"react-grid-customDragHandle",sx:{userSelect:"none",cursor:"grab",position:"absolute",top:5,right:t>38?5:20,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",children:i(I.ArrowsMove,{size:16})})),WC=y.forwardRef(({handleAxis:t,...e},n)=>i(s.ActionIcon,{ref:n,className:"react-grid-customResizeHandle",sx:{userSelect:"none",cursor:"nwse-resize",position:"absolute",bottom:0,right:0,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",...e,children:i(I.ChevronDownRight,{size:16})})),RC=fn.WidthProvider(fn),jC=k.observer(({view:t,className:e="layout"})=>{const n=K(),{panels:r,layouts:a}=n.panels.panelsByIDs(t.panelIDs),o=y.useCallback(c=>{c.forEach(({i:u,...d})=>{const f=n.panels.findByID(u);f&&f.layout.set(d)})},[n]),l=(c,u,d,f)=>{d.h<30&&(d.h=30,f.h=30),d.w<4&&(d.w=4,f.w=4)};return i(RC,{onLayoutChange:o,className:`dashboard-layout ${e}`,rowHeight:1,cols:36,margin:[0,0],isBounded:!0,isDraggable:!0,isResizable:!0,layout:a,draggableHandle:".react-grid-customDragHandle",resizeHandle:i(WC,{}),onResize:l,children:r.map((c,u)=>p("div",{"data-grid":{...c.layout},className:"panel-grid-item",children:[i(GC,{h:c.layout.h}),i(Hn,{view:t,panel:c})]},c.id))})}),YC=fn.WidthProvider(fn),QC=k.observer(function({view:e,className:n="layout"}){const{panels:r,layouts:a}=K().panels.panelsByIDs(e.panelIDs);return i(YC,{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(Hn,{view:e,panel:o})},o.id))})}),KC=k.observer(({children:t})=>i(s.Box,{pt:10,pb:100,children:t})),UC=k.observer(({children:t,view:e})=>{const n=e.config;return i(s.Modal,{size:n.width,overflow:"inside",opened:!0,onClose:x.noop,withCloseButton:!1,title:n.custom_modal_title.value,trapFocus:!0,onDragStart:r=>{r.stopPropagation()},styles:{root:{position:"relative",height:"100%"},overlay:{position:"absolute !important"},modal:{border:"1px solid #efefef"},body:{maxHeight:"calc(100vh - 325px)"}},withinPortal:!1,transitionDuration:0,children:t})}),XC=({variant:t,orientation:e})=>{const n={tab:{},panel:{padding:"16px"}};return t==="pills"&&e==="horizontal"&&(n.tab.paddingTop="6px",n.tab.paddingBottom="6px"),e==="vertical"&&(n.tab["&.add-a-tab"]={paddingTop:"1px",paddingBottom:"1px"},n.tab["&.add-a-tab .mantine-Tabs-tabLabel"]={marginLeft:"auto",marginRight:"auto"}),n},JC=t=>t.color?{"&[data-active], &[data-active]:hover":{borderColor:t.color?t.color:"..."}}:{},ZC=k.observer(({children:t,view:e})=>{const n=Ke.useModals(),r=K(),a=y.useMemo(()=>r.views.options.filter(u=>u.type===H.Division),[e.id,r.views.options]),o=e.config,l=u=>n.openConfirmModal({title:"Delete this tab?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{o.removeTab(u)},confirmProps:{color:"red"},zIndex:320}),c=o.tabs.length===0;return p(s.Box,{className:"preview-view-tabs",children:[p(s.Tabs,{variant:o.variant,orientation:o.orientation,defaultValue:o.tabs.length>0?o.tabs[0].id:"0",styles:XC(o),children:[p(s.Tabs.List,{grow:o.grow,children:[o.tabs.map(u=>i(s.Tabs.Tab,{value:u.id,sx:JC(u),children:u.name??u.id},u.id)),i(s.Tabs.Tab,{onClick:o.addTab,value:"add",className:"add-a-tab",children:i(I.Plus,{size:18,color:"#228be6"})})]}),o.tabs.map((u,d)=>{const f=r.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:h=>u.setName(h.currentTarget.value)}),i(s.Select,{label:"View",value:u.view_id,onChange:u.setViewID,data:a}),i(s.ColorInput,{label:"Color",value:u.color,onChange:u.setColor,disabled:o.variant!=="default"}),f&&p(s.Button,{mt:20,variant:"gradient",leftIcon:i(L.IconArrowsLeftRight,{size:18}),gradient:{from:"cyan",to:"indigo"},onClick:()=>r.views.setIDOfVIE(f.id),children:["Swith to View: ",f.name]}),i(s.Button,{mt:20,variant:"subtle",color:"red",onClick:()=>l(d),disabled:c,leftIcon:i(L.IconTrash,{size:14}),children:"Delete This Tab"})]})]}),f&&i(er,{view:f})]},u.id)})]}),t]})}),HC=k.observer(({view:t,children:e})=>{switch(t.type){case H.Modal:return i(UC,{view:t,children:e});case H.Tabs:return i(ZC,{view:t,children:e});case H.Division:default:return i(KC,{children:e})}}),fl=k.observer(function({view:e}){return i(_i.Provider,{value:{viewPanelInFullScreen:x.noop,inFullScreen:!1},children:i(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:i(HC,{view:e,children:p(s.Box,{sx:{position:"relative"},children:[i(s.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:i(ol,{view:e})}),i(jC,{view:e})]})})})})}),e1={modal:{display:"flex",flexDirection:"column",flexWrap:"nowrap"},body:{display:"flex",height:"calc(100vh - 88px)"}},t1=k.observer(function({view:e,panel:n,exitFullScreen:r}){return i(s.Modal,{opened:!0,fullScreen:!0,onClose:r,title:i(s.Button,{color:"blue",size:"xs",onClick:r,leftIcon:i(I.ArrowLeft,{size:20}),children:"Exit fullscreen"}),styles:e1,children:i(s.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:i(Hn,{view:e,panel:n})})})});function n1(t,e,n){const{panels:r}=K(),a=t.id==="Main",[o,l]=y.useState(()=>a&&r.findByID(e)?e:null),c=y.useCallback(h=>{l(h),a&&n(h)},[a,n]),u=y.useCallback(()=>{l(null),a&&n("")},[a,n]),d=o?r.findByID(o):null;return{viewPanelInFullScreen:c,exitFullScreen:u,inFullScreen:!!d,fullScreenPanel:d}}const r1=k.observer(({children:t})=>i(s.Box,{children:t})),i1=k.observer(({children:t,view:e})=>{const n=K(),r=e.config,a=n.views.visibleViewIDs.includes(e.id),o=()=>n.views.rmVisibleViewID(e.id);return i(s.Modal,{size:r.width,centered:!0,overflow:"inside",opened:a,onClose:o,withCloseButton:!1,title:r.custom_modal_title.value,trapFocus:!0,onDragStart:l=>{l.stopPropagation()},styles:{modal:{border:"1px solid #efefef"},body:{maxHeight:r.height,overflow:"auto"}},transitionDuration:0,children:t})}),a1=t=>t.color?{"&[data-active], &[data-active]:hover":{borderColor:t.color?t.color:"..."}}:{},s1=k.observer(({children:t,view:e})=>{const n=K(),r=e.config;return p(s.Box,{className:"render-view-tabs",children:[p(s.Tabs,{variant:r.variant,orientation:r.orientation,defaultValue:r.tabs.length>0?r.tabs[0].id:"0",styles:{panel:{padding:r.orientation==="horizontal"?"16px 0px":"0"}},keepMounted:!1,children:[i(s.Tabs.List,{grow:r.grow,children:r.tabs.map(a=>i(s.Tabs.Tab,{value:a.id,sx:a1(a),disabled:!a.view_id,children:a.name??a.id},a.id))}),r.tabs.map(a=>{const o=n.views.findByID(a.view_id);return o?i(s.Tabs.Panel,{value:a.id,children:i(er,{view:o})},a.id):null})]}),t]})}),o1=k.observer(({view:t,children:e})=>{switch(t.type){case H.Modal:return i(i1,{view:t,children:e});case H.Tabs:return i(s1,{view:t,children:e});case H.Division:default:return i(r1,{children:e})}}),er=k.observer(function({view:e}){const{fullScreenPanelID:n,setFullScreenPanelID:r}=bs(),{viewPanelInFullScreen:a,exitFullScreen:o,inFullScreen:l,fullScreenPanel:c}=n1(e,n,r);return i(_i.Provider,{value:{viewPanelInFullScreen:a,inFullScreen:l},children:p(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:[l&&i(t1,{view:e,panel:c,exitFullScreen:o}),i(o1,{view:e,children:p(s.Box,{sx:{position:"relative"},children:[!l&&i(s.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:i(ol,{view:e})}),!l&&i(QC,{view:e})]})})]})})});function ki(t){return y.useCallback(e=>e.provideValue(we.pluginManager,t.pluginManager).provideValue(we.vizManager,t.vizManager).provideValue(we.colorManager,t.colorManager),[])}const l1=k.observer(({headerMenuItems:t=null})=>{const e=ge(),n=K(),r=()=>{const a=JSON.stringify(n.json,null,2),o=`${e.name}__${n.name}`;kc(o,a)};return p(s.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:310,children:[i(s.Menu.Target,{children:i(s.ActionIcon,{variant:"light",color:"blue",children:i(L.IconMenu2,{size:14})})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{icon:i(L.IconDownload,{size:14}),onClick:n.queries.downloadAllData,children:"Download Data"}),i(s.Menu.Item,{icon:i(L.IconCode,{size:14}),onClick:r,children:"Download Schema"}),t]})]})}),c1=k.observer(({saveDashboardChanges:t})=>{const e=Ke.useModals(),n=K(),r=()=>{e.openConfirmModal({title:p(s.Group,{position:"left",children:[i(L.IconAlertTriangle,{size:18,color:"red"}),i(s.Text,{children:"You are reverting changes"})]}),labels:{confirm:"Confirm",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:()=>n.reset(),zIndex:320,withCloseButton:!1})},a=n.changed;return p(s.Group,{spacing:0,children:[i(s.Button,{color:"green",variant:"filled",size:"xs",leftIcon:i(L.IconDeviceFloppy,{size:18}),onClick:t,disabled:!a,sx:{borderTopRightRadius:0,borderBottomRightRadius:0},children:"Save Changes"}),p(s.Menu,{width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:320,disabled:!a,children:[i(s.Menu.Target,{children:i(s.ActionIcon,{variant:"default",disabled:!a,sx:{height:"30px",borderTopLeftRadius:0,borderBottomLeftRadius:0,svg:{fill:"rgb(173, 181, 189)",stroke:"none"}},children:i(L.IconCaretDown,{size:18})})}),i(s.Menu.Dropdown,{children:i(s.Menu.Item,{icon:i(L.IconRecycle,{size:14,color:"red"}),disabled:!a,onClick:r,children:"Revert Changes"})})]})]})}),u1=k.observer(({saveDashboardChanges:t,headerSlot:e=null,headerMenuItems:n})=>{const r=Zl.useNavigate(),a=ge(),o=()=>{r(`/dashboard/${a.id}`)},l=Ke.useModals(),c=()=>{l.openConfirmModal({title:p(s.Group,{position:"left",children:[i(L.IconAlertTriangle,{size:18,color:"red"}),i(s.Text,{children:"There are unsaved changes"})]}),labels:{confirm:"Discard",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:o,zIndex:320,withCloseButton:!1})},u=a.content.changed;return i(s.Header,{height:60,px:"md",py:0,sx:{zIndex:299},children:p(s.Group,{position:"apart",sx:{height:60,minWidth:"1000px",position:"relative"},children:[p(s.Group,{children:[i(s.Button,{size:"xs",color:u?"red":"green",leftIcon:i(L.IconArrowLeft,{size:20}),onClick:u?c:o,children:p(s.Group,{spacing:4,children:["End Editing",i(s.Text,{td:"underline",children:a.name})]})}),i(c1,{saveDashboardChanges:t})]}),p(s.Group,{position:"right",sx:{flexGrow:1},children:[e,i(l1,{headerMenuItems:n})]})]})})}),d1={position:"fixed",top:60,left:0,right:0,height:30,zIndex:299,borderBottom:"1px solid #e9ecef",background:"rgba(233,236,239, 0.15)"},p1=k.observer(()=>{const t=K();return i(s.Box,{sx:d1,pl:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},children:p(s.Group,{position:"apart",align:"center",sx:{height:"30px"},pr:16,children:[i(s.Button,{variant:"outline",color:"blue",radius:0,size:"xs",disabled:!t.views.VIE,onClick:()=>t.addANewPanel(t.views.idOfVIE),leftIcon:i(L.IconPlaylistAdd,{size:20}),sx:{height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef",background:"rgb(231, 245, 255)"},children:"Add a Panel"}),i(s.Box,{}),i(s.Box,{})]})})}),h1=k.observer(t=>p(N,{children:[i(u1,{...t}),i(p1,{})]})),JT="",ZT="";function f1(t,e,n){const r=[];return t.filter(a=>"__INTERACTIONS"in a.viz.conf).forEach((a,o)=>{const l=e[a.id];l.data.interactions=x.get(l,"data.interactions",[]);const{__INTERACTIONS:c,__OPERATIONS:u,__TRIGGERS:d}=a.viz.conf;Object.entries(u).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 g1(t,e){const n=t.filters.keyLabelMap;return{edges:f1(t.panels.list,e,n),edgeNodes:[]}}function gl(t,e,n){return t*e+t*n}function m1(t,e,n){return t*e+(t-1)*n}const tr=25,Ti=40,ml=25,Di=350,y1=150,b1=150,yl=150,bl=300,nr=40,vl=25,v1=300;function x1(t,e){const n=x.keyBy(e,a=>a.id),r=[];return t.current.forEach((a,o)=>{a.panelIDs.forEach((l,c)=>{const u=gl(c,nr,vl)+Ti,d=n[l];if(!d){r.push({id:l,_node_type:"panel",parentNode:a.id,data:{label:`!: ${l}`},position:{x:tr,y:u},sourcePosition:Me.Position.Right,targetPosition:Me.Position.Left,style:{width:bl,height:nr}});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:tr,y:u},sourcePosition:Me.Position.Right,targetPosition:Me.Position.Left,style:{width:bl,height:nr}})})}),r}const w1={[H.Division]:"Div",[H.Modal]:"Modal",[H.Tabs]:"Tabs"},C1=Ko;function S1(t){return t.current.map((n,r)=>{const a=m1(n.panelIDs.length,nr,vl)+Ti+ml;let o=[];return n.type===H.Tabs&&(o=n.config.tabs.map(c=>c.view_id)),{id:n.id,_node_type:"view-root",_view_type:n.type,_view_level:0,_sub_view_ids:[],_tab_view_ids:o,data:{label:`${w1[n.type]}:${n.name}`},position:{x:0,y:0},sourcePosition:Me.Position.Right,targetPosition:Me.Position.Left,className:"light",style:{backgroundColor:C1[n.type],width:Di,height:a}}})}function _1(t){const e=x.keyBy(t,n=>n.id);t.forEach(n=>{n._node_type!=="view-root"||n._view_type!==H.Tabs||n._tab_view_ids.forEach(r=>{e[r].parentNode=n.id})})}function k1(t){const e=S1(t.views);_1(e);const n=x1(t.views,t.panels.list);return[...e,...n]}function T1({nodeMap:t,nodes:e,edges:n}){e.forEach(r=>{r._node_type!=="view-root"||r._view_type!==H.Tabs||(r.sourcePosition=Me.Position.Bottom,r.style.width=Di+tr*2,r.style.height=ml+r._tab_view_ids.reduce((a,o)=>{const l=t[o];l.position.y=a,l.position.x=tr;const c=l.style.height;return a+c+20},Ti))})}function D1({nodeMap:t,nodes:e,edges:n}){n.filter(r=>r.label==="Open View").forEach(r=>{const a=t[r.source],o=t[r.target];if(!a||!o||!a.parentNode)return;const l=t[a.parentNode];l._node_type!=="view-root"||o._node_type!=="view-root"||(o._view_level+=1+l._view_level,l._sub_view_ids.push(o.id))}),e.sort((r,a)=>r._node_type==="view-root"&&a._node_type==="view-root"?r._view_level-a._view_level:r._node_type!=="view-root"&&a._node_type!=="view-root"?0:r._node_type==="view-root"?-1:1)}function I1({nodeMap:t,nodes:e,edges:n}){const r={};n.forEach(a=>{if(a.label!=="Open View")return;const o=t[a.source],l=t[a.target];if(o&&l&&o.parentNode){const c=t[o.parentNode],u=c.position.x,d=Number(x.get(l,"style.height",0)),f=Number(c.style.width);l.position.x=u+f+v1,c._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+yl}})}function M1({nodeMap:t,nodes:e,edges:n}){const r=new Set,a=new Set;n.forEach(l=>{r.add(l.source),a.add(l.target)}),e.filter(l=>l._node_type!=="view-root"||l.id==="Main"||l.parentNode?!1:!r.has(l.id)&&!a.has(l.id)).forEach((l,c)=>{l.position.x=gl(c,Di,b1),l.position.y=0-y1-yl})}function E1({nodeMap:t,nodes:e,edges:n}){const r={nodeMap:t,nodes:e,edges:n};return M1(r),D1(r),T1(r),I1(r),{nodes:e,edges:n}}function A1(t){const e=k1(t),n=x.keyBy(e,u=>u.id),{edges:r,edgeNodes:a}=g1(t,n),o=[...e,...a],l=x.keyBy(o,u=>u.id),c={edges:x.uniqBy(r,u=>u.id),nodes:o,nodeMap:l};return E1(c)}const HT="",Ii={"builtin:op:open-link":i(s.ThemeIcon,{color:"blue",size:20,radius:"xl",children:i(L.IconCircleDashed,{size:14})}),"builtin:op:set_filter_values":i(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:i(L.IconCircleDot,{size:14})}),"builtin:op:clear_filter_values":i(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:i(L.IconCircleOff,{size:14})})};function z1(t){const e=[];return t.forEach(n=>{switch(n.schemaRef){case"builtin:op:open-link":e.push({key:n.urlTemplate,icon:Ii[n.schemaRef],text:p(s.Group,{spacing:4,children:[i(s.Text,{children:"Open: "}),i(s.Text,{color:"dimmed",children:n.shortURLTemplate})]})});return;case"builtin:op:set_filter_values":n.filters.forEach(({key:r,label:a})=>{e.push({key:n.schemaRef+r,icon:Ii[n.schemaRef],text:i(s.Group,{spacing:4,children:p(s.Text,{children:["Set Filter: ",a]})})})});return;case"builtin:op:clear_filter_values":n.filters.forEach(({key:r,label:a})=>{e.push({key:n.schemaRef+r,icon:Ii[n.schemaRef],text:i(s.Group,{spacing:4,children:p(s.Text,{children:["Clear Filter: ",a]})})})});return}}),e}const $1=y.memo(({data:t,isConnectable:e,sourcePosition:n=Me.Position.Right,targetPosition:r=Me.Position.Left,...a})=>{const o=y.useMemo(()=>z1(t.interactions),[t.interactions]);return p(N,{children:[i(Me.Handle,{type:"target",position:r,isConnectable:e}),i(s.Box,{sx:{position:"absolute",top:0,right:0},children:i(I.ChevronsUpRight,{size:12})}),p(s.HoverCard,{shadow:"xl",withinPortal:!0,children:[i(s.HoverCard.Target,{children:i(s.Text,{children:t.label})}),i(s.HoverCard.Dropdown,{children:i(s.List,{spacing:"xs",size:"sm",center:!0,children:o.map(l=>i(s.List.Item,{icon:l.icon,children:l.text},l.key))})})]}),i(Me.Handle,{type:"source",position:n,isConnectable:e})]})}),eD="",L1={interaction:$1},O1=k.observer(()=>{const t=K(),{edges:e,nodes:n}=A1(t);return p(Me,{nodes:n,edges:e,onNodesChange:x.noop,onEdgesChange:x.noop,onConnect:x.noop,className:"interactions-viewer",fitView:!0,nodeTypes:L1,children:[i(Me.MiniMap,{}),i(Me.Controls,{}),i(Me.Background,{})]})}),P1=k.observer(({opened:t,close:e})=>{const{freezeLayout:n}=y.useContext(ft);return y.useEffect(()=>{n(t)},[t]),i(s.Modal,{size:"96vw",overflow:"inside",opened:t,onClose:e,title:"Interactions",trapFocus:!0,onDragStart:r=>{r.stopPropagation()},styles:{body:{height:"90vh"},modal:{transform:"none !important"}},zIndex:300,children:i(O1,{})})}),B1={"> 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 V1({onClick:t,name:e,active:n,openSettings:r}){return p(s.Box,{sx:{position:"relative"},children:[i(s.UnstyledButton,{sx:a=>({display:"block",width:"100%",padding:a.spacing.xs,borderRadius:0,position:"relative",color:a.black,"&:hover":{backgroundColor:a.colors.gray[0]},backgroundColor:n?a.colors.gray[2]:"transparent"}),children:i(s.Group,{sx:{width:"calc(100% - 28px)"},onClick:t,children:i(s.Text,{size:"sm",children:e})})}),n&&i(s.Tooltip,{label:"Edit",position:"right",withinPortal:!0,children:i(s.ActionIcon,{onClick:r,variant:"light",color:"blue",sx:{position:"absolute",top:0,bottom:0,height:"100%",right:0,zIndex:0,borderRadius:0},children:i(L.IconAdjustments,{size:16})})})]})}const N1=k.observer(()=>{const t=ge(),e=K(),n=y.useCallback(a=>()=>e.views.setIDOfVIE(a),[e]),r=a=>{t.editor.open(["_VIEWS_",a])};return p(s.Box,{sx:{position:"relative"},children:[e.views.options.map(a=>i(V1,{active:e.views.idOfVIE===a.value,name:a.label,onClick:n(a.value),openSettings:()=>r(a.value)},a.value)),i(s.Divider,{variant:"dashed"}),i(s.Button,{variant:"subtle",rightIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",color:"blue",onClick:e.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"space-between"}},children:"Add a View"})]})}),q1=k.observer(()=>{const t=ge(),e=K(),n=()=>{if(!e.queries.firstID){t.editor.open(["_QUERIES_",""]);return}t.editor.open(["_QUERIES_",e.queries.firstID])},r=()=>{if(!e.filters.firstID){t.editor.open(["_FILTERS_",""]);return}t.editor.open(["_FILTERS_",e.filters.firstID])},[a,o]=y.useState(!1),l=()=>o(!0),c=()=>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:{...B1,button:{borderWidth:0,borderBottomWidth:1,borderColor:"#e9ecef"}},children:[i(s.Tooltip,{label:"Filters",withinPortal:!0,children:i(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:r,children:i(L.IconFilter,{size:20})})}),i(s.Tooltip,{label:"Queries",withinPortal:!0,children:i(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:n,children:i(L.IconDatabase,{size:20})})}),i(s.Tooltip,{label:"Interactions Viewer",withinPortal:!0,children:i(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:l,children:i(L.IconLink,{size:20})})})]}),i(P1,{opened:a,close:c})]}),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(N1,{})}),i(s.Navbar.Section,{children:i(s.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:i(s.Button,{size:"xs",leftIcon:i(L.IconSettings,{size:20}),onClick:()=>t.editor.open([]),children:"Settings"})})})]})}),F1=k.observer(function({config:e}){return p(N,{children:[i(s.Checkbox,{checked:e.default_value,onChange:n=>e.setDefaultValue(n.currentTarget.checked),label:"Default Checked"}),i(ri,{label:"Description",value:e.description,onChange:e.setDescription,styles:{root:{flexGrow:1,minHeight:"400px"}}})]})}),G1=[{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"}],W1=k.observer(function({config:e}){return p(N,{children:[p(s.Group,{children:[i(s.Checkbox,{checked:e.required,onChange:n=>e.setRequired(n.currentTarget.checked),label:"Required"}),i(s.Checkbox,{checked:e.clearable,onChange:n=>e.setClearable(n.currentTarget.checked),disabled:e.max_days>0,label:"Clearable"}),i(s.Checkbox,{checked:e.allowSingleDateInRange,onChange:n=>e.setAllowSingleDateInRange(n.currentTarget.checked),label:"Allow choosing 1 day"})]}),i(s.Select,{data:G1,label:"Display Format",value:e.inputFormat,onChange:e.setInputFormat}),i(il,{label:"Default Value",config:e,value:e.default_value,onChange:e.setDefaultValue}),i(s.NumberInput,{label:"Max Days",description:p(s.Group,{position:"apart",children:[i(s.Text,{children:"Set 0 to disable."}),p(s.Group,{spacing:4,children:[i(s.Text,{children:"This feature requires"}),i(s.Text,{color:"blue",children:"Clearable"}),i(s.Text,{children:"to be checked"})]})]}),min:0,value:e.max_days,onChange:e.setMaxDays,hideControls:!0})]})}),Mi=k.observer(({value:t,onChange:e})=>{const n=K(),r=y.useMemo(()=>n.queries.options,[n.queries.current]),a=r.length===0;return i(s.Select,{label:"Pick a query",data:r,value:t,onChange:e,allowDeselect:!1,clearable:!0,sx:{flexGrow:1},disabled:a,error:a?"You need to add a query in Data Settings":void 0})}),R1=`
|
|
479
|
+
`}},show_in_legend:!0}))}function c0(t,e,n,r){const a=q(e.data_key),o=e.name,l=n.map(u=>{const c=x.sumBy(r[u],a.columnKey);return[u,c]});return{type:"line",name:o,xAxisIndex:3,yAxisIndex:3,color:"#b41529",data:l,show_in_legend:!1}}function d0(t,e,n,r){const l={barMinWidth:5,barMaxWidth:20};return[a0(t,n,r),o0(t,n,r,l),...u0(t,n,r,l),c0(t,e,n,r)]}function p0(t,e){const{axisLabel:n}=t.x_axis;return[{data:e,id:"准确估算比例",gridIndex:0,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:e,id:"平均偏差",gridIndex:1,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!0,lineStyle:{color:"#FFFFFF",width:2}},type:"category"},{data:e,id:"数量占比",gridIndex:2,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:e,id:"代码当量",gridIndex:3,axisTick:{show:!1},type:"category",axisLabel:{...n,formatter:Ns(n.formatter)},axisLine:{show:!1}}]}function h0(t){return[{type:"category",name:"准确估算比例",nameRotate:0,nameGap:5,nameLocation:"end",nameTextStyle:{align:"left"},gridIndex:0,axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:"平均偏差",nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:1,boundaryGap:[1,1],axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:"数量占比",nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:2,axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1},min:0,max:1},{type:"value",gridIndex:3,position:"right",splitNumber:3,axisLabel:{show:!0,verticalAlign:"top",showMinLabel:!1,lineHeight:14},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:t.name,nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:3,position:"left",axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}}]}function hi(t){return t==1||t==2?1:hi(t-2)+hi(t-1)}const f0=Array.from(new Array(20),(t,e)=>hi(e+1));function Bo(t){return t<=1?t:f0.findIndex(e=>t<=e)-1}function g0(t,e){const{x_axis:n,deviation:r}=t,a=q(n.data_key),o=q(r.data_keys.estimated_value),l=q(r.data_keys.actual_value);return e[a.queryID].map(u=>{const c=Bo(u[o.columnKey]),d=Bo(u[l.columnKey]),f=c-d;return{...u,level:{estimated:c,actual:d,diff:f}}})}function m0(t){return t==="rgba(255, 255, 255, 1)"?{borderColor:"rgba(0,0,0,.1)",borderWidth:1}:{}}function y0(t){return{show:!0,orient:"vertical",top:"middle",right:0,data:t.filter(n=>n.show_in_legend).reverse().map(n=>({name:`${n.name}`,color:n.color,itemStyle:m0(n.color)})),tooltip:{show:!0,formatter:"档位偏差:{a}"}}}const b0={tooltip:{trigger:"axis"}};function v0(t,e){const{deviation:n,metrics:r}=t,a=r.find(l=>l.data_key===e);if(a)return a;const o=n.data_keys.actual_value;return{id:o,name:n.name,data_key:o}}function x0(t,e,n){const r=g0(t,n),a=q(t.x_axis.data_key),o=x.uniqBy(n[a.queryID],a.columnKey).map(f=>f[a.columnKey]),l=x.groupBy(r,a.columnKey),u=v0(t,e),c=d0(t,u,o,l),d={xAxis:p0(t,o),yAxis:h0(u),series:c,grid:i0(),visualMap:[{min:0,max:1,calculable:!0,show:!1,seriesIndex:0,color:["#F0F0F0","#418AAF"]}],legend:y0(c)};return x.defaultsDeep({},d,b0)}const w0={input:{border:"none !important",paddingLeft:0,lineHeight:"1.55 !important"}},C0=({conf:t,metricKey:e,setMetricKey:n})=>{const{deviation:r,metrics:a}=t,o=y.useMemo(()=>{const l=a.map(u=>({label:u.name,value:u.data_key}));return l.push({label:r.name?r.name:r.data_keys.actual_value,value:r.data_keys.actual_value}),l},[r,a]);return h(s.Group,{spacing:1,children:[i(s.Text,{size:12,color:"dimmed",sx:{cursor:"default",userSelect:"none"},children:"基线指标"}),i(s.NativeSelect,{size:"xs",data:o,value:e,onChange:l=>n(l.currentTarget.value),styles:w0})]})},S0={"tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function _0(){return h(s.HoverCard,{width:400,shadow:"md",children:[i(s.HoverCard.Target,{children:i(s.Button,{size:"xs",variant:"subtle",compact:!0,leftIcon:i(L.IconInfoCircle,{size:14}),children:"指标说明"})}),i(s.HoverCard.Dropdown,{children:i(s.Table,{fontSize:14,sx:S0,children:h("tbody",{children:[h("tr",{children:[i("th",{children:"估算偏差"}),i("td",{children:"使用斐波那契数列(1,2,3,5,8,13)估算故事点,每个数位为一个档位,计算issue实际故事点与估算故事点的档位偏差,即为估算偏差。如估算故事点为5,实际故事点为8,则估算偏差为-1。"})]}),h("tr",{children:[i("th",{children:"准确估算比例"}),i("td",{children:"偏差在 ± 1 档位内的 issue 均为准确估算,以此计算准确估算的比例。"})]})]})})})]})}function k0(t){return h(s.Group,{position:"apart",children:[i(_0,{}),i(C0,{...t})]})}ue.use([he.BarChart,he.LineChart,he.HeatmapChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer,G.VisualMapComponent]);function T0({conf:t,data:e,width:n,height:r,metricKey:a}){const o=y.useMemo(()=>x0(t,a,e),[t,e,a]);return i(Ne,{echarts:ue,option:o,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})}function D0({context:t}){const{value:e}=R(t.instanceData,"config"),n=y.useMemo(()=>x.defaults({},e,pi),[e]),r=t.data,{width:a,height:o}=t.viewport,{x_axis:l,deviation:u}=n,{estimated_value:c,actual_value:d}=u.data_keys,[f,p]=y.useState(d);if(y.useEffect(()=>{p(C=>C||d)},[d]),!l.data_key||!c||!d||!a||!o)return null;const g=Math.max(a,300),m=Math.max(o,370);return h(s.Box,{sx:{overflow:"hidden",height:m,width:g},children:[i(k0,{conf:n,metricKey:f,setMetricKey:p}),i(T0,{width:g,height:m-30,data:r,conf:n,metricKey:f})]})}function I0({control:t,watch:e}){return e(["deviation"]),h(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"deviation.name",control:t,render:({field:n})=>i(s.TextInput,{label:"指标名称",sx:{flex:1},...n})})}),h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"deviation.data_keys.estimated_value",control:t,render:({field:n})=>i(j,{label:"估算值字段",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"deviation.data_keys.actual_value",control:t,render:({field:n})=>i(j,{label:"实际值字段",required:!0,sx:{flex:1},...n})})]})]})}const M0=({control:t,index:e,remove:n})=>h(s.Stack,{children:[h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`metrics.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`metrics.${e}.data_key`,control:t,render:({field:r})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),E0=({control:t,watch:e})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"metrics"}),o=e("metrics"),l=n.map((p,g)=>({...p,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=e("metrics.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(p=>p!==null?p:c)},[c]),h(N,{children:[h(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(I.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"设置可以展示在基线图的指标,例如代码当量"})]}),i(s.Divider,{variant:"dashed",my:10}),h(s.Tabs,{value:d,onTabChange:p=>f(p),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[h(s.Tabs.List,{children:[l.map((p,g)=>i(s.Tabs.Tab,{value:p.id,children:p.name?p.name:g},p.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((p,g)=>i(s.Tabs.Panel,{value:p.id,children:i(M0,{control:t,index:g,remove:a},p.id)},p.id))]})]})};function A0({control:t,watch:e}){return e(["x_axis"]),h(s.Stack,{children:[h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>i(j,{label:"数据字段",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"X轴名称",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"点位文案",labelPosition:"center"}),h(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"旋转",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"度"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Gs,{...n})})]})]})}function z0({context:t}){const{value:e,set:n}=R(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,pi),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l([]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,r),[d,r]);return i(s.Stack,{spacing:"xs",children:h("form",{onSubmit:o(n),children:[h(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Merico Estimation Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(I.DeviceFloppy,{size:20})})]}),h(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"12px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[h(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(A0,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Deviation",children:i(I0,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Additional Metrics",children:i(E0,{control:a,watch:l})})]})]})})}function $0(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,deviation:o,metrics:l,...u}=t;return{...u,x_axis:{...a,data_key:r(a.data_key)},deviation:{...o,data_keys:{estimated_value:r(o.data_keys.estimated_value),actual_value:r(o.data_keys.actual_value)}},metrics:l.map(c=>({...c,data_key:r(c.data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class L0 extends ve{constructor(){super(...arguments);V(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:$0(a,r)}})}}const O0={displayName:"Merico Estimation Chart",displayGroup:"Merico suite",migrator:new L0,name:"mericoEstimationChart",viewRender:D0,configRender:z0,createConfig:()=>({version:2,config:pi})},P0=[{value:"#25262B",name:"Dark"},{value:"#868E96",name:"Gray"},{value:"#FA5252",name:"Red"},{value:"#E64980",name:"Pink"},{value:"#BE4BDB",name:"Grape"},{value:"#7950F2",name:"Violet"},{value:"#4C6EF5",name:"Indigo"},{value:"#228BE6",name:"Blue"},{value:"#15AABF",name:"Cyan"},{value:"#12B886",name:"Teal"},{value:"#40C057",name:"Green"},{value:"#82C91E",name:"Lime"},{value:"#FAB005",name:"Yellow"},{value:"#FD7E14",name:"Orange"}].map(t=>({name:t.name,value:t.value,type:"single",category:"basic"})),B0=[Xu,Ju,ec,Hu,Zu,tc],Vo=()=>({id:"dashboard",version:ms,manifest:{viz:[bi,sv,Ov,By,Iv,ug,r0,pc,Ed,qh,yf,yx,Xf,yh,Kb,Dg,nm,Wv,O0,Rd],color:[...P0,...B0]}}),sn=new ac,we={pluginManager:st("pluginManager"),vizManager:st("vizManager"),colorManager:st("colorManager"),instanceScope:{panelModel:st("panelModel"),vizInstance:st("vizInstance"),interactionManager:st("interactionManager"),migrator:st("migrator"),operationManager:st("operationManager"),triggerManager:st("triggerManager")}},fi=()=>{try{sn.install(Vo())}catch{}const t=new Qu(sn),e=new ic(sn);return{pluginManager:sn,vizManager:t,colorManager:e}},it=y.createContext(fi());try{sn.install(Vo())}catch{}function V0(t,e){const{value:n,set:r}=R(t.operation.operationData,"config"),[a,o]=y.useState(x.defaults({},n,e)),l=async()=>{await r(a)};return y.useEffect(()=>{o(x.defaults({},n,e))},[n]),{config:a,setConfig:o,commit:l}}function N0(t){const{config:e,setConfig:n,commit:r}=V0(t,{urlTemplate:"",openInNewTab:!0});async function a(){await r()}async function o(u){n({...e,openInNewTab:u}),await r()}const l=u=>n({...e,urlTemplate:u.currentTarget.value});return h(s.Stack,{children:[i(s.TextInput,{label:"Url",value:e.urlTemplate,onChange:l,onBlur:a}),i(s.Switch,{label:"Open in new Tab",checked:e.openInNewTab,onChange:u=>o(u.currentTarget.checked)})]})}async function q0(t,e){const{urlTemplate:n,openInNewTab:r}=await e.operationData.getItem("config");window.dispatchEvent(new CustomEvent("open-link",{detail:{urlTemplate:n,openInNewTab:r,payload:t}}))}class F0 extends ve{constructor(){super(...arguments);V(this,"VERSION",1)}configVersions(){this.version(1,n=>n)}}const G0={displayName:"Open Link",id:"builtin:op:open-link",configRender:N0,run:q0,migrator:new F0,createDefaultConfig:()=>({version:1,config:{urlTemplate:"",openInNewTab:!0}})};function W0(t){const{value:e,set:n}=R(t.operationData,"config"),r=a=>void n({template:a});return[(e==null?void 0:e.template)||"",r]}function R0(t){const[e,n]=W0(t.operation);return i(s.TextInput,{defaultValue:e,onBlur:r=>n(r.currentTarget.value),label:"console.log"})}async function j0(t,e){const n=await e.operationData.getItem("config"),r=x.template(n.template||"");console.log("run with payload",t),console.log(r(t))}const Y0={displayName:"console.log (debug)",id:"builtin:op:debug",configRender:R0,run:j0},Q0=k.observer(t=>{const e=K(),{value:n,set:r}=R(t.operation.operationData,"config");console.log({value:n,viewID:n==null?void 0:n.viewID});const a=(n==null?void 0:n.viewID)||"",o=l=>void r({viewID:l});return i(s.Select,{defaultValue:a,value:a,onChange:o,label:"View",data:e.views.options})});async function K0(t,e){const r=(await e.operationData.getItem("config")).viewID;window.dispatchEvent(new CustomEvent("open-view",{detail:{viewID:r}}))}const U0={displayName:"Open View",id:"builtin:op:open_view",configRender:Q0,run:K0},X0={"tbody tr":{opacity:.5,transition:"opacity 200ms ease"},"tr[data-affected=true]":{opacity:1}},J0=({value:t="",onChange:e})=>{const[n,r]=y.useState(t);y.useEffect(()=>{r(t)},[t]);const a=()=>{e(n)};return i(s.TextInput,{size:"xs",label:"",value:n,onChange:o=>r(o.currentTarget.value),sx:{flexGrow:1},rightSection:i(s.ActionIcon,{color:"green",size:"xs",onClick:a,disabled:n===t,children:i(L.IconDeviceFloppy,{})})})},Z0={dictionary:{}},H0=k.observer(t=>{const e=K(),{value:n=Z0,set:r}=R(t.operation.operationData,"config"),{dictionary:a={}}=n;console.log({value:{...n},dictionary:{...a},filters:[...e.filters.keyLabelOptions]});const o=(l,u)=>{if(u===""){const c={...a};delete c[l],r({dictionary:c});return}r({dictionary:{...a,[l]:u}})};return h(s.Table,{sx:X0,children:[i("thead",{children:h("tr",{children:[i("th",{children:"Set filter"}),i("th",{children:"with"})]})}),i("tbody",{children:[...e.filters.keyLabelOptions].map(l=>{const u=l.value in a;return h("tr",{"data-affected":u,children:[i("td",{children:l.label}),i("td",{children:i(J0,{value:a[l.value],onChange:c=>o(l.value,c)})})]},l.value)})})]})});async function ew(t,e){const r=(await e.operationData.getItem("config")).dictionary;window.dispatchEvent(new CustomEvent("set-filter-values",{detail:{dictionary:r,payload:t}}))}const tw={displayName:"Set Filter Values",id:"builtin:op:set_filter_values",configRender:H0,run:ew},nw={filter_keys:[]},rw=k.observer(t=>{const e=K(),{value:n=nw,set:r}=R(t.operation.operationData,"config"),{filter_keys:a=[]}=n,o=u=>{r({filter_keys:[...u]})},l=y.useMemo(()=>e.filters.current.map(u=>({label:u.label,value:u.key})),[e.filters.values]);return i(s.Stack,{spacing:10,children:i(s.MultiSelect,{label:"Select Filters to Clear",data:l,value:a,onChange:o})})});async function iw(t,e){const r=(await e.operationData.getItem("config")).filter_keys;window.dispatchEvent(new CustomEvent("clear-filter-values",{detail:{filter_keys:r,payload:t}}))}const Un=[Y0,G0,U0,tw,{displayName:"Clear Filter Values",id:"builtin:op:clear_filter_values",configRender:rw,run:iw}];class aw{constructor(e,n=Un){V(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 $t(a,"data")}};this.attachments=new br(e,"__OPERATIONS",r)}async runOperation(e,n){const r=await this.attachments.getInstance(e);if(!r){console.warn(`Operation '${e}' is not defined`);return}const a=this.tryGetSchema(r.schemaRef);if(!a){console.warn(`Operation schema '${r.schemaRef}' is not defined`);return}await a.run(n,r)}tryGetSchema(e){return this.operations.find(n=>n.id===e)}async needMigration(){const n=(await this.attachments.list()).map(async r=>{const a={configData:r.operationData},o=this.tryGetSchema(r.schemaRef),l=o==null?void 0:o.migrator;return l&&await l.needMigration(a)});return(await Promise.all(n)).some(r=>r)}async runMigration(){const n=(await this.attachments.list()).map(async r=>{const a={configData:r.operationData},o=this.tryGetSchema(r.schemaRef),l=o==null?void 0:o.migrator;l&&await l.needMigration(a)&&await l.migrate(a)});await Promise.all(n)}async createOrGetOperation(e,n){var l;if(!this.getOperationSchemaList().some(u=>u.id===n.id))throw new Error(`Operation schema '${n.id}' is not defined`);const a=await this.attachments.getInstance(e);return!a||a.schemaRef!==n.id?await this.attachments.create(e,{id:e,schemaRef:n.id,data:((l=n.createDefaultConfig)==null?void 0:l.call(n))??{}}):a}getOperationList(){return this.attachments.list()}getOperationSchemaList(){return this.operations}removeOperation(e){return this.attachments.remove(e)}async retrieveTrigger(e){return await this.attachments.getInstance(e)}}class gi{constructor(e,n,r){V(this,"operationManager");V(this,"triggerManager");V(this,"attachments");this.operationManager=new aw(e,r),this.triggerManager=new Oc(e,n);const a=async o=>{const{id:l,triggerRef:u,operationRef:c}=await o.getItem(null);return{id:l,triggerRef:u,operationRef:c}};this.attachments=new br(e,"__INTERACTIONS",a)}async addInteraction(e,n){const r=e.id,a=n.id,o=`[${r}]:[${a}]`;await this.attachments.create(o,{id:o,triggerRef:r,operationRef:a})}getInteractionList(){return this.attachments.list()}async removeInteraction(e){const n=await this.attachments.getInstance(e);if(!n)return;const{triggerRef:r,operationRef:a}=n;await this.getTriggerRefCount(r)<=1&&await this.triggerManager.removeTrigger(r),await this.getOperationRefCount(a)<=1&&await this.operationManager.removeOperation(a),await this.attachments.remove(e)}async getOperationRefCount(e){return(await this.getInteractionList()).filter(r=>r.operationRef===e).length}async getTriggerRefCount(e){return(await this.getInteractionList()).filter(r=>r.triggerRef===e).length}async runInteraction(e,n){const a=(await this.getInteractionList()).filter(o=>o.triggerRef===e);await Promise.all(a.map(async o=>{try{return await this.operationManager.runOperation(o.operationRef,n)}catch(l){console.warn(`Failed to run operation '${o.operationRef}'`,l)}}))}}const et=({vizManager:t,instance:e})=>J.useCreation(()=>new gi(e,t.resolveComponent(e.type),Un),[e,t]),No={left:"flex-start",center:"center",right:"flex-end"},sw=({header:t,cx:e})=>{const n=x.get(t.column.columnDef.meta,"align","left");return h(s.Text,{className:e("table-head-cell",{"table-head-cell--sortable":t.column.getCanSort()}),onClick:t.column.getToggleSortingHandler(),align:n,sx:{justifyContent:No[n]},children:[t.isPlaceholder?null:Ue.flexRender(t.column.columnDef.header,t.getContext()),i(ow,{direction:t.column.getIsSorted()})]})},ow=({direction:t})=>{switch(t){case"asc":return i(L.IconArrowUp,{size:16});case"desc":return i(L.IconArrowDown,{size:"1em"});default:return null}},mi={id:"builtin:table:click-cell-content",displayName:"Click Cell Content",nameRender:dw,configRender:uw,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"}]},lw={column:""};function qo(t,e){const{value:n}=R(t.instanceData,"config"),r={columnsFromConfig:[],columnsFromData:[]};if(n&&(r.columnsFromConfig=n.columns.map((a,o)=>({label:a.label,value:o.toString()}))),!e)return r;if(n!=null&&n.id_field){const a=xn(e,n.id_field);(a==null?void 0:a.length)>0&&(r.columnsFromData=Object.keys(a[0]).map(o=>({label:o,value:o})))}return r}function uw(t){const{columnsFromConfig:e,columnsFromData:n}=qo(t.instance,t.sampleData),r=e.length>0?e:n,{value:a,set:o}=R(t.trigger.triggerData,"config"),{column:l}=x.defaults({},a,lw),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 cw(t,e){return t?x.isNumber(t.column)?`Click cell of ${e[t.column].label}`:`Click cell of ${t.column}`:"Click cell content (click to config)"}function dw(t){const{columnsFromConfig:e}=qo(t.instance),{value:n}=R(t.trigger.triggerData,"config");return i(s.Text,{children:cw(n,e)})}const pw=s.createStyles(t=>({root:{overflow:"auto",position:"relative","& .table-head-cell":{display:"flex",flexFlow:"row nowrap",alignItems:"center",whiteSpace:"nowrap","&.table-head-cell--sortable":{cursor:"pointer",userSelect:"none"}},"&.table-highlight-on-hover tr":{transition:"background-color 0.2s","&:hover":{backgroundColor:t.colorScheme==="dark"?t.colors.dark[5]:t.colors.gray[0]}}},thead:{background:t.colorScheme==="dark"?t.colors.dark[7]:t.white,position:"sticky",top:24,transform:"translateY(-1px)",zIndex:10},info_bar:{position:"sticky",top:0,left:0,right:0,zIndex:10,background:"white"}})),hw={tableLayout:"fixed","th, td":{padding:"2px 10px",div:{overflow:"hidden",textOverflow:"ellipsis"},"&:first-of-type":{paddingLeft:2,paddingRight:2}}};function Fo(t,e,n){return Math.min(Math.max(t,e),n)}class fw{constructor(e){this.steps=e;const n=[],r=new Set;for(const a of e)r.has(a.to)||(n.push(a),r.add(a.to));if(n.sort((a,o)=>a.from-o.from),n.length<2)throw new Error("MultiStepValueMapper requires at least 2 steps");this.steps=n}getLinearFunction(e,n){const r=(n.to-e.to)/(n.from-e.from),a=e.to-r*e.from;return o=>r*o+a}getStepFunctionForValue(e){let n=x.findLastIndex(this.steps,r=>r.from<=e);return n=Fo(n,0,this.steps.length-2),this.getLinearFunction(this.steps[n],this.steps[n+1])}mapValue(e){return Fo(this.getStepFunctionForValue(e)(e),0,100)}}class gw{constructor(e,n,r,a,o){this.getColIndex=e,this.cell=n,this.triggers=r,this.interactionManager=a,this.colorManager=o}getClickHandler(){const e=this.getRelatedTrigger();if(e.length!==0)return()=>{const n={row_data:this.cell.row.original,row_index:this.cell.row.index,col_index:this.getColIndex(this.cell)};for(const r of e)this.interactionManager.runInteraction(r.id,n)}}getRelatedTrigger(){return this.triggers.filter(n=>n.schemaRef===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 e=this.columnConf.cellBackgroundColor;if(!e||e==="none")return;if(x.isString(e))return e;const n=+this.cell.getValue();if(isFinite(n)){const r=this.colorManager.decodeInterpolation(e.interpolation),o=new fw(e.steps).mapValue(n);return r==null?void 0:r.getColor(o)}}}const mw=s.createStyles((t,e)=>({content:{display:"flex",alignItems:"center",justifyContent:No[e.align],".table-cell-text":{whiteSpace:"nowrap",cursor:e.clickable?"pointer":"default",textDecoration:e.clickable?"underline":"none"}}}));function yw(t){return t?at(t).oklch()[0]>.7?"black":"white":"inherit"}function bw(t){const e=t.tableCellContext.bgColor;return{backgroundColor:e,color:yw(e)}}function qt(t){const e=t.tableCellContext.isClickable(),n=mw({clickable:e,align:t.align});return i("div",{className:n.classes.content,style:{...bw(t)},children:i(s.Text,{className:"table-cell-text",onClick:t.tableCellContext.getClickHandler(),children:i("span",{title:t.children,children:t.children})})})}function vw(t){return i(qt,{...t,children:t.value})}function xw(t){const e=te(t.value).format({average:!0,mantissa:2,trimMantissa:!0});return i(qt,{...t,children:e})}function ww(t){const e=te(t.value).format({thousandSeparated:!0});return i(qt,{...t,children:e})}function Cw(t){const e=te(t.value).format({output:"percent",mantissa:3});return i(qt,{...t,children:e})}function Sw(t){const e=t.value,n=t.func_content;if(!n)return i(qt,{...t,children:e});const r=new Function(`return ${n}`)()({value:e});return i(qt,{...t,children:r})}function _w(t){switch(t.type){case Xe.string:return i(vw,{...t});case Xe.eloc:return i(xw,{...t});case Xe.number:return i(ww,{...t});case Xe.percentage:return i(Cw,{...t});case Xe.custom:return i(Sw,{...t})}}const kw=t=>{const e=et(t),n=He(e.triggerManager,mi.id),{colorManager:r}=y.useContext(it);return y.useCallback(a=>new gw(t.getColIndex,a,n,e,r),[n,e,t.getColIndex])};function Tw({context:t,instance:e}){var de,Ce;const n=t.data,{height:r,width:a}=t.viewport,{value:o=yr}=R(t.instanceData,"config"),{id_field:l,use_raw_columns:u,columns:c,...d}=o,{classes:f,cx:p}=pw(),g=y.useMemo(()=>{if(!l)return[];const ye=q(l);return n[ye.queryID]},[n,l]),m=y.useMemo(()=>u?!Array.isArray(g)||g.length===0?[]:Object.keys(g[0]).map(ye=>({id:ye,label:ye,value_field:ye,value_type:Xe.string,align:"left"})):c,[u,c,g]),C=kw({getColIndex:y.useCallback(ye=>m.indexOf(ye.column.columnDef.meta),[m]),vizManager:t.vizManager,instance:e}),w=y.useMemo(()=>{const ye=Ue.createColumnHelper();return m.map(fe=>{const Oe=q(fe.value_field);return ye.accessor(Oe.columnKey,{cell:Ye=>i(_w,{tableCellContext:C(Ye.cell),value:Ye.getValue(),type:fe.value_type,...fe}),header:fe.label,enableSorting:!0,meta:fe,size:fe.width,minSize:fe.width})})},[m,C]),[_,T]=y.useState([]),M=Ue.useReactTable({data:g,state:{sorting:_},onSortingChange:T,columns:w,getCoreRowModel:Ue.getCoreRowModel(),getSortedRowModel:Ue.getSortedRowModel()}),{rows:O}=M.getRowModel(),B=y.useRef(null),F=Ul.useVirtual({parentRef:B,size:O.length,estimateSize:y.useCallback(()=>28,[]),overscan:20}),{virtualItems:$,totalSize:E}=F,z=$.length>0&&((de=$==null?void 0:$[0])==null?void 0:de.start)||0,W=$.length>0?E-(((Ce=$==null?void 0:$[$.length-1])==null?void 0:Ce.end)||0):0,U=O.length,X=U>0,oe=X?r-22:r,re=X?22:0;return!Array.isArray(g)||g.length===0?i(s.Text,{color:"gray",align:"center",children:"Empty Data"}):h("div",{ref:B,style:{height:r,width:a},"data-enable-scrollbar":!0,className:p(f.root,{"table-highlight-on-hover":o.highlightOnHover}),children:[U>0&&i(s.Box,{className:f.info_bar,sx:{height:22},children:h(s.Text,{align:"right",pr:6,size:14,color:"dimmed",fw:"normal",children:["Total: ",U]})}),h(s.Table,{sx:{...hw,maxHeight:oe},...d,striped:o.striped,children:[i("thead",{className:f.thead,style:{top:re},children:M.getHeaderGroups().map(ye=>i("tr",{children:ye.headers.map(Te=>i("th",{style:{width:Te.getSize()},children:i(sw,{header:Te,cx:p})},Te.id))},ye.id))}),h("tbody",{children:[z>0&&i("tr",{children:i("td",{style:{height:`${z}px`}})}),$.map(ye=>{const Te=O[ye.index];return i("tr",{children:Te.getVisibleCells().map(fe=>i("td",{children:Ue.flexRender(fe.column.columnDef.cell,fe.getContext())},fe.id))},Te.id)}),W>0&&i("tr",{children:i("td",{style:{height:`${W}px`}})})]})]})]})}const Go=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)"}}}})),Dw=[{from:0,to:0},{from:100,to:100}];class Iw{constructor(){V(this,"steps",new Map);V(this,"interpolation");V(this,"onChange");ae.makeAutoObservable(this,{steps:ae.observable},{deep:!1}),ae.reaction(()=>ae.toJS(this.steps),()=>{this.notifyStepChange()})}setSteps(e){for(const n of e)this.steps.set(n.to,n.from)}notifyStepChange(){var e;(e=this.onChange)==null||e.call(this,Array.from(this.steps.entries()).map(([n,r])=>({to:n,from:r})).sort((n,r)=>n.to-r.to||n.from-r.from))}fromProps(e){e.steps.length<2?this.setSteps(Dw):this.setSteps(e.steps),this.interpolation=e.interpolation,this.onChange=e.onChange}changeStep(e,n){e==null?this.steps.delete(n):this.steps.set(n,e)}getStepFromValue(e){return this.steps.get(e)}}function Mw(t){const{onChange:e,color:n,index:r,value:a}=t,{classes:o}=Go(),[l,u]=y.useState(a),[c,{setTrue:d,setFalse:f}]=J.useBoolean(!1),p=r%2===1,g=p&&a!=null,m=!p&&a!=null,C=`map ${a} to color ${r}`,w=()=>{u(a),f()},_=()=>{f(),e==null||e(l)},T=te(a).format({average:!0});return h("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}),h(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":at(n).alpha(.5).hex(),backgroundColor:n}})}),i(s.Popover.Dropdown,{children:h(s.Stack,{children:[i(s.NumberInput,{size:"xs",label:"Map a value to this color",value:l,onChange:u}),h(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 Ew=k.observer(({model:t})=>{const{classes:e}=Go(),n=x.range(0,13,1).map(r=>100/12*r).map(r=>[t.interpolation.getColor(r),r]);return i("div",{className:e.palette,children:n.map(([r,a],o)=>i(Mw,{index:o,color:r,value:t.getStepFromValue(a),onChange:l=>t.changeStep(l,a)},r))})}),Aw=k.observer(function(e){const n=J.useCreation(()=>new Iw,[]);return y.useEffect(()=>{n.fromProps(e)}),n.interpolation==null?null:i(Ew,{model:n})}),zw=t=>{const{value:e,onChange:n,colorManager:r}=t,a=r.getColorInterpolations(),[o,l]=y.useState(e),u=r.decodeInterpolation(o.interpolation)||a[0],[c,{setTrue:d,setFalse:f}]=J.useBoolean(),p=a.map(_=>({label:_.displayName,value:r.encodeColor(_),group:_.category}));function g(_){_&&l(T=>({...T,interpolation:_}))}const m=()=>{f(),n==null||n(ae.toJS(o))};function C(_){l(T=>({...T,steps:_}))}const w=()=>{f(),l(e)};return h(N,{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&&h(s.Stack,{"data-testid":"color-interpolation-modal",children:[i(s.Select,{label:"Color style",value:o.interpolation,data:p,onChange:g}),i(Aw,{steps:o.steps,interpolation:u,onChange:C}),h(s.Group,{position:"right",children:[i(s.Button,{onClick:w,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:m,children:"OK"})]})]})})]})},$w=["static","interpolation","none"].map(t=>({label:x.capitalize(t),value:t})),Lw=[{from:0,to:0},{from:100,to:100}];function Wo(t){return t?x.isString(t)?t==="none"?"none":"static":"interpolation":"none"}function Ow(t,e){var n;return Wo(e)==="static"?e:(n=t.getStaticColors()[0])==null?void 0:n.value}function Pw(t,e){return x.isObject(e)?e:{steps:Lw,interpolation:t.encodeColor(t.getColorInterpolations()[0])}}const Bw=y.forwardRef((t,e)=>{const{colorManager:n}=y.useContext(it),[r,a]=y.useState(Wo(t.value)),[o,l]=y.useState(Ow(n,t.value)),u=J.useLatest(o),[c,d]=y.useState(Pw(n,t.value)),f=J.useLatest(c),p=C=>{var w,_,T;a(C||"none"),C==="static"?(w=t.onChange)==null||w.call(t,u.current):C==="none"||!C?(_=t.onChange)==null||_.call(t,"none"):(T=t.onChange)==null||T.call(t,f.current)},g=C=>{var w;l(C),(w=t.onChange)==null||w.call(t,C)},m=C=>{var w;d(C),(w=t.onChange)==null||w.call(t,C)};return h(s.Stack,{align:"stretch",children:[i(s.Select,{label:"Cell background",value:r||"none",onChange:p,data:$w}),r==="static"&&i(Pe,{value:o,onChange:g}),r==="interpolation"&&i(zw,{colorManager:n,value:c,onChange:m})]})}),Vw={[Xe.eloc]:"ELOC"},Nw=Object.values(Xe).map(t=>({label:x.get(Vw,t,x.capitalize(t)),value:t})),qw=y.forwardRef(({label:t,value:e,onChange:n,sx:r},a)=>i(s.Select,{ref:a,label:t,data:Nw,value:e,onChange:n,sx:r})),Fw=y.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:a,setFalse:o}]=J.useBoolean(),[l,u]=y.useState(t),c=()=>{o(),e(l)},d=()=>{o(),u(t)},f=()=>{u(ps)};return y.useEffect(()=>{u(t)},[t]),h(N,{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&&h(s.Stack,{children:[i(s.Box,{sx:{position:"relative"},children:i(ze,{height:"500px",defaultLanguage:"javascript",value:l,onChange:p=>u(p??""),theme:"vs-dark",options:{minimap:{enabled:!1}}})}),h(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Rest"}),h(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"}),Ww=({control:t,index:e,watch:n,remove:r,column:a})=>{const o=n(`columns.${e}.value_type`);return h(s.Stack,{my:0,sx:{position:"relative"},children:[h(s.Group,{grow:!0,children:[i(v.Controller,{name:`columns.${e}.label`,control:t,render:({field:l})=>i(s.TextInput,{label:"Label",required:!0,id:`col-label-${e}`,sx:{flex:1},...l})}),i(v.Controller,{name:`columns.${e}.value_field`,control:t,render:({field:l})=>i(j,{label:"Value Field",required:!0,...l})})]}),h(s.Group,{grow:!0,children:[i(v.Controller,{name:`columns.${e}.value_type`,control:t,render:({field:l})=>i(qw,{label:"Value Type",sx:{flex:1},...l})}),o===Xe.custom&&i(v.Controller,{name:`columns.${e}.func_content`,control:t,render:({field:l})=>i(Fw,{value:l.value??ps,onChange:u=>l.onChange(u??"")})})]}),i(s.Divider,{mb:-10,variant:"dashed",label:"Style",labelPosition:"center"}),h(s.Group,{grow:!0,children:[i(s.NumberInput,{hideControls:!0,label:"Min Width",rightSection:i(yi,{}),disabled:!0}),i(v.Controller,{name:`columns.${e}.width`,control:t,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.${e}.align`,control:t,render:({field:l})=>i(s.Select,{label:"Alignment",data:Gw,...l})})}),i(v.Controller,{name:`columns.${e}.cellBackgroundColor`,control:t,render:({field:l})=>i(Bw,{...l})}),i(s.Divider,{mb:4,mt:12,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(e),children:"Delete this column"})]})},Rw=({control:t,watch:e})=>{const{fields:n,append:r,remove:a,update:o}=v.useFieldArray({control:t,name:"columns"}),l=()=>{const c=Ie.randomId();r({id:c,label:c,align:"center",value_field:"",value_type:Xe.string})};e("columns");const u=e("use_raw_columns");return h(N,{children:[i(v.Controller,{name:"use_raw_columns",control:t,render:({field:c})=>i(s.Switch,{mt:20,label:"Use Original Data Columns",checked:c.value,onChange:d=>c.onChange(d.currentTarget.checked)})}),i(s.Divider,{mt:20,mb:10,variant:"dashed"}),!u&&h(s.Stack,{children:[i(s.Text,{my:0,children:"Custom Columns"}),h(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[h(s.Tabs.List,{children:[n.map((c,d)=>i(s.Tabs.Tab,{value:d.toString(),children:d+1},c.id)),i(s.Tabs.Tab,{onClick:l,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),n.map((c,d)=>i(s.Tabs.Panel,{value:d.toString(),children:i(Ww,{control:t,watch:e,index:d,column:c,remove:a},d)},c.id))]})]})]})};function jw({control:t,watch:e}){return e(["horizontalSpacing","verticalSpacing","fontSize","striped","highlightOnHover"]),h(s.Stack,{spacing:"xs",children:[h(s.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:[i(v.Controller,{name:"horizontalSpacing",control:t,render:({field:n})=>i(s.TextInput,{label:"Horizontal Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"verticalSpacing",control:t,render:({field:n})=>i(s.TextInput,{label:"Vertical Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})})]}),i(s.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:i(v.Controller,{name:"fontSize",control:t,render:({field:n})=>i(s.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})})}),h(s.Group,{position:"apart",grow:!0,children:[i(v.Controller,{name:"striped",control:t,render:({field:n})=>i(s.Switch,{label:"Striped",checked:n.value,onChange:r=>n.onChange(r.currentTarget.checked)})}),i(v.Controller,{name:"highlightOnHover",control:t,render:({field:n})=>i(s.Switch,{label:"Highlight on hover",checked:n.value,onChange:r=>n.onChange(r.currentTarget.checked)})})]})]})}function Yw({columns:t,...e}){return{...e,columns:t.map(({id:n,...r})=>({id:n??Ie.randomId(),...r}))}}function Qw({context:t}){const{value:e,set:n}=R(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,yr),[e]),a=y.useMemo(()=>Yw(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(),p=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return u(["id_field"]),h("form",{onSubmit:l(n),children:[h(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:!p,children:i(I.DeviceFloppy,{size:20})})]}),h(s.Tabs,{defaultValue:"Columns",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[h(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Data",children:"Data"}),i(s.Tabs.Tab,{value:"Style",children:"Style"}),i(s.Tabs.Tab,{value:"Columns",children:"Columns"})]}),i(s.Tabs.Panel,{value:"Data",children:i(v.Controller,{name:"id_field",control:o,render:({field:g})=>i(j,{label:"ID Field",required:!0,...g})})}),i(s.Tabs.Panel,{value:"Style",children:i(jw,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Columns",children:i(Rw,{control:o,watch:u})})]})]})}function Kw(t){const{columns:e,...n}=t;return{...t,columns:e.map(r=>({...r,align:r.align??"left"}))}}function Uw(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{id_field:a,columns:o,...l}=t;return{...l,id_field:r(a),columns:o.map(u=>({...u,value_field:r(u.value_field)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class Xw extends ve{constructor(){super(...arguments);V(this,"VERSION",4)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{columns:r,...a}=n.config;return{...n,version:2,config:{...a,columns:r.map(({id:o,...l})=>({id:o??Ie.randomId(),...l}))}}}),this.version(3,n=>({...n,version:3,config:Kw(n.config)})),this.version(4,(n,r)=>({...n,version:4,config:Uw(n.config,r)}))}}const bi={createConfig(){return{version:4,config:x.cloneDeep(yr)}},displayName:"Table",displayGroup:"Others",migrator:new Xw,name:"table",viewRender:Tw,configRender:Qw,triggers:[mi]},Jw=b.types.model("PanelLayoutModel",{x:b.types.number,y:b.types.maybeNull(b.types.number),w:b.types.number,h:b.types.number,moved:b.types.optional(b.types.boolean,!1),static:b.types.optional(b.types.boolean,!1)}).views(t=>({get json(){const{x:e,y:n,w:r,h:a,moved:o}=t;return{h:a,w:r,x:e,y:n===null?0:n,moved:o,static:t.static}}})).actions(t=>({set(e){const{x:n,y:r,w:a,h:o,moved:l}=e;t.x=n,t.y=r,t.w=a,t.h=o,t.moved=!!l,t.static=!!e.static}})),Zw=b.types.model("PanelStyleBorderModel",{enabled:b.types.boolean}).views(t=>({get json(){const{enabled:e}=t;return{enabled:e}}})).actions(t=>({setEnabled(e){t.enabled=e}})),Hw=b.types.model("PanelStyleModel",{border:Zw}).views(t=>({get json(){const{border:e}=t;return{border:e.json}}})).actions(t=>({})),eC=b.types.model("PanelVizModel",{type:b.types.string,conf:b.types.frozen()}).views(t=>({get json(){return{conf:t.conf,type:t.type}}})).actions(t=>({setType(e){t.type=e},setConf(e){t.conf=e}})),Ro=b.types.model({id:b.types.string,title:b.types.string,description:b.types.string,layout:Jw,queryIDs:b.types.array(b.types.string),viz:eC,style:Hw,variables:b.types.optional(b.types.array(Gu),[])}).views(t=>({get contentModel(){return b.getParentOfType(t,Xn)}})).views(t=>({get queryIDSet(){return new Set(t.queryIDs)},get queries(){return t.contentModel.queries.findByIDSet(this.queryIDSet)},get data(){return this.queries.reduce((e,n)=>(e[n.id]=n.data.toJSON(),e),{})},get dataLoading(){return this.queries.some(e=>e.state==="loading")},get queryStateMessages(){return this.queries.map(e=>e.stateMessage).filter(e=>!!e)},get queryErrors(){return this.queries.map(e=>e.error).filter(e=>!!e)},get canRenderViz(){return this.queryErrors.length===0&&this.queryStateMessages.length===0&&!this.dataLoading},get json(){const{id:e,title:n,description:r,queryIDs:a}=t;return{id:e,viz:t.viz.json,style:t.style.json,title:n,layout:t.layout.json,queryIDs:[...a],variables:t.variables.map(o=>o.json),description:r}},get dataFieldOptions(){return t.queryIDs.length===0?[]:this.queries.map(e=>{const n=e.data;return n.length===0?[]:Object.keys(n[0]).map(a=>({label:a,value:`${e.id}.${a}`,group:e.name}))}).flat()}})).actions(t=>({setID(e){t.id=e},setTitle(e){t.title=e},setDescription(e){t.description=e},addQueryID(e){t.queryIDSet.has(e)||t.queryIDs.push(e)},removeQueryID(e){if(!t.queryIDSet.has(e))return;const n=new Set(t.queryIDSet);n.delete(e),t.queryIDs=b.cast(Array.from(n))},setQueryIDs(e){t.queryIDs=b.cast(e)},addVariable(e){t.variables.push(e)},removeVariable(e){t.variables.remove(e)},removeSelf(){b.getParent(t,2).removeByID(t.id)}})).actions(t=>({moveToView(e,n){b.getRoot(t).content.views.findByID(e).removePanelID(t.id),b.getRoot(t).content.views.findByID(n).appendPanelID(t.id),b.getRoot(t).editor.setPath(["_VIEWS_",n,"_PANELS_",t.id])},refreshData(){t.queries.forEach(e=>e.fetchData())},downloadData(){b.getRoot(t).content.queries.downloadDataByQueryIDs(t.queryIDs)}}));function jo(t){return{id:t,layout:{x:0,y:1/0,w:18,h:300},title:t,description:"<p></p>",queryIDs:[],viz:{type:bi.name,conf:bi.createConfig()},style:{border:{enabled:!0}}}}const Yo=b.types.model("PanelsModel",{list:b.types.optional(b.types.array(Ro),[])}).views(t=>({get json(){return t.list.map(e=>e.json)},findByID(e){return t.list.find(n=>n.id===e)},get idMap(){const e=new Map;return t.list.forEach(n=>{e.set(n.id,n)}),e}})).views(t=>({panelsByIDs(e){const n=[];e.forEach(a=>{const o=t.idMap.get(a);o?n.push(o):console.warn(`Panel is not found, id:${a}`)});const r=n.map(a=>({...a.layout.json,i:a.id}));return{panels:n,layouts:r}}})).views(t=>({editorOptions(e,n){const{panels:r}=t.panelsByIDs(n);r.length!==n.length&&console.warn(`Unfulfilled panels for View[${e}]`);const a=r.map(l=>({label:l.title?l.title:x.capitalize(l.viz.type),value:l.id,_type:"panel",parentID:e})),o="_Add_A_PANEL_";return a.push({label:o,value:o,_type:"ACTION",_action_type:o,parentID:e,Icon:null,children:null}),a}})).actions(t=>({replace(e){t.list=b.castToSnapshot(e)},append(e){t.list.push(e)},remove(e){t.list.splice(e,1)},removeByID(e){const n=t.list.findIndex(r=>r.id===e);n!==-1&&t.list.splice(n,1)},duplicateByID(e){const n=t.list.find(a=>a.id===e);if(!n){console.error(new Error(`[duplicate panel] Can't find a panel by id[${e}]`));return}const r=new Date().getTime().toString();return t.list.push({...n.json,id:r,layout:{...n.layout,y:1/0,moved:!1}}),r},replaceByIndex(e,n){t.list.splice(e,1,n)}}));var Qo=(t=>(t.Use="use",t.Edit="edit",t))(Qo||{}),H=(t=>(t.Division="div",t.Modal="modal",t.Tabs="tabs",t))(H||{});const tC={div:"Division",tabs:"Tabs",modal:"Modal"},Ko={div:"rgba(255, 0, 0, 0.2)",modal:"rgba(0, 0, 0, 0.2)",tabs:"rgba(255, 200, 100, 0.4)"},nC={div:"#ff4000",modal:"#000",tabs:"#ffad18"},rC={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:"div",config:{},panelIDs:[]}],panels:[],filters:[],version:"9.19.0"};var vi=(t=>(t.Select="select",t.TreeSelect="tree-select",t.MultiSelect="multi-select",t.TextInput="text-input",t.Checkbox="checkbox",t.DateRange="date-range",t))(vi||{});const Uo=b.types.model("ViewModel_Division",{_name:b.types.literal(H.Division)}).views(t=>({get json(){const{_name:e}=t;return{_name:e}}})).actions(t=>({})),iC=()=>Uo.create({_name:H.Division}),xi={enabled:!1,func_content:["function text({ filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
|
|
480
|
+
`)},aC=b.types.model("CustomModalTitleModel",{enabled:b.types.optional(b.types.boolean,!1),func_content:b.types.optional(b.types.string,"")}).views(t=>({get json(){const{enabled:e,func_content:n}=t;return{enabled:e,func_content:n}},get value(){const{enabled:e,func_content:n}=t,r=b.getParent(t,2),a=b.getRoot(t);if(!e)return r.name;try{const o={filters:a.content.filters.values,context:a.context.current};return new Function(`return ${n}`)()(o)}catch(o){return console.error(o),r.name}}})).actions(t=>({setEnabled(e){t.enabled=e},setFuncContent(e){t.func_content=e},replace({enabled:e,func_content:n}){t.enabled=e,t.func_content=n}})),Xo=b.types.model("ViewModel_Modal",{_name:b.types.literal(H.Modal),width:b.types.string,height:b.types.string,custom_modal_title:b.types.optional(aC,xi)}).views(t=>({get json(){const{_name:e,width:n,height:r,custom_modal_title:a}=t;return{_name:e,width:n,height:r,custom_modal_title:a.json}}})).actions(t=>({setWidth(e){t.width=e},setHeight(e){t.height=e}})),sC=()=>Xo.create({_name:H.Modal,width:"90vw",height:"90vh"}),oC=b.types.model("ViewModel_Tabs_Tab",{id:b.types.identifier,name:b.types.string,view_id:b.types.string,color:b.types.optional(b.types.string,"")}).views(t=>({get json(){const{id:e,name:n,view_id:r,color:a}=t;return{id:e,name:n,color:a,view_id:r}}})).actions(t=>({setName(e){t.name=e},setViewID(e){t.view_id=e},setColor(e){t.color=e}})),Jo=b.types.model("ViewModel_Tabs",{_name:b.types.literal(H.Modal),tabs:b.types.optional(b.types.array(oC),[]),variant:b.types.optional(b.types.enumeration("variant",["default","outline","pills"]),"default"),orientation:b.types.optional(b.types.enumeration("orientation",["horizontal","vertical"]),"horizontal"),grow:b.types.optional(b.types.boolean,!1)}).views(t=>({get json(){const{_name:e,variant:n,orientation:r,tabs:a,grow:o}=t;return{grow:o,tabs:a.map(l=>l.json),_name:e,variant:n,orientation:r}}})).actions(t=>({setVariant(e){t.variant=e},setOrientation(e){t.orientation=e},setGrow(e){t.grow=e},setTabs(e){t.tabs.length=0,t.tabs=b.cast(e)},addTab(){const e=Ie.randomId(),n={id:e,name:e,view_id:""};t.tabs.push(n)},removeTab(e){t.tabs.splice(e,1)}})),lC=()=>Jo.create({_name:H.Modal,tabs:[]}),Zo=b.types.model({id:b.types.identifier,name:b.types.string,type:b.types.enumeration("EViewComponentType",[H.Division,H.Modal,H.Tabs]),config:b.types.union(Uo,Xo,Jo),panelIDs:b.types.optional(b.types.array(b.types.string),[])}).views(t=>({get json(){const{id:e,name:n,type:r,config:a}=t;return{id:e,name:n,type:r,config:a.json,panelIDs:t.panelIDs}}})).actions(t=>({setName(e){t.name=e},setType(e){if(t.type!==e){switch(e){case H.Division:t.config=iC();break;case H.Modal:t.config=sC();break;case H.Tabs:t.config=lC();break}t.type=e}},appendPanelID(e){t.panelIDs.push(e)},removePanelID(e){const n=t.panelIDs.filter(r=>r!==e);t.panelIDs.length=0,t.panelIDs.push(...n)}})).actions(t=>({})),Ho=b.types.model("ViewsModel",{current:b.types.optional(b.types.array(Zo),[]),visibleViewIDs:b.types.array(b.types.string),idOfVIE:b.types.string}).views(t=>({get json(){return t.current.map(e=>yn(e.json))},get idMap(){const e=new Map;return t.current.forEach(n=>{e.set(n.id,n)}),e},findByID(e){return t.current.find(n=>n.id===e)},get isVIETheFirstView(){return t.current.length===0||!t.idOfVIE?!1:t.current[0].id===t.idOfVIE},get firstVisibleView(){const[e]=t.visibleViewIDs;return t.current.find(({id:n})=>n===e)},get visibleViews(){const e=new Set(t.visibleViewIDs);return t.current.filter(({id:n})=>e.has(n))},get VIE(){return t.current.find(({id:e})=>e===t.idOfVIE)},get options(){return t.current.map(e=>({label:e.name,value:e.id,type:e.type}))},get editorOptions(){const e=b.getRoot(t).content.panels;return t.current.map(n=>({label:n.name,value:n.id,_type:"view",children:e.editorOptions(n.id,n.panelIDs)}))}})).actions(t=>({replace(e){t.current.replace(e)},addANewView(e,n,r,a){t.current.push({id:e,name:n,type:r,config:a,panelIDs:[]})},append(e){t.current.push(e)},remove(e){t.current.splice(e,1)},removeByID(e){const n=t.current.findIndex(r=>r.id===e);n!==-1&&t.current.splice(n,1)},replaceByIndex(e,n){t.current.splice(e,1,n)},setIDOfVIE(e){t.idOfVIE=e,t.visibleViewIDs.length=0,t.visibleViewIDs.push(e)},appendToVisibles(e){new Set(t.visibleViewIDs.map(r=>r)).has(e)||t.visibleViewIDs.push(e)}})).actions(t=>({addARandomNewView(){const e=new Date().getTime().toString();t.addANewView(e,H.Division,H.Division,{_name:H.Division}),t.setIDOfVIE(e)},removeVIE(){t.current.length!==1&&(t.removeByID(t.idOfVIE),t.setIDOfVIE(t.current[0].id))},rmVisibleViewID(e){const n=t.visibleViewIDs.findIndex(r=>r===e);n!==-1&&t.visibleViewIDs.splice(n,1)}}));function wi(t){const e=t.length>0?[t[0].id]:[],n=t.length>0?t[0].id:"";return{current:t.map(a=>{const{_name:o=a.type}=a.config;return{...a,config:{...a.config,_name:o},panelIDs:a.panelIDs}}),visibleViewIDs:e,idOfVIE:n}}function el(t,e,n,r){return t.reduce((a,o)=>(a[o[e]]=cr(o[n],r),a),{})}const uC=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:ts,queries:ls,sqlSnippets:cs,views:Ho,panels:Yo,mock_context:Fu,origin:b.types.maybe(b.types.frozen())}).views(t=>({get json(){return{id:t.id,name:t.name,create_time:t.create_time,update_time:t.update_time,dashboard_id:t.dashboard_id,content:{views:t.views.json,panels:t.panels.json,filters:t.filters.json,version:t.version,definition:{queries:t.queries.json,sqlSnippets:t.sqlSnippets.json,mock_context:t.mock_context.current}}}},get filtersChanged(){const e="filters.current";return!x.isEqual(b.getSnapshot(x.get(t,e)),x.get(t.origin,e))},get queriesChanged(){const e="queries.current",n=b.getSnapshot(x.get(t,e)).map(r=>x.pick(r,["id","name","key","type","sql","run_by","react_to","pre_process","post_process"]));return!x.isEqual(n,x.get(t.origin,e))},get sqlSnippetsChanged(){const e="sqlSnippets.current";return!x.isEqual(b.getSnapshot(x.get(t,e)),x.get(t.origin,e))},get viewsChanged(){const e="views.current";return!x.isEqual(b.getSnapshot(x.get(t,e)),x.get(t.origin,e))},get panelsChanged(){const e="panels.list";return!x.isEqual(b.getSnapshot(x.get(t,e)),x.get(t.origin,e))},get mockContextChanged(){const e="mock_context.current";return!x.isEqual(x.get(t,e),x.get(t.origin,e))},get payloadForSQL(){const e=b.getParent(t).context.current,n=b.getParent(t).globalSQLSnippets,r={context:{...t.mock_context.current,...e},filters:t.filters.values};return{...r,sql_snippets:el(t.sqlSnippets.current,"key","value",r),global_sql_snippets:el(n.list,"id","content",r)}},get payloadForViz(){const e=b.getParent(t).context.current;return{context:{...t.mock_context.current,...e},filters:t.filters.values}},get changed(){return this.filtersChanged||this.queriesChanged||this.sqlSnippetsChanged||this.viewsChanged||this.panelsChanged||this.mockContextChanged},get data(){return t.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(e){const n=t.queries.findByID(e);return n?{data:n.data.toJSON(),len:n.data.length,state:n.state,error:n.error}:{data:[],len:0,state:"idle",error:void 0}}})).views(t=>({findQueryUsage(e){const n=t.panels.idMap,r=t.views.current.flatMap(l=>l.panelIDs.map(u=>n.get(u)).filter(u=>(u==null?void 0:u.queryIDSet.has(e))??!1).map(u=>({type:"panel",id:u.id,label:u.title?u.title:u.viz.type,views:[{id:l.id,label:l.name}]}))),a=t.views.idMap,o=t.filters.current.filter(l=>x.get(l,"config.options_query_id")===e).map(l=>({type:"filter",id:l.id,label:l.label,views:l.visibleInViewsIDs.map(u=>{var c;return{id:u,label:((c=a.get(u))==null?void 0:c.name)??u}})}));return r.concat(o)}})).actions(t=>({duplicatePanelByID(e,n){var a;const r=t.panels.duplicateByID(e);r&&((a=t.views.findByID(n))==null||a.appendPanelID(r))},removePanelByID(e,n){var r;t.panels.removeByID(e),(r=t.views.findByID(n))==null||r.removePanelID(e)},addANewPanel(e){var r;const n=new Date().getTime().toString();t.panels.append(jo(n)),(r=t.views.findByID(e))==null||r.appendPanelID(n)}})).actions(t=>({reset(){b.applySnapshot(t.filters.current,t.origin.filters.current),b.applySnapshot(t.queries.current,t.origin.queries.current),b.applySnapshot(t.sqlSnippets.current,t.origin.sqlSnippets.current),b.applySnapshot(t.views.current,t.origin.views.current),b.applySnapshot(t.panels.list,t.origin.panels.list),t.mock_context.current=t.origin.mock_context.current},resetFilters(){b.applySnapshot(t.filters.current,t.origin.filters.current)},updateCurrent(e){const{id:n,name:r,content:a}=e;if(!a)throw new Error("unexpected null content when updating a content model");const{version:o,filters:l,views:u,panels:c,definition:{queries:d,sqlSnippets:f,mock_context:p={}}}=a;t.id=n,t.name=r,t.version=o,b.applySnapshot(t.filters.current,l),b.applySnapshot(t.views.current,wi(u).current),b.applySnapshot(t.panels.list,c),b.applySnapshot(t.queries.current,d),b.applySnapshot(t.sqlSnippets.current,f),t.mock_context.current=p}})),Xn=b.types.snapshotProcessor(uC,{preProcessor(t){return{...t,origin:t}},postProcessor(t){delete t.origin;const e=b.castToSnapshot(t.queries.current.map(n=>x.pick(n,["id","key","type","sql"])));return x.defaults({},{queries:{current:e}},t)}});function cC(t,e){e.filters&&b.applySnapshot(t.filters.current,e.filters)}function tl({id:t,name:e,dashboard_id:n,create_time:r,update_time:a,content:o}){if(!o)throw new Error("unexpected null content when creating a content model");const{version:l,filters:u,views:c,panels:d,definition:{queries:f,sqlSnippets:p,mock_context:g={}}}=o;return Xn.create({id:t,name:e,dashboard_id:n,create_time:r,update_time:a,version:l,filters:ns(u),queries:{current:f},sqlSnippets:{current:p},mock_context:{current:g},views:wi(c),panels:{list:d}})}const dC=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}),pC=b.types.model("GlobalSQLSnippetsModel",{list:b.types.optional(b.types.array(dC),[])}).views(t=>({find(e){return t.list.find(n=>n.id===e)},get options(){return t.list.map(e=>({value:e.id,label:e.id}))}})).actions(t=>({replace(e){t.list.length=0,t.list.push(...e)}})),nl=b.types.model({id:b.types.identifier,name:b.types.string,group:b.types.string,content:Xn,content_id:b.types.string,datasources:Vu,globalSQLSnippets:pC,context:ds,editor:qu}).views(t=>({get json(){return{id:t.id,name:t.name,group:t.group,content_id:t.content_id}}})).actions(t=>({updateCurrentContent(e){t.content.updateCurrent(e)},updateCurrent(e,n){const{id:r,name:a,group:o,content_id:l}=e;t.id=r,t.name=a,t.group=o,t.content_id=l,this.updateCurrentContent(n)}}));function Ci({id:t,name:e,group:n,content_id:r},a,o,l,u){return nl.create({id:t,name:e,group:n,content_id:r,content:tl(a),datasources:{list:o},globalSQLSnippets:{list:l},context:{current:u},editor:{}})}const Si=y.createContext(null);function Jn(t){const e=y.useContext(Si),n=J.useCreation(()=>t.configure(e||new vr),[t.configure]),r=J.usePrevious(n);return r&&r!==n&&r.dispose(),i(Si.Provider,{value:n,children:t.children})}function rl(){return y.useContext(Si)}const hC={viewPanelInFullScreen:x.noop,inFullScreen:!1},_i=y.createContext(hC),fC=({description:t,isDescriptionEmpty:e})=>e?null:i(s.Tooltip,{color:"white",label:i(Yn,{value:t,styles:{root:{border:"none"},content:{padding:0}}}),styles:{tooltip:{border:"0.0625rem solid rgb(233, 236, 239)",boxShadow:"rgb(0 0 0 / 5%) 0px 0.0625rem 0.1875rem, rgb(0 0 0 / 5%) 0px 1.25rem 1.5625rem -0.3125rem, rgb(0 0 0 / 4%) 0px 0.625rem 0.625rem -0.3125rem"}},withArrow:!0,children:i(s.Box,{sx:{height:"16px",alignSelf:"center"},children:i(L.IconInfoCircle,{size:16,color:"gray"})})}),gC=k.observer(({label:t,config:{default_value:e,description:n,isDescriptionEmpty:r,...a},value:o,onChange:l})=>h(s.Box,{children:[i(s.Text,{children:" "}),i(s.Checkbox,{label:h(s.Group,{noWrap:!0,position:"apart",align:"middle",spacing:6,children:[i(s.Box,{sx:{flexGrow:1},children:t}),i(fC,{description:n,isDescriptionEmpty:r})]}),checked:o||!1,onChange:u=>l(u.currentTarget.checked),...a,pt:".4em",styles:{input:{borderColor:"#e9ecef"}}})]})),il=k.observer(({label:t,config:e,value:n=[null,null],onChange:r})=>{const{inputFormat:a,...o}=e,l=Array.isArray(n)?n.map(f=>f?Y(f).toDate():null):[null,null],u=f=>{r(f.map(p=>p&&Y(p).format(a)))},c=e.getMinDate(l[0]),d=e.getMaxDate(l[0]);return i(Zl.DatePickerInput,{type:"range",label:t,value:l,onChange:u,icon:i(I.Calendar,{size:16}),sx:{minWidth:"16em"},minDate:c,maxDate:d,valueFormat:a,styles:{input:{borderColor:"#e9ecef"}},...o})}),mC=s.createStyles((t,{radius:e=4})=>({root:{borderRadius:t.fn.radius(e),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-select.rc-select-open":{borderColor:"#228be6 !important",".rc-select-selection-overflow-item-rest":{display:"none"},".rc-select-selection-overflow-item-suffix":{display:"block"}},".rc-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-select-selection-search-mirror":{display:"none"},".rc-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:t.fontSizes.sm,fontWeight:500,color:"#212529"},dropdown:{fontSize:t.fontSizes.xs,zIndex:300,backgroundColor:"#fff",border:"1px solid #e9ecef",marginTop:6,padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px","&.rc-select-dropdown-slide-up-leave-active":{display:"none"},".rc-select-item-empty":{padding:"8px 12px"},".rc-select-item-option":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"8px 12px 8px 2px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},flexDirection:"row-reverse",".rc-select-item-option-state":{flexGrow:0,flexShrink:0,width:"30px",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},".rc-select-item-option-content":{flexGrow:1}}}})),al=({errorMessage:t})=>t?i(s.Text,{color:"red",size:12,children:t}):i(s.Text,{color:"dimmed",size:12,children:"Not found"}),yC=({disabled:t,classNames:e,styles:n,unstyled:r,radius:a,style:o,label:l,value:u,onChange:c,options:d,errorMessage:f})=>{const{classes:p,cx:g}=mC({radius:a},{name:"MultiSelectWidget",classNames:e,styles:n,unstyled:r}),[m,C]=y.useState(!1),w=B=>{C(B)},_=m&&(u==null?void 0:u.length)>0,[T,M]=y.useState(""),O=y.useMemo(()=>{if(!T)return d;const B=T.toLowerCase(),F=$=>{var E;return((E=$.description)==null?void 0:E.toLowerCase().includes(B))||$.label.toLowerCase().includes(B)};return d.filter(F)},[T,d]);return h(s.Stack,{spacing:3,children:[h(s.Group,{position:"apart",children:[i(s.Text,{className:p.label,children:l}),_&&i(s.Tooltip,{label:`${u.length} selected`,children:i(s.Badge,{children:u.length})})]}),i(Ba,{disabled:t,allowClear:!0,className:g(p.root,"check-select"),dropdownClassName:g(p.dropdown,""),onDropdownVisibleChange:w,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(al,{errorMessage:f}),maxTagTextLength:10,maxTagPlaceholder:B=>`${B.length} selected`,searchValue:T,onSearch:M,filterOption:!1,children:O.map(B=>i(Ba.Option,{children:i(s.Group,{noWrap:!0,children:h("div",{children:[i(s.Text,{size:"sm","data-role":"label",children:B.label}),B.description&&i(s.Text,{size:"xs",color:"dimmed","data-role":"description",children:B.description})]})})},B.value))})]})},bC=k.observer(({label:t,config:e,value:n,onChange:r})=>{const a=K(),o=!!e.options_query_id,{state:l,error:u}=a.getDataStuffByID(e.options_query_id),c=l==="loading",d=e.min_width?e.min_width:"200px",f=o?c:!1,p=g=>r(g,!1);return i(yC,{label:t,options:e.options,style:{minWidth:"160px",width:d,maxWidth:f?d:"unset",borderColor:"#e9ecef"},disabled:f,value:n,onChange:p,errorMessage:u})}),vC=y.forwardRef(({label:t,description:e,...n},r)=>i("div",{ref:r,...n,children:i(s.Group,{noWrap:!0,children:h("div",{children:[i(s.Text,{size:"sm","data-role":"label",children:t}),i(s.Text,{size:"xs",color:"dimmed","data-role":"description",children:e})]})})})),xC=k.observer(({label:t,config:e,value:n,onChange:r})=>{const a=K(),o=!!e.options_query_id,{state:l,error:u}=a.getDataStuffByID(e.options_query_id),c=l==="loading";return y.useEffect(()=>{var p;const{default_selection_count:d}=e;if(!d)return;const f=((p=e.options[0])==null?void 0:p.value)??"";console.log("Selecting the first option by default. New value: ",f),r(f,!0)},[e.default_selection_count,e.options]),i(s.Select,{label:t,data:e.options,disabled:o?c:!1,value:n,onChange:r,error:!!u,placeholder:u,maxDropdownHeight:500,styles:{root:{width:e.width?e.width:"200px"},input:{borderColor:"#e9ecef"}},sx:{".mantine-Select-item[data-selected] .mantine-Text-root[data-role=description]":{color:"rgba(255,255,255,.7)"}},itemComponent:vC})});function wC({label:t,config:e,value:n,onChange:r}){return i(s.TextInput,{label:t,value:n||"",onChange:a=>r(a.currentTarget.value),...e,styles:{input:{borderColor:"#e9ecef"}}})}const CC=({rotate:t,onClick:e})=>i("svg",{onClick:e,className:"caret-icon",viewBox:"0 0 1024 1024",focusable:"false","data-icon":"caret-down",width:"14px",height:"14px",fill:"currentColor","aria-hidden":"true",transform:`rotate(${t})`,children:i("path",{d:"M840.4 300H183.6c-19.7 0-30.7 20.8-18.5 35l328.4 380.8c9.4 10.9 27.5 10.9 37 0L858.9 335c12.2-14.2 1.2-35-18.5-35z"})}),SC=({expanded:t,isLeaf:e,value:n,onClick:r,...a})=>(n==="0-0-value"&&console.log(a),e?i("span",{style:{width:"14px",display:"inline-block"}}):i(CC,{rotate:t?"0":"-90",onClick:r,...a})),_C=({onClick:t})=>h("svg",{onClick:t,className:"checkbox-icon",width:"16",height:"16",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[i("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),i("rect",{className:"border",x:"4",y:"4",width:"16",height:"16",rx:"2"}),i("rect",{className:"checkmark-indeterminate",x:"8",y:"8",width:"8",height:"8",rx:"2",stroke:"none"}),i("path",{className:"checkmark-checked",d:"M9 12l2 2l4 -4"})]}),kC=({onClick:t,...e})=>i(_C,{onClick:t,...e}),TC=s.createStyles((t,{radius:e=4})=>({root:{borderRadius:t.fn.radius(e),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-tree-select.rc-tree-select-open":{borderColor:"#228be6 !important",".rc-tree-select-selection-overflow-item-rest":{display:"none"},".rc-tree-select-selection-overflow-item-suffix":{display:"block"}},".rc-tree-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-tree-select-selection-search-mirror":{display:"none"},".rc-tree-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-tree-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-tree-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-tree-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-tree-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-tree-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-tree-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-tree-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:t.fontSizes.sm,fontWeight:500,color:"#212529"},dropdown:{fontSize:t.fontSizes.xs,zIndex:300,paddingTop:"6px","&.rc-tree-select-dropdown-slide-up-leave-active":{display:"none"},".rc-tree-select-tree-list .rc-tree-select-tree-list-holder":{},".rc-tree-select-tree-list, .rc-tree-select-empty":{backgroundColor:"#fff",border:"1px solid #e9ecef",padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px"},".rc-tree-select-empty":{padding:"8px 12px"},".rc-tree-select-tree-treenode":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"8px 12px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},"&.rc-tree-select-tree-treenode-checkbox-checked":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-checked":{stroke:"rgb(64, 192, 87)",animation:"check 200ms linear forwards"}},"&.rc-tree-select-tree-treenode-checkbox-indeterminate":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-indeterminate":{fill:"rgb(64, 192, 87)"}},".rc-tree-select-tree-switcher":{height:"16px",alignSelf:"center",paddingRight:"2px",transition:"color 200ms ease","&:hover":{color:"#228be6","svg.caret-icon":{color:"#228be6"}},"svg.caret-icon":{color:"#ced4da",transition:"all 200ms ease"}},".rc-tree-select-tree-node-content-wrapper":{display:"flex",flexWrap:"nowrap",overflow:"hidden",alignItems:"center",gap:"8px",transition:"color 200ms ease","&:hover":{color:"#228be6"}},".rc-tree-select-tree-iconEle":{height:"16px","svg .border":{stroke:"#ced4da"},".checkbox-icon .checkmark-indeterminate":{fill:"transparent",transition:"fill 200ms ease"},".checkbox-icon .checkmark-checked":{transform:"scale(1.2)",transformOrigin:"center center",strokeDasharray:10,strokeDashoffset:-10},"@keyframes check":{"0%":{strokeDashoffset:10},"100%":{strokeDashoffset:0}}},".rc-tree-select-tree-title":{textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden",".rc-tree-select-tree-title-desc":{fontSize:"12px",maxWidth:"100%",textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden"}},".rc-tree-select-tree-indent":{flexGrow:0,height:0,verticalAlign:"bottom"},".rc-tree-select-tree-indent-unit":{display:"inline-block",width:"1em"}}}})),DC=({disabled:t,classNames:e,styles:n,unstyled:r,radius:a,style:o,label:l,value:u,onChange:c,treeData:d,errorMessage:f})=>{const{classes:p,cx:g}=TC({radius:a},{name:"FilterTreeSelectWidget",classNames:e,styles:n,unstyled:r}),[m,C]=y.useState(!1),w=T=>{C(T)},_=m&&(u==null?void 0:u.length)>0;return h(s.Stack,{spacing:3,children:[h(s.Group,{position:"apart",children:[i(s.Text,{className:p.label,children:l}),_&&i(s.Tooltip,{label:`${u.length} selected`,children:i(s.Badge,{children:u.length})})]}),i(Va,{disabled:t,allowClear:!0,className:g(p.root,"check-select"),dropdownClassName:g(p.dropdown,""),onDropdownVisibleChange:w,transitionName:"rc-tree-select-dropdown-slide-up",choiceTransitionName:"rc-tree-select-selection__choice-zoom",style:o,treeLine:!0,clearIcon:()=>i(s.CloseButton,{}),switcherIcon:SC,treeIcon:kC,maxTagTextLength:10,value:u,treeData:d,notFoundContent:i(al,{errorMessage:f}),treeNodeFilterProp:"filterBasis",treeCheckable:!0,showCheckedStrategy:Va.SHOW_PARENT,onChange:c,onSelect:console.log,maxTagCount:0,maxTagPlaceholder:T=>`${T.length} selected`})]})},IC=k.observer(({label:t,config:e,value:n,onChange:r})=>{const{treeData:a,treeDataLoading:o,errorMessage:l}=e,u=e.min_width?e.min_width:"200px",d=!!e.options_query_id?o:!1;return i(DC,{disabled:d,style:{minWidth:"160px",width:u,maxWidth:d?u:"unset",borderColor:"#e9ecef"},value:n,onChange:f=>r(f,!1),treeData:a,errorMessage:l,label:t})}),MC=k.observer(({filter:{type:t,config:e,key:n,...r},formFieldProps:a})=>{switch(t){case"select":return i(xC,{...r,...a,config:e});case"multi-select":return i(bC,{...r,...a,config:e});case"tree-select":return i(IC,{...r,...a,config:e});case"text-input":return i(wC,{...r,...a,config:e});case"date-range":return i(il,{...r,...a,config:e});case"checkbox":return i(gC,{...r,...a,config:e});default:return null}}),sl=k.observer(y.forwardRef(({filter:t,...e},n)=>i("div",{className:"filter-root",ref:n,children:i(Fe,{children:i(MC,{filter:t,formFieldProps:e})})}))),ol=k.observer(function({view:e}){const n=K(),{control:r,handleSubmit:a,reset:o}=v.useForm({defaultValues:n.filters.values,reValidateMode:"onBlur"}),l=v.useWatch({control:r});y.useEffect(()=>{o(n.filters.values)},[n.filters.values,o]),y.useEffect(()=>{n.filters.updatePreviewValues(l)},[l]);const u=n.filters.visibleInView(e.id),c=y.useMemo(()=>u.every(g=>g.should_auto_submit),[u]),d=y.useMemo(()=>u.filter(g=>x.get(g,"config.required",!1)),[u]),f=y.useMemo(()=>d.length===0?!1:d.some(g=>!g.requiredAndPass(l[g.key])),[l,d]);if(u.length===0)return null;const p=(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:h(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(sl,{filter:g,value:m.value,onChange:p(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"})})]})})}),KT="";function EC(t){return t?["<p><br></p>","<p></p>"].includes(t):!0}const ll=k.observer(()=>{const{freezeLayout:t}=y.useContext(ft),[e,n]=y.useState(!1),{panel:r}=Ae();return y.useEffect(()=>{t(e)},[e]),EC(r.description)?null:h(N,{children:[i(s.Modal,{opened:e,onClose:()=>n(!1),title:r.title,withCloseButton:!1,withinPortal:!0,zIndex:310,children:i(Yn,{value:r.description,styles:{root:{border:"none"},content:{padding:0}}})}),i(s.Tooltip,{label:"Click to see description",position:"top-start",withinPortal:!0,children:i(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>n(a=>!a),sx:{verticalAlign:"baseline",cursor:"pointer"},children:i(I.InfoCircle,{size:20})})})]})}),AC=k.observer(({view:t})=>{const e=ge(),n=K(),r=Ke.useModals(),{panel:a}=Ae(),{id:o}=a,{inEditMode:l}=y.useContext(ft),{viewPanelInFullScreen:u,inFullScreen:c}=y.useContext(_i),d=()=>{n.duplicatePanelByID(o,t.id)},f=()=>{e.editor.open(["_VIEWS_",t.id,"_PANELS_",o])},p=()=>r.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>n.removePanelByID(o,t.id),confirmProps:{color:"red"},zIndex:320}),g=y.useCallback(()=>{u(o)},[o,u]),m=!c&&t.type!==H.Modal;return i(N,{children:i(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:h(s.Menu,{withinPortal:!0,children:[i(s.Menu.Target,{children:i(s.Box,{className:"panel-dropdown-target",sx:{width:"100%",height:"25px"}})}),h(s.Menu.Dropdown,{children:[i(s.Menu.Item,{onClick:a.refreshData,icon:i(I.Refresh,{size:14}),children:"Refresh"}),i(s.Menu.Item,{onClick:a.downloadData,icon:i(I.Download,{size:14}),children:"Download Data"}),m&&i(s.Menu.Item,{onClick:g,icon:i(I.ArrowsMaximize,{size:14}),disabled:l,children:"Full Screen"}),l&&h(N,{children:[i(s.Divider,{label:"Edit",labelPosition:"center"}),i(s.Menu.Item,{onClick:f,icon:i(I.Settings,{size:14}),children:"Settings"}),i(s.Menu.Item,{onClick:d,icon:i(I.Copy,{size:14}),children:"Duplicate"}),i(s.Menu.Item,{color:"red",onClick:p,icon:i(I.Trash,{size:14}),children:"Delete"})]})]})]})})})}),zC=k.observer(({panel:t})=>h(s.Stack,{children:[t.queryErrors.map((e,n)=>i(s.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:e},`${n}-${e}`)),t.queryStateMessages.map((e,n)=>i(s.Text,{color:"gray",align:"center",children:e},`${n}-${e}`))]}));var ul=(t=>(t.migrated="migrated",t.nothingToMigrate="nothingToMigrate",t.checkFailed="checkFailed",t.migrationFailed="migrationFailed",t))(ul||{}),Zn=(t=>(t.notStarted="notStarted",t.inProgress="inProgress",t.done="done",t))(Zn||{});class $C{constructor(e){V(this,"vizInstance");V(this,"operationManager");V(this,"triggerManager");V(this,"vizManager");V(this,"runningMigration");V(this,"panelModel");V(this,"status","notStarted");this.panelModel=e.getRequired(we.instanceScope.panelModel),this.vizInstance=e.getRequired(we.instanceScope.vizInstance),this.operationManager=e.getRequired(we.instanceScope.operationManager),this.triggerManager=e.getRequired(we.instanceScope.triggerManager),this.vizManager=e.getRequired(we.vizManager)}async createMigrationTask(){const e=[];try{await this.instanceNeedMigration()&&e.push(()=>this.runInstanceMigration()),await this.interactionNeedMigration()&&e.push(()=>this.runInteractionMigration())}catch(n){return console.warn("check migration failed",n),"checkFailed"}if(e.length===0)return"nothingToMigrate";try{return await Promise.all(e.map(n=>n())),"migrated"}catch(n){return console.warn("migration failed",n),"migrationFailed"}}async runMigration(){return this.runningMigration||(this.status="inProgress",this.runningMigration=this.createMigrationTask().then(e=>(this.status="done",e))),this.runningMigration}async runInteractionMigration(){await this.operationManager.runMigration(),await this.triggerManager.runMigration()}async runInstanceMigration(){const e=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData,panelModel:this.panelModel};await e.migrator.migrate(n)}async instanceNeedMigration(){const e=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData};return e.migrator.needMigration(n)}async interactionNeedMigration(){return await this.operationManager.needMigration()||await this.triggerManager.needMigration()}}function cl(t){const{panel:e}=Ae();return y.useCallback(n=>{const r=n.getRequired(we.vizManager),a=r.resolveComponent(t.viz.type);return n.createScoped().provideFactory(we.instanceScope.vizInstance,()=>r.getOrCreateInstance(t)).provideFactory(we.instanceScope.interactionManager,o=>{const l=o.getRequired(we.instanceScope.vizInstance);return new gi(l,a,Un)}).provideFactory(we.instanceScope.operationManager,o=>o.getRequired(we.instanceScope.interactionManager).operationManager).provideFactory(we.instanceScope.triggerManager,o=>o.getRequired(we.instanceScope.interactionManager).triggerManager).provideValue(we.instanceScope.panelModel,e).provideFactory(we.instanceScope.migrator,o=>new $C(o))},[t.viz.type,t.viz.conf])}function dl(t){const[e,n]=y.useState(!1),r=rl().getRequired(we.instanceScope.migrator);return J.useAsyncEffect(async()=>{const a=r.status===Zn.notStarted;n(r.status===Zn.done),r.status===Zn.notStarted&&r.runMigration().then(o=>{o===ul.migrated&&a&&(t==null||t())}).finally(()=>{n(!0)})},[r]),e}function pl(t,e){const n=rl().getRequired(we.instanceScope.vizInstance);return y.useEffect(()=>(n.instanceData.setItem(null,e.viz.conf),n.instanceData.watchItem(null,r=>{t(r)})),[t,e.viz.type]),n}function LC({setVizConf:t,...e}){const{panel:n}=e,r=pl(t,n),a=dl(()=>{hn.showNotification({title:`${n.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})});return J.useAsyncEffect(async()=>{await r.instanceData.setItem(null,n.viz.conf)},[r,n.viz.type]),a?i(Uu,{...e}):i(s.Text,{children:"Checking update..."})}function OC(t){const{panel:e,setVizConf:n}=t;pl(n,e);const{inEditMode:r}=y.useContext(ft);return dl(()=>{r&&hn.showNotification({title:`${e.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?i(Ku,{...t}):i(s.Text,{children:"Checking update"})}const UT="";function PC(t,e){const{vizManager:n}=y.useContext(it),{panel:{viz:r,title:a,id:o,description:l,queryIDs:u,variables:c}}=Ae(),d={title:a,id:o,description:l,queryIDs:u,viz:r,layout:e},f=cl(d);try{return n.resolveComponent(r.type),i(Jn,{configure:f,children:i(OC,{setVizConf:r.setConf,panel:d,data:t,variables:c,vizManager:n})})}catch(p){return console.info(x.get(p,"message")),null}}const BC=k.observer(function({data:e}){const{ref:n,width:r,height:a}=Ie.useElementSize(),o=PC(e,{w:r,h:a});return i("div",{className:"viz-root",ref:n,children:r&&a&&i(Fe,{children:o})})}),hl=k.observer(({panel:t,height:e})=>h(s.Flex,{direction:"column",sx:{height:e,position:"relative",width:"100%"},children:[i(s.LoadingOverlay,{visible:t.dataLoading,exitTransitionDuration:0}),!t.canRenderViz&&i(zC,{panel:t}),t.canRenderViz&&i(BC,{data:t.data})]})),XT="",VC=k.observer(function(){const{panel:e}=Ae(),{title:n}=e;return n?i(s.Group,{grow:!0,position:"center",px:20,className:"panel-title-wrapper",sx:{flexGrow:1},children:i(s.Text,{align:"center",lineClamp:1,weight:"bold",children:n})}):null});function NC(t){return!["richText","button"].includes(t)}const qC={border:"1px solid #e9ecef"},FC={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function GC(t,e){return t.style.border.enabled?qC:e?FC:{border:"1px dashed transparent"}}const Hn=k.observer(function({panel:e,view:n}){const{inEditMode:r}=y.useContext(ft),a=e.title?"calc(100% - 25px - 5px)":"100%",o=GC(e,r),u=NC(e.viz.type)||r;return i(wr,{value:{panel:e,data:e.data,loading:e.dataLoading,errors:e.queryErrors},children:h(s.Box,{className:"panel-root",p:5,pt:0,sx:{...o},children:[i(s.Box,{sx:{position:"absolute",left:0,top:0,height:28,zIndex:310},children:i(ll,{})}),u&&i(AC,{view:n}),i(VC,{}),i(hl,{panel:e,height:a})]})})}),JT="",WC=y.forwardRef(({h:t},e)=>i(s.ActionIcon,{ref:e,className:"react-grid-customDragHandle",sx:{userSelect:"none",cursor:"grab",position:"absolute",top:5,right:t>38?5:20,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",children:i(I.ArrowsMove,{size:16})})),RC=y.forwardRef(({handleAxis:t,...e},n)=>i(s.ActionIcon,{ref:n,className:"react-grid-customResizeHandle",sx:{userSelect:"none",cursor:"nwse-resize",position:"absolute",bottom:0,right:0,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",...e,children:i(I.ChevronDownRight,{size:16})})),jC=fn.WidthProvider(fn),YC=k.observer(({view:t,className:e="layout"})=>{const n=K(),{panels:r,layouts:a}=n.panels.panelsByIDs(t.panelIDs),o=y.useCallback(u=>{u.forEach(({i:c,...d})=>{const f=n.panels.findByID(c);f&&f.layout.set(d)})},[n]),l=(u,c,d,f)=>{d.h<30&&(d.h=30,f.h=30),d.w<4&&(d.w=4,f.w=4)};return i(jC,{onLayoutChange:o,className:`dashboard-layout ${e}`,rowHeight:1,cols:36,margin:[0,0],isBounded:!0,isDraggable:!0,isResizable:!0,layout:a,draggableHandle:".react-grid-customDragHandle",resizeHandle:i(RC,{}),onResize:l,children:r.map((u,c)=>h("div",{"data-grid":{...u.layout},className:"panel-grid-item",children:[i(WC,{h:u.layout.h}),i(Hn,{view:t,panel:u})]},u.id))})}),QC=fn.WidthProvider(fn),KC=k.observer(function({view:e,className:n="layout"}){const{panels:r,layouts:a}=K().panels.panelsByIDs(e.panelIDs);return i(QC,{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(Hn,{view:e,panel:o})},o.id))})}),UC=k.observer(({children:t})=>i(s.Box,{pt:10,pb:100,children:t}));function fl(t){return t.replace(/(vw|vh)/,"%")}const XC=k.observer(({children:t,view:e})=>{const n=e.config,{width:r,height:a}=y.useMemo(()=>({width:fl(n.width),height:fl(n.height)}),[n.width,n.height]);return i(s.Box,{sx:{height:"100%","> div:not(.mantine-Modal-root)":{height:"100%"}},children:i(s.Modal,{size:n.width,opened:!0,onClose:x.noop,withCloseButton:!1,title:n.custom_modal_title.value,trapFocus:!0,onDragStart:o=>{o.stopPropagation()},styles:{root:{position:"relative",height:"100%"},overlay:{position:"absolute !important"},inner:{position:"relative",top:"50%",left:"50%",right:"unset",bottom:"unset",transform:"translate(-50%, -50%)",width:r,height:a},content:{border:"1px solid #efefef"},body:{maxHeight:"calc(100vh - 325px)"}},withinPortal:!1,transitionProps:{duration:0},children:t})})}),JC=({variant:t,orientation:e})=>{const n={tab:{},panel:{padding:"16px"}};return t==="pills"&&e==="horizontal"&&(n.tab.paddingTop="6px",n.tab.paddingBottom="6px"),e==="vertical"&&(n.tab["&.add-a-tab"]={paddingTop:"1px",paddingBottom:"1px"},n.tab["&.add-a-tab .mantine-Tabs-tabLabel"]={marginLeft:"auto",marginRight:"auto"}),n},ZC=t=>t.color?{"&[data-active], &[data-active]:hover":{borderColor:t.color?t.color:"..."}}:{},HC=k.observer(({children:t,view:e})=>{const n=Ke.useModals(),r=K(),a=y.useMemo(()=>r.views.options.filter(c=>c.type===H.Division),[e.id,r.views.options]),o=e.config,l=c=>n.openConfirmModal({title:"Delete this tab?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{o.removeTab(c)},confirmProps:{color:"red"},zIndex:320}),u=o.tabs.length===0;return h(s.Box,{className:"preview-view-tabs",children:[h(s.Tabs,{variant:o.variant,orientation:o.orientation,defaultValue:o.tabs.length>0?o.tabs[0].id:"0",styles:JC(o),children:[h(s.Tabs.List,{grow:o.grow,children:[o.tabs.map(c=>i(s.Tabs.Tab,{value:c.id,sx:ZC(c),children:c.name??c.id},c.id)),i(s.Tabs.Tab,{onClick:o.addTab,value:"add",className:"add-a-tab",children:i(I.Plus,{size:18,color:"#228be6"})})]}),o.tabs.map((c,d)=>{const f=r.views.findByID(c.view_id);return h(s.Tabs.Panel,{value:c.id,sx:{position:"relative"},children:[h(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}),h(s.Stack,{mx:"auto",mt:100,sx:{width:"300px",position:"relative",zIndex:200},children:[i(s.TextInput,{label:"Tab Name",value:c.name,onChange:p=>c.setName(p.currentTarget.value)}),i(s.Select,{label:"View",value:c.view_id,onChange:c.setViewID,data:a}),i(s.ColorInput,{label:"Color",value:c.color,onChange:c.setColor,disabled:o.variant!=="default"}),f&&h(s.Button,{mt:20,variant:"gradient",leftIcon:i(L.IconArrowsLeftRight,{size:18}),gradient:{from:"cyan",to:"indigo"},onClick:()=>r.views.setIDOfVIE(f.id),children:["Swith to View: ",f.name]}),i(s.Button,{mt:20,variant:"subtle",color:"red",onClick:()=>l(d),disabled:u,leftIcon:i(L.IconTrash,{size:14}),children:"Delete This Tab"})]})]}),f&&i(er,{view:f})]},c.id)})]}),t]})}),e1=k.observer(({view:t,children:e})=>{switch(t.type){case H.Modal:return i(XC,{view:t,children:e});case H.Tabs:return i(HC,{view:t,children:e});case H.Division:default:return i(UC,{children:e})}}),gl=k.observer(function({view:e}){return i(_i.Provider,{value:{viewPanelInFullScreen:x.noop,inFullScreen:!1},children:i(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:i(e1,{view:e,children:h(s.Box,{sx:{position:"relative"},children:[i(s.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:i(ol,{view:e})}),i(YC,{view:e})]})})})})}),t1={modal:{display:"flex",flexDirection:"column",flexWrap:"nowrap"},body:{display:"flex",height:"calc(100vh - 88px)"}},n1=k.observer(function({view:e,panel:n,exitFullScreen:r}){return i(s.Modal,{opened:!0,fullScreen:!0,onClose:r,title:i(s.Button,{color:"blue",size:"xs",onClick:r,leftIcon:i(I.ArrowLeft,{size:20}),children:"Exit fullscreen"}),styles:t1,children:i(s.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:i(Hn,{view:e,panel:n})})})});function r1(t,e,n){const{panels:r}=K(),a=t.id==="Main",[o,l]=y.useState(()=>a&&r.findByID(e)?e:null),u=y.useCallback(p=>{l(p),a&&n(p)},[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 i1=k.observer(({children:t})=>i(s.Box,{children:t})),a1=k.observer(({children:t,view:e})=>{const n=K(),r=e.config,a=n.views.visibleViewIDs.includes(e.id),o=()=>n.views.rmVisibleViewID(e.id);return i(s.Modal,{size:r.width,centered:!0,opened:a,onClose:o,withCloseButton:!1,title:r.custom_modal_title.value,trapFocus:!0,onDragStart:l=>{l.stopPropagation()},styles:{content:{border:"1px solid #efefef"},body:{maxHeight:r.height,overflow:"auto"}},transitionProps:{duration:0},children:t})}),s1=t=>t.color?{"&[data-active], &[data-active]:hover":{borderColor:t.color?t.color:"..."}}:{},o1=k.observer(({children:t,view:e})=>{const n=K(),r=e.config;return h(s.Box,{className:"render-view-tabs",children:[h(s.Tabs,{variant:r.variant,orientation:r.orientation,defaultValue:r.tabs.length>0?r.tabs[0].id:"0",styles:{panel:{padding:r.orientation==="horizontal"?"16px 0px":"0"}},keepMounted:!1,children:[i(s.Tabs.List,{grow:r.grow,children:r.tabs.map(a=>i(s.Tabs.Tab,{value:a.id,sx:s1(a),disabled:!a.view_id,children:a.name??a.id},a.id))}),r.tabs.map(a=>{const o=n.views.findByID(a.view_id);return o?i(s.Tabs.Panel,{value:a.id,children:i(er,{view:o})},a.id):null})]}),t]})}),l1=k.observer(({view:t,children:e})=>{switch(t.type){case H.Modal:return i(a1,{view:t,children:e});case H.Tabs:return i(o1,{view:t,children:e});case H.Division:default:return i(i1,{children:e})}}),er=k.observer(function({view:e}){const{fullScreenPanelID:n,setFullScreenPanelID:r}=bs(),{viewPanelInFullScreen:a,exitFullScreen:o,inFullScreen:l,fullScreenPanel:u}=r1(e,n,r);return i(_i.Provider,{value:{viewPanelInFullScreen:a,inFullScreen:l},children:h(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:[l&&i(n1,{view:e,panel:u,exitFullScreen:o}),i(l1,{view:e,children:h(s.Box,{sx:{position:"relative"},children:[!l&&i(s.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:i(ol,{view:e})}),!l&&i(KC,{view:e})]})})]})})});function ki(t){return y.useCallback(e=>e.provideValue(we.pluginManager,t.pluginManager).provideValue(we.vizManager,t.vizManager).provideValue(we.colorManager,t.colorManager),[])}const u1=k.observer(({headerMenuItems:t=null})=>{const e=ge(),n=K(),r=()=>{const a=JSON.stringify(n.json,null,2),o=`${e.name}__${n.name}`;Tu(o,a)};return h(s.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:310,children:[i(s.Menu.Target,{children:i(s.ActionIcon,{variant:"light",color:"blue",children:i(L.IconMenu2,{size:14})})}),h(s.Menu.Dropdown,{children:[i(s.Menu.Item,{icon:i(L.IconDownload,{size:14}),onClick:n.queries.downloadAllData,children:"Download Data"}),i(s.Menu.Item,{icon:i(L.IconCode,{size:14}),onClick:r,children:"Download Schema"}),t]})]})}),c1=k.observer(({saveDashboardChanges:t})=>{const e=Ke.useModals(),n=K(),r=()=>{e.openConfirmModal({title:h(s.Group,{position:"left",children:[i(L.IconAlertTriangle,{size:18,color:"red"}),i(s.Text,{children:"You are reverting changes"})]}),labels:{confirm:"Confirm",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:()=>n.reset(),zIndex:320,withCloseButton:!1})},a=n.changed;return h(s.Group,{spacing:0,children:[i(s.Button,{color:"green",variant:"filled",size:"xs",leftIcon:i(L.IconDeviceFloppy,{size:18}),onClick:t,disabled:!a,sx:{borderTopRightRadius:0,borderBottomRightRadius:0},children:"Save Changes"}),h(s.Menu,{width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:320,disabled:!a,children:[i(s.Menu.Target,{children:i(s.ActionIcon,{variant:"default",disabled:!a,sx:{height:"30px",borderTopLeftRadius:0,borderBottomLeftRadius:0,svg:{fill:"rgb(173, 181, 189)",stroke:"none"}},children:i(L.IconCaretDown,{size:18})})}),i(s.Menu.Dropdown,{children:i(s.Menu.Item,{icon:i(L.IconRecycle,{size:14,color:"red"}),disabled:!a,onClick:r,children:"Revert Changes"})})]})]})}),d1=k.observer(({saveDashboardChanges:t,headerSlot:e=null,headerMenuItems:n})=>{const r=Hl.useNavigate(),a=ge(),o=()=>{r(`/dashboard/${a.id}`)},l=Ke.useModals(),u=()=>{l.openConfirmModal({title:h(s.Group,{position:"left",children:[i(L.IconAlertTriangle,{size:18,color:"red"}),i(s.Text,{children:"There are unsaved changes"})]}),labels:{confirm:"Discard",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:o,zIndex:320,withCloseButton:!1})},c=a.content.changed;return i(s.Header,{height:60,px:"md",py:0,sx:{zIndex:299},children:h(s.Group,{position:"apart",sx:{height:60,minWidth:"1000px",position:"relative"},children:[h(s.Group,{children:[i(s.Button,{size:"xs",color:c?"red":"green",leftIcon:i(L.IconArrowLeft,{size:20}),onClick:c?u:o,children:h(s.Group,{spacing:4,children:["End Editing",i(s.Text,{td:"underline",children:a.name})]})}),i(c1,{saveDashboardChanges:t})]}),h(s.Group,{position:"right",sx:{flexGrow:1},children:[e,i(u1,{headerMenuItems:n})]})]})})}),p1={position:"fixed",top:60,left:0,right:0,height:30,zIndex:299,borderBottom:"1px solid #e9ecef",background:"rgba(233,236,239, 0.15)"},h1=k.observer(()=>{const t=K();return i(s.Box,{sx:p1,pl:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},children:h(s.Group,{position:"apart",align:"center",sx:{height:"30px"},pr:16,children:[i(s.Button,{variant:"outline",color:"blue",radius:0,size:"xs",disabled:!t.views.VIE,onClick:()=>t.addANewPanel(t.views.idOfVIE),leftIcon:i(L.IconPlaylistAdd,{size:20}),sx:{height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef",background:"rgb(231, 245, 255)"},children:"Add a Panel"}),i(s.Box,{}),i(s.Box,{})]})})}),f1=k.observer(t=>h(N,{children:[i(d1,{...t}),i(h1,{})]})),ZT="",HT="";function g1(t,e,n){const r=[];return t.filter(a=>"__INTERACTIONS"in a.viz.conf).forEach((a,o)=>{const l=e[a.id];l.data.interactions=x.get(l,"data.interactions",[]);const{__INTERACTIONS:u,__OPERATIONS:c,__TRIGGERS:d}=a.viz.conf;Object.entries(c).forEach(([f,p])=>{const{schemaRef:g,data:m}=p,{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 m1(t,e){const n=t.filters.keyLabelMap;return{edges:g1(t.panels.list,e,n),edgeNodes:[]}}function ml(t,e,n){return t*e+t*n}function y1(t,e,n){return t*e+(t-1)*n}const tr=25,Ti=40,yl=25,Di=350,b1=150,v1=150,bl=150,vl=300,nr=40,xl=25,x1=300;function w1(t,e){const n=x.keyBy(e,a=>a.id),r=[];return t.current.forEach((a,o)=>{a.panelIDs.forEach((l,u)=>{const c=ml(u,nr,xl)+Ti,d=n[l];if(!d){r.push({id:l,_node_type:"panel",parentNode:a.id,data:{label:`!: ${l}`},position:{x:tr,y:c},sourcePosition:Me.Position.Right,targetPosition:Me.Position.Left,style:{width:vl,height:nr}});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:tr,y:c},sourcePosition:Me.Position.Right,targetPosition:Me.Position.Left,style:{width:vl,height:nr}})})}),r}const C1={[H.Division]:"Div",[H.Modal]:"Modal",[H.Tabs]:"Tabs"},S1=Ko;function _1(t){return t.current.map((n,r)=>{const a=y1(n.panelIDs.length,nr,xl)+Ti+yl;let o=[];return n.type===H.Tabs&&(o=n.config.tabs.map(u=>u.view_id)),{id:n.id,_node_type:"view-root",_view_type:n.type,_view_level:0,_sub_view_ids:[],_tab_view_ids:o,data:{label:`${C1[n.type]}:${n.name}`},position:{x:0,y:0},sourcePosition:Me.Position.Right,targetPosition:Me.Position.Left,className:"light",style:{backgroundColor:S1[n.type],width:Di,height:a}}})}function k1(t){const e=x.keyBy(t,n=>n.id);t.forEach(n=>{n._node_type!=="view-root"||n._view_type!==H.Tabs||n._tab_view_ids.forEach(r=>{e[r].parentNode=n.id})})}function T1(t){const e=_1(t.views);k1(e);const n=w1(t.views,t.panels.list);return[...e,...n]}function D1({nodeMap:t,nodes:e,edges:n}){e.forEach(r=>{r._node_type!=="view-root"||r._view_type!==H.Tabs||(r.sourcePosition=Me.Position.Bottom,r.style.width=Di+tr*2,r.style.height=yl+r._tab_view_ids.reduce((a,o)=>{const l=t[o];l.position.y=a,l.position.x=tr;const u=l.style.height;return a+u+20},Ti))})}function I1({nodeMap:t,nodes:e,edges:n}){n.filter(r=>r.label==="Open View").forEach(r=>{const a=t[r.source],o=t[r.target];if(!a||!o||!a.parentNode)return;const l=t[a.parentNode];l._node_type!=="view-root"||o._node_type!=="view-root"||(o._view_level+=1+l._view_level,l._sub_view_ids.push(o.id))}),e.sort((r,a)=>r._node_type==="view-root"&&a._node_type==="view-root"?r._view_level-a._view_level:r._node_type!=="view-root"&&a._node_type!=="view-root"?0:r._node_type==="view-root"?-1:1)}function M1({nodeMap:t,nodes:e,edges:n}){const r={};n.forEach(a=>{if(a.label!=="Open View")return;const o=t[a.source],l=t[a.target];if(o&&l&&o.parentNode){const u=t[o.parentNode],c=u.position.x,d=Number(x.get(l,"style.height",0)),f=Number(u.style.width);l.position.x=c+f+x1,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+bl}})}function E1({nodeMap:t,nodes:e,edges:n}){const r=new Set,a=new Set;n.forEach(l=>{r.add(l.source),a.add(l.target)}),e.filter(l=>l._node_type!=="view-root"||l.id==="Main"||l.parentNode?!1:!r.has(l.id)&&!a.has(l.id)).forEach((l,u)=>{l.position.x=ml(u,Di,v1),l.position.y=0-b1-bl})}function A1({nodeMap:t,nodes:e,edges:n}){const r={nodeMap:t,nodes:e,edges:n};return E1(r),I1(r),D1(r),M1(r),{nodes:e,edges:n}}function z1(t){const e=T1(t),n=x.keyBy(e,c=>c.id),{edges:r,edgeNodes:a}=m1(t,n),o=[...e,...a],l=x.keyBy(o,c=>c.id),u={edges:x.uniqBy(r,c=>c.id),nodes:o,nodeMap:l};return A1(u)}const eD="",Ii={"builtin:op:open-link":i(s.ThemeIcon,{color:"blue",size:20,radius:"xl",children:i(L.IconCircleDashed,{size:14})}),"builtin:op:set_filter_values":i(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:i(L.IconCircleDot,{size:14})}),"builtin:op:clear_filter_values":i(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:i(L.IconCircleOff,{size:14})})};function $1(t){const e=[];return t.forEach(n=>{switch(n.schemaRef){case"builtin:op:open-link":e.push({key:n.urlTemplate,icon:Ii[n.schemaRef],text:h(s.Group,{spacing:4,children:[i(s.Text,{children:"Open: "}),i(s.Text,{color:"dimmed",children:n.shortURLTemplate})]})});return;case"builtin:op:set_filter_values":n.filters.forEach(({key:r,label:a})=>{e.push({key:n.schemaRef+r,icon:Ii[n.schemaRef],text:i(s.Group,{spacing:4,children:h(s.Text,{children:["Set Filter: ",a]})})})});return;case"builtin:op:clear_filter_values":n.filters.forEach(({key:r,label:a})=>{e.push({key:n.schemaRef+r,icon:Ii[n.schemaRef],text:i(s.Group,{spacing:4,children:h(s.Text,{children:["Clear Filter: ",a]})})})});return}}),e}const L1=y.memo(({data:t,isConnectable:e,sourcePosition:n=Me.Position.Right,targetPosition:r=Me.Position.Left,...a})=>{const o=y.useMemo(()=>$1(t.interactions),[t.interactions]);return h(N,{children:[i(Me.Handle,{type:"target",position:r,isConnectable:e}),i(s.Box,{sx:{position:"absolute",top:0,right:0},children:i(I.ChevronsUpRight,{size:12})}),h(s.HoverCard,{shadow:"xl",withinPortal:!0,children:[i(s.HoverCard.Target,{children:i(s.Text,{children:t.label})}),i(s.HoverCard.Dropdown,{children:i(s.List,{spacing:"xs",size:"sm",center:!0,children:o.map(l=>i(s.List.Item,{icon:l.icon,children:l.text},l.key))})})]}),i(Me.Handle,{type:"source",position:n,isConnectable:e})]})}),tD="",O1={interaction:L1},P1=k.observer(()=>{const t=K(),{edges:e,nodes:n}=z1(t);return h(Me,{nodes:n,edges:e,onNodesChange:x.noop,onEdgesChange:x.noop,onConnect:x.noop,className:"interactions-viewer",fitView:!0,nodeTypes:O1,children:[i(Me.MiniMap,{}),i(Me.Controls,{}),i(Me.Background,{})]})}),B1=k.observer(({opened:t,close:e})=>{const{freezeLayout:n}=y.useContext(ft);return y.useEffect(()=>{n(t)},[t]),i(s.Modal,{size:"96vw",opened:t,onClose:e,title:"Interactions",trapFocus:!0,onDragStart:r=>{r.stopPropagation()},styles:{body:{height:"90vh"},content:{transform:"none !important"}},zIndex:300,children:i(P1,{})})}),V1={"> 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 N1({onClick:t,name:e,active:n,openSettings:r}){return h(s.Box,{sx:{position:"relative"},children:[i(s.UnstyledButton,{sx:a=>({display:"block",width:"100%",padding:a.spacing.xs,borderRadius:0,position:"relative",color:a.black,"&:hover":{backgroundColor:a.colors.gray[0]},backgroundColor:n?a.colors.gray[2]:"transparent"}),children:i(s.Group,{sx:{width:"calc(100% - 28px)"},onClick:t,children:i(s.Text,{size:"sm",children:e})})}),n&&i(s.Tooltip,{label:"Edit",position:"right",withinPortal:!0,children:i(s.ActionIcon,{onClick:r,variant:"light",color:"blue",sx:{position:"absolute",top:0,bottom:0,height:"100%",right:0,zIndex:0,borderRadius:0},children:i(L.IconAdjustments,{size:16})})})]})}const q1=k.observer(()=>{const t=ge(),e=K(),n=y.useCallback(a=>()=>e.views.setIDOfVIE(a),[e]),r=a=>{t.editor.open(["_VIEWS_",a])};return h(s.Box,{sx:{position:"relative"},children:[e.views.options.map(a=>i(N1,{active:e.views.idOfVIE===a.value,name:a.label,onClick:n(a.value),openSettings:()=>r(a.value)},a.value)),i(s.Divider,{variant:"dashed"}),i(s.Button,{variant:"subtle",rightIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",color:"blue",onClick:e.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"space-between"}},children:"Add a View"})]})}),F1=k.observer(()=>{const t=ge(),e=K(),n=()=>{if(!e.queries.firstID){t.editor.open(["_QUERIES_",""]);return}t.editor.open(["_QUERIES_",e.queries.firstID])},r=()=>{if(!e.filters.firstID){t.editor.open(["_FILTERS_",""]);return}t.editor.open(["_FILTERS_",e.filters.firstID])},[a,o]=y.useState(!1),l=()=>o(!0),u=()=>o(!1);return h(s.Navbar,{p:0,width:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},zIndex:299,children:[h(s.Navbar.Section,{children:[h(s.Group,{grow:!0,spacing:0,sx:{...V1,button:{borderWidth:0,borderBottomWidth:1,borderColor:"#e9ecef"}},children:[i(s.Tooltip,{label:"Filters",withinPortal:!0,children:i(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:r,children:i(L.IconFilter,{size:18})})}),i(s.Tooltip,{label:"Queries",withinPortal:!0,children:i(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:n,children:i(L.IconDatabase,{size:18})})}),i(s.Tooltip,{label:"Interactions Viewer",withinPortal:!0,children:i(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:l,children:i(L.IconLink,{size:18})})})]}),i(B1,{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(q1,{})}),i(s.Navbar.Section,{children:i(s.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:i(s.Button,{size:"xs",leftIcon:i(L.IconSettings,{size:20}),onClick:()=>t.editor.open([]),children:"Settings"})})})]})}),G1=k.observer(function({config:e}){return h(N,{children:[i(s.Checkbox,{checked:e.default_value,onChange:n=>e.setDefaultValue(n.currentTarget.checked),label:"Default Checked"}),i(ri,{label:"Description",value:e.description,onChange:e.setDescription,styles:{root:{flexGrow:1,minHeight:"400px"}}})]})}),W1=[{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"}],R1=k.observer(function({config:e}){return h(N,{children:[h(s.Group,{children:[i(s.Checkbox,{checked:e.required,onChange:n=>e.setRequired(n.currentTarget.checked),label:"Required"}),i(s.Checkbox,{checked:e.clearable,onChange:n=>e.setClearable(n.currentTarget.checked),disabled:e.max_days>0,label:"Clearable"}),i(s.Checkbox,{checked:e.allowSingleDateInRange,onChange:n=>e.setAllowSingleDateInRange(n.currentTarget.checked),label:"Allow choosing 1 day"})]}),i(s.Select,{data:W1,label:"Display Format",value:e.inputFormat,onChange:e.setInputFormat}),i(il,{label:"Default Value",config:e,value:e.default_value,onChange:e.setDefaultValue}),i(s.NumberInput,{label:"Max Days",description:h(s.Group,{position:"apart",children:[i(s.Text,{children:"Set 0 to disable."}),h(s.Group,{spacing:4,children:[i(s.Text,{children:"This feature requires"}),i(s.Text,{color:"blue",children:"Clearable"}),i(s.Text,{children:"to be checked"})]})]}),min:0,value:e.max_days,onChange:e.setMaxDays,hideControls:!0})]})}),Mi=k.observer(({value:t,onChange:e})=>{const n=K(),r=y.useMemo(()=>n.queries.options,[n.queries.current]),a=r.length===0;return i(s.Select,{label:"Pick a query",data:r,value:t,onChange:e,allowDeselect:!1,clearable:!0,sx:{flexGrow:1},disabled:a,error:a?"You need to add a query in Data Settings":void 0})}),j1=`
|
|
481
481
|
// row
|
|
482
482
|
{
|
|
483
483
|
label: string;
|
|
484
484
|
value: string;
|
|
485
485
|
description?: string; // optional
|
|
486
486
|
}
|
|
487
|
-
`,
|
|
487
|
+
`,wl=()=>{const[t,e]=y.useState(!1);return h(N,{children:[i(s.Button,{variant:"subtle",compact:!0,onClick:()=>e(n=>!n),children:t?"Close":"Click to see expected data structure"}),i(s.Collapse,{in:t,children:i(St.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:j1})})]})},Y1=k.observer(function({config:e}){const n=()=>{e.addStaticOption({label:"",value:""})},r=e.static_options,a=[...r];return h(N,{children:[i(s.TextInput,{label:"Width",description:"At least 160px",value:e.min_width,onChange:o=>e.setMinWidth(o.currentTarget.value),placeholder:"default: 200px"}),i(s.Divider,{label:"Configure options",labelPosition:"center"}),h(s.Stack,{spacing:10,sx:{position:"relative",minHeight:"50px"},children:[e.usingQuery&&h(N,{children:[i(s.Overlay,{opacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),i(s.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:i(s.Text,{color:"white",size:16,children:"Using query"})})]}),r.length>0&&i(s.MultiSelect,{label:"Default Selection",data:a,value:[...e.default_value],onChange:e.setDefaultValue}),r.map((o,l)=>h(s.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[i(s.TextInput,{label:"Label",required:!0,value:e.static_options[l].label,onChange:u=>{e.static_options[l].setLabel(u.currentTarget.value)},sx:{flexGrow:1}}),i(s.TextInput,{label:"Value",required:!0,value:e.static_options[l].value,onChange:u=>{e.static_options[l].setValue(u.currentTarget.value)},sx:{flexGrow:1}}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>e.removeStaticOption(l),sx:{position:"absolute",top:28,right:5},children:i(I.Trash,{size:16})})]},l)),i(s.Button,{mt:10,size:"xs",color:"blue",leftIcon:i(I.PlaylistAdd,{size:20}),onClick:n,sx:{width:"50%"},mx:"auto",children:"Add an Option"})]}),i(s.Divider,{label:"Or fetch options from database",labelPosition:"center"}),i(s.NumberInput,{value:e.default_selection_count,onChange:e.setDefaultSelectionCount,label:"Select first N options by default"}),i(Mi,{value:e.options_query_id,onChange:e.setOptionsQueryID}),i(wl,{})]})}),Q1=k.observer(function({config:e}){const n=()=>{e.addStaticOption({label:"",value:""})},r=e.static_options,a=[{label:"No default selection",value:""},...r];return h(N,{children:[i(s.Checkbox,{checked:e.required,onChange:o=>e.setRequired(o.currentTarget.checked),label:"Required"}),i(s.TextInput,{label:"Width",value:e.width,onChange:o=>e.setWidth(o.currentTarget.value),placeholder:"200px"}),i(s.Divider,{label:"Configure options",labelPosition:"center"}),h(s.Stack,{spacing:10,sx:{position:"relative",minHeight:"50px"},children:[e.usingQuery&&h(N,{children:[i(s.Overlay,{opacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),i(s.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:i(s.Text,{color:"white",size:16,children:"Using query"})})]}),r.length>0&&i(s.Select,{label:"Default Selection",data:a,value:e.default_value,onChange:e.setDefaultValue}),r.map((o,l)=>h(s.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[i(s.TextInput,{label:"Label",required:!0,value:e.static_options[l].label,onChange:u=>{e.static_options[l].setLabel(u.currentTarget.value)},sx:{flexGrow:1}}),i(s.TextInput,{label:"Value",required:!0,value:e.static_options[l].value,onChange:u=>{e.static_options[l].setValue(u.currentTarget.value)},sx:{flexGrow:1}}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>e.removeStaticOption(l),sx:{position:"absolute",top:28,right:5},children:i(I.Trash,{size:16})})]},l)),i(s.Button,{size:"xs",color:"blue",leftIcon:i(I.PlaylistAdd,{size:20}),onClick:n,sx:{width:"50%"},mx:"auto",children:"Add an Option"})]}),i(s.Divider,{label:"Or fetch options from database",labelPosition:"center"}),i(s.Checkbox,{checked:e.default_selection_count===1,onChange:o=>e.setDefaultSelectionCount(o.currentTarget.checked?1:0),label:"Select the first option by default"}),i(Mi,{value:e.options_query_id,onChange:e.setOptionsQueryID}),i(wl,{})]})}),K1=k.observer(function({config:e}){return h(N,{children:[i(s.TextInput,{label:"Default Value",value:e.default_value,onChange:n=>{e.setDefaultValue(n.currentTarget.value)}}),i(s.Checkbox,{checked:e.required,onChange:n=>e.setRequired(n.currentTarget.checked),label:"Required"})]})}),U1=`
|
|
488
488
|
// row
|
|
489
489
|
{
|
|
490
490
|
label: string;
|
|
@@ -492,7 +492,7 @@ Check the top-level render call using <`+P+">.")}return A}}function ql(S,A){{if(
|
|
|
492
492
|
parent_value: string;
|
|
493
493
|
description?: string;
|
|
494
494
|
}
|
|
495
|
-
`,U1=()=>{const[t,e]=y.useState(!1);return p(N,{children:[i(s.Button,{variant:"subtle",compact:!0,onClick:()=>e(n=>!n),children:t?"Close":"Click to see expected data structure"}),i(s.Collapse,{in:t,children:i(St.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:K1})})]})},X1=k.observer(function({config:e}){return p(N,{children:[i(s.TextInput,{label:"Min-width",value:e.min_width,onChange:n=>e.setMinWidth(n.currentTarget.value),placeholder:"200px"}),i(s.Divider,{label:"Fetch options from database",labelPosition:"center"}),i(s.NumberInput,{value:e.default_selection_count,onChange:e.setDefaultSelectionCount,label:"Select first N options by default"}),i(Mi,{value:e.options_query_id,onChange:e.setOptionsQueryID}),i(U1,{})]})}),J1=k.observer(function({filter:e}){const[n,r]=y.useState(e.plainDefaultValue);return y.useEffect(()=>{r(e.plainDefaultValue)},[e]),p(s.Box,{sx:{maxWidth:"480px"},children:[i(s.Text,{pb:"md",color:"gray",children:"Preview"}),i(sl,{filter:e,value:n,onChange:r}),i(s.Text,{pt:"lg",pb:"md",color:"gray",children:"Config"}),i(St.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(e,null,4)})]})}),Z1={select:Y1,"multi-select":j1,"tree-select":X1,"text-input":Q1,checkbox:F1,"date-range":W1},H1=[{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"}],eS=k.observer(function({filter:e}){const n=K(),r=y.useMemo(()=>Z1[e.type],[e.type]);return p(s.Group,{grow:!0,spacing:20,align:"top",children:[p(s.Box,{sx:{maxWidth:"600px"},children:[i(s.Text,{pb:"md",color:"gray",children:"Edit"}),p(s.Stack,{children:[p(s.Group,{noWrap:!0,children:[i(s.NumberInput,{label:"Placement Order",required:!0,value:e.order,onChange:e.setOrder,hideControls:!0,sx:{flexGrow:"1 !important"}}),e.auto_submit_supported&&i(s.Checkbox,{label:"Submit automatically",checked:e.auto_submit,onChange:a=>e.setAutoSubmit(a.currentTarget.checked),mt:22})]}),i(s.MultiSelect,{label:"Visible in...",data:n.views.options,value:[...e.visibleInViewsIDs],onChange:e.setVisibleInViewsIDs}),i(s.TextInput,{label:"Key",placeholder:"A unique key to refer",required:!0,value:e.key,onChange:a=>{e.setKey(a.currentTarget.value)}}),i(s.TextInput,{label:"Label",placeholder:"Label for this field",required:!0,value:e.label,onChange:a=>{e.setLabel(a.currentTarget.value)}}),i(s.Select,{label:"Widget",data:H1,required:!0,value:e.type,onChange:e.setType}),i(r,{config:e.config})]})]}),i(J1,{filter:e})]})}),tS=k.observer(({id:t})=>{const e=Ke.useModals(),n=ge(),r=K();if(t==="")return null;const a=r.filters.findByID(t);if(!a)return p(s.Text,{size:14,children:["Filter by ID[",t,"] is not found"]});const o=()=>{n.editor.setPath(["_FILTERS_",""])},l=()=>{e.openConfirmModal({title:"Delete this filter?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.filters.removeByID(t),o()},confirmProps:{color:"red"},zIndex:320})};return p(s.Stack,{sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",pb:30,children:[i(s.Group,{position:"right",pt:10,children:i(s.Button,{size:"xs",color:"red",leftIcon:i(I.Trash,{size:16}),onClick:l,children:"Delete this filter"})}),i(s.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:i(eS,{filter:a})})]})}),nS=k.observer(()=>{const t=K(),[e,n]=y.useState(()=>JSON.stringify(t.mock_context.current,null,4)),r=()=>{try{t.mock_context.replace(JSON.parse(e))}catch(o){hn.showNotification({title:"Failed",message:o.message,color:"red"})}},a=y.useMemo(()=>{try{return JSON.stringify(JSON.parse(e))!==JSON.stringify(t.mock_context.current)}catch{return!1}},[e,t.mock_context.current]);return p(s.Stack,{sx:{border:"1px solid #eee",borderLeft:"none",borderRight:"none",flexGrow:1,maxWidth:"unset"},children:[i(s.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:i(s.Text,{weight:500,children:"Mock Context"})}),p(s.Group,{grow:!0,px:"md",pb:"md",pt:0,sx:{flexGrow:1,position:"relative",alignItems:"flex-start"},children:[p(s.Stack,{spacing:10,sx:{maxWidth:"unset !important"},children:[i(s.Text,{children:"A valid json string is required"}),i(s.JsonInput,{validationError:"Invalid json",formatOnBlur:!0,autosize:!0,minRows:30,value:e,onChange:n,sx:{flexGrow:1}})]}),i(s.ActionIcon,{mr:5,variant:"filled",color:"blue",sx:{position:"absolute",right:12,top:0},disabled:!a,onClick:r,children:i(I.DeviceFloppy,{size:20})})]})]})}),rS=k.observer(()=>{const{panel:t}=Ae();return i(ri,{label:"Description",value:t.description,onChange:t.setDescription,styles:{root:{flexGrow:1}}})}),iS=k.observer(()=>{const{panel:t}=Ae(),{style:e}=t;return i(N,{children:i(s.Switch,{label:"Border",checked:e.border.enabled,onChange:n=>e.border.setEnabled(n.currentTarget.checked)})})}),aS=k.observer(()=>{const{panel:t}=Ae(),{title:e,setTitle:n}=t,[r,a]=Ie.useInputState(e),o=e!==r,l=y.useCallback(()=>{o&&n(r)},[o,r]);return y.useEffect(()=>{a(e)},[e]),i(s.TextInput,{value:r,onChange:a,label:p(s.Group,{children:[i(s.Text,{children:"Panel Title"}),i(s.ActionIcon,{variant:"subtle",color:"blue",disabled:!o,onClick:l,children:i(I.DeviceFloppy,{size:20})})]}),styles:{label:{display:"block",paddingBottom:"4px"}}})});function sS(){return p(s.Stack,{sx:{height:"100%"},children:[i(s.Divider,{label:"Style",labelPosition:"center",variant:"dashed"}),i(iS,{}),i(s.Divider,{label:"Info",labelPosition:"center",variant:"dashed"}),i(aS,{}),i(rS,{})]})}const oS=({queryID:t})=>{const e=K(),{state:n,error:r}=e.getDataStuffByID(t),a=y.useMemo(()=>e.queries.findByID(t),[e,t]);return n==="loading"?null:r?i(s.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:r}):a!=null&&a.stateMessage?i(s.Text,{color:"gray",align:"center",children:a.stateMessage}):null},lS={width:"fit-content",minWidth:"100%",tableLayout:"fixed",tr:{width:"fit-content"},th:{position:"relative"},".resizer":{position:"absolute",right:0,top:"50%",transform:"translateY(-50%)",cursor:"col-resize",userSelect:"none",touchAction:"none"},".resizer.isResizing":{color:"#228be6",opacity:"1"},"@media (hover: hover)":{".resizer":{opacity:"0"},"*:hover > .resizer":{color:"#228be6",opacity:"1"}}};function wl({data:t}){const e=y.useMemo(()=>{if(!Array.isArray(t)||t.length===0)return[];const r=Ue.createColumnHelper();return Object.keys(t[0]).map(a=>r.accessor(a,{cell:o=>o.getValue()}))},[t]),n=Ue.useReactTable({data:t,columns:e,columnResizeMode:"onChange",getCoreRowModel:Ue.getCoreRowModel()});return t.length===0?i(s.Box,{sx:{height:"5em"}}):i(Fe,{children:p(s.Table,{sx:lS,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:Ue.flexRender(a.column.columnDef.header,a.getContext()),i(s.ActionIcon,{onMouseDown:a.getResizeHandler(),onTouchStart:a.getResizeHandler(),className:`resizer ${a.column.getIsResizing()?"isResizing":""}`,children:i(I.ArrowBarToRight,{})})]},a.id))},r.id))}),i("tbody",{children:n.getRowModel().rows.map(r=>i("tr",{children:r.getVisibleCells().map(a=>i("td",{children:i(Fe,{children:Ue.flexRender(a.column.columnDef.cell,a.getContext())})},a.id))},r.id))})]})})}const Ei=k.observer(function({id:e,moreActions:n=null}){const r=K(),{data:a,state:o}=r.getDataStuffByID(e),l=o==="loading",c=()=>{r.queries.refetchDataByQueryID(e)},u=()=>{r.queries.downloadDataByQueryID(e)},d=y.useMemo(()=>Array.isArray(a)?a.slice(0,10):[],[a]),f=!Array.isArray(a)||a.length===0;return p(s.Stack,{sx:{border:"1px solid #eee"},children:[p(s.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[p(s.Group,{position:"left",children:[i(s.Text,{weight:500,children:"Preview Data"}),a.length>10&&p(s.Text,{size:"sm",color:"gray",children:["Showing 10 rows of ",a.length]})]}),p(s.Group,{pr:15,children:[n,i(s.ActionIcon,{variant:"subtle",color:"blue",disabled:l,onClick:c,children:i(I.Refresh,{size:16})}),i(s.ActionIcon,{variant:"subtle",color:"blue",disabled:l||f,onClick:u,children:i(I.Download,{size:16})})]})]}),p(s.Box,{sx:{position:"relative",overflow:"auto"},children:[i(s.LoadingOverlay,{visible:l}),i(oS,{queryID:e}),i(wl,{data:d})]})]})}),cS=k.observer(function(){const e=ge(),n=K(),{panel:r}=Ae(),[a,o]=y.useState(!1),l=c=>{e.editor.setPath(["_QUERIES_",c])};return p(N,{children:[i(s.Drawer,{opened:a,onClose:()=>o(!1),title:"Choose queries",padding:"xl",size:"xl",zIndex:320,children:i(s.Checkbox.Group,{orientation:"vertical",value:[...r.queryIDs],onChange:r.setQueryIDs,children:n.queries.options.map(c=>i(s.Checkbox,{label:c.label,value:c.value},c.value))})}),p(s.Stack,{spacing:6,children:[i(s.Group,{position:"right",children:i(s.Button,{variant:"light",size:"sm",leftIcon:i(L.IconLine,{size:16}),onClick:()=>o(!0),children:"Click me to choose queries for this panel"})}),r.queryIDs.length===1&&i(Ei,{id:r.queryIDs[0],moreActions:i(s.Tooltip,{label:"Open this query",children:i(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>l(r.queryIDs[0]),children:i(L.IconArrowCurveRight,{size:16})})})}),r.queryIDs.length>1&&p(s.Tabs,{defaultValue:r.queryIDs[0],children:[i(s.Tabs.List,{children:r.queries.map(c=>i(s.Tabs.Tab,{value:c.id,children:c.name},c.id))}),r.queries.map(c=>i(s.Tabs.Panel,{value:c.id,children:i(Ei,{id:c.id,moreActions:i(s.Tooltip,{label:"Open this query",children:i(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>l(c.id),children:i(L.IconArrowCurveRight,{size:16})})})})},c.id))]})]})]})}),uS=k.observer(()=>{const{panel:t}=Ae();return i(Fe,{children:i(s.Box,{sx:{height:"100%",flexGrow:0,flexShrink:0,width:"600px"},children:p(s.Stack,{mt:24,spacing:5,sx:{width:"600px",height:"450px",background:"transparent",borderRadius:"5px",border:"1px solid #e9ecef",borderWidth:t.style.border.enabled?"1px":"0px"},children:[p(s.Group,{position:"apart",noWrap:!0,sx:{flexGrow:0,flexShrink:0},children:[i(s.Group,{children:i(ll,{})}),i(s.Group,{grow:!0,position:"center",children:i(s.Text,{lineClamp:1,weight:"bold",children:t.title})}),i(s.Group,{position:"right",spacing:0,sx:{height:"28px"}})]}),i(s.Group,{px:5,pb:5,sx:{flexGrow:1},children:i(hl,{panel:t,height:"410px"})})]})})})}),Ai={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 dS{constructor(e){V(this,"panel");V(this,"selected");this.panel=e,ae.makeAutoObservable(this,{},{deep:!1,autoBind:!0})}get variables(){return this.panel.variables}addNew(){const e=this.panel.variables.filter(n=>n.name.startsWith(Ai.name)).length;this.panel.addVariable(x.cloneDeep({...Ai,name:`${Ai.name}${e||""}`})),this.selected=x.last(this.panel.variables)}select(e){this.selected=e}remove(e){this.selected===e&&(this.selected=void 0);const n=this.panel.variables.indexOf(e);if(this.panel.removeVariable(e),!this.selected&&!x.isEmpty(this.panel.variables)){const r=Math.min(this.panel.variables.length-1,n);this.selected=this.panel.variables[r]}}}function pS(){const{panel:t}=Ae();return J.useCreation(()=>new dS(t),[t])}const Cl=s.createStyles(t=>({root:{height:"100%",overflow:"hidden",".var-list-container":{"& > *":{height:"100%"},width:250,height:"100%"},".var-list-actions":{height:"fit-content",flexShrink:0,width:"100%"},".var-list":{flex:"1 1 auto",overflow:"auto",minHeight:0,"& > *":{flex:"0 0 auto"}}},config:{height:"100%",overflow:"auto",paddingRight:10}})),hS=y.forwardRef(function({value:e,onChange:n,data:r,withStyle:a=!0},o){const l=(c,u)=>{const d=x.cloneDeep(e);x.set(d,c,u),n(d)};return p(s.Box,{px:"sm",py:"md",ref:o,children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(s.TextInput,{label:"Name",required:!0,value:e.name,onChange:c=>l("name",c.currentTarget.value)}),i(j,{label:"Data Field",required:!0,value:e.data_field,onChange:c=>l("data_field",c)})]}),i(Sn,{label:"Aggregation",value:e.aggregation,onChange:c=>l("aggregation",c)}),i(s.Divider,{my:"xs",label:"Format",labelPosition:"center"}),i(Je,{value:e.formatter,onChange:c=>l("formatter",c)}),a&&i(Ss,{value:e,onChange:n})]})}),fS=t=>{const{uiModel:e}=t;return i(s.Stack,{className:"var-list",children:e.variables.map(n=>i(s.Button,{variant:e.selected===n?"filled":"subtle",color:"gray",onClick:()=>e.select(n),children:n.name},n.name))})},gS=k.observer(fS),mS=({variable:t,data:e})=>i(s.Group,{style:{minHeight:0,height:"calc(100% - 68px)"},children:i(s.Paper,{withBorder:!0,p:"md",children:_s(t,e)})}),yS=k.observer(mS),bS=t=>{const e=J.useCreation(()=>Wc(t.variable),[t.variable]),{classes:n}=Cl(),{data:r}=Ae();return p(s.Group,{style:{height:"100%"},align:"start",children:[p(s.Stack,{"data-testid":"variable-editor",align:"stretch",className:n.config,children:[p(s.Group,{position:"right",children:[i(s.ActionIcon,{variant:"filled",disabled:!e.changed,color:"primary",onClick:e.commit,children:i(L.IconDeviceFloppy,{size:18})}),i(s.ActionIcon,{color:"red",onClick:()=>t.uiModel.remove(t.variable),children:i(L.IconTrash,{size:18})})]}),i(hS,{value:b.getSnapshot(e.copy),onChange:e.update,data:r})]}),i(yS,{variable:b.getSnapshot(e.copy),data:r})]})},vS=k.observer(bS),xS=()=>{const t=pS(),{classes:e}=Cl();return p(s.Group,{className:e.root,noWrap:!0,align:"start",children:[i(s.Paper,{withBorder:!0,p:"md",className:"var-list-container",children:p(s.Stack,{justify:"space-between",children:[i(s.Box,{className:"var-list-actions",children:i(s.Button,{variant:"light",size:"sm",onClick:t.addNew,fullWidth:!0,children:"Add Variable"})}),i(gS,{uiModel:t})]})}),t.selected?i(N,{children:i(vS,{uiModel:t,variable:t.selected})}):i("span",{children:"Select or create a new variable on right side"})]})},wS=k.observer(xS);function CS(){const{vizManager:t}=y.useContext(it);return y.useMemo(()=>{const e=t.availableVizList.map(n=>({value:n.name,label:n.displayName??n.name,group:n.displayGroup??""}));return x.orderBy(e,[n=>n.group,n=>n.label],["asc","asc"])},[t])}const SS=k.observer(({value:t,submit:e})=>{const[n,r]=Ie.useInputState(t);y.useEffect(()=>{r(t)},[t]);const a=CS(),o=t!==n;return i(s.Select,{label:"Visualization",value:n,searchable:!0,onChange:r,data:a,rightSection:i(s.ActionIcon,{disabled:!o,onClick:()=>e(n),children:i(I.DeviceFloppy,{size:20})}),maxDropdownHeight:600})}),Sl=[];function _S(t,e){try{return t.resolveComponent(e).createConfig()}catch{return null}}function kS(){const{data:t,panel:{variables:e,viz:n,title:r,queryIDs:a,description:o,setDescription:l,setTitle:c,addQueryID:u,removeQueryID:d,id:f}}=Ae(),{vizManager:h}=y.useContext(it),g={title:r,description:o,viz:n,queryIDs:a,id:f},m={setDescription:l,addQueryID:u,removeQueryID:d,setTitle:c},C=ul(g);try{return h.resolveComponent(g.viz.type),i(Jn,{configure:C,children:i($C,{variables:e,setVizConf:n.setConf,panel:g,panelInfoEditor:m,vizManager:h,data:t})})}catch(w){return console.info(x.get(w,"message")),null}}const TS=k.observer(()=>{const{data:t,panel:{viz:e}}=Ae(),{vizManager:n}=y.useContext(it),r=y.useCallback(d=>{if(d===e.type)return;const f=_S(n,d);e.setType(d),e.setConf(f||{})},[e.type]),a=d=>{try{e.setConf(JSON.parse(d))}catch(f){console.error(f)}},o=y.useMemo(()=>{var d;return(d=Sl.find(f=>f.value===e.type))==null?void 0:d.Panel},[e.type,Sl]),l=kS(),c=o?y.createElement(o,{data:t,conf:e.conf,setConf:e.setConf}):null,u=l||c;return p(s.Stack,{align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[i(SS,{submit:r,value:e.type}),p(Fe,{children:[i(s.Stack,{pb:10,sx:{flexGrow:1,maxHeight:"100%",overflow:"auto"},children:u}),!u&&i(s.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(e.conf,null,2),onChange:a})]})]})}),DS=k.observer(({panel:t,sourceViewID:e})=>{const n=K(),[r,a]=y.useState(e);y.useEffect(()=>{a(e)},[e]);const[o,{open:l,close:c}]=Ie.useDisclosure(!1),u=()=>{t.moveToView(e,r),c()};return p(N,{children:[i(s.Button,{size:"xs",variant:"subtle",color:"blue",onClick:l,leftIcon:i(L.IconBoxMultiple,{size:14}),children:"Move into Another View"}),i(s.Modal,{opened:o,onClose:c,title:"Move panel into another view",zIndex:320,overflow:"inside",children:p(s.Stack,{sx:{maxHeight:"calc(100vh - 185px)",overflow:"hidden"},children:[i(s.Radio.Group,{value:r,onChange:a,pb:10,sx:{flexGrow:1,maxHeight:"calc(100vh - 185px - 30px)",overflow:"auto"},children:i(s.Stack,{spacing:"xs",children:n.views.options.map(d=>i(s.Radio,{value:d.value,label:d.label},d.value))})}),p(s.Group,{noWrap:!0,position:"apart",sx:{flexGrow:0,flexShrink:0},children:[i(s.Button,{size:"xs",color:"red",leftIcon:i(L.IconX,{size:14}),onClick:c,children:"Cancel"}),i(s.Button,{size:"xs",color:"blue",leftIcon:i(L.IconDeviceFloppy,{size:14}),onClick:u,disabled:r===e,children:"Confirm"})]})]})})]})}),IS={root:{flexGrow:1,width:"100%",overflow:"hidden"},panel:{width:"100%",height:"calc(100% - 44px)",padding:10,overflow:"scroll"}},_l=({children:t})=>p(s.Group,{noWrap:!0,grow:!0,position:"left",spacing:20,sx:{width:"100%",height:"100%"},children:[i(s.Box,{sx:{maxWidth:"calc(100% - 610px - 10px)",height:"100%",overflow:"auto"},children:t}),i(uS,{})]});function MS(t){return!["richText","button"].includes(t)}const ES=k.observer(({panel:t})=>{const e=Ke.useModals(),n=ge(),r=K(),[a,o]=y.useState("Data"),l=t.queries,u=MS(t.viz.type)&&t.dataLoading,d=u||t.queryErrors.length>0||t.queryStateMessages.length>0||l.length===0,f=n.editor.path[1];y.useEffect(()=>{o(m=>d&&m==="Visualization"?"Data":m)},[t.id,d]);const h=()=>{n.editor.setPath(["_VIEWS_",f])},g=()=>e.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.removePanelByID(t.id,f),h()},confirmProps:{color:"red"},zIndex:320});return p(wr,{value:{panel:t,data:t.data,loading:u,errors:t.queryErrors},children:[p(s.Group,{px:16,position:"apart",sx:{borderBottom:"1px solid #eee"},children:[p(s.Text,{pt:9,pb:8,children:[t.title?t.title:t.viz.type," "]}),p(s.Group,{position:"right",noWrap:!0,children:[i(DS,{panel:t,sourceViewID:f}),i(s.Button,{size:"xs",variant:"subtle",color:"red",onClick:g,leftIcon:i(L.IconTrash,{size:14}),children:"Delete This Panel"})]})]}),p(s.Tabs,{value:a,onTabChange:o,keepMounted:!1,styles:IS,children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Data",disabled:u,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:u,exitTransitionDuration:0}),i(cS,{})]}),i(s.Tabs.Panel,{value:"Panel",children:i(_l,{children:i(sS,{})})}),i(s.Tabs.Panel,{value:"Variables",children:i(wS,{})}),i(s.Tabs.Panel,{value:"Visualization",children:i(Fe,{children:i(_l,{children:i(TS,{})})})}),i(s.Tabs.Panel,{value:"Interactions",children:i(Fe,{children:i($u,{})})})]})]})}),AS=k.observer(({viewID:t,panelID:e})=>{const n=K();if(!n.views.findByID(t))return p(s.Text,{size:14,children:["View by ID[",t,"] is not found"]});const a=n.panels.findByID(e);return a?i(ES,{panel:a}):p(s.Text,{size:14,children:["Panel by ID[",e,"] is not found"]})}),kl=({width:t="calc(100% - 32px)",lastWidth:e="50%",height:n,count:r,spacing:a=16,pl:o=0})=>p(s.Stack,{spacing:a,mt:6,pl:o,children:[Array.from(new Array(r-1),(l,c)=>i(s.Skeleton,{width:t,height:n,radius:"xs"},c)),i(s.Skeleton,{width:e,height:n,radius:"xs"})]}),on=({value:t})=>t===null||t===""?null:i(s.Tooltip,{label:t,disabled:!t,multiline:!0,children:i(s.ActionIcon,{children:i(L.IconInfoCircle,{size:14})})}),zS=({column:t})=>{const{column_key:e,column_key_text:n}=t;return e?i(s.Tooltip,{label:n,disabled:!n,children:i(s.Badge,{children:e})}):null},$S=k.observer(({dataSource:t})=>{const{columns:e}=t;return e.loading?i(kl,{height:"24px",width:"100%",lastWidth:"100%",count:20,pl:6}):e.empty?null:p(s.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"1000px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[i("col",{style:{width:50}}),i("col",{style:{minWidth:300}}),i("col",{style:{width:30}}),i("col",{style:{width:70}}),i("col",{style:{minWidth:300}}),i("col",{style:{minWidth:80,width:80}}),i("col",{style:{minWidth:120,width:120}})]}),i("thead",{children:p("tr",{children:[i("th",{children:"#"}),i("th",{children:"Column Name"}),i("th",{}),i("th",{}),i("th",{children:"Type"}),i("th",{children:"Nullable"}),i("th",{children:"Default Value"})]})}),i("tbody",{children:e.data.map(n=>p("tr",{children:[i("td",{children:n.ordinal_position}),i("td",{children:n.column_name}),i("td",{children:i(on,{value:n.column_comment})}),i("td",{children:i(zS,{column:n})}),i("td",{children:n.column_type}),i("td",{children:n.is_nullable}),i("td",{children:i(on,{value:n.column_default})})]},n.column_name))})]})}),LS=k.observer(({dataSource:t})=>{const{indexes:e}=t,n=e.data;return p(s.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"950px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[i("col",{style:{width:100}}),i("col",{style:{minWidth:300}}),i("col",{style:{width:150}}),i("col",{style:{width:150}}),i("col",{style:{width:250}})]}),i("thead",{children:p("tr",{children:[i("th",{children:"Index Length"}),i("th",{children:"Index Name"}),i("th",{children:"Index Algorithm"}),i("th",{children:"Unique"}),i("th",{children:"Column Name"})]})}),i("tbody",{children:n.map(r=>p("tr",{children:[i("td",{children:r.index_length}),i("td",{children:r.index_name}),i("td",{children:r.index_algorithm}),i("td",{children:r.is_unique?"YES":"NO"}),i("td",{children:r.column_name})]},r.index_name))})]})}),OS=k.observer(({dataSource:t})=>{const{indexes:e}=t,n=e.data;return p(s.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"850px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[i("col",{style:{minWidth:300}}),i("col",{style:{width:150}}),i("col",{style:{width:100}}),i("col",{style:{width:100}}),i("col",{style:{width:100}}),i("col",{style:{width:100}})]}),i("thead",{children:p("tr",{children:[i("th",{children:"Index Name"}),i("th",{children:"Index Algorithm"}),i("th",{children:"Unique"}),i("th",{children:"Definition"}),i("th",{children:"Condition"}),i("th",{children:"Comment"})]})}),i("tbody",{children:n.map(r=>p("tr",{children:[i("td",{children:r.index_name}),i("td",{children:r.index_algorithm}),i("td",{children:r.is_unique?"YES":"NO"}),i("td",{children:i(on,{value:r.index_definition})}),i("td",{children:i(on,{value:r.condition})}),i("td",{children:i(on,{value:r.comment})})]},r.index_name))})]})}),PS=k.observer(({dataSource:t})=>{const{indexes:e}=t;return e.loading||e.empty?null:t.type===be.MySQL?i(LS,{dataSource:t}):t.type===be.Postgresql?i(OS,{dataSource:t}):null}),BS=k.observer(({dataSource:t})=>p(s.Stack,{spacing:40,pt:10,sx:{flexGrow:1,overflow:"auto",position:"relative"},children:[i(Fe,{children:i($S,{dataSource:t})}),i(Fe,{children:i(PS,{dataSource:t})})]}));function VS({table_type:t}){return t==="VIEW"?i(L.IconEye,{size:14}):t==="BASE TABLE"?i(L.IconTable,{size:14}):null}const NS=k.observer(({dataSource:t})=>{const{tables:e}=t;return e.loading?i(kl,{height:"24px",lastWidth:"50%",count:15}):i(s.Box,{h:"100%",sx:{overflow:"auto",".mantine-NavLink-label":{fontFamily:"monospace"}},children:Object.entries(e.data).map(([n,r])=>i(s.NavLink,{label:n,icon:i(L.IconDatabase,{size:14}),defaultOpened:t.table_schema===n,pl:0,childrenOffset:14,children:r.map(a=>i(s.NavLink,{label:a.table_name,icon:i(VS,{table_type:a.table_type}),onClick:()=>{t.setKeywords(n,a.table_name)},active:t.table_name===a.table_name},a.table_name))},n))})}),qS=({visible:t})=>i(s.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:i(s.LoadingOverlay,{visible:t})}),FS=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],GS={icon:{width:"50px",textAlign:"center"},input:{"&.mantine-Input-withIcon":{paddingLeft:"50px"}}},WS=k.observer(({dataSource:t})=>{const{tableData:e}=t;return p(s.Group,{pt:10,px:10,position:"apart",children:[p(s.Group,{position:"left",children:[e.maxPage>1&&i(s.Pagination,{size:"sm",page:e.page,onChange:e.setPage,total:e.maxPage,withEdges:e.maxPage>7,styles:{item:{height:"30px"}}}),i(s.Select,{icon:i(s.Text,{ta:"center",color:"dimmed",size:14,children:"Limit"}),size:"xs",styles:GS,data:FS,value:String(e.limit),onChange:n=>e.setLimit(Number(n))})]}),i(s.Group,{position:"right",children:p(s.Text,{color:"dimmed",my:0,size:14,children:["Total ",e.total," rows"]})})]})}),RS=k.observer(({dataSource:t})=>{const e=t.tableData;return e.maxPage===0?i(s.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:"This table is empty"}):e.error?i(s.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:e.error}):e.page===1&&e.loading?i(qS,{visible:!0}):p(Fe,{children:[i(WS,{dataSource:t}),p(s.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[i(s.LoadingOverlay,{visible:e.loading,overlayBlur:2}),i(wl,{data:e.data})]})]})}),jS={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},YS=k.observer(({dataSource:t})=>(y.useEffect(()=>{t.loadTablesIfEmpty()},[t]),t.tables.error?i(s.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:t.tables.error}):p(s.Flex,{sx:{height:"100%"},children:[i(s.Box,{w:300,sx:{flexGrow:0,flexShrink:0,position:"relative"},children:i(Fe,{children:i(NS,{dataSource:t})})}),p(s.Tabs,{defaultValue:"structure",styles:jS,children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"structure",icon:i(L.IconColumns,{size:14}),children:"Structure"}),i(s.Tabs.Tab,{value:"data",icon:i(L.IconDatabase,{size:14}),children:"Data"})]}),i(s.Tabs.Panel,{value:"structure",children:i(BS,{dataSource:t})}),i(s.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:i(RS,{dataSource:t})})]})]}))),QS={modal:{paddingLeft:"0px !important",paddingRight:"0px !important"},header:{marginBottom:0,padding:"0 20px 10px",borderBottom:"1px solid #efefef"},title:{flexGrow:1},body:{padding:"0 0 0 20px"}},Tl=k.observer(({dataSource:t,triggerButtonProps:e={}})=>{const[n,r]=y.useState(!1);return t.type==="http"?null:p(N,{children:[i(s.Modal,{opened:n,onClose:()=>r(!1),title:p(s.Group,{position:"apart",sx:{flexGrow:1},children:[i(s.Text,{fw:500,children:"Explorer Data Source"}),p(s.Group,{spacing:7,children:[i(s.Badge,{variant:"gradient",gradient:{from:"indigo",to:"cyan"},children:t.key}),i(s.Badge,{variant:"gradient",gradient:{from:"orange",to:"red"},children:t.type})]})]}),zIndex:320,size:"96vw",overflow:"inside",styles:QS,children:i(s.Box,{sx:{height:"calc(100vh - 220px)"},children:i(YS,{dataSource:t})})}),i(s.Button,{variant:"subtle",onClick:()=>r(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},...e,children:"See Table Structure"})]})}),KS=y.forwardRef(({label:t,type:e,...n},r)=>p(s.Group,{position:"apart",ref:r,...n,children:[i(s.Text,{children:t}),i(s.Text,{children:e})]})),US=k.observer(({value:t,onChange:e})=>{const n=ge(),{data:r=[],loading:a}=J.useRequest(pr,{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]),c=d=>{d!==null&&e({key:d,type:l[d]})},u=y.useMemo(()=>n.datasources.find(t),[n,t]);return i(s.Select,{data:o,label:p(s.Group,{position:"apart",children:[i(s.Box,{children:"Data Source"}),u&&i(Tl,{dataSource:u,triggerButtonProps:{compact:!0,size:"xs",px:10}})]}),itemComponent:KS,rightSection:u?i(s.Text,{size:"xs",color:"dimmed",children:u.type}):void 0,rightSectionWidth:85,maxDropdownHeight:280,styles:{root:{flex:1},label:{display:"block"},rightSection:{pointerEvents:"none",justifyContent:"flex-end",paddingRight:"10px",".mantine-Text-root":{userSelect:"none"}}},disabled:a,value:t.key,onChange:c})}),XS=t=>{const{queryModel:e}=t,n=ge(),r=K(),o=r.findQueryUsage(e.id).length>0,l=Ke.useModals(),c=()=>{l.openConfirmModal({title:"Delete this query?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.queries.removeQuery(e.id),n.editor.setPath(["_QUERIES_",""])},confirmProps:{color:"red"},zIndex:320})};return o?i(s.Tooltip,{label:"Can't delete this query for it's being used, check out Usage tab for details",withArrow:!0,events:{hover:!0,focus:!1,touch:!1},withinPortal:!0,children:i(s.Button,{color:"gray",size:"xs",leftIcon:i(L.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})}):i(s.Button,{color:"red",size:"xs",onClick:c,leftIcon:i(L.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})},JS=k.observer(XS),ZS=k.observer(({queryModel:t})=>{const[e,n]=y.useState(t.name);return y.useEffect(()=>{n(t.name)},[t.name]),i(s.Center,{ml:20,mt:20,sx:{maxWidth:"600px"},children:p(s.Stack,{spacing:10,sx:{width:"100%"},children:[i(s.Divider,{mb:-10,variant:"dashed",label:"Basics",labelPosition:"center"}),i(s.TextInput,{placeholder:"A unique name",label:"Name",required:!0,sx:{flex:1},value:e,onChange:r=>{n(r.currentTarget.value)},rightSection:i(s.ActionIcon,{variant:"filled",color:"blue",size:"sm",onClick:()=>t.setName(e),disabled:e===t.name,children:i(L.IconDeviceFloppy,{size:16})}),onBlur:()=>{t.setName(e)}}),i(US,{value:{type:t.type,key:t.key},onChange:({type:r,key:a})=>{t.setKey(a),t.setType(r)}}),i(s.Divider,{mt:10,mb:-10,variant:"dashed",label:"Conditions",labelPosition:"center"}),i(s.MultiSelect,{label:"Run query when these are truthy",placeholder:"Always run this query on load",data:t.conditionOptions,value:[...t.run_by],onChange:t.setRunBy}),t.typedAsHTTP&&i(s.MultiSelect,{label:"Re-run query when these changed",placeholder:"Leave it empty to never re-run this query",data:t.conditionOptions,value:[...t.react_to],onChange:t.setReactTo}),i(s.Divider,{mt:20,mb:10,variant:"dashed"}),i(JS,{queryModel:t})]})})});function HS(){const[t,{open:e,close:n}]=Ie.useDisclosure(!1);return p(N,{children:[i(s.Modal,{opened:t,onClose:n,title:"About FunctionUtils",zIndex:320,children:i(Yn,{value:ac,styles:{root:{border:"none"},content:{padding:0,table:{marginBottom:0}}}})}),i(s.Button,{variant:"light",color:"violet",size:"xs",onClick:e,leftIcon:i(L.IconInfoCircle,{size:16}),children:"About parameter 'utils'"})]})}const e_=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return i(s.Box,{sx:{position:"relative",flexGrow:1},children:i(ze,{className:"function-editor",height:"100%",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1}}})})},rr=y.forwardRef(({value:t,onChange:e,label:n,defaultValue:r},a)=>{const[o,l]=y.useState(t),c=()=>{e(o)},u=()=>{l(t)},d=()=>{l(r)};y.useEffect(()=>{l(t)},[t]);const f=o!==t;return p(s.Stack,{spacing:4,sx:{height:"100%"},children:[p(s.Group,{mb:6,position:"apart",sx:{flexShrink:0,flexGrow:0},children:[i(s.Group,{position:"left",children:i(HS,{})}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,size:"xs",variant:"default",leftIcon:i(L.IconPlayerSkipBack,{size:16}),children:"Reset to default"}),i(s.Button,{onClick:u,color:"red",size:"xs",disabled:!f,leftIcon:i(L.IconRecycle,{size:16}),children:"Revert Changes"}),i(s.Button,{size:"xs",onClick:c,disabled:!f,leftIcon:i(L.IconDeviceFloppy,{size:16}),children:"Confirm Changes"})]})]}),i(s.Text,{size:14,children:n}),i(e_,{value:o,onChange:l})]})});function t_({content:t}){return p(s.HoverCard,{width:"60vw",shadow:"md",children:[i(s.HoverCard.Target,{children:i(s.ActionIcon,{size:16,color:"blue",children:i(L.IconEye,{})})}),i(s.HoverCard.Dropdown,{children:i(St.Prism,{language:"sql",noCopy:!0,withLineNumbers:!0,children:t})})]})}const n_=k.observer(()=>{const e=[...ge().globalSQLSnippets.list];return e.length===0?null:p(s.Table,{horizontalSpacing:"xs",verticalSpacing:"xs",fontSize:"sm",highlightOnHover:!0,children:[i("thead",{children:p("tr",{children:[i("th",{children:"Key"}),i("th",{children:"Value"})]})}),i("tbody",{children:e.map(n=>{const{id:r,content:a}=n;return p("tr",{children:[i("td",{children:r}),i("td",{width:200,children:i(t_,{content:a})})]},r)})})]})}),r_=`
|
|
495
|
+
`,X1=()=>{const[t,e]=y.useState(!1);return h(N,{children:[i(s.Button,{variant:"subtle",compact:!0,onClick:()=>e(n=>!n),children:t?"Close":"Click to see expected data structure"}),i(s.Collapse,{in:t,children:i(St.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:U1})})]})},J1=k.observer(function({config:e}){return h(N,{children:[i(s.TextInput,{label:"Min-width",value:e.min_width,onChange:n=>e.setMinWidth(n.currentTarget.value),placeholder:"200px"}),i(s.Divider,{label:"Fetch options from database",labelPosition:"center"}),i(s.NumberInput,{value:e.default_selection_count,onChange:e.setDefaultSelectionCount,label:"Select first N options by default"}),i(Mi,{value:e.options_query_id,onChange:e.setOptionsQueryID}),i(X1,{})]})}),Z1=k.observer(function({filter:e}){const[n,r]=y.useState(e.plainDefaultValue);return y.useEffect(()=>{r(e.plainDefaultValue)},[e]),h(s.Box,{sx:{maxWidth:"480px"},children:[i(s.Text,{pb:"md",color:"gray",children:"Preview"}),i(sl,{filter:e,value:n,onChange:r}),i(s.Text,{pt:"lg",pb:"md",color:"gray",children:"Config"}),i(St.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(e,null,4)})]})}),H1={select:Q1,"multi-select":Y1,"tree-select":J1,"text-input":K1,checkbox:G1,"date-range":R1},eS=[{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"}],tS=k.observer(function({filter:e}){const n=K(),r=y.useMemo(()=>H1[e.type],[e.type]);return h(s.Group,{grow:!0,spacing:20,align:"top",children:[h(s.Box,{sx:{maxWidth:"600px"},children:[i(s.Text,{pb:"md",color:"gray",children:"Edit"}),h(s.Stack,{children:[h(s.Group,{noWrap:!0,children:[i(s.NumberInput,{label:"Placement Order",required:!0,value:e.order,onChange:e.setOrder,hideControls:!0,sx:{flexGrow:"1 !important"}}),e.auto_submit_supported&&i(s.Checkbox,{label:"Submit automatically",checked:e.auto_submit,onChange:a=>e.setAutoSubmit(a.currentTarget.checked),mt:22})]}),i(s.MultiSelect,{label:"Visible in...",data:n.views.options,value:[...e.visibleInViewsIDs],onChange:e.setVisibleInViewsIDs}),i(s.TextInput,{label:"Key",placeholder:"A unique key to refer",required:!0,value:e.key,onChange:a=>{e.setKey(a.currentTarget.value)}}),i(s.TextInput,{label:"Label",placeholder:"Label for this field",required:!0,value:e.label,onChange:a=>{e.setLabel(a.currentTarget.value)}}),i(s.Select,{label:"Widget",data:eS,required:!0,value:e.type,onChange:e.setType}),i(r,{config:e.config})]})]}),i(Z1,{filter:e})]})}),nS=k.observer(({id:t})=>{const e=Ke.useModals(),n=ge(),r=K();if(t==="")return null;const a=r.filters.findByID(t);if(!a)return h(s.Text,{size:14,children:["Filter by ID[",t,"] is not found"]});const o=()=>{n.editor.setPath(["_FILTERS_",""])},l=()=>{e.openConfirmModal({title:"Delete this filter?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.filters.removeByID(t),o()},confirmProps:{color:"red"},zIndex:320})};return h(s.Stack,{sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",pb:30,children:[i(s.Group,{position:"right",pt:10,children:i(s.Button,{size:"xs",color:"red",leftIcon:i(I.Trash,{size:16}),onClick:l,children:"Delete this filter"})}),i(s.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:i(tS,{filter:a})})]})}),rS=k.observer(()=>{const t=K(),[e,n]=y.useState(()=>JSON.stringify(t.mock_context.current,null,4)),r=()=>{try{t.mock_context.replace(JSON.parse(e))}catch(o){hn.showNotification({title:"Failed",message:o.message,color:"red"})}},a=y.useMemo(()=>{try{return JSON.stringify(JSON.parse(e))!==JSON.stringify(t.mock_context.current)}catch{return!1}},[e,t.mock_context.current]);return h(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"})}),h(s.Group,{grow:!0,px:"md",pb:"md",pt:0,sx:{flexGrow:1,position:"relative",alignItems:"flex-start"},children:[h(s.Stack,{spacing:10,sx:{maxWidth:"unset !important"},children:[i(s.Text,{children:"A valid json string is required"}),i(s.JsonInput,{validationError:"Invalid json",formatOnBlur:!0,autosize:!0,minRows:30,value:e,onChange:n,sx:{flexGrow:1}})]}),i(s.ActionIcon,{mr:5,variant:"filled",color:"blue",sx:{position:"absolute",right:12,top:0},disabled:!a,onClick:r,children:i(I.DeviceFloppy,{size:20})})]})]})}),iS=k.observer(()=>{const{panel:t}=Ae();return i(ri,{label:"Description",value:t.description,onChange:t.setDescription,styles:{root:{flexGrow:1}}})}),aS=k.observer(()=>{const{panel:t}=Ae(),{style:e}=t;return i(N,{children:i(s.Switch,{label:"Border",checked:e.border.enabled,onChange:n=>e.border.setEnabled(n.currentTarget.checked)})})}),sS=k.observer(()=>{const{panel:t}=Ae(),{title:e,setTitle:n}=t,[r,a]=Ie.useInputState(e),o=e!==r,l=y.useCallback(()=>{o&&n(r)},[o,r]);return y.useEffect(()=>{a(e)},[e]),i(s.TextInput,{value:r,onChange:a,label:h(s.Group,{children:[i(s.Text,{children:"Panel Title"}),i(s.ActionIcon,{variant:"subtle",color:"blue",disabled:!o,onClick:l,children:i(I.DeviceFloppy,{size:20})})]}),styles:{label:{display:"block",paddingBottom:"4px"}}})});function oS(){return h(s.Stack,{sx:{height:"100%"},children:[i(s.Divider,{label:"Style",labelPosition:"center",variant:"dashed"}),i(aS,{}),i(s.Divider,{label:"Info",labelPosition:"center",variant:"dashed"}),i(sS,{}),i(iS,{})]})}const lS=({queryID:t})=>{const e=K(),{state:n,error:r}=e.getDataStuffByID(t),a=y.useMemo(()=>e.queries.findByID(t),[e,t]);return n==="loading"?null:r?i(s.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:r}):a!=null&&a.stateMessage?i(s.Text,{color:"gray",align:"center",children:a.stateMessage}):null},uS={width:"fit-content",minWidth:"100%",tableLayout:"fixed",tr:{width:"fit-content"},th:{position:"relative"},".resizer":{position:"absolute",right:0,top:"50%",transform:"translateY(-50%)",cursor:"col-resize",userSelect:"none",touchAction:"none"},".resizer.isResizing":{color:"#228be6",opacity:"1"},"@media (hover: hover)":{".resizer":{opacity:"0"},"*:hover > .resizer":{color:"#228be6",opacity:"1"}}};function Cl({data:t}){const e=y.useMemo(()=>{if(!Array.isArray(t)||t.length===0)return[];const r=Ue.createColumnHelper();return Object.keys(t[0]).map(a=>r.accessor(a,{cell:o=>o.getValue()}))},[t]),n=Ue.useReactTable({data:t,columns:e,columnResizeMode:"onChange",getCoreRowModel:Ue.getCoreRowModel()});return t.length===0?i(s.Box,{sx:{height:"5em"}}):i(Fe,{children:h(s.Table,{sx:uS,children:[i("thead",{children:n.getHeaderGroups().map(r=>i("tr",{children:r.headers.map(a=>h("th",{style:{width:a.getSize()},children:[a.isPlaceholder?null:Ue.flexRender(a.column.columnDef.header,a.getContext()),i(s.ActionIcon,{onMouseDown:a.getResizeHandler(),onTouchStart:a.getResizeHandler(),className:`resizer ${a.column.getIsResizing()?"isResizing":""}`,children:i(I.ArrowBarToRight,{})})]},a.id))},r.id))}),i("tbody",{children:n.getRowModel().rows.map(r=>i("tr",{children:r.getVisibleCells().map(a=>i("td",{children:i(Fe,{children:Ue.flexRender(a.column.columnDef.cell,a.getContext())})},a.id))},r.id))})]})})}const Ei=k.observer(function({id:e,moreActions:n=null}){const r=K(),{data:a,state:o}=r.getDataStuffByID(e),l=o==="loading",u=()=>{r.queries.refetchDataByQueryID(e)},c=()=>{r.queries.downloadDataByQueryID(e)},d=y.useMemo(()=>Array.isArray(a)?a.slice(0,10):[],[a]),f=!Array.isArray(a)||a.length===0;return h(s.Stack,{sx:{border:"1px solid #eee"},children:[h(s.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[h(s.Group,{position:"left",children:[i(s.Text,{weight:500,children:"Preview Data"}),a.length>10&&h(s.Text,{size:"sm",color:"gray",children:["Showing 10 rows of ",a.length]})]}),h(s.Group,{pr:15,children:[n,i(s.ActionIcon,{variant:"subtle",color:"blue",disabled:l,onClick:u,children:i(I.Refresh,{size:16})}),i(s.ActionIcon,{variant:"subtle",color:"blue",disabled:l||f,onClick:c,children:i(I.Download,{size:16})})]})]}),h(s.Box,{sx:{position:"relative",overflow:"auto"},children:[i(s.LoadingOverlay,{visible:l}),i(lS,{queryID:e}),i(Cl,{data:d})]})]})}),cS=k.observer(function(){const e=ge(),n=K(),{panel:r}=Ae(),[a,o]=y.useState(!1),l=u=>{e.editor.setPath(["_QUERIES_",u])};return h(N,{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))})})}),h(s.Stack,{spacing:6,children:[i(s.Group,{position:"right",children:i(s.Button,{variant:"light",size:"sm",leftIcon:i(L.IconLine,{size:16}),onClick:()=>o(!0),children:"Click me to choose queries for this panel"})}),r.queryIDs.length===1&&i(Ei,{id:r.queryIDs[0],moreActions:i(s.Tooltip,{label:"Open this query",children:i(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>l(r.queryIDs[0]),children:i(L.IconArrowCurveRight,{size:16})})})}),r.queryIDs.length>1&&h(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(Ei,{id:u.id,moreActions:i(s.Tooltip,{label:"Open this query",children:i(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>l(u.id),children:i(L.IconArrowCurveRight,{size:16})})})})},u.id))]})]})]})}),dS=k.observer(()=>{const{panel:t}=Ae();return i(Fe,{children:i(s.Box,{sx:{height:"100%",flexGrow:0,flexShrink:0,width:"600px"},children:h(s.Stack,{mt:24,spacing:5,sx:{width:"600px",height:"450px",background:"transparent",borderRadius:"5px",border:"1px solid #e9ecef",borderWidth:t.style.border.enabled?"1px":"0px"},children:[h(s.Group,{position:"apart",noWrap:!0,sx:{flexGrow:0,flexShrink:0},children:[i(s.Group,{children:i(ll,{})}),i(s.Group,{grow:!0,position:"center",children:i(s.Text,{lineClamp:1,weight:"bold",children:t.title})}),i(s.Group,{position:"right",spacing:0,sx:{height:"28px"}})]}),i(s.Group,{px:5,pb:5,sx:{flexGrow:1},children:i(hl,{panel:t,height:"410px"})})]})})})}),Ai={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 pS{constructor(e){V(this,"panel");V(this,"selected");this.panel=e,ae.makeAutoObservable(this,{},{deep:!1,autoBind:!0})}get variables(){return this.panel.variables}addNew(){const e=this.panel.variables.filter(n=>n.name.startsWith(Ai.name)).length;this.panel.addVariable(x.cloneDeep({...Ai,name:`${Ai.name}${e||""}`})),this.selected=x.last(this.panel.variables)}select(e){this.selected=e}remove(e){this.selected===e&&(this.selected=void 0);const n=this.panel.variables.indexOf(e);if(this.panel.removeVariable(e),!this.selected&&!x.isEmpty(this.panel.variables)){const r=Math.min(this.panel.variables.length-1,n);this.selected=this.panel.variables[r]}}}function hS(){const{panel:t}=Ae();return J.useCreation(()=>new pS(t),[t])}const Sl=s.createStyles(t=>({root:{height:"100%",overflow:"hidden",".var-list-container":{"& > *":{height:"100%"},width:250,height:"100%"},".var-list-actions":{height:"fit-content",flexShrink:0,width:"100%"},".var-list":{flex:"1 1 auto",overflow:"auto",minHeight:0,"& > *":{flex:"0 0 auto"}}},config:{height:"100%",overflow:"auto",paddingRight:10}})),fS=y.forwardRef(function({value:e,onChange:n,data:r,withStyle:a=!0},o){const l=(u,c)=>{const d=x.cloneDeep(e);x.set(d,u,c),n(d)};return h(s.Box,{px:"sm",py:"md",ref:o,children:[h(s.Group,{grow:!0,noWrap:!0,children:[i(s.TextInput,{label:"Name",required:!0,value:e.name,onChange:u=>l("name",u.currentTarget.value)}),i(j,{label:"Data Field",required:!0,value:e.data_field,onChange:u=>l("data_field",u)})]}),i(Sn,{label:"Aggregation",value:e.aggregation,onChange:u=>l("aggregation",u)}),i(s.Divider,{my:"xs",label:"Format",labelPosition:"center"}),i(Je,{value:e.formatter,onChange:u=>l("formatter",u)}),a&&i(Ss,{value:e,onChange:n})]})}),gS=t=>{const{uiModel:e}=t;return i(s.Stack,{className:"var-list",children:e.variables.map(n=>i(s.Button,{variant:e.selected===n?"filled":"subtle",color:"gray",onClick:()=>e.select(n),children:n.name},n.name))})},mS=k.observer(gS),yS=({variable:t,data:e})=>i(s.Group,{style:{minHeight:0,height:"calc(100% - 68px)"},children:i(s.Paper,{withBorder:!0,p:"md",children:_s(t,e)})}),bS=k.observer(yS),vS=t=>{const e=J.useCreation(()=>Ru(t.variable),[t.variable]),{classes:n}=Sl(),{data:r}=Ae();return h(s.Group,{style:{height:"100%"},align:"start",children:[h(s.Stack,{"data-testid":"variable-editor",align:"stretch",className:n.config,children:[h(s.Group,{position:"right",children:[i(s.ActionIcon,{variant:"filled",disabled:!e.changed,color:"primary",onClick:e.commit,children:i(L.IconDeviceFloppy,{size:18})}),i(s.ActionIcon,{color:"red",onClick:()=>t.uiModel.remove(t.variable),children:i(L.IconTrash,{size:18})})]}),i(fS,{value:b.getSnapshot(e.copy),onChange:e.update,data:r})]}),i(bS,{variable:b.getSnapshot(e.copy),data:r})]})},xS=k.observer(vS),wS=()=>{const t=hS(),{classes:e}=Sl();return h(s.Group,{className:e.root,noWrap:!0,align:"start",children:[i(s.Paper,{withBorder:!0,p:"md",className:"var-list-container",children:h(s.Stack,{justify:"space-between",children:[i(s.Box,{className:"var-list-actions",children:i(s.Button,{variant:"light",size:"sm",onClick:t.addNew,fullWidth:!0,children:"Add Variable"})}),i(mS,{uiModel:t})]})}),t.selected?i(N,{children:i(xS,{uiModel:t,variable:t.selected})}):i("span",{children:"Select or create a new variable on right side"})]})},CS=k.observer(wS);function SS(){const{vizManager:t}=y.useContext(it);return y.useMemo(()=>{const e=t.availableVizList.map(n=>({value:n.name,label:n.displayName??n.name,group:n.displayGroup??""}));return x.orderBy(e,[n=>n.group,n=>n.label],["asc","asc"])},[t])}const _S=k.observer(({value:t,submit:e})=>{const[n,r]=Ie.useInputState(t);y.useEffect(()=>{r(t)},[t]);const a=SS(),o=t!==n;return i(s.Select,{label:"Visualization",value:n,searchable:!0,onChange:r,data:a,rightSection:i(s.ActionIcon,{disabled:!o,onClick:()=>e(n),children:i(I.DeviceFloppy,{size:20})}),maxDropdownHeight:600})}),_l=[];function kS(t,e){try{return t.resolveComponent(e).createConfig()}catch{return null}}function TS(){const{data:t,panel:{variables:e,viz:n,title:r,queryIDs:a,description:o,setDescription:l,setTitle:u,addQueryID:c,removeQueryID:d,id:f}}=Ae(),{vizManager:p}=y.useContext(it),g={title:r,description:o,viz:n,queryIDs:a,id:f},m={setDescription:l,addQueryID:c,removeQueryID:d,setTitle:u},C=cl(g);try{return p.resolveComponent(g.viz.type),i(Jn,{configure:C,children:i(LC,{variables:e,setVizConf:n.setConf,panel:g,panelInfoEditor:m,vizManager:p,data:t})})}catch(w){return console.info(x.get(w,"message")),null}}const DS=k.observer(()=>{const{data:t,panel:{viz:e}}=Ae(),{vizManager:n}=y.useContext(it),r=y.useCallback(d=>{if(d===e.type)return;const f=kS(n,d);e.setType(d),e.setConf(f||{})},[e.type]),a=d=>{try{e.setConf(JSON.parse(d))}catch(f){console.error(f)}},o=y.useMemo(()=>{var d;return(d=_l.find(f=>f.value===e.type))==null?void 0:d.Panel},[e.type,_l]),l=TS(),u=o?y.createElement(o,{data:t,conf:e.conf,setConf:e.setConf}):null,c=l||u;return h(s.Stack,{align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[i(_S,{submit:r,value:e.type}),h(Fe,{children:[i(s.Stack,{pb:10,sx:{flexGrow:1,maxHeight:"100%",overflow:"auto"},children:c}),!c&&i(s.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(e.conf,null,2),onChange:a})]})]})}),IS=k.observer(({panel:t,sourceViewID:e})=>{const n=K(),[r,a]=y.useState(e);y.useEffect(()=>{a(e)},[e]);const[o,{open:l,close:u}]=Ie.useDisclosure(!1),c=()=>{t.moveToView(e,r),u()};return h(N,{children:[i(s.Button,{size:"xs",variant:"subtle",color:"blue",onClick:l,leftIcon:i(L.IconBoxMultiple,{size:14}),children:"Move into Another View"}),i(s.Modal,{opened:o,onClose:u,title:"Move panel into another view",zIndex:320,children:h(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))})}),h(s.Group,{noWrap:!0,position:"apart",sx:{flexGrow:0,flexShrink:0},children:[i(s.Button,{size:"xs",color:"red",leftIcon:i(L.IconX,{size:14}),onClick:u,children:"Cancel"}),i(s.Button,{size:"xs",color:"blue",leftIcon:i(L.IconDeviceFloppy,{size:14}),onClick:c,disabled:r===e,children:"Confirm"})]})]})})]})}),MS={root:{flexGrow:1,width:"100%",overflow:"hidden"},panel:{width:"100%",height:"calc(100% - 44px)",padding:10,overflow:"scroll"}},kl=({children:t})=>h(s.Group,{noWrap:!0,grow:!0,position:"left",spacing:20,sx:{width:"100%",height:"100%"},children:[i(s.Box,{sx:{maxWidth:"calc(100% - 610px - 10px)",height:"100%",overflow:"auto"},children:t}),i(dS,{})]});function ES(t){return!["richText","button"].includes(t)}const AS=k.observer(({panel:t})=>{const e=Ke.useModals(),n=ge(),r=K(),[a,o]=y.useState("Data"),l=t.queries,c=ES(t.viz.type)&&t.dataLoading,d=c||t.queryErrors.length>0||t.queryStateMessages.length>0||l.length===0,f=n.editor.path[1];y.useEffect(()=>{o(m=>d&&m==="Visualization"?"Data":m)},[t.id,d]);const p=()=>{n.editor.setPath(["_VIEWS_",f])},g=()=>e.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.removePanelByID(t.id,f),p()},confirmProps:{color:"red"},zIndex:320});return h(wr,{value:{panel:t,data:t.data,loading:c,errors:t.queryErrors},children:[h(s.Group,{px:16,position:"apart",sx:{borderBottom:"1px solid #eee"},children:[h(s.Text,{pt:9,pb:8,children:[t.title?t.title:t.viz.type," "]}),h(s.Group,{position:"right",noWrap:!0,children:[i(IS,{panel:t,sourceViewID:f}),i(s.Button,{size:"xs",variant:"subtle",color:"red",onClick:g,leftIcon:i(L.IconTrash,{size:14}),children:"Delete This Panel"})]})]}),h(s.Tabs,{value:a,onTabChange:o,keepMounted:!1,styles:MS,children:[h(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"})]}),h(s.Tabs.Panel,{value:"Data",children:[i(s.LoadingOverlay,{visible:c,exitTransitionDuration:0}),i(cS,{})]}),i(s.Tabs.Panel,{value:"Panel",children:i(kl,{children:i(oS,{})})}),i(s.Tabs.Panel,{value:"Variables",children:i(CS,{})}),i(s.Tabs.Panel,{value:"Visualization",children:i(Fe,{children:i(kl,{children:i(DS,{})})})}),i(s.Tabs.Panel,{value:"Interactions",children:i(Fe,{children:i(Lc,{})})})]})]})}),zS=k.observer(({viewID:t,panelID:e})=>{const n=K();if(!n.views.findByID(t))return h(s.Text,{size:14,children:["View by ID[",t,"] is not found"]});const a=n.panels.findByID(e);return a?i(AS,{panel:a}):h(s.Text,{size:14,children:["Panel by ID[",e,"] is not found"]})}),Tl=({width:t="calc(100% - 32px)",lastWidth:e="50%",height:n,count:r,spacing:a=16,pl:o=0})=>h(s.Stack,{spacing:a,mt:6,pl:o,children:[Array.from(new Array(r-1),(l,u)=>i(s.Skeleton,{width:t,height:n,radius:"xs"},u)),i(s.Skeleton,{width:e,height:n,radius:"xs"})]}),on=({value:t})=>t===null||t===""?null:i(s.Tooltip,{label:t,disabled:!t,multiline:!0,children:i(s.ActionIcon,{children:i(L.IconInfoCircle,{size:14})})}),$S=({column:t})=>{const{column_key:e,column_key_text:n}=t;return e?i(s.Tooltip,{label:n,disabled:!n,children:i(s.Badge,{children:e})}):null},LS=k.observer(({dataSource:t})=>{const{columns:e}=t;return e.loading?i(Tl,{height:"24px",width:"100%",lastWidth:"100%",count:20,pl:6}):e.empty?null:h(s.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"1000px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[h("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:h("tr",{children:[i("th",{children:"#"}),i("th",{children:"Column Name"}),i("th",{}),i("th",{}),i("th",{children:"Type"}),i("th",{children:"Nullable"}),i("th",{children:"Default Value"})]})}),i("tbody",{children:e.data.map(n=>h("tr",{children:[i("td",{children:n.ordinal_position}),i("td",{children:n.column_name}),i("td",{children:i(on,{value:n.column_comment})}),i("td",{children:i($S,{column:n})}),i("td",{children:n.column_type}),i("td",{children:n.is_nullable}),i("td",{children:i(on,{value:n.column_default})})]},n.column_name))})]})}),OS=k.observer(({dataSource:t})=>{const{indexes:e}=t,n=e.data;return h(s.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"950px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[h("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:h("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=>h("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))})]})}),PS=k.observer(({dataSource:t})=>{const{indexes:e}=t,n=e.data;return h(s.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"850px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[h("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:h("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=>h("tr",{children:[i("td",{children:r.index_name}),i("td",{children:r.index_algorithm}),i("td",{children:r.is_unique?"YES":"NO"}),i("td",{children:i(on,{value:r.index_definition})}),i("td",{children:i(on,{value:r.condition})}),i("td",{children:i(on,{value:r.comment})})]},r.index_name))})]})}),BS=k.observer(({dataSource:t})=>{const{indexes:e}=t;return e.loading||e.empty?null:t.type===be.MySQL?i(OS,{dataSource:t}):t.type===be.Postgresql?i(PS,{dataSource:t}):null}),VS=k.observer(({dataSource:t})=>h(s.Stack,{spacing:40,pt:10,sx:{flexGrow:1,overflow:"auto",position:"relative"},children:[i(Fe,{children:i(LS,{dataSource:t})}),i(Fe,{children:i(BS,{dataSource:t})})]}));function NS({table_type:t}){return t==="VIEW"?i(L.IconEye,{size:14}):t==="BASE TABLE"?i(L.IconTable,{size:14}):null}const qS=k.observer(({dataSource:t})=>{const{tables:e}=t;return e.loading?i(Tl,{height:"24px",lastWidth:"50%",count:15}):i(s.Box,{h:"100%",sx:{overflow:"auto",".mantine-NavLink-label":{fontFamily:"monospace"}},children:Object.entries(e.data).map(([n,r])=>i(s.NavLink,{label:n,icon:i(L.IconDatabase,{size:14}),defaultOpened:t.table_schema===n,pl:0,childrenOffset:14,children:r.map(a=>i(s.NavLink,{label:a.table_name,icon:i(NS,{table_type:a.table_type}),onClick:()=>{t.setKeywords(n,a.table_name)},active:t.table_name===a.table_name},a.table_name))},n))})}),FS=({visible:t})=>i(s.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:i(s.LoadingOverlay,{visible:t})}),GS=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],WS={icon:{width:"50px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"50px"}}},RS=k.observer(({dataSource:t})=>{const{tableData:e}=t;return h(s.Group,{pt:10,px:10,position:"apart",children:[h(s.Group,{position:"left",children:[e.maxPage>1&&i(s.Pagination,{size:"sm",value:e.page,onChange:e.setPage,total:e.maxPage,withEdges:e.maxPage>7,styles:{control:{height:"30px"}}}),i(s.Select,{icon:i(s.Text,{ta:"center",color:"dimmed",size:14,children:"Limit"}),size:"xs",styles:WS,data:GS,value:String(e.limit),onChange:n=>e.setLimit(Number(n))})]}),i(s.Group,{position:"right",children:h(s.Text,{color:"dimmed",my:0,size:14,children:["Total ",e.total," rows"]})})]})}),jS=k.observer(({dataSource:t})=>{const e=t.tableData;return e.maxPage===0?i(s.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:"This table is empty"}):e.error?i(s.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:e.error}):e.page===1&&e.loading?i(FS,{visible:!0}):h(Fe,{children:[i(RS,{dataSource:t}),h(s.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[i(s.LoadingOverlay,{visible:e.loading,overlayBlur:2}),i(Cl,{data:e.data})]})]})}),YS={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},QS=k.observer(({dataSource:t})=>(y.useEffect(()=>{t.loadTablesIfEmpty()},[t]),t.tables.error?i(s.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:t.tables.error}):h(s.Flex,{sx:{height:"100%"},children:[i(s.Box,{w:300,sx:{flexGrow:0,flexShrink:0,position:"relative"},children:i(Fe,{children:i(qS,{dataSource:t})})}),h(s.Tabs,{defaultValue:"structure",styles:YS,children:[h(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"structure",icon:i(L.IconColumns,{size:14}),children:"Structure"}),i(s.Tabs.Tab,{value:"data",icon:i(L.IconDatabase,{size:14}),children:"Data"})]}),i(s.Tabs.Panel,{value:"structure",children:i(VS,{dataSource:t})}),i(s.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:i(jS,{dataSource:t})})]})]}))),KS={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"}},Dl=k.observer(({dataSource:t,triggerButtonProps:e={}})=>{const[n,r]=y.useState(!1);return t.type==="http"?null:h(N,{children:[i(s.Modal,{opened:n,onClose:()=>r(!1),title:h(s.Group,{position:"apart",sx:{flexGrow:1},children:[i(s.Text,{fw:500,children:"Explorer Data Source"}),h(s.Group,{spacing:7,children:[i(s.Badge,{variant:"gradient",gradient:{from:"indigo",to:"cyan"},children:t.key}),i(s.Badge,{variant:"gradient",gradient:{from:"orange",to:"red"},children:t.type})]})]}),zIndex:320,size:"96vw",styles:KS,children:i(s.Box,{sx:{height:"calc(100vh - 220px)"},children:i(QS,{dataSource:t})})}),i(s.Button,{variant:"subtle",onClick:()=>r(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},...e,children:"See Table Structure"})]})}),US=y.forwardRef(({label:t,type:e,...n},r)=>h(s.Group,{position:"apart",ref:r,...n,children:[i(s.Text,{children:t}),i(s.Text,{children:e})]})),XS=k.observer(({value:t,onChange:e})=>{const n=ge(),{data:r=[],loading:a}=J.useRequest(pr,{refreshDeps:[]},[]),o=y.useMemo(()=>r.map(d=>({label:d.key,value:d.key,type:d.type})),[r]),l=y.useMemo(()=>o.reduce((d,f)=>(d[f.value]=f.type,d),{}),[o]),u=d=>{d!==null&&e({key:d,type:l[d]})},c=y.useMemo(()=>n.datasources.find(t),[n,t]);return i(s.Select,{data:o,label:h(s.Group,{position:"apart",children:[i(s.Box,{children:"Data Source"}),c&&i(Dl,{dataSource:c,triggerButtonProps:{compact:!0,size:"xs",px:10}})]}),itemComponent:US,rightSection:c?i(s.Text,{size:"xs",color:"dimmed",children:c.type}):void 0,rightSectionWidth:85,maxDropdownHeight:280,styles:{root:{flex:1},label:{display:"block"},rightSection:{pointerEvents:"none",justifyContent:"flex-end",paddingRight:"10px",".mantine-Text-root":{userSelect:"none"}}},disabled:a,value:t.key,onChange:u})}),JS=t=>{const{queryModel:e}=t,n=ge(),r=K(),o=r.findQueryUsage(e.id).length>0,l=Ke.useModals(),u=()=>{l.openConfirmModal({title:"Delete this query?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.queries.removeQuery(e.id),n.editor.setPath(["_QUERIES_",""])},confirmProps:{color:"red"},zIndex:320})};return o?i(s.Tooltip,{label:"Can't delete this query for it's being used, check out Usage tab for details",withArrow:!0,events:{hover:!0,focus:!1,touch:!1},withinPortal:!0,children:i(s.Button,{color:"gray",size:"xs",leftIcon:i(L.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})}):i(s.Button,{color:"red",size:"xs",onClick:u,leftIcon:i(L.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})},ZS=k.observer(JS),HS=k.observer(({queryModel:t})=>{const[e,n]=y.useState(t.name);return y.useEffect(()=>{n(t.name)},[t.name]),i(s.Center,{ml:20,mt:20,sx:{maxWidth:"600px"},children:h(s.Stack,{spacing:10,sx:{width:"100%"},children:[i(s.Divider,{mb:-10,variant:"dashed",label:"Basics",labelPosition:"center"}),i(s.TextInput,{placeholder:"A unique name",label:"Name",required:!0,sx:{flex:1},value:e,onChange:r=>{n(r.currentTarget.value)},rightSection:i(s.ActionIcon,{variant:"filled",color:"blue",size:"sm",onClick:()=>t.setName(e),disabled:e===t.name,children:i(L.IconDeviceFloppy,{size:16})}),onBlur:()=>{t.setName(e)}}),i(XS,{value:{type:t.type,key:t.key},onChange:({type:r,key:a})=>{t.setKey(a),t.setType(r)}}),i(s.Divider,{mt:10,mb:-10,variant:"dashed",label:"Conditions",labelPosition:"center"}),i(s.MultiSelect,{label:"Run query when these are truthy",placeholder:"Always run this query on load",data:t.conditionOptions,value:[...t.run_by],onChange:t.setRunBy}),t.typedAsHTTP&&i(s.MultiSelect,{label:"Re-run query when these changed",placeholder:"Leave it empty to never re-run this query",data:t.conditionOptions,value:[...t.react_to],onChange:t.setReactTo}),i(s.Divider,{mt:20,mb:10,variant:"dashed"}),i(ZS,{queryModel:t})]})})});function e_(){const[t,{open:e,close:n}]=Ie.useDisclosure(!1);return h(N,{children:[i(s.Modal,{opened:t,onClose:n,title:"About FunctionUtils",zIndex:320,children:i(Yn,{value:su,styles:{root:{border:"none"},content:{padding:0,table:{marginBottom:0}}}})}),i(s.Button,{variant:"light",color:"violet",size:"xs",onClick:e,leftIcon:i(L.IconInfoCircle,{size:16}),children:"About parameter 'utils'"})]})}const t_=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return i(s.Box,{sx:{position:"relative",flexGrow:1},children:i(ze,{className:"function-editor",height:"100%",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1}}})})},rr=y.forwardRef(({value:t,onChange:e,label:n,defaultValue:r},a)=>{const[o,l]=y.useState(t),u=()=>{e(o)},c=()=>{l(t)},d=()=>{l(r)};y.useEffect(()=>{l(t)},[t]);const f=o!==t;return h(s.Stack,{spacing:4,sx:{height:"100%"},children:[h(s.Group,{mb:6,position:"apart",sx:{flexShrink:0,flexGrow:0},children:[i(s.Group,{position:"left",children:i(e_,{})}),h(s.Group,{position:"right",children:[i(s.Button,{onClick:d,size:"xs",variant:"default",leftIcon:i(L.IconPlayerSkipBack,{size:16}),children:"Reset to default"}),i(s.Button,{onClick:c,color:"red",size:"xs",disabled:!f,leftIcon:i(L.IconRecycle,{size:16}),children:"Revert Changes"}),i(s.Button,{size:"xs",onClick:u,disabled:!f,leftIcon:i(L.IconDeviceFloppy,{size:16}),children:"Confirm Changes"})]})]}),i(s.Text,{size:14,children:n}),i(t_,{value:o,onChange:l})]})});function n_({content:t}){return h(s.HoverCard,{width:"60vw",shadow:"md",children:[i(s.HoverCard.Target,{children:i(s.ActionIcon,{size:16,color:"blue",children:i(L.IconEye,{})})}),i(s.HoverCard.Dropdown,{children:i(St.Prism,{language:"sql",noCopy:!0,withLineNumbers:!0,children:t})})]})}const r_=k.observer(()=>{const e=[...ge().globalSQLSnippets.list];return e.length===0?null:h(s.Table,{horizontalSpacing:"xs",verticalSpacing:"xs",fontSize:"sm",highlightOnHover:!0,children:[i("thead",{children:h("tr",{children:[i("th",{children:"Key"}),i("th",{children:"Value"})]})}),i("tbody",{children:e.map(n=>{const{id:r,content:a}=n;return h("tr",{children:[i("td",{children:r}),i("td",{width:200,children:i(n_,{content:a})})]},r)})})]})}),i_=`
|
|
496
496
|
-- You may reference query variables in SQL or VizConfig.
|
|
497
497
|
SELECT *
|
|
498
498
|
FROM commit
|
|
@@ -505,8 +505,8 @@ WHERE
|
|
|
505
505
|
AND \${sql_snippets.author_email_condition}
|
|
506
506
|
-- Global SQL snippets (shared between dashboards)
|
|
507
507
|
AND \${global_sql_snippets.account_condition}
|
|
508
|
-
`,
|
|
508
|
+
`,Il=k.observer(function({showSQLSnippets:e=!0,sx:n={}}){const r=ge(),a=K(),o=r.context.current,l=(()=>{const u={context:{...a.mock_context.current,...o},filters:a.filters.previewValues};return e&&(u.sql_snippets=a.sqlSnippets.record),JSON.stringify(u,null,2)})();return i(s.Stack,{sx:{overflow:"hidden",...n},children:h(s.Tabs,{defaultValue:"guide",keepMounted:!1,children:[h(s.Tabs.List,{grow:!0,children:[i(s.Tabs.Tab,{value:"guide",icon:i(L.IconAlertCircle,{size:14}),children:"Guide"}),i(s.Tabs.Tab,{value:"local_query_vars",icon:i(L.IconVariable,{size:14}),children:"Variables in this dashboard"}),i(s.Tabs.Tab,{value:"global_sql_snippets",icon:i(L.IconVariablePlus,{size:14}),children:"Global SQL Snippets"})]}),i(s.Tabs.Panel,{value:"guide",pt:"xs",children:i(St.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:i_})}),i(s.Tabs.Panel,{value:"local_query_vars",pt:"xs",children:i(St.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:l})}),i(s.Tabs.Panel,{value:"global_sql_snippets",pt:"xs",children:h(s.Stack,{spacing:10,children:[i(s.Alert,{icon:i(L.IconAlertCircle,{size:16}),title:"Global SQL Snippets",children:"SQL snippets worth sharing between dashboards are managed in System Settings by admins."}),i(r_,{})]})})]})})}),zi=k.observer(()=>{const[t,e]=y.useState(!1);return h(N,{children:[i(s.Modal,{opened:t,onClose:()=>e(!1),title:"Query Variables",zIndex:320,size:"800px",children:i(Il,{})}),i(s.Button,{variant:"subtle",onClick:()=>e(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},children:"See Query Variables"})]})}),Ml={pre:["function build_request({ context, filters }, utils) {"," // build the quest"," return { method: 'POST', url: '/', params: {}, headers: {}, data: {} }","}"].join(`
|
|
509
509
|
`),post:["function process_result(res, utils) {"," // your code goes here"," return data","}"].join(`
|
|
510
|
-
`)},
|
|
510
|
+
`)},a_=k.observer(({queryModel:t})=>t.typedAsHTTP?h(s.Tabs,{defaultValue:"pre_process",orientation:"vertical",sx:{flexGrow:1},children:[h(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(zi,{})]}),i(s.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:i(rr,{label:"",value:t.pre_process,onChange:t.setPreProcess,defaultValue:Ml.pre})}),i(s.Tabs.Panel,{value:"post_process",p:"sm",children:i(rr,{label:"",value:t.post_process,onChange:t.setPostProcess,defaultValue:Ml.post})})]}):null),s_=k.observer(({queryID:t,usage:e})=>{const n=ge().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:h(s.Table,{highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[i("thead",{children:h("tr",{children:[i("th",{style:{width:100},children:"Type"}),i("th",{style:{width:"calc(50% - 50px)"},children:"Name"}),i("th",{children:"In View(s)"})]})}),i("tbody",{children:e.map(o=>h("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:h(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))})]})})}),$i=({value:t,onChange:e,height:n="200px",defaultLanguage:r="sql",theme:a="vs-dark"})=>{const o=u=>{console.log("changing"),e==null||e(u??"")},l=!e;return i(ze,{className:"minimal-monaco-editor",height:n,defaultLanguage:r,value:t,onChange:l?void 0:o,theme:a,options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1},readOnly:l||!e,"semanticHighlighting.enabled":!0}})},o_=({value:t,height:e="200px",defaultLanguage:n="sql"})=>i(ze,{className:"preview-sql-in-monaco-editor",height:e,defaultLanguage:n,value:t,onChange:void 0,theme:"vs-light",options:{lineNumbers:"on",folding:!0,lineDecorationsWidth:20,wordWrap:"on",minimap:{enabled:!1},readOnly:!0}}),l_=k.observer(({value:t})=>{const n=K().payloadForSQL,r=y.useMemo(()=>dr(t,n),[t,n]);return i(o_,{height:"100%",value:r})}),El={pre:["function process_request({ context, filters, sql }, utils) {"," // modify and return sql"," return sql","}"].join(`
|
|
511
511
|
`),post:["function process_result(data, utils) {"," // process data and return the result"," return data","}"].join(`
|
|
512
|
-
`)},l_=k.observer(({queryModel:t})=>{const[e,n]=y.useState(t.sql);y.useEffect(()=>{n(o=>o!==t.sql?t.sql:o)},[t.sql]);const r=e!==t.sql,a=()=>{t.setSQL(e)};return t.typedAsSQL?p(s.Tabs,{defaultValue:"Edit",orientation:"vertical",sx:{flexGrow:1},styles:{tabLabel:{width:"100%",height:"28px",lineHeight:"28px"}},keepMounted:!1,children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Edit",children:p(s.Group,{spacing:14,position:"apart",children:["Edit SQL",i(s.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!r,onClick:a,children:i(I.DeviceFloppy,{size:20})})]})}),i(s.Tabs.Tab,{value:"Preview",children:"Preview SQL"}),i(s.Tabs.Tab,{value:"pre_process",children:"Process Request"}),i(s.Tabs.Tab,{value:"post_process",children:"Process Result"}),i(zi,{}),t.datasource&&i(Tl,{dataSource:t.datasource})]}),i(s.Tabs.Panel,{value:"Edit",sx:{position:"relative"},p:"sm",children:i($i,{height:"100%",value:e,onChange:n,theme:"sql-dark",defaultLanguage:"sql"})}),i(s.Tabs.Panel,{value:"Preview",p:0,pl:4,children:i(o_,{value:t.sql})}),i(s.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:i(rr,{label:"",value:t.pre_process,onChange:t.setPreProcess,defaultValue:Ml.pre})}),i(s.Tabs.Panel,{value:"post_process",p:"sm",children:i(rr,{label:"",value:t.post_process,onChange:t.setPostProcess,defaultValue:Ml.post})})]}):null}),ir={height:"calc(100% - 44px)",padding:0},c_=k.observer(({queryModel:t})=>{const e=K(),n=y.useMemo(()=>t.datasource?t.typedAsHTTP?"HTTP":"SQL":"Configurations",[t.datasource,t.typedAsHTTP]),[r,a]=y.useState(n);y.useEffect(()=>{a(c=>c!=="Configurations"&&n==="Configurations"?"Configurations":c)},[n]);const o=e.findQueryUsage(t.id),l=o.length===0;return i(s.Stack,{sx:{flexGrow:1},my:0,p:0,children:p(s.Tabs,{value:r,onTabChange:a,defaultValue:n,orientation:"horizontal",keepMounted:!1,sx:{flexGrow:1},children:[p(s.Tabs.List,{grow:!0,children:[i(s.Tabs.Tab,{value:"Configurations",children:"Configurations"}),t.typedAsSQL&&i(s.Tabs.Tab,{value:"SQL",children:"Request"}),t.typedAsHTTP&&i(s.Tabs.Tab,{value:"HTTP",children:"Request"}),i(s.Tabs.Tab,{value:"Data",disabled:!t.datasource,children:i(s.Tooltip,{label:"Need to pick a Data Source first",disabled:t.datasource,withinPortal:!0,children:i(s.Text,{children:"Data"})})}),i(s.Tabs.Tab,{value:"Usage",disabled:l,children:i(s.Tooltip,{label:"This query is not used for any filter or panel",disabled:!l,withinPortal:!0,children:i(s.Text,{children:"Usage"})})})]}),i(s.Tabs.Panel,{value:"Configurations",pt:0,p:0,children:i(ZS,{queryModel:t})}),t.typedAsSQL&&i(s.Tabs.Panel,{value:"SQL",sx:ir,children:i(s.Stack,{sx:{height:"100%"},children:i(l_,{queryModel:t})})}),t.typedAsHTTP&&i(s.Tabs.Panel,{value:"HTTP",sx:ir,children:i(s.Stack,{sx:{height:"100%"},children:i(i_,{queryModel:t})})}),i(s.Tabs.Panel,{value:"Data",sx:{...ir,overflow:"hidden"},children:i(Ei,{id:t.id})}),i(s.Tabs.Panel,{value:"Usage",sx:{...ir,overflow:"hidden"},children:i(a_,{queryID:t.id,usage:o})})]})})}),u_=k.observer(({id:t})=>{const n=K().queries.findByID(t);return t===""?null:n?i(s.Stack,{sx:{height:"100%"},spacing:"sm",children:i(c_,{queryModel:n})}):i(s.Text,{size:14,color:"red",children:"Invalid Query ID"})}),d_=k.observer(({value:t})=>{const n=K().payloadForSQL,r=y.useMemo(()=>dr(t,n),[t,n]);return i($i,{height:"100%",value:r})}),p_=k.observer(({item:t,remove:e,onKeyChanged:n})=>{const[r,a]=y.useState("SQL"),[o,l]=y.useState(t.key),c=()=>{t.setKey(o),n(o)},u=o!==t.key,d=t.isADuplicatedKey(o),[f,h]=y.useState(t.value),g=()=>{t.setValue(f)};y.useEffect(()=>{l(t.key),h(t.value)},[t]);const m=f!==t.value,C=Ke.useModals(),w=()=>{C.openConfirmModal({title:"Delete this SQL snippet?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:e,confirmProps:{color:"red"},zIndex:320})};return p(s.Stack,{p:20,sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",children:[p(s.Group,{sx:{alignItems:"end"},spacing:40,children:[i(s.TextInput,{label:d?"This key is occupied by another snippet":"Key",value:o,onChange:_=>{l(_.currentTarget.value)},sx:{flexGrow:"1 !important"},rightSection:i(s.ActionIcon,{color:"blue",variant:"subtle",onClick:c,disabled:!u||d,children:i(I.DeviceFloppy,{size:16})}),error:d}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:w,children:"Delete this SQL Snippet"})]}),p(s.Tabs,{value:r,onTabChange:a,sx:{flexGrow:1},styles:{panel:{height:"calc(100% - 50px)"}},children:[p(s.Tabs.List,{sx:{position:"relative"},children:[i(s.Tabs.Tab,{value:"SQL",children:"SQL"}),i(s.Tabs.Tab,{value:"Preview",children:"Preview"}),i(zi,{}),i(s.ActionIcon,{color:"blue",variant:"filled",onClick:g,disabled:!m,sx:{position:"absolute",top:0,right:10},children:i(I.DeviceFloppy,{size:18})})]}),i(s.Tabs.Panel,{value:"SQL",pt:"sm",children:i($i,{height:"100%",value:f,onChange:h,defaultLanguage:"sql",theme:"sql-dark"})}),i(s.Tabs.Panel,{value:"Preview",pt:"sm",children:i(d_,{value:f})})]})]})}),h_=k.observer(({id:t})=>{const e=ge(),n=K(),r=y.useMemo(()=>n.sqlSnippets.findByKey(t),[t]);if(!t)return null;if(!r)return p(s.Text,{size:14,children:["SQL Snippet by key[",t,"] is not found"]});const a=()=>{e.editor.setPath(["_SQL_SNIPPETS_",""])};return i(p_,{item:r,remove:()=>{n.sqlSnippets.removeByKey(t),a()},onKeyChanged:c=>{e.editor.setPath(["_SQL_SNIPPETS_",c])}})}),f_=k.observer(({view:t})=>!t||t.type!==H.Division?null:p(s.Stack,{children:[i(s.Divider,{mt:8,mb:0,label:"Division settings",labelPosition:"center"}),i(s.Text,{align:"center",size:"xs",color:"dimmed",children:"Under construction"})]})),g_=[{value:"default",label:"Default"},{value:"outline",label:"Outline"},{value:"pills",label:"Pills"}],m_=[{value:"horizontal",label:"Horizontal"},{value:"vertical",label:"Vertical"}],y_=k.observer(({view:t})=>{if(!t||t.type!==H.Tabs)return null;const e=t.config;return p(s.Stack,{children:[i(s.Divider,{mt:8,mb:0,label:"Tabs settings",labelPosition:"center"}),i(s.Select,{label:"Variant",value:e.variant,onChange:e.setVariant,data:g_}),i(s.Select,{label:"Orientation",value:e.orientation,onChange:e.setOrientation,data:m_}),i(s.Switch,{label:"Grow Tabs",checked:e.grow,onChange:n=>e.setGrow(n.currentTarget.checked)})]})}),b_=({disabled:t,value:e,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[t&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(ze,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},v_=({value:t,onChange:e})=>{const[n,{setTrue:r,setFalse:a}]=J.useBoolean(),[o,l]=y.useState(t??xi),c=g=>{l({...o,enabled:g})},u=()=>{a();const{enabled:g,func_content:m}=o,C={enabled:g,func_content:m};l(C),e(C)},d=()=>{a(),l(t)},f=g=>{l(m=>({...m,func_content:g}))},h=()=>{f(xi.func_content)};return p(N,{children:[i(s.ActionIcon,{size:"lg",color:"blue",variant:"filled",mt:26,onClick:r,sx:{flexGrow:0},children:i(I.Settings,{size:14})}),i(s.Modal,{size:800,title:"Customize modal title",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:o.enabled,onChange:g=>c(g.currentTarget.checked)}),i(b_,{value:o.func_content,onChange:f,disabled:!o.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:h,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:u,children:"OK"})]})]})]})})]})},x_=k.observer(({view:t})=>{if(!t||t.type!==H.Modal)return null;const e=t.config,n=e.custom_modal_title.value;return p(s.Stack,{children:[i(s.Divider,{mt:8,label:"Modal settings",labelPosition:"center"}),p(s.Flex,{gap:10,children:[i(s.TextInput,{label:"Modal Title",value:n,onChange:x.noop,disabled:!0,sx:{flexGrow:1}}),i(v_,{value:e.custom_modal_title,onChange:e.custom_modal_title.replace})]}),p(s.Group,{grow:!0,children:[i(s.TextInput,{label:"Width",value:e.width,onChange:r=>e.setWidth(r.currentTarget.value),placeholder:"600px / 50vw"}),i(s.TextInput,{label:"Height",value:e.height,onChange:r=>e.setHeight(r.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),w_=k.observer(({view:t})=>p(N,{children:[i(f_,{view:t}),i(x_,{view:t}),i(y_,{view:t})]})),C_=[{label:"Division",value:H.Division},{label:"Modal",value:H.Modal},{label:"Tabs",value:H.Tabs}],S_=k.observer(({view:t})=>t?p(s.Stack,{sx:{position:"relative"},children:[i(s.TextInput,{label:"Name",value:t.name,onChange:e=>{t.setName(e.currentTarget.value)}}),i(s.Select,{label:"Type",withinPortal:!0,value:t.type,onChange:t.setType,data:C_}),i(w_,{view:t})]}):null),__=k.observer(({id:t})=>{const e=Ke.useModals(),n=ge(),r=K();if(t==="")return null;const a=r.views.findByID(t);if(!a)return p(s.Text,{size:14,children:["View by ID[",t,"] is not found"]});const o=()=>{n.editor.setPath(["_VIEWS_",""])},l=()=>{e.openConfirmModal({title:"Delete this view?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.views.removeByID(t),o()},zIndex:320})};return p(s.Stack,{sx:{maxWidth:"600px",height:"100%"},spacing:"sm",children:[i(s.Group,{position:"right",pt:10,children:i(s.Button,{size:"xs",color:"red",leftIcon:i(I.Trash,{size:16}),onClick:l,children:"Delete this view"})}),i(s.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:i(S_,{view:a})})]})});function k_(t){return t.length===1&&t[0]==="_QUERY_VARS_"}function T_(t){return t.length===1&&t[0]==="_MOCK_CONTEXT_"}function D_(t){return t.length===2&&t[0]==="_FILTERS_"}function I_(t){return t.length===2&&t[0]==="_SQL_SNIPPETS_"}function M_(t){return t.length===2&&t[0]==="_QUERIES_"}function E_(t){return t.length===2&&t[0]==="_VIEWS_"}function A_(t){return t.length===4&&t[0]==="_VIEWS_"&&t[2]==="_PANELS_"}const z_=k.observer(()=>i(s.Stack,{sx:{height:"100%"},p:"sm",children:i(Dl,{})})),$_=k.observer(()=>{const t=ge().editor,e=t.path;return k_(e)?i(z_,{}):T_(e)?i(nS,{}):D_(e)?i(s.Box,{p:"xs",pl:20,children:i(tS,{id:e[1]})}):I_(e)?i(h_,{id:e[1]}):M_(e)?i(u_,{id:e[1]}):E_(e)?i(s.Box,{p:"xs",pl:20,children:i(__,{id:e[1]})}):A_(e)?i(AS,{viewID:e[1],panelID:e[3]}):i(s.Box,{children:t.path})}),L_=k.observer(()=>i($_,{})),O_=k.observer(()=>{const t=ge(),e=()=>{const n=new Date().getTime().toString(),r={id:n,key:n,label:n,order:t.content.filters.current.length+1,type:vi.TextInput,config:Ha(),visibleInViewsIDs:["Main"],auto_submit:!1};t.content.filters.append(r),t.editor.setPath(["_FILTERS_",n])};return i(s.Button,{variant:"subtle",leftIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:e,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Filter"})}),P_=k.observer(({parentID:t})=>{const e=K();if(!t)return null;const n=e.views.findByID(t);return n?i(s.Button,{variant:"subtle",leftIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:()=>e.addANewPanel(n.id),sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Panel"}):null}),B_=k.observer(()=>{const t=ge(),e=()=>{const n=new Date().getTime().toString(),r={id:n,name:n,type:be.Postgresql,key:"",sql:""};t.content.queries.append(r),t.editor.setPath(["_QUERIES_",n])};return i(s.Button,{variant:"subtle",leftIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:e,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Query"})}),V_=k.observer(()=>{const t=ge(),e=()=>{const n=new Date().getTime().toString(),r={key:n,value:""};t.content.sqlSnippets.append(r),t.editor.setPath(["_SQL_SNIPPETS_",n])};return i(s.Button,{variant:"subtle",leftIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:e,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a SQL Snippet"})}),N_=k.observer(()=>{const t=K();return i(s.Button,{variant:"subtle",leftIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a View"})}),q_=k.observer(({action_type:t,parentID:e})=>(K(),t==="_Add_A_Filter_"?i(O_,{}):t==="_Add_A_SQL_SNIPPET_"?i(V_,{}):t==="_Add_A_QUERY_"?i(B_,{}):t==="_Add_A_VIEW_"?i(N_,{}):t==="_Add_A_PANEL_"?i(P_,{parentID:e}):null)),El=k.observer(({option:t})=>{var d;const e=ge().editor,n=e.isOptionActive,r=n(e.path,t),a=e.isOptionOpened,o=e.navigate,l=a(t),[c,u]=y.useState(l);return y.useEffect(()=>{u(l)},[l]),i(s.NavLink,{active:r,defaultOpened:l,opened:c,onChange:u,label:t.label,onClick:()=>o(t),icon:t.Icon?i(t.Icon,{size:18}):null,children:(d=t.children)==null?void 0:d.map(f=>f._type==="ACTION"?i(q_,{action_type:f._action_type,parentID:f.parentID},`_ADD_${f.value}_`):i(El,{option:f},f.value))},t.label)}),F_=k.observer(()=>{const t=ge();return i(s.Box,{sx:{position:"relative"},children:t.editor.navOptions.map(e=>i(El,{option:e},e.value))})}),G_=k.observer(()=>{const t=ge();return p(s.Navbar,{p:0,width:{base:200,xs:200,sm:220,md:240,lg:280,xl:300},sx:{height:"100vh - 60px - 60px"},children:[i(s.Navbar.Section,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:i(s.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Settings"})}),i(s.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:i(F_,{})}),i(s.Navbar.Section,{children:i(s.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:i(s.Button,{size:"xs",color:"red",leftIcon:i(L.IconX,{size:18}),onClick:()=>t.editor.close(),children:"Close"})})})]})}),W_={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"}},R_=k.observer(()=>{const t=ge().editor;return i(s.Modal,{onClose:()=>t.setSettingsOpen(!1),closeOnEscape:!1,closeOnClickOutside:!1,opened:t.settings_open,fullScreen:!0,title:null,transitionDuration:0,withCloseButton:!1,withinPortal:!0,zIndex:300,styles:{modal:{padding:"0 !important"}},children:i(s.AppShell,{padding:0,navbar:i(G_,{}),styles:W_,children:i(L_,{})})})}),j_=t=>t.replace(/([^:])(\/\/+)/g,"$1/");function Y_(t){y.useEffect(()=>{if(ze.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const n=j_(t);ze.loader.config({paths:{vs:n}}),ze.loader.init().then(r=>console.log("monaco instance:",r))},[])}Ls();const Q_={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:60+30,height:"100vh"}},K_=({context:t,dashboard:e,content:n,update:r,className:a="dashboard",config:o,onChange:l,headerSlot:c,headerMenuItems:u},d)=>{Y_(o.monacoPath),Fa(o);const{data:f=[]}=J.useRequest(pr),{data:h=[]}=J.useRequest(Ga),[g,m]=y.useState(!1),C=y.useMemo(()=>Ci(e,n,f,h,t),[e,n]);y.useImperativeHandle(d,()=>C,[C]),ja(C.content,!0),y.useEffect(()=>{C.context.replace(t)},[t]),y.useEffect(()=>{C.datasources.replace(f)},[f]),y.useEffect(()=>{C.globalSQLSnippets.replace(h)},[h]),y.useEffect(()=>ae.reaction(()=>ae.toJS(C.json),M=>{l==null||l(M)}),[C]);const w=async()=>{await r(C.json,C.content.json)},_=J.useCreation(fi,[]),T=ki(_);return i(Ke.ModalsProvider,{children:i(fr,{value:C,children:i(hr,{value:C.content,children:i(ft.Provider,{value:{layoutFrozen:g,freezeLayout:m,inEditMode:!0},children:i(it.Provider,{value:_,children:p(Jn,{configure:T,children:[i(s.AppShell,{padding:0,header:i(h1,{saveDashboardChanges:w,headerSlot:c,headerMenuItems:u}),navbar:i(q1,{}),styles:Q_,children:i(s.Box,{className:`${a} dashboard-root`,sx:{position:"relative"},children:C.content.views.visibleViews.map(M=>i(fl,{view:M},M.id))})}),i(R_,{})]})})})})})})},U_=k.observer(y.forwardRef(K_)),tD="";Ls();const X_=k.observer(({context:t,dashboard:e,content:n,className:r="dashboard",config:a,fullScreenPanelID:o,setFullScreenPanelID:l})=>{Fa(a);const{data:c=[]}=J.useRequest(pr),{data:u=[]}=J.useRequest(Ga),d=y.useMemo(()=>Ci(e,n,c,u,t),[e,n]);ja(d.content,!1),y.useEffect(()=>{d.context.replace(t)},[t]),y.useEffect(()=>{d.datasources.replace(c)},[c]),y.useEffect(()=>{d.globalSQLSnippets.replace(u)},[u]);const f=J.useCreation(fi,[]),h=ki(f);return i(Ke.ModalsProvider,{children:i(fr,{value:d,children:i(hr,{value:d.content,children:i(Cr.Provider,{value:{fullScreenPanelID:o,setFullScreenPanelID:l},children:i(ft.Provider,{value:{layoutFrozen:!0,freezeLayout:x.noop,inEditMode:!1},children:i(s.Box,{className:`${r} dashboard-root`,children:i(it.Provider,{value:f,children:i(Jn,{configure:h,children:d.content.views.visibleViews.map(g=>i(er,{view:g},g.id))})})})})})})})})});var Li={},J_={get exports(){return Li},set exports(t){Li=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){var a=r.prototype,o=a.format;a.format=function(l){var c=this,u=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((c.$M+1)/3);case"Do":return u.ordinal(c.$D);case"gggg":return c.weekYear();case"GGGG":return c.isoWeekYear();case"wo":return u.ordinal(c.week(),"W");case"w":case"ww":return d.s(c.week(),h==="w"?1:2,"0");case"W":case"WW":return d.s(c.isoWeek(),h==="W"?1:2,"0");case"k":case"kk":return d.s(String(c.$H===0?24:c.$H),h==="k"?1:2,"0");case"X":return Math.floor(c.$d.getTime()/1e3);case"x":return c.$d.getTime();case"z":return"["+c.offsetName()+"]";case"zzz":return"["+c.offsetName("long")+"]";default:return h}});return o.bind(this)(f)}}})})(J_);const Z_=Li;var Oi={},H_={get exports(){return Oi},set exports(t){Oi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){var o=r.prototype,l=function(u){var d=u.date,f=u.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},c=o.parse;o.parse=function(u){u.date=l.bind(this)(u),c.bind(this)(u)}}})})(H_);const ek=Oi;var Pi={},tk={get exports(){return Pi},set exports(t){Pi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){var a=r.prototype;a.$g=function(g,m,C){return this.$utils().u(g)?this[m]:this.$set(C,g)},a.set=function(g,m){return this.$set(g,m)};var o=a.startOf;a.startOf=function(g,m){return this.$d=o.bind(this)(g,m).toDate(),this.init(),this};var l=a.add;a.add=function(g,m){return this.$d=l.bind(this)(g,m).toDate(),this.init(),this};var c=a.locale;a.locale=function(g,m){return g?(this.$L=c.bind(this)(g,m).$L,this):this.$L};var u=a.daysInMonth;a.daysInMonth=function(){return u.bind(this.clone())()};var d=a.isSame;a.isSame=function(g,m){return d.bind(this.clone())(g,m)};var f=a.isBefore;a.isBefore=function(g,m){return f.bind(this.clone())(g,m)};var h=a.isAfter;a.isAfter=function(g,m){return h.bind(this.clone())(g,m)}}})})(tk);const nk=Pi;var Bi={},rk={get exports(){return Bi},set exports(t){Bi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){var a=r.prototype,o=a.format;a.format=function(l){var c=this,u=(l||"YYYY-MM-DDTHH:mm:ssZ").replace(/(\[[^\]]+])|BBBB|BB/g,function(d,f){var h,g=String(c.$y+543),m=d==="BB"?[g.slice(-2),2]:[g,4];return f||(h=c.$utils()).s.apply(h,m.concat(["0"]))});return o.bind(this)(u)}}})})(rk);const ik=Bi;var Vi={},ak={get exports(){return Vi},set exports(t){Vi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){var o="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(c,u){var d=u||this.$locale().calendar||l,f=a(c||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)}}})})(ak);const sk=Vi;var Ni={},ok={get exports(){return Ni},set exports(t){Ni=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"},r=/(\[[^[]*\])|([-_:/.,()\s]+)|(A|a|YYYY|YY?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g,a=/\d\d/,o=/\d\d?/,l=/\d*[^-_:/,()\s\d]+/,c={},u=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 _=c[w];return _&&(_.indexOf?_:_.s.concat(_.f))},g=function(w,_){var T,M=c.meridiem;if(M){for(var O=1;O<=24;O+=1)if(w.indexOf(M(O,0,_))>-1){T=O>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 _=c.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=u(w)}],YYYY:[/\d{4}/,d("year")],Z:f,ZZ:f};function C(w){var _,T;_=w,T=c&&c.formats;for(var M=(w=_.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(W,U,X){var oe=X&&X.toUpperCase();return U||T[X]||n[X]||T[oe].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(re,de,Ce){return de||Ce.slice(1)})})).match(r),O=M.length,B=0;B<O;B+=1){var F=M[B],$=m[F],E=$&&$[0],z=$&&$[1];M[B]=z?{regex:E,parser:z}:F.replace(/^\[|\]$/g,"")}return function(W){for(var U={},X=0,oe=0;X<O;X+=1){var re=M[X];if(typeof re=="string")oe+=re.length;else{var de=re.regex,Ce=re.parser,ye=W.slice(oe),Te=de.exec(ye)[0];Ce.call(U,Te),W=W.replace(Te,"")}}return function(fe){var Oe=fe.afternoon;if(Oe!==void 0){var Ye=fe.hours;Oe?Ye<12&&(fe.hours+=12):Ye===12&&(fe.hours=0),delete fe.afternoon}}(U),U}}return function(w,_,T){T.p.customParseFormat=!0,w&&w.parseTwoDigitYear&&(u=w.parseTwoDigitYear);var M=_.prototype,O=M.parse;M.parse=function(B){var F=B.date,$=B.utc,E=B.args;this.$u=$;var z=E[1];if(typeof z=="string"){var W=E[2]===!0,U=E[3]===!0,X=W||U,oe=E[2];U&&(oe=E[2]),c=this.$locale(),!W&&oe&&(c=T.Ls[oe]),this.$d=function(ye,Te,fe){try{if(["x","X"].indexOf(Te)>-1)return new Date((Te==="X"?1e3:1)*ye);var Oe=C(Te)(ye),Ye=Oe.year,Mt=Oe.month,ar=Oe.day,sr=Oe.hours,fa=Oe.minutes,ga=Oe.seconds,ln=Oe.milliseconds,Ft=Oe.zone,xt=new Date,Et=ar||(Ye||Mt?1:xt.getDate()),wt=Ye||xt.getFullYear(),Gt=0;Ye&&!Mt||(Gt=Mt>0?Mt-1:xt.getMonth());var Wt=sr||0,cn=fa||0,un=ga||0,Ct=ln||0;return Ft?new Date(Date.UTC(wt,Gt,Et,Wt,cn,un,Ct+60*Ft.offset*1e3)):fe?new Date(Date.UTC(wt,Gt,Et,Wt,cn,un,Ct)):new Date(wt,Gt,Et,Wt,cn,un,Ct)}catch{return new Date("")}}(F,z,$),this.init(),oe&&oe!==!0&&(this.$L=this.locale(oe).$L),X&&F!=this.format(z)&&(this.$d=new Date("")),c={}}else if(z instanceof Array)for(var re=z.length,de=1;de<=re;de+=1){E[1]=z[de-1];var Ce=T.apply(this,E);if(Ce.isValid()){this.$d=Ce.$d,this.$L=Ce.$L,this.init();break}de===re&&(this.$d=new Date(""))}else O.call(this,B)}}})})(ok);const lk=Ni;var qi={},ck={get exports(){return qi},set exports(t){qi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){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")}}})})(ck);const uk=qi;var Fi={},dk={get exports(){return Fi},set exports(t){Fi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n,r,a=1e3,o=6e4,l=36e5,c=864e5,u=/\[([^\]]+)]|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:c,hours:l,minutes:o,seconds:a,milliseconds:1,weeks:6048e5},m=function($){return $ instanceof B},C=function($,E,z){return new B($,z,E.$l)},w=function($){return r.p($)+"s"},_=function($){return $<0},T=function($){return _($)?Math.ceil($):Math.floor($)},M=function($){return Math.abs($)},O=function($,E){return $?_($)?{negative:!0,format:""+M($)+E}:{negative:!1,format:""+$+E}:{negative:!1,format:""}},B=function(){function $(z,W,U){var X=this;if(this.$d={},this.$l=U,z===void 0&&(this.$ms=0,this.parseFromMilliseconds()),W)return C(z*g[w(W)],this);if(typeof z=="number")return this.$ms=z,this.parseFromMilliseconds(),this;if(typeof z=="object")return Object.keys(z).forEach(function(de){X.$d[w(de)]=z[de]}),this.calMilliseconds(),this;if(typeof z=="string"){var oe=z.match(h);if(oe){var re=oe.slice(2).map(function(de){return de!=null?Number(de):0});return this.$d.years=re[0],this.$d.months=re[1],this.$d.weeks=re[2],this.$d.days=re[3],this.$d.hours=re[4],this.$d.minutes=re[5],this.$d.seconds=re[6],this.calMilliseconds(),this}}return this}var E=$.prototype;return E.calMilliseconds=function(){var z=this;this.$ms=Object.keys(this.$d).reduce(function(W,U){return W+(z.$d[U]||0)*g[U]},0)},E.parseFromMilliseconds=function(){var z=this.$ms;this.$d.years=T(z/d),z%=d,this.$d.months=T(z/f),z%=f,this.$d.days=T(z/c),z%=c,this.$d.hours=T(z/l),z%=l,this.$d.minutes=T(z/o),z%=o,this.$d.seconds=T(z/a),z%=a,this.$d.milliseconds=z},E.toISOString=function(){var z=O(this.$d.years,"Y"),W=O(this.$d.months,"M"),U=+this.$d.days||0;this.$d.weeks&&(U+=7*this.$d.weeks);var X=O(U,"D"),oe=O(this.$d.hours,"H"),re=O(this.$d.minutes,"M"),de=this.$d.seconds||0;this.$d.milliseconds&&(de+=this.$d.milliseconds/1e3);var Ce=O(de,"S"),ye=z.negative||W.negative||X.negative||oe.negative||re.negative||Ce.negative,Te=oe.format||re.format||Ce.format?"T":"",fe=(ye?"-":"")+"P"+z.format+W.format+X.format+Te+oe.format+re.format+Ce.format;return fe==="P"||fe==="-P"?"P0D":fe},E.toJSON=function(){return this.toISOString()},E.format=function(z){var W=z||"YYYY-MM-DDTHH:mm:ss",U={Y:this.$d.years,YY:r.s(this.$d.years,2,"0"),YYYY:r.s(this.$d.years,4,"0"),M:this.$d.months,MM:r.s(this.$d.months,2,"0"),D:this.$d.days,DD:r.s(this.$d.days,2,"0"),H:this.$d.hours,HH:r.s(this.$d.hours,2,"0"),m:this.$d.minutes,mm:r.s(this.$d.minutes,2,"0"),s:this.$d.seconds,ss:r.s(this.$d.seconds,2,"0"),SSS:r.s(this.$d.milliseconds,3,"0")};return W.replace(u,function(X,oe){return oe||String(U[X])})},E.as=function(z){return this.$ms/g[w(z)]},E.get=function(z){var W=this.$ms,U=w(z);return U==="milliseconds"?W%=1e3:W=U==="weeks"?T(W/g[U]):this.$d[U],W===0?0:W},E.add=function(z,W,U){var X;return X=W?z*g[w(W)]:m(z)?z.$ms:C(z,this).$ms,C(this.$ms+X*(U?-1:1),this)},E.subtract=function(z,W){return this.add(z,W,!0)},E.locale=function(z){var W=this.clone();return W.$l=z,W},E.clone=function(){return C(this.$ms,this)},E.humanize=function(z){return n().add(this.$ms,"ms").locale(this.$l).fromNow(!z)},E.valueOf=function(){return this.asMilliseconds()},E.milliseconds=function(){return this.get("milliseconds")},E.asMilliseconds=function(){return this.as("milliseconds")},E.seconds=function(){return this.get("seconds")},E.asSeconds=function(){return this.as("seconds")},E.minutes=function(){return this.get("minutes")},E.asMinutes=function(){return this.as("minutes")},E.hours=function(){return this.get("hours")},E.asHours=function(){return this.as("hours")},E.days=function(){return this.get("days")},E.asDays=function(){return this.as("days")},E.weeks=function(){return this.get("weeks")},E.asWeeks=function(){return this.as("weeks")},E.months=function(){return this.get("months")},E.asMonths=function(){return this.as("months")},E.years=function(){return this.get("years")},E.asYears=function(){return this.as("years")},$}(),F=function($,E,z){return $.add(E.years()*z,"y").add(E.months()*z,"M").add(E.days()*z,"d").add(E.hours()*z,"h").add(E.minutes()*z,"m").add(E.seconds()*z,"s").add(E.milliseconds()*z,"ms")};return function($,E,z){n=z,r=z().$utils(),z.duration=function(X,oe){var re=z.locale();return C(X,{$l:re},oe)},z.isDuration=m;var W=E.prototype.add,U=E.prototype.subtract;E.prototype.add=function(X,oe){return m(X)?F(this,X,1):W.bind(this)(X,oe)},E.prototype.subtract=function(X,oe){return m(X)?F(this,X,-1):U.bind(this)(X,oe)}}})})(dk);const pk=Fi;var Gi={},hk={get exports(){return Gi},set exports(t){Gi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){r.prototype.isBetween=function(o,l,c,u){var d=a(o),f=a(l),h=(u=u||"()")[0]==="(",g=u[1]===")";return(h?this.isAfter(d,c):!this.isBefore(d,c))&&(g?this.isBefore(f,c):!this.isAfter(f,c))||(h?this.isBefore(d,c):!this.isAfter(d,c))&&(g?this.isAfter(f,c):!this.isBefore(f,c))}}})})(hk);const fk=Gi;var Wi={},gk={get exports(){return Wi},set exports(t){Wi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.isLeapYear=function(){return this.$y%4==0&&this.$y%100!=0||this.$y%400==0}}})})(gk);const mk=Wi;var Ri={},yk={get exports(){return Ri},set exports(t){Ri=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){a.isMoment=function(o){return a.isDayjs(o)}}})})(yk);const bk=Ri;var ji={},vk={get exports(){return ji},set exports(t){ji=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n="day";return function(r,a,o){var l=function(d){return d.add(4-d.isoWeekday(),n)},c=a.prototype;c.isoWeekYear=function(){return l(this).year()},c.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},c.isoWeekday=function(d){return this.$utils().u(d)?this.day()||7:this.day(this.day()%7?d:d-7)};var u=c.startOf;c.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"):u.bind(this)(d,f)}}})})(vk);const xk=ji;var Yi={},wk={get exports(){return Yi},set exports(t){Yi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.isoWeeksInYear=function(){var a=this.isLeapYear(),o=this.endOf("y").day();return o===4||a&&o===5?53:52}}})})(wk);const Ck=Yi;var Qi={},Sk={get exports(){return Qi},set exports(t){Qi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.isSameOrAfter=function(a,o){return this.isSame(a,o)||this.isAfter(a,o)}}})})(Sk);const _k=Qi;var Ki={},kk={get exports(){return Ki},set exports(t){Ki=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.isSameOrBefore=function(a,o){return this.isSame(a,o)||this.isBefore(a,o)}}})})(kk);const Tk=Ki;var Ui={},Dk={get exports(){return Ui},set exports(t){Ui=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){r.prototype.isToday=function(){var o="YYYY-MM-DD",l=a();return this.format(o)===l.format(o)}}})})(Dk);const Ik=Ui;var Xi={},Mk={get exports(){return Xi},set exports(t){Xi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){r.prototype.isTomorrow=function(){var o="YYYY-MM-DD",l=a().add(1,"day");return this.format(o)===l.format(o)}}})})(Mk);const Ek=Xi;var Ji={},Ak={get exports(){return Ji},set exports(t){Ji=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){r.prototype.isYesterday=function(){var o="YYYY-MM-DD",l=a().subtract(1,"day");return this.format(o)===l.format(o)}}})})(Ak);const zk=Ji;var Zi={},$k={get exports(){return Zi},set exports(t){Zi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){var o=r.prototype,l=function(h){return h&&(h.indexOf?h:h.s)},c=function(h,g,m,C,w){var _=h.name?h:h.$locale(),T=l(_[g]),M=l(_[m]),O=T||M.map(function(F){return F.slice(0,C)});if(!w)return O;var B=_.weekStart;return O.map(function(F,$){return O[($+(B||0))%7]})},u=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"):c(h,"months")},monthsShort:function(g){return g?g.format("MMM"):c(h,"monthsShort","months",3)},firstDayOfWeek:function(){return h.$locale().weekStart||0},weekdays:function(g){return g?g.format("dddd"):c(h,"weekdays")},weekdaysMin:function(g){return g?g.format("dd"):c(h,"weekdaysMin","weekdays",2)},weekdaysShort:function(g){return g?g.format("ddd"):c(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=u();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 c(u(),"months")},a.monthsShort=function(){return c(u(),"monthsShort","months",3)},a.weekdays=function(h){return c(u(),"weekdays",null,null,h)},a.weekdaysShort=function(h){return c(u(),"weekdaysShort","weekdays",3,h)},a.weekdaysMin=function(h){return c(u(),"weekdaysMin","weekdays",2,h)}}})})($k);const Lk=Zi;var Hi={},Ok={get exports(){return Hi},set exports(t){Hi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"};return function(r,a,o){var l=a.prototype,c=l.format;o.en.formats=n,l.format=function(u){u===void 0&&(u="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,O){return M||O.slice(1)})})}(u,d===void 0?{}:d);return c.call(this,f)}}})})(Ok);const Pk=Hi;var ea={},Bk={get exports(){return ea},set exports(t){ea=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){var o=function(l,c){if(!c||!c.length||c.length===1&&!c[0]||c.length===1&&Array.isArray(c[0])&&!c[0].length)return null;var u;c.length===1&&c[0].length>0&&(c=c[0]),u=(c=c.filter(function(f){return f}))[0];for(var d=1;d<c.length;d+=1)c[d].isValid()&&!c[d][l](u)||(u=c[d]);return u};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)}}})})(Bk);const Vk=ea;var ta={},Nk={get exports(){return ta},set exports(t){ta=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){var o=r.prototype,l=function(g){var m,C=g.date,w=g.utc,_={};if(!((m=C)===null||m 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(W){var U,X;_[U=W,X=o.$utils().p(U),X==="date"?"day":X]=C[W]});var M=_.day||(_.year||_.month>=0?1:T.date()),O=_.year||T.year(),B=_.month>=0?_.month:_.year||_.day?0:T.month(),F=_.hour||0,$=_.minute||0,E=_.second||0,z=_.millisecond||0;return w?new Date(Date.UTC(O,B,M,F,$,E,z)):new Date(O,B,M,F,$,E,z)}return C},c=o.parse;o.parse=function(g){g.date=l.bind(this)(g),c.bind(this)(g)};var u=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 u.bind(this)(w,C)},m,g):u.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)}}})})(Nk);const qk=ta;var na={},Fk={get exports(){return na},set exports(t){na=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){var a=r.prototype;["milliseconds","seconds","minutes","hours","days","weeks","isoWeeks","months","quarters","years","dates"].forEach(function(o){a[o]=a[o.replace(/s$/,"")]})}})})(Fk);const Gk=na;var ra={},Wk={get exports(){return ra},set exports(t){ra=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){var a=r.prototype.parse;r.prototype.parse=function(c){if(typeof c.date=="string"){var u=this.$locale();c.date=u&&u.preparse?u.preparse(c.date):c.date}return a.bind(this)(c)};var o=r.prototype.format;r.prototype.format=function(){for(var c=arguments.length,u=new Array(c),d=0;d<c;d++)u[d]=arguments[d];var f=o.call.apply(o,[this].concat(u)),h=this.$locale();return h&&h.postformat?h.postformat(f):f};var l=r.prototype.fromToBase;l&&(r.prototype.fromToBase=function(c,u,d,f){var h=this.$locale()||d.$locale();return l.call(this,c,u,d,f,h&&h.postformat)})}})})(Wk);const Rk=ra;var ia={},jk={get exports(){return ia},set exports(t){ia=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n="month",r="quarter";return function(a,o){var l=o.prototype;l.quarter=function(d){return this.$utils().u(d)?Math.ceil((this.month()+1)/3):this.month(this.month()%3+3*(d-1))};var c=l.add;l.add=function(d,f){return d=Number(d),this.$utils().p(f)===r?this.add(3*d,n):c.bind(this)(d,f)};var u=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 u.bind(this)(d,f)}}})})(jk);const Yk=ia;var aa={},Qk={get exports(){return aa},set exports(t){aa=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){n=n||{};var o=r.prototype,l={future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"};function c(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"}],O=M.length,B=0;B<O;B+=1){var F=M[B];F.d&&(C=g?a(d).diff(h,F.d,!0):h.diff(d,F.d,!0));var $=(n.rounding||Math.round)(Math.abs(C));if(_=C>0,$<=F.r||!F.r){$<=1&&B>0&&(F=M[B-1]);var E=T[F.l];m&&($=m(""+$)),w=typeof E=="string"?E.replace("%d",$):E($,f,F.l,_);break}}if(f)return w;var z=_?T.future:T.past;return typeof z=="function"?z(w):z.replace("%s",w)},o.to=function(d,f){return c(d,f,this,!0)},o.from=function(d,f){return c(d,f,this)};var u=function(d){return d.$u?a.utc():a()};o.toNow=function(d){return this.to(u(this),d)},o.fromNow=function(d){return this.from(u(this),d)}}})})(Qk);const Kk=aa;var sa={},Uk={get exports(){return sa},set exports(t){sa=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n={year:0,month:1,day:2,hour:3,minute:4,second:5},r={};return function(a,o,l){var c,u=function(g,m,C){C===void 0&&(C={});var w=new Date(g),_=function(T,M){M===void 0&&(M={});var O=M.timeZoneName||"short",B=T+"|"+O,F=r[B];return F||(F=new Intl.DateTimeFormat("en-US",{hour12:!1,timeZone:T,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:O}),r[B]=F),F}(m,C);return _.formatToParts(w)},d=function(g,m){for(var C=u(g,m),w=[],_=0;_<C.length;_+=1){var T=C[_],M=T.type,O=T.value,B=n[M];B>=0&&(w[B]=parseInt(O,10))}var F=w[3],$=F===24?0:F,E=w[0]+"-"+w[1]+"-"+w[2]+" "+$+":"+w[4]+":"+w[5]+":000",z=+g;return(l.utc(E).valueOf()-(z-=z%1e3))/6e4},f=o.prototype;f.tz=function(g,m){g===void 0&&(g=c);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 O=M.utcOffset();M=M.add(C-O,"minute")}return M.$x.$timezone=g,M},f.offsetName=function(g){var m=this.$x.$timezone||l.tz.guess(),C=u(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||c,T=d(+l(),_);if(typeof g!="string")return l(g).tz(_);var M=function($,E,z){var W=$-60*E*1e3,U=d(W,z);if(E===U)return[W,E];var X=d(W-=60*(U-E)*1e3,z);return U===X?[W,U]:[$-60*Math.min(U,X)*1e3,Math.max(U,X)]}(l.utc(g,w).valueOf(),T,_),O=M[0],B=M[1],F=l(O).utcOffset(B);return F.$x.$timezone=_,F},l.tz.guess=function(){return Intl.DateTimeFormat().resolvedOptions().timeZone},l.tz.setDefault=function(g){c=g}}})})(Uk);const Xk=sa;var oa={},Jk={get exports(){return oa},set exports(t){oa=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.toArray=function(){return[this.$y,this.$M,this.$D,this.$H,this.$m,this.$s,this.$ms]}}})})(Jk);const Zk=oa;var la={},Hk={get exports(){return la},set exports(t){la=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.toObject=function(){return{years:this.$y,months:this.$M,date:this.$D,hours:this.$H,minutes:this.$m,seconds:this.$s,milliseconds:this.$ms}}}})})(Hk);const eT=la;var ca={},tT={get exports(){return ca},set exports(t){ca=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){a.updateLocale=function(o,l){var c=a.Ls[o];if(c)return(l?Object.keys(l):[]).forEach(function(u){c[u]=l[u]}),c}}})})(tT);const nT=ca;var ua={},rT={get exports(){return ua},set exports(t){ua=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n="minute",r=/[+-]\d\d(?::?\d\d)?/g,a=/([+-]|\d\d)/g;return function(o,l,c){var u=l.prototype;c.utc=function(w){var _={date:w,utc:!0,args:arguments};return new l(_)},u.utc=function(w){var _=c(this.toDate(),{locale:this.$L,utc:!0});return w?_.add(this.utcOffset(),n):_},u.local=function(){return c(this.toDate(),{locale:this.$L,utc:!1})};var d=u.parse;u.parse=function(w){w.utc&&(this.$u=!0),this.$utils().u(w.$offset)||(this.$offset=w.$offset),d.call(this,w)};var f=u.init;u.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=u.utcOffset;u.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(F){F===void 0&&(F="");var $=F.match(r);if(!$)return null;var E=(""+$[0]).match(a)||["-",0,0],z=E[0],W=60*+E[1]+ +E[2];return W===0?0:z==="+"?W:-W}(w),w===null))return this;var M=Math.abs(w)<=16?60*w:w,O=this;if(_)return O.$offset=M,O.$u=w===0,O;if(w!==0){var B=this.$u?this.toDate().getTimezoneOffset():-1*this.utcOffset();(O=this.local().add(M+B,n)).$offset=M,O.$x.$localOffset=B}else O=this.utc();return O};var g=u.format;u.format=function(w){var _=w||(this.$u?"YYYY-MM-DDTHH:mm:ss[Z]":"");return g.call(this,_)},u.valueOf=function(){var w=this.$utils().u(this.$offset)?0:this.$offset+(this.$x.$localOffset||this.$d.getTimezoneOffset());return this.$d.valueOf()-6e4*w},u.isUTC=function(){return!!this.$u},u.toISOString=function(){return this.toDate().toISOString()},u.toString=function(){return this.toDate().toUTCString()};var m=u.toDate;u.toDate=function(w){return w==="s"&&this.$offset?c(this.format("YYYY-MM-DD HH:mm:ss:SSS")).toDate():m.call(this)};var C=u.diff;u.diff=function(w,_,T){if(w&&this.$u===w.$u)return C.call(this,w,_,T);var M=this.local(),O=c(w).local();return C.call(M,O,_,T)}}})})(rT);const iT=ua;var da={},aT={get exports(){return da},set exports(t){da=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.weekday=function(a){var o=this.$locale().weekStart||0,l=this.$W,c=(l<o?l+7:l)-o;return this.$utils().u(a)?c:this.subtract(c,"day").add(a,"day")}}})})(aT);const sT=da;var pa={},oT={get exports(){return pa},set exports(t){pa=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n="week",r="year";return function(a,o,l){var c=o.prototype;c.week=function(u){if(u===void 0&&(u=null),u!==null)return this.add(7*(u-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)},c.weeks=function(u){return u===void 0&&(u=null),this.week(u)}}})})(oT);const lT=pa;var ha={},cT={get exports(){return ha},set exports(t){ha=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.weekYear=function(){var a=this.month(),o=this.week(),l=this.year();return o===1&&a===11?l+1:a===0&&o>=52?l-1:l}}})})(cT);const uT=ha;Y.extend(Z_),Y.extend(ek),Y.extend(nk),Y.extend(ik),Y.extend(sk),Y.extend(lk),Y.extend(uk),Y.extend(pk),Y.extend(fk),Y.extend(mk),Y.extend(bk),Y.extend(_k),Y.extend(Tk),Y.extend(Ik),Y.extend(Ek),Y.extend(zk),Y.extend(xk),Y.extend(Ck),Y.extend(Lk),Y.extend(Pk),Y.extend(Vk),Y.extend(qk),Y.extend(Gk),Y.extend(Rk),Y.extend(Yk),Y.extend(Kk),Y.extend(Xk),Y.extend(Zk),Y.extend(eT),Y.extend(nT),Y.extend(iT),Y.extend(lT),Y.extend(uT),Y.extend(sT),Y.tz.setDefault("UTC");const dT=()=>Promise.resolve().then(()=>nu).then(({version:t})=>(console.log(`[@devtable/dashboard] version: ${t}`),t));D.ContentModel=Xn,D.ContentModelContextProvider=hr,D.ContextModel=ds,D.DashboardEditor=U_,D.DashboardFilterType=vi,D.DashboardMode=Qo,D.DashboardModel=nl,D.DashboardViewEditor=fl,D.DashboardViewRender=er,D.EViewComponentType=H,D.FilterModel=mr,D.FiltersModel=ts,D.FullScreenPanelContext=Cr,D.LayoutStateContext=ft,D.ModelContextProvider=fr,D.Panel=Hn,D.PanelContextProvider=wr,D.PanelModel=Ro,D.PanelsModel=Yo,D.QueriesModel=ls,D.QueryModel=os,D.ReadOnlyDashboard=X_,D.SQLSnippetModel=cs,D.SQLSnippetsModel=us,D.ViewComponentTypeBackground=Ko,D.ViewComponentTypeColor=tC,D.ViewComponentTypeName=eC,D.ViewModel=Zo,D.ViewsModel=Ho,D.applyPartialDashboard=cC,D.createContentModel=tl,D.createDashboardModel=Ci,D.createDashboardViewsModel=wi,D.getInitialFiltersPayload=ns,D.getNewPanel=jo,D.getVersion=dT,D.initialDashboardContent=nC,D.useContentModelContext=K,D.useFullScreenPanelContext=bs,D.useModelContext=ge,D.usePanelContext=Ae,D.useTopLevelServices=ki,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
|
|
512
|
+
`)},u_=k.observer(({queryModel:t})=>{const[e,n]=y.useState(t.sql);y.useEffect(()=>{n(o=>o!==t.sql?t.sql:o)},[t.sql]);const r=e!==t.sql,a=()=>{t.setSQL(e)};return t.typedAsSQL?h(s.Tabs,{defaultValue:"Edit",orientation:"vertical",sx:{flexGrow:1},styles:{tabLabel:{width:"100%",height:"28px",lineHeight:"28px"}},keepMounted:!1,children:[h(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Edit",children:h(s.Group,{spacing:14,position:"apart",children:["Edit SQL",i(s.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!r,onClick:a,children:i(I.DeviceFloppy,{size:20})})]})}),i(s.Tabs.Tab,{value:"Preview",children:"Preview SQL"}),i(s.Tabs.Tab,{value:"pre_process",children:"Process Request"}),i(s.Tabs.Tab,{value:"post_process",children:"Process Result"}),i(zi,{}),t.datasource&&i(Dl,{dataSource:t.datasource})]}),i(s.Tabs.Panel,{value:"Edit",sx:{position:"relative"},p:"sm",children:i($i,{height:"100%",value:e,onChange:n,theme:"sql-dark",defaultLanguage:"sql"})}),i(s.Tabs.Panel,{value:"Preview",p:0,pl:4,children:i(l_,{value:t.sql})}),i(s.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:i(rr,{label:"",value:t.pre_process,onChange:t.setPreProcess,defaultValue:El.pre})}),i(s.Tabs.Panel,{value:"post_process",p:"sm",children:i(rr,{label:"",value:t.post_process,onChange:t.setPostProcess,defaultValue:El.post})})]}):null}),ir={height:"calc(100% - 44px)",padding:0},c_=k.observer(({queryModel:t})=>{const e=K(),n=y.useMemo(()=>t.datasource?t.typedAsHTTP?"HTTP":"SQL":"Configurations",[t.datasource,t.typedAsHTTP]),[r,a]=y.useState(n);y.useEffect(()=>{a(u=>u!=="Configurations"&&n==="Configurations"?"Configurations":u)},[n]);const o=e.findQueryUsage(t.id),l=o.length===0;return i(s.Stack,{sx:{flexGrow:1},my:0,p:0,children:h(s.Tabs,{value:r,onTabChange:a,defaultValue:n,orientation:"horizontal",keepMounted:!1,sx:{flexGrow:1},children:[h(s.Tabs.List,{grow:!0,children:[i(s.Tabs.Tab,{value:"Configurations",children:"Configurations"}),t.typedAsSQL&&i(s.Tabs.Tab,{value:"SQL",children:"Request"}),t.typedAsHTTP&&i(s.Tabs.Tab,{value:"HTTP",children:"Request"}),i(s.Tabs.Tab,{value:"Data",disabled:!t.datasource,children:i(s.Tooltip,{label:"Need to pick a Data Source first",disabled:t.datasource,withinPortal:!0,children:i(s.Text,{children:"Data"})})}),i(s.Tabs.Tab,{value:"Usage",disabled:l,children:i(s.Tooltip,{label:"This query is not used for any filter or panel",disabled:!l,withinPortal:!0,children:i(s.Text,{children:"Usage"})})})]}),i(s.Tabs.Panel,{value:"Configurations",pt:0,p:0,children:i(HS,{queryModel:t})}),t.typedAsSQL&&i(s.Tabs.Panel,{value:"SQL",sx:ir,children:i(s.Stack,{sx:{height:"100%"},children:i(u_,{queryModel:t})})}),t.typedAsHTTP&&i(s.Tabs.Panel,{value:"HTTP",sx:ir,children:i(s.Stack,{sx:{height:"100%"},children:i(a_,{queryModel:t})})}),i(s.Tabs.Panel,{value:"Data",sx:{...ir,overflow:"hidden"},children:i(Ei,{id:t.id})}),i(s.Tabs.Panel,{value:"Usage",sx:{...ir,overflow:"hidden"},children:i(s_,{queryID:t.id,usage:o})})]})})}),d_=k.observer(({id:t})=>{const n=K().queries.findByID(t);return t===""?null:n?i(s.Stack,{sx:{height:"100%"},spacing:"sm",children:i(c_,{queryModel:n})}):i(s.Text,{size:14,color:"red",children:"Invalid Query ID"})}),p_=k.observer(({value:t})=>{const n=K().payloadForSQL,r=y.useMemo(()=>dr(t,n),[t,n]);return i($i,{height:"100%",value:r})}),h_=k.observer(({item:t,remove:e,onKeyChanged:n})=>{const[r,a]=y.useState("SQL"),[o,l]=y.useState(t.key),u=()=>{t.setKey(o),n(o)},c=o!==t.key,d=t.isADuplicatedKey(o),[f,p]=y.useState(t.value),g=()=>{t.setValue(f)};y.useEffect(()=>{l(t.key),p(t.value)},[t]);const m=f!==t.value,C=Ke.useModals(),w=()=>{C.openConfirmModal({title:"Delete this SQL snippet?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:e,confirmProps:{color:"red"},zIndex:320})};return h(s.Stack,{p:20,sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",children:[h(s.Group,{sx:{alignItems:"end"},spacing:40,children:[i(s.TextInput,{label:d?"This key is occupied by another snippet":"Key",value:o,onChange:_=>{l(_.currentTarget.value)},sx:{flexGrow:"1 !important"},rightSection:i(s.ActionIcon,{color:"blue",variant:"subtle",onClick:u,disabled:!c||d,children:i(I.DeviceFloppy,{size:16})}),error:d}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:w,children:"Delete this SQL Snippet"})]}),h(s.Tabs,{value:r,onTabChange:a,sx:{flexGrow:1},styles:{panel:{height:"calc(100% - 50px)"}},children:[h(s.Tabs.List,{sx:{position:"relative"},children:[i(s.Tabs.Tab,{value:"SQL",children:"SQL"}),i(s.Tabs.Tab,{value:"Preview",children:"Preview"}),i(zi,{}),i(s.ActionIcon,{color:"blue",variant:"filled",onClick:g,disabled:!m,sx:{position:"absolute",top:0,right:10},children:i(I.DeviceFloppy,{size:18})})]}),i(s.Tabs.Panel,{value:"SQL",pt:"sm",children:i($i,{height:"100%",value:f,onChange:p,defaultLanguage:"sql",theme:"sql-dark"})}),i(s.Tabs.Panel,{value:"Preview",pt:"sm",children:i(p_,{value:f})})]})]})}),f_=k.observer(({id:t})=>{const e=ge(),n=K(),r=y.useMemo(()=>n.sqlSnippets.findByKey(t),[t]);if(!t)return null;if(!r)return h(s.Text,{size:14,children:["SQL Snippet by key[",t,"] is not found"]});const a=()=>{e.editor.setPath(["_SQL_SNIPPETS_",""])};return i(h_,{item:r,remove:()=>{n.sqlSnippets.removeByKey(t),a()},onKeyChanged:u=>{e.editor.setPath(["_SQL_SNIPPETS_",u])}})}),g_=k.observer(({view:t})=>!t||t.type!==H.Division?null:h(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"})]})),m_=[{value:"default",label:"Default"},{value:"outline",label:"Outline"},{value:"pills",label:"Pills"}],y_=[{value:"horizontal",label:"Horizontal"},{value:"vertical",label:"Vertical"}],b_=k.observer(({view:t})=>{if(!t||t.type!==H.Tabs)return null;const e=t.config;return h(s.Stack,{children:[i(s.Divider,{mt:8,mb:0,label:"Tabs settings",labelPosition:"center"}),i(s.Select,{label:"Variant",value:e.variant,onChange:e.setVariant,data:m_}),i(s.Select,{label:"Orientation",value:e.orientation,onChange:e.setOrientation,data:y_}),i(s.Switch,{label:"Grow Tabs",checked:e.grow,onChange:n=>e.setGrow(n.currentTarget.checked)})]})}),v_=({disabled:t,value:e,onChange:n})=>{const r=a=>{a&&n(a)};return h(s.Box,{sx:{position:"relative"},children:[t&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(ze,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},x_=({value:t,onChange:e})=>{const[n,{setTrue:r,setFalse:a}]=J.useBoolean(),[o,l]=y.useState(t??xi),u=g=>{l({...o,enabled:g})},c=()=>{a();const{enabled:g,func_content:m}=o,C={enabled:g,func_content:m};l(C),e(C)},d=()=>{a(),l(t)},f=g=>{l(m=>({...m,func_content:g}))},p=()=>{f(xi.func_content)};return h(N,{children:[i(s.ActionIcon,{size:"lg",color:"blue",variant:"filled",mt:26,onClick:r,sx:{flexGrow:0},children:i(I.Settings,{size:14})}),i(s.Modal,{size:800,title:"Customize modal title",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&h(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:o.enabled,onChange:g=>u(g.currentTarget.checked)}),i(v_,{value:o.func_content,onChange:f,disabled:!o.enabled}),h(s.Group,{position:"apart",children:[i(s.Button,{onClick:p,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Rest"}),h(s.Group,{position:"right",children:[i(s.Button,{onClick:d,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:c,children:"OK"})]})]})]})})]})},w_=k.observer(({view:t})=>{if(!t||t.type!==H.Modal)return null;const e=t.config,n=e.custom_modal_title.value;return h(s.Stack,{children:[i(s.Divider,{mt:8,label:"Modal settings",labelPosition:"center"}),h(s.Flex,{gap:10,children:[i(s.TextInput,{label:"Modal Title",value:n,onChange:x.noop,disabled:!0,sx:{flexGrow:1}}),i(x_,{value:e.custom_modal_title,onChange:e.custom_modal_title.replace})]}),h(s.Group,{grow:!0,children:[i(s.TextInput,{label:"Width",value:e.width,onChange:r=>e.setWidth(r.currentTarget.value),placeholder:"600px / 50vw"}),i(s.TextInput,{label:"Height",value:e.height,onChange:r=>e.setHeight(r.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),C_=k.observer(({view:t})=>h(N,{children:[i(g_,{view:t}),i(w_,{view:t}),i(b_,{view:t})]})),S_=[{label:"Division",value:H.Division},{label:"Modal",value:H.Modal},{label:"Tabs",value:H.Tabs}],__=k.observer(({view:t})=>t?h(s.Stack,{sx:{position:"relative"},children:[i(s.TextInput,{label:"Name",value:t.name,onChange:e=>{t.setName(e.currentTarget.value)}}),i(s.Select,{label:"Type",withinPortal:!0,value:t.type,onChange:t.setType,data:S_}),i(C_,{view:t})]}):null),k_=k.observer(({id:t})=>{const e=Ke.useModals(),n=ge(),r=K();if(t==="")return null;const a=r.views.findByID(t);if(!a)return h(s.Text,{size:14,children:["View by ID[",t,"] is not found"]});const o=()=>{n.editor.setPath(["_VIEWS_",""])},l=()=>{e.openConfirmModal({title:"Delete this view?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.views.removeByID(t),o()},zIndex:320})};return h(s.Stack,{sx:{maxWidth:"600px",height:"100%"},spacing:"sm",children:[i(s.Group,{position:"right",pt:10,children:i(s.Button,{size:"xs",color:"red",leftIcon:i(I.Trash,{size:16}),onClick:l,children:"Delete this view"})}),i(s.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:i(__,{view:a})})]})});function T_(t){return t.length===1&&t[0]==="_QUERY_VARS_"}function D_(t){return t.length===1&&t[0]==="_MOCK_CONTEXT_"}function I_(t){return t.length===2&&t[0]==="_FILTERS_"}function M_(t){return t.length===2&&t[0]==="_SQL_SNIPPETS_"}function E_(t){return t.length===2&&t[0]==="_QUERIES_"}function A_(t){return t.length===2&&t[0]==="_VIEWS_"}function z_(t){return t.length===4&&t[0]==="_VIEWS_"&&t[2]==="_PANELS_"}const $_=k.observer(()=>i(s.Stack,{sx:{height:"100%"},p:"sm",children:i(Il,{})})),L_=k.observer(()=>{const t=ge().editor,e=t.path;return T_(e)?i($_,{}):D_(e)?i(rS,{}):I_(e)?i(s.Box,{p:"xs",pl:20,children:i(nS,{id:e[1]})}):M_(e)?i(f_,{id:e[1]}):E_(e)?i(d_,{id:e[1]}):A_(e)?i(s.Box,{p:"xs",pl:20,children:i(k_,{id:e[1]})}):z_(e)?i(zS,{viewID:e[1],panelID:e[3]}):i(s.Box,{children:t.path})}),O_=k.observer(()=>i(L_,{})),P_=k.observer(()=>{const t=ge(),e=()=>{const n=new Date().getTime().toString(),r={id:n,key:n,label:n,order:t.content.filters.current.length+1,type:vi.TextInput,config:Ha(),visibleInViewsIDs:["Main"],auto_submit:!1};t.content.filters.append(r),t.editor.setPath(["_FILTERS_",n])};return i(s.Button,{variant:"subtle",leftIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:e,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Filter"})}),B_=k.observer(({parentID:t})=>{const e=K();if(!t)return null;const n=e.views.findByID(t);return n?i(s.Button,{variant:"subtle",leftIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:()=>e.addANewPanel(n.id),sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Panel"}):null}),V_=k.observer(()=>{const t=ge(),e=()=>{const n=new Date().getTime().toString(),r={id:n,name:n,type:be.Postgresql,key:"",sql:""};t.content.queries.append(r),t.editor.setPath(["_QUERIES_",n])};return i(s.Button,{variant:"subtle",leftIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:e,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Query"})}),N_=k.observer(()=>{const t=ge(),e=()=>{const n=new Date().getTime().toString(),r={key:n,value:""};t.content.sqlSnippets.append(r),t.editor.setPath(["_SQL_SNIPPETS_",n])};return i(s.Button,{variant:"subtle",leftIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:e,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a SQL Snippet"})}),q_=k.observer(()=>{const t=K();return i(s.Button,{variant:"subtle",leftIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a View"})}),F_=k.observer(({action_type:t,parentID:e})=>(K(),t==="_Add_A_Filter_"?i(P_,{}):t==="_Add_A_SQL_SNIPPET_"?i(N_,{}):t==="_Add_A_QUERY_"?i(V_,{}):t==="_Add_A_VIEW_"?i(q_,{}):t==="_Add_A_PANEL_"?i(B_,{parentID:e}):null)),Al=k.observer(({option:t})=>{var d;const e=ge().editor,n=e.isOptionActive,r=n(e.path,t),a=e.isOptionOpened,o=e.navigate,l=a(t),[u,c]=y.useState(l);return y.useEffect(()=>{c(l)},[l]),i(s.NavLink,{active:r,defaultOpened:l,opened:u,onChange:c,label:t.label,onClick:()=>o(t),icon:t.Icon?i(t.Icon,{size:18}):null,children:(d=t.children)==null?void 0:d.map(f=>f._type==="ACTION"?i(F_,{action_type:f._action_type,parentID:f.parentID},`_ADD_${f.value}_`):i(Al,{option:f},f.value))},t.label)}),G_=k.observer(()=>{const t=ge();return i(s.Box,{sx:{position:"relative"},children:t.editor.navOptions.map(e=>i(Al,{option:e},e.value))})}),W_=k.observer(()=>{const t=ge();return h(s.Navbar,{p:0,width:{base:200,xs:200,sm:220,md:240,lg:280,xl:300},sx:{height:"100vh - 60px - 60px"},children:[i(s.Navbar.Section,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:i(s.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Settings"})}),i(s.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:i(G_,{})}),i(s.Navbar.Section,{children:i(s.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:i(s.Button,{size:"xs",color:"red",leftIcon:i(L.IconX,{size:18}),onClick:()=>t.editor.close(),children:"Close"})})})]})}),R_={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"}},j_=k.observer(()=>{const t=ge().editor;return i(s.Modal,{onClose:()=>t.setSettingsOpen(!1),closeOnEscape:!1,closeOnClickOutside:!1,opened:t.settings_open,fullScreen:!0,title:null,transitionProps:{duration:0},withCloseButton:!1,withinPortal:!0,zIndex:300,styles:{body:{padding:"0 !important"}},children:i(s.AppShell,{padding:0,navbar:i(W_,{}),styles:R_,children:i(O_,{})})})}),Y_=t=>t.replace(/([^:])(\/\/+)/g,"$1/");function Q_(t){y.useEffect(()=>{if(ze.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const n=Y_(t);ze.loader.config({paths:{vs:n}}),ze.loader.init().then(r=>console.log("monaco instance:",r))},[])}Ls();const K_={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:60+30,height:"100vh"}},U_=({context:t,dashboard:e,content:n,update:r,className:a="dashboard",config:o,onChange:l,headerSlot:u,headerMenuItems:c},d)=>{Q_(o.monacoPath),Fa(o);const{data:f=[]}=J.useRequest(pr),{data:p=[]}=J.useRequest(Ga),[g,m]=y.useState(!1),C=y.useMemo(()=>Ci(e,n,f,p,t),[e,n]);y.useImperativeHandle(d,()=>C,[C]),ja(C.content,!0),y.useEffect(()=>{C.context.replace(t)},[t]),y.useEffect(()=>{C.datasources.replace(f)},[f]),y.useEffect(()=>{C.globalSQLSnippets.replace(p)},[p]),y.useEffect(()=>ae.reaction(()=>ae.toJS(C.json),M=>{l==null||l(M)}),[C]);const w=async()=>{await r(C.json,C.content.json)},_=J.useCreation(fi,[]),T=ki(_);return i(Ke.ModalsProvider,{children:i(fr,{value:C,children:i(hr,{value:C.content,children:i(ft.Provider,{value:{layoutFrozen:g,freezeLayout:m,inEditMode:!0},children:i(it.Provider,{value:_,children:h(Jn,{configure:T,children:[i(s.AppShell,{padding:0,header:i(f1,{saveDashboardChanges:w,headerSlot:u,headerMenuItems:c}),navbar:i(F1,{}),styles:K_,children:i(s.Box,{className:`${a} dashboard-root`,sx:{position:"relative"},children:C.content.views.visibleViews.map(M=>i(gl,{view:M},M.id))})}),i(j_,{})]})})})})})})},X_=k.observer(y.forwardRef(U_)),nD="";Ls();const J_=k.observer(({context:t,dashboard:e,content:n,className:r="dashboard",config:a,fullScreenPanelID:o,setFullScreenPanelID:l})=>{Fa(a);const{data:u=[]}=J.useRequest(pr),{data:c=[]}=J.useRequest(Ga),d=y.useMemo(()=>Ci(e,n,u,c,t),[e,n]);ja(d.content,!1),y.useEffect(()=>{d.context.replace(t)},[t]),y.useEffect(()=>{d.datasources.replace(u)},[u]),y.useEffect(()=>{d.globalSQLSnippets.replace(c)},[c]);const f=J.useCreation(fi,[]),p=ki(f);return i(Ke.ModalsProvider,{children:i(fr,{value:d,children:i(hr,{value:d.content,children:i(Cr.Provider,{value:{fullScreenPanelID:o,setFullScreenPanelID:l},children:i(ft.Provider,{value:{layoutFrozen:!0,freezeLayout:x.noop,inEditMode:!1},children:i(s.Box,{className:`${r} dashboard-root`,children:i(it.Provider,{value:f,children:i(Jn,{configure:p,children:d.content.views.visibleViews.map(g=>i(er,{view:g},g.id))})})})})})})})})});var Li={},Z_={get exports(){return Li},set exports(t){Li=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){var a=r.prototype,o=a.format;a.format=function(l){var u=this,c=this.$locale();if(!this.isValid())return o.bind(this)(l);var d=this.$utils(),f=(l||"YYYY-MM-DDTHH:mm:ssZ").replace(/\[([^\]]+)]|Q|wo|ww|w|WW|W|zzz|z|gggg|GGGG|Do|X|x|k{1,2}|S/g,function(p){switch(p){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(),p==="w"?1:2,"0");case"W":case"WW":return d.s(u.isoWeek(),p==="W"?1:2,"0");case"k":case"kk":return d.s(String(u.$H===0?24:u.$H),p==="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 p}});return o.bind(this)(f)}}})})(Z_);const H_=Li;var Oi={},ek={get exports(){return Oi},set exports(t){Oi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){var o=r.prototype,l=function(c){var d=c.date,f=c.utc;return Array.isArray(d)?f?d.length?new Date(Date.UTC.apply(null,d)):new Date:d.length===1?a(String(d[0])).toDate():new(Function.prototype.bind.apply(Date,[null].concat(d))):d},u=o.parse;o.parse=function(c){c.date=l.bind(this)(c),u.bind(this)(c)}}})})(ek);const tk=Oi;var Pi={},nk={get exports(){return Pi},set exports(t){Pi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){var a=r.prototype;a.$g=function(g,m,C){return this.$utils().u(g)?this[m]:this.$set(C,g)},a.set=function(g,m){return this.$set(g,m)};var o=a.startOf;a.startOf=function(g,m){return this.$d=o.bind(this)(g,m).toDate(),this.init(),this};var l=a.add;a.add=function(g,m){return this.$d=l.bind(this)(g,m).toDate(),this.init(),this};var u=a.locale;a.locale=function(g,m){return g?(this.$L=u.bind(this)(g,m).$L,this):this.$L};var c=a.daysInMonth;a.daysInMonth=function(){return c.bind(this.clone())()};var d=a.isSame;a.isSame=function(g,m){return d.bind(this.clone())(g,m)};var f=a.isBefore;a.isBefore=function(g,m){return f.bind(this.clone())(g,m)};var p=a.isAfter;a.isAfter=function(g,m){return p.bind(this.clone())(g,m)}}})})(nk);const rk=Pi;var Bi={},ik={get exports(){return Bi},set exports(t){Bi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){var a=r.prototype,o=a.format;a.format=function(l){var u=this,c=(l||"YYYY-MM-DDTHH:mm:ssZ").replace(/(\[[^\]]+])|BBBB|BB/g,function(d,f){var p,g=String(u.$y+543),m=d==="BB"?[g.slice(-2),2]:[g,4];return f||(p=u.$utils()).s.apply(p,m.concat(["0"]))});return o.bind(this)(c)}}})})(ik);const ak=Bi;var Vi={},sk={get exports(){return Vi},set exports(t){Vi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){var o="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"),p=this.diff(f,"d",!0),g="sameElse",m=p<-6?g:p<-1?"lastWeek":p<0?"lastDay":p<1?"sameDay":p<2?"nextDay":p<7?"nextWeek":g,C=d[m]||l[m];return typeof C=="function"?C.call(this,a()):this.format(C)}}})})(sk);const ok=Vi;var Ni={},lk={get exports(){return Ni},set exports(t){Ni=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"},r=/(\[[^[]*\])|([-_:/.,()\s]+)|(A|a|YYYY|YY?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g,a=/\d\d/,o=/\d\d?/,l=/\d*[^-_:/,()\s\d]+/,u={},c=function(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)}],p=function(w){var _=u[w];return _&&(_.indexOf?_:_.s.concat(_.f))},g=function(w,_){var T,M=u.meridiem;if(M){for(var O=1;O<=24;O+=1)if(w.indexOf(M(O,0,_))>-1){T=O>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 _=p("months"),T=(p("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 _=p("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(W,U,X){var oe=X&&X.toUpperCase();return U||T[X]||n[X]||T[oe].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(re,de,Ce){return de||Ce.slice(1)})})).match(r),O=M.length,B=0;B<O;B+=1){var F=M[B],$=m[F],E=$&&$[0],z=$&&$[1];M[B]=z?{regex:E,parser:z}:F.replace(/^\[|\]$/g,"")}return function(W){for(var U={},X=0,oe=0;X<O;X+=1){var re=M[X];if(typeof re=="string")oe+=re.length;else{var de=re.regex,Ce=re.parser,ye=W.slice(oe),Te=de.exec(ye)[0];Ce.call(U,Te),W=W.replace(Te,"")}}return function(fe){var Oe=fe.afternoon;if(Oe!==void 0){var Ye=fe.hours;Oe?Ye<12&&(fe.hours+=12):Ye===12&&(fe.hours=0),delete fe.afternoon}}(U),U}}return function(w,_,T){T.p.customParseFormat=!0,w&&w.parseTwoDigitYear&&(c=w.parseTwoDigitYear);var M=_.prototype,O=M.parse;M.parse=function(B){var F=B.date,$=B.utc,E=B.args;this.$u=$;var z=E[1];if(typeof z=="string"){var W=E[2]===!0,U=E[3]===!0,X=W||U,oe=E[2];U&&(oe=E[2]),u=this.$locale(),!W&&oe&&(u=T.Ls[oe]),this.$d=function(ye,Te,fe){try{if(["x","X"].indexOf(Te)>-1)return new Date((Te==="X"?1e3:1)*ye);var Oe=C(Te)(ye),Ye=Oe.year,Mt=Oe.month,ar=Oe.day,sr=Oe.hours,fa=Oe.minutes,ga=Oe.seconds,ln=Oe.milliseconds,Ft=Oe.zone,xt=new Date,Et=ar||(Ye||Mt?1:xt.getDate()),wt=Ye||xt.getFullYear(),Gt=0;Ye&&!Mt||(Gt=Mt>0?Mt-1:xt.getMonth());var Wt=sr||0,un=fa||0,cn=ga||0,Ct=ln||0;return Ft?new Date(Date.UTC(wt,Gt,Et,Wt,un,cn,Ct+60*Ft.offset*1e3)):fe?new Date(Date.UTC(wt,Gt,Et,Wt,un,cn,Ct)):new Date(wt,Gt,Et,Wt,un,cn,Ct)}catch{return new Date("")}}(F,z,$),this.init(),oe&&oe!==!0&&(this.$L=this.locale(oe).$L),X&&F!=this.format(z)&&(this.$d=new Date("")),u={}}else if(z instanceof Array)for(var re=z.length,de=1;de<=re;de+=1){E[1]=z[de-1];var Ce=T.apply(this,E);if(Ce.isValid()){this.$d=Ce.$d,this.$L=Ce.$L,this.init();break}de===re&&(this.$d=new Date(""))}else O.call(this,B)}}})})(lk);const uk=Ni;var qi={},ck={get exports(){return qi},set exports(t){qi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){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")}}})})(ck);const dk=qi;var Fi={},pk={get exports(){return Fi},set exports(t){Fi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n,r,a=1e3,o=6e4,l=36e5,u=864e5,c=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,d=31536e6,f=2592e6,p=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/,g={years:d,months:f,days:u,hours:l,minutes:o,seconds:a,milliseconds:1,weeks:6048e5},m=function($){return $ instanceof B},C=function($,E,z){return new B($,z,E.$l)},w=function($){return r.p($)+"s"},_=function($){return $<0},T=function($){return _($)?Math.ceil($):Math.floor($)},M=function($){return Math.abs($)},O=function($,E){return $?_($)?{negative:!0,format:""+M($)+E}:{negative:!1,format:""+$+E}:{negative:!1,format:""}},B=function(){function $(z,W,U){var X=this;if(this.$d={},this.$l=U,z===void 0&&(this.$ms=0,this.parseFromMilliseconds()),W)return C(z*g[w(W)],this);if(typeof z=="number")return this.$ms=z,this.parseFromMilliseconds(),this;if(typeof z=="object")return Object.keys(z).forEach(function(de){X.$d[w(de)]=z[de]}),this.calMilliseconds(),this;if(typeof z=="string"){var oe=z.match(p);if(oe){var re=oe.slice(2).map(function(de){return de!=null?Number(de):0});return this.$d.years=re[0],this.$d.months=re[1],this.$d.weeks=re[2],this.$d.days=re[3],this.$d.hours=re[4],this.$d.minutes=re[5],this.$d.seconds=re[6],this.calMilliseconds(),this}}return this}var E=$.prototype;return E.calMilliseconds=function(){var z=this;this.$ms=Object.keys(this.$d).reduce(function(W,U){return W+(z.$d[U]||0)*g[U]},0)},E.parseFromMilliseconds=function(){var z=this.$ms;this.$d.years=T(z/d),z%=d,this.$d.months=T(z/f),z%=f,this.$d.days=T(z/u),z%=u,this.$d.hours=T(z/l),z%=l,this.$d.minutes=T(z/o),z%=o,this.$d.seconds=T(z/a),z%=a,this.$d.milliseconds=z},E.toISOString=function(){var z=O(this.$d.years,"Y"),W=O(this.$d.months,"M"),U=+this.$d.days||0;this.$d.weeks&&(U+=7*this.$d.weeks);var X=O(U,"D"),oe=O(this.$d.hours,"H"),re=O(this.$d.minutes,"M"),de=this.$d.seconds||0;this.$d.milliseconds&&(de+=this.$d.milliseconds/1e3);var Ce=O(de,"S"),ye=z.negative||W.negative||X.negative||oe.negative||re.negative||Ce.negative,Te=oe.format||re.format||Ce.format?"T":"",fe=(ye?"-":"")+"P"+z.format+W.format+X.format+Te+oe.format+re.format+Ce.format;return fe==="P"||fe==="-P"?"P0D":fe},E.toJSON=function(){return this.toISOString()},E.format=function(z){var W=z||"YYYY-MM-DDTHH:mm:ss",U={Y:this.$d.years,YY:r.s(this.$d.years,2,"0"),YYYY:r.s(this.$d.years,4,"0"),M:this.$d.months,MM:r.s(this.$d.months,2,"0"),D:this.$d.days,DD:r.s(this.$d.days,2,"0"),H:this.$d.hours,HH:r.s(this.$d.hours,2,"0"),m:this.$d.minutes,mm:r.s(this.$d.minutes,2,"0"),s:this.$d.seconds,ss:r.s(this.$d.seconds,2,"0"),SSS:r.s(this.$d.milliseconds,3,"0")};return W.replace(c,function(X,oe){return oe||String(U[X])})},E.as=function(z){return this.$ms/g[w(z)]},E.get=function(z){var W=this.$ms,U=w(z);return U==="milliseconds"?W%=1e3:W=U==="weeks"?T(W/g[U]):this.$d[U],W===0?0:W},E.add=function(z,W,U){var X;return X=W?z*g[w(W)]:m(z)?z.$ms:C(z,this).$ms,C(this.$ms+X*(U?-1:1),this)},E.subtract=function(z,W){return this.add(z,W,!0)},E.locale=function(z){var W=this.clone();return W.$l=z,W},E.clone=function(){return C(this.$ms,this)},E.humanize=function(z){return n().add(this.$ms,"ms").locale(this.$l).fromNow(!z)},E.valueOf=function(){return this.asMilliseconds()},E.milliseconds=function(){return this.get("milliseconds")},E.asMilliseconds=function(){return this.as("milliseconds")},E.seconds=function(){return this.get("seconds")},E.asSeconds=function(){return this.as("seconds")},E.minutes=function(){return this.get("minutes")},E.asMinutes=function(){return this.as("minutes")},E.hours=function(){return this.get("hours")},E.asHours=function(){return this.as("hours")},E.days=function(){return this.get("days")},E.asDays=function(){return this.as("days")},E.weeks=function(){return this.get("weeks")},E.asWeeks=function(){return this.as("weeks")},E.months=function(){return this.get("months")},E.asMonths=function(){return this.as("months")},E.years=function(){return this.get("years")},E.asYears=function(){return this.as("years")},$}(),F=function($,E,z){return $.add(E.years()*z,"y").add(E.months()*z,"M").add(E.days()*z,"d").add(E.hours()*z,"h").add(E.minutes()*z,"m").add(E.seconds()*z,"s").add(E.milliseconds()*z,"ms")};return function($,E,z){n=z,r=z().$utils(),z.duration=function(X,oe){var re=z.locale();return C(X,{$l:re},oe)},z.isDuration=m;var W=E.prototype.add,U=E.prototype.subtract;E.prototype.add=function(X,oe){return m(X)?F(this,X,1):W.bind(this)(X,oe)},E.prototype.subtract=function(X,oe){return m(X)?F(this,X,-1):U.bind(this)(X,oe)}}})})(pk);const hk=Fi;var Gi={},fk={get exports(){return Gi},set exports(t){Gi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){r.prototype.isBetween=function(o,l,u,c){var d=a(o),f=a(l),p=(c=c||"()")[0]==="(",g=c[1]===")";return(p?this.isAfter(d,u):!this.isBefore(d,u))&&(g?this.isBefore(f,u):!this.isAfter(f,u))||(p?this.isBefore(d,u):!this.isAfter(d,u))&&(g?this.isAfter(f,u):!this.isBefore(f,u))}}})})(fk);const gk=Gi;var Wi={},mk={get exports(){return Wi},set exports(t){Wi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.isLeapYear=function(){return this.$y%4==0&&this.$y%100!=0||this.$y%400==0}}})})(mk);const yk=Wi;var Ri={},bk={get exports(){return Ri},set exports(t){Ri=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){a.isMoment=function(o){return a.isDayjs(o)}}})})(bk);const vk=Ri;var ji={},xk={get exports(){return ji},set exports(t){ji=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n="day";return function(r,a,o){var l=function(d){return d.add(4-d.isoWeekday(),n)},u=a.prototype;u.isoWeekYear=function(){return l(this).year()},u.isoWeek=function(d){if(!this.$utils().u(d))return this.add(7*(d-this.isoWeek()),n);var f,p,g,m,C=l(this),w=(f=this.isoWeekYear(),p=this.$u,g=(p?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 p=this.$utils(),g=!!p.u(f)||f;return p.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)}}})})(xk);const wk=ji;var Yi={},Ck={get exports(){return Yi},set exports(t){Yi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.isoWeeksInYear=function(){var a=this.isLeapYear(),o=this.endOf("y").day();return o===4||a&&o===5?53:52}}})})(Ck);const Sk=Yi;var Qi={},_k={get exports(){return Qi},set exports(t){Qi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.isSameOrAfter=function(a,o){return this.isSame(a,o)||this.isAfter(a,o)}}})})(_k);const kk=Qi;var Ki={},Tk={get exports(){return Ki},set exports(t){Ki=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.isSameOrBefore=function(a,o){return this.isSame(a,o)||this.isBefore(a,o)}}})})(Tk);const Dk=Ki;var Ui={},Ik={get exports(){return Ui},set exports(t){Ui=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){r.prototype.isToday=function(){var o="YYYY-MM-DD",l=a();return this.format(o)===l.format(o)}}})})(Ik);const Mk=Ui;var Xi={},Ek={get exports(){return Xi},set exports(t){Xi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){r.prototype.isTomorrow=function(){var o="YYYY-MM-DD",l=a().add(1,"day");return this.format(o)===l.format(o)}}})})(Ek);const Ak=Xi;var Ji={},zk={get exports(){return Ji},set exports(t){Ji=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){r.prototype.isYesterday=function(){var o="YYYY-MM-DD",l=a().subtract(1,"day");return this.format(o)===l.format(o)}}})})(zk);const $k=Ji;var Zi={},Lk={get exports(){return Zi},set exports(t){Zi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){var o=r.prototype,l=function(p){return p&&(p.indexOf?p:p.s)},u=function(p,g,m,C,w){var _=p.name?p:p.$locale(),T=l(_[g]),M=l(_[m]),O=T||M.map(function(F){return F.slice(0,C)});if(!w)return O;var B=_.weekStart;return O.map(function(F,$){return O[($+(B||0))%7]})},c=function(){return a.Ls[a.locale()]},d=function(p,g){return p.formats[g]||function(m){return m.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(C,w,_){return w||_.slice(1)})}(p.formats[g.toUpperCase()])},f=function(){var p=this;return{months:function(g){return g?g.format("MMMM"):u(p,"months")},monthsShort:function(g){return g?g.format("MMM"):u(p,"monthsShort","months",3)},firstDayOfWeek:function(){return p.$locale().weekStart||0},weekdays:function(g){return g?g.format("dddd"):u(p,"weekdays")},weekdaysMin:function(g){return g?g.format("dd"):u(p,"weekdaysMin","weekdays",2)},weekdaysShort:function(g){return g?g.format("ddd"):u(p,"weekdaysShort","weekdays",3)},longDateFormat:function(g){return d(p.$locale(),g)},meridiem:this.$locale().meridiem,ordinal:this.$locale().ordinal}};o.localeData=function(){return f.bind(this)()},a.localeData=function(){var p=c();return{firstDayOfWeek:function(){return p.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(p,g)},meridiem:p.meridiem,ordinal:p.ordinal}},a.months=function(){return u(c(),"months")},a.monthsShort=function(){return u(c(),"monthsShort","months",3)},a.weekdays=function(p){return u(c(),"weekdays",null,null,p)},a.weekdaysShort=function(p){return u(c(),"weekdaysShort","weekdays",3,p)},a.weekdaysMin=function(p){return u(c(),"weekdaysMin","weekdays",2,p)}}})})(Lk);const Ok=Zi;var Hi={},Pk={get exports(){return Hi},set exports(t){Hi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"};return function(r,a,o){var l=a.prototype,u=l.format;o.en.formats=n,l.format=function(c){c===void 0&&(c="YYYY-MM-DDTHH:mm:ssZ");var d=this.$locale().formats,f=function(p,g){return p.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,O){return M||O.slice(1)})})}(c,d===void 0?{}:d);return u.call(this,f)}}})})(Pk);const Bk=Hi;var ea={},Vk={get exports(){return ea},set exports(t){ea=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){var o=function(l,u){if(!u||!u.length||u.length===1&&!u[0]||u.length===1&&Array.isArray(u[0])&&!u[0].length)return null;var c;u.length===1&&u[0].length>0&&(u=u[0]),c=(u=u.filter(function(f){return f}))[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)}}})})(Vk);const Nk=ea;var ta={},qk={get exports(){return ta},set exports(t){ta=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){var o=r.prototype,l=function(g){var m,C=g.date,w=g.utc,_={};if(!((m=C)===null||m 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(W){var U,X;_[U=W,X=o.$utils().p(U),X==="date"?"day":X]=C[W]});var M=_.day||(_.year||_.month>=0?1:T.date()),O=_.year||T.year(),B=_.month>=0?_.month:_.year||_.day?0:T.month(),F=_.hour||0,$=_.minute||0,E=_.second||0,z=_.millisecond||0;return w?new Date(Date.UTC(O,B,M,F,$,E,z)):new Date(O,B,M,F,$,E,z)}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,p=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"?p.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"?p.bind(this)(d,g,m):d.bind(this)(g,m)},o.subtract=function(g,m){return g.constructor.name==="Object"?p.bind(this)(d,g,m,-1):f.bind(this)(g,m)}}})})(qk);const Fk=ta;var na={},Gk={get exports(){return na},set exports(t){na=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){var a=r.prototype;["milliseconds","seconds","minutes","hours","days","weeks","isoWeeks","months","quarters","years","dates"].forEach(function(o){a[o]=a[o.replace(/s$/,"")]})}})})(Gk);const Wk=na;var ra={},Rk={get exports(){return ra},set exports(t){ra=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){var a=r.prototype.parse;r.prototype.parse=function(u){if(typeof u.date=="string"){var c=this.$locale();u.date=c&&c.preparse?c.preparse(u.date):u.date}return a.bind(this)(u)};var o=r.prototype.format;r.prototype.format=function(){for(var u=arguments.length,c=new Array(u),d=0;d<u;d++)c[d]=arguments[d];var f=o.call.apply(o,[this].concat(c)),p=this.$locale();return p&&p.postformat?p.postformat(f):f};var l=r.prototype.fromToBase;l&&(r.prototype.fromToBase=function(u,c,d,f){var p=this.$locale()||d.$locale();return l.call(this,u,c,d,f,p&&p.postformat)})}})})(Rk);const jk=ra;var ia={},Yk={get exports(){return ia},set exports(t){ia=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n="month",r="quarter";return function(a,o){var l=o.prototype;l.quarter=function(d){return this.$utils().u(d)?Math.ceil((this.month()+1)/3):this.month(this.month()%3+3*(d-1))};var u=l.add;l.add=function(d,f){return d=Number(d),this.$utils().p(f)===r?this.add(3*d,n):u.bind(this)(d,f)};var c=l.startOf;l.startOf=function(d,f){var p=this.$utils(),g=!!p.u(f)||f;if(p.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)}}})})(Yk);const Qk=ia;var aa={},Kk={get exports(){return aa},set exports(t){aa=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){n=n||{};var o=r.prototype,l={future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"};function u(d,f,p,g){return o.fromToBase(d,f,p,g)}a.en.relativeTime=l,o.fromToBase=function(d,f,p,g,m){for(var C,w,_,T=p.$locale().relativeTime||l,M=n.thresholds||[{l:"s",r:44,d:"second"},{l:"m",r:89},{l:"mm",r:44,d:"minute"},{l:"h",r:89},{l:"hh",r:21,d:"hour"},{l:"d",r:35},{l:"dd",r:25,d:"day"},{l:"M",r:45},{l:"MM",r:10,d:"month"},{l:"y",r:17},{l:"yy",d:"year"}],O=M.length,B=0;B<O;B+=1){var F=M[B];F.d&&(C=g?a(d).diff(p,F.d,!0):p.diff(d,F.d,!0));var $=(n.rounding||Math.round)(Math.abs(C));if(_=C>0,$<=F.r||!F.r){$<=1&&B>0&&(F=M[B-1]);var E=T[F.l];m&&($=m(""+$)),w=typeof E=="string"?E.replace("%d",$):E($,f,F.l,_);break}}if(f)return w;var z=_?T.future:T.past;return typeof z=="function"?z(w):z.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)}}})})(Kk);const Uk=aa;var sa={},Xk={get exports(){return sa},set exports(t){sa=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n={year:0,month:1,day:2,hour:3,minute:4,second:5},r={};return function(a,o,l){var u,c=function(g,m,C){C===void 0&&(C={});var w=new Date(g),_=function(T,M){M===void 0&&(M={});var O=M.timeZoneName||"short",B=T+"|"+O,F=r[B];return F||(F=new Intl.DateTimeFormat("en-US",{hour12:!1,timeZone:T,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:O}),r[B]=F),F}(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,O=T.value,B=n[M];B>=0&&(w[B]=parseInt(O,10))}var F=w[3],$=F===24?0:F,E=w[0]+"-"+w[1]+"-"+w[2]+" "+$+":"+w[4]+":"+w[5]+":000",z=+g;return(l.utc(E).valueOf()-(z-=z%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 O=M.utcOffset();M=M.add(C-O,"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 p=f.startOf;f.startOf=function(g,m){if(!this.$x||!this.$x.$timezone)return p.call(this,g,m);var C=l(this.format("YYYY-MM-DD HH:mm:ss:SSS"));return p.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($,E,z){var W=$-60*E*1e3,U=d(W,z);if(E===U)return[W,E];var X=d(W-=60*(U-E)*1e3,z);return U===X?[W,U]:[$-60*Math.min(U,X)*1e3,Math.max(U,X)]}(l.utc(g,w).valueOf(),T,_),O=M[0],B=M[1],F=l(O).utcOffset(B);return F.$x.$timezone=_,F},l.tz.guess=function(){return Intl.DateTimeFormat().resolvedOptions().timeZone},l.tz.setDefault=function(g){u=g}}})})(Xk);const Jk=sa;var oa={},Zk={get exports(){return oa},set exports(t){oa=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.toArray=function(){return[this.$y,this.$M,this.$D,this.$H,this.$m,this.$s,this.$ms]}}})})(Zk);const Hk=oa;var la={},eT={get exports(){return la},set exports(t){la=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.toObject=function(){return{years:this.$y,months:this.$M,date:this.$D,hours:this.$H,minutes:this.$m,seconds:this.$s,milliseconds:this.$ms}}}})})(eT);const tT=la;var ua={},nT={get exports(){return ua},set exports(t){ua=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){a.updateLocale=function(o,l){var u=a.Ls[o];if(u)return(l?Object.keys(l):[]).forEach(function(c){u[c]=l[c]}),u}}})})(nT);const rT=ua;var ca={},iT={get exports(){return ca},set exports(t){ca=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n="minute",r=/[+-]\d\d(?::?\d\d)?/g,a=/([+-]|\d\d)/g;return function(o,l,u){var c=l.prototype;u.utc=function(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 p=c.utcOffset;c.utcOffset=function(w,_){var T=this.$utils().u;if(T(w))return this.$u?0:T(this.$offset)?p.call(this):this.$offset;if(typeof w=="string"&&(w=function(F){F===void 0&&(F="");var $=F.match(r);if(!$)return null;var E=(""+$[0]).match(a)||["-",0,0],z=E[0],W=60*+E[1]+ +E[2];return W===0?0:z==="+"?W:-W}(w),w===null))return this;var M=Math.abs(w)<=16?60*w:w,O=this;if(_)return O.$offset=M,O.$u=w===0,O;if(w!==0){var B=this.$u?this.toDate().getTimezoneOffset():-1*this.utcOffset();(O=this.local().add(M+B,n)).$offset=M,O.$x.$localOffset=B}else O=this.utc();return O};var g=c.format;c.format=function(w){var _=w||(this.$u?"YYYY-MM-DDTHH:mm:ss[Z]":"");return g.call(this,_)},c.valueOf=function(){var w=this.$utils().u(this.$offset)?0:this.$offset+(this.$x.$localOffset||this.$d.getTimezoneOffset());return this.$d.valueOf()-6e4*w},c.isUTC=function(){return!!this.$u},c.toISOString=function(){return this.toDate().toISOString()},c.toString=function(){return this.toDate().toUTCString()};var 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(),O=u(w).local();return C.call(M,O,_,T)}}})})(iT);const aT=ca;var da={},sT={get exports(){return da},set exports(t){da=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.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")}}})})(sT);const oT=da;var pa={},lT={get exports(){return pa},set exports(t){pa=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n="week",r="year";return function(a,o,l){var u=o.prototype;u.week=function(c){if(c===void 0&&(c=null),c!==null)return this.add(7*(c-this.week()),"day");var d=this.$locale().yearStart||1;if(this.month()===11&&this.date()>25){var f=l(this).startOf(r).add(1,r).date(d),p=l(this).endOf(n);if(f.isBefore(p))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)}}})})(lT);const uT=pa;var ha={},cT={get exports(){return ha},set exports(t){ha=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.weekYear=function(){var a=this.month(),o=this.week(),l=this.year();return o===1&&a===11?l+1:a===0&&o>=52?l-1:l}}})})(cT);const dT=ha;Y.extend(H_),Y.extend(tk),Y.extend(rk),Y.extend(ak),Y.extend(ok),Y.extend(uk),Y.extend(dk),Y.extend(hk),Y.extend(gk),Y.extend(yk),Y.extend(vk),Y.extend(kk),Y.extend(Dk),Y.extend(Mk),Y.extend(Ak),Y.extend($k),Y.extend(wk),Y.extend(Sk),Y.extend(Ok),Y.extend(Bk),Y.extend(Nk),Y.extend(Fk),Y.extend(Wk),Y.extend(jk),Y.extend(Qk),Y.extend(Uk),Y.extend(Jk),Y.extend(Hk),Y.extend(tT),Y.extend(rT),Y.extend(aT),Y.extend(uT),Y.extend(dT),Y.extend(oT),Y.tz.setDefault("UTC");const pT=()=>Promise.resolve().then(()=>rc).then(({version:t})=>(console.log(`[@devtable/dashboard] version: ${t}`),t));D.ContentModel=Xn,D.ContentModelContextProvider=hr,D.ContextModel=ds,D.DashboardEditor=X_,D.DashboardFilterType=vi,D.DashboardMode=Qo,D.DashboardModel=nl,D.DashboardViewEditor=gl,D.DashboardViewRender=er,D.EViewComponentType=H,D.FilterModel=mr,D.FiltersModel=ts,D.FullScreenPanelContext=Cr,D.LayoutStateContext=ft,D.ModelContextProvider=fr,D.Panel=Hn,D.PanelContextProvider=wr,D.PanelModel=Ro,D.PanelsModel=Yo,D.QueriesModel=ls,D.QueryModel=os,D.ReadOnlyDashboard=J_,D.SQLSnippetModel=us,D.SQLSnippetsModel=cs,D.ViewComponentTypeBackground=Ko,D.ViewComponentTypeColor=nC,D.ViewComponentTypeName=tC,D.ViewModel=Zo,D.ViewsModel=Ho,D.applyPartialDashboard=cC,D.createContentModel=tl,D.createDashboardModel=Ci,D.createDashboardViewsModel=wi,D.getInitialFiltersPayload=ns,D.getNewPanel=jo,D.getVersion=pT,D.initialDashboardContent=rC,D.useContentModelContext=K,D.useFullScreenPanelContext=bs,D.useModelContext=ge,D.usePanelContext=Ae,D.useTopLevelServices=ki,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
|