@devtable/dashboard 10.44.0 → 10.44.2
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 +14003 -15258
- package/dist/dashboard.umd.js +124 -124
- package/dist/stats.html +1 -1
- package/package.json +2 -2
package/dist/dashboard.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(T,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("react"),require("@mantine/core"),require("@mantine/modals"),require("ahooks"),require("mobx"),require("mobx-react-lite"),require("crypto-js"),require("dayjs"),require("lodash"),require("numbro"),require("d3-array"),require("mathjs"),require("@faker-js/faker"),require("axios"),require("eventemitter2"),require("chroma-js"),require("echarts-for-react/lib/core"),require("echarts-gl"),require("echarts/components"),require("echarts/core"),require("echarts/renderers"),require("react-hook-form"),require("tabler-icons-react"),require("echarts/charts"),require("@tabler/icons-react"),require("@mantine/hooks"),require("@mantine/notifications"),require("@mantine/tiptap"),require("@tiptap/extension-color"),require("@tiptap/extension-highlight"),require("@tiptap/extension-placeholder"),require("@tiptap/extension-subscript"),require("@tiptap/extension-superscript"),require("@tiptap/extension-text-align"),require("@tiptap/extension-text-style"),require("@tiptap/extension-table"),require("@tiptap/extension-table-cell"),require("@tiptap/extension-table-header"),require("@tiptap/extension-table-row"),require("@tiptap/extension-underline"),require("@tiptap/react"),require("@tiptap/starter-kit"),require("prosemirror-keymap"),require("prosemirror-commands"),require("prosemirror-schema-list"),require("@monaco-editor/react"),require("popmotion"),require("d3-regression"),require("@mantine/prism"),require("@tanstack/react-table"),require("react-virtual"),require("@mantine/dates"),require("rc-select"),require("rc-tree-select"),require("react-grid-layout"),require("mobx-state-tree"),require("performant-array-to-tree"),require("@json2csv/whatwg"),require("file-saver"),require("jszip"),require("dom-to-image-more"),require("react-router-dom"),require("reactflow")):typeof define=="function"&&define.amd?define(["exports","react","@mantine/core","@mantine/modals","ahooks","mobx","mobx-react-lite","crypto-js","dayjs","lodash","numbro","d3-array","mathjs","@faker-js/faker","axios","eventemitter2","chroma-js","echarts-for-react/lib/core","echarts-gl","echarts/components","echarts/core","echarts/renderers","react-hook-form","tabler-icons-react","echarts/charts","@tabler/icons-react","@mantine/hooks","@mantine/notifications","@mantine/tiptap","@tiptap/extension-color","@tiptap/extension-highlight","@tiptap/extension-placeholder","@tiptap/extension-subscript","@tiptap/extension-superscript","@tiptap/extension-text-align","@tiptap/extension-text-style","@tiptap/extension-table","@tiptap/extension-table-cell","@tiptap/extension-table-header","@tiptap/extension-table-row","@tiptap/extension-underline","@tiptap/react","@tiptap/starter-kit","prosemirror-keymap","prosemirror-commands","prosemirror-schema-list","@monaco-editor/react","popmotion","d3-regression","@mantine/prism","@tanstack/react-table","react-virtual","@mantine/dates","rc-select","rc-tree-select","react-grid-layout","mobx-state-tree","performant-array-to-tree","@json2csv/whatwg","file-saver","jszip","dom-to-image-more","react-router-dom","reactflow"],m):(T=typeof globalThis<"u"?globalThis:T||self,m(T.dashboard={},T.react,T["@mantine/core"],T["@mantine/modals"],T.ahooks,T.mobx,T["mobx-react-lite"],T.CryptoJS,T.dayjs,T._,T.numbro,T["d3-array"],T.mathjs,T["@faker-js/faker"],T.axios,T.eventemitter2,T["chroma-js"],T["echarts-for-react/lib/core"],T["echarts-gl"],T["echarts/components"],T["echarts/core"],T["echarts/renderers"],T["react-hook-form"],T["tabler-icons-react"],T["echarts/charts"],T["@tabler/icons-react"],T["@mantine/hooks"],T["@mantine/notifications"],T["@mantine/tiptap"],T["@tiptap/extension-color"],T["@tiptap/extension-highlight"],T["@tiptap/extension-placeholder"],T["@tiptap/extension-subscript"],T["@tiptap/extension-superscript"],T["@tiptap/extension-text-align"],T["@tiptap/extension-text-style"],T["@tiptap/extension-table"],T["@tiptap/extension-table-cell"],T["@tiptap/extension-table-header"],T["@tiptap/extension-table-row"],T["@tiptap/extension-underline"],T["@tiptap/react"],T["@tiptap/starter-kit"],T["prosemirror-keymap"],T["prosemirror-commands"],T["prosemirror-schema-list"],T["@monaco-editor/react"],T.popmotion,T["d3-regression"],T["@mantine/prism"],T["@tanstack/react-table"],T["react-virtual"],T["@mantine/dates"],T["rc-select"],T["rc-tree-select"],T["react-grid-layout"],T["mobx-state-tree"],T["performant-array-to-tree"],T["@json2csv/whatwg"],T["file-saver"],T.jszip,T["dom-to-image-more"],T["react-router-dom"],T.reactflow))})(this,function(T,m,s,Fe,Q,te,k,Ba,U,x,Z,tn,qu,Fu,pt,Va,ht,Ae,CM,F,Gu,ze,v,I,he,E,_e,Tn,J,Na,qa,Fa,Ga,Wa,ja,Ra,Ya,Qa,Ua,Ka,Xa,Ja,Za,SM,ke,br,Te,It,Wu,Mt,et,ju,Ru,Ha,es,Dn,b,Yu,Qu,vr,Uu,ts,Ku,Ie){"use strict";var xM=Object.defineProperty;var wM=(T,m,s)=>m in T?xM(T,m,{enumerable:!0,configurable:!0,writable:!0,value:s}):T[m]=s;var q=(T,m,s)=>(wM(T,typeof m!="symbol"?m+"":m,s),s);function nn(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const Xu=nn(Ba),Ju=nn(tn),In=nn(qu),ie=nn(Gu),wt=nn(Wu);var re=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},rn={},Zu={get exports(){return rn},set exports(e){rn=e}},an={};/**
|
|
1
|
+
(function(S,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("react"),require("@mantine/core"),require("@mantine/modals"),require("ahooks"),require("mobx"),require("mobx-react-lite"),require("crypto-js"),require("dayjs"),require("lodash"),require("numbro"),require("d3-array"),require("mathjs"),require("@faker-js/faker"),require("axios"),require("eventemitter2"),require("chroma-js"),require("echarts-for-react/lib/core"),require("echarts-gl"),require("echarts/components"),require("echarts/core"),require("echarts/renderers"),require("react-hook-form"),require("tabler-icons-react"),require("echarts/charts"),require("@tabler/icons-react"),require("@mantine/hooks"),require("@mantine/notifications"),require("@mantine/tiptap"),require("@tiptap/extension-color"),require("@tiptap/extension-highlight"),require("@tiptap/extension-placeholder"),require("@tiptap/extension-subscript"),require("@tiptap/extension-superscript"),require("@tiptap/extension-text-align"),require("@tiptap/extension-text-style"),require("@tiptap/extension-table"),require("@tiptap/extension-table-cell"),require("@tiptap/extension-table-header"),require("@tiptap/extension-table-row"),require("@tiptap/extension-underline"),require("@tiptap/react"),require("@tiptap/starter-kit"),require("prosemirror-keymap"),require("prosemirror-commands"),require("prosemirror-schema-list"),require("@monaco-editor/react"),require("popmotion"),require("d3-regression"),require("@mantine/prism"),require("@tanstack/react-table"),require("react-virtual"),require("@mantine/dates"),require("rc-select"),require("rc-tree-select"),require("react-grid-layout"),require("mobx-state-tree"),require("performant-array-to-tree"),require("@json2csv/whatwg"),require("file-saver"),require("jszip"),require("dom-to-image-more"),require("/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/advancedFormat.js"),require("/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/arraySupport.js"),require("/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/buddhistEra.js"),require("/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/calendar.js"),require("/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/customParseFormat.js"),require("/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/dayOfYear.js"),require("/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/duration.js"),require("/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/isBetween.js"),require("/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/isLeapYear.js"),require("/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/isMoment.js"),require("/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/isoWeek.js"),require("/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/isoWeeksInYear.js"),require("/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/isSameOrAfter.js"),require("/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/isSameOrBefore.js"),require("/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/isToday.js"),require("/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/isTomorrow.js"),require("/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/isYesterday.js"),require("/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/localeData.js"),require("/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/localizedFormat.js"),require("/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/minMax.js"),require("/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/objectSupport.js"),require("/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/pluralGetSet.js"),require("/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/preParsePostFormat.js"),require("/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/quarterOfYear.js"),require("/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/relativeTime.js"),require("/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/timezone.js"),require("/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/toArray.js"),require("/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/toObject.js"),require("/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/updateLocale.js"),require("/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/utc.js"),require("/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/weekday.js"),require("/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/weekOfYear.js"),require("/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/weekYear.js"),require("react-router-dom"),require("reactflow")):typeof define=="function"&&define.amd?define(["exports","react","@mantine/core","@mantine/modals","ahooks","mobx","mobx-react-lite","crypto-js","dayjs","lodash","numbro","d3-array","mathjs","@faker-js/faker","axios","eventemitter2","chroma-js","echarts-for-react/lib/core","echarts-gl","echarts/components","echarts/core","echarts/renderers","react-hook-form","tabler-icons-react","echarts/charts","@tabler/icons-react","@mantine/hooks","@mantine/notifications","@mantine/tiptap","@tiptap/extension-color","@tiptap/extension-highlight","@tiptap/extension-placeholder","@tiptap/extension-subscript","@tiptap/extension-superscript","@tiptap/extension-text-align","@tiptap/extension-text-style","@tiptap/extension-table","@tiptap/extension-table-cell","@tiptap/extension-table-header","@tiptap/extension-table-row","@tiptap/extension-underline","@tiptap/react","@tiptap/starter-kit","prosemirror-keymap","prosemirror-commands","prosemirror-schema-list","@monaco-editor/react","popmotion","d3-regression","@mantine/prism","@tanstack/react-table","react-virtual","@mantine/dates","rc-select","rc-tree-select","react-grid-layout","mobx-state-tree","performant-array-to-tree","@json2csv/whatwg","file-saver","jszip","dom-to-image-more","/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/advancedFormat.js","/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/arraySupport.js","/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/buddhistEra.js","/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/calendar.js","/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/customParseFormat.js","/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/dayOfYear.js","/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/duration.js","/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/isBetween.js","/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/isLeapYear.js","/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/isMoment.js","/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/isoWeek.js","/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/isoWeeksInYear.js","/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/isSameOrAfter.js","/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/isSameOrBefore.js","/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/isToday.js","/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/isTomorrow.js","/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/isYesterday.js","/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/localeData.js","/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/localizedFormat.js","/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/minMax.js","/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/objectSupport.js","/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/pluralGetSet.js","/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/preParsePostFormat.js","/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/quarterOfYear.js","/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/relativeTime.js","/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/timezone.js","/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/toArray.js","/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/toObject.js","/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/updateLocale.js","/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/utc.js","/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/weekday.js","/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/weekOfYear.js","/Users/leto/github/merico-dev/table/node_modules/dayjs/plugin/weekYear.js","react-router-dom","reactflow"],m):(S=typeof globalThis<"u"?globalThis:S||self,m(S.dashboard={},S.react,S["@mantine/core"],S["@mantine/modals"],S.ahooks,S.mobx,S["mobx-react-lite"],S.CryptoJS,S.dayjs,S._,S.numbro,S["d3-array"],S.mathjs,S["@faker-js/faker"],S.axios,S.eventemitter2,S["chroma-js"],S["echarts-for-react/lib/core"],S["echarts-gl"],S["echarts/components"],S["echarts/core"],S["echarts/renderers"],S["react-hook-form"],S["tabler-icons-react"],S["echarts/charts"],S["@tabler/icons-react"],S["@mantine/hooks"],S["@mantine/notifications"],S["@mantine/tiptap"],S["@tiptap/extension-color"],S["@tiptap/extension-highlight"],S["@tiptap/extension-placeholder"],S["@tiptap/extension-subscript"],S["@tiptap/extension-superscript"],S["@tiptap/extension-text-align"],S["@tiptap/extension-text-style"],S["@tiptap/extension-table"],S["@tiptap/extension-table-cell"],S["@tiptap/extension-table-header"],S["@tiptap/extension-table-row"],S["@tiptap/extension-underline"],S["@tiptap/react"],S["@tiptap/starter-kit"],S["prosemirror-keymap"],S["prosemirror-commands"],S["prosemirror-schema-list"],S["@monaco-editor/react"],S.popmotion,S["d3-regression"],S["@mantine/prism"],S["@tanstack/react-table"],S["react-virtual"],S["@mantine/dates"],S["rc-select"],S["rc-tree-select"],S["react-grid-layout"],S["mobx-state-tree"],S["performant-array-to-tree"],S["@json2csv/whatwg"],S["file-saver"],S.jszip,S["dom-to-image-more"],S.dayjs,S.dayjs,S.dayjs,S.dayjs,S.dayjs,S.dayjs,S.dayjs,S.dayjs,S.dayjs,S.dayjs,S.dayjs,S.dayjs,S.dayjs,S.dayjs,S.dayjs,S.dayjs,S.dayjs,S.dayjs,S.dayjs,S.dayjs,S.dayjs,S.dayjs,S.dayjs,S.dayjs,S.dayjs,S.dayjs,S.dayjs,S.dayjs,S.dayjs,S.dayjs,S.dayjs,S.dayjs,S.dayjs,S["react-router-dom"],S.reactflow))})(this,function(S,m,s,Ee,q,Q,k,ji,G,x,W,Vt,tu,nu,nt,Wi,rt,Se,uI,B,ru,_e,v,T,re,M,ye,on,j,Ri,Qi,Ui,Ki,Yi,Xi,Ji,Zi,Hi,ea,ta,na,ra,ia,cI,be,tr,ve,ft,iu,gt,We,au,su,aa,sa,ln,y,ou,lu,nr,uu,oa,cu,du,pu,hu,fu,gu,mu,yu,bu,vu,xu,wu,Cu,Su,_u,ku,Tu,Du,Iu,Mu,Au,zu,Eu,Pu,Lu,Bu,Ou,$u,Vu,Nu,qu,Gu,Fu,ju,we){"use strict";var oI=Object.defineProperty;var lI=(S,m,s)=>m in S?oI(S,m,{enumerable:!0,configurable:!0,writable:!0,value:s}):S[m]=s;var P=(S,m,s)=>(lI(S,typeof m!="symbol"?m+"":m,s),s);function Nt(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const i=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,i.get?i:{enumerable:!0,get:()=>t[n]})}}return e.default=t,Object.freeze(e)}const Wu=Nt(ji),Ru=Nt(Vt),un=Nt(tu),Y=Nt(ru),ct=Nt(iu);var qt={},Qu={get exports(){return qt},set exports(t){qt=t}},Gt={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var
|
|
9
|
+
*/var la;function Uu(){if(la)return Gt;la=1;var t=m,e=Symbol.for("react.element"),n=Symbol.for("react.fragment"),i=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,p){var h,f={},g=null,b=null;p!==void 0&&(g=""+p),c.key!==void 0&&(g=""+c.key),c.ref!==void 0&&(b=c.ref);for(h in c)i.call(c,h)&&!o.hasOwnProperty(h)&&(f[h]=c[h]);if(u&&u.defaultProps)for(h in c=u.defaultProps,c)f[h]===void 0&&(f[h]=c[h]);return{$$typeof:e,type:u,key:g,ref:b,props:f,_owner:a.current}}return Gt.Fragment=n,Gt.jsx=l,Gt.jsxs=l,Gt}var Ft={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,29 +14,29 @@
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var
|
|
18
|
-
`+
|
|
19
|
-
`),
|
|
20
|
-
`),
|
|
21
|
-
`+
|
|
17
|
+
*/var ua;function Ku(){return ua||(ua=1,process.env.NODE_ENV!=="production"&&function(){var t=m,e=Symbol.for("react.element"),n=Symbol.for("react.portal"),i=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"),p=Symbol.for("react.suspense"),h=Symbol.for("react.suspense_list"),f=Symbol.for("react.memo"),g=Symbol.for("react.lazy"),b=Symbol.for("react.offscreen"),w=Symbol.iterator,_="@@iterator";function D(C){if(C===null||typeof C!="object")return null;var I=w&&C[w]||C[_];return typeof I=="function"?I:null}var L=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function N(C){{for(var I=arguments.length,E=new Array(I>1?I-1:0),F=1;F<I;F++)E[F-1]=arguments[F];J("error",C,E)}}function J(C,I,E){{var F=L.ReactDebugCurrentFrame,Z=F.getStackAddendum();Z!==""&&(I+="%s",E=E.concat([Z]));var ne=E.map(function(U){return String(U)});ne.unshift("Warning: "+I),Function.prototype.apply.call(console[C],console,ne)}}var ae=!1,K=!1,oe=!1,pe=!1,me=!1,St;St=Symbol.for("react.module.reference");function Ye(C){return!!(typeof C=="string"||typeof C=="function"||C===i||C===o||me||C===a||C===p||C===h||pe||C===b||ae||K||oe||typeof C=="object"&&C!==null&&(C.$$typeof===g||C.$$typeof===f||C.$$typeof===l||C.$$typeof===u||C.$$typeof===c||C.$$typeof===St||C.getModuleId!==void 0))}function Li(C,I,E){var F=C.displayName;if(F)return F;var Z=I.displayName||I.name||"";return Z!==""?E+"("+Z+")":E}function rn(C){return C.displayName||"Context"}function lt(C){if(C==null)return null;if(typeof C.tag=="number"&&N("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof C=="function")return C.displayName||C.name||null;if(typeof C=="string")return C;switch(C){case i:return"Fragment";case n:return"Portal";case o:return"Profiler";case a:return"StrictMode";case p:return"Suspense";case h:return"SuspenseList"}if(typeof C=="object")switch(C.$$typeof){case u:var I=C;return rn(I)+".Consumer";case l:var E=C;return rn(E._context)+".Provider";case c:return Li(C,C.render,"ForwardRef");case f:var F=C.displayName||null;return F!==null?F:lt(C.type)||"Memo";case g:{var Z=C,ne=Z._payload,U=Z._init;try{return lt(U(ne))}catch{return null}}}return null}var _t=Object.assign,an=0,Pl,Ll,Bl,Ol,$l,Vl,Nl;function ql(){}ql.__reactDisabledLog=!0;function OD(){{if(an===0){Pl=console.log,Ll=console.info,Bl=console.warn,Ol=console.error,$l=console.group,Vl=console.groupCollapsed,Nl=console.groupEnd;var C={configurable:!0,enumerable:!0,value:ql,writable:!0};Object.defineProperties(console,{info:C,log:C,warn:C,error:C,group:C,groupCollapsed:C,groupEnd:C})}an++}}function $D(){{if(an--,an===0){var C={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:_t({},C,{value:Pl}),info:_t({},C,{value:Ll}),warn:_t({},C,{value:Bl}),error:_t({},C,{value:Ol}),group:_t({},C,{value:$l}),groupCollapsed:_t({},C,{value:Vl}),groupEnd:_t({},C,{value:Nl})})}an<0&&N("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var Bi=L.ReactCurrentDispatcher,Oi;function Xn(C,I,E){{if(Oi===void 0)try{throw Error()}catch(Z){var F=Z.stack.trim().match(/\n( *(at )?)/);Oi=F&&F[1]||""}return`
|
|
18
|
+
`+Oi+C}}var $i=!1,Jn;{var VD=typeof WeakMap=="function"?WeakMap:Map;Jn=new VD}function Gl(C,I){if(!C||$i)return"";{var E=Jn.get(C);if(E!==void 0)return E}var F;$i=!0;var Z=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var ne;ne=Bi.current,Bi.current=null,OD();try{if(I){var U=function(){throw Error()};if(Object.defineProperty(U.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(U,[])}catch(ut){F=ut}Reflect.construct(C,[],U)}else{try{U.call()}catch(ut){F=ut}C.call(U.prototype)}}else{try{throw Error()}catch(ut){F=ut}C()}}catch(ut){if(ut&&F&&typeof ut.stack=="string"){for(var R=ut.stack.split(`
|
|
19
|
+
`),De=F.stack.split(`
|
|
20
|
+
`),le=R.length-1,he=De.length-1;le>=1&&he>=0&&R[le]!==De[he];)he--;for(;le>=1&&he>=0;le--,he--)if(R[le]!==De[he]){if(le!==1||he!==1)do if(le--,he--,he<0||R[le]!==De[he]){var je=`
|
|
21
|
+
`+R[le].replace(" at new "," at ");return C.displayName&&je.includes("<anonymous>")&&(je=je.replace("<anonymous>",C.displayName)),typeof C=="function"&&Jn.set(C,je),je}while(le>=1&&he>=0);break}}}finally{$i=!1,Bi.current=ne,$D(),Error.prepareStackTrace=Z}var $t=C?C.displayName||C.name:"",eu=$t?Xn($t):"";return typeof C=="function"&&Jn.set(C,eu),eu}function ND(C,I,E){return Gl(C,!1)}function qD(C){var I=C.prototype;return!!(I&&I.isReactComponent)}function Zn(C,I,E){if(C==null)return"";if(typeof C=="function")return Gl(C,qD(C));if(typeof C=="string")return Xn(C);switch(C){case p:return Xn("Suspense");case h:return Xn("SuspenseList")}if(typeof C=="object")switch(C.$$typeof){case c:return ND(C.render);case f:return Zn(C.type,I,E);case g:{var F=C,Z=F._payload,ne=F._init;try{return Zn(ne(Z),I,E)}catch{}}}return""}var Hn=Object.prototype.hasOwnProperty,Fl={},jl=L.ReactDebugCurrentFrame;function er(C){if(C){var I=C._owner,E=Zn(C.type,C._source,I?I.type:null);jl.setExtraStackFrame(E)}else jl.setExtraStackFrame(null)}function GD(C,I,E,F,Z){{var ne=Function.call.bind(Hn);for(var U in C)if(ne(C,U)){var R=void 0;try{if(typeof C[U]!="function"){var De=Error((F||"React class")+": "+E+" type `"+U+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof C[U]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw De.name="Invariant Violation",De}R=C[U](I,U,F,E,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(le){R=le}R&&!(R instanceof Error)&&(er(Z),N("%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).",F||"React class",E,U,typeof R),er(null)),R instanceof Error&&!(R.message in Fl)&&(Fl[R.message]=!0,er(Z),N("Failed %s type: %s",E,R.message),er(null))}}}var FD=Array.isArray;function Vi(C){return FD(C)}function jD(C){{var I=typeof Symbol=="function"&&Symbol.toStringTag,E=I&&C[Symbol.toStringTag]||C.constructor.name||"Object";return E}}function WD(C){try{return Wl(C),!1}catch{return!0}}function Wl(C){return""+C}function Rl(C){if(WD(C))return N("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",jD(C)),Wl(C)}var sn=L.ReactCurrentOwner,RD={key:!0,ref:!0,__self:!0,__source:!0},Ql,Ul,Ni;Ni={};function QD(C){if(Hn.call(C,"ref")){var I=Object.getOwnPropertyDescriptor(C,"ref").get;if(I&&I.isReactWarning)return!1}return C.ref!==void 0}function UD(C){if(Hn.call(C,"key")){var I=Object.getOwnPropertyDescriptor(C,"key").get;if(I&&I.isReactWarning)return!1}return C.key!==void 0}function KD(C,I){if(typeof C.ref=="string"&&sn.current&&I&&sn.current.stateNode!==I){var E=lt(sn.current.type);Ni[E]||(N('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',lt(sn.current.type),C.ref),Ni[E]=!0)}}function YD(C,I){{var E=function(){Ql||(Ql=!0,N("%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)",I))};E.isReactWarning=!0,Object.defineProperty(C,"key",{get:E,configurable:!0})}}function XD(C,I){{var E=function(){Ul||(Ul=!0,N("%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)",I))};E.isReactWarning=!0,Object.defineProperty(C,"ref",{get:E,configurable:!0})}}var JD=function(C,I,E,F,Z,ne,U){var R={$$typeof:e,type:C,key:I,ref:E,props:U,_owner:ne};return R._store={},Object.defineProperty(R._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(R,"_self",{configurable:!1,enumerable:!1,writable:!1,value:F}),Object.defineProperty(R,"_source",{configurable:!1,enumerable:!1,writable:!1,value:Z}),Object.freeze&&(Object.freeze(R.props),Object.freeze(R)),R};function ZD(C,I,E,F,Z){{var ne,U={},R=null,De=null;E!==void 0&&(Rl(E),R=""+E),UD(I)&&(Rl(I.key),R=""+I.key),QD(I)&&(De=I.ref,KD(I,Z));for(ne in I)Hn.call(I,ne)&&!RD.hasOwnProperty(ne)&&(U[ne]=I[ne]);if(C&&C.defaultProps){var le=C.defaultProps;for(ne in le)U[ne]===void 0&&(U[ne]=le[ne])}if(R||De){var he=typeof C=="function"?C.displayName||C.name||"Unknown":C;R&&YD(U,he),De&&XD(U,he)}return JD(C,R,De,Z,F,sn.current,U)}}var qi=L.ReactCurrentOwner,Kl=L.ReactDebugCurrentFrame;function Ot(C){if(C){var I=C._owner,E=Zn(C.type,C._source,I?I.type:null);Kl.setExtraStackFrame(E)}else Kl.setExtraStackFrame(null)}var Gi;Gi=!1;function Fi(C){return typeof C=="object"&&C!==null&&C.$$typeof===e}function Yl(){{if(qi.current){var C=lt(qi.current.type);if(C)return`
|
|
22
22
|
|
|
23
|
-
Check the render method of \``+
|
|
23
|
+
Check the render method of \``+C+"`."}return""}}function HD(C){{if(C!==void 0){var I=C.fileName.replace(/^.*[\\\/]/,""),E=C.lineNumber;return`
|
|
24
24
|
|
|
25
|
-
Check your code at `+
|
|
25
|
+
Check your code at `+I+":"+E+"."}return""}}var Xl={};function eI(C){{var I=Yl();if(!I){var E=typeof C=="string"?C:C.displayName||C.name;E&&(I=`
|
|
26
26
|
|
|
27
|
-
Check the top-level render call using <`+
|
|
27
|
+
Check the top-level render call using <`+E+">.")}return I}}function Jl(C,I){{if(!C._store||C._store.validated||C.key!=null)return;C._store.validated=!0;var E=eI(I);if(Xl[E])return;Xl[E]=!0;var F="";C&&C._owner&&C._owner!==qi.current&&(F=" It was passed a child from "+lt(C._owner.type)+"."),Ot(C),N('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',E,F),Ot(null)}}function Zl(C,I){{if(typeof C!="object")return;if(Vi(C))for(var E=0;E<C.length;E++){var F=C[E];Fi(F)&&Jl(F,I)}else if(Fi(C))C._store&&(C._store.validated=!0);else if(C){var Z=D(C);if(typeof Z=="function"&&Z!==C.entries)for(var ne=Z.call(C),U;!(U=ne.next()).done;)Fi(U.value)&&Jl(U.value,I)}}}function tI(C){{var I=C.type;if(I==null||typeof I=="string")return;var E;if(typeof I=="function")E=I.propTypes;else if(typeof I=="object"&&(I.$$typeof===c||I.$$typeof===f))E=I.propTypes;else return;if(E){var F=lt(I);GD(E,C.props,"prop",F,C)}else if(I.PropTypes!==void 0&&!Gi){Gi=!0;var Z=lt(I);N("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",Z||"Unknown")}typeof I.getDefaultProps=="function"&&!I.getDefaultProps.isReactClassApproved&&N("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function nI(C){{for(var I=Object.keys(C.props),E=0;E<I.length;E++){var F=I[E];if(F!=="children"&&F!=="key"){Ot(C),N("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",F),Ot(null);break}}C.ref!==null&&(Ot(C),N("Invalid attribute `ref` supplied to `React.Fragment`."),Ot(null))}}function Hl(C,I,E,F,Z,ne){{var U=Ye(C);if(!U){var R="";(C===void 0||typeof C=="object"&&C!==null&&Object.keys(C).length===0)&&(R+=" 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 De=HD(Z);De?R+=De:R+=Yl();var le;C===null?le="null":Vi(C)?le="array":C!==void 0&&C.$$typeof===e?(le="<"+(lt(C.type)||"Unknown")+" />",R=" Did you accidentally export a JSX literal instead of a component?"):le=typeof C,N("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",le,R)}var he=ZD(C,I,E,Z,ne);if(he==null)return he;if(U){var je=I.children;if(je!==void 0)if(F)if(Vi(je)){for(var $t=0;$t<je.length;$t++)Zl(je[$t],C);Object.freeze&&Object.freeze(je)}else N("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 Zl(je,C)}return C===i?nI(he):tI(he),he}}function rI(C,I,E){return Hl(C,I,E,!0)}function iI(C,I,E){return Hl(C,I,E,!1)}var aI=iI,sI=rI;Ft.Fragment=i,Ft.jsx=aI,Ft.jsxs=sI}()),Ft}(function(t){process.env.NODE_ENV==="production"?t.exports=Uu():t.exports=Ku()})(Qu);const z=qt.Fragment,r=qt.jsx,d=qt.jsxs,mt={CryptoJS:ji,d3Array:Ru,dayjs:G,lodash:x,numbro:W,mathjs:un,faker:nu.faker},Yu=[{name:"CryptoJS",url:"https://github.com/brix/crypto-js",version:"4.1.1"},{name:"d3Array",url:"https://github.com/d3/d3-array",version:"3.2.0"},{name:"dayjs",url:"https://day.js.org/",version:"1.11.6"},{name:"lodash",url:"https://lodash.com/docs/4.17.15",version:"4.17.21"},{name:"mathjs",url:"https://mathjs.org/",version:"11.7.0"},{name:"numbro",url:"https://numbrojs.com/",version:"2.3.6"},{name:"faker",url:"https://fakerjs.dev/",version:"7.6.0"}],Xu=t=>`
|
|
28
28
|
<tr>
|
|
29
|
-
<td><code>${
|
|
29
|
+
<td><code>${t.name}</code></td>
|
|
30
30
|
<td>
|
|
31
31
|
<a
|
|
32
32
|
target="_blank"
|
|
33
33
|
rel="noopener noreferrer nofollow"
|
|
34
|
-
href="${
|
|
35
|
-
>${
|
|
34
|
+
href="${t.url}"
|
|
35
|
+
>${t.name}@${t.version}</a
|
|
36
36
|
>
|
|
37
37
|
</td>
|
|
38
38
|
</tr>
|
|
39
|
-
`,
|
|
39
|
+
`,Ju=`
|
|
40
40
|
<p>
|
|
41
41
|
Parameter <code>utils</code> is <code>functionUtils</code>, which contains:
|
|
42
42
|
</p>
|
|
@@ -48,68 +48,68 @@ Check the top-level render call using <`+V+">.")}return z}}function Ou(S,z){{if(
|
|
|
48
48
|
</tr>
|
|
49
49
|
</thead>
|
|
50
50
|
<tbody>
|
|
51
|
-
${
|
|
51
|
+
${Yu.map(Xu).join("")}
|
|
52
52
|
</tbody>
|
|
53
53
|
</table>
|
|
54
|
-
`;function xr(e,t){const n=Object.keys(t),r=Object.values(t);try{return new Function(...n,`return \`${e}\`;`)(...r)}catch(a){throw n.length===0&&e.includes("$")?new Error("[formatSQL] insufficient payload"):a}}function wr(e,t){try{return xr(e,t)}catch(n){return console.error(n),n.message}}function ic({sql:e,pre_process:t}){if(!t.trim())return e;try{return new Function(`return ${t}`)()({sql:e},At)}catch(n){return console.error(n),e}}function ac(e,t,n){if(!e.trim())return t;try{return new Function(`return ${e}`)()(t,At,n)}catch(r){return console.error(r),t}}function sc(e){e=e||{};const t=Object.keys(e).sort(),n=[];for(let r=0;r<t.length;r++){const a=t[r];if(a!="authentication"&&e[a])n.push(t[r]+"="+(typeof e[a]=="object"?JSON.stringify(e[a]):e[a]));else{const o=Object.keys(e[a]).sort();for(let l=0;l<o.length;l++){const u=o[l];u!="sign"&&e[a][u]&&n.push(o[l]+"="+(typeof e[a][u]=="object"?JSON.stringify(e[a][u]):e[a][u]))}}}return n.sort().join("&")}function oc(e,t){let n=sc(e);return n+="&key="+t,Xu.MD5(n).toString().toUpperCase()}class is{constructor(){this.type="default_api_client",this.baseURL="http://localhost:31200",this.app_id="",this.app_secret=""}getAuthentication(t){if(!this.app_id||!this.app_secret)return;const n=new Date().getTime().toString();return{app_id:this.app_id,nonce_str:n,sign:oc({app_id:this.app_id,nonce_str:n,...t},this.app_secret)}}getRequest(t,n){return(r,a,o,l)=>{const u=this.buildHeader(o),c=this.buildAxiosConfig(t,r,a,o,u,n);return pt(c).then(d=>l?d:d.data).catch(d=>Promise.reject(d))}}get(t){return this.getRequest("GET",t)}post(t){return this.getRequest("POST",t)}put(t){return this.getRequest("PUT",t)}buildAxiosConfig(t,n,r,a,o,l){const u={baseURL:this.baseURL,method:t,url:n,params:t==="GET"?r:a.params,headers:o,signal:l};return["POST","PUT"].includes(t)&&(u.data=a.string?JSON.stringify(r):r,u.data.authentication=this.getAuthentication(u.data)),u}buildHeader(t){const n=window.localStorage.getItem("token");return{"X-Requested-With":"XMLHttpRequest","Content-Type":t.string?"application/x-www-form-urlencoded":"application/json",authorization:n?`bearer ${n}`:"",...t.headers}}}class lc{constructor(t){this.implementation=t}getRequest(t,n){return this.implementation.getRequest(t,n)}get(t){return this.getRequest("GET",t)}post(t){return this.getRequest("POST",t)}put(t){return this.getRequest("PUT",t)}}class as extends is{constructor(){super(...arguments);q(this,"makeQueryENV",null)}query(n){return async(r,a={})=>{var o;return r.env||(r.env=((o=this.makeQueryENV)==null?void 0:o.call(this))??{error:"failed to run makeQueryENV"}),this.post(n)("/query",r,a)}}httpDataSourceQuery(n){return async(r,a={})=>{var o;return r.env||(r.env=((o=this.makeQueryENV)==null?void 0:o.call(this))??{error:"failed to run makeQueryENV"}),this.getRequest("POST",n)("/query",r,a,!0)}}structure(n){return async(r,a={})=>this.post(n)("/query/structure",r,a)}}class ss{constructor(t){this.implementation=t}query(t){return this.implementation.query(t)}httpDataSourceQuery(t){return this.implementation.httpDataSourceQuery(t)}structure(t){return this.implementation.structure(t)}getRequest(t,n){return this.implementation.getRequest(t,n)}get(t){return this.getRequest("GET",t)}post(t){return this.getRequest("POST",t)}put(t){return this.getRequest("PUT",t)}}const Nt=new as;function Cr(e){Nt.baseURL!==e.apiBaseURL&&(Nt.baseURL=e.apiBaseURL),e.app_id&&(Nt.app_id=e.app_id),e.app_secret&&(Nt.app_secret=e.app_secret),e.makeQueryENV&&(Nt.makeQueryENV=e.makeQueryENV)}const os=new ss(Nt),at=os;function ls(){return{filters:{},context:{}}}function Sr(e){const t=ls();if(!e)return ls();const{filters:n=t.filters,context:r=t.context}=e;return{filters:n,context:r}}async function uc({query:e,name:t,payload:n,additionals:r},a){if(!e.sql)return[];const{type:o,key:l,sql:u,pre_process:c,post_process:d}=e,f=xr(u,n),h=ic({sql:f,pre_process:c});let g=await at.query(a)({type:o,key:l,query:h,...r},{params:{name:t}});return g=ac(d,g,Sr(n)),g}async function cc({type:e,key:t,configString:n,name:r,additionals:a},o){try{return await at.httpDataSourceQuery(o)({type:e,key:t,query:n,...a},{params:{name:r}})}catch(l){if(pt.isCancel(l))throw l;return console.error(l),l}}async function _r(){try{return(await at.post()("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}},{})).data}catch(e){return console.error(e),[]}}async function us(){try{return(await at.post()("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}},{})).data}catch(e){return console.error(e),[]}}class cs{constructor(t){q(this,"rootRef");this.rootRef=te.observable({current:t})}async deleteItem(t){te.runInAction(()=>{x.unset(this.rootRef.current,[t])})}getItem(t){const n=this.getValueFromRoot(t);return Promise.resolve(n)}getValueFromRoot(t){return t===null?te.toJS(this.rootRef.current):x.get(this.rootRef.current,[t])}setItem(t,n){if(t===null)if(x.isObject(n))te.runInAction(()=>{this.rootRef.current=n});else throw new Error("Cannot set root value to non-object");else te.runInAction(()=>{x.set(this.rootRef.current,[t],n)});return Promise.resolve(this.getItem(t))}watchItem(t,n,r){return te.reaction(()=>this.getValueFromRoot(t),(a,o)=>{n(a,o)},{requiresObservable:!0,fireImmediately:x.get(r,"fireImmediately",!1)})}}class dc{constructor(){q(this,"channels",new Map);q(this,"globalChannel",new Va)}getChannel(t){const n=this.channels.get(t);if(n)return n;const r=new Va;return this.channels.set(t,r),r}}class pc{constructor(t){q(this,"instances",new Map);this.pluginManager=t}get availableVizList(){return this.pluginManager.installedPlugins.flatMap(t=>t.manifest.viz)}resolveComponent(t){return this.pluginManager.factory.viz(t)}getOrCreateInstance(t){const n=this.instances.get(t.id);if(n)return n;const r={id:t.id,name:t.viz.type,type:t.viz.type,messageChannels:new dc,instanceData:new cs(t.viz.conf)};return this.instances.set(t.id,r),r}}function ds(e,t,n,r){return{vizManager:n,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new cs({}),colorPalette:{getColor(){return()=>""}},data:t,variables:r}}const hc=e=>{const{panel:t,vizManager:n,data:r,variables:a}=e,o=n.resolveComponent(t.viz.type),l=n.getOrCreateInstance(t),u={...ds(l,r,n,a),viewport:{width:t.layout.w,height:t.layout.h}},c=o.viewRender;return i(c,{context:u,instance:l,...x.omit(e,["panel","vizManager","data"])})},fc=e=>{const{vizManager:t,panel:n,data:r,variables:a}=e,o=t.resolveComponent(n.viz.type),l=t.getOrCreateInstance(n),u={...ds(l,r,t,a)},c=o.configRender;return i(c,{context:u,instance:l,...x.omit(e,["panel","vizManager","data"])})},ps=(e,t)=>{const n=ht.bezier(e),r=ht.bezier(t);return function(a){return a<50?n(a*2/100).hex():r((a-50)*2/100).hex()}},Mn=e=>{const t=ht.bezier(e);return function(n){return t(n/100).hex()}},gc={type:"interpolation",displayName:"Red / Green",getColor:ps(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},mc={type:"interpolation",displayName:"Yellow / Blue",getColor:ps(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},yc={type:"interpolation",displayName:"Red",getColor:Mn(["#fff7f1","darkred"]),name:"red",category:"sequential"},bc={type:"interpolation",displayName:"Green",getColor:Mn(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},vc={type:"interpolation",displayName:"Blue",getColor:Mn(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},xc={type:"interpolation",displayName:"Orange",getColor:Mn(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class wc{constructor(t){q(this,"symbol");this.symbol=Symbol(t)}}function ft(e){return new wc(e)}class kr{constructor(){q(this,"parent");q(this,"factoryRegistry",new Map);q(this,"instanceRegistry",new Map)}createScoped(){const t=new kr;return t.parent=this,t}getRequired(t){return this.get(t)}get(t){if(this.instanceRegistry.has(t.symbol))return this.instanceRegistry.get(t.symbol);const n=this.factoryRegistry.get(t.symbol);if(n){const r=n(this);return this.instanceRegistry.set(t.symbol,r),r}if(this.parent)return this.parent.get(t)}provideFactory(t,n){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,n),this}provideValue(t,n){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,()=>n),this}dispose(){this.instanceRegistry.forEach(t=>{const n=x.get(t,"dispose");x.isFunction(n)&&n.bind(t)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}const hs="10.44.0",Cc=Object.freeze(Object.defineProperty({__proto__:null,version:hs},Symbol.toStringTag,{value:"Module"}));class Sc{constructor(t){q(this,"staticColors",new Map);q(this,"interpolations",new Map);t.installedPlugins.forEach(n=>{n.manifest.color.forEach(r=>{this.register(r)})})}getStaticColors(){return Array.from(this.staticColors.values())}register(t){const n=this.encodeColor(t);t.type==="single"?(this.staticColors.has(n)&&console.warn(`the color '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.staticColors.set(n,t)):t.type==="interpolation"&&(this.interpolations.has(n)&&console.warn(`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`,`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.interpolations.set(n,t))}decodeStaticColor(t){return this.staticColors.get(t)}encodeColor(t){return`\${${t.category}}.{${t.name}}`}decodeInterpolation(t){return this.interpolations.get(t)}getColorInterpolations(){return Array.from(this.interpolations.values())}}class _c{constructor(){q(this,"plugins",new Map);q(this,"vizComponents",new Map);q(this,"factory",{viz:t=>{const n=this.vizComponents.get(t);if(n)return n;throw new Error(`Viz Component (${t}) not found`)}})}install(t){if(this.plugins.has(t.id))throw new Error(`Plugin (${t.id}) has been installed before`);this.plugins.set(t.id,t);for(const n of t.manifest.viz){if(this.vizComponents.has(n.name))throw new Error(`Viz Component (${n.name}) has been installed before`);this.vizComponents.set(n.name,n)}}get installedPlugins(){return Array.from(this.plugins.values())}}class kc{constructor(){q(this,"migrations",[])}version(t,n){return this.migrations.push({version:t,handler:n}),this}run(t,n,r){var l;if(t.from===t.to)return n;if(t.from>t.to)throw new Error(`Can not downgrade from version '${t.from}' to (${t.to})`);const a=this.migrations.filter(u=>u.version>t.from&&u.version<=t.to),o=x.orderBy(a,"version","asc");if(((l=x.last(o))==null?void 0:l.version)!==t.to)throw new Error(`Migration to version ${t.to} not found`);return o.reduce((u,c)=>c.handler(u,r),n)}}class ge extends kc{constructor(){super(),this.configVersions()}version(t,n){return super.version(t,(r,a)=>({version:t,...n(r,a)}))}async migrate({configData:t,panelModel:n}){const r=await t.getItem(null),a=x.get(r,"version",0),o=this.run({from:a,to:this.VERSION},r,{panelModel:n});await t.setItem(null,o)}async needMigration({configData:t}){const n=await t.getItem(null);return x.get(n,"version",0)<this.VERSION}}const R=(e,t)=>{const[n,{setFalse:r}]=Q.useBoolean(!0),[a,o]=m.useState();m.useEffect(()=>(e.getItem(t).then(u=>{o(u),r()}),e.watchItem(t,u=>{o(u)})));const l=m.useCallback(async u=>{await e.setItem(t,u),o(u)},[e,t]);return{loading:n,value:a,set:l}},Oe={top:16,right:16,bottom:16,left:16},tt=e=>Math.max(0,e-Oe.left-Oe.right),nt=e=>Math.max(0,e-Oe.top-Oe.bottom),on=(e,t)=>({width:tt(e),height:nt(t)}),Be=({width:e,height:t,children:n})=>i(s.Box,{pt:Oe.top,pr:Oe.right,pb:Oe.bottom,pl:Oe.left,sx:{width:e,height:t,overflow:"hidden",position:"relative"},children:n});function P(e){const[t,n]=e.split(".");return{queryID:t,columnKey:n}}function Tc(e){return e.includes(".")?P(e):{queryID:"",columnKey:e}}function gt(e,t){var a;const{queryID:n,columnKey:r}=P(t);return n?r?((a=e[n])==null?void 0:a.map(o=>o[r]))??[]:e[n]:[]}function ln(e,t){const{queryID:n}=P(t);return n?e[n]:[]}function Dc(e){return Object.values(e)[0]}function An(e,t){const{queryID:n,columnKey:r}=P(t);return e[r]}const Tr={x_axis_data_key:"",y_axis_data_key:"",z_axis_data_key:"",xAxis3D:{type:"value",name:"X Axis Name"},yAxis3D:{type:"value",name:"Y Axis Name"},zAxis3D:{type:"value",name:"Z Axis Name"}};ie.use([F.GridComponent,F.VisualMapComponent,F.LegendComponent,F.TooltipComponent,ze.CanvasRenderer]);function Ic({context:e}){const{value:t}=R(e.instanceData,"config"),n=e.data,{width:r,height:a}=e.viewport,{x_axis_data_key:o,y_axis_data_key:l,z_axis_data_key:u,xAxis3D:c,yAxis3D:d,zAxis3D:f}=x.defaults({},t,Tr),h=m.useMemo(()=>ln(n,o),[n,o]),{x:g,y,z:C}=m.useMemo(()=>({x:P(o),y:P(l),z:P(u)}),[o,l,u]),{min:w,max:_}=m.useMemo(()=>{const M=x.minBy(h,G=>G[C.columnKey]),O=x.maxBy(h,G=>G[C.columnKey]);return{min:x.get(M,C.columnKey),max:x.get(O,C.columnKey)}},[h,C]),D={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:w,max:_,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:c,yAxis3D:d,zAxis3D:f,grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}},series:[{type:"bar3D",wireframe:{},data:h.map(M=>[M[g.columnKey],M[y.columnKey],M[C.columnKey]])}]};return t?i(Be,{width:r,height:a,children:i(Ae,{echarts:ie,option:D,style:on(r,a),notMerge:!0,theme:"merico-light"})}):null}const fs=m.createContext(null),Dr=fs.Provider;function Ir(){const e=m.useContext(fs);if(!e)throw new Error("Please use DashboardModelContextProvider");return e}const ue=()=>Ir(),Mr=()=>Ir(),gs=m.createContext({searchButtonProps:{}}),Ar=gs.Provider;function ms(){return m.useContext(gs)}const ys=m.createContext(null),zr=ys.Provider;function bs(){const e=m.useContext(ys);if(!e)throw new Error("Please use ContentModelContextProvider");return e}const le=()=>bs(),ye=()=>bs(),Mc={inEditMode:!1},zn=m.createContext(Mc),vs=m.createContext({panel:null,data:{},loading:!1,errors:[],downloadPanelScreenshot:()=>{}}),Er=vs.Provider;function xs(){const e=m.useContext(vs);if(!e.panel)throw new Error("Please use PanelContextProvider");return e}const Ct=()=>xs(),Qe=()=>xs(),Ac={fullScreenPanelID:"",setFullScreenPanelID:x.noop},$r=m.createContext(Ac);function ws(){const e=m.useContext($r);if(!e)throw new Error("Please use FullScreenPanelContext.Provider");return e}const W=k.observer(m.forwardRef(({label:e,required:t,value:n,onChange:r,clearable:a=!1,sx:o,...l},u)=>{const{panel:c}=Qe(),d=m.useMemo(()=>{const f=[...c.dataFieldOptions];return a&&f.unshift({label:"unset",value:"",group:""}),f},[c.dataFieldOptions]);return i(s.Select,{ref:u,label:e,data:d,value:n,onChange:r,required:t,sx:o,maxDropdownHeight:500,...l})}));function zc({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=x.defaults({},t,Tr),{control:a,handleSubmit:o,reset:l}=v.useForm({defaultValues:r});return m.useEffect(()=>{l(r)},[t]),t?i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[i(s.Text,{children:"X Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"x_axis_data_key",control:a,render:({field:u})=>i(W,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"xAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Text,{mt:"lg",children:"Y Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"y_axis_data_key",control:a,render:({field:u})=>i(W,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"yAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Text,{mt:"lg",children:"Z Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"z_axis_data_key",control:a,render:({field:u})=>i(W,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"zAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:p(s.Button,{color:"blue",type:"submit",children:[i(I.DeviceFloppy,{size:20}),i(s.Text,{ml:"md",children:"Save"})]})})]})}):null}function Ec(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis_data_key:a,y_axis_data_key:o,z_axis_data_key:l,...u}=e;return{...u,x_axis_data_key:r(a),y_axis_data_key:r(o),z_axis_data_key:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class $c extends ge{constructor(){super(...arguments);q(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:a}=n;return{...n,version:2,config:Ec(a,r)}})}}const Lc={displayName:"Bar Chart (3D)",displayGroup:"ECharts-based charts",migrator:new $c,name:"bar-3d",viewRender:Ic,configRender:zc,createConfig(){return{version:2,config:x.cloneDeep(Tr)}}};class Ee extends m.Component{constructor(t){super(t),this.state={error:null}}componentDidCatch(t){this.setState({error:t})}render(){var t;if(this.state.error){const n=()=>{this.setState({error:null})};return p(s.Box,{children:[i(s.Text,{size:"xs",children:(t=this.state.error)==null?void 0:t.message}),i(s.Button,{variant:"subtle",size:"xs",mx:"auto",compact:!0,sx:{display:"block"},onClick:n,children:"Retry"})]})}return this.props.children}}const De={mantissa:0,output:"number",trimMantissa:!1,average:!1};function Pc({value:e,onChange:t},n){const r=u=>{t({...e,output:u})},a=u=>{const c=u===0?!1:e.trimMantissa;t({...e,mantissa:u,trimMantissa:c})},o=u=>{t({...e,trimMantissa:u.currentTarget.checked})},l=u=>{t({...e,average:u.currentTarget.checked})};return p(s.Stack,{ref:n,children:[p(s.Group,{grow:!0,children:[i(s.Select,{label:"Format",data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:e.output,onChange:r,sx:{flexGrow:1}}),i(s.Switch,{label:p(s.Stack,{spacing:0,children:[i(s.Text,{children:"Average"}),i(s.Text,{size:12,color:"gray",children:"like 1.234k, 1.234m"})]}),checked:e.average,onChange:l,disabled:e.output!=="number",sx:{flexGrow:1},styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}}})]}),p(s.Group,{grow:!0,children:[i(s.NumberInput,{label:"Mantissa",defaultValue:0,min:0,step:1,max:4,value:e.mantissa,onChange:a}),i(s.Switch,{label:"Trim mantissa",checked:e.trimMantissa,onChange:o,disabled:e.mantissa===0,styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"}}})]}),p(s.Stack,{spacing:0,children:[i(s.Text,{weight:"bold",children:"Preview"}),i(Ee,{children:p(s.Group,{position:"apart",children:[p(s.Text,{size:12,color:"gray",children:["123456789 ",i(I.ArrowRight,{size:9})," ",Z(123456789).format(e)]}),p(s.Text,{size:12,color:"gray",children:["1234 ",i(I.ArrowRight,{size:9})," ",Z(1234).format(e)]}),p(s.Text,{size:12,color:"gray",children:["0.1234 ",i(I.ArrowRight,{size:9})," ",Z(.1234).format(e)]})]})})]})]})}const Ge=m.forwardRef(Pc),Ue={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
55
|
-
`)},
|
|
56
|
-
max-width: ${
|
|
54
|
+
`;function rr(t,e){const n=Object.keys(e),i=Object.values(e);try{return new Function(...n,`return \`${t}\`;`)(...i)}catch(a){throw n.length===0&&t.includes("$")?new Error("[formatSQL] insufficient payload"):a}}function ir(t,e){try{return rr(t,e)}catch(n){return console.error(n),n.message}}function Zu({sql:t,pre_process:e}){if(!e.trim())return t;try{return new Function(`return ${e}`)()({sql:t},mt)}catch(n){return console.error(n),t}}function Hu(t,e,n){if(!t.trim())return e;try{return new Function(`return ${t}`)()(e,mt,n)}catch(i){return console.error(i),e}}function ec(t){t=t||{};const e=Object.keys(t).sort(),n=[];for(let i=0;i<e.length;i++){const a=e[i];if(a!="authentication"&&t[a])n.push(e[i]+"="+(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 tc(t,e){let n=ec(t);return n+="&key="+e,Wu.MD5(n).toString().toUpperCase()}class ca{constructor(){this.type="default_api_client",this.baseURL="http://localhost:31200",this.app_id="",this.app_secret=""}getAuthentication(e){if(!this.app_id||!this.app_secret)return;const n=new Date().getTime().toString();return{app_id:this.app_id,nonce_str:n,sign:tc({app_id:this.app_id,nonce_str:n,...e},this.app_secret)}}getRequest(e,n){return(i,a,o,l)=>{const u=this.buildHeader(o),c=this.buildAxiosConfig(e,i,a,o,u,n);return nt(c).then(p=>l?p:p.data).catch(p=>Promise.reject(p))}}get(e){return this.getRequest("GET",e)}post(e){return this.getRequest("POST",e)}put(e){return this.getRequest("PUT",e)}buildAxiosConfig(e,n,i,a,o,l){const u={baseURL:this.baseURL,method:e,url:n,params:e==="GET"?i:a.params,headers:o,signal:l};return["POST","PUT"].includes(e)&&(u.data=a.string?JSON.stringify(i):i,u.data.authentication=this.getAuthentication(u.data)),u}buildHeader(e){const n=window.localStorage.getItem("token");return{"X-Requested-With":"XMLHttpRequest","Content-Type":e.string?"application/x-www-form-urlencoded":"application/json",authorization:n?`bearer ${n}`:"",...e.headers}}}class nc{constructor(e){this.implementation=e}getRequest(e,n){return this.implementation.getRequest(e,n)}get(e){return this.getRequest("GET",e)}post(e){return this.getRequest("POST",e)}put(e){return this.getRequest("PUT",e)}}class da extends ca{constructor(){super(...arguments);P(this,"makeQueryENV",null)}query(n){return async(i,a={})=>{var o;return i.env||(i.env=((o=this.makeQueryENV)==null?void 0:o.call(this))??{error:"failed to run makeQueryENV"}),this.post(n)("/query",i,a)}}httpDataSourceQuery(n){return async(i,a={})=>{var o;return i.env||(i.env=((o=this.makeQueryENV)==null?void 0:o.call(this))??{error:"failed to run makeQueryENV"}),this.getRequest("POST",n)("/query",i,a,!0)}}structure(n){return async(i,a={})=>this.post(n)("/query/structure",i,a)}}class pa{constructor(e){this.implementation=e}query(e){return this.implementation.query(e)}httpDataSourceQuery(e){return this.implementation.httpDataSourceQuery(e)}structure(e){return this.implementation.structure(e)}getRequest(e,n){return this.implementation.getRequest(e,n)}get(e){return this.getRequest("GET",e)}post(e){return this.getRequest("POST",e)}put(e){return this.getRequest("PUT",e)}}const kt=new da;function ar(t){kt.baseURL!==t.apiBaseURL&&(kt.baseURL=t.apiBaseURL),t.app_id&&(kt.app_id=t.app_id),t.app_secret&&(kt.app_secret=t.app_secret),t.makeQueryENV&&(kt.makeQueryENV=t.makeQueryENV)}const ha=new pa(kt),Xe=ha;function fa(){return{filters:{},context:{}}}function sr(t){const e=fa();if(!t)return fa();const{filters:n=e.filters,context:i=e.context}=t;return{filters:n,context:i}}async function rc({query:t,name:e,payload:n,additionals:i},a){if(!t.sql)return[];const{type:o,key:l,sql:u,pre_process:c,post_process:p}=t,h=rr(u,n),f=Zu({sql:h,pre_process:c});let g=await Xe.query(a)({type:o,key:l,query:f,...i},{params:{name:e}});return g=Hu(p,g,sr(n)),g}async function ic({type:t,key:e,configString:n,name:i,additionals:a},o){try{return await Xe.httpDataSourceQuery(o)({type:t,key:e,query:n,...a},{params:{name:i}})}catch(l){if(nt.isCancel(l))throw l;return console.error(l),l}}async function or(){try{return(await Xe.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 Xe.post()("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}},{})).data}catch(t){return console.error(t),[]}}class ma{constructor(e){P(this,"rootRef");this.rootRef=Q.observable({current:e})}async deleteItem(e){Q.runInAction(()=>{x.unset(this.rootRef.current,[e])})}getItem(e){const n=this.getValueFromRoot(e);return Promise.resolve(n)}getValueFromRoot(e){return e===null?Q.toJS(this.rootRef.current):x.get(this.rootRef.current,[e])}setItem(e,n){if(e===null)if(x.isObject(n))Q.runInAction(()=>{this.rootRef.current=n});else throw new Error("Cannot set root value to non-object");else Q.runInAction(()=>{x.set(this.rootRef.current,[e],n)});return Promise.resolve(this.getItem(e))}watchItem(e,n,i){return Q.reaction(()=>this.getValueFromRoot(e),(a,o)=>{n(a,o)},{requiresObservable:!0,fireImmediately:x.get(i,"fireImmediately",!1)})}}class ac{constructor(){P(this,"channels",new Map);P(this,"globalChannel",new Wi)}getChannel(e){const n=this.channels.get(e);if(n)return n;const i=new Wi;return this.channels.set(e,i),i}}class sc{constructor(e){P(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 i={id:e.id,name:e.viz.type,type:e.viz.type,messageChannels:new ac,instanceData:new ma(e.viz.conf)};return this.instances.set(e.id,i),i}}function ya(t,e,n,i){return{vizManager:n,locale:"zh",msgChannels:t.messageChannels,instanceData:t.instanceData,pluginData:new ma({}),colorPalette:{getColor(){return()=>""}},data:e,variables:i}}const oc=t=>{const{panel:e,vizManager:n,data:i,variables:a}=t,o=n.resolveComponent(e.viz.type),l=n.getOrCreateInstance(e),u={...ya(l,i,n,a),viewport:{width:e.layout.w,height:e.layout.h}},c=o.viewRender;return r(c,{context:u,instance:l,...x.omit(t,["panel","vizManager","data"])})},lc=t=>{const{vizManager:e,panel:n,data:i,variables:a}=t,o=e.resolveComponent(n.viz.type),l=e.getOrCreateInstance(n),u={...ya(l,i,e,a)},c=o.configRender;return r(c,{context:u,instance:l,...x.omit(t,["panel","vizManager","data"])})},ba=(t,e)=>{const n=rt.bezier(t),i=rt.bezier(e);return function(a){return a<50?n(a*2/100).hex():i((a-50)*2/100).hex()}},cn=t=>{const e=rt.bezier(t);return function(n){return e(n/100).hex()}},uc={type:"interpolation",displayName:"Red / Green",getColor:ba(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},cc={type:"interpolation",displayName:"Yellow / Blue",getColor:ba(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},dc={type:"interpolation",displayName:"Red",getColor:cn(["#fff7f1","darkred"]),name:"red",category:"sequential"},pc={type:"interpolation",displayName:"Green",getColor:cn(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},hc={type:"interpolation",displayName:"Blue",getColor:cn(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},fc={type:"interpolation",displayName:"Orange",getColor:cn(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class gc{constructor(e){P(this,"symbol");this.symbol=Symbol(e)}}function it(t){return new gc(t)}class lr{constructor(){P(this,"parent");P(this,"factoryRegistry",new Map);P(this,"instanceRegistry",new Map)}createScoped(){const e=new lr;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 i=n(this);return this.instanceRegistry.set(e.symbol,i),i}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 va="10.44.2",mc=Object.freeze(Object.defineProperty({__proto__:null,version:va},Symbol.toStringTag,{value:"Module"}));class yc{constructor(e){P(this,"staticColors",new Map);P(this,"interpolations",new Map);e.installedPlugins.forEach(n=>{n.manifest.color.forEach(i=>{this.register(i)})})}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 bc{constructor(){P(this,"plugins",new Map);P(this,"vizComponents",new Map);P(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())}}class vc{constructor(){P(this,"migrations",[])}version(e,n){return this.migrations.push({version:e,handler:n}),this}run(e,n,i){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,i),n)}}class se extends vc{constructor(){super(),this.configVersions()}version(e,n){return super.version(e,(i,a)=>({version:e,...n(i,a)}))}async migrate({configData:e,panelModel:n}){const i=await e.getItem(null),a=x.get(i,"version",0),o=this.run({from:a,to:this.VERSION},i,{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}}const V=(t,e)=>{const[n,{setFalse:i}]=q.useBoolean(!0),[a,o]=m.useState();m.useEffect(()=>(t.getItem(e).then(u=>{o(u),i()}),t.watchItem(e,u=>{o(u)})));const l=m.useCallback(async u=>{await t.setItem(e,u),o(u)},[t,e]);return{loading:n,value:a,set:l}},Ie={top:16,right:16,bottom:16,left:16},Re=t=>Math.max(0,t-Ie.left-Ie.right),Qe=t=>Math.max(0,t-Ie.top-Ie.bottom),jt=(t,e)=>({width:Re(t),height:Qe(e)}),Me=({width:t,height:e,children:n})=>r(s.Box,{pt:Ie.top,pr:Ie.right,pb:Ie.bottom,pl:Ie.left,sx:{width:t,height:e,overflow:"hidden",position:"relative"},children:n});function A(t){const[e,n]=t.split(".");return{queryID:e,columnKey:n}}function xc(t){return t.includes(".")?A(t):{queryID:"",columnKey:t}}function at(t,e){var a;const{queryID:n,columnKey:i}=A(e);return n?i?((a=t[n])==null?void 0:a.map(o=>o[i]))??[]:t[n]:[]}function Wt(t,e){const{queryID:n}=A(e);return n?t[n]:[]}function wc(t){return Object.values(t)[0]}function dn(t,e){const{queryID:n,columnKey:i}=A(e);return t[i]}const ur={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"}};Y.use([B.GridComponent,B.VisualMapComponent,B.LegendComponent,B.TooltipComponent,_e.CanvasRenderer]);function Cc({context:t}){const{value:e}=V(t.instanceData,"config"),n=t.data,{width:i,height:a}=t.viewport,{x_axis_data_key:o,y_axis_data_key:l,z_axis_data_key:u,xAxis3D:c,yAxis3D:p,zAxis3D:h}=x.defaults({},e,ur),f=m.useMemo(()=>Wt(n,o),[n,o]),{x:g,y:b,z:w}=m.useMemo(()=>({x:A(o),y:A(l),z:A(u)}),[o,l,u]),{min:_,max:D}=m.useMemo(()=>{const N=x.minBy(f,ae=>ae[w.columnKey]),J=x.maxBy(f,ae=>ae[w.columnKey]);return{min:x.get(N,w.columnKey),max:x.get(J,w.columnKey)}},[f,w]),L={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:_,max:D,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:c,yAxis3D:p,zAxis3D:h,grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}},series:[{type:"bar3D",wireframe:{},data:f.map(N=>[N[g.columnKey],N[b.columnKey],N[w.columnKey]])}]};return e?r(Me,{width:i,height:a,children:r(Se,{echarts:Y,option:L,style:jt(i,a),notMerge:!0,theme:"merico-light"})}):null}const xa=m.createContext(null),cr=xa.Provider;function dr(){const t=m.useContext(xa);if(!t)throw new Error("Please use DashboardModelContextProvider");return t}const ee=()=>dr(),pr=()=>dr(),wa=m.createContext({searchButtonProps:{}}),hr=wa.Provider;function Ca(){return m.useContext(wa)}const Sa=m.createContext(null),fr=Sa.Provider;function _a(){const t=m.useContext(Sa);if(!t)throw new Error("Please use ContentModelContextProvider");return t}const H=()=>_a(),ue=()=>_a(),Sc={inEditMode:!1},pn=m.createContext(Sc),ka=m.createContext({panel:null,data:{},loading:!1,errors:[],downloadPanelScreenshot:()=>{}}),gr=ka.Provider;function Ta(){const t=m.useContext(ka);if(!t.panel)throw new Error("Please use PanelContextProvider");return t}const dt=()=>Ta(),$e=()=>Ta(),_c={fullScreenPanelID:"",setFullScreenPanelID:x.noop},mr=m.createContext(_c);function Da(){const t=m.useContext(mr);if(!t)throw new Error("Please use FullScreenPanelContext.Provider");return t}const O=k.observer(m.forwardRef(({label:t,required:e,value:n,onChange:i,clearable:a=!1,sx:o,...l},u)=>{const{panel:c}=$e(),p=m.useMemo(()=>{const h=[...c.dataFieldOptions];return a&&h.unshift({label:"unset",value:"",group:""}),h},[c.dataFieldOptions]);return r(s.Select,{ref:u,label:t,data:p,value:n,onChange:i,required:e,sx:o,maxDropdownHeight:500,...l})}));function kc({context:t}){const{value:e,set:n}=V(t.instanceData,"config"),i=x.defaults({},e,ur),{control:a,handleSubmit:o,reset:l}=v.useForm({defaultValues:i});return m.useEffect(()=>{l(i)},[e]),e?r(s.Stack,{spacing:"xs",children:d("form",{onSubmit:o(n),children:[r(s.Text,{children:"X Axis"}),d(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[r(v.Controller,{name:"x_axis_data_key",control:a,render:({field:u})=>r(O,{label:"Data Field",required:!0,...u})}),r(v.Controller,{name:"xAxis3D.name",control:a,render:({field:u})=>r(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),r(s.Text,{mt:"lg",children:"Y Axis"}),d(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[r(v.Controller,{name:"y_axis_data_key",control:a,render:({field:u})=>r(O,{label:"Data Field",required:!0,...u})}),r(v.Controller,{name:"yAxis3D.name",control:a,render:({field:u})=>r(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),r(s.Text,{mt:"lg",children:"Z Axis"}),d(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[r(v.Controller,{name:"z_axis_data_key",control:a,render:({field:u})=>r(O,{label:"Data Field",required:!0,...u})}),r(v.Controller,{name:"zAxis3D.name",control:a,render:({field:u})=>r(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),r(s.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:d(s.Button,{color:"blue",type:"submit",children:[r(T.DeviceFloppy,{size:20}),r(s.Text,{ml:"md",children:"Save"})]})})]})}):null}function Tc(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=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:i(a),y_axis_data_key:i(o),z_axis_data_key:i(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class Dc extends se{constructor(){super(...arguments);P(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,i)=>{const{config:a}=n;return{...n,version:2,config:Tc(a,i)}})}}const Ic={displayName:"Bar Chart (3D)",displayGroup:"ECharts-based charts",migrator:new Dc,name:"bar-3d",viewRender:Cc,configRender:kc,createConfig(){return{version:2,config:x.cloneDeep(ur)}}};class ke extends m.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 d(s.Box,{children:[r(s.Text,{size:"xs",children:(e=this.state.error)==null?void 0:e.message}),r(s.Button,{variant:"subtle",size:"xs",mx:"auto",compact:!0,sx:{display:"block"},onClick:n,children:"Retry"})]})}return this.props.children}}const xe={mantissa:0,output:"number",trimMantissa:!1,average:!1};function Mc({value:t,onChange:e},n){const i=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 d(s.Stack,{ref:n,children:[d(s.Group,{grow:!0,children:[r(s.Select,{label:"Format",data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:t.output,onChange:i,sx:{flexGrow:1}}),r(s.Switch,{label:d(s.Stack,{spacing:0,children:[r(s.Text,{children:"Average"}),r(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"}}})]}),d(s.Group,{grow:!0,children:[r(s.NumberInput,{label:"Mantissa",defaultValue:0,min:0,step:1,max:4,value:t.mantissa,onChange:a}),r(s.Switch,{label:"Trim mantissa",checked:t.trimMantissa,onChange:o,disabled:t.mantissa===0,styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"}}})]}),d(s.Stack,{spacing:0,children:[r(s.Text,{weight:"bold",children:"Preview"}),r(ke,{children:d(s.Group,{position:"apart",children:[d(s.Text,{size:12,color:"gray",children:["123456789 ",r(T.ArrowRight,{size:9})," ",W(123456789).format(t)]}),d(s.Text,{size:12,color:"gray",children:["1234 ",r(T.ArrowRight,{size:9})," ",W(1234).format(t)]}),d(s.Text,{size:12,color:"gray",children:["0.1234 ",r(T.ArrowRight,{size:9})," ",W(.1234).format(t)]})]})})]})]})}const Pe=m.forwardRef(Mc),Ve={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
55
|
+
`)},Ia={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:zc,configRender:Ac,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 Ac(t){return r(z,{})}function zc(t){return r(s.Text,{children:"Click chart's series"})}const Ec=[{label:"Truncate",value:"truncate"},{label:"Break Line",value:"break"},{label:"Break Word",value:"breakAll"}],hn=m.forwardRef(({sectionTitle:t,value:e,onChange:n},i)=>{const a=o=>l=>{const u=x.cloneDeep(e);x.set(u,o,l),n(u)};return d(s.Stack,{spacing:0,children:[t&&r(s.Divider,{mb:-5,mt:5,variant:"dotted",label:t,labelPosition:"right",labelProps:{color:"dimmed"}}),d(s.Group,{grow:!0,noWrap:!0,children:[r(s.NumberInput,{label:"Max Width",hideControls:!0,value:e.width,onChange:a("width")}),r(s.Select,{label:"Overflow",data:Ec,value:e.overflow,onChange:a("overflow")}),r(s.TextInput,{label:"Ellipsis",value:e.ellipsis,disabled:!0})]})]})}),Je=m.forwardRef(({value:t,onChange:e},n)=>{const i=o=>{e({...t,on_axis:o})},a=o=>{e({...t,in_tooltip:o})};return d(s.Stack,{ref:n,spacing:0,children:[r(hn,{sectionTitle:"Overflow on Axis",value:t.on_axis,onChange:i}),r(hn,{sectionTitle:"Overflow in Tooltip",value:t.in_tooltip,onChange:a})]})}),Le={on_axis:{width:80,overflow:"truncate",ellipsis:"..."},in_tooltip:{width:200,overflow:"break",ellipsis:"..."}};function Ze({overflow:t,width:e}){const n={truncate:"initial",break:"break-all",breakAll:"break-word"}[t],i=t==="truncate"?"nowrap":"initial",a={truncate:"ellipsis",break:"clip",breakAll:"clip"}[t];return`
|
|
56
|
+
max-width: ${e}px;
|
|
57
57
|
word-break: ${n};
|
|
58
|
-
white-space: ${
|
|
58
|
+
white-space: ${i};
|
|
59
59
|
overflow: hidden;
|
|
60
60
|
text-overflow: ${a};
|
|
61
|
-
`}function rt(e){return{width:e.width,overflow:e.overflow,ellipsis:e.ellipsis}}const Lr={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...Ue},overflow:We}},y_axis:{name:"Y Axis",data_key:"value",label_formatter:De},tooltip:{metrics:[]},color:"#228be6",reference_lines:[],legend:{show:!0,top:"10",right:"0",left:"auto",bottom:"auto",orient:"vertical",type:"scroll"}};function zt(e,t){return m.useMemo(()=>{const{queryID:n,columnKey:r}=P(t);return x.keyBy(e[n],r)},[e,t])}const Ke=(e,t)=>{const[n,r]=m.useState([]);return m.useEffect(()=>e.watchTriggerSnapshotList(a=>r(a.filter(o=>o.schemaRef===t))),[]),n};class qt{constructor(t,n){this.root=t,this.path=n}async deleteItem(t){t===null&&await this.root.deleteItem(this.path);const n=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,x.omit(n,t))}async getItem(t){const n=await this.root.getItem(this.path);return t===null?n:x.get(n,t)}async setItem(t,n){if(t===null)await this.root.setItem(this.path,n);else{const r=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,{...r,[t]:n})}return await this.getItem(t)}watchItem(t,n,r){return t===null?this.root.watchItem(this.path,(a,o)=>{n(a,o)},r):this.root.watchItem(this.path,(a,o)=>{const l=x.get(a,t),u=x.get(o,t);l!==u&&n(l,u)},r)}}class Pr{constructor(t,n,r){q(this,"attachmentStorage");this.instance=t,this.attachmentKey=n,this.constructInstance=r,this.attachmentStorage=new qt(t.instanceData,n)}async getInstance(t){if(await this.attachmentStorage.getItem(t))return this.constructInstance(new qt(this.attachmentStorage,t))}async create(t,n){return await this.attachmentStorage.setItem(t,n),this.constructInstance(new qt(this.attachmentStorage,t))}async remove(t){await this.attachmentStorage.deleteItem(t)}async list(){const t=await this.attachmentStorage.getItem(null);return Promise.all(x.values(t).map(n=>this.constructInstance(new qt(this.attachmentStorage,n.id))))}}function Nc(e,t){const{value:n,set:r}=R(e.operation.operationData,"config"),[a,o]=m.useState(x.defaults({},n,t)),l=async()=>{await r(a)};return m.useEffect(()=>{o(x.defaults({},n,t))},[n]),{config:a,setConfig:o,commit:l}}function qc(e){const{config:t,setConfig:n,commit:r}=Nc(e,{urlTemplate:"",openInNewTab:!0});async function a(){await r()}async function o(u){n({...t,openInNewTab:u}),await r()}const l=u=>n({...t,urlTemplate:u.currentTarget.value});return p(s.Stack,{children:[i(s.TextInput,{label:"Url",value:t.urlTemplate,onChange:l,onBlur:a}),i(s.Switch,{label:"Open in new Tab",checked:t.openInNewTab,onChange:u=>o(u.currentTarget.checked)})]})}async function Fc(e,t){const{urlTemplate:n,openInNewTab:r}=await t.operationData.getItem("config");window.dispatchEvent(new CustomEvent("open-link",{detail:{urlTemplate:n,openInNewTab:r,payload:e}}))}class Gc extends ge{constructor(){super(...arguments);q(this,"VERSION",1)}configVersions(){this.version(1,n=>n)}}const Wc={displayName:"Open Link",id:"builtin:op:open-link",configRender:qc,run:Fc,migrator:new Gc,createDefaultConfig:()=>({version:1,config:{urlTemplate:"",openInNewTab:!0}})};function jc(e){const{value:t,set:n}=R(e.operationData,"config"),r=a=>void n({template:a});return[(t==null?void 0:t.template)||"",r]}function Rc(e){const[t,n]=jc(e.operation);return i(s.TextInput,{defaultValue:t,onBlur:r=>n(r.currentTarget.value),label:"console.log"})}async function Yc(e,t){const n=await t.operationData.getItem("config"),r=x.template(n.template||"");console.log("run with payload",e),console.log(r(e))}const Qc={displayName:"console.log (debug)",id:"builtin:op:debug",configRender:Rc,run:Yc},Uc=k.observer(e=>{const t=le(),{value:n,set:r}=R(e.operation.operationData,"config");console.log({value:n,viewID:n==null?void 0:n.viewID});const a=(n==null?void 0:n.viewID)||"",o=l=>void r({viewID:l});return i(s.Select,{defaultValue:a,value:a,onChange:o,label:"View",data:t.views.options,withinPortal:!0,zIndex:340,maxDropdownHeight:500})});async function Kc(e,t){const r=(await t.operationData.getItem("config")).viewID;window.dispatchEvent(new CustomEvent("open-view",{detail:{viewID:r}}))}const Xc={displayName:"Open View",id:"builtin:op:open_view",configRender:Uc,run:Kc},Jc={"tbody tr":{opacity:.5,transition:"opacity 200ms ease"},"tr[data-affected=true]":{opacity:1}},Zc=({value:e="",onChange:t})=>{const[n,r]=m.useState(e);m.useEffect(()=>{r(e)},[e]);const a=()=>{t(n)};return i(s.TextInput,{size:"xs",label:"",value:n,onChange:o=>r(o.currentTarget.value),sx:{flexGrow:1},rightSection:i(s.ActionIcon,{color:"green",size:"xs",onClick:a,disabled:n===e,children:i(E.IconDeviceFloppy,{})})})},Hc={dictionary:{}},ed=k.observer(e=>{const t=le(),{value:n=Hc,set:r}=R(e.operation.operationData,"config"),{dictionary:a={}}=n;console.log({value:{...n},dictionary:{...a},filters:[...t.filters.keyLabelOptions]});const o=(l,u)=>{if(u===""){const c={...a};delete c[l],r({dictionary:c});return}r({dictionary:{...a,[l]:u}})};return p(s.Table,{sx:Jc,children:[i("thead",{children:p("tr",{children:[i("th",{children:"Set filter"}),i("th",{children:"with"})]})}),i("tbody",{children:[...t.filters.keyLabelOptions].map(l=>{const u=l.value in a;return p("tr",{"data-affected":u,children:[i("td",{children:l.label}),i("td",{children:i(Zc,{value:a[l.value],onChange:c=>o(l.value,c)})})]},l.value)})})]})});async function td(e,t){const r=(await t.operationData.getItem("config")).dictionary;window.dispatchEvent(new CustomEvent("set-filter-values",{detail:{dictionary:r,payload:e}}))}const nd={displayName:"Set Filter Values",id:"builtin:op:set_filter_values",configRender:ed,run:td},rd={filter_keys:[]},id=k.observer(e=>{const t=le(),{value:n=rd,set:r}=R(e.operation.operationData,"config"),{filter_keys:a=[]}=n,o=u=>{r({filter_keys:[...u]})},l=m.useMemo(()=>t.filters.current.map(u=>({label:u.label,value:u.key})),[t.filters.values]);return i(s.Stack,{spacing:10,children:i(s.MultiSelect,{label:"Select Filters to Clear",data:l,value:a,onChange:o})})});async function ad(e,t){const r=(await t.operationData.getItem("config")).filter_keys;window.dispatchEvent(new CustomEvent("clear-filter-values",{detail:{filter_keys:r,payload:e}}))}const $n=[Qc,Wc,Xc,nd,{displayName:"Clear Filter Values",id:"builtin:op:clear_filter_values",configRender:id,run:ad}];class sd{constructor(t,n=$n){q(this,"attachments");this.operations=n;const r=async a=>{const{id:o,schemaRef:l}=await a.getItem(null);return{id:o,schemaRef:l,operationData:new qt(a,"data")}};this.attachments=new Pr(t,"__OPERATIONS",r)}async runOperation(t,n){const r=await this.attachments.getInstance(t);if(!r){console.warn(`Operation '${t}' is not defined`);return}const a=this.tryGetSchema(r.schemaRef);if(!a){console.warn(`Operation schema '${r.schemaRef}' is not defined`);return}await a.run(n,r)}tryGetSchema(t){return this.operations.find(n=>n.id===t)}async needMigration(){const n=(await this.attachments.list()).map(async r=>{const a={configData:r.operationData},o=this.tryGetSchema(r.schemaRef),l=o==null?void 0:o.migrator;return l&&await l.needMigration(a)});return(await Promise.all(n)).some(r=>r)}async runMigration(){const n=(await this.attachments.list()).map(async r=>{const a={configData:r.operationData},o=this.tryGetSchema(r.schemaRef),l=o==null?void 0:o.migrator;l&&await l.needMigration(a)&&await l.migrate(a)});await Promise.all(n)}async createOrGetOperation(t,n){var l;if(!this.getOperationSchemaList().some(u=>u.id===n.id))throw new Error(`Operation schema '${n.id}' is not defined`);const a=await this.attachments.getInstance(t);return!a||a.schemaRef!==n.id?await this.attachments.create(t,{id:t,schemaRef:n.id,data:((l=n.createDefaultConfig)==null?void 0:l.call(n))??{}}):a}getOperationList(){return this.attachments.list()}getOperationSchemaList(){return this.operations}removeOperation(t){return this.attachments.remove(t)}async retrieveTrigger(t){return await this.attachments.getInstance(t)}}const Ss="__TRIGGERS";class od{constructor(t,n){q(this,"attachments");this.instance=t,this.component=n;const r=async a=>{const{id:o,schemaRef:l}=await a.getItem(null);return{id:o,schemaRef:l,triggerData:new qt(a,"data")}};this.attachments=new Pr(t,Ss,r)}watchTriggerSnapshotList(t){return this.instance.instanceData.watchItem(Ss,n=>{const r=x.values(n).map(a=>({id:x.get(a,"id"),schemaRef:x.get(a,"schemaRef"),config:te.toJS(x.get(a,"data.config"))}));t(r)},{fireImmediately:!0})}async createOrGetTrigger(t,n,r={recreate:!1}){var u;if(!this.getTriggerSchemaList().some(c=>c.id===n.id))throw new Error(`Trigger schema '${n.id}' is not defined in component '${this.component.name}'`);const o=await this.attachments.getInstance(t);return!o||r.recreate||o.schemaRef!==n.id?await this.attachments.create(t,{id:t,schemaRef:n.id,data:((u=n==null?void 0:n.createDefaultConfig)==null?void 0:u.call(n))||{}}):o}async getTriggerList(){return await this.attachments.list()}getTriggerSchemaList(){return this.component.triggers||[]}async removeTrigger(t){await this.attachments.remove(t)}async retrieveTrigger(t){return await this.attachments.getInstance(t)}async getMigrationTasks(){const n=(await this.getTriggerList()).map(async r=>{const a=this.getTriggerSchemaList().find(u=>u.id===r.schemaRef),o=a==null?void 0:a.migrator,l={configData:r.triggerData};return o&&await o.needMigration(l)?()=>o.migrate(l):null});return Promise.all(n).then(r=>r.filter(a=>a))}async needMigration(){return(await this.getMigrationTasks()).length>0}async runMigration(){const t=await this.getMigrationTasks();await Promise.all(t.map(n=>n()))}}class Or{constructor(t,n,r){q(this,"operationManager");q(this,"triggerManager");q(this,"attachments");this.operationManager=new sd(t,r),this.triggerManager=new od(t,n);const a=async o=>{const{id:l,triggerRef:u,operationRef:c}=await o.getItem(null);return{id:l,triggerRef:u,operationRef:c}};this.attachments=new Pr(t,"__INTERACTIONS",a)}async addInteraction(t,n){const r=t.id,a=n.id,o=`[${r}]:[${a}]`;await this.attachments.create(o,{id:o,triggerRef:r,operationRef:a})}getInteractionList(){return this.attachments.list()}async removeInteraction(t){const n=await this.attachments.getInstance(t);if(!n)return;const{triggerRef:r,operationRef:a}=n;await this.getTriggerRefCount(r)<=1&&await this.triggerManager.removeTrigger(r),await this.getOperationRefCount(a)<=1&&await this.operationManager.removeOperation(a),await this.attachments.remove(t)}async getOperationRefCount(t){return(await this.getInteractionList()).filter(r=>r.operationRef===t).length}async getTriggerRefCount(t){return(await this.getInteractionList()).filter(r=>r.triggerRef===t).length}async runInteraction(t,n){const a=(await this.getInteractionList()).filter(o=>o.triggerRef===t);await Promise.all(a.map(async o=>{try{return await this.operationManager.runOperation(o.operationRef,n)}catch(l){console.warn(`Failed to run operation '${o.operationRef}'`,l)}}))}}const Xe=({vizManager:e,instance:t})=>Q.useCreation(()=>new Or(t,e.resolveComponent(t.type),$n),[t,e]),_s=e=>{const{title:t="Variables",variables:n}=e,r=_e.useClipboard(),a=o=>{r.copy(o),Tn.showNotification({color:"green",message:"Copied to clipboard"})};return p(s.Paper,{withBorder:!0,p:"sm",children:[i(s.Text,{size:"xs",color:"dimmed",mb:"sm",children:t}),i(s.Stack,{style:{maxHeight:"500px"},children:n.map(o=>p(s.Text,{size:"sm",children:[p(s.Code,{color:"teal",children:["// ",o.description]}),i("br",{}),p(s.Code,{onClick:()=>a(o.name),style:{cursor:"pointer"},children:[o.name," : ",o.valueType]})]},o.name))})]})};class ld{constructor(t,n){q(this,"operationId");q(this,"operation");q(this,"operationSchema");q(this,"variables",[]);this.operationManager=t,this.instance=n,te.makeAutoObservable(this)}get schemaList(){return this.operationManager.getOperationSchemaList()}async configOperation(t,n){const r=await this.operationManager.retrieveTrigger(t),a=this.operationManager.getOperationSchemaList().find(o=>o.id===(r==null?void 0:r.schemaRef));te.runInAction(()=>{this.operationId=t,this.operation=r,this.operationSchema=a,this.variables=n})}async changeSchema(t){this.operationId&&(await this.operationManager.createOrGetOperation(this.operationId,t),await this.configOperation(this.operationId,this.variables))}}function ud(e){return!!e.operationId}const cd=k.observer(({model:e,onClick:t})=>{var r;const n=(r=e.operationSchema)==null?void 0:r.displayName;return i(s.Button,{variant:"outline",onClick:t,children:n})}),dd=k.observer(({model:e})=>{const t={operation:e.operation,instance:e.instance,variables:[]};return m.createElement(e.operationSchema.configRender,t)}),pd=k.observer(({model:e})=>{const t=e.schemaList,n=t.map(a=>({label:a.displayName,value:a.id}));async function r(a){await e.changeSchema(t.find(o=>o.id===a))}return i(s.Select,{label:"Operation",data:n,onChange:r,value:e.operationSchema.id,withinPortal:!0,zIndex:340})}),hd=k.observer(e=>{const[t,{setTrue:n,setFalse:r}]=Q.useBoolean(!1),{operationManager:a,operationId:o,instance:l,variables:u}=e,c=Q.useCreation(()=>new ld(a,l),[a,l]);return Q.useAsyncEffect(async()=>{await c.configOperation(o,u)},[o,c]),ud(c)?p(B,{children:[i(cd,{model:c,onClick:n}),i(s.Modal,{size:600,opened:t,onClose:r,title:"Operation Settings",zIndex:320,children:p(s.Stack,{children:[i(pd,{model:c}),p(s.Tabs,{defaultValue:"settings",children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"settings",children:"Settings"}),i(s.Tabs.Tab,{value:"variables",children:"Variables"})]}),i(s.Tabs.Panel,{value:"settings",pt:10,children:i(dd,{model:c})}),i(s.Tabs.Panel,{value:"variables",pt:10,children:i(_s,{title:"Variables",variables:c.variables})})]})]})})]}):null});class fd{constructor(t,n){q(this,"triggerId");q(this,"trigger");q(this,"triggerSchema");q(this,"sampleData");this.triggerManager=t,this.instance=n,te.makeAutoObservable(this)}get schemaList(){return this.triggerManager.getTriggerSchemaList()}async configTrigger(t,n){const r=await this.triggerManager.retrieveTrigger(t),a=this.triggerManager.getTriggerSchemaList().find(o=>o.id===(r==null?void 0:r.schemaRef));te.runInAction(()=>{this.triggerId=t,this.trigger=r,this.triggerSchema=a,this.sampleData=n})}async changeSchema(t){this.triggerId&&(await this.triggerManager.createOrGetTrigger(this.triggerId,t),await this.configTrigger(this.triggerId,this.sampleData))}isReady(){return gd(this)}}function gd(e){return!!e.triggerId&&!!e.triggerSchema}function md(e,t){return Q.useCreation(()=>new fd(e,t),[e,t])}const yd=k.observer(({model:e,onClick:t})=>{const n=e.triggerSchema.nameRender,r={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return i(s.Button,{variant:"outline",onClick:t,children:m.createElement(n,r)})}),bd=k.observer(({model:e})=>{const t=e.schemaList,n=t.map(a=>({label:a.displayName,value:a.id}));async function r(a){await e.changeSchema(t.find(o=>o.id===a))}return i(s.Select,{label:"Trigger",data:n,value:e.triggerSchema.id,onChange:r})}),vd=k.observer(({model:e})=>{const t={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return m.createElement(e.triggerSchema.configRender,t)}),xd=k.observer(e=>{const[t,{setTrue:n,setFalse:r}]=Q.useBoolean(!1),a=e.model;return p(B,{children:[i(s.Modal,{opened:t,onClose:r,title:"Setup Trigger",zIndex:320,children:p(s.Stack,{children:[i(bd,{model:a}),i(vd,{model:a}),i(_s,{title:"Payload",variables:a.triggerSchema.payload})]})}),i(yd,{onClick:n,model:a})]})});function wd(e,t){const[n,r]=m.useState([]);return Q.useAsyncEffect(async()=>{const a=await e.getInteractionList();r(a)},[t,e]),n}const Cd=k.observer(({item:e,manager:t,instance:n,sampleData:r,variables:a,onRemove:o})=>{const{triggerRef:l,operationRef:u}=e,c=md(t.triggerManager,n);if(Q.useAsyncEffect(async()=>{await c.configTrigger(l,r)},[c,l,r]),c.isReady()){const d=[...c.triggerSchema.payload,...a];return p(s.Group,{children:[i(xd,{model:c}),i(hd,{instance:n,operationId:u,variables:d,operationManager:t.operationManager}),i(s.ActionIcon,{"aria-label":"delete-interaction",variant:"filled",color:"red",onClick:()=>o(e),children:i(I.Trash,{size:16})})]})}return null}),Sd=e=>{const[t,n]=m.useState(0),{interactionManager:r,instance:a,sampleData:o,variables:l}=e,u=wd(r,t),c=async()=>{const g=await r.triggerManager.createOrGetTrigger(_e.randomId(),r.triggerManager.getTriggerSchemaList()[0]),y=await r.operationManager.createOrGetOperation(_e.randomId(),r.operationManager.getOperationSchemaList()[0]);await r.addInteraction(g,y),n(C=>C+1)};async function d(g){await r.removeInteraction(g.id),n(y=>y+1)}const{data:f=0,loading:h}=Q.useRequest(async()=>{try{return(await r.triggerManager.getTriggerSchemaList()).length}catch{return 0}});return p(s.Stack,{children:[i(s.LoadingOverlay,{visible:h}),f===0&&i(s.Alert,{icon:i(I.AlertCircle,{size:16}),title:"Unavailable",color:"gray",children:"This visualization does not have available interactions to choose from"}),u.map(g=>i(Cd,{onRemove:d,instance:a,sampleData:o,variables:l,item:g,manager:e.interactionManager},g.id)),i(s.Button,{style:{width:"fit-content"},onClick:()=>c(),disabled:f===0,children:"Add interaction"})]})},_d=()=>{const{panel:e,data:t}=Ct(),n=e.viz,{vizManager:r}=m.useContext(ct),a=e.json,o=Q.useCreation(()=>r.getOrCreateInstance(a),[r,a]),l=Q.useCreation(()=>new Or(o,r.resolveComponent(n.type),$n),[o,n.type]);return m.useEffect(()=>o.instanceData.watchItem(null,x.throttle(u=>{e.viz.setConf(u)},100,{leading:!1,trailing:!0})),[o]),{instance:o,vizManager:r,interactionManager:l,sampleData:t,variables:[]}},kd=()=>{const e=_d();return i(Sd,{...e})};function Ft({enabled:e,func_content:t}){return(n,r)=>{if(!e)return n;try{return new Function(`return ${t}`)()(n,r)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function Td(e,t){return Object.entries(e).map(([r,a])=>{const o=a.map(_=>_[t]).sort((_,D)=>_-D),l=tn.quantile(o,.25)??0,u=tn.quantile(o,.5)??0,c=tn.quantile(o,.75)??0,d=c-l,f=l-1.5*d,h=c+1.5*d,g=Math.max(o[0],f),y=Math.min(x.last(o)??0,h),C=a.filter(_=>{const D=_[t];return D<g||D>y}).map(_=>[r,_[t],_]);return{name:r,min:g,q1:l,median:u,q3:c,max:y,outliers:C}})}function Dd(e,t){const{x_axis:n,y_axis:r}=e;if(!n.data_key||!r.data_key)return[];const a=P(n.data_key),o=P(r.data_key);if(a.queryID!==o.queryID)throw new Error("Please use the same query for X & Y axis");const l=x.groupBy(t[a.queryID],a.columnKey),u=Td(l,o.columnKey),c=u.map(d=>d.outliers).flat();return[{source:u},{source:c}]}function Id({config:e}){return{...e.legend,data:[{name:"Box",icon:"roundRect",itemStyle:{color:e.color}},{name:"Outlier",icon:"circle",itemStyle:{color:"#2F8CC0"}}]}}const Br=["max","q3","median","q1","min"];function Md(e){const{color:t}=e;return[{name:"Box",type:"boxplot",itemStyle:{color:t,borderColor:"#2F8CC0",borderWidth:2},emphasis:{disabled:!0},boxWidth:[10,40],datasetIndex:0,encode:{y:Br,x:"name",itemName:["name"],tooltip:Br}},{name:"Outlier",type:"scatter",symbolSize:5,itemStyle:{color:"#2F8CC0"},emphasis:{scale:2},datasetIndex:1}]}function Ad(e){const{outliers:t,min:n,max:r}=e,a=t.filter(u=>u[1]<n).length,o=t.filter(u=>u[1]>r).length,l=(u,c)=>`
|
|
61
|
+
`}function Ue(t){return{width:t.width,overflow:t.overflow,ellipsis:t.ellipsis}}const yr={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...Ve},overflow:Le}},y_axis:{name:"Y Axis",data_key:"value",label_formatter:xe},tooltip:{metrics:[]},color:"#228be6",reference_lines:[],legend:{show:!0,top:"10",right:"0",left:"auto",bottom:"auto",orient:"vertical",type:"scroll"}};function yt(t,e){return m.useMemo(()=>{const{queryID:n,columnKey:i}=A(e);return x.keyBy(t[n],i)},[t,e])}const Ne=(t,e)=>{const[n,i]=m.useState([]);return m.useEffect(()=>t.watchTriggerSnapshotList(a=>i(a.filter(o=>o.schemaRef===e))),[]),n};class Tt{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 i=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,{...i,[e]:n})}return await this.getItem(e)}watchItem(e,n,i){return e===null?this.root.watchItem(this.path,(a,o)=>{n(a,o)},i):this.root.watchItem(this.path,(a,o)=>{const l=x.get(a,e),u=x.get(o,e);l!==u&&n(l,u)},i)}}class br{constructor(e,n,i){P(this,"attachmentStorage");this.instance=e,this.attachmentKey=n,this.constructInstance=i,this.attachmentStorage=new Tt(e.instanceData,n)}async getInstance(e){if(await this.attachmentStorage.getItem(e))return this.constructInstance(new Tt(this.attachmentStorage,e))}async create(e,n){return await this.attachmentStorage.setItem(e,n),this.constructInstance(new Tt(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 Tt(this.attachmentStorage,n.id))))}}function Pc(t,e){const{value:n,set:i}=V(t.operation.operationData,"config"),[a,o]=m.useState(x.defaults({},n,e)),l=async()=>{await i(a)};return m.useEffect(()=>{o(x.defaults({},n,e))},[n]),{config:a,setConfig:o,commit:l}}function Lc(t){const{config:e,setConfig:n,commit:i}=Pc(t,{urlTemplate:"",openInNewTab:!0});async function a(){await i()}async function o(u){n({...e,openInNewTab:u}),await i()}const l=u=>n({...e,urlTemplate:u.currentTarget.value});return d(s.Stack,{children:[r(s.TextInput,{label:"Url",value:e.urlTemplate,onChange:l,onBlur:a}),r(s.Switch,{label:"Open in new Tab",checked:e.openInNewTab,onChange:u=>o(u.currentTarget.checked)})]})}async function Bc(t,e){const{urlTemplate:n,openInNewTab:i}=await e.operationData.getItem("config");window.dispatchEvent(new CustomEvent("open-link",{detail:{urlTemplate:n,openInNewTab:i,payload:t}}))}class Oc extends se{constructor(){super(...arguments);P(this,"VERSION",1)}configVersions(){this.version(1,n=>n)}}const $c={displayName:"Open Link",id:"builtin:op:open-link",configRender:Lc,run:Bc,migrator:new Oc,createDefaultConfig:()=>({version:1,config:{urlTemplate:"",openInNewTab:!0}})};function Vc(t){const{value:e,set:n}=V(t.operationData,"config"),i=a=>void n({template:a});return[(e==null?void 0:e.template)||"",i]}function Nc(t){const[e,n]=Vc(t.operation);return r(s.TextInput,{defaultValue:e,onBlur:i=>n(i.currentTarget.value),label:"console.log"})}async function qc(t,e){const n=await e.operationData.getItem("config"),i=x.template(n.template||"");console.log("run with payload",t),console.log(i(t))}const Gc={displayName:"console.log (debug)",id:"builtin:op:debug",configRender:Nc,run:qc},Fc=k.observer(t=>{const e=H(),{value:n,set:i}=V(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 i({viewID:l});return r(s.Select,{defaultValue:a,value:a,onChange:o,label:"View",data:e.views.options,withinPortal:!0,zIndex:340,maxDropdownHeight:500})});async function jc(t,e){const i=(await e.operationData.getItem("config")).viewID;window.dispatchEvent(new CustomEvent("open-view",{detail:{viewID:i}}))}const Wc={displayName:"Open View",id:"builtin:op:open_view",configRender:Fc,run:jc},Rc={"tbody tr":{opacity:.5,transition:"opacity 200ms ease"},"tr[data-affected=true]":{opacity:1}},Qc=({value:t="",onChange:e})=>{const[n,i]=m.useState(t);m.useEffect(()=>{i(t)},[t]);const a=()=>{e(n)};return r(s.TextInput,{size:"xs",label:"",value:n,onChange:o=>i(o.currentTarget.value),sx:{flexGrow:1},rightSection:r(s.ActionIcon,{color:"green",size:"xs",onClick:a,disabled:n===t,children:r(M.IconDeviceFloppy,{})})})},Uc={dictionary:{}},Kc=k.observer(t=>{const e=H(),{value:n=Uc,set:i}=V(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],i({dictionary:c});return}i({dictionary:{...a,[l]:u}})};return d(s.Table,{sx:Rc,children:[r("thead",{children:d("tr",{children:[r("th",{children:"Set filter"}),r("th",{children:"with"})]})}),r("tbody",{children:[...e.filters.keyLabelOptions].map(l=>{const u=l.value in a;return d("tr",{"data-affected":u,children:[r("td",{children:l.label}),r("td",{children:r(Qc,{value:a[l.value],onChange:c=>o(l.value,c)})})]},l.value)})})]})});async function Yc(t,e){const i=(await e.operationData.getItem("config")).dictionary;window.dispatchEvent(new CustomEvent("set-filter-values",{detail:{dictionary:i,payload:t}}))}const Xc={displayName:"Set Filter Values",id:"builtin:op:set_filter_values",configRender:Kc,run:Yc},Jc={filter_keys:[]},Zc=k.observer(t=>{const e=H(),{value:n=Jc,set:i}=V(t.operation.operationData,"config"),{filter_keys:a=[]}=n,o=u=>{i({filter_keys:[...u]})},l=m.useMemo(()=>e.filters.current.map(u=>({label:u.label,value:u.key})),[e.filters.values]);return r(s.Stack,{spacing:10,children:r(s.MultiSelect,{label:"Select Filters to Clear",data:l,value:a,onChange:o})})});async function Hc(t,e){const i=(await e.operationData.getItem("config")).filter_keys;window.dispatchEvent(new CustomEvent("clear-filter-values",{detail:{filter_keys:i,payload:t}}))}const fn=[Gc,$c,Wc,Xc,{displayName:"Clear Filter Values",id:"builtin:op:clear_filter_values",configRender:Zc,run:Hc}];class ed{constructor(e,n=fn){P(this,"attachments");this.operations=n;const i=async a=>{const{id:o,schemaRef:l}=await a.getItem(null);return{id:o,schemaRef:l,operationData:new Tt(a,"data")}};this.attachments=new br(e,"__OPERATIONS",i)}async runOperation(e,n){const i=await this.attachments.getInstance(e);if(!i){console.warn(`Operation '${e}' is not defined`);return}const a=this.tryGetSchema(i.schemaRef);if(!a){console.warn(`Operation schema '${i.schemaRef}' is not defined`);return}await a.run(n,i)}tryGetSchema(e){return this.operations.find(n=>n.id===e)}async needMigration(){const n=(await this.attachments.list()).map(async i=>{const a={configData:i.operationData},o=this.tryGetSchema(i.schemaRef),l=o==null?void 0:o.migrator;return l&&await l.needMigration(a)});return(await Promise.all(n)).some(i=>i)}async runMigration(){const n=(await this.attachments.list()).map(async i=>{const a={configData:i.operationData},o=this.tryGetSchema(i.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)}}const Ma="__TRIGGERS";class td{constructor(e,n){P(this,"attachments");this.instance=e,this.component=n;const i=async a=>{const{id:o,schemaRef:l}=await a.getItem(null);return{id:o,schemaRef:l,triggerData:new Tt(a,"data")}};this.attachments=new br(e,Ma,i)}watchTriggerSnapshotList(e){return this.instance.instanceData.watchItem(Ma,n=>{const i=x.values(n).map(a=>({id:x.get(a,"id"),schemaRef:x.get(a,"schemaRef"),config:Q.toJS(x.get(a,"data.config"))}));e(i)},{fireImmediately:!0})}async createOrGetTrigger(e,n,i={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||i.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 i=>{const a=this.getTriggerSchemaList().find(u=>u.id===i.schemaRef),o=a==null?void 0:a.migrator,l={configData:i.triggerData};return o&&await o.needMigration(l)?()=>o.migrate(l):null});return Promise.all(n).then(i=>i.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()))}}class vr{constructor(e,n,i){P(this,"operationManager");P(this,"triggerManager");P(this,"attachments");this.operationManager=new ed(e,i),this.triggerManager=new td(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 i=e.id,a=n.id,o=`[${i}]:[${a}]`;await this.attachments.create(o,{id:o,triggerRef:i,operationRef:a})}getInteractionList(){return this.attachments.list()}async removeInteraction(e){const n=await this.attachments.getInstance(e);if(!n)return;const{triggerRef:i,operationRef:a}=n;await this.getTriggerRefCount(i)<=1&&await this.triggerManager.removeTrigger(i),await this.getOperationRefCount(a)<=1&&await this.operationManager.removeOperation(a),await this.attachments.remove(e)}async getOperationRefCount(e){return(await this.getInteractionList()).filter(i=>i.operationRef===e).length}async getTriggerRefCount(e){return(await this.getInteractionList()).filter(i=>i.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 qe=({vizManager:t,instance:e})=>q.useCreation(()=>new vr(e,t.resolveComponent(e.type),fn),[e,t]),Aa=t=>{const{title:e="Variables",variables:n}=t,i=ye.useClipboard(),a=o=>{i.copy(o),on.showNotification({color:"green",message:"Copied to clipboard"})};return d(s.Paper,{withBorder:!0,p:"sm",children:[r(s.Text,{size:"xs",color:"dimmed",mb:"sm",children:e}),r(s.Stack,{style:{maxHeight:"500px"},children:n.map(o=>d(s.Text,{size:"sm",children:[d(s.Code,{color:"teal",children:["// ",o.description]}),r("br",{}),d(s.Code,{onClick:()=>a(o.name),style:{cursor:"pointer"},children:[o.name," : ",o.valueType]})]},o.name))})]})};class nd{constructor(e,n){P(this,"operationId");P(this,"operation");P(this,"operationSchema");P(this,"variables",[]);this.operationManager=e,this.instance=n,Q.makeAutoObservable(this)}get schemaList(){return this.operationManager.getOperationSchemaList()}async configOperation(e,n){const i=await this.operationManager.retrieveTrigger(e),a=this.operationManager.getOperationSchemaList().find(o=>o.id===(i==null?void 0:i.schemaRef));Q.runInAction(()=>{this.operationId=e,this.operation=i,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 rd(t){return!!t.operationId}const id=k.observer(({model:t,onClick:e})=>{var i;const n=(i=t.operationSchema)==null?void 0:i.displayName;return r(s.Button,{variant:"outline",onClick:e,children:n})}),ad=k.observer(({model:t})=>{const e={operation:t.operation,instance:t.instance,variables:[]};return m.createElement(t.operationSchema.configRender,e)}),sd=k.observer(({model:t})=>{const e=t.schemaList,n=e.map(a=>({label:a.displayName,value:a.id}));async function i(a){await t.changeSchema(e.find(o=>o.id===a))}return r(s.Select,{label:"Operation",data:n,onChange:i,value:t.operationSchema.id,withinPortal:!0,zIndex:340})}),od=k.observer(t=>{const[e,{setTrue:n,setFalse:i}]=q.useBoolean(!1),{operationManager:a,operationId:o,instance:l,variables:u}=t,c=q.useCreation(()=>new nd(a,l),[a,l]);return q.useAsyncEffect(async()=>{await c.configOperation(o,u)},[o,c]),rd(c)?d(z,{children:[r(id,{model:c,onClick:n}),r(s.Modal,{size:600,opened:e,onClose:i,title:"Operation Settings",zIndex:320,children:d(s.Stack,{children:[r(sd,{model:c}),d(s.Tabs,{defaultValue:"settings",children:[d(s.Tabs.List,{children:[r(s.Tabs.Tab,{value:"settings",children:"Settings"}),r(s.Tabs.Tab,{value:"variables",children:"Variables"})]}),r(s.Tabs.Panel,{value:"settings",pt:10,children:r(ad,{model:c})}),r(s.Tabs.Panel,{value:"variables",pt:10,children:r(Aa,{title:"Variables",variables:c.variables})})]})]})})]}):null});class ld{constructor(e,n){P(this,"triggerId");P(this,"trigger");P(this,"triggerSchema");P(this,"sampleData");this.triggerManager=e,this.instance=n,Q.makeAutoObservable(this)}get schemaList(){return this.triggerManager.getTriggerSchemaList()}async configTrigger(e,n){const i=await this.triggerManager.retrieveTrigger(e),a=this.triggerManager.getTriggerSchemaList().find(o=>o.id===(i==null?void 0:i.schemaRef));Q.runInAction(()=>{this.triggerId=e,this.trigger=i,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 ud(this)}}function ud(t){return!!t.triggerId&&!!t.triggerSchema}function cd(t,e){return q.useCreation(()=>new ld(t,e),[t,e])}const dd=k.observer(({model:t,onClick:e})=>{const n=t.triggerSchema.nameRender,i={trigger:t.trigger,instance:t.instance,sampleData:t.sampleData};return r(s.Button,{variant:"outline",onClick:e,children:m.createElement(n,i)})}),pd=k.observer(({model:t})=>{const e=t.schemaList,n=e.map(a=>({label:a.displayName,value:a.id}));async function i(a){await t.changeSchema(e.find(o=>o.id===a))}return r(s.Select,{label:"Trigger",data:n,value:t.triggerSchema.id,onChange:i})}),hd=k.observer(({model:t})=>{const e={trigger:t.trigger,instance:t.instance,sampleData:t.sampleData};return m.createElement(t.triggerSchema.configRender,e)}),fd=k.observer(t=>{const[e,{setTrue:n,setFalse:i}]=q.useBoolean(!1),a=t.model;return d(z,{children:[r(s.Modal,{opened:e,onClose:i,title:"Setup Trigger",zIndex:320,children:d(s.Stack,{children:[r(pd,{model:a}),r(hd,{model:a}),r(Aa,{title:"Payload",variables:a.triggerSchema.payload})]})}),r(dd,{onClick:n,model:a})]})});function gd(t,e){const[n,i]=m.useState([]);return q.useAsyncEffect(async()=>{const a=await t.getInteractionList();i(a)},[e,t]),n}const md=k.observer(({item:t,manager:e,instance:n,sampleData:i,variables:a,onRemove:o})=>{const{triggerRef:l,operationRef:u}=t,c=cd(e.triggerManager,n);if(q.useAsyncEffect(async()=>{await c.configTrigger(l,i)},[c,l,i]),c.isReady()){const p=[...c.triggerSchema.payload,...a];return d(s.Group,{children:[r(fd,{model:c}),r(od,{instance:n,operationId:u,variables:p,operationManager:e.operationManager}),r(s.ActionIcon,{"aria-label":"delete-interaction",variant:"filled",color:"red",onClick:()=>o(t),children:r(T.Trash,{size:16})})]})}return null}),yd=t=>{const[e,n]=m.useState(0),{interactionManager:i,instance:a,sampleData:o,variables:l}=t,u=gd(i,e),c=async()=>{const g=await i.triggerManager.createOrGetTrigger(ye.randomId(),i.triggerManager.getTriggerSchemaList()[0]),b=await i.operationManager.createOrGetOperation(ye.randomId(),i.operationManager.getOperationSchemaList()[0]);await i.addInteraction(g,b),n(w=>w+1)};async function p(g){await i.removeInteraction(g.id),n(b=>b+1)}const{data:h=0,loading:f}=q.useRequest(async()=>{try{return(await i.triggerManager.getTriggerSchemaList()).length}catch{return 0}});return d(s.Stack,{children:[r(s.LoadingOverlay,{visible:f}),h===0&&r(s.Alert,{icon:r(T.AlertCircle,{size:16}),title:"Unavailable",color:"gray",children:"This visualization does not have available interactions to choose from"}),u.map(g=>r(md,{onRemove:p,instance:a,sampleData:o,variables:l,item:g,manager:t.interactionManager},g.id)),r(s.Button,{style:{width:"fit-content"},onClick:()=>c(),disabled:h===0,children:"Add interaction"})]})},bd=()=>{const{panel:t,data:e}=dt(),n=t.viz,{vizManager:i}=m.useContext(tt),a=t.json,o=q.useCreation(()=>i.getOrCreateInstance(a),[i,a]),l=q.useCreation(()=>new vr(o,i.resolveComponent(n.type),fn),[o,n.type]);return m.useEffect(()=>o.instanceData.watchItem(null,x.throttle(u=>{t.viz.setConf(u)},100,{leading:!1,trailing:!0})),[o]),{instance:o,vizManager:i,interactionManager:l,sampleData:e,variables:[]}},vd=()=>{const t=bd();return r(yd,{...t})};function Dt({enabled:t,func_content:e}){return(n,i)=>{if(!t)return n;try{return new Function(`return ${e}`)()(n,i)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function xd(t,e){return Object.entries(t).map(([i,a])=>{const o=a.map(D=>D[e]).sort((D,L)=>D-L),l=Vt.quantile(o,.25)??0,u=Vt.quantile(o,.5)??0,c=Vt.quantile(o,.75)??0,p=c-l,h=l-1.5*p,f=c+1.5*p,g=Math.max(o[0],h),b=Math.min(x.last(o)??0,f),w=a.filter(D=>{const L=D[e];return L<g||L>b}).map(D=>[i,D[e],D]);return{name:i,min:g,q1:l,median:u,q3:c,max:b,outliers:w}})}function wd(t,e){const{x_axis:n,y_axis:i}=t;if(!n.data_key||!i.data_key)return[];const a=A(n.data_key),o=A(i.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=xd(l,o.columnKey),c=u.map(p=>p.outliers).flat();return[{source:u},{source:c}]}function Cd({config:t}){return{...t.legend,data:[{name:"Box",icon:"roundRect",itemStyle:{color:t.color}},{name:"Outlier",icon:"circle",itemStyle:{color:"#2F8CC0"}}]}}const xr=["max","q3","median","q1","min"];function Sd(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:xr,x:"name",itemName:["name"],tooltip:xr}},{name:"Outlier",type:"scatter",symbolSize:5,itemStyle:{color:"#2F8CC0"},emphasis:{scale:2},datasetIndex:1}]}function _d(t){const{outliers:e,min:n,max:i}=t,a=e.filter(u=>u[1]<n).length,o=e.filter(u=>u[1]>i).length,l=(u,c)=>`
|
|
62
62
|
<tr>
|
|
63
63
|
<th style="text-align: right; padding: 0 1em;">${u}</th>
|
|
64
64
|
<td style="text-align: left; padding: 0 1em;">
|
|
65
65
|
${c}
|
|
66
66
|
</td>
|
|
67
67
|
</tr>
|
|
68
|
-
`;return{greater:l("Outliers ⬆",o),less:l("Outliers ⬇",a)}}const
|
|
68
|
+
`;return{greater:l("Outliers ⬆",o),less:l("Outliers ⬇",a)}}const kd=(t,e)=>{const n=xr.map(l=>`
|
|
69
69
|
<tr>
|
|
70
70
|
<th style="text-align: right; padding: 0 1em;">${x.capitalize(l)}</th>
|
|
71
71
|
<td style="text-align: left; padding: 0 1em;">
|
|
72
|
-
${
|
|
72
|
+
${W(e[l]).format(t.y_axis.label_formatter)}
|
|
73
73
|
</td>
|
|
74
|
-
</tr>`),
|
|
74
|
+
</tr>`),i=_d(e);return n.unshift(i.greater),n.push(i.less),`
|
|
75
75
|
<div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
|
|
76
|
-
<div style="${
|
|
76
|
+
<div style="${Ze(t.x_axis.axisLabel.overflow.in_tooltip)}">${e.name}</div>
|
|
77
77
|
</div>
|
|
78
78
|
<table style="width: auto">
|
|
79
79
|
<tbody>
|
|
80
80
|
${n.join("")}
|
|
81
81
|
</tbody>
|
|
82
82
|
</table>
|
|
83
|
-
`},
|
|
83
|
+
`},Td=t=>{try{return W(t).format({trimMantissa:!0,mantissa:2})}catch{return t}};function Dd(t,e){const n=Ze(t.x_axis.axisLabel.overflow.in_tooltip),i=[`<tr>
|
|
84
84
|
<th style="text-align: right; padding: 0 1em;">Outlier</th>
|
|
85
|
-
<td style="text-align: left; padding: 0 1em;">${
|
|
85
|
+
<td style="text-align: left; padding: 0 1em;">${e[1]}</td>
|
|
86
86
|
</tr>
|
|
87
|
-
`],a=
|
|
87
|
+
`],a=t.tooltip.metrics.map(l=>{const u=A(l.data_key);return`
|
|
88
88
|
<tr>
|
|
89
89
|
<th style="text-align: right; padding: 0 1em;">${l.name}</th>
|
|
90
|
-
<td style="text-align: left; padding: 0 1em;">${
|
|
91
|
-
</tr>`});return
|
|
90
|
+
<td style="text-align: left; padding: 0 1em;">${Td(e[2][u.columnKey])}</td>
|
|
91
|
+
</tr>`});return i.push(...a),`
|
|
92
92
|
<div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
|
|
93
|
-
<div style="${n}">${
|
|
93
|
+
<div style="${n}">${e[0]}</div>
|
|
94
94
|
</div>
|
|
95
95
|
<table>
|
|
96
96
|
<tbody>
|
|
97
|
-
${
|
|
97
|
+
${i.join("")}
|
|
98
98
|
</tbody>
|
|
99
99
|
</table>
|
|
100
|
-
`}const Ld=e=>t=>{const{componentSubType:n,value:r}=t;return n==="scatter"?$d(e,r):zd(e,r)};function Pd({config:e}){return{trigger:"item",confine:!0,formatter:Ld(e)}}const un=m.forwardRef(function({value:t,onChange:n,...r},a){return i(s.TextInput,{ref:a,value:t,onChange:n,...r})}),Vr={fontSize:"14px",lineHeight:"32px",color:"#3D3E45",ul:{paddingLeft:"2em",margin:"6px 0 0"},p:{margin:0},a:{WebkitTapHighlightColor:"transparent",color:"rgb(34, 139, 230)",textDecoration:"none","&:hover":{textDecoration:"underline"},"&:active, &:hover":{outlineWidth:0}},table:{tr:{"th, td":{padding:"0 .5em"}}},"table.rich-text-table-render, div.tableWrapper table":{"th, td":{border:"1px solid #eaeaea"},"tr:last-of-type td":{borderBottom:"1px solid #eaeaea"}},".resize-cursor":{cursor:"col-resize"},details:{summary:{listStyle:"none",cursor:"pointer",transition:"color 300ms ease",userSelect:"none"},"summary::-webkit-details-marker":{display:"none"},"summary:hover":{color:"black","&::before":{opacity:1}},"summary::before":{content:'"►"',fontSize:"10px",margin:"0px 5px",opacity:.5,display:"inline-block",transition:"opacity 300ms ease, transform 300ms ease"}},"details[open] summary::before":{transform:"rotate(90deg)"},"details + details":{marginTop:"10px"},blockquote:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45",margin:"0 0 14px"}};function ks(e,t,n){for(let r=0;;r++){if(r==e.childCount||r==t.childCount)return e.childCount==t.childCount?null:n;let a=e.child(r),o=t.child(r);if(a==o){n+=a.nodeSize;continue}if(!a.sameMarkup(o))return n;if(a.isText&&a.text!=o.text){for(let l=0;a.text[l]==o.text[l];l++)n++;return n}if(a.content.size||o.content.size){let l=ks(a.content,o.content,n+1);if(l!=null)return l}n+=a.nodeSize}}function Ts(e,t,n,r){for(let a=e.childCount,o=t.childCount;;){if(a==0||o==0)return a==o?null:{a:n,b:r};let l=e.child(--a),u=t.child(--o),c=l.nodeSize;if(l==u){n-=c,r-=c;continue}if(!l.sameMarkup(u))return{a:n,b:r};if(l.isText&&l.text!=u.text){let d=0,f=Math.min(l.text.length,u.text.length);for(;d<f&&l.text[l.text.length-d-1]==u.text[u.text.length-d-1];)d++,n--,r--;return{a:n,b:r}}if(l.content.size||u.content.size){let d=Ts(l.content,u.content,n-1,r-1);if(d)return d}n-=c,r-=c}}class ae{constructor(t,n){if(this.content=t,this.size=n||0,n==null)for(let r=0;r<t.length;r++)this.size+=t[r].nodeSize}nodesBetween(t,n,r,a=0,o){for(let l=0,u=0;u<n;l++){let c=this.content[l],d=u+c.nodeSize;if(d>t&&r(c,a+u,o||null,l)!==!1&&c.content.size){let f=u+1;c.nodesBetween(Math.max(0,t-f),Math.min(c.content.size,n-f),r,a+f)}u=d}}descendants(t){this.nodesBetween(0,this.size,t)}textBetween(t,n,r,a){let o="",l=!0;return this.nodesBetween(t,n,(u,c)=>{u.isText?(o+=u.text.slice(Math.max(t,c)-c,n-c),l=!r):u.isLeaf?(a?o+=typeof a=="function"?a(u):a:u.type.spec.leafText&&(o+=u.type.spec.leafText(u)),l=!r):!l&&u.isBlock&&(o+=r,l=!0)},0),o}append(t){if(!t.size)return this;if(!this.size)return t;let n=this.lastChild,r=t.firstChild,a=this.content.slice(),o=0;for(n.isText&&n.sameMarkup(r)&&(a[a.length-1]=n.withText(n.text+r.text),o=1);o<t.content.length;o++)a.push(t.content[o]);return new ae(a,this.size+t.size)}cut(t,n=this.size){if(t==0&&n==this.size)return this;let r=[],a=0;if(n>t)for(let o=0,l=0;l<n;o++){let u=this.content[o],c=l+u.nodeSize;c>t&&((l<t||c>n)&&(u.isText?u=u.cut(Math.max(0,t-l),Math.min(u.text.length,n-l)):u=u.cut(Math.max(0,t-l-1),Math.min(u.content.size,n-l-1))),r.push(u),a+=u.nodeSize),l=c}return new ae(r,a)}cutByIndex(t,n){return t==n?ae.empty:t==0&&n==this.content.length?this:new ae(this.content.slice(t,n))}replaceChild(t,n){let r=this.content[t];if(r==n)return this;let a=this.content.slice(),o=this.size+n.nodeSize-r.nodeSize;return a[t]=n,new ae(a,o)}addToStart(t){return new ae([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new ae(this.content.concat(t),this.size+t.nodeSize)}eq(t){if(this.content.length!=t.content.length)return!1;for(let n=0;n<this.content.length;n++)if(!this.content[n].eq(t.content[n]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(t){let n=this.content[t];if(!n)throw new RangeError("Index "+t+" out of range for "+this);return n}maybeChild(t){return this.content[t]||null}forEach(t){for(let n=0,r=0;n<this.content.length;n++){let a=this.content[n];t(a,r,n),r+=a.nodeSize}}findDiffStart(t,n=0){return ks(this,t,n)}findDiffEnd(t,n=this.size,r=t.size){return Ts(this,t,n,r)}findIndex(t,n=-1){if(t==0)return Ln(0,t);if(t==this.size)return Ln(this.content.length,t);if(t>this.size||t<0)throw new RangeError(`Position ${t} outside of fragment (${this})`);for(let r=0,a=0;;r++){let o=this.child(r),l=a+o.nodeSize;if(l>=t)return l==t||n>0?Ln(r+1,l):Ln(r,a);a=l}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(t=>t.toJSON()):null}static fromJSON(t,n){if(!n)return ae.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new ae(n.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return ae.empty;let n,r=0;for(let a=0;a<t.length;a++){let o=t[a];r+=o.nodeSize,a&&o.isText&&t[a-1].sameMarkup(o)?(n||(n=t.slice(0,a)),n[n.length-1]=o.withText(n[n.length-1].text+o.text)):n&&n.push(o)}return new ae(n||t,r)}static from(t){if(!t)return ae.empty;if(t instanceof ae)return t;if(Array.isArray(t))return this.fromArray(t);if(t.attrs)return new ae([t],t.nodeSize);throw new RangeError("Can not convert "+t+" to a Fragment"+(t.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}ae.empty=new ae([],0);const Nr={index:0,offset:0};function Ln(e,t){return Nr.index=e,Nr.offset=t,Nr}function qr(e,t){if(e===t)return!0;if(!(e&&typeof e=="object")||!(t&&typeof t=="object"))return!1;let n=Array.isArray(e);if(Array.isArray(t)!=n)return!1;if(n){if(e.length!=t.length)return!1;for(let r=0;r<e.length;r++)if(!qr(e[r],t[r]))return!1}else{for(let r in e)if(!(r in t)||!qr(e[r],t[r]))return!1;for(let r in t)if(!(r in e))return!1}return!0}class je{constructor(t,n){this.type=t,this.attrs=n}addToSet(t){let n,r=!1;for(let a=0;a<t.length;a++){let o=t[a];if(this.eq(o))return t;if(this.type.excludes(o.type))n||(n=t.slice(0,a));else{if(o.type.excludes(this.type))return t;!r&&o.type.rank>this.type.rank&&(n||(n=t.slice(0,a)),n.push(this),r=!0),n&&n.push(o)}}return n||(n=t.slice()),r||n.push(this),n}removeFromSet(t){for(let n=0;n<t.length;n++)if(this.eq(t[n]))return t.slice(0,n).concat(t.slice(n+1));return t}isInSet(t){for(let n=0;n<t.length;n++)if(this.eq(t[n]))return!0;return!1}eq(t){return this==t||this.type==t.type&&qr(this.attrs,t.attrs)}toJSON(){let t={type:this.type.name};for(let n in this.attrs){t.attrs=this.attrs;break}return t}static fromJSON(t,n){if(!n)throw new RangeError("Invalid input for Mark.fromJSON");let r=t.marks[n.type];if(!r)throw new RangeError(`There is no mark type ${n.type} in this schema`);return r.create(n.attrs)}static sameSet(t,n){if(t==n)return!0;if(t.length!=n.length)return!1;for(let r=0;r<t.length;r++)if(!t[r].eq(n[r]))return!1;return!0}static setFrom(t){if(!t||Array.isArray(t)&&t.length==0)return je.none;if(t instanceof je)return[t];let n=t.slice();return n.sort((r,a)=>r.type.rank-a.type.rank),n}}je.none=[];class Od extends Error{}class ce{constructor(t,n,r){this.content=t,this.openStart=n,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,n){let r=Is(this.content,t+this.openStart,n);return r&&new ce(r,this.openStart,this.openEnd)}removeBetween(t,n){return new ce(Ds(this.content,t+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(t){return this.content.eq(t.content)&&this.openStart==t.openStart&&this.openEnd==t.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let t={content:this.content.toJSON()};return this.openStart>0&&(t.openStart=this.openStart),this.openEnd>0&&(t.openEnd=this.openEnd),t}static fromJSON(t,n){if(!n)return ce.empty;let r=n.openStart||0,a=n.openEnd||0;if(typeof r!="number"||typeof a!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new ce(ae.fromJSON(t,n.content),r,a)}static maxOpen(t,n=!0){let r=0,a=0;for(let o=t.firstChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=t.lastChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.lastChild)a++;return new ce(t,r,a)}}ce.empty=new ce(ae.empty,0,0);function Ds(e,t,n){let{index:r,offset:a}=e.findIndex(t),o=e.maybeChild(r),{index:l,offset:u}=e.findIndex(n);if(a==t||o.isText){if(u!=n&&!e.child(l).isText)throw new RangeError("Removing non-flat range");return e.cut(0,t).append(e.cut(n))}if(r!=l)throw new RangeError("Removing non-flat range");return e.replaceChild(r,o.copy(Ds(o.content,t-a-1,n-a-1)))}function Is(e,t,n,r){let{index:a,offset:o}=e.findIndex(t),l=e.maybeChild(a);if(o==t||l.isText)return r&&!r.canReplace(a,a,n)?null:e.cut(0,t).append(n).append(e.cut(t));let u=Is(l.content,t-o-1,n);return u&&e.replaceChild(a,l.copy(u))}class Pn{constructor(t,n){this.schema=t,this.rules=n,this.tags=[],this.styles=[],n.forEach(r=>{r.tag?this.tags.push(r):r.style&&this.styles.push(r)}),this.normalizeLists=!this.tags.some(r=>{if(!/^(ul|ol)\b/.test(r.tag)||!r.node)return!1;let a=t.nodes[r.node];return a.contentMatch.matchType(a)})}parse(t,n={}){let r=new Es(this,n,!1);return r.addAll(t,n.from,n.to),r.finish()}parseSlice(t,n={}){let r=new Es(this,n,!0);return r.addAll(t,n.from,n.to),ce.maxOpen(r.finish())}matchTag(t,n,r){for(let a=r?this.tags.indexOf(r)+1:0;a<this.tags.length;a++){let o=this.tags[a];if(Nd(t,o.tag)&&(o.namespace===void 0||t.namespaceURI==o.namespace)&&(!o.context||n.matchesContext(o.context))){if(o.getAttrs){let l=o.getAttrs(t);if(l===!1)continue;o.attrs=l||void 0}return o}}}matchStyle(t,n,r,a){for(let o=a?this.styles.indexOf(a)+1:0;o<this.styles.length;o++){let l=this.styles[o],u=l.style;if(!(u.indexOf(t)!=0||l.context&&!r.matchesContext(l.context)||u.length>t.length&&(u.charCodeAt(t.length)!=61||u.slice(t.length+1)!=n))){if(l.getAttrs){let c=l.getAttrs(n);if(c===!1)continue;l.attrs=c||void 0}return l}}}static schemaRules(t){let n=[];function r(a){let o=a.priority==null?50:a.priority,l=0;for(;l<n.length;l++){let u=n[l];if((u.priority==null?50:u.priority)<o)break}n.splice(l,0,a)}for(let a in t.marks){let o=t.marks[a].spec.parseDOM;o&&o.forEach(l=>{r(l=$s(l)),l.mark||l.ignore||l.clearMark||(l.mark=a)})}for(let a in t.nodes){let o=t.nodes[a].spec.parseDOM;o&&o.forEach(l=>{r(l=$s(l)),l.node||l.ignore||l.mark||(l.node=a)})}return n}static fromSchema(t){return t.cached.domParser||(t.cached.domParser=new Pn(t,Pn.schemaRules(t)))}}const Ms={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},Bd={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},As={ol:!0,ul:!0},On=1,Bn=2,cn=4;function zs(e,t,n){return t!=null?(t?On:0)|(t==="full"?Bn:0):e&&e.whitespace=="pre"?On|Bn:n&~cn}class Vn{constructor(t,n,r,a,o,l,u){this.type=t,this.attrs=n,this.marks=r,this.pendingMarks=a,this.solid=o,this.options=u,this.content=[],this.activeMarks=je.none,this.stashMarks=[],this.match=l||(u&cn?null:t.contentMatch)}findWrapping(t){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(ae.from(t));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let r=this.type.contentMatch,a;return(a=r.findWrapping(t.type))?(this.match=r,a):null}}return this.match.findWrapping(t.type)}finish(t){if(!(this.options&On)){let r=this.content[this.content.length-1],a;if(r&&r.isText&&(a=/[ \t\r\n\u000c]+$/.exec(r.text))){let o=r;r.text.length==a[0].length?this.content.pop():this.content[this.content.length-1]=o.withText(o.text.slice(0,o.text.length-a[0].length))}}let n=ae.from(this.content);return!t&&this.match&&(n=n.append(this.match.fillBefore(ae.empty,!0))),this.type?this.type.create(this.attrs,n,this.marks):n}popFromStashMark(t){for(let n=this.stashMarks.length-1;n>=0;n--)if(t.eq(this.stashMarks[n]))return this.stashMarks.splice(n,1)[0]}applyPending(t){for(let n=0,r=this.pendingMarks;n<r.length;n++){let a=r[n];(this.type?this.type.allowsMarkType(a.type):Fd(a.type,t))&&!a.isInSet(this.activeMarks)&&(this.activeMarks=a.addToSet(this.activeMarks),this.pendingMarks=a.removeFromSet(this.pendingMarks))}}inlineContext(t){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:t.parentNode&&!Ms.hasOwnProperty(t.parentNode.nodeName.toLowerCase())}}class Es{constructor(t,n,r){this.parser=t,this.options=n,this.isOpen=r,this.open=0;let a=n.topNode,o,l=zs(null,n.preserveWhitespace,0)|(r?cn:0);a?o=new Vn(a.type,a.attrs,je.none,je.none,!0,n.topMatch||a.type.contentMatch,l):r?o=new Vn(null,null,je.none,je.none,!0,null,l):o=new Vn(t.schema.topNodeType,null,je.none,je.none,!0,null,l),this.nodes=[o],this.find=n.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(t){if(t.nodeType==3)this.addTextNode(t);else if(t.nodeType==1){let n=t.getAttribute("style");if(!n)this.addElement(t);else{let r=this.readStyles(qd(n));if(!r)return;let[a,o]=r,l=this.top;for(let u=0;u<o.length;u++)this.removePendingMark(o[u],l);for(let u=0;u<a.length;u++)this.addPendingMark(a[u]);this.addElement(t);for(let u=0;u<a.length;u++)this.removePendingMark(a[u],l);for(let u=0;u<o.length;u++)this.addPendingMark(o[u])}}}addTextNode(t){let n=t.nodeValue,r=this.top;if(r.options&Bn||r.inlineContext(t)||/[^ \t\r\n\u000c]/.test(n)){if(r.options&On)r.options&Bn?n=n.replace(/\r\n?/g,`
|
|
101
|
-
`):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=
|
|
102
|
-
`))}ignoreFallback(t){t.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"))}readStyles(t){let n=je.none,r=je.none;for(let a=0;a<t.length;a+=2)for(let o=void 0;;){let l=this.parser.matchStyle(t[a],t[a+1],this,o);if(!l)break;if(l.ignore)return null;if(l.clearMark?this.top.pendingMarks.concat(this.top.activeMarks).forEach(u=>{l.clearMark(u)&&(r=u.addToSet(r))}):n=this.parser.schema.marks[l.mark].create(l.attrs).addToSet(n),l.consuming===!1)o=l;else break}return[n,r]}addElementByRule(t,n,r){let a,o,l;n.node?(o=this.parser.schema.nodes[n.node],o.isLeaf?this.insertNode(o.create(n.attrs))||this.leafFallback(t):a=this.enter(o,n.attrs||null,n.preserveWhitespace)):(l=this.parser.schema.marks[n.mark].create(n.attrs),this.addPendingMark(l));let u=this.top;if(o&&o.isLeaf)this.findInside(t);else if(r)this.addElement(t,r);else if(n.getContent)this.findInside(t),n.getContent(t,this.parser.schema).forEach(c=>this.insertNode(c));else{let c=t;typeof n.contentElement=="string"?c=t.querySelector(n.contentElement):typeof n.contentElement=="function"?c=n.contentElement(t):n.contentElement&&(c=n.contentElement),this.findAround(t,c,!0),this.addAll(c)}a&&this.sync(u)&&this.open--,l&&this.removePendingMark(l,u)}addAll(t,n,r){let a=n||0;for(let o=n?t.childNodes[n]:t.firstChild,l=r==null?null:t.childNodes[r];o!=l;o=o.nextSibling,++a)this.findAtPoint(t,a),this.addDOM(o);this.findAtPoint(t,a)}findPlace(t){let n,r;for(let a=this.open;a>=0;a--){let o=this.nodes[a],l=o.findWrapping(t);if(l&&(!n||n.length>l.length)&&(n=l,r=o,!l.length)||o.solid)break}if(!n)return!1;this.sync(r);for(let a=0;a<n.length;a++)this.enterInner(n[a],null,!1);return!0}insertNode(t){if(t.isInline&&this.needsBlock&&!this.top.type){let n=this.textblockFromContext();n&&this.enterInner(n)}if(this.findPlace(t)){this.closeExtra();let n=this.top;n.applyPending(t.type),n.match&&(n.match=n.match.matchType(t.type));let r=n.activeMarks;for(let a=0;a<t.marks.length;a++)(!n.type||n.type.allowsMarkType(t.marks[a].type))&&(r=t.marks[a].addToSet(r));return n.content.push(t.mark(r)),!0}return!1}enter(t,n,r){let a=this.findPlace(t.create(n));return a&&this.enterInner(t,n,!0,r),a}enterInner(t,n=null,r=!1,a){this.closeExtra();let o=this.top;o.applyPending(t),o.match=o.match&&o.match.matchType(t);let l=zs(t,a,o.options);o.options&cn&&o.content.length==0&&(l|=cn),this.nodes.push(new Vn(t,n,o.activeMarks,o.pendingMarks,r,null,l)),this.open++}closeExtra(t=!1){let n=this.nodes.length-1;if(n>this.open){for(;n>this.open;n--)this.nodes[n-1].content.push(this.nodes[n].finish(t));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(t){for(let n=this.open;n>=0;n--)if(this.nodes[n]==t)return this.open=n,!0;return!1}get currentPos(){this.closeExtra();let t=0;for(let n=this.open;n>=0;n--){let r=this.nodes[n].content;for(let a=r.length-1;a>=0;a--)t+=r[a].nodeSize;n&&t++}return t}findAtPoint(t,n){if(this.find)for(let r=0;r<this.find.length;r++)this.find[r].node==t&&this.find[r].offset==n&&(this.find[r].pos=this.currentPos)}findInside(t){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].pos==null&&t.nodeType==1&&t.contains(this.find[n].node)&&(this.find[n].pos=this.currentPos)}findAround(t,n,r){if(t!=n&&this.find)for(let a=0;a<this.find.length;a++)this.find[a].pos==null&&t.nodeType==1&&t.contains(this.find[a].node)&&n.compareDocumentPosition(this.find[a].node)&(r?2:4)&&(this.find[a].pos=this.currentPos)}findInText(t){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==t&&(this.find[n].pos=this.currentPos-(t.nodeValue.length-this.find[n].offset))}matchesContext(t){if(t.indexOf("|")>-1)return t.split(/\s*\|\s*/).some(this.matchesContext,this);let n=t.split("/"),r=this.options.context,a=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),o=-(r?r.depth+1:0)+(a?0:1),l=(u,c)=>{for(;u>=0;u--){let d=n[u];if(d==""){if(u==n.length-1||u==0)continue;for(;c>=o;c--)if(l(u-1,c))return!0;return!1}else{let f=c>0||c==0&&a?this.nodes[c].type:r&&c>=o?r.node(c-o).type:null;if(!f||f.name!=d&&f.groups.indexOf(d)==-1)return!1;c--}}return!0};return l(n.length-1,this.open)}textblockFromContext(){let t=this.options.context;if(t)for(let n=t.depth;n>=0;n--){let r=t.node(n).contentMatchAt(t.indexAfter(n)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let n in this.parser.schema.nodes){let r=this.parser.schema.nodes[n];if(r.isTextblock&&r.defaultAttrs)return r}}addPendingMark(t){let n=Gd(t,this.top.pendingMarks);n&&this.top.stashMarks.push(n),this.top.pendingMarks=t.addToSet(this.top.pendingMarks)}removePendingMark(t,n){for(let r=this.open;r>=0;r--){let a=this.nodes[r];if(a.pendingMarks.lastIndexOf(t)>-1)a.pendingMarks=t.removeFromSet(a.pendingMarks);else{a.activeMarks=t.removeFromSet(a.activeMarks);let l=a.popFromStashMark(t);l&&a.type&&a.type.allowsMarkType(l.type)&&(a.activeMarks=l.addToSet(a.activeMarks))}if(a==n)break}}}function Vd(e){for(let t=e.firstChild,n=null;t;t=t.nextSibling){let r=t.nodeType==1?t.nodeName.toLowerCase():null;r&&As.hasOwnProperty(r)&&n?(n.appendChild(t),t=n):r=="li"?n=t:r&&(n=null)}}function Nd(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function qd(e){let t=/\s*([\w-]+)\s*:\s*([^;]+)/g,n,r=[];for(;n=t.exec(e);)r.push(n[1],n[2].trim());return r}function $s(e){let t={};for(let n in e)t[n]=e[n];return t}function Fd(e,t){let n=t.schema.nodes;for(let r in n){let a=n[r];if(!a.allowsMarkType(e))continue;let o=[],l=u=>{o.push(u);for(let c=0;c<u.edgeCount;c++){let{type:d,next:f}=u.edge(c);if(d==t||o.indexOf(f)<0&&l(f))return!0}};if(l(a.contentMatch))return!0}}function Gd(e,t){for(let n=0;n<t.length;n++)if(e.eq(t[n]))return t[n]}const Ls=65535,Ps=Math.pow(2,16);function Wd(e,t){return e+t*Ps}function Os(e){return e&Ls}function jd(e){return(e-(e&Ls))/Ps}const Bs=1,Vs=2,Nn=4,Ns=8;class qs{constructor(t,n,r){this.pos=t,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&Ns)>0}get deletedBefore(){return(this.delInfo&(Bs|Nn))>0}get deletedAfter(){return(this.delInfo&(Vs|Nn))>0}get deletedAcross(){return(this.delInfo&Nn)>0}}class Je{constructor(t,n=!1){if(this.ranges=t,this.inverted=n,!t.length&&Je.empty)return Je.empty}recover(t){let n=0,r=Os(t);if(!this.inverted)for(let a=0;a<r;a++)n+=this.ranges[a*3+2]-this.ranges[a*3+1];return this.ranges[r*3]+n+jd(t)}mapResult(t,n=1){return this._map(t,n,!1)}map(t,n=1){return this._map(t,n,!0)}_map(t,n,r){let a=0,o=this.inverted?2:1,l=this.inverted?1:2;for(let u=0;u<this.ranges.length;u+=3){let c=this.ranges[u]-(this.inverted?a:0);if(c>t)break;let d=this.ranges[u+o],f=this.ranges[u+l],h=c+d;if(t<=h){let g=d?t==c?-1:t==h?1:n:n,y=c+a+(g<0?0:f);if(r)return y;let C=t==(n<0?c:h)?null:Wd(u/3,t-c),w=t==c?Vs:t==h?Bs:Nn;return(n<0?t!=c:t!=h)&&(w|=Ns),new qs(y,w,C)}a+=f-d}return r?t+a:new qs(t+a,0,null)}touches(t,n){let r=0,a=Os(n),o=this.inverted?2:1,l=this.inverted?1:2;for(let u=0;u<this.ranges.length;u+=3){let c=this.ranges[u]-(this.inverted?r:0);if(c>t)break;let d=this.ranges[u+o],f=c+d;if(t<=f&&u==a*3)return!0;r+=this.ranges[u+l]-d}return!1}forEach(t){let n=this.inverted?2:1,r=this.inverted?1:2;for(let a=0,o=0;a<this.ranges.length;a+=3){let l=this.ranges[a],u=l-(this.inverted?o:0),c=l+(this.inverted?0:o),d=this.ranges[a+n],f=this.ranges[a+r];t(u,u+d,c,c+f),o+=f-d}}invert(){return new Je(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(t){return t==0?Je.empty:new Je(t<0?[0,-t,0]:[0,0,t])}}Je.empty=new Je([]);const Fr=Object.create(null);class Ve{getMap(){return Je.empty}merge(t){return null}static fromJSON(t,n){if(!n||!n.stepType)throw new RangeError("Invalid input for Step.fromJSON");let r=Fr[n.stepType];if(!r)throw new RangeError(`No step type ${n.stepType} defined`);return r.fromJSON(t,n)}static jsonID(t,n){if(t in Fr)throw new RangeError("Duplicate use of step JSON ID "+t);return Fr[t]=n,n.prototype.jsonID=t,n}}class Ce{constructor(t,n){this.doc=t,this.failed=n}static ok(t){return new Ce(t,null)}static fail(t){return new Ce(null,t)}static fromReplace(t,n,r,a){try{return Ce.ok(t.replace(n,r,a))}catch(o){if(o instanceof Od)return Ce.fail(o.message);throw o}}}function Gr(e,t,n){let r=[];for(let a=0;a<e.childCount;a++){let o=e.child(a);o.content.size&&(o=o.copy(Gr(o.content,t,o))),o.isInline&&(o=t(o,n,a)),r.push(o)}return ae.fromArray(r)}class Et extends Ve{constructor(t,n,r){super(),this.from=t,this.to=n,this.mark=r}apply(t){let n=t.slice(this.from,this.to),r=t.resolve(this.from),a=r.node(r.sharedDepth(this.to)),o=new ce(Gr(n.content,(l,u)=>!l.isAtom||!u.type.allowsMarkType(this.mark.type)?l:l.mark(this.mark.addToSet(l.marks)),a),n.openStart,n.openEnd);return Ce.fromReplace(t,this.from,this.to,o)}invert(){return new $t(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new Et(n.pos,r.pos,this.mark)}merge(t){return t instanceof Et&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new Et(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new Et(n.from,n.to,t.markFromJSON(n.mark))}}Ve.jsonID("addMark",Et);class $t extends Ve{constructor(t,n,r){super(),this.from=t,this.to=n,this.mark=r}apply(t){let n=t.slice(this.from,this.to),r=new ce(Gr(n.content,a=>a.mark(this.mark.removeFromSet(a.marks)),t),n.openStart,n.openEnd);return Ce.fromReplace(t,this.from,this.to,r)}invert(){return new Et(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new $t(n.pos,r.pos,this.mark)}merge(t){return t instanceof $t&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new $t(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new $t(n.from,n.to,t.markFromJSON(n.mark))}}Ve.jsonID("removeMark",$t);class Lt extends Ve{constructor(t,n){super(),this.pos=t,this.mark=n}apply(t){let n=t.nodeAt(this.pos);if(!n)return Ce.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return Ce.fromReplace(t,this.pos,this.pos+1,new ce(ae.from(r),0,n.isLeaf?0:1))}invert(t){let n=t.nodeAt(this.pos);if(n){let r=this.mark.addToSet(n.marks);if(r.length==n.marks.length){for(let a=0;a<n.marks.length;a++)if(!n.marks[a].isInSet(r))return new Lt(this.pos,n.marks[a]);return new Lt(this.pos,this.mark)}}return new dn(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new Lt(n.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new Lt(n.pos,t.markFromJSON(n.mark))}}Ve.jsonID("addNodeMark",Lt);class dn extends Ve{constructor(t,n){super(),this.pos=t,this.mark=n}apply(t){let n=t.nodeAt(this.pos);if(!n)return Ce.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.removeFromSet(n.marks));return Ce.fromReplace(t,this.pos,this.pos+1,new ce(ae.from(r),0,n.isLeaf?0:1))}invert(t){let n=t.nodeAt(this.pos);return!n||!this.mark.isInSet(n.marks)?this:new Lt(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new dn(n.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new dn(n.pos,t.markFromJSON(n.mark))}}Ve.jsonID("removeNodeMark",dn);class lt extends Ve{constructor(t,n,r,a=!1){super(),this.from=t,this.to=n,this.slice=r,this.structure=a}apply(t){return this.structure&&Wr(t,this.from,this.to)?Ce.fail("Structure replace would overwrite content"):Ce.fromReplace(t,this.from,this.to,this.slice)}getMap(){return new Je([this.from,this.to-this.from,this.slice.size])}invert(t){return new lt(this.from,this.from+this.slice.size,t.slice(this.from,this.to))}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deletedAcross&&r.deletedAcross?null:new lt(n.pos,Math.max(n.pos,r.pos),this.slice)}merge(t){if(!(t instanceof lt)||t.structure||this.structure)return null;if(this.from+this.slice.size==t.from&&!this.slice.openEnd&&!t.slice.openStart){let n=this.slice.size+t.slice.size==0?ce.empty:new ce(this.slice.content.append(t.slice.content),this.slice.openStart,t.slice.openEnd);return new lt(this.from,this.to+(t.to-t.from),n,this.structure)}else if(t.to==this.from&&!this.slice.openStart&&!t.slice.openEnd){let n=this.slice.size+t.slice.size==0?ce.empty:new ce(t.slice.content.append(this.slice.content),t.slice.openStart,this.slice.openEnd);return new lt(t.from,this.to,n,this.structure)}else return null}toJSON(){let t={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(t.slice=this.slice.toJSON()),this.structure&&(t.structure=!0),t}static fromJSON(t,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new lt(n.from,n.to,ce.fromJSON(t,n.slice),!!n.structure)}}Ve.jsonID("replace",lt);class Pt extends Ve{constructor(t,n,r,a,o,l,u=!1){super(),this.from=t,this.to=n,this.gapFrom=r,this.gapTo=a,this.slice=o,this.insert=l,this.structure=u}apply(t){if(this.structure&&(Wr(t,this.from,this.gapFrom)||Wr(t,this.gapTo,this.to)))return Ce.fail("Structure gap-replace would overwrite content");let n=t.slice(this.gapFrom,this.gapTo);if(n.openStart||n.openEnd)return Ce.fail("Gap is not a flat range");let r=this.slice.insertAt(this.insert,n.content);return r?Ce.fromReplace(t,this.from,this.to,r):Ce.fail("Content does not fit in gap")}getMap(){return new Je([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(t){let n=this.gapTo-this.gapFrom;return new Pt(this.from,this.from+this.slice.size+n,this.from+this.insert,this.from+this.insert+n,t.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1),a=t.map(this.gapFrom,-1),o=t.map(this.gapTo,1);return n.deletedAcross&&r.deletedAcross||a<n.pos||o>r.pos?null:new Pt(n.pos,r.pos,a,o,this.slice,this.insert,this.structure)}toJSON(){let t={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(t.slice=this.slice.toJSON()),this.structure&&(t.structure=!0),t}static fromJSON(t,n){if(typeof n.from!="number"||typeof n.to!="number"||typeof n.gapFrom!="number"||typeof n.gapTo!="number"||typeof n.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Pt(n.from,n.to,n.gapFrom,n.gapTo,ce.fromJSON(t,n.slice),n.insert,!!n.structure)}}Ve.jsonID("replaceAround",Pt);function Wr(e,t,n){let r=e.resolve(t),a=n-t,o=r.depth;for(;a>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,a--;if(a>0){let l=r.node(o).maybeChild(r.indexAfter(o));for(;a>0;){if(!l||l.isLeaf)return!0;l=l.firstChild,a--}}return!1}function Rd(e,t,n){return(t==0||e.canReplace(t,e.childCount))&&(n==e.childCount||e.canReplace(0,n))}function Yd(e){let n=e.parent.content.cutByIndex(e.startIndex,e.endIndex);for(let r=e.depth;;--r){let a=e.$from.node(r),o=e.$from.index(r),l=e.$to.indexAfter(r);if(r<e.depth&&a.canReplace(o,l,n))return r;if(r==0||a.type.spec.isolating||!Rd(a,o,l))break}return null}function qn(e,t,n=1,r){let a=e.resolve(t),o=a.depth-n,l=r&&r[r.length-1]||a.parent;if(o<0||a.parent.type.spec.isolating||!a.parent.canReplace(a.index(),a.parent.childCount)||!l.type.validContent(a.parent.content.cutByIndex(a.index(),a.parent.childCount)))return!1;for(let d=a.depth-1,f=n-2;d>o;d--,f--){let h=a.node(d),g=a.index(d);if(h.type.spec.isolating)return!1;let y=h.content.cutByIndex(g,h.childCount),C=r&&r[f+1];C&&(y=y.replaceChild(0,C.type.create(C.attrs)));let w=r&&r[f]||h;if(!h.canReplace(g+1,h.childCount)||!w.type.validContent(y))return!1}let u=a.indexAfter(o),c=r&&r[0];return a.node(o).canReplaceWith(u,u,c?c.type:a.node(o+1).type)}function Fs(e,t){let n=e.resolve(t),r=n.index();return Qd(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function Qd(e,t){return!!(e&&t&&!e.isLeaf&&e.canAppend(t))}class pn extends Ve{constructor(t,n,r){super(),this.pos=t,this.attr=n,this.value=r}apply(t){let n=t.nodeAt(this.pos);if(!n)return Ce.fail("No node at attribute step's position");let r=Object.create(null);for(let o in n.attrs)r[o]=n.attrs[o];r[this.attr]=this.value;let a=n.type.create(r,null,n.marks);return Ce.fromReplace(t,this.pos,this.pos+1,new ce(ae.from(a),0,n.isLeaf?0:1))}getMap(){return Je.empty}invert(t){return new pn(this.pos,this.attr,t.nodeAt(this.pos).attrs[this.attr])}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new pn(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(t,n){if(typeof n.pos!="number"||typeof n.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new pn(n.pos,n.attr,n.value)}}Ve.jsonID("attr",pn);let hn=class extends Error{};hn=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n},hn.prototype=Object.create(Error.prototype),hn.prototype.constructor=hn,hn.prototype.name="TransformError";const jr=Object.create(null);class fe{constructor(t,n,r){this.$anchor=t,this.$head=n,this.ranges=r||[new Ud(t.min(n),t.max(n))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let t=this.ranges;for(let n=0;n<t.length;n++)if(t[n].$from.pos!=t[n].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(t,n=ce.empty){let r=n.content.lastChild,a=null;for(let u=0;u<n.openEnd;u++)a=r,r=r.lastChild;let o=t.steps.length,l=this.ranges;for(let u=0;u<l.length;u++){let{$from:c,$to:d}=l[u],f=t.mapping.slice(o);t.replaceRange(f.map(c.pos),f.map(d.pos),u?ce.empty:n),u==0&&js(t,o,(r?r.isInline:a&&a.isTextblock)?-1:1)}}replaceWith(t,n){let r=t.steps.length,a=this.ranges;for(let o=0;o<a.length;o++){let{$from:l,$to:u}=a[o],c=t.mapping.slice(r),d=c.map(l.pos),f=c.map(u.pos);o?t.deleteRange(d,f):(t.replaceRangeWith(d,f,n),js(t,r,n.isInline?-1:1))}}static findFrom(t,n,r=!1){let a=t.parent.inlineContent?new Se(t):Gt(t.node(0),t.parent,t.pos,t.index(),n,r);if(a)return a;for(let o=t.depth-1;o>=0;o--){let l=n<0?Gt(t.node(0),t.node(o),t.before(o+1),t.index(o),n,r):Gt(t.node(0),t.node(o),t.after(o+1),t.index(o)+1,n,r);if(l)return l}return null}static near(t,n=1){return this.findFrom(t,n)||this.findFrom(t,-n)||new mt(t.node(0))}static atStart(t){return Gt(t,t,0,0,1)||new mt(t)}static atEnd(t){return Gt(t,t,t.content.size,t.childCount,-1)||new mt(t)}static fromJSON(t,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=jr[n.type];if(!r)throw new RangeError(`No selection type ${n.type} defined`);return r.fromJSON(t,n)}static jsonID(t,n){if(t in jr)throw new RangeError("Duplicate use of selection JSON ID "+t);return jr[t]=n,n.prototype.jsonID=t,n}getBookmark(){return Se.between(this.$anchor,this.$head).getBookmark()}}fe.prototype.visible=!0;class Ud{constructor(t,n){this.$from=t,this.$to=n}}let Gs=!1;function Ws(e){!Gs&&!e.parent.inlineContent&&(Gs=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+e.parent.type.name+")"))}class Se extends fe{constructor(t,n=t){Ws(t),Ws(n),super(t,n)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(t,n){let r=t.resolve(n.map(this.head));if(!r.parent.inlineContent)return fe.near(r);let a=t.resolve(n.map(this.anchor));return new Se(a.parent.inlineContent?a:r,r)}replace(t,n=ce.empty){if(super.replace(t,n),n==ce.empty){let r=this.$from.marksAcross(this.$to);r&&t.ensureMarks(r)}}eq(t){return t instanceof Se&&t.anchor==this.anchor&&t.head==this.head}getBookmark(){return new Fn(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(t,n){if(typeof n.anchor!="number"||typeof n.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new Se(t.resolve(n.anchor),t.resolve(n.head))}static create(t,n,r=n){let a=t.resolve(n);return new this(a,r==n?a:t.resolve(r))}static between(t,n,r){let a=t.pos-n.pos;if((!r||a)&&(r=a>=0?1:-1),!n.parent.inlineContent){let o=fe.findFrom(n,r,!0)||fe.findFrom(n,-r,!0);if(o)n=o.$head;else return fe.near(n,r)}return t.parent.inlineContent||(a==0?t=n:(t=(fe.findFrom(t,-r,!0)||fe.findFrom(t,r,!0)).$anchor,t.pos<n.pos!=a<0&&(t=n))),new Se(t,n)}}fe.jsonID("text",Se);class Fn{constructor(t,n){this.anchor=t,this.head=n}map(t){return new Fn(t.map(this.anchor),t.map(this.head))}resolve(t){return Se.between(t.resolve(this.anchor),t.resolve(this.head))}}class Re extends fe{constructor(t){let n=t.nodeAfter,r=t.node(0).resolve(t.pos+n.nodeSize);super(t,r),this.node=n}map(t,n){let{deleted:r,pos:a}=n.mapResult(this.anchor),o=t.resolve(a);return r?fe.near(o):new Re(o)}content(){return new ce(ae.from(this.node),0,0)}eq(t){return t instanceof Re&&t.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new Rr(this.anchor)}static fromJSON(t,n){if(typeof n.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new Re(t.resolve(n.anchor))}static create(t,n){return new Re(t.resolve(n))}static isSelectable(t){return!t.isText&&t.type.spec.selectable!==!1}}Re.prototype.visible=!1,fe.jsonID("node",Re);class Rr{constructor(t){this.anchor=t}map(t){let{deleted:n,pos:r}=t.mapResult(this.anchor);return n?new Fn(r,r):new Rr(r)}resolve(t){let n=t.resolve(this.anchor),r=n.nodeAfter;return r&&Re.isSelectable(r)?new Re(n):fe.near(n)}}class mt extends fe{constructor(t){super(t.resolve(0),t.resolve(t.content.size))}replace(t,n=ce.empty){if(n==ce.empty){t.delete(0,t.doc.content.size);let r=fe.atStart(t.doc);r.eq(t.selection)||t.setSelection(r)}else super.replace(t,n)}toJSON(){return{type:"all"}}static fromJSON(t){return new mt(t)}map(t){return new mt(t)}eq(t){return t instanceof mt}getBookmark(){return Kd}}fe.jsonID("all",mt);const Kd={map(){return this},resolve(e){return new mt(e)}};function Gt(e,t,n,r,a,o=!1){if(t.inlineContent)return Se.create(e,n);for(let l=r-(a>0?0:1);a>0?l<t.childCount:l>=0;l+=a){let u=t.child(l);if(u.isAtom){if(!o&&Re.isSelectable(u))return Re.create(e,n-(a<0?u.nodeSize:0))}else{let c=Gt(e,u,n+a,a<0?u.childCount:0,a,o);if(c)return c}n+=u.nodeSize*a}return null}function js(e,t,n){let r=e.steps.length-1;if(r<t)return;let a=e.steps[r];if(!(a instanceof lt||a instanceof Pt))return;let o=e.mapping.maps[r],l;o.forEach((u,c,d,f)=>{l==null&&(l=f)}),e.setSelection(fe.near(e.doc.resolve(l),n))}function Rs(e,t){return!t||!e?e:e.bind(t)}class Gn{constructor(t,n,r){this.name=t,this.init=Rs(n.init,r),this.apply=Rs(n.apply,r)}}new Gn("doc",{init(e){return e.doc||e.schema.topNodeType.createAndFill()},apply(e){return e.doc}}),new Gn("selection",{init(e,t){return e.selection||fe.atStart(t.doc)},apply(e){return e.selection}}),new Gn("storedMarks",{init(e){return e.storedMarks||null},apply(e,t,n,r){return r.selection.$cursor?e.storedMarks:null}}),new Gn("scrollToSelection",{init(){return 0},apply(e,t){return e.scrolledIntoView?t+1:t}});function Ys(e,t,n){for(let r in e){let a=e[r];a instanceof Function?a=a.bind(t):r=="handleDOMEvents"&&(a=Ys(a,t,{})),n[r]=a}return n}class fn{constructor(t){this.spec=t,this.props={},t.props&&Ys(t.props,this,this.props),this.key=t.key?t.key.key:Qs("plugin")}getState(t){return t[this.key]}}const Yr=Object.create(null);function Qs(e){return e in Yr?e+"$"+ ++Yr[e]:(Yr[e]=0,e+"$")}class gn{constructor(t="key"){this.key=Qs(t)}get(t){return t.config.pluginsByKey[this.key]}getState(t){return t[this.key]}}function Us(e){const{state:t,transaction:n}=e;let{selection:r}=n,{doc:a}=n,{storedMarks:o}=n;return{...t,apply:t.apply.bind(t),applyTransaction:t.applyTransaction.bind(t),filterTransaction:t.filterTransaction,plugins:t.plugins,schema:t.schema,reconfigure:t.reconfigure.bind(t),toJSON:t.toJSON.bind(t),get storedMarks(){return o},get selection(){return r},get doc(){return a},get tr(){return r=n.selection,a=n.doc,o=n.storedMarks,n}}}class Xd{constructor(t){this.editor=t.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=t.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){const{rawCommands:t,editor:n,state:r}=this,{view:a}=n,{tr:o}=r,l=this.buildProps(o);return Object.fromEntries(Object.entries(t).map(([u,c])=>[u,(...f)=>{const h=c(...f)(l);return!o.getMeta("preventDispatch")&&!this.hasCustomState&&a.dispatch(o),h}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(t,n=!0){const{rawCommands:r,editor:a,state:o}=this,{view:l}=a,u=[],c=!!t,d=t||o.tr,f=()=>(!c&&n&&!d.getMeta("preventDispatch")&&!this.hasCustomState&&l.dispatch(d),u.every(g=>g===!0)),h={...Object.fromEntries(Object.entries(r).map(([g,y])=>[g,(...w)=>{const _=this.buildProps(d,n),D=y(...w)(_);return u.push(D),h}])),run:f};return h}createCan(t){const{rawCommands:n,state:r}=this,a=!1,o=t||r.tr,l=this.buildProps(o,a);return{...Object.fromEntries(Object.entries(n).map(([c,d])=>[c,(...f)=>d(...f)({...l,dispatch:void 0})])),chain:()=>this.createChain(o,a)}}buildProps(t,n=!0){const{rawCommands:r,editor:a,state:o}=this,{view:l}=a;o.storedMarks&&t.setStoredMarks(o.storedMarks);const u={tr:t,editor:a,view:l,state:Us({state:o,transaction:t}),dispatch:n?()=>{}:void 0,chain:()=>this.createChain(t),can:()=>this.createCan(t),get commands(){return Object.fromEntries(Object.entries(r).map(([c,d])=>[c,(...f)=>d(...f)(u)]))}};return u}}function St(e,t,n){return e.config[t]===void 0&&e.parent?St(e.parent,t,n):typeof e.config[t]=="function"?e.config[t].bind({...n,parent:e.parent?St(e.parent,t,n):null}):e.config[t]}function Jd(e){const t=e.filter(a=>a.type==="extension"),n=e.filter(a=>a.type==="node"),r=e.filter(a=>a.type==="mark");return{baseExtensions:t,nodeExtensions:n,markExtensions:r}}function Me(e,t){if(typeof e=="string"){if(!t.nodes[e])throw Error(`There is no node type named '${e}'. Maybe you forgot to add the extension?`);return t.nodes[e]}return e}function Zd(e){return typeof e=="function"}function Wt(e,t=void 0,...n){return Zd(e)?t?e.bind(t)(...n):e(...n):e}function Hd(e){return Object.prototype.toString.call(e)==="[object RegExp]"}function ep(e){return Object.prototype.toString.call(e).slice(8,-1)}function Qr(e){return ep(e)!=="Object"?!1:e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype}function Ks(e,t){const n={...e};return Qr(e)&&Qr(t)&&Object.keys(t).forEach(r=>{Qr(t[r])?r in e?n[r]=Ks(e[r],t[r]):Object.assign(n,{[r]:t[r]}):Object.assign(n,{[r]:t[r]})}),n}class ut{constructor(t={}){this.type="extension",this.name="extension",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...t},this.name=this.config.name,t.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=Wt(St(this,"addOptions",{name:this.name}))),this.storage=Wt(St(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(t={}){return new ut(t)}configure(t={}){const n=this.extend();return n.options=Ks(this.options,t),n.storage=Wt(St(n,"addStorage",{name:n.name,options:n.options})),n}extend(t={}){const n=new ut(t);return n.parent=this,this.child=n,n.name=t.name?t.name:n.parent.name,t.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${n.name}".`),n.options=Wt(St(n,"addOptions",{name:n.name})),n.storage=Wt(St(n,"addStorage",{name:n.name,options:n.options})),n}}function tp(e,t,n){const{from:r,to:a}=t,{blockSeparator:o=`
|
|
100
|
+
`}const Id=t=>e=>{const{componentSubType:n,value:i}=e;return n==="scatter"?Dd(t,i):kd(t,i)};function Md({config:t}){return{trigger:"item",confine:!0,formatter:Id(t)}}const Rt=m.forwardRef(function({value:e,onChange:n,...i},a){return r(s.TextInput,{ref:a,value:e,onChange:n,...i})}),wr={fontSize:"14px",lineHeight:"32px",color:"#3D3E45",ul:{paddingLeft:"2em",margin:"6px 0 0"},p:{margin:0},a:{WebkitTapHighlightColor:"transparent",color:"rgb(34, 139, 230)",textDecoration:"none","&:hover":{textDecoration:"underline"},"&:active, &:hover":{outlineWidth:0}},table:{tr:{"th, td":{padding:"0 .5em"}}},"table.rich-text-table-render, div.tableWrapper table":{"th, td":{border:"1px solid #eaeaea"},"tr:last-of-type td":{borderBottom:"1px solid #eaeaea"}},".resize-cursor":{cursor:"col-resize"},details:{summary:{listStyle:"none",cursor:"pointer",transition:"color 300ms ease",userSelect:"none"},"summary::-webkit-details-marker":{display:"none"},"summary:hover":{color:"black","&::before":{opacity:1}},"summary::before":{content:'"►"',fontSize:"10px",margin:"0px 5px",opacity:.5,display:"inline-block",transition:"opacity 300ms ease, transform 300ms ease"}},"details[open] summary::before":{transform:"rotate(90deg)"},"details + details":{marginTop:"10px"},blockquote:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45",margin:"0 0 14px"}};function za(t,e,n){for(let i=0;;i++){if(i==t.childCount||i==e.childCount)return t.childCount==e.childCount?null:n;let a=t.child(i),o=e.child(i);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=za(a.content,o.content,n+1);if(l!=null)return l}n+=a.nodeSize}}function Ea(t,e,n,i){for(let a=t.childCount,o=e.childCount;;){if(a==0||o==0)return a==o?null:{a:n,b:i};let l=t.child(--a),u=e.child(--o),c=l.nodeSize;if(l==u){n-=c,i-=c;continue}if(!l.sameMarkup(u))return{a:n,b:i};if(l.isText&&l.text!=u.text){let p=0,h=Math.min(l.text.length,u.text.length);for(;p<h&&l.text[l.text.length-p-1]==u.text[u.text.length-p-1];)p++,n--,i--;return{a:n,b:i}}if(l.content.size||u.content.size){let p=Ea(l.content,u.content,n-1,i-1);if(p)return p}n-=c,i-=c}}class X{constructor(e,n){if(this.content=e,this.size=n||0,n==null)for(let i=0;i<e.length;i++)this.size+=e[i].nodeSize}nodesBetween(e,n,i,a=0,o){for(let l=0,u=0;u<n;l++){let c=this.content[l],p=u+c.nodeSize;if(p>e&&i(c,a+u,o||null,l)!==!1&&c.content.size){let h=u+1;c.nodesBetween(Math.max(0,e-h),Math.min(c.content.size,n-h),i,a+h)}u=p}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,n,i,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=!i):u.isLeaf?(a?o+=typeof a=="function"?a(u):a:u.type.spec.leafText&&(o+=u.type.spec.leafText(u)),l=!i):!l&&u.isBlock&&(o+=i,l=!0)},0),o}append(e){if(!e.size)return this;if(!this.size)return e;let n=this.lastChild,i=e.firstChild,a=this.content.slice(),o=0;for(n.isText&&n.sameMarkup(i)&&(a[a.length-1]=n.withText(n.text+i.text),o=1);o<e.content.length;o++)a.push(e.content[o]);return new X(a,this.size+e.size)}cut(e,n=this.size){if(e==0&&n==this.size)return this;let i=[],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))),i.push(u),a+=u.nodeSize),l=c}return new X(i,a)}cutByIndex(e,n){return e==n?X.empty:e==0&&n==this.content.length?this:new X(this.content.slice(e,n))}replaceChild(e,n){let i=this.content[e];if(i==n)return this;let a=this.content.slice(),o=this.size+n.nodeSize-i.nodeSize;return a[e]=n,new X(a,o)}addToStart(e){return new X([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new X(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,i=0;n<this.content.length;n++){let a=this.content[n];e(a,i,n),i+=a.nodeSize}}findDiffStart(e,n=0){return za(this,e,n)}findDiffEnd(e,n=this.size,i=e.size){return Ea(this,e,n,i)}findIndex(e,n=-1){if(e==0)return gn(0,e);if(e==this.size)return gn(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let i=0,a=0;;i++){let o=this.child(i),l=a+o.nodeSize;if(l>=e)return l==e||n>0?gn(i+1,l):gn(i,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 X.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new X(n.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return X.empty;let n,i=0;for(let a=0;a<e.length;a++){let o=e[a];i+=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 X(n||e,i)}static from(e){if(!e)return X.empty;if(e instanceof X)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new X([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}X.empty=new X([],0);const Cr={index:0,offset:0};function gn(t,e){return Cr.index=t,Cr.offset=e,Cr}function Sr(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 i=0;i<t.length;i++)if(!Sr(t[i],e[i]))return!1}else{for(let i in t)if(!(i in e)||!Sr(t[i],e[i]))return!1;for(let i in e)if(!(i in t))return!1}return!0}class Be{constructor(e,n){this.type=e,this.attrs=n}addToSet(e){let n,i=!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;!i&&o.type.rank>this.type.rank&&(n||(n=e.slice(0,a)),n.push(this),i=!0),n&&n.push(o)}}return n||(n=e.slice()),i||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&&Sr(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 i=e.marks[n.type];if(!i)throw new RangeError(`There is no mark type ${n.type} in this schema`);return i.create(n.attrs)}static sameSet(e,n){if(e==n)return!0;if(e.length!=n.length)return!1;for(let i=0;i<e.length;i++)if(!e[i].eq(n[i]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&e.length==0)return Be.none;if(e instanceof Be)return[e];let n=e.slice();return n.sort((i,a)=>i.type.rank-a.type.rank),n}}Be.none=[];class Ad extends Error{}class te{constructor(e,n,i){this.content=e,this.openStart=n,this.openEnd=i}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,n){let i=La(this.content,e+this.openStart,n);return i&&new te(i,this.openStart,this.openEnd)}removeBetween(e,n){return new te(Pa(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 te.empty;let i=n.openStart||0,a=n.openEnd||0;if(typeof i!="number"||typeof a!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new te(X.fromJSON(e,n.content),i,a)}static maxOpen(e,n=!0){let i=0,a=0;for(let o=e.firstChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.firstChild)i++;for(let o=e.lastChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.lastChild)a++;return new te(e,i,a)}}te.empty=new te(X.empty,0,0);function Pa(t,e,n){let{index:i,offset:a}=t.findIndex(e),o=t.maybeChild(i),{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(i!=l)throw new RangeError("Removing non-flat range");return t.replaceChild(i,o.copy(Pa(o.content,e-a-1,n-a-1)))}function La(t,e,n,i){let{index:a,offset:o}=t.findIndex(e),l=t.maybeChild(a);if(o==e||l.isText)return i&&!i.canReplace(a,a,n)?null:t.cut(0,e).append(n).append(t.cut(e));let u=La(l.content,e-o-1,n);return u&&t.replaceChild(a,l.copy(u))}class mn{constructor(e,n){this.schema=e,this.rules=n,this.tags=[],this.styles=[],n.forEach(i=>{i.tag?this.tags.push(i):i.style&&this.styles.push(i)}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let a=e.nodes[i.node];return a.contentMatch.matchType(a)})}parse(e,n={}){let i=new Va(this,n,!1);return i.addAll(e,n.from,n.to),i.finish()}parseSlice(e,n={}){let i=new Va(this,n,!0);return i.addAll(e,n.from,n.to),te.maxOpen(i.finish())}matchTag(e,n,i){for(let a=i?this.tags.indexOf(i)+1:0;a<this.tags.length;a++){let o=this.tags[a];if(Pd(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,i,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&&!i.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 i(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=>{i(l=Na(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=>{i(l=Na(l)),l.node||l.ignore||l.mark||(l.node=a)})}return n}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new mn(e,mn.schemaRules(e)))}}const Ba={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},zd={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Oa={ol:!0,ul:!0},yn=1,bn=2,Qt=4;function $a(t,e,n){return e!=null?(e?yn:0)|(e==="full"?bn:0):t&&t.whitespace=="pre"?yn|bn:n&~Qt}class vn{constructor(e,n,i,a,o,l,u){this.type=e,this.attrs=n,this.marks=i,this.pendingMarks=a,this.solid=o,this.options=u,this.content=[],this.activeMarks=Be.none,this.stashMarks=[],this.match=l||(u&Qt?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(X.from(e));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let i=this.type.contentMatch,a;return(a=i.findWrapping(e.type))?(this.match=i,a):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&yn)){let i=this.content[this.content.length-1],a;if(i&&i.isText&&(a=/[ \t\r\n\u000c]+$/.exec(i.text))){let o=i;i.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=X.from(this.content);return!e&&this.match&&(n=n.append(this.match.fillBefore(X.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,i=this.pendingMarks;n<i.length;n++){let a=i[n];(this.type?this.type.allowsMarkType(a.type):Bd(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&&!Ba.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class Va{constructor(e,n,i){this.parser=e,this.options=n,this.isOpen=i,this.open=0;let a=n.topNode,o,l=$a(null,n.preserveWhitespace,0)|(i?Qt:0);a?o=new vn(a.type,a.attrs,Be.none,Be.none,!0,n.topMatch||a.type.contentMatch,l):i?o=new vn(null,null,Be.none,Be.none,!0,null,l):o=new vn(e.schema.topNodeType,null,Be.none,Be.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 i=this.readStyles(Ld(n));if(!i)return;let[a,o]=i,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,i=this.top;if(i.options&bn||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(i.options&yn)i.options&bn?n=n.replace(/\r\n?/g,`
|
|
101
|
+
`):n=n.replace(/\r?\n|\r/g," ");else if(n=n.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let a=i.content[i.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 i=e.nodeName.toLowerCase(),a;Oa.hasOwnProperty(i)&&this.parser.normalizeLists&&Ed(e);let o=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(a=this.parser.matchTag(e,this,n));if(o?o.ignore:zd.hasOwnProperty(i))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(Ba.hasOwnProperty(i))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(`
|
|
102
|
+
`))}ignoreFallback(e){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"))}readStyles(e){let n=Be.none,i=Be.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)&&(i=u.addToSet(i))}):n=this.parser.schema.marks[l.mark].create(l.attrs).addToSet(n),l.consuming===!1)o=l;else break}return[n,i]}addElementByRule(e,n,i){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(i)this.addElement(e,i);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,i){let a=n||0;for(let o=n?e.childNodes[n]:e.firstChild,l=i==null?null:e.childNodes[i];o!=l;o=o.nextSibling,++a)this.findAtPoint(e,a),this.addDOM(o);this.findAtPoint(e,a)}findPlace(e){let n,i;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,i=o,!l.length)||o.solid)break}if(!n)return!1;this.sync(i);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 i=n.activeMarks;for(let a=0;a<e.marks.length;a++)(!n.type||n.type.allowsMarkType(e.marks[a].type))&&(i=e.marks[a].addToSet(i));return n.content.push(e.mark(i)),!0}return!1}enter(e,n,i){let a=this.findPlace(e.create(n));return a&&this.enterInner(e,n,!0,i),a}enterInner(e,n=null,i=!1,a){this.closeExtra();let o=this.top;o.applyPending(e),o.match=o.match&&o.match.matchType(e);let l=$a(e,a,o.options);o.options&Qt&&o.content.length==0&&(l|=Qt),this.nodes.push(new vn(e,n,o.activeMarks,o.pendingMarks,i,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 i=this.nodes[n].content;for(let a=i.length-1;a>=0;a--)e+=i[a].nodeSize;n&&e++}return e}findAtPoint(e,n){if(this.find)for(let i=0;i<this.find.length;i++)this.find[i].node==e&&this.find[i].offset==n&&(this.find[i].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,i){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)&(i?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("/"),i=this.options.context,a=!this.isOpen&&(!i||i.parent.type==this.nodes[0].type),o=-(i?i.depth+1:0)+(a?0:1),l=(u,c)=>{for(;u>=0;u--){let p=n[u];if(p==""){if(u==n.length-1||u==0)continue;for(;c>=o;c--)if(l(u-1,c))return!0;return!1}else{let h=c>0||c==0&&a?this.nodes[c].type:i&&c>=o?i.node(c-o).type:null;if(!h||h.name!=p&&h.groups.indexOf(p)==-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 i=e.node(n).contentMatchAt(e.indexAfter(n)).defaultType;if(i&&i.isTextblock&&i.defaultAttrs)return i}for(let n in this.parser.schema.nodes){let i=this.parser.schema.nodes[n];if(i.isTextblock&&i.defaultAttrs)return i}}addPendingMark(e){let n=Od(e,this.top.pendingMarks);n&&this.top.stashMarks.push(n),this.top.pendingMarks=e.addToSet(this.top.pendingMarks)}removePendingMark(e,n){for(let i=this.open;i>=0;i--){let a=this.nodes[i];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 Ed(t){for(let e=t.firstChild,n=null;e;e=e.nextSibling){let i=e.nodeType==1?e.nodeName.toLowerCase():null;i&&Oa.hasOwnProperty(i)&&n?(n.appendChild(e),e=n):i=="li"?n=e:i&&(n=null)}}function Pd(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function Ld(t){let e=/\s*([\w-]+)\s*:\s*([^;]+)/g,n,i=[];for(;n=e.exec(t);)i.push(n[1],n[2].trim());return i}function Na(t){let e={};for(let n in t)e[n]=t[n];return e}function Bd(t,e){let n=e.schema.nodes;for(let i in n){let a=n[i];if(!a.allowsMarkType(t))continue;let o=[],l=u=>{o.push(u);for(let c=0;c<u.edgeCount;c++){let{type:p,next:h}=u.edge(c);if(p==e||o.indexOf(h)<0&&l(h))return!0}};if(l(a.contentMatch))return!0}}function Od(t,e){for(let n=0;n<e.length;n++)if(t.eq(e[n]))return e[n]}const qa=65535,Ga=Math.pow(2,16);function $d(t,e){return t+e*Ga}function Fa(t){return t&qa}function Vd(t){return(t-(t&qa))/Ga}const ja=1,Wa=2,xn=4,Ra=8;class Qa{constructor(e,n,i){this.pos=e,this.delInfo=n,this.recover=i}get deleted(){return(this.delInfo&Ra)>0}get deletedBefore(){return(this.delInfo&(ja|xn))>0}get deletedAfter(){return(this.delInfo&(Wa|xn))>0}get deletedAcross(){return(this.delInfo&xn)>0}}class Ge{constructor(e,n=!1){if(this.ranges=e,this.inverted=n,!e.length&&Ge.empty)return Ge.empty}recover(e){let n=0,i=Fa(e);if(!this.inverted)for(let a=0;a<i;a++)n+=this.ranges[a*3+2]-this.ranges[a*3+1];return this.ranges[i*3]+n+Vd(e)}mapResult(e,n=1){return this._map(e,n,!1)}map(e,n=1){return this._map(e,n,!0)}_map(e,n,i){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 p=this.ranges[u+o],h=this.ranges[u+l],f=c+p;if(e<=f){let g=p?e==c?-1:e==f?1:n:n,b=c+a+(g<0?0:h);if(i)return b;let w=e==(n<0?c:f)?null:$d(u/3,e-c),_=e==c?Wa:e==f?ja:xn;return(n<0?e!=c:e!=f)&&(_|=Ra),new Qa(b,_,w)}a+=h-p}return i?e+a:new Qa(e+a,0,null)}touches(e,n){let i=0,a=Fa(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?i:0);if(c>e)break;let p=this.ranges[u+o],h=c+p;if(e<=h&&u==a*3)return!0;i+=this.ranges[u+l]-p}return!1}forEach(e){let n=this.inverted?2:1,i=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),p=this.ranges[a+n],h=this.ranges[a+i];e(u,u+p,c,c+h),o+=h-p}}invert(){return new Ge(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?Ge.empty:new Ge(e<0?[0,-e,0]:[0,0,e])}}Ge.empty=new Ge([]);const _r=Object.create(null);class Ae{getMap(){return Ge.empty}merge(e){return null}static fromJSON(e,n){if(!n||!n.stepType)throw new RangeError("Invalid input for Step.fromJSON");let i=_r[n.stepType];if(!i)throw new RangeError(`No step type ${n.stepType} defined`);return i.fromJSON(e,n)}static jsonID(e,n){if(e in _r)throw new RangeError("Duplicate use of step JSON ID "+e);return _r[e]=n,n.prototype.jsonID=e,n}}class fe{constructor(e,n){this.doc=e,this.failed=n}static ok(e){return new fe(e,null)}static fail(e){return new fe(null,e)}static fromReplace(e,n,i,a){try{return fe.ok(e.replace(n,i,a))}catch(o){if(o instanceof Ad)return fe.fail(o.message);throw o}}}function kr(t,e,n){let i=[];for(let a=0;a<t.childCount;a++){let o=t.child(a);o.content.size&&(o=o.copy(kr(o.content,e,o))),o.isInline&&(o=e(o,n,a)),i.push(o)}return X.fromArray(i)}class bt extends Ae{constructor(e,n,i){super(),this.from=e,this.to=n,this.mark=i}apply(e){let n=e.slice(this.from,this.to),i=e.resolve(this.from),a=i.node(i.sharedDepth(this.to)),o=new te(kr(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 fe.fromReplace(e,this.from,this.to,o)}invert(){return new vt(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),i=e.mapResult(this.to,-1);return n.deleted&&i.deleted||n.pos>=i.pos?null:new bt(n.pos,i.pos,this.mark)}merge(e){return e instanceof bt&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new bt(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 bt(n.from,n.to,e.markFromJSON(n.mark))}}Ae.jsonID("addMark",bt);class vt extends Ae{constructor(e,n,i){super(),this.from=e,this.to=n,this.mark=i}apply(e){let n=e.slice(this.from,this.to),i=new te(kr(n.content,a=>a.mark(this.mark.removeFromSet(a.marks)),e),n.openStart,n.openEnd);return fe.fromReplace(e,this.from,this.to,i)}invert(){return new bt(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),i=e.mapResult(this.to,-1);return n.deleted&&i.deleted||n.pos>=i.pos?null:new vt(n.pos,i.pos,this.mark)}merge(e){return e instanceof vt&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new vt(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 vt(n.from,n.to,e.markFromJSON(n.mark))}}Ae.jsonID("removeMark",vt);class xt extends Ae{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return fe.fail("No node at mark step's position");let i=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return fe.fromReplace(e,this.pos,this.pos+1,new te(X.from(i),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);if(n){let i=this.mark.addToSet(n.marks);if(i.length==n.marks.length){for(let a=0;a<n.marks.length;a++)if(!n.marks[a].isInSet(i))return new xt(this.pos,n.marks[a]);return new xt(this.pos,this.mark)}}return new Ut(this.pos,this.mark)}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new xt(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 xt(n.pos,e.markFromJSON(n.mark))}}Ae.jsonID("addNodeMark",xt);class Ut extends Ae{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return fe.fail("No node at mark step's position");let i=n.type.create(n.attrs,null,this.mark.removeFromSet(n.marks));return fe.fromReplace(e,this.pos,this.pos+1,new te(X.from(i),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);return!n||!this.mark.isInSet(n.marks)?this:new xt(this.pos,this.mark)}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new Ut(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 Ut(n.pos,e.markFromJSON(n.mark))}}Ae.jsonID("removeNodeMark",Ut);class He extends Ae{constructor(e,n,i,a=!1){super(),this.from=e,this.to=n,this.slice=i,this.structure=a}apply(e){return this.structure&&Tr(e,this.from,this.to)?fe.fail("Structure replace would overwrite content"):fe.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new Ge([this.from,this.to-this.from,this.slice.size])}invert(e){return new He(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let n=e.mapResult(this.from,1),i=e.mapResult(this.to,-1);return n.deletedAcross&&i.deletedAcross?null:new He(n.pos,Math.max(n.pos,i.pos),this.slice)}merge(e){if(!(e instanceof He)||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?te.empty:new te(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new He(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?te.empty:new te(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new He(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 He(n.from,n.to,te.fromJSON(e,n.slice),!!n.structure)}}Ae.jsonID("replace",He);class wt extends Ae{constructor(e,n,i,a,o,l,u=!1){super(),this.from=e,this.to=n,this.gapFrom=i,this.gapTo=a,this.slice=o,this.insert=l,this.structure=u}apply(e){if(this.structure&&(Tr(e,this.from,this.gapFrom)||Tr(e,this.gapTo,this.to)))return fe.fail("Structure gap-replace would overwrite content");let n=e.slice(this.gapFrom,this.gapTo);if(n.openStart||n.openEnd)return fe.fail("Gap is not a flat range");let i=this.slice.insertAt(this.insert,n.content);return i?fe.fromReplace(e,this.from,this.to,i):fe.fail("Content does not fit in gap")}getMap(){return new Ge([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 wt(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),i=e.mapResult(this.to,-1),a=e.map(this.gapFrom,-1),o=e.map(this.gapTo,1);return n.deletedAcross&&i.deletedAcross||a<n.pos||o>i.pos?null:new wt(n.pos,i.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 wt(n.from,n.to,n.gapFrom,n.gapTo,te.fromJSON(e,n.slice),n.insert,!!n.structure)}}Ae.jsonID("replaceAround",wt);function Tr(t,e,n){let i=t.resolve(e),a=n-e,o=i.depth;for(;a>0&&o>0&&i.indexAfter(o)==i.node(o).childCount;)o--,a--;if(a>0){let l=i.node(o).maybeChild(i.indexAfter(o));for(;a>0;){if(!l||l.isLeaf)return!0;l=l.firstChild,a--}}return!1}function Nd(t,e,n){return(e==0||t.canReplace(e,t.childCount))&&(n==t.childCount||t.canReplace(0,n))}function qd(t){let n=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let i=t.depth;;--i){let a=t.$from.node(i),o=t.$from.index(i),l=t.$to.indexAfter(i);if(i<t.depth&&a.canReplace(o,l,n))return i;if(i==0||a.type.spec.isolating||!Nd(a,o,l))break}return null}function wn(t,e,n=1,i){let a=t.resolve(e),o=a.depth-n,l=i&&i[i.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 p=a.depth-1,h=n-2;p>o;p--,h--){let f=a.node(p),g=a.index(p);if(f.type.spec.isolating)return!1;let b=f.content.cutByIndex(g,f.childCount),w=i&&i[h+1];w&&(b=b.replaceChild(0,w.type.create(w.attrs)));let _=i&&i[h]||f;if(!f.canReplace(g+1,f.childCount)||!_.type.validContent(b))return!1}let u=a.indexAfter(o),c=i&&i[0];return a.node(o).canReplaceWith(u,u,c?c.type:a.node(o+1).type)}function Ua(t,e){let n=t.resolve(e),i=n.index();return Gd(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(i,i+1)}function Gd(t,e){return!!(t&&e&&!t.isLeaf&&t.canAppend(e))}class Kt extends Ae{constructor(e,n,i){super(),this.pos=e,this.attr=n,this.value=i}apply(e){let n=e.nodeAt(this.pos);if(!n)return fe.fail("No node at attribute step's position");let i=Object.create(null);for(let o in n.attrs)i[o]=n.attrs[o];i[this.attr]=this.value;let a=n.type.create(i,null,n.marks);return fe.fromReplace(e,this.pos,this.pos+1,new te(X.from(a),0,n.isLeaf?0:1))}getMap(){return Ge.empty}invert(e){return new Kt(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 Kt(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 Kt(n.pos,n.attr,n.value)}}Ae.jsonID("attr",Kt);let Yt=class extends Error{};Yt=function t(e){let n=Error.call(this,e);return n.__proto__=t.prototype,n},Yt.prototype=Object.create(Error.prototype),Yt.prototype.constructor=Yt,Yt.prototype.name="TransformError";const Dr=Object.create(null);class ie{constructor(e,n,i){this.$anchor=e,this.$head=n,this.ranges=i||[new Fd(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=te.empty){let i=n.content.lastChild,a=null;for(let u=0;u<n.openEnd;u++)a=i,i=i.lastChild;let o=e.steps.length,l=this.ranges;for(let u=0;u<l.length;u++){let{$from:c,$to:p}=l[u],h=e.mapping.slice(o);e.replaceRange(h.map(c.pos),h.map(p.pos),u?te.empty:n),u==0&&Xa(e,o,(i?i.isInline:a&&a.isTextblock)?-1:1)}}replaceWith(e,n){let i=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(i),p=c.map(l.pos),h=c.map(u.pos);o?e.deleteRange(p,h):(e.replaceRangeWith(p,h,n),Xa(e,i,n.isInline?-1:1))}}static findFrom(e,n,i=!1){let a=e.parent.inlineContent?new ge(e):It(e.node(0),e.parent,e.pos,e.index(),n,i);if(a)return a;for(let o=e.depth-1;o>=0;o--){let l=n<0?It(e.node(0),e.node(o),e.before(o+1),e.index(o),n,i):It(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,n,i);if(l)return l}return null}static near(e,n=1){return this.findFrom(e,n)||this.findFrom(e,-n)||new st(e.node(0))}static atStart(e){return It(e,e,0,0,1)||new st(e)}static atEnd(e){return It(e,e,e.content.size,e.childCount,-1)||new st(e)}static fromJSON(e,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let i=Dr[n.type];if(!i)throw new RangeError(`No selection type ${n.type} defined`);return i.fromJSON(e,n)}static jsonID(e,n){if(e in Dr)throw new RangeError("Duplicate use of selection JSON ID "+e);return Dr[e]=n,n.prototype.jsonID=e,n}getBookmark(){return ge.between(this.$anchor,this.$head).getBookmark()}}ie.prototype.visible=!0;class Fd{constructor(e,n){this.$from=e,this.$to=n}}let Ka=!1;function Ya(t){!Ka&&!t.parent.inlineContent&&(Ka=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")"))}class ge extends ie{constructor(e,n=e){Ya(e),Ya(n),super(e,n)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,n){let i=e.resolve(n.map(this.head));if(!i.parent.inlineContent)return ie.near(i);let a=e.resolve(n.map(this.anchor));return new ge(a.parent.inlineContent?a:i,i)}replace(e,n=te.empty){if(super.replace(e,n),n==te.empty){let i=this.$from.marksAcross(this.$to);i&&e.ensureMarks(i)}}eq(e){return e instanceof ge&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Cn(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 ge(e.resolve(n.anchor),e.resolve(n.head))}static create(e,n,i=n){let a=e.resolve(n);return new this(a,i==n?a:e.resolve(i))}static between(e,n,i){let a=e.pos-n.pos;if((!i||a)&&(i=a>=0?1:-1),!n.parent.inlineContent){let o=ie.findFrom(n,i,!0)||ie.findFrom(n,-i,!0);if(o)n=o.$head;else return ie.near(n,i)}return e.parent.inlineContent||(a==0?e=n:(e=(ie.findFrom(e,-i,!0)||ie.findFrom(e,i,!0)).$anchor,e.pos<n.pos!=a<0&&(e=n))),new ge(e,n)}}ie.jsonID("text",ge);class Cn{constructor(e,n){this.anchor=e,this.head=n}map(e){return new Cn(e.map(this.anchor),e.map(this.head))}resolve(e){return ge.between(e.resolve(this.anchor),e.resolve(this.head))}}class Oe extends ie{constructor(e){let n=e.nodeAfter,i=e.node(0).resolve(e.pos+n.nodeSize);super(e,i),this.node=n}map(e,n){let{deleted:i,pos:a}=n.mapResult(this.anchor),o=e.resolve(a);return i?ie.near(o):new Oe(o)}content(){return new te(X.from(this.node),0,0)}eq(e){return e instanceof Oe&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new Ir(this.anchor)}static fromJSON(e,n){if(typeof n.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new Oe(e.resolve(n.anchor))}static create(e,n){return new Oe(e.resolve(n))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}}Oe.prototype.visible=!1,ie.jsonID("node",Oe);class Ir{constructor(e){this.anchor=e}map(e){let{deleted:n,pos:i}=e.mapResult(this.anchor);return n?new Cn(i,i):new Ir(i)}resolve(e){let n=e.resolve(this.anchor),i=n.nodeAfter;return i&&Oe.isSelectable(i)?new Oe(n):ie.near(n)}}class st extends ie{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,n=te.empty){if(n==te.empty){e.delete(0,e.doc.content.size);let i=ie.atStart(e.doc);i.eq(e.selection)||e.setSelection(i)}else super.replace(e,n)}toJSON(){return{type:"all"}}static fromJSON(e){return new st(e)}map(e){return new st(e)}eq(e){return e instanceof st}getBookmark(){return jd}}ie.jsonID("all",st);const jd={map(){return this},resolve(t){return new st(t)}};function It(t,e,n,i,a,o=!1){if(e.inlineContent)return ge.create(t,n);for(let l=i-(a>0?0:1);a>0?l<e.childCount:l>=0;l+=a){let u=e.child(l);if(u.isAtom){if(!o&&Oe.isSelectable(u))return Oe.create(t,n-(a<0?u.nodeSize:0))}else{let c=It(t,u,n+a,a<0?u.childCount:0,a,o);if(c)return c}n+=u.nodeSize*a}return null}function Xa(t,e,n){let i=t.steps.length-1;if(i<e)return;let a=t.steps[i];if(!(a instanceof He||a instanceof wt))return;let o=t.mapping.maps[i],l;o.forEach((u,c,p,h)=>{l==null&&(l=h)}),t.setSelection(ie.near(t.doc.resolve(l),n))}function Ja(t,e){return!e||!t?t:t.bind(e)}class Sn{constructor(e,n,i){this.name=e,this.init=Ja(n.init,i),this.apply=Ja(n.apply,i)}}new Sn("doc",{init(t){return t.doc||t.schema.topNodeType.createAndFill()},apply(t){return t.doc}}),new Sn("selection",{init(t,e){return t.selection||ie.atStart(e.doc)},apply(t){return t.selection}}),new Sn("storedMarks",{init(t){return t.storedMarks||null},apply(t,e,n,i){return i.selection.$cursor?t.storedMarks:null}}),new Sn("scrollToSelection",{init(){return 0},apply(t,e){return t.scrolledIntoView?e+1:e}});function Za(t,e,n){for(let i in t){let a=t[i];a instanceof Function?a=a.bind(e):i=="handleDOMEvents"&&(a=Za(a,e,{})),n[i]=a}return n}class Xt{constructor(e){this.spec=e,this.props={},e.props&&Za(e.props,this,this.props),this.key=e.key?e.key.key:Ha("plugin")}getState(e){return e[this.key]}}const Mr=Object.create(null);function Ha(t){return t in Mr?t+"$"+ ++Mr[t]:(Mr[t]=0,t+"$")}class Jt{constructor(e="key"){this.key=Ha(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}function es(t){const{state:e,transaction:n}=t;let{selection:i}=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 i},get doc(){return a},get tr(){return i=n.selection,a=n.doc,o=n.storedMarks,n}}}class Wd{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:i}=this,{view:a}=n,{tr:o}=i,l=this.buildProps(o);return Object.fromEntries(Object.entries(e).map(([u,c])=>[u,(...h)=>{const f=c(...h)(l);return!o.getMeta("preventDispatch")&&!this.hasCustomState&&a.dispatch(o),f}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,n=!0){const{rawCommands:i,editor:a,state:o}=this,{view:l}=a,u=[],c=!!e,p=e||o.tr,h=()=>(!c&&n&&!p.getMeta("preventDispatch")&&!this.hasCustomState&&l.dispatch(p),u.every(g=>g===!0)),f={...Object.fromEntries(Object.entries(i).map(([g,b])=>[g,(..._)=>{const D=this.buildProps(p,n),L=b(..._)(D);return u.push(L),f}])),run:h};return f}createCan(e){const{rawCommands:n,state:i}=this,a=!1,o=e||i.tr,l=this.buildProps(o,a);return{...Object.fromEntries(Object.entries(n).map(([c,p])=>[c,(...h)=>p(...h)({...l,dispatch:void 0})])),chain:()=>this.createChain(o,a)}}buildProps(e,n=!0){const{rawCommands:i,editor:a,state:o}=this,{view:l}=a;o.storedMarks&&e.setStoredMarks(o.storedMarks);const u={tr:e,editor:a,view:l,state:es({state:o,transaction:e}),dispatch:n?()=>{}:void 0,chain:()=>this.createChain(e),can:()=>this.createCan(e),get commands(){return Object.fromEntries(Object.entries(i).map(([c,p])=>[c,(...h)=>p(...h)(u)]))}};return u}}function pt(t,e,n){return t.config[e]===void 0&&t.parent?pt(t.parent,e,n):typeof t.config[e]=="function"?t.config[e].bind({...n,parent:t.parent?pt(t.parent,e,n):null}):t.config[e]}function Rd(t){const e=t.filter(a=>a.type==="extension"),n=t.filter(a=>a.type==="node"),i=t.filter(a=>a.type==="mark");return{baseExtensions:e,nodeExtensions:n,markExtensions:i}}function Ce(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 Qd(t){return typeof t=="function"}function Mt(t,e=void 0,...n){return Qd(t)?e?t.bind(e)(...n):t(...n):t}function Ud(t){return Object.prototype.toString.call(t)==="[object RegExp]"}function Kd(t){return Object.prototype.toString.call(t).slice(8,-1)}function Ar(t){return Kd(t)!=="Object"?!1:t.constructor===Object&&Object.getPrototypeOf(t)===Object.prototype}function ts(t,e){const n={...t};return Ar(t)&&Ar(e)&&Object.keys(e).forEach(i=>{Ar(e[i])?i in t?n[i]=ts(t[i],e[i]):Object.assign(n,{[i]:e[i]}):Object.assign(n,{[i]:e[i]})}),n}class et{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=Mt(pt(this,"addOptions",{name:this.name}))),this.storage=Mt(pt(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new et(e)}configure(e={}){const n=this.extend();return n.options=ts(this.options,e),n.storage=Mt(pt(n,"addStorage",{name:n.name,options:n.options})),n}extend(e={}){const n=new et(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=Mt(pt(n,"addOptions",{name:n.name})),n.storage=Mt(pt(n,"addStorage",{name:n.name,options:n.options})),n}}function Yd(t,e,n){const{from:i,to:a}=e,{blockSeparator:o=`
|
|
103
103
|
|
|
104
|
-
`,textSerializers:l={}}=n||{};let u="",c=!0;return e.nodesBetween(r,a,(d,f,h,g)=>{var y;const C=l==null?void 0:l[d.type.name];C?(d.isBlock&&!c&&(u+=o,c=!0),h&&(u+=C({node:d,pos:f,parent:h,index:g,range:t}))):d.isText?(u+=(y=d==null?void 0:d.text)===null||y===void 0?void 0:y.slice(Math.max(r,f)-f,a-f),c=!1):d.isBlock&&!c&&(u+=o,c=!0)}),u}function np(e){return Object.fromEntries(Object.entries(e.nodes).filter(([,t])=>t.spec.toText).map(([t,n])=>[t,n.spec.toText]))}ut.create({name:"clipboardTextSerializer",addProseMirrorPlugins(){return[new fn({key:new gn("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:e}=this,{state:t,schema:n}=e,{doc:r,selection:a}=t,{ranges:o}=a,l=Math.min(...o.map(f=>f.$from.pos)),u=Math.max(...o.map(f=>f.$to.pos)),c=np(n);return tp(r,{from:l,to:u},{textSerializers:c})}}})]}});const rp=()=>({editor:e,view:t})=>(requestAnimationFrame(()=>{var n;e.isDestroyed||(t.dom.blur(),(n=window==null?void 0:window.getSelection())===null||n===void 0||n.removeAllRanges())}),!0),ip=(e=!1)=>({commands:t})=>t.setContent("",e),ap=()=>({state:e,tr:t,dispatch:n})=>{const{selection:r}=t,{ranges:a}=r;return n&&a.forEach(({$from:o,$to:l})=>{e.doc.nodesBetween(o.pos,l.pos,(u,c)=>{if(u.type.isText)return;const{doc:d,mapping:f}=t,h=d.resolve(f.map(c)),g=d.resolve(f.map(c+u.nodeSize)),y=h.blockRange(g);if(!y)return;const C=Yd(y);if(u.type.isTextblock){const{defaultType:w}=h.parent.contentMatchAt(h.index());t.setNodeMarkup(y.start,w)}(C||C===0)&&t.lift(y,C)})}),!0},sp=e=>t=>e(t),op=()=>({state:e,dispatch:t})=>ke.createParagraphNear(e,t),lp=()=>({tr:e,dispatch:t})=>{const{selection:n}=e,r=n.$anchor.node();if(r.content.size>0)return!1;const a=e.selection.$anchor;for(let o=a.depth;o>0;o-=1)if(a.node(o).type===r.type){if(t){const u=a.before(o),c=a.after(o);e.delete(u,c).scrollIntoView()}return!0}return!1},up=e=>({tr:t,state:n,dispatch:r})=>{const a=Me(e,n.schema),o=t.selection.$anchor;for(let l=o.depth;l>0;l-=1)if(o.node(l).type===a){if(r){const c=o.before(l),d=o.after(l);t.delete(c,d).scrollIntoView()}return!0}return!1},cp=e=>({tr:t,dispatch:n})=>{const{from:r,to:a}=e;return n&&t.delete(r,a),!0},dp=()=>({state:e,dispatch:t})=>ke.deleteSelection(e,t),pp=()=>({commands:e})=>e.keyboardShortcut("Enter"),hp=()=>({state:e,dispatch:t})=>ke.exitCode(e,t);function Wn(e,t,n={strict:!0}){const r=Object.keys(t);return r.length?r.every(a=>n.strict?t[a]===e[a]:Hd(t[a])?t[a].test(e[a]):t[a]===e[a]):!0}function Ur(e,t,n={}){return e.find(r=>r.type===t&&Wn(r.attrs,n))}function fp(e,t,n={}){return!!Ur(e,t,n)}function Xs(e,t,n={}){if(!e||!t)return;let r=e.parent.childAfter(e.parentOffset);if(e.parentOffset===r.offset&&r.offset!==0&&(r=e.parent.childBefore(e.parentOffset)),!r.node)return;const a=Ur([...r.node.marks],t,n);if(!a)return;let o=r.index,l=e.start()+r.offset,u=o+1,c=l+r.node.nodeSize;for(Ur([...r.node.marks],t,n);o>0&&a.isInSet(e.parent.child(o-1).marks);)o-=1,l-=e.parent.child(o).nodeSize;for(;u<e.parent.childCount&&fp([...e.parent.child(u).marks],t,n);)c+=e.parent.child(u).nodeSize,u+=1;return{from:l,to:c}}function _t(e,t){if(typeof e=="string"){if(!t.marks[e])throw Error(`There is no mark type named '${e}'. Maybe you forgot to add the extension?`);return t.marks[e]}return e}const gp=(e,t={})=>({tr:n,state:r,dispatch:a})=>{const o=_t(e,r.schema),{doc:l,selection:u}=n,{$from:c,from:d,to:f}=u;if(a){const h=Xs(c,o,t);if(h&&h.from<=d&&h.to>=f){const g=Se.create(l,h.from,h.to);n.setSelection(g)}}return!0},mp=e=>t=>{const n=typeof e=="function"?e(t):e;for(let r=0;r<n.length;r+=1)if(n[r](t))return!0;return!1};function Js(e){return e instanceof Se}function Ot(e=0,t=0,n=0){return Math.min(Math.max(e,t),n)}function yp(e,t=null){if(!t)return null;const n=fe.atStart(e),r=fe.atEnd(e);if(t==="start"||t===!0)return n;if(t==="end")return r;const a=n.from,o=r.to;return t==="all"?Se.create(e,Ot(0,a,o),Ot(e.content.size,a,o)):Se.create(e,Ot(t,a,o),Ot(t,a,o))}function Kr(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}const bp=(e=null,t={})=>({editor:n,view:r,tr:a,dispatch:o})=>{t={scrollIntoView:!0,...t};const l=()=>{Kr()&&r.dom.focus(),requestAnimationFrame(()=>{n.isDestroyed||(r.focus(),t!=null&&t.scrollIntoView&&n.commands.scrollIntoView())})};if(r.hasFocus()&&e===null||e===!1)return!0;if(o&&e===null&&!Js(n.state.selection))return l(),!0;const u=yp(a.doc,e)||n.state.selection,c=n.state.selection.eq(u);return o&&(c||a.setSelection(u),c&&a.storedMarks&&a.setStoredMarks(a.storedMarks),l()),!0},vp=(e,t)=>n=>e.every((r,a)=>t(r,{...n,index:a})),xp=(e,t)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},e,t);function Zs(e){const t=`<body>${e}</body>`;return new window.DOMParser().parseFromString(t,"text/html").body}function jn(e,t,n){if(n={slice:!0,parseOptions:{},...n},typeof e=="object"&&e!==null)try{return Array.isArray(e)&&e.length>0?ae.fromArray(e.map(r=>t.nodeFromJSON(r))):t.nodeFromJSON(e)}catch(r){return console.warn("[tiptap warn]: Invalid content.","Passed value:",e,"Error:",r),jn("",t,n)}if(typeof e=="string"){const r=Pn.fromSchema(t);return n.slice?r.parseSlice(Zs(e),n.parseOptions).content:r.parse(Zs(e),n.parseOptions)}return jn("",t,n)}function wp(e,t,n){const r=e.steps.length-1;if(r<t)return;const a=e.steps[r];if(!(a instanceof lt||a instanceof Pt))return;const o=e.mapping.maps[r];let l=0;o.forEach((u,c,d,f)=>{l===0&&(l=f)}),e.setSelection(fe.near(e.doc.resolve(l),n))}const Cp=e=>e.toString().startsWith("<"),Sp=(e,t,n)=>({tr:r,dispatch:a,editor:o})=>{if(a){n={parseOptions:{},updateSelection:!0,...n};const l=jn(t,o.schema,{parseOptions:{preserveWhitespace:"full",...n.parseOptions}});if(l.toString()==="<>")return!0;let{from:u,to:c}=typeof e=="number"?{from:e,to:e}:e,d=!0,f=!0;if((Cp(l)?l:[l]).forEach(g=>{g.check(),d=d?g.isText&&g.marks.length===0:!1,f=f?g.isBlock:!1}),u===c&&f){const{parent:g}=r.doc.resolve(u);g.isTextblock&&!g.type.spec.code&&!g.childCount&&(u-=1,c+=1)}d?Array.isArray(t)?r.insertText(t.map(g=>g.text||"").join(""),u,c):typeof t=="object"&&t&&t.text?r.insertText(t.text,u,c):r.insertText(t,u,c):r.replaceWith(u,c,l),n.updateSelection&&wp(r,r.steps.length-1,-1)}return!0},_p=()=>({state:e,dispatch:t})=>ke.joinUp(e,t),kp=()=>({state:e,dispatch:t})=>ke.joinDown(e,t),Tp=()=>({state:e,dispatch:t})=>ke.joinBackward(e,t),Dp=()=>({state:e,dispatch:t})=>ke.joinForward(e,t);function Hs(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function Ip(e){const t=e.split(/-(?!$)/);let n=t[t.length-1];n==="Space"&&(n=" ");let r,a,o,l;for(let u=0;u<t.length-1;u+=1){const c=t[u];if(/^(cmd|meta|m)$/i.test(c))l=!0;else if(/^a(lt)?$/i.test(c))r=!0;else if(/^(c|ctrl|control)$/i.test(c))a=!0;else if(/^s(hift)?$/i.test(c))o=!0;else if(/^mod$/i.test(c))Kr()||Hs()?l=!0:a=!0;else throw new Error(`Unrecognized modifier name: ${c}`)}return r&&(n=`Alt-${n}`),a&&(n=`Ctrl-${n}`),l&&(n=`Meta-${n}`),o&&(n=`Shift-${n}`),n}const Mp=e=>({editor:t,view:n,tr:r,dispatch:a})=>{const o=Ip(e).split(/-(?!$)/),l=o.find(d=>!["Alt","Ctrl","Meta","Shift"].includes(d)),u=new KeyboardEvent("keydown",{key:l==="Space"?" ":l,altKey:o.includes("Alt"),ctrlKey:o.includes("Ctrl"),metaKey:o.includes("Meta"),shiftKey:o.includes("Shift"),bubbles:!0,cancelable:!0}),c=t.captureTransaction(()=>{n.someProp("handleKeyDown",d=>d(n,u))});return c==null||c.steps.forEach(d=>{const f=d.map(r.mapping);f&&a&&r.maybeStep(f)}),!0};function Xr(e,t,n={}){const{from:r,to:a,empty:o}=e.selection,l=t?Me(t,e.schema):null,u=[];e.doc.nodesBetween(r,a,(h,g)=>{if(h.isText)return;const y=Math.max(r,g),C=Math.min(a,g+h.nodeSize);u.push({node:h,from:y,to:C})});const c=a-r,d=u.filter(h=>l?l.name===h.node.type.name:!0).filter(h=>Wn(h.node.attrs,n,{strict:!1}));return o?!!d.length:d.reduce((h,g)=>h+g.to-g.from,0)>=c}const Ap=(e,t={})=>({state:n,dispatch:r})=>{const a=Me(e,n.schema);return Xr(n,a,t)?ke.lift(n,r):!1},zp=()=>({state:e,dispatch:t})=>ke.liftEmptyBlock(e,t),Ep=e=>({state:t,dispatch:n})=>{const r=Me(e,t.schema);return br.liftListItem(r)(t,n)},$p=()=>({state:e,dispatch:t})=>ke.newlineInCode(e,t);function eo(e,t){return t.nodes[e]?"node":t.marks[e]?"mark":null}function to(e,t){const n=typeof t=="string"?[t]:t;return Object.keys(e).reduce((r,a)=>(n.includes(a)||(r[a]=e[a]),r),{})}const Lp=(e,t)=>({tr:n,state:r,dispatch:a})=>{let o=null,l=null;const u=eo(typeof e=="string"?e:e.name,r.schema);return u?(u==="node"&&(o=Me(e,r.schema)),u==="mark"&&(l=_t(e,r.schema)),a&&n.selection.ranges.forEach(c=>{r.doc.nodesBetween(c.$from.pos,c.$to.pos,(d,f)=>{o&&o===d.type&&n.setNodeMarkup(f,void 0,to(d.attrs,t)),l&&d.marks.length&&d.marks.forEach(h=>{l===h.type&&n.addMark(f,f+d.nodeSize,l.create(to(h.attrs,t)))})})}),!0):!1},Pp=()=>({tr:e,dispatch:t})=>(t&&e.scrollIntoView(),!0),Op=()=>({tr:e,commands:t})=>t.setTextSelection({from:0,to:e.doc.content.size}),Bp=()=>({state:e,dispatch:t})=>ke.selectNodeBackward(e,t),Vp=()=>({state:e,dispatch:t})=>ke.selectNodeForward(e,t),Np=()=>({state:e,dispatch:t})=>ke.selectParentNode(e,t),qp=()=>({state:e,dispatch:t})=>ke.selectTextblockEnd(e,t),Fp=()=>({state:e,dispatch:t})=>ke.selectTextblockStart(e,t);function Gp(e,t,n={}){return jn(e,t,{slice:!1,parseOptions:n})}const Wp=(e,t=!1,n={})=>({tr:r,editor:a,dispatch:o})=>{const{doc:l}=r,u=Gp(e,a.schema,n);return o&&r.replaceWith(0,l.content.size,u).setMeta("preventUpdate",!t),!0};function jp(e){for(let t=0;t<e.edgeCount;t+=1){const{type:n}=e.edge(t);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}function Rp(e,t){for(let n=e.depth;n>0;n-=1){const r=e.node(n);if(t(r))return{pos:n>0?e.before(n):0,start:e.start(n),depth:n,node:r}}}function Jr(e){return t=>Rp(t.$from,e)}function Yp(e,t){const n=_t(t,e.schema),{from:r,to:a,empty:o}=e.selection,l=[];o?(e.storedMarks&&l.push(...e.storedMarks),l.push(...e.selection.$head.marks())):e.doc.nodesBetween(r,a,c=>{l.push(...c.marks)});const u=l.find(c=>c.type.name===n.name);return u?{...u.attrs}:{}}function Rn(e,t,n){return Object.fromEntries(Object.entries(n).filter(([r])=>{const a=e.find(o=>o.type===t&&o.name===r);return a?a.attribute.keepOnSplit:!1}))}function Qp(e,t,n={}){const{empty:r,ranges:a}=e.selection,o=t?_t(t,e.schema):null;if(r)return!!(e.storedMarks||e.selection.$from.marks()).filter(h=>o?o.name===h.type.name:!0).find(h=>Wn(h.attrs,n,{strict:!1}));let l=0;const u=[];if(a.forEach(({$from:h,$to:g})=>{const y=h.pos,C=g.pos;e.doc.nodesBetween(y,C,(w,_)=>{if(!w.isText&&!w.marks.length)return;const D=Math.max(y,_),M=Math.min(C,_+w.nodeSize),O=M-D;l+=O,u.push(...w.marks.map(G=>({mark:G,from:D,to:M})))})}),l===0)return!1;const c=u.filter(h=>o?o.name===h.mark.type.name:!0).filter(h=>Wn(h.mark.attrs,n,{strict:!1})).reduce((h,g)=>h+g.to-g.from,0),d=u.filter(h=>o?h.mark.type!==o&&h.mark.type.excludes(o):!0).reduce((h,g)=>h+g.to-g.from,0);return(c>0?c+d:c)>=l}function no(e,t){const{nodeExtensions:n}=Jd(t),r=n.find(l=>l.name===e);if(!r)return!1;const a={name:r.name,options:r.options,storage:r.storage},o=Wt(St(r,"group",a));return typeof o!="string"?!1:o.split(" ").includes("list")}function Up(e,t,n){var r;const{selection:a}=t;let o=null;if(Js(a)&&(o=a.$cursor),o){const u=(r=e.storedMarks)!==null&&r!==void 0?r:o.marks();return!!n.isInSet(u)||!u.some(c=>c.type.excludes(n))}const{ranges:l}=a;return l.some(({$from:u,$to:c})=>{let d=u.depth===0?e.doc.inlineContent&&e.doc.type.allowsMarkType(n):!1;return e.doc.nodesBetween(u.pos,c.pos,(f,h,g)=>{if(d)return!1;if(f.isInline){const y=!g||g.type.allowsMarkType(n),C=!!n.isInSet(f.marks)||!f.marks.some(w=>w.type.excludes(n));d=y&&C}return!d}),d})}const Kp=(e,t={})=>({tr:n,state:r,dispatch:a})=>{const{selection:o}=n,{empty:l,ranges:u}=o,c=_t(e,r.schema);if(a)if(l){const d=Yp(r,c);n.addStoredMark(c.create({...d,...t}))}else u.forEach(d=>{const f=d.$from.pos,h=d.$to.pos;r.doc.nodesBetween(f,h,(g,y)=>{const C=Math.max(y,f),w=Math.min(y+g.nodeSize,h);g.marks.find(D=>D.type===c)?g.marks.forEach(D=>{c===D.type&&n.addMark(C,w,c.create({...D.attrs,...t}))}):n.addMark(C,w,c.create(t))})});return Up(r,n,c)},Xp=(e,t)=>({tr:n})=>(n.setMeta(e,t),!0),Jp=(e,t={})=>({state:n,dispatch:r,chain:a})=>{const o=Me(e,n.schema);return o.isTextblock?a().command(({commands:l})=>ke.setBlockType(o,t)(n)?!0:l.clearNodes()).command(({state:l})=>ke.setBlockType(o,t)(l,r)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},Zp=e=>({tr:t,dispatch:n})=>{if(n){const{doc:r}=t,a=Ot(e,0,r.content.size),o=Re.create(r,a);t.setSelection(o)}return!0},Hp=e=>({tr:t,dispatch:n})=>{if(n){const{doc:r}=t,{from:a,to:o}=typeof e=="number"?{from:e,to:e}:e,l=Se.atStart(r).from,u=Se.atEnd(r).to,c=Ot(a,l,u),d=Ot(o,l,u),f=Se.create(r,c,d);t.setSelection(f)}return!0},eh=e=>({state:t,dispatch:n})=>{const r=Me(e,t.schema);return br.sinkListItem(r)(t,n)};function ro(e,t){const n=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();if(n){const r=n.filter(a=>t==null?void 0:t.includes(a.type.name));e.tr.ensureMarks(r)}}const th=({keepMarks:e=!0}={})=>({tr:t,state:n,dispatch:r,editor:a})=>{const{selection:o,doc:l}=t,{$from:u,$to:c}=o,d=a.extensionManager.attributes,f=Rn(d,u.node().type.name,u.node().attrs);if(o instanceof Re&&o.node.isBlock)return!u.parentOffset||!qn(l,u.pos)?!1:(r&&(e&&ro(n,a.extensionManager.splittableMarks),t.split(u.pos).scrollIntoView()),!0);if(!u.parent.isBlock)return!1;if(r){const h=c.parentOffset===c.parent.content.size;o instanceof Se&&t.deleteSelection();const g=u.depth===0?void 0:jp(u.node(-1).contentMatchAt(u.indexAfter(-1)));let y=h&&g?[{type:g,attrs:f}]:void 0,C=qn(t.doc,t.mapping.map(u.pos),1,y);if(!y&&!C&&qn(t.doc,t.mapping.map(u.pos),1,g?[{type:g}]:void 0)&&(C=!0,y=g?[{type:g,attrs:f}]:void 0),C&&(t.split(t.mapping.map(u.pos),1,y),g&&!h&&!u.parentOffset&&u.parent.type!==g)){const w=t.mapping.map(u.before()),_=t.doc.resolve(w);u.node(-1).canReplaceWith(_.index(),_.index()+1,g)&&t.setNodeMarkup(t.mapping.map(u.before()),g)}e&&ro(n,a.extensionManager.splittableMarks),t.scrollIntoView()}return!0},nh=e=>({tr:t,state:n,dispatch:r,editor:a})=>{var o;const l=Me(e,n.schema),{$from:u,$to:c}=n.selection,d=n.selection.node;if(d&&d.isBlock||u.depth<2||!u.sameParent(c))return!1;const f=u.node(-1);if(f.type!==l)return!1;const h=a.extensionManager.attributes;if(u.parent.content.size===0&&u.node(-1).childCount===u.indexAfter(-1)){if(u.depth===2||u.node(-3).type!==l||u.index(-2)!==u.node(-2).childCount-1)return!1;if(r){let _=ae.empty;const D=u.index(-1)?1:u.index(-2)?2:3;for(let A=u.depth-D;A>=u.depth-3;A-=1)_=ae.from(u.node(A).copy(_));const M=u.indexAfter(-1)<u.node(-2).childCount?1:u.indexAfter(-2)<u.node(-3).childCount?2:3,O=Rn(h,u.node().type.name,u.node().attrs),G=((o=l.contentMatch.defaultType)===null||o===void 0?void 0:o.createAndFill(O))||void 0;_=_.append(ae.from(l.createAndFill(null,G)||void 0));const $=u.before(u.depth-(D-1));t.replace($,u.after(-M),new ce(_,4-D,0));let L=-1;t.doc.nodesBetween($,t.doc.content.size,(A,N)=>{if(L>-1)return!1;A.isTextblock&&A.content.size===0&&(L=N+1)}),L>-1&&t.setSelection(Se.near(t.doc.resolve(L))),t.scrollIntoView()}return!0}const g=c.pos===u.end()?f.contentMatchAt(0).defaultType:null,y=Rn(h,f.type.name,f.attrs),C=Rn(h,u.node().type.name,u.node().attrs);t.delete(u.pos,c.pos);const w=g?[{type:l,attrs:y},{type:g,attrs:C}]:[{type:l,attrs:y}];if(!qn(t.doc,u.pos,2))return!1;if(r){const{selection:_,storedMarks:D}=n,{splittableMarks:M}=a.extensionManager,O=D||_.$to.parentOffset&&_.$from.marks();if(t.split(u.pos,2,w).scrollIntoView(),!O||!r)return!0;const G=O.filter($=>M.includes($.type.name));t.ensureMarks(G)}return!0},Zr=(e,t)=>{const n=Jr(l=>l.type===t)(e.selection);if(!n)return!0;const r=e.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(r===void 0)return!0;const a=e.doc.nodeAt(r);return n.node.type===(a==null?void 0:a.type)&&Fs(e.doc,n.pos)&&e.join(n.pos),!0},Hr=(e,t)=>{const n=Jr(l=>l.type===t)(e.selection);if(!n)return!0;const r=e.doc.resolve(n.start).after(n.depth);if(r===void 0)return!0;const a=e.doc.nodeAt(r);return n.node.type===(a==null?void 0:a.type)&&Fs(e.doc,r)&&e.join(r),!0};var rh=Object.freeze({__proto__:null,blur:rp,clearContent:ip,clearNodes:ap,command:sp,createParagraphNear:op,deleteCurrentNode:lp,deleteNode:up,deleteRange:cp,deleteSelection:dp,enter:pp,exitCode:hp,extendMarkRange:gp,first:mp,focus:bp,forEach:vp,insertContent:xp,insertContentAt:Sp,joinUp:_p,joinDown:kp,joinBackward:Tp,joinForward:Dp,keyboardShortcut:Mp,lift:Ap,liftEmptyBlock:zp,liftListItem:Ep,newlineInCode:$p,resetAttributes:Lp,scrollIntoView:Pp,selectAll:Op,selectNodeBackward:Bp,selectNodeForward:Vp,selectParentNode:Np,selectTextblockEnd:qp,selectTextblockStart:Fp,setContent:Wp,setMark:Kp,setMeta:Xp,setNode:Jp,setNodeSelection:Zp,setTextSelection:Hp,sinkListItem:eh,splitBlock:th,splitListItem:nh,toggleList:(e,t,n,r={})=>({editor:a,tr:o,state:l,dispatch:u,chain:c,commands:d,can:f})=>{const{extensions:h,splittableMarks:g}=a.extensionManager,y=Me(e,l.schema),C=Me(t,l.schema),{selection:w,storedMarks:_}=l,{$from:D,$to:M}=w,O=D.blockRange(M),G=_||w.$to.parentOffset&&w.$from.marks();if(!O)return!1;const $=Jr(L=>no(L.type.name,h))(w);if(O.depth>=1&&$&&O.depth-$.depth<=1){if($.node.type===y)return d.liftListItem(C);if(no($.node.type.name,h)&&y.validContent($.node.content)&&u)return c().command(()=>(o.setNodeMarkup($.pos,y),!0)).command(()=>Zr(o,y)).command(()=>Hr(o,y)).run()}return!n||!G||!u?c().command(()=>f().wrapInList(y,r)?!0:d.clearNodes()).wrapInList(y,r).command(()=>Zr(o,y)).command(()=>Hr(o,y)).run():c().command(()=>{const L=f().wrapInList(y,r),A=G.filter(N=>g.includes(N.type.name));return o.ensureMarks(A),L?!0:d.clearNodes()}).wrapInList(y,r).command(()=>Zr(o,y)).command(()=>Hr(o,y)).run()},toggleMark:(e,t={},n={})=>({state:r,commands:a})=>{const{extendEmptyMarkRange:o=!1}=n,l=_t(e,r.schema);return Qp(r,l,t)?a.unsetMark(l,{extendEmptyMarkRange:o}):a.setMark(l,t)},toggleNode:(e,t,n={})=>({state:r,commands:a})=>{const o=Me(e,r.schema),l=Me(t,r.schema);return Xr(r,o,n)?a.setNode(l):a.setNode(o,n)},toggleWrap:(e,t={})=>({state:n,commands:r})=>{const a=Me(e,n.schema);return Xr(n,a,t)?r.lift(a):r.wrapIn(a,t)},undoInputRule:()=>({state:e,dispatch:t})=>{const n=e.plugins;for(let r=0;r<n.length;r+=1){const a=n[r];let o;if(a.spec.isInputRules&&(o=a.getState(e))){if(t){const l=e.tr,u=o.transform;for(let c=u.steps.length-1;c>=0;c-=1)l.step(u.steps[c].invert(u.docs[c]));if(o.text){const c=l.doc.resolve(o.from).marks();l.replaceWith(o.from,o.to,e.schema.text(o.text,c))}else l.delete(o.from,o.to)}return!0}}return!1},unsetAllMarks:()=>({tr:e,dispatch:t})=>{const{selection:n}=e,{empty:r,ranges:a}=n;return r||t&&a.forEach(o=>{e.removeMark(o.$from.pos,o.$to.pos)}),!0},unsetMark:(e,t={})=>({tr:n,state:r,dispatch:a})=>{var o;const{extendEmptyMarkRange:l=!1}=t,{selection:u}=n,c=_t(e,r.schema),{$from:d,empty:f,ranges:h}=u;if(!a)return!0;if(f&&l){let{from:g,to:y}=u;const C=(o=d.marks().find(_=>_.type===c))===null||o===void 0?void 0:o.attrs,w=Xs(d,c,C);w&&(g=w.from,y=w.to),n.removeMark(g,y,c)}else h.forEach(g=>{n.removeMark(g.$from.pos,g.$to.pos,c)});return n.removeStoredMark(c),!0},updateAttributes:(e,t={})=>({tr:n,state:r,dispatch:a})=>{let o=null,l=null;const u=eo(typeof e=="string"?e:e.name,r.schema);return u?(u==="node"&&(o=Me(e,r.schema)),u==="mark"&&(l=_t(e,r.schema)),a&&n.selection.ranges.forEach(c=>{const d=c.$from.pos,f=c.$to.pos;r.doc.nodesBetween(d,f,(h,g)=>{o&&o===h.type&&n.setNodeMarkup(g,void 0,{...h.attrs,...t}),l&&h.marks.length&&h.marks.forEach(y=>{if(l===y.type){const C=Math.max(g,d),w=Math.min(g+h.nodeSize,f);n.addMark(C,w,l.create({...y.attrs,...t}))}})})}),!0):!1},wrapIn:(e,t={})=>({state:n,dispatch:r})=>{const a=Me(e,n.schema);return ke.wrapIn(a,t)(n,r)},wrapInList:(e,t={})=>({state:n,dispatch:r})=>{const a=Me(e,n.schema);return br.wrapInList(a,t)(n,r)}});ut.create({name:"commands",addCommands(){return{...rh}}}),ut.create({name:"editable",addProseMirrorPlugins(){return[new fn({key:new gn("editable"),props:{editable:()=>this.editor.options.editable}})]}}),ut.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:e}=this;return[new fn({key:new gn("focusEvents"),props:{handleDOMEvents:{focus:(t,n)=>{e.isFocused=!0;const r=e.state.tr.setMeta("focus",{event:n}).setMeta("addToHistory",!1);return t.dispatch(r),!1},blur:(t,n)=>{e.isFocused=!1;const r=e.state.tr.setMeta("blur",{event:n}).setMeta("addToHistory",!1);return t.dispatch(r),!1}}}})]}}),ut.create({name:"keymap",addKeyboardShortcuts(){const e=()=>this.editor.commands.first(({commands:l})=>[()=>l.undoInputRule(),()=>l.command(({tr:u})=>{const{selection:c,doc:d}=u,{empty:f,$anchor:h}=c,{pos:g,parent:y}=h,C=fe.atStart(d).from===g;return!f||!C||!y.type.isTextblock||y.textContent.length?!1:l.clearNodes()}),()=>l.deleteSelection(),()=>l.joinBackward(),()=>l.selectNodeBackward()]),t=()=>this.editor.commands.first(({commands:l})=>[()=>l.deleteSelection(),()=>l.deleteCurrentNode(),()=>l.joinForward(),()=>l.selectNodeForward()]),r={Enter:()=>this.editor.commands.first(({commands:l})=>[()=>l.newlineInCode(),()=>l.createParagraphNear(),()=>l.liftEmptyBlock(),()=>l.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:e,"Mod-Backspace":e,"Shift-Backspace":e,Delete:t,"Mod-Delete":t,"Mod-a":()=>this.editor.commands.selectAll()},a={...r},o={...r,"Ctrl-h":e,"Alt-Backspace":e,"Ctrl-d":t,"Ctrl-Alt-Backspace":t,"Alt-Delete":t,"Alt-d":t,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return Kr()||Hs()?o:a},addProseMirrorPlugins(){return[new fn({key:new gn("clearDocument"),appendTransaction:(e,t,n)=>{if(!(e.some(C=>C.docChanged)&&!t.doc.eq(n.doc)))return;const{empty:a,from:o,to:l}=t.selection,u=fe.atStart(t.doc).from,c=fe.atEnd(t.doc).to;if(a||!(o===u&&l===c)||!(n.doc.textBetween(0,n.doc.content.size," "," ").length===0))return;const h=n.tr,g=Us({state:n,transaction:h}),{commands:y}=new Xd({editor:this.editor,state:g});if(y.clearNodes(),!!h.steps.length)return h}})]}}),ut.create({name:"tabindex",addProseMirrorPlugins(){return[new fn({key:new gn("tabindex"),props:{attributes:this.editor.isEditable?{tabindex:"0"}:{}}})]}});const io=ut.create({name:"fontSize",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{fontSize:{default:null,parseHTML:e=>e.style.fontSize.replace(/['"]+/g,""),renderHTML:e=>e.fontSize?{style:`font-size: ${e.fontSize}`}:{}}}}]},addCommands(){return{setFontSize:e=>({chain:t})=>t().setMark("textStyle",{fontSize:e}).run(),unsetFontSize:()=>({chain:e})=>e().setMark("textStyle",{fontSize:null}).removeEmptyTextStyle().run()}}}),ih=["8","10","12","14","16","18","20","24","30","36","48","60","72"].map(e=>`${e}px`),ah=[{label:"auto",value:""}].concat(ih.map(e=>({label:e,value:e}))),sh={input:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important"}},oh=({editor:e})=>{const t=e.getAttributes("textStyle").fontSize;return i(J.RichTextEditor.ControlsGroup,{children:i(s.NativeSelect,{size:"xs",icon:i(E.IconTextSize,{stroke:1.5,size:16}),data:ah,styles:sh,value:t||"",onChange:n=>{const r=n.currentTarget.value;r?e.chain().focus().setFontSize(r).run():e.chain().focus().unsetFontSize().run()}})})},Yn=({value:e,styles:t={}})=>{const n=Ja.useEditor({extensions:[Za,Xa,J.Link,Wa,Ga,qa,Ya.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),Ka,Ua,Qa,ja.configure({types:["heading","paragraph"]}),Fa.configure({placeholder:"This is placeholder"}),Ra,Na.Color,io],content:e,editable:!1});m.useEffect(()=>{n==null||n.commands.setContent(e)},[e,n]);const r=m.useMemo(()=>x.defaultsDeep({},{content:Vr},t),[t]);return i(J.RichTextEditor,{editor:n,styles:r,children:i(J.RichTextEditor.Content,{})})};function lh(){const[e,{open:t,close:n}]=_e.useDisclosure(!1);return p(B,{children:[i(s.Modal,{opened:e,onClose:n,title:"About FunctionUtils",zIndex:330,withinPortal:!0,children:i(Yn,{value:rc,styles:{root:{border:"none"},content:{padding:0,table:{marginBottom:0}}}})}),i(s.Button,{variant:"light",color:"violet",size:"xs",onClick:t,leftIcon:i(E.IconInfoCircle,{size:16}),children:"About parameter 'utils'"})]})}const uh=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return i(s.Box,{sx:{position:"relative",flexGrow:1},children:i(Te,{className:"function-editor",height:"100%",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1}}})})},mn=m.forwardRef(({value:e,onChange:t,label:n,defaultValue:r},a)=>{const[o,l]=m.useState(e),u=()=>{t(o)},c=()=>{l(e)},d=()=>{l(r)};m.useEffect(()=>{l(e)},[e]);const f=o!==e;return p(s.Stack,{spacing:4,sx:{height:"100%"},children:[p(s.Group,{mb:6,position:"apart",sx:{flexShrink:0,flexGrow:0},children:[i(s.Group,{position:"left",children:i(lh,{})}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,size:"xs",variant:"default",leftIcon:i(E.IconPlayerSkipBack,{size:16}),children:"Reset to default"}),i(s.Button,{onClick:c,color:"red",size:"xs",disabled:!f,leftIcon:i(E.IconRecycle,{size:16}),children:"Revert Changes"}),i(s.Button,{size:"xs",onClick:u,disabled:!f,leftIcon:i(E.IconDeviceFloppy,{size:16}),children:"Confirm Changes"})]})]}),i(s.Text,{size:14,children:n}),i(uh,{value:o,onChange:l})]})}),ch=m.forwardRef(({value:e,onChange:t,label:n,triggerLabel:r="Edit",triggerButtonProps:a={},defaultValue:o},l)=>{const[u,{open:c,close:d}]=_e.useDisclosure(!1);return p(B,{children:[i(s.Modal,{opened:u,onClose:d,title:"Authentication",withinPortal:!0,zIndex:320,size:"900px",children:i(s.Box,{h:600,children:i(mn,{value:e,onChange:t,defaultValue:o,label:n})})}),i(s.Button,{onClick:c,...a,children:r})]})}),ao=["function aggregation({ queryData }, utils) {",' return "Aggregation Result";',"}"].join(`
|
|
105
|
-
`),
|
|
106
|
-
`,"<br/>").split("<br/>");return n.map((a,o)=>{const l=[Dh(a)];return o!==n.length-1&&l.push(i("br",{},`br-${o}`)),l}).flat().filter(a=>a!==void 0)}function ti(e){return Ih(e)}function yn(e,t,n){const r=Th(t,n),a=/^\{(.+)\}(.*)$/;return e.split("$").map((o,l)=>{const u=a.exec(o);if(!u)return ti(o);const c=r[u[1]];if(!c)return ti(o);const d=u[2]??"";return p(m.Fragment,{children:[c,ti(d)]},`${o}-${l}`)})}function Mh(e,t){const n={};return e.forEach(r=>{const{name:a,data_field:o,aggregation:l}=r,u=Qn(t,o,l);n[a]=Ze(r,u)}),n}function Xn(e,t,n){const r=Mh(t,n),a=/^\{(.+)\}(.*)$/;return e.split("$").map(o=>{const l=a.exec(o);if(!l)return o;const u=r[l[1]];if(!u)return o;const c=l[2]??"";return`${u}${c}`}).join("")}function Ah(e,t,n){const r=t.reduce((a,o)=>{const l=yt(o,n);return a[o.name]=Ze(o,l),a},{});return e.map(a=>({name:"refs",type:"scatter",data:[],markLine:{data:[{name:a.name,yAxis:Number(r[a.variable_key])}],silent:!0,symbol:["none","none"],label:{formatter:function(){return Xn(a.template,t,n)},position:"insideEndTop"}}}))}function zh(e){const t={top:30,left:20,right:15,bottom:25,containLabel:!0};return e.legend.orient==="vertical"&&(t.right=80),t}function Eh({config:e,data:t,variables:n}){const{x_axis:r,y_axis:a,reference_lines:o}=e,l=Dd(e,t),u=rt(r.axisLabel.overflow.on_axis),c=Md(e);return{grid:zh(e),dataset:l,legend:Id({config:e}),tooltip:Pd({config:e}),xAxis:[{type:"category",name:r.name,nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold",align:"center"},axisTick:{show:!0,alignWithLabel:!0},axisLabel:{...r.axisLabel,...u,formatter:Ft(r.axisLabel.formatter)}}],yAxis:[{name:a.name,minInterval:1,nameTextStyle:{fontWeight:"bold"},axisLine:{show:!0},axisLabel:{formatter:function(d){return Z(d).format(a.label_formatter)}}}],series:[...c,...Ah(o,n,t)]}}ie.use([F.DataZoomComponent,he.BoxplotChart,F.MarkLineComponent,F.GridComponent,F.LegendComponent,F.TooltipComponent,ze.CanvasRenderer]);function $h({context:e,instance:t}){const{value:n}=R(e.instanceData,"config"),{variables:r}=e,a=e.data,{width:o,height:l}=e.viewport,u=x.defaults({},n,Lr),c=Xe({vizManager:e.vizManager,instance:t}),d=Ke(c.triggerManager,Cs.id),f=zt(a,u.x_axis.data_key),h=m.useCallback(C=>{const w=x.get(f,C.name,{error:"rowData is not found"});d.forEach(_=>{c.runInteraction(_.id,{...C,rowData:w})})},[f,d,c]),g=m.useMemo(()=>({click:h}),[h]),y=m.useMemo(()=>Eh({config:u,data:a,variables:r}),[u,a,r]);return!n||!o||!l?null:i(Be,{width:o,height:l,children:i(Ae,{echarts:ie,option:y,style:on(o,l),onEvents:g,notMerge:!0,theme:"merico-light"})})}function Lh({control:e,index:t,remove:n,variableOptions:r}){return p(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:a})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:a})=>i(s.Select,{label:"Value",required:!0,data:r,sx:{flex:1},...a})})]}),i(v.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:a})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",required:!0,sx:{flex:1},...a})}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(t),sx:{position:"absolute",top:15,right:5},children:i(I.Trash,{size:16})})]})}function Ph({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=r.map((f,h)=>({...f,...l[h]})),c=()=>a({name:"",template:"",variable_key:""}),d=m.useMemo(()=>n.map(f=>({label:f.name,value:f.name})),[n]);return p(s.Stack,{children:[u.map((f,h)=>i(Lh,{control:e,index:h,remove:o,variableOptions:d},f.id)),i(s.Group,{position:"center",mt:"xs",children:i(s.Button,{onClick:c,children:"Add a Reference Line"})})]})}const Oh=({disabled:e,value:t,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[e&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Te,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},Jn=m.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:a,setFalse:o}]=Q.useBoolean(),[l,u]=m.useState(e);m.useEffect(()=>{u(e)},[e]);const c=y=>{u({...l,enabled:y})},d=()=>{o();const{enabled:y,func_content:C}=l,w={enabled:y,func_content:C};u(w),t(w)},f=()=>{o(),u(e)},h=y=>{u(C=>({...C,func_content:y}))},g=()=>{h(Ue.func_content)};return p(B,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Customize Label"}),i(s.Modal,{size:800,title:"Customize label content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:y=>c(y.currentTarget.checked)}),i(Oh,{value:l.func_content,onChange:h,disabled:!l.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:g,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:d,children:"OK"})]})]})]})})]})}),Bh=({control:e,watch:t})=>(t(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"X Axis Name",sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>i(W,{label:"X Axis Data Field",required:!0,sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>i(Jn,{...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>i(st,{...n})})]})),Vh=({control:e,watch:t})=>(t(["y_axis"]),p(B,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"Y Axis Name",sx:{flex:1},...n})}),i(v.Controller,{name:"y_axis.data_key",control:e,render:({field:n})=>i(W,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:"y_axis.label_formatter",control:e,render:({field:n})=>i(Ge,{...n})})]})]})),Nh=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),qh=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[d,f]=m.useState(()=>c??null);return m.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(B,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(I.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Set additional metrics to show in scatter's tooltip"})]}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(Nh,{control:e,index:g,remove:a},h.id)},h.id))]})]})};function Fh({control:e,watch:t}){return i(s.Stack,{children:i(qh,{control:e,watch:t})})}const Gh=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}],Wh=({control:e,watch:t})=>{const n=t("legend"),r=(a,o)=>{const l={...n,orient:a};a==="horizontal"?(l.top="0",l.left="auto",l.right="10",l.bottom="auto"):(l.top="10",l.left="auto",l.right="0",l.bottom="auto"),o(l)};return p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,mt:20,children:i(v.Controller,{name:"legend.show",control:e,render:({field:a})=>i(s.Switch,{label:"Show Legend",sx:{flex:1},checked:a.value,onChange:o=>a.onChange(o.currentTarget.checked)})})}),i(s.Group,{children:i(v.Controller,{name:"legend",control:e,render:({field:a})=>i(s.Select,{label:"Orientation",data:Gh,sx:{flex:1},value:a.value.orient,onChange:o=>{r(o,a.onChange)},disabled:!n.show})})})]})};function jh({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),{variables:r}=e,a=m.useMemo(()=>x.defaults({},t,Lr),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});m.useEffect(()=>{d(a)},[a]),u(["x_axis","y_axis","reference_lines","color"]);const f=c(),h=m.useMemo(()=>!x.isEqual(f,t),[f,t]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(I.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),i(s.Tabs.Tab,{value:"Legend",children:"Legend"}),i(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"}),i(s.Tabs.Tab,{value:"Style",children:"Style"}),i(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(Bh,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(Vh,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Legend",children:i(Wh,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(Fh,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Style",children:p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:"color",control:o,render:({field:g})=>i($e,{...g})})]})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(Ph,{variables:r,control:o,watch:u})})]})]})})}function Rh(e){return x.omit(e,"variables")}function Yh(e){const{label_formatter:t=De,...n}=e.y_axis;return{...e,y_axis:{...n,label_formatter:t}}}function Qh(e){const t={rotate:0,formatter:{...Ue}},{axisLabel:n=t,...r}=e.x_axis;return{...e,x_axis:{...r,axisLabel:n}}}function Uh(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return x.defaultsDeep(t,e)}function Kh(e){delete e.config;const{x_axis:t,tooltip:n}=e.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:t,in_tooltip:n}}}};return x.defaultsDeep(r,e)}function Xh(e){const t={tooltip:{metrics:[]}};return x.defaultsDeep(t,e)}function Jh(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,y_axis:o,tooltip:l,...u}=e;return{...u,x_axis:{...a,data_key:r(a.data_key)},y_axis:{...o,data_key:r(o.data_key)},tooltip:{...l,metrics:l.metrics.map(c=>({...c,data_key:r(c.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}function Zh(e){const t={legend:{show:!0,top:"0",right:"10",left:"auto",bottom:"auto",orient:"horizontal",type:"scroll"}};return x.defaultsDeep(t,e)}class Hh extends ge{constructor(){super(...arguments);q(this,"VERSION",9)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,{panelModel:r})=>{const{config:a}=n;return(a.variables||[]).forEach(l=>{r.variables.find(u=>u.name===l.name)||r.addVariable(l)}),{...n,version:2,config:Rh(a)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:Yh(r)}}),this.version(4,n=>{const{config:r}=n;return{...n,version:4,config:Qh(r)}}),this.version(5,n=>{const{config:r}=n;return{...n,version:5,config:Uh(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:Kh(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:Xh(r)}}),this.version(8,(n,r)=>{const{config:a}=n;return{...n,version:8,config:Jh(a,r)}}),this.version(9,n=>{const{config:r}=n;return{...n,version:9,config:Zh(r)}})}}const ef={displayName:"Boxplot Chart",displayGroup:"ECharts-based charts",migrator:new Hh,name:"boxplot",viewRender:$h,configRender:jh,createConfig(){return{version:9,config:x.cloneDeep(Lr)}},triggers:[Cs]},uo={id:"builtin:button:click-button",displayName:"Click Button",nameRender:nf,configRender:tf,payload:[]};function tf(e){return i(B,{})}function nf(e){return i(s.Text,{children:"Click this button"})}const ni={content:"Button",variant:"filled",color:"blue",size:"xs",compact:!1,horizontal_align:"left",vertical_align:"center"},rf={left:"flex-start",center:"center",right:"flex-end"},af={top:"flex-start",center:"center",bottom:"flex-end"},sf=k.observer(({context:e,instance:t})=>{const n=Xe({vizManager:e.vizManager,instance:t}),r=Ke(n.triggerManager,uo.id),a=ye(),{value:o}=R(e.instanceData,"config"),l=m.useMemo(()=>x.defaultsDeep({},o,ni),[o]),{content:u,horizontal_align:c,vertical_align:d,...f}=l,{width:h,height:g}=e.viewport,y=a.payloadForSQL,C=()=>{r.forEach(w=>{n.runInteraction(w.id,{})})};return i(s.Center,{sx:{width:h,height:g,justifyContent:rf[c],alignItems:af[d]},children:i(s.Button,{...f,onClick:C,children:x.template(u)(y)})})}),of=({value:e,onChange:t,label:n})=>{const r=s.useMantineTheme(),a=m.useCallback(l=>()=>t(l),[t]),o=l=>e===l;return p(s.Stack,{spacing:2,children:[i(s.Text,{size:14,sx:{fontWeight:500},children:n}),i(s.Group,{position:"left",spacing:"xs",children:Object.keys(r.colors).map(l=>{const u=r.colors[l][6];return i(s.ColorSwatch,{color:u,onClick:a(l),radius:4,size:26,sx:{cursor:"pointer"},children:o(l)&&i(s.CheckIcon,{width:10,color:"white"})},l)})})]})},lf=s.MANTINE_SIZES.map(e=>({label:e.toUpperCase(),value:e})),uf=({label:e,value:t,onChange:n})=>i(s.Select,{data:lf,label:e,value:t,onChange:n}),cf=[{label:"Filled",value:"filled"},{label:"Outline",value:"outline"},{label:"Light",value:"light"},{label:"White",value:"white"},{label:"Default",value:"default"},{label:"Subtle",value:"subtle"},{label:"Gradient",value:"gradient",disabled:!0}],df=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],pf=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function hf({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=m.useMemo(()=>x.defaultsDeep({},t,ni),[t]),a=r;m.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});m.useEffect(()=>{d(a)},[a]);const f=c(),h=m.useMemo(()=>!x.isEqual(f,r),[f,r]);return u(["content","variant","color","size","compact","horizontal_align","vertical_align"]),p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(I.DeviceFloppy,{size:20})})]}),p(s.Stack,{children:[i(v.Controller,{control:o,name:"content",render:({field:g})=>i(s.TextInput,{label:"Content Template",description:"Filter values & context entries are supported",...g,required:!0})}),i(s.Divider,{mt:"xs",mb:0,label:"Styles",labelPosition:"center",variant:"dashed"}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{control:o,name:"variant",render:({field:g})=>i(s.Select,{label:"Variant",data:cf,...g})}),i(v.Controller,{control:o,name:"color",render:({field:g})=>i(of,{label:"Theme",...g})})]}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{control:o,name:"size",render:({field:g})=>i(uf,{label:"Size",...g})}),i(v.Controller,{control:o,name:"compact",render:({field:g})=>i(s.Checkbox,{label:"Compact",checked:g.value,onChange:y=>g.onChange(y.currentTarget.checked),mt:26})})]}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{control:o,name:"horizontal_align",render:({field:g})=>i(s.Select,{label:"Horizontal Alignment",data:df,...g})}),i(v.Controller,{control:o,name:"vertical_align",render:({field:g})=>i(s.Select,{label:"Vertical Alignment",data:pf,...g})})]})]})]})}class ff extends ge{constructor(){super(...arguments);q(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{horizontal_align:r="left",vertical_align:a="center",...o}=n.config;return{...n,version:2,config:{...o,horizontal_align:r,vertical_align:a}}})}}const gf={displayName:"Button",displayGroup:"Others",migrator:new ff,name:"button",viewRender:sf,configRender:hf,createConfig(){return{version:2,config:x.cloneDeep(ni)}},triggers:[uo]},ri={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:yf,configRender:mf,payload:[{name:"seriesType",description:"'line' | 'scatter' | 'bar'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function mf(e){return i(B,{})}function yf(e){return i(s.Text,{children:"Click chart's series"})}const Rt={x_axis_scroll:!1,y_axis_scroll:!1,x_axis_slider:!1,y_axis_slider:!1},ii={regressions:[],series:[],stats:{templates:{bottom:"",top:""}},x_axis:{type:"category",axisLabel:{rotate:0,formatter:{...Ue},overflow:We}},x_axis_data_key:"",x_axis_name:"",y_axes:[{min:"",max:"",name:"Y Axis",show:!0,position:"left",nameAlignment:"center",label_formatter:De}],reference_lines:[],reference_areas:[],dataZoom:Rt};function ai(e){const t=[];return e.x_axis_scroll&&t.push({type:"inside",xAxisIndex:[0],filterMode:"none",minSpan:1}),e.y_axis_scroll&&t.push({type:"inside",yAxisIndex:[0],filterMode:"none",minSpan:1}),e.x_axis_slider&&t.push({type:"slider",xAxisIndex:[0],filterMode:"none",bottom:"auto",top:0,height:15,moveHandleSize:0,showDataShadow:!1,minSpan:1}),t}function bf(e){const t=e.y_axes.some(a=>!!a.name);let n=15;t&&(n+=20),e.dataZoom.x_axis_slider&&(n+=20);let r=5;return e.x_axis_name&&(r+=15),e.series.some(a=>!a.hide_in_legend)&&(r+=20),{top:n,right:15,bottom:r,left:20,containLabel:!0}}function vf(e){return e!=="line"?{}:{itemStyle:{opacity:0}}}function xf(e){switch(e){case"line":return;case"bar":return"roundRect";case"scatter":return"circle"}}function wf(e){const t={show:!0,bottom:0,left:"center",type:"scroll"};return t.data=e.filter(n=>!n.hide_in_legend).map(({name:n,type:r})=>({name:n,icon:xf(r),...vf(r)})),t}function Zn(e,t){switch(e.config.method){case"linear":return[...wt.regressionLinear()(t)];case"exponential":return[...wt.regressionExp()(t)];case"logarithmic":return[...wt.regressionLog()(t)];case"polynomial":return[...wt.regressionPoly().order(e.config.order)(t)];default:return[]}}function Cf(e,t,n,r){const{transform:a,plot:o}=e,l={...o,name:t,data:Zn(a,r),showSymbol:!1,tooltip:{show:!1},smooth:!1,custom:{}};return n&&(l.custom={type:"regression-line",targetSeries:n}),l}function Sf({regressions:e=[],x_axis_data_key:t},n){const r=[];if(Object.keys(n).length===0)return r;function a(o,l,u,c){const d=Cf(o,l,u,c);r.push(d)}return e.forEach(o=>{const{name:l,group_by_key:u}=o;if(!u||u===t){const h=gt(n,o.y_axis_data_key).map((g,y)=>[y,Number(g)]);a(o,l,"",h);return}const{columnKey:c}=P(o.y_axis_data_key),d=x.groupBy(ln(n,o.y_axis_data_key),u);Object.entries(d).forEach(([f,h])=>{const g=h.map((C,w)=>[w,Number(C[c])]);a(o,f,f,g)})}),r}function _f(e,t){return e.map(n=>({name:"",type:"line",hide_in_legend:!0,data:[],markArea:{itemStyle:{color:n.color},data:[[{yAxis:t[n.y_keys.upper]},{yAxis:t[n.y_keys.lower]}]],silent:!0}}))}function kf(e,t,n,r){return t?r==="value"?[[n[0],e]]:[e]:[]}function Tf(e,t,n,r,a,o){return e.map(l=>{const u=n[l.variable_key],c=l.orientation==="horizontal",d=c?"yAxis":"xAxis",f=c?"insideEndTop":"end",h=kf(u,c,a,o);return{name:l.name,type:"scatter",hide_in_legend:!l.show_in_legend,xAxisId:"main-x-axis",yAxisIndex:l.yAxisIndex,data:h,symbol:"none",silent:!0,tooltip:{show:!1},markLine:{data:[{name:l.name,[d]:u}],silent:!0,symbol:["none","none"],lineStyle:l.lineStyle,label:{formatter:function(){return l.template?Xn(l.template,t,r):""},position:f}}}})}function Df({type:e,...t},n,r,a){if(!e)return 10;if(e==="static"){const{size:d}=t;return d}const{func_content:o}=t,{queryID:l,columnKey:u}=P(r),c=x.keyBy(ln(n,l),u);return(d,f)=>{let h;f.name?h=c[f.name]:h=n[f.dataIndex];try{return new Function(`return ${o}`)()({rowData:h,params:f,variables:a},{lodash:x,interpolate:It.interpolate})}catch(g){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${g.message}`),10}}}function si(e,t,n){const r=gt(e,t),a=gt(e,n);return x.zip(r,a)}function If(e,t,n,r){const a=si(t,n,r);return x.unionBy(a,e,0)}function Mf({dataTemplate:e,data:t,x_axis_data_key:n,y_axis_data_key:r,valueTypedXAxis:a}){return a?If(e,t,n,r):gt(t,r)}function Af({dataTemplate:e,data:t,aggregation_on_value:n,x_axis_data_key:r,y_axis_data_key:a,valueTypedXAxis:o}){if(!n||n.type==="none")return Mf({dataTemplate:e,data:t,x_axis_data_key:r,y_axis_data_key:a,valueTypedXAxis:o});const l=si(t,r,a),u=x.groupBy(l,"0");return e.map(([d])=>{const h=u[d].map(y=>y[1]),g=ei(h,n);return[d,g]})}function zf({group_by_key:e,data:t,x_axis_data_key:n,y_axis_data_key:r}){const{queryID:a,columnKey:o}=P(e),l=x.groupBy(t[a],o);return Object.entries(l).forEach(([u,c])=>{l[u]=si({[a]:c},n,r)}),l}function Ef({x_axis_data_key:e,x_axis:t},{y_axis_data_key:n,yAxisIndex:r,label_position:a,name:o,group_by_key:l,aggregation_on_value:u,stack:c,color:d,display_name_on_line:f,symbolSize:h,hide_in_legend:g,...y},C,w,_,D){const M=t.type!=="category",O={label:{show:!!a,position:a,formatter:D[r??"default"]},name:o,xAxisId:"main-x-axis",yAxisIndex:r,stack:c,color:d,symbolSize:Df(h,w,e,_),hide_in_legend:g,labelLayout:{hideOverlap:!0},...y};if(f&&(O.endLabel={show:!0,formatter:o,offset:[-12,12],align:"right"}),!l||l===e)return O.data=Af({dataTemplate:C,data:w,aggregation_on_value:u,x_axis_data_key:e,y_axis_data_key:n,valueTypedXAxis:M}),O;const G=zf({group_by_key:l,data:w,x_axis_data_key:e,y_axis_data_key:n});return Object.entries(G).map(([$,L])=>{const A=x.cloneDeep(O);return A.name=$,A.color=void 0,A.data=L,A})}function $f(e,t,n,r,a,o){const l=t.map(c=>[c,0]);return e.series.map(c=>Ef(e,c,l,n,o,r)).flat().concat(Tf(e.reference_lines,a,o,n,t,e.x_axis.type)).concat(_f(e.reference_areas,o))}function Lf(e,t){const n=e.find(o=>o.axisDim==="x"&&o.axisId==="main-x-axis");if(!n)return"";const{axisValue:r,axisIndex:a}=n;return Ft(t.x_axis.axisLabel.formatter)(r,a)}function Pf(e,t,n){const r=t.reduce((a,{yAxisIndex:o,name:l})=>(a[l]=o,a),{});return{trigger:"axis",confine:!0,formatter:function(a){const o=Array.isArray(a)?a:[a];if(o.length===0)return"";const l=o.map(({seriesName:d,marker:f,value:h})=>{if(Array.isArray(h)&&h.length===2&&(h=h[1]),!d)return h;const g=r[d],y=n[g]??n.default;return`
|
|
104
|
+
`,textSerializers:l={}}=n||{};let u="",c=!0;return t.nodesBetween(i,a,(p,h,f,g)=>{var b;const w=l==null?void 0:l[p.type.name];w?(p.isBlock&&!c&&(u+=o,c=!0),f&&(u+=w({node:p,pos:h,parent:f,index:g,range:e}))):p.isText?(u+=(b=p==null?void 0:p.text)===null||b===void 0?void 0:b.slice(Math.max(i,h)-h,a-h),c=!1):p.isBlock&&!c&&(u+=o,c=!0)}),u}function Xd(t){return Object.fromEntries(Object.entries(t.nodes).filter(([,e])=>e.spec.toText).map(([e,n])=>[e,n.spec.toText]))}et.create({name:"clipboardTextSerializer",addProseMirrorPlugins(){return[new Xt({key:new Jt("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:t}=this,{state:e,schema:n}=t,{doc:i,selection:a}=e,{ranges:o}=a,l=Math.min(...o.map(h=>h.$from.pos)),u=Math.max(...o.map(h=>h.$to.pos)),c=Xd(n);return Yd(i,{from:l,to:u},{textSerializers:c})}}})]}});const Jd=()=>({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),Zd=(t=!1)=>({commands:e})=>e.setContent("",t),Hd=()=>({state:t,tr:e,dispatch:n})=>{const{selection:i}=e,{ranges:a}=i;return n&&a.forEach(({$from:o,$to:l})=>{t.doc.nodesBetween(o.pos,l.pos,(u,c)=>{if(u.type.isText)return;const{doc:p,mapping:h}=e,f=p.resolve(h.map(c)),g=p.resolve(h.map(c+u.nodeSize)),b=f.blockRange(g);if(!b)return;const w=qd(b);if(u.type.isTextblock){const{defaultType:_}=f.parent.contentMatchAt(f.index());e.setNodeMarkup(b.start,_)}(w||w===0)&&e.lift(b,w)})}),!0},ep=t=>e=>t(e),tp=()=>({state:t,dispatch:e})=>be.createParagraphNear(t,e),np=()=>({tr:t,dispatch:e})=>{const{selection:n}=t,i=n.$anchor.node();if(i.content.size>0)return!1;const a=t.selection.$anchor;for(let o=a.depth;o>0;o-=1)if(a.node(o).type===i.type){if(e){const u=a.before(o),c=a.after(o);t.delete(u,c).scrollIntoView()}return!0}return!1},rp=t=>({tr:e,state:n,dispatch:i})=>{const a=Ce(t,n.schema),o=e.selection.$anchor;for(let l=o.depth;l>0;l-=1)if(o.node(l).type===a){if(i){const c=o.before(l),p=o.after(l);e.delete(c,p).scrollIntoView()}return!0}return!1},ip=t=>({tr:e,dispatch:n})=>{const{from:i,to:a}=t;return n&&e.delete(i,a),!0},ap=()=>({state:t,dispatch:e})=>be.deleteSelection(t,e),sp=()=>({commands:t})=>t.keyboardShortcut("Enter"),op=()=>({state:t,dispatch:e})=>be.exitCode(t,e);function _n(t,e,n={strict:!0}){const i=Object.keys(e);return i.length?i.every(a=>n.strict?e[a]===t[a]:Ud(e[a])?e[a].test(t[a]):e[a]===t[a]):!0}function zr(t,e,n={}){return t.find(i=>i.type===e&&_n(i.attrs,n))}function lp(t,e,n={}){return!!zr(t,e,n)}function ns(t,e,n={}){if(!t||!e)return;let i=t.parent.childAfter(t.parentOffset);if(t.parentOffset===i.offset&&i.offset!==0&&(i=t.parent.childBefore(t.parentOffset)),!i.node)return;const a=zr([...i.node.marks],e,n);if(!a)return;let o=i.index,l=t.start()+i.offset,u=o+1,c=l+i.node.nodeSize;for(zr([...i.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&&lp([...t.parent.child(u).marks],e,n);)c+=t.parent.child(u).nodeSize,u+=1;return{from:l,to:c}}function ht(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 up=(t,e={})=>({tr:n,state:i,dispatch:a})=>{const o=ht(t,i.schema),{doc:l,selection:u}=n,{$from:c,from:p,to:h}=u;if(a){const f=ns(c,o,e);if(f&&f.from<=p&&f.to>=h){const g=ge.create(l,f.from,f.to);n.setSelection(g)}}return!0},cp=t=>e=>{const n=typeof t=="function"?t(e):t;for(let i=0;i<n.length;i+=1)if(n[i](e))return!0;return!1};function rs(t){return t instanceof ge}function Ct(t=0,e=0,n=0){return Math.min(Math.max(t,e),n)}function dp(t,e=null){if(!e)return null;const n=ie.atStart(t),i=ie.atEnd(t);if(e==="start"||e===!0)return n;if(e==="end")return i;const a=n.from,o=i.to;return e==="all"?ge.create(t,Ct(0,a,o),Ct(t.content.size,a,o)):ge.create(t,Ct(e,a,o),Ct(e,a,o))}function Er(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}const pp=(t=null,e={})=>({editor:n,view:i,tr:a,dispatch:o})=>{e={scrollIntoView:!0,...e};const l=()=>{Er()&&i.dom.focus(),requestAnimationFrame(()=>{n.isDestroyed||(i.focus(),e!=null&&e.scrollIntoView&&n.commands.scrollIntoView())})};if(i.hasFocus()&&t===null||t===!1)return!0;if(o&&t===null&&!rs(n.state.selection))return l(),!0;const u=dp(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},hp=(t,e)=>n=>t.every((i,a)=>e(i,{...n,index:a})),fp=(t,e)=>({tr:n,commands:i})=>i.insertContentAt({from:n.selection.from,to:n.selection.to},t,e);function is(t){const e=`<body>${t}</body>`;return new window.DOMParser().parseFromString(e,"text/html").body}function kn(t,e,n){if(n={slice:!0,parseOptions:{},...n},typeof t=="object"&&t!==null)try{return Array.isArray(t)&&t.length>0?X.fromArray(t.map(i=>e.nodeFromJSON(i))):e.nodeFromJSON(t)}catch(i){return console.warn("[tiptap warn]: Invalid content.","Passed value:",t,"Error:",i),kn("",e,n)}if(typeof t=="string"){const i=mn.fromSchema(e);return n.slice?i.parseSlice(is(t),n.parseOptions).content:i.parse(is(t),n.parseOptions)}return kn("",e,n)}function gp(t,e,n){const i=t.steps.length-1;if(i<e)return;const a=t.steps[i];if(!(a instanceof He||a instanceof wt))return;const o=t.mapping.maps[i];let l=0;o.forEach((u,c,p,h)=>{l===0&&(l=h)}),t.setSelection(ie.near(t.doc.resolve(l),n))}const mp=t=>t.toString().startsWith("<"),yp=(t,e,n)=>({tr:i,dispatch:a,editor:o})=>{if(a){n={parseOptions:{},updateSelection:!0,...n};const l=kn(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,p=!0,h=!0;if((mp(l)?l:[l]).forEach(g=>{g.check(),p=p?g.isText&&g.marks.length===0:!1,h=h?g.isBlock:!1}),u===c&&h){const{parent:g}=i.doc.resolve(u);g.isTextblock&&!g.type.spec.code&&!g.childCount&&(u-=1,c+=1)}p?Array.isArray(e)?i.insertText(e.map(g=>g.text||"").join(""),u,c):typeof e=="object"&&e&&e.text?i.insertText(e.text,u,c):i.insertText(e,u,c):i.replaceWith(u,c,l),n.updateSelection&&gp(i,i.steps.length-1,-1)}return!0},bp=()=>({state:t,dispatch:e})=>be.joinUp(t,e),vp=()=>({state:t,dispatch:e})=>be.joinDown(t,e),xp=()=>({state:t,dispatch:e})=>be.joinBackward(t,e),wp=()=>({state:t,dispatch:e})=>be.joinForward(t,e);function as(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function Cp(t){const e=t.split(/-(?!$)/);let n=e[e.length-1];n==="Space"&&(n=" ");let i,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))i=!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))Er()||as()?l=!0:a=!0;else throw new Error(`Unrecognized modifier name: ${c}`)}return i&&(n=`Alt-${n}`),a&&(n=`Ctrl-${n}`),l&&(n=`Meta-${n}`),o&&(n=`Shift-${n}`),n}const Sp=t=>({editor:e,view:n,tr:i,dispatch:a})=>{const o=Cp(t).split(/-(?!$)/),l=o.find(p=>!["Alt","Ctrl","Meta","Shift"].includes(p)),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",p=>p(n,u))});return c==null||c.steps.forEach(p=>{const h=p.map(i.mapping);h&&a&&i.maybeStep(h)}),!0};function Pr(t,e,n={}){const{from:i,to:a,empty:o}=t.selection,l=e?Ce(e,t.schema):null,u=[];t.doc.nodesBetween(i,a,(f,g)=>{if(f.isText)return;const b=Math.max(i,g),w=Math.min(a,g+f.nodeSize);u.push({node:f,from:b,to:w})});const c=a-i,p=u.filter(f=>l?l.name===f.node.type.name:!0).filter(f=>_n(f.node.attrs,n,{strict:!1}));return o?!!p.length:p.reduce((f,g)=>f+g.to-g.from,0)>=c}const _p=(t,e={})=>({state:n,dispatch:i})=>{const a=Ce(t,n.schema);return Pr(n,a,e)?be.lift(n,i):!1},kp=()=>({state:t,dispatch:e})=>be.liftEmptyBlock(t,e),Tp=t=>({state:e,dispatch:n})=>{const i=Ce(t,e.schema);return tr.liftListItem(i)(e,n)},Dp=()=>({state:t,dispatch:e})=>be.newlineInCode(t,e);function ss(t,e){return e.nodes[t]?"node":e.marks[t]?"mark":null}function os(t,e){const n=typeof e=="string"?[e]:e;return Object.keys(t).reduce((i,a)=>(n.includes(a)||(i[a]=t[a]),i),{})}const Ip=(t,e)=>({tr:n,state:i,dispatch:a})=>{let o=null,l=null;const u=ss(typeof t=="string"?t:t.name,i.schema);return u?(u==="node"&&(o=Ce(t,i.schema)),u==="mark"&&(l=ht(t,i.schema)),a&&n.selection.ranges.forEach(c=>{i.doc.nodesBetween(c.$from.pos,c.$to.pos,(p,h)=>{o&&o===p.type&&n.setNodeMarkup(h,void 0,os(p.attrs,e)),l&&p.marks.length&&p.marks.forEach(f=>{l===f.type&&n.addMark(h,h+p.nodeSize,l.create(os(f.attrs,e)))})})}),!0):!1},Mp=()=>({tr:t,dispatch:e})=>(e&&t.scrollIntoView(),!0),Ap=()=>({tr:t,commands:e})=>e.setTextSelection({from:0,to:t.doc.content.size}),zp=()=>({state:t,dispatch:e})=>be.selectNodeBackward(t,e),Ep=()=>({state:t,dispatch:e})=>be.selectNodeForward(t,e),Pp=()=>({state:t,dispatch:e})=>be.selectParentNode(t,e),Lp=()=>({state:t,dispatch:e})=>be.selectTextblockEnd(t,e),Bp=()=>({state:t,dispatch:e})=>be.selectTextblockStart(t,e);function Op(t,e,n={}){return kn(t,e,{slice:!1,parseOptions:n})}const $p=(t,e=!1,n={})=>({tr:i,editor:a,dispatch:o})=>{const{doc:l}=i,u=Op(t,a.schema,n);return o&&i.replaceWith(0,l.content.size,u).setMeta("preventUpdate",!e),!0};function Vp(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 Np(t,e){for(let n=t.depth;n>0;n-=1){const i=t.node(n);if(e(i))return{pos:n>0?t.before(n):0,start:t.start(n),depth:n,node:i}}}function Lr(t){return e=>Np(e.$from,t)}function qp(t,e){const n=ht(e,t.schema),{from:i,to:a,empty:o}=t.selection,l=[];o?(t.storedMarks&&l.push(...t.storedMarks),l.push(...t.selection.$head.marks())):t.doc.nodesBetween(i,a,c=>{l.push(...c.marks)});const u=l.find(c=>c.type.name===n.name);return u?{...u.attrs}:{}}function Tn(t,e,n){return Object.fromEntries(Object.entries(n).filter(([i])=>{const a=t.find(o=>o.type===e&&o.name===i);return a?a.attribute.keepOnSplit:!1}))}function Gp(t,e,n={}){const{empty:i,ranges:a}=t.selection,o=e?ht(e,t.schema):null;if(i)return!!(t.storedMarks||t.selection.$from.marks()).filter(f=>o?o.name===f.type.name:!0).find(f=>_n(f.attrs,n,{strict:!1}));let l=0;const u=[];if(a.forEach(({$from:f,$to:g})=>{const b=f.pos,w=g.pos;t.doc.nodesBetween(b,w,(_,D)=>{if(!_.isText&&!_.marks.length)return;const L=Math.max(b,D),N=Math.min(w,D+_.nodeSize),J=N-L;l+=J,u.push(..._.marks.map(ae=>({mark:ae,from:L,to:N})))})}),l===0)return!1;const c=u.filter(f=>o?o.name===f.mark.type.name:!0).filter(f=>_n(f.mark.attrs,n,{strict:!1})).reduce((f,g)=>f+g.to-g.from,0),p=u.filter(f=>o?f.mark.type!==o&&f.mark.type.excludes(o):!0).reduce((f,g)=>f+g.to-g.from,0);return(c>0?c+p:c)>=l}function ls(t,e){const{nodeExtensions:n}=Rd(e),i=n.find(l=>l.name===t);if(!i)return!1;const a={name:i.name,options:i.options,storage:i.storage},o=Mt(pt(i,"group",a));return typeof o!="string"?!1:o.split(" ").includes("list")}function Fp(t,e,n){var i;const{selection:a}=e;let o=null;if(rs(a)&&(o=a.$cursor),o){const u=(i=t.storedMarks)!==null&&i!==void 0?i: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 p=u.depth===0?t.doc.inlineContent&&t.doc.type.allowsMarkType(n):!1;return t.doc.nodesBetween(u.pos,c.pos,(h,f,g)=>{if(p)return!1;if(h.isInline){const b=!g||g.type.allowsMarkType(n),w=!!n.isInSet(h.marks)||!h.marks.some(_=>_.type.excludes(n));p=b&&w}return!p}),p})}const jp=(t,e={})=>({tr:n,state:i,dispatch:a})=>{const{selection:o}=n,{empty:l,ranges:u}=o,c=ht(t,i.schema);if(a)if(l){const p=qp(i,c);n.addStoredMark(c.create({...p,...e}))}else u.forEach(p=>{const h=p.$from.pos,f=p.$to.pos;i.doc.nodesBetween(h,f,(g,b)=>{const w=Math.max(b,h),_=Math.min(b+g.nodeSize,f);g.marks.find(L=>L.type===c)?g.marks.forEach(L=>{c===L.type&&n.addMark(w,_,c.create({...L.attrs,...e}))}):n.addMark(w,_,c.create(e))})});return Fp(i,n,c)},Wp=(t,e)=>({tr:n})=>(n.setMeta(t,e),!0),Rp=(t,e={})=>({state:n,dispatch:i,chain:a})=>{const o=Ce(t,n.schema);return o.isTextblock?a().command(({commands:l})=>be.setBlockType(o,e)(n)?!0:l.clearNodes()).command(({state:l})=>be.setBlockType(o,e)(l,i)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},Qp=t=>({tr:e,dispatch:n})=>{if(n){const{doc:i}=e,a=Ct(t,0,i.content.size),o=Oe.create(i,a);e.setSelection(o)}return!0},Up=t=>({tr:e,dispatch:n})=>{if(n){const{doc:i}=e,{from:a,to:o}=typeof t=="number"?{from:t,to:t}:t,l=ge.atStart(i).from,u=ge.atEnd(i).to,c=Ct(a,l,u),p=Ct(o,l,u),h=ge.create(i,c,p);e.setSelection(h)}return!0},Kp=t=>({state:e,dispatch:n})=>{const i=Ce(t,e.schema);return tr.sinkListItem(i)(e,n)};function us(t,e){const n=t.storedMarks||t.selection.$to.parentOffset&&t.selection.$from.marks();if(n){const i=n.filter(a=>e==null?void 0:e.includes(a.type.name));t.tr.ensureMarks(i)}}const Yp=({keepMarks:t=!0}={})=>({tr:e,state:n,dispatch:i,editor:a})=>{const{selection:o,doc:l}=e,{$from:u,$to:c}=o,p=a.extensionManager.attributes,h=Tn(p,u.node().type.name,u.node().attrs);if(o instanceof Oe&&o.node.isBlock)return!u.parentOffset||!wn(l,u.pos)?!1:(i&&(t&&us(n,a.extensionManager.splittableMarks),e.split(u.pos).scrollIntoView()),!0);if(!u.parent.isBlock)return!1;if(i){const f=c.parentOffset===c.parent.content.size;o instanceof ge&&e.deleteSelection();const g=u.depth===0?void 0:Vp(u.node(-1).contentMatchAt(u.indexAfter(-1)));let b=f&&g?[{type:g,attrs:h}]:void 0,w=wn(e.doc,e.mapping.map(u.pos),1,b);if(!b&&!w&&wn(e.doc,e.mapping.map(u.pos),1,g?[{type:g}]:void 0)&&(w=!0,b=g?[{type:g,attrs:h}]:void 0),w&&(e.split(e.mapping.map(u.pos),1,b),g&&!f&&!u.parentOffset&&u.parent.type!==g)){const _=e.mapping.map(u.before()),D=e.doc.resolve(_);u.node(-1).canReplaceWith(D.index(),D.index()+1,g)&&e.setNodeMarkup(e.mapping.map(u.before()),g)}t&&us(n,a.extensionManager.splittableMarks),e.scrollIntoView()}return!0},Xp=t=>({tr:e,state:n,dispatch:i,editor:a})=>{var o;const l=Ce(t,n.schema),{$from:u,$to:c}=n.selection,p=n.selection.node;if(p&&p.isBlock||u.depth<2||!u.sameParent(c))return!1;const h=u.node(-1);if(h.type!==l)return!1;const f=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(i){let D=X.empty;const L=u.index(-1)?1:u.index(-2)?2:3;for(let pe=u.depth-L;pe>=u.depth-3;pe-=1)D=X.from(u.node(pe).copy(D));const N=u.indexAfter(-1)<u.node(-2).childCount?1:u.indexAfter(-2)<u.node(-3).childCount?2:3,J=Tn(f,u.node().type.name,u.node().attrs),ae=((o=l.contentMatch.defaultType)===null||o===void 0?void 0:o.createAndFill(J))||void 0;D=D.append(X.from(l.createAndFill(null,ae)||void 0));const K=u.before(u.depth-(L-1));e.replace(K,u.after(-N),new te(D,4-L,0));let oe=-1;e.doc.nodesBetween(K,e.doc.content.size,(pe,me)=>{if(oe>-1)return!1;pe.isTextblock&&pe.content.size===0&&(oe=me+1)}),oe>-1&&e.setSelection(ge.near(e.doc.resolve(oe))),e.scrollIntoView()}return!0}const g=c.pos===u.end()?h.contentMatchAt(0).defaultType:null,b=Tn(f,h.type.name,h.attrs),w=Tn(f,u.node().type.name,u.node().attrs);e.delete(u.pos,c.pos);const _=g?[{type:l,attrs:b},{type:g,attrs:w}]:[{type:l,attrs:b}];if(!wn(e.doc,u.pos,2))return!1;if(i){const{selection:D,storedMarks:L}=n,{splittableMarks:N}=a.extensionManager,J=L||D.$to.parentOffset&&D.$from.marks();if(e.split(u.pos,2,_).scrollIntoView(),!J||!i)return!0;const ae=J.filter(K=>N.includes(K.type.name));e.ensureMarks(ae)}return!0},Br=(t,e)=>{const n=Lr(l=>l.type===e)(t.selection);if(!n)return!0;const i=t.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(i===void 0)return!0;const a=t.doc.nodeAt(i);return n.node.type===(a==null?void 0:a.type)&&Ua(t.doc,n.pos)&&t.join(n.pos),!0},Or=(t,e)=>{const n=Lr(l=>l.type===e)(t.selection);if(!n)return!0;const i=t.doc.resolve(n.start).after(n.depth);if(i===void 0)return!0;const a=t.doc.nodeAt(i);return n.node.type===(a==null?void 0:a.type)&&Ua(t.doc,i)&&t.join(i),!0};var Jp=Object.freeze({__proto__:null,blur:Jd,clearContent:Zd,clearNodes:Hd,command:ep,createParagraphNear:tp,deleteCurrentNode:np,deleteNode:rp,deleteRange:ip,deleteSelection:ap,enter:sp,exitCode:op,extendMarkRange:up,first:cp,focus:pp,forEach:hp,insertContent:fp,insertContentAt:yp,joinUp:bp,joinDown:vp,joinBackward:xp,joinForward:wp,keyboardShortcut:Sp,lift:_p,liftEmptyBlock:kp,liftListItem:Tp,newlineInCode:Dp,resetAttributes:Ip,scrollIntoView:Mp,selectAll:Ap,selectNodeBackward:zp,selectNodeForward:Ep,selectParentNode:Pp,selectTextblockEnd:Lp,selectTextblockStart:Bp,setContent:$p,setMark:jp,setMeta:Wp,setNode:Rp,setNodeSelection:Qp,setTextSelection:Up,sinkListItem:Kp,splitBlock:Yp,splitListItem:Xp,toggleList:(t,e,n,i={})=>({editor:a,tr:o,state:l,dispatch:u,chain:c,commands:p,can:h})=>{const{extensions:f,splittableMarks:g}=a.extensionManager,b=Ce(t,l.schema),w=Ce(e,l.schema),{selection:_,storedMarks:D}=l,{$from:L,$to:N}=_,J=L.blockRange(N),ae=D||_.$to.parentOffset&&_.$from.marks();if(!J)return!1;const K=Lr(oe=>ls(oe.type.name,f))(_);if(J.depth>=1&&K&&J.depth-K.depth<=1){if(K.node.type===b)return p.liftListItem(w);if(ls(K.node.type.name,f)&&b.validContent(K.node.content)&&u)return c().command(()=>(o.setNodeMarkup(K.pos,b),!0)).command(()=>Br(o,b)).command(()=>Or(o,b)).run()}return!n||!ae||!u?c().command(()=>h().wrapInList(b,i)?!0:p.clearNodes()).wrapInList(b,i).command(()=>Br(o,b)).command(()=>Or(o,b)).run():c().command(()=>{const oe=h().wrapInList(b,i),pe=ae.filter(me=>g.includes(me.type.name));return o.ensureMarks(pe),oe?!0:p.clearNodes()}).wrapInList(b,i).command(()=>Br(o,b)).command(()=>Or(o,b)).run()},toggleMark:(t,e={},n={})=>({state:i,commands:a})=>{const{extendEmptyMarkRange:o=!1}=n,l=ht(t,i.schema);return Gp(i,l,e)?a.unsetMark(l,{extendEmptyMarkRange:o}):a.setMark(l,e)},toggleNode:(t,e,n={})=>({state:i,commands:a})=>{const o=Ce(t,i.schema),l=Ce(e,i.schema);return Pr(i,o,n)?a.setNode(l):a.setNode(o,n)},toggleWrap:(t,e={})=>({state:n,commands:i})=>{const a=Ce(t,n.schema);return Pr(n,a,e)?i.lift(a):i.wrapIn(a,e)},undoInputRule:()=>({state:t,dispatch:e})=>{const n=t.plugins;for(let i=0;i<n.length;i+=1){const a=n[i];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:i,ranges:a}=n;return i||e&&a.forEach(o=>{t.removeMark(o.$from.pos,o.$to.pos)}),!0},unsetMark:(t,e={})=>({tr:n,state:i,dispatch:a})=>{var o;const{extendEmptyMarkRange:l=!1}=e,{selection:u}=n,c=ht(t,i.schema),{$from:p,empty:h,ranges:f}=u;if(!a)return!0;if(h&&l){let{from:g,to:b}=u;const w=(o=p.marks().find(D=>D.type===c))===null||o===void 0?void 0:o.attrs,_=ns(p,c,w);_&&(g=_.from,b=_.to),n.removeMark(g,b,c)}else f.forEach(g=>{n.removeMark(g.$from.pos,g.$to.pos,c)});return n.removeStoredMark(c),!0},updateAttributes:(t,e={})=>({tr:n,state:i,dispatch:a})=>{let o=null,l=null;const u=ss(typeof t=="string"?t:t.name,i.schema);return u?(u==="node"&&(o=Ce(t,i.schema)),u==="mark"&&(l=ht(t,i.schema)),a&&n.selection.ranges.forEach(c=>{const p=c.$from.pos,h=c.$to.pos;i.doc.nodesBetween(p,h,(f,g)=>{o&&o===f.type&&n.setNodeMarkup(g,void 0,{...f.attrs,...e}),l&&f.marks.length&&f.marks.forEach(b=>{if(l===b.type){const w=Math.max(g,p),_=Math.min(g+f.nodeSize,h);n.addMark(w,_,l.create({...b.attrs,...e}))}})})}),!0):!1},wrapIn:(t,e={})=>({state:n,dispatch:i})=>{const a=Ce(t,n.schema);return be.wrapIn(a,e)(n,i)},wrapInList:(t,e={})=>({state:n,dispatch:i})=>{const a=Ce(t,n.schema);return tr.wrapInList(a,e)(n,i)}});et.create({name:"commands",addCommands(){return{...Jp}}}),et.create({name:"editable",addProseMirrorPlugins(){return[new Xt({key:new Jt("editable"),props:{editable:()=>this.editor.options.editable}})]}}),et.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:t}=this;return[new Xt({key:new Jt("focusEvents"),props:{handleDOMEvents:{focus:(e,n)=>{t.isFocused=!0;const i=t.state.tr.setMeta("focus",{event:n}).setMeta("addToHistory",!1);return e.dispatch(i),!1},blur:(e,n)=>{t.isFocused=!1;const i=t.state.tr.setMeta("blur",{event:n}).setMeta("addToHistory",!1);return e.dispatch(i),!1}}}})]}}),et.create({name:"keymap",addKeyboardShortcuts(){const t=()=>this.editor.commands.first(({commands:l})=>[()=>l.undoInputRule(),()=>l.command(({tr:u})=>{const{selection:c,doc:p}=u,{empty:h,$anchor:f}=c,{pos:g,parent:b}=f,w=ie.atStart(p).from===g;return!h||!w||!b.type.isTextblock||b.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()]),i={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={...i},o={...i,"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 Er()||as()?o:a},addProseMirrorPlugins(){return[new Xt({key:new Jt("clearDocument"),appendTransaction:(t,e,n)=>{if(!(t.some(w=>w.docChanged)&&!e.doc.eq(n.doc)))return;const{empty:a,from:o,to:l}=e.selection,u=ie.atStart(e.doc).from,c=ie.atEnd(e.doc).to;if(a||!(o===u&&l===c)||!(n.doc.textBetween(0,n.doc.content.size," "," ").length===0))return;const f=n.tr,g=es({state:n,transaction:f}),{commands:b}=new Wd({editor:this.editor,state:g});if(b.clearNodes(),!!f.steps.length)return f}})]}}),et.create({name:"tabindex",addProseMirrorPlugins(){return[new Xt({key:new Jt("tabindex"),props:{attributes:this.editor.isEditable?{tabindex:"0"}:{}}})]}});const cs=et.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()}}}),Zp=["8","10","12","14","16","18","20","24","30","36","48","60","72"].map(t=>`${t}px`),Hp=[{label:"auto",value:""}].concat(Zp.map(t=>({label:t,value:t}))),eh={input:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important"}},th=({editor:t})=>{const e=t.getAttributes("textStyle").fontSize;return r(j.RichTextEditor.ControlsGroup,{children:r(s.NativeSelect,{size:"xs",icon:r(M.IconTextSize,{stroke:1.5,size:16}),data:Hp,styles:eh,value:e||"",onChange:n=>{const i=n.currentTarget.value;i?t.chain().focus().setFontSize(i).run():t.chain().focus().unsetFontSize().run()}})})},Dn=({value:t,styles:e={}})=>{const n=ra.useEditor({extensions:[ia,na,j.Link,Yi,Ki,Qi,Zi.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),ta,ea,Hi,Xi.configure({types:["heading","paragraph"]}),Ui.configure({placeholder:"This is placeholder"}),Ji,Ri.Color,cs],content:t,editable:!1});m.useEffect(()=>{n==null||n.commands.setContent(t)},[t,n]);const i=m.useMemo(()=>x.defaultsDeep({},{content:wr},e),[e]);return r(j.RichTextEditor,{editor:n,styles:i,children:r(j.RichTextEditor.Content,{})})};function nh(){const[t,{open:e,close:n}]=ye.useDisclosure(!1);return d(z,{children:[r(s.Modal,{opened:t,onClose:n,title:"About FunctionUtils",zIndex:330,withinPortal:!0,children:r(Dn,{value:Ju,styles:{root:{border:"none"},content:{padding:0,table:{marginBottom:0}}}})}),r(s.Button,{variant:"light",color:"violet",size:"xs",onClick:e,leftIcon:r(M.IconInfoCircle,{size:16}),children:"About parameter 'utils'"})]})}const rh=({value:t,onChange:e})=>{const n=i=>{i&&e(i)};return r(s.Box,{sx:{position:"relative",flexGrow:1},children:r(ve,{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}}})})},Zt=m.forwardRef(({value:t,onChange:e,label:n,defaultValue:i},a)=>{const[o,l]=m.useState(t),u=()=>{e(o)},c=()=>{l(t)},p=()=>{l(i)};m.useEffect(()=>{l(t)},[t]);const h=o!==t;return d(s.Stack,{spacing:4,sx:{height:"100%"},children:[d(s.Group,{mb:6,position:"apart",sx:{flexShrink:0,flexGrow:0},children:[r(s.Group,{position:"left",children:r(nh,{})}),d(s.Group,{position:"right",children:[r(s.Button,{onClick:p,size:"xs",variant:"default",leftIcon:r(M.IconPlayerSkipBack,{size:16}),children:"Reset to default"}),r(s.Button,{onClick:c,color:"red",size:"xs",disabled:!h,leftIcon:r(M.IconRecycle,{size:16}),children:"Revert Changes"}),r(s.Button,{size:"xs",onClick:u,disabled:!h,leftIcon:r(M.IconDeviceFloppy,{size:16}),children:"Confirm Changes"})]})]}),r(s.Text,{size:14,children:n}),r(rh,{value:o,onChange:l})]})}),ih=m.forwardRef(({value:t,onChange:e,label:n,triggerLabel:i="Edit",triggerButtonProps:a={},defaultValue:o},l)=>{const[u,{open:c,close:p}]=ye.useDisclosure(!1);return d(z,{children:[r(s.Modal,{opened:u,onClose:p,title:"Authentication",withinPortal:!0,zIndex:320,size:"900px",children:r(s.Box,{h:600,children:r(Zt,{value:t,onChange:e,defaultValue:o,label:n})})}),r(s.Button,{onClick:c,...a,children:i})]})}),ds=["function aggregation({ queryData }, utils) {",' return "Aggregation Result";',"}"].join(`
|
|
105
|
+
`),At={type:"none",config:{}};function ah(t){const e=Array.from(t).sort((i,a)=>i-a),n=Math.floor(e.length/2);return e.length%2===0?(e[n-1]+e[n])/2:e[n]}function sh(t){const e=Number(t);return isFinite(e)?e:0}function oh(t,e){switch(e.type){case"sum":return x.sum(t);case"mean":return x.mean(t);case"median":return ah(t);case"max":return x.max(t)??0;case"min":return x.min(t)??0;case"quantile":return Vt.quantile(t,e.config.p)??0;case"CV":const n=un.std(...t),i=un.mean(...t);return i?n/i:"N/A";case"std":return un.std(...t);default:return t}}function $r(t,e){const n=t.map(sh);return oh(n,e)}function lh(t,e,n){try{const i=Wt(t,e);return new Function(`return ${n.config.func}`)()({queryData:i},mt)}catch(i){return console.error(i),i.message}}function In(t,e,n){try{return n.type==="custom"?lh(t,e,n):$r(at(t,e),n)}catch(i){return console.error(i),null}}const uh=[{label:"None",value:"none"},{label:"Sum",value:"sum"},{label:"Mean",value:"mean"},{label:"Median",value:"median"},{label:"Max",value:"max"},{label:"Min",value:"min"},{label:"Coefficient of Variation",value:"CV"},{label:"Standard Variation",value:"std"},{label:"Quantile(99%, 95%, ...)",value:"quantile"},{label:"Custom",value:"custom"}];function ch({label:t,value:e,onChange:n,pt:i="sm"},a){m.useEffect(()=>{typeof e=="string"&&n({type:e,config:{}})},[e,n]);const o=c=>{n(c==="quantile"?{type:"quantile",config:{p:.99}}:c==="custom"?{type:"custom",config:{func:ds}}:{type:c,config:{}})},l=c=>{n({type:"quantile",config:{p:c}})},u=c=>{n({type:"custom",config:{func:c}})};return d(s.Group,{grow:!0,noWrap:!0,pt:i,children:[r(s.Select,{ref:a,label:t,data:uh,value:e.type,onChange:o}),e.type==="quantile"&&r(s.NumberInput,{label:"p",value:e.config.p,onChange:l,precision:2,min:.05,step:.05,max:1}),e.type==="custom"&&r(ih,{label:"",triggerLabel:"Edit Function",value:e.config.func,onChange:u,defaultValue:ds,triggerButtonProps:{size:"xs",sx:{flexGrow:0,alignSelf:"center",marginTop:"22px"},leftIcon:r(M.IconMathFunction,{size:16})}})]})}const Mn=m.forwardRef(ch);function dh({label:t,value:e,onChange:n},i){const[a,o]=m.useState(Array.isArray(e)?[...e]:[]),l=m.useCallback(()=>{o(g=>[...g,""])},[o]),u=m.useCallback(g=>{o(b=>(b.splice(g,1),[...b]))},[o]),c=m.useMemo(()=>!x.isEqual(a,e),[a,e]),p=()=>{n(a.map(g=>g.toString()))},h=s.useMantineTheme(),f=m.useMemo(()=>Object.entries(h.colors).map(([g,b])=>b[6]),[h]);return d(z,{children:[d(s.Group,{position:"left",ref:i,children:[r(s.Text,{children:t}),r(s.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!c,onClick:p,children:r(T.DeviceFloppy,{size:20})})]}),d(s.Group,{children:[a.map((g,b)=>r(s.ColorInput,{value:g,onChange:w=>{o(_=>(_.splice(b,1,w),[..._]))},swatches:f,rightSection:r(s.ActionIcon,{onClick:()=>u(b),color:"red",children:r(T.Trash,{size:14})}),sx:{width:"45%"}})),r(s.ActionIcon,{onClick:l,color:"blue",variant:"outline",children:r(T.PlaylistAdd,{size:20})})]})]})}const ph=m.forwardRef(dh);function hh({value:t,onChange:e},n){const{colorManager:i}=m.useContext(tt),a=m.useMemo(()=>i.getStaticColors().map(u=>({label:u.name,group:u.category,value:u.value})),[i]),o=m.useMemo(()=>a.some(l=>l.value===t),[t,a]);return d(s.Group,{position:"apart",spacing:4,ref:n,children:[r(s.TextInput,{placeholder:"Set any color",value:o?"":t,onChange:l=>e(l.currentTarget.value),rightSection:r(s.ColorSwatch,{color:o?"transparent":t,radius:4}),variant:o?"filled":"default",sx:{maxWidth:"46%",flexGrow:1}}),r(s.Text,{sx:{flexGrow:0},children:"or"}),r(s.Select,{data:a,value:t,onChange:e,variant:o?"default":"filled",placeholder:"Pick a theme color",icon:r(s.ColorSwatch,{color:o?t:"transparent",radius:4}),sx:{maxWidth:"46%",flexGrow:1}})]})}const Te=m.forwardRef(hh),An=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function fh({label:t,value:e,onChange:n},i){var l;const[a,o]=m.useState(((l=An.find(u=>u.label===e))==null?void 0:l.value)??An[0].value);return m.useEffect(()=>{const u=An.find(c=>c.value===a);u&&n(u.label)},[a]),d(s.Stack,{spacing:0,mt:"sm",mb:"lg",children:[r(s.Text,{size:"sm",children:t}),r(s.Slider,{label:null,marks:An,value:a,onChange:o,step:25,placeholder:"Pick a font size",px:"1em",ref:i})]})}const ps=m.forwardRef(fh);function gh({label:t,value:e,onChange:n,type:i},a){const[o,l]=m.useState(Array.isArray(e)?[...e]:[]),u=m.useCallback(()=>{l(f=>[...f,""])},[l]),c=m.useCallback(f=>{l(g=>(g.splice(f,1),[...g]))},[l]),p=m.useMemo(()=>!x.isEqual(o.map(String),e.map(String)),[o,e]),h=()=>{n(o.map(f=>i==="number"?Number(f):f.toString()))};return d(z,{children:[d(s.Group,{position:"left",ref:a,children:[r(s.Text,{children:t}),r(s.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!p,onClick:h,children:r(T.DeviceFloppy,{size:20})})]}),d(s.Group,{children:[o.map((f,g)=>r(s.TextInput,{type:i,value:f,onChange:b=>{const w=b.currentTarget.value;l(_=>(_.splice(g,1,w),[..._]))},rightSection:r(s.ActionIcon,{onClick:()=>c(g),color:"red",children:r(T.Trash,{size:14})}),sx:{width:"45%"}})),r(s.ActionIcon,{onClick:u,color:"blue",variant:"outline",children:r(T.PlaylistAdd,{size:20})})]})]})}const mh=m.forwardRef(gh),hs=m.forwardRef(function({value:e,onChange:n},i){const a=e.color.type,o=(u,c)=>{const p=x.cloneDeep(e);x.set(p,u,c),n(p)},l=u=>{if(u==="static"){n({...e,color:{type:"static",staticColor:"#25262B"}});return}n({...e,color:{type:"continuous",colorRange:[],valueRange:[]}})};return d(z,{children:[r(s.Divider,{my:"xs",label:"Typography",labelPosition:"center"}),r(s.Stack,{children:r(s.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1},value:e.size,onChange:u=>o("size",u.currentTarget.value)})}),r(s.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:r(ps,{label:"Font Weight",value:e.weight,onChange:u=>o("weight",u)})}),r(s.Divider,{my:"xs",label:"Style",labelPosition:"center"}),d(s.Stack,{children:[r(s.Select,{label:"Color Type",data:[{label:"Static Color",value:"static"},{label:"Continuous Color",value:"continuous"}],value:e.color.type,onChange:l}),a==="static"&&r(Te,{value:e.color.staticColor,onChange:u=>o("color.staticColor",u)}),a==="continuous"&&d(z,{children:[r(mh,{label:"Value Range",value:e.color.valueRange,type:"number",onChange:u=>o("color.valueRange",u)}),r(ph,{label:"Color Range",value:e.color.colorRange,onChange:u=>o("color.colorRange",u)})]})]})]})});m.forwardRef(function({value:e,onChange:n,withStyle:i=!0},a){const o=(l,u)=>{const c=x.cloneDeep(e);x.set(c,l,u),n(c)};return d(s.Box,{px:"sm",py:"md",ref:a,children:[r(s.Text,{weight:"bold",pb:0,children:e.name}),r(s.Divider,{my:"xs",label:"Data",labelPosition:"center"}),d(s.Group,{grow:!0,noWrap:!0,children:[r(s.TextInput,{label:"Name",required:!0,value:e.name,onChange:l=>o("name",l.currentTarget.value)}),r(O,{label:"Data Field",required:!0,value:e.data_field,onChange:l=>o("data_field",l)})]}),r(Mn,{label:"Aggregation",value:e.aggregation,onChange:l=>o("aggregation",l)}),r(s.Divider,{my:"xs",label:"Format",labelPosition:"center"}),e.aggregation.type!=="custom"&&r(Pe,{value:e.formatter,onChange:l=>o("formatter",l)}),i&&r(hs,{value:e,onChange:n})]})});class yh{constructor({valueRange:e,colorRange:n}){P(this,"mapper");this.mapper=ft.interpolate(e,n)}getColor(e){return this.mapper(e)}}function bh(t){return t===null?"null":t===void 0?"undefined":Array.isArray(t)?`Array(${t.length})`:t.toString()}function ot({data_field:t,aggregation:e},n){return In(n,t,e)}function Fe({formatter:t,aggregation:e},n){if(!["string","number"].includes(typeof n))return bh(n);if(e.type==="custom")return n;try{return W(n).format(t)}catch(i){return console.error(i),n}}function vh(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 yh(t).getColor(e)}catch(n){return console.error(n),"black"}return"black"}function fs(t,e){const{color:n,data_field:i,aggregation:a,size:o,weight:l}=t,u=In(e,i,a),c=Fe(t,u);return r(s.Text,{sx:{fontSize:o,display:"inline"},color:vh(n,u),weight:l,children:c})}function xh(t,e){const n={};return t.forEach(i=>{const a=i.name;n[a]=fs(i,e)}),n}function wh(t){return t.split(" ").map((e,n)=>d(m.Fragment,{children:[e," "]},n))}function Ch(t){const n=t.replaceAll("<br />","<br/>").replaceAll(`
|
|
106
|
+
`,"<br/>").split("<br/>");return n.map((a,o)=>{const l=[wh(a)];return o!==n.length-1&&l.push(r("br",{},`br-${o}`)),l}).flat().filter(a=>a!==void 0)}function Vr(t){return Ch(t)}function Ht(t,e,n){const i=xh(e,n),a=/^\{(.+)\}(.*)$/;return t.split("$").map((o,l)=>{const u=a.exec(o);if(!u)return Vr(o);const c=i[u[1]];if(!c)return Vr(o);const p=u[2]??"";return d(m.Fragment,{children:[c,Vr(p)]},`${o}-${l}`)})}function Sh(t,e){const n={};return t.forEach(i=>{const{name:a,data_field:o,aggregation:l}=i,u=In(e,o,l);n[a]=Fe(i,u)}),n}function zn(t,e,n){const i=Sh(e,n),a=/^\{(.+)\}(.*)$/;return t.split("$").map(o=>{const l=a.exec(o);if(!l)return o;const u=i[l[1]];if(!u)return o;const c=l[2]??"";return`${u}${c}`}).join("")}function _h(t,e,n){const i=e.reduce((a,o)=>{const l=ot(o,n);return a[o.name]=Fe(o,l),a},{});return t.map(a=>({name:"refs",type:"scatter",data:[],markLine:{data:[{name:a.name,yAxis:Number(i[a.variable_key])}],silent:!0,symbol:["none","none"],label:{formatter:function(){return zn(a.template,e,n)},position:"insideEndTop"}}}))}function kh(t){const e={top:30,left:20,right:15,bottom:25,containLabel:!0};return t.legend.orient==="vertical"&&(e.right=80),e}function Th({config:t,data:e,variables:n}){const{x_axis:i,y_axis:a,reference_lines:o}=t,l=wd(t,e),u=Ue(i.axisLabel.overflow.on_axis),c=Sd(t);return{grid:kh(t),dataset:l,legend:Cd({config:t}),tooltip:Md({config:t}),xAxis:[{type:"category",name:i.name,nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold",align:"center"},axisTick:{show:!0,alignWithLabel:!0},axisLabel:{...i.axisLabel,...u,formatter:Dt(i.axisLabel.formatter)}}],yAxis:[{name:a.name,minInterval:1,nameTextStyle:{fontWeight:"bold"},axisLine:{show:!0},axisLabel:{formatter:function(p){return W(p).format(a.label_formatter)}}}],series:[...c,..._h(o,n,e)]}}Y.use([B.DataZoomComponent,re.BoxplotChart,B.MarkLineComponent,B.GridComponent,B.LegendComponent,B.TooltipComponent,_e.CanvasRenderer]);function Dh({context:t,instance:e}){const{value:n}=V(t.instanceData,"config"),{variables:i}=t,a=t.data,{width:o,height:l}=t.viewport,u=x.defaults({},n,yr),c=qe({vizManager:t.vizManager,instance:e}),p=Ne(c.triggerManager,Ia.id),h=yt(a,u.x_axis.data_key),f=m.useCallback(w=>{const _=x.get(h,w.name,{error:"rowData is not found"});p.forEach(D=>{c.runInteraction(D.id,{...w,rowData:_})})},[h,p,c]),g=m.useMemo(()=>({click:f}),[f]),b=m.useMemo(()=>Th({config:u,data:a,variables:i}),[u,a,i]);return!n||!o||!l?null:r(Me,{width:o,height:l,children:r(Se,{echarts:Y,option:b,style:jt(o,l),onEvents:g,notMerge:!0,theme:"merico-light"})})}function Ih({control:t,index:e,remove:n,variableOptions:i}){return d(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`reference_lines.${e}.name`,control:t,render:({field:a})=>r(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...a})}),r(v.Controller,{name:`reference_lines.${e}.variable_key`,control:t,render:({field:a})=>r(s.Select,{label:"Value",required:!0,data:i,sx:{flex:1},...a})})]}),r(v.Controller,{name:`reference_lines.${e}.template`,control:t,render:({field:a})=>r(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",required:!0,sx:{flex:1},...a})}),r(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(e),sx:{position:"absolute",top:15,right:5},children:r(T.Trash,{size:16})})]})}function Mh({control:t,watch:e,variables:n}){const{fields:i,append:a,remove:o}=v.useFieldArray({control:t,name:"reference_lines"}),l=e("reference_lines"),u=i.map((h,f)=>({...h,...l[f]})),c=()=>a({name:"",template:"",variable_key:""}),p=m.useMemo(()=>n.map(h=>({label:h.name,value:h.name})),[n]);return d(s.Stack,{children:[u.map((h,f)=>r(Ih,{control:t,index:f,remove:o,variableOptions:p},h.id)),r(s.Group,{position:"center",mt:"xs",children:r(s.Button,{onClick:c,children:"Add a Reference Line"})})]})}const Ah=({disabled:t,value:e,onChange:n})=>{const i=a=>{a&&n(a)};return d(s.Box,{sx:{position:"relative"},children:[t&&r(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),r(ve,{height:"500px",defaultLanguage:"javascript",value:e,onChange:i,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},En=m.forwardRef(({value:t,onChange:e},n)=>{const[i,{setTrue:a,setFalse:o}]=q.useBoolean(),[l,u]=m.useState(t);m.useEffect(()=>{u(t)},[t]);const c=b=>{u({...l,enabled:b})},p=()=>{o();const{enabled:b,func_content:w}=l,_={enabled:b,func_content:w};u(_),e(_)},h=()=>{o(),u(t)},f=b=>{u(w=>({...w,func_content:b}))},g=()=>{f(Ve.func_content)};return d(z,{children:[r(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Customize Label"}),r(s.Modal,{size:800,title:"Customize label content",opened:i,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:i&&d(s.Stack,{children:[r(s.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:b=>c(b.currentTarget.checked)}),r(Ah,{value:l.func_content,onChange:f,disabled:!l.enabled}),d(s.Group,{position:"apart",children:[r(s.Button,{onClick:g,color:"red",leftIcon:r(T.Recycle,{size:20}),children:"Reset"}),d(s.Group,{position:"right",children:[r(s.Button,{onClick:h,variant:"subtle",children:"Cancel"}),r(s.Button,{onClick:p,children:"OK"})]})]})]})})]})}),zh=({control:t,watch:e})=>(e(["x_axis"]),d(s.Stack,{children:[d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>r(s.TextInput,{label:"X Axis Name",sx:{flex:1},...n})}),r(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>r(O,{label:"X Axis Data Field",required:!0,sx:{flex:1},...n})})]}),r(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>r(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:r(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),r(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>r(En,{...n})})]}),r(v.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>r(Je,{...n})})]})),Eh=({control:t,watch:e})=>(e(["y_axis"]),d(z,{children:[d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"y_axis.name",control:t,render:({field:n})=>r(s.TextInput,{label:"Y Axis Name",sx:{flex:1},...n})}),r(v.Controller,{name:"y_axis.data_key",control:t,render:({field:n})=>r(O,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})})]}),d(s.Stack,{children:[r(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),r(v.Controller,{name:"y_axis.label_formatter",control:t,render:({field:n})=>r(Pe,{...n})})]})]})),Ph=({control:t,index:e,remove:n})=>d(s.Stack,{children:[d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`tooltip.metrics.${e}.name`,control:t,render:({field:i})=>r(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})}),r(v.Controller,{name:`tooltip.metrics.${e}.data_key`,control:t,render:({field:i})=>r(O,{label:"Value Field",required:!0,sx:{flex:1},...i})})]}),r(s.Divider,{mb:-10,mt:10,variant:"dashed"}),r(s.Button,{leftIcon:r(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),Lh=({control:t,watch:e})=>{const{fields:n,append:i,remove:a}=v.useFieldArray({control:t,name:"tooltip.metrics"}),o=e("tooltip.metrics"),l=n.map((f,g)=>({...f,...o[g]})),u=()=>i({id:Date.now().toString(),data_key:"",name:""}),c=e("tooltip.metrics.0.id"),[p,h]=m.useState(()=>c??null);return m.useEffect(()=>{c&&h(f=>f!==null?f:c)},[c]),d(z,{children:[d(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[r(T.InfoCircle,{size:14,color:"#888"}),r(s.Text,{size:14,color:"#888",children:"Set additional metrics to show in scatter's tooltip"})]}),d(s.Tabs,{value:p,onTabChange:f=>h(f),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[d(s.Tabs.List,{children:[l.map((f,g)=>r(s.Tabs.Tab,{value:f.id,children:f.name?f.name:g},f.id)),r(s.Tabs.Tab,{onClick:u,value:"add",children:r(T.Plus,{size:18,color:"#228be6"})})]}),l.map((f,g)=>r(s.Tabs.Panel,{value:f.id,children:r(Ph,{control:t,index:g,remove:a},f.id)},f.id))]})]})};function Bh({control:t,watch:e}){return r(s.Stack,{children:r(Lh,{control:t,watch:e})})}const Oh=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}],$h=({control:t,watch:e})=>{const n=e("legend"),i=(a,o)=>{const l={...n,orient:a};a==="horizontal"?(l.top="0",l.left="auto",l.right="10",l.bottom="auto"):(l.top="10",l.left="auto",l.right="0",l.bottom="auto"),o(l)};return d(s.Stack,{children:[r(s.Group,{grow:!0,noWrap:!0,mt:20,children:r(v.Controller,{name:"legend.show",control:t,render:({field:a})=>r(s.Switch,{label:"Show Legend",sx:{flex:1},checked:a.value,onChange:o=>a.onChange(o.currentTarget.checked)})})}),r(s.Group,{children:r(v.Controller,{name:"legend",control:t,render:({field:a})=>r(s.Select,{label:"Orientation",data:Oh,sx:{flex:1},value:a.value.orient,onChange:o=>{i(o,a.onChange)},disabled:!n.show})})})]})};function Vh({context:t}){const{value:e,set:n}=V(t.instanceData,"config"),{variables:i}=t,a=m.useMemo(()=>x.defaults({},e,yr),[e]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:p}=v.useForm({defaultValues:a});m.useEffect(()=>{p(a)},[a]),u(["x_axis","y_axis","reference_lines","color"]);const h=c(),f=m.useMemo(()=>!x.isEqual(h,e),[h,e]);return r(s.Stack,{spacing:"xs",children:d("form",{onSubmit:l(n),children:[d(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(s.Text,{children:"Chart Config"}),r(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:r(T.DeviceFloppy,{size:20})})]}),d(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[d(s.Tabs.List,{children:[r(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),r(s.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),r(s.Tabs.Tab,{value:"Legend",children:"Legend"}),r(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"}),r(s.Tabs.Tab,{value:"Style",children:"Style"}),r(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"})]}),r(s.Tabs.Panel,{value:"X Axis",children:r(zh,{control:o,watch:u})}),r(s.Tabs.Panel,{value:"Y Axis",children:r(Eh,{control:o,watch:u})}),r(s.Tabs.Panel,{value:"Legend",children:r($h,{control:o,watch:u})}),r(s.Tabs.Panel,{value:"Tooltip",children:r(Bh,{control:o,watch:u})}),r(s.Tabs.Panel,{value:"Style",children:d(s.Stack,{spacing:4,children:[r(s.Text,{size:"sm",children:"Color"}),r(v.Controller,{name:"color",control:o,render:({field:g})=>r(Te,{...g})})]})}),r(s.Tabs.Panel,{value:"Reference Lines",children:r(Mh,{variables:i,control:o,watch:u})})]})]})})}function Nh(t){return x.omit(t,"variables")}function qh(t){const{label_formatter:e=xe,...n}=t.y_axis;return{...t,y_axis:{...n,label_formatter:e}}}function Gh(t){const e={rotate:0,formatter:{...Ve}},{axisLabel:n=e,...i}=t.x_axis;return{...t,x_axis:{...i,axisLabel:n}}}function Fh(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 jh(t){delete t.config;const{x_axis:e,tooltip:n}=t.x_axis.axisLabel.overflow,i={x_axis:{axisLabel:{overflow:{on_axis:e,in_tooltip:n}}}};return x.defaultsDeep(i,t)}function Wh(t){const e={tooltip:{metrics:[]}};return x.defaultsDeep(e,t)}function Rh(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=c=>c&&`${n}.${c}`,{x_axis:a,y_axis:o,tooltip:l,...u}=t;return{...u,x_axis:{...a,data_key:i(a.data_key)},y_axis:{...o,data_key:i(o.data_key)},tooltip:{...l,metrics:l.metrics.map(c=>({...c,data_key:i(c.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}function Qh(t){const e={legend:{show:!0,top:"0",right:"10",left:"auto",bottom:"auto",orient:"horizontal",type:"scroll"}};return x.defaultsDeep(e,t)}class Uh extends se{constructor(){super(...arguments);P(this,"VERSION",9)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,{panelModel:i})=>{const{config:a}=n;return(a.variables||[]).forEach(l=>{i.variables.find(u=>u.name===l.name)||i.addVariable(l)}),{...n,version:2,config:Nh(a)}}),this.version(3,n=>{const{config:i}=n;return{...n,version:3,config:qh(i)}}),this.version(4,n=>{const{config:i}=n;return{...n,version:4,config:Gh(i)}}),this.version(5,n=>{const{config:i}=n;return{...n,version:5,config:Fh(i)}}),this.version(6,n=>{const{config:i}=n;return{...n,version:6,config:jh(i)}}),this.version(7,n=>{const{config:i}=n;return{...n,version:7,config:Wh(i)}}),this.version(8,(n,i)=>{const{config:a}=n;return{...n,version:8,config:Rh(a,i)}}),this.version(9,n=>{const{config:i}=n;return{...n,version:9,config:Qh(i)}})}}const Kh={displayName:"Boxplot Chart",displayGroup:"ECharts-based charts",migrator:new Uh,name:"boxplot",viewRender:Dh,configRender:Vh,createConfig(){return{version:9,config:x.cloneDeep(yr)}},triggers:[Ia]},gs={id:"builtin:button:click-button",displayName:"Click Button",nameRender:Xh,configRender:Yh,payload:[]};function Yh(t){return r(z,{})}function Xh(t){return r(s.Text,{children:"Click this button"})}const Nr={content:"Button",variant:"filled",color:"blue",size:"xs",compact:!1,horizontal_align:"left",vertical_align:"center"},Jh={left:"flex-start",center:"center",right:"flex-end"},Zh={top:"flex-start",center:"center",bottom:"flex-end"},Hh=k.observer(({context:t,instance:e})=>{const n=qe({vizManager:t.vizManager,instance:e}),i=Ne(n.triggerManager,gs.id),a=ue(),{value:o}=V(t.instanceData,"config"),l=m.useMemo(()=>x.defaultsDeep({},o,Nr),[o]),{content:u,horizontal_align:c,vertical_align:p,...h}=l,{width:f,height:g}=t.viewport,b=a.payloadForSQL,w=()=>{i.forEach(_=>{n.runInteraction(_.id,{})})};return r(s.Center,{sx:{width:f,height:g,justifyContent:Jh[c],alignItems:Zh[p]},children:r(s.Button,{...h,onClick:w,children:x.template(u)(b)})})}),ef=({value:t,onChange:e,label:n})=>{const i=s.useMantineTheme(),a=m.useCallback(l=>()=>e(l),[e]),o=l=>t===l;return d(s.Stack,{spacing:2,children:[r(s.Text,{size:14,sx:{fontWeight:500},children:n}),r(s.Group,{position:"left",spacing:"xs",children:Object.keys(i.colors).map(l=>{const u=i.colors[l][6];return r(s.ColorSwatch,{color:u,onClick:a(l),radius:4,size:26,sx:{cursor:"pointer"},children:o(l)&&r(s.CheckIcon,{width:10,color:"white"})},l)})})]})},tf=s.MANTINE_SIZES.map(t=>({label:t.toUpperCase(),value:t})),nf=({label:t,value:e,onChange:n})=>r(s.Select,{data:tf,label:t,value:e,onChange:n}),rf=[{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}],af=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],sf=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function of({context:t}){const{value:e,set:n}=V(t.instanceData,"config"),i=m.useMemo(()=>x.defaultsDeep({},e,Nr),[e]),a=i;m.useEffect(()=>{!x.isEqual(i,a)&&(console.log("config malformed, resetting to defaults",i,a),n(a))},[i,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:p}=v.useForm({defaultValues:a});m.useEffect(()=>{p(a)},[a]);const h=c(),f=m.useMemo(()=>!x.isEqual(h,i),[h,i]);return u(["content","variant","color","size","compact","horizontal_align","vertical_align"]),d("form",{onSubmit:l(n),children:[d(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(s.Text,{children:"Chart Config"}),r(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:r(T.DeviceFloppy,{size:20})})]}),d(s.Stack,{children:[r(v.Controller,{control:o,name:"content",render:({field:g})=>r(s.TextInput,{label:"Content Template",description:"Filter values & context entries are supported",...g,required:!0})}),r(s.Divider,{mt:"xs",mb:0,label:"Styles",labelPosition:"center",variant:"dashed"}),d(s.SimpleGrid,{cols:2,children:[r(v.Controller,{control:o,name:"variant",render:({field:g})=>r(s.Select,{label:"Variant",data:rf,...g})}),r(v.Controller,{control:o,name:"color",render:({field:g})=>r(ef,{label:"Theme",...g})})]}),d(s.SimpleGrid,{cols:2,children:[r(v.Controller,{control:o,name:"size",render:({field:g})=>r(nf,{label:"Size",...g})}),r(v.Controller,{control:o,name:"compact",render:({field:g})=>r(s.Checkbox,{label:"Compact",checked:g.value,onChange:b=>g.onChange(b.currentTarget.checked),mt:26})})]}),d(s.SimpleGrid,{cols:2,children:[r(v.Controller,{control:o,name:"horizontal_align",render:({field:g})=>r(s.Select,{label:"Horizontal Alignment",data:af,...g})}),r(v.Controller,{control:o,name:"vertical_align",render:({field:g})=>r(s.Select,{label:"Vertical Alignment",data:sf,...g})})]})]})]})}class lf extends se{constructor(){super(...arguments);P(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{horizontal_align:i="left",vertical_align:a="center",...o}=n.config;return{...n,version:2,config:{...o,horizontal_align:i,vertical_align:a}}})}}const uf={displayName:"Button",displayGroup:"Others",migrator:new lf,name:"button",viewRender:Hh,configRender:of,createConfig(){return{version:2,config:x.cloneDeep(Nr)}},triggers:[gs]},qr={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:df,configRender:cf,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 cf(t){return r(z,{})}function df(t){return r(s.Text,{children:"Click chart's series"})}const zt={x_axis_scroll:!1,y_axis_scroll:!1,x_axis_slider:!1,y_axis_slider:!1},Gr={regressions:[],series:[],stats:{templates:{bottom:"",top:""}},x_axis:{type:"category",axisLabel:{rotate:0,formatter:{...Ve},overflow:Le}},x_axis_data_key:"",x_axis_name:"",y_axes:[{min:"",max:"",name:"Y Axis",show:!0,position:"left",nameAlignment:"center",label_formatter:xe}],reference_lines:[],reference_areas:[],dataZoom:zt};function Fr(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 pf(t){const e=t.y_axes.some(a=>!!a.name);let n=15;e&&(n+=20),t.dataZoom.x_axis_slider&&(n+=20);let i=5;return t.x_axis_name&&(i+=15),t.series.some(a=>!a.hide_in_legend)&&(i+=20),{top:n,right:15,bottom:i,left:20,containLabel:!0}}function hf(t){return t!=="line"?{}:{itemStyle:{opacity:0}}}function ff(t){switch(t){case"line":return;case"bar":return"roundRect";case"scatter":return"circle"}}function gf(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:i})=>({name:n,icon:ff(i),...hf(i)})),e}function Pn(t,e){switch(t.config.method){case"linear":return[...ct.regressionLinear()(e)];case"exponential":return[...ct.regressionExp()(e)];case"logarithmic":return[...ct.regressionLog()(e)];case"polynomial":return[...ct.regressionPoly().order(t.config.order)(e)];default:return[]}}function mf(t,e,n,i){const{transform:a,plot:o}=t,l={...o,name:e,data:Pn(a,i),showSymbol:!1,tooltip:{show:!1},smooth:!1,custom:{}};return n&&(l.custom={type:"regression-line",targetSeries:n}),l}function yf({regressions:t=[],x_axis_data_key:e},n){const i=[];if(Object.keys(n).length===0)return i;function a(o,l,u,c){const p=mf(o,l,u,c);i.push(p)}return t.forEach(o=>{const{name:l,group_by_key:u}=o;if(!u||u===e){const f=at(n,o.y_axis_data_key).map((g,b)=>[b,Number(g)]);a(o,l,"",f);return}const{columnKey:c}=A(o.y_axis_data_key),p=x.groupBy(Wt(n,o.y_axis_data_key),u);Object.entries(p).forEach(([h,f])=>{const g=f.map((w,_)=>[_,Number(w[c])]);a(o,h,h,g)})}),i}function bf(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 vf(t,e,n,i){return e?i==="value"?[[n[0],t]]:[t]:[]}function xf(t,e,n,i,a,o){return t.map(l=>{const u=n[l.variable_key],c=l.orientation==="horizontal",p=c?"yAxis":"xAxis",h=c?"insideEndTop":"end",f=vf(u,c,a,o);return{name:l.name,type:"scatter",hide_in_legend:!l.show_in_legend,xAxisId:"main-x-axis",yAxisIndex:l.yAxisIndex,data:f,symbol:"none",silent:!0,tooltip:{show:!1},markLine:{data:[{name:l.name,[p]:u}],silent:!0,symbol:["none","none"],lineStyle:l.lineStyle,label:{formatter:function(){return l.template?zn(l.template,e,i):""},position:h}}}})}function wf({type:t,...e},n,i,a){if(!t)return 10;if(t==="static"){const{size:p}=e;return p}const{func_content:o}=e,{queryID:l,columnKey:u}=A(i),c=x.keyBy(Wt(n,l),u);return(p,h)=>{let f;h.name?f=c[h.name]:f=n[h.dataIndex];try{return new Function(`return ${o}`)()({rowData:f,params:h,variables:a},{lodash:x,interpolate:ft.interpolate})}catch(g){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${g.message}`),10}}}function jr(t,e,n){const i=at(t,e),a=at(t,n);return x.zip(i,a)}function Cf(t,e,n,i){const a=jr(e,n,i);return x.unionBy(a,t,0)}function Sf({dataTemplate:t,data:e,x_axis_data_key:n,y_axis_data_key:i,valueTypedXAxis:a}){return a?Cf(t,e,n,i):at(e,i)}function _f({dataTemplate:t,data:e,aggregation_on_value:n,x_axis_data_key:i,y_axis_data_key:a,valueTypedXAxis:o}){if(!n||n.type==="none")return Sf({dataTemplate:t,data:e,x_axis_data_key:i,y_axis_data_key:a,valueTypedXAxis:o});const l=jr(e,i,a),u=x.groupBy(l,"0");return t.map(([p])=>{const f=u[p].map(b=>b[1]),g=$r(f,n);return[p,g]})}function kf({group_by_key:t,data:e,x_axis_data_key:n,y_axis_data_key:i}){const{queryID:a,columnKey:o}=A(t),l=x.groupBy(e[a],o);return Object.entries(l).forEach(([u,c])=>{l[u]=jr({[a]:c},n,i)}),l}function Tf({x_axis_data_key:t,x_axis:e},{y_axis_data_key:n,yAxisIndex:i,label_position:a,name:o,group_by_key:l,aggregation_on_value:u,stack:c,color:p,display_name_on_line:h,symbolSize:f,hide_in_legend:g,...b},w,_,D,L){const N=e.type!=="category",J={label:{show:!!a,position:a,formatter:L[i??"default"]},name:o,xAxisId:"main-x-axis",yAxisIndex:i,stack:c,color:p,symbolSize:wf(f,_,t,D),hide_in_legend:g,labelLayout:{hideOverlap:!0},...b};if(h&&(J.endLabel={show:!0,formatter:o,offset:[-12,12],align:"right"}),!l||l===t)return J.data=_f({dataTemplate:w,data:_,aggregation_on_value:u,x_axis_data_key:t,y_axis_data_key:n,valueTypedXAxis:N}),J;const ae=kf({group_by_key:l,data:_,x_axis_data_key:t,y_axis_data_key:n});return Object.entries(ae).map(([K,oe])=>{const pe=x.cloneDeep(J);return pe.name=K,pe.color=void 0,pe.data=oe,pe})}function Df(t,e,n,i,a,o){const l=e.map(c=>[c,0]);return t.series.map(c=>Tf(t,c,l,n,o,i)).flat().concat(xf(t.reference_lines,a,o,n,e,t.x_axis.type)).concat(bf(t.reference_areas,o))}function If(t,e){const n=t.find(o=>o.axisDim==="x"&&o.axisId==="main-x-axis");if(!n)return"";const{axisValue:i,axisIndex:a}=n;return Dt(e.x_axis.axisLabel.formatter)(i,a)}function Mf(t,e,n){const i=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:p,marker:h,value:f})=>{if(Array.isArray(f)&&f.length===2&&(f=f[1]),!p)return f;const g=i[p],b=n[g]??n.default;return`
|
|
107
107
|
<tr>
|
|
108
|
-
<td>${
|
|
109
|
-
<th style="text-align: right; padding: 0 1em;">${
|
|
110
|
-
<td style="text-align: left; padding: 0 1em;">${
|
|
108
|
+
<td>${h}</td>
|
|
109
|
+
<th style="text-align: right; padding: 0 1em;">${p}</th>
|
|
110
|
+
<td style="text-align: left; padding: 0 1em;">${b({value:f})}</td>
|
|
111
111
|
</tr>
|
|
112
|
-
`}),u=
|
|
112
|
+
`}),u=Ze(t.x_axis.axisLabel.overflow.in_tooltip),c=If(o,t);return`
|
|
113
113
|
<div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
|
|
114
114
|
<div style="${u}">${c}</div>
|
|
115
115
|
</div>
|
|
@@ -118,14 +118,14 @@ Check the top-level render call using <`+V+">.")}return z}}function Ou(S,z){{if(
|
|
|
118
118
|
${l.join("")}
|
|
119
119
|
</tbody>
|
|
120
120
|
</table>
|
|
121
|
-
`}}}function Of(e){return e.y_axes.reduce((n,{label_formatter:r},a)=>(n[a]=function(l){let u=l;if(typeof l=="object"&&(Array.isArray(l.value)&&l.value.length===2?u=l.value[1]:u=l.value),!r)return u;try{return Z(u).format(r)}catch(c){return console.error(c),u}},n),{default:({value:n})=>n})}function co(e,t){const n={};return t.map(r=>{const a=yt(r,e);n[r.name]=Ze(r,a)}),n}function Bf(e,t){const{overflow:n,...r}=e.x_axis.axisLabel,a=rt(n.on_axis);return[{data:t,name:e.x_axis_name??"",id:"main-x-axis",axisTick:{show:!0,alignWithLabel:!0},type:e.x_axis.type,axisLabel:{...r,...a,formatter:Ft(r.formatter)}}]}function Vf(e){var t;try{return Array.isArray(e[0])&&((t=e[0])==null?void 0:t.length)>=2?e.map(r=>Number(r[1])):[...e]}catch(n){return console.error(n),[...e]}}function Nf(e){if(e.length===0)return{};const t={},n={};return e.forEach(r=>{const a=Vf(r.data);if(!n[r.yAxisIndex]){n[r.yAxisIndex]=a;return}n[r.yAxisIndex]=n[r.yAxisIndex].concat(a)}),Object.entries(n).forEach(([r,a])=>{const o=x.minBy(a)??0,l=x.maxBy(a)??0;o==0&&l==0&&(t[r]=1)}),t}function qf(e,t,n){const r=Nf(n);return e.y_axes.map(({nameAlignment:a,min:o,max:l,show:u,...c},d)=>{let f=c.position;return f||(f=d>0?"right":"left"),{...c,minInterval:r[d]??0,show:u,min:o||void 0,max:l||void 0,position:f,axisLabel:{show:u,formatter:t[d]??t.default},axisLine:{show:u},nameTextStyle:{fontWeight:"bold",align:a},nameLocation:"end",nameGap:u?15:0,splitLine:{show:!1}}})}const Ff={xAxis:[{type:"category",nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0}}]};function Gf(e,t,n){const r=co(t,n),a=Of(e),o=x.uniq(gt(t,e.x_axis_data_key)),l=$f(e,o,t,a,n,r),u=Sf(e,t),c={xAxis:Bf(e,o),yAxis:qf(e,a,l),series:[...l,...u],tooltip:Pf(e,l,a),grid:bf(e),legend:wf(l),dataZoom:ai(e.dataZoom)};return x.defaultsDeep({},c,Ff)}function po(e){const t=e.getModel(),n=t.getSeries().map(r=>{if(!r.option.custom)return r.option;const a=t.getColorFromPalette(r.option.custom.targetSeries,null);return r.option.color=a,r.option});e.setOption({...e.getOption(),series:n})}ie.use([F.DataZoomComponent,he.BarChart,he.LineChart,he.ScatterChart,F.GridComponent,F.LegendComponent,F.TooltipComponent,ze.CanvasRenderer,F.MarkLineComponent,F.MarkAreaComponent]);function ho(e){return e.trim().length>0}function Wf({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=zt(t,e.x_axis_data_key),u=Ke(a.triggerManager,ri.id),c=m.useCallback(y=>{const C=x.get(l,y.name,{error:"rowData is not found"});u.forEach(w=>{a.runInteraction(w.id,{...y,rowData:C})})},[l,u,a]),d=m.useMemo(()=>Gf(e,t,o),[e,t]),f=m.useRef(),h=m.useMemo(()=>({click:c}),[c]),g=y=>{f.current=y,po(y)};return m.useEffect(()=>{f.current&&po(f.current)},[d]),!n||!r?null:i(Ae,{echarts:ie,option:d,style:{width:n,height:r},onEvents:h,onChartReady:g,notMerge:!0,theme:"merico-light"})}function jf({context:e,instance:t}){const n=Xe({vizManager:e.vizManager,instance:t}),{value:r}=R(e.instanceData,"config"),{variables:a}=e,o=m.useMemo(()=>x.defaults({},r,ii),[r]),l=e.data,{width:u,height:c}=e.viewport,{ref:d,height:f}=_e.useElementSize(),{ref:h,height:g}=_e.useElementSize(),y=m.useMemo(()=>{const{stats:{templates:_}}=o;return{top:yn(_.top,a,l),bottom:yn(_.bottom,a,l)}},[o,l]),C=Math.max(0,nt(c)-f-g),w=tt(u);return p(Be,{width:u,height:c,children:[i(s.Text,{ref:d,align:"left",size:"xs",pl:"sm",sx:{display:ho(o.stats.templates.top)?"block":"none"},children:Object.values(y.top).map((_,D)=>i(m.Fragment,{children:_},D))}),i(Wf,{variables:a,width:w,height:C,data:l,conf:o,interactionManager:n}),i(s.Text,{ref:h,align:"left",size:"xs",pl:"sm",sx:{display:ho(o.stats.templates.bottom)?"block":"none"},children:Object.values(y.bottom).map((_,D)=>i(m.Fragment,{children:_},D))})]})}const oi=m.forwardRef(({value:e,onChange:t},n)=>{const r=a=>o=>{t({...e,[a]:o})};return p(s.Stack,{children:[i(s.Divider,{variant:"dashed",label:"Scroll to Zoom",labelPosition:"center"}),p(s.Group,{children:[i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Enable on X Axis",checked:e.x_axis_scroll,onChange:a=>r("x_axis_scroll")(a.currentTarget.checked)})}),i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Enable on Y Axis",checked:e.y_axis_scroll,onChange:a=>r("y_axis_scroll")(a.currentTarget.checked)})})]}),i(s.Divider,{variant:"dashed",label:"Slider for Zooming",labelPosition:"center"}),p(s.Group,{children:[i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Slider for X Axis",checked:e.x_axis_slider,onChange:a=>r("x_axis_slider")(a.currentTarget.checked)})}),i(s.Tooltip,{label:"Not available for now, will overlap y-axis's label",children:i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Slider for Y Axis",disabled:!e.y_axis_slider,checked:e.y_axis_slider,onChange:a=>r("y_axis_slider")(a.currentTarget.checked)})})})]})]})}),Rf=[{label:"Rectangle",value:"rectangle"}],Yf=[{label:"Horizontal",value:"horizontal"}];function Qf({control:e,index:t,remove:n,variableOptions:r}){return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_areas.${t}.name`,control:e,render:({field:a})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_areas.${t}.color`,control:e,render:({field:a})=>i(s.TextInput,{label:"Color",required:!0,sx:{flex:1},...a})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_areas.${t}.type`,control:e,render:({field:a})=>i(s.Select,{label:"Type",required:!0,data:Rf,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_areas.${t}.direction`,control:e,render:({field:a})=>i(s.Select,{label:"Direction",required:!0,data:Yf,sx:{flex:1},...a})})]}),i(s.Divider,{variant:"dashed",label:"Data",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_areas.${t}.y_keys.upper`,control:e,render:({field:a})=>i(s.Select,{label:"Upper Boundary",required:!0,data:r,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_areas.${t}.y_keys.lower`,control:e,render:({field:a})=>i(s.Select,{label:"Lower Boundary",required:!0,data:r,sx:{flex:1},...a})})]}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Area"})]})}function Uf({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_areas"}),l=t("reference_areas"),u=r.map((f,h)=>({...f,...l[h]})),c=()=>a({name:"",color:"rgba(0,0,0,0.1)",type:"rectangle",direction:"horizontal",y_keys:{upper:"",lower:""}}),d=m.useMemo(()=>n.map(f=>({label:f.name,value:f.name})),[n]);return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"6px 0px 0px"}},children:[p(s.Tabs.List,{children:[u.map((f,h)=>i(s.Tabs.Tab,{value:h.toString(),children:h+1},f.id)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),u.map((f,h)=>i(s.Tabs.Panel,{value:h.toString(),children:i(Qf,{control:e,index:h,remove:o,variableOptions:d})},f.id))]})}const Kf=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Xf=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Jf({control:e,index:t,remove:n,watch:r,variableOptions:a,yAxisOptions:o}){const l=r(`reference_lines.${t}.orientation`);return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:u})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:u})=>i(s.Select,{label:"Value",required:!0,data:a,sx:{flex:1},...u})})]}),i(v.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:u})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...u})}),p(s.Group,{grow:!0,children:[p(s.Stack,{children:[i(v.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:u})=>i(s.Select,{label:"Orientation",data:Xf,required:!0,sx:{flex:1},...u})}),l==="vertical"&&i(s.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&i(v.Controller,{name:`reference_lines.${t}.yAxisIndex`,control:e,render:({field:{value:u,onChange:c,...d}})=>i(s.Select,{label:"Y Axis",data:o,disabled:o.length===0,...d,value:(u==null?void 0:u.toString())??"",onChange:f=>{if(!f){c(0);return}c(Number(f))},sx:{flex:1}})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:u})=>i(s.Select,{label:"Line Type",data:Kf,sx:{flexGrow:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:u})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...u})})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:u})=>i($e,{...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`reference_lines.${t}.show_in_legend`,control:e,render:({field:u})=>i(s.Checkbox,{label:"Show in legend",checked:u.value,onChange:c=>u.onChange(c.currentTarget.checked)})}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]})}function Zf({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=r.map((g,y)=>({...g,...l[y]})),c=()=>{a({name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,yAxisIndex:0})},d=m.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=t("y_axes"),h=m.useMemo(()=>f.map(({name:g},y)=>({label:g,value:y.toString()})),[f]);return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[u.map((g,y)=>i(s.Tabs.Tab,{value:y.toString(),children:y+1},g.id)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),u.map((g,y)=>i(s.Tabs.Panel,{value:y.toString(),children:i(Jf,{control:e,index:y,remove:o,watch:t,variableOptions:d,yAxisOptions:h})},g.id))]})}const Hf=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}],eg=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function tg({control:e,regressionItem:t,index:n,remove:r,yAxisOptions:a}){const o=t.transform.config.method;return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,children:[i(v.Controller,{name:`regressions.${n}.name`,control:e,render:({field:l})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`regressions.${n}.group_by_key`,control:e,render:({field:l})=>i(W,{label:"Split into multiple regression lines by this key...",clearable:!0,sx:{flex:1},...l})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`regressions.${n}.y_axis_data_key`,control:e,render:({field:l})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`regressions.${n}.plot.yAxisIndex`,control:e,render:({field:{value:l,onChange:u,...c}})=>i(s.Select,{label:"Y Axis",data:a,disabled:a.length===0,...c,value:(l==null?void 0:l.toString())??"",onChange:d=>{if(!d){u(0);return}u(Number(d))},sx:{flex:1}})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`regressions.${n}.transform.config.method`,control:e,render:({field:l})=>i(s.Select,{label:"Method",data:Hf,sx:{flex:1},...l})}),o==="polynomial"&&i(v.Controller,{name:`regressions.${n}.transform.config.order`,control:e,render:({field:l})=>i(s.NumberInput,{label:"Order",sx:{flex:1},...l})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Line Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`regressions.${n}.plot.lineStyle.type`,control:e,render:({field:l})=>i(s.Select,{label:"Line Type",data:eg,sx:{flexGrow:1},...l})}),i(v.Controller,{name:`regressions.${n}.plot.lineStyle.width`,control:e,render:({field:l})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...l})})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`regressions.${n}.plot.color`,control:e,render:({field:l})=>i($e,{...l})})]}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(n),sx:{top:15,right:5},children:"Delete this Regression Line"})]})}function ng({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"regressions"}),o=t("regressions"),l=n.map((f,h)=>({...f,...o[h]})),u=t("y_axes"),c=m.useMemo(()=>u.map(({name:f},h)=>({label:f,value:h.toString()})),[u]),d=()=>r({transform:{type:"ecStat:regression",config:{method:"linear",order:1,formulaOn:"end"}},group_by_key:"",name:"",y_axis_data_key:"",plot:{type:"line",yAxisIndex:0,color:"#666666",lineStyle:{type:"solid",width:1}}});return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((f,h)=>i(s.Tabs.Tab,{value:h.toString(),children:h+1},f.id)),i(s.Tabs.Tab,{onClick:d,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((f,h)=>i(s.Tabs.Panel,{value:h.toString(),children:i(tg,{regressionItem:f,control:e,index:h,remove:a,yAxisOptions:c})},f.id))]})}const li={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
|
|
122
|
-
`)}},rg=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function ig({control:e,index:t,seriesItem:n}){const r=!!n.barWidth.trim();return p(B,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.stack`,control:e,render:({field:a})=>i(s.TextInput,{label:"Stack",placeholder:"Stack bars by this ID",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barGap`,control:e,render:({field:a})=>i(s.Select,{label:"Bar Gap",data:rg,sx:{flexGrow:1},...a})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.barMinWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Min)",disabled:r,sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barMaxWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Max)",disabled:r,sx:{flexGrow:1},...a})})]})]})}const ag=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return i(s.Box,{children:i(Te,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},sg=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:a}]=Q.useBoolean(),[o,l]=m.useState(e),u=()=>{a();const{type:h,func_content:g}=o,y={type:h,func_content:g};l(y),t(y)},c=()=>{a(),l(e)},d=h=>{l(g=>({...g,func_content:h}))},f=()=>{d(li.dynamic.func_content)};return p(B,{children:[i(s.Box,{sx:{width:"50%"},children:i(s.Button,{variant:"filled",mt:24,onClick:r,sx:{flexGrow:0},children:"Setup"})}),i(s.Modal,{size:800,title:"Setup dynamic size",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&p(s.Stack,{children:[i(s.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),i(ag,{value:o.func_content,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:c,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:u,children:"OK"})]})]})]})})]})},og=({value:e,onChange:t})=>e.type!=="dynamic"?null:i(sg,{value:e,onChange:t}),lg=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=r=>{t({...e,size:r})};return i(B,{children:i(s.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:e.size,onChange:n})})},ug=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],fo=m.forwardRef(({label:e="Size",value:t,onChange:n},r)=>{const a=o=>{n({...li[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:e,data:ug,value:t.type,onChange:a,sx:{flexGrow:1}}),i(lg,{value:t,onChange:n}),i(og,{value:t,onChange:n})]})}),cg=[{label:"off",value:"false"},{label:"start",value:"start"},{label:"middle",value:"middle"},{label:"end",value:"end"}],dg=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function pg({control:e,index:t,seriesItem:n}){const r=n.showSymbol;return p(B,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Line Settings",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`series.${t}.lineStyle.type`,control:e,render:({field:a})=>i(s.Select,{label:"Line Type",data:dg,sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.lineStyle.width`,control:e,render:({field:a})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...a})})]}),p(s.Group,{grow:!0,align:"center",children:[i(v.Controller,{name:`series.${t}.step`,control:e,render:({field:a})=>i(s.Select,{label:"Step",data:cg,sx:{flexGrow:1,maxWidth:"48%"},...a,value:String(a.value),onChange:o=>{const l=o==="false"?!1:o;a.onChange(l)}})}),p(s.Stack,{children:[i(v.Controller,{name:`series.${t}.smooth`,control:e,render:({field:a})=>i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Smooth Line",checked:a.value,onChange:o=>a.onChange(o.currentTarget.checked)})})}),i(v.Controller,{name:`series.${t}.display_name_on_line`,control:e,render:({field:a})=>i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Display Name on Line",checked:a.value??!1,onChange:o=>a.onChange(o.currentTarget.checked)})})})]})]}),p(s.Stack,{children:[i(v.Controller,{name:`series.${t}.showSymbol`,control:e,render:({field:a})=>i(s.Box,{mt:10,mb:-10,sx:{flexGrow:1},children:i(s.Switch,{label:"Show Symbol on Line",checked:a.value,onChange:o=>a.onChange(o.currentTarget.checked)})})}),r&&i(v.Controller,{name:`series.${t}.symbolSize`,control:e,render:({field:a})=>i(fo,{label:"Symbol Size",...a})})]})]})}function hg({control:e,index:t}){return i(v.Controller,{name:`series.${t}.symbolSize`,control:e,render:({field:n})=>i(fo,{label:"Size",...n})})}const fg=[{label:"off",value:""},{label:"top",value:"top"},{label:"left",value:"left"},{label:"right",value:"right"},{label:"bottom",value:"bottom"},{label:"inside",value:"inside"},{label:"insideLeft",value:"insideLeft"},{label:"insideRight",value:"insideRight"},{label:"insideTop",value:"insideTop"},{label:"insideBottom",value:"insideBottom"},{label:"insideTopLeft",value:"insideTopLeft"},{label:"insideBottomLeft",value:"insideBottomLeft"},{label:"insideTopRight",value:"insideTopRight"},{label:"insideBottomRight",value:"insideBottomRight"}];function gg({control:e,index:t,remove:n,seriesItem:r,yAxisOptions:a}){const o=r.type;return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[i(s.Stack,{children:i(v.Controller,{name:`series.${t}.type`,control:e,render:({field:l})=>i(s.SegmentedControl,{data:[{label:"Line",value:"line"},{label:"Bar",value:"bar"},{label:"Scatter",value:"scatter"}],...l})})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.name`,control:e,render:({field:l})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`series.${t}.yAxisIndex`,control:e,render:({field:{value:l,onChange:u,...c}})=>i(s.Select,{label:"Y Axis",data:a,disabled:a.length===0,...c,value:(l==null?void 0:l.toString())??"",onChange:d=>{if(!d){u(0);return}u(Number(d))},sx:{flex:1}})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.y_axis_data_key`,control:e,render:({field:l})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`series.${t}.aggregation_on_value`,control:e,render:({field:l})=>i(Un,{label:"Aggregation on Value",value:l.value??jt,onChange:l.onChange,pt:0})})]}),i(s.Group,{grow:!0,children:i(v.Controller,{name:`series.${t}.group_by_key`,control:e,render:({field:l})=>i(W,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...l})})}),o==="line"&&i(pg,{index:t,control:e,seriesItem:r}),o==="bar"&&i(ig,{index:t,control:e,seriesItem:r}),o==="scatter"&&i(hg,{index:t,control:e}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),i(v.Controller,{name:`series.${t}.label_position`,control:e,render:({field:l})=>i(s.Select,{label:"Label Position",data:fg,...l})}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`series.${t}.color`,control:e,render:({field:l})=>i($e,{...l})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`series.${t}.hide_in_legend`,control:e,render:({field:l})=>i(s.Checkbox,{label:"Hide in legend",checked:l.value,onChange:u=>l.onChange(u.currentTarget.checked)})}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Series"})]})}function mg({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"series"}),o=t("series"),l=n.map((f,h)=>({...f,...o[h]})),u=()=>{const f={type:"bar",name:_e.randomId(),showSymbol:!1,symbolSize:li.static,y_axis_data_key:"value",yAxisIndex:0,label_position:"top",display_name_on_line:!1,stack:"",color:"#000",step:!1,smooth:!1,barMinWidth:"1",barWidth:"10%",barMaxWidth:"10",barGap:"0%",lineStyle:{type:"solid",width:1},hide_in_legend:!1,group_by_key:""};r(f)},c=t("y_axes"),d=m.useMemo(()=>c.map(({name:f},h)=>({label:f,value:h.toString()})),[c]);return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((f,h)=>i(s.Tabs.Tab,{value:h.toString(),children:h+1},f.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((f,h)=>i(s.Tabs.Panel,{value:h.toString(),children:i(gg,{control:e,index:h,remove:a,seriesItem:f,yAxisOptions:d},f.id)},f.id))]})}function yg({control:e,watch:t}){return t("stats"),i(s.Stack,{children:p(s.Stack,{spacing:0,children:[i(v.Controller,{name:"stats.templates.top",control:e,render:({field:n})=>i(un,{label:"Template for stats above the chart",py:"md",sx:{flexGrow:1},...n})}),i(v.Controller,{name:"stats.templates.bottom",control:e,render:({field:n})=>i(un,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const bg=()=>p(s.Group,{sx:{display:"inline-flex"},spacing:6,mr:14,children:[i(s.Text,{children:"X Axis Data Type"}),p(s.HoverCard,{width:340,shadow:"md",position:"top",children:[i(s.HoverCard.Target,{children:i(s.ActionIcon,{size:"xs",sx:{transform:"none !important"},children:i(E.IconInfoCircle,{})})}),i(s.HoverCard.Dropdown,{children:p(s.Text,{size:"sm",children:["Click",i(s.Anchor,{href:"https://echarts.apache.org/en/option.html#xAxis.type",target:"_blank",mx:4,children:"here"}),"to learn more about these options"]})})]})]}),vg=[{label:"Value",value:"value"},{label:"Category",value:"category"},{label:"Time",value:"time"},{label:"Log",value:"log"}];function xg({control:e,watch:t}){return t(["x_axis_data_key","x_axis_name","x_axis"]),p(s.Stack,{children:[i(v.Controller,{name:"x_axis_name",control:e,render:({field:n})=>i(s.TextInput,{label:"X Axis Name",sx:{flex:1},...n})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis_data_key",control:e,render:({field:n})=>i(W,{label:"X Axis Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.type",control:e,render:({field:n})=>i(s.Select,{label:i(bg,{}),required:!0,data:vg,sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>i(Jn,{...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>i(st,{...n})})]})}const wg=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],Cg=[{label:"left",value:"left"},{label:"right",value:"right"}];function Sg({control:e,index:t,remove:n}){return p(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[i(s.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`y_axes.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`y_axes.${t}.nameAlignment`,control:e,render:({field:r})=>i(s.Select,{label:"Name Anchor",required:!0,data:wg,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`y_axes.${t}.position`,control:e,render:({field:r})=>i(s.Select,{label:"Position",required:!0,data:Cg,sx:{flex:1},...r})})}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:`y_axes.${t}.label_formatter`,control:e,render:({field:r})=>i(Ge,{...r})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`y_axes.${t}.min`,control:e,render:({field:r})=>i(s.TextInput,{label:"Min",...r})}),i(v.Controller,{name:`y_axes.${t}.max`,control:e,render:({field:r})=>i(s.TextInput,{label:"Max",...r})})]})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`y_axes.${t}.show`,control:e,render:({field:r})=>i(s.Checkbox,{label:"Visible",checked:r.value,onChange:a=>r.onChange(a.currentTarget.checked)})}),i(s.Button,{mt:20,leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this YAxis"})]})}function _g({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"y_axes"}),o=t("y_axes"),l=n.map((c,d)=>({...c,...o[d]})),u=()=>r({name:"",position:"left",nameAlignment:"left",label_formatter:De,min:"",max:"",show:!0});return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[l.map((c,d)=>i(s.Tabs.Tab,{value:d.toString(),children:d+1},c.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((c,d)=>i(s.Tabs.Panel,{value:d.toString(),children:i(Sg,{control:e,index:d,remove:a})},c.id))]})}function kg({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),{variables:r}=e,a=m.useMemo(()=>x.defaultsDeep({},t,ii),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});m.useEffect(()=>{d(a)},[a]);const f=c(),h=m.useMemo(()=>!x.isEqual(f,a),[f,a]);return u(["dataZoom"]),i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(I.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"Series",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axes",children:"Y Axes"}),i(s.Tabs.Tab,{value:"Series",children:"Series"}),i(s.Tabs.Tab,{value:"Regression Lines",children:"Regression Lines"}),i(s.Tabs.Tab,{value:"Stats",children:"Stats"}),i(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"}),i(s.Tabs.Tab,{value:"Reference Areas",children:"Reference Areas"}),i(s.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(xg,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axes",children:i(_g,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Series",children:i(mg,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Regression Lines",children:i(ng,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Stats",children:i(yg,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(Zf,{variables:r,control:o,watch:u})}),i(s.Tabs.Panel,{value:"Reference Areas",children:i(Uf,{variables:r,control:o,watch:u})}),i(s.Tabs.Panel,{value:"Zooming",children:i(v.Controller,{name:"dataZoom",control:o,render:({field:g})=>i(oi,{...g})})})]})]})})}function Tg(e){const t=x.cloneDeep(x.omit(e,"variables"));return t.stats=x.omit(t.stats,"variables"),t}function Dg(e){const{rotate:t,formatter:n=Ue}=e.x_axis.axisLabel;return{...e,x_axis:{...e.x_axis,axisLabel:{rotate:t,formatter:n}}}}function Ig(e){const{dataZoom:t=Rt,...n}=e;return{...n,dataZoom:t}}function Mg(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return x.defaultsDeep(t,e)}function Ag(e){const t=e.reference_lines.map(n=>{const{lineStyle:r={type:"dashed",width:1,color:ht.random().css()},show_in_legend:a=!1}=n;return{...n,lineStyle:r,show_in_legend:a}});return{...e,reference_lines:t}}function zg(e){const t=e.reference_lines.map(n=>{const{yAxisIndex:r=0}=n;return{...n,yAxisIndex:r}});return{...e,reference_lines:t}}function Eg(e){const t=e.series.map(n=>{const{aggregation_on_group:r=jt}=n;return{...n,aggregation_on_group:r}});return{...e,series:t}}function $g(e){const t=e.series.map(n=>{const{aggregation_on_value:r=jt}=n;return{...n,aggregation_on_value:r}});return{...e,series:t}}function Lg(e){delete e.config;const{x_axis:t,tooltip:n}=e.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:t,in_tooltip:n}}}};return x.defaultsDeep(r,e)}function Pg(e){const{series:t,...n}=e;return{...n,series:t.map(r=>{const{barMinWidth:a,barWidth:o,barMaxWidth:l}=r;return a?{...r,barMinWidth:a,barWidth:"",barMaxWidth:l??o}:{...r,barMinWidth:"",barWidth:o,barMaxWidth:""}})}}function Og(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(r=>{const{min:a="",max:o=""}=r;return{...r,min:a,max:o}})}}function Bg(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(r=>{const{nameAlignment:a="left"}=r;return{...r,nameAlignment:a}})}}function Vg(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(r=>{const{show:a=!0}=r;return{...r,show:a}})}}function Ng(e){const{regressions:t,...n}=e;return{...n,regressions:t.map(r=>{const{group_by_key:a=""}=r;return{...r,group_by_key:a}})}}function qg(e){const{series:t,y_axes:n,...r}=e;return{...r,series:t.map(a=>{const{hide_in_legend:o=!1,aggregation_on_value:l=jt}=a;return{...a,hide_in_legend:o,aggregation_on_value:l}}),y_axes:n.map(a=>{const{min:o="",max:l="",show:u=!0}=a;return{...a,min:o,max:l,show:u}})}}function Fg(e){const{type:t="category",...n}=e.x_axis;return{...e,x_axis:{...n,type:t}}}function Gg(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis_data_key:a,series:o,regressions:l,...u}=e;return{...u,x_axis_data_key:r(a),series:o.map(c=>({...c,y_axis_data_key:r(c.y_axis_data_key),group_by_key:r(c.group_by_key)})),regressions:l.map(c=>({...c,y_axis_data_key:r(c.y_axis_data_key),group_by_key:r(c.group_by_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class Wg extends ge{constructor(){super(...arguments);q(this,"VERSION",18)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,{panelModel:r})=>{const{config:a}=n;return(a.variables||[]).forEach(u=>{r.variables.find(c=>c.name===u.name)||r.addVariable(u)}),(x.get(a,"stats.variables")||[]).forEach(u=>{r.variables.find(c=>c.name===u.name)||r.addVariable(u)}),{...n,version:2,config:Tg(a)}}),this.version(3,n=>({...n,version:3,config:Dg(n.config)})),this.version(4,n=>({...n,version:4,config:Ig(n.config)})),this.version(5,n=>({...n,version:5,config:Mg(n.config)})),this.version(6,n=>({...n,version:6,config:Ag(n.config)})),this.version(7,n=>({...n,version:7,config:zg(n.config)})),this.version(8,n=>({...n,version:8,config:Eg(n.config)})),this.version(9,n=>({...n,version:9,config:$g(n.config)})),this.version(10,n=>({...n,version:10,config:Lg(n.config)})),this.version(11,n=>({...n,version:11,config:Pg(n.config)})),this.version(12,n=>({...n,version:12,config:Og(n.config)})),this.version(13,n=>({...n,version:13,config:Bg(n.config)})),this.version(14,n=>({...n,version:14,config:Vg(n.config)})),this.version(15,n=>({...n,version:15,config:Ng(n.config)})),this.version(16,n=>({...n,version:16,config:qg(n.config)})),this.version(17,n=>({...n,version:17,config:Fg(n.config)})),this.version(18,(n,r)=>({...n,version:18,config:Gg(n.config,r)}))}}const jg={displayName:"Cartesian Chart",displayGroup:"ECharts-based charts",migrator:new Wg,name:"cartesian",viewRender:jf,configRender:kg,createConfig(){return{version:18,config:x.cloneDeep(ii)}},triggers:[ri]};function Rg(e){if(e.enable_value)return e.value}function Yg(e){if(e.enable_value)return e.value}function Qg(e){const t=e.axisLabel.overflow.on_axis.width,n=e.axisLabel.position,r={top:5,left:5,right:5,bottom:5};return e.orient==="vertical"&&x.get(r,n)&&n===e.funnelAlign&&x.set(r,n,t),r}function Ug(e,t){return e.series.map(n=>{const{level_name_data_key:r,level_value_data_key:a,axisLabel:o,min:l,max:u,funnelAlign:c,orient:d,...f}=n;if(!r||!a)return{};const h=P(r),g=P(a),y=t[h.queryID].map(w=>({name:w[h.columnKey],value:w[g.columnKey]})),C=rt(o.overflow.on_axis);return{type:"funnel",...Qg(n),min:Rg(l),max:Yg(u),minSize:l.size,maxSize:u.size,...f,label:{show:!0,position:o.position,...C},orient:d,funnelAlign:d==="horizontal"?"center":c,data:y}})}function Kg({conf:e,params:t,max:n}){const{name:r,value:a}=t.data,o=Z(a/n).format({output:"percent",mantissa:2,trimMantissa:!0});return[{label:`${t.marker} ${r}`,value:`${a} (${o})`,style:{label:"",value:""}}]}function Xg(e,t){var o;const n=P(e.series[0].level_name_data_key),r=P(e.series[0].level_value_data_key),a=(o=x.maxBy(t[n.queryID],r.columnKey))==null?void 0:o[r.columnKey];return l=>{const c=Kg({conf:e,params:l,max:a}).map(f=>`
|
|
121
|
+
`}}}function Af(t){return t.y_axes.reduce((n,{label_formatter:i},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),!i)return u;try{return W(u).format(i)}catch(c){return console.error(c),u}},n),{default:({value:n})=>n})}function ms(t,e){const n={};return e.map(i=>{const a=ot(i,t);n[i.name]=Fe(i,a)}),n}function zf(t,e){const{overflow:n,...i}=t.x_axis.axisLabel,a=Ue(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:{...i,...a,formatter:Dt(i.formatter)}}]}function Ef(t){var e;try{return Array.isArray(t[0])&&((e=t[0])==null?void 0:e.length)>=2?t.map(i=>Number(i[1])):[...t]}catch(n){return console.error(n),[...t]}}function Pf(t){if(t.length===0)return{};const e={},n={};return t.forEach(i=>{const a=Ef(i.data);if(!n[i.yAxisIndex]){n[i.yAxisIndex]=a;return}n[i.yAxisIndex]=n[i.yAxisIndex].concat(a)}),Object.entries(n).forEach(([i,a])=>{const o=x.minBy(a)??0,l=x.maxBy(a)??0;o==0&&l==0&&(e[i]=1)}),e}function Lf(t,e,n){const i=Pf(n);return t.y_axes.map(({nameAlignment:a,min:o,max:l,show:u,...c},p)=>{let h=c.position;return h||(h=p>0?"right":"left"),{...c,minInterval:i[p]??0,show:u,min:o||void 0,max:l||void 0,position:h,axisLabel:{show:u,formatter:e[p]??e.default},axisLine:{show:u},nameTextStyle:{fontWeight:"bold",align:a},nameLocation:"end",nameGap:u?15:0,splitLine:{show:!1}}})}const Bf={xAxis:[{type:"category",nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0}}]};function Of(t,e,n){const i=ms(e,n),a=Af(t),o=x.uniq(at(e,t.x_axis_data_key)),l=Df(t,o,e,a,n,i),u=yf(t,e),c={xAxis:zf(t,o),yAxis:Lf(t,a,l),series:[...l,...u],tooltip:Mf(t,l,a),grid:pf(t),legend:gf(l),dataZoom:Fr(t.dataZoom)};return x.defaultsDeep({},c,Bf)}function ys(t){const e=t.getModel(),n=e.getSeries().map(i=>{if(!i.option.custom)return i.option;const a=e.getColorFromPalette(i.option.custom.targetSeries,null);return i.option.color=a,i.option});t.setOption({...t.getOption(),series:n})}Y.use([B.DataZoomComponent,re.BarChart,re.LineChart,re.ScatterChart,B.GridComponent,B.LegendComponent,B.TooltipComponent,_e.CanvasRenderer,B.MarkLineComponent,B.MarkAreaComponent]);function bs(t){return t.trim().length>0}function $f({conf:t,data:e,width:n,height:i,interactionManager:a,variables:o}){const l=yt(e,t.x_axis_data_key),u=Ne(a.triggerManager,qr.id),c=m.useCallback(b=>{const w=x.get(l,b.name,{error:"rowData is not found"});u.forEach(_=>{a.runInteraction(_.id,{...b,rowData:w})})},[l,u,a]),p=m.useMemo(()=>Of(t,e,o),[t,e]),h=m.useRef(),f=m.useMemo(()=>({click:c}),[c]),g=b=>{h.current=b,ys(b)};return m.useEffect(()=>{h.current&&ys(h.current)},[p]),!n||!i?null:r(Se,{echarts:Y,option:p,style:{width:n,height:i},onEvents:f,onChartReady:g,notMerge:!0,theme:"merico-light"})}function Vf({context:t,instance:e}){const n=qe({vizManager:t.vizManager,instance:e}),{value:i}=V(t.instanceData,"config"),{variables:a}=t,o=m.useMemo(()=>x.defaults({},i,Gr),[i]),l=t.data,{width:u,height:c}=t.viewport,{ref:p,height:h}=ye.useElementSize(),{ref:f,height:g}=ye.useElementSize(),b=m.useMemo(()=>{const{stats:{templates:D}}=o;return{top:Ht(D.top,a,l),bottom:Ht(D.bottom,a,l)}},[o,l]),w=Math.max(0,Qe(c)-h-g),_=Re(u);return d(Me,{width:u,height:c,children:[r(s.Text,{ref:p,align:"left",size:"xs",pl:"sm",sx:{display:bs(o.stats.templates.top)?"block":"none"},children:Object.values(b.top).map((D,L)=>r(m.Fragment,{children:D},L))}),r($f,{variables:a,width:_,height:w,data:l,conf:o,interactionManager:n}),r(s.Text,{ref:f,align:"left",size:"xs",pl:"sm",sx:{display:bs(o.stats.templates.bottom)?"block":"none"},children:Object.values(b.bottom).map((D,L)=>r(m.Fragment,{children:D},L))})]})}const Wr=m.forwardRef(({value:t,onChange:e},n)=>{const i=a=>o=>{e({...t,[a]:o})};return d(s.Stack,{children:[r(s.Divider,{variant:"dashed",label:"Scroll to Zoom",labelPosition:"center"}),d(s.Group,{children:[r(s.Box,{sx:{flexGrow:1},children:r(s.Switch,{label:"Enable on X Axis",checked:t.x_axis_scroll,onChange:a=>i("x_axis_scroll")(a.currentTarget.checked)})}),r(s.Box,{sx:{flexGrow:1},children:r(s.Switch,{label:"Enable on Y Axis",checked:t.y_axis_scroll,onChange:a=>i("y_axis_scroll")(a.currentTarget.checked)})})]}),r(s.Divider,{variant:"dashed",label:"Slider for Zooming",labelPosition:"center"}),d(s.Group,{children:[r(s.Box,{sx:{flexGrow:1},children:r(s.Switch,{label:"Slider for X Axis",checked:t.x_axis_slider,onChange:a=>i("x_axis_slider")(a.currentTarget.checked)})}),r(s.Tooltip,{label:"Not available for now, will overlap y-axis's label",children:r(s.Box,{sx:{flexGrow:1},children:r(s.Switch,{label:"Slider for Y Axis",disabled:!t.y_axis_slider,checked:t.y_axis_slider,onChange:a=>i("y_axis_slider")(a.currentTarget.checked)})})})]})]})}),Nf=[{label:"Rectangle",value:"rectangle"}],qf=[{label:"Horizontal",value:"horizontal"}];function Gf({control:t,index:e,remove:n,variableOptions:i}){return d(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`reference_areas.${e}.name`,control:t,render:({field:a})=>r(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...a})}),r(v.Controller,{name:`reference_areas.${e}.color`,control:t,render:({field:a})=>r(s.TextInput,{label:"Color",required:!0,sx:{flex:1},...a})})]}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`reference_areas.${e}.type`,control:t,render:({field:a})=>r(s.Select,{label:"Type",required:!0,data:Nf,sx:{flex:1},...a})}),r(v.Controller,{name:`reference_areas.${e}.direction`,control:t,render:({field:a})=>r(s.Select,{label:"Direction",required:!0,data:qf,sx:{flex:1},...a})})]}),r(s.Divider,{variant:"dashed",label:"Data",labelPosition:"center"}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`reference_areas.${e}.y_keys.upper`,control:t,render:({field:a})=>r(s.Select,{label:"Upper Boundary",required:!0,data:i,sx:{flex:1},...a})}),r(v.Controller,{name:`reference_areas.${e}.y_keys.lower`,control:t,render:({field:a})=>r(s.Select,{label:"Lower Boundary",required:!0,data:i,sx:{flex:1},...a})})]}),r(s.Button,{leftIcon:r(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Reference Area"})]})}function Ff({control:t,watch:e,variables:n}){const{fields:i,append:a,remove:o}=v.useFieldArray({control:t,name:"reference_areas"}),l=e("reference_areas"),u=i.map((h,f)=>({...h,...l[f]})),c=()=>a({name:"",color:"rgba(0,0,0,0.1)",type:"rectangle",direction:"horizontal",y_keys:{upper:"",lower:""}}),p=m.useMemo(()=>n.map(h=>({label:h.name,value:h.name})),[n]);return d(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"6px 0px 0px"}},children:[d(s.Tabs.List,{children:[u.map((h,f)=>r(s.Tabs.Tab,{value:f.toString(),children:f+1},h.id)),r(s.Tabs.Tab,{onClick:c,value:"add",children:r(T.Plus,{size:18,color:"#228be6"})})]}),u.map((h,f)=>r(s.Tabs.Panel,{value:f.toString(),children:r(Gf,{control:t,index:f,remove:o,variableOptions:p})},h.id))]})}const jf=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Wf=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Rf({control:t,index:e,remove:n,watch:i,variableOptions:a,yAxisOptions:o}){const l=i(`reference_lines.${e}.orientation`);return d(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`reference_lines.${e}.name`,control:t,render:({field:u})=>r(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),r(v.Controller,{name:`reference_lines.${e}.variable_key`,control:t,render:({field:u})=>r(s.Select,{label:"Value",required:!0,data:a,sx:{flex:1},...u})})]}),r(v.Controller,{name:`reference_lines.${e}.template`,control:t,render:({field:u})=>r(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...u})}),d(s.Group,{grow:!0,children:[d(s.Stack,{children:[r(v.Controller,{name:`reference_lines.${e}.orientation`,control:t,render:({field:u})=>r(s.Select,{label:"Orientation",data:Wf,required:!0,sx:{flex:1},...u})}),l==="vertical"&&r(s.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&r(v.Controller,{name:`reference_lines.${e}.yAxisIndex`,control:t,render:({field:{value:u,onChange:c,...p}})=>r(s.Select,{label:"Y Axis",data:o,disabled:o.length===0,...p,value:(u==null?void 0:u.toString())??"",onChange:h=>{if(!h){c(0);return}c(Number(h))},sx:{flex:1}})})]}),r(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),d(s.Group,{grow:!0,children:[r(v.Controller,{name:`reference_lines.${e}.lineStyle.type`,control:t,render:({field:u})=>r(s.Select,{label:"Line Type",data:jf,sx:{flexGrow:1},...u})}),r(v.Controller,{name:`reference_lines.${e}.lineStyle.width`,control:t,render:({field:u})=>r(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...u})})]}),d(s.Stack,{spacing:4,children:[r(s.Text,{size:"sm",children:"Color"}),r(v.Controller,{name:`reference_lines.${e}.lineStyle.color`,control:t,render:({field:u})=>r(Te,{...u})})]}),r(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),r(v.Controller,{name:`reference_lines.${e}.show_in_legend`,control:t,render:({field:u})=>r(s.Checkbox,{label:"Show in legend",checked:u.value,onChange:c=>u.onChange(c.currentTarget.checked)})}),r(s.Button,{leftIcon:r(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Reference Line"})]})}function Qf({control:t,watch:e,variables:n}){const{fields:i,append:a,remove:o}=v.useFieldArray({control:t,name:"reference_lines"}),l=e("reference_lines"),u=i.map((g,b)=>({...g,...l[b]})),c=()=>{a({name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,yAxisIndex:0})},p=m.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),h=e("y_axes"),f=m.useMemo(()=>h.map(({name:g},b)=>({label:g,value:b.toString()})),[h]);return d(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[d(s.Tabs.List,{children:[u.map((g,b)=>r(s.Tabs.Tab,{value:b.toString(),children:b+1},g.id)),r(s.Tabs.Tab,{onClick:c,value:"add",children:r(T.Plus,{size:18,color:"#228be6"})})]}),u.map((g,b)=>r(s.Tabs.Panel,{value:b.toString(),children:r(Rf,{control:t,index:b,remove:o,watch:e,variableOptions:p,yAxisOptions:f})},g.id))]})}const Uf=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}],Kf=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function Yf({control:t,regressionItem:e,index:n,remove:i,yAxisOptions:a}){const o=e.transform.config.method;return d(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[d(s.Group,{grow:!0,children:[r(v.Controller,{name:`regressions.${n}.name`,control:t,render:({field:l})=>r(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...l})}),r(v.Controller,{name:`regressions.${n}.group_by_key`,control:t,render:({field:l})=>r(O,{label:"Split into multiple regression lines by this key...",clearable:!0,sx:{flex:1},...l})})]}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`regressions.${n}.y_axis_data_key`,control:t,render:({field:l})=>r(O,{label:"Value Field",required:!0,sx:{flex:1},...l})}),r(v.Controller,{name:`regressions.${n}.plot.yAxisIndex`,control:t,render:({field:{value:l,onChange:u,...c}})=>r(s.Select,{label:"Y Axis",data:a,disabled:a.length===0,...c,value:(l==null?void 0:l.toString())??"",onChange:p=>{if(!p){u(0);return}u(Number(p))},sx:{flex:1}})})]}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`regressions.${n}.transform.config.method`,control:t,render:({field:l})=>r(s.Select,{label:"Method",data:Uf,sx:{flex:1},...l})}),o==="polynomial"&&r(v.Controller,{name:`regressions.${n}.transform.config.order`,control:t,render:({field:l})=>r(s.NumberInput,{label:"Order",sx:{flex:1},...l})})]}),r(s.Divider,{mb:-15,variant:"dashed",label:"Line Style",labelPosition:"center"}),d(s.Group,{grow:!0,children:[r(v.Controller,{name:`regressions.${n}.plot.lineStyle.type`,control:t,render:({field:l})=>r(s.Select,{label:"Line Type",data:Kf,sx:{flexGrow:1},...l})}),r(v.Controller,{name:`regressions.${n}.plot.lineStyle.width`,control:t,render:({field:l})=>r(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...l})})]}),d(s.Stack,{spacing:4,children:[r(s.Text,{size:"sm",children:"Color"}),r(v.Controller,{name:`regressions.${n}.plot.color`,control:t,render:({field:l})=>r(Te,{...l})})]}),r(s.Button,{leftIcon:r(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>i(n),sx:{top:15,right:5},children:"Delete this Regression Line"})]})}function Xf({control:t,watch:e}){const{fields:n,append:i,remove:a}=v.useFieldArray({control:t,name:"regressions"}),o=e("regressions"),l=n.map((h,f)=>({...h,...o[f]})),u=e("y_axes"),c=m.useMemo(()=>u.map(({name:h},f)=>({label:h,value:f.toString()})),[u]),p=()=>i({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 d(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[d(s.Tabs.List,{children:[l.map((h,f)=>r(s.Tabs.Tab,{value:f.toString(),children:f+1},h.id)),r(s.Tabs.Tab,{onClick:p,value:"add",children:r(T.Plus,{size:18,color:"#228be6"})})]}),l.map((h,f)=>r(s.Tabs.Panel,{value:f.toString(),children:r(Yf,{regressionItem:h,control:t,index:f,remove:a,yAxisOptions:c})},h.id))]})}const Rr={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
|
|
122
|
+
`)}},Jf=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function Zf({control:t,index:e,seriesItem:n}){const i=!!n.barWidth.trim();return d(z,{children:[d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`series.${e}.stack`,control:t,render:({field:a})=>r(s.TextInput,{label:"Stack",placeholder:"Stack bars by this ID",sx:{flexGrow:1},...a})}),r(v.Controller,{name:`series.${e}.barGap`,control:t,render:({field:a})=>r(s.Select,{label:"Bar Gap",data:Jf,sx:{flexGrow:1},...a})})]}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`series.${e}.barMinWidth`,control:t,render:({field:a})=>r(s.TextInput,{label:"Bar Width(Min)",disabled:i,sx:{flexGrow:1},...a})}),r(v.Controller,{name:`series.${e}.barWidth`,control:t,render:({field:a})=>r(s.TextInput,{label:"Bar Width",sx:{flexGrow:1},...a})}),r(v.Controller,{name:`series.${e}.barMaxWidth`,control:t,render:({field:a})=>r(s.TextInput,{label:"Bar Width(Max)",disabled:i,sx:{flexGrow:1},...a})})]})]})}const Hf=({value:t,onChange:e})=>{const n=i=>{i&&e(i)};return r(s.Box,{children:r(ve,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},eg=({value:t,onChange:e})=>{const[n,{setTrue:i,setFalse:a}]=q.useBoolean(),[o,l]=m.useState(t),u=()=>{a();const{type:f,func_content:g}=o,b={type:f,func_content:g};l(b),e(b)},c=()=>{a(),l(t)},p=f=>{l(g=>({...g,func_content:f}))},h=()=>{p(Rr.dynamic.func_content)};return d(z,{children:[r(s.Box,{sx:{width:"50%"},children:r(s.Button,{variant:"filled",mt:24,onClick:i,sx:{flexGrow:0},children:"Setup"})}),r(s.Modal,{size:800,title:"Setup dynamic size",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&d(s.Stack,{children:[r(s.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),r(Hf,{value:o.func_content,onChange:p}),d(s.Group,{position:"apart",children:[r(s.Button,{onClick:h,color:"red",leftIcon:r(T.Recycle,{size:20}),children:"Reset"}),d(s.Group,{position:"right",children:[r(s.Button,{onClick:c,variant:"subtle",children:"Cancel"}),r(s.Button,{onClick:u,children:"OK"})]})]})]})})]})},tg=({value:t,onChange:e})=>t.type!=="dynamic"?null:r(eg,{value:t,onChange:e}),ng=({value:t,onChange:e})=>{if(t.type!=="static")return null;const n=i=>{e({...t,size:i})};return r(z,{children:r(s.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:t.size,onChange:n})})},rg=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],vs=m.forwardRef(({label:t="Size",value:e,onChange:n},i)=>{const a=o=>{n({...Rr[o]})};return d(s.SimpleGrid,{cols:2,children:[r(s.Select,{ref:i,label:t,data:rg,value:e.type,onChange:a,sx:{flexGrow:1}}),r(ng,{value:e,onChange:n}),r(tg,{value:e,onChange:n})]})}),ig=[{label:"off",value:"false"},{label:"start",value:"start"},{label:"middle",value:"middle"},{label:"end",value:"end"}],ag=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function sg({control:t,index:e,seriesItem:n}){const i=n.showSymbol;return d(z,{children:[r(s.Divider,{mb:-15,variant:"dashed",label:"Line Settings",labelPosition:"center"}),d(s.Group,{grow:!0,children:[r(v.Controller,{name:`series.${e}.lineStyle.type`,control:t,render:({field:a})=>r(s.Select,{label:"Line Type",data:ag,sx:{flexGrow:1},...a})}),r(v.Controller,{name:`series.${e}.lineStyle.width`,control:t,render:({field:a})=>r(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...a})})]}),d(s.Group,{grow:!0,align:"center",children:[r(v.Controller,{name:`series.${e}.step`,control:t,render:({field:a})=>r(s.Select,{label:"Step",data:ig,sx:{flexGrow:1,maxWidth:"48%"},...a,value:String(a.value),onChange:o=>{const l=o==="false"?!1:o;a.onChange(l)}})}),d(s.Stack,{children:[r(v.Controller,{name:`series.${e}.smooth`,control:t,render:({field:a})=>r(s.Box,{sx:{flexGrow:1},children:r(s.Switch,{label:"Smooth Line",checked:a.value,onChange:o=>a.onChange(o.currentTarget.checked)})})}),r(v.Controller,{name:`series.${e}.display_name_on_line`,control:t,render:({field:a})=>r(s.Box,{sx:{flexGrow:1},children:r(s.Switch,{label:"Display Name on Line",checked:a.value??!1,onChange:o=>a.onChange(o.currentTarget.checked)})})})]})]}),d(s.Stack,{children:[r(v.Controller,{name:`series.${e}.showSymbol`,control:t,render:({field:a})=>r(s.Box,{mt:10,mb:-10,sx:{flexGrow:1},children:r(s.Switch,{label:"Show Symbol on Line",checked:a.value,onChange:o=>a.onChange(o.currentTarget.checked)})})}),i&&r(v.Controller,{name:`series.${e}.symbolSize`,control:t,render:({field:a})=>r(vs,{label:"Symbol Size",...a})})]})]})}function og({control:t,index:e}){return r(v.Controller,{name:`series.${e}.symbolSize`,control:t,render:({field:n})=>r(vs,{label:"Size",...n})})}const lg=[{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 ug({control:t,index:e,remove:n,seriesItem:i,yAxisOptions:a}){const o=i.type;return d(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[r(s.Stack,{children:r(v.Controller,{name:`series.${e}.type`,control:t,render:({field:l})=>r(s.SegmentedControl,{data:[{label:"Line",value:"line"},{label:"Bar",value:"bar"},{label:"Scatter",value:"scatter"}],...l})})}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`series.${e}.name`,control:t,render:({field:l})=>r(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...l})}),r(v.Controller,{name:`series.${e}.yAxisIndex`,control:t,render:({field:{value:l,onChange:u,...c}})=>r(s.Select,{label:"Y Axis",data:a,disabled:a.length===0,...c,value:(l==null?void 0:l.toString())??"",onChange:p=>{if(!p){u(0);return}u(Number(p))},sx:{flex:1}})})]}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`series.${e}.y_axis_data_key`,control:t,render:({field:l})=>r(O,{label:"Value Field",required:!0,sx:{flex:1},...l})}),r(v.Controller,{name:`series.${e}.aggregation_on_value`,control:t,render:({field:l})=>r(Mn,{label:"Aggregation on Value",value:l.value??At,onChange:l.onChange,pt:0})})]}),r(s.Group,{grow:!0,children:r(v.Controller,{name:`series.${e}.group_by_key`,control:t,render:({field:l})=>r(O,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...l})})}),o==="line"&&r(sg,{index:e,control:t,seriesItem:i}),o==="bar"&&r(Zf,{index:e,control:t,seriesItem:i}),o==="scatter"&&r(og,{index:e,control:t}),r(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),r(v.Controller,{name:`series.${e}.label_position`,control:t,render:({field:l})=>r(s.Select,{label:"Label Position",data:lg,...l})}),d(s.Stack,{spacing:4,children:[r(s.Text,{size:"sm",children:"Color"}),r(v.Controller,{name:`series.${e}.color`,control:t,render:({field:l})=>r(Te,{...l})})]}),r(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),r(v.Controller,{name:`series.${e}.hide_in_legend`,control:t,render:({field:l})=>r(s.Checkbox,{label:"Hide in legend",checked:l.value,onChange:u=>l.onChange(u.currentTarget.checked)})}),r(s.Divider,{mb:-10,mt:10,variant:"dashed"}),r(s.Button,{leftIcon:r(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Series"})]})}function cg({control:t,watch:e}){const{fields:n,append:i,remove:a}=v.useFieldArray({control:t,name:"series"}),o=e("series"),l=n.map((h,f)=>({...h,...o[f]})),u=()=>{const h={type:"bar",name:ye.randomId(),showSymbol:!1,symbolSize:Rr.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:""};i(h)},c=e("y_axes"),p=m.useMemo(()=>c.map(({name:h},f)=>({label:h,value:f.toString()})),[c]);return d(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[d(s.Tabs.List,{children:[l.map((h,f)=>r(s.Tabs.Tab,{value:f.toString(),children:f+1},h.id)),r(s.Tabs.Tab,{onClick:u,value:"add",children:r(T.Plus,{size:18,color:"#228be6"})})]}),l.map((h,f)=>r(s.Tabs.Panel,{value:f.toString(),children:r(ug,{control:t,index:f,remove:a,seriesItem:h,yAxisOptions:p},h.id)},h.id))]})}function dg({control:t,watch:e}){return e("stats"),r(s.Stack,{children:d(s.Stack,{spacing:0,children:[r(v.Controller,{name:"stats.templates.top",control:t,render:({field:n})=>r(Rt,{label:"Template for stats above the chart",py:"md",sx:{flexGrow:1},...n})}),r(v.Controller,{name:"stats.templates.bottom",control:t,render:({field:n})=>r(Rt,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const pg=()=>d(s.Group,{sx:{display:"inline-flex"},spacing:6,mr:14,children:[r(s.Text,{children:"X Axis Data Type"}),d(s.HoverCard,{width:340,shadow:"md",position:"top",children:[r(s.HoverCard.Target,{children:r(s.ActionIcon,{size:"xs",sx:{transform:"none !important"},children:r(M.IconInfoCircle,{})})}),r(s.HoverCard.Dropdown,{children:d(s.Text,{size:"sm",children:["Click",r(s.Anchor,{href:"https://echarts.apache.org/en/option.html#xAxis.type",target:"_blank",mx:4,children:"here"}),"to learn more about these options"]})})]})]}),hg=[{label:"Value",value:"value"},{label:"Category",value:"category"},{label:"Time",value:"time"},{label:"Log",value:"log"}];function fg({control:t,watch:e}){return e(["x_axis_data_key","x_axis_name","x_axis"]),d(s.Stack,{children:[r(v.Controller,{name:"x_axis_name",control:t,render:({field:n})=>r(s.TextInput,{label:"X Axis Name",sx:{flex:1},...n})}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"x_axis_data_key",control:t,render:({field:n})=>r(O,{label:"X Axis Data Field",required:!0,sx:{flex:1},...n})}),r(v.Controller,{name:"x_axis.type",control:t,render:({field:n})=>r(s.Select,{label:r(pg,{}),required:!0,data:hg,sx:{flex:1},...n})})]}),r(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>r(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:r(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),r(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>r(En,{...n})})]}),r(v.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>r(Je,{...n})})]})}const gg=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],mg=[{label:"left",value:"left"},{label:"right",value:"right"}];function yg({control:t,index:e,remove:n}){return d(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[r(s.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`y_axes.${e}.name`,control:t,render:({field:i})=>r(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})}),r(v.Controller,{name:`y_axes.${e}.nameAlignment`,control:t,render:({field:i})=>r(s.Select,{label:"Name Anchor",required:!0,data:gg,sx:{flex:1},...i})})]}),r(s.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),r(s.Group,{grow:!0,noWrap:!0,children:r(v.Controller,{name:`y_axes.${e}.position`,control:t,render:({field:i})=>r(s.Select,{label:"Position",required:!0,data:mg,sx:{flex:1},...i})})}),d(s.Stack,{children:[r(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),r(v.Controller,{name:`y_axes.${e}.label_formatter`,control:t,render:({field:i})=>r(Pe,{...i})})]}),d(s.Stack,{children:[r(s.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),d(s.Group,{grow:!0,children:[r(v.Controller,{name:`y_axes.${e}.min`,control:t,render:({field:i})=>r(s.TextInput,{label:"Min",...i})}),r(v.Controller,{name:`y_axes.${e}.max`,control:t,render:({field:i})=>r(s.TextInput,{label:"Max",...i})})]})]}),r(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),r(v.Controller,{name:`y_axes.${e}.show`,control:t,render:({field:i})=>r(s.Checkbox,{label:"Visible",checked:i.value,onChange:a=>i.onChange(a.currentTarget.checked)})}),r(s.Button,{mt:20,leftIcon:r(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),disabled:e===0,children:"Delete this YAxis"})]})}function bg({control:t,watch:e}){const{fields:n,append:i,remove:a}=v.useFieldArray({control:t,name:"y_axes"}),o=e("y_axes"),l=n.map((c,p)=>({...c,...o[p]})),u=()=>i({name:"",position:"left",nameAlignment:"left",label_formatter:xe,min:"",max:"",show:!0});return d(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[d(s.Tabs.List,{children:[l.map((c,p)=>r(s.Tabs.Tab,{value:p.toString(),children:p+1},c.id)),r(s.Tabs.Tab,{onClick:u,value:"add",children:r(T.Plus,{size:18,color:"#228be6"})})]}),l.map((c,p)=>r(s.Tabs.Panel,{value:p.toString(),children:r(yg,{control:t,index:p,remove:a})},c.id))]})}function vg({context:t}){const{value:e,set:n}=V(t.instanceData,"config"),{variables:i}=t,a=m.useMemo(()=>x.defaultsDeep({},e,Gr),[e]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:p}=v.useForm({defaultValues:a});m.useEffect(()=>{p(a)},[a]);const h=c(),f=m.useMemo(()=>!x.isEqual(h,a),[h,a]);return u(["dataZoom"]),r(s.Stack,{spacing:"xs",children:d("form",{onSubmit:l(n),children:[d(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(s.Text,{children:"Chart Config"}),r(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:r(T.DeviceFloppy,{size:20})})]}),d(s.Tabs,{defaultValue:"Series",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[d(s.Tabs.List,{children:[r(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),r(s.Tabs.Tab,{value:"Y Axes",children:"Y Axes"}),r(s.Tabs.Tab,{value:"Series",children:"Series"}),r(s.Tabs.Tab,{value:"Regression Lines",children:"Regression Lines"}),r(s.Tabs.Tab,{value:"Stats",children:"Stats"}),r(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"}),r(s.Tabs.Tab,{value:"Reference Areas",children:"Reference Areas"}),r(s.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),r(s.Tabs.Panel,{value:"X Axis",children:r(fg,{control:o,watch:u})}),r(s.Tabs.Panel,{value:"Y Axes",children:r(bg,{control:o,watch:u})}),r(s.Tabs.Panel,{value:"Series",children:r(cg,{control:o,watch:u})}),r(s.Tabs.Panel,{value:"Regression Lines",children:r(Xf,{control:o,watch:u})}),r(s.Tabs.Panel,{value:"Stats",children:r(dg,{control:o,watch:u})}),r(s.Tabs.Panel,{value:"Reference Lines",children:r(Qf,{variables:i,control:o,watch:u})}),r(s.Tabs.Panel,{value:"Reference Areas",children:r(Ff,{variables:i,control:o,watch:u})}),r(s.Tabs.Panel,{value:"Zooming",children:r(v.Controller,{name:"dataZoom",control:o,render:({field:g})=>r(Wr,{...g})})})]})]})})}function xg(t){const e=x.cloneDeep(x.omit(t,"variables"));return e.stats=x.omit(e.stats,"variables"),e}function wg(t){const{rotate:e,formatter:n=Ve}=t.x_axis.axisLabel;return{...t,x_axis:{...t.x_axis,axisLabel:{rotate:e,formatter:n}}}}function Cg(t){const{dataZoom:e=zt,...n}=t;return{...n,dataZoom:e}}function Sg(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 _g(t){const e=t.reference_lines.map(n=>{const{lineStyle:i={type:"dashed",width:1,color:rt.random().css()},show_in_legend:a=!1}=n;return{...n,lineStyle:i,show_in_legend:a}});return{...t,reference_lines:e}}function kg(t){const e=t.reference_lines.map(n=>{const{yAxisIndex:i=0}=n;return{...n,yAxisIndex:i}});return{...t,reference_lines:e}}function Tg(t){const e=t.series.map(n=>{const{aggregation_on_group:i=At}=n;return{...n,aggregation_on_group:i}});return{...t,series:e}}function Dg(t){const e=t.series.map(n=>{const{aggregation_on_value:i=At}=n;return{...n,aggregation_on_value:i}});return{...t,series:e}}function Ig(t){delete t.config;const{x_axis:e,tooltip:n}=t.x_axis.axisLabel.overflow,i={x_axis:{axisLabel:{overflow:{on_axis:e,in_tooltip:n}}}};return x.defaultsDeep(i,t)}function Mg(t){const{series:e,...n}=t;return{...n,series:e.map(i=>{const{barMinWidth:a,barWidth:o,barMaxWidth:l}=i;return a?{...i,barMinWidth:a,barWidth:"",barMaxWidth:l??o}:{...i,barMinWidth:"",barWidth:o,barMaxWidth:""}})}}function Ag(t){const{y_axes:e,...n}=t;return{...n,y_axes:e.map(i=>{const{min:a="",max:o=""}=i;return{...i,min:a,max:o}})}}function zg(t){const{y_axes:e,...n}=t;return{...n,y_axes:e.map(i=>{const{nameAlignment:a="left"}=i;return{...i,nameAlignment:a}})}}function Eg(t){const{y_axes:e,...n}=t;return{...n,y_axes:e.map(i=>{const{show:a=!0}=i;return{...i,show:a}})}}function Pg(t){const{regressions:e,...n}=t;return{...n,regressions:e.map(i=>{const{group_by_key:a=""}=i;return{...i,group_by_key:a}})}}function Lg(t){const{series:e,y_axes:n,...i}=t;return{...i,series:e.map(a=>{const{hide_in_legend:o=!1,aggregation_on_value:l=At}=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 Bg(t){const{type:e="category",...n}=t.x_axis;return{...t,x_axis:{...n,type:e}}}function Og(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=c=>c&&`${n}.${c}`,{x_axis_data_key:a,series:o,regressions:l,...u}=t;return{...u,x_axis_data_key:i(a),series:o.map(c=>({...c,y_axis_data_key:i(c.y_axis_data_key),group_by_key:i(c.group_by_key)})),regressions:l.map(c=>({...c,y_axis_data_key:i(c.y_axis_data_key),group_by_key:i(c.group_by_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class $g extends se{constructor(){super(...arguments);P(this,"VERSION",18)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,{panelModel:i})=>{const{config:a}=n;return(a.variables||[]).forEach(u=>{i.variables.find(c=>c.name===u.name)||i.addVariable(u)}),(x.get(a,"stats.variables")||[]).forEach(u=>{i.variables.find(c=>c.name===u.name)||i.addVariable(u)}),{...n,version:2,config:xg(a)}}),this.version(3,n=>({...n,version:3,config:wg(n.config)})),this.version(4,n=>({...n,version:4,config:Cg(n.config)})),this.version(5,n=>({...n,version:5,config:Sg(n.config)})),this.version(6,n=>({...n,version:6,config:_g(n.config)})),this.version(7,n=>({...n,version:7,config:kg(n.config)})),this.version(8,n=>({...n,version:8,config:Tg(n.config)})),this.version(9,n=>({...n,version:9,config:Dg(n.config)})),this.version(10,n=>({...n,version:10,config:Ig(n.config)})),this.version(11,n=>({...n,version:11,config:Mg(n.config)})),this.version(12,n=>({...n,version:12,config:Ag(n.config)})),this.version(13,n=>({...n,version:13,config:zg(n.config)})),this.version(14,n=>({...n,version:14,config:Eg(n.config)})),this.version(15,n=>({...n,version:15,config:Pg(n.config)})),this.version(16,n=>({...n,version:16,config:Lg(n.config)})),this.version(17,n=>({...n,version:17,config:Bg(n.config)})),this.version(18,(n,i)=>({...n,version:18,config:Og(n.config,i)}))}}const Vg={displayName:"Cartesian Chart",displayGroup:"ECharts-based charts",migrator:new $g,name:"cartesian",viewRender:Vf,configRender:vg,createConfig(){return{version:18,config:x.cloneDeep(Gr)}},triggers:[qr]};function Ng(t){if(t.enable_value)return t.value}function qg(t){if(t.enable_value)return t.value}function Gg(t){const e=t.axisLabel.overflow.on_axis.width,n=t.axisLabel.position,i={top:5,left:5,right:5,bottom:5};return t.orient==="vertical"&&x.get(i,n)&&n===t.funnelAlign&&x.set(i,n,e),i}function Fg(t,e){return t.series.map(n=>{const{level_name_data_key:i,level_value_data_key:a,axisLabel:o,min:l,max:u,funnelAlign:c,orient:p,...h}=n;if(!i||!a)return{};const f=A(i),g=A(a),b=e[f.queryID].map(_=>({name:_[f.columnKey],value:_[g.columnKey]})),w=Ue(o.overflow.on_axis);return{type:"funnel",...Gg(n),min:Ng(l),max:qg(u),minSize:l.size,maxSize:u.size,...h,label:{show:!0,position:o.position,...w},orient:p,funnelAlign:p==="horizontal"?"center":c,data:b}})}function jg({conf:t,params:e,max:n}){const{name:i,value:a}=e.data,o=W(a/n).format({output:"percent",mantissa:2,trimMantissa:!0});return[{label:`${e.marker} ${i}`,value:`${a} (${o})`,style:{label:"",value:""}}]}function Wg(t,e){var o;const n=A(t.series[0].level_name_data_key),i=A(t.series[0].level_value_data_key),a=(o=x.maxBy(e[n.queryID],i.columnKey))==null?void 0:o[i.columnKey];return l=>{const c=jg({conf:t,params:l,max:a}).map(h=>`
|
|
123
123
|
<tr>
|
|
124
124
|
<th style="text-align: right;">
|
|
125
|
-
<div style="${
|
|
125
|
+
<div style="${h.style.label}">${h.label}</div>
|
|
126
126
|
</th>
|
|
127
127
|
<td style="text-align: right; padding: 0 1em;">
|
|
128
|
-
<div style="${
|
|
128
|
+
<div style="${h.style.value}">${h.value}
|
|
129
129
|
</td>
|
|
130
130
|
</tr>
|
|
131
131
|
`);return`
|
|
@@ -135,13 +135,13 @@ Check the top-level render call using <`+V+">.")}return z}}function Ou(S,z){{if(
|
|
|
135
135
|
<table style="width: auto">
|
|
136
136
|
<tbody>${c.join("")}</tbody>
|
|
137
137
|
</table>
|
|
138
|
-
`}}function
|
|
138
|
+
`}}function Rg(t,e){return{trigger:"item",confine:!0,formatter:Wg(t,e)}}function Qg(t,e){return{grid:{top:0,left:0,right:0,bottom:0},tooltip:Rg(t,e),series:Fg(t,e)}}function Ug(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:Le},sort:"descending",orient:"vertical",funnelAlign:"center"}}const Qr={series:[Ug("Funnel")]};Y.use([re.FunnelChart,B.DataZoomComponent,B.GridComponent,B.LegendComponent,B.TooltipComponent,_e.CanvasRenderer]);function Kg({conf:t,data:e,width:n,height:i}){const a=m.useMemo(()=>Qg(t,e),[t,e]);return r(Se,{echarts:Y,option:a,style:{width:n,height:i},notMerge:!0,theme:"merico-light"})}function Yg({context:t}){const{value:e}=V(t.instanceData,"config"),n=m.useMemo(()=>x.defaults({},e,Qr),[e]),i=t.data,{width:a,height:o}=t.viewport;return!a||!o?null:r(Me,{width:a,height:o,children:r(Kg,{width:Re(a),height:Qe(o),data:i,conf:n})})}const Xg=[{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"}],Ur=m.forwardRef(({label:t,value:e,onChange:n,options:i=Xg},a)=>r(s.Select,{ref:a,label:t,data:i,value:e,onChange:n})),Jg=[{label:"Ascending",value:"ascending"},{label:"Descending",value:"descending"},{label:"Use original data order",value:"0"}],Zg=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Hg=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}],em={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"}]},tm=({item:t,control:e,index:n,remove:i})=>{const a=t.min.enable_value,o=t.max.enable_value,{orient:l}=t;return d(s.Stack,{children:[r(s.Group,{grow:!0,noWrap:!0,children:r(v.Controller,{name:`series.${n}.name`,control:e,render:({field:u})=>r(s.TextInput,{label:"Series Name",...u})})}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`series.${n}.level_name_data_key`,control:e,render:({field:u})=>r(O,{label:"Level Name Field",...u})}),r(v.Controller,{name:`series.${n}.level_value_data_key`,control:e,render:({field:u})=>r(O,{label:"Level Value Field",...u})})]}),r(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Funnel Style",labelPosition:"center"}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`series.${n}.min.value`,control:e,render:({field:u})=>r(s.NumberInput,{disabled:!a,labelProps:{display:"block"},label:d(s.Group,{position:"apart",pr:6,sx:{width:"100%"},children:[r(s.Text,{children:"Min Value"}),r(s.Tooltip,{label:"Check to enable specific min value",children:r(s.Box,{children:r(v.Controller,{name:`series.${n}.min.enable_value`,control:e,render:({field:c})=>r(s.Checkbox,{size:"xs",checked:c.value,onChange:p=>c.onChange(p.currentTarget.checked)})})})})]}),...u})}),r(v.Controller,{name:`series.${n}.min.size`,control:e,render:({field:u})=>r(s.TextInput,{placeholder:"0%",label:"Min Size",...u})})]}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`series.${n}.max.value`,control:e,render:({field:u})=>r(s.NumberInput,{disabled:!o,labelProps:{display:"block"},label:d(s.Group,{position:"apart",pr:6,sx:{width:"100%"},children:[r(s.Text,{children:"Max Value"}),r(s.Tooltip,{label:"Check to enable specific max value",children:r(s.Box,{children:r(v.Controller,{name:`series.${n}.max.enable_value`,control:e,render:({field:c})=>r(s.Checkbox,{size:"xs",checked:c.value,onChange:p=>c.onChange(p.currentTarget.checked)})})})})]}),...u})}),r(v.Controller,{name:`series.${n}.max.size`,control:e,render:({field:u})=>r(s.TextInput,{placeholder:"100%",label:"Max Size",...u})})]}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`series.${n}.orient`,control:e,render:({field:u})=>r(s.Select,{label:"Orientation",data:Hg,...u})}),r(v.Controller,{name:`series.${n}.sort`,control:e,render:({field:u})=>r(s.Select,{label:"Sort",data:Jg,...u})})]}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`series.${n}.funnelAlign`,control:e,render:({field:u})=>r(s.Select,{label:"Align",disabled:l==="horizontal",data:Zg,...u})}),r(v.Controller,{name:`series.${n}.gap`,control:e,render:({field:u})=>r(s.NumberInput,{placeholder:"0, 5, 10...",label:"Gap",...u})})]}),r(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Label Style",labelPosition:"center"}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`series.${n}.axisLabel.position`,control:e,render:({field:u})=>r(Ur,{label:"Position",options:em[l],...u})}),r(s.Box,{})]}),r(s.Group,{grow:!0,noWrap:!0,children:r(v.Controller,{name:`series.${n}.axisLabel.overflow`,control:e,render:({field:u})=>r(Je,{...u})})})]})},nm=({control:t,watch:e})=>{const{fields:n,append:i,remove:a}=v.useFieldArray({control:t,name:"series"}),o=e("series"),l=n.map((h,f)=>({...h,...o[f]})),u=x.get(l,"0.id"),[c,p]=m.useState(u??null);return m.useEffect(()=>{u&&p(h=>h!==null?h:u)},[u]),d(s.Tabs,{value:c,onTabChange:h=>p(h),styles:{panel:{padding:"0px",paddingTop:"6px"}},children:[d(s.Tabs.List,{children:[l.map((h,f)=>r(s.Tabs.Tab,{value:h.id,children:h.name},h.id)),r(s.Tabs.Tab,{value:"add",disabled:!0,children:r(s.Tooltip,{label:"TODO",children:r(s.Center,{children:r(M.IconPlus,{size:18,color:"#228be6"})})})})]}),l.map((h,f)=>r(s.Tabs.Panel,{value:h.id,children:r(tm,{item:h,control:t,index:f,remove:a})},h.id))]})};function rm({context:t}){const{value:e,set:n}=V(t.instanceData,"config"),i=m.useMemo(()=>x.defaultsDeep({},e,Qr),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:i});m.useEffect(()=>{c(i)},[i]),l([]);const p=u(),h=m.useMemo(()=>!x.isEqual(p,i),[p,i]);return r(s.Stack,{spacing:"xs",children:d("form",{onSubmit:o(n),children:[d(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(s.Text,{children:"Funnel Config"}),r(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:r(T.DeviceFloppy,{size:20})})]}),r(nm,{control:a,watch:l})]})})}function im(t){return{series:t.series.map(e=>{const{min:n,minSize:i,max:a,maxSize:o,...l}=e;return{...l,min:{value:n,use_data_min:!1,size:i},max:{value:a,use_data_max:!1,size:o}}})}}function am(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=l=>l&&`${n}.${l}`,{series:a,...o}=t;return{...o,series:a.map(l=>({...l,level_name_data_key:i(l.level_name_data_key),level_value_data_key:i(l.level_value_data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class sm extends se{constructor(){super(...arguments);P(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{config:i}=n;return{...n,version:2,config:im(i)}}),this.version(3,(n,i)=>{const{config:a}=n;return{...n,version:3,config:am(a,i)}})}}const om={displayName:"Funnel Chart",displayGroup:"ECharts-based charts",migrator:new sm,name:"funnel",viewRender:Yg,configRender:rm,createConfig:()=>({version:3,config:Qr})};function xs({enabled:t,func_content:e}){return(n,i)=>{if(!t)return n;try{return new Function(`return ${e}`)()(n,i)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function lm(t){const e=xs(t.x_axis.axisLabel.formatter),n=xs(t.y_axis.axisLabel.formatter);return{x_axis:e,y_axis:n}}function um(t){return{heat_block:function(i){if(!t.heat_block.value_formatter)return i;try{return W(i).format(t.heat_block.value_formatter)}catch(a){return console.error(a),i}}}}function cm(t){let e=0;return t.x_axis.name&&(e+=20),{top:45,left:5,right:5,bottom:e,containLabel:!0}}function dm(t,e,n){const{heat_block:i}=t;return{type:"heatmap",name:i.name,xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{borderColor:"white",borderWidth:n},data:e,label:i.label,labelLayout:{hideOverlap:!0}}}const pm=t=>{try{return W(t).format({trimMantissa:!0,mantissa:2})}catch{return t}};function hm({conf:t,labelFormatters:e,valueFormatters:n,dataDict:i,params:a}){const{value:o,dataIndex:l}=a,[u,c,p]=o,h={label:t.x_axis.name?t.x_axis.name:"X Axis",value:e.x_axis(u,l),style:{label:"",value:Ze(t.x_axis.axisLabel.overflow.in_tooltip)}},f={label:t.y_axis.name?t.y_axis.name:"Y Axis",value:e.y_axis(c,l),style:{label:"",value:Ze(t.y_axis.axisLabel.overflow.in_tooltip)}},g={label:t.heat_block.name,value:n.heat_block(p),style:{label:"",value:""}},b=[h,f,g],w=i[`${u}---${c}`];return w&&t.tooltip.metrics.forEach(_=>{const D=A(_.data_key);b.push({label:_.name,value:pm(x.get(w,D.columnKey,"")),style:{label:"",value:""}})}),b}function fm(t,e,n,i){const{x_axis:a,y_axis:o,heat_block:l}=t,u=A(a.data_key),c=A(o.data_key);A(l.data_key);const p=x.keyBy(e[u.queryID],h=>`${h[u.columnKey]}---${h[c.columnKey]}`);return{confine:!0,formatter:function(h){const g=hm({conf:t,labelFormatters:n,valueFormatters:i,dataDict:p,params:h}).map(w=>`
|
|
139
139
|
<tr>
|
|
140
140
|
<th style="text-align: right;">
|
|
141
|
-
<div style="${
|
|
141
|
+
<div style="${w.style.label}">${w.label}</div>
|
|
142
142
|
</th>
|
|
143
143
|
<td style="text-align: right; padding: 0 1em;">
|
|
144
|
-
<div style="${
|
|
144
|
+
<div style="${w.style.value}">${w.value}
|
|
145
145
|
</td>
|
|
146
146
|
</tr>
|
|
147
147
|
`);return`
|
|
@@ -150,20 +150,20 @@ Check the top-level render call using <`+V+">.")}return z}}function Ou(S,z){{if(
|
|
|
150
150
|
<tr colspan="2">
|
|
151
151
|
<div style="
|
|
152
152
|
width: 100%; height: 4px; border-radius: 2px; margin-bottom: 6px;
|
|
153
|
-
background-color: ${
|
|
153
|
+
background-color: ${h.color};"
|
|
154
154
|
/>
|
|
155
155
|
</tr>
|
|
156
156
|
</thead>
|
|
157
157
|
<tbody>${g.join("")}</tbody>
|
|
158
158
|
</table>
|
|
159
|
-
`}}}const
|
|
160
|
-
`)}},
|
|
161
|
-
`)},
|
|
159
|
+
`}}}const gm=({value:t,onChange:e})=>{const n=i=>{i&&e(i)};return r(s.Box,{children:r(ve,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},ws={static:{type:"static",value:10},dynamic:{type:"dynamic",value:["function getValue({ variables }, { lodash, interpolate }) {"," // your code goes here"," return 100;","}"].join(`
|
|
160
|
+
`)}},mm=({value:t,onChange:e})=>{const[n,{setTrue:i,setFalse:a}]=q.useBoolean(),[o,l]=m.useState(t),u=()=>{a();const{type:f,value:g}=o,b={type:f,value:g};l(b),e(b)},c=()=>{a(),l(t)},p=f=>{l(g=>({...g,value:f}))},h=()=>{p(ws.dynamic.value)};return d(z,{children:[r(s.Box,{sx:{width:"50%"},children:r(s.Button,{variant:"filled",mt:24,onClick:i,sx:{flexGrow:0},children:"Setup"})}),r(s.Modal,{size:800,title:"Setup dynamic value",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&d(s.Stack,{children:[r(s.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),r(gm,{value:o.value,onChange:p}),d(s.Group,{position:"apart",children:[r(s.Button,{onClick:h,color:"red",leftIcon:r(T.Recycle,{size:20}),children:"Reset"}),d(s.Group,{position:"right",children:[r(s.Button,{onClick:c,variant:"subtle",children:"Cancel"}),r(s.Button,{onClick:u,children:"OK"})]})]})]})})]})},ym=({value:t,onChange:e})=>t.type!=="dynamic"?null:r(mm,{value:t,onChange:e}),bm=({value:t,onChange:e})=>{if(t.type!=="static")return null;const n=i=>{e({...t,value:i})};return r(s.NumberInput,{defaultValue:18,label:" ",hideControls:!0,value:t.value,onChange:n})},vm=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Et=m.forwardRef(({label:t="Value",value:e,onChange:n},i)=>{const a=o=>{n({...ws[o]})};return d(s.SimpleGrid,{cols:2,children:[r(s.Select,{ref:i,label:t,data:vm,value:e.type,onChange:a,sx:{flexGrow:1}}),r(bm,{value:e,onChange:n}),r(ym,{value:e,onChange:n})]})});function Pt(t,e,n){if(!t.type)return n;if(t.type==="static"){const{value:a}=t;return a}const{value:i}=t;try{return new Function(`return ${i}`)()({variables:e},{lodash:x,interpolate:ft.interpolate})}catch(a){return console.error(`[getNumberOrDynamicValue] failed parsing custom function, error: ${a.message}`),10}}function xm(t,e){const n=Pt(t.heat_block.min,e),i=Pt(t.heat_block.max,e);return{min:n,max:i,calculable:!0,orient:"horizontal",left:"center",top:0,itemWidth:15}}function wm(t,e,n){const{overflow:i,rotate:a}=t.x_axis.axisLabel,o=Ue(i.on_axis);return{id:"main-x-axis",type:"category",data:e,name:t.x_axis.name??"",align:"center",axisTick:{show:!0,alignWithLabel:!0},axisLabel:{rotate:a,...o,formatter:n},splitArea:{show:!0},nameLocation:"center",nameGap:25,nameTextStyle:{fontWeight:"bold",align:"center"},z:2}}function Cm(t,e,n){const{nameAlignment:i,data_key:a,...o}=t.y_axis,{overflow:l,rotate:u}=t.y_axis.axisLabel,c=Ue(l.on_axis);return{...o,type:"category",data:e,axisLabel:{rotate:u,...c,formatter:n},axisLine:{show:!0,color:"blue"},axisTick:{show:!0,alignWithLabel:!0},splitArea:{show:!0},nameTextStyle:{fontWeight:"bold",align:i},nameLocation:"end",nameGap:15,z:2}}const Sm={tooltip:{confine:!0}};function _m(t,e,n,i){return n<t*10||i<e*10?0:n<t*20||i<e*20?1:2}function km(t,e,n,i,a){if(!t.x_axis.data_key||!t.y_axis.data_key||!t.heat_block.data_key)return{};const o=n.reduce((D,L)=>{const N=ot(L,e);return D[L.name]=Fe(L,N),D},{}),l=lm(t),u=um(t),c=A(t.x_axis.data_key),p=A(t.y_axis.data_key),h=A(t.heat_block.data_key),f=x.uniq(e[c.queryID].map(D=>D[c.columnKey])),g=x.uniq(e[c.queryID].map(D=>D[p.columnKey])),b=e[c.queryID].map(D=>[x.get(D,c.columnKey),x.get(D,p.columnKey),x.get(D,h.columnKey)]),w=_m(f.length,g.length,i,a),_={xAxis:wm(t,f,l.x_axis),yAxis:Cm(t,g,l.y_axis),series:dm(t,b,w),tooltip:fm(t,e,l,u),grid:cm(t),visualMap:xm(t,o)};return x.defaultsDeep({},_,Sm)}function Tm(t){return r(z,{})}function Dm(t){return r(s.Text,{children:"Click heat block"})}const Cs={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:Dm,configRender:Tm,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"}]},Kr={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,overflow:Le,formatter:{...Ve}}},y_axis:{name:"Y Axis",data_key:"",nameAlignment:"center",axisLabel:{rotate:0,overflow:Le,formatter:{...Ve}}},heat_block:{min:{type:"static",value:0},max:{type:"static",value:100},name:"Value",data_key:"",value_formatter:xe,label:{show:!1,fontSize:10}},tooltip:{metrics:[]}};Y.use([B.DataZoomComponent,re.HeatmapChart,B.GridComponent,B.LegendComponent,B.TooltipComponent,B.VisualMapComponent,_e.CanvasRenderer]);function Im({conf:t,data:e,width:n,height:i,interactionManager:a,variables:o}){const l=m.useMemo(()=>{const f=A(t.x_axis.data_key),g=A(t.y_axis.data_key);return x.keyBy(e[f.queryID],b=>`${b[f.columnKey]}---${b[g.columnKey]}`)},[e,t.x_axis.data_key,t.y_axis.data_key]),u=Ne(a.triggerManager,Cs.id),c=m.useCallback(f=>{const[g,b]=f.value,w=x.get(l,`${g}---${b}`,{error:"rowData is not found"});u.forEach(_=>{a.runInteraction(_.id,{...f,rowData:w})})},[l,u,a]),p=m.useMemo(()=>({click:c}),[c]),h=m.useMemo(()=>km(t,e,o,n,i),[t,e,n,i]);return r(Se,{echarts:Y,option:h,style:{width:n,height:i},onEvents:p,notMerge:!0,theme:"merico-light"})}function Mm({context:t,instance:e}){const n=qe({vizManager:t.vizManager,instance:e}),{value:i}=V(t.instanceData,"config"),{variables:a}=t,o=m.useMemo(()=>x.defaults({},i,Kr),[i]),l=t.data,{width:u,height:c}=t.viewport;return!u||!c?null:r(Me,{width:u,height:c,children:r(Im,{variables:a,width:Re(u),height:Qe(c),data:l,conf:o,interactionManager:n})})}function Am({control:t,watch:e}){e(["heat_block"]);const n=e("heat_block.label.show");return d(s.Stack,{children:[d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"heat_block.data_key",control:t,render:({field:i})=>r(O,{label:"Data Field",required:!0,sx:{flex:1},...i})}),r(v.Controller,{name:"heat_block.name",control:t,render:({field:i})=>r(s.TextInput,{label:"Name",sx:{flex:1},...i})})]}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"heat_block.min",control:t,render:({field:i})=>r(Et,{label:"Min Value",...i})}),r(v.Controller,{name:"heat_block.max",control:t,render:({field:i})=>r(Et,{label:"Max Value",...i})})]}),r(s.Divider,{mb:-15,variant:"dashed",label:"Value Format",labelPosition:"center"}),r(v.Controller,{name:"heat_block.value_formatter",control:t,render:({field:i})=>r(Pe,{...i})}),r(s.Divider,{mb:-5,variant:"dashed",label:"Label",labelPosition:"center"}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"heat_block.label.show",control:t,render:({field:i})=>r(s.Switch,{label:"Show label",checked:i.value,onChange:a=>i.onChange(a.currentTarget.checked),sx:{flexGrow:1}})}),r(v.Controller,{name:"heat_block.label.fontSize",control:t,render:({field:i})=>r(s.NumberInput,{size:"xs",icon:r(M.IconTextSize,{size:16}),disabled:!n,...i})})]})]})}const zm=({control:t,index:e,remove:n})=>d(s.Stack,{children:[d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`tooltip.metrics.${e}.name`,control:t,render:({field:i})=>r(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})}),r(v.Controller,{name:`tooltip.metrics.${e}.data_key`,control:t,render:({field:i})=>r(O,{label:"Value Field",required:!0,sx:{flex:1},...i})})]}),r(s.Divider,{mb:-10,mt:10,variant:"dashed"}),r(s.Button,{leftIcon:r(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),Em=({control:t,watch:e})=>{const{fields:n,append:i,remove:a}=v.useFieldArray({control:t,name:"tooltip.metrics"}),o=e("tooltip.metrics"),l=n.map((f,g)=>({...f,...o[g]})),u=()=>i({id:Date.now().toString(),data_key:"",name:""}),c=e("tooltip.metrics.0.id"),[p,h]=m.useState(()=>c??null);return m.useEffect(()=>{c&&h(f=>f!==null?f:c)},[c]),d(z,{children:[d(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[r(T.InfoCircle,{size:14,color:"#888"}),r(s.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),r(s.Divider,{variant:"dashed",my:10}),d(s.Tabs,{value:p,onTabChange:f=>h(f),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[d(s.Tabs.List,{children:[l.map((f,g)=>r(s.Tabs.Tab,{value:f.id,children:f.name?f.name:g},f.id)),r(s.Tabs.Tab,{onClick:u,value:"add",children:r(T.Plus,{size:18,color:"#228be6"})})]}),l.map((f,g)=>r(s.Tabs.Panel,{value:f.id,children:r(zm,{control:t,index:g,remove:a},f.id)},f.id))]})]})};function Pm({control:t,watch:e}){return r(Em,{control:t,watch:e})}const Lm=({disabled:t,value:e,onChange:n})=>{const i=a=>{a&&n(a)};return d(s.Box,{sx:{position:"relative"},children:[t&&r(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),r(ve,{height:"500px",defaultLanguage:"javascript",value:e,onChange:i,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},Bm={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
161
|
+
`)},Ss=m.forwardRef(({value:t,onChange:e},n)=>{const[i,{setTrue:a,setFalse:o}]=q.useBoolean(),[l,u]=m.useState(t);m.useEffect(()=>{u(t)},[t]);const c=b=>{u({...l,enabled:b})},p=()=>{o();const{enabled:b,func_content:w}=l,_={enabled:b,func_content:w};u(_),e(_)},h=()=>{o(),u(t)},f=b=>{u(w=>({...w,func_content:b}))},g=()=>{f(Bm.func_content)};return d(z,{children:[r(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Customize Label"}),r(s.Modal,{size:800,title:"Customize label content",opened:i,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:i&&d(s.Stack,{children:[r(s.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:b=>c(b.currentTarget.checked)}),r(Lm,{value:l.func_content,onChange:f,disabled:!l.enabled}),d(s.Group,{position:"apart",children:[r(s.Button,{onClick:g,color:"red",leftIcon:r(T.Recycle,{size:20}),children:"Reset"}),d(s.Group,{position:"right",children:[r(s.Button,{onClick:h,variant:"subtle",children:"Cancel"}),r(s.Button,{onClick:p,children:"OK"})]})]})]})})]})});function Om({control:t,watch:e}){return e(["x_axis"]),d(s.Stack,{children:[d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>r(O,{label:"Data Field",required:!0,sx:{flex:1},...n})}),r(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>r(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),r(s.Divider,{mb:-15,variant:"dashed",label:"Tick Label",labelPosition:"center"}),r(v.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>r(Je,{...n})}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>r(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:r(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),r(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>r(Ss,{...n})})]})]})}const $m=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function Vm({control:t,watch:e}){return e(["y_axis"]),d(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"y_axis.data_key",control:t,render:({field:n})=>r(O,{label:"Data Field",required:!0,sx:{flex:1},...n})}),r(v.Controller,{name:"y_axis.name",control:t,render:({field:n})=>r(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...n})})]}),r(s.Group,{grow:!0,noWrap:!0,children:r(v.Controller,{name:"y_axis.nameAlignment",control:t,render:({field:n})=>r(s.Select,{label:"Name Alignment",required:!0,data:$m,sx:{flex:1},...n})})}),r(s.Divider,{mb:-15,variant:"dashed",label:"Tick Label",labelPosition:"center"}),r(v.Controller,{name:"y_axis.axisLabel.overflow",control:t,render:({field:n})=>r(Je,{...n})}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"y_axis.axisLabel.rotate",control:t,render:({field:n})=>r(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:r(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),r(v.Controller,{name:"y_axis.axisLabel.formatter",control:t,render:({field:n})=>r(Ss,{...n})})]})]})}function Nm({context:t}){const{value:e,set:n}=V(t.instanceData,"config"),i=m.useMemo(()=>x.defaultsDeep({},e,Kr),[e]),a=m.useMemo(()=>x.cloneDeep(i),[i]);m.useEffect(()=>{!x.isEqual(i,a)&&(console.log("config malformed, resetting to defaults",i,a),n(a))},[i,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:p}=v.useForm({defaultValues:a});m.useEffect(()=>{p(a)},[a]);const h=c(),f=m.useMemo(()=>!x.isEqual(h,i),[h,i]);return r("form",{onSubmit:l(n),style:{flexGrow:1},children:d(s.Stack,{spacing:"xs",sx:{height:"100%"},children:[d(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(s.Text,{children:"Chart Config"}),r(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:r(T.DeviceFloppy,{size:20})})]}),d(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{root:{flexGrow:1},tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[d(s.Tabs.List,{children:[r(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),r(s.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),r(s.Tabs.Tab,{value:"Heat Block",children:"Heat Block"}),r(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"})]}),r(s.Tabs.Panel,{value:"X Axis",children:r(Om,{control:o,watch:u})}),r(s.Tabs.Panel,{value:"Y Axis",children:r(Vm,{control:o,watch:u})}),r(s.Tabs.Panel,{value:"Heat Block",children:r(Am,{control:o,watch:u})}),r(s.Tabs.Panel,{value:"Tooltip",children:r(Pm,{control:o,watch:u})})]})]})})}function qm(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=p=>p&&`${n}.${p}`,{x_axis:a,y_axis:o,heat_block:l,tooltip:u,...c}=t;return{...c,x_axis:{...a,data_key:i(a.data_key)},y_axis:{...o,data_key:i(o.data_key)},heat_block:{...l,data_key:i(l.data_key)},tooltip:{...u,metrics:u.metrics.map(p=>({...p,data_key:i(p.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}function Gm(t){return x.defaultsDeep({},t,{heat_block:{label:{show:!1,fontSize:10}}})}function Fm(t){const{heat_block:e}=t;let{min:n,max:i}=e;return typeof n!="number"&&(n=0),typeof i!="number"&&(i=100),{...t,heat_block:{...e,min:{type:"static",value:n},max:{type:"static",value:i}}}}class jm extends se{constructor(){super(...arguments);P(this,"VERSION",4)}configVersions(){this.version(1,n=>(console.log("🟥 unexpected calling"),{version:1,config:n})),this.version(2,(n,i)=>({...n,version:2,config:qm(n.config,i)})),this.version(3,n=>({...n,version:3,config:Gm(n.config)})),this.version(4,n=>({...n,version:4,config:Fm(n.config)}))}}const Wm={displayName:"Heatmap",displayGroup:"ECharts-based charts",migrator:new jm,name:"heatmap",viewRender:Mm,configRender:Nm,createConfig:()=>({version:4,config:Kr}),triggers:[Cs]},_s={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:Qm,configRender:Rm,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 Rm(t){return r(z,{})}function Qm(t){return r(s.Text,{children:"Click chart's series"})}const ks={label_template:"${percentage.x} of ${x_axis.name} causes ${percentage.y} of ${bar.name}",color:"rgba(0,0,0,0.3)"},Yr={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...Ve},overflow:Le}},data_key:"value",bar:{name:"Value",nameAlignment:"left",color:"#228be6",label_formatter:xe},line:{name:"Value",nameAlignment:"right",color:"red"},dataZoom:zt,markLine:ks};function Ln(t){return W(t).format({output:"percent",mantissa:0})}function Um(t){const e=t.value[1];try{return Ln(e)}catch(n){return console.error(n),e}}function Km(t){function e(n){let i=n;if(typeof n=="object"&&(Array.isArray(n.value)&&n.value.length===2?i=n.value[1]:i=n.value),!t.bar.label_formatter)return i;try{return W(i).format(t.bar.label_formatter)}catch(a){return console.error(a),i}}return{bar:e,line:Um,lineValue:Ln}}function Ym(t,e,n){const{label_template:i}=t.markLine;if(!i)return"";const a={...t,percentage:e,count:n},o=Object.keys(a),l=Object.values(a);return new Function(...o,`return \`${i}\`;`)(...l)}function Xm(t,e){if(e.length===0)return{};const n=e.findIndex(u=>u[1]>=.8);if(n===-1)return{};const i=e[n],a={x:Ln((n+1)/e.length),y:Ln(i[1])},o={left:n+1,right:e.length-n-1},l=i[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:Ym(t,a,o)}}]}:{}}function Jm(t,e,n){const{x_axis:i,data_key:a}=t;if(!i.data_key||!a)return[];const o=A(i.data_key),l=A(a);if(o.queryID!==l.queryID)throw new Error("Please use the same query for X & Y axis");const u=e[o.queryID].map(f=>[f[o.columnKey],Number(f[l.columnKey])]).sort((f,g)=>g[1]-f[1]),c=u.reduce((f,g)=>f+g[1],0),p=u.reduce((f,g,b)=>{const w=b===0?0:f[b-1][1];return f.push([g[0],w+g[1]]),f},[]).map(f=>[f[0],f[1]/c]),h=Xm(t,p);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:p,markLine:h}]}const Zm=(t,e)=>n=>{const i=Array.isArray(n)?n:[n];if(i.length===0)return"";const a=i.map((u,c)=>{const p=u.seriesName,[h,f]=u.value;if(!p)return f;const g=c===0?e.bar:e.lineValue;return`
|
|
162
162
|
<tr>
|
|
163
|
-
<th style="text-align: right; padding: 0 1em;">${
|
|
164
|
-
<td style="text-align: left; padding: 0 1em;">${g(
|
|
163
|
+
<th style="text-align: right; padding: 0 1em;">${p}</th>
|
|
164
|
+
<td style="text-align: left; padding: 0 1em;">${g(f)}</td>
|
|
165
165
|
</tr>
|
|
166
|
-
`}),o=
|
|
166
|
+
`}),o=Ze(t.x_axis.axisLabel.overflow.in_tooltip),l=i[0].name;return`
|
|
167
167
|
<div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
|
|
168
168
|
<div style="${o}">${l}</div>
|
|
169
169
|
</div>
|
|
@@ -172,7 +172,7 @@ Check the top-level render call using <`+V+">.")}return z}}function Ou(S,z){{if(
|
|
|
172
172
|
${a.join("")}
|
|
173
173
|
</tbody>
|
|
174
174
|
</table>
|
|
175
|
-
`};function
|
|
175
|
+
`};function Hm(t,e){return{trigger:"axis",formatter:Zm(t,e)}}function ey(t){const{name:e,axisLabel:n}=t.x_axis,i=Ue(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,...i,formatter:Dt(n.formatter)}}]}function ty(t,e){return[{name:t.bar.name,nameGap:20,minInterval:1,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 ny(t,e,n){const i=Km(t);return{dataZoom:Fr(t.dataZoom),tooltip:Hm(t,i),xAxis:ey(t),yAxis:ty(t,i),series:Jm(t,e,i),grid:{top:50,left:30,right:15,bottom:5,containLabel:!0}}}Y.use([re.BarChart,re.LineChart,B.DataZoomComponent,B.GridComponent,B.LegendComponent,B.TooltipComponent,_e.CanvasRenderer]);function ry({context:t,instance:e}){const{value:n}=V(t.instanceData,"config"),i=t.data,{width:a,height:o}=t.viewport,l=x.defaults({},n,Yr),u=ny(l,i),c=qe({vizManager:t.vizManager,instance:e}),p=Ne(c.triggerManager,_s.id),h=yt(i,l.x_axis.data_key),f=m.useCallback(b=>{const w=x.get(h,b.name,{error:"rowData is not found"});p.forEach(_=>{c.runInteraction(_.id,{...b,rowData:w})})},[h,p,c]),g=m.useMemo(()=>({click:f}),[f]);return!l||!a||!o?null:r(Me,{width:a,height:o,children:r(Se,{echarts:Y,option:u,style:jt(a,o),onEvents:g,notMerge:!0,theme:"merico-light"})})}const iy=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function ay({control:t,watch:e}){return e(["bar"]),d(s.Stack,{children:[d(s.Group,{grow:!0,children:[r(v.Controller,{name:"bar.name",control:t,render:({field:n})=>r(s.TextInput,{label:"Bar Name",sx:{flex:1},...n})}),r(v.Controller,{name:"bar.nameAlignment",control:t,render:({field:n})=>r(s.Select,{label:"Align",required:!0,data:iy,sx:{flex:1},...n})})]}),d(s.Stack,{spacing:2,children:[r(s.Text,{size:"sm",children:"Color"}),r(v.Controller,{name:"bar.color",control:t,render:({field:n})=>r(Te,{...n})})]}),d(s.Stack,{children:[r(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),r(v.Controller,{name:"bar.label_formatter",control:t,render:({field:n})=>r(Pe,{...n})})]})]})}const sy=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function oy({control:t,watch:e}){return e(["line"]),d(s.Stack,{children:[d(s.Group,{grow:!0,children:[r(v.Controller,{name:"line.name",control:t,render:({field:n})=>r(s.TextInput,{label:"Line Name",sx:{flex:1},...n})}),r(v.Controller,{name:"line.nameAlignment",control:t,render:({field:n})=>r(s.Select,{label:"Align",required:!0,data:sy,sx:{flex:1},...n})})]}),d(s.Stack,{spacing:2,children:[r(s.Text,{size:"sm",children:"Color"}),r(v.Controller,{name:"line.color",control:t,render:({field:n})=>r(Te,{...n})})]})]})}const ly=`
|
|
176
176
|
{
|
|
177
177
|
// 80-20 line stuff
|
|
178
178
|
percentage: {
|
|
@@ -195,8 +195,8 @@ Check the top-level render call using <`+V+">.")}return z}}function Ou(S,z){{if(
|
|
|
195
195
|
name: string;
|
|
196
196
|
};
|
|
197
197
|
}
|
|
198
|
-
`,
|
|
199
|
-
{percentage|{d}%}`,minMargin:5,edgeDistance:10,lineHeight:15,rich:{percentage:{color:"#999"}},margin:20},labelLine:{length:15,length2:0,maxSurfaceAngle:80,showAbove:!0},labelLayout:function(
|
|
198
|
+
`,uy=()=>{const[t,e]=m.useState(!1);return d(z,{children:[r(s.Button,{variant:"subtle",compact:!0,onClick:()=>e(n=>!n),children:t?"Close":"Click to see params for Label Template"}),r(s.Collapse,{in:t,children:r(gt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:ly})})]})};function cy({control:t,watch:e}){return e(["markLine"]),d(s.Stack,{children:[d(s.Stack,{spacing:2,children:[r(s.Text,{size:"sm",children:"Color"}),r(v.Controller,{name:"markLine.color",control:t,render:({field:n})=>r(Te,{...n})})]}),d(s.Stack,{spacing:4,children:[r(v.Controller,{name:"markLine.label_template",control:t,render:({field:n})=>r(s.Textarea,{autosize:!0,minRows:2,maxRows:4,label:"Label Template",sx:{flex:1},...n})}),r(uy,{})]})]})}function dy({control:t,watch:e}){return e(["x_axis"]),d(s.Stack,{children:[d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>r(O,{label:"Data Field",required:!0,sx:{flex:1},...n})}),r(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>r(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),r(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>r(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:r(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),r(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>r(En,{...n})})]}),r(v.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>r(Je,{...n})})]})}function py({control:t,watch:e}){return e(["data_key"]),r(s.Stack,{children:r(v.Controller,{name:"data_key",control:t,render:({field:n})=>r(O,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})})})}function hy({context:t}){const{value:e,set:n}=V(t.instanceData,"config"),i=m.useMemo(()=>x.defaults({},e,Yr),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:i});m.useEffect(()=>{c(i)},[i]),l(["x_axis","data_key","bar","line","dataZoom"]);const p=u(),h=m.useMemo(()=>!x.isEqual(p,e),[p,e]);return d("form",{onSubmit:o(n),children:[d(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(s.Text,{children:"Chart Config"}),r(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:r(T.DeviceFloppy,{size:20})})]}),d(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[d(s.Tabs.List,{children:[r(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),r(s.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),r(s.Tabs.Tab,{value:"Bar",children:"Bar"}),r(s.Tabs.Tab,{value:"Line",children:"Line"}),r(s.Tabs.Tab,{value:"80-20 Line",children:"80-20 Line"}),r(s.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),r(s.Tabs.Panel,{value:"X Axis",children:r(dy,{control:a,watch:l})}),r(s.Tabs.Panel,{value:"Y Axis",children:r(py,{control:a,watch:l})}),r(s.Tabs.Panel,{value:"Bar",children:r(ay,{control:a,watch:l})}),r(s.Tabs.Panel,{value:"Line",children:r(oy,{control:a,watch:l})}),r(s.Tabs.Panel,{value:"80-20 Line",children:r(cy,{control:a,watch:l})}),r(s.Tabs.Panel,{value:"Zooming",children:r(v.Controller,{name:"dataZoom",control:a,render:({field:f})=>r(Wr,{...f})})})]})]})}function fy(t){const{dataZoom:e=zt,...n}=t;return{...n,dataZoom:e}}function gy(t){const{markLine:e=ks,...n}=t;return{...n,markLine:e}}function my(t){const e=x.defaultsDeep({},t.x_axis.axisLabel,{rotate:0,formatter:{...Ve}});return{...t,x_axis:{...t.x_axis,axisLabel:e}}}function yy(t){const{label_formatter:e=xe}=t.bar;return{...t,bar:{...t.bar,label_formatter:e}}}function by(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 vy(t){const e={bar:{nameAlignment:"left"},line:{nameAlignment:"right"}};return x.defaultsDeep(e,t)}function xy(t){console.log(t);const{x_axis:e,tooltip:n}=t.x_axis.axisLabel.overflow,i={x_axis:{axisLabel:{overflow:{on_axis:e,in_tooltip:n}}}};return x.defaultsDeep(i,t)}function wy(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=u=>u&&`${n}.${u}`,{x_axis:a,data_key:o,...l}=t;return{...l,x_axis:{...a,data_key:i(a.data_key)},data_key:i(o)}}catch(n){throw console.error("[Migration failed]",n),n}}class Cy extends se{constructor(){super(...arguments);P(this,"VERSION",9)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:fy(n.config)})),this.version(3,n=>({...n,version:3,config:gy(n.config)})),this.version(4,n=>({...n,version:4,config:my(n.config)})),this.version(5,n=>({...n,version:5,config:yy(n.config)})),this.version(6,n=>({...n,version:6,config:by(n.config)})),this.version(7,n=>({...n,version:7,config:vy(n.config)})),this.version(8,n=>({...n,version:8,config:xy(n.config)})),this.version(9,(n,i)=>({...n,version:9,config:wy(n.config,i)}))}}const Sy={displayName:"Pareto Chart",displayGroup:"ECharts-based charts",migrator:new Cy,name:"paretoChart",viewRender:ry,configRender:hy,createConfig(){return{version:9,config:x.cloneDeep(Yr)}},triggers:[_s]},Xr={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 _y(){Y.registerTheme("merico-light",{color:Object.values(Xr.graphics.multiple),visualMap:{color:Object.values(Xr.graphics.depth).reverse()}})}function Ts(){_y()}function*ky(t){const e=Xr.graphics[t];if(!e)throw new Error("Invalid palette key provided");const n=Object.values(e);let i=0;for(;;)yield n[i%n.length],i++}function Ty(t,e,n){const{label_field:i,value_field:a,color_field:o}=t;if(!i||!a)return{};const l=A(i),u=A(a),c=A(o),p=e[l.queryID].map(f=>({name:f[l.columnKey],value:Number(f[u.columnKey]),color:c.columnKey?f[c.columnKey]:void 0})),h=ky("multiple");return{type:"pie",name:"pie",radius:["50%","80%"],itemStyle:{color:({data:f})=>f.color?f.color:h.next().value},label:{position:"outer",alignTo:"edge",formatter:`{name|{b}}
|
|
199
|
+
{percentage|{d}%}`,minMargin:5,edgeDistance:10,lineHeight:15,rich:{percentage:{color:"#999"}},margin:20},labelLine:{length:15,length2:0,maxSurfaceAngle:80,showAbove:!0},labelLayout:function(f){const g=f.labelRect.x<n/2,b=f.labelLinePoints;return x.set(b,[2,0],g?f.labelRect.x:f.labelRect.x+f.labelRect.width),{labelLinePoints:b}},data:p,top:10,bottom:10,left:10,right:10}}function Dy(t,e,n){return{tooltip:{show:!0,confine:!0},series:Ty(t,e,n)}}const Ds={id:"builtin:echarts:click-pie-chart:series",displayName:"Click Pie Series",nameRender:My,configRender:Iy,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 Iy(t){return r(z,{})}function My(t){return r(s.Text,{children:"Click chart's series"})}const Jr={label_field:"",value_field:"",color_field:""};Y.use([re.PieChart,_e.CanvasRenderer]);function Ay({conf:t,data:e,width:n,height:i,interactionManager:a}){const o=yt(e,t.label_field),l=Ne(a.triggerManager,Ds.id),u=m.useCallback(h=>{const f=x.get(o,h.name,{error:"rowData is not found"});l.forEach(g=>{a.runInteraction(g.id,{...h,rowData:f})})},[o,l,a]),c=m.useMemo(()=>Dy(t,e,n),[t,e,n]),p=m.useMemo(()=>({click:u}),[u]);return!n||!i||!c.series.name?null:r(Se,{echarts:Y,option:c,style:{width:n,height:i},onEvents:p,notMerge:!0,theme:"merico-light"})}function zy({context:t,instance:e}){const n=qe({vizManager:t.vizManager,instance:e}),{value:i}=V(t.instanceData,"config"),a=m.useMemo(()=>x.defaults({},i,Jr),[i]),o=t.data,{width:l,height:u}=t.viewport;return!l||!u?null:r(Me,{width:l,height:u,children:r(Ay,{conf:a,width:Re(l),height:Qe(u),data:o,interactionManager:n})})}function Ey({context:t}){const{value:e,set:n}=V(t.instanceData,"config"),i=m.useMemo(()=>x.defaultsDeep({},e,Jr),[e]),a=m.useMemo(()=>x.clone(i),[i]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:p}=v.useForm({defaultValues:a});m.useEffect(()=>{p(a)},[a]);const h=c(),f=m.useMemo(()=>!x.isEqual(h,i),[h,i]);return u(["label_field","value_field","color_field"]),r(s.Stack,{spacing:"xs",children:d("form",{onSubmit:l(n),children:[d(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(s.Text,{children:"Pie Chart Config"}),r(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:r(T.DeviceFloppy,{size:20})})]}),d(s.Stack,{mt:"md",spacing:"xs",p:"md",mb:"sm",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[r(v.Controller,{control:o,name:"label_field",render:({field:g})=>r(O,{label:"Label Key",required:!0,...g})}),r(v.Controller,{control:o,name:"value_field",render:({field:g})=>r(O,{label:"Value Key",required:!0,...g})}),r(v.Controller,{control:o,name:"color_field",render:({field:g})=>r(O,{label:"Color Key",clearable:!0,...g})})]})]})})}function Py(t){const{color_field:e="",...n}=t;return{...n,color_field:e}}function Ly(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=u=>u&&`${n}.${u}`,{label_field:a,value_field:o,color_field:l}=t;return{label_field:i(a),value_field:i(o),color_field:i(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class By extends se{constructor(){super(...arguments);P(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:Py(n.config)})),this.version(3,(n,i)=>({...n,version:3,config:Ly(n.config,i)}))}}const Oy={displayName:"Pie Chart",displayGroup:"ECharts-based charts",migrator:new By,name:"pie",viewRender:zy,configRender:Ey,createConfig(){return{version:3,config:x.cloneDeep(Jr)}},triggers:[Ds]};function $y(t){return r(z,{})}function Vy(t){return r(s.Text,{children:"Click heat block"})}const Is={id:"builtin:echarts:click-radar-chart:series",displayName:"Click radar chart series",nameRender:Vy,configRender:$y,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"}]},Bn={series_name_key:"",additional_series:[],background:{enabled:!0},label:{enabled:!0},dimensions:[]};function Ms(t){return t?e=>{try{return W(e).format(t)}catch(n){return console.error(n),e}}:e=>e}function As(t){return{show:t.label.enabled,formatter:({dimensionIndex:e,value:n})=>Ms(t.dimensions[e].formatter)(n)}}function zs(t,e){return e.map(({data_key:n})=>{const i=A(n);return t[i.columnKey]})}function Ny(t,e,n){const i=A(e);return t[i.queryID].map(a=>({value:zs(a,n),name:a[i.columnKey]}))}function qy(t,e){const{series_name_key:n,dimensions:i}=e;return[{type:"radar",name:"main-radar",data:Ny(t,n,i),symbolSize:4,lineStyle:{width:1},emphasis:{lineStyle:{width:4}},areaStyle:e.background.enabled?{opacity:.4}:void 0,label:As(e)}]}function Gy(t,e){const{additional_series:n,dimensions:i}=e;return n.map(o=>{const l=A(o.name_key),u=A(o.color_key);return{type:"radar",colorBy:"data",data:t[l.queryID].map(h=>{const f=h[l.columnKey],g=h[u.columnKey];return{name:f,value:zs(h,i),itemStyle:{color:g}}}),symbolSize:4,lineStyle:{width:1},emphasis:{lineStyle:{width:4}},areaStyle:e.background.enabled?{opacity:.4}:void 0,label:As(e)}}).flat()}function Fy(t,e){return[...qy(t,e),...Gy(t,e)]}function jy(t){return({name:e,marker:n,value:i})=>{if(i.length===0)return"";const a=i.map((o,l)=>{const u=t.dimensions[l],c=Ms(u.formatter);return`
|
|
200
200
|
<tr>
|
|
201
201
|
<td style="padding-left: 18px;">${u.name}</td>
|
|
202
202
|
<td style="text-align: right; "><strong>${c(o)}</strong></td>
|
|
@@ -216,7 +216,7 @@ Check the top-level render call using <`+V+">.")}return z}}function Ou(S,z){{if(
|
|
|
216
216
|
text-align: left;
|
|
217
217
|
vertical-align: top;
|
|
218
218
|
"
|
|
219
|
-
>${
|
|
219
|
+
>${e}</strong>
|
|
220
220
|
</th>
|
|
221
221
|
</tr>
|
|
222
222
|
</thead>
|
|
@@ -224,7 +224,7 @@ Check the top-level render call using <`+V+">.")}return z}}function Ou(S,z){{if(
|
|
|
224
224
|
${a.join("")}
|
|
225
225
|
</tbody>
|
|
226
226
|
</table>
|
|
227
|
-
`}}const Xy={legend:{show:!0,bottom:0,left:0},tooltip:{trigger:"item"}},Jy=["#66B4DB","#39BFA2","#E46464","#33A678","#EEBA00","#9D88CB","#939943","#E49792","#09A2B8","#AF5F6B","#6CA157","#09A2B8","#6398C7","#E692BA","#97B566","#8CACE2","#CA79AC","#6DBC80","#B08F4B","#826BAF"];function Zy(e,t){const{series_name_key:n,dimensions:r,additional_series:a}=e;if(!n||r.length===0)return{};const l={radar:{indicator:r.map(({name:u,max:c})=>({name:u,max:c})),splitArea:{show:!1}},tooltip:{confine:!0,backgroundColor:"rgba(255,255,255,0.6)",formatter:Ky(e)},legend:{show:!0,bottom:0,left:"center",type:"scroll"},series:Uy(t,e),color:Jy};return x.merge({},Xy,l)}ie.use([he.RadarChart,F.GridComponent,F.LegendComponent,F.TooltipComponent,ze.CanvasRenderer]);function Hy({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=m.useMemo(()=>{const{queryID:h,columnKey:g}=P(e.series_name_key),y=x.keyBy(t[h],g),C=e.additional_series.reduce((w,_)=>{const D=P(_.name_key),M=x.keyBy(t[D.queryID],D.columnKey);return{...w,...M}},y);return{...y,...C}},[t,e.series_name_key,e.additional_series]),u=Ke(a.triggerManager,So.id),c=m.useCallback(h=>{const g=x.get(l,h.name,{error:"rowData is not found"});u.forEach(y=>{a.runInteraction(y.id,{...h,rowData:g})})},[l,u,a]),d=m.useMemo(()=>({click:c}),[c]),f=m.useMemo(()=>Zy(x.defaultsDeep({},e,er),t),[e,t]);return!n||!r?null:i(Ae,{echarts:ie,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function eb({context:e,instance:t}){const n=Xe({vizManager:e.vizManager,instance:t}),{value:r}=R(e.instanceData,"config"),{variables:a}=e,o=m.useMemo(()=>x.defaults({},r,er),[r]),l=e.data,{width:u,height:c}=e.viewport;return!u||!c||!o||x.isEmpty(o==null?void 0:o.dimensions)?null:i(Be,{width:u,height:c,children:i(Hy,{variables:a,width:tt(u),height:nt(c),data:l,conf:o,interactionManager:n})})}function tb({control:e,index:t,remove:n}){return p(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`additional_series.${t}.name_key`,control:e,render:({field:r})=>i(W,{label:"Series Name Key",required:!0,sx:{flex:1},...r})})}),i(s.Stack,{children:i(v.Controller,{name:`additional_series.${t}.color_key`,control:e,render:({field:r})=>i(W,{label:"Color Key",required:!0,clearable:!0,sx:{flex:1},...r})})}),i(s.Button,{mt:20,leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),children:"Delete"})]})}function nb({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"additional_series"}),o=t("additional_series"),l=n.map((g,y)=>({...g,...o[y]})),u=()=>{const g=new Date().getTime().toString();r({id:g,name_key:"",color_key:""})},c=x.get(l,"0.id",null),[d,f]=m.useState(c);m.useEffect(()=>{f(g=>g||c)},[c]);const h=g=>{a(g);const y=x.get(l,"0.id",null);f(y)};return p(B,{children:[p(s.Alert,{icon:i(E.IconInfoCircle,{size:16}),title:"Additional Series",children:["By setting ",i(s.Mark,{children:"Series Name Key"}),", you may add series from more queries to the chart."]}),p(s.Tabs,{value:d,onTabChange:f,styles:{tab:{paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[l.map((g,y)=>i(s.Tabs.Tab,{value:g.id,children:y+1},g.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(E.IconPlus,{size:18,color:"#228be6"})})]}),l.map((g,y)=>i(s.Tabs.Panel,{value:g.id,children:i(tb,{control:e,index:y,remove:h})},g.id))]})]})}function rb({control:e,index:t,remove:n}){return p(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,align:"top",children:[i(v.Controller,{name:`dimensions.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`dimensions.${t}.data_key`,control:e,render:({field:r})=>i(W,{label:"Data Key",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`dimensions.${t}.max`,control:e,rules:{validate:r=>{if(Number.isNaN(Number(r)))return"A number is required"}},render:({field:r,fieldState:a})=>{var o;return i(s.TextInput,{label:"Max",required:!0,sx:{flex:1},...r,error:(o=a.error)==null?void 0:o.message})}})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Formatter",labelPosition:"center"}),i(v.Controller,{name:`dimensions.${t}.formatter`,control:e,render:({field:r})=>i(Ge,{...r})})]}),i(s.Button,{mt:20,leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this Metric"})]})}function ib({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"dimensions"}),o=t("dimensions"),l=n.map((g,y)=>({...g,...o[y]})),u=()=>{const g=new Date().getTime().toString();r({id:g,name:g,data_key:"",max:"100",formatter:De})},c=x.get(l,"0.id",null),[d,f]=m.useState(c);m.useEffect(()=>{f(g=>g||c)},[c]);const h=g=>{a(g);const y=x.get(l,"0.id",null);f(y)};return i(B,{children:p(s.Tabs,{value:d,onTabChange:f,styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[l.map((g,y)=>i(s.Tabs.Tab,{value:g.id,children:g.name?g.name:y+1},g.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(E.IconPlus,{size:18,color:"#228be6"})})]}),l.map((g,y)=>i(s.Tabs.Panel,{value:g.id,children:i(rb,{control:e,index:y,remove:h})},g.id))]})})}function ab({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=m.useMemo(()=>x.defaultsDeep({},t,er),[t]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c,formState:d}=v.useForm({defaultValues:r,mode:"all"});m.useEffect(()=>{c(r)},[r]),l(["series_name_key","background","label"]);const f=u(),h=m.useMemo(()=>!x.isEqual(f,r),[f,r]);return i("form",{onSubmit:o(n),children:p(s.Stack,{spacing:"xs",children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Radar Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h||!d.isValid,children:i(I.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"series",children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"series",children:"Series"}),i(s.Tabs.Tab,{value:"metrics",children:"Metrics"}),i(s.Tabs.Tab,{value:"style",children:"Style"}),i(s.Tabs.Tab,{value:"additional_series",ml:"auto",children:"Additional Series"})]}),i(s.Tabs.Panel,{value:"series",p:"md",children:i(v.Controller,{name:"series_name_key",control:a,render:({field:g})=>i(W,{label:"Series Name Field",required:!0,sx:{flex:1},...g})})}),i(s.Tabs.Panel,{value:"metrics",p:"md",children:i(ib,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"style",p:"md",children:p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"background.enabled",control:a,render:({field:g})=>i(s.Checkbox,{label:"Show background",checked:g.value,onChange:y=>g.onChange(y.currentTarget.checked)})}),i(v.Controller,{name:"label.enabled",control:a,render:({field:g})=>i(s.Checkbox,{label:"Show value label",checked:g.value,onChange:y=>g.onChange(y.currentTarget.checked)})})]})}),i(s.Tabs.Panel,{value:"additional_series",p:"md",children:i(nb,{control:a,watch:l})})]})]})})}function sb(e){const{dimensions:t=[],...n}=e;function r({name:a="",data_key:o="",max:l=10,formatter:u=De}){return{name:a,data_key:o,max:l,formatter:u}}return{...n,dimensions:t.map(r)}}function ob(e){const{dimensions:t=[],...n}=e;return{...n,dimensions:t.map(r=>({...r,id:r.id??r.name}))}}function lb(e){const t={background:{enabled:!0},label:{enabled:!0}};return x.defaultsDeep(t,e)}function ub(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{series_name_key:a,dimensions:o,...l}=e;return{...l,series_name_key:r(a),dimensions:o.map(u=>({...u,data_key:r(u.data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}function cb(e){const t={additional_series:[]};return x.defaultsDeep(t,e)}function db(e){const t={...e,dimensions:e.dimensions.map(n=>({...n,max:String(n.max)}))};return delete t.additionalSeries,t}class pb extends ge{constructor(){super(...arguments);q(this,"VERSION",7)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{config:r}=n;return{...n,version:2,config:sb(r)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:ob(r)}}),this.version(4,n=>{const{config:r}=n;return{...n,version:4,config:lb(r)}}),this.version(5,(n,r)=>{const{config:a}=n;return{...n,version:5,config:ub(a,r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:cb(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:db(r)}})}}const hb={displayName:"Radar Chart",displayGroup:"ECharts-based charts",migrator:new pb,name:"radar",viewRender:eb,configRender:ab,createConfig:()=>({version:7,config:er}),triggers:[So]};function fb(e,t){const{plot:n,transform:r}=e.regression;return t.map(a=>({...n,id:`reg-for-${a.name}`,name:a.name,data:Zn(r,a.data),color:a.color,showSymbol:!1,smooth:!0,tooltip:{show:!1},custom:{type:"regression-line",targetSeries:a.name}}))}function Do(e,t){const n=P(e.x_axis.data_key),r=P(e.regression.y_axis_data_key);return x.uniqBy(t.map(a=>[a[n.columnKey],a[r.columnKey]]),0)}function gb(e,t){const{plot:n,transform:r}=e.regression,a=Do(e,t);return[{type:"scatter",name:e.y_axis.name,data:a,symbolSize:4,color:"red",markLine:{...n,data:[Zn(r,a)],color:"blue",smooth:!0,silent:!0,symbol:["none","none"]}}]}function mb(e,t){const{plot:n,transform:r,group_by_key:a}=e.regression,o=P(a),l=x.groupBy(t,o.columnKey);return Object.entries(l).map(([u,c])=>{const d=Do(e,c);return{type:"scatter",name:u,data:d,symbolSize:4,markLine:{...n,data:[Zn(r,d)],smooth:!0,silent:!0,symbol:["none","none"]}}})}function yb(e,t){if(t.length===0)return[];const{group_by_key:n}=e.regression;return n?mb(e,t):gb(e,t)}function bb(e){return Array.isArray(e)||(e=[e]),e.map(t=>({marker:t.marker,label:t.seriesName,x:t.value[0],y:t.value[1]}))}function vb(e){return{confine:!0,trigger:"axis",formatter:t=>{const n=bb(t);return n.length===0?"":`
|
|
227
|
+
`}}const Wy={legend:{show:!0,bottom:0,left:0},tooltip:{trigger:"item"}},Ry=["#66B4DB","#39BFA2","#E46464","#33A678","#EEBA00","#9D88CB","#939943","#E49792","#09A2B8","#AF5F6B","#6CA157","#09A2B8","#6398C7","#E692BA","#97B566","#8CACE2","#CA79AC","#6DBC80","#B08F4B","#826BAF"];function Qy(t,e){const{series_name_key:n,dimensions:i,additional_series:a}=t;if(!n||i.length===0)return{};const l={radar:{indicator:i.map(({name:u,max:c})=>({name:u,max:c})),splitArea:{show:!1}},tooltip:{confine:!0,backgroundColor:"rgba(255,255,255,0.6)",formatter:jy(t)},legend:{show:!0,bottom:0,left:"center",type:"scroll"},series:Fy(e,t),color:Ry};return x.merge({},Wy,l)}Y.use([re.RadarChart,B.GridComponent,B.LegendComponent,B.TooltipComponent,_e.CanvasRenderer]);function Uy({conf:t,data:e,width:n,height:i,interactionManager:a,variables:o}){const l=m.useMemo(()=>{const{queryID:f,columnKey:g}=A(t.series_name_key),b=x.keyBy(e[f],g),w=t.additional_series.reduce((_,D)=>{const L=A(D.name_key),N=x.keyBy(e[L.queryID],L.columnKey);return{..._,...N}},b);return{...b,...w}},[e,t.series_name_key,t.additional_series]),u=Ne(a.triggerManager,Is.id),c=m.useCallback(f=>{const g=x.get(l,f.name,{error:"rowData is not found"});u.forEach(b=>{a.runInteraction(b.id,{...f,rowData:g})})},[l,u,a]),p=m.useMemo(()=>({click:c}),[c]),h=m.useMemo(()=>Qy(x.defaultsDeep({},t,Bn),e),[t,e]);return!n||!i?null:r(Se,{echarts:Y,option:h,style:{width:n,height:i},onEvents:p,notMerge:!0,theme:"merico-light"})}function Ky({context:t,instance:e}){const n=qe({vizManager:t.vizManager,instance:e}),{value:i}=V(t.instanceData,"config"),{variables:a}=t,o=m.useMemo(()=>x.defaults({},i,Bn),[i]),l=t.data,{width:u,height:c}=t.viewport;return!u||!c||!o||x.isEmpty(o==null?void 0:o.dimensions)?null:r(Me,{width:u,height:c,children:r(Uy,{variables:a,width:Re(u),height:Qe(c),data:l,conf:o,interactionManager:n})})}function Yy({control:t,index:e,remove:n}){return d(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[r(s.Group,{grow:!0,noWrap:!0,children:r(v.Controller,{name:`additional_series.${e}.name_key`,control:t,render:({field:i})=>r(O,{label:"Series Name Key",required:!0,sx:{flex:1},...i})})}),r(s.Stack,{children:r(v.Controller,{name:`additional_series.${e}.color_key`,control:t,render:({field:i})=>r(O,{label:"Color Key",required:!0,clearable:!0,sx:{flex:1},...i})})}),r(s.Button,{mt:20,leftIcon:r(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),children:"Delete"})]})}function Xy({control:t,watch:e}){const{fields:n,append:i,remove:a}=v.useFieldArray({control:t,name:"additional_series"}),o=e("additional_series"),l=n.map((g,b)=>({...g,...o[b]})),u=()=>{const g=new Date().getTime().toString();i({id:g,name_key:"",color_key:""})},c=x.get(l,"0.id",null),[p,h]=m.useState(c);m.useEffect(()=>{h(g=>g||c)},[c]);const f=g=>{a(g);const b=x.get(l,"0.id",null);h(b)};return d(z,{children:[d(s.Alert,{icon:r(M.IconInfoCircle,{size:16}),title:"Additional Series",children:["By setting ",r(s.Mark,{children:"Series Name Key"}),", you may add series from more queries to the chart."]}),d(s.Tabs,{value:p,onTabChange:h,styles:{tab:{paddingBottom:"0px"},panel:{padding:"0px"}},children:[d(s.Tabs.List,{children:[l.map((g,b)=>r(s.Tabs.Tab,{value:g.id,children:b+1},g.id)),r(s.Tabs.Tab,{onClick:u,value:"add",children:r(M.IconPlus,{size:18,color:"#228be6"})})]}),l.map((g,b)=>r(s.Tabs.Panel,{value:g.id,children:r(Yy,{control:t,index:b,remove:f})},g.id))]})]})}function Jy({control:t,index:e,remove:n}){return d(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[d(s.Group,{grow:!0,noWrap:!0,align:"top",children:[r(v.Controller,{name:`dimensions.${e}.name`,control:t,render:({field:i})=>r(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})}),r(v.Controller,{name:`dimensions.${e}.data_key`,control:t,render:({field:i})=>r(O,{label:"Data Key",required:!0,sx:{flex:1},...i})}),r(v.Controller,{name:`dimensions.${e}.max`,control:t,rules:{validate:i=>{if(Number.isNaN(Number(i)))return"A number is required"}},render:({field:i,fieldState:a})=>{var o;return r(s.TextInput,{label:"Max",required:!0,sx:{flex:1},...i,error:(o=a.error)==null?void 0:o.message})}})]}),d(s.Stack,{children:[r(s.Divider,{mb:-15,variant:"dashed",label:"Value Formatter",labelPosition:"center"}),r(v.Controller,{name:`dimensions.${e}.formatter`,control:t,render:({field:i})=>r(Pe,{...i})})]}),r(s.Button,{mt:20,leftIcon:r(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),disabled:e===0,children:"Delete this Metric"})]})}function Zy({control:t,watch:e}){const{fields:n,append:i,remove:a}=v.useFieldArray({control:t,name:"dimensions"}),o=e("dimensions"),l=n.map((g,b)=>({...g,...o[b]})),u=()=>{const g=new Date().getTime().toString();i({id:g,name:g,data_key:"",max:"100",formatter:xe})},c=x.get(l,"0.id",null),[p,h]=m.useState(c);m.useEffect(()=>{h(g=>g||c)},[c]);const f=g=>{a(g);const b=x.get(l,"0.id",null);h(b)};return r(z,{children:d(s.Tabs,{value:p,onTabChange:h,styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[d(s.Tabs.List,{children:[l.map((g,b)=>r(s.Tabs.Tab,{value:g.id,children:g.name?g.name:b+1},g.id)),r(s.Tabs.Tab,{onClick:u,value:"add",children:r(M.IconPlus,{size:18,color:"#228be6"})})]}),l.map((g,b)=>r(s.Tabs.Panel,{value:g.id,children:r(Jy,{control:t,index:b,remove:f})},g.id))]})})}function Hy({context:t}){const{value:e,set:n}=V(t.instanceData,"config"),i=m.useMemo(()=>x.defaultsDeep({},e,Bn),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c,formState:p}=v.useForm({defaultValues:i,mode:"all"});m.useEffect(()=>{c(i)},[i]),l(["series_name_key","background","label"]);const h=u(),f=m.useMemo(()=>!x.isEqual(h,i),[h,i]);return r("form",{onSubmit:o(n),children:d(s.Stack,{spacing:"xs",children:[d(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(s.Text,{children:"Radar Config"}),r(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f||!p.isValid,children:r(T.DeviceFloppy,{size:20})})]}),d(s.Tabs,{defaultValue:"series",children:[d(s.Tabs.List,{children:[r(s.Tabs.Tab,{value:"series",children:"Series"}),r(s.Tabs.Tab,{value:"metrics",children:"Metrics"}),r(s.Tabs.Tab,{value:"style",children:"Style"}),r(s.Tabs.Tab,{value:"additional_series",ml:"auto",children:"Additional Series"})]}),r(s.Tabs.Panel,{value:"series",p:"md",children:r(v.Controller,{name:"series_name_key",control:a,render:({field:g})=>r(O,{label:"Series Name Field",required:!0,sx:{flex:1},...g})})}),r(s.Tabs.Panel,{value:"metrics",p:"md",children:r(Zy,{control:a,watch:l})}),r(s.Tabs.Panel,{value:"style",p:"md",children:d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"background.enabled",control:a,render:({field:g})=>r(s.Checkbox,{label:"Show background",checked:g.value,onChange:b=>g.onChange(b.currentTarget.checked)})}),r(v.Controller,{name:"label.enabled",control:a,render:({field:g})=>r(s.Checkbox,{label:"Show value label",checked:g.value,onChange:b=>g.onChange(b.currentTarget.checked)})})]})}),r(s.Tabs.Panel,{value:"additional_series",p:"md",children:r(Xy,{control:a,watch:l})})]})]})})}function eb(t){const{dimensions:e=[],...n}=t;function i({name:a="",data_key:o="",max:l=10,formatter:u=xe}){return{name:a,data_key:o,max:l,formatter:u}}return{...n,dimensions:e.map(i)}}function tb(t){const{dimensions:e=[],...n}=t;return{...n,dimensions:e.map(i=>({...i,id:i.id??i.name}))}}function nb(t){const e={background:{enabled:!0},label:{enabled:!0}};return x.defaultsDeep(e,t)}function rb(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=u=>u&&`${n}.${u}`,{series_name_key:a,dimensions:o,...l}=t;return{...l,series_name_key:i(a),dimensions:o.map(u=>({...u,data_key:i(u.data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}function ib(t){const e={additional_series:[]};return x.defaultsDeep(e,t)}function ab(t){const e={...t,dimensions:t.dimensions.map(n=>({...n,max:String(n.max)}))};return delete e.additionalSeries,e}class sb extends se{constructor(){super(...arguments);P(this,"VERSION",7)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{config:i}=n;return{...n,version:2,config:eb(i)}}),this.version(3,n=>{const{config:i}=n;return{...n,version:3,config:tb(i)}}),this.version(4,n=>{const{config:i}=n;return{...n,version:4,config:nb(i)}}),this.version(5,(n,i)=>{const{config:a}=n;return{...n,version:5,config:rb(a,i)}}),this.version(6,n=>{const{config:i}=n;return{...n,version:6,config:ib(i)}}),this.version(7,n=>{const{config:i}=n;return{...n,version:7,config:ab(i)}})}}const ob={displayName:"Radar Chart",displayGroup:"ECharts-based charts",migrator:new sb,name:"radar",viewRender:Ky,configRender:Hy,createConfig:()=>({version:7,config:Bn}),triggers:[Is]};function lb(t,e){const{plot:n,transform:i}=t.regression;return e.map(a=>({...n,id:`reg-for-${a.name}`,name:a.name,data:Pn(i,a.data),color:a.color,showSymbol:!1,smooth:!0,tooltip:{show:!1},custom:{type:"regression-line",targetSeries:a.name}}))}function Es(t,e){const n=A(t.x_axis.data_key),i=A(t.regression.y_axis_data_key);return x.uniqBy(e.map(a=>[a[n.columnKey],a[i.columnKey]]),0)}function ub(t,e){const{plot:n,transform:i}=t.regression,a=Es(t,e);return[{type:"scatter",name:t.y_axis.name,data:a,symbolSize:4,color:"red",markLine:{...n,data:[Pn(i,a)],color:"blue",smooth:!0,silent:!0,symbol:["none","none"]}}]}function cb(t,e){const{plot:n,transform:i,group_by_key:a}=t.regression,o=A(a),l=x.groupBy(e,o.columnKey);return Object.entries(l).map(([u,c])=>{const p=Es(t,c);return{type:"scatter",name:u,data:p,symbolSize:4,markLine:{...n,data:[Pn(i,p)],smooth:!0,silent:!0,symbol:["none","none"]}}})}function db(t,e){if(e.length===0)return[];const{group_by_key:n}=t.regression;return n?cb(t,e):ub(t,e)}function pb(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 hb(t){return{confine:!0,trigger:"axis",formatter:e=>{const n=pb(e);return n.length===0?"":`
|
|
228
228
|
<table style="width: auto">
|
|
229
229
|
<thead>
|
|
230
230
|
<tr>
|
|
@@ -234,73 +234,73 @@ Check the top-level render call using <`+V+">.")}return z}}function Ou(S,z){{if(
|
|
|
234
234
|
</thead>
|
|
235
235
|
<tbody>
|
|
236
236
|
<tr>
|
|
237
|
-
<th style="text-align: left; padding: 0 .5em;">${
|
|
237
|
+
<th style="text-align: left; padding: 0 .5em;">${t.x_axis.name}</th>
|
|
238
238
|
${n.map(({x:a})=>`<td style="text-align: right; padding: 0 .5em;">${a}</td>`).join("")}
|
|
239
239
|
</tr>
|
|
240
240
|
<tr>
|
|
241
|
-
<th style="text-align: left; padding: 0 .5em;">${
|
|
241
|
+
<th style="text-align: left; padding: 0 .5em;">${t.y_axis.name}</th>
|
|
242
242
|
${n.map(({y:a})=>`<td style="text-align: right; padding: 0 .5em;">${a}</td>`).join("")}
|
|
243
243
|
</tr>
|
|
244
244
|
</tbody>
|
|
245
245
|
</table>
|
|
246
|
-
`}}}function
|
|
247
|
-
`)},
|
|
246
|
+
`}}}function Ps({enabled:t,func_content:e}){return(n,i)=>{if(!t)return n;try{return new Function(`return ${e}`)()(n,i)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function fb(t){const{overflow:e,format:n,formatter:i,...a}=t.x_axis.axisLabel,o=Ue(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=W(l).format(n)}catch{}return Ps(i)(c,u)}}}}const gb={tooltip:{trigger:"axis"},grid:{top:50,left:5,right:10,bottom:20,containLabel:!0},dataZoom:[{type:"inside",xAxisIndex:[0]},{type:"inside",yAxisIndex:[0]}]};function mb(t,e){const n=db(t,e),i=lb(t,n),a={xAxis:fb(t),yAxis:{name:t.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"left"},nameGap:5,axisLine:{show:!0}},series:[...n,...i],tooltip:hb(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,gb)}function On(t,e,n){return 1-(1-t)*(e-1)/(e-n-1)}function yb(t,e,n,i){const{x_axis:a,y_axis:o}=i,l=ct.regressionLinear()(n),{a:u,b:c,rSquared:p}=l;return{name:t,expression:d(s.Group,{position:"center",noWrap:!0,spacing:10,children:[r(s.Text,{children:o.name}),r(s.Text,{children:"="}),r(s.Text,{weight:"bold",color:"red",children:W(c).format({mantissa:2,trimMantissa:!0})}),r(s.Text,{children:"+"}),r(s.Text,{weight:"bold",color:"red",children:W(u).format({mantissa:2,trimMantissa:!0})}),r(s.Text,{children:"×"}),r(s.Text,{children:a.name})]}),rSquared:p,adjustedRSquared:On(p,e.length,1)}}function bb(t,e,n,i){const{x_axis:a,y_axis:o}=i,{a:l,b:u,rSquared:c}=ct.regressionExp()(n);return{name:t,expression:d(s.Group,{position:"center",noWrap:!0,spacing:10,children:[r(s.Text,{children:o.name}),r(s.Text,{children:"="}),r(s.Text,{weight:"bold",color:"gray",children:l}),r(s.Text,{children:"×"}),d(s.Group,{position:"left",noWrap:!0,spacing:2,children:[r(s.Text,{children:"Math.exp("}),r(s.Text,{weight:"bold",color:"gray",children:u}),r(s.Text,{children:"×"}),r(s.Text,{children:a.name}),r(s.Text,{children:")"})]})]}),rSquared:c,adjustedRSquared:On(c,e.length,1)}}function vb(t,e,n,i){const{x_axis:a,y_axis:o}=i,{a:l,b:u,rSquared:c}=ct.regressionLog()(n);return{name:t,expression:d(s.Group,{position:"center",noWrap:!0,spacing:10,children:[r(s.Text,{children:o.name}),r(s.Text,{children:"="}),r(s.Text,{weight:"bold",color:"gray",children:l}),r(s.Text,{children:"×"}),d(s.Group,{position:"left",noWrap:!0,spacing:2,children:[r(s.Text,{children:"Math.log("}),r(s.Text,{children:a.name}),r(s.Text,{children:")"}),r(s.Text,{children:"+"}),r(s.Text,{weight:"bold",color:"gray",children:u})]})]}),rSquared:c,adjustedRSquared:On(c,e.length,1)}}function xb(t,e,n,i){const{x_axis:a,y_axis:o,regression:l}=i,u=ct.regressionPoly().order(l.transform.config.order)(n),{rSquared:c}=u;return console.log(u),{name:t,expression:"",rSquared:c,adjustedRSquared:On(c,e.length,1)}}function Ls(t,e,n){const{regression:i,x_axis:a}=n,o=A(a.data_key),l=A(i.y_axis_data_key),u=e.map(c=>[c[o.columnKey],c[l.columnKey]]);return i.transform.config.method==="linear"?yb(t,e,u,n):i.transform.config.method==="exponential"?bb(t,e,u,n):i.transform.config.method==="logarithmic"?vb(t,e,u,n):i.transform.config.method==="polynomial"?xb(t,e,u,n):{name:t,expression:"",rSquared:0,adjustedRSquared:0}}function wb(t,e){if(!e)return[{name:"",expression:"",rSquared:0,adjustedRSquared:0}];if(!e.regression.group_by_key)return[Ls("",t,e)];const n=A(e.regression.group_by_key),i=x.groupBy(t,n.columnKey);return Object.entries(i).map(([a,o])=>Ls(a,o,e))}const Cb={marginTop:"10px","tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function Bs({desc:t}){const{expression:e,rSquared:n,adjustedRSquared:i}=t;return e?r(s.Table,{fontSize:14,sx:Cb,children:d("tbody",{children:[r("tr",{children:r("td",{colSpan:2,children:r(s.Text,{align:"center",children:e})})}),d("tr",{children:[r("td",{children:"R-Sq"}),r("td",{style:{textAlign:"right"},children:W(n).format({output:"percent",mantissa:1})})]}),d("tr",{children:[r("td",{children:"R-Sq(Adjusted)"}),r("td",{style:{textAlign:"right"},children:W(i).format({output:"percent",mantissa:1})})]})]})}):r(s.Text,{children:"Unavailable for this regression method"})}function Sb({conf:t,queryData:e}){var i;const n=m.useMemo(()=>wb(e,t),[t,e]);return t.regression.group_by_key?(console.log(n),d(s.Tabs,{defaultValue:(i=n[0])==null?void 0:i.name,color:"gray",children:[r(s.Tabs.List,{grow:!0,children:n.map(a=>r(s.Tabs.Tab,{value:a.name,children:a.name},a.name))}),n.map(a=>r(s.Tabs.Panel,{value:a.name,children:r(Bs,{desc:a})},a.name))]})):r(Bs,{desc:n[0]})}function _b({conf:t,queryData:e}){return d(s.HoverCard,{shadow:"md",withinPortal:!0,zIndex:320,children:[r(s.HoverCard.Target,{children:r(s.Button,{size:"xs",variant:"subtle",compact:!0,leftIcon:r(M.IconInfoCircle,{size:14}),children:"Regression Info"})}),r(s.HoverCard.Dropdown,{children:r(ke,{children:r(Sb,{conf:t,queryData:e})})})]})}function kb(t){return r(s.Group,{position:"apart",sx:{position:"absolute",top:0,left:Ie.left,right:Ie.right,height:"22px",zIndex:1},children:r(_b,{...t})})}const $n={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
247
|
+
`)},Zr={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,format:xe,overflow:Le,formatter:{...$n}}},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"}};Y.use([B.DataZoomComponent,re.ScatterChart,B.GridComponent,B.LegendComponent,B.TooltipComponent,_e.CanvasRenderer]);function Tb({context:t}){const{value:e}=V(t.instanceData,"config"),{width:n,height:i}=t.viewport,a=m.useMemo(()=>{var b;const c=t.data,p=e==null?void 0:e.x_axis.data_key,h=(b=e==null?void 0:e.regression)==null?void 0:b.y_axis_data_key;if(!p||!h)return[];const f=A(p),g=A(h);return c[f.queryID].map(w=>typeof w[g.columnKey]=="number"?w:{...w,[g.columnKey]:Number(w[g.columnKey])})},[t.data,e==null?void 0:e.regression.y_axis_data_key]),o=m.useMemo(()=>mb(x.defaultsDeep({},e,Zr),a),[e,a]),l=m.useRef(null),u=c=>{l.current=c};return!n||!i||!e?null:d(Me,{width:n,height:i,children:[r(kb,{conf:e,queryData:a}),r(Se,{echarts:Y,onChartReady:u,option:o,style:jt(n,i),notMerge:!0,theme:"merico-light"})]})}const Db=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}];function Ib({control:t,watch:e}){e("regression");const n=e("regression.transform.config.method"),i=e("regression.group_by_key");return d(s.Stack,{children:[r(s.Group,{grow:!0,noWrap:!0,children:r(v.Controller,{name:"regression.name",control:t,render:({field:a})=>r(s.TextInput,{label:"回归线名称",sx:{flex:1},...a})})}),r(v.Controller,{name:"regression.group_by_key",control:t,render:({field:a})=>r(O,{label:"按此字段将数据分为多个系列",clearable:!0,sx:{flex:1},...a})}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"regression.transform.config.method",control:t,render:({field:a})=>r(s.Select,{label:"回归方法",data:Db,sx:{flex:1},...a})}),n==="polynomial"&&r(v.Controller,{name:"regression.transform.config.order",control:t,render:({field:a})=>r(s.NumberInput,{label:"次",sx:{flex:1},...a})})]}),!i&&d(s.Stack,{spacing:4,children:[r(s.Text,{size:"sm",children:"颜色"}),r(v.Controller,{name:"regression.plot.color",control:t,render:({field:a})=>r(Te,{...a})})]})]})}const Mb=({disabled:t,value:e,onChange:n})=>{const i=a=>{a&&n(a)};return d(s.Box,{sx:{position:"relative"},children:[t&&r(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),r(ve,{height:"500px",defaultLanguage:"javascript",value:e,onChange:i,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},Os=m.forwardRef(({value:t,onChange:e,triggerButtonText:n="Customize Label"},i)=>{const[a,{setTrue:o,setFalse:l}]=q.useBoolean(),[u,c]=m.useState(t);m.useEffect(()=>{c(t)},[t]);const p=w=>{c({...u,enabled:w})},h=()=>{l();const{enabled:w,func_content:_}=u,D={enabled:w,func_content:_};c(D),e(D)},f=()=>{l(),c(t)},g=w=>{c(_=>({..._,func_content:w}))},b=()=>{g($n.func_content)};return d(z,{children:[r(s.Button,{variant:"filled",mt:24,onClick:o,sx:{flexGrow:0},children:n}),r(s.Modal,{size:800,title:"Customize label content",opened:a,onClose:l,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:a&&d(s.Stack,{children:[r(s.Checkbox,{mt:10,label:"Enabled",checked:u.enabled,onChange:w=>p(w.currentTarget.checked)}),r(Mb,{value:u.func_content,onChange:g,disabled:!u.enabled}),d(s.Group,{position:"apart",children:[r(s.Button,{onClick:b,color:"red",leftIcon:r(T.Recycle,{size:20}),children:"Reset"}),d(s.Group,{position:"right",children:[r(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),r(s.Button,{onClick:h,children:"OK"})]})]})]})})]})});function Ab({control:t,watch:e}){return e(["x_axis"]),d(s.Stack,{children:[d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>r(s.TextInput,{label:"X轴名称",sx:{flex:1},...n})}),r(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>r(O,{label:"X轴数据字段",required:!0,sx:{flex:1},...n})})]}),r(s.Divider,{variant:"dashed",labelPosition:"center",label:"格式化数据"}),r(s.Stack,{children:r(v.Controller,{name:"x_axis.axisLabel.format",control:t,render:({field:n})=>r(Pe,{...n})})}),r(s.Divider,{variant:"dashed",labelPosition:"center",label:"标签文案样式"}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>r(s.NumberInput,{label:"旋转",hideControls:!0,min:-90,max:90,rightSection:r(s.Text,{color:"dimmed",children:"度"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),r(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>r(Os,{triggerButtonText:"自定义标签文案内容",...n})})]}),r(v.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>r(Je,{...n})})]})}function zb({control:t,watch:e}){return e(["y_axis","regression.y_axis_data_key"]),r(s.Stack,{children:d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"y_axis.name",control:t,render:({field:n})=>r(s.TextInput,{label:"Y轴名称",sx:{flex:1},...n})}),r(v.Controller,{name:"regression.y_axis_data_key",control:t,render:({field:n})=>r(O,{label:"Y轴数据字段",required:!0,sx:{flex:1},...n})})]})})}function Eb({context:t}){const{value:e,set:n}=V(t.instanceData,"config"),i=m.useMemo(()=>x.defaults({},e,Zr),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:i});m.useEffect(()=>{c(i)},[i]),l(["x_axis","y_axis","regression"]);const p=u(),h=m.useMemo(()=>!x.isEqual(p,e),[p,e]);return r(s.Stack,{spacing:"xs",children:d("form",{onSubmit:o(n),children:[d(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(s.Text,{children:"Chart Config"}),r(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:r(T.DeviceFloppy,{size:20})})]}),d(s.Tabs,{defaultValue:"X轴",orientation:"vertical",styles:{panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[d(s.Tabs.List,{children:[r(s.Tabs.Tab,{value:"X轴",children:"X轴"}),r(s.Tabs.Tab,{value:"Y轴",children:"Y轴"}),r(s.Tabs.Tab,{value:"回归",children:"回归"})]}),r(s.Tabs.Panel,{value:"X轴",children:r(Ab,{watch:l,control:a})}),r(s.Tabs.Panel,{value:"Y轴",children:r(zb,{watch:l,control:a})}),r(s.Tabs.Panel,{value:"回归",children:r(Ib,{control:a,watch:l})})]})]})})}function Pb(t){const e={x_axis:{axisLabel:{rotate:0,format:xe,overflow:Le,formatter:$n}},regression:{group_by_key:""}};return x.defaultsDeep(e,t)}function Lb(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=u=>u&&`${n}.${u}`,{x_axis:a,regression:o,...l}=t;return{...l,x_axis:{...a,data_key:i(a.data_key)},regression:{...o,group_by_key:i(o.group_by_key),y_axis_data_key:i(o.y_axis_data_key)}}}catch(n){throw console.error("[Migration failed]",n),n}}class Bb extends se{constructor(){super(...arguments);P(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:Pb(n.config)})),this.version(3,(n,i)=>{const{config:a}=n;return{...n,version:3,config:Lb(a,i)}})}}const Ob={displayName:"Regression Chart",displayGroup:"Merico suite",migrator:new Bb,name:"regressionChart",viewRender:Tb,configRender:Eb,createConfig(){return{version:3,config:x.cloneDeep(Zr)}}},Vn={content:""};function $b(t,e){const n={};return t.forEach(i=>{const{name:a,data_field:o,aggregation:l}=i,u=In(e,o,l);n[a]=Fe(i,u)}),n}function Vb(t){const e=document.createElement("span");return e.innerHTML=t,e.innerText}function Nb(t,e,n){try{return new Function("payload",`
|
|
248
248
|
const filters = payload.filters;
|
|
249
249
|
const context = payload.context;
|
|
250
|
-
${Object.entries(
|
|
250
|
+
${Object.entries(e).map(([i,a])=>`const ${i} = '${a}';`).join(`
|
|
251
251
|
`)}
|
|
252
|
-
return ${
|
|
253
|
-
`)(n)}catch(
|
|
254
|
-
`)}}
|
|
255
|
-
`)},
|
|
252
|
+
return ${t};
|
|
253
|
+
`)(n)}catch(i){return console.error(i),console.log(t),t}}function qb(t,e,n,i){const a=$b(e,i),o=/^(.+)\}\}(.*)$/;return t.split("{{").map(l=>{const u=o.exec(l);if(!u)return l;const c=a[u[1]];if(c){const h=u[2]??"";return`${c}${h}`}const p=Vb(u[1]);return`${Nb(p,a,n)}${u[2]}`}).join("")}const Gb=k.observer(({context:t})=>{const e=ue(),{value:n}=V(t.instanceData,"config"),{variables:i,data:a}=t,o=m.useMemo(()=>{const l=x.defaults({},n,Vn);return l.content?qb(l.content,i,e.payloadForViz,a):""},[n,i,e.payloadForViz]);return o?r(Dn,{value:o,styles:{root:{border:"none",height:"100%"},content:{padding:0}}}):null});function Fb(){const{editor:t}=j.useRichTextEditorContext();return r(j.RichTextEditor.Control,{onClick:()=>t==null?void 0:t.commands.insertTable({rows:3,cols:3,withHeaderRow:!0}),"aria-label":"Insert table",title:"Insert table",children:r(M.IconBorderAll,{stroke:1.5,size:16})})}const Hr=m.forwardRef(({value:t,onChange:e,styles:n={},label:i,onSubmit:a},o)=>{const[l,u]=m.useState(t),c=ra.useEditor({extensions:[ia,na,j.Link,Yi,Ki,Qi,Zi.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),ta,ea,Hi,Xi.configure({types:["heading","paragraph"]}),Ui.configure({placeholder:"This is placeholder"}),Ji,Ri.Color,cs],content:l,onUpdate:({editor:g})=>{u(g.getHTML())}});m.useEffect(()=>{u(t),c==null||c.commands.setContent(t)},[t]);const p=()=>{e(l),a==null||a()},h=t!==l,f=m.useMemo(()=>x.defaultsDeep({},{content:wr},n),[n]);return c?d(s.Stack,{spacing:4,sx:{flexGrow:1,position:"relative"},children:[d(s.Group,{align:"center",children:[r(s.Text,{size:14,fw:500,children:i}),r(s.ActionIcon,{color:"blue",disabled:!h,onClick:p,children:r(M.IconDeviceFloppy,{size:18})})]}),d(j.RichTextEditor,{editor:c,styles:f,children:[d(j.RichTextEditor.Toolbar,{sticky:!0,stickyOffset:0,children:[r(j.RichTextEditor.ControlsGroup,{children:r(j.RichTextEditor.ColorPicker,{colors:["#25262b","#868e96","#fa5252","#e64980","#be4bdb","#7950f2","#4c6ef5","#228be6","#15aabf","#12b886","#40c057","#82c91e","#fab005","#fd7e14"],popoverProps:{zIndex:320}})}),d(j.RichTextEditor.ControlsGroup,{children:[r(j.RichTextEditor.Bold,{}),r(j.RichTextEditor.Italic,{}),r(j.RichTextEditor.Underline,{}),r(j.RichTextEditor.ClearFormatting,{}),r(j.RichTextEditor.Highlight,{}),r(j.RichTextEditor.Code,{})]}),d(j.RichTextEditor.ControlsGroup,{children:[r(j.RichTextEditor.H1,{}),r(j.RichTextEditor.H2,{}),r(j.RichTextEditor.H3,{}),r(j.RichTextEditor.H4,{})]}),d(j.RichTextEditor.ControlsGroup,{children:[r(j.RichTextEditor.Blockquote,{}),r(j.RichTextEditor.Hr,{}),r(j.RichTextEditor.BulletList,{}),r(j.RichTextEditor.OrderedList,{}),r(j.RichTextEditor.Subscript,{}),r(j.RichTextEditor.Superscript,{})]}),d(j.RichTextEditor.ControlsGroup,{children:[r(j.RichTextEditor.Link,{}),r(j.RichTextEditor.Unlink,{})]}),d(j.RichTextEditor.ControlsGroup,{children:[r(j.RichTextEditor.AlignLeft,{}),r(j.RichTextEditor.AlignCenter,{}),r(j.RichTextEditor.AlignJustify,{}),r(j.RichTextEditor.AlignRight,{})]}),r(j.RichTextEditor.ControlsGroup,{children:r(Fb,{})}),r(th,{editor:c})]}),r(j.RichTextEditor.Content,{})]})]}):null});function jb({context:t}){const{value:e,set:n}=V(t.instanceData,"config"),i=m.useMemo(()=>x.defaults({},e,Vn),[e]),{control:a,handleSubmit:o,watch:l,reset:u}=v.useForm({defaultValues:i});l("content"),m.useEffect(()=>{u(i)},[i]);const c=m.useRef(null),p=()=>{var h;return(h=c.current)==null?void 0:h.click()};return r("form",{onSubmit:o(n),style:{flexGrow:1,display:"flex",flexDirection:"column"},children:d(s.Stack,{spacing:"xs",sx:{flexGrow:1},children:[d(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",display:"none"},children:[r(s.Text,{children:"Content"}),r(s.ActionIcon,{ref:c,type:"submit",mr:5,variant:"filled",color:"blue",children:r(T.DeviceFloppy,{size:20})})]}),r(v.Controller,{name:"content",control:a,render:({field:h})=>r(Hr,{...h,styles:{root:{flexGrow:1}},label:"Content",onSubmit:p})})]})})}class Wb extends se{constructor(){super(...arguments);P(this,"VERSION",1)}fixMalformedConfig(n){return x.defaults({},n,Vn)}configVersions(){this.version(1,n=>({version:1,config:this.fixMalformedConfig(n)}))}}const Rb={displayName:"Rich Text",displayGroup:"Others",migrator:new Wb,name:"richText",viewRender:Gb,configRender:jb,createConfig(){return{version:1,config:x.cloneDeep(Vn)}}},en={static:{type:"static",color:rt.random().css()},dynamic:{type:"dynamic",func_content:["function getColor({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here",' // return "blue"',"}"].join(`
|
|
254
|
+
`)}},$s={id:"builtin:echarts:click-scatter-chart:series",displayName:"Click Scatter",nameRender:Ub,configRender:Qb,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 Qb(t){return r(z,{})}function Ub(t){return r(s.Text,{children:"Click scatter"})}const Vs={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
255
|
+
`)},Ns={label:Le.on_axis,tooltip:Le.in_tooltip},ei={scatter:{y_data_key:"",name_data_key:"",symbolSize:{type:"static",size:10},color:en.static,label_position:"right",label_overflow:Ns},stats:{templates:{top:"",bottom:""}},x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...Vs}}},y_axes:[{name:"Y Axis",position:"left",nameAlignment:"center",label_formatter:xe,min:"",max:"",show:!0}],tooltip:{trigger:"item",metrics:[]},reference_lines:[],reference_areas:[],dataZoom:zt};function Kb(t,e){if(!t.x_axis.data_key)return[];const n=A(t.x_axis.data_key);return[{source:e[n.queryID]}]}function Yb(t){const e=t.y_axes.some(a=>!!a.name);let n=15;e&&(n+=20),t.dataZoom.x_axis_slider&&(n+=20);let i=5;return t.x_axis.name&&(i+=15),{top:n,bottom:i}}function Xb(){return{show:!1,bottom:0,left:"center",type:"scroll"}}function Nn(t,e){if(t)return e[t]??void 0}function Jb({reference_areas:t,variableValueMap:e}){const n=t.map(i=>[{name:i.content.text,value:i.content.text,itemStyle:i.itemStyle,label:i.label,xAxis:Nn(i.leftBottomPoint.x_data_key,e),yAxis:Nn(i.leftBottomPoint.y_data_key,e)},{xAxis:Nn(i.rightTopPoint.x_data_key,e),yAxis:Nn(i.rightTopPoint.y_data_key,e)}]);return{type:"scatter",name:"ref_areas",silent:!0,data:[],markArea:{data:n}}}function Zb({type:t,...e},n){if(!t)return 10;if(t==="static"){const{size:a}=e;return a}const{func_content:i}=e;return(a,o)=>{const l=o.data;try{return new Function(`return ${i}`)()({rowData:l,params:o,variables:n},{lodash:x,interpolate:ft.interpolate})}catch(u){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${u.message}`),10}}}function Hb({type:t,...e},n){if(!t)return en.static.color;if(t==="static"){const{color:a}=e;return a}const{func_content:i}=e;return({value:a})=>{try{return new Function(`return ${i}`)()({rowData:a,variables:n},{lodash:x,interpolate:ft.interpolate})}catch(o){return console.error(`[getSeriesColor] failed parsing custom function, error: ${o.message}`),10}}}function ev(t,e,n,i){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?zn(a.template,e,i):""},position:u}}}})}function tv({x_axis:t,scatter:e},n){const i=A(t.data_key),a=A(e.y_data_key),o=A(e.name_data_key);return{label:{show:!!e.label_position,position:e.label_position,...Ue(e.label_overflow.label),formatter:({value:l})=>l[o.columnKey]},type:"scatter",name:"",xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{color:Hb(e.color,n)},symbolSize:Zb(e.symbolSize,n),encode:{x:i.columnKey,y:a.columnKey}}}function nv(t,e,n,i){return[tv(t,i)].concat(ev(t.reference_lines,n,i,e)).concat(Jb({reference_areas:t.reference_areas,variableValueMap:i}))}function qs({enabled:t,func_content:e}){return(n,i)=>{if(!t)return n;try{return new Function(`return ${e}`)()(n,i)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function Gs(t,e,n){const{x_axis:i}=n;return i.axisLabel.formatter.enabled?qs(i.axisLabel.formatter)(t,e):t}function rv(t,e){const{x_axis:n,tooltip:i}=e;if(i.trigger==="item"){const u=dn(t[0].data,n.data_key);return Gs(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 Gs(o,l,e)}const iv=t=>{try{return W(t).format({trimMantissa:!0,mantissa:2})}catch{return t}};function av(t,e){const{scatter:n,tooltip:i}=t;return{confine:!0,trigger:i.trigger,formatter:function(a){const o=e[0]??e.default,l=Array.isArray(a)?a:[a];if(l.length===0)return"";const u=rv(l,t),c=Ze(t.scatter.label_overflow.tooltip),p=l.map(({value:b})=>`
|
|
256
256
|
<th style="text-align: right; padding-right: 1em">
|
|
257
|
-
<div style="${c}">${
|
|
257
|
+
<div style="${c}">${dn(b,n.name_data_key)}</div>
|
|
258
258
|
</th>
|
|
259
|
-
`);
|
|
260
|
-
<th style="text-align: right;">${
|
|
261
|
-
${l.map(
|
|
259
|
+
`);p.unshift("<th></th>");const h=[`<tr>
|
|
260
|
+
<th style="text-align: right;">${t.x_axis.name}</th>
|
|
261
|
+
${l.map(b=>`<td style="text-align: right; padding: 0 1em;">${u}</td>`).join("")}
|
|
262
262
|
</tr>`,`<tr>
|
|
263
|
-
<th style="text-align: right;">${
|
|
264
|
-
${l.map(({value:
|
|
263
|
+
<th style="text-align: right;">${t.y_axes[0].name}</th>
|
|
264
|
+
${l.map(({value:b})=>`
|
|
265
265
|
<td style="text-align: right; padding: 0 1em;">
|
|
266
|
-
${o(
|
|
266
|
+
${o(dn(b,n.y_data_key))}
|
|
267
267
|
</td>`).join("")}
|
|
268
|
-
</tr>`],
|
|
269
|
-
<th style="text-align: right;">${
|
|
270
|
-
${l.map(({value:
|
|
271
|
-
</tr>`);return
|
|
268
|
+
</tr>`],f=t.tooltip.metrics.map(b=>`<tr>
|
|
269
|
+
<th style="text-align: right;">${b.name}</th>
|
|
270
|
+
${l.map(({value:w})=>`<td style="text-align: right; padding: 0 1em;">${iv(dn(w,b.data_key))}</td>`).join("")}
|
|
271
|
+
</tr>`);return h.push(...f),`
|
|
272
272
|
<table style="width: auto">
|
|
273
|
-
<thead><tr>${
|
|
274
|
-
<tbody>${
|
|
273
|
+
<thead><tr>${p.join("")}</tr></thead>
|
|
274
|
+
<tbody>${h.join("")}</tbody>
|
|
275
275
|
</table>
|
|
276
|
-
`}}}function pv(e,t){const n=t.every(a=>!Number.isNaN(Number(a))),{axisLabel:r}=e.x_axis;return[{data:t,name:e.x_axis.name??"",id:"main-x-axis",axisTick:{show:!0,alignWithLabel:!0},type:n?"value":"category",axisLabel:{...r,formatter:Po(r.formatter)}}]}function hv(e,t){return e.y_axes.map(({nameAlignment:n,min:r,max:a,...o},l)=>{let u=o.position;return u||(u=l>0?"right":"left"),{...o,minInterval:1,min:r||void 0,max:a||void 0,position:u,axisLabel:{show:!0,formatter:t[l]??t.default},axisLine:{show:!0},nameTextStyle:{fontWeight:"bold",align:n},nameLocation:"end",nameGap:15,splitLine:{show:!1}}})}const fv={xAxis:[{type:"category",nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0}}],grid:{top:10,left:20,right:15,bottom:25,containLabel:!0}};function gv(e,t,n){const r=n.reduce((c,d)=>{const f=yt(d,t);return c[d.name]=Ze(d,f),c},{}),a=e.y_axes.reduce((c,{label_formatter:d},f)=>(c[f]=function(g){let y=g;if(typeof g=="object"&&(Array.isArray(g.value)&&g.value.length===2?y=g.value[1]:y=g.value),!d)return y;try{return Z(y).format(d)}catch(C){return console.error(C),y}},c),{default:({value:c})=>c}),o=x.uniq(gt(t,e.x_axis.data_key)),l=lv(e,t,n,r),u={xAxis:pv(e,o),yAxis:hv(e,a),series:l,dataset:ev(e,t),tooltip:dv(e,a),grid:tv(e),legend:nv(),dataZoom:ai(e.dataZoom)};return x.defaultsDeep({},u,fv)}ie.use([F.DataZoomComponent,he.BarChart,he.LineChart,he.ScatterChart,F.GridComponent,F.LegendComponent,F.TooltipComponent,ze.CanvasRenderer,F.MarkLineComponent,F.MarkAreaComponent]);function Bo(e){return e.trim().length>0}function mv({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=zt(t,e.x_axis.data_key),u=Ke(a.triggerManager,Eo.id),c=m.useCallback(h=>{const g=h.data;u.forEach(y=>{a.runInteraction(y.id,{...h,rowData:g})})},[l,u,a]),d=m.useMemo(()=>({click:c}),[c]),f=m.useMemo(()=>gv(e,t,o),[e,t]);return i(Ae,{echarts:ie,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function yv({context:e,instance:t}){const n=Xe({vizManager:e.vizManager,instance:t}),{value:r}=R(e.instanceData,"config"),{variables:a}=e,o=m.useMemo(()=>x.defaults({},r,yi),[r]),l=e.data,{width:u,height:c}=e.viewport,{ref:d,height:f}=_e.useElementSize(),{ref:h,height:g}=_e.useElementSize(),y=m.useMemo(()=>{const{stats:{templates:w}}=o;return{top:yn(w.top,a,l),bottom:yn(w.bottom,a,l)}},[o,l]),C=Math.max(0,nt(c)-f-g);return!u||!c?null:p(Be,{width:u,height:c,children:[i(s.Text,{ref:d,align:"left",size:"xs",pl:"sm",sx:{display:Bo(o.stats.templates.top)?"block":"none"},children:Object.values(y.top).map(w=>w)}),i(mv,{variables:a,width:tt(u),height:C,data:l,conf:o,interactionManager:n}),i(s.Text,{ref:h,align:"left",size:"xs",pl:"sm",sx:{display:Bo(o.stats.templates.bottom)?"block":"none"},children:Object.values(y.bottom).map(w=>w)})]})}const bv=m.forwardRef(({value:e,onChange:t,xAxisOptions:n,yAxisOptions:r,variableOptions:a},o)=>{const l=(u,c)=>{const d=x.cloneDeep(e);x.set(d,u,c),t(d)};return p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Content",labelPosition:"right"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(s.TextInput,{label:"Content Text",value:e.content.text,onChange:u=>l("content.text",u.currentTarget.value)}),i(ci,{label:"Text Position",value:e.label.position,onChange:u=>l("label.position",u)})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Endpoints",labelPosition:"right"}),p(s.Group,{grow:!0,noWrap:!0,children:[n&&i(s.Select,{label:"X Axis",data:n,value:e.xAxisIndex,onChange:u=>l("xAxisIndex",u)}),r&&i(s.Select,{label:"Y Axis",data:r,value:e.yAxisIndex,onChange:u=>l("xAxisIndex",u)})]}),p(s.Stack,{spacing:0,children:[i(s.Text,{size:14,color:"#212529",fw:500,children:"Left-Bottom Point"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(s.Select,{icon:i(s.Text,{children:"x"}),data:a,value:e.leftBottomPoint.x_data_key,onChange:u=>l("leftBottomPoint.x_data_key",u??""),clearable:!0}),i(s.Select,{icon:i(s.Text,{children:"y"}),data:a,value:e.leftBottomPoint.y_data_key,onChange:u=>l("leftBottomPoint.y_data_key",u??""),clearable:!0})]})]}),p(s.Stack,{spacing:0,children:[i(s.Text,{size:14,color:"#212529",fw:500,children:"Right-Top Point"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(s.Select,{icon:i(s.Text,{children:"x"}),data:a,value:e.rightTopPoint.x_data_key,onChange:u=>l("rightTopPoint.x_data_key",u??""),clearable:!0}),i(s.Select,{icon:i(s.Text,{children:"y"}),data:a,value:e.rightTopPoint.y_data_key,onChange:u=>l("rightTopPoint.y_data_key",u??""),clearable:!0})]})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Style",labelPosition:"right"}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:14,children:"Background Color"}),i($e,{value:e.itemStyle.color,onChange:u=>l("itemStyle.color",u)})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:14,children:"Text Color"}),i($e,{value:e.label.color,onChange:u=>l("label.color",u)})]})]})});function vv(){const e=new Date().getTime().toString();return{id:e,content:{text:e},itemStyle:{color:"rgba(0,0,0,0.05)"},label:{position:"inside",color:"rgba(0,0,0,0.5)"},leftBottomPoint:{x_data_key:"",y_data_key:""},rightTopPoint:{x_data_key:"",y_data_key:""},xAxisIndex:"0",yAxisIndex:"0"}}function xv({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_areas"}),l=t("reference_areas"),u=r.map((g,y)=>({...g,...l[y]})),c=()=>{const g=vv();a(g)},d=m.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=t("y_axes"),h=m.useMemo(()=>f.map(({name:g},y)=>({label:g,value:y.toString()})),[f]);return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[u.map((g,y)=>i(s.Tabs.Tab,{value:y.toString(),children:y+1},g.id)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),u.map((g,y)=>i(s.Tabs.Panel,{value:y.toString(),children:i(v.Controller,{name:`reference_areas.${y}`,control:e,render:({field:C})=>p(s.Stack,{children:[i(bv,{variableOptions:d,yAxisOptions:h,...C}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(E.IconTrash,{size:16}),color:"red",variant:"light",onClick:()=>o(y),children:"Delete this Reference Area"})]})})},g.id))]})}const wv=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Cv=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Sv({control:e,index:t,remove:n,watch:r,variableOptions:a,yAxisOptions:o}){const l=r(`reference_lines.${t}.orientation`);return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:u})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:u})=>i(s.Select,{label:"Value",required:!0,data:a,sx:{flex:1},...u})})]}),i(v.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:u})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...u})}),p(s.Group,{grow:!0,children:[p(s.Stack,{children:[i(v.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:u})=>i(s.Select,{label:"Orientation",data:Cv,required:!0,sx:{flex:1},...u})}),l==="vertical"&&i(s.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&i(v.Controller,{name:`reference_lines.${t}.yAxisIndex`,control:e,render:({field:{value:u,onChange:c,...d}})=>i(s.Select,{label:"Y Axis",data:o,disabled:o.length===0,...d,value:(u==null?void 0:u.toString())??"",onChange:f=>{if(!f){c(0);return}c(Number(f))},sx:{flex:1}})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:u})=>i(s.Select,{label:"Line Type",data:wv,sx:{flexGrow:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:u})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...u})})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:u})=>i($e,{...u})})]}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]})}function _v({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=r.map((g,y)=>({...g,...l[y]})),c=()=>{const g={name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:ht.random().css()},show_in_legend:!1,yAxisIndex:0};a(g)},d=m.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=t("y_axes"),h=m.useMemo(()=>f.map(({name:g},y)=>({label:g,value:y.toString()})),[f]);return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[u.map((g,y)=>i(s.Tabs.Tab,{value:y.toString(),children:y+1},g.id)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),u.map((g,y)=>i(s.Tabs.Panel,{value:y.toString(),children:i(Sv,{control:e,index:y,remove:o,watch:t,variableOptions:d,yAxisOptions:h})},g.id))]})}const kv=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return i(s.Box,{children:i(Te,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Tv=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:a}]=Q.useBoolean(),[o,l]=m.useState(e),u=()=>{a();const{type:h,func_content:g}=o,y={type:h,func_content:g};l(y),t(y)},c=()=>{a(),l(e)},d=h=>{l(g=>({...g,func_content:h}))},f=()=>{d(bn.dynamic.func_content)};return p(B,{children:[i(s.Box,{sx:{width:"50%"},children:i(s.Button,{variant:"filled",mt:24,onClick:r,sx:{flexGrow:0},children:"Setup"})}),i(s.Modal,{size:800,title:"Setup dynamic color",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&p(s.Stack,{children:[i(s.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),i(kv,{value:o.func_content,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:c,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:u,children:"OK"})]})]})]})})]})},Dv=({value:e,onChange:t})=>e.type!=="dynamic"?null:i(Tv,{value:e,onChange:t}),Iv=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=r=>{t({...e,color:r})};return i(s.ColorInput,{label:" ",format:"rgb",value:e.color,onChange:n})},Mv=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Av=m.forwardRef(({label:e="Color",value:t,onChange:n},r)=>{const a=o=>{n({...bn[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:e,data:Mv,value:t.type,onChange:a,sx:{flexGrow:1}}),i(Iv,{value:t,onChange:n}),i(Dv,{value:t,onChange:n})]})}),zv=m.forwardRef(({value:e,onChange:t},n)=>{const r=o=>{t({...e,label:o})},a=o=>{t({...e,tooltip:o})};return p(s.Stack,{ref:n,spacing:0,children:[i(En,{sectionTitle:"Overflow on Chart",value:e.label,onChange:r}),i(En,{sectionTitle:"Overflow in Tooltip",value:e.tooltip,onChange:a})]})}),Ev=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return i(s.Box,{children:i(Te,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Vo={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
|
|
277
|
-
`)}},$v=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:a}]=Q.useBoolean(),[o,l]=m.useState(e),u=()=>{a();const{type:h,func_content:g}=o,y={type:h,func_content:g};l(y),t(y)},c=()=>{a(),l(e)},d=h=>{l(g=>({...g,func_content:h}))},f=()=>{d(Vo.dynamic.func_content)};return p(B,{children:[i(s.Box,{sx:{width:"50%"},children:i(s.Button,{variant:"filled",mt:24,onClick:r,sx:{flexGrow:0},children:"Setup"})}),i(s.Modal,{size:800,title:"Setup dynamic size",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&p(s.Stack,{children:[i(s.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),i(Ev,{value:o.func_content,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:c,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:u,children:"OK"})]})]})]})})]})},Lv=({value:e,onChange:t})=>e.type!=="dynamic"?null:i($v,{value:e,onChange:t}),Pv=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=r=>{t({...e,size:r})};return i(B,{children:i(s.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:e.size,onChange:n})})},Ov=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Bv=m.forwardRef(({label:e="Size",value:t,onChange:n},r)=>{const a=o=>{n({...Vo[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:e,data:Ov,value:t.type,onChange:a,sx:{flexGrow:1}}),i(Pv,{value:t,onChange:n}),i(Lv,{value:t,onChange:n})]})}),Vv=[{label:"off",value:""},{label:"top",value:"top"},{label:"left",value:"left"},{label:"right",value:"right"},{label:"bottom",value:"bottom"},{label:"inside",value:"inside"},{label:"insideLeft",value:"insideLeft"},{label:"insideRight",value:"insideRight"},{label:"insideTop",value:"insideTop"},{label:"insideBottom",value:"insideBottom"},{label:"insideTopLeft",value:"insideTopLeft"},{label:"insideBottomLeft",value:"insideBottomLeft"},{label:"insideTopRight",value:"insideTopRight"},{label:"insideBottomRight",value:"insideBottomRight"}];function Nv({control:e,watch:t}){return t(["scatter"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"scatter.name_data_key",control:e,render:({field:n})=>i(W,{label:"Name Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"scatter.y_data_key",control:e,render:({field:n})=>i(W,{label:"Value Data Field",required:!0,sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Style",labelPosition:"center"}),i(v.Controller,{name:"scatter.symbolSize",control:e,render:({field:n})=>i(Bv,{label:"Size",...n})}),i(v.Controller,{name:"scatter.color",control:e,render:({field:n})=>i(Av,{...n})}),i(s.Divider,{mb:-15,label:"Label",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"scatter.label_position",control:e,render:({field:n})=>i(s.Select,{label:"Label Position",data:Vv,...n})})}),i(v.Controller,{name:"scatter.label_overflow",control:e,render:({field:n})=>i(zv,{...n})})]})}function qv({control:e,watch:t}){return t("stats"),i(s.Stack,{children:p(s.Stack,{spacing:0,children:[i(v.Controller,{name:"stats.templates.top",control:e,render:({field:n})=>i(un,{label:"Template for stats above the chart",py:"md",sx:{flexGrow:1},...n})}),i(v.Controller,{name:"stats.templates.bottom",control:e,render:({field:n})=>i(un,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const Fv=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),Gv=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[d,f]=m.useState(()=>c??null);return m.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(B,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(I.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(Fv,{control:e,index:g,remove:a},h.id)},h.id))]})]})},Wv=[{label:"Scatter Point",value:"item"},{label:"X Axis",value:"axis"}];function jv({control:e,watch:t}){return t("tooltip.trigger"),p(s.Stack,{children:[i(v.Controller,{name:"tooltip.trigger",control:e,render:({field:n})=>i(s.Select,{label:"Trigger",data:Wv,sx:{flexGrow:1},...n})}),i(s.Divider,{variant:"dashed"}),i(Gv,{control:e,watch:t})]})}const Rv=({disabled:e,value:t,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[e&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Te,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},Yv=m.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:a,setFalse:o}]=Q.useBoolean(),[l,u]=m.useState(e);m.useEffect(()=>{u(e)},[e]);const c=y=>{u({...l,enabled:y})},d=()=>{o();const{enabled:y,func_content:C}=l,w={enabled:y,func_content:C};u(w),t(w)},f=()=>{o(),u(e)},h=y=>{u(C=>({...C,func_content:y}))},g=()=>{h($o.func_content)};return p(B,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Customize Label"}),i(s.Modal,{size:800,title:"Customize label content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:y=>c(y.currentTarget.checked)}),i(Rv,{value:l.func_content,onChange:h,disabled:!l.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:g,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:d,children:"OK"})]})]})]})})]})});function Qv({control:e,watch:t}){return t(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>i(Yv,{...n})})]})]})}const Uv=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],Kv=[{label:"left",value:"left"},{label:"right",value:"right"}];function Xv({control:e,index:t,remove:n}){return p(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[i(s.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`y_axes.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`y_axes.${t}.nameAlignment`,control:e,render:({field:r})=>i(s.Select,{label:"Align",required:!0,data:Uv,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`y_axes.${t}.position`,control:e,render:({field:r})=>i(s.Select,{label:"Position",required:!0,data:Kv,sx:{flex:1},...r})})}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:`y_axes.${t}.label_formatter`,control:e,render:({field:r})=>i(Ge,{...r})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`y_axes.${t}.min`,control:e,render:({field:r})=>i(s.TextInput,{label:"Min",...r})}),i(v.Controller,{name:`y_axes.${t}.max`,control:e,render:({field:r})=>i(s.TextInput,{label:"Max",...r})})]})]}),i(s.Button,{mt:20,leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this YAxis"})]})}function Jv({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"y_axes"}),o=t("y_axes"),l=n.map((c,d)=>({...c,...o[d]})),u=()=>r({name:"",label_formatter:De,min:"",max:"",show:!0,position:"right",nameAlignment:"right"});return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[l.map((c,d)=>i(s.Tabs.Tab,{value:d.toString(),children:d+1},c.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((c,d)=>i(s.Tabs.Panel,{value:d.toString(),children:i(Xv,{control:e,index:d,remove:a})},c.id))]})}function Zv(e){return e||{templates:{top:"",bottom:""}}}function Hv({reference_lines:e=[],stats:t,...n}){return{reference_lines:e,stats:Zv(t),...n}}function ex({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),{variables:r}=e,a=m.useMemo(()=>x.defaultsDeep({},t,yi),[t]),o=m.useMemo(()=>Hv(a),[a]);m.useEffect(()=>{!x.isEqual(a,o)&&(console.log("config malformed, resetting to defaults",a,o),n(o))},[a,o]);const{control:l,handleSubmit:u,watch:c,getValues:d,reset:f}=v.useForm({defaultValues:o});m.useEffect(()=>{f(o)},[o]);const h=d(),g=m.useMemo(()=>!x.isEqual(h,a),[h,a]);return c(["dataZoom"]),i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:u(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!g,children:i(I.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axes",children:"Y Axes"}),i(s.Tabs.Tab,{value:"Scatter",children:"Scatter"}),i(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"}),i(s.Tabs.Tab,{value:"Stats",children:"Stats"}),i(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"}),i(s.Tabs.Tab,{value:"Reference Areas",children:"Reference Areas"}),i(s.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(Qv,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Y Axes",children:i(Jv,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Scatter",children:i(Nv,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(jv,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Stats",children:i(qv,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(_v,{variables:r,control:l,watch:c})}),i(s.Tabs.Panel,{value:"Reference Areas",children:i(xv,{variables:r,control:l,watch:c})}),i(s.Tabs.Panel,{value:"Zooming",children:i(v.Controller,{name:"dataZoom",control:l,render:({field:y})=>i(oi,{...y})})})]})]})})}function tx(e){const{dataZoom:t=Rt,...n}=e;return{...n,dataZoom:t}}function nx(e){const t={scatter:{label_overflow:Lo}};return x.defaultsDeep(t,e)}function rx(e){const{color:t}=e.scatter;return typeof t=="string"?{...e,scatter:{...e.scatter,color:{...bn.static,color:t}}}:e}function ix(e){const t=e.reference_lines.map(n=>{const{lineStyle:r={type:"dashed",width:1,color:ht.random().css()},show_in_legend:a=!1,yAxisIndex:o=0}=n;return{...n,lineStyle:r,show_in_legend:a,yAxisIndex:o}});return{...e,reference_lines:t}}function ax(e){const t={tooltip:{trigger:"item"}};return x.defaultsDeep({},e,t)}function sx(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,scatter:o,tooltip:l,...u}=e;return{...u,x_axis:{...a,data_key:r(a.data_key)},scatter:{...o,y_data_key:r(o.y_data_key),name_data_key:r(o.name_data_key)},tooltip:{...l,metrics:l.metrics.map(c=>({...c,data_key:r(c.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}class ox extends ge{constructor(){super(...arguments);q(this,"VERSION",9)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{tooltip:r={metrics:[]},...a}=n.config;return{...n,version:2,config:{...a,tooltip:r}}}),this.version(3,n=>({...n,version:3,config:tx(n.config)})),this.version(4,n=>{const{config:r}=n;return{...n,version:5,config:nx(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:rx(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:ix(r)}}),this.version(8,n=>{const{config:r}=n;return{...n,version:8,config:ax(r)}}),this.version(9,(n,r)=>{const{config:a}=n;return{...n,version:9,config:sx(a,r)}})}}const lx={displayName:"Scatter Chart",displayGroup:"ECharts-based charts",migrator:new ox,name:"scatterChart",viewRender:yv,configRender:ex,createConfig(){return{version:9,config:x.cloneDeep(yi)}},triggers:[Eo]},bi={template:"The variable ${value} is defined in Variables section",vertical_align:"center",horizontal_align:"left"};function ux(e){if("variables"in e)return e;const{align:t,size:n,weight:r,color:a,content:{prefix:o="",data_field:l="value",formatter:u={output:"number",mantissa:0},postfix:c=""}={}}=e;return{align:t,template:`${o} \${value} ${c}`,variables:[{name:"value",data_field:l,aggregation:{type:"none",config:{}},formatter:u,color:a,weight:r,size:n}]}}function cx(e){return x.omit(e,["variables"])}function dx(e){const{align:t,...n}=e;return{horizontal_align:t,vertical_align:"center",...n}}function px(e){const t=x.cloneDeep(e),n=x.get(t,"color.valueRange");return n!==void 0&&x.set(t,"color.valueRange",n.map(r=>Number(r))),t}class hx extends ge{constructor(){super(...arguments);q(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:ux(n)})),this.version(2,(n,{panelModel:r})=>{const{config:a}=n;return(a.variables||[]).forEach(l=>{r.variables.find(u=>u.name===l.name)||r.addVariable(px(l))}),{...n,version:2,config:cx(a)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:dx(r)}})}}const fx={left:"flex-start",center:"center",right:"flex-end"},gx={top:"flex-start",center:"center",bottom:"flex-end"},mx=k.observer(({context:e})=>{const t=ye(),{value:n=bi}=R(e.instanceData,"config"),{variables:r}=e,{template:a,horizontal_align:o,vertical_align:l}=n,{width:u,height:c}=e.viewport,d=m.useMemo(()=>{try{return x.template(a)(t.payloadForSQL)}catch{return a}},[t.payloadForSQL,a]),f=m.useMemo(()=>yn(d,r,e.data),[d,r,e.data,e]);return i(s.Center,{sx:{width:u,height:c,justifyContent:fx[o],alignItems:gx[l]},children:i(s.Box,{children:Object.values(f).map((h,g)=>i(m.Fragment,{children:h},g))})})}),yx=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],bx=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function vx({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=m.useMemo(()=>x.defaultsDeep({},t,bi),[t]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});m.useEffect(()=>{c(r)},[r]),l(["template","horizontal_align","vertical_align"]);const d=u(),f=m.useMemo(()=>!x.isEqual(d,t),[d,t]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{weight:500,children:"Stats Configurations"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(I.DeviceFloppy,{size:20})})]}),i(v.Controller,{name:"template",control:a,render:({field:h})=>i(un,{label:"Template",py:"md",sx:{flexGrow:1},...h})}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{name:"horizontal_align",control:a,render:({field:h})=>i(s.Select,{label:"Horizontal Alignment",data:yx,...h})}),i(v.Controller,{control:a,name:"vertical_align",render:({field:h})=>i(s.Select,{label:"Vertical Alignment",data:bx,...h})})]})]})})}const xx={createConfig(){return{version:3,config:bi}},displayName:"Stats",displayGroup:"Others",migrator:new hx,name:"stats",viewRender:mx,configRender:vx},vi={label_key:"",value_key:"",group_key:"",levels:[]};function wx(e){const t=new Set(e.map(r=>r.parent_id)),n=new Set(e.map(r=>r.id));return t.forEach(r=>{r===null||n.has(r)||e.push({id:r,name:r,parent_id:null})}),e}function Cx(e){const t=wx(e).map(a=>({...a,children:[]})),n=x.keyBy(t,a=>a.id),r=[];return t.forEach(a=>{if(!a.parent_id||!n[a.parent_id]){r.push(a);return}n[a.parent_id].children.push(a)}),r}function Sx(e,t){const{label_key:n,value_key:r,group_key:a}=e;if(!n||!r)return[];const o=P(n),l=P(r),u=P(a),c=t[o.queryID].map(d=>({...d,id:d[o.columnKey],parent_id:d[u.columnKey],name:d[o.columnKey],value:d[l.columnKey]?Number(d[l.columnKey]):d[l.columnKey]}));return a?Cx(c):c}const _x=e=>({treePathInfo:t,name:n,value:r})=>{if(t.length===1||!e)return n;try{const a=t[t.length-2].value;if(r/a<e)return" "}catch{return n}};function kx(e){const{levels:t}=e;return t.map(n=>{const{show_label_tolerance:r,...a}=n.label;return{...n,label:{...a,formatter:_x(r)}}})}function Tx(){return({treePathInfo:e,name:t,value:n,color:r,marker:a,...o})=>{const l=e.slice(0,e.length-1),u=[`<tr>
|
|
276
|
+
`}}}function sv(t,e){const n=e.every(a=>!Number.isNaN(Number(a))),{axisLabel:i}=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:{...i,formatter:qs(i.formatter)}}]}function ov(t,e){return t.y_axes.map(({nameAlignment:n,min:i,max:a,...o},l)=>{let u=o.position;return u||(u=l>0?"right":"left"),{...o,minInterval:1,min:i||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 lv={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 uv(t,e,n){const i=n.reduce((c,p)=>{const h=ot(p,e);return c[p.name]=Fe(p,h),c},{}),a=t.y_axes.reduce((c,{label_formatter:p},h)=>(c[h]=function(g){let b=g;if(typeof g=="object"&&(Array.isArray(g.value)&&g.value.length===2?b=g.value[1]:b=g.value),!p)return b;try{return W(b).format(p)}catch(w){return console.error(w),b}},c),{default:({value:c})=>c}),o=x.uniq(at(e,t.x_axis.data_key)),l=nv(t,e,n,i),u={xAxis:sv(t,o),yAxis:ov(t,a),series:l,dataset:Kb(t,e),tooltip:av(t,a),grid:Yb(t),legend:Xb(),dataZoom:Fr(t.dataZoom)};return x.defaultsDeep({},u,lv)}Y.use([B.DataZoomComponent,re.BarChart,re.LineChart,re.ScatterChart,B.GridComponent,B.LegendComponent,B.TooltipComponent,_e.CanvasRenderer,B.MarkLineComponent,B.MarkAreaComponent]);function Fs(t){return t.trim().length>0}function cv({conf:t,data:e,width:n,height:i,interactionManager:a,variables:o}){const l=yt(e,t.x_axis.data_key),u=Ne(a.triggerManager,$s.id),c=m.useCallback(f=>{const g=f.data;u.forEach(b=>{a.runInteraction(b.id,{...f,rowData:g})})},[l,u,a]),p=m.useMemo(()=>({click:c}),[c]),h=m.useMemo(()=>uv(t,e,o),[t,e]);return r(Se,{echarts:Y,option:h,style:{width:n,height:i},onEvents:p,notMerge:!0,theme:"merico-light"})}function dv({context:t,instance:e}){const n=qe({vizManager:t.vizManager,instance:e}),{value:i}=V(t.instanceData,"config"),{variables:a}=t,o=m.useMemo(()=>x.defaults({},i,ei),[i]),l=t.data,{width:u,height:c}=t.viewport,{ref:p,height:h}=ye.useElementSize(),{ref:f,height:g}=ye.useElementSize(),b=m.useMemo(()=>{const{stats:{templates:_}}=o;return{top:Ht(_.top,a,l),bottom:Ht(_.bottom,a,l)}},[o,l]),w=Math.max(0,Qe(c)-h-g);return!u||!c?null:d(Me,{width:u,height:c,children:[r(s.Text,{ref:p,align:"left",size:"xs",pl:"sm",sx:{display:Fs(o.stats.templates.top)?"block":"none"},children:Object.values(b.top).map(_=>_)}),r(cv,{variables:a,width:Re(u),height:w,data:l,conf:o,interactionManager:n}),r(s.Text,{ref:f,align:"left",size:"xs",pl:"sm",sx:{display:Fs(o.stats.templates.bottom)?"block":"none"},children:Object.values(b.bottom).map(_=>_)})]})}const pv=m.forwardRef(({value:t,onChange:e,xAxisOptions:n,yAxisOptions:i,variableOptions:a},o)=>{const l=(u,c)=>{const p=x.cloneDeep(t);x.set(p,u,c),e(p)};return d(s.Stack,{children:[r(s.Divider,{mb:-15,variant:"dashed",label:"Content",labelPosition:"right"}),d(s.Group,{grow:!0,noWrap:!0,children:[r(s.TextInput,{label:"Content Text",value:t.content.text,onChange:u=>l("content.text",u.currentTarget.value)}),r(Ur,{label:"Text Position",value:t.label.position,onChange:u=>l("label.position",u)})]}),r(s.Divider,{mb:-15,variant:"dashed",label:"Endpoints",labelPosition:"right"}),d(s.Group,{grow:!0,noWrap:!0,children:[n&&r(s.Select,{label:"X Axis",data:n,value:t.xAxisIndex,onChange:u=>l("xAxisIndex",u)}),i&&r(s.Select,{label:"Y Axis",data:i,value:t.yAxisIndex,onChange:u=>l("xAxisIndex",u)})]}),d(s.Stack,{spacing:0,children:[r(s.Text,{size:14,color:"#212529",fw:500,children:"Left-Bottom Point"}),d(s.Group,{grow:!0,noWrap:!0,children:[r(s.Select,{icon:r(s.Text,{children:"x"}),data:a,value:t.leftBottomPoint.x_data_key,onChange:u=>l("leftBottomPoint.x_data_key",u??""),clearable:!0}),r(s.Select,{icon:r(s.Text,{children:"y"}),data:a,value:t.leftBottomPoint.y_data_key,onChange:u=>l("leftBottomPoint.y_data_key",u??""),clearable:!0})]})]}),d(s.Stack,{spacing:0,children:[r(s.Text,{size:14,color:"#212529",fw:500,children:"Right-Top Point"}),d(s.Group,{grow:!0,noWrap:!0,children:[r(s.Select,{icon:r(s.Text,{children:"x"}),data:a,value:t.rightTopPoint.x_data_key,onChange:u=>l("rightTopPoint.x_data_key",u??""),clearable:!0}),r(s.Select,{icon:r(s.Text,{children:"y"}),data:a,value:t.rightTopPoint.y_data_key,onChange:u=>l("rightTopPoint.y_data_key",u??""),clearable:!0})]})]}),r(s.Divider,{mb:-15,variant:"dashed",label:"Style",labelPosition:"right"}),d(s.Stack,{spacing:4,children:[r(s.Text,{size:14,children:"Background Color"}),r(Te,{value:t.itemStyle.color,onChange:u=>l("itemStyle.color",u)})]}),d(s.Stack,{spacing:4,children:[r(s.Text,{size:14,children:"Text Color"}),r(Te,{value:t.label.color,onChange:u=>l("label.color",u)})]})]})});function hv(){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 fv({control:t,watch:e,variables:n}){const{fields:i,append:a,remove:o}=v.useFieldArray({control:t,name:"reference_areas"}),l=e("reference_areas"),u=i.map((g,b)=>({...g,...l[b]})),c=()=>{const g=hv();a(g)},p=m.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),h=e("y_axes"),f=m.useMemo(()=>h.map(({name:g},b)=>({label:g,value:b.toString()})),[h]);return d(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[d(s.Tabs.List,{children:[u.map((g,b)=>r(s.Tabs.Tab,{value:b.toString(),children:b+1},g.id)),r(s.Tabs.Tab,{onClick:c,value:"add",children:r(T.Plus,{size:18,color:"#228be6"})})]}),u.map((g,b)=>r(s.Tabs.Panel,{value:b.toString(),children:r(v.Controller,{name:`reference_areas.${b}`,control:t,render:({field:w})=>d(s.Stack,{children:[r(pv,{variableOptions:p,yAxisOptions:f,...w}),r(s.Divider,{mb:-10,mt:10,variant:"dashed"}),r(s.Button,{leftIcon:r(M.IconTrash,{size:16}),color:"red",variant:"light",onClick:()=>o(b),children:"Delete this Reference Area"})]})})},g.id))]})}const gv=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],mv=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function yv({control:t,index:e,remove:n,watch:i,variableOptions:a,yAxisOptions:o}){const l=i(`reference_lines.${e}.orientation`);return d(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`reference_lines.${e}.name`,control:t,render:({field:u})=>r(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),r(v.Controller,{name:`reference_lines.${e}.variable_key`,control:t,render:({field:u})=>r(s.Select,{label:"Value",required:!0,data:a,sx:{flex:1},...u})})]}),r(v.Controller,{name:`reference_lines.${e}.template`,control:t,render:({field:u})=>r(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...u})}),d(s.Group,{grow:!0,children:[d(s.Stack,{children:[r(v.Controller,{name:`reference_lines.${e}.orientation`,control:t,render:({field:u})=>r(s.Select,{label:"Orientation",data:mv,required:!0,sx:{flex:1},...u})}),l==="vertical"&&r(s.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&r(v.Controller,{name:`reference_lines.${e}.yAxisIndex`,control:t,render:({field:{value:u,onChange:c,...p}})=>r(s.Select,{label:"Y Axis",data:o,disabled:o.length===0,...p,value:(u==null?void 0:u.toString())??"",onChange:h=>{if(!h){c(0);return}c(Number(h))},sx:{flex:1}})})]}),r(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),d(s.Group,{grow:!0,children:[r(v.Controller,{name:`reference_lines.${e}.lineStyle.type`,control:t,render:({field:u})=>r(s.Select,{label:"Line Type",data:gv,sx:{flexGrow:1},...u})}),r(v.Controller,{name:`reference_lines.${e}.lineStyle.width`,control:t,render:({field:u})=>r(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...u})})]}),d(s.Stack,{spacing:4,children:[r(s.Text,{size:"sm",children:"Color"}),r(v.Controller,{name:`reference_lines.${e}.lineStyle.color`,control:t,render:({field:u})=>r(Te,{...u})})]}),r(s.Button,{leftIcon:r(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Reference Line"})]})}function bv({control:t,watch:e,variables:n}){const{fields:i,append:a,remove:o}=v.useFieldArray({control:t,name:"reference_lines"}),l=e("reference_lines"),u=i.map((g,b)=>({...g,...l[b]})),c=()=>{const g={name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:rt.random().css()},show_in_legend:!1,yAxisIndex:0};a(g)},p=m.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),h=e("y_axes"),f=m.useMemo(()=>h.map(({name:g},b)=>({label:g,value:b.toString()})),[h]);return d(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[d(s.Tabs.List,{children:[u.map((g,b)=>r(s.Tabs.Tab,{value:b.toString(),children:b+1},g.id)),r(s.Tabs.Tab,{onClick:c,value:"add",children:r(T.Plus,{size:18,color:"#228be6"})})]}),u.map((g,b)=>r(s.Tabs.Panel,{value:b.toString(),children:r(yv,{control:t,index:b,remove:o,watch:e,variableOptions:p,yAxisOptions:f})},g.id))]})}const vv=({value:t,onChange:e})=>{const n=i=>{i&&e(i)};return r(s.Box,{children:r(ve,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},xv=({value:t,onChange:e})=>{const[n,{setTrue:i,setFalse:a}]=q.useBoolean(),[o,l]=m.useState(t),u=()=>{a();const{type:f,func_content:g}=o,b={type:f,func_content:g};l(b),e(b)},c=()=>{a(),l(t)},p=f=>{l(g=>({...g,func_content:f}))},h=()=>{p(en.dynamic.func_content)};return d(z,{children:[r(s.Box,{sx:{width:"50%"},children:r(s.Button,{variant:"filled",mt:24,onClick:i,sx:{flexGrow:0},children:"Setup"})}),r(s.Modal,{size:800,title:"Setup dynamic color",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&d(s.Stack,{children:[r(s.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),r(vv,{value:o.func_content,onChange:p}),d(s.Group,{position:"apart",children:[r(s.Button,{onClick:h,color:"red",leftIcon:r(T.Recycle,{size:20}),children:"Reset"}),d(s.Group,{position:"right",children:[r(s.Button,{onClick:c,variant:"subtle",children:"Cancel"}),r(s.Button,{onClick:u,children:"OK"})]})]})]})})]})},wv=({value:t,onChange:e})=>t.type!=="dynamic"?null:r(xv,{value:t,onChange:e}),Cv=({value:t,onChange:e})=>{if(t.type!=="static")return null;const n=i=>{e({...t,color:i})};return r(s.ColorInput,{label:" ",format:"rgb",value:t.color,onChange:n})},Sv=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],_v=m.forwardRef(({label:t="Color",value:e,onChange:n},i)=>{const a=o=>{n({...en[o]})};return d(s.SimpleGrid,{cols:2,children:[r(s.Select,{ref:i,label:t,data:Sv,value:e.type,onChange:a,sx:{flexGrow:1}}),r(Cv,{value:e,onChange:n}),r(wv,{value:e,onChange:n})]})}),kv=m.forwardRef(({value:t,onChange:e},n)=>{const i=o=>{e({...t,label:o})},a=o=>{e({...t,tooltip:o})};return d(s.Stack,{ref:n,spacing:0,children:[r(hn,{sectionTitle:"Overflow on Chart",value:t.label,onChange:i}),r(hn,{sectionTitle:"Overflow in Tooltip",value:t.tooltip,onChange:a})]})}),Tv=({value:t,onChange:e})=>{const n=i=>{i&&e(i)};return r(s.Box,{children:r(ve,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},js={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
|
|
277
|
+
`)}},Dv=({value:t,onChange:e})=>{const[n,{setTrue:i,setFalse:a}]=q.useBoolean(),[o,l]=m.useState(t),u=()=>{a();const{type:f,func_content:g}=o,b={type:f,func_content:g};l(b),e(b)},c=()=>{a(),l(t)},p=f=>{l(g=>({...g,func_content:f}))},h=()=>{p(js.dynamic.func_content)};return d(z,{children:[r(s.Box,{sx:{width:"50%"},children:r(s.Button,{variant:"filled",mt:24,onClick:i,sx:{flexGrow:0},children:"Setup"})}),r(s.Modal,{size:800,title:"Setup dynamic size",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&d(s.Stack,{children:[r(s.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),r(Tv,{value:o.func_content,onChange:p}),d(s.Group,{position:"apart",children:[r(s.Button,{onClick:h,color:"red",leftIcon:r(T.Recycle,{size:20}),children:"Reset"}),d(s.Group,{position:"right",children:[r(s.Button,{onClick:c,variant:"subtle",children:"Cancel"}),r(s.Button,{onClick:u,children:"OK"})]})]})]})})]})},Iv=({value:t,onChange:e})=>t.type!=="dynamic"?null:r(Dv,{value:t,onChange:e}),Mv=({value:t,onChange:e})=>{if(t.type!=="static")return null;const n=i=>{e({...t,size:i})};return r(z,{children:r(s.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:t.size,onChange:n})})},Av=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],zv=m.forwardRef(({label:t="Size",value:e,onChange:n},i)=>{const a=o=>{n({...js[o]})};return d(s.SimpleGrid,{cols:2,children:[r(s.Select,{ref:i,label:t,data:Av,value:e.type,onChange:a,sx:{flexGrow:1}}),r(Mv,{value:e,onChange:n}),r(Iv,{value:e,onChange:n})]})}),Ev=[{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 Pv({control:t,watch:e}){return e(["scatter"]),d(s.Stack,{children:[d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"scatter.name_data_key",control:t,render:({field:n})=>r(O,{label:"Name Data Field",required:!0,sx:{flex:1},...n})}),r(v.Controller,{name:"scatter.y_data_key",control:t,render:({field:n})=>r(O,{label:"Value Data Field",required:!0,sx:{flex:1},...n})})]}),r(s.Divider,{mb:-15,label:"Style",labelPosition:"center"}),r(v.Controller,{name:"scatter.symbolSize",control:t,render:({field:n})=>r(zv,{label:"Size",...n})}),r(v.Controller,{name:"scatter.color",control:t,render:({field:n})=>r(_v,{...n})}),r(s.Divider,{mb:-15,label:"Label",labelPosition:"center"}),r(s.Group,{grow:!0,noWrap:!0,children:r(v.Controller,{name:"scatter.label_position",control:t,render:({field:n})=>r(s.Select,{label:"Label Position",data:Ev,...n})})}),r(v.Controller,{name:"scatter.label_overflow",control:t,render:({field:n})=>r(kv,{...n})})]})}function Lv({control:t,watch:e}){return e("stats"),r(s.Stack,{children:d(s.Stack,{spacing:0,children:[r(v.Controller,{name:"stats.templates.top",control:t,render:({field:n})=>r(Rt,{label:"Template for stats above the chart",py:"md",sx:{flexGrow:1},...n})}),r(v.Controller,{name:"stats.templates.bottom",control:t,render:({field:n})=>r(Rt,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const Bv=({control:t,index:e,remove:n})=>d(s.Stack,{children:[d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`tooltip.metrics.${e}.name`,control:t,render:({field:i})=>r(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})}),r(v.Controller,{name:`tooltip.metrics.${e}.data_key`,control:t,render:({field:i})=>r(O,{label:"Value Field",required:!0,sx:{flex:1},...i})})]}),r(s.Divider,{mb:-10,mt:10,variant:"dashed"}),r(s.Button,{leftIcon:r(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),Ov=({control:t,watch:e})=>{const{fields:n,append:i,remove:a}=v.useFieldArray({control:t,name:"tooltip.metrics"}),o=e("tooltip.metrics"),l=n.map((f,g)=>({...f,...o[g]})),u=()=>i({id:Date.now().toString(),data_key:"",name:""}),c=e("tooltip.metrics.0.id"),[p,h]=m.useState(()=>c??null);return m.useEffect(()=>{c&&h(f=>f!==null?f:c)},[c]),d(z,{children:[d(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[r(T.InfoCircle,{size:14,color:"#888"}),r(s.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),d(s.Tabs,{value:p,onTabChange:f=>h(f),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[d(s.Tabs.List,{children:[l.map((f,g)=>r(s.Tabs.Tab,{value:f.id,children:f.name?f.name:g},f.id)),r(s.Tabs.Tab,{onClick:u,value:"add",children:r(T.Plus,{size:18,color:"#228be6"})})]}),l.map((f,g)=>r(s.Tabs.Panel,{value:f.id,children:r(Bv,{control:t,index:g,remove:a},f.id)},f.id))]})]})},$v=[{label:"Scatter Point",value:"item"},{label:"X Axis",value:"axis"}];function Vv({control:t,watch:e}){return e("tooltip.trigger"),d(s.Stack,{children:[r(v.Controller,{name:"tooltip.trigger",control:t,render:({field:n})=>r(s.Select,{label:"Trigger",data:$v,sx:{flexGrow:1},...n})}),r(s.Divider,{variant:"dashed"}),r(Ov,{control:t,watch:e})]})}const Nv=({disabled:t,value:e,onChange:n})=>{const i=a=>{a&&n(a)};return d(s.Box,{sx:{position:"relative"},children:[t&&r(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),r(ve,{height:"500px",defaultLanguage:"javascript",value:e,onChange:i,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},qv=m.forwardRef(({value:t,onChange:e},n)=>{const[i,{setTrue:a,setFalse:o}]=q.useBoolean(),[l,u]=m.useState(t);m.useEffect(()=>{u(t)},[t]);const c=b=>{u({...l,enabled:b})},p=()=>{o();const{enabled:b,func_content:w}=l,_={enabled:b,func_content:w};u(_),e(_)},h=()=>{o(),u(t)},f=b=>{u(w=>({...w,func_content:b}))},g=()=>{f(Vs.func_content)};return d(z,{children:[r(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Customize Label"}),r(s.Modal,{size:800,title:"Customize label content",opened:i,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:i&&d(s.Stack,{children:[r(s.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:b=>c(b.currentTarget.checked)}),r(Nv,{value:l.func_content,onChange:f,disabled:!l.enabled}),d(s.Group,{position:"apart",children:[r(s.Button,{onClick:g,color:"red",leftIcon:r(T.Recycle,{size:20}),children:"Reset"}),d(s.Group,{position:"right",children:[r(s.Button,{onClick:h,variant:"subtle",children:"Cancel"}),r(s.Button,{onClick:p,children:"OK"})]})]})]})})]})});function Gv({control:t,watch:e}){return e(["x_axis"]),d(s.Stack,{children:[d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>r(O,{label:"Data Field",required:!0,sx:{flex:1},...n})}),r(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>r(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),r(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>r(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:r(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),r(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>r(qv,{...n})})]})]})}const Fv=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],jv=[{label:"left",value:"left"},{label:"right",value:"right"}];function Wv({control:t,index:e,remove:n}){return d(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[r(s.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`y_axes.${e}.name`,control:t,render:({field:i})=>r(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})}),r(v.Controller,{name:`y_axes.${e}.nameAlignment`,control:t,render:({field:i})=>r(s.Select,{label:"Align",required:!0,data:Fv,sx:{flex:1},...i})})]}),r(s.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),r(s.Group,{grow:!0,noWrap:!0,children:r(v.Controller,{name:`y_axes.${e}.position`,control:t,render:({field:i})=>r(s.Select,{label:"Position",required:!0,data:jv,sx:{flex:1},...i})})}),d(s.Stack,{children:[r(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),r(v.Controller,{name:`y_axes.${e}.label_formatter`,control:t,render:({field:i})=>r(Pe,{...i})})]}),d(s.Stack,{children:[r(s.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),d(s.Group,{grow:!0,children:[r(v.Controller,{name:`y_axes.${e}.min`,control:t,render:({field:i})=>r(s.TextInput,{label:"Min",...i})}),r(v.Controller,{name:`y_axes.${e}.max`,control:t,render:({field:i})=>r(s.TextInput,{label:"Max",...i})})]})]}),r(s.Button,{mt:20,leftIcon:r(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),disabled:e===0,children:"Delete this YAxis"})]})}function Rv({control:t,watch:e}){const{fields:n,append:i,remove:a}=v.useFieldArray({control:t,name:"y_axes"}),o=e("y_axes"),l=n.map((c,p)=>({...c,...o[p]})),u=()=>i({name:"",label_formatter:xe,min:"",max:"",show:!0,position:"right",nameAlignment:"right"});return d(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[d(s.Tabs.List,{children:[l.map((c,p)=>r(s.Tabs.Tab,{value:p.toString(),children:p+1},c.id)),r(s.Tabs.Tab,{onClick:u,value:"add",children:r(T.Plus,{size:18,color:"#228be6"})})]}),l.map((c,p)=>r(s.Tabs.Panel,{value:p.toString(),children:r(Wv,{control:t,index:p,remove:a})},c.id))]})}function Qv(t){return t||{templates:{top:"",bottom:""}}}function Uv({reference_lines:t=[],stats:e,...n}){return{reference_lines:t,stats:Qv(e),...n}}function Kv({context:t}){const{value:e,set:n}=V(t.instanceData,"config"),{variables:i}=t,a=m.useMemo(()=>x.defaultsDeep({},e,ei),[e]),o=m.useMemo(()=>Uv(a),[a]);m.useEffect(()=>{!x.isEqual(a,o)&&(console.log("config malformed, resetting to defaults",a,o),n(o))},[a,o]);const{control:l,handleSubmit:u,watch:c,getValues:p,reset:h}=v.useForm({defaultValues:o});m.useEffect(()=>{h(o)},[o]);const f=p(),g=m.useMemo(()=>!x.isEqual(f,a),[f,a]);return c(["dataZoom"]),r(s.Stack,{spacing:"xs",children:d("form",{onSubmit:u(n),children:[d(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(s.Text,{children:"Chart Config"}),r(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!g,children:r(T.DeviceFloppy,{size:20})})]}),d(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[d(s.Tabs.List,{children:[r(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),r(s.Tabs.Tab,{value:"Y Axes",children:"Y Axes"}),r(s.Tabs.Tab,{value:"Scatter",children:"Scatter"}),r(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"}),r(s.Tabs.Tab,{value:"Stats",children:"Stats"}),r(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"}),r(s.Tabs.Tab,{value:"Reference Areas",children:"Reference Areas"}),r(s.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),r(s.Tabs.Panel,{value:"X Axis",children:r(Gv,{control:l,watch:c})}),r(s.Tabs.Panel,{value:"Y Axes",children:r(Rv,{control:l,watch:c})}),r(s.Tabs.Panel,{value:"Scatter",children:r(Pv,{control:l,watch:c})}),r(s.Tabs.Panel,{value:"Tooltip",children:r(Vv,{control:l,watch:c})}),r(s.Tabs.Panel,{value:"Stats",children:r(Lv,{control:l,watch:c})}),r(s.Tabs.Panel,{value:"Reference Lines",children:r(bv,{variables:i,control:l,watch:c})}),r(s.Tabs.Panel,{value:"Reference Areas",children:r(fv,{variables:i,control:l,watch:c})}),r(s.Tabs.Panel,{value:"Zooming",children:r(v.Controller,{name:"dataZoom",control:l,render:({field:b})=>r(Wr,{...b})})})]})]})})}function Yv(t){const{dataZoom:e=zt,...n}=t;return{...n,dataZoom:e}}function Xv(t){const e={scatter:{label_overflow:Ns}};return x.defaultsDeep(e,t)}function Jv(t){const{color:e}=t.scatter;return typeof e=="string"?{...t,scatter:{...t.scatter,color:{...en.static,color:e}}}:t}function Zv(t){const e=t.reference_lines.map(n=>{const{lineStyle:i={type:"dashed",width:1,color:rt.random().css()},show_in_legend:a=!1,yAxisIndex:o=0}=n;return{...n,lineStyle:i,show_in_legend:a,yAxisIndex:o}});return{...t,reference_lines:e}}function Hv(t){const e={tooltip:{trigger:"item"}};return x.defaultsDeep({},t,e)}function ex(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=c=>c&&`${n}.${c}`,{x_axis:a,scatter:o,tooltip:l,...u}=t;return{...u,x_axis:{...a,data_key:i(a.data_key)},scatter:{...o,y_data_key:i(o.y_data_key),name_data_key:i(o.name_data_key)},tooltip:{...l,metrics:l.metrics.map(c=>({...c,data_key:i(c.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}class tx extends se{constructor(){super(...arguments);P(this,"VERSION",9)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{tooltip:i={metrics:[]},...a}=n.config;return{...n,version:2,config:{...a,tooltip:i}}}),this.version(3,n=>({...n,version:3,config:Yv(n.config)})),this.version(4,n=>{const{config:i}=n;return{...n,version:5,config:Xv(i)}}),this.version(6,n=>{const{config:i}=n;return{...n,version:6,config:Jv(i)}}),this.version(7,n=>{const{config:i}=n;return{...n,version:7,config:Zv(i)}}),this.version(8,n=>{const{config:i}=n;return{...n,version:8,config:Hv(i)}}),this.version(9,(n,i)=>{const{config:a}=n;return{...n,version:9,config:ex(a,i)}})}}const nx={displayName:"Scatter Chart",displayGroup:"ECharts-based charts",migrator:new tx,name:"scatterChart",viewRender:dv,configRender:Kv,createConfig(){return{version:9,config:x.cloneDeep(ei)}},triggers:[$s]},ti={template:"The variable ${value} is defined in Variables section",vertical_align:"center",horizontal_align:"left"};function rx(t){if("variables"in t)return t;const{align:e,size:n,weight:i,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:i,size:n}]}}function ix(t){return x.omit(t,["variables"])}function ax(t){const{align:e,...n}=t;return{horizontal_align:e,vertical_align:"center",...n}}function sx(t){const e=x.cloneDeep(t),n=x.get(e,"color.valueRange");return n!==void 0&&x.set(e,"color.valueRange",n.map(i=>Number(i))),e}class ox extends se{constructor(){super(...arguments);P(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:rx(n)})),this.version(2,(n,{panelModel:i})=>{const{config:a}=n;return(a.variables||[]).forEach(l=>{i.variables.find(u=>u.name===l.name)||i.addVariable(sx(l))}),{...n,version:2,config:ix(a)}}),this.version(3,n=>{const{config:i}=n;return{...n,version:3,config:ax(i)}})}}const lx={left:"flex-start",center:"center",right:"flex-end"},ux={top:"flex-start",center:"center",bottom:"flex-end"},cx=k.observer(({context:t})=>{const e=ue(),{value:n=ti}=V(t.instanceData,"config"),{variables:i}=t,{template:a,horizontal_align:o,vertical_align:l}=n,{width:u,height:c}=t.viewport,p=m.useMemo(()=>{try{return x.template(a)(e.payloadForSQL)}catch{return a}},[e.payloadForSQL,a]),h=m.useMemo(()=>Ht(p,i,t.data),[p,i,t.data,t]);return r(s.Center,{sx:{width:u,height:c,justifyContent:lx[o],alignItems:ux[l]},children:r(s.Box,{children:Object.values(h).map((f,g)=>r(m.Fragment,{children:f},g))})})}),dx=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],px=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function hx({context:t}){const{value:e,set:n}=V(t.instanceData,"config"),i=m.useMemo(()=>x.defaultsDeep({},e,ti),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:i});m.useEffect(()=>{c(i)},[i]),l(["template","horizontal_align","vertical_align"]);const p=u(),h=m.useMemo(()=>!x.isEqual(p,e),[p,e]);return r(s.Stack,{spacing:"xs",children:d("form",{onSubmit:o(n),children:[d(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(s.Text,{weight:500,children:"Stats Configurations"}),r(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:r(T.DeviceFloppy,{size:20})})]}),r(v.Controller,{name:"template",control:a,render:({field:f})=>r(Rt,{label:"Template",py:"md",sx:{flexGrow:1},...f})}),d(s.SimpleGrid,{cols:2,children:[r(v.Controller,{name:"horizontal_align",control:a,render:({field:f})=>r(s.Select,{label:"Horizontal Alignment",data:dx,...f})}),r(v.Controller,{control:a,name:"vertical_align",render:({field:f})=>r(s.Select,{label:"Vertical Alignment",data:px,...f})})]})]})})}const fx={createConfig(){return{version:3,config:ti}},displayName:"Stats",displayGroup:"Others",migrator:new ox,name:"stats",viewRender:cx,configRender:hx},ni={label_key:"",value_key:"",group_key:"",levels:[]};function gx(t){const e=new Set(t.map(i=>i.parent_id)),n=new Set(t.map(i=>i.id));return e.forEach(i=>{i===null||n.has(i)||t.push({id:i,name:i,parent_id:null})}),t}function mx(t){const e=gx(t).map(a=>({...a,children:[]})),n=x.keyBy(e,a=>a.id),i=[];return e.forEach(a=>{if(!a.parent_id||!n[a.parent_id]){i.push(a);return}n[a.parent_id].children.push(a)}),i}function yx(t,e){const{label_key:n,value_key:i,group_key:a}=t;if(!n||!i)return[];const o=A(n),l=A(i),u=A(a),c=e[o.queryID].map(p=>({...p,id:p[o.columnKey],parent_id:p[u.columnKey],name:p[o.columnKey],value:p[l.columnKey]?Number(p[l.columnKey]):p[l.columnKey]}));return a?mx(c):c}const bx=t=>({treePathInfo:e,name:n,value:i})=>{if(e.length===1||!t)return n;try{const a=e[e.length-2].value;if(i/a<t)return" "}catch{return n}};function vx(t){const{levels:e}=t;return e.map(n=>{const{show_label_tolerance:i,...a}=n.label;return{...n,label:{...a,formatter:bx(i)}}})}function xx(){return({treePathInfo:t,name:e,value:n,color:i,marker:a,...o})=>{const l=t.slice(0,t.length-1),u=[`<tr>
|
|
278
278
|
<th style="text-align: right; padding: 0 1em;">Value</th>
|
|
279
279
|
<td style="text-align: left; padding: 0 1em;">${n}</td>
|
|
280
280
|
</tr>
|
|
281
|
-
`];return l.reverse().forEach(({value:
|
|
281
|
+
`];return l.reverse().forEach(({value:p,name:h})=>{u.push(`
|
|
282
282
|
<tr>
|
|
283
|
-
<th style="text-align: right; padding: 0 1em;">${
|
|
283
|
+
<th style="text-align: right; padding: 0 1em;">${h||"Total"}</th>
|
|
284
284
|
<td style="text-align: left; padding: 0 1em;">
|
|
285
|
-
${
|
|
285
|
+
${W(n/p).format({output:"percent",mantissa:2,trimMantissa:!0})}
|
|
286
286
|
</td>
|
|
287
287
|
</tr>
|
|
288
288
|
`)}),`
|
|
289
289
|
<div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
|
|
290
|
-
<div>${a} ${
|
|
290
|
+
<div>${a} ${e}</div>
|
|
291
291
|
</div>
|
|
292
292
|
<table style="width: auto">
|
|
293
293
|
<tbody>${u.join("")}</tbody>
|
|
294
294
|
</table>
|
|
295
|
-
`}}function
|
|
296
|
-
`),qo={columns:[],fontSize:"14px",highlightOnHover:!0,horizontalSpacing:"14px",id_field:"",striped:!0,use_raw_columns:!0,verticalSpacing:"14px"},Fo={left:"flex-start",center:"center",right:"flex-end"},Wx=({header:e,cx:t})=>{const n=x.get(e.column.columnDef.meta,"align","left");return p(s.Text,{className:t("table-head-cell",{"table-head-cell--sortable":e.column.getCanSort()}),onClick:e.column.getToggleSortingHandler(),align:n,sx:{justifyContent:Fo[n]},children:[e.isPlaceholder?null:et.flexRender(e.column.columnDef.header,e.getContext()),i(jx,{direction:e.column.getIsSorted()})]})},jx=({direction:e})=>{switch(e){case"asc":return i(E.IconArrowUp,{size:16});case"desc":return i(E.IconArrowDown,{size:"1em"});default:return null}},Rx=s.createStyles(e=>({root:{overflow:"auto",position:"relative","& .table-head-cell":{display:"flex",flexFlow:"row nowrap",alignItems:"center",whiteSpace:"nowrap","&.table-head-cell--sortable":{cursor:"pointer",userSelect:"none"}},"&.table-highlight-on-hover tr":{transition:"background-color 0.2s","&:hover":{backgroundColor:e.colorScheme==="dark"?e.colors.dark[5]:e.colors.gray[0]}}},thead:{background:e.colorScheme==="dark"?e.colors.dark[7]:e.white,position:"sticky",top:24,transform:"translateY(-1px)",zIndex:10},info_bar:{position:"sticky",top:0,left:0,right:0,zIndex:10,background:"white"}})),Yx={tableLayout:"fixed","thead, tbody":{tr:{"th, td":{padding:"2px 10px",div:{overflow:"hidden",textOverflow:"ellipsis"},"&:first-of-type":{paddingLeft:2,paddingRight:2}}}}},Qx=s.createStyles((e,t)=>({content:{display:"flex",alignItems:"center",justifyContent:Fo[t.align],".table-cell-text":{whiteSpace:"nowrap",cursor:t.clickable?"pointer":"default",textDecoration:t.clickable?"underline":"none"}}}));function Ux(e){return e?ht(e).oklch()[0]>.7?"black":"white":"inherit"}function Kx(e){const t=e.tableCellContext.bgColor;return{backgroundColor:t,color:Ux(t)}}function Ut(e){const t=e.tableCellContext.isClickable(),n=Qx({clickable:t,align:e.align});return i("div",{className:n.classes.content,style:{...Kx(e)},children:i(s.Text,{className:"table-cell-text",onClick:e.tableCellContext.getClickHandler(),children:i("span",{title:e.children,children:e.children})})})}function Xx(e){return i(Ut,{...e,children:e.value})}function Jx(e){const t=Z(e.value).format({average:!0,mantissa:2,trimMantissa:!0});return i(Ut,{...e,children:t})}function Zx(e){const t=Z(e.value).format({thousandSeparated:!0});return i(Ut,{...e,children:t})}function Hx(e){const t=Z(e.value).format({output:"percent",mantissa:3,trimMantissa:!0});return i(Ut,{...e,children:t})}function e0(e){const t=e.value,n=e.func_content;if(!n)return i(Ut,{...e,children:t});const r=new Function(`return ${n}`)()({value:t});return i(Ut,{...e,children:r})}function t0(e){switch(e.type){case it.string:return i(Xx,{...e});case it.eloc:return i(Jx,{...e});case it.number:return i(Zx,{...e});case it.percentage:return i(Hx,{...e});case it.custom:return i(e0,{...e})}}function n0({tableContainerRef:e,rows:t}){var u,c;const n=ju.useVirtual({parentRef:e,size:t.length,estimateSize:m.useCallback(()=>28,[]),overscan:20}),{virtualItems:r,totalSize:a}=n,o=r.length>0&&((u=r==null?void 0:r[0])==null?void 0:u.start)||0,l=r.length>0?a-(((c=r==null?void 0:r[r.length-1])==null?void 0:c.end)||0):0;return Q.useWhyDidYouUpdate("TableBody",{tableContainerRef:e,rows:t}),p("tbody",{children:[o>0&&i("tr",{children:i("td",{style:{height:`${o}px`}})}),r.map(d=>{const f=t[d.index];return i("tr",{children:f.getVisibleCells().map(h=>i("td",{children:et.flexRender(h.column.columnDef.cell,h.getContext())},h.id))},f.id)}),l>0&&i("tr",{children:i("td",{style:{height:`${l}px`}})})]})}const xi={id:"builtin:table:click-cell-content",displayName:"Click Cell Content",nameRender:s0,configRender:i0,payload:[{name:"row_index",description:"Index of the row that the cell belongs to",valueType:"number"},{name:"col_index",description:"Index of the column that the cell belongs to",valueType:"number"},{name:"row_data",description:"Data of the row that the cell belongs to",valueType:"object"}]},r0={column:""};function Go(e,t){const{value:n}=R(e.instanceData,"config"),r={columnsFromConfig:[],columnsFromData:[]};if(n&&(r.columnsFromConfig=n.columns.map((a,o)=>({label:a.label,value:o.toString()}))),!t)return r;if(n!=null&&n.id_field){const a=ln(t,n.id_field);(a==null?void 0:a.length)>0&&(r.columnsFromData=Object.keys(a[0]).map(o=>({label:o,value:o})))}return r}function i0(e){const{columnsFromConfig:t,columnsFromData:n}=Go(e.instance,e.sampleData),r=t.length>0?t:n,{value:a,set:o}=R(e.trigger.triggerData,"config"),{column:l}=x.defaults({},a,r0),u=c=>{isNaN(+c)?o({column:c}):o({column:+c})};return i(s.Select,{clearable:!1,data:r,label:"Choose a column",value:l.toString(),onChange:u})}function a0(e,t){return e?x.isNumber(e.column)?`Click cell of ${t[e.column].label}`:`Click cell of ${e.column}`:"Click cell content (click to config)"}function s0(e){const{columnsFromConfig:t}=Go(e.instance),{value:n}=R(e.trigger.triggerData,"config");return i(s.Text,{children:a0(n,t)})}function Wo(e,t,n){return Math.min(Math.max(e,t),n)}class o0{constructor(t){this.steps=t;const n=[],r=new Set;for(const a of t)r.has(a.to)||(n.push(a),r.add(a.to));if(n.sort((a,o)=>a.from-o.from),n.length<2)throw new Error("MultiStepValueMapper requires at least 2 steps");this.steps=n}getLinearFunction(t,n){const r=(n.to-t.to)/(n.from-t.from),a=t.to-r*t.from;return o=>r*o+a}getStepFunctionForValue(t){let n=x.findLastIndex(this.steps,r=>r.from<=t);return n=Wo(n,0,this.steps.length-2),this.getLinearFunction(this.steps[n],this.steps[n+1])}mapValue(t){return Wo(this.getStepFunctionForValue(t)(t),0,100)}}class l0{constructor(t,n,r,a,o){this.getColIndex=t,this.cell=n,this.triggers=r,this.interactionManager=a,this.colorManager=o}getClickHandler(){const t=this.getRelatedTrigger();if(t.length!==0)return()=>{const n={row_data:this.cell.row.original,row_index:this.cell.row.index,col_index:this.getColIndex(this.cell)};for(const r of t)this.interactionManager.runInteraction(r.id,n)}}getRelatedTrigger(){return this.triggers.filter(n=>n.schemaRef===xi.id).filter(n=>{const r=this.getColIndex(this.cell),a=x.get(this.cell.column.columnDef.meta,"value_field"),o=x.get(n.config,"column");return o==r||o==a})}isClickable(){return this.getRelatedTrigger().length>0}get columnConf(){return this.cell.column.columnDef.meta}get bgColor(){const t=this.columnConf.cellBackgroundColor;if(!t||t==="none")return;if(x.isString(t))return t;const n=+this.cell.getValue();if(isFinite(n)){const r=this.colorManager.decodeInterpolation(t.interpolation),o=new o0(t.steps).mapValue(n);return r==null?void 0:r.getColor(o)}}}const u0=e=>{const t=Xe(e),n=Ke(t.triggerManager,xi.id),{colorManager:r}=m.useContext(ct);return m.useCallback(a=>new l0(e.getColIndex,a,n,t,r),[n,t,e.getColIndex])};function c0({queryData:e,width:t,height:n,conf:r,context:a,instance:o}){const{id_field:l,use_raw_columns:u,columns:c,...d}=r,{classes:f,cx:h}=Rx(),g=m.useMemo(()=>u?!Array.isArray(e)||e.length===0?[]:Object.keys(e[0]).map(N=>({id:N,label:N,value_field:N,value_type:it.string,align:"left",width:"",cellBackgroundColor:""})):c,[u,c,e]),y=u0({getColIndex:m.useCallback(N=>g.indexOf(N.column.columnDef.meta),[g]),vizManager:a.vizManager,instance:o}),C=m.useMemo(()=>{const N=et.createColumnHelper();return g.map(Y=>{const H=Tc(Y.value_field);return N.accessor(H.columnKey,{cell:se=>i(t0,{tableCellContext:y(se.cell),value:se.getValue(),type:Y.value_type,...Y}),header:Y.label,enableSorting:!0,meta:Y,size:typeof Y.width=="number"?Y.width:void 0,minSize:typeof Y.width=="number"?Y.width:void 0})})},[g,y]),[w,_]=m.useState([]),D=et.useReactTable({data:e,state:{sorting:w},onSortingChange:_,columns:C,getCoreRowModel:et.getCoreRowModel(),getSortedRowModel:et.getSortedRowModel()}),{rows:M}=D.getRowModel(),O=m.useRef(null),G=M.length,$=G>0,L=$?n-22:n,A=$?22:0;return Q.useWhyDidYouUpdate("VizTableComponent",{queryData:e,width:t,height:n,conf:r,context:a,instance:o,finalColumns:g,getCellContext:y,tableColumns:C,table:D,rows:M,tableContainerRef:O}),p("div",{ref:O,style:{height:n,width:t,padding:"0 5px"},"data-enable-scrollbar":!0,className:h(f.root,{"table-highlight-on-hover":r.highlightOnHover}),children:[G>0&&i(s.Box,{className:f.info_bar,sx:{height:22},children:p(s.Text,{align:"right",pr:6,size:14,color:"dimmed",fw:"normal",children:["Total: ",G]})}),p(s.Table,{sx:{...Yx,maxHeight:L},...d,striped:r.striped,children:[i("thead",{className:f.thead,style:{top:A},children:D.getHeaderGroups().map(N=>i("tr",{children:N.headers.map(K=>i("th",{style:{width:K.getSize()},children:i(Wx,{header:K,cx:h})},K.id))},N.id))}),i(n0,{tableContainerRef:O,rows:M})]})]})}function d0({data:e,width:t,height:n,conf:r,context:a,instance:o}){const{id_field:l,use_raw_columns:u,columns:c}=r,d=m.useMemo(()=>{if(!l)return[];const f=P(l);return e[f.queryID]},[e,l]);return!Array.isArray(d)||d.length===0?i(s.Text,{color:"gray",align:"center",children:"Empty Data"}):i(c0,{queryData:d,width:t,height:n,conf:r,context:a,instance:o})}function p0({context:e,instance:t}){const n=e.data,{height:r,width:a}=e.viewport,{value:o}=R(e.instanceData,"config");return o?o.id_field?i(d0,{data:n,width:a,height:r,conf:o,context:e,instance:t}):i(s.Text,{color:"red",align:"center",children:"ID Field is not set, can't render a table without it"}):null}const jo=s.createStyles(()=>({palette:{display:"flex",flexFlow:"row nowrap"},paletteItem:{".palette-value":{height:24,overflow:"visible",width:36},".palette-item":{width:"36px",height:36*.618,cursor:"pointer",transition:"transform 100ms ease-in-out","&:hover":{boxShadow:"0 0 0 2px var(--shadow-color)",borderRadius:2,transform:"scale(1.2)"}}}})),h0=[{from:0,to:0},{from:100,to:100}];class f0{constructor(){q(this,"steps",new Map);q(this,"interpolation");q(this,"onChange");te.makeAutoObservable(this,{steps:te.observable},{deep:!1}),te.reaction(()=>te.toJS(this.steps),()=>{this.notifyStepChange()})}setSteps(t){for(const n of t)this.steps.set(n.to,n.from)}notifyStepChange(){var t;(t=this.onChange)==null||t.call(this,Array.from(this.steps.entries()).map(([n,r])=>({to:n,from:r})).sort((n,r)=>n.to-r.to||n.from-r.from))}fromProps(t){t.steps.length<2?this.setSteps(h0):this.setSteps(t.steps),this.interpolation=t.interpolation,this.onChange=t.onChange}changeStep(t,n){t==null?this.steps.delete(n):this.steps.set(n,t)}getStepFromValue(t){return this.steps.get(t)}}function g0(e){const{onChange:t,color:n,index:r,value:a}=e,{classes:o}=jo(),[l,u]=m.useState(a),[c,{setTrue:d,setFalse:f}]=Q.useBoolean(!1),h=r%2===1,g=h&&a!=null,y=!h&&a!=null,C=`map ${a} to color ${r}`,w=()=>{u(a),f()},_=()=>{f(),t==null||t(l)},D=Z(a).format({average:!0});return p("div",{"data-testid":`palette-item-${r}`,className:o.paletteItem,children:[i(s.Text,{title:C,style:{opacity:g?1:0},color:"dimmed",size:"sm",className:"palette-value--up palette-value",children:D}),p(s.Popover,{width:200,trapFocus:!0,opened:c,onClose:f,children:[i(s.Popover.Target,{children:i("div",{"data-testid":"palette-item-target",className:"palette-item",onClick:d,style:{"--shadow-color":ht(n).alpha(.5).hex(),backgroundColor:n}})}),i(s.Popover.Dropdown,{children:p(s.Stack,{children:[i(s.NumberInput,{size:"xs",label:"Map a value to this color",value:l,onChange:u}),p(s.Group,{position:"right",children:[i(s.Button,{variant:"subtle",size:"xs",onClick:w,children:"Cancel"}),i(s.Button,{"data-testid":"palette-item-ok",size:"xs",onClick:_,children:"OK"})]})]})})]}),i(s.Text,{title:C,style:{opacity:y?1:0},color:"dimmed",size:"sm",className:"palette-value--bottom palette-value",children:D})]})}const m0=k.observer(({model:e})=>{const{classes:t}=jo(),n=x.range(0,13,1).map(r=>100/12*r).map(r=>[e.interpolation.getColor(r),r]);return i("div",{className:t.palette,children:n.map(([r,a],o)=>i(g0,{index:o,color:r,value:e.getStepFromValue(a),onChange:l=>e.changeStep(l,a)},r))})}),y0=k.observer(function(t){const n=Q.useCreation(()=>new f0,[]);return m.useEffect(()=>{n.fromProps(t)}),n.interpolation==null?null:i(m0,{model:n})}),b0=e=>{const{value:t,onChange:n,colorManager:r}=e,a=r.getColorInterpolations(),[o,l]=m.useState(t),u=r.decodeInterpolation(o.interpolation)||a[0],[c,{setTrue:d,setFalse:f}]=Q.useBoolean(),h=a.map(_=>({label:_.displayName,value:r.encodeColor(_),group:_.category}));function g(_){_&&l(D=>({...D,interpolation:_}))}const y=()=>{f(),n==null||n(te.toJS(o))};function C(_){l(D=>({...D,steps:_}))}const w=()=>{f(),l(t)};return p(B,{children:[i(s.Button,{variant:"outline",onClick:d,children:u==null?void 0:u.displayName}),i(s.Modal,{size:508,title:"Setup color interpolation",opened:c,onClose:f,zIndex:320,children:c&&p(s.Stack,{"data-testid":"color-interpolation-modal",children:[i(s.Select,{label:"Color style",value:o.interpolation,data:h,onChange:g,withinPortal:!0,zIndex:340,maxDropdownHeight:500}),i(y0,{steps:o.steps,interpolation:u,onChange:C}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:w,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:y,children:"OK"})]})]})})]})},v0=["static","interpolation","none"].map(e=>({label:x.capitalize(e),value:e})),x0=[{from:0,to:0},{from:100,to:100}];function Ro(e){return e?x.isString(e)?e==="none"?"none":"static":"interpolation":"none"}function w0(e,t){var n;return Ro(t)==="static"?t:(n=e.getStaticColors()[0])==null?void 0:n.value}function C0(e,t){return x.isObject(t)?t:{steps:x0,interpolation:e.encodeColor(e.getColorInterpolations()[0])}}const S0=m.forwardRef((e,t)=>{const{colorManager:n}=m.useContext(ct),[r,a]=m.useState(Ro(e.value)),[o,l]=m.useState(w0(n,e.value)),u=Q.useLatest(o),[c,d]=m.useState(C0(n,e.value)),f=Q.useLatest(c),h=C=>{var w,_,D;a(C||"none"),C==="static"?(w=e.onChange)==null||w.call(e,u.current):C==="none"||!C?(_=e.onChange)==null||_.call(e,"none"):(D=e.onChange)==null||D.call(e,f.current)},g=C=>{var w;l(C),(w=e.onChange)==null||w.call(e,C)},y=C=>{var w;d(C),(w=e.onChange)==null||w.call(e,C)};return p(s.Stack,{align:"stretch",children:[i(s.Select,{label:"Cell background",value:r||"none",onChange:h,data:v0}),r==="static"&&i($e,{value:o,onChange:g}),r==="interpolation"&&i(b0,{colorManager:n,value:c,onChange:y})]})}),_0={[it.eloc]:"ELOC"},k0=Object.values(it).map(e=>({label:x.get(_0,e,x.capitalize(e)),value:e})),T0=m.forwardRef(({label:e,value:t,onChange:n,sx:r},a)=>i(s.Select,{ref:a,label:e,data:k0,value:t,onChange:n,sx:r})),D0=m.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:a,setFalse:o}]=Q.useBoolean(),[l,u]=m.useState(e),c=()=>{o(),t(l)},d=()=>{o(),u(e)},f=()=>{u(No)};return m.useEffect(()=>{u(e)},[e]),p(B,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Custom Cell Content"}),i(s.Modal,{size:800,title:"Custom cell content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(s.Box,{sx:{position:"relative"},children:i(Te,{height:"500px",defaultLanguage:"javascript",value:l,onChange:h=>u(h??""),theme:"vs-dark",options:{minimap:{enabled:!1}}})}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:c,children:"OK"})]})]})]})})]})}),I0=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],wi=()=>i(s.Text,{color:"dimmed",size:12,children:"px"}),M0=({control:e,index:t,watch:n,remove:r,column:a})=>{const o=n(`columns.${t}.value_type`);return p(s.Stack,{my:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,children:[i(v.Controller,{name:`columns.${t}.label`,control:e,render:({field:l})=>i(s.TextInput,{label:"Label",required:!0,id:`col-label-${t}`,sx:{flex:1},...l})}),i(v.Controller,{name:`columns.${t}.value_field`,control:e,render:({field:l})=>i(W,{label:"Value Field",required:!0,...l})})]}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`columns.${t}.value_type`,control:e,render:({field:l})=>i(T0,{label:"Value Type",sx:{flex:1},...l})}),o===it.custom&&i(v.Controller,{name:`columns.${t}.func_content`,control:e,render:({field:l})=>i(D0,{value:l.value??No,onChange:u=>l.onChange(u??"")})})]}),i(s.Divider,{mb:-10,variant:"dashed",label:"Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(s.NumberInput,{hideControls:!0,label:"Min Width",rightSection:i(wi,{}),disabled:!0}),i(v.Controller,{name:`columns.${t}.width`,control:e,render:({field:l})=>i(s.NumberInput,{hideControls:!0,label:"Width",rightSection:i(wi,{}),...l})}),i(s.NumberInput,{hideControls:!0,label:"Max Width",rightSection:i(wi,{}),disabled:!0})]}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`columns.${t}.align`,control:e,render:({field:l})=>i(s.Select,{label:"Alignment",data:I0,...l})})}),i(v.Controller,{name:`columns.${t}.cellBackgroundColor`,control:e,render:({field:l})=>i(S0,{...l})}),i(s.Divider,{mb:4,mt:12,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(t),children:"Delete this column"})]})},A0=({control:e,watch:t})=>{const{fields:n,append:r,remove:a,update:o}=v.useFieldArray({control:e,name:"columns"}),l=()=>{const c=_e.randomId();r({id:c,label:c,align:"center",value_field:"",value_type:it.string,width:""})};t("columns");const u=t("use_raw_columns");return p(B,{children:[i(v.Controller,{name:"use_raw_columns",control:e,render:({field:c})=>i(s.Switch,{mt:20,mb:20,label:"Use Original Data Columns",checked:c.value,onChange:d=>c.onChange(d.currentTarget.checked)})}),!u&&i(s.Stack,{children:p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[n.map((c,d)=>i(s.Tabs.Tab,{value:d.toString(),children:d+1},c.id)),i(s.Tabs.Tab,{onClick:l,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),n.map((c,d)=>i(s.Tabs.Panel,{value:d.toString(),children:i(M0,{control:e,watch:t,index:d,column:c,remove:a})},c.id))]})})]})};function z0({control:e,watch:t}){return t(["horizontalSpacing","verticalSpacing","fontSize","striped","highlightOnHover"]),p(s.Stack,{spacing:"xs",children:[p(s.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:[i(v.Controller,{name:"horizontalSpacing",control:e,render:({field:n})=>i(s.TextInput,{label:"Horizontal Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"verticalSpacing",control:e,render:({field:n})=>i(s.TextInput,{label:"Vertical Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})})]}),i(s.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:i(v.Controller,{name:"fontSize",control:e,render:({field:n})=>i(s.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})})}),p(s.Group,{position:"apart",grow:!0,children:[i(v.Controller,{name:"striped",control:e,render:({field:n})=>i(s.Switch,{label:"Striped",checked:n.value,onChange:r=>n.onChange(r.currentTarget.checked)})}),i(v.Controller,{name:"highlightOnHover",control:e,render:({field:n})=>i(s.Switch,{label:"Highlight on hover",checked:n.value,onChange:r=>n.onChange(r.currentTarget.checked)})})]})]})}function E0({columns:e,...t}){return{...t,columns:e.map(({id:n,...r})=>({id:n??_e.randomId(),...r}))}}function $0({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=m.useMemo(()=>x.defaultsDeep({},t,qo),[t]),a=m.useMemo(()=>E0(r),[r]);m.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});m.useEffect(()=>{d(a)},[a]);const f=c(),h=m.useMemo(()=>!x.isEqual(f,r),[f,r]);return u(["id_field"]),p("form",{onSubmit:l(n),children:[p(s.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Table Config"}),i(s.ActionIcon,{type:"submit","aria-label":"save config",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(I.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"Columns",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Columns",children:"Columns"}),i(s.Tabs.Tab,{value:"Style",children:"Style"})]}),p(s.Tabs.Panel,{value:"Columns",children:[i(v.Controller,{name:"id_field",control:o,render:({field:g})=>i(W,{label:"ID Field",required:!0,...g})}),i(s.Divider,{mt:20,mb:10,variant:"dashed"}),i(A0,{control:o,watch:u})]}),i(s.Tabs.Panel,{value:"Style",children:i(z0,{control:o,watch:u})})]})]})}function L0(e){const{columns:t,...n}=e;return{...e,columns:t.map(r=>({...r,align:r.align??"left"}))}}function P0(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{id_field:a,columns:o,...l}=e;return{...l,id_field:r(a),columns:o.map(u=>({...u,value_field:r(u.value_field)}))}}catch(n){throw console.error("[Migration failed]",n),n}}function O0(e){const{columns:t,...n}=e;return{...n,columns:t.map(r=>({...r,align:r.align??"left",cellBackgroundColor:r.cellBackgroundColor??"",width:r.width??""}))}}class B0 extends ge{constructor(){super(...arguments);q(this,"VERSION",5)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{columns:r,...a}=n.config;return{...n,version:2,config:{...a,columns:r.map(({id:o,...l})=>({id:o??_e.randomId(),...l}))}}}),this.version(3,n=>({...n,version:3,config:L0(n.config)})),this.version(4,(n,r)=>({...n,version:4,config:P0(n.config,r)})),this.version(5,n=>({...n,version:5,config:O0(n.config)}))}}const Ci={createConfig(){return{version:5,config:x.cloneDeep(qo)}},displayName:"Table",displayGroup:"Others",migrator:new B0,name:"table",viewRender:p0,configRender:$0,triggers:[xi]},Yo=["function text({ data, variables, filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
|
|
297
|
-
`),Si={func_content:Yo,horizontal_align:"left",font_size:"14px",font_weight:"normal"},V0=k.observer(({context:e})=>{const t=ye(),{value:n=Si}=R(e.instanceData,"config"),{variables:r}=e,a=e.data,{func_content:o,horizontal_align:l,font_size:u,font_weight:c}=n,d=m.useMemo(()=>r.reduce((h,g)=>{const y=yt(g,a);return h[g.name]=Ze(g,y),h},{}),[r,a]),f=m.useMemo(()=>new Function(`return ${o}`)()({data:a,variables:d,filters:t.payloadForSQL.filters,context:t.payloadForSQL.context}),[o,a,d,t.payloadForSQL]);return i(s.Text,{align:l,weight:c,sx:{fontSize:u},children:f})}),N0=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return i(s.Box,{sx:{position:"relative"},children:i(Te,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},q0=m.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:a,setFalse:o}]=Q.useBoolean(),[l,u]=m.useState(e),c=()=>{o(),t(l)},d=()=>{o(),u(e)},f=()=>{u(Yo)};return m.useEffect(()=>{u(e)},[e]),p(B,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Edit Content"}),i(s.Modal,{size:800,title:"Text content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(N0,{value:l,onChange:u}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:c,children:"OK"})]})]})]})})]})}),F0=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}];function G0({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=m.useMemo(()=>x.defaultsDeep({},t,Si),[t]),a=m.useMemo(()=>{const{func_content:g,horizontal_align:y,font_size:C,font_weight:w}=r;return{func_content:g,horizontal_align:y,font_size:C,font_weight:w}},[r]);m.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});m.useEffect(()=>{d(a)},[a]),u(["func_content","horizontal_align","font_size","font_weight"]);const f=c(),h=m.useMemo(()=>!x.isEqual(f,r),[f,r]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{weight:500,children:"Configurations"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(I.DeviceFloppy,{size:20})})]}),p(s.Stack,{spacing:10,children:[i(v.Controller,{name:"func_content",control:o,render:({field:g})=>i(q0,{...g})}),i(s.Divider,{mt:10,mb:-10,variant:"dashed",label:"Style",labelPosition:"center"}),i(v.Controller,{name:"horizontal_align",control:o,render:({field:g})=>i(s.Select,{label:"Horizontal Alignment",data:F0,...g})}),i(v.Controller,{name:"font_size",control:o,render:({field:g})=>i(s.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1},...g})}),i(s.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:i(v.Controller,{name:"font_weight",control:o,render:({field:g})=>i(so,{label:"Font Weight",...g})})})]})]})})}class W0 extends ge{constructor(){super(...arguments);q(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const j0={displayName:"Text",displayGroup:"Others",migrator:new W0,name:"text",viewRender:V0,configRender:G0,createConfig(){return{version:1,config:x.cloneDeep(Si)}}},R0=()=>p("svg",{width:"64",height:"64",viewBox:"0 0 64 64",fill:"none",children:[i("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M22.49 27.79H14.47C13.55 27.79 12.81 28.53 12.81 29.45C12.81 30.37 13.55 31.11 14.47 31.11H22.49C23.41 31.11 24.15 30.37 24.15 29.45C24.15 28.54 23.41 27.79 22.49 27.79ZM34.32 31.28C35.22 31.32 35.7 31.82 35.74 32.76C35.78 33.54 35.37 34.3 34.51 35.04C33.52 35.9 33.03 36.95 33.03 38.19V38.81H34.82V38.25C34.78 37.59 35.07 37.02 35.68 36.52C37.12 35.41 37.82 34.15 37.78 32.75C37.66 30.53 36.5 29.35 34.32 29.23C32.3 29.23 31.05 30.46 30.55 32.93L32.53 33.55C32.82 32.04 33.42 31.28 34.32 31.28ZM35 39.93H32.84V42.21H35V39.93ZM14.83 36.42H18.54C19.46 36.42 20.2 37.17 20.2 38.08C20.2 39 19.46 39.74 18.54 39.74H10.52C9.6 39.74 8.86 39 8.86 38.08C8.86 37.61 9.06 37.19 9.37 36.89H5.66C4.74 36.89 4 36.15 4 35.23C4 34.31 4.74 33.57 5.66 33.57H13.68C14.6 33.57 15.34 34.31 15.34 35.23C15.34 35.7 15.14 36.12 14.83 36.42ZM50.94 36.85H58.74C59.66 36.85 60.4 37.59 60.41 38.51C60.41 39.43 59.67 40.17 58.75 40.17H54.26C54.56 40.47 54.74 40.88 54.74 41.34C54.74 42.26 54 43 53.08 43H50.94V36.85Z",fill:"#B8C0CC"}),i("path",{d:"M18.39 32.28H16.51V35.02H18.39V32.28Z",fill:"#9399A5"}),i("path",{d:"M46.87 15H20.69C18.38 15 16.5 16.88 16.5 19.19V26.22H18.38V23.45H49.18V47.68H18.38V41.07H16.5V49.55H51.05V19.19C51.06 16.88 49.18 15 46.87 15ZM39.46 20.73C38.81 20.73 38.29 20.2 38.29 19.56C38.29 18.92 38.82 18.39 39.46 18.39C40.11 18.39 40.63 18.92 40.63 19.56C40.63 20.2 40.11 20.73 39.46 20.73ZM43.22 20.73C42.57 20.73 42.05 20.2 42.05 19.56C42.05 18.92 42.58 18.39 43.22 18.39C43.87 18.39 44.39 18.92 44.39 19.56C44.39 20.2 43.87 20.73 43.22 20.73ZM46.97 20.73C46.32 20.73 45.8 20.2 45.8 19.56C45.8 18.92 46.33 18.39 46.97 18.39C47.62 18.39 48.14 18.92 48.14 19.56C48.14 20.2 47.62 20.73 46.97 20.73Z",fill:"#9399A5"})]});function Qo(e,t){const n=x.get(e,t,"");if(n)throw new Error(n)}async function Y0(e,t,n,r={}){const a={"X-Requested-With":"XMLHttpRequest","Content-Type":r.string?"application/x-www-form-urlencoded":"application/json",...r.headers},o={baseURL:e,method:"POST",url:t,params:r.params,headers:a};return o.data=r.string?JSON.stringify(n):n,pt(o).then(l=>l.data).catch(l=>Promise.reject(l))}const Q0=({conf:e,panelData:t})=>async()=>{const{expertSystemURL:n,path:r,goal:a,question:o}=e;if(!r||!a||!o)return;const l=Dc(t);if(!l)return;const u={dashboard:a,panel:o,data:l};try{const c=n.startsWith("http")?n:window.location.origin;return await Y0(c,`/expert/v3/devtable/${r}`,u,{})}catch(c){throw Qo(c,"response.data.detail"),Qo(c,"response.data.error"),console.error(c),c}},_i={expertSystemURL:"",path:"",goal:"",question:""},ki={height:"100%",overflowY:"auto",...Vr},Uo=({message:e})=>i(s.Box,{sx:ki,children:i("div",{dangerouslySetInnerHTML:{__html:e},style:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45"}})}),U0=({error:e,width:t,height:n})=>{const r=e.message;if(r.startsWith("<"))return i(Uo,{message:r});const o=n-25-20-30;return i(s.Center,{sx:{width:"100%",height:o},children:p(s.Stack,{align:"center",spacing:20,children:[i(R0,{}),i(Uo,{message:r})]})})};function K0({context:e}){const{value:t}=R(e.instanceData,"config"),n=m.useMemo(()=>x.defaultsDeep({},t,_i),[t]),{width:r,height:a}=e.viewport,o=e.data,{data:l,error:u,loading:c}=Q.useRequest(Q0({conf:n,panelData:o}),{refreshDeps:[o,n]});return!r||!a||!n?null:c?i(s.Box,{sx:{position:"relative",height:a},children:i(s.LoadingOverlay,{visible:!0})}):u?i(s.Box,{sx:ki,"data-enable-scrollbar":!0,children:i(U0,{error:u,width:r,height:a})}):!l||!Array.isArray(l.replies)||l.replies.length===0?null:i(s.Box,{sx:ki,"data-enable-scrollbar":!0,children:l.replies.map((d,f)=>i("div",{dangerouslySetInnerHTML:{__html:d.interpretation.html}},f))})}function X0({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=m.useMemo(()=>x.defaultsDeep({},t,_i),[t]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});m.useEffect(()=>{c(r)},[r]),l(["expertSystemURL","goal","path","question"]);const d=u(),f=m.useMemo(()=>!x.isEqual(d,r),[d,r]);return i("form",{onSubmit:o(n),children:p(s.Stack,{children:[p(s.Group,{grow:!0,children:[i(v.Controller,{name:"expertSystemURL",control:a,render:({field:h})=>i(s.TextInput,{label:"Expert System URL",...h})}),i(v.Controller,{name:"path",control:a,render:({field:h})=>i(s.TextInput,{label:"Path",required:!0,...h})})]}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:"goal",control:a,render:({field:h})=>i(s.TextInput,{label:"Goal",required:!0,...h})}),i(v.Controller,{name:"question",control:a,render:({field:h})=>i(s.TextInput,{label:"Question",required:!0,...h})})]}),i(s.Divider,{variant:"dashed",mt:16,mb:8}),i(s.Button,{type:"submit",variant:"filled",color:"blue",leftIcon:i(I.DeviceFloppy,{size:20}),disabled:!f,sx:{alignSelf:"flex-end"},children:"Submit Changes"})]})})}class J0 extends ge{constructor(){super(...arguments);q(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const Z0={displayName:"Merico GQM",displayGroup:"Merico suite",migrator:new J0,name:"mericoGQM",viewRender:K0,configRender:X0,createConfig(){return{version:1,config:x.cloneDeep(_i)}}};function H0(e,t,n){if(!e)return n[0];try{return[t,U(t).add(1,"year").subtract(1,"day").valueOf()]}catch(r){return console.error(r),n[0]}}function ew(e,t,n){const r=H0(e,t,n);return{top:50,left:25,right:5,cellSize:["auto",13],range:r,itemStyle:{borderColor:"#eee"},splitLine:{show:!0},dayLabel:{firstDay:1},monthLabel:{position:"end"},yearLabel:{show:!0}}}function tw(e){return{heat_block:function(r){if(!e.heat_block.value_formatter)return r;try{return Z(r).format(e.heat_block.value_formatter)}catch(a){return console.error(a),r}}}}function nw(e,t){return{show:!e,selectedMode:"single",top:5,right:5,data:t.map(n=>({name:n,icon:"circle"}))}}function rw(e,t,n,r){const{calendar:a,heat_block:o}=e,l=P(a.data_key),u=P(o.data_key);return t?{type:"heatmap",name:"heatmap",coordinateSystem:"calendar",calendarIndex:0,data:r[l.queryID].map(c=>[x.get(c,l.columnKey),x.get(c,u.columnKey)])}:Object.entries(n).map(([c,d])=>({type:"heatmap",name:c,coordinateSystem:"calendar",calendarIndex:0,data:d.map(f=>[x.get(f,l.columnKey),x.get(f,u.columnKey)])}))}const iw=e=>{try{return Z(e).format({trimMantissa:!0,mantissa:2})}catch{return e}};function aw({conf:e,valueFormatters:t,dataDict:n,params:r}){const{value:a}=r,[o,l]=a,c=[{label:e.heat_block.name,value:t.heat_block(l),style:{label:"",value:""}}],d=n[o];return d&&e.tooltip.metrics.forEach(f=>{const h=P(f.data_key);c.push({label:f.name,value:iw(x.get(d,h.columnKey,"")),style:{label:"",value:""}})}),c}function sw(e,t,n){const r=P(e.calendar.data_key),a=x.keyBy(t[r.queryID],r.columnKey);return{confine:!0,formatter:function(o){const u=aw({conf:e,valueFormatters:n,dataDict:a,params:o}).map(f=>`
|
|
295
|
+
`}}function wx(){return{show:!0,trigger:"item",confine:!0,formatter:xx()}}const Cx={tooltip:{show:!0},series:{type:"sunburst",radius:[0,"90%"],emphasis:{focus:"ancestor"}}};function Sx(t,e,n){n.reduce((o,l)=>{const u=ot(l,e);return o[l.name]=Fe(l,u),o},{});const a={series:{data:yx(t,e),levels:vx(t)},tooltip:wx()};return x.defaultsDeep({},a,Cx)}Y.use([re.SunburstChart,_e.CanvasRenderer]);function _x({context:t}){const{variables:e}=t,{value:n}=V(t.instanceData,"config"),i=m.useMemo(()=>x.defaults({},n,ni),[n]),a=t.data,{width:o,height:l}=t.viewport,u=m.useMemo(()=>Sx(i,a,e),[i,a,e]);return!o||!l?null:r(Me,{width:o,height:l,children:r(Se,{echarts:Y,option:u,style:jt(o,l),notMerge:!0,theme:"merico-light"})})}function kx({control:t,watch:e}){return e(["label_key","value_key","group_key"]),d(s.Stack,{children:[r(v.Controller,{name:"label_key",control:t,render:({field:n})=>r(O,{label:"Label Key",required:!0,...n})}),r(v.Controller,{name:"value_key",control:t,render:({field:n})=>r(O,{label:"Value Key",required:!0,...n})}),r(v.Controller,{name:"group_key",control:t,render:({field:n})=>r(O,{label:"Group Key",clearable:!0,...n})})]})}const Tx=[{label:"Radial",value:"radial"},{label:"Tangential",value:"tangential"},{label:"None",value:"0"}],Dx=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Ix=({control:t,index:e,remove:n})=>d(s.Stack,{children:[d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`levels.${e}.r0`,control:t,render:({field:i})=>r(s.TextInput,{label:"Inside Radius",placeholder:"0%",...i})}),r(v.Controller,{name:`levels.${e}.r`,control:t,render:({field:i})=>r(s.TextInput,{label:"Outside Radius",placeholder:"50%",...i})})]}),r(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Label Style",labelPosition:"center"}),r(v.Controller,{name:`levels.${e}.label.show_label_tolerance`,control:t,render:({field:i})=>r(s.NumberInput,{label:"Hide label when its percentage is less than...",precision:4,step:5e-4,min:0,max:1,...i})}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`levels.${e}.label.rotate`,control:t,render:({field:i})=>r(s.Select,{label:"Rotate",data:Tx,...i})}),r(v.Controller,{name:`levels.${e}.label.align`,control:t,render:({field:i})=>r(s.Select,{label:"Align",data:Dx,...i})})]}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`levels.${e}.label.position`,control:t,render:({field:i})=>r(Ur,{label:"Position",...i})}),r(v.Controller,{name:`levels.${e}.label.padding`,control:t,render:({field:i})=>r(s.NumberInput,{label:"Padding",min:0,hideControls:!0,...i})})]}),r(s.Divider,{mb:-10,mt:10,variant:"dashed"}),r(s.Button,{leftIcon:r(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Level"})]}),Mx=({control:t,watch:e})=>{const{fields:n,append:i,remove:a}=v.useFieldArray({control:t,name:"levels"}),o=e("levels"),l=n.map((f,g)=>({...f,...o[g]})),u=()=>i({id:Date.now().toString(),r0:"",r:"",label:{show_label_tolerance:.001,rotate:"0",align:"center",position:"inside",padding:0}}),c=e("levels.0.id"),[p,h]=m.useState(()=>c??null);return m.useEffect(()=>{c&&h(f=>f!==null?f:c)},[c]),d(z,{children:[d(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[r(T.InfoCircle,{size:14,color:"#888"}),r(s.Text,{size:14,color:"#888",children:"Configure ring style on each level"})]}),r(s.Divider,{variant:"dashed",my:10}),d(s.Tabs,{value:p,onTabChange:f=>h(f),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[d(s.Tabs.List,{children:[l.map((f,g)=>r(s.Tabs.Tab,{value:f.id,children:g},f.id)),r(s.Tabs.Tab,{onClick:u,value:"add",children:r(T.Plus,{size:18,color:"#228be6"})})]}),l.map((f,g)=>r(s.Tabs.Panel,{value:f.id,children:r(Ix,{control:t,index:g,remove:a},f.id)},f.id))]})]})};function Ax({context:t}){const{value:e,set:n}=V(t.instanceData,"config"),i=m.useMemo(()=>x.defaultsDeep({},e,ni),[e]),a=m.useMemo(()=>x.clone(i),[i]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:p}=v.useForm({defaultValues:a});m.useEffect(()=>{p(a)},[a]);const h=c(),f=m.useMemo(()=>!x.isEqual(h,i),[h,i]);u(["label_key","value_key","group_key","levels"]);const[g,b]=m.useState("Data");return r("form",{onSubmit:l(n),children:d(s.Stack,{spacing:"xs",children:[d(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(s.Text,{children:"Sunburst Config"}),r(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:r(T.DeviceFloppy,{size:20})})]}),d(s.Tabs,{value:g,onTabChange:b,orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[d(s.Tabs.List,{children:[r(s.Tabs.Tab,{value:"Data",children:"Data"}),r(s.Tabs.Tab,{value:"Levels",children:"Levels"})]}),r(s.Tabs.Panel,{value:"Data",children:r(kx,{control:o,watch:u})}),r(s.Tabs.Panel,{value:"Levels",children:r(Mx,{control:o,watch:u})})]})]})})}function zx(t){const{label_field:e,value_field:n,...i}=t;return{...i,label_key:e,value_key:n}}function Ex(t){const{group_key:e="",...n}=t;return{...n,group_key:e}}function Px(t){const{levels:e=[],...n}=t;return{...n,levels:e}}function Lx(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=c=>c&&`${n}.${c}`,{label_key:a,value_key:o,group_key:l,...u}=t;return{...u,label_key:i(a),value_key:i(o),group_key:i(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class Bx extends se{constructor(){super(...arguments);P(this,"VERSION",5)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:zx(n.config)})),this.version(3,n=>({...n,version:3,config:Ex(n.config)})),this.version(4,n=>({...n,version:4,config:Px(n.config)})),this.version(5,(n,i)=>({...n,version:5,config:Lx(n.config,i)}))}}const Ox={displayName:"Sunburst Chart",displayGroup:"ECharts-based charts",migrator:new Bx,name:"sunburst",viewRender:_x,configRender:Ax,createConfig(){return{version:5,config:x.cloneDeep(ni)}}};var Ke=(t=>(t.string="string",t.number="number",t.eloc="eloc",t.percentage="percentage",t.custom="custom",t))(Ke||{});const Ws=["function text({ value }) {"," // your code goes here"," return value","}"].join(`
|
|
296
|
+
`),Rs={columns:[],fontSize:"14px",highlightOnHover:!0,horizontalSpacing:"14px",id_field:"",striped:!0,use_raw_columns:!0,verticalSpacing:"14px"},Qs={left:"flex-start",center:"center",right:"flex-end"},$x=({header:t,cx:e})=>{const n=x.get(t.column.columnDef.meta,"align","left");return d(s.Text,{className:e("table-head-cell",{"table-head-cell--sortable":t.column.getCanSort()}),onClick:t.column.getToggleSortingHandler(),align:n,sx:{justifyContent:Qs[n]},children:[t.isPlaceholder?null:We.flexRender(t.column.columnDef.header,t.getContext()),r(Vx,{direction:t.column.getIsSorted()})]})},Vx=({direction:t})=>{switch(t){case"asc":return r(M.IconArrowUp,{size:16});case"desc":return r(M.IconArrowDown,{size:"1em"});default:return null}},Nx=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"}})),qx={tableLayout:"fixed","thead, tbody":{tr:{"th, td":{padding:"2px 10px",div:{overflow:"hidden",textOverflow:"ellipsis"},"&:first-of-type":{paddingLeft:2,paddingRight:2}}}}},Gx=s.createStyles((t,e)=>({content:{display:"flex",alignItems:"center",justifyContent:Qs[e.align],".table-cell-text":{whiteSpace:"nowrap",cursor:e.clickable?"pointer":"default",textDecoration:e.clickable?"underline":"none"}}}));function Fx(t){return t?rt(t).oklch()[0]>.7?"black":"white":"inherit"}function jx(t){const e=t.tableCellContext.bgColor;return{backgroundColor:e,color:Fx(e)}}function Lt(t){const e=t.tableCellContext.isClickable(),n=Gx({clickable:e,align:t.align});return r("div",{className:n.classes.content,style:{...jx(t)},children:r(s.Text,{className:"table-cell-text",onClick:t.tableCellContext.getClickHandler(),children:r("span",{title:t.children,children:t.children})})})}function Wx(t){return r(Lt,{...t,children:t.value})}function Rx(t){const e=W(t.value).format({average:!0,mantissa:2,trimMantissa:!0});return r(Lt,{...t,children:e})}function Qx(t){const e=W(t.value).format({thousandSeparated:!0});return r(Lt,{...t,children:e})}function Ux(t){const e=W(t.value).format({output:"percent",mantissa:3,trimMantissa:!0});return r(Lt,{...t,children:e})}function Kx(t){const e=t.value,n=t.func_content;if(!n)return r(Lt,{...t,children:e});const i=new Function(`return ${n}`)()({value:e});return r(Lt,{...t,children:i})}function Yx(t){switch(t.type){case Ke.string:return r(Wx,{...t});case Ke.eloc:return r(Rx,{...t});case Ke.number:return r(Qx,{...t});case Ke.percentage:return r(Ux,{...t});case Ke.custom:return r(Kx,{...t})}}function Xx({tableContainerRef:t,rows:e}){var u,c;const n=au.useVirtual({parentRef:t,size:e.length,estimateSize:m.useCallback(()=>28,[]),overscan:20}),{virtualItems:i,totalSize:a}=n,o=i.length>0&&((u=i==null?void 0:i[0])==null?void 0:u.start)||0,l=i.length>0?a-(((c=i==null?void 0:i[i.length-1])==null?void 0:c.end)||0):0;return q.useWhyDidYouUpdate("TableBody",{tableContainerRef:t,rows:e}),d("tbody",{children:[o>0&&r("tr",{children:r("td",{style:{height:`${o}px`}})}),i.map(p=>{const h=e[p.index];return r("tr",{children:h.getVisibleCells().map(f=>r("td",{children:We.flexRender(f.column.columnDef.cell,f.getContext())},f.id))},h.id)}),l>0&&r("tr",{children:r("td",{style:{height:`${l}px`}})})]})}const ri={id:"builtin:table:click-cell-content",displayName:"Click Cell Content",nameRender:ew,configRender:Zx,payload:[{name:"row_index",description:"Index of the row that the cell belongs to",valueType:"number"},{name:"col_index",description:"Index of the column that the cell belongs to",valueType:"number"},{name:"row_data",description:"Data of the row that the cell belongs to",valueType:"object"}]},Jx={column:""};function Us(t,e){const{value:n}=V(t.instanceData,"config"),i={columnsFromConfig:[],columnsFromData:[]};if(n&&(i.columnsFromConfig=n.columns.map((a,o)=>({label:a.label,value:o.toString()}))),!e)return i;if(n!=null&&n.id_field){const a=Wt(e,n.id_field);(a==null?void 0:a.length)>0&&(i.columnsFromData=Object.keys(a[0]).map(o=>({label:o,value:o})))}return i}function Zx(t){const{columnsFromConfig:e,columnsFromData:n}=Us(t.instance,t.sampleData),i=e.length>0?e:n,{value:a,set:o}=V(t.trigger.triggerData,"config"),{column:l}=x.defaults({},a,Jx),u=c=>{isNaN(+c)?o({column:c}):o({column:+c})};return r(s.Select,{clearable:!1,data:i,label:"Choose a column",value:l.toString(),onChange:u})}function Hx(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 ew(t){const{columnsFromConfig:e}=Us(t.instance),{value:n}=V(t.trigger.triggerData,"config");return r(s.Text,{children:Hx(n,e)})}function Ks(t,e,n){return Math.min(Math.max(t,e),n)}class tw{constructor(e){this.steps=e;const n=[],i=new Set;for(const a of e)i.has(a.to)||(n.push(a),i.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 i=(n.to-e.to)/(n.from-e.from),a=e.to-i*e.from;return o=>i*o+a}getStepFunctionForValue(e){let n=x.findLastIndex(this.steps,i=>i.from<=e);return n=Ks(n,0,this.steps.length-2),this.getLinearFunction(this.steps[n],this.steps[n+1])}mapValue(e){return Ks(this.getStepFunctionForValue(e)(e),0,100)}}class nw{constructor(e,n,i,a,o){this.getColIndex=e,this.cell=n,this.triggers=i,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 i of e)this.interactionManager.runInteraction(i.id,n)}}getRelatedTrigger(){return this.triggers.filter(n=>n.schemaRef===ri.id).filter(n=>{const i=this.getColIndex(this.cell),a=x.get(this.cell.column.columnDef.meta,"value_field"),o=x.get(n.config,"column");return o==i||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 i=this.colorManager.decodeInterpolation(e.interpolation),o=new tw(e.steps).mapValue(n);return i==null?void 0:i.getColor(o)}}}const rw=t=>{const e=qe(t),n=Ne(e.triggerManager,ri.id),{colorManager:i}=m.useContext(tt);return m.useCallback(a=>new nw(t.getColIndex,a,n,e,i),[n,e,t.getColIndex])};function iw({queryData:t,width:e,height:n,conf:i,context:a,instance:o}){const{id_field:l,use_raw_columns:u,columns:c,...p}=i,{classes:h,cx:f}=Nx(),g=m.useMemo(()=>u?!Array.isArray(t)||t.length===0?[]:Object.keys(t[0]).map(me=>({id:me,label:me,value_field:me,value_type:Ke.string,align:"left",width:"",cellBackgroundColor:""})):c,[u,c,t]),b=rw({getColIndex:m.useCallback(me=>g.indexOf(me.column.columnDef.meta),[g]),vizManager:a.vizManager,instance:o}),w=m.useMemo(()=>{const me=We.createColumnHelper();return g.map(Ye=>{const Li=xc(Ye.value_field);return me.accessor(Li.columnKey,{cell:rn=>r(Yx,{tableCellContext:b(rn.cell),value:rn.getValue(),type:Ye.value_type,...Ye}),header:Ye.label,enableSorting:!0,meta:Ye,size:typeof Ye.width=="number"?Ye.width:void 0,minSize:typeof Ye.width=="number"?Ye.width:void 0})})},[g,b]),[_,D]=m.useState([]),L=We.useReactTable({data:t,state:{sorting:_},onSortingChange:D,columns:w,getCoreRowModel:We.getCoreRowModel(),getSortedRowModel:We.getSortedRowModel()}),{rows:N}=L.getRowModel(),J=m.useRef(null),ae=N.length,K=ae>0,oe=K?n-22:n,pe=K?22:0;return q.useWhyDidYouUpdate("VizTableComponent",{queryData:t,width:e,height:n,conf:i,context:a,instance:o,finalColumns:g,getCellContext:b,tableColumns:w,table:L,rows:N,tableContainerRef:J}),d("div",{ref:J,style:{height:n,width:e,padding:"0 5px"},"data-enable-scrollbar":!0,className:f(h.root,{"table-highlight-on-hover":i.highlightOnHover}),children:[ae>0&&r(s.Box,{className:h.info_bar,sx:{height:22},children:d(s.Text,{align:"right",pr:6,size:14,color:"dimmed",fw:"normal",children:["Total: ",ae]})}),d(s.Table,{sx:{...qx,maxHeight:oe},...p,striped:i.striped,children:[r("thead",{className:h.thead,style:{top:pe},children:L.getHeaderGroups().map(me=>r("tr",{children:me.headers.map(St=>r("th",{style:{width:St.getSize()},children:r($x,{header:St,cx:f})},St.id))},me.id))}),r(Xx,{tableContainerRef:J,rows:N})]})]})}function aw({data:t,width:e,height:n,conf:i,context:a,instance:o}){const{id_field:l,use_raw_columns:u,columns:c}=i,p=m.useMemo(()=>{if(!l)return[];const h=A(l);return t[h.queryID]},[t,l]);return!Array.isArray(p)||p.length===0?r(s.Text,{color:"gray",align:"center",children:"Empty Data"}):r(iw,{queryData:p,width:e,height:n,conf:i,context:a,instance:o})}function sw({context:t,instance:e}){const n=t.data,{height:i,width:a}=t.viewport,{value:o}=V(t.instanceData,"config");return o?o.id_field?r(aw,{data:n,width:a,height:i,conf:o,context:t,instance:e}):r(s.Text,{color:"red",align:"center",children:"ID Field is not set, can't render a table without it"}):null}const Ys=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)"}}}})),ow=[{from:0,to:0},{from:100,to:100}];class lw{constructor(){P(this,"steps",new Map);P(this,"interpolation");P(this,"onChange");Q.makeAutoObservable(this,{steps:Q.observable},{deep:!1}),Q.reaction(()=>Q.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,i])=>({to:n,from:i})).sort((n,i)=>n.to-i.to||n.from-i.from))}fromProps(e){e.steps.length<2?this.setSteps(ow):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 uw(t){const{onChange:e,color:n,index:i,value:a}=t,{classes:o}=Ys(),[l,u]=m.useState(a),[c,{setTrue:p,setFalse:h}]=q.useBoolean(!1),f=i%2===1,g=f&&a!=null,b=!f&&a!=null,w=`map ${a} to color ${i}`,_=()=>{u(a),h()},D=()=>{h(),e==null||e(l)},L=W(a).format({average:!0});return d("div",{"data-testid":`palette-item-${i}`,className:o.paletteItem,children:[r(s.Text,{title:w,style:{opacity:g?1:0},color:"dimmed",size:"sm",className:"palette-value--up palette-value",children:L}),d(s.Popover,{width:200,trapFocus:!0,opened:c,onClose:h,children:[r(s.Popover.Target,{children:r("div",{"data-testid":"palette-item-target",className:"palette-item",onClick:p,style:{"--shadow-color":rt(n).alpha(.5).hex(),backgroundColor:n}})}),r(s.Popover.Dropdown,{children:d(s.Stack,{children:[r(s.NumberInput,{size:"xs",label:"Map a value to this color",value:l,onChange:u}),d(s.Group,{position:"right",children:[r(s.Button,{variant:"subtle",size:"xs",onClick:_,children:"Cancel"}),r(s.Button,{"data-testid":"palette-item-ok",size:"xs",onClick:D,children:"OK"})]})]})})]}),r(s.Text,{title:w,style:{opacity:b?1:0},color:"dimmed",size:"sm",className:"palette-value--bottom palette-value",children:L})]})}const cw=k.observer(({model:t})=>{const{classes:e}=Ys(),n=x.range(0,13,1).map(i=>100/12*i).map(i=>[t.interpolation.getColor(i),i]);return r("div",{className:e.palette,children:n.map(([i,a],o)=>r(uw,{index:o,color:i,value:t.getStepFromValue(a),onChange:l=>t.changeStep(l,a)},i))})}),dw=k.observer(function(e){const n=q.useCreation(()=>new lw,[]);return m.useEffect(()=>{n.fromProps(e)}),n.interpolation==null?null:r(cw,{model:n})}),pw=t=>{const{value:e,onChange:n,colorManager:i}=t,a=i.getColorInterpolations(),[o,l]=m.useState(e),u=i.decodeInterpolation(o.interpolation)||a[0],[c,{setTrue:p,setFalse:h}]=q.useBoolean(),f=a.map(D=>({label:D.displayName,value:i.encodeColor(D),group:D.category}));function g(D){D&&l(L=>({...L,interpolation:D}))}const b=()=>{h(),n==null||n(Q.toJS(o))};function w(D){l(L=>({...L,steps:D}))}const _=()=>{h(),l(e)};return d(z,{children:[r(s.Button,{variant:"outline",onClick:p,children:u==null?void 0:u.displayName}),r(s.Modal,{size:508,title:"Setup color interpolation",opened:c,onClose:h,zIndex:320,children:c&&d(s.Stack,{"data-testid":"color-interpolation-modal",children:[r(s.Select,{label:"Color style",value:o.interpolation,data:f,onChange:g,withinPortal:!0,zIndex:340,maxDropdownHeight:500}),r(dw,{steps:o.steps,interpolation:u,onChange:w}),d(s.Group,{position:"right",children:[r(s.Button,{onClick:_,variant:"subtle",children:"Cancel"}),r(s.Button,{onClick:b,children:"OK"})]})]})})]})},hw=["static","interpolation","none"].map(t=>({label:x.capitalize(t),value:t})),fw=[{from:0,to:0},{from:100,to:100}];function Xs(t){return t?x.isString(t)?t==="none"?"none":"static":"interpolation":"none"}function gw(t,e){var n;return Xs(e)==="static"?e:(n=t.getStaticColors()[0])==null?void 0:n.value}function mw(t,e){return x.isObject(e)?e:{steps:fw,interpolation:t.encodeColor(t.getColorInterpolations()[0])}}const yw=m.forwardRef((t,e)=>{const{colorManager:n}=m.useContext(tt),[i,a]=m.useState(Xs(t.value)),[o,l]=m.useState(gw(n,t.value)),u=q.useLatest(o),[c,p]=m.useState(mw(n,t.value)),h=q.useLatest(c),f=w=>{var _,D,L;a(w||"none"),w==="static"?(_=t.onChange)==null||_.call(t,u.current):w==="none"||!w?(D=t.onChange)==null||D.call(t,"none"):(L=t.onChange)==null||L.call(t,h.current)},g=w=>{var _;l(w),(_=t.onChange)==null||_.call(t,w)},b=w=>{var _;p(w),(_=t.onChange)==null||_.call(t,w)};return d(s.Stack,{align:"stretch",children:[r(s.Select,{label:"Cell background",value:i||"none",onChange:f,data:hw}),i==="static"&&r(Te,{value:o,onChange:g}),i==="interpolation"&&r(pw,{colorManager:n,value:c,onChange:b})]})}),bw={[Ke.eloc]:"ELOC"},vw=Object.values(Ke).map(t=>({label:x.get(bw,t,x.capitalize(t)),value:t})),xw=m.forwardRef(({label:t,value:e,onChange:n,sx:i},a)=>r(s.Select,{ref:a,label:t,data:vw,value:e,onChange:n,sx:i})),ww=m.forwardRef(({value:t,onChange:e},n)=>{const[i,{setTrue:a,setFalse:o}]=q.useBoolean(),[l,u]=m.useState(t),c=()=>{o(),e(l)},p=()=>{o(),u(t)},h=()=>{u(Ws)};return m.useEffect(()=>{u(t)},[t]),d(z,{children:[r(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Custom Cell Content"}),r(s.Modal,{size:800,title:"Custom cell content",opened:i,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:i&&d(s.Stack,{children:[r(s.Box,{sx:{position:"relative"},children:r(ve,{height:"500px",defaultLanguage:"javascript",value:l,onChange:f=>u(f??""),theme:"vs-dark",options:{minimap:{enabled:!1}}})}),d(s.Group,{position:"apart",children:[r(s.Button,{onClick:h,color:"red",leftIcon:r(T.Recycle,{size:20}),children:"Reset"}),d(s.Group,{position:"right",children:[r(s.Button,{onClick:p,variant:"subtle",children:"Cancel"}),r(s.Button,{onClick:c,children:"OK"})]})]})]})})]})}),Cw=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],ii=()=>r(s.Text,{color:"dimmed",size:12,children:"px"}),Sw=({control:t,index:e,watch:n,remove:i,column:a})=>{const o=n(`columns.${e}.value_type`);return d(s.Stack,{my:0,sx:{position:"relative"},children:[d(s.Group,{grow:!0,children:[r(v.Controller,{name:`columns.${e}.label`,control:t,render:({field:l})=>r(s.TextInput,{label:"Label",required:!0,id:`col-label-${e}`,sx:{flex:1},...l})}),r(v.Controller,{name:`columns.${e}.value_field`,control:t,render:({field:l})=>r(O,{label:"Value Field",required:!0,...l})})]}),d(s.Group,{grow:!0,children:[r(v.Controller,{name:`columns.${e}.value_type`,control:t,render:({field:l})=>r(xw,{label:"Value Type",sx:{flex:1},...l})}),o===Ke.custom&&r(v.Controller,{name:`columns.${e}.func_content`,control:t,render:({field:l})=>r(ww,{value:l.value??Ws,onChange:u=>l.onChange(u??"")})})]}),r(s.Divider,{mb:-10,variant:"dashed",label:"Style",labelPosition:"center"}),d(s.Group,{grow:!0,children:[r(s.NumberInput,{hideControls:!0,label:"Min Width",rightSection:r(ii,{}),disabled:!0}),r(v.Controller,{name:`columns.${e}.width`,control:t,render:({field:l})=>r(s.NumberInput,{hideControls:!0,label:"Width",rightSection:r(ii,{}),...l})}),r(s.NumberInput,{hideControls:!0,label:"Max Width",rightSection:r(ii,{}),disabled:!0})]}),r(s.Group,{grow:!0,noWrap:!0,children:r(v.Controller,{name:`columns.${e}.align`,control:t,render:({field:l})=>r(s.Select,{label:"Alignment",data:Cw,...l})})}),r(v.Controller,{name:`columns.${e}.cellBackgroundColor`,control:t,render:({field:l})=>r(yw,{...l})}),r(s.Divider,{mb:4,mt:12,variant:"dashed"}),r(s.Button,{leftIcon:r(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>i(e),children:"Delete this column"})]})},_w=({control:t,watch:e})=>{const{fields:n,append:i,remove:a,update:o}=v.useFieldArray({control:t,name:"columns"}),l=()=>{const c=ye.randomId();i({id:c,label:c,align:"center",value_field:"",value_type:Ke.string,width:""})};e("columns");const u=e("use_raw_columns");return d(z,{children:[r(v.Controller,{name:"use_raw_columns",control:t,render:({field:c})=>r(s.Switch,{mt:20,mb:20,label:"Use Original Data Columns",checked:c.value,onChange:p=>c.onChange(p.currentTarget.checked)})}),!u&&r(s.Stack,{children:d(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[d(s.Tabs.List,{children:[n.map((c,p)=>r(s.Tabs.Tab,{value:p.toString(),children:p+1},c.id)),r(s.Tabs.Tab,{onClick:l,value:"add",children:r(T.Plus,{size:18,color:"#228be6"})})]}),n.map((c,p)=>r(s.Tabs.Panel,{value:p.toString(),children:r(Sw,{control:t,watch:e,index:p,column:c,remove:a})},c.id))]})})]})};function kw({control:t,watch:e}){return e(["horizontalSpacing","verticalSpacing","fontSize","striped","highlightOnHover"]),d(s.Stack,{spacing:"xs",children:[d(s.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:[r(v.Controller,{name:"horizontalSpacing",control:t,render:({field:n})=>r(s.TextInput,{label:"Horizontal Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})}),r(v.Controller,{name:"verticalSpacing",control:t,render:({field:n})=>r(s.TextInput,{label:"Vertical Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})})]}),r(s.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:r(v.Controller,{name:"fontSize",control:t,render:({field:n})=>r(s.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})})}),d(s.Group,{position:"apart",grow:!0,children:[r(v.Controller,{name:"striped",control:t,render:({field:n})=>r(s.Switch,{label:"Striped",checked:n.value,onChange:i=>n.onChange(i.currentTarget.checked)})}),r(v.Controller,{name:"highlightOnHover",control:t,render:({field:n})=>r(s.Switch,{label:"Highlight on hover",checked:n.value,onChange:i=>n.onChange(i.currentTarget.checked)})})]})]})}function Tw({columns:t,...e}){return{...e,columns:t.map(({id:n,...i})=>({id:n??ye.randomId(),...i}))}}function Dw({context:t}){const{value:e,set:n}=V(t.instanceData,"config"),i=m.useMemo(()=>x.defaultsDeep({},e,Rs),[e]),a=m.useMemo(()=>Tw(i),[i]);m.useEffect(()=>{!x.isEqual(i,a)&&(console.log("config malformed, resetting to defaults",i,a),n(a))},[i,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:p}=v.useForm({defaultValues:a});m.useEffect(()=>{p(a)},[a]);const h=c(),f=m.useMemo(()=>!x.isEqual(h,i),[h,i]);return u(["id_field"]),d("form",{onSubmit:l(n),children:[d(s.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(s.Text,{children:"Table Config"}),r(s.ActionIcon,{type:"submit","aria-label":"save config",mr:5,variant:"filled",color:"blue",disabled:!f,children:r(T.DeviceFloppy,{size:20})})]}),d(s.Tabs,{defaultValue:"Columns",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[d(s.Tabs.List,{children:[r(s.Tabs.Tab,{value:"Columns",children:"Columns"}),r(s.Tabs.Tab,{value:"Style",children:"Style"})]}),d(s.Tabs.Panel,{value:"Columns",children:[r(v.Controller,{name:"id_field",control:o,render:({field:g})=>r(O,{label:"ID Field",required:!0,...g})}),r(s.Divider,{mt:20,mb:10,variant:"dashed"}),r(_w,{control:o,watch:u})]}),r(s.Tabs.Panel,{value:"Style",children:r(kw,{control:o,watch:u})})]})]})}function Iw(t){const{columns:e,...n}=t;return{...t,columns:e.map(i=>({...i,align:i.align??"left"}))}}function Mw(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=u=>u&&`${n}.${u}`,{id_field:a,columns:o,...l}=t;return{...l,id_field:i(a),columns:o.map(u=>({...u,value_field:i(u.value_field)}))}}catch(n){throw console.error("[Migration failed]",n),n}}function Aw(t){const{columns:e,...n}=t;return{...n,columns:e.map(i=>({...i,align:i.align??"left",cellBackgroundColor:i.cellBackgroundColor??"",width:i.width??""}))}}class zw extends se{constructor(){super(...arguments);P(this,"VERSION",5)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{columns:i,...a}=n.config;return{...n,version:2,config:{...a,columns:i.map(({id:o,...l})=>({id:o??ye.randomId(),...l}))}}}),this.version(3,n=>({...n,version:3,config:Iw(n.config)})),this.version(4,(n,i)=>({...n,version:4,config:Mw(n.config,i)})),this.version(5,n=>({...n,version:5,config:Aw(n.config)}))}}const ai={createConfig(){return{version:5,config:x.cloneDeep(Rs)}},displayName:"Table",displayGroup:"Others",migrator:new zw,name:"table",viewRender:sw,configRender:Dw,triggers:[ri]},Js=["function text({ data, variables, filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
|
|
297
|
+
`),si={func_content:Js,horizontal_align:"left",font_size:"14px",font_weight:"normal"},Ew=k.observer(({context:t})=>{const e=ue(),{value:n=si}=V(t.instanceData,"config"),{variables:i}=t,a=t.data,{func_content:o,horizontal_align:l,font_size:u,font_weight:c}=n,p=m.useMemo(()=>i.reduce((f,g)=>{const b=ot(g,a);return f[g.name]=Fe(g,b),f},{}),[i,a]),h=m.useMemo(()=>new Function(`return ${o}`)()({data:a,variables:p,filters:e.payloadForSQL.filters,context:e.payloadForSQL.context}),[o,a,p,e.payloadForSQL]);return r(s.Text,{align:l,weight:c,sx:{fontSize:u},children:h})}),Pw=({value:t,onChange:e})=>{const n=i=>{i&&e(i)};return r(s.Box,{sx:{position:"relative"},children:r(ve,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Lw=m.forwardRef(({value:t,onChange:e},n)=>{const[i,{setTrue:a,setFalse:o}]=q.useBoolean(),[l,u]=m.useState(t),c=()=>{o(),e(l)},p=()=>{o(),u(t)},h=()=>{u(Js)};return m.useEffect(()=>{u(t)},[t]),d(z,{children:[r(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Edit Content"}),r(s.Modal,{size:800,title:"Text content",opened:i,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:i&&d(s.Stack,{children:[r(Pw,{value:l,onChange:u}),d(s.Group,{position:"apart",children:[r(s.Button,{onClick:h,color:"red",leftIcon:r(T.Recycle,{size:20}),children:"Reset"}),d(s.Group,{position:"right",children:[r(s.Button,{onClick:p,variant:"subtle",children:"Cancel"}),r(s.Button,{onClick:c,children:"OK"})]})]})]})})]})}),Bw=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}];function Ow({context:t}){const{value:e,set:n}=V(t.instanceData,"config"),i=m.useMemo(()=>x.defaultsDeep({},e,si),[e]),a=m.useMemo(()=>{const{func_content:g,horizontal_align:b,font_size:w,font_weight:_}=i;return{func_content:g,horizontal_align:b,font_size:w,font_weight:_}},[i]);m.useEffect(()=>{!x.isEqual(i,a)&&(console.log("config malformed, resetting to defaults",i,a),n(a))},[i,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:p}=v.useForm({defaultValues:a});m.useEffect(()=>{p(a)},[a]),u(["func_content","horizontal_align","font_size","font_weight"]);const h=c(),f=m.useMemo(()=>!x.isEqual(h,i),[h,i]);return r(s.Stack,{spacing:"xs",children:d("form",{onSubmit:l(n),children:[d(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(s.Text,{weight:500,children:"Configurations"}),r(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:r(T.DeviceFloppy,{size:20})})]}),d(s.Stack,{spacing:10,children:[r(v.Controller,{name:"func_content",control:o,render:({field:g})=>r(Lw,{...g})}),r(s.Divider,{mt:10,mb:-10,variant:"dashed",label:"Style",labelPosition:"center"}),r(v.Controller,{name:"horizontal_align",control:o,render:({field:g})=>r(s.Select,{label:"Horizontal Alignment",data:Bw,...g})}),r(v.Controller,{name:"font_size",control:o,render:({field:g})=>r(s.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1},...g})}),r(s.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:r(v.Controller,{name:"font_weight",control:o,render:({field:g})=>r(ps,{label:"Font Weight",...g})})})]})]})})}class $w extends se{constructor(){super(...arguments);P(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const Vw={displayName:"Text",displayGroup:"Others",migrator:new $w,name:"text",viewRender:Ew,configRender:Ow,createConfig(){return{version:1,config:x.cloneDeep(si)}}},Nw=()=>d("svg",{width:"64",height:"64",viewBox:"0 0 64 64",fill:"none",children:[r("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"}),r("path",{d:"M18.39 32.28H16.51V35.02H18.39V32.28Z",fill:"#9399A5"}),r("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 Zs(t,e){const n=x.get(t,e,"");if(n)throw new Error(n)}async function qw(t,e,n,i={}){const a={"X-Requested-With":"XMLHttpRequest","Content-Type":i.string?"application/x-www-form-urlencoded":"application/json",...i.headers},o={baseURL:t,method:"POST",url:e,params:i.params,headers:a};return o.data=i.string?JSON.stringify(n):n,nt(o).then(l=>l.data).catch(l=>Promise.reject(l))}const Gw=({conf:t,panelData:e})=>async()=>{const{expertSystemURL:n,path:i,goal:a,question:o}=t;if(!i||!a||!o)return;const l=wc(e);if(!l)return;const u={dashboard:a,panel:o,data:l};try{const c=n.startsWith("http")?n:window.location.origin;return await qw(c,`/expert/v3/devtable/${i}`,u,{})}catch(c){throw Zs(c,"response.data.detail"),Zs(c,"response.data.error"),console.error(c),c}},oi={expertSystemURL:"",path:"",goal:"",question:""},li={height:"100%",overflowY:"auto",...wr},Hs=({message:t})=>r(s.Box,{sx:li,children:r("div",{dangerouslySetInnerHTML:{__html:t},style:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45"}})}),Fw=({error:t,width:e,height:n})=>{const i=t.message;if(i.startsWith("<"))return r(Hs,{message:i});const o=n-25-20-30;return r(s.Center,{sx:{width:"100%",height:o},children:d(s.Stack,{align:"center",spacing:20,children:[r(Nw,{}),r(Hs,{message:i})]})})};function jw({context:t}){const{value:e}=V(t.instanceData,"config"),n=m.useMemo(()=>x.defaultsDeep({},e,oi),[e]),{width:i,height:a}=t.viewport,o=t.data,{data:l,error:u,loading:c}=q.useRequest(Gw({conf:n,panelData:o}),{refreshDeps:[o,n]});return!i||!a||!n?null:c?r(s.Box,{sx:{position:"relative",height:a},children:r(s.LoadingOverlay,{visible:!0})}):u?r(s.Box,{sx:li,"data-enable-scrollbar":!0,children:r(Fw,{error:u,width:i,height:a})}):!l||!Array.isArray(l.replies)||l.replies.length===0?null:r(s.Box,{sx:li,"data-enable-scrollbar":!0,children:l.replies.map((p,h)=>r("div",{dangerouslySetInnerHTML:{__html:p.interpretation.html}},h))})}function Ww({context:t}){const{value:e,set:n}=V(t.instanceData,"config"),i=m.useMemo(()=>x.defaultsDeep({},e,oi),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:i});m.useEffect(()=>{c(i)},[i]),l(["expertSystemURL","goal","path","question"]);const p=u(),h=m.useMemo(()=>!x.isEqual(p,i),[p,i]);return r("form",{onSubmit:o(n),children:d(s.Stack,{children:[d(s.Group,{grow:!0,children:[r(v.Controller,{name:"expertSystemURL",control:a,render:({field:f})=>r(s.TextInput,{label:"Expert System URL",...f})}),r(v.Controller,{name:"path",control:a,render:({field:f})=>r(s.TextInput,{label:"Path",required:!0,...f})})]}),d(s.Group,{grow:!0,children:[r(v.Controller,{name:"goal",control:a,render:({field:f})=>r(s.TextInput,{label:"Goal",required:!0,...f})}),r(v.Controller,{name:"question",control:a,render:({field:f})=>r(s.TextInput,{label:"Question",required:!0,...f})})]}),r(s.Divider,{variant:"dashed",mt:16,mb:8}),r(s.Button,{type:"submit",variant:"filled",color:"blue",leftIcon:r(T.DeviceFloppy,{size:20}),disabled:!h,sx:{alignSelf:"flex-end"},children:"Submit Changes"})]})})}class Rw extends se{constructor(){super(...arguments);P(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const Qw={displayName:"Merico GQM",displayGroup:"Merico suite",migrator:new Rw,name:"mericoGQM",viewRender:jw,configRender:Ww,createConfig(){return{version:1,config:x.cloneDeep(oi)}}};function Uw(t,e,n){if(!t)return n[0];try{return[e,G(e).add(1,"year").subtract(1,"day").valueOf()]}catch(i){return console.error(i),n[0]}}function Kw(t,e,n){const i=Uw(t,e,n);return{top:50,left:25,right:5,cellSize:["auto",13],range:i,itemStyle:{borderColor:"#eee"},splitLine:{show:!0},dayLabel:{firstDay:1},monthLabel:{position:"end"},yearLabel:{show:!0}}}function Yw(t){return{heat_block:function(i){if(!t.heat_block.value_formatter)return i;try{return W(i).format(t.heat_block.value_formatter)}catch(a){return console.error(a),i}}}}function Xw(t,e){return{show:!t,selectedMode:"single",top:5,right:5,data:e.map(n=>({name:n,icon:"circle"}))}}function Jw(t,e,n,i){const{calendar:a,heat_block:o}=t,l=A(a.data_key),u=A(o.data_key);return e?{type:"heatmap",name:"heatmap",coordinateSystem:"calendar",calendarIndex:0,data:i[l.queryID].map(c=>[x.get(c,l.columnKey),x.get(c,u.columnKey)])}:Object.entries(n).map(([c,p])=>({type:"heatmap",name:c,coordinateSystem:"calendar",calendarIndex:0,data:p.map(h=>[x.get(h,l.columnKey),x.get(h,u.columnKey)])}))}const Zw=t=>{try{return W(t).format({trimMantissa:!0,mantissa:2})}catch{return t}};function Hw({conf:t,valueFormatters:e,dataDict:n,params:i}){const{value:a}=i,[o,l]=a,c=[{label:t.heat_block.name,value:e.heat_block(l),style:{label:"",value:""}}],p=n[o];return p&&t.tooltip.metrics.forEach(h=>{const f=A(h.data_key);c.push({label:h.name,value:Zw(x.get(p,f.columnKey,"")),style:{label:"",value:""}})}),c}function eC(t,e,n){const i=A(t.calendar.data_key),a=x.keyBy(e[i.queryID],i.columnKey);return{confine:!0,formatter:function(o){const u=Hw({conf:t,valueFormatters:n,dataDict:a,params:o}).map(h=>`
|
|
298
298
|
<tr>
|
|
299
299
|
<th style="text-align: right;">
|
|
300
|
-
<div style="${
|
|
300
|
+
<div style="${h.style.label}">${h.label}</div>
|
|
301
301
|
</th>
|
|
302
302
|
<td style="text-align: right; padding: 0 1em;">
|
|
303
|
-
<div style="${
|
|
303
|
+
<div style="${h.style.value}">${h.value}
|
|
304
304
|
</td>
|
|
305
305
|
</tr>
|
|
306
306
|
`),c=x.get(o.value,0);return`
|
|
@@ -320,13 +320,13 @@ Check the top-level render call using <`+V+">.")}return z}}function Ou(S,z){{if(
|
|
|
320
320
|
</thead>
|
|
321
321
|
<tbody>${u.join("")}</tbody>
|
|
322
322
|
</table>
|
|
323
|
-
`}}}function ow(e,t,n){const r=Qt(e.heat_block.min,n),a=Qt(e.heat_block.max,n);return{min:r,max:a,calculable:!0,orient:"horizontal",left:t?"center":5,top:0,itemWidth:15}}const lw={tooltip:{confine:!0},grid:{containLabel:!0}},uw=e=>U(e).get("year");function cw(e,t){const n=P(e.calendar.data_key),r=t[n.queryID],a=x.groupBy(r,d=>uw(d[n.columnKey])),o=Object.keys(a),l=r.map(d=>U(d[n.columnKey]).valueOf()),u=x.min(l),c=x.max(l);return{minDate:u??0,maxDate:c??0,dateSpan:U(c).diff(u,"day"),dataByYear:a,years:o}}function dw(e,t,n){const r=n.reduce((h,g)=>{const y=yt(g,t);return h[g.name]=Ze(g,y),h},{}),a=tw(e),{dateSpan:o,minDate:l,dataByYear:u,years:c}=cw(e,t),d=o<=366,f={calendar:ew(d,l,c),series:rw(e,d,u,t),tooltip:sw(e,t,a),visualMap:ow(e,d,r),legend:nw(d,c)};return x.defaultsDeep({},f,lw)}function pw(e){return i(B,{})}function hw(e){return i(s.Text,{children:"Click heat block"})}const Ko={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:hw,configRender:pw,payload:[{name:"seriesType",description:"'heatmap'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]},Ti={calendar:{data_key:"",locale:"EN"},heat_block:{min:{type:"static",value:0},max:{type:"static",value:100},name:"Value",data_key:"",value_formatter:De},tooltip:{metrics:[]}};ie.use([F.DataZoomComponent,he.BarChart,he.LineChart,he.HeatmapChart,F.CalendarComponent,F.GridComponent,F.LegendComponent,F.TooltipComponent,F.VisualMapComponent,ze.CanvasRenderer]);function fw({name:e},t){const n=t.getOption();n.calendar.forEach(r=>{r.range=e}),t.setOption(n)}function gw({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=zt(t,e.calendar.data_key),u=Ke(a.triggerManager,Ko.id),c=m.useCallback(h=>{const[g,y]=h.value,C=x.get(l,g,{error:"rowData is not found"});u.forEach(w=>{a.runInteraction(w.id,{...h,rowData:C})})},[l,u,a]),d=m.useMemo(()=>({click:c,legendselectchanged:fw}),[c]),f=m.useMemo(()=>dw(e,t,o),[e,t]);return i(Ae,{echarts:ie,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,opts:{locale:e.calendar.locale},theme:"merico-light"})}function mw({context:e,instance:t}){const n=Xe({vizManager:e.vizManager,instance:t}),{value:r}=R(e.instanceData,"config"),{variables:a}=e,o=m.useMemo(()=>x.defaults({},r,Ti),[r]),l=e.data,{width:u,height:c}=e.viewport;return!o.calendar.data_key||!o.heat_block.data_key||!u||!c?null:i(Be,{width:u,height:c,children:i(gw,{variables:a,width:tt(u),height:nt(c),data:l,conf:o,interactionManager:n})})}function yw({control:e,watch:t}){return t(["heat_block"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.data_key",control:e,render:({field:n})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"heat_block.name",control:e,render:({field:n})=>i(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.min",control:e,render:({field:n})=>i(Yt,{label:"Min Value",...n})}),i(v.Controller,{name:"heat_block.max",control:e,render:({field:n})=>i(Yt,{label:"Max Value",...n})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Value Format",labelPosition:"center"}),i(v.Controller,{name:"heat_block.value_formatter",control:e,render:({field:n})=>i(Ge,{...n})})]})}const bw=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),vw=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[d,f]=m.useState(()=>c??null);return m.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(B,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(I.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),i(s.Divider,{variant:"dashed",my:10}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(bw,{control:e,index:g,remove:a},h.id)},h.id))]})]})};function xw({control:e,watch:t}){return i(vw,{control:e,watch:t})}const ww=[{label:"Chinese",value:"ZH"},{label:"English",value:"EN"}];function Cw({control:e,watch:t}){return t(["calendar"]),p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"calendar.data_key",control:e,render:({field:n})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...n})})}),i(v.Controller,{name:"calendar.locale",control:e,render:({field:n})=>i(s.Select,{label:"Language",required:!0,data:ww,sx:{flex:1},...n})})]})}function Sw({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=m.useMemo(()=>x.defaultsDeep({},t,Ti),[t]),a=m.useMemo(()=>x.cloneDeep(r),[r]);m.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});m.useEffect(()=>{d(a)},[a]);const f=c(),h=m.useMemo(()=>!x.isEqual(f,r),[f,r]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Calendar Heatmap Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(I.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"Calendar",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Calendar",children:"Calendar"}),i(s.Tabs.Tab,{value:"Heat Block",children:"Heat Block"}),i(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"})]}),i(s.Tabs.Panel,{value:"Calendar",children:i(Cw,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Heat Block",children:i(yw,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(xw,{control:o,watch:u})})]})]})})}function _w(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{calendar:a,heat_block:o,tooltip:l,...u}=e;return{...u,calendar:{...a,data_key:r(a.data_key)},heat_block:{...o,data_key:r(o.data_key)},tooltip:{...l,metrics:l.metrics.map(c=>({...c,data_key:r(c.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}function kw(e){const{heat_block:t}=e;let{min:n,max:r}=t;return typeof n!="number"&&(n=0),typeof r!="number"&&(r=100),{...e,heat_block:{...t,min:{type:"static",value:n},max:{type:"static",value:r}}}}class Tw extends ge{constructor(){super(...arguments);q(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>({...n,version:2,config:_w(n.config,r)})),this.version(3,n=>({...n,version:3,config:kw(n.config)}))}}const Dw={displayName:"Heatmap(Calendar)",displayGroup:"ECharts-based charts",migrator:new Tw,name:"calendarHeatmap",viewRender:mw,configRender:Sw,createConfig:()=>({version:3,config:Ti}),triggers:[Ko]},Di={x_axes:[{id:"initial-x",min:"",max:"",name:"X Axis",data_key:"",position:"bottom",label_formatter:De,show:!0}],y_axis:{name:"Y Axis",data_key:"",axisLabel:{formatter:{...Ue},overflow:We},nameAlignment:"center"},series:[],tooltip:{metrics:[]},reference_lines:[]};function Iw(){const e=new Date().getTime().toString();return{id:e,min:"",max:"",name:e,data_key:"",position:"bottom",label_formatter:De,show:!0}}function Mw(){const e=new Date().getTime().toString();return{id:e,type:"bar",name:e,stack:"",color:"",barGap:"0%",data_key:"",barWidth:"",barMinWidth:"1",barMaxWidth:"10",group_by_key:"",hide_in_legend:!1,invisible:!1,label_position:"right",aggregation_on_value:jt,xAxisIndex:"0"}}function Aw(){const e=new Date().getTime().toString();return{id:e,name:e,template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,xAxisIndex:"0"}}function zw(e){const t=e.x_axes.some(o=>o.position==="top"&&!!o.name&&o.show);let n=0;t&&(n+=15);const r=e.x_axes.some(o=>o.position==="bottom"&&!!o.name&&o.show);let a=0;return r&&(a+=15),e.series.some(o=>!o.hide_in_legend)&&(a+=20),{top:n,right:5,bottom:a,left:5,containLabel:!0}}function Ew(e){switch(e){case"bar":return"roundRect";case"scatter":return"circle"}}function $w(e){const t={show:!0,bottom:0,left:"center",type:"scroll"};return t.data=e.filter(n=>!n.hide_in_legend).map(({name:n,type:r})=>({name:n,icon:Ew(r)})),t}function Lw(e,t,n,r){return e.map(a=>{const o=a.orientation==="horizontal",l=o?"yAxis":"xAxis",u=o?"insideEndTop":"end";return{name:a.name,type:"line",hide_in_legend:!a.show_in_legend,xAxisIndex:a.xAxisIndex,data:[],lineStyle:a.lineStyle,markLine:{data:[{name:a.name,[l]:Number(n[a.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:a.lineStyle,label:{formatter:function(){return a.template?Xn(a.template,t,r):""},position:u}}}})}function ar(e,t,n){const r=gt(e,t),a=gt(e,n);return x.zip(a,r)}function Pw(e,t,n,r){const a=ar(t,n,r);return x.unionBy(a,e,0)}function Ow({dataTemplate:e,data:t,name_data_key:n,value_data_key:r,valueTypedXAxis:a}){return a?Pw(e,t,n,r):ar(t,n,r)}function Bw({dataTemplate:e,data:t,aggregation_on_value:n,name_data_key:r,value_data_key:a,valueTypedXAxis:o}){if(!n||n.type==="none")return Ow({dataTemplate:e,data:t,name_data_key:r,value_data_key:a,valueTypedXAxis:o});const l=ar(t,r,a),u=x.groupBy(l,"0");return e.map(([d])=>{const h=u[d].map(y=>y[1]),g=ei(h,n);return[d,g]})}function Vw({group_by_key:e,data:t,value_data_key:n,name_data_key:r}){const{queryID:a,columnKey:o}=P(e),l=x.groupBy(t[a],o);return Object.entries(l).forEach(([u,c])=>{l[u]=ar({[a]:c},r,n)}),l}function Nw({y_axis:e},{data_key:t,xAxisIndex:n,label_position:r,name:a,group_by_key:o,aggregation_on_value:l,stack:u,color:c,hide_in_legend:d,invisible:f,id:h,...g},y,C,w,_,D){const M={label:{show:!!r,position:r,formatter:D[n??"default"]},name:a,yAxisId:"main-y-axis",xAxisIndex:n,stack:u,color:f?"transparent":c,hide_in_legend:d,labelLayout:{hideOverlap:!0},emphasis:{disabled:!0},...g};if(!o||o===e.data_key)return M.data=Bw({dataTemplate:y,data:w,aggregation_on_value:l,name_data_key:e.data_key,value_data_key:t,valueTypedXAxis:C}),M;const O=Vw({group_by_key:o,data:w,name_data_key:e.data_key,value_data_key:t});return Object.entries(O).map(([G,$])=>{const L=x.cloneDeep(M);return L.name=G,L.color=void 0,L.data=$,L})}function qw(e,t,n,r,a,o,l){const u=t.map(d=>[d,0]);return e.series.map(d=>Nw(e,d,u,n,r,l,a)).flat().concat(Lw(e.reference_lines,o,l,r))}function Fw(e,t){const n=e.find(u=>u.axisDim==="y"&&u.axisId==="main-y-axis");if(!n)return"";const{name:r,axisType:a,axisValue:o,axisIndex:l}=n;return a==="yAxis.category"?r:Ft(t.y_axis.axisLabel.formatter)(o,l)}function Gw(e,t,n){const r=t.reduce((a,{xAxisIndex:o,name:l})=>(a[l]=o,a),{});return{trigger:"axis",axisPointer:{type:"shadow"},formatter:function(a){const o=Array.isArray(a)?a:[a];if(o.length===0)return"";const l=o.map(({seriesName:d,marker:f,value:h})=>{if(Array.isArray(h)&&h.length===2&&(h=h[0]),!d)return h;const g=r[d],y=n[g]??n.default;return`
|
|
323
|
+
`}}}function tC(t,e,n){const i=Pt(t.heat_block.min,n),a=Pt(t.heat_block.max,n);return{min:i,max:a,calculable:!0,orient:"horizontal",left:e?"center":5,top:0,itemWidth:15}}const nC={tooltip:{confine:!0},grid:{containLabel:!0}},rC=t=>G(t).get("year");function iC(t,e){const n=A(t.calendar.data_key),i=e[n.queryID],a=x.groupBy(i,p=>rC(p[n.columnKey])),o=Object.keys(a),l=i.map(p=>G(p[n.columnKey]).valueOf()),u=x.min(l),c=x.max(l);return{minDate:u??0,maxDate:c??0,dateSpan:G(c).diff(u,"day"),dataByYear:a,years:o}}function aC(t,e,n){const i=n.reduce((f,g)=>{const b=ot(g,e);return f[g.name]=Fe(g,b),f},{}),a=Yw(t),{dateSpan:o,minDate:l,dataByYear:u,years:c}=iC(t,e),p=o<=366,h={calendar:Kw(p,l,c),series:Jw(t,p,u,e),tooltip:eC(t,e,a),visualMap:tC(t,p,i),legend:Xw(p,c)};return x.defaultsDeep({},h,nC)}function sC(t){return r(z,{})}function oC(t){return r(s.Text,{children:"Click heat block"})}const eo={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:oC,configRender:sC,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:{type:"static",value:0},max:{type:"static",value:100},name:"Value",data_key:"",value_formatter:xe},tooltip:{metrics:[]}};Y.use([B.DataZoomComponent,re.BarChart,re.LineChart,re.HeatmapChart,B.CalendarComponent,B.GridComponent,B.LegendComponent,B.TooltipComponent,B.VisualMapComponent,_e.CanvasRenderer]);function lC({name:t},e){const n=e.getOption();n.calendar.forEach(i=>{i.range=t}),e.setOption(n)}function uC({conf:t,data:e,width:n,height:i,interactionManager:a,variables:o}){const l=yt(e,t.calendar.data_key),u=Ne(a.triggerManager,eo.id),c=m.useCallback(f=>{const[g,b]=f.value,w=x.get(l,g,{error:"rowData is not found"});u.forEach(_=>{a.runInteraction(_.id,{...f,rowData:w})})},[l,u,a]),p=m.useMemo(()=>({click:c,legendselectchanged:lC}),[c]),h=m.useMemo(()=>aC(t,e,o),[t,e]);return r(Se,{echarts:Y,option:h,style:{width:n,height:i},onEvents:p,notMerge:!0,opts:{locale:t.calendar.locale},theme:"merico-light"})}function cC({context:t,instance:e}){const n=qe({vizManager:t.vizManager,instance:e}),{value:i}=V(t.instanceData,"config"),{variables:a}=t,o=m.useMemo(()=>x.defaults({},i,ui),[i]),l=t.data,{width:u,height:c}=t.viewport;return!o.calendar.data_key||!o.heat_block.data_key||!u||!c?null:r(Me,{width:u,height:c,children:r(uC,{variables:a,width:Re(u),height:Qe(c),data:l,conf:o,interactionManager:n})})}function dC({control:t,watch:e}){return e(["heat_block"]),d(s.Stack,{children:[d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"heat_block.data_key",control:t,render:({field:n})=>r(O,{label:"Data Field",required:!0,sx:{flex:1},...n})}),r(v.Controller,{name:"heat_block.name",control:t,render:({field:n})=>r(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"heat_block.min",control:t,render:({field:n})=>r(Et,{label:"Min Value",...n})}),r(v.Controller,{name:"heat_block.max",control:t,render:({field:n})=>r(Et,{label:"Max Value",...n})})]}),r(s.Divider,{mb:-15,variant:"dashed",label:"Value Format",labelPosition:"center"}),r(v.Controller,{name:"heat_block.value_formatter",control:t,render:({field:n})=>r(Pe,{...n})})]})}const pC=({control:t,index:e,remove:n})=>d(s.Stack,{children:[d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`tooltip.metrics.${e}.name`,control:t,render:({field:i})=>r(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})}),r(v.Controller,{name:`tooltip.metrics.${e}.data_key`,control:t,render:({field:i})=>r(O,{label:"Value Field",required:!0,sx:{flex:1},...i})})]}),r(s.Divider,{mb:-10,mt:10,variant:"dashed"}),r(s.Button,{leftIcon:r(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),hC=({control:t,watch:e})=>{const{fields:n,append:i,remove:a}=v.useFieldArray({control:t,name:"tooltip.metrics"}),o=e("tooltip.metrics"),l=n.map((f,g)=>({...f,...o[g]})),u=()=>i({id:Date.now().toString(),data_key:"",name:""}),c=e("tooltip.metrics.0.id"),[p,h]=m.useState(()=>c??null);return m.useEffect(()=>{c&&h(f=>f!==null?f:c)},[c]),d(z,{children:[d(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[r(T.InfoCircle,{size:14,color:"#888"}),r(s.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),r(s.Divider,{variant:"dashed",my:10}),d(s.Tabs,{value:p,onTabChange:f=>h(f),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[d(s.Tabs.List,{children:[l.map((f,g)=>r(s.Tabs.Tab,{value:f.id,children:f.name?f.name:g},f.id)),r(s.Tabs.Tab,{onClick:u,value:"add",children:r(T.Plus,{size:18,color:"#228be6"})})]}),l.map((f,g)=>r(s.Tabs.Panel,{value:f.id,children:r(pC,{control:t,index:g,remove:a},f.id)},f.id))]})]})};function fC({control:t,watch:e}){return r(hC,{control:t,watch:e})}const gC=[{label:"Chinese",value:"ZH"},{label:"English",value:"EN"}];function mC({control:t,watch:e}){return e(["calendar"]),d(s.Stack,{children:[r(s.Group,{grow:!0,noWrap:!0,children:r(v.Controller,{name:"calendar.data_key",control:t,render:({field:n})=>r(O,{label:"Data Field",required:!0,sx:{flex:1},...n})})}),r(v.Controller,{name:"calendar.locale",control:t,render:({field:n})=>r(s.Select,{label:"Language",required:!0,data:gC,sx:{flex:1},...n})})]})}function yC({context:t}){const{value:e,set:n}=V(t.instanceData,"config"),i=m.useMemo(()=>x.defaultsDeep({},e,ui),[e]),a=m.useMemo(()=>x.cloneDeep(i),[i]);m.useEffect(()=>{!x.isEqual(i,a)&&(console.log("config malformed, resetting to defaults",i,a),n(a))},[i,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:p}=v.useForm({defaultValues:a});m.useEffect(()=>{p(a)},[a]);const h=c(),f=m.useMemo(()=>!x.isEqual(h,i),[h,i]);return r(s.Stack,{spacing:"xs",children:d("form",{onSubmit:l(n),children:[d(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(s.Text,{children:"Calendar Heatmap Config"}),r(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:r(T.DeviceFloppy,{size:20})})]}),d(s.Tabs,{defaultValue:"Calendar",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[d(s.Tabs.List,{children:[r(s.Tabs.Tab,{value:"Calendar",children:"Calendar"}),r(s.Tabs.Tab,{value:"Heat Block",children:"Heat Block"}),r(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"})]}),r(s.Tabs.Panel,{value:"Calendar",children:r(mC,{control:o,watch:u})}),r(s.Tabs.Panel,{value:"Heat Block",children:r(dC,{control:o,watch:u})}),r(s.Tabs.Panel,{value:"Tooltip",children:r(fC,{control:o,watch:u})})]})]})})}function bC(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=c=>c&&`${n}.${c}`,{calendar:a,heat_block:o,tooltip:l,...u}=t;return{...u,calendar:{...a,data_key:i(a.data_key)},heat_block:{...o,data_key:i(o.data_key)},tooltip:{...l,metrics:l.metrics.map(c=>({...c,data_key:i(c.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}function vC(t){const{heat_block:e}=t;let{min:n,max:i}=e;return typeof n!="number"&&(n=0),typeof i!="number"&&(i=100),{...t,heat_block:{...e,min:{type:"static",value:n},max:{type:"static",value:i}}}}class xC extends se{constructor(){super(...arguments);P(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,i)=>({...n,version:2,config:bC(n.config,i)})),this.version(3,n=>({...n,version:3,config:vC(n.config)}))}}const wC={displayName:"Heatmap(Calendar)",displayGroup:"ECharts-based charts",migrator:new xC,name:"calendarHeatmap",viewRender:cC,configRender:yC,createConfig:()=>({version:3,config:ui}),triggers:[eo]},ci={x_axes:[{id:"initial-x",min:"",max:"",name:"X Axis",data_key:"",position:"bottom",label_formatter:xe,show:!0}],y_axis:{name:"Y Axis",data_key:"",axisLabel:{formatter:{...Ve},overflow:Le},nameAlignment:"center"},series:[],tooltip:{metrics:[]},reference_lines:[]};function CC(){const t=new Date().getTime().toString();return{id:t,min:"",max:"",name:t,data_key:"",position:"bottom",label_formatter:xe,show:!0}}function SC(){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:At,xAxisIndex:"0"}}function _C(){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 kC(t){const e=t.x_axes.some(o=>o.position==="top"&&!!o.name&&o.show);let n=0;e&&(n+=15);const i=t.x_axes.some(o=>o.position==="bottom"&&!!o.name&&o.show);let a=0;return i&&(a+=15),t.series.some(o=>!o.hide_in_legend)&&(a+=20),{top:n,right:5,bottom:a,left:5,containLabel:!0}}function TC(t){switch(t){case"bar":return"roundRect";case"scatter":return"circle"}}function DC(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:i})=>({name:n,icon:TC(i)})),e}function IC(t,e,n,i){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?zn(a.template,e,i):""},position:u}}}})}function qn(t,e,n){const i=at(t,e),a=at(t,n);return x.zip(a,i)}function MC(t,e,n,i){const a=qn(e,n,i);return x.unionBy(a,t,0)}function AC({dataTemplate:t,data:e,name_data_key:n,value_data_key:i,valueTypedXAxis:a}){return a?MC(t,e,n,i):qn(e,n,i)}function zC({dataTemplate:t,data:e,aggregation_on_value:n,name_data_key:i,value_data_key:a,valueTypedXAxis:o}){if(!n||n.type==="none")return AC({dataTemplate:t,data:e,name_data_key:i,value_data_key:a,valueTypedXAxis:o});const l=qn(e,i,a),u=x.groupBy(l,"0");return t.map(([p])=>{const f=u[p].map(b=>b[1]),g=$r(f,n);return[p,g]})}function EC({group_by_key:t,data:e,value_data_key:n,name_data_key:i}){const{queryID:a,columnKey:o}=A(t),l=x.groupBy(e[a],o);return Object.entries(l).forEach(([u,c])=>{l[u]=qn({[a]:c},i,n)}),l}function PC({y_axis:t},{data_key:e,xAxisIndex:n,label_position:i,name:a,group_by_key:o,aggregation_on_value:l,stack:u,color:c,hide_in_legend:p,invisible:h,id:f,...g},b,w,_,D,L){const N={label:{show:!!i,position:i,formatter:L[n??"default"]},name:a,yAxisId:"main-y-axis",xAxisIndex:n,stack:u,color:h?"transparent":c,hide_in_legend:p,labelLayout:{hideOverlap:!0},emphasis:{disabled:!0},...g};if(!o||o===t.data_key)return N.data=zC({dataTemplate:b,data:_,aggregation_on_value:l,name_data_key:t.data_key,value_data_key:e,valueTypedXAxis:w}),N;const J=EC({group_by_key:o,data:_,name_data_key:t.data_key,value_data_key:e});return Object.entries(J).map(([ae,K])=>{const oe=x.cloneDeep(N);return oe.name=ae,oe.color=void 0,oe.data=K,oe})}function LC(t,e,n,i,a,o,l){const u=e.map(p=>[p,0]);return t.series.map(p=>PC(t,p,u,n,i,l,a)).flat().concat(IC(t.reference_lines,o,l,i))}function BC(t,e){const n=t.find(u=>u.axisDim==="y"&&u.axisId==="main-y-axis");if(!n)return"";const{name:i,axisType:a,axisValue:o,axisIndex:l}=n;return a==="yAxis.category"?i:Dt(e.y_axis.axisLabel.formatter)(o,l)}function OC(t,e,n){const i=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:p,marker:h,value:f})=>{if(Array.isArray(f)&&f.length===2&&(f=f[0]),!p)return f;const g=i[p],b=n[g]??n.default;return`
|
|
324
324
|
<tr>
|
|
325
|
-
<td>${
|
|
326
|
-
<th style="text-align: right; padding: 0 1em;">${
|
|
327
|
-
<td style="text-align: left; padding: 0 1em;">${
|
|
325
|
+
<td>${h}</td>
|
|
326
|
+
<th style="text-align: right; padding: 0 1em;">${p}</th>
|
|
327
|
+
<td style="text-align: left; padding: 0 1em;">${b({value:f})}</td>
|
|
328
328
|
</tr>
|
|
329
|
-
`}),u=
|
|
329
|
+
`}),u=Ze(t.y_axis.axisLabel.overflow.in_tooltip),c=BC(o,t);return`
|
|
330
330
|
<div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
|
|
331
331
|
<div style="${u}">${c}</div>
|
|
332
332
|
</div>
|
|
@@ -335,7 +335,7 @@ Check the top-level render call using <`+V+">.")}return z}}function Ou(S,z){{if(
|
|
|
335
335
|
${l.join("")}
|
|
336
336
|
</tbody>
|
|
337
337
|
</table>
|
|
338
|
-
`}}}function Ww(e){return e.x_axes.reduce((n,{label_formatter:r},a)=>(n[a]=function(l){let u=l;if(typeof l=="object"&&(Array.isArray(l.value)&&l.value.length===2?u=l.value[0]:u=l.value),!r)return u;try{return Z(u).format(r)}catch(c){return console.error(c),u}},n),{default:({value:n})=>n})}function jw(e,t){const n={};return t.map(r=>{const a=yt(r,e);n[r.name]=Ze(r,a)}),n}function Rw(e,t){return e.x_axes.map(({min:n,max:r,...a},o)=>{let l=a.position;return l||(l=o>0?"bottom":"top"),{...a,type:"value",min:n||void 0,max:r||void 0,position:l,axisLabel:{show:!0,margin:2,formatter:t[o]??t.default},axisLine:{show:!0},axisTick:{show:!1},splitLine:{show:!0},nameTextStyle:{fontWeight:"bold"},nameLocation:"center",nameGap:15}})}function Yw(e,t){const n=t.every(l=>!Number.isNaN(Number(l))),{overflow:r,...a}=e.y_axis.axisLabel,o=rt(r.on_axis);return[{data:t,name:e.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"center",fontWeight:"bold"},id:"main-y-axis",axisTick:{show:!0,alignWithLabel:!0},type:n?"value":"category",axisLabel:{...a,...o,formatter:Ft(a.formatter)},z:5}]}function Qw(e,t,n){if(!e.y_axis.data_key)return{};const r=jw(t,n),a=Ww(e),o=P(e.y_axis.data_key),l=x.uniq(t[o.queryID].map(f=>f[o.columnKey])),u=l.every(f=>!Number.isNaN(Number(f))),c=qw(e,l,u,t,a,n,r);return{xAxis:Rw(e,a),yAxis:Yw(e,l),series:c,tooltip:Gw(e,c,a),grid:zw(e),legend:$w(c)}}ie.use([F.DataZoomComponent,he.BarChart,he.LineChart,he.ScatterChart,F.GridComponent,F.LegendComponent,F.TooltipComponent,ze.CanvasRenderer,F.MarkLineComponent,F.MarkAreaComponent]);function Uw({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=zt(t,e.y_axis.data_key),u=Ke(a.triggerManager,ri.id),c=m.useCallback(h=>{const g=x.get(l,h.name,{error:"rowData is not found"});u.forEach(y=>{a.runInteraction(y.id,{...h,rowData:g})})},[l,u,a]),d=m.useMemo(()=>({click:c}),[c]),f=m.useMemo(()=>Qw(e,t,o),[e,t]);return i(Ae,{echarts:ie,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function Kw({context:e,instance:t}){const n=Xe({vizManager:e.vizManager,instance:t}),{value:r}=R(e.instanceData,"config"),{variables:a}=e,o=m.useMemo(()=>x.defaults({},r,Di),[r]),l=e.data,{width:u,height:c}=e.viewport;return!u||!c?null:i(Be,{width:u,height:c,children:i(Uw,{variables:a,width:tt(u),height:nt(c),data:l,conf:o,interactionManager:n})})}const Xw=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Jw=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Zw({control:e,index:t,remove:n,watch:r,variableOptions:a,xAxisOptions:o}){const l=r(`reference_lines.${t}.orientation`);return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:u})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:u})=>i(s.Select,{label:"Value",required:!0,data:a,sx:{flex:1},...u})})]}),i(v.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:u})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...u})}),p(s.Group,{grow:!0,children:[p(s.Stack,{children:[i(v.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:u})=>i(s.Select,{label:"Orientation",data:Jw,required:!0,sx:{flex:1},...u})}),l==="vertical"&&i(s.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&i(v.Controller,{name:`reference_lines.${t}.xAxisIndex`,control:e,render:({field:u})=>i(s.Select,{label:"X Axis",data:o,disabled:o.length===0,sx:{flex:1},...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:u})=>i(s.Select,{label:"Line Type",data:Xw,sx:{flexGrow:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:u})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...u})})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:u})=>i($e,{...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`reference_lines.${t}.show_in_legend`,control:e,render:({field:u})=>i(s.Checkbox,{label:"Show in legend",checked:u.value,onChange:c=>u.onChange(c.currentTarget.checked)})}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]})}function Hw({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=r.map((y,C)=>({...y,...l[C]})),c=()=>{const y=Aw();a(y)},d=m.useMemo(()=>n.map(y=>({label:y.name,value:y.name})),[n]),f=t("x_axes"),h=m.useMemo(()=>f.map(({name:y},C)=>({label:y,value:C.toString()})),[f]),g=u.length>0?u[0].id:"0";return p(s.Tabs,{defaultValue:g,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[u.map((y,C)=>i(s.Tabs.Tab,{value:y.id,children:y.name},y.id)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),u.map((y,C)=>i(s.Tabs.Panel,{value:y.id,children:i(Zw,{control:e,index:C,remove:o,watch:t,variableOptions:d,xAxisOptions:h})},y.id))]})}function eC(e){const[t,n]=m.useState(e);return m.useEffect(()=>{n(e)},[e]),{tab:t,setTab:n}}const tC=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function nC({control:e,index:t,seriesItem:n}){const r=!!n.barWidth.trim();return p(B,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.stack`,control:e,render:({field:a})=>i(s.TextInput,{label:"Stack",placeholder:"Stack bars by this ID",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barGap`,control:e,render:({field:a})=>i(s.Select,{label:"Bar Gap",data:tC,sx:{flexGrow:1},...a})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.barMinWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Min)",disabled:r,sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barMaxWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Max)",disabled:r,sx:{flexGrow:1},...a})})]})]})}const rC=[{label:"off",value:""},{label:"top",value:"top"},{label:"left",value:"left"},{label:"right",value:"right"},{label:"bottom",value:"bottom"},{label:"inside",value:"inside"},{label:"insideLeft",value:"insideLeft"},{label:"insideRight",value:"insideRight"},{label:"insideTop",value:"insideTop"},{label:"insideBottom",value:"insideBottom"},{label:"insideTopLeft",value:"insideTopLeft"},{label:"insideBottomLeft",value:"insideBottomLeft"},{label:"insideTopRight",value:"insideTopRight"},{label:"insideBottomRight",value:"insideBottomRight"}];function iC({control:e,index:t,remove:n,seriesItem:r,xAxisOptions:a}){return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.name`,control:e,render:({field:o})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...o})}),i(v.Controller,{name:`series.${t}.xAxisIndex`,control:e,render:({field:o})=>i(s.Select,{label:"X Axis",data:a,disabled:a.length===0,sx:{flex:1},...o})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.data_key`,control:e,render:({field:o})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...o})}),i(v.Controller,{name:`series.${t}.aggregation_on_value`,control:e,render:({field:o})=>i(Un,{label:"Aggregation on Value",value:o.value??jt,onChange:o.onChange,pt:0})})]}),i(s.Group,{grow:!0,children:i(v.Controller,{name:`series.${t}.group_by_key`,control:e,render:({field:o})=>i(W,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...o})})}),i(nC,{index:t,control:e,seriesItem:r}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),i(v.Controller,{name:`series.${t}.label_position`,control:e,render:({field:o})=>i(s.Select,{label:"Label Position",data:rC,...o})}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`series.${t}.color`,control:e,render:({field:o})=>i($e,{...o})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`series.${t}.hide_in_legend`,control:e,render:({field:o})=>i(s.Checkbox,{label:"Hide in legend",checked:o.value,onChange:l=>o.onChange(l.currentTarget.checked)})}),i(v.Controller,{name:`series.${t}.invisible`,control:e,render:({field:o})=>i(s.Checkbox,{label:"Invisible",checked:o.value,onChange:l=>o.onChange(l.currentTarget.checked)})}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Series"})]})}function aC({control:e,watch:t}){var g;const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"series"}),o=t("series"),l=n.map((y,C)=>({...y,...o[C]})),u=()=>{const y=Mw();r(y)},c=t("x_axes"),d=m.useMemo(()=>c.map(({name:y},C)=>({label:y,value:C.toString()})),[c]),{tab:f,setTab:h}=eC((g=l[0])==null?void 0:g.id);return p(s.Tabs,{value:f,onTabChange:h,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map(y=>i(s.Tabs.Tab,{value:y.id,children:y.name},y.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((y,C)=>i(s.Tabs.Panel,{value:y.id,children:i(iC,{control:e,index:C,remove:a,seriesItem:y,xAxisOptions:d},y.id)},y.id))]})}const sC=[{label:"Top",value:"top"},{label:"Bottom",value:"bottom"}];function oC({control:e,index:t,remove:n}){return p(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[i(s.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`x_axes.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})})}),i(s.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`x_axes.${t}.position`,control:e,render:({field:r})=>i(s.Select,{label:"Position",required:!0,data:sC,sx:{flex:1},...r})})}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:`x_axes.${t}.label_formatter`,control:e,render:({field:r})=>i(Ge,{...r})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`x_axes.${t}.min`,control:e,render:({field:r})=>i(s.TextInput,{label:"Min",...r})}),i(v.Controller,{name:`x_axes.${t}.max`,control:e,render:({field:r})=>i(s.TextInput,{label:"Max",...r})})]})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`x_axes.${t}.show`,control:e,render:({field:r})=>i(s.Checkbox,{label:"Visible",checked:r.value,onChange:a=>r.onChange(a.currentTarget.checked)})}),i(s.Button,{mt:20,leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this X Axis"})]})}function lC({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"x_axes"}),o=t("x_axes"),l=n.map((d,f)=>({...d,...o[f]})),u=()=>{const d=Iw();r(d)},c=l.length>0?l[0].id:"0";return p(s.Tabs,{defaultValue:c,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[l.map(d=>i(s.Tabs.Tab,{value:d.id,children:d.name},d.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((d,f)=>i(s.Tabs.Panel,{value:d.id,children:i(oC,{control:e,index:f,remove:a})},d.id))]})}function uC({control:e,watch:t}){return t(["y_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.data_key",control:e,render:({field:n})=>i(W,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"y_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"X Axis Name",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"y_axis.axisLabel.formatter",control:e,render:({field:n})=>i(Jn,{...n})})}),i(v.Controller,{name:"y_axis.axisLabel.overflow",control:e,render:({field:n})=>i(st,{...n})})]})}function cC({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),{variables:r}=e,a=m.useMemo(()=>x.defaultsDeep({},t,Di),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});m.useEffect(()=>{d(a)},[a]),u([]);const f=c(),h=m.useMemo(()=>!x.isEqual(f,a),[f,a]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Horizontal Bar Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(I.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"Series",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axes",children:"X Axes"}),i(s.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),i(s.Tabs.Tab,{value:"Series",children:"Series"}),i(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"})]}),i(s.Tabs.Panel,{value:"X Axes",children:i(lC,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(uC,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Series",children:i(aC,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(Hw,{variables:r,control:o,watch:u})})]})]})})}function dC(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,y_axis:o,series:l,...u}=e;return{...u,x_axis:{...a,data_key:r(a.data_key)},y_axis:{...o,data_key:r(o.data_key)},series:l.map(c=>({...c,data_key:r(c.data_key),group_by_key:r(c.group_by_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class pC extends ge{constructor(){super(...arguments);q(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:a}=n;return{...n,version:2,config:dC(a,r)}})}}const hC={displayName:"Horizontal Bar Chart",displayGroup:"ECharts-based charts",migrator:new pC,name:"horizontalBarChart",viewRender:Kw,configRender:cC,createConfig:()=>({version:2,config:Di})},Ii={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...nr}}},deviation:{name:"",data_keys:{estimated_value:"",actual_value:""}},metrics:[]};function fC(){return[{top:20,left:30,right:60,height:40,containLabel:!0,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0},{top:70,left:30,right:60,height:100,containLabel:!0,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0},{top:180,left:30,right:60,bottom:130,containLabel:!0,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0},{left:30,right:60,bottom:20,height:100,containLabel:!1,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0}]}const Xo=({value:e})=>{try{return Z(e[2]).format({output:"percent",mantissa:0})}catch(t){return console.error(t),e}};function gC(e,t,n){return{type:"heatmap",name:"准确估算比例",xAxisIndex:0,yAxisIndex:0,data:t.map(a=>{const o=n[a].length,c=(x.countBy(n[a],d=>d.level.diff===0).true??0)/o;return[a,"_y",c]}),label:{show:!0,formatter:Xo},labelLayout:{hideOverlap:!0},visualMapIndex:0,tooltip:{trigger:"item",formatter:({color:a,value:o})=>`
|
|
338
|
+
`}}}function $C(t){return t.x_axes.reduce((n,{label_formatter:i},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),!i)return u;try{return W(u).format(i)}catch(c){return console.error(c),u}},n),{default:({value:n})=>n})}function VC(t,e){const n={};return e.map(i=>{const a=ot(i,t);n[i.name]=Fe(i,a)}),n}function NC(t,e){return t.x_axes.map(({min:n,max:i,...a},o)=>{let l=a.position;return l||(l=o>0?"bottom":"top"),{...a,type:"value",min:n||void 0,max:i||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 qC(t,e){const n=e.every(l=>!Number.isNaN(Number(l))),{overflow:i,...a}=t.y_axis.axisLabel,o=Ue(i.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:Dt(a.formatter)},z:5}]}function GC(t,e,n){if(!t.y_axis.data_key)return{};const i=VC(e,n),a=$C(t),o=A(t.y_axis.data_key),l=x.uniq(e[o.queryID].map(h=>h[o.columnKey])),u=l.every(h=>!Number.isNaN(Number(h))),c=LC(t,l,u,e,a,n,i);return{xAxis:NC(t,a),yAxis:qC(t,l),series:c,tooltip:OC(t,c,a),grid:kC(t),legend:DC(c)}}Y.use([B.DataZoomComponent,re.BarChart,re.LineChart,re.ScatterChart,B.GridComponent,B.LegendComponent,B.TooltipComponent,_e.CanvasRenderer,B.MarkLineComponent,B.MarkAreaComponent]);function FC({conf:t,data:e,width:n,height:i,interactionManager:a,variables:o}){const l=yt(e,t.y_axis.data_key),u=Ne(a.triggerManager,qr.id),c=m.useCallback(f=>{const g=x.get(l,f.name,{error:"rowData is not found"});u.forEach(b=>{a.runInteraction(b.id,{...f,rowData:g})})},[l,u,a]),p=m.useMemo(()=>({click:c}),[c]),h=m.useMemo(()=>GC(t,e,o),[t,e]);return r(Se,{echarts:Y,option:h,style:{width:n,height:i},onEvents:p,notMerge:!0,theme:"merico-light"})}function jC({context:t,instance:e}){const n=qe({vizManager:t.vizManager,instance:e}),{value:i}=V(t.instanceData,"config"),{variables:a}=t,o=m.useMemo(()=>x.defaults({},i,ci),[i]),l=t.data,{width:u,height:c}=t.viewport;return!u||!c?null:r(Me,{width:u,height:c,children:r(FC,{variables:a,width:Re(u),height:Qe(c),data:l,conf:o,interactionManager:n})})}const WC=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],RC=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function QC({control:t,index:e,remove:n,watch:i,variableOptions:a,xAxisOptions:o}){const l=i(`reference_lines.${e}.orientation`);return d(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`reference_lines.${e}.name`,control:t,render:({field:u})=>r(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),r(v.Controller,{name:`reference_lines.${e}.variable_key`,control:t,render:({field:u})=>r(s.Select,{label:"Value",required:!0,data:a,sx:{flex:1},...u})})]}),r(v.Controller,{name:`reference_lines.${e}.template`,control:t,render:({field:u})=>r(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...u})}),d(s.Group,{grow:!0,children:[d(s.Stack,{children:[r(v.Controller,{name:`reference_lines.${e}.orientation`,control:t,render:({field:u})=>r(s.Select,{label:"Orientation",data:RC,required:!0,sx:{flex:1},...u})}),l==="vertical"&&r(s.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&r(v.Controller,{name:`reference_lines.${e}.xAxisIndex`,control:t,render:({field:u})=>r(s.Select,{label:"X Axis",data:o,disabled:o.length===0,sx:{flex:1},...u})})]}),r(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),d(s.Group,{grow:!0,children:[r(v.Controller,{name:`reference_lines.${e}.lineStyle.type`,control:t,render:({field:u})=>r(s.Select,{label:"Line Type",data:WC,sx:{flexGrow:1},...u})}),r(v.Controller,{name:`reference_lines.${e}.lineStyle.width`,control:t,render:({field:u})=>r(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...u})})]}),d(s.Stack,{spacing:4,children:[r(s.Text,{size:"sm",children:"Color"}),r(v.Controller,{name:`reference_lines.${e}.lineStyle.color`,control:t,render:({field:u})=>r(Te,{...u})})]}),r(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),r(v.Controller,{name:`reference_lines.${e}.show_in_legend`,control:t,render:({field:u})=>r(s.Checkbox,{label:"Show in legend",checked:u.value,onChange:c=>u.onChange(c.currentTarget.checked)})}),r(s.Button,{leftIcon:r(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Reference Line"})]})}function UC({control:t,watch:e,variables:n}){const{fields:i,append:a,remove:o}=v.useFieldArray({control:t,name:"reference_lines"}),l=e("reference_lines"),u=i.map((b,w)=>({...b,...l[w]})),c=()=>{const b=_C();a(b)},p=m.useMemo(()=>n.map(b=>({label:b.name,value:b.name})),[n]),h=e("x_axes"),f=m.useMemo(()=>h.map(({name:b},w)=>({label:b,value:w.toString()})),[h]),g=u.length>0?u[0].id:"0";return d(s.Tabs,{defaultValue:g,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},children:[d(s.Tabs.List,{children:[u.map((b,w)=>r(s.Tabs.Tab,{value:b.id,children:b.name},b.id)),r(s.Tabs.Tab,{onClick:c,value:"add",children:r(T.Plus,{size:18,color:"#228be6"})})]}),u.map((b,w)=>r(s.Tabs.Panel,{value:b.id,children:r(QC,{control:t,index:w,remove:o,watch:e,variableOptions:p,xAxisOptions:f})},b.id))]})}function KC(t){const[e,n]=m.useState(t);return m.useEffect(()=>{n(t)},[t]),{tab:e,setTab:n}}const YC=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function XC({control:t,index:e,seriesItem:n}){const i=!!n.barWidth.trim();return d(z,{children:[d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`series.${e}.stack`,control:t,render:({field:a})=>r(s.TextInput,{label:"Stack",placeholder:"Stack bars by this ID",sx:{flexGrow:1},...a})}),r(v.Controller,{name:`series.${e}.barGap`,control:t,render:({field:a})=>r(s.Select,{label:"Bar Gap",data:YC,sx:{flexGrow:1},...a})})]}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`series.${e}.barMinWidth`,control:t,render:({field:a})=>r(s.TextInput,{label:"Bar Width(Min)",disabled:i,sx:{flexGrow:1},...a})}),r(v.Controller,{name:`series.${e}.barWidth`,control:t,render:({field:a})=>r(s.TextInput,{label:"Bar Width",sx:{flexGrow:1},...a})}),r(v.Controller,{name:`series.${e}.barMaxWidth`,control:t,render:({field:a})=>r(s.TextInput,{label:"Bar Width(Max)",disabled:i,sx:{flexGrow:1},...a})})]})]})}const JC=[{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 ZC({control:t,index:e,remove:n,seriesItem:i,xAxisOptions:a}){return d(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`series.${e}.name`,control:t,render:({field:o})=>r(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...o})}),r(v.Controller,{name:`series.${e}.xAxisIndex`,control:t,render:({field:o})=>r(s.Select,{label:"X Axis",data:a,disabled:a.length===0,sx:{flex:1},...o})})]}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`series.${e}.data_key`,control:t,render:({field:o})=>r(O,{label:"Value Field",required:!0,sx:{flex:1},...o})}),r(v.Controller,{name:`series.${e}.aggregation_on_value`,control:t,render:({field:o})=>r(Mn,{label:"Aggregation on Value",value:o.value??At,onChange:o.onChange,pt:0})})]}),r(s.Group,{grow:!0,children:r(v.Controller,{name:`series.${e}.group_by_key`,control:t,render:({field:o})=>r(O,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...o})})}),r(XC,{index:e,control:t,seriesItem:i}),r(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),r(v.Controller,{name:`series.${e}.label_position`,control:t,render:({field:o})=>r(s.Select,{label:"Label Position",data:JC,...o})}),d(s.Stack,{spacing:4,children:[r(s.Text,{size:"sm",children:"Color"}),r(v.Controller,{name:`series.${e}.color`,control:t,render:({field:o})=>r(Te,{...o})})]}),r(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),r(v.Controller,{name:`series.${e}.hide_in_legend`,control:t,render:({field:o})=>r(s.Checkbox,{label:"Hide in legend",checked:o.value,onChange:l=>o.onChange(l.currentTarget.checked)})}),r(v.Controller,{name:`series.${e}.invisible`,control:t,render:({field:o})=>r(s.Checkbox,{label:"Invisible",checked:o.value,onChange:l=>o.onChange(l.currentTarget.checked)})}),r(s.Divider,{mb:-10,mt:10,variant:"dashed"}),r(s.Button,{leftIcon:r(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Series"})]})}function HC({control:t,watch:e}){var g;const{fields:n,append:i,remove:a}=v.useFieldArray({control:t,name:"series"}),o=e("series"),l=n.map((b,w)=>({...b,...o[w]})),u=()=>{const b=SC();i(b)},c=e("x_axes"),p=m.useMemo(()=>c.map(({name:b},w)=>({label:b,value:w.toString()})),[c]),{tab:h,setTab:f}=KC((g=l[0])==null?void 0:g.id);return d(s.Tabs,{value:h,onTabChange:f,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px",paddingTop:"6px"}},children:[d(s.Tabs.List,{children:[l.map(b=>r(s.Tabs.Tab,{value:b.id,children:b.name},b.id)),r(s.Tabs.Tab,{onClick:u,value:"add",children:r(T.Plus,{size:18,color:"#228be6"})})]}),l.map((b,w)=>r(s.Tabs.Panel,{value:b.id,children:r(ZC,{control:t,index:w,remove:a,seriesItem:b,xAxisOptions:p},b.id)},b.id))]})}const e0=[{label:"Top",value:"top"},{label:"Bottom",value:"bottom"}];function t0({control:t,index:e,remove:n}){return d(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[r(s.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),r(s.Group,{grow:!0,noWrap:!0,children:r(v.Controller,{name:`x_axes.${e}.name`,control:t,render:({field:i})=>r(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})})}),r(s.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),r(s.Group,{grow:!0,noWrap:!0,children:r(v.Controller,{name:`x_axes.${e}.position`,control:t,render:({field:i})=>r(s.Select,{label:"Position",required:!0,data:e0,sx:{flex:1},...i})})}),d(s.Stack,{children:[r(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),r(v.Controller,{name:`x_axes.${e}.label_formatter`,control:t,render:({field:i})=>r(Pe,{...i})})]}),d(s.Stack,{children:[r(s.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),d(s.Group,{grow:!0,children:[r(v.Controller,{name:`x_axes.${e}.min`,control:t,render:({field:i})=>r(s.TextInput,{label:"Min",...i})}),r(v.Controller,{name:`x_axes.${e}.max`,control:t,render:({field:i})=>r(s.TextInput,{label:"Max",...i})})]})]}),r(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),r(v.Controller,{name:`x_axes.${e}.show`,control:t,render:({field:i})=>r(s.Checkbox,{label:"Visible",checked:i.value,onChange:a=>i.onChange(a.currentTarget.checked)})}),r(s.Button,{mt:20,leftIcon:r(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),disabled:e===0,children:"Delete this X Axis"})]})}function n0({control:t,watch:e}){const{fields:n,append:i,remove:a}=v.useFieldArray({control:t,name:"x_axes"}),o=e("x_axes"),l=n.map((p,h)=>({...p,...o[h]})),u=()=>{const p=CC();i(p)},c=l.length>0?l[0].id:"0";return d(s.Tabs,{defaultValue:c,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},children:[d(s.Tabs.List,{children:[l.map(p=>r(s.Tabs.Tab,{value:p.id,children:p.name},p.id)),r(s.Tabs.Tab,{onClick:u,value:"add",children:r(T.Plus,{size:18,color:"#228be6"})})]}),l.map((p,h)=>r(s.Tabs.Panel,{value:p.id,children:r(t0,{control:t,index:h,remove:a})},p.id))]})}function r0({control:t,watch:e}){return e(["y_axis"]),d(s.Stack,{children:[d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"y_axis.data_key",control:t,render:({field:n})=>r(O,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})}),r(v.Controller,{name:"y_axis.name",control:t,render:({field:n})=>r(s.TextInput,{label:"X Axis Name",sx:{flex:1},...n})})]}),r(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),r(s.Group,{grow:!0,noWrap:!0,children:r(v.Controller,{name:"y_axis.axisLabel.formatter",control:t,render:({field:n})=>r(En,{...n})})}),r(v.Controller,{name:"y_axis.axisLabel.overflow",control:t,render:({field:n})=>r(Je,{...n})})]})}function i0({context:t}){const{value:e,set:n}=V(t.instanceData,"config"),{variables:i}=t,a=m.useMemo(()=>x.defaultsDeep({},e,ci),[e]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:p}=v.useForm({defaultValues:a});m.useEffect(()=>{p(a)},[a]),u([]);const h=c(),f=m.useMemo(()=>!x.isEqual(h,a),[h,a]);return r(s.Stack,{spacing:"xs",children:d("form",{onSubmit:l(n),children:[d(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(s.Text,{children:"Horizontal Bar Chart Config"}),r(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:r(T.DeviceFloppy,{size:20})})]}),d(s.Tabs,{defaultValue:"Series",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[d(s.Tabs.List,{children:[r(s.Tabs.Tab,{value:"X Axes",children:"X Axes"}),r(s.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),r(s.Tabs.Tab,{value:"Series",children:"Series"}),r(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"})]}),r(s.Tabs.Panel,{value:"X Axes",children:r(n0,{control:o,watch:u})}),r(s.Tabs.Panel,{value:"Y Axis",children:r(r0,{control:o,watch:u})}),r(s.Tabs.Panel,{value:"Series",children:r(HC,{control:o,watch:u})}),r(s.Tabs.Panel,{value:"Reference Lines",children:r(UC,{variables:i,control:o,watch:u})})]})]})})}function a0(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const i=c=>c&&`${n}.${c}`,{x_axis:a,y_axis:o,series:l,...u}=t;return{...u,x_axis:{...a,data_key:i(a.data_key)},y_axis:{...o,data_key:i(o.data_key)},series:l.map(c=>({...c,data_key:i(c.data_key),group_by_key:i(c.group_by_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class s0 extends se{constructor(){super(...arguments);P(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,i)=>{const{config:a}=n;return{...n,version:2,config:a0(a,i)}})}}const o0={displayName:"Horizontal Bar Chart",displayGroup:"ECharts-based charts",migrator:new s0,name:"horizontalBarChart",viewRender:jC,configRender:i0,createConfig:()=>({version:2,config:ci})},di={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...$n}}},deviation:{name:"",data_keys:{estimated_value:"",actual_value:""}},metrics:[]};function l0(){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 to=({value:t})=>{try{return W(t[2]).format({output:"percent",mantissa:0})}catch(e){return console.error(e),t}};function u0(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],p=>p.level.diff===0).true??0)/o;return[a,"_y",c]}),label:{show:!0,formatter:to},labelLayout:{hideOverlap:!0},visualMapIndex:0,tooltip:{trigger:"item",formatter:({color:a,value:o})=>`
|
|
339
339
|
<table style="width: auto">
|
|
340
340
|
<thead>
|
|
341
341
|
<tr colspan="2">
|
|
@@ -353,17 +353,17 @@ Check the top-level render call using <`+V+">.")}return z}}function Ou(S,z){{if(
|
|
|
353
353
|
<tbody>
|
|
354
354
|
<tr>
|
|
355
355
|
<th style="text-align: right;">准确估算比例</th>
|
|
356
|
-
<td style="text-align: left; padding: 0 1em;">${
|
|
356
|
+
<td style="text-align: left; padding: 0 1em;">${to({value:o})}</td>
|
|
357
357
|
</tr>
|
|
358
358
|
</tbody>
|
|
359
359
|
</table>
|
|
360
|
-
`},show_in_legend:!1}}function
|
|
360
|
+
`},show_in_legend:!1}}function no(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 c0([t,e]){const n={x:t,v:`${e}`};try{n.v=W(e).format({output:"number",mantissa:2,trimMantissa:!0})}catch{}return n}function d0(t,e,n,i){var c,p;const a=e.map(h=>{const f=n[h],g=x.sumBy(f,b=>b.level.diff);return[h,g/f.length]}),o=Number(((c=x.maxBy(a,h=>h[1]))==null?void 0:c[1])??0),l=Number(((p=x.minBy(a,h=>h[1]))==null?void 0:p[1])??0),u=ft.interpolate([o,0,l],["#D15A40","#FFF","#418AAF"]);return{type:"bar",name:"平均偏差",xAxisIndex:1,yAxisIndex:1,...i,data:a,itemStyle:{color:({value:h})=>{try{return u(h[1])}catch{return"#FFF"}}},label:{position:"outside",show:!0,formatter:({value:h})=>{try{return W(h[1]).format({output:"number",mantissa:1,trimMantissa:!0})}catch{return h[1]}}},tooltip:{trigger:"item",formatter:({color:h,value:f})=>{const{x:g,v:b}=c0(f);return`
|
|
361
361
|
<table style="width: auto">
|
|
362
362
|
<thead>
|
|
363
363
|
<tr colspan="2">
|
|
364
364
|
<div style="
|
|
365
365
|
width: 100%; height: 4px; border-radius: 2px; margin-bottom: 6px;
|
|
366
|
-
${
|
|
366
|
+
${no(h)}
|
|
367
367
|
"/>
|
|
368
368
|
</tr>
|
|
369
369
|
<tr>
|
|
@@ -375,53 +375,53 @@ Check the top-level render call using <`+V+">.")}return z}}function Ou(S,z){{if(
|
|
|
375
375
|
<tbody>
|
|
376
376
|
<tr>
|
|
377
377
|
<th style="text-align: right;">平均偏差</th>
|
|
378
|
-
<td style="text-align: left; padding: 0 1em;">${
|
|
378
|
+
<td style="text-align: left; padding: 0 1em;">${b}</td>
|
|
379
379
|
</tr>
|
|
380
380
|
</tbody>
|
|
381
381
|
</table>
|
|
382
|
-
`}},show_in_legend:!1}}function
|
|
382
|
+
`}},show_in_legend:!1}}function p0([t,e,n,i]){const a={x:t,percentage:`${e}`,count:n,sum:i};try{a.percentage=W(e).format({output:"percent",mantissa:2,trimMantissa:!0})}catch{}return a}function h0(t,e,n,i){const a={};e.forEach(h=>{const f=x.countBy(n[h],b=>b.level.diff),g=x.sum(Object.values(f));Object.entries(f).forEach(([b,w])=>{a[b]||(a[b]=[]);const _=w/g;a[b].push([h,_,w,g])})});const o=Object.entries(a).map(([h])=>Number(h)).sort((h,f)=>h-f),l=Math.max(...o),u=Math.min(...o),c=ft.interpolate([l,0,u],["#D15A40","#FFF","#418AAF"]);return o.map(h=>({type:"bar",name:h,xAxisIndex:2,yAxisIndex:2,stack:1,...i,color:c(h),data:a[h],tooltip:{trigger:"item",formatter:({color:f,value:g})=>{const{x:b,percentage:w,count:_,sum:D}=p0(g);return`
|
|
383
383
|
<table style="width: auto">
|
|
384
384
|
<thead>
|
|
385
385
|
<tr colspan="2">
|
|
386
386
|
<div style="
|
|
387
387
|
width: 100%; height: 4px; border-radius: 2px; margin-bottom: 6px;
|
|
388
|
-
${
|
|
388
|
+
${no(f)}
|
|
389
389
|
"
|
|
390
390
|
/>
|
|
391
391
|
</tr>
|
|
392
392
|
<tr>
|
|
393
393
|
<th colspan="2" style="text-align: center;">
|
|
394
|
-
${
|
|
394
|
+
${b}
|
|
395
395
|
</th>
|
|
396
396
|
</tr>
|
|
397
397
|
</thead>
|
|
398
398
|
<tbody>
|
|
399
399
|
<tr>
|
|
400
400
|
<th style="text-align: right;">偏差档位</th>
|
|
401
|
-
<td style="text-align: left; padding: 0 1em;">${
|
|
401
|
+
<td style="text-align: left; padding: 0 1em;">${h}</td>
|
|
402
402
|
</tr>
|
|
403
403
|
<tr>
|
|
404
404
|
<th style="text-align: right;">占比</th>
|
|
405
|
-
<td style="text-align: left; padding: 0 1em;">${
|
|
405
|
+
<td style="text-align: left; padding: 0 1em;">${w}</td>
|
|
406
406
|
</tr>
|
|
407
407
|
<tr>
|
|
408
408
|
<th style="text-align: right;">数量</th>
|
|
409
|
-
<td style="text-align: left; padding: 0 1em;">${
|
|
409
|
+
<td style="text-align: left; padding: 0 1em;">${_}</td>
|
|
410
410
|
</tr>
|
|
411
411
|
<tr>
|
|
412
412
|
<th style="text-align: right;">总数</th>
|
|
413
|
-
<td style="text-align: left; padding: 0 1em;">${
|
|
413
|
+
<td style="text-align: left; padding: 0 1em;">${D}</td>
|
|
414
414
|
</tr>
|
|
415
415
|
</tbody>
|
|
416
416
|
</table>
|
|
417
|
-
`}},show_in_legend:!0}))}function xC(e,t,n,r){const a=P(t.data_key),o=t.name,l=n.map(u=>{const c=x.sumBy(r[u],a.columnKey);return[u,c]});return{type:"line",name:o,xAxisIndex:3,yAxisIndex:3,color:"#b41529",data:l,show_in_legend:!1}}function wC(e,t,n,r){const l={barMinWidth:5,barMaxWidth:20};return[gC(e,n,r),yC(e,n,r,l),...vC(e,n,r,l),xC(e,t,n,r)]}function CC(e,t){const{axisLabel:n}=e.x_axis;return[{data:t,id:"准确估算比例",gridIndex:0,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:t,id:"平均偏差",gridIndex:1,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!0,lineStyle:{color:"#FFFFFF",width:2}},type:"category"},{data:t,id:"数量占比",gridIndex:2,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:t,id:"代码当量",gridIndex:3,axisTick:{show:!1},type:"category",axisLabel:{...n,formatter:Io(n.formatter)},axisLine:{show:!1}}]}function SC(e){return[{type:"category",name:"准确估算比例",nameRotate:0,nameGap:5,nameLocation:"end",nameTextStyle:{align:"left"},gridIndex:0,axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:"平均偏差",nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:1,boundaryGap:[1,1],axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:"数量占比",nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:2,axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1},min:0,max:1},{type:"value",gridIndex:3,position:"right",splitNumber:3,axisLabel:{show:!0,verticalAlign:"top",showMinLabel:!1,lineHeight:14},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:e.name,nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:3,position:"left",axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}}]}function Mi(e){return e==1||e==2?1:Mi(e-2)+Mi(e-1)}const _C=Array.from(new Array(20),(e,t)=>Mi(t+1));function Zo(e){return e<=1?e:_C.findIndex(t=>e<=t)-1}function kC(e,t){const{x_axis:n,deviation:r}=e,a=P(n.data_key),o=P(r.data_keys.estimated_value),l=P(r.data_keys.actual_value);return t[a.queryID].map(u=>{const c=Zo(u[o.columnKey]),d=Zo(u[l.columnKey]),f=c-d;return{...u,level:{estimated:c,actual:d,diff:f}}})}function TC(e){return e==="rgba(255, 255, 255, 1)"?{borderColor:"rgba(0,0,0,.1)",borderWidth:1}:{}}function DC(e){return{show:!0,orient:"vertical",top:"middle",right:0,data:e.filter(n=>n.show_in_legend).reverse().map(n=>({name:`${n.name}`,color:n.color,itemStyle:TC(n.color)})),tooltip:{show:!0,formatter:"档位偏差:{a}"}}}const IC={tooltip:{trigger:"axis"}};function MC(e,t){const{deviation:n,metrics:r}=e,a=r.find(l=>l.data_key===t);if(a)return a;const o=n.data_keys.actual_value;return{id:o,name:n.name,data_key:o}}function AC(e,t,n){const r=kC(e,n),a=P(e.x_axis.data_key),o=x.uniqBy(n[a.queryID],a.columnKey).map(f=>f[a.columnKey]),l=x.groupBy(r,a.columnKey),u=MC(e,t),c=wC(e,u,o,l),d={xAxis:CC(e,o),yAxis:SC(u),series:c,grid:fC(),visualMap:[{min:0,max:1,calculable:!0,show:!1,seriesIndex:0,color:["#F0F0F0","#418AAF"]}],legend:DC(c)};return x.defaultsDeep({},d,IC)}const zC={input:{border:"none !important",paddingLeft:0,lineHeight:"1.55 !important"}},EC=({conf:e,metricKey:t,setMetricKey:n})=>{const{deviation:r,metrics:a}=e,o=m.useMemo(()=>{const l=a.map(u=>({label:u.name,value:u.data_key}));return l.push({label:r.name?r.name:r.data_keys.actual_value,value:r.data_keys.actual_value}),l},[r,a]);return p(s.Group,{spacing:1,children:[i(s.Text,{size:12,color:"dimmed",sx:{cursor:"default",userSelect:"none"},children:"基线指标"}),i(s.NativeSelect,{size:"xs",data:o,value:t,onChange:l=>n(l.currentTarget.value),styles:zC})]})},$C={"tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function LC(){return p(s.HoverCard,{width:400,shadow:"md",children:[i(s.HoverCard.Target,{children:i(s.Button,{size:"xs",variant:"subtle",compact:!0,leftIcon:i(E.IconInfoCircle,{size:14}),children:"指标说明"})}),i(s.HoverCard.Dropdown,{children:i(s.Table,{fontSize:14,sx:$C,children:p("tbody",{children:[p("tr",{children:[i("th",{children:"估算偏差"}),i("td",{children:"使用斐波那契数列(1,2,3,5,8,13)估算故事点,每个数位为一个档位,计算issue实际故事点与估算故事点的档位偏差,即为估算偏差。如估算故事点为5,实际故事点为8,则估算偏差为-1。"})]}),p("tr",{children:[i("th",{children:"准确估算比例"}),i("td",{children:"偏差在 ± 1 档位内的 issue 均为准确估算,以此计算准确估算的比例。"})]})]})})})]})}function PC(e){return p(s.Group,{position:"apart",children:[i(LC,{}),i(EC,{...e})]})}ie.use([he.BarChart,he.LineChart,he.HeatmapChart,F.GridComponent,F.LegendComponent,F.TooltipComponent,ze.CanvasRenderer,F.VisualMapComponent]);function OC({conf:e,data:t,width:n,height:r,metricKey:a}){const o=m.useMemo(()=>AC(e,a,t),[e,t,a]);return i(Ae,{echarts:ie,option:o,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})}function BC({context:e}){const{value:t}=R(e.instanceData,"config"),n=m.useMemo(()=>x.defaults({},t,Ii),[t]),r=e.data,{width:a,height:o}=e.viewport,{x_axis:l,deviation:u}=n,{estimated_value:c,actual_value:d}=u.data_keys,[f,h]=m.useState(d);if(m.useEffect(()=>{h(C=>C||d)},[d]),!l.data_key||!c||!d||!a||!o)return null;const g=Math.max(tt(a),300),y=Math.max(nt(o),370);return p(s.Box,{pt:Oe.top,pr:Oe.right,pb:Oe.bottom,pl:Oe.left,sx:{overflow:"hidden",height:o,width:a},children:[i(PC,{conf:n,metricKey:f,setMetricKey:h}),i(OC,{width:g,height:y-30,data:r,conf:n,metricKey:f})]})}function VC({control:e,watch:t}){return t(["deviation"]),p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"deviation.name",control:e,render:({field:n})=>i(s.TextInput,{label:"指标名称",sx:{flex:1},...n})})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"deviation.data_keys.estimated_value",control:e,render:({field:n})=>i(W,{label:"估算值字段",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"deviation.data_keys.actual_value",control:e,render:({field:n})=>i(W,{label:"实际值字段",required:!0,sx:{flex:1},...n})})]})]})}const NC=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`metrics.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`metrics.${t}.data_key`,control:e,render:({field:r})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),qC=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"metrics"}),o=t("metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("metrics.0.id"),[d,f]=m.useState(()=>c??null);return m.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(B,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(I.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"设置可以展示在基线图的指标,例如代码当量"})]}),i(s.Divider,{variant:"dashed",my:10}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(NC,{control:e,index:g,remove:a},h.id)},h.id))]})]})};function FC({control:e,watch:t}){return t(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>i(W,{label:"数据字段",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"X轴名称",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"点位文案",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>i(s.NumberInput,{label:"旋转",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"度"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>i(zo,{...n})})]})]})}function GC({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),r=m.useMemo(()=>x.defaultsDeep({},t,Ii),[t]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});m.useEffect(()=>{c(r)},[r]),l([]);const d=u(),f=m.useMemo(()=>!x.isEqual(d,r),[d,r]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Merico Estimation Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(I.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"12px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X 轴"}),i(s.Tabs.Tab,{value:"Deviation",children:"偏差"}),i(s.Tabs.Tab,{value:"Additional Metrics",children:"指标"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(FC,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Deviation",children:i(VC,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Additional Metrics",children:i(qC,{control:a,watch:l})})]})]})})}function WC(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,deviation:o,metrics:l,...u}=e;return{...u,x_axis:{...a,data_key:r(a.data_key)},deviation:{...o,data_keys:{estimated_value:r(o.data_keys.estimated_value),actual_value:r(o.data_keys.actual_value)}},metrics:l.map(c=>({...c,data_key:r(c.data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class jC extends ge{constructor(){super(...arguments);q(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:a}=n;return{...n,version:2,config:WC(a,r)}})}}const RC={displayName:"Merico Estimation Chart",displayGroup:"Merico suite",migrator:new jC,name:"mericoEstimationChart",viewRender:BC,configRender:GC,createConfig:()=>({version:2,config:Ii})},Ai={styles:{justify:"space-around",align:"start"},metrics:[]};function YC(){return{id:new Date().getTime().toString(),names:{value:"Value",basis:"Basis"},data_keys:{value:"",basis:""},formatter:De,postfix:{type:"text",value:""}}}const Ho=({postfix:e})=>e?p(B,{children:[i(s.Text,{size:"12px",color:"#818388",sx:{lineHeight:1},children:"/"}),i(s.Text,{size:"12px",color:"#818388",sx:{lineHeight:1},children:e})]}):null,QC=k.observer(({metric:e,variableValueMap:t})=>{const{names:n,data_keys:r,formatter:a,postfix:o}=e,l=ye(),u=m.useMemo(()=>{if(o.type==="text"&&o.value)return o.value;if(o.type==="filter-option-label"&&o.value){const c=l.filters.getSelectOption(o.value);return c?c.label:null}return null},[o,l]);return p(s.Stack,{spacing:18,children:[p(s.Stack,{spacing:12,children:[i(s.Text,{size:"14px",color:"#818388",children:n.value}),p(s.Group,{spacing:"2px",align:"baseline",children:[i(s.Text,{size:"24px",fw:"bold",color:"#3D3E45",sx:{lineHeight:1},children:Z(t[r.value]).format(a)}),i(Ho,{postfix:u})]})]}),p(s.Stack,{spacing:12,children:[i(s.Text,{size:"14px",color:"#818388",children:n.basis}),p(s.Group,{spacing:"2px",align:"baseline",children:[i(s.Text,{size:"12px",color:"#3D3E45",sx:{lineHeight:1},children:Z(t[r.basis]).format(a)}),i(Ho,{postfix:u})]})]})]})}),UC=k.observer(({context:e,instance:t})=>{const{value:n}=R(e.instanceData,"config"),{variables:r}=e,a=m.useMemo(()=>x.defaults({},n,Ai),[n]),o=e.data,l=m.useMemo(()=>co(o,r),[r,o]),{width:u,height:c}=e.viewport;return!u||!c||!a?null:i(s.Flex,{w:`${u}px`,h:`${c}px`,justify:a.styles.justify,align:a.styles.align,direction:"row",wrap:"nowrap",sx:{overflow:"hidden"},children:a.metrics.map(d=>i(QC,{metric:d,variableValueMap:l},d.id))})}),KC=[{label:"Text",value:"text"},{label:"Filter Option Label",value:"filter-option-label"}],XC=k.observer(m.forwardRef(({value:e,onChange:t},n)=>{const a=le().filters.selects,o=u=>{t({type:u,value:e.value})},l=u=>{t({type:e.type,value:u})};return p(s.Group,{grow:!0,noWrap:!0,children:[i(s.Select,{label:"Postfix Type",data:KC,value:e.type,onChange:o}),e.type==="text"&&i(s.TextInput,{label:"Postfix Content",value:e.value,onChange:u=>{l(u.currentTarget.value)}}),e.type==="filter-option-label"&&i(s.Select,{label:"Filter",value:e.value,onChange:l,data:a})]})}));function JC({control:e,index:t,remove:n,watch:r,variableOptions:a}){return r(`metrics.${t}.postfix`),p(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`metrics.${t}.names.value`,control:e,render:({field:o})=>i(s.TextInput,{label:"Metric Name",required:!0,sx:{flex:1},...o})}),i(v.Controller,{name:`metrics.${t}.data_keys.value`,control:e,render:({field:o})=>i(s.Select,{label:"Metric Data",required:!0,data:a,sx:{flex:1},...o})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`metrics.${t}.names.basis`,control:e,render:({field:o})=>i(s.TextInput,{label:"Basis Name",required:!0,sx:{flex:1},...o})}),i(v.Controller,{name:`metrics.${t}.data_keys.basis`,control:e,render:({field:o})=>i(s.Select,{label:"Basis Data",required:!0,data:a,sx:{flex:1},...o})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Format",labelPosition:"center"}),i(v.Controller,{name:`metrics.${t}.formatter`,control:e,render:({field:o})=>i(Ge,{...o})}),i(s.Divider,{mb:-15,variant:"dashed",label:"Others",labelPosition:"center"}),i(v.Controller,{name:`metrics.${t}.postfix`,control:e,render:({field:o})=>i(XC,{...o})}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(t),sx:{position:"absolute",top:15,right:5},disabled:t===0,children:i(I.Trash,{size:16})})]})}const ZC=({control:e,watch:t,variables:n})=>{const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"metrics"}),l=t("metrics"),u=r.map((C,w)=>({...C,...l[w]})),c=()=>{a(YC())},d=m.useMemo(()=>n.map(C=>({label:C.name,value:C.name})),[n]),f=x.get(u,"0.id",null),[h,g]=m.useState(f);m.useEffect(()=>{g(C=>C||f)},[f]);const y=C=>{o(C);const w=x.get(u,"0.id",null);g(w)};return p(B,{children:[i(s.Divider,{mt:15,variant:"dashed",label:"Metrics",labelPosition:"center"}),p(s.Tabs,{value:h,onTabChange:g,styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[u.map((C,w)=>i(s.Tabs.Tab,{value:C.id,children:C.names.value?C.names.value:w+1},C.id)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(E.IconPlus,{size:18,color:"#228be6"})})]}),u.map((C,w)=>i(s.Tabs.Panel,{value:C.id,children:i(JC,{control:e,index:w,remove:y,variableOptions:d,watch:t})},C.id))]})]})},HC=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"},{label:"Space Between",value:"space-between"},{label:"Space Around",value:"space-around"},{label:"Space Evenly",value:"space-evenly"}],e1=[{label:"Start",value:"start"},{label:"Center",value:"center"},{label:"End",value:"end"},{label:"Stretch",value:"stretch"}];function t1({control:e,watch:t}){return t("styles"),p(B,{children:[i(s.Divider,{mt:15,variant:"dashed",label:"Styles",labelPosition:"center"}),p(s.Group,{children:[i(v.Controller,{name:"styles.justify",control:e,render:({field:n})=>i(s.Select,{label:"Justify Content",required:!0,data:HC,sx:{flex:1},...n})}),i(v.Controller,{name:"styles.align",control:e,render:({field:n})=>i(s.Select,{label:"Align",required:!0,data:e1,sx:{flex:1},...n})})]})]})}function n1({context:e}){const{value:t,set:n}=R(e.instanceData,"config"),{variables:r}=e,a=m.useMemo(()=>x.defaultsDeep({},t,Ai),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});m.useEffect(()=>{d(a)},[a]);const f=c(),h=m.useMemo(()=>!x.isEqual(f,a),[f,a]);return i("form",{onSubmit:l(n),children:p(s.Stack,{spacing:"xs",children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Merico Stats Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(I.DeviceFloppy,{size:20})})]}),i(t1,{control:o,watch:u}),i(ZC,{control:o,watch:u,variables:r})]})})}function r1(e){const{metrics:t,...n}=e;return{...n,metrics:t.map(r=>({...r,postfix:r.postfix??{type:"text",value:""}}))}}class i1 extends ge{constructor(){super(...arguments);q(this,"VERSION",2)}configVersions(){this.version(1,n=>({...n,version:1,config:n.config})),this.version(2,n=>({...n,version:2,config:r1(n.config)}))}}const a1={displayName:"Merico Stats",displayGroup:"Merico suite",migrator:new i1,name:"merico-stats",viewRender:UC,configRender:n1,createConfig:()=>({version:2,config:Ai})};function s1({control:e,watch:t}){t(["heat_block"]);const n=t("heat_block.label.show");return p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.data_key",control:e,render:({field:r})=>i(W,{label:"Data Field",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:"heat_block.name",control:e,render:({field:r})=>i(s.TextInput,{label:"Name",sx:{flex:1},...r})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.min",control:e,render:({field:r})=>i(Yt,{label:"Min Value",...r})}),i(v.Controller,{name:"heat_block.max",control:e,render:({field:r})=>i(Yt,{label:"Max Value",...r})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Value Format",labelPosition:"center"}),i(v.Controller,{name:"heat_block.value_formatter",control:e,render:({field:r})=>i(Ge,{...r})}),i(s.Divider,{mb:-5,variant:"dashed",label:"Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.label.show",control:e,render:({field:r})=>i(s.Switch,{label:"Show label",checked:r.value,onChange:a=>r.onChange(a.currentTarget.checked),sx:{flexGrow:1}})}),i(v.Controller,{name:"heat_block.label.fontSize",control:e,render:({field:r})=>i(s.NumberInput,{size:"xs",icon:i(E.IconTextSize,{size:16}),disabled:!n,...r})})]})]})}const o1=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),l1=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[d,f]=m.useState(()=>c??null);return m.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(B,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(I.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),i(s.Divider,{variant:"dashed",my:10}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(I.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(o1,{control:e,index:g,remove:a},h.id)},h.id))]})]})};function u1({control:e,watch:t}){return i(l1,{control:e,watch:t})}const c1=({disabled:e,value:t,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[e&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Te,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},d1={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
418
|
-
`)},
|
|
417
|
+
`}},show_in_legend:!0}))}function f0(t,e,n,i){const a=A(e.data_key),o=e.name,l=n.map(u=>{const c=x.sumBy(i[u],a.columnKey);return[u,c]});return{type:"line",name:o,xAxisIndex:3,yAxisIndex:3,color:"#b41529",data:l,show_in_legend:!1}}function g0(t,e,n,i){const l={barMinWidth:5,barMaxWidth:20};return[u0(t,n,i),d0(t,n,i,l),...h0(t,n,i,l),f0(t,e,n,i)]}function m0(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:Ps(n.formatter)},axisLine:{show:!1}}]}function y0(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 pi(t){return t==1||t==2?1:pi(t-2)+pi(t-1)}const b0=Array.from(new Array(20),(t,e)=>pi(e+1));function ro(t){return t<=1?t:b0.findIndex(e=>t<=e)-1}function v0(t,e){const{x_axis:n,deviation:i}=t,a=A(n.data_key),o=A(i.data_keys.estimated_value),l=A(i.data_keys.actual_value);return e[a.queryID].map(u=>{const c=ro(u[o.columnKey]),p=ro(u[l.columnKey]),h=c-p;return{...u,level:{estimated:c,actual:p,diff:h}}})}function x0(t){return t==="rgba(255, 255, 255, 1)"?{borderColor:"rgba(0,0,0,.1)",borderWidth:1}:{}}function w0(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:x0(n.color)})),tooltip:{show:!0,formatter:"档位偏差:{a}"}}}const C0={tooltip:{trigger:"axis"}};function S0(t,e){const{deviation:n,metrics:i}=t,a=i.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 _0(t,e,n){const i=v0(t,n),a=A(t.x_axis.data_key),o=x.uniqBy(n[a.queryID],a.columnKey).map(h=>h[a.columnKey]),l=x.groupBy(i,a.columnKey),u=S0(t,e),c=g0(t,u,o,l),p={xAxis:m0(t,o),yAxis:y0(u),series:c,grid:l0(),visualMap:[{min:0,max:1,calculable:!0,show:!1,seriesIndex:0,color:["#F0F0F0","#418AAF"]}],legend:w0(c)};return x.defaultsDeep({},p,C0)}const k0={input:{border:"none !important",paddingLeft:0,lineHeight:"1.55 !important"}},T0=({conf:t,metricKey:e,setMetricKey:n})=>{const{deviation:i,metrics:a}=t,o=m.useMemo(()=>{const l=a.map(u=>({label:u.name,value:u.data_key}));return l.push({label:i.name?i.name:i.data_keys.actual_value,value:i.data_keys.actual_value}),l},[i,a]);return d(s.Group,{spacing:1,children:[r(s.Text,{size:12,color:"dimmed",sx:{cursor:"default",userSelect:"none"},children:"基线指标"}),r(s.NativeSelect,{size:"xs",data:o,value:e,onChange:l=>n(l.currentTarget.value),styles:k0})]})},D0={"tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function I0(){return d(s.HoverCard,{width:400,shadow:"md",children:[r(s.HoverCard.Target,{children:r(s.Button,{size:"xs",variant:"subtle",compact:!0,leftIcon:r(M.IconInfoCircle,{size:14}),children:"指标说明"})}),r(s.HoverCard.Dropdown,{children:r(s.Table,{fontSize:14,sx:D0,children:d("tbody",{children:[d("tr",{children:[r("th",{children:"估算偏差"}),r("td",{children:"使用斐波那契数列(1,2,3,5,8,13)估算故事点,每个数位为一个档位,计算issue实际故事点与估算故事点的档位偏差,即为估算偏差。如估算故事点为5,实际故事点为8,则估算偏差为-1。"})]}),d("tr",{children:[r("th",{children:"准确估算比例"}),r("td",{children:"偏差在 ± 1 档位内的 issue 均为准确估算,以此计算准确估算的比例。"})]})]})})})]})}function M0(t){return d(s.Group,{position:"apart",children:[r(I0,{}),r(T0,{...t})]})}Y.use([re.BarChart,re.LineChart,re.HeatmapChart,B.GridComponent,B.LegendComponent,B.TooltipComponent,_e.CanvasRenderer,B.VisualMapComponent]);function A0({conf:t,data:e,width:n,height:i,metricKey:a}){const o=m.useMemo(()=>_0(t,a,e),[t,e,a]);return r(Se,{echarts:Y,option:o,style:{width:n,height:i},notMerge:!0,theme:"merico-light"})}function z0({context:t}){const{value:e}=V(t.instanceData,"config"),n=m.useMemo(()=>x.defaults({},e,di),[e]),i=t.data,{width:a,height:o}=t.viewport,{x_axis:l,deviation:u}=n,{estimated_value:c,actual_value:p}=u.data_keys,[h,f]=m.useState(p);if(m.useEffect(()=>{f(w=>w||p)},[p]),!l.data_key||!c||!p||!a||!o)return null;const g=Math.max(Re(a),300),b=Math.max(Qe(o),370);return d(s.Box,{pt:Ie.top,pr:Ie.right,pb:Ie.bottom,pl:Ie.left,sx:{overflow:"hidden",height:o,width:a},children:[r(M0,{conf:n,metricKey:h,setMetricKey:f}),r(A0,{width:g,height:b-30,data:i,conf:n,metricKey:h})]})}function E0({control:t,watch:e}){return e(["deviation"]),d(s.Stack,{children:[r(s.Group,{grow:!0,noWrap:!0,children:r(v.Controller,{name:"deviation.name",control:t,render:({field:n})=>r(s.TextInput,{label:"指标名称",sx:{flex:1},...n})})}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"deviation.data_keys.estimated_value",control:t,render:({field:n})=>r(O,{label:"估算值字段",required:!0,sx:{flex:1},...n})}),r(v.Controller,{name:"deviation.data_keys.actual_value",control:t,render:({field:n})=>r(O,{label:"实际值字段",required:!0,sx:{flex:1},...n})})]})]})}const P0=({control:t,index:e,remove:n})=>d(s.Stack,{children:[d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`metrics.${e}.name`,control:t,render:({field:i})=>r(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})}),r(v.Controller,{name:`metrics.${e}.data_key`,control:t,render:({field:i})=>r(O,{label:"Value Field",required:!0,sx:{flex:1},...i})})]}),r(s.Divider,{mb:-10,mt:10,variant:"dashed"}),r(s.Button,{leftIcon:r(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),L0=({control:t,watch:e})=>{const{fields:n,append:i,remove:a}=v.useFieldArray({control:t,name:"metrics"}),o=e("metrics"),l=n.map((f,g)=>({...f,...o[g]})),u=()=>i({id:Date.now().toString(),data_key:"",name:""}),c=e("metrics.0.id"),[p,h]=m.useState(()=>c??null);return m.useEffect(()=>{c&&h(f=>f!==null?f:c)},[c]),d(z,{children:[d(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[r(T.InfoCircle,{size:14,color:"#888"}),r(s.Text,{size:14,color:"#888",children:"设置可以展示在基线图的指标,例如代码当量"})]}),r(s.Divider,{variant:"dashed",my:10}),d(s.Tabs,{value:p,onTabChange:f=>h(f),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[d(s.Tabs.List,{children:[l.map((f,g)=>r(s.Tabs.Tab,{value:f.id,children:f.name?f.name:g},f.id)),r(s.Tabs.Tab,{onClick:u,value:"add",children:r(T.Plus,{size:18,color:"#228be6"})})]}),l.map((f,g)=>r(s.Tabs.Panel,{value:f.id,children:r(P0,{control:t,index:g,remove:a},f.id)},f.id))]})]})};function B0({control:t,watch:e}){return e(["x_axis"]),d(s.Stack,{children:[d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>r(O,{label:"数据字段",required:!0,sx:{flex:1},...n})}),r(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>r(s.TextInput,{label:"X轴名称",sx:{flex:1},...n})})]}),r(s.Divider,{mb:-15,label:"点位文案",labelPosition:"center"}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>r(s.NumberInput,{label:"旋转",hideControls:!0,min:-90,max:90,rightSection:r(s.Text,{color:"dimmed",children:"度"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),r(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>r(Os,{...n})})]})]})}function O0({context:t}){const{value:e,set:n}=V(t.instanceData,"config"),i=m.useMemo(()=>x.defaultsDeep({},e,di),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:i});m.useEffect(()=>{c(i)},[i]),l([]);const p=u(),h=m.useMemo(()=>!x.isEqual(p,i),[p,i]);return r(s.Stack,{spacing:"xs",children:d("form",{onSubmit:o(n),children:[d(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(s.Text,{children:"Merico Estimation Chart Config"}),r(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:r(T.DeviceFloppy,{size:20})})]}),d(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"12px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[d(s.Tabs.List,{children:[r(s.Tabs.Tab,{value:"X Axis",children:"X 轴"}),r(s.Tabs.Tab,{value:"Deviation",children:"偏差"}),r(s.Tabs.Tab,{value:"Additional Metrics",children:"指标"})]}),r(s.Tabs.Panel,{value:"X Axis",children:r(B0,{control:a,watch:l})}),r(s.Tabs.Panel,{value:"Deviation",children:r(E0,{control:a,watch:l})}),r(s.Tabs.Panel,{value:"Additional Metrics",children:r(L0,{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 i=c=>c&&`${n}.${c}`,{x_axis:a,deviation:o,metrics:l,...u}=t;return{...u,x_axis:{...a,data_key:i(a.data_key)},deviation:{...o,data_keys:{estimated_value:i(o.data_keys.estimated_value),actual_value:i(o.data_keys.actual_value)}},metrics:l.map(c=>({...c,data_key:i(c.data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class V0 extends se{constructor(){super(...arguments);P(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,i)=>{const{config:a}=n;return{...n,version:2,config:$0(a,i)}})}}const N0={displayName:"Merico Estimation Chart",displayGroup:"Merico suite",migrator:new V0,name:"mericoEstimationChart",viewRender:z0,configRender:O0,createConfig:()=>({version:2,config:di})},hi={styles:{justify:"space-around",align:"start"},metrics:[]};function q0(){return{id:new Date().getTime().toString(),names:{value:"Value",basis:"Basis"},data_keys:{value:"",basis:""},formatter:xe,postfix:{type:"text",value:""}}}const io=({postfix:t})=>t?d(z,{children:[r(s.Text,{size:"12px",color:"#818388",sx:{lineHeight:1},children:"/"}),r(s.Text,{size:"12px",color:"#818388",sx:{lineHeight:1},children:t})]}):null,G0=k.observer(({metric:t,variableValueMap:e})=>{const{names:n,data_keys:i,formatter:a,postfix:o}=t,l=ue(),u=m.useMemo(()=>{if(o.type==="text"&&o.value)return o.value;if(o.type==="filter-option-label"&&o.value){const c=l.filters.getSelectOption(o.value);return c?c.label:null}return null},[o,l]);return d(s.Stack,{spacing:18,children:[d(s.Stack,{spacing:12,children:[r(s.Text,{size:"14px",color:"#818388",children:n.value}),d(s.Group,{spacing:"2px",align:"baseline",children:[r(s.Text,{size:"24px",fw:"bold",color:"#3D3E45",sx:{lineHeight:1},children:W(e[i.value]).format(a)}),r(io,{postfix:u})]})]}),d(s.Stack,{spacing:12,children:[r(s.Text,{size:"14px",color:"#818388",children:n.basis}),d(s.Group,{spacing:"2px",align:"baseline",children:[r(s.Text,{size:"12px",color:"#3D3E45",sx:{lineHeight:1},children:W(e[i.basis]).format(a)}),r(io,{postfix:u})]})]})]})}),F0=k.observer(({context:t,instance:e})=>{const{value:n}=V(t.instanceData,"config"),{variables:i}=t,a=m.useMemo(()=>x.defaults({},n,hi),[n]),o=t.data,l=m.useMemo(()=>ms(o,i),[i,o]),{width:u,height:c}=t.viewport;return!u||!c||!a?null:r(s.Flex,{w:`${u}px`,h:`${c}px`,justify:a.styles.justify,align:a.styles.align,direction:"row",wrap:"nowrap",sx:{overflow:"hidden"},children:a.metrics.map(p=>r(G0,{metric:p,variableValueMap:l},p.id))})}),j0=[{label:"Text",value:"text"},{label:"Filter Option Label",value:"filter-option-label"}],W0=k.observer(m.forwardRef(({value:t,onChange:e},n)=>{const a=H().filters.selects,o=u=>{e({type:u,value:t.value})},l=u=>{e({type:t.type,value:u})};return d(s.Group,{grow:!0,noWrap:!0,children:[r(s.Select,{label:"Postfix Type",data:j0,value:t.type,onChange:o}),t.type==="text"&&r(s.TextInput,{label:"Postfix Content",value:t.value,onChange:u=>{l(u.currentTarget.value)}}),t.type==="filter-option-label"&&r(s.Select,{label:"Filter",value:t.value,onChange:l,data:a})]})}));function R0({control:t,index:e,remove:n,watch:i,variableOptions:a}){return i(`metrics.${e}.postfix`),d(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`metrics.${e}.names.value`,control:t,render:({field:o})=>r(s.TextInput,{label:"Metric Name",required:!0,sx:{flex:1},...o})}),r(v.Controller,{name:`metrics.${e}.data_keys.value`,control:t,render:({field:o})=>r(s.Select,{label:"Metric Data",required:!0,data:a,sx:{flex:1},...o})})]}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`metrics.${e}.names.basis`,control:t,render:({field:o})=>r(s.TextInput,{label:"Basis Name",required:!0,sx:{flex:1},...o})}),r(v.Controller,{name:`metrics.${e}.data_keys.basis`,control:t,render:({field:o})=>r(s.Select,{label:"Basis Data",required:!0,data:a,sx:{flex:1},...o})})]}),r(s.Divider,{mb:-15,variant:"dashed",label:"Format",labelPosition:"center"}),r(v.Controller,{name:`metrics.${e}.formatter`,control:t,render:({field:o})=>r(Pe,{...o})}),r(s.Divider,{mb:-15,variant:"dashed",label:"Others",labelPosition:"center"}),r(v.Controller,{name:`metrics.${e}.postfix`,control:t,render:({field:o})=>r(W0,{...o})}),r(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(e),sx:{position:"absolute",top:15,right:5},disabled:e===0,children:r(T.Trash,{size:16})})]})}const Q0=({control:t,watch:e,variables:n})=>{const{fields:i,append:a,remove:o}=v.useFieldArray({control:t,name:"metrics"}),l=e("metrics"),u=i.map((w,_)=>({...w,...l[_]})),c=()=>{a(q0())},p=m.useMemo(()=>n.map(w=>({label:w.name,value:w.name})),[n]),h=x.get(u,"0.id",null),[f,g]=m.useState(h);m.useEffect(()=>{g(w=>w||h)},[h]);const b=w=>{o(w);const _=x.get(u,"0.id",null);g(_)};return d(z,{children:[r(s.Divider,{mt:15,variant:"dashed",label:"Metrics",labelPosition:"center"}),d(s.Tabs,{value:f,onTabChange:g,styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[d(s.Tabs.List,{children:[u.map((w,_)=>r(s.Tabs.Tab,{value:w.id,children:w.names.value?w.names.value:_+1},w.id)),r(s.Tabs.Tab,{onClick:c,value:"add",children:r(M.IconPlus,{size:18,color:"#228be6"})})]}),u.map((w,_)=>r(s.Tabs.Panel,{value:w.id,children:r(R0,{control:t,index:_,remove:b,variableOptions:p,watch:e})},w.id))]})]})},U0=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"},{label:"Space Between",value:"space-between"},{label:"Space Around",value:"space-around"},{label:"Space Evenly",value:"space-evenly"}],K0=[{label:"Start",value:"start"},{label:"Center",value:"center"},{label:"End",value:"end"},{label:"Stretch",value:"stretch"}];function Y0({control:t,watch:e}){return e("styles"),d(z,{children:[r(s.Divider,{mt:15,variant:"dashed",label:"Styles",labelPosition:"center"}),d(s.Group,{children:[r(v.Controller,{name:"styles.justify",control:t,render:({field:n})=>r(s.Select,{label:"Justify Content",required:!0,data:U0,sx:{flex:1},...n})}),r(v.Controller,{name:"styles.align",control:t,render:({field:n})=>r(s.Select,{label:"Align",required:!0,data:K0,sx:{flex:1},...n})})]})]})}function X0({context:t}){const{value:e,set:n}=V(t.instanceData,"config"),{variables:i}=t,a=m.useMemo(()=>x.defaultsDeep({},e,hi),[e]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:p}=v.useForm({defaultValues:a});m.useEffect(()=>{p(a)},[a]);const h=c(),f=m.useMemo(()=>!x.isEqual(h,a),[h,a]);return r("form",{onSubmit:l(n),children:d(s.Stack,{spacing:"xs",children:[d(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(s.Text,{children:"Merico Stats Config"}),r(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:r(T.DeviceFloppy,{size:20})})]}),r(Y0,{control:o,watch:u}),r(Q0,{control:o,watch:u,variables:i})]})})}function J0(t){const{metrics:e,...n}=t;return{...n,metrics:e.map(i=>({...i,postfix:i.postfix??{type:"text",value:""}}))}}class Z0 extends se{constructor(){super(...arguments);P(this,"VERSION",2)}configVersions(){this.version(1,n=>({...n,version:1,config:n.config})),this.version(2,n=>({...n,version:2,config:J0(n.config)}))}}const H0={displayName:"Merico Stats",displayGroup:"Merico suite",migrator:new Z0,name:"merico-stats",viewRender:F0,configRender:X0,createConfig:()=>({version:2,config:hi})};function eS({control:t,watch:e}){e(["heat_block"]);const n=e("heat_block.label.show");return d(s.Stack,{children:[d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"heat_block.data_key",control:t,render:({field:i})=>r(O,{label:"Data Field",required:!0,sx:{flex:1},...i})}),r(v.Controller,{name:"heat_block.name",control:t,render:({field:i})=>r(s.TextInput,{label:"Name",sx:{flex:1},...i})})]}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"heat_block.min",control:t,render:({field:i})=>r(Et,{label:"Min Value",...i})}),r(v.Controller,{name:"heat_block.max",control:t,render:({field:i})=>r(Et,{label:"Max Value",...i})})]}),r(s.Divider,{mb:-15,variant:"dashed",label:"Value Format",labelPosition:"center"}),r(v.Controller,{name:"heat_block.value_formatter",control:t,render:({field:i})=>r(Pe,{...i})}),r(s.Divider,{mb:-5,variant:"dashed",label:"Label",labelPosition:"center"}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"heat_block.label.show",control:t,render:({field:i})=>r(s.Switch,{label:"Show label",checked:i.value,onChange:a=>i.onChange(a.currentTarget.checked),sx:{flexGrow:1}})}),r(v.Controller,{name:"heat_block.label.fontSize",control:t,render:({field:i})=>r(s.NumberInput,{size:"xs",icon:r(M.IconTextSize,{size:16}),disabled:!n,...i})})]})]})}const tS=({control:t,index:e,remove:n})=>d(s.Stack,{children:[d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:`tooltip.metrics.${e}.name`,control:t,render:({field:i})=>r(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})}),r(v.Controller,{name:`tooltip.metrics.${e}.data_key`,control:t,render:({field:i})=>r(O,{label:"Value Field",required:!0,sx:{flex:1},...i})})]}),r(s.Divider,{mb:-10,mt:10,variant:"dashed"}),r(s.Button,{leftIcon:r(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),nS=({control:t,watch:e})=>{const{fields:n,append:i,remove:a}=v.useFieldArray({control:t,name:"tooltip.metrics"}),o=e("tooltip.metrics"),l=n.map((f,g)=>({...f,...o[g]})),u=()=>i({id:Date.now().toString(),data_key:"",name:""}),c=e("tooltip.metrics.0.id"),[p,h]=m.useState(()=>c??null);return m.useEffect(()=>{c&&h(f=>f!==null?f:c)},[c]),d(z,{children:[d(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[r(T.InfoCircle,{size:14,color:"#888"}),r(s.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),r(s.Divider,{variant:"dashed",my:10}),d(s.Tabs,{value:p,onTabChange:f=>h(f),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[d(s.Tabs.List,{children:[l.map((f,g)=>r(s.Tabs.Tab,{value:f.id,children:f.name?f.name:g},f.id)),r(s.Tabs.Tab,{onClick:u,value:"add",children:r(T.Plus,{size:18,color:"#228be6"})})]}),l.map((f,g)=>r(s.Tabs.Panel,{value:f.id,children:r(tS,{control:t,index:g,remove:a},f.id)},f.id))]})]})};function rS({control:t,watch:e}){return r(nS,{control:t,watch:e})}const iS=({disabled:t,value:e,onChange:n})=>{const i=a=>{a&&n(a)};return d(s.Box,{sx:{position:"relative"},children:[t&&r(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),r(ve,{height:"500px",defaultLanguage:"javascript",value:e,onChange:i,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},aS={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
418
|
+
`)},ao=m.forwardRef(({value:t,onChange:e},n)=>{const[i,{setTrue:a,setFalse:o}]=q.useBoolean(),[l,u]=m.useState(t);m.useEffect(()=>{u(t)},[t]);const c=b=>{u({...l,enabled:b})},p=()=>{o();const{enabled:b,func_content:w}=l,_={enabled:b,func_content:w};u(_),e(_)},h=()=>{o(),u(t)},f=b=>{u(w=>({...w,func_content:b}))},g=()=>{f(aS.func_content)};return d(z,{children:[r(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Customize Label"}),r(s.Modal,{size:800,title:"Customize label content",opened:i,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:i&&d(s.Stack,{children:[r(s.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:b=>c(b.currentTarget.checked)}),r(iS,{value:l.func_content,onChange:f,disabled:!l.enabled}),d(s.Group,{position:"apart",children:[r(s.Button,{onClick:g,color:"red",leftIcon:r(T.Recycle,{size:20}),children:"Reset"}),d(s.Group,{position:"right",children:[r(s.Button,{onClick:h,variant:"subtle",children:"Cancel"}),r(s.Button,{onClick:p,children:"OK"})]})]})]})})]})});function sS({control:t,watch:e}){return e(["x_axis"]),d(s.Stack,{children:[d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>r(O,{label:"Data Field",required:!0,sx:{flex:1},...n})}),r(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>r(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),r(s.Divider,{mb:-15,variant:"dashed",label:"Tick Label",labelPosition:"center"}),r(v.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>r(Je,{...n})}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>r(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:r(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),r(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>r(ao,{...n})})]})]})}const oS=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function lS({control:t,watch:e}){return e(["y_axis"]),d(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"y_axis.data_key",control:t,render:({field:n})=>r(O,{label:"Data Field",required:!0,sx:{flex:1},...n})}),r(v.Controller,{name:"y_axis.name",control:t,render:({field:n})=>r(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...n})})]}),r(s.Group,{grow:!0,noWrap:!0,children:r(v.Controller,{name:"y_axis.nameAlignment",control:t,render:({field:n})=>r(s.Select,{label:"Name Alignment",required:!0,data:oS,sx:{flex:1},...n})})}),r(s.Divider,{mb:-15,variant:"dashed",label:"Tick Label",labelPosition:"center"}),r(v.Controller,{name:"y_axis.axisLabel.overflow",control:t,render:({field:n})=>r(Je,{...n})}),d(s.Group,{grow:!0,noWrap:!0,children:[r(v.Controller,{name:"y_axis.axisLabel.rotate",control:t,render:({field:n})=>r(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:r(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),r(v.Controller,{name:"y_axis.axisLabel.formatter",control:t,render:({field:n})=>r(ao,{...n})})]})]})}const fi={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,overflow:Le,formatter:{...Ve}}},y_axis:{name:"Y Axis",data_key:"",nameAlignment:"center",axisLabel:{rotate:0,overflow:Le,formatter:{...Ve}}},heat_block:{min:{type:"static",value:0},max:{type:"static",value:100},name:"Value",data_key:"",value_formatter:xe,label:{show:!1,fontSize:10}},tooltip:{metrics:[]}};function uS({context:t}){const{value:e,set:n}=V(t.instanceData,"config"),i=m.useMemo(()=>x.defaultsDeep({},e,fi),[e]),a=m.useMemo(()=>x.cloneDeep(i),[i]);m.useEffect(()=>{!x.isEqual(i,a)&&(console.log("config malformed, resetting to defaults",i,a),n(a))},[i,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:p}=v.useForm({defaultValues:a});m.useEffect(()=>{p(a)},[a]);const h=c(),f=m.useMemo(()=>!x.isEqual(h,i),[h,i]);return r("form",{onSubmit:l(n),style:{flexGrow:1},children:d(s.Stack,{spacing:"xs",sx:{height:"100%"},children:[d(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(s.Text,{children:"Chart Config"}),r(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:r(T.DeviceFloppy,{size:20})})]}),d(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{root:{flexGrow:1},tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[d(s.Tabs.List,{children:[r(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),r(s.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),r(s.Tabs.Tab,{value:"Heat Block",children:"Heat Block"}),r(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"})]}),r(s.Tabs.Panel,{value:"X Axis",children:r(sS,{control:o,watch:u})}),r(s.Tabs.Panel,{value:"Y Axis",children:r(lS,{control:o,watch:u})}),r(s.Tabs.Panel,{value:"Heat Block",children:r(eS,{control:o,watch:u})}),r(s.Tabs.Panel,{value:"Tooltip",children:r(rS,{control:o,watch:u})})]})]})})}function cS(t){return r(z,{})}function dS(t){return r(s.Text,{children:"Click heat block"})}const so={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:dS,configRender:cS,payload:[{name:"seriesType",description:"'heatmap'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function oo({enabled:t,func_content:e}){return(n,i)=>{if(!t)return n;try{return new Function(`return ${e}`)()(n,i)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function pS(t){const e=oo(t.x_axis.axisLabel.formatter),n=oo(t.y_axis.axisLabel.formatter);return{x_axis:e,y_axis:n}}function hS(t){return{heat_block:function(i){if(!t.heat_block.value_formatter)return i;try{return W(i).format(t.heat_block.value_formatter)}catch(a){return console.error(a),i}}}}function fS(t){let e=0;return t.x_axis.name&&(e+=20),{top:45,left:5,right:5,bottom:e,containLabel:!0}}function gS(t,e){const{x_axis:n,y_axis:i,heat_block:a}=t,o=A(n.data_key),l=A(i.data_key),u=A(a.data_key),c=e[o.queryID].map(p=>[x.get(p,o.columnKey),x.get(p,l.columnKey),x.get(p,u.columnKey)]);return{type:"heatmap",name:a.name,xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{borderWidth:0},data:c,label:a.label,labelLayout:{hideOverlap:!0}}}const mS=t=>{try{return W(t).format({trimMantissa:!0,mantissa:2})}catch{return t}};function yS({conf:t,labelFormatters:e,valueFormatters:n,dataDict:i,params:a}){const{value:o,dataIndex:l}=a,[u,c,p]=o,h={label:t.x_axis.name?t.x_axis.name:"X Axis",value:e.x_axis(u,l),style:{label:"",value:Ze(t.x_axis.axisLabel.overflow.in_tooltip)}},f={label:t.y_axis.name?t.y_axis.name:"Y Axis",value:e.y_axis(c,l),style:{label:"",value:Ze(t.y_axis.axisLabel.overflow.in_tooltip)}},g={label:t.heat_block.name,value:n.heat_block(p),style:{label:"",value:""}},b=[h,f,g],w=i[`${u}---${c}`];return w&&t.tooltip.metrics.forEach(_=>{const D=A(_.data_key);b.push({label:_.name,value:mS(x.get(w,D.columnKey,"")),style:{label:"",value:""}})}),b}function bS(t,e,n,i){const{x_axis:a,y_axis:o,heat_block:l}=t,u=A(a.data_key),c=A(o.data_key);A(l.data_key);const p=x.keyBy(e[u.queryID],h=>`${h[u.columnKey]}---${h[c.columnKey]}`);return{confine:!0,formatter:function(h){const g=yS({conf:t,labelFormatters:n,valueFormatters:i,dataDict:p,params:h}).map(w=>`
|
|
419
419
|
<tr>
|
|
420
420
|
<th style="text-align: right;">
|
|
421
|
-
<div style="${
|
|
421
|
+
<div style="${w.style.label}">${w.label}</div>
|
|
422
422
|
</th>
|
|
423
423
|
<td style="text-align: right; padding: 0 1em;">
|
|
424
|
-
<div style="${
|
|
424
|
+
<div style="${w.style.value}">${w.value}
|
|
425
425
|
</td>
|
|
426
426
|
</tr>
|
|
427
427
|
`);return`
|
|
@@ -430,24 +430,24 @@ Check the top-level render call using <`+V+">.")}return z}}function Ou(S,z){{if(
|
|
|
430
430
|
<tr colspan="2">
|
|
431
431
|
<div style="
|
|
432
432
|
width: 100%; height: 4px; border-radius: 2px; margin-bottom: 6px;
|
|
433
|
-
background-color: ${
|
|
433
|
+
background-color: ${h.color};"
|
|
434
434
|
/>
|
|
435
435
|
</tr>
|
|
436
436
|
</thead>
|
|
437
437
|
<tbody>${g.join("")}</tbody>
|
|
438
438
|
</table>
|
|
439
|
-
`}}}function k1(e,t){const n=Qt(e.heat_block.min,t),r=Qt(e.heat_block.max,t);return{min:n,max:r,calculable:!0,orient:"horizontal",left:"center",top:0,itemWidth:15}}function T1(e,t,n){const r=P(e.x_axis.data_key),a=x.uniq(t[r.queryID].map(c=>c[r.columnKey])),{overflow:o,rotate:l}=e.x_axis.axisLabel,u=rt(o.on_axis);return{id:"main-x-axis",type:"category",data:a,name:e.x_axis.name??"",align:"center",axisTick:{show:!0,alignWithLabel:!0},axisLabel:{rotate:l,...u,formatter:n},splitArea:{show:!0},nameLocation:"center",nameGap:25,nameTextStyle:{fontWeight:"bold",align:"center"},z:2}}function D1(e,t,n){const r=P(e.x_axis.data_key),a=P(e.y_axis.data_key),{nameAlignment:o,data_key:l,...u}=e.y_axis,c=x.uniq(t[r.queryID].map(g=>g[a.columnKey])),{overflow:d,rotate:f}=e.y_axis.axisLabel,h=rt(d.on_axis);return{...u,type:"category",data:c,axisLabel:{rotate:f,...h,formatter:n},axisLine:{show:!0,color:"blue"},axisTick:{show:!0,alignWithLabel:!0},splitArea:{show:!0},nameTextStyle:{fontWeight:"bold",align:o},nameLocation:"end",nameGap:15,z:2}}const I1={tooltip:{confine:!0}};function M1(e,t,n){if(!e.x_axis.data_key||!e.y_axis.data_key||!e.heat_block.data_key)return{};const r=n.reduce((u,c)=>{const d=yt(c,t);return u[c.name]=Ze(c,d),u},{}),a=b1(e),o=v1(e),l={xAxis:T1(e,t,a.x_axis),yAxis:D1(e,t,a.y_axis),series:w1(e,t),tooltip:_1(e,t,a,o),grid:x1(e),visualMap:k1(e,r)};return x.defaultsDeep({},l,I1)}ie.use([F.DataZoomComponent,he.HeatmapChart,F.GridComponent,F.LegendComponent,F.TooltipComponent,F.VisualMapComponent,ze.CanvasRenderer]);function A1({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=m.useMemo(()=>{const h=P(e.x_axis.data_key),g=P(e.y_axis.data_key);return x.keyBy(t[h.queryID],y=>`${y[h.columnKey]}---${y[g.columnKey]}`)},[t,e.x_axis.data_key,e.y_axis.data_key]),u=Ke(a.triggerManager,tl.id),c=m.useCallback(h=>{const[g,y]=h.value,C=x.get(l,`${g}---${y}`,{error:"rowData is not found"});u.forEach(w=>{a.runInteraction(w.id,{...h,rowData:C})})},[l,u,a]),d=m.useMemo(()=>({click:c}),[c]),f=m.useMemo(()=>M1(e,t,o),[e,t]);return i(Ae,{echarts:ie,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function z1({context:e,instance:t}){const n=Xe({vizManager:e.vizManager,instance:t}),{value:r}=R(e.instanceData,"config"),{variables:a}=e,o=m.useMemo(()=>x.defaults({},r,zi),[r]),l=e.data,{width:u,height:c}=e.viewport;return!u||!c?null:i(Be,{width:u,height:c,children:i(A1,{variables:a,width:tt(u),height:nt(c),data:l,conf:o,interactionManager:n})})}class E1 extends ge{constructor(){super(...arguments);q(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const $1={displayName:"Merico Heatmap",displayGroup:"Merico suite",migrator:new E1,name:"merico-heatmap",viewRender:z1,configRender:g1,createConfig:()=>({version:1,config:zi}),triggers:[tl]},L1=[{value:"#25262B",name:"Dark"},{value:"#868E96",name:"Gray"},{value:"#FA5252",name:"Red"},{value:"#E64980",name:"Pink"},{value:"#BE4BDB",name:"Grape"},{value:"#7950F2",name:"Violet"},{value:"#4C6EF5",name:"Indigo"},{value:"#228BE6",name:"Blue"},{value:"#15AABF",name:"Cyan"},{value:"#12B886",name:"Teal"},{value:"#40C057",name:"Green"},{value:"#82C91E",name:"Lime"},{value:"#FAB005",name:"Yellow"},{value:"#FD7E14",name:"Orange"}].map(e=>({name:e.name,value:e.value,type:"single",category:"basic"})),P1=[gc,mc,vc,bc,yc,xc],rl=()=>({id:"dashboard",version:hs,manifest:{viz:[Ci,xx,j0,Jb,Gx,Gy,hC,Lc,ef,hm,Xm,Dw,My,jg,lx,hb,Gb,Z0,RC,$1,a1,gf],color:[...L1,...P1]}}),vn=new _c,be={pluginManager:ft("pluginManager"),vizManager:ft("vizManager"),colorManager:ft("colorManager"),instanceScope:{panelModel:ft("panelModel"),vizInstance:ft("vizInstance"),interactionManager:ft("interactionManager"),migrator:ft("migrator"),operationManager:ft("operationManager"),triggerManager:ft("triggerManager")}},Ei=()=>{try{vn.install(rl())}catch{}const e=new pc(vn),t=new Sc(vn);return{pluginManager:vn,vizManager:e,colorManager:t}},ct=m.createContext(Ei());try{vn.install(rl())}catch{}const $i=m.createContext(null);function sr(e){const t=m.useContext($i),n=Q.useCreation(()=>e.configure(t||new kr),[e.configure]),r=Q.usePrevious(n);return r&&r!==n&&r.dispose(),i($i.Provider,{value:n,children:e.children})}function il(){return m.useContext($i)}const O1=({description:e,isDescriptionEmpty:t})=>t?null:i(s.Tooltip,{color:"white",label:i(Yn,{value:e,styles:{root:{border:"none"},content:{padding:0}}}),styles:{tooltip:{border:"0.0625rem solid rgb(233, 236, 239)",boxShadow:"rgb(0 0 0 / 5%) 0px 0.0625rem 0.1875rem, rgb(0 0 0 / 5%) 0px 1.25rem 1.5625rem -0.3125rem, rgb(0 0 0 / 4%) 0px 0.625rem 0.625rem -0.3125rem"}},withArrow:!0,children:i(s.Box,{sx:{height:"16px",alignSelf:"center"},children:i(E.IconInfoCircle,{size:16,color:"gray"})})}),B1=k.observer(({label:e,config:{default_value:t,description:n,isDescriptionEmpty:r,...a},value:o,onChange:l})=>p(s.Box,{children:[i(s.Text,{children:" "}),i(s.Checkbox,{label:p(s.Group,{noWrap:!0,position:"apart",align:"middle",spacing:6,children:[i(s.Box,{sx:{flexGrow:1},children:e}),i(O1,{description:n,isDescriptionEmpty:r})]}),checked:o||!1,onChange:u=>l(u.currentTarget.checked),...a,pt:".4em",styles:{input:{borderColor:"#e9ecef"}}})]})),al=k.observer(({label:e,config:t,value:n=[null,null],onChange:r})=>{const{inputFormat:a,...o}=t,l=Array.isArray(n)?n.map(f=>f?U(f).toDate():null):[null,null],u=f=>{r(f.map(h=>h&&U(h).format(a)))},c=t.getMinDate(l[0]),d=t.getMaxDate(l[0]);return i(Ru.DatePickerInput,{type:"range",label:e,value:l,onChange:u,icon:i(I.Calendar,{size:16}),sx:{minWidth:"16em"},minDate:c,maxDate:d,valueFormat:a,styles:{input:{borderColor:"#e9ecef"}},...o})}),V1=s.createStyles((e,{radius:t=4})=>({root:{borderRadius:e.fn.radius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-select.rc-select-open":{borderColor:"#228be6 !important",".rc-select-selection-overflow-item-rest":{display:"none"},".rc-select-selection-overflow-item-suffix":{display:"block"}},".rc-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-select-selection-search-mirror":{display:"none"},".rc-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},required:{color:"#fa5252",paddingLeft:"3px"},dropdown:{fontSize:e.fontSizes.xs,zIndex:300,backgroundColor:"#fff",border:"1px solid #e9ecef",marginTop:6,padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px","&.rc-select-dropdown-slide-up-leave-active":{display:"none"},".rc-select-item-empty":{padding:"8px 12px"},".rc-select-item-option":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"8px 12px 8px 2px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},flexDirection:"row-reverse",".rc-select-item-option-state":{flexGrow:0,flexShrink:0,width:"30px",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},".rc-select-item-option-content":{width:"calc(100% - 30px)",overflow:"hidden",'div[data-role="label"]':{overflowWrap:"break-word"}}},".rc-virtual-list-holder-inner":{alignItems:"flex-start"}}})),sl=({errorMessage:e})=>e?i(s.Text,{color:"red",size:12,children:e}):i(s.Text,{color:"dimmed",size:12,children:"Not found"}),N1=({disabled:e,classNames:t,styles:n,unstyled:r,radius:a,style:o,label:l,value:u,onChange:c,options:d,errorMessage:f,required:h})=>{const{classes:g,cx:y}=V1({radius:a},{name:"MultiSelectWidget",classNames:t,styles:n,unstyled:r}),[C,w]=m.useState(!1),_=$=>{w($)},D=C&&(u==null?void 0:u.length)>0,[M,O]=m.useState(""),G=m.useMemo(()=>{if(!M)return d;const $=M.toLowerCase(),L=A=>{var N;return((N=A.description)==null?void 0:N.toLowerCase().includes($))||A.label.toLowerCase().includes($)};return d.filter(L)},[M,d]);return p(s.Stack,{spacing:3,children:[p(s.Group,{position:"apart",children:[p(s.Text,{className:g.label,children:[l,h&&i("span",{className:g.required,"aria-hidden":"true",children:"*"})]}),D&&i(s.Tooltip,{label:`${u.length} selected`,children:i(s.Badge,{children:u.length})})]}),i(Ha,{disabled:e,allowClear:!0,className:y(g.root,"check-select"),dropdownClassName:y(g.dropdown,""),onDropdownVisibleChange:_,transitionName:"rc-select-dropdown-slide-up",choiceTransitionName:"rc-select-selection__choice-zoom",style:o,clearIcon:()=>i(s.CloseButton,{}),value:u,onChange:c,onSelect:console.log,mode:"multiple",maxTagCount:0,notFoundContent:i(sl,{errorMessage:f}),maxTagTextLength:10,maxTagPlaceholder:$=>`${$.length} selected`,searchValue:M,onSearch:O,filterOption:!1,children:G.map($=>p(Ha.Option,{title:$.label,children:[i(s.Text,{size:"sm","data-role":"label",children:$.label}),$.description&&i(s.Text,{size:"xs",color:"dimmed","data-role":"description",children:$.description})]},$.value))})]})},q1=k.observer(({label:e,config:t,value:n,onChange:r})=>{const a=ye(),o=!!t.options_query_id,{state:l,error:u}=a.getDataStuffByID(t.options_query_id),c=l==="loading",d=t.min_width?t.min_width:"200px",f=o?c:!1,h=g=>r(g,!1);return i(N1,{label:e,options:t.options,style:{minWidth:"160px",width:d,maxWidth:f?d:"unset",borderColor:"#e9ecef"},disabled:f,value:n,onChange:h,errorMessage:u,required:t.required})}),F1=m.forwardRef(({label:e,description:t,...n},r)=>i("div",{ref:r,...n,children:i(s.Group,{noWrap:!0,children:p("div",{children:[i(s.Text,{size:"sm","data-role":"label",children:e}),i(s.Text,{size:"xs",color:"dimmed","data-role":"description",children:t})]})})})),G1=k.observer(({label:e,config:t,value:n,onChange:r})=>{const a=ye(),o=!!t.options_query_id,{state:l,error:u}=a.getDataStuffByID(t.options_query_id),c=l==="loading";return i(s.Select,{label:e,data:t.options,disabled:o?c:!1,value:n,onChange:r,error:!!u,placeholder:u,maxDropdownHeight:500,styles:{root:{width:t.width?t.width:"200px"},input:{borderColor:"#e9ecef"}},sx:{".mantine-Select-item[data-selected] .mantine-Text-root[data-role=description]":{color:"rgba(255,255,255,.7)"}},itemComponent:F1})});function W1({label:e,config:t,value:n,onChange:r}){return i(s.TextInput,{label:e,value:n||"",onChange:a=>r(a.currentTarget.value),...t,styles:{input:{borderColor:"#e9ecef"}}})}const j1=({rotate:e,onClick:t})=>i("svg",{onClick:t,className:"caret-icon",viewBox:"0 0 1024 1024",focusable:"false","data-icon":"caret-down",width:"14px",height:"14px",fill:"currentColor","aria-hidden":"true",transform:`rotate(${e})`,children:i("path",{d:"M840.4 300H183.6c-19.7 0-30.7 20.8-18.5 35l328.4 380.8c9.4 10.9 27.5 10.9 37 0L858.9 335c12.2-14.2 1.2-35-18.5-35z"})}),R1=({expanded:e,isLeaf:t,value:n,onClick:r,...a})=>(n==="0-0-value"&&console.log(a),t?i("span",{style:{width:"14px",display:"inline-block"}}):i(j1,{rotate:e?"0":"-90",onClick:r,...a})),Y1=({onClick:e})=>p("svg",{onClick:e,className:"checkbox-icon",width:"16",height:"16",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[i("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),i("rect",{className:"border",x:"4",y:"4",width:"16",height:"16",rx:"2"}),i("rect",{className:"checkmark-indeterminate",x:"8",y:"8",width:"8",height:"8",rx:"2",stroke:"none"}),i("path",{className:"checkmark-checked",d:"M9 12l2 2l4 -4"})]}),Q1=({onClick:e,...t})=>i(Y1,{onClick:e,...t}),U1=s.createStyles((e,{radius:t=4})=>({root:{borderRadius:e.fn.radius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-tree-select.rc-tree-select-open":{borderColor:"#228be6 !important",".rc-tree-select-selection-overflow-item-rest":{display:"none"},".rc-tree-select-selection-overflow-item-suffix":{display:"block"}},".rc-tree-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-tree-select-selection-search-mirror":{display:"none"},".rc-tree-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-tree-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-tree-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-tree-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-tree-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-tree-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-tree-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-tree-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},required:{color:"#fa5252",paddingLeft:"3px"},dropdown:{fontSize:e.fontSizes.xs,zIndex:300,paddingTop:"6px","&.rc-tree-select-dropdown-slide-up-leave-active":{display:"none"},".rc-tree-select-tree-list .rc-tree-select-tree-list-holder":{},".rc-tree-select-tree-list, .rc-tree-select-empty":{backgroundColor:"#fff",border:"1px solid #e9ecef",padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px"},".rc-tree-select-empty":{padding:"8px 12px"},".rc-tree-select-tree-treenode":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"8px 12px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},"&.rc-tree-select-tree-treenode-checkbox-checked":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-checked":{stroke:"rgb(64, 192, 87)",animation:"check 200ms linear forwards"}},"&.rc-tree-select-tree-treenode-checkbox-indeterminate":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-indeterminate":{fill:"rgb(64, 192, 87)"}},".rc-tree-select-tree-switcher":{height:"16px",alignSelf:"center",paddingRight:"2px",transition:"color 200ms ease","&:hover":{color:"#228be6","svg.caret-icon":{color:"#228be6"}},"svg.caret-icon":{color:"#ced4da",transition:"all 200ms ease"}},".rc-tree-select-tree-node-content-wrapper":{display:"flex",flexWrap:"nowrap",overflow:"hidden",alignItems:"center",gap:"8px",transition:"color 200ms ease","&:hover":{color:"#228be6"}},".rc-tree-select-tree-iconEle":{height:"16px","svg .border":{stroke:"#ced4da"},".checkbox-icon .checkmark-indeterminate":{fill:"transparent",transition:"fill 200ms ease"},".checkbox-icon .checkmark-checked":{transform:"scale(1.2)",transformOrigin:"center center",strokeDasharray:10,strokeDashoffset:-10},"@keyframes check":{"0%":{strokeDashoffset:10},"100%":{strokeDashoffset:0}}},".rc-tree-select-tree-title":{textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden",".rc-tree-select-tree-title-desc":{fontSize:"12px",maxWidth:"100%",textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden"}},".rc-tree-select-tree-indent":{flexGrow:0,height:0,verticalAlign:"bottom"},".rc-tree-select-tree-indent-unit":{display:"inline-block",width:"1em"}}}})),K1=({disabled:e,classNames:t,styles:n,unstyled:r,radius:a,style:o,label:l,value:u,onChange:c,treeData:d,errorMessage:f,required:h,treeCheckStrictly:g})=>{const{classes:y,cx:C}=U1({radius:a},{name:"FilterTreeSelectWidget",classNames:t,styles:n,unstyled:r}),[w,_]=m.useState(!1),D=O=>{_(O)},M=w&&(u==null?void 0:u.length)>0;return p(s.Stack,{spacing:3,children:[p(s.Group,{position:"apart",children:[p(s.Text,{className:y.label,children:[l,h&&i("span",{className:y.required,"aria-hidden":"true",children:"*"})]}),M&&i(s.Tooltip,{label:`${u.length} selected`,children:i(s.Badge,{children:u.length})})]}),i(es,{disabled:e,allowClear:!0,treeCheckStrictly:g,className:C(y.root,"check-select"),dropdownClassName:C(y.dropdown,""),onDropdownVisibleChange:D,transitionName:"rc-tree-select-dropdown-slide-up",choiceTransitionName:"rc-tree-select-selection__choice-zoom",style:o,listHeight:510,treeLine:!0,clearIcon:()=>i(s.CloseButton,{}),switcherIcon:R1,treeIcon:Q1,maxTagTextLength:10,value:u,treeData:d,notFoundContent:i(sl,{errorMessage:f}),treeNodeFilterProp:"filterBasis",treeCheckable:!0,showCheckedStrategy:es.SHOW_PARENT,onChange:c,onSelect:console.log,maxTagCount:0,maxTagPlaceholder:O=>`${O.length} selected`})]})},X1=k.observer(({label:e,config:t,value:n,onChange:r})=>{const{treeData:a,treeDataLoading:o,errorMessage:l}=t,u=t.min_width?t.min_width:"200px",d=!!t.options_query_id?o:!1;return i(K1,{disabled:d,style:{minWidth:"160px",width:u,maxWidth:d?u:"unset",borderColor:"#e9ecef"},value:n,onChange:f=>r(f,!1),treeData:a,errorMessage:l,label:e,required:t.required,treeCheckStrictly:t.treeCheckStrictly})}),J1=k.observer(({filter:{type:e,config:t,key:n,...r},formFieldProps:a})=>{switch(e){case"select":return i(G1,{...r,...a,config:t});case"multi-select":return i(q1,{...r,...a,config:t});case"tree-select":return i(X1,{...r,...a,config:t});case"text-input":return i(W1,{...r,...a,config:t});case"date-range":return i(al,{...r,...a,config:t});case"checkbox":return i(B1,{...r,...a,config:t});default:return null}}),Z1=k.observer(m.forwardRef(({filter:e,...t},n)=>i("div",{className:"filter-root",ref:n,children:i(Ee,{children:i(J1,{filter:e,formFieldProps:t})})}))),H1=({disabled:e})=>{const{searchButtonProps:t}=ms(),{children:n="Search",type:r,...a}=t;return i(s.Button,{color:"blue",size:"sm",type:"submit",...a,disabled:e||a.disabled,children:n})};function eS(e){const t=le();m.useEffect(()=>{var n,r;(r=(n=t.filters).updatePreviewValues)==null||r.call(n,e)},[e])}const ol=k.observer(function({view:t}){const n=ye(),{control:r,handleSubmit:a,reset:o}=v.useForm({defaultValues:n.filters.values,reValidateMode:"onBlur"}),l=v.useWatch({control:r});m.useEffect(()=>{o(n.filters.values)},[n.filters.values,o]),eS(l);const u=n.filters.visibleInView(t.id),c=m.useMemo(()=>u.every(g=>g.should_auto_submit),[u]),d=m.useMemo(()=>u.filter(g=>x.get(g,"config.required",!1)),[u]),f=m.useMemo(()=>d.length===0?!1:d.some(g=>!g.requiredAndPass(l[g.key])),[l,d]);if(u.length===0)return null;const h=(g,y)=>(C,w)=>{y(C),(g.should_auto_submit||w)&&n.filters.setValueByKey(g.key,C)};return i("form",{onSubmit:a(n.filters.setValues),children:p(s.Group,{className:"dashboard-filters",position:"apart",noWrap:!0,sx:c?{}:{border:"1px solid #e9ecef",borderRadius:"4px",padding:"16px"},children:[i(s.Group,{align:"flex-start",children:u.map(g=>i(v.Controller,{name:g.key,control:r,render:({field:y})=>i(Z1,{filter:g,value:y.value,onChange:h(g,y.onChange)})},g.id))}),!c&&i(s.Group,{sx:{alignSelf:"flex-end"},children:i(H1,{disabled:f})})]})})}),tS={viewPanelInFullScreen:x.noop,inFullScreen:!1},or=m.createContext(tS),ll=b.types.model("MockContextMeta",{current:b.types.optional(b.types.frozen(),{})}).views(e=>({get keys(){return Object.keys(e.current)},get entries(){return Object.entries(e.current)}})).actions(e=>({replace(t){e.current=t},get(t){return e.current[t]},set(t,n){e.current[t]=n}}));function ul(e){return{current:e}}const nS=b.types.model("PanelLayoutMeta",{x:b.types.number,y:b.types.maybeNull(b.types.number),w:b.types.number,h:b.types.number,moved:b.types.optional(b.types.boolean,!1),static:b.types.optional(b.types.boolean,!1)}).views(e=>({get json(){const{x:t,y:n,w:r,h:a,moved:o}=e;return{h:a,w:r,x:t,y:n===null?0:n,moved:o,static:e.static}}})).actions(e=>({set(t){const{x:n,y:r,w:a,h:o,moved:l}=t;e.x=n,e.y=r,e.w=a,e.h=o,e.moved=!!l,e.static=!!t.static},setWidth(t){e.w=t},setHeight(t){e.h=t}})),rS=b.types.model("PanelStyleBorderMeta",{enabled:b.types.boolean}).views(e=>({get json(){const{enabled:t}=e;return{enabled:t}}})).actions(e=>({setEnabled(t){e.enabled=t}})),iS=b.types.model("PanelStyleMeta",{border:rS}).views(e=>({get json(){const{border:t}=e;return{border:t.json}}})).actions(e=>({})),aS=b.types.model("VariableMeta",{name:b.types.string,size:b.types.string,weight:b.types.string,color:b.types.union(b.types.model({type:b.types.literal("static"),staticColor:b.types.string}),b.types.model({type:b.types.literal("continuous"),valueRange:b.types.array(b.types.number),colorRange:b.types.array(b.types.string)}),b.types.model({type:b.types.literal("piecewise")})),formatter:b.types.model({output:b.types.enumeration("Output",["number","percent"]),average:b.types.optional(b.types.boolean,!1),mantissa:b.types.number,trimMantissa:b.types.optional(b.types.boolean,!1)}),data_field:b.types.string,aggregation:b.types.union(b.types.model({type:b.types.enumeration(["none","sum","mean","median","min","max","CV","std"]),config:b.types.frozen()}),b.types.model({type:b.types.literal("quantile"),config:b.types.model({p:b.types.number})}),b.types.model({type:b.types.literal("custom"),config:b.types.model({func:b.types.string})}))}).views(e=>({get json(){const{name:t,size:n,weight:r,color:a,formatter:o,data_field:l,aggregation:u}=e;return x.cloneDeep({name:t,size:n,color:a,weight:r,formatter:o,data_field:l,aggregation:u})}})),sS=b.types.model("PanelVizMeta",{type:b.types.string,conf:b.types.frozen()}).views(e=>({get json(){return{conf:e.conf,type:e.type}}})).actions(e=>({setType(t){e.type=t},setConf(t){e.conf=t}})),oS=b.types.model("PanelTitleMeta",{show:b.types.optional(b.types.boolean,!0)}).views(e=>({get json(){const{show:t}=e;return{show:t}}})).actions(e=>({setShow(t){e.show=t}})),lS=b.types.model({id:b.types.string,name:b.types.optional(b.types.string,""),title:oS,description:b.types.string,layout:nS,queryIDs:b.types.array(b.types.string),viz:sS,style:iS,variables:b.types.optional(b.types.array(aS),[])}).views(e=>({get json(){const{id:t,name:n,title:r,description:a,queryIDs:o}=e;return{id:t,viz:e.viz.json,name:n,style:e.style.json,title:r,layout:e.layout.json,queryIDs:[...o],variables:e.variables.map(l=>l.json),description:a}},get queryIDSet(){return new Set(e.queryIDs)}})).actions(e=>({setID(t){e.id=t},setName(t){e.name=t},setDescription(t){e.description=t},addQueryID(t){e.queryIDSet.has(t)||e.queryIDs.push(t)},removeQueryID(t){if(!e.queryIDSet.has(t))return;const n=new Set(e.queryIDSet);n.delete(t),e.queryIDs=b.cast(Array.from(n))},setQueryIDs(t){e.queryIDs=b.cast(t)},addVariable(t){e.variables.push(t)},removeVariable(t){e.variables.remove(t)}})),lr=e=>x.cloneDeepWith(e,(t,n)=>{if(n!==void 0&&t)return te.toJS(t)});var Ne=(e=>(e.Postgresql="postgresql",e.MySQL="mysql",e.HTTP="http",e))(Ne||{});const uS=b.types.model("QueryMeta",{id:b.types.string,name:b.types.string,type:b.types.enumeration("DataSourceType",[Ne.Postgresql,Ne.MySQL,Ne.HTTP]),key:b.types.string,sql:b.types.string,pre_process:b.types.optional(b.types.string,""),post_process:b.types.optional(b.types.string,""),run_by:b.types.optional(b.types.array(b.types.string),[]),react_to:b.types.optional(b.types.array(b.types.string),[])}).views(e=>({get valid(){return e.id&&e.type&&e.key&&e.name?e.type===Ne.HTTP?!!e.pre_process:!!e.sql:!1},get json(){const{id:t,name:n,type:r,key:a,sql:o,run_by:l,react_to:u,pre_process:c,post_process:d}=e;return lr({id:t,key:a,sql:o,name:n,type:r,run_by:l,react_to:u,pre_process:c,post_process:d})}})).actions(e=>({setName(t){e.name=t},setKey(t){e.key=t},setType(t){e.type=t},setSQL(t){e.sql=t},setRunBy(t){e.run_by.length=0,e.run_by.push(...t)},setReactTo(t){e.react_to.length=0,e.react_to.push(...t)},setPreProcess(t){e.pre_process=t},setPostProcess(t){e.post_process=t}})),cS=b.types.model("SQLSnippetMeta",{key:b.types.string,value:b.types.string}).views(e=>({get json(){const{key:t,value:n}=e;return{key:t,value:n}}})).actions(e=>({setKey(t){e.key=t},setValue(t){e.value=t}}));var ve=(e=>(e.Select="select",e.MultiSelect="multi-select",e.TreeSelect="tree-select",e.TextInput="text-input",e.Checkbox="checkbox",e.DateRange="date-range",e))(ve||{});const cl=b.types.model("FilterCheckboxConfigMeta",{_name:b.types.literal("checkbox"),description:b.types.optional(b.types.string,""),default_value:b.types.boolean}).views(e=>({get json(){const{_name:t,description:n,default_value:r}=e;return{_name:t,description:n,default_value:r}},get isDescriptionEmpty(){const{description:t}=e;return t===""||t==="<p></p>"}})).actions(e=>({setDefaultValue(t){e.default_value=t},setDescription(t){e.description=t}})),dS=()=>cl.create({_name:"checkbox",description:"",default_value:!1});function dl(e,t){return e.map(n=>{try{return n?U.tz(n,"UTC").format(t):null}catch{return console.log(`[date-range] failed parsing ${n}`),null}})}const pS=b.types.model("FilterDateRangeConfigMeta",{_name:b.types.literal("date-range"),required:b.types.boolean,inputFormat:b.types.enumeration("DateRangeInputFormat",["YYYY","YYYYMM","YYYYMMDD","YYYY-MM","YYYY-MM-DD"]),default_value:b.types.optional(b.types.array(b.types.union(b.types.string,b.types.null)),[null,null]),clearable:b.types.boolean,max_days:b.types.optional(b.types.number,0),allowSingleDateInRange:b.types.optional(b.types.boolean,!1)}).views(e=>({get json(){const{_name:t,max_days:n,required:r,clearable:a,inputFormat:o,default_value:l,allowSingleDateInRange:u}=e;return{_name:t,max_days:n,required:r,clearable:a,inputFormat:o,default_value:dl(l,o),allowSingleDateInRange:u}},truthy(t){return Array.isArray(t)&&t.length===2&&t.every(n=>!!n)}})).views(e=>({getMaxDate(t){const{max_days:n}=e;if(!(!n||!t))return U(t).startOf("day").add(n,"days").toDate()},getMinDate(t){const{max_days:n}=e;if(!(!n||!t))return U(t).startOf("day").subtract(n,"days").toDate()}})).actions(e=>({setFilterValue(t){try{const n=b.getParent(e);b.getRoot(e).filters.setValueByKey(n.key,t)}catch(n){console.error(n)}}})).actions(e=>({setRequired(t){e.required=t},setClearable(t){e.clearable=t},setInputFormat(t){e.inputFormat=t},setDefaultValue(t){e.default_value.length=0,e.default_value.push(...t),e.setFilterValue(t)},setMaxDays(t){e.max_days=t,t>0&&(e.clearable=!0)},setAllowSingleDateInRange(t){e.allowSingleDateInRange=t}})),pl=b.types.snapshotProcessor(pS,{preProcessor({default_value:e,...t}){return{...t,default_value:e.map(n=>n===null?null:U.tz(n,"UTC").toISOString())}},postProcessor(e){const{default_value:t,...n}=e;return{...n,default_value:dl(t,n.inputFormat)}}}),hS=()=>pl.create({_name:"date-range",required:!1,inputFormat:"YYYY-MM-DD",clearable:!1,default_value:[null,null]}),fS=b.types.model({label:b.types.string,value:b.types.string}).actions(e=>({setLabel(t){e.label=t},setValue(t){e.value=t}})),Li=b.types.model("FilterConfigModel_BaseSelect",{static_options:b.types.optional(b.types.array(fS),[]),options_query_id:b.types.optional(b.types.string,""),default_selection_count:b.types.optional(b.types.number,0),required:b.types.optional(b.types.boolean,!1)}).views(e=>({get usingQuery(){return!!e.options_query_id}})).views(e=>({get options(){if(!e.usingQuery)return e.static_options;const{data:t,state:n,error:r}=b.getRoot(e).content.getDataStuffByID(e.options_query_id);return n==="idle"?t:[]}})).actions(e=>({setRequired(t){e.required=t},addStaticOption(t){e.static_options.push(t)},removeStaticOption(t){e.static_options.splice(t,1)},setDefaultSelectionCount(t){e.default_selection_count=t},setOptionsQueryID(t){e.options_query_id=t??""}})),hl=b.types.compose("FilterMultiSelectConfigMeta",b.types.model({_name:b.types.literal("multi-select"),min_width:b.types.optional(b.types.string,""),default_value:b.types.optional(b.types.array(b.types.string),[])}),Li).views(e=>({get json(){const{_name:t,default_value:n,required:r,min_width:a,static_options:o,options_query_id:l,default_selection_count:u}=e;return lr({_name:t,required:!!r,min_width:a,default_value:n,static_options:o,options_query_id:l,default_selection_count:u})},get default_selection(){return e.usingQuery?e.options.slice(0,e.default_selection_count).map(t=>t.value):e.default_value},truthy(t){return Array.isArray(t)&&t.length>0}})).actions(e=>({setDefaultValue(t){e.default_value=b.cast(t)},setMinWidth(t){e.min_width=t},setDefaultSelection(){const t=b.getRoot(e).content.filters,n=b.getParent(e).key;t.setValueByKey(n,e.default_selection)}})).actions(e=>({afterCreate(){b.addDisposer(e,te.reaction(()=>te.toJS(e.default_selection),e.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),gS=()=>hl.create({_name:"multi-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),fl=b.types.compose("FilterConfigModel_Select",b.types.model({_name:b.types.literal("select"),default_value:b.types.string,width:b.types.optional(b.types.string,"")}),Li).views(e=>({get json(){const{_name:t,default_value:n,required:r,width:a,static_options:o,options_query_id:l,default_selection_count:u}=e;return lr({_name:t,width:a,required:r,default_value:n,static_options:o,options_query_id:l,default_selection_count:u})},truthy(t){return!!t},getSelectOption(t){return e.options.find(n=>n.value===t)},get default_selection(){return e.usingQuery?e.default_selection_count>0&&e.options.length>0?e.options[0].value:"":e.default_value}})).actions(e=>({setDefaultValue(t){e.default_value=t},setWidth(t){e.width=t},setDefaultSelection(){const t=b.getRoot(e).content.filters,n=b.getParent(e).key;t.setValueByKey(n,e.default_selection)}})).actions(e=>({afterCreate(){b.addDisposer(e,te.reaction(()=>te.toJS(e.default_selection),e.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),mS=()=>fl.create({_name:"select",required:!1,default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),gl=b.types.model("FilterTextInputConfigMeta",{_name:b.types.literal("text-input"),required:b.types.boolean,default_value:b.types.string}).views(e=>({get json(){const{_name:t,required:n,default_value:r}=e;return{_name:t,required:n,default_value:r}},truthy(t){return typeof t!="string"?!1:!!t.trim()}})).actions(e=>({setRequired(t){e.required=t},setDefaultValue(t){e.default_value=t}})),ml=()=>gl.create({_name:"text-input",required:!1,default_value:""});function yS(e){return Yu.arrayToTree(e,{id:"value",parentId:"parent_value",childrenField:"children",dataField:null})}function bS(e){return e.map(t=>{const{label:n,description:r,...a}=t,o={...a,filterBasis:`${n}___${r??""}`,description:r,label:n};return r&&(o.label=m.createElement("div",{},[m.createElement(s.Text,{key:0,title:t.label},t.label),m.createElement(s.Text,{key:1,className:"rc-tree-select-tree-title-desc",color:"dimmed",title:t.description},t.description)])),o})}const yl=b.types.compose("FilterTreeSelectConfigMeta",b.types.model({_name:b.types.literal("tree-select"),min_width:b.types.optional(b.types.string,""),default_value:b.types.optional(b.types.array(b.types.string),[]),treeCheckStrictly:b.types.optional(b.types.boolean,!1)}),Li).views(e=>({get json(){const{_name:t,default_value:n,required:r,min_width:a,static_options:o,options_query_id:l,default_selection_count:u,treeCheckStrictly:c}=e;return{_name:t,required:!!r,min_width:a,default_value:n,static_options:o,options_query_id:l,treeCheckStrictly:c,default_selection_count:u}},get treeData(){const{data:t}=b.getRoot(e).content.getDataStuffByID(e.options_query_id),n=bS(t);return yS(n)},get errorMessage(){const{error:t}=b.getRoot(e).content.getDataStuffByID(e.options_query_id);return t},get treeDataLoading(){const{state:t}=b.getRoot(e).content.getDataStuffByID(e.options_query_id);return t==="loading"},get defaultSelection(){const{default_selection_count:t}=e;return t?this.treeData.slice(0,t).map(r=>r.value):[]},truthy(t){return Array.isArray(t)&&t.length>0}})).actions(e=>({setDefaultValue(t){e.default_value=b.cast(t)},setMinWidth(t){e.min_width=t},setTreeCheckStrictly(t){e.treeCheckStrictly=t},applyDefaultSelection(){const t=b.getParent(e,1).key;b.getRoot(e).content.filters.setValueByKey(t,e.defaultSelection)},afterCreate(){b.addDisposer(e,te.reaction(()=>JSON.stringify(e.defaultSelection),this.applyDefaultSelection,{fireImmediately:!0,delay:0}))}})),vS=()=>yl.create({_name:"tree-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),bl=b.types.model("FilterMeta",{id:b.types.identifier,key:b.types.string,label:b.types.string,order:b.types.number,visibleInViewsIDs:b.types.array(b.types.string),auto_submit:b.types.optional(b.types.boolean,!1),type:b.types.enumeration("DashboardFilterType",[ve.Select,ve.MultiSelect,ve.TreeSelect,ve.TextInput,ve.Checkbox,ve.DateRange]),config:b.types.union(fl,hl,yl,gl,cl,pl)}).views(e=>({get plainDefaultValue(){const t=e.config.default_value;return Array.isArray(t)?[...t]:t},get usingDefaultValue(){return e.type!==ve.TreeSelect},get auto_submit_supported(){return[ve.Select,ve.Checkbox,ve.DateRange].includes(e.type)}})).views(e=>({get json(){const{id:t,key:n,label:r,order:a,visibleInViewsIDs:o,auto_submit:l,type:u,config:c}=e;return{id:t,key:n,type:u,label:r,order:a,config:c.json,auto_submit:l,visibleInViewsIDs:te.toJS(o)}},get visibleInViewsIDSet(){return new Set(e.visibleInViewsIDs)},get should_auto_submit(){return e.auto_submit_supported&&e.auto_submit},requiredAndPass(t){return x.get(e.config,"required",!1)?x.get(e.config,"truthy",()=>!0)(t):!1}})).actions(e=>({setKey(t){e.key=t},setLabel(t){e.label=t},setOrder(t){e.order=t},setType(t){switch(t){case ve.Select:e.config=mS();break;case ve.MultiSelect:e.config=gS();break;case ve.TreeSelect:e.config=vS();break;case ve.TextInput:e.config=ml();break;case ve.Checkbox:e.config=dS();break;case ve.DateRange:e.config=hS();break}e.type=t},setVisibleInViewsIDs(t){e.visibleInViewsIDs.length=0,e.visibleInViewsIDs.push(...t)},setAutoSubmit(t){e.auto_submit=e.auto_submit_supported&&t}}));var j=(e=>(e.Division="div",e.Modal="modal",e.Tabs="tabs",e))(j||{});const vl=b.types.model("ViewDivisionConfig",{_name:b.types.literal(j.Division)}).views(e=>({get json(){const{_name:t}=e;return{_name:t}}})),xS=()=>vl.create({_name:j.Division}),wS=b.types.model("CustomModalTitleModel",{enabled:b.types.optional(b.types.boolean,!1),func_content:b.types.optional(b.types.string,"")}).views(e=>({get json(){const{enabled:t,func_content:n}=e;return{enabled:t,func_content:n}},get value(){const{enabled:t,func_content:n}=e,r=b.getParent(e,2),a=b.getRoot(e);if(!t)return r.name;try{const o={filters:a.content.filters.values,context:a.context.current};return new Function(`return ${n}`)()(o)}catch(o){return console.error(o),r.name}}})).actions(e=>({setEnabled(t){e.enabled=t},setFuncContent(t){e.func_content=t},replace({enabled:t,func_content:n}){e.enabled=t,e.func_content=n}})),Pi={enabled:!1,func_content:["function text({ filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
|
|
440
|
-
`)},xl=b.types.model("ViewModalConfig",{_name:b.types.literal(j.Modal),width:b.types.string,height:b.types.string,custom_modal_title:b.types.optional(wS,Pi)}).views(e=>({get json(){const{_name:t,width:n,height:r,custom_modal_title:a}=e;return{_name:t,width:n,height:r,custom_modal_title:a.json}}})).actions(e=>({setWidth(t){e.width=t},setHeight(t){e.height=t}})),CS=()=>xl.create({_name:j.Modal,width:"90vw",height:"90vh"}),SS=b.types.model("ViewTabsTabModel",{id:b.types.identifier,name:b.types.string,view_id:b.types.string,color:b.types.optional(b.types.string,"")}).views(e=>({get json(){const{id:t,name:n,view_id:r,color:a}=e;return{id:t,name:n,color:a,view_id:r}}})).actions(e=>({setName(t){e.name=t},setViewID(t){e.view_id=t},setColor(t){e.color=t}})),wl=b.types.model("ViewTabsConfig",{_name:b.types.literal(j.Modal),tabs:b.types.optional(b.types.array(SS),[]),variant:b.types.optional(b.types.enumeration("variant",["default","outline","pills"]),"default"),orientation:b.types.optional(b.types.enumeration("orientation",["horizontal","vertical"]),"horizontal"),grow:b.types.optional(b.types.boolean,!1)}).views(e=>({get json(){const{_name:t,variant:n,orientation:r,tabs:a,grow:o}=e;return{grow:o,tabs:a.map(l=>l.json),_name:t,variant:n,orientation:r}}})).actions(e=>({setVariant(t){e.variant=t},setOrientation(t){e.orientation=t},setGrow(t){e.grow=t},setTabs(t){e.tabs.length=0,e.tabs=b.cast(t)},addTab(){const t=_e.randomId(),n={id:t,name:t,view_id:""};e.tabs.push(n)},removeTab(t){e.tabs.splice(t,1)}})),_S=()=>wl.create({_name:j.Modal,tabs:[]}),kS=b.types.model({id:b.types.identifier,name:b.types.string,type:b.types.enumeration("EViewComponentType",[j.Division,j.Modal,j.Tabs]),config:b.types.union(vl,xl,wl),panelIDs:b.types.optional(b.types.array(b.types.string),[])}).views(e=>({get json(){const{id:t,name:n,type:r,config:a}=e;return{id:t,name:n,type:r,config:a.json,panelIDs:e.panelIDs}}})).actions(e=>({setName(t){e.name=t},setType(t){if(e.type!==t){switch(t){case j.Division:e.config=xS();break;case j.Modal:e.config=CS();break;case j.Tabs:e.config=_S();break}e.type=t}},appendPanelID(t){e.panelIDs.push(t)},removePanelID(t){const n=e.panelIDs.filter(r=>r!==t);e.panelIDs.length=0,e.panelIDs.push(...n)}})),Cl=b.types.model("DataSourceMetaModel",{id:b.types.string,type:b.types.enumeration("DataSourceType",[Ne.HTTP,Ne.MySQL,Ne.Postgresql]),key:b.types.string,config:b.types.frozen()}),TS=b.types.model("DataSourcesMetaModel",{list:b.types.optional(b.types.array(Cl),[])}).views(e=>({find({type:t,key:n}){return e.list.find(r=>r.key===n&&r.type===t)},get options(){return e.list.map(t=>({value:t.key,label:t.key}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}})),DS=b.types.model({id:b.types.string,content:b.types.string,create_time:b.types.string,update_time:b.types.string,is_preset:b.types.boolean}),Sl=b.types.model("GlobalSQLSnippetsMeta",{list:b.types.optional(b.types.array(DS),[])}).views(e=>({find(t){return e.list.find(n=>n.id===t)},get options(){return e.list.map(t=>({value:t.id,label:t.id}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}})),Oi=b.types.model("ContextMeta",{current:b.types.optional(b.types.frozen(),{})}).views(e=>({get keys(){return Object.keys(e.current)},get entries(){return Object.entries(e.current)}})).actions(e=>({replace(t){e.current=t},get(t){return e.current[t]},set(t,n){e.current[t]=n}}));function _l(e){return Oi.create({current:e})}const IS=b.types.compose("ViewRenderModel",kS,b.types.model({tab:b.types.optional(b.types.string,"")})).views(e=>({get defaultTab(){if(e.type!==j.Tabs)return"";const t=e.config;return t.tabs.length>0?t.tabs[0].id:""},get tabViewID(){var n;return e.type!==j.Tabs?"":((n=e.config.tabs.find(r=>r.id===e.tab))==null?void 0:n.view_id)??""},get contentModel(){return b.getParent(e,3)},get panels(){if(e.type!==j.Tabs)return this.contentModel.panels.panelsByIDs(e.panelIDs).panels;const t=this.tabViewID;return this.contentModel.views.findByID(t).panels},get renderViewIDs(){const t=[e.id];return e.type===j.Tabs&&t.push(this.tabViewID),t}})).actions(e=>({setTab(t){e.tab=t??""},afterCreate(){b.addDisposer(e,te.reaction(()=>e.defaultTab,t=>this.setTab(t),{fireImmediately:!0,delay:0}))}})),kl=b.types.model("ViewsRenderModel",{current:b.types.optional(b.types.array(IS),[]),visibleViewIDs:b.types.array(b.types.string)}).views(e=>({get json(){return e.current.map(t=>lr(t.json))},get idMap(){const t=new Map;return e.current.forEach(n=>{t.set(n.id,n)}),t},findByID(t){return e.current.find(n=>n.id===t)},get firstVisibleView(){const[t]=e.visibleViewIDs;return e.current.find(({id:n})=>n===t)},get visibleViews(){const t=new Set(e.visibleViewIDs);return e.current.filter(({id:n})=>t.has(n))}})).actions(e=>({appendToVisibles(t){new Set(e.visibleViewIDs.map(r=>r)).has(t)||e.visibleViewIDs.push(t)},rmVisibleViewID(t){const n=e.visibleViewIDs.findIndex(r=>r===t);n!==-1&&e.visibleViewIDs.splice(n,1)}}));function MS(e){const t=e.length>0?[e[0].id]:[];return{current:e.map(r=>{const{_name:a=r.type}=r.config;return{...r,config:{...r.config,_name:a},panelIDs:r.panelIDs}}),visibleViewIDs:t}}const Tl=lS.views(e=>({get contentModel(){return b.getRoot(e).content}})).views(e=>({get queries(){return e.contentModel.queries.findByIDSet(e.queryIDSet)},get data(){return this.queries.reduce((t,n)=>(t[n.id]=n.data,t),{})},get dataLoading(){return this.queries.some(t=>t.state==="loading")},get queryStateMessages(){const t=this.queries.filter(o=>!o.runByConditionsMet);if(t.length===0)return"";const n=new Set,r=new Set;t.forEach(o=>{const l=o.conditionNames;l.context.forEach(u=>n.add(u)),l.filters.forEach(u=>r.add(u))});const a=[];return n.size>0&&(console.log(n),a.push(`context: ${Array.from(n).join(", ")}`)),r.size>0&&a.push(`filter${r.size>1?"s":""}: ${Array.from(r).join(", ")}`),a.length===2&&a.splice(1,0,"and"),a.unshift("Waiting for"),a.join(" ")},get queryErrors(){return this.queries.map(t=>t.error).filter(t=>!!t)},get canRenderViz(){return this.queryErrors.length===0&&this.queryStateMessages===""&&!this.dataLoading}})).actions(e=>({refreshData(){e.queries.forEach(t=>t.fetchData(!0))},downloadData(){b.getRoot(e).content.queries.downloadDataByQueryIDs(e.queryIDs)}}));function AS(e){return{id:e,name:e,layout:{x:0,y:1/0,w:18,h:300},title:{show:!0},description:"<p></p>",queryIDs:[],viz:{type:Ci.name,conf:Ci.createConfig()},style:{border:{enabled:!0}}}}const Dl=b.types.model("PanelsRenderModel",{list:b.types.optional(b.types.array(Tl),[])}).views(e=>({get json(){return e.list.map(t=>t.json)},findByID(t){return e.list.find(n=>n.id===t)},get idMap(){const t=new Map;return e.list.forEach(n=>{t.set(n.id,n)}),t}})).views(e=>({panelsByIDs(t){const n=[];t.forEach(a=>{const o=e.idMap.get(a);o?n.push(o):console.warn(`Panel is not found, id:${a}`)});const r=n.map(a=>({...a.layout.json,i:a.id}));return{panels:n,layouts:r}}}));function Il(e,t){if(e===void 0)return e;if(t._name==="date-range")try{const[...n]=e;return n.map(r=>r===null?r:U.tz(r,"UTC").format(t.inputFormat)??r)}catch(n){return console.error(n),e}return e}function zS(e){return e.reduce((t,n)=>(t[n.key]=Il(n.config.default_value,n.config),t),{})}const Ml=b.types.model("FiltersRenderModel",{current:b.types.optional(b.types.array(bl),[]),values:b.types.optional(b.types.frozen(),{})}).views(e=>({get json(){return e.current.map(t=>t.json)},get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(n=>n.id===t)},get inOrder(){return x.sortBy(e.current,"order")},get empty(){return e.current.length===0},visibleInView(t){return x.sortBy(e.current.filter(n=>n.visibleInViewsIDSet.has(t)),"order")},get firstFilterValueKey(){return Object.keys(e.values)[0]??""},get keyLabelMap(){return e.current.reduce((t,n)=>(t[n.key]=n.label,t),{})},getSelectOption(t){const n=this.findByID(t);if(!n||!("getSelectOption"in n.config))return null;const r=e.values[n.key];return n.config.getSelectOption(r)}})).actions(e=>({setValues(t){e.values=t},setValueByKey(t,n){e.values={...e.values,[t]:n}},getValueByKey(t){return e.values[t]}}));function Al(e){return{current:e,values:zS(e)}}const ES=new Qu.AsyncParser({withBOM:!0});async function zl(e){return!Array.isArray(e)||e.length===0?"":await ES.parse(e).promise()}async function $S(e,t){const n=await zl(t),r=new Blob([n],{type:"text/csv"});vr.saveAs(r,`${e}.csv`)}function El(e){const t=new Uu;e.forEach(({id:n,data:r})=>{t.file(`${n}.csv`,zl(r))}),t.generateAsync({type:"blob"}).then(n=>{vr.saveAs(n,"dashboard_data.zip")})}function $l(e,t){const n=new Blob([t],{type:"application/json"});vr.saveAs(n,`${e}.json`)}function LS(e,t){return new Function(`return ${e}`)()(t,At)}function PS(e,t,n){return LS(e,{context:t,filters:n})}function OS(e,t){try{return new Function(`return ${e.config.processing.pre}`)()(t,At)}catch(n){return console.error(n),t}}function BS(e,t){return new Function(`return ${e.config.processing.post}`)()(t,At)}function VS(e,t,n){return e?new Function(`return ${e}`)()(t,At,n):t}const NS=uS.views(e=>({get conditionOptions(){if(!b.isAlive(e))return[];const t=b.getRoot(e).content,{context:n}=t.payloadForSQL,r=Object.keys(n).map(o=>({group:"Context",label:o,value:`context.${o}`,description:void 0})),a=t.filters.keyLabelOptions.map(o=>({group:"Filters",label:o.label,value:`filters.${o.value}`,description:o.value}));return[...r,...a]},get unmetRunByConditions(){if(!b.isAlive(e))return[];const{run_by:t}=e;if(t.length===0)return[];const n=b.getRoot(e).content.payloadForSQL;return t.filter(r=>{const a=x.get(n,r);return Array.isArray(a)?a.length===0:typeof a=="number"?Number.isNaN(a):!a})}})).views(e=>({get reQueryKey(){const{react_to:t=[]}=e;if(t.length===0)return"";const n=b.getRoot(e).content.payloadForSQL,r=[...t].reduce((a,o)=>(a[o]=x.get(n,o),a),{});return JSON.stringify(r)},get runByConditionsMet(){return e.unmetRunByConditions.length===0},get conditionNames(){if(e.unmetRunByConditions.length===0)return{context:[],filters:[]};const{keyLabelMap:t}=b.getRoot(e).content.filters,n=e.unmetRunByConditions.filter(a=>a.startsWith("context.")).map(a=>a.split("context.")[0]),r=e.unmetRunByConditions.filter(a=>a.startsWith("filters.")).map(a=>x.get({filters:t},a)).filter(a=>!!a);return{context:n,filters:r}},get queries(){return b.getParent(e,2)},get inUse(){return this.queries.isQueryInUse(e.id)}})),qS=b.types.compose("QueryRenderModel",NS,b.types.model({state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),data:b.types.optional(b.types.frozen([]),[]),error:b.types.frozen()})).views(e=>({get rootModel(){return b.getRoot(e)},get contentModel(){return this.rootModel.content},get payload(){return this.contentModel.payloadForSQL},get formattedSQL(){return wr(e.sql,this.payload)},get typedAsSQL(){return[Ne.Postgresql,Ne.MySQL].includes(e.type)},get typedAsHTTP(){return[Ne.HTTP].includes(e.type)},get datasource(){const{key:t,type:n}=e;return this.rootModel.datasources.find({type:n,key:t})},get httpConfigString(){const{context:t,filters:n}=this.payload,{name:r,pre_process:a}=e.json,o=PS(a,t,n);return console.groupCollapsed(`Request config for: ${r}`),console.log(o),console.groupEnd(),JSON.stringify(o)},get additionalQueryInfo(){return this.contentModel.getAdditionalQueryInfo(e.id)}})).views(e=>({get stateMessage(){if(e.state!=="idle")return"";if(!e.runByConditionsMet){const{context:t,filters:n}=e.conditionNames;if(t.length===0&&n.length===0)return"Waiting";const r=[];return t.length>0&&r.push(`context: ${t.join(", ")}`),n.length>0&&r.push(`filter${n.length>1?"s":""}: ${n.join(", ")}`),r.length===2&&r.splice(1,0,"and"),r.unshift("Waiting for"),r.join(" ")}return e.data.length>0?"":"Empty Data"}})).volatile(()=>({controller:new AbortController})).actions(e=>({runSQL:b.flow(function*(){var t;if(e.valid&&((t=e.controller)==null||t.abort(),!!e.runByConditionsMet)){e.controller=new AbortController,e.state="loading";try{const n=e.payload;e.data=yield*b.toGenerator(uc({payload:n,name:e.name,query:e.json,additionals:e.additionalQueryInfo},e.controller.signal)),e.state="idle",e.error=null}catch(n){if(!pt.isCancel(n)){e.data=[];const r=x.get(n,"message","unkown error");e.error=x.get(n,"response.data.detail.message",r),e.state="error"}}}}),runHTTP:b.flow(function*(){var t;if(!(!e.valid||!e.datasource)&&((t=e.controller)==null||t.abort(),!!e.runByConditionsMet)){e.controller=new AbortController,e.state="loading";try{const{type:n,key:r,post_process:a}=e.json;let o=JSON.parse(e.httpConfigString);o=OS(e.datasource,o);const l=yield*b.toGenerator(cc({type:n,key:r,configString:JSON.stringify(o),name:e.name,additionals:e.additionalQueryInfo},e.controller.signal)),u=BS(e.datasource,l),c=VS(a,u,e.contentModel.dashboardState);e.data=c,e.state="idle",e.error=null}catch(n){if(console.error(n),!pt.isCancel(n)){e.data=[];const r=x.get(n,"message","unkown error");e.error=x.get(n,"response.data.detail.message",r),e.state="error"}}}})})).actions(e=>({fetchData:t=>{if(!e.inUse&&!t){console.debug(`Skipping query[${e.name}]`);return}return e.typedAsHTTP?e.runHTTP():e.runSQL()},beforeDestroy(){var t;(t=e.controller)==null||t.abort()}})).actions(e=>({afterCreate(){b.addDisposer(e,te.reaction(()=>{var n;return e.typedAsHTTP?`${e.inUse}--${e.id}--${e.key}--${e.reQueryKey}--${(n=e.datasource)==null?void 0:n.id}`:[e.inUse,e.id,e.key,e.formattedSQL,e.pre_process,e.post_process].join("--")},()=>e.fetchData(!1),{fireImmediately:!0,delay:0}))}})),Ll=b.types.model("QueriesRenderModel",{current:b.types.optional(b.types.array(qS),[])}).views(e=>({get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(n=>n.id===t)},findByIDSet(t){return e.current.filter(n=>t.has(n.id))},get json(){return e.current.filter(t=>t.id&&t.key).map(t=>t.json)},get contentModel(){return b.getParent(e,1)},get visibleQueryIDSet(){const{views:t,filters:n}=this.contentModel,r=[];t.visibleViews.forEach(l=>{l.panels.forEach(u=>{r.push(...u.queryIDs)})});const a=x.uniq(t.visibleViews.map(l=>l.renderViewIDs).flat());n.current.forEach(l=>{const u=x.get(l,"config.options_query_id");if(!u)return;a.some(d=>l.visibleInViewsIDSet.has(d))&&r.push(u)});const o=new Set(r);return console.debug("QueryIDs:",o),o},isQueryInUse(t){return this.visibleQueryIDSet.has(t)}})).actions(e=>({downloadAllData(){const t=e.current.map(({name:n,data:r})=>({id:n,data:r}));El(t)},downloadDataByQueryIDs(t){const n=new Set(t),r=e.current.filter(a=>n.has(a.id)).map(({name:a,data:o})=>({id:a,data:o}));El(r)},downloadDataByQueryID(t){const n=e.findByID(t);if(!n){console.log("[downloadDataByQueryID] query not found");return}const{name:r,data:a}=n;$S(r,a)},refetchDataByQueryID(t){const n=e.findByID(t);if(!n){console.error(new Error(`[downloadDataByQueryID] query by ID[${t}] not found`));return}return n.fetchData(!0)}}));function FS(e){return{current:e}}const GS=cS.views(e=>({isADuplicatedKey(t){return!t||t===e.key?!1:!!b.getParent(e,2).findByKey(t)}})),Pl=b.types.model("SQLSnippetsRenderModel",{current:b.types.optional(b.types.array(GS),[])}).views(e=>({get json(){return e.current.map(t=>t.json)},get record(){return e.current.reduce((t,n)=>(t[n.key]=n.value,t),{})},get firstKey(){if(e.current.length!==0)return e.current[0].key},findByKey(t){return e.current.find(n=>n.key===t)}}));function WS(e){return{current:e}}function ur(e,t,n,r){return e.reduce((a,o)=>{try{a[o[t]]=xr(o[n],r)}catch(l){a[o[t]]=l.message}return a},{})}class jS{constructor(t){q(this,"origin");q(this,"copy");this.origin=t,this.copy=b.clone(t),te.makeAutoObservable(this,{},{autoBind:!0,deep:!1})}get changed(){return!x.isEqual(b.getSnapshot(this.origin),b.getSnapshot(this.copy))}commit(){b.applySnapshot(this.origin,b.getSnapshot(this.copy))}update(t){b.applySnapshot(this.copy,t)}}const RS=e=>new jS(e),YS=k.observer(({view:e})=>{const t=ue(),n=le(),r=Fe.useModals(),{panel:a,downloadPanelScreenshot:o}=Qe(),{id:l}=a,{viewPanelInFullScreen:u,inFullScreen:c}=m.useContext(or),d=()=>{n.duplicatePanelByID(l,e.id)},f=()=>{t.editor.open(["_VIEWS_",e.id,"_PANELS_",l])},h=()=>r.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>n.removePanelByID(l,e.id),confirmProps:{color:"red"},zIndex:320}),g=m.useCallback(()=>{u(l)},[l,u]),y=!c&&e.type!==j.Modal;return i(B,{children:i(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:p(s.Menu,{withinPortal:!0,children:[i(s.Menu.Target,{children:i(s.Box,{className:"panel-dropdown-target",sx:{width:"100%"}})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{onClick:a.refreshData,icon:i(I.Refresh,{size:14}),children:"Refresh"}),i(s.Menu.Item,{onClick:a.downloadData,icon:i(I.Download,{size:14}),children:"Download Data"}),i(s.Menu.Item,{onClick:o,icon:i(E.IconCamera,{size:14}),children:"Screenshot"}),y&&i(s.Menu.Item,{onClick:g,icon:i(I.ArrowsMaximize,{size:14}),disabled:!0,children:"Full Screen"}),i(s.Divider,{label:"Edit",labelPosition:"center"}),i(s.Menu.Item,{onClick:f,icon:i(I.Settings,{size:14}),children:"Settings"}),i(s.Menu.Item,{onClick:d,icon:i(I.Copy,{size:14}),children:"Duplicate"}),i(s.Menu.Item,{color:"red",onClick:h,icon:i(I.Trash,{size:14}),children:"Delete"})]})]})})})});function QS(e){return e?["<p><br></p>","<p></p>"].includes(e):!0}const Bi=k.observer(()=>{const[e,t]=m.useState(!1),{panel:n}=Ct();return QS(n.description)?null:p(B,{children:[i(s.Modal,{opened:e,onClose:()=>t(!1),title:n.name,withCloseButton:!1,withinPortal:!0,zIndex:310,children:i(Yn,{value:n.description,styles:{root:{border:"none"},content:{padding:0}}})}),i(s.Tooltip,{label:"Click to see description",position:"top-start",withinPortal:!0,children:i(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>t(r=>!r),sx:{verticalAlign:"baseline",cursor:"pointer"},children:i(I.InfoCircle,{size:20})})})]})}),PM="",US=k.observer(function(){const{panel:t}=Ct(),{name:n,title:r}=t;return r.show?i(s.Group,{grow:!0,position:"center",className:"panel-title-wrapper",sx:{flexGrow:1},children:i(s.Text,{align:"center",lineClamp:1,className:"panel-title-text",children:n})}):null});function KS(e){const t=m.useRef(null);return{ref:t,downloadPanelScreenshot:()=>{const r=t.current;if(!r)return;const a=r.offsetWidth*2,o=r.offsetHeight*2;ts.toBlob(t.current,{bgcolor:"white",width:a,height:o,style:{border:"none",borderRadius:0,transformOrigin:"0 0",transform:"scale(2)"}}).then(l=>{window.saveAs(l,`${e.title?e.title:e.viz.type}.png`)})}}}var Ol=(e=>(e.migrated="migrated",e.nothingToMigrate="nothingToMigrate",e.checkFailed="checkFailed",e.migrationFailed="migrationFailed",e))(Ol||{}),cr=(e=>(e.notStarted="notStarted",e.inProgress="inProgress",e.done="done",e))(cr||{});class XS{constructor(t){q(this,"vizInstance");q(this,"operationManager");q(this,"triggerManager");q(this,"vizManager");q(this,"runningMigration");q(this,"panelModel");q(this,"status","notStarted");this.panelModel=t.getRequired(be.instanceScope.panelModel),this.vizInstance=t.getRequired(be.instanceScope.vizInstance),this.operationManager=t.getRequired(be.instanceScope.operationManager),this.triggerManager=t.getRequired(be.instanceScope.triggerManager),this.vizManager=t.getRequired(be.vizManager)}async createMigrationTask(){const t=[];try{await this.instanceNeedMigration()&&t.push(()=>this.runInstanceMigration()),await this.interactionNeedMigration()&&t.push(()=>this.runInteractionMigration())}catch(n){return console.warn("check migration failed",n),"checkFailed"}if(t.length===0)return"nothingToMigrate";try{return await Promise.all(t.map(n=>n())),"migrated"}catch(n){return console.warn("migration failed",n),"migrationFailed"}}async runMigration(){return this.runningMigration||(this.status="inProgress",this.runningMigration=this.createMigrationTask().then(t=>(this.status="done",t))),this.runningMigration}async runInteractionMigration(){await this.operationManager.runMigration(),await this.triggerManager.runMigration()}async runInstanceMigration(){const t=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData,panelModel:this.panelModel};await t.migrator.migrate(n)}async instanceNeedMigration(){const t=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData};return t.migrator.needMigration(n)}async interactionNeedMigration(){return await this.operationManager.needMigration()||await this.triggerManager.needMigration()}}function Bl(e){const{panel:t}=Ct();return m.useCallback(n=>{const r=n.getRequired(be.vizManager),a=r.resolveComponent(e.viz.type);return n.createScoped().provideFactory(be.instanceScope.vizInstance,()=>r.getOrCreateInstance(e)).provideFactory(be.instanceScope.interactionManager,o=>{const l=o.getRequired(be.instanceScope.vizInstance);return new Or(l,a,$n)}).provideFactory(be.instanceScope.operationManager,o=>o.getRequired(be.instanceScope.interactionManager).operationManager).provideFactory(be.instanceScope.triggerManager,o=>o.getRequired(be.instanceScope.interactionManager).triggerManager).provideValue(be.instanceScope.panelModel,t).provideFactory(be.instanceScope.migrator,o=>new XS(o))},[e.viz.type,e.viz.conf])}function Vl(e){const[t,n]=m.useState(!1),r=il().getRequired(be.instanceScope.migrator);return Q.useAsyncEffect(async()=>{const a=r.status===cr.notStarted;n(r.status===cr.done),r.status===cr.notStarted&&r.runMigration().then(o=>{o===Ol.migrated&&a&&(e==null||e())}).finally(()=>{n(!0)})},[r]),t}function Nl(e,t){const n=il().getRequired(be.instanceScope.vizInstance);return m.useEffect(()=>(n.instanceData.setItem(null,t.viz.conf),n.instanceData.watchItem(null,r=>{e(r)})),[e,t.viz.type]),n}function JS({setVizConf:e,...t}){const{panel:n}=t,r=Nl(e,n),a=Vl(()=>{Tn.showNotification({title:`${n.name} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})});return Q.useAsyncEffect(async()=>{await r.instanceData.setItem(null,n.viz.conf)},[r,n.viz.type]),a?i(fc,{...t}):i(s.Text,{children:"Checking update..."})}function ZS(e){const{panel:t,setVizConf:n}=e;Nl(n,t);const{inEditMode:r}=m.useContext(zn);return Vl(()=>{r&&Tn.showNotification({title:`${t.name} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?i(hc,{...e}):i(s.Text,{children:"Checking update"})}const OM="";function HS(e,t){const{vizManager:n}=m.useContext(ct),{panel:{viz:r,title:a,id:o,name:l,description:u,queryIDs:c,variables:d}}=Ct(),f={id:o,name:l,title:a,description:u,queryIDs:c,viz:r,layout:t},h=Bl(f);try{return n.resolveComponent(r.type),i(sr,{configure:h,children:i(ZS,{setVizConf:r.setConf,panel:f,data:e,variables:d,vizManager:n})})}catch(g){return console.info(x.get(g,"message")),null}}const ql=k.observer(function({data:t}){const{ref:n,width:r,height:a}=_e.useElementSize(),o=HS(t,{w:r,h:a}),l=r>0&&a>0;return i("div",{className:"viz-root",ref:n,children:i(s.Box,{sx:{width:r,height:a,overflow:"hidden"},children:l&&i(Ee,{children:o})})})}),Fl=k.observer(({panel:e})=>p(s.Stack,{children:[e.queryErrors.map((t,n)=>i(s.Text,{color:"red",size:"sm",align:"center",sx:{fontFamily:"monospace"},children:t},`${n}-${t}`)),i(s.Text,{color:"gray",align:"center",size:"sm",children:e.queryStateMessages})]})),Vi=k.observer(({panel:e})=>p(s.Flex,{className:"panel-viz-section",direction:"column",sx:{position:"relative",width:"100%"},children:[i(s.LoadingOverlay,{visible:e.dataLoading,exitTransitionDuration:0}),!e.canRenderViz&&i(Fl,{panel:e}),e.canRenderViz&&i(ql,{data:e.data})]})),e_={border:"1px solid #e9ecef"},Gl=k.observer(({panel:e,panelStyle:t,dropdownContent:n})=>{const{ref:r,downloadPanelScreenshot:a}=KS(e);return e.title.show,i(Er,{value:{panel:e,data:e.data,loading:e.dataLoading,errors:e.queryErrors,downloadPanelScreenshot:a},children:p(s.Box,{className:`panel-root ${e.title.show?"panel-root--show-title":""}`,ref:r,p:0,sx:{...e_,...t},children:[i(s.Box,{className:"panel-description-popover-wrapper",children:i(Bi,{})}),n,i(US,{}),i(Vi,{panel:e})]})})}),t_={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function n_(e){return e.style.border.enabled?{}:t_}const Wl=k.observer(function({panel:t,view:n}){const r=n_(t);return i(Gl,{panel:t,panelStyle:r,dropdownContent:i(YS,{view:n})})});function r_(e){return!["richText","button"].includes(e)}const i_=k.observer(({view:e})=>{const{panel:t,downloadPanelScreenshot:n}=Ct(),{id:r}=t,{viewPanelInFullScreen:a,inFullScreen:o}=m.useContext(or),l=m.useCallback(()=>{a(r)},[r,a]),u=!o&&e.type!==j.Modal;return r_(t.viz.type)?i(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:p(s.Menu,{withinPortal:!0,children:[i(s.Menu.Target,{children:i(s.Box,{className:"panel-dropdown-target"})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{onClick:t.refreshData,icon:i(I.Refresh,{size:14}),children:"Refresh"}),i(s.Menu.Item,{onClick:t.downloadData,icon:i(I.Download,{size:14}),children:"Download Data"}),i(s.Menu.Item,{onClick:n,icon:i(E.IconCamera,{size:14}),children:"Screenshot"}),u&&i(s.Menu.Item,{onClick:l,icon:i(I.ArrowsMaximize,{size:14}),children:"Full Screen"})]})]})}):null});function a_(e){return e.style.border.enabled?{}:{border:"1px dashed transparent"}}const Ni=k.observer(({panel:e,view:t})=>{const n=a_(e);return i(Gl,{panel:e,panelStyle:n,dropdownContent:i(i_,{view:t})})}),s_={modal:{display:"flex",flexDirection:"column",flexWrap:"nowrap"},body:{display:"flex",height:"calc(100vh - 88px)"}},jl=k.observer(function({view:t,panel:n,exitFullScreen:r}){return i(s.Modal,{opened:!0,fullScreen:!0,onClose:r,title:i(s.Button,{color:"blue",size:"xs",onClick:r,leftIcon:i(I.ArrowLeft,{size:20}),children:"Exit fullscreen"}),styles:s_,children:i(s.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:i(Ni,{view:t,panel:n})})})});function Rl(e,t,n){const{panels:r}=ye(),a=e.id==="Main",[o,l]=m.useState(()=>a&&r.findByID(t)?t:null),u=m.useCallback(h=>{l(h),a&&n(h)},[a,n]),c=m.useCallback(()=>{l(null),a&&n("")},[a,n]),d=o?r.findByID(o):null;return{viewPanelInFullScreen:u,exitFullScreen:c,inFullScreen:!!d,fullScreenPanel:d}}const BM="",o_=m.forwardRef(({h:e},t)=>i(s.ActionIcon,{ref:t,className:"react-grid-customDragHandle",sx:{userSelect:"none",cursor:"grab",position:"absolute",top:5,right:e>38?5:20,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",children:i(I.ArrowsMove,{size:16})})),l_=m.forwardRef(({handleAxis:e,...t},n)=>i(s.ActionIcon,{ref:n,className:"react-grid-customResizeHandle",sx:{userSelect:"none",cursor:"nwse-resize",position:"absolute",bottom:0,right:0,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",...t,children:i(I.ChevronDownRight,{size:16})})),u_=Dn.WidthProvider(Dn),c_=k.observer(({view:e,className:t="layout"})=>{const n=ye(),{panels:r,layouts:a}=n.panels.panelsByIDs(e.panelIDs),o=m.useCallback(u=>{u.forEach(({i:c,...d})=>{const f=n.panels.findByID(c);f&&f.layout.set(d)})},[n]),l=(u,c,d,f)=>{d.h<30&&(d.h=30,f.h=30),d.w<4&&(d.w=4,f.w=4)};return i(u_,{onLayoutChange:o,className:`dashboard-layout ${t}`,rowHeight:1,cols:36,margin:[0,0],isBounded:!0,isDraggable:!0,isResizable:!0,layout:a,draggableHandle:".react-grid-customDragHandle",resizeHandle:i(l_,{}),onResize:l,children:r.map((u,c)=>p("div",{"data-grid":{...u.layout},className:"panel-grid-item",children:[i(o_,{h:u.layout.h}),i(Wl,{view:e,panel:u})]},u.id))})}),d_=Dn.WidthProvider(Dn),p_=k.observer(function({view:t,className:n="layout"}){const{panels:r,layouts:a}=ye().panels.panelsByIDs(t.panelIDs);return i(d_,{className:`dashboard-layout ${n}`,cols:36,rowHeight:1,margin:[0,0],isDraggable:!1,isResizable:!1,layout:a,children:r.map(o=>i("div",{"data-grid":{...o.layout},className:"panel-grid-item",children:i(Ni,{view:t,panel:o})},o.id))})});function qi(e){const t=m.useRef(null);return{ref:t,downloadScreenshot:()=>{var l;const r=(l=t.current)==null?void 0:l.querySelector(".react-grid-layout");if(!r)return;const a=r.offsetWidth*2+10,o=r.offsetHeight*2+10;ts.toBlob(r,{bgcolor:"white",width:a,height:o,style:{transformOrigin:"0 0",transform:"scale(2)"}}).then(u=>{window.saveAs(u,`${e.name}.png`)})}}}const h_=k.observer(({downloadScreenShot:e})=>{const[t,{setTrue:n,setFalse:r}]=Q.useBoolean(!1),a=Mr(),o=ye(),l=()=>{const u=JSON.stringify(o.json,null,2),c=`${a.name}__${o.name}`;$l(c,u)};return p(s.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:200,closeDelay:400,withinPortal:!0,position:"bottom-end",children:[i(s.Menu.Target,{children:i(s.Affix,{position:{bottom:"20px",right:"10px"},zIndex:1,children:i(s.ActionIcon,{size:"md",variant:"gradient",gradient:{from:"indigo",to:"cyan"},onMouseEnter:n,onMouseLeave:r,sx:{opacity:t?1:.6,transform:`translateX(${t?0:"2px"})`,transition:"all ease 300ms",borderRadius:"50%"},children:i(E.IconShare3,{size:"1rem"})})})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{icon:i(E.IconCamera,{size:14}),onClick:e,children:"Screenshot"}),i(s.Menu.Divider,{}),i(s.Menu.Item,{icon:i(E.IconDownload,{size:14}),onClick:o.queries.downloadAllData,children:"Download Data"}),i(s.Menu.Item,{icon:i(E.IconCode,{size:14}),onClick:l,children:"Download Schema"})]})]})}),Yl=k.observer(({children:e,view:t,sx:n={}})=>{const{ref:r,downloadScreenshot:a}=qi(t);return p(B,{children:[i(s.Box,{ref:r,sx:n,children:e}),i(h_,{downloadScreenShot:a})]})}),Ql=k.observer(({downloadScreenshot:e})=>i(s.ActionIcon,{className:"download-screenshot-button",color:"blue",onClick:e,children:i(E.IconCamera,{size:14})})),f_=k.observer(({children:e,view:t})=>{const n=ye(),r=t.config,a=n.views.visibleViewIDs.includes(t.id),o=()=>n.views.rmVisibleViewID(t.id),{ref:l,downloadScreenshot:u}=qi(t);return i(s.Modal,{size:r.width,centered:!0,opened:a,onClose:o,withCloseButton:!1,title:p(s.Group,{position:"apart",px:"1rem",h:"48px",children:[i(s.Box,{children:r.custom_modal_title.value}),i(Ql,{downloadScreenshot:u})]}),trapFocus:!0,onDragStart:c=>{c.stopPropagation()},styles:{root:{position:"fixed",zIndex:200,inset:0},overlay:{zIndex:"unset"},inner:{zIndex:"unset",padding:"0 !important"},content:{border:"1px solid #efefef",maxHeight:"unset !important",overflow:"hidden"},body:{maxHeight:r.height,overflow:"auto",position:"relative"},header:{padding:0},title:{flexGrow:1}},transitionProps:{duration:0},children:i(s.Box,{ref:l,children:e})})}),g_=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},m_=k.observer(({view:e})=>{const t=ye(),n=e.config;return p(s.Tabs,{className:"render-view-tabs",variant:n.variant,orientation:n.orientation,value:e.tab,onTabChange:e.setTab,styles:{root:{height:"100%",overflow:n.orientation==="horizontal"?"hidden":"auto"},panel:{padding:n.orientation==="horizontal"?"8px 0px 8px":"0",height:"100%",overflow:"auto"}},keepMounted:!1,children:[i(s.Tabs.List,{grow:n.grow,children:n.tabs.map(r=>i(s.Tabs.Tab,{value:r.id,sx:g_(r),disabled:!r.view_id,children:r.name??r.id},r.id))}),n.tabs.map(r=>{const a=t.views.findByID(r.view_id);return a?i(s.Tabs.Panel,{value:r.id,children:i(dr,{view:a})},r.id):null})]})}),y_=k.observer(({view:e,children:t})=>{switch(e.type){case j.Modal:return i(f_,{view:e,children:t});case j.Tabs:return i(m_,{view:e});case j.Division:default:return i(Yl,{view:e,children:t})}}),b_=k.observer(({children:e,view:t})=>i(Yl,{sx:{paddingTop:"10px",paddingBottom:"100px"},view:t,children:e}));function Ul(e){return e.replace(/(vw|vh)/,"%")}const v_=k.observer(({children:e,view:t})=>{const n=t.config,{width:r,height:a}=m.useMemo(()=>({width:Ul(n.width),height:Ul(n.height)}),[n.width,n.height]),{ref:o,downloadScreenshot:l}=qi(t);return i(s.Box,{sx:{height:"100%","> div:not(.mantine-Modal-root)":{height:"100%"}},children:i(s.Modal,{size:n.width,opened:!0,onClose:x.noop,withCloseButton:!1,title:p(s.Group,{position:"apart",px:"1rem",h:"48px",children:[i(s.Box,{children:n.custom_modal_title.value}),i(Ql,{downloadScreenshot:l})]}),trapFocus:!0,onDragStart:u=>{u.stopPropagation()},styles:{root:{position:"relative",height:"100%"},overlay:{position:"absolute !important"},inner:{position:"relative",top:"50%",left:"50%",right:"unset",bottom:"unset",transform:"translate(-50%, -50%)",padding:"0 !important",width:r,height:a,maxHeight:a},content:{border:"1px solid #efefef",height:"100%"},body:{maxHeight:"calc(100% - 48px)",overflow:"auto"},header:{padding:0},title:{flexGrow:1}},withinPortal:!1,transitionProps:{duration:0},children:i(s.Box,{ref:o,children:e})})})}),x_=({variant:e,orientation:t})=>{const n={root:{height:"100%",overflow:"hidden"},tab:{},panel:{padding:"16px"}};return e==="pills"&&t==="horizontal"&&(n.tab.paddingTop="6px",n.tab.paddingBottom="6px"),t==="vertical"&&(n.tab["&.add-a-tab"]={paddingTop:"1px",paddingBottom:"1px"},n.tab["&.add-a-tab .mantine-Tabs-tabLabel"]={marginLeft:"auto",marginRight:"auto"}),n},w_=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},C_=k.observer(({view:e})=>{const t=Fe.useModals(),n=le(),r=m.useMemo(()=>n.views.options.filter(u=>u.type===j.Division),[e.id,n.views.options]),a=e.config,o=u=>t.openConfirmModal({title:"Delete this tab?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{a.removeTab(u)},confirmProps:{color:"red"},zIndex:320}),l=a.tabs.length===0;return p(s.Tabs,{className:"preview-view-tabs",variant:a.variant,orientation:a.orientation,value:e.tab,onTabChange:e.setTab,styles:x_(a),children:[p(s.Tabs.List,{grow:a.grow,children:[a.tabs.map(u=>i(s.Tabs.Tab,{value:u.id,sx:w_(u),children:u.name??u.id},u.id)),i(s.Tabs.Tab,{onClick:a.addTab,value:"add",className:"add-a-tab",children:i(I.Plus,{size:18,color:"#228be6"})})]}),a.tabs.map((u,c)=>{const d=n.views.findByID(u.view_id);return p(s.Tabs.Panel,{value:u.id,sx:{position:"relative"},children:[p(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:200},children:[i(s.Overlay,{opacity:.8,color:"#FFF",blur:10,zIndex:100}),p(s.Stack,{mx:"auto",mt:100,sx:{width:"300px",position:"relative",zIndex:200},children:[i(s.TextInput,{label:"Tab Name",value:u.name,onChange:f=>u.setName(f.currentTarget.value)}),i(s.Select,{label:"View",value:u.view_id,onChange:u.setViewID,data:r}),i(s.ColorInput,{label:"Color",value:u.color,onChange:u.setColor,disabled:a.variant!=="default"}),d&&p(s.Button,{mt:20,variant:"gradient",leftIcon:i(E.IconArrowsLeftRight,{size:18}),gradient:{from:"cyan",to:"indigo"},onClick:()=>n.views.setIDOfVIE(d.id),children:["Swith to View: ",d.name]}),i(s.Button,{mt:20,variant:"subtle",color:"red",onClick:()=>o(c),disabled:l,leftIcon:i(E.IconTrash,{size:14}),children:"Delete This Tab"})]})]}),d&&i(dr,{view:d})]},u.id)})]})}),S_=k.observer(({view:e,children:t})=>{switch(e.type){case j.Modal:return i(v_,{view:e,children:t});case j.Tabs:return i(C_,{view:e});case j.Division:default:return i(b_,{view:e,children:t})}}),Kl=k.observer(function({view:t}){return i(or.Provider,{value:{viewPanelInFullScreen:x.noop,inFullScreen:!1},children:i(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:i(S_,{view:t,children:p(s.Box,{sx:{position:"relative"},children:[i(s.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:i(ol,{view:t})}),i(c_,{view:t})]})})})})}),dr=k.observer(function({view:t}){const{fullScreenPanelID:n,setFullScreenPanelID:r}=ws(),{viewPanelInFullScreen:a,exitFullScreen:o,inFullScreen:l,fullScreenPanel:u}=Rl(t,n,r);return i(or.Provider,{value:{viewPanelInFullScreen:a,inFullScreen:l},children:p(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,sx:{height:t.type===j.Modal?"0 !important":"100%"},children:[l&&i(jl,{view:t,panel:u,exitFullScreen:o}),i(y_,{view:t,children:p(s.Box,{sx:{position:"relative"},children:[!l&&i(s.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:i(ol,{view:t})}),!l&&i(p_,{view:t})]})})]})})});var Xl=(e=>(e.Use="use",e.Edit="edit",e))(Xl||{});const __={[j.Division]:"Division",[j.Tabs]:"Tabs",[j.Modal]:"Modal"},Jl={[j.Division]:"rgba(255, 0, 0, 0.2)",[j.Modal]:"rgba(0, 0, 0, 0.2)",[j.Tabs]:"rgba(255, 200, 100, 0.4)"},k_={[j.Division]:"#ff4000",[j.Modal]:"#000",[j.Tabs]:"#ffad18"},T_={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:j.Division,config:{},panelIDs:[]}],panels:[],filters:[],version:"9.19.0"};function D_(e,t,n){b.addDisposer(e,b.addMiddleware(e,(r,a)=>{a(r,()=>{b.getType(r.context)===t&&r.type==="action"&&n(r.name,r.context)})}))}const Zl=b.types.compose("FiltersModel",Ml,b.types.model("FiltersModel",{previewValues:b.types.optional(b.types.frozen(),{})})).views(e=>({get options(){return e.current.map(t=>({label:t.label??t.id,value:t.id,_type:"filter"}))},get selects(){return e.current.filter(t=>t.type===ve.Select).map(t=>({label:t.label??t.id,value:t.id}))},get keyLabelOptions(){return e.current.map(t=>({label:t.label??t.key,value:t.key}))}})).actions(e=>({replace(t){e.current=b.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByID(t){const n=e.current.findIndex(r=>r.id===t);n>=0&&e.current.splice(n,1)},updatePreviewValues(t){e.previewValues=t}})).actions(e=>{function t(){D_(e.current,bl,(n,r)=>{if(n==="setType"){const a=Il(r.config.default_value,r.config);e.setValueByKey(r.key,a),e.updatePreviewValues({...e.previewValues,[r.key]:a})}})}return{afterCreate(){t()}}}),Hl=Ll.views(e=>({get options(){const t=e.current.map(n=>({value:n.id,label:n.name,_type:"query"}));return x.sortBy(t,n=>n.label.toLowerCase())},get sortedList(){return x.sortBy(e.current,t=>t.name.toLowerCase())}})).actions(e=>({replace(t){e.current=b.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},replaceByIndex(t,n){e.current.splice(t,1,n)},removeQuery(t){const n=e.current.find(r=>r.id===t);n&&(b.detach(n),e.current.remove(n))},removeQueries(t){const n=new Set(t);e.current.forEach(a=>{n.has(a.id)&&b.detach(a)});const r=[...e.current];x.remove(r,a=>n.has(a.id)),e.current=b.cast(r)}})),eu=Pl.views(e=>({get sortedList(){return x.sortBy(e.current,t=>t.key.toLowerCase())},get options(){const t=e.current.map(n=>({label:n.key,value:n.key,_type:"sql_snippet"}));return x.sortBy(t,n=>n.label.toLowerCase())}})).actions(e=>({replace(t){e.current=b.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByKey(t){const n=e.current.findIndex(r=>r.key===t);n>=0&&e.current.splice(n,1)},removeByKeys(t){const n=new Set(t);e.current.forEach(a=>{n.has(a.key)&&b.detach(a)});const r=[...e.current];x.remove(r,a=>n.has(a.key)),e.current=b.cast(r)},replaceByIndex(t,n){e.current.splice(t,1,n)}})),I_=b.types.model({data:b.types.optional(b.types.frozen(),[]),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0}})),M_=b.types.model({data:b.types.optional(b.types.frozen(),[]),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0}})),A_=b.types.model({page:b.types.optional(b.types.number,1),limit:b.types.optional(b.types.number,20),data:b.types.optional(b.types.frozen(),[]),total:b.types.optional(b.types.number,0),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(e=>({get keywords(){return b.getParent(e,1)},get keywordString(){const{table_name:t,table_schema:n}=b.getParent(e,1);return`${n}||${t}`}})).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0},get maxPage(){return Math.ceil(e.total/e.limit)},get offset(){return(e.page-1)*e.limit},get countSql(){const{table_name:t,table_schema:n}=e.keywords;return`
|
|
439
|
+
`}}}function vS(t,e){const n=Pt(t.heat_block.min,e),i=Pt(t.heat_block.max,e);return{min:n,max:i,calculable:!0,orient:"horizontal",left:"center",top:0,itemWidth:15}}function xS(t,e,n){const i=A(t.x_axis.data_key),a=x.uniq(e[i.queryID].map(c=>c[i.columnKey])),{overflow:o,rotate:l}=t.x_axis.axisLabel,u=Ue(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:2}}function wS(t,e,n){const i=A(t.x_axis.data_key),a=A(t.y_axis.data_key),{nameAlignment:o,data_key:l,...u}=t.y_axis,c=x.uniq(e[i.queryID].map(g=>g[a.columnKey])),{overflow:p,rotate:h}=t.y_axis.axisLabel,f=Ue(p.on_axis);return{...u,type:"category",data:c,axisLabel:{rotate:h,...f,formatter:n},axisLine:{show:!0,color:"blue"},axisTick:{show:!0,alignWithLabel:!0},splitArea:{show:!0},nameTextStyle:{fontWeight:"bold",align:o},nameLocation:"end",nameGap:15,z:2}}const CS={tooltip:{confine:!0}};function SS(t,e,n){if(!t.x_axis.data_key||!t.y_axis.data_key||!t.heat_block.data_key)return{};const i=n.reduce((u,c)=>{const p=ot(c,e);return u[c.name]=Fe(c,p),u},{}),a=pS(t),o=hS(t),l={xAxis:xS(t,e,a.x_axis),yAxis:wS(t,e,a.y_axis),series:gS(t,e),tooltip:bS(t,e,a,o),grid:fS(t),visualMap:vS(t,i)};return x.defaultsDeep({},l,CS)}Y.use([B.DataZoomComponent,re.HeatmapChart,B.GridComponent,B.LegendComponent,B.TooltipComponent,B.VisualMapComponent,_e.CanvasRenderer]);function _S({conf:t,data:e,width:n,height:i,interactionManager:a,variables:o}){const l=m.useMemo(()=>{const f=A(t.x_axis.data_key),g=A(t.y_axis.data_key);return x.keyBy(e[f.queryID],b=>`${b[f.columnKey]}---${b[g.columnKey]}`)},[e,t.x_axis.data_key,t.y_axis.data_key]),u=Ne(a.triggerManager,so.id),c=m.useCallback(f=>{const[g,b]=f.value,w=x.get(l,`${g}---${b}`,{error:"rowData is not found"});u.forEach(_=>{a.runInteraction(_.id,{...f,rowData:w})})},[l,u,a]),p=m.useMemo(()=>({click:c}),[c]),h=m.useMemo(()=>SS(t,e,o),[t,e]);return r(Se,{echarts:Y,option:h,style:{width:n,height:i},onEvents:p,notMerge:!0,theme:"merico-light"})}function kS({context:t,instance:e}){const n=qe({vizManager:t.vizManager,instance:e}),{value:i}=V(t.instanceData,"config"),{variables:a}=t,o=m.useMemo(()=>x.defaults({},i,fi),[i]),l=t.data,{width:u,height:c}=t.viewport;return!u||!c?null:r(Me,{width:u,height:c,children:r(_S,{variables:a,width:Re(u),height:Qe(c),data:l,conf:o,interactionManager:n})})}class TS extends se{constructor(){super(...arguments);P(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const DS={displayName:"Merico Heatmap",displayGroup:"Merico suite",migrator:new TS,name:"merico-heatmap",viewRender:kS,configRender:uS,createConfig:()=>({version:1,config:fi}),triggers:[so]},IS=[{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"})),MS=[uc,cc,hc,pc,dc,fc],lo=()=>({id:"dashboard",version:va,manifest:{viz:[ai,fx,Vw,Rb,Ox,Oy,o0,Ic,Kh,om,Wm,wC,Sy,Vg,nx,ob,Ob,Qw,N0,DS,H0,uf],color:[...IS,...MS]}}),tn=new bc,ce={pluginManager:it("pluginManager"),vizManager:it("vizManager"),colorManager:it("colorManager"),instanceScope:{panelModel:it("panelModel"),vizInstance:it("vizInstance"),interactionManager:it("interactionManager"),migrator:it("migrator"),operationManager:it("operationManager"),triggerManager:it("triggerManager")}},gi=()=>{try{tn.install(lo())}catch{}const t=new sc(tn),e=new yc(tn);return{pluginManager:tn,vizManager:t,colorManager:e}},tt=m.createContext(gi());try{tn.install(lo())}catch{}const mi=m.createContext(null);function Gn(t){const e=m.useContext(mi),n=q.useCreation(()=>t.configure(e||new lr),[t.configure]),i=q.usePrevious(n);return i&&i!==n&&i.dispose(),r(mi.Provider,{value:n,children:t.children})}function uo(){return m.useContext(mi)}const AS=({description:t,isDescriptionEmpty:e})=>e?null:r(s.Tooltip,{color:"white",label:r(Dn,{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:r(s.Box,{sx:{height:"16px",alignSelf:"center"},children:r(M.IconInfoCircle,{size:16,color:"gray"})})}),zS=k.observer(({label:t,config:{default_value:e,description:n,isDescriptionEmpty:i,...a},value:o,onChange:l})=>d(s.Box,{children:[r(s.Text,{children:" "}),r(s.Checkbox,{label:d(s.Group,{noWrap:!0,position:"apart",align:"middle",spacing:6,children:[r(s.Box,{sx:{flexGrow:1},children:t}),r(AS,{description:n,isDescriptionEmpty:i})]}),checked:o||!1,onChange:u=>l(u.currentTarget.checked),...a,pt:".4em",styles:{input:{borderColor:"#e9ecef"}}})]})),co=k.observer(({label:t,config:e,value:n=[null,null],onChange:i})=>{const{inputFormat:a,...o}=e,l=Array.isArray(n)?n.map(h=>h?G(h).toDate():null):[null,null],u=h=>{i(h.map(f=>f&&G(f).format(a)))},c=e.getMinDate(l[0]),p=e.getMaxDate(l[0]);return r(su.DatePickerInput,{type:"range",label:t,value:l,onChange:u,icon:r(T.Calendar,{size:16}),sx:{minWidth:"16em"},minDate:c,maxDate:p,valueFormat:a,styles:{input:{borderColor:"#e9ecef"}},...o})}),ES=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"},required:{color:"#fa5252",paddingLeft:"3px"},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":{width:"calc(100% - 30px)",overflow:"hidden",'div[data-role="label"]':{overflowWrap:"break-word"}}},".rc-virtual-list-holder-inner":{alignItems:"flex-start"}}})),po=({errorMessage:t})=>t?r(s.Text,{color:"red",size:12,children:t}):r(s.Text,{color:"dimmed",size:12,children:"Not found"}),PS=({disabled:t,classNames:e,styles:n,unstyled:i,radius:a,style:o,label:l,value:u,onChange:c,options:p,errorMessage:h,required:f})=>{const{classes:g,cx:b}=ES({radius:a},{name:"MultiSelectWidget",classNames:e,styles:n,unstyled:i}),[w,_]=m.useState(!1),D=K=>{_(K)},L=w&&(u==null?void 0:u.length)>0,[N,J]=m.useState(""),ae=m.useMemo(()=>{if(!N)return p;const K=N.toLowerCase(),oe=pe=>{var me;return((me=pe.description)==null?void 0:me.toLowerCase().includes(K))||pe.label.toLowerCase().includes(K)};return p.filter(oe)},[N,p]);return d(s.Stack,{spacing:3,children:[d(s.Group,{position:"apart",children:[d(s.Text,{className:g.label,children:[l,f&&r("span",{className:g.required,"aria-hidden":"true",children:"*"})]}),L&&r(s.Tooltip,{label:`${u.length} selected`,children:r(s.Badge,{children:u.length})})]}),r(aa,{disabled:t,allowClear:!0,className:b(g.root,"check-select"),dropdownClassName:b(g.dropdown,""),onDropdownVisibleChange:D,transitionName:"rc-select-dropdown-slide-up",choiceTransitionName:"rc-select-selection__choice-zoom",style:o,clearIcon:()=>r(s.CloseButton,{}),value:u,onChange:c,onSelect:console.log,mode:"multiple",maxTagCount:0,notFoundContent:r(po,{errorMessage:h}),maxTagTextLength:10,maxTagPlaceholder:K=>`${K.length} selected`,searchValue:N,onSearch:J,filterOption:!1,children:ae.map(K=>d(aa.Option,{title:K.label,children:[r(s.Text,{size:"sm","data-role":"label",children:K.label}),K.description&&r(s.Text,{size:"xs",color:"dimmed","data-role":"description",children:K.description})]},K.value))})]})},LS=k.observer(({label:t,config:e,value:n,onChange:i})=>{const a=ue(),o=!!e.options_query_id,{state:l,error:u}=a.getDataStuffByID(e.options_query_id),c=l==="loading",p=e.min_width?e.min_width:"200px",h=o?c:!1,f=g=>i(g,!1);return r(PS,{label:t,options:e.options,style:{minWidth:"160px",width:p,maxWidth:h?p:"unset",borderColor:"#e9ecef"},disabled:h,value:n,onChange:f,errorMessage:u,required:e.required})}),BS=m.forwardRef(({label:t,description:e,...n},i)=>r("div",{ref:i,...n,children:r(s.Group,{noWrap:!0,children:d("div",{children:[r(s.Text,{size:"sm","data-role":"label",children:t}),r(s.Text,{size:"xs",color:"dimmed","data-role":"description",children:e})]})})})),OS=k.observer(({label:t,config:e,value:n,onChange:i})=>{const a=ue(),o=!!e.options_query_id,{state:l,error:u}=a.getDataStuffByID(e.options_query_id),c=l==="loading";return r(s.Select,{label:t,data:e.options,disabled:o?c:!1,value:n,onChange:i,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:BS})});function $S({label:t,config:e,value:n,onChange:i}){return r(s.TextInput,{label:t,value:n||"",onChange:a=>i(a.currentTarget.value),...e,styles:{input:{borderColor:"#e9ecef"}}})}const VS=({rotate:t,onClick:e})=>r("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:r("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"})}),NS=({expanded:t,isLeaf:e,value:n,onClick:i,...a})=>(n==="0-0-value"&&console.log(a),e?r("span",{style:{width:"14px",display:"inline-block"}}):r(VS,{rotate:t?"0":"-90",onClick:i,...a})),qS=({onClick:t})=>d("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:[r("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),r("rect",{className:"border",x:"4",y:"4",width:"16",height:"16",rx:"2"}),r("rect",{className:"checkmark-indeterminate",x:"8",y:"8",width:"8",height:"8",rx:"2",stroke:"none"}),r("path",{className:"checkmark-checked",d:"M9 12l2 2l4 -4"})]}),GS=({onClick:t,...e})=>r(qS,{onClick:t,...e}),FS=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"},required:{color:"#fa5252",paddingLeft:"3px"},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"}}}})),jS=({disabled:t,classNames:e,styles:n,unstyled:i,radius:a,style:o,label:l,value:u,onChange:c,treeData:p,errorMessage:h,required:f,treeCheckStrictly:g})=>{const{classes:b,cx:w}=FS({radius:a},{name:"FilterTreeSelectWidget",classNames:e,styles:n,unstyled:i}),[_,D]=m.useState(!1),L=J=>{D(J)},N=_&&(u==null?void 0:u.length)>0;return d(s.Stack,{spacing:3,children:[d(s.Group,{position:"apart",children:[d(s.Text,{className:b.label,children:[l,f&&r("span",{className:b.required,"aria-hidden":"true",children:"*"})]}),N&&r(s.Tooltip,{label:`${u.length} selected`,children:r(s.Badge,{children:u.length})})]}),r(sa,{disabled:t,allowClear:!0,treeCheckStrictly:g,className:w(b.root,"check-select"),dropdownClassName:w(b.dropdown,""),onDropdownVisibleChange:L,transitionName:"rc-tree-select-dropdown-slide-up",choiceTransitionName:"rc-tree-select-selection__choice-zoom",style:o,listHeight:510,treeLine:!0,clearIcon:()=>r(s.CloseButton,{}),switcherIcon:NS,treeIcon:GS,maxTagTextLength:10,value:u,treeData:p,notFoundContent:r(po,{errorMessage:h}),treeNodeFilterProp:"filterBasis",treeCheckable:!0,showCheckedStrategy:sa.SHOW_PARENT,onChange:c,onSelect:console.log,maxTagCount:0,maxTagPlaceholder:J=>`${J.length} selected`})]})},WS=k.observer(({label:t,config:e,value:n,onChange:i})=>{const{treeData:a,treeDataLoading:o,errorMessage:l}=e,u=e.min_width?e.min_width:"200px",p=!!e.options_query_id?o:!1;return r(jS,{disabled:p,style:{minWidth:"160px",width:u,maxWidth:p?u:"unset",borderColor:"#e9ecef"},value:n,onChange:h=>i(h,!1),treeData:a,errorMessage:l,label:t,required:e.required,treeCheckStrictly:e.treeCheckStrictly})}),RS=k.observer(({filter:{type:t,config:e,key:n,...i},formFieldProps:a})=>{switch(t){case"select":return r(OS,{...i,...a,config:e});case"multi-select":return r(LS,{...i,...a,config:e});case"tree-select":return r(WS,{...i,...a,config:e});case"text-input":return r($S,{...i,...a,config:e});case"date-range":return r(co,{...i,...a,config:e});case"checkbox":return r(zS,{...i,...a,config:e});default:return null}}),QS=k.observer(m.forwardRef(({filter:t,...e},n)=>r("div",{className:"filter-root",ref:n,children:r(ke,{children:r(RS,{filter:t,formFieldProps:e})})}))),US=({disabled:t})=>{const{searchButtonProps:e}=Ca(),{children:n="Search",type:i,...a}=e;return r(s.Button,{color:"blue",size:"sm",type:"submit",...a,disabled:t||a.disabled,children:n})};function KS(t){const e=H();m.useEffect(()=>{var n,i;(i=(n=e.filters).updatePreviewValues)==null||i.call(n,t)},[t])}const ho=k.observer(function({view:e}){const n=ue(),{control:i,handleSubmit:a,reset:o}=v.useForm({defaultValues:n.filters.values,reValidateMode:"onBlur"}),l=v.useWatch({control:i});m.useEffect(()=>{o(n.filters.values)},[n.filters.values,o]),KS(l);const u=n.filters.visibleInView(e.id),c=m.useMemo(()=>u.every(g=>g.should_auto_submit),[u]),p=m.useMemo(()=>u.filter(g=>x.get(g,"config.required",!1)),[u]),h=m.useMemo(()=>p.length===0?!1:p.some(g=>!g.requiredAndPass(l[g.key])),[l,p]);if(u.length===0)return null;const f=(g,b)=>(w,_)=>{b(w),(g.should_auto_submit||_)&&n.filters.setValueByKey(g.key,w)};return r("form",{onSubmit:a(n.filters.setValues),children:d(s.Group,{className:"dashboard-filters",position:"apart",noWrap:!0,sx:c?{}:{border:"1px solid #e9ecef",borderRadius:"4px",padding:"16px"},children:[r(s.Group,{align:"flex-start",children:u.map(g=>r(v.Controller,{name:g.key,control:i,render:({field:b})=>r(QS,{filter:g,value:b.value,onChange:f(g,b.onChange)})},g.id))}),!c&&r(s.Group,{sx:{alignSelf:"flex-end"},children:r(US,{disabled:h})})]})})}),YS={viewPanelInFullScreen:x.noop,inFullScreen:!1},Fn=m.createContext(YS),fo=y.types.model("MockContextMeta",{current:y.types.optional(y.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}}));function go(t){return{current:t}}const XS=y.types.model("PanelLayoutMeta",{x:y.types.number,y:y.types.maybeNull(y.types.number),w:y.types.number,h:y.types.number,moved:y.types.optional(y.types.boolean,!1),static:y.types.optional(y.types.boolean,!1)}).views(t=>({get json(){const{x:e,y:n,w:i,h:a,moved:o}=t;return{h:a,w:i,x:e,y:n===null?0:n,moved:o,static:t.static}}})).actions(t=>({set(e){const{x:n,y:i,w:a,h:o,moved:l}=e;t.x=n,t.y=i,t.w=a,t.h=o,t.moved=!!l,t.static=!!e.static},setWidth(e){t.w=e},setHeight(e){t.h=e}})),JS=y.types.model("PanelStyleBorderMeta",{enabled:y.types.boolean}).views(t=>({get json(){const{enabled:e}=t;return{enabled:e}}})).actions(t=>({setEnabled(e){t.enabled=e}})),ZS=y.types.model("PanelStyleMeta",{border:JS}).views(t=>({get json(){const{border:e}=t;return{border:e.json}}})).actions(t=>({})),HS=y.types.model("VariableMeta",{name:y.types.string,size:y.types.string,weight:y.types.string,color:y.types.union(y.types.model({type:y.types.literal("static"),staticColor:y.types.string}),y.types.model({type:y.types.literal("continuous"),valueRange:y.types.array(y.types.number),colorRange:y.types.array(y.types.string)}),y.types.model({type:y.types.literal("piecewise")})),formatter:y.types.model({output:y.types.enumeration("Output",["number","percent"]),average:y.types.optional(y.types.boolean,!1),mantissa:y.types.number,trimMantissa:y.types.optional(y.types.boolean,!1)}),data_field:y.types.string,aggregation:y.types.union(y.types.model({type:y.types.enumeration(["none","sum","mean","median","min","max","CV","std"]),config:y.types.frozen()}),y.types.model({type:y.types.literal("quantile"),config:y.types.model({p:y.types.number})}),y.types.model({type:y.types.literal("custom"),config:y.types.model({func:y.types.string})}))}).views(t=>({get json(){const{name:e,size:n,weight:i,color:a,formatter:o,data_field:l,aggregation:u}=t;return x.cloneDeep({name:e,size:n,color:a,weight:i,formatter:o,data_field:l,aggregation:u})}})),e_=y.types.model("PanelVizMeta",{type:y.types.string,conf:y.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}})),t_=y.types.model("PanelTitleMeta",{show:y.types.optional(y.types.boolean,!0)}).views(t=>({get json(){const{show:e}=t;return{show:e}}})).actions(t=>({setShow(e){t.show=e}})),n_=y.types.model({id:y.types.string,name:y.types.optional(y.types.string,""),title:t_,description:y.types.string,layout:XS,queryIDs:y.types.array(y.types.string),viz:e_,style:ZS,variables:y.types.optional(y.types.array(HS),[])}).views(t=>({get json(){const{id:e,name:n,title:i,description:a,queryIDs:o}=t;return{id:e,viz:t.viz.json,name:n,style:t.style.json,title:i,layout:t.layout.json,queryIDs:[...o],variables:t.variables.map(l=>l.json),description:a}},get queryIDSet(){return new Set(t.queryIDs)}})).actions(t=>({setID(e){t.id=e},setName(e){t.name=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=y.cast(Array.from(n))},setQueryIDs(e){t.queryIDs=y.cast(e)},addVariable(e){t.variables.push(e)},removeVariable(e){t.variables.remove(e)}})),jn=t=>x.cloneDeepWith(t,(e,n)=>{if(n!==void 0&&e)return Q.toJS(e)});var ze=(t=>(t.Postgresql="postgresql",t.MySQL="mysql",t.HTTP="http",t))(ze||{});const r_=y.types.model("QueryMeta",{id:y.types.string,name:y.types.string,type:y.types.enumeration("DataSourceType",[ze.Postgresql,ze.MySQL,ze.HTTP]),key:y.types.string,sql:y.types.string,pre_process:y.types.optional(y.types.string,""),post_process:y.types.optional(y.types.string,""),run_by:y.types.optional(y.types.array(y.types.string),[]),react_to:y.types.optional(y.types.array(y.types.string),[])}).views(t=>({get valid(){return t.id&&t.type&&t.key&&t.name?t.type===ze.HTTP?!!t.pre_process:!!t.sql:!1},get json(){const{id:e,name:n,type:i,key:a,sql:o,run_by:l,react_to:u,pre_process:c,post_process:p}=t;return jn({id:e,key:a,sql:o,name:n,type:i,run_by:l,react_to:u,pre_process:c,post_process:p})}})).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}})),i_=y.types.model("SQLSnippetMeta",{key:y.types.string,value:y.types.string}).views(t=>({get json(){const{key:e,value:n}=t;return{key:e,value:n}}})).actions(t=>({setKey(e){t.key=e},setValue(e){t.value=e}}));var de=(t=>(t.Select="select",t.MultiSelect="multi-select",t.TreeSelect="tree-select",t.TextInput="text-input",t.Checkbox="checkbox",t.DateRange="date-range",t))(de||{});const mo=y.types.model("FilterCheckboxConfigMeta",{_name:y.types.literal("checkbox"),description:y.types.optional(y.types.string,""),default_value:y.types.boolean}).views(t=>({get json(){const{_name:e,description:n,default_value:i}=t;return{_name:e,description:n,default_value:i}},get isDescriptionEmpty(){const{description:e}=t;return e===""||e==="<p></p>"}})).actions(t=>({setDefaultValue(e){t.default_value=e},setDescription(e){t.description=e}})),a_=()=>mo.create({_name:"checkbox",description:"",default_value:!1});function yo(t,e){return t.map(n=>{try{return n?G.tz(n,"UTC").format(e):null}catch{return console.log(`[date-range] failed parsing ${n}`),null}})}const s_=y.types.model("FilterDateRangeConfigMeta",{_name:y.types.literal("date-range"),required:y.types.boolean,inputFormat:y.types.enumeration("DateRangeInputFormat",["YYYY","YYYYMM","YYYYMMDD","YYYY-MM","YYYY-MM-DD"]),default_value:y.types.optional(y.types.array(y.types.union(y.types.string,y.types.null)),[null,null]),clearable:y.types.boolean,max_days:y.types.optional(y.types.number,0),allowSingleDateInRange:y.types.optional(y.types.boolean,!1)}).views(t=>({get json(){const{_name:e,max_days:n,required:i,clearable:a,inputFormat:o,default_value:l,allowSingleDateInRange:u}=t;return{_name:e,max_days:n,required:i,clearable:a,inputFormat:o,default_value:yo(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 G(e).startOf("day").add(n,"days").toDate()},getMinDate(e){const{max_days:n}=t;if(!(!n||!e))return G(e).startOf("day").subtract(n,"days").toDate()}})).actions(t=>({setFilterValue(e){try{const n=y.getParent(t);y.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}})),bo=y.types.snapshotProcessor(s_,{preProcessor({default_value:t,...e}){return{...e,default_value:t.map(n=>n===null?null:G.tz(n,"UTC").toISOString())}},postProcessor(t){const{default_value:e,...n}=t;return{...n,default_value:yo(e,n.inputFormat)}}}),o_=()=>bo.create({_name:"date-range",required:!1,inputFormat:"YYYY-MM-DD",clearable:!1,default_value:[null,null]}),l_=y.types.model({label:y.types.string,value:y.types.string}).actions(t=>({setLabel(e){t.label=e},setValue(e){t.value=e}})),yi=y.types.model("FilterConfigModel_BaseSelect",{static_options:y.types.optional(y.types.array(l_),[]),options_query_id:y.types.optional(y.types.string,""),default_selection_count:y.types.optional(y.types.number,0),required:y.types.optional(y.types.boolean,!1)}).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:i}=y.getRoot(t).content.getDataStuffByID(t.options_query_id);return n==="idle"?Array.isArray(e)?e:[]:[]}})).actions(t=>({setRequired(e){t.required=e},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??""}})),vo=y.types.compose("FilterMultiSelectConfigMeta",y.types.model({_name:y.types.literal("multi-select"),min_width:y.types.optional(y.types.string,""),default_value:y.types.optional(y.types.array(y.types.string),[])}),yi).views(t=>({get json(){const{_name:e,default_value:n,required:i,min_width:a,static_options:o,options_query_id:l,default_selection_count:u}=t;return jn({_name:e,required:!!i,min_width:a,default_value:n,static_options:o,options_query_id:l,default_selection_count:u})},get default_selection(){return t.usingQuery?t.options.slice(0,t.default_selection_count).map(e=>e.value):t.default_value},truthy(e){return Array.isArray(e)&&e.length>0}})).actions(t=>({setDefaultValue(e){t.default_value=y.cast(e)},setMinWidth(e){t.min_width=e},setDefaultSelection(){const e=y.getRoot(t).content.filters,n=y.getParent(t).key;e.setValueByKey(n,t.default_selection)}})).actions(t=>({afterCreate(){y.addDisposer(t,Q.reaction(()=>Q.toJS(t.default_selection),t.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),u_=()=>vo.create({_name:"multi-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),xo=y.types.compose("FilterConfigModel_Select",y.types.model({_name:y.types.literal("select"),default_value:y.types.string,width:y.types.optional(y.types.string,"")}),yi).views(t=>({get json(){const{_name:e,default_value:n,required:i,width:a,static_options:o,options_query_id:l,default_selection_count:u}=t;return jn({_name:e,width:a,required:i,default_value:n,static_options:o,options_query_id:l,default_selection_count:u})},truthy(e){return!!e},getSelectOption(e){return t.options.find(n=>n.value===e)},get default_selection(){return t.usingQuery?t.default_selection_count>0&&t.options.length>0?t.options[0].value:"":t.default_value}})).actions(t=>({setDefaultValue(e){t.default_value=e},setWidth(e){t.width=e},setDefaultSelection(){const e=y.getRoot(t).content.filters,n=y.getParent(t).key;e.setValueByKey(n,t.default_selection)}})).actions(t=>({afterCreate(){y.addDisposer(t,Q.reaction(()=>Q.toJS(t.default_selection),t.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),c_=()=>xo.create({_name:"select",required:!1,default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),wo=y.types.model("FilterTextInputConfigMeta",{_name:y.types.literal("text-input"),required:y.types.boolean,default_value:y.types.string}).views(t=>({get json(){const{_name:e,required:n,default_value:i}=t;return{_name:e,required:n,default_value:i}},truthy(e){return typeof e!="string"?!1:!!e.trim()}})).actions(t=>({setRequired(e){t.required=e},setDefaultValue(e){t.default_value=e}})),Co=()=>wo.create({_name:"text-input",required:!1,default_value:""});function d_(t){return ou.arrayToTree(t,{id:"value",parentId:"parent_value",childrenField:"children",dataField:null})}function p_(t){return t.map(e=>{const{label:n,description:i,...a}=e,o={...a,filterBasis:`${n}___${i??""}`,description:i,label:n};return i&&(o.label=m.createElement("div",{},[m.createElement(s.Text,{key:0,title:e.label},e.label),m.createElement(s.Text,{key:1,className:"rc-tree-select-tree-title-desc",color:"dimmed",title:e.description},e.description)])),o})}const So=y.types.compose("FilterTreeSelectConfigMeta",y.types.model({_name:y.types.literal("tree-select"),min_width:y.types.optional(y.types.string,""),default_value:y.types.optional(y.types.array(y.types.string),[]),treeCheckStrictly:y.types.optional(y.types.boolean,!1)}),yi).views(t=>({get json(){const{_name:e,default_value:n,required:i,min_width:a,static_options:o,options_query_id:l,default_selection_count:u,treeCheckStrictly:c}=t;return{_name:e,required:!!i,min_width:a,default_value:n,static_options:o,options_query_id:l,treeCheckStrictly:c,default_selection_count:u}},get treeData(){const{data:e}=y.getRoot(t).content.getDataStuffByID(t.options_query_id),n=p_(e);return d_(n)},get errorMessage(){const{error:e}=y.getRoot(t).content.getDataStuffByID(t.options_query_id);return e},get treeDataLoading(){const{state:e}=y.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(i=>i.value):[]},truthy(e){return Array.isArray(e)&&e.length>0}})).actions(t=>({setDefaultValue(e){t.default_value=y.cast(e)},setMinWidth(e){t.min_width=e},setTreeCheckStrictly(e){t.treeCheckStrictly=e},applyDefaultSelection(){const e=y.getParent(t,1).key;y.getRoot(t).content.filters.setValueByKey(e,t.defaultSelection)},afterCreate(){y.addDisposer(t,Q.reaction(()=>JSON.stringify(t.defaultSelection),this.applyDefaultSelection,{fireImmediately:!0,delay:0}))}})),h_=()=>So.create({_name:"tree-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),_o=y.types.model("FilterMeta",{id:y.types.identifier,key:y.types.string,label:y.types.string,order:y.types.number,visibleInViewsIDs:y.types.array(y.types.string),auto_submit:y.types.optional(y.types.boolean,!1),type:y.types.enumeration("DashboardFilterType",[de.Select,de.MultiSelect,de.TreeSelect,de.TextInput,de.Checkbox,de.DateRange]),config:y.types.union(xo,vo,So,wo,mo,bo)}).views(t=>({get plainDefaultValue(){const e=t.config.default_value;return Array.isArray(e)?[...e]:e},get usingDefaultValue(){return t.type!==de.TreeSelect},get auto_submit_supported(){return[de.Select,de.Checkbox,de.DateRange].includes(t.type)}})).views(t=>({get json(){const{id:e,key:n,label:i,order:a,visibleInViewsIDs:o,auto_submit:l,type:u,config:c}=t;return{id:e,key:n,type:u,label:i,order:a,config:c.json,auto_submit:l,visibleInViewsIDs:Q.toJS(o)}},get visibleInViewsIDSet(){return new Set(t.visibleInViewsIDs)},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 de.Select:t.config=c_();break;case de.MultiSelect:t.config=u_();break;case de.TreeSelect:t.config=h_();break;case de.TextInput:t.config=Co();break;case de.Checkbox:t.config=a_();break;case de.DateRange:t.config=o_();break}t.type=e},setVisibleInViewsIDs(e){t.visibleInViewsIDs.length=0,t.visibleInViewsIDs.push(...e)},setAutoSubmit(e){t.auto_submit=t.auto_submit_supported&&e}}));var $=(t=>(t.Division="div",t.Modal="modal",t.Tabs="tabs",t))($||{});const ko=y.types.model("ViewDivisionConfig",{_name:y.types.literal($.Division)}).views(t=>({get json(){const{_name:e}=t;return{_name:e}}})),f_=()=>ko.create({_name:$.Division}),g_=y.types.model("CustomModalTitleModel",{enabled:y.types.optional(y.types.boolean,!1),func_content:y.types.optional(y.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,i=y.getParent(t,2),a=y.getRoot(t);if(!e)return i.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),i.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}})),bi={enabled:!1,func_content:["function text({ filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
|
|
440
|
+
`)},To=y.types.model("ViewModalConfig",{_name:y.types.literal($.Modal),width:y.types.string,height:y.types.string,custom_modal_title:y.types.optional(g_,bi)}).views(t=>({get json(){const{_name:e,width:n,height:i,custom_modal_title:a}=t;return{_name:e,width:n,height:i,custom_modal_title:a.json}}})).actions(t=>({setWidth(e){t.width=e},setHeight(e){t.height=e}})),m_=()=>To.create({_name:$.Modal,width:"90vw",height:"90vh"}),y_=y.types.model("ViewTabsTabModel",{id:y.types.identifier,name:y.types.string,view_id:y.types.string,color:y.types.optional(y.types.string,"")}).views(t=>({get json(){const{id:e,name:n,view_id:i,color:a}=t;return{id:e,name:n,color:a,view_id:i}}})).actions(t=>({setName(e){t.name=e},setViewID(e){t.view_id=e},setColor(e){t.color=e}})),Do=y.types.model("ViewTabsConfig",{_name:y.types.literal($.Modal),tabs:y.types.optional(y.types.array(y_),[]),variant:y.types.optional(y.types.enumeration("variant",["default","outline","pills"]),"default"),orientation:y.types.optional(y.types.enumeration("orientation",["horizontal","vertical"]),"horizontal"),grow:y.types.optional(y.types.boolean,!1)}).views(t=>({get json(){const{_name:e,variant:n,orientation:i,tabs:a,grow:o}=t;return{grow:o,tabs:a.map(l=>l.json),_name:e,variant:n,orientation:i}}})).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=y.cast(e)},addTab(){const e=ye.randomId(),n={id:e,name:e,view_id:""};t.tabs.push(n)},removeTab(e){t.tabs.splice(e,1)}})),b_=()=>Do.create({_name:$.Modal,tabs:[]}),v_=y.types.model({id:y.types.identifier,name:y.types.string,type:y.types.enumeration("EViewComponentType",[$.Division,$.Modal,$.Tabs]),config:y.types.union(ko,To,Do),panelIDs:y.types.optional(y.types.array(y.types.string),[])}).views(t=>({get json(){const{id:e,name:n,type:i,config:a}=t;return{id:e,name:n,type:i,config:a.json,panelIDs:t.panelIDs}}})).actions(t=>({setName(e){t.name=e},setType(e){if(t.type!==e){switch(e){case $.Division:t.config=f_();break;case $.Modal:t.config=m_();break;case $.Tabs:t.config=b_();break}t.type=e}},appendPanelID(e){t.panelIDs.push(e)},removePanelID(e){const n=t.panelIDs.filter(i=>i!==e);t.panelIDs.length=0,t.panelIDs.push(...n)}})),Io=y.types.model("DataSourceMetaModel",{id:y.types.string,type:y.types.enumeration("DataSourceType",[ze.HTTP,ze.MySQL,ze.Postgresql]),key:y.types.string,config:y.types.frozen()}),x_=y.types.model("DataSourcesMetaModel",{list:y.types.optional(y.types.array(Io),[])}).views(t=>({find({type:e,key:n}){return t.list.find(i=>i.key===n&&i.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)}})),w_=y.types.model({id:y.types.string,content:y.types.string,create_time:y.types.string,update_time:y.types.string,is_preset:y.types.boolean}),Mo=y.types.model("GlobalSQLSnippetsMeta",{list:y.types.optional(y.types.array(w_),[])}).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)}})),vi=y.types.model("ContextMeta",{current:y.types.optional(y.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}}));function Ao(t){return vi.create({current:t})}const C_=y.types.compose("ViewRenderModel",v_,y.types.model({tab:y.types.optional(y.types.string,"")})).views(t=>({get defaultTab(){if(t.type!==$.Tabs)return"";const e=t.config;return e.tabs.length>0?e.tabs[0].id:""},get tabViewID(){var n;return t.type!==$.Tabs?"":((n=t.config.tabs.find(i=>i.id===t.tab))==null?void 0:n.view_id)??""},get contentModel(){return y.getParent(t,3)},get panels(){if(t.type!==$.Tabs)return this.contentModel.panels.panelsByIDs(t.panelIDs).panels;const e=this.tabViewID;return this.contentModel.views.findByID(e).panels},get renderViewIDs(){const e=[t.id];return t.type===$.Tabs&&e.push(this.tabViewID),e}})).actions(t=>({setTab(e){t.tab=e??""},afterCreate(){y.addDisposer(t,Q.reaction(()=>t.defaultTab,e=>this.setTab(e),{fireImmediately:!0,delay:0}))}})),zo=y.types.model("ViewsRenderModel",{current:y.types.optional(y.types.array(C_),[]),visibleViewIDs:y.types.array(y.types.string)}).views(t=>({get json(){return t.current.map(e=>jn(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 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))}})).actions(t=>({appendToVisibles(e){new Set(t.visibleViewIDs.map(i=>i)).has(e)||t.visibleViewIDs.push(e)},rmVisibleViewID(e){const n=t.visibleViewIDs.findIndex(i=>i===e);n!==-1&&t.visibleViewIDs.splice(n,1)}}));function S_(t){const e=t.length>0?[t[0].id]:[];return{current:t.map(i=>{const{_name:a=i.type}=i.config;return{...i,config:{...i.config,_name:a},panelIDs:i.panelIDs}}),visibleViewIDs:e}}const Eo=n_.views(t=>({get contentModel(){return y.getRoot(t).content}})).views(t=>({get queries(){return t.contentModel.queries.findByIDSet(t.queryIDSet)},get data(){return this.queries.reduce((e,n)=>(e[n.id]=n.data,e),{})},get dataLoading(){return this.queries.some(e=>e.state==="loading")},get queryStateMessages(){const e=this.queries.filter(o=>!o.runByConditionsMet);if(e.length===0)return"";const n=new Set,i=new Set;e.forEach(o=>{const l=o.conditionNames;l.context.forEach(u=>n.add(u)),l.filters.forEach(u=>i.add(u))});const a=[];return n.size>0&&(console.log(n),a.push(`context: ${Array.from(n).join(", ")}`)),i.size>0&&a.push(`filter${i.size>1?"s":""}: ${Array.from(i).join(", ")}`),a.length===2&&a.splice(1,0,"and"),a.unshift("Waiting for"),a.join(" ")},get queryErrors(){return this.queries.map(e=>e.error).filter(e=>!!e)},get canRenderViz(){return this.queryErrors.length===0&&this.queryStateMessages===""&&!this.dataLoading}})).actions(t=>({refreshData(){t.queries.forEach(e=>e.fetchData(!0))},downloadData(){y.getRoot(t).content.queries.downloadDataByQueryIDs(t.queryIDs)}}));function __(t){return{id:t,name:t,layout:{x:0,y:1/0,w:18,h:300},title:{show:!0},description:"<p></p>",queryIDs:[],viz:{type:ai.name,conf:ai.createConfig()},style:{border:{enabled:!0}}}}const Po=y.types.model("PanelsRenderModel",{list:y.types.optional(y.types.array(Eo),[])}).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 i=n.map(a=>({...a.layout.json,i:a.id}));return{panels:n,layouts:i}}}));function Lo(t,e){if(t===void 0)return t;if(e._name==="date-range")try{const[...n]=t;return n.map(i=>i===null?i:G.tz(i,"UTC").format(e.inputFormat)??i)}catch(n){return console.error(n),t}return t}function k_(t){return t.reduce((e,n)=>(e[n.key]=Lo(n.config.default_value,n.config),e),{})}const Bo=y.types.model("FiltersRenderModel",{current:y.types.optional(y.types.array(_o),[]),values:y.types.optional(y.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 empty(){return t.current.length===0},visibleInView(e){return x.sortBy(t.current.filter(n=>n.visibleInViewsIDSet.has(e)),"order")},get firstFilterValueKey(){return Object.keys(t.values)[0]??""},get keyLabelMap(){return t.current.reduce((e,n)=>(e[n.key]=n.label,e),{})},getSelectOption(e){const n=this.findByID(e);if(!n||!("getSelectOption"in n.config))return null;const i=t.values[n.key];return n.config.getSelectOption(i)}})).actions(t=>({setValues(e){t.values=e},setValueByKey(e,n){t.values={...t.values,[e]:n}},getValueByKey(e){return t.values[e]}}));function Oo(t){return{current:t,values:k_(t)}}const T_=new lu.AsyncParser({withBOM:!0});async function $o(t){return!Array.isArray(t)||t.length===0?"":await T_.parse(t).promise()}async function D_(t,e){const n=await $o(e),i=new Blob([n],{type:"text/csv"});nr.saveAs(i,`${t}.csv`)}function Vo(t){const e=new uu;t.forEach(({id:n,data:i})=>{e.file(`${n}.csv`,$o(i))}),e.generateAsync({type:"blob"}).then(n=>{nr.saveAs(n,"dashboard_data.zip")})}function No(t,e){const n=new Blob([e],{type:"application/json"});nr.saveAs(n,`${t}.json`)}function I_(t,e){return new Function(`return ${t}`)()(e,mt)}function M_(t,e,n){return I_(t,{context:e,filters:n})}function A_(t,e){try{return new Function(`return ${t.config.processing.pre}`)()(e,mt)}catch(n){return console.error(n),e}}function z_(t,e){return new Function(`return ${t.config.processing.post}`)()(e,mt)}function E_(t,e,n){return t?new Function(`return ${t}`)()(e,mt,n):e}const P_=r_.views(t=>({get conditionOptions(){if(!y.isAlive(t))return[];const e=y.getRoot(t).content,{context:n}=e.payloadForSQL,i=Object.keys(n).map(o=>({group:"Context",label:o,value:`context.${o}`,description:void 0})),a=e.filters.keyLabelOptions.map(o=>({group:"Filters",label:o.label,value:`filters.${o.value}`,description:o.value}));return[...i,...a]},get unmetRunByConditions(){if(!y.isAlive(t))return[];const{run_by:e}=t;if(e.length===0)return[];const n=y.getRoot(t).content.payloadForSQL;return e.filter(i=>{const a=x.get(n,i);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=y.getRoot(t).content.payloadForSQL,i=[...e].reduce((a,o)=>(a[o]=x.get(n,o),a),{});return JSON.stringify(i)},get runByConditionsMet(){return t.unmetRunByConditions.length===0},get conditionNames(){if(t.unmetRunByConditions.length===0)return{context:[],filters:[]};const{keyLabelMap:e}=y.getRoot(t).content.filters,n=t.unmetRunByConditions.filter(a=>a.startsWith("context.")).map(a=>a.split("context.")[0]),i=t.unmetRunByConditions.filter(a=>a.startsWith("filters.")).map(a=>x.get({filters:e},a)).filter(a=>!!a);return{context:n,filters:i}},get queries(){return y.getParent(t,2)},get inUse(){return this.queries.isQueryInUse(t.id)}})),L_=y.types.compose("QueryRenderModel",P_,y.types.model({state:y.types.optional(y.types.enumeration(["idle","loading","error"]),"idle"),data:y.types.optional(y.types.frozen([]),[]),error:y.types.frozen()})).views(t=>({get rootModel(){return y.getRoot(t)},get contentModel(){return this.rootModel.content},get payload(){return this.contentModel.payloadForSQL},get formattedSQL(){return ir(t.sql,this.payload)},get typedAsSQL(){return[ze.Postgresql,ze.MySQL].includes(t.type)},get typedAsHTTP(){return[ze.HTTP].includes(t.type)},get datasource(){const{key:e,type:n}=t;return this.rootModel.datasources.find({type:n,key:e})},get httpConfigString(){const{context:e,filters:n}=this.payload,{name:i,pre_process:a}=t.json,o=M_(a,e,n);return console.groupCollapsed(`Request config for: ${i}`),console.log(o),console.groupEnd(),JSON.stringify(o)},get additionalQueryInfo(){return this.contentModel.getAdditionalQueryInfo(t.id)}})).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 i=[];return e.length>0&&i.push(`context: ${e.join(", ")}`),n.length>0&&i.push(`filter${n.length>1?"s":""}: ${n.join(", ")}`),i.length===2&&i.splice(1,0,"and"),i.unshift("Waiting for"),i.join(" ")}return t.data.length>0?"":"Empty Data"}})).volatile(()=>({controller:new AbortController})).actions(t=>({runSQL:y.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=t.payload;t.data=yield*y.toGenerator(rc({payload:n,name:t.name,query:t.json,additionals:t.additionalQueryInfo},t.controller.signal)),t.state="idle",t.error=null}catch(n){if(!nt.isCancel(n)){t.data=[];const i=x.get(n,"message","unkown error");t.error=x.get(n,"response.data.detail.message",i),t.state="error"}}}}),runHTTP:y.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:i,post_process:a}=t.json;let o=JSON.parse(t.httpConfigString);o=A_(t.datasource,o);const l=yield*y.toGenerator(ic({type:n,key:i,configString:JSON.stringify(o),name:t.name,additionals:t.additionalQueryInfo},t.controller.signal)),u=z_(t.datasource,l),c=E_(a,u,t.contentModel.dashboardState);t.data=c,t.state="idle",t.error=null}catch(n){if(console.error(n),!nt.isCancel(n)){t.data=[];const i=x.get(n,"message","unkown error");t.error=x.get(n,"response.data.detail.message",i),t.state="error"}}}})})).actions(t=>({fetchData:e=>{if(!t.inUse&&!e){console.debug(`Skipping query[${t.name}]`);return}return t.typedAsHTTP?t.runHTTP():t.runSQL()},beforeDestroy(){var e;(e=t.controller)==null||e.abort()}})).actions(t=>({afterCreate(){y.addDisposer(t,Q.reaction(()=>{var n;return t.typedAsHTTP?`${t.inUse}--${t.id}--${t.key}--${t.reQueryKey}--${(n=t.datasource)==null?void 0:n.id}`:[t.inUse,t.id,t.key,t.formattedSQL,t.pre_process,t.post_process].join("--")},()=>t.fetchData(!1),{fireImmediately:!0,delay:0}))}})),qo=y.types.model("QueriesRenderModel",{current:y.types.optional(y.types.array(L_),[])}).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 json(){return t.current.filter(e=>e.id&&e.key).map(e=>e.json)},get contentModel(){return y.getParent(t,1)},get visibleQueryIDSet(){const{views:e,filters:n}=this.contentModel,i=[];e.visibleViews.forEach(l=>{l.panels.forEach(u=>{i.push(...u.queryIDs)})});const a=x.uniq(e.visibleViews.map(l=>l.renderViewIDs).flat());n.current.forEach(l=>{const u=x.get(l,"config.options_query_id");if(!u)return;a.some(p=>l.visibleInViewsIDSet.has(p))&&i.push(u)});const o=new Set(i);return console.debug("QueryIDs:",o),o},isQueryInUse(e){return this.visibleQueryIDSet.has(e)}})).actions(t=>({downloadAllData(){const e=t.current.map(({name:n,data:i})=>({id:n,data:i}));Vo(e)},downloadDataByQueryIDs(e){const n=new Set(e),i=t.current.filter(a=>n.has(a.id)).map(({name:a,data:o})=>({id:a,data:o}));Vo(i)},downloadDataByQueryID(e){const n=t.findByID(e);if(!n){console.log("[downloadDataByQueryID] query not found");return}const{name:i,data:a}=n;D_(i,a)},refetchDataByQueryID(e){const n=t.findByID(e);if(!n){console.error(new Error(`[downloadDataByQueryID] query by ID[${e}] not found`));return}return n.fetchData(!0)}}));function B_(t){return{current:t}}const O_=i_.views(t=>({isADuplicatedKey(e){return!e||e===t.key?!1:!!y.getParent(t,2).findByKey(e)}})),Go=y.types.model("SQLSnippetsRenderModel",{current:y.types.optional(y.types.array(O_),[])}).views(t=>({get json(){return t.current.map(e=>e.json)},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)}}));function $_(t){return{current:t}}function Wn(t,e,n,i){return t.reduce((a,o)=>{try{a[o[e]]=rr(o[n],i)}catch(l){a[o[e]]=l.message}return a},{})}class V_{constructor(e){P(this,"origin");P(this,"copy");this.origin=e,this.copy=y.clone(e),Q.makeAutoObservable(this,{},{autoBind:!0,deep:!1})}get changed(){return!x.isEqual(y.getSnapshot(this.origin),y.getSnapshot(this.copy))}commit(){y.applySnapshot(this.origin,y.getSnapshot(this.copy))}update(e){y.applySnapshot(this.copy,e)}}const N_=t=>new V_(t),q_=k.observer(({view:t})=>{const e=ee(),n=H(),i=Ee.useModals(),{panel:a,downloadPanelScreenshot:o}=$e(),{id:l}=a,{viewPanelInFullScreen:u,inFullScreen:c}=m.useContext(Fn),p=()=>{n.duplicatePanelByID(l,t.id)},h=()=>{e.editor.open(["_VIEWS_",t.id,"_PANELS_",l])},f=()=>i.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>n.removePanelByID(l,t.id),confirmProps:{color:"red"},zIndex:320}),g=m.useCallback(()=>{u(l)},[l,u]),b=!c&&t.type!==$.Modal;return r(z,{children:r(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:d(s.Menu,{withinPortal:!0,children:[r(s.Menu.Target,{children:r(s.Box,{className:"panel-dropdown-target",sx:{width:"100%"}})}),d(s.Menu.Dropdown,{children:[r(s.Menu.Item,{onClick:a.refreshData,icon:r(T.Refresh,{size:14}),children:"Refresh"}),r(s.Menu.Item,{onClick:a.downloadData,icon:r(T.Download,{size:14}),children:"Download Data"}),r(s.Menu.Item,{onClick:o,icon:r(M.IconCamera,{size:14}),children:"Screenshot"}),b&&r(s.Menu.Item,{onClick:g,icon:r(T.ArrowsMaximize,{size:14}),disabled:!0,children:"Full Screen"}),r(s.Divider,{label:"Edit",labelPosition:"center"}),r(s.Menu.Item,{onClick:h,icon:r(T.Settings,{size:14}),children:"Settings"}),r(s.Menu.Item,{onClick:p,icon:r(T.Copy,{size:14}),children:"Duplicate"}),r(s.Menu.Item,{color:"red",onClick:f,icon:r(T.Trash,{size:14}),children:"Delete"})]})]})})})});function G_(t){return t?["<p><br></p>","<p></p>"].includes(t):!0}const xi=k.observer(()=>{const[t,e]=m.useState(!1),{panel:n}=dt();return G_(n.description)?null:d(z,{children:[r(s.Modal,{opened:t,onClose:()=>e(!1),title:n.name,withCloseButton:!1,withinPortal:!0,zIndex:310,children:r(Dn,{value:n.description,styles:{root:{border:"none"},content:{padding:0}}})}),r(s.Tooltip,{label:"Click to see description",position:"top-start",withinPortal:!0,children:r(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>e(i=>!i),sx:{verticalAlign:"baseline",cursor:"pointer"},children:r(T.InfoCircle,{size:20})})})]})}),CI="",F_=k.observer(function(){const{panel:e}=dt(),{name:n,title:i}=e;return i.show?r(s.Group,{grow:!0,position:"center",className:"panel-title-wrapper",sx:{flexGrow:1},children:r(s.Text,{align:"center",lineClamp:1,className:"panel-title-text",children:n})}):null});function j_(t){const e=m.useRef(null);return{ref:e,downloadPanelScreenshot:()=>{const i=e.current;if(!i)return;const a=i.offsetWidth*2,o=i.offsetHeight*2;oa.toBlob(e.current,{bgcolor:"white",width:a,height:o,style:{border:"none",borderRadius:0,transformOrigin:"0 0",transform:"scale(2)"}}).then(l=>{window.saveAs(l,`${t.title?t.title:t.viz.type}.png`)})}}}var Fo=(t=>(t.migrated="migrated",t.nothingToMigrate="nothingToMigrate",t.checkFailed="checkFailed",t.migrationFailed="migrationFailed",t))(Fo||{}),Rn=(t=>(t.notStarted="notStarted",t.inProgress="inProgress",t.done="done",t))(Rn||{});class W_{constructor(e){P(this,"vizInstance");P(this,"operationManager");P(this,"triggerManager");P(this,"vizManager");P(this,"runningMigration");P(this,"panelModel");P(this,"status","notStarted");this.panelModel=e.getRequired(ce.instanceScope.panelModel),this.vizInstance=e.getRequired(ce.instanceScope.vizInstance),this.operationManager=e.getRequired(ce.instanceScope.operationManager),this.triggerManager=e.getRequired(ce.instanceScope.triggerManager),this.vizManager=e.getRequired(ce.vizManager)}async createMigrationTask(){const e=[];try{await this.instanceNeedMigration()&&e.push(()=>this.runInstanceMigration()),await this.interactionNeedMigration()&&e.push(()=>this.runInteractionMigration())}catch(n){return console.warn("check migration failed",n),"checkFailed"}if(e.length===0)return"nothingToMigrate";try{return await Promise.all(e.map(n=>n())),"migrated"}catch(n){return console.warn("migration failed",n),"migrationFailed"}}async runMigration(){return this.runningMigration||(this.status="inProgress",this.runningMigration=this.createMigrationTask().then(e=>(this.status="done",e))),this.runningMigration}async runInteractionMigration(){await this.operationManager.runMigration(),await this.triggerManager.runMigration()}async runInstanceMigration(){const e=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData,panelModel:this.panelModel};await e.migrator.migrate(n)}async instanceNeedMigration(){const e=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData};return e.migrator.needMigration(n)}async interactionNeedMigration(){return await this.operationManager.needMigration()||await this.triggerManager.needMigration()}}function jo(t){const{panel:e}=dt();return m.useCallback(n=>{const i=n.getRequired(ce.vizManager),a=i.resolveComponent(t.viz.type);return n.createScoped().provideFactory(ce.instanceScope.vizInstance,()=>i.getOrCreateInstance(t)).provideFactory(ce.instanceScope.interactionManager,o=>{const l=o.getRequired(ce.instanceScope.vizInstance);return new vr(l,a,fn)}).provideFactory(ce.instanceScope.operationManager,o=>o.getRequired(ce.instanceScope.interactionManager).operationManager).provideFactory(ce.instanceScope.triggerManager,o=>o.getRequired(ce.instanceScope.interactionManager).triggerManager).provideValue(ce.instanceScope.panelModel,e).provideFactory(ce.instanceScope.migrator,o=>new W_(o))},[t.viz.type,t.viz.conf])}function Wo(t){const[e,n]=m.useState(!1),i=uo().getRequired(ce.instanceScope.migrator);return q.useAsyncEffect(async()=>{const a=i.status===Rn.notStarted;n(i.status===Rn.done),i.status===Rn.notStarted&&i.runMigration().then(o=>{o===Fo.migrated&&a&&(t==null||t())}).finally(()=>{n(!0)})},[i]),e}function Ro(t,e){const n=uo().getRequired(ce.instanceScope.vizInstance);return m.useEffect(()=>(n.instanceData.setItem(null,e.viz.conf),n.instanceData.watchItem(null,i=>{t(i)})),[t,e.viz.type]),n}function R_({setVizConf:t,...e}){const{panel:n}=e,i=Ro(t,n),a=Wo(()=>{on.showNotification({title:`${n.name} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})});return q.useAsyncEffect(async()=>{await i.instanceData.setItem(null,n.viz.conf)},[i,n.viz.type]),a?r(lc,{...e}):r(s.Text,{children:"Checking update..."})}function Q_(t){const{panel:e,setVizConf:n}=t;Ro(n,e);const{inEditMode:i}=m.useContext(pn);return Wo(()=>{i&&on.showNotification({title:`${e.name} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?r(oc,{...t}):r(s.Text,{children:"Checking update"})}const SI="";function U_(t,e){const{vizManager:n}=m.useContext(tt),{panel:{viz:i,title:a,id:o,name:l,description:u,queryIDs:c,variables:p}}=dt(),h={id:o,name:l,title:a,description:u,queryIDs:c,viz:i,layout:e},f=jo(h);try{return n.resolveComponent(i.type),r(Gn,{configure:f,children:r(Q_,{setVizConf:i.setConf,panel:h,data:t,variables:p,vizManager:n})})}catch(g){return console.info(x.get(g,"message")),null}}const Qo=k.observer(function({data:e}){const{ref:n,width:i,height:a}=ye.useElementSize(),o=U_(e,{w:i,h:a}),l=i>0&&a>0;return r("div",{className:"viz-root",ref:n,children:r(s.Box,{sx:{width:i,height:a,overflow:"hidden"},children:l&&r(ke,{children:o})})})}),Uo=k.observer(({panel:t})=>d(s.Stack,{children:[t.queryErrors.map((e,n)=>r(s.Text,{color:"red",size:"sm",align:"center",sx:{fontFamily:"monospace"},children:e},`${n}-${e}`)),r(s.Text,{color:"gray",align:"center",size:"sm",children:t.queryStateMessages})]})),wi=k.observer(({panel:t})=>d(s.Flex,{className:"panel-viz-section",direction:"column",sx:{position:"relative",width:"100%"},children:[r(s.LoadingOverlay,{visible:t.dataLoading,exitTransitionDuration:0}),!t.canRenderViz&&r(Uo,{panel:t}),t.canRenderViz&&r(Qo,{data:t.data})]})),K_={border:"1px solid #e9ecef"},Ko=k.observer(({panel:t,panelStyle:e,dropdownContent:n})=>{const{ref:i,downloadPanelScreenshot:a}=j_(t);return t.title.show,r(gr,{value:{panel:t,data:t.data,loading:t.dataLoading,errors:t.queryErrors,downloadPanelScreenshot:a},children:d(s.Box,{className:`panel-root ${t.title.show?"panel-root--show-title":""}`,ref:i,p:0,sx:{...K_,...e},children:[r(s.Box,{className:"panel-description-popover-wrapper",children:r(xi,{})}),n,r(F_,{}),r(wi,{panel:t})]})})}),Y_={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function X_(t){return t.style.border.enabled?{}:Y_}const Yo=k.observer(function({panel:e,view:n}){const i=X_(e);return r(Ko,{panel:e,panelStyle:i,dropdownContent:r(q_,{view:n})})});function J_(t){return!["richText","button"].includes(t)}const Z_=k.observer(({view:t})=>{const{panel:e,downloadPanelScreenshot:n}=dt(),{id:i}=e,{viewPanelInFullScreen:a,inFullScreen:o}=m.useContext(Fn),l=m.useCallback(()=>{a(i)},[i,a]),u=!o&&t.type!==$.Modal;return J_(e.viz.type)?r(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:d(s.Menu,{withinPortal:!0,children:[r(s.Menu.Target,{children:r(s.Box,{className:"panel-dropdown-target"})}),d(s.Menu.Dropdown,{children:[r(s.Menu.Item,{onClick:e.refreshData,icon:r(T.Refresh,{size:14}),children:"Refresh"}),r(s.Menu.Item,{onClick:e.downloadData,icon:r(T.Download,{size:14}),children:"Download Data"}),r(s.Menu.Item,{onClick:n,icon:r(M.IconCamera,{size:14}),children:"Screenshot"}),u&&r(s.Menu.Item,{onClick:l,icon:r(T.ArrowsMaximize,{size:14}),children:"Full Screen"})]})]})}):null});function H_(t){return t.style.border.enabled?{}:{border:"1px dashed transparent"}}const Ci=k.observer(({panel:t,view:e})=>{const n=H_(t);return r(Ko,{panel:t,panelStyle:n,dropdownContent:r(Z_,{view:e})})}),e1={modal:{display:"flex",flexDirection:"column",flexWrap:"nowrap"},body:{display:"flex",height:"calc(100vh - 88px)"}},Xo=k.observer(function({view:e,panel:n,exitFullScreen:i}){return r(s.Modal,{opened:!0,fullScreen:!0,onClose:i,title:r(s.Button,{color:"blue",size:"xs",onClick:i,leftIcon:r(T.ArrowLeft,{size:20}),children:"Exit fullscreen"}),styles:e1,children:r(s.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:r(Ci,{view:e,panel:n})})})});function Jo(t,e,n){const{panels:i}=ue(),a=t.id==="Main",[o,l]=m.useState(()=>a&&i.findByID(e)?e:null),u=m.useCallback(f=>{l(f),a&&n(f)},[a,n]),c=m.useCallback(()=>{l(null),a&&n("")},[a,n]),p=o?i.findByID(o):null;return{viewPanelInFullScreen:u,exitFullScreen:c,inFullScreen:!!p,fullScreenPanel:p}}const _I="",t1=m.forwardRef(({h:t},e)=>r(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:r(T.ArrowsMove,{size:16})})),n1=m.forwardRef(({handleAxis:t,...e},n)=>r(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:r(T.ChevronDownRight,{size:16})})),r1=ln.WidthProvider(ln),i1=k.observer(({view:t,className:e="layout"})=>{const n=ue(),{panels:i,layouts:a}=n.panels.panelsByIDs(t.panelIDs),o=m.useCallback(u=>{u.forEach(({i:c,...p})=>{const h=n.panels.findByID(c);h&&h.layout.set(p)})},[n]),l=(u,c,p,h)=>{p.h<30&&(p.h=30,h.h=30),p.w<4&&(p.w=4,h.w=4)};return r(r1,{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:r(n1,{}),onResize:l,children:i.map((u,c)=>d("div",{"data-grid":{...u.layout},className:"panel-grid-item",children:[r(t1,{h:u.layout.h}),r(Yo,{view:t,panel:u})]},u.id))})}),a1=ln.WidthProvider(ln),s1=k.observer(function({view:e,className:n="layout"}){const{panels:i,layouts:a}=ue().panels.panelsByIDs(e.panelIDs);return r(a1,{className:`dashboard-layout ${n}`,cols:36,rowHeight:1,margin:[0,0],isDraggable:!1,isResizable:!1,layout:a,children:i.map(o=>r("div",{"data-grid":{...o.layout},className:"panel-grid-item",children:r(Ci,{view:e,panel:o})},o.id))})});function Si(t){const e=m.useRef(null);return{ref:e,downloadScreenshot:()=>{var l;const i=(l=e.current)==null?void 0:l.querySelector(".react-grid-layout");if(!i)return;const a=i.offsetWidth*2+10,o=i.offsetHeight*2+10;oa.toBlob(i,{bgcolor:"white",width:a,height:o,style:{transformOrigin:"0 0",transform:"scale(2)"}}).then(u=>{window.saveAs(u,`${t.name}.png`)})}}}const o1=k.observer(({downloadScreenShot:t})=>{const[e,{setTrue:n,setFalse:i}]=q.useBoolean(!1),a=pr(),o=ue(),l=()=>{const u=JSON.stringify(o.json,null,2),c=`${a.name}__${o.name}`;No(c,u)};return d(s.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:200,closeDelay:400,withinPortal:!0,position:"bottom-end",children:[r(s.Menu.Target,{children:r(s.Affix,{position:{bottom:"20px",right:"10px"},zIndex:1,children:r(s.ActionIcon,{size:"md",variant:"gradient",gradient:{from:"indigo",to:"cyan"},onMouseEnter:n,onMouseLeave:i,sx:{opacity:e?1:.6,transform:`translateX(${e?0:"2px"})`,transition:"all ease 300ms",borderRadius:"50%"},children:r(M.IconShare3,{size:"1rem"})})})}),d(s.Menu.Dropdown,{children:[r(s.Menu.Item,{icon:r(M.IconCamera,{size:14}),onClick:t,children:"Screenshot"}),r(s.Menu.Divider,{}),r(s.Menu.Item,{icon:r(M.IconDownload,{size:14}),onClick:o.queries.downloadAllData,children:"Download Data"}),r(s.Menu.Item,{icon:r(M.IconCode,{size:14}),onClick:l,children:"Download Schema"})]})]})}),Zo=k.observer(({children:t,view:e,sx:n={}})=>{const{ref:i,downloadScreenshot:a}=Si(e);return d(z,{children:[r(s.Box,{ref:i,sx:n,children:t}),r(o1,{downloadScreenShot:a})]})}),Ho=k.observer(({downloadScreenshot:t})=>r(s.ActionIcon,{className:"download-screenshot-button",color:"blue",onClick:t,children:r(M.IconCamera,{size:14})})),l1=k.observer(({children:t,view:e})=>{const n=ue(),i=e.config,a=n.views.visibleViewIDs.includes(e.id),o=()=>n.views.rmVisibleViewID(e.id),{ref:l,downloadScreenshot:u}=Si(e);return r(s.Modal,{size:i.width,centered:!0,opened:a,onClose:o,withCloseButton:!1,title:d(s.Group,{position:"apart",px:"1rem",h:"48px",children:[r(s.Box,{children:i.custom_modal_title.value}),r(Ho,{downloadScreenshot:u})]}),trapFocus:!0,onDragStart:c=>{c.stopPropagation()},styles:{root:{position:"fixed",zIndex:200,inset:0},overlay:{zIndex:"unset"},inner:{zIndex:"unset",padding:"0 !important"},content:{border:"1px solid #efefef",maxHeight:"unset !important",overflow:"hidden"},body:{maxHeight:i.height,overflow:"auto",position:"relative"},header:{padding:0},title:{flexGrow:1}},transitionProps:{duration:0},children:r(s.Box,{ref:l,children:t})})}),u1=t=>t.color?{"&[data-active], &[data-active]:hover":{borderColor:t.color?t.color:"..."}}:{},c1=k.observer(({view:t})=>{const e=ue(),n=t.config;return d(s.Tabs,{className:"render-view-tabs",variant:n.variant,orientation:n.orientation,value:t.tab,onTabChange:t.setTab,styles:{root:{height:"100%",overflow:n.orientation==="horizontal"?"hidden":"auto"},panel:{padding:n.orientation==="horizontal"?"8px 0px 8px":"0",height:"100%",overflow:"auto"}},keepMounted:!1,children:[r(s.Tabs.List,{grow:n.grow,children:n.tabs.map(i=>r(s.Tabs.Tab,{value:i.id,sx:u1(i),disabled:!i.view_id,children:i.name??i.id},i.id))}),n.tabs.map(i=>{const a=e.views.findByID(i.view_id);return a?r(s.Tabs.Panel,{value:i.id,children:r(Qn,{view:a})},i.id):null})]})}),d1=k.observer(({view:t,children:e})=>{switch(t.type){case $.Modal:return r(l1,{view:t,children:e});case $.Tabs:return r(c1,{view:t});case $.Division:default:return r(Zo,{view:t,children:e})}}),p1=k.observer(({children:t,view:e})=>r(Zo,{sx:{paddingTop:"10px",paddingBottom:"100px"},view:e,children:t}));function el(t){return t.replace(/(vw|vh)/,"%")}const h1=k.observer(({children:t,view:e})=>{const n=e.config,{width:i,height:a}=m.useMemo(()=>({width:el(n.width),height:el(n.height)}),[n.width,n.height]),{ref:o,downloadScreenshot:l}=Si(e);return r(s.Box,{sx:{height:"100%","> div:not(.mantine-Modal-root)":{height:"100%"}},children:r(s.Modal,{size:n.width,opened:!0,onClose:x.noop,withCloseButton:!1,title:d(s.Group,{position:"apart",px:"1rem",h:"48px",children:[r(s.Box,{children:n.custom_modal_title.value}),r(Ho,{downloadScreenshot:l})]}),trapFocus:!0,onDragStart:u=>{u.stopPropagation()},styles:{root:{position:"relative",height:"100%"},overlay:{position:"absolute !important"},inner:{position:"relative",top:"50%",left:"50%",right:"unset",bottom:"unset",transform:"translate(-50%, -50%)",padding:"0 !important",width:i,height:a,maxHeight:a},content:{border:"1px solid #efefef",height:"100%"},body:{maxHeight:"calc(100% - 48px)",overflow:"auto"},header:{padding:0},title:{flexGrow:1}},withinPortal:!1,transitionProps:{duration:0},children:r(s.Box,{ref:o,children:t})})})}),f1=({variant:t,orientation:e})=>{const n={root:{height:"100%",overflow:"hidden"},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},g1=t=>t.color?{"&[data-active], &[data-active]:hover":{borderColor:t.color?t.color:"..."}}:{},m1=k.observer(({view:t})=>{const e=Ee.useModals(),n=H(),i=m.useMemo(()=>n.views.options.filter(u=>u.type===$.Division),[t.id,n.views.options]),a=t.config,o=u=>e.openConfirmModal({title:"Delete this tab?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{a.removeTab(u)},confirmProps:{color:"red"},zIndex:320}),l=a.tabs.length===0;return d(s.Tabs,{className:"preview-view-tabs",variant:a.variant,orientation:a.orientation,value:t.tab,onTabChange:t.setTab,styles:f1(a),children:[d(s.Tabs.List,{grow:a.grow,children:[a.tabs.map(u=>r(s.Tabs.Tab,{value:u.id,sx:g1(u),children:u.name??u.id},u.id)),r(s.Tabs.Tab,{onClick:a.addTab,value:"add",className:"add-a-tab",children:r(T.Plus,{size:18,color:"#228be6"})})]}),a.tabs.map((u,c)=>{const p=n.views.findByID(u.view_id);return d(s.Tabs.Panel,{value:u.id,sx:{position:"relative"},children:[d(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:200},children:[r(s.Overlay,{opacity:.8,color:"#FFF",blur:10,zIndex:100}),d(s.Stack,{mx:"auto",mt:100,sx:{width:"300px",position:"relative",zIndex:200},children:[r(s.TextInput,{label:"Tab Name",value:u.name,onChange:h=>u.setName(h.currentTarget.value)}),r(s.Select,{label:"View",value:u.view_id,onChange:u.setViewID,data:i}),r(s.ColorInput,{label:"Color",value:u.color,onChange:u.setColor,disabled:a.variant!=="default"}),p&&d(s.Button,{mt:20,variant:"gradient",leftIcon:r(M.IconArrowsLeftRight,{size:18}),gradient:{from:"cyan",to:"indigo"},onClick:()=>n.views.setIDOfVIE(p.id),children:["Swith to View: ",p.name]}),r(s.Button,{mt:20,variant:"subtle",color:"red",onClick:()=>o(c),disabled:l,leftIcon:r(M.IconTrash,{size:14}),children:"Delete This Tab"})]})]}),p&&r(Qn,{view:p})]},u.id)})]})}),y1=k.observer(({view:t,children:e})=>{switch(t.type){case $.Modal:return r(h1,{view:t,children:e});case $.Tabs:return r(m1,{view:t});case $.Division:default:return r(p1,{view:t,children:e})}}),tl=k.observer(function({view:e}){return r(Fn.Provider,{value:{viewPanelInFullScreen:x.noop,inFullScreen:!1},children:r(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:r(y1,{view:e,children:d(s.Box,{sx:{position:"relative"},children:[r(s.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:r(ho,{view:e})}),r(i1,{view:e})]})})})})}),Qn=k.observer(function({view:e}){const{fullScreenPanelID:n,setFullScreenPanelID:i}=Da(),{viewPanelInFullScreen:a,exitFullScreen:o,inFullScreen:l,fullScreenPanel:u}=Jo(e,n,i);return r(Fn.Provider,{value:{viewPanelInFullScreen:a,inFullScreen:l},children:d(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,sx:{height:e.type===$.Modal?"0 !important":"100%"},children:[l&&r(Xo,{view:e,panel:u,exitFullScreen:o}),r(d1,{view:e,children:d(s.Box,{sx:{position:"relative"},children:[!l&&r(s.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:r(ho,{view:e})}),!l&&r(s1,{view:e})]})})]})})});var nl=(t=>(t.Use="use",t.Edit="edit",t))(nl||{});const b1={[$.Division]:"Division",[$.Tabs]:"Tabs",[$.Modal]:"Modal"},rl={[$.Division]:"rgba(255, 0, 0, 0.2)",[$.Modal]:"rgba(0, 0, 0, 0.2)",[$.Tabs]:"rgba(255, 200, 100, 0.4)"},v1={[$.Division]:"#ff4000",[$.Modal]:"#000",[$.Tabs]:"#ffad18"},x1={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:$.Division,config:{},panelIDs:[]}],panels:[],filters:[],version:"9.19.0"};function w1(t,e,n){y.addDisposer(t,y.addMiddleware(t,(i,a)=>{a(i,()=>{y.getType(i.context)===e&&i.type==="action"&&n(i.name,i.context)})}))}const il=y.types.compose("FiltersModel",Bo,y.types.model("FiltersModel",{previewValues:y.types.optional(y.types.frozen(),{})})).views(t=>({get options(){return t.current.map(e=>({label:e.label??e.id,value:e.id,_type:"filter"}))},get selects(){return t.current.filter(e=>e.type===de.Select).map(e=>({label:e.label??e.id,value:e.id}))},get keyLabelOptions(){return t.current.map(e=>({label:e.label??e.key,value:e.key}))}})).actions(t=>({replace(e){t.current=y.cast(e)},append(e){t.current.push(e)},remove(e){t.current.splice(e,1)},removeByID(e){const n=t.current.findIndex(i=>i.id===e);n>=0&&t.current.splice(n,1)},updatePreviewValues(e){t.previewValues=e}})).actions(t=>{function e(){w1(t.current,_o,(n,i)=>{if(n==="setType"){const a=Lo(i.config.default_value,i.config);t.setValueByKey(i.key,a),t.updatePreviewValues({...t.previewValues,[i.key]:a})}})}return{afterCreate(){e()}}}),al=qo.views(t=>({get options(){const e=t.current.map(n=>({value:n.id,label:n.name,_type:"query"}));return x.sortBy(e,n=>n.label.toLowerCase())},get sortedList(){return x.sortBy(t.current,e=>e.name.toLowerCase())}})).actions(t=>({replace(e){t.current=y.cast(e)},append(e){t.current.push(e)},remove(e){t.current.splice(e,1)},replaceByIndex(e,n){t.current.splice(e,1,n)},removeQuery(e){const n=t.current.find(i=>i.id===e);n&&(y.detach(n),t.current.remove(n))},removeQueries(e){const n=new Set(e);t.current.forEach(a=>{n.has(a.id)&&y.detach(a)});const i=[...t.current];x.remove(i,a=>n.has(a.id)),t.current=y.cast(i)}})),sl=Go.views(t=>({get sortedList(){return x.sortBy(t.current,e=>e.key.toLowerCase())},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())}})).actions(t=>({replace(e){t.current=y.cast(e)},append(e){t.current.push(e)},remove(e){t.current.splice(e,1)},removeByKey(e){const n=t.current.findIndex(i=>i.key===e);n>=0&&t.current.splice(n,1)},removeByKeys(e){const n=new Set(e);t.current.forEach(a=>{n.has(a.key)&&y.detach(a)});const i=[...t.current];x.remove(i,a=>n.has(a.key)),t.current=y.cast(i)},replaceByIndex(e,n){t.current.splice(e,1,n)}})),C1=y.types.model({data:y.types.optional(y.types.frozen(),[]),state:y.types.optional(y.types.enumeration(["idle","loading","error"]),"idle"),error:y.types.frozen()}).views(t=>({get loading(){return t.state==="loading"},get empty(){return t.data.length===0}})),S1=y.types.model({data:y.types.optional(y.types.frozen(),[]),state:y.types.optional(y.types.enumeration(["idle","loading","error"]),"idle"),error:y.types.frozen()}).views(t=>({get loading(){return t.state==="loading"},get empty(){return t.data.length===0}})),_1=y.types.model({page:y.types.optional(y.types.number,1),limit:y.types.optional(y.types.number,20),data:y.types.optional(y.types.frozen(),[]),total:y.types.optional(y.types.number,0),state:y.types.optional(y.types.enumeration(["idle","loading","error"]),"idle"),error:y.types.frozen()}).views(t=>({get keywords(){return y.getParent(t,1)},get keywordString(){const{table_name:e,table_schema:n}=y.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 offset(){return(t.page-1)*t.limit},get countSql(){const{table_name:e,table_schema:n}=t.keywords;return`
|
|
441
441
|
SELECT count(*) AS total
|
|
442
|
-
FROM ${n}.${
|
|
443
|
-
`}})).actions(e=>({setPage(t){e.page=t},resetPage(){e.page=1},setLimit(t){e.limit=t}})).actions(e=>({afterCreate(){b.addDisposer(e,te.reaction(()=>e.keywordString,e.resetPage,{fireImmediately:!1,delay:0})),b.addDisposer(e,te.reaction(()=>e.limit,e.resetPage,{fireImmediately:!1,delay:0}))}})),z_=b.types.model({data:b.types.optional(b.types.frozen(),{}),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return Object.keys(e.data).length===0}})),E_=b.types.compose("DataSourceModel",Cl,b.types.model({tables:b.types.optional(z_,{}),columns:b.types.optional(I_,{}),tableData:b.types.optional(A_,{}),indexes:b.types.optional(M_,{}),table_schema:b.types.optional(b.types.string,""),table_name:b.types.optional(b.types.string,"")})).views(e=>({get sqlDataSourceType(){return e.type},get reloadConditionString(){const{type:t,table_name:n,table_schema:r}=e;return`${t};${n};${r}`}})).volatile(()=>({controllers:{tables:new AbortController,columns:new AbortController,indexes:new AbortController,tableData:new AbortController}})).actions(e=>({setKeywords(t,n){e.table_schema=t,e.table_name=n}})).actions(e=>({initKeywords(){if(e.tables.empty)return;const t=Object.keys(e.tables.data)[0],n=e.tables.data[t][0].table_name;e.setKeywords(t,n)}})).actions(e=>{const t=b.flow(function*(){var n;(n=e.controllers.tables)==null||n.abort(),e.controllers.tables=new AbortController,e.tables.state="loading";try{const r=yield*b.toGenerator(at.structure(e.controllers.tables.signal)({query_type:"TABLES",type:e.sqlDataSourceType,key:e.key,table_schema:"",table_name:""},{params:{query_type:"TABLES"}}));e.tables.data=x.groupBy(r,"table_schema"),e.tables.state="idle",e.tables.error=null,e.initKeywords()}catch(r){if(!pt.isCancel(r)){e.tables.data={};const a=x.get(r,"message","unkown error");e.tables.error=x.get(r,"response.data.detail.message",a),e.tables.state="error"}}});return{loadTables:t,loadTablesIfEmpty(){e.tables.empty&&t()},loadColumns:b.flow(function*(){var n;(n=e.controllers.columns)==null||n.abort(),e.controllers.columns=new AbortController,e.columns.state="loading";try{e.columns.data=yield*b.toGenerator(at.structure(e.controllers.columns.signal)({query_type:"COLUMNS",type:e.sqlDataSourceType,key:e.key,table_schema:e.table_schema,table_name:e.table_name},{params:{query_type:"COLUMNS"}})),e.columns.state="idle",e.columns.error=null}catch(r){if(pt.isCancel(r))e.columns.state="idle",e.columns.error=null;else{e.columns.data=[];const a=x.get(r,"message","unkown error");e.columns.error=x.get(r,"response.data.detail.message",a),e.columns.state="error"}}}),loadIndexes:b.flow(function*(){var n;(n=e.controllers.indexes)==null||n.abort(),e.controllers.indexes=new AbortController,e.indexes.state="loading";try{e.indexes.data=yield*b.toGenerator(at.structure(e.controllers.indexes.signal)({query_type:"INDEXES",type:e.sqlDataSourceType,key:e.key,table_schema:e.table_schema,table_name:e.table_name},{params:{query_type:"INDEXES"}})),e.indexes.state="idle",e.indexes.error=null}catch(r){if(pt.isCancel(r))e.indexes.state="idle",e.indexes.error=null;else{e.indexes.data=[];const a=x.get(r,"message","unkown error");e.indexes.error=x.get(r,"response.data.detail.message",a),e.indexes.state="error"}}}),loadTableData:b.flow(function*(){var r;(r=e.controllers.tableData)==null||r.abort(),e.controllers.tableData=new AbortController;const n=e.tableData;n.state="loading";try{n.data=yield*b.toGenerator(at.structure(e.controllers.tableData.signal)({query_type:"DATA",type:e.sqlDataSourceType,key:e.key,table_schema:e.table_schema,table_name:e.table_name,limit:n.limit,offset:n.offset},{params:{query_type:"DATA"}}));const[{total:a}]=yield*b.toGenerator(at.structure(e.controllers.tableData.signal)({query_type:"COUNT",type:e.sqlDataSourceType,key:e.key,table_schema:e.table_schema,table_name:e.table_name},{params:{query_type:"COUNT"}}));n.total=Number(a),n.state="idle",n.error=null}catch(a){if(pt.isCancel(a))n.state="idle",n.error=null;else{n.data=[];const o=x.get(a,"message","unkown error");n.error=x.get(a,"response.data.detail.message",o),n.state="error"}}})}}).actions(e=>({afterCreate(){b.addDisposer(e,te.reaction(()=>e.reloadConditionString,e.loadColumns,{fireImmediately:!1,delay:500}))}})).actions(e=>({afterCreate(){b.addDisposer(e,te.reaction(()=>e.reloadConditionString,e.loadIndexes,{fireImmediately:!1,delay:500})),b.addDisposer(e,te.reaction(()=>`${e.reloadConditionString};limit:${e.tableData.limit};offset:${e.tableData.offset}`,e.loadTableData,{fireImmediately:!1,delay:0}))}})),$_=b.types.model("DataSourcesModel",{list:b.types.optional(b.types.array(E_),[])}).views(e=>({find({type:t,key:n}){return e.list.find(r=>r.key===n&&r.type===t)},get options(){return e.list.map(t=>({value:t.key,label:t.key}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}}));function Kt(e){return{label:e,value:e,_type:"ACTION",_action_type:e,Icon:null,children:null}}function L_(e){switch(e._type){case"GROUP":case"ACTION":return null;case"query_variables":return["_QUERY_VARS_"];case"mock_context":return["_MOCK_CONTEXT_"];case"filter":return["_FILTERS_",e.value];case"sql_snippet":return["_SQL_SNIPPETS_",e.value];case"query":return["_QUERIES_",e.value];case"view":return["_VIEWS_",e.value];case"panel":return e.parentID?["_VIEWS_",e.parentID,"_PANELS_",e.value]:(console.error("[getPathFromOption] parentID is required"),null)}}const P_=b.types.model("EditorModel",{path:b.types.optional(b.types.frozen(),[]),settings_open:b.types.optional(b.types.boolean,!1)}).views(e=>({get navOptions(){const{content:t}=b.getRoot(e),{filters:n,views:r,sqlSnippets:a,queries:o}=t;return[{label:"Query Variables",value:"_QUERY_VARS_",_type:"query_variables",Icon:E.IconVariable},{label:"Mock Context",value:"_MOCK_CONTEXT_",Icon:E.IconCodeDots,_type:"mock_context"},{label:"Filters",value:"_FILTERS_",Icon:E.IconFilter,children:[...n.options,Kt("_Add_A_Filter_")],_type:"GROUP"},{label:"SQL Snippets",value:"_SQL_SNIPPETS_",Icon:E.IconCopy,children:[Kt("_SQL_SNIPPETS_SETTINGS_"),...a.options,Kt("_Add_A_SQL_SNIPPET_")],_type:"GROUP"},{label:"Queries",value:"_QUERIES_",Icon:E.IconDatabase,children:[Kt("_QUERIES_SETTINGS_"),...o.options,Kt("_Add_A_QUERY_")],_type:"GROUP"},{label:"Views",value:"_VIEWS_",Icon:E.IconBoxMultiple,children:[...r.editorOptions,Kt("_Add_A_VIEW_")],_type:"GROUP"}]},isOptionActive(t,n){return t.length===0?!1:t[t.length-1]===n.value},isOptionOpened(t){const{path:n}=e;return n.length===0||!t.children||t.children.length===0?!1:n.includes(t.value)}})).actions(e=>({setPath(t){e.path=t},setSettingsOpen(t){e.settings_open=t}})).actions(e=>({open(t){e.setPath(t),e.setSettingsOpen(!0)},close(){e.setSettingsOpen(!1)},navigate(t){const n=L_(t);n&&e.setPath(n)}})),tu=Tl.views(e=>({get dataFieldOptions(){return e.queryIDs.length===0?[]:e.queries.map(t=>{const n=t.data;return n.length===0?[]:Object.keys(n[0]).map(a=>({label:a,value:`${t.id}.${a}`,group:t.name}))}).flat()}})).actions(e=>({removeSelf(){b.getParent(e,2).removeByID(e.id)}})).actions(e=>({moveToView(t,n){b.getRoot(e).content.views.findByID(t).removePanelID(e.id),b.getRoot(e).content.views.findByID(n).appendPanelID(e.id),b.getRoot(e).editor.setPath(["_VIEWS_",n,"_PANELS_",e.id])}})),nu=b.types.compose("PanelsModel",Dl,b.types.model({list:b.types.optional(b.types.array(tu),[])})).views(e=>({editorOptions(t,n){const{panels:r}=e.panelsByIDs(n);r.length!==n.length&&console.warn(`Unfulfilled panels for View[${t}]`);const a=r.map(l=>({label:l.name,value:l.id,_type:"panel",parentID:t})),o="_Add_A_PANEL_";return a.push({label:o,value:o,_type:"ACTION",_action_type:o,parentID:t,Icon:null,children:null}),a}})).actions(e=>({replace(t){e.list=b.castToSnapshot(t)},append(t){e.list.push(t)},remove(t){e.list.splice(t,1)},removeByID(t){const n=e.list.findIndex(r=>r.id===t);n!==-1&&e.list.splice(n,1)},removeByIDs(t){t.forEach(n=>{this.removeByID(n)})},duplicateByID(t){const n=e.list.find(a=>a.id===t);if(!n){console.error(new Error(`[duplicate panel] Can't find a panel by id[${t}]`));return}const r=new Date().getTime().toString();return e.list.push({...n.json,id:r,layout:{...n.layout,y:1/0,moved:!1}}),r},replaceByIndex(t,n){e.list.splice(t,1,n)}})),ru=b.types.compose("ViewsModel",kl,b.types.model({idOfVIE:b.types.string})).views(e=>({get isVIETheFirstView(){return e.current.length===0||!e.idOfVIE?!1:e.current[0].id===e.idOfVIE},get VIE(){return e.current.find(({id:t})=>t===e.idOfVIE)},get options(){return e.current.map(t=>({label:t.name,value:t.id,type:t.type}))},get editorOptions(){const t=b.getRoot(e).content.panels;return e.current.map(n=>({label:n.name,value:n.id,_type:"view",children:t.editorOptions(n.id,n.panelIDs)}))}})).actions(e=>({setIDOfVIE(t){e.idOfVIE=t,e.visibleViewIDs.length=0,e.visibleViewIDs.push(t)},replace(t){e.current.replace(t)},addANewView(t,n,r,a){e.current.push({id:t,name:n,type:r,config:a,panelIDs:[]})},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByID(t){const n=e.current.findIndex(o=>o.id===t);if(n===-1)return;const r=e.current[n];b.getRoot(e).content.panels.removeByIDs(r.panelIDs),e.current.splice(n,1)},replaceByIndex(t,n){e.current.splice(t,1,n)},addARandomNewView(){const t=new Date().getTime().toString();this.addANewView(t,j.Division,j.Division,{_name:j.Division}),this.setIDOfVIE(t)},removeVIE(){e.current.length!==1&&(this.removeByID(e.idOfVIE),this.setIDOfVIE(e.current[0].id))}}));function Fi(e){const t=e.length>0?[e[0].id]:[],n=e.length>0?e[0].id:"";return{current:e.map(a=>{const{_name:o=a.type}=a.config;return{...a,config:{...a.config,_name:o},panelIDs:a.panelIDs}}),visibleViewIDs:t,idOfVIE:n}}const O_=b.types.model({id:b.types.string,name:b.types.string,dashboard_id:b.types.string,create_time:b.types.string,update_time:b.types.string,version:b.types.string,filters:Zl,queries:Hl,sqlSnippets:eu,views:ru,panels:nu,mock_context:ll,origin:b.types.maybe(b.types.frozen())}).views(e=>({get json(){return{id:e.id,name:e.name,create_time:e.create_time,update_time:e.update_time,dashboard_id:e.dashboard_id,content:{views:e.views.json,panels:e.panels.json,filters:e.filters.json,version:e.version,definition:{queries:e.queries.json,sqlSnippets:e.sqlSnippets.json,mock_context:e.mock_context.current}}}},get filtersChanged(){const t="filters.current";return!x.isEqual(b.getSnapshot(x.get(e,t)),x.get(e.origin,t))},get queriesChanged(){const t="queries.current",n=b.getSnapshot(x.get(e,t)).map(r=>x.pick(r,["id","name","key","type","sql","run_by","react_to","pre_process","post_process"]));return!x.isEqual(n,x.get(e.origin,t))},get sqlSnippetsChanged(){const t="sqlSnippets.current";return!x.isEqual(b.getSnapshot(x.get(e,t)),x.get(e.origin,t))},get viewsChanged(){const t="views.current";return!x.isEqual(e.views.json,x.get(e.origin,t))},get panelsChanged(){const t="panels.list";return!x.isEqual(b.getSnapshot(x.get(e,t)),x.get(e.origin,t))},get mockContextChanged(){const t="mock_context.current";return!x.isEqual(x.get(e,t),x.get(e.origin,t))},get payloadForSQL(){const t=b.getParent(e).context.current,n=b.getParent(e).globalSQLSnippets,r={context:{...e.mock_context.current,...t},filters:e.filters.values};return{...r,sql_snippets:ur(e.sqlSnippets.current,"key","value",r),global_sql_snippets:ur(n.list,"id","content",r)}},get payloadForViz(){const t=b.getParent(e).context.current;return{context:{...e.mock_context.current,...t},filters:e.filters.values}},get dashboardState(){return Sr(this.payloadForSQL)},getAdditionalQueryInfo(t){return{content_id:e.id,query_id:t,params:this.dashboardState}},get changed(){return this.filtersChanged||this.queriesChanged||this.sqlSnippetsChanged||this.viewsChanged||this.panelsChanged||this.mockContextChanged},get data(){return e.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(t){const n=e.queries.findByID(t);return n?{data:n.data,len:n.data.length,state:n.state,error:n.error}:{data:[],len:0,state:"idle",error:void 0}}})).views(e=>({get queriesUsage(){const t=e.panels.idMap,n=[];e.views.current.forEach(a=>{a.panelIDs.forEach(o=>{const l=t.get(o);if(!l)return;const u="panel",c=l.name,d=[{id:a.id,label:a.name}];l.queryIDs.forEach(f=>{n.push({id:o,queryID:f,type:u,label:c,views:d})})})});const r=e.views.idMap;return e.filters.current.filter(a=>!!x.get(a,"config.options_query_id")).forEach(a=>{n.push({type:"filter",id:a.id,queryID:x.get(a,"config.options_query_id"),label:a.label,views:a.visibleInViewsIDs.map(o=>{var l;return{id:o,label:((l=r.get(o))==null?void 0:l.name)??o}})})}),x.groupBy(n,"queryID")},get hasUnusedQueries(){return e.queries.current.length>Object.keys(this.queriesUsage).length},findQueryUsage(t){return this.queriesUsage[t]??[]},get sqlSnippetsUsage(){const t=[],n=new RegExp("(?<=sql_snippets\\.)([^}.]+)","gm");return e.queries.current.forEach(r=>{if(!r.typedAsSQL)return;x.uniq(r.sql.match(n)).forEach(o=>{t.push({queryID:r.id,sqlSnippetKey:o,queryName:r.name})})}),x.groupBy(t,"sqlSnippetKey")},get hasUnusedSQLSnippets(){return e.sqlSnippets.current.length>Object.keys(this.sqlSnippetsUsage).length},findSQLSnippetUsage(t){return this.sqlSnippetsUsage[t]??[]}})).actions(e=>({removeUnusedQueries(){const t=new Set(Object.keys(e.queriesUsage)),n=e.queries.current.filter(r=>!t.has(r.id)).map(r=>r.id);e.queries.removeQueries(n)},removeUnusedSQLSnippets(){const t=new Set(Object.keys(e.sqlSnippetsUsage)),n=e.sqlSnippets.current.filter(r=>!t.has(r.key)).map(r=>r.key);e.sqlSnippets.removeByKeys(n)},duplicatePanelByID(t,n){var a;const r=e.panels.duplicateByID(t);r&&((a=e.views.findByID(n))==null||a.appendPanelID(r))},removePanelByID(t,n){var r;e.panels.removeByID(t),(r=e.views.findByID(n))==null||r.removePanelID(t)},addANewPanel(t){var r;const n=new Date().getTime().toString();e.panels.append(AS(n)),(r=e.views.findByID(t))==null||r.appendPanelID(n)}})).actions(e=>({reset(){b.applySnapshot(e.filters.current,e.origin.filters.current),b.applySnapshot(e.queries.current,e.origin.queries.current),b.applySnapshot(e.sqlSnippets.current,e.origin.sqlSnippets.current),b.applySnapshot(e.views.current,e.origin.views.current),b.applySnapshot(e.panels.list,e.origin.panels.list),e.mock_context.current=e.origin.mock_context.current},resetFilters(){b.applySnapshot(e.filters.current,e.origin.filters.current)},updateCurrent(t){const{id:n,name:r,content:a}=t;if(!a)throw new Error("unexpected null content when updating a content model");const{version:o,filters:l,views:u,panels:c,definition:{queries:d,sqlSnippets:f,mock_context:h={}}}=a;e.id=n,e.name=r,e.version=o,b.applySnapshot(e.filters.current,l),b.applySnapshot(e.views.current,Fi(u).current),b.applySnapshot(e.panels.list,c),b.applySnapshot(e.queries.current,d),b.applySnapshot(e.sqlSnippets.current,f),e.mock_context.current=h}})),Gi=b.types.snapshotProcessor(O_,{preProcessor(e){return{...e,origin:e}},postProcessor(e){delete e.origin;const t=b.castToSnapshot(e.queries.current.map(n=>x.pick(n,["id","key","type","sql"])));return x.defaults({},{queries:{current:t}},e)}});function B_(e,t){t.filters&&b.applySnapshot(e.filters.current,t.filters)}function iu({id:e,name:t,dashboard_id:n,create_time:r,update_time:a,content:o}){if(!o)throw new Error("unexpected null content when creating a content model");const{version:l,filters:u,views:c,panels:d,definition:{queries:f,sqlSnippets:h,mock_context:g={}}}=o;return Gi.create({id:e,name:t,dashboard_id:n,create_time:r,update_time:a,version:l,filters:Al(u),queries:{current:f},sqlSnippets:{current:h},mock_context:ul(g),views:Fi(c),panels:{list:d}})}const au=b.types.model({id:b.types.identifier,name:b.types.string,group:b.types.string,content:Gi,content_id:b.types.string,datasources:$_,globalSQLSnippets:Sl,context:Oi,editor:P_}).views(e=>({get json(){return{id:e.id,name:e.name,group:e.group,content_id:e.content_id}}})).actions(e=>({updateCurrentContent(t){e.content.updateCurrent(t)},updateCurrent(t,n){const{id:r,name:a,group:o,content_id:l}=t;e.id=r,e.name=a,e.group=o,e.content_id=l,this.updateCurrentContent(n)}}));function su({id:e,name:t,group:n,content_id:r},a,o,l,u){return au.create({id:e,name:t,group:n,content_id:r,content:iu(a),datasources:{list:o},globalSQLSnippets:{list:l},context:_l(u),editor:{}})}function ou(e,t){m.useEffect(()=>{const n=r=>{console.log(r);const{viewID:a}=r.detail;if(!a){console.error(new Error("[Open View] Needs to pick a view first"));return}e.views.appendToVisibles(a),t&&e.views.setIDOfVIE(a)};return window.addEventListener("open-view",n),()=>{window.removeEventListener("open-view",n)}},[e,t]),m.useEffect(()=>{const n=r=>{console.log(r);const{dictionary:a,payload:o}=r.detail;if(!o||Object.keys(o).length===0){console.error(new Error("[Set Filter Values] payload is empty"));return}Object.entries(a).forEach(([l,u])=>{e.filters.setValueByKey(l,x.get(o,u))})};return window.addEventListener("set-filter-values",n),()=>{window.removeEventListener("set-filter-values",n)}},[e]),m.useEffect(()=>{function n(a){return Array.isArray(a)?[]:typeof a=="object"?{}:typeof a=="boolean"?!1:typeof a=="string"?"":typeof a=="number"?0:a}const r=a=>{console.log(a);const{filter_keys:o}=a.detail;o.forEach(l=>{const u=x.get(e.filters.values,l),c=n(u);console.log(`${l}: ${c}`),e.filters.setValueByKey(l,c)})};return window.addEventListener("clear-filter-values",r),()=>{window.removeEventListener("clear-filter-values",r)}},[e]),m.useEffect(()=>{const n=r=>{console.log(r);const{urlTemplate:a,openInNewTab:o,enableEncoding:l=!1,payload:u}=r.detail;if(!a){console.error(new Error("[Open Link] URL is empty"));return}function c(h){return x.cloneDeepWith(h,y=>{if(l&&typeof y=="string")return encodeURIComponent(y)})}const f=x.template(a||"")(c({...u,filters:e.payloadForSQL.filters,context:e.payloadForSQL.context}));window.open(f,o?"_blank":"_self","noopener")};return window.addEventListener("open-link",n),()=>{window.removeEventListener("open-link",n)}},[e])}function lu(e){return m.useCallback(t=>t.provideValue(be.pluginManager,e.pluginManager).provideValue(be.vizManager,e.vizManager).provideValue(be.colorManager,e.colorManager),[])}const VM="",V_=k.observer(()=>{const e=Mr(),t=le(),n=()=>{const r=JSON.stringify(t.json,null,2),a=`${e.name}__${t.name}`;$l(a,r)};return p(s.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:310,children:[i(s.Menu.Target,{children:i(s.ActionIcon,{variant:"light",color:"blue",children:i(E.IconMenu2,{size:14})})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{icon:i(E.IconDownload,{size:14}),onClick:t.queries.downloadAllData,children:"Download Data"}),i(s.Menu.Item,{icon:i(E.IconCode,{size:14}),onClick:n,children:"Download Schema"})]})]})}),N_=k.observer(({saveDashboardChanges:e})=>{const t=Fe.useModals(),n=le(),r=()=>{t.openConfirmModal({title:p(s.Group,{position:"left",children:[i(E.IconAlertTriangle,{size:18,color:"red"}),i(s.Text,{children:"You are reverting changes"})]}),labels:{confirm:"Confirm",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:()=>n.reset(),zIndex:320,withCloseButton:!1})},a=n.changed;return p(s.Group,{spacing:0,children:[i(s.Button,{color:"green",variant:"filled",size:"xs",leftIcon:i(E.IconDeviceFloppy,{size:18}),onClick:e,disabled:!a,sx:{borderTopRightRadius:0,borderBottomRightRadius:0},children:"Save Changes"}),p(s.Menu,{width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:320,disabled:!a,children:[i(s.Menu.Target,{children:i(s.ActionIcon,{variant:"default",disabled:!a,sx:{height:"30px",borderTopLeftRadius:0,borderBottomLeftRadius:0,svg:{fill:"rgb(173, 181, 189)",stroke:"none"}},children:i(E.IconCaretDown,{size:18})})}),i(s.Menu.Dropdown,{children:i(s.Menu.Item,{icon:i(E.IconRecycle,{size:14,color:"red"}),disabled:!a,onClick:r,children:"Revert Changes"})})]})]})}),q_=k.observer(({saveDashboardChanges:e,headerSlot:t=null})=>{const n=Ku.useNavigate(),r=ue(),a=()=>{n(`/dashboard/${r.id}`)},o=Fe.useModals(),l=()=>{o.openConfirmModal({title:p(s.Group,{position:"left",children:[i(E.IconAlertTriangle,{size:18,color:"red"}),i(s.Text,{children:"There are unsaved changes"})]}),labels:{confirm:"Discard",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:a,zIndex:320,withCloseButton:!1})},u=r.content.changed;return i(s.Header,{height:60,px:"md",py:0,sx:{zIndex:299},children:p(s.Group,{position:"apart",sx:{height:60,minWidth:"1000px",position:"relative"},children:[p(s.Group,{children:[i(s.Button,{size:"xs",color:u?"red":"green",leftIcon:i(E.IconArrowLeft,{size:20}),onClick:u?l:a,children:p(s.Group,{spacing:4,children:["End Editing",i(s.Text,{td:"underline",children:r.name})]})}),i(N_,{saveDashboardChanges:e})]}),p(s.Group,{position:"right",sx:{flexGrow:1},children:[t,i(V_,{})]})]})})}),F_={position:"fixed",top:60,left:0,right:0,height:30,zIndex:299,borderBottom:"1px solid #e9ecef",background:"rgba(233,236,239, 0.15)"},G_=k.observer(()=>{var n;const e=le(),t=((n=e.views.VIE)==null?void 0:n.type)===j.Tabs;return i(s.Box,{sx:F_,pl:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},children:p(s.Group,{position:"apart",align:"center",sx:{height:"30px"},pr:16,children:[i(s.Button,{variant:"outline",color:"blue",radius:0,size:"xs",disabled:!e.views.VIE||t,onClick:()=>e.addANewPanel(e.views.idOfVIE),leftIcon:i(E.IconPlaylistAdd,{size:20}),sx:{height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef",background:"rgb(231, 245, 255)"},children:"Add a Panel"}),i(s.Box,{}),i(s.Box,{})]})})}),W_=k.observer(e=>p(B,{children:[i(q_,{...e}),i(G_,{})]})),NM="";function j_(e,t,n){const r=[];return e.filter(a=>"__INTERACTIONS"in a.viz.conf).forEach((a,o)=>{const l=t[a.id];l.data.interactions=x.get(l,"data.interactions",[]);const{__INTERACTIONS:u,__OPERATIONS:c,__TRIGGERS:d}=a.viz.conf;Object.entries(c).forEach(([f,h])=>{const{schemaRef:g,data:y}=h,{config:C}=y;switch(g){case"builtin:op:open-link":let w=C.urlTemplate.substring(0,100);C.urlTemplate.length>=20&&(w+="..."),l.type="interaction",l.data.interactions.push({schemaRef:g,urlTemplate:C.urlTemplate,shortURLTemplate:w});return;case"builtin:op:open_view":r.push({id:`OPERATION--${f}`,source:a.id,target:C.viewID,label:"Open View",style:{stroke:"rgba(0,0,0,0.8)"},type:"default"});return;case"builtin:op:set_filter_values":l.type="interaction",l.data.interactions.push({schemaRef:g,filters:Object.keys(C.dictionary).map(_=>({key:_,label:n[_]}))});return;case"builtin:op:clear_filter_values":l.type="interaction",l.data.interactions.push({schemaRef:g,filters:C.filter_keys.map(_=>({key:_,label:n[_]}))});return;default:return}})}),r}function R_(e,t){const n=e.filters.keyLabelMap;return{edges:j_(e.panels.list,t,n),edgeNodes:[]}}function uu(e,t,n){return e*t+e*n}function Y_(e,t,n){return e*t+(e-1)*n}const pr=25,Wi=40,cu=25,ji=350,Q_=150,U_=150,du=150,pu=300,hr=40,hu=25,K_=300;function X_(e,t){const n=x.keyBy(t,a=>a.id),r=[];return e.current.forEach((a,o)=>{a.panelIDs.forEach((l,u)=>{const c=uu(u,hr,hu)+Wi,d=n[l];if(!d){r.push({id:l,_node_type:"panel",parentNode:a.id,data:{label:`!: ${l}`},position:{x:pr,y:c},sourcePosition:Ie.Position.Right,targetPosition:Ie.Position.Left,style:{width:pu,height:hr}});return}const f=d.name;r.push({id:d.id,_node_type:"panel",parentNode:a.id,data:{label:f},position:{x:pr,y:c},sourcePosition:Ie.Position.Right,targetPosition:Ie.Position.Left,style:{width:pu,height:hr}})})}),r}const J_={[j.Division]:"Div",[j.Modal]:"Modal",[j.Tabs]:"Tabs"},Z_=Jl;function H_(e){return e.current.map((n,r)=>{const a=Y_(n.panelIDs.length,hr,hu)+Wi+cu;let o=[];return n.type===j.Tabs&&(o=n.config.tabs.map(u=>u.view_id)),{id:n.id,_node_type:"view-root",_view_type:n.type,_view_level:0,_sub_view_ids:[],_tab_view_ids:o,data:{label:`${J_[n.type]}:${n.name}`},position:{x:0,y:0},sourcePosition:Ie.Position.Right,targetPosition:Ie.Position.Left,className:"light",style:{backgroundColor:Z_[n.type],width:ji,height:a}}})}function ek(e){const t=x.keyBy(e,n=>n.id);e.forEach(n=>{n._node_type!=="view-root"||n._view_type!==j.Tabs||n._tab_view_ids.forEach(r=>{t[r].parentNode=n.id})})}function tk(e){const t=H_(e.views);ek(t);const n=X_(e.views,e.panels.list);return[...t,...n]}function nk({nodeMap:e,nodes:t,edges:n}){t.forEach(r=>{r._node_type!=="view-root"||r._view_type!==j.Tabs||(r.sourcePosition=Ie.Position.Bottom,r.style.width=ji+pr*2,r.style.height=cu+r._tab_view_ids.reduce((a,o)=>{const l=e[o];l.position.y=a,l.position.x=pr;const u=l.style.height;return a+u+20},Wi))})}function rk({nodeMap:e,nodes:t,edges:n}){n.filter(r=>r.label==="Open View").forEach(r=>{const a=e[r.source],o=e[r.target];if(!a||!o||!a.parentNode)return;const l=e[a.parentNode];l._node_type!=="view-root"||o._node_type!=="view-root"||(o._view_level+=1+l._view_level,l._sub_view_ids.push(o.id))}),t.sort((r,a)=>r._node_type==="view-root"&&a._node_type==="view-root"?r._view_level-a._view_level:r._node_type!=="view-root"&&a._node_type!=="view-root"?0:r._node_type==="view-root"?-1:1)}function ik({nodeMap:e,nodes:t,edges:n}){const r={};n.forEach(a=>{if(a.label!=="Open View")return;const o=e[a.source],l=e[a.target];if(o&&l&&o.parentNode){const u=e[o.parentNode],c=u.position.x,d=Number(x.get(l,"style.height",0)),f=Number(u.style.width);l.position.x=c+f+K_,u._view_level===0&&l._sub_view_ids.length===0&&(o.sourcePosition=Ie.Position.Left,l.targetPosition=Ie.Position.Right,l.position.x*=-1);const g=l.position.x,y=x.get(r,g,0);l.position.y=y,r[g]=y+d+du}})}function ak({nodeMap:e,nodes:t,edges:n}){const r=new Set,a=new Set;n.forEach(l=>{r.add(l.source),a.add(l.target)}),t.filter(l=>l._node_type!=="view-root"||l.id==="Main"||l.parentNode?!1:!r.has(l.id)&&!a.has(l.id)).forEach((l,u)=>{l.position.x=uu(u,ji,U_),l.position.y=0-Q_-du})}function sk({nodeMap:e,nodes:t,edges:n}){const r={nodeMap:e,nodes:t,edges:n};return ak(r),rk(r),nk(r),ik(r),{nodes:t,edges:n}}function ok(e){const t=tk(e),n=x.keyBy(t,c=>c.id),{edges:r,edgeNodes:a}=R_(e,n),o=[...t,...a],l=x.keyBy(o,c=>c.id),u={edges:x.uniqBy(r,c=>c.id),nodes:o,nodeMap:l};return sk(u)}const qM="",Ri={"builtin:op:open-link":i(s.ThemeIcon,{color:"blue",size:20,radius:"xl",children:i(E.IconCircleDashed,{size:14})}),"builtin:op:set_filter_values":i(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:i(E.IconCircleDot,{size:14})}),"builtin:op:clear_filter_values":i(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:i(E.IconCircleOff,{size:14})})};function lk(e){const t=[];return e.forEach(n=>{switch(n.schemaRef){case"builtin:op:open-link":t.push({key:n.urlTemplate,icon:Ri[n.schemaRef],text:p(s.Group,{spacing:4,children:[i(s.Text,{children:"Open: "}),i(s.Text,{color:"dimmed",children:n.shortURLTemplate})]})});return;case"builtin:op:set_filter_values":n.filters.forEach(({key:r,label:a})=>{t.push({key:n.schemaRef+r,icon:Ri[n.schemaRef],text:i(s.Group,{spacing:4,children:p(s.Text,{children:["Set Filter: ",a]})})})});return;case"builtin:op:clear_filter_values":n.filters.forEach(({key:r,label:a})=>{t.push({key:n.schemaRef+r,icon:Ri[n.schemaRef],text:i(s.Group,{spacing:4,children:p(s.Text,{children:["Clear Filter: ",a]})})})});return}}),t}const uk=m.memo(({data:e,isConnectable:t,sourcePosition:n=Ie.Position.Right,targetPosition:r=Ie.Position.Left,...a})=>{const o=m.useMemo(()=>lk(e.interactions),[e.interactions]);return p(B,{children:[i(Ie.Handle,{type:"target",position:r,isConnectable:t}),i(s.Box,{sx:{position:"absolute",top:0,right:0},children:i(I.ChevronsUpRight,{size:12})}),p(s.HoverCard,{shadow:"xl",withinPortal:!0,children:[i(s.HoverCard.Target,{children:i(s.Text,{children:e.label})}),i(s.HoverCard.Dropdown,{children:i(s.List,{spacing:"xs",size:"sm",center:!0,children:o.map(l=>i(s.List.Item,{icon:l.icon,children:l.text},l.key))})})]}),i(Ie.Handle,{type:"source",position:n,isConnectable:t})]})}),FM="",ck={interaction:uk},dk=k.observer(()=>{const e=ye(),{edges:t,nodes:n}=ok(e);return p(Ie,{nodes:n,edges:t,onNodesChange:x.noop,onEdgesChange:x.noop,onConnect:x.noop,className:"interactions-viewer",fitView:!0,nodeTypes:ck,children:[i(Ie.MiniMap,{}),i(Ie.Controls,{}),i(Ie.Background,{})]})}),pk=k.observer(({opened:e,close:t})=>i(s.Modal,{size:"96vw",opened:e,onClose:t,title:"Interactions",trapFocus:!0,onDragStart:n=>{n.stopPropagation()},styles:{body:{height:"calc(90vh - 54px)"},content:{transform:"none !important"}},zIndex:300,children:i(dk,{})})),hk={"> button":{"&:first-of-type":{borderTopRightRadius:0,borderBottomRightRadius:0,borderRightWidth:.5},":not(:first-of-type):not(:last-of-type)":{borderTopRightRadius:0,borderBottomRightRadius:0,borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeftWidth:.5,borderRightWidth:.5},"&:last-of-type":{borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeftWidth:.5}}};function fk({onClick:e,name:t,active:n,openSettings:r}){return p(s.Box,{sx:{position:"relative"},children:[i(s.UnstyledButton,{sx:a=>({display:"block",width:"100%",padding:a.spacing.xs,borderRadius:0,position:"relative",color:a.black,"&:hover":{backgroundColor:a.colors.gray[0]},backgroundColor:n?a.colors.gray[2]:"transparent"}),children:i(s.Group,{sx:{width:"calc(100% - 28px)"},onClick:e,children:i(s.Text,{size:"sm",children:t})})}),n&&i(s.Tooltip,{label:"Edit",position:"right",withinPortal:!0,children:i(s.ActionIcon,{onClick:r,variant:"light",color:"blue",sx:{position:"absolute",top:0,bottom:0,height:"100%",right:0,zIndex:0,borderRadius:0},children:i(E.IconAdjustments,{size:16})})})]})}const gk=k.observer(()=>{const e=ue(),t=le(),n=m.useCallback(a=>()=>t.views.setIDOfVIE(a),[t]),r=a=>{e.editor.open(["_VIEWS_",a])};return p(s.Box,{sx:{position:"relative"},children:[t.views.options.map(a=>i(fk,{active:t.views.idOfVIE===a.value,name:a.label,onClick:n(a.value),openSettings:()=>r(a.value)},a.value)),i(s.Divider,{variant:"dashed"}),i(s.Button,{variant:"subtle",rightIcon:i(E.IconPlus,{size:14}),size:"sm",px:"xs",color:"blue",onClick:t.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"space-between"}},children:"Add a View"})]})}),mk=k.observer(()=>{const e=ue(),t=le(),n=()=>{if(!t.queries.firstID){e.editor.open(["_QUERIES_",""]);return}e.editor.open(["_QUERIES_",t.queries.firstID])},r=()=>{if(!t.filters.firstID){e.editor.open(["_FILTERS_",""]);return}e.editor.open(["_FILTERS_",t.filters.firstID])},[a,o]=m.useState(!1),l=()=>o(!0),u=()=>o(!1);return p(s.Navbar,{p:0,width:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},zIndex:299,children:[p(s.Navbar.Section,{children:[p(s.Group,{grow:!0,spacing:0,sx:{...hk,button:{borderWidth:0,borderBottomWidth:1,borderColor:"#e9ecef"}},children:[i(s.Tooltip,{label:"Filters",withinPortal:!0,children:i(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:r,children:i(E.IconFilter,{size:18})})}),i(s.Tooltip,{label:"Queries",withinPortal:!0,children:i(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:n,children:i(E.IconDatabase,{size:18})})}),i(s.Tooltip,{label:"Interactions Viewer",withinPortal:!0,children:i(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:l,children:i(E.IconLink,{size:18})})})]}),i(pk,{opened:a,close:u})]}),i(s.Navbar.Section,{py:5,sx:{borderBottom:"1px solid #eee"},children:i(s.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Views"})}),i(s.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:i(gk,{})}),i(s.Navbar.Section,{children:i(s.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:i(s.Button,{size:"xs",leftIcon:i(E.IconSettings,{size:20}),onClick:()=>e.editor.open([]),children:"Settings"})})})]})}),yk=k.observer(function({config:t}){return p(B,{children:[i(s.Checkbox,{checked:t.default_value,onChange:n=>t.setDefaultValue(n.currentTarget.checked),label:"Default Checked"}),i(mi,{label:"Description",value:t.description,onChange:t.setDescription,styles:{root:{flexGrow:1,minHeight:"400px"}}})]})}),bk=[{label:"2022",value:"YYYY"},{label:"202201",value:"YYYYMM"},{label:"20220101",value:"YYYYMMDD"},{label:"2022-01",value:"YYYY-MM"},{label:"2022-01-01",value:"YYYY-MM-DD"}],vk=k.observer(function({config:t}){return p(B,{children:[p(s.Group,{children:[i(s.Checkbox,{checked:t.required,onChange:n=>t.setRequired(n.currentTarget.checked),label:"Required"}),i(s.Checkbox,{checked:t.clearable,onChange:n=>t.setClearable(n.currentTarget.checked),disabled:t.max_days>0,label:"Clearable"}),i(s.Checkbox,{checked:t.allowSingleDateInRange,onChange:n=>t.setAllowSingleDateInRange(n.currentTarget.checked),label:"Allow choosing 1 day"})]}),i(s.Select,{data:bk,label:"Display Format",value:t.inputFormat,onChange:t.setInputFormat}),i(al,{label:"Default Value",config:t,value:t.default_value,onChange:t.setDefaultValue}),i(s.NumberInput,{label:"Max Days",description:p(s.Group,{position:"apart",children:[i(s.Text,{children:"Set 0 to disable."}),p(s.Group,{spacing:4,children:[i(s.Text,{children:"This feature requires"}),i(s.Text,{color:"blue",children:"Clearable"}),i(s.Text,{children:"to be checked"})]})]}),min:0,value:t.max_days,onChange:t.setMaxDays,hideControls:!0})]})}),Yi=k.observer(({value:e,onChange:t})=>{const n=ue(),r=le(),a=m.useMemo(()=>r.queries.options,[r.queries.current]),o=a.length===0,l=u=>{n.editor.setPath(["_QUERIES_",u])};return i(s.Select,{label:p(s.Group,{position:"apart",children:[i(s.Text,{children:"Use query data as options"}),e&&i(s.Button,{size:"xs",leftIcon:i(E.IconArrowCurveRight,{size:16}),variant:"subtle",color:"blue",onClick:()=>l(e),children:"Open this query"})]}),data:a,value:e,onChange:t,allowDeselect:!1,clearable:!0,sx:{flexGrow:1},disabled:o,error:o?"You need to add a query in Data Settings":void 0,styles:{label:{display:"block"}}})}),xk=`
|
|
442
|
+
FROM ${n}.${e}
|
|
443
|
+
`}})).actions(t=>({setPage(e){t.page=e},resetPage(){t.page=1},setLimit(e){t.limit=e}})).actions(t=>({afterCreate(){y.addDisposer(t,Q.reaction(()=>t.keywordString,t.resetPage,{fireImmediately:!1,delay:0})),y.addDisposer(t,Q.reaction(()=>t.limit,t.resetPage,{fireImmediately:!1,delay:0}))}})),k1=y.types.model({data:y.types.optional(y.types.frozen(),{}),state:y.types.optional(y.types.enumeration(["idle","loading","error"]),"idle"),error:y.types.frozen()}).views(t=>({get loading(){return t.state==="loading"},get empty(){return Object.keys(t.data).length===0}})),T1=y.types.compose("DataSourceModel",Io,y.types.model({tables:y.types.optional(k1,{}),columns:y.types.optional(C1,{}),tableData:y.types.optional(_1,{}),indexes:y.types.optional(S1,{}),table_schema:y.types.optional(y.types.string,""),table_name:y.types.optional(y.types.string,"")})).views(t=>({get sqlDataSourceType(){return t.type},get reloadConditionString(){const{type:e,table_name:n,table_schema:i}=t;return`${e};${n};${i}`}})).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=y.flow(function*(){var n;(n=t.controllers.tables)==null||n.abort(),t.controllers.tables=new AbortController,t.tables.state="loading";try{const i=yield*y.toGenerator(Xe.structure(t.controllers.tables.signal)({query_type:"TABLES",type:t.sqlDataSourceType,key:t.key,table_schema:"",table_name:""},{params:{query_type:"TABLES"}}));t.tables.data=x.groupBy(i,"table_schema"),t.tables.state="idle",t.tables.error=null,t.initKeywords()}catch(i){if(!nt.isCancel(i)){t.tables.data={};const a=x.get(i,"message","unkown error");t.tables.error=x.get(i,"response.data.detail.message",a),t.tables.state="error"}}});return{loadTables:e,loadTablesIfEmpty(){t.tables.empty&&e()},loadColumns:y.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*y.toGenerator(Xe.structure(t.controllers.columns.signal)({query_type:"COLUMNS",type:t.sqlDataSourceType,key:t.key,table_schema:t.table_schema,table_name:t.table_name},{params:{query_type:"COLUMNS"}})),t.columns.state="idle",t.columns.error=null}catch(i){if(nt.isCancel(i))t.columns.state="idle",t.columns.error=null;else{t.columns.data=[];const a=x.get(i,"message","unkown error");t.columns.error=x.get(i,"response.data.detail.message",a),t.columns.state="error"}}}),loadIndexes:y.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*y.toGenerator(Xe.structure(t.controllers.indexes.signal)({query_type:"INDEXES",type:t.sqlDataSourceType,key:t.key,table_schema:t.table_schema,table_name:t.table_name},{params:{query_type:"INDEXES"}})),t.indexes.state="idle",t.indexes.error=null}catch(i){if(nt.isCancel(i))t.indexes.state="idle",t.indexes.error=null;else{t.indexes.data=[];const a=x.get(i,"message","unkown error");t.indexes.error=x.get(i,"response.data.detail.message",a),t.indexes.state="error"}}}),loadTableData:y.flow(function*(){var i;(i=t.controllers.tableData)==null||i.abort(),t.controllers.tableData=new AbortController;const n=t.tableData;n.state="loading";try{n.data=yield*y.toGenerator(Xe.structure(t.controllers.tableData.signal)({query_type:"DATA",type:t.sqlDataSourceType,key:t.key,table_schema:t.table_schema,table_name:t.table_name,limit:n.limit,offset:n.offset},{params:{query_type:"DATA"}}));const[{total:a}]=yield*y.toGenerator(Xe.structure(t.controllers.tableData.signal)({query_type:"COUNT",type:t.sqlDataSourceType,key:t.key,table_schema:t.table_schema,table_name:t.table_name},{params:{query_type:"COUNT"}}));n.total=Number(a),n.state="idle",n.error=null}catch(a){if(nt.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(){y.addDisposer(t,Q.reaction(()=>t.reloadConditionString,t.loadColumns,{fireImmediately:!1,delay:500}))}})).actions(t=>({afterCreate(){y.addDisposer(t,Q.reaction(()=>t.reloadConditionString,t.loadIndexes,{fireImmediately:!1,delay:500})),y.addDisposer(t,Q.reaction(()=>`${t.reloadConditionString};limit:${t.tableData.limit};offset:${t.tableData.offset}`,t.loadTableData,{fireImmediately:!1,delay:0}))}})),D1=y.types.model("DataSourcesModel",{list:y.types.optional(y.types.array(T1),[])}).views(t=>({find({type:e,key:n}){return t.list.find(i=>i.key===n&&i.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 Bt(t){return{label:t,value:t,_type:"ACTION",_action_type:t,Icon:null,children:null}}function I1(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 M1=y.types.model("EditorModel",{path:y.types.optional(y.types.frozen(),[]),settings_open:y.types.optional(y.types.boolean,!1)}).views(t=>({get navOptions(){const{content:e}=y.getRoot(t),{filters:n,views:i,sqlSnippets:a,queries:o}=e;return[{label:"Query Variables",value:"_QUERY_VARS_",_type:"query_variables",Icon:M.IconVariable},{label:"Mock Context",value:"_MOCK_CONTEXT_",Icon:M.IconCodeDots,_type:"mock_context"},{label:"Filters",value:"_FILTERS_",Icon:M.IconFilter,children:[...n.options,Bt("_Add_A_Filter_")],_type:"GROUP"},{label:"SQL Snippets",value:"_SQL_SNIPPETS_",Icon:M.IconCopy,children:[Bt("_SQL_SNIPPETS_SETTINGS_"),...a.options,Bt("_Add_A_SQL_SNIPPET_")],_type:"GROUP"},{label:"Queries",value:"_QUERIES_",Icon:M.IconDatabase,children:[Bt("_QUERIES_SETTINGS_"),...o.options,Bt("_Add_A_QUERY_")],_type:"GROUP"},{label:"Views",value:"_VIEWS_",Icon:M.IconBoxMultiple,children:[...i.editorOptions,Bt("_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=I1(e);n&&t.setPath(n)}})),ol=Eo.views(t=>({get dataFieldOptions(){return t.queryIDs.length===0?[]:t.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=>({removeSelf(){y.getParent(t,2).removeByID(t.id)}})).actions(t=>({moveToView(e,n){y.getRoot(t).content.views.findByID(e).removePanelID(t.id),y.getRoot(t).content.views.findByID(n).appendPanelID(t.id),y.getRoot(t).editor.setPath(["_VIEWS_",n,"_PANELS_",t.id])}})),ll=y.types.compose("PanelsModel",Po,y.types.model({list:y.types.optional(y.types.array(ol),[])})).views(t=>({editorOptions(e,n){const{panels:i}=t.panelsByIDs(n);i.length!==n.length&&console.warn(`Unfulfilled panels for View[${e}]`);const a=i.map(l=>({label:l.name,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=y.castToSnapshot(e)},append(e){t.list.push(e)},remove(e){t.list.splice(e,1)},removeByID(e){const n=t.list.findIndex(i=>i.id===e);n!==-1&&t.list.splice(n,1)},removeByIDs(e){e.forEach(n=>{this.removeByID(n)})},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 i=new Date().getTime().toString();return t.list.push({...n.json,id:i,layout:{...n.layout,y:1/0,moved:!1}}),i},replaceByIndex(e,n){t.list.splice(e,1,n)}})),ul=y.types.compose("ViewsModel",zo,y.types.model({idOfVIE:y.types.string})).views(t=>({get isVIETheFirstView(){return t.current.length===0||!t.idOfVIE?!1:t.current[0].id===t.idOfVIE},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=y.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=>({setIDOfVIE(e){t.idOfVIE=e,t.visibleViewIDs.length=0,t.visibleViewIDs.push(e)},replace(e){t.current.replace(e)},addANewView(e,n,i,a){t.current.push({id:e,name:n,type:i,config:a,panelIDs:[]})},append(e){t.current.push(e)},remove(e){t.current.splice(e,1)},removeByID(e){const n=t.current.findIndex(o=>o.id===e);if(n===-1)return;const i=t.current[n];y.getRoot(t).content.panels.removeByIDs(i.panelIDs),t.current.splice(n,1)},replaceByIndex(e,n){t.current.splice(e,1,n)},addARandomNewView(){const e=new Date().getTime().toString();this.addANewView(e,$.Division,$.Division,{_name:$.Division}),this.setIDOfVIE(e)},removeVIE(){t.current.length!==1&&(this.removeByID(t.idOfVIE),this.setIDOfVIE(t.current[0].id))}}));function _i(t){const e=t.length>0?[t[0].id]:[],n=t.length>0?t[0].id:"";return{current:t.map(a=>{const{_name:o=a.type}=a.config;return{...a,config:{...a.config,_name:o},panelIDs:a.panelIDs}}),visibleViewIDs:e,idOfVIE:n}}const A1=y.types.model({id:y.types.string,name:y.types.string,dashboard_id:y.types.string,create_time:y.types.string,update_time:y.types.string,version:y.types.string,filters:il,queries:al,sqlSnippets:sl,views:ul,panels:ll,mock_context:fo,origin:y.types.maybe(y.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(y.getSnapshot(x.get(t,e)),x.get(t.origin,e))},get queriesChanged(){const e="queries.current",n=y.getSnapshot(x.get(t,e)).map(i=>x.pick(i,["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(y.getSnapshot(x.get(t,e)),x.get(t.origin,e))},get viewsChanged(){const e="views.current";return!x.isEqual(t.views.json,x.get(t.origin,e))},get panelsChanged(){const e="panels.list";return!x.isEqual(y.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=y.getParent(t).context.current,n=y.getParent(t).globalSQLSnippets,i={context:{...t.mock_context.current,...e},filters:t.filters.values};return{...i,sql_snippets:Wn(t.sqlSnippets.current,"key","value",i),global_sql_snippets:Wn(n.list,"id","content",i)}},get payloadForViz(){const e=y.getParent(t).context.current;return{context:{...t.mock_context.current,...e},filters:t.filters.values}},get dashboardState(){return sr(this.payloadForSQL)},getAdditionalQueryInfo(e){return{content_id:t.id,query_id:e,params:this.dashboardState}},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:i})=>({id:n,data:i})).reduce((n,i)=>(n[i.id]=i.data,n),{})},getDataStuffByID(e){const n=t.queries.findByID(e);return n?{data:n.data,len:n.data.length,state:n.state,error:n.error}:{data:[],len:0,state:"idle",error:void 0}}})).views(t=>({get queriesUsage(){const e=t.panels.idMap,n=[];t.views.current.forEach(a=>{a.panelIDs.forEach(o=>{const l=e.get(o);if(!l)return;const u="panel",c=l.name,p=[{id:a.id,label:a.name}];l.queryIDs.forEach(h=>{n.push({id:o,queryID:h,type:u,label:c,views:p})})})});const i=t.views.idMap;return t.filters.current.filter(a=>!!x.get(a,"config.options_query_id")).forEach(a=>{n.push({type:"filter",id:a.id,queryID:x.get(a,"config.options_query_id"),label:a.label,views:a.visibleInViewsIDs.map(o=>{var l;return{id:o,label:((l=i.get(o))==null?void 0:l.name)??o}})})}),x.groupBy(n,"queryID")},get hasUnusedQueries(){return t.queries.current.length>Object.keys(this.queriesUsage).length},findQueryUsage(e){return this.queriesUsage[e]??[]},get sqlSnippetsUsage(){const e=[],n=new RegExp("(?<=sql_snippets\\.)([^}.]+)","gm");return t.queries.current.forEach(i=>{if(!i.typedAsSQL)return;x.uniq(i.sql.match(n)).forEach(o=>{e.push({queryID:i.id,sqlSnippetKey:o,queryName:i.name})})}),x.groupBy(e,"sqlSnippetKey")},get hasUnusedSQLSnippets(){return t.sqlSnippets.current.length>Object.keys(this.sqlSnippetsUsage).length},findSQLSnippetUsage(e){return this.sqlSnippetsUsage[e]??[]}})).actions(t=>({removeUnusedQueries(){const e=new Set(Object.keys(t.queriesUsage)),n=t.queries.current.filter(i=>!e.has(i.id)).map(i=>i.id);t.queries.removeQueries(n)},removeUnusedSQLSnippets(){const e=new Set(Object.keys(t.sqlSnippetsUsage)),n=t.sqlSnippets.current.filter(i=>!e.has(i.key)).map(i=>i.key);t.sqlSnippets.removeByKeys(n)},duplicatePanelByID(e,n){var a;const i=t.panels.duplicateByID(e);i&&((a=t.views.findByID(n))==null||a.appendPanelID(i))},removePanelByID(e,n){var i;t.panels.removeByID(e),(i=t.views.findByID(n))==null||i.removePanelID(e)},addANewPanel(e){var i;const n=new Date().getTime().toString();t.panels.append(__(n)),(i=t.views.findByID(e))==null||i.appendPanelID(n)}})).actions(t=>({reset(){y.applySnapshot(t.filters.current,t.origin.filters.current),y.applySnapshot(t.queries.current,t.origin.queries.current),y.applySnapshot(t.sqlSnippets.current,t.origin.sqlSnippets.current),y.applySnapshot(t.views.current,t.origin.views.current),y.applySnapshot(t.panels.list,t.origin.panels.list),t.mock_context.current=t.origin.mock_context.current},resetFilters(){y.applySnapshot(t.filters.current,t.origin.filters.current)},updateCurrent(e){const{id:n,name:i,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:p,sqlSnippets:h,mock_context:f={}}}=a;t.id=n,t.name=i,t.version=o,y.applySnapshot(t.filters.current,l),y.applySnapshot(t.views.current,_i(u).current),y.applySnapshot(t.panels.list,c),y.applySnapshot(t.queries.current,p),y.applySnapshot(t.sqlSnippets.current,h),t.mock_context.current=f}})),ki=y.types.snapshotProcessor(A1,{preProcessor(t){return{...t,origin:t}},postProcessor(t){delete t.origin;const e=y.castToSnapshot(t.queries.current.map(n=>x.pick(n,["id","key","type","sql"])));return x.defaults({},{queries:{current:e}},t)}});function z1(t,e){e.filters&&y.applySnapshot(t.filters.current,e.filters)}function cl({id:t,name:e,dashboard_id:n,create_time:i,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:p,definition:{queries:h,sqlSnippets:f,mock_context:g={}}}=o;return ki.create({id:t,name:e,dashboard_id:n,create_time:i,update_time:a,version:l,filters:Oo(u),queries:{current:h},sqlSnippets:{current:f},mock_context:go(g),views:_i(c),panels:{list:p}})}const dl=y.types.model({id:y.types.identifier,name:y.types.string,group:y.types.string,content:ki,content_id:y.types.string,datasources:D1,globalSQLSnippets:Mo,context:vi,editor:M1}).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:i,name:a,group:o,content_id:l}=e;t.id=i,t.name=a,t.group=o,t.content_id=l,this.updateCurrentContent(n)}}));function pl({id:t,name:e,group:n,content_id:i},a,o,l,u){return dl.create({id:t,name:e,group:n,content_id:i,content:cl(a),datasources:{list:o},globalSQLSnippets:{list:l},context:Ao(u),editor:{}})}function hl(t,e){m.useEffect(()=>{const n=i=>{console.log(i);const{viewID:a}=i.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]),m.useEffect(()=>{const n=i=>{console.log(i);const{dictionary:a,payload:o}=i.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]),m.useEffect(()=>{function n(a){return Array.isArray(a)?[]:typeof a=="object"?{}:typeof a=="boolean"?!1:typeof a=="string"?"":typeof a=="number"?0:a}const i=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",i),()=>{window.removeEventListener("clear-filter-values",i)}},[t]),m.useEffect(()=>{const n=i=>{console.log(i);const{urlTemplate:a,openInNewTab:o,enableEncoding:l=!1,payload:u}=i.detail;if(!a){console.error(new Error("[Open Link] URL is empty"));return}function c(f){return x.cloneDeepWith(f,b=>{if(l&&typeof b=="string")return encodeURIComponent(b)})}const h=x.template(a||"")(c({...u,filters:t.payloadForSQL.filters,context:t.payloadForSQL.context}));window.open(h,o?"_blank":"_self","noopener")};return window.addEventListener("open-link",n),()=>{window.removeEventListener("open-link",n)}},[t])}function fl(t){return m.useCallback(e=>e.provideValue(ce.pluginManager,t.pluginManager).provideValue(ce.vizManager,t.vizManager).provideValue(ce.colorManager,t.colorManager),[])}const kI="",E1=k.observer(()=>{const t=pr(),e=H(),n=()=>{const i=JSON.stringify(e.json,null,2),a=`${t.name}__${e.name}`;No(a,i)};return d(s.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:310,children:[r(s.Menu.Target,{children:r(s.ActionIcon,{variant:"light",color:"blue",children:r(M.IconMenu2,{size:14})})}),d(s.Menu.Dropdown,{children:[r(s.Menu.Item,{icon:r(M.IconDownload,{size:14}),onClick:e.queries.downloadAllData,children:"Download Data"}),r(s.Menu.Item,{icon:r(M.IconCode,{size:14}),onClick:n,children:"Download Schema"})]})]})}),P1=k.observer(({saveDashboardChanges:t})=>{const e=Ee.useModals(),n=H(),i=()=>{e.openConfirmModal({title:d(s.Group,{position:"left",children:[r(M.IconAlertTriangle,{size:18,color:"red"}),r(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 d(s.Group,{spacing:0,children:[r(s.Button,{color:"green",variant:"filled",size:"xs",leftIcon:r(M.IconDeviceFloppy,{size:18}),onClick:t,disabled:!a,sx:{borderTopRightRadius:0,borderBottomRightRadius:0},children:"Save Changes"}),d(s.Menu,{width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:320,disabled:!a,children:[r(s.Menu.Target,{children:r(s.ActionIcon,{variant:"default",disabled:!a,sx:{height:"30px",borderTopLeftRadius:0,borderBottomLeftRadius:0,svg:{fill:"rgb(173, 181, 189)",stroke:"none"}},children:r(M.IconCaretDown,{size:18})})}),r(s.Menu.Dropdown,{children:r(s.Menu.Item,{icon:r(M.IconRecycle,{size:14,color:"red"}),disabled:!a,onClick:i,children:"Revert Changes"})})]})]})}),L1=k.observer(({saveDashboardChanges:t,headerSlot:e=null})=>{const n=ju.useNavigate(),i=ee(),a=()=>{n(`/dashboard/${i.id}`)},o=Ee.useModals(),l=()=>{o.openConfirmModal({title:d(s.Group,{position:"left",children:[r(M.IconAlertTriangle,{size:18,color:"red"}),r(s.Text,{children:"There are unsaved changes"})]}),labels:{confirm:"Discard",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:a,zIndex:320,withCloseButton:!1})},u=i.content.changed;return r(s.Header,{height:60,px:"md",py:0,sx:{zIndex:299},children:d(s.Group,{position:"apart",sx:{height:60,minWidth:"1000px",position:"relative"},children:[d(s.Group,{children:[r(s.Button,{size:"xs",color:u?"red":"green",leftIcon:r(M.IconArrowLeft,{size:20}),onClick:u?l:a,children:d(s.Group,{spacing:4,children:["End Editing",r(s.Text,{td:"underline",children:i.name})]})}),r(P1,{saveDashboardChanges:t})]}),d(s.Group,{position:"right",sx:{flexGrow:1},children:[e,r(E1,{})]})]})})}),B1={position:"fixed",top:60,left:0,right:0,height:30,zIndex:299,borderBottom:"1px solid #e9ecef",background:"rgba(233,236,239, 0.15)"},O1=k.observer(()=>{var n;const t=H(),e=((n=t.views.VIE)==null?void 0:n.type)===$.Tabs;return r(s.Box,{sx:B1,pl:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},children:d(s.Group,{position:"apart",align:"center",sx:{height:"30px"},pr:16,children:[r(s.Button,{variant:"outline",color:"blue",radius:0,size:"xs",disabled:!t.views.VIE||e,onClick:()=>t.addANewPanel(t.views.idOfVIE),leftIcon:r(M.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"}),r(s.Box,{}),r(s.Box,{})]})})}),$1=k.observer(t=>d(z,{children:[r(L1,{...t}),r(O1,{})]})),TI="";function V1(t,e,n){const i=[];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:p}=a.viz.conf;Object.entries(c).forEach(([h,f])=>{const{schemaRef:g,data:b}=f,{config:w}=b;switch(g){case"builtin:op:open-link":let _=w.urlTemplate.substring(0,100);w.urlTemplate.length>=20&&(_+="..."),l.type="interaction",l.data.interactions.push({schemaRef:g,urlTemplate:w.urlTemplate,shortURLTemplate:_});return;case"builtin:op:open_view":i.push({id:`OPERATION--${h}`,source:a.id,target:w.viewID,label:"Open View",style:{stroke:"rgba(0,0,0,0.8)"},type:"default"});return;case"builtin:op:set_filter_values":l.type="interaction",l.data.interactions.push({schemaRef:g,filters:Object.keys(w.dictionary).map(D=>({key:D,label:n[D]}))});return;case"builtin:op:clear_filter_values":l.type="interaction",l.data.interactions.push({schemaRef:g,filters:w.filter_keys.map(D=>({key:D,label:n[D]}))});return;default:return}})}),i}function N1(t,e){const n=t.filters.keyLabelMap;return{edges:V1(t.panels.list,e,n),edgeNodes:[]}}function gl(t,e,n){return t*e+t*n}function q1(t,e,n){return t*e+(t-1)*n}const Un=25,Ti=40,ml=25,Di=350,G1=150,F1=150,yl=150,bl=300,Kn=40,vl=25,j1=300;function W1(t,e){const n=x.keyBy(e,a=>a.id),i=[];return t.current.forEach((a,o)=>{a.panelIDs.forEach((l,u)=>{const c=gl(u,Kn,vl)+Ti,p=n[l];if(!p){i.push({id:l,_node_type:"panel",parentNode:a.id,data:{label:`!: ${l}`},position:{x:Un,y:c},sourcePosition:we.Position.Right,targetPosition:we.Position.Left,style:{width:bl,height:Kn}});return}const h=p.name;i.push({id:p.id,_node_type:"panel",parentNode:a.id,data:{label:h},position:{x:Un,y:c},sourcePosition:we.Position.Right,targetPosition:we.Position.Left,style:{width:bl,height:Kn}})})}),i}const R1={[$.Division]:"Div",[$.Modal]:"Modal",[$.Tabs]:"Tabs"},Q1=rl;function U1(t){return t.current.map((n,i)=>{const a=q1(n.panelIDs.length,Kn,vl)+Ti+ml;let o=[];return n.type===$.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:`${R1[n.type]}:${n.name}`},position:{x:0,y:0},sourcePosition:we.Position.Right,targetPosition:we.Position.Left,className:"light",style:{backgroundColor:Q1[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!==$.Tabs||n._tab_view_ids.forEach(i=>{e[i].parentNode=n.id})})}function Y1(t){const e=U1(t.views);K1(e);const n=W1(t.views,t.panels.list);return[...e,...n]}function X1({nodeMap:t,nodes:e,edges:n}){e.forEach(i=>{i._node_type!=="view-root"||i._view_type!==$.Tabs||(i.sourcePosition=we.Position.Bottom,i.style.width=Di+Un*2,i.style.height=ml+i._tab_view_ids.reduce((a,o)=>{const l=t[o];l.position.y=a,l.position.x=Un;const u=l.style.height;return a+u+20},Ti))})}function J1({nodeMap:t,nodes:e,edges:n}){n.filter(i=>i.label==="Open View").forEach(i=>{const a=t[i.source],o=t[i.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((i,a)=>i._node_type==="view-root"&&a._node_type==="view-root"?i._view_level-a._view_level:i._node_type!=="view-root"&&a._node_type!=="view-root"?0:i._node_type==="view-root"?-1:1)}function Z1({nodeMap:t,nodes:e,edges:n}){const i={};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,p=Number(x.get(l,"style.height",0)),h=Number(u.style.width);l.position.x=c+h+j1,u._view_level===0&&l._sub_view_ids.length===0&&(o.sourcePosition=we.Position.Left,l.targetPosition=we.Position.Right,l.position.x*=-1);const g=l.position.x,b=x.get(i,g,0);l.position.y=b,i[g]=b+p+yl}})}function H1({nodeMap:t,nodes:e,edges:n}){const i=new Set,a=new Set;n.forEach(l=>{i.add(l.source),a.add(l.target)}),e.filter(l=>l._node_type!=="view-root"||l.id==="Main"||l.parentNode?!1:!i.has(l.id)&&!a.has(l.id)).forEach((l,u)=>{l.position.x=gl(u,Di,F1),l.position.y=0-G1-yl})}function ek({nodeMap:t,nodes:e,edges:n}){const i={nodeMap:t,nodes:e,edges:n};return H1(i),J1(i),X1(i),Z1(i),{nodes:e,edges:n}}function tk(t){const e=Y1(t),n=x.keyBy(e,c=>c.id),{edges:i,edgeNodes:a}=N1(t,n),o=[...e,...a],l=x.keyBy(o,c=>c.id),u={edges:x.uniqBy(i,c=>c.id),nodes:o,nodeMap:l};return ek(u)}const DI="",Ii={"builtin:op:open-link":r(s.ThemeIcon,{color:"blue",size:20,radius:"xl",children:r(M.IconCircleDashed,{size:14})}),"builtin:op:set_filter_values":r(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:r(M.IconCircleDot,{size:14})}),"builtin:op:clear_filter_values":r(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:r(M.IconCircleOff,{size:14})})};function nk(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:d(s.Group,{spacing:4,children:[r(s.Text,{children:"Open: "}),r(s.Text,{color:"dimmed",children:n.shortURLTemplate})]})});return;case"builtin:op:set_filter_values":n.filters.forEach(({key:i,label:a})=>{e.push({key:n.schemaRef+i,icon:Ii[n.schemaRef],text:r(s.Group,{spacing:4,children:d(s.Text,{children:["Set Filter: ",a]})})})});return;case"builtin:op:clear_filter_values":n.filters.forEach(({key:i,label:a})=>{e.push({key:n.schemaRef+i,icon:Ii[n.schemaRef],text:r(s.Group,{spacing:4,children:d(s.Text,{children:["Clear Filter: ",a]})})})});return}}),e}const rk=m.memo(({data:t,isConnectable:e,sourcePosition:n=we.Position.Right,targetPosition:i=we.Position.Left,...a})=>{const o=m.useMemo(()=>nk(t.interactions),[t.interactions]);return d(z,{children:[r(we.Handle,{type:"target",position:i,isConnectable:e}),r(s.Box,{sx:{position:"absolute",top:0,right:0},children:r(T.ChevronsUpRight,{size:12})}),d(s.HoverCard,{shadow:"xl",withinPortal:!0,children:[r(s.HoverCard.Target,{children:r(s.Text,{children:t.label})}),r(s.HoverCard.Dropdown,{children:r(s.List,{spacing:"xs",size:"sm",center:!0,children:o.map(l=>r(s.List.Item,{icon:l.icon,children:l.text},l.key))})})]}),r(we.Handle,{type:"source",position:n,isConnectable:e})]})}),II="",ik={interaction:rk},ak=k.observer(()=>{const t=ue(),{edges:e,nodes:n}=tk(t);return d(we,{nodes:n,edges:e,onNodesChange:x.noop,onEdgesChange:x.noop,onConnect:x.noop,className:"interactions-viewer",fitView:!0,nodeTypes:ik,children:[r(we.MiniMap,{}),r(we.Controls,{}),r(we.Background,{})]})}),sk=k.observer(({opened:t,close:e})=>r(s.Modal,{size:"96vw",opened:t,onClose:e,title:"Interactions",trapFocus:!0,onDragStart:n=>{n.stopPropagation()},styles:{body:{height:"calc(90vh - 54px)"},content:{transform:"none !important"}},zIndex:300,children:r(ak,{})})),ok={"> 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 lk({onClick:t,name:e,active:n,openSettings:i}){return d(s.Box,{sx:{position:"relative"},children:[r(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:r(s.Group,{sx:{width:"calc(100% - 28px)"},onClick:t,children:r(s.Text,{size:"sm",children:e})})}),n&&r(s.Tooltip,{label:"Edit",position:"right",withinPortal:!0,children:r(s.ActionIcon,{onClick:i,variant:"light",color:"blue",sx:{position:"absolute",top:0,bottom:0,height:"100%",right:0,zIndex:0,borderRadius:0},children:r(M.IconAdjustments,{size:16})})})]})}const uk=k.observer(()=>{const t=ee(),e=H(),n=m.useCallback(a=>()=>e.views.setIDOfVIE(a),[e]),i=a=>{t.editor.open(["_VIEWS_",a])};return d(s.Box,{sx:{position:"relative"},children:[e.views.options.map(a=>r(lk,{active:e.views.idOfVIE===a.value,name:a.label,onClick:n(a.value),openSettings:()=>i(a.value)},a.value)),r(s.Divider,{variant:"dashed"}),r(s.Button,{variant:"subtle",rightIcon:r(M.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"})]})}),ck=k.observer(()=>{const t=ee(),e=H(),n=()=>{if(!e.queries.firstID){t.editor.open(["_QUERIES_",""]);return}t.editor.open(["_QUERIES_",e.queries.firstID])},i=()=>{if(!e.filters.firstID){t.editor.open(["_FILTERS_",""]);return}t.editor.open(["_FILTERS_",e.filters.firstID])},[a,o]=m.useState(!1),l=()=>o(!0),u=()=>o(!1);return d(s.Navbar,{p:0,width:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},zIndex:299,children:[d(s.Navbar.Section,{children:[d(s.Group,{grow:!0,spacing:0,sx:{...ok,button:{borderWidth:0,borderBottomWidth:1,borderColor:"#e9ecef"}},children:[r(s.Tooltip,{label:"Filters",withinPortal:!0,children:r(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:i,children:r(M.IconFilter,{size:18})})}),r(s.Tooltip,{label:"Queries",withinPortal:!0,children:r(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:n,children:r(M.IconDatabase,{size:18})})}),r(s.Tooltip,{label:"Interactions Viewer",withinPortal:!0,children:r(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:l,children:r(M.IconLink,{size:18})})})]}),r(sk,{opened:a,close:u})]}),r(s.Navbar.Section,{py:5,sx:{borderBottom:"1px solid #eee"},children:r(s.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Views"})}),r(s.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:r(uk,{})}),r(s.Navbar.Section,{children:r(s.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:r(s.Button,{size:"xs",leftIcon:r(M.IconSettings,{size:20}),onClick:()=>t.editor.open([]),children:"Settings"})})})]})}),dk=k.observer(function({config:e}){return d(z,{children:[r(s.Checkbox,{checked:e.default_value,onChange:n=>e.setDefaultValue(n.currentTarget.checked),label:"Default Checked"}),r(Hr,{label:"Description",value:e.description,onChange:e.setDescription,styles:{root:{flexGrow:1,minHeight:"400px"}}})]})}),pk=[{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"}],hk=k.observer(function({config:e}){return d(z,{children:[d(s.Group,{children:[r(s.Checkbox,{checked:e.required,onChange:n=>e.setRequired(n.currentTarget.checked),label:"Required"}),r(s.Checkbox,{checked:e.clearable,onChange:n=>e.setClearable(n.currentTarget.checked),disabled:e.max_days>0,label:"Clearable"}),r(s.Checkbox,{checked:e.allowSingleDateInRange,onChange:n=>e.setAllowSingleDateInRange(n.currentTarget.checked),label:"Allow choosing 1 day"})]}),r(s.Select,{data:pk,label:"Display Format",value:e.inputFormat,onChange:e.setInputFormat}),r(co,{label:"Default Value",config:e,value:e.default_value,onChange:e.setDefaultValue}),r(s.NumberInput,{label:"Max Days",description:d(s.Group,{position:"apart",children:[r(s.Text,{children:"Set 0 to disable."}),d(s.Group,{spacing:4,children:[r(s.Text,{children:"This feature requires"}),r(s.Text,{color:"blue",children:"Clearable"}),r(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=ee(),i=H(),a=m.useMemo(()=>i.queries.options,[i.queries.current]),o=a.length===0,l=u=>{n.editor.setPath(["_QUERIES_",u])};return r(s.Select,{label:d(s.Group,{position:"apart",children:[r(s.Text,{children:"Use query data as options"}),t&&r(s.Button,{size:"xs",leftIcon:r(M.IconArrowCurveRight,{size:16}),variant:"subtle",color:"blue",onClick:()=>l(t),children:"Open this query"})]}),data:a,value:t,onChange:e,allowDeselect:!1,clearable:!0,sx:{flexGrow:1},disabled:o,error:o?"You need to add a query in Data Settings":void 0,styles:{label:{display:"block"}}})}),fk=`
|
|
444
444
|
// row
|
|
445
445
|
{
|
|
446
446
|
label: string;
|
|
447
447
|
value: string;
|
|
448
448
|
description?: string; // optional
|
|
449
449
|
}
|
|
450
|
-
`,
|
|
450
|
+
`,xl=()=>{const[t,e]=m.useState(!1);return d(z,{children:[r(s.Button,{variant:"subtle",compact:!0,onClick:()=>e(n=>!n),children:t?"Close":"Click to see expected data structure"}),r(s.Collapse,{in:t,children:r(gt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:fk})})]})},gk=k.observer(function({config:e}){const n=()=>{e.addStaticOption({label:"",value:""})},i=e.static_options,a=[...i];return d(z,{children:[r(s.Checkbox,{checked:e.required,onChange:o=>e.setRequired(o.currentTarget.checked),label:"Required"}),r(s.TextInput,{label:"Width",description:"At least 160px",value:e.min_width,onChange:o=>e.setMinWidth(o.currentTarget.value),placeholder:"default: 200px"}),r(s.Divider,{label:"Configure options",labelPosition:"center"}),d(s.Stack,{spacing:10,sx:{position:"relative",minHeight:"50px"},children:[e.usingQuery&&d(z,{children:[r(s.Overlay,{opacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),r(s.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:r(s.Text,{color:"white",size:16,children:"Using query"})})]}),i.length>0&&r(s.MultiSelect,{label:"Default Selection",data:a,value:[...e.default_value],onChange:e.setDefaultValue}),i.map((o,l)=>d(s.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[r(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}}),r(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}}),r(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>e.removeStaticOption(l),sx:{position:"absolute",top:28,right:5},children:r(T.Trash,{size:16})})]},l)),r(s.Button,{mt:10,size:"xs",color:"blue",leftIcon:r(T.PlaylistAdd,{size:20}),onClick:n,sx:{width:"50%"},mx:"auto",children:"Add an Option"})]}),r(s.Divider,{label:"Or fetch options from database",labelPosition:"center"}),r(s.NumberInput,{value:e.default_selection_count,onChange:e.setDefaultSelectionCount,label:"Select first N options by default"}),r(Mi,{value:e.options_query_id,onChange:e.setOptionsQueryID}),r(xl,{})]})}),mk=k.observer(function({config:e}){const n=()=>{e.addStaticOption({label:"",value:""})},i=e.static_options,a=[{label:"No default selection",value:""},...i];return d(z,{children:[r(s.Checkbox,{checked:e.required,onChange:o=>e.setRequired(o.currentTarget.checked),label:"Required"}),r(s.TextInput,{label:"Width",value:e.width,onChange:o=>e.setWidth(o.currentTarget.value),placeholder:"200px"}),r(s.Divider,{label:"Configure options",labelPosition:"center"}),d(s.Stack,{spacing:10,sx:{position:"relative",minHeight:"50px"},children:[e.usingQuery&&d(z,{children:[r(s.Overlay,{opacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),r(s.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:r(s.Text,{color:"white",size:16,children:"Using query"})})]}),i.length>0&&r(s.Select,{label:"Default Selection",data:a,value:e.default_value,onChange:e.setDefaultValue}),i.map((o,l)=>d(s.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[r(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}}),r(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}}),r(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>e.removeStaticOption(l),sx:{position:"absolute",top:28,right:5},children:r(T.Trash,{size:16})})]},l)),r(s.Button,{size:"xs",color:"blue",leftIcon:r(T.PlaylistAdd,{size:20}),onClick:n,sx:{width:"50%"},mx:"auto",children:"Add an Option"})]}),r(s.Divider,{label:"Or fetch options from database",labelPosition:"center"}),r(s.Checkbox,{checked:e.default_selection_count===1,onChange:o=>e.setDefaultSelectionCount(o.currentTarget.checked?1:0),label:"Select the first option by default"}),r(Mi,{value:e.options_query_id,onChange:e.setOptionsQueryID}),r(xl,{})]})}),yk=k.observer(function({config:e}){return d(z,{children:[r(s.TextInput,{label:"Default Value",value:e.default_value,onChange:n=>{e.setDefaultValue(n.currentTarget.value)}}),r(s.Checkbox,{checked:e.required,onChange:n=>e.setRequired(n.currentTarget.checked),label:"Required"})]})}),bk=`
|
|
451
451
|
// row
|
|
452
452
|
{
|
|
453
453
|
label: string;
|
|
@@ -455,7 +455,7 @@ Check the top-level render call using <`+V+">.")}return z}}function Ou(S,z){{if(
|
|
|
455
455
|
parent_value: string;
|
|
456
456
|
description?: string;
|
|
457
457
|
}
|
|
458
|
-
`,kk=()=>{const[e,t]=m.useState(!1);return p(B,{children:[i(s.Button,{variant:"subtle",compact:!0,onClick:()=>t(n=>!n),children:e?"Close":"Click to see expected data structure"}),i(s.Collapse,{in:e,children:i(Mt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:_k})})]})},Tk=k.observer(function({config:t}){return p(B,{children:[i(s.Checkbox,{checked:t.required,onChange:n=>t.setRequired(n.currentTarget.checked),label:"Required"}),i(s.TextInput,{label:"Min-width",value:t.min_width,onChange:n=>t.setMinWidth(n.currentTarget.value),placeholder:"200px"}),i(s.Divider,{label:"Fetch options from database",labelPosition:"center"}),i(s.Checkbox,{checked:t.treeCheckStrictly,onChange:n=>t.setTreeCheckStrictly(n.currentTarget.checked),label:"Parent and children nodes are not associated"}),i(s.NumberInput,{value:t.default_selection_count,onChange:t.setDefaultSelectionCount,label:"Select first N options by default"}),i(Yi,{value:t.options_query_id,onChange:t.setOptionsQueryID}),i(kk,{})]})}),Dk=k.observer(function({filter:t}){return p(s.Box,{sx:{maxWidth:"480px"},children:[i(s.Text,{pt:"0",pb:"md",color:"gray",children:"Config"}),i(Mt.Prism,{mt:22,language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(t,null,4)})]})}),Ik={select:Ck,"multi-select":wk,"tree-select":Tk,"text-input":Sk,checkbox:yk,"date-range":vk},Mk=[{label:"Select",value:"select"},{label:"Multi Select",value:"multi-select"},{label:"Tree Select",value:"tree-select"},{label:"Text Input",value:"text-input"},{label:"Checkbox",value:"checkbox"},{label:"Date Range",value:"date-range"}],Ak=k.observer(function({filter:t}){const n=le(),r=m.useMemo(()=>Ik[t.type],[t.type]);return p(s.Group,{grow:!0,spacing:20,align:"top",children:[p(s.Box,{sx:{maxWidth:"600px"},children:[i(s.Text,{pb:"md",color:"gray",children:"Edit"}),p(s.Stack,{children:[p(s.Group,{noWrap:!0,children:[i(s.NumberInput,{label:"Placement Order",required:!0,value:t.order,onChange:t.setOrder,hideControls:!0,sx:{flexGrow:"1 !important"}}),t.auto_submit_supported&&i(s.Checkbox,{label:"Submit automatically",checked:t.auto_submit,onChange:a=>t.setAutoSubmit(a.currentTarget.checked),mt:22})]}),i(s.MultiSelect,{label:"Visible in...",data:n.views.options,value:[...t.visibleInViewsIDs],onChange:t.setVisibleInViewsIDs}),i(s.TextInput,{label:"Key",placeholder:"A unique key to refer",required:!0,value:t.key,onChange:a=>{t.setKey(a.currentTarget.value)}}),i(s.TextInput,{label:"Label",placeholder:"Label for this field",required:!0,value:t.label,onChange:a=>{t.setLabel(a.currentTarget.value)}}),i(s.Select,{label:"Widget",data:Mk,required:!0,value:t.type,onChange:t.setType}),i(r,{config:t.config})]})]}),i(Dk,{filter:t})]})}),zk=k.observer(({id:e})=>{const t=Fe.useModals(),n=ue(),r=le();if(e==="")return null;const a=r.filters.findByID(e);if(!a)return p(s.Text,{size:14,children:["Filter by ID[",e,"] is not found"]});const o=()=>{n.editor.setPath(["_FILTERS_",""])},l=()=>{t.openConfirmModal({title:"Delete this filter?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.filters.removeByID(e),o()},confirmProps:{color:"red"},zIndex:320})};return p(s.Stack,{sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",pb:30,children:[i(s.Group,{position:"right",pt:10,children:i(s.Button,{size:"xs",color:"red",leftIcon:i(I.Trash,{size:16}),onClick:l,children:"Delete this filter"})}),i(s.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:i(Ak,{filter:a})})]})}),Ek=k.observer(()=>{const e=le(),[t,n]=m.useState(()=>JSON.stringify(e.mock_context.current,null,4)),r=()=>{try{e.mock_context.replace(JSON.parse(t))}catch(o){Tn.showNotification({title:"Failed",message:o.message,color:"red"})}},a=m.useMemo(()=>{try{return JSON.stringify(JSON.parse(t))!==JSON.stringify(e.mock_context.current)}catch{return!1}},[t,e.mock_context.current]);return p(s.Stack,{sx:{border:"1px solid #eee",borderLeft:"none",borderRight:"none",flexGrow:1,maxWidth:"unset"},children:[i(s.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:i(s.Text,{weight:500,children:"Mock Context"})}),p(s.Group,{grow:!0,px:"md",pb:"md",pt:0,sx:{flexGrow:1,position:"relative",alignItems:"flex-start"},children:[p(s.Stack,{spacing:10,sx:{maxWidth:"unset !important"},children:[i(s.Text,{children:"A valid json string is required"}),i(s.JsonInput,{validationError:"Invalid json",formatOnBlur:!0,autosize:!0,minRows:30,value:t,onChange:n,sx:{flexGrow:1}})]}),i(s.ActionIcon,{mr:5,variant:"filled",color:"blue",sx:{position:"absolute",right:12,top:0},disabled:!a,onClick:r,children:i(I.DeviceFloppy,{size:20})})]})]})}),$k=k.observer(()=>{const{panel:e}=Qe();return i(mi,{label:"Description",value:e.description,onChange:e.setDescription,styles:{root:{flexGrow:1}}})}),Lk=k.observer(()=>{const{panel:e}=Qe(),{style:t}=e;return p(B,{children:[i(s.Divider,{mb:-10,label:"Style",labelPosition:"center",variant:"dashed"}),p(s.Stack,{spacing:20,children:[p(s.Group,{grow:!0,align:"top",children:[i(s.NumberInput,{label:"Width",min:1,max:36,step:1,precision:0,rightSection:i(s.Text,{size:12,children:"of 36 columns"}),styles:{rightSection:{width:"110px"}},value:e.layout.w,onChange:n=>{n&&e.layout.setWidth(n)}}),i(s.NumberInput,{label:"Height",rightSection:i(s.Text,{size:12,children:"px"}),styles:{rightSection:{width:"40px"}},value:e.layout.h,onChange:n=>{n&&e.layout.setHeight(n)}})]}),i(s.Checkbox,{ml:6,label:"Border",checked:t.border.enabled,onChange:n=>t.border.setEnabled(n.currentTarget.checked)})]})]})}),Pk=()=>p("span",{className:"mantine-103svbs mantine-InputWrapper-required mantine-Select-required","aria-hidden":"true",children:[" ","*"]}),Ok=k.observer(()=>{const{panel:e}=Qe(),{name:t}=e,[n,r]=_e.useInputState(t),a=t!==n,o=m.useCallback(()=>{a&&e.setName(n)},[a,n]);m.useEffect(()=>{r(t)},[t]);const l=!n.trim();return p(s.Stack,{spacing:4,children:[p(s.Group,{align:"center",children:[p(s.Text,{size:14,fw:500,children:["Panel Name",i(Pk,{})]}),i(s.ActionIcon,{variant:"subtle",color:"blue",disabled:!a||l,onClick:o,children:i(E.IconDeviceFloppy,{size:18})})]}),i(s.TextInput,{value:n,onChange:r,required:!0})]})}),Bk=k.observer(()=>{const{panel:e}=Qe();return i(s.Stack,{spacing:6,mb:10,children:p(s.Group,{pl:6,position:"left",spacing:20,children:[i(s.Checkbox,{size:"sm",checked:e.title.show,onChange:t=>e.title.setShow(t.currentTarget.checked),label:"Show Title",sx:{userSelect:"none"}}),i(s.Checkbox,{size:"sm",checked:!0,disabled:!0,label:"Use name as title"})]})})});function Vk(){return p(s.Stack,{sx:{height:"100%"},children:[i(Lk,{}),i(s.Divider,{label:"Info",labelPosition:"center",variant:"dashed"}),i(Ok,{}),i(Bk,{}),i($k,{})]})}const Nk={width:"fit-content",minWidth:"100%",tableLayout:"fixed",tr:{width:"fit-content"},th:{position:"relative"},"th, td":{wordBreak:"break-word"},".resizer":{position:"absolute",right:0,top:"50%",transform:"translateY(-50%)",cursor:"col-resize",userSelect:"none",touchAction:"none"},".resizer.isResizing":{color:"#228be6",opacity:"1"},"@media (hover: hover)":{".resizer":{opacity:"0"},"*:hover > .resizer":{color:"#228be6",opacity:"1"}}};function gu({data:e}){const t=m.useMemo(()=>{if(!Array.isArray(e)||e.length===0)return[];const r=et.createColumnHelper();return Object.keys(e[0]).map(a=>r.accessor(a,{cell:o=>o.getValue()}))},[e]),n=et.useReactTable({data:e,columns:t,columnResizeMode:"onChange",getCoreRowModel:et.getCoreRowModel()});return e.length===0?i(s.Box,{sx:{height:"5em"}}):i(Ee,{children:p(s.Table,{sx:Nk,children:[i("thead",{children:n.getHeaderGroups().map(r=>i("tr",{children:r.headers.map(a=>p("th",{style:{width:a.getSize()},children:[a.isPlaceholder?null:et.flexRender(a.column.columnDef.header,a.getContext()),i(s.ActionIcon,{onMouseDown:a.getResizeHandler(),onTouchStart:a.getResizeHandler(),className:`resizer ${a.column.getIsResizing()?"isResizing":""}`,children:i(I.ArrowBarToRight,{})})]},a.id))},r.id))}),i("tbody",{children:n.getRowModel().rows.map(r=>i("tr",{children:r.getVisibleCells().map(a=>i("td",{children:i(Ee,{children:et.flexRender(a.column.columnDef.cell,a.getContext())})},a.id))},r.id))})]})})}const qk=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],Fk={icon:{width:"80px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"80px"}}},Gk=({data:e,page:t,setPage:n,limit:r,setLimit:a})=>{const o=e.length,l=Math.ceil(o/r),u=d=>{n(1),a(Number(d))};if(o===0)return null;const c=l===1&&o<=10;return p(s.Group,{pt:10,px:10,position:"apart",children:[p(s.Group,{position:"left",children:[l>1&&i(s.Pagination,{size:"sm",value:t,onChange:n,total:l,withEdges:l>7,styles:{control:{height:"30px"}}}),!c&&i(s.Select,{icon:i(s.Text,{ta:"center",color:"dimmed",size:14,children:"Page Size"}),size:"xs",styles:Fk,data:qk,value:String(r),onChange:u})]}),i(s.Group,{position:"right",children:p(s.Text,{color:"dimmed",my:0,size:14,children:["Total ",o," rows"]})})]})},Wk=({data:e,loading:t})=>{const[n,r]=m.useState(1),[a,o]=m.useState(20),l=m.useMemo(()=>{const u=(n-1)*a,c=u+a;return e.slice(u,c)},[e,n,a]);return p(Ee,{children:[i(Gk,{data:e,page:n,setPage:r,limit:a,setLimit:o}),p(s.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[i(s.LoadingOverlay,{visible:t,overlayBlur:2}),i(gu,{data:l})]})]})},jk=({queryID:e})=>{const t=ye(),{state:n,error:r}=t.getDataStuffByID(e),a=m.useMemo(()=>t.queries.findByID(e),[t,e]);return n==="loading"?null:r?i(s.Text,{mt:10,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:r}):a!=null&&a.stateMessage?i(s.Text,{mt:10,color:"gray",align:"center",children:a.stateMessage}):null},Qi=k.observer(({id:e,moreActions:t,refreshOnMount:n})=>{const r=ye(),{data:a,state:o}=r.getDataStuffByID(e),l=o==="loading",u=m.useCallback(()=>{r.queries.refetchDataByQueryID(e)},[e,r]),c=()=>{r.queries.downloadDataByQueryID(e)};m.useEffect(()=>{n&&u()},[u,n]);const d=!Array.isArray(a)||a.length===0;return p(s.Stack,{spacing:0,sx:{height:"100%",border:"1px solid #eee"},children:[p(s.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Group,{position:"left",children:i(s.Text,{weight:500,children:"Preview Data"})}),p(s.Group,{pr:15,children:[t,i(s.ActionIcon,{variant:"subtle",color:"blue",disabled:l,onClick:u,children:i(I.Refresh,{size:16})}),i(s.ActionIcon,{variant:"subtle",color:"blue",disabled:l||d,onClick:c,children:i(I.Download,{size:16})})]})]}),p(s.Box,{pb:20,sx:{position:"relative",flexGrow:1,overflow:"auto"},children:[i(jk,{queryID:e}),i(Wk,{data:a,loading:l})]})]})}),Rk=k.observer(function(){const t=ue(),n=le(),{panel:r}=Qe(),[a,o]=m.useState(!1),l=u=>{t.editor.setPath(["_QUERIES_",u])};return p(B,{children:[i(s.Drawer,{opened:a,onClose:()=>o(!1),title:"Choose queries",padding:"xl",size:500,zIndex:320,children:i(s.Checkbox.Group,{value:[...r.queryIDs],onChange:r.setQueryIDs,children:i(s.Stack,{spacing:"lg",children:n.queries.options.map(u=>i(s.Checkbox,{label:u.label,value:u.value},u.value))})})}),p(s.Stack,{spacing:6,children:[i(s.Group,{position:"right",children:i(s.Button,{variant:"light",size:"sm",leftIcon:i(E.IconLine,{size:16}),onClick:()=>o(!0),children:"Click me to choose queries for this panel"})}),r.queryIDs.length===1&&i(Qi,{id:r.queryIDs[0],moreActions:i(s.Tooltip,{label:"Open this query",children:i(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>l(r.queryIDs[0]),children:i(E.IconArrowCurveRight,{size:16})})})}),r.queryIDs.length>1&&p(s.Tabs,{defaultValue:r.queryIDs[0],children:[i(s.Tabs.List,{children:r.queries.map(u=>i(s.Tabs.Tab,{value:u.id,children:u.name},u.id))}),r.queries.map(u=>i(s.Tabs.Panel,{value:u.id,children:i(Qi,{id:u.id,moreActions:i(s.Tooltip,{label:"Open this query",children:i(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>l(u.id),children:i(E.IconArrowCurveRight,{size:16})})})})},u.id))]})]})]})}),Yk=k.observer(()=>{const{panel:e}=Ct();return i(Ee,{children:i(s.Box,{sx:{height:"100%",flexGrow:0,flexShrink:0,width:"600px"},children:p(s.Stack,{mt:24,spacing:5,sx:{width:"600px",height:"450px",background:"transparent",borderRadius:"5px",border:"1px solid #e9ecef",borderWidth:e.style.border.enabled?"1px":"0px"},children:[p(s.Group,{position:"apart",noWrap:!0,sx:{flexGrow:0,flexShrink:0},children:[i(s.Group,{children:i(Bi,{})}),i(s.Group,{grow:!0,position:"center",children:i(s.Text,{lineClamp:1,weight:"bold",children:e.title.show?e.name:""})}),i(s.Group,{position:"right",spacing:0,sx:{height:"28px"}})]}),i(s.Group,{px:5,pb:5,sx:{flexGrow:1,".panel-viz-section":{height:"calc(100% - 28px)"}},children:i(Vi,{panel:e})})]})})})}),Ui={name:"new_var",size:"1rem",weight:"initial",color:{type:"static",staticColor:"Red"},data_field:"",aggregation:{type:"sum",config:{}},formatter:{output:"number",mantissa:0,trimMantissa:!1,average:!1}};class Qk{constructor(t){q(this,"panel");q(this,"selected");this.panel=t,te.makeAutoObservable(this,{},{deep:!1,autoBind:!0})}get variables(){return this.panel.variables}addNew(){const t=this.panel.variables.filter(n=>n.name.startsWith(Ui.name)).length;this.panel.addVariable(x.cloneDeep({...Ui,name:`${Ui.name}${t||""}`})),this.selected=x.last(this.panel.variables)}select(t){this.selected=t}remove(t){this.selected===t&&(this.selected=void 0);const n=this.panel.variables.indexOf(t);if(this.panel.removeVariable(t),!this.selected&&!x.isEmpty(this.panel.variables)){const r=Math.min(this.panel.variables.length-1,n);this.selected=this.panel.variables[r]}}}function Uk(){const{panel:e}=Qe();return Q.useCreation(()=>new Qk(e),[e])}const mu=s.createStyles(e=>({root:{height:"100%",overflow:"hidden",".var-list-container":{"& > *":{height:"100%"},width:250,height:"100%"},".var-list-actions":{height:"fit-content",flexShrink:0,width:"100%"},".var-list":{flex:"1 1 auto",overflow:"auto",minHeight:0,"& > *":{flex:"0 0 auto"}}},config:{height:"100%",overflow:"auto",paddingRight:10}})),Kk=m.forwardRef(function({value:t,onChange:n,data:r,withStyle:a=!0},o){const l=(u,c)=>{const d=x.cloneDeep(t);x.set(d,u,c),n(d)};return p(s.Box,{px:"sm",py:"md",ref:o,children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(s.TextInput,{label:"Name",required:!0,value:t.name,onChange:u=>l("name",u.currentTarget.value)}),i(W,{label:"Data Field",required:!0,value:t.data_field,onChange:u=>l("data_field",u)})]}),i(Un,{label:"Aggregation",value:t.aggregation,onChange:u=>l("aggregation",u)}),t.aggregation.type!=="custom"&&p(B,{children:[i(s.Divider,{my:"xs",label:"Format",labelPosition:"center"}),i(Ge,{value:t.formatter,onChange:u=>l("formatter",u)})]}),a&&i(oo,{value:t,onChange:n})]})}),Xk=e=>{const{uiModel:t}=e;return i(s.Stack,{className:"var-list",children:t.variables.map(n=>i(s.Button,{variant:t.selected===n?"filled":"subtle",color:"gray",onClick:()=>t.select(n),children:n.name},n.name))})},Jk=k.observer(Xk),Zk=({variable:e,data:t})=>i(s.Group,{style:{minHeight:0,height:"calc(100% - 68px)"},children:i(s.Paper,{withBorder:!0,p:"md",children:lo(e,t)})}),Hk=k.observer(Zk),eT=e=>{const t=Q.useCreation(()=>RS(e.variable),[e.variable]),{classes:n}=mu(),{data:r}=Qe();return p(s.Group,{style:{height:"100%"},align:"start",children:[p(s.Stack,{"data-testid":"variable-editor",align:"stretch",className:n.config,children:[p(s.Group,{position:"right",children:[i(s.ActionIcon,{variant:"filled",disabled:!t.changed,color:"primary",onClick:t.commit,children:i(E.IconDeviceFloppy,{size:18})}),i(s.ActionIcon,{color:"red",onClick:()=>e.uiModel.remove(e.variable),children:i(E.IconTrash,{size:18})})]}),i(Kk,{value:b.getSnapshot(t.copy),onChange:t.update,data:r})]}),i(Hk,{variable:b.getSnapshot(t.copy),data:r})]})},tT=k.observer(eT),nT=()=>{const e=Uk(),{classes:t}=mu();return p(s.Group,{className:t.root,noWrap:!0,align:"start",children:[i(s.Paper,{withBorder:!0,p:"md",className:"var-list-container",children:p(s.Stack,{justify:"space-between",children:[i(s.Box,{className:"var-list-actions",children:i(s.Button,{variant:"light",size:"sm",onClick:e.addNew,fullWidth:!0,children:"Add Variable"})}),i(Jk,{uiModel:e})]})}),e.selected?i(B,{children:i(tT,{uiModel:e,variable:e.selected})}):i("span",{children:"Select or create a new variable on right side"})]})},rT=k.observer(nT);function iT(){const{vizManager:e}=m.useContext(ct);return m.useMemo(()=>{const t=e.availableVizList.map(n=>({value:n.name,label:n.displayName??n.name,group:n.displayGroup??""}));return x.orderBy(t,[n=>n.group,n=>n.label],["asc","asc"])},[e])}const aT=k.observer(({value:e,submit:t})=>{const[n,r]=_e.useInputState(e);m.useEffect(()=>{r(e)},[e]);const a=iT(),o=e!==n;return i(s.Select,{label:"Visualization",value:n,searchable:!0,onChange:r,data:a,rightSection:i(s.ActionIcon,{disabled:!o,onClick:()=>t(n),children:i(I.DeviceFloppy,{size:20})}),maxDropdownHeight:600})}),yu=[];function sT(e,t){try{return e.resolveComponent(t).createConfig()}catch{return null}}function oT(){const{data:e,panel:{variables:t,viz:n,title:r,name:a,queryIDs:o,description:l,id:u}}=Qe(),{vizManager:c}=m.useContext(ct),d={name:a,title:r,description:l,viz:n,queryIDs:o,id:u},f=Bl(d);try{return c.resolveComponent(d.viz.type),i(sr,{configure:f,children:i(JS,{variables:t,setVizConf:n.setConf,panel:d,vizManager:c,data:e})})}catch(h){return console.info(x.get(h,"message")),null}}const lT=k.observer(()=>{const{data:e,panel:{viz:t}}=Qe(),{vizManager:n}=m.useContext(ct),r=m.useCallback(d=>{if(d===t.type)return;const f=sT(n,d);t.setType(d),t.setConf(f||{})},[t.type]),a=d=>{try{t.setConf(JSON.parse(d))}catch(f){console.error(f)}},o=m.useMemo(()=>{var d;return(d=yu.find(f=>f.value===t.type))==null?void 0:d.Panel},[t.type,yu]),l=oT(),u=o?m.createElement(o,{data:e,conf:t.conf,setConf:t.setConf}):null,c=l||u;return p(s.Stack,{align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[i(aT,{submit:r,value:t.type}),p(Ee,{children:[i(s.Stack,{pb:10,sx:{flexGrow:1,maxHeight:"100%",overflow:"auto"},children:c}),!c&&i(s.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(t.conf,null,2),onChange:a})]})]})}),uT=k.observer(({panel:e,sourceViewID:t})=>{const n=le(),[r,a]=m.useState(t);m.useEffect(()=>{a(t)},[t]);const[o,{open:l,close:u}]=_e.useDisclosure(!1),c=()=>{e.moveToView(t,r),u()};return p(B,{children:[i(s.Button,{size:"xs",variant:"subtle",color:"blue",onClick:l,leftIcon:i(E.IconBoxMultiple,{size:14}),children:"Move into Another View"}),i(s.Modal,{opened:o,onClose:u,title:"Move panel into another view",zIndex:320,children:p(s.Stack,{sx:{maxHeight:"calc(100vh - 185px)",overflow:"hidden"},children:[i(s.Radio.Group,{value:r,onChange:a,pb:10,sx:{flexGrow:1,maxHeight:"calc(100vh - 185px - 30px)",overflow:"auto"},children:i(s.Stack,{spacing:"xs",children:n.views.options.map(d=>i(s.Radio,{value:d.value,label:d.label},d.value))})}),p(s.Group,{noWrap:!0,position:"apart",sx:{flexGrow:0,flexShrink:0},children:[i(s.Button,{size:"xs",color:"red",leftIcon:i(E.IconX,{size:14}),onClick:u,children:"Cancel"}),i(s.Button,{size:"xs",color:"blue",leftIcon:i(E.IconDeviceFloppy,{size:14}),onClick:c,disabled:r===t,children:"Confirm"})]})]})})]})}),cT={root:{flexGrow:1,width:"100%",overflow:"hidden"},panel:{width:"100%",height:"calc(100% - 44px)",padding:10,overflow:"scroll"}},bu=({children:e})=>p(s.Group,{noWrap:!0,grow:!0,position:"left",spacing:20,sx:{width:"100%",height:"100%"},children:[i(s.Box,{sx:{maxWidth:"calc(100% - 610px - 10px)",height:"100%",overflow:"auto"},children:e}),i(Yk,{})]});function dT(e){return!["richText","button"].includes(e)}const pT=k.observer(({panel:e})=>{const t=Fe.useModals(),n=ue(),r=le(),[a,o]=m.useState("Data"),l=e.queries,c=dT(e.viz.type)&&e.dataLoading,d=c||e.queryErrors.length>0||e.queryStateMessages!==""||l.length===0,f=n.editor.path[1];m.useEffect(()=>{o(y=>d&&y==="Visualization"?"Data":y)},[e.id,d]);const h=()=>{n.editor.setPath(["_VIEWS_",f])},g=()=>t.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.removePanelByID(e.id,f),h()},confirmProps:{color:"red"},zIndex:320});return p(Er,{value:{panel:e,data:e.data,loading:c,errors:e.queryErrors,downloadPanelScreenshot:()=>{}},children:[p(s.Group,{px:16,position:"apart",sx:{borderBottom:"1px solid #eee"},children:[i(s.Text,{pt:9,pb:8,children:e.name}),p(s.Group,{position:"right",noWrap:!0,children:[i(uT,{panel:e,sourceViewID:f}),i(s.Button,{size:"xs",variant:"subtle",color:"red",onClick:g,leftIcon:i(E.IconTrash,{size:14}),children:"Delete This Panel"})]})]}),p(s.Tabs,{value:a,onTabChange:o,keepMounted:!1,styles:cT,children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Data",disabled:c,children:"Data"}),i(s.Tabs.Tab,{value:"Panel",children:"Panel"}),i(s.Tabs.Tab,{value:"Variables",disabled:d,children:i(s.Tooltip,{label:"Requires data",disabled:!d,withinPortal:!0,zIndex:310,children:i(s.Text,{children:"Variables"})})}),i(s.Tabs.Tab,{value:"Visualization",disabled:d,children:i(s.Tooltip,{label:"Requires data",disabled:!d,withinPortal:!0,zIndex:310,children:i(s.Text,{children:"Visualization"})})}),i(s.Tabs.Tab,{value:"Interactions",children:"Interactions"})]}),p(s.Tabs.Panel,{value:"Data",children:[i(s.LoadingOverlay,{visible:c,exitTransitionDuration:0}),i(Rk,{})]}),i(s.Tabs.Panel,{value:"Panel",children:i(bu,{children:i(Vk,{})})}),i(s.Tabs.Panel,{value:"Variables",children:i(rT,{})}),i(s.Tabs.Panel,{value:"Visualization",children:i(Ee,{children:i(bu,{children:i(lT,{})})})}),i(s.Tabs.Panel,{value:"Interactions",children:i(Ee,{children:i(kd,{})})})]})]})}),hT=k.observer(({viewID:e,panelID:t})=>{const n=le();if(!n.views.findByID(e))return p(s.Text,{size:14,children:["View by ID[",e,"] is not found"]});const a=n.panels.findByID(t);return a?i(pT,{panel:a}):p(s.Text,{size:14,children:["Panel by ID[",t,"] is not found"]})}),fT=e=>{const{queryModel:t}=e,n=ue(),r=le(),o=r.findQueryUsage(t.id).length>0,l=Fe.useModals(),u=()=>{l.openConfirmModal({title:"Delete this query?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.queries.removeQuery(t.id),n.editor.setPath(["_QUERIES_",""])},confirmProps:{color:"red"},zIndex:320})};return o?i(s.Tooltip,{label:"Can't delete this query for it's being used, check out Usage tab for details",withArrow:!0,events:{hover:!0,focus:!1,touch:!1},withinPortal:!0,children:i(s.Button,{color:"gray",size:"xs",leftIcon:i(E.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})}):i(s.Button,{color:"red",size:"xs",onClick:u,leftIcon:i(E.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})},gT=k.observer(fT),vu=({width:e="calc(100% - 32px)",lastWidth:t="50%",height:n,count:r,spacing:a=16,pl:o=0})=>p(s.Stack,{spacing:a,mt:6,pl:o,children:[Array.from(new Array(r-1),(l,u)=>i(s.Skeleton,{width:e,height:n,radius:"xs"},u)),i(s.Skeleton,{width:t,height:n,radius:"xs"})]}),xn=({value:e})=>e===null||e===""?null:i(s.Tooltip,{label:e,disabled:!e,multiline:!0,children:i(s.ActionIcon,{children:i(E.IconInfoCircle,{size:14})})}),mT=({column:e})=>{const{column_key:t,column_key_text:n}=e;return t?i(s.Tooltip,{label:n,disabled:!n,children:i(s.Badge,{children:t})}):null},yT=k.observer(({dataSource:e})=>{const{columns:t}=e;return t.loading?i(vu,{height:"24px",width:"100%",lastWidth:"100%",count:20,pl:6}):t.empty?null:p(s.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"1000px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[i("col",{style:{width:50}}),i("col",{style:{minWidth:300}}),i("col",{style:{width:30}}),i("col",{style:{width:70}}),i("col",{style:{minWidth:300}}),i("col",{style:{minWidth:80,width:80}}),i("col",{style:{minWidth:120,width:120}})]}),i("thead",{children:p("tr",{children:[i("th",{children:"#"}),i("th",{children:"Column Name"}),i("th",{}),i("th",{}),i("th",{children:"Type"}),i("th",{children:"Nullable"}),i("th",{children:"Default Value"})]})}),i("tbody",{children:t.data.map(n=>p("tr",{children:[i("td",{children:n.ordinal_position}),i("td",{children:n.column_name}),i("td",{children:i(xn,{value:n.column_comment})}),i("td",{children:i(mT,{column:n})}),i("td",{children:n.column_type}),i("td",{children:n.is_nullable}),i("td",{children:i(xn,{value:n.column_default})})]},n.column_name))})]})}),bT=k.observer(({dataSource:e})=>{const{indexes:t}=e,n=t.data;return p(s.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"950px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[i("col",{style:{width:100}}),i("col",{style:{minWidth:300}}),i("col",{style:{width:150}}),i("col",{style:{width:150}}),i("col",{style:{width:250}})]}),i("thead",{children:p("tr",{children:[i("th",{children:"Index Length"}),i("th",{children:"Index Name"}),i("th",{children:"Index Algorithm"}),i("th",{children:"Unique"}),i("th",{children:"Column Name"})]})}),i("tbody",{children:n.map(r=>p("tr",{children:[i("td",{children:r.index_length}),i("td",{children:r.index_name}),i("td",{children:r.index_algorithm}),i("td",{children:r.is_unique?"YES":"NO"}),i("td",{children:r.column_name})]},r.index_name))})]})}),vT=k.observer(({dataSource:e})=>{const{indexes:t}=e,n=t.data;return p(s.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"850px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[i("col",{style:{minWidth:300}}),i("col",{style:{width:150}}),i("col",{style:{width:100}}),i("col",{style:{width:100}}),i("col",{style:{width:100}}),i("col",{style:{width:100}})]}),i("thead",{children:p("tr",{children:[i("th",{children:"Index Name"}),i("th",{children:"Index Algorithm"}),i("th",{children:"Unique"}),i("th",{children:"Definition"}),i("th",{children:"Condition"}),i("th",{children:"Comment"})]})}),i("tbody",{children:n.map(r=>p("tr",{children:[i("td",{children:r.index_name}),i("td",{children:r.index_algorithm}),i("td",{children:r.is_unique?"YES":"NO"}),i("td",{children:i(xn,{value:r.index_definition})}),i("td",{children:i(xn,{value:r.condition})}),i("td",{children:i(xn,{value:r.comment})})]},r.index_name))})]})}),xT=k.observer(({dataSource:e})=>{const{indexes:t}=e;return t.loading||t.empty?null:e.type===Ne.MySQL?i(bT,{dataSource:e}):e.type===Ne.Postgresql?i(vT,{dataSource:e}):null}),wT=k.observer(({dataSource:e})=>p(s.Stack,{spacing:40,pt:10,sx:{flexGrow:1,overflow:"auto",position:"relative"},children:[i(Ee,{children:i(yT,{dataSource:e})}),i(Ee,{children:i(xT,{dataSource:e})})]}));function CT({table_type:e}){return e==="VIEW"?i(E.IconEye,{size:14}):e==="BASE TABLE"?i(E.IconTable,{size:14}):null}const ST=k.observer(({dataSource:e})=>{const{tables:t}=e;return t.loading?i(vu,{height:"24px",lastWidth:"50%",count:15}):i(s.Box,{h:"100%",sx:{overflow:"auto",".mantine-NavLink-label":{fontFamily:"monospace"}},children:Object.entries(t.data).map(([n,r])=>i(s.NavLink,{label:n,icon:i(E.IconDatabase,{size:14}),defaultOpened:e.table_schema===n,pl:0,childrenOffset:14,children:r.map(a=>i(s.NavLink,{label:a.table_name,icon:i(CT,{table_type:a.table_type}),onClick:()=>{e.setKeywords(n,a.table_name)},active:e.table_name===a.table_name},a.table_name))},n))})}),_T=({visible:e})=>i(s.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:i(s.LoadingOverlay,{visible:e})}),kT=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],TT={icon:{width:"50px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"50px"}}},DT=k.observer(({dataSource:e})=>{const{tableData:t}=e;return p(s.Group,{pt:10,px:10,position:"apart",children:[p(s.Group,{position:"left",children:[t.maxPage>1&&i(s.Pagination,{size:"sm",value:t.page,onChange:t.setPage,total:t.maxPage,withEdges:t.maxPage>7,styles:{control:{height:"30px"}}}),i(s.Select,{icon:i(s.Text,{ta:"center",color:"dimmed",size:14,children:"Limit"}),size:"xs",styles:TT,data:kT,value:String(t.limit),onChange:n=>t.setLimit(Number(n))})]}),i(s.Group,{position:"right",children:p(s.Text,{color:"dimmed",my:0,size:14,children:["Total ",t.total," rows"]})})]})}),IT=k.observer(({dataSource:e})=>{const t=e.tableData;return t.maxPage===0?i(s.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:"This table is empty"}):t.error?i(s.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:t.error}):t.page===1&&t.loading?i(_T,{visible:!0}):p(Ee,{children:[i(DT,{dataSource:e}),p(s.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[i(s.LoadingOverlay,{visible:t.loading,overlayBlur:2}),i(gu,{data:t.data})]})]})}),MT={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},AT=k.observer(({dataSource:e})=>(m.useEffect(()=>{e.loadTablesIfEmpty()},[e]),e.tables.error?i(s.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:e.tables.error}):p(s.Flex,{sx:{height:"100%"},children:[i(s.Box,{w:300,sx:{flexGrow:0,flexShrink:0,position:"relative"},children:i(Ee,{children:i(ST,{dataSource:e})})}),p(s.Tabs,{defaultValue:"structure",styles:MT,children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"structure",icon:i(E.IconColumns,{size:14}),children:"Structure"}),i(s.Tabs.Tab,{value:"data",icon:i(E.IconDatabase,{size:14}),children:"Data"})]}),i(s.Tabs.Panel,{value:"structure",children:i(wT,{dataSource:e})}),i(s.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:i(IT,{dataSource:e})})]})]}))),zT={modal:{paddingLeft:"0px !important",paddingRight:"0px !important"},header:{marginBottom:0,padding:"20px 20px 10px",borderBottom:"1px solid #efefef",gap:"20px"},title:{flexGrow:1},body:{padding:"0 0 0 20px"}},xu=k.observer(({dataSource:e,triggerButtonProps:t={}})=>{const[n,r]=m.useState(!1);return e.type==="http"?null:p(B,{children:[i(s.Modal,{opened:n,onClose:()=>r(!1),title:p(s.Group,{position:"apart",sx:{flexGrow:1},children:[i(s.Text,{fw:500,children:"Explorer Data Source"}),p(s.Group,{spacing:7,children:[i(s.Badge,{variant:"gradient",gradient:{from:"indigo",to:"cyan"},children:e.key}),i(s.Badge,{variant:"gradient",gradient:{from:"orange",to:"red"},children:e.type})]})]}),zIndex:320,size:"96vw",styles:zT,children:i(s.Box,{sx:{height:"calc(100vh - 220px)"},children:i(AT,{dataSource:e})})}),i(s.Button,{variant:"subtle",onClick:()=>r(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},...t,children:"See Table Structure"})]})}),ET=m.forwardRef(({label:e,type:t,...n},r)=>p(s.Group,{position:"apart",ref:r,...n,children:[i(s.Text,{children:e}),i(s.Text,{children:t})]})),$T=k.observer(({value:e,onChange:t})=>{const n=ue(),{data:r=[],loading:a}=Q.useRequest(_r,{refreshDeps:[]},[]),o=m.useMemo(()=>r.map(d=>({label:d.key,value:d.key,type:d.type})),[r]),l=m.useMemo(()=>o.reduce((d,f)=>(d[f.value]=f.type,d),{}),[o]),u=d=>{d!==null&&t({key:d,type:l[d]})},c=m.useMemo(()=>n.datasources.find(e),[n,e]);return i(s.Select,{data:o,label:p(s.Group,{position:"apart",children:[i(s.Box,{children:"Data Source"}),c&&i(xu,{dataSource:c,triggerButtonProps:{compact:!0,size:"xs",px:10}})]}),itemComponent:ET,rightSection:c?i(s.Text,{size:"xs",color:"dimmed",children:c.type}):void 0,rightSectionWidth:85,maxDropdownHeight:280,styles:{root:{flex:1},label:{display:"block"},rightSection:{pointerEvents:"none",justifyContent:"flex-end",paddingRight:"10px",".mantine-Text-root":{userSelect:"none"}}},disabled:a,value:e.key,onChange:u})}),wu=m.forwardRef((e,t)=>{const{label:n,description:r,...a}=e;return i("div",{ref:t,...a,children:p(s.Group,{position:"apart",noWrap:!0,children:[i(s.Text,{children:n}),i(s.Text,{size:"xs",color:"dimmed",children:r})]})})}),LT=k.observer(({queryModel:e})=>{const[t,n]=m.useState(e.name);return m.useEffect(()=>{n(e.name)},[e.name]),i(s.Center,{ml:20,mt:20,sx:{maxWidth:"600px"},children:p(s.Stack,{spacing:10,sx:{width:"100%"},children:[i(s.Divider,{mb:-10,variant:"dashed",label:"Basics",labelPosition:"center"}),i(s.TextInput,{placeholder:"A unique name",label:"Name",required:!0,sx:{flex:1},value:t,onChange:r=>{n(r.currentTarget.value)},rightSection:i(s.ActionIcon,{variant:"filled",color:"blue",size:"sm",onClick:()=>e.setName(t),disabled:t===e.name,children:i(E.IconDeviceFloppy,{size:16})}),onBlur:()=>{e.setName(t)}}),i($T,{value:{type:e.type,key:e.key},onChange:({type:r,key:a})=>{e.setKey(a),e.setType(r)}}),i(s.Divider,{mt:10,mb:-10,variant:"dashed",label:"Conditions",labelPosition:"center"}),i(s.MultiSelect,{label:"Run query when these are truthy",placeholder:"Always run this query on load",data:e.conditionOptions,value:[...e.run_by],onChange:e.setRunBy,itemComponent:wu,maxDropdownHeight:500}),e.typedAsHTTP&&i(s.MultiSelect,{label:"Re-run query when these changed",placeholder:"Leave it empty to never re-run this query",data:e.conditionOptions,value:[...e.react_to],onChange:e.setReactTo,itemComponent:wu,maxDropdownHeight:500}),i(s.Divider,{mt:20,mb:10,variant:"dashed"}),i(gT,{queryModel:e})]})})});function PT({content:e}){return p(s.HoverCard,{width:"60vw",shadow:"md",children:[i(s.HoverCard.Target,{children:i(s.ActionIcon,{size:16,color:"blue",children:i(E.IconEye,{})})}),i(s.HoverCard.Dropdown,{children:i(Mt.Prism,{language:"sql",noCopy:!0,withLineNumbers:!0,children:e})})]})}const OT=k.observer(()=>{const t=[...ue().globalSQLSnippets.list];return t.length===0?null:p(s.Table,{horizontalSpacing:"xs",verticalSpacing:"xs",fontSize:"sm",highlightOnHover:!0,children:[i("thead",{children:p("tr",{children:[i("th",{children:"Key"}),i("th",{children:"Value"})]})}),i("tbody",{children:t.map(n=>{const{id:r,content:a}=n;return p("tr",{children:[i("td",{children:r}),i("td",{width:200,children:i(PT,{content:a})})]},r)})})]})}),BT=`
|
|
458
|
+
`,vk=()=>{const[t,e]=m.useState(!1);return d(z,{children:[r(s.Button,{variant:"subtle",compact:!0,onClick:()=>e(n=>!n),children:t?"Close":"Click to see expected data structure"}),r(s.Collapse,{in:t,children:r(gt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:bk})})]})},xk=k.observer(function({config:e}){return d(z,{children:[r(s.Checkbox,{checked:e.required,onChange:n=>e.setRequired(n.currentTarget.checked),label:"Required"}),r(s.TextInput,{label:"Min-width",value:e.min_width,onChange:n=>e.setMinWidth(n.currentTarget.value),placeholder:"200px"}),r(s.Divider,{label:"Fetch options from database",labelPosition:"center"}),r(s.Checkbox,{checked:e.treeCheckStrictly,onChange:n=>e.setTreeCheckStrictly(n.currentTarget.checked),label:"Parent and children nodes are not associated"}),r(s.NumberInput,{value:e.default_selection_count,onChange:e.setDefaultSelectionCount,label:"Select first N options by default"}),r(Mi,{value:e.options_query_id,onChange:e.setOptionsQueryID}),r(vk,{})]})}),wk=k.observer(function({filter:e}){return d(s.Box,{sx:{maxWidth:"480px"},children:[r(s.Text,{pt:"0",pb:"md",color:"gray",children:"Config"}),r(gt.Prism,{mt:22,language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(e,null,4)})]})}),Ck={select:mk,"multi-select":gk,"tree-select":xk,"text-input":yk,checkbox:dk,"date-range":hk},Sk=[{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"}],_k=k.observer(function({filter:e}){const n=H(),i=m.useMemo(()=>Ck[e.type],[e.type]);return d(s.Group,{grow:!0,spacing:20,align:"top",children:[d(s.Box,{sx:{maxWidth:"600px"},children:[r(s.Text,{pb:"md",color:"gray",children:"Edit"}),d(s.Stack,{children:[d(s.Group,{noWrap:!0,children:[r(s.NumberInput,{label:"Placement Order",required:!0,value:e.order,onChange:e.setOrder,hideControls:!0,sx:{flexGrow:"1 !important"}}),e.auto_submit_supported&&r(s.Checkbox,{label:"Submit automatically",checked:e.auto_submit,onChange:a=>e.setAutoSubmit(a.currentTarget.checked),mt:22})]}),r(s.MultiSelect,{label:"Visible in...",data:n.views.options,value:[...e.visibleInViewsIDs],onChange:e.setVisibleInViewsIDs}),r(s.TextInput,{label:"Key",placeholder:"A unique key to refer",required:!0,value:e.key,onChange:a=>{e.setKey(a.currentTarget.value)}}),r(s.TextInput,{label:"Label",placeholder:"Label for this field",required:!0,value:e.label,onChange:a=>{e.setLabel(a.currentTarget.value)}}),r(s.Select,{label:"Widget",data:Sk,required:!0,value:e.type,onChange:e.setType}),r(i,{config:e.config})]})]}),r(wk,{filter:e})]})}),kk=k.observer(({id:t})=>{const e=Ee.useModals(),n=ee(),i=H();if(t==="")return null;const a=i.filters.findByID(t);if(!a)return d(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:()=>{i.filters.removeByID(t),o()},confirmProps:{color:"red"},zIndex:320})};return d(s.Stack,{sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",pb:30,children:[r(s.Group,{position:"right",pt:10,children:r(s.Button,{size:"xs",color:"red",leftIcon:r(T.Trash,{size:16}),onClick:l,children:"Delete this filter"})}),r(s.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:r(_k,{filter:a})})]})}),Tk=k.observer(()=>{const t=H(),[e,n]=m.useState(()=>JSON.stringify(t.mock_context.current,null,4)),i=()=>{try{t.mock_context.replace(JSON.parse(e))}catch(o){on.showNotification({title:"Failed",message:o.message,color:"red"})}},a=m.useMemo(()=>{try{return JSON.stringify(JSON.parse(e))!==JSON.stringify(t.mock_context.current)}catch{return!1}},[e,t.mock_context.current]);return d(s.Stack,{sx:{border:"1px solid #eee",borderLeft:"none",borderRight:"none",flexGrow:1,maxWidth:"unset"},children:[r(s.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:r(s.Text,{weight:500,children:"Mock Context"})}),d(s.Group,{grow:!0,px:"md",pb:"md",pt:0,sx:{flexGrow:1,position:"relative",alignItems:"flex-start"},children:[d(s.Stack,{spacing:10,sx:{maxWidth:"unset !important"},children:[r(s.Text,{children:"A valid json string is required"}),r(s.JsonInput,{validationError:"Invalid json",formatOnBlur:!0,autosize:!0,minRows:30,value:e,onChange:n,sx:{flexGrow:1}})]}),r(s.ActionIcon,{mr:5,variant:"filled",color:"blue",sx:{position:"absolute",right:12,top:0},disabled:!a,onClick:i,children:r(T.DeviceFloppy,{size:20})})]})]})}),Dk=k.observer(()=>{const{panel:t}=$e();return r(Hr,{label:"Description",value:t.description,onChange:t.setDescription,styles:{root:{flexGrow:1}}})}),Ik=k.observer(()=>{const{panel:t}=$e(),{style:e}=t;return d(z,{children:[r(s.Divider,{mb:-10,label:"Style",labelPosition:"center",variant:"dashed"}),d(s.Stack,{spacing:20,children:[d(s.Group,{grow:!0,align:"top",children:[r(s.NumberInput,{label:"Width",min:1,max:36,step:1,precision:0,rightSection:r(s.Text,{size:12,children:"of 36 columns"}),styles:{rightSection:{width:"110px"}},value:t.layout.w,onChange:n=>{n&&t.layout.setWidth(n)}}),r(s.NumberInput,{label:"Height",rightSection:r(s.Text,{size:12,children:"px"}),styles:{rightSection:{width:"40px"}},value:t.layout.h,onChange:n=>{n&&t.layout.setHeight(n)}})]}),r(s.Checkbox,{ml:6,label:"Border",checked:e.border.enabled,onChange:n=>e.border.setEnabled(n.currentTarget.checked)})]})]})}),Mk=()=>d("span",{className:"mantine-103svbs mantine-InputWrapper-required mantine-Select-required","aria-hidden":"true",children:[" ","*"]}),Ak=k.observer(()=>{const{panel:t}=$e(),{name:e}=t,[n,i]=ye.useInputState(e),a=e!==n,o=m.useCallback(()=>{a&&t.setName(n)},[a,n]);m.useEffect(()=>{i(e)},[e]);const l=!n.trim();return d(s.Stack,{spacing:4,children:[d(s.Group,{align:"center",children:[d(s.Text,{size:14,fw:500,children:["Panel Name",r(Mk,{})]}),r(s.ActionIcon,{variant:"subtle",color:"blue",disabled:!a||l,onClick:o,children:r(M.IconDeviceFloppy,{size:18})})]}),r(s.TextInput,{value:n,onChange:i,required:!0})]})}),zk=k.observer(()=>{const{panel:t}=$e();return r(s.Stack,{spacing:6,mb:10,children:d(s.Group,{pl:6,position:"left",spacing:20,children:[r(s.Checkbox,{size:"sm",checked:t.title.show,onChange:e=>t.title.setShow(e.currentTarget.checked),label:"Show Title",sx:{userSelect:"none"}}),r(s.Checkbox,{size:"sm",checked:!0,disabled:!0,label:"Use name as title"})]})})});function Ek(){return d(s.Stack,{sx:{height:"100%"},children:[r(Ik,{}),r(s.Divider,{label:"Info",labelPosition:"center",variant:"dashed"}),r(Ak,{}),r(zk,{}),r(Dk,{})]})}const Pk={width:"fit-content",minWidth:"100%",tableLayout:"fixed",tr:{width:"fit-content"},th:{position:"relative"},"th, td":{wordBreak:"break-word"},".resizer":{position:"absolute",right:0,top:"50%",transform:"translateY(-50%)",cursor:"col-resize",userSelect:"none",touchAction:"none"},".resizer.isResizing":{color:"#228be6",opacity:"1"},"@media (hover: hover)":{".resizer":{opacity:"0"},"*:hover > .resizer":{color:"#228be6",opacity:"1"}}};function wl({data:t}){const e=m.useMemo(()=>{if(!Array.isArray(t)||t.length===0)return[];const i=We.createColumnHelper();return Object.keys(t[0]).map(a=>i.accessor(a,{cell:o=>o.getValue()}))},[t]),n=We.useReactTable({data:t,columns:e,columnResizeMode:"onChange",getCoreRowModel:We.getCoreRowModel()});return t.length===0?r(s.Box,{sx:{height:"5em"}}):r(ke,{children:d(s.Table,{sx:Pk,children:[r("thead",{children:n.getHeaderGroups().map(i=>r("tr",{children:i.headers.map(a=>d("th",{style:{width:a.getSize()},children:[a.isPlaceholder?null:We.flexRender(a.column.columnDef.header,a.getContext()),r(s.ActionIcon,{onMouseDown:a.getResizeHandler(),onTouchStart:a.getResizeHandler(),className:`resizer ${a.column.getIsResizing()?"isResizing":""}`,children:r(T.ArrowBarToRight,{})})]},a.id))},i.id))}),r("tbody",{children:n.getRowModel().rows.map(i=>r("tr",{children:i.getVisibleCells().map(a=>r("td",{children:r(ke,{children:We.flexRender(a.column.columnDef.cell,a.getContext())})},a.id))},i.id))})]})})}const Lk=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],Bk={icon:{width:"80px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"80px"}}},Ok=({data:t,page:e,setPage:n,limit:i,setLimit:a})=>{const o=t.length,l=Math.ceil(o/i),u=p=>{n(1),a(Number(p))};if(o===0)return null;const c=l===1&&o<=10;return d(s.Group,{pt:10,px:10,position:"apart",children:[d(s.Group,{position:"left",children:[l>1&&r(s.Pagination,{size:"sm",value:e,onChange:n,total:l,withEdges:l>7,styles:{control:{height:"30px"}}}),!c&&r(s.Select,{icon:r(s.Text,{ta:"center",color:"dimmed",size:14,children:"Page Size"}),size:"xs",styles:Bk,data:Lk,value:String(i),onChange:u})]}),r(s.Group,{position:"right",children:d(s.Text,{color:"dimmed",my:0,size:14,children:["Total ",o," rows"]})})]})},$k=({data:t,loading:e})=>{const[n,i]=m.useState(1),[a,o]=m.useState(20),l=m.useMemo(()=>{const u=(n-1)*a,c=u+a;return t.slice(u,c)},[t,n,a]);return d(ke,{children:[r(Ok,{data:t,page:n,setPage:i,limit:a,setLimit:o}),d(s.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[r(s.LoadingOverlay,{visible:e,overlayBlur:2}),r(wl,{data:l})]})]})},Vk=({queryID:t})=>{const e=ue(),{state:n,error:i}=e.getDataStuffByID(t),a=m.useMemo(()=>e.queries.findByID(t),[e,t]);return n==="loading"?null:i?r(s.Text,{mt:10,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:i}):a!=null&&a.stateMessage?r(s.Text,{mt:10,color:"gray",align:"center",children:a.stateMessage}):null},Ai=k.observer(({id:t,moreActions:e,refreshOnMount:n})=>{const i=ue(),{data:a,state:o}=i.getDataStuffByID(t),l=o==="loading",u=m.useCallback(()=>{i.queries.refetchDataByQueryID(t)},[t,i]),c=()=>{i.queries.downloadDataByQueryID(t)};m.useEffect(()=>{n&&u()},[u,n]);const p=!Array.isArray(a)||a.length===0;return d(s.Stack,{spacing:0,sx:{height:"100%",border:"1px solid #eee"},children:[d(s.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[r(s.Group,{position:"left",children:r(s.Text,{weight:500,children:"Preview Data"})}),d(s.Group,{pr:15,children:[e,r(s.ActionIcon,{variant:"subtle",color:"blue",disabled:l,onClick:u,children:r(T.Refresh,{size:16})}),r(s.ActionIcon,{variant:"subtle",color:"blue",disabled:l||p,onClick:c,children:r(T.Download,{size:16})})]})]}),d(s.Box,{pb:20,sx:{position:"relative",flexGrow:1,overflow:"auto"},children:[r(Vk,{queryID:t}),r($k,{data:a,loading:l})]})]})}),Nk=k.observer(function(){const e=ee(),n=H(),{panel:i}=$e(),[a,o]=m.useState(!1),l=u=>{e.editor.setPath(["_QUERIES_",u])};return d(z,{children:[r(s.Drawer,{opened:a,onClose:()=>o(!1),title:"Choose queries",padding:"xl",size:500,zIndex:320,children:r(s.Checkbox.Group,{value:[...i.queryIDs],onChange:i.setQueryIDs,children:r(s.Stack,{spacing:"lg",children:n.queries.options.map(u=>r(s.Checkbox,{label:u.label,value:u.value},u.value))})})}),d(s.Stack,{spacing:6,children:[r(s.Group,{position:"right",children:r(s.Button,{variant:"light",size:"sm",leftIcon:r(M.IconLine,{size:16}),onClick:()=>o(!0),children:"Click me to choose queries for this panel"})}),i.queryIDs.length===1&&r(Ai,{id:i.queryIDs[0],moreActions:r(s.Tooltip,{label:"Open this query",children:r(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>l(i.queryIDs[0]),children:r(M.IconArrowCurveRight,{size:16})})})}),i.queryIDs.length>1&&d(s.Tabs,{defaultValue:i.queryIDs[0],children:[r(s.Tabs.List,{children:i.queries.map(u=>r(s.Tabs.Tab,{value:u.id,children:u.name},u.id))}),i.queries.map(u=>r(s.Tabs.Panel,{value:u.id,children:r(Ai,{id:u.id,moreActions:r(s.Tooltip,{label:"Open this query",children:r(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>l(u.id),children:r(M.IconArrowCurveRight,{size:16})})})})},u.id))]})]})]})}),qk=k.observer(()=>{const{panel:t}=dt();return r(ke,{children:r(s.Box,{sx:{height:"100%",flexGrow:0,flexShrink:0,width:"600px"},children:d(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:[d(s.Group,{position:"apart",noWrap:!0,sx:{flexGrow:0,flexShrink:0},children:[r(s.Group,{children:r(xi,{})}),r(s.Group,{grow:!0,position:"center",children:r(s.Text,{lineClamp:1,weight:"bold",children:t.title.show?t.name:""})}),r(s.Group,{position:"right",spacing:0,sx:{height:"28px"}})]}),r(s.Group,{px:5,pb:5,sx:{flexGrow:1,".panel-viz-section":{height:"calc(100% - 28px)"}},children:r(wi,{panel:t})})]})})})}),zi={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 Gk{constructor(e){P(this,"panel");P(this,"selected");this.panel=e,Q.makeAutoObservable(this,{},{deep:!1,autoBind:!0})}get variables(){return this.panel.variables}addNew(){const e=this.panel.variables.filter(n=>n.name.startsWith(zi.name)).length;this.panel.addVariable(x.cloneDeep({...zi,name:`${zi.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 i=Math.min(this.panel.variables.length-1,n);this.selected=this.panel.variables[i]}}}function Fk(){const{panel:t}=$e();return q.useCreation(()=>new Gk(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}})),jk=m.forwardRef(function({value:e,onChange:n,data:i,withStyle:a=!0},o){const l=(u,c)=>{const p=x.cloneDeep(e);x.set(p,u,c),n(p)};return d(s.Box,{px:"sm",py:"md",ref:o,children:[d(s.Group,{grow:!0,noWrap:!0,children:[r(s.TextInput,{label:"Name",required:!0,value:e.name,onChange:u=>l("name",u.currentTarget.value)}),r(O,{label:"Data Field",required:!0,value:e.data_field,onChange:u=>l("data_field",u)})]}),r(Mn,{label:"Aggregation",value:e.aggregation,onChange:u=>l("aggregation",u)}),e.aggregation.type!=="custom"&&d(z,{children:[r(s.Divider,{my:"xs",label:"Format",labelPosition:"center"}),r(Pe,{value:e.formatter,onChange:u=>l("formatter",u)})]}),a&&r(hs,{value:e,onChange:n})]})}),Wk=t=>{const{uiModel:e}=t;return r(s.Stack,{className:"var-list",children:e.variables.map(n=>r(s.Button,{variant:e.selected===n?"filled":"subtle",color:"gray",onClick:()=>e.select(n),children:n.name},n.name))})},Rk=k.observer(Wk),Qk=({variable:t,data:e})=>r(s.Group,{style:{minHeight:0,height:"calc(100% - 68px)"},children:r(s.Paper,{withBorder:!0,p:"md",children:fs(t,e)})}),Uk=k.observer(Qk),Kk=t=>{const e=q.useCreation(()=>N_(t.variable),[t.variable]),{classes:n}=Cl(),{data:i}=$e();return d(s.Group,{style:{height:"100%"},align:"start",children:[d(s.Stack,{"data-testid":"variable-editor",align:"stretch",className:n.config,children:[d(s.Group,{position:"right",children:[r(s.ActionIcon,{variant:"filled",disabled:!e.changed,color:"primary",onClick:e.commit,children:r(M.IconDeviceFloppy,{size:18})}),r(s.ActionIcon,{color:"red",onClick:()=>t.uiModel.remove(t.variable),children:r(M.IconTrash,{size:18})})]}),r(jk,{value:y.getSnapshot(e.copy),onChange:e.update,data:i})]}),r(Uk,{variable:y.getSnapshot(e.copy),data:i})]})},Yk=k.observer(Kk),Xk=()=>{const t=Fk(),{classes:e}=Cl();return d(s.Group,{className:e.root,noWrap:!0,align:"start",children:[r(s.Paper,{withBorder:!0,p:"md",className:"var-list-container",children:d(s.Stack,{justify:"space-between",children:[r(s.Box,{className:"var-list-actions",children:r(s.Button,{variant:"light",size:"sm",onClick:t.addNew,fullWidth:!0,children:"Add Variable"})}),r(Rk,{uiModel:t})]})}),t.selected?r(z,{children:r(Yk,{uiModel:t,variable:t.selected})}):r("span",{children:"Select or create a new variable on right side"})]})},Jk=k.observer(Xk);function Zk(){const{vizManager:t}=m.useContext(tt);return m.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 Hk=k.observer(({value:t,submit:e})=>{const[n,i]=ye.useInputState(t);m.useEffect(()=>{i(t)},[t]);const a=Zk(),o=t!==n;return r(s.Select,{label:"Visualization",value:n,searchable:!0,onChange:i,data:a,rightSection:r(s.ActionIcon,{disabled:!o,onClick:()=>e(n),children:r(T.DeviceFloppy,{size:20})}),maxDropdownHeight:600})}),Sl=[];function eT(t,e){try{return t.resolveComponent(e).createConfig()}catch{return null}}function tT(){const{data:t,panel:{variables:e,viz:n,title:i,name:a,queryIDs:o,description:l,id:u}}=$e(),{vizManager:c}=m.useContext(tt),p={name:a,title:i,description:l,viz:n,queryIDs:o,id:u},h=jo(p);try{return c.resolveComponent(p.viz.type),r(Gn,{configure:h,children:r(R_,{variables:e,setVizConf:n.setConf,panel:p,vizManager:c,data:t})})}catch(f){return console.info(x.get(f,"message")),null}}const nT=k.observer(()=>{const{data:t,panel:{viz:e}}=$e(),{vizManager:n}=m.useContext(tt),i=m.useCallback(p=>{if(p===e.type)return;const h=eT(n,p);e.setType(p),e.setConf(h||{})},[e.type]),a=p=>{try{e.setConf(JSON.parse(p))}catch(h){console.error(h)}},o=m.useMemo(()=>{var p;return(p=Sl.find(h=>h.value===e.type))==null?void 0:p.Panel},[e.type,Sl]),l=tT(),u=o?m.createElement(o,{data:t,conf:e.conf,setConf:e.setConf}):null,c=l||u;return d(s.Stack,{align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[r(Hk,{submit:i,value:e.type}),d(ke,{children:[r(s.Stack,{pb:10,sx:{flexGrow:1,maxHeight:"100%",overflow:"auto"},children:c}),!c&&r(s.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(e.conf,null,2),onChange:a})]})]})}),rT=k.observer(({panel:t,sourceViewID:e})=>{const n=H(),[i,a]=m.useState(e);m.useEffect(()=>{a(e)},[e]);const[o,{open:l,close:u}]=ye.useDisclosure(!1),c=()=>{t.moveToView(e,i),u()};return d(z,{children:[r(s.Button,{size:"xs",variant:"subtle",color:"blue",onClick:l,leftIcon:r(M.IconBoxMultiple,{size:14}),children:"Move into Another View"}),r(s.Modal,{opened:o,onClose:u,title:"Move panel into another view",zIndex:320,children:d(s.Stack,{sx:{maxHeight:"calc(100vh - 185px)",overflow:"hidden"},children:[r(s.Radio.Group,{value:i,onChange:a,pb:10,sx:{flexGrow:1,maxHeight:"calc(100vh - 185px - 30px)",overflow:"auto"},children:r(s.Stack,{spacing:"xs",children:n.views.options.map(p=>r(s.Radio,{value:p.value,label:p.label},p.value))})}),d(s.Group,{noWrap:!0,position:"apart",sx:{flexGrow:0,flexShrink:0},children:[r(s.Button,{size:"xs",color:"red",leftIcon:r(M.IconX,{size:14}),onClick:u,children:"Cancel"}),r(s.Button,{size:"xs",color:"blue",leftIcon:r(M.IconDeviceFloppy,{size:14}),onClick:c,disabled:i===e,children:"Confirm"})]})]})})]})}),iT={root:{flexGrow:1,width:"100%",overflow:"hidden"},panel:{width:"100%",height:"calc(100% - 44px)",padding:10,overflow:"scroll"}},_l=({children:t})=>d(s.Group,{noWrap:!0,grow:!0,position:"left",spacing:20,sx:{width:"100%",height:"100%"},children:[r(s.Box,{sx:{maxWidth:"calc(100% - 610px - 10px)",height:"100%",overflow:"auto"},children:t}),r(qk,{})]});function aT(t){return!["richText","button"].includes(t)}const sT=k.observer(({panel:t})=>{const e=Ee.useModals(),n=ee(),i=H(),[a,o]=m.useState("Data"),l=t.queries,c=aT(t.viz.type)&&t.dataLoading,p=c||t.queryErrors.length>0||t.queryStateMessages!==""||l.length===0,h=n.editor.path[1];m.useEffect(()=>{o(b=>p&&b==="Visualization"?"Data":b)},[t.id,p]);const f=()=>{n.editor.setPath(["_VIEWS_",h])},g=()=>e.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.removePanelByID(t.id,h),f()},confirmProps:{color:"red"},zIndex:320});return d(gr,{value:{panel:t,data:t.data,loading:c,errors:t.queryErrors,downloadPanelScreenshot:()=>{}},children:[d(s.Group,{px:16,position:"apart",sx:{borderBottom:"1px solid #eee"},children:[r(s.Text,{pt:9,pb:8,children:t.name}),d(s.Group,{position:"right",noWrap:!0,children:[r(rT,{panel:t,sourceViewID:h}),r(s.Button,{size:"xs",variant:"subtle",color:"red",onClick:g,leftIcon:r(M.IconTrash,{size:14}),children:"Delete This Panel"})]})]}),d(s.Tabs,{value:a,onTabChange:o,keepMounted:!1,styles:iT,children:[d(s.Tabs.List,{children:[r(s.Tabs.Tab,{value:"Data",disabled:c,children:"Data"}),r(s.Tabs.Tab,{value:"Panel",children:"Panel"}),r(s.Tabs.Tab,{value:"Variables",disabled:p,children:r(s.Tooltip,{label:"Requires data",disabled:!p,withinPortal:!0,zIndex:310,children:r(s.Text,{children:"Variables"})})}),r(s.Tabs.Tab,{value:"Visualization",disabled:p,children:r(s.Tooltip,{label:"Requires data",disabled:!p,withinPortal:!0,zIndex:310,children:r(s.Text,{children:"Visualization"})})}),r(s.Tabs.Tab,{value:"Interactions",children:"Interactions"})]}),d(s.Tabs.Panel,{value:"Data",children:[r(s.LoadingOverlay,{visible:c,exitTransitionDuration:0}),r(Nk,{})]}),r(s.Tabs.Panel,{value:"Panel",children:r(_l,{children:r(Ek,{})})}),r(s.Tabs.Panel,{value:"Variables",children:r(Jk,{})}),r(s.Tabs.Panel,{value:"Visualization",children:r(ke,{children:r(_l,{children:r(nT,{})})})}),r(s.Tabs.Panel,{value:"Interactions",children:r(ke,{children:r(vd,{})})})]})]})}),oT=k.observer(({viewID:t,panelID:e})=>{const n=H();if(!n.views.findByID(t))return d(s.Text,{size:14,children:["View by ID[",t,"] is not found"]});const a=n.panels.findByID(e);return a?r(sT,{panel:a}):d(s.Text,{size:14,children:["Panel by ID[",e,"] is not found"]})}),lT=t=>{const{queryModel:e}=t,n=ee(),i=H(),o=i.findQueryUsage(e.id).length>0,l=Ee.useModals(),u=()=>{l.openConfirmModal({title:"Delete this query?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.queries.removeQuery(e.id),n.editor.setPath(["_QUERIES_",""])},confirmProps:{color:"red"},zIndex:320})};return o?r(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:r(s.Button,{color:"gray",size:"xs",leftIcon:r(M.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})}):r(s.Button,{color:"red",size:"xs",onClick:u,leftIcon:r(M.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})},uT=k.observer(lT),kl=({width:t="calc(100% - 32px)",lastWidth:e="50%",height:n,count:i,spacing:a=16,pl:o=0})=>d(s.Stack,{spacing:a,mt:6,pl:o,children:[Array.from(new Array(i-1),(l,u)=>r(s.Skeleton,{width:t,height:n,radius:"xs"},u)),r(s.Skeleton,{width:e,height:n,radius:"xs"})]}),nn=({value:t})=>t===null||t===""?null:r(s.Tooltip,{label:t,disabled:!t,multiline:!0,children:r(s.ActionIcon,{children:r(M.IconInfoCircle,{size:14})})}),cT=({column:t})=>{const{column_key:e,column_key_text:n}=t;return e?r(s.Tooltip,{label:n,disabled:!n,children:r(s.Badge,{children:e})}):null},dT=k.observer(({dataSource:t})=>{const{columns:e}=t;return e.loading?r(kl,{height:"24px",width:"100%",lastWidth:"100%",count:20,pl:6}):e.empty?null:d(s.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"1000px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[d("colgroup",{children:[r("col",{style:{width:50}}),r("col",{style:{minWidth:300}}),r("col",{style:{width:30}}),r("col",{style:{width:70}}),r("col",{style:{minWidth:300}}),r("col",{style:{minWidth:80,width:80}}),r("col",{style:{minWidth:120,width:120}})]}),r("thead",{children:d("tr",{children:[r("th",{children:"#"}),r("th",{children:"Column Name"}),r("th",{}),r("th",{}),r("th",{children:"Type"}),r("th",{children:"Nullable"}),r("th",{children:"Default Value"})]})}),r("tbody",{children:e.data.map(n=>d("tr",{children:[r("td",{children:n.ordinal_position}),r("td",{children:n.column_name}),r("td",{children:r(nn,{value:n.column_comment})}),r("td",{children:r(cT,{column:n})}),r("td",{children:n.column_type}),r("td",{children:n.is_nullable}),r("td",{children:r(nn,{value:n.column_default})})]},n.column_name))})]})}),pT=k.observer(({dataSource:t})=>{const{indexes:e}=t,n=e.data;return d(s.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"950px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[d("colgroup",{children:[r("col",{style:{width:100}}),r("col",{style:{minWidth:300}}),r("col",{style:{width:150}}),r("col",{style:{width:150}}),r("col",{style:{width:250}})]}),r("thead",{children:d("tr",{children:[r("th",{children:"Index Length"}),r("th",{children:"Index Name"}),r("th",{children:"Index Algorithm"}),r("th",{children:"Unique"}),r("th",{children:"Column Name"})]})}),r("tbody",{children:n.map(i=>d("tr",{children:[r("td",{children:i.index_length}),r("td",{children:i.index_name}),r("td",{children:i.index_algorithm}),r("td",{children:i.is_unique?"YES":"NO"}),r("td",{children:i.column_name})]},i.index_name))})]})}),hT=k.observer(({dataSource:t})=>{const{indexes:e}=t,n=e.data;return d(s.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"850px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[d("colgroup",{children:[r("col",{style:{minWidth:300}}),r("col",{style:{width:150}}),r("col",{style:{width:100}}),r("col",{style:{width:100}}),r("col",{style:{width:100}}),r("col",{style:{width:100}})]}),r("thead",{children:d("tr",{children:[r("th",{children:"Index Name"}),r("th",{children:"Index Algorithm"}),r("th",{children:"Unique"}),r("th",{children:"Definition"}),r("th",{children:"Condition"}),r("th",{children:"Comment"})]})}),r("tbody",{children:n.map(i=>d("tr",{children:[r("td",{children:i.index_name}),r("td",{children:i.index_algorithm}),r("td",{children:i.is_unique?"YES":"NO"}),r("td",{children:r(nn,{value:i.index_definition})}),r("td",{children:r(nn,{value:i.condition})}),r("td",{children:r(nn,{value:i.comment})})]},i.index_name))})]})}),fT=k.observer(({dataSource:t})=>{const{indexes:e}=t;return e.loading||e.empty?null:t.type===ze.MySQL?r(pT,{dataSource:t}):t.type===ze.Postgresql?r(hT,{dataSource:t}):null}),gT=k.observer(({dataSource:t})=>d(s.Stack,{spacing:40,pt:10,sx:{flexGrow:1,overflow:"auto",position:"relative"},children:[r(ke,{children:r(dT,{dataSource:t})}),r(ke,{children:r(fT,{dataSource:t})})]}));function mT({table_type:t}){return t==="VIEW"?r(M.IconEye,{size:14}):t==="BASE TABLE"?r(M.IconTable,{size:14}):null}const yT=k.observer(({dataSource:t})=>{const{tables:e}=t;return e.loading?r(kl,{height:"24px",lastWidth:"50%",count:15}):r(s.Box,{h:"100%",sx:{overflow:"auto",".mantine-NavLink-label":{fontFamily:"monospace"}},children:Object.entries(e.data).map(([n,i])=>r(s.NavLink,{label:n,icon:r(M.IconDatabase,{size:14}),defaultOpened:t.table_schema===n,pl:0,childrenOffset:14,children:i.map(a=>r(s.NavLink,{label:a.table_name,icon:r(mT,{table_type:a.table_type}),onClick:()=>{t.setKeywords(n,a.table_name)},active:t.table_name===a.table_name},a.table_name))},n))})}),bT=({visible:t})=>r(s.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:r(s.LoadingOverlay,{visible:t})}),vT=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],xT={icon:{width:"50px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"50px"}}},wT=k.observer(({dataSource:t})=>{const{tableData:e}=t;return d(s.Group,{pt:10,px:10,position:"apart",children:[d(s.Group,{position:"left",children:[e.maxPage>1&&r(s.Pagination,{size:"sm",value:e.page,onChange:e.setPage,total:e.maxPage,withEdges:e.maxPage>7,styles:{control:{height:"30px"}}}),r(s.Select,{icon:r(s.Text,{ta:"center",color:"dimmed",size:14,children:"Limit"}),size:"xs",styles:xT,data:vT,value:String(e.limit),onChange:n=>e.setLimit(Number(n))})]}),r(s.Group,{position:"right",children:d(s.Text,{color:"dimmed",my:0,size:14,children:["Total ",e.total," rows"]})})]})}),CT=k.observer(({dataSource:t})=>{const e=t.tableData;return e.maxPage===0?r(s.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:"This table is empty"}):e.error?r(s.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:e.error}):e.page===1&&e.loading?r(bT,{visible:!0}):d(ke,{children:[r(wT,{dataSource:t}),d(s.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[r(s.LoadingOverlay,{visible:e.loading,overlayBlur:2}),r(wl,{data:e.data})]})]})}),ST={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},_T=k.observer(({dataSource:t})=>(m.useEffect(()=>{t.loadTablesIfEmpty()},[t]),t.tables.error?r(s.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:t.tables.error}):d(s.Flex,{sx:{height:"100%"},children:[r(s.Box,{w:300,sx:{flexGrow:0,flexShrink:0,position:"relative"},children:r(ke,{children:r(yT,{dataSource:t})})}),d(s.Tabs,{defaultValue:"structure",styles:ST,children:[d(s.Tabs.List,{children:[r(s.Tabs.Tab,{value:"structure",icon:r(M.IconColumns,{size:14}),children:"Structure"}),r(s.Tabs.Tab,{value:"data",icon:r(M.IconDatabase,{size:14}),children:"Data"})]}),r(s.Tabs.Panel,{value:"structure",children:r(gT,{dataSource:t})}),r(s.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:r(CT,{dataSource:t})})]})]}))),kT={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"}},Tl=k.observer(({dataSource:t,triggerButtonProps:e={}})=>{const[n,i]=m.useState(!1);return t.type==="http"?null:d(z,{children:[r(s.Modal,{opened:n,onClose:()=>i(!1),title:d(s.Group,{position:"apart",sx:{flexGrow:1},children:[r(s.Text,{fw:500,children:"Explorer Data Source"}),d(s.Group,{spacing:7,children:[r(s.Badge,{variant:"gradient",gradient:{from:"indigo",to:"cyan"},children:t.key}),r(s.Badge,{variant:"gradient",gradient:{from:"orange",to:"red"},children:t.type})]})]}),zIndex:320,size:"96vw",styles:kT,children:r(s.Box,{sx:{height:"calc(100vh - 220px)"},children:r(_T,{dataSource:t})})}),r(s.Button,{variant:"subtle",onClick:()=>i(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},...e,children:"See Table Structure"})]})}),TT=m.forwardRef(({label:t,type:e,...n},i)=>d(s.Group,{position:"apart",ref:i,...n,children:[r(s.Text,{children:t}),r(s.Text,{children:e})]})),DT=k.observer(({value:t,onChange:e})=>{const n=ee(),{data:i=[],loading:a}=q.useRequest(or,{refreshDeps:[]},[]),o=m.useMemo(()=>i.map(p=>({label:p.key,value:p.key,type:p.type})),[i]),l=m.useMemo(()=>o.reduce((p,h)=>(p[h.value]=h.type,p),{}),[o]),u=p=>{p!==null&&e({key:p,type:l[p]})},c=m.useMemo(()=>n.datasources.find(t),[n,t]);return r(s.Select,{data:o,label:d(s.Group,{position:"apart",children:[r(s.Box,{children:"Data Source"}),c&&r(Tl,{dataSource:c,triggerButtonProps:{compact:!0,size:"xs",px:10}})]}),itemComponent:TT,rightSection:c?r(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})}),Dl=m.forwardRef((t,e)=>{const{label:n,description:i,...a}=t;return r("div",{ref:e,...a,children:d(s.Group,{position:"apart",noWrap:!0,children:[r(s.Text,{children:n}),r(s.Text,{size:"xs",color:"dimmed",children:i})]})})}),IT=k.observer(({queryModel:t})=>{const[e,n]=m.useState(t.name);return m.useEffect(()=>{n(t.name)},[t.name]),r(s.Center,{ml:20,mt:20,sx:{maxWidth:"600px"},children:d(s.Stack,{spacing:10,sx:{width:"100%"},children:[r(s.Divider,{mb:-10,variant:"dashed",label:"Basics",labelPosition:"center"}),r(s.TextInput,{placeholder:"A unique name",label:"Name",required:!0,sx:{flex:1},value:e,onChange:i=>{n(i.currentTarget.value)},rightSection:r(s.ActionIcon,{variant:"filled",color:"blue",size:"sm",onClick:()=>t.setName(e),disabled:e===t.name,children:r(M.IconDeviceFloppy,{size:16})}),onBlur:()=>{t.setName(e)}}),r(DT,{value:{type:t.type,key:t.key},onChange:({type:i,key:a})=>{t.setKey(a),t.setType(i)}}),r(s.Divider,{mt:10,mb:-10,variant:"dashed",label:"Conditions",labelPosition:"center"}),r(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,itemComponent:Dl,maxDropdownHeight:500}),t.typedAsHTTP&&r(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,itemComponent:Dl,maxDropdownHeight:500}),r(s.Divider,{mt:20,mb:10,variant:"dashed"}),r(uT,{queryModel:t})]})})});function MT({content:t}){return d(s.HoverCard,{width:"60vw",shadow:"md",children:[r(s.HoverCard.Target,{children:r(s.ActionIcon,{size:16,color:"blue",children:r(M.IconEye,{})})}),r(s.HoverCard.Dropdown,{children:r(gt.Prism,{language:"sql",noCopy:!0,withLineNumbers:!0,children:t})})]})}const AT=k.observer(()=>{const e=[...ee().globalSQLSnippets.list];return e.length===0?null:d(s.Table,{horizontalSpacing:"xs",verticalSpacing:"xs",fontSize:"sm",highlightOnHover:!0,children:[r("thead",{children:d("tr",{children:[r("th",{children:"Key"}),r("th",{children:"Value"})]})}),r("tbody",{children:e.map(n=>{const{id:i,content:a}=n;return d("tr",{children:[r("td",{children:i}),r("td",{width:200,children:r(MT,{content:a})})]},i)})})]})}),zT=`
|
|
459
459
|
-- You may reference query variables in SQL or VizConfig.
|
|
460
460
|
SELECT *
|
|
461
461
|
FROM commit
|
|
@@ -468,8 +468,8 @@ WHERE
|
|
|
468
468
|
AND \${sql_snippets.author_email_condition}
|
|
469
469
|
-- Global SQL snippets (shared between dashboards)
|
|
470
470
|
AND \${global_sql_snippets.account_condition}
|
|
471
|
-
`,
|
|
471
|
+
`,Il=k.observer(function({showSQLSnippets:e=!0,sx:n={}}){const i=ee(),a=H(),o=i.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 r(s.Stack,{sx:{overflow:"hidden",...n},children:d(s.Tabs,{defaultValue:"guide",keepMounted:!1,children:[d(s.Tabs.List,{grow:!0,children:[r(s.Tabs.Tab,{value:"guide",icon:r(M.IconAlertCircle,{size:14}),children:"Guide"}),r(s.Tabs.Tab,{value:"local_query_vars",icon:r(M.IconVariable,{size:14}),children:"Variables in this dashboard"}),r(s.Tabs.Tab,{value:"global_sql_snippets",icon:r(M.IconVariablePlus,{size:14}),children:"Global SQL Snippets"})]}),r(s.Tabs.Panel,{value:"guide",pt:"xs",children:r(gt.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:zT})}),r(s.Tabs.Panel,{value:"local_query_vars",pt:"xs",children:r(gt.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:l})}),r(s.Tabs.Panel,{value:"global_sql_snippets",pt:"xs",children:d(s.Stack,{spacing:10,children:[r(s.Alert,{icon:r(M.IconAlertCircle,{size:16}),title:"Global SQL Snippets",children:"SQL snippets worth sharing between dashboards are managed in System Settings by admins."}),r(AT,{})]})})]})})}),Ei=k.observer(()=>{const[t,e]=m.useState(!1);return d(z,{children:[r(s.Modal,{opened:t,onClose:()=>e(!1),title:"Query Variables",zIndex:320,size:"800px",children:r(Il,{})}),r(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(`
|
|
472
472
|
`),post:["function process_result(res, utils, state) {"," // your code goes here"," return data","}"].join(`
|
|
473
|
-
`)},
|
|
473
|
+
`)},ET=k.observer(({queryModel:t})=>t.typedAsHTTP?d(s.Tabs,{defaultValue:"pre_process",orientation:"vertical",sx:{flexGrow:1},children:[d(s.Tabs.List,{children:[r(s.Tabs.Tab,{value:"pre_process",children:"Build Request"}),r(s.Tabs.Tab,{value:"post_process",children:"Process Result"}),r(Ei,{})]}),r(s.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:r(Zt,{label:"",value:t.pre_process,onChange:t.setPreProcess,defaultValue:Ml.pre})}),r(s.Tabs.Panel,{value:"post_process",p:"sm",children:r(Zt,{label:"",value:t.post_process,onChange:t.setPostProcess,defaultValue:Ml.post})})]}):null),PT=k.observer(({queryID:t,usage:e})=>{const n=ee().editor,i=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 r(s.Stack,{py:"sm",px:"md",children:d(s.Table,{highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[r("thead",{children:d("tr",{children:[r("th",{style:{width:100},children:"Type"}),r("th",{style:{width:"calc(50% - 50px)"},children:"Name"}),r("th",{children:"In View(s)"})]})}),r("tbody",{children:e.map(o=>d("tr",{children:[r("td",{children:x.capitalize(o.type)}),r("td",{children:r(s.Anchor,{component:"button",type:"button",onClick:()=>i(o),children:o.label})}),r("td",{children:d(s.Stack,{align:"flex-start",justify:"flex-start",spacing:2,children:[o.views.map(l=>r(s.Anchor,{component:"button",type:"button",onClick:()=>a(l.id),children:r(s.Box,{children:l.label})},l.id)),o.views.length===0&&r(s.Box,{children:"--"})]})})]},o.id))})]})})}),Pi=({value:t,onChange:e,height:n="200px",defaultLanguage:i="sql",theme:a="vs-dark"})=>{const o=u=>{e==null||e(u??"")},l=!e;return r(ve,{className:"minimal-monaco-editor",height:n,defaultLanguage:i,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}})},LT=({value:t,onChange:e,defaultValue:n})=>{const[i,a]=m.useState(t),o=()=>{e(i)},l=()=>{a(t)},u=()=>{a(n)};m.useEffect(()=>{a(t)},[t]);const c=i!==t;return d(s.Stack,{spacing:4,sx:{height:"100%"},children:[d(s.Group,{mb:6,position:"apart",sx:{flexShrink:0,flexGrow:0},children:[r(s.Group,{position:"left",children:r(s.Button,{onClick:u,size:"xs",variant:"default",leftIcon:r(M.IconPlayerSkipBack,{size:16}),children:"Reset to default"})}),d(s.Group,{position:"right",children:[r(s.Button,{onClick:l,color:"red",size:"xs",disabled:!c,leftIcon:r(M.IconRecycle,{size:16}),children:"Revert Changes"}),r(s.Button,{size:"xs",onClick:o,disabled:!c,leftIcon:r(M.IconDeviceFloppy,{size:16}),children:"Confirm Changes"})]})]}),r(Pi,{height:"100%",value:i,onChange:a,theme:"sql-dark",defaultLanguage:"sql"})]})},BT=({value:t,height:e="200px",defaultLanguage:n="sql"})=>r(ve,{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}}),OT=k.observer(({value:t})=>{const n=ue().payloadForSQL,i=m.useMemo(()=>ir(t,n),[t,n]);return r(BT,{height:"100%",value:i})}),Al={pre:["function process_request({ context, filters, sql }, utils) {"," // modify and return sql"," return sql","}"].join(`
|
|
474
474
|
`),post:["function process_result(data, utils, state) {"," // process data and return the result"," return data","}"].join(`
|
|
475
|
-
`)},WT=k.observer(({queryModel:e})=>e.typedAsSQL?p(s.Tabs,{defaultValue:"Edit",orientation:"vertical",sx:{flexGrow:1},styles:{tabLabel:{width:"100%",height:"28px",lineHeight:"28px"}},keepMounted:!1,children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Edit",children:i(s.Group,{spacing:14,position:"apart",children:"Edit SQL"})}),i(s.Tabs.Tab,{value:"Preview",children:"Preview SQL"}),i(s.Tabs.Tab,{value:"pre_process",children:"Process Request"}),i(s.Tabs.Tab,{value:"post_process",children:"Process Result"}),i(Ki,{}),e.datasource&&i(xu,{dataSource:e.datasource})]}),i(s.Tabs.Panel,{value:"Edit",sx:{position:"relative"},p:"sm",children:i(qT,{value:e.sql,onChange:e.setSQL,defaultValue:"SELECT 1"})}),i(s.Tabs.Panel,{value:"Preview",p:0,pl:4,children:i(GT,{value:e.sql})}),i(s.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:i(mn,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:_u.pre})}),i(s.Tabs.Panel,{value:"post_process",p:"sm",children:i(mn,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:_u.post})})]}):null),fr={height:"calc(100% - 44px)",padding:0},jT=k.observer(({queryModel:e})=>{const t=le(),n=m.useMemo(()=>e.datasource?e.typedAsHTTP?"HTTP":"SQL":"Configurations",[e.datasource,e.typedAsHTTP]),[r,a]=m.useState(n);m.useEffect(()=>{a(u=>u!=="Configurations"&&n==="Configurations"?"Configurations":u)},[n]);const o=t.findQueryUsage(e.id),l=o.length===0;return p(s.Tabs,{value:r,onTabChange:a,defaultValue:n,orientation:"horizontal",keepMounted:!1,sx:{height:"100vh"},children:[p(s.Tabs.List,{grow:!0,children:[i(s.Tabs.Tab,{value:"Configurations",children:"Configurations"}),e.typedAsSQL&&i(s.Tabs.Tab,{value:"SQL",children:"Request"}),e.typedAsHTTP&&i(s.Tabs.Tab,{value:"HTTP",children:"Request"}),i(s.Tabs.Tab,{value:"Data",disabled:!e.datasource,children:i(s.Tooltip,{label:"Need to pick a Data Source first",disabled:e.datasource,withinPortal:!0,children:i(s.Text,{children:"Data"})})}),i(s.Tabs.Tab,{value:"Usage",disabled:l,children:i(s.Tooltip,{label:"This query is not used for any filter or panel",disabled:!l,withinPortal:!0,children:i(s.Text,{children:"Usage"})})})]}),i(s.Tabs.Panel,{value:"Configurations",pt:0,p:0,children:i(LT,{queryModel:e})}),e.typedAsSQL&&i(s.Tabs.Panel,{value:"SQL",sx:fr,children:i(s.Stack,{sx:{height:"100%"},children:i(WT,{queryModel:e})})}),e.typedAsHTTP&&i(s.Tabs.Panel,{value:"HTTP",sx:fr,children:i(s.Stack,{sx:{height:"100%"},children:i(VT,{queryModel:e})})}),i(s.Tabs.Panel,{value:"Data",sx:{...fr,overflow:"hidden"},children:i(Qi,{id:e.id,moreActions:null,refreshOnMount:!0})}),i(s.Tabs.Panel,{value:"Usage",sx:{...fr,overflow:"hidden"},children:i(NT,{queryID:e.id,usage:o})})]})}),RT=k.observer(({id:e})=>{const n=le().queries.findByID(e);return e===""?null:n?i(jT,{queryModel:n}):i(s.Text,{size:14,color:"red",children:"Invalid Query ID"})}),YT=k.observer(({value:e})=>{const n=ye().payloadForSQL,r=m.useMemo(()=>wr(e,n),[e,n]);return i(Xi,{height:"100%",value:r})}),QT=k.observer(({item:e,remove:t,onKeyChanged:n})=>{const[r,a]=m.useState("SQL"),[o,l]=m.useState(e.key),u=()=>{e.setKey(o),n(o)},c=o!==e.key,d=e.isADuplicatedKey(o),[f,h]=m.useState(e.value),g=()=>{e.setValue(f)};m.useEffect(()=>{l(e.key),h(e.value)},[e]);const y=f!==e.value,C=Fe.useModals(),w=()=>{C.openConfirmModal({title:"Delete this SQL snippet?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:t,confirmProps:{color:"red"},zIndex:320})};return p(s.Stack,{p:20,sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",children:[p(s.Group,{sx:{alignItems:"end"},spacing:40,children:[i(s.TextInput,{label:d?"This key is occupied by another snippet":"Key",value:o,onChange:_=>{l(_.currentTarget.value)},sx:{flexGrow:"1 !important"},rightSection:i(s.ActionIcon,{color:"blue",variant:"subtle",onClick:u,disabled:!c||d,children:i(I.DeviceFloppy,{size:16})}),error:d}),i(s.Button,{leftIcon:i(I.Trash,{size:16}),color:"red",variant:"light",onClick:w,children:"Delete this SQL Snippet"})]}),p(s.Tabs,{value:r,onTabChange:a,sx:{flexGrow:1},styles:{panel:{height:"calc(100% - 50px)"}},children:[p(s.Tabs.List,{sx:{position:"relative"},children:[i(s.Tabs.Tab,{value:"SQL",children:"SQL"}),i(s.Tabs.Tab,{value:"Preview",children:"Preview"}),i(Ki,{}),i(s.ActionIcon,{color:"blue",variant:"filled",onClick:g,disabled:!y,sx:{position:"absolute",top:0,right:10},children:i(I.DeviceFloppy,{size:18})})]}),i(s.Tabs.Panel,{value:"SQL",pt:"sm",children:i(Xi,{height:"100%",value:f,onChange:h,defaultLanguage:"sql",theme:"sql-dark"})}),i(s.Tabs.Panel,{value:"Preview",pt:"sm",children:i(YT,{value:f})})]})]})}),UT=k.observer(({id:e})=>{const t=ue(),n=le(),r=m.useMemo(()=>n.sqlSnippets.findByKey(e),[e]);if(!e)return null;if(!r)return p(s.Text,{size:14,children:["SQL Snippet by key[",e,"] is not found"]});const a=()=>{t.editor.setPath(["_SQL_SNIPPETS_",""])};return i(QT,{item:r,remove:()=>{n.sqlSnippets.removeByKey(e),a()},onKeyChanged:u=>{t.editor.setPath(["_SQL_SNIPPETS_",u])}})}),KT=k.observer(({view:e})=>!e||e.type!==j.Division?null:p(s.Stack,{children:[i(s.Divider,{mt:8,mb:0,label:"Division settings",labelPosition:"center"}),i(s.Text,{align:"center",size:"xs",color:"dimmed",children:"Under construction"})]})),XT=[{value:"default",label:"Default"},{value:"outline",label:"Outline"},{value:"pills",label:"Pills"}],JT=[{value:"horizontal",label:"Horizontal"},{value:"vertical",label:"Vertical"}],ZT=k.observer(({view:e})=>{if(!e||e.type!==j.Tabs)return null;const t=e.config;return p(s.Stack,{children:[i(s.Divider,{mt:8,mb:0,label:"Tabs settings",labelPosition:"center"}),i(s.Select,{label:"Variant",value:t.variant,onChange:t.setVariant,data:XT}),i(s.Select,{label:"Orientation",value:t.orientation,onChange:t.setOrientation,data:JT}),i(s.Switch,{label:"Grow Tabs",checked:t.grow,onChange:n=>t.setGrow(n.currentTarget.checked)})]})}),HT=({disabled:e,value:t,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[e&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Te,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},eD=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:a}]=Q.useBoolean(),[o,l]=m.useState(e??Pi),u=g=>{l({...o,enabled:g})},c=()=>{a();const{enabled:g,func_content:y}=o,C={enabled:g,func_content:y};l(C),t(C)},d=()=>{a(),l(e)},f=g=>{l(y=>({...y,func_content:g}))},h=()=>{f(Pi.func_content)};return p(B,{children:[i(s.ActionIcon,{size:"lg",color:"blue",variant:"filled",mt:26,onClick:r,sx:{flexGrow:0},children:i(I.Settings,{size:14})}),i(s.Modal,{size:800,title:"Customize modal title",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:o.enabled,onChange:g=>u(g.currentTarget.checked)}),i(HT,{value:o.func_content,onChange:f,disabled:!o.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:h,color:"red",leftIcon:i(I.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:c,children:"OK"})]})]})]})})]})},tD=k.observer(({view:e})=>{if(!e||e.type!==j.Modal)return null;const t=e.config,n=t.custom_modal_title.value;return p(s.Stack,{children:[i(s.Divider,{mt:8,label:"Modal settings",labelPosition:"center"}),p(s.Flex,{gap:10,children:[i(s.TextInput,{label:"Modal Title",value:n,onChange:x.noop,disabled:!0,sx:{flexGrow:1}}),i(eD,{value:t.custom_modal_title,onChange:t.custom_modal_title.replace})]}),p(s.Group,{grow:!0,children:[i(s.TextInput,{label:"Width",value:t.width,onChange:r=>t.setWidth(r.currentTarget.value),placeholder:"600px / 50vw"}),i(s.TextInput,{label:"Height",value:t.height,onChange:r=>t.setHeight(r.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),nD=k.observer(({view:e})=>p(B,{children:[i(KT,{view:e}),i(tD,{view:e}),i(ZT,{view:e})]})),rD=[{label:"Division",value:j.Division},{label:"Modal",value:j.Modal},{label:"Tabs",value:j.Tabs}],iD=k.observer(({view:e})=>e?p(s.Stack,{sx:{position:"relative"},children:[i(s.TextInput,{label:"Name",value:e.name,onChange:t=>{e.setName(t.currentTarget.value)}}),i(s.Select,{label:"Type",withinPortal:!0,zIndex:320,value:e.type,onChange:e.setType,data:rD}),i(nD,{view:e})]}):null),aD=k.observer(({id:e})=>{const t=Fe.useModals(),n=ue(),r=le();if(e==="")return null;const a=r.views.findByID(e);if(!a)return p(s.Text,{size:14,children:["View by ID[",e,"] is not found"]});const o=()=>{n.editor.setPath(["_VIEWS_",""])},l=()=>{t.openConfirmModal({title:"Delete this view?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.views.removeByID(e),o()},zIndex:320})};return p(s.Stack,{sx:{maxWidth:"600px",height:"100%"},spacing:"sm",children:[i(s.Group,{position:"right",pt:10,children:i(s.Button,{size:"xs",color:"red",leftIcon:i(I.Trash,{size:16}),onClick:l,children:"Delete this view"})}),i(s.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:i(iD,{view:a})})]})});function sD(e){return e.length===1&&e[0]==="_QUERY_VARS_"}function oD(e){return e.length===1&&e[0]==="_MOCK_CONTEXT_"}function lD(e){return e.length===2&&e[0]==="_FILTERS_"}function uD(e){return e.length===1&&e[0]==="_SQL_SNIPPETS_"}function cD(e){return e.length===2&&e[0]==="_SQL_SNIPPETS_"}function dD(e){return e.length===2&&e[0]==="_QUERIES_"}function pD(e){return e.length===1&&e[0]==="_QUERIES_"}function hD(e){return e.length===2&&e[0]==="_VIEWS_"}function fD(e){return e.length===4&&e[0]==="_VIEWS_"&&e[2]==="_PANELS_"}const gD=k.observer(()=>i(s.Stack,{sx:{height:"100%"},p:"sm",children:i(Cu,{})})),mD=k.observer(()=>{const e=Fe.useModals(),t=ue(),n=o=>{t.editor.setPath(["_QUERIES_",o])},r=()=>{e.openConfirmModal({title:"Delete ununsed queries?",children:i(s.Text,{size:"sm",children:"This action cannot be undone."}),labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>t.content.removeUnusedQueries(),confirmProps:{color:"red"},zIndex:320})},a=t.content.queriesUsage;return p(s.Stack,{sx:{height:"100%"},spacing:"sm",pb:"59px",children:[i(s.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:i(s.Text,{px:"md",align:"left",sx:{userSelect:"none",cursor:"default"},children:"Manage Queries"})}),i(s.Flex,{justify:"flex-end",align:"center",px:12,children:i(s.Button,{variant:"subtle",size:"xs",color:"red",leftIcon:i(E.IconTrash,{size:14}),disabled:!t.content.hasUnusedQueries,onClick:r,children:"Delete unused queries"})}),i(s.Box,{sx:{flexGrow:1,overflow:"auto"},children:p(s.Table,{fontSize:"sm",highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[i("thead",{children:p("tr",{children:[i("th",{children:"Name"}),i("th",{style:{width:"200px"},children:"Data Source"}),i("th",{style:{width:"100px",textAlign:"right"},children:"Type"}),i("th",{style:{width:"100px",textAlign:"center"},children:"Usage"}),i("th",{style:{width:"300px",paddingLeft:"24px"},children:"Action"})]})}),i("tbody",{children:t.content.queries.sortedList.map(o=>{var u;const l=((u=a[o.id])==null?void 0:u.length)??0;return p("tr",{children:[i("td",{children:o.name}),i("td",{children:o.key}),i("td",{style:{textAlign:"right"},children:o.type}),i("td",{style:{color:l===0?"#ff0000":"#000",fontWeight:l===0?"bold":"normal",textAlign:"center"},children:l}),i("td",{children:i(s.Button,{variant:"subtle",size:"xs",onClick:()=>n(o.id),children:"Open"})})]},o.id)})})]})})]})}),yD=k.observer(()=>{const e=Fe.useModals(),t=ue(),n=o=>{t.editor.setPath(["_SQL_SNIPPETS_",o])},r=()=>{e.openConfirmModal({title:"Delete ununsed SQL snippets?",children:i(s.Text,{size:"sm",children:"This action cannot be undone."}),labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>t.content.removeUnusedSQLSnippets(),confirmProps:{color:"red"},zIndex:320})},a=t.content.sqlSnippetsUsage;return p(s.Stack,{sx:{height:"100%"},spacing:"sm",pb:"59px",children:[i(s.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:i(s.Text,{px:"md",align:"left",sx:{userSelect:"none",cursor:"default"},children:"Manage SQL Snippets"})}),i(s.Flex,{justify:"flex-end",align:"center",px:12,children:i(s.Button,{variant:"subtle",size:"xs",color:"red",leftIcon:i(E.IconTrash,{size:14}),disabled:!t.content.hasUnusedSQLSnippets,onClick:r,children:"Delete unused SQL snippets"})}),i(s.Box,{sx:{flexGrow:1,overflow:"auto"},children:p(s.Table,{fontSize:"sm",highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[i("thead",{children:p("tr",{children:[i("th",{children:"Key"}),i("th",{style:{width:"100px",textAlign:"center"},children:"Usage"}),i("th",{style:{width:"300px",paddingLeft:"24px"},children:"Action"})]})}),i("tbody",{children:t.content.sqlSnippets.sortedList.map(o=>{var u;const l=((u=a[o.key])==null?void 0:u.length)??0;return p("tr",{children:[i("td",{children:o.key}),i("td",{style:{color:l===0?"#ff0000":"#000",fontWeight:l===0?"bold":"normal",textAlign:"center"},children:l}),i("td",{children:i(s.Button,{variant:"subtle",size:"xs",onClick:()=>n(o.key),children:"Open"})})]},o.key)})})]})})]})}),bD=k.observer(()=>{const e=ue().editor,t=e.path;return sD(t)?i(gD,{}):oD(t)?i(Ek,{}):lD(t)?i(s.Box,{p:"xs",pl:20,children:i(zk,{id:t[1]})}):uD(t)?i(yD,{}):cD(t)?i(UT,{id:t[1]}):pD(t)?i(mD,{}):dD(t)?i(RT,{id:t[1]}):hD(t)?i(s.Box,{p:"xs",pl:20,children:i(aD,{id:t[1]})}):fD(t)?i(hT,{viewID:t[1],panelID:t[3]}):i(s.Box,{children:e.path})}),vD=k.observer(()=>i(bD,{})),xD=k.observer(()=>{const e=ue(),t=()=>{const n=new Date().getTime().toString(),r={id:n,key:n,label:n,order:e.content.filters.current.length+1,type:ve.TextInput,config:ml(),visibleInViewsIDs:["Main"],auto_submit:!1};e.content.filters.append(r),e.editor.setPath(["_FILTERS_",n])};return i(s.Button,{variant:"subtle",leftIcon:i(E.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Filter"})}),wD=k.observer(({parentID:e})=>{const t=le();if(!e)return null;const n=t.views.findByID(e);return!n||n.type===j.Tabs?null:i(s.Button,{variant:"subtle",leftIcon:i(E.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:()=>t.addANewPanel(n.id),sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Panel"})}),CD=k.observer(()=>{const e=ue(),t=()=>{const n=new Date().getTime().toString(),r={id:n,name:n,type:Ne.Postgresql,key:"",sql:""};e.content.queries.append(r),e.editor.setPath(["_QUERIES_",n])};return i(s.Button,{variant:"subtle",leftIcon:i(E.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Query"})}),SD=k.observer(()=>{const e=ue(),t=()=>{const n=new Date().getTime().toString(),r={key:n,value:""};e.content.sqlSnippets.append(r),e.editor.setPath(["_SQL_SNIPPETS_",n])};return i(s.Button,{variant:"subtle",leftIcon:i(E.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a SQL Snippet"})}),_D=k.observer(()=>{const e=le();return i(s.Button,{variant:"subtle",leftIcon:i(E.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:e.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a View"})}),kD=k.observer(()=>{const e=ue();return i(s.Button,{variant:"subtle",rightIcon:i(E.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>e.editor.setPath(["_QUERIES_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:"Manage Queries"})}),TD=k.observer(()=>{const e=ue();return i(s.Button,{variant:"subtle",rightIcon:i(E.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>e.editor.setPath(["_SQL_SNIPPETS_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:"Manage SQL Snippets"})}),DD=k.observer(({action_type:e,parentID:t})=>e==="_Add_A_Filter_"?i(xD,{}):e==="_Add_A_SQL_SNIPPET_"?i(SD,{}):e==="_Add_A_QUERY_"?i(CD,{}):e==="_Add_A_VIEW_"?i(_D,{}):e==="_Add_A_PANEL_"?i(wD,{parentID:t}):e==="_QUERIES_SETTINGS_"?i(kD,{}):e==="_SQL_SNIPPETS_SETTINGS_"?i(TD,{}):null),ku=k.observer(({option:e})=>{var d;const t=ue().editor,n=t.isOptionActive,r=n(t.path,e),a=t.isOptionOpened,o=t.navigate,l=a(e),[u,c]=m.useState(l);return m.useEffect(()=>{c(l)},[l]),i(s.NavLink,{active:r,defaultOpened:l,opened:u,onChange:c,label:e.label,onClick:()=>o(e),icon:e.Icon?i(e.Icon,{size:18}):null,children:(d=e.children)==null?void 0:d.map(f=>f._type==="ACTION"?i(DD,{action_type:f._action_type,parentID:f.parentID},`_ADD_${f.value}_`):i(ku,{option:f},f.value))},e.label)}),ID=k.observer(()=>{const e=ue();return i(s.Box,{sx:{position:"relative"},children:e.editor.navOptions.map(t=>i(ku,{option:t},t.value))})}),MD=k.observer(()=>{const e=ue();return p(s.Navbar,{p:0,width:{base:220,xs:220,sm:240,md:260,lg:300,xl:320},sx:{height:"100vh - 60px - 60px"},children:[i(s.Navbar.Section,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:i(s.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Settings"})}),i(s.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:i(ID,{})}),i(s.Navbar.Section,{children:i(s.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:i(s.Button,{size:"xs",color:"red",leftIcon:i(E.IconX,{size:18}),onClick:()=>e.editor.close(),children:"Close"})})})]})}),AD={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden",minWidth:"calc(var(--mantine-navbar-width, 0px) + 1000px)"},body:{flexGrow:1,nav:{top:0,height:"100vh"}},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:0,height:"100vh"}},zD=k.observer(()=>{const e=ue().editor;return i(s.Modal,{onClose:()=>e.setSettingsOpen(!1),closeOnEscape:!1,closeOnClickOutside:!1,opened:e.settings_open,fullScreen:!0,title:null,transitionProps:{duration:0},withCloseButton:!1,withinPortal:!0,zIndex:300,styles:{body:{padding:"0 !important"},content:{overflowY:"hidden !important"}},children:i(s.AppShell,{padding:0,navbar:i(MD,{}),styles:AD,children:i(vD,{})})})}),ED=e=>e.replace(/([^:])(\/\/+)/g,"$1/");function $D(e){m.useEffect(()=>{if(Te.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const n=ED(e);Te.loader.config({paths:{vs:n}}),Te.loader.init().then(r=>console.log("monaco instance:",r))},[])}wo();const LD={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:60+30,height:"100vh"}},PD=({context:e,dashboard:t,content:n,update:r,className:a="dashboard",config:o,onChange:l,headerSlot:u},c)=>{$D(o.monacoPath),Cr(o);const{data:d=[]}=Q.useRequest(_r),{data:f=[]}=Q.useRequest(us),h=m.useMemo(()=>su(t,n,d,f,e),[t,n]);m.useImperativeHandle(c,()=>h,[h]),ou(h.content,!0),m.useEffect(()=>{h.context.replace(e)},[e]),m.useEffect(()=>{h.datasources.replace(d)},[d]),m.useEffect(()=>{h.globalSQLSnippets.replace(f)},[f]),m.useEffect(()=>te.reaction(()=>te.toJS(h.json),w=>{l==null||l(w)}),[h]);const g=async()=>{await r(h.json,h.content.json)},y=Q.useCreation(Ei,[]),C=lu(y);return i(Fe.ModalsProvider,{children:i(Ar,{value:{searchButtonProps:o.searchButtonProps},children:i(Dr,{value:h,children:i(zr,{value:h.content,children:i(zn.Provider,{value:{inEditMode:!0},children:i(ct.Provider,{value:y,children:p(sr,{configure:C,children:[i(s.AppShell,{padding:0,header:i(W_,{saveDashboardChanges:g,headerSlot:u}),navbar:i(mk,{}),styles:LD,children:i(s.Box,{className:`${a} dashboard-root`,sx:{position:"relative"},children:h.content.views.visibleViews.map(w=>i(Kl,{view:w},w.id))})}),i(zD,{})]})})})})})})})},OD=k.observer(m.forwardRef(PD)),GM="",Tu=b.types.model({id:b.types.string,name:b.types.string,dashboard_id:b.types.string,create_time:b.types.string,update_time:b.types.string,version:b.types.string,filters:Ml,queries:Ll,sqlSnippets:Pl,views:kl,panels:Dl,mock_context:ll}).views(e=>({get json(){return{id:e.id,name:e.name,create_time:e.create_time,update_time:e.update_time,dashboard_id:e.dashboard_id,content:{views:e.views.json,panels:e.panels.json,filters:e.filters.json,version:e.version,definition:{queries:e.queries.json,sqlSnippets:e.sqlSnippets.json,mock_context:e.mock_context.current}}}},get payloadForSQL(){const t=b.getParent(e).context.current,n=b.getParent(e).globalSQLSnippets,r={context:{...e.mock_context.current,...t},filters:e.filters.values};return{...r,sql_snippets:ur(e.sqlSnippets.current,"key","value",r),global_sql_snippets:ur(n.list,"id","content",r)}},get payloadForViz(){const t=b.getParent(e).context.current;return{context:{...e.mock_context.current,...t},filters:e.filters.values}},get dashboardState(){return Sr(this.payloadForSQL)},getAdditionalQueryInfo(t){return{content_id:e.id,query_id:t,params:this.dashboardState}},get data(){return e.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(t){const n=e.queries.findByID(t);return n?{data:n.data,len:n.data.length,state:n.state,error:n.error}:{data:[],len:0,state:"idle",error:void 0}}})).actions(e=>({}));function BD({id:e,name:t,dashboard_id:n,create_time:r,update_time:a,content:o}){if(!o)throw new Error("unexpected null content when creating a content model");const{version:l,filters:u,views:c,panels:d,definition:{queries:f,sqlSnippets:h,mock_context:g={}}}=o;return Tu.create({id:e,name:t,dashboard_id:n,create_time:r,update_time:a,version:l,filters:Al(u),queries:FS(f),sqlSnippets:WS(h),mock_context:ul(g),views:MS(c),panels:{list:d}})}const VD=b.types.model({id:b.types.identifier,name:b.types.string,group:b.types.string,content:Tu,content_id:b.types.string,datasources:TS,globalSQLSnippets:Sl,context:Oi});function ND({id:e,name:t,group:n,content_id:r},a,o,l,u){return VD.create({id:e,name:t,group:n,content_id:r,content:BD(a),datasources:{list:o},globalSQLSnippets:{list:l},context:_l(u)})}wo();const qD=k.observer(({context:e,dashboard:t,content:n,className:r="dashboard",config:a,fullScreenPanelID:o,setFullScreenPanelID:l})=>{Cr(a);const{data:u=[]}=Q.useRequest(_r),{data:c=[]}=Q.useRequest(us),d=m.useMemo(()=>ND(t,n,u,c,e),[t,n]);ou(d.content,!1),m.useEffect(()=>{d.context.replace(e)},[e]),m.useEffect(()=>{d.datasources.replace(u)},[u]),m.useEffect(()=>{d.globalSQLSnippets.replace(c)},[c]);const f=Q.useCreation(Ei,[]),h=lu(f);return i(Fe.ModalsProvider,{children:i(Ar,{value:{searchButtonProps:a.searchButtonProps},children:i(Dr,{value:d,children:i(zr,{value:d.content,children:i($r.Provider,{value:{fullScreenPanelID:o,setFullScreenPanelID:l},children:i(zn.Provider,{value:{inEditMode:!1},children:i(s.Box,{className:`${r} dashboard-root`,children:i(ct.Provider,{value:f,children:i(sr,{configure:h,children:d.content.views.visibleViews.map(g=>i(dr,{view:g},g.id))})})})})})})})})})});var Ji={},FD={get exports(){return Ji},set exports(e){Ji=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){var a=r.prototype,o=a.format;a.format=function(l){var u=this,c=this.$locale();if(!this.isValid())return o.bind(this)(l);var d=this.$utils(),f=(l||"YYYY-MM-DDTHH:mm:ssZ").replace(/\[([^\]]+)]|Q|wo|ww|w|WW|W|zzz|z|gggg|GGGG|Do|X|x|k{1,2}|S/g,function(h){switch(h){case"Q":return Math.ceil((u.$M+1)/3);case"Do":return c.ordinal(u.$D);case"gggg":return u.weekYear();case"GGGG":return u.isoWeekYear();case"wo":return c.ordinal(u.week(),"W");case"w":case"ww":return d.s(u.week(),h==="w"?1:2,"0");case"W":case"WW":return d.s(u.isoWeek(),h==="W"?1:2,"0");case"k":case"kk":return d.s(String(u.$H===0?24:u.$H),h==="k"?1:2,"0");case"X":return Math.floor(u.$d.getTime()/1e3);case"x":return u.$d.getTime();case"z":return"["+u.offsetName()+"]";case"zzz":return"["+u.offsetName("long")+"]";default:return h}});return o.bind(this)(f)}}})})(FD);const GD=Ji;var Zi={},WD={get exports(){return Zi},set exports(e){Zi=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){var o=r.prototype,l=function(c){var d=c.date,f=c.utc;return Array.isArray(d)?f?d.length?new Date(Date.UTC.apply(null,d)):new Date:d.length===1?a(String(d[0])).toDate():new(Function.prototype.bind.apply(Date,[null].concat(d))):d},u=o.parse;o.parse=function(c){c.date=l.bind(this)(c),u.bind(this)(c)}}})})(WD);const jD=Zi;var Hi={},RD={get exports(){return Hi},set exports(e){Hi=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){var a=r.prototype,o=a.format;a.format=function(l){var u=this,c=(l||"YYYY-MM-DDTHH:mm:ssZ").replace(/(\[[^\]]+])|BBBB|BB/g,function(d,f){var h,g=String(u.$y+543),y=d==="BB"?[g.slice(-2),2]:[g,4];return f||(h=u.$utils()).s.apply(h,y.concat(["0"]))});return o.bind(this)(c)}}})})(RD);const YD=Hi;var ea={},QD={get exports(){return ea},set exports(e){ea=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){var o="h:mm A",l={lastDay:"[Yesterday at] "+o,sameDay:"[Today at] "+o,nextDay:"[Tomorrow at] "+o,nextWeek:"dddd [at] "+o,lastWeek:"[Last] dddd [at] "+o,sameElse:"MM/DD/YYYY"};r.prototype.calendar=function(u,c){var d=c||this.$locale().calendar||l,f=a(u||void 0).startOf("d"),h=this.diff(f,"d",!0),g="sameElse",y=h<-6?g:h<-1?"lastWeek":h<0?"lastDay":h<1?"sameDay":h<2?"nextDay":h<7?"nextWeek":g,C=d[y]||l[y];return typeof C=="function"?C.call(this,a()):this.format(C)}}})})(QD);const UD=ea;var ta={},KD={get exports(){return ta},set exports(e){ta=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){var n={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"},r=/(\[[^[]*\])|([-_:/.,()\s]+)|(A|a|YYYY|YY?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g,a=/\d\d/,o=/\d\d?/,l=/\d*[^-_:/,()\s\d]+/,u={},c=function(w){return(w=+w)+(w>68?1900:2e3)},d=function(w){return function(_){this[w]=+_}},f=[/[+-]\d\d:?(\d\d)?|Z/,function(w){(this.zone||(this.zone={})).offset=function(_){if(!_||_==="Z")return 0;var D=_.match(/([+-]|\d\d)/g),M=60*D[1]+(+D[2]||0);return M===0?0:D[0]==="+"?-M:M}(w)}],h=function(w){var _=u[w];return _&&(_.indexOf?_:_.s.concat(_.f))},g=function(w,_){var D,M=u.meridiem;if(M){for(var O=1;O<=24;O+=1)if(w.indexOf(M(O,0,_))>-1){D=O>12;break}}else D=w===(_?"pm":"PM");return D},y={A:[l,function(w){this.afternoon=g(w,!1)}],a:[l,function(w){this.afternoon=g(w,!0)}],S:[/\d/,function(w){this.milliseconds=100*+w}],SS:[a,function(w){this.milliseconds=10*+w}],SSS:[/\d{3}/,function(w){this.milliseconds=+w}],s:[o,d("seconds")],ss:[o,d("seconds")],m:[o,d("minutes")],mm:[o,d("minutes")],H:[o,d("hours")],h:[o,d("hours")],HH:[o,d("hours")],hh:[o,d("hours")],D:[o,d("day")],DD:[a,d("day")],Do:[l,function(w){var _=u.ordinal,D=w.match(/\d+/);if(this.day=D[0],_)for(var M=1;M<=31;M+=1)_(M).replace(/\[|\]/g,"")===w&&(this.day=M)}],M:[o,d("month")],MM:[a,d("month")],MMM:[l,function(w){var _=h("months"),D=(h("monthsShort")||_.map(function(M){return M.slice(0,3)})).indexOf(w)+1;if(D<1)throw new Error;this.month=D%12||D}],MMMM:[l,function(w){var _=h("months").indexOf(w)+1;if(_<1)throw new Error;this.month=_%12||_}],Y:[/[+-]?\d+/,d("year")],YY:[a,function(w){this.year=c(w)}],YYYY:[/\d{4}/,d("year")],Z:f,ZZ:f};function C(w){var _,D;_=w,D=u&&u.formats;for(var M=(w=_.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(K,Y,H){var se=H&&H.toUpperCase();return Y||D[H]||n[H]||D[se].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(de,xe,Le){return xe||Le.slice(1)})})).match(r),O=M.length,G=0;G<O;G+=1){var $=M[G],L=y[$],A=L&&L[0],N=L&&L[1];M[G]=N?{regex:A,parser:N}:$.replace(/^\[|\]$/g,"")}return function(K){for(var Y={},H=0,se=0;H<O;H+=1){var de=M[H];if(typeof de=="string")se+=de.length;else{var xe=de.regex,Le=de.parser,bt=K.slice(se),Ye=xe.exec(bt)[0];Le.call(Y,Ye),K=K.replace(Ye,"")}}return function(dt){var qe=dt.afternoon;if(qe!==void 0){var vt=dt.hours;qe?vt<12&&(dt.hours+=12):vt===12&&(dt.hours=0),delete dt.afternoon}}(Y),Y}}return function(w,_,D){D.p.customParseFormat=!0,w&&w.parseTwoDigitYear&&(c=w.parseTwoDigitYear);var M=_.prototype,O=M.parse;M.parse=function(G){var $=G.date,L=G.utc,A=G.args;this.$u=L;var N=A[1];if(typeof N=="string"){var K=A[2]===!0,Y=A[3]===!0,H=K||Y,se=A[2];Y&&(se=A[2]),u=this.$locale(),!K&&se&&(u=D.Ls[se]),this.$d=function(bt,Ye,dt){try{if(["x","X"].indexOf(Ye)>-1)return new Date((Ye==="X"?1e3:1)*bt);var qe=C(Ye)(bt),vt=qe.year,Bt=qe.month,gr=qe.day,mr=qe.hours,Aa=qe.minutes,za=qe.seconds,wn=qe.milliseconds,Xt=qe.zone,kt=new Date,Vt=gr||(vt||Bt?1:kt.getDate()),Tt=vt||kt.getFullYear(),Jt=0;vt&&!Bt||(Jt=Bt>0?Bt-1:kt.getMonth());var Zt=mr||0,Cn=Aa||0,Sn=za||0,Dt=wn||0;return Xt?new Date(Date.UTC(Tt,Jt,Vt,Zt,Cn,Sn,Dt+60*Xt.offset*1e3)):dt?new Date(Date.UTC(Tt,Jt,Vt,Zt,Cn,Sn,Dt)):new Date(Tt,Jt,Vt,Zt,Cn,Sn,Dt)}catch{return new Date("")}}($,N,L),this.init(),se&&se!==!0&&(this.$L=this.locale(se).$L),H&&$!=this.format(N)&&(this.$d=new Date("")),u={}}else if(N instanceof Array)for(var de=N.length,xe=1;xe<=de;xe+=1){A[1]=N[xe-1];var Le=D.apply(this,A);if(Le.isValid()){this.$d=Le.$d,this.$L=Le.$L,this.init();break}xe===de&&(this.$d=new Date(""))}else O.call(this,G)}}})})(KD);const XD=ta;var na={},JD={get exports(){return na},set exports(e){na=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){r.prototype.dayOfYear=function(o){var l=Math.round((a(this).startOf("day")-a(this).startOf("year"))/864e5)+1;return o==null?l:this.add(o-l,"day")}}})})(JD);const ZD=na;var ra={},HD={get exports(){return ra},set exports(e){ra=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){var n,r,a=1e3,o=6e4,l=36e5,u=864e5,c=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,d=31536e6,f=2592e6,h=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/,g={years:d,months:f,days:u,hours:l,minutes:o,seconds:a,milliseconds:1,weeks:6048e5},y=function($){return $ instanceof G},C=function($,L,A){return new G($,A,L.$l)},w=function($){return r.p($)+"s"},_=function($){return $<0},D=function($){return _($)?Math.ceil($):Math.floor($)},M=function($){return Math.abs($)},O=function($,L){return $?_($)?{negative:!0,format:""+M($)+L}:{negative:!1,format:""+$+L}:{negative:!1,format:""}},G=function(){function $(A,N,K){var Y=this;if(this.$d={},this.$l=K,A===void 0&&(this.$ms=0,this.parseFromMilliseconds()),N)return C(A*g[w(N)],this);if(typeof A=="number")return this.$ms=A,this.parseFromMilliseconds(),this;if(typeof A=="object")return Object.keys(A).forEach(function(de){Y.$d[w(de)]=A[de]}),this.calMilliseconds(),this;if(typeof A=="string"){var H=A.match(h);if(H){var se=H.slice(2).map(function(de){return de!=null?Number(de):0});return this.$d.years=se[0],this.$d.months=se[1],this.$d.weeks=se[2],this.$d.days=se[3],this.$d.hours=se[4],this.$d.minutes=se[5],this.$d.seconds=se[6],this.calMilliseconds(),this}}return this}var L=$.prototype;return L.calMilliseconds=function(){var A=this;this.$ms=Object.keys(this.$d).reduce(function(N,K){return N+(A.$d[K]||0)*g[K]},0)},L.parseFromMilliseconds=function(){var A=this.$ms;this.$d.years=D(A/d),A%=d,this.$d.months=D(A/f),A%=f,this.$d.days=D(A/u),A%=u,this.$d.hours=D(A/l),A%=l,this.$d.minutes=D(A/o),A%=o,this.$d.seconds=D(A/a),A%=a,this.$d.milliseconds=A},L.toISOString=function(){var A=O(this.$d.years,"Y"),N=O(this.$d.months,"M"),K=+this.$d.days||0;this.$d.weeks&&(K+=7*this.$d.weeks);var Y=O(K,"D"),H=O(this.$d.hours,"H"),se=O(this.$d.minutes,"M"),de=this.$d.seconds||0;this.$d.milliseconds&&(de+=this.$d.milliseconds/1e3);var xe=O(de,"S"),Le=A.negative||N.negative||Y.negative||H.negative||se.negative||xe.negative,bt=H.format||se.format||xe.format?"T":"",Ye=(Le?"-":"")+"P"+A.format+N.format+Y.format+bt+H.format+se.format+xe.format;return Ye==="P"||Ye==="-P"?"P0D":Ye},L.toJSON=function(){return this.toISOString()},L.format=function(A){var N=A||"YYYY-MM-DDTHH:mm:ss",K={Y:this.$d.years,YY:r.s(this.$d.years,2,"0"),YYYY:r.s(this.$d.years,4,"0"),M:this.$d.months,MM:r.s(this.$d.months,2,"0"),D:this.$d.days,DD:r.s(this.$d.days,2,"0"),H:this.$d.hours,HH:r.s(this.$d.hours,2,"0"),m:this.$d.minutes,mm:r.s(this.$d.minutes,2,"0"),s:this.$d.seconds,ss:r.s(this.$d.seconds,2,"0"),SSS:r.s(this.$d.milliseconds,3,"0")};return N.replace(c,function(Y,H){return H||String(K[Y])})},L.as=function(A){return this.$ms/g[w(A)]},L.get=function(A){var N=this.$ms,K=w(A);return K==="milliseconds"?N%=1e3:N=K==="weeks"?D(N/g[K]):this.$d[K],N===0?0:N},L.add=function(A,N,K){var Y;return Y=N?A*g[w(N)]:y(A)?A.$ms:C(A,this).$ms,C(this.$ms+Y*(K?-1:1),this)},L.subtract=function(A,N){return this.add(A,N,!0)},L.locale=function(A){var N=this.clone();return N.$l=A,N},L.clone=function(){return C(this.$ms,this)},L.humanize=function(A){return n().add(this.$ms,"ms").locale(this.$l).fromNow(!A)},L.milliseconds=function(){return this.get("milliseconds")},L.asMilliseconds=function(){return this.as("milliseconds")},L.seconds=function(){return this.get("seconds")},L.asSeconds=function(){return this.as("seconds")},L.minutes=function(){return this.get("minutes")},L.asMinutes=function(){return this.as("minutes")},L.hours=function(){return this.get("hours")},L.asHours=function(){return this.as("hours")},L.days=function(){return this.get("days")},L.asDays=function(){return this.as("days")},L.weeks=function(){return this.get("weeks")},L.asWeeks=function(){return this.as("weeks")},L.months=function(){return this.get("months")},L.asMonths=function(){return this.as("months")},L.years=function(){return this.get("years")},L.asYears=function(){return this.as("years")},$}();return function($,L,A){n=A,r=A().$utils(),A.duration=function(Y,H){var se=A.locale();return C(Y,{$l:se},H)},A.isDuration=y;var N=L.prototype.add,K=L.prototype.subtract;L.prototype.add=function(Y,H){return y(Y)&&(Y=Y.asMilliseconds()),N.bind(this)(Y,H)},L.prototype.subtract=function(Y,H){return y(Y)&&(Y=Y.asMilliseconds()),K.bind(this)(Y,H)}}})})(HD);const eI=ra;var ia={},tI={get exports(){return ia},set exports(e){ia=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){r.prototype.isBetween=function(o,l,u,c){var d=a(o),f=a(l),h=(c=c||"()")[0]==="(",g=c[1]===")";return(h?this.isAfter(d,u):!this.isBefore(d,u))&&(g?this.isBefore(f,u):!this.isAfter(f,u))||(h?this.isBefore(d,u):!this.isAfter(d,u))&&(g?this.isAfter(f,u):!this.isBefore(f,u))}}})})(tI);const nI=ia;var aa={},rI={get exports(){return aa},set exports(e){aa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){r.prototype.isLeapYear=function(){return this.$y%4==0&&this.$y%100!=0||this.$y%400==0}}})})(rI);const iI=aa;var sa={},aI={get exports(){return sa},set exports(e){sa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){a.isMoment=function(o){return a.isDayjs(o)}}})})(aI);const sI=sa;var oa={},oI={get exports(){return oa},set exports(e){oa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){var n="day";return function(r,a,o){var l=function(d){return d.add(4-d.isoWeekday(),n)},u=a.prototype;u.isoWeekYear=function(){return l(this).year()},u.isoWeek=function(d){if(!this.$utils().u(d))return this.add(7*(d-this.isoWeek()),n);var f,h,g,y,C=l(this),w=(f=this.isoWeekYear(),h=this.$u,g=(h?o.utc:o)().year(f).startOf("year"),y=4-g.isoWeekday(),g.isoWeekday()>4&&(y+=7),g.add(y,n));return C.diff(w,"week")+1},u.isoWeekday=function(d){return this.$utils().u(d)?this.day()||7:this.day(this.day()%7?d:d-7)};var c=u.startOf;u.startOf=function(d,f){var h=this.$utils(),g=!!h.u(f)||f;return h.p(d)==="isoweek"?g?this.date(this.date()-(this.isoWeekday()-1)).startOf("day"):this.date(this.date()-1-(this.isoWeekday()-1)+7).endOf("day"):c.bind(this)(d,f)}}})})(oI);const lI=oa;var la={},uI={get exports(){return la},set exports(e){la=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){r.prototype.isoWeeksInYear=function(){var a=this.isLeapYear(),o=this.endOf("y").day();return o===4||a&&o===5?53:52}}})})(uI);const cI=la;var ua={},dI={get exports(){return ua},set exports(e){ua=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){r.prototype.isSameOrAfter=function(a,o){return this.isSame(a,o)||this.isAfter(a,o)}}})})(dI);const pI=ua;var ca={},hI={get exports(){return ca},set exports(e){ca=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){r.prototype.isSameOrBefore=function(a,o){return this.isSame(a,o)||this.isBefore(a,o)}}})})(hI);const fI=ca;var da={},gI={get exports(){return da},set exports(e){da=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){r.prototype.isToday=function(){var o="YYYY-MM-DD",l=a();return this.format(o)===l.format(o)}}})})(gI);const mI=da;var pa={},yI={get exports(){return pa},set exports(e){pa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){r.prototype.isTomorrow=function(){var o="YYYY-MM-DD",l=a().add(1,"day");return this.format(o)===l.format(o)}}})})(yI);const bI=pa;var ha={},vI={get exports(){return ha},set exports(e){ha=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){r.prototype.isYesterday=function(){var o="YYYY-MM-DD",l=a().subtract(1,"day");return this.format(o)===l.format(o)}}})})(vI);const xI=ha;var fa={},wI={get exports(){return fa},set exports(e){fa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){var o=r.prototype,l=function(h){return h&&(h.indexOf?h:h.s)},u=function(h,g,y,C,w){var _=h.name?h:h.$locale(),D=l(_[g]),M=l(_[y]),O=D||M.map(function($){return $.slice(0,C)});if(!w)return O;var G=_.weekStart;return O.map(function($,L){return O[(L+(G||0))%7]})},c=function(){return a.Ls[a.locale()]},d=function(h,g){return h.formats[g]||function(y){return y.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(C,w,_){return w||_.slice(1)})}(h.formats[g.toUpperCase()])},f=function(){var h=this;return{months:function(g){return g?g.format("MMMM"):u(h,"months")},monthsShort:function(g){return g?g.format("MMM"):u(h,"monthsShort","months",3)},firstDayOfWeek:function(){return h.$locale().weekStart||0},weekdays:function(g){return g?g.format("dddd"):u(h,"weekdays")},weekdaysMin:function(g){return g?g.format("dd"):u(h,"weekdaysMin","weekdays",2)},weekdaysShort:function(g){return g?g.format("ddd"):u(h,"weekdaysShort","weekdays",3)},longDateFormat:function(g){return d(h.$locale(),g)},meridiem:this.$locale().meridiem,ordinal:this.$locale().ordinal}};o.localeData=function(){return f.bind(this)()},a.localeData=function(){var h=c();return{firstDayOfWeek:function(){return h.weekStart||0},weekdays:function(){return a.weekdays()},weekdaysShort:function(){return a.weekdaysShort()},weekdaysMin:function(){return a.weekdaysMin()},months:function(){return a.months()},monthsShort:function(){return a.monthsShort()},longDateFormat:function(g){return d(h,g)},meridiem:h.meridiem,ordinal:h.ordinal}},a.months=function(){return u(c(),"months")},a.monthsShort=function(){return u(c(),"monthsShort","months",3)},a.weekdays=function(h){return u(c(),"weekdays",null,null,h)},a.weekdaysShort=function(h){return u(c(),"weekdaysShort","weekdays",3,h)},a.weekdaysMin=function(h){return u(c(),"weekdaysMin","weekdays",2,h)}}})})(wI);const CI=fa;var ga={},SI={get exports(){return ga},set exports(e){ga=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){var n={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"};return function(r,a,o){var l=a.prototype,u=l.format;o.en.formats=n,l.format=function(c){c===void 0&&(c="YYYY-MM-DDTHH:mm:ssZ");var d=this.$locale().formats,f=function(h,g){return h.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(y,C,w){var _=w&&w.toUpperCase();return C||g[w]||n[w]||g[_].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(D,M,O){return M||O.slice(1)})})}(c,d===void 0?{}:d);return u.call(this,f)}}})})(SI);const _I=ga;var ma={},kI={get exports(){return ma},set exports(e){ma=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){var o=function(l,u){if(!u||!u.length||!u[0]||u.length===1&&!u[0].length)return null;var c;u.length===1&&u[0].length>0&&(u=u[0]),c=u[0];for(var d=1;d<u.length;d+=1)u[d].isValid()&&!u[d][l](c)||(c=u[d]);return c};a.max=function(){var l=[].slice.call(arguments,0);return o("isAfter",l)},a.min=function(){var l=[].slice.call(arguments,0);return o("isBefore",l)}}})})(kI);const TI=ma;var ya={},DI={get exports(){return ya},set exports(e){ya=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){var o=r.prototype,l=function(g){var y,C=g.date,w=g.utc,_={};if(!((y=C)instanceof Date||y instanceof Array||o.$utils().u(y)||y.constructor.name!=="Object")){if(!Object.keys(C).length)return new Date;var D=w?a.utc():a();Object.keys(C).forEach(function(K){var Y,H;_[Y=K,H=o.$utils().p(Y),H==="date"?"day":H]=C[K]});var M=_.day||(_.year||_.month>=0?1:D.date()),O=_.year||D.year(),G=_.month>=0?_.month:_.year||_.day?0:D.month(),$=_.hour||0,L=_.minute||0,A=_.second||0,N=_.millisecond||0;return w?new Date(Date.UTC(O,G,M,$,L,A,N)):new Date(O,G,M,$,L,A,N)}return C},u=o.parse;o.parse=function(g){g.date=l.bind(this)(g),u.bind(this)(g)};var c=o.set,d=o.add,f=o.subtract,h=function(g,y,C,w){w===void 0&&(w=1);var _=Object.keys(y),D=this;return _.forEach(function(M){D=g.bind(D)(y[M]*w,M)}),D};o.set=function(g,y){return y=y===void 0?g:y,g.constructor.name==="Object"?h.bind(this)(function(C,w){return c.bind(this)(w,C)},y,g):c.bind(this)(g,y)},o.add=function(g,y){return g.constructor.name==="Object"?h.bind(this)(d,g,y):d.bind(this)(g,y)},o.subtract=function(g,y){return g.constructor.name==="Object"?h.bind(this)(d,g,y,-1):f.bind(this)(g,y)}}})})(DI);const II=ya;var ba={},MI={get exports(){return ba},set exports(e){ba=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){var a=r.prototype;["milliseconds","seconds","minutes","hours","days","weeks","isoWeeks","months","quarters","years","dates"].forEach(function(o){a[o]=a[o.replace(/s$/,"")]})}})})(MI);const AI=ba;var va={},zI={get exports(){return va},set exports(e){va=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){var a=r.prototype.parse;r.prototype.parse=function(u){if(typeof u.date=="string"){var c=this.$locale();u.date=c&&c.preparse?c.preparse(u.date):u.date}return a.bind(this)(u)};var o=r.prototype.format;r.prototype.format=function(){for(var u=arguments.length,c=new Array(u),d=0;d<u;d++)c[d]=arguments[d];var f=o.call.apply(o,[this].concat(c)),h=this.$locale();return h&&h.postformat?h.postformat(f):f};var l=r.prototype.fromToBase;l&&(r.prototype.fromToBase=function(u,c,d,f){var h=this.$locale()||d.$locale();return l.call(this,u,c,d,f,h&&h.postformat)})}})})(zI);const EI=va;var xa={},$I={get exports(){return xa},set exports(e){xa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){var n="month",r="quarter";return function(a,o){var l=o.prototype;l.quarter=function(d){return this.$utils().u(d)?Math.ceil((this.month()+1)/3):this.month(this.month()%3+3*(d-1))};var u=l.add;l.add=function(d,f){return d=Number(d),this.$utils().p(f)===r?this.add(3*d,n):u.bind(this)(d,f)};var c=l.startOf;l.startOf=function(d,f){var h=this.$utils(),g=!!h.u(f)||f;if(h.p(d)===r){var y=this.quarter()-1;return g?this.month(3*y).startOf(n).startOf("day"):this.month(3*y+2).endOf(n).endOf("day")}return c.bind(this)(d,f)}}})})($I);const LI=xa;var wa={},PI={get exports(){return wa},set exports(e){wa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){n=n||{};var o=r.prototype,l={future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"};function u(d,f,h,g){return o.fromToBase(d,f,h,g)}a.en.relativeTime=l,o.fromToBase=function(d,f,h,g,y){for(var C,w,_,D=h.$locale().relativeTime||l,M=n.thresholds||[{l:"s",r:44,d:"second"},{l:"m",r:89},{l:"mm",r:44,d:"minute"},{l:"h",r:89},{l:"hh",r:21,d:"hour"},{l:"d",r:35},{l:"dd",r:25,d:"day"},{l:"M",r:45},{l:"MM",r:10,d:"month"},{l:"y",r:17},{l:"yy",d:"year"}],O=M.length,G=0;G<O;G+=1){var $=M[G];$.d&&(C=g?a(d).diff(h,$.d,!0):h.diff(d,$.d,!0));var L=(n.rounding||Math.round)(Math.abs(C));if(_=C>0,L<=$.r||!$.r){L<=1&&G>0&&($=M[G-1]);var A=D[$.l];y&&(L=y(""+L)),w=typeof A=="string"?A.replace("%d",L):A(L,f,$.l,_);break}}if(f)return w;var N=_?D.future:D.past;return typeof N=="function"?N(w):N.replace("%s",w)},o.to=function(d,f){return u(d,f,this,!0)},o.from=function(d,f){return u(d,f,this)};var c=function(d){return d.$u?a.utc():a()};o.toNow=function(d){return this.to(c(this),d)},o.fromNow=function(d){return this.from(c(this),d)}}})})(PI);const OI=wa;var Ca={},BI={get exports(){return Ca},set exports(e){Ca=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){var n={year:0,month:1,day:2,hour:3,minute:4,second:5},r={};return function(a,o,l){var u,c=function(g,y,C){C===void 0&&(C={});var w=new Date(g),_=function(D,M){M===void 0&&(M={});var O=M.timeZoneName||"short",G=D+"|"+O,$=r[G];return $||($=new Intl.DateTimeFormat("en-US",{hour12:!1,timeZone:D,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:O}),r[G]=$),$}(y,C);return _.formatToParts(w)},d=function(g,y){for(var C=c(g,y),w=[],_=0;_<C.length;_+=1){var D=C[_],M=D.type,O=D.value,G=n[M];G>=0&&(w[G]=parseInt(O,10))}var $=w[3],L=$===24?0:$,A=w[0]+"-"+w[1]+"-"+w[2]+" "+L+":"+w[4]+":"+w[5]+":000",N=+g;return(l.utc(A).valueOf()-(N-=N%1e3))/6e4},f=o.prototype;f.tz=function(g,y){g===void 0&&(g=u);var C=this.utcOffset(),w=this.toDate(),_=w.toLocaleString("en-US",{timeZone:g}),D=Math.round((w-new Date(_))/1e3/60),M=l(_).$set("millisecond",this.$ms).utcOffset(15*-Math.round(w.getTimezoneOffset()/15)-D,!0);if(y){var O=M.utcOffset();M=M.add(C-O,"minute")}return M.$x.$timezone=g,M},f.offsetName=function(g){var y=this.$x.$timezone||l.tz.guess(),C=c(this.valueOf(),y,{timeZoneName:g}).find(function(w){return w.type.toLowerCase()==="timezonename"});return C&&C.value};var h=f.startOf;f.startOf=function(g,y){if(!this.$x||!this.$x.$timezone)return h.call(this,g,y);var C=l(this.format("YYYY-MM-DD HH:mm:ss:SSS"));return h.call(C,g,y).tz(this.$x.$timezone,!0)},l.tz=function(g,y,C){var w=C&&y,_=C||y||u,D=d(+l(),_);if(typeof g!="string")return l(g).tz(_);var M=function(L,A,N){var K=L-60*A*1e3,Y=d(K,N);if(A===Y)return[K,A];var H=d(K-=60*(Y-A)*1e3,N);return Y===H?[K,Y]:[L-60*Math.min(Y,H)*1e3,Math.max(Y,H)]}(l.utc(g,w).valueOf(),D,_),O=M[0],G=M[1],$=l(O).utcOffset(G);return $.$x.$timezone=_,$},l.tz.guess=function(){return Intl.DateTimeFormat().resolvedOptions().timeZone},l.tz.setDefault=function(g){u=g}}})})(BI);const VI=Ca;var Sa={},NI={get exports(){return Sa},set exports(e){Sa=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){r.prototype.toArray=function(){return[this.$y,this.$M,this.$D,this.$H,this.$m,this.$s,this.$ms]}}})})(NI);const qI=Sa;var _a={},FI={get exports(){return _a},set exports(e){_a=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){r.prototype.toObject=function(){return{years:this.$y,months:this.$M,date:this.$D,hours:this.$H,minutes:this.$m,seconds:this.$s,milliseconds:this.$ms}}}})})(FI);const GI=_a;var ka={},WI={get exports(){return ka},set exports(e){ka=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r,a){a.updateLocale=function(o,l){var u=a.Ls[o];if(u)return(l?Object.keys(l):[]).forEach(function(c){u[c]=l[c]}),u}}})})(WI);const jI=ka;var Ta={},RI={get exports(){return Ta},set exports(e){Ta=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){var n="minute",r=/[+-]\d\d(?::?\d\d)?/g,a=/([+-]|\d\d)/g;return function(o,l,u){var c=l.prototype;u.utc=function(w){var _={date:w,utc:!0,args:arguments};return new l(_)},c.utc=function(w){var _=u(this.toDate(),{locale:this.$L,utc:!0});return w?_.add(this.utcOffset(),n):_},c.local=function(){return u(this.toDate(),{locale:this.$L,utc:!1})};var d=c.parse;c.parse=function(w){w.utc&&(this.$u=!0),this.$utils().u(w.$offset)||(this.$offset=w.$offset),d.call(this,w)};var f=c.init;c.init=function(){if(this.$u){var w=this.$d;this.$y=w.getUTCFullYear(),this.$M=w.getUTCMonth(),this.$D=w.getUTCDate(),this.$W=w.getUTCDay(),this.$H=w.getUTCHours(),this.$m=w.getUTCMinutes(),this.$s=w.getUTCSeconds(),this.$ms=w.getUTCMilliseconds()}else f.call(this)};var h=c.utcOffset;c.utcOffset=function(w,_){var D=this.$utils().u;if(D(w))return this.$u?0:D(this.$offset)?h.call(this):this.$offset;if(typeof w=="string"&&(w=function($){$===void 0&&($="");var L=$.match(r);if(!L)return null;var A=(""+L[0]).match(a)||["-",0,0],N=A[0],K=60*+A[1]+ +A[2];return K===0?0:N==="+"?K:-K}(w),w===null))return this;var M=Math.abs(w)<=16?60*w:w,O=this;if(_)return O.$offset=M,O.$u=w===0,O;if(w!==0){var G=this.$u?this.toDate().getTimezoneOffset():-1*this.utcOffset();(O=this.local().add(M+G,n)).$offset=M,O.$x.$localOffset=G}else O=this.utc();return O};var g=c.format;c.format=function(w){var _=w||(this.$u?"YYYY-MM-DDTHH:mm:ss[Z]":"");return g.call(this,_)},c.valueOf=function(){var w=this.$utils().u(this.$offset)?0:this.$offset+(this.$x.$localOffset||this.$d.getTimezoneOffset());return this.$d.valueOf()-6e4*w},c.isUTC=function(){return!!this.$u},c.toISOString=function(){return this.toDate().toISOString()},c.toString=function(){return this.toDate().toUTCString()};var y=c.toDate;c.toDate=function(w){return w==="s"&&this.$offset?u(this.format("YYYY-MM-DD HH:mm:ss:SSS")).toDate():y.call(this)};var C=c.diff;c.diff=function(w,_,D){if(w&&this.$u===w.$u)return C.call(this,w,_,D);var M=this.local(),O=u(w).local();return C.call(M,O,_,D)}}})})(RI);const YI=Ta;var Da={},QI={get exports(){return Da},set exports(e){Da=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){r.prototype.weekday=function(a){var o=this.$locale().weekStart||0,l=this.$W,u=(l<o?l+7:l)-o;return this.$utils().u(a)?u:this.subtract(u,"day").add(a,"day")}}})})(QI);const UI=Da;var Ia={},KI={get exports(){return Ia},set exports(e){Ia=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){var n="week",r="year";return function(a,o,l){var u=o.prototype;u.week=function(c){if(c===void 0&&(c=null),c!==null)return this.add(7*(c-this.week()),"day");var d=this.$locale().yearStart||1;if(this.month()===11&&this.date()>25){var f=l(this).startOf(r).add(1,r).date(d),h=l(this).endOf(n);if(f.isBefore(h))return 1}var g=l(this).startOf(r).date(d).startOf(n).subtract(1,"millisecond"),y=this.diff(g,n,!0);return y<0?l(this).startOf("week").week():Math.ceil(y)},u.weeks=function(c){return c===void 0&&(c=null),this.week(c)}}})})(KI);const XI=Ia;var Ma={},JI={get exports(){return Ma},set exports(e){Ma=e}};(function(e,t){(function(n,r){e.exports=r()})(re,function(){return function(n,r){r.prototype.weekYear=function(){var a=this.month(),o=this.week(),l=this.year();return o===1&&a===11?l+1:a===0&&o>=52?l-1:l}}})})(JI);const ZI=Ma;U.extend(GD),U.extend(jD),U.extend(YD),U.extend(UD),U.extend(XD),U.extend(ZD),U.extend(eI),U.extend(nI),U.extend(iI),U.extend(sI),U.extend(pI),U.extend(fI),U.extend(mI),U.extend(bI),U.extend(xI),U.extend(lI),U.extend(cI),U.extend(CI),U.extend(_I),U.extend(TI),U.extend(II),U.extend(AI),U.extend(EI),U.extend(LI),U.extend(OI),U.extend(VI),U.extend(qI),U.extend(GI),U.extend(jI),U.extend(YI),U.extend(XI),U.extend(ZI),U.extend(UI),U.tz.setDefault("UTC");const HI=()=>Promise.resolve().then(()=>Cc).then(({version:e})=>(console.log(`[@devtable/dashboard] version: ${e}`),e));T.APIClient=at,T.ContentModel=Gi,T.ContentModelContextProvider=zr,T.DashboardApiClient=as,T.DashboardApiFacadeClient=ss,T.DashboardEditor=OD,T.DashboardFilterType=ve,T.DashboardMode=Xl,T.DashboardModel=au,T.DashboardModelContextProvider=Dr,T.DashboardThemeContextProvider=Ar,T.DashboardViewEditor=Kl,T.DashboardViewRender=dr,T.DefaultApiClient=is,T.DescriptionPopover=Bi,T.FacadeApiClient=lc,T.FiltersModel=Zl,T.FullScreenPanel=jl,T.FullScreenPanelContext=$r,T.LayoutStateContext=zn,T.Panel=Wl,T.PanelContextProvider=Er,T.PanelErrorOrStateMessage=Fl,T.PanelModel=tu,T.PanelRender=Ni,T.PanelVizSection=Vi,T.PanelsModel=nu,T.QueriesModel=Hl,T.ReadOnlyDashboard=qD,T.SQLSnippetsModel=eu,T.ViewComponentTypeBackground=Jl,T.ViewComponentTypeColor=k_,T.ViewComponentTypeName=__,T.ViewsModel=ru,T.Viz=ql,T.applyPartialDashboard=B_,T.configureAPIClient=Cr,T.createContentModel=iu,T.createDashboardModel=su,T.facadeApiClient=os,T.getInitialDashboardViewsModel=Fi,T.getVersion=HI,T.initialDashboardContent=T_,T.useDashboardContext=Ir,T.useDashboardThemeContext=ms,T.useEditContentModelContext=le,T.useEditDashboardContext=ue,T.useEditPanelContext=Qe,T.useFullScreenPanelContext=ws,T.usePanelFullScreen=Rl,T.useRenderContentModelContext=ye,T.useRenderDashboardContext=Mr,T.useRenderPanelContext=Ct,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})});
|
|
475
|
+
`)},$T=k.observer(({queryModel:t})=>t.typedAsSQL?d(s.Tabs,{defaultValue:"Edit",orientation:"vertical",sx:{flexGrow:1},styles:{tabLabel:{width:"100%",height:"28px",lineHeight:"28px"}},keepMounted:!1,children:[d(s.Tabs.List,{children:[r(s.Tabs.Tab,{value:"Edit",children:r(s.Group,{spacing:14,position:"apart",children:"Edit SQL"})}),r(s.Tabs.Tab,{value:"Preview",children:"Preview SQL"}),r(s.Tabs.Tab,{value:"pre_process",children:"Process Request"}),r(s.Tabs.Tab,{value:"post_process",children:"Process Result"}),r(Ei,{}),t.datasource&&r(Tl,{dataSource:t.datasource})]}),r(s.Tabs.Panel,{value:"Edit",sx:{position:"relative"},p:"sm",children:r(LT,{value:t.sql,onChange:t.setSQL,defaultValue:"SELECT 1"})}),r(s.Tabs.Panel,{value:"Preview",p:0,pl:4,children:r(OT,{value:t.sql})}),r(s.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:r(Zt,{label:"",value:t.pre_process,onChange:t.setPreProcess,defaultValue:Al.pre})}),r(s.Tabs.Panel,{value:"post_process",p:"sm",children:r(Zt,{label:"",value:t.post_process,onChange:t.setPostProcess,defaultValue:Al.post})})]}):null),Yn={height:"calc(100% - 44px)",padding:0},VT=k.observer(({queryModel:t})=>{const e=H(),n=m.useMemo(()=>t.datasource?t.typedAsHTTP?"HTTP":"SQL":"Configurations",[t.datasource,t.typedAsHTTP]),[i,a]=m.useState(n);m.useEffect(()=>{a(u=>u!=="Configurations"&&n==="Configurations"?"Configurations":u)},[n]);const o=e.findQueryUsage(t.id),l=o.length===0;return d(s.Tabs,{value:i,onTabChange:a,defaultValue:n,orientation:"horizontal",keepMounted:!1,sx:{height:"100vh"},children:[d(s.Tabs.List,{grow:!0,children:[r(s.Tabs.Tab,{value:"Configurations",children:"Configurations"}),t.typedAsSQL&&r(s.Tabs.Tab,{value:"SQL",children:"Request"}),t.typedAsHTTP&&r(s.Tabs.Tab,{value:"HTTP",children:"Request"}),r(s.Tabs.Tab,{value:"Data",disabled:!t.datasource,children:r(s.Tooltip,{label:"Need to pick a Data Source first",disabled:t.datasource,withinPortal:!0,children:r(s.Text,{children:"Data"})})}),r(s.Tabs.Tab,{value:"Usage",disabled:l,children:r(s.Tooltip,{label:"This query is not used for any filter or panel",disabled:!l,withinPortal:!0,children:r(s.Text,{children:"Usage"})})})]}),r(s.Tabs.Panel,{value:"Configurations",pt:0,p:0,children:r(IT,{queryModel:t})}),t.typedAsSQL&&r(s.Tabs.Panel,{value:"SQL",sx:Yn,children:r(s.Stack,{sx:{height:"100%"},children:r($T,{queryModel:t})})}),t.typedAsHTTP&&r(s.Tabs.Panel,{value:"HTTP",sx:Yn,children:r(s.Stack,{sx:{height:"100%"},children:r(ET,{queryModel:t})})}),r(s.Tabs.Panel,{value:"Data",sx:{...Yn,overflow:"hidden"},children:r(Ai,{id:t.id,moreActions:null,refreshOnMount:!0})}),r(s.Tabs.Panel,{value:"Usage",sx:{...Yn,overflow:"hidden"},children:r(PT,{queryID:t.id,usage:o})})]})}),NT=k.observer(({id:t})=>{const n=H().queries.findByID(t);return t===""?null:n?r(VT,{queryModel:n}):r(s.Text,{size:14,color:"red",children:"Invalid Query ID"})}),qT=k.observer(({value:t})=>{const n=ue().payloadForSQL,i=m.useMemo(()=>ir(t,n),[t,n]);return r(Pi,{height:"100%",value:i})}),GT=k.observer(({item:t,remove:e,onKeyChanged:n})=>{const[i,a]=m.useState("SQL"),[o,l]=m.useState(t.key),u=()=>{t.setKey(o),n(o)},c=o!==t.key,p=t.isADuplicatedKey(o),[h,f]=m.useState(t.value),g=()=>{t.setValue(h)};m.useEffect(()=>{l(t.key),f(t.value)},[t]);const b=h!==t.value,w=Ee.useModals(),_=()=>{w.openConfirmModal({title:"Delete this SQL snippet?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:e,confirmProps:{color:"red"},zIndex:320})};return d(s.Stack,{p:20,sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",children:[d(s.Group,{sx:{alignItems:"end"},spacing:40,children:[r(s.TextInput,{label:p?"This key is occupied by another snippet":"Key",value:o,onChange:D=>{l(D.currentTarget.value)},sx:{flexGrow:"1 !important"},rightSection:r(s.ActionIcon,{color:"blue",variant:"subtle",onClick:u,disabled:!c||p,children:r(T.DeviceFloppy,{size:16})}),error:p}),r(s.Button,{leftIcon:r(T.Trash,{size:16}),color:"red",variant:"light",onClick:_,children:"Delete this SQL Snippet"})]}),d(s.Tabs,{value:i,onTabChange:a,sx:{flexGrow:1},styles:{panel:{height:"calc(100% - 50px)"}},children:[d(s.Tabs.List,{sx:{position:"relative"},children:[r(s.Tabs.Tab,{value:"SQL",children:"SQL"}),r(s.Tabs.Tab,{value:"Preview",children:"Preview"}),r(Ei,{}),r(s.ActionIcon,{color:"blue",variant:"filled",onClick:g,disabled:!b,sx:{position:"absolute",top:0,right:10},children:r(T.DeviceFloppy,{size:18})})]}),r(s.Tabs.Panel,{value:"SQL",pt:"sm",children:r(Pi,{height:"100%",value:h,onChange:f,defaultLanguage:"sql",theme:"sql-dark"})}),r(s.Tabs.Panel,{value:"Preview",pt:"sm",children:r(qT,{value:h})})]})]})}),FT=k.observer(({id:t})=>{const e=ee(),n=H(),i=m.useMemo(()=>n.sqlSnippets.findByKey(t),[t]);if(!t)return null;if(!i)return d(s.Text,{size:14,children:["SQL Snippet by key[",t,"] is not found"]});const a=()=>{e.editor.setPath(["_SQL_SNIPPETS_",""])};return r(GT,{item:i,remove:()=>{n.sqlSnippets.removeByKey(t),a()},onKeyChanged:u=>{e.editor.setPath(["_SQL_SNIPPETS_",u])}})}),jT=k.observer(({view:t})=>!t||t.type!==$.Division?null:d(s.Stack,{children:[r(s.Divider,{mt:8,mb:0,label:"Division settings",labelPosition:"center"}),r(s.Text,{align:"center",size:"xs",color:"dimmed",children:"Under construction"})]})),WT=[{value:"default",label:"Default"},{value:"outline",label:"Outline"},{value:"pills",label:"Pills"}],RT=[{value:"horizontal",label:"Horizontal"},{value:"vertical",label:"Vertical"}],QT=k.observer(({view:t})=>{if(!t||t.type!==$.Tabs)return null;const e=t.config;return d(s.Stack,{children:[r(s.Divider,{mt:8,mb:0,label:"Tabs settings",labelPosition:"center"}),r(s.Select,{label:"Variant",value:e.variant,onChange:e.setVariant,data:WT}),r(s.Select,{label:"Orientation",value:e.orientation,onChange:e.setOrientation,data:RT}),r(s.Switch,{label:"Grow Tabs",checked:e.grow,onChange:n=>e.setGrow(n.currentTarget.checked)})]})}),UT=({disabled:t,value:e,onChange:n})=>{const i=a=>{a&&n(a)};return d(s.Box,{sx:{position:"relative"},children:[t&&r(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),r(ve,{height:"500px",defaultLanguage:"javascript",value:e,onChange:i,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},KT=({value:t,onChange:e})=>{const[n,{setTrue:i,setFalse:a}]=q.useBoolean(),[o,l]=m.useState(t??bi),u=g=>{l({...o,enabled:g})},c=()=>{a();const{enabled:g,func_content:b}=o,w={enabled:g,func_content:b};l(w),e(w)},p=()=>{a(),l(t)},h=g=>{l(b=>({...b,func_content:g}))},f=()=>{h(bi.func_content)};return d(z,{children:[r(s.ActionIcon,{size:"lg",color:"blue",variant:"filled",mt:26,onClick:i,sx:{flexGrow:0},children:r(T.Settings,{size:14})}),r(s.Modal,{size:800,title:"Customize modal title",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&d(s.Stack,{children:[r(s.Checkbox,{mt:10,label:"Enabled",checked:o.enabled,onChange:g=>u(g.currentTarget.checked)}),r(UT,{value:o.func_content,onChange:h,disabled:!o.enabled}),d(s.Group,{position:"apart",children:[r(s.Button,{onClick:f,color:"red",leftIcon:r(T.Recycle,{size:20}),children:"Reset"}),d(s.Group,{position:"right",children:[r(s.Button,{onClick:p,variant:"subtle",children:"Cancel"}),r(s.Button,{onClick:c,children:"OK"})]})]})]})})]})},YT=k.observer(({view:t})=>{if(!t||t.type!==$.Modal)return null;const e=t.config,n=e.custom_modal_title.value;return d(s.Stack,{children:[r(s.Divider,{mt:8,label:"Modal settings",labelPosition:"center"}),d(s.Flex,{gap:10,children:[r(s.TextInput,{label:"Modal Title",value:n,onChange:x.noop,disabled:!0,sx:{flexGrow:1}}),r(KT,{value:e.custom_modal_title,onChange:e.custom_modal_title.replace})]}),d(s.Group,{grow:!0,children:[r(s.TextInput,{label:"Width",value:e.width,onChange:i=>e.setWidth(i.currentTarget.value),placeholder:"600px / 50vw"}),r(s.TextInput,{label:"Height",value:e.height,onChange:i=>e.setHeight(i.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),XT=k.observer(({view:t})=>d(z,{children:[r(jT,{view:t}),r(YT,{view:t}),r(QT,{view:t})]})),JT=[{label:"Division",value:$.Division},{label:"Modal",value:$.Modal},{label:"Tabs",value:$.Tabs}],ZT=k.observer(({view:t})=>t?d(s.Stack,{sx:{position:"relative"},children:[r(s.TextInput,{label:"Name",value:t.name,onChange:e=>{t.setName(e.currentTarget.value)}}),r(s.Select,{label:"Type",withinPortal:!0,zIndex:320,value:t.type,onChange:t.setType,data:JT}),r(XT,{view:t})]}):null),HT=k.observer(({id:t})=>{const e=Ee.useModals(),n=ee(),i=H();if(t==="")return null;const a=i.views.findByID(t);if(!a)return d(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:()=>{i.views.removeByID(t),o()},zIndex:320})};return d(s.Stack,{sx:{maxWidth:"600px",height:"100%"},spacing:"sm",children:[r(s.Group,{position:"right",pt:10,children:r(s.Button,{size:"xs",color:"red",leftIcon:r(T.Trash,{size:16}),onClick:l,children:"Delete this view"})}),r(s.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:r(ZT,{view:a})})]})});function eD(t){return t.length===1&&t[0]==="_QUERY_VARS_"}function tD(t){return t.length===1&&t[0]==="_MOCK_CONTEXT_"}function nD(t){return t.length===2&&t[0]==="_FILTERS_"}function rD(t){return t.length===1&&t[0]==="_SQL_SNIPPETS_"}function iD(t){return t.length===2&&t[0]==="_SQL_SNIPPETS_"}function aD(t){return t.length===2&&t[0]==="_QUERIES_"}function sD(t){return t.length===1&&t[0]==="_QUERIES_"}function oD(t){return t.length===2&&t[0]==="_VIEWS_"}function lD(t){return t.length===4&&t[0]==="_VIEWS_"&&t[2]==="_PANELS_"}const uD=k.observer(()=>r(s.Stack,{sx:{height:"100%"},p:"sm",children:r(Il,{})})),cD=k.observer(()=>{const t=Ee.useModals(),e=ee(),n=o=>{e.editor.setPath(["_QUERIES_",o])},i=()=>{t.openConfirmModal({title:"Delete ununsed queries?",children:r(s.Text,{size:"sm",children:"This action cannot be undone."}),labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>e.content.removeUnusedQueries(),confirmProps:{color:"red"},zIndex:320})},a=e.content.queriesUsage;return d(s.Stack,{sx:{height:"100%"},spacing:"sm",pb:"59px",children:[r(s.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:r(s.Text,{px:"md",align:"left",sx:{userSelect:"none",cursor:"default"},children:"Manage Queries"})}),r(s.Flex,{justify:"flex-end",align:"center",px:12,children:r(s.Button,{variant:"subtle",size:"xs",color:"red",leftIcon:r(M.IconTrash,{size:14}),disabled:!e.content.hasUnusedQueries,onClick:i,children:"Delete unused queries"})}),r(s.Box,{sx:{flexGrow:1,overflow:"auto"},children:d(s.Table,{fontSize:"sm",highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[r("thead",{children:d("tr",{children:[r("th",{children:"Name"}),r("th",{style:{width:"200px"},children:"Data Source"}),r("th",{style:{width:"100px",textAlign:"right"},children:"Type"}),r("th",{style:{width:"100px",textAlign:"center"},children:"Usage"}),r("th",{style:{width:"300px",paddingLeft:"24px"},children:"Action"})]})}),r("tbody",{children:e.content.queries.sortedList.map(o=>{var u;const l=((u=a[o.id])==null?void 0:u.length)??0;return d("tr",{children:[r("td",{children:o.name}),r("td",{children:o.key}),r("td",{style:{textAlign:"right"},children:o.type}),r("td",{style:{color:l===0?"#ff0000":"#000",fontWeight:l===0?"bold":"normal",textAlign:"center"},children:l}),r("td",{children:r(s.Button,{variant:"subtle",size:"xs",onClick:()=>n(o.id),children:"Open"})})]},o.id)})})]})})]})}),dD=k.observer(()=>{const t=Ee.useModals(),e=ee(),n=o=>{e.editor.setPath(["_SQL_SNIPPETS_",o])},i=()=>{t.openConfirmModal({title:"Delete ununsed SQL snippets?",children:r(s.Text,{size:"sm",children:"This action cannot be undone."}),labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>e.content.removeUnusedSQLSnippets(),confirmProps:{color:"red"},zIndex:320})},a=e.content.sqlSnippetsUsage;return d(s.Stack,{sx:{height:"100%"},spacing:"sm",pb:"59px",children:[r(s.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:r(s.Text,{px:"md",align:"left",sx:{userSelect:"none",cursor:"default"},children:"Manage SQL Snippets"})}),r(s.Flex,{justify:"flex-end",align:"center",px:12,children:r(s.Button,{variant:"subtle",size:"xs",color:"red",leftIcon:r(M.IconTrash,{size:14}),disabled:!e.content.hasUnusedSQLSnippets,onClick:i,children:"Delete unused SQL snippets"})}),r(s.Box,{sx:{flexGrow:1,overflow:"auto"},children:d(s.Table,{fontSize:"sm",highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[r("thead",{children:d("tr",{children:[r("th",{children:"Key"}),r("th",{style:{width:"100px",textAlign:"center"},children:"Usage"}),r("th",{style:{width:"300px",paddingLeft:"24px"},children:"Action"})]})}),r("tbody",{children:e.content.sqlSnippets.sortedList.map(o=>{var u;const l=((u=a[o.key])==null?void 0:u.length)??0;return d("tr",{children:[r("td",{children:o.key}),r("td",{style:{color:l===0?"#ff0000":"#000",fontWeight:l===0?"bold":"normal",textAlign:"center"},children:l}),r("td",{children:r(s.Button,{variant:"subtle",size:"xs",onClick:()=>n(o.key),children:"Open"})})]},o.key)})})]})})]})}),pD=k.observer(()=>{const t=ee().editor,e=t.path;return eD(e)?r(uD,{}):tD(e)?r(Tk,{}):nD(e)?r(s.Box,{p:"xs",pl:20,children:r(kk,{id:e[1]})}):rD(e)?r(dD,{}):iD(e)?r(FT,{id:e[1]}):sD(e)?r(cD,{}):aD(e)?r(NT,{id:e[1]}):oD(e)?r(s.Box,{p:"xs",pl:20,children:r(HT,{id:e[1]})}):lD(e)?r(oT,{viewID:e[1],panelID:e[3]}):r(s.Box,{children:t.path})}),hD=k.observer(()=>r(pD,{})),fD=k.observer(()=>{const t=ee(),e=()=>{const n=new Date().getTime().toString(),i={id:n,key:n,label:n,order:t.content.filters.current.length+1,type:de.TextInput,config:Co(),visibleInViewsIDs:["Main"],auto_submit:!1};t.content.filters.append(i),t.editor.setPath(["_FILTERS_",n])};return r(s.Button,{variant:"subtle",leftIcon:r(M.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"})}),gD=k.observer(({parentID:t})=>{const e=H();if(!t)return null;const n=e.views.findByID(t);return!n||n.type===$.Tabs?null:r(s.Button,{variant:"subtle",leftIcon:r(M.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"})}),mD=k.observer(()=>{const t=ee(),e=()=>{const n=new Date().getTime().toString(),i={id:n,name:n,type:ze.Postgresql,key:"",sql:""};t.content.queries.append(i),t.editor.setPath(["_QUERIES_",n])};return r(s.Button,{variant:"subtle",leftIcon:r(M.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"})}),yD=k.observer(()=>{const t=ee(),e=()=>{const n=new Date().getTime().toString(),i={key:n,value:""};t.content.sqlSnippets.append(i),t.editor.setPath(["_SQL_SNIPPETS_",n])};return r(s.Button,{variant:"subtle",leftIcon:r(M.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"})}),bD=k.observer(()=>{const t=H();return r(s.Button,{variant:"subtle",leftIcon:r(M.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"})}),vD=k.observer(()=>{const t=ee();return r(s.Button,{variant:"subtle",rightIcon:r(M.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>t.editor.setPath(["_QUERIES_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:"Manage Queries"})}),xD=k.observer(()=>{const t=ee();return r(s.Button,{variant:"subtle",rightIcon:r(M.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>t.editor.setPath(["_SQL_SNIPPETS_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:"Manage SQL Snippets"})}),wD=k.observer(({action_type:t,parentID:e})=>t==="_Add_A_Filter_"?r(fD,{}):t==="_Add_A_SQL_SNIPPET_"?r(yD,{}):t==="_Add_A_QUERY_"?r(mD,{}):t==="_Add_A_VIEW_"?r(bD,{}):t==="_Add_A_PANEL_"?r(gD,{parentID:e}):t==="_QUERIES_SETTINGS_"?r(vD,{}):t==="_SQL_SNIPPETS_SETTINGS_"?r(xD,{}):null),zl=k.observer(({option:t})=>{var p;const e=ee().editor,n=e.isOptionActive,i=n(e.path,t),a=e.isOptionOpened,o=e.navigate,l=a(t),[u,c]=m.useState(l);return m.useEffect(()=>{c(l)},[l]),r(s.NavLink,{active:i,defaultOpened:l,opened:u,onChange:c,label:t.label,onClick:()=>o(t),icon:t.Icon?r(t.Icon,{size:18}):null,children:(p=t.children)==null?void 0:p.map(h=>h._type==="ACTION"?r(wD,{action_type:h._action_type,parentID:h.parentID},`_ADD_${h.value}_`):r(zl,{option:h},h.value))},t.label)}),CD=k.observer(()=>{const t=ee();return r(s.Box,{sx:{position:"relative"},children:t.editor.navOptions.map(e=>r(zl,{option:e},e.value))})}),SD=k.observer(()=>{const t=ee();return d(s.Navbar,{p:0,width:{base:220,xs:220,sm:240,md:260,lg:300,xl:320},sx:{height:"100vh - 60px - 60px"},children:[r(s.Navbar.Section,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:r(s.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Settings"})}),r(s.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:r(CD,{})}),r(s.Navbar.Section,{children:r(s.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:r(s.Button,{size:"xs",color:"red",leftIcon:r(M.IconX,{size:18}),onClick:()=>t.editor.close(),children:"Close"})})})]})}),_D={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden",minWidth:"calc(var(--mantine-navbar-width, 0px) + 1000px)"},body:{flexGrow:1,nav:{top:0,height:"100vh"}},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:0,height:"100vh"}},kD=k.observer(()=>{const t=ee().editor;return r(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"},content:{overflowY:"hidden !important"}},children:r(s.AppShell,{padding:0,navbar:r(SD,{}),styles:_D,children:r(hD,{})})})}),TD=t=>t.replace(/([^:])(\/\/+)/g,"$1/");function DD(t){m.useEffect(()=>{if(ve.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const n=TD(t);ve.loader.config({paths:{vs:n}}),ve.loader.init().then(i=>console.log("monaco instance:",i))},[])}Ts();const ID={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:60+30,height:"100vh"}},MD=({context:t,dashboard:e,content:n,update:i,className:a="dashboard",config:o,onChange:l,headerSlot:u},c)=>{DD(o.monacoPath),ar(o);const{data:p=[]}=q.useRequest(or),{data:h=[]}=q.useRequest(ga),f=m.useMemo(()=>pl(e,n,p,h,t),[e,n]);m.useImperativeHandle(c,()=>f,[f]),hl(f.content,!0),m.useEffect(()=>{f.context.replace(t)},[t]),m.useEffect(()=>{f.datasources.replace(p)},[p]),m.useEffect(()=>{f.globalSQLSnippets.replace(h)},[h]),m.useEffect(()=>Q.reaction(()=>Q.toJS(f.json),_=>{l==null||l(_)}),[f]);const g=async()=>{await i(f.json,f.content.json)},b=q.useCreation(gi,[]),w=fl(b);return r(Ee.ModalsProvider,{children:r(hr,{value:{searchButtonProps:o.searchButtonProps},children:r(cr,{value:f,children:r(fr,{value:f.content,children:r(pn.Provider,{value:{inEditMode:!0},children:r(tt.Provider,{value:b,children:d(Gn,{configure:w,children:[r(s.AppShell,{padding:0,header:r($1,{saveDashboardChanges:g,headerSlot:u}),navbar:r(ck,{}),styles:ID,children:r(s.Box,{className:`${a} dashboard-root`,sx:{position:"relative"},children:f.content.views.visibleViews.map(_=>r(tl,{view:_},_.id))})}),r(kD,{})]})})})})})})})},AD=k.observer(m.forwardRef(MD)),MI="",El=y.types.model({id:y.types.string,name:y.types.string,dashboard_id:y.types.string,create_time:y.types.string,update_time:y.types.string,version:y.types.string,filters:Bo,queries:qo,sqlSnippets:Go,views:zo,panels:Po,mock_context:fo}).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 payloadForSQL(){const e=y.getParent(t).context.current,n=y.getParent(t).globalSQLSnippets,i={context:{...t.mock_context.current,...e},filters:t.filters.values};return{...i,sql_snippets:Wn(t.sqlSnippets.current,"key","value",i),global_sql_snippets:Wn(n.list,"id","content",i)}},get payloadForViz(){const e=y.getParent(t).context.current;return{context:{...t.mock_context.current,...e},filters:t.filters.values}},get dashboardState(){return sr(this.payloadForSQL)},getAdditionalQueryInfo(e){return{content_id:t.id,query_id:e,params:this.dashboardState}},get data(){return t.queries.current.map(({id:n,data:i})=>({id:n,data:i})).reduce((n,i)=>(n[i.id]=i.data,n),{})},getDataStuffByID(e){const n=t.queries.findByID(e);return n?{data:n.data,len:n.data.length,state:n.state,error:n.error}:{data:[],len:0,state:"idle",error:void 0}}})).actions(t=>({}));function zD({id:t,name:e,dashboard_id:n,create_time:i,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:p,definition:{queries:h,sqlSnippets:f,mock_context:g={}}}=o;return El.create({id:t,name:e,dashboard_id:n,create_time:i,update_time:a,version:l,filters:Oo(u),queries:B_(h),sqlSnippets:$_(f),mock_context:go(g),views:S_(c),panels:{list:p}})}const ED=y.types.model({id:y.types.identifier,name:y.types.string,group:y.types.string,content:El,content_id:y.types.string,datasources:x_,globalSQLSnippets:Mo,context:vi});function PD({id:t,name:e,group:n,content_id:i},a,o,l,u){return ED.create({id:t,name:e,group:n,content_id:i,content:zD(a),datasources:{list:o},globalSQLSnippets:{list:l},context:Ao(u)})}Ts();const LD=k.observer(({context:t,dashboard:e,content:n,className:i="dashboard",config:a,fullScreenPanelID:o,setFullScreenPanelID:l})=>{ar(a);const{data:u=[]}=q.useRequest(or),{data:c=[]}=q.useRequest(ga),p=m.useMemo(()=>PD(e,n,u,c,t),[e,n]);hl(p.content,!1),m.useEffect(()=>{p.context.replace(t)},[t]),m.useEffect(()=>{p.datasources.replace(u)},[u]),m.useEffect(()=>{p.globalSQLSnippets.replace(c)},[c]);const h=q.useCreation(gi,[]),f=fl(h);return r(Ee.ModalsProvider,{children:r(hr,{value:{searchButtonProps:a.searchButtonProps},children:r(cr,{value:p,children:r(fr,{value:p.content,children:r(mr.Provider,{value:{fullScreenPanelID:o,setFullScreenPanelID:l},children:r(pn.Provider,{value:{inEditMode:!1},children:r(s.Box,{className:`${i} dashboard-root`,children:r(tt.Provider,{value:h,children:r(Gn,{configure:f,children:p.content.views.visibleViews.map(g=>r(Qn,{view:g},g.id))})})})})})})})})})});G.extend(cu),G.extend(du),G.extend(pu),G.extend(hu),G.extend(fu),G.extend(gu),G.extend(mu),G.extend(yu),G.extend(bu),G.extend(vu),G.extend(Cu),G.extend(Su),G.extend(_u),G.extend(ku),G.extend(Tu),G.extend(xu),G.extend(wu),G.extend(Du),G.extend(Iu),G.extend(Mu),G.extend(Au),G.extend(zu),G.extend(Eu),G.extend(Pu),G.extend(Lu),G.extend(Bu),G.extend(Ou),G.extend($u),G.extend(Vu),G.extend(Nu),G.extend(Gu),G.extend(Fu),G.extend(qu),G.tz.setDefault("UTC");const BD=()=>Promise.resolve().then(()=>mc).then(({version:t})=>(console.log(`[@devtable/dashboard] version: ${t}`),t));S.APIClient=Xe,S.ContentModel=ki,S.ContentModelContextProvider=fr,S.DashboardApiClient=da,S.DashboardApiFacadeClient=pa,S.DashboardEditor=AD,S.DashboardFilterType=de,S.DashboardMode=nl,S.DashboardModel=dl,S.DashboardModelContextProvider=cr,S.DashboardThemeContextProvider=hr,S.DashboardViewEditor=tl,S.DashboardViewRender=Qn,S.DefaultApiClient=ca,S.DescriptionPopover=xi,S.FacadeApiClient=nc,S.FiltersModel=il,S.FullScreenPanel=Xo,S.FullScreenPanelContext=mr,S.LayoutStateContext=pn,S.Panel=Yo,S.PanelContextProvider=gr,S.PanelErrorOrStateMessage=Uo,S.PanelModel=ol,S.PanelRender=Ci,S.PanelVizSection=wi,S.PanelsModel=ll,S.QueriesModel=al,S.ReadOnlyDashboard=LD,S.SQLSnippetsModel=sl,S.ViewComponentTypeBackground=rl,S.ViewComponentTypeColor=v1,S.ViewComponentTypeName=b1,S.ViewsModel=ul,S.Viz=Qo,S.applyPartialDashboard=z1,S.configureAPIClient=ar,S.createContentModel=cl,S.createDashboardModel=pl,S.facadeApiClient=ha,S.getInitialDashboardViewsModel=_i,S.getVersion=BD,S.initialDashboardContent=x1,S.useDashboardContext=dr,S.useDashboardThemeContext=Ca,S.useEditContentModelContext=H,S.useEditDashboardContext=ee,S.useEditPanelContext=$e,S.useFullScreenPanelContext=Da,S.usePanelFullScreen=Jo,S.useRenderContentModelContext=ue,S.useRenderDashboardContext=pr,S.useRenderPanelContext=dt,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})});
|