@devtable/dashboard 12.1.0 → 12.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- (function(v,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("react"),require("@mantine/core"),require("@mantine/modals"),require("ahooks"),require("mobx"),require("mobx-react-lite"),require("@faker-js/faker"),require("crypto-js"),require("d3-array"),require("dayjs"),require("lodash"),require("mathjs"),require("numbro"),require("axios"),require("@mantine/hooks"),require("popmotion"),require("echarts/core"),require("js-base64"),require("eventemitter2"),require("chroma-js"),require("echarts-for-react/lib/core"),require("echarts-gl"),require("echarts/components"),require("echarts/renderers"),require("react-hook-form"),require("tabler-icons-react"),require("echarts/charts"),require("@tabler/icons-react"),require("@mantine/notifications"),require("@monaco-editor/react"),require("d3-regression"),require("@mantine/tiptap"),require("@tiptap/extension-color"),require("@tiptap/extension-highlight"),require("@tiptap/extension-placeholder"),require("@tiptap/extension-subscript"),require("@tiptap/extension-superscript"),require("@tiptap/extension-text-align"),require("@tiptap/extension-text-style"),require("@tiptap/extension-table"),require("@tiptap/extension-table-cell"),require("@tiptap/extension-table-header"),require("@tiptap/extension-table-row"),require("@tiptap/extension-underline"),require("@tiptap/react"),require("@tiptap/starter-kit"),require("prosemirror-keymap"),require("prosemirror-commands"),require("prosemirror-schema-list"),require("@mantine/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("uuid"),require("performant-array-to-tree"),require("file-saver"),require("dom-to-image-more"),require("jszip"),require("@json2csv/whatwg"),require("dayjs/plugin/advancedFormat"),require("dayjs/plugin/arraySupport"),require("dayjs/plugin/buddhistEra"),require("dayjs/plugin/calendar"),require("dayjs/plugin/customParseFormat"),require("dayjs/plugin/dayOfYear"),require("dayjs/plugin/duration"),require("dayjs/plugin/isBetween"),require("dayjs/plugin/isLeapYear"),require("dayjs/plugin/isMoment"),require("dayjs/plugin/isoWeek"),require("dayjs/plugin/isoWeeksInYear"),require("dayjs/plugin/isSameOrAfter"),require("dayjs/plugin/isSameOrBefore"),require("dayjs/plugin/isToday"),require("dayjs/plugin/isTomorrow"),require("dayjs/plugin/isYesterday"),require("dayjs/plugin/localeData"),require("dayjs/plugin/localizedFormat"),require("dayjs/plugin/minMax"),require("dayjs/plugin/objectSupport"),require("dayjs/plugin/pluralGetSet"),require("dayjs/plugin/preParsePostFormat"),require("dayjs/plugin/quarterOfYear"),require("dayjs/plugin/relativeTime"),require("dayjs/plugin/timezone"),require("dayjs/plugin/toArray"),require("dayjs/plugin/toObject"),require("dayjs/plugin/updateLocale"),require("dayjs/plugin/utc"),require("dayjs/plugin/weekday"),require("dayjs/plugin/weekOfYear"),require("dayjs/plugin/weekYear"),require("reactflow")):typeof define=="function"&&define.amd?define(["exports","react","@mantine/core","@mantine/modals","ahooks","mobx","mobx-react-lite","@faker-js/faker","crypto-js","d3-array","dayjs","lodash","mathjs","numbro","axios","@mantine/hooks","popmotion","echarts/core","js-base64","eventemitter2","chroma-js","echarts-for-react/lib/core","echarts-gl","echarts/components","echarts/renderers","react-hook-form","tabler-icons-react","echarts/charts","@tabler/icons-react","@mantine/notifications","@monaco-editor/react","d3-regression","@mantine/tiptap","@tiptap/extension-color","@tiptap/extension-highlight","@tiptap/extension-placeholder","@tiptap/extension-subscript","@tiptap/extension-superscript","@tiptap/extension-text-align","@tiptap/extension-text-style","@tiptap/extension-table","@tiptap/extension-table-cell","@tiptap/extension-table-header","@tiptap/extension-table-row","@tiptap/extension-underline","@tiptap/react","@tiptap/starter-kit","prosemirror-keymap","prosemirror-commands","prosemirror-schema-list","@mantine/prism","@tanstack/react-table","react-virtual","@mantine/dates","rc-select","rc-tree-select","react-grid-layout","mobx-state-tree","uuid","performant-array-to-tree","file-saver","dom-to-image-more","jszip","@json2csv/whatwg","dayjs/plugin/advancedFormat","dayjs/plugin/arraySupport","dayjs/plugin/buddhistEra","dayjs/plugin/calendar","dayjs/plugin/customParseFormat","dayjs/plugin/dayOfYear","dayjs/plugin/duration","dayjs/plugin/isBetween","dayjs/plugin/isLeapYear","dayjs/plugin/isMoment","dayjs/plugin/isoWeek","dayjs/plugin/isoWeeksInYear","dayjs/plugin/isSameOrAfter","dayjs/plugin/isSameOrBefore","dayjs/plugin/isToday","dayjs/plugin/isTomorrow","dayjs/plugin/isYesterday","dayjs/plugin/localeData","dayjs/plugin/localizedFormat","dayjs/plugin/minMax","dayjs/plugin/objectSupport","dayjs/plugin/pluralGetSet","dayjs/plugin/preParsePostFormat","dayjs/plugin/quarterOfYear","dayjs/plugin/relativeTime","dayjs/plugin/timezone","dayjs/plugin/toArray","dayjs/plugin/toObject","dayjs/plugin/updateLocale","dayjs/plugin/utc","dayjs/plugin/weekday","dayjs/plugin/weekOfYear","dayjs/plugin/weekYear","reactflow"],g):(v=typeof globalThis<"u"?globalThis:v||self,g(v.dashboard={},v.react,v["@mantine/core"],v["@mantine/modals"],v.ahooks,v.mobx,v["mobx-react-lite"],v["@faker-js/faker"],v.CryptoJS,v["d3-array"],v.dayjs,v._,v.mathjs,v.numbro,v.axios,v["@mantine/hooks"],v.popmotion,v["echarts/core"],v["js-base64"],v.eventemitter2,v["chroma-js"],v["echarts-for-react/lib/core"],v["echarts-gl"],v["echarts/components"],v["echarts/renderers"],v["react-hook-form"],v["tabler-icons-react"],v["echarts/charts"],v["@tabler/icons-react"],v["@mantine/notifications"],v["@monaco-editor/react"],v["d3-regression"],v["@mantine/tiptap"],v["@tiptap/extension-color"],v["@tiptap/extension-highlight"],v["@tiptap/extension-placeholder"],v["@tiptap/extension-subscript"],v["@tiptap/extension-superscript"],v["@tiptap/extension-text-align"],v["@tiptap/extension-text-style"],v["@tiptap/extension-table"],v["@tiptap/extension-table-cell"],v["@tiptap/extension-table-header"],v["@tiptap/extension-table-row"],v["@tiptap/extension-underline"],v["@tiptap/react"],v["@tiptap/starter-kit"],v["prosemirror-keymap"],v["prosemirror-commands"],v["prosemirror-schema-list"],v["@mantine/prism"],v["@tanstack/react-table"],v["react-virtual"],v["@mantine/dates"],v["rc-select"],v["rc-tree-select"],v["react-grid-layout"],v["mobx-state-tree"],v.uuid,v["performant-array-to-tree"],v["file-saver"],v["dom-to-image-more"],v.jszip,v["@json2csv/whatwg"],v["dayjs/plugin/advancedFormat"],v["dayjs/plugin/arraySupport"],v["dayjs/plugin/buddhistEra"],v["dayjs/plugin/calendar"],v["dayjs/plugin/customParseFormat"],v["dayjs/plugin/dayOfYear"],v["dayjs/plugin/duration"],v["dayjs/plugin/isBetween"],v["dayjs/plugin/isLeapYear"],v["dayjs/plugin/isMoment"],v["dayjs/plugin/isoWeek"],v["dayjs/plugin/isoWeeksInYear"],v["dayjs/plugin/isSameOrAfter"],v["dayjs/plugin/isSameOrBefore"],v["dayjs/plugin/isToday"],v["dayjs/plugin/isTomorrow"],v["dayjs/plugin/isYesterday"],v["dayjs/plugin/localeData"],v["dayjs/plugin/localizedFormat"],v["dayjs/plugin/minMax"],v["dayjs/plugin/objectSupport"],v["dayjs/plugin/pluralGetSet"],v["dayjs/plugin/preParsePostFormat"],v["dayjs/plugin/quarterOfYear"],v["dayjs/plugin/relativeTime"],v["dayjs/plugin/timezone"],v["dayjs/plugin/toArray"],v["dayjs/plugin/toObject"],v["dayjs/plugin/updateLocale"],v["dayjs/plugin/utc"],v["dayjs/plugin/weekday"],v["dayjs/plugin/weekOfYear"],v["dayjs/plugin/weekYear"],v.reactflow))})(this,function(v,g,a,Le,V,K,S,lc,Di,Qt,M,y,uc,fn,nt,oe,bt,cc,Ii,Mi,st,Se,DI,B,_e,b,k,ie,_,dt,ye,dc,N,zi,Ai,Ei,Li,Pi,Bi,Oi,$i,Vi,qi,Ni,Fi,Gi,Wi,II,be,ps,pt,Re,pc,hc,Ri,Qi,gn,f,ht,xc,mn,Ui,Ki,fc,gc,mc,yc,bc,jc,vc,wc,Cc,Sc,_c,kc,Tc,Dc,Ic,Mc,zc,Ac,Ec,Lc,Pc,Bc,Oc,$c,Vc,qc,Nc,Fc,Gc,Wc,Rc,Qc,Uc,Kc,ve){"use strict";var kI=Object.defineProperty;var TI=(v,g,a)=>g in v?kI(v,g,{enumerable:!0,configurable:!0,writable:!0,value:a}):v[g]=a;var L=(v,g,a)=>(TI(v,typeof g!="symbol"?g+"":g,a),a);function Ut(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 Yc=Ut(Di),Xc=Ut(Qt),Mt=Ut(uc),J=Ut(cc),xt=Ut(dc);var hs={exports:{}},Kt={};/**
1
+ (function(v,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("react"),require("@mantine/core"),require("@mantine/modals"),require("ahooks"),require("mobx"),require("mobx-react-lite"),require("@faker-js/faker"),require("crypto-js"),require("d3-array"),require("dayjs"),require("lodash"),require("mathjs"),require("numbro"),require("axios"),require("@mantine/hooks"),require("popmotion"),require("echarts/core"),require("echarts/charts"),require("echarts/components"),require("echarts/renderers"),require("js-base64"),require("eventemitter2"),require("chroma-js"),require("echarts-for-react/lib/core"),require("echarts-gl"),require("react-hook-form"),require("tabler-icons-react"),require("@tabler/icons-react"),require("@mantine/notifications"),require("@monaco-editor/react"),require("d3-regression"),require("@mantine/tiptap"),require("@tiptap/extension-color"),require("@tiptap/extension-highlight"),require("@tiptap/extension-placeholder"),require("@tiptap/extension-subscript"),require("@tiptap/extension-superscript"),require("@tiptap/extension-text-align"),require("@tiptap/extension-text-style"),require("@tiptap/extension-table"),require("@tiptap/extension-table-cell"),require("@tiptap/extension-table-header"),require("@tiptap/extension-table-row"),require("@tiptap/extension-underline"),require("@tiptap/react"),require("@tiptap/starter-kit"),require("prosemirror-keymap"),require("prosemirror-commands"),require("prosemirror-schema-list"),require("@mantine/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("uuid"),require("performant-array-to-tree"),require("file-saver"),require("dom-to-image-more"),require("jszip"),require("@json2csv/whatwg"),require("dayjs/plugin/advancedFormat"),require("dayjs/plugin/arraySupport"),require("dayjs/plugin/buddhistEra"),require("dayjs/plugin/calendar"),require("dayjs/plugin/customParseFormat"),require("dayjs/plugin/dayOfYear"),require("dayjs/plugin/duration"),require("dayjs/plugin/isBetween"),require("dayjs/plugin/isLeapYear"),require("dayjs/plugin/isMoment"),require("dayjs/plugin/isoWeek"),require("dayjs/plugin/isoWeeksInYear"),require("dayjs/plugin/isSameOrAfter"),require("dayjs/plugin/isSameOrBefore"),require("dayjs/plugin/isToday"),require("dayjs/plugin/isTomorrow"),require("dayjs/plugin/isYesterday"),require("dayjs/plugin/localeData"),require("dayjs/plugin/localizedFormat"),require("dayjs/plugin/minMax"),require("dayjs/plugin/objectSupport"),require("dayjs/plugin/pluralGetSet"),require("dayjs/plugin/preParsePostFormat"),require("dayjs/plugin/quarterOfYear"),require("dayjs/plugin/relativeTime"),require("dayjs/plugin/timezone"),require("dayjs/plugin/toArray"),require("dayjs/plugin/toObject"),require("dayjs/plugin/updateLocale"),require("dayjs/plugin/utc"),require("dayjs/plugin/weekday"),require("dayjs/plugin/weekOfYear"),require("dayjs/plugin/weekYear"),require("reactflow")):typeof define=="function"&&define.amd?define(["exports","react","@mantine/core","@mantine/modals","ahooks","mobx","mobx-react-lite","@faker-js/faker","crypto-js","d3-array","dayjs","lodash","mathjs","numbro","axios","@mantine/hooks","popmotion","echarts/core","echarts/charts","echarts/components","echarts/renderers","js-base64","eventemitter2","chroma-js","echarts-for-react/lib/core","echarts-gl","react-hook-form","tabler-icons-react","@tabler/icons-react","@mantine/notifications","@monaco-editor/react","d3-regression","@mantine/tiptap","@tiptap/extension-color","@tiptap/extension-highlight","@tiptap/extension-placeholder","@tiptap/extension-subscript","@tiptap/extension-superscript","@tiptap/extension-text-align","@tiptap/extension-text-style","@tiptap/extension-table","@tiptap/extension-table-cell","@tiptap/extension-table-header","@tiptap/extension-table-row","@tiptap/extension-underline","@tiptap/react","@tiptap/starter-kit","prosemirror-keymap","prosemirror-commands","prosemirror-schema-list","@mantine/prism","@tanstack/react-table","react-virtual","@mantine/dates","rc-select","rc-tree-select","react-grid-layout","mobx-state-tree","uuid","performant-array-to-tree","file-saver","dom-to-image-more","jszip","@json2csv/whatwg","dayjs/plugin/advancedFormat","dayjs/plugin/arraySupport","dayjs/plugin/buddhistEra","dayjs/plugin/calendar","dayjs/plugin/customParseFormat","dayjs/plugin/dayOfYear","dayjs/plugin/duration","dayjs/plugin/isBetween","dayjs/plugin/isLeapYear","dayjs/plugin/isMoment","dayjs/plugin/isoWeek","dayjs/plugin/isoWeeksInYear","dayjs/plugin/isSameOrAfter","dayjs/plugin/isSameOrBefore","dayjs/plugin/isToday","dayjs/plugin/isTomorrow","dayjs/plugin/isYesterday","dayjs/plugin/localeData","dayjs/plugin/localizedFormat","dayjs/plugin/minMax","dayjs/plugin/objectSupport","dayjs/plugin/pluralGetSet","dayjs/plugin/preParsePostFormat","dayjs/plugin/quarterOfYear","dayjs/plugin/relativeTime","dayjs/plugin/timezone","dayjs/plugin/toArray","dayjs/plugin/toObject","dayjs/plugin/updateLocale","dayjs/plugin/utc","dayjs/plugin/weekday","dayjs/plugin/weekOfYear","dayjs/plugin/weekYear","reactflow"],g):(v=typeof globalThis<"u"?globalThis:v||self,g(v.dashboard={},v.react,v["@mantine/core"],v["@mantine/modals"],v.ahooks,v.mobx,v["mobx-react-lite"],v["@faker-js/faker"],v.CryptoJS,v["d3-array"],v.dayjs,v._,v.mathjs,v.numbro,v.axios,v["@mantine/hooks"],v.popmotion,v["echarts/core"],v["echarts/charts"],v["echarts/components"],v["echarts/renderers"],v["js-base64"],v.eventemitter2,v["chroma-js"],v["echarts-for-react/lib/core"],v["echarts-gl"],v["react-hook-form"],v["tabler-icons-react"],v["@tabler/icons-react"],v["@mantine/notifications"],v["@monaco-editor/react"],v["d3-regression"],v["@mantine/tiptap"],v["@tiptap/extension-color"],v["@tiptap/extension-highlight"],v["@tiptap/extension-placeholder"],v["@tiptap/extension-subscript"],v["@tiptap/extension-superscript"],v["@tiptap/extension-text-align"],v["@tiptap/extension-text-style"],v["@tiptap/extension-table"],v["@tiptap/extension-table-cell"],v["@tiptap/extension-table-header"],v["@tiptap/extension-table-row"],v["@tiptap/extension-underline"],v["@tiptap/react"],v["@tiptap/starter-kit"],v["prosemirror-keymap"],v["prosemirror-commands"],v["prosemirror-schema-list"],v["@mantine/prism"],v["@tanstack/react-table"],v["react-virtual"],v["@mantine/dates"],v["rc-select"],v["rc-tree-select"],v["react-grid-layout"],v["mobx-state-tree"],v.uuid,v["performant-array-to-tree"],v["file-saver"],v["dom-to-image-more"],v.jszip,v["@json2csv/whatwg"],v["dayjs/plugin/advancedFormat"],v["dayjs/plugin/arraySupport"],v["dayjs/plugin/buddhistEra"],v["dayjs/plugin/calendar"],v["dayjs/plugin/customParseFormat"],v["dayjs/plugin/dayOfYear"],v["dayjs/plugin/duration"],v["dayjs/plugin/isBetween"],v["dayjs/plugin/isLeapYear"],v["dayjs/plugin/isMoment"],v["dayjs/plugin/isoWeek"],v["dayjs/plugin/isoWeeksInYear"],v["dayjs/plugin/isSameOrAfter"],v["dayjs/plugin/isSameOrBefore"],v["dayjs/plugin/isToday"],v["dayjs/plugin/isTomorrow"],v["dayjs/plugin/isYesterday"],v["dayjs/plugin/localeData"],v["dayjs/plugin/localizedFormat"],v["dayjs/plugin/minMax"],v["dayjs/plugin/objectSupport"],v["dayjs/plugin/pluralGetSet"],v["dayjs/plugin/preParsePostFormat"],v["dayjs/plugin/quarterOfYear"],v["dayjs/plugin/relativeTime"],v["dayjs/plugin/timezone"],v["dayjs/plugin/toArray"],v["dayjs/plugin/toObject"],v["dayjs/plugin/updateLocale"],v["dayjs/plugin/utc"],v["dayjs/plugin/weekday"],v["dayjs/plugin/weekOfYear"],v["dayjs/plugin/weekYear"],v.reactflow))})(this,function(v,g,a,ze,$,U,S,cu,Ti,Rt,M,y,uu,xn,He,re,yt,Di,et,ct,du,Ii,Mi,tt,we,II,b,k,_,ut,fe,pu,q,zi,Ai,Ei,Pi,Li,Bi,Oi,$i,Vi,qi,Ni,Fi,Gi,Wi,MI,ge,ds,dt,Fe,hu,xu,Ri,Qi,fn,f,pt,fu,gn,Ui,Ki,gu,mu,yu,bu,ju,vu,wu,Cu,Su,_u,ku,Tu,Du,Iu,Mu,zu,Au,Eu,Pu,Lu,Bu,Ou,$u,Vu,qu,Nu,Fu,Gu,Wu,Ru,Qu,Uu,Ku,Yu,ye){"use strict";var TI=Object.defineProperty;var DI=(v,g,a)=>g in v?TI(v,g,{enumerable:!0,configurable:!0,writable:!0,value:a}):v[g]=a;var P=(v,g,a)=>(DI(v,typeof g!="symbol"?g+"":g,a),a);function Qt(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=Qt(Ti),Ju=Qt(Rt),It=Qt(uu),be=Qt(Di),ht=Qt(pu);var ps={exports:{}},Ut={};/**
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 Yi;function Jc(){if(Yi)return Kt;Yi=1;var e=g,t=Symbol.for("react.element"),n=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,i=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function l(u,c,d){var h,p={},x=null,m=null;d!==void 0&&(x=""+d),c.key!==void 0&&(x=""+c.key),c.ref!==void 0&&(m=c.ref);for(h in c)r.call(c,h)&&!o.hasOwnProperty(h)&&(p[h]=c[h]);if(u&&u.defaultProps)for(h in c=u.defaultProps,c)p[h]===void 0&&(p[h]=c[h]);return{$$typeof:t,type:u,key:x,ref:m,props:p,_owner:i.current}}return Kt.Fragment=n,Kt.jsx=l,Kt.jsxs=l,Kt}var Yt={};/**
9
+ */var Yi;function Zu(){if(Yi)return Ut;Yi=1;var e=g,t=Symbol.for("react.element"),n=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,i=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function l(c,u,d){var h,p={},x=null,m=null;d!==void 0&&(x=""+d),u.key!==void 0&&(x=""+u.key),u.ref!==void 0&&(m=u.ref);for(h in u)r.call(u,h)&&!o.hasOwnProperty(h)&&(p[h]=u[h]);if(c&&c.defaultProps)for(h in u=c.defaultProps,u)p[h]===void 0&&(p[h]=u[h]);return{$$typeof:t,type:c,key:x,ref:m,props:p,_owner:i.current}}return Ut.Fragment=n,Ut.jsx=l,Ut.jsxs=l,Ut}var Kt={};/**
10
10
  * @license React
11
11
  * react-jsx-runtime.development.js
12
12
  *
@@ -14,17 +14,17 @@
14
14
  *
15
15
  * This source code is licensed under the MIT license found in the
16
16
  * LICENSE file in the root directory of this source tree.
17
- */var Xi;function Zc(){return Xi||(Xi=1,process.env.NODE_ENV!=="production"&&function(){var e=g,t=Symbol.for("react.element"),n=Symbol.for("react.portal"),r=Symbol.for("react.fragment"),i=Symbol.for("react.strict_mode"),o=Symbol.for("react.profiler"),l=Symbol.for("react.provider"),u=Symbol.for("react.context"),c=Symbol.for("react.forward_ref"),d=Symbol.for("react.suspense"),h=Symbol.for("react.suspense_list"),p=Symbol.for("react.memo"),x=Symbol.for("react.lazy"),m=Symbol.for("react.offscreen"),j=Symbol.iterator,C="@@iterator";function T(w){if(w===null||typeof w!="object")return null;var I=j&&w[j]||w[C];return typeof I=="function"?I:null}var D=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function A(w){{for(var I=arguments.length,E=new Array(I>1?I-1:0),q=1;q<I;q++)E[q-1]=arguments[q];F("error",w,E)}}function F(w,I,E){{var q=D.ReactDebugCurrentFrame,te=q.getStackAddendum();te!==""&&(I+="%s",E=E.concat([te]));var re=E.map(function(Y){return String(Y)});re.unshift("Warning: "+I),Function.prototype.apply.call(console[w],console,re)}}var X=!1,Q=!1,G=!1,ee=!1,ae=!1,Dt;Dt=Symbol.for("react.module.reference");function Xe(w){return!!(typeof w=="string"||typeof w=="function"||w===r||w===o||ae||w===i||w===d||w===h||ee||w===m||X||Q||G||typeof w=="object"&&w!==null&&(w.$$typeof===x||w.$$typeof===p||w.$$typeof===l||w.$$typeof===u||w.$$typeof===c||w.$$typeof===Dt||w.getModuleId!==void 0))}function bi(w,I,E){var q=w.displayName;if(q)return q;var te=I.displayName||I.name||"";return te!==""?E+"("+te+")":E}function pn(w){return w.displayName||"Context"}function ut(w){if(w==null)return null;if(typeof w.tag=="number"&&A("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof w=="function")return w.displayName||w.name||null;if(typeof w=="string")return w;switch(w){case r:return"Fragment";case n:return"Portal";case o:return"Profiler";case i:return"StrictMode";case d:return"Suspense";case h:return"SuspenseList"}if(typeof w=="object")switch(w.$$typeof){case u:var I=w;return pn(I)+".Consumer";case l:var E=w;return pn(E._context)+".Provider";case c:return bi(w,w.render,"ForwardRef");case p:var q=w.displayName||null;return q!==null?q:ut(w.type)||"Memo";case x:{var te=w,re=te._payload,Y=te._init;try{return ut(Y(re))}catch{return null}}}return null}var It=Object.assign,hn=0,qu,Nu,Fu,Gu,Wu,Ru,Qu;function Uu(){}Uu.__reactDisabledLog=!0;function tI(){{if(hn===0){qu=console.log,Nu=console.info,Fu=console.warn,Gu=console.error,Wu=console.group,Ru=console.groupCollapsed,Qu=console.groupEnd;var w={configurable:!0,enumerable:!0,value:Uu,writable:!0};Object.defineProperties(console,{info:w,log:w,warn:w,error:w,group:w,groupCollapsed:w,groupEnd:w})}hn++}}function nI(){{if(hn--,hn===0){var w={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:It({},w,{value:qu}),info:It({},w,{value:Nu}),warn:It({},w,{value:Fu}),error:It({},w,{value:Gu}),group:It({},w,{value:Wu}),groupCollapsed:It({},w,{value:Ru}),groupEnd:It({},w,{value:Qu})})}hn<0&&A("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var ji=D.ReactCurrentDispatcher,vi;function os(w,I,E){{if(vi===void 0)try{throw Error()}catch(te){var q=te.stack.trim().match(/\n( *(at )?)/);vi=q&&q[1]||""}return`
18
- `+vi+w}}var wi=!1,ls;{var sI=typeof WeakMap=="function"?WeakMap:Map;ls=new sI}function Ku(w,I){if(!w||wi)return"";{var E=ls.get(w);if(E!==void 0)return E}var q;wi=!0;var te=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var re;re=ji.current,ji.current=null,tI();try{if(I){var Y=function(){throw Error()};if(Object.defineProperty(Y.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(Y,[])}catch(ct){q=ct}Reflect.construct(w,[],Y)}else{try{Y.call()}catch(ct){q=ct}w.call(Y.prototype)}}else{try{throw Error()}catch(ct){q=ct}w()}}catch(ct){if(ct&&q&&typeof ct.stack=="string"){for(var U=ct.stack.split(`
19
- `),Te=q.stack.split(`
20
- `),de=U.length-1,fe=Te.length-1;de>=1&&fe>=0&&U[de]!==Te[fe];)fe--;for(;de>=1&&fe>=0;de--,fe--)if(U[de]!==Te[fe]){if(de!==1||fe!==1)do if(de--,fe--,fe<0||U[de]!==Te[fe]){var We=`
21
- `+U[de].replace(" at new "," at ");return w.displayName&&We.includes("<anonymous>")&&(We=We.replace("<anonymous>",w.displayName)),typeof w=="function"&&ls.set(w,We),We}while(de>=1&&fe>=0);break}}}finally{wi=!1,ji.current=re,nI(),Error.prepareStackTrace=te}var Rt=w?w.displayName||w.name:"",oc=Rt?os(Rt):"";return typeof w=="function"&&ls.set(w,oc),oc}function rI(w,I,E){return Ku(w,!1)}function iI(w){var I=w.prototype;return!!(I&&I.isReactComponent)}function us(w,I,E){if(w==null)return"";if(typeof w=="function")return Ku(w,iI(w));if(typeof w=="string")return os(w);switch(w){case d:return os("Suspense");case h:return os("SuspenseList")}if(typeof w=="object")switch(w.$$typeof){case c:return rI(w.render);case p:return us(w.type,I,E);case x:{var q=w,te=q._payload,re=q._init;try{return us(re(te),I,E)}catch{}}}return""}var cs=Object.prototype.hasOwnProperty,Yu={},Xu=D.ReactDebugCurrentFrame;function ds(w){if(w){var I=w._owner,E=us(w.type,w._source,I?I.type:null);Xu.setExtraStackFrame(E)}else Xu.setExtraStackFrame(null)}function aI(w,I,E,q,te){{var re=Function.call.bind(cs);for(var Y in w)if(re(w,Y)){var U=void 0;try{if(typeof w[Y]!="function"){var Te=Error((q||"React class")+": "+E+" type `"+Y+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof w[Y]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw Te.name="Invariant Violation",Te}U=w[Y](I,Y,q,E,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(de){U=de}U&&!(U instanceof Error)&&(ds(te),A("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",q||"React class",E,Y,typeof U),ds(null)),U instanceof Error&&!(U.message in Yu)&&(Yu[U.message]=!0,ds(te),A("Failed %s type: %s",E,U.message),ds(null))}}}var oI=Array.isArray;function Ci(w){return oI(w)}function lI(w){{var I=typeof Symbol=="function"&&Symbol.toStringTag,E=I&&w[Symbol.toStringTag]||w.constructor.name||"Object";return E}}function uI(w){try{return Ju(w),!1}catch{return!0}}function Ju(w){return""+w}function Zu(w){if(uI(w))return A("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",lI(w)),Ju(w)}var xn=D.ReactCurrentOwner,cI={key:!0,ref:!0,__self:!0,__source:!0},Hu,ec,Si;Si={};function dI(w){if(cs.call(w,"ref")){var I=Object.getOwnPropertyDescriptor(w,"ref").get;if(I&&I.isReactWarning)return!1}return w.ref!==void 0}function pI(w){if(cs.call(w,"key")){var I=Object.getOwnPropertyDescriptor(w,"key").get;if(I&&I.isReactWarning)return!1}return w.key!==void 0}function hI(w,I){if(typeof w.ref=="string"&&xn.current&&I&&xn.current.stateNode!==I){var E=ut(xn.current.type);Si[E]||(A('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',ut(xn.current.type),w.ref),Si[E]=!0)}}function xI(w,I){{var E=function(){Hu||(Hu=!0,A("%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(w,"key",{get:E,configurable:!0})}}function fI(w,I){{var E=function(){ec||(ec=!0,A("%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(w,"ref",{get:E,configurable:!0})}}var gI=function(w,I,E,q,te,re,Y){var U={$$typeof:t,type:w,key:I,ref:E,props:Y,_owner:re};return U._store={},Object.defineProperty(U._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(U,"_self",{configurable:!1,enumerable:!1,writable:!1,value:q}),Object.defineProperty(U,"_source",{configurable:!1,enumerable:!1,writable:!1,value:te}),Object.freeze&&(Object.freeze(U.props),Object.freeze(U)),U};function mI(w,I,E,q,te){{var re,Y={},U=null,Te=null;E!==void 0&&(Zu(E),U=""+E),pI(I)&&(Zu(I.key),U=""+I.key),dI(I)&&(Te=I.ref,hI(I,te));for(re in I)cs.call(I,re)&&!cI.hasOwnProperty(re)&&(Y[re]=I[re]);if(w&&w.defaultProps){var de=w.defaultProps;for(re in de)Y[re]===void 0&&(Y[re]=de[re])}if(U||Te){var fe=typeof w=="function"?w.displayName||w.name||"Unknown":w;U&&xI(Y,fe),Te&&fI(Y,fe)}return gI(w,U,Te,te,q,xn.current,Y)}}var _i=D.ReactCurrentOwner,tc=D.ReactDebugCurrentFrame;function Wt(w){if(w){var I=w._owner,E=us(w.type,w._source,I?I.type:null);tc.setExtraStackFrame(E)}else tc.setExtraStackFrame(null)}var ki;ki=!1;function Ti(w){return typeof w=="object"&&w!==null&&w.$$typeof===t}function nc(){{if(_i.current){var w=ut(_i.current.type);if(w)return`
17
+ */var Xi;function Hu(){return Xi||(Xi=1,process.env.NODE_ENV!=="production"&&function(){var e=g,t=Symbol.for("react.element"),n=Symbol.for("react.portal"),r=Symbol.for("react.fragment"),i=Symbol.for("react.strict_mode"),o=Symbol.for("react.profiler"),l=Symbol.for("react.provider"),c=Symbol.for("react.context"),u=Symbol.for("react.forward_ref"),d=Symbol.for("react.suspense"),h=Symbol.for("react.suspense_list"),p=Symbol.for("react.memo"),x=Symbol.for("react.lazy"),m=Symbol.for("react.offscreen"),j=Symbol.iterator,C="@@iterator";function T(w){if(w===null||typeof w!="object")return null;var I=j&&w[j]||w[C];return typeof I=="function"?I:null}var D=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function A(w){{for(var I=arguments.length,E=new Array(I>1?I-1:0),V=1;V<I;V++)E[V-1]=arguments[V];N("error",w,E)}}function N(w,I,E){{var V=D.ReactDebugCurrentFrame,H=V.getStackAddendum();H!==""&&(I+="%s",E=E.concat([H]));var ne=E.map(function(K){return String(K)});ne.unshift("Warning: "+I),Function.prototype.apply.call(console[w],console,ne)}}var Y=!1,R=!1,F=!1,Z=!1,se=!1,Tt;Tt=Symbol.for("react.module.reference");function Ue(w){return!!(typeof w=="string"||typeof w=="function"||w===r||w===o||se||w===i||w===d||w===h||Z||w===m||Y||R||F||typeof w=="object"&&w!==null&&(w.$$typeof===x||w.$$typeof===p||w.$$typeof===l||w.$$typeof===c||w.$$typeof===u||w.$$typeof===Tt||w.getModuleId!==void 0))}function yi(w,I,E){var V=w.displayName;if(V)return V;var H=I.displayName||I.name||"";return H!==""?E+"("+H+")":E}function dn(w){return w.displayName||"Context"}function ot(w){if(w==null)return null;if(typeof w.tag=="number"&&A("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof w=="function")return w.displayName||w.name||null;if(typeof w=="string")return w;switch(w){case r:return"Fragment";case n:return"Portal";case o:return"Profiler";case i:return"StrictMode";case d:return"Suspense";case h:return"SuspenseList"}if(typeof w=="object")switch(w.$$typeof){case c:var I=w;return dn(I)+".Consumer";case l:var E=w;return dn(E._context)+".Provider";case u:return yi(w,w.render,"ForwardRef");case p:var V=w.displayName||null;return V!==null?V:ot(w.type)||"Memo";case x:{var H=w,ne=H._payload,K=H._init;try{return ot(K(ne))}catch{return null}}}return null}var Dt=Object.assign,pn=0,Nc,Fc,Gc,Wc,Rc,Qc,Uc;function Kc(){}Kc.__reactDisabledLog=!0;function nI(){{if(pn===0){Nc=console.log,Fc=console.info,Gc=console.warn,Wc=console.error,Rc=console.group,Qc=console.groupCollapsed,Uc=console.groupEnd;var w={configurable:!0,enumerable:!0,value:Kc,writable:!0};Object.defineProperties(console,{info:w,log:w,warn:w,error:w,group:w,groupCollapsed:w,groupEnd:w})}pn++}}function sI(){{if(pn--,pn===0){var w={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:Dt({},w,{value:Nc}),info:Dt({},w,{value:Fc}),warn:Dt({},w,{value:Gc}),error:Dt({},w,{value:Wc}),group:Dt({},w,{value:Rc}),groupCollapsed:Dt({},w,{value:Qc}),groupEnd:Dt({},w,{value:Uc})})}pn<0&&A("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var bi=D.ReactCurrentDispatcher,ji;function as(w,I,E){{if(ji===void 0)try{throw Error()}catch(H){var V=H.stack.trim().match(/\n( *(at )?)/);ji=V&&V[1]||""}return`
18
+ `+ji+w}}var vi=!1,os;{var rI=typeof WeakMap=="function"?WeakMap:Map;os=new rI}function Yc(w,I){if(!w||vi)return"";{var E=os.get(w);if(E!==void 0)return E}var V;vi=!0;var H=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var ne;ne=bi.current,bi.current=null,nI();try{if(I){var K=function(){throw Error()};if(Object.defineProperty(K.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(K,[])}catch(lt){V=lt}Reflect.construct(w,[],K)}else{try{K.call()}catch(lt){V=lt}w.call(K.prototype)}}else{try{throw Error()}catch(lt){V=lt}w()}}catch(lt){if(lt&&V&&typeof lt.stack=="string"){for(var Q=lt.stack.split(`
19
+ `),Se=V.stack.split(`
20
+ `),le=Q.length-1,pe=Se.length-1;le>=1&&pe>=0&&Q[le]!==Se[pe];)pe--;for(;le>=1&&pe>=0;le--,pe--)if(Q[le]!==Se[pe]){if(le!==1||pe!==1)do if(le--,pe--,pe<0||Q[le]!==Se[pe]){var Ne=`
21
+ `+Q[le].replace(" at new "," at ");return w.displayName&&Ne.includes("<anonymous>")&&(Ne=Ne.replace("<anonymous>",w.displayName)),typeof w=="function"&&os.set(w,Ne),Ne}while(le>=1&&pe>=0);break}}}finally{vi=!1,bi.current=ne,sI(),Error.prepareStackTrace=H}var Wt=w?w.displayName||w.name:"",lu=Wt?as(Wt):"";return typeof w=="function"&&os.set(w,lu),lu}function iI(w,I,E){return Yc(w,!1)}function aI(w){var I=w.prototype;return!!(I&&I.isReactComponent)}function ls(w,I,E){if(w==null)return"";if(typeof w=="function")return Yc(w,aI(w));if(typeof w=="string")return as(w);switch(w){case d:return as("Suspense");case h:return as("SuspenseList")}if(typeof w=="object")switch(w.$$typeof){case u:return iI(w.render);case p:return ls(w.type,I,E);case x:{var V=w,H=V._payload,ne=V._init;try{return ls(ne(H),I,E)}catch{}}}return""}var cs=Object.prototype.hasOwnProperty,Xc={},Jc=D.ReactDebugCurrentFrame;function us(w){if(w){var I=w._owner,E=ls(w.type,w._source,I?I.type:null);Jc.setExtraStackFrame(E)}else Jc.setExtraStackFrame(null)}function oI(w,I,E,V,H){{var ne=Function.call.bind(cs);for(var K in w)if(ne(w,K)){var Q=void 0;try{if(typeof w[K]!="function"){var Se=Error((V||"React class")+": "+E+" type `"+K+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof w[K]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw Se.name="Invariant Violation",Se}Q=w[K](I,K,V,E,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(le){Q=le}Q&&!(Q instanceof Error)&&(us(H),A("%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).",V||"React class",E,K,typeof Q),us(null)),Q instanceof Error&&!(Q.message in Xc)&&(Xc[Q.message]=!0,us(H),A("Failed %s type: %s",E,Q.message),us(null))}}}var lI=Array.isArray;function wi(w){return lI(w)}function cI(w){{var I=typeof Symbol=="function"&&Symbol.toStringTag,E=I&&w[Symbol.toStringTag]||w.constructor.name||"Object";return E}}function uI(w){try{return Zc(w),!1}catch{return!0}}function Zc(w){return""+w}function Hc(w){if(uI(w))return A("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",cI(w)),Zc(w)}var hn=D.ReactCurrentOwner,dI={key:!0,ref:!0,__self:!0,__source:!0},eu,tu,Ci;Ci={};function pI(w){if(cs.call(w,"ref")){var I=Object.getOwnPropertyDescriptor(w,"ref").get;if(I&&I.isReactWarning)return!1}return w.ref!==void 0}function hI(w){if(cs.call(w,"key")){var I=Object.getOwnPropertyDescriptor(w,"key").get;if(I&&I.isReactWarning)return!1}return w.key!==void 0}function xI(w,I){if(typeof w.ref=="string"&&hn.current&&I&&hn.current.stateNode!==I){var E=ot(hn.current.type);Ci[E]||(A('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',ot(hn.current.type),w.ref),Ci[E]=!0)}}function fI(w,I){{var E=function(){eu||(eu=!0,A("%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(w,"key",{get:E,configurable:!0})}}function gI(w,I){{var E=function(){tu||(tu=!0,A("%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(w,"ref",{get:E,configurable:!0})}}var mI=function(w,I,E,V,H,ne,K){var Q={$$typeof:t,type:w,key:I,ref:E,props:K,_owner:ne};return Q._store={},Object.defineProperty(Q._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(Q,"_self",{configurable:!1,enumerable:!1,writable:!1,value:V}),Object.defineProperty(Q,"_source",{configurable:!1,enumerable:!1,writable:!1,value:H}),Object.freeze&&(Object.freeze(Q.props),Object.freeze(Q)),Q};function yI(w,I,E,V,H){{var ne,K={},Q=null,Se=null;E!==void 0&&(Hc(E),Q=""+E),hI(I)&&(Hc(I.key),Q=""+I.key),pI(I)&&(Se=I.ref,xI(I,H));for(ne in I)cs.call(I,ne)&&!dI.hasOwnProperty(ne)&&(K[ne]=I[ne]);if(w&&w.defaultProps){var le=w.defaultProps;for(ne in le)K[ne]===void 0&&(K[ne]=le[ne])}if(Q||Se){var pe=typeof w=="function"?w.displayName||w.name||"Unknown":w;Q&&fI(K,pe),Se&&gI(K,pe)}return mI(w,Q,Se,H,V,hn.current,K)}}var Si=D.ReactCurrentOwner,nu=D.ReactDebugCurrentFrame;function Gt(w){if(w){var I=w._owner,E=ls(w.type,w._source,I?I.type:null);nu.setExtraStackFrame(E)}else nu.setExtraStackFrame(null)}var _i;_i=!1;function ki(w){return typeof w=="object"&&w!==null&&w.$$typeof===t}function su(){{if(Si.current){var w=ot(Si.current.type);if(w)return`
22
22
 
23
- Check the render method of \``+w+"`."}return""}}function yI(w){{if(w!==void 0){var I=w.fileName.replace(/^.*[\\\/]/,""),E=w.lineNumber;return`
23
+ Check the render method of \``+w+"`."}return""}}function bI(w){{if(w!==void 0){var I=w.fileName.replace(/^.*[\\\/]/,""),E=w.lineNumber;return`
24
24
 
25
- Check your code at `+I+":"+E+"."}return""}}var sc={};function bI(w){{var I=nc();if(!I){var E=typeof w=="string"?w:w.displayName||w.name;E&&(I=`
25
+ Check your code at `+I+":"+E+"."}return""}}var ru={};function jI(w){{var I=su();if(!I){var E=typeof w=="string"?w:w.displayName||w.name;E&&(I=`
26
26
 
27
- Check the top-level render call using <`+E+">.")}return I}}function rc(w,I){{if(!w._store||w._store.validated||w.key!=null)return;w._store.validated=!0;var E=bI(I);if(sc[E])return;sc[E]=!0;var q="";w&&w._owner&&w._owner!==_i.current&&(q=" It was passed a child from "+ut(w._owner.type)+"."),Wt(w),A('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',E,q),Wt(null)}}function ic(w,I){{if(typeof w!="object")return;if(Ci(w))for(var E=0;E<w.length;E++){var q=w[E];Ti(q)&&rc(q,I)}else if(Ti(w))w._store&&(w._store.validated=!0);else if(w){var te=T(w);if(typeof te=="function"&&te!==w.entries)for(var re=te.call(w),Y;!(Y=re.next()).done;)Ti(Y.value)&&rc(Y.value,I)}}}function jI(w){{var I=w.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===p))E=I.propTypes;else return;if(E){var q=ut(I);aI(E,w.props,"prop",q,w)}else if(I.PropTypes!==void 0&&!ki){ki=!0;var te=ut(I);A("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",te||"Unknown")}typeof I.getDefaultProps=="function"&&!I.getDefaultProps.isReactClassApproved&&A("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function vI(w){{for(var I=Object.keys(w.props),E=0;E<I.length;E++){var q=I[E];if(q!=="children"&&q!=="key"){Wt(w),A("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",q),Wt(null);break}}w.ref!==null&&(Wt(w),A("Invalid attribute `ref` supplied to `React.Fragment`."),Wt(null))}}function ac(w,I,E,q,te,re){{var Y=Xe(w);if(!Y){var U="";(w===void 0||typeof w=="object"&&w!==null&&Object.keys(w).length===0)&&(U+=" 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 Te=yI(te);Te?U+=Te:U+=nc();var de;w===null?de="null":Ci(w)?de="array":w!==void 0&&w.$$typeof===t?(de="<"+(ut(w.type)||"Unknown")+" />",U=" Did you accidentally export a JSX literal instead of a component?"):de=typeof w,A("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",de,U)}var fe=mI(w,I,E,te,re);if(fe==null)return fe;if(Y){var We=I.children;if(We!==void 0)if(q)if(Ci(We)){for(var Rt=0;Rt<We.length;Rt++)ic(We[Rt],w);Object.freeze&&Object.freeze(We)}else A("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 ic(We,w)}return w===r?vI(fe):jI(fe),fe}}function wI(w,I,E){return ac(w,I,E,!0)}function CI(w,I,E){return ac(w,I,E,!1)}var SI=CI,_I=wI;Yt.Fragment=r,Yt.jsx=SI,Yt.jsxs=_I}()),Yt}process.env.NODE_ENV==="production"?hs.exports=Jc():hs.exports=Zc();var s=hs.exports;const rt={CryptoJS:Di,d3Array:Xc,dayjs:M,lodash:y,numbro:fn,mathjs:Mt,faker:lc.faker},Hc=[{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"}],ed=e=>`
27
+ Check the top-level render call using <`+E+">.")}return I}}function iu(w,I){{if(!w._store||w._store.validated||w.key!=null)return;w._store.validated=!0;var E=jI(I);if(ru[E])return;ru[E]=!0;var V="";w&&w._owner&&w._owner!==Si.current&&(V=" It was passed a child from "+ot(w._owner.type)+"."),Gt(w),A('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',E,V),Gt(null)}}function au(w,I){{if(typeof w!="object")return;if(wi(w))for(var E=0;E<w.length;E++){var V=w[E];ki(V)&&iu(V,I)}else if(ki(w))w._store&&(w._store.validated=!0);else if(w){var H=T(w);if(typeof H=="function"&&H!==w.entries)for(var ne=H.call(w),K;!(K=ne.next()).done;)ki(K.value)&&iu(K.value,I)}}}function vI(w){{var I=w.type;if(I==null||typeof I=="string")return;var E;if(typeof I=="function")E=I.propTypes;else if(typeof I=="object"&&(I.$$typeof===u||I.$$typeof===p))E=I.propTypes;else return;if(E){var V=ot(I);oI(E,w.props,"prop",V,w)}else if(I.PropTypes!==void 0&&!_i){_i=!0;var H=ot(I);A("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",H||"Unknown")}typeof I.getDefaultProps=="function"&&!I.getDefaultProps.isReactClassApproved&&A("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function wI(w){{for(var I=Object.keys(w.props),E=0;E<I.length;E++){var V=I[E];if(V!=="children"&&V!=="key"){Gt(w),A("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",V),Gt(null);break}}w.ref!==null&&(Gt(w),A("Invalid attribute `ref` supplied to `React.Fragment`."),Gt(null))}}function ou(w,I,E,V,H,ne){{var K=Ue(w);if(!K){var Q="";(w===void 0||typeof w=="object"&&w!==null&&Object.keys(w).length===0)&&(Q+=" 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 Se=bI(H);Se?Q+=Se:Q+=su();var le;w===null?le="null":wi(w)?le="array":w!==void 0&&w.$$typeof===t?(le="<"+(ot(w.type)||"Unknown")+" />",Q=" Did you accidentally export a JSX literal instead of a component?"):le=typeof w,A("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",le,Q)}var pe=yI(w,I,E,H,ne);if(pe==null)return pe;if(K){var Ne=I.children;if(Ne!==void 0)if(V)if(wi(Ne)){for(var Wt=0;Wt<Ne.length;Wt++)au(Ne[Wt],w);Object.freeze&&Object.freeze(Ne)}else A("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 au(Ne,w)}return w===r?wI(pe):vI(pe),pe}}function CI(w,I,E){return ou(w,I,E,!0)}function SI(w,I,E){return ou(w,I,E,!1)}var _I=SI,kI=CI;Kt.Fragment=r,Kt.jsx=_I,Kt.jsxs=kI}()),Kt}process.env.NODE_ENV==="production"?ps.exports=Zu():ps.exports=Hu();var s=ps.exports;const nt={CryptoJS:Ti,d3Array:Ju,dayjs:M,lodash:y,numbro:xn,mathjs:It,faker:cu.faker},ed=[{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"}],td=e=>`
28
28
  <tr>
29
29
  <td><code>${e.name}</code></td>
30
30
  <td>
@@ -36,7 +36,7 @@ Check the top-level render call using <`+E+">.")}return I}}function rc(w,I){{if(
36
36
  >
37
37
  </td>
38
38
  </tr>
39
- `,td=`
39
+ `,nd=`
40
40
  <p>
41
41
  Parameter <code>utils</code> is <code>functionUtils</code>, which contains:
42
42
  </p>
@@ -48,42 +48,42 @@ Check the top-level render call using <`+E+">.")}return I}}function rc(w,I){{if(
48
48
  </tr>
49
49
  </thead>
50
50
  <tbody>
51
- ${Hc.map(ed).join("")}
51
+ ${ed.map(td).join("")}
52
52
  </tbody>
53
53
  </table>
54
- `;function xs(e,t){const n=Object.keys(t),r=Object.values(t);try{return new Function(...n,`return \`${e}\`;`)(...r)}catch(i){throw n.length===0&&e.includes("$")?new Error("[formatSQL] insufficient payload"):i}}function fs(e,t){try{return xs(e,t)}catch(n){return console.error(n),n.message}}function nd({sql:e,pre_process:t}){if(!t.trim())return e;try{return new Function(`return ${t}`)()({sql:e},rt)}catch(n){return console.error(n),e}}function sd(e,t,n){if(!e.trim())return t;try{return new Function(`return ${e}`)()(t,rt,n)}catch(r){return console.error(r),t}}function rd(e){e=e||{};const t=Object.keys(e).sort(),n=[];for(let r=0;r<t.length;r++){const i=t[r];if(i!="authentication"&&e[i])n.push(t[r]+"="+(typeof e[i]=="object"?JSON.stringify(e[i]):e[i]));else{const o=Object.keys(e[i]).sort();for(let l=0;l<o.length;l++){const u=o[l];u!="sign"&&e[i][u]&&n.push(o[l]+"="+(typeof e[i][u]=="object"?JSON.stringify(e[i][u]):e[i][u]))}}}return n.sort().join("&")}function id(e,t){let n=rd(e);return n+="&key="+t,Yc.MD5(n).toString().toUpperCase()}class Ji{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:id({app_id:this.app_id,nonce_str:n,...t},this.app_secret)}}getRequest(t,n){return(r,i,o,l)=>{const u=this.buildHeader(o),c=this.buildAxiosConfig(t,r,i,o,u,n);return nt(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,i,o,l){const u={baseURL:this.baseURL,method:t,url:n,params:t==="GET"?r:i.params,headers:o,signal:l};return["POST","PUT"].includes(t)&&(u.data=i.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 ad{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 Zi extends Ji{constructor(){super(...arguments);L(this,"makeQueryENV",null)}query(n){return async(r,i={})=>{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,i)}}httpDataSourceQuery(n){return async(r,i={})=>{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,i,!0)}}structure(n){return async(r,i={})=>this.post(n)("/query/structure",r,i)}}class Hi{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 zt=new Zi;function gs(e){zt.baseURL!==e.apiBaseURL&&(zt.baseURL=e.apiBaseURL),e.app_id&&(zt.app_id=e.app_id),e.app_secret&&(zt.app_secret=e.app_secret),e.makeQueryENV&&(zt.makeQueryENV=e.makeQueryENV)}const ea=new Hi(zt),Je=ea,Xt=g.forwardRef(function({value:t,onChange:n,...r},i){return s.jsx(a.TextInput,{ref:i,value:t,onChange:n,...r})});function z(e){const[t,n]=e.split(".");return{queryID:t,columnKey:n}}function od(e){return e.includes(".")?z(e):{queryID:"",columnKey:e}}function Ze(e,t){var i;const{queryID:n,columnKey:r}=z(t);return n?r?((i=e[n])==null?void 0:i.map(o=>o[r]))??[]:e[n]:[]}function Jt(e,t){const{queryID:n}=z(t);return n?e[n]:[]}function ld(e){return Object.values(e)[0]}function yn(e,t){const{queryID:n,columnKey:r}=z(t);return e[r]}const ta=["function aggregation({ queryData }, utils) {",' return "Aggregation Result";',"}"].join(`
55
- `),At={type:"none",config:{},fallback:"0"};function ud(e){const t=Array.from(e).sort((r,i)=>r-i),n=Math.floor(t.length/2);return t.length%2===0?(t[n-1]+t[n])/2:t[n]}function cd(e,t){switch(t.type){case"sum":return y.sum(e);case"mean":return y.mean(e);case"median":return ud(e);case"max":return y.max(e);case"min":return y.min(e);case"quantile":return Qt.quantile(e,t.config.p);case"CV":const n=Mt.std(...e),r=Mt.mean(...e);return r?n/r:Number.NaN;case"std":return Mt.std(...e);default:return e}}function ms(e,t){const n=e.map(Number),r=cd(n,t);return typeof r=="number"?Number.isFinite(r)?r:t.fallback:r??t.fallback}function dd(e,t,n){try{const r=Jt(e,t);return new Function(`return ${n.config.func}`)()({queryData:r},rt)}catch(r){return console.error(r),r.message}}function bn(e,t,n){try{return n.type==="custom"?dd(e,t,n):ms(Ze(e,t),n)}catch(r){return console.error(r),null}}class pd{constructor({valueRange:t,colorRange:n}){L(this,"mapper");this.mapper=bt.interpolate(t,n)}getColor(t){return this.mapper(t)}}const je={mantissa:0,output:"number",trimMantissa:!1,average:!1,absolute:!1};function W(e,{absolute:t,...n}){if(e===null)return String(e);try{let r=fn(e).value();if(r===void 0||Number.isNaN(r))throw new Error(`[formatNumber]Not a number: ${e}`);return t&&(r=Math.abs(r)),fn(r).format(n)}catch(r){return console.debug(r),String(e)}}function hd(e){return e===null?"null":e===void 0?"undefined":Array.isArray(e)?`Array(${e.length})`:e.toString()}function it({data_field:e,aggregation:t},n){return bn(n,e,t)}function Pe({formatter:e,aggregation:t},n){if(typeof n!="string"&&typeof n!="number")return hd(n);if(t.type==="custom")return n;try{return W(n,e)}catch(r){return console.error(r),n}}function xd(e,t){if(e.type==="static")return e.staticColor;if(e.type==="continuous")try{if(typeof t!="number")throw new Error(`[getColorByColorConf] Invalid type of aggregated value: ${t}`);return new pd(e).getColor(t)}catch(n){return console.error(n),"black"}return"black"}function fd(e,t){const{color:n,data_field:r,aggregation:i,size:o,weight:l}=e,u=bn(t,r,i),c=Pe(e,u);return s.jsx(a.Text,{sx:{fontSize:o,display:"inline"},color:xd(n,u),weight:l,children:c})}function gd(e,t){const n={};return e.forEach(r=>{const i=r.name;n[i]=fd(r,t)}),n}function md(e){return e.split(" ").map((t,n)=>s.jsxs(g.Fragment,{children:[t," "]},n))}function yd(e){const n=e.replaceAll("<br />","<br/>").replaceAll(`
56
- `,"<br/>").split("<br/>");return n.map((i,o)=>{const l=[md(i)];return o!==n.length-1&&l.push(s.jsx("br",{},`br-${o}`)),l}).flat().filter(i=>i!==void 0)}function ys(e){return yd(e)}function Zt(e,t,n){const r=gd(t,n),i=/^\{(.+)\}(.*)$/;return e.split("$").map((o,l)=>{const u=i.exec(o);if(!u)return ys(o);const c=r[u[1]];if(!c)return ys(o);const d=u[2]??"";return s.jsxs(g.Fragment,{children:[c,ys(d)]},`${o}-${l}`)})}function bd(e,t){const{data_field:n,aggregation:r}=e,i=bn(t,n,r);return Pe(e,i)}function na(e,t){const n={};return e.forEach(r=>{n[r.name]=bd(r,t)}),n}function jn(e,t,n){const r=na(t,n),i=/^\{(.+)\}(.*)$/;return e.split("$").map(o=>{const l=i.exec(o);if(!l)return o;const u=r[l[1]];if(!u)return o;const c=l[2]??"";return`${u}${c}`}).join("")}const bs={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 jd(){J.registerTheme("merico-light",{color:Object.values(bs.graphics.multiple),visualMap:{color:Object.values(bs.graphics.depth).reverse()},axes:[{type:"all",name:"通用坐标轴",axisLineColor:"#97999D",axisTickColor:"#97999D",axisLabelShow:!0,axisLabelColor:"#818388",splitLineShow:!0,splitLineColor:["#E0E6F1"]}]})}function sa(){jd()}function*vd(e){const t=bs.graphics[e];if(!t)throw new Error("Invalid palette key provided");const n=Object.values(t);let r=0;for(;;)yield n[r%n.length],r++}function ra(){return{filters:{},context:{}}}function js(e){const t=ra();if(!e)return ra();const{filters:n=t.filters,context:r=t.context}=e;return{filters:n,context:r}}class we extends g.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 s.jsxs(a.Box,{children:[s.jsx(a.Text,{size:"xs",children:(t=this.state.error)==null?void 0:t.message}),s.jsx(a.Button,{variant:"subtle",size:"xs",mx:"auto",compact:!0,sx:{display:"block"},onClick:n,children:"Retry"})]})}return this.props.children}}function wd(e,t={handleError:!0}){return n=>s.jsx(we,{...t,children:s.jsx(e,{...n})})}function Cd(e,t){return new Function(`return ${e}`)()(t,rt)}function Sd(e,t,n){return Cd(e,{context:t,filters:n})}function _d(e,t){try{return new Function(`return ${e.config.processing.pre}`)()(t,rt)}catch(n){return console.error(n),t}}function kd(e,t){return new Function(`return ${e.config.processing.post}`)()(t,rt)}function Td(e,t,n){return e?new Function(`return ${e}`)()(t,rt,n):t}const Et=e=>y.cloneDeepWith(e,(t,n)=>{if(n!==void 0&&t)return K.toJS(t)}),vn={sqlSnippet:new RegExp("(?<=sql_snippets\\.)([^\\?}.]+)","gm"),context:new RegExp("(?<=context\\.)([^\\?}.]+)","gm"),filter:new RegExp("(?<=filters\\.)([^\\?}.]+)","gm")};function Dd(e,t){const n=Ii.decode(t);n!==e&&(console.error("Inconsistent sql"),console.groupCollapsed("Inconsistent sql"),console.table({before:e,after:t,v:n}),console.groupEnd())}async function Id({query:e,name:t,payload:n,additionals:r},i){if(!e.sql)return[];const{type:o,key:l,sql:u,pre_process:c,post_process:d}=e,h=xs(u,n),p=nd({sql:h,pre_process:c}),x=Ii.encode(p);Dd(p,x);let m=await Je.query(i)({type:o,key:l,query:x,...r},{params:{name:t}});return m=sd(d,m,js(n)),m}async function Md({type:e,key:t,configString:n,name:r,additionals:i},o){try{return await Je.httpDataSourceQuery(o)({type:e,key:t,query:n,...i},{params:{name:r}})}catch(l){if(nt.isCancel(l))throw l;return console.error(l),l}}async function vs(){try{return(await Je.post()("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}},{})).data}catch(e){return console.error(e),[]}}async function ia(){try{return(await Je.post()("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}},{})).data}catch(e){return console.error(e),[]}}class aa{constructor(t){L(this,"rootRef");this.rootRef=K.observable({current:t})}async deleteItem(t){K.runInAction(()=>{y.unset(this.rootRef.current,[t])})}getItem(t){const n=this.getValueFromRoot(t);return Promise.resolve(n)}getValueFromRoot(t){return t===null?K.toJS(this.rootRef.current):y.get(this.rootRef.current,[t])}setItem(t,n){if(t===null)if(y.isObject(n))K.runInAction(()=>{this.rootRef.current=n});else throw new Error("Cannot set root value to non-object");else K.runInAction(()=>{y.set(this.rootRef.current,[t],n)});return Promise.resolve(this.getItem(t))}watchItem(t,n,r){return K.reaction(()=>this.getValueFromRoot(t),(i,o)=>{n(i,o)},{requiresObservable:!0,fireImmediately:y.get(r,"fireImmediately",!1)})}}class zd{constructor(){L(this,"channels",new Map);L(this,"globalChannel",new Mi)}getChannel(t){const n=this.channels.get(t);if(n)return n;const r=new Mi;return this.channels.set(t,r),r}}class Ad{constructor(t){L(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 zd,instanceData:new aa(t.viz.conf)};return this.instances.set(t.id,r),r}}function oa(e,t,n,r){return{vizManager:n,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new aa({}),colorPalette:{getColor(){return()=>""}},data:t,variables:r}}const Ed=e=>{const{panel:t,measure:n,vizManager:r,data:i,variables:o}=e,l=r.resolveComponent(t.viz.type),u=r.getOrCreateInstance(t),c={...oa(u,i,r,o),viewport:{width:n.w,height:n.h}},d=l.viewRender;return s.jsx(d,{context:c,instance:u,...y.omit(e,["panel","vizManager","data"])})},Ld=e=>{const{vizManager:t,panel:n,data:r,variables:i}=e,o=t.resolveComponent(n.viz.type),l=t.getOrCreateInstance(n),u={...oa(l,r,t,i)},c=o.configRender;return s.jsx(c,{context:u,instance:l,...y.omit(e,["panel","vizManager","data"])})},la=(e,t)=>{const n=st.bezier(e),r=st.bezier(t);return function(i){return i<50?n(i*2/100).hex():r((i-50)*2/100).hex()}},wn=e=>{const t=st.bezier(e);return function(n){return t(n/100).hex()}},Pd={type:"interpolation",displayName:"Red / Green",getColor:la(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},Bd={type:"interpolation",displayName:"Yellow / Blue",getColor:la(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},Od={type:"interpolation",displayName:"Red",getColor:wn(["#fff7f1","darkred"]),name:"red",category:"sequential"},$d={type:"interpolation",displayName:"Green",getColor:wn(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},Vd={type:"interpolation",displayName:"Blue",getColor:wn(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},qd={type:"interpolation",displayName:"Orange",getColor:wn(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class Nd{constructor(t){L(this,"symbol");this.symbol=Symbol(t)}}function at(e){return new Nd(e)}class ws{constructor(){L(this,"parent");L(this,"factoryRegistry",new Map);L(this,"instanceRegistry",new Map)}createScoped(){const t=new ws;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=y.get(t,"dispose");y.isFunction(n)&&n.bind(t)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}const ua="12.1.0",Fd=Object.freeze(Object.defineProperty({__proto__:null,version:ua},Symbol.toStringTag,{value:"Module"}));class Gd{constructor(t){L(this,"staticColors",new Map);L(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 Wd{constructor(){L(this,"plugins",new Map);L(this,"vizComponents",new Map);L(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 Rd{constructor(){L(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 i=this.migrations.filter(u=>u.version>t.from&&u.version<=t.to),o=y.orderBy(i,"version","asc");if(((l=y.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 ue extends Rd{constructor(){super(),this.configVersions()}version(t,n){return super.version(t,(r,i)=>({version:t,...n(r,i)}))}async migrate({configData:t,panelModel:n}){const r=await t.getItem(null),i=y.get(r,"version",0),o=this.run({from:i,to:this.VERSION},r,{panelModel:n});await t.setItem(null,o)}async needMigration({configData:t}){const n=await t.getItem(null);return y.get(n,"version",0)<this.VERSION}}const $=(e,t)=>{const[n,{setFalse:r}]=V.useBoolean(!0),[i,o]=g.useState();g.useEffect(()=>(e.getItem(t).then(u=>{o(u),r()}),e.watchItem(t,u=>{o(u)})));const l=g.useCallback(async u=>{await e.setItem(t,u),o(u)},[e,t]);return{loading:n,value:i,set:l}},De={top:16,right:16,bottom:16,left:16},Qe=e=>Math.max(0,e-De.left-De.right),Ue=e=>Math.max(0,e-De.top-De.bottom),Ht=(e,t)=>({width:Qe(e),height:Ue(t)}),Ie=({width:e,height:t,children:n})=>s.jsx(a.Box,{pt:De.top,pr:De.right,pb:De.bottom,pl:De.left,sx:{width:e,height:t,overflow:"hidden",position:"relative"},children:n}),Cs={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"}};J.use([B.GridComponent,B.VisualMapComponent,B.LegendComponent,B.TooltipComponent,_e.CanvasRenderer]);function Qd({context:e}){const{value:t}=$(e.instanceData,"config"),n=e.data,{width:r,height:i}=e.viewport,{x_axis_data_key:o,y_axis_data_key:l,z_axis_data_key:u,xAxis3D:c,yAxis3D:d,zAxis3D:h}=y.defaults({},t,Cs),p=g.useMemo(()=>Jt(n,o),[n,o]),{x,y:m,z:j}=g.useMemo(()=>({x:z(o),y:z(l),z:z(u)}),[o,l,u]),{min:C,max:T}=g.useMemo(()=>{const A=y.minBy(p,X=>X[j.columnKey]),F=y.maxBy(p,X=>X[j.columnKey]);return{min:y.get(A,j.columnKey),max:y.get(F,j.columnKey)}},[p,j]),D={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:C,max:T,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:c,yAxis3D:d,zAxis3D:h,grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}},series:[{type:"bar3D",wireframe:{},data:p.map(A=>[A[x.columnKey],A[m.columnKey],A[j.columnKey]])}]};return t?s.jsx(Ie,{width:r,height:i,children:s.jsx(Se,{echarts:J,option:D,style:Ht(r,i),notMerge:!0,theme:"merico-light"})}):null}const ca=g.createContext(null),Ss=ca.Provider;function _s(){const e=g.useContext(ca);if(!e)throw new Error("Please use DashboardModelContextProvider");return e}const Z=()=>_s(),da=()=>_s(),pa=g.createContext({searchButtonProps:{}}),ks=pa.Provider;function ha(){return g.useContext(pa)}const xa=g.createContext(null),Ts=xa.Provider;function fa(){const e=g.useContext(xa);if(!e)throw new Error("Please use ContentModelContextProvider");return e}const R=()=>fa(),pe=()=>fa(),Ud={inEditMode:!1},Cn=g.createContext(Ud),ga=g.createContext({panel:null,data:{},loading:!1,errors:[],downloadPanelScreenshot:()=>{}}),Ds=ga.Provider;function ma(){const e=g.useContext(ga);if(!e.panel)throw new Error("Please use PanelContextProvider");return e}const ft=()=>ma(),Be=()=>ma(),Kd={fullScreenPanelID:"",setFullScreenPanelID:y.noop},Is=g.createContext(Kd);function ya(){const e=g.useContext(Is);if(!e)throw new Error("Please use FullScreenPanelContext.Provider");return e}const O=S.observer(g.forwardRef(({label:e,required:t,value:n,onChange:r,clearable:i=!1,sx:o,...l},u)=>{const{panel:c}=Be(),d=g.useMemo(()=>c.dataFieldOptions(n,i),[n,i]);if(d.length===0){const h=c.explainDataKey(n);return s.jsxs(a.HoverCard,{shadow:"md",position:"bottom-start",withinPortal:!0,zIndex:320,children:[s.jsx(a.HoverCard.Target,{children:s.jsx(a.Box,{children:s.jsx(a.TextInput,{label:e,required:t,defaultValue:h.columnKey,readOnly:!0,disabled:!0})})}),s.jsx(a.HoverCard.Dropdown,{children:s.jsxs(a.Group,{position:"left",spacing:0,children:[s.jsx(a.Text,{size:"xs",color:h.queryName?"black":"red",sx:{fontFamily:"monospace"},children:h.queryName??h.queryID}),s.jsx(a.Text,{size:"xs",color:"black",sx:{fontFamily:"monospace"},children:"."}),s.jsx(a.Text,{size:"xs",color:"red",sx:{fontFamily:"monospace"},children:h.columnKey})]})})]})}return s.jsx(a.Select,{ref:u,label:e,data:d,value:n,onChange:r,required:t,sx:o,maxDropdownHeight:500,...l})}));function Yd({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=y.defaults({},t,Cs),{control:i,handleSubmit:o,reset:l}=b.useForm({defaultValues:r});return g.useEffect(()=>{l(r)},[t]),t?s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:o(n),children:[s.jsx(a.Text,{children:"X Axis"}),s.jsxs(a.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[s.jsx(b.Controller,{name:"x_axis_data_key",control:i,render:({field:u})=>s.jsx(O,{label:"Data Field",required:!0,...u})}),s.jsx(b.Controller,{name:"xAxis3D.name",control:i,render:({field:u})=>s.jsx(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),s.jsx(a.Text,{mt:"lg",children:"Y Axis"}),s.jsxs(a.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[s.jsx(b.Controller,{name:"y_axis_data_key",control:i,render:({field:u})=>s.jsx(O,{label:"Data Field",required:!0,...u})}),s.jsx(b.Controller,{name:"yAxis3D.name",control:i,render:({field:u})=>s.jsx(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),s.jsx(a.Text,{mt:"lg",children:"Z Axis"}),s.jsxs(a.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[s.jsx(b.Controller,{name:"z_axis_data_key",control:i,render:({field:u})=>s.jsx(O,{label:"Data Field",required:!0,...u})}),s.jsx(b.Controller,{name:"zAxis3D.name",control:i,render:({field:u})=>s.jsx(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),s.jsx(a.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:s.jsxs(a.Button,{color:"blue",type:"submit",children:[s.jsx(k.DeviceFloppy,{size:20}),s.jsx(a.Text,{ml:"md",children:"Save"})]})})]})}):null}function Xd(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:i,y_axis_data_key:o,z_axis_data_key:l,...u}=e;return{...u,x_axis_data_key:r(i),y_axis_data_key:r(o),z_axis_data_key:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class Jd extends ue{constructor(){super(...arguments);L(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:i}=n;return{...n,version:2,config:Xd(i,r)}})}}const Zd={displayName:"Bar Chart (3D)",displayGroup:"ECharts-based charts",migrator:new Jd,name:"bar-3d",viewRender:Qd,configRender:Yd,createConfig(){return{version:2,config:y.cloneDeep(Cs)}}},Oe={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
57
- `)},ba={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:ep,configRender:Hd,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 Hd(e){return s.jsx(s.Fragment,{})}function ep(e){return s.jsx(a.Text,{children:"Click chart's series"})}const tp=[{label:"Truncate",value:"truncate"},{label:"Break Line",value:"break"},{label:"Break Word",value:"breakAll"}],Sn=g.forwardRef(({sectionTitle:e,value:t,onChange:n},r)=>{const i=o=>l=>{const u=y.cloneDeep(t);y.set(u,o,l),n(u)};return s.jsxs(a.Stack,{spacing:0,children:[e&&s.jsx(a.Divider,{mb:-5,mt:5,variant:"dotted",label:e,labelPosition:"right",labelProps:{color:"dimmed"}}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(a.NumberInput,{label:"Max Width",hideControls:!0,value:t.width,onChange:i("width")}),s.jsx(a.Select,{label:"Overflow",data:tp,value:t.overflow,onChange:i("overflow")}),s.jsx(a.TextInput,{label:"Ellipsis",value:t.ellipsis,disabled:!0})]})]})}),Ke=g.forwardRef(({value:e,onChange:t},n)=>{const r=o=>{t({...e,on_axis:o})},i=o=>{t({...e,in_tooltip:o})};return s.jsxs(a.Stack,{ref:n,spacing:0,children:[s.jsx(Sn,{sectionTitle:"Overflow on Axis",value:e.on_axis,onChange:r}),s.jsx(Sn,{sectionTitle:"Overflow in Tooltip",value:e.in_tooltip,onChange:i})]})});function Me(){return{on_axis:{width:80,overflow:"truncate",ellipsis:"..."},in_tooltip:{width:200,overflow:"break",ellipsis:"..."}}}function $e({overflow:e,width:t}){const n={truncate:"initial",break:"break-all",breakAll:"break-word"}[e],r=e==="truncate"?"nowrap":"initial",i={truncate:"ellipsis",break:"clip",breakAll:"clip"}[e];return`
54
+ `;function hs(e,t){const n=Object.keys(t),r=Object.values(t);try{return new Function(...n,`return \`${e}\`;`)(...r)}catch(i){throw n.length===0&&e.includes("$")?new Error("[formatSQL] insufficient payload"):i}}function xs(e,t){try{return hs(e,t)}catch(n){return console.error(n),n.message}}function sd({sql:e,pre_process:t}){if(!t.trim())return e;try{return new Function(`return ${t}`)()({sql:e},nt)}catch(n){return console.error(n),e}}function rd(e,t,n){if(!e.trim())return t;try{return new Function(`return ${e}`)()(t,nt,n)}catch(r){return console.error(r),t}}function id(e){e=e||{};const t=Object.keys(e).sort(),n=[];for(let r=0;r<t.length;r++){const i=t[r];if(i!="authentication"&&e[i])n.push(t[r]+"="+(typeof e[i]=="object"?JSON.stringify(e[i]):e[i]));else{const o=Object.keys(e[i]).sort();for(let l=0;l<o.length;l++){const c=o[l];c!="sign"&&e[i][c]&&n.push(o[l]+"="+(typeof e[i][c]=="object"?JSON.stringify(e[i][c]):e[i][c]))}}}return n.sort().join("&")}function ad(e,t){let n=id(e);return n+="&key="+t,Xu.MD5(n).toString().toUpperCase()}class Ji{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:ad({app_id:this.app_id,nonce_str:n,...t},this.app_secret)}}getRequest(t,n){return(r,i,o,l)=>{const c=this.buildHeader(o),u=this.buildAxiosConfig(t,r,i,o,c,n);return He(u).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,i,o,l){const c={baseURL:this.baseURL,method:t,url:n,params:t==="GET"?r:i.params,headers:o,signal:l};return["POST","PUT"].includes(t)&&(c.data=i.string?JSON.stringify(r):r,c.data.authentication=this.getAuthentication(c.data)),c}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 od{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 Zi extends Ji{constructor(){super(...arguments);P(this,"makeQueryENV",null)}query(n){return async(r,i={})=>{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,i)}}httpDataSourceQuery(n){return async(r,i={})=>{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,i,!0)}}structure(n){return async(r,i={})=>this.post(n)("/query/structure",r,i)}}class Hi{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 Mt=new Zi;function fs(e){Mt.baseURL!==e.apiBaseURL&&(Mt.baseURL=e.apiBaseURL),e.app_id&&(Mt.app_id=e.app_id),e.app_secret&&(Mt.app_secret=e.app_secret),e.makeQueryENV&&(Mt.makeQueryENV=e.makeQueryENV)}const ea=new Hi(Mt),Ke=ea,Yt=g.forwardRef(function({value:t,onChange:n,...r},i){return s.jsx(a.TextInput,{ref:i,value:t,onChange:n,...r})});function z(e){const[t,n]=e.split(".");return{queryID:t,columnKey:n}}function ld(e){return e.includes(".")?z(e):{queryID:"",columnKey:e}}function Ye(e,t){var i;const{queryID:n,columnKey:r}=z(t);return n?r?((i=e[n])==null?void 0:i.map(o=>o[r]))??[]:e[n]:[]}function Xt(e,t){const{queryID:n}=z(t);return n?e[n]:[]}function cd(e){return Object.values(e)[0]}function mn(e,t){const{queryID:n,columnKey:r}=z(t);return e[r]}const ta=["function aggregation({ queryData }, utils) {",' return "Aggregation Result";',"}"].join(`
55
+ `),zt={type:"none",config:{},fallback:"0"};function ud(e){const t=Array.from(e).sort((r,i)=>r-i),n=Math.floor(t.length/2);return t.length%2===0?(t[n-1]+t[n])/2:t[n]}function dd(e,t){switch(t.type){case"sum":return y.sum(e);case"mean":return y.mean(e);case"median":return ud(e);case"max":return y.max(e);case"min":return y.min(e);case"quantile":return Rt.quantile(e,t.config.p);case"CV":const n=It.std(...e),r=It.mean(...e);return r?n/r:Number.NaN;case"std":return It.std(...e);default:return e}}function gs(e,t){const n=e.map(Number),r=dd(n,t);return typeof r=="number"?Number.isFinite(r)?r:t.fallback:r??t.fallback}function pd(e,t,n){try{const r=Xt(e,t);return new Function(`return ${n.config.func}`)()({queryData:r},nt)}catch(r){return console.error(r),r.message}}function yn(e,t,n){try{return n.type==="custom"?pd(e,t,n):gs(Ye(e,t),n)}catch(r){return console.error(r),null}}class hd{constructor({valueRange:t,colorRange:n}){P(this,"mapper");this.mapper=yt.interpolate(t,n)}getColor(t){return this.mapper(t)}}const me={mantissa:0,output:"number",trimMantissa:!1,average:!1,absolute:!1};function G(e,{absolute:t,...n}){if(e===null)return String(e);try{let r=xn(e).value();if(r===void 0||Number.isNaN(r))throw new Error(`[formatNumber]Not a number: ${e}`);return t&&(r=Math.abs(r)),xn(r).format(n)}catch(r){return console.debug(r),String(e)}}function xd(e){return e===null?"null":e===void 0?"undefined":Array.isArray(e)?`Array(${e.length})`:e.toString()}function st({data_field:e,aggregation:t},n){return yn(n,e,t)}function Ae({formatter:e,aggregation:t},n){if(typeof n!="string"&&typeof n!="number")return xd(n);if(t.type==="custom")return n;try{return G(n,e)}catch(r){return console.error(r),n}}function fd(e,t){if(e.type==="static")return e.staticColor;if(e.type==="continuous")try{if(typeof t!="number")throw new Error(`[getColorByColorConf] Invalid type of aggregated value: ${t}`);return new hd(e).getColor(t)}catch(n){return console.error(n),"black"}return"black"}function gd(e,t){const{color:n,data_field:r,aggregation:i,size:o,weight:l}=e,c=yn(t,r,i),u=Ae(e,c);return s.jsx(a.Text,{sx:{fontSize:o,display:"inline"},color:fd(n,c),weight:l,children:u})}function md(e,t){const n={};return e.forEach(r=>{const i=r.name;n[i]=gd(r,t)}),n}function yd(e){return e.split(" ").map((t,n)=>s.jsxs(g.Fragment,{children:[t," "]},n))}function bd(e){const n=e.replaceAll("<br />","<br/>").replaceAll(`
56
+ `,"<br/>").split("<br/>");return n.map((i,o)=>{const l=[yd(i)];return o!==n.length-1&&l.push(s.jsx("br",{},`br-${o}`)),l}).flat().filter(i=>i!==void 0)}function ms(e){return bd(e)}function Jt(e,t,n){const r=md(t,n),i=/^\{(.+)\}(.*)$/;return e.split("$").map((o,l)=>{const c=i.exec(o);if(!c)return ms(o);const u=r[c[1]];if(!u)return ms(o);const d=c[2]??"";return s.jsxs(g.Fragment,{children:[u,ms(d)]},`${o}-${l}`)})}function jd(e,t){const{data_field:n,aggregation:r}=e,i=yn(t,n,r);return Ae(e,i)}function na(e,t){const n={};return e.forEach(r=>{n[r.name]=jd(r,t)}),n}function bn(e,t,n){const r=na(t,n),i=/^\{(.+)\}(.*)$/;return e.split("$").map(o=>{const l=i.exec(o);if(!l)return o;const c=r[l[1]];if(!c)return o;const u=l[2]??"";return`${c}${u}`}).join("")}const ys={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 vd(){be.registerTheme("merico-light",{color:Object.values(ys.graphics.multiple),visualMap:{color:Object.values(ys.graphics.depth).reverse()},axes:[{type:"all",name:"通用坐标轴",axisLineColor:"#97999D",axisTickColor:"#97999D",axisLabelShow:!0,axisLabelColor:"#818388",splitLineShow:!0,splitLineColor:["#E0E6F1"]}]})}function sa(){vd()}function*wd(e){const t=ys.graphics[e];if(!t)throw new Error("Invalid palette key provided");const n=Object.values(t);let r=0;for(;;)yield n[r%n.length],r++}function ra(){return{filters:{},context:{}}}function bs(e){const t=ra();if(!e)return ra();const{filters:n=t.filters,context:r=t.context}=e;return{filters:n,context:r}}class je extends g.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 s.jsxs(a.Box,{children:[s.jsx(a.Text,{size:"xs",children:(t=this.state.error)==null?void 0:t.message}),s.jsx(a.Button,{variant:"subtle",size:"xs",mx:"auto",compact:!0,sx:{display:"block"},onClick:n,children:"Retry"})]})}return this.props.children}}function Cd(e,t={handleError:!0}){return n=>s.jsx(je,{...t,children:s.jsx(e,{...n})})}function Sd(e,t){return new Function(`return ${e}`)()(t,nt)}function _d(e,t,n){return Sd(e,{context:t,filters:n})}function kd(e,t){try{return new Function(`return ${e.config.processing.pre}`)()(t,nt)}catch(n){return console.error(n),t}}function Td(e,t){return new Function(`return ${e.config.processing.post}`)()(t,nt)}function Dd(e,t,n){return e?new Function(`return ${e}`)()(t,nt,n):t}function ia(){Di.use([du.CanvasRenderer,et.BarChart,et.BoxplotChart,et.FunnelChart,et.HeatmapChart,et.LineChart,et.PieChart,et.RadarChart,et.ScatterChart,et.SunburstChart,ct.CalendarComponent,ct.DataZoomComponent,ct.GridComponent,ct.LegendComponent,ct.TooltipComponent,ct.MarkLineComponent,ct.MarkAreaComponent,ct.VisualMapComponent])}const At=e=>y.cloneDeepWith(e,(t,n)=>{if(n!==void 0&&t)return U.toJS(t)}),jn={sqlSnippet:new RegExp("(?<=sql_snippets\\.)([^\\?}.]+)","gm"),context:new RegExp("(?<=context\\.)([^\\?}.]+)","gm"),filter:new RegExp("(?<=filters\\.)([^\\?}.]+)","gm")};function Id(e,t){const n=Ii.decode(t);n!==e&&(console.error("Inconsistent sql"),console.groupCollapsed("Inconsistent sql"),console.table({before:e,after:t,v:n}),console.groupEnd())}async function Md({query:e,name:t,payload:n,additionals:r},i){if(!e.sql)return[];const{type:o,key:l,sql:c,pre_process:u,post_process:d}=e,h=hs(c,n),p=sd({sql:h,pre_process:u}),x=Ii.encode(p);Id(p,x);let m=await Ke.query(i)({type:o,key:l,query:x,...r},{params:{name:t}});return m=rd(d,m,bs(n)),m}async function zd({type:e,key:t,configString:n,name:r,additionals:i},o){try{return await Ke.httpDataSourceQuery(o)({type:e,key:t,query:n,...i},{params:{name:r}})}catch(l){if(He.isCancel(l))throw l;return console.error(l),l}}async function js(){try{return(await Ke.post()("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}},{})).data}catch(e){return console.error(e),[]}}async function aa(){try{return(await Ke.post()("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}},{})).data}catch(e){return console.error(e),[]}}class oa{constructor(t){P(this,"rootRef");this.rootRef=U.observable({current:t})}async deleteItem(t){U.runInAction(()=>{y.unset(this.rootRef.current,[t])})}getItem(t){const n=this.getValueFromRoot(t);return Promise.resolve(n)}getValueFromRoot(t){return t===null?U.toJS(this.rootRef.current):y.get(this.rootRef.current,[t])}setItem(t,n){if(t===null)if(y.isObject(n))U.runInAction(()=>{this.rootRef.current=n});else throw new Error("Cannot set root value to non-object");else U.runInAction(()=>{y.set(this.rootRef.current,[t],n)});return Promise.resolve(this.getItem(t))}watchItem(t,n,r){return U.reaction(()=>this.getValueFromRoot(t),(i,o)=>{n(i,o)},{requiresObservable:!0,fireImmediately:y.get(r,"fireImmediately",!1)})}}class Ad{constructor(){P(this,"channels",new Map);P(this,"globalChannel",new Mi)}getChannel(t){const n=this.channels.get(t);if(n)return n;const r=new Mi;return this.channels.set(t,r),r}}class Ed{constructor(t){P(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 Ad,instanceData:new oa(t.viz.conf)};return this.instances.set(t.id,r),r}}function la(e,t,n,r){return{vizManager:n,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new oa({}),colorPalette:{getColor(){return()=>""}},data:t,variables:r}}const Pd=e=>{const{panel:t,measure:n,vizManager:r,data:i,variables:o}=e,l=r.resolveComponent(t.viz.type),c=r.getOrCreateInstance(t),u={...la(c,i,r,o),viewport:{width:n.w,height:n.h}},d=l.viewRender;return s.jsx(d,{context:u,instance:c,...y.omit(e,["panel","vizManager","data"])})},Ld=e=>{const{vizManager:t,panel:n,data:r,variables:i}=e,o=t.resolveComponent(n.viz.type),l=t.getOrCreateInstance(n),c={...la(l,r,t,i)},u=o.configRender;return s.jsx(u,{context:c,instance:l,...y.omit(e,["panel","vizManager","data"])})},ca=(e,t)=>{const n=tt.bezier(e),r=tt.bezier(t);return function(i){return i<50?n(i*2/100).hex():r((i-50)*2/100).hex()}},vn=e=>{const t=tt.bezier(e);return function(n){return t(n/100).hex()}},Bd={type:"interpolation",displayName:"Red / Green",getColor:ca(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},Od={type:"interpolation",displayName:"Yellow / Blue",getColor:ca(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},$d={type:"interpolation",displayName:"Red",getColor:vn(["#fff7f1","darkred"]),name:"red",category:"sequential"},Vd={type:"interpolation",displayName:"Green",getColor:vn(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},qd={type:"interpolation",displayName:"Blue",getColor:vn(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},Nd={type:"interpolation",displayName:"Orange",getColor:vn(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class Fd{constructor(t){P(this,"symbol");this.symbol=Symbol(t)}}function rt(e){return new Fd(e)}class vs{constructor(){P(this,"parent");P(this,"factoryRegistry",new Map);P(this,"instanceRegistry",new Map)}createScoped(){const t=new vs;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=y.get(t,"dispose");y.isFunction(n)&&n.bind(t)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}const ua="12.2.0",Gd=Object.freeze(Object.defineProperty({__proto__:null,version:ua},Symbol.toStringTag,{value:"Module"}));class Wd{constructor(t){P(this,"staticColors",new Map);P(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 Rd{constructor(){P(this,"plugins",new Map);P(this,"vizComponents",new Map);P(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 Qd{constructor(){P(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 i=this.migrations.filter(c=>c.version>t.from&&c.version<=t.to),o=y.orderBy(i,"version","asc");if(((l=y.last(o))==null?void 0:l.version)!==t.to)throw new Error(`Migration to version ${t.to} not found`);return o.reduce((c,u)=>u.handler(c,r),n)}}class ae extends Qd{constructor(){super(),this.configVersions()}version(t,n){return super.version(t,(r,i)=>({version:t,...n(r,i)}))}async migrate({configData:t,panelModel:n}){const r=await t.getItem(null),i=y.get(r,"version",0),o=this.run({from:i,to:this.VERSION},r,{panelModel:n});await t.setItem(null,o)}async needMigration({configData:t}){const n=await t.getItem(null);return y.get(n,"version",0)<this.VERSION}}const O=(e,t)=>{const[n,{setFalse:r}]=$.useBoolean(!0),[i,o]=g.useState();g.useEffect(()=>(e.getItem(t).then(c=>{o(c),r()}),e.watchItem(t,c=>{o(c)})));const l=g.useCallback(async c=>{await e.setItem(t,c),o(c)},[e,t]);return{loading:n,value:i,set:l}},_e={top:16,right:16,bottom:16,left:16},Ge=e=>Math.max(0,e-_e.left-_e.right),We=e=>Math.max(0,e-_e.top-_e.bottom),Zt=(e,t)=>({width:Ge(e),height:We(t)}),ke=({width:e,height:t,children:n})=>s.jsx(a.Box,{pt:_e.top,pr:_e.right,pb:_e.bottom,pl:_e.left,sx:{width:e,height:t,overflow:"hidden",position:"relative"},children:n}),ws={x_axis_data_key:"",y_axis_data_key:"",z_axis_data_key:"",xAxis3D:{type:"value",name:"X Axis Name"},yAxis3D:{type:"value",name:"Y Axis Name"},zAxis3D:{type:"value",name:"Z Axis Name"}};function Ud({context:e}){const{value:t}=O(e.instanceData,"config"),n=e.data,{width:r,height:i}=e.viewport,{x_axis_data_key:o,y_axis_data_key:l,z_axis_data_key:c,xAxis3D:u,yAxis3D:d,zAxis3D:h}=y.defaults({},t,ws),p=g.useMemo(()=>Xt(n,o),[n,o]),{x,y:m,z:j}=g.useMemo(()=>({x:z(o),y:z(l),z:z(c)}),[o,l,c]),{min:C,max:T}=g.useMemo(()=>{const A=y.minBy(p,Y=>Y[j.columnKey]),N=y.maxBy(p,Y=>Y[j.columnKey]);return{min:y.get(A,j.columnKey),max:y.get(N,j.columnKey)}},[p,j]),D={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:C,max:T,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:u,yAxis3D:d,zAxis3D:h,grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}},series:[{type:"bar3D",wireframe:{},data:p.map(A=>[A[x.columnKey],A[m.columnKey],A[j.columnKey]])}]};return t?s.jsx(ke,{width:r,height:i,children:s.jsx(we,{echarts:be,option:D,style:Zt(r,i),notMerge:!0,theme:"merico-light"})}):null}const da=g.createContext(null),Cs=da.Provider;function Ss(){const e=g.useContext(da);if(!e)throw new Error("Please use DashboardModelContextProvider");return e}const X=()=>Ss(),pa=()=>Ss(),ha=g.createContext({searchButtonProps:{}}),_s=ha.Provider;function xa(){return g.useContext(ha)}const fa=g.createContext(null),ks=fa.Provider;function ga(){const e=g.useContext(fa);if(!e)throw new Error("Please use ContentModelContextProvider");return e}const W=()=>ga(),ce=()=>ga(),Kd={inEditMode:!1},wn=g.createContext(Kd),ma=g.createContext({panel:null,data:{},loading:!1,errors:[],downloadPanelScreenshot:()=>{}}),Ts=ma.Provider;function ya(){const e=g.useContext(ma);if(!e.panel)throw new Error("Please use PanelContextProvider");return e}const xt=()=>ya(),Ee=()=>ya(),Yd={fullScreenPanelID:"",setFullScreenPanelID:y.noop},Ds=g.createContext(Yd);function ba(){const e=g.useContext(Ds);if(!e)throw new Error("Please use FullScreenPanelContext.Provider");return e}const B=S.observer(g.forwardRef(({label:e,required:t,value:n,onChange:r,clearable:i=!1,sx:o,...l},c)=>{const{panel:u}=Ee(),d=g.useMemo(()=>u.dataFieldOptions(n,i),[n,i]);if(d.length===0){const h=u.explainDataKey(n);return s.jsxs(a.HoverCard,{shadow:"md",position:"bottom-start",withinPortal:!0,zIndex:320,children:[s.jsx(a.HoverCard.Target,{children:s.jsx(a.Box,{children:s.jsx(a.TextInput,{label:e,required:t,defaultValue:h.columnKey,readOnly:!0,disabled:!0})})}),s.jsx(a.HoverCard.Dropdown,{children:s.jsxs(a.Group,{position:"left",spacing:0,children:[s.jsx(a.Text,{size:"xs",color:h.queryName?"black":"red",sx:{fontFamily:"monospace"},children:h.queryName??h.queryID}),s.jsx(a.Text,{size:"xs",color:"black",sx:{fontFamily:"monospace"},children:"."}),s.jsx(a.Text,{size:"xs",color:"red",sx:{fontFamily:"monospace"},children:h.columnKey})]})})]})}return s.jsx(a.Select,{ref:c,label:e,data:d,value:n,onChange:r,required:t,sx:o,maxDropdownHeight:500,...l})}));function Xd({context:e}){const{value:t,set:n}=O(e.instanceData,"config"),r=y.defaults({},t,ws),{control:i,handleSubmit:o,reset:l}=b.useForm({defaultValues:r});return g.useEffect(()=>{l(r)},[t]),t?s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:o(n),children:[s.jsx(a.Text,{children:"X Axis"}),s.jsxs(a.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[s.jsx(b.Controller,{name:"x_axis_data_key",control:i,render:({field:c})=>s.jsx(B,{label:"Data Field",required:!0,...c})}),s.jsx(b.Controller,{name:"xAxis3D.name",control:i,render:({field:c})=>s.jsx(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...c})})]}),s.jsx(a.Text,{mt:"lg",children:"Y Axis"}),s.jsxs(a.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[s.jsx(b.Controller,{name:"y_axis_data_key",control:i,render:({field:c})=>s.jsx(B,{label:"Data Field",required:!0,...c})}),s.jsx(b.Controller,{name:"yAxis3D.name",control:i,render:({field:c})=>s.jsx(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...c})})]}),s.jsx(a.Text,{mt:"lg",children:"Z Axis"}),s.jsxs(a.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[s.jsx(b.Controller,{name:"z_axis_data_key",control:i,render:({field:c})=>s.jsx(B,{label:"Data Field",required:!0,...c})}),s.jsx(b.Controller,{name:"zAxis3D.name",control:i,render:({field:c})=>s.jsx(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...c})})]}),s.jsx(a.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:s.jsxs(a.Button,{color:"blue",type:"submit",children:[s.jsx(k.DeviceFloppy,{size:20}),s.jsx(a.Text,{ml:"md",children:"Save"})]})})]})}):null}function Jd(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis_data_key:i,y_axis_data_key:o,z_axis_data_key:l,...c}=e;return{...c,x_axis_data_key:r(i),y_axis_data_key:r(o),z_axis_data_key:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class Zd extends ae{constructor(){super(...arguments);P(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:i}=n;return{...n,version:2,config:Jd(i,r)}})}}const Hd={displayName:"Bar Chart (3D)",displayGroup:"ECharts-based charts",migrator:new Zd,name:"bar-3d",viewRender:Ud,configRender:Xd,createConfig(){return{version:2,config:y.cloneDeep(ws)}}},Pe={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
57
+ `)},ja={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:tp,configRender:ep,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 ep(e){return s.jsx(s.Fragment,{})}function tp(e){return s.jsx(a.Text,{children:"Click chart's series"})}const np=[{label:"Truncate",value:"truncate"},{label:"Break Line",value:"break"},{label:"Break Word",value:"breakAll"}],Cn=g.forwardRef(({sectionTitle:e,value:t,onChange:n},r)=>{const i=o=>l=>{const c=y.cloneDeep(t);y.set(c,o,l),n(c)};return s.jsxs(a.Stack,{spacing:0,children:[e&&s.jsx(a.Divider,{mb:-5,mt:5,variant:"dotted",label:e,labelPosition:"right",labelProps:{color:"dimmed"}}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(a.NumberInput,{label:"Max Width",hideControls:!0,value:t.width,onChange:i("width")}),s.jsx(a.Select,{label:"Overflow",data:np,value:t.overflow,onChange:i("overflow")}),s.jsx(a.TextInput,{label:"Ellipsis",value:t.ellipsis,disabled:!0})]})]})}),Re=g.forwardRef(({value:e,onChange:t},n)=>{const r=o=>{t({...e,on_axis:o})},i=o=>{t({...e,in_tooltip:o})};return s.jsxs(a.Stack,{ref:n,spacing:0,children:[s.jsx(Cn,{sectionTitle:"Overflow on Axis",value:e.on_axis,onChange:r}),s.jsx(Cn,{sectionTitle:"Overflow in Tooltip",value:e.in_tooltip,onChange:i})]})});function Te(){return{on_axis:{width:80,overflow:"truncate",ellipsis:"..."},in_tooltip:{width:200,overflow:"break",ellipsis:"..."}}}function Le({overflow:e,width:t}){const n={truncate:"initial",break:"break-all",breakAll:"break-word"}[e],r=e==="truncate"?"nowrap":"initial",i={truncate:"ellipsis",break:"clip",breakAll:"clip"}[e];return`
58
58
  max-width: ${t}px;
59
59
  word-break: ${n};
60
60
  white-space: ${r};
61
61
  overflow: hidden;
62
62
  text-overflow: ${i};
63
- `}function Ve(e){return{width:e.width,overflow:e.overflow,ellipsis:e.ellipsis}}const jt={x_axis_scroll:!1,y_axis_scroll:!1,x_axis_slider:!1,y_axis_slider:!1};function ja(){return y.cloneDeep(jt)}const Ms={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...Oe},overflow:Me()}},y_axis:{name:"Y Axis",data_key:"value",label_formatter:je},tooltip:{metrics:[]},color:"rgba(99, 152, 199, 0.10)",reference_lines:[],legend:{show:!0,top:"10",right:"0",left:"auto",bottom:"auto",orient:"vertical",type:"scroll"},dataZoom:ja()};function vt(e,t){return g.useMemo(()=>{const{queryID:n,columnKey:r}=z(t);return y.keyBy(e[n],r)},[e,t])}const qe=(e,t)=>{const[n,r]=g.useState([]);return g.useEffect(()=>e.watchTriggerSnapshotList(i=>r(i.filter(o=>o.schemaRef===t))),[]),n};class Lt{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,y.omit(n,t))}async getItem(t){const n=await this.root.getItem(this.path);return t===null?n:y.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,(i,o)=>{n(i,o)},r):this.root.watchItem(this.path,(i,o)=>{const l=y.get(i,t),u=y.get(o,t);l!==u&&n(l,u)},r)}}class zs{constructor(t,n,r){L(this,"attachmentStorage");this.instance=t,this.attachmentKey=n,this.constructInstance=r,this.attachmentStorage=new Lt(t.instanceData,n)}async getInstance(t){if(await this.attachmentStorage.getItem(t))return this.constructInstance(new Lt(this.attachmentStorage,t))}async create(t,n){return await this.attachmentStorage.setItem(t,n),this.constructInstance(new Lt(this.attachmentStorage,t))}async remove(t){await this.attachmentStorage.deleteItem(t)}async list(){const t=await this.attachmentStorage.getItem(null);return Promise.all(y.values(t).map(n=>this.constructInstance(new Lt(this.attachmentStorage,n.id))))}}function np(e,t){const{value:n,set:r}=$(e.operation.operationData,"config"),[i,o]=g.useState(y.defaults({},n,t)),l=async()=>{await r(i)};return g.useEffect(()=>{o(y.defaults({},n,t))},[n]),{config:i,setConfig:o,commit:l}}function sp(e){const{config:t,setConfig:n,commit:r}=np(e,{urlTemplate:"",openInNewTab:!0});async function i(){await r()}async function o(u){n({...t,openInNewTab:u}),await r()}const l=u=>n({...t,urlTemplate:u.currentTarget.value});return s.jsxs(a.Stack,{children:[s.jsx(a.TextInput,{label:"Url",value:t.urlTemplate,onChange:l,onBlur:i}),s.jsx(a.Switch,{label:"Open in new Tab",checked:t.openInNewTab,onChange:u=>o(u.currentTarget.checked)})]})}async function rp(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 ip extends ue{constructor(){super(...arguments);L(this,"VERSION",1)}configVersions(){this.version(1,n=>n)}}const ap={displayName:"Open Link",id:"builtin:op:open-link",configRender:sp,run:rp,migrator:new ip,createDefaultConfig:()=>({version:1,config:{urlTemplate:"",openInNewTab:!0}})};function op(e){const{value:t,set:n}=$(e.operationData,"config"),r=i=>void n({template:i});return[(t==null?void 0:t.template)||"",r]}function lp(e){const[t,n]=op(e.operation);return s.jsx(a.TextInput,{defaultValue:t,onBlur:r=>n(r.currentTarget.value),label:"console.log"})}async function up(e,t){const n=await t.operationData.getItem("config"),r=y.template(n.template||"");console.log("run with payload",e),console.log(r(e))}const cp={displayName:"console.log (debug)",id:"builtin:op:debug",configRender:lp,run:up},dp=S.observer(e=>{const t=R(),{value:n,set:r}=$(e.operation.operationData,"config");console.log({value:n,viewID:n==null?void 0:n.viewID});const i=(n==null?void 0:n.viewID)||"",o=l=>void r({viewID:l});return s.jsx(a.Select,{defaultValue:i,value:i,onChange:o,label:"View",data:t.views.options,withinPortal:!0,zIndex:340,maxDropdownHeight:500})});async function pp(e,t){const r=(await t.operationData.getItem("config")).viewID;window.dispatchEvent(new CustomEvent("open-view",{detail:{viewID:r}}))}const hp={displayName:"Open View",id:"builtin:op:open_view",configRender:dp,run:pp},xp={"tbody tr":{opacity:.5,transition:"opacity 200ms ease"},"tr[data-affected=true]":{opacity:1}},fp=({value:e="",onChange:t})=>{const[n,r]=g.useState(e);g.useEffect(()=>{r(e)},[e]);const i=()=>{t(n)};return s.jsx(a.TextInput,{size:"xs",label:"",value:n,onChange:o=>r(o.currentTarget.value),sx:{flexGrow:1},rightSection:s.jsx(a.ActionIcon,{color:"green",size:"xs",onClick:i,disabled:n===e,children:s.jsx(_.IconDeviceFloppy,{})})})},gp={dictionary:{}},mp=S.observer(e=>{const t=R(),{value:n=gp,set:r}=$(e.operation.operationData,"config"),{dictionary:i={}}=n;console.log({value:{...n},dictionary:{...i},filters:[...t.filters.keyLabelOptions]});const o=(l,u)=>{if(u===""){const c={...i};delete c[l],r({dictionary:c});return}r({dictionary:{...i,[l]:u}})};return s.jsxs(a.Table,{sx:xp,children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Set filter"}),s.jsx("th",{children:"with"})]})}),s.jsx("tbody",{children:[...t.filters.keyLabelOptions].map(l=>{const u=l.value in i;return s.jsxs("tr",{"data-affected":u,children:[s.jsx("td",{children:l.label}),s.jsx("td",{children:s.jsx(fp,{value:i[l.value],onChange:c=>o(l.value,c)})})]},l.value)})})]})});async function yp(e,t){const r=(await t.operationData.getItem("config")).dictionary;window.dispatchEvent(new CustomEvent("set-filter-values",{detail:{dictionary:r,payload:e}}))}const bp={displayName:"Set Filter Values",id:"builtin:op:set_filter_values",configRender:mp,run:yp},jp={filter_keys:[]},vp=S.observer(e=>{const t=R(),{value:n=jp,set:r}=$(e.operation.operationData,"config"),{filter_keys:i=[]}=n,o=u=>{r({filter_keys:[...u]})},l=g.useMemo(()=>t.filters.current.map(u=>({label:u.label,value:u.key})),[t.filters.values]);return s.jsx(a.Stack,{spacing:10,children:s.jsx(a.MultiSelect,{label:"Select Filters to Clear",data:l,value:i,onChange:o})})});async function wp(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=[cp,ap,hp,bp,{displayName:"Clear Filter Values",id:"builtin:op:clear_filter_values",configRender:vp,run:wp}];class Cp{constructor(t,n=_n){L(this,"attachments");this.operations=n;const r=async i=>{const{id:o,schemaRef:l}=await i.getItem(null);return{id:o,schemaRef:l,operationData:new Lt(i,"data")}};this.attachments=new zs(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 i=this.tryGetSchema(r.schemaRef);if(!i){console.warn(`Operation schema '${r.schemaRef}' is not defined`);return}await i.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 i={configData:r.operationData},o=this.tryGetSchema(r.schemaRef),l=o==null?void 0:o.migrator;return l&&await l.needMigration(i)});return(await Promise.all(n)).some(r=>r)}async runMigration(){const n=(await this.attachments.list()).map(async r=>{const i={configData:r.operationData},o=this.tryGetSchema(r.schemaRef),l=o==null?void 0:o.migrator;l&&await l.needMigration(i)&&await l.migrate(i)});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 i=await this.attachments.getInstance(t);return!i||i.schemaRef!==n.id?await this.attachments.create(t,{id:t,schemaRef:n.id,data:((l=n.createDefaultConfig)==null?void 0:l.call(n))??{}}):i}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 va="__TRIGGERS";class Sp{constructor(t,n){L(this,"attachments");this.instance=t,this.component=n;const r=async i=>{const{id:o,schemaRef:l}=await i.getItem(null);return{id:o,schemaRef:l,triggerData:new Lt(i,"data")}};this.attachments=new zs(t,va,r)}watchTriggerSnapshotList(t){return this.instance.instanceData.watchItem(va,n=>{const r=y.values(n).map(i=>({id:y.get(i,"id"),schemaRef:y.get(i,"schemaRef"),config:K.toJS(y.get(i,"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 i=this.getTriggerSchemaList().find(u=>u.id===r.schemaRef),o=i==null?void 0:i.migrator,l={configData:r.triggerData};return o&&await o.needMigration(l)?()=>o.migrate(l):null});return Promise.all(n).then(r=>r.filter(i=>i))}async needMigration(){return(await this.getMigrationTasks()).length>0}async runMigration(){const t=await this.getMigrationTasks();await Promise.all(t.map(n=>n()))}}class As{constructor(t,n,r){L(this,"operationManager");L(this,"triggerManager");L(this,"attachments");this.operationManager=new Cp(t,r),this.triggerManager=new Sp(t,n);const i=async o=>{const{id:l,triggerRef:u,operationRef:c}=await o.getItem(null);return{id:l,triggerRef:u,operationRef:c}};this.attachments=new zs(t,"__INTERACTIONS",i)}async addInteraction(t,n){const r=t.id,i=n.id,o=`[${r}]:[${i}]`;await this.attachments.create(o,{id:o,triggerRef:r,operationRef:i})}getInteractionList(){return this.attachments.list()}async removeInteraction(t){const n=await this.attachments.getInstance(t);if(!n)return;const{triggerRef:r,operationRef:i}=n;await this.getTriggerRefCount(r)<=1&&await this.triggerManager.removeTrigger(r),await this.getOperationRefCount(i)<=1&&await this.operationManager.removeOperation(i),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 i=(await this.getInteractionList()).filter(o=>o.triggerRef===t);await Promise.all(i.map(async o=>{try{return await this.operationManager.runOperation(o.operationRef,n)}catch(l){console.warn(`Failed to run operation '${o.operationRef}'`,l)}}))}}const Ne=({vizManager:e,instance:t})=>V.useCreation(()=>new As(t,e.resolveComponent(t.type),_n),[t,e]),wa=e=>{const{title:t="Variables",variables:n}=e,r=oe.useClipboard(),i=o=>{r.copy(o),dt.showNotification({color:"green",message:"Copied to clipboard"})};return s.jsxs(a.Paper,{withBorder:!0,p:"sm",children:[s.jsx(a.Text,{size:"xs",color:"dimmed",mb:"sm",children:t}),s.jsx(a.Stack,{style:{maxHeight:"500px"},children:n.map(o=>s.jsxs(a.Text,{size:"sm",children:[s.jsxs(a.Code,{color:"teal",children:["// ",o.description]}),s.jsx("br",{}),s.jsxs(a.Code,{onClick:()=>i(o.name),style:{cursor:"pointer"},children:[o.name," : ",o.valueType]})]},o.name))})]})};class _p{constructor(t,n){L(this,"operationId");L(this,"operation");L(this,"operationSchema");L(this,"variables",[]);this.operationManager=t,this.instance=n,K.makeAutoObservable(this)}get schemaList(){return this.operationManager.getOperationSchemaList()}async configOperation(t,n){const r=await this.operationManager.retrieveTrigger(t),i=this.operationManager.getOperationSchemaList().find(o=>o.id===(r==null?void 0:r.schemaRef));K.runInAction(()=>{this.operationId=t,this.operation=r,this.operationSchema=i,this.variables=n})}async changeSchema(t){this.operationId&&(await this.operationManager.createOrGetOperation(this.operationId,t),await this.configOperation(this.operationId,this.variables))}}function kp(e){return!!e.operationId}const Tp=S.observer(({model:e,onClick:t})=>{var r;const n=(r=e.operationSchema)==null?void 0:r.displayName;return s.jsx(a.Button,{variant:"outline",onClick:t,children:n})}),Dp=S.observer(({model:e})=>{const t={operation:e.operation,instance:e.instance,variables:[]};return g.createElement(e.operationSchema.configRender,t)}),Ip=S.observer(({model:e})=>{const t=e.schemaList,n=t.map(i=>({label:i.displayName,value:i.id}));async function r(i){await e.changeSchema(t.find(o=>o.id===i))}return s.jsx(a.Select,{label:"Operation",data:n,onChange:r,value:e.operationSchema.id,withinPortal:!0,zIndex:340})}),Mp=S.observer(e=>{const[t,{setTrue:n,setFalse:r}]=V.useBoolean(!1),{operationManager:i,operationId:o,instance:l,variables:u}=e,c=V.useCreation(()=>new _p(i,l),[i,l]);return V.useAsyncEffect(async()=>{await c.configOperation(o,u)},[o,c]),kp(c)?s.jsxs(s.Fragment,{children:[s.jsx(Tp,{model:c,onClick:n}),s.jsx(a.Modal,{size:600,opened:t,onClose:r,title:"Operation Settings",zIndex:320,children:s.jsxs(a.Stack,{children:[s.jsx(Ip,{model:c}),s.jsxs(a.Tabs,{defaultValue:"settings",children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"settings",children:"Settings"}),s.jsx(a.Tabs.Tab,{value:"variables",children:"Variables"})]}),s.jsx(a.Tabs.Panel,{value:"settings",pt:10,children:s.jsx(Dp,{model:c})}),s.jsx(a.Tabs.Panel,{value:"variables",pt:10,children:s.jsx(wa,{title:"Variables",variables:c.variables})})]})]})})]}):null});class zp{constructor(t,n){L(this,"triggerId");L(this,"trigger");L(this,"triggerSchema");L(this,"sampleData");this.triggerManager=t,this.instance=n,K.makeAutoObservable(this)}get schemaList(){return this.triggerManager.getTriggerSchemaList()}async configTrigger(t,n){const r=await this.triggerManager.retrieveTrigger(t),i=this.triggerManager.getTriggerSchemaList().find(o=>o.id===(r==null?void 0:r.schemaRef));K.runInAction(()=>{this.triggerId=t,this.trigger=r,this.triggerSchema=i,this.sampleData=n})}async changeSchema(t){this.triggerId&&(await this.triggerManager.createOrGetTrigger(this.triggerId,t),await this.configTrigger(this.triggerId,this.sampleData))}isReady(){return Ap(this)}}function Ap(e){return!!e.triggerId&&!!e.triggerSchema}function Ep(e,t){return V.useCreation(()=>new zp(e,t),[e,t])}const Lp=S.observer(({model:e,onClick:t})=>{const n=e.triggerSchema.nameRender,r={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return s.jsx(a.Button,{variant:"outline",onClick:t,children:g.createElement(n,r)})}),Pp=S.observer(({model:e})=>{const t=e.schemaList,n=t.map(i=>({label:i.displayName,value:i.id}));async function r(i){await e.changeSchema(t.find(o=>o.id===i))}return s.jsx(a.Select,{label:"Trigger",data:n,value:e.triggerSchema.id,onChange:r})}),Bp=S.observer(({model:e})=>{const t={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return g.createElement(e.triggerSchema.configRender,t)}),Op=S.observer(e=>{const[t,{setTrue:n,setFalse:r}]=V.useBoolean(!1),i=e.model;return s.jsxs(s.Fragment,{children:[s.jsx(a.Modal,{opened:t,onClose:r,title:"Setup Trigger",zIndex:320,children:s.jsxs(a.Stack,{children:[s.jsx(Pp,{model:i}),s.jsx(Bp,{model:i}),s.jsx(wa,{title:"Payload",variables:i.triggerSchema.payload})]})}),s.jsx(Lp,{onClick:n,model:i})]})});function $p(e,t){const[n,r]=g.useState([]);return V.useAsyncEffect(async()=>{const i=await e.getInteractionList();r(i)},[t,e]),n}const Vp=S.observer(({item:e,manager:t,instance:n,sampleData:r,variables:i,onRemove:o})=>{const{triggerRef:l,operationRef:u}=e,c=Ep(t.triggerManager,n);if(V.useAsyncEffect(async()=>{await c.configTrigger(l,r)},[c,l,r]),c.isReady()){const d=[...c.triggerSchema.payload,...i];return s.jsxs(a.Group,{children:[s.jsx(Op,{model:c}),s.jsx(Mp,{instance:n,operationId:u,variables:d,operationManager:t.operationManager}),s.jsx(a.ActionIcon,{"aria-label":"delete-interaction",variant:"filled",color:"red",onClick:()=>o(e),children:s.jsx(k.Trash,{size:16})})]})}return null}),qp=e=>{const[t,n]=g.useState(0),{interactionManager:r,instance:i,sampleData:o,variables:l}=e,u=$p(r,t),c=async()=>{const x=await r.triggerManager.createOrGetTrigger(oe.randomId(),r.triggerManager.getTriggerSchemaList()[0]),m=await r.operationManager.createOrGetOperation(oe.randomId(),r.operationManager.getOperationSchemaList()[0]);await r.addInteraction(x,m),n(j=>j+1)};async function d(x){await r.removeInteraction(x.id),n(m=>m+1)}const{data:h=0,loading:p}=V.useRequest(async()=>{try{return(await r.triggerManager.getTriggerSchemaList()).length}catch{return 0}});return s.jsxs(a.Stack,{children:[s.jsx(a.LoadingOverlay,{visible:p}),h===0&&s.jsx(a.Alert,{icon:s.jsx(k.AlertCircle,{size:16}),title:"Unavailable",color:"gray",children:"This visualization does not have available interactions to choose from"}),u.map(x=>s.jsx(Vp,{onRemove:d,instance:i,sampleData:o,variables:l,item:x,manager:e.interactionManager},x.id)),s.jsx(a.Button,{style:{width:"fit-content"},onClick:()=>c(),disabled:h===0,children:"Add interaction"})]})},Np=()=>{const{panel:e,data:t}=ft(),n=e.viz,{vizManager:r}=g.useContext(tt),i=e.json,o=V.useCreation(()=>r.getOrCreateInstance(i),[r,i]),l=V.useCreation(()=>new As(o,r.resolveComponent(n.type),_n),[o,n.type]);return g.useEffect(()=>o.instanceData.watchItem(null,y.throttle(u=>{e.viz.setConf(u)},100,{leading:!1,trailing:!0})),[o]),{instance:o,vizManager:r,interactionManager:l,sampleData:t,variables:[]}},Fp=()=>{const e=Np();return s.jsx(qp,{...e})},Ca={axisTick:{show:!0,alignWithLabel:!0,lineStyle:{width:2}},axisLine:{show:!0,lineStyle:{width:3}},splitLine:{show:!1},z:3};function Gp(e){return y.defaultsDeep({},e,Ca)}const Wp=Object.freeze(Object.defineProperty({__proto__:null,getXAxis:Gp,xAxis:Ca},Symbol.toStringTag,{value:"Module"})),Sa={axisTick:{show:!1},axisLine:{show:!1,lineStyle:{width:3}},splitLine:{show:!0,lineStyle:{type:"dashed"}}};function Rp(e){return y.defaultsDeep({},e,Sa)}const Qp=Object.freeze(Object.defineProperty({__proto__:null,getYAxis:Rp,yAxis:Sa},Symbol.toStringTag,{value:"Module"})),_a={confine:!0,appendToBody:!0};function Up(e){return y.defaultsDeep({},e,_a)}const ne={...Wp,...Qp,...Object.freeze(Object.defineProperty({__proto__:null,getTooltip:Up,tooltip:_a},Symbol.toStringTag,{value:"Module"}))};function Pt({enabled:e,func_content:t}){return(n,r)=>{if(!e)return n;try{return new Function(`return ${t}`)()(n,r)}catch(i){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${i.message}`),n}}}function Kp(e,t){const n=[],r=[];return{boxplotData:Object.entries(e).map(([o,l])=>{const u=l.map(D=>D[t]).sort((D,A)=>D-A),c=Qt.quantile(u,.25)??0,d=Qt.quantile(u,.5)??0,h=Qt.quantile(u,.75)??0,p=h-c,x=c-1.5*p,m=h+1.5*p,j=Math.max(u[0],x),C=Math.min(y.last(u)??0,m);return l.filter(D=>{const A=D[t];return A<j||A>C}).forEach(D=>n.push([o,D[t],D])),l.filter(D=>{const A=D[t];return A>=j&&A<=C}).forEach(D=>r.push([o,D[t],D])),{name:o,min:j,q1:c,median:d,q3:h,max:C}}),outliersData:n,scatterData:r}}function Yp(e,t){const{x_axis:n,y_axis:r}=e;if(!n.data_key||!r.data_key)return[];const i=z(n.data_key),o=z(r.data_key);if(i.queryID!==o.queryID)throw new Error("Please use the same query for X & Y axis");const l=y.groupBy(t[i.queryID],i.columnKey),{boxplotData:u,outliersData:c,scatterData:d}=Kp(l,o.columnKey);return[{source:u},{source:c},{source:d}]}function Xp(e){const t={top:35,left:20,right:15,bottom:25,containLabel:!0};return e.legend.orient==="vertical"&&(t.right=80),e.dataZoom.x_axis_slider&&(t.top=50),t}function Jp({config:e}){const t={...e.legend,data:[{name:"Box",icon:"roundRect",itemStyle:{color:e.color}},{name:"Scatter",icon:"circle",itemStyle:{color:"#ED6A45",opacity:.5}},{name:"Outlier",icon:"circle",itemStyle:{color:"#ED6A45"}}]};return e.legend.orient==="horizontal"&&e.dataZoom.x_axis_slider&&(t.top=15),t}function Zp(e,t,n){const r=t.reduce((i,o)=>{const l=it(o,n);return i[o.name]=Pe(o,l),i},{});return e.map(i=>({name:"refs",type:"scatter",data:[],markLine:{data:[{name:i.name,yAxis:Number(r[i.variable_key])}],silent:!0,symbol:["none","triangle"],symbolRotate:90,symbolSize:[10,8],label:{formatter:function(){return jn(i.template,t,n)},position:"insideEndTop"}}}))}const Es=["max","q3","median","q1","min"],Ls=[10,40];function Ps(e){return e.barLayout({barMinWidth:Ls[0],barMaxWidth:Ls[1],count:2})}function Hp(e,t,n){const{itemStyle:{color:r,borderColor:i,borderWidth:o}}=n,l=Ps(t),u=t.value(0),c=e.source[u],{min:d,q1:h,median:p,q3:x,max:m}=c,j={min:t.coord([u,d]),q1:t.coord([u,h]),median:t.coord([u,p]),q3:t.coord([u,x]),max:t.coord([u,m])},C={left:l[1].offset,center:(l[1].offset+l[1].width)/2,right:l[1].width},T={type:"group",children:[]},D=[{x1:j.max[0]+C.left,x2:j.max[0]+C.right,y1:j.max[1],y2:j.max[1]},{x1:j.median[0]+C.left,x2:j.median[0]+C.right,y1:j.median[1],y2:j.median[1]},{x1:j.min[0]+C.left,x2:j.min[0]+C.right,y1:j.min[1],y2:j.min[1]},{x1:j.min[0]+C.center,x2:j.min[0]+C.center,y1:j.min[1],y2:j.q1[1]},{x1:j.max[0]+C.center,x2:j.max[0]+C.center,y1:j.max[1],y2:j.q3[1]}],A={stroke:i,lineWidth:o};return D.forEach(F=>{T.children.push({type:"line",shape:F,style:A})}),T.children.push({type:"rect",shape:{x:j.q1[0]+C.left,y:j.q1[1],width:C.right-C.left,height:j.q3[1]-j.q1[1]},style:{fill:r,stroke:i,lineWidth:o}}),T}function eh(e,t){const{color:n}=t,r={name:"Box",type:"custom",itemStyle:{color:n,borderColor:"#2F8CC0",borderWidth:2},emphasis:{disabled:!0},boxWidth:Ls,datasetIndex:0};return r.renderItem=(i,o)=>Hp(e,o,r),r}function th(e){const t=Ps(e),n=t[0].width,r=e.value(0),i=e.value(1),[o,l]=e.coord([r,i]),c=o+t[0].offset+Math.random()*n;return{type:"circle",transition:["shape"],x:c,y:l,shape:{cx:0,cy:0,r:2},style:{fill:e.visual("color"),opacity:.5}}}function nh(){const e={name:"Scatter",type:"custom",itemStyle:{color:"#ED6A45"},emphasis:{scale:2},datasetIndex:2};return e.renderItem=(t,n)=>th(n),e}function sh(e,t){const n=Ps(e),r=n[0].width,i=e.value(0),o=e.value(1),[l,u]=e.coord([i,o]),d=l+n[0].offset+Math.random()*r;return{type:"circle",transition:["shape"],x:d,y:u,shape:{cx:0,cy:0,r:3},style:{fill:e.visual("color")}}}function rh(){const e={name:"Outlier",type:"custom",itemStyle:{color:"#ED6A45"},emphasis:{scale:2},datasetIndex:1};return e.renderItem=(t,n)=>sh(n),e}function ih(e,t){const n=t[0],r=eh(n,e),i=nh(),o=rh();return[{name:"Placeholder Box",type:"boxplot",ignore:!0,silent:!0,itemStyle:{color:"none",borderColor:"none",opacity:0},boxWidth:[20,80],datasetIndex:0,encode:{y:Es,x:"name",itemName:["name"],tooltip:Es}},{name:"Outlier",type:"scatter",symbolSize:7,itemStyle:{color:"transparent"},ignore:!0,silent:!0,emphasis:{disabled:!0},datasetIndex:1},r,i,o]}const ah=(e,t)=>{const n=Es.map(o=>`
63
+ `}function Be(e){return{width:e.width,overflow:e.overflow,ellipsis:e.ellipsis}}const bt={x_axis_scroll:!1,y_axis_scroll:!1,x_axis_slider:!1,y_axis_slider:!1};function va(){return y.cloneDeep(bt)}const Is={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...Pe},overflow:Te()}},y_axis:{name:"Y Axis",data_key:"value",label_formatter:me},tooltip:{metrics:[]},color:"rgba(99, 152, 199, 0.10)",reference_lines:[],legend:{show:!0,top:"10",right:"0",left:"auto",bottom:"auto",orient:"vertical",type:"scroll"},dataZoom:va()};function jt(e,t){return g.useMemo(()=>{const{queryID:n,columnKey:r}=z(t);return y.keyBy(e[n],r)},[e,t])}const Oe=(e,t)=>{const[n,r]=g.useState([]);return g.useEffect(()=>e.watchTriggerSnapshotList(i=>r(i.filter(o=>o.schemaRef===t))),[]),n};class Et{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,y.omit(n,t))}async getItem(t){const n=await this.root.getItem(this.path);return t===null?n:y.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,(i,o)=>{n(i,o)},r):this.root.watchItem(this.path,(i,o)=>{const l=y.get(i,t),c=y.get(o,t);l!==c&&n(l,c)},r)}}class Ms{constructor(t,n,r){P(this,"attachmentStorage");this.instance=t,this.attachmentKey=n,this.constructInstance=r,this.attachmentStorage=new Et(t.instanceData,n)}async getInstance(t){if(await this.attachmentStorage.getItem(t))return this.constructInstance(new Et(this.attachmentStorage,t))}async create(t,n){return await this.attachmentStorage.setItem(t,n),this.constructInstance(new Et(this.attachmentStorage,t))}async remove(t){await this.attachmentStorage.deleteItem(t)}async list(){const t=await this.attachmentStorage.getItem(null);return Promise.all(y.values(t).map(n=>this.constructInstance(new Et(this.attachmentStorage,n.id))))}}function sp(e,t){const{value:n,set:r}=O(e.operation.operationData,"config"),[i,o]=g.useState(y.defaults({},n,t)),l=async()=>{await r(i)};return g.useEffect(()=>{o(y.defaults({},n,t))},[n]),{config:i,setConfig:o,commit:l}}function rp(e){const{config:t,setConfig:n,commit:r}=sp(e,{urlTemplate:"",openInNewTab:!0});async function i(){await r()}async function o(c){n({...t,openInNewTab:c}),await r()}const l=c=>n({...t,urlTemplate:c.currentTarget.value});return s.jsxs(a.Stack,{children:[s.jsx(a.TextInput,{label:"Url",value:t.urlTemplate,onChange:l,onBlur:i}),s.jsx(a.Switch,{label:"Open in new Tab",checked:t.openInNewTab,onChange:c=>o(c.currentTarget.checked)})]})}async function ip(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 ap extends ae{constructor(){super(...arguments);P(this,"VERSION",1)}configVersions(){this.version(1,n=>n)}}const op={displayName:"Open Link",id:"builtin:op:open-link",configRender:rp,run:ip,migrator:new ap,createDefaultConfig:()=>({version:1,config:{urlTemplate:"",openInNewTab:!0}})};function lp(e){const{value:t,set:n}=O(e.operationData,"config"),r=i=>void n({template:i});return[(t==null?void 0:t.template)||"",r]}function cp(e){const[t,n]=lp(e.operation);return s.jsx(a.TextInput,{defaultValue:t,onBlur:r=>n(r.currentTarget.value),label:"console.log"})}async function up(e,t){const n=await t.operationData.getItem("config"),r=y.template(n.template||"");console.log("run with payload",e),console.log(r(e))}const dp={displayName:"console.log (debug)",id:"builtin:op:debug",configRender:cp,run:up},pp=S.observer(e=>{const t=W(),{value:n,set:r}=O(e.operation.operationData,"config");console.log({value:n,viewID:n==null?void 0:n.viewID});const i=(n==null?void 0:n.viewID)||"",o=l=>void r({viewID:l});return s.jsx(a.Select,{defaultValue:i,value:i,onChange:o,label:"View",data:t.views.options,withinPortal:!0,zIndex:340,maxDropdownHeight:500})});async function hp(e,t){const r=(await t.operationData.getItem("config")).viewID;window.dispatchEvent(new CustomEvent("open-view",{detail:{viewID:r}}))}const xp={displayName:"Open View",id:"builtin:op:open_view",configRender:pp,run:hp},fp={"tbody tr":{opacity:.5,transition:"opacity 200ms ease"},"tr[data-affected=true]":{opacity:1}},gp=({value:e="",onChange:t})=>{const[n,r]=g.useState(e);g.useEffect(()=>{r(e)},[e]);const i=()=>{t(n)};return s.jsx(a.TextInput,{size:"xs",label:"",value:n,onChange:o=>r(o.currentTarget.value),sx:{flexGrow:1},rightSection:s.jsx(a.ActionIcon,{color:"green",size:"xs",onClick:i,disabled:n===e,children:s.jsx(_.IconDeviceFloppy,{})})})},mp={dictionary:{}},yp=S.observer(e=>{const t=W(),{value:n=mp,set:r}=O(e.operation.operationData,"config"),{dictionary:i={}}=n;console.log({value:{...n},dictionary:{...i},filters:[...t.filters.keyLabelOptions]});const o=(l,c)=>{if(c===""){const u={...i};delete u[l],r({dictionary:u});return}r({dictionary:{...i,[l]:c}})};return s.jsxs(a.Table,{sx:fp,children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Set filter"}),s.jsx("th",{children:"with"})]})}),s.jsx("tbody",{children:[...t.filters.keyLabelOptions].map(l=>{const c=l.value in i;return s.jsxs("tr",{"data-affected":c,children:[s.jsx("td",{children:l.label}),s.jsx("td",{children:s.jsx(gp,{value:i[l.value],onChange:u=>o(l.value,u)})})]},l.value)})})]})});async function bp(e,t){const r=(await t.operationData.getItem("config")).dictionary;window.dispatchEvent(new CustomEvent("set-filter-values",{detail:{dictionary:r,payload:e}}))}const jp={displayName:"Set Filter Values",id:"builtin:op:set_filter_values",configRender:yp,run:bp},vp={filter_keys:[]},wp=S.observer(e=>{const t=W(),{value:n=vp,set:r}=O(e.operation.operationData,"config"),{filter_keys:i=[]}=n,o=c=>{r({filter_keys:[...c]})},l=g.useMemo(()=>t.filters.current.map(c=>({label:c.label,value:c.key})),[t.filters.values]);return s.jsx(a.Stack,{spacing:10,children:s.jsx(a.MultiSelect,{label:"Select Filters to Clear",data:l,value:i,onChange:o})})});async function Cp(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 Sn=[dp,op,xp,jp,{displayName:"Clear Filter Values",id:"builtin:op:clear_filter_values",configRender:wp,run:Cp}];class Sp{constructor(t,n=Sn){P(this,"attachments");this.operations=n;const r=async i=>{const{id:o,schemaRef:l}=await i.getItem(null);return{id:o,schemaRef:l,operationData:new Et(i,"data")}};this.attachments=new Ms(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 i=this.tryGetSchema(r.schemaRef);if(!i){console.warn(`Operation schema '${r.schemaRef}' is not defined`);return}await i.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 i={configData:r.operationData},o=this.tryGetSchema(r.schemaRef),l=o==null?void 0:o.migrator;return l&&await l.needMigration(i)});return(await Promise.all(n)).some(r=>r)}async runMigration(){const n=(await this.attachments.list()).map(async r=>{const i={configData:r.operationData},o=this.tryGetSchema(r.schemaRef),l=o==null?void 0:o.migrator;l&&await l.needMigration(i)&&await l.migrate(i)});await Promise.all(n)}async createOrGetOperation(t,n){var l;if(!this.getOperationSchemaList().some(c=>c.id===n.id))throw new Error(`Operation schema '${n.id}' is not defined`);const i=await this.attachments.getInstance(t);return!i||i.schemaRef!==n.id?await this.attachments.create(t,{id:t,schemaRef:n.id,data:((l=n.createDefaultConfig)==null?void 0:l.call(n))??{}}):i}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 wa="__TRIGGERS";class _p{constructor(t,n){P(this,"attachments");this.instance=t,this.component=n;const r=async i=>{const{id:o,schemaRef:l}=await i.getItem(null);return{id:o,schemaRef:l,triggerData:new Et(i,"data")}};this.attachments=new Ms(t,wa,r)}watchTriggerSnapshotList(t){return this.instance.instanceData.watchItem(wa,n=>{const r=y.values(n).map(i=>({id:y.get(i,"id"),schemaRef:y.get(i,"schemaRef"),config:U.toJS(y.get(i,"data.config"))}));t(r)},{fireImmediately:!0})}async createOrGetTrigger(t,n,r={recreate:!1}){var c;if(!this.getTriggerSchemaList().some(u=>u.id===n.id))throw new Error(`Trigger schema '${n.id}' is not defined in component '${this.component.name}'`);const o=await this.attachments.getInstance(t);return!o||r.recreate||o.schemaRef!==n.id?await this.attachments.create(t,{id:t,schemaRef:n.id,data:((c=n==null?void 0:n.createDefaultConfig)==null?void 0:c.call(n))||{}}):o}async getTriggerList(){return await this.attachments.list()}getTriggerSchemaList(){return this.component.triggers||[]}async removeTrigger(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 i=this.getTriggerSchemaList().find(c=>c.id===r.schemaRef),o=i==null?void 0:i.migrator,l={configData:r.triggerData};return o&&await o.needMigration(l)?()=>o.migrate(l):null});return Promise.all(n).then(r=>r.filter(i=>i))}async needMigration(){return(await this.getMigrationTasks()).length>0}async runMigration(){const t=await this.getMigrationTasks();await Promise.all(t.map(n=>n()))}}class zs{constructor(t,n,r){P(this,"operationManager");P(this,"triggerManager");P(this,"attachments");this.operationManager=new Sp(t,r),this.triggerManager=new _p(t,n);const i=async o=>{const{id:l,triggerRef:c,operationRef:u}=await o.getItem(null);return{id:l,triggerRef:c,operationRef:u}};this.attachments=new Ms(t,"__INTERACTIONS",i)}async addInteraction(t,n){const r=t.id,i=n.id,o=`[${r}]:[${i}]`;await this.attachments.create(o,{id:o,triggerRef:r,operationRef:i})}getInteractionList(){return this.attachments.list()}async removeInteraction(t){const n=await this.attachments.getInstance(t);if(!n)return;const{triggerRef:r,operationRef:i}=n;await this.getTriggerRefCount(r)<=1&&await this.triggerManager.removeTrigger(r),await this.getOperationRefCount(i)<=1&&await this.operationManager.removeOperation(i),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 i=(await this.getInteractionList()).filter(o=>o.triggerRef===t);await Promise.all(i.map(async o=>{try{return await this.operationManager.runOperation(o.operationRef,n)}catch(l){console.warn(`Failed to run operation '${o.operationRef}'`,l)}}))}}const $e=({vizManager:e,instance:t})=>$.useCreation(()=>new zs(t,e.resolveComponent(t.type),Sn),[t,e]),Ca=e=>{const{title:t="Variables",variables:n}=e,r=re.useClipboard(),i=o=>{r.copy(o),ut.showNotification({color:"green",message:"Copied to clipboard"})};return s.jsxs(a.Paper,{withBorder:!0,p:"sm",children:[s.jsx(a.Text,{size:"xs",color:"dimmed",mb:"sm",children:t}),s.jsx(a.Stack,{style:{maxHeight:"500px"},children:n.map(o=>s.jsxs(a.Text,{size:"sm",children:[s.jsxs(a.Code,{color:"teal",children:["// ",o.description]}),s.jsx("br",{}),s.jsxs(a.Code,{onClick:()=>i(o.name),style:{cursor:"pointer"},children:[o.name," : ",o.valueType]})]},o.name))})]})};class kp{constructor(t,n){P(this,"operationId");P(this,"operation");P(this,"operationSchema");P(this,"variables",[]);this.operationManager=t,this.instance=n,U.makeAutoObservable(this)}get schemaList(){return this.operationManager.getOperationSchemaList()}async configOperation(t,n){const r=await this.operationManager.retrieveTrigger(t),i=this.operationManager.getOperationSchemaList().find(o=>o.id===(r==null?void 0:r.schemaRef));U.runInAction(()=>{this.operationId=t,this.operation=r,this.operationSchema=i,this.variables=n})}async changeSchema(t){this.operationId&&(await this.operationManager.createOrGetOperation(this.operationId,t),await this.configOperation(this.operationId,this.variables))}}function Tp(e){return!!e.operationId}const Dp=S.observer(({model:e,onClick:t})=>{var r;const n=(r=e.operationSchema)==null?void 0:r.displayName;return s.jsx(a.Button,{variant:"outline",onClick:t,children:n})}),Ip=S.observer(({model:e})=>{const t={operation:e.operation,instance:e.instance,variables:[]};return g.createElement(e.operationSchema.configRender,t)}),Mp=S.observer(({model:e})=>{const t=e.schemaList,n=t.map(i=>({label:i.displayName,value:i.id}));async function r(i){await e.changeSchema(t.find(o=>o.id===i))}return s.jsx(a.Select,{label:"Operation",data:n,onChange:r,value:e.operationSchema.id,withinPortal:!0,zIndex:340})}),zp=S.observer(e=>{const[t,{setTrue:n,setFalse:r}]=$.useBoolean(!1),{operationManager:i,operationId:o,instance:l,variables:c}=e,u=$.useCreation(()=>new kp(i,l),[i,l]);return $.useAsyncEffect(async()=>{await u.configOperation(o,c)},[o,u]),Tp(u)?s.jsxs(s.Fragment,{children:[s.jsx(Dp,{model:u,onClick:n}),s.jsx(a.Modal,{size:600,opened:t,onClose:r,title:"Operation Settings",zIndex:320,children:s.jsxs(a.Stack,{children:[s.jsx(Mp,{model:u}),s.jsxs(a.Tabs,{defaultValue:"settings",children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"settings",children:"Settings"}),s.jsx(a.Tabs.Tab,{value:"variables",children:"Variables"})]}),s.jsx(a.Tabs.Panel,{value:"settings",pt:10,children:s.jsx(Ip,{model:u})}),s.jsx(a.Tabs.Panel,{value:"variables",pt:10,children:s.jsx(Ca,{title:"Variables",variables:u.variables})})]})]})})]}):null});class Ap{constructor(t,n){P(this,"triggerId");P(this,"trigger");P(this,"triggerSchema");P(this,"sampleData");this.triggerManager=t,this.instance=n,U.makeAutoObservable(this)}get schemaList(){return this.triggerManager.getTriggerSchemaList()}async configTrigger(t,n){const r=await this.triggerManager.retrieveTrigger(t),i=this.triggerManager.getTriggerSchemaList().find(o=>o.id===(r==null?void 0:r.schemaRef));U.runInAction(()=>{this.triggerId=t,this.trigger=r,this.triggerSchema=i,this.sampleData=n})}async changeSchema(t){this.triggerId&&(await this.triggerManager.createOrGetTrigger(this.triggerId,t),await this.configTrigger(this.triggerId,this.sampleData))}isReady(){return Ep(this)}}function Ep(e){return!!e.triggerId&&!!e.triggerSchema}function Pp(e,t){return $.useCreation(()=>new Ap(e,t),[e,t])}const Lp=S.observer(({model:e,onClick:t})=>{const n=e.triggerSchema.nameRender,r={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return s.jsx(a.Button,{variant:"outline",onClick:t,children:g.createElement(n,r)})}),Bp=S.observer(({model:e})=>{const t=e.schemaList,n=t.map(i=>({label:i.displayName,value:i.id}));async function r(i){await e.changeSchema(t.find(o=>o.id===i))}return s.jsx(a.Select,{label:"Trigger",data:n,value:e.triggerSchema.id,onChange:r})}),Op=S.observer(({model:e})=>{const t={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return g.createElement(e.triggerSchema.configRender,t)}),$p=S.observer(e=>{const[t,{setTrue:n,setFalse:r}]=$.useBoolean(!1),i=e.model;return s.jsxs(s.Fragment,{children:[s.jsx(a.Modal,{opened:t,onClose:r,title:"Setup Trigger",zIndex:320,children:s.jsxs(a.Stack,{children:[s.jsx(Bp,{model:i}),s.jsx(Op,{model:i}),s.jsx(Ca,{title:"Payload",variables:i.triggerSchema.payload})]})}),s.jsx(Lp,{onClick:n,model:i})]})});function Vp(e,t){const[n,r]=g.useState([]);return $.useAsyncEffect(async()=>{const i=await e.getInteractionList();r(i)},[t,e]),n}const qp=S.observer(({item:e,manager:t,instance:n,sampleData:r,variables:i,onRemove:o})=>{const{triggerRef:l,operationRef:c}=e,u=Pp(t.triggerManager,n);if($.useAsyncEffect(async()=>{await u.configTrigger(l,r)},[u,l,r]),u.isReady()){const d=[...u.triggerSchema.payload,...i];return s.jsxs(a.Group,{children:[s.jsx($p,{model:u}),s.jsx(zp,{instance:n,operationId:c,variables:d,operationManager:t.operationManager}),s.jsx(a.ActionIcon,{"aria-label":"delete-interaction",variant:"filled",color:"red",onClick:()=>o(e),children:s.jsx(k.Trash,{size:16})})]})}return null}),Np=e=>{const[t,n]=g.useState(0),{interactionManager:r,instance:i,sampleData:o,variables:l}=e,c=Vp(r,t),u=async()=>{const x=await r.triggerManager.createOrGetTrigger(re.randomId(),r.triggerManager.getTriggerSchemaList()[0]),m=await r.operationManager.createOrGetOperation(re.randomId(),r.operationManager.getOperationSchemaList()[0]);await r.addInteraction(x,m),n(j=>j+1)};async function d(x){await r.removeInteraction(x.id),n(m=>m+1)}const{data:h=0,loading:p}=$.useRequest(async()=>{try{return(await r.triggerManager.getTriggerSchemaList()).length}catch{return 0}});return s.jsxs(a.Stack,{children:[s.jsx(a.LoadingOverlay,{visible:p}),h===0&&s.jsx(a.Alert,{icon:s.jsx(k.AlertCircle,{size:16}),title:"Unavailable",color:"gray",children:"This visualization does not have available interactions to choose from"}),c.map(x=>s.jsx(qp,{onRemove:d,instance:i,sampleData:o,variables:l,item:x,manager:e.interactionManager},x.id)),s.jsx(a.Button,{style:{width:"fit-content"},onClick:()=>u(),disabled:h===0,children:"Add interaction"})]})},Fp=()=>{const{panel:e,data:t}=xt(),n=e.viz,{vizManager:r}=g.useContext(Ze),i=e.json,o=$.useCreation(()=>r.getOrCreateInstance(i),[r,i]),l=$.useCreation(()=>new zs(o,r.resolveComponent(n.type),Sn),[o,n.type]);return g.useEffect(()=>o.instanceData.watchItem(null,y.throttle(c=>{e.viz.setConf(c)},100,{leading:!1,trailing:!0})),[o]),{instance:o,vizManager:r,interactionManager:l,sampleData:t,variables:[]}},Gp=()=>{const e=Fp();return s.jsx(Np,{...e})},Sa={axisTick:{show:!0,alignWithLabel:!0,lineStyle:{width:2}},axisLine:{show:!0,lineStyle:{width:3}},splitLine:{show:!1},z:3};function Wp(e){return y.defaultsDeep({},e,Sa)}const Rp=Object.freeze(Object.defineProperty({__proto__:null,getXAxis:Wp,xAxis:Sa},Symbol.toStringTag,{value:"Module"})),_a={axisTick:{show:!1},axisLine:{show:!1,lineStyle:{width:3}},splitLine:{show:!0,lineStyle:{type:"dashed"}}};function Qp(e){return y.defaultsDeep({},e,_a)}const Up=Object.freeze(Object.defineProperty({__proto__:null,getYAxis:Qp,yAxis:_a},Symbol.toStringTag,{value:"Module"})),ka={confine:!0,appendToBody:!0};function Kp(e){return y.defaultsDeep({},e,ka)}const ee={...Rp,...Up,...Object.freeze(Object.defineProperty({__proto__:null,getTooltip:Kp,tooltip:ka},Symbol.toStringTag,{value:"Module"}))};function Pt({enabled:e,func_content:t}){return(n,r)=>{if(!e)return n;try{return new Function(`return ${t}`)()(n,r)}catch(i){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${i.message}`),n}}}function Yp(e,t){const n=[],r=[];return{boxplotData:Object.entries(e).map(([o,l])=>{const c=l.map(D=>D[t]).sort((D,A)=>D-A),u=Rt.quantile(c,.25)??0,d=Rt.quantile(c,.5)??0,h=Rt.quantile(c,.75)??0,p=h-u,x=u-1.5*p,m=h+1.5*p,j=Math.max(c[0],x),C=Math.min(y.last(c)??0,m);return l.filter(D=>{const A=D[t];return A<j||A>C}).forEach(D=>n.push([o,D[t],D])),l.filter(D=>{const A=D[t];return A>=j&&A<=C}).forEach(D=>r.push([o,D[t],D])),{name:o,min:j,q1:u,median:d,q3:h,max:C}}),outliersData:n,scatterData:r}}function Xp(e,t){const{x_axis:n,y_axis:r}=e;if(!n.data_key||!r.data_key)return[];const i=z(n.data_key),o=z(r.data_key);if(i.queryID!==o.queryID)throw new Error("Please use the same query for X & Y axis");const l=y.groupBy(t[i.queryID],i.columnKey),{boxplotData:c,outliersData:u,scatterData:d}=Yp(l,o.columnKey);return[{source:c},{source:u},{source:d}]}function Jp(e){const t={top:35,left:20,right:15,bottom:25,containLabel:!0};return e.legend.orient==="vertical"&&(t.right=80),e.dataZoom.x_axis_slider&&(t.top=50),t}function Zp({config:e}){const t={...e.legend,data:[{name:"Box",icon:"roundRect",itemStyle:{color:e.color}},{name:"Scatter",icon:"circle",itemStyle:{color:"#ED6A45",opacity:.5}},{name:"Outlier",icon:"circle",itemStyle:{color:"#ED6A45"}}]};return e.legend.orient==="horizontal"&&e.dataZoom.x_axis_slider&&(t.top=15),t}function Hp(e,t,n){const r=t.reduce((i,o)=>{const l=st(o,n);return i[o.name]=Ae(o,l),i},{});return e.map(i=>({name:"refs",type:"scatter",data:[],markLine:{data:[{name:i.name,yAxis:Number(r[i.variable_key])}],silent:!0,symbol:["none","triangle"],symbolRotate:90,symbolSize:[10,8],label:{formatter:function(){return bn(i.template,t,n)},position:"insideEndTop"}}}))}const As=["max","q3","median","q1","min"],Es=[10,40];function Ps(e){return e.barLayout({barMinWidth:Es[0],barMaxWidth:Es[1],count:2})}function eh(e,t,n){const{itemStyle:{color:r,borderColor:i,borderWidth:o}}=n,l=Ps(t),c=t.value(0),u=e.source[c],{min:d,q1:h,median:p,q3:x,max:m}=u,j={min:t.coord([c,d]),q1:t.coord([c,h]),median:t.coord([c,p]),q3:t.coord([c,x]),max:t.coord([c,m])},C={left:l[1].offset,center:(l[1].offset+l[1].width)/2,right:l[1].width},T={type:"group",children:[]},D=[{x1:j.max[0]+C.left,x2:j.max[0]+C.right,y1:j.max[1],y2:j.max[1]},{x1:j.median[0]+C.left,x2:j.median[0]+C.right,y1:j.median[1],y2:j.median[1]},{x1:j.min[0]+C.left,x2:j.min[0]+C.right,y1:j.min[1],y2:j.min[1]},{x1:j.min[0]+C.center,x2:j.min[0]+C.center,y1:j.min[1],y2:j.q1[1]},{x1:j.max[0]+C.center,x2:j.max[0]+C.center,y1:j.max[1],y2:j.q3[1]}],A={stroke:i,lineWidth:o};return D.forEach(N=>{T.children.push({type:"line",shape:N,style:A})}),T.children.push({type:"rect",shape:{x:j.q1[0]+C.left,y:j.q1[1],width:C.right-C.left,height:j.q3[1]-j.q1[1]},style:{fill:r,stroke:i,lineWidth:o}}),T}function th(e,t){const{color:n}=t,r={name:"Box",type:"custom",itemStyle:{color:n,borderColor:"#2F8CC0",borderWidth:2},emphasis:{disabled:!0},boxWidth:Es,datasetIndex:0};return r.renderItem=(i,o)=>eh(e,o,r),r}function nh(e){const t=Ps(e),n=t[0].width,r=e.value(0),i=e.value(1),[o,l]=e.coord([r,i]),u=o+t[0].offset+Math.random()*n;return{type:"circle",transition:["shape"],x:u,y:l,shape:{cx:0,cy:0,r:2},style:{fill:e.visual("color"),opacity:.5}}}function sh(){const e={name:"Scatter",type:"custom",itemStyle:{color:"#ED6A45"},emphasis:{scale:2},datasetIndex:2};return e.renderItem=(t,n)=>nh(n),e}function rh(e,t){const n=Ps(e),r=n[0].width,i=e.value(0),o=e.value(1),[l,c]=e.coord([i,o]),d=l+n[0].offset+Math.random()*r;return{type:"circle",transition:["shape"],x:d,y:c,shape:{cx:0,cy:0,r:3},style:{fill:e.visual("color")}}}function ih(){const e={name:"Outlier",type:"custom",itemStyle:{color:"#ED6A45"},emphasis:{scale:2},datasetIndex:1};return e.renderItem=(t,n)=>rh(n),e}function ah(e,t){const n=t[0],r=th(n,e),i=sh(),o=ih();return[{name:"Placeholder Box",type:"boxplot",ignore:!0,silent:!0,itemStyle:{color:"none",borderColor:"none",opacity:0},boxWidth:[20,80],datasetIndex:0,encode:{y:As,x:"name",itemName:["name"],tooltip:As}},{name:"Outlier",type:"scatter",symbolSize:7,itemStyle:{color:"transparent"},ignore:!0,silent:!0,emphasis:{disabled:!0},datasetIndex:1},r,i,o]}const oh=(e,t)=>{const n=As.map(o=>`
64
64
  <tr>
65
65
  <th style="text-align: right; padding: 0 1em;">${y.capitalize(o)}</th>
66
66
  <td style="text-align: left; padding: 0 1em;">
67
- ${W(t[o],e.y_axis.label_formatter)}
67
+ ${G(t[o],e.y_axis.label_formatter)}
68
68
  </td>
69
69
  </tr>`);return`
70
70
  <div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
71
- <div style="${$e(e.x_axis.axisLabel.overflow.in_tooltip)}">${t.name}</div>
71
+ <div style="${Le(e.x_axis.axisLabel.overflow.in_tooltip)}">${t.name}</div>
72
72
  </div>
73
73
  <table style="width: auto">
74
74
  <tbody>
75
75
  ${n.join("")}
76
76
  </tbody>
77
77
  </table>
78
- `},oh=e=>W(e,{output:"number",trimMantissa:!0,mantissa:2,absolute:!1});function ka(e,t){return e.tooltip.metrics.map(n=>{const r=z(n.data_key);return`
78
+ `},lh=e=>G(e,{output:"number",trimMantissa:!0,mantissa:2,absolute:!1});function Ta(e,t){return e.tooltip.metrics.map(n=>{const r=z(n.data_key);return`
79
79
  <tr>
80
80
  <th style="text-align: right; padding: 0 1em;">${n.name}</th>
81
- <td style="text-align: left; padding: 0 1em;">${oh(t[r.columnKey])}</td>
82
- </tr>`})}function lh(e,t){const n=$e(e.x_axis.axisLabel.overflow.in_tooltip),r=[`<tr>
81
+ <td style="text-align: left; padding: 0 1em;">${lh(t[r.columnKey])}</td>
82
+ </tr>`})}function ch(e,t){const n=Le(e.x_axis.axisLabel.overflow.in_tooltip),r=[`<tr>
83
83
  <th style="text-align: right; padding: 0 1em;">${e.y_axis.name}</th>
84
84
  <td style="text-align: left; padding: 0 1em;">${t[1]}</td>
85
85
  </tr>
86
- `],i=ka(e,t[2]);return r.push(...i),`
86
+ `],i=Ta(e,t[2]);return r.push(...i),`
87
87
  <div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
88
88
  <div style="${n}">${t[0]}</div>
89
89
  </div>
@@ -92,11 +92,11 @@ Check the top-level render call using <`+E+">.")}return I}}function rc(w,I){{if(
92
92
  ${r.join("")}
93
93
  </tbody>
94
94
  </table>
95
- `}function uh(e,t){const n=$e(e.x_axis.axisLabel.overflow.in_tooltip),r=[`<tr>
95
+ `}function uh(e,t){const n=Le(e.x_axis.axisLabel.overflow.in_tooltip),r=[`<tr>
96
96
  <th style="text-align: right; padding: 0 1em;">${e.y_axis.name}</th>
97
97
  <td style="text-align: left; padding: 0 1em;">${t[1]}</td>
98
98
  </tr>
99
- `],i=ka(e,t[2]);return r.push(...i),`
99
+ `],i=Ta(e,t[2]);return r.push(...i),`
100
100
  <div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
101
101
  <div style="${n}">${t[0]}</div>
102
102
  </div>
@@ -105,31 +105,31 @@ Check the top-level render call using <`+E+">.")}return I}}function rc(w,I){{if(
105
105
  ${r.join("")}
106
106
  </tbody>
107
107
  </table>
108
- `}const ch=e=>t=>{const{seriesName:n,value:r}=t;switch(n){case"Box":return ah(e,r);case"Outlier":return lh(e,r);case"Scatter":return uh(e,r)}};function dh({config:e}){return ne.getTooltip({trigger:"item",formatter:ch(e)})}function kn(e,t){t||(t="none");const n=[];return e.x_axis_scroll&&n.push({type:"inside",xAxisIndex:[0],filterMode:t,minSpan:1}),e.y_axis_scroll&&n.push({type:"inside",yAxisIndex:[0],filterMode:t,minSpan:1}),e.x_axis_slider&&n.push({type:"slider",xAxisIndex:[0],filterMode:t,bottom:"auto",top:0,height:15,moveHandleSize:0,showDataShadow:!1,minSpan:1}),n}function ph({min:e,max:t}){if(e<=110)return Math.min(0,e);if(e<=200)return 100;const n=Mt.floor(Mt.log10(e)),r=Math.pow(10,n),i=Math.pow(10,n-1);return e/r<=2?y.round(e,-1*(n-1))-i:y.round(e,-1*n)-r}function hh({config:e,data:t,variables:n}){const{x_axis:r,y_axis:i,reference_lines:o}=e,l=Yp(e,t),u=Ve(r.axisLabel.overflow.on_axis),c=ih(e,l);return{dataZoom:kn(e.dataZoom,"filter"),grid:Xp(e),dataset:l,legend:Jp({config:e}),tooltip:dh({config:e}),xAxis:[ne.getXAxis({type:"category",name:r.name,nameGap:25,nameLocation:"center",nameTextStyle:{align:"center"},axisLabel:{...r.axisLabel,...u,formatter:Pt(r.axisLabel.formatter)}})],yAxis:[ne.getYAxis({name:i.name,minInterval:1,axisLabel:{formatter:function(d){return W(d,i.label_formatter)}},min:ph})],series:[...c,...Zp(o,n,t)]}}J.use([B.DataZoomComponent,ie.BoxplotChart,ie.CustomChart,B.MarkLineComponent,B.GridComponent,B.LegendComponent,B.TooltipComponent,_e.CanvasRenderer]);function xh({context:e,instance:t}){const{value:n}=$(e.instanceData,"config"),{variables:r}=e,i=e.data,{width:o,height:l}=e.viewport,u=y.defaults({},n,Ms),c=Ne({vizManager:e.vizManager,instance:t}),d=qe(c.triggerManager,ba.id),h=vt(i,u.x_axis.data_key),p=g.useCallback(j=>{const C=y.get(h,j.name,{error:"rowData is not found"});d.forEach(T=>{c.runInteraction(T.id,{...j,rowData:C})})},[h,d,c]),x=g.useMemo(()=>({click:p}),[p]),m=g.useMemo(()=>hh({config:u,data:i,variables:r}),[u,i,r]);return!n||!o||!l?null:s.jsx(Ie,{width:o,height:l,children:s.jsx(Se,{echarts:J,option:m,style:Ht(o,l),onEvents:x,notMerge:!0,theme:"merico-light"})})}function fh({value:e,onChange:t},n){const{colorManager:r}=g.useContext(tt),i=g.useMemo(()=>r.getStaticColors().map(u=>({label:u.name,group:u.category,value:u.value})),[r]),o=g.useMemo(()=>i.some(l=>l.value===e),[e,i]);return s.jsxs(a.Group,{position:"apart",spacing:4,ref:n,children:[s.jsx(a.TextInput,{placeholder:"Set any color",value:o?"":e,onChange:l=>t(l.currentTarget.value),rightSection:s.jsx(a.ColorSwatch,{color:o?"transparent":e,radius:4}),variant:o?"filled":"default",sx:{maxWidth:"46%",flexGrow:1}}),s.jsx(a.Text,{sx:{flexGrow:0},children:"or"}),s.jsx(a.Select,{data:i,value:e,onChange:t,variant:o?"default":"filled",placeholder:"Pick a theme color",icon:s.jsx(a.ColorSwatch,{color:o?e:"transparent",radius:4}),sx:{maxWidth:"46%",flexGrow:1}})]})}const ke=g.forwardRef(fh);function gh({control:e,index:t,remove:n,variableOptions:r}){return s.jsxs(a.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:i})=>s.jsx(a.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...i})}),s.jsx(b.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:i})=>s.jsx(a.Select,{label:"Value",required:!0,data:r,sx:{flex:1},...i})})]}),s.jsx(b.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:i})=>s.jsx(a.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",required:!0,sx:{flex:1},...i})}),s.jsx(a.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(t),sx:{position:"absolute",top:15,right:5},children:s.jsx(k.Trash,{size:16})})]})}function mh({control:e,watch:t,variables:n}){const{fields:r,append:i,remove:o}=b.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=r.map((h,p)=>({...h,...l[p]})),c=()=>i({name:"",template:"",variable_key:""}),d=g.useMemo(()=>n.map(h=>({label:h.name,value:h.name})),[n]);return s.jsxs(a.Stack,{children:[u.map((h,p)=>s.jsx(gh,{control:e,index:p,remove:o,variableOptions:d},h.id)),s.jsx(a.Group,{position:"center",mt:"xs",children:s.jsx(a.Button,{onClick:c,children:"Add a Reference Line"})})]})}const yh=({disabled:e,value:t,onChange:n})=>{const r=i=>{i&&n(i)};return s.jsxs(a.Box,{sx:{position:"relative"},children:[e&&s.jsx(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),s.jsx(ye,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},Tn=g.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:i,setFalse:o}]=V.useBoolean(),[l,u]=g.useState(e);g.useEffect(()=>{u(e)},[e]);const c=m=>{u({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:j}=l,C={enabled:m,func_content:j};u(C),t(C)},h=()=>{o(),u(e)},p=m=>{u(j=>({...j,func_content:m}))},x=()=>{p(Oe.func_content)};return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"filled",mt:24,onClick:i,sx:{flexGrow:0},children:"Customize Label"}),s.jsx(a.Modal,{size:800,title:"Customize label content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&s.jsxs(a.Stack,{children:[s.jsx(a.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:m=>c(m.currentTarget.checked)}),s.jsx(yh,{value:l.func_content,onChange:p,disabled:!l.enabled}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:x,color:"red",leftIcon:s.jsx(k.Recycle,{size:20}),children:"Reset"}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:h,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:d,children:"OK"})]})]})]})})]})}),bh=({control:e,watch:t})=>(t(["x_axis"]),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"X Axis Name",sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>s.jsx(O,{label:"X Axis Data Field",required:!0,sx:{flex:1},...n})})]}),s.jsx(a.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>s.jsx(a.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:s.jsx(a.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),s.jsx(b.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>s.jsx(Tn,{...n})})]}),s.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>s.jsx(Ke,{...n})})]})),Bs={root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}},jh=["123456789","1234","1234.56789","1.234","0.123456789","-0.123456789"];function vh({format:e}){const[t,{toggle:n}]=oe.useDisclosure(!1);return s.jsxs(a.Box,{children:[s.jsx(a.Button,{variant:"subtle",w:"100%",compact:!0,onClick:n,leftIcon:t?s.jsx(_.IconChevronUp,{size:14}):s.jsx(_.IconChevronDown,{size:14}),children:t?"Close preview":"Open preview"}),s.jsx(a.Collapse,{in:t,children:t&&s.jsxs(a.Table,{highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"In"}),s.jsx("th",{children:"Out"})]})}),s.jsx("tbody",{children:jh.map(r=>s.jsxs("tr",{children:[s.jsx("td",{children:r}),s.jsx("td",{children:s.jsx(we,{children:W(r,e)})})]},r))})]})})]})}function wh({value:e,onChange:t},n){const r=c=>{t({...e,output:c})},i=c=>{const d=c===0?!1:e.trimMantissa;t({...e,mantissa:c,trimMantissa:d})},o=c=>{t({...e,trimMantissa:c.currentTarget.checked})},l=c=>{t({...e,average:c.currentTarget.checked})},u=c=>{const d={...e,absolute:c.currentTarget.checked};t(d)};return console.log({value:e}),s.jsxs(a.Stack,{ref:n,children:[s.jsxs(a.Group,{grow:!0,children:[s.jsx(a.Select,{label:"Format",data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:e.output,onChange:r,sx:{flexGrow:1}}),s.jsx(a.Switch,{label:s.jsxs(a.Stack,{spacing:0,children:[s.jsx(a.Text,{children:"Absolute"}),s.jsx(a.Text,{size:12,color:"gray",children:"Non-negative"})]}),checked:e.absolute,onChange:u,sx:{flexGrow:1},styles:Bs}),s.jsx(a.Switch,{label:s.jsxs(a.Stack,{spacing:0,children:[s.jsx(a.Text,{children:"Average"}),s.jsx(a.Text,{size:12,color:"gray",children:"like 1.234k, 1.234m"})]}),checked:e.average,onChange:l,disabled:e.output!=="number",sx:{flexGrow:1},styles:Bs})]}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(a.NumberInput,{label:"Mantissa",defaultValue:0,min:0,step:1,max:4,value:e.mantissa,onChange:i}),s.jsx(a.Switch,{label:s.jsxs(a.Stack,{spacing:0,children:[s.jsx(a.Text,{children:"Trim mantissa"}),s.jsx(a.Text,{size:12,color:"gray",children:"hide trailing zero(s)"})]}),checked:e.trimMantissa,onChange:o,disabled:e.mantissa===0,styles:Bs}),s.jsx(a.Box,{})]}),s.jsx(vh,{format:e})]})}const Fe=g.forwardRef(wh),Ch=({control:e,watch:t})=>(t(["y_axis"]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"y_axis.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"Y Axis Name",sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"y_axis.data_key",control:e,render:({field:n})=>s.jsx(O,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})})]}),s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),s.jsx(b.Controller,{name:"y_axis.label_formatter",control:e,render:({field:n})=>s.jsx(Fe,{...n})})]})]})),Sh=({control:e,index:t,remove:n})=>s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>s.jsx(O,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed"}),s.jsx(a.Button,{leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),_h=({control:e,watch:t})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((p,x)=>({...p,...o[x]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[d,h]=g.useState(()=>c??null);return g.useEffect(()=>{c&&h(p=>p!==null?p:c)},[c]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(k.InfoCircle,{size:14,color:"#888"}),s.jsx(a.Text,{size:14,color:"#888",children:"Set additional metrics to show in scatter's tooltip"})]}),s.jsxs(a.Tabs,{value:d,onTabChange:p=>h(p),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((p,x)=>s.jsx(a.Tabs.Tab,{value:p.id,children:p.name?p.name:x},p.id)),s.jsx(a.Tabs.Tab,{onClick:u,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),l.map((p,x)=>s.jsx(a.Tabs.Panel,{value:p.id,children:s.jsx(Sh,{control:e,index:x,remove:i},p.id)},p.id))]})]})};function kh({control:e,watch:t}){return s.jsx(a.Stack,{children:s.jsx(_h,{control:e,watch:t})})}const Th=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}],Dh=({control:e,watch:t})=>{const n=t("legend"),r=(i,o)=>{const l={...n,orient:i};i==="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 s.jsxs(a.Stack,{children:[s.jsx(a.Group,{grow:!0,noWrap:!0,mt:20,children:s.jsx(b.Controller,{name:"legend.show",control:e,render:({field:i})=>s.jsx(a.Switch,{label:"Show Legend",sx:{flex:1},checked:i.value,onChange:o=>i.onChange(o.currentTarget.checked)})})}),s.jsx(a.Group,{children:s.jsx(b.Controller,{name:"legend",control:e,render:({field:i})=>s.jsx(a.Select,{label:"Orientation",data:Th,sx:{flex:1},value:i.value.orient,onChange:o=>{r(o,i.onChange)},disabled:!n.show})})})]})},Dn=g.forwardRef(({value:e,onChange:t},n)=>{const r=i=>o=>{t({...e,[i]:o})};return s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{variant:"dashed",label:"Scroll to Zoom",labelPosition:"center"}),s.jsxs(a.Group,{children:[s.jsx(a.Box,{sx:{flexGrow:1},children:s.jsx(a.Switch,{label:"Enable on X Axis",checked:e.x_axis_scroll,onChange:i=>r("x_axis_scroll")(i.currentTarget.checked)})}),s.jsx(a.Box,{sx:{flexGrow:1},children:s.jsx(a.Switch,{label:"Enable on Y Axis",checked:e.y_axis_scroll,onChange:i=>r("y_axis_scroll")(i.currentTarget.checked)})})]}),s.jsx(a.Divider,{variant:"dashed",label:"Slider for Zooming",labelPosition:"center"}),s.jsxs(a.Group,{children:[s.jsx(a.Box,{sx:{flexGrow:1},children:s.jsx(a.Switch,{label:"Slider for X Axis",checked:e.x_axis_slider,onChange:i=>r("x_axis_slider")(i.currentTarget.checked)})}),s.jsx(a.Tooltip,{label:"Not available for now, will overlap y-axis's label",children:s.jsx(a.Box,{sx:{flexGrow:1},children:s.jsx(a.Switch,{label:"Slider for Y Axis",disabled:!e.y_axis_slider,checked:e.y_axis_slider,onChange:i=>r("y_axis_slider")(i.currentTarget.checked)})})})]})]})});function Ih({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),{variables:r}=e,i=g.useMemo(()=>y.defaults({},t,Ms),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=b.useForm({defaultValues:i});g.useEffect(()=>{d(i)},[i]),u(["x_axis","y_axis","reference_lines","color","dataZoom"]);const h=c(),p=g.useMemo(()=>!y.isEqual(h,t),[h,t]);return s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:l(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Chart Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"X Axis",children:"X Axis"}),s.jsx(a.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),s.jsx(a.Tabs.Tab,{value:"Legend",children:"Legend"}),s.jsx(a.Tabs.Tab,{value:"Tooltip",children:"Tooltip"}),s.jsx(a.Tabs.Tab,{value:"Style",children:"Style"}),s.jsx(a.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"}),s.jsx(a.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),s.jsx(a.Tabs.Panel,{value:"X Axis",children:s.jsx(bh,{control:o,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Y Axis",children:s.jsx(Ch,{control:o,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Legend",children:s.jsx(Dh,{control:o,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(kh,{control:o,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Style",children:s.jsxs(a.Stack,{spacing:4,children:[s.jsx(a.Text,{size:"sm",children:"Color"}),s.jsx(b.Controller,{name:"color",control:o,render:({field:x})=>s.jsx(ke,{...x})})]})}),s.jsx(a.Tabs.Panel,{value:"Reference Lines",children:s.jsx(mh,{variables:r,control:o,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Zooming",children:s.jsx(b.Controller,{name:"dataZoom",control:o,render:({field:x})=>s.jsx(Dn,{...x})})})]})]})})}function Mh(e){return y.omit(e,"variables")}function zh(e){const{label_formatter:t=je,...n}=e.y_axis;return{...e,y_axis:{...n,label_formatter:t}}}function Ah(e){const t={rotate:0,formatter:{...Oe}},{axisLabel:n=t,...r}=e.x_axis;return{...e,x_axis:{...r,axisLabel:n}}}function Eh(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return y.defaultsDeep(t,e)}function Lh(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 y.defaultsDeep(r,e)}function Ph(e){const t={tooltip:{metrics:[]}};return y.defaultsDeep(t,e)}function Bh(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:i,y_axis:o,tooltip:l,...u}=e;return{...u,x_axis:{...i,data_key:r(i.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 Oh(e){const t={legend:{show:!0,top:"0",right:"10",left:"auto",bottom:"auto",orient:"horizontal",type:"scroll"}};return y.defaultsDeep(t,e)}function $h(e){const{dataZoom:t,...n}=e;return{...n,dataZoom:t??ja()}}class Vh extends ue{constructor(){super(...arguments);L(this,"VERSION",9)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,{panelModel:r})=>{const{config:i}=n;return(i.variables||[]).forEach(l=>{r.variables.find(u=>u.name===l.name)||r.addVariable(l)}),{...n,version:2,config:Mh(i)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:zh(r)}}),this.version(4,n=>{const{config:r}=n;return{...n,version:4,config:Ah(r)}}),this.version(5,n=>{const{config:r}=n;return{...n,version:5,config:Eh(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:Lh(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:Ph(r)}}),this.version(8,(n,r)=>{const{config:i}=n;return{...n,version:8,config:Bh(i,r)}}),this.version(9,n=>{const{config:r}=n;return{...n,version:9,config:Oh(r)}}),this.version(10,n=>{const{config:r}=n;return{...n,version:10,config:$h(r)}})}}const qh={displayName:"Boxplot Chart",displayGroup:"ECharts-based charts",migrator:new Vh,name:"boxplot",viewRender:xh,configRender:Ih,createConfig(){return{version:10,config:y.cloneDeep(Ms)}},triggers:[ba]},Ta={id:"builtin:button:click-button",displayName:"Click Button",nameRender:Fh,configRender:Nh,payload:[]};function Nh(e){return s.jsx(s.Fragment,{})}function Fh(e){return s.jsx(a.Text,{children:"Click this button"})}const Os={content:"Button",variant:"filled",color:"blue",size:"xs",compact:!1,horizontal_align:"left",vertical_align:"center"},Gh={left:"flex-start",center:"center",right:"flex-end"},Wh={top:"flex-start",center:"center",bottom:"flex-end"},Rh=S.observer(({context:e,instance:t})=>{const n=Ne({vizManager:e.vizManager,instance:t}),r=qe(n.triggerManager,Ta.id),i=pe(),{value:o}=$(e.instanceData,"config"),l=g.useMemo(()=>y.defaultsDeep({},o,Os),[o]),{content:u,horizontal_align:c,vertical_align:d,...h}=l,{width:p,height:x}=e.viewport,m=i.payloadForSQL,j=()=>{r.forEach(C=>{n.runInteraction(C.id,{})})};return s.jsx(a.Center,{sx:{width:p,height:x,justifyContent:Gh[c],alignItems:Wh[d]},children:s.jsx(a.Button,{...h,onClick:j,children:y.template(u)(m)})})}),Qh=({value:e,onChange:t,label:n})=>{const r=a.useMantineTheme(),i=g.useCallback(l=>()=>t(l),[t]),o=l=>e===l;return s.jsxs(a.Stack,{spacing:2,children:[s.jsx(a.Text,{size:14,sx:{fontWeight:500},children:n}),s.jsx(a.Group,{position:"left",spacing:"xs",children:Object.keys(r.colors).map(l=>{const u=r.colors[l][6];return s.jsx(a.ColorSwatch,{color:u,onClick:i(l),radius:4,size:26,sx:{cursor:"pointer"},children:o(l)&&s.jsx(a.CheckIcon,{width:10,color:"white"})},l)})})]})},Uh=a.MANTINE_SIZES.map(e=>({label:e.toUpperCase(),value:e})),Kh=({label:e,value:t,onChange:n})=>s.jsx(a.Select,{data:Uh,label:e,value:t,onChange:n}),Yh=[{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}],Xh=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Jh=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function Zh({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=g.useMemo(()=>y.defaultsDeep({},t,Os),[t]),i=r;g.useEffect(()=>{!y.isEqual(r,i)&&(console.log("config malformed, resetting to defaults",r,i),n(i))},[r,i]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=b.useForm({defaultValues:i});g.useEffect(()=>{d(i)},[i]);const h=c(),p=g.useMemo(()=>!y.isEqual(h,r),[h,r]);return u(["content","variant","color","size","compact","horizontal_align","vertical_align"]),s.jsxs("form",{onSubmit:l(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Chart Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Stack,{children:[s.jsx(b.Controller,{control:o,name:"content",render:({field:x})=>s.jsx(a.TextInput,{label:"Content Template",description:"Filter values & context entries are supported",...x,required:!0})}),s.jsx(a.Divider,{mt:"xs",mb:0,label:"Styles",labelPosition:"center",variant:"dashed"}),s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(b.Controller,{control:o,name:"variant",render:({field:x})=>s.jsx(a.Select,{label:"Variant",data:Yh,...x})}),s.jsx(b.Controller,{control:o,name:"color",render:({field:x})=>s.jsx(Qh,{label:"Theme",...x})})]}),s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(b.Controller,{control:o,name:"size",render:({field:x})=>s.jsx(Kh,{label:"Size",...x})}),s.jsx(b.Controller,{control:o,name:"compact",render:({field:x})=>s.jsx(a.Checkbox,{label:"Compact",checked:x.value,onChange:m=>x.onChange(m.currentTarget.checked),mt:26})})]}),s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(b.Controller,{control:o,name:"horizontal_align",render:({field:x})=>s.jsx(a.Select,{label:"Horizontal Alignment",data:Xh,...x})}),s.jsx(b.Controller,{control:o,name:"vertical_align",render:({field:x})=>s.jsx(a.Select,{label:"Vertical Alignment",data:Jh,...x})})]})]})]})}class Hh extends ue{constructor(){super(...arguments);L(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{horizontal_align:r="left",vertical_align:i="center",...o}=n.config;return{...n,version:2,config:{...o,horizontal_align:r,vertical_align:i}}})}}const ex={displayName:"Button",displayGroup:"Others",migrator:new Hh,name:"button",viewRender:Rh,configRender:Zh,createConfig(){return{version:2,config:y.cloneDeep(Os)}},triggers:[Ta]},$s={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:nx,configRender:tx,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 tx(e){return s.jsx(s.Fragment,{})}function nx(e){return s.jsx(a.Text,{children:"Click chart's series"})}const Vs={regressions:[],series:[],stats:{templates:{bottom:"",top:""}},x_axis:{type:"category",axisLabel:{rotate:0,formatter:{...Oe},overflow:Me()}},tooltip:{metrics:[]},x_axis_data_key:"",x_axis_name:"",y_axes:[{min:"",max:"",name:"Y Axis",show:!0,position:"left",nameAlignment:"center",label_formatter:je}],reference_lines:[],reference_areas:[],dataZoom:jt};function sx(e){const t=e.y_axes.some(i=>!!i.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(i=>!i.hide_in_legend)&&(r+=20),{top:n,right:15,bottom:r,left:20,containLabel:!0}}function rx(e){return e!=="line"?{}:{itemStyle:{opacity:0}}}function ix(e){switch(e){case"line":return;case"bar":return"roundRect";case"scatter":return"circle"}}function ax(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:ix(r),...rx(r)})),t}function In(e,t){switch(e.config.method){case"linear":return[...xt.regressionLinear()(t)];case"exponential":return[...xt.regressionExp()(t)];case"logarithmic":return[...xt.regressionLog()(t)];case"polynomial":return[...xt.regressionPoly().order(e.config.order)(t)];default:return[]}}function ox(e,t,n,r){const{transform:i,plot:o}=e,l={...o,name:t,data:In(i,r),showSymbol:!1,tooltip:{show:!1},smooth:!1,custom:{}};return n&&(l.custom={type:"regression-line",targetSeries:n}),l}function lx({regressions:e=[],x_axis_data_key:t},n){const r=[];if(Object.keys(n).length===0)return r;function i(o,l,u,c){const d=ox(o,l,u,c);r.push(d)}return e.forEach(o=>{const{name:l,group_by_key:u}=o;if(!u||u===t){const p=Ze(n,o.y_axis_data_key).map((x,m)=>[m,Number(x)]);i(o,l,"",p);return}const{columnKey:c}=z(o.y_axis_data_key),d=y.groupBy(Jt(n,o.y_axis_data_key),u);Object.entries(d).forEach(([h,p])=>{const x=p.map((j,C)=>[C,Number(j[c])]);i(o,h,h,x)})}),r}function ux(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 cx(e,t,n,r){return t?r==="value"?[[n[0],e]]:[e]:[]}function dx(e,t,n,r,i,o){return e.map(l=>{const u=n[l.variable_key],c=l.orientation==="horizontal",d=c?"yAxis":"xAxis",h=c?"insideEndTop":"end",p=cx(u,c,i,o);return{name:l.name,type:"scatter",hide_in_legend:!l.show_in_legend,xAxisId:"main-x-axis",yAxisIndex:l.yAxisIndex,data:p,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?jn(l.template,t,r):""},position:h}}}})}function px({type:e,...t},n,r,i){if(!e)return 10;if(e==="static"){const{size:d}=t;return d}const{func_content:o}=t,{queryID:l,columnKey:u}=z(r),c=y.keyBy(Jt(n,l),u);return(d,h)=>{let p;h.name?p=c[h.name]:p=n[h.dataIndex];try{return new Function(`return ${o}`)()({rowData:p,params:h,variables:i},{lodash:y,interpolate:bt.interpolate})}catch(x){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${x.message}`),10}}}function qs(e,t,n){const r=Ze(e,t),i=Ze(e,n);return y.zip(r,i)}function hx(e,t,n,r){const i=qs(t,n,r);return y.unionBy(i,e,0)}function xx({dataTemplate:e,data:t,x_axis_data_key:n,y_axis_data_key:r,valueTypedXAxis:i}){return i?hx(e,t,n,r):Ze(t,r)}function fx({dataTemplate:e,data:t,aggregation_on_value:n,x_axis_data_key:r,y_axis_data_key:i,valueTypedXAxis:o}){if(!n||n.type==="none")return xx({dataTemplate:e,data:t,x_axis_data_key:r,y_axis_data_key:i,valueTypedXAxis:o});const l=qs(t,r,i),u=y.groupBy(l,"0");return e.map(([d])=>{const p=u[d].map(m=>m[1]),x=ms(p,n);return[d,x]})}function gx({group_by_key:e,data:t,x_axis_data_key:n,y_axis_data_key:r}){const{queryID:i,columnKey:o}=z(e),l=y.groupBy(t[i],o);return Object.entries(l).forEach(([u,c])=>{l[u]=qs({[i]:c},n,r)}),l}function mx({x_axis_data_key:e,x_axis:t},{y_axis_data_key:n,yAxisIndex:r,label_position:i,name:o,group_by_key:l,aggregation_on_value:u,stack:c,color:d,display_name_on_line:h,symbolSize:p,hide_in_legend:x,...m},j,C,T,D){const A=t.type!=="category",F={label:{show:!!i,position:i,formatter:D[r??"default"]},name:o,xAxisId:"main-x-axis",yAxisIndex:r,stack:c,color:d,symbolSize:px(p,C,e,T),hide_in_legend:x,labelLayout:{hideOverlap:!0},...m};if(m.type==="line"&&(F.lineStyle={shadowColor:"rgba(255,255,255,1)",shadowBlur:0,shadowOffsetX:0,shadowOffsetY:3}),h&&(F.endLabel={show:!0,formatter:o,offset:[-12,12],align:"right"}),!l||l===e)return F.data=fx({dataTemplate:j,data:C,aggregation_on_value:u,x_axis_data_key:e,y_axis_data_key:n,valueTypedXAxis:A}),F;const X=gx({group_by_key:l,data:C,x_axis_data_key:e,y_axis_data_key:n});return Object.entries(X).map(([Q,G])=>{const ee=y.cloneDeep(F);return ee.name=Q,ee.color=void 0,ee.data=G,ee})}function yx(e,t,n,r,i,o){const l=t.map(c=>[c,0]);return e.series.map(c=>mx(e,c,l,n,o,r)).flat().concat(dx(e.reference_lines,i,o,n,t,e.x_axis.type)).concat(ux(e.reference_areas,o))}function bx(e,t){const n=e.find(o=>o.axisDim==="x"&&o.axisId==="main-x-axis");if(!n)return"";const{axisValue:r,axisIndex:i}=n;return Pt(t.x_axis.axisLabel.formatter)(r,i)}const jx=e=>W(e,{output:"number",trimMantissa:!0,mantissa:2,absolute:!1});function vx(e,t,n,r){const i=n.reduce((o,{yAxisIndex:l,name:u})=>(o[u]=l,o),{});return ne.getTooltip({trigger:"axis",formatter:function(o){const l=Array.isArray(o)?o:[o];if(l.length===0)return"";const u=l.map(({seriesName:p,marker:x,value:m})=>{if(Array.isArray(m)&&m.length===2&&(m=m[1]),!p)return m;const j=i[p],C=r[j]??r.default;return`
108
+ `}const dh=e=>t=>{const{seriesName:n,value:r}=t;switch(n){case"Box":return oh(e,r);case"Outlier":return ch(e,r);case"Scatter":return uh(e,r)}};function ph({config:e}){return ee.getTooltip({trigger:"item",formatter:dh(e)})}function _n(e,t){t||(t="none");const n=[];return e.x_axis_scroll&&n.push({type:"inside",xAxisIndex:[0],filterMode:t,minSpan:1}),e.y_axis_scroll&&n.push({type:"inside",yAxisIndex:[0],filterMode:t,minSpan:1}),e.x_axis_slider&&n.push({type:"slider",xAxisIndex:[0],filterMode:t,bottom:"auto",top:0,height:15,moveHandleSize:0,showDataShadow:!1,minSpan:1}),n}function hh({min:e,max:t}){if(e<=110)return Math.min(0,e);if(e<=200)return 100;const n=It.floor(It.log10(e)),r=Math.pow(10,n),i=Math.pow(10,n-1);return e/r<=2?y.round(e,-1*(n-1))-i:y.round(e,-1*n)-r}function xh({config:e,data:t,variables:n}){const{x_axis:r,y_axis:i,reference_lines:o}=e,l=Xp(e,t),c=Be(r.axisLabel.overflow.on_axis),u=ah(e,l);return{dataZoom:_n(e.dataZoom,"filter"),grid:Jp(e),dataset:l,legend:Zp({config:e}),tooltip:ph({config:e}),xAxis:[ee.getXAxis({type:"category",name:r.name,nameGap:25,nameLocation:"center",nameTextStyle:{align:"center"},axisLabel:{...r.axisLabel,...c,formatter:Pt(r.axisLabel.formatter)}})],yAxis:[ee.getYAxis({name:i.name,minInterval:1,axisLabel:{formatter:function(d){return G(d,i.label_formatter)}},min:hh})],series:[...u,...Hp(o,n,t)]}}function fh({context:e,instance:t}){const{value:n}=O(e.instanceData,"config"),{variables:r}=e,i=e.data,{width:o,height:l}=e.viewport,c=y.defaults({},n,Is),u=$e({vizManager:e.vizManager,instance:t}),d=Oe(u.triggerManager,ja.id),h=jt(i,c.x_axis.data_key),p=g.useCallback(j=>{const C=y.get(h,j.name,{error:"rowData is not found"});d.forEach(T=>{u.runInteraction(T.id,{...j,rowData:C})})},[h,d,u]),x=g.useMemo(()=>({click:p}),[p]),m=g.useMemo(()=>xh({config:c,data:i,variables:r}),[c,i,r]);return!n||!o||!l?null:s.jsx(ke,{width:o,height:l,children:s.jsx(we,{echarts:be,option:m,style:Zt(o,l),onEvents:x,notMerge:!0,theme:"merico-light"})})}function gh({value:e,onChange:t},n){const{colorManager:r}=g.useContext(Ze),i=g.useMemo(()=>r.getStaticColors().map(c=>({label:c.name,group:c.category,value:c.value})),[r]),o=g.useMemo(()=>i.some(l=>l.value===e),[e,i]);return s.jsxs(a.Group,{position:"apart",spacing:4,ref:n,children:[s.jsx(a.TextInput,{placeholder:"Set any color",value:o?"":e,onChange:l=>t(l.currentTarget.value),rightSection:s.jsx(a.ColorSwatch,{color:o?"transparent":e,radius:4}),variant:o?"filled":"default",sx:{maxWidth:"46%",flexGrow:1}}),s.jsx(a.Text,{sx:{flexGrow:0},children:"or"}),s.jsx(a.Select,{data:i,value:e,onChange:t,variant:o?"default":"filled",placeholder:"Pick a theme color",icon:s.jsx(a.ColorSwatch,{color:o?e:"transparent",radius:4}),sx:{maxWidth:"46%",flexGrow:1}})]})}const Ce=g.forwardRef(gh);function mh({control:e,index:t,remove:n,variableOptions:r}){return s.jsxs(a.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:i})=>s.jsx(a.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...i})}),s.jsx(b.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:i})=>s.jsx(a.Select,{label:"Value",required:!0,data:r,sx:{flex:1},...i})})]}),s.jsx(b.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:i})=>s.jsx(a.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",required:!0,sx:{flex:1},...i})}),s.jsx(a.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(t),sx:{position:"absolute",top:15,right:5},children:s.jsx(k.Trash,{size:16})})]})}function yh({control:e,watch:t,variables:n}){const{fields:r,append:i,remove:o}=b.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),c=r.map((h,p)=>({...h,...l[p]})),u=()=>i({name:"",template:"",variable_key:""}),d=g.useMemo(()=>n.map(h=>({label:h.name,value:h.name})),[n]);return s.jsxs(a.Stack,{children:[c.map((h,p)=>s.jsx(mh,{control:e,index:p,remove:o,variableOptions:d},h.id)),s.jsx(a.Group,{position:"center",mt:"xs",children:s.jsx(a.Button,{onClick:u,children:"Add a Reference Line"})})]})}const bh=({disabled:e,value:t,onChange:n})=>{const r=i=>{i&&n(i)};return s.jsxs(a.Box,{sx:{position:"relative"},children:[e&&s.jsx(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),s.jsx(fe,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},kn=g.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:i,setFalse:o}]=$.useBoolean(),[l,c]=g.useState(e);g.useEffect(()=>{c(e)},[e]);const u=m=>{c({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:j}=l,C={enabled:m,func_content:j};c(C),t(C)},h=()=>{o(),c(e)},p=m=>{c(j=>({...j,func_content:m}))},x=()=>{p(Pe.func_content)};return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"filled",mt:24,onClick:i,sx:{flexGrow:0},children:"Customize Label"}),s.jsx(a.Modal,{size:800,title:"Customize label content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&s.jsxs(a.Stack,{children:[s.jsx(a.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:m=>u(m.currentTarget.checked)}),s.jsx(bh,{value:l.func_content,onChange:p,disabled:!l.enabled}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:x,color:"red",leftIcon:s.jsx(k.Recycle,{size:20}),children:"Reset"}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:h,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:d,children:"OK"})]})]})]})})]})}),jh=({control:e,watch:t})=>(t(["x_axis"]),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"X Axis Name",sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>s.jsx(B,{label:"X Axis Data Field",required:!0,sx:{flex:1},...n})})]}),s.jsx(a.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>s.jsx(a.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:s.jsx(a.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),s.jsx(b.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>s.jsx(kn,{...n})})]}),s.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>s.jsx(Re,{...n})})]})),Ls={root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}},vh=["123456789","1234","1234.56789","1.234","0.123456789","-0.123456789"];function wh({format:e}){const[t,{toggle:n}]=re.useDisclosure(!1);return s.jsxs(a.Box,{children:[s.jsx(a.Button,{variant:"subtle",w:"100%",compact:!0,onClick:n,leftIcon:t?s.jsx(_.IconChevronUp,{size:14}):s.jsx(_.IconChevronDown,{size:14}),children:t?"Close preview":"Open preview"}),s.jsx(a.Collapse,{in:t,children:t&&s.jsxs(a.Table,{highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"In"}),s.jsx("th",{children:"Out"})]})}),s.jsx("tbody",{children:vh.map(r=>s.jsxs("tr",{children:[s.jsx("td",{children:r}),s.jsx("td",{children:s.jsx(je,{children:G(r,e)})})]},r))})]})})]})}function Ch({value:e,onChange:t},n){const r=u=>{t({...e,output:u})},i=u=>{const d=u===0?!1:e.trimMantissa;t({...e,mantissa:u,trimMantissa:d})},o=u=>{t({...e,trimMantissa:u.currentTarget.checked})},l=u=>{t({...e,average:u.currentTarget.checked})},c=u=>{const d={...e,absolute:u.currentTarget.checked};t(d)};return console.log({value:e}),s.jsxs(a.Stack,{ref:n,children:[s.jsxs(a.Group,{grow:!0,children:[s.jsx(a.Select,{label:"Format",data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:e.output,onChange:r,sx:{flexGrow:1}}),s.jsx(a.Switch,{label:s.jsxs(a.Stack,{spacing:0,children:[s.jsx(a.Text,{children:"Absolute"}),s.jsx(a.Text,{size:12,color:"gray",children:"Non-negative"})]}),checked:e.absolute,onChange:c,sx:{flexGrow:1},styles:Ls}),s.jsx(a.Switch,{label:s.jsxs(a.Stack,{spacing:0,children:[s.jsx(a.Text,{children:"Average"}),s.jsx(a.Text,{size:12,color:"gray",children:"like 1.234k, 1.234m"})]}),checked:e.average,onChange:l,disabled:e.output!=="number",sx:{flexGrow:1},styles:Ls})]}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(a.NumberInput,{label:"Mantissa",defaultValue:0,min:0,step:1,max:4,value:e.mantissa,onChange:i}),s.jsx(a.Switch,{label:s.jsxs(a.Stack,{spacing:0,children:[s.jsx(a.Text,{children:"Trim mantissa"}),s.jsx(a.Text,{size:12,color:"gray",children:"hide trailing zero(s)"})]}),checked:e.trimMantissa,onChange:o,disabled:e.mantissa===0,styles:Ls}),s.jsx(a.Box,{})]}),s.jsx(wh,{format:e})]})}const Ve=g.forwardRef(Ch),Sh=({control:e,watch:t})=>(t(["y_axis"]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"y_axis.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"Y Axis Name",sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"y_axis.data_key",control:e,render:({field:n})=>s.jsx(B,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})})]}),s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),s.jsx(b.Controller,{name:"y_axis.label_formatter",control:e,render:({field:n})=>s.jsx(Ve,{...n})})]})]})),_h=({control:e,index:t,remove:n})=>s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>s.jsx(B,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed"}),s.jsx(a.Button,{leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),kh=({control:e,watch:t})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((p,x)=>({...p,...o[x]})),c=()=>r({id:Date.now().toString(),data_key:"",name:""}),u=t("tooltip.metrics.0.id"),[d,h]=g.useState(()=>u??null);return g.useEffect(()=>{u&&h(p=>p!==null?p:u)},[u]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(k.InfoCircle,{size:14,color:"#888"}),s.jsx(a.Text,{size:14,color:"#888",children:"Set additional metrics to show in scatter's tooltip"})]}),s.jsxs(a.Tabs,{value:d,onTabChange:p=>h(p),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((p,x)=>s.jsx(a.Tabs.Tab,{value:p.id,children:p.name?p.name:x},p.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),l.map((p,x)=>s.jsx(a.Tabs.Panel,{value:p.id,children:s.jsx(_h,{control:e,index:x,remove:i},p.id)},p.id))]})]})};function Th({control:e,watch:t}){return s.jsx(a.Stack,{children:s.jsx(kh,{control:e,watch:t})})}const Dh=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}],Ih=({control:e,watch:t})=>{const n=t("legend"),r=(i,o)=>{const l={...n,orient:i};i==="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 s.jsxs(a.Stack,{children:[s.jsx(a.Group,{grow:!0,noWrap:!0,mt:20,children:s.jsx(b.Controller,{name:"legend.show",control:e,render:({field:i})=>s.jsx(a.Switch,{label:"Show Legend",sx:{flex:1},checked:i.value,onChange:o=>i.onChange(o.currentTarget.checked)})})}),s.jsx(a.Group,{children:s.jsx(b.Controller,{name:"legend",control:e,render:({field:i})=>s.jsx(a.Select,{label:"Orientation",data:Dh,sx:{flex:1},value:i.value.orient,onChange:o=>{r(o,i.onChange)},disabled:!n.show})})})]})},Tn=g.forwardRef(({value:e,onChange:t},n)=>{const r=i=>o=>{t({...e,[i]:o})};return s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{variant:"dashed",label:"Scroll to Zoom",labelPosition:"center"}),s.jsxs(a.Group,{children:[s.jsx(a.Box,{sx:{flexGrow:1},children:s.jsx(a.Switch,{label:"Enable on X Axis",checked:e.x_axis_scroll,onChange:i=>r("x_axis_scroll")(i.currentTarget.checked)})}),s.jsx(a.Box,{sx:{flexGrow:1},children:s.jsx(a.Switch,{label:"Enable on Y Axis",checked:e.y_axis_scroll,onChange:i=>r("y_axis_scroll")(i.currentTarget.checked)})})]}),s.jsx(a.Divider,{variant:"dashed",label:"Slider for Zooming",labelPosition:"center"}),s.jsxs(a.Group,{children:[s.jsx(a.Box,{sx:{flexGrow:1},children:s.jsx(a.Switch,{label:"Slider for X Axis",checked:e.x_axis_slider,onChange:i=>r("x_axis_slider")(i.currentTarget.checked)})}),s.jsx(a.Tooltip,{label:"Not available for now, will overlap y-axis's label",children:s.jsx(a.Box,{sx:{flexGrow:1},children:s.jsx(a.Switch,{label:"Slider for Y Axis",disabled:!e.y_axis_slider,checked:e.y_axis_slider,onChange:i=>r("y_axis_slider")(i.currentTarget.checked)})})})]})]})});function Mh({context:e}){const{value:t,set:n}=O(e.instanceData,"config"),{variables:r}=e,i=g.useMemo(()=>y.defaults({},t,Is),[t]),{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=b.useForm({defaultValues:i});g.useEffect(()=>{d(i)},[i]),c(["x_axis","y_axis","reference_lines","color","dataZoom"]);const h=u(),p=g.useMemo(()=>!y.isEqual(h,t),[h,t]);return s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:l(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Chart Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"X Axis",children:"X Axis"}),s.jsx(a.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),s.jsx(a.Tabs.Tab,{value:"Legend",children:"Legend"}),s.jsx(a.Tabs.Tab,{value:"Tooltip",children:"Tooltip"}),s.jsx(a.Tabs.Tab,{value:"Style",children:"Style"}),s.jsx(a.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"}),s.jsx(a.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),s.jsx(a.Tabs.Panel,{value:"X Axis",children:s.jsx(jh,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Y Axis",children:s.jsx(Sh,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Legend",children:s.jsx(Ih,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(Th,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Style",children:s.jsxs(a.Stack,{spacing:4,children:[s.jsx(a.Text,{size:"sm",children:"Color"}),s.jsx(b.Controller,{name:"color",control:o,render:({field:x})=>s.jsx(Ce,{...x})})]})}),s.jsx(a.Tabs.Panel,{value:"Reference Lines",children:s.jsx(yh,{variables:r,control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Zooming",children:s.jsx(b.Controller,{name:"dataZoom",control:o,render:({field:x})=>s.jsx(Tn,{...x})})})]})]})})}function zh(e){return y.omit(e,"variables")}function Ah(e){const{label_formatter:t=me,...n}=e.y_axis;return{...e,y_axis:{...n,label_formatter:t}}}function Eh(e){const t={rotate:0,formatter:{...Pe}},{axisLabel:n=t,...r}=e.x_axis;return{...e,x_axis:{...r,axisLabel:n}}}function Ph(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return y.defaultsDeep(t,e)}function Lh(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 y.defaultsDeep(r,e)}function Bh(e){const t={tooltip:{metrics:[]}};return y.defaultsDeep(t,e)}function Oh(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis:i,y_axis:o,tooltip:l,...c}=e;return{...c,x_axis:{...i,data_key:r(i.data_key)},y_axis:{...o,data_key:r(o.data_key)},tooltip:{...l,metrics:l.metrics.map(u=>({...u,data_key:r(u.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}function $h(e){const t={legend:{show:!0,top:"0",right:"10",left:"auto",bottom:"auto",orient:"horizontal",type:"scroll"}};return y.defaultsDeep(t,e)}function Vh(e){const{dataZoom:t,...n}=e;return{...n,dataZoom:t??va()}}class qh extends ae{constructor(){super(...arguments);P(this,"VERSION",9)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,{panelModel:r})=>{const{config:i}=n;return(i.variables||[]).forEach(l=>{r.variables.find(c=>c.name===l.name)||r.addVariable(l)}),{...n,version:2,config:zh(i)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:Ah(r)}}),this.version(4,n=>{const{config:r}=n;return{...n,version:4,config:Eh(r)}}),this.version(5,n=>{const{config:r}=n;return{...n,version:5,config:Ph(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:Lh(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:Bh(r)}}),this.version(8,(n,r)=>{const{config:i}=n;return{...n,version:8,config:Oh(i,r)}}),this.version(9,n=>{const{config:r}=n;return{...n,version:9,config:$h(r)}}),this.version(10,n=>{const{config:r}=n;return{...n,version:10,config:Vh(r)}})}}const Nh={displayName:"Boxplot Chart",displayGroup:"ECharts-based charts",migrator:new qh,name:"boxplot",viewRender:fh,configRender:Mh,createConfig(){return{version:10,config:y.cloneDeep(Is)}},triggers:[ja]},Da={id:"builtin:button:click-button",displayName:"Click Button",nameRender:Gh,configRender:Fh,payload:[]};function Fh(e){return s.jsx(s.Fragment,{})}function Gh(e){return s.jsx(a.Text,{children:"Click this button"})}const Bs={content:"Button",variant:"filled",color:"blue",size:"xs",compact:!1,horizontal_align:"left",vertical_align:"center"},Wh={left:"flex-start",center:"center",right:"flex-end"},Rh={top:"flex-start",center:"center",bottom:"flex-end"},Qh=S.observer(({context:e,instance:t})=>{const n=$e({vizManager:e.vizManager,instance:t}),r=Oe(n.triggerManager,Da.id),i=ce(),{value:o}=O(e.instanceData,"config"),l=g.useMemo(()=>y.defaultsDeep({},o,Bs),[o]),{content:c,horizontal_align:u,vertical_align:d,...h}=l,{width:p,height:x}=e.viewport,m=i.payloadForSQL,j=()=>{r.forEach(C=>{n.runInteraction(C.id,{})})};return s.jsx(a.Center,{sx:{width:p,height:x,justifyContent:Wh[u],alignItems:Rh[d]},children:s.jsx(a.Button,{...h,onClick:j,children:y.template(c)(m)})})}),Uh=({value:e,onChange:t,label:n})=>{const r=a.useMantineTheme(),i=g.useCallback(l=>()=>t(l),[t]),o=l=>e===l;return s.jsxs(a.Stack,{spacing:2,children:[s.jsx(a.Text,{size:14,sx:{fontWeight:500},children:n}),s.jsx(a.Group,{position:"left",spacing:"xs",children:Object.keys(r.colors).map(l=>{const c=r.colors[l][6];return s.jsx(a.ColorSwatch,{color:c,onClick:i(l),radius:4,size:26,sx:{cursor:"pointer"},children:o(l)&&s.jsx(a.CheckIcon,{width:10,color:"white"})},l)})})]})},Kh=a.MANTINE_SIZES.map(e=>({label:e.toUpperCase(),value:e})),Yh=({label:e,value:t,onChange:n})=>s.jsx(a.Select,{data:Kh,label:e,value:t,onChange:n}),Xh=[{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}],Jh=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Zh=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function Hh({context:e}){const{value:t,set:n}=O(e.instanceData,"config"),r=g.useMemo(()=>y.defaultsDeep({},t,Bs),[t]),i=r;g.useEffect(()=>{!y.isEqual(r,i)&&(console.log("config malformed, resetting to defaults",r,i),n(i))},[r,i]);const{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=b.useForm({defaultValues:i});g.useEffect(()=>{d(i)},[i]);const h=u(),p=g.useMemo(()=>!y.isEqual(h,r),[h,r]);return c(["content","variant","color","size","compact","horizontal_align","vertical_align"]),s.jsxs("form",{onSubmit:l(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Chart Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Stack,{children:[s.jsx(b.Controller,{control:o,name:"content",render:({field:x})=>s.jsx(a.TextInput,{label:"Content Template",description:"Filter values & context entries are supported",...x,required:!0})}),s.jsx(a.Divider,{mt:"xs",mb:0,label:"Styles",labelPosition:"center",variant:"dashed"}),s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(b.Controller,{control:o,name:"variant",render:({field:x})=>s.jsx(a.Select,{label:"Variant",data:Xh,...x})}),s.jsx(b.Controller,{control:o,name:"color",render:({field:x})=>s.jsx(Uh,{label:"Theme",...x})})]}),s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(b.Controller,{control:o,name:"size",render:({field:x})=>s.jsx(Yh,{label:"Size",...x})}),s.jsx(b.Controller,{control:o,name:"compact",render:({field:x})=>s.jsx(a.Checkbox,{label:"Compact",checked:x.value,onChange:m=>x.onChange(m.currentTarget.checked),mt:26})})]}),s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(b.Controller,{control:o,name:"horizontal_align",render:({field:x})=>s.jsx(a.Select,{label:"Horizontal Alignment",data:Jh,...x})}),s.jsx(b.Controller,{control:o,name:"vertical_align",render:({field:x})=>s.jsx(a.Select,{label:"Vertical Alignment",data:Zh,...x})})]})]})]})}class ex extends ae{constructor(){super(...arguments);P(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{horizontal_align:r="left",vertical_align:i="center",...o}=n.config;return{...n,version:2,config:{...o,horizontal_align:r,vertical_align:i}}})}}const tx={displayName:"Button",displayGroup:"Others",migrator:new ex,name:"button",viewRender:Qh,configRender:Hh,createConfig(){return{version:2,config:y.cloneDeep(Bs)}},triggers:[Da]},Os={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:sx,configRender:nx,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 nx(e){return s.jsx(s.Fragment,{})}function sx(e){return s.jsx(a.Text,{children:"Click chart's series"})}const $s={regressions:[],series:[],stats:{templates:{bottom:"",top:""}},x_axis:{type:"category",axisLabel:{rotate:0,formatter:{...Pe},overflow:Te()}},tooltip:{metrics:[]},x_axis_data_key:"",x_axis_name:"",y_axes:[{min:"",max:"",name:"Y Axis",show:!0,position:"left",nameAlignment:"center",label_formatter:me}],reference_lines:[],reference_areas:[],dataZoom:bt};function rx(e){const t=e.y_axes.some(i=>!!i.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(i=>!i.hide_in_legend)&&(r+=20),{top:n,right:15,bottom:r,left:20,containLabel:!0}}function ix(e){return e!=="line"?{}:{itemStyle:{opacity:0}}}function ax(e){switch(e){case"line":return;case"bar":return"roundRect";case"scatter":return"circle"}}function ox(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:ax(r),...ix(r)})),t}function Dn(e,t){switch(e.config.method){case"linear":return[...ht.regressionLinear()(t)];case"exponential":return[...ht.regressionExp()(t)];case"logarithmic":return[...ht.regressionLog()(t)];case"polynomial":return[...ht.regressionPoly().order(e.config.order)(t)];default:return[]}}function lx(e,t,n,r){const{transform:i,plot:o}=e,l={...o,name:t,data:Dn(i,r),showSymbol:!1,tooltip:{show:!1},smooth:!1,custom:{}};return n&&(l.custom={type:"regression-line",targetSeries:n}),l}function cx({regressions:e=[],x_axis_data_key:t},n){const r=[];if(Object.keys(n).length===0)return r;function i(o,l,c,u){const d=lx(o,l,c,u);r.push(d)}return e.forEach(o=>{const{name:l,group_by_key:c}=o;if(!c||c===t){const p=Ye(n,o.y_axis_data_key).map((x,m)=>[m,Number(x)]);i(o,l,"",p);return}const{columnKey:u}=z(o.y_axis_data_key),d=y.groupBy(Xt(n,o.y_axis_data_key),c);Object.entries(d).forEach(([h,p])=>{const x=p.map((j,C)=>[C,Number(j[u])]);i(o,h,h,x)})}),r}function ux(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 dx(e,t,n,r){return t?r==="value"?[[n[0],e]]:[e]:[]}function px(e,t,n,r,i,o){return e.map(l=>{const c=n[l.variable_key],u=l.orientation==="horizontal",d=u?"yAxis":"xAxis",h=u?"insideEndTop":"end",p=dx(c,u,i,o);return{name:l.name,type:"scatter",hide_in_legend:!l.show_in_legend,xAxisId:"main-x-axis",yAxisIndex:l.yAxisIndex,data:p,symbol:"none",silent:!0,tooltip:{show:!1},markLine:{data:[{name:l.name,[d]:c}],silent:!0,symbol:["none","none"],lineStyle:l.lineStyle,label:{formatter:function(){return l.template?bn(l.template,t,r):""},position:h}}}})}function hx({type:e,...t},n,r,i){if(!e)return 10;if(e==="static"){const{size:d}=t;return d}const{func_content:o}=t,{queryID:l,columnKey:c}=z(r),u=y.keyBy(Xt(n,l),c);return(d,h)=>{let p;h.name?p=u[h.name]:p=n[h.dataIndex];try{return new Function(`return ${o}`)()({rowData:p,params:h,variables:i},{lodash:y,interpolate:yt.interpolate})}catch(x){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${x.message}`),10}}}function Vs(e,t,n){const r=Ye(e,t),i=Ye(e,n);return y.zip(r,i)}function xx(e,t,n,r){const i=Vs(t,n,r);return y.unionBy(i,e,0)}function fx({dataTemplate:e,data:t,x_axis_data_key:n,y_axis_data_key:r,valueTypedXAxis:i}){return i?xx(e,t,n,r):Ye(t,r)}function gx({dataTemplate:e,data:t,aggregation_on_value:n,x_axis_data_key:r,y_axis_data_key:i,valueTypedXAxis:o}){if(!n||n.type==="none")return fx({dataTemplate:e,data:t,x_axis_data_key:r,y_axis_data_key:i,valueTypedXAxis:o});const l=Vs(t,r,i),c=y.groupBy(l,"0");return e.map(([d])=>{const p=c[d].map(m=>m[1]),x=gs(p,n);return[d,x]})}function mx({group_by_key:e,data:t,x_axis_data_key:n,y_axis_data_key:r}){const{queryID:i,columnKey:o}=z(e),l=y.groupBy(t[i],o);return Object.entries(l).forEach(([c,u])=>{l[c]=Vs({[i]:u},n,r)}),l}function yx({x_axis_data_key:e,x_axis:t},{y_axis_data_key:n,yAxisIndex:r,label_position:i,name:o,group_by_key:l,aggregation_on_value:c,stack:u,color:d,display_name_on_line:h,symbolSize:p,hide_in_legend:x,...m},j,C,T,D){const A=t.type!=="category",N={label:{show:!!i,position:i,formatter:D[r??"default"]},name:o,xAxisId:"main-x-axis",yAxisIndex:r,stack:u,color:d,symbolSize:hx(p,C,e,T),hide_in_legend:x,labelLayout:{hideOverlap:!0},...m};if(m.type==="line"&&(N.lineStyle={shadowColor:"rgba(255,255,255,1)",shadowBlur:0,shadowOffsetX:0,shadowOffsetY:3}),h&&(N.endLabel={show:!0,formatter:o,offset:[-12,12],align:"right"}),!l||l===e)return N.data=gx({dataTemplate:j,data:C,aggregation_on_value:c,x_axis_data_key:e,y_axis_data_key:n,valueTypedXAxis:A}),N;const Y=mx({group_by_key:l,data:C,x_axis_data_key:e,y_axis_data_key:n});return Object.entries(Y).map(([R,F])=>{const Z=y.cloneDeep(N);return Z.name=R,Z.color=void 0,Z.data=F,Z})}function bx(e,t,n,r,i,o){const l=t.map(u=>[u,0]);return e.series.map(u=>yx(e,u,l,n,o,r)).flat().concat(px(e.reference_lines,i,o,n,t,e.x_axis.type)).concat(ux(e.reference_areas,o))}function jx(e,t){const n=e.find(o=>o.axisDim==="x"&&o.axisId==="main-x-axis");if(!n)return"";const{axisValue:r,axisIndex:i}=n;return Pt(t.x_axis.axisLabel.formatter)(r,i)}const vx=e=>G(e,{output:"number",trimMantissa:!0,mantissa:2,absolute:!1});function wx(e,t,n,r){const i=n.reduce((o,{yAxisIndex:l,name:c})=>(o[c]=l,o),{});return ee.getTooltip({trigger:"axis",formatter:function(o){const l=Array.isArray(o)?o:[o];if(l.length===0)return"";const c=l.map(({seriesName:p,marker:x,value:m})=>{if(Array.isArray(m)&&m.length===2&&(m=m[1]),!p)return m;const j=i[p],C=r[j]??r.default;return`
109
109
  <tr>
110
110
  <td>${x}</td>
111
111
  <th style="text-align: right; padding: 0 1em;">${p}</th>
112
112
  <td style="text-align: left; padding: 0 1em;">${C({value:m})}</td>
113
113
  </tr>
114
- `}),c=e.tooltip.metrics.map(p=>{const x=Ze(t,p.data_key),m=y.uniq(l.map(({dataIndex:j})=>x[j]));return`<tr>
114
+ `}),u=e.tooltip.metrics.map(p=>{const x=Ye(t,p.data_key),m=y.uniq(l.map(({dataIndex:j})=>x[j]));return`<tr>
115
115
  <td />
116
116
  <th style="text-align: right; padding: 0 1em;">${p.name}</th>
117
- ${m.map(j=>`<td style="text-align: left; padding: 0 1em;">${jx(j)}</td>`)}
118
- </tr>`});u.push(...c);const d=$e(e.x_axis.axisLabel.overflow.in_tooltip),h=bx(l,e);return`
117
+ ${m.map(j=>`<td style="text-align: left; padding: 0 1em;">${vx(j)}</td>`)}
118
+ </tr>`});c.push(...u);const d=Le(e.x_axis.axisLabel.overflow.in_tooltip),h=jx(l,e);return`
119
119
  <div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
120
120
  <div style="${d}">${h}</div>
121
121
  </div>
122
122
  <table style="width: auto">
123
123
  <tbody>
124
- ${u.join("")}
124
+ ${c.join("")}
125
125
  </tbody>
126
126
  </table>
127
- `}})}function wx(e){return e.y_axes.reduce((n,{label_formatter:r},i)=>(n[i]=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 W(u,r)}catch(c){return console.error(c),u}},n),{default:({value:n})=>n})}function Da(e,t){const n={};return t.map(r=>{const i=it(r,e);n[r.name]=Pe(r,i)}),n}function Cx(e,t){const{overflow:n,...r}=e.x_axis.axisLabel,i=Ve(n.on_axis),o=t.length===0;return[ne.getXAxis({data:t,name:e.x_axis_name??"",nameGap:o?5:void 0,id:"main-x-axis",type:e.x_axis.type,axisLabel:{...r,...i,formatter:Pt(r.formatter)}})]}function Sx(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 _x(e){if(e.length===0)return{};const t={},n={};return e.forEach(r=>{const i=Sx(r.data);if(!n[r.yAxisIndex]){n[r.yAxisIndex]=i;return}n[r.yAxisIndex]=n[r.yAxisIndex].concat(i)}),Object.entries(n).forEach(([r,i])=>{const o=y.minBy(i)??0,l=y.maxBy(i)??0;o==0&&l==0&&(t[r]=1)}),t}function kx(e,t,n){const r=_x(n);return e.y_axes.map(({nameAlignment:i,min:o,max:l,show:u,...c},d)=>{let h=c.position;return h||(h=d>0?"right":"left"),ne.getYAxis({...c,minInterval:r[d]??0,show:u,min:o||void 0,max:l||void 0,position:h,axisLabel:{show:u,formatter:t[d]??t.default},nameTextStyle:{align:i},nameLocation:"end",nameGap:u?15:0,splitLine:{show:d===0}})})}const Tx={xAxis:[{type:"category",nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0}}]};function Dx(e,t,n){const r=Da(t,n),i=wx(e),o=y.uniq(Ze(t,e.x_axis_data_key)),l=yx(e,o,t,i,n,r),u=lx(e,t),c={xAxis:Cx(e,o),yAxis:kx(e,i,l),series:[...l,...u],tooltip:vx(e,t,l,i),grid:sx(e),legend:ax(l),dataZoom:kn(e.dataZoom)};return y.defaultsDeep({},c,Tx)}function Ia(e){const t=e.getModel(),n=t.getSeries().map(r=>{if(!r.option.custom)return r.option;const i=t.getColorFromPalette(r.option.custom.targetSeries,null);return r.option.color=i,r.option});e.setOption({...e.getOption(),series:n})}J.use([B.DataZoomComponent,ie.BarChart,ie.LineChart,ie.ScatterChart,B.GridComponent,B.LegendComponent,B.TooltipComponent,_e.CanvasRenderer,B.MarkLineComponent,B.MarkAreaComponent]);function Ma(e){return e.trim().length>0}function Ix({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const l=vt(t,e.x_axis_data_key),u=qe(i.triggerManager,$s.id),c=g.useCallback(m=>{const j=y.get(l,m.name,{error:"rowData is not found"});u.forEach(C=>{i.runInteraction(C.id,{...m,rowData:j})})},[l,u,i]),d=g.useMemo(()=>Dx(e,t,o),[e,t]),h=g.useRef(),p=g.useMemo(()=>({click:c}),[c]),x=m=>{h.current=m,Ia(m)};return g.useEffect(()=>{h.current&&Ia(h.current)},[d]),!n||!r?null:s.jsx(Se,{echarts:J,option:d,style:{width:n,height:r},onEvents:p,onChartReady:x,notMerge:!0,theme:"merico-light"})}function Mx({context:e,instance:t}){const n=Ne({vizManager:e.vizManager,instance:t}),{value:r}=$(e.instanceData,"config"),{variables:i}=e,o=g.useMemo(()=>y.defaults({},r,Vs),[r]),l=e.data,{width:u,height:c}=e.viewport,{ref:d,height:h}=oe.useElementSize(),{ref:p,height:x}=oe.useElementSize(),m=g.useMemo(()=>{const{stats:{templates:T}}=o;return{top:Zt(T.top,i,l),bottom:Zt(T.bottom,i,l)}},[o,l]),j=Math.max(0,Ue(c)-h-x),C=Qe(u);return s.jsxs(Ie,{width:u,height:c,children:[s.jsx(a.Text,{ref:d,align:"left",size:"xs",pl:"sm",sx:{display:Ma(o.stats.templates.top)?"block":"none"},children:Object.values(m.top).map((T,D)=>s.jsx(g.Fragment,{children:T},D))}),s.jsx(Ix,{variables:i,width:C,height:j,data:l,conf:o,interactionManager:n}),s.jsx(a.Text,{ref:p,align:"left",size:"xs",pl:"sm",sx:{display:Ma(o.stats.templates.bottom)?"block":"none"},children:Object.values(m.bottom).map((T,D)=>s.jsx(g.Fragment,{children:T},D))})]})}const zx=[{label:"Rectangle",value:"rectangle"}],Ax=[{label:"Horizontal",value:"horizontal"}];function Ex({control:e,index:t,remove:n,variableOptions:r}){return s.jsxs(a.Stack,{my:0,p:0,sx:{position:"relative"},children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`reference_areas.${t}.name`,control:e,render:({field:i})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})}),s.jsx(b.Controller,{name:`reference_areas.${t}.color`,control:e,render:({field:i})=>s.jsx(a.TextInput,{label:"Color",required:!0,sx:{flex:1},...i})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`reference_areas.${t}.type`,control:e,render:({field:i})=>s.jsx(a.Select,{label:"Type",required:!0,data:zx,sx:{flex:1},...i})}),s.jsx(b.Controller,{name:`reference_areas.${t}.direction`,control:e,render:({field:i})=>s.jsx(a.Select,{label:"Direction",required:!0,data:Ax,sx:{flex:1},...i})})]}),s.jsx(a.Divider,{variant:"dashed",label:"Data",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`reference_areas.${t}.y_keys.upper`,control:e,render:({field:i})=>s.jsx(a.Select,{label:"Upper Boundary",required:!0,data:r,sx:{flex:1},...i})}),s.jsx(b.Controller,{name:`reference_areas.${t}.y_keys.lower`,control:e,render:({field:i})=>s.jsx(a.Select,{label:"Lower Boundary",required:!0,data:r,sx:{flex:1},...i})})]}),s.jsx(a.Button,{leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Area"})]})}function Lx({control:e,watch:t,variables:n}){const{fields:r,append:i,remove:o}=b.useFieldArray({control:e,name:"reference_areas"}),l=t("reference_areas"),u=r.map((h,p)=>({...h,...l[p]})),c=()=>i({name:"",color:"rgba(0,0,0,0.1)",type:"rectangle",direction:"horizontal",y_keys:{upper:"",lower:""}}),d=g.useMemo(()=>n.map(h=>({label:h.name,value:h.name})),[n]);return s.jsxs(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"6px 0px 0px"}},children:[s.jsxs(a.Tabs.List,{children:[u.map((h,p)=>s.jsx(a.Tabs.Tab,{value:p.toString(),children:p+1},h.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),u.map((h,p)=>s.jsx(a.Tabs.Panel,{value:p.toString(),children:s.jsx(Ex,{control:e,index:p,remove:o,variableOptions:d})},h.id))]})}const Px=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Bx=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Ox({control:e,index:t,remove:n,watch:r,variableOptions:i,yAxisOptions:o}){const l=r(`reference_lines.${t}.orientation`);return s.jsxs(a.Stack,{my:0,p:0,sx:{position:"relative"},children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:u})=>s.jsx(a.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),s.jsx(b.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:u})=>s.jsx(a.Select,{label:"Value",required:!0,data:i,sx:{flex:1},...u})})]}),s.jsx(b.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:u})=>s.jsx(a.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...u})}),s.jsxs(a.Group,{grow:!0,children:[s.jsxs(a.Stack,{children:[s.jsx(b.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:u})=>s.jsx(a.Select,{label:"Orientation",data:Bx,required:!0,sx:{flex:1},...u})}),l==="vertical"&&s.jsx(a.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&s.jsx(b.Controller,{name:`reference_lines.${t}.yAxisIndex`,control:e,render:({field:{value:u,onChange:c,...d}})=>s.jsx(a.Select,{label:"Y Axis",data:o,disabled:o.length===0,...d,value:(u==null?void 0:u.toString())??"",onChange:h=>{if(!h){c(0);return}c(Number(h))},sx:{flex:1}})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:u})=>s.jsx(a.Select,{label:"Line Type",data:Px,sx:{flexGrow:1},...u})}),s.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:u})=>s.jsx(a.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...u})})]}),s.jsxs(a.Stack,{spacing:4,children:[s.jsx(a.Text,{size:"sm",children:"Color"}),s.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:u})=>s.jsx(ke,{...u})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),s.jsx(b.Controller,{name:`reference_lines.${t}.show_in_legend`,control:e,render:({field:u})=>s.jsx(a.Checkbox,{label:"Show in legend",checked:u.value,onChange:c=>u.onChange(c.currentTarget.checked)})}),s.jsx(a.Button,{leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]})}function $x({control:e,watch:t,variables:n}){const{fields:r,append:i,remove:o}=b.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=r.map((x,m)=>({...x,...l[m]})),c=()=>{i({name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,yAxisIndex:0})},d=g.useMemo(()=>n.map(x=>({label:x.name,value:x.name})),[n]),h=t("y_axes"),p=g.useMemo(()=>h.map(({name:x},m)=>({label:x,value:m.toString()})),[h]);return s.jsxs(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[s.jsxs(a.Tabs.List,{children:[u.map((x,m)=>s.jsx(a.Tabs.Tab,{value:m.toString(),children:m+1},x.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),u.map((x,m)=>s.jsx(a.Tabs.Panel,{value:m.toString(),children:s.jsx(Ox,{control:e,index:m,remove:o,watch:t,variableOptions:d,yAxisOptions:p})},x.id))]})}const Vx=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}],qx=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function Nx({control:e,regressionItem:t,index:n,remove:r,yAxisOptions:i}){const o=t.transform.config.method;return s.jsxs(a.Stack,{my:0,p:0,sx:{position:"relative"},children:[s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:`regressions.${n}.name`,control:e,render:({field:l})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...l})}),s.jsx(b.Controller,{name:`regressions.${n}.group_by_key`,control:e,render:({field:l})=>s.jsx(O,{label:"Split into multiple regression lines by this key...",clearable:!0,sx:{flex:1},...l})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`regressions.${n}.y_axis_data_key`,control:e,render:({field:l})=>s.jsx(O,{label:"Value Field",required:!0,sx:{flex:1},...l})}),s.jsx(b.Controller,{name:`regressions.${n}.plot.yAxisIndex`,control:e,render:({field:{value:l,onChange:u,...c}})=>s.jsx(a.Select,{label:"Y Axis",data:i,disabled:i.length===0,...c,value:(l==null?void 0:l.toString())??"",onChange:d=>{if(!d){u(0);return}u(Number(d))},sx:{flex:1}})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`regressions.${n}.transform.config.method`,control:e,render:({field:l})=>s.jsx(a.Select,{label:"Method",data:Vx,sx:{flex:1},...l})}),o==="polynomial"&&s.jsx(b.Controller,{name:`regressions.${n}.transform.config.order`,control:e,render:({field:l})=>s.jsx(a.NumberInput,{label:"Order",sx:{flex:1},...l})})]}),s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Line Style",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:`regressions.${n}.plot.lineStyle.type`,control:e,render:({field:l})=>s.jsx(a.Select,{label:"Line Type",data:qx,sx:{flexGrow:1},...l})}),s.jsx(b.Controller,{name:`regressions.${n}.plot.lineStyle.width`,control:e,render:({field:l})=>s.jsx(a.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...l})})]}),s.jsxs(a.Stack,{spacing:4,children:[s.jsx(a.Text,{size:"sm",children:"Color"}),s.jsx(b.Controller,{name:`regressions.${n}.plot.color`,control:e,render:({field:l})=>s.jsx(ke,{...l})})]}),s.jsx(a.Button,{leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(n),sx:{top:15,right:5},children:"Delete this Regression Line"})]})}function Fx({control:e,watch:t}){const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"regressions"}),o=t("regressions"),l=n.map((h,p)=>({...h,...o[p]})),u=t("y_axes"),c=g.useMemo(()=>u.map(({name:h},p)=>({label:h,value:p.toString()})),[u]),d=()=>r({transform:{type:"ecStat:regression",config:{method:"linear",order:1,formulaOn:"end"}},group_by_key:"",name:"",y_axis_data_key:"",plot:{type:"line",yAxisIndex:0,color:"#666666",lineStyle:{type:"solid",width:1}}});return s.jsxs(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((h,p)=>s.jsx(a.Tabs.Tab,{value:p.toString(),children:p+1},h.id)),s.jsx(a.Tabs.Tab,{onClick:d,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),l.map((h,p)=>s.jsx(a.Tabs.Panel,{value:p.toString(),children:s.jsx(Nx,{regressionItem:h,control:e,index:p,remove:i,yAxisOptions:c})},h.id))]})}const Ns={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
128
- `)}},Fs={fontSize:"14px",lineHeight:"32px",color:"#3D3E45",ul:{paddingLeft:"2em",margin:"6px 0 0"},p:{margin:"0 !important"},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(e,t,n){for(let r=0;;r++){if(r==e.childCount||r==t.childCount)return e.childCount==t.childCount?null:n;let i=e.child(r),o=t.child(r);if(i==o){n+=i.nodeSize;continue}if(!i.sameMarkup(o))return n;if(i.isText&&i.text!=o.text){for(let l=0;i.text[l]==o.text[l];l++)n++;return n}if(i.content.size||o.content.size){let l=za(i.content,o.content,n+1);if(l!=null)return l}n+=i.nodeSize}}function Aa(e,t,n,r){for(let i=e.childCount,o=t.childCount;;){if(i==0||o==0)return i==o?null:{a:n,b:r};let l=e.child(--i),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,h=Math.min(l.text.length,u.text.length);for(;d<h&&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=Aa(l.content,u.content,n-1,r-1);if(d)return d}n-=c,r-=c}}class H{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,i=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,i+u,o||null,l)!==!1&&c.content.size){let h=u+1;c.nodesBetween(Math.max(0,t-h),Math.min(c.content.size,n-h),r,i+h)}u=d}}descendants(t){this.nodesBetween(0,this.size,t)}textBetween(t,n,r,i){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?(i?o+=typeof i=="function"?i(u):i: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,i=this.content.slice(),o=0;for(n.isText&&n.sameMarkup(r)&&(i[i.length-1]=n.withText(n.text+r.text),o=1);o<t.content.length;o++)i.push(t.content[o]);return new H(i,this.size+t.size)}cut(t,n=this.size){if(t==0&&n==this.size)return this;let r=[],i=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),i+=u.nodeSize),l=c}return new H(r,i)}cutByIndex(t,n){return t==n?H.empty:t==0&&n==this.content.length?this:new H(this.content.slice(t,n))}replaceChild(t,n){let r=this.content[t];if(r==n)return this;let i=this.content.slice(),o=this.size+n.nodeSize-r.nodeSize;return i[t]=n,new H(i,o)}addToStart(t){return new H([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new H(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 i=this.content[n];t(i,r,n),r+=i.nodeSize}}findDiffStart(t,n=0){return za(this,t,n)}findDiffEnd(t,n=this.size,r=t.size){return Aa(this,t,n,r)}findIndex(t,n=-1){if(t==0)return Mn(0,t);if(t==this.size)return Mn(this.content.length,t);if(t>this.size||t<0)throw new RangeError(`Position ${t} outside of fragment (${this})`);for(let r=0,i=0;;r++){let o=this.child(r),l=i+o.nodeSize;if(l>=t)return l==t||n>0?Mn(r+1,l):Mn(r,i);i=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 H.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new H(n.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return H.empty;let n,r=0;for(let i=0;i<t.length;i++){let o=t[i];r+=o.nodeSize,i&&o.isText&&t[i-1].sameMarkup(o)?(n||(n=t.slice(0,i)),n[n.length-1]=o.withText(n[n.length-1].text+o.text)):n&&n.push(o)}return new H(n||t,r)}static from(t){if(!t)return H.empty;if(t instanceof H)return t;if(Array.isArray(t))return this.fromArray(t);if(t.attrs)return new H([t],t.nodeSize);throw new RangeError("Can not convert "+t+" to a Fragment"+(t.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}H.empty=new H([],0);const Gs={index:0,offset:0};function Mn(e,t){return Gs.index=e,Gs.offset=t,Gs}function Ws(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(!Ws(e[r],t[r]))return!1}else{for(let r in e)if(!(r in t)||!Ws(e[r],t[r]))return!1;for(let r in t)if(!(r in e))return!1}return!0}class Ae{constructor(t,n){this.type=t,this.attrs=n}addToSet(t){let n,r=!1;for(let i=0;i<t.length;i++){let o=t[i];if(this.eq(o))return t;if(this.type.excludes(o.type))n||(n=t.slice(0,i));else{if(o.type.excludes(this.type))return t;!r&&o.type.rank>this.type.rank&&(n||(n=t.slice(0,i)),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&&Ws(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 Ae.none;if(t instanceof Ae)return[t];let n=t.slice();return n.sort((r,i)=>r.type.rank-i.type.rank),n}}Ae.none=[];class Gx extends Error{}class se{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=La(this.content,t+this.openStart,n);return r&&new se(r,this.openStart,this.openEnd)}removeBetween(t,n){return new se(Ea(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 se.empty;let r=n.openStart||0,i=n.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new se(H.fromJSON(t,n.content),r,i)}static maxOpen(t,n=!0){let r=0,i=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)i++;return new se(t,r,i)}}se.empty=new se(H.empty,0,0);function Ea(e,t,n){let{index:r,offset:i}=e.findIndex(t),o=e.maybeChild(r),{index:l,offset:u}=e.findIndex(n);if(i==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(Ea(o.content,t-i-1,n-i-1)))}function La(e,t,n,r){let{index:i,offset:o}=e.findIndex(t),l=e.maybeChild(i);if(o==t||l.isText)return r&&!r.canReplace(i,i,n)?null:e.cut(0,t).append(n).append(e.cut(t));let u=La(l.content,t-o-1,n);return u&&e.replaceChild(i,l.copy(u))}class zn{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 i=t.nodes[r.node];return i.contentMatch.matchType(i)})}parse(t,n={}){let r=new $a(this,n,!1);return r.addAll(t,n.from,n.to),r.finish()}parseSlice(t,n={}){let r=new $a(this,n,!0);return r.addAll(t,n.from,n.to),se.maxOpen(r.finish())}matchTag(t,n,r){for(let i=r?this.tags.indexOf(r)+1:0;i<this.tags.length;i++){let o=this.tags[i];if(Qx(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,i){for(let o=i?this.styles.indexOf(i)+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(i){let o=i.priority==null?50:i.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,i)}for(let i in t.marks){let o=t.marks[i].spec.parseDOM;o&&o.forEach(l=>{r(l=Va(l)),l.mark||l.ignore||l.clearMark||(l.mark=i)})}for(let i in t.nodes){let o=t.nodes[i].spec.parseDOM;o&&o.forEach(l=>{r(l=Va(l)),l.node||l.ignore||l.mark||(l.node=i)})}return n}static fromSchema(t){return t.cached.domParser||(t.cached.domParser=new zn(t,zn.schemaRules(t)))}}const Pa={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},Wx={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Ba={ol:!0,ul:!0},An=1,En=2,en=4;function Oa(e,t,n){return t!=null?(t?An:0)|(t==="full"?En:0):e&&e.whitespace=="pre"?An|En:n&~en}class Ln{constructor(t,n,r,i,o,l,u){this.type=t,this.attrs=n,this.marks=r,this.pendingMarks=i,this.solid=o,this.options=u,this.content=[],this.activeMarks=Ae.none,this.stashMarks=[],this.match=l||(u&en?null:t.contentMatch)}findWrapping(t){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(H.from(t));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(t.type))?(this.match=r,i):null}}return this.match.findWrapping(t.type)}finish(t){if(!(this.options&An)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let o=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=o.withText(o.text.slice(0,o.text.length-i[0].length))}}let n=H.from(this.content);return!t&&this.match&&(n=n.append(this.match.fillBefore(H.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 i=r[n];(this.type?this.type.allowsMarkType(i.type):Kx(i.type,t))&&!i.isInSet(this.activeMarks)&&(this.activeMarks=i.addToSet(this.activeMarks),this.pendingMarks=i.removeFromSet(this.pendingMarks))}}inlineContext(t){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:t.parentNode&&!Pa.hasOwnProperty(t.parentNode.nodeName.toLowerCase())}}class $a{constructor(t,n,r){this.parser=t,this.options=n,this.isOpen=r,this.open=0;let i=n.topNode,o,l=Oa(null,n.preserveWhitespace,0)|(r?en:0);i?o=new Ln(i.type,i.attrs,Ae.none,Ae.none,!0,n.topMatch||i.type.contentMatch,l):r?o=new Ln(null,null,Ae.none,Ae.none,!0,null,l):o=new Ln(t.schema.topNodeType,null,Ae.none,Ae.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(Ux(n));if(!r)return;let[i,o]=r,l=this.top;for(let u=0;u<o.length;u++)this.removePendingMark(o[u],l);for(let u=0;u<i.length;u++)this.addPendingMark(i[u]);this.addElement(t);for(let u=0;u<i.length;u++)this.removePendingMark(i[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&En||r.inlineContext(t)||/[^ \t\r\n\u000c]/.test(n)){if(r.options&An)r.options&En?n=n.replace(/\r\n?/g,`
129
- `):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 i=r.content[r.content.length-1],o=t.previousSibling;(!i||o&&o.nodeName=="BR"||i.isText&&/[ \t\r\n\u000c]$/.test(i.text))&&(n=n.slice(1))}n&&this.insertNode(this.parser.schema.text(n)),this.findInText(t)}else this.findInside(t)}addElement(t,n){let r=t.nodeName.toLowerCase(),i;Ba.hasOwnProperty(r)&&this.parser.normalizeLists&&Rx(t);let o=this.options.ruleFromNode&&this.options.ruleFromNode(t)||(i=this.parser.matchTag(t,this,n));if(o?o.ignore:Wx.hasOwnProperty(r))this.findInside(t),this.ignoreFallback(t);else if(!o||o.skip||o.closeParent){o&&o.closeParent?this.open=Math.max(0,this.open-1):o&&o.skip.nodeType&&(t=o.skip);let l,u=this.top,c=this.needsBlock;if(Pa.hasOwnProperty(r))u.content.length&&u.content[0].isInline&&this.open&&(this.open--,u=this.top),l=!0,u.type||(this.needsBlock=!0);else if(!t.firstChild){this.leafFallback(t);return}this.addAll(t),l&&this.sync(u),this.needsBlock=c}else this.addElementByRule(t,o,o.consuming===!1?i:void 0)}leafFallback(t){t.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(t.ownerDocument.createTextNode(`
130
- `))}ignoreFallback(t){t.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"))}readStyles(t){let n=Ae.none,r=Ae.none;for(let i=0;i<t.length;i+=2)for(let o=void 0;;){let l=this.parser.matchStyle(t[i],t[i+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 i,o,l;n.node?(o=this.parser.schema.nodes[n.node],o.isLeaf?this.insertNode(o.create(n.attrs))||this.leafFallback(t):i=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)}i&&this.sync(u)&&this.open--,l&&this.removePendingMark(l,u)}addAll(t,n,r){let i=n||0;for(let o=n?t.childNodes[n]:t.firstChild,l=r==null?null:t.childNodes[r];o!=l;o=o.nextSibling,++i)this.findAtPoint(t,i),this.addDOM(o);this.findAtPoint(t,i)}findPlace(t){let n,r;for(let i=this.open;i>=0;i--){let o=this.nodes[i],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 i=0;i<n.length;i++)this.enterInner(n[i],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 i=0;i<t.marks.length;i++)(!n.type||n.type.allowsMarkType(t.marks[i].type))&&(r=t.marks[i].addToSet(r));return n.content.push(t.mark(r)),!0}return!1}enter(t,n,r){let i=this.findPlace(t.create(n));return i&&this.enterInner(t,n,!0,r),i}enterInner(t,n=null,r=!1,i){this.closeExtra();let o=this.top;o.applyPending(t),o.match=o.match&&o.match.matchType(t);let l=Oa(t,i,o.options);o.options&en&&o.content.length==0&&(l|=en),this.nodes.push(new Ln(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 i=r.length-1;i>=0;i--)t+=r[i].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 i=0;i<this.find.length;i++)this.find[i].pos==null&&t.nodeType==1&&t.contains(this.find[i].node)&&n.compareDocumentPosition(this.find[i].node)&(r?2:4)&&(this.find[i].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,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),o=-(r?r.depth+1:0)+(i?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 h=c>0||c==0&&i?this.nodes[c].type:r&&c>=o?r.node(c-o).type:null;if(!h||h.name!=d&&h.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=Yx(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 i=this.nodes[r];if(i.pendingMarks.lastIndexOf(t)>-1)i.pendingMarks=t.removeFromSet(i.pendingMarks);else{i.activeMarks=t.removeFromSet(i.activeMarks);let l=i.popFromStashMark(t);l&&i.type&&i.type.allowsMarkType(l.type)&&(i.activeMarks=l.addToSet(i.activeMarks))}if(i==n)break}}}function Rx(e){for(let t=e.firstChild,n=null;t;t=t.nextSibling){let r=t.nodeType==1?t.nodeName.toLowerCase():null;r&&Ba.hasOwnProperty(r)&&n?(n.appendChild(t),t=n):r=="li"?n=t:r&&(n=null)}}function Qx(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function Ux(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 Va(e){let t={};for(let n in e)t[n]=e[n];return t}function Kx(e,t){let n=t.schema.nodes;for(let r in n){let i=n[r];if(!i.allowsMarkType(e))continue;let o=[],l=u=>{o.push(u);for(let c=0;c<u.edgeCount;c++){let{type:d,next:h}=u.edge(c);if(d==t||o.indexOf(h)<0&&l(h))return!0}};if(l(i.contentMatch))return!0}}function Yx(e,t){for(let n=0;n<t.length;n++)if(e.eq(t[n]))return t[n]}const qa=65535,Na=Math.pow(2,16);function Xx(e,t){return e+t*Na}function Fa(e){return e&qa}function Jx(e){return(e-(e&qa))/Na}const Ga=1,Wa=2,Pn=4,Ra=8;class Qa{constructor(t,n,r){this.pos=t,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&Ra)>0}get deletedBefore(){return(this.delInfo&(Ga|Pn))>0}get deletedAfter(){return(this.delInfo&(Wa|Pn))>0}get deletedAcross(){return(this.delInfo&Pn)>0}}class Ge{constructor(t,n=!1){if(this.ranges=t,this.inverted=n,!t.length&&Ge.empty)return Ge.empty}recover(t){let n=0,r=Fa(t);if(!this.inverted)for(let i=0;i<r;i++)n+=this.ranges[i*3+2]-this.ranges[i*3+1];return this.ranges[r*3]+n+Jx(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 i=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?i:0);if(c>t)break;let d=this.ranges[u+o],h=this.ranges[u+l],p=c+d;if(t<=p){let x=d?t==c?-1:t==p?1:n:n,m=c+i+(x<0?0:h);if(r)return m;let j=t==(n<0?c:p)?null:Xx(u/3,t-c),C=t==c?Wa:t==p?Ga:Pn;return(n<0?t!=c:t!=p)&&(C|=Ra),new Qa(m,C,j)}i+=h-d}return r?t+i:new Qa(t+i,0,null)}touches(t,n){let r=0,i=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?r:0);if(c>t)break;let d=this.ranges[u+o],h=c+d;if(t<=h&&u==i*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 i=0,o=0;i<this.ranges.length;i+=3){let l=this.ranges[i],u=l-(this.inverted?o:0),c=l+(this.inverted?0:o),d=this.ranges[i+n],h=this.ranges[i+r];t(u,u+d,c,c+h),o+=h-d}}invert(){return new Ge(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(t){return t==0?Ge.empty:new Ge(t<0?[0,-t,0]:[0,0,t])}}Ge.empty=new Ge([]);const Rs=Object.create(null);class ze{getMap(){return Ge.empty}merge(t){return null}static fromJSON(t,n){if(!n||!n.stepType)throw new RangeError("Invalid input for Step.fromJSON");let r=Rs[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 Rs)throw new RangeError("Duplicate use of step JSON ID "+t);return Rs[t]=n,n.prototype.jsonID=t,n}}class ge{constructor(t,n){this.doc=t,this.failed=n}static ok(t){return new ge(t,null)}static fail(t){return new ge(null,t)}static fromReplace(t,n,r,i){try{return ge.ok(t.replace(n,r,i))}catch(o){if(o instanceof Gx)return ge.fail(o.message);throw o}}}function Qs(e,t,n){let r=[];for(let i=0;i<e.childCount;i++){let o=e.child(i);o.content.size&&(o=o.copy(Qs(o.content,t,o))),o.isInline&&(o=t(o,n,i)),r.push(o)}return H.fromArray(r)}class wt extends ze{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),i=r.node(r.sharedDepth(this.to)),o=new se(Qs(n.content,(l,u)=>!l.isAtom||!u.type.allowsMarkType(this.mark.type)?l:l.mark(this.mark.addToSet(l.marks)),i),n.openStart,n.openEnd);return ge.fromReplace(t,this.from,this.to,o)}invert(){return new Ct(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 wt(n.pos,r.pos,this.mark)}merge(t){return t instanceof wt&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new wt(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 wt(n.from,n.to,t.markFromJSON(n.mark))}}ze.jsonID("addMark",wt);class Ct extends ze{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 se(Qs(n.content,i=>i.mark(this.mark.removeFromSet(i.marks)),t),n.openStart,n.openEnd);return ge.fromReplace(t,this.from,this.to,r)}invert(){return new wt(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 Ct(n.pos,r.pos,this.mark)}merge(t){return t instanceof Ct&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new Ct(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 Ct(n.from,n.to,t.markFromJSON(n.mark))}}ze.jsonID("removeMark",Ct);class St extends ze{constructor(t,n){super(),this.pos=t,this.mark=n}apply(t){let n=t.nodeAt(this.pos);if(!n)return ge.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return ge.fromReplace(t,this.pos,this.pos+1,new se(H.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 i=0;i<n.marks.length;i++)if(!n.marks[i].isInSet(r))return new St(this.pos,n.marks[i]);return new St(this.pos,this.mark)}}return new tn(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new St(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 St(n.pos,t.markFromJSON(n.mark))}}ze.jsonID("addNodeMark",St);class tn extends ze{constructor(t,n){super(),this.pos=t,this.mark=n}apply(t){let n=t.nodeAt(this.pos);if(!n)return ge.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.removeFromSet(n.marks));return ge.fromReplace(t,this.pos,this.pos+1,new se(H.from(r),0,n.isLeaf?0:1))}invert(t){let n=t.nodeAt(this.pos);return!n||!this.mark.isInSet(n.marks)?this:new St(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new tn(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 tn(n.pos,t.markFromJSON(n.mark))}}ze.jsonID("removeNodeMark",tn);class He extends ze{constructor(t,n,r,i=!1){super(),this.from=t,this.to=n,this.slice=r,this.structure=i}apply(t){return this.structure&&Us(t,this.from,this.to)?ge.fail("Structure replace would overwrite content"):ge.fromReplace(t,this.from,this.to,this.slice)}getMap(){return new Ge([this.from,this.to-this.from,this.slice.size])}invert(t){return new He(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 He(n.pos,Math.max(n.pos,r.pos),this.slice)}merge(t){if(!(t instanceof He)||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?se.empty:new se(this.slice.content.append(t.slice.content),this.slice.openStart,t.slice.openEnd);return new He(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?se.empty:new se(t.slice.content.append(this.slice.content),t.slice.openStart,this.slice.openEnd);return new He(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 He(n.from,n.to,se.fromJSON(t,n.slice),!!n.structure)}}ze.jsonID("replace",He);class _t extends ze{constructor(t,n,r,i,o,l,u=!1){super(),this.from=t,this.to=n,this.gapFrom=r,this.gapTo=i,this.slice=o,this.insert=l,this.structure=u}apply(t){if(this.structure&&(Us(t,this.from,this.gapFrom)||Us(t,this.gapTo,this.to)))return ge.fail("Structure gap-replace would overwrite content");let n=t.slice(this.gapFrom,this.gapTo);if(n.openStart||n.openEnd)return ge.fail("Gap is not a flat range");let r=this.slice.insertAt(this.insert,n.content);return r?ge.fromReplace(t,this.from,this.to,r):ge.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(t){let n=this.gapTo-this.gapFrom;return new _t(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),i=t.map(this.gapFrom,-1),o=t.map(this.gapTo,1);return n.deletedAcross&&r.deletedAcross||i<n.pos||o>r.pos?null:new _t(n.pos,r.pos,i,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 _t(n.from,n.to,n.gapFrom,n.gapTo,se.fromJSON(t,n.slice),n.insert,!!n.structure)}}ze.jsonID("replaceAround",_t);function Us(e,t,n){let r=e.resolve(t),i=n-t,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let l=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!l||l.isLeaf)return!0;l=l.firstChild,i--}}return!1}function Zx(e,t,n){return(t==0||e.canReplace(t,e.childCount))&&(n==e.childCount||e.canReplace(0,n))}function Hx(e){let n=e.parent.content.cutByIndex(e.startIndex,e.endIndex);for(let r=e.depth;;--r){let i=e.$from.node(r),o=e.$from.index(r),l=e.$to.indexAfter(r);if(r<e.depth&&i.canReplace(o,l,n))return r;if(r==0||i.type.spec.isolating||!Zx(i,o,l))break}return null}function Bn(e,t,n=1,r){let i=e.resolve(t),o=i.depth-n,l=r&&r[r.length-1]||i.parent;if(o<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!l.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let d=i.depth-1,h=n-2;d>o;d--,h--){let p=i.node(d),x=i.index(d);if(p.type.spec.isolating)return!1;let m=p.content.cutByIndex(x,p.childCount),j=r&&r[h+1];j&&(m=m.replaceChild(0,j.type.create(j.attrs)));let C=r&&r[h]||p;if(!p.canReplace(x+1,p.childCount)||!C.type.validContent(m))return!1}let u=i.indexAfter(o),c=r&&r[0];return i.node(o).canReplaceWith(u,u,c?c.type:i.node(o+1).type)}function Ua(e,t){let n=e.resolve(t),r=n.index();return ef(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function ef(e,t){return!!(e&&t&&!e.isLeaf&&e.canAppend(t))}class nn extends ze{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 ge.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 i=n.type.create(r,null,n.marks);return ge.fromReplace(t,this.pos,this.pos+1,new se(H.from(i),0,n.isLeaf?0:1))}getMap(){return Ge.empty}invert(t){return new nn(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 nn(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 nn(n.pos,n.attr,n.value)}}ze.jsonID("attr",nn);let sn=class extends Error{};sn=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n},sn.prototype=Object.create(Error.prototype),sn.prototype.constructor=sn,sn.prototype.name="TransformError";const Ks=Object.create(null);class le{constructor(t,n,r){this.$anchor=t,this.$head=n,this.ranges=r||[new tf(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=se.empty){let r=n.content.lastChild,i=null;for(let u=0;u<n.openEnd;u++)i=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],h=t.mapping.slice(o);t.replaceRange(h.map(c.pos),h.map(d.pos),u?se.empty:n),u==0&&Xa(t,o,(r?r.isInline:i&&i.isTextblock)?-1:1)}}replaceWith(t,n){let r=t.steps.length,i=this.ranges;for(let o=0;o<i.length;o++){let{$from:l,$to:u}=i[o],c=t.mapping.slice(r),d=c.map(l.pos),h=c.map(u.pos);o?t.deleteRange(d,h):(t.replaceRangeWith(d,h,n),Xa(t,r,n.isInline?-1:1))}}static findFrom(t,n,r=!1){let i=t.parent.inlineContent?new me(t):Bt(t.node(0),t.parent,t.pos,t.index(),n,r);if(i)return i;for(let o=t.depth-1;o>=0;o--){let l=n<0?Bt(t.node(0),t.node(o),t.before(o+1),t.index(o),n,r):Bt(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 ot(t.node(0))}static atStart(t){return Bt(t,t,0,0,1)||new ot(t)}static atEnd(t){return Bt(t,t,t.content.size,t.childCount,-1)||new ot(t)}static fromJSON(t,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=Ks[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 Ks)throw new RangeError("Duplicate use of selection JSON ID "+t);return Ks[t]=n,n.prototype.jsonID=t,n}getBookmark(){return me.between(this.$anchor,this.$head).getBookmark()}}le.prototype.visible=!0;class tf{constructor(t,n){this.$from=t,this.$to=n}}let Ka=!1;function Ya(e){!Ka&&!e.parent.inlineContent&&(Ka=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+e.parent.type.name+")"))}class me extends le{constructor(t,n=t){Ya(t),Ya(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 le.near(r);let i=t.resolve(n.map(this.anchor));return new me(i.parent.inlineContent?i:r,r)}replace(t,n=se.empty){if(super.replace(t,n),n==se.empty){let r=this.$from.marksAcross(this.$to);r&&t.ensureMarks(r)}}eq(t){return t instanceof me&&t.anchor==this.anchor&&t.head==this.head}getBookmark(){return new On(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 me(t.resolve(n.anchor),t.resolve(n.head))}static create(t,n,r=n){let i=t.resolve(n);return new this(i,r==n?i:t.resolve(r))}static between(t,n,r){let i=t.pos-n.pos;if((!r||i)&&(r=i>=0?1:-1),!n.parent.inlineContent){let o=le.findFrom(n,r,!0)||le.findFrom(n,-r,!0);if(o)n=o.$head;else return le.near(n,r)}return t.parent.inlineContent||(i==0?t=n:(t=(le.findFrom(t,-r,!0)||le.findFrom(t,r,!0)).$anchor,t.pos<n.pos!=i<0&&(t=n))),new me(t,n)}}le.jsonID("text",me);class On{constructor(t,n){this.anchor=t,this.head=n}map(t){return new On(t.map(this.anchor),t.map(this.head))}resolve(t){return me.between(t.resolve(this.anchor),t.resolve(this.head))}}class Ee extends le{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:i}=n.mapResult(this.anchor),o=t.resolve(i);return r?le.near(o):new Ee(o)}content(){return new se(H.from(this.node),0,0)}eq(t){return t instanceof Ee&&t.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new Ys(this.anchor)}static fromJSON(t,n){if(typeof n.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new Ee(t.resolve(n.anchor))}static create(t,n){return new Ee(t.resolve(n))}static isSelectable(t){return!t.isText&&t.type.spec.selectable!==!1}}Ee.prototype.visible=!1,le.jsonID("node",Ee);class Ys{constructor(t){this.anchor=t}map(t){let{deleted:n,pos:r}=t.mapResult(this.anchor);return n?new On(r,r):new Ys(r)}resolve(t){let n=t.resolve(this.anchor),r=n.nodeAfter;return r&&Ee.isSelectable(r)?new Ee(n):le.near(n)}}class ot extends le{constructor(t){super(t.resolve(0),t.resolve(t.content.size))}replace(t,n=se.empty){if(n==se.empty){t.delete(0,t.doc.content.size);let r=le.atStart(t.doc);r.eq(t.selection)||t.setSelection(r)}else super.replace(t,n)}toJSON(){return{type:"all"}}static fromJSON(t){return new ot(t)}map(t){return new ot(t)}eq(t){return t instanceof ot}getBookmark(){return nf}}le.jsonID("all",ot);const nf={map(){return this},resolve(e){return new ot(e)}};function Bt(e,t,n,r,i,o=!1){if(t.inlineContent)return me.create(e,n);for(let l=r-(i>0?0:1);i>0?l<t.childCount:l>=0;l+=i){let u=t.child(l);if(u.isAtom){if(!o&&Ee.isSelectable(u))return Ee.create(e,n-(i<0?u.nodeSize:0))}else{let c=Bt(e,u,n+i,i<0?u.childCount:0,i,o);if(c)return c}n+=u.nodeSize*i}return null}function Xa(e,t,n){let r=e.steps.length-1;if(r<t)return;let i=e.steps[r];if(!(i instanceof He||i instanceof _t))return;let o=e.mapping.maps[r],l;o.forEach((u,c,d,h)=>{l==null&&(l=h)}),e.setSelection(le.near(e.doc.resolve(l),n))}function Ja(e,t){return!t||!e?e:e.bind(t)}class $n{constructor(t,n,r){this.name=t,this.init=Ja(n.init,r),this.apply=Ja(n.apply,r)}}new $n("doc",{init(e){return e.doc||e.schema.topNodeType.createAndFill()},apply(e){return e.doc}}),new $n("selection",{init(e,t){return e.selection||le.atStart(t.doc)},apply(e){return e.selection}}),new $n("storedMarks",{init(e){return e.storedMarks||null},apply(e,t,n,r){return r.selection.$cursor?e.storedMarks:null}}),new $n("scrollToSelection",{init(){return 0},apply(e,t){return e.scrolledIntoView?t+1:t}});function Za(e,t,n){for(let r in e){let i=e[r];i instanceof Function?i=i.bind(t):r=="handleDOMEvents"&&(i=Za(i,t,{})),n[r]=i}return n}class rn{constructor(t){this.spec=t,this.props={},t.props&&Za(t.props,this,this.props),this.key=t.key?t.key.key:Ha("plugin")}getState(t){return t[this.key]}}const Xs=Object.create(null);function Ha(e){return e in Xs?e+"$"+ ++Xs[e]:(Xs[e]=0,e+"$")}class an{constructor(t="key"){this.key=Ha(t)}get(t){return t.config.pluginsByKey[this.key]}getState(t){return t[this.key]}}function eo(e){const{state:t,transaction:n}=e;let{selection:r}=n,{doc:i}=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 i},get tr(){return r=n.selection,i=n.doc,o=n.storedMarks,n}}}class sf{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:i}=n,{tr:o}=r,l=this.buildProps(o);return Object.fromEntries(Object.entries(t).map(([u,c])=>[u,(...h)=>{const p=c(...h)(l);return!o.getMeta("preventDispatch")&&!this.hasCustomState&&i.dispatch(o),p}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(t,n=!0){const{rawCommands:r,editor:i,state:o}=this,{view:l}=i,u=[],c=!!t,d=t||o.tr,h=()=>(!c&&n&&!d.getMeta("preventDispatch")&&!this.hasCustomState&&l.dispatch(d),u.every(x=>x===!0)),p={...Object.fromEntries(Object.entries(r).map(([x,m])=>[x,(...C)=>{const T=this.buildProps(d,n),D=m(...C)(T);return u.push(D),p}])),run:h};return p}createCan(t){const{rawCommands:n,state:r}=this,i=!1,o=t||r.tr,l=this.buildProps(o,i);return{...Object.fromEntries(Object.entries(n).map(([c,d])=>[c,(...h)=>d(...h)({...l,dispatch:void 0})])),chain:()=>this.createChain(o,i)}}buildProps(t,n=!0){const{rawCommands:r,editor:i,state:o}=this,{view:l}=i;o.storedMarks&&t.setStoredMarks(o.storedMarks);const u={tr:t,editor:i,view:l,state:eo({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,(...h)=>d(...h)(u)]))}};return u}}function gt(e,t,n){return e.config[t]===void 0&&e.parent?gt(e.parent,t,n):typeof e.config[t]=="function"?e.config[t].bind({...n,parent:e.parent?gt(e.parent,t,n):null}):e.config[t]}function rf(e){const t=e.filter(i=>i.type==="extension"),n=e.filter(i=>i.type==="node"),r=e.filter(i=>i.type==="mark");return{baseExtensions:t,nodeExtensions:n,markExtensions:r}}function Ce(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 af(e){return typeof e=="function"}function Ot(e,t=void 0,...n){return af(e)?t?e.bind(t)(...n):e(...n):e}function of(e){return Object.prototype.toString.call(e)==="[object RegExp]"}function lf(e){return Object.prototype.toString.call(e).slice(8,-1)}function Js(e){return lf(e)!=="Object"?!1:e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype}function to(e,t){const n={...e};return Js(e)&&Js(t)&&Object.keys(t).forEach(r=>{Js(t[r])?r in e?n[r]=to(e[r],t[r]):Object.assign(n,{[r]:t[r]}):Object.assign(n,{[r]:t[r]})}),n}class et{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=Ot(gt(this,"addOptions",{name:this.name}))),this.storage=Ot(gt(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(t={}){return new et(t)}configure(t={}){const n=this.extend();return n.options=to(this.options,t),n.storage=Ot(gt(n,"addStorage",{name:n.name,options:n.options})),n}extend(t={}){const n=new et(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=Ot(gt(n,"addOptions",{name:n.name})),n.storage=Ot(gt(n,"addStorage",{name:n.name,options:n.options})),n}}function uf(e,t,n){const{from:r,to:i}=t,{blockSeparator:o=`
127
+ `}})}function Cx(e){return e.y_axes.reduce((n,{label_formatter:r},i)=>(n[i]=function(l){let c=l;if(typeof l=="object"&&(Array.isArray(l.value)&&l.value.length===2?c=l.value[1]:c=l.value),!r)return c;try{return G(c,r)}catch(u){return console.error(u),c}},n),{default:({value:n})=>n})}function Ia(e,t){const n={};return t.map(r=>{const i=st(r,e);n[r.name]=Ae(r,i)}),n}function Sx(e,t){const{overflow:n,...r}=e.x_axis.axisLabel,i=Be(n.on_axis),o=t.length===0;return[ee.getXAxis({data:t,name:e.x_axis_name??"",nameGap:o?5:void 0,id:"main-x-axis",type:e.x_axis.type,axisLabel:{...r,...i,formatter:Pt(r.formatter)}})]}function _x(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 kx(e){if(e.length===0)return{};const t={},n={};return e.forEach(r=>{const i=_x(r.data);if(!n[r.yAxisIndex]){n[r.yAxisIndex]=i;return}n[r.yAxisIndex]=n[r.yAxisIndex].concat(i)}),Object.entries(n).forEach(([r,i])=>{const o=y.minBy(i)??0,l=y.maxBy(i)??0;o==0&&l==0&&(t[r]=1)}),t}function Tx(e,t,n){const r=kx(n);return e.y_axes.map(({nameAlignment:i,min:o,max:l,show:c,...u},d)=>{let h=u.position;return h||(h=d>0?"right":"left"),ee.getYAxis({...u,minInterval:r[d]??0,show:c,min:o||void 0,max:l||void 0,position:h,axisLabel:{show:c,formatter:t[d]??t.default},nameTextStyle:{align:i},nameLocation:"end",nameGap:c?15:0,splitLine:{show:d===0}})})}const Dx={xAxis:[{type:"category",nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0}}]};function Ix(e,t,n){const r=Ia(t,n),i=Cx(e),o=y.uniq(Ye(t,e.x_axis_data_key)),l=bx(e,o,t,i,n,r),c=cx(e,t),u={xAxis:Sx(e,o),yAxis:Tx(e,i,l),series:[...l,...c],tooltip:wx(e,t,l,i),grid:rx(e),legend:ox(l),dataZoom:_n(e.dataZoom)};return y.defaultsDeep({},u,Dx)}function Ma(e){const t=e.getModel(),n=t.getSeries().map(r=>{if(!r.option.custom)return r.option;const i=t.getColorFromPalette(r.option.custom.targetSeries,null);return r.option.color=i,r.option});e.setOption({...e.getOption(),series:n})}function za(e){return e.trim().length>0}function Mx({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const l=jt(t,e.x_axis_data_key),c=Oe(i.triggerManager,Os.id),u=g.useCallback(m=>{const j=y.get(l,m.name,{error:"rowData is not found"});c.forEach(C=>{i.runInteraction(C.id,{...m,rowData:j})})},[l,c,i]),d=g.useMemo(()=>Ix(e,t,o),[e,t]),h=g.useRef(),p=g.useMemo(()=>({click:u}),[u]),x=m=>{h.current=m,Ma(m)};return g.useEffect(()=>{h.current&&Ma(h.current)},[d]),!n||!r?null:s.jsx(we,{echarts:be,option:d,style:{width:n,height:r},onEvents:p,onChartReady:x,notMerge:!0,theme:"merico-light"})}function zx({context:e,instance:t}){const n=$e({vizManager:e.vizManager,instance:t}),{value:r}=O(e.instanceData,"config"),{variables:i}=e,o=g.useMemo(()=>y.defaults({},r,$s),[r]),l=e.data,{width:c,height:u}=e.viewport,{ref:d,height:h}=re.useElementSize(),{ref:p,height:x}=re.useElementSize(),m=g.useMemo(()=>{const{stats:{templates:T}}=o;return{top:Jt(T.top,i,l),bottom:Jt(T.bottom,i,l)}},[o,l]),j=Math.max(0,We(u)-h-x),C=Ge(c);return s.jsxs(ke,{width:c,height:u,children:[s.jsx(a.Text,{ref:d,align:"left",size:"xs",pl:"sm",sx:{display:za(o.stats.templates.top)?"block":"none"},children:Object.values(m.top).map((T,D)=>s.jsx(g.Fragment,{children:T},D))}),s.jsx(Mx,{variables:i,width:C,height:j,data:l,conf:o,interactionManager:n}),s.jsx(a.Text,{ref:p,align:"left",size:"xs",pl:"sm",sx:{display:za(o.stats.templates.bottom)?"block":"none"},children:Object.values(m.bottom).map((T,D)=>s.jsx(g.Fragment,{children:T},D))})]})}const Ax=[{label:"Rectangle",value:"rectangle"}],Ex=[{label:"Horizontal",value:"horizontal"}];function Px({control:e,index:t,remove:n,variableOptions:r}){return s.jsxs(a.Stack,{my:0,p:0,sx:{position:"relative"},children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`reference_areas.${t}.name`,control:e,render:({field:i})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})}),s.jsx(b.Controller,{name:`reference_areas.${t}.color`,control:e,render:({field:i})=>s.jsx(a.TextInput,{label:"Color",required:!0,sx:{flex:1},...i})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`reference_areas.${t}.type`,control:e,render:({field:i})=>s.jsx(a.Select,{label:"Type",required:!0,data:Ax,sx:{flex:1},...i})}),s.jsx(b.Controller,{name:`reference_areas.${t}.direction`,control:e,render:({field:i})=>s.jsx(a.Select,{label:"Direction",required:!0,data:Ex,sx:{flex:1},...i})})]}),s.jsx(a.Divider,{variant:"dashed",label:"Data",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`reference_areas.${t}.y_keys.upper`,control:e,render:({field:i})=>s.jsx(a.Select,{label:"Upper Boundary",required:!0,data:r,sx:{flex:1},...i})}),s.jsx(b.Controller,{name:`reference_areas.${t}.y_keys.lower`,control:e,render:({field:i})=>s.jsx(a.Select,{label:"Lower Boundary",required:!0,data:r,sx:{flex:1},...i})})]}),s.jsx(a.Button,{leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Area"})]})}function Lx({control:e,watch:t,variables:n}){const{fields:r,append:i,remove:o}=b.useFieldArray({control:e,name:"reference_areas"}),l=t("reference_areas"),c=r.map((h,p)=>({...h,...l[p]})),u=()=>i({name:"",color:"rgba(0,0,0,0.1)",type:"rectangle",direction:"horizontal",y_keys:{upper:"",lower:""}}),d=g.useMemo(()=>n.map(h=>({label:h.name,value:h.name})),[n]);return s.jsxs(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"6px 0px 0px"}},children:[s.jsxs(a.Tabs.List,{children:[c.map((h,p)=>s.jsx(a.Tabs.Tab,{value:p.toString(),children:p+1},h.id)),s.jsx(a.Tabs.Tab,{onClick:u,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),c.map((h,p)=>s.jsx(a.Tabs.Panel,{value:p.toString(),children:s.jsx(Px,{control:e,index:p,remove:o,variableOptions:d})},h.id))]})}const Bx=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Ox=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function $x({control:e,index:t,remove:n,watch:r,variableOptions:i,yAxisOptions:o}){const l=r(`reference_lines.${t}.orientation`);return s.jsxs(a.Stack,{my:0,p:0,sx:{position:"relative"},children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:c})=>s.jsx(a.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...c})}),s.jsx(b.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:c})=>s.jsx(a.Select,{label:"Value",required:!0,data:i,sx:{flex:1},...c})})]}),s.jsx(b.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:c})=>s.jsx(a.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...c})}),s.jsxs(a.Group,{grow:!0,children:[s.jsxs(a.Stack,{children:[s.jsx(b.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:c})=>s.jsx(a.Select,{label:"Orientation",data:Ox,required:!0,sx:{flex:1},...c})}),l==="vertical"&&s.jsx(a.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&s.jsx(b.Controller,{name:`reference_lines.${t}.yAxisIndex`,control:e,render:({field:{value:c,onChange:u,...d}})=>s.jsx(a.Select,{label:"Y Axis",data:o,disabled:o.length===0,...d,value:(c==null?void 0:c.toString())??"",onChange:h=>{if(!h){u(0);return}u(Number(h))},sx:{flex:1}})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:c})=>s.jsx(a.Select,{label:"Line Type",data:Bx,sx:{flexGrow:1},...c})}),s.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:c})=>s.jsx(a.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...c})})]}),s.jsxs(a.Stack,{spacing:4,children:[s.jsx(a.Text,{size:"sm",children:"Color"}),s.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:c})=>s.jsx(Ce,{...c})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),s.jsx(b.Controller,{name:`reference_lines.${t}.show_in_legend`,control:e,render:({field:c})=>s.jsx(a.Checkbox,{label:"Show in legend",checked:c.value,onChange:u=>c.onChange(u.currentTarget.checked)})}),s.jsx(a.Button,{leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]})}function Vx({control:e,watch:t,variables:n}){const{fields:r,append:i,remove:o}=b.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),c=r.map((x,m)=>({...x,...l[m]})),u=()=>{i({name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,yAxisIndex:0})},d=g.useMemo(()=>n.map(x=>({label:x.name,value:x.name})),[n]),h=t("y_axes"),p=g.useMemo(()=>h.map(({name:x},m)=>({label:x,value:m.toString()})),[h]);return s.jsxs(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[s.jsxs(a.Tabs.List,{children:[c.map((x,m)=>s.jsx(a.Tabs.Tab,{value:m.toString(),children:m+1},x.id)),s.jsx(a.Tabs.Tab,{onClick:u,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),c.map((x,m)=>s.jsx(a.Tabs.Panel,{value:m.toString(),children:s.jsx($x,{control:e,index:m,remove:o,watch:t,variableOptions:d,yAxisOptions:p})},x.id))]})}const qx=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}],Nx=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function Fx({control:e,regressionItem:t,index:n,remove:r,yAxisOptions:i}){const o=t.transform.config.method;return s.jsxs(a.Stack,{my:0,p:0,sx:{position:"relative"},children:[s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:`regressions.${n}.name`,control:e,render:({field:l})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...l})}),s.jsx(b.Controller,{name:`regressions.${n}.group_by_key`,control:e,render:({field:l})=>s.jsx(B,{label:"Split into multiple regression lines by this key...",clearable:!0,sx:{flex:1},...l})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`regressions.${n}.y_axis_data_key`,control:e,render:({field:l})=>s.jsx(B,{label:"Value Field",required:!0,sx:{flex:1},...l})}),s.jsx(b.Controller,{name:`regressions.${n}.plot.yAxisIndex`,control:e,render:({field:{value:l,onChange:c,...u}})=>s.jsx(a.Select,{label:"Y Axis",data:i,disabled:i.length===0,...u,value:(l==null?void 0:l.toString())??"",onChange:d=>{if(!d){c(0);return}c(Number(d))},sx:{flex:1}})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`regressions.${n}.transform.config.method`,control:e,render:({field:l})=>s.jsx(a.Select,{label:"Method",data:qx,sx:{flex:1},...l})}),o==="polynomial"&&s.jsx(b.Controller,{name:`regressions.${n}.transform.config.order`,control:e,render:({field:l})=>s.jsx(a.NumberInput,{label:"Order",sx:{flex:1},...l})})]}),s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Line Style",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:`regressions.${n}.plot.lineStyle.type`,control:e,render:({field:l})=>s.jsx(a.Select,{label:"Line Type",data:Nx,sx:{flexGrow:1},...l})}),s.jsx(b.Controller,{name:`regressions.${n}.plot.lineStyle.width`,control:e,render:({field:l})=>s.jsx(a.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...l})})]}),s.jsxs(a.Stack,{spacing:4,children:[s.jsx(a.Text,{size:"sm",children:"Color"}),s.jsx(b.Controller,{name:`regressions.${n}.plot.color`,control:e,render:({field:l})=>s.jsx(Ce,{...l})})]}),s.jsx(a.Button,{leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(n),sx:{top:15,right:5},children:"Delete this Regression Line"})]})}function Gx({control:e,watch:t}){const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"regressions"}),o=t("regressions"),l=n.map((h,p)=>({...h,...o[p]})),c=t("y_axes"),u=g.useMemo(()=>c.map(({name:h},p)=>({label:h,value:p.toString()})),[c]),d=()=>r({transform:{type:"ecStat:regression",config:{method:"linear",order:1,formulaOn:"end"}},group_by_key:"",name:"",y_axis_data_key:"",plot:{type:"line",yAxisIndex:0,color:"#666666",lineStyle:{type:"solid",width:1}}});return s.jsxs(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((h,p)=>s.jsx(a.Tabs.Tab,{value:p.toString(),children:p+1},h.id)),s.jsx(a.Tabs.Tab,{onClick:d,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),l.map((h,p)=>s.jsx(a.Tabs.Panel,{value:p.toString(),children:s.jsx(Fx,{regressionItem:h,control:e,index:p,remove:i,yAxisOptions:u})},h.id))]})}const qs={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
128
+ `)}},Ns={fontSize:"14px",lineHeight:"32px",color:"#3D3E45",ul:{paddingLeft:"2em",margin:"6px 0 0"},p:{margin:"0 !important"},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 Aa(e,t,n){for(let r=0;;r++){if(r==e.childCount||r==t.childCount)return e.childCount==t.childCount?null:n;let i=e.child(r),o=t.child(r);if(i==o){n+=i.nodeSize;continue}if(!i.sameMarkup(o))return n;if(i.isText&&i.text!=o.text){for(let l=0;i.text[l]==o.text[l];l++)n++;return n}if(i.content.size||o.content.size){let l=Aa(i.content,o.content,n+1);if(l!=null)return l}n+=i.nodeSize}}function Ea(e,t,n,r){for(let i=e.childCount,o=t.childCount;;){if(i==0||o==0)return i==o?null:{a:n,b:r};let l=e.child(--i),c=t.child(--o),u=l.nodeSize;if(l==c){n-=u,r-=u;continue}if(!l.sameMarkup(c))return{a:n,b:r};if(l.isText&&l.text!=c.text){let d=0,h=Math.min(l.text.length,c.text.length);for(;d<h&&l.text[l.text.length-d-1]==c.text[c.text.length-d-1];)d++,n--,r--;return{a:n,b:r}}if(l.content.size||c.content.size){let d=Ea(l.content,c.content,n-1,r-1);if(d)return d}n-=u,r-=u}}class J{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,i=0,o){for(let l=0,c=0;c<n;l++){let u=this.content[l],d=c+u.nodeSize;if(d>t&&r(u,i+c,o||null,l)!==!1&&u.content.size){let h=c+1;u.nodesBetween(Math.max(0,t-h),Math.min(u.content.size,n-h),r,i+h)}c=d}}descendants(t){this.nodesBetween(0,this.size,t)}textBetween(t,n,r,i){let o="",l=!0;return this.nodesBetween(t,n,(c,u)=>{c.isText?(o+=c.text.slice(Math.max(t,u)-u,n-u),l=!r):c.isLeaf?(i?o+=typeof i=="function"?i(c):i:c.type.spec.leafText&&(o+=c.type.spec.leafText(c)),l=!r):!l&&c.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,i=this.content.slice(),o=0;for(n.isText&&n.sameMarkup(r)&&(i[i.length-1]=n.withText(n.text+r.text),o=1);o<t.content.length;o++)i.push(t.content[o]);return new J(i,this.size+t.size)}cut(t,n=this.size){if(t==0&&n==this.size)return this;let r=[],i=0;if(n>t)for(let o=0,l=0;l<n;o++){let c=this.content[o],u=l+c.nodeSize;u>t&&((l<t||u>n)&&(c.isText?c=c.cut(Math.max(0,t-l),Math.min(c.text.length,n-l)):c=c.cut(Math.max(0,t-l-1),Math.min(c.content.size,n-l-1))),r.push(c),i+=c.nodeSize),l=u}return new J(r,i)}cutByIndex(t,n){return t==n?J.empty:t==0&&n==this.content.length?this:new J(this.content.slice(t,n))}replaceChild(t,n){let r=this.content[t];if(r==n)return this;let i=this.content.slice(),o=this.size+n.nodeSize-r.nodeSize;return i[t]=n,new J(i,o)}addToStart(t){return new J([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new J(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 i=this.content[n];t(i,r,n),r+=i.nodeSize}}findDiffStart(t,n=0){return Aa(this,t,n)}findDiffEnd(t,n=this.size,r=t.size){return Ea(this,t,n,r)}findIndex(t,n=-1){if(t==0)return In(0,t);if(t==this.size)return In(this.content.length,t);if(t>this.size||t<0)throw new RangeError(`Position ${t} outside of fragment (${this})`);for(let r=0,i=0;;r++){let o=this.child(r),l=i+o.nodeSize;if(l>=t)return l==t||n>0?In(r+1,l):In(r,i);i=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 J.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new J(n.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return J.empty;let n,r=0;for(let i=0;i<t.length;i++){let o=t[i];r+=o.nodeSize,i&&o.isText&&t[i-1].sameMarkup(o)?(n||(n=t.slice(0,i)),n[n.length-1]=o.withText(n[n.length-1].text+o.text)):n&&n.push(o)}return new J(n||t,r)}static from(t){if(!t)return J.empty;if(t instanceof J)return t;if(Array.isArray(t))return this.fromArray(t);if(t.attrs)return new J([t],t.nodeSize);throw new RangeError("Can not convert "+t+" to a Fragment"+(t.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}J.empty=new J([],0);const Fs={index:0,offset:0};function In(e,t){return Fs.index=e,Fs.offset=t,Fs}function Gs(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(!Gs(e[r],t[r]))return!1}else{for(let r in e)if(!(r in t)||!Gs(e[r],t[r]))return!1;for(let r in t)if(!(r in e))return!1}return!0}class Ie{constructor(t,n){this.type=t,this.attrs=n}addToSet(t){let n,r=!1;for(let i=0;i<t.length;i++){let o=t[i];if(this.eq(o))return t;if(this.type.excludes(o.type))n||(n=t.slice(0,i));else{if(o.type.excludes(this.type))return t;!r&&o.type.rank>this.type.rank&&(n||(n=t.slice(0,i)),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&&Gs(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 Ie.none;if(t instanceof Ie)return[t];let n=t.slice();return n.sort((r,i)=>r.type.rank-i.type.rank),n}}Ie.none=[];class Wx extends Error{}class te{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=La(this.content,t+this.openStart,n);return r&&new te(r,this.openStart,this.openEnd)}removeBetween(t,n){return new te(Pa(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 te.empty;let r=n.openStart||0,i=n.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new te(J.fromJSON(t,n.content),r,i)}static maxOpen(t,n=!0){let r=0,i=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)i++;return new te(t,r,i)}}te.empty=new te(J.empty,0,0);function Pa(e,t,n){let{index:r,offset:i}=e.findIndex(t),o=e.maybeChild(r),{index:l,offset:c}=e.findIndex(n);if(i==t||o.isText){if(c!=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(Pa(o.content,t-i-1,n-i-1)))}function La(e,t,n,r){let{index:i,offset:o}=e.findIndex(t),l=e.maybeChild(i);if(o==t||l.isText)return r&&!r.canReplace(i,i,n)?null:e.cut(0,t).append(n).append(e.cut(t));let c=La(l.content,t-o-1,n);return c&&e.replaceChild(i,l.copy(c))}class Mn{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 i=t.nodes[r.node];return i.contentMatch.matchType(i)})}parse(t,n={}){let r=new Va(this,n,!1);return r.addAll(t,n.from,n.to),r.finish()}parseSlice(t,n={}){let r=new Va(this,n,!0);return r.addAll(t,n.from,n.to),te.maxOpen(r.finish())}matchTag(t,n,r){for(let i=r?this.tags.indexOf(r)+1:0;i<this.tags.length;i++){let o=this.tags[i];if(Ux(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,i){for(let o=i?this.styles.indexOf(i)+1:0;o<this.styles.length;o++){let l=this.styles[o],c=l.style;if(!(c.indexOf(t)!=0||l.context&&!r.matchesContext(l.context)||c.length>t.length&&(c.charCodeAt(t.length)!=61||c.slice(t.length+1)!=n))){if(l.getAttrs){let u=l.getAttrs(n);if(u===!1)continue;l.attrs=u||void 0}return l}}}static schemaRules(t){let n=[];function r(i){let o=i.priority==null?50:i.priority,l=0;for(;l<n.length;l++){let c=n[l];if((c.priority==null?50:c.priority)<o)break}n.splice(l,0,i)}for(let i in t.marks){let o=t.marks[i].spec.parseDOM;o&&o.forEach(l=>{r(l=qa(l)),l.mark||l.ignore||l.clearMark||(l.mark=i)})}for(let i in t.nodes){let o=t.nodes[i].spec.parseDOM;o&&o.forEach(l=>{r(l=qa(l)),l.node||l.ignore||l.mark||(l.node=i)})}return n}static fromSchema(t){return t.cached.domParser||(t.cached.domParser=new Mn(t,Mn.schemaRules(t)))}}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},Rx={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Oa={ol:!0,ul:!0},zn=1,An=2,Ht=4;function $a(e,t,n){return t!=null?(t?zn:0)|(t==="full"?An:0):e&&e.whitespace=="pre"?zn|An:n&~Ht}class En{constructor(t,n,r,i,o,l,c){this.type=t,this.attrs=n,this.marks=r,this.pendingMarks=i,this.solid=o,this.options=c,this.content=[],this.activeMarks=Ie.none,this.stashMarks=[],this.match=l||(c&Ht?null:t.contentMatch)}findWrapping(t){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(J.from(t));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(t.type))?(this.match=r,i):null}}return this.match.findWrapping(t.type)}finish(t){if(!(this.options&zn)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let o=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=o.withText(o.text.slice(0,o.text.length-i[0].length))}}let n=J.from(this.content);return!t&&this.match&&(n=n.append(this.match.fillBefore(J.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 i=r[n];(this.type?this.type.allowsMarkType(i.type):Yx(i.type,t))&&!i.isInSet(this.activeMarks)&&(this.activeMarks=i.addToSet(this.activeMarks),this.pendingMarks=i.removeFromSet(this.pendingMarks))}}inlineContext(t){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:t.parentNode&&!Ba.hasOwnProperty(t.parentNode.nodeName.toLowerCase())}}class Va{constructor(t,n,r){this.parser=t,this.options=n,this.isOpen=r,this.open=0;let i=n.topNode,o,l=$a(null,n.preserveWhitespace,0)|(r?Ht:0);i?o=new En(i.type,i.attrs,Ie.none,Ie.none,!0,n.topMatch||i.type.contentMatch,l):r?o=new En(null,null,Ie.none,Ie.none,!0,null,l):o=new En(t.schema.topNodeType,null,Ie.none,Ie.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(Kx(n));if(!r)return;let[i,o]=r,l=this.top;for(let c=0;c<o.length;c++)this.removePendingMark(o[c],l);for(let c=0;c<i.length;c++)this.addPendingMark(i[c]);this.addElement(t);for(let c=0;c<i.length;c++)this.removePendingMark(i[c],l);for(let c=0;c<o.length;c++)this.addPendingMark(o[c])}}}addTextNode(t){let n=t.nodeValue,r=this.top;if(r.options&An||r.inlineContext(t)||/[^ \t\r\n\u000c]/.test(n)){if(r.options&zn)r.options&An?n=n.replace(/\r\n?/g,`
129
+ `):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 i=r.content[r.content.length-1],o=t.previousSibling;(!i||o&&o.nodeName=="BR"||i.isText&&/[ \t\r\n\u000c]$/.test(i.text))&&(n=n.slice(1))}n&&this.insertNode(this.parser.schema.text(n)),this.findInText(t)}else this.findInside(t)}addElement(t,n){let r=t.nodeName.toLowerCase(),i;Oa.hasOwnProperty(r)&&this.parser.normalizeLists&&Qx(t);let o=this.options.ruleFromNode&&this.options.ruleFromNode(t)||(i=this.parser.matchTag(t,this,n));if(o?o.ignore:Rx.hasOwnProperty(r))this.findInside(t),this.ignoreFallback(t);else if(!o||o.skip||o.closeParent){o&&o.closeParent?this.open=Math.max(0,this.open-1):o&&o.skip.nodeType&&(t=o.skip);let l,c=this.top,u=this.needsBlock;if(Ba.hasOwnProperty(r))c.content.length&&c.content[0].isInline&&this.open&&(this.open--,c=this.top),l=!0,c.type||(this.needsBlock=!0);else if(!t.firstChild){this.leafFallback(t);return}this.addAll(t),l&&this.sync(c),this.needsBlock=u}else this.addElementByRule(t,o,o.consuming===!1?i:void 0)}leafFallback(t){t.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(t.ownerDocument.createTextNode(`
130
+ `))}ignoreFallback(t){t.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"))}readStyles(t){let n=Ie.none,r=Ie.none;for(let i=0;i<t.length;i+=2)for(let o=void 0;;){let l=this.parser.matchStyle(t[i],t[i+1],this,o);if(!l)break;if(l.ignore)return null;if(l.clearMark?this.top.pendingMarks.concat(this.top.activeMarks).forEach(c=>{l.clearMark(c)&&(r=c.addToSet(r))}):n=this.parser.schema.marks[l.mark].create(l.attrs).addToSet(n),l.consuming===!1)o=l;else break}return[n,r]}addElementByRule(t,n,r){let i,o,l;n.node?(o=this.parser.schema.nodes[n.node],o.isLeaf?this.insertNode(o.create(n.attrs))||this.leafFallback(t):i=this.enter(o,n.attrs||null,n.preserveWhitespace)):(l=this.parser.schema.marks[n.mark].create(n.attrs),this.addPendingMark(l));let c=this.top;if(o&&o.isLeaf)this.findInside(t);else if(r)this.addElement(t,r);else if(n.getContent)this.findInside(t),n.getContent(t,this.parser.schema).forEach(u=>this.insertNode(u));else{let u=t;typeof n.contentElement=="string"?u=t.querySelector(n.contentElement):typeof n.contentElement=="function"?u=n.contentElement(t):n.contentElement&&(u=n.contentElement),this.findAround(t,u,!0),this.addAll(u)}i&&this.sync(c)&&this.open--,l&&this.removePendingMark(l,c)}addAll(t,n,r){let i=n||0;for(let o=n?t.childNodes[n]:t.firstChild,l=r==null?null:t.childNodes[r];o!=l;o=o.nextSibling,++i)this.findAtPoint(t,i),this.addDOM(o);this.findAtPoint(t,i)}findPlace(t){let n,r;for(let i=this.open;i>=0;i--){let o=this.nodes[i],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 i=0;i<n.length;i++)this.enterInner(n[i],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 i=0;i<t.marks.length;i++)(!n.type||n.type.allowsMarkType(t.marks[i].type))&&(r=t.marks[i].addToSet(r));return n.content.push(t.mark(r)),!0}return!1}enter(t,n,r){let i=this.findPlace(t.create(n));return i&&this.enterInner(t,n,!0,r),i}enterInner(t,n=null,r=!1,i){this.closeExtra();let o=this.top;o.applyPending(t),o.match=o.match&&o.match.matchType(t);let l=$a(t,i,o.options);o.options&Ht&&o.content.length==0&&(l|=Ht),this.nodes.push(new En(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 i=r.length-1;i>=0;i--)t+=r[i].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 i=0;i<this.find.length;i++)this.find[i].pos==null&&t.nodeType==1&&t.contains(this.find[i].node)&&n.compareDocumentPosition(this.find[i].node)&(r?2:4)&&(this.find[i].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,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),o=-(r?r.depth+1:0)+(i?0:1),l=(c,u)=>{for(;c>=0;c--){let d=n[c];if(d==""){if(c==n.length-1||c==0)continue;for(;u>=o;u--)if(l(c-1,u))return!0;return!1}else{let h=u>0||u==0&&i?this.nodes[u].type:r&&u>=o?r.node(u-o).type:null;if(!h||h.name!=d&&h.groups.indexOf(d)==-1)return!1;u--}}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=Xx(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 i=this.nodes[r];if(i.pendingMarks.lastIndexOf(t)>-1)i.pendingMarks=t.removeFromSet(i.pendingMarks);else{i.activeMarks=t.removeFromSet(i.activeMarks);let l=i.popFromStashMark(t);l&&i.type&&i.type.allowsMarkType(l.type)&&(i.activeMarks=l.addToSet(i.activeMarks))}if(i==n)break}}}function Qx(e){for(let t=e.firstChild,n=null;t;t=t.nextSibling){let r=t.nodeType==1?t.nodeName.toLowerCase():null;r&&Oa.hasOwnProperty(r)&&n?(n.appendChild(t),t=n):r=="li"?n=t:r&&(n=null)}}function Ux(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function Kx(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 qa(e){let t={};for(let n in e)t[n]=e[n];return t}function Yx(e,t){let n=t.schema.nodes;for(let r in n){let i=n[r];if(!i.allowsMarkType(e))continue;let o=[],l=c=>{o.push(c);for(let u=0;u<c.edgeCount;u++){let{type:d,next:h}=c.edge(u);if(d==t||o.indexOf(h)<0&&l(h))return!0}};if(l(i.contentMatch))return!0}}function Xx(e,t){for(let n=0;n<t.length;n++)if(e.eq(t[n]))return t[n]}const Na=65535,Fa=Math.pow(2,16);function Jx(e,t){return e+t*Fa}function Ga(e){return e&Na}function Zx(e){return(e-(e&Na))/Fa}const Wa=1,Ra=2,Pn=4,Qa=8;class Ua{constructor(t,n,r){this.pos=t,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&Qa)>0}get deletedBefore(){return(this.delInfo&(Wa|Pn))>0}get deletedAfter(){return(this.delInfo&(Ra|Pn))>0}get deletedAcross(){return(this.delInfo&Pn)>0}}class qe{constructor(t,n=!1){if(this.ranges=t,this.inverted=n,!t.length&&qe.empty)return qe.empty}recover(t){let n=0,r=Ga(t);if(!this.inverted)for(let i=0;i<r;i++)n+=this.ranges[i*3+2]-this.ranges[i*3+1];return this.ranges[r*3]+n+Zx(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 i=0,o=this.inverted?2:1,l=this.inverted?1:2;for(let c=0;c<this.ranges.length;c+=3){let u=this.ranges[c]-(this.inverted?i:0);if(u>t)break;let d=this.ranges[c+o],h=this.ranges[c+l],p=u+d;if(t<=p){let x=d?t==u?-1:t==p?1:n:n,m=u+i+(x<0?0:h);if(r)return m;let j=t==(n<0?u:p)?null:Jx(c/3,t-u),C=t==u?Ra:t==p?Wa:Pn;return(n<0?t!=u:t!=p)&&(C|=Qa),new Ua(m,C,j)}i+=h-d}return r?t+i:new Ua(t+i,0,null)}touches(t,n){let r=0,i=Ga(n),o=this.inverted?2:1,l=this.inverted?1:2;for(let c=0;c<this.ranges.length;c+=3){let u=this.ranges[c]-(this.inverted?r:0);if(u>t)break;let d=this.ranges[c+o],h=u+d;if(t<=h&&c==i*3)return!0;r+=this.ranges[c+l]-d}return!1}forEach(t){let n=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i<this.ranges.length;i+=3){let l=this.ranges[i],c=l-(this.inverted?o:0),u=l+(this.inverted?0:o),d=this.ranges[i+n],h=this.ranges[i+r];t(c,c+d,u,u+h),o+=h-d}}invert(){return new qe(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(t){return t==0?qe.empty:new qe(t<0?[0,-t,0]:[0,0,t])}}qe.empty=new qe([]);const Ws=Object.create(null);class De{getMap(){return qe.empty}merge(t){return null}static fromJSON(t,n){if(!n||!n.stepType)throw new RangeError("Invalid input for Step.fromJSON");let r=Ws[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 Ws)throw new RangeError("Duplicate use of step JSON ID "+t);return Ws[t]=n,n.prototype.jsonID=t,n}}class he{constructor(t,n){this.doc=t,this.failed=n}static ok(t){return new he(t,null)}static fail(t){return new he(null,t)}static fromReplace(t,n,r,i){try{return he.ok(t.replace(n,r,i))}catch(o){if(o instanceof Wx)return he.fail(o.message);throw o}}}function Rs(e,t,n){let r=[];for(let i=0;i<e.childCount;i++){let o=e.child(i);o.content.size&&(o=o.copy(Rs(o.content,t,o))),o.isInline&&(o=t(o,n,i)),r.push(o)}return J.fromArray(r)}class vt extends De{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),i=r.node(r.sharedDepth(this.to)),o=new te(Rs(n.content,(l,c)=>!l.isAtom||!c.type.allowsMarkType(this.mark.type)?l:l.mark(this.mark.addToSet(l.marks)),i),n.openStart,n.openEnd);return he.fromReplace(t,this.from,this.to,o)}invert(){return new wt(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 vt(n.pos,r.pos,this.mark)}merge(t){return t instanceof vt&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new vt(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 vt(n.from,n.to,t.markFromJSON(n.mark))}}De.jsonID("addMark",vt);class wt extends De{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 te(Rs(n.content,i=>i.mark(this.mark.removeFromSet(i.marks)),t),n.openStart,n.openEnd);return he.fromReplace(t,this.from,this.to,r)}invert(){return new vt(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 wt(n.pos,r.pos,this.mark)}merge(t){return t instanceof wt&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new wt(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 wt(n.from,n.to,t.markFromJSON(n.mark))}}De.jsonID("removeMark",wt);class Ct extends De{constructor(t,n){super(),this.pos=t,this.mark=n}apply(t){let n=t.nodeAt(this.pos);if(!n)return he.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return he.fromReplace(t,this.pos,this.pos+1,new te(J.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 i=0;i<n.marks.length;i++)if(!n.marks[i].isInSet(r))return new Ct(this.pos,n.marks[i]);return new Ct(this.pos,this.mark)}}return new en(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new Ct(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 Ct(n.pos,t.markFromJSON(n.mark))}}De.jsonID("addNodeMark",Ct);class en extends De{constructor(t,n){super(),this.pos=t,this.mark=n}apply(t){let n=t.nodeAt(this.pos);if(!n)return he.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.removeFromSet(n.marks));return he.fromReplace(t,this.pos,this.pos+1,new te(J.from(r),0,n.isLeaf?0:1))}invert(t){let n=t.nodeAt(this.pos);return!n||!this.mark.isInSet(n.marks)?this:new Ct(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new en(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 en(n.pos,t.markFromJSON(n.mark))}}De.jsonID("removeNodeMark",en);class Xe extends De{constructor(t,n,r,i=!1){super(),this.from=t,this.to=n,this.slice=r,this.structure=i}apply(t){return this.structure&&Qs(t,this.from,this.to)?he.fail("Structure replace would overwrite content"):he.fromReplace(t,this.from,this.to,this.slice)}getMap(){return new qe([this.from,this.to-this.from,this.slice.size])}invert(t){return new Xe(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 Xe(n.pos,Math.max(n.pos,r.pos),this.slice)}merge(t){if(!(t instanceof Xe)||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?te.empty:new te(this.slice.content.append(t.slice.content),this.slice.openStart,t.slice.openEnd);return new Xe(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?te.empty:new te(t.slice.content.append(this.slice.content),t.slice.openStart,this.slice.openEnd);return new Xe(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 Xe(n.from,n.to,te.fromJSON(t,n.slice),!!n.structure)}}De.jsonID("replace",Xe);class St extends De{constructor(t,n,r,i,o,l,c=!1){super(),this.from=t,this.to=n,this.gapFrom=r,this.gapTo=i,this.slice=o,this.insert=l,this.structure=c}apply(t){if(this.structure&&(Qs(t,this.from,this.gapFrom)||Qs(t,this.gapTo,this.to)))return he.fail("Structure gap-replace would overwrite content");let n=t.slice(this.gapFrom,this.gapTo);if(n.openStart||n.openEnd)return he.fail("Gap is not a flat range");let r=this.slice.insertAt(this.insert,n.content);return r?he.fromReplace(t,this.from,this.to,r):he.fail("Content does not fit in gap")}getMap(){return new qe([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 St(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),i=t.map(this.gapFrom,-1),o=t.map(this.gapTo,1);return n.deletedAcross&&r.deletedAcross||i<n.pos||o>r.pos?null:new St(n.pos,r.pos,i,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 St(n.from,n.to,n.gapFrom,n.gapTo,te.fromJSON(t,n.slice),n.insert,!!n.structure)}}De.jsonID("replaceAround",St);function Qs(e,t,n){let r=e.resolve(t),i=n-t,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let l=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!l||l.isLeaf)return!0;l=l.firstChild,i--}}return!1}function Hx(e,t,n){return(t==0||e.canReplace(t,e.childCount))&&(n==e.childCount||e.canReplace(0,n))}function ef(e){let n=e.parent.content.cutByIndex(e.startIndex,e.endIndex);for(let r=e.depth;;--r){let i=e.$from.node(r),o=e.$from.index(r),l=e.$to.indexAfter(r);if(r<e.depth&&i.canReplace(o,l,n))return r;if(r==0||i.type.spec.isolating||!Hx(i,o,l))break}return null}function Ln(e,t,n=1,r){let i=e.resolve(t),o=i.depth-n,l=r&&r[r.length-1]||i.parent;if(o<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!l.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let d=i.depth-1,h=n-2;d>o;d--,h--){let p=i.node(d),x=i.index(d);if(p.type.spec.isolating)return!1;let m=p.content.cutByIndex(x,p.childCount),j=r&&r[h+1];j&&(m=m.replaceChild(0,j.type.create(j.attrs)));let C=r&&r[h]||p;if(!p.canReplace(x+1,p.childCount)||!C.type.validContent(m))return!1}let c=i.indexAfter(o),u=r&&r[0];return i.node(o).canReplaceWith(c,c,u?u.type:i.node(o+1).type)}function Ka(e,t){let n=e.resolve(t),r=n.index();return tf(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function tf(e,t){return!!(e&&t&&!e.isLeaf&&e.canAppend(t))}class tn extends De{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 he.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 i=n.type.create(r,null,n.marks);return he.fromReplace(t,this.pos,this.pos+1,new te(J.from(i),0,n.isLeaf?0:1))}getMap(){return qe.empty}invert(t){return new tn(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 tn(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 tn(n.pos,n.attr,n.value)}}De.jsonID("attr",tn);let nn=class extends Error{};nn=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n},nn.prototype=Object.create(Error.prototype),nn.prototype.constructor=nn,nn.prototype.name="TransformError";const Us=Object.create(null);class ie{constructor(t,n,r){this.$anchor=t,this.$head=n,this.ranges=r||[new nf(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=te.empty){let r=n.content.lastChild,i=null;for(let c=0;c<n.openEnd;c++)i=r,r=r.lastChild;let o=t.steps.length,l=this.ranges;for(let c=0;c<l.length;c++){let{$from:u,$to:d}=l[c],h=t.mapping.slice(o);t.replaceRange(h.map(u.pos),h.map(d.pos),c?te.empty:n),c==0&&Ja(t,o,(r?r.isInline:i&&i.isTextblock)?-1:1)}}replaceWith(t,n){let r=t.steps.length,i=this.ranges;for(let o=0;o<i.length;o++){let{$from:l,$to:c}=i[o],u=t.mapping.slice(r),d=u.map(l.pos),h=u.map(c.pos);o?t.deleteRange(d,h):(t.replaceRangeWith(d,h,n),Ja(t,r,n.isInline?-1:1))}}static findFrom(t,n,r=!1){let i=t.parent.inlineContent?new xe(t):Lt(t.node(0),t.parent,t.pos,t.index(),n,r);if(i)return i;for(let o=t.depth-1;o>=0;o--){let l=n<0?Lt(t.node(0),t.node(o),t.before(o+1),t.index(o),n,r):Lt(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 it(t.node(0))}static atStart(t){return Lt(t,t,0,0,1)||new it(t)}static atEnd(t){return Lt(t,t,t.content.size,t.childCount,-1)||new it(t)}static fromJSON(t,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=Us[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 Us)throw new RangeError("Duplicate use of selection JSON ID "+t);return Us[t]=n,n.prototype.jsonID=t,n}getBookmark(){return xe.between(this.$anchor,this.$head).getBookmark()}}ie.prototype.visible=!0;class nf{constructor(t,n){this.$from=t,this.$to=n}}let Ya=!1;function Xa(e){!Ya&&!e.parent.inlineContent&&(Ya=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+e.parent.type.name+")"))}class xe extends ie{constructor(t,n=t){Xa(t),Xa(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 ie.near(r);let i=t.resolve(n.map(this.anchor));return new xe(i.parent.inlineContent?i:r,r)}replace(t,n=te.empty){if(super.replace(t,n),n==te.empty){let r=this.$from.marksAcross(this.$to);r&&t.ensureMarks(r)}}eq(t){return t instanceof xe&&t.anchor==this.anchor&&t.head==this.head}getBookmark(){return new Bn(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 xe(t.resolve(n.anchor),t.resolve(n.head))}static create(t,n,r=n){let i=t.resolve(n);return new this(i,r==n?i:t.resolve(r))}static between(t,n,r){let i=t.pos-n.pos;if((!r||i)&&(r=i>=0?1:-1),!n.parent.inlineContent){let o=ie.findFrom(n,r,!0)||ie.findFrom(n,-r,!0);if(o)n=o.$head;else return ie.near(n,r)}return t.parent.inlineContent||(i==0?t=n:(t=(ie.findFrom(t,-r,!0)||ie.findFrom(t,r,!0)).$anchor,t.pos<n.pos!=i<0&&(t=n))),new xe(t,n)}}ie.jsonID("text",xe);class Bn{constructor(t,n){this.anchor=t,this.head=n}map(t){return new Bn(t.map(this.anchor),t.map(this.head))}resolve(t){return xe.between(t.resolve(this.anchor),t.resolve(this.head))}}class Me extends ie{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:i}=n.mapResult(this.anchor),o=t.resolve(i);return r?ie.near(o):new Me(o)}content(){return new te(J.from(this.node),0,0)}eq(t){return t instanceof Me&&t.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new Ks(this.anchor)}static fromJSON(t,n){if(typeof n.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new Me(t.resolve(n.anchor))}static create(t,n){return new Me(t.resolve(n))}static isSelectable(t){return!t.isText&&t.type.spec.selectable!==!1}}Me.prototype.visible=!1,ie.jsonID("node",Me);class Ks{constructor(t){this.anchor=t}map(t){let{deleted:n,pos:r}=t.mapResult(this.anchor);return n?new Bn(r,r):new Ks(r)}resolve(t){let n=t.resolve(this.anchor),r=n.nodeAfter;return r&&Me.isSelectable(r)?new Me(n):ie.near(n)}}class it extends ie{constructor(t){super(t.resolve(0),t.resolve(t.content.size))}replace(t,n=te.empty){if(n==te.empty){t.delete(0,t.doc.content.size);let r=ie.atStart(t.doc);r.eq(t.selection)||t.setSelection(r)}else super.replace(t,n)}toJSON(){return{type:"all"}}static fromJSON(t){return new it(t)}map(t){return new it(t)}eq(t){return t instanceof it}getBookmark(){return sf}}ie.jsonID("all",it);const sf={map(){return this},resolve(e){return new it(e)}};function Lt(e,t,n,r,i,o=!1){if(t.inlineContent)return xe.create(e,n);for(let l=r-(i>0?0:1);i>0?l<t.childCount:l>=0;l+=i){let c=t.child(l);if(c.isAtom){if(!o&&Me.isSelectable(c))return Me.create(e,n-(i<0?c.nodeSize:0))}else{let u=Lt(e,c,n+i,i<0?c.childCount:0,i,o);if(u)return u}n+=c.nodeSize*i}return null}function Ja(e,t,n){let r=e.steps.length-1;if(r<t)return;let i=e.steps[r];if(!(i instanceof Xe||i instanceof St))return;let o=e.mapping.maps[r],l;o.forEach((c,u,d,h)=>{l==null&&(l=h)}),e.setSelection(ie.near(e.doc.resolve(l),n))}function Za(e,t){return!t||!e?e:e.bind(t)}class On{constructor(t,n,r){this.name=t,this.init=Za(n.init,r),this.apply=Za(n.apply,r)}}new On("doc",{init(e){return e.doc||e.schema.topNodeType.createAndFill()},apply(e){return e.doc}}),new On("selection",{init(e,t){return e.selection||ie.atStart(t.doc)},apply(e){return e.selection}}),new On("storedMarks",{init(e){return e.storedMarks||null},apply(e,t,n,r){return r.selection.$cursor?e.storedMarks:null}}),new On("scrollToSelection",{init(){return 0},apply(e,t){return e.scrolledIntoView?t+1:t}});function Ha(e,t,n){for(let r in e){let i=e[r];i instanceof Function?i=i.bind(t):r=="handleDOMEvents"&&(i=Ha(i,t,{})),n[r]=i}return n}class sn{constructor(t){this.spec=t,this.props={},t.props&&Ha(t.props,this,this.props),this.key=t.key?t.key.key:eo("plugin")}getState(t){return t[this.key]}}const Ys=Object.create(null);function eo(e){return e in Ys?e+"$"+ ++Ys[e]:(Ys[e]=0,e+"$")}class rn{constructor(t="key"){this.key=eo(t)}get(t){return t.config.pluginsByKey[this.key]}getState(t){return t[this.key]}}function to(e){const{state:t,transaction:n}=e;let{selection:r}=n,{doc:i}=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 i},get tr(){return r=n.selection,i=n.doc,o=n.storedMarks,n}}}class rf{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:i}=n,{tr:o}=r,l=this.buildProps(o);return Object.fromEntries(Object.entries(t).map(([c,u])=>[c,(...h)=>{const p=u(...h)(l);return!o.getMeta("preventDispatch")&&!this.hasCustomState&&i.dispatch(o),p}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(t,n=!0){const{rawCommands:r,editor:i,state:o}=this,{view:l}=i,c=[],u=!!t,d=t||o.tr,h=()=>(!u&&n&&!d.getMeta("preventDispatch")&&!this.hasCustomState&&l.dispatch(d),c.every(x=>x===!0)),p={...Object.fromEntries(Object.entries(r).map(([x,m])=>[x,(...C)=>{const T=this.buildProps(d,n),D=m(...C)(T);return c.push(D),p}])),run:h};return p}createCan(t){const{rawCommands:n,state:r}=this,i=!1,o=t||r.tr,l=this.buildProps(o,i);return{...Object.fromEntries(Object.entries(n).map(([u,d])=>[u,(...h)=>d(...h)({...l,dispatch:void 0})])),chain:()=>this.createChain(o,i)}}buildProps(t,n=!0){const{rawCommands:r,editor:i,state:o}=this,{view:l}=i;o.storedMarks&&t.setStoredMarks(o.storedMarks);const c={tr:t,editor:i,view:l,state:to({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(([u,d])=>[u,(...h)=>d(...h)(c)]))}};return c}}function ft(e,t,n){return e.config[t]===void 0&&e.parent?ft(e.parent,t,n):typeof e.config[t]=="function"?e.config[t].bind({...n,parent:e.parent?ft(e.parent,t,n):null}):e.config[t]}function af(e){const t=e.filter(i=>i.type==="extension"),n=e.filter(i=>i.type==="node"),r=e.filter(i=>i.type==="mark");return{baseExtensions:t,nodeExtensions:n,markExtensions:r}}function ve(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 of(e){return typeof e=="function"}function Bt(e,t=void 0,...n){return of(e)?t?e.bind(t)(...n):e(...n):e}function lf(e){return Object.prototype.toString.call(e)==="[object RegExp]"}function cf(e){return Object.prototype.toString.call(e).slice(8,-1)}function Xs(e){return cf(e)!=="Object"?!1:e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype}function no(e,t){const n={...e};return Xs(e)&&Xs(t)&&Object.keys(t).forEach(r=>{Xs(t[r])?r in e?n[r]=no(e[r],t[r]):Object.assign(n,{[r]:t[r]}):Object.assign(n,{[r]:t[r]})}),n}class Je{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=Bt(ft(this,"addOptions",{name:this.name}))),this.storage=Bt(ft(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(t={}){return new Je(t)}configure(t={}){const n=this.extend();return n.options=no(this.options,t),n.storage=Bt(ft(n,"addStorage",{name:n.name,options:n.options})),n}extend(t={}){const n=new Je(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=Bt(ft(n,"addOptions",{name:n.name})),n.storage=Bt(ft(n,"addStorage",{name:n.name,options:n.options})),n}}function uf(e,t,n){const{from:r,to:i}=t,{blockSeparator:o=`
131
131
 
132
- `,textSerializers:l={}}=n||{};let u="",c=!0;return e.nodesBetween(r,i,(d,h,p,x)=>{var m;const j=l==null?void 0:l[d.type.name];j?(d.isBlock&&!c&&(u+=o,c=!0),p&&(u+=j({node:d,pos:h,parent:p,index:x,range:t}))):d.isText?(u+=(m=d==null?void 0:d.text)===null||m===void 0?void 0:m.slice(Math.max(r,h)-h,i-h),c=!1):d.isBlock&&!c&&(u+=o,c=!0)}),u}function cf(e){return Object.fromEntries(Object.entries(e.nodes).filter(([,t])=>t.spec.toText).map(([t,n])=>[t,n.spec.toText]))}et.create({name:"clipboardTextSerializer",addProseMirrorPlugins(){return[new rn({key:new an("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:e}=this,{state:t,schema:n}=e,{doc:r,selection:i}=t,{ranges:o}=i,l=Math.min(...o.map(h=>h.$from.pos)),u=Math.max(...o.map(h=>h.$to.pos)),c=cf(n);return uf(r,{from:l,to:u},{textSerializers:c})}}})]}});const df=()=>({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),pf=(e=!1)=>({commands:t})=>t.setContent("",e),hf=()=>({state:e,tr:t,dispatch:n})=>{const{selection:r}=t,{ranges:i}=r;return n&&i.forEach(({$from:o,$to:l})=>{e.doc.nodesBetween(o.pos,l.pos,(u,c)=>{if(u.type.isText)return;const{doc:d,mapping:h}=t,p=d.resolve(h.map(c)),x=d.resolve(h.map(c+u.nodeSize)),m=p.blockRange(x);if(!m)return;const j=Hx(m);if(u.type.isTextblock){const{defaultType:C}=p.parent.contentMatchAt(p.index());t.setNodeMarkup(m.start,C)}(j||j===0)&&t.lift(m,j)})}),!0},xf=e=>t=>e(t),ff=()=>({state:e,dispatch:t})=>be.createParagraphNear(e,t),gf=()=>({tr:e,dispatch:t})=>{const{selection:n}=e,r=n.$anchor.node();if(r.content.size>0)return!1;const i=e.selection.$anchor;for(let o=i.depth;o>0;o-=1)if(i.node(o).type===r.type){if(t){const u=i.before(o),c=i.after(o);e.delete(u,c).scrollIntoView()}return!0}return!1},mf=e=>({tr:t,state:n,dispatch:r})=>{const i=Ce(e,n.schema),o=t.selection.$anchor;for(let l=o.depth;l>0;l-=1)if(o.node(l).type===i){if(r){const c=o.before(l),d=o.after(l);t.delete(c,d).scrollIntoView()}return!0}return!1},yf=e=>({tr:t,dispatch:n})=>{const{from:r,to:i}=e;return n&&t.delete(r,i),!0},bf=()=>({state:e,dispatch:t})=>be.deleteSelection(e,t),jf=()=>({commands:e})=>e.keyboardShortcut("Enter"),vf=()=>({state:e,dispatch:t})=>be.exitCode(e,t);function Vn(e,t,n={strict:!0}){const r=Object.keys(t);return r.length?r.every(i=>n.strict?t[i]===e[i]:of(t[i])?t[i].test(e[i]):t[i]===e[i]):!0}function Zs(e,t,n={}){return e.find(r=>r.type===t&&Vn(r.attrs,n))}function wf(e,t,n={}){return!!Zs(e,t,n)}function no(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 i=Zs([...r.node.marks],t,n);if(!i)return;let o=r.index,l=e.start()+r.offset,u=o+1,c=l+r.node.nodeSize;for(Zs([...r.node.marks],t,n);o>0&&i.isInSet(e.parent.child(o-1).marks);)o-=1,l-=e.parent.child(o).nodeSize;for(;u<e.parent.childCount&&wf([...e.parent.child(u).marks],t,n);)c+=e.parent.child(u).nodeSize,u+=1;return{from:l,to:c}}function mt(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 Cf=(e,t={})=>({tr:n,state:r,dispatch:i})=>{const o=mt(e,r.schema),{doc:l,selection:u}=n,{$from:c,from:d,to:h}=u;if(i){const p=no(c,o,t);if(p&&p.from<=d&&p.to>=h){const x=me.create(l,p.from,p.to);n.setSelection(x)}}return!0},Sf=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 so(e){return e instanceof me}function kt(e=0,t=0,n=0){return Math.min(Math.max(e,t),n)}function _f(e,t=null){if(!t)return null;const n=le.atStart(e),r=le.atEnd(e);if(t==="start"||t===!0)return n;if(t==="end")return r;const i=n.from,o=r.to;return t==="all"?me.create(e,kt(0,i,o),kt(e.content.size,i,o)):me.create(e,kt(t,i,o),kt(t,i,o))}function Hs(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}const kf=(e=null,t={})=>({editor:n,view:r,tr:i,dispatch:o})=>{t={scrollIntoView:!0,...t};const l=()=>{Hs()&&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&&!so(n.state.selection))return l(),!0;const u=_f(i.doc,e)||n.state.selection,c=n.state.selection.eq(u);return o&&(c||i.setSelection(u),c&&i.storedMarks&&i.setStoredMarks(i.storedMarks),l()),!0},Tf=(e,t)=>n=>e.every((r,i)=>t(r,{...n,index:i})),Df=(e,t)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},e,t);function ro(e){const t=`<body>${e}</body>`;return new window.DOMParser().parseFromString(t,"text/html").body}function qn(e,t,n){if(n={slice:!0,parseOptions:{},...n},typeof e=="object"&&e!==null)try{return Array.isArray(e)&&e.length>0?H.fromArray(e.map(r=>t.nodeFromJSON(r))):t.nodeFromJSON(e)}catch(r){return console.warn("[tiptap warn]: Invalid content.","Passed value:",e,"Error:",r),qn("",t,n)}if(typeof e=="string"){const r=zn.fromSchema(t);return n.slice?r.parseSlice(ro(e),n.parseOptions).content:r.parse(ro(e),n.parseOptions)}return qn("",t,n)}function If(e,t,n){const r=e.steps.length-1;if(r<t)return;const i=e.steps[r];if(!(i instanceof He||i instanceof _t))return;const o=e.mapping.maps[r];let l=0;o.forEach((u,c,d,h)=>{l===0&&(l=h)}),e.setSelection(le.near(e.doc.resolve(l),n))}const Mf=e=>e.toString().startsWith("<"),zf=(e,t,n)=>({tr:r,dispatch:i,editor:o})=>{if(i){n={parseOptions:{},updateSelection:!0,...n};const l=qn(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,h=!0;if((Mf(l)?l:[l]).forEach(x=>{x.check(),d=d?x.isText&&x.marks.length===0:!1,h=h?x.isBlock:!1}),u===c&&h){const{parent:x}=r.doc.resolve(u);x.isTextblock&&!x.type.spec.code&&!x.childCount&&(u-=1,c+=1)}d?Array.isArray(t)?r.insertText(t.map(x=>x.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&&If(r,r.steps.length-1,-1)}return!0},Af=()=>({state:e,dispatch:t})=>be.joinUp(e,t),Ef=()=>({state:e,dispatch:t})=>be.joinDown(e,t),Lf=()=>({state:e,dispatch:t})=>be.joinBackward(e,t),Pf=()=>({state:e,dispatch:t})=>be.joinForward(e,t);function io(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function Bf(e){const t=e.split(/-(?!$)/);let n=t[t.length-1];n==="Space"&&(n=" ");let r,i,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))i=!0;else if(/^s(hift)?$/i.test(c))o=!0;else if(/^mod$/i.test(c))Hs()||io()?l=!0:i=!0;else throw new Error(`Unrecognized modifier name: ${c}`)}return r&&(n=`Alt-${n}`),i&&(n=`Ctrl-${n}`),l&&(n=`Meta-${n}`),o&&(n=`Shift-${n}`),n}const Of=e=>({editor:t,view:n,tr:r,dispatch:i})=>{const o=Bf(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 h=d.map(r.mapping);h&&i&&r.maybeStep(h)}),!0};function er(e,t,n={}){const{from:r,to:i,empty:o}=e.selection,l=t?Ce(t,e.schema):null,u=[];e.doc.nodesBetween(r,i,(p,x)=>{if(p.isText)return;const m=Math.max(r,x),j=Math.min(i,x+p.nodeSize);u.push({node:p,from:m,to:j})});const c=i-r,d=u.filter(p=>l?l.name===p.node.type.name:!0).filter(p=>Vn(p.node.attrs,n,{strict:!1}));return o?!!d.length:d.reduce((p,x)=>p+x.to-x.from,0)>=c}const $f=(e,t={})=>({state:n,dispatch:r})=>{const i=Ce(e,n.schema);return er(n,i,t)?be.lift(n,r):!1},Vf=()=>({state:e,dispatch:t})=>be.liftEmptyBlock(e,t),qf=e=>({state:t,dispatch:n})=>{const r=Ce(e,t.schema);return ps.liftListItem(r)(t,n)},Nf=()=>({state:e,dispatch:t})=>be.newlineInCode(e,t);function ao(e,t){return t.nodes[e]?"node":t.marks[e]?"mark":null}function oo(e,t){const n=typeof t=="string"?[t]:t;return Object.keys(e).reduce((r,i)=>(n.includes(i)||(r[i]=e[i]),r),{})}const Ff=(e,t)=>({tr:n,state:r,dispatch:i})=>{let o=null,l=null;const u=ao(typeof e=="string"?e:e.name,r.schema);return u?(u==="node"&&(o=Ce(e,r.schema)),u==="mark"&&(l=mt(e,r.schema)),i&&n.selection.ranges.forEach(c=>{r.doc.nodesBetween(c.$from.pos,c.$to.pos,(d,h)=>{o&&o===d.type&&n.setNodeMarkup(h,void 0,oo(d.attrs,t)),l&&d.marks.length&&d.marks.forEach(p=>{l===p.type&&n.addMark(h,h+d.nodeSize,l.create(oo(p.attrs,t)))})})}),!0):!1},Gf=()=>({tr:e,dispatch:t})=>(t&&e.scrollIntoView(),!0),Wf=()=>({tr:e,commands:t})=>t.setTextSelection({from:0,to:e.doc.content.size}),Rf=()=>({state:e,dispatch:t})=>be.selectNodeBackward(e,t),Qf=()=>({state:e,dispatch:t})=>be.selectNodeForward(e,t),Uf=()=>({state:e,dispatch:t})=>be.selectParentNode(e,t),Kf=()=>({state:e,dispatch:t})=>be.selectTextblockEnd(e,t),Yf=()=>({state:e,dispatch:t})=>be.selectTextblockStart(e,t);function Xf(e,t,n={}){return qn(e,t,{slice:!1,parseOptions:n})}const Jf=(e,t=!1,n={})=>({tr:r,editor:i,dispatch:o})=>{const{doc:l}=r,u=Xf(e,i.schema,n);return o&&r.replaceWith(0,l.content.size,u).setMeta("preventUpdate",!t),!0};function Zf(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 Hf(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 tr(e){return t=>Hf(t.$from,e)}function eg(e,t){const n=mt(t,e.schema),{from:r,to:i,empty:o}=e.selection,l=[];o?(e.storedMarks&&l.push(...e.storedMarks),l.push(...e.selection.$head.marks())):e.doc.nodesBetween(r,i,c=>{l.push(...c.marks)});const u=l.find(c=>c.type.name===n.name);return u?{...u.attrs}:{}}function Nn(e,t,n){return Object.fromEntries(Object.entries(n).filter(([r])=>{const i=e.find(o=>o.type===t&&o.name===r);return i?i.attribute.keepOnSplit:!1}))}function tg(e,t,n={}){const{empty:r,ranges:i}=e.selection,o=t?mt(t,e.schema):null;if(r)return!!(e.storedMarks||e.selection.$from.marks()).filter(p=>o?o.name===p.type.name:!0).find(p=>Vn(p.attrs,n,{strict:!1}));let l=0;const u=[];if(i.forEach(({$from:p,$to:x})=>{const m=p.pos,j=x.pos;e.doc.nodesBetween(m,j,(C,T)=>{if(!C.isText&&!C.marks.length)return;const D=Math.max(m,T),A=Math.min(j,T+C.nodeSize),F=A-D;l+=F,u.push(...C.marks.map(X=>({mark:X,from:D,to:A})))})}),l===0)return!1;const c=u.filter(p=>o?o.name===p.mark.type.name:!0).filter(p=>Vn(p.mark.attrs,n,{strict:!1})).reduce((p,x)=>p+x.to-x.from,0),d=u.filter(p=>o?p.mark.type!==o&&p.mark.type.excludes(o):!0).reduce((p,x)=>p+x.to-x.from,0);return(c>0?c+d:c)>=l}function lo(e,t){const{nodeExtensions:n}=rf(t),r=n.find(l=>l.name===e);if(!r)return!1;const i={name:r.name,options:r.options,storage:r.storage},o=Ot(gt(r,"group",i));return typeof o!="string"?!1:o.split(" ").includes("list")}function ng(e,t,n){var r;const{selection:i}=t;let o=null;if(so(i)&&(o=i.$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}=i;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,(h,p,x)=>{if(d)return!1;if(h.isInline){const m=!x||x.type.allowsMarkType(n),j=!!n.isInSet(h.marks)||!h.marks.some(C=>C.type.excludes(n));d=m&&j}return!d}),d})}const sg=(e,t={})=>({tr:n,state:r,dispatch:i})=>{const{selection:o}=n,{empty:l,ranges:u}=o,c=mt(e,r.schema);if(i)if(l){const d=eg(r,c);n.addStoredMark(c.create({...d,...t}))}else u.forEach(d=>{const h=d.$from.pos,p=d.$to.pos;r.doc.nodesBetween(h,p,(x,m)=>{const j=Math.max(m,h),C=Math.min(m+x.nodeSize,p);x.marks.find(D=>D.type===c)?x.marks.forEach(D=>{c===D.type&&n.addMark(j,C,c.create({...D.attrs,...t}))}):n.addMark(j,C,c.create(t))})});return ng(r,n,c)},rg=(e,t)=>({tr:n})=>(n.setMeta(e,t),!0),ig=(e,t={})=>({state:n,dispatch:r,chain:i})=>{const o=Ce(e,n.schema);return o.isTextblock?i().command(({commands:l})=>be.setBlockType(o,t)(n)?!0:l.clearNodes()).command(({state:l})=>be.setBlockType(o,t)(l,r)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},ag=e=>({tr:t,dispatch:n})=>{if(n){const{doc:r}=t,i=kt(e,0,r.content.size),o=Ee.create(r,i);t.setSelection(o)}return!0},og=e=>({tr:t,dispatch:n})=>{if(n){const{doc:r}=t,{from:i,to:o}=typeof e=="number"?{from:e,to:e}:e,l=me.atStart(r).from,u=me.atEnd(r).to,c=kt(i,l,u),d=kt(o,l,u),h=me.create(r,c,d);t.setSelection(h)}return!0},lg=e=>({state:t,dispatch:n})=>{const r=Ce(e,t.schema);return ps.sinkListItem(r)(t,n)};function uo(e,t){const n=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();if(n){const r=n.filter(i=>t==null?void 0:t.includes(i.type.name));e.tr.ensureMarks(r)}}const ug=({keepMarks:e=!0}={})=>({tr:t,state:n,dispatch:r,editor:i})=>{const{selection:o,doc:l}=t,{$from:u,$to:c}=o,d=i.extensionManager.attributes,h=Nn(d,u.node().type.name,u.node().attrs);if(o instanceof Ee&&o.node.isBlock)return!u.parentOffset||!Bn(l,u.pos)?!1:(r&&(e&&uo(n,i.extensionManager.splittableMarks),t.split(u.pos).scrollIntoView()),!0);if(!u.parent.isBlock)return!1;if(r){const p=c.parentOffset===c.parent.content.size;o instanceof me&&t.deleteSelection();const x=u.depth===0?void 0:Zf(u.node(-1).contentMatchAt(u.indexAfter(-1)));let m=p&&x?[{type:x,attrs:h}]:void 0,j=Bn(t.doc,t.mapping.map(u.pos),1,m);if(!m&&!j&&Bn(t.doc,t.mapping.map(u.pos),1,x?[{type:x}]:void 0)&&(j=!0,m=x?[{type:x,attrs:h}]:void 0),j&&(t.split(t.mapping.map(u.pos),1,m),x&&!p&&!u.parentOffset&&u.parent.type!==x)){const C=t.mapping.map(u.before()),T=t.doc.resolve(C);u.node(-1).canReplaceWith(T.index(),T.index()+1,x)&&t.setNodeMarkup(t.mapping.map(u.before()),x)}e&&uo(n,i.extensionManager.splittableMarks),t.scrollIntoView()}return!0},cg=e=>({tr:t,state:n,dispatch:r,editor:i})=>{var o;const l=Ce(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 h=u.node(-1);if(h.type!==l)return!1;const p=i.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 T=H.empty;const D=u.index(-1)?1:u.index(-2)?2:3;for(let ee=u.depth-D;ee>=u.depth-3;ee-=1)T=H.from(u.node(ee).copy(T));const A=u.indexAfter(-1)<u.node(-2).childCount?1:u.indexAfter(-2)<u.node(-3).childCount?2:3,F=Nn(p,u.node().type.name,u.node().attrs),X=((o=l.contentMatch.defaultType)===null||o===void 0?void 0:o.createAndFill(F))||void 0;T=T.append(H.from(l.createAndFill(null,X)||void 0));const Q=u.before(u.depth-(D-1));t.replace(Q,u.after(-A),new se(T,4-D,0));let G=-1;t.doc.nodesBetween(Q,t.doc.content.size,(ee,ae)=>{if(G>-1)return!1;ee.isTextblock&&ee.content.size===0&&(G=ae+1)}),G>-1&&t.setSelection(me.near(t.doc.resolve(G))),t.scrollIntoView()}return!0}const x=c.pos===u.end()?h.contentMatchAt(0).defaultType:null,m=Nn(p,h.type.name,h.attrs),j=Nn(p,u.node().type.name,u.node().attrs);t.delete(u.pos,c.pos);const C=x?[{type:l,attrs:m},{type:x,attrs:j}]:[{type:l,attrs:m}];if(!Bn(t.doc,u.pos,2))return!1;if(r){const{selection:T,storedMarks:D}=n,{splittableMarks:A}=i.extensionManager,F=D||T.$to.parentOffset&&T.$from.marks();if(t.split(u.pos,2,C).scrollIntoView(),!F||!r)return!0;const X=F.filter(Q=>A.includes(Q.type.name));t.ensureMarks(X)}return!0},nr=(e,t)=>{const n=tr(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 i=e.doc.nodeAt(r);return n.node.type===(i==null?void 0:i.type)&&Ua(e.doc,n.pos)&&e.join(n.pos),!0},sr=(e,t)=>{const n=tr(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 i=e.doc.nodeAt(r);return n.node.type===(i==null?void 0:i.type)&&Ua(e.doc,r)&&e.join(r),!0};var dg=Object.freeze({__proto__:null,blur:df,clearContent:pf,clearNodes:hf,command:xf,createParagraphNear:ff,deleteCurrentNode:gf,deleteNode:mf,deleteRange:yf,deleteSelection:bf,enter:jf,exitCode:vf,extendMarkRange:Cf,first:Sf,focus:kf,forEach:Tf,insertContent:Df,insertContentAt:zf,joinUp:Af,joinDown:Ef,joinBackward:Lf,joinForward:Pf,keyboardShortcut:Of,lift:$f,liftEmptyBlock:Vf,liftListItem:qf,newlineInCode:Nf,resetAttributes:Ff,scrollIntoView:Gf,selectAll:Wf,selectNodeBackward:Rf,selectNodeForward:Qf,selectParentNode:Uf,selectTextblockEnd:Kf,selectTextblockStart:Yf,setContent:Jf,setMark:sg,setMeta:rg,setNode:ig,setNodeSelection:ag,setTextSelection:og,sinkListItem:lg,splitBlock:ug,splitListItem:cg,toggleList:(e,t,n,r={})=>({editor:i,tr:o,state:l,dispatch:u,chain:c,commands:d,can:h})=>{const{extensions:p,splittableMarks:x}=i.extensionManager,m=Ce(e,l.schema),j=Ce(t,l.schema),{selection:C,storedMarks:T}=l,{$from:D,$to:A}=C,F=D.blockRange(A),X=T||C.$to.parentOffset&&C.$from.marks();if(!F)return!1;const Q=tr(G=>lo(G.type.name,p))(C);if(F.depth>=1&&Q&&F.depth-Q.depth<=1){if(Q.node.type===m)return d.liftListItem(j);if(lo(Q.node.type.name,p)&&m.validContent(Q.node.content)&&u)return c().command(()=>(o.setNodeMarkup(Q.pos,m),!0)).command(()=>nr(o,m)).command(()=>sr(o,m)).run()}return!n||!X||!u?c().command(()=>h().wrapInList(m,r)?!0:d.clearNodes()).wrapInList(m,r).command(()=>nr(o,m)).command(()=>sr(o,m)).run():c().command(()=>{const G=h().wrapInList(m,r),ee=X.filter(ae=>x.includes(ae.type.name));return o.ensureMarks(ee),G?!0:d.clearNodes()}).wrapInList(m,r).command(()=>nr(o,m)).command(()=>sr(o,m)).run()},toggleMark:(e,t={},n={})=>({state:r,commands:i})=>{const{extendEmptyMarkRange:o=!1}=n,l=mt(e,r.schema);return tg(r,l,t)?i.unsetMark(l,{extendEmptyMarkRange:o}):i.setMark(l,t)},toggleNode:(e,t,n={})=>({state:r,commands:i})=>{const o=Ce(e,r.schema),l=Ce(t,r.schema);return er(r,o,n)?i.setNode(l):i.setNode(o,n)},toggleWrap:(e,t={})=>({state:n,commands:r})=>{const i=Ce(e,n.schema);return er(n,i,t)?r.lift(i):r.wrapIn(i,t)},undoInputRule:()=>({state:e,dispatch:t})=>{const n=e.plugins;for(let r=0;r<n.length;r+=1){const i=n[r];let o;if(i.spec.isInputRules&&(o=i.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:i}=n;return r||t&&i.forEach(o=>{e.removeMark(o.$from.pos,o.$to.pos)}),!0},unsetMark:(e,t={})=>({tr:n,state:r,dispatch:i})=>{var o;const{extendEmptyMarkRange:l=!1}=t,{selection:u}=n,c=mt(e,r.schema),{$from:d,empty:h,ranges:p}=u;if(!i)return!0;if(h&&l){let{from:x,to:m}=u;const j=(o=d.marks().find(T=>T.type===c))===null||o===void 0?void 0:o.attrs,C=no(d,c,j);C&&(x=C.from,m=C.to),n.removeMark(x,m,c)}else p.forEach(x=>{n.removeMark(x.$from.pos,x.$to.pos,c)});return n.removeStoredMark(c),!0},updateAttributes:(e,t={})=>({tr:n,state:r,dispatch:i})=>{let o=null,l=null;const u=ao(typeof e=="string"?e:e.name,r.schema);return u?(u==="node"&&(o=Ce(e,r.schema)),u==="mark"&&(l=mt(e,r.schema)),i&&n.selection.ranges.forEach(c=>{const d=c.$from.pos,h=c.$to.pos;r.doc.nodesBetween(d,h,(p,x)=>{o&&o===p.type&&n.setNodeMarkup(x,void 0,{...p.attrs,...t}),l&&p.marks.length&&p.marks.forEach(m=>{if(l===m.type){const j=Math.max(x,d),C=Math.min(x+p.nodeSize,h);n.addMark(j,C,l.create({...m.attrs,...t}))}})})}),!0):!1},wrapIn:(e,t={})=>({state:n,dispatch:r})=>{const i=Ce(e,n.schema);return be.wrapIn(i,t)(n,r)},wrapInList:(e,t={})=>({state:n,dispatch:r})=>{const i=Ce(e,n.schema);return ps.wrapInList(i,t)(n,r)}});et.create({name:"commands",addCommands(){return{...dg}}}),et.create({name:"editable",addProseMirrorPlugins(){return[new rn({key:new an("editable"),props:{editable:()=>this.editor.options.editable}})]}}),et.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:e}=this;return[new rn({key:new an("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}}}})]}}),et.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:h,$anchor:p}=c,{pos:x,parent:m}=p,j=le.atStart(d).from===x;return!h||!j||!m.type.isTextblock||m.textContent.length?!1:l.clearNodes()}),()=>l.deleteSelection(),()=>l.joinBackward(),()=>l.selectNodeBackward()]),t=()=>this.editor.commands.first(({commands:l})=>[()=>l.deleteSelection(),()=>l.deleteCurrentNode(),()=>l.joinForward(),()=>l.selectNodeForward()]),r={Enter:()=>this.editor.commands.first(({commands:l})=>[()=>l.newlineInCode(),()=>l.createParagraphNear(),()=>l.liftEmptyBlock(),()=>l.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:e,"Mod-Backspace":e,"Shift-Backspace":e,Delete:t,"Mod-Delete":t,"Mod-a":()=>this.editor.commands.selectAll()},i={...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 Hs()||io()?o:i},addProseMirrorPlugins(){return[new rn({key:new an("clearDocument"),appendTransaction:(e,t,n)=>{if(!(e.some(j=>j.docChanged)&&!t.doc.eq(n.doc)))return;const{empty:i,from:o,to:l}=t.selection,u=le.atStart(t.doc).from,c=le.atEnd(t.doc).to;if(i||!(o===u&&l===c)||!(n.doc.textBetween(0,n.doc.content.size," "," ").length===0))return;const p=n.tr,x=eo({state:n,transaction:p}),{commands:m}=new sf({editor:this.editor,state:x});if(m.clearNodes(),!!p.steps.length)return p}})]}}),et.create({name:"tabindex",addProseMirrorPlugins(){return[new rn({key:new an("tabindex"),props:{attributes:this.editor.isEditable?{tabindex:"0"}:{}}})]}});const co=et.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()}}}),pg=["8","10","12","14","16","18","20","24","30","36","48","60","72"].map(e=>`${e}px`),hg=[{label:"auto",value:""}].concat(pg.map(e=>({label:e,value:e}))),xg={input:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important"}},fg=({editor:e})=>{const t=e.getAttributes("textStyle").fontSize;return s.jsx(N.RichTextEditor.ControlsGroup,{children:s.jsx(a.NativeSelect,{size:"xs",icon:s.jsx(_.IconTextSize,{stroke:1.5,size:16}),data:hg,styles:xg,value:t||"",onChange:n=>{const r=n.currentTarget.value;r?e.chain().focus().setFontSize(r).run():e.chain().focus().unsetFontSize().run()}})})},Fn=({value:e,styles:t={},sx:n={}})=>{const r=Gi.useEditor({extensions:[Wi,Fi,N.Link,Pi,Li,Ai,$i.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),Ni,qi,Vi,Bi.configure({types:["heading","paragraph"]}),Ei.configure({placeholder:"This is placeholder"}),Oi,zi.Color,co],content:e,editable:!1});g.useEffect(()=>{r==null||r.commands.setContent(e)},[e,r]);const i=g.useMemo(()=>y.defaultsDeep({},{content:Fs},t),[t]);return s.jsx(N.RichTextEditor,{editor:r,styles:i,sx:n,children:s.jsx(N.RichTextEditor.Content,{})})};function gg(){const[e,{open:t,close:n}]=oe.useDisclosure(!1);return s.jsxs(s.Fragment,{children:[s.jsx(a.Modal,{opened:e,onClose:n,title:"About FunctionUtils",zIndex:330,withinPortal:!0,children:s.jsx(Fn,{value:td,styles:{root:{border:"none"},content:{padding:0,table:{marginBottom:0}}}})}),s.jsx(a.Button,{variant:"light",color:"violet",size:"xs",onClick:t,leftIcon:s.jsx(_.IconInfoCircle,{size:16}),children:"About parameter 'utils'"})]})}const mg=({value:e,onChange:t})=>{const n=r=>{if(!r){t("");return}t(r)};return s.jsx(a.Box,{sx:{position:"relative",flexGrow:1},children:s.jsx(ye,{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}}})})},$t=g.forwardRef(({value:e,onChange:t,label:n,defaultValue:r},i)=>{const[o,l]=g.useState(e),u=()=>{t(o)},c=()=>{l(e)},d=()=>{l(r)};g.useEffect(()=>{l(e)},[e]);const h=o!==e;return s.jsxs(a.Stack,{spacing:4,sx:{height:"100%"},children:[s.jsxs(a.Group,{mb:6,position:"apart",sx:{flexShrink:0,flexGrow:0},children:[s.jsx(a.Group,{position:"left",children:s.jsx(gg,{})}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:d,size:"xs",variant:"default",leftIcon:s.jsx(_.IconPlayerSkipBack,{size:16}),children:"Reset to default"}),s.jsx(a.Button,{onClick:c,color:"red",size:"xs",disabled:!h,leftIcon:s.jsx(_.IconRecycle,{size:16}),children:"Revert Changes"}),s.jsx(a.Button,{size:"xs",onClick:u,disabled:!h,leftIcon:s.jsx(_.IconDeviceFloppy,{size:16}),children:"Confirm Changes"})]})]}),s.jsx(a.Text,{size:14,children:n}),s.jsx(mg,{value:o,onChange:l})]})}),po=g.forwardRef(({title:e,value:t,onChange:n,label:r,description:i=null,triggerLabel:o="Edit",triggerButtonProps:l={},defaultValue:u},c)=>{const[d,{open:h,close:p}]=oe.useDisclosure(!1);return s.jsxs(s.Fragment,{children:[s.jsxs(a.Modal,{opened:d,onClose:p,title:e,withinPortal:!0,zIndex:320,size:"900px",children:[i,s.jsx(a.Box,{h:600,children:s.jsx($t,{value:t,onChange:n,defaultValue:u,label:r})})]}),s.jsx(a.Button,{onClick:h,...l,children:o})]})}),yg=[{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 bg({label:e,value:t,onChange:n,pt:r="sm",withFallback:i},o){g.useEffect(()=>{typeof t=="string"&&n({type:t,config:{},fallback:"0"})},[t,n]);const l=h=>{n(h==="quantile"?{type:"quantile",config:{p:.99},fallback:t.fallback}:h==="custom"?{type:"custom",config:{func:ta},fallback:t.fallback}:{type:h,config:{},fallback:t.fallback})},u=h=>{n({type:"quantile",config:{p:h},fallback:t.fallback})},c=h=>{n({type:"custom",config:{func:h},fallback:t.fallback})},d=h=>{n({...t,fallback:h.currentTarget.value})};return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,pt:r,children:[s.jsx(a.Select,{ref:o,label:e,data:yg,value:t.type,onChange:l,maxDropdownHeight:600}),t.type==="quantile"&&s.jsx(a.NumberInput,{label:"p",value:t.config.p,onChange:u,precision:2,min:.05,step:.05,max:1}),t.type==="custom"&&s.jsx(po,{title:"Custom Aggregation",label:"",triggerLabel:"Edit Function",value:t.config.func,onChange:c,defaultValue:ta,triggerButtonProps:{size:"xs",sx:{flexGrow:0,alignSelf:"center",marginTop:"22px"},leftIcon:s.jsx(_.IconMathFunction,{size:16})}})]}),i&&s.jsx(a.TextInput,{label:"Fallback Value",description:"Used when data is empty or the aggregation yields NaN",value:t.fallback,onChange:d})]})}const rr=g.forwardRef(bg),jg=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function vg({control:e,index:t,seriesItem:n}){const r=!!n.barWidth.trim();return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${t}.stack`,control:e,render:({field:i})=>s.jsx(a.TextInput,{label:"Stack",placeholder:"Stack bars by this ID",sx:{flexGrow:1},...i})}),s.jsx(b.Controller,{name:`series.${t}.barGap`,control:e,render:({field:i})=>s.jsx(a.Select,{label:"Bar Gap",data:jg,sx:{flexGrow:1},...i})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${t}.barMinWidth`,control:e,render:({field:i})=>s.jsx(a.TextInput,{label:"Bar Width(Min)",disabled:r,sx:{flexGrow:1},...i})}),s.jsx(b.Controller,{name:`series.${t}.barWidth`,control:e,render:({field:i})=>s.jsx(a.TextInput,{label:"Bar Width",sx:{flexGrow:1},...i})}),s.jsx(b.Controller,{name:`series.${t}.barMaxWidth`,control:e,render:({field:i})=>s.jsx(a.TextInput,{label:"Bar Width(Max)",disabled:r,sx:{flexGrow:1},...i})})]})]})}const wg=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return s.jsx(a.Box,{children:s.jsx(ye,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Cg=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:i}]=V.useBoolean(),[o,l]=g.useState(e),u=()=>{i();const{type:p,func_content:x}=o,m={type:p,func_content:x};l(m),t(m)},c=()=>{i(),l(e)},d=p=>{l(x=>({...x,func_content:p}))},h=()=>{d(Ns.dynamic.func_content)};return s.jsxs(s.Fragment,{children:[s.jsx(a.Box,{sx:{width:"50%"},children:s.jsx(a.Button,{variant:"filled",mt:24,onClick:r,sx:{flexGrow:0},children:"Setup"})}),s.jsx(a.Modal,{size:800,title:"Setup dynamic size",opened:n,onClose:i,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),s.jsx(wg,{value:o.func_content,onChange:d}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:h,color:"red",leftIcon:s.jsx(k.Recycle,{size:20}),children:"Reset"}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:c,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:u,children:"OK"})]})]})]})})]})},Sg=({value:e,onChange:t})=>e.type!=="dynamic"?null:s.jsx(Cg,{value:e,onChange:t}),_g=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=r=>{t({...e,size:r})};return s.jsx(s.Fragment,{children:s.jsx(a.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:e.size,onChange:n})})},kg=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],ho=g.forwardRef(({label:e="Size",value:t,onChange:n},r)=>{const i=o=>{n({...Ns[o]})};return s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(a.Select,{ref:r,label:e,data:kg,value:t.type,onChange:i,sx:{flexGrow:1}}),s.jsx(_g,{value:t,onChange:n}),s.jsx(Sg,{value:t,onChange:n})]})}),Tg=[{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 Ig({control:e,index:t,seriesItem:n}){const r=n.showSymbol;return s.jsxs(s.Fragment,{children:[s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Line Settings",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:`series.${t}.lineStyle.type`,control:e,render:({field:i})=>s.jsx(a.Select,{label:"Line Type",data:Dg,sx:{flexGrow:1},...i})}),s.jsx(b.Controller,{name:`series.${t}.lineStyle.width`,control:e,render:({field:i})=>s.jsx(a.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...i})})]}),s.jsxs(a.Group,{grow:!0,align:"center",children:[s.jsx(b.Controller,{name:`series.${t}.step`,control:e,render:({field:i})=>s.jsx(a.Select,{label:"Step",data:Tg,sx:{flexGrow:1,maxWidth:"48%"},...i,value:String(i.value),onChange:o=>{const l=o==="false"?!1:o;i.onChange(l)}})}),s.jsxs(a.Stack,{children:[s.jsx(b.Controller,{name:`series.${t}.smooth`,control:e,render:({field:i})=>s.jsx(a.Box,{sx:{flexGrow:1},children:s.jsx(a.Switch,{label:"Smooth Line",checked:i.value,onChange:o=>i.onChange(o.currentTarget.checked)})})}),s.jsx(b.Controller,{name:`series.${t}.display_name_on_line`,control:e,render:({field:i})=>s.jsx(a.Box,{sx:{flexGrow:1},children:s.jsx(a.Switch,{label:"Display Name on Line",checked:i.value??!1,onChange:o=>i.onChange(o.currentTarget.checked)})})})]})]}),s.jsxs(a.Stack,{children:[s.jsx(b.Controller,{name:`series.${t}.showSymbol`,control:e,render:({field:i})=>s.jsx(a.Box,{mt:10,mb:-10,sx:{flexGrow:1},children:s.jsx(a.Switch,{label:"Show Symbol on Line",checked:i.value,onChange:o=>i.onChange(o.currentTarget.checked)})})}),r&&s.jsx(b.Controller,{name:`series.${t}.symbolSize`,control:e,render:({field:i})=>s.jsx(ho,{label:"Symbol Size",...i})})]})]})}function Mg({control:e,index:t}){return s.jsx(b.Controller,{name:`series.${t}.symbolSize`,control:e,render:({field:n})=>s.jsx(ho,{label:"Size",...n})})}const zg=[{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 Ag({control:e,index:t,remove:n,seriesItem:r,yAxisOptions:i}){const o=r.type;return s.jsxs(a.Stack,{my:0,p:0,sx:{position:"relative"},children:[s.jsx(a.Stack,{children:s.jsx(b.Controller,{name:`series.${t}.type`,control:e,render:({field:l})=>s.jsx(a.SegmentedControl,{data:[{label:"Line",value:"line"},{label:"Bar",value:"bar"},{label:"Scatter",value:"scatter"}],...l})})}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${t}.name`,control:e,render:({field:l})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...l})}),s.jsx(b.Controller,{name:`series.${t}.yAxisIndex`,control:e,render:({field:{value:l,onChange:u,...c}})=>s.jsx(a.Select,{label:"Y Axis",data:i,disabled:i.length===0,...c,value:(l==null?void 0:l.toString())??"",onChange:d=>{if(!d){u(0);return}u(Number(d))},sx:{flex:1}})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${t}.y_axis_data_key`,control:e,render:({field:l})=>s.jsx(O,{label:"Value Field",required:!0,sx:{flex:1},...l})}),s.jsx(b.Controller,{name:`series.${t}.aggregation_on_value`,control:e,render:({field:l})=>s.jsx(rr,{label:"Aggregation on Value",value:l.value??At,onChange:l.onChange,pt:0,withFallback:!1})})]}),s.jsx(a.Group,{grow:!0,children:s.jsx(b.Controller,{name:`series.${t}.group_by_key`,control:e,render:({field:l})=>s.jsx(O,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...l})})}),o==="line"&&s.jsx(Ig,{index:t,control:e,seriesItem:r}),o==="bar"&&s.jsx(vg,{index:t,control:e,seriesItem:r}),o==="scatter"&&s.jsx(Mg,{index:t,control:e}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),s.jsx(b.Controller,{name:`series.${t}.label_position`,control:e,render:({field:l})=>s.jsx(a.Select,{label:"Label Position",data:zg,...l})}),s.jsxs(a.Stack,{spacing:4,children:[s.jsx(a.Text,{size:"sm",children:"Color"}),s.jsx(b.Controller,{name:`series.${t}.color`,control:e,render:({field:l})=>s.jsx(ke,{...l})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),s.jsx(b.Controller,{name:`series.${t}.hide_in_legend`,control:e,render:({field:l})=>s.jsx(a.Checkbox,{label:"Hide in legend",checked:l.value,onChange:u=>l.onChange(u.currentTarget.checked)})}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed"}),s.jsx(a.Button,{leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Series"})]})}function Eg({control:e,watch:t}){const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"series"}),o=t("series"),l=n.map((h,p)=>({...h,...o[p]})),u=()=>{const h={type:"bar",name:oe.randomId(),showSymbol:!1,symbolSize:Ns.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(h)},c=t("y_axes"),d=g.useMemo(()=>c.map(({name:h},p)=>({label:h,value:p.toString()})),[c]);return s.jsxs(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((h,p)=>s.jsx(a.Tabs.Tab,{value:p.toString(),children:p+1},h.id)),s.jsx(a.Tabs.Tab,{onClick:u,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),l.map((h,p)=>s.jsx(a.Tabs.Panel,{value:p.toString(),children:s.jsx(Ag,{control:e,index:p,remove:i,seriesItem:h,yAxisOptions:d},h.id)},h.id))]})}function Lg({control:e,watch:t}){return t("stats"),s.jsx(a.Stack,{children:s.jsxs(a.Stack,{spacing:0,children:[s.jsx(b.Controller,{name:"stats.templates.top",control:e,render:({field:n})=>s.jsx(Xt,{label:"Template for stats above the chart",py:"md",sx:{flexGrow:1},...n})}),s.jsx(b.Controller,{name:"stats.templates.bottom",control:e,render:({field:n})=>s.jsx(Xt,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const Pg=()=>s.jsxs(a.Group,{sx:{display:"inline-flex"},spacing:6,mr:14,children:[s.jsx(a.Text,{children:"X Axis Data Type"}),s.jsxs(a.HoverCard,{width:340,shadow:"md",position:"top",children:[s.jsx(a.HoverCard.Target,{children:s.jsx(a.ActionIcon,{size:"xs",sx:{transform:"none !important"},children:s.jsx(_.IconInfoCircle,{})})}),s.jsx(a.HoverCard.Dropdown,{children:s.jsxs(a.Text,{size:"sm",children:["Click",s.jsx(a.Anchor,{href:"https://echarts.apache.org/en/option.html#xAxis.type",target:"_blank",mx:4,children:"here"}),"to learn more about these options"]})})]})]}),Bg=[{label:"Value",value:"value"},{label:"Category",value:"category"},{label:"Time",value:"time"},{label:"Log",value:"log"}];function Og({control:e,watch:t}){return t(["x_axis_data_key","x_axis_name","x_axis"]),s.jsxs(a.Stack,{children:[s.jsx(b.Controller,{name:"x_axis_name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"X Axis Name",sx:{flex:1},...n})}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis_data_key",control:e,render:({field:n})=>s.jsx(O,{label:"X Axis Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"x_axis.type",control:e,render:({field:n})=>s.jsx(a.Select,{label:s.jsx(Pg,{}),required:!0,data:Bg,sx:{flex:1},...n})})]}),s.jsx(a.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>s.jsx(a.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:s.jsx(a.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),s.jsx(b.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>s.jsx(Tn,{...n})})]}),s.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>s.jsx(Ke,{...n})})]})}const $g=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],Vg=[{label:"left",value:"left"},{label:"right",value:"right"}];function qg({control:e,index:t,remove:n}){return s.jsxs(a.Stack,{my:0,p:"0",sx:{position:"relative"},children:[s.jsx(a.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`y_axes.${t}.name`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`y_axes.${t}.nameAlignment`,control:e,render:({field:r})=>s.jsx(a.Select,{label:"Name Anchor",required:!0,data:$g,sx:{flex:1},...r})})]}),s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:`y_axes.${t}.position`,control:e,render:({field:r})=>s.jsx(a.Select,{label:"Position",required:!0,data:Vg,sx:{flex:1},...r})})}),s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),s.jsx(b.Controller,{name:`y_axes.${t}.label_formatter`,control:e,render:({field:r})=>s.jsx(Fe,{...r})})]}),s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:`y_axes.${t}.min`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Min",...r})}),s.jsx(b.Controller,{name:`y_axes.${t}.max`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Max",...r})})]})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),s.jsx(b.Controller,{name:`y_axes.${t}.show`,control:e,render:({field:r})=>s.jsx(a.Checkbox,{label:"Visible",checked:r.value,onChange:i=>r.onChange(i.currentTarget.checked)})}),s.jsx(a.Button,{mt:20,leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this YAxis"})]})}function Ng({control:e,watch:t}){const{fields:n,append:r,remove:i}=b.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:je,min:"",max:"",show:!0});return s.jsxs(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((c,d)=>s.jsx(a.Tabs.Tab,{value:d.toString(),children:d+1},c.id)),s.jsx(a.Tabs.Tab,{onClick:u,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),l.map((c,d)=>s.jsx(a.Tabs.Panel,{value:d.toString(),children:s.jsx(qg,{control:e,index:d,remove:i})},c.id))]})}const Fg=({control:e,index:t,remove:n})=>s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>s.jsx(O,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed"}),s.jsx(a.Button,{leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),Gg=({control:e,watch:t})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((p,x)=>({...p,...o[x]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[d,h]=g.useState(()=>c??null);return g.useEffect(()=>{c&&h(p=>p!==null?p:c)},[c]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(k.InfoCircle,{size:14,color:"#888"}),s.jsx(a.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),s.jsxs(a.Tabs,{value:d,onTabChange:p=>h(p),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((p,x)=>s.jsx(a.Tabs.Tab,{value:p.id,children:p.name?p.name:x},p.id)),s.jsx(a.Tabs.Tab,{onClick:u,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),l.map((p,x)=>s.jsx(a.Tabs.Panel,{value:p.id,children:s.jsx(Fg,{control:e,index:x,remove:i},p.id)},p.id))]})]})};function Wg({control:e,watch:t}){return s.jsx(a.Stack,{children:s.jsx(Gg,{control:e,watch:t})})}function Rg({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),{variables:r}=e,i=g.useMemo(()=>y.defaultsDeep({},t,Vs),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=b.useForm({defaultValues:i});g.useEffect(()=>{d(i)},[i]);const h=c(),p=g.useMemo(()=>!y.isEqual(h,i),[h,i]);return u(["dataZoom"]),s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:l(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Chart Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Tabs,{defaultValue:"Series",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"X Axis",children:"X Axis"}),s.jsx(a.Tabs.Tab,{value:"Y Axes",children:"Y Axes"}),s.jsx(a.Tabs.Tab,{value:"Series",children:"Series"}),s.jsx(a.Tabs.Tab,{value:"Regression Lines",children:"Regression Lines"}),s.jsx(a.Tabs.Tab,{value:"Tooltip",children:"Tooltip"}),s.jsx(a.Tabs.Tab,{value:"Stats",children:"Stats"}),s.jsx(a.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"}),s.jsx(a.Tabs.Tab,{value:"Reference Areas",children:"Reference Areas"}),s.jsx(a.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),s.jsx(a.Tabs.Panel,{value:"X Axis",children:s.jsx(Og,{control:o,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Y Axes",children:s.jsx(Ng,{control:o,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Series",children:s.jsx(Eg,{control:o,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Regression Lines",children:s.jsx(Fx,{control:o,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(Wg,{control:o,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Stats",children:s.jsx(Lg,{control:o,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Reference Lines",children:s.jsx($x,{variables:r,control:o,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Reference Areas",children:s.jsx(Lx,{variables:r,control:o,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Zooming",children:s.jsx(b.Controller,{name:"dataZoom",control:o,render:({field:x})=>s.jsx(Dn,{...x})})})]})]})})}function Qg(e){const t=y.cloneDeep(y.omit(e,"variables"));return t.stats=y.omit(t.stats,"variables"),t}function Ug(e){const{rotate:t,formatter:n=Oe}=e.x_axis.axisLabel;return{...e,x_axis:{...e.x_axis,axisLabel:{rotate:t,formatter:n}}}}function Kg(e){const{dataZoom:t=jt,...n}=e;return{...n,dataZoom:t}}function Yg(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return y.defaultsDeep(t,e)}function Xg(e){const t=e.reference_lines.map(n=>{const{lineStyle:r={type:"dashed",width:1,color:st.random().css()},show_in_legend:i=!1}=n;return{...n,lineStyle:r,show_in_legend:i}});return{...e,reference_lines:t}}function Jg(e){const t=e.reference_lines.map(n=>{const{yAxisIndex:r=0}=n;return{...n,yAxisIndex:r}});return{...e,reference_lines:t}}function Zg(e){const t=e.series.map(n=>{const{aggregation_on_group:r=At}=n;return{...n,aggregation_on_group:r}});return{...e,series:t}}function Hg(e){const t=e.series.map(n=>{const{aggregation_on_value:r=At}=n;return{...n,aggregation_on_value:r}});return{...e,series:t}}function em(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 y.defaultsDeep(r,e)}function tm(e){const{series:t,...n}=e;return{...n,series:t.map(r=>{const{barMinWidth:i,barWidth:o,barMaxWidth:l}=r;return i?{...r,barMinWidth:i,barWidth:"",barMaxWidth:l??o}:{...r,barMinWidth:"",barWidth:o,barMaxWidth:""}})}}function nm(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(r=>{const{min:i="",max:o=""}=r;return{...r,min:i,max:o}})}}function sm(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(r=>{const{nameAlignment:i="left"}=r;return{...r,nameAlignment:i}})}}function rm(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(r=>{const{show:i=!0}=r;return{...r,show:i}})}}function im(e){const{regressions:t,...n}=e;return{...n,regressions:t.map(r=>{const{group_by_key:i=""}=r;return{...r,group_by_key:i}})}}function am(e){const{series:t,y_axes:n,...r}=e;return{...r,series:t.map(i=>{const{hide_in_legend:o=!1,aggregation_on_value:l=At}=i;return{...i,hide_in_legend:o,aggregation_on_value:l}}),y_axes:n.map(i=>{const{min:o="",max:l="",show:u=!0}=i;return{...i,min:o,max:l,show:u}})}}function om(e){const{type:t="category",...n}=e.x_axis;return{...e,x_axis:{...n,type:t}}}function lm(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:i,series:o,regressions:l,...u}=e;return{...u,x_axis_data_key:r(i),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}}function um(e){const{tooltip:t={metrics:[]},...n}=e;return{...e,tooltip:t}}class cm extends ue{constructor(){super(...arguments);L(this,"VERSION",19)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,{panelModel:r})=>{const{config:i}=n;return(i.variables||[]).forEach(u=>{r.variables.find(c=>c.name===u.name)||r.addVariable(u)}),(y.get(i,"stats.variables")||[]).forEach(u=>{r.variables.find(c=>c.name===u.name)||r.addVariable(u)}),{...n,version:2,config:Qg(i)}}),this.version(3,n=>({...n,version:3,config:Ug(n.config)})),this.version(4,n=>({...n,version:4,config:Kg(n.config)})),this.version(5,n=>({...n,version:5,config:Yg(n.config)})),this.version(6,n=>({...n,version:6,config:Xg(n.config)})),this.version(7,n=>({...n,version:7,config:Jg(n.config)})),this.version(8,n=>({...n,version:8,config:Zg(n.config)})),this.version(9,n=>({...n,version:9,config:Hg(n.config)})),this.version(10,n=>({...n,version:10,config:em(n.config)})),this.version(11,n=>({...n,version:11,config:tm(n.config)})),this.version(12,n=>({...n,version:12,config:nm(n.config)})),this.version(13,n=>({...n,version:13,config:sm(n.config)})),this.version(14,n=>({...n,version:14,config:rm(n.config)})),this.version(15,n=>({...n,version:15,config:im(n.config)})),this.version(16,n=>({...n,version:16,config:am(n.config)})),this.version(17,n=>({...n,version:17,config:om(n.config)})),this.version(18,(n,r)=>({...n,version:18,config:lm(n.config,r)})),this.version(19,n=>({...n,version:19,config:um(n.config)}))}}const dm={displayName:"Cartesian Chart",displayGroup:"ECharts-based charts",migrator:new cm,name:"cartesian",viewRender:Mx,configRender:Rg,createConfig(){return{version:19,config:y.cloneDeep(Vs)}},triggers:[$s]};function pm(e){if(e.enable_value)return e.value}function hm(e){if(e.enable_value)return e.value}function xm(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"&&y.get(r,n)&&n===e.funnelAlign&&y.set(r,n,t),r}function fm(e,t){return e.series.map(n=>{const{level_name_data_key:r,level_value_data_key:i,axisLabel:o,min:l,max:u,funnelAlign:c,orient:d,...h}=n;if(!r||!i)return{};const p=z(r),x=z(i),m=t[p.queryID].map(C=>({name:C[p.columnKey],value:C[x.columnKey]})),j=Ve(o.overflow.on_axis);return{type:"funnel",...xm(n),min:pm(l),max:hm(u),minSize:l.size,maxSize:u.size,...h,label:{show:!0,position:o.position,...j},orient:d,funnelAlign:d==="horizontal"?"center":c,data:m}})}function gm({conf:e,params:t,max:n}){const{name:r,value:i}=t.data,o=W(i/n,{output:"percent",mantissa:2,trimMantissa:!0,absolute:!1});return[{label:`${t.marker} ${r}`,value:`${i} (${o})`,style:{label:"",value:""}}]}function mm(e,t){var o;const n=z(e.series[0].level_name_data_key),r=z(e.series[0].level_value_data_key),i=(o=y.maxBy(t[n.queryID],r.columnKey))==null?void 0:o[r.columnKey];return l=>{const c=gm({conf:e,params:l,max:i}).map(h=>`
132
+ `,textSerializers:l={}}=n||{};let c="",u=!0;return e.nodesBetween(r,i,(d,h,p,x)=>{var m;const j=l==null?void 0:l[d.type.name];j?(d.isBlock&&!u&&(c+=o,u=!0),p&&(c+=j({node:d,pos:h,parent:p,index:x,range:t}))):d.isText?(c+=(m=d==null?void 0:d.text)===null||m===void 0?void 0:m.slice(Math.max(r,h)-h,i-h),u=!1):d.isBlock&&!u&&(c+=o,u=!0)}),c}function df(e){return Object.fromEntries(Object.entries(e.nodes).filter(([,t])=>t.spec.toText).map(([t,n])=>[t,n.spec.toText]))}Je.create({name:"clipboardTextSerializer",addProseMirrorPlugins(){return[new sn({key:new rn("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:e}=this,{state:t,schema:n}=e,{doc:r,selection:i}=t,{ranges:o}=i,l=Math.min(...o.map(h=>h.$from.pos)),c=Math.max(...o.map(h=>h.$to.pos)),u=df(n);return uf(r,{from:l,to:c},{textSerializers:u})}}})]}});const pf=()=>({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),hf=(e=!1)=>({commands:t})=>t.setContent("",e),xf=()=>({state:e,tr:t,dispatch:n})=>{const{selection:r}=t,{ranges:i}=r;return n&&i.forEach(({$from:o,$to:l})=>{e.doc.nodesBetween(o.pos,l.pos,(c,u)=>{if(c.type.isText)return;const{doc:d,mapping:h}=t,p=d.resolve(h.map(u)),x=d.resolve(h.map(u+c.nodeSize)),m=p.blockRange(x);if(!m)return;const j=ef(m);if(c.type.isTextblock){const{defaultType:C}=p.parent.contentMatchAt(p.index());t.setNodeMarkup(m.start,C)}(j||j===0)&&t.lift(m,j)})}),!0},ff=e=>t=>e(t),gf=()=>({state:e,dispatch:t})=>ge.createParagraphNear(e,t),mf=()=>({tr:e,dispatch:t})=>{const{selection:n}=e,r=n.$anchor.node();if(r.content.size>0)return!1;const i=e.selection.$anchor;for(let o=i.depth;o>0;o-=1)if(i.node(o).type===r.type){if(t){const c=i.before(o),u=i.after(o);e.delete(c,u).scrollIntoView()}return!0}return!1},yf=e=>({tr:t,state:n,dispatch:r})=>{const i=ve(e,n.schema),o=t.selection.$anchor;for(let l=o.depth;l>0;l-=1)if(o.node(l).type===i){if(r){const u=o.before(l),d=o.after(l);t.delete(u,d).scrollIntoView()}return!0}return!1},bf=e=>({tr:t,dispatch:n})=>{const{from:r,to:i}=e;return n&&t.delete(r,i),!0},jf=()=>({state:e,dispatch:t})=>ge.deleteSelection(e,t),vf=()=>({commands:e})=>e.keyboardShortcut("Enter"),wf=()=>({state:e,dispatch:t})=>ge.exitCode(e,t);function $n(e,t,n={strict:!0}){const r=Object.keys(t);return r.length?r.every(i=>n.strict?t[i]===e[i]:lf(t[i])?t[i].test(e[i]):t[i]===e[i]):!0}function Js(e,t,n={}){return e.find(r=>r.type===t&&$n(r.attrs,n))}function Cf(e,t,n={}){return!!Js(e,t,n)}function so(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 i=Js([...r.node.marks],t,n);if(!i)return;let o=r.index,l=e.start()+r.offset,c=o+1,u=l+r.node.nodeSize;for(Js([...r.node.marks],t,n);o>0&&i.isInSet(e.parent.child(o-1).marks);)o-=1,l-=e.parent.child(o).nodeSize;for(;c<e.parent.childCount&&Cf([...e.parent.child(c).marks],t,n);)u+=e.parent.child(c).nodeSize,c+=1;return{from:l,to:u}}function gt(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 Sf=(e,t={})=>({tr:n,state:r,dispatch:i})=>{const o=gt(e,r.schema),{doc:l,selection:c}=n,{$from:u,from:d,to:h}=c;if(i){const p=so(u,o,t);if(p&&p.from<=d&&p.to>=h){const x=xe.create(l,p.from,p.to);n.setSelection(x)}}return!0},_f=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 ro(e){return e instanceof xe}function _t(e=0,t=0,n=0){return Math.min(Math.max(e,t),n)}function kf(e,t=null){if(!t)return null;const n=ie.atStart(e),r=ie.atEnd(e);if(t==="start"||t===!0)return n;if(t==="end")return r;const i=n.from,o=r.to;return t==="all"?xe.create(e,_t(0,i,o),_t(e.content.size,i,o)):xe.create(e,_t(t,i,o),_t(t,i,o))}function Zs(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}const Tf=(e=null,t={})=>({editor:n,view:r,tr:i,dispatch:o})=>{t={scrollIntoView:!0,...t};const l=()=>{Zs()&&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&&!ro(n.state.selection))return l(),!0;const c=kf(i.doc,e)||n.state.selection,u=n.state.selection.eq(c);return o&&(u||i.setSelection(c),u&&i.storedMarks&&i.setStoredMarks(i.storedMarks),l()),!0},Df=(e,t)=>n=>e.every((r,i)=>t(r,{...n,index:i})),If=(e,t)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},e,t);function io(e){const t=`<body>${e}</body>`;return new window.DOMParser().parseFromString(t,"text/html").body}function Vn(e,t,n){if(n={slice:!0,parseOptions:{},...n},typeof e=="object"&&e!==null)try{return Array.isArray(e)&&e.length>0?J.fromArray(e.map(r=>t.nodeFromJSON(r))):t.nodeFromJSON(e)}catch(r){return console.warn("[tiptap warn]: Invalid content.","Passed value:",e,"Error:",r),Vn("",t,n)}if(typeof e=="string"){const r=Mn.fromSchema(t);return n.slice?r.parseSlice(io(e),n.parseOptions).content:r.parse(io(e),n.parseOptions)}return Vn("",t,n)}function Mf(e,t,n){const r=e.steps.length-1;if(r<t)return;const i=e.steps[r];if(!(i instanceof Xe||i instanceof St))return;const o=e.mapping.maps[r];let l=0;o.forEach((c,u,d,h)=>{l===0&&(l=h)}),e.setSelection(ie.near(e.doc.resolve(l),n))}const zf=e=>e.toString().startsWith("<"),Af=(e,t,n)=>({tr:r,dispatch:i,editor:o})=>{if(i){n={parseOptions:{},updateSelection:!0,...n};const l=Vn(t,o.schema,{parseOptions:{preserveWhitespace:"full",...n.parseOptions}});if(l.toString()==="<>")return!0;let{from:c,to:u}=typeof e=="number"?{from:e,to:e}:e,d=!0,h=!0;if((zf(l)?l:[l]).forEach(x=>{x.check(),d=d?x.isText&&x.marks.length===0:!1,h=h?x.isBlock:!1}),c===u&&h){const{parent:x}=r.doc.resolve(c);x.isTextblock&&!x.type.spec.code&&!x.childCount&&(c-=1,u+=1)}d?Array.isArray(t)?r.insertText(t.map(x=>x.text||"").join(""),c,u):typeof t=="object"&&t&&t.text?r.insertText(t.text,c,u):r.insertText(t,c,u):r.replaceWith(c,u,l),n.updateSelection&&Mf(r,r.steps.length-1,-1)}return!0},Ef=()=>({state:e,dispatch:t})=>ge.joinUp(e,t),Pf=()=>({state:e,dispatch:t})=>ge.joinDown(e,t),Lf=()=>({state:e,dispatch:t})=>ge.joinBackward(e,t),Bf=()=>({state:e,dispatch:t})=>ge.joinForward(e,t);function ao(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function Of(e){const t=e.split(/-(?!$)/);let n=t[t.length-1];n==="Space"&&(n=" ");let r,i,o,l;for(let c=0;c<t.length-1;c+=1){const u=t[c];if(/^(cmd|meta|m)$/i.test(u))l=!0;else if(/^a(lt)?$/i.test(u))r=!0;else if(/^(c|ctrl|control)$/i.test(u))i=!0;else if(/^s(hift)?$/i.test(u))o=!0;else if(/^mod$/i.test(u))Zs()||ao()?l=!0:i=!0;else throw new Error(`Unrecognized modifier name: ${u}`)}return r&&(n=`Alt-${n}`),i&&(n=`Ctrl-${n}`),l&&(n=`Meta-${n}`),o&&(n=`Shift-${n}`),n}const $f=e=>({editor:t,view:n,tr:r,dispatch:i})=>{const o=Of(e).split(/-(?!$)/),l=o.find(d=>!["Alt","Ctrl","Meta","Shift"].includes(d)),c=new KeyboardEvent("keydown",{key:l==="Space"?" ":l,altKey:o.includes("Alt"),ctrlKey:o.includes("Ctrl"),metaKey:o.includes("Meta"),shiftKey:o.includes("Shift"),bubbles:!0,cancelable:!0}),u=t.captureTransaction(()=>{n.someProp("handleKeyDown",d=>d(n,c))});return u==null||u.steps.forEach(d=>{const h=d.map(r.mapping);h&&i&&r.maybeStep(h)}),!0};function Hs(e,t,n={}){const{from:r,to:i,empty:o}=e.selection,l=t?ve(t,e.schema):null,c=[];e.doc.nodesBetween(r,i,(p,x)=>{if(p.isText)return;const m=Math.max(r,x),j=Math.min(i,x+p.nodeSize);c.push({node:p,from:m,to:j})});const u=i-r,d=c.filter(p=>l?l.name===p.node.type.name:!0).filter(p=>$n(p.node.attrs,n,{strict:!1}));return o?!!d.length:d.reduce((p,x)=>p+x.to-x.from,0)>=u}const Vf=(e,t={})=>({state:n,dispatch:r})=>{const i=ve(e,n.schema);return Hs(n,i,t)?ge.lift(n,r):!1},qf=()=>({state:e,dispatch:t})=>ge.liftEmptyBlock(e,t),Nf=e=>({state:t,dispatch:n})=>{const r=ve(e,t.schema);return ds.liftListItem(r)(t,n)},Ff=()=>({state:e,dispatch:t})=>ge.newlineInCode(e,t);function oo(e,t){return t.nodes[e]?"node":t.marks[e]?"mark":null}function lo(e,t){const n=typeof t=="string"?[t]:t;return Object.keys(e).reduce((r,i)=>(n.includes(i)||(r[i]=e[i]),r),{})}const Gf=(e,t)=>({tr:n,state:r,dispatch:i})=>{let o=null,l=null;const c=oo(typeof e=="string"?e:e.name,r.schema);return c?(c==="node"&&(o=ve(e,r.schema)),c==="mark"&&(l=gt(e,r.schema)),i&&n.selection.ranges.forEach(u=>{r.doc.nodesBetween(u.$from.pos,u.$to.pos,(d,h)=>{o&&o===d.type&&n.setNodeMarkup(h,void 0,lo(d.attrs,t)),l&&d.marks.length&&d.marks.forEach(p=>{l===p.type&&n.addMark(h,h+d.nodeSize,l.create(lo(p.attrs,t)))})})}),!0):!1},Wf=()=>({tr:e,dispatch:t})=>(t&&e.scrollIntoView(),!0),Rf=()=>({tr:e,commands:t})=>t.setTextSelection({from:0,to:e.doc.content.size}),Qf=()=>({state:e,dispatch:t})=>ge.selectNodeBackward(e,t),Uf=()=>({state:e,dispatch:t})=>ge.selectNodeForward(e,t),Kf=()=>({state:e,dispatch:t})=>ge.selectParentNode(e,t),Yf=()=>({state:e,dispatch:t})=>ge.selectTextblockEnd(e,t),Xf=()=>({state:e,dispatch:t})=>ge.selectTextblockStart(e,t);function Jf(e,t,n={}){return Vn(e,t,{slice:!1,parseOptions:n})}const Zf=(e,t=!1,n={})=>({tr:r,editor:i,dispatch:o})=>{const{doc:l}=r,c=Jf(e,i.schema,n);return o&&r.replaceWith(0,l.content.size,c).setMeta("preventUpdate",!t),!0};function Hf(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 eg(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 er(e){return t=>eg(t.$from,e)}function tg(e,t){const n=gt(t,e.schema),{from:r,to:i,empty:o}=e.selection,l=[];o?(e.storedMarks&&l.push(...e.storedMarks),l.push(...e.selection.$head.marks())):e.doc.nodesBetween(r,i,u=>{l.push(...u.marks)});const c=l.find(u=>u.type.name===n.name);return c?{...c.attrs}:{}}function qn(e,t,n){return Object.fromEntries(Object.entries(n).filter(([r])=>{const i=e.find(o=>o.type===t&&o.name===r);return i?i.attribute.keepOnSplit:!1}))}function ng(e,t,n={}){const{empty:r,ranges:i}=e.selection,o=t?gt(t,e.schema):null;if(r)return!!(e.storedMarks||e.selection.$from.marks()).filter(p=>o?o.name===p.type.name:!0).find(p=>$n(p.attrs,n,{strict:!1}));let l=0;const c=[];if(i.forEach(({$from:p,$to:x})=>{const m=p.pos,j=x.pos;e.doc.nodesBetween(m,j,(C,T)=>{if(!C.isText&&!C.marks.length)return;const D=Math.max(m,T),A=Math.min(j,T+C.nodeSize),N=A-D;l+=N,c.push(...C.marks.map(Y=>({mark:Y,from:D,to:A})))})}),l===0)return!1;const u=c.filter(p=>o?o.name===p.mark.type.name:!0).filter(p=>$n(p.mark.attrs,n,{strict:!1})).reduce((p,x)=>p+x.to-x.from,0),d=c.filter(p=>o?p.mark.type!==o&&p.mark.type.excludes(o):!0).reduce((p,x)=>p+x.to-x.from,0);return(u>0?u+d:u)>=l}function co(e,t){const{nodeExtensions:n}=af(t),r=n.find(l=>l.name===e);if(!r)return!1;const i={name:r.name,options:r.options,storage:r.storage},o=Bt(ft(r,"group",i));return typeof o!="string"?!1:o.split(" ").includes("list")}function sg(e,t,n){var r;const{selection:i}=t;let o=null;if(ro(i)&&(o=i.$cursor),o){const c=(r=e.storedMarks)!==null&&r!==void 0?r:o.marks();return!!n.isInSet(c)||!c.some(u=>u.type.excludes(n))}const{ranges:l}=i;return l.some(({$from:c,$to:u})=>{let d=c.depth===0?e.doc.inlineContent&&e.doc.type.allowsMarkType(n):!1;return e.doc.nodesBetween(c.pos,u.pos,(h,p,x)=>{if(d)return!1;if(h.isInline){const m=!x||x.type.allowsMarkType(n),j=!!n.isInSet(h.marks)||!h.marks.some(C=>C.type.excludes(n));d=m&&j}return!d}),d})}const rg=(e,t={})=>({tr:n,state:r,dispatch:i})=>{const{selection:o}=n,{empty:l,ranges:c}=o,u=gt(e,r.schema);if(i)if(l){const d=tg(r,u);n.addStoredMark(u.create({...d,...t}))}else c.forEach(d=>{const h=d.$from.pos,p=d.$to.pos;r.doc.nodesBetween(h,p,(x,m)=>{const j=Math.max(m,h),C=Math.min(m+x.nodeSize,p);x.marks.find(D=>D.type===u)?x.marks.forEach(D=>{u===D.type&&n.addMark(j,C,u.create({...D.attrs,...t}))}):n.addMark(j,C,u.create(t))})});return sg(r,n,u)},ig=(e,t)=>({tr:n})=>(n.setMeta(e,t),!0),ag=(e,t={})=>({state:n,dispatch:r,chain:i})=>{const o=ve(e,n.schema);return o.isTextblock?i().command(({commands:l})=>ge.setBlockType(o,t)(n)?!0:l.clearNodes()).command(({state:l})=>ge.setBlockType(o,t)(l,r)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},og=e=>({tr:t,dispatch:n})=>{if(n){const{doc:r}=t,i=_t(e,0,r.content.size),o=Me.create(r,i);t.setSelection(o)}return!0},lg=e=>({tr:t,dispatch:n})=>{if(n){const{doc:r}=t,{from:i,to:o}=typeof e=="number"?{from:e,to:e}:e,l=xe.atStart(r).from,c=xe.atEnd(r).to,u=_t(i,l,c),d=_t(o,l,c),h=xe.create(r,u,d);t.setSelection(h)}return!0},cg=e=>({state:t,dispatch:n})=>{const r=ve(e,t.schema);return ds.sinkListItem(r)(t,n)};function uo(e,t){const n=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();if(n){const r=n.filter(i=>t==null?void 0:t.includes(i.type.name));e.tr.ensureMarks(r)}}const ug=({keepMarks:e=!0}={})=>({tr:t,state:n,dispatch:r,editor:i})=>{const{selection:o,doc:l}=t,{$from:c,$to:u}=o,d=i.extensionManager.attributes,h=qn(d,c.node().type.name,c.node().attrs);if(o instanceof Me&&o.node.isBlock)return!c.parentOffset||!Ln(l,c.pos)?!1:(r&&(e&&uo(n,i.extensionManager.splittableMarks),t.split(c.pos).scrollIntoView()),!0);if(!c.parent.isBlock)return!1;if(r){const p=u.parentOffset===u.parent.content.size;o instanceof xe&&t.deleteSelection();const x=c.depth===0?void 0:Hf(c.node(-1).contentMatchAt(c.indexAfter(-1)));let m=p&&x?[{type:x,attrs:h}]:void 0,j=Ln(t.doc,t.mapping.map(c.pos),1,m);if(!m&&!j&&Ln(t.doc,t.mapping.map(c.pos),1,x?[{type:x}]:void 0)&&(j=!0,m=x?[{type:x,attrs:h}]:void 0),j&&(t.split(t.mapping.map(c.pos),1,m),x&&!p&&!c.parentOffset&&c.parent.type!==x)){const C=t.mapping.map(c.before()),T=t.doc.resolve(C);c.node(-1).canReplaceWith(T.index(),T.index()+1,x)&&t.setNodeMarkup(t.mapping.map(c.before()),x)}e&&uo(n,i.extensionManager.splittableMarks),t.scrollIntoView()}return!0},dg=e=>({tr:t,state:n,dispatch:r,editor:i})=>{var o;const l=ve(e,n.schema),{$from:c,$to:u}=n.selection,d=n.selection.node;if(d&&d.isBlock||c.depth<2||!c.sameParent(u))return!1;const h=c.node(-1);if(h.type!==l)return!1;const p=i.extensionManager.attributes;if(c.parent.content.size===0&&c.node(-1).childCount===c.indexAfter(-1)){if(c.depth===2||c.node(-3).type!==l||c.index(-2)!==c.node(-2).childCount-1)return!1;if(r){let T=J.empty;const D=c.index(-1)?1:c.index(-2)?2:3;for(let Z=c.depth-D;Z>=c.depth-3;Z-=1)T=J.from(c.node(Z).copy(T));const A=c.indexAfter(-1)<c.node(-2).childCount?1:c.indexAfter(-2)<c.node(-3).childCount?2:3,N=qn(p,c.node().type.name,c.node().attrs),Y=((o=l.contentMatch.defaultType)===null||o===void 0?void 0:o.createAndFill(N))||void 0;T=T.append(J.from(l.createAndFill(null,Y)||void 0));const R=c.before(c.depth-(D-1));t.replace(R,c.after(-A),new te(T,4-D,0));let F=-1;t.doc.nodesBetween(R,t.doc.content.size,(Z,se)=>{if(F>-1)return!1;Z.isTextblock&&Z.content.size===0&&(F=se+1)}),F>-1&&t.setSelection(xe.near(t.doc.resolve(F))),t.scrollIntoView()}return!0}const x=u.pos===c.end()?h.contentMatchAt(0).defaultType:null,m=qn(p,h.type.name,h.attrs),j=qn(p,c.node().type.name,c.node().attrs);t.delete(c.pos,u.pos);const C=x?[{type:l,attrs:m},{type:x,attrs:j}]:[{type:l,attrs:m}];if(!Ln(t.doc,c.pos,2))return!1;if(r){const{selection:T,storedMarks:D}=n,{splittableMarks:A}=i.extensionManager,N=D||T.$to.parentOffset&&T.$from.marks();if(t.split(c.pos,2,C).scrollIntoView(),!N||!r)return!0;const Y=N.filter(R=>A.includes(R.type.name));t.ensureMarks(Y)}return!0},tr=(e,t)=>{const n=er(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 i=e.doc.nodeAt(r);return n.node.type===(i==null?void 0:i.type)&&Ka(e.doc,n.pos)&&e.join(n.pos),!0},nr=(e,t)=>{const n=er(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 i=e.doc.nodeAt(r);return n.node.type===(i==null?void 0:i.type)&&Ka(e.doc,r)&&e.join(r),!0};var pg=Object.freeze({__proto__:null,blur:pf,clearContent:hf,clearNodes:xf,command:ff,createParagraphNear:gf,deleteCurrentNode:mf,deleteNode:yf,deleteRange:bf,deleteSelection:jf,enter:vf,exitCode:wf,extendMarkRange:Sf,first:_f,focus:Tf,forEach:Df,insertContent:If,insertContentAt:Af,joinUp:Ef,joinDown:Pf,joinBackward:Lf,joinForward:Bf,keyboardShortcut:$f,lift:Vf,liftEmptyBlock:qf,liftListItem:Nf,newlineInCode:Ff,resetAttributes:Gf,scrollIntoView:Wf,selectAll:Rf,selectNodeBackward:Qf,selectNodeForward:Uf,selectParentNode:Kf,selectTextblockEnd:Yf,selectTextblockStart:Xf,setContent:Zf,setMark:rg,setMeta:ig,setNode:ag,setNodeSelection:og,setTextSelection:lg,sinkListItem:cg,splitBlock:ug,splitListItem:dg,toggleList:(e,t,n,r={})=>({editor:i,tr:o,state:l,dispatch:c,chain:u,commands:d,can:h})=>{const{extensions:p,splittableMarks:x}=i.extensionManager,m=ve(e,l.schema),j=ve(t,l.schema),{selection:C,storedMarks:T}=l,{$from:D,$to:A}=C,N=D.blockRange(A),Y=T||C.$to.parentOffset&&C.$from.marks();if(!N)return!1;const R=er(F=>co(F.type.name,p))(C);if(N.depth>=1&&R&&N.depth-R.depth<=1){if(R.node.type===m)return d.liftListItem(j);if(co(R.node.type.name,p)&&m.validContent(R.node.content)&&c)return u().command(()=>(o.setNodeMarkup(R.pos,m),!0)).command(()=>tr(o,m)).command(()=>nr(o,m)).run()}return!n||!Y||!c?u().command(()=>h().wrapInList(m,r)?!0:d.clearNodes()).wrapInList(m,r).command(()=>tr(o,m)).command(()=>nr(o,m)).run():u().command(()=>{const F=h().wrapInList(m,r),Z=Y.filter(se=>x.includes(se.type.name));return o.ensureMarks(Z),F?!0:d.clearNodes()}).wrapInList(m,r).command(()=>tr(o,m)).command(()=>nr(o,m)).run()},toggleMark:(e,t={},n={})=>({state:r,commands:i})=>{const{extendEmptyMarkRange:o=!1}=n,l=gt(e,r.schema);return ng(r,l,t)?i.unsetMark(l,{extendEmptyMarkRange:o}):i.setMark(l,t)},toggleNode:(e,t,n={})=>({state:r,commands:i})=>{const o=ve(e,r.schema),l=ve(t,r.schema);return Hs(r,o,n)?i.setNode(l):i.setNode(o,n)},toggleWrap:(e,t={})=>({state:n,commands:r})=>{const i=ve(e,n.schema);return Hs(n,i,t)?r.lift(i):r.wrapIn(i,t)},undoInputRule:()=>({state:e,dispatch:t})=>{const n=e.plugins;for(let r=0;r<n.length;r+=1){const i=n[r];let o;if(i.spec.isInputRules&&(o=i.getState(e))){if(t){const l=e.tr,c=o.transform;for(let u=c.steps.length-1;u>=0;u-=1)l.step(c.steps[u].invert(c.docs[u]));if(o.text){const u=l.doc.resolve(o.from).marks();l.replaceWith(o.from,o.to,e.schema.text(o.text,u))}else l.delete(o.from,o.to)}return!0}}return!1},unsetAllMarks:()=>({tr:e,dispatch:t})=>{const{selection:n}=e,{empty:r,ranges:i}=n;return r||t&&i.forEach(o=>{e.removeMark(o.$from.pos,o.$to.pos)}),!0},unsetMark:(e,t={})=>({tr:n,state:r,dispatch:i})=>{var o;const{extendEmptyMarkRange:l=!1}=t,{selection:c}=n,u=gt(e,r.schema),{$from:d,empty:h,ranges:p}=c;if(!i)return!0;if(h&&l){let{from:x,to:m}=c;const j=(o=d.marks().find(T=>T.type===u))===null||o===void 0?void 0:o.attrs,C=so(d,u,j);C&&(x=C.from,m=C.to),n.removeMark(x,m,u)}else p.forEach(x=>{n.removeMark(x.$from.pos,x.$to.pos,u)});return n.removeStoredMark(u),!0},updateAttributes:(e,t={})=>({tr:n,state:r,dispatch:i})=>{let o=null,l=null;const c=oo(typeof e=="string"?e:e.name,r.schema);return c?(c==="node"&&(o=ve(e,r.schema)),c==="mark"&&(l=gt(e,r.schema)),i&&n.selection.ranges.forEach(u=>{const d=u.$from.pos,h=u.$to.pos;r.doc.nodesBetween(d,h,(p,x)=>{o&&o===p.type&&n.setNodeMarkup(x,void 0,{...p.attrs,...t}),l&&p.marks.length&&p.marks.forEach(m=>{if(l===m.type){const j=Math.max(x,d),C=Math.min(x+p.nodeSize,h);n.addMark(j,C,l.create({...m.attrs,...t}))}})})}),!0):!1},wrapIn:(e,t={})=>({state:n,dispatch:r})=>{const i=ve(e,n.schema);return ge.wrapIn(i,t)(n,r)},wrapInList:(e,t={})=>({state:n,dispatch:r})=>{const i=ve(e,n.schema);return ds.wrapInList(i,t)(n,r)}});Je.create({name:"commands",addCommands(){return{...pg}}}),Je.create({name:"editable",addProseMirrorPlugins(){return[new sn({key:new rn("editable"),props:{editable:()=>this.editor.options.editable}})]}}),Je.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:e}=this;return[new sn({key:new rn("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}}}})]}}),Je.create({name:"keymap",addKeyboardShortcuts(){const e=()=>this.editor.commands.first(({commands:l})=>[()=>l.undoInputRule(),()=>l.command(({tr:c})=>{const{selection:u,doc:d}=c,{empty:h,$anchor:p}=u,{pos:x,parent:m}=p,j=ie.atStart(d).from===x;return!h||!j||!m.type.isTextblock||m.textContent.length?!1:l.clearNodes()}),()=>l.deleteSelection(),()=>l.joinBackward(),()=>l.selectNodeBackward()]),t=()=>this.editor.commands.first(({commands:l})=>[()=>l.deleteSelection(),()=>l.deleteCurrentNode(),()=>l.joinForward(),()=>l.selectNodeForward()]),r={Enter:()=>this.editor.commands.first(({commands:l})=>[()=>l.newlineInCode(),()=>l.createParagraphNear(),()=>l.liftEmptyBlock(),()=>l.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:e,"Mod-Backspace":e,"Shift-Backspace":e,Delete:t,"Mod-Delete":t,"Mod-a":()=>this.editor.commands.selectAll()},i={...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 Zs()||ao()?o:i},addProseMirrorPlugins(){return[new sn({key:new rn("clearDocument"),appendTransaction:(e,t,n)=>{if(!(e.some(j=>j.docChanged)&&!t.doc.eq(n.doc)))return;const{empty:i,from:o,to:l}=t.selection,c=ie.atStart(t.doc).from,u=ie.atEnd(t.doc).to;if(i||!(o===c&&l===u)||!(n.doc.textBetween(0,n.doc.content.size," "," ").length===0))return;const p=n.tr,x=to({state:n,transaction:p}),{commands:m}=new rf({editor:this.editor,state:x});if(m.clearNodes(),!!p.steps.length)return p}})]}}),Je.create({name:"tabindex",addProseMirrorPlugins(){return[new sn({key:new rn("tabindex"),props:{attributes:this.editor.isEditable?{tabindex:"0"}:{}}})]}});const po=Je.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()}}}),hg=["8","10","12","14","16","18","20","24","30","36","48","60","72"].map(e=>`${e}px`),xg=[{label:"auto",value:""}].concat(hg.map(e=>({label:e,value:e}))),fg={input:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important"}},gg=({editor:e})=>{const t=e.getAttributes("textStyle").fontSize;return s.jsx(q.RichTextEditor.ControlsGroup,{children:s.jsx(a.NativeSelect,{size:"xs",icon:s.jsx(_.IconTextSize,{stroke:1.5,size:16}),data:xg,styles:fg,value:t||"",onChange:n=>{const r=n.currentTarget.value;r?e.chain().focus().setFontSize(r).run():e.chain().focus().unsetFontSize().run()}})})},Nn=({value:e,styles:t={},sx:n={}})=>{const r=Gi.useEditor({extensions:[Wi,Fi,q.Link,Li,Pi,Ai,$i.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),Ni,qi,Vi,Bi.configure({types:["heading","paragraph"]}),Ei.configure({placeholder:"This is placeholder"}),Oi,zi.Color,po],content:e,editable:!1});g.useEffect(()=>{r==null||r.commands.setContent(e)},[e,r]);const i=g.useMemo(()=>y.defaultsDeep({},{content:Ns},t),[t]);return s.jsx(q.RichTextEditor,{editor:r,styles:i,sx:n,children:s.jsx(q.RichTextEditor.Content,{})})};function mg(){const[e,{open:t,close:n}]=re.useDisclosure(!1);return s.jsxs(s.Fragment,{children:[s.jsx(a.Modal,{opened:e,onClose:n,title:"About FunctionUtils",zIndex:330,withinPortal:!0,children:s.jsx(Nn,{value:nd,styles:{root:{border:"none"},content:{padding:0,table:{marginBottom:0}}}})}),s.jsx(a.Button,{variant:"light",color:"violet",size:"xs",onClick:t,leftIcon:s.jsx(_.IconInfoCircle,{size:16}),children:"About parameter 'utils'"})]})}const yg=({value:e,onChange:t})=>{const n=r=>{if(!r){t("");return}t(r)};return s.jsx(a.Box,{sx:{position:"relative",flexGrow:1},children:s.jsx(fe,{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}}})})},Ot=g.forwardRef(({value:e,onChange:t,label:n,defaultValue:r},i)=>{const[o,l]=g.useState(e),c=()=>{t(o)},u=()=>{l(e)},d=()=>{l(r)};g.useEffect(()=>{l(e)},[e]);const h=o!==e;return s.jsxs(a.Stack,{spacing:4,sx:{height:"100%"},children:[s.jsxs(a.Group,{mb:6,position:"apart",sx:{flexShrink:0,flexGrow:0},children:[s.jsx(a.Group,{position:"left",children:s.jsx(mg,{})}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:d,size:"xs",variant:"default",leftIcon:s.jsx(_.IconPlayerSkipBack,{size:16}),children:"Reset to default"}),s.jsx(a.Button,{onClick:u,color:"red",size:"xs",disabled:!h,leftIcon:s.jsx(_.IconRecycle,{size:16}),children:"Revert Changes"}),s.jsx(a.Button,{size:"xs",onClick:c,disabled:!h,leftIcon:s.jsx(_.IconDeviceFloppy,{size:16}),children:"Confirm Changes"})]})]}),s.jsx(a.Text,{size:14,children:n}),s.jsx(yg,{value:o,onChange:l})]})}),ho=g.forwardRef(({title:e,value:t,onChange:n,label:r,description:i=null,triggerLabel:o="Edit",triggerButtonProps:l={},defaultValue:c},u)=>{const[d,{open:h,close:p}]=re.useDisclosure(!1);return s.jsxs(s.Fragment,{children:[s.jsxs(a.Modal,{opened:d,onClose:p,title:e,withinPortal:!0,zIndex:320,size:"900px",children:[i,s.jsx(a.Box,{h:600,children:s.jsx(Ot,{value:t,onChange:n,defaultValue:c,label:r})})]}),s.jsx(a.Button,{onClick:h,...l,children:o})]})}),bg=[{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 jg({label:e,value:t,onChange:n,pt:r="sm",withFallback:i},o){g.useEffect(()=>{typeof t=="string"&&n({type:t,config:{},fallback:"0"})},[t,n]);const l=h=>{n(h==="quantile"?{type:"quantile",config:{p:.99},fallback:t.fallback}:h==="custom"?{type:"custom",config:{func:ta},fallback:t.fallback}:{type:h,config:{},fallback:t.fallback})},c=h=>{n({type:"quantile",config:{p:h},fallback:t.fallback})},u=h=>{n({type:"custom",config:{func:h},fallback:t.fallback})},d=h=>{n({...t,fallback:h.currentTarget.value})};return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,pt:r,children:[s.jsx(a.Select,{ref:o,label:e,data:bg,value:t.type,onChange:l,maxDropdownHeight:600}),t.type==="quantile"&&s.jsx(a.NumberInput,{label:"p",value:t.config.p,onChange:c,precision:2,min:.05,step:.05,max:1}),t.type==="custom"&&s.jsx(ho,{title:"Custom Aggregation",label:"",triggerLabel:"Edit Function",value:t.config.func,onChange:u,defaultValue:ta,triggerButtonProps:{size:"xs",sx:{flexGrow:0,alignSelf:"center",marginTop:"22px"},leftIcon:s.jsx(_.IconMathFunction,{size:16})}})]}),i&&s.jsx(a.TextInput,{label:"Fallback Value",description:"Used when data is empty or the aggregation yields NaN",value:t.fallback,onChange:d})]})}const sr=g.forwardRef(jg),vg=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function wg({control:e,index:t,seriesItem:n}){const r=!!n.barWidth.trim();return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${t}.stack`,control:e,render:({field:i})=>s.jsx(a.TextInput,{label:"Stack",placeholder:"Stack bars by this ID",sx:{flexGrow:1},...i})}),s.jsx(b.Controller,{name:`series.${t}.barGap`,control:e,render:({field:i})=>s.jsx(a.Select,{label:"Bar Gap",data:vg,sx:{flexGrow:1},...i})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${t}.barMinWidth`,control:e,render:({field:i})=>s.jsx(a.TextInput,{label:"Bar Width(Min)",disabled:r,sx:{flexGrow:1},...i})}),s.jsx(b.Controller,{name:`series.${t}.barWidth`,control:e,render:({field:i})=>s.jsx(a.TextInput,{label:"Bar Width",sx:{flexGrow:1},...i})}),s.jsx(b.Controller,{name:`series.${t}.barMaxWidth`,control:e,render:({field:i})=>s.jsx(a.TextInput,{label:"Bar Width(Max)",disabled:r,sx:{flexGrow:1},...i})})]})]})}const Cg=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return s.jsx(a.Box,{children:s.jsx(fe,{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:i}]=$.useBoolean(),[o,l]=g.useState(e),c=()=>{i();const{type:p,func_content:x}=o,m={type:p,func_content:x};l(m),t(m)},u=()=>{i(),l(e)},d=p=>{l(x=>({...x,func_content:p}))},h=()=>{d(qs.dynamic.func_content)};return s.jsxs(s.Fragment,{children:[s.jsx(a.Box,{sx:{width:"50%"},children:s.jsx(a.Button,{variant:"filled",mt:24,onClick:r,sx:{flexGrow:0},children:"Setup"})}),s.jsx(a.Modal,{size:800,title:"Setup dynamic size",opened:n,onClose:i,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),s.jsx(Cg,{value:o.func_content,onChange:d}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:h,color:"red",leftIcon:s.jsx(k.Recycle,{size:20}),children:"Reset"}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:u,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:c,children:"OK"})]})]})]})})]})},_g=({value:e,onChange:t})=>e.type!=="dynamic"?null:s.jsx(Sg,{value:e,onChange:t}),kg=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=r=>{t({...e,size:r})};return s.jsx(s.Fragment,{children:s.jsx(a.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:e.size,onChange:n})})},Tg=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],xo=g.forwardRef(({label:e="Size",value:t,onChange:n},r)=>{const i=o=>{n({...qs[o]})};return s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(a.Select,{ref:r,label:e,data:Tg,value:t.type,onChange:i,sx:{flexGrow:1}}),s.jsx(kg,{value:t,onChange:n}),s.jsx(_g,{value:t,onChange:n})]})}),Dg=[{label:"off",value:"false"},{label:"start",value:"start"},{label:"middle",value:"middle"},{label:"end",value:"end"}],Ig=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function Mg({control:e,index:t,seriesItem:n}){const r=n.showSymbol;return s.jsxs(s.Fragment,{children:[s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Line Settings",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:`series.${t}.lineStyle.type`,control:e,render:({field:i})=>s.jsx(a.Select,{label:"Line Type",data:Ig,sx:{flexGrow:1},...i})}),s.jsx(b.Controller,{name:`series.${t}.lineStyle.width`,control:e,render:({field:i})=>s.jsx(a.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...i})})]}),s.jsxs(a.Group,{grow:!0,align:"center",children:[s.jsx(b.Controller,{name:`series.${t}.step`,control:e,render:({field:i})=>s.jsx(a.Select,{label:"Step",data:Dg,sx:{flexGrow:1,maxWidth:"48%"},...i,value:String(i.value),onChange:o=>{const l=o==="false"?!1:o;i.onChange(l)}})}),s.jsxs(a.Stack,{children:[s.jsx(b.Controller,{name:`series.${t}.smooth`,control:e,render:({field:i})=>s.jsx(a.Box,{sx:{flexGrow:1},children:s.jsx(a.Switch,{label:"Smooth Line",checked:i.value,onChange:o=>i.onChange(o.currentTarget.checked)})})}),s.jsx(b.Controller,{name:`series.${t}.display_name_on_line`,control:e,render:({field:i})=>s.jsx(a.Box,{sx:{flexGrow:1},children:s.jsx(a.Switch,{label:"Display Name on Line",checked:i.value??!1,onChange:o=>i.onChange(o.currentTarget.checked)})})})]})]}),s.jsxs(a.Stack,{children:[s.jsx(b.Controller,{name:`series.${t}.showSymbol`,control:e,render:({field:i})=>s.jsx(a.Box,{mt:10,mb:-10,sx:{flexGrow:1},children:s.jsx(a.Switch,{label:"Show Symbol on Line",checked:i.value,onChange:o=>i.onChange(o.currentTarget.checked)})})}),r&&s.jsx(b.Controller,{name:`series.${t}.symbolSize`,control:e,render:({field:i})=>s.jsx(xo,{label:"Symbol Size",...i})})]})]})}function zg({control:e,index:t}){return s.jsx(b.Controller,{name:`series.${t}.symbolSize`,control:e,render:({field:n})=>s.jsx(xo,{label:"Size",...n})})}const Ag=[{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 Eg({control:e,index:t,remove:n,seriesItem:r,yAxisOptions:i}){const o=r.type;return s.jsxs(a.Stack,{my:0,p:0,sx:{position:"relative"},children:[s.jsx(a.Stack,{children:s.jsx(b.Controller,{name:`series.${t}.type`,control:e,render:({field:l})=>s.jsx(a.SegmentedControl,{data:[{label:"Line",value:"line"},{label:"Bar",value:"bar"},{label:"Scatter",value:"scatter"}],...l})})}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${t}.name`,control:e,render:({field:l})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...l})}),s.jsx(b.Controller,{name:`series.${t}.yAxisIndex`,control:e,render:({field:{value:l,onChange:c,...u}})=>s.jsx(a.Select,{label:"Y Axis",data:i,disabled:i.length===0,...u,value:(l==null?void 0:l.toString())??"",onChange:d=>{if(!d){c(0);return}c(Number(d))},sx:{flex:1}})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${t}.y_axis_data_key`,control:e,render:({field:l})=>s.jsx(B,{label:"Value Field",required:!0,sx:{flex:1},...l})}),s.jsx(b.Controller,{name:`series.${t}.aggregation_on_value`,control:e,render:({field:l})=>s.jsx(sr,{label:"Aggregation on Value",value:l.value??zt,onChange:l.onChange,pt:0,withFallback:!1})})]}),s.jsx(a.Group,{grow:!0,children:s.jsx(b.Controller,{name:`series.${t}.group_by_key`,control:e,render:({field:l})=>s.jsx(B,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...l})})}),o==="line"&&s.jsx(Mg,{index:t,control:e,seriesItem:r}),o==="bar"&&s.jsx(wg,{index:t,control:e,seriesItem:r}),o==="scatter"&&s.jsx(zg,{index:t,control:e}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),s.jsx(b.Controller,{name:`series.${t}.label_position`,control:e,render:({field:l})=>s.jsx(a.Select,{label:"Label Position",data:Ag,...l})}),s.jsxs(a.Stack,{spacing:4,children:[s.jsx(a.Text,{size:"sm",children:"Color"}),s.jsx(b.Controller,{name:`series.${t}.color`,control:e,render:({field:l})=>s.jsx(Ce,{...l})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),s.jsx(b.Controller,{name:`series.${t}.hide_in_legend`,control:e,render:({field:l})=>s.jsx(a.Checkbox,{label:"Hide in legend",checked:l.value,onChange:c=>l.onChange(c.currentTarget.checked)})}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed"}),s.jsx(a.Button,{leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Series"})]})}function Pg({control:e,watch:t}){const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"series"}),o=t("series"),l=n.map((h,p)=>({...h,...o[p]})),c=()=>{const h={type:"bar",name:re.randomId(),showSymbol:!1,symbolSize:qs.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(h)},u=t("y_axes"),d=g.useMemo(()=>u.map(({name:h},p)=>({label:h,value:p.toString()})),[u]);return s.jsxs(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((h,p)=>s.jsx(a.Tabs.Tab,{value:p.toString(),children:p+1},h.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),l.map((h,p)=>s.jsx(a.Tabs.Panel,{value:p.toString(),children:s.jsx(Eg,{control:e,index:p,remove:i,seriesItem:h,yAxisOptions:d},h.id)},h.id))]})}function Lg({control:e,watch:t}){return t("stats"),s.jsx(a.Stack,{children:s.jsxs(a.Stack,{spacing:0,children:[s.jsx(b.Controller,{name:"stats.templates.top",control:e,render:({field:n})=>s.jsx(Yt,{label:"Template for stats above the chart",py:"md",sx:{flexGrow:1},...n})}),s.jsx(b.Controller,{name:"stats.templates.bottom",control:e,render:({field:n})=>s.jsx(Yt,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const Bg=()=>s.jsxs(a.Group,{sx:{display:"inline-flex"},spacing:6,mr:14,children:[s.jsx(a.Text,{children:"X Axis Data Type"}),s.jsxs(a.HoverCard,{width:340,shadow:"md",position:"top",children:[s.jsx(a.HoverCard.Target,{children:s.jsx(a.ActionIcon,{size:"xs",sx:{transform:"none !important"},children:s.jsx(_.IconInfoCircle,{})})}),s.jsx(a.HoverCard.Dropdown,{children:s.jsxs(a.Text,{size:"sm",children:["Click",s.jsx(a.Anchor,{href:"https://echarts.apache.org/en/option.html#xAxis.type",target:"_blank",mx:4,children:"here"}),"to learn more about these options"]})})]})]}),Og=[{label:"Value",value:"value"},{label:"Category",value:"category"},{label:"Time",value:"time"},{label:"Log",value:"log"}];function $g({control:e,watch:t}){return t(["x_axis_data_key","x_axis_name","x_axis"]),s.jsxs(a.Stack,{children:[s.jsx(b.Controller,{name:"x_axis_name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"X Axis Name",sx:{flex:1},...n})}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis_data_key",control:e,render:({field:n})=>s.jsx(B,{label:"X Axis Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"x_axis.type",control:e,render:({field:n})=>s.jsx(a.Select,{label:s.jsx(Bg,{}),required:!0,data:Og,sx:{flex:1},...n})})]}),s.jsx(a.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>s.jsx(a.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:s.jsx(a.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),s.jsx(b.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>s.jsx(kn,{...n})})]}),s.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>s.jsx(Re,{...n})})]})}const Vg=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],qg=[{label:"left",value:"left"},{label:"right",value:"right"}];function Ng({control:e,index:t,remove:n}){return s.jsxs(a.Stack,{my:0,p:"0",sx:{position:"relative"},children:[s.jsx(a.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`y_axes.${t}.name`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`y_axes.${t}.nameAlignment`,control:e,render:({field:r})=>s.jsx(a.Select,{label:"Name Anchor",required:!0,data:Vg,sx:{flex:1},...r})})]}),s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:`y_axes.${t}.position`,control:e,render:({field:r})=>s.jsx(a.Select,{label:"Position",required:!0,data:qg,sx:{flex:1},...r})})}),s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),s.jsx(b.Controller,{name:`y_axes.${t}.label_formatter`,control:e,render:({field:r})=>s.jsx(Ve,{...r})})]}),s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:`y_axes.${t}.min`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Min",...r})}),s.jsx(b.Controller,{name:`y_axes.${t}.max`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Max",...r})})]})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),s.jsx(b.Controller,{name:`y_axes.${t}.show`,control:e,render:({field:r})=>s.jsx(a.Checkbox,{label:"Visible",checked:r.value,onChange:i=>r.onChange(i.currentTarget.checked)})}),s.jsx(a.Button,{mt:20,leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this YAxis"})]})}function Fg({control:e,watch:t}){const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"y_axes"}),o=t("y_axes"),l=n.map((u,d)=>({...u,...o[d]})),c=()=>r({name:"",position:"left",nameAlignment:"left",label_formatter:me,min:"",max:"",show:!0});return s.jsxs(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((u,d)=>s.jsx(a.Tabs.Tab,{value:d.toString(),children:d+1},u.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),l.map((u,d)=>s.jsx(a.Tabs.Panel,{value:d.toString(),children:s.jsx(Ng,{control:e,index:d,remove:i})},u.id))]})}const Gg=({control:e,index:t,remove:n})=>s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>s.jsx(B,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed"}),s.jsx(a.Button,{leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),Wg=({control:e,watch:t})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((p,x)=>({...p,...o[x]})),c=()=>r({id:Date.now().toString(),data_key:"",name:""}),u=t("tooltip.metrics.0.id"),[d,h]=g.useState(()=>u??null);return g.useEffect(()=>{u&&h(p=>p!==null?p:u)},[u]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(k.InfoCircle,{size:14,color:"#888"}),s.jsx(a.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),s.jsxs(a.Tabs,{value:d,onTabChange:p=>h(p),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((p,x)=>s.jsx(a.Tabs.Tab,{value:p.id,children:p.name?p.name:x},p.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),l.map((p,x)=>s.jsx(a.Tabs.Panel,{value:p.id,children:s.jsx(Gg,{control:e,index:x,remove:i},p.id)},p.id))]})]})};function Rg({control:e,watch:t}){return s.jsx(a.Stack,{children:s.jsx(Wg,{control:e,watch:t})})}function Qg({context:e}){const{value:t,set:n}=O(e.instanceData,"config"),{variables:r}=e,i=g.useMemo(()=>y.defaultsDeep({},t,$s),[t]),{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=b.useForm({defaultValues:i});g.useEffect(()=>{d(i)},[i]);const h=u(),p=g.useMemo(()=>!y.isEqual(h,i),[h,i]);return c(["dataZoom"]),s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:l(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Chart Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Tabs,{defaultValue:"Series",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"X Axis",children:"X Axis"}),s.jsx(a.Tabs.Tab,{value:"Y Axes",children:"Y Axes"}),s.jsx(a.Tabs.Tab,{value:"Series",children:"Series"}),s.jsx(a.Tabs.Tab,{value:"Regression Lines",children:"Regression Lines"}),s.jsx(a.Tabs.Tab,{value:"Tooltip",children:"Tooltip"}),s.jsx(a.Tabs.Tab,{value:"Stats",children:"Stats"}),s.jsx(a.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"}),s.jsx(a.Tabs.Tab,{value:"Reference Areas",children:"Reference Areas"}),s.jsx(a.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),s.jsx(a.Tabs.Panel,{value:"X Axis",children:s.jsx($g,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Y Axes",children:s.jsx(Fg,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Series",children:s.jsx(Pg,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Regression Lines",children:s.jsx(Gx,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(Rg,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Stats",children:s.jsx(Lg,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Reference Lines",children:s.jsx(Vx,{variables:r,control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Reference Areas",children:s.jsx(Lx,{variables:r,control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Zooming",children:s.jsx(b.Controller,{name:"dataZoom",control:o,render:({field:x})=>s.jsx(Tn,{...x})})})]})]})})}function Ug(e){const t=y.cloneDeep(y.omit(e,"variables"));return t.stats=y.omit(t.stats,"variables"),t}function Kg(e){const{rotate:t,formatter:n=Pe}=e.x_axis.axisLabel;return{...e,x_axis:{...e.x_axis,axisLabel:{rotate:t,formatter:n}}}}function Yg(e){const{dataZoom:t=bt,...n}=e;return{...n,dataZoom:t}}function Xg(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return y.defaultsDeep(t,e)}function Jg(e){const t=e.reference_lines.map(n=>{const{lineStyle:r={type:"dashed",width:1,color:tt.random().css()},show_in_legend:i=!1}=n;return{...n,lineStyle:r,show_in_legend:i}});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 Hg(e){const t=e.series.map(n=>{const{aggregation_on_group:r=zt}=n;return{...n,aggregation_on_group:r}});return{...e,series:t}}function em(e){const t=e.series.map(n=>{const{aggregation_on_value:r=zt}=n;return{...n,aggregation_on_value:r}});return{...e,series:t}}function tm(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 y.defaultsDeep(r,e)}function nm(e){const{series:t,...n}=e;return{...n,series:t.map(r=>{const{barMinWidth:i,barWidth:o,barMaxWidth:l}=r;return i?{...r,barMinWidth:i,barWidth:"",barMaxWidth:l??o}:{...r,barMinWidth:"",barWidth:o,barMaxWidth:""}})}}function sm(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(r=>{const{min:i="",max:o=""}=r;return{...r,min:i,max:o}})}}function rm(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(r=>{const{nameAlignment:i="left"}=r;return{...r,nameAlignment:i}})}}function im(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(r=>{const{show:i=!0}=r;return{...r,show:i}})}}function am(e){const{regressions:t,...n}=e;return{...n,regressions:t.map(r=>{const{group_by_key:i=""}=r;return{...r,group_by_key:i}})}}function om(e){const{series:t,y_axes:n,...r}=e;return{...r,series:t.map(i=>{const{hide_in_legend:o=!1,aggregation_on_value:l=zt}=i;return{...i,hide_in_legend:o,aggregation_on_value:l}}),y_axes:n.map(i=>{const{min:o="",max:l="",show:c=!0}=i;return{...i,min:o,max:l,show:c}})}}function lm(e){const{type:t="category",...n}=e.x_axis;return{...e,x_axis:{...n,type:t}}}function cm(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis_data_key:i,series:o,regressions:l,...c}=e;return{...c,x_axis_data_key:r(i),series:o.map(u=>({...u,y_axis_data_key:r(u.y_axis_data_key),group_by_key:r(u.group_by_key)})),regressions:l.map(u=>({...u,y_axis_data_key:r(u.y_axis_data_key),group_by_key:r(u.group_by_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}function um(e){const{tooltip:t={metrics:[]},...n}=e;return{...e,tooltip:t}}class dm extends ae{constructor(){super(...arguments);P(this,"VERSION",19)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,{panelModel:r})=>{const{config:i}=n;return(i.variables||[]).forEach(c=>{r.variables.find(u=>u.name===c.name)||r.addVariable(c)}),(y.get(i,"stats.variables")||[]).forEach(c=>{r.variables.find(u=>u.name===c.name)||r.addVariable(c)}),{...n,version:2,config:Ug(i)}}),this.version(3,n=>({...n,version:3,config:Kg(n.config)})),this.version(4,n=>({...n,version:4,config:Yg(n.config)})),this.version(5,n=>({...n,version:5,config:Xg(n.config)})),this.version(6,n=>({...n,version:6,config:Jg(n.config)})),this.version(7,n=>({...n,version:7,config:Zg(n.config)})),this.version(8,n=>({...n,version:8,config:Hg(n.config)})),this.version(9,n=>({...n,version:9,config:em(n.config)})),this.version(10,n=>({...n,version:10,config:tm(n.config)})),this.version(11,n=>({...n,version:11,config:nm(n.config)})),this.version(12,n=>({...n,version:12,config:sm(n.config)})),this.version(13,n=>({...n,version:13,config:rm(n.config)})),this.version(14,n=>({...n,version:14,config:im(n.config)})),this.version(15,n=>({...n,version:15,config:am(n.config)})),this.version(16,n=>({...n,version:16,config:om(n.config)})),this.version(17,n=>({...n,version:17,config:lm(n.config)})),this.version(18,(n,r)=>({...n,version:18,config:cm(n.config,r)})),this.version(19,n=>({...n,version:19,config:um(n.config)}))}}const pm={displayName:"Cartesian Chart",displayGroup:"ECharts-based charts",migrator:new dm,name:"cartesian",viewRender:zx,configRender:Qg,createConfig(){return{version:19,config:y.cloneDeep($s)}},triggers:[Os]};function hm(e){if(e.enable_value)return e.value}function xm(e){if(e.enable_value)return e.value}function fm(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"&&y.get(r,n)&&n===e.funnelAlign&&y.set(r,n,t),r}function gm(e,t){return e.series.map(n=>{const{level_name_data_key:r,level_value_data_key:i,axisLabel:o,min:l,max:c,funnelAlign:u,orient:d,...h}=n;if(!r||!i)return{};const p=z(r),x=z(i),m=t[p.queryID].map(C=>({name:C[p.columnKey],value:C[x.columnKey]})),j=Be(o.overflow.on_axis);return{type:"funnel",...fm(n),min:hm(l),max:xm(c),minSize:l.size,maxSize:c.size,...h,label:{show:!0,position:o.position,...j},orient:d,funnelAlign:d==="horizontal"?"center":u,data:m}})}function mm({conf:e,params:t,max:n}){const{name:r,value:i}=t.data,o=G(i/n,{output:"percent",mantissa:2,trimMantissa:!0,absolute:!1});return[{label:`${t.marker} ${r}`,value:`${i} (${o})`,style:{label:"",value:""}}]}function ym(e,t){var o;const n=z(e.series[0].level_name_data_key),r=z(e.series[0].level_value_data_key),i=(o=y.maxBy(t[n.queryID],r.columnKey))==null?void 0:o[r.columnKey];return l=>{const u=mm({conf:e,params:l,max:i}).map(h=>`
133
133
  <tr>
134
134
  <th style="text-align: right;">
135
135
  <div style="${h.style.label}">${h.label}</div>
@@ -143,9 +143,9 @@ Check the top-level render call using <`+E+">.")}return I}}function rc(w,I){{if(
143
143
  ${l.seriesName}
144
144
  </div>
145
145
  <table style="width: auto">
146
- <tbody>${c.join("")}</tbody>
146
+ <tbody>${u.join("")}</tbody>
147
147
  </table>
148
- `}}function ym(e,t){return ne.getTooltip({trigger:"item",formatter:mm(e,t)})}function bm(e,t){return{grid:{top:0,left:0,right:0,bottom:0},tooltip:ym(e,t),series:fm(e,t)}}function jm(e){return e||(e=Date.now().toString()),{id:e,name:e,level_name_data_key:"",level_value_data_key:"",min:{value:0,enable_value:!1,size:"0%"},max:{value:0,enable_value:!1,size:"100%"},gap:2,axisLabel:{show:!0,position:"inside",overflow:Me()},sort:"descending",orient:"vertical",funnelAlign:"center"}}const ir={series:[jm("Funnel")]};J.use([ie.FunnelChart,B.DataZoomComponent,B.GridComponent,B.LegendComponent,B.TooltipComponent,_e.CanvasRenderer]);function vm({conf:e,data:t,width:n,height:r}){const i=g.useMemo(()=>bm(e,t),[e,t]);return s.jsx(Se,{echarts:J,option:i,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})}function wm({context:e}){const{value:t}=$(e.instanceData,"config"),n=g.useMemo(()=>y.defaults({},t,ir),[t]),r=e.data,{width:i,height:o}=e.viewport;return!i||!o?null:s.jsx(Ie,{width:i,height:o,children:s.jsx(vm,{width:Qe(i),height:Ue(o),data:r,conf:n})})}const Cm=[{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"}],ar=g.forwardRef(({label:e,value:t,onChange:n,options:r=Cm},i)=>s.jsx(a.Select,{ref:i,label:e,data:r,value:t,onChange:n})),Sm=[{label:"Ascending",value:"ascending"},{label:"Descending",value:"descending"},{label:"Use original data order",value:"0"}],_m=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],km=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}],Tm={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"}]},Dm=({item:e,control:t,index:n,remove:r})=>{const i=e.min.enable_value,o=e.max.enable_value,{orient:l}=e;return s.jsxs(a.Stack,{children:[s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:`series.${n}.name`,control:t,render:({field:u})=>s.jsx(a.TextInput,{label:"Series Name",...u})})}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${n}.level_name_data_key`,control:t,render:({field:u})=>s.jsx(O,{label:"Level Name Field",...u})}),s.jsx(b.Controller,{name:`series.${n}.level_value_data_key`,control:t,render:({field:u})=>s.jsx(O,{label:"Level Value Field",...u})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Funnel Style",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${n}.min.value`,control:t,render:({field:u})=>s.jsx(a.NumberInput,{disabled:!i,labelProps:{display:"block"},label:s.jsxs(a.Group,{position:"apart",pr:6,sx:{width:"100%"},children:[s.jsx(a.Text,{children:"Min Value"}),s.jsx(a.Tooltip,{label:"Check to enable specific min value",children:s.jsx(a.Box,{children:s.jsx(b.Controller,{name:`series.${n}.min.enable_value`,control:t,render:({field:c})=>s.jsx(a.Checkbox,{size:"xs",checked:c.value,onChange:d=>c.onChange(d.currentTarget.checked)})})})})]}),...u})}),s.jsx(b.Controller,{name:`series.${n}.min.size`,control:t,render:({field:u})=>s.jsx(a.TextInput,{placeholder:"0%",label:"Min Size",...u})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${n}.max.value`,control:t,render:({field:u})=>s.jsx(a.NumberInput,{disabled:!o,labelProps:{display:"block"},label:s.jsxs(a.Group,{position:"apart",pr:6,sx:{width:"100%"},children:[s.jsx(a.Text,{children:"Max Value"}),s.jsx(a.Tooltip,{label:"Check to enable specific max value",children:s.jsx(a.Box,{children:s.jsx(b.Controller,{name:`series.${n}.max.enable_value`,control:t,render:({field:c})=>s.jsx(a.Checkbox,{size:"xs",checked:c.value,onChange:d=>c.onChange(d.currentTarget.checked)})})})})]}),...u})}),s.jsx(b.Controller,{name:`series.${n}.max.size`,control:t,render:({field:u})=>s.jsx(a.TextInput,{placeholder:"100%",label:"Max Size",...u})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${n}.orient`,control:t,render:({field:u})=>s.jsx(a.Select,{label:"Orientation",data:km,...u})}),s.jsx(b.Controller,{name:`series.${n}.sort`,control:t,render:({field:u})=>s.jsx(a.Select,{label:"Sort",data:Sm,...u})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${n}.funnelAlign`,control:t,render:({field:u})=>s.jsx(a.Select,{label:"Align",disabled:l==="horizontal",data:_m,...u})}),s.jsx(b.Controller,{name:`series.${n}.gap`,control:t,render:({field:u})=>s.jsx(a.NumberInput,{placeholder:"0, 5, 10...",label:"Gap",...u})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Label Style",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${n}.axisLabel.position`,control:t,render:({field:u})=>s.jsx(ar,{label:"Position",options:Tm[l],...u})}),s.jsx(a.Box,{})]}),s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:`series.${n}.axisLabel.overflow`,control:t,render:({field:u})=>s.jsx(Ke,{...u})})})]})},Im=({control:e,watch:t})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"series"}),o=t("series"),l=n.map((h,p)=>({...h,...o[p]})),u=y.get(l,"0.id"),[c,d]=g.useState(u??null);return g.useEffect(()=>{u&&d(h=>h!==null?h:u)},[u]),s.jsxs(a.Tabs,{value:c,onTabChange:h=>d(h),styles:{panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((h,p)=>s.jsx(a.Tabs.Tab,{value:h.id,children:h.name},h.id)),s.jsx(a.Tabs.Tab,{value:"add",disabled:!0,children:s.jsx(a.Tooltip,{label:"TODO",children:s.jsx(a.Center,{children:s.jsx(_.IconPlus,{size:18,color:"#228be6"})})})})]}),l.map((h,p)=>s.jsx(a.Tabs.Panel,{value:h.id,children:s.jsx(Dm,{item:h,control:e,index:p,remove:i})},h.id))]})};function Mm({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=g.useMemo(()=>y.defaultsDeep({},t,ir),[t]),{control:i,handleSubmit:o,watch:l,getValues:u,reset:c}=b.useForm({defaultValues:r});g.useEffect(()=>{c(r)},[r]),l([]);const d=u(),h=g.useMemo(()=>!y.isEqual(d,r),[d,r]);return s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:o(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Funnel Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsx(Im,{control:i,watch:l})]})})}function zm(e){return{series:e.series.map(t=>{const{min:n,minSize:r,max:i,maxSize:o,...l}=t;return{...l,min:{value:n,use_data_min:!1,size:r},max:{value:i,use_data_max:!1,size:o}}})}}function Am(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=l=>l&&`${n}.${l}`,{series:i,...o}=e;return{...o,series:i.map(l=>({...l,level_name_data_key:r(l.level_name_data_key),level_value_data_key:r(l.level_value_data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class Em extends ue{constructor(){super(...arguments);L(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{config:r}=n;return{...n,version:2,config:zm(r)}}),this.version(3,(n,r)=>{const{config:i}=n;return{...n,version:3,config:Am(i,r)}})}}const Lm={displayName:"Funnel Chart",displayGroup:"ECharts-based charts",migrator:new Em,name:"funnel",viewRender:wm,configRender:Mm,createConfig:()=>({version:3,config:ir})};function xo({enabled:e,func_content:t}){return(n,r)=>{if(!e)return n;try{return new Function(`return ${t}`)()(n,r)}catch(i){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${i.message}`),n}}}function Pm(e){const t=xo(e.x_axis.axisLabel.formatter),n=xo(e.y_axis.axisLabel.formatter);return{x_axis:t,y_axis:n}}function Bm(e){return{heat_block:function(r){if(!e.heat_block.value_formatter)return r;try{return W(r,e.heat_block.value_formatter)}catch(i){return console.error(i),r}}}}function Om(e){let t=0;return e.x_axis.name&&(t+=20),{show:!0,top:45,left:5,right:5,bottom:t,containLabel:!0,borderColor:"none",backgroundColor:"#E7E7E9",z:1}}function $m(e,t,n){const{heat_block:r}=e;return{type:"heatmap",name:r.name,xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{borderColor:"white",borderWidth:n},data:t,label:r.label,labelLayout:{hideOverlap:!0},z:2}}const Vm=e=>W(e,{output:"number",trimMantissa:!0,mantissa:2,absolute:!1});function qm({conf:e,labelFormatters:t,valueFormatters:n,dataDict:r,params:i}){const{value:o,dataIndex:l}=i,[u,c,d]=o,h={label:e.x_axis.name?e.x_axis.name:"X Axis",value:t.x_axis(u,l),style:{label:"",value:$e(e.x_axis.axisLabel.overflow.in_tooltip)}},p={label:e.y_axis.name?e.y_axis.name:"Y Axis",value:t.y_axis(c,l),style:{label:"",value:$e(e.y_axis.axisLabel.overflow.in_tooltip)}},x={label:e.heat_block.name,value:n.heat_block(d),style:{label:"",value:""}},m=[h,p,x],j=r[`${u}---${c}`];return j&&e.tooltip.metrics.forEach(C=>{const T=z(C.data_key);m.push({label:C.name,value:Vm(y.get(j,T.columnKey,"")),style:{label:"",value:""}})}),m}function Nm(e,t,n,r){const{x_axis:i,y_axis:o,heat_block:l}=e,u=z(i.data_key),c=z(o.data_key);z(l.data_key);const d=y.keyBy(t[u.queryID],h=>`${h[u.columnKey]}---${h[c.columnKey]}`);return ne.getTooltip({formatter:function(h){const x=qm({conf:e,labelFormatters:n,valueFormatters:r,dataDict:d,params:h}).map(j=>`
148
+ `}}function bm(e,t){return ee.getTooltip({trigger:"item",formatter:ym(e,t)})}function jm(e,t){return{grid:{top:0,left:0,right:0,bottom:0},tooltip:bm(e,t),series:gm(e,t)}}function vm(e){return e||(e=Date.now().toString()),{id:e,name:e,level_name_data_key:"",level_value_data_key:"",min:{value:0,enable_value:!1,size:"0%"},max:{value:0,enable_value:!1,size:"100%"},gap:2,axisLabel:{show:!0,position:"inside",overflow:Te()},sort:"descending",orient:"vertical",funnelAlign:"center"}}const rr={series:[vm("Funnel")]};function wm({conf:e,data:t,width:n,height:r}){const i=g.useMemo(()=>jm(e,t),[e,t]);return s.jsx(we,{echarts:be,option:i,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})}function Cm({context:e}){const{value:t}=O(e.instanceData,"config"),n=g.useMemo(()=>y.defaults({},t,rr),[t]),r=e.data,{width:i,height:o}=e.viewport;return!i||!o?null:s.jsx(ke,{width:i,height:o,children:s.jsx(wm,{width:Ge(i),height:We(o),data:r,conf:n})})}const Sm=[{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"}],ir=g.forwardRef(({label:e,value:t,onChange:n,options:r=Sm},i)=>s.jsx(a.Select,{ref:i,label:e,data:r,value:t,onChange:n})),_m=[{label:"Ascending",value:"ascending"},{label:"Descending",value:"descending"},{label:"Use original data order",value:"0"}],km=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Tm=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}],Dm={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"}]},Im=({item:e,control:t,index:n,remove:r})=>{const i=e.min.enable_value,o=e.max.enable_value,{orient:l}=e;return s.jsxs(a.Stack,{children:[s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:`series.${n}.name`,control:t,render:({field:c})=>s.jsx(a.TextInput,{label:"Series Name",...c})})}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${n}.level_name_data_key`,control:t,render:({field:c})=>s.jsx(B,{label:"Level Name Field",...c})}),s.jsx(b.Controller,{name:`series.${n}.level_value_data_key`,control:t,render:({field:c})=>s.jsx(B,{label:"Level Value Field",...c})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Funnel Style",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${n}.min.value`,control:t,render:({field:c})=>s.jsx(a.NumberInput,{disabled:!i,labelProps:{display:"block"},label:s.jsxs(a.Group,{position:"apart",pr:6,sx:{width:"100%"},children:[s.jsx(a.Text,{children:"Min Value"}),s.jsx(a.Tooltip,{label:"Check to enable specific min value",children:s.jsx(a.Box,{children:s.jsx(b.Controller,{name:`series.${n}.min.enable_value`,control:t,render:({field:u})=>s.jsx(a.Checkbox,{size:"xs",checked:u.value,onChange:d=>u.onChange(d.currentTarget.checked)})})})})]}),...c})}),s.jsx(b.Controller,{name:`series.${n}.min.size`,control:t,render:({field:c})=>s.jsx(a.TextInput,{placeholder:"0%",label:"Min Size",...c})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${n}.max.value`,control:t,render:({field:c})=>s.jsx(a.NumberInput,{disabled:!o,labelProps:{display:"block"},label:s.jsxs(a.Group,{position:"apart",pr:6,sx:{width:"100%"},children:[s.jsx(a.Text,{children:"Max Value"}),s.jsx(a.Tooltip,{label:"Check to enable specific max value",children:s.jsx(a.Box,{children:s.jsx(b.Controller,{name:`series.${n}.max.enable_value`,control:t,render:({field:u})=>s.jsx(a.Checkbox,{size:"xs",checked:u.value,onChange:d=>u.onChange(d.currentTarget.checked)})})})})]}),...c})}),s.jsx(b.Controller,{name:`series.${n}.max.size`,control:t,render:({field:c})=>s.jsx(a.TextInput,{placeholder:"100%",label:"Max Size",...c})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${n}.orient`,control:t,render:({field:c})=>s.jsx(a.Select,{label:"Orientation",data:Tm,...c})}),s.jsx(b.Controller,{name:`series.${n}.sort`,control:t,render:({field:c})=>s.jsx(a.Select,{label:"Sort",data:_m,...c})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${n}.funnelAlign`,control:t,render:({field:c})=>s.jsx(a.Select,{label:"Align",disabled:l==="horizontal",data:km,...c})}),s.jsx(b.Controller,{name:`series.${n}.gap`,control:t,render:({field:c})=>s.jsx(a.NumberInput,{placeholder:"0, 5, 10...",label:"Gap",...c})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Label Style",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${n}.axisLabel.position`,control:t,render:({field:c})=>s.jsx(ir,{label:"Position",options:Dm[l],...c})}),s.jsx(a.Box,{})]}),s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:`series.${n}.axisLabel.overflow`,control:t,render:({field:c})=>s.jsx(Re,{...c})})})]})},Mm=({control:e,watch:t})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"series"}),o=t("series"),l=n.map((h,p)=>({...h,...o[p]})),c=y.get(l,"0.id"),[u,d]=g.useState(c??null);return g.useEffect(()=>{c&&d(h=>h!==null?h:c)},[c]),s.jsxs(a.Tabs,{value:u,onTabChange:h=>d(h),styles:{panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((h,p)=>s.jsx(a.Tabs.Tab,{value:h.id,children:h.name},h.id)),s.jsx(a.Tabs.Tab,{value:"add",disabled:!0,children:s.jsx(a.Tooltip,{label:"TODO",children:s.jsx(a.Center,{children:s.jsx(_.IconPlus,{size:18,color:"#228be6"})})})})]}),l.map((h,p)=>s.jsx(a.Tabs.Panel,{value:h.id,children:s.jsx(Im,{item:h,control:e,index:p,remove:i})},h.id))]})};function zm({context:e}){const{value:t,set:n}=O(e.instanceData,"config"),r=g.useMemo(()=>y.defaultsDeep({},t,rr),[t]),{control:i,handleSubmit:o,watch:l,getValues:c,reset:u}=b.useForm({defaultValues:r});g.useEffect(()=>{u(r)},[r]),l([]);const d=c(),h=g.useMemo(()=>!y.isEqual(d,r),[d,r]);return s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:o(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Funnel Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsx(Mm,{control:i,watch:l})]})})}function Am(e){return{series:e.series.map(t=>{const{min:n,minSize:r,max:i,maxSize:o,...l}=t;return{...l,min:{value:n,use_data_min:!1,size:r},max:{value:i,use_data_max:!1,size:o}}})}}function Em(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=l=>l&&`${n}.${l}`,{series:i,...o}=e;return{...o,series:i.map(l=>({...l,level_name_data_key:r(l.level_name_data_key),level_value_data_key:r(l.level_value_data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class Pm extends ae{constructor(){super(...arguments);P(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{config:r}=n;return{...n,version:2,config:Am(r)}}),this.version(3,(n,r)=>{const{config:i}=n;return{...n,version:3,config:Em(i,r)}})}}const Lm={displayName:"Funnel Chart",displayGroup:"ECharts-based charts",migrator:new Pm,name:"funnel",viewRender:Cm,configRender:zm,createConfig:()=>({version:3,config:rr})};function fo({enabled:e,func_content:t}){return(n,r)=>{if(!e)return n;try{return new Function(`return ${t}`)()(n,r)}catch(i){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${i.message}`),n}}}function Bm(e){const t=fo(e.x_axis.axisLabel.formatter),n=fo(e.y_axis.axisLabel.formatter);return{x_axis:t,y_axis:n}}function Om(e){return{heat_block:function(r){if(!e.heat_block.value_formatter)return r;try{return G(r,e.heat_block.value_formatter)}catch(i){return console.error(i),r}}}}function $m(e){let t=0;return e.x_axis.name&&(t+=20),{show:!0,top:45,left:5,right:5,bottom:t,containLabel:!0,borderColor:"none",backgroundColor:"#E7E7E9",z:1}}function Vm(e,t,n){const{heat_block:r}=e;return{type:"heatmap",name:r.name,xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{borderColor:"white",borderWidth:n},data:t,label:r.label,labelLayout:{hideOverlap:!0},z:2}}const qm=e=>G(e,{output:"number",trimMantissa:!0,mantissa:2,absolute:!1});function Nm({conf:e,labelFormatters:t,valueFormatters:n,dataDict:r,params:i}){const{value:o,dataIndex:l}=i,[c,u,d]=o,h={label:e.x_axis.name?e.x_axis.name:"X Axis",value:t.x_axis(c,l),style:{label:"",value:Le(e.x_axis.axisLabel.overflow.in_tooltip)}},p={label:e.y_axis.name?e.y_axis.name:"Y Axis",value:t.y_axis(u,l),style:{label:"",value:Le(e.y_axis.axisLabel.overflow.in_tooltip)}},x={label:e.heat_block.name,value:n.heat_block(d),style:{label:"",value:""}},m=[h,p,x],j=r[`${c}---${u}`];return j&&e.tooltip.metrics.forEach(C=>{const T=z(C.data_key);m.push({label:C.name,value:qm(y.get(j,T.columnKey,"")),style:{label:"",value:""}})}),m}function Fm(e,t,n,r){const{x_axis:i,y_axis:o,heat_block:l}=e,c=z(i.data_key),u=z(o.data_key);z(l.data_key);const d=y.keyBy(t[c.queryID],h=>`${h[c.columnKey]}---${h[u.columnKey]}`);return ee.getTooltip({formatter:function(h){const x=Nm({conf:e,labelFormatters:n,valueFormatters:r,dataDict:d,params:h}).map(j=>`
149
149
  <tr>
150
150
  <th style="text-align: right;">
151
151
  <div style="${j.style.label}">${j.label}</div>
@@ -166,14 +166,14 @@ Check the top-level render call using <`+E+">.")}return I}}function rc(w,I){{if(
166
166
  </thead>
167
167
  <tbody>${x.join("")}</tbody>
168
168
  </table>
169
- `}})}const Fm=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return s.jsx(a.Box,{children:s.jsx(ye,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},fo={static:{type:"static",value:10},dynamic:{type:"dynamic",value:["function getValue({ variables }, { lodash, interpolate }) {"," // your code goes here"," return 100;","}"].join(`
170
- `)}},Gm=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:i}]=V.useBoolean(),[o,l]=g.useState(e),u=()=>{i();const{type:p,value:x}=o,m={type:p,value:x};l(m),t(m)},c=()=>{i(),l(e)},d=p=>{l(x=>({...x,value:p}))},h=()=>{d(fo.dynamic.value)};return s.jsxs(s.Fragment,{children:[s.jsx(a.Box,{sx:{width:"50%"},children:s.jsx(a.Button,{variant:"filled",mt:24,onClick:r,sx:{flexGrow:0},children:"Setup"})}),s.jsx(a.Modal,{size:800,title:"Setup dynamic value",opened:n,onClose:i,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),s.jsx(Fm,{value:o.value,onChange:d}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:h,color:"red",leftIcon:s.jsx(k.Recycle,{size:20}),children:"Reset"}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:c,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:u,children:"OK"})]})]})]})})]})},Wm=({value:e,onChange:t})=>e.type!=="dynamic"?null:s.jsx(Gm,{value:e,onChange:t}),Rm=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=r=>{t({...e,value:r})};return s.jsx(a.NumberInput,{defaultValue:18,label:" ",hideControls:!0,value:e.value,onChange:n})},Qm=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Vt=g.forwardRef(({label:e="Value",value:t,onChange:n},r)=>{const i=o=>{n({...fo[o]})};return s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(a.Select,{ref:r,label:e,data:Qm,value:t.type,onChange:i,sx:{flexGrow:1}}),s.jsx(Rm,{value:t,onChange:n}),s.jsx(Wm,{value:t,onChange:n})]})});function qt(e,t,n){if(!e.type)return n;if(e.type==="static"){const{value:i}=e;return i}const{value:r}=e;try{return new Function(`return ${r}`)()({variables:t},{lodash:y,interpolate:bt.interpolate})}catch(i){return console.error(`[getNumberOrDynamicValue] failed parsing custom function, error: ${i.message}`),10}}function Um(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 Km(e,t,n,r){const{overflow:i,rotate:o}=e.x_axis.axisLabel,l=Ve(i.on_axis);return ne.getXAxis({id:"main-x-axis",type:"category",data:t,name:e.x_axis.name??"",align:"center",axisTick:{show:!0,alignWithLabel:!0},axisLabel:{rotate:o,...l,formatter:n},splitArea:{show:!1,areaStyle:{color:"#E7E7E9"}},splitLine:{show:r>0,interval:0,lineStyle:{type:"solid",color:"white"}},nameLocation:"center",nameGap:25,nameTextStyle:{fontWeight:"bold",align:"center"},z:3})}function Ym(e,t,n,r){const{nameAlignment:i,data_key:o,...l}=e.y_axis,{overflow:u,rotate:c}=e.y_axis.axisLabel,d=Ve(u.on_axis);return ne.getYAxis({...l,type:"category",data:t,axisLabel:{rotate:c,...d,formatter:n},axisTick:{show:!0,alignWithLabel:!0},axisLine:{show:!0,lineStyle:{width:3}},splitArea:{show:!1,areaStyle:{color:"#E7E7E9"}},splitLine:{show:r>0,interval:0,lineStyle:{type:"solid",color:"white"}},nameTextStyle:{fontWeight:"bold",align:i},nameLocation:"end",nameGap:15,z:3})}function Xm(e,t,n,r){return n<e*10||r<t*10?0:n<e*20||r<t*20?1:2}function Jm(e,t,n,r,i){if(!e.x_axis.data_key||!e.y_axis.data_key||!e.heat_block.data_key)return{};const o=n.reduce((T,D)=>{const A=it(D,t);return T[D.name]=Pe(D,A),T},{}),l=Pm(e),u=Bm(e),c=z(e.x_axis.data_key),d=z(e.y_axis.data_key),h=z(e.heat_block.data_key),p=y.uniq(t[c.queryID].map(T=>T[c.columnKey])),x=y.uniq(t[c.queryID].map(T=>T[d.columnKey])),m=t[c.queryID].map(T=>[y.get(T,c.columnKey),y.get(T,d.columnKey),y.get(T,h.columnKey)]),j=Xm(p.length,x.length,r,i);return{xAxis:Km(e,p,l.x_axis,j),yAxis:Ym(e,x,l.y_axis,j),series:$m(e,m,j),tooltip:Nm(e,t,l,u),grid:Om(e),visualMap:Um(e,o)}}function Zm(e){return s.jsx(s.Fragment,{})}function Hm(e){return s.jsx(a.Text,{children:"Click heat block"})}const go={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:Hm,configRender:Zm,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"}]},or={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,overflow:Me(),formatter:{...Oe}}},y_axis:{name:"Y Axis",data_key:"",nameAlignment:"center",axisLabel:{rotate:0,overflow:Me(),formatter:{...Oe}}},heat_block:{min:{type:"static",value:0},max:{type:"static",value:100},name:"Value",data_key:"",value_formatter:je,label:{show:!1,fontSize:10}},tooltip:{metrics:[]}};J.use([B.DataZoomComponent,ie.HeatmapChart,B.GridComponent,B.LegendComponent,B.TooltipComponent,B.VisualMapComponent,_e.CanvasRenderer]);function ey({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const l=g.useMemo(()=>{const p=z(e.x_axis.data_key),x=z(e.y_axis.data_key);return y.keyBy(t[p.queryID],m=>`${m[p.columnKey]}---${m[x.columnKey]}`)},[t,e.x_axis.data_key,e.y_axis.data_key]),u=qe(i.triggerManager,go.id),c=g.useCallback(p=>{const[x,m]=p.value,j=y.get(l,`${x}---${m}`,{error:"rowData is not found"});u.forEach(C=>{i.runInteraction(C.id,{...p,rowData:j})})},[l,u,i]),d=g.useMemo(()=>({click:c}),[c]),h=g.useMemo(()=>Jm(e,t,o,n,r),[e,t,n,r]);return s.jsx(Se,{echarts:J,option:h,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function ty({context:e,instance:t}){const n=Ne({vizManager:e.vizManager,instance:t}),{value:r}=$(e.instanceData,"config"),{variables:i}=e,o=g.useMemo(()=>y.defaults({},r,or),[r]),l=e.data,{width:u,height:c}=e.viewport;return!u||!c?null:s.jsx(Ie,{width:u,height:c,children:s.jsx(ey,{variables:i,width:Qe(u),height:Ue(c),data:l,conf:o,interactionManager:n})})}function ny({control:e,watch:t}){t(["heat_block"]);const n=t("heat_block.label.show");return s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"heat_block.data_key",control:e,render:({field:r})=>s.jsx(O,{label:"Data Field",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:"heat_block.name",control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",sx:{flex:1},...r})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"heat_block.min",control:e,render:({field:r})=>s.jsx(Vt,{label:"Min Value",...r})}),s.jsx(b.Controller,{name:"heat_block.max",control:e,render:({field:r})=>s.jsx(Vt,{label:"Max Value",...r})})]}),s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Value Format",labelPosition:"center"}),s.jsx(b.Controller,{name:"heat_block.value_formatter",control:e,render:({field:r})=>s.jsx(Fe,{...r})}),s.jsx(a.Divider,{mb:-5,variant:"dashed",label:"Label",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"heat_block.label.show",control:e,render:({field:r})=>s.jsx(a.Switch,{label:"Show label",checked:r.value,onChange:i=>r.onChange(i.currentTarget.checked),sx:{flexGrow:1}})}),s.jsx(b.Controller,{name:"heat_block.label.fontSize",control:e,render:({field:r})=>s.jsx(a.NumberInput,{size:"xs",icon:s.jsx(_.IconTextSize,{size:16}),disabled:!n,...r})})]})]})}const sy=({control:e,index:t,remove:n})=>s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>s.jsx(O,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed"}),s.jsx(a.Button,{leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),ry=({control:e,watch:t})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((p,x)=>({...p,...o[x]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[d,h]=g.useState(()=>c??null);return g.useEffect(()=>{c&&h(p=>p!==null?p:c)},[c]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(k.InfoCircle,{size:14,color:"#888"}),s.jsx(a.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),s.jsx(a.Divider,{variant:"dashed",my:10}),s.jsxs(a.Tabs,{value:d,onTabChange:p=>h(p),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((p,x)=>s.jsx(a.Tabs.Tab,{value:p.id,children:p.name?p.name:x},p.id)),s.jsx(a.Tabs.Tab,{onClick:u,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),l.map((p,x)=>s.jsx(a.Tabs.Panel,{value:p.id,children:s.jsx(sy,{control:e,index:x,remove:i},p.id)},p.id))]})]})};function iy({control:e,watch:t}){return s.jsx(ry,{control:e,watch:t})}const ay=({disabled:e,value:t,onChange:n})=>{const r=i=>{i&&n(i)};return s.jsxs(a.Box,{sx:{position:"relative"},children:[e&&s.jsx(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),s.jsx(ye,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},oy={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
171
- `)},mo=g.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:i,setFalse:o}]=V.useBoolean(),[l,u]=g.useState(e);g.useEffect(()=>{u(e)},[e]);const c=m=>{u({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:j}=l,C={enabled:m,func_content:j};u(C),t(C)},h=()=>{o(),u(e)},p=m=>{u(j=>({...j,func_content:m}))},x=()=>{p(oy.func_content)};return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"filled",mt:24,onClick:i,sx:{flexGrow:0},children:"Customize Label"}),s.jsx(a.Modal,{size:800,title:"Customize label content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&s.jsxs(a.Stack,{children:[s.jsx(a.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:m=>c(m.currentTarget.checked)}),s.jsx(ay,{value:l.func_content,onChange:p,disabled:!l.enabled}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:x,color:"red",leftIcon:s.jsx(k.Recycle,{size:20}),children:"Reset"}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:h,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:d,children:"OK"})]})]})]})})]})});function ly({control:e,watch:t}){return t(["x_axis"]),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>s.jsx(O,{label:"Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"x_axis.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"Name",sx:{flex:1},...n})})]}),s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Tick Label",labelPosition:"center"}),s.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>s.jsx(Ke,{...n})}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>s.jsx(a.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:s.jsx(a.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),s.jsx(b.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>s.jsx(mo,{...n})})]})]})}const uy=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function cy({control:e,watch:t}){return t(["y_axis"]),s.jsxs(a.Stack,{my:0,p:"0",sx:{position:"relative"},children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"y_axis.data_key",control:e,render:({field:n})=>s.jsx(O,{label:"Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"y_axis.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...n})})]}),s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:"y_axis.nameAlignment",control:e,render:({field:n})=>s.jsx(a.Select,{label:"Name Alignment",required:!0,data:uy,sx:{flex:1},...n})})}),s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Tick Label",labelPosition:"center"}),s.jsx(b.Controller,{name:"y_axis.axisLabel.overflow",control:e,render:({field:n})=>s.jsx(Ke,{...n})}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"y_axis.axisLabel.rotate",control:e,render:({field:n})=>s.jsx(a.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:s.jsx(a.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),s.jsx(b.Controller,{name:"y_axis.axisLabel.formatter",control:e,render:({field:n})=>s.jsx(mo,{...n})})]})]})}function dy({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=g.useMemo(()=>y.defaultsDeep({},t,or),[t]),i=g.useMemo(()=>y.cloneDeep(r),[r]);g.useEffect(()=>{!y.isEqual(r,i)&&(console.log("config malformed, resetting to defaults",r,i),n(i))},[r,i]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=b.useForm({defaultValues:i});g.useEffect(()=>{d(i)},[i]);const h=c(),p=g.useMemo(()=>!y.isEqual(h,r),[h,r]);return s.jsx("form",{onSubmit:l(n),style:{flexGrow:1},children:s.jsxs(a.Stack,{spacing:"xs",sx:{height:"100%"},children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Chart Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{root:{flexGrow:1},tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"X Axis",children:"X Axis"}),s.jsx(a.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),s.jsx(a.Tabs.Tab,{value:"Heat Block",children:"Heat Block"}),s.jsx(a.Tabs.Tab,{value:"Tooltip",children:"Tooltip"})]}),s.jsx(a.Tabs.Panel,{value:"X Axis",children:s.jsx(ly,{control:o,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Y Axis",children:s.jsx(cy,{control:o,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Heat Block",children:s.jsx(ny,{control:o,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(iy,{control:o,watch:u})})]})]})})}function py(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=d=>d&&`${n}.${d}`,{x_axis:i,y_axis:o,heat_block:l,tooltip:u,...c}=e;return{...c,x_axis:{...i,data_key:r(i.data_key)},y_axis:{...o,data_key:r(o.data_key)},heat_block:{...l,data_key:r(l.data_key)},tooltip:{...u,metrics:u.metrics.map(d=>({...d,data_key:r(d.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}function hy(e){return y.defaultsDeep({},e,{heat_block:{label:{show:!1,fontSize:10}}})}function xy(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 fy extends ue{constructor(){super(...arguments);L(this,"VERSION",4)}configVersions(){this.version(1,n=>(console.log("🟥 unexpected calling"),{version:1,config:n})),this.version(2,(n,r)=>({...n,version:2,config:py(n.config,r)})),this.version(3,n=>({...n,version:3,config:hy(n.config)})),this.version(4,n=>({...n,version:4,config:xy(n.config)}))}}const gy={displayName:"Heatmap",displayGroup:"ECharts-based charts",migrator:new fy,name:"heatmap",viewRender:ty,configRender:dy,createConfig:()=>({version:4,config:or}),triggers:[go]},yo={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:yy,configRender:my,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 my(e){return s.jsx(s.Fragment,{})}function yy(e){return s.jsx(a.Text,{children:"Click chart's series"})}const bo={label_template:"${percentage.x} of ${x_axis.name} causes ${percentage.y} of ${bar.name}",color:"#789AB4"},lr={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...Oe},overflow:Me()}},data_key:"value",bar:{name:"Value",nameAlignment:"left",color:"#228be6",label_formatter:je},line:{name:"Value",nameAlignment:"right",color:"red"},dataZoom:jt,markLine:bo};function Gn(e){return W(e,{output:"percent",mantissa:0,absolute:!1})}function by(e){const t=e.value[1];try{return Gn(t)}catch(n){return console.error(n),t}}function jy(e){function t(n){let r=n;if(typeof n=="object"&&(Array.isArray(n.value)&&n.value.length===2?r=n.value[1]:r=n.value),!e.bar.label_formatter)return r;try{return W(r,e.bar.label_formatter)}catch(i){return console.error(i),r}}return{bar:t,line:by,lineValue:Gn}}function vy(e,t,n){const{label_template:r}=e.markLine;if(!r)return"";const i={...e,percentage:t,count:n},o=Object.keys(i),l=Object.values(i);return new Function(...o,`return \`${r}\`;`)(...l)}function wy(e,t){if(t.length===0)return{};const n=t.findIndex(u=>u[1]>=.8);if(n===-1)return{};const r=t[n],i={x:Gn((n+1)/t.length),y:Gn(r[1])},o={left:n+1,right:t.length-n-1},l=r[0];return l?{markLine:{name:"",silent:!0,symbol:"triangle",symbolRotate:180,symbolSize:[10,8],data:[{name:"",symbol:"none",xAxis:l,lineStyle:{color:e.markLine.color},label:{formatter:vy(e,i,o)}}]},markArea:{name:"",silent:!0,itemStyle:{color:"rgba(47, 140, 192, 0.05)"},data:[[{coord:["min",0]},{xAxis:l}]]}}:{}}function Cy(e,t,n){const{x_axis:r,data_key:i}=e;if(!r.data_key||!i)return[];const o=z(r.data_key),l=z(i);if(o.queryID!==l.queryID)throw new Error("Please use the same query for X & Y axis");const u=t[o.queryID].map(x=>[x[o.columnKey],Number(x[l.columnKey])]).sort((x,m)=>m[1]-x[1]),c=u.reduce((x,m)=>x+m[1],0),d=u.reduce((x,m,j)=>{const C=j===0?0:x[j-1][1];return x.push([m[0],C+m[1]]),x},[]).map(x=>[x[0],x[1]/c]),{markLine:h,markArea:p}=wy(e,d);return[{name:e.bar.name,type:"bar",barMaxWidth:20,itemStyle:{color:e.bar.color},label:{show:!1,position:"top",formatter:n.bar},yAxisIndex:0,data:u},{name:e.line.name,type:"line",itemStyle:{color:e.line.color},symbolSize:2,lineStyle:{width:1,shadowColor:"rgba(255,255,255,1)",shadowBlur:0,shadowOffsetX:0,shadowOffsetY:1},label:{show:!1,position:"top",formatter:n.line},yAxisIndex:1,data:d,markLine:h,markArea:p}]}const Sy=(e,t)=>n=>{const r=Array.isArray(n)?n:[n];if(r.length===0)return"";const i=r.map((u,c)=>{const d=u.seriesName,[h,p]=u.value;if(!d)return p;const x=c===0?t.bar:t.lineValue;return`
169
+ `}})}const Gm=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return s.jsx(a.Box,{children:s.jsx(fe,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},go={static:{type:"static",value:10},dynamic:{type:"dynamic",value:["function getValue({ variables }, { lodash, interpolate }) {"," // your code goes here"," return 100;","}"].join(`
170
+ `)}},Wm=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:i}]=$.useBoolean(),[o,l]=g.useState(e),c=()=>{i();const{type:p,value:x}=o,m={type:p,value:x};l(m),t(m)},u=()=>{i(),l(e)},d=p=>{l(x=>({...x,value:p}))},h=()=>{d(go.dynamic.value)};return s.jsxs(s.Fragment,{children:[s.jsx(a.Box,{sx:{width:"50%"},children:s.jsx(a.Button,{variant:"filled",mt:24,onClick:r,sx:{flexGrow:0},children:"Setup"})}),s.jsx(a.Modal,{size:800,title:"Setup dynamic value",opened:n,onClose:i,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),s.jsx(Gm,{value:o.value,onChange:d}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:h,color:"red",leftIcon:s.jsx(k.Recycle,{size:20}),children:"Reset"}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:u,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:c,children:"OK"})]})]})]})})]})},Rm=({value:e,onChange:t})=>e.type!=="dynamic"?null:s.jsx(Wm,{value:e,onChange:t}),Qm=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=r=>{t({...e,value:r})};return s.jsx(a.NumberInput,{defaultValue:18,label:" ",hideControls:!0,value:e.value,onChange:n})},Um=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],$t=g.forwardRef(({label:e="Value",value:t,onChange:n},r)=>{const i=o=>{n({...go[o]})};return s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(a.Select,{ref:r,label:e,data:Um,value:t.type,onChange:i,sx:{flexGrow:1}}),s.jsx(Qm,{value:t,onChange:n}),s.jsx(Rm,{value:t,onChange:n})]})});function Vt(e,t,n){if(!e.type)return n;if(e.type==="static"){const{value:i}=e;return i}const{value:r}=e;try{return new Function(`return ${r}`)()({variables:t},{lodash:y,interpolate:yt.interpolate})}catch(i){return console.error(`[getNumberOrDynamicValue] failed parsing custom function, error: ${i.message}`),10}}function Km(e,t){const n=Vt(e.heat_block.min,t),r=Vt(e.heat_block.max,t);return{min:n,max:r,calculable:!0,orient:"horizontal",left:"center",top:0,itemWidth:15}}function Ym(e,t,n,r){const{overflow:i,rotate:o}=e.x_axis.axisLabel,l=Be(i.on_axis);return ee.getXAxis({id:"main-x-axis",type:"category",data:t,name:e.x_axis.name??"",align:"center",axisTick:{show:!0,alignWithLabel:!0},axisLabel:{rotate:o,...l,formatter:n},splitArea:{show:!1,areaStyle:{color:"#E7E7E9"}},splitLine:{show:r>0,interval:0,lineStyle:{type:"solid",color:"white"}},nameLocation:"center",nameGap:25,nameTextStyle:{fontWeight:"bold",align:"center"},z:3})}function Xm(e,t,n,r){const{nameAlignment:i,data_key:o,...l}=e.y_axis,{overflow:c,rotate:u}=e.y_axis.axisLabel,d=Be(c.on_axis);return ee.getYAxis({...l,type:"category",data:t,axisLabel:{rotate:u,...d,formatter:n},axisTick:{show:!0,alignWithLabel:!0},axisLine:{show:!0,lineStyle:{width:3}},splitArea:{show:!1,areaStyle:{color:"#E7E7E9"}},splitLine:{show:r>0,interval:0,lineStyle:{type:"solid",color:"white"}},nameTextStyle:{fontWeight:"bold",align:i},nameLocation:"end",nameGap:15,z:3})}function Jm(e,t,n,r){return n<e*10||r<t*10?0:n<e*20||r<t*20?1:2}function Zm(e,t,n,r,i){if(!e.x_axis.data_key||!e.y_axis.data_key||!e.heat_block.data_key)return{};const o=n.reduce((T,D)=>{const A=st(D,t);return T[D.name]=Ae(D,A),T},{}),l=Bm(e),c=Om(e),u=z(e.x_axis.data_key),d=z(e.y_axis.data_key),h=z(e.heat_block.data_key),p=y.uniq(t[u.queryID].map(T=>T[u.columnKey])),x=y.uniq(t[u.queryID].map(T=>T[d.columnKey])),m=t[u.queryID].map(T=>[y.get(T,u.columnKey),y.get(T,d.columnKey),y.get(T,h.columnKey)]),j=Jm(p.length,x.length,r,i);return{xAxis:Ym(e,p,l.x_axis,j),yAxis:Xm(e,x,l.y_axis,j),series:Vm(e,m,j),tooltip:Fm(e,t,l,c),grid:$m(e),visualMap:Km(e,o)}}function Hm(e){return s.jsx(s.Fragment,{})}function ey(e){return s.jsx(a.Text,{children:"Click heat block"})}const mo={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:ey,configRender:Hm,payload:[{name:"seriesType",description:"'heatmap'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]},ar={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,overflow:Te(),formatter:{...Pe}}},y_axis:{name:"Y Axis",data_key:"",nameAlignment:"center",axisLabel:{rotate:0,overflow:Te(),formatter:{...Pe}}},heat_block:{min:{type:"static",value:0},max:{type:"static",value:100},name:"Value",data_key:"",value_formatter:me,label:{show:!1,fontSize:10}},tooltip:{metrics:[]}};function ty({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const l=g.useMemo(()=>{const p=z(e.x_axis.data_key),x=z(e.y_axis.data_key);return y.keyBy(t[p.queryID],m=>`${m[p.columnKey]}---${m[x.columnKey]}`)},[t,e.x_axis.data_key,e.y_axis.data_key]),c=Oe(i.triggerManager,mo.id),u=g.useCallback(p=>{const[x,m]=p.value,j=y.get(l,`${x}---${m}`,{error:"rowData is not found"});c.forEach(C=>{i.runInteraction(C.id,{...p,rowData:j})})},[l,c,i]),d=g.useMemo(()=>({click:u}),[u]),h=g.useMemo(()=>Zm(e,t,o,n,r),[e,t,n,r]);return s.jsx(we,{echarts:be,option:h,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function ny({context:e,instance:t}){const n=$e({vizManager:e.vizManager,instance:t}),{value:r}=O(e.instanceData,"config"),{variables:i}=e,o=g.useMemo(()=>y.defaults({},r,ar),[r]),l=e.data,{width:c,height:u}=e.viewport;return!c||!u?null:s.jsx(ke,{width:c,height:u,children:s.jsx(ty,{variables:i,width:Ge(c),height:We(u),data:l,conf:o,interactionManager:n})})}function sy({control:e,watch:t}){t(["heat_block"]);const n=t("heat_block.label.show");return s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"heat_block.data_key",control:e,render:({field:r})=>s.jsx(B,{label:"Data Field",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:"heat_block.name",control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",sx:{flex:1},...r})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"heat_block.min",control:e,render:({field:r})=>s.jsx($t,{label:"Min Value",...r})}),s.jsx(b.Controller,{name:"heat_block.max",control:e,render:({field:r})=>s.jsx($t,{label:"Max Value",...r})})]}),s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Value Format",labelPosition:"center"}),s.jsx(b.Controller,{name:"heat_block.value_formatter",control:e,render:({field:r})=>s.jsx(Ve,{...r})}),s.jsx(a.Divider,{mb:-5,variant:"dashed",label:"Label",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"heat_block.label.show",control:e,render:({field:r})=>s.jsx(a.Switch,{label:"Show label",checked:r.value,onChange:i=>r.onChange(i.currentTarget.checked),sx:{flexGrow:1}})}),s.jsx(b.Controller,{name:"heat_block.label.fontSize",control:e,render:({field:r})=>s.jsx(a.NumberInput,{size:"xs",icon:s.jsx(_.IconTextSize,{size:16}),disabled:!n,...r})})]})]})}const ry=({control:e,index:t,remove:n})=>s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>s.jsx(B,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed"}),s.jsx(a.Button,{leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),iy=({control:e,watch:t})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((p,x)=>({...p,...o[x]})),c=()=>r({id:Date.now().toString(),data_key:"",name:""}),u=t("tooltip.metrics.0.id"),[d,h]=g.useState(()=>u??null);return g.useEffect(()=>{u&&h(p=>p!==null?p:u)},[u]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(k.InfoCircle,{size:14,color:"#888"}),s.jsx(a.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),s.jsx(a.Divider,{variant:"dashed",my:10}),s.jsxs(a.Tabs,{value:d,onTabChange:p=>h(p),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((p,x)=>s.jsx(a.Tabs.Tab,{value:p.id,children:p.name?p.name:x},p.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),l.map((p,x)=>s.jsx(a.Tabs.Panel,{value:p.id,children:s.jsx(ry,{control:e,index:x,remove:i},p.id)},p.id))]})]})};function ay({control:e,watch:t}){return s.jsx(iy,{control:e,watch:t})}const oy=({disabled:e,value:t,onChange:n})=>{const r=i=>{i&&n(i)};return s.jsxs(a.Box,{sx:{position:"relative"},children:[e&&s.jsx(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),s.jsx(fe,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},ly={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
171
+ `)},yo=g.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:i,setFalse:o}]=$.useBoolean(),[l,c]=g.useState(e);g.useEffect(()=>{c(e)},[e]);const u=m=>{c({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:j}=l,C={enabled:m,func_content:j};c(C),t(C)},h=()=>{o(),c(e)},p=m=>{c(j=>({...j,func_content:m}))},x=()=>{p(ly.func_content)};return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"filled",mt:24,onClick:i,sx:{flexGrow:0},children:"Customize Label"}),s.jsx(a.Modal,{size:800,title:"Customize label content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&s.jsxs(a.Stack,{children:[s.jsx(a.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:m=>u(m.currentTarget.checked)}),s.jsx(oy,{value:l.func_content,onChange:p,disabled:!l.enabled}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:x,color:"red",leftIcon:s.jsx(k.Recycle,{size:20}),children:"Reset"}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:h,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:d,children:"OK"})]})]})]})})]})});function cy({control:e,watch:t}){return t(["x_axis"]),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>s.jsx(B,{label:"Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"x_axis.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"Name",sx:{flex:1},...n})})]}),s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Tick Label",labelPosition:"center"}),s.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>s.jsx(Re,{...n})}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>s.jsx(a.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:s.jsx(a.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),s.jsx(b.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>s.jsx(yo,{...n})})]})]})}const uy=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function dy({control:e,watch:t}){return t(["y_axis"]),s.jsxs(a.Stack,{my:0,p:"0",sx:{position:"relative"},children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"y_axis.data_key",control:e,render:({field:n})=>s.jsx(B,{label:"Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"y_axis.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...n})})]}),s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:"y_axis.nameAlignment",control:e,render:({field:n})=>s.jsx(a.Select,{label:"Name Alignment",required:!0,data:uy,sx:{flex:1},...n})})}),s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Tick Label",labelPosition:"center"}),s.jsx(b.Controller,{name:"y_axis.axisLabel.overflow",control:e,render:({field:n})=>s.jsx(Re,{...n})}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"y_axis.axisLabel.rotate",control:e,render:({field:n})=>s.jsx(a.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:s.jsx(a.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),s.jsx(b.Controller,{name:"y_axis.axisLabel.formatter",control:e,render:({field:n})=>s.jsx(yo,{...n})})]})]})}function py({context:e}){const{value:t,set:n}=O(e.instanceData,"config"),r=g.useMemo(()=>y.defaultsDeep({},t,ar),[t]),i=g.useMemo(()=>y.cloneDeep(r),[r]);g.useEffect(()=>{!y.isEqual(r,i)&&(console.log("config malformed, resetting to defaults",r,i),n(i))},[r,i]);const{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=b.useForm({defaultValues:i});g.useEffect(()=>{d(i)},[i]);const h=u(),p=g.useMemo(()=>!y.isEqual(h,r),[h,r]);return s.jsx("form",{onSubmit:l(n),style:{flexGrow:1},children:s.jsxs(a.Stack,{spacing:"xs",sx:{height:"100%"},children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Chart Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{root:{flexGrow:1},tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"X Axis",children:"X Axis"}),s.jsx(a.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),s.jsx(a.Tabs.Tab,{value:"Heat Block",children:"Heat Block"}),s.jsx(a.Tabs.Tab,{value:"Tooltip",children:"Tooltip"})]}),s.jsx(a.Tabs.Panel,{value:"X Axis",children:s.jsx(cy,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Y Axis",children:s.jsx(dy,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Heat Block",children:s.jsx(sy,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(ay,{control:o,watch:c})})]})]})})}function hy(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=d=>d&&`${n}.${d}`,{x_axis:i,y_axis:o,heat_block:l,tooltip:c,...u}=e;return{...u,x_axis:{...i,data_key:r(i.data_key)},y_axis:{...o,data_key:r(o.data_key)},heat_block:{...l,data_key:r(l.data_key)},tooltip:{...c,metrics:c.metrics.map(d=>({...d,data_key:r(d.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}function xy(e){return y.defaultsDeep({},e,{heat_block:{label:{show:!1,fontSize:10}}})}function fy(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 gy extends ae{constructor(){super(...arguments);P(this,"VERSION",4)}configVersions(){this.version(1,n=>(console.log("🟥 unexpected calling"),{version:1,config:n})),this.version(2,(n,r)=>({...n,version:2,config:hy(n.config,r)})),this.version(3,n=>({...n,version:3,config:xy(n.config)})),this.version(4,n=>({...n,version:4,config:fy(n.config)}))}}const my={displayName:"Heatmap",displayGroup:"ECharts-based charts",migrator:new gy,name:"heatmap",viewRender:ny,configRender:py,createConfig:()=>({version:4,config:ar}),triggers:[mo]},bo={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:by,configRender:yy,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 yy(e){return s.jsx(s.Fragment,{})}function by(e){return s.jsx(a.Text,{children:"Click chart's series"})}const jo={label_template:"${percentage.x} of ${x_axis.name} causes ${percentage.y} of ${bar.name}",color:"#789AB4"},or={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...Pe},overflow:Te()}},data_key:"value",bar:{name:"Value",nameAlignment:"left",color:"#228be6",label_formatter:me},line:{name:"Value",nameAlignment:"right",color:"red"},dataZoom:bt,markLine:jo};function Fn(e){return G(e,{output:"percent",mantissa:0,absolute:!1})}function jy(e){const t=e.value[1];try{return Fn(t)}catch(n){return console.error(n),t}}function vy(e){function t(n){let r=n;if(typeof n=="object"&&(Array.isArray(n.value)&&n.value.length===2?r=n.value[1]:r=n.value),!e.bar.label_formatter)return r;try{return G(r,e.bar.label_formatter)}catch(i){return console.error(i),r}}return{bar:t,line:jy,lineValue:Fn}}function wy(e,t,n){const{label_template:r}=e.markLine;if(!r)return"";const i={...e,percentage:t,count:n},o=Object.keys(i),l=Object.values(i);return new Function(...o,`return \`${r}\`;`)(...l)}function Cy(e,t){if(t.length===0)return{};const n=t.findIndex(c=>c[1]>=.8);if(n===-1)return{};const r=t[n],i={x:Fn((n+1)/t.length),y:Fn(r[1])},o={left:n+1,right:t.length-n-1},l=r[0];return l?{markLine:{name:"",silent:!0,symbol:"triangle",symbolRotate:180,symbolSize:[10,8],data:[{name:"",symbol:"none",xAxis:l,lineStyle:{color:e.markLine.color},label:{formatter:wy(e,i,o)}}]},markArea:{name:"",silent:!0,itemStyle:{color:"rgba(47, 140, 192, 0.05)"},data:[[{coord:["min",0]},{xAxis:l}]]}}:{}}function Sy(e,t,n){const{x_axis:r,data_key:i}=e;if(!r.data_key||!i)return[];const o=z(r.data_key),l=z(i);if(o.queryID!==l.queryID)throw new Error("Please use the same query for X & Y axis");const c=t[o.queryID].map(x=>[x[o.columnKey],Number(x[l.columnKey])]).sort((x,m)=>m[1]-x[1]),u=c.reduce((x,m)=>x+m[1],0),d=c.reduce((x,m,j)=>{const C=j===0?0:x[j-1][1];return x.push([m[0],C+m[1]]),x},[]).map(x=>[x[0],x[1]/u]),{markLine:h,markArea:p}=Cy(e,d);return[{name:e.bar.name,type:"bar",barMaxWidth:20,itemStyle:{color:e.bar.color},label:{show:!1,position:"top",formatter:n.bar},yAxisIndex:0,data:c},{name:e.line.name,type:"line",itemStyle:{color:e.line.color},symbolSize:2,lineStyle:{width:1,shadowColor:"rgba(255,255,255,1)",shadowBlur:0,shadowOffsetX:0,shadowOffsetY:1},label:{show:!1,position:"top",formatter:n.line},yAxisIndex:1,data:d,markLine:h,markArea:p}]}const _y=(e,t)=>n=>{const r=Array.isArray(n)?n:[n];if(r.length===0)return"";const i=r.map((c,u)=>{const d=c.seriesName,[h,p]=c.value;if(!d)return p;const x=u===0?t.bar:t.lineValue;return`
172
172
  <tr>
173
173
  <th style="text-align: right; padding: 0 1em;">${d}</th>
174
174
  <td style="text-align: left; padding: 0 1em;">${x(p)}</td>
175
175
  </tr>
176
- `}),o=$e(e.x_axis.axisLabel.overflow.in_tooltip),l=r[0].name;return`
176
+ `}),o=Le(e.x_axis.axisLabel.overflow.in_tooltip),l=r[0].name;return`
177
177
  <div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
178
178
  <div style="${o}">${l}</div>
179
179
  </div>
@@ -182,7 +182,7 @@ Check the top-level render call using <`+E+">.")}return I}}function rc(w,I){{if(
182
182
  ${i.join("")}
183
183
  </tbody>
184
184
  </table>
185
- `};function _y(e,t){return ne.getTooltip({trigger:"axis",formatter:Sy(e,t)})}function ky(e){const{name:t,axisLabel:n}=e.x_axis,r=Ve(n.overflow.on_axis);return[ne.getXAxis({type:"category",name:t,nameLocation:"middle",nameGap:30,nameTextStyle:{align:"right"},axisLabel:{...n,...r,formatter:Pt(n.formatter)}})]}function Ty(e,t){return[ne.getYAxis({name:e.bar.name,nameGap:20,minInterval:1,nameTextStyle:{align:e.bar.nameAlignment},position:"left",axisLabel:{show:!0,formatter:t.bar},splitLine:{show:!1}}),ne.getYAxis({name:e.line.name,nameGap:20,nameTextStyle:{align:e.line.nameAlignment},position:"right",axisLabel:{show:!0,formatter:t.lineValue}})]}function Dy(e,t,n){const r=jy(e);return{dataZoom:kn(e.dataZoom),tooltip:_y(e,r),xAxis:ky(e),yAxis:Ty(e,r),series:Cy(e,t,r),grid:{top:50,left:30,right:15,bottom:5,containLabel:!0}}}J.use([ie.BarChart,ie.LineChart,B.DataZoomComponent,B.GridComponent,B.LegendComponent,B.TooltipComponent,_e.CanvasRenderer]);function Iy({context:e,instance:t}){const{value:n}=$(e.instanceData,"config"),r=e.data,{width:i,height:o}=e.viewport,l=y.defaults({},n,lr),u=Dy(l,r),c=Ne({vizManager:e.vizManager,instance:t}),d=qe(c.triggerManager,yo.id),h=vt(r,l.x_axis.data_key),p=g.useCallback(m=>{const j=y.get(h,m.name,{error:"rowData is not found"});d.forEach(C=>{c.runInteraction(C.id,{...m,rowData:j})})},[h,d,c]),x=g.useMemo(()=>({click:p}),[p]);return!l||!i||!o?null:s.jsx(Ie,{width:i,height:o,children:s.jsx(Se,{echarts:J,option:u,style:Ht(i,o),onEvents:x,notMerge:!0,theme:"merico-light"})})}const My=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function zy({control:e,watch:t}){return t(["bar"]),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:"bar.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"Bar Name",sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"bar.nameAlignment",control:e,render:({field:n})=>s.jsx(a.Select,{label:"Align",required:!0,data:My,sx:{flex:1},...n})})]}),s.jsxs(a.Stack,{spacing:2,children:[s.jsx(a.Text,{size:"sm",children:"Color"}),s.jsx(b.Controller,{name:"bar.color",control:e,render:({field:n})=>s.jsx(ke,{...n})})]}),s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),s.jsx(b.Controller,{name:"bar.label_formatter",control:e,render:({field:n})=>s.jsx(Fe,{...n})})]})]})}const Ay=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function Ey({control:e,watch:t}){return t(["line"]),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:"line.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"Line Name",sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"line.nameAlignment",control:e,render:({field:n})=>s.jsx(a.Select,{label:"Align",required:!0,data:Ay,sx:{flex:1},...n})})]}),s.jsxs(a.Stack,{spacing:2,children:[s.jsx(a.Text,{size:"sm",children:"Color"}),s.jsx(b.Controller,{name:"line.color",control:e,render:({field:n})=>s.jsx(ke,{...n})})]})]})}const Ly=`
185
+ `};function ky(e,t){return ee.getTooltip({trigger:"axis",formatter:_y(e,t)})}function Ty(e){const{name:t,axisLabel:n}=e.x_axis,r=Be(n.overflow.on_axis);return[ee.getXAxis({type:"category",name:t,nameLocation:"middle",nameGap:30,nameTextStyle:{align:"right"},axisLabel:{...n,...r,formatter:Pt(n.formatter)}})]}function Dy(e,t){return[ee.getYAxis({name:e.bar.name,nameGap:20,minInterval:1,nameTextStyle:{align:e.bar.nameAlignment},position:"left",axisLabel:{show:!0,formatter:t.bar},splitLine:{show:!1}}),ee.getYAxis({name:e.line.name,nameGap:20,nameTextStyle:{align:e.line.nameAlignment},position:"right",axisLabel:{show:!0,formatter:t.lineValue}})]}function Iy(e,t,n){const r=vy(e);return{dataZoom:_n(e.dataZoom),tooltip:ky(e,r),xAxis:Ty(e),yAxis:Dy(e,r),series:Sy(e,t,r),grid:{top:50,left:30,right:15,bottom:5,containLabel:!0}}}function My({context:e,instance:t}){const{value:n}=O(e.instanceData,"config"),r=e.data,{width:i,height:o}=e.viewport,l=y.defaults({},n,or),c=Iy(l,r),u=$e({vizManager:e.vizManager,instance:t}),d=Oe(u.triggerManager,bo.id),h=jt(r,l.x_axis.data_key),p=g.useCallback(m=>{const j=y.get(h,m.name,{error:"rowData is not found"});d.forEach(C=>{u.runInteraction(C.id,{...m,rowData:j})})},[h,d,u]),x=g.useMemo(()=>({click:p}),[p]);return!l||!i||!o?null:s.jsx(ke,{width:i,height:o,children:s.jsx(we,{echarts:be,option:c,style:Zt(i,o),onEvents:x,notMerge:!0,theme:"merico-light"})})}const zy=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function Ay({control:e,watch:t}){return t(["bar"]),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:"bar.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"Bar Name",sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"bar.nameAlignment",control:e,render:({field:n})=>s.jsx(a.Select,{label:"Align",required:!0,data:zy,sx:{flex:1},...n})})]}),s.jsxs(a.Stack,{spacing:2,children:[s.jsx(a.Text,{size:"sm",children:"Color"}),s.jsx(b.Controller,{name:"bar.color",control:e,render:({field:n})=>s.jsx(Ce,{...n})})]}),s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),s.jsx(b.Controller,{name:"bar.label_formatter",control:e,render:({field:n})=>s.jsx(Ve,{...n})})]})]})}const Ey=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function Py({control:e,watch:t}){return t(["line"]),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:"line.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"Line Name",sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"line.nameAlignment",control:e,render:({field:n})=>s.jsx(a.Select,{label:"Align",required:!0,data:Ey,sx:{flex:1},...n})})]}),s.jsxs(a.Stack,{spacing:2,children:[s.jsx(a.Text,{size:"sm",children:"Color"}),s.jsx(b.Controller,{name:"line.color",control:e,render:({field:n})=>s.jsx(Ce,{...n})})]})]})}const Ly=`
186
186
  {
187
187
  // 80-20 line stuff
188
188
  percentage: {
@@ -205,11 +205,11 @@ Check the top-level render call using <`+E+">.")}return I}}function rc(w,I){{if(
205
205
  name: string;
206
206
  };
207
207
  }
208
- `,Py=()=>{const[e,t]=g.useState(!1);return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"subtle",compact:!0,onClick:()=>t(n=>!n),children:e?"Close":"Click to see params for Label Template"}),s.jsx(a.Collapse,{in:e,children:s.jsx(pt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:Ly})})]})};function By({control:e,watch:t}){return t(["markLine"]),s.jsxs(a.Stack,{children:[s.jsxs(a.Stack,{spacing:2,children:[s.jsx(a.Text,{size:"sm",children:"Color"}),s.jsx(b.Controller,{name:"markLine.color",control:e,render:({field:n})=>s.jsx(ke,{...n})})]}),s.jsxs(a.Stack,{spacing:4,children:[s.jsx(b.Controller,{name:"markLine.label_template",control:e,render:({field:n})=>s.jsx(a.Textarea,{autosize:!0,minRows:2,maxRows:4,label:"Label Template",sx:{flex:1},...n})}),s.jsx(Py,{})]})]})}function Oy({control:e,watch:t}){return t(["x_axis"]),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>s.jsx(O,{label:"Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"x_axis.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"Name",sx:{flex:1},...n})})]}),s.jsx(a.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>s.jsx(a.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:s.jsx(a.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),s.jsx(b.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>s.jsx(Tn,{...n})})]}),s.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>s.jsx(Ke,{...n})})]})}function $y({control:e,watch:t}){return t(["data_key"]),s.jsx(a.Stack,{children:s.jsx(b.Controller,{name:"data_key",control:e,render:({field:n})=>s.jsx(O,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})})})}function Vy({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=g.useMemo(()=>y.defaults({},t,lr),[t]),{control:i,handleSubmit:o,watch:l,getValues:u,reset:c}=b.useForm({defaultValues:r});g.useEffect(()=>{c(r)},[r]),l(["x_axis","data_key","bar","line","dataZoom"]);const d=u(),h=g.useMemo(()=>!y.isEqual(d,t),[d,t]);return s.jsxs("form",{onSubmit:o(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Chart Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"X Axis",children:"X Axis"}),s.jsx(a.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),s.jsx(a.Tabs.Tab,{value:"Bar",children:"Bar"}),s.jsx(a.Tabs.Tab,{value:"Line",children:"Line"}),s.jsx(a.Tabs.Tab,{value:"80-20 Line",children:"80-20 Line"}),s.jsx(a.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),s.jsx(a.Tabs.Panel,{value:"X Axis",children:s.jsx(Oy,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Y Axis",children:s.jsx($y,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Bar",children:s.jsx(zy,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Line",children:s.jsx(Ey,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"80-20 Line",children:s.jsx(By,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Zooming",children:s.jsx(b.Controller,{name:"dataZoom",control:i,render:({field:p})=>s.jsx(Dn,{...p})})})]})]})}function qy(e){const{dataZoom:t=jt,...n}=e;return{...n,dataZoom:t}}function Ny(e){const{markLine:t=bo,...n}=e;return{...n,markLine:t}}function Fy(e){const t=y.defaultsDeep({},e.x_axis.axisLabel,{rotate:0,formatter:{...Oe}});return{...e,x_axis:{...e.x_axis,axisLabel:t}}}function Gy(e){const{label_formatter:t=je}=e.bar;return{...e,bar:{...e.bar,label_formatter:t}}}function Wy(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return y.defaultsDeep(t,e)}function Ry(e){const t={bar:{nameAlignment:"left"},line:{nameAlignment:"right"}};return y.defaultsDeep(t,e)}function Qy(e){console.log(e);const{x_axis:t,tooltip:n}=e.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:t,in_tooltip:n}}}};return y.defaultsDeep(r,e)}function Uy(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis:i,data_key:o,...l}=e;return{...l,x_axis:{...i,data_key:r(i.data_key)},data_key:r(o)}}catch(n){throw console.error("[Migration failed]",n),n}}class Ky extends ue{constructor(){super(...arguments);L(this,"VERSION",9)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:qy(n.config)})),this.version(3,n=>({...n,version:3,config:Ny(n.config)})),this.version(4,n=>({...n,version:4,config:Fy(n.config)})),this.version(5,n=>({...n,version:5,config:Gy(n.config)})),this.version(6,n=>({...n,version:6,config:Wy(n.config)})),this.version(7,n=>({...n,version:7,config:Ry(n.config)})),this.version(8,n=>({...n,version:8,config:Qy(n.config)})),this.version(9,(n,r)=>({...n,version:9,config:Uy(n.config,r)}))}}const Yy={displayName:"Pareto Chart",displayGroup:"ECharts-based charts",migrator:new Ky,name:"paretoChart",viewRender:Iy,configRender:Vy,createConfig(){return{version:9,config:y.cloneDeep(lr)}},triggers:[yo]};function Xy(e,t,n){const{label_field:r,value_field:i,color_field:o}=e;if(!r||!i)return{};const l=z(r),u=z(i),c=z(o),d=t[l.queryID].map(p=>({name:p[l.columnKey],value:Number(p[u.columnKey]),color:c.columnKey?p[c.columnKey]:void 0})),h=vd("multiple");return{type:"pie",name:"pie",radius:["50%","80%"],itemStyle:{color:({data:p})=>p.color?p.color:h.next().value},label:{position:"outer",alignTo:"edge",formatter:`{name|{b}}
209
- {percentage|{d}%}`,minMargin:5,edgeDistance:10,lineHeight:15,rich:{percentage:{color:"#999"}},margin:20},labelLine:{length:15,length2:0,maxSurfaceAngle:80,showAbove:!0},labelLayout:function(p){const x=p.labelRect.x<n/2,m=p.labelLinePoints;return y.set(m,[2,0],x?p.labelRect.x:p.labelRect.x+p.labelRect.width),{labelLinePoints:m}},data:d,top:10,bottom:10,left:10,right:10}}function Jy(e,t,n){return{tooltip:ne.getTooltip({}),series:Xy(e,t,n)}}const jo={id:"builtin:echarts:click-pie-chart:series",displayName:"Click Pie Series",nameRender:Hy,configRender:Zy,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 Zy(e){return s.jsx(s.Fragment,{})}function Hy(e){return s.jsx(a.Text,{children:"Click chart's series"})}const ur={label_field:"",value_field:"",color_field:""};J.use([ie.PieChart,_e.CanvasRenderer]);function eb({conf:e,data:t,width:n,height:r,interactionManager:i}){const o=vt(t,e.label_field),l=qe(i.triggerManager,jo.id),u=g.useCallback(h=>{const p=y.get(o,h.name,{error:"rowData is not found"});l.forEach(x=>{i.runInteraction(x.id,{...h,rowData:p})})},[o,l,i]),c=g.useMemo(()=>Jy(e,t,n),[e,t,n]),d=g.useMemo(()=>({click:u}),[u]);return!n||!r||!c.series.name?null:s.jsx(Se,{echarts:J,option:c,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function tb({context:e,instance:t}){const n=Ne({vizManager:e.vizManager,instance:t}),{value:r}=$(e.instanceData,"config"),i=g.useMemo(()=>y.defaults({},r,ur),[r]),o=e.data,{width:l,height:u}=e.viewport;return!l||!u?null:s.jsx(Ie,{width:l,height:u,children:s.jsx(eb,{conf:i,width:Qe(l),height:Ue(u),data:o,interactionManager:n})})}function nb({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=g.useMemo(()=>y.defaultsDeep({},t,ur),[t]),i=g.useMemo(()=>y.clone(r),[r]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=b.useForm({defaultValues:i});g.useEffect(()=>{d(i)},[i]);const h=c(),p=g.useMemo(()=>!y.isEqual(h,r),[h,r]);return u(["label_field","value_field","color_field"]),s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:l(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Pie Chart Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Stack,{mt:"md",spacing:"xs",p:"md",mb:"sm",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[s.jsx(b.Controller,{control:o,name:"label_field",render:({field:x})=>s.jsx(O,{label:"Label Key",required:!0,...x})}),s.jsx(b.Controller,{control:o,name:"value_field",render:({field:x})=>s.jsx(O,{label:"Value Key",required:!0,...x})}),s.jsx(b.Controller,{control:o,name:"color_field",render:({field:x})=>s.jsx(O,{label:"Color Key",clearable:!0,...x})})]})]})})}function sb(e){const{color_field:t="",...n}=e;return{...n,color_field:t}}function rb(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{label_field:i,value_field:o,color_field:l}=e;return{label_field:r(i),value_field:r(o),color_field:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class ib extends ue{constructor(){super(...arguments);L(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:sb(n.config)})),this.version(3,(n,r)=>({...n,version:3,config:rb(n.config,r)}))}}const ab={displayName:"Pie Chart",displayGroup:"ECharts-based charts",migrator:new ib,name:"pie",viewRender:tb,configRender:nb,createConfig(){return{version:3,config:y.cloneDeep(ur)}},triggers:[jo]};function ob(e){return s.jsx(s.Fragment,{})}function lb(e){return s.jsx(a.Text,{children:"Click heat block"})}const vo={id:"builtin:echarts:click-radar-chart:series",displayName:"Click radar chart series",nameRender:lb,configRender:ob,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"}]},Wn={series_name_key:"",additional_series:[],background:{enabled:!0},label:{enabled:!0},dimensions:[]};function wo(e){return e?t=>{try{return W(t,e)}catch(n){return console.error(n),t}}:t=>t}function Co(e){return{show:e.label.enabled,formatter:({dimensionIndex:t,value:n})=>wo(e.dimensions[t].formatter)(n)}}function So(e,t){return t.map(({data_key:n})=>{const r=z(n);return e[r.columnKey]})}function ub(e,t,n){const r=z(t);return e[r.queryID].map(i=>({value:So(i,n),name:i[r.columnKey]}))}function cb(e,t){const{series_name_key:n,dimensions:r}=t;return[{type:"radar",name:"main-radar",data:ub(e,n,r),symbolSize:4,lineStyle:{width:1},emphasis:{lineStyle:{width:4}},areaStyle:t.background.enabled?{opacity:.4}:void 0,label:Co(t)}]}function db(e,t){const{additional_series:n,dimensions:r}=t;return n.map(o=>{const l=z(o.name_key),u=z(o.color_key);return{type:"radar",colorBy:"data",data:e[l.queryID].map(h=>{const p=h[l.columnKey],x=h[u.columnKey];return{name:p,value:So(h,r),itemStyle:{color:x}}}),symbolSize:4,lineStyle:{width:1},emphasis:{lineStyle:{width:4}},areaStyle:t.background.enabled?{opacity:.4}:void 0,label:Co(t)}}).flat()}function pb(e,t){return[...cb(e,t),...db(e,t)]}function hb(e){return({name:t,marker:n,value:r})=>{if(r.length===0)return"";const i=r.map((o,l)=>{const u=e.dimensions[l],c=wo(u.formatter);return`
208
+ `,By=()=>{const[e,t]=g.useState(!1);return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"subtle",compact:!0,onClick:()=>t(n=>!n),children:e?"Close":"Click to see params for Label Template"}),s.jsx(a.Collapse,{in:e,children:s.jsx(dt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:Ly})})]})};function Oy({control:e,watch:t}){return t(["markLine"]),s.jsxs(a.Stack,{children:[s.jsxs(a.Stack,{spacing:2,children:[s.jsx(a.Text,{size:"sm",children:"Color"}),s.jsx(b.Controller,{name:"markLine.color",control:e,render:({field:n})=>s.jsx(Ce,{...n})})]}),s.jsxs(a.Stack,{spacing:4,children:[s.jsx(b.Controller,{name:"markLine.label_template",control:e,render:({field:n})=>s.jsx(a.Textarea,{autosize:!0,minRows:2,maxRows:4,label:"Label Template",sx:{flex:1},...n})}),s.jsx(By,{})]})]})}function $y({control:e,watch:t}){return t(["x_axis"]),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>s.jsx(B,{label:"Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"x_axis.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"Name",sx:{flex:1},...n})})]}),s.jsx(a.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>s.jsx(a.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:s.jsx(a.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),s.jsx(b.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>s.jsx(kn,{...n})})]}),s.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>s.jsx(Re,{...n})})]})}function Vy({control:e,watch:t}){return t(["data_key"]),s.jsx(a.Stack,{children:s.jsx(b.Controller,{name:"data_key",control:e,render:({field:n})=>s.jsx(B,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})})})}function qy({context:e}){const{value:t,set:n}=O(e.instanceData,"config"),r=g.useMemo(()=>y.defaults({},t,or),[t]),{control:i,handleSubmit:o,watch:l,getValues:c,reset:u}=b.useForm({defaultValues:r});g.useEffect(()=>{u(r)},[r]),l(["x_axis","data_key","bar","line","dataZoom"]);const d=c(),h=g.useMemo(()=>!y.isEqual(d,t),[d,t]);return s.jsxs("form",{onSubmit:o(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Chart Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"X Axis",children:"X Axis"}),s.jsx(a.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),s.jsx(a.Tabs.Tab,{value:"Bar",children:"Bar"}),s.jsx(a.Tabs.Tab,{value:"Line",children:"Line"}),s.jsx(a.Tabs.Tab,{value:"80-20 Line",children:"80-20 Line"}),s.jsx(a.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),s.jsx(a.Tabs.Panel,{value:"X Axis",children:s.jsx($y,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Y Axis",children:s.jsx(Vy,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Bar",children:s.jsx(Ay,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Line",children:s.jsx(Py,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"80-20 Line",children:s.jsx(Oy,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Zooming",children:s.jsx(b.Controller,{name:"dataZoom",control:i,render:({field:p})=>s.jsx(Tn,{...p})})})]})]})}function Ny(e){const{dataZoom:t=bt,...n}=e;return{...n,dataZoom:t}}function Fy(e){const{markLine:t=jo,...n}=e;return{...n,markLine:t}}function Gy(e){const t=y.defaultsDeep({},e.x_axis.axisLabel,{rotate:0,formatter:{...Pe}});return{...e,x_axis:{...e.x_axis,axisLabel:t}}}function Wy(e){const{label_formatter:t=me}=e.bar;return{...e,bar:{...e.bar,label_formatter:t}}}function Ry(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return y.defaultsDeep(t,e)}function Qy(e){const t={bar:{nameAlignment:"left"},line:{nameAlignment:"right"}};return y.defaultsDeep(t,e)}function Uy(e){console.log(e);const{x_axis:t,tooltip:n}=e.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:t,in_tooltip:n}}}};return y.defaultsDeep(r,e)}function Ky(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:i,data_key:o,...l}=e;return{...l,x_axis:{...i,data_key:r(i.data_key)},data_key:r(o)}}catch(n){throw console.error("[Migration failed]",n),n}}class Yy extends ae{constructor(){super(...arguments);P(this,"VERSION",9)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:Ny(n.config)})),this.version(3,n=>({...n,version:3,config:Fy(n.config)})),this.version(4,n=>({...n,version:4,config:Gy(n.config)})),this.version(5,n=>({...n,version:5,config:Wy(n.config)})),this.version(6,n=>({...n,version:6,config:Ry(n.config)})),this.version(7,n=>({...n,version:7,config:Qy(n.config)})),this.version(8,n=>({...n,version:8,config:Uy(n.config)})),this.version(9,(n,r)=>({...n,version:9,config:Ky(n.config,r)}))}}const Xy={displayName:"Pareto Chart",displayGroup:"ECharts-based charts",migrator:new Yy,name:"paretoChart",viewRender:My,configRender:qy,createConfig(){return{version:9,config:y.cloneDeep(or)}},triggers:[bo]};function Jy(e,t,n){const{label_field:r,value_field:i,color_field:o}=e;if(!r||!i)return{};const l=z(r),c=z(i),u=z(o),d=t[l.queryID].map(p=>({name:p[l.columnKey],value:Number(p[c.columnKey]),color:u.columnKey?p[u.columnKey]:void 0})),h=wd("multiple");return{type:"pie",name:"pie",radius:["50%","80%"],itemStyle:{color:({data:p})=>p.color?p.color:h.next().value},label:{position:"outer",alignTo:"edge",formatter:`{name|{b}}
209
+ {percentage|{d}%}`,minMargin:5,edgeDistance:10,lineHeight:15,rich:{percentage:{color:"#999"}},margin:20},labelLine:{length:15,length2:0,maxSurfaceAngle:80,showAbove:!0},labelLayout:function(p){const x=p.labelRect.x<n/2,m=p.labelLinePoints;return y.set(m,[2,0],x?p.labelRect.x:p.labelRect.x+p.labelRect.width),{labelLinePoints:m}},data:d,top:10,bottom:10,left:10,right:10}}function Zy(e,t,n){return{tooltip:ee.getTooltip({}),series:Jy(e,t,n)}}const vo={id:"builtin:echarts:click-pie-chart:series",displayName:"Click Pie Series",nameRender:eb,configRender:Hy,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 Hy(e){return s.jsx(s.Fragment,{})}function eb(e){return s.jsx(a.Text,{children:"Click chart's series"})}const lr={label_field:"",value_field:"",color_field:""};function tb({conf:e,data:t,width:n,height:r,interactionManager:i}){const o=jt(t,e.label_field),l=Oe(i.triggerManager,vo.id),c=g.useCallback(h=>{const p=y.get(o,h.name,{error:"rowData is not found"});l.forEach(x=>{i.runInteraction(x.id,{...h,rowData:p})})},[o,l,i]),u=g.useMemo(()=>Zy(e,t,n),[e,t,n]),d=g.useMemo(()=>({click:c}),[c]);return!n||!r||!u.series.name?null:s.jsx(we,{echarts:be,option:u,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function nb({context:e,instance:t}){const n=$e({vizManager:e.vizManager,instance:t}),{value:r}=O(e.instanceData,"config"),i=g.useMemo(()=>y.defaults({},r,lr),[r]),o=e.data,{width:l,height:c}=e.viewport;return!l||!c?null:s.jsx(ke,{width:l,height:c,children:s.jsx(tb,{conf:i,width:Ge(l),height:We(c),data:o,interactionManager:n})})}function sb({context:e}){const{value:t,set:n}=O(e.instanceData,"config"),r=g.useMemo(()=>y.defaultsDeep({},t,lr),[t]),i=g.useMemo(()=>y.clone(r),[r]),{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=b.useForm({defaultValues:i});g.useEffect(()=>{d(i)},[i]);const h=u(),p=g.useMemo(()=>!y.isEqual(h,r),[h,r]);return c(["label_field","value_field","color_field"]),s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:l(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Pie Chart Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Stack,{mt:"md",spacing:"xs",p:"md",mb:"sm",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[s.jsx(b.Controller,{control:o,name:"label_field",render:({field:x})=>s.jsx(B,{label:"Label Key",required:!0,...x})}),s.jsx(b.Controller,{control:o,name:"value_field",render:({field:x})=>s.jsx(B,{label:"Value Key",required:!0,...x})}),s.jsx(b.Controller,{control:o,name:"color_field",render:({field:x})=>s.jsx(B,{label:"Color Key",clearable:!0,...x})})]})]})})}function rb(e){const{color_field:t="",...n}=e;return{...n,color_field:t}}function ib(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{label_field:i,value_field:o,color_field:l}=e;return{label_field:r(i),value_field:r(o),color_field:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class ab extends ae{constructor(){super(...arguments);P(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:rb(n.config)})),this.version(3,(n,r)=>({...n,version:3,config:ib(n.config,r)}))}}const ob={displayName:"Pie Chart",displayGroup:"ECharts-based charts",migrator:new ab,name:"pie",viewRender:nb,configRender:sb,createConfig(){return{version:3,config:y.cloneDeep(lr)}},triggers:[vo]};function lb(e){return s.jsx(s.Fragment,{})}function cb(e){return s.jsx(a.Text,{children:"Click heat block"})}const wo={id:"builtin:echarts:click-radar-chart:series",displayName:"Click radar chart series",nameRender:cb,configRender:lb,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"}]},Gn={series_name_key:"",additional_series:[],background:{enabled:!0},label:{enabled:!0},dimensions:[]};function Co(e){return e?t=>{try{return G(t,e)}catch(n){return console.error(n),t}}:t=>t}function So(e){return{show:e.label.enabled,formatter:({dimensionIndex:t,value:n})=>Co(e.dimensions[t].formatter)(n)}}function _o(e,t){return t.map(({data_key:n})=>{const r=z(n);return e[r.columnKey]})}function ub(e,t,n){const r=z(t);return e[r.queryID].map(i=>({value:_o(i,n),name:i[r.columnKey]}))}function db(e,t){const{series_name_key:n,dimensions:r}=t;return[{type:"radar",name:"main-radar",data:ub(e,n,r),symbolSize:4,lineStyle:{width:1},emphasis:{lineStyle:{width:4}},areaStyle:t.background.enabled?{opacity:.4}:void 0,label:So(t)}]}function pb(e,t){const{additional_series:n,dimensions:r}=t;return n.map(o=>{const l=z(o.name_key),c=z(o.color_key);return{type:"radar",colorBy:"data",data:e[l.queryID].map(h=>{const p=h[l.columnKey],x=h[c.columnKey];return{name:p,value:_o(h,r),itemStyle:{color:x}}}),symbolSize:4,lineStyle:{width:1},emphasis:{lineStyle:{width:4}},areaStyle:t.background.enabled?{opacity:.4}:void 0,label:So(t)}}).flat()}function hb(e,t){return[...db(e,t),...pb(e,t)]}function xb(e){return({name:t,marker:n,value:r})=>{if(r.length===0)return"";const i=r.map((o,l)=>{const c=e.dimensions[l],u=Co(c.formatter);return`
210
210
  <tr>
211
- <td style="padding-left: 18px;">${u.name}</td>
212
- <td style="text-align: right; "><strong>${c(o)}</strong></td>
211
+ <td style="padding-left: 18px;">${c.name}</td>
212
+ <td style="text-align: right; "><strong>${u(o)}</strong></td>
213
213
  </tr>
214
214
  `});return`
215
215
  <table>
@@ -234,7 +234,7 @@ Check the top-level render call using <`+E+">.")}return I}}function rc(w,I){{if(
234
234
  ${i.join("")}
235
235
  </tbody>
236
236
  </table>
237
- `}}const xb={legend:{show:!0,bottom:0,left:0},tooltip:{trigger:"item"}},fb=["#66B4DB","#39BFA2","#E46464","#33A678","#EEBA00","#9D88CB","#939943","#E49792","#09A2B8","#AF5F6B","#6CA157","#09A2B8","#6398C7","#E692BA","#97B566","#8CACE2","#CA79AC","#6DBC80","#B08F4B","#826BAF"];function gb(e,t){const{series_name_key:n,dimensions:r,additional_series:i}=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:ne.getTooltip({backgroundColor:"rgba(255,255,255,0.6)",formatter:hb(e)}),legend:{show:!0,bottom:0,left:"center",type:"scroll"},series:pb(t,e),color:fb};return y.merge({},xb,l)}J.use([ie.RadarChart,B.GridComponent,B.LegendComponent,B.TooltipComponent,_e.CanvasRenderer]);function mb({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const l=g.useMemo(()=>{const{queryID:p,columnKey:x}=z(e.series_name_key),m=y.keyBy(t[p],x),j=e.additional_series.reduce((C,T)=>{const D=z(T.name_key),A=y.keyBy(t[D.queryID],D.columnKey);return{...C,...A}},m);return{...m,...j}},[t,e.series_name_key,e.additional_series]),u=qe(i.triggerManager,vo.id),c=g.useCallback(p=>{const x=y.get(l,p.name,{error:"rowData is not found"});u.forEach(m=>{i.runInteraction(m.id,{...p,rowData:x})})},[l,u,i]),d=g.useMemo(()=>({click:c}),[c]),h=g.useMemo(()=>gb(y.defaultsDeep({},e,Wn),t),[e,t]);return!n||!r?null:s.jsx(Se,{echarts:J,option:h,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function yb({context:e,instance:t}){const n=Ne({vizManager:e.vizManager,instance:t}),{value:r}=$(e.instanceData,"config"),{variables:i}=e,o=g.useMemo(()=>y.defaults({},r,Wn),[r]),l=e.data,{width:u,height:c}=e.viewport;return!u||!c||!o||y.isEmpty(o==null?void 0:o.dimensions)?null:s.jsx(Ie,{width:u,height:c,children:s.jsx(mb,{variables:i,width:Qe(u),height:Ue(c),data:l,conf:o,interactionManager:n})})}function bb({control:e,index:t,remove:n}){return s.jsxs(a.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:`additional_series.${t}.name_key`,control:e,render:({field:r})=>s.jsx(O,{label:"Series Name Key",required:!0,sx:{flex:1},...r})})}),s.jsx(a.Stack,{children:s.jsx(b.Controller,{name:`additional_series.${t}.color_key`,control:e,render:({field:r})=>s.jsx(O,{label:"Color Key",required:!0,clearable:!0,sx:{flex:1},...r})})}),s.jsx(a.Button,{mt:20,leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),children:"Delete"})]})}function jb({control:e,watch:t}){const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"additional_series"}),o=t("additional_series"),l=n.map((x,m)=>({...x,...o[m]})),u=()=>{const x=new Date().getTime().toString();r({id:x,name_key:"",color_key:""})},c=y.get(l,"0.id",null),[d,h]=g.useState(c);g.useEffect(()=>{h(x=>x||c)},[c]);const p=x=>{i(x);const m=y.get(l,"0.id",null);h(m)};return s.jsxs(s.Fragment,{children:[s.jsxs(a.Alert,{icon:s.jsx(_.IconInfoCircle,{size:16}),title:"Additional Series",children:["By setting ",s.jsx(a.Mark,{children:"Series Name Key"}),", you may add series from more queries to the chart."]}),s.jsxs(a.Tabs,{value:d,onTabChange:h,styles:{tab:{paddingBottom:"0px"},panel:{padding:"0px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((x,m)=>s.jsx(a.Tabs.Tab,{value:x.id,children:m+1},x.id)),s.jsx(a.Tabs.Tab,{onClick:u,value:"add",children:s.jsx(_.IconPlus,{size:18,color:"#228be6"})})]}),l.map((x,m)=>s.jsx(a.Tabs.Panel,{value:x.id,children:s.jsx(bb,{control:e,index:m,remove:p})},x.id))]})]})}function vb({control:e,index:t,remove:n}){return s.jsxs(a.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,align:"top",children:[s.jsx(b.Controller,{name:`dimensions.${t}.name`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`dimensions.${t}.data_key`,control:e,render:({field:r})=>s.jsx(O,{label:"Data Key",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`dimensions.${t}.max`,control:e,rules:{validate:r=>{if(Number.isNaN(Number(r)))return"A number is required"}},render:({field:r,fieldState:i})=>{var o;return s.jsx(a.TextInput,{label:"Max",required:!0,sx:{flex:1},...r,error:(o=i.error)==null?void 0:o.message})}})]}),s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Value Formatter",labelPosition:"center"}),s.jsx(b.Controller,{name:`dimensions.${t}.formatter`,control:e,render:({field:r})=>s.jsx(Fe,{...r})})]}),s.jsx(a.Button,{mt:20,leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this Metric"})]})}function wb({control:e,watch:t}){const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"dimensions"}),o=t("dimensions"),l=n.map((x,m)=>({...x,...o[m]})),u=()=>{const x=new Date().getTime().toString();r({id:x,name:x,data_key:"",max:"100",formatter:je})},c=y.get(l,"0.id",null),[d,h]=g.useState(c);g.useEffect(()=>{h(x=>x||c)},[c]);const p=x=>{i(x);const m=y.get(l,"0.id",null);h(m)};return s.jsx(s.Fragment,{children:s.jsxs(a.Tabs,{value:d,onTabChange:h,styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((x,m)=>s.jsx(a.Tabs.Tab,{value:x.id,children:x.name?x.name:m+1},x.id)),s.jsx(a.Tabs.Tab,{onClick:u,value:"add",children:s.jsx(_.IconPlus,{size:18,color:"#228be6"})})]}),l.map((x,m)=>s.jsx(a.Tabs.Panel,{value:x.id,children:s.jsx(vb,{control:e,index:m,remove:p})},x.id))]})})}function Cb({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=g.useMemo(()=>y.defaultsDeep({},t,Wn),[t]),{control:i,handleSubmit:o,watch:l,getValues:u,reset:c,formState:d}=b.useForm({defaultValues:r,mode:"all"});g.useEffect(()=>{c(r)},[r]),l(["series_name_key","background","label"]);const h=u(),p=g.useMemo(()=>!y.isEqual(h,r),[h,r]);return s.jsx("form",{onSubmit:o(n),children:s.jsxs(a.Stack,{spacing:"xs",children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Radar Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p||!d.isValid,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Tabs,{defaultValue:"series",children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"series",children:"Series"}),s.jsx(a.Tabs.Tab,{value:"metrics",children:"Metrics"}),s.jsx(a.Tabs.Tab,{value:"style",children:"Style"}),s.jsx(a.Tabs.Tab,{value:"additional_series",ml:"auto",children:"Additional Series"})]}),s.jsx(a.Tabs.Panel,{value:"series",p:"md",children:s.jsx(b.Controller,{name:"series_name_key",control:i,render:({field:x})=>s.jsx(O,{label:"Series Name Field",required:!0,sx:{flex:1},...x})})}),s.jsx(a.Tabs.Panel,{value:"metrics",p:"md",children:s.jsx(wb,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"style",p:"md",children:s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"background.enabled",control:i,render:({field:x})=>s.jsx(a.Checkbox,{label:"Show background",checked:x.value,onChange:m=>x.onChange(m.currentTarget.checked)})}),s.jsx(b.Controller,{name:"label.enabled",control:i,render:({field:x})=>s.jsx(a.Checkbox,{label:"Show value label",checked:x.value,onChange:m=>x.onChange(m.currentTarget.checked)})})]})}),s.jsx(a.Tabs.Panel,{value:"additional_series",p:"md",children:s.jsx(jb,{control:i,watch:l})})]})]})})}function Sb(e){const{dimensions:t=[],...n}=e;function r({name:i="",data_key:o="",max:l=10,formatter:u=je}){return{name:i,data_key:o,max:l,formatter:u}}return{...n,dimensions:t.map(r)}}function _b(e){const{dimensions:t=[],...n}=e;return{...n,dimensions:t.map(r=>({...r,id:r.id??r.name}))}}function kb(e){const t={background:{enabled:!0},label:{enabled:!0}};return y.defaultsDeep(t,e)}function Tb(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:i,dimensions:o,...l}=e;return{...l,series_name_key:r(i),dimensions:o.map(u=>({...u,data_key:r(u.data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}function Db(e){const t={additional_series:[]};return y.defaultsDeep(t,e)}function Ib(e){const t={...e,dimensions:e.dimensions.map(n=>({...n,max:String(n.max)}))};return delete t.additionalSeries,t}class Mb extends ue{constructor(){super(...arguments);L(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:_b(r)}}),this.version(4,n=>{const{config:r}=n;return{...n,version:4,config:kb(r)}}),this.version(5,(n,r)=>{const{config:i}=n;return{...n,version:5,config:Tb(i,r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:Db(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:Ib(r)}})}}const zb={displayName:"Radar Chart",displayGroup:"ECharts-based charts",migrator:new Mb,name:"radar",viewRender:yb,configRender:Cb,createConfig:()=>({version:7,config:Wn}),triggers:[vo]};function Ab(e,t){const{plot:n,transform:r}=e.regression;return t.map(i=>({...n,id:`reg-for-${i.name}`,name:i.name,data:In(r,i.data),color:i.color,showSymbol:!1,smooth:!0,tooltip:{show:!1},custom:{type:"regression-line",targetSeries:i.name}}))}function _o(e,t){const n=z(e.x_axis.data_key),r=z(e.regression.y_axis_data_key);return y.uniqBy(t.map(i=>[i[n.columnKey],i[r.columnKey]]),0)}function Eb(e,t){const{plot:n,transform:r}=e.regression,i=_o(e,t);return[{type:"scatter",name:e.y_axis.name,data:i,symbolSize:4,color:"red",markLine:{...n,data:[In(r,i)],color:"blue",smooth:!0,silent:!0,symbol:["none","none"]}}]}function Lb(e,t){const{plot:n,transform:r,group_by_key:i}=e.regression,o=z(i),l=y.groupBy(t,o.columnKey);return Object.entries(l).map(([u,c])=>{const d=_o(e,c);return{type:"scatter",name:u,data:d,symbolSize:4,markLine:{...n,data:[In(r,d)],smooth:!0,silent:!0,symbol:["none","none"]}}})}function Pb(e,t){if(t.length===0)return[];const{group_by_key:n}=e.regression;return n?Lb(e,t):Eb(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 Ob(e){return ne.getTooltip({trigger:"axis",formatter:t=>{const n=Bb(t);return n.length===0?"":`
237
+ `}}const fb={legend:{show:!0,bottom:0,left:0},tooltip:{trigger:"item"}},gb=["#66B4DB","#39BFA2","#E46464","#33A678","#EEBA00","#9D88CB","#939943","#E49792","#09A2B8","#AF5F6B","#6CA157","#09A2B8","#6398C7","#E692BA","#97B566","#8CACE2","#CA79AC","#6DBC80","#B08F4B","#826BAF"];function mb(e,t){const{series_name_key:n,dimensions:r,additional_series:i}=e;if(!n||r.length===0)return{};const l={radar:{indicator:r.map(({name:c,max:u})=>({name:c,max:u})),splitArea:{show:!1}},tooltip:ee.getTooltip({backgroundColor:"rgba(255,255,255,0.6)",formatter:xb(e)}),legend:{show:!0,bottom:0,left:"center",type:"scroll"},series:hb(t,e),color:gb};return y.merge({},fb,l)}function yb({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const l=g.useMemo(()=>{const{queryID:p,columnKey:x}=z(e.series_name_key),m=y.keyBy(t[p],x),j=e.additional_series.reduce((C,T)=>{const D=z(T.name_key),A=y.keyBy(t[D.queryID],D.columnKey);return{...C,...A}},m);return{...m,...j}},[t,e.series_name_key,e.additional_series]),c=Oe(i.triggerManager,wo.id),u=g.useCallback(p=>{const x=y.get(l,p.name,{error:"rowData is not found"});c.forEach(m=>{i.runInteraction(m.id,{...p,rowData:x})})},[l,c,i]),d=g.useMemo(()=>({click:u}),[u]),h=g.useMemo(()=>mb(y.defaultsDeep({},e,Gn),t),[e,t]);return!n||!r?null:s.jsx(we,{echarts:be,option:h,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function bb({context:e,instance:t}){const n=$e({vizManager:e.vizManager,instance:t}),{value:r}=O(e.instanceData,"config"),{variables:i}=e,o=g.useMemo(()=>y.defaults({},r,Gn),[r]),l=e.data,{width:c,height:u}=e.viewport;return!c||!u||!o||y.isEmpty(o==null?void 0:o.dimensions)?null:s.jsx(ke,{width:c,height:u,children:s.jsx(yb,{variables:i,width:Ge(c),height:We(u),data:l,conf:o,interactionManager:n})})}function jb({control:e,index:t,remove:n}){return s.jsxs(a.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:`additional_series.${t}.name_key`,control:e,render:({field:r})=>s.jsx(B,{label:"Series Name Key",required:!0,sx:{flex:1},...r})})}),s.jsx(a.Stack,{children:s.jsx(b.Controller,{name:`additional_series.${t}.color_key`,control:e,render:({field:r})=>s.jsx(B,{label:"Color Key",required:!0,clearable:!0,sx:{flex:1},...r})})}),s.jsx(a.Button,{mt:20,leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),children:"Delete"})]})}function vb({control:e,watch:t}){const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"additional_series"}),o=t("additional_series"),l=n.map((x,m)=>({...x,...o[m]})),c=()=>{const x=new Date().getTime().toString();r({id:x,name_key:"",color_key:""})},u=y.get(l,"0.id",null),[d,h]=g.useState(u);g.useEffect(()=>{h(x=>x||u)},[u]);const p=x=>{i(x);const m=y.get(l,"0.id",null);h(m)};return s.jsxs(s.Fragment,{children:[s.jsxs(a.Alert,{icon:s.jsx(_.IconInfoCircle,{size:16}),title:"Additional Series",children:["By setting ",s.jsx(a.Mark,{children:"Series Name Key"}),", you may add series from more queries to the chart."]}),s.jsxs(a.Tabs,{value:d,onTabChange:h,styles:{tab:{paddingBottom:"0px"},panel:{padding:"0px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((x,m)=>s.jsx(a.Tabs.Tab,{value:x.id,children:m+1},x.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(_.IconPlus,{size:18,color:"#228be6"})})]}),l.map((x,m)=>s.jsx(a.Tabs.Panel,{value:x.id,children:s.jsx(jb,{control:e,index:m,remove:p})},x.id))]})]})}function wb({control:e,index:t,remove:n}){return s.jsxs(a.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,align:"top",children:[s.jsx(b.Controller,{name:`dimensions.${t}.name`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`dimensions.${t}.data_key`,control:e,render:({field:r})=>s.jsx(B,{label:"Data Key",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`dimensions.${t}.max`,control:e,rules:{validate:r=>{if(Number.isNaN(Number(r)))return"A number is required"}},render:({field:r,fieldState:i})=>{var o;return s.jsx(a.TextInput,{label:"Max",required:!0,sx:{flex:1},...r,error:(o=i.error)==null?void 0:o.message})}})]}),s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Value Formatter",labelPosition:"center"}),s.jsx(b.Controller,{name:`dimensions.${t}.formatter`,control:e,render:({field:r})=>s.jsx(Ve,{...r})})]}),s.jsx(a.Button,{mt:20,leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this Metric"})]})}function Cb({control:e,watch:t}){const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"dimensions"}),o=t("dimensions"),l=n.map((x,m)=>({...x,...o[m]})),c=()=>{const x=new Date().getTime().toString();r({id:x,name:x,data_key:"",max:"100",formatter:me})},u=y.get(l,"0.id",null),[d,h]=g.useState(u);g.useEffect(()=>{h(x=>x||u)},[u]);const p=x=>{i(x);const m=y.get(l,"0.id",null);h(m)};return s.jsx(s.Fragment,{children:s.jsxs(a.Tabs,{value:d,onTabChange:h,styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((x,m)=>s.jsx(a.Tabs.Tab,{value:x.id,children:x.name?x.name:m+1},x.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(_.IconPlus,{size:18,color:"#228be6"})})]}),l.map((x,m)=>s.jsx(a.Tabs.Panel,{value:x.id,children:s.jsx(wb,{control:e,index:m,remove:p})},x.id))]})})}function Sb({context:e}){const{value:t,set:n}=O(e.instanceData,"config"),r=g.useMemo(()=>y.defaultsDeep({},t,Gn),[t]),{control:i,handleSubmit:o,watch:l,getValues:c,reset:u,formState:d}=b.useForm({defaultValues:r,mode:"all"});g.useEffect(()=>{u(r)},[r]),l(["series_name_key","background","label"]);const h=c(),p=g.useMemo(()=>!y.isEqual(h,r),[h,r]);return s.jsx("form",{onSubmit:o(n),children:s.jsxs(a.Stack,{spacing:"xs",children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Radar Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p||!d.isValid,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Tabs,{defaultValue:"series",children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"series",children:"Series"}),s.jsx(a.Tabs.Tab,{value:"metrics",children:"Metrics"}),s.jsx(a.Tabs.Tab,{value:"style",children:"Style"}),s.jsx(a.Tabs.Tab,{value:"additional_series",ml:"auto",children:"Additional Series"})]}),s.jsx(a.Tabs.Panel,{value:"series",p:"md",children:s.jsx(b.Controller,{name:"series_name_key",control:i,render:({field:x})=>s.jsx(B,{label:"Series Name Field",required:!0,sx:{flex:1},...x})})}),s.jsx(a.Tabs.Panel,{value:"metrics",p:"md",children:s.jsx(Cb,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"style",p:"md",children:s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"background.enabled",control:i,render:({field:x})=>s.jsx(a.Checkbox,{label:"Show background",checked:x.value,onChange:m=>x.onChange(m.currentTarget.checked)})}),s.jsx(b.Controller,{name:"label.enabled",control:i,render:({field:x})=>s.jsx(a.Checkbox,{label:"Show value label",checked:x.value,onChange:m=>x.onChange(m.currentTarget.checked)})})]})}),s.jsx(a.Tabs.Panel,{value:"additional_series",p:"md",children:s.jsx(vb,{control:i,watch:l})})]})]})})}function _b(e){const{dimensions:t=[],...n}=e;function r({name:i="",data_key:o="",max:l=10,formatter:c=me}){return{name:i,data_key:o,max:l,formatter:c}}return{...n,dimensions:t.map(r)}}function kb(e){const{dimensions:t=[],...n}=e;return{...n,dimensions:t.map(r=>({...r,id:r.id??r.name}))}}function Tb(e){const t={background:{enabled:!0},label:{enabled:!0}};return y.defaultsDeep(t,e)}function Db(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}`,{series_name_key:i,dimensions:o,...l}=e;return{...l,series_name_key:r(i),dimensions:o.map(c=>({...c,data_key:r(c.data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}function Ib(e){const t={additional_series:[]};return y.defaultsDeep(t,e)}function Mb(e){const t={...e,dimensions:e.dimensions.map(n=>({...n,max:String(n.max)}))};return delete t.additionalSeries,t}class zb extends ae{constructor(){super(...arguments);P(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:_b(r)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:kb(r)}}),this.version(4,n=>{const{config:r}=n;return{...n,version:4,config:Tb(r)}}),this.version(5,(n,r)=>{const{config:i}=n;return{...n,version:5,config:Db(i,r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:Ib(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:Mb(r)}})}}const Ab={displayName:"Radar Chart",displayGroup:"ECharts-based charts",migrator:new zb,name:"radar",viewRender:bb,configRender:Sb,createConfig:()=>({version:7,config:Gn}),triggers:[wo]};function Eb(e,t){const{plot:n,transform:r}=e.regression;return t.map(i=>({...n,id:`reg-for-${i.name}`,name:i.name,data:Dn(r,i.data),color:i.color,showSymbol:!1,smooth:!0,tooltip:{show:!1},custom:{type:"regression-line",targetSeries:i.name}}))}function ko(e,t){const n=z(e.x_axis.data_key),r=z(e.regression.y_axis_data_key);return y.uniqBy(t.map(i=>[i[n.columnKey],i[r.columnKey]]),0)}function Pb(e,t){const{plot:n,transform:r}=e.regression,i=ko(e,t);return[{type:"scatter",name:e.y_axis.name,data:i,symbolSize:4,color:"red",markLine:{...n,data:[Dn(r,i)],color:"blue",smooth:!0,silent:!0,symbol:["none","none"]}}]}function Lb(e,t){const{plot:n,transform:r,group_by_key:i}=e.regression,o=z(i),l=y.groupBy(t,o.columnKey);return Object.entries(l).map(([c,u])=>{const d=ko(e,u);return{type:"scatter",name:c,data:d,symbolSize:4,markLine:{...n,data:[Dn(r,d)],smooth:!0,silent:!0,symbol:["none","none"]}}})}function Bb(e,t){if(t.length===0)return[];const{group_by_key:n}=e.regression;return n?Lb(e,t):Pb(e,t)}function Ob(e){return Array.isArray(e)||(e=[e]),e.map(t=>({marker:t.marker,label:t.seriesName,x:t.value[0],y:t.value[1]}))}function $b(e){return ee.getTooltip({trigger:"axis",formatter:t=>{const n=Ob(t);return n.length===0?"":`
238
238
  <table style="width: auto">
239
239
  <thead>
240
240
  <tr>
@@ -253,46 +253,46 @@ Check the top-level render call using <`+E+">.")}return I}}function rc(w,I){{if(
253
253
  </tr>
254
254
  </tbody>
255
255
  </table>
256
- `}})}function ko({enabled:e,func_content:t}){return(n,r)=>{if(!e)return n;try{return new Function(`return ${t}`)()(n,r)}catch(i){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${i.message}`),n}}}function $b(e){const{overflow:t,format:n,formatter:r,...i}=e.x_axis.axisLabel,o=Ve(t.on_axis);return ne.getXAxis({type:"value",name:e.x_axis.name??"",nameLocation:"middle",nameGap:25,axisLabel:{...i,...o,formatter:(l,u)=>{let c=l;try{c=W(l,n)}catch{}return ko(r)(c,u)}}})}const Vb={tooltip:{trigger:"axis"},grid:{top:50,left:5,right:10,bottom:20,containLabel:!0},dataZoom:[{type:"inside",xAxisIndex:[0]},{type:"inside",yAxisIndex:[0]}]};function qb(e,t){const n=Pb(e,t),r=Ab(e,n),i={xAxis:$b(e),yAxis:ne.getYAxis({name:e.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"left"},nameGap:5}),series:[...n,...r],tooltip:Ob(e),legend:{show:!0,type:"scroll",orient:"horizontal",align:"left",right:0,top:0,left:"auto",itemGap:20,padding:[4,8,0,140],data:n.map(o=>o.name)}};return y.defaultsDeep({},i,Vb)}const To={output:"number",mantissa:2,trimMantissa:!0,absolute:!1};function Rn(e,t,n){return 1-(1-e)*(t-1)/(t-n-1)}function Nb(e,t,n,r){const{x_axis:i,y_axis:o}=r,l=xt.regressionLinear()(n),{a:u,b:c,rSquared:d}=l;return{name:e,expression:s.jsxs(a.Group,{position:"center",noWrap:!0,spacing:10,children:[s.jsx(a.Text,{children:o.name}),s.jsx(a.Text,{children:"="}),s.jsx(a.Text,{weight:"bold",color:"red",children:W(c,To)}),s.jsx(a.Text,{children:"+"}),s.jsx(a.Text,{weight:"bold",color:"red",children:W(u,To)}),s.jsx(a.Text,{children:"×"}),s.jsx(a.Text,{children:i.name})]}),rSquared:d,adjustedRSquared:Rn(d,t.length,1)}}function Fb(e,t,n,r){const{x_axis:i,y_axis:o}=r,{a:l,b:u,rSquared:c}=xt.regressionExp()(n);return{name:e,expression:s.jsxs(a.Group,{position:"center",noWrap:!0,spacing:10,children:[s.jsx(a.Text,{children:o.name}),s.jsx(a.Text,{children:"="}),s.jsx(a.Text,{weight:"bold",color:"gray",children:l}),s.jsx(a.Text,{children:"×"}),s.jsxs(a.Group,{position:"left",noWrap:!0,spacing:2,children:[s.jsx(a.Text,{children:"Math.exp("}),s.jsx(a.Text,{weight:"bold",color:"gray",children:u}),s.jsx(a.Text,{children:"×"}),s.jsx(a.Text,{children:i.name}),s.jsx(a.Text,{children:")"})]})]}),rSquared:c,adjustedRSquared:Rn(c,t.length,1)}}function Gb(e,t,n,r){const{x_axis:i,y_axis:o}=r,{a:l,b:u,rSquared:c}=xt.regressionLog()(n);return{name:e,expression:s.jsxs(a.Group,{position:"center",noWrap:!0,spacing:10,children:[s.jsx(a.Text,{children:o.name}),s.jsx(a.Text,{children:"="}),s.jsx(a.Text,{weight:"bold",color:"gray",children:l}),s.jsx(a.Text,{children:"×"}),s.jsxs(a.Group,{position:"left",noWrap:!0,spacing:2,children:[s.jsx(a.Text,{children:"Math.log("}),s.jsx(a.Text,{children:i.name}),s.jsx(a.Text,{children:")"}),s.jsx(a.Text,{children:"+"}),s.jsx(a.Text,{weight:"bold",color:"gray",children:u})]})]}),rSquared:c,adjustedRSquared:Rn(c,t.length,1)}}function Wb(e,t,n,r){const{x_axis:i,y_axis:o,regression:l}=r,u=xt.regressionPoly().order(l.transform.config.order)(n),{rSquared:c}=u;return console.log(u),{name:e,expression:"",rSquared:c,adjustedRSquared:Rn(c,t.length,1)}}function Do(e,t,n){const{regression:r,x_axis:i}=n,o=z(i.data_key),l=z(r.y_axis_data_key),u=t.map(c=>[c[o.columnKey],c[l.columnKey]]);return r.transform.config.method==="linear"?Nb(e,t,u,n):r.transform.config.method==="exponential"?Fb(e,t,u,n):r.transform.config.method==="logarithmic"?Gb(e,t,u,n):r.transform.config.method==="polynomial"?Wb(e,t,u,n):{name:e,expression:"",rSquared:0,adjustedRSquared:0}}function Rb(e,t){if(!t)return[{name:"",expression:"",rSquared:0,adjustedRSquared:0}];if(!t.regression.group_by_key)return[Do("",e,t)];const n=z(t.regression.group_by_key),r=y.groupBy(e,n.columnKey);return Object.entries(r).map(([i,o])=>Do(i,o,t))}const Qb={marginTop:"10px","tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function Io({desc:e}){const{expression:t,rSquared:n,adjustedRSquared:r}=e;return t?s.jsx(a.Table,{fontSize:14,sx:Qb,children:s.jsxs("tbody",{children:[s.jsx("tr",{children:s.jsx("td",{colSpan:2,children:s.jsx(a.Text,{align:"center",children:t})})}),s.jsxs("tr",{children:[s.jsx("td",{children:"R-Sq"}),s.jsx("td",{style:{textAlign:"right"},children:W(n,{output:"percent",mantissa:1,absolute:!1})})]}),s.jsxs("tr",{children:[s.jsx("td",{children:"R-Sq(Adjusted)"}),s.jsx("td",{style:{textAlign:"right"},children:W(r,{output:"percent",mantissa:1,absolute:!1})})]})]})}):s.jsx(a.Text,{children:"Unavailable for this regression method"})}function Ub({conf:e,queryData:t}){var r;const n=g.useMemo(()=>Rb(t,e),[e,t]);return e.regression.group_by_key?(console.log(n),s.jsxs(a.Tabs,{defaultValue:(r=n[0])==null?void 0:r.name,color:"gray",children:[s.jsx(a.Tabs.List,{grow:!0,children:n.map(i=>s.jsx(a.Tabs.Tab,{value:i.name,children:i.name},i.name))}),n.map(i=>s.jsx(a.Tabs.Panel,{value:i.name,children:s.jsx(Io,{desc:i})},i.name))]})):s.jsx(Io,{desc:n[0]})}function Kb({conf:e,queryData:t}){return s.jsxs(a.HoverCard,{shadow:"md",withinPortal:!0,zIndex:320,children:[s.jsx(a.HoverCard.Target,{children:s.jsx(a.Button,{size:"xs",variant:"subtle",compact:!0,leftIcon:s.jsx(_.IconInfoCircle,{size:14}),children:"Regression Info"})}),s.jsx(a.HoverCard.Dropdown,{children:s.jsx(we,{children:s.jsx(Ub,{conf:e,queryData:t})})})]})}function Yb(e){return s.jsx(a.Group,{position:"apart",sx:{position:"absolute",top:0,left:De.left,right:De.right,height:"22px",zIndex:1},children:s.jsx(Kb,{...e})})}const Qn={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
257
- `)},cr={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,format:je,overflow:Me(),formatter:{...Qn}}},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"}};J.use([B.DataZoomComponent,ie.ScatterChart,B.GridComponent,B.LegendComponent,B.TooltipComponent,_e.CanvasRenderer]);function Xb({context:e}){const{value:t}=$(e.instanceData,"config"),{width:n,height:r}=e.viewport,i=g.useMemo(()=>{var m;const c=e.data,d=t==null?void 0:t.x_axis.data_key,h=(m=t==null?void 0:t.regression)==null?void 0:m.y_axis_data_key;if(!d||!h)return[];const p=z(d),x=z(h);return c[p.queryID].map(j=>typeof j[x.columnKey]=="number"?j:{...j,[x.columnKey]:Number(j[x.columnKey])})},[e.data,t==null?void 0:t.regression.y_axis_data_key]),o=g.useMemo(()=>qb(y.defaultsDeep({},t,cr),i),[t,i]),l=g.useRef(null),u=c=>{l.current=c};return!n||!r||!t?null:s.jsxs(Ie,{width:n,height:r,children:[s.jsx(Yb,{conf:t,queryData:i}),s.jsx(Se,{echarts:J,onChartReady:u,option:o,style:Ht(n,r),notMerge:!0,theme:"merico-light"})]})}const Jb=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}];function Zb({control:e,watch:t}){t("regression");const n=t("regression.transform.config.method"),r=t("regression.group_by_key");return s.jsxs(a.Stack,{children:[s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:"regression.name",control:e,render:({field:i})=>s.jsx(a.TextInput,{label:"回归线名称",sx:{flex:1},...i})})}),s.jsx(b.Controller,{name:"regression.group_by_key",control:e,render:({field:i})=>s.jsx(O,{label:"按此字段将数据分为多个系列",clearable:!0,sx:{flex:1},...i})}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"regression.transform.config.method",control:e,render:({field:i})=>s.jsx(a.Select,{label:"回归方法",data:Jb,sx:{flex:1},...i})}),n==="polynomial"&&s.jsx(b.Controller,{name:"regression.transform.config.order",control:e,render:({field:i})=>s.jsx(a.NumberInput,{label:"次",sx:{flex:1},...i})})]}),!r&&s.jsxs(a.Stack,{spacing:4,children:[s.jsx(a.Text,{size:"sm",children:"颜色"}),s.jsx(b.Controller,{name:"regression.plot.color",control:e,render:({field:i})=>s.jsx(ke,{...i})})]})]})}const Hb=({disabled:e,value:t,onChange:n})=>{const r=i=>{i&&n(i)};return s.jsxs(a.Box,{sx:{position:"relative"},children:[e&&s.jsx(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),s.jsx(ye,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},Mo=g.forwardRef(({value:e,onChange:t,triggerButtonText:n="Customize Label"},r)=>{const[i,{setTrue:o,setFalse:l}]=V.useBoolean(),[u,c]=g.useState(e);g.useEffect(()=>{c(e)},[e]);const d=j=>{c({...u,enabled:j})},h=()=>{l();const{enabled:j,func_content:C}=u,T={enabled:j,func_content:C};c(T),t(T)},p=()=>{l(),c(e)},x=j=>{c(C=>({...C,func_content:j}))},m=()=>{x(Qn.func_content)};return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"filled",mt:24,onClick:o,sx:{flexGrow:0},children:n}),s.jsx(a.Modal,{size:800,title:"Customize label content",opened:i,onClose:l,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:i&&s.jsxs(a.Stack,{children:[s.jsx(a.Checkbox,{mt:10,label:"Enabled",checked:u.enabled,onChange:j=>d(j.currentTarget.checked)}),s.jsx(Hb,{value:u.func_content,onChange:x,disabled:!u.enabled}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:m,color:"red",leftIcon:s.jsx(k.Recycle,{size:20}),children:"Reset"}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:p,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:h,children:"OK"})]})]})]})})]})});function ej({control:e,watch:t}){return t(["x_axis"]),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"X轴名称",sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>s.jsx(O,{label:"X轴数据字段",required:!0,sx:{flex:1},...n})})]}),s.jsx(a.Divider,{variant:"dashed",labelPosition:"center",label:"格式化数据"}),s.jsx(a.Stack,{children:s.jsx(b.Controller,{name:"x_axis.axisLabel.format",control:e,render:({field:n})=>s.jsx(Fe,{...n})})}),s.jsx(a.Divider,{variant:"dashed",labelPosition:"center",label:"标签文案样式"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>s.jsx(a.NumberInput,{label:"旋转",hideControls:!0,min:-90,max:90,rightSection:s.jsx(a.Text,{color:"dimmed",children:"度"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),s.jsx(b.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>s.jsx(Mo,{triggerButtonText:"自定义标签文案内容",...n})})]}),s.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>s.jsx(Ke,{...n})})]})}function tj({control:e,watch:t}){return t(["y_axis","regression.y_axis_data_key"]),s.jsx(a.Stack,{children:s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"y_axis.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"Y轴名称",sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"regression.y_axis_data_key",control:e,render:({field:n})=>s.jsx(O,{label:"Y轴数据字段",required:!0,sx:{flex:1},...n})})]})})}function nj({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=g.useMemo(()=>y.defaults({},t,cr),[t]),{control:i,handleSubmit:o,watch:l,getValues:u,reset:c}=b.useForm({defaultValues:r});g.useEffect(()=>{c(r)},[r]),l(["x_axis","y_axis","regression"]);const d=u(),h=g.useMemo(()=>!y.isEqual(d,t),[d,t]);return s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:o(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Chart Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Tabs,{defaultValue:"X轴",orientation:"vertical",styles:{panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"X轴",children:"X轴"}),s.jsx(a.Tabs.Tab,{value:"Y轴",children:"Y轴"}),s.jsx(a.Tabs.Tab,{value:"回归",children:"回归"})]}),s.jsx(a.Tabs.Panel,{value:"X轴",children:s.jsx(ej,{watch:l,control:i})}),s.jsx(a.Tabs.Panel,{value:"Y轴",children:s.jsx(tj,{watch:l,control:i})}),s.jsx(a.Tabs.Panel,{value:"回归",children:s.jsx(Zb,{control:i,watch:l})})]})]})})}function sj(e){const t={x_axis:{axisLabel:{rotate:0,format:je,overflow:Me(),formatter:Qn}},regression:{group_by_key:""}};return y.defaultsDeep(t,e)}function rj(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis:i,regression:o,...l}=e;return{...l,x_axis:{...i,data_key:r(i.data_key)},regression:{...o,group_by_key:r(o.group_by_key),y_axis_data_key:r(o.y_axis_data_key)}}}catch(n){throw console.error("[Migration failed]",n),n}}class ij extends ue{constructor(){super(...arguments);L(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:sj(n.config)})),this.version(3,(n,r)=>{const{config:i}=n;return{...n,version:3,config:rj(i,r)}})}}const aj={displayName:"Regression Chart",displayGroup:"Merico suite",migrator:new ij,name:"regressionChart",viewRender:Xb,configRender:nj,createConfig(){return{version:3,config:y.cloneDeep(cr)}}},Un={content:""};function oj(e,t){const n={};return e.forEach(r=>{const{name:i,data_field:o,aggregation:l}=r,u=bn(t,o,l);n[i]=Pe(r,u)}),n}function lj(e){const t=document.createElement("span");return t.innerHTML=e,t.innerText}function uj(e,t,n){try{return new Function("payload",`
256
+ `}})}function To({enabled:e,func_content:t}){return(n,r)=>{if(!e)return n;try{return new Function(`return ${t}`)()(n,r)}catch(i){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${i.message}`),n}}}function Vb(e){const{overflow:t,format:n,formatter:r,...i}=e.x_axis.axisLabel,o=Be(t.on_axis);return ee.getXAxis({type:"value",name:e.x_axis.name??"",nameLocation:"middle",nameGap:25,axisLabel:{...i,...o,formatter:(l,c)=>{let u=l;try{u=G(l,n)}catch{}return To(r)(u,c)}}})}const qb={tooltip:{trigger:"axis"},grid:{top:50,left:5,right:10,bottom:20,containLabel:!0},dataZoom:[{type:"inside",xAxisIndex:[0]},{type:"inside",yAxisIndex:[0]}]};function Nb(e,t){const n=Bb(e,t),r=Eb(e,n),i={xAxis:Vb(e),yAxis:ee.getYAxis({name:e.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"left"},nameGap:5}),series:[...n,...r],tooltip:$b(e),legend:{show:!0,type:"scroll",orient:"horizontal",align:"left",right:0,top:0,left:"auto",itemGap:20,padding:[4,8,0,140],data:n.map(o=>o.name)}};return y.defaultsDeep({},i,qb)}const Do={output:"number",mantissa:2,trimMantissa:!0,absolute:!1};function Wn(e,t,n){return 1-(1-e)*(t-1)/(t-n-1)}function Fb(e,t,n,r){const{x_axis:i,y_axis:o}=r,l=ht.regressionLinear()(n),{a:c,b:u,rSquared:d}=l;return{name:e,expression:s.jsxs(a.Group,{position:"center",noWrap:!0,spacing:10,children:[s.jsx(a.Text,{children:o.name}),s.jsx(a.Text,{children:"="}),s.jsx(a.Text,{weight:"bold",color:"red",children:G(u,Do)}),s.jsx(a.Text,{children:"+"}),s.jsx(a.Text,{weight:"bold",color:"red",children:G(c,Do)}),s.jsx(a.Text,{children:"×"}),s.jsx(a.Text,{children:i.name})]}),rSquared:d,adjustedRSquared:Wn(d,t.length,1)}}function Gb(e,t,n,r){const{x_axis:i,y_axis:o}=r,{a:l,b:c,rSquared:u}=ht.regressionExp()(n);return{name:e,expression:s.jsxs(a.Group,{position:"center",noWrap:!0,spacing:10,children:[s.jsx(a.Text,{children:o.name}),s.jsx(a.Text,{children:"="}),s.jsx(a.Text,{weight:"bold",color:"gray",children:l}),s.jsx(a.Text,{children:"×"}),s.jsxs(a.Group,{position:"left",noWrap:!0,spacing:2,children:[s.jsx(a.Text,{children:"Math.exp("}),s.jsx(a.Text,{weight:"bold",color:"gray",children:c}),s.jsx(a.Text,{children:"×"}),s.jsx(a.Text,{children:i.name}),s.jsx(a.Text,{children:")"})]})]}),rSquared:u,adjustedRSquared:Wn(u,t.length,1)}}function Wb(e,t,n,r){const{x_axis:i,y_axis:o}=r,{a:l,b:c,rSquared:u}=ht.regressionLog()(n);return{name:e,expression:s.jsxs(a.Group,{position:"center",noWrap:!0,spacing:10,children:[s.jsx(a.Text,{children:o.name}),s.jsx(a.Text,{children:"="}),s.jsx(a.Text,{weight:"bold",color:"gray",children:l}),s.jsx(a.Text,{children:"×"}),s.jsxs(a.Group,{position:"left",noWrap:!0,spacing:2,children:[s.jsx(a.Text,{children:"Math.log("}),s.jsx(a.Text,{children:i.name}),s.jsx(a.Text,{children:")"}),s.jsx(a.Text,{children:"+"}),s.jsx(a.Text,{weight:"bold",color:"gray",children:c})]})]}),rSquared:u,adjustedRSquared:Wn(u,t.length,1)}}function Rb(e,t,n,r){const{x_axis:i,y_axis:o,regression:l}=r,c=ht.regressionPoly().order(l.transform.config.order)(n),{rSquared:u}=c;return console.log(c),{name:e,expression:"",rSquared:u,adjustedRSquared:Wn(u,t.length,1)}}function Io(e,t,n){const{regression:r,x_axis:i}=n,o=z(i.data_key),l=z(r.y_axis_data_key),c=t.map(u=>[u[o.columnKey],u[l.columnKey]]);return r.transform.config.method==="linear"?Fb(e,t,c,n):r.transform.config.method==="exponential"?Gb(e,t,c,n):r.transform.config.method==="logarithmic"?Wb(e,t,c,n):r.transform.config.method==="polynomial"?Rb(e,t,c,n):{name:e,expression:"",rSquared:0,adjustedRSquared:0}}function Qb(e,t){if(!t)return[{name:"",expression:"",rSquared:0,adjustedRSquared:0}];if(!t.regression.group_by_key)return[Io("",e,t)];const n=z(t.regression.group_by_key),r=y.groupBy(e,n.columnKey);return Object.entries(r).map(([i,o])=>Io(i,o,t))}const Ub={marginTop:"10px","tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function Mo({desc:e}){const{expression:t,rSquared:n,adjustedRSquared:r}=e;return t?s.jsx(a.Table,{fontSize:14,sx:Ub,children:s.jsxs("tbody",{children:[s.jsx("tr",{children:s.jsx("td",{colSpan:2,children:s.jsx(a.Text,{align:"center",children:t})})}),s.jsxs("tr",{children:[s.jsx("td",{children:"R-Sq"}),s.jsx("td",{style:{textAlign:"right"},children:G(n,{output:"percent",mantissa:1,absolute:!1})})]}),s.jsxs("tr",{children:[s.jsx("td",{children:"R-Sq(Adjusted)"}),s.jsx("td",{style:{textAlign:"right"},children:G(r,{output:"percent",mantissa:1,absolute:!1})})]})]})}):s.jsx(a.Text,{children:"Unavailable for this regression method"})}function Kb({conf:e,queryData:t}){var r;const n=g.useMemo(()=>Qb(t,e),[e,t]);return e.regression.group_by_key?(console.log(n),s.jsxs(a.Tabs,{defaultValue:(r=n[0])==null?void 0:r.name,color:"gray",children:[s.jsx(a.Tabs.List,{grow:!0,children:n.map(i=>s.jsx(a.Tabs.Tab,{value:i.name,children:i.name},i.name))}),n.map(i=>s.jsx(a.Tabs.Panel,{value:i.name,children:s.jsx(Mo,{desc:i})},i.name))]})):s.jsx(Mo,{desc:n[0]})}function Yb({conf:e,queryData:t}){return s.jsxs(a.HoverCard,{shadow:"md",withinPortal:!0,zIndex:320,children:[s.jsx(a.HoverCard.Target,{children:s.jsx(a.Button,{size:"xs",variant:"subtle",compact:!0,leftIcon:s.jsx(_.IconInfoCircle,{size:14}),children:"Regression Info"})}),s.jsx(a.HoverCard.Dropdown,{children:s.jsx(je,{children:s.jsx(Kb,{conf:e,queryData:t})})})]})}function Xb(e){return s.jsx(a.Group,{position:"apart",sx:{position:"absolute",top:0,left:_e.left,right:_e.right,height:"22px",zIndex:1},children:s.jsx(Yb,{...e})})}const Rn={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
257
+ `)},cr={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,format:me,overflow:Te(),formatter:{...Rn}}},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"}};function Jb({context:e}){const{value:t}=O(e.instanceData,"config"),{width:n,height:r}=e.viewport,i=g.useMemo(()=>{var m;const u=e.data,d=t==null?void 0:t.x_axis.data_key,h=(m=t==null?void 0:t.regression)==null?void 0:m.y_axis_data_key;if(!d||!h)return[];const p=z(d),x=z(h);return u[p.queryID].map(j=>typeof j[x.columnKey]=="number"?j:{...j,[x.columnKey]:Number(j[x.columnKey])})},[e.data,t==null?void 0:t.regression.y_axis_data_key]),o=g.useMemo(()=>Nb(y.defaultsDeep({},t,cr),i),[t,i]),l=g.useRef(null),c=u=>{l.current=u};return!n||!r||!t?null:s.jsxs(ke,{width:n,height:r,children:[s.jsx(Xb,{conf:t,queryData:i}),s.jsx(we,{echarts:be,onChartReady:c,option:o,style:Zt(n,r),notMerge:!0,theme:"merico-light"})]})}const Zb=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}];function Hb({control:e,watch:t}){t("regression");const n=t("regression.transform.config.method"),r=t("regression.group_by_key");return s.jsxs(a.Stack,{children:[s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:"regression.name",control:e,render:({field:i})=>s.jsx(a.TextInput,{label:"回归线名称",sx:{flex:1},...i})})}),s.jsx(b.Controller,{name:"regression.group_by_key",control:e,render:({field:i})=>s.jsx(B,{label:"按此字段将数据分为多个系列",clearable:!0,sx:{flex:1},...i})}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"regression.transform.config.method",control:e,render:({field:i})=>s.jsx(a.Select,{label:"回归方法",data:Zb,sx:{flex:1},...i})}),n==="polynomial"&&s.jsx(b.Controller,{name:"regression.transform.config.order",control:e,render:({field:i})=>s.jsx(a.NumberInput,{label:"次",sx:{flex:1},...i})})]}),!r&&s.jsxs(a.Stack,{spacing:4,children:[s.jsx(a.Text,{size:"sm",children:"颜色"}),s.jsx(b.Controller,{name:"regression.plot.color",control:e,render:({field:i})=>s.jsx(Ce,{...i})})]})]})}const ej=({disabled:e,value:t,onChange:n})=>{const r=i=>{i&&n(i)};return s.jsxs(a.Box,{sx:{position:"relative"},children:[e&&s.jsx(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),s.jsx(fe,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},zo=g.forwardRef(({value:e,onChange:t,triggerButtonText:n="Customize Label"},r)=>{const[i,{setTrue:o,setFalse:l}]=$.useBoolean(),[c,u]=g.useState(e);g.useEffect(()=>{u(e)},[e]);const d=j=>{u({...c,enabled:j})},h=()=>{l();const{enabled:j,func_content:C}=c,T={enabled:j,func_content:C};u(T),t(T)},p=()=>{l(),u(e)},x=j=>{u(C=>({...C,func_content:j}))},m=()=>{x(Rn.func_content)};return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"filled",mt:24,onClick:o,sx:{flexGrow:0},children:n}),s.jsx(a.Modal,{size:800,title:"Customize label content",opened:i,onClose:l,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:i&&s.jsxs(a.Stack,{children:[s.jsx(a.Checkbox,{mt:10,label:"Enabled",checked:c.enabled,onChange:j=>d(j.currentTarget.checked)}),s.jsx(ej,{value:c.func_content,onChange:x,disabled:!c.enabled}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:m,color:"red",leftIcon:s.jsx(k.Recycle,{size:20}),children:"Reset"}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:p,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:h,children:"OK"})]})]})]})})]})});function tj({control:e,watch:t}){return t(["x_axis"]),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"X轴名称",sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>s.jsx(B,{label:"X轴数据字段",required:!0,sx:{flex:1},...n})})]}),s.jsx(a.Divider,{variant:"dashed",labelPosition:"center",label:"格式化数据"}),s.jsx(a.Stack,{children:s.jsx(b.Controller,{name:"x_axis.axisLabel.format",control:e,render:({field:n})=>s.jsx(Ve,{...n})})}),s.jsx(a.Divider,{variant:"dashed",labelPosition:"center",label:"标签文案样式"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>s.jsx(a.NumberInput,{label:"旋转",hideControls:!0,min:-90,max:90,rightSection:s.jsx(a.Text,{color:"dimmed",children:"度"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),s.jsx(b.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>s.jsx(zo,{triggerButtonText:"自定义标签文案内容",...n})})]}),s.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>s.jsx(Re,{...n})})]})}function nj({control:e,watch:t}){return t(["y_axis","regression.y_axis_data_key"]),s.jsx(a.Stack,{children:s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"y_axis.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"Y轴名称",sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"regression.y_axis_data_key",control:e,render:({field:n})=>s.jsx(B,{label:"Y轴数据字段",required:!0,sx:{flex:1},...n})})]})})}function sj({context:e}){const{value:t,set:n}=O(e.instanceData,"config"),r=g.useMemo(()=>y.defaults({},t,cr),[t]),{control:i,handleSubmit:o,watch:l,getValues:c,reset:u}=b.useForm({defaultValues:r});g.useEffect(()=>{u(r)},[r]),l(["x_axis","y_axis","regression"]);const d=c(),h=g.useMemo(()=>!y.isEqual(d,t),[d,t]);return s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:o(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Chart Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Tabs,{defaultValue:"X轴",orientation:"vertical",styles:{panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"X轴",children:"X轴"}),s.jsx(a.Tabs.Tab,{value:"Y轴",children:"Y轴"}),s.jsx(a.Tabs.Tab,{value:"回归",children:"回归"})]}),s.jsx(a.Tabs.Panel,{value:"X轴",children:s.jsx(tj,{watch:l,control:i})}),s.jsx(a.Tabs.Panel,{value:"Y轴",children:s.jsx(nj,{watch:l,control:i})}),s.jsx(a.Tabs.Panel,{value:"回归",children:s.jsx(Hb,{control:i,watch:l})})]})]})})}function rj(e){const t={x_axis:{axisLabel:{rotate:0,format:me,overflow:Te(),formatter:Rn}},regression:{group_by_key:""}};return y.defaultsDeep(t,e)}function ij(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:i,regression:o,...l}=e;return{...l,x_axis:{...i,data_key:r(i.data_key)},regression:{...o,group_by_key:r(o.group_by_key),y_axis_data_key:r(o.y_axis_data_key)}}}catch(n){throw console.error("[Migration failed]",n),n}}class aj extends ae{constructor(){super(...arguments);P(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:rj(n.config)})),this.version(3,(n,r)=>{const{config:i}=n;return{...n,version:3,config:ij(i,r)}})}}const oj={displayName:"Regression Chart",displayGroup:"Merico suite",migrator:new aj,name:"regressionChart",viewRender:Jb,configRender:sj,createConfig(){return{version:3,config:y.cloneDeep(cr)}}},Qn={content:""};function lj(e,t){const n={};return e.forEach(r=>{const{name:i,data_field:o,aggregation:l}=r,c=yn(t,o,l);n[i]=Ae(r,c)}),n}function cj(e){const t=document.createElement("span");return t.innerHTML=e,t.innerText}function uj(e,t,n){try{return new Function("payload",`
258
258
  const filters = payload.filters;
259
259
  const context = payload.context;
260
260
  ${Object.entries(t).map(([r,i])=>`const ${r} = '${i}';`).join(`
261
261
  `)}
262
262
  return ${e};
263
- `)(n)}catch(r){return console.error(r),console.log(e),e}}function cj(e,t,n,r){const i=oj(t,r),o=/^(.+)\}\}(.*)$/;return e.split("{{").map(l=>{const u=o.exec(l);if(!u)return l;const c=i[u[1]];if(c){const h=u[2]??"";return`${c}${h}`}const d=lj(u[1]);return`${uj(d,i,n)}${u[2]}`}).join("")}const dj=S.observer(({context:e})=>{const t=pe(),{value:n}=$(e.instanceData,"config"),{variables:r,data:i}=e,o=g.useMemo(()=>{const l=y.defaults({},n,Un);return l.content?cj(l.content,r,t.payloadForViz,i):""},[n,r,t.payloadForViz]);return o?s.jsx(Fn,{value:o,styles:{root:{border:"none",height:"100%"},content:{padding:0}}}):null});function pj(){const{editor:e}=N.useRichTextEditorContext();return s.jsx(N.RichTextEditor.Control,{onClick:()=>e==null?void 0:e.commands.insertTable({rows:3,cols:3,withHeaderRow:!0}),"aria-label":"Insert table",title:"Insert table",children:s.jsx(_.IconBorderAll,{stroke:1.5,size:16})})}const dr=g.forwardRef(({value:e,onChange:t,styles:n={},label:r,onSubmit:i},o)=>{const[l,u]=g.useState(e),c=Gi.useEditor({extensions:[Wi,Fi,N.Link,Pi,Li,Ai,$i.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),Ni,qi,Vi,Bi.configure({types:["heading","paragraph"]}),Ei.configure({placeholder:"This is placeholder"}),Oi,zi.Color,co],content:l,onUpdate:({editor:x})=>{u(x.getHTML())}});g.useEffect(()=>{u(e),c==null||c.commands.setContent(e)},[e]);const d=()=>{t(l),i==null||i()},h=e!==l,p=g.useMemo(()=>y.defaultsDeep({},{content:Fs},n),[n]);return c?s.jsxs(a.Stack,{spacing:4,sx:{flexGrow:1,position:"relative"},children:[s.jsxs(a.Group,{align:"center",children:[s.jsx(a.Text,{size:14,fw:500,children:r}),s.jsx(a.ActionIcon,{color:"blue",disabled:!h,onClick:d,children:s.jsx(_.IconDeviceFloppy,{size:18})})]}),s.jsxs(N.RichTextEditor,{editor:c,styles:p,children:[s.jsxs(N.RichTextEditor.Toolbar,{sticky:!0,stickyOffset:0,children:[s.jsx(N.RichTextEditor.ControlsGroup,{children:s.jsx(N.RichTextEditor.ColorPicker,{colors:["#25262b","#868e96","#fa5252","#e64980","#be4bdb","#7950f2","#4c6ef5","#228be6","#15aabf","#12b886","#40c057","#82c91e","#fab005","#fd7e14"],popoverProps:{zIndex:320}})}),s.jsxs(N.RichTextEditor.ControlsGroup,{children:[s.jsx(N.RichTextEditor.Bold,{}),s.jsx(N.RichTextEditor.Italic,{}),s.jsx(N.RichTextEditor.Underline,{}),s.jsx(N.RichTextEditor.ClearFormatting,{}),s.jsx(N.RichTextEditor.Highlight,{}),s.jsx(N.RichTextEditor.Code,{})]}),s.jsxs(N.RichTextEditor.ControlsGroup,{children:[s.jsx(N.RichTextEditor.H1,{}),s.jsx(N.RichTextEditor.H2,{}),s.jsx(N.RichTextEditor.H3,{}),s.jsx(N.RichTextEditor.H4,{})]}),s.jsxs(N.RichTextEditor.ControlsGroup,{children:[s.jsx(N.RichTextEditor.Blockquote,{}),s.jsx(N.RichTextEditor.Hr,{}),s.jsx(N.RichTextEditor.BulletList,{}),s.jsx(N.RichTextEditor.OrderedList,{}),s.jsx(N.RichTextEditor.Subscript,{}),s.jsx(N.RichTextEditor.Superscript,{})]}),s.jsxs(N.RichTextEditor.ControlsGroup,{children:[s.jsx(N.RichTextEditor.Link,{}),s.jsx(N.RichTextEditor.Unlink,{})]}),s.jsxs(N.RichTextEditor.ControlsGroup,{children:[s.jsx(N.RichTextEditor.AlignLeft,{}),s.jsx(N.RichTextEditor.AlignCenter,{}),s.jsx(N.RichTextEditor.AlignJustify,{}),s.jsx(N.RichTextEditor.AlignRight,{})]}),s.jsx(N.RichTextEditor.ControlsGroup,{children:s.jsx(pj,{})}),s.jsx(fg,{editor:c})]}),s.jsx(N.RichTextEditor.Content,{})]})]}):null});function hj({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=g.useMemo(()=>y.defaults({},t,Un),[t]),{control:i,handleSubmit:o,watch:l,reset:u}=b.useForm({defaultValues:r});l("content"),g.useEffect(()=>{u(r)},[r]);const c=g.useRef(null),d=()=>{var h;return(h=c.current)==null?void 0:h.click()};return s.jsx("form",{onSubmit:o(n),style:{flexGrow:1,display:"flex",flexDirection:"column"},children:s.jsxs(a.Stack,{spacing:"xs",sx:{flexGrow:1},children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",display:"none"},children:[s.jsx(a.Text,{children:"Content"}),s.jsx(a.ActionIcon,{ref:c,type:"submit",mr:5,variant:"filled",color:"blue",children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsx(b.Controller,{name:"content",control:i,render:({field:h})=>s.jsx(dr,{...h,styles:{root:{flexGrow:1}},label:"Content",onSubmit:d})})]})})}class xj extends ue{constructor(){super(...arguments);L(this,"VERSION",1)}fixMalformedConfig(n){return y.defaults({},n,Un)}configVersions(){this.version(1,n=>({version:1,config:this.fixMalformedConfig(n)}))}}const fj={displayName:"Rich Text",displayGroup:"Others",migrator:new xj,name:"richText",viewRender:dj,configRender:hj,createConfig(){return{version:1,config:y.cloneDeep(Un)}}},on={static:{type:"static",color:st.random().css()},dynamic:{type:"dynamic",func_content:["function getColor({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here",' // return "blue"',"}"].join(`
264
- `)}},zo={id:"builtin:echarts:click-scatter-chart:series",displayName:"Click Scatter",nameRender:mj,configRender:gj,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 gj(e){return s.jsx(s.Fragment,{})}function mj(e){return s.jsx(a.Text,{children:"Click scatter"})}function Ao(){return{enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
265
- `)}}function Eo(){const{on_axis:e,in_tooltip:t}=Me();return{label:e,tooltip:t}}const pr={scatter:{y_data_key:"",name_data_key:"",symbolSize:{type:"static",size:10},color:on.static,label_position:"right",label_overflow:Eo()},stats:{templates:{top:"",bottom:""}},x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:Ao(),overflow:Me()}},y_axes:[{name:"Y Axis",position:"left",nameAlignment:"center",label_formatter:je,min:"",max:"",show:!0}],tooltip:{trigger:"item",metrics:[]},reference_lines:[],reference_areas:[],dataZoom:jt};function yj(e,t){if(!e.x_axis.data_key)return[];const n=z(e.x_axis.data_key);return[{source:t[n.queryID]}]}function bj(e){const t=e.y_axes.some(i=>!!i.name);let n=15;t&&(n+=20),e.dataZoom.x_axis_slider&&(n+=20);let r=5;return e.x_axis.name&&(r+=15),{top:n,bottom:r}}function jj(){return{show:!1,bottom:0,left:"center",type:"scroll"}}function Kn(e,t){if(e)return t[e]??void 0}function vj({reference_areas:e,variableValueMap:t}){const n=e.map(r=>[{name:r.content.text,value:r.content.text,itemStyle:r.itemStyle,label:r.label,xAxis:Kn(r.leftBottomPoint.x_data_key,t),yAxis:Kn(r.leftBottomPoint.y_data_key,t)},{xAxis:Kn(r.rightTopPoint.x_data_key,t),yAxis:Kn(r.rightTopPoint.y_data_key,t)}]);return{type:"scatter",name:"ref_areas",silent:!0,data:[],markArea:{data:n}}}function wj({type:e,...t},n){if(!e)return 10;if(e==="static"){const{size:i}=t;return i}const{func_content:r}=t;return(i,o)=>{const l=o.data;try{return new Function(`return ${r}`)()({rowData:l,params:o,variables:n},{lodash:y,interpolate:bt.interpolate})}catch(u){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${u.message}`),10}}}function Cj({type:e,...t},n){if(!e)return on.static.color;if(e==="static"){const{color:i}=t;return i}const{func_content:r}=t;return({value:i})=>{try{return new Function(`return ${r}`)()({rowData:i,variables:n},{lodash:y,interpolate:bt.interpolate})}catch(o){return console.error(`[getSeriesColor] failed parsing custom function, error: ${o.message}`),10}}}function Sj(e,t,n,r){return e.map(i=>{const o=i.orientation==="horizontal",l=o?"yAxis":"xAxis",u=o?"insideEndTop":"end";return{name:i.name,type:"line",hide_in_legend:!i.show_in_legend,yAxisIndex:i.yAxisIndex,data:[],lineStyle:i.lineStyle,markLine:{data:[{name:i.name,[l]:Number(n[i.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:i.lineStyle,label:{formatter:function(){return i.template?jn(i.template,t,r):""},position:u}}}})}function _j({x_axis:e,scatter:t},n){const r=z(e.data_key),i=z(t.y_data_key),o=z(t.name_data_key);return{label:{show:!!t.label_position,position:t.label_position,...Ve(t.label_overflow.label),formatter:({value:l})=>l[o.columnKey]},type:"scatter",name:"",xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{color:Cj(t.color,n)},symbolSize:wj(t.symbolSize,n),encode:{x:r.columnKey,y:i.columnKey}}}function kj(e,t,n,r){return[_j(e,r)].concat(Sj(e.reference_lines,n,r,t)).concat(vj({reference_areas:e.reference_areas,variableValueMap:r}))}function Lo({enabled:e,func_content:t}){return(n,r)=>{if(!e)return n;try{return new Function(`return ${t}`)()(n,r)}catch(i){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${i.message}`),n}}}function Po(e,t,n){const{x_axis:r}=n;return r.axisLabel.formatter.enabled?Lo(r.axisLabel.formatter)(e,t):e}function Tj(e,t){const{x_axis:n,tooltip:r}=t;if(r.trigger==="item"){const u=yn(e[0].data,n.data_key);return Po(u,0,t)}const i=e.find(u=>u.axisDim==="x"&&u.axisId==="main-x-axis");if(!i)return"";const{axisValue:o,axisIndex:l}=i;return Po(o,l,t)}const Dj=e=>W(e,{output:"number",trimMantissa:!0,mantissa:2,absolute:!1});function Ij(e,t){const{scatter:n,tooltip:r}=e;return ne.getTooltip({trigger:r.trigger,formatter:function(i){const o=t[0]??t.default,l=Array.isArray(i)?i:[i];if(l.length===0)return"";const u=Tj(l,e),c=$e(e.scatter.label_overflow.tooltip),d=l.map(({value:j})=>`
263
+ `)(n)}catch(r){return console.error(r),console.log(e),e}}function dj(e,t,n,r){const i=lj(t,r),o=/^(.+)\}\}(.*)$/;return e.split("{{").map(l=>{const c=o.exec(l);if(!c)return l;const u=i[c[1]];if(u){const h=c[2]??"";return`${u}${h}`}const d=cj(c[1]);return`${uj(d,i,n)}${c[2]}`}).join("")}const pj=S.observer(({context:e})=>{const t=ce(),{value:n}=O(e.instanceData,"config"),{variables:r,data:i}=e,o=g.useMemo(()=>{const l=y.defaults({},n,Qn);return l.content?dj(l.content,r,t.payloadForViz,i):""},[n,r,t.payloadForViz]);return o?s.jsx(Nn,{value:o,styles:{root:{border:"none",height:"100%"},content:{padding:0}}}):null});function hj(){const{editor:e}=q.useRichTextEditorContext();return s.jsx(q.RichTextEditor.Control,{onClick:()=>e==null?void 0:e.commands.insertTable({rows:3,cols:3,withHeaderRow:!0}),"aria-label":"Insert table",title:"Insert table",children:s.jsx(_.IconBorderAll,{stroke:1.5,size:16})})}const ur=g.forwardRef(({value:e,onChange:t,styles:n={},label:r,onSubmit:i},o)=>{const[l,c]=g.useState(e),u=Gi.useEditor({extensions:[Wi,Fi,q.Link,Li,Pi,Ai,$i.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),Ni,qi,Vi,Bi.configure({types:["heading","paragraph"]}),Ei.configure({placeholder:"This is placeholder"}),Oi,zi.Color,po],content:l,onUpdate:({editor:x})=>{c(x.getHTML())}});g.useEffect(()=>{c(e),u==null||u.commands.setContent(e)},[e]);const d=()=>{t(l),i==null||i()},h=e!==l,p=g.useMemo(()=>y.defaultsDeep({},{content:Ns},n),[n]);return u?s.jsxs(a.Stack,{spacing:4,sx:{flexGrow:1,position:"relative"},children:[s.jsxs(a.Group,{align:"center",children:[s.jsx(a.Text,{size:14,fw:500,children:r}),s.jsx(a.ActionIcon,{color:"blue",disabled:!h,onClick:d,children:s.jsx(_.IconDeviceFloppy,{size:18})})]}),s.jsxs(q.RichTextEditor,{editor:u,styles:p,children:[s.jsxs(q.RichTextEditor.Toolbar,{sticky:!0,stickyOffset:0,children:[s.jsx(q.RichTextEditor.ControlsGroup,{children:s.jsx(q.RichTextEditor.ColorPicker,{colors:["#25262b","#868e96","#fa5252","#e64980","#be4bdb","#7950f2","#4c6ef5","#228be6","#15aabf","#12b886","#40c057","#82c91e","#fab005","#fd7e14"],popoverProps:{zIndex:320}})}),s.jsxs(q.RichTextEditor.ControlsGroup,{children:[s.jsx(q.RichTextEditor.Bold,{}),s.jsx(q.RichTextEditor.Italic,{}),s.jsx(q.RichTextEditor.Underline,{}),s.jsx(q.RichTextEditor.ClearFormatting,{}),s.jsx(q.RichTextEditor.Highlight,{}),s.jsx(q.RichTextEditor.Code,{})]}),s.jsxs(q.RichTextEditor.ControlsGroup,{children:[s.jsx(q.RichTextEditor.H1,{}),s.jsx(q.RichTextEditor.H2,{}),s.jsx(q.RichTextEditor.H3,{}),s.jsx(q.RichTextEditor.H4,{})]}),s.jsxs(q.RichTextEditor.ControlsGroup,{children:[s.jsx(q.RichTextEditor.Blockquote,{}),s.jsx(q.RichTextEditor.Hr,{}),s.jsx(q.RichTextEditor.BulletList,{}),s.jsx(q.RichTextEditor.OrderedList,{}),s.jsx(q.RichTextEditor.Subscript,{}),s.jsx(q.RichTextEditor.Superscript,{})]}),s.jsxs(q.RichTextEditor.ControlsGroup,{children:[s.jsx(q.RichTextEditor.Link,{}),s.jsx(q.RichTextEditor.Unlink,{})]}),s.jsxs(q.RichTextEditor.ControlsGroup,{children:[s.jsx(q.RichTextEditor.AlignLeft,{}),s.jsx(q.RichTextEditor.AlignCenter,{}),s.jsx(q.RichTextEditor.AlignJustify,{}),s.jsx(q.RichTextEditor.AlignRight,{})]}),s.jsx(q.RichTextEditor.ControlsGroup,{children:s.jsx(hj,{})}),s.jsx(gg,{editor:u})]}),s.jsx(q.RichTextEditor.Content,{})]})]}):null});function xj({context:e}){const{value:t,set:n}=O(e.instanceData,"config"),r=g.useMemo(()=>y.defaults({},t,Qn),[t]),{control:i,handleSubmit:o,watch:l,reset:c}=b.useForm({defaultValues:r});l("content"),g.useEffect(()=>{c(r)},[r]);const u=g.useRef(null),d=()=>{var h;return(h=u.current)==null?void 0:h.click()};return s.jsx("form",{onSubmit:o(n),style:{flexGrow:1,display:"flex",flexDirection:"column"},children:s.jsxs(a.Stack,{spacing:"xs",sx:{flexGrow:1},children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",display:"none"},children:[s.jsx(a.Text,{children:"Content"}),s.jsx(a.ActionIcon,{ref:u,type:"submit",mr:5,variant:"filled",color:"blue",children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsx(b.Controller,{name:"content",control:i,render:({field:h})=>s.jsx(ur,{...h,styles:{root:{flexGrow:1}},label:"Content",onSubmit:d})})]})})}class fj extends ae{constructor(){super(...arguments);P(this,"VERSION",1)}fixMalformedConfig(n){return y.defaults({},n,Qn)}configVersions(){this.version(1,n=>({version:1,config:this.fixMalformedConfig(n)}))}}const gj={displayName:"Rich Text",displayGroup:"Others",migrator:new fj,name:"richText",viewRender:pj,configRender:xj,createConfig(){return{version:1,config:y.cloneDeep(Qn)}}},an={static:{type:"static",color:tt.random().css()},dynamic:{type:"dynamic",func_content:["function getColor({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here",' // return "blue"',"}"].join(`
264
+ `)}},Ao={id:"builtin:echarts:click-scatter-chart:series",displayName:"Click Scatter",nameRender:yj,configRender:mj,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 mj(e){return s.jsx(s.Fragment,{})}function yj(e){return s.jsx(a.Text,{children:"Click scatter"})}function Eo(){return{enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
265
+ `)}}function Po(){const{on_axis:e,in_tooltip:t}=Te();return{label:e,tooltip:t}}const dr={scatter:{y_data_key:"",name_data_key:"",symbolSize:{type:"static",size:10},color:an.static,label_position:"right",label_overflow:Po()},stats:{templates:{top:"",bottom:""}},x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:Eo(),overflow:Te()}},y_axes:[{name:"Y Axis",position:"left",nameAlignment:"center",label_formatter:me,min:"",max:"",show:!0}],tooltip:{trigger:"item",metrics:[]},reference_lines:[],reference_areas:[],dataZoom:bt};function bj(e,t){if(!e.x_axis.data_key)return[];const n=z(e.x_axis.data_key);return[{source:t[n.queryID]}]}function jj(e){const t=e.y_axes.some(i=>!!i.name);let n=15;t&&(n+=20),e.dataZoom.x_axis_slider&&(n+=20);let r=5;return e.x_axis.name&&(r+=15),{top:n,bottom:r}}function vj(){return{show:!1,bottom:0,left:"center",type:"scroll"}}function Un(e,t){if(e)return t[e]??void 0}function wj({reference_areas:e,variableValueMap:t}){const n=e.map(r=>[{name:r.content.text,value:r.content.text,itemStyle:r.itemStyle,label:r.label,xAxis:Un(r.leftBottomPoint.x_data_key,t),yAxis:Un(r.leftBottomPoint.y_data_key,t)},{xAxis:Un(r.rightTopPoint.x_data_key,t),yAxis:Un(r.rightTopPoint.y_data_key,t)}]);return{type:"scatter",name:"ref_areas",silent:!0,data:[],markArea:{data:n}}}function Cj({type:e,...t},n){if(!e)return 10;if(e==="static"){const{size:i}=t;return i}const{func_content:r}=t;return(i,o)=>{const l=o.data;try{return new Function(`return ${r}`)()({rowData:l,params:o,variables:n},{lodash:y,interpolate:yt.interpolate})}catch(c){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${c.message}`),10}}}function Sj({type:e,...t},n){if(!e)return an.static.color;if(e==="static"){const{color:i}=t;return i}const{func_content:r}=t;return({value:i})=>{try{return new Function(`return ${r}`)()({rowData:i,variables:n},{lodash:y,interpolate:yt.interpolate})}catch(o){return console.error(`[getSeriesColor] failed parsing custom function, error: ${o.message}`),10}}}function _j(e,t,n,r){return e.map(i=>{const o=i.orientation==="horizontal",l=o?"yAxis":"xAxis",c=o?"insideEndTop":"end";return{name:i.name,type:"line",hide_in_legend:!i.show_in_legend,yAxisIndex:i.yAxisIndex,data:[],lineStyle:i.lineStyle,markLine:{data:[{name:i.name,[l]:Number(n[i.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:i.lineStyle,label:{formatter:function(){return i.template?bn(i.template,t,r):""},position:c}}}})}function kj({x_axis:e,scatter:t},n){const r=z(e.data_key),i=z(t.y_data_key),o=z(t.name_data_key);return{label:{show:!!t.label_position,position:t.label_position,...Be(t.label_overflow.label),formatter:({value:l})=>l[o.columnKey]},type:"scatter",name:"",xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{color:Sj(t.color,n)},symbolSize:Cj(t.symbolSize,n),encode:{x:r.columnKey,y:i.columnKey}}}function Tj(e,t,n,r){return[kj(e,r)].concat(_j(e.reference_lines,n,r,t)).concat(wj({reference_areas:e.reference_areas,variableValueMap:r}))}function Lo({enabled:e,func_content:t}){return(n,r)=>{if(!e)return n;try{return new Function(`return ${t}`)()(n,r)}catch(i){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${i.message}`),n}}}function Bo(e,t,n){const{x_axis:r}=n;return r.axisLabel.formatter.enabled?Lo(r.axisLabel.formatter)(e,t):e}function Dj(e,t){const{x_axis:n,tooltip:r}=t;if(r.trigger==="item"){const c=mn(e[0].data,n.data_key);return Bo(c,0,t)}const i=e.find(c=>c.axisDim==="x"&&c.axisId==="main-x-axis");if(!i)return"";const{axisValue:o,axisIndex:l}=i;return Bo(o,l,t)}const Ij=e=>G(e,{output:"number",trimMantissa:!0,mantissa:2,absolute:!1});function Mj(e,t){const{scatter:n,tooltip:r}=e;return ee.getTooltip({trigger:r.trigger,formatter:function(i){const o=t[0]??t.default,l=Array.isArray(i)?i:[i];if(l.length===0)return"";const c=Dj(l,e),u=Le(e.scatter.label_overflow.tooltip),d=l.map(({value:j})=>`
266
266
  <th style="text-align: right; padding-right: 1em">
267
- <div style="${c}">${yn(j,n.name_data_key)}</div>
267
+ <div style="${u}">${mn(j,n.name_data_key)}</div>
268
268
  </th>
269
- `);d.unshift("<th></th>");const h=$e(e.x_axis.axisLabel.overflow.in_tooltip),p=[`<tr>
269
+ `);d.unshift("<th></th>");const h=Le(e.x_axis.axisLabel.overflow.in_tooltip),p=[`<tr>
270
270
  <th style="text-align: right;">${e.x_axis.name}</th>
271
- ${l.map(j=>`<td style="text-align: right; padding: 0 1em;"><div style="${h}">${u}</div></td>`).join("")}
271
+ ${l.map(j=>`<td style="text-align: right; padding: 0 1em;"><div style="${h}">${c}</div></td>`).join("")}
272
272
  </tr>`,`<tr>
273
273
  <th style="text-align: right;">${e.y_axes[0].name}</th>
274
274
  ${l.map(({value:j})=>`
275
275
  <td style="text-align: right; padding: 0 1em;">
276
- ${o(yn(j,n.y_data_key))}
276
+ ${o(mn(j,n.y_data_key))}
277
277
  </td>`).join("")}
278
278
  </tr>`],x=e.tooltip.metrics.map(j=>`<tr>
279
279
  <th style="text-align: right;">${j.name}</th>
280
- ${l.map(({value:C})=>`<td style="text-align: right; padding: 0 1em;">${Dj(yn(C,j.data_key))}</td>`).join("")}
280
+ ${l.map(({value:C})=>`<td style="text-align: right; padding: 0 1em;">${Ij(mn(C,j.data_key))}</td>`).join("")}
281
281
  </tr>`);return p.push(...x),`
282
282
  <table style="width: auto">
283
283
  <thead><tr>${d.join("")}</tr></thead>
284
284
  <tbody>${p.join("")}</tbody>
285
285
  </table>
286
- `}})}function Mj(e,t){const n=t.every(u=>!Number.isNaN(Number(u))),{overflow:r,...i}=e.x_axis.axisLabel,o=Ve(r.on_axis),l=t.length===0;return[ne.getXAxis({data:t,name:e.x_axis.name??"",nameGap:l?5:void 0,id:"main-x-axis",type:n?"value":"category",axisLabel:{...i,...o,formatter:Lo(i.formatter)}})]}function zj(e,t){return e.y_axes.map(({nameAlignment:n,min:r,max:i,...o},l)=>{let u=o.position;return u||(u=l>0?"right":"left"),ne.getYAxis({...o,minInterval:1,min:r||void 0,max:i||void 0,position:u,axisLine:{show:!0},axisLabel:{show:!0,formatter:t[l]??t.default},nameTextStyle:{align:n},nameLocation:"end",nameGap:15,splitLine:{show:!1}})})}const Aj={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 Ej(e,t,n){const r=n.reduce((c,d)=>{const h=it(d,t);return c[d.name]=Pe(d,h),c},{}),i=e.y_axes.reduce((c,{label_formatter:d},h)=>(c[h]=function(x){let m=x;if(typeof x=="object"&&(Array.isArray(x.value)&&x.value.length===2?m=x.value[1]:m=x.value),!d)return m;try{return W(m,d)}catch(j){return console.error(j),m}},c),{default:({value:c})=>c}),o=y.uniq(Ze(t,e.x_axis.data_key)),l=kj(e,t,n,r),u={xAxis:Mj(e,o),yAxis:zj(e,i),series:l,dataset:yj(e,t),tooltip:Ij(e,i),grid:bj(e),legend:jj(),dataZoom:kn(e.dataZoom)};return y.defaultsDeep({},u,Aj)}J.use([B.DataZoomComponent,ie.BarChart,ie.LineChart,ie.ScatterChart,B.GridComponent,B.LegendComponent,B.TooltipComponent,_e.CanvasRenderer,B.MarkLineComponent,B.MarkAreaComponent]);function Bo(e){return e.trim().length>0}function Lj({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const l=vt(t,e.x_axis.data_key),u=qe(i.triggerManager,zo.id),c=g.useCallback(p=>{const x=p.data;u.forEach(m=>{i.runInteraction(m.id,{...p,rowData:x})})},[l,u,i]),d=g.useMemo(()=>({click:c}),[c]),h=g.useMemo(()=>Ej(e,t,o),[e,t]);return s.jsx(Se,{echarts:J,option:h,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function Pj({context:e,instance:t}){const n=Ne({vizManager:e.vizManager,instance:t}),{value:r}=$(e.instanceData,"config"),{variables:i}=e,o=g.useMemo(()=>y.defaults({},r,pr),[r]),l=e.data,{width:u,height:c}=e.viewport,{ref:d,height:h}=oe.useElementSize(),{ref:p,height:x}=oe.useElementSize(),m=g.useMemo(()=>{const{stats:{templates:C}}=o;return{top:Zt(C.top,i,l),bottom:Zt(C.bottom,i,l)}},[o,l]),j=Math.max(0,Ue(c)-h-x);return!u||!c?null:s.jsxs(Ie,{width:u,height:c,children:[s.jsx(a.Text,{ref:d,align:"left",size:"xs",pl:"sm",sx:{display:Bo(o.stats.templates.top)?"block":"none"},children:Object.values(m.top).map(C=>C)}),s.jsx(Lj,{variables:i,width:Qe(u),height:j,data:l,conf:o,interactionManager:n}),s.jsx(a.Text,{ref:p,align:"left",size:"xs",pl:"sm",sx:{display:Bo(o.stats.templates.bottom)?"block":"none"},children:Object.values(m.bottom).map(C=>C)})]})}const Bj=g.forwardRef(({value:e,onChange:t,xAxisOptions:n,yAxisOptions:r,variableOptions:i},o)=>{const l=(u,c)=>{const d=y.cloneDeep(e);y.set(d,u,c),t(d)};return s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Content",labelPosition:"right"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(a.TextInput,{label:"Content Text",value:e.content.text,onChange:u=>l("content.text",u.currentTarget.value)}),s.jsx(ar,{label:"Text Position",value:e.label.position,onChange:u=>l("label.position",u)})]}),s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Endpoints",labelPosition:"right"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[n&&s.jsx(a.Select,{label:"X Axis",data:n,value:e.xAxisIndex,onChange:u=>l("xAxisIndex",u)}),r&&s.jsx(a.Select,{label:"Y Axis",data:r,value:e.yAxisIndex,onChange:u=>l("xAxisIndex",u)})]}),s.jsxs(a.Stack,{spacing:0,children:[s.jsx(a.Text,{size:14,color:"#212529",fw:500,children:"Left-Bottom Point"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(a.Select,{icon:s.jsx(a.Text,{children:"x"}),data:i,value:e.leftBottomPoint.x_data_key,onChange:u=>l("leftBottomPoint.x_data_key",u??""),clearable:!0}),s.jsx(a.Select,{icon:s.jsx(a.Text,{children:"y"}),data:i,value:e.leftBottomPoint.y_data_key,onChange:u=>l("leftBottomPoint.y_data_key",u??""),clearable:!0})]})]}),s.jsxs(a.Stack,{spacing:0,children:[s.jsx(a.Text,{size:14,color:"#212529",fw:500,children:"Right-Top Point"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(a.Select,{icon:s.jsx(a.Text,{children:"x"}),data:i,value:e.rightTopPoint.x_data_key,onChange:u=>l("rightTopPoint.x_data_key",u??""),clearable:!0}),s.jsx(a.Select,{icon:s.jsx(a.Text,{children:"y"}),data:i,value:e.rightTopPoint.y_data_key,onChange:u=>l("rightTopPoint.y_data_key",u??""),clearable:!0})]})]}),s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Style",labelPosition:"right"}),s.jsxs(a.Stack,{spacing:4,children:[s.jsx(a.Text,{size:14,children:"Background Color"}),s.jsx(ke,{value:e.itemStyle.color,onChange:u=>l("itemStyle.color",u)})]}),s.jsxs(a.Stack,{spacing:4,children:[s.jsx(a.Text,{size:14,children:"Text Color"}),s.jsx(ke,{value:e.label.color,onChange:u=>l("label.color",u)})]})]})});function Oj(){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 $j({control:e,watch:t,variables:n}){const{fields:r,append:i,remove:o}=b.useFieldArray({control:e,name:"reference_areas"}),l=t("reference_areas"),u=r.map((x,m)=>({...x,...l[m]})),c=()=>{const x=Oj();i(x)},d=g.useMemo(()=>n.map(x=>({label:x.name,value:x.name})),[n]),h=t("y_axes"),p=g.useMemo(()=>h.map(({name:x},m)=>({label:x,value:m.toString()})),[h]);return s.jsxs(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[s.jsxs(a.Tabs.List,{children:[u.map((x,m)=>s.jsx(a.Tabs.Tab,{value:m.toString(),children:m+1},x.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),u.map((x,m)=>s.jsx(a.Tabs.Panel,{value:m.toString(),children:s.jsx(b.Controller,{name:`reference_areas.${m}`,control:e,render:({field:j})=>s.jsxs(a.Stack,{children:[s.jsx(Bj,{variableOptions:d,yAxisOptions:p,...j}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed"}),s.jsx(a.Button,{leftIcon:s.jsx(_.IconTrash,{size:16}),color:"red",variant:"light",onClick:()=>o(m),children:"Delete this Reference Area"})]})})},x.id))]})}const Vj=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],qj=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Nj({control:e,index:t,remove:n,watch:r,variableOptions:i,yAxisOptions:o}){const l=r(`reference_lines.${t}.orientation`);return s.jsxs(a.Stack,{my:0,p:0,sx:{position:"relative"},children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:u})=>s.jsx(a.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),s.jsx(b.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:u})=>s.jsx(a.Select,{label:"Value",required:!0,data:i,sx:{flex:1},...u})})]}),s.jsx(b.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:u})=>s.jsx(a.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...u})}),s.jsxs(a.Group,{grow:!0,children:[s.jsxs(a.Stack,{children:[s.jsx(b.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:u})=>s.jsx(a.Select,{label:"Orientation",data:qj,required:!0,sx:{flex:1},...u})}),l==="vertical"&&s.jsx(a.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&s.jsx(b.Controller,{name:`reference_lines.${t}.yAxisIndex`,control:e,render:({field:{value:u,onChange:c,...d}})=>s.jsx(a.Select,{label:"Y Axis",data:o,disabled:o.length===0,...d,value:(u==null?void 0:u.toString())??"",onChange:h=>{if(!h){c(0);return}c(Number(h))},sx:{flex:1}})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:u})=>s.jsx(a.Select,{label:"Line Type",data:Vj,sx:{flexGrow:1},...u})}),s.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:u})=>s.jsx(a.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...u})})]}),s.jsxs(a.Stack,{spacing:4,children:[s.jsx(a.Text,{size:"sm",children:"Color"}),s.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:u})=>s.jsx(ke,{...u})})]}),s.jsx(a.Button,{leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]})}function Fj({control:e,watch:t,variables:n}){const{fields:r,append:i,remove:o}=b.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=r.map((x,m)=>({...x,...l[m]})),c=()=>{const x={name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:st.random().css()},show_in_legend:!1,yAxisIndex:0};i(x)},d=g.useMemo(()=>n.map(x=>({label:x.name,value:x.name})),[n]),h=t("y_axes"),p=g.useMemo(()=>h.map(({name:x},m)=>({label:x,value:m.toString()})),[h]);return s.jsxs(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[s.jsxs(a.Tabs.List,{children:[u.map((x,m)=>s.jsx(a.Tabs.Tab,{value:m.toString(),children:m+1},x.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),u.map((x,m)=>s.jsx(a.Tabs.Panel,{value:m.toString(),children:s.jsx(Nj,{control:e,index:m,remove:o,watch:t,variableOptions:d,yAxisOptions:p})},x.id))]})}const Gj=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return s.jsx(a.Box,{children:s.jsx(ye,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Wj=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:i}]=V.useBoolean(),[o,l]=g.useState(e),u=()=>{i();const{type:p,func_content:x}=o,m={type:p,func_content:x};l(m),t(m)},c=()=>{i(),l(e)},d=p=>{l(x=>({...x,func_content:p}))},h=()=>{d(on.dynamic.func_content)};return s.jsxs(s.Fragment,{children:[s.jsx(a.Box,{sx:{width:"50%"},children:s.jsx(a.Button,{variant:"filled",mt:24,onClick:r,sx:{flexGrow:0},children:"Setup"})}),s.jsx(a.Modal,{size:800,title:"Setup dynamic color",opened:n,onClose:i,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),s.jsx(Gj,{value:o.func_content,onChange:d}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:h,color:"red",leftIcon:s.jsx(k.Recycle,{size:20}),children:"Reset"}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:c,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:u,children:"OK"})]})]})]})})]})},Rj=({value:e,onChange:t})=>e.type!=="dynamic"?null:s.jsx(Wj,{value:e,onChange:t}),Qj=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=r=>{t({...e,color:r})};return s.jsx(a.ColorInput,{label:" ",format:"rgb",value:e.color,onChange:n})},Uj=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Kj=g.forwardRef(({label:e="Color",value:t,onChange:n},r)=>{const i=o=>{n({...on[o]})};return s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(a.Select,{ref:r,label:e,data:Uj,value:t.type,onChange:i,sx:{flexGrow:1}}),s.jsx(Qj,{value:t,onChange:n}),s.jsx(Rj,{value:t,onChange:n})]})}),Yj=g.forwardRef(({value:e,onChange:t},n)=>{const r=o=>{t({...e,label:o})},i=o=>{t({...e,tooltip:o})};return s.jsxs(a.Stack,{ref:n,spacing:0,children:[s.jsx(Sn,{sectionTitle:"Overflow on Chart",value:e.label,onChange:r}),s.jsx(Sn,{sectionTitle:"Overflow in Tooltip",value:e.tooltip,onChange:i})]})}),Xj=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return s.jsx(a.Box,{children:s.jsx(ye,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Oo={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
287
- `)}},Jj=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:i}]=V.useBoolean(),[o,l]=g.useState(e),u=()=>{i();const{type:p,func_content:x}=o,m={type:p,func_content:x};l(m),t(m)},c=()=>{i(),l(e)},d=p=>{l(x=>({...x,func_content:p}))},h=()=>{d(Oo.dynamic.func_content)};return s.jsxs(s.Fragment,{children:[s.jsx(a.Box,{sx:{width:"50%"},children:s.jsx(a.Button,{variant:"filled",mt:24,onClick:r,sx:{flexGrow:0},children:"Setup"})}),s.jsx(a.Modal,{size:800,title:"Setup dynamic size",opened:n,onClose:i,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),s.jsx(Xj,{value:o.func_content,onChange:d}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:h,color:"red",leftIcon:s.jsx(k.Recycle,{size:20}),children:"Reset"}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:c,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:u,children:"OK"})]})]})]})})]})},Zj=({value:e,onChange:t})=>e.type!=="dynamic"?null:s.jsx(Jj,{value:e,onChange:t}),Hj=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=r=>{t({...e,size:r})};return s.jsx(s.Fragment,{children:s.jsx(a.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:e.size,onChange:n})})},ev=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],tv=g.forwardRef(({label:e="Size",value:t,onChange:n},r)=>{const i=o=>{n({...Oo[o]})};return s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(a.Select,{ref:r,label:e,data:ev,value:t.type,onChange:i,sx:{flexGrow:1}}),s.jsx(Hj,{value:t,onChange:n}),s.jsx(Zj,{value:t,onChange:n})]})}),nv=[{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 sv({control:e,watch:t}){return t(["scatter"]),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"scatter.name_data_key",control:e,render:({field:n})=>s.jsx(O,{label:"Name Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"scatter.y_data_key",control:e,render:({field:n})=>s.jsx(O,{label:"Value Data Field",required:!0,sx:{flex:1},...n})})]}),s.jsx(a.Divider,{mb:-15,label:"Style",labelPosition:"center"}),s.jsx(b.Controller,{name:"scatter.symbolSize",control:e,render:({field:n})=>s.jsx(tv,{label:"Size",...n})}),s.jsx(b.Controller,{name:"scatter.color",control:e,render:({field:n})=>s.jsx(Kj,{...n})}),s.jsx(a.Divider,{mb:-15,label:"Label",labelPosition:"center"}),s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:"scatter.label_position",control:e,render:({field:n})=>s.jsx(a.Select,{label:"Label Position",data:nv,...n})})}),s.jsx(b.Controller,{name:"scatter.label_overflow",control:e,render:({field:n})=>s.jsx(Yj,{...n})})]})}function rv({control:e,watch:t}){return t("stats"),s.jsx(a.Stack,{children:s.jsxs(a.Stack,{spacing:0,children:[s.jsx(b.Controller,{name:"stats.templates.top",control:e,render:({field:n})=>s.jsx(Xt,{label:"Template for stats above the chart",py:"md",sx:{flexGrow:1},...n})}),s.jsx(b.Controller,{name:"stats.templates.bottom",control:e,render:({field:n})=>s.jsx(Xt,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const iv=({control:e,index:t,remove:n})=>s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>s.jsx(O,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed"}),s.jsx(a.Button,{leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),av=({control:e,watch:t})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((p,x)=>({...p,...o[x]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[d,h]=g.useState(()=>c??null);return g.useEffect(()=>{c&&h(p=>p!==null?p:c)},[c]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(k.InfoCircle,{size:14,color:"#888"}),s.jsx(a.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),s.jsxs(a.Tabs,{value:d,onTabChange:p=>h(p),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((p,x)=>s.jsx(a.Tabs.Tab,{value:p.id,children:p.name?p.name:x},p.id)),s.jsx(a.Tabs.Tab,{onClick:u,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),l.map((p,x)=>s.jsx(a.Tabs.Panel,{value:p.id,children:s.jsx(iv,{control:e,index:x,remove:i},p.id)},p.id))]})]})},ov=[{label:"Scatter Point",value:"item"},{label:"X Axis",value:"axis"}];function lv({control:e,watch:t}){return t("tooltip.trigger"),s.jsxs(a.Stack,{children:[s.jsx(b.Controller,{name:"tooltip.trigger",control:e,render:({field:n})=>s.jsx(a.Select,{label:"Trigger",data:ov,sx:{flexGrow:1},...n})}),s.jsx(a.Divider,{variant:"dashed"}),s.jsx(av,{control:e,watch:t})]})}const uv=({disabled:e,value:t,onChange:n})=>{const r=i=>{i&&n(i)};return s.jsxs(a.Box,{sx:{position:"relative"},children:[e&&s.jsx(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),s.jsx(ye,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},cv=g.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:i,setFalse:o}]=V.useBoolean(),[l,u]=g.useState(e);g.useEffect(()=>{u(e)},[e]);const c=m=>{u({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:j}=l,C={enabled:m,func_content:j};u(C),t(C)},h=()=>{o(),u(e)},p=m=>{u(j=>({...j,func_content:m}))},x=()=>{p(Ao().func_content)};return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"filled",mt:24,onClick:i,sx:{flexGrow:0},children:"Customize Label"}),s.jsx(a.Modal,{size:800,title:"Customize label content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&s.jsxs(a.Stack,{children:[s.jsx(a.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:m=>c(m.currentTarget.checked)}),s.jsx(uv,{value:l.func_content,onChange:p,disabled:!l.enabled}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:x,color:"red",leftIcon:s.jsx(k.Recycle,{size:20}),children:"Reset"}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:h,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:d,children:"OK"})]})]})]})})]})});function dv({control:e,watch:t}){return t(["x_axis"]),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>s.jsx(O,{label:"Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"x_axis.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"Name",sx:{flex:1},...n})})]}),s.jsx(a.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>s.jsx(a.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:s.jsx(a.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),s.jsx(b.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>s.jsx(cv,{...n})})]}),s.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>s.jsx(Ke,{...n})})]})}const pv=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],hv=[{label:"left",value:"left"},{label:"right",value:"right"}];function xv({control:e,index:t,remove:n}){return s.jsxs(a.Stack,{my:0,p:"0",sx:{position:"relative"},children:[s.jsx(a.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`y_axes.${t}.name`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`y_axes.${t}.nameAlignment`,control:e,render:({field:r})=>s.jsx(a.Select,{label:"Align",required:!0,data:pv,sx:{flex:1},...r})})]}),s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:`y_axes.${t}.position`,control:e,render:({field:r})=>s.jsx(a.Select,{label:"Position",required:!0,data:hv,sx:{flex:1},...r})})}),s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),s.jsx(b.Controller,{name:`y_axes.${t}.label_formatter`,control:e,render:({field:r})=>s.jsx(Fe,{...r})})]}),s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:`y_axes.${t}.min`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Min",...r})}),s.jsx(b.Controller,{name:`y_axes.${t}.max`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Max",...r})})]})]}),s.jsx(a.Button,{mt:20,leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this YAxis"})]})}function fv({control:e,watch:t}){const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"y_axes"}),o=t("y_axes"),l=n.map((c,d)=>({...c,...o[d]})),u=()=>r({name:"",label_formatter:je,min:"",max:"",show:!0,position:"right",nameAlignment:"right"});return s.jsxs(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((c,d)=>s.jsx(a.Tabs.Tab,{value:d.toString(),children:d+1},c.id)),s.jsx(a.Tabs.Tab,{onClick:u,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),l.map((c,d)=>s.jsx(a.Tabs.Panel,{value:d.toString(),children:s.jsx(xv,{control:e,index:d,remove:i})},c.id))]})}function gv(e){return e||{templates:{top:"",bottom:""}}}function mv({reference_lines:e=[],stats:t,...n}){return{reference_lines:e,stats:gv(t),...n}}function yv({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),{variables:r}=e,i=g.useMemo(()=>y.defaultsDeep({},t,pr),[t]),o=g.useMemo(()=>mv(i),[i]);g.useEffect(()=>{!y.isEqual(i,o)&&(console.log("config malformed, resetting to defaults",i,o),n(o))},[i,o]);const{control:l,handleSubmit:u,watch:c,getValues:d,reset:h}=b.useForm({defaultValues:o});g.useEffect(()=>{h(o)},[o]);const p=d(),x=g.useMemo(()=>!y.isEqual(p,i),[p,i]);return c(["dataZoom"]),s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:u(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Chart Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!x,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"X Axis",children:"X Axis"}),s.jsx(a.Tabs.Tab,{value:"Y Axes",children:"Y Axes"}),s.jsx(a.Tabs.Tab,{value:"Scatter",children:"Scatter"}),s.jsx(a.Tabs.Tab,{value:"Tooltip",children:"Tooltip"}),s.jsx(a.Tabs.Tab,{value:"Stats",children:"Stats"}),s.jsx(a.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"}),s.jsx(a.Tabs.Tab,{value:"Reference Areas",children:"Reference Areas"}),s.jsx(a.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),s.jsx(a.Tabs.Panel,{value:"X Axis",children:s.jsx(dv,{control:l,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Y Axes",children:s.jsx(fv,{control:l,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Scatter",children:s.jsx(sv,{control:l,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(lv,{control:l,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Stats",children:s.jsx(rv,{control:l,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Reference Lines",children:s.jsx(Fj,{variables:r,control:l,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Reference Areas",children:s.jsx($j,{variables:r,control:l,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Zooming",children:s.jsx(b.Controller,{name:"dataZoom",control:l,render:({field:m})=>s.jsx(Dn,{...m})})})]})]})})}function bv(e){const{dataZoom:t=jt,...n}=e;return{...n,dataZoom:t}}function jv(e){const t={scatter:{label_overflow:Eo()}};return y.defaultsDeep(t,e)}function vv(e){const{color:t}=e.scatter;return typeof t=="string"?{...e,scatter:{...e.scatter,color:{...on.static,color:t}}}:e}function wv(e){const t=e.reference_lines.map(n=>{const{lineStyle:r={type:"dashed",width:1,color:st.random().css()},show_in_legend:i=!1,yAxisIndex:o=0}=n;return{...n,lineStyle:r,show_in_legend:i,yAxisIndex:o}});return{...e,reference_lines:t}}function Cv(e){const t={tooltip:{trigger:"item"}};return y.defaultsDeep({},e,t)}function Sv(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:i,scatter:o,tooltip:l,...u}=e;return{...u,x_axis:{...i,data_key:r(i.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}}function _v(e){const t={x_axis:{axisLabel:{overflow:Me()}}};return y.defaultsDeep(t,e)}class kv extends ue{constructor(){super(...arguments);L(this,"VERSION",10)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{tooltip:r={metrics:[]},...i}=n.config;return{...n,version:2,config:{...i,tooltip:r}}}),this.version(3,n=>({...n,version:3,config:bv(n.config)})),this.version(4,n=>{const{config:r}=n;return{...n,version:5,config:jv(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:vv(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:wv(r)}}),this.version(8,n=>{const{config:r}=n;return{...n,version:8,config:Cv(r)}}),this.version(9,(n,r)=>{const{config:i}=n;return{...n,version:9,config:Sv(i,r)}}),this.version(10,(n,r)=>{const{config:i}=n;return{...n,version:10,config:_v(i)}})}}const Tv={displayName:"Scatter Chart",displayGroup:"ECharts-based charts",migrator:new kv,name:"scatterChart",viewRender:Pj,configRender:yv,createConfig(){return{version:10,config:y.cloneDeep(pr)}},triggers:[zo]},hr={template:"The variable ${value} is defined in Variables section",vertical_align:"center",horizontal_align:"left"};function Dv(e){if("variables"in e)return e;const{align:t,size:n,weight:r,color:i,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:i,weight:r,size:n}]}}function Iv(e){return y.omit(e,["variables"])}function Mv(e){const{align:t,...n}=e;return{horizontal_align:t,vertical_align:"center",...n}}function zv(e){const t=y.cloneDeep(e),n=y.get(t,"color.valueRange");return n!==void 0&&y.set(t,"color.valueRange",n.map(r=>Number(r))),t}class Av extends ue{constructor(){super(...arguments);L(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:Dv(n)})),this.version(2,(n,{panelModel:r})=>{const{config:i}=n;return(i.variables||[]).forEach(l=>{r.variables.find(u=>u.name===l.name)||r.addVariable(zv(l))}),{...n,version:2,config:Iv(i)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:Mv(r)}})}}const Ev={left:"flex-start",center:"center",right:"flex-end"},Lv={top:"flex-start",center:"center",bottom:"flex-end"},Pv=S.observer(({context:e})=>{const t=pe(),{value:n=hr}=$(e.instanceData,"config"),{variables:r}=e,{template:i,horizontal_align:o,vertical_align:l}=n,{width:u,height:c}=e.viewport,d=g.useMemo(()=>{try{return y.template(i)(t.payloadForSQL)}catch{return i}},[t.payloadForSQL,i]),h=g.useMemo(()=>Zt(d,r,e.data),[d,r,e.data,e]);return s.jsx(a.Center,{sx:{width:u,height:c,justifyContent:Ev[o],alignItems:Lv[l]},children:s.jsx(a.Box,{children:Object.values(h).map((p,x)=>s.jsx(g.Fragment,{children:p},x))})})}),Bv=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Ov=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function $v({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=g.useMemo(()=>y.defaultsDeep({},t,hr),[t]),{control:i,handleSubmit:o,watch:l,getValues:u,reset:c}=b.useForm({defaultValues:r});g.useEffect(()=>{c(r)},[r]),l(["template","horizontal_align","vertical_align"]);const d=u(),h=g.useMemo(()=>!y.isEqual(d,t),[d,t]);return s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:o(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{weight:500,children:"Stats Configurations"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsx(b.Controller,{name:"template",control:i,render:({field:p})=>s.jsx(Xt,{label:"Template",py:"md",sx:{flexGrow:1},...p})}),s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(b.Controller,{name:"horizontal_align",control:i,render:({field:p})=>s.jsx(a.Select,{label:"Horizontal Alignment",data:Bv,...p})}),s.jsx(b.Controller,{control:i,name:"vertical_align",render:({field:p})=>s.jsx(a.Select,{label:"Vertical Alignment",data:Ov,...p})})]})]})})}const Vv={createConfig(){return{version:3,config:hr}},displayName:"Stats",displayGroup:"Others",migrator:new Av,name:"stats",viewRender:Pv,configRender:$v},xr={label_key:"",value_key:"",group_key:"",levels:[]};function qv(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 Nv(e){const t=qv(e).map(i=>({...i,children:[]})),n=y.keyBy(t,i=>i.id),r=[];return t.forEach(i=>{if(!i.parent_id||!n[i.parent_id]){r.push(i);return}n[i.parent_id].children.push(i)}),r}function Fv(e,t){const{label_key:n,value_key:r,group_key:i}=e;if(!n||!r)return[];const o=z(n),l=z(r),u=z(i),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 i?Nv(c):c}const Gv=e=>({treePathInfo:t,name:n,value:r})=>{if(t.length===1||!e)return n;try{const i=t[t.length-2].value;if(r/i<e)return" "}catch{return n}};function Wv(e){const{levels:t}=e;return t.map(n=>{const{show_label_tolerance:r,...i}=n.label;return{...n,label:{...i,formatter:Gv(r)}}})}function Rv(){return({treePathInfo:e,name:t,value:n,color:r,marker:i,...o})=>{const l=e.slice(0,e.length-1),u=[`<tr>
286
+ `}})}function zj(e,t){const n=t.every(c=>!Number.isNaN(Number(c))),{overflow:r,...i}=e.x_axis.axisLabel,o=Be(r.on_axis),l=t.length===0;return[ee.getXAxis({data:t,name:e.x_axis.name??"",nameGap:l?5:void 0,id:"main-x-axis",type:n?"value":"category",axisLabel:{...i,...o,formatter:Lo(i.formatter)}})]}function Aj(e,t){return e.y_axes.map(({nameAlignment:n,min:r,max:i,...o},l)=>{let c=o.position;return c||(c=l>0?"right":"left"),ee.getYAxis({...o,minInterval:1,min:r||void 0,max:i||void 0,position:c,axisLine:{show:!0},axisLabel:{show:!0,formatter:t[l]??t.default},nameTextStyle:{align:n},nameLocation:"end",nameGap:15,splitLine:{show:!1}})})}const Ej={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 Pj(e,t,n){const r=n.reduce((u,d)=>{const h=st(d,t);return u[d.name]=Ae(d,h),u},{}),i=e.y_axes.reduce((u,{label_formatter:d},h)=>(u[h]=function(x){let m=x;if(typeof x=="object"&&(Array.isArray(x.value)&&x.value.length===2?m=x.value[1]:m=x.value),!d)return m;try{return G(m,d)}catch(j){return console.error(j),m}},u),{default:({value:u})=>u}),o=y.uniq(Ye(t,e.x_axis.data_key)),l=Tj(e,t,n,r),c={xAxis:zj(e,o),yAxis:Aj(e,i),series:l,dataset:bj(e,t),tooltip:Mj(e,i),grid:jj(e),legend:vj(),dataZoom:_n(e.dataZoom)};return y.defaultsDeep({},c,Ej)}function Oo(e){return e.trim().length>0}function Lj({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const l=jt(t,e.x_axis.data_key),c=Oe(i.triggerManager,Ao.id),u=g.useCallback(p=>{const x=p.data;c.forEach(m=>{i.runInteraction(m.id,{...p,rowData:x})})},[l,c,i]),d=g.useMemo(()=>({click:u}),[u]),h=g.useMemo(()=>Pj(e,t,o),[e,t]);return s.jsx(we,{echarts:be,option:h,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function Bj({context:e,instance:t}){const n=$e({vizManager:e.vizManager,instance:t}),{value:r}=O(e.instanceData,"config"),{variables:i}=e,o=g.useMemo(()=>y.defaults({},r,dr),[r]),l=e.data,{width:c,height:u}=e.viewport,{ref:d,height:h}=re.useElementSize(),{ref:p,height:x}=re.useElementSize(),m=g.useMemo(()=>{const{stats:{templates:C}}=o;return{top:Jt(C.top,i,l),bottom:Jt(C.bottom,i,l)}},[o,l]),j=Math.max(0,We(u)-h-x);return!c||!u?null:s.jsxs(ke,{width:c,height:u,children:[s.jsx(a.Text,{ref:d,align:"left",size:"xs",pl:"sm",sx:{display:Oo(o.stats.templates.top)?"block":"none"},children:Object.values(m.top).map(C=>C)}),s.jsx(Lj,{variables:i,width:Ge(c),height:j,data:l,conf:o,interactionManager:n}),s.jsx(a.Text,{ref:p,align:"left",size:"xs",pl:"sm",sx:{display:Oo(o.stats.templates.bottom)?"block":"none"},children:Object.values(m.bottom).map(C=>C)})]})}const Oj=g.forwardRef(({value:e,onChange:t,xAxisOptions:n,yAxisOptions:r,variableOptions:i},o)=>{const l=(c,u)=>{const d=y.cloneDeep(e);y.set(d,c,u),t(d)};return s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Content",labelPosition:"right"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(a.TextInput,{label:"Content Text",value:e.content.text,onChange:c=>l("content.text",c.currentTarget.value)}),s.jsx(ir,{label:"Text Position",value:e.label.position,onChange:c=>l("label.position",c)})]}),s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Endpoints",labelPosition:"right"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[n&&s.jsx(a.Select,{label:"X Axis",data:n,value:e.xAxisIndex,onChange:c=>l("xAxisIndex",c)}),r&&s.jsx(a.Select,{label:"Y Axis",data:r,value:e.yAxisIndex,onChange:c=>l("xAxisIndex",c)})]}),s.jsxs(a.Stack,{spacing:0,children:[s.jsx(a.Text,{size:14,color:"#212529",fw:500,children:"Left-Bottom Point"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(a.Select,{icon:s.jsx(a.Text,{children:"x"}),data:i,value:e.leftBottomPoint.x_data_key,onChange:c=>l("leftBottomPoint.x_data_key",c??""),clearable:!0}),s.jsx(a.Select,{icon:s.jsx(a.Text,{children:"y"}),data:i,value:e.leftBottomPoint.y_data_key,onChange:c=>l("leftBottomPoint.y_data_key",c??""),clearable:!0})]})]}),s.jsxs(a.Stack,{spacing:0,children:[s.jsx(a.Text,{size:14,color:"#212529",fw:500,children:"Right-Top Point"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(a.Select,{icon:s.jsx(a.Text,{children:"x"}),data:i,value:e.rightTopPoint.x_data_key,onChange:c=>l("rightTopPoint.x_data_key",c??""),clearable:!0}),s.jsx(a.Select,{icon:s.jsx(a.Text,{children:"y"}),data:i,value:e.rightTopPoint.y_data_key,onChange:c=>l("rightTopPoint.y_data_key",c??""),clearable:!0})]})]}),s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Style",labelPosition:"right"}),s.jsxs(a.Stack,{spacing:4,children:[s.jsx(a.Text,{size:14,children:"Background Color"}),s.jsx(Ce,{value:e.itemStyle.color,onChange:c=>l("itemStyle.color",c)})]}),s.jsxs(a.Stack,{spacing:4,children:[s.jsx(a.Text,{size:14,children:"Text Color"}),s.jsx(Ce,{value:e.label.color,onChange:c=>l("label.color",c)})]})]})});function $j(){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 Vj({control:e,watch:t,variables:n}){const{fields:r,append:i,remove:o}=b.useFieldArray({control:e,name:"reference_areas"}),l=t("reference_areas"),c=r.map((x,m)=>({...x,...l[m]})),u=()=>{const x=$j();i(x)},d=g.useMemo(()=>n.map(x=>({label:x.name,value:x.name})),[n]),h=t("y_axes"),p=g.useMemo(()=>h.map(({name:x},m)=>({label:x,value:m.toString()})),[h]);return s.jsxs(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[s.jsxs(a.Tabs.List,{children:[c.map((x,m)=>s.jsx(a.Tabs.Tab,{value:m.toString(),children:m+1},x.id)),s.jsx(a.Tabs.Tab,{onClick:u,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),c.map((x,m)=>s.jsx(a.Tabs.Panel,{value:m.toString(),children:s.jsx(b.Controller,{name:`reference_areas.${m}`,control:e,render:({field:j})=>s.jsxs(a.Stack,{children:[s.jsx(Oj,{variableOptions:d,yAxisOptions:p,...j}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed"}),s.jsx(a.Button,{leftIcon:s.jsx(_.IconTrash,{size:16}),color:"red",variant:"light",onClick:()=>o(m),children:"Delete this Reference Area"})]})})},x.id))]})}const qj=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Nj=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Fj({control:e,index:t,remove:n,watch:r,variableOptions:i,yAxisOptions:o}){const l=r(`reference_lines.${t}.orientation`);return s.jsxs(a.Stack,{my:0,p:0,sx:{position:"relative"},children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:c})=>s.jsx(a.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...c})}),s.jsx(b.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:c})=>s.jsx(a.Select,{label:"Value",required:!0,data:i,sx:{flex:1},...c})})]}),s.jsx(b.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:c})=>s.jsx(a.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...c})}),s.jsxs(a.Group,{grow:!0,children:[s.jsxs(a.Stack,{children:[s.jsx(b.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:c})=>s.jsx(a.Select,{label:"Orientation",data:Nj,required:!0,sx:{flex:1},...c})}),l==="vertical"&&s.jsx(a.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&s.jsx(b.Controller,{name:`reference_lines.${t}.yAxisIndex`,control:e,render:({field:{value:c,onChange:u,...d}})=>s.jsx(a.Select,{label:"Y Axis",data:o,disabled:o.length===0,...d,value:(c==null?void 0:c.toString())??"",onChange:h=>{if(!h){u(0);return}u(Number(h))},sx:{flex:1}})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:c})=>s.jsx(a.Select,{label:"Line Type",data:qj,sx:{flexGrow:1},...c})}),s.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:c})=>s.jsx(a.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...c})})]}),s.jsxs(a.Stack,{spacing:4,children:[s.jsx(a.Text,{size:"sm",children:"Color"}),s.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:c})=>s.jsx(Ce,{...c})})]}),s.jsx(a.Button,{leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]})}function Gj({control:e,watch:t,variables:n}){const{fields:r,append:i,remove:o}=b.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),c=r.map((x,m)=>({...x,...l[m]})),u=()=>{const x={name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:tt.random().css()},show_in_legend:!1,yAxisIndex:0};i(x)},d=g.useMemo(()=>n.map(x=>({label:x.name,value:x.name})),[n]),h=t("y_axes"),p=g.useMemo(()=>h.map(({name:x},m)=>({label:x,value:m.toString()})),[h]);return s.jsxs(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[s.jsxs(a.Tabs.List,{children:[c.map((x,m)=>s.jsx(a.Tabs.Tab,{value:m.toString(),children:m+1},x.id)),s.jsx(a.Tabs.Tab,{onClick:u,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),c.map((x,m)=>s.jsx(a.Tabs.Panel,{value:m.toString(),children:s.jsx(Fj,{control:e,index:m,remove:o,watch:t,variableOptions:d,yAxisOptions:p})},x.id))]})}const Wj=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return s.jsx(a.Box,{children:s.jsx(fe,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Rj=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:i}]=$.useBoolean(),[o,l]=g.useState(e),c=()=>{i();const{type:p,func_content:x}=o,m={type:p,func_content:x};l(m),t(m)},u=()=>{i(),l(e)},d=p=>{l(x=>({...x,func_content:p}))},h=()=>{d(an.dynamic.func_content)};return s.jsxs(s.Fragment,{children:[s.jsx(a.Box,{sx:{width:"50%"},children:s.jsx(a.Button,{variant:"filled",mt:24,onClick:r,sx:{flexGrow:0},children:"Setup"})}),s.jsx(a.Modal,{size:800,title:"Setup dynamic color",opened:n,onClose:i,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),s.jsx(Wj,{value:o.func_content,onChange:d}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:h,color:"red",leftIcon:s.jsx(k.Recycle,{size:20}),children:"Reset"}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:u,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:c,children:"OK"})]})]})]})})]})},Qj=({value:e,onChange:t})=>e.type!=="dynamic"?null:s.jsx(Rj,{value:e,onChange:t}),Uj=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=r=>{t({...e,color:r})};return s.jsx(a.ColorInput,{label:" ",format:"rgb",value:e.color,onChange:n})},Kj=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Yj=g.forwardRef(({label:e="Color",value:t,onChange:n},r)=>{const i=o=>{n({...an[o]})};return s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(a.Select,{ref:r,label:e,data:Kj,value:t.type,onChange:i,sx:{flexGrow:1}}),s.jsx(Uj,{value:t,onChange:n}),s.jsx(Qj,{value:t,onChange:n})]})}),Xj=g.forwardRef(({value:e,onChange:t},n)=>{const r=o=>{t({...e,label:o})},i=o=>{t({...e,tooltip:o})};return s.jsxs(a.Stack,{ref:n,spacing:0,children:[s.jsx(Cn,{sectionTitle:"Overflow on Chart",value:e.label,onChange:r}),s.jsx(Cn,{sectionTitle:"Overflow in Tooltip",value:e.tooltip,onChange:i})]})}),Jj=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return s.jsx(a.Box,{children:s.jsx(fe,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},$o={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
287
+ `)}},Zj=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:i}]=$.useBoolean(),[o,l]=g.useState(e),c=()=>{i();const{type:p,func_content:x}=o,m={type:p,func_content:x};l(m),t(m)},u=()=>{i(),l(e)},d=p=>{l(x=>({...x,func_content:p}))},h=()=>{d($o.dynamic.func_content)};return s.jsxs(s.Fragment,{children:[s.jsx(a.Box,{sx:{width:"50%"},children:s.jsx(a.Button,{variant:"filled",mt:24,onClick:r,sx:{flexGrow:0},children:"Setup"})}),s.jsx(a.Modal,{size:800,title:"Setup dynamic size",opened:n,onClose:i,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),s.jsx(Jj,{value:o.func_content,onChange:d}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:h,color:"red",leftIcon:s.jsx(k.Recycle,{size:20}),children:"Reset"}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:u,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:c,children:"OK"})]})]})]})})]})},Hj=({value:e,onChange:t})=>e.type!=="dynamic"?null:s.jsx(Zj,{value:e,onChange:t}),ev=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=r=>{t({...e,size:r})};return s.jsx(s.Fragment,{children:s.jsx(a.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:e.size,onChange:n})})},tv=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],nv=g.forwardRef(({label:e="Size",value:t,onChange:n},r)=>{const i=o=>{n({...$o[o]})};return s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(a.Select,{ref:r,label:e,data:tv,value:t.type,onChange:i,sx:{flexGrow:1}}),s.jsx(ev,{value:t,onChange:n}),s.jsx(Hj,{value:t,onChange:n})]})}),sv=[{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 rv({control:e,watch:t}){return t(["scatter"]),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"scatter.name_data_key",control:e,render:({field:n})=>s.jsx(B,{label:"Name Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"scatter.y_data_key",control:e,render:({field:n})=>s.jsx(B,{label:"Value Data Field",required:!0,sx:{flex:1},...n})})]}),s.jsx(a.Divider,{mb:-15,label:"Style",labelPosition:"center"}),s.jsx(b.Controller,{name:"scatter.symbolSize",control:e,render:({field:n})=>s.jsx(nv,{label:"Size",...n})}),s.jsx(b.Controller,{name:"scatter.color",control:e,render:({field:n})=>s.jsx(Yj,{...n})}),s.jsx(a.Divider,{mb:-15,label:"Label",labelPosition:"center"}),s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:"scatter.label_position",control:e,render:({field:n})=>s.jsx(a.Select,{label:"Label Position",data:sv,...n})})}),s.jsx(b.Controller,{name:"scatter.label_overflow",control:e,render:({field:n})=>s.jsx(Xj,{...n})})]})}function iv({control:e,watch:t}){return t("stats"),s.jsx(a.Stack,{children:s.jsxs(a.Stack,{spacing:0,children:[s.jsx(b.Controller,{name:"stats.templates.top",control:e,render:({field:n})=>s.jsx(Yt,{label:"Template for stats above the chart",py:"md",sx:{flexGrow:1},...n})}),s.jsx(b.Controller,{name:"stats.templates.bottom",control:e,render:({field:n})=>s.jsx(Yt,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const av=({control:e,index:t,remove:n})=>s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>s.jsx(B,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed"}),s.jsx(a.Button,{leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),ov=({control:e,watch:t})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((p,x)=>({...p,...o[x]})),c=()=>r({id:Date.now().toString(),data_key:"",name:""}),u=t("tooltip.metrics.0.id"),[d,h]=g.useState(()=>u??null);return g.useEffect(()=>{u&&h(p=>p!==null?p:u)},[u]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(k.InfoCircle,{size:14,color:"#888"}),s.jsx(a.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),s.jsxs(a.Tabs,{value:d,onTabChange:p=>h(p),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((p,x)=>s.jsx(a.Tabs.Tab,{value:p.id,children:p.name?p.name:x},p.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),l.map((p,x)=>s.jsx(a.Tabs.Panel,{value:p.id,children:s.jsx(av,{control:e,index:x,remove:i},p.id)},p.id))]})]})},lv=[{label:"Scatter Point",value:"item"},{label:"X Axis",value:"axis"}];function cv({control:e,watch:t}){return t("tooltip.trigger"),s.jsxs(a.Stack,{children:[s.jsx(b.Controller,{name:"tooltip.trigger",control:e,render:({field:n})=>s.jsx(a.Select,{label:"Trigger",data:lv,sx:{flexGrow:1},...n})}),s.jsx(a.Divider,{variant:"dashed"}),s.jsx(ov,{control:e,watch:t})]})}const uv=({disabled:e,value:t,onChange:n})=>{const r=i=>{i&&n(i)};return s.jsxs(a.Box,{sx:{position:"relative"},children:[e&&s.jsx(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),s.jsx(fe,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},dv=g.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:i,setFalse:o}]=$.useBoolean(),[l,c]=g.useState(e);g.useEffect(()=>{c(e)},[e]);const u=m=>{c({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:j}=l,C={enabled:m,func_content:j};c(C),t(C)},h=()=>{o(),c(e)},p=m=>{c(j=>({...j,func_content:m}))},x=()=>{p(Eo().func_content)};return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"filled",mt:24,onClick:i,sx:{flexGrow:0},children:"Customize Label"}),s.jsx(a.Modal,{size:800,title:"Customize label content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&s.jsxs(a.Stack,{children:[s.jsx(a.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:m=>u(m.currentTarget.checked)}),s.jsx(uv,{value:l.func_content,onChange:p,disabled:!l.enabled}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:x,color:"red",leftIcon:s.jsx(k.Recycle,{size:20}),children:"Reset"}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:h,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:d,children:"OK"})]})]})]})})]})});function pv({control:e,watch:t}){return t(["x_axis"]),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>s.jsx(B,{label:"Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"x_axis.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"Name",sx:{flex:1},...n})})]}),s.jsx(a.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>s.jsx(a.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:s.jsx(a.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),s.jsx(b.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>s.jsx(dv,{...n})})]}),s.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>s.jsx(Re,{...n})})]})}const hv=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],xv=[{label:"left",value:"left"},{label:"right",value:"right"}];function fv({control:e,index:t,remove:n}){return s.jsxs(a.Stack,{my:0,p:"0",sx:{position:"relative"},children:[s.jsx(a.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`y_axes.${t}.name`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`y_axes.${t}.nameAlignment`,control:e,render:({field:r})=>s.jsx(a.Select,{label:"Align",required:!0,data:hv,sx:{flex:1},...r})})]}),s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:`y_axes.${t}.position`,control:e,render:({field:r})=>s.jsx(a.Select,{label:"Position",required:!0,data:xv,sx:{flex:1},...r})})}),s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),s.jsx(b.Controller,{name:`y_axes.${t}.label_formatter`,control:e,render:({field:r})=>s.jsx(Ve,{...r})})]}),s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:`y_axes.${t}.min`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Min",...r})}),s.jsx(b.Controller,{name:`y_axes.${t}.max`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Max",...r})})]})]}),s.jsx(a.Button,{mt:20,leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this YAxis"})]})}function gv({control:e,watch:t}){const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"y_axes"}),o=t("y_axes"),l=n.map((u,d)=>({...u,...o[d]})),c=()=>r({name:"",label_formatter:me,min:"",max:"",show:!0,position:"right",nameAlignment:"right"});return s.jsxs(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((u,d)=>s.jsx(a.Tabs.Tab,{value:d.toString(),children:d+1},u.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),l.map((u,d)=>s.jsx(a.Tabs.Panel,{value:d.toString(),children:s.jsx(fv,{control:e,index:d,remove:i})},u.id))]})}function mv(e){return e||{templates:{top:"",bottom:""}}}function yv({reference_lines:e=[],stats:t,...n}){return{reference_lines:e,stats:mv(t),...n}}function bv({context:e}){const{value:t,set:n}=O(e.instanceData,"config"),{variables:r}=e,i=g.useMemo(()=>y.defaultsDeep({},t,dr),[t]),o=g.useMemo(()=>yv(i),[i]);g.useEffect(()=>{!y.isEqual(i,o)&&(console.log("config malformed, resetting to defaults",i,o),n(o))},[i,o]);const{control:l,handleSubmit:c,watch:u,getValues:d,reset:h}=b.useForm({defaultValues:o});g.useEffect(()=>{h(o)},[o]);const p=d(),x=g.useMemo(()=>!y.isEqual(p,i),[p,i]);return u(["dataZoom"]),s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:c(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Chart Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!x,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"X Axis",children:"X Axis"}),s.jsx(a.Tabs.Tab,{value:"Y Axes",children:"Y Axes"}),s.jsx(a.Tabs.Tab,{value:"Scatter",children:"Scatter"}),s.jsx(a.Tabs.Tab,{value:"Tooltip",children:"Tooltip"}),s.jsx(a.Tabs.Tab,{value:"Stats",children:"Stats"}),s.jsx(a.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"}),s.jsx(a.Tabs.Tab,{value:"Reference Areas",children:"Reference Areas"}),s.jsx(a.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),s.jsx(a.Tabs.Panel,{value:"X Axis",children:s.jsx(pv,{control:l,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Y Axes",children:s.jsx(gv,{control:l,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Scatter",children:s.jsx(rv,{control:l,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(cv,{control:l,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Stats",children:s.jsx(iv,{control:l,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Reference Lines",children:s.jsx(Gj,{variables:r,control:l,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Reference Areas",children:s.jsx(Vj,{variables:r,control:l,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Zooming",children:s.jsx(b.Controller,{name:"dataZoom",control:l,render:({field:m})=>s.jsx(Tn,{...m})})})]})]})})}function jv(e){const{dataZoom:t=bt,...n}=e;return{...n,dataZoom:t}}function vv(e){const t={scatter:{label_overflow:Po()}};return y.defaultsDeep(t,e)}function wv(e){const{color:t}=e.scatter;return typeof t=="string"?{...e,scatter:{...e.scatter,color:{...an.static,color:t}}}:e}function Cv(e){const t=e.reference_lines.map(n=>{const{lineStyle:r={type:"dashed",width:1,color:tt.random().css()},show_in_legend:i=!1,yAxisIndex:o=0}=n;return{...n,lineStyle:r,show_in_legend:i,yAxisIndex:o}});return{...e,reference_lines:t}}function Sv(e){const t={tooltip:{trigger:"item"}};return y.defaultsDeep({},e,t)}function _v(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis:i,scatter:o,tooltip:l,...c}=e;return{...c,x_axis:{...i,data_key:r(i.data_key)},scatter:{...o,y_data_key:r(o.y_data_key),name_data_key:r(o.name_data_key)},tooltip:{...l,metrics:l.metrics.map(u=>({...u,data_key:r(u.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}function kv(e){const t={x_axis:{axisLabel:{overflow:Te()}}};return y.defaultsDeep(t,e)}class Tv extends ae{constructor(){super(...arguments);P(this,"VERSION",10)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{tooltip:r={metrics:[]},...i}=n.config;return{...n,version:2,config:{...i,tooltip:r}}}),this.version(3,n=>({...n,version:3,config:jv(n.config)})),this.version(4,n=>{const{config:r}=n;return{...n,version:5,config:vv(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:wv(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:Cv(r)}}),this.version(8,n=>{const{config:r}=n;return{...n,version:8,config:Sv(r)}}),this.version(9,(n,r)=>{const{config:i}=n;return{...n,version:9,config:_v(i,r)}}),this.version(10,(n,r)=>{const{config:i}=n;return{...n,version:10,config:kv(i)}})}}const Dv={displayName:"Scatter Chart",displayGroup:"ECharts-based charts",migrator:new Tv,name:"scatterChart",viewRender:Bj,configRender:bv,createConfig(){return{version:10,config:y.cloneDeep(dr)}},triggers:[Ao]},pr={template:"The variable ${value} is defined in Variables section",vertical_align:"center",horizontal_align:"left"};function Iv(e){if("variables"in e)return e;const{align:t,size:n,weight:r,color:i,content:{prefix:o="",data_field:l="value",formatter:c={output:"number",mantissa:0},postfix:u=""}={}}=e;return{align:t,template:`${o} \${value} ${u}`,variables:[{name:"value",data_field:l,aggregation:{type:"none",config:{}},formatter:c,color:i,weight:r,size:n}]}}function Mv(e){return y.omit(e,["variables"])}function zv(e){const{align:t,...n}=e;return{horizontal_align:t,vertical_align:"center",...n}}function Av(e){const t=y.cloneDeep(e),n=y.get(t,"color.valueRange");return n!==void 0&&y.set(t,"color.valueRange",n.map(r=>Number(r))),t}class Ev extends ae{constructor(){super(...arguments);P(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:Iv(n)})),this.version(2,(n,{panelModel:r})=>{const{config:i}=n;return(i.variables||[]).forEach(l=>{r.variables.find(c=>c.name===l.name)||r.addVariable(Av(l))}),{...n,version:2,config:Mv(i)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:zv(r)}})}}const Pv={left:"flex-start",center:"center",right:"flex-end"},Lv={top:"flex-start",center:"center",bottom:"flex-end"},Bv=S.observer(({context:e})=>{const t=ce(),{value:n=pr}=O(e.instanceData,"config"),{variables:r}=e,{template:i,horizontal_align:o,vertical_align:l}=n,{width:c,height:u}=e.viewport,d=g.useMemo(()=>{try{return y.template(i)(t.payloadForSQL)}catch{return i}},[t.payloadForSQL,i]),h=g.useMemo(()=>Jt(d,r,e.data),[d,r,e.data,e]);return s.jsx(a.Center,{sx:{width:c,height:u,justifyContent:Pv[o],alignItems:Lv[l]},children:s.jsx(a.Box,{children:Object.values(h).map((p,x)=>s.jsx(g.Fragment,{children:p},x))})})}),Ov=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],$v=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function Vv({context:e}){const{value:t,set:n}=O(e.instanceData,"config"),r=g.useMemo(()=>y.defaultsDeep({},t,pr),[t]),{control:i,handleSubmit:o,watch:l,getValues:c,reset:u}=b.useForm({defaultValues:r});g.useEffect(()=>{u(r)},[r]),l(["template","horizontal_align","vertical_align"]);const d=c(),h=g.useMemo(()=>!y.isEqual(d,t),[d,t]);return s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:o(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{weight:500,children:"Stats Configurations"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsx(b.Controller,{name:"template",control:i,render:({field:p})=>s.jsx(Yt,{label:"Template",py:"md",sx:{flexGrow:1},...p})}),s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(b.Controller,{name:"horizontal_align",control:i,render:({field:p})=>s.jsx(a.Select,{label:"Horizontal Alignment",data:Ov,...p})}),s.jsx(b.Controller,{control:i,name:"vertical_align",render:({field:p})=>s.jsx(a.Select,{label:"Vertical Alignment",data:$v,...p})})]})]})})}const qv={createConfig(){return{version:3,config:pr}},displayName:"Stats",displayGroup:"Others",migrator:new Ev,name:"stats",viewRender:Bv,configRender:Vv},hr={label_key:"",value_key:"",group_key:"",levels:[]};function Nv(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 Fv(e){const t=Nv(e).map(i=>({...i,children:[]})),n=y.keyBy(t,i=>i.id),r=[];return t.forEach(i=>{if(!i.parent_id||!n[i.parent_id]){r.push(i);return}n[i.parent_id].children.push(i)}),r}function Gv(e,t){const{label_key:n,value_key:r,group_key:i}=e;if(!n||!r)return[];const o=z(n),l=z(r),c=z(i),u=t[o.queryID].map(d=>({...d,id:d[o.columnKey],parent_id:d[c.columnKey],name:d[o.columnKey],value:d[l.columnKey]?Number(d[l.columnKey]):d[l.columnKey]}));return i?Fv(u):u}const Wv=e=>({treePathInfo:t,name:n,value:r})=>{if(t.length===1||!e)return n;try{const i=t[t.length-2].value;if(r/i<e)return" "}catch{return n}};function Rv(e){const{levels:t}=e;return t.map(n=>{const{show_label_tolerance:r,...i}=n.label;return{...n,label:{...i,formatter:Wv(r)}}})}function Qv(){return({treePathInfo:e,name:t,value:n,color:r,marker:i,...o})=>{const l=e.slice(0,e.length-1),c=[`<tr>
288
288
  <th style="text-align: right; padding: 0 1em;">Value</th>
289
289
  <td style="text-align: left; padding: 0 1em;">${n}</td>
290
290
  </tr>
291
- `];return l.reverse().forEach(({value:d,name:h})=>{u.push(`
291
+ `];return l.reverse().forEach(({value:d,name:h})=>{c.push(`
292
292
  <tr>
293
293
  <th style="text-align: right; padding: 0 1em;">${h||"Total"}</th>
294
294
  <td style="text-align: left; padding: 0 1em;">
295
- ${W(n/d,{output:"percent",mantissa:2,trimMantissa:!0,absolute:!1})}
295
+ ${G(n/d,{output:"percent",mantissa:2,trimMantissa:!0,absolute:!1})}
296
296
  </td>
297
297
  </tr>
298
298
  `)}),`
@@ -300,11 +300,11 @@ Check the top-level render call using <`+E+">.")}return I}}function rc(w,I){{if(
300
300
  <div>${i} ${t}</div>
301
301
  </div>
302
302
  <table style="width: auto">
303
- <tbody>${u.join("")}</tbody>
303
+ <tbody>${c.join("")}</tbody>
304
304
  </table>
305
- `}}function Qv(){return ne.getTooltip({trigger:"item",formatter:Rv()})}const Uv={tooltip:{show:!0},series:{type:"sunburst",radius:[0,"90%"],emphasis:{focus:"ancestor"}}};function Kv(e,t,n){n.reduce((o,l)=>{const u=it(l,t);return o[l.name]=Pe(l,u),o},{});const i={series:{data:Fv(e,t),levels:Wv(e)},tooltip:Qv()};return y.defaultsDeep({},i,Uv)}J.use([ie.SunburstChart,_e.CanvasRenderer]);function Yv({context:e}){const{variables:t}=e,{value:n}=$(e.instanceData,"config"),r=g.useMemo(()=>y.defaults({},n,xr),[n]),i=e.data,{width:o,height:l}=e.viewport,u=g.useMemo(()=>Kv(r,i,t),[r,i,t]);return!o||!l?null:s.jsx(Ie,{width:o,height:l,children:s.jsx(Se,{echarts:J,option:u,style:Ht(o,l),notMerge:!0,theme:"merico-light"})})}function Xv({control:e,watch:t}){return t(["label_key","value_key","group_key"]),s.jsxs(a.Stack,{children:[s.jsx(b.Controller,{name:"label_key",control:e,render:({field:n})=>s.jsx(O,{label:"Label Key",required:!0,...n})}),s.jsx(b.Controller,{name:"value_key",control:e,render:({field:n})=>s.jsx(O,{label:"Value Key",required:!0,...n})}),s.jsx(b.Controller,{name:"group_key",control:e,render:({field:n})=>s.jsx(O,{label:"Group Key",clearable:!0,...n})})]})}const Jv=[{label:"Radial",value:"radial"},{label:"Tangential",value:"tangential"},{label:"None",value:"0"}],Zv=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Hv=({control:e,index:t,remove:n})=>s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`levels.${t}.r0`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Inside Radius",placeholder:"0%",...r})}),s.jsx(b.Controller,{name:`levels.${t}.r`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Outside Radius",placeholder:"50%",...r})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Label Style",labelPosition:"center"}),s.jsx(b.Controller,{name:`levels.${t}.label.show_label_tolerance`,control:e,render:({field:r})=>s.jsx(a.NumberInput,{label:"Hide label when its percentage is less than...",precision:4,step:5e-4,min:0,max:1,...r})}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`levels.${t}.label.rotate`,control:e,render:({field:r})=>s.jsx(a.Select,{label:"Rotate",data:Jv,...r})}),s.jsx(b.Controller,{name:`levels.${t}.label.align`,control:e,render:({field:r})=>s.jsx(a.Select,{label:"Align",data:Zv,...r})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`levels.${t}.label.position`,control:e,render:({field:r})=>s.jsx(ar,{label:"Position",...r})}),s.jsx(b.Controller,{name:`levels.${t}.label.padding`,control:e,render:({field:r})=>s.jsx(a.NumberInput,{label:"Padding",min:0,hideControls:!0,...r})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed"}),s.jsx(a.Button,{leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Level"})]}),ew=({control:e,watch:t})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"levels"}),o=t("levels"),l=n.map((p,x)=>({...p,...o[x]})),u=()=>r({id:Date.now().toString(),r0:"",r:"",label:{show_label_tolerance:.001,rotate:"0",align:"center",position:"inside",padding:0}}),c=t("levels.0.id"),[d,h]=g.useState(()=>c??null);return g.useEffect(()=>{c&&h(p=>p!==null?p:c)},[c]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(k.InfoCircle,{size:14,color:"#888"}),s.jsx(a.Text,{size:14,color:"#888",children:"Configure ring style on each level"})]}),s.jsx(a.Divider,{variant:"dashed",my:10}),s.jsxs(a.Tabs,{value:d,onTabChange:p=>h(p),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((p,x)=>s.jsx(a.Tabs.Tab,{value:p.id,children:x},p.id)),s.jsx(a.Tabs.Tab,{onClick:u,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),l.map((p,x)=>s.jsx(a.Tabs.Panel,{value:p.id,children:s.jsx(Hv,{control:e,index:x,remove:i},p.id)},p.id))]})]})};function tw({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=g.useMemo(()=>y.defaultsDeep({},t,xr),[t]),i=g.useMemo(()=>y.clone(r),[r]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=b.useForm({defaultValues:i});g.useEffect(()=>{d(i)},[i]);const h=c(),p=g.useMemo(()=>!y.isEqual(h,r),[h,r]);u(["label_key","value_key","group_key","levels"]);const[x,m]=g.useState("Data");return s.jsx("form",{onSubmit:l(n),children:s.jsxs(a.Stack,{spacing:"xs",children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Sunburst Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Tabs,{value:x,onTabChange:m,orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"Data",children:"Data"}),s.jsx(a.Tabs.Tab,{value:"Levels",children:"Levels"})]}),s.jsx(a.Tabs.Panel,{value:"Data",children:s.jsx(Xv,{control:o,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Levels",children:s.jsx(ew,{control:o,watch:u})})]})]})})}function nw(e){const{label_field:t,value_field:n,...r}=e;return{...r,label_key:t,value_key:n}}function sw(e){const{group_key:t="",...n}=e;return{...n,group_key:t}}function rw(e){const{levels:t=[],...n}=e;return{...n,levels:t}}function iw(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{label_key:i,value_key:o,group_key:l,...u}=e;return{...u,label_key:r(i),value_key:r(o),group_key:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class aw extends ue{constructor(){super(...arguments);L(this,"VERSION",5)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:nw(n.config)})),this.version(3,n=>({...n,version:3,config:sw(n.config)})),this.version(4,n=>({...n,version:4,config:rw(n.config)})),this.version(5,(n,r)=>({...n,version:5,config:iw(n.config,r)}))}}const ow={displayName:"Sunburst Chart",displayGroup:"ECharts-based charts",migrator:new aw,name:"sunburst",viewRender:Yv,configRender:tw,createConfig(){return{version:5,config:y.cloneDeep(xr)}}};var Ye=(e=>(e.string="string",e.number="number",e.eloc="eloc",e.percentage="percentage",e.custom="custom",e))(Ye||{});const $o=["function text({ value }) {"," // your code goes here"," return value","}"].join(`
306
- `),Vo={columns:[],fontSize:"14px",highlightOnHover:!0,horizontalSpacing:"14px",id_field:"",striped:!0,use_raw_columns:!0,verticalSpacing:"14px"},qo={left:"flex-start",center:"center",right:"flex-end"},lw=({header:e,cx:t})=>{const n=y.get(e.column.columnDef.meta,"align","left");return s.jsxs(a.Text,{className:t("table-head-cell",{"table-head-cell--sortable":e.column.getCanSort()}),onClick:e.column.getToggleSortingHandler(),align:n,sx:{justifyContent:qo[n]},children:[e.isPlaceholder?null:Re.flexRender(e.column.columnDef.header,e.getContext()),s.jsx(uw,{direction:e.column.getIsSorted()})]})},uw=({direction:e})=>{switch(e){case"asc":return s.jsx(_.IconArrowUp,{size:16});case"desc":return s.jsx(_.IconArrowDown,{size:"1em"});default:return null}},cw=a.createStyles(e=>({root:{overflow:"auto",position:"relative","& .table-head-cell":{display:"flex",flexFlow:"row nowrap",alignItems:"center",whiteSpace:"nowrap","&.table-head-cell--sortable":{cursor:"pointer",userSelect:"none"}},"&.table-highlight-on-hover tr":{transition:"background-color 0.2s","&:hover":{backgroundColor:e.colorScheme==="dark"?e.colors.dark[5]:e.colors.gray[0]}}},thead:{background:e.colorScheme==="dark"?e.colors.dark[7]:e.white,position:"sticky",top:24,transform:"translateY(-1px)",zIndex:10},info_bar:{position:"sticky",top:0,left:0,right:0,zIndex:10,background:"white"}})),dw={tableLayout:"fixed","thead, tbody":{tr:{"th, td":{padding:"2px 10px",div:{overflow:"hidden",textOverflow:"ellipsis"},"&:first-of-type":{paddingLeft:2,paddingRight:2}}}}},pw=a.createStyles((e,t)=>({content:{display:"flex",alignItems:"center",justifyContent:qo[t.align],".table-cell-text":{whiteSpace:"nowrap",cursor:t.clickable?"pointer":"default",textDecoration:t.clickable?"underline":"none"}}}));function hw(e){return e?st(e).oklch()[0]>.7?"black":"white":"inherit"}function xw(e){const t=e.tableCellContext.bgColor;return{backgroundColor:t,color:hw(t)}}function Nt(e){const t=e.tableCellContext.isClickable(),n=pw({clickable:t,align:e.align});return s.jsx("div",{className:n.classes.content,style:{...xw(e)},children:s.jsx(a.Text,{className:"table-cell-text",onClick:e.tableCellContext.getClickHandler(),children:s.jsx("span",{title:e.children,children:e.children})})})}function fw(e){return s.jsx(Nt,{...e,children:e.value})}function gw(e){const t=W(e.value,{output:"number",average:!0,mantissa:2,trimMantissa:!0,absolute:!1});return s.jsx(Nt,{...e,children:t})}function mw(e){const t=W(e.value,{output:"number",mantissa:0,thousandSeparated:!0,absolute:!1});return s.jsx(Nt,{...e,children:t})}function yw(e){const t=W(e.value,{output:"percent",mantissa:3,trimMantissa:!0,absolute:!1});return s.jsx(Nt,{...e,children:t})}function bw(e){const t=e.value,n=e.func_content;if(!n)return s.jsx(Nt,{...e,children:t});const r=new Function(`return ${n}`)()({value:t});return s.jsx(Nt,{...e,children:r})}function jw(e){switch(e.type){case Ye.string:return s.jsx(fw,{...e});case Ye.eloc:return s.jsx(gw,{...e});case Ye.number:return s.jsx(mw,{...e});case Ye.percentage:return s.jsx(yw,{...e});case Ye.custom:return s.jsx(bw,{...e})}}function vw({tableContainerRef:e,rows:t}){var u,c;const n=pc.useVirtual({parentRef:e,size:t.length,estimateSize:g.useCallback(()=>28,[]),overscan:20}),{virtualItems:r,totalSize:i}=n,o=r.length>0&&((u=r==null?void 0:r[0])==null?void 0:u.start)||0,l=r.length>0?i-(((c=r==null?void 0:r[r.length-1])==null?void 0:c.end)||0):0;return V.useWhyDidYouUpdate("TableBody",{tableContainerRef:e,rows:t}),s.jsxs("tbody",{children:[o>0&&s.jsx("tr",{children:s.jsx("td",{style:{height:`${o}px`}})}),r.map(d=>{const h=t[d.index];return s.jsx("tr",{children:h.getVisibleCells().map(p=>s.jsx("td",{children:Re.flexRender(p.column.columnDef.cell,p.getContext())},p.id))},h.id)}),l>0&&s.jsx("tr",{children:s.jsx("td",{style:{height:`${l}px`}})})]})}const fr={id:"builtin:table:click-cell-content",displayName:"Click Cell Content",nameRender:_w,configRender:Cw,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"}]},ww={column:""};function No(e,t){const{value:n}=$(e.instanceData,"config"),r={columnsFromConfig:[],columnsFromData:[]};if(n&&(r.columnsFromConfig=n.columns.map((i,o)=>({label:i.label,value:o.toString()}))),!t)return r;if(n!=null&&n.id_field){const i=Jt(t,n.id_field);(i==null?void 0:i.length)>0&&(r.columnsFromData=Object.keys(i[0]).map(o=>({label:o,value:o})))}return r}function Cw(e){const{columnsFromConfig:t,columnsFromData:n}=No(e.instance,e.sampleData),r=t.length>0?t:n,{value:i,set:o}=$(e.trigger.triggerData,"config"),{column:l}=y.defaults({},i,ww),u=c=>{isNaN(+c)?o({column:c}):o({column:+c})};return s.jsx(a.Select,{clearable:!1,data:r,label:"Choose a column",value:l.toString(),onChange:u})}function Sw(e,t){return e?y.isNumber(e.column)?`Click cell of ${t[e.column].label}`:`Click cell of ${e.column}`:"Click cell content (click to config)"}function _w(e){const{columnsFromConfig:t}=No(e.instance),{value:n}=$(e.trigger.triggerData,"config");return s.jsx(a.Text,{children:Sw(n,t)})}function Fo(e,t,n){return Math.min(Math.max(e,t),n)}class kw{constructor(t){this.steps=t;const n=[],r=new Set;for(const i of t)r.has(i.to)||(n.push(i),r.add(i.to));if(n.sort((i,o)=>i.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),i=t.to-r*t.from;return o=>r*o+i}getStepFunctionForValue(t){let n=y.findLastIndex(this.steps,r=>r.from<=t);return n=Fo(n,0,this.steps.length-2),this.getLinearFunction(this.steps[n],this.steps[n+1])}mapValue(t){return Fo(this.getStepFunctionForValue(t)(t),0,100)}}class Tw{constructor(t,n,r,i,o){this.getColIndex=t,this.cell=n,this.triggers=r,this.interactionManager=i,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===fr.id).filter(n=>{const r=this.getColIndex(this.cell),i=y.get(this.cell.column.columnDef.meta,"value_field"),o=y.get(n.config,"column");return o==r||o==i})}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(y.isString(t))return t;const n=+this.cell.getValue();if(isFinite(n)){const r=this.colorManager.decodeInterpolation(t.interpolation),o=new kw(t.steps).mapValue(n);return r==null?void 0:r.getColor(o)}}}const Dw=e=>{const t=Ne(e),n=qe(t.triggerManager,fr.id),{colorManager:r}=g.useContext(tt);return g.useCallback(i=>new Tw(e.getColIndex,i,n,t,r),[n,t,e.getColIndex])};function Iw({queryData:e,width:t,height:n,conf:r,context:i,instance:o}){const{id_field:l,use_raw_columns:u,columns:c,...d}=r,{classes:h,cx:p}=cw(),x=g.useMemo(()=>u?!Array.isArray(e)||e.length===0?[]:Object.keys(e[0]).map(ae=>({id:ae,label:ae,value_field:ae,value_type:Ye.string,align:"left",width:"",cellBackgroundColor:""})):c,[u,c,e]),m=Dw({getColIndex:g.useCallback(ae=>x.indexOf(ae.column.columnDef.meta),[x]),vizManager:i.vizManager,instance:o}),j=g.useMemo(()=>{const ae=Re.createColumnHelper();return x.map(Xe=>{const bi=od(Xe.value_field);return ae.accessor(bi.columnKey,{cell:pn=>s.jsx(jw,{tableCellContext:m(pn.cell),value:pn.getValue(),type:Xe.value_type,...Xe}),header:Xe.label,enableSorting:!0,meta:Xe,size:typeof Xe.width=="number"?Xe.width:void 0,minSize:typeof Xe.width=="number"?Xe.width:void 0})})},[x,m]),[C,T]=g.useState([]),D=Re.useReactTable({data:e,state:{sorting:C},onSortingChange:T,columns:j,getCoreRowModel:Re.getCoreRowModel(),getSortedRowModel:Re.getSortedRowModel()}),{rows:A}=D.getRowModel(),F=g.useRef(null),X=A.length,Q=X>0,G=Q?n-22:n,ee=Q?22:0;return V.useWhyDidYouUpdate("VizTableComponent",{queryData:e,width:t,height:n,conf:r,context:i,instance:o,finalColumns:x,getCellContext:m,tableColumns:j,table:D,rows:A,tableContainerRef:F}),s.jsxs("div",{ref:F,style:{height:n,width:t,padding:"0 5px"},"data-enable-scrollbar":!0,className:p(h.root,{"table-highlight-on-hover":r.highlightOnHover}),children:[X>0&&s.jsx(a.Box,{className:h.info_bar,sx:{height:22},children:s.jsxs(a.Text,{align:"right",pr:6,size:14,color:"dimmed",fw:"normal",children:["Total: ",X]})}),s.jsxs(a.Table,{sx:{...dw,maxHeight:G},...d,striped:r.striped,children:[s.jsx("thead",{className:h.thead,style:{top:ee},children:D.getHeaderGroups().map(ae=>s.jsx("tr",{children:ae.headers.map(Dt=>s.jsx("th",{style:{width:Dt.getSize()},children:s.jsx(lw,{header:Dt,cx:p})},Dt.id))},ae.id))}),s.jsx(vw,{tableContainerRef:F,rows:A})]})]})}function Mw({data:e,width:t,height:n,conf:r,context:i,instance:o}){const{id_field:l,use_raw_columns:u,columns:c}=r,d=g.useMemo(()=>{if(!l)return[];const h=z(l);return e[h.queryID]},[e,l]);return!Array.isArray(d)||d.length===0?s.jsx(a.Text,{color:"gray",align:"center",children:"Empty Data"}):s.jsx(Iw,{queryData:d,width:t,height:n,conf:r,context:i,instance:o})}function zw({context:e,instance:t}){const n=e.data,{height:r,width:i}=e.viewport,{value:o}=$(e.instanceData,"config");return o?o.id_field?s.jsx(Mw,{data:n,width:i,height:r,conf:o,context:e,instance:t}):s.jsx(a.Text,{color:"red",align:"center",children:"ID Field is not set, can't render a table without it"}):null}const Go=a.createStyles(()=>({palette:{display:"flex",flexFlow:"row nowrap"},paletteItem:{".palette-value":{height:24,overflow:"visible",width:36},".palette-item":{width:"36px",height:36*.618,cursor:"pointer",transition:"transform 100ms ease-in-out","&:hover":{boxShadow:"0 0 0 2px var(--shadow-color)",borderRadius:2,transform:"scale(1.2)"}}}})),Aw=[{from:0,to:0},{from:100,to:100}];class Ew{constructor(){L(this,"steps",new Map);L(this,"interpolation");L(this,"onChange");K.makeAutoObservable(this,{steps:K.observable},{deep:!1}),K.reaction(()=>K.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(Aw):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 Lw(e){const{onChange:t,color:n,index:r,value:i}=e,{classes:o}=Go(),[l,u]=g.useState(i),[c,{setTrue:d,setFalse:h}]=V.useBoolean(!1),p=r%2===1,x=p&&i!=null,m=!p&&i!=null,j=`map ${i} to color ${r}`,C=()=>{u(i),h()},T=()=>{h(),t==null||t(l)},D=W(i??null,{output:"number",mantissa:0,average:!0,absolute:!1});return s.jsxs("div",{"data-testid":`palette-item-${r}`,className:o.paletteItem,children:[s.jsx(a.Text,{title:j,style:{opacity:x?1:0},color:"dimmed",size:"sm",className:"palette-value--up palette-value",children:D}),s.jsxs(a.Popover,{width:200,trapFocus:!0,opened:c,onClose:h,children:[s.jsx(a.Popover.Target,{children:s.jsx("div",{"data-testid":"palette-item-target",className:"palette-item",onClick:d,style:{"--shadow-color":st(n).alpha(.5).hex(),backgroundColor:n}})}),s.jsx(a.Popover.Dropdown,{children:s.jsxs(a.Stack,{children:[s.jsx(a.NumberInput,{size:"xs",label:"Map a value to this color",value:l,onChange:u}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{variant:"subtle",size:"xs",onClick:C,children:"Cancel"}),s.jsx(a.Button,{"data-testid":"palette-item-ok",size:"xs",onClick:T,children:"OK"})]})]})})]}),s.jsx(a.Text,{title:j,style:{opacity:m?1:0},color:"dimmed",size:"sm",className:"palette-value--bottom palette-value",children:D})]})}const Pw=S.observer(({model:e})=>{const{classes:t}=Go(),n=y.range(0,13,1).map(r=>100/12*r).map(r=>[e.interpolation.getColor(r),r]);return s.jsx("div",{className:t.palette,children:n.map(([r,i],o)=>s.jsx(Lw,{index:o,color:r,value:e.getStepFromValue(i),onChange:l=>e.changeStep(l,i)},r))})}),Bw=S.observer(function(t){const n=V.useCreation(()=>new Ew,[]);return g.useEffect(()=>{n.fromProps(t)}),n.interpolation==null?null:s.jsx(Pw,{model:n})}),Ow=e=>{const{value:t,onChange:n,colorManager:r}=e,i=r.getColorInterpolations(),[o,l]=g.useState(t),u=r.decodeInterpolation(o.interpolation)||i[0],[c,{setTrue:d,setFalse:h}]=V.useBoolean(),p=i.map(T=>({label:T.displayName,value:r.encodeColor(T),group:T.category}));function x(T){T&&l(D=>({...D,interpolation:T}))}const m=()=>{h(),n==null||n(K.toJS(o))};function j(T){l(D=>({...D,steps:T}))}const C=()=>{h(),l(t)};return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"outline",onClick:d,children:u==null?void 0:u.displayName}),s.jsx(a.Modal,{size:508,title:"Setup color interpolation",opened:c,onClose:h,zIndex:320,children:c&&s.jsxs(a.Stack,{"data-testid":"color-interpolation-modal",children:[s.jsx(a.Select,{label:"Color style",value:o.interpolation,data:p,onChange:x,withinPortal:!0,zIndex:340,maxDropdownHeight:500}),s.jsx(Bw,{steps:o.steps,interpolation:u,onChange:j}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:C,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:m,children:"OK"})]})]})})]})},$w=["static","interpolation","none"].map(e=>({label:y.capitalize(e),value:e})),Vw=[{from:0,to:0},{from:100,to:100}];function Wo(e){return e?y.isString(e)?e==="none"?"none":"static":"interpolation":"none"}function qw(e,t){var n;return Wo(t)==="static"?t:(n=e.getStaticColors()[0])==null?void 0:n.value}function Nw(e,t){return y.isObject(t)?t:{steps:Vw,interpolation:e.encodeColor(e.getColorInterpolations()[0])}}const Fw=g.forwardRef((e,t)=>{const{colorManager:n}=g.useContext(tt),[r,i]=g.useState(Wo(e.value)),[o,l]=g.useState(qw(n,e.value)),u=V.useLatest(o),[c,d]=g.useState(Nw(n,e.value)),h=V.useLatest(c),p=j=>{var C,T,D;i(j||"none"),j==="static"?(C=e.onChange)==null||C.call(e,u.current):j==="none"||!j?(T=e.onChange)==null||T.call(e,"none"):(D=e.onChange)==null||D.call(e,h.current)},x=j=>{var C;l(j),(C=e.onChange)==null||C.call(e,j)},m=j=>{var C;d(j),(C=e.onChange)==null||C.call(e,j)};return s.jsxs(a.Stack,{align:"stretch",children:[s.jsx(a.Select,{label:"Cell background",value:r||"none",onChange:p,data:$w}),r==="static"&&s.jsx(ke,{value:o,onChange:x}),r==="interpolation"&&s.jsx(Ow,{colorManager:n,value:c,onChange:m})]})}),Gw={[Ye.eloc]:"ELOC"},Ww=Object.values(Ye).map(e=>({label:y.get(Gw,e,y.capitalize(e)),value:e})),Rw=g.forwardRef(({label:e,value:t,onChange:n,sx:r},i)=>s.jsx(a.Select,{ref:i,label:e,data:Ww,value:t,onChange:n,sx:r})),Qw=g.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:i,setFalse:o}]=V.useBoolean(),[l,u]=g.useState(e),c=()=>{o(),t(l)},d=()=>{o(),u(e)},h=()=>{u($o)};return g.useEffect(()=>{u(e)},[e]),s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"filled",mt:24,onClick:i,sx:{flexGrow:0},children:"Custom Cell Content"}),s.jsx(a.Modal,{size:800,title:"Custom cell content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&s.jsxs(a.Stack,{children:[s.jsx(a.Box,{sx:{position:"relative"},children:s.jsx(ye,{height:"500px",defaultLanguage:"javascript",value:l,onChange:p=>u(p??""),theme:"vs-dark",options:{minimap:{enabled:!1}}})}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:h,color:"red",leftIcon:s.jsx(k.Recycle,{size:20}),children:"Reset"}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:d,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:c,children:"OK"})]})]})]})})]})}),Uw=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],gr=()=>s.jsx(a.Text,{color:"dimmed",size:12,children:"px"}),Kw=({control:e,index:t,watch:n,remove:r,column:i})=>{const o=n(`columns.${t}.value_type`);return s.jsxs(a.Stack,{my:0,sx:{position:"relative"},children:[s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:`columns.${t}.label`,control:e,render:({field:l})=>s.jsx(a.TextInput,{label:"Label",required:!0,id:`col-label-${t}`,sx:{flex:1},...l})}),s.jsx(b.Controller,{name:`columns.${t}.value_field`,control:e,render:({field:l})=>s.jsx(O,{label:"Value Field",required:!0,...l})})]}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:`columns.${t}.value_type`,control:e,render:({field:l})=>s.jsx(Rw,{label:"Value Type",sx:{flex:1},...l})}),o===Ye.custom&&s.jsx(b.Controller,{name:`columns.${t}.func_content`,control:e,render:({field:l})=>s.jsx(Qw,{value:l.value??$o,onChange:u=>l.onChange(u??"")})})]}),s.jsx(a.Divider,{mb:-10,variant:"dashed",label:"Style",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(a.NumberInput,{hideControls:!0,label:"Min Width",rightSection:s.jsx(gr,{}),disabled:!0}),s.jsx(b.Controller,{name:`columns.${t}.width`,control:e,render:({field:l})=>s.jsx(a.NumberInput,{hideControls:!0,label:"Width",rightSection:s.jsx(gr,{}),...l})}),s.jsx(a.NumberInput,{hideControls:!0,label:"Max Width",rightSection:s.jsx(gr,{}),disabled:!0})]}),s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:`columns.${t}.align`,control:e,render:({field:l})=>s.jsx(a.Select,{label:"Alignment",data:Uw,...l})})}),s.jsx(b.Controller,{name:`columns.${t}.cellBackgroundColor`,control:e,render:({field:l})=>s.jsx(Fw,{...l})}),s.jsx(a.Divider,{mb:4,mt:12,variant:"dashed"}),s.jsx(a.Button,{leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(t),children:"Delete this column"})]})},Yw=({control:e,watch:t})=>{const{fields:n,append:r,remove:i,update:o}=b.useFieldArray({control:e,name:"columns"}),l=()=>{const c=oe.randomId();r({id:c,label:c,align:"center",value_field:"",value_type:Ye.string,width:""})};t("columns");const u=t("use_raw_columns");return s.jsxs(s.Fragment,{children:[s.jsx(b.Controller,{name:"use_raw_columns",control:e,render:({field:c})=>s.jsx(a.Switch,{mt:20,mb:20,label:"Use Original Data Columns",checked:c.value,onChange:d=>c.onChange(d.currentTarget.checked)})}),!u&&s.jsx(a.Stack,{children:s.jsxs(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[n.map((c,d)=>s.jsx(a.Tabs.Tab,{value:d.toString(),children:d+1},c.id)),s.jsx(a.Tabs.Tab,{onClick:l,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),n.map((c,d)=>s.jsx(a.Tabs.Panel,{value:d.toString(),children:s.jsx(Kw,{control:e,watch:t,index:d,column:c,remove:i})},c.id))]})})]})};function Xw({control:e,watch:t}){return t(["horizontalSpacing","verticalSpacing","fontSize","striped","highlightOnHover"]),s.jsxs(a.Stack,{spacing:"xs",children:[s.jsxs(a.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:[s.jsx(b.Controller,{name:"horizontalSpacing",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"Horizontal Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"verticalSpacing",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"Vertical Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})})]}),s.jsx(a.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:s.jsx(b.Controller,{name:"fontSize",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})})}),s.jsxs(a.Group,{position:"apart",grow:!0,children:[s.jsx(b.Controller,{name:"striped",control:e,render:({field:n})=>s.jsx(a.Switch,{label:"Striped",checked:n.value,onChange:r=>n.onChange(r.currentTarget.checked)})}),s.jsx(b.Controller,{name:"highlightOnHover",control:e,render:({field:n})=>s.jsx(a.Switch,{label:"Highlight on hover",checked:n.value,onChange:r=>n.onChange(r.currentTarget.checked)})})]})]})}function Jw({columns:e,...t}){return{...t,columns:e.map(({id:n,...r})=>({id:n??oe.randomId(),...r}))}}function Zw({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=g.useMemo(()=>y.defaultsDeep({},t,Vo),[t]),i=g.useMemo(()=>Jw(r),[r]);g.useEffect(()=>{!y.isEqual(r,i)&&(console.log("config malformed, resetting to defaults",r,i),n(i))},[r,i]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=b.useForm({defaultValues:i});g.useEffect(()=>{d(i)},[i]);const h=c(),p=g.useMemo(()=>!y.isEqual(h,r),[h,r]);return u(["id_field"]),s.jsxs("form",{onSubmit:l(n),children:[s.jsxs(a.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Table Config"}),s.jsx(a.ActionIcon,{type:"submit","aria-label":"save config",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Tabs,{defaultValue:"Columns",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"Columns",children:"Columns"}),s.jsx(a.Tabs.Tab,{value:"Style",children:"Style"})]}),s.jsxs(a.Tabs.Panel,{value:"Columns",children:[s.jsx(b.Controller,{name:"id_field",control:o,render:({field:x})=>s.jsx(O,{label:"ID Field",required:!0,...x})}),s.jsx(a.Divider,{mt:20,mb:10,variant:"dashed"}),s.jsx(Yw,{control:o,watch:u})]}),s.jsx(a.Tabs.Panel,{value:"Style",children:s.jsx(Xw,{control:o,watch:u})})]})]})}function Hw(e){const{columns:t,...n}=e;return{...e,columns:t.map(r=>({...r,align:r.align??"left"}))}}function e0(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:i,columns:o,...l}=e;return{...l,id_field:r(i),columns:o.map(u=>({...u,value_field:r(u.value_field)}))}}catch(n){throw console.error("[Migration failed]",n),n}}function t0(e){const{columns:t,...n}=e;return{...n,columns:t.map(r=>({...r,align:r.align??"left",cellBackgroundColor:r.cellBackgroundColor??"",width:r.width??""}))}}class n0 extends ue{constructor(){super(...arguments);L(this,"VERSION",5)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{columns:r,...i}=n.config;return{...n,version:2,config:{...i,columns:r.map(({id:o,...l})=>({id:o??oe.randomId(),...l}))}}}),this.version(3,n=>({...n,version:3,config:Hw(n.config)})),this.version(4,(n,r)=>({...n,version:4,config:e0(n.config,r)})),this.version(5,n=>({...n,version:5,config:t0(n.config)}))}}const mr={createConfig(){return{version:5,config:y.cloneDeep(Vo)}},displayName:"Table",displayGroup:"Others",migrator:new n0,name:"table",viewRender:zw,configRender:Zw,triggers:[fr]},Ro=["function text({ data, variables, filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
307
- `),yr={func_content:Ro,horizontal_align:"left",font_size:"14px",font_weight:"normal"},s0=S.observer(({context:e})=>{const t=pe(),{value:n=yr}=$(e.instanceData,"config"),{variables:r}=e,i=e.data,{func_content:o,horizontal_align:l,font_size:u,font_weight:c}=n,d=g.useMemo(()=>r.reduce((p,x)=>{const m=it(x,i);return p[x.name]=Pe(x,m),p},{}),[r,i]),h=g.useMemo(()=>new Function(`return ${o}`)()({data:i,variables:d,filters:t.payloadForSQL.filters,context:t.payloadForSQL.context}),[o,i,d,t.payloadForSQL]);return s.jsx(a.Text,{align:l,weight:c,sx:{fontSize:u},children:h})}),Yn=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function r0({label:e,value:t,onChange:n},r){var l;const[i,o]=g.useState(((l=Yn.find(u=>u.label===t))==null?void 0:l.value)??Yn[0].value);return g.useEffect(()=>{const u=Yn.find(c=>c.value===i);u&&n(u.label)},[i]),s.jsxs(a.Stack,{spacing:0,mt:"sm",mb:"lg",children:[s.jsx(a.Text,{size:"sm",children:e}),s.jsx(a.Slider,{label:null,marks:Yn,value:i,onChange:o,step:25,placeholder:"Pick a font size",mx:"1em",ref:r})]})}const Qo=g.forwardRef(r0),i0=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return s.jsx(a.Box,{sx:{position:"relative"},children:s.jsx(ye,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},a0=g.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:i,setFalse:o}]=V.useBoolean(),[l,u]=g.useState(e),c=()=>{o(),t(l)},d=()=>{o(),u(e)},h=()=>{u(Ro)};return g.useEffect(()=>{u(e)},[e]),s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"filled",mt:24,onClick:i,sx:{flexGrow:0},children:"Edit Content"}),s.jsx(a.Modal,{size:800,title:"Text content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&s.jsxs(a.Stack,{children:[s.jsx(i0,{value:l,onChange:u}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:h,color:"red",leftIcon:s.jsx(k.Recycle,{size:20}),children:"Reset"}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:d,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:c,children:"OK"})]})]})]})})]})}),o0=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}];function l0({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=g.useMemo(()=>y.defaultsDeep({},t,yr),[t]),i=g.useMemo(()=>{const{func_content:x,horizontal_align:m,font_size:j,font_weight:C}=r;return{func_content:x,horizontal_align:m,font_size:j,font_weight:C}},[r]);g.useEffect(()=>{!y.isEqual(r,i)&&(console.log("config malformed, resetting to defaults",r,i),n(i))},[r,i]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=b.useForm({defaultValues:i});g.useEffect(()=>{d(i)},[i]),u(["func_content","horizontal_align","font_size","font_weight"]);const h=c(),p=g.useMemo(()=>!y.isEqual(h,r),[h,r]);return s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:l(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{weight:500,children:"Configurations"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Stack,{spacing:10,children:[s.jsx(b.Controller,{name:"func_content",control:o,render:({field:x})=>s.jsx(a0,{...x})}),s.jsx(a.Divider,{mt:10,mb:-10,variant:"dashed",label:"Style",labelPosition:"center"}),s.jsx(b.Controller,{name:"horizontal_align",control:o,render:({field:x})=>s.jsx(a.Select,{label:"Horizontal Alignment",data:o0,...x})}),s.jsx(b.Controller,{name:"font_size",control:o,render:({field:x})=>s.jsx(a.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1},...x})}),s.jsx(a.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:s.jsx(b.Controller,{name:"font_weight",control:o,render:({field:x})=>s.jsx(Qo,{label:"Font Weight",...x})})})]})]})})}class u0 extends ue{constructor(){super(...arguments);L(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const c0={displayName:"Text",displayGroup:"Others",migrator:new u0,name:"text",viewRender:s0,configRender:l0,createConfig(){return{version:1,config:y.cloneDeep(yr)}}},d0=()=>s.jsxs("svg",{width:"64",height:"64",viewBox:"0 0 64 64",fill:"none",children:[s.jsx("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"}),s.jsx("path",{d:"M18.39 32.28H16.51V35.02H18.39V32.28Z",fill:"#9399A5"}),s.jsx("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 Uo(e,t){const n=y.get(e,t,"");if(n)throw new Error(n)}async function p0(e,t,n,r={}){const i={"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:i};return o.data=r.string?JSON.stringify(n):n,nt(o).then(l=>l.data).catch(l=>Promise.reject(l))}const h0=({conf:e,panelData:t})=>async()=>{const{expertSystemURL:n,path:r,goal:i,question:o}=e;if(!r||!i||!o)return;const l=ld(t);if(!l)return;const u={dashboard:i,panel:o,data:l};try{const c=n.startsWith("http")?n:window.location.origin;return await p0(c,`/expert/v3/devtable/${r}`,u,{})}catch(c){throw Uo(c,"response.data.detail"),Uo(c,"response.data.error"),console.error(c),c}},br={expertSystemURL:"",path:"",goal:"",question:""},jr={height:"100%",overflowY:"auto",...Fs},Ko=({message:e})=>s.jsx(a.Box,{sx:jr,children:s.jsx("div",{dangerouslySetInnerHTML:{__html:e},style:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45"}})}),x0=({error:e,width:t,height:n})=>{const r=e.message;if(r.startsWith("<"))return s.jsx(Ko,{message:r});const o=n-25-20-30;return s.jsx(a.Center,{sx:{width:"100%",height:o},children:s.jsxs(a.Stack,{align:"center",spacing:20,children:[s.jsx(d0,{}),s.jsx(Ko,{message:r})]})})};function f0({context:e}){const{value:t}=$(e.instanceData,"config"),n=g.useMemo(()=>y.defaultsDeep({},t,br),[t]),{width:r,height:i}=e.viewport,o=e.data,{data:l,error:u,loading:c}=V.useRequest(h0({conf:n,panelData:o}),{refreshDeps:[o,n]});return!r||!i||!n?null:c?s.jsx(a.Box,{sx:{position:"relative",height:i},children:s.jsx(a.LoadingOverlay,{visible:!0})}):u?s.jsx(a.Box,{sx:jr,"data-enable-scrollbar":!0,children:s.jsx(x0,{error:u,width:r,height:i})}):!l||!Array.isArray(l.replies)||l.replies.length===0?null:s.jsx(a.Box,{sx:jr,"data-enable-scrollbar":!0,children:l.replies.map((d,h)=>s.jsx("div",{dangerouslySetInnerHTML:{__html:d.interpretation.html}},h))})}function g0({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=g.useMemo(()=>y.defaultsDeep({},t,br),[t]),{control:i,handleSubmit:o,watch:l,getValues:u,reset:c}=b.useForm({defaultValues:r});g.useEffect(()=>{c(r)},[r]),l(["expertSystemURL","goal","path","question"]);const d=u(),h=g.useMemo(()=>!y.isEqual(d,r),[d,r]);return s.jsx("form",{onSubmit:o(n),children:s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:"expertSystemURL",control:i,render:({field:p})=>s.jsx(a.TextInput,{label:"Expert System URL",...p})}),s.jsx(b.Controller,{name:"path",control:i,render:({field:p})=>s.jsx(a.TextInput,{label:"Path",required:!0,...p})})]}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:"goal",control:i,render:({field:p})=>s.jsx(a.TextInput,{label:"Goal",required:!0,...p})}),s.jsx(b.Controller,{name:"question",control:i,render:({field:p})=>s.jsx(a.TextInput,{label:"Question",required:!0,...p})})]}),s.jsx(a.Divider,{variant:"dashed",mt:16,mb:8}),s.jsx(a.Button,{type:"submit",variant:"filled",color:"blue",leftIcon:s.jsx(k.DeviceFloppy,{size:20}),disabled:!h,sx:{alignSelf:"flex-end"},children:"Submit Changes"})]})})}class m0 extends ue{constructor(){super(...arguments);L(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const y0={displayName:"Merico GQM",displayGroup:"Merico suite",migrator:new m0,name:"mericoGQM",viewRender:f0,configRender:g0,createConfig(){return{version:1,config:y.cloneDeep(br)}}};function b0(e,t,n){if(!e)return n[0];try{return[t,M(t).add(1,"year").subtract(1,"day").valueOf()]}catch(r){return console.error(r),n[0]}}function j0(e,t,n){const r=b0(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 v0(e){return{heat_block:function(r){if(!e.heat_block.value_formatter)return r;try{return W(r,e.heat_block.value_formatter)}catch(i){return console.error(i),r}}}}function w0(e,t){return{show:!e,selectedMode:"single",top:5,right:5,data:t.map(n=>({name:n,icon:"circle"}))}}function C0(e,t,n,r){const{calendar:i,heat_block:o}=e,l=z(i.data_key),u=z(o.data_key);return t?{type:"heatmap",name:"heatmap",coordinateSystem:"calendar",calendarIndex:0,data:r[l.queryID].map(c=>[y.get(c,l.columnKey),y.get(c,u.columnKey)])}:Object.entries(n).map(([c,d])=>({type:"heatmap",name:c,coordinateSystem:"calendar",calendarIndex:0,data:d.map(h=>[y.get(h,l.columnKey),y.get(h,u.columnKey)])}))}const S0=e=>W(e,{output:"number",trimMantissa:!0,mantissa:2,absolute:!1});function _0({conf:e,valueFormatters:t,dataDict:n,params:r}){const{value:i}=r,[o,l]=i,c=[{label:e.heat_block.name,value:t.heat_block(l),style:{label:"",value:""}}],d=n[o];return d&&e.tooltip.metrics.forEach(h=>{const p=z(h.data_key);c.push({label:h.name,value:S0(y.get(d,p.columnKey,"")),style:{label:"",value:""}})}),c}function k0(e,t,n){const r=z(e.calendar.data_key),i=y.keyBy(t[r.queryID],r.columnKey);return ne.getTooltip({formatter:function(o){const u=_0({conf:e,valueFormatters:n,dataDict:i,params:o}).map(h=>`
305
+ `}}function Uv(){return ee.getTooltip({trigger:"item",formatter:Qv()})}const Kv={tooltip:{show:!0},series:{type:"sunburst",radius:[0,"90%"],emphasis:{focus:"ancestor"}}};function Yv(e,t,n){n.reduce((o,l)=>{const c=st(l,t);return o[l.name]=Ae(l,c),o},{});const i={series:{data:Gv(e,t),levels:Rv(e)},tooltip:Uv()};return y.defaultsDeep({},i,Kv)}function Xv({context:e}){const{variables:t}=e,{value:n}=O(e.instanceData,"config"),r=g.useMemo(()=>y.defaults({},n,hr),[n]),i=e.data,{width:o,height:l}=e.viewport,c=g.useMemo(()=>Yv(r,i,t),[r,i,t]);return!o||!l?null:s.jsx(ke,{width:o,height:l,children:s.jsx(we,{echarts:be,option:c,style:Zt(o,l),notMerge:!0,theme:"merico-light"})})}function Jv({control:e,watch:t}){return t(["label_key","value_key","group_key"]),s.jsxs(a.Stack,{children:[s.jsx(b.Controller,{name:"label_key",control:e,render:({field:n})=>s.jsx(B,{label:"Label Key",required:!0,...n})}),s.jsx(b.Controller,{name:"value_key",control:e,render:({field:n})=>s.jsx(B,{label:"Value Key",required:!0,...n})}),s.jsx(b.Controller,{name:"group_key",control:e,render:({field:n})=>s.jsx(B,{label:"Group Key",clearable:!0,...n})})]})}const Zv=[{label:"Radial",value:"radial"},{label:"Tangential",value:"tangential"},{label:"None",value:"0"}],Hv=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],ew=({control:e,index:t,remove:n})=>s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`levels.${t}.r0`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Inside Radius",placeholder:"0%",...r})}),s.jsx(b.Controller,{name:`levels.${t}.r`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Outside Radius",placeholder:"50%",...r})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Label Style",labelPosition:"center"}),s.jsx(b.Controller,{name:`levels.${t}.label.show_label_tolerance`,control:e,render:({field:r})=>s.jsx(a.NumberInput,{label:"Hide label when its percentage is less than...",precision:4,step:5e-4,min:0,max:1,...r})}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`levels.${t}.label.rotate`,control:e,render:({field:r})=>s.jsx(a.Select,{label:"Rotate",data:Zv,...r})}),s.jsx(b.Controller,{name:`levels.${t}.label.align`,control:e,render:({field:r})=>s.jsx(a.Select,{label:"Align",data:Hv,...r})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`levels.${t}.label.position`,control:e,render:({field:r})=>s.jsx(ir,{label:"Position",...r})}),s.jsx(b.Controller,{name:`levels.${t}.label.padding`,control:e,render:({field:r})=>s.jsx(a.NumberInput,{label:"Padding",min:0,hideControls:!0,...r})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed"}),s.jsx(a.Button,{leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Level"})]}),tw=({control:e,watch:t})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"levels"}),o=t("levels"),l=n.map((p,x)=>({...p,...o[x]})),c=()=>r({id:Date.now().toString(),r0:"",r:"",label:{show_label_tolerance:.001,rotate:"0",align:"center",position:"inside",padding:0}}),u=t("levels.0.id"),[d,h]=g.useState(()=>u??null);return g.useEffect(()=>{u&&h(p=>p!==null?p:u)},[u]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(k.InfoCircle,{size:14,color:"#888"}),s.jsx(a.Text,{size:14,color:"#888",children:"Configure ring style on each level"})]}),s.jsx(a.Divider,{variant:"dashed",my:10}),s.jsxs(a.Tabs,{value:d,onTabChange:p=>h(p),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((p,x)=>s.jsx(a.Tabs.Tab,{value:p.id,children:x},p.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),l.map((p,x)=>s.jsx(a.Tabs.Panel,{value:p.id,children:s.jsx(ew,{control:e,index:x,remove:i},p.id)},p.id))]})]})};function nw({context:e}){const{value:t,set:n}=O(e.instanceData,"config"),r=g.useMemo(()=>y.defaultsDeep({},t,hr),[t]),i=g.useMemo(()=>y.clone(r),[r]),{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=b.useForm({defaultValues:i});g.useEffect(()=>{d(i)},[i]);const h=u(),p=g.useMemo(()=>!y.isEqual(h,r),[h,r]);c(["label_key","value_key","group_key","levels"]);const[x,m]=g.useState("Data");return s.jsx("form",{onSubmit:l(n),children:s.jsxs(a.Stack,{spacing:"xs",children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Sunburst Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Tabs,{value:x,onTabChange:m,orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"Data",children:"Data"}),s.jsx(a.Tabs.Tab,{value:"Levels",children:"Levels"})]}),s.jsx(a.Tabs.Panel,{value:"Data",children:s.jsx(Jv,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Levels",children:s.jsx(tw,{control:o,watch:c})})]})]})})}function sw(e){const{label_field:t,value_field:n,...r}=e;return{...r,label_key:t,value_key:n}}function rw(e){const{group_key:t="",...n}=e;return{...n,group_key:t}}function iw(e){const{levels:t=[],...n}=e;return{...n,levels:t}}function aw(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{label_key:i,value_key:o,group_key:l,...c}=e;return{...c,label_key:r(i),value_key:r(o),group_key:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class ow extends ae{constructor(){super(...arguments);P(this,"VERSION",5)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:sw(n.config)})),this.version(3,n=>({...n,version:3,config:rw(n.config)})),this.version(4,n=>({...n,version:4,config:iw(n.config)})),this.version(5,(n,r)=>({...n,version:5,config:aw(n.config,r)}))}}const lw={displayName:"Sunburst Chart",displayGroup:"ECharts-based charts",migrator:new ow,name:"sunburst",viewRender:Xv,configRender:nw,createConfig(){return{version:5,config:y.cloneDeep(hr)}}};var Qe=(e=>(e.string="string",e.number="number",e.eloc="eloc",e.percentage="percentage",e.custom="custom",e))(Qe||{});const Vo=["function text({ value }) {"," // your code goes here"," return value","}"].join(`
306
+ `),qo={columns:[],fontSize:"14px",highlightOnHover:!0,horizontalSpacing:"14px",id_field:"",striped:!0,use_raw_columns:!0,verticalSpacing:"14px"},No={left:"flex-start",center:"center",right:"flex-end"},cw=({header:e,cx:t})=>{const n=y.get(e.column.columnDef.meta,"align","left");return s.jsxs(a.Text,{className:t("table-head-cell",{"table-head-cell--sortable":e.column.getCanSort()}),onClick:e.column.getToggleSortingHandler(),align:n,sx:{justifyContent:No[n]},children:[e.isPlaceholder?null:Fe.flexRender(e.column.columnDef.header,e.getContext()),s.jsx(uw,{direction:e.column.getIsSorted()})]})},uw=({direction:e})=>{switch(e){case"asc":return s.jsx(_.IconArrowUp,{size:16});case"desc":return s.jsx(_.IconArrowDown,{size:"1em"});default:return null}},dw=a.createStyles(e=>({root:{overflow:"auto",position:"relative","& .table-head-cell":{display:"flex",flexFlow:"row nowrap",alignItems:"center",whiteSpace:"nowrap","&.table-head-cell--sortable":{cursor:"pointer",userSelect:"none"}},"&.table-highlight-on-hover tr":{transition:"background-color 0.2s","&:hover":{backgroundColor:e.colorScheme==="dark"?e.colors.dark[5]:e.colors.gray[0]}}},thead:{background:e.colorScheme==="dark"?e.colors.dark[7]:e.white,position:"sticky",top:24,transform:"translateY(-1px)",zIndex:10},info_bar:{position:"sticky",top:0,left:0,right:0,zIndex:10,background:"white"}})),pw={tableLayout:"fixed","thead, tbody":{tr:{"th, td":{padding:"2px 10px",div:{overflow:"hidden",textOverflow:"ellipsis"},"&:first-of-type":{paddingLeft:2,paddingRight:2}}}}},hw=a.createStyles((e,t)=>({content:{display:"flex",alignItems:"center",justifyContent:No[t.align],".table-cell-text":{whiteSpace:"nowrap",cursor:t.clickable?"pointer":"default",textDecoration:t.clickable?"underline":"none"}}}));function xw(e){return e?tt(e).oklch()[0]>.7?"black":"white":"inherit"}function fw(e){const t=e.tableCellContext.bgColor;return{backgroundColor:t,color:xw(t)}}function qt(e){const t=e.tableCellContext.isClickable(),n=hw({clickable:t,align:e.align});return s.jsx("div",{className:n.classes.content,style:{...fw(e)},children:s.jsx(a.Text,{className:"table-cell-text",onClick:e.tableCellContext.getClickHandler(),children:s.jsx("span",{title:e.children,children:e.children})})})}function gw(e){return s.jsx(qt,{...e,children:e.value})}function mw(e){const t=G(e.value,{output:"number",average:!0,mantissa:2,trimMantissa:!0,absolute:!1});return s.jsx(qt,{...e,children:t})}function yw(e){const t=G(e.value,{output:"number",mantissa:0,thousandSeparated:!0,absolute:!1});return s.jsx(qt,{...e,children:t})}function bw(e){const t=G(e.value,{output:"percent",mantissa:3,trimMantissa:!0,absolute:!1});return s.jsx(qt,{...e,children:t})}function jw(e){const t=e.value,n=e.func_content;if(!n)return s.jsx(qt,{...e,children:t});const r=new Function(`return ${n}`)()({value:t});return s.jsx(qt,{...e,children:r})}function vw(e){switch(e.type){case Qe.string:return s.jsx(gw,{...e});case Qe.eloc:return s.jsx(mw,{...e});case Qe.number:return s.jsx(yw,{...e});case Qe.percentage:return s.jsx(bw,{...e});case Qe.custom:return s.jsx(jw,{...e})}}function ww({tableContainerRef:e,rows:t}){var c,u;const n=hu.useVirtual({parentRef:e,size:t.length,estimateSize:g.useCallback(()=>28,[]),overscan:20}),{virtualItems:r,totalSize:i}=n,o=r.length>0&&((c=r==null?void 0:r[0])==null?void 0:c.start)||0,l=r.length>0?i-(((u=r==null?void 0:r[r.length-1])==null?void 0:u.end)||0):0;return $.useWhyDidYouUpdate("TableBody",{tableContainerRef:e,rows:t}),s.jsxs("tbody",{children:[o>0&&s.jsx("tr",{children:s.jsx("td",{style:{height:`${o}px`}})}),r.map(d=>{const h=t[d.index];return s.jsx("tr",{children:h.getVisibleCells().map(p=>s.jsx("td",{children:Fe.flexRender(p.column.columnDef.cell,p.getContext())},p.id))},h.id)}),l>0&&s.jsx("tr",{children:s.jsx("td",{style:{height:`${l}px`}})})]})}const xr={id:"builtin:table:click-cell-content",displayName:"Click Cell Content",nameRender:kw,configRender:Sw,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"}]},Cw={column:""};function Fo(e,t){const{value:n}=O(e.instanceData,"config"),r={columnsFromConfig:[],columnsFromData:[]};if(n&&(r.columnsFromConfig=n.columns.map((i,o)=>({label:i.label,value:o.toString()}))),!t)return r;if(n!=null&&n.id_field){const i=Xt(t,n.id_field);(i==null?void 0:i.length)>0&&(r.columnsFromData=Object.keys(i[0]).map(o=>({label:o,value:o})))}return r}function Sw(e){const{columnsFromConfig:t,columnsFromData:n}=Fo(e.instance,e.sampleData),r=t.length>0?t:n,{value:i,set:o}=O(e.trigger.triggerData,"config"),{column:l}=y.defaults({},i,Cw),c=u=>{isNaN(+u)?o({column:u}):o({column:+u})};return s.jsx(a.Select,{clearable:!1,data:r,label:"Choose a column",value:l.toString(),onChange:c})}function _w(e,t){return e?y.isNumber(e.column)?`Click cell of ${t[e.column].label}`:`Click cell of ${e.column}`:"Click cell content (click to config)"}function kw(e){const{columnsFromConfig:t}=Fo(e.instance),{value:n}=O(e.trigger.triggerData,"config");return s.jsx(a.Text,{children:_w(n,t)})}function Go(e,t,n){return Math.min(Math.max(e,t),n)}class Tw{constructor(t){this.steps=t;const n=[],r=new Set;for(const i of t)r.has(i.to)||(n.push(i),r.add(i.to));if(n.sort((i,o)=>i.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),i=t.to-r*t.from;return o=>r*o+i}getStepFunctionForValue(t){let n=y.findLastIndex(this.steps,r=>r.from<=t);return n=Go(n,0,this.steps.length-2),this.getLinearFunction(this.steps[n],this.steps[n+1])}mapValue(t){return Go(this.getStepFunctionForValue(t)(t),0,100)}}class Dw{constructor(t,n,r,i,o){this.getColIndex=t,this.cell=n,this.triggers=r,this.interactionManager=i,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===xr.id).filter(n=>{const r=this.getColIndex(this.cell),i=y.get(this.cell.column.columnDef.meta,"value_field"),o=y.get(n.config,"column");return o==r||o==i})}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(y.isString(t))return t;const n=+this.cell.getValue();if(isFinite(n)){const r=this.colorManager.decodeInterpolation(t.interpolation),o=new Tw(t.steps).mapValue(n);return r==null?void 0:r.getColor(o)}}}const Iw=e=>{const t=$e(e),n=Oe(t.triggerManager,xr.id),{colorManager:r}=g.useContext(Ze);return g.useCallback(i=>new Dw(e.getColIndex,i,n,t,r),[n,t,e.getColIndex])};function Mw({queryData:e,width:t,height:n,conf:r,context:i,instance:o}){const{id_field:l,use_raw_columns:c,columns:u,...d}=r,{classes:h,cx:p}=dw(),x=g.useMemo(()=>c?!Array.isArray(e)||e.length===0?[]:Object.keys(e[0]).map(se=>({id:se,label:se,value_field:se,value_type:Qe.string,align:"left",width:"",cellBackgroundColor:""})):u,[c,u,e]),m=Iw({getColIndex:g.useCallback(se=>x.indexOf(se.column.columnDef.meta),[x]),vizManager:i.vizManager,instance:o}),j=g.useMemo(()=>{const se=Fe.createColumnHelper();return x.map(Ue=>{const yi=ld(Ue.value_field);return se.accessor(yi.columnKey,{cell:dn=>s.jsx(vw,{tableCellContext:m(dn.cell),value:dn.getValue(),type:Ue.value_type,...Ue}),header:Ue.label,enableSorting:!0,meta:Ue,size:typeof Ue.width=="number"?Ue.width:void 0,minSize:typeof Ue.width=="number"?Ue.width:void 0})})},[x,m]),[C,T]=g.useState([]),D=Fe.useReactTable({data:e,state:{sorting:C},onSortingChange:T,columns:j,getCoreRowModel:Fe.getCoreRowModel(),getSortedRowModel:Fe.getSortedRowModel()}),{rows:A}=D.getRowModel(),N=g.useRef(null),Y=A.length,R=Y>0,F=R?n-22:n,Z=R?22:0;return $.useWhyDidYouUpdate("VizTableComponent",{queryData:e,width:t,height:n,conf:r,context:i,instance:o,finalColumns:x,getCellContext:m,tableColumns:j,table:D,rows:A,tableContainerRef:N}),s.jsxs("div",{ref:N,style:{height:n,width:t,padding:"0 5px"},"data-enable-scrollbar":!0,className:p(h.root,{"table-highlight-on-hover":r.highlightOnHover}),children:[Y>0&&s.jsx(a.Box,{className:h.info_bar,sx:{height:22},children:s.jsxs(a.Text,{align:"right",pr:6,size:14,color:"dimmed",fw:"normal",children:["Total: ",Y]})}),s.jsxs(a.Table,{sx:{...pw,maxHeight:F},...d,striped:r.striped,children:[s.jsx("thead",{className:h.thead,style:{top:Z},children:D.getHeaderGroups().map(se=>s.jsx("tr",{children:se.headers.map(Tt=>s.jsx("th",{style:{width:Tt.getSize()},children:s.jsx(cw,{header:Tt,cx:p})},Tt.id))},se.id))}),s.jsx(ww,{tableContainerRef:N,rows:A})]})]})}function zw({data:e,width:t,height:n,conf:r,context:i,instance:o}){const{id_field:l,use_raw_columns:c,columns:u}=r,d=g.useMemo(()=>{if(!l)return[];const h=z(l);return e[h.queryID]},[e,l]);return!Array.isArray(d)||d.length===0?s.jsx(a.Text,{color:"gray",align:"center",children:"Empty Data"}):s.jsx(Mw,{queryData:d,width:t,height:n,conf:r,context:i,instance:o})}function Aw({context:e,instance:t}){const n=e.data,{height:r,width:i}=e.viewport,{value:o}=O(e.instanceData,"config");return o?o.id_field?s.jsx(zw,{data:n,width:i,height:r,conf:o,context:e,instance:t}):s.jsx(a.Text,{color:"red",align:"center",children:"ID Field is not set, can't render a table without it"}):null}const Wo=a.createStyles(()=>({palette:{display:"flex",flexFlow:"row nowrap"},paletteItem:{".palette-value":{height:24,overflow:"visible",width:36},".palette-item":{width:"36px",height:36*.618,cursor:"pointer",transition:"transform 100ms ease-in-out","&:hover":{boxShadow:"0 0 0 2px var(--shadow-color)",borderRadius:2,transform:"scale(1.2)"}}}})),Ew=[{from:0,to:0},{from:100,to:100}];class Pw{constructor(){P(this,"steps",new Map);P(this,"interpolation");P(this,"onChange");U.makeAutoObservable(this,{steps:U.observable},{deep:!1}),U.reaction(()=>U.toJS(this.steps),()=>{this.notifyStepChange()})}setSteps(t){for(const n of t)this.steps.set(n.to,n.from)}notifyStepChange(){var t;(t=this.onChange)==null||t.call(this,Array.from(this.steps.entries()).map(([n,r])=>({to:n,from:r})).sort((n,r)=>n.to-r.to||n.from-r.from))}fromProps(t){t.steps.length<2?this.setSteps(Ew):this.setSteps(t.steps),this.interpolation=t.interpolation,this.onChange=t.onChange}changeStep(t,n){t==null?this.steps.delete(n):this.steps.set(n,t)}getStepFromValue(t){return this.steps.get(t)}}function Lw(e){const{onChange:t,color:n,index:r,value:i}=e,{classes:o}=Wo(),[l,c]=g.useState(i),[u,{setTrue:d,setFalse:h}]=$.useBoolean(!1),p=r%2===1,x=p&&i!=null,m=!p&&i!=null,j=`map ${i} to color ${r}`,C=()=>{c(i),h()},T=()=>{h(),t==null||t(l)},D=G(i??null,{output:"number",mantissa:0,average:!0,absolute:!1});return s.jsxs("div",{"data-testid":`palette-item-${r}`,className:o.paletteItem,children:[s.jsx(a.Text,{title:j,style:{opacity:x?1:0},color:"dimmed",size:"sm",className:"palette-value--up palette-value",children:D}),s.jsxs(a.Popover,{width:200,trapFocus:!0,opened:u,onClose:h,children:[s.jsx(a.Popover.Target,{children:s.jsx("div",{"data-testid":"palette-item-target",className:"palette-item",onClick:d,style:{"--shadow-color":tt(n).alpha(.5).hex(),backgroundColor:n}})}),s.jsx(a.Popover.Dropdown,{children:s.jsxs(a.Stack,{children:[s.jsx(a.NumberInput,{size:"xs",label:"Map a value to this color",value:l,onChange:c}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{variant:"subtle",size:"xs",onClick:C,children:"Cancel"}),s.jsx(a.Button,{"data-testid":"palette-item-ok",size:"xs",onClick:T,children:"OK"})]})]})})]}),s.jsx(a.Text,{title:j,style:{opacity:m?1:0},color:"dimmed",size:"sm",className:"palette-value--bottom palette-value",children:D})]})}const Bw=S.observer(({model:e})=>{const{classes:t}=Wo(),n=y.range(0,13,1).map(r=>100/12*r).map(r=>[e.interpolation.getColor(r),r]);return s.jsx("div",{className:t.palette,children:n.map(([r,i],o)=>s.jsx(Lw,{index:o,color:r,value:e.getStepFromValue(i),onChange:l=>e.changeStep(l,i)},r))})}),Ow=S.observer(function(t){const n=$.useCreation(()=>new Pw,[]);return g.useEffect(()=>{n.fromProps(t)}),n.interpolation==null?null:s.jsx(Bw,{model:n})}),$w=e=>{const{value:t,onChange:n,colorManager:r}=e,i=r.getColorInterpolations(),[o,l]=g.useState(t),c=r.decodeInterpolation(o.interpolation)||i[0],[u,{setTrue:d,setFalse:h}]=$.useBoolean(),p=i.map(T=>({label:T.displayName,value:r.encodeColor(T),group:T.category}));function x(T){T&&l(D=>({...D,interpolation:T}))}const m=()=>{h(),n==null||n(U.toJS(o))};function j(T){l(D=>({...D,steps:T}))}const C=()=>{h(),l(t)};return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"outline",onClick:d,children:c==null?void 0:c.displayName}),s.jsx(a.Modal,{size:508,title:"Setup color interpolation",opened:u,onClose:h,zIndex:320,children:u&&s.jsxs(a.Stack,{"data-testid":"color-interpolation-modal",children:[s.jsx(a.Select,{label:"Color style",value:o.interpolation,data:p,onChange:x,withinPortal:!0,zIndex:340,maxDropdownHeight:500}),s.jsx(Ow,{steps:o.steps,interpolation:c,onChange:j}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:C,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:m,children:"OK"})]})]})})]})},Vw=["static","interpolation","none"].map(e=>({label:y.capitalize(e),value:e})),qw=[{from:0,to:0},{from:100,to:100}];function Ro(e){return e?y.isString(e)?e==="none"?"none":"static":"interpolation":"none"}function Nw(e,t){var n;return Ro(t)==="static"?t:(n=e.getStaticColors()[0])==null?void 0:n.value}function Fw(e,t){return y.isObject(t)?t:{steps:qw,interpolation:e.encodeColor(e.getColorInterpolations()[0])}}const Gw=g.forwardRef((e,t)=>{const{colorManager:n}=g.useContext(Ze),[r,i]=g.useState(Ro(e.value)),[o,l]=g.useState(Nw(n,e.value)),c=$.useLatest(o),[u,d]=g.useState(Fw(n,e.value)),h=$.useLatest(u),p=j=>{var C,T,D;i(j||"none"),j==="static"?(C=e.onChange)==null||C.call(e,c.current):j==="none"||!j?(T=e.onChange)==null||T.call(e,"none"):(D=e.onChange)==null||D.call(e,h.current)},x=j=>{var C;l(j),(C=e.onChange)==null||C.call(e,j)},m=j=>{var C;d(j),(C=e.onChange)==null||C.call(e,j)};return s.jsxs(a.Stack,{align:"stretch",children:[s.jsx(a.Select,{label:"Cell background",value:r||"none",onChange:p,data:Vw}),r==="static"&&s.jsx(Ce,{value:o,onChange:x}),r==="interpolation"&&s.jsx($w,{colorManager:n,value:u,onChange:m})]})}),Ww={[Qe.eloc]:"ELOC"},Rw=Object.values(Qe).map(e=>({label:y.get(Ww,e,y.capitalize(e)),value:e})),Qw=g.forwardRef(({label:e,value:t,onChange:n,sx:r},i)=>s.jsx(a.Select,{ref:i,label:e,data:Rw,value:t,onChange:n,sx:r})),Uw=g.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:i,setFalse:o}]=$.useBoolean(),[l,c]=g.useState(e),u=()=>{o(),t(l)},d=()=>{o(),c(e)},h=()=>{c(Vo)};return g.useEffect(()=>{c(e)},[e]),s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"filled",mt:24,onClick:i,sx:{flexGrow:0},children:"Custom Cell Content"}),s.jsx(a.Modal,{size:800,title:"Custom cell content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&s.jsxs(a.Stack,{children:[s.jsx(a.Box,{sx:{position:"relative"},children:s.jsx(fe,{height:"500px",defaultLanguage:"javascript",value:l,onChange:p=>c(p??""),theme:"vs-dark",options:{minimap:{enabled:!1}}})}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:h,color:"red",leftIcon:s.jsx(k.Recycle,{size:20}),children:"Reset"}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:d,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:u,children:"OK"})]})]})]})})]})}),Kw=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],fr=()=>s.jsx(a.Text,{color:"dimmed",size:12,children:"px"}),Yw=({control:e,index:t,watch:n,remove:r,column:i})=>{const o=n(`columns.${t}.value_type`);return s.jsxs(a.Stack,{my:0,sx:{position:"relative"},children:[s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:`columns.${t}.label`,control:e,render:({field:l})=>s.jsx(a.TextInput,{label:"Label",required:!0,id:`col-label-${t}`,sx:{flex:1},...l})}),s.jsx(b.Controller,{name:`columns.${t}.value_field`,control:e,render:({field:l})=>s.jsx(B,{label:"Value Field",required:!0,...l})})]}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:`columns.${t}.value_type`,control:e,render:({field:l})=>s.jsx(Qw,{label:"Value Type",sx:{flex:1},...l})}),o===Qe.custom&&s.jsx(b.Controller,{name:`columns.${t}.func_content`,control:e,render:({field:l})=>s.jsx(Uw,{value:l.value??Vo,onChange:c=>l.onChange(c??"")})})]}),s.jsx(a.Divider,{mb:-10,variant:"dashed",label:"Style",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(a.NumberInput,{hideControls:!0,label:"Min Width",rightSection:s.jsx(fr,{}),disabled:!0}),s.jsx(b.Controller,{name:`columns.${t}.width`,control:e,render:({field:l})=>s.jsx(a.NumberInput,{hideControls:!0,label:"Width",rightSection:s.jsx(fr,{}),...l})}),s.jsx(a.NumberInput,{hideControls:!0,label:"Max Width",rightSection:s.jsx(fr,{}),disabled:!0})]}),s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:`columns.${t}.align`,control:e,render:({field:l})=>s.jsx(a.Select,{label:"Alignment",data:Kw,...l})})}),s.jsx(b.Controller,{name:`columns.${t}.cellBackgroundColor`,control:e,render:({field:l})=>s.jsx(Gw,{...l})}),s.jsx(a.Divider,{mb:4,mt:12,variant:"dashed"}),s.jsx(a.Button,{leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(t),children:"Delete this column"})]})},Xw=({control:e,watch:t})=>{const{fields:n,append:r,remove:i,update:o}=b.useFieldArray({control:e,name:"columns"}),l=()=>{const u=re.randomId();r({id:u,label:u,align:"center",value_field:"",value_type:Qe.string,width:""})};t("columns");const c=t("use_raw_columns");return s.jsxs(s.Fragment,{children:[s.jsx(b.Controller,{name:"use_raw_columns",control:e,render:({field:u})=>s.jsx(a.Switch,{mt:20,mb:20,label:"Use Original Data Columns",checked:u.value,onChange:d=>u.onChange(d.currentTarget.checked)})}),!c&&s.jsx(a.Stack,{children:s.jsxs(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[n.map((u,d)=>s.jsx(a.Tabs.Tab,{value:d.toString(),children:d+1},u.id)),s.jsx(a.Tabs.Tab,{onClick:l,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),n.map((u,d)=>s.jsx(a.Tabs.Panel,{value:d.toString(),children:s.jsx(Yw,{control:e,watch:t,index:d,column:u,remove:i})},u.id))]})})]})};function Jw({control:e,watch:t}){return t(["horizontalSpacing","verticalSpacing","fontSize","striped","highlightOnHover"]),s.jsxs(a.Stack,{spacing:"xs",children:[s.jsxs(a.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:[s.jsx(b.Controller,{name:"horizontalSpacing",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"Horizontal Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"verticalSpacing",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"Vertical Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})})]}),s.jsx(a.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:s.jsx(b.Controller,{name:"fontSize",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})})}),s.jsxs(a.Group,{position:"apart",grow:!0,children:[s.jsx(b.Controller,{name:"striped",control:e,render:({field:n})=>s.jsx(a.Switch,{label:"Striped",checked:n.value,onChange:r=>n.onChange(r.currentTarget.checked)})}),s.jsx(b.Controller,{name:"highlightOnHover",control:e,render:({field:n})=>s.jsx(a.Switch,{label:"Highlight on hover",checked:n.value,onChange:r=>n.onChange(r.currentTarget.checked)})})]})]})}function Zw({columns:e,...t}){return{...t,columns:e.map(({id:n,...r})=>({id:n??re.randomId(),...r}))}}function Hw({context:e}){const{value:t,set:n}=O(e.instanceData,"config"),r=g.useMemo(()=>y.defaultsDeep({},t,qo),[t]),i=g.useMemo(()=>Zw(r),[r]);g.useEffect(()=>{!y.isEqual(r,i)&&(console.log("config malformed, resetting to defaults",r,i),n(i))},[r,i]);const{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=b.useForm({defaultValues:i});g.useEffect(()=>{d(i)},[i]);const h=u(),p=g.useMemo(()=>!y.isEqual(h,r),[h,r]);return c(["id_field"]),s.jsxs("form",{onSubmit:l(n),children:[s.jsxs(a.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Table Config"}),s.jsx(a.ActionIcon,{type:"submit","aria-label":"save config",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Tabs,{defaultValue:"Columns",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"Columns",children:"Columns"}),s.jsx(a.Tabs.Tab,{value:"Style",children:"Style"})]}),s.jsxs(a.Tabs.Panel,{value:"Columns",children:[s.jsx(b.Controller,{name:"id_field",control:o,render:({field:x})=>s.jsx(B,{label:"ID Field",required:!0,...x})}),s.jsx(a.Divider,{mt:20,mb:10,variant:"dashed"}),s.jsx(Xw,{control:o,watch:c})]}),s.jsx(a.Tabs.Panel,{value:"Style",children:s.jsx(Jw,{control:o,watch:c})})]})]})}function e0(e){const{columns:t,...n}=e;return{...e,columns:t.map(r=>({...r,align:r.align??"left"}))}}function t0(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}`,{id_field:i,columns:o,...l}=e;return{...l,id_field:r(i),columns:o.map(c=>({...c,value_field:r(c.value_field)}))}}catch(n){throw console.error("[Migration failed]",n),n}}function n0(e){const{columns:t,...n}=e;return{...n,columns:t.map(r=>({...r,align:r.align??"left",cellBackgroundColor:r.cellBackgroundColor??"",width:r.width??""}))}}class s0 extends ae{constructor(){super(...arguments);P(this,"VERSION",5)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{columns:r,...i}=n.config;return{...n,version:2,config:{...i,columns:r.map(({id:o,...l})=>({id:o??re.randomId(),...l}))}}}),this.version(3,n=>({...n,version:3,config:e0(n.config)})),this.version(4,(n,r)=>({...n,version:4,config:t0(n.config,r)})),this.version(5,n=>({...n,version:5,config:n0(n.config)}))}}const gr={createConfig(){return{version:5,config:y.cloneDeep(qo)}},displayName:"Table",displayGroup:"Others",migrator:new s0,name:"table",viewRender:Aw,configRender:Hw,triggers:[xr]},Qo=["function text({ data, variables, filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
307
+ `),mr={func_content:Qo,horizontal_align:"left",font_size:"14px",font_weight:"normal"},r0=S.observer(({context:e})=>{const t=ce(),{value:n=mr}=O(e.instanceData,"config"),{variables:r}=e,i=e.data,{func_content:o,horizontal_align:l,font_size:c,font_weight:u}=n,d=g.useMemo(()=>r.reduce((p,x)=>{const m=st(x,i);return p[x.name]=Ae(x,m),p},{}),[r,i]),h=g.useMemo(()=>new Function(`return ${o}`)()({data:i,variables:d,filters:t.payloadForSQL.filters,context:t.payloadForSQL.context}),[o,i,d,t.payloadForSQL]);return s.jsx(a.Text,{align:l,weight:u,sx:{fontSize:c},children:h})}),Kn=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function i0({label:e,value:t,onChange:n},r){var l;const[i,o]=g.useState(((l=Kn.find(c=>c.label===t))==null?void 0:l.value)??Kn[0].value);return g.useEffect(()=>{const c=Kn.find(u=>u.value===i);c&&n(c.label)},[i]),s.jsxs(a.Stack,{spacing:0,mt:"sm",mb:"lg",children:[s.jsx(a.Text,{size:"sm",children:e}),s.jsx(a.Slider,{label:null,marks:Kn,value:i,onChange:o,step:25,placeholder:"Pick a font size",mx:"1em",ref:r})]})}const Uo=g.forwardRef(i0),a0=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return s.jsx(a.Box,{sx:{position:"relative"},children:s.jsx(fe,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},o0=g.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:i,setFalse:o}]=$.useBoolean(),[l,c]=g.useState(e),u=()=>{o(),t(l)},d=()=>{o(),c(e)},h=()=>{c(Qo)};return g.useEffect(()=>{c(e)},[e]),s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"filled",mt:24,onClick:i,sx:{flexGrow:0},children:"Edit Content"}),s.jsx(a.Modal,{size:800,title:"Text content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&s.jsxs(a.Stack,{children:[s.jsx(a0,{value:l,onChange:c}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:h,color:"red",leftIcon:s.jsx(k.Recycle,{size:20}),children:"Reset"}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:d,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:u,children:"OK"})]})]})]})})]})}),l0=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}];function c0({context:e}){const{value:t,set:n}=O(e.instanceData,"config"),r=g.useMemo(()=>y.defaultsDeep({},t,mr),[t]),i=g.useMemo(()=>{const{func_content:x,horizontal_align:m,font_size:j,font_weight:C}=r;return{func_content:x,horizontal_align:m,font_size:j,font_weight:C}},[r]);g.useEffect(()=>{!y.isEqual(r,i)&&(console.log("config malformed, resetting to defaults",r,i),n(i))},[r,i]);const{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=b.useForm({defaultValues:i});g.useEffect(()=>{d(i)},[i]),c(["func_content","horizontal_align","font_size","font_weight"]);const h=u(),p=g.useMemo(()=>!y.isEqual(h,r),[h,r]);return s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:l(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{weight:500,children:"Configurations"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Stack,{spacing:10,children:[s.jsx(b.Controller,{name:"func_content",control:o,render:({field:x})=>s.jsx(o0,{...x})}),s.jsx(a.Divider,{mt:10,mb:-10,variant:"dashed",label:"Style",labelPosition:"center"}),s.jsx(b.Controller,{name:"horizontal_align",control:o,render:({field:x})=>s.jsx(a.Select,{label:"Horizontal Alignment",data:l0,...x})}),s.jsx(b.Controller,{name:"font_size",control:o,render:({field:x})=>s.jsx(a.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1},...x})}),s.jsx(a.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:s.jsx(b.Controller,{name:"font_weight",control:o,render:({field:x})=>s.jsx(Uo,{label:"Font Weight",...x})})})]})]})})}class u0 extends ae{constructor(){super(...arguments);P(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const d0={displayName:"Text",displayGroup:"Others",migrator:new u0,name:"text",viewRender:r0,configRender:c0,createConfig(){return{version:1,config:y.cloneDeep(mr)}}},p0=()=>s.jsxs("svg",{width:"64",height:"64",viewBox:"0 0 64 64",fill:"none",children:[s.jsx("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"}),s.jsx("path",{d:"M18.39 32.28H16.51V35.02H18.39V32.28Z",fill:"#9399A5"}),s.jsx("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 Ko(e,t){const n=y.get(e,t,"");if(n)throw new Error(n)}async function h0(e,t,n,r={}){const i={"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:i};return o.data=r.string?JSON.stringify(n):n,He(o).then(l=>l.data).catch(l=>Promise.reject(l))}const x0=({conf:e,panelData:t})=>async()=>{const{expertSystemURL:n,path:r,goal:i,question:o}=e;if(!r||!i||!o)return;const l=cd(t);if(!l)return;const c={dashboard:i,panel:o,data:l};try{const u=n.startsWith("http")?n:window.location.origin;return await h0(u,`/expert/v3/devtable/${r}`,c,{})}catch(u){throw Ko(u,"response.data.detail"),Ko(u,"response.data.error"),console.error(u),u}},yr={expertSystemURL:"",path:"",goal:"",question:""},br={height:"100%",overflowY:"auto",...Ns},Yo=({message:e})=>s.jsx(a.Box,{sx:br,children:s.jsx("div",{dangerouslySetInnerHTML:{__html:e},style:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45"}})}),f0=({error:e,width:t,height:n})=>{const r=e.message;if(r.startsWith("<"))return s.jsx(Yo,{message:r});const o=n-25-20-30;return s.jsx(a.Center,{sx:{width:"100%",height:o},children:s.jsxs(a.Stack,{align:"center",spacing:20,children:[s.jsx(p0,{}),s.jsx(Yo,{message:r})]})})};function g0({context:e}){const{value:t}=O(e.instanceData,"config"),n=g.useMemo(()=>y.defaultsDeep({},t,yr),[t]),{width:r,height:i}=e.viewport,o=e.data,{data:l,error:c,loading:u}=$.useRequest(x0({conf:n,panelData:o}),{refreshDeps:[o,n]});return!r||!i||!n?null:u?s.jsx(a.Box,{sx:{position:"relative",height:i},children:s.jsx(a.LoadingOverlay,{visible:!0})}):c?s.jsx(a.Box,{sx:br,"data-enable-scrollbar":!0,children:s.jsx(f0,{error:c,width:r,height:i})}):!l||!Array.isArray(l.replies)||l.replies.length===0?null:s.jsx(a.Box,{sx:br,"data-enable-scrollbar":!0,children:l.replies.map((d,h)=>s.jsx("div",{dangerouslySetInnerHTML:{__html:d.interpretation.html}},h))})}function m0({context:e}){const{value:t,set:n}=O(e.instanceData,"config"),r=g.useMemo(()=>y.defaultsDeep({},t,yr),[t]),{control:i,handleSubmit:o,watch:l,getValues:c,reset:u}=b.useForm({defaultValues:r});g.useEffect(()=>{u(r)},[r]),l(["expertSystemURL","goal","path","question"]);const d=c(),h=g.useMemo(()=>!y.isEqual(d,r),[d,r]);return s.jsx("form",{onSubmit:o(n),children:s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:"expertSystemURL",control:i,render:({field:p})=>s.jsx(a.TextInput,{label:"Expert System URL",...p})}),s.jsx(b.Controller,{name:"path",control:i,render:({field:p})=>s.jsx(a.TextInput,{label:"Path",required:!0,...p})})]}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:"goal",control:i,render:({field:p})=>s.jsx(a.TextInput,{label:"Goal",required:!0,...p})}),s.jsx(b.Controller,{name:"question",control:i,render:({field:p})=>s.jsx(a.TextInput,{label:"Question",required:!0,...p})})]}),s.jsx(a.Divider,{variant:"dashed",mt:16,mb:8}),s.jsx(a.Button,{type:"submit",variant:"filled",color:"blue",leftIcon:s.jsx(k.DeviceFloppy,{size:20}),disabled:!h,sx:{alignSelf:"flex-end"},children:"Submit Changes"})]})})}class y0 extends ae{constructor(){super(...arguments);P(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const b0={displayName:"Merico GQM",displayGroup:"Merico suite",migrator:new y0,name:"mericoGQM",viewRender:g0,configRender:m0,createConfig(){return{version:1,config:y.cloneDeep(yr)}}};function j0(e,t,n){if(!e)return n[0];try{return[t,M(t).add(1,"year").subtract(1,"day").valueOf()]}catch(r){return console.error(r),n[0]}}function v0(e,t,n){const r=j0(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 w0(e){return{heat_block:function(r){if(!e.heat_block.value_formatter)return r;try{return G(r,e.heat_block.value_formatter)}catch(i){return console.error(i),r}}}}function C0(e,t){return{show:!e,selectedMode:"single",top:5,right:5,data:t.map(n=>({name:n,icon:"circle"}))}}function S0(e,t,n,r){const{calendar:i,heat_block:o}=e,l=z(i.data_key),c=z(o.data_key);return t?{type:"heatmap",name:"heatmap",coordinateSystem:"calendar",calendarIndex:0,data:r[l.queryID].map(u=>[y.get(u,l.columnKey),y.get(u,c.columnKey)])}:Object.entries(n).map(([u,d])=>({type:"heatmap",name:u,coordinateSystem:"calendar",calendarIndex:0,data:d.map(h=>[y.get(h,l.columnKey),y.get(h,c.columnKey)])}))}const _0=e=>G(e,{output:"number",trimMantissa:!0,mantissa:2,absolute:!1});function k0({conf:e,valueFormatters:t,dataDict:n,params:r}){const{value:i}=r,[o,l]=i,u=[{label:e.heat_block.name,value:t.heat_block(l),style:{label:"",value:""}}],d=n[o];return d&&e.tooltip.metrics.forEach(h=>{const p=z(h.data_key);u.push({label:h.name,value:_0(y.get(d,p.columnKey,"")),style:{label:"",value:""}})}),u}function T0(e,t,n){const r=z(e.calendar.data_key),i=y.keyBy(t[r.queryID],r.columnKey);return ee.getTooltip({formatter:function(o){const c=k0({conf:e,valueFormatters:n,dataDict:i,params:o}).map(h=>`
308
308
  <tr>
309
309
  <th style="text-align: right;">
310
310
  <div style="${h.style.label}">${h.label}</div>
@@ -313,7 +313,7 @@ Check the top-level render call using <`+E+">.")}return I}}function rc(w,I){{if(
313
313
  <div style="${h.style.value}">${h.value}
314
314
  </td>
315
315
  </tr>
316
- `),c=y.get(o.value,0);return`
316
+ `),u=y.get(o.value,0);return`
317
317
  <table style="width: auto">
318
318
  <thead>
319
319
  <tr colspan="2">
@@ -324,28 +324,28 @@ Check the top-level render call using <`+E+">.")}return I}}function rc(w,I){{if(
324
324
  </tr>
325
325
  <tr>
326
326
  <th colspan="2" style="text-align: center;">
327
- <div>${c}</div>
327
+ <div>${u}</div>
328
328
  </th>
329
329
  </tr>
330
330
  </thead>
331
- <tbody>${u.join("")}</tbody>
331
+ <tbody>${c.join("")}</tbody>
332
332
  </table>
333
- `}})}function T0(e,t,n){const r=qt(e.heat_block.min,n),i=qt(e.heat_block.max,n);return{min:r,max:i,calculable:!0,orient:"horizontal",left:t?"center":5,top:0,itemWidth:15}}const D0={grid:{containLabel:!0}},I0=e=>M(e).get("year");function M0(e,t){const n=z(e.calendar.data_key),r=t[n.queryID],i=y.groupBy(r,d=>I0(d[n.columnKey])),o=Object.keys(i),l=r.map(d=>M(d[n.columnKey]).valueOf()),u=y.min(l),c=y.max(l);return{minDate:u??0,maxDate:c??0,dateSpan:M(c).diff(u,"day"),dataByYear:i,years:o}}function z0(e,t,n){const r=n.reduce((p,x)=>{const m=it(x,t);return p[x.name]=Pe(x,m),p},{}),i=v0(e),{dateSpan:o,minDate:l,dataByYear:u,years:c}=M0(e,t),d=o<=366,h={calendar:j0(d,l,c),series:C0(e,d,u,t),tooltip:k0(e,t,i),visualMap:T0(e,d,r),legend:w0(d,c)};return y.defaultsDeep({},h,D0)}function A0(e){return s.jsx(s.Fragment,{})}function E0(e){return s.jsx(a.Text,{children:"Click heat block"})}const Yo={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:E0,configRender:A0,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"}]},vr={calendar:{data_key:"",locale:"EN"},heat_block:{min:{type:"static",value:0},max:{type:"static",value:100},name:"Value",data_key:"",value_formatter:je},tooltip:{metrics:[]}};J.use([B.DataZoomComponent,ie.BarChart,ie.LineChart,ie.HeatmapChart,B.CalendarComponent,B.GridComponent,B.LegendComponent,B.TooltipComponent,B.VisualMapComponent,_e.CanvasRenderer]);function L0({name:e},t){const n=t.getOption();n.calendar.forEach(r=>{r.range=e}),t.setOption(n)}function P0({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const l=vt(t,e.calendar.data_key),u=qe(i.triggerManager,Yo.id),c=g.useCallback(p=>{const[x,m]=p.value,j=y.get(l,x,{error:"rowData is not found"});u.forEach(C=>{i.runInteraction(C.id,{...p,rowData:j})})},[l,u,i]),d=g.useMemo(()=>({click:c,legendselectchanged:L0}),[c]),h=g.useMemo(()=>z0(e,t,o),[e,t]);return s.jsx(Se,{echarts:J,option:h,style:{width:n,height:r},onEvents:d,notMerge:!0,opts:{locale:e.calendar.locale},theme:"merico-light"})}function B0({context:e,instance:t}){const n=Ne({vizManager:e.vizManager,instance:t}),{value:r}=$(e.instanceData,"config"),{variables:i}=e,o=g.useMemo(()=>y.defaults({},r,vr),[r]),l=e.data,{width:u,height:c}=e.viewport;return!o.calendar.data_key||!o.heat_block.data_key||!u||!c?null:s.jsx(Ie,{width:u,height:c,children:s.jsx(P0,{variables:i,width:Qe(u),height:Ue(c),data:l,conf:o,interactionManager:n})})}function O0({control:e,watch:t}){return t(["heat_block"]),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"heat_block.data_key",control:e,render:({field:n})=>s.jsx(O,{label:"Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"heat_block.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"Name",sx:{flex:1},...n})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"heat_block.min",control:e,render:({field:n})=>s.jsx(Vt,{label:"Min Value",...n})}),s.jsx(b.Controller,{name:"heat_block.max",control:e,render:({field:n})=>s.jsx(Vt,{label:"Max Value",...n})})]}),s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Value Format",labelPosition:"center"}),s.jsx(b.Controller,{name:"heat_block.value_formatter",control:e,render:({field:n})=>s.jsx(Fe,{...n})})]})}const $0=({control:e,index:t,remove:n})=>s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>s.jsx(O,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed"}),s.jsx(a.Button,{leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),V0=({control:e,watch:t})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((p,x)=>({...p,...o[x]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[d,h]=g.useState(()=>c??null);return g.useEffect(()=>{c&&h(p=>p!==null?p:c)},[c]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(k.InfoCircle,{size:14,color:"#888"}),s.jsx(a.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),s.jsx(a.Divider,{variant:"dashed",my:10}),s.jsxs(a.Tabs,{value:d,onTabChange:p=>h(p),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((p,x)=>s.jsx(a.Tabs.Tab,{value:p.id,children:p.name?p.name:x},p.id)),s.jsx(a.Tabs.Tab,{onClick:u,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),l.map((p,x)=>s.jsx(a.Tabs.Panel,{value:p.id,children:s.jsx($0,{control:e,index:x,remove:i},p.id)},p.id))]})]})};function q0({control:e,watch:t}){return s.jsx(V0,{control:e,watch:t})}const N0=[{label:"Chinese",value:"ZH"},{label:"English",value:"EN"}];function F0({control:e,watch:t}){return t(["calendar"]),s.jsxs(a.Stack,{children:[s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:"calendar.data_key",control:e,render:({field:n})=>s.jsx(O,{label:"Data Field",required:!0,sx:{flex:1},...n})})}),s.jsx(b.Controller,{name:"calendar.locale",control:e,render:({field:n})=>s.jsx(a.Select,{label:"Language",required:!0,data:N0,sx:{flex:1},...n})})]})}function G0({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=g.useMemo(()=>y.defaultsDeep({},t,vr),[t]),i=g.useMemo(()=>y.cloneDeep(r),[r]);g.useEffect(()=>{!y.isEqual(r,i)&&(console.log("config malformed, resetting to defaults",r,i),n(i))},[r,i]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=b.useForm({defaultValues:i});g.useEffect(()=>{d(i)},[i]);const h=c(),p=g.useMemo(()=>!y.isEqual(h,r),[h,r]);return s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:l(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Calendar Heatmap Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Tabs,{defaultValue:"Calendar",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"Calendar",children:"Calendar"}),s.jsx(a.Tabs.Tab,{value:"Heat Block",children:"Heat Block"}),s.jsx(a.Tabs.Tab,{value:"Tooltip",children:"Tooltip"})]}),s.jsx(a.Tabs.Panel,{value:"Calendar",children:s.jsx(F0,{control:o,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Heat Block",children:s.jsx(O0,{control:o,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(q0,{control:o,watch:u})})]})]})})}function W0(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:i,heat_block:o,tooltip:l,...u}=e;return{...u,calendar:{...i,data_key:r(i.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 R0(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 Q0 extends ue{constructor(){super(...arguments);L(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>({...n,version:2,config:W0(n.config,r)})),this.version(3,n=>({...n,version:3,config:R0(n.config)}))}}const U0={displayName:"Heatmap(Calendar)",displayGroup:"ECharts-based charts",migrator:new Q0,name:"calendarHeatmap",viewRender:B0,configRender:G0,createConfig:()=>({version:3,config:vr}),triggers:[Yo]},wr={x_axes:[{id:"initial-x",min:"",max:"",name:"X Axis",data_key:"",position:"bottom",label_formatter:je,show:!0}],y_axis:{name:"Y Axis",data_key:"",axisLabel:{formatter:{...Oe},overflow:Me()},nameAlignment:"center"},series:[],tooltip:{metrics:[]},reference_lines:[]};function K0(){const e=new Date().getTime().toString();return{id:e,min:"",max:"",name:e,data_key:"",position:"bottom",label_formatter:je,show:!0}}function Y0(){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:At,xAxisIndex:"0"}}function X0(){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 J0(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 i=0;return r&&(i+=15),e.series.some(o=>!o.hide_in_legend)&&(i+=20),{top:n,right:5,bottom:i,left:5,containLabel:!0}}function Z0(e){switch(e){case"bar":return"roundRect";case"scatter":return"circle"}}function H0(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:Z0(r)})),t}function eC(e,t,n,r){return e.map(i=>{const o=i.orientation==="horizontal",l=o?"yAxis":"xAxis",u=o?"insideEndTop":"end";return{name:i.name,type:"line",hide_in_legend:!i.show_in_legend,xAxisIndex:i.xAxisIndex,data:[],lineStyle:i.lineStyle,markLine:{data:[{name:i.name,[l]:Number(n[i.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:i.lineStyle,label:{formatter:function(){return i.template?jn(i.template,t,r):""},position:u}}}})}function Xn(e,t,n){const r=Ze(e,t),i=Ze(e,n);return y.zip(i,r)}function tC(e,t,n,r){const i=Xn(t,n,r);return y.unionBy(i,e,0)}function nC({dataTemplate:e,data:t,name_data_key:n,value_data_key:r,valueTypedXAxis:i}){return i?tC(e,t,n,r):Xn(t,n,r)}function sC({dataTemplate:e,data:t,aggregation_on_value:n,name_data_key:r,value_data_key:i,valueTypedXAxis:o}){if(!n||n.type==="none")return nC({dataTemplate:e,data:t,name_data_key:r,value_data_key:i,valueTypedXAxis:o});const l=Xn(t,r,i),u=y.groupBy(l,"0");return e.map(([d])=>{const p=u[d].map(m=>m[1]),x=ms(p,n);return[d,x]})}function rC({group_by_key:e,data:t,value_data_key:n,name_data_key:r}){const{queryID:i,columnKey:o}=z(e),l=y.groupBy(t[i],o);return Object.entries(l).forEach(([u,c])=>{l[u]=Xn({[i]:c},r,n)}),l}function iC({y_axis:e},{data_key:t,xAxisIndex:n,label_position:r,name:i,group_by_key:o,aggregation_on_value:l,stack:u,color:c,hide_in_legend:d,invisible:h,id:p,...x},m,j,C,T,D){const A={label:{show:!!r,position:r,formatter:D[n??"default"]},name:i,yAxisId:"main-y-axis",xAxisIndex:n,stack:u,color:h?"transparent":c,hide_in_legend:d,labelLayout:{hideOverlap:!0},emphasis:{disabled:!0},...x};if(!o||o===e.data_key)return A.data=sC({dataTemplate:m,data:C,aggregation_on_value:l,name_data_key:e.data_key,value_data_key:t,valueTypedXAxis:j}),A;const F=rC({group_by_key:o,data:C,name_data_key:e.data_key,value_data_key:t});return Object.entries(F).map(([X,Q])=>{const G=y.cloneDeep(A);return G.name=X,G.color=void 0,G.data=Q,G})}function aC(e,t,n,r,i,o,l){const u=t.map(d=>[d,0]);return e.series.map(d=>iC(e,d,u,n,r,l,i)).flat().concat(eC(e.reference_lines,o,l,r))}function oC(e,t){const n=e.find(u=>u.axisDim==="y"&&u.axisId==="main-y-axis");if(!n)return"";const{name:r,axisType:i,axisValue:o,axisIndex:l}=n;return i==="yAxis.category"?r:Pt(t.y_axis.axisLabel.formatter)(o,l)}function lC(e,t,n){const r=t.reduce((i,{xAxisIndex:o,name:l})=>(i[l]=o,i),{});return ne.getTooltip({trigger:"axis",axisPointer:{type:"shadow"},formatter:function(i){const o=Array.isArray(i)?i:[i];if(o.length===0)return"";const l=o.map(({seriesName:d,marker:h,value:p})=>{if(Array.isArray(p)&&p.length===2&&(p=p[0]),!d)return p;const x=r[d],m=n[x]??n.default;return`
333
+ `}})}function D0(e,t,n){const r=Vt(e.heat_block.min,n),i=Vt(e.heat_block.max,n);return{min:r,max:i,calculable:!0,orient:"horizontal",left:t?"center":5,top:0,itemWidth:15}}const I0={grid:{containLabel:!0}},M0=e=>M(e).get("year");function z0(e,t){const n=z(e.calendar.data_key),r=t[n.queryID],i=y.groupBy(r,d=>M0(d[n.columnKey])),o=Object.keys(i),l=r.map(d=>M(d[n.columnKey]).valueOf()),c=y.min(l),u=y.max(l);return{minDate:c??0,maxDate:u??0,dateSpan:M(u).diff(c,"day"),dataByYear:i,years:o}}function A0(e,t,n){const r=n.reduce((p,x)=>{const m=st(x,t);return p[x.name]=Ae(x,m),p},{}),i=w0(e),{dateSpan:o,minDate:l,dataByYear:c,years:u}=z0(e,t),d=o<=366,h={calendar:v0(d,l,u),series:S0(e,d,c,t),tooltip:T0(e,t,i),visualMap:D0(e,d,r),legend:C0(d,u)};return y.defaultsDeep({},h,I0)}function E0(e){return s.jsx(s.Fragment,{})}function P0(e){return s.jsx(a.Text,{children:"Click heat block"})}const Xo={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:P0,configRender:E0,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"}]},jr={calendar:{data_key:"",locale:"EN"},heat_block:{min:{type:"static",value:0},max:{type:"static",value:100},name:"Value",data_key:"",value_formatter:me},tooltip:{metrics:[]}};function L0({name:e},t){const n=t.getOption();n.calendar.forEach(r=>{r.range=e}),t.setOption(n)}function B0({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const l=jt(t,e.calendar.data_key),c=Oe(i.triggerManager,Xo.id),u=g.useCallback(p=>{const[x,m]=p.value,j=y.get(l,x,{error:"rowData is not found"});c.forEach(C=>{i.runInteraction(C.id,{...p,rowData:j})})},[l,c,i]),d=g.useMemo(()=>({click:u,legendselectchanged:L0}),[u]),h=g.useMemo(()=>A0(e,t,o),[e,t]);return s.jsx(we,{echarts:be,option:h,style:{width:n,height:r},onEvents:d,notMerge:!0,opts:{locale:e.calendar.locale},theme:"merico-light"})}function O0({context:e,instance:t}){const n=$e({vizManager:e.vizManager,instance:t}),{value:r}=O(e.instanceData,"config"),{variables:i}=e,o=g.useMemo(()=>y.defaults({},r,jr),[r]),l=e.data,{width:c,height:u}=e.viewport;return!o.calendar.data_key||!o.heat_block.data_key||!c||!u?null:s.jsx(ke,{width:c,height:u,children:s.jsx(B0,{variables:i,width:Ge(c),height:We(u),data:l,conf:o,interactionManager:n})})}function $0({control:e,watch:t}){return t(["heat_block"]),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"heat_block.data_key",control:e,render:({field:n})=>s.jsx(B,{label:"Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"heat_block.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"Name",sx:{flex:1},...n})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"heat_block.min",control:e,render:({field:n})=>s.jsx($t,{label:"Min Value",...n})}),s.jsx(b.Controller,{name:"heat_block.max",control:e,render:({field:n})=>s.jsx($t,{label:"Max Value",...n})})]}),s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Value Format",labelPosition:"center"}),s.jsx(b.Controller,{name:"heat_block.value_formatter",control:e,render:({field:n})=>s.jsx(Ve,{...n})})]})}const V0=({control:e,index:t,remove:n})=>s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>s.jsx(B,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed"}),s.jsx(a.Button,{leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),q0=({control:e,watch:t})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((p,x)=>({...p,...o[x]})),c=()=>r({id:Date.now().toString(),data_key:"",name:""}),u=t("tooltip.metrics.0.id"),[d,h]=g.useState(()=>u??null);return g.useEffect(()=>{u&&h(p=>p!==null?p:u)},[u]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(k.InfoCircle,{size:14,color:"#888"}),s.jsx(a.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),s.jsx(a.Divider,{variant:"dashed",my:10}),s.jsxs(a.Tabs,{value:d,onTabChange:p=>h(p),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((p,x)=>s.jsx(a.Tabs.Tab,{value:p.id,children:p.name?p.name:x},p.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),l.map((p,x)=>s.jsx(a.Tabs.Panel,{value:p.id,children:s.jsx(V0,{control:e,index:x,remove:i},p.id)},p.id))]})]})};function N0({control:e,watch:t}){return s.jsx(q0,{control:e,watch:t})}const F0=[{label:"Chinese",value:"ZH"},{label:"English",value:"EN"}];function G0({control:e,watch:t}){return t(["calendar"]),s.jsxs(a.Stack,{children:[s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:"calendar.data_key",control:e,render:({field:n})=>s.jsx(B,{label:"Data Field",required:!0,sx:{flex:1},...n})})}),s.jsx(b.Controller,{name:"calendar.locale",control:e,render:({field:n})=>s.jsx(a.Select,{label:"Language",required:!0,data:F0,sx:{flex:1},...n})})]})}function W0({context:e}){const{value:t,set:n}=O(e.instanceData,"config"),r=g.useMemo(()=>y.defaultsDeep({},t,jr),[t]),i=g.useMemo(()=>y.cloneDeep(r),[r]);g.useEffect(()=>{!y.isEqual(r,i)&&(console.log("config malformed, resetting to defaults",r,i),n(i))},[r,i]);const{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=b.useForm({defaultValues:i});g.useEffect(()=>{d(i)},[i]);const h=u(),p=g.useMemo(()=>!y.isEqual(h,r),[h,r]);return s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:l(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Calendar Heatmap Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Tabs,{defaultValue:"Calendar",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"Calendar",children:"Calendar"}),s.jsx(a.Tabs.Tab,{value:"Heat Block",children:"Heat Block"}),s.jsx(a.Tabs.Tab,{value:"Tooltip",children:"Tooltip"})]}),s.jsx(a.Tabs.Panel,{value:"Calendar",children:s.jsx(G0,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Heat Block",children:s.jsx($0,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(N0,{control:o,watch:c})})]})]})})}function R0(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}`,{calendar:i,heat_block:o,tooltip:l,...c}=e;return{...c,calendar:{...i,data_key:r(i.data_key)},heat_block:{...o,data_key:r(o.data_key)},tooltip:{...l,metrics:l.metrics.map(u=>({...u,data_key:r(u.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}function Q0(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 U0 extends ae{constructor(){super(...arguments);P(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>({...n,version:2,config:R0(n.config,r)})),this.version(3,n=>({...n,version:3,config:Q0(n.config)}))}}const K0={displayName:"Heatmap(Calendar)",displayGroup:"ECharts-based charts",migrator:new U0,name:"calendarHeatmap",viewRender:O0,configRender:W0,createConfig:()=>({version:3,config:jr}),triggers:[Xo]},vr={x_axes:[{id:"initial-x",min:"",max:"",name:"X Axis",data_key:"",position:"bottom",label_formatter:me,show:!0}],y_axis:{name:"Y Axis",data_key:"",axisLabel:{formatter:{...Pe},overflow:Te()},nameAlignment:"center"},series:[],tooltip:{metrics:[]},reference_lines:[]};function Y0(){const e=new Date().getTime().toString();return{id:e,min:"",max:"",name:e,data_key:"",position:"bottom",label_formatter:me,show:!0}}function X0(){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:zt,xAxisIndex:"0"}}function J0(){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 Z0(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 i=0;return r&&(i+=15),e.series.some(o=>!o.hide_in_legend)&&(i+=20),{top:n,right:5,bottom:i,left:5,containLabel:!0}}function H0(e){switch(e){case"bar":return"roundRect";case"scatter":return"circle"}}function eC(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:H0(r)})),t}function tC(e,t,n,r){return e.map(i=>{const o=i.orientation==="horizontal",l=o?"yAxis":"xAxis",c=o?"insideEndTop":"end";return{name:i.name,type:"line",hide_in_legend:!i.show_in_legend,xAxisIndex:i.xAxisIndex,data:[],lineStyle:i.lineStyle,markLine:{data:[{name:i.name,[l]:Number(n[i.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:i.lineStyle,label:{formatter:function(){return i.template?bn(i.template,t,r):""},position:c}}}})}function Yn(e,t,n){const r=Ye(e,t),i=Ye(e,n);return y.zip(i,r)}function nC(e,t,n,r){const i=Yn(t,n,r);return y.unionBy(i,e,0)}function sC({dataTemplate:e,data:t,name_data_key:n,value_data_key:r,valueTypedXAxis:i}){return i?nC(e,t,n,r):Yn(t,n,r)}function rC({dataTemplate:e,data:t,aggregation_on_value:n,name_data_key:r,value_data_key:i,valueTypedXAxis:o}){if(!n||n.type==="none")return sC({dataTemplate:e,data:t,name_data_key:r,value_data_key:i,valueTypedXAxis:o});const l=Yn(t,r,i),c=y.groupBy(l,"0");return e.map(([d])=>{const p=c[d].map(m=>m[1]),x=gs(p,n);return[d,x]})}function iC({group_by_key:e,data:t,value_data_key:n,name_data_key:r}){const{queryID:i,columnKey:o}=z(e),l=y.groupBy(t[i],o);return Object.entries(l).forEach(([c,u])=>{l[c]=Yn({[i]:u},r,n)}),l}function aC({y_axis:e},{data_key:t,xAxisIndex:n,label_position:r,name:i,group_by_key:o,aggregation_on_value:l,stack:c,color:u,hide_in_legend:d,invisible:h,id:p,...x},m,j,C,T,D){const A={label:{show:!!r,position:r,formatter:D[n??"default"]},name:i,yAxisId:"main-y-axis",xAxisIndex:n,stack:c,color:h?"transparent":u,hide_in_legend:d,labelLayout:{hideOverlap:!0},emphasis:{disabled:!0},...x};if(!o||o===e.data_key)return A.data=rC({dataTemplate:m,data:C,aggregation_on_value:l,name_data_key:e.data_key,value_data_key:t,valueTypedXAxis:j}),A;const N=iC({group_by_key:o,data:C,name_data_key:e.data_key,value_data_key:t});return Object.entries(N).map(([Y,R])=>{const F=y.cloneDeep(A);return F.name=Y,F.color=void 0,F.data=R,F})}function oC(e,t,n,r,i,o,l){const c=t.map(d=>[d,0]);return e.series.map(d=>aC(e,d,c,n,r,l,i)).flat().concat(tC(e.reference_lines,o,l,r))}function lC(e,t){const n=e.find(c=>c.axisDim==="y"&&c.axisId==="main-y-axis");if(!n)return"";const{name:r,axisType:i,axisValue:o,axisIndex:l}=n;return i==="yAxis.category"?r:Pt(t.y_axis.axisLabel.formatter)(o,l)}function cC(e,t,n){const r=t.reduce((i,{xAxisIndex:o,name:l})=>(i[l]=o,i),{});return ee.getTooltip({trigger:"axis",axisPointer:{type:"shadow"},formatter:function(i){const o=Array.isArray(i)?i:[i];if(o.length===0)return"";const l=o.map(({seriesName:d,marker:h,value:p})=>{if(Array.isArray(p)&&p.length===2&&(p=p[0]),!d)return p;const x=r[d],m=n[x]??n.default;return`
334
334
  <tr>
335
335
  <td>${h}</td>
336
336
  <th style="text-align: right; padding: 0 1em;">${d}</th>
337
337
  <td style="text-align: left; padding: 0 1em;">${m({value:p})}</td>
338
338
  </tr>
339
- `}),u=$e(e.y_axis.axisLabel.overflow.in_tooltip),c=oC(o,e);return`
339
+ `}),c=Le(e.y_axis.axisLabel.overflow.in_tooltip),u=lC(o,e);return`
340
340
  <div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
341
- <div style="${u}">${c}</div>
341
+ <div style="${c}">${u}</div>
342
342
  </div>
343
343
  <table style="width: auto">
344
344
  <tbody>
345
345
  ${l.join("")}
346
346
  </tbody>
347
347
  </table>
348
- `}})}function uC(e){return e.x_axes.reduce((n,{label_formatter:r},i)=>(n[i]=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 W(u,r)}catch(c){return console.error(c),u}},n),{default:({value:n})=>n})}function cC(e,t){const n={};return t.map(r=>{const i=it(r,e);n[r.name]=Pe(r,i)}),n}function dC(e,t){return e.x_axes.map(({min:n,max:r,...i},o)=>{let l=i.position;return l||(l=o>0?"bottom":"top"),ne.getYAxis({...i,type:"value",min:n||void 0,max:r||void 0,position:l,axisLabel:{show:!0,margin:2,formatter:t[o]??t.default},nameLocation:"center",nameGap:15})})}function pC(e,t){const n=t.every(l=>!Number.isNaN(Number(l))),{overflow:r,...i}=e.y_axis.axisLabel,o=Ve(r.on_axis);return[ne.getXAxis({data:t,name:e.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"center"},id:"main-y-axis",type:n?"value":"category",axisLabel:{...i,...o,formatter:Pt(i.formatter)},z:5})]}function hC(e,t,n){if(!e.y_axis.data_key)return{};const r=cC(t,n),i=uC(e),o=z(e.y_axis.data_key),l=y.uniq(t[o.queryID].map(h=>h[o.columnKey])),u=l.every(h=>!Number.isNaN(Number(h))),c=aC(e,l,u,t,i,n,r);return{xAxis:dC(e,i),yAxis:pC(e,l),series:c,tooltip:lC(e,c,i),grid:J0(e),legend:H0(c)}}J.use([B.DataZoomComponent,ie.BarChart,ie.LineChart,ie.ScatterChart,B.GridComponent,B.LegendComponent,B.TooltipComponent,_e.CanvasRenderer,B.MarkLineComponent,B.MarkAreaComponent]);function xC({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const l=vt(t,e.y_axis.data_key),u=qe(i.triggerManager,$s.id),c=g.useCallback(p=>{const x=y.get(l,p.name,{error:"rowData is not found"});u.forEach(m=>{i.runInteraction(m.id,{...p,rowData:x})})},[l,u,i]),d=g.useMemo(()=>({click:c}),[c]),h=g.useMemo(()=>hC(e,t,o),[e,t]);return s.jsx(Se,{echarts:J,option:h,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function fC({context:e,instance:t}){const n=Ne({vizManager:e.vizManager,instance:t}),{value:r}=$(e.instanceData,"config"),{variables:i}=e,o=g.useMemo(()=>y.defaults({},r,wr),[r]),l=e.data,{width:u,height:c}=e.viewport;return!u||!c?null:s.jsx(Ie,{width:u,height:c,children:s.jsx(xC,{variables:i,width:Qe(u),height:Ue(c),data:l,conf:o,interactionManager:n})})}const gC=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],mC=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function yC({control:e,index:t,remove:n,watch:r,variableOptions:i,xAxisOptions:o}){const l=r(`reference_lines.${t}.orientation`);return s.jsxs(a.Stack,{my:0,p:0,sx:{position:"relative"},children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:u})=>s.jsx(a.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),s.jsx(b.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:u})=>s.jsx(a.Select,{label:"Value",required:!0,data:i,sx:{flex:1},...u})})]}),s.jsx(b.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:u})=>s.jsx(a.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...u})}),s.jsxs(a.Group,{grow:!0,children:[s.jsxs(a.Stack,{children:[s.jsx(b.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:u})=>s.jsx(a.Select,{label:"Orientation",data:mC,required:!0,sx:{flex:1},...u})}),l==="vertical"&&s.jsx(a.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&s.jsx(b.Controller,{name:`reference_lines.${t}.xAxisIndex`,control:e,render:({field:u})=>s.jsx(a.Select,{label:"X Axis",data:o,disabled:o.length===0,sx:{flex:1},...u})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:u})=>s.jsx(a.Select,{label:"Line Type",data:gC,sx:{flexGrow:1},...u})}),s.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:u})=>s.jsx(a.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...u})})]}),s.jsxs(a.Stack,{spacing:4,children:[s.jsx(a.Text,{size:"sm",children:"Color"}),s.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:u})=>s.jsx(ke,{...u})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),s.jsx(b.Controller,{name:`reference_lines.${t}.show_in_legend`,control:e,render:({field:u})=>s.jsx(a.Checkbox,{label:"Show in legend",checked:u.value,onChange:c=>u.onChange(c.currentTarget.checked)})}),s.jsx(a.Button,{leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]})}function bC({control:e,watch:t,variables:n}){const{fields:r,append:i,remove:o}=b.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=r.map((m,j)=>({...m,...l[j]})),c=()=>{const m=X0();i(m)},d=g.useMemo(()=>n.map(m=>({label:m.name,value:m.name})),[n]),h=t("x_axes"),p=g.useMemo(()=>h.map(({name:m},j)=>({label:m,value:j.toString()})),[h]),x=u.length>0?u[0].id:"0";return s.jsxs(a.Tabs,{defaultValue:x,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},children:[s.jsxs(a.Tabs.List,{children:[u.map((m,j)=>s.jsx(a.Tabs.Tab,{value:m.id,children:m.name},m.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),u.map((m,j)=>s.jsx(a.Tabs.Panel,{value:m.id,children:s.jsx(yC,{control:e,index:j,remove:o,watch:t,variableOptions:d,xAxisOptions:p})},m.id))]})}function jC(e){const[t,n]=g.useState(e);return g.useEffect(()=>{n(e)},[e]),{tab:t,setTab:n}}const vC=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function wC({control:e,index:t,seriesItem:n}){const r=!!n.barWidth.trim();return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${t}.stack`,control:e,render:({field:i})=>s.jsx(a.TextInput,{label:"Stack",placeholder:"Stack bars by this ID",sx:{flexGrow:1},...i})}),s.jsx(b.Controller,{name:`series.${t}.barGap`,control:e,render:({field:i})=>s.jsx(a.Select,{label:"Bar Gap",data:vC,sx:{flexGrow:1},...i})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${t}.barMinWidth`,control:e,render:({field:i})=>s.jsx(a.TextInput,{label:"Bar Width(Min)",disabled:r,sx:{flexGrow:1},...i})}),s.jsx(b.Controller,{name:`series.${t}.barWidth`,control:e,render:({field:i})=>s.jsx(a.TextInput,{label:"Bar Width",sx:{flexGrow:1},...i})}),s.jsx(b.Controller,{name:`series.${t}.barMaxWidth`,control:e,render:({field:i})=>s.jsx(a.TextInput,{label:"Bar Width(Max)",disabled:r,sx:{flexGrow:1},...i})})]})]})}const CC=[{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 SC({control:e,index:t,remove:n,seriesItem:r,xAxisOptions:i}){return s.jsxs(a.Stack,{my:0,p:0,sx:{position:"relative"},children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${t}.name`,control:e,render:({field:o})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...o})}),s.jsx(b.Controller,{name:`series.${t}.xAxisIndex`,control:e,render:({field:o})=>s.jsx(a.Select,{label:"X Axis",data:i,disabled:i.length===0,sx:{flex:1},...o})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${t}.data_key`,control:e,render:({field:o})=>s.jsx(O,{label:"Value Field",required:!0,sx:{flex:1},...o})}),s.jsx(b.Controller,{name:`series.${t}.aggregation_on_value`,control:e,render:({field:o})=>s.jsx(rr,{label:"Aggregation on Value",value:o.value??At,onChange:o.onChange,pt:0,withFallback:!1})})]}),s.jsx(a.Group,{grow:!0,children:s.jsx(b.Controller,{name:`series.${t}.group_by_key`,control:e,render:({field:o})=>s.jsx(O,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...o})})}),s.jsx(wC,{index:t,control:e,seriesItem:r}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),s.jsx(b.Controller,{name:`series.${t}.label_position`,control:e,render:({field:o})=>s.jsx(a.Select,{label:"Label Position",data:CC,...o})}),s.jsxs(a.Stack,{spacing:4,children:[s.jsx(a.Text,{size:"sm",children:"Color"}),s.jsx(b.Controller,{name:`series.${t}.color`,control:e,render:({field:o})=>s.jsx(ke,{...o})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),s.jsx(b.Controller,{name:`series.${t}.hide_in_legend`,control:e,render:({field:o})=>s.jsx(a.Checkbox,{label:"Hide in legend",checked:o.value,onChange:l=>o.onChange(l.currentTarget.checked)})}),s.jsx(b.Controller,{name:`series.${t}.invisible`,control:e,render:({field:o})=>s.jsx(a.Checkbox,{label:"Invisible",checked:o.value,onChange:l=>o.onChange(l.currentTarget.checked)})}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed"}),s.jsx(a.Button,{leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Series"})]})}function _C({control:e,watch:t}){var x;const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"series"}),o=t("series"),l=n.map((m,j)=>({...m,...o[j]})),u=()=>{const m=Y0();r(m)},c=t("x_axes"),d=g.useMemo(()=>c.map(({name:m},j)=>({label:m,value:j.toString()})),[c]),{tab:h,setTab:p}=jC((x=l[0])==null?void 0:x.id);return s.jsxs(a.Tabs,{value:h,onTabChange:p,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map(m=>s.jsx(a.Tabs.Tab,{value:m.id,children:m.name},m.id)),s.jsx(a.Tabs.Tab,{onClick:u,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),l.map((m,j)=>s.jsx(a.Tabs.Panel,{value:m.id,children:s.jsx(SC,{control:e,index:j,remove:i,seriesItem:m,xAxisOptions:d},m.id)},m.id))]})}const kC=[{label:"Top",value:"top"},{label:"Bottom",value:"bottom"}];function TC({control:e,index:t,remove:n}){return s.jsxs(a.Stack,{my:0,p:"0",sx:{position:"relative"},children:[s.jsx(a.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:`x_axes.${t}.name`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})})}),s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:`x_axes.${t}.position`,control:e,render:({field:r})=>s.jsx(a.Select,{label:"Position",required:!0,data:kC,sx:{flex:1},...r})})}),s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),s.jsx(b.Controller,{name:`x_axes.${t}.label_formatter`,control:e,render:({field:r})=>s.jsx(Fe,{...r})})]}),s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:`x_axes.${t}.min`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Min",...r})}),s.jsx(b.Controller,{name:`x_axes.${t}.max`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Max",...r})})]})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),s.jsx(b.Controller,{name:`x_axes.${t}.show`,control:e,render:({field:r})=>s.jsx(a.Checkbox,{label:"Visible",checked:r.value,onChange:i=>r.onChange(i.currentTarget.checked)})}),s.jsx(a.Button,{mt:20,leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this X Axis"})]})}function DC({control:e,watch:t}){const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"x_axes"}),o=t("x_axes"),l=n.map((d,h)=>({...d,...o[h]})),u=()=>{const d=K0();r(d)},c=l.length>0?l[0].id:"0";return s.jsxs(a.Tabs,{defaultValue:c,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map(d=>s.jsx(a.Tabs.Tab,{value:d.id,children:d.name},d.id)),s.jsx(a.Tabs.Tab,{onClick:u,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),l.map((d,h)=>s.jsx(a.Tabs.Panel,{value:d.id,children:s.jsx(TC,{control:e,index:h,remove:i})},d.id))]})}function IC({control:e,watch:t}){return t(["y_axis"]),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"y_axis.data_key",control:e,render:({field:n})=>s.jsx(O,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"y_axis.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"X Axis Name",sx:{flex:1},...n})})]}),s.jsx(a.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:"y_axis.axisLabel.formatter",control:e,render:({field:n})=>s.jsx(Tn,{...n})})}),s.jsx(b.Controller,{name:"y_axis.axisLabel.overflow",control:e,render:({field:n})=>s.jsx(Ke,{...n})})]})}function MC({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),{variables:r}=e,i=g.useMemo(()=>y.defaultsDeep({},t,wr),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=b.useForm({defaultValues:i});g.useEffect(()=>{d(i)},[i]),u([]);const h=c(),p=g.useMemo(()=>!y.isEqual(h,i),[h,i]);return s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:l(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Horizontal Bar Chart Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Tabs,{defaultValue:"Series",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"X Axes",children:"X Axes"}),s.jsx(a.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),s.jsx(a.Tabs.Tab,{value:"Series",children:"Series"}),s.jsx(a.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"})]}),s.jsx(a.Tabs.Panel,{value:"X Axes",children:s.jsx(DC,{control:o,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Y Axis",children:s.jsx(IC,{control:o,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Series",children:s.jsx(_C,{control:o,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Reference Lines",children:s.jsx(bC,{variables:r,control:o,watch:u})})]})]})})}function zC(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:i,y_axis:o,series:l,...u}=e;return{...u,x_axis:{...i,data_key:r(i.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 AC extends ue{constructor(){super(...arguments);L(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:i}=n;return{...n,version:2,config:zC(i,r)}})}}const EC={displayName:"Horizontal Bar Chart",displayGroup:"ECharts-based charts",migrator:new AC,name:"horizontalBarChart",viewRender:fC,configRender:MC,createConfig:()=>({version:2,config:wr})},Cr={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...Qn}}},deviation:{name:"",data_keys:{estimated_value:"",actual_value:""}},metrics:[]};function LC(){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 W(e[2],{output:"percent",mantissa:0,absolute:!1})}catch(t){return console.error(t),e}};function PC(e,t,n){return{type:"heatmap",name:"准确估算比例",xAxisIndex:0,yAxisIndex:0,data:t.map(i=>{const o=n[i].length,c=(y.countBy(n[i],d=>d.level.diff===0).true??0)/o;return[i,"_y",c]}),label:{show:!0,formatter:Xo},labelLayout:{hideOverlap:!0},visualMapIndex:0,tooltip:{trigger:"item",formatter:({color:i,value:o})=>`
348
+ `}})}function uC(e){return e.x_axes.reduce((n,{label_formatter:r},i)=>(n[i]=function(l){let c=l;if(typeof l=="object"&&(Array.isArray(l.value)&&l.value.length===2?c=l.value[0]:c=l.value),!r)return c;try{return G(c,r)}catch(u){return console.error(u),c}},n),{default:({value:n})=>n})}function dC(e,t){const n={};return t.map(r=>{const i=st(r,e);n[r.name]=Ae(r,i)}),n}function pC(e,t){return e.x_axes.map(({min:n,max:r,...i},o)=>{let l=i.position;return l||(l=o>0?"bottom":"top"),ee.getYAxis({...i,type:"value",min:n||void 0,max:r||void 0,position:l,axisLabel:{show:!0,margin:2,formatter:t[o]??t.default},nameLocation:"center",nameGap:15})})}function hC(e,t){const n=t.every(l=>!Number.isNaN(Number(l))),{overflow:r,...i}=e.y_axis.axisLabel,o=Be(r.on_axis);return[ee.getXAxis({data:t,name:e.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"center"},id:"main-y-axis",type:n?"value":"category",axisLabel:{...i,...o,formatter:Pt(i.formatter)},z:5})]}function xC(e,t,n){if(!e.y_axis.data_key)return{};const r=dC(t,n),i=uC(e),o=z(e.y_axis.data_key),l=y.uniq(t[o.queryID].map(h=>h[o.columnKey])),c=l.every(h=>!Number.isNaN(Number(h))),u=oC(e,l,c,t,i,n,r);return{xAxis:pC(e,i),yAxis:hC(e,l),series:u,tooltip:cC(e,u,i),grid:Z0(e),legend:eC(u)}}function fC({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const l=jt(t,e.y_axis.data_key),c=Oe(i.triggerManager,Os.id),u=g.useCallback(p=>{const x=y.get(l,p.name,{error:"rowData is not found"});c.forEach(m=>{i.runInteraction(m.id,{...p,rowData:x})})},[l,c,i]),d=g.useMemo(()=>({click:u}),[u]),h=g.useMemo(()=>xC(e,t,o),[e,t]);return s.jsx(we,{echarts:be,option:h,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function gC({context:e,instance:t}){const n=$e({vizManager:e.vizManager,instance:t}),{value:r}=O(e.instanceData,"config"),{variables:i}=e,o=g.useMemo(()=>y.defaults({},r,vr),[r]),l=e.data,{width:c,height:u}=e.viewport;return!c||!u?null:s.jsx(ke,{width:c,height:u,children:s.jsx(fC,{variables:i,width:Ge(c),height:We(u),data:l,conf:o,interactionManager:n})})}const mC=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],yC=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function bC({control:e,index:t,remove:n,watch:r,variableOptions:i,xAxisOptions:o}){const l=r(`reference_lines.${t}.orientation`);return s.jsxs(a.Stack,{my:0,p:0,sx:{position:"relative"},children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:c})=>s.jsx(a.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...c})}),s.jsx(b.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:c})=>s.jsx(a.Select,{label:"Value",required:!0,data:i,sx:{flex:1},...c})})]}),s.jsx(b.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:c})=>s.jsx(a.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...c})}),s.jsxs(a.Group,{grow:!0,children:[s.jsxs(a.Stack,{children:[s.jsx(b.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:c})=>s.jsx(a.Select,{label:"Orientation",data:yC,required:!0,sx:{flex:1},...c})}),l==="vertical"&&s.jsx(a.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&s.jsx(b.Controller,{name:`reference_lines.${t}.xAxisIndex`,control:e,render:({field:c})=>s.jsx(a.Select,{label:"X Axis",data:o,disabled:o.length===0,sx:{flex:1},...c})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:c})=>s.jsx(a.Select,{label:"Line Type",data:mC,sx:{flexGrow:1},...c})}),s.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:c})=>s.jsx(a.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...c})})]}),s.jsxs(a.Stack,{spacing:4,children:[s.jsx(a.Text,{size:"sm",children:"Color"}),s.jsx(b.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:c})=>s.jsx(Ce,{...c})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),s.jsx(b.Controller,{name:`reference_lines.${t}.show_in_legend`,control:e,render:({field:c})=>s.jsx(a.Checkbox,{label:"Show in legend",checked:c.value,onChange:u=>c.onChange(u.currentTarget.checked)})}),s.jsx(a.Button,{leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]})}function jC({control:e,watch:t,variables:n}){const{fields:r,append:i,remove:o}=b.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),c=r.map((m,j)=>({...m,...l[j]})),u=()=>{const m=J0();i(m)},d=g.useMemo(()=>n.map(m=>({label:m.name,value:m.name})),[n]),h=t("x_axes"),p=g.useMemo(()=>h.map(({name:m},j)=>({label:m,value:j.toString()})),[h]),x=c.length>0?c[0].id:"0";return s.jsxs(a.Tabs,{defaultValue:x,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},children:[s.jsxs(a.Tabs.List,{children:[c.map((m,j)=>s.jsx(a.Tabs.Tab,{value:m.id,children:m.name},m.id)),s.jsx(a.Tabs.Tab,{onClick:u,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),c.map((m,j)=>s.jsx(a.Tabs.Panel,{value:m.id,children:s.jsx(bC,{control:e,index:j,remove:o,watch:t,variableOptions:d,xAxisOptions:p})},m.id))]})}function vC(e){const[t,n]=g.useState(e);return g.useEffect(()=>{n(e)},[e]),{tab:t,setTab:n}}const wC=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function CC({control:e,index:t,seriesItem:n}){const r=!!n.barWidth.trim();return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${t}.stack`,control:e,render:({field:i})=>s.jsx(a.TextInput,{label:"Stack",placeholder:"Stack bars by this ID",sx:{flexGrow:1},...i})}),s.jsx(b.Controller,{name:`series.${t}.barGap`,control:e,render:({field:i})=>s.jsx(a.Select,{label:"Bar Gap",data:wC,sx:{flexGrow:1},...i})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${t}.barMinWidth`,control:e,render:({field:i})=>s.jsx(a.TextInput,{label:"Bar Width(Min)",disabled:r,sx:{flexGrow:1},...i})}),s.jsx(b.Controller,{name:`series.${t}.barWidth`,control:e,render:({field:i})=>s.jsx(a.TextInput,{label:"Bar Width",sx:{flexGrow:1},...i})}),s.jsx(b.Controller,{name:`series.${t}.barMaxWidth`,control:e,render:({field:i})=>s.jsx(a.TextInput,{label:"Bar Width(Max)",disabled:r,sx:{flexGrow:1},...i})})]})]})}const SC=[{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 _C({control:e,index:t,remove:n,seriesItem:r,xAxisOptions:i}){return s.jsxs(a.Stack,{my:0,p:0,sx:{position:"relative"},children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${t}.name`,control:e,render:({field:o})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...o})}),s.jsx(b.Controller,{name:`series.${t}.xAxisIndex`,control:e,render:({field:o})=>s.jsx(a.Select,{label:"X Axis",data:i,disabled:i.length===0,sx:{flex:1},...o})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${t}.data_key`,control:e,render:({field:o})=>s.jsx(B,{label:"Value Field",required:!0,sx:{flex:1},...o})}),s.jsx(b.Controller,{name:`series.${t}.aggregation_on_value`,control:e,render:({field:o})=>s.jsx(sr,{label:"Aggregation on Value",value:o.value??zt,onChange:o.onChange,pt:0,withFallback:!1})})]}),s.jsx(a.Group,{grow:!0,children:s.jsx(b.Controller,{name:`series.${t}.group_by_key`,control:e,render:({field:o})=>s.jsx(B,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...o})})}),s.jsx(CC,{index:t,control:e,seriesItem:r}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),s.jsx(b.Controller,{name:`series.${t}.label_position`,control:e,render:({field:o})=>s.jsx(a.Select,{label:"Label Position",data:SC,...o})}),s.jsxs(a.Stack,{spacing:4,children:[s.jsx(a.Text,{size:"sm",children:"Color"}),s.jsx(b.Controller,{name:`series.${t}.color`,control:e,render:({field:o})=>s.jsx(Ce,{...o})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),s.jsx(b.Controller,{name:`series.${t}.hide_in_legend`,control:e,render:({field:o})=>s.jsx(a.Checkbox,{label:"Hide in legend",checked:o.value,onChange:l=>o.onChange(l.currentTarget.checked)})}),s.jsx(b.Controller,{name:`series.${t}.invisible`,control:e,render:({field:o})=>s.jsx(a.Checkbox,{label:"Invisible",checked:o.value,onChange:l=>o.onChange(l.currentTarget.checked)})}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed"}),s.jsx(a.Button,{leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Series"})]})}function kC({control:e,watch:t}){var x;const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"series"}),o=t("series"),l=n.map((m,j)=>({...m,...o[j]})),c=()=>{const m=X0();r(m)},u=t("x_axes"),d=g.useMemo(()=>u.map(({name:m},j)=>({label:m,value:j.toString()})),[u]),{tab:h,setTab:p}=vC((x=l[0])==null?void 0:x.id);return s.jsxs(a.Tabs,{value:h,onTabChange:p,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map(m=>s.jsx(a.Tabs.Tab,{value:m.id,children:m.name},m.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),l.map((m,j)=>s.jsx(a.Tabs.Panel,{value:m.id,children:s.jsx(_C,{control:e,index:j,remove:i,seriesItem:m,xAxisOptions:d},m.id)},m.id))]})}const TC=[{label:"Top",value:"top"},{label:"Bottom",value:"bottom"}];function DC({control:e,index:t,remove:n}){return s.jsxs(a.Stack,{my:0,p:"0",sx:{position:"relative"},children:[s.jsx(a.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:`x_axes.${t}.name`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})})}),s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:`x_axes.${t}.position`,control:e,render:({field:r})=>s.jsx(a.Select,{label:"Position",required:!0,data:TC,sx:{flex:1},...r})})}),s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),s.jsx(b.Controller,{name:`x_axes.${t}.label_formatter`,control:e,render:({field:r})=>s.jsx(Ve,{...r})})]}),s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:`x_axes.${t}.min`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Min",...r})}),s.jsx(b.Controller,{name:`x_axes.${t}.max`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Max",...r})})]})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),s.jsx(b.Controller,{name:`x_axes.${t}.show`,control:e,render:({field:r})=>s.jsx(a.Checkbox,{label:"Visible",checked:r.value,onChange:i=>r.onChange(i.currentTarget.checked)})}),s.jsx(a.Button,{mt:20,leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this X Axis"})]})}function IC({control:e,watch:t}){const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"x_axes"}),o=t("x_axes"),l=n.map((d,h)=>({...d,...o[h]})),c=()=>{const d=Y0();r(d)},u=l.length>0?l[0].id:"0";return s.jsxs(a.Tabs,{defaultValue:u,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map(d=>s.jsx(a.Tabs.Tab,{value:d.id,children:d.name},d.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),l.map((d,h)=>s.jsx(a.Tabs.Panel,{value:d.id,children:s.jsx(DC,{control:e,index:h,remove:i})},d.id))]})}function MC({control:e,watch:t}){return t(["y_axis"]),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"y_axis.data_key",control:e,render:({field:n})=>s.jsx(B,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"y_axis.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"X Axis Name",sx:{flex:1},...n})})]}),s.jsx(a.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:"y_axis.axisLabel.formatter",control:e,render:({field:n})=>s.jsx(kn,{...n})})}),s.jsx(b.Controller,{name:"y_axis.axisLabel.overflow",control:e,render:({field:n})=>s.jsx(Re,{...n})})]})}function zC({context:e}){const{value:t,set:n}=O(e.instanceData,"config"),{variables:r}=e,i=g.useMemo(()=>y.defaultsDeep({},t,vr),[t]),{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=b.useForm({defaultValues:i});g.useEffect(()=>{d(i)},[i]),c([]);const h=u(),p=g.useMemo(()=>!y.isEqual(h,i),[h,i]);return s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:l(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Horizontal Bar Chart Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Tabs,{defaultValue:"Series",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"X Axes",children:"X Axes"}),s.jsx(a.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),s.jsx(a.Tabs.Tab,{value:"Series",children:"Series"}),s.jsx(a.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"})]}),s.jsx(a.Tabs.Panel,{value:"X Axes",children:s.jsx(IC,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Y Axis",children:s.jsx(MC,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Series",children:s.jsx(kC,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Reference Lines",children:s.jsx(jC,{variables:r,control:o,watch:c})})]})]})})}function AC(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis:i,y_axis:o,series:l,...c}=e;return{...c,x_axis:{...i,data_key:r(i.data_key)},y_axis:{...o,data_key:r(o.data_key)},series:l.map(u=>({...u,data_key:r(u.data_key),group_by_key:r(u.group_by_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class EC extends ae{constructor(){super(...arguments);P(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:i}=n;return{...n,version:2,config:AC(i,r)}})}}const PC={displayName:"Horizontal Bar Chart",displayGroup:"ECharts-based charts",migrator:new EC,name:"horizontalBarChart",viewRender:gC,configRender:zC,createConfig:()=>({version:2,config:vr})},wr={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...Rn}}},deviation:{name:"",data_keys:{estimated_value:"",actual_value:""}},metrics:[]};function LC(){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 Jo=({value:e})=>{try{return G(e[2],{output:"percent",mantissa:0,absolute:!1})}catch(t){return console.error(t),e}};function BC(e,t,n){return{type:"heatmap",name:"准确估算比例",xAxisIndex:0,yAxisIndex:0,data:t.map(i=>{const o=n[i].length,u=(y.countBy(n[i],d=>d.level.diff===0).true??0)/o;return[i,"_y",u]}),label:{show:!0,formatter:Jo},labelLayout:{hideOverlap:!0},visualMapIndex:0,tooltip:{trigger:"item",formatter:({color:i,value:o})=>`
349
349
  <table style="width: auto">
350
350
  <thead>
351
351
  <tr colspan="2">
@@ -363,17 +363,17 @@ Check the top-level render call using <`+E+">.")}return I}}function rc(w,I){{if(
363
363
  <tbody>
364
364
  <tr>
365
365
  <th style="text-align: right;">准确估算比例</th>
366
- <td style="text-align: left; padding: 0 1em;">${Xo({value:o})}</td>
366
+ <td style="text-align: left; padding: 0 1em;">${Jo({value:o})}</td>
367
367
  </tr>
368
368
  </tbody>
369
369
  </table>
370
- `},show_in_legend:!1}}function Jo(e){const t=[`background-color: ${e}`];return e==="rgba(255, 255, 255, 1)"&&t.push("box-shadow: 0px 0px 1px 0px rgba(0,0,0,.5)"),t.join(";")}function BC([e,t]){const n={x:e,v:`${t}`};try{n.v=W(t,{output:"number",mantissa:2,trimMantissa:!0,absolute:!1})}catch{}return n}function OC(e,t,n,r){var c,d;const i=t.map(h=>{const p=n[h],x=y.sumBy(p,m=>m.level.diff);return[h,x/p.length]}),o=Number(((c=y.maxBy(i,h=>h[1]))==null?void 0:c[1])??0),l=Number(((d=y.minBy(i,h=>h[1]))==null?void 0:d[1])??0),u=bt.interpolate([o,0,l],["#D15A40","#FFF","#418AAF"]);return{type:"bar",name:"平均偏差",xAxisIndex:1,yAxisIndex:1,...r,data:i,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],{output:"number",mantissa:1,trimMantissa:!0,absolute:!1})}catch{return h[1]}}},tooltip:{trigger:"item",formatter:({color:h,value:p})=>{const{x,v:m}=BC(p);return`
370
+ `},show_in_legend:!1}}function Zo(e){const t=[`background-color: ${e}`];return e==="rgba(255, 255, 255, 1)"&&t.push("box-shadow: 0px 0px 1px 0px rgba(0,0,0,.5)"),t.join(";")}function OC([e,t]){const n={x:e,v:`${t}`};try{n.v=G(t,{output:"number",mantissa:2,trimMantissa:!0,absolute:!1})}catch{}return n}function $C(e,t,n,r){var u,d;const i=t.map(h=>{const p=n[h],x=y.sumBy(p,m=>m.level.diff);return[h,x/p.length]}),o=Number(((u=y.maxBy(i,h=>h[1]))==null?void 0:u[1])??0),l=Number(((d=y.minBy(i,h=>h[1]))==null?void 0:d[1])??0),c=yt.interpolate([o,0,l],["#D15A40","#FFF","#418AAF"]);return{type:"bar",name:"平均偏差",xAxisIndex:1,yAxisIndex:1,...r,data:i,itemStyle:{color:({value:h})=>{try{return c(h[1])}catch{return"#FFF"}}},label:{position:"outside",show:!0,formatter:({value:h})=>{try{return G(h[1],{output:"number",mantissa:1,trimMantissa:!0,absolute:!1})}catch{return h[1]}}},tooltip:{trigger:"item",formatter:({color:h,value:p})=>{const{x,v:m}=OC(p);return`
371
371
  <table style="width: auto">
372
372
  <thead>
373
373
  <tr colspan="2">
374
374
  <div style="
375
375
  width: 100%; height: 4px; border-radius: 2px; margin-bottom: 6px;
376
- ${Jo(h)}
376
+ ${Zo(h)}
377
377
  "/>
378
378
  </tr>
379
379
  <tr>
@@ -389,13 +389,13 @@ Check the top-level render call using <`+E+">.")}return I}}function rc(w,I){{if(
389
389
  </tr>
390
390
  </tbody>
391
391
  </table>
392
- `}},show_in_legend:!1}}function $C([e,t,n,r]){const i={x:e,percentage:`${t}`,count:n,sum:r};try{i.percentage=W(t,{output:"percent",mantissa:2,trimMantissa:!0,absolute:!1})}catch{}return i}function VC(e,t,n,r){const i={};t.forEach(h=>{const p=y.countBy(n[h],m=>m.level.diff),x=y.sum(Object.values(p));Object.entries(p).forEach(([m,j])=>{i[m]||(i[m]=[]);const C=j/x;i[m].push([h,C,j,x])})});const o=Object.entries(i).map(([h])=>Number(h)).sort((h,p)=>h-p),l=Math.max(...o),u=Math.min(...o),c=bt.interpolate([l,0,u],["#D15A40","#FFF","#418AAF"]);return o.map(h=>({type:"bar",name:h,xAxisIndex:2,yAxisIndex:2,stack:1,...r,color:c(h),data:i[h],tooltip:{trigger:"item",formatter:({color:p,value:x})=>{const{x:m,percentage:j,count:C,sum:T}=$C(x);return`
392
+ `}},show_in_legend:!1}}function VC([e,t,n,r]){const i={x:e,percentage:`${t}`,count:n,sum:r};try{i.percentage=G(t,{output:"percent",mantissa:2,trimMantissa:!0,absolute:!1})}catch{}return i}function qC(e,t,n,r){const i={};t.forEach(h=>{const p=y.countBy(n[h],m=>m.level.diff),x=y.sum(Object.values(p));Object.entries(p).forEach(([m,j])=>{i[m]||(i[m]=[]);const C=j/x;i[m].push([h,C,j,x])})});const o=Object.entries(i).map(([h])=>Number(h)).sort((h,p)=>h-p),l=Math.max(...o),c=Math.min(...o),u=yt.interpolate([l,0,c],["#D15A40","#FFF","#418AAF"]);return o.map(h=>({type:"bar",name:h,xAxisIndex:2,yAxisIndex:2,stack:1,...r,color:u(h),data:i[h],tooltip:{trigger:"item",formatter:({color:p,value:x})=>{const{x:m,percentage:j,count:C,sum:T}=VC(x);return`
393
393
  <table style="width: auto">
394
394
  <thead>
395
395
  <tr colspan="2">
396
396
  <div style="
397
397
  width: 100%; height: 4px; border-radius: 2px; margin-bottom: 6px;
398
- ${Jo(p)}
398
+ ${Zo(p)}
399
399
  "
400
400
  />
401
401
  </tr>
@@ -424,8 +424,8 @@ Check the top-level render call using <`+E+">.")}return I}}function rc(w,I){{if(
424
424
  </tr>
425
425
  </tbody>
426
426
  </table>
427
- `}},show_in_legend:!0}))}function qC(e,t,n,r){const i=z(t.data_key),o=t.name,l=n.map(u=>{const c=y.sumBy(r[u],i.columnKey);return[u,c]});return{type:"line",name:o,xAxisIndex:3,yAxisIndex:3,color:"#b41529",data:l,show_in_legend:!1}}function NC(e,t,n,r){const l={barMinWidth:5,barMaxWidth:20};return[PC(e,n,r),OC(e,n,r,l),...VC(e,n,r,l),qC(e,t,n,r)]}function FC(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:ko(n.formatter)},axisLine:{show:!1}}]}function GC(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 Sr(e){return e==1||e==2?1:Sr(e-2)+Sr(e-1)}const WC=Array.from(new Array(20),(e,t)=>Sr(t+1));function Zo(e){return e<=1?e:WC.findIndex(t=>e<=t)-1}function RC(e,t){const{x_axis:n,deviation:r}=e,i=z(n.data_key),o=z(r.data_keys.estimated_value),l=z(r.data_keys.actual_value);return t[i.queryID].map(u=>{const c=Zo(u[o.columnKey]),d=Zo(u[l.columnKey]),h=c-d;return{...u,level:{estimated:c,actual:d,diff:h}}})}function QC(e){return e==="rgba(255, 255, 255, 1)"?{borderColor:"rgba(0,0,0,.1)",borderWidth:1}:{}}function UC(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:QC(n.color)})),tooltip:{show:!0,formatter:"档位偏差:{a}"}}}const KC={tooltip:{trigger:"axis"}};function YC(e,t){const{deviation:n,metrics:r}=e,i=r.find(l=>l.data_key===t);if(i)return i;const o=n.data_keys.actual_value;return{id:o,name:n.name,data_key:o}}function XC(e,t,n){const r=RC(e,n),i=z(e.x_axis.data_key),o=y.uniqBy(n[i.queryID],i.columnKey).map(h=>h[i.columnKey]),l=y.groupBy(r,i.columnKey),u=YC(e,t),c=NC(e,u,o,l),d={xAxis:FC(e,o),yAxis:GC(u),series:c,grid:LC(),visualMap:[{min:0,max:1,calculable:!0,show:!1,seriesIndex:0,color:["#F0F0F0","#418AAF"]}],legend:UC(c)};return y.defaultsDeep({},d,KC)}const JC={input:{border:"none !important",paddingLeft:0,lineHeight:"1.55 !important"}},ZC=({conf:e,metricKey:t,setMetricKey:n})=>{const{deviation:r,metrics:i}=e,o=g.useMemo(()=>{const l=i.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,i]);return s.jsxs(a.Group,{spacing:1,children:[s.jsx(a.Text,{size:12,color:"dimmed",sx:{cursor:"default",userSelect:"none"},children:"基线指标"}),s.jsx(a.NativeSelect,{size:"xs",data:o,value:t,onChange:l=>n(l.currentTarget.value),styles:JC})]})},HC={"tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function eS(){return s.jsxs(a.HoverCard,{width:400,shadow:"md",children:[s.jsx(a.HoverCard.Target,{children:s.jsx(a.Button,{size:"xs",variant:"subtle",compact:!0,leftIcon:s.jsx(_.IconInfoCircle,{size:14}),children:"指标说明"})}),s.jsx(a.HoverCard.Dropdown,{children:s.jsx(a.Table,{fontSize:14,sx:HC,children:s.jsxs("tbody",{children:[s.jsxs("tr",{children:[s.jsx("th",{children:"估算偏差"}),s.jsx("td",{children:"使用斐波那契数列(1,2,3,5,8,13)估算故事点,每个数位为一个档位,计算issue实际故事点与估算故事点的档位偏差,即为估算偏差。如估算故事点为5,实际故事点为8,则估算偏差为-1。"})]}),s.jsxs("tr",{children:[s.jsx("th",{children:"准确估算比例"}),s.jsx("td",{children:"偏差在 ± 1 档位内的 issue 均为准确估算,以此计算准确估算的比例。"})]})]})})})]})}function tS(e){return s.jsxs(a.Group,{position:"apart",children:[s.jsx(eS,{}),s.jsx(ZC,{...e})]})}J.use([ie.BarChart,ie.LineChart,ie.HeatmapChart,B.GridComponent,B.LegendComponent,B.TooltipComponent,_e.CanvasRenderer,B.VisualMapComponent]);function nS({conf:e,data:t,width:n,height:r,metricKey:i}){const o=g.useMemo(()=>XC(e,i,t),[e,t,i]);return s.jsx(Se,{echarts:J,option:o,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})}function sS({context:e}){const{value:t}=$(e.instanceData,"config"),n=g.useMemo(()=>y.defaults({},t,Cr),[t]),r=e.data,{width:i,height:o}=e.viewport,{x_axis:l,deviation:u}=n,{estimated_value:c,actual_value:d}=u.data_keys,[h,p]=g.useState(d);if(g.useEffect(()=>{p(j=>j||d)},[d]),!l.data_key||!c||!d||!i||!o)return null;const x=Math.max(Qe(i),300),m=Math.max(Ue(o),370);return s.jsxs(a.Box,{pt:De.top,pr:De.right,pb:De.bottom,pl:De.left,sx:{overflow:"hidden",height:o,width:i},children:[s.jsx(tS,{conf:n,metricKey:h,setMetricKey:p}),s.jsx(nS,{width:x,height:m-30,data:r,conf:n,metricKey:h})]})}function rS({control:e,watch:t}){return t(["deviation"]),s.jsxs(a.Stack,{children:[s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:"deviation.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"指标名称",sx:{flex:1},...n})})}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"deviation.data_keys.estimated_value",control:e,render:({field:n})=>s.jsx(O,{label:"估算值字段",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"deviation.data_keys.actual_value",control:e,render:({field:n})=>s.jsx(O,{label:"实际值字段",required:!0,sx:{flex:1},...n})})]})]})}const iS=({control:e,index:t,remove:n})=>s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`metrics.${t}.name`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`metrics.${t}.data_key`,control:e,render:({field:r})=>s.jsx(O,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed"}),s.jsx(a.Button,{leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),aS=({control:e,watch:t})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"metrics"}),o=t("metrics"),l=n.map((p,x)=>({...p,...o[x]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("metrics.0.id"),[d,h]=g.useState(()=>c??null);return g.useEffect(()=>{c&&h(p=>p!==null?p:c)},[c]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(k.InfoCircle,{size:14,color:"#888"}),s.jsx(a.Text,{size:14,color:"#888",children:"设置可以展示在基线图的指标,例如代码当量"})]}),s.jsx(a.Divider,{variant:"dashed",my:10}),s.jsxs(a.Tabs,{value:d,onTabChange:p=>h(p),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((p,x)=>s.jsx(a.Tabs.Tab,{value:p.id,children:p.name?p.name:x},p.id)),s.jsx(a.Tabs.Tab,{onClick:u,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),l.map((p,x)=>s.jsx(a.Tabs.Panel,{value:p.id,children:s.jsx(iS,{control:e,index:x,remove:i},p.id)},p.id))]})]})};function oS({control:e,watch:t}){return t(["x_axis"]),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>s.jsx(O,{label:"数据字段",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"x_axis.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"X轴名称",sx:{flex:1},...n})})]}),s.jsx(a.Divider,{mb:-15,label:"点位文案",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>s.jsx(a.NumberInput,{label:"旋转",hideControls:!0,min:-90,max:90,rightSection:s.jsx(a.Text,{color:"dimmed",children:"度"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),s.jsx(b.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>s.jsx(Mo,{...n})})]})]})}function lS({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=g.useMemo(()=>y.defaultsDeep({},t,Cr),[t]),{control:i,handleSubmit:o,watch:l,getValues:u,reset:c}=b.useForm({defaultValues:r});g.useEffect(()=>{c(r)},[r]),l([]);const d=u(),h=g.useMemo(()=>!y.isEqual(d,r),[d,r]);return s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:o(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Merico Estimation Chart Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"12px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"X Axis",children:"X 轴"}),s.jsx(a.Tabs.Tab,{value:"Deviation",children:"偏差"}),s.jsx(a.Tabs.Tab,{value:"Additional Metrics",children:"指标"})]}),s.jsx(a.Tabs.Panel,{value:"X Axis",children:s.jsx(oS,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Deviation",children:s.jsx(rS,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Additional Metrics",children:s.jsx(aS,{control:i,watch:l})})]})]})})}function uS(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:i,deviation:o,metrics:l,...u}=e;return{...u,x_axis:{...i,data_key:r(i.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 cS extends ue{constructor(){super(...arguments);L(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:i}=n;return{...n,version:2,config:uS(i,r)}})}}const dS={displayName:"Merico Estimation Chart",displayGroup:"Merico suite",migrator:new cS,name:"mericoEstimationChart",viewRender:sS,configRender:lS,createConfig:()=>({version:2,config:Cr})},_r={styles:{justify:"space-around",align:"start"},metrics:[]};function pS(){return{id:new Date().getTime().toString(),names:{value:"Value",basis:"Basis"},data_keys:{value:"",basis:""},formatter:je,postfix:{type:"text",value:""}}}const Ho=({postfix:e})=>e?s.jsxs(s.Fragment,{children:[s.jsx(a.Text,{size:"12px",color:"#818388",sx:{lineHeight:1},children:"/"}),s.jsx(a.Text,{size:"12px",color:"#818388",sx:{lineHeight:1},children:e})]}):null,hS=S.observer(({metric:e,variableValueMap:t})=>{const{names:n,data_keys:r,formatter:i,postfix:o}=e,l=pe(),u=g.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 s.jsxs(a.Stack,{spacing:18,children:[s.jsxs(a.Stack,{spacing:12,children:[s.jsx(a.Text,{size:"14px",color:"#818388",children:n.value}),s.jsxs(a.Group,{spacing:"2px",align:"baseline",children:[s.jsx(a.Text,{size:"24px",fw:"bold",color:"#3D3E45",sx:{lineHeight:1},children:W(t[r.value],i)}),s.jsx(Ho,{postfix:u})]})]}),s.jsxs(a.Stack,{spacing:12,children:[s.jsx(a.Text,{size:"14px",color:"#818388",children:n.basis}),s.jsxs(a.Group,{spacing:"2px",align:"baseline",children:[s.jsx(a.Text,{size:"12px",color:"#3D3E45",sx:{lineHeight:1},children:W(t[r.basis],i)}),s.jsx(Ho,{postfix:u})]})]})]})}),xS=S.observer(({context:e,instance:t})=>{const{value:n}=$(e.instanceData,"config"),{variables:r}=e,i=g.useMemo(()=>y.defaults({},n,_r),[n]),o=e.data,l=g.useMemo(()=>Da(o,r),[r,o]),{width:u,height:c}=e.viewport;return!u||!c||!i?null:s.jsx(a.Flex,{w:`${u}px`,h:`${c}px`,justify:i.styles.justify,align:i.styles.align,direction:"row",wrap:"nowrap",sx:{overflow:"hidden"},children:i.metrics.map(d=>s.jsx(hS,{metric:d,variableValueMap:l},d.id))})}),fS=[{label:"Text",value:"text"},{label:"Filter Option Label",value:"filter-option-label"}],gS=S.observer(g.forwardRef(({value:e,onChange:t},n)=>{const i=R().filters.selects,o=u=>{t({type:u,value:e.value})},l=u=>{t({type:e.type,value:u})};return s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(a.Select,{label:"Postfix Type",data:fS,value:e.type,onChange:o}),e.type==="text"&&s.jsx(a.TextInput,{label:"Postfix Content",value:e.value,onChange:u=>{l(u.currentTarget.value)}}),e.type==="filter-option-label"&&s.jsx(a.Select,{label:"Filter",value:e.value,onChange:l,data:i})]})}));function mS({control:e,index:t,remove:n,watch:r,variableOptions:i}){return r(`metrics.${t}.postfix`),s.jsxs(a.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`metrics.${t}.names.value`,control:e,render:({field:o})=>s.jsx(a.TextInput,{label:"Metric Name",required:!0,sx:{flex:1},...o})}),s.jsx(b.Controller,{name:`metrics.${t}.data_keys.value`,control:e,render:({field:o})=>s.jsx(a.Select,{label:"Metric Data",required:!0,data:i,sx:{flex:1},...o})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`metrics.${t}.names.basis`,control:e,render:({field:o})=>s.jsx(a.TextInput,{label:"Basis Name",required:!0,sx:{flex:1},...o})}),s.jsx(b.Controller,{name:`metrics.${t}.data_keys.basis`,control:e,render:({field:o})=>s.jsx(a.Select,{label:"Basis Data",required:!0,data:i,sx:{flex:1},...o})})]}),s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Format",labelPosition:"center"}),s.jsx(b.Controller,{name:`metrics.${t}.formatter`,control:e,render:({field:o})=>s.jsx(Fe,{...o})}),s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Others",labelPosition:"center"}),s.jsx(b.Controller,{name:`metrics.${t}.postfix`,control:e,render:({field:o})=>s.jsx(gS,{...o})}),s.jsx(a.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(t),sx:{position:"absolute",top:15,right:5},disabled:t===0,children:s.jsx(k.Trash,{size:16})})]})}const yS=({control:e,watch:t,variables:n})=>{const{fields:r,append:i,remove:o}=b.useFieldArray({control:e,name:"metrics"}),l=t("metrics"),u=r.map((j,C)=>({...j,...l[C]})),c=()=>{i(pS())},d=g.useMemo(()=>n.map(j=>({label:j.name,value:j.name})),[n]),h=y.get(u,"0.id",null),[p,x]=g.useState(h);g.useEffect(()=>{x(j=>j||h)},[h]);const m=j=>{o(j);const C=y.get(u,"0.id",null);x(C)};return s.jsxs(s.Fragment,{children:[s.jsx(a.Divider,{mt:15,variant:"dashed",label:"Metrics",labelPosition:"center"}),s.jsxs(a.Tabs,{value:p,onTabChange:x,styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[s.jsxs(a.Tabs.List,{children:[u.map((j,C)=>s.jsx(a.Tabs.Tab,{value:j.id,children:j.names.value?j.names.value:C+1},j.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(_.IconPlus,{size:18,color:"#228be6"})})]}),u.map((j,C)=>s.jsx(a.Tabs.Panel,{value:j.id,children:s.jsx(mS,{control:e,index:C,remove:m,variableOptions:d,watch:t})},j.id))]})]})},bS=[{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"}],jS=[{label:"Start",value:"start"},{label:"Center",value:"center"},{label:"End",value:"end"},{label:"Stretch",value:"stretch"}];function vS({control:e,watch:t}){return t("styles"),s.jsxs(s.Fragment,{children:[s.jsx(a.Divider,{mt:15,variant:"dashed",label:"Styles",labelPosition:"center"}),s.jsxs(a.Group,{children:[s.jsx(b.Controller,{name:"styles.justify",control:e,render:({field:n})=>s.jsx(a.Select,{label:"Justify Content",required:!0,data:bS,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"styles.align",control:e,render:({field:n})=>s.jsx(a.Select,{label:"Align",required:!0,data:jS,sx:{flex:1},...n})})]})]})}function wS({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),{variables:r}=e,i=g.useMemo(()=>y.defaultsDeep({},t,_r),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=b.useForm({defaultValues:i});g.useEffect(()=>{d(i)},[i]);const h=c(),p=g.useMemo(()=>!y.isEqual(h,i),[h,i]);return s.jsx("form",{onSubmit:l(n),children:s.jsxs(a.Stack,{spacing:"xs",children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Merico Stats Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsx(vS,{control:o,watch:u}),s.jsx(yS,{control:o,watch:u,variables:r})]})})}function CS(e){const{metrics:t,...n}=e;return{...n,metrics:t.map(r=>({...r,postfix:r.postfix??{type:"text",value:""}}))}}class SS extends ue{constructor(){super(...arguments);L(this,"VERSION",2)}configVersions(){this.version(1,n=>({...n,version:1,config:n.config})),this.version(2,n=>({...n,version:2,config:CS(n.config)}))}}const _S={displayName:"Merico Stats",displayGroup:"Merico suite",migrator:new SS,name:"merico-stats",viewRender:xS,configRender:wS,createConfig:()=>({version:2,config:_r})};function kS({control:e,watch:t}){t(["heat_block"]);const n=t("heat_block.label.show");return s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"heat_block.data_key",control:e,render:({field:r})=>s.jsx(O,{label:"Data Field",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:"heat_block.name",control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",sx:{flex:1},...r})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"heat_block.min",control:e,render:({field:r})=>s.jsx(Vt,{label:"Min Value",...r})}),s.jsx(b.Controller,{name:"heat_block.max",control:e,render:({field:r})=>s.jsx(Vt,{label:"Max Value",...r})})]}),s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Value Format",labelPosition:"center"}),s.jsx(b.Controller,{name:"heat_block.value_formatter",control:e,render:({field:r})=>s.jsx(Fe,{...r})}),s.jsx(a.Divider,{mb:-5,variant:"dashed",label:"Label",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"heat_block.label.show",control:e,render:({field:r})=>s.jsx(a.Switch,{label:"Show label",checked:r.value,onChange:i=>r.onChange(i.currentTarget.checked),sx:{flexGrow:1}})}),s.jsx(b.Controller,{name:"heat_block.label.fontSize",control:e,render:({field:r})=>s.jsx(a.NumberInput,{size:"xs",icon:s.jsx(_.IconTextSize,{size:16}),disabled:!n,...r})})]})]})}const TS=({control:e,index:t,remove:n})=>s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>s.jsx(O,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed"}),s.jsx(a.Button,{leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),DS=({control:e,watch:t})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((p,x)=>({...p,...o[x]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[d,h]=g.useState(()=>c??null);return g.useEffect(()=>{c&&h(p=>p!==null?p:c)},[c]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(k.InfoCircle,{size:14,color:"#888"}),s.jsx(a.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),s.jsx(a.Divider,{variant:"dashed",my:10}),s.jsxs(a.Tabs,{value:d,onTabChange:p=>h(p),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((p,x)=>s.jsx(a.Tabs.Tab,{value:p.id,children:p.name?p.name:x},p.id)),s.jsx(a.Tabs.Tab,{onClick:u,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),l.map((p,x)=>s.jsx(a.Tabs.Panel,{value:p.id,children:s.jsx(TS,{control:e,index:x,remove:i},p.id)},p.id))]})]})};function IS({control:e,watch:t}){return s.jsx(DS,{control:e,watch:t})}const MS=({disabled:e,value:t,onChange:n})=>{const r=i=>{i&&n(i)};return s.jsxs(a.Box,{sx:{position:"relative"},children:[e&&s.jsx(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),s.jsx(ye,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},zS={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
428
- `)},el=g.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:i,setFalse:o}]=V.useBoolean(),[l,u]=g.useState(e);g.useEffect(()=>{u(e)},[e]);const c=m=>{u({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:j}=l,C={enabled:m,func_content:j};u(C),t(C)},h=()=>{o(),u(e)},p=m=>{u(j=>({...j,func_content:m}))},x=()=>{p(zS.func_content)};return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"filled",mt:24,onClick:i,sx:{flexGrow:0},children:"Customize Label"}),s.jsx(a.Modal,{size:800,title:"Customize label content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&s.jsxs(a.Stack,{children:[s.jsx(a.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:m=>c(m.currentTarget.checked)}),s.jsx(MS,{value:l.func_content,onChange:p,disabled:!l.enabled}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:x,color:"red",leftIcon:s.jsx(k.Recycle,{size:20}),children:"Reset"}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:h,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:d,children:"OK"})]})]})]})})]})});function AS({control:e,watch:t}){return t(["x_axis"]),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>s.jsx(O,{label:"Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"x_axis.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"Name",sx:{flex:1},...n})})]}),s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Tick Label",labelPosition:"center"}),s.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>s.jsx(Ke,{...n})}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>s.jsx(a.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:s.jsx(a.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),s.jsx(b.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>s.jsx(el,{...n})})]})]})}const ES=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function LS({control:e,watch:t}){return t(["y_axis"]),s.jsxs(a.Stack,{my:0,p:"0",sx:{position:"relative"},children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"y_axis.data_key",control:e,render:({field:n})=>s.jsx(O,{label:"Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"y_axis.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...n})})]}),s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:"y_axis.nameAlignment",control:e,render:({field:n})=>s.jsx(a.Select,{label:"Name Alignment",required:!0,data:ES,sx:{flex:1},...n})})}),s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Tick Label",labelPosition:"center"}),s.jsx(b.Controller,{name:"y_axis.axisLabel.overflow",control:e,render:({field:n})=>s.jsx(Ke,{...n})}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"y_axis.axisLabel.rotate",control:e,render:({field:n})=>s.jsx(a.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:s.jsx(a.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),s.jsx(b.Controller,{name:"y_axis.axisLabel.formatter",control:e,render:({field:n})=>s.jsx(el,{...n})})]})]})}const kr={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,overflow:Me(),formatter:{...Oe}}},y_axis:{name:"Y Axis",data_key:"",nameAlignment:"center",axisLabel:{rotate:0,overflow:Me(),formatter:{...Oe}}},heat_block:{min:{type:"static",value:0},max:{type:"static",value:100},name:"Value",data_key:"",value_formatter:je,label:{show:!1,fontSize:10}},tooltip:{metrics:[]}};function PS({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=g.useMemo(()=>y.defaultsDeep({},t,kr),[t]),i=g.useMemo(()=>y.cloneDeep(r),[r]);g.useEffect(()=>{!y.isEqual(r,i)&&(console.log("config malformed, resetting to defaults",r,i),n(i))},[r,i]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=b.useForm({defaultValues:i});g.useEffect(()=>{d(i)},[i]);const h=c(),p=g.useMemo(()=>!y.isEqual(h,r),[h,r]);return s.jsx("form",{onSubmit:l(n),style:{flexGrow:1},children:s.jsxs(a.Stack,{spacing:"xs",sx:{height:"100%"},children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Chart Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{root:{flexGrow:1},tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"X Axis",children:"X Axis"}),s.jsx(a.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),s.jsx(a.Tabs.Tab,{value:"Heat Block",children:"Heat Block"}),s.jsx(a.Tabs.Tab,{value:"Tooltip",children:"Tooltip"})]}),s.jsx(a.Tabs.Panel,{value:"X Axis",children:s.jsx(AS,{control:o,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Y Axis",children:s.jsx(LS,{control:o,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Heat Block",children:s.jsx(kS,{control:o,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(IS,{control:o,watch:u})})]})]})})}function BS(e){return s.jsx(s.Fragment,{})}function OS(e){return s.jsx(a.Text,{children:"Click heat block"})}const tl={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:OS,configRender:BS,payload:[{name:"seriesType",description:"'heatmap'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function nl({enabled:e,func_content:t}){return(n,r)=>{if(!e)return n;try{return new Function(`return ${t}`)()(n,r)}catch(i){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${i.message}`),n}}}function $S(e){const t=nl(e.x_axis.axisLabel.formatter),n=nl(e.y_axis.axisLabel.formatter);return{x_axis:t,y_axis:n}}function VS(e){return{heat_block:function(r){if(!e.heat_block.value_formatter)return r;try{return W(r,e.heat_block.value_formatter)}catch(i){return console.error(i),r}}}}function qS(e){let t=0;return e.x_axis.name&&(t+=20),{top:45,left:5,right:5,bottom:t,containLabel:!0,borderColor:"none",backgroundColor:"#E7E7E9",z:1}}function NS(e,t){const{x_axis:n,y_axis:r,heat_block:i}=e,o=z(n.data_key),l=z(r.data_key),u=z(i.data_key),c=t[o.queryID].map(d=>[y.get(d,o.columnKey),y.get(d,l.columnKey),y.get(d,u.columnKey)]);return{type:"heatmap",name:i.name,xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{borderWidth:0},data:c,label:i.label,labelLayout:{hideOverlap:!0},z:2}}const FS=e=>W(e,{output:"number",trimMantissa:!0,mantissa:2,absolute:!1});function GS({conf:e,labelFormatters:t,valueFormatters:n,dataDict:r,params:i}){const{value:o,dataIndex:l}=i,[u,c,d]=o,h={label:e.x_axis.name?e.x_axis.name:"X Axis",value:t.x_axis(u,l),style:{label:"",value:$e(e.x_axis.axisLabel.overflow.in_tooltip)}},p={label:e.y_axis.name?e.y_axis.name:"Y Axis",value:t.y_axis(c,l),style:{label:"",value:$e(e.y_axis.axisLabel.overflow.in_tooltip)}},x={label:e.heat_block.name,value:n.heat_block(d),style:{label:"",value:""}},m=[h,p,x],j=r[`${u}---${c}`];return j&&e.tooltip.metrics.forEach(C=>{const T=z(C.data_key);m.push({label:C.name,value:FS(y.get(j,T.columnKey,"")),style:{label:"",value:""}})}),m}function WS(e,t,n,r){const{x_axis:i,y_axis:o,heat_block:l}=e,u=z(i.data_key),c=z(o.data_key);z(l.data_key);const d=y.keyBy(t[u.queryID],h=>`${h[u.columnKey]}---${h[c.columnKey]}`);return ne.getTooltip({formatter:function(h){const x=GS({conf:e,labelFormatters:n,valueFormatters:r,dataDict:d,params:h}).map(j=>`
427
+ `}},show_in_legend:!0}))}function NC(e,t,n,r){const i=z(t.data_key),o=t.name,l=n.map(c=>{const u=y.sumBy(r[c],i.columnKey);return[c,u]});return{type:"line",name:o,xAxisIndex:3,yAxisIndex:3,color:"#b41529",data:l,show_in_legend:!1}}function FC(e,t,n,r){const l={barMinWidth:5,barMaxWidth:20};return[BC(e,n,r),$C(e,n,r,l),...qC(e,n,r,l),NC(e,t,n,r)]}function GC(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:To(n.formatter)},axisLine:{show:!1}}]}function WC(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 Cr(e){return e==1||e==2?1:Cr(e-2)+Cr(e-1)}const RC=Array.from(new Array(20),(e,t)=>Cr(t+1));function Ho(e){return e<=1?e:RC.findIndex(t=>e<=t)-1}function QC(e,t){const{x_axis:n,deviation:r}=e,i=z(n.data_key),o=z(r.data_keys.estimated_value),l=z(r.data_keys.actual_value);return t[i.queryID].map(c=>{const u=Ho(c[o.columnKey]),d=Ho(c[l.columnKey]),h=u-d;return{...c,level:{estimated:u,actual:d,diff:h}}})}function UC(e){return e==="rgba(255, 255, 255, 1)"?{borderColor:"rgba(0,0,0,.1)",borderWidth:1}:{}}function KC(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:UC(n.color)})),tooltip:{show:!0,formatter:"档位偏差:{a}"}}}const YC={tooltip:{trigger:"axis"}};function XC(e,t){const{deviation:n,metrics:r}=e,i=r.find(l=>l.data_key===t);if(i)return i;const o=n.data_keys.actual_value;return{id:o,name:n.name,data_key:o}}function JC(e,t,n){const r=QC(e,n),i=z(e.x_axis.data_key),o=y.uniqBy(n[i.queryID],i.columnKey).map(h=>h[i.columnKey]),l=y.groupBy(r,i.columnKey),c=XC(e,t),u=FC(e,c,o,l),d={xAxis:GC(e,o),yAxis:WC(c),series:u,grid:LC(),visualMap:[{min:0,max:1,calculable:!0,show:!1,seriesIndex:0,color:["#F0F0F0","#418AAF"]}],legend:KC(u)};return y.defaultsDeep({},d,YC)}const ZC={input:{border:"none !important",paddingLeft:0,lineHeight:"1.55 !important"}},HC=({conf:e,metricKey:t,setMetricKey:n})=>{const{deviation:r,metrics:i}=e,o=g.useMemo(()=>{const l=i.map(c=>({label:c.name,value:c.data_key}));return l.push({label:r.name?r.name:r.data_keys.actual_value,value:r.data_keys.actual_value}),l},[r,i]);return s.jsxs(a.Group,{spacing:1,children:[s.jsx(a.Text,{size:12,color:"dimmed",sx:{cursor:"default",userSelect:"none"},children:"基线指标"}),s.jsx(a.NativeSelect,{size:"xs",data:o,value:t,onChange:l=>n(l.currentTarget.value),styles:ZC})]})},eS={"tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function tS(){return s.jsxs(a.HoverCard,{width:400,shadow:"md",children:[s.jsx(a.HoverCard.Target,{children:s.jsx(a.Button,{size:"xs",variant:"subtle",compact:!0,leftIcon:s.jsx(_.IconInfoCircle,{size:14}),children:"指标说明"})}),s.jsx(a.HoverCard.Dropdown,{children:s.jsx(a.Table,{fontSize:14,sx:eS,children:s.jsxs("tbody",{children:[s.jsxs("tr",{children:[s.jsx("th",{children:"估算偏差"}),s.jsx("td",{children:"使用斐波那契数列(1,2,3,5,8,13)估算故事点,每个数位为一个档位,计算issue实际故事点与估算故事点的档位偏差,即为估算偏差。如估算故事点为5,实际故事点为8,则估算偏差为-1。"})]}),s.jsxs("tr",{children:[s.jsx("th",{children:"准确估算比例"}),s.jsx("td",{children:"偏差在 ± 1 档位内的 issue 均为准确估算,以此计算准确估算的比例。"})]})]})})})]})}function nS(e){return s.jsxs(a.Group,{position:"apart",children:[s.jsx(tS,{}),s.jsx(HC,{...e})]})}function sS({conf:e,data:t,width:n,height:r,metricKey:i}){const o=g.useMemo(()=>JC(e,i,t),[e,t,i]);return s.jsx(we,{echarts:be,option:o,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})}function rS({context:e}){const{value:t}=O(e.instanceData,"config"),n=g.useMemo(()=>y.defaults({},t,wr),[t]),r=e.data,{width:i,height:o}=e.viewport,{x_axis:l,deviation:c}=n,{estimated_value:u,actual_value:d}=c.data_keys,[h,p]=g.useState(d);if(g.useEffect(()=>{p(j=>j||d)},[d]),!l.data_key||!u||!d||!i||!o)return null;const x=Math.max(Ge(i),300),m=Math.max(We(o),370);return s.jsxs(a.Box,{pt:_e.top,pr:_e.right,pb:_e.bottom,pl:_e.left,sx:{overflow:"hidden",height:o,width:i},children:[s.jsx(nS,{conf:n,metricKey:h,setMetricKey:p}),s.jsx(sS,{width:x,height:m-30,data:r,conf:n,metricKey:h})]})}function iS({control:e,watch:t}){return t(["deviation"]),s.jsxs(a.Stack,{children:[s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:"deviation.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"指标名称",sx:{flex:1},...n})})}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"deviation.data_keys.estimated_value",control:e,render:({field:n})=>s.jsx(B,{label:"估算值字段",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"deviation.data_keys.actual_value",control:e,render:({field:n})=>s.jsx(B,{label:"实际值字段",required:!0,sx:{flex:1},...n})})]})]})}const aS=({control:e,index:t,remove:n})=>s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`metrics.${t}.name`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`metrics.${t}.data_key`,control:e,render:({field:r})=>s.jsx(B,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed"}),s.jsx(a.Button,{leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),oS=({control:e,watch:t})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"metrics"}),o=t("metrics"),l=n.map((p,x)=>({...p,...o[x]})),c=()=>r({id:Date.now().toString(),data_key:"",name:""}),u=t("metrics.0.id"),[d,h]=g.useState(()=>u??null);return g.useEffect(()=>{u&&h(p=>p!==null?p:u)},[u]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(k.InfoCircle,{size:14,color:"#888"}),s.jsx(a.Text,{size:14,color:"#888",children:"设置可以展示在基线图的指标,例如代码当量"})]}),s.jsx(a.Divider,{variant:"dashed",my:10}),s.jsxs(a.Tabs,{value:d,onTabChange:p=>h(p),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((p,x)=>s.jsx(a.Tabs.Tab,{value:p.id,children:p.name?p.name:x},p.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),l.map((p,x)=>s.jsx(a.Tabs.Panel,{value:p.id,children:s.jsx(aS,{control:e,index:x,remove:i},p.id)},p.id))]})]})};function lS({control:e,watch:t}){return t(["x_axis"]),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>s.jsx(B,{label:"数据字段",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"x_axis.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"X轴名称",sx:{flex:1},...n})})]}),s.jsx(a.Divider,{mb:-15,label:"点位文案",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>s.jsx(a.NumberInput,{label:"旋转",hideControls:!0,min:-90,max:90,rightSection:s.jsx(a.Text,{color:"dimmed",children:"度"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),s.jsx(b.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>s.jsx(zo,{...n})})]})]})}function cS({context:e}){const{value:t,set:n}=O(e.instanceData,"config"),r=g.useMemo(()=>y.defaultsDeep({},t,wr),[t]),{control:i,handleSubmit:o,watch:l,getValues:c,reset:u}=b.useForm({defaultValues:r});g.useEffect(()=>{u(r)},[r]),l([]);const d=c(),h=g.useMemo(()=>!y.isEqual(d,r),[d,r]);return s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:o(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Merico Estimation Chart Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"12px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"X Axis",children:"X 轴"}),s.jsx(a.Tabs.Tab,{value:"Deviation",children:"偏差"}),s.jsx(a.Tabs.Tab,{value:"Additional Metrics",children:"指标"})]}),s.jsx(a.Tabs.Panel,{value:"X Axis",children:s.jsx(lS,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Deviation",children:s.jsx(iS,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Additional Metrics",children:s.jsx(oS,{control:i,watch:l})})]})]})})}function uS(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis:i,deviation:o,metrics:l,...c}=e;return{...c,x_axis:{...i,data_key:r(i.data_key)},deviation:{...o,data_keys:{estimated_value:r(o.data_keys.estimated_value),actual_value:r(o.data_keys.actual_value)}},metrics:l.map(u=>({...u,data_key:r(u.data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class dS extends ae{constructor(){super(...arguments);P(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:i}=n;return{...n,version:2,config:uS(i,r)}})}}const pS={displayName:"Merico Estimation Chart",displayGroup:"Merico suite",migrator:new dS,name:"mericoEstimationChart",viewRender:rS,configRender:cS,createConfig:()=>({version:2,config:wr})},Sr={styles:{justify:"space-around",align:"start"},metrics:[]};function hS(){return{id:new Date().getTime().toString(),names:{value:"Value",basis:"Basis"},data_keys:{value:"",basis:""},formatter:me,postfix:{type:"text",value:""}}}const el=({postfix:e})=>e?s.jsxs(s.Fragment,{children:[s.jsx(a.Text,{size:"12px",color:"#818388",sx:{lineHeight:1},children:"/"}),s.jsx(a.Text,{size:"12px",color:"#818388",sx:{lineHeight:1},children:e})]}):null,xS=S.observer(({metric:e,variableValueMap:t})=>{const{names:n,data_keys:r,formatter:i,postfix:o}=e,l=ce(),c=g.useMemo(()=>{if(o.type==="text"&&o.value)return o.value;if(o.type==="filter-option-label"&&o.value){const u=l.filters.getSelectOption(o.value);return u?u.label:null}return null},[o,l]);return s.jsxs(a.Stack,{spacing:18,children:[s.jsxs(a.Stack,{spacing:12,children:[s.jsx(a.Text,{size:"14px",color:"#818388",children:n.value}),s.jsxs(a.Group,{spacing:"2px",align:"baseline",children:[s.jsx(a.Text,{size:"24px",fw:"bold",color:"#3D3E45",sx:{lineHeight:1},children:G(t[r.value],i)}),s.jsx(el,{postfix:c})]})]}),s.jsxs(a.Stack,{spacing:12,children:[s.jsx(a.Text,{size:"14px",color:"#818388",children:n.basis}),s.jsxs(a.Group,{spacing:"2px",align:"baseline",children:[s.jsx(a.Text,{size:"12px",color:"#3D3E45",sx:{lineHeight:1},children:G(t[r.basis],i)}),s.jsx(el,{postfix:c})]})]})]})}),fS=S.observer(({context:e,instance:t})=>{const{value:n}=O(e.instanceData,"config"),{variables:r}=e,i=g.useMemo(()=>y.defaults({},n,Sr),[n]),o=e.data,l=g.useMemo(()=>Ia(o,r),[r,o]),{width:c,height:u}=e.viewport;return!c||!u||!i?null:s.jsx(a.Flex,{w:`${c}px`,h:`${u}px`,justify:i.styles.justify,align:i.styles.align,direction:"row",wrap:"nowrap",sx:{overflow:"hidden"},children:i.metrics.map(d=>s.jsx(xS,{metric:d,variableValueMap:l},d.id))})}),gS=[{label:"Text",value:"text"},{label:"Filter Option Label",value:"filter-option-label"}],mS=S.observer(g.forwardRef(({value:e,onChange:t},n)=>{const i=W().filters.selects,o=c=>{t({type:c,value:e.value})},l=c=>{t({type:e.type,value:c})};return s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(a.Select,{label:"Postfix Type",data:gS,value:e.type,onChange:o}),e.type==="text"&&s.jsx(a.TextInput,{label:"Postfix Content",value:e.value,onChange:c=>{l(c.currentTarget.value)}}),e.type==="filter-option-label"&&s.jsx(a.Select,{label:"Filter",value:e.value,onChange:l,data:i})]})}));function yS({control:e,index:t,remove:n,watch:r,variableOptions:i}){return r(`metrics.${t}.postfix`),s.jsxs(a.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`metrics.${t}.names.value`,control:e,render:({field:o})=>s.jsx(a.TextInput,{label:"Metric Name",required:!0,sx:{flex:1},...o})}),s.jsx(b.Controller,{name:`metrics.${t}.data_keys.value`,control:e,render:({field:o})=>s.jsx(a.Select,{label:"Metric Data",required:!0,data:i,sx:{flex:1},...o})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`metrics.${t}.names.basis`,control:e,render:({field:o})=>s.jsx(a.TextInput,{label:"Basis Name",required:!0,sx:{flex:1},...o})}),s.jsx(b.Controller,{name:`metrics.${t}.data_keys.basis`,control:e,render:({field:o})=>s.jsx(a.Select,{label:"Basis Data",required:!0,data:i,sx:{flex:1},...o})})]}),s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Format",labelPosition:"center"}),s.jsx(b.Controller,{name:`metrics.${t}.formatter`,control:e,render:({field:o})=>s.jsx(Ve,{...o})}),s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Others",labelPosition:"center"}),s.jsx(b.Controller,{name:`metrics.${t}.postfix`,control:e,render:({field:o})=>s.jsx(mS,{...o})}),s.jsx(a.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(t),sx:{position:"absolute",top:15,right:5},disabled:t===0,children:s.jsx(k.Trash,{size:16})})]})}const bS=({control:e,watch:t,variables:n})=>{const{fields:r,append:i,remove:o}=b.useFieldArray({control:e,name:"metrics"}),l=t("metrics"),c=r.map((j,C)=>({...j,...l[C]})),u=()=>{i(hS())},d=g.useMemo(()=>n.map(j=>({label:j.name,value:j.name})),[n]),h=y.get(c,"0.id",null),[p,x]=g.useState(h);g.useEffect(()=>{x(j=>j||h)},[h]);const m=j=>{o(j);const C=y.get(c,"0.id",null);x(C)};return s.jsxs(s.Fragment,{children:[s.jsx(a.Divider,{mt:15,variant:"dashed",label:"Metrics",labelPosition:"center"}),s.jsxs(a.Tabs,{value:p,onTabChange:x,styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[s.jsxs(a.Tabs.List,{children:[c.map((j,C)=>s.jsx(a.Tabs.Tab,{value:j.id,children:j.names.value?j.names.value:C+1},j.id)),s.jsx(a.Tabs.Tab,{onClick:u,value:"add",children:s.jsx(_.IconPlus,{size:18,color:"#228be6"})})]}),c.map((j,C)=>s.jsx(a.Tabs.Panel,{value:j.id,children:s.jsx(yS,{control:e,index:C,remove:m,variableOptions:d,watch:t})},j.id))]})]})},jS=[{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"}],vS=[{label:"Start",value:"start"},{label:"Center",value:"center"},{label:"End",value:"end"},{label:"Stretch",value:"stretch"}];function wS({control:e,watch:t}){return t("styles"),s.jsxs(s.Fragment,{children:[s.jsx(a.Divider,{mt:15,variant:"dashed",label:"Styles",labelPosition:"center"}),s.jsxs(a.Group,{children:[s.jsx(b.Controller,{name:"styles.justify",control:e,render:({field:n})=>s.jsx(a.Select,{label:"Justify Content",required:!0,data:jS,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"styles.align",control:e,render:({field:n})=>s.jsx(a.Select,{label:"Align",required:!0,data:vS,sx:{flex:1},...n})})]})]})}function CS({context:e}){const{value:t,set:n}=O(e.instanceData,"config"),{variables:r}=e,i=g.useMemo(()=>y.defaultsDeep({},t,Sr),[t]),{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=b.useForm({defaultValues:i});g.useEffect(()=>{d(i)},[i]);const h=u(),p=g.useMemo(()=>!y.isEqual(h,i),[h,i]);return s.jsx("form",{onSubmit:l(n),children:s.jsxs(a.Stack,{spacing:"xs",children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Merico Stats Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsx(wS,{control:o,watch:c}),s.jsx(bS,{control:o,watch:c,variables:r})]})})}function SS(e){const{metrics:t,...n}=e;return{...n,metrics:t.map(r=>({...r,postfix:r.postfix??{type:"text",value:""}}))}}class _S extends ae{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:SS(n.config)}))}}const kS={displayName:"Merico Stats",displayGroup:"Merico suite",migrator:new _S,name:"merico-stats",viewRender:fS,configRender:CS,createConfig:()=>({version:2,config:Sr})};function TS({control:e,watch:t}){t(["heat_block"]);const n=t("heat_block.label.show");return s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"heat_block.data_key",control:e,render:({field:r})=>s.jsx(B,{label:"Data Field",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:"heat_block.name",control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",sx:{flex:1},...r})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"heat_block.min",control:e,render:({field:r})=>s.jsx($t,{label:"Min Value",...r})}),s.jsx(b.Controller,{name:"heat_block.max",control:e,render:({field:r})=>s.jsx($t,{label:"Max Value",...r})})]}),s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Value Format",labelPosition:"center"}),s.jsx(b.Controller,{name:"heat_block.value_formatter",control:e,render:({field:r})=>s.jsx(Ve,{...r})}),s.jsx(a.Divider,{mb:-5,variant:"dashed",label:"Label",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"heat_block.label.show",control:e,render:({field:r})=>s.jsx(a.Switch,{label:"Show label",checked:r.value,onChange:i=>r.onChange(i.currentTarget.checked),sx:{flexGrow:1}})}),s.jsx(b.Controller,{name:"heat_block.label.fontSize",control:e,render:({field:r})=>s.jsx(a.NumberInput,{size:"xs",icon:s.jsx(_.IconTextSize,{size:16}),disabled:!n,...r})})]})]})}const DS=({control:e,index:t,remove:n})=>s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>s.jsx(B,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed"}),s.jsx(a.Button,{leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),IS=({control:e,watch:t})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((p,x)=>({...p,...o[x]})),c=()=>r({id:Date.now().toString(),data_key:"",name:""}),u=t("tooltip.metrics.0.id"),[d,h]=g.useState(()=>u??null);return g.useEffect(()=>{u&&h(p=>p!==null?p:u)},[u]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(k.InfoCircle,{size:14,color:"#888"}),s.jsx(a.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),s.jsx(a.Divider,{variant:"dashed",my:10}),s.jsxs(a.Tabs,{value:d,onTabChange:p=>h(p),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((p,x)=>s.jsx(a.Tabs.Tab,{value:p.id,children:p.name?p.name:x},p.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),l.map((p,x)=>s.jsx(a.Tabs.Panel,{value:p.id,children:s.jsx(DS,{control:e,index:x,remove:i},p.id)},p.id))]})]})};function MS({control:e,watch:t}){return s.jsx(IS,{control:e,watch:t})}const zS=({disabled:e,value:t,onChange:n})=>{const r=i=>{i&&n(i)};return s.jsxs(a.Box,{sx:{position:"relative"},children:[e&&s.jsx(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),s.jsx(fe,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},AS={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
428
+ `)},tl=g.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:i,setFalse:o}]=$.useBoolean(),[l,c]=g.useState(e);g.useEffect(()=>{c(e)},[e]);const u=m=>{c({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:j}=l,C={enabled:m,func_content:j};c(C),t(C)},h=()=>{o(),c(e)},p=m=>{c(j=>({...j,func_content:m}))},x=()=>{p(AS.func_content)};return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"filled",mt:24,onClick:i,sx:{flexGrow:0},children:"Customize Label"}),s.jsx(a.Modal,{size:800,title:"Customize label content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&s.jsxs(a.Stack,{children:[s.jsx(a.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:m=>u(m.currentTarget.checked)}),s.jsx(zS,{value:l.func_content,onChange:p,disabled:!l.enabled}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:x,color:"red",leftIcon:s.jsx(k.Recycle,{size:20}),children:"Reset"}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:h,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:d,children:"OK"})]})]})]})})]})});function ES({control:e,watch:t}){return t(["x_axis"]),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>s.jsx(B,{label:"Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"x_axis.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"Name",sx:{flex:1},...n})})]}),s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Tick Label",labelPosition:"center"}),s.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>s.jsx(Re,{...n})}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>s.jsx(a.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:s.jsx(a.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),s.jsx(b.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>s.jsx(tl,{...n})})]})]})}const PS=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function LS({control:e,watch:t}){return t(["y_axis"]),s.jsxs(a.Stack,{my:0,p:"0",sx:{position:"relative"},children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"y_axis.data_key",control:e,render:({field:n})=>s.jsx(B,{label:"Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"y_axis.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...n})})]}),s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:"y_axis.nameAlignment",control:e,render:({field:n})=>s.jsx(a.Select,{label:"Name Alignment",required:!0,data:PS,sx:{flex:1},...n})})}),s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Tick Label",labelPosition:"center"}),s.jsx(b.Controller,{name:"y_axis.axisLabel.overflow",control:e,render:({field:n})=>s.jsx(Re,{...n})}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"y_axis.axisLabel.rotate",control:e,render:({field:n})=>s.jsx(a.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:s.jsx(a.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),s.jsx(b.Controller,{name:"y_axis.axisLabel.formatter",control:e,render:({field:n})=>s.jsx(tl,{...n})})]})]})}const _r={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,overflow:Te(),formatter:{...Pe}}},y_axis:{name:"Y Axis",data_key:"",nameAlignment:"center",axisLabel:{rotate:0,overflow:Te(),formatter:{...Pe}}},heat_block:{min:{type:"static",value:0},max:{type:"static",value:100},name:"Value",data_key:"",value_formatter:me,label:{show:!1,fontSize:10}},tooltip:{metrics:[]}};function BS({context:e}){const{value:t,set:n}=O(e.instanceData,"config"),r=g.useMemo(()=>y.defaultsDeep({},t,_r),[t]),i=g.useMemo(()=>y.cloneDeep(r),[r]);g.useEffect(()=>{!y.isEqual(r,i)&&(console.log("config malformed, resetting to defaults",r,i),n(i))},[r,i]);const{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=b.useForm({defaultValues:i});g.useEffect(()=>{d(i)},[i]);const h=u(),p=g.useMemo(()=>!y.isEqual(h,r),[h,r]);return s.jsx("form",{onSubmit:l(n),style:{flexGrow:1},children:s.jsxs(a.Stack,{spacing:"xs",sx:{height:"100%"},children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Chart Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{root:{flexGrow:1},tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"X Axis",children:"X Axis"}),s.jsx(a.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),s.jsx(a.Tabs.Tab,{value:"Heat Block",children:"Heat Block"}),s.jsx(a.Tabs.Tab,{value:"Tooltip",children:"Tooltip"})]}),s.jsx(a.Tabs.Panel,{value:"X Axis",children:s.jsx(ES,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Y Axis",children:s.jsx(LS,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Heat Block",children:s.jsx(TS,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(MS,{control:o,watch:c})})]})]})})}function OS(e){return s.jsx(s.Fragment,{})}function $S(e){return s.jsx(a.Text,{children:"Click heat block"})}const nl={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:$S,configRender:OS,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 sl({enabled:e,func_content:t}){return(n,r)=>{if(!e)return n;try{return new Function(`return ${t}`)()(n,r)}catch(i){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${i.message}`),n}}}function VS(e){const t=sl(e.x_axis.axisLabel.formatter),n=sl(e.y_axis.axisLabel.formatter);return{x_axis:t,y_axis:n}}function qS(e){return{heat_block:function(r){if(!e.heat_block.value_formatter)return r;try{return G(r,e.heat_block.value_formatter)}catch(i){return console.error(i),r}}}}function NS(e){let t=0;return e.x_axis.name&&(t+=20),{top:45,left:5,right:5,bottom:t,containLabel:!0,borderColor:"none",backgroundColor:"#E7E7E9",z:1}}function FS(e,t){const{x_axis:n,y_axis:r,heat_block:i}=e,o=z(n.data_key),l=z(r.data_key),c=z(i.data_key),u=t[o.queryID].map(d=>[y.get(d,o.columnKey),y.get(d,l.columnKey),y.get(d,c.columnKey)]);return{type:"heatmap",name:i.name,xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{borderWidth:0},data:u,label:i.label,labelLayout:{hideOverlap:!0},z:2}}const GS=e=>G(e,{output:"number",trimMantissa:!0,mantissa:2,absolute:!1});function WS({conf:e,labelFormatters:t,valueFormatters:n,dataDict:r,params:i}){const{value:o,dataIndex:l}=i,[c,u,d]=o,h={label:e.x_axis.name?e.x_axis.name:"X Axis",value:t.x_axis(c,l),style:{label:"",value:Le(e.x_axis.axisLabel.overflow.in_tooltip)}},p={label:e.y_axis.name?e.y_axis.name:"Y Axis",value:t.y_axis(u,l),style:{label:"",value:Le(e.y_axis.axisLabel.overflow.in_tooltip)}},x={label:e.heat_block.name,value:n.heat_block(d),style:{label:"",value:""}},m=[h,p,x],j=r[`${c}---${u}`];return j&&e.tooltip.metrics.forEach(C=>{const T=z(C.data_key);m.push({label:C.name,value:GS(y.get(j,T.columnKey,"")),style:{label:"",value:""}})}),m}function RS(e,t,n,r){const{x_axis:i,y_axis:o,heat_block:l}=e,c=z(i.data_key),u=z(o.data_key);z(l.data_key);const d=y.keyBy(t[c.queryID],h=>`${h[c.columnKey]}---${h[u.columnKey]}`);return ee.getTooltip({formatter:function(h){const x=WS({conf:e,labelFormatters:n,valueFormatters:r,dataDict:d,params:h}).map(j=>`
429
429
  <tr>
430
430
  <th style="text-align: right;">
431
431
  <div style="${j.style.label}">${j.label}</div>
@@ -446,19 +446,19 @@ Check the top-level render call using <`+E+">.")}return I}}function rc(w,I){{if(
446
446
  </thead>
447
447
  <tbody>${x.join("")}</tbody>
448
448
  </table>
449
- `}})}function RS(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 QS(e,t,n){const r=z(e.x_axis.data_key),i=y.uniq(t[r.queryID].map(c=>c[r.columnKey])),{overflow:o,rotate:l}=e.x_axis.axisLabel,u=Ve(o.on_axis);return ne.getXAxis({id:"main-x-axis",type:"category",data:i,name:e.x_axis.name??"",align:"center",axisTick:{show:!0,alignWithLabel:!0},axisLabel:{rotate:l,...u,formatter:n},splitArea:{show:!1,areaStyle:{color:"#E7E7E9"}},splitLine:{show:!1},nameLocation:"center",nameGap:25,nameTextStyle:{fontWeight:"bold",align:"center"},z:3})}function US(e,t,n){const r=z(e.x_axis.data_key),i=z(e.y_axis.data_key),{nameAlignment:o,data_key:l,...u}=e.y_axis,c=y.uniq(t[r.queryID].map(x=>x[i.columnKey])),{overflow:d,rotate:h}=e.y_axis.axisLabel,p=Ve(d.on_axis);return ne.getYAxis({...u,type:"category",data:c,axisLabel:{rotate:h,...p,formatter:n},axisLine:{show:!0,lineStyle:{width:3}},axisTick:{show:!0,alignWithLabel:!0},splitArea:{show:!1,areaStyle:{color:"#E7E7E9"}},splitLine:{show:!1},nameTextStyle:{fontWeight:"bold",align:o},nameLocation:"end",nameGap:15,z:3})}function KS(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=it(c,t);return u[c.name]=Pe(c,d),u},{}),i=$S(e),o=VS(e);return{xAxis:QS(e,t,i.x_axis),yAxis:US(e,t,i.y_axis),series:NS(e,t),tooltip:WS(e,t,i,o),grid:qS(e),visualMap:RS(e,r)}}J.use([B.DataZoomComponent,ie.HeatmapChart,B.GridComponent,B.LegendComponent,B.TooltipComponent,B.VisualMapComponent,_e.CanvasRenderer]);function YS({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const l=g.useMemo(()=>{const p=z(e.x_axis.data_key),x=z(e.y_axis.data_key);return y.keyBy(t[p.queryID],m=>`${m[p.columnKey]}---${m[x.columnKey]}`)},[t,e.x_axis.data_key,e.y_axis.data_key]),u=qe(i.triggerManager,tl.id),c=g.useCallback(p=>{const[x,m]=p.value,j=y.get(l,`${x}---${m}`,{error:"rowData is not found"});u.forEach(C=>{i.runInteraction(C.id,{...p,rowData:j})})},[l,u,i]),d=g.useMemo(()=>({click:c}),[c]),h=g.useMemo(()=>KS(e,t,o),[e,t]);return s.jsx(Se,{echarts:J,option:h,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function XS({context:e,instance:t}){const n=Ne({vizManager:e.vizManager,instance:t}),{value:r}=$(e.instanceData,"config"),{variables:i}=e,o=g.useMemo(()=>y.defaults({},r,kr),[r]),l=e.data,{width:u,height:c}=e.viewport;return!u||!c?null:s.jsx(Ie,{width:u,height:c,children:s.jsx(YS,{variables:i,width:Qe(u),height:Ue(c),data:l,conf:o,interactionManager:n})})}class JS extends ue{constructor(){super(...arguments);L(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const ZS={displayName:"Merico Heatmap",displayGroup:"Merico suite",migrator:new JS,name:"merico-heatmap",viewRender:XS,configRender:PS,createConfig:()=>({version:1,config:kr}),triggers:[tl]},HS=[{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"})),e1=[Pd,Bd,Vd,$d,Od,qd],sl=()=>({id:"dashboard",version:ua,manifest:{viz:[mr,Vv,c0,fj,ow,ab,EC,Zd,qh,Lm,gy,U0,Yy,dm,Tv,zb,aj,y0,dS,ZS,_S,ex],color:[...HS,...e1]}}),ln=new Wd,he={pluginManager:at("pluginManager"),vizManager:at("vizManager"),colorManager:at("colorManager"),instanceScope:{panelModel:at("panelModel"),vizInstance:at("vizInstance"),interactionManager:at("interactionManager"),migrator:at("migrator"),operationManager:at("operationManager"),triggerManager:at("triggerManager")}},Tr=()=>{try{ln.install(sl())}catch{}const e=new Ad(ln),t=new Gd(ln);return{pluginManager:ln,vizManager:e,colorManager:t}},tt=g.createContext(Tr());try{ln.install(sl())}catch{}const Dr=g.createContext(null);function Jn(e){const t=g.useContext(Dr),n=V.useCreation(()=>e.configure(t||new ws),[e.configure]),r=V.usePrevious(n);return r&&r!==n&&r.dispose(),s.jsx(Dr.Provider,{value:n,children:e.children})}function rl(){return g.useContext(Dr)}const t1=({description:e,isDescriptionEmpty:t})=>t?null:s.jsx(a.Tooltip,{color:"white",label:s.jsx(Fn,{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:s.jsx(a.Box,{sx:{height:"16px",alignSelf:"center"},children:s.jsx(_.IconInfoCircle,{size:16,color:"gray"})})}),n1=S.observer(({label:e,config:{default_value:t,description:n,isDescriptionEmpty:r,...i},value:o,onChange:l})=>s.jsxs(a.Box,{children:[s.jsx(a.Text,{children:" "}),s.jsx(a.Checkbox,{label:s.jsxs(a.Group,{noWrap:!0,position:"apart",align:"middle",spacing:6,children:[s.jsx(a.Box,{sx:{flexGrow:1},children:e}),s.jsx(t1,{description:n,isDescriptionEmpty:r})]}),checked:o||!1,onChange:u=>l(u.currentTarget.checked),...i,pt:".4em",styles:{input:{borderColor:"#e9ecef"}}})]})),s1=({value:e,onChange:t,close:n,max_days:r,allowSingleDateInRange:i})=>{const[o,l]=e,u=g.useMemo(()=>o||new Date,[o]),c=g.useMemo(()=>{if(o&&!l)return o},[o,l]),d=g.useMemo(()=>{if(o&&!l&&r>0)return M(o).add(r-1,"days").toDate()},[o,l,r]),h=p=>{const[x,m]=p;t(p),x&&m&&n()};return s.jsx(hc.DatePicker,{defaultDate:u,numberOfColumns:2,type:"range",value:e,onChange:h,onNextMonth:console.log,minDate:c,maxDate:d,allowSingleDateInRange:i})},r1=({begin:e,end:t})=>{const n=g.useMemo(()=>M(t).diff(M(e),"days")+1,[e,t]);if(Number.isNaN(n))return s.jsx("span",{style:{userSelect:"none",opacity:0,visibility:"hidden"},children:"."});const r=n===1?"day":"days";return s.jsx(a.Tooltip,{label:`${n}${r}`,children:s.jsx(a.Badge,{size:"sm",children:n})})},i1=({max_days:e})=>e?s.jsxs(s.Fragment,{children:[s.jsx(a.Group,{position:"right",children:s.jsxs(a.Badge,{size:"xs",children:[e," days max"]})}),s.jsx(a.Divider,{variant:"dashed",my:10})]}):null,Ir=()=>[{label:"yesterday",value:"yesterday",group:"last",getRange:()=>{const e=Date.now();return[M(e).subtract(1,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()]}},{label:"week",value:"last week",group:"last",getRange:()=>{const e=Date.now();return[M(e).subtract(1,"week").startOf("week").toDate(),M(e).subtract(1,"week").endOf("week").toDate()]}},{label:"month",value:"last month",group:"last",getRange:()=>{const e=Date.now();return[M(e).subtract(1,"month").startOf("month").toDate(),M(e).subtract(1,"month").endOf("month").toDate()]}},{label:"2 months",value:"last 2 months",group:"last",getRange:()=>{const e=Date.now();return[M(e).subtract(2,"month").startOf("month").toDate(),M(e).subtract(1,"month").endOf("month").toDate()]}},{label:"3 months",value:"last 3 months",group:"last",getRange:()=>{const e=Date.now();return[M(e).subtract(3,"month").startOf("month").toDate(),M(e).subtract(1,"month").endOf("month").toDate()]}},{label:"year",value:"last year",group:"last",getRange:()=>{const e=Date.now();return[M(e).subtract(1,"year").startOf("year").toDate(),M(e).subtract(1,"year").endOf("year").toDate()]}},{label:"7 days",value:"recent 7 days",group:"recent",getRange:()=>{const e=Date.now();return[M(e).subtract(7,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()]}},{label:"30 days",value:"recent 30 days",group:"recent",getRange:()=>{const e=Date.now();return[M(e).subtract(30,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()]}},{label:"60 days",value:"recent 60 days",group:"recent",getRange:()=>{const e=Date.now();return[M(e).subtract(60,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()]}},{label:"90 days",value:"recent 90 days",group:"recent",getRange:()=>{const e=Date.now();return[M(e).subtract(90,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()]}},{label:"180 days",value:"recent 180 days",group:"recent",getRange:()=>{const e=Date.now();return[M(e).subtract(180,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()]}},{label:"365 days",value:"recent 365 days",group:"recent",getRange:()=>{const e=Date.now();return[M(e).subtract(365,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()]}},{label:"today",value:"today",group:"this",getRange:()=>{const e=Date.now();return[M(e).startOf("day").toDate(),M(e).endOf("day").toDate()]}},{label:"week",value:"this week",group:"this",getRange:()=>{const e=Date.now();return[M(e).startOf("week").toDate(),M(e).endOf("week").toDate()]}},{label:"month",value:"this month",group:"this",getRange:()=>{const e=Date.now();return[M(e).startOf("month").toDate(),M(e).endOf("month").toDate()]}},{label:"2 months",value:"this 2 months",group:"this",getRange:()=>{const e=Date.now();return[M(e).startOf("month").toDate(),M(e).add(1,"month").endOf("week").toDate()]}},{label:"3 months",value:"this 3 months",group:"this",getRange:()=>{const e=Date.now();return[M(e).startOf("month").toDate(),M(e).add(2,"month").endOf("week").toDate()]}},{label:"year",value:"this year",group:"this",getRange:()=>{const e=Date.now();return[M(e).startOf("year").toDate(),M(e).endOf("year").toDate()]}}];function il(e){const n=Ir().find(r=>r.value===e);return n?n.getRange():null}const a1=({onChange:e})=>{const t=r=>()=>{const i=r();e(i)},n=g.useMemo(()=>y.groupBy(Ir(),"group"),[]);return s.jsxs(s.Fragment,{children:[s.jsx(a.Divider,{variant:"dashed",my:10}),s.jsx(a.Table,{withBorder:!1,sx:{"tbody > tr > th, tbody > tr > td":{borderTop:"none",padding:"2px 6px"},"tbody > tr > th":{cursor:"default",userSelect:"none"},td:{paddingLeft:"1px"}},children:s.jsx("tbody",{children:Object.entries(n).map(([r,i])=>s.jsxs("tr",{children:[s.jsx("th",{children:s.jsx(a.Text,{size:"xs",color:"#555",children:r})}),i.map(({label:o,value:l,getRange:u})=>s.jsx("td",{children:s.jsx(a.Button,{compact:!0,size:"xs",variant:"subtle",onClick:t(u),children:o})},o))]},r))})})]})},al=e=>({label:{display:"block",height:"21.7px"},input:{borderColor:e?"#228be6":"#e9ecef"}}),o1=({label:e,required:t,value:n,onChange:r,max_days:i,allowSingleDateInRange:o,inputFormat:l})=>{const[u,{open:c,close:d}]=oe.useDisclosure(!1),[h,p]=n,x=h?M(h).format(l):"",m=p?M(p).format(l):"";return s.jsxs(a.Popover,{opened:u,onClose:d,position:"bottom-start",shadow:"md",children:[s.jsxs(a.Group,{position:"left",grow:!0,noWrap:!0,spacing:0,w:"18em",sx:{marginTop:"3px"},children:[s.jsx(a.Popover.Target,{children:s.jsx(a.TextInput,{label:e,required:t,icon:s.jsx(_.IconCalendar,{size:16}),placeholder:"Start date",readOnly:!0,value:x,onFocus:c,styles:al(u),sx:{".mantine-Input-input":{borderRight:"none",borderTopRightRadius:0,borderBottomRightRadius:0}}})}),s.jsx(a.TextInput,{label:s.jsx(a.Group,{position:"right",children:s.jsx(r1,{begin:h,end:p})}),icon:s.jsx(_.IconMinus,{size:16}),placeholder:"End date",readOnly:!0,disabled:!h,value:m,onFocus:c,styles:al(u),sx:{".mantine-Input-icon":{transform:"translateX(-22px)"},".mantine-Input-input":{borderLeft:"none",borderTopLeftRadius:0,borderBottomLeftRadius:0},".mantine-Input-input[data-disabled]":{backgroundColor:"transparent",backgroundImage:"linear-gradient(to right, #fff 0%, #f1f3f5 30%)",opacity:1},".mantine-Input-input[data-disabled]::placeholder":{opacity:.6}}})]}),s.jsxs(a.Popover.Dropdown,{p:"sm",children:[s.jsx(i1,{max_days:i}),s.jsx(s1,{value:n,onChange:r,close:d,allowSingleDateInRange:o,max_days:i}),s.jsx(a1,{onChange:r})]})]})},ol=S.observer(({label:e,config:t,value:n=[null,null],onChange:r})=>{const{inputFormat:i,required:o,max_days:l,allowSingleDateInRange:u}=t,c=Array.isArray(n)?n.map(h=>h?M(h).toDate():null):[null,null],d=h=>{r(h.map(p=>p&&M(p).format(i)))};return s.jsx(o1,{label:e,value:c,onChange:d,inputFormat:i,allowSingleDateInRange:u,max_days:l,required:o})}),l1=a.createStyles((e,{radius:t=4})=>({root:{borderRadius:e.fn.radius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-select.rc-select-open":{borderColor:"#228be6 !important",".rc-select-selection-overflow-item-rest":{display:"none"},".rc-select-selection-overflow-item-suffix":{display:"block"}},".rc-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-select-selection-search-mirror":{display:"none"},".rc-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},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"}}})),ll=({errorMessage:e})=>e?s.jsx(a.Text,{color:"red",size:12,children:e}):s.jsx(a.Text,{color:"dimmed",size:12,children:"Not found"}),u1=({disabled:e,classNames:t,styles:n,unstyled:r,radius:i,style:o,label:l,value:u,onChange:c,options:d,errorMessage:h,required:p})=>{const{classes:x,cx:m}=l1({radius:i},{name:"MultiSelectWidget",classNames:t,styles:n,unstyled:r}),[j,C]=g.useState(!1),T=Q=>{C(Q)},D=j&&(u==null?void 0:u.length)>0,[A,F]=g.useState(""),X=g.useMemo(()=>{if(!A)return d;const Q=A.toLowerCase(),G=ee=>{var ae;return((ae=ee.description)==null?void 0:ae.toLowerCase().includes(Q))||ee.label.toLowerCase().includes(Q)};return d.filter(G)},[A,d]);return s.jsxs(a.Stack,{spacing:3,children:[s.jsxs(a.Group,{position:"apart",children:[s.jsxs(a.Text,{className:x.label,children:[l,p&&s.jsx("span",{className:x.required,"aria-hidden":"true",children:"*"})]}),D&&s.jsx(a.Tooltip,{label:`${u.length} selected`,children:s.jsx(a.Badge,{children:u.length})})]}),s.jsx(Ri,{disabled:e,allowClear:!0,className:m(x.root,"check-select"),dropdownClassName:m(x.dropdown,""),onDropdownVisibleChange:T,transitionName:"rc-select-dropdown-slide-up",choiceTransitionName:"rc-select-selection__choice-zoom",style:o,clearIcon:()=>s.jsx(a.CloseButton,{}),value:u,onChange:c,onSelect:console.log,mode:"multiple",maxTagCount:0,notFoundContent:s.jsx(ll,{errorMessage:h}),maxTagTextLength:10,maxTagPlaceholder:Q=>`${Q.length} selected`,searchValue:A,onSearch:F,filterOption:!1,children:X.map(Q=>s.jsxs(Ri.Option,{title:Q.label,children:[s.jsx(a.Text,{size:"sm","data-role":"label",children:Q.label}),Q.description&&s.jsx(a.Text,{size:"xs",color:"dimmed","data-role":"description",children:Q.description})]},Q.value))})]})},c1=S.observer(({label:e,config:t,value:n,onChange:r})=>{const i=pe(),o=!!t.options_query_id,{state:l,error:u}=i.getDataStuffByID(t.options_query_id),c=l==="loading",d=t.min_width?t.min_width:"200px",h=o?c:!1,p=x=>r(x,!1);return s.jsx(u1,{label:e,options:t.options,style:{minWidth:"160px",width:d,maxWidth:h?d:"unset",borderColor:"#e9ecef"},disabled:h,value:n,onChange:p,errorMessage:u,required:t.required})}),d1=g.forwardRef(({label:e,description:t,...n},r)=>s.jsx("div",{ref:r,...n,children:s.jsx(a.Group,{noWrap:!0,children:s.jsxs("div",{children:[s.jsx(a.Text,{size:"sm","data-role":"label",children:e}),s.jsx(a.Text,{size:"xs",color:"dimmed","data-role":"description",children:t})]})})})),p1=S.observer(({label:e,config:t,value:n,onChange:r})=>{const i=pe(),o=!!t.options_query_id,{state:l,error:u}=i.getDataStuffByID(t.options_query_id),c=l==="loading";return s.jsx(a.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:d1})});function h1({label:e,config:t,value:n,onChange:r}){return s.jsx(a.TextInput,{label:e,value:n||"",onChange:i=>r(i.currentTarget.value),...t,styles:{input:{borderColor:"#e9ecef"}}})}const x1=({rotate:e,onClick:t})=>s.jsx("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:s.jsx("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"})}),f1=({expanded:e,isLeaf:t,value:n,onClick:r,...i})=>(n==="0-0-value"&&console.log(i),t?s.jsx("span",{style:{width:"14px",display:"inline-block"}}):s.jsx(x1,{rotate:e?"0":"-90",onClick:r,...i})),g1=({onClick:e})=>s.jsxs("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:[s.jsx("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),s.jsx("rect",{className:"border",x:"4",y:"4",width:"16",height:"16",rx:"2"}),s.jsx("rect",{className:"checkmark-indeterminate",x:"8",y:"8",width:"8",height:"8",rx:"2",stroke:"none"}),s.jsx("path",{className:"checkmark-checked",d:"M9 12l2 2l4 -4"})]}),m1=({onClick:e,...t})=>s.jsx(g1,{onClick:e,...t}),y1=a.createStyles((e,{radius:t=4})=>({root:{borderRadius:e.fn.radius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-tree-select.rc-tree-select-open":{borderColor:"#228be6 !important",".rc-tree-select-selection-overflow-item-rest":{display:"none"},".rc-tree-select-selection-overflow-item-suffix":{display:"block"}},".rc-tree-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-tree-select-selection-search-mirror":{display:"none"},".rc-tree-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-tree-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-tree-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-tree-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-tree-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-tree-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-tree-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-tree-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},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"}}}})),b1=({disabled:e,classNames:t,styles:n,unstyled:r,radius:i,style:o,label:l,value:u,onChange:c,treeData:d,errorMessage:h,required:p,treeCheckStrictly:x})=>{const{classes:m,cx:j}=y1({radius:i},{name:"FilterTreeSelectWidget",classNames:t,styles:n,unstyled:r}),[C,T]=g.useState(!1),D=F=>{T(F)},A=C&&(u==null?void 0:u.length)>0;return s.jsxs(a.Stack,{spacing:3,children:[s.jsxs(a.Group,{position:"apart",children:[s.jsxs(a.Text,{className:m.label,children:[l,p&&s.jsx("span",{className:m.required,"aria-hidden":"true",children:"*"})]}),A&&s.jsx(a.Tooltip,{label:`${u.length} selected`,children:s.jsx(a.Badge,{children:u.length})})]}),s.jsx(Qi,{disabled:e,allowClear:!0,treeCheckStrictly:x,labelInValue:!0,className:j(m.root,"check-select"),dropdownClassName:j(m.dropdown,""),onDropdownVisibleChange:D,transitionName:"rc-tree-select-dropdown-slide-up",choiceTransitionName:"rc-tree-select-selection__choice-zoom",style:o,listHeight:510,treeLine:!0,clearIcon:()=>s.jsx(a.CloseButton,{}),switcherIcon:f1,treeIcon:m1,maxTagTextLength:10,value:u,treeData:d,notFoundContent:s.jsx(ll,{errorMessage:h}),treeNodeFilterProp:"filterBasis",treeCheckable:!0,showCheckedStrategy:Qi.SHOW_PARENT,onChange:c,onSelect:console.log,maxTagCount:0,maxTagPlaceholder:()=>`${u.length} selected`})]})},j1=S.observer(({label:e,config:t,value:n,onChange:r})=>{const{treeData:i,treeDataLoading:o,errorMessage:l}=t,u=x=>{const m=x.map(j=>j.value);r(m,!1)},c=g.useMemo(()=>t.initialSelection(n),[n,t.plainData,t.defaultSelection,t.initialSelection]),d=t.min_width?t.min_width:"200px",p=!!t.options_query_id?o:!1;return s.jsx(b1,{disabled:p,style:{minWidth:"160px",width:d,maxWidth:p?d:"unset",borderColor:"#e9ecef"},value:[...c],onChange:u,treeData:i,errorMessage:l,label:e,required:t.required,treeCheckStrictly:t.treeCheckStrictly})}),v1=S.observer(({filter:{type:e,config:t,key:n,...r},formFieldProps:i})=>{switch(e){case"select":return s.jsx(p1,{...r,...i,config:t});case"multi-select":return s.jsx(c1,{...r,...i,config:t});case"tree-select":return s.jsx(j1,{...r,...i,config:t});case"text-input":return s.jsx(h1,{...r,...i,config:t});case"date-range":return s.jsx(ol,{...r,...i,config:t});case"checkbox":return s.jsx(n1,{...r,...i,config:t});default:return null}}),w1=S.observer(g.forwardRef(({filter:e,...t},n)=>s.jsx("div",{className:"filter-root",ref:n,children:s.jsx(we,{children:s.jsx(v1,{filter:e,formFieldProps:t})})}))),C1=({disabled:e})=>{const{searchButtonProps:t}=ha(),{children:n="Search",type:r,...i}=t;return s.jsx(a.Button,{color:"blue",size:"sm",type:"submit",...i,disabled:e||i.disabled,children:n})};function S1(e){const t=R();g.useEffect(()=>{var n,r;(r=(n=t.filters).updatePreviewValues)==null||r.call(n,e)},[e])}const _1=({opened:e,toggle:t})=>s.jsx(a.Group,{position:"right",ml:-4,mt:-4,mb:e?4:0,children:s.jsx(a.Button,{size:"xs",compact:!0,variant:"subtle",color:e?"gray":"blue",leftIcon:e?s.jsx(_.IconChevronsUp,{size:14}):s.jsx(_.IconChevronsDown,{size:14}),onClick:t,children:e?"Hide Filters":"Show Filters"})}),ul=S.observer(function({view:t}){const[n,{toggle:r}]=oe.useDisclosure(!0),i=pe(),{control:o,handleSubmit:l,reset:u}=b.useForm({defaultValues:i.filters.values,reValidateMode:"onBlur"}),c=b.useWatch({control:o});g.useEffect(()=>{u(i.filters.values)},[i.filters.values,u]),S1(c);const d=i.filters.visibleInView(t.id),h=g.useMemo(()=>d.every(j=>j.should_auto_submit),[d]),p=g.useMemo(()=>d.filter(j=>y.get(j,"config.required",!1)),[d]),x=g.useMemo(()=>p.length===0?!1:p.some(j=>!j.requiredAndPass(c[j.key])),[c,p]);if(d.length===0)return null;const m=(j,C)=>(T,D)=>{C(T),(j.should_auto_submit||D)&&i.filters.setValueByKey(j.key,T)};return s.jsxs("form",{onSubmit:l(i.filters.setValues),children:[s.jsx(_1,{opened:n,toggle:r}),s.jsx(a.Collapse,{in:n,children:s.jsxs(a.Group,{className:"dashboard-filters",position:"apart",noWrap:!0,sx:h?{}:{border:"1px solid #e9ecef",borderRadius:"4px",padding:"16px"},children:[s.jsx(a.Group,{align:"flex-start",children:d.map(j=>s.jsx(b.Controller,{name:j.key,control:o,render:({field:C})=>s.jsx(w1,{filter:j,value:C.value,onChange:m(j,C.onChange)})},j.id))}),!h&&s.jsx(a.Group,{sx:{alignSelf:"flex-end"},children:s.jsx(C1,{disabled:x})})]})})]})}),k1={viewPanelInFullScreen:y.noop,inFullScreen:!1},Zn=g.createContext(k1),Mr=f.types.model("MockContextMeta",{current:f.types.optional(f.types.frozen(),{})}).views(e=>({get keys(){return Object.keys(e.current)},get keySet(){return new Set(this.keys)},get entries(){return Object.entries(e.current)}})).actions(e=>({replace(t){e.current=t},defaults(t){e.current={...t,...e.current}},get(t){return e.current[t]},set(t,n){e.current[t]=n}}));function zr(e){return{current:e}}const T1=f.types.model("PanelStyleBorderMeta",{enabled:f.types.boolean}).views(e=>({get json(){const{enabled:t}=e;return{enabled:t}}})).actions(e=>({setEnabled(t){e.enabled=t}})),cl=f.types.model("PanelStyleMeta",{border:T1}).views(e=>({get json(){const{border:t}=e;return{border:t.json}}})).actions(e=>({})),dl=f.types.model("PanelTitleMeta",{show:f.types.optional(f.types.boolean,!0)}).views(e=>({get json(){const{show:t}=e;return{show:t}}})).actions(e=>({setShow(t){e.show=t}})),pl=f.types.model("VariableMeta",{name:f.types.string,size:f.types.string,weight:f.types.string,color:f.types.union(f.types.model({type:f.types.literal("static"),staticColor:f.types.string}),f.types.model({type:f.types.literal("continuous"),valueRange:f.types.array(f.types.number),colorRange:f.types.array(f.types.string)}),f.types.model({type:f.types.literal("piecewise")})),formatter:f.types.model({output:f.types.enumeration("Output",["number","percent"]),average:f.types.optional(f.types.boolean,!1),mantissa:f.types.number,trimMantissa:f.types.optional(f.types.boolean,!1),absolute:f.types.optional(f.types.boolean,!1)}),data_field:f.types.string,aggregation:f.types.union(f.types.model({type:f.types.enumeration(["none","sum","mean","median","min","max","CV","std"]),config:f.types.frozen(),fallback:f.types.optional(f.types.string,"0")}),f.types.model({type:f.types.literal("quantile"),config:f.types.model({p:f.types.number}),fallback:f.types.optional(f.types.string,"0")}),f.types.model({type:f.types.literal("custom"),config:f.types.model({func:f.types.string}),fallback:f.types.optional(f.types.string,"0")}))}).views(e=>({get json(){const{name:t,size:n,weight:r,color:i,formatter:o,data_field:l,aggregation:u}=e;return y.cloneDeep({name:t,size:n,color:i,weight:r,formatter:o,data_field:l,aggregation:u})}})),hl=f.types.model("PanelVizMeta",{type:f.types.string,conf:f.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}})),xl=f.types.model({id:f.types.string,name:f.types.optional(f.types.string,""),title:dl,description:f.types.string,queryIDs:f.types.array(f.types.string),viz:hl,style:cl,variables:f.types.optional(f.types.array(pl),[])}).views(e=>({get json(){const{id:t,name:n,title:r,description:i,queryIDs:o}=e;return{id:t,viz:e.viz.json,name:n,style:e.style.json,title:r.json,queryIDs:[...o],variables:e.variables.map(l=>l.json),description:i}},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=f.cast(Array.from(n))},setQueryIDs(t){e.queryIDs=f.cast(t)},addVariable(t){e.variables.push(t)},removeVariable(t){e.variables.remove(t)}}));var ce=(e=>(e.Postgresql="postgresql",e.MySQL="mysql",e.HTTP="http",e.Transform="transform",e))(ce||{});const fl=f.types.model("QueryMeta",{id:f.types.string,name:f.types.string,type:f.types.enumeration("DataSourceType",[ce.Postgresql,ce.MySQL,ce.HTTP,ce.Transform]),key:f.types.string,sql:f.types.string,pre_process:f.types.optional(f.types.string,""),post_process:f.types.optional(f.types.string,""),run_by:f.types.optional(f.types.array(f.types.string),[]),react_to:f.types.optional(f.types.array(f.types.string),[]),dep_query_ids:f.types.optional(f.types.array(f.types.string),[])}).views(e=>({get valid(){return e.id&&e.type&&e.key&&e.name?e.type===ce.HTTP?!!e.pre_process:!!e.sql:!1},get json(){const{id:t,name:n,type:r,key:i,sql:o,run_by:l,react_to:u,pre_process:c,post_process:d,dep_query_ids:h}=e;return Et({id:t,key:i,sql:o,name:n,type:r,run_by:l,react_to:u,pre_process:c,post_process:d,dep_query_ids:h})}})).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},setDependantQueryIDs(t){e.dep_query_ids.length=0,e.dep_query_ids.push(...t)}})),gl=f.types.model("LayoutItemMeta",{id:f.types.identifier,panelID:f.types.string,x:f.types.number,y:f.types.maybeNull(f.types.number),w:f.types.number,h:f.types.number,moved:f.types.optional(f.types.boolean,!1),static:f.types.optional(f.types.boolean,!1)}).views(e=>({get json(){const{id:t,panelID:n,x:r,y:i,w:o,h:l,moved:u}=e;return{h:l,w:o,x:r,y:i===null?0:i,id:t,moved:u,static:e.static,panelID:n}},get contentModel(){return f.getRoot(e).content},get panel(){const{panelID:t}=e;return this.contentModel.panels.findByID(t)},get layoutProperies(){const{id:t,x:n,y:r,w:i,h:o,moved:l}=e;return{id:t,i:t,x:n,y:r===null?1/0:r,w:i,h:o,moved:l,static:e.static}}})).actions(e=>({set(t){const{isDraggable:n,x:r,y:i,w:o,h:l,moved:u}=t;e.x=r,e.y=i,e.w=o,e.h=l,e.moved=!!u,e.static=!!t.static},setWidth(t){e.w=t},setHeight(t){e.h=t}})),ml=f.types.model("LayoutSetMeta",{id:f.types.identifier,name:f.types.string,breakpoint:f.types.number,list:f.types.optional(f.types.array(gl),[])}).views(e=>({get json(){const{id:t,name:n,breakpoint:r,list:i}=e;return{id:t,name:n,breakpoint:r,list:i.map(o=>Et(o.json))}},jsonByPanelIDSet(t){const{id:n,name:r,breakpoint:i,list:o}=e;return{id:n,name:r,breakpoint:i,list:o.filter(l=>t.has(l.panelID)).map(l=>Et(l.json))}},findByID(t){return e.list.find(n=>n.id===t)},findByPanelID(t){return e.list.find(n=>n.panelID===t)}})).actions(e=>({setName(t){e.name=t},setBreakpoint(t){e.breakpoint=t},addLayout(t){e.list.push(t)},addNewLayout(t){e.list.push({id:ht.v4(),panelID:t,x:0,y:1/0,w:18,h:300,static:!1,moved:!1})},removeByPanelID(t){const n=e.list.findIndex(r=>r.panelID===t);n>=0&&e.list.splice(n,1)},updateLayoutItem(t){const n=e.list.find(r=>r.id===t.i);if(!n){console.error("Trying to update a layout that doesn't exist"),console.log({strangeLayoutItem:t});return}n.set(t)}})),yl=f.types.model("SQLSnippetMeta",{key:f.types.string,value:f.types.string}).views(e=>({get json(){const{key:t,value:n}=e;return{key:t,value:n}}})).actions(e=>({setKey(t){e.key=t},setValue(t){e.value=t}}));var xe=(e=>(e.Select="select",e.MultiSelect="multi-select",e.TreeSelect="tree-select",e.TextInput="text-input",e.Checkbox="checkbox",e.DateRange="date-range",e))(xe||{});const Ar=f.types.model("FilterCheckboxConfigMeta",{_name:f.types.literal("checkbox"),description:f.types.optional(f.types.string,""),default_value:f.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}})),bl=()=>Ar.create({_name:"checkbox",description:"",default_value:!1});function jl(e,t){return e.map(n=>{try{return n?M.tz(n,"UTC").format(t):null}catch{return console.log(`[date-range] failed parsing ${n}`),null}})}const D1=f.types.model("FilterDateRangeConfigMeta",{_name:f.types.literal("date-range"),required:f.types.boolean,inputFormat:f.types.enumeration("DateRangeInputFormat",["YYYY","YYYYMM","YYYYMMDD","YYYY-MM","YYYY-MM-DD"]),default_value:f.types.optional(f.types.array(f.types.union(f.types.string,f.types.null)),[null,null]),default_shortcut:f.types.optional(f.types.string,""),clearable:f.types.boolean,max_days:f.types.optional(f.types.number,0),allowSingleDateInRange:f.types.optional(f.types.boolean,!1)}).views(e=>({get json(){const{_name:t,max_days:n,required:r,clearable:i,inputFormat:o,default_value:l,default_shortcut:u,allowSingleDateInRange:c}=e;return{_name:t,max_days:n,required:r,clearable:i,inputFormat:o,default_value:jl(l,o),default_shortcut:u,allowSingleDateInRange:c}},truthy(t){return Array.isArray(t)&&t.length===2&&t.every(n=>!!n)}})).actions(e=>({setFilterValue(t){try{const n=f.getParent(e);f.getParent(n,2).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)},setDefaultShortcut(t){if(e.default_shortcut=t,!t)return;const n=il(e.default_shortcut);if(console.log(n),n){const r=n.map(i=>M(i).format(e.inputFormat));e.setFilterValue(r)}},setMaxDays(t){e.max_days=t,t>0&&(e.clearable=!0)},setAllowSingleDateInRange(t){e.allowSingleDateInRange=t}})),Er=f.types.snapshotProcessor(D1,{preProcessor({default_value:e,...t}){return{...t,default_value:e.map(n=>n===null?null:M.tz(n,"UTC").toISOString())}},postProcessor(e){const{default_value:t,...n}=e;return{...n,default_value:jl(t,n.inputFormat)}}}),vl=()=>Er.create({_name:"date-range",required:!1,inputFormat:"YYYY-MM-DD",clearable:!1,default_value:[null,null]}),I1=f.types.model({label:f.types.string,value:f.types.string}).actions(e=>({setLabel(t){e.label=t},setValue(t){e.value=t}})),Lr=f.types.model("FilterConfigModel_BaseSelect",{static_options:f.types.optional(f.types.array(I1),[]),options_query_id:f.types.optional(f.types.string,""),default_selection_count:f.types.optional(f.types.number,0),required:f.types.optional(f.types.boolean,!1)}).views(e=>({get contentModel(){return f.getRoot(e).content},get filter(){return f.getParent(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}=e.contentModel.getDataStuffByID(e.options_query_id);return n==="idle"?Array.isArray(t)?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??""}})),Pr=f.types.compose("FilterMultiSelectConfigMeta",f.types.model({_name:f.types.literal("multi-select"),min_width:f.types.optional(f.types.string,""),default_value:f.types.optional(f.types.array(f.types.string),[])}),Lr).views(e=>({get json(){const{_name:t,default_value:n,required:r,min_width:i,static_options:o,options_query_id:l,default_selection_count:u}=e;return Et({_name:t,required:!!r,min_width:i,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.filter.formattedDefaultValue},truthy(t){return Array.isArray(t)&&t.length>0}})).actions(e=>({setDefaultValue(t){e.default_value=f.cast(t)},setMinWidth(t){e.min_width=t},setDefaultSelection(){const t=f.getRoot(e).content.filters,n=f.getParent(e).key;t.setValueByKey(n,e.default_selection)}})).actions(e=>({afterCreate(){f.addDisposer(e,K.reaction(()=>K.toJS(e.default_selection),e.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),wl=()=>Pr.create({_name:"multi-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),Br=f.types.compose("FilterConfigModel_Select",f.types.model({_name:f.types.literal("select"),default_value:f.types.string,width:f.types.optional(f.types.string,"")}),Lr).views(e=>({get json(){const{_name:t,default_value:n,required:r,width:i,static_options:o,options_query_id:l,default_selection_count:u}=e;return Et({_name:t,width:i,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.filter.formattedDefaultValue}})).actions(e=>({setDefaultValue(t){e.default_value=t},setWidth(t){e.width=t},setDefaultSelection(){const t=f.getRoot(e).content.filters,n=f.getParent(e).key;t.setValueByKey(n,e.default_selection)}})).actions(e=>({afterCreate(){f.addDisposer(e,K.reaction(()=>K.toJS(e.default_selection),e.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),Cl=()=>Br.create({_name:"select",required:!1,default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),Or=f.types.model("FilterTextInputConfigMeta",{_name:f.types.literal("text-input"),required:f.types.boolean,default_value:f.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}})),$r=()=>Or.create({_name:"text-input",required:!1,default_value:""});function M1(e){return xc.arrayToTree(e,{id:"value",parentId:"parent_value",childrenField:"children",dataField:null})}function z1(e){return e.map(t=>{const{label:n,description:r,...i}=t,o={...i,filterBasis:`${n}___${r??""}`,description:r,label:n};return r&&(o.label=g.createElement("div",{},[g.createElement(a.Text,{key:0,title:t.label},t.label),g.createElement(a.Text,{key:1,className:"rc-tree-select-tree-title-desc",color:"dimmed",title:t.description},t.description)])),o})}const Vr=f.types.compose("FilterTreeSelectConfigMeta",f.types.model({_name:f.types.literal("tree-select"),min_width:f.types.optional(f.types.string,""),default_value:f.types.optional(f.types.array(f.types.string),[]),treeCheckStrictly:f.types.optional(f.types.boolean,!1)}),Lr).views(e=>({get json(){const{_name:t,default_value:n,required:r,min_width:i,static_options:o,options_query_id:l,default_selection_count:u,treeCheckStrictly:c}=e;return{_name:t,required:!!r,min_width:i,default_value:n,static_options:o,options_query_id:l,treeCheckStrictly:c,default_selection_count:u}},get plainData(){const{data:t}=e.contentModel.getDataStuffByID(e.options_query_id);return t},get treeData(){const t=this.plainData,n=z1(t);return M1(n)},get errorMessage(){const{error:t}=e.contentModel.getDataStuffByID(e.options_query_id);return t},get treeDataLoading(){const{state:t}=e.contentModel.getDataStuffByID(e.options_query_id);return t==="loading"},get defaultSelection(){const t=e.filter.formattedDefaultValue;if(Array.isArray(t)&&t.length>0)return t;const{default_selection_count:n}=e;return n?this.treeData.slice(0,n).map(i=>i.value):[]},valueObjects(t){const n=new Set(t);return this.plainData.filter(r=>n.has(r.value))},initialSelection(t){return!t||t.length===0?this.valueObjects(this.defaultSelection):this.valueObjects(t)},truthy(t){return Array.isArray(t)&&t.length>0}})).actions(e=>({setDefaultValue(t){e.default_value=f.cast(t)},setMinWidth(t){e.min_width=t},setTreeCheckStrictly(t){e.treeCheckStrictly=t},applyDefaultSelection(){const t=f.getParent(e,1).key;e.contentModel.filters.setValueByKey(t,e.defaultSelection)},afterCreate(){f.addDisposer(e,K.reaction(()=>JSON.stringify(e.defaultSelection),this.applyDefaultSelection,{fireImmediately:!0,delay:0}))}})),Sl=()=>Vr.create({_name:"tree-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),qr=f.types.model("FilterMeta",{id:f.types.identifier,key:f.types.string,label:f.types.string,order:f.types.number,visibleInViewsIDs:f.types.array(f.types.string),auto_submit:f.types.optional(f.types.boolean,!1),default_value_func:f.types.optional(f.types.string,""),type:f.types.enumeration("DashboardFilterType",[xe.Select,xe.MultiSelect,xe.TreeSelect,xe.TextInput,xe.Checkbox,xe.DateRange]),config:f.types.union(Br,Pr,Vr,Or,Ar,Er)}).views(e=>({get contentModel(){return f.getRoot(e).content},get filters(){return this.contentModel.filters},get plainDefaultValue(){const t=e.config.default_value;return Array.isArray(t)?[...t]:t},get usingDefaultValue(){return e.type!==xe.TreeSelect},get usingDefaultValueFunc(){return!!e.default_value_func},get formattedDefaultValue(){return this.filters.formattedDefaultValues[e.key]},get auto_submit_supported(){return[xe.Select,xe.Checkbox,xe.DateRange].includes(e.type)}})).views(e=>({get json(){const{id:t,key:n,label:r,order:i,visibleInViewsIDs:o,default_value_func:l,auto_submit:u,type:c,config:d}=e;return{id:t,key:n,type:c,label:r,order:i,config:d.json,auto_submit:u,visibleInViewsIDs:K.toJS(o),default_value_func:l}},get visibleInViewsIDSet(){return new Set(e.visibleInViewsIDs)},get should_auto_submit(){return e.auto_submit_supported&&e.auto_submit},requiredAndPass(t){return y.get(e.config,"required",!1)?y.get(e.config,"truthy",()=>!0)(t):!1}})).actions(e=>({setKey(t){e.key=t},setLabel(t){e.label=t},setOrder(t){e.order=t},setType(t){switch(t){case xe.Select:e.config=Cl();break;case xe.MultiSelect:e.config=wl();break;case xe.TreeSelect:e.config=Sl();break;case xe.TextInput:e.config=$r();break;case xe.Checkbox:e.config=bl();break;case xe.DateRange:e.config=vl();break}e.type=t},setVisibleInViewsIDs(t){e.visibleInViewsIDs.length=0,e.visibleInViewsIDs.push(...t)},setAutoSubmit(t){e.auto_submit=e.auto_submit_supported&&t},setDefaultValueFunc(t){e.default_value_func=t}}));var P=(e=>(e.Division="div",e.Modal="modal",e.Tabs="tabs",e))(P||{});const Nr=f.types.model("ViewDivisionConfig",{_name:f.types.literal(P.Division)}).views(e=>({get json(){const{_name:t}=e;return{_name:t}}})),_l=()=>Nr.create({_name:P.Division}),A1=f.types.model("CustomModalTitleModel",{enabled:f.types.optional(f.types.boolean,!1),func_content:f.types.optional(f.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=f.getParent(e,2),i=f.getRoot(e);if(!t)return r.name;try{const o={filters:i.content.filters.values,context:i.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}})),Hn={enabled:!1,func_content:["function text({ filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
450
- `)},Fr=f.types.model("ViewModalConfig",{_name:f.types.literal(P.Modal),width:f.types.string,height:f.types.string,custom_modal_title:f.types.optional(A1,Hn)}).views(e=>({get json(){const{_name:t,width:n,height:r,custom_modal_title:i}=e;return{_name:t,width:n,height:r,custom_modal_title:i.json}}})).actions(e=>({setWidth(t){e.width=t},setHeight(t){e.height=t}})),kl=()=>Fr.create({_name:P.Modal,width:"90vw",height:"90vh"}),E1=f.types.model("ViewTabsTabModel",{id:f.types.identifier,name:f.types.string,view_id:f.types.string,color:f.types.optional(f.types.string,""),order:f.types.optional(f.types.number,0)}).views(e=>({get json(){const{id:t,name:n,view_id:r,color:i,order:o}=e;return{id:t,name:n,color:i,order:o,view_id:r}}})).actions(e=>({setName(t){e.name=t},setViewID(t){e.view_id=t},setColor(t){e.color=t},setOrder(t){e.order=t}})),Gr=f.types.model("ViewTabsConfig",{_name:f.types.literal(P.Modal),tabs:f.types.optional(f.types.array(E1),[]),variant:f.types.optional(f.types.enumeration("variant",["default","outline","pills"]),"default"),orientation:f.types.optional(f.types.enumeration("orientation",["horizontal","vertical"]),"horizontal"),grow:f.types.optional(f.types.boolean,!1)}).views(e=>({get json(){const{_name:t,variant:n,orientation:r,tabs:i,grow:o}=e;return{grow:o,tabs:i.map(l=>l.json),_name:t,variant:n,orientation:r}},get tabsInOrder(){return y.sortBy(e.tabs,"order")}})).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=f.cast(t)},addTab(){const t=oe.randomId(),n={id:t,name:t,view_id:""};e.tabs.push(n)},removeTab(t){e.tabs.splice(t,1)}})),Tl=()=>Gr.create({_name:P.Modal,tabs:[]}),Dl=f.types.model({id:f.types.identifier,name:f.types.string,type:f.types.enumeration("EViewComponentType",[P.Division,P.Modal,P.Tabs]),config:f.types.union(Nr,Fr,Gr),panelIDs:f.types.optional(f.types.array(f.types.string),[])}).views(e=>({get json(){const{id:t,name:n,type:r,config:i}=e;return{id:t,name:n,type:r,config:i.json,panelIDs:e.panelIDs.map(o=>o)}}})).actions(e=>({setName(t){e.name=t},setType(t){if(e.type!==t){switch(t){case P.Division:e.config=_l();break;case P.Modal:e.config=kl();break;case P.Tabs:e.config=Tl();break}e.type=t}},appendPanelID(t){e.panelIDs.push(t)},appendPanelIDs(t){e.panelIDs.push(...t)},removePanelID(t){const n=e.panelIDs.filter(r=>r!==t);e.panelIDs.length=0,e.panelIDs.push(...n)}})),lt="11.10.0",L1={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:P.Division,config:{},panelIDs:[]}],panels:[],filters:[],version:lt,layouts:[{id:"basis",name:"basis",list:[],breakpoint:0}]},Wr=f.types.model("DataSourceMetaModel",{id:f.types.string,type:f.types.enumeration("DataSourceType",[ce.HTTP,ce.MySQL,ce.Postgresql]),key:f.types.string,config:f.types.frozen()}),Il=f.types.model("DataSourcesMetaModel",{list:f.types.optional(f.types.array(Wr),[])}).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)}})),Ml=f.types.model({id:f.types.string,content:f.types.string,create_time:f.types.string,update_time:f.types.string,is_preset:f.types.boolean}),Rr=f.types.model("GlobalSQLSnippetsMeta",{list:f.types.optional(f.types.array(Ml),[])}).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)}})),es=f.types.model("ContextMeta",{current:f.types.optional(f.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 Qr(e){return es.create({current:e})}const Ur=f.types.compose("ViewRenderModel",Dl,f.types.model({tab:f.types.optional(f.types.string,"")})).views(e=>({get defaultTab(){if(e.type!==P.Tabs)return"";const t=e.config;return t.tabs.length>0?t.tabs[0].id:""},get tabViewID(){var n;return e.type!==P.Tabs?"":((n=e.config.tabs.find(r=>r.id===e.tab))==null?void 0:n.view_id)??""},get contentModel(){return f.getParent(e,3)},get panels(){if(e.type!==P.Tabs)return this.contentModel.panels.panelsByIDs(e.panelIDs);const t=this.tabViewID,n=this.contentModel.views.findByID(t);return(n==null?void 0:n.panels)??[]},get renderViewIDs(){const t=[e.id];return e.type===P.Tabs&&t.push(this.tabViewID),t},async downloadScreenshot(t){const n=t.offsetWidth*2+10,r=t.offsetHeight*2+10,i=new Ki,o=new Date().getTime(),l=await Ui.toBlob(t,{bgcolor:"white",width:n,height:r,style:{transformOrigin:"0 0",transform:"scale(2)"}});i.file(`${e.name}_${o}.png`,l),i.file(`dashboard_state_${o}.json`,JSON.stringify(this.contentModel.dashboardState,null,4)),i.generateAsync({type:"blob"}).then(u=>{mn.saveAs(u,`${e.name}_${o}.zip`)}).catch(u=>{console.error(u),dt.notifications.show({color:"red",title:"Failed to download screenshot with dashboard state",message:u.message})})}})).actions(e=>({setTab(t){e.tab=t??""},afterCreate(){f.addDisposer(e,K.reaction(()=>e.defaultTab,t=>this.setTab(t),{fireImmediately:!0,delay:0}))}})),Kr=f.types.model("ViewsRenderModel",{current:f.types.optional(f.types.array(Ur),[]),visibleViewIDs:f.types.array(f.types.string)}).views(e=>({get json(){return e.current.map(t=>Et(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 zl(e){const t=e.length>0?[e[0].id]:[];return{current:e.map(r=>{const{_name:i=r.type}=r.config;return{...r,config:{...r.config,_name:i},panelIDs:r.panelIDs}}),visibleViewIDs:t}}const P1=new fc.AsyncParser({withBOM:!0});async function Al(e){return!Array.isArray(e)||e.length===0?"":await P1.parse(e).promise()}async function B1(e,t){const n=await Al(t),r=new Blob([n],{type:"text/csv"});mn.saveAs(r,`${e}.csv`)}function El(e){const t=new Ki,n=e.map(async({id:r,data:i})=>{const o=await Al(i);t.file(`${r}.csv`,o)});Promise.all(n).then(()=>{t.generateAsync({type:"blob"}).then(r=>{mn.saveAs(r,"dashboard_data.zip")})}).catch(r=>{console.error(r),dt.notifications.show({color:"red",title:"Failed to download data",message:r.message})})}function Ft(e,t){const n=new Blob([t],{type:"application/json"});mn.saveAs(n,`${e}.json`)}const Yr=xl.views(e=>({get contentModel(){return f.getRoot(e).content}})).views(e=>({get queries(){return e.contentModel.queries.findByIDSet(e.queryIDSet)},queryByID(t){return this.queries.find(n=>n.id===t)},get data(){return this.queries.reduce((t,n)=>(t[n.id]=n.data,t),{})},get variableStrings(){return na(e.variables,this.data)},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 i=[];return n.size>0&&(console.log(n),i.push(`context: ${Array.from(n).join(", ")}`)),r.size>0&&i.push(`filter${r.size>1?"s":""}: ${Array.from(r).join(", ")}`),i.length===2&&i.splice(1,0,"and"),i.unshift("Waiting for"),i.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(){e.contentModel.queries.downloadDataByQueryIDs(e.queryIDs)},getSchema(){const t=e.json;return t.viz.conf={...t.viz.conf,__INTERACTIONS:{},__OPERATIONS:{},__TRIGGERS:{}},{panel:t,queries:e.queries.map(n=>n.json),layouts:e.contentModel.layouts.jsonByPanelIDSet(new Set([e.id]))}},downloadSchema(){const{panel:t,queries:n,layouts:r}=this.getSchema(),o=JSON.stringify({panels:[t],definition:{queries:n},layouts:r,version:lt},null,2),l=e.name;Ft(l,o)}}));function Ll(e){return{id:e,name:e,title:{show:!0},description:"<p></p>",queryIDs:[],viz:{type:mr.name,conf:mr.createConfig()},style:{border:{enabled:!0}}}}const Xr=f.types.model("PanelsRenderModel",{list:f.types.optional(f.types.array(Yr),[])}).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=[];return t.forEach(r=>{const i=e.idMap.get(r);i?n.push(i):console.warn(`Panel is not found, id:${r}`)}),n}}));function Pl(e){const t=e.config,n=t.default_value;if(n===void 0)return n;if(t._name==="date-range")try{if(t.default_shortcut){const i=il(t.default_shortcut);if(i)return i.map(o=>M(o).format(t.inputFormat))}const[...r]=n;return r.map(i=>i===null?i:M.tz(i,"UTC").format(t.inputFormat)??i)}catch(r){return console.error(r),n}return n}function O1(e,t){const n=e.default_value_func;try{return new Function(`return ${n}`)()(e,rt,t)}catch(r){return console.error(r),Pl(e)}}function Bl(e,t){var n;return(n=e.default_value_func)!=null&&n.trim()?O1(e,t):Pl(e)}function Ol(e,t){return e.reduce((n,r)=>(n[r.key]=Bl(r,t),n),{})}const Jr=f.types.model("FiltersRenderModel",{current:f.types.optional(f.types.array(qr),[]),values:f.types.optional(f.types.frozen(),{})}).views(e=>({get json(){return e.current.map(t=>t.json)},get contentModel(){return f.getRoot(e).content},get context(){return this.contentModel.payloadForSQL.context},get initialValuesDep(){return JSON.stringify({filters:e.current.map(({default_value_func:t,config:n})=>({default_value_func:t,config:n})),context:this.contentModel.payloadForSQL.context})},get formattedDefaultValues(){return Ol(this.json,this.contentModel.context)},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 inOrder(){return y.sortBy(e.current,"order")},get empty(){return e.current.length===0},visibleInView(t){return y.sortBy(e.current.filter(n=>n.visibleInViewsIDSet.has(t)),"order")},get firstFilterValueKey(){return Object.keys(e.values)[0]??""},get keySet(){return new Set(e.current.map(t=>t.key))},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},patchValues(t){e.values=y.defaults({},t,e.values)},setValueByKey(t,n){e.values={...e.values,[t]:n}},getValueByKey(t){return e.values[t]},getSchema(t,n){return{filters:e.findByIDSet(new Set(t)).map(o=>({...o.json,visibleInViewsIDs:n?o.json.visibleInViewsIDs:[]})),version:lt}},downloadSchema(t){const n=JSON.stringify(this.getSchema(t,!1),null,2);Ft("Filters",n)}}));function Zr(e,t,n,r){const i=y.defaults({},r,Ol(e,{...n,...t}));return{current:e,values:i}}const $l=fl.views(e=>({get rootModel(){return f.getRoot(e)},get contentModel(){return this.rootModel.content},get conditionOptions(){if(!f.isAlive(e))return[];const{context:t}=this.contentModel.payloadForSQL,n=Object.keys(t).map(l=>({group:"Context",label:l,value:`context.${l}`,description:void 0})),r=this.contentModel.filters.keyLabelOptions.map(l=>({group:"Filters",label:l.label,value:`filters.${l.value}`,description:l.value})),i=[...n,...r],o=new Set(i.map(l=>l.value));return e.run_by.forEach(l=>{o.has(l)||i.push({group:"Invalid",label:l,value:l})}),i},get unmetRunByConditions(){if(!f.isAlive(e))return[];const{run_by:t}=e;if(t.length===0)return[];const n=this.contentModel.payloadForSQL;return t.filter(r=>{const i=y.get(n,r);return Array.isArray(i)?i.length===0:typeof i=="number"?Number.isNaN(i):!i})}})).views(e=>({get payload(){return e.contentModel.payloadForSQL},get formattedSQL(){return fs(e.sql,this.payload)},get httpConfigString(){const{context:t,filters:n}=this.payload,{name:r,pre_process:i}=e.json,o=Sd(i,t,n);return console.groupCollapsed(`Request config for: ${r}`),console.log(o),console.groupEnd(),JSON.stringify(o)},get typedAsSQL(){return[ce.Postgresql,ce.MySQL].includes(e.type)},get typedAsHTTP(){return[ce.HTTP].includes(e.type)},get isTransform(){return e.type===ce.Transform},get reQueryKey(){const{react_to:t=[]}=e;if(t.length===0)return"";const n=e.contentModel.payloadForSQL,r=[...t].reduce((i,o)=>(i[o]=y.get(n,o),i),{});return JSON.stringify(r)},get runByConditionsMet(){return e.unmetRunByConditions.length===0},get conditionNames(){if(e.unmetRunByConditions.length===0)return{context:[],filters:[]};const{keyLabelMap:t}=e.contentModel.filters,n=e.unmetRunByConditions.filter(i=>i.startsWith("context.")).map(i=>i.replace("context.","")),r=e.unmetRunByConditions.filter(i=>i.startsWith("filters.")).map(i=>y.get({filters:t},i,i.replace("filters.",""))).filter(i=>!!i);return{context:n,filters:r}},get queries(){return f.getParent(e,2)},get inUse(){return this.queries.isQueryInUse(e.id)},get dependencies(){if(!this.typedAsSQL)return[];const t=y.uniq(e.sql.match(vn.sqlSnippet)),n=y.uniq(e.sql.match(vn.filter)),r=y.uniq(e.sql.match(vn.context)),i=[];return t.forEach(o=>{i.push({type:"SQL Snippet",key:o,valid:e.contentModel.sqlSnippets.keySet.has(o)})}),n.forEach(o=>{i.push({type:"Filter",key:o,valid:e.contentModel.filters.keySet.has(o)})}),r.forEach(o=>{i.push({type:"Context",key:o,valid:e.contentModel.mock_context.keySet.has(o)})}),i}})),Hr=f.types.compose("QueryRenderModel",$l,f.types.model({state:f.types.optional(f.types.enumeration(["idle","loading","error"]),"idle"),data:f.types.optional(f.types.frozen([]),[]),error:f.types.frozen()})).views(e=>({get datasource(){const{key:t,type:n}=e;return e.rootModel.datasources.find({type:n,key:t})},get additionalQueryInfo(){return e.contentModel.getAdditionalQueryInfo(e.id)},get depQueryModels(){return e.contentModel.queries.findByIDSet(new Set(e.dep_query_ids))},get depQueryModelStates(){return this.depQueryModels.map(t=>t.state)},get depQueryModelStatesString(){return this.depQueryModelStates.toString()}})).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:f.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*f.toGenerator(Id({payload:n,name:e.name,query:e.json,additionals:e.additionalQueryInfo},e.controller.signal)),e.state="idle",e.error=null}catch(n){if(!nt.isCancel(n)){e.data=[];const r=y.get(n,"message","unkown error");e.error=y.get(n,"response.data.detail.message",r),e.state="error"}}}}),runHTTP:f.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:i}=e.json;let o=JSON.parse(e.httpConfigString);o=_d(e.datasource,o);const l=yield*f.toGenerator(Md({type:n,key:r,configString:JSON.stringify(o),name:e.name,additionals:e.additionalQueryInfo},e.controller.signal)),u=kd(e.datasource,l),c=Td(i,u,e.contentModel.dashboardState);e.data=c,e.state="idle",e.error=null}catch(n){if(console.error(n),!nt.isCancel(n)){e.data=[];const r=y.get(n,"message","unkown error");e.error=y.get(n,"response.data.detail.message",r),e.state="error"}}}}),runTransformation(){e.state="loading";try{const n=e.contentModel.queries.findByIDSet(new Set(e.dep_query_ids)).map(l=>({id:l.id,name:l.name,data:l.data})),r=e.contentModel.dashboardState,i=e.pre_process,o=new Function(`return ${i}`)()(n,r,rt);e.data=o,e.state="idle",e.error=null}catch(t){e.data=[],e.error=t.message,e.state="error"}}})).actions(e=>({fetchData:t=>{if(!e.inUse&&!t){console.debug(`🟡 Skipping query[${e.name}]`);return}return console.debug(`🔵 Running query[${e.name}]`),e.isTransform?e.runTransformation():e.typedAsHTTP?e.runHTTP():e.runSQL()},beforeDestroy(){var t;(t=e.controller)==null||t.abort()}})).actions(e=>({afterCreate(){f.addDisposer(e,K.reaction(()=>{var n;return e.isTransform?[e.inUse,e.id,e.key,e.dep_query_ids.toString(),e.pre_process,e.depQueryModelStatesString].join("--"):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}))}})),ei=f.types.model("QueriesRenderModel",{current:f.types.optional(f.types.array(Hr),[])}).views(e=>({get idSet(){return new Set(e.current.map(t=>t.id))},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 f.getParent(e,1)},get visibleQueryIDSet(){const{views:t,filters:n,queries:r}=this.contentModel,i=[];t.visibleViews.forEach(u=>{u.panels.forEach(c=>{i.push(...c.queryIDs)})});const o=y.uniq(t.visibleViews.map(u=>u.renderViewIDs).flat());n.current.forEach(u=>{const c=y.get(u,"config.options_query_id");if(!c)return;o.some(h=>u.visibleInViewsIDSet.has(h))&&i.push(c)}),r.findByIDSet(new Set(i)).forEach(u=>{!u.isTransform||u.dep_query_ids.length===0||i.push(...u.dep_query_ids)});const l=new Set(i);return console.debug("QueryIDs:",l),l},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(i=>n.has(i.id)).map(({name:i,data:o})=>({id:i,data:o}));El(r)},downloadDataByQueryID(t){const n=e.findByID(t);if(!n){console.log("[downloadDataByQueryID] query not found");return}const{name:r,data:i}=n;B1(r,i)},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)},getSchema(t){return{definition:{queries:e.findByIDSet(new Set(t)).map(i=>i.json)},version:lt}},downloadSchema(t){const n=JSON.stringify(this.getSchema(t),null,2);Ft("Queries",n)}}));function Vl(e){return{current:e}}function ql({min:e,max:t}){const n=`${e}px`,r=Number.isFinite(t)?`${t}px`:"∞";return`[${n}, ${r})`}const ti=f.types.model("LayoutsRenderModel",{list:f.types.array(ml),currentBreakpoint:f.types.string}).views(e=>({get json(){return e.list.map(t=>t.json)},jsonByPanelIDSet(t){return e.list.map(n=>n.jsonByPanelIDSet(t))},get root(){return f.getRoot(e)},get contentModel(){return this.root.content},get basisLayoutSet(){return e.list.find(t=>t.id==="basis")},get currentLayoutSet(){return e.list.find(t=>t.id===e.currentBreakpoint)},get currentLayoutRange(){return this.breakpointRanges.find(t=>t.id===e.currentBreakpoint)},get currentRangeText(){const t=this.currentLayoutRange;return ql(t)},get cols(){const t={};return e.list.forEach(n=>{t[n.id]=36}),t},get breakpoints(){const t={};return e.list.forEach(n=>{t[n.id]=n.breakpoint}),t},get breakpointNameRecord(){const t={};return e.list.forEach(n=>{t[n.name]=n.breakpoint}),t},get breakpointRanges(){const t=e.list.map(n=>({id:n.id,name:n.name,min:n.breakpoint,max:1/0,text:""}));return t.sort((n,r)=>n.min-r.min).forEach((n,r)=>{r!==t.length-1&&(n.max=t[r+1].min)}),t.forEach(n=>{n.text=ql(n)}),t},get breakpointsInfo(){return e.list.map(t=>({id:t.id,name:t.name,breakpoint:t.breakpoint})).sort((t,n)=>t.breakpoint-n.breakpoint)},get currentBreakpointRange(){return this.breakpointRanges.find(t=>t.id===e.currentBreakpoint)},get currentLayoutPreviewWidth(){const t=this.currentBreakpointRange;if(t)return t.max===1/0?t.min===0?void 0:t.min+1:t.max},items(t){const n=new Set(t);return this.currentLayoutSet.list.filter(i=>n.has(i.panelID))},gridLayouts(t){const n=new Set(t),r={};return e.list.forEach(i=>{r[i.id]=i.list.filter(o=>n.has(o.panelID)).map(o=>o.layoutProperies)}),r},findItemByPanelID(t){return this.currentLayoutSet.findByPanelID(t)}})).actions(e=>({setCurrentBreakpoint(t){console.log("🔴 onBreakpointChange:",t),e.currentBreakpoint=t},afterCreate(){f.addDisposer(e,K.reaction(()=>e.currentBreakpoint,()=>{setTimeout(()=>{window.dispatchEvent(new Event("resize"))},32)},{fireImmediately:!1,delay:0}))}})),Nl=yl.views(e=>({isADuplicatedKey(t){return!t||t===e.key?!1:!!f.getParent(e,2).findByKey(t)}})),ni=f.types.model("SQLSnippetsRenderModel",{current:f.types.optional(f.types.array(Nl),[])}).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 keySet(){return new Set(e.current.map(t=>t.key))},get firstKey(){if(e.current.length!==0)return e.current[0].key},findByKey(t){return e.current.find(n=>n.key===t)},findByKeySet(t){return e.current.filter(n=>t.has(n.key))}})).actions(e=>({getSchema(t){return{definition:{sqlSnippets:e.findByKeySet(new Set(t)).map(i=>i.json)},version:lt}},downloadSchema(t){const n=JSON.stringify(this.getSchema(t),null,2);Ft("SQL Snippets",n)}}));function Fl(e){return{current:e}}function un(e,t,n,r){return e.reduce((i,o)=>{try{i[o[t]]=xs(o[n],r)}catch(l){i[o[t]]=l.message}return i},{})}class Gl{constructor(t){L(this,"origin");L(this,"copy");this.origin=t,this.copy=f.clone(t),K.makeAutoObservable(this,{},{autoBind:!0,deep:!1})}get changed(){return!y.isEqual(f.getSnapshot(this.origin),f.getSnapshot(this.copy))}commit(){f.applySnapshot(this.origin,f.getSnapshot(this.copy))}reset(){f.applySnapshot(this.copy,f.getSnapshot(this.origin))}update(t){f.applySnapshot(this.copy,t)}}const Wl=e=>new Gl(e),$1=S.observer(({view:e})=>{const t=Z(),n=R(),r=Le.useModals(),{panel:i,downloadPanelScreenshot:o}=Be(),{id:l}=i,{viewPanelInFullScreen:u,inFullScreen:c}=g.useContext(Zn),d=()=>{n.duplicatePanelByID(l,e.id)},h=()=>{t.editor.open(["_VIEWS_",e.id,"_PANELS_",l])},p=()=>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}),x=g.useCallback(()=>{u(l)},[l,u]),m=!c&&e.type!==P.Modal;return s.jsx(s.Fragment,{children:s.jsx(a.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:s.jsxs(a.Menu,{withinPortal:!0,children:[s.jsx(a.Menu.Target,{children:s.jsx(a.Box,{className:"panel-dropdown-target",sx:{width:"100%"}})}),s.jsxs(a.Menu.Dropdown,{children:[s.jsx(a.Menu.Item,{onClick:i.refreshData,icon:s.jsx(k.Refresh,{size:14}),children:"Refresh"}),s.jsx(a.Menu.Item,{onClick:i.downloadData,icon:s.jsx(k.Download,{size:14}),children:"Download Data"}),s.jsx(a.Menu.Item,{onClick:i.downloadSchema,icon:s.jsx(_.IconCode,{size:14}),children:"Download Schema"}),s.jsx(a.Menu.Item,{onClick:o,icon:s.jsx(_.IconCamera,{size:14}),children:"Screenshot"}),m&&s.jsx(a.Menu.Item,{onClick:x,icon:s.jsx(k.ArrowsMaximize,{size:14}),disabled:!0,children:"Full Screen"}),s.jsx(a.Divider,{label:"Edit",labelPosition:"center"}),s.jsx(a.Menu.Item,{onClick:h,icon:s.jsx(k.Settings,{size:14}),children:"Settings"}),s.jsx(a.Menu.Item,{onClick:d,icon:s.jsx(k.Copy,{size:14}),children:"Duplicate"}),s.jsx(a.Menu.Item,{color:"red",onClick:p,icon:s.jsx(k.Trash,{size:14}),children:"Delete"})]})]})})})});function V1(e){return e?["<p><br></p>","<p></p>"].includes(e):!0}const si=S.observer(()=>{const[e,t]=g.useState(!1),{panel:n}=ft();return V1(n.description)?null:s.jsxs(s.Fragment,{children:[s.jsx(a.Modal,{opened:e,onClose:()=>t(!1),title:n.title.show?n.name:"",withCloseButton:!1,withinPortal:!0,zIndex:310,children:s.jsx(Fn,{value:n.description,styles:{root:{border:"none"},content:{padding:0}},sx:{".mantine-RichTextEditor-content .ProseMirror":{padding:"0 !important"}}})}),s.jsx(a.Tooltip,{label:"Click to see description",position:"top-start",withinPortal:!0,children:s.jsx(a.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>t(r=>!r),sx:{verticalAlign:"baseline",cursor:"pointer"},children:s.jsx(k.InfoCircle,{size:20})})})]})}),FI="",q1=S.observer(function(){const{panel:t}=ft(),{name:n,title:r}=t;return r.show?s.jsx(a.Group,{grow:!0,position:"center",className:"panel-title-wrapper",sx:{flexGrow:1},children:s.jsx(a.Text,{align:"center",lineClamp:1,className:"panel-title-text",children:n})}):null});function N1(e){const t=g.useRef(null);return{ref:t,downloadPanelScreenshot:()=>{const r=t.current;if(!r)return;const i=r.offsetWidth*2,o=r.offsetHeight*2;Ui.toBlob(t.current,{bgcolor:"white",width:i,height:o,style:{border:"none",borderRadius:0,transformOrigin:"0 0",transform:"scale(2)"}}).then(l=>{window.saveAs(l,`${e.name?e.name:e.viz.type}.png`)})}}}var Rl=(e=>(e.migrated="migrated",e.nothingToMigrate="nothingToMigrate",e.checkFailed="checkFailed",e.migrationFailed="migrationFailed",e))(Rl||{}),ts=(e=>(e.notStarted="notStarted",e.inProgress="inProgress",e.done="done",e))(ts||{});class F1{constructor(t){L(this,"vizInstance");L(this,"operationManager");L(this,"triggerManager");L(this,"vizManager");L(this,"runningMigration");L(this,"panelModel");L(this,"status","notStarted");this.panelModel=t.getRequired(he.instanceScope.panelModel),this.vizInstance=t.getRequired(he.instanceScope.vizInstance),this.operationManager=t.getRequired(he.instanceScope.operationManager),this.triggerManager=t.getRequired(he.instanceScope.triggerManager),this.vizManager=t.getRequired(he.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 Ql(e){const{panel:t}=ft();return g.useCallback(n=>{const r=n.getRequired(he.vizManager),i=r.resolveComponent(e.viz.type);return n.createScoped().provideFactory(he.instanceScope.vizInstance,()=>r.getOrCreateInstance(e)).provideFactory(he.instanceScope.interactionManager,o=>{const l=o.getRequired(he.instanceScope.vizInstance);return new As(l,i,_n)}).provideFactory(he.instanceScope.operationManager,o=>o.getRequired(he.instanceScope.interactionManager).operationManager).provideFactory(he.instanceScope.triggerManager,o=>o.getRequired(he.instanceScope.interactionManager).triggerManager).provideValue(he.instanceScope.panelModel,t).provideFactory(he.instanceScope.migrator,o=>new F1(o))},[e.viz.type,e.viz.conf])}function Ul(e){const[t,n]=g.useState(!1),r=rl().getRequired(he.instanceScope.migrator);return V.useAsyncEffect(async()=>{const i=r.status===ts.notStarted;n(r.status===ts.done),r.status===ts.notStarted&&r.runMigration().then(o=>{o===Rl.migrated&&i&&(e==null||e())}).finally(()=>{n(!0)})},[r]),t}function Kl(e,t){const n=rl().getRequired(he.instanceScope.vizInstance);return g.useEffect(()=>(n.instanceData.setItem(null,t.viz.conf),n.instanceData.watchItem(null,r=>{e(r)})),[e,t.viz.type]),n}function G1({setVizConf:e,...t}){const{panel:n}=t,r=Kl(e,n),i=Ul(()=>{dt.showNotification({title:`${n.name} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})});return V.useAsyncEffect(async()=>{await r.instanceData.setItem(null,n.viz.conf)},[r,n.viz.type]),i?s.jsx(Ld,{...t}):s.jsx(a.Text,{children:"Checking update..."})}function W1(e){const{panel:t,setVizConf:n}=e;Kl(n,t);const{inEditMode:r}=g.useContext(Cn);return Ul(()=>{r&&dt.showNotification({title:`${t.name} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?s.jsx(Ed,{...e}):s.jsx(a.Text,{children:"Checking update"})}const GI="";function R1(e,t){const{vizManager:n}=g.useContext(tt),{panel:{viz:r,title:i,id:o,name:l,description:u,queryIDs:c,variables:d}}=ft(),h={id:o,name:l,title:i,description:u,queryIDs:c,viz:r},p=Ql(h);try{return n.resolveComponent(r.type),s.jsx(Jn,{configure:p,children:s.jsx(W1,{setVizConf:r.setConf,panel:h,measure:t,data:e,variables:d,vizManager:n})})}catch(x){return console.info(y.get(x,"message")),null}}const Yl=S.observer(function({data:t}){const{ref:n,width:r,height:i}=oe.useElementSize(),o=R1(t,{w:r,h:i}),l=r>0&&i>0;return s.jsx("div",{className:"viz-root",ref:n,children:s.jsx(a.Box,{sx:{width:r,height:i,overflow:"hidden"},children:l&&s.jsx(we,{children:o})})})}),Xl=S.observer(({panel:e})=>s.jsxs(a.Stack,{children:[e.queryErrors.map((t,n)=>s.jsx(a.Text,{color:"red",size:"sm",align:"center",sx:{fontFamily:"monospace"},children:t},`${n}-${t}`)),s.jsx(a.Text,{color:"gray",align:"center",size:"sm",children:e.queryStateMessages})]})),ri=S.observer(({panel:e})=>s.jsxs(a.Flex,{className:"panel-viz-section",direction:"column",sx:{position:"relative",width:"100%"},children:[s.jsx(a.LoadingOverlay,{visible:e.dataLoading,exitTransitionDuration:0}),!e.canRenderViz&&s.jsx(Xl,{panel:e}),e.canRenderViz&&s.jsx(Yl,{data:e.data})]})),Q1={border:"1px solid #e9ecef"},Jl=S.observer(({panel:e,panelStyle:t,dropdownContent:n})=>{const{ref:r,downloadPanelScreenshot:i}=N1(e);return e.title.show,s.jsx(Ds,{value:{panel:e,data:e.data,loading:e.dataLoading,errors:e.queryErrors,downloadPanelScreenshot:i},children:s.jsxs(a.Box,{className:`panel-root ${e.title.show?"panel-root--show-title":""}`,ref:r,p:0,sx:{...Q1,...t},children:[s.jsx(a.Box,{className:"panel-description-popover-wrapper",children:s.jsx(si,{})}),n,s.jsx(q1,{}),s.jsx(ri,{panel:e})]})})}),U1={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function K1(e){return e.style.border.enabled?{}:U1}const Zl=S.observer(function({panel:t,view:n}){const r=K1(t);return s.jsx(Jl,{panel:t,panelStyle:r,dropdownContent:s.jsx($1,{view:n})})});function Y1(e){return!["richText","button"].includes(e)}const X1=S.observer(({view:e})=>{const{panel:t,downloadPanelScreenshot:n}=ft(),{id:r}=t,{viewPanelInFullScreen:i,inFullScreen:o}=g.useContext(Zn),l=g.useCallback(()=>{i(r)},[r,i]),u=!o&&e.type!==P.Modal;return Y1(t.viz.type)?s.jsx(a.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:s.jsxs(a.Menu,{withinPortal:!0,children:[s.jsx(a.Menu.Target,{children:s.jsx(a.Box,{className:"panel-dropdown-target"})}),s.jsxs(a.Menu.Dropdown,{children:[s.jsx(a.Menu.Item,{onClick:t.refreshData,icon:s.jsx(k.Refresh,{size:14}),children:"Refresh"}),s.jsx(a.Menu.Item,{onClick:t.downloadData,icon:s.jsx(k.Download,{size:14}),children:"Download Data"}),s.jsx(a.Menu.Item,{onClick:n,icon:s.jsx(_.IconCamera,{size:14}),children:"Screenshot"}),u&&s.jsx(a.Menu.Item,{onClick:l,icon:s.jsx(k.ArrowsMaximize,{size:14}),children:"Full Screen"})]})]})}):null});function J1(e){return e.style.border.enabled?{}:{border:"1px dashed transparent"}}const ii=S.observer(({panel:e,view:t})=>{const n=J1(e);return s.jsx(Jl,{panel:e,panelStyle:n,dropdownContent:s.jsx(X1,{view:t})})}),Z1={modal:{display:"flex",flexDirection:"column",flexWrap:"nowrap"},body:{display:"flex",height:"calc(100vh - 88px)"}},Hl=S.observer(function({view:t,panel:n,exitFullScreen:r}){return s.jsx(a.Modal,{opened:!0,fullScreen:!0,onClose:r,title:s.jsx(a.Button,{color:"blue",size:"xs",onClick:r,leftIcon:s.jsx(k.ArrowLeft,{size:20}),children:"Exit fullscreen"}),styles:Z1,children:s.jsx(a.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:s.jsx(ii,{view:t,panel:n})})})});function eu(e,t,n){const{panels:r}=pe(),i=e.id==="Main",[o,l]=g.useState(()=>i&&r.findByID(t)?t:null),u=g.useCallback(p=>{l(p),i&&n(p)},[i,n]),c=g.useCallback(()=>{l(null),i&&n("")},[i,n]),d=o?r.findByID(o):null;return{viewPanelInFullScreen:u,exitFullScreen:c,inFullScreen:!!d,fullScreenPanel:d}}const WI="",H1=g.forwardRef(({h:e},t)=>s.jsx(a.ActionIcon,{ref:t,className:"react-grid-customDragHandle",sx:{userSelect:"none",cursor:"grab",position:"absolute",top:5,right:e>38?5:20,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",children:s.jsx(k.ArrowsMove,{size:16})})),e_=g.forwardRef(({handleAxis:e,...t},n)=>s.jsx(a.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:s.jsx(k.ChevronDownRight,{size:16})})),t_=gn.WidthProvider(gn.Responsive),n_=S.observer(({view:e,className:t="layout"})=>{const r=R().layouts,i=r.items(e.panelIDs),o=r.gridLayouts(e.panelIDs),l=(d,h,p,x)=>{console.log("🔴 onResize",d),p.h<30&&(p.h=30,x.h=30),p.w<4&&(p.w=4,x.w=4)},u=(d,h,p)=>{console.log("🔴 onResizeStop",{layouts:d,oldItem:h,newItem:p}),r.updateCurrentLayoutItem(p)},c=(d,h,p)=>{console.log("🔴 onDragStop",{layouts:d,oldItem:h,newItem:p}),r.updateCurrentLayoutItem(p)};return s.jsx(t_,{className:`dashboard-layout ${t}`,rowHeight:1,margin:[0,0],isBounded:!0,isDraggable:!0,isResizable:!0,cols:r.cols,layouts:o,draggableHandle:".react-grid-customDragHandle",resizeHandle:s.jsx(e_,{}),onResize:l,breakpoints:r.breakpoints,onBreakpointChange:r.setCurrentBreakpoint,onResizeStop:u,onDragStop:c,width:r.currentLayoutPreviewWidth,children:i.map(d=>s.jsxs("div",{"data-grid":d.layoutProperies,className:"panel-grid-item",children:[s.jsx(H1,{h:d.h}),s.jsx(Zl,{view:e,panel:d.panel})]},d.id))})}),s_=gn.WidthProvider(gn.Responsive),r_=S.observer(({view:e,className:t="layout"})=>{const n=pe(),r=n.layouts.items(e.panelIDs),i=n.layouts.gridLayouts(e.panelIDs);return s.jsx(s_,{className:`dashboard-layout ${t}`,rowHeight:1,margin:[0,0],isDraggable:!1,isResizable:!1,cols:n.layouts.cols,layouts:i,breakpoints:n.layouts.breakpoints,onBreakpointChange:n.layouts.setCurrentBreakpoint,children:r.map(o=>s.jsx("div",{"data-grid":o.layoutProperies,className:"panel-grid-item",children:s.jsx(ii,{view:e,panel:o.panel})},o.id))})});function ai(e){const t=g.useRef(null);return{ref:t,downloadScreenshot:()=>{var i;const r=(i=t.current)==null?void 0:i.querySelector(".react-grid-layout");r&&e.downloadScreenshot(r)}}}const i_=S.observer(({downloadScreenshot:e})=>{const[t,{setTrue:n,setFalse:r}]=V.useBoolean(!1),i=da(),o=pe(),l=()=>{const u=JSON.stringify(o.contentJSON,null,2),c=`${i.name}__${o.name}`;Ft(c,u)};return s.jsxs(a.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:200,closeDelay:400,withinPortal:!0,position:"bottom-end",children:[s.jsx(a.Menu.Target,{children:s.jsx(a.Affix,{position:{bottom:"20px",right:"10px"},zIndex:1,children:s.jsx(a.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:s.jsx(_.IconShare3,{size:"1rem"})})})}),s.jsxs(a.Menu.Dropdown,{children:[s.jsx(a.Menu.Item,{icon:s.jsx(_.IconCamera,{size:14}),onClick:e,children:"Screenshot"}),s.jsx(a.Menu.Divider,{}),s.jsx(a.Menu.Item,{icon:s.jsx(_.IconDownload,{size:14}),onClick:o.queries.downloadAllData,children:"Download Data"}),s.jsx(a.Menu.Item,{icon:s.jsx(_.IconCode,{size:14}),onClick:l,children:"Download Schema"})]})]})}),tu=S.observer(({children:e,view:t,sx:n={}})=>{const{ref:r,downloadScreenshot:i}=ai(t);return s.jsxs(s.Fragment,{children:[s.jsx(a.Box,{ref:r,pt:10,pb:10,sx:n,children:e}),s.jsx(i_,{downloadScreenshot:i})]})}),nu=S.observer(({downloadScreenshot:e})=>s.jsx(a.ActionIcon,{className:"download-screenshot-button",color:"blue",onClick:e,children:s.jsx(_.IconCamera,{size:14})})),a_=S.observer(({children:e,view:t})=>{const n=pe(),r=t.config,i=n.views.visibleViewIDs.includes(t.id),o=()=>n.views.rmVisibleViewID(t.id),{ref:l,downloadScreenshot:u}=ai(t);return s.jsx(a.Modal,{size:r.width,centered:!0,opened:i,onClose:o,withCloseButton:!1,title:s.jsxs(a.Group,{position:"apart",px:"1rem",h:"48px",children:[s.jsx(a.Box,{children:r.custom_modal_title.value}),s.jsx(nu,{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",paddingBottom:10},header:{padding:0},title:{flexGrow:1}},transitionProps:{duration:0},children:s.jsx(a.Box,{ref:l,children:e})})}),o_=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},l_=S.observer(({view:e})=>{const t=pe(),n=e.config;return s.jsxs(a.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"?"0px 0px 36px":"0",height:"100%",overflow:"auto"}},keepMounted:!1,children:[s.jsx(a.Tabs.List,{grow:n.grow,children:n.tabsInOrder.map(r=>s.jsx(a.Tabs.Tab,{value:r.id,sx:o_(r),disabled:!r.view_id,children:r.name??r.id},r.id))}),n.tabsInOrder.map(r=>{const i=t.views.findByID(r.view_id);return i?s.jsx(a.Tabs.Panel,{value:r.id,children:s.jsx(ns,{view:i})},r.id):null})]})}),u_=S.observer(({view:e,children:t})=>{switch(e.type){case P.Modal:return s.jsx(a_,{view:e,children:t});case P.Tabs:return s.jsx(l_,{view:e});case P.Division:default:return s.jsx(tu,{view:e,children:t})}}),c_=S.observer(({children:e,view:t})=>{const r=R().layouts,[i,o]=oe.useResizeObserver();return g.useEffect(()=>{r.setCurrentLayoutWrapperWidth(o.width)},[o.width]),s.jsx(a.Box,{sx:{height:"100%"},ref:i,children:s.jsx(a.Box,{sx:{paddingBottom:"100px",background:"white",margin:"0 auto",width:r.currentLayoutPreviewWidth??"100%",transform:`scale(${r.divisionPreviewScale})`,transformOrigin:"0 0"},children:s.jsx(tu,{view:t,sx:{paddingTop:"0px !important",".dashboard-sticky-area > form":{paddingBottom:"5px"},".dashboard-layout":{marginTop:0,marginBottom:0}},children:e})})})});function su(e){return e.replace(/(vw|vh)/,"%")}const d_=S.observer(({children:e,view:t})=>{const n=t.config,{width:r,height:i}=g.useMemo(()=>({width:su(n.width),height:su(n.height)}),[n.width,n.height]),{ref:o,downloadScreenshot:l}=ai(t);return s.jsx(a.Box,{sx:{height:"100%","> div:not(.mantine-Modal-root)":{height:"100%"}},children:s.jsx(a.Modal,{size:n.width,opened:!0,onClose:y.noop,withCloseButton:!1,title:s.jsxs(a.Group,{position:"apart",px:"1rem",h:"48px",children:[s.jsx(a.Box,{children:n.custom_modal_title.value}),s.jsx(nu,{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:i,maxHeight:i},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:s.jsx(a.Box,{ref:o,children:e})})})}),p_=({variant:e,orientation:t})=>{const n={root:{height:"100%",overflow:"hidden"},tabsList:{backgroundColor:"white"},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},h_=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},x_=S.observer(({view:e})=>{const t=Le.useModals(),n=R(),r=g.useMemo(()=>n.views.options.filter(u=>u.type===P.Division),[e.id,n.views.options]),i=e.config,o=u=>t.openConfirmModal({title:"Delete this tab?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.removeTab(u)},confirmProps:{color:"red"},zIndex:320}),l=i.tabs.length===0;return s.jsxs(a.Tabs,{className:"preview-view-tabs",variant:i.variant,orientation:i.orientation,value:e.tab,onTabChange:e.setTab,styles:p_(i),children:[s.jsxs(a.Tabs.List,{grow:i.grow,children:[i.tabsInOrder.map(u=>s.jsx(a.Tabs.Tab,{value:u.id,sx:h_(u),children:u.name??u.id},u.id)),s.jsx(a.Tabs.Tab,{onClick:i.addTab,value:"add",className:"add-a-tab",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),i.tabsInOrder.map((u,c)=>{const d=n.views.findByID(u.view_id);return s.jsxs(a.Tabs.Panel,{value:u.id,sx:{position:"relative"},children:[s.jsxs(a.Box,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:200},children:[s.jsx(a.Overlay,{opacity:.8,color:"#FFF",blur:10,zIndex:100}),s.jsxs(a.Stack,{mx:"auto",mt:100,sx:{width:"300px",position:"relative",zIndex:200},children:[s.jsx(a.TextInput,{label:"Tab Name",required:!0,value:u.name,onChange:h=>u.setName(h.currentTarget.value)}),s.jsx(a.Select,{label:"View",value:u.view_id,onChange:u.setViewID,data:r}),s.jsx(a.NumberInput,{label:"Placement Order",required:!0,value:u.order,onChange:h=>u.setOrder(h||0),min:0,max:1e3,step:1}),s.jsx(a.ColorInput,{label:"Color",value:u.color,onChange:u.setColor,disabled:i.variant!=="default"}),d&&s.jsxs(a.Button,{mt:20,variant:"gradient",leftIcon:s.jsx(_.IconArrowsLeftRight,{size:18}),gradient:{from:"cyan",to:"indigo"},onClick:()=>n.views.setIDOfVIE(d.id),children:["Swith to View: ",d.name]}),s.jsx(a.Button,{mt:20,variant:"subtle",color:"red",onClick:()=>o(c),disabled:l,leftIcon:s.jsx(_.IconTrash,{size:14}),children:"Delete This Tab"})]})]}),d&&s.jsx(ns,{view:d})]},u.id)})]})}),f_=S.observer(({view:e,children:t})=>{switch(e.type){case P.Modal:return s.jsx(d_,{view:e,children:t});case P.Tabs:return s.jsx(x_,{view:e});case P.Division:default:return s.jsx(c_,{view:e,children:t})}}),ru=S.observer(function({view:t}){const r=R().layouts.divisionPreviewScale!==1;return s.jsx(Zn.Provider,{value:{viewPanelInFullScreen:y.noop,inFullScreen:!1},children:s.jsx(a.Box,{className:"dashboard-view","data-enable-scrollbar":!0,sx:{background:r?"transparent":"#efefef"},children:s.jsx(f_,{view:t,children:s.jsxs(a.Box,{sx:{position:"relative"},children:[s.jsx(a.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:s.jsx(ul,{view:t})}),s.jsx(n_,{view:t})]})})})})}),ns=S.observer(function({view:t}){const{fullScreenPanelID:n,setFullScreenPanelID:r}=ya(),{viewPanelInFullScreen:i,exitFullScreen:o,inFullScreen:l,fullScreenPanel:u}=eu(t,n,r);return s.jsx(Zn.Provider,{value:{viewPanelInFullScreen:i,inFullScreen:l},children:s.jsxs(a.Box,{className:"dashboard-view","data-enable-scrollbar":!0,sx:{height:t.type===P.Modal?"0 !important":"100%"},children:[l&&s.jsx(Hl,{view:t,panel:u,exitFullScreen:o}),s.jsx(u_,{view:t,children:s.jsxs(a.Box,{sx:{position:"relative"},children:[!l&&s.jsx(a.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:s.jsx(ul,{view:t})}),!l&&s.jsx(r_,{view:t})]})})]})})});var iu=(e=>(e.Use="use",e.Edit="edit",e))(iu||{});const g_={[P.Division]:"Division",[P.Tabs]:"Tabs",[P.Modal]:"Modal"},au={[P.Division]:"rgba(255, 0, 0, 0.2)",[P.Modal]:"rgba(0, 0, 0, 0.2)",[P.Tabs]:"rgba(255, 200, 100, 0.4)"},m_={[P.Division]:"#ff4000",[P.Modal]:"#000",[P.Tabs]:"#ffad18"};function y_(e,t,n){f.addDisposer(e,f.addMiddleware(e,(r,i)=>{i(r,()=>{f.getType(r.context)===t&&r.type==="action"&&n(r.name,r.context)})}))}const ou=f.types.compose("FiltersModel",Jr,f.types.model("FiltersModel",{previewValues:f.types.optional(f.types.frozen(),{})})).views(e=>({get idSet(){return new Set(e.current.map(t=>t.id))},get keySet(){return new Set(e.current.map(t=>t.key))},get options(){return e.current.map(t=>({label:t.label??t.id,value:t.id,_type:"filter"}))},get selects(){return e.current.filter(t=>t.type===xe.Select).map(t=>({label:t.label??t.id,value:t.id}))},get keyLabelOptions(){return e.current.map(t=>({label:t.label??t.key,value:t.key}))},get sortedList(){return y.sortBy(e.current,t=>t.label.toLowerCase())}})).actions(e=>({replace(t){e.current=f.cast(t)},append(t){e.current.push(t)},appendMultiple(t){if(t.length===0)return;const n=t.filter(r=>!e.idSet.has(r.id));e.current.push(...n)},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(){y_(e.current,qr,(n,r)=>{if(n==="setType"){const i=Bl(r.config.default_value,r.config);e.setValueByKey(r.key,i),e.updatePreviewValues({...e.previewValues,[r.key]:i})}})}return{afterCreate(){t()}}}),lu=Hr.views(e=>({get canPreviewData(){return e.isTransform?e.dep_query_ids.length>0&&!!e.pre_process:!!e.datasource},get guideToPreviewData(){return e.isTransform?"Need to complete settings in Transform tab":"Need to pick a Data Source first"}})),uu=f.types.compose("QueriesModel",ei,f.types.model({current:f.types.optional(f.types.array(lu),[])})).views(e=>({get options(){const t=e.current.map(n=>({value:n.id,label:n.name,_type:"query"}));return y.sortBy(t,n=>n.label.toLowerCase())},get optionsWithoutTransform(){const t=e.current.filter(n=>n.type!==ce.Transform).map(n=>({value:n.id,label:n.name,_type:"query"}));return y.sortBy(t,n=>n.label.toLowerCase())},get sortedList(){return y.sortBy(e.current,t=>t.name.toLowerCase())}})).actions(e=>({replace(t){e.current=f.cast(t)},append(t){e.current.push(t)},appendMultiple(t){if(t.length===0)return;const n=t.filter(r=>!e.idSet.has(r.id));e.current.push(...n)},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&&(f.detach(n),e.current.remove(n))},removeQueries(t){const n=new Set(t);e.current.forEach(i=>{n.has(i.id)&&f.detach(i)});const r=[...e.current];y.remove(r,i=>n.has(i.id)),e.current=f.cast(r)}})),cu=ni.views(e=>({get sortedList(){return y.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 y.sortBy(t,n=>n.label.toLowerCase())}})).actions(e=>({replace(t){e.current=f.cast(t)},append(t){e.current.push(t)},appendMultiple(t){if(t.length===0)return;const n=t.filter(r=>!e.keySet.has(r.key));e.current.push(...n)},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(i=>{n.has(i.key)&&f.detach(i)});const r=[...e.current];y.remove(r,i=>n.has(i.key)),e.current=f.cast(r)},replaceByIndex(t,n){e.current.splice(t,1,n)}})),b_=f.types.model({data:f.types.optional(f.types.frozen(),[]),state:f.types.optional(f.types.enumeration(["idle","loading","error"]),"idle"),error:f.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0}})),j_=f.types.model({data:f.types.optional(f.types.frozen(),[]),state:f.types.optional(f.types.enumeration(["idle","loading","error"]),"idle"),error:f.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0}})),v_=f.types.model({page:f.types.optional(f.types.number,1),limit:f.types.optional(f.types.number,20),data:f.types.optional(f.types.frozen(),[]),total:f.types.optional(f.types.number,0),state:f.types.optional(f.types.enumeration(["idle","loading","error"]),"idle"),error:f.types.frozen()}).views(e=>({get keywords(){return f.getParent(e,1)},get keywordString(){const{table_name:t,table_schema:n}=f.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`
449
+ `}})}function QS(e,t){const n=Vt(e.heat_block.min,t),r=Vt(e.heat_block.max,t);return{min:n,max:r,calculable:!0,orient:"horizontal",left:"center",top:0,itemWidth:15}}function US(e,t,n){const r=z(e.x_axis.data_key),i=y.uniq(t[r.queryID].map(u=>u[r.columnKey])),{overflow:o,rotate:l}=e.x_axis.axisLabel,c=Be(o.on_axis);return ee.getXAxis({id:"main-x-axis",type:"category",data:i,name:e.x_axis.name??"",align:"center",axisTick:{show:!0,alignWithLabel:!0},axisLabel:{rotate:l,...c,formatter:n},splitArea:{show:!1,areaStyle:{color:"#E7E7E9"}},splitLine:{show:!1},nameLocation:"center",nameGap:25,nameTextStyle:{fontWeight:"bold",align:"center"},z:3})}function KS(e,t,n){const r=z(e.x_axis.data_key),i=z(e.y_axis.data_key),{nameAlignment:o,data_key:l,...c}=e.y_axis,u=y.uniq(t[r.queryID].map(x=>x[i.columnKey])),{overflow:d,rotate:h}=e.y_axis.axisLabel,p=Be(d.on_axis);return ee.getYAxis({...c,type:"category",data:u,axisLabel:{rotate:h,...p,formatter:n},axisLine:{show:!0,lineStyle:{width:3}},axisTick:{show:!0,alignWithLabel:!0},splitArea:{show:!1,areaStyle:{color:"#E7E7E9"}},splitLine:{show:!1},nameTextStyle:{fontWeight:"bold",align:o},nameLocation:"end",nameGap:15,z:3})}function YS(e,t,n){if(!e.x_axis.data_key||!e.y_axis.data_key||!e.heat_block.data_key)return{};const r=n.reduce((c,u)=>{const d=st(u,t);return c[u.name]=Ae(u,d),c},{}),i=VS(e),o=qS(e);return{xAxis:US(e,t,i.x_axis),yAxis:KS(e,t,i.y_axis),series:FS(e,t),tooltip:RS(e,t,i,o),grid:NS(e),visualMap:QS(e,r)}}function XS({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const l=g.useMemo(()=>{const p=z(e.x_axis.data_key),x=z(e.y_axis.data_key);return y.keyBy(t[p.queryID],m=>`${m[p.columnKey]}---${m[x.columnKey]}`)},[t,e.x_axis.data_key,e.y_axis.data_key]),c=Oe(i.triggerManager,nl.id),u=g.useCallback(p=>{const[x,m]=p.value,j=y.get(l,`${x}---${m}`,{error:"rowData is not found"});c.forEach(C=>{i.runInteraction(C.id,{...p,rowData:j})})},[l,c,i]),d=g.useMemo(()=>({click:u}),[u]),h=g.useMemo(()=>YS(e,t,o),[e,t]);return s.jsx(we,{echarts:be,option:h,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function JS({context:e,instance:t}){const n=$e({vizManager:e.vizManager,instance:t}),{value:r}=O(e.instanceData,"config"),{variables:i}=e,o=g.useMemo(()=>y.defaults({},r,_r),[r]),l=e.data,{width:c,height:u}=e.viewport;return!c||!u?null:s.jsx(ke,{width:c,height:u,children:s.jsx(XS,{variables:i,width:Ge(c),height:We(u),data:l,conf:o,interactionManager:n})})}class ZS extends ae{constructor(){super(...arguments);P(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const HS={displayName:"Merico Heatmap",displayGroup:"Merico suite",migrator:new ZS,name:"merico-heatmap",viewRender:JS,configRender:BS,createConfig:()=>({version:1,config:_r}),triggers:[nl]},e1=[{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"})),t1=[Bd,Od,qd,Vd,$d,Nd],rl=()=>({id:"dashboard",version:ua,manifest:{viz:[gr,qv,d0,gj,lw,ob,PC,Hd,Nh,Lm,my,K0,Xy,pm,Dv,Ab,oj,b0,pS,HS,kS,tx],color:[...e1,...t1]}}),on=new Rd,ue={pluginManager:rt("pluginManager"),vizManager:rt("vizManager"),colorManager:rt("colorManager"),instanceScope:{panelModel:rt("panelModel"),vizInstance:rt("vizInstance"),interactionManager:rt("interactionManager"),migrator:rt("migrator"),operationManager:rt("operationManager"),triggerManager:rt("triggerManager")}},kr=()=>{try{on.install(rl())}catch{}const e=new Ed(on),t=new Wd(on);return{pluginManager:on,vizManager:e,colorManager:t}},Ze=g.createContext(kr());try{on.install(rl())}catch{}const Tr=g.createContext(null);function Xn(e){const t=g.useContext(Tr),n=$.useCreation(()=>e.configure(t||new vs),[e.configure]),r=$.usePrevious(n);return r&&r!==n&&r.dispose(),s.jsx(Tr.Provider,{value:n,children:e.children})}function il(){return g.useContext(Tr)}const n1=({description:e,isDescriptionEmpty:t})=>t?null:s.jsx(a.Tooltip,{color:"white",label:s.jsx(Nn,{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:s.jsx(a.Box,{sx:{height:"16px",alignSelf:"center"},children:s.jsx(_.IconInfoCircle,{size:16,color:"gray"})})}),s1=S.observer(({label:e,config:{default_value:t,description:n,isDescriptionEmpty:r,...i},value:o,onChange:l})=>s.jsxs(a.Box,{children:[s.jsx(a.Text,{children:" "}),s.jsx(a.Checkbox,{label:s.jsxs(a.Group,{noWrap:!0,position:"apart",align:"middle",spacing:6,children:[s.jsx(a.Box,{sx:{flexGrow:1},children:e}),s.jsx(n1,{description:n,isDescriptionEmpty:r})]}),checked:o||!1,onChange:c=>l(c.currentTarget.checked),...i,pt:".4em",styles:{input:{borderColor:"#e9ecef"}}})]})),r1=({value:e,onChange:t,close:n,max_days:r,allowSingleDateInRange:i})=>{const[o,l]=e,c=g.useMemo(()=>o||new Date,[o]),u=g.useMemo(()=>{if(o&&!l)return o},[o,l]),d=g.useMemo(()=>{if(o&&!l&&r>0)return M(o).add(r-1,"days").toDate()},[o,l,r]),h=p=>{const[x,m]=p;t(p),x&&m&&n()};return s.jsx(xu.DatePicker,{defaultDate:c,numberOfColumns:2,type:"range",value:e,onChange:h,onNextMonth:console.log,minDate:u,maxDate:d,allowSingleDateInRange:i})},i1=({begin:e,end:t})=>{const n=g.useMemo(()=>M(t).diff(M(e),"days")+1,[e,t]);if(Number.isNaN(n))return s.jsx("span",{style:{userSelect:"none",opacity:0,visibility:"hidden"},children:"."});const r=n===1?"day":"days";return s.jsx(a.Tooltip,{label:`${n}${r}`,children:s.jsx(a.Badge,{size:"sm",children:n})})},a1=({max_days:e})=>e?s.jsxs(s.Fragment,{children:[s.jsx(a.Group,{position:"right",children:s.jsxs(a.Badge,{size:"xs",children:[e," days max"]})}),s.jsx(a.Divider,{variant:"dashed",my:10})]}):null,Dr=()=>[{label:"yesterday",value:"yesterday",group:"last",getRange:()=>{const e=Date.now();return[M(e).subtract(1,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()]}},{label:"week",value:"last week",group:"last",getRange:()=>{const e=Date.now();return[M(e).subtract(1,"week").startOf("week").toDate(),M(e).subtract(1,"week").endOf("week").toDate()]}},{label:"month",value:"last month",group:"last",getRange:()=>{const e=Date.now();return[M(e).subtract(1,"month").startOf("month").toDate(),M(e).subtract(1,"month").endOf("month").toDate()]}},{label:"2 months",value:"last 2 months",group:"last",getRange:()=>{const e=Date.now();return[M(e).subtract(2,"month").startOf("month").toDate(),M(e).subtract(1,"month").endOf("month").toDate()]}},{label:"3 months",value:"last 3 months",group:"last",getRange:()=>{const e=Date.now();return[M(e).subtract(3,"month").startOf("month").toDate(),M(e).subtract(1,"month").endOf("month").toDate()]}},{label:"year",value:"last year",group:"last",getRange:()=>{const e=Date.now();return[M(e).subtract(1,"year").startOf("year").toDate(),M(e).subtract(1,"year").endOf("year").toDate()]}},{label:"7 days",value:"recent 7 days",group:"recent",getRange:()=>{const e=Date.now();return[M(e).subtract(7,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()]}},{label:"30 days",value:"recent 30 days",group:"recent",getRange:()=>{const e=Date.now();return[M(e).subtract(30,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()]}},{label:"60 days",value:"recent 60 days",group:"recent",getRange:()=>{const e=Date.now();return[M(e).subtract(60,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()]}},{label:"90 days",value:"recent 90 days",group:"recent",getRange:()=>{const e=Date.now();return[M(e).subtract(90,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()]}},{label:"180 days",value:"recent 180 days",group:"recent",getRange:()=>{const e=Date.now();return[M(e).subtract(180,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()]}},{label:"365 days",value:"recent 365 days",group:"recent",getRange:()=>{const e=Date.now();return[M(e).subtract(365,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()]}},{label:"today",value:"today",group:"this",getRange:()=>{const e=Date.now();return[M(e).startOf("day").toDate(),M(e).endOf("day").toDate()]}},{label:"week",value:"this week",group:"this",getRange:()=>{const e=Date.now();return[M(e).startOf("week").toDate(),M(e).endOf("week").toDate()]}},{label:"month",value:"this month",group:"this",getRange:()=>{const e=Date.now();return[M(e).startOf("month").toDate(),M(e).endOf("month").toDate()]}},{label:"2 months",value:"this 2 months",group:"this",getRange:()=>{const e=Date.now();return[M(e).startOf("month").toDate(),M(e).add(1,"month").endOf("week").toDate()]}},{label:"3 months",value:"this 3 months",group:"this",getRange:()=>{const e=Date.now();return[M(e).startOf("month").toDate(),M(e).add(2,"month").endOf("week").toDate()]}},{label:"year",value:"this year",group:"this",getRange:()=>{const e=Date.now();return[M(e).startOf("year").toDate(),M(e).endOf("year").toDate()]}}];function al(e){const n=Dr().find(r=>r.value===e);return n?n.getRange():null}const o1=({onChange:e})=>{const t=r=>()=>{const i=r();e(i)},n=g.useMemo(()=>y.groupBy(Dr(),"group"),[]);return s.jsxs(s.Fragment,{children:[s.jsx(a.Divider,{variant:"dashed",my:10}),s.jsx(a.Table,{withBorder:!1,sx:{"tbody > tr > th, tbody > tr > td":{borderTop:"none",padding:"2px 6px"},"tbody > tr > th":{cursor:"default",userSelect:"none"},td:{paddingLeft:"1px"}},children:s.jsx("tbody",{children:Object.entries(n).map(([r,i])=>s.jsxs("tr",{children:[s.jsx("th",{children:s.jsx(a.Text,{size:"xs",color:"#555",children:r})}),i.map(({label:o,value:l,getRange:c})=>s.jsx("td",{children:s.jsx(a.Button,{compact:!0,size:"xs",variant:"subtle",onClick:t(c),children:o})},o))]},r))})})]})},ol=e=>({label:{display:"block",height:"21.7px"},input:{borderColor:e?"#228be6":"#e9ecef"}}),l1=({label:e,required:t,value:n,onChange:r,max_days:i,allowSingleDateInRange:o,inputFormat:l})=>{const[c,{open:u,close:d}]=re.useDisclosure(!1),[h,p]=n,x=h?M(h).format(l):"",m=p?M(p).format(l):"";return s.jsxs(a.Popover,{opened:c,onClose:d,position:"bottom-start",shadow:"md",children:[s.jsxs(a.Group,{position:"left",grow:!0,noWrap:!0,spacing:0,w:"18em",sx:{marginTop:"3px"},children:[s.jsx(a.Popover.Target,{children:s.jsx(a.TextInput,{label:e,required:t,icon:s.jsx(_.IconCalendar,{size:16}),placeholder:"Start date",readOnly:!0,value:x,onFocus:u,styles:ol(c),sx:{".mantine-Input-input":{borderRight:"none",borderTopRightRadius:0,borderBottomRightRadius:0}}})}),s.jsx(a.TextInput,{label:s.jsx(a.Group,{position:"right",children:s.jsx(i1,{begin:h,end:p})}),icon:s.jsx(_.IconMinus,{size:16}),placeholder:"End date",readOnly:!0,disabled:!h,value:m,onFocus:u,styles:ol(c),sx:{".mantine-Input-icon":{transform:"translateX(-22px)"},".mantine-Input-input":{borderLeft:"none",borderTopLeftRadius:0,borderBottomLeftRadius:0},".mantine-Input-input[data-disabled]":{backgroundColor:"transparent",backgroundImage:"linear-gradient(to right, #fff 0%, #f1f3f5 30%)",opacity:1},".mantine-Input-input[data-disabled]::placeholder":{opacity:.6}}})]}),s.jsxs(a.Popover.Dropdown,{p:"sm",children:[s.jsx(a1,{max_days:i}),s.jsx(r1,{value:n,onChange:r,close:d,allowSingleDateInRange:o,max_days:i}),s.jsx(o1,{onChange:r})]})]})},ll=S.observer(({label:e,config:t,value:n=[null,null],onChange:r})=>{const{inputFormat:i,required:o,max_days:l,allowSingleDateInRange:c}=t,u=Array.isArray(n)?n.map(h=>h?M(h).toDate():null):[null,null],d=h=>{r(h.map(p=>p&&M(p).format(i)))};return s.jsx(l1,{label:e,value:u,onChange:d,inputFormat:i,allowSingleDateInRange:c,max_days:l,required:o})}),c1=a.createStyles((e,{radius:t=4})=>({root:{borderRadius:e.fn.radius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-select.rc-select-open":{borderColor:"#228be6 !important",".rc-select-selection-overflow-item-rest":{display:"none"},".rc-select-selection-overflow-item-suffix":{display:"block"}},".rc-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-select-selection-search-mirror":{display:"none"},".rc-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},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"}}})),cl=({errorMessage:e})=>e?s.jsx(a.Text,{color:"red",size:12,children:e}):s.jsx(a.Text,{color:"dimmed",size:12,children:"Not found"}),u1=({disabled:e,classNames:t,styles:n,unstyled:r,radius:i,style:o,label:l,value:c,onChange:u,options:d,errorMessage:h,required:p})=>{const{classes:x,cx:m}=c1({radius:i},{name:"MultiSelectWidget",classNames:t,styles:n,unstyled:r}),[j,C]=g.useState(!1),T=R=>{C(R)},D=j&&(c==null?void 0:c.length)>0,[A,N]=g.useState(""),Y=g.useMemo(()=>{if(!A)return d;const R=A.toLowerCase(),F=Z=>{var se;return((se=Z.description)==null?void 0:se.toLowerCase().includes(R))||Z.label.toLowerCase().includes(R)};return d.filter(F)},[A,d]);return s.jsxs(a.Stack,{spacing:3,children:[s.jsxs(a.Group,{position:"apart",children:[s.jsxs(a.Text,{className:x.label,children:[l,p&&s.jsx("span",{className:x.required,"aria-hidden":"true",children:"*"})]}),D&&s.jsx(a.Tooltip,{label:`${c.length} selected`,children:s.jsx(a.Badge,{children:c.length})})]}),s.jsx(Ri,{disabled:e,allowClear:!0,className:m(x.root,"check-select"),dropdownClassName:m(x.dropdown,""),onDropdownVisibleChange:T,transitionName:"rc-select-dropdown-slide-up",choiceTransitionName:"rc-select-selection__choice-zoom",style:o,clearIcon:()=>s.jsx(a.CloseButton,{}),value:c,onChange:u,onSelect:console.log,mode:"multiple",maxTagCount:0,notFoundContent:s.jsx(cl,{errorMessage:h}),maxTagTextLength:10,maxTagPlaceholder:R=>`${R.length} selected`,searchValue:A,onSearch:N,filterOption:!1,children:Y.map(R=>s.jsxs(Ri.Option,{title:R.label,children:[s.jsx(a.Text,{size:"sm","data-role":"label",children:R.label}),R.description&&s.jsx(a.Text,{size:"xs",color:"dimmed","data-role":"description",children:R.description})]},R.value))})]})},d1=S.observer(({label:e,config:t,value:n,onChange:r})=>{const i=ce(),o=!!t.options_query_id,{state:l,error:c}=i.getDataStuffByID(t.options_query_id),u=l==="loading",d=t.min_width?t.min_width:"200px",h=o?u:!1,p=x=>r(x,!1);return s.jsx(u1,{label:e,options:t.options,style:{minWidth:"160px",width:d,maxWidth:h?d:"unset",borderColor:"#e9ecef"},disabled:h,value:n,onChange:p,errorMessage:c,required:t.required})}),p1=g.forwardRef(({label:e,description:t,...n},r)=>s.jsx("div",{ref:r,...n,children:s.jsx(a.Group,{noWrap:!0,children:s.jsxs("div",{children:[s.jsx(a.Text,{size:"sm","data-role":"label",children:e}),s.jsx(a.Text,{size:"xs",color:"dimmed","data-role":"description",children:t})]})})})),h1=S.observer(({label:e,config:t,value:n,onChange:r})=>{const i=ce(),o=!!t.options_query_id,{state:l,error:c}=i.getDataStuffByID(t.options_query_id),u=l==="loading";return s.jsx(a.Select,{label:e,data:t.options,disabled:o?u:!1,value:n,onChange:r,error:!!c,placeholder:c,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:p1})});function x1({label:e,config:t,value:n,onChange:r}){return s.jsx(a.TextInput,{label:e,value:n||"",onChange:i=>r(i.currentTarget.value),...t,styles:{input:{borderColor:"#e9ecef"}}})}const f1=({rotate:e,onClick:t})=>s.jsx("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:s.jsx("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"})}),g1=({expanded:e,isLeaf:t,value:n,onClick:r,...i})=>(n==="0-0-value"&&console.log(i),t?s.jsx("span",{style:{width:"14px",display:"inline-block"}}):s.jsx(f1,{rotate:e?"0":"-90",onClick:r,...i})),m1=({onClick:e})=>s.jsxs("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:[s.jsx("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),s.jsx("rect",{className:"border",x:"4",y:"4",width:"16",height:"16",rx:"2"}),s.jsx("rect",{className:"checkmark-indeterminate",x:"8",y:"8",width:"8",height:"8",rx:"2",stroke:"none"}),s.jsx("path",{className:"checkmark-checked",d:"M9 12l2 2l4 -4"})]}),y1=({onClick:e,...t})=>s.jsx(m1,{onClick:e,...t}),b1=a.createStyles((e,{radius:t=4})=>({root:{borderRadius:e.fn.radius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-tree-select.rc-tree-select-open":{borderColor:"#228be6 !important",".rc-tree-select-selection-overflow-item-rest":{display:"none"},".rc-tree-select-selection-overflow-item-suffix":{display:"block"}},".rc-tree-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-tree-select-selection-search-mirror":{display:"none"},".rc-tree-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-tree-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-tree-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-tree-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-tree-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-tree-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-tree-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-tree-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},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"}}}})),j1=({disabled:e,classNames:t,styles:n,unstyled:r,radius:i,style:o,label:l,value:c,onChange:u,treeData:d,errorMessage:h,required:p,treeCheckStrictly:x})=>{const{classes:m,cx:j}=b1({radius:i},{name:"FilterTreeSelectWidget",classNames:t,styles:n,unstyled:r}),[C,T]=g.useState(!1),D=N=>{T(N)},A=C&&(c==null?void 0:c.length)>0;return s.jsxs(a.Stack,{spacing:3,children:[s.jsxs(a.Group,{position:"apart",children:[s.jsxs(a.Text,{className:m.label,children:[l,p&&s.jsx("span",{className:m.required,"aria-hidden":"true",children:"*"})]}),A&&s.jsx(a.Tooltip,{label:`${c.length} selected`,children:s.jsx(a.Badge,{children:c.length})})]}),s.jsx(Qi,{disabled:e,allowClear:!0,treeCheckStrictly:x,labelInValue:!0,className:j(m.root,"check-select"),dropdownClassName:j(m.dropdown,""),onDropdownVisibleChange:D,transitionName:"rc-tree-select-dropdown-slide-up",choiceTransitionName:"rc-tree-select-selection__choice-zoom",style:o,listHeight:510,treeLine:!0,clearIcon:()=>s.jsx(a.CloseButton,{}),switcherIcon:g1,treeIcon:y1,maxTagTextLength:10,value:c,treeData:d,notFoundContent:s.jsx(cl,{errorMessage:h}),treeNodeFilterProp:"filterBasis",treeCheckable:!0,showCheckedStrategy:Qi.SHOW_PARENT,onChange:u,onSelect:console.log,maxTagCount:0,maxTagPlaceholder:()=>`${c.length} selected`})]})},v1=S.observer(({label:e,config:t,value:n,onChange:r})=>{const{treeData:i,treeDataLoading:o,errorMessage:l}=t,c=x=>{const m=x.map(j=>j.value);r(m,!1)},u=g.useMemo(()=>t.initialSelection(n),[n,t.plainData,t.defaultSelection,t.initialSelection]),d=t.min_width?t.min_width:"200px",p=!!t.options_query_id?o:!1;return s.jsx(j1,{disabled:p,style:{minWidth:"160px",width:d,maxWidth:p?d:"unset",borderColor:"#e9ecef"},value:[...u],onChange:c,treeData:i,errorMessage:l,label:e,required:t.required,treeCheckStrictly:t.treeCheckStrictly})}),w1=S.observer(({filter:{type:e,config:t,key:n,...r},formFieldProps:i})=>{switch(e){case"select":return s.jsx(h1,{...r,...i,config:t});case"multi-select":return s.jsx(d1,{...r,...i,config:t});case"tree-select":return s.jsx(v1,{...r,...i,config:t});case"text-input":return s.jsx(x1,{...r,...i,config:t});case"date-range":return s.jsx(ll,{...r,...i,config:t});case"checkbox":return s.jsx(s1,{...r,...i,config:t});default:return null}}),C1=S.observer(g.forwardRef(({filter:e,...t},n)=>s.jsx("div",{className:"filter-root",ref:n,children:s.jsx(je,{children:s.jsx(w1,{filter:e,formFieldProps:t})})}))),S1=({disabled:e})=>{const{searchButtonProps:t}=xa(),{children:n="Search",type:r,...i}=t;return s.jsx(a.Button,{color:"blue",size:"sm",type:"submit",...i,disabled:e||i.disabled,children:n})};function _1(e){const t=W();g.useEffect(()=>{var n,r;(r=(n=t.filters).updatePreviewValues)==null||r.call(n,e)},[e])}const k1=({opened:e,toggle:t})=>s.jsx(a.Group,{position:"right",ml:-4,mt:-4,mb:e?4:0,children:s.jsx(a.Button,{size:"xs",compact:!0,variant:"subtle",color:e?"gray":"blue",leftIcon:e?s.jsx(_.IconChevronsUp,{size:14}):s.jsx(_.IconChevronsDown,{size:14}),onClick:t,children:e?"Hide Filters":"Show Filters"})}),ul=S.observer(function({view:t}){const[n,{toggle:r}]=re.useDisclosure(!0),i=ce(),{control:o,handleSubmit:l,reset:c}=b.useForm({defaultValues:i.filters.values,reValidateMode:"onBlur"}),u=b.useWatch({control:o});g.useEffect(()=>{c(i.filters.values)},[i.filters.values,c]),_1(u);const d=i.filters.visibleInView(t.id),h=g.useMemo(()=>d.every(j=>j.should_auto_submit),[d]),p=g.useMemo(()=>d.filter(j=>y.get(j,"config.required",!1)),[d]),x=g.useMemo(()=>p.length===0?!1:p.some(j=>!j.requiredAndPass(u[j.key])),[u,p]);if(d.length===0)return null;const m=(j,C)=>(T,D)=>{C(T),(j.should_auto_submit||D)&&i.filters.setValueByKey(j.key,T)};return s.jsxs("form",{onSubmit:l(i.filters.setValues),children:[s.jsx(k1,{opened:n,toggle:r}),s.jsx(a.Collapse,{in:n,children:s.jsxs(a.Group,{className:"dashboard-filters",position:"apart",noWrap:!0,sx:h?{}:{border:"1px solid #e9ecef",borderRadius:"4px",padding:"16px"},children:[s.jsx(a.Group,{align:"flex-start",children:d.map(j=>s.jsx(b.Controller,{name:j.key,control:o,render:({field:C})=>s.jsx(C1,{filter:j,value:C.value,onChange:m(j,C.onChange)})},j.id))}),!h&&s.jsx(a.Group,{sx:{alignSelf:"flex-end"},children:s.jsx(S1,{disabled:x})})]})})]})}),T1={viewPanelInFullScreen:y.noop,inFullScreen:!1},Jn=g.createContext(T1),Ir=f.types.model("MockContextMeta",{current:f.types.optional(f.types.frozen(),{})}).views(e=>({get keys(){return Object.keys(e.current)},get keySet(){return new Set(this.keys)},get entries(){return Object.entries(e.current)}})).actions(e=>({replace(t){e.current=t},defaults(t){e.current={...t,...e.current}},get(t){return e.current[t]},set(t,n){e.current[t]=n}}));function Mr(e){return{current:e}}const D1=f.types.model("PanelStyleBorderMeta",{enabled:f.types.boolean}).views(e=>({get json(){const{enabled:t}=e;return{enabled:t}}})).actions(e=>({setEnabled(t){e.enabled=t}})),dl=f.types.model("PanelStyleMeta",{border:D1}).views(e=>({get json(){const{border:t}=e;return{border:t.json}}})).actions(e=>({})),pl=f.types.model("PanelTitleMeta",{show:f.types.optional(f.types.boolean,!0)}).views(e=>({get json(){const{show:t}=e;return{show:t}}})).actions(e=>({setShow(t){e.show=t}})),hl=f.types.model("VariableMeta",{name:f.types.string,size:f.types.string,weight:f.types.string,color:f.types.union(f.types.model({type:f.types.literal("static"),staticColor:f.types.string}),f.types.model({type:f.types.literal("continuous"),valueRange:f.types.array(f.types.number),colorRange:f.types.array(f.types.string)}),f.types.model({type:f.types.literal("piecewise")})),formatter:f.types.model({output:f.types.enumeration("Output",["number","percent"]),average:f.types.optional(f.types.boolean,!1),mantissa:f.types.number,trimMantissa:f.types.optional(f.types.boolean,!1),absolute:f.types.optional(f.types.boolean,!1)}),data_field:f.types.string,aggregation:f.types.union(f.types.model({type:f.types.enumeration(["none","sum","mean","median","min","max","CV","std"]),config:f.types.frozen(),fallback:f.types.optional(f.types.string,"0")}),f.types.model({type:f.types.literal("quantile"),config:f.types.model({p:f.types.number}),fallback:f.types.optional(f.types.string,"0")}),f.types.model({type:f.types.literal("custom"),config:f.types.model({func:f.types.string}),fallback:f.types.optional(f.types.string,"0")}))}).views(e=>({get json(){const{name:t,size:n,weight:r,color:i,formatter:o,data_field:l,aggregation:c}=e;return y.cloneDeep({name:t,size:n,color:i,weight:r,formatter:o,data_field:l,aggregation:c})}})),xl=f.types.model("PanelVizMeta",{type:f.types.string,conf:f.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}})),fl=f.types.model({id:f.types.string,name:f.types.optional(f.types.string,""),title:pl,description:f.types.string,queryIDs:f.types.array(f.types.string),viz:xl,style:dl,variables:f.types.optional(f.types.array(hl),[])}).views(e=>({get json(){const{id:t,name:n,title:r,description:i,queryIDs:o}=e;return{id:t,viz:e.viz.json,name:n,style:e.style.json,title:r.json,queryIDs:[...o],variables:e.variables.map(l=>l.json),description:i}},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=f.cast(Array.from(n))},setQueryIDs(t){e.queryIDs=f.cast(t)},addVariable(t){e.variables.push(t)},removeVariable(t){e.variables.remove(t)}}));var oe=(e=>(e.Postgresql="postgresql",e.MySQL="mysql",e.HTTP="http",e.Transform="transform",e))(oe||{});const gl=f.types.model("QueryMeta",{id:f.types.string,name:f.types.string,type:f.types.enumeration("DataSourceType",[oe.Postgresql,oe.MySQL,oe.HTTP,oe.Transform]),key:f.types.string,sql:f.types.string,pre_process:f.types.optional(f.types.string,""),post_process:f.types.optional(f.types.string,""),run_by:f.types.optional(f.types.array(f.types.string),[]),react_to:f.types.optional(f.types.array(f.types.string),[]),dep_query_ids:f.types.optional(f.types.array(f.types.string),[])}).views(e=>({get valid(){return e.id&&e.type&&e.key&&e.name?e.type===oe.HTTP?!!e.pre_process:!!e.sql:!1},get json(){const{id:t,name:n,type:r,key:i,sql:o,run_by:l,react_to:c,pre_process:u,post_process:d,dep_query_ids:h}=e;return At({id:t,key:i,sql:o,name:n,type:r,run_by:l,react_to:c,pre_process:u,post_process:d,dep_query_ids:h})}})).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},setDependantQueryIDs(t){e.dep_query_ids.length=0,e.dep_query_ids.push(...t)}})),ml=f.types.model("LayoutItemMeta",{id:f.types.identifier,panelID:f.types.string,x:f.types.number,y:f.types.maybeNull(f.types.number),w:f.types.number,h:f.types.number,moved:f.types.optional(f.types.boolean,!1),static:f.types.optional(f.types.boolean,!1)}).views(e=>({get json(){const{id:t,panelID:n,x:r,y:i,w:o,h:l,moved:c}=e;return{h:l,w:o,x:r,y:i===null?0:i,id:t,moved:c,static:e.static,panelID:n}},get contentModel(){return f.getRoot(e).content},get panel(){const{panelID:t}=e;return this.contentModel.panels.findByID(t)},get layoutProperies(){const{id:t,x:n,y:r,w:i,h:o,moved:l}=e;return{id:t,i:t,x:n,y:r===null?1/0:r,w:i,h:o,moved:l,static:e.static}}})).actions(e=>({set(t){const{isDraggable:n,x:r,y:i,w:o,h:l,moved:c}=t;e.x=r,e.y=i,e.w=o,e.h=l,e.moved=!!c,e.static=!!t.static},setWidth(t){e.w=t},setHeight(t){e.h=t}})),yl=f.types.model("LayoutSetMeta",{id:f.types.identifier,name:f.types.string,breakpoint:f.types.number,list:f.types.optional(f.types.array(ml),[])}).views(e=>({get json(){const{id:t,name:n,breakpoint:r,list:i}=e;return{id:t,name:n,breakpoint:r,list:i.map(o=>At(o.json))}},jsonByPanelIDSet(t){const{id:n,name:r,breakpoint:i,list:o}=e;return{id:n,name:r,breakpoint:i,list:o.filter(l=>t.has(l.panelID)).map(l=>At(l.json))}},findByID(t){return e.list.find(n=>n.id===t)},findByPanelID(t){return e.list.find(n=>n.panelID===t)}})).actions(e=>({setName(t){e.name=t},setBreakpoint(t){e.breakpoint=t},addLayout(t){e.list.push(t)},addNewLayout(t){e.list.push({id:pt.v4(),panelID:t,x:0,y:1/0,w:18,h:300,static:!1,moved:!1})},removeByPanelID(t){const n=e.list.findIndex(r=>r.panelID===t);n>=0&&e.list.splice(n,1)},updateLayoutItem(t){const n=e.list.find(r=>r.id===t.i);if(!n){console.error("Trying to update a layout that doesn't exist"),console.log({strangeLayoutItem:t});return}n.set(t)}})),bl=f.types.model("SQLSnippetMeta",{key:f.types.string,value:f.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 de=(e=>(e.Select="select",e.MultiSelect="multi-select",e.TreeSelect="tree-select",e.TextInput="text-input",e.Checkbox="checkbox",e.DateRange="date-range",e))(de||{});const zr=f.types.model("FilterCheckboxConfigMeta",{_name:f.types.literal("checkbox"),description:f.types.optional(f.types.string,""),default_value:f.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}})),jl=()=>zr.create({_name:"checkbox",description:"",default_value:!1});function vl(e,t){return e.map(n=>{try{return n?M.tz(n,"UTC").format(t):null}catch{return console.log(`[date-range] failed parsing ${n}`),null}})}const I1=f.types.model("FilterDateRangeConfigMeta",{_name:f.types.literal("date-range"),required:f.types.boolean,inputFormat:f.types.enumeration("DateRangeInputFormat",["YYYY","YYYYMM","YYYYMMDD","YYYY-MM","YYYY-MM-DD"]),default_value:f.types.optional(f.types.array(f.types.union(f.types.string,f.types.null)),[null,null]),default_shortcut:f.types.optional(f.types.string,""),clearable:f.types.boolean,max_days:f.types.optional(f.types.number,0),allowSingleDateInRange:f.types.optional(f.types.boolean,!1)}).views(e=>({get json(){const{_name:t,max_days:n,required:r,clearable:i,inputFormat:o,default_value:l,default_shortcut:c,allowSingleDateInRange:u}=e;return{_name:t,max_days:n,required:r,clearable:i,inputFormat:o,default_value:vl(l,o),default_shortcut:c,allowSingleDateInRange:u}},truthy(t){return Array.isArray(t)&&t.length===2&&t.every(n=>!!n)}})).actions(e=>({setFilterValue(t){try{const n=f.getParent(e);f.getParent(n,2).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)},setDefaultShortcut(t){if(e.default_shortcut=t,!t)return;const n=al(e.default_shortcut);if(console.log(n),n){const r=n.map(i=>M(i).format(e.inputFormat));e.setFilterValue(r)}},setMaxDays(t){e.max_days=t,t>0&&(e.clearable=!0)},setAllowSingleDateInRange(t){e.allowSingleDateInRange=t}})),Ar=f.types.snapshotProcessor(I1,{preProcessor({default_value:e,...t}){return{...t,default_value:e.map(n=>n===null?null:M.tz(n,"UTC").toISOString())}},postProcessor(e){const{default_value:t,...n}=e;return{...n,default_value:vl(t,n.inputFormat)}}}),wl=()=>Ar.create({_name:"date-range",required:!1,inputFormat:"YYYY-MM-DD",clearable:!1,default_value:[null,null]}),M1=f.types.model({label:f.types.string,value:f.types.string}).actions(e=>({setLabel(t){e.label=t},setValue(t){e.value=t}})),Er=f.types.model("FilterConfigModel_BaseSelect",{static_options:f.types.optional(f.types.array(M1),[]),options_query_id:f.types.optional(f.types.string,""),default_selection_count:f.types.optional(f.types.number,0),required:f.types.optional(f.types.boolean,!1)}).views(e=>({get contentModel(){return f.getRoot(e).content},get filter(){return f.getParent(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}=e.contentModel.getDataStuffByID(e.options_query_id);return n==="idle"?Array.isArray(t)?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??""}})),Pr=f.types.compose("FilterMultiSelectConfigMeta",f.types.model({_name:f.types.literal("multi-select"),min_width:f.types.optional(f.types.string,""),default_value:f.types.optional(f.types.array(f.types.string),[])}),Er).views(e=>({get json(){const{_name:t,default_value:n,required:r,min_width:i,static_options:o,options_query_id:l,default_selection_count:c}=e;return At({_name:t,required:!!r,min_width:i,default_value:n,static_options:o,options_query_id:l,default_selection_count:c})},get default_selection(){return e.usingQuery?e.options.slice(0,e.default_selection_count).map(t=>t.value):e.filter.formattedDefaultValue},truthy(t){return Array.isArray(t)&&t.length>0}})).actions(e=>({setDefaultValue(t){e.default_value=f.cast(t)},setMinWidth(t){e.min_width=t},setDefaultSelection(){const t=f.getRoot(e).content.filters,n=f.getParent(e).key;t.setValueByKey(n,e.default_selection)}})).actions(e=>({afterCreate(){f.addDisposer(e,U.reaction(()=>U.toJS(e.default_selection),e.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),Cl=()=>Pr.create({_name:"multi-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),Lr=f.types.compose("FilterConfigModel_Select",f.types.model({_name:f.types.literal("select"),default_value:f.types.string,width:f.types.optional(f.types.string,"")}),Er).views(e=>({get json(){const{_name:t,default_value:n,required:r,width:i,static_options:o,options_query_id:l,default_selection_count:c}=e;return At({_name:t,width:i,required:r,default_value:n,static_options:o,options_query_id:l,default_selection_count:c})},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.filter.formattedDefaultValue}})).actions(e=>({setDefaultValue(t){e.default_value=t},setWidth(t){e.width=t},setDefaultSelection(){const t=f.getRoot(e).content.filters,n=f.getParent(e).key;t.setValueByKey(n,e.default_selection)}})).actions(e=>({afterCreate(){f.addDisposer(e,U.reaction(()=>U.toJS(e.default_selection),e.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),Sl=()=>Lr.create({_name:"select",required:!1,default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),Br=f.types.model("FilterTextInputConfigMeta",{_name:f.types.literal("text-input"),required:f.types.boolean,default_value:f.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}})),Or=()=>Br.create({_name:"text-input",required:!1,default_value:""});function z1(e){return fu.arrayToTree(e,{id:"value",parentId:"parent_value",childrenField:"children",dataField:null})}function A1(e){return e.map(t=>{const{label:n,description:r,...i}=t,o={...i,filterBasis:`${n}___${r??""}`,description:r,label:n};return r&&(o.label=g.createElement("div",{},[g.createElement(a.Text,{key:0,title:t.label},t.label),g.createElement(a.Text,{key:1,className:"rc-tree-select-tree-title-desc",color:"dimmed",title:t.description},t.description)])),o})}const $r=f.types.compose("FilterTreeSelectConfigMeta",f.types.model({_name:f.types.literal("tree-select"),min_width:f.types.optional(f.types.string,""),default_value:f.types.optional(f.types.array(f.types.string),[]),treeCheckStrictly:f.types.optional(f.types.boolean,!1)}),Er).views(e=>({get json(){const{_name:t,default_value:n,required:r,min_width:i,static_options:o,options_query_id:l,default_selection_count:c,treeCheckStrictly:u}=e;return{_name:t,required:!!r,min_width:i,default_value:n,static_options:o,options_query_id:l,treeCheckStrictly:u,default_selection_count:c}},get plainData(){const{data:t}=e.contentModel.getDataStuffByID(e.options_query_id);return t},get treeData(){const t=this.plainData,n=A1(t);return z1(n)},get errorMessage(){const{error:t}=e.contentModel.getDataStuffByID(e.options_query_id);return t},get treeDataLoading(){const{state:t}=e.contentModel.getDataStuffByID(e.options_query_id);return t==="loading"},get defaultSelection(){const t=e.filter.formattedDefaultValue;if(Array.isArray(t)&&t.length>0)return t;const{default_selection_count:n}=e;return n?this.treeData.slice(0,n).map(i=>i.value):[]},valueObjects(t){const n=new Set(t);return this.plainData.filter(r=>n.has(r.value))},initialSelection(t){return!t||t.length===0?this.valueObjects(this.defaultSelection):this.valueObjects(t)},truthy(t){return Array.isArray(t)&&t.length>0}})).actions(e=>({setDefaultValue(t){e.default_value=f.cast(t)},setMinWidth(t){e.min_width=t},setTreeCheckStrictly(t){e.treeCheckStrictly=t},applyDefaultSelection(){const t=f.getParent(e,1).key;e.contentModel.filters.setValueByKey(t,e.defaultSelection)},afterCreate(){f.addDisposer(e,U.reaction(()=>JSON.stringify(e.defaultSelection),this.applyDefaultSelection,{fireImmediately:!0,delay:0}))}})),_l=()=>$r.create({_name:"tree-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),Vr=f.types.model("FilterMeta",{id:f.types.identifier,key:f.types.string,label:f.types.string,order:f.types.number,visibleInViewsIDs:f.types.array(f.types.string),auto_submit:f.types.optional(f.types.boolean,!1),default_value_func:f.types.optional(f.types.string,""),type:f.types.enumeration("DashboardFilterType",[de.Select,de.MultiSelect,de.TreeSelect,de.TextInput,de.Checkbox,de.DateRange]),config:f.types.union(Lr,Pr,$r,Br,zr,Ar)}).views(e=>({get contentModel(){return f.getRoot(e).content},get filters(){return this.contentModel.filters},get plainDefaultValue(){const t=e.config.default_value;return Array.isArray(t)?[...t]:t},get usingDefaultValue(){return e.type!==de.TreeSelect},get usingDefaultValueFunc(){return!!e.default_value_func},get formattedDefaultValue(){return this.filters.formattedDefaultValues[e.key]},get auto_submit_supported(){return[de.Select,de.Checkbox,de.DateRange].includes(e.type)}})).views(e=>({get json(){const{id:t,key:n,label:r,order:i,visibleInViewsIDs:o,default_value_func:l,auto_submit:c,type:u,config:d}=e;return{id:t,key:n,type:u,label:r,order:i,config:d.json,auto_submit:c,visibleInViewsIDs:U.toJS(o),default_value_func:l}},get visibleInViewsIDSet(){return new Set(e.visibleInViewsIDs)},get should_auto_submit(){return e.auto_submit_supported&&e.auto_submit},requiredAndPass(t){return y.get(e.config,"required",!1)?y.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 de.Select:e.config=Sl();break;case de.MultiSelect:e.config=Cl();break;case de.TreeSelect:e.config=_l();break;case de.TextInput:e.config=Or();break;case de.Checkbox:e.config=jl();break;case de.DateRange:e.config=wl();break}e.type=t},setVisibleInViewsIDs(t){e.visibleInViewsIDs.length=0,e.visibleInViewsIDs.push(...t)},setAutoSubmit(t){e.auto_submit=e.auto_submit_supported&&t},setDefaultValueFunc(t){e.default_value_func=t}}));var L=(e=>(e.Division="div",e.Modal="modal",e.Tabs="tabs",e))(L||{});const qr=f.types.model("ViewDivisionConfig",{_name:f.types.literal(L.Division)}).views(e=>({get json(){const{_name:t}=e;return{_name:t}}})),kl=()=>qr.create({_name:L.Division}),E1=f.types.model("CustomModalTitleModel",{enabled:f.types.optional(f.types.boolean,!1),func_content:f.types.optional(f.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=f.getParent(e,2),i=f.getRoot(e);if(!t)return r.name;try{const o={filters:i.content.filters.values,context:i.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}})),Zn={enabled:!1,func_content:["function text({ filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
450
+ `)},Nr=f.types.model("ViewModalConfig",{_name:f.types.literal(L.Modal),width:f.types.string,height:f.types.string,custom_modal_title:f.types.optional(E1,Zn)}).views(e=>({get json(){const{_name:t,width:n,height:r,custom_modal_title:i}=e;return{_name:t,width:n,height:r,custom_modal_title:i.json}}})).actions(e=>({setWidth(t){e.width=t},setHeight(t){e.height=t}})),Tl=()=>Nr.create({_name:L.Modal,width:"90vw",height:"90vh"}),P1=f.types.model("ViewTabsTabModel",{id:f.types.identifier,name:f.types.string,view_id:f.types.string,color:f.types.optional(f.types.string,""),order:f.types.optional(f.types.number,0)}).views(e=>({get json(){const{id:t,name:n,view_id:r,color:i,order:o}=e;return{id:t,name:n,color:i,order:o,view_id:r}}})).actions(e=>({setName(t){e.name=t},setViewID(t){e.view_id=t},setColor(t){e.color=t},setOrder(t){e.order=t}})),Fr=f.types.model("ViewTabsConfig",{_name:f.types.literal(L.Modal),tabs:f.types.optional(f.types.array(P1),[]),variant:f.types.optional(f.types.enumeration("variant",["default","outline","pills"]),"default"),orientation:f.types.optional(f.types.enumeration("orientation",["horizontal","vertical"]),"horizontal"),grow:f.types.optional(f.types.boolean,!1)}).views(e=>({get json(){const{_name:t,variant:n,orientation:r,tabs:i,grow:o}=e;return{grow:o,tabs:i.map(l=>l.json),_name:t,variant:n,orientation:r}},get tabsInOrder(){return y.sortBy(e.tabs,"order")}})).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=f.cast(t)},addTab(){const t=re.randomId(),n={id:t,name:t,view_id:""};e.tabs.push(n)},removeTab(t){e.tabs.splice(t,1)}})),Dl=()=>Fr.create({_name:L.Modal,tabs:[]}),Il=f.types.model({id:f.types.identifier,name:f.types.string,type:f.types.enumeration("EViewComponentType",[L.Division,L.Modal,L.Tabs]),config:f.types.union(qr,Nr,Fr),panelIDs:f.types.optional(f.types.array(f.types.string),[])}).views(e=>({get json(){const{id:t,name:n,type:r,config:i}=e;return{id:t,name:n,type:r,config:i.json,panelIDs:e.panelIDs.map(o=>o)}}})).actions(e=>({setName(t){e.name=t},setType(t){if(e.type!==t){switch(t){case L.Division:e.config=kl();break;case L.Modal:e.config=Tl();break;case L.Tabs:e.config=Dl();break}e.type=t}},appendPanelID(t){e.panelIDs.push(t)},appendPanelIDs(t){e.panelIDs.push(...t)},removePanelID(t){const n=e.panelIDs.filter(r=>r!==t);e.panelIDs.length=0,e.panelIDs.push(...n)}})),at="11.10.0",L1={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:L.Division,config:{},panelIDs:[]}],panels:[],filters:[],version:at,layouts:[{id:"basis",name:"basis",list:[],breakpoint:0}]},Gr=f.types.model("DataSourceMetaModel",{id:f.types.string,type:f.types.enumeration("DataSourceType",[oe.HTTP,oe.MySQL,oe.Postgresql]),key:f.types.string,config:f.types.frozen()}),Ml=f.types.model("DataSourcesMetaModel",{list:f.types.optional(f.types.array(Gr),[])}).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)}})),zl=f.types.model({id:f.types.string,content:f.types.string,create_time:f.types.string,update_time:f.types.string,is_preset:f.types.boolean}),Wr=f.types.model("GlobalSQLSnippetsMeta",{list:f.types.optional(f.types.array(zl),[])}).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)}})),Hn=f.types.model("ContextMeta",{current:f.types.optional(f.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 Rr(e){return Hn.create({current:e})}const Qr=f.types.compose("ViewRenderModel",Il,f.types.model({tab:f.types.optional(f.types.string,"")})).views(e=>({get defaultTab(){if(e.type!==L.Tabs)return"";const t=e.config;return t.tabs.length>0?t.tabs[0].id:""},get tabViewID(){var n;return e.type!==L.Tabs?"":((n=e.config.tabs.find(r=>r.id===e.tab))==null?void 0:n.view_id)??""},get contentModel(){return f.getParent(e,3)},get panels(){if(e.type!==L.Tabs)return this.contentModel.panels.panelsByIDs(e.panelIDs);const t=this.tabViewID,n=this.contentModel.views.findByID(t);return(n==null?void 0:n.panels)??[]},get renderViewIDs(){const t=[e.id];return e.type===L.Tabs&&t.push(this.tabViewID),t},async downloadScreenshot(t){const n=t.offsetWidth*2+10,r=t.offsetHeight*2+10,i=new Ki,o=new Date().getTime(),l=await Ui.toBlob(t,{bgcolor:"white",width:n,height:r,style:{transformOrigin:"0 0",transform:"scale(2)"}});i.file(`${e.name}_${o}.png`,l),i.file(`dashboard_state_${o}.json`,JSON.stringify(this.contentModel.dashboardState,null,4)),i.generateAsync({type:"blob"}).then(c=>{gn.saveAs(c,`${e.name}_${o}.zip`)}).catch(c=>{console.error(c),ut.notifications.show({color:"red",title:"Failed to download screenshot with dashboard state",message:c.message})})}})).actions(e=>({setTab(t){e.tab=t??""},afterCreate(){f.addDisposer(e,U.reaction(()=>e.defaultTab,t=>this.setTab(t),{fireImmediately:!0,delay:0}))}})),Ur=f.types.model("ViewsRenderModel",{current:f.types.optional(f.types.array(Qr),[]),visibleViewIDs:f.types.array(f.types.string)}).views(e=>({get json(){return e.current.map(t=>At(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 Al(e){const t=e.length>0?[e[0].id]:[];return{current:e.map(r=>{const{_name:i=r.type}=r.config;return{...r,config:{...r.config,_name:i},panelIDs:r.panelIDs}}),visibleViewIDs:t}}const B1=new gu.AsyncParser({withBOM:!0});async function El(e){return!Array.isArray(e)||e.length===0?"":await B1.parse(e).promise()}async function O1(e,t){const n=await El(t),r=new Blob([n],{type:"text/csv"});gn.saveAs(r,`${e}.csv`)}function Pl(e){const t=new Ki,n=e.map(async({id:r,data:i})=>{const o=await El(i);t.file(`${r}.csv`,o)});Promise.all(n).then(()=>{t.generateAsync({type:"blob"}).then(r=>{gn.saveAs(r,"dashboard_data.zip")})}).catch(r=>{console.error(r),ut.notifications.show({color:"red",title:"Failed to download data",message:r.message})})}function Nt(e,t){const n=new Blob([t],{type:"application/json"});gn.saveAs(n,`${e}.json`)}const Kr=fl.views(e=>({get contentModel(){return f.getRoot(e).content}})).views(e=>({get queries(){return e.contentModel.queries.findByIDSet(e.queryIDSet)},queryByID(t){return this.queries.find(n=>n.id===t)},get data(){return this.queries.reduce((t,n)=>(t[n.id]=n.data,t),{})},get variableStrings(){return na(e.variables,this.data)},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(c=>n.add(c)),l.filters.forEach(c=>r.add(c))});const i=[];return n.size>0&&(console.log(n),i.push(`context: ${Array.from(n).join(", ")}`)),r.size>0&&i.push(`filter${r.size>1?"s":""}: ${Array.from(r).join(", ")}`),i.length===2&&i.splice(1,0,"and"),i.unshift("Waiting for"),i.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(){e.contentModel.queries.downloadDataByQueryIDs(e.queryIDs)},getSchema(){const t=e.json;return t.viz.conf={...t.viz.conf,__INTERACTIONS:{},__OPERATIONS:{},__TRIGGERS:{}},{panel:t,queries:e.queries.map(n=>n.json),layouts:e.contentModel.layouts.jsonByPanelIDSet(new Set([e.id]))}},downloadSchema(){const{panel:t,queries:n,layouts:r}=this.getSchema(),o=JSON.stringify({panels:[t],definition:{queries:n},layouts:r,version:at},null,2),l=e.name;Nt(l,o)}}));function Ll(e){return{id:e,name:e,title:{show:!0},description:"<p></p>",queryIDs:[],viz:{type:gr.name,conf:gr.createConfig()},style:{border:{enabled:!0}}}}const Yr=f.types.model("PanelsRenderModel",{list:f.types.optional(f.types.array(Kr),[])}).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=[];return t.forEach(r=>{const i=e.idMap.get(r);i?n.push(i):console.warn(`Panel is not found, id:${r}`)}),n}}));function Bl(e){const t=e.config,n=t.default_value;if(n===void 0)return n;if(t._name==="date-range")try{if(t.default_shortcut){const i=al(t.default_shortcut);if(i)return i.map(o=>M(o).format(t.inputFormat))}const[...r]=n;return r.map(i=>i===null?i:M.tz(i,"UTC").format(t.inputFormat)??i)}catch(r){return console.error(r),n}return n}function $1(e,t){const n=e.default_value_func;try{return new Function(`return ${n}`)()(e,nt,t)}catch(r){return console.error(r),Bl(e)}}function Ol(e,t){var n;return(n=e.default_value_func)!=null&&n.trim()?$1(e,t):Bl(e)}function $l(e,t){return e.reduce((n,r)=>(n[r.key]=Ol(r,t),n),{})}const Xr=f.types.model("FiltersRenderModel",{current:f.types.optional(f.types.array(Vr),[]),values:f.types.optional(f.types.frozen(),{})}).views(e=>({get json(){return e.current.map(t=>t.json)},get contentModel(){return f.getRoot(e).content},get context(){return this.contentModel.payloadForSQL.context},get initialValuesDep(){return JSON.stringify({filters:e.current.map(({default_value_func:t,config:n})=>({default_value_func:t,config:n})),context:this.contentModel.payloadForSQL.context})},get formattedDefaultValues(){return $l(this.json,this.contentModel.context)},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 inOrder(){return y.sortBy(e.current,"order")},get empty(){return e.current.length===0},visibleInView(t){return y.sortBy(e.current.filter(n=>n.visibleInViewsIDSet.has(t)),"order")},get firstFilterValueKey(){return Object.keys(e.values)[0]??""},get keySet(){return new Set(e.current.map(t=>t.key))},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},patchValues(t){e.values=y.defaults({},t,e.values)},setValueByKey(t,n){e.values={...e.values,[t]:n}},getValueByKey(t){return e.values[t]},getSchema(t,n){return{filters:e.findByIDSet(new Set(t)).map(o=>({...o.json,visibleInViewsIDs:n?o.json.visibleInViewsIDs:[]})),version:at}},downloadSchema(t){const n=JSON.stringify(this.getSchema(t,!1),null,2);Nt("Filters",n)}}));function Jr(e,t,n,r){const i=y.defaults({},r,$l(e,{...n,...t}));return{current:e,values:i}}const Vl=gl.views(e=>({get rootModel(){return f.getRoot(e)},get contentModel(){return this.rootModel.content},get conditionOptions(){if(!f.isAlive(e))return[];const{context:t}=this.contentModel.payloadForSQL,n=Object.keys(t).map(l=>({group:"Context",label:l,value:`context.${l}`,description:void 0})),r=this.contentModel.filters.keyLabelOptions.map(l=>({group:"Filters",label:l.label,value:`filters.${l.value}`,description:l.value})),i=[...n,...r],o=new Set(i.map(l=>l.value));return e.run_by.forEach(l=>{o.has(l)||i.push({group:"Invalid",label:l,value:l})}),i},get unmetRunByConditions(){if(!f.isAlive(e))return[];const{run_by:t}=e;if(t.length===0)return[];const n=this.contentModel.payloadForSQL;return t.filter(r=>{const i=y.get(n,r);return Array.isArray(i)?i.length===0:typeof i=="number"?Number.isNaN(i):!i})}})).views(e=>({get payload(){return e.contentModel.payloadForSQL},get formattedSQL(){return xs(e.sql,this.payload)},get httpConfigString(){const{context:t,filters:n}=this.payload,{name:r,pre_process:i}=e.json,o=_d(i,t,n);return console.groupCollapsed(`Request config for: ${r}`),console.log(o),console.groupEnd(),JSON.stringify(o)},get typedAsSQL(){return[oe.Postgresql,oe.MySQL].includes(e.type)},get typedAsHTTP(){return[oe.HTTP].includes(e.type)},get isTransform(){return e.type===oe.Transform},get reQueryKey(){const{react_to:t=[]}=e;if(t.length===0)return"";const n=e.contentModel.payloadForSQL,r=[...t].reduce((i,o)=>(i[o]=y.get(n,o),i),{});return JSON.stringify(r)},get runByConditionsMet(){return e.unmetRunByConditions.length===0},get conditionNames(){if(e.unmetRunByConditions.length===0)return{context:[],filters:[]};const{keyLabelMap:t}=e.contentModel.filters,n=e.unmetRunByConditions.filter(i=>i.startsWith("context.")).map(i=>i.replace("context.","")),r=e.unmetRunByConditions.filter(i=>i.startsWith("filters.")).map(i=>y.get({filters:t},i,i.replace("filters.",""))).filter(i=>!!i);return{context:n,filters:r}},get queries(){return f.getParent(e,2)},get inUse(){return this.queries.isQueryInUse(e.id)},get dependencies(){if(!this.typedAsSQL)return[];const t=y.uniq(e.sql.match(jn.sqlSnippet)),n=y.uniq(e.sql.match(jn.filter)),r=y.uniq(e.sql.match(jn.context)),i=[];return t.forEach(o=>{i.push({type:"SQL Snippet",key:o,valid:e.contentModel.sqlSnippets.keySet.has(o)})}),n.forEach(o=>{i.push({type:"Filter",key:o,valid:e.contentModel.filters.keySet.has(o)})}),r.forEach(o=>{i.push({type:"Context",key:o,valid:e.contentModel.mock_context.keySet.has(o)})}),i}})),Zr=f.types.compose("QueryRenderModel",Vl,f.types.model({state:f.types.optional(f.types.enumeration(["idle","loading","error"]),"idle"),data:f.types.optional(f.types.frozen([]),[]),error:f.types.frozen()})).views(e=>({get datasource(){const{key:t,type:n}=e;return e.rootModel.datasources.find({type:n,key:t})},get additionalQueryInfo(){return e.contentModel.getAdditionalQueryInfo(e.id)},get depQueryModels(){return e.contentModel.queries.findByIDSet(new Set(e.dep_query_ids))},get depQueryModelStates(){return this.depQueryModels.map(t=>t.state)},get depQueryModelStatesString(){return this.depQueryModelStates.toString()}})).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:f.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*f.toGenerator(Md({payload:n,name:e.name,query:e.json,additionals:e.additionalQueryInfo},e.controller.signal)),e.state="idle",e.error=null}catch(n){if(!He.isCancel(n)){e.data=[];const r=y.get(n,"message","unkown error");e.error=y.get(n,"response.data.detail.message",r),e.state="error"}}}}),runHTTP:f.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:i}=e.json;let o=JSON.parse(e.httpConfigString);o=kd(e.datasource,o);const l=yield*f.toGenerator(zd({type:n,key:r,configString:JSON.stringify(o),name:e.name,additionals:e.additionalQueryInfo},e.controller.signal)),c=Td(e.datasource,l),u=Dd(i,c,e.contentModel.dashboardState);e.data=u,e.state="idle",e.error=null}catch(n){if(console.error(n),!He.isCancel(n)){e.data=[];const r=y.get(n,"message","unkown error");e.error=y.get(n,"response.data.detail.message",r),e.state="error"}}}}),runTransformation(){e.state="loading";try{const n=e.contentModel.queries.findByIDSet(new Set(e.dep_query_ids)).map(l=>({id:l.id,name:l.name,data:l.data})),r=e.contentModel.dashboardState,i=e.pre_process,o=new Function(`return ${i}`)()(n,r,nt);e.data=o,e.state="idle",e.error=null}catch(t){e.data=[],e.error=t.message,e.state="error"}}})).actions(e=>({fetchData:t=>{if(!e.inUse&&!t){console.debug(`🟡 Skipping query[${e.name}]`);return}return console.debug(`🔵 Running query[${e.name}]`),e.isTransform?e.runTransformation():e.typedAsHTTP?e.runHTTP():e.runSQL()},beforeDestroy(){var t;(t=e.controller)==null||t.abort()}})).actions(e=>({afterCreate(){f.addDisposer(e,U.reaction(()=>{var n;return e.isTransform?[e.inUse,e.id,e.key,e.dep_query_ids.toString(),e.pre_process,e.depQueryModelStatesString].join("--"):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}))}})),Hr=f.types.model("QueriesRenderModel",{current:f.types.optional(f.types.array(Zr),[])}).views(e=>({get idSet(){return new Set(e.current.map(t=>t.id))},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 f.getParent(e,1)},get visibleQueryIDSet(){const{views:t,filters:n,queries:r}=this.contentModel,i=[];t.visibleViews.forEach(c=>{c.panels.forEach(u=>{i.push(...u.queryIDs)})});const o=y.uniq(t.visibleViews.map(c=>c.renderViewIDs).flat());n.current.forEach(c=>{const u=y.get(c,"config.options_query_id");if(!u)return;o.some(h=>c.visibleInViewsIDSet.has(h))&&i.push(u)}),r.findByIDSet(new Set(i)).forEach(c=>{!c.isTransform||c.dep_query_ids.length===0||i.push(...c.dep_query_ids)});const l=new Set(i);return console.debug("QueryIDs:",l),l},isQueryInUse(t){return this.visibleQueryIDSet.has(t)}})).actions(e=>({downloadAllData(){const t=e.current.map(({name:n,data:r})=>({id:n,data:r}));Pl(t)},downloadDataByQueryIDs(t){const n=new Set(t),r=e.current.filter(i=>n.has(i.id)).map(({name:i,data:o})=>({id:i,data:o}));Pl(r)},downloadDataByQueryID(t){const n=e.findByID(t);if(!n){console.log("[downloadDataByQueryID] query not found");return}const{name:r,data:i}=n;O1(r,i)},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)},getSchema(t){return{definition:{queries:e.findByIDSet(new Set(t)).map(i=>i.json)},version:at}},downloadSchema(t){const n=JSON.stringify(this.getSchema(t),null,2);Nt("Queries",n)}}));function ql(e){return{current:e}}function Nl({min:e,max:t}){const n=`${e}px`,r=Number.isFinite(t)?`${t}px`:"∞";return`[${n}, ${r})`}const ei=f.types.model("LayoutsRenderModel",{list:f.types.array(yl),currentBreakpoint:f.types.string}).views(e=>({get json(){return e.list.map(t=>t.json)},jsonByPanelIDSet(t){return e.list.map(n=>n.jsonByPanelIDSet(t))},get root(){return f.getRoot(e)},get contentModel(){return this.root.content},get basisLayoutSet(){return e.list.find(t=>t.id==="basis")},get currentLayoutSet(){return e.list.find(t=>t.id===e.currentBreakpoint)},get currentLayoutRange(){return this.breakpointRanges.find(t=>t.id===e.currentBreakpoint)},get currentRangeText(){const t=this.currentLayoutRange;return Nl(t)},get cols(){const t={};return e.list.forEach(n=>{t[n.id]=36}),t},get breakpoints(){const t={};return e.list.forEach(n=>{t[n.id]=n.breakpoint}),t},get breakpointNameRecord(){const t={};return e.list.forEach(n=>{t[n.name]=n.breakpoint}),t},get breakpointRanges(){const t=e.list.map(n=>({id:n.id,name:n.name,min:n.breakpoint,max:1/0,text:""}));return t.sort((n,r)=>n.min-r.min).forEach((n,r)=>{r!==t.length-1&&(n.max=t[r+1].min)}),t.forEach(n=>{n.text=Nl(n)}),t},get breakpointsInfo(){return e.list.map(t=>({id:t.id,name:t.name,breakpoint:t.breakpoint})).sort((t,n)=>t.breakpoint-n.breakpoint)},get currentBreakpointRange(){return this.breakpointRanges.find(t=>t.id===e.currentBreakpoint)},get currentLayoutPreviewWidth(){const t=this.currentBreakpointRange;if(t)return t.max===1/0?t.min===0?void 0:t.min+1:t.max},items(t){const n=new Set(t);return this.currentLayoutSet.list.filter(i=>n.has(i.panelID))},gridLayouts(t){const n=new Set(t),r={};return e.list.forEach(i=>{r[i.id]=i.list.filter(o=>n.has(o.panelID)).map(o=>o.layoutProperies)}),r},findItemByPanelID(t){return this.currentLayoutSet.findByPanelID(t)}})).actions(e=>({setCurrentBreakpoint(t){console.log("🔴 onBreakpointChange:",t),e.currentBreakpoint=t},afterCreate(){f.addDisposer(e,U.reaction(()=>e.currentBreakpoint,()=>{setTimeout(()=>{window.dispatchEvent(new Event("resize"))},32)},{fireImmediately:!1,delay:0}))}})),Fl=bl.views(e=>({isADuplicatedKey(t){return!t||t===e.key?!1:!!f.getParent(e,2).findByKey(t)}})),ti=f.types.model("SQLSnippetsRenderModel",{current:f.types.optional(f.types.array(Fl),[])}).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 keySet(){return new Set(e.current.map(t=>t.key))},get firstKey(){if(e.current.length!==0)return e.current[0].key},findByKey(t){return e.current.find(n=>n.key===t)},findByKeySet(t){return e.current.filter(n=>t.has(n.key))}})).actions(e=>({getSchema(t){return{definition:{sqlSnippets:e.findByKeySet(new Set(t)).map(i=>i.json)},version:at}},downloadSchema(t){const n=JSON.stringify(this.getSchema(t),null,2);Nt("SQL Snippets",n)}}));function Gl(e){return{current:e}}function ln(e,t,n,r){return e.reduce((i,o)=>{try{i[o[t]]=hs(o[n],r)}catch(l){i[o[t]]=l.message}return i},{})}class Wl{constructor(t){P(this,"origin");P(this,"copy");this.origin=t,this.copy=f.clone(t),U.makeAutoObservable(this,{},{autoBind:!0,deep:!1})}get changed(){return!y.isEqual(f.getSnapshot(this.origin),f.getSnapshot(this.copy))}commit(){f.applySnapshot(this.origin,f.getSnapshot(this.copy))}reset(){f.applySnapshot(this.copy,f.getSnapshot(this.origin))}update(t){f.applySnapshot(this.copy,t)}}const Rl=e=>new Wl(e),V1=S.observer(({view:e})=>{const t=X(),n=W(),r=ze.useModals(),{panel:i,downloadPanelScreenshot:o}=Ee(),{id:l}=i,{viewPanelInFullScreen:c,inFullScreen:u}=g.useContext(Jn),d=()=>{n.duplicatePanelByID(l,e.id)},h=()=>{t.editor.open(["_VIEWS_",e.id,"_PANELS_",l])},p=()=>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}),x=g.useCallback(()=>{c(l)},[l,c]),m=!u&&e.type!==L.Modal;return s.jsx(s.Fragment,{children:s.jsx(a.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:s.jsxs(a.Menu,{withinPortal:!0,children:[s.jsx(a.Menu.Target,{children:s.jsx(a.Box,{className:"panel-dropdown-target",sx:{width:"100%"}})}),s.jsxs(a.Menu.Dropdown,{children:[s.jsx(a.Menu.Item,{onClick:i.refreshData,icon:s.jsx(k.Refresh,{size:14}),children:"Refresh"}),s.jsx(a.Menu.Item,{onClick:i.downloadData,icon:s.jsx(k.Download,{size:14}),children:"Download Data"}),s.jsx(a.Menu.Item,{onClick:i.downloadSchema,icon:s.jsx(_.IconCode,{size:14}),children:"Download Schema"}),s.jsx(a.Menu.Item,{onClick:o,icon:s.jsx(_.IconCamera,{size:14}),children:"Screenshot"}),m&&s.jsx(a.Menu.Item,{onClick:x,icon:s.jsx(k.ArrowsMaximize,{size:14}),disabled:!0,children:"Full Screen"}),s.jsx(a.Divider,{label:"Edit",labelPosition:"center"}),s.jsx(a.Menu.Item,{onClick:h,icon:s.jsx(k.Settings,{size:14}),children:"Settings"}),s.jsx(a.Menu.Item,{onClick:d,icon:s.jsx(k.Copy,{size:14}),children:"Duplicate"}),s.jsx(a.Menu.Item,{color:"red",onClick:p,icon:s.jsx(k.Trash,{size:14}),children:"Delete"})]})]})})})});function q1(e){return e?["<p><br></p>","<p></p>"].includes(e):!0}const ni=S.observer(()=>{const[e,t]=g.useState(!1),{panel:n}=xt();return q1(n.description)?null:s.jsxs(s.Fragment,{children:[s.jsx(a.Modal,{opened:e,onClose:()=>t(!1),title:n.title.show?n.name:"",withCloseButton:!1,withinPortal:!0,zIndex:310,children:s.jsx(Nn,{value:n.description,styles:{root:{border:"none"},content:{padding:0}},sx:{".mantine-RichTextEditor-content .ProseMirror":{padding:"0 !important"}}})}),s.jsx(a.Tooltip,{label:"Click to see description",position:"top-start",withinPortal:!0,children:s.jsx(a.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>t(r=>!r),sx:{verticalAlign:"baseline",cursor:"pointer"},children:s.jsx(k.InfoCircle,{size:20})})})]})}),GI="",N1=S.observer(function(){const{panel:t}=xt(),{name:n,title:r}=t;return r.show?s.jsx(a.Group,{grow:!0,position:"center",className:"panel-title-wrapper",sx:{flexGrow:1},children:s.jsx(a.Text,{align:"center",lineClamp:1,className:"panel-title-text",children:n})}):null});function F1(e){const t=g.useRef(null);return{ref:t,downloadPanelScreenshot:()=>{const r=t.current;if(!r)return;const i=r.offsetWidth*2,o=r.offsetHeight*2;Ui.toBlob(t.current,{bgcolor:"white",width:i,height:o,style:{border:"none",borderRadius:0,transformOrigin:"0 0",transform:"scale(2)"}}).then(l=>{window.saveAs(l,`${e.name?e.name:e.viz.type}.png`)})}}}var Ql=(e=>(e.migrated="migrated",e.nothingToMigrate="nothingToMigrate",e.checkFailed="checkFailed",e.migrationFailed="migrationFailed",e))(Ql||{}),es=(e=>(e.notStarted="notStarted",e.inProgress="inProgress",e.done="done",e))(es||{});class G1{constructor(t){P(this,"vizInstance");P(this,"operationManager");P(this,"triggerManager");P(this,"vizManager");P(this,"runningMigration");P(this,"panelModel");P(this,"status","notStarted");this.panelModel=t.getRequired(ue.instanceScope.panelModel),this.vizInstance=t.getRequired(ue.instanceScope.vizInstance),this.operationManager=t.getRequired(ue.instanceScope.operationManager),this.triggerManager=t.getRequired(ue.instanceScope.triggerManager),this.vizManager=t.getRequired(ue.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 Ul(e){const{panel:t}=xt();return g.useCallback(n=>{const r=n.getRequired(ue.vizManager),i=r.resolveComponent(e.viz.type);return n.createScoped().provideFactory(ue.instanceScope.vizInstance,()=>r.getOrCreateInstance(e)).provideFactory(ue.instanceScope.interactionManager,o=>{const l=o.getRequired(ue.instanceScope.vizInstance);return new zs(l,i,Sn)}).provideFactory(ue.instanceScope.operationManager,o=>o.getRequired(ue.instanceScope.interactionManager).operationManager).provideFactory(ue.instanceScope.triggerManager,o=>o.getRequired(ue.instanceScope.interactionManager).triggerManager).provideValue(ue.instanceScope.panelModel,t).provideFactory(ue.instanceScope.migrator,o=>new G1(o))},[e.viz.type,e.viz.conf])}function Kl(e){const[t,n]=g.useState(!1),r=il().getRequired(ue.instanceScope.migrator);return $.useAsyncEffect(async()=>{const i=r.status===es.notStarted;n(r.status===es.done),r.status===es.notStarted&&r.runMigration().then(o=>{o===Ql.migrated&&i&&(e==null||e())}).finally(()=>{n(!0)})},[r]),t}function Yl(e,t){const n=il().getRequired(ue.instanceScope.vizInstance);return g.useEffect(()=>(n.instanceData.setItem(null,t.viz.conf),n.instanceData.watchItem(null,r=>{e(r)})),[e,t.viz.type]),n}function W1({setVizConf:e,...t}){const{panel:n}=t,r=Yl(e,n),i=Kl(()=>{ut.showNotification({title:`${n.name} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})});return $.useAsyncEffect(async()=>{await r.instanceData.setItem(null,n.viz.conf)},[r,n.viz.type]),i?s.jsx(Ld,{...t}):s.jsx(a.Text,{children:"Checking update..."})}function R1(e){const{panel:t,setVizConf:n}=e;Yl(n,t);const{inEditMode:r}=g.useContext(wn);return Kl(()=>{r&&ut.showNotification({title:`${t.name} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?s.jsx(Pd,{...e}):s.jsx(a.Text,{children:"Checking update"})}const WI="";function Q1(e,t){const{vizManager:n}=g.useContext(Ze),{panel:{viz:r,title:i,id:o,name:l,description:c,queryIDs:u,variables:d}}=xt(),h={id:o,name:l,title:i,description:c,queryIDs:u,viz:r},p=Ul(h);try{return n.resolveComponent(r.type),s.jsx(Xn,{configure:p,children:s.jsx(R1,{setVizConf:r.setConf,panel:h,measure:t,data:e,variables:d,vizManager:n})})}catch(x){return console.info(y.get(x,"message")),null}}const Xl=S.observer(function({data:t}){const{ref:n,width:r,height:i}=re.useElementSize(),o=Q1(t,{w:r,h:i}),l=r>0&&i>0;return s.jsx("div",{className:"viz-root",ref:n,children:s.jsx(a.Box,{sx:{width:r,height:i,overflow:"hidden"},children:l&&s.jsx(je,{children:o})})})}),Jl=S.observer(({panel:e})=>s.jsxs(a.Stack,{children:[e.queryErrors.map((t,n)=>s.jsx(a.Text,{color:"red",size:"sm",align:"center",sx:{fontFamily:"monospace"},children:t},`${n}-${t}`)),s.jsx(a.Text,{color:"gray",align:"center",size:"sm",children:e.queryStateMessages})]})),si=S.observer(({panel:e})=>s.jsxs(a.Flex,{className:"panel-viz-section",direction:"column",sx:{position:"relative",width:"100%"},children:[s.jsx(a.LoadingOverlay,{visible:e.dataLoading,exitTransitionDuration:0}),!e.canRenderViz&&s.jsx(Jl,{panel:e}),e.canRenderViz&&s.jsx(Xl,{data:e.data})]})),U1={border:"1px solid #e9ecef"},Zl=S.observer(({panel:e,panelStyle:t,dropdownContent:n})=>{const{ref:r,downloadPanelScreenshot:i}=F1(e);return e.title.show,s.jsx(Ts,{value:{panel:e,data:e.data,loading:e.dataLoading,errors:e.queryErrors,downloadPanelScreenshot:i},children:s.jsxs(a.Box,{className:`panel-root ${e.title.show?"panel-root--show-title":""}`,ref:r,p:0,sx:{...U1,...t},children:[s.jsx(a.Box,{className:"panel-description-popover-wrapper",children:s.jsx(ni,{})}),n,s.jsx(N1,{}),s.jsx(si,{panel:e})]})})}),K1={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function Y1(e){return e.style.border.enabled?{}:K1}const Hl=S.observer(function({panel:t,view:n}){const r=Y1(t);return s.jsx(Zl,{panel:t,panelStyle:r,dropdownContent:s.jsx(V1,{view:n})})});function X1(e){return!["richText","button"].includes(e)}const J1=S.observer(({view:e})=>{const{panel:t,downloadPanelScreenshot:n}=xt(),{id:r}=t,{viewPanelInFullScreen:i,inFullScreen:o}=g.useContext(Jn),l=g.useCallback(()=>{i(r)},[r,i]),c=!o&&e.type!==L.Modal;return X1(t.viz.type)?s.jsx(a.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:s.jsxs(a.Menu,{withinPortal:!0,children:[s.jsx(a.Menu.Target,{children:s.jsx(a.Box,{className:"panel-dropdown-target"})}),s.jsxs(a.Menu.Dropdown,{children:[s.jsx(a.Menu.Item,{onClick:t.refreshData,icon:s.jsx(k.Refresh,{size:14}),children:"Refresh"}),s.jsx(a.Menu.Item,{onClick:t.downloadData,icon:s.jsx(k.Download,{size:14}),children:"Download Data"}),s.jsx(a.Menu.Item,{onClick:n,icon:s.jsx(_.IconCamera,{size:14}),children:"Screenshot"}),c&&s.jsx(a.Menu.Item,{onClick:l,icon:s.jsx(k.ArrowsMaximize,{size:14}),children:"Full Screen"})]})]})}):null});function Z1(e){return e.style.border.enabled?{}:{border:"1px dashed transparent"}}const ri=S.observer(({panel:e,view:t})=>{const n=Z1(e);return s.jsx(Zl,{panel:e,panelStyle:n,dropdownContent:s.jsx(J1,{view:t})})}),H1={modal:{display:"flex",flexDirection:"column",flexWrap:"nowrap"},body:{display:"flex",height:"calc(100vh - 88px)"}},ec=S.observer(function({view:t,panel:n,exitFullScreen:r}){return s.jsx(a.Modal,{opened:!0,fullScreen:!0,onClose:r,title:s.jsx(a.Button,{color:"blue",size:"xs",onClick:r,leftIcon:s.jsx(k.ArrowLeft,{size:20}),children:"Exit fullscreen"}),styles:H1,children:s.jsx(a.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:s.jsx(ri,{view:t,panel:n})})})});function tc(e,t,n){const{panels:r}=ce(),i=e.id==="Main",[o,l]=g.useState(()=>i&&r.findByID(t)?t:null),c=g.useCallback(p=>{l(p),i&&n(p)},[i,n]),u=g.useCallback(()=>{l(null),i&&n("")},[i,n]),d=o?r.findByID(o):null;return{viewPanelInFullScreen:c,exitFullScreen:u,inFullScreen:!!d,fullScreenPanel:d}}const RI="",e_=g.forwardRef(({h:e},t)=>s.jsx(a.ActionIcon,{ref:t,className:"react-grid-customDragHandle",sx:{userSelect:"none",cursor:"grab",position:"absolute",top:5,right:e>38?5:20,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",children:s.jsx(k.ArrowsMove,{size:16})})),t_=g.forwardRef(({handleAxis:e,...t},n)=>s.jsx(a.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:s.jsx(k.ChevronDownRight,{size:16})})),n_=fn.WidthProvider(fn.Responsive),s_=S.observer(({view:e,className:t="layout"})=>{const r=W().layouts,i=r.items(e.panelIDs),o=r.gridLayouts(e.panelIDs),l=(d,h,p,x)=>{console.log("🔴 onResize",d),p.h<30&&(p.h=30,x.h=30),p.w<4&&(p.w=4,x.w=4)},c=(d,h,p)=>{console.log("🔴 onResizeStop",{layouts:d,oldItem:h,newItem:p}),r.updateCurrentLayoutItem(p)},u=(d,h,p)=>{console.log("🔴 onDragStop",{layouts:d,oldItem:h,newItem:p}),r.updateCurrentLayoutItem(p)};return s.jsx(n_,{className:`dashboard-layout ${t}`,rowHeight:1,margin:[0,0],isBounded:!0,isDraggable:!0,isResizable:!0,cols:r.cols,layouts:o,draggableHandle:".react-grid-customDragHandle",resizeHandle:s.jsx(t_,{}),onResize:l,breakpoints:r.breakpoints,onBreakpointChange:r.setCurrentBreakpoint,onResizeStop:c,onDragStop:u,width:r.currentLayoutPreviewWidth,children:i.map(d=>s.jsxs("div",{"data-grid":d.layoutProperies,className:"panel-grid-item",children:[s.jsx(e_,{h:d.h}),s.jsx(Hl,{view:e,panel:d.panel})]},d.id))})}),r_=fn.WidthProvider(fn.Responsive),i_=S.observer(({view:e,className:t="layout"})=>{const n=ce(),r=n.layouts.items(e.panelIDs),i=n.layouts.gridLayouts(e.panelIDs);return s.jsx(r_,{className:`dashboard-layout ${t}`,rowHeight:1,margin:[0,0],isDraggable:!1,isResizable:!1,cols:n.layouts.cols,layouts:i,breakpoints:n.layouts.breakpoints,onBreakpointChange:n.layouts.setCurrentBreakpoint,children:r.map(o=>s.jsx("div",{"data-grid":o.layoutProperies,className:"panel-grid-item",children:s.jsx(ri,{view:e,panel:o.panel})},o.id))})});function ii(e){const t=g.useRef(null);return{ref:t,downloadScreenshot:()=>{var i;const r=(i=t.current)==null?void 0:i.querySelector(".react-grid-layout");r&&e.downloadScreenshot(r)}}}const a_=S.observer(({downloadScreenshot:e})=>{const[t,{setTrue:n,setFalse:r}]=$.useBoolean(!1),i=pa(),o=ce(),l=()=>{const c=JSON.stringify(o.contentJSON,null,2),u=`${i.name}__${o.name}`;Nt(u,c)};return s.jsxs(a.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:200,closeDelay:400,withinPortal:!0,position:"bottom-end",children:[s.jsx(a.Menu.Target,{children:s.jsx(a.Affix,{position:{bottom:"20px",right:"10px"},zIndex:1,children:s.jsx(a.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:s.jsx(_.IconShare3,{size:"1rem"})})})}),s.jsxs(a.Menu.Dropdown,{children:[s.jsx(a.Menu.Item,{icon:s.jsx(_.IconCamera,{size:14}),onClick:e,children:"Screenshot"}),s.jsx(a.Menu.Divider,{}),s.jsx(a.Menu.Item,{icon:s.jsx(_.IconDownload,{size:14}),onClick:o.queries.downloadAllData,children:"Download Data"}),s.jsx(a.Menu.Item,{icon:s.jsx(_.IconCode,{size:14}),onClick:l,children:"Download Schema"})]})]})}),nc=S.observer(({children:e,view:t,sx:n={}})=>{const{ref:r,downloadScreenshot:i}=ii(t);return s.jsxs(s.Fragment,{children:[s.jsx(a.Box,{ref:r,pt:10,pb:10,sx:n,children:e}),s.jsx(a_,{downloadScreenshot:i})]})}),sc=S.observer(({downloadScreenshot:e})=>s.jsx(a.ActionIcon,{className:"download-screenshot-button",color:"blue",onClick:e,children:s.jsx(_.IconCamera,{size:14})})),o_=S.observer(({children:e,view:t})=>{const n=ce(),r=t.config,i=n.views.visibleViewIDs.includes(t.id),o=()=>n.views.rmVisibleViewID(t.id),{ref:l,downloadScreenshot:c}=ii(t);return s.jsx(a.Modal,{size:r.width,centered:!0,opened:i,onClose:o,withCloseButton:!1,title:s.jsxs(a.Group,{position:"apart",px:"1rem",h:"48px",children:[s.jsx(a.Box,{children:r.custom_modal_title.value}),s.jsx(sc,{downloadScreenshot:c})]}),trapFocus:!0,onDragStart:u=>{u.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",paddingBottom:10},header:{padding:0},title:{flexGrow:1}},transitionProps:{duration:0},children:s.jsx(a.Box,{ref:l,children:e})})}),l_=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},c_=S.observer(({view:e})=>{const t=ce(),n=e.config;return s.jsxs(a.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"?"0px 0px 36px":"0",height:"100%",overflow:"auto"}},keepMounted:!1,children:[s.jsx(a.Tabs.List,{grow:n.grow,children:n.tabsInOrder.map(r=>s.jsx(a.Tabs.Tab,{value:r.id,sx:l_(r),disabled:!r.view_id,children:r.name??r.id},r.id))}),n.tabsInOrder.map(r=>{const i=t.views.findByID(r.view_id);return i?s.jsx(a.Tabs.Panel,{value:r.id,children:s.jsx(ts,{view:i})},r.id):null})]})}),u_=S.observer(({view:e,children:t})=>{switch(e.type){case L.Modal:return s.jsx(o_,{view:e,children:t});case L.Tabs:return s.jsx(c_,{view:e});case L.Division:default:return s.jsx(nc,{view:e,children:t})}}),d_=S.observer(({children:e,view:t})=>{const r=W().layouts,[i,o]=re.useResizeObserver();return g.useEffect(()=>{r.setCurrentLayoutWrapperWidth(o.width)},[o.width]),s.jsx(a.Box,{sx:{height:"100%"},ref:i,children:s.jsx(a.Box,{sx:{paddingBottom:"100px",background:"white",margin:"0 auto",width:r.currentLayoutPreviewWidth??"100%",transform:`scale(${r.divisionPreviewScale})`,transformOrigin:"0 0"},children:s.jsx(nc,{view:t,sx:{paddingTop:"0px !important",".dashboard-sticky-area > form":{paddingBottom:"5px"},".dashboard-layout":{marginTop:0,marginBottom:0}},children:e})})})});function rc(e){return e.replace(/(vw|vh)/,"%")}const p_=S.observer(({children:e,view:t})=>{const n=t.config,{width:r,height:i}=g.useMemo(()=>({width:rc(n.width),height:rc(n.height)}),[n.width,n.height]),{ref:o,downloadScreenshot:l}=ii(t);return s.jsx(a.Box,{sx:{height:"100%","> div:not(.mantine-Modal-root)":{height:"100%"}},children:s.jsx(a.Modal,{size:n.width,opened:!0,onClose:y.noop,withCloseButton:!1,title:s.jsxs(a.Group,{position:"apart",px:"1rem",h:"48px",children:[s.jsx(a.Box,{children:n.custom_modal_title.value}),s.jsx(sc,{downloadScreenshot:l})]}),trapFocus:!0,onDragStart:c=>{c.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:i,maxHeight:i},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:s.jsx(a.Box,{ref:o,children:e})})})}),h_=({variant:e,orientation:t})=>{const n={root:{height:"100%",overflow:"hidden"},tabsList:{backgroundColor:"white"},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},x_=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},f_=S.observer(({view:e})=>{const t=ze.useModals(),n=W(),r=g.useMemo(()=>n.views.options.filter(c=>c.type===L.Division),[e.id,n.views.options]),i=e.config,o=c=>t.openConfirmModal({title:"Delete this tab?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.removeTab(c)},confirmProps:{color:"red"},zIndex:320}),l=i.tabs.length===0;return s.jsxs(a.Tabs,{className:"preview-view-tabs",variant:i.variant,orientation:i.orientation,value:e.tab,onTabChange:e.setTab,styles:h_(i),children:[s.jsxs(a.Tabs.List,{grow:i.grow,children:[i.tabsInOrder.map(c=>s.jsx(a.Tabs.Tab,{value:c.id,sx:x_(c),children:c.name??c.id},c.id)),s.jsx(a.Tabs.Tab,{onClick:i.addTab,value:"add",className:"add-a-tab",children:s.jsx(k.Plus,{size:18,color:"#228be6"})})]}),i.tabsInOrder.map((c,u)=>{const d=n.views.findByID(c.view_id);return s.jsxs(a.Tabs.Panel,{value:c.id,sx:{position:"relative"},children:[s.jsxs(a.Box,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:200},children:[s.jsx(a.Overlay,{opacity:.8,color:"#FFF",blur:10,zIndex:100}),s.jsxs(a.Stack,{mx:"auto",mt:100,sx:{width:"300px",position:"relative",zIndex:200},children:[s.jsx(a.TextInput,{label:"Tab Name",required:!0,value:c.name,onChange:h=>c.setName(h.currentTarget.value)}),s.jsx(a.Select,{label:"View",value:c.view_id,onChange:c.setViewID,data:r}),s.jsx(a.NumberInput,{label:"Placement Order",required:!0,value:c.order,onChange:h=>c.setOrder(h||0),min:0,max:1e3,step:1}),s.jsx(a.ColorInput,{label:"Color",value:c.color,onChange:c.setColor,disabled:i.variant!=="default"}),d&&s.jsxs(a.Button,{mt:20,variant:"gradient",leftIcon:s.jsx(_.IconArrowsLeftRight,{size:18}),gradient:{from:"cyan",to:"indigo"},onClick:()=>n.views.setIDOfVIE(d.id),children:["Swith to View: ",d.name]}),s.jsx(a.Button,{mt:20,variant:"subtle",color:"red",onClick:()=>o(u),disabled:l,leftIcon:s.jsx(_.IconTrash,{size:14}),children:"Delete This Tab"})]})]}),d&&s.jsx(ts,{view:d})]},c.id)})]})}),g_=S.observer(({view:e,children:t})=>{switch(e.type){case L.Modal:return s.jsx(p_,{view:e,children:t});case L.Tabs:return s.jsx(f_,{view:e});case L.Division:default:return s.jsx(d_,{view:e,children:t})}}),ic=S.observer(function({view:t}){const r=W().layouts.divisionPreviewScale!==1;return s.jsx(Jn.Provider,{value:{viewPanelInFullScreen:y.noop,inFullScreen:!1},children:s.jsx(a.Box,{className:"dashboard-view","data-enable-scrollbar":!0,sx:{background:r?"transparent":"#efefef"},children:s.jsx(g_,{view:t,children:s.jsxs(a.Box,{sx:{position:"relative"},children:[s.jsx(a.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:s.jsx(ul,{view:t})}),s.jsx(s_,{view:t})]})})})})}),ts=S.observer(function({view:t}){const{fullScreenPanelID:n,setFullScreenPanelID:r}=ba(),{viewPanelInFullScreen:i,exitFullScreen:o,inFullScreen:l,fullScreenPanel:c}=tc(t,n,r);return s.jsx(Jn.Provider,{value:{viewPanelInFullScreen:i,inFullScreen:l},children:s.jsxs(a.Box,{className:"dashboard-view","data-enable-scrollbar":!0,sx:{height:t.type===L.Modal?"0 !important":"100%"},children:[l&&s.jsx(ec,{view:t,panel:c,exitFullScreen:o}),s.jsx(u_,{view:t,children:s.jsxs(a.Box,{sx:{position:"relative"},children:[!l&&s.jsx(a.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:s.jsx(ul,{view:t})}),!l&&s.jsx(i_,{view:t})]})})]})})});var ac=(e=>(e.Use="use",e.Edit="edit",e))(ac||{});const m_={[L.Division]:"Division",[L.Tabs]:"Tabs",[L.Modal]:"Modal"},oc={[L.Division]:"rgba(255, 0, 0, 0.2)",[L.Modal]:"rgba(0, 0, 0, 0.2)",[L.Tabs]:"rgba(255, 200, 100, 0.4)"},y_={[L.Division]:"#ff4000",[L.Modal]:"#000",[L.Tabs]:"#ffad18"};function b_(e,t,n){f.addDisposer(e,f.addMiddleware(e,(r,i)=>{i(r,()=>{f.getType(r.context)===t&&r.type==="action"&&n(r.name,r.context)})}))}const lc=f.types.compose("FiltersModel",Xr,f.types.model("FiltersModel",{previewValues:f.types.optional(f.types.frozen(),{})})).views(e=>({get idSet(){return new Set(e.current.map(t=>t.id))},get keySet(){return new Set(e.current.map(t=>t.key))},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===de.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}))},get sortedList(){return y.sortBy(e.current,t=>t.label.toLowerCase())}})).actions(e=>({replace(t){e.current=f.cast(t)},append(t){e.current.push(t)},appendMultiple(t){if(t.length===0)return;const n=t.filter(r=>!e.idSet.has(r.id));e.current.push(...n)},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(){b_(e.current,Vr,(n,r)=>{if(n==="setType"){const i=Ol(r.config.default_value,r.config);e.setValueByKey(r.key,i),e.updatePreviewValues({...e.previewValues,[r.key]:i})}})}return{afterCreate(){t()}}}),cc=Zr.views(e=>({get canPreviewData(){return e.isTransform?e.dep_query_ids.length>0&&!!e.pre_process:!!e.datasource},get guideToPreviewData(){return e.isTransform?"Need to complete settings in Transform tab":"Need to pick a Data Source first"}})),uc=f.types.compose("QueriesModel",Hr,f.types.model({current:f.types.optional(f.types.array(cc),[])})).views(e=>({get options(){const t=e.current.map(n=>({value:n.id,label:n.name,_type:"query"}));return y.sortBy(t,n=>n.label.toLowerCase())},get optionsWithoutTransform(){const t=e.current.filter(n=>n.type!==oe.Transform).map(n=>({value:n.id,label:n.name,_type:"query"}));return y.sortBy(t,n=>n.label.toLowerCase())},get sortedList(){return y.sortBy(e.current,t=>t.name.toLowerCase())}})).actions(e=>({replace(t){e.current=f.cast(t)},append(t){e.current.push(t)},appendMultiple(t){if(t.length===0)return;const n=t.filter(r=>!e.idSet.has(r.id));e.current.push(...n)},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&&(f.detach(n),e.current.remove(n))},removeQueries(t){const n=new Set(t);e.current.forEach(i=>{n.has(i.id)&&f.detach(i)});const r=[...e.current];y.remove(r,i=>n.has(i.id)),e.current=f.cast(r)}})),dc=ti.views(e=>({get sortedList(){return y.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 y.sortBy(t,n=>n.label.toLowerCase())}})).actions(e=>({replace(t){e.current=f.cast(t)},append(t){e.current.push(t)},appendMultiple(t){if(t.length===0)return;const n=t.filter(r=>!e.keySet.has(r.key));e.current.push(...n)},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(i=>{n.has(i.key)&&f.detach(i)});const r=[...e.current];y.remove(r,i=>n.has(i.key)),e.current=f.cast(r)},replaceByIndex(t,n){e.current.splice(t,1,n)}})),j_=f.types.model({data:f.types.optional(f.types.frozen(),[]),state:f.types.optional(f.types.enumeration(["idle","loading","error"]),"idle"),error:f.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0}})),v_=f.types.model({data:f.types.optional(f.types.frozen(),[]),state:f.types.optional(f.types.enumeration(["idle","loading","error"]),"idle"),error:f.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0}})),w_=f.types.model({page:f.types.optional(f.types.number,1),limit:f.types.optional(f.types.number,20),data:f.types.optional(f.types.frozen(),[]),total:f.types.optional(f.types.number,0),state:f.types.optional(f.types.enumeration(["idle","loading","error"]),"idle"),error:f.types.frozen()}).views(e=>({get keywords(){return f.getParent(e,1)},get keywordString(){const{table_name:t,table_schema:n}=f.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`
451
451
  SELECT count(*) AS total
452
452
  FROM ${n}.${t}
453
- `}})).actions(e=>({setPage(t){e.page=t},resetPage(){e.page=1},setLimit(t){e.limit=t}})).actions(e=>({afterCreate(){f.addDisposer(e,K.reaction(()=>e.keywordString,e.resetPage,{fireImmediately:!1,delay:0})),f.addDisposer(e,K.reaction(()=>e.limit,e.resetPage,{fireImmediately:!1,delay:0}))}})),w_=f.types.model({data:f.types.optional(f.types.frozen(),{}),state:f.types.optional(f.types.enumeration(["idle","loading","error"]),"idle"),error:f.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return Object.keys(e.data).length===0}})),C_=f.types.compose("DataSourceModel",Wr,f.types.model({tables:f.types.optional(w_,{}),columns:f.types.optional(b_,{}),tableData:f.types.optional(v_,{}),indexes:f.types.optional(j_,{}),table_schema:f.types.optional(f.types.string,""),table_name:f.types.optional(f.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=f.flow(function*(){var n;(n=e.controllers.tables)==null||n.abort(),e.controllers.tables=new AbortController,e.tables.state="loading";try{const r=yield*f.toGenerator(Je.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=y.groupBy(r,"table_schema"),e.tables.state="idle",e.tables.error=null,e.initKeywords()}catch(r){if(!nt.isCancel(r)){e.tables.data={};const i=y.get(r,"message","unkown error");e.tables.error=y.get(r,"response.data.detail.message",i),e.tables.state="error"}}});return{loadTables:t,loadTablesIfEmpty(){e.tables.empty&&t()},loadColumns:f.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*f.toGenerator(Je.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(nt.isCancel(r))e.columns.state="idle",e.columns.error=null;else{e.columns.data=[];const i=y.get(r,"message","unkown error");e.columns.error=y.get(r,"response.data.detail.message",i),e.columns.state="error"}}}),loadIndexes:f.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*f.toGenerator(Je.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(nt.isCancel(r))e.indexes.state="idle",e.indexes.error=null;else{e.indexes.data=[];const i=y.get(r,"message","unkown error");e.indexes.error=y.get(r,"response.data.detail.message",i),e.indexes.state="error"}}}),loadTableData:f.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*f.toGenerator(Je.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:i}]=yield*f.toGenerator(Je.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(i),n.state="idle",n.error=null}catch(i){if(nt.isCancel(i))n.state="idle",n.error=null;else{n.data=[];const o=y.get(i,"message","unkown error");n.error=y.get(i,"response.data.detail.message",o),n.state="error"}}})}}).actions(e=>({afterCreate(){f.addDisposer(e,K.reaction(()=>e.reloadConditionString,e.loadColumns,{fireImmediately:!1,delay:500}))}})).actions(e=>({afterCreate(){f.addDisposer(e,K.reaction(()=>e.reloadConditionString,e.loadIndexes,{fireImmediately:!1,delay:500})),f.addDisposer(e,K.reaction(()=>`${e.reloadConditionString};limit:${e.tableData.limit};offset:${e.tableData.offset}`,e.loadTableData,{fireImmediately:!1,delay:0}))}})),S_=f.types.model("DataSourcesModel",{list:f.types.optional(f.types.array(C_),[])}).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 Tt(e){return{label:e,value:e,_type:"ACTION",_action_type:e,Icon:null,children:null}}function __(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 k_=f.types.model("EditorModel",{path:f.types.optional(f.types.frozen(),[]),settings_open:f.types.optional(f.types.boolean,!1)}).views(e=>({get navOptions(){const{content:t}=f.getRoot(e),{filters:n,views:r,sqlSnippets:i,queries:o}=t;return[{label:"Query Variables",value:"_QUERY_VARS_",_type:"query_variables",Icon:_.IconVariable},{label:"Mock Context",value:"_MOCK_CONTEXT_",Icon:_.IconCodeDots,_type:"mock_context"},{label:"Filters",value:"_FILTERS_",Icon:_.IconFilter,children:[Tt("_FILTERS_SETTINGS_"),...n.options,Tt("_Add_A_Filter_")],_type:"GROUP"},{label:"SQL Snippets",value:"_SQL_SNIPPETS_",Icon:_.IconCopy,children:[Tt("_SQL_SNIPPETS_SETTINGS_"),...i.options,Tt("_Add_A_SQL_SNIPPET_")],_type:"GROUP"},{label:"Queries",value:"_QUERIES_",Icon:_.IconDatabase,children:[Tt("_QUERIES_SETTINGS_"),...o.options,Tt("_Add_A_QUERY_")],_type:"GROUP"},{label:"Views",value:"_VIEWS_",Icon:_.IconBoxMultiple,children:[...r.editorOptions,Tt("_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=__(t);n&&e.setPath(n)}})),T_=f.types.compose("LayoutsModel",ti,f.types.model({currentLayoutWrapperWidth:f.types.optional(f.types.number,0)})).views(e=>({get divisionPreviewScale(){const t=e.currentLayoutPreviewWidth,n=e.currentLayoutWrapperWidth;return!t||!n||t<=n?1:n/t}})).actions(e=>({addALayoutItem(t){e.list.forEach(n=>{n.addNewLayout(t)})},duplicateLayoutItemsByPanelID(t,n){e.list.forEach(r=>{const i=r.findByPanelID(t);if(!i){console.error(`Can't find a layout item by panelID[${t}] in layoutSet[${r.name}]`);return}r.list.push({...i,id:ht.v4(),panelID:n,y:1/0})})},removeByPanelID(t){e.list.forEach(n=>{n.removeByPanelID(t)})},setCurrentLayoutWrapperWidth(t){e.currentLayoutWrapperWidth=t},addALayoutSet(t,n,r){const i=e.basisLayoutSet,o={id:t,name:n,breakpoint:r,list:i.json.list.map(l=>({...l,id:ht.v4()}))};e.list.push(o)},updateLayoutSetsInfo(t){const n=y.keyBy(e.list,"id");t.forEach(o=>{const l=n[o.id];if(l){l.setName(o.name),l.setBreakpoint(o.breakpoint),delete n[o.id];return}this.addALayoutSet(o.id,o.name,o.breakpoint)});const r=new Set(Object.keys(n)),i=r.size>0;r.forEach(o=>{const l=e.list.findIndex(u=>u.id===o);e.list.splice(l,1)}),i&&e.setCurrentBreakpoint("basis")},updateCurrentLayoutItem(t){e.currentLayoutSet.updateLayoutItem(t)},append(t){e.list.push(t)},appendMultiple(t){t.length!==0&&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)})}})),du=Yr.views(e=>({get realDataFieldOptions(){return e.queryIDs.length===0?[]:e.queries.map(t=>{const n=t.data;return n.length===0?[]:Object.keys(n[0]).map(i=>({label:i,value:`${t.id}.${i}`,group:t.name,disabled:!1}))}).flat()},dataFieldOptions(t,n){const r=[...this.realDataFieldOptions];if(t&&!r.find(i=>i.value===t)){const i=z(t),o=e.queryByID(i.queryID);r.unshift({label:i.columnKey,value:t,group:o?o.name:i.queryID,disabled:!0})}return n&&r.unshift({label:"unset",value:"",group:"",disabled:!1}),r},explainDataKey(t){const{queryID:n,columnKey:r}=z(t),i=e.queries.find(o=>o.id===n);return i?{queryID:n,queryName:i.name,columnKey:r}:{queryID:n,queryName:null,columnKey:r}}})).actions(e=>({removeSelf(){f.getParent(e,2).removeByID(e.id)}})).actions(e=>({moveToView(t,n){f.getRoot(e).content.views.findByID(t).removePanelID(e.id),f.getRoot(e).content.views.findByID(n).appendPanelID(e.id),f.getRoot(e).editor.setPath(["_VIEWS_",n,"_PANELS_",e.id])}})),pu=f.types.compose("PanelsModel",Xr,f.types.model({list:f.types.optional(f.types.array(du),[])})).views(e=>({get contentModel(){return f.getRoot(e).content},editorOptions(t,n){const r=e.panelsByIDs(n);r.length!==n.length&&console.warn(`Unfulfilled panels for View[${t}]`);const i=r.map(l=>({label:l.name,value:l.id,_type:"panel",parentID:t})),o="_Add_A_PANEL_";return i.push({label:o,value:o,_type:"ACTION",_action_type:o,parentID:t,Icon:null,children:null}),i}})).actions(e=>({replace(t){e.list=f.castToSnapshot(t)},append(t){e.list.push(t)},appendMultiple(t){t.length!==0&&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(i=>i.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,title:{...n.json.title}}),e.contentModel.layouts.duplicateLayoutItemsByPanelID(n.id,r),r},replaceByIndex(t,n){e.list.splice(t,1,n)}})),D_=Ur.actions(e=>({getSchema(){const t=e.json,n=[],r=[];e.panels.forEach(l=>{const u=l.getSchema();n.push(u.panel),u.queries.length>0&&r.push(...u.queries)});const i=e.contentModel.layouts.jsonByPanelIDSet(new Set(e.panelIDs));return{views:[t],panels:n,definition:{queries:y.uniqBy(r,l=>l.id)},layouts:i,version:lt}},downloadSchema(){if(e.type===P.Tabs){console.error(new Error("Please choose a tab first"));return}const t=JSON.stringify(this.getSchema(),null,2),n=e.name;Ft(n,t)}})),hu=f.types.compose("ViewsModel",Kr,f.types.model({current:f.types.optional(f.types.array(D_),[]),idOfVIE:f.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=f.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,i){e.current.push({id:t,name:n,type:r,config:i,panelIDs:[]})},append(t){e.current.push(t)},appendMultiple(t){t.length!==0&&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];f.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,P.Division,P.Division,{_name:P.Division}),this.setIDOfVIE(t)},removeVIE(){e.current.length!==1&&(this.removeByID(e.idOfVIE),this.setIDOfVIE(e.current[0].id))}}));function oi(e){const t=e.length>0?[e[0].id]:[],n=e.length>0?e[0].id:"";return{current:e.map(i=>{const{_name:o=i.type}=i.config;return{...i,config:{...i.config,_name:o},panelIDs:i.panelIDs}}),visibleViewIDs:t,idOfVIE:n}}const I_=f.types.model({id:f.types.string,name:f.types.string,dashboard_id:f.types.string,create_time:f.types.string,update_time:f.types.string,version:f.types.string,filters:ou,queries:uu,sqlSnippets:cu,views:hu,panels:pu,layouts:T_,mock_context:Mr,origin:f.types.maybe(f.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,layouts:e.layouts.json,definition:{queries:e.queries.json,sqlSnippets:e.sqlSnippets.json,mock_context:e.mock_context.current}}}},get contentJSON(){return this.json.content},get filtersChanged(){const t="filters.current";return!y.isEqual(f.getSnapshot(y.get(e,t)),y.get(e.origin,t))},get queriesChanged(){const t="queries.current",n=f.getSnapshot(y.get(e,t)).map(r=>y.pick(r,["id","name","key","type","sql","run_by","react_to","pre_process","post_process","dep_query_ids"]));return!y.isEqual(n,y.get(e.origin,t))},get sqlSnippetsChanged(){const t="sqlSnippets.current";return!y.isEqual(f.getSnapshot(y.get(e,t)),y.get(e.origin,t))},get viewsChanged(){const t="views.current";return!y.isEqual(e.views.json,y.get(e.origin,t))},get panelsChanged(){const t="panels.list";return!y.isEqual(f.getSnapshot(y.get(e,t)),y.get(e.origin,t))},get layoutsChanged(){const t="layouts.list";return!y.isEqual(f.getSnapshot(y.get(e,t)),y.get(e.origin,t))},get mockContextChanged(){const t="mock_context.current";return!y.isEqual(y.get(e,t),y.get(e.origin,t))},get context(){const t=f.getParent(e).context.current;return{...e.mock_context.current,...t}},get payloadForSQL(){const t=f.getParent(e).globalSQLSnippets,n={context:this.context,filters:e.filters.values};return{...n,sql_snippets:un(e.sqlSnippets.current,"key","value",n),global_sql_snippets:un(t.list,"id","content",n)}},get payloadForViz(){const t=f.getParent(e).context.current;return{context:{...e.mock_context.current,...t},filters:e.filters.values}},get dashboardState(){return js(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.layoutsChanged||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(i=>{i.panelIDs.forEach(o=>{const l=t.get(o);if(!l)return;const u="panel",c=l.name,d=[{id:i.id,label:i.name}];l.queryIDs.forEach(h=>{n.push({id:o,queryID:h,type:u,label:c,views:d})})})});const r=e.views.idMap;return e.filters.current.filter(i=>!!y.get(i,"config.options_query_id")).forEach(i=>{n.push({type:"filter",id:i.id,queryID:y.get(i,"config.options_query_id"),label:i.label,views:i.visibleInViewsIDs.map(o=>{var l;return{id:o,label:((l=r.get(o))==null?void 0:l.name)??o}})})}),y.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=[];return e.queries.current.forEach(n=>{if(!n.typedAsSQL)return;y.uniq(n.sql.match(vn.sqlSnippet)).forEach(i=>{t.push({queryID:n.id,sqlSnippetKey:i,queryName:n.name})})}),y.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 i;const r=e.panels.duplicateByID(t);r&&((i=e.views.findByID(n))==null||i.appendPanelID(r))},removePanelByID(t,n){var r;e.panels.removeByID(t),e.layouts.removeByPanelID(t),(r=e.views.findByID(n))==null||r.removePanelID(t)},addANewPanel(t){var r;const n=ht.v4();e.panels.append(Ll(n)),(r=e.views.findByID(t))==null||r.appendPanelID(n),e.layouts.addALayoutItem(n)},applyJSONSchema(t){var p;const{views:n,panels:r,filters:i,definition:o={},layouts:l}=t,{queries:u,sqlSnippets:c,mock_context:d}=o,h=new Map;if(Array.isArray(r)){const x=r.map(m=>{const j=ht.v4();return h.set(m.id,j),{...m,id:j}});if(e.panels.appendMultiple(x),!Array.isArray(n)||n.length===0){const m=x.map(j=>j.id);(p=e.views.VIE)==null||p.appendPanelIDs(m)}}if(Array.isArray(n)){const x=n.map(m=>{const j=m.panelIDs.map(C=>h.get(C)??C);return{...m,id:ht.v4(),panelIDs:j}});e.views.appendMultiple(x)}if(Array.isArray(l)){const x=(C,T)=>e.layouts.breakpointNameRecord[C]===T;let m=[];const j=l.filter(C=>x(C.name,C.breakpoint));j.forEach(C=>{C.id==="basis"&&(m=C.list),C.list.forEach(T=>{const D=h.get(T.panelID);T.id=ht.v4(),T.panelID=D})}),e.layouts.list.forEach(C=>{const T=j.find(D=>D.name===C.name&&D.breakpoint===C.breakpoint);if(!T){m.forEach(D=>{C.addLayout(D)});return}T.list.forEach(D=>{C.addLayout(D)})})}Array.isArray(i)&&e.filters.appendMultiple(i),Array.isArray(u)&&e.queries.appendMultiple(u),Array.isArray(c)&&e.sqlSnippets.appendMultiple(c),d&&Object.keys(d).length>0&&e.mock_context.defaults(d)}})).actions(e=>({reset(){f.applySnapshot(e.filters.current,e.origin.filters.current),f.applySnapshot(e.queries.current,e.origin.queries.current),f.applySnapshot(e.sqlSnippets.current,e.origin.sqlSnippets.current),f.applySnapshot(e.views.current,e.origin.views.current),f.applySnapshot(e.panels.list,e.origin.panels.list),f.applySnapshot(e.layouts.list,e.origin.layouts.list),e.mock_context.current=e.origin.mock_context.current},resetFilters(){f.applySnapshot(e.filters.current,e.origin.filters.current)},updateCurrent(t){const{id:n,name:r,content:i}=t;if(!i)throw new Error("unexpected null content when updating a content model");const{version:o,filters:l,views:u,panels:c,definition:{queries:d,sqlSnippets:h,mock_context:p={}}}=i;e.id=n,e.name=r,e.version=o,f.applySnapshot(e.filters.current,l),f.applySnapshot(e.views.current,oi(u).current),f.applySnapshot(e.panels.list,c),f.applySnapshot(e.queries.current,d),f.applySnapshot(e.sqlSnippets.current,h),e.mock_context.current=p}})),li=f.types.snapshotProcessor(I_,{preProcessor(e){return{...e,origin:e}},postProcessor(e){delete e.origin;const t=f.castToSnapshot(e.queries.current.map(n=>y.pick(n,["id","key","type","sql"])));return y.defaults({},{queries:{current:t}},e)}});function M_(e,t){t.filters&&f.applySnapshot(e.filters.current,t.filters)}function xu({id:e,name:t,dashboard_id:n,create_time:r,update_time:i,content:o},l,u){if(!o)throw new Error("unexpected null content when creating a content model");const{version:c,filters:d,views:h,panels:p,layouts:x,definition:{queries:m,sqlSnippets:j,mock_context:C={}}}=o;return li.create({id:e,name:t,dashboard_id:n,create_time:r,update_time:i,version:c,filters:Zr(d,l,C,u),queries:{current:m},sqlSnippets:{current:j},mock_context:zr(C),views:oi(h),panels:{list:p},layouts:{list:x,currentBreakpoint:x[0].id}})}const fu=f.types.model({id:f.types.identifier,name:f.types.string,group:f.types.string,content:li,content_id:f.types.string,datasources:S_,globalSQLSnippets:Rr,context:es,editor:k_}).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:i,group:o,content_id:l}=t;e.id=r,e.name=i,e.group=o,e.content_id=l,this.updateCurrentContent(n)}}));function gu({id:e,name:t,group:n,content_id:r},i,o,l,u,c){return fu.create({id:e,name:t,group:n,content_id:r,content:xu(i,u,c),datasources:{list:o},globalSQLSnippets:{list:l},context:Qr(u),editor:{}})}function mu(e,t){g.useEffect(()=>{const n=r=>{console.log(r);const{viewID:i}=r.detail;if(!i){console.error(new Error("[Open View] Needs to pick a view first"));return}e.views.appendToVisibles(i),t&&e.views.setIDOfVIE(i)};return window.addEventListener("open-view",n),()=>{window.removeEventListener("open-view",n)}},[e,t]),g.useEffect(()=>{const n=r=>{console.log(r);const{dictionary:i,payload:o}=r.detail;if(!o||Object.keys(o).length===0){console.error(new Error("[Set Filter Values] payload is empty"));return}Object.entries(i).forEach(([l,u])=>{e.filters.setValueByKey(l,y.get(o,u))})};return window.addEventListener("set-filter-values",n),()=>{window.removeEventListener("set-filter-values",n)}},[e]),g.useEffect(()=>{function n(i){return Array.isArray(i)?[]:typeof i=="object"?{}:typeof i=="boolean"?!1:typeof i=="string"?"":typeof i=="number"?0:i}const r=i=>{console.log(i);const{filter_keys:o}=i.detail;o.forEach(l=>{const u=y.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]),g.useEffect(()=>{const n=r=>{console.log(r);const{urlTemplate:i,openInNewTab:o,enableEncoding:l=!1,payload:u}=r.detail;if(!i){console.error(new Error("[Open Link] URL is empty"));return}function c(p){return y.cloneDeepWith(p,m=>{if(l&&typeof m=="string")return encodeURIComponent(m)})}const h=y.template(i||"")(c({...u,filters:e.payloadForSQL.filters,context:e.payloadForSQL.context}));window.open(h,o?"_blank":"_self","noopener")};return window.addEventListener("open-link",n),()=>{window.removeEventListener("open-link",n)}},[e])}function yu(e){return g.useCallback(t=>t.provideValue(he.pluginManager,e.pluginManager).provideValue(he.vizManager,e.vizManager).provideValue(he.colorManager,e.colorManager),[])}const RI="",z_=S.observer(({saveDashboardChanges:e})=>{const t=Le.useModals(),n=R(),r=()=>{t.openConfirmModal({title:s.jsxs(a.Group,{position:"left",children:[s.jsx(_.IconAlertTriangle,{size:18,color:"red"}),s.jsx(a.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})},i=n.changed;return s.jsxs(a.Group,{spacing:0,children:[s.jsx(a.Button,{color:"green",variant:"filled",size:"xs",leftIcon:s.jsx(_.IconDeviceFloppy,{size:18}),onClick:e,disabled:!i,sx:{borderTopRightRadius:0,borderBottomRightRadius:0},children:"Save Changes"}),s.jsxs(a.Menu,{width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:320,disabled:!i,children:[s.jsx(a.Menu.Target,{children:s.jsx(a.ActionIcon,{variant:"default",disabled:!i,sx:{height:"30px",borderTopLeftRadius:0,borderBottomLeftRadius:0,svg:{fill:"rgb(173, 181, 189)",stroke:"none"}},children:s.jsx(_.IconCaretDown,{size:18})})}),s.jsx(a.Menu.Dropdown,{children:s.jsx(a.Menu.Item,{icon:s.jsx(_.IconRecycle,{size:14,color:"red"}),disabled:!i,onClick:r,children:"Revert Changes"})})]})]})}),A_=S.observer(({saveDashboardChanges:e,onExit:t,headerSlot:n=null})=>{const r=Z(),i=r.content.changed,o=()=>{t({hasChanges:i,dashboardId:r.id})};return s.jsx(a.Header,{height:60,px:"md",py:0,sx:{zIndex:299},children:s.jsxs(a.Group,{position:"apart",sx:{height:60,minWidth:"1000px",position:"relative"},children:[s.jsxs(a.Group,{children:[s.jsx(a.Button,{size:"xs",color:i?"red":"green",leftIcon:s.jsx(_.IconArrowLeft,{size:20}),onClick:o,children:s.jsxs(a.Group,{spacing:4,children:["End Editing",s.jsx(a.Text,{td:"underline",children:r.name})]})}),s.jsx(z_,{saveDashboardChanges:e})]}),s.jsx(a.Group,{position:"right",sx:{flexGrow:1},children:n})]})})}),bu={height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},E_=S.observer(()=>{var r;const e=R(),t=((r=e.views.VIE)==null?void 0:r.type)===P.Tabs,n=()=>e.addANewPanel(e.views.idOfVIE);return t?s.jsx(a.Tooltip,{label:"Please choose a tab first",children:s.jsx(a.Button,{variant:"outline",color:"gray",radius:0,size:"xs",leftIcon:s.jsx(_.IconPlaylistAdd,{size:20}),sx:{...bu,transform:"none !important"},children:"Add a Panel"})}):s.jsx(a.Button,{variant:"outline",color:"blue",radius:0,size:"xs",onClick:n,leftIcon:s.jsx(_.IconPlaylistAdd,{size:20}),sx:{...bu,background:"rgb(231, 245, 255)"},children:"Add a Panel"})}),L_=S.observer(({done:e})=>{var X,Q;const n=R().layouts,r=g.useMemo(()=>({list:n.breakpointsInfo}),[n.breakpointsInfo]),{control:i,handleSubmit:o,watch:l,getValues:u,reset:c,formState:d}=b.useForm({defaultValues:r}),{fields:h,append:p,remove:x}=b.useFieldArray({control:i,name:"list",rules:{validate:G=>{if(console.log({values:G}),y.uniqBy(G,"breakpoint").length!==G.length)return"Screen sizes should be unique by min width"}}}),m=l("list"),j=h.map((G,ee)=>({...G,...m[ee]})),C=()=>{p({id:ht.v4(),name:"",breakpoint:""})},T=({list:G})=>{const ee=G.filter(ae=>Number.isFinite(ae.breakpoint));n.updateLayoutSetsInfo(ee),e()},D=u(),A=g.useMemo(()=>{const G={list:D.list.filter(ee=>!!ee.name&&Number.isFinite(ee.breakpoint))};return!y.isEqual(G,r)},[D,r]),F=(Q=(X=d.errors.list)==null?void 0:X.root)==null?void 0:Q.message;return s.jsx(s.Fragment,{children:s.jsxs("form",{onSubmit:o(T),children:[s.jsxs(a.Table,{fontSize:"sm",highlightOnHover:!0,withBorder:!0,sx:{tableLayout:"fixed"},children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"340px"},children:"Name"}),s.jsx("th",{style:{width:"160px"},children:"Min Width"}),s.jsx("th",{})]})}),s.jsxs("tbody",{children:[j.map((G,ee)=>s.jsxs("tr",{children:[s.jsx("th",{children:G.id==="basis"?G.name:s.jsx(b.Controller,{name:`list.${ee}.name`,control:i,render:({field:ae})=>s.jsx(a.TextInput,{size:"xs",label:"",required:!0,sx:{flex:1},...ae})})}),s.jsx("td",{children:G.id==="basis"?s.jsxs(a.Text,{ff:"monospace",children:[G.breakpoint,"px"]}):s.jsx(b.Controller,{name:`list.${ee}.breakpoint`,control:i,render:({field:ae})=>s.jsx(a.NumberInput,{size:"xs",label:"",required:!0,max:1e4,hideControls:!0,rightSection:s.jsx(a.Text,{color:"dimmed",children:"px"}),rightSectionProps:{style:{width:"30px"}},sx:{flex:1,fontFamily:"monospace"},styles:{input:{paddingRight:"30px"}},...ae})})}),s.jsx("td",{children:G.id!=="basis"&&s.jsx(a.ActionIcon,{mx:"auto",size:"xs",variant:"subtle",color:"red",onClick:()=>x(ee),children:s.jsx(_.IconTrash,{})})})]},G.id)),s.jsx("tr",{style:{backgroundColor:"transparent"},children:s.jsx("td",{colSpan:3,style:{padding:"0"},children:s.jsx(a.Tooltip,{label:"Add a screen size",children:s.jsx(a.ActionIcon,{variant:"subtle",size:"md",color:"blue",onClick:C,sx:{width:"100%"},children:s.jsx(_.IconPlus,{size:18})})})})})]})]}),s.jsx(a.Text,{mt:6,ta:"right",size:"xs",color:"red",children:F??" "}),s.jsxs(a.Group,{mt:6,position:"apart",children:[s.jsx(a.Button,{color:"orange",size:"xs",onClick:()=>c(),leftIcon:s.jsx(_.IconRecycle,{size:18}),disabled:!A,children:"Revert"}),s.jsx(a.Button,{color:"green",size:"xs",type:"submit",leftIcon:s.jsx(_.IconDeviceFloppy,{size:18}),disabled:!A,children:"Save changes"})]})]})})}),P_=S.observer(()=>{const[e,{open:t,close:n}]=oe.useDisclosure(!1),r=R(),i=r.layouts.currentBreakpoint,o=r.layouts.currentLayoutRange,l=()=>{setTimeout(()=>{window.dispatchEvent(new Event("resize"))},32)},u=()=>{n(),l()};return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{children:[s.jsxs(a.Menu,{withArrow:!0,withinPortal:!0,zIndex:320,trigger:"hover",children:[s.jsx(a.Menu.Target,{children:s.jsx(a.Button,{size:"xs",variant:"subtle",leftIcon:s.jsx(_.IconDevices,{size:16}),sx:{borderRadius:0},children:s.jsxs(a.Group,{spacing:6,children:[s.jsx(a.Text,{size:"xs",fw:"normal",children:o.name}),s.jsx(a.Text,{size:"xs",color:"#777",children:r.layouts.currentRangeText})]})})}),s.jsxs(a.Menu.Dropdown,{children:[r.layouts.breakpointRanges.map(c=>s.jsx(a.Menu.Item,{onClick:()=>r.layouts.setCurrentBreakpoint(c.id),disabled:i===c.id,children:s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Text,{size:"sm",children:c.name}),s.jsx(a.Text,{size:"xs",color:"dimmed",children:c.text})]})},c.id)),s.jsx(a.Menu.Divider,{}),s.jsx(a.Menu.Item,{color:"blue",icon:s.jsx(_.IconSettings,{size:14}),onClick:t,children:s.jsx(a.Text,{size:"sm",children:"Manage screen sizes"})})]})]}),r.layouts.divisionPreviewScale<1&&s.jsx(a.Text,{size:"xs",color:"dimmed",children:fn(r.layouts.divisionPreviewScale).format({output:"percent",mantissa:0})})]}),s.jsx(a.Modal,{opened:e,onClose:u,title:"Screen sizes",withinPortal:!0,zIndex:320,size:600,closeOnClickOutside:!1,children:s.jsx(L_,{done:u})})]})}),ju={height:"30px",borderRight:"none",borderTop:"none",borderLeft:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},B_=S.observer(()=>{var r;const e=R(),t=((r=e.views.VIE)==null?void 0:r.type)===P.Tabs,n=()=>{var i;return(i=e.views.VIE)==null?void 0:i.downloadSchema()};return t?s.jsx(a.Tooltip,{label:"Please choose a tab first",children:s.jsx(a.Button,{variant:"outline",color:"gray",radius:0,size:"xs",leftIcon:s.jsx(_.IconCode,{size:16}),sx:{...ju,transform:"none !important"},children:"Download this View"})}):s.jsx(a.Button,{variant:"outline",color:"blue",radius:0,size:"xs",onClick:n,leftIcon:s.jsx(_.IconCode,{size:16}),sx:{...ju},children:"Download this View"})}),O_=S.observer(({view:e})=>!e||e.type!==P.Division?null:s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mt:8,mb:0,label:"Division settings",labelPosition:"center"}),s.jsx(a.Text,{align:"center",size:"xs",color:"dimmed",children:"Under construction"})]})),$_=[{value:"default",label:"Default"},{value:"outline",label:"Outline"},{value:"pills",label:"Pills"}],V_=[{value:"horizontal",label:"Horizontal"},{value:"vertical",label:"Vertical"}],q_=S.observer(({view:e})=>{if(!e||e.type!==P.Tabs)return null;const t=e.config;return s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mt:8,mb:0,label:"Tabs settings",labelPosition:"center"}),s.jsx(a.Select,{label:"Variant",value:t.variant,onChange:t.setVariant,data:$_}),s.jsx(a.Select,{label:"Orientation",value:t.orientation,onChange:t.setOrientation,data:V_}),s.jsx(a.Switch,{label:"Grow Tabs",checked:t.grow,onChange:n=>t.setGrow(n.currentTarget.checked)})]})}),N_=({disabled:e,value:t,onChange:n})=>{const r=i=>{i&&n(i)};return s.jsxs(a.Box,{sx:{position:"relative"},children:[e&&s.jsx(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),s.jsx(ye,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},F_=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:i}]=V.useBoolean(),[o,l]=g.useState(e??Hn),u=x=>{l({...o,enabled:x})},c=()=>{i();const{enabled:x,func_content:m}=o,j={enabled:x,func_content:m};l(j),t(j)},d=()=>{i(),l(e)},h=x=>{l(m=>({...m,func_content:x}))},p=()=>{h(Hn.func_content)};return s.jsxs(s.Fragment,{children:[s.jsx(a.ActionIcon,{size:"lg",color:"blue",variant:"filled",mt:26,onClick:r,sx:{flexGrow:0},children:s.jsx(k.Settings,{size:14})}),s.jsx(a.Modal,{size:800,title:"Customize modal title",opened:n,onClose:i,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&s.jsxs(a.Stack,{children:[s.jsx(a.Checkbox,{mt:10,label:"Enabled",checked:o.enabled,onChange:x=>u(x.currentTarget.checked)}),s.jsx(N_,{value:o.func_content,onChange:h,disabled:!o.enabled}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:p,color:"red",leftIcon:s.jsx(k.Recycle,{size:20}),children:"Reset"}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:d,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:c,children:"OK"})]})]})]})})]})},G_=S.observer(({view:e})=>{if(!e||e.type!==P.Modal)return null;const t=e.config,n=t.custom_modal_title.value;return s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mt:8,label:"Modal settings",labelPosition:"center"}),s.jsxs(a.Flex,{gap:10,children:[s.jsx(a.TextInput,{label:"Modal Title",value:n,onChange:y.noop,disabled:!0,sx:{flexGrow:1}}),s.jsx(F_,{value:t.custom_modal_title,onChange:t.custom_modal_title.replace})]}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(a.TextInput,{label:"Width",value:t.width,onChange:r=>t.setWidth(r.currentTarget.value),placeholder:"600px / 50vw"}),s.jsx(a.TextInput,{label:"Height",value:t.height,onChange:r=>t.setHeight(r.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),W_=S.observer(({view:e})=>s.jsxs(s.Fragment,{children:[s.jsx(O_,{view:e}),s.jsx(G_,{view:e}),s.jsx(q_,{view:e})]})),ss={[P.Division]:"Division",[P.Modal]:"Modal",[P.Tabs]:"Tabs"},R_=[{label:ss[P.Division],value:P.Division},{label:ss[P.Modal],value:P.Modal},{label:ss[P.Tabs],value:P.Tabs}],Q_=S.observer(({view:e})=>e?s.jsxs(a.Stack,{sx:{position:"relative"},children:[s.jsx(a.TextInput,{label:"Name",value:e.name,onChange:t=>{e.setName(t.currentTarget.value)}}),s.jsx(a.Select,{label:"Type",withinPortal:!0,zIndex:320,value:e.type,onChange:e.setType,data:R_}),s.jsx(W_,{view:e})]}):null),rs=({headers:e,rows:t})=>s.jsxs(a.Table,{fontSize:"xs",highlightOnHover:!0,sx:{tableLayout:"fixed",fontFamily:"monospace"},children:[s.jsx("thead",{children:e}),s.jsx("tbody",{children:t})]}),U_=({content:e})=>{const t=e.views;return!Array.isArray(t)||t.length===0?null:s.jsxs(a.Box,{children:[s.jsx(a.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:"Views"}),s.jsx(rs,{headers:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"160px"},children:"ID"}),s.jsx("th",{children:"Name"}),s.jsx("th",{children:"Type"})]}),rows:t.map(n=>s.jsxs("tr",{children:[s.jsx("td",{children:n.id}),s.jsx("td",{children:n.name}),s.jsx("td",{children:ss[n.type]})]},n.id))})]})},K_=({content:e})=>{const t=e.filters;return!Array.isArray(t)||t.length===0?null:s.jsxs(a.Box,{children:[s.jsx(a.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:"Filters"}),s.jsx(rs,{headers:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"160px"},children:"ID"}),s.jsx("th",{children:"Key"}),s.jsx("th",{children:"Label"})]}),rows:t.map(n=>s.jsxs("tr",{children:[s.jsx("td",{children:n.id}),s.jsx("td",{children:n.key}),s.jsx("td",{children:n.label})]},n.id))})]})},Y_=({content:e})=>{const t=e.panels;return!Array.isArray(t)||t.length===0?null:s.jsxs(a.Box,{children:[s.jsx(a.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:"Panels"}),s.jsx(rs,{headers:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"160px"},children:"ID"}),s.jsx("th",{children:"Name"}),s.jsx("th",{children:"Visualization"})]}),rows:t.map(n=>s.jsxs("tr",{children:[s.jsx("td",{children:n.id}),s.jsx("td",{children:n.name}),s.jsx("td",{children:n.viz.type})]},n.id))})]})},X_=({content:e})=>{var n;const t=(n=e.definition)==null?void 0:n.queries;return!Array.isArray(t)||t.length===0?null:s.jsxs(a.Box,{children:[s.jsx(a.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:"Queries"}),s.jsx(rs,{headers:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"160px"},children:"ID"}),s.jsx("th",{children:"Name"}),s.jsx("th",{style:{width:"140px"},children:"Type"}),s.jsx("th",{style:{width:"260px"},children:"Data Source"})]}),rows:t.map(r=>s.jsxs("tr",{children:[s.jsx("td",{children:r.id}),s.jsx("td",{children:r.name}),s.jsx("td",{children:r.type}),s.jsx("td",{children:r.key})]},r.id))})]})},J_=({content:e})=>{var n;const t=(n=e.definition)==null?void 0:n.sqlSnippets;return!Array.isArray(t)||t.length===0?null:s.jsxs(a.Box,{children:[s.jsx(a.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:"SQL Snippets"}),s.jsx(a.List,{size:"sm",pl:10,ff:"monospace",icon:s.jsx(_.IconPointFilled,{size:10}),children:t.map(r=>s.jsx(a.List.Item,{children:r.key},r.key))})]})},Z_=({content:e})=>{var n;const t=Object.keys(((n=e.definition)==null?void 0:n.mock_context)??{});return t.length===0?null:s.jsxs(a.Box,{children:[s.jsx(a.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:"Mock Context"}),s.jsx(a.List,{size:"sm",pl:10,ff:"monospace",icon:s.jsx(_.IconPointFilled,{size:10}),children:t.map(r=>s.jsx(a.List.Item,{children:r},r))})]})},H_=({content:e})=>e?s.jsxs(a.Box,{children:[s.jsx(a.Divider,{mt:20,mb:10,variant:"dashed"}),s.jsx(a.Text,{ta:"left",c:"dimmed",children:"Preview"}),s.jsxs(a.Stack,{children:[s.jsx(U_,{content:e}),s.jsx(K_,{content:e}),s.jsx(Y_,{content:e}),s.jsx(X_,{content:e}),s.jsx(J_,{content:e}),s.jsx(Z_,{content:e})]})]}):null;function ek(e){if(e.target===null)throw new Error("FileReader failed with null result");if(typeof e.target.result!="string")throw new Error(`Unparsable file content of type: ${typeof e.target.result}`);let t=JSON.parse(e.target.result);if("content"in t&&(t=t.content),t.version!==lt)throw new Error("Schema version mismatch");return t}const tk=S.observer(({onSuccess:e,stretchModal:t,shrinkModal:n})=>{var T,D;const r=R(),{handleSubmit:i,formState:{errors:o},setValue:l,watch:u,setError:c,clearErrors:d}=b.useForm({defaultValues:{content:null}}),h=({content:A})=>{try{if(!A)throw new Error("please use a valid json file");r.applyJSONSchema(A),dt.showNotification({title:"Successful",message:"",color:"green"}),e()}catch(F){console.error(F),dt.showNotification({title:"Failed",message:F.message,color:"red"})}},[p,x]=g.useState(null);g.useEffect(()=>{if(!p)return;const A=new FileReader;A.readAsText(p,"UTF-8"),A.onload=F=>{try{const X=ek(F);l("content",X),d("content")}catch(X){console.error(X),c("content",{type:"custom",message:X.message})}},A.onabort=()=>console.log("🟨 abort"),A.onerror=()=>{A.error&&(console.error(A.error),c("content",{type:"custom",message:A.error.message}))}},[p]);const[m]=u(["content"]),j=!m,C=(T=o==null?void 0:o.content)==null?void 0:T.message;return g.useEffect(()=>{!m||C?n():t()},[m,C]),s.jsx(a.Box,{mx:"auto",sx:{position:"relative"},children:s.jsxs("form",{onSubmit:i(h),children:[s.jsx(a.FileInput,{label:"JSON File",required:!0,value:p,onChange:x,error:(D=o==null?void 0:o.content)==null?void 0:D.message,sx:{maxWidth:500}}),C?s.jsx(a.Table,{fontSize:12,mt:10,children:s.jsxs("tbody",{children:[s.jsxs("tr",{children:[s.jsx("th",{children:"Dashboard"}),s.jsx("td",{children:lt})]}),s.jsxs("tr",{children:[s.jsx("th",{children:"This file"}),s.jsx("td",{style:{color:"red"},children:m==null?void 0:m.version})]})]})}):s.jsxs(s.Fragment,{children:[s.jsx(H_,{content:m}),s.jsx(a.Group,{position:"right",my:"md",children:s.jsx(a.Button,{type:"submit",color:"green",disabled:j,children:"Confirm"})})]})]})})}),vu={height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},nk=S.observer(()=>{var c;const[e,{open:t,close:n}]=oe.useDisclosure(!1),[r,{setTrue:i,setFalse:o}]=V.useBoolean(!1),u=((c=Z().content.views.VIE)==null?void 0:c.type)===P.Tabs;return u?s.jsx(a.Tooltip,{label:"Please choose a tab first",children:s.jsx(a.Button,{variant:"outline",color:"gray",radius:0,size:"xs",leftIcon:s.jsx(_.IconFileImport,{size:16}),sx:{...vu,transform:"none !important"},children:"Import..."})}):s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"subtle",color:"blue",radius:0,size:"xs",disabled:u||e,onClick:t,leftIcon:s.jsx(_.IconFileImport,{size:16}),sx:{...vu},children:"Import..."}),s.jsx(a.Modal,{opened:e,onClose:n,title:"Import content with schema json",trapFocus:!0,onDragStart:d=>{d.stopPropagation()},withinPortal:!0,zIndex:320,size:r?"90vw":500,children:s.jsx(tk,{onSuccess:n,stretchModal:i,shrinkModal:o})})]})}),sk={position:"fixed",top:60,left:0,right:0,height:30,zIndex:299,borderBottom:"1px solid #e9ecef",background:"rgba(233,236,239, 0.15)"},rk=S.observer(()=>s.jsx(a.Box,{sx:sk,pl:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},children:s.jsxs(a.Group,{position:"apart",align:"center",sx:{height:"30px"},children:[s.jsxs(a.Group,{position:"left",spacing:0,children:[s.jsx(E_,{}),s.jsx(nk,{})]}),s.jsx(P_,{}),s.jsx(a.Group,{position:"right",spacing:0,children:s.jsx(B_,{})})]})})),ik=S.observer(e=>s.jsxs(s.Fragment,{children:[s.jsx(A_,{...e}),s.jsx(rk,{})]})),QI="";function ak(e,t,n){const r=[];return e.filter(i=>"__INTERACTIONS"in i.viz.conf).forEach((i,o)=>{const l=t[i.id];l.data.interactions=y.get(l,"data.interactions",[]);const{__INTERACTIONS:u,__OPERATIONS:c,__TRIGGERS:d}=i.viz.conf;Object.entries(c).forEach(([h,p])=>{const{schemaRef:x,data:m}=p,{config:j}=m;switch(x){case"builtin:op:open-link":let C=j.urlTemplate.substring(0,100);j.urlTemplate.length>=20&&(C+="..."),l.type="interaction",l.data.interactions.push({schemaRef:x,urlTemplate:j.urlTemplate,shortURLTemplate:C});return;case"builtin:op:open_view":r.push({id:`OPERATION--${h}`,source:i.id,target:j.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:x,filters:Object.keys(j.dictionary).map(T=>({key:T,label:n[T]}))});return;case"builtin:op:clear_filter_values":l.type="interaction",l.data.interactions.push({schemaRef:x,filters:j.filter_keys.map(T=>({key:T,label:n[T]}))});return;default:return}})}),r}function ok(e,t){const n=e.filters.keyLabelMap;return{edges:ak(e.panels.list,t,n),edgeNodes:[]}}function wu(e,t,n){return e*t+e*n}function lk(e,t,n){return e*t+(e-1)*n}const is=25,ui=40,Cu=25,ci=350,uk=150,ck=150,Su=150,_u=300,as=40,ku=25,dk=300;function pk(e,t){const n=y.keyBy(t,i=>i.id),r=[];return e.current.forEach((i,o)=>{i.panelIDs.forEach((l,u)=>{const c=wu(u,as,ku)+ui,d=n[l];if(!d){r.push({id:l,_node_type:"panel",parentNode:i.id,data:{label:`!: ${l}`},position:{x:is,y:c},sourcePosition:ve.Position.Right,targetPosition:ve.Position.Left,style:{width:_u,height:as}});return}const h=d.name;r.push({id:d.id,_node_type:"panel",parentNode:i.id,data:{label:h},position:{x:is,y:c},sourcePosition:ve.Position.Right,targetPosition:ve.Position.Left,style:{width:_u,height:as}})})}),r}const hk={[P.Division]:"Div",[P.Modal]:"Modal",[P.Tabs]:"Tabs"},xk=au;function fk(e){return e.current.map((n,r)=>{const i=lk(n.panelIDs.length,as,ku)+ui+Cu;let o=[];return n.type===P.Tabs&&(o=n.config.tabsInOrder.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:`${hk[n.type]}:${n.name}`},position:{x:0,y:0},sourcePosition:ve.Position.Right,targetPosition:ve.Position.Left,className:"light",style:{backgroundColor:xk[n.type],width:ci,height:i}}})}function gk(e){const t=y.keyBy(e,n=>n.id);e.forEach(n=>{n._node_type!=="view-root"||n._view_type!==P.Tabs||n._tab_view_ids.forEach(r=>{t[r].parentNode=n.id})})}function mk(e){const t=fk(e.views);gk(t);const n=pk(e.views,e.panels.list);return[...t,...n]}function yk({nodeMap:e,nodes:t,edges:n}){t.forEach(r=>{r._node_type!=="view-root"||r._view_type!==P.Tabs||(r.sourcePosition=ve.Position.Bottom,r.style.width=ci+is*2,r.style.height=Cu+r._tab_view_ids.reduce((i,o)=>{const l=e[o];l.position.y=i,l.position.x=is;const u=l.style.height;return i+u+20},ui))})}function bk({nodeMap:e,nodes:t,edges:n}){n.filter(r=>r.label==="Open View").forEach(r=>{const i=e[r.source],o=e[r.target];if(!i||!o||!i.parentNode)return;const l=e[i.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,i)=>r._node_type==="view-root"&&i._node_type==="view-root"?r._view_level-i._view_level:r._node_type!=="view-root"&&i._node_type!=="view-root"?0:r._node_type==="view-root"?-1:1)}function jk({nodeMap:e,nodes:t,edges:n}){const r={};n.forEach(i=>{if(i.label!=="Open View")return;const o=e[i.source],l=e[i.target];if(o&&l&&o.parentNode){const u=e[o.parentNode],c=u.position.x,d=Number(y.get(l,"style.height",0)),h=Number(u.style.width);l.position.x=c+h+dk,u._view_level===0&&l._sub_view_ids.length===0&&(o.sourcePosition=ve.Position.Left,l.targetPosition=ve.Position.Right,l.position.x*=-1);const x=l.position.x,m=y.get(r,x,0);l.position.y=m,r[x]=m+d+Su}})}function vk({nodeMap:e,nodes:t,edges:n}){const r=new Set,i=new Set;n.forEach(l=>{r.add(l.source),i.add(l.target)}),t.filter(l=>l._node_type!=="view-root"||l.id==="Main"||l.parentNode?!1:!r.has(l.id)&&!i.has(l.id)).forEach((l,u)=>{l.position.x=wu(u,ci,ck),l.position.y=0-uk-Su})}function wk({nodeMap:e,nodes:t,edges:n}){const r={nodeMap:e,nodes:t,edges:n};return vk(r),bk(r),yk(r),jk(r),{nodes:t,edges:n}}function Ck(e){const t=mk(e),n=y.keyBy(t,c=>c.id),{edges:r,edgeNodes:i}=ok(e,n),o=[...t,...i],l=y.keyBy(o,c=>c.id),u={edges:y.uniqBy(r,c=>c.id),nodes:o,nodeMap:l};return wk(u)}const UI="",di={"builtin:op:open-link":s.jsx(a.ThemeIcon,{color:"blue",size:20,radius:"xl",children:s.jsx(_.IconCircleDashed,{size:14})}),"builtin:op:set_filter_values":s.jsx(a.ThemeIcon,{color:"orange",size:20,radius:"xl",children:s.jsx(_.IconCircleDot,{size:14})}),"builtin:op:clear_filter_values":s.jsx(a.ThemeIcon,{color:"orange",size:20,radius:"xl",children:s.jsx(_.IconCircleOff,{size:14})})};function Sk(e){const t=[];return e.forEach(n=>{switch(n.schemaRef){case"builtin:op:open-link":t.push({key:n.urlTemplate,icon:di[n.schemaRef],text:s.jsxs(a.Group,{spacing:4,children:[s.jsx(a.Text,{children:"Open: "}),s.jsx(a.Text,{color:"dimmed",children:n.shortURLTemplate})]})});return;case"builtin:op:set_filter_values":n.filters.forEach(({key:r,label:i})=>{t.push({key:n.schemaRef+r,icon:di[n.schemaRef],text:s.jsx(a.Group,{spacing:4,children:s.jsxs(a.Text,{children:["Set Filter: ",i]})})})});return;case"builtin:op:clear_filter_values":n.filters.forEach(({key:r,label:i})=>{t.push({key:n.schemaRef+r,icon:di[n.schemaRef],text:s.jsx(a.Group,{spacing:4,children:s.jsxs(a.Text,{children:["Clear Filter: ",i]})})})});return}}),t}const _k=g.memo(({data:e,isConnectable:t,sourcePosition:n=ve.Position.Right,targetPosition:r=ve.Position.Left,...i})=>{const o=g.useMemo(()=>Sk(e.interactions),[e.interactions]);return s.jsxs(s.Fragment,{children:[s.jsx(ve.Handle,{type:"target",position:r,isConnectable:t}),s.jsx(a.Box,{sx:{position:"absolute",top:0,right:0},children:s.jsx(k.ChevronsUpRight,{size:12})}),s.jsxs(a.HoverCard,{shadow:"xl",withinPortal:!0,children:[s.jsx(a.HoverCard.Target,{children:s.jsx(a.Text,{children:e.label})}),s.jsx(a.HoverCard.Dropdown,{children:s.jsx(a.List,{spacing:"xs",size:"sm",center:!0,children:o.map(l=>s.jsx(a.List.Item,{icon:l.icon,children:l.text},l.key))})})]}),s.jsx(ve.Handle,{type:"source",position:n,isConnectable:t})]})}),KI="",kk={interaction:_k},Tk=S.observer(()=>{const e=pe(),{edges:t,nodes:n}=Ck(e);return s.jsxs(ve,{nodes:n,edges:t,onNodesChange:y.noop,onEdgesChange:y.noop,onConnect:y.noop,className:"interactions-viewer",fitView:!0,nodeTypes:kk,children:[s.jsx(ve.MiniMap,{}),s.jsx(ve.Controls,{}),s.jsx(ve.Background,{})]})}),Dk=S.observer(({opened:e,close:t})=>s.jsx(a.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:s.jsx(Tk,{})})),Ik={"> 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 Mk({onClick:e,name:t,active:n,openSettings:r}){return s.jsxs(a.Box,{sx:{position:"relative"},children:[s.jsx(a.UnstyledButton,{sx:i=>({display:"block",width:"100%",padding:i.spacing.xs,borderRadius:0,position:"relative",color:i.black,"&:hover":{backgroundColor:i.colors.gray[0]},backgroundColor:n?i.colors.gray[2]:"transparent"}),children:s.jsx(a.Group,{sx:{width:"calc(100% - 28px)"},onClick:e,children:s.jsx(a.Text,{size:"sm",children:t})})}),n&&s.jsx(a.Tooltip,{label:"Edit",position:"right",withinPortal:!0,children:s.jsx(a.ActionIcon,{onClick:r,variant:"light",color:"blue",sx:{position:"absolute",top:0,bottom:0,height:"100%",right:0,zIndex:0,borderRadius:0},children:s.jsx(_.IconAdjustments,{size:16})})})]})}const zk=S.observer(()=>{const e=Z(),t=R(),n=g.useCallback(i=>()=>t.views.setIDOfVIE(i),[t]),r=i=>{e.editor.open(["_VIEWS_",i])};return s.jsxs(a.Box,{sx:{position:"relative"},children:[t.views.options.map(i=>s.jsx(Mk,{active:t.views.idOfVIE===i.value,name:i.label,onClick:n(i.value),openSettings:()=>r(i.value)},i.value)),s.jsx(a.Divider,{variant:"dashed"}),s.jsx(a.Button,{variant:"subtle",rightIcon:s.jsx(_.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"})]})}),Ak=S.observer(()=>{const e=Z(),t=R(),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])},[i,o]=g.useState(!1),l=()=>o(!0),u=()=>o(!1);return s.jsxs(a.Navbar,{p:0,width:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},zIndex:299,children:[s.jsxs(a.Navbar.Section,{children:[s.jsxs(a.Group,{grow:!0,spacing:0,sx:{...Ik,button:{borderWidth:0,borderBottomWidth:1,borderColor:"#e9ecef"}},children:[s.jsx(a.Tooltip,{label:"Filters",withinPortal:!0,children:s.jsx(a.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:r,children:s.jsx(_.IconFilter,{size:18})})}),s.jsx(a.Tooltip,{label:"Queries",withinPortal:!0,children:s.jsx(a.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:n,children:s.jsx(_.IconDatabase,{size:18})})}),s.jsx(a.Tooltip,{label:"Interactions Viewer",withinPortal:!0,children:s.jsx(a.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:l,children:s.jsx(_.IconLink,{size:18})})})]}),s.jsx(Dk,{opened:i,close:u})]}),s.jsx(a.Navbar.Section,{py:5,sx:{borderBottom:"1px solid #eee"},children:s.jsx(a.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Views"})}),s.jsx(a.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:s.jsx(zk,{})}),s.jsx(a.Navbar.Section,{children:s.jsx(a.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:s.jsx(a.Button,{size:"xs",leftIcon:s.jsx(_.IconSettings,{size:20}),onClick:()=>e.editor.open([]),children:"Settings"})})})]})}),Ek=["function getDefaultValue(filter, utils, context) {",' return "";',"}"].join(`
454
- `),Gt=S.observer(({filter:e})=>s.jsx(po,{label:"",title:"Custom Default Value",triggerLabel:"Default by function",value:e.default_value_func,onChange:e.setDefaultValueFunc,defaultValue:Ek,triggerButtonProps:{size:"xs",color:"grape",sx:{flexGrow:0,alignSelf:"flex-start"},leftIcon:s.jsx(_.IconMathFunction,{size:16})},description:s.jsx(a.Alert,{title:"Tips",color:"gray",mb:16,children:s.jsxs(a.List,{size:13,type:"ordered",children:[s.jsx(a.List.Item,{children:"Function has the highest priority of getting filter's default value"}),s.jsx(a.List.Item,{children:"Leave this editor empty to disable this feature"})]})})})),Lk=S.observer(function({filter:t}){const n=t.config;return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Checkbox,{checked:n.default_value,onChange:r=>n.setDefaultValue(r.currentTarget.checked),label:"Default Checked"}),s.jsx(Gt,{filter:t})]}),s.jsx(dr,{label:"Description",value:n.description,onChange:n.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"}],Bk=S.observer(function({filter:t}){const n=t.config,r=g.useMemo(()=>Ir().map(({value:i,group:o})=>({label:i,value:i,group:o})),[]);return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{children:[s.jsx(a.Checkbox,{checked:n.required,onChange:i=>n.setRequired(i.currentTarget.checked),label:"Required"}),s.jsx(a.Checkbox,{checked:n.allowSingleDateInRange,onChange:i=>n.setAllowSingleDateInRange(i.currentTarget.checked),label:"Allow choosing 1 day"})]}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(a.Select,{data:Pk,label:"Display Format",value:n.inputFormat,onChange:n.setInputFormat}),s.jsx(a.NumberInput,{label:"Max Days",min:0,value:n.max_days,onChange:n.setMaxDays,hideControls:!0})]}),s.jsxs(a.Group,{children:[s.jsx(ol,{label:"Default Value",config:n,value:n.default_value,onChange:n.setDefaultValue,disabled:!!n.default_shortcut}),s.jsx(a.Select,{data:r,label:"Default by Shortcut",value:n.default_shortcut,onChange:n.setDefaultShortcut,placeholder:"Priors default value",clearable:!0,sx:{flexGrow:1},maxDropdownHeight:500})]}),s.jsx(Gt,{filter:t})]})}),pi=S.observer(({value:e,onChange:t})=>{const n=Z(),r=R(),i=g.useMemo(()=>r.queries.options,[r.queries.current]),o=i.length===0,l=u=>{n.editor.setPath(["_QUERIES_",u])};return s.jsx(a.Select,{label:s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Text,{children:"Use query data as options"}),e&&s.jsx(a.Button,{size:"xs",leftIcon:s.jsx(_.IconArrowCurveRight,{size:16}),variant:"subtle",color:"blue",onClick:()=>l(e),children:"Open this query"})]}),data:i,value:e,onChange:t,allowDeselect:!1,clearable:!0,sx:{flexGrow:1},disabled:o,error:o?"You need to add a query in Data Settings":void 0,styles:{label:{display:"block"}}})}),Ok=`
453
+ `}})).actions(e=>({setPage(t){e.page=t},resetPage(){e.page=1},setLimit(t){e.limit=t}})).actions(e=>({afterCreate(){f.addDisposer(e,U.reaction(()=>e.keywordString,e.resetPage,{fireImmediately:!1,delay:0})),f.addDisposer(e,U.reaction(()=>e.limit,e.resetPage,{fireImmediately:!1,delay:0}))}})),C_=f.types.model({data:f.types.optional(f.types.frozen(),{}),state:f.types.optional(f.types.enumeration(["idle","loading","error"]),"idle"),error:f.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return Object.keys(e.data).length===0}})),S_=f.types.compose("DataSourceModel",Gr,f.types.model({tables:f.types.optional(C_,{}),columns:f.types.optional(j_,{}),tableData:f.types.optional(w_,{}),indexes:f.types.optional(v_,{}),table_schema:f.types.optional(f.types.string,""),table_name:f.types.optional(f.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=f.flow(function*(){var n;(n=e.controllers.tables)==null||n.abort(),e.controllers.tables=new AbortController,e.tables.state="loading";try{const r=yield*f.toGenerator(Ke.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=y.groupBy(r,"table_schema"),e.tables.state="idle",e.tables.error=null,e.initKeywords()}catch(r){if(!He.isCancel(r)){e.tables.data={};const i=y.get(r,"message","unkown error");e.tables.error=y.get(r,"response.data.detail.message",i),e.tables.state="error"}}});return{loadTables:t,loadTablesIfEmpty(){e.tables.empty&&t()},loadColumns:f.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*f.toGenerator(Ke.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(He.isCancel(r))e.columns.state="idle",e.columns.error=null;else{e.columns.data=[];const i=y.get(r,"message","unkown error");e.columns.error=y.get(r,"response.data.detail.message",i),e.columns.state="error"}}}),loadIndexes:f.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*f.toGenerator(Ke.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(He.isCancel(r))e.indexes.state="idle",e.indexes.error=null;else{e.indexes.data=[];const i=y.get(r,"message","unkown error");e.indexes.error=y.get(r,"response.data.detail.message",i),e.indexes.state="error"}}}),loadTableData:f.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*f.toGenerator(Ke.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:i}]=yield*f.toGenerator(Ke.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(i),n.state="idle",n.error=null}catch(i){if(He.isCancel(i))n.state="idle",n.error=null;else{n.data=[];const o=y.get(i,"message","unkown error");n.error=y.get(i,"response.data.detail.message",o),n.state="error"}}})}}).actions(e=>({afterCreate(){f.addDisposer(e,U.reaction(()=>e.reloadConditionString,e.loadColumns,{fireImmediately:!1,delay:500}))}})).actions(e=>({afterCreate(){f.addDisposer(e,U.reaction(()=>e.reloadConditionString,e.loadIndexes,{fireImmediately:!1,delay:500})),f.addDisposer(e,U.reaction(()=>`${e.reloadConditionString};limit:${e.tableData.limit};offset:${e.tableData.offset}`,e.loadTableData,{fireImmediately:!1,delay:0}))}})),__=f.types.model("DataSourcesModel",{list:f.types.optional(f.types.array(S_),[])}).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 k_(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 T_=f.types.model("EditorModel",{path:f.types.optional(f.types.frozen(),[]),settings_open:f.types.optional(f.types.boolean,!1)}).views(e=>({get navOptions(){const{content:t}=f.getRoot(e),{filters:n,views:r,sqlSnippets:i,queries:o}=t;return[{label:"Query Variables",value:"_QUERY_VARS_",_type:"query_variables",Icon:_.IconVariable},{label:"Mock Context",value:"_MOCK_CONTEXT_",Icon:_.IconCodeDots,_type:"mock_context"},{label:"Filters",value:"_FILTERS_",Icon:_.IconFilter,children:[kt("_FILTERS_SETTINGS_"),...n.options,kt("_Add_A_Filter_")],_type:"GROUP"},{label:"SQL Snippets",value:"_SQL_SNIPPETS_",Icon:_.IconCopy,children:[kt("_SQL_SNIPPETS_SETTINGS_"),...i.options,kt("_Add_A_SQL_SNIPPET_")],_type:"GROUP"},{label:"Queries",value:"_QUERIES_",Icon:_.IconDatabase,children:[kt("_QUERIES_SETTINGS_"),...o.options,kt("_Add_A_QUERY_")],_type:"GROUP"},{label:"Views",value:"_VIEWS_",Icon:_.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=k_(t);n&&e.setPath(n)}})),D_=f.types.compose("LayoutsModel",ei,f.types.model({currentLayoutWrapperWidth:f.types.optional(f.types.number,0)})).views(e=>({get divisionPreviewScale(){const t=e.currentLayoutPreviewWidth,n=e.currentLayoutWrapperWidth;return!t||!n||t<=n?1:n/t}})).actions(e=>({addALayoutItem(t){e.list.forEach(n=>{n.addNewLayout(t)})},duplicateLayoutItemsByPanelID(t,n){e.list.forEach(r=>{const i=r.findByPanelID(t);if(!i){console.error(`Can't find a layout item by panelID[${t}] in layoutSet[${r.name}]`);return}r.list.push({...i,id:pt.v4(),panelID:n,y:1/0})})},removeByPanelID(t){e.list.forEach(n=>{n.removeByPanelID(t)})},setCurrentLayoutWrapperWidth(t){e.currentLayoutWrapperWidth=t},addALayoutSet(t,n,r){const i=e.basisLayoutSet,o={id:t,name:n,breakpoint:r,list:i.json.list.map(l=>({...l,id:pt.v4()}))};e.list.push(o)},updateLayoutSetsInfo(t){const n=y.keyBy(e.list,"id");t.forEach(o=>{const l=n[o.id];if(l){l.setName(o.name),l.setBreakpoint(o.breakpoint),delete n[o.id];return}this.addALayoutSet(o.id,o.name,o.breakpoint)});const r=new Set(Object.keys(n)),i=r.size>0;r.forEach(o=>{const l=e.list.findIndex(c=>c.id===o);e.list.splice(l,1)}),i&&e.setCurrentBreakpoint("basis")},updateCurrentLayoutItem(t){e.currentLayoutSet.updateLayoutItem(t)},append(t){e.list.push(t)},appendMultiple(t){t.length!==0&&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)})}})),pc=Kr.views(e=>({get realDataFieldOptions(){return e.queryIDs.length===0?[]:e.queries.map(t=>{const n=t.data;return n.length===0?[]:Object.keys(n[0]).map(i=>({label:i,value:`${t.id}.${i}`,group:t.name,disabled:!1}))}).flat()},dataFieldOptions(t,n){const r=[...this.realDataFieldOptions];if(t&&!r.find(i=>i.value===t)){const i=z(t),o=e.queryByID(i.queryID);r.unshift({label:i.columnKey,value:t,group:o?o.name:i.queryID,disabled:!0})}return n&&r.unshift({label:"unset",value:"",group:"",disabled:!1}),r},explainDataKey(t){const{queryID:n,columnKey:r}=z(t),i=e.queries.find(o=>o.id===n);return i?{queryID:n,queryName:i.name,columnKey:r}:{queryID:n,queryName:null,columnKey:r}}})).actions(e=>({removeSelf(){f.getParent(e,2).removeByID(e.id)}})).actions(e=>({moveToView(t,n){f.getRoot(e).content.views.findByID(t).removePanelID(e.id),f.getRoot(e).content.views.findByID(n).appendPanelID(e.id),f.getRoot(e).editor.setPath(["_VIEWS_",n,"_PANELS_",e.id])}})),hc=f.types.compose("PanelsModel",Yr,f.types.model({list:f.types.optional(f.types.array(pc),[])})).views(e=>({get contentModel(){return f.getRoot(e).content},editorOptions(t,n){const r=e.panelsByIDs(n);r.length!==n.length&&console.warn(`Unfulfilled panels for View[${t}]`);const i=r.map(l=>({label:l.name,value:l.id,_type:"panel",parentID:t})),o="_Add_A_PANEL_";return i.push({label:o,value:o,_type:"ACTION",_action_type:o,parentID:t,Icon:null,children:null}),i}})).actions(e=>({replace(t){e.list=f.castToSnapshot(t)},append(t){e.list.push(t)},appendMultiple(t){t.length!==0&&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(i=>i.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,title:{...n.json.title}}),e.contentModel.layouts.duplicateLayoutItemsByPanelID(n.id,r),r},replaceByIndex(t,n){e.list.splice(t,1,n)}})),I_=Qr.actions(e=>({getSchema(){const t=e.json,n=[],r=[];e.panels.forEach(l=>{const c=l.getSchema();n.push(c.panel),c.queries.length>0&&r.push(...c.queries)});const i=e.contentModel.layouts.jsonByPanelIDSet(new Set(e.panelIDs));return{views:[t],panels:n,definition:{queries:y.uniqBy(r,l=>l.id)},layouts:i,version:at}},downloadSchema(){if(e.type===L.Tabs){console.error(new Error("Please choose a tab first"));return}const t=JSON.stringify(this.getSchema(),null,2),n=e.name;Nt(n,t)}})),xc=f.types.compose("ViewsModel",Ur,f.types.model({current:f.types.optional(f.types.array(I_),[]),idOfVIE:f.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=f.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,i){e.current.push({id:t,name:n,type:r,config:i,panelIDs:[]})},append(t){e.current.push(t)},appendMultiple(t){t.length!==0&&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];f.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,L.Division,L.Division,{_name:L.Division}),this.setIDOfVIE(t)},removeVIE(){e.current.length!==1&&(this.removeByID(e.idOfVIE),this.setIDOfVIE(e.current[0].id))}}));function ai(e){const t=e.length>0?[e[0].id]:[],n=e.length>0?e[0].id:"";return{current:e.map(i=>{const{_name:o=i.type}=i.config;return{...i,config:{...i.config,_name:o},panelIDs:i.panelIDs}}),visibleViewIDs:t,idOfVIE:n}}const M_=f.types.model({id:f.types.string,name:f.types.string,dashboard_id:f.types.string,create_time:f.types.string,update_time:f.types.string,version:f.types.string,filters:lc,queries:uc,sqlSnippets:dc,views:xc,panels:hc,layouts:D_,mock_context:Ir,origin:f.types.maybe(f.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,layouts:e.layouts.json,definition:{queries:e.queries.json,sqlSnippets:e.sqlSnippets.json,mock_context:e.mock_context.current}}}},get contentJSON(){return this.json.content},get filtersChanged(){const t="filters.current";return!y.isEqual(f.getSnapshot(y.get(e,t)),y.get(e.origin,t))},get queriesChanged(){const t="queries.current",n=f.getSnapshot(y.get(e,t)).map(r=>y.pick(r,["id","name","key","type","sql","run_by","react_to","pre_process","post_process","dep_query_ids"]));return!y.isEqual(n,y.get(e.origin,t))},get sqlSnippetsChanged(){const t="sqlSnippets.current";return!y.isEqual(f.getSnapshot(y.get(e,t)),y.get(e.origin,t))},get viewsChanged(){const t="views.current";return!y.isEqual(e.views.json,y.get(e.origin,t))},get panelsChanged(){const t="panels.list";return!y.isEqual(f.getSnapshot(y.get(e,t)),y.get(e.origin,t))},get layoutsChanged(){const t="layouts.list";return!y.isEqual(f.getSnapshot(y.get(e,t)),y.get(e.origin,t))},get mockContextChanged(){const t="mock_context.current";return!y.isEqual(y.get(e,t),y.get(e.origin,t))},get context(){const t=f.getParent(e).context.current;return{...e.mock_context.current,...t}},get payloadForSQL(){const t=f.getParent(e).globalSQLSnippets,n={context:this.context,filters:e.filters.values};return{...n,sql_snippets:ln(e.sqlSnippets.current,"key","value",n),global_sql_snippets:ln(t.list,"id","content",n)}},get payloadForViz(){const t=f.getParent(e).context.current;return{context:{...e.mock_context.current,...t},filters:e.filters.values}},get dashboardState(){return bs(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.layoutsChanged||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(i=>{i.panelIDs.forEach(o=>{const l=t.get(o);if(!l)return;const c="panel",u=l.name,d=[{id:i.id,label:i.name}];l.queryIDs.forEach(h=>{n.push({id:o,queryID:h,type:c,label:u,views:d})})})});const r=e.views.idMap;return e.filters.current.filter(i=>!!y.get(i,"config.options_query_id")).forEach(i=>{n.push({type:"filter",id:i.id,queryID:y.get(i,"config.options_query_id"),label:i.label,views:i.visibleInViewsIDs.map(o=>{var l;return{id:o,label:((l=r.get(o))==null?void 0:l.name)??o}})})}),y.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=[];return e.queries.current.forEach(n=>{if(!n.typedAsSQL)return;y.uniq(n.sql.match(jn.sqlSnippet)).forEach(i=>{t.push({queryID:n.id,sqlSnippetKey:i,queryName:n.name})})}),y.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 i;const r=e.panels.duplicateByID(t);r&&((i=e.views.findByID(n))==null||i.appendPanelID(r))},removePanelByID(t,n){var r;e.panels.removeByID(t),e.layouts.removeByPanelID(t),(r=e.views.findByID(n))==null||r.removePanelID(t)},addANewPanel(t){var r;const n=pt.v4();e.panels.append(Ll(n)),(r=e.views.findByID(t))==null||r.appendPanelID(n),e.layouts.addALayoutItem(n)},applyJSONSchema(t){var p;const{views:n,panels:r,filters:i,definition:o={},layouts:l}=t,{queries:c,sqlSnippets:u,mock_context:d}=o,h=new Map;if(Array.isArray(r)){const x=r.map(m=>{const j=pt.v4();return h.set(m.id,j),{...m,id:j}});if(e.panels.appendMultiple(x),!Array.isArray(n)||n.length===0){const m=x.map(j=>j.id);(p=e.views.VIE)==null||p.appendPanelIDs(m)}}if(Array.isArray(n)){const x=n.map(m=>{const j=m.panelIDs.map(C=>h.get(C)??C);return{...m,id:pt.v4(),panelIDs:j}});e.views.appendMultiple(x)}if(Array.isArray(l)){const x=(C,T)=>e.layouts.breakpointNameRecord[C]===T;let m=[];const j=l.filter(C=>x(C.name,C.breakpoint));j.forEach(C=>{C.id==="basis"&&(m=C.list),C.list.forEach(T=>{const D=h.get(T.panelID);T.id=pt.v4(),T.panelID=D})}),e.layouts.list.forEach(C=>{const T=j.find(D=>D.name===C.name&&D.breakpoint===C.breakpoint);if(!T){m.forEach(D=>{C.addLayout(D)});return}T.list.forEach(D=>{C.addLayout(D)})})}Array.isArray(i)&&e.filters.appendMultiple(i),Array.isArray(c)&&e.queries.appendMultiple(c),Array.isArray(u)&&e.sqlSnippets.appendMultiple(u),d&&Object.keys(d).length>0&&e.mock_context.defaults(d)}})).actions(e=>({reset(){f.applySnapshot(e.filters.current,e.origin.filters.current),f.applySnapshot(e.queries.current,e.origin.queries.current),f.applySnapshot(e.sqlSnippets.current,e.origin.sqlSnippets.current),f.applySnapshot(e.views.current,e.origin.views.current),f.applySnapshot(e.panels.list,e.origin.panels.list),f.applySnapshot(e.layouts.list,e.origin.layouts.list),e.mock_context.current=e.origin.mock_context.current},resetFilters(){f.applySnapshot(e.filters.current,e.origin.filters.current)},updateCurrent(t){const{id:n,name:r,content:i}=t;if(!i)throw new Error("unexpected null content when updating a content model");const{version:o,filters:l,views:c,panels:u,definition:{queries:d,sqlSnippets:h,mock_context:p={}}}=i;e.id=n,e.name=r,e.version=o,f.applySnapshot(e.filters.current,l),f.applySnapshot(e.views.current,ai(c).current),f.applySnapshot(e.panels.list,u),f.applySnapshot(e.queries.current,d),f.applySnapshot(e.sqlSnippets.current,h),e.mock_context.current=p}})),oi=f.types.snapshotProcessor(M_,{preProcessor(e){return{...e,origin:e}},postProcessor(e){delete e.origin;const t=f.castToSnapshot(e.queries.current.map(n=>y.pick(n,["id","key","type","sql"])));return y.defaults({},{queries:{current:t}},e)}});function z_(e,t){t.filters&&f.applySnapshot(e.filters.current,t.filters)}function fc({id:e,name:t,dashboard_id:n,create_time:r,update_time:i,content:o},l,c){if(!o)throw new Error("unexpected null content when creating a content model");const{version:u,filters:d,views:h,panels:p,layouts:x,definition:{queries:m,sqlSnippets:j,mock_context:C={}}}=o;return oi.create({id:e,name:t,dashboard_id:n,create_time:r,update_time:i,version:u,filters:Jr(d,l,C,c),queries:{current:m},sqlSnippets:{current:j},mock_context:Mr(C),views:ai(h),panels:{list:p},layouts:{list:x,currentBreakpoint:x[0].id}})}const gc=f.types.model({id:f.types.identifier,name:f.types.string,group:f.types.string,content:oi,content_id:f.types.string,datasources:__,globalSQLSnippets:Wr,context:Hn,editor:T_}).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:i,group:o,content_id:l}=t;e.id=r,e.name=i,e.group=o,e.content_id=l,this.updateCurrentContent(n)}}));function mc({id:e,name:t,group:n,content_id:r},i,o,l,c,u){return gc.create({id:e,name:t,group:n,content_id:r,content:fc(i,c,u),datasources:{list:o},globalSQLSnippets:{list:l},context:Rr(c),editor:{}})}function yc(e,t){g.useEffect(()=>{const n=r=>{console.log(r);const{viewID:i}=r.detail;if(!i){console.error(new Error("[Open View] Needs to pick a view first"));return}e.views.appendToVisibles(i),t&&e.views.setIDOfVIE(i)};return window.addEventListener("open-view",n),()=>{window.removeEventListener("open-view",n)}},[e,t]),g.useEffect(()=>{const n=r=>{console.log(r);const{dictionary:i,payload:o}=r.detail;if(!o||Object.keys(o).length===0){console.error(new Error("[Set Filter Values] payload is empty"));return}Object.entries(i).forEach(([l,c])=>{e.filters.setValueByKey(l,y.get(o,c))})};return window.addEventListener("set-filter-values",n),()=>{window.removeEventListener("set-filter-values",n)}},[e]),g.useEffect(()=>{function n(i){return Array.isArray(i)?[]:typeof i=="object"?{}:typeof i=="boolean"?!1:typeof i=="string"?"":typeof i=="number"?0:i}const r=i=>{console.log(i);const{filter_keys:o}=i.detail;o.forEach(l=>{const c=y.get(e.filters.values,l),u=n(c);console.log(`${l}: ${u}`),e.filters.setValueByKey(l,u)})};return window.addEventListener("clear-filter-values",r),()=>{window.removeEventListener("clear-filter-values",r)}},[e]),g.useEffect(()=>{const n=r=>{console.log(r);const{urlTemplate:i,openInNewTab:o,enableEncoding:l=!1,payload:c}=r.detail;if(!i){console.error(new Error("[Open Link] URL is empty"));return}function u(p){return y.cloneDeepWith(p,m=>{if(l&&typeof m=="string")return encodeURIComponent(m)})}const h=y.template(i||"")(u({...c,filters:e.payloadForSQL.filters,context:e.payloadForSQL.context}));window.open(h,o?"_blank":"_self","noopener")};return window.addEventListener("open-link",n),()=>{window.removeEventListener("open-link",n)}},[e])}function bc(e){return g.useCallback(t=>t.provideValue(ue.pluginManager,e.pluginManager).provideValue(ue.vizManager,e.vizManager).provideValue(ue.colorManager,e.colorManager),[])}const QI="",A_=S.observer(({saveDashboardChanges:e})=>{const t=ze.useModals(),n=W(),r=()=>{t.openConfirmModal({title:s.jsxs(a.Group,{position:"left",children:[s.jsx(_.IconAlertTriangle,{size:18,color:"red"}),s.jsx(a.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})},i=n.changed;return s.jsxs(a.Group,{spacing:0,children:[s.jsx(a.Button,{color:"green",variant:"filled",size:"xs",leftIcon:s.jsx(_.IconDeviceFloppy,{size:18}),onClick:e,disabled:!i,sx:{borderTopRightRadius:0,borderBottomRightRadius:0},children:"Save Changes"}),s.jsxs(a.Menu,{width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:320,disabled:!i,children:[s.jsx(a.Menu.Target,{children:s.jsx(a.ActionIcon,{variant:"default",disabled:!i,sx:{height:"30px",borderTopLeftRadius:0,borderBottomLeftRadius:0,svg:{fill:"rgb(173, 181, 189)",stroke:"none"}},children:s.jsx(_.IconCaretDown,{size:18})})}),s.jsx(a.Menu.Dropdown,{children:s.jsx(a.Menu.Item,{icon:s.jsx(_.IconRecycle,{size:14,color:"red"}),disabled:!i,onClick:r,children:"Revert Changes"})})]})]})}),E_=S.observer(({saveDashboardChanges:e,onExit:t,headerSlot:n=null})=>{const r=X(),i=r.content.changed,o=()=>{t({hasChanges:i,dashboardId:r.id})};return s.jsx(a.Header,{height:60,px:"md",py:0,sx:{zIndex:299},children:s.jsxs(a.Group,{position:"apart",sx:{height:60,minWidth:"1000px",position:"relative"},children:[s.jsxs(a.Group,{children:[s.jsx(a.Button,{size:"xs",color:i?"red":"green",leftIcon:s.jsx(_.IconArrowLeft,{size:20}),onClick:o,children:s.jsxs(a.Group,{spacing:4,children:["End Editing",s.jsx(a.Text,{td:"underline",children:r.name})]})}),s.jsx(A_,{saveDashboardChanges:e})]}),s.jsx(a.Group,{position:"right",sx:{flexGrow:1},children:n})]})})}),jc={height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},P_=S.observer(()=>{var r;const e=W(),t=((r=e.views.VIE)==null?void 0:r.type)===L.Tabs,n=()=>e.addANewPanel(e.views.idOfVIE);return t?s.jsx(a.Tooltip,{label:"Please choose a tab first",children:s.jsx(a.Button,{variant:"outline",color:"gray",radius:0,size:"xs",leftIcon:s.jsx(_.IconPlaylistAdd,{size:20}),sx:{...jc,transform:"none !important"},children:"Add a Panel"})}):s.jsx(a.Button,{variant:"outline",color:"blue",radius:0,size:"xs",onClick:n,leftIcon:s.jsx(_.IconPlaylistAdd,{size:20}),sx:{...jc,background:"rgb(231, 245, 255)"},children:"Add a Panel"})}),L_=S.observer(({done:e})=>{var Y,R;const n=W().layouts,r=g.useMemo(()=>({list:n.breakpointsInfo}),[n.breakpointsInfo]),{control:i,handleSubmit:o,watch:l,getValues:c,reset:u,formState:d}=b.useForm({defaultValues:r}),{fields:h,append:p,remove:x}=b.useFieldArray({control:i,name:"list",rules:{validate:F=>{if(console.log({values:F}),y.uniqBy(F,"breakpoint").length!==F.length)return"Screen sizes should be unique by min width"}}}),m=l("list"),j=h.map((F,Z)=>({...F,...m[Z]})),C=()=>{p({id:pt.v4(),name:"",breakpoint:""})},T=({list:F})=>{const Z=F.filter(se=>Number.isFinite(se.breakpoint));n.updateLayoutSetsInfo(Z),e()},D=c(),A=g.useMemo(()=>{const F={list:D.list.filter(Z=>!!Z.name&&Number.isFinite(Z.breakpoint))};return!y.isEqual(F,r)},[D,r]),N=(R=(Y=d.errors.list)==null?void 0:Y.root)==null?void 0:R.message;return s.jsx(s.Fragment,{children:s.jsxs("form",{onSubmit:o(T),children:[s.jsxs(a.Table,{fontSize:"sm",highlightOnHover:!0,withBorder:!0,sx:{tableLayout:"fixed"},children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"340px"},children:"Name"}),s.jsx("th",{style:{width:"160px"},children:"Min Width"}),s.jsx("th",{})]})}),s.jsxs("tbody",{children:[j.map((F,Z)=>s.jsxs("tr",{children:[s.jsx("th",{children:F.id==="basis"?F.name:s.jsx(b.Controller,{name:`list.${Z}.name`,control:i,render:({field:se})=>s.jsx(a.TextInput,{size:"xs",label:"",required:!0,sx:{flex:1},...se})})}),s.jsx("td",{children:F.id==="basis"?s.jsxs(a.Text,{ff:"monospace",children:[F.breakpoint,"px"]}):s.jsx(b.Controller,{name:`list.${Z}.breakpoint`,control:i,render:({field:se})=>s.jsx(a.NumberInput,{size:"xs",label:"",required:!0,max:1e4,hideControls:!0,rightSection:s.jsx(a.Text,{color:"dimmed",children:"px"}),rightSectionProps:{style:{width:"30px"}},sx:{flex:1,fontFamily:"monospace"},styles:{input:{paddingRight:"30px"}},...se})})}),s.jsx("td",{children:F.id!=="basis"&&s.jsx(a.ActionIcon,{mx:"auto",size:"xs",variant:"subtle",color:"red",onClick:()=>x(Z),children:s.jsx(_.IconTrash,{})})})]},F.id)),s.jsx("tr",{style:{backgroundColor:"transparent"},children:s.jsx("td",{colSpan:3,style:{padding:"0"},children:s.jsx(a.Tooltip,{label:"Add a screen size",children:s.jsx(a.ActionIcon,{variant:"subtle",size:"md",color:"blue",onClick:C,sx:{width:"100%"},children:s.jsx(_.IconPlus,{size:18})})})})})]})]}),s.jsx(a.Text,{mt:6,ta:"right",size:"xs",color:"red",children:N??" "}),s.jsxs(a.Group,{mt:6,position:"apart",children:[s.jsx(a.Button,{color:"orange",size:"xs",onClick:()=>u(),leftIcon:s.jsx(_.IconRecycle,{size:18}),disabled:!A,children:"Revert"}),s.jsx(a.Button,{color:"green",size:"xs",type:"submit",leftIcon:s.jsx(_.IconDeviceFloppy,{size:18}),disabled:!A,children:"Save changes"})]})]})})}),B_=S.observer(()=>{const[e,{open:t,close:n}]=re.useDisclosure(!1),r=W(),i=r.layouts.currentBreakpoint,o=r.layouts.currentLayoutRange,l=()=>{setTimeout(()=>{window.dispatchEvent(new Event("resize"))},32)},c=()=>{n(),l()};return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{children:[s.jsxs(a.Menu,{withArrow:!0,withinPortal:!0,zIndex:320,trigger:"hover",children:[s.jsx(a.Menu.Target,{children:s.jsx(a.Button,{size:"xs",variant:"subtle",leftIcon:s.jsx(_.IconDevices,{size:16}),sx:{borderRadius:0},children:s.jsxs(a.Group,{spacing:6,children:[s.jsx(a.Text,{size:"xs",fw:"normal",children:o.name}),s.jsx(a.Text,{size:"xs",color:"#777",children:r.layouts.currentRangeText})]})})}),s.jsxs(a.Menu.Dropdown,{children:[r.layouts.breakpointRanges.map(u=>s.jsx(a.Menu.Item,{onClick:()=>r.layouts.setCurrentBreakpoint(u.id),disabled:i===u.id,children:s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Text,{size:"sm",children:u.name}),s.jsx(a.Text,{size:"xs",color:"dimmed",children:u.text})]})},u.id)),s.jsx(a.Menu.Divider,{}),s.jsx(a.Menu.Item,{color:"blue",icon:s.jsx(_.IconSettings,{size:14}),onClick:t,children:s.jsx(a.Text,{size:"sm",children:"Manage screen sizes"})})]})]}),r.layouts.divisionPreviewScale<1&&s.jsx(a.Text,{size:"xs",color:"dimmed",children:xn(r.layouts.divisionPreviewScale).format({output:"percent",mantissa:0})})]}),s.jsx(a.Modal,{opened:e,onClose:c,title:"Screen sizes",withinPortal:!0,zIndex:320,size:600,closeOnClickOutside:!1,children:s.jsx(L_,{done:c})})]})}),vc={height:"30px",borderRight:"none",borderTop:"none",borderLeft:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},O_=S.observer(()=>{var r;const e=W(),t=((r=e.views.VIE)==null?void 0:r.type)===L.Tabs,n=()=>{var i;return(i=e.views.VIE)==null?void 0:i.downloadSchema()};return t?s.jsx(a.Tooltip,{label:"Please choose a tab first",children:s.jsx(a.Button,{variant:"outline",color:"gray",radius:0,size:"xs",leftIcon:s.jsx(_.IconCode,{size:16}),sx:{...vc,transform:"none !important"},children:"Download this View"})}):s.jsx(a.Button,{variant:"outline",color:"blue",radius:0,size:"xs",onClick:n,leftIcon:s.jsx(_.IconCode,{size:16}),sx:{...vc},children:"Download this View"})}),$_=S.observer(({view:e})=>!e||e.type!==L.Division?null:s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mt:8,mb:0,label:"Division settings",labelPosition:"center"}),s.jsx(a.Text,{align:"center",size:"xs",color:"dimmed",children:"Under construction"})]})),V_=[{value:"default",label:"Default"},{value:"outline",label:"Outline"},{value:"pills",label:"Pills"}],q_=[{value:"horizontal",label:"Horizontal"},{value:"vertical",label:"Vertical"}],N_=S.observer(({view:e})=>{if(!e||e.type!==L.Tabs)return null;const t=e.config;return s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mt:8,mb:0,label:"Tabs settings",labelPosition:"center"}),s.jsx(a.Select,{label:"Variant",value:t.variant,onChange:t.setVariant,data:V_}),s.jsx(a.Select,{label:"Orientation",value:t.orientation,onChange:t.setOrientation,data:q_}),s.jsx(a.Switch,{label:"Grow Tabs",checked:t.grow,onChange:n=>t.setGrow(n.currentTarget.checked)})]})}),F_=({disabled:e,value:t,onChange:n})=>{const r=i=>{i&&n(i)};return s.jsxs(a.Box,{sx:{position:"relative"},children:[e&&s.jsx(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),s.jsx(fe,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},G_=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:i}]=$.useBoolean(),[o,l]=g.useState(e??Zn),c=x=>{l({...o,enabled:x})},u=()=>{i();const{enabled:x,func_content:m}=o,j={enabled:x,func_content:m};l(j),t(j)},d=()=>{i(),l(e)},h=x=>{l(m=>({...m,func_content:x}))},p=()=>{h(Zn.func_content)};return s.jsxs(s.Fragment,{children:[s.jsx(a.ActionIcon,{size:"lg",color:"blue",variant:"filled",mt:26,onClick:r,sx:{flexGrow:0},children:s.jsx(k.Settings,{size:14})}),s.jsx(a.Modal,{size:800,title:"Customize modal title",opened:n,onClose:i,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&s.jsxs(a.Stack,{children:[s.jsx(a.Checkbox,{mt:10,label:"Enabled",checked:o.enabled,onChange:x=>c(x.currentTarget.checked)}),s.jsx(F_,{value:o.func_content,onChange:h,disabled:!o.enabled}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:p,color:"red",leftIcon:s.jsx(k.Recycle,{size:20}),children:"Reset"}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:d,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:u,children:"OK"})]})]})]})})]})},W_=S.observer(({view:e})=>{if(!e||e.type!==L.Modal)return null;const t=e.config,n=t.custom_modal_title.value;return s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mt:8,label:"Modal settings",labelPosition:"center"}),s.jsxs(a.Flex,{gap:10,children:[s.jsx(a.TextInput,{label:"Modal Title",value:n,onChange:y.noop,disabled:!0,sx:{flexGrow:1}}),s.jsx(G_,{value:t.custom_modal_title,onChange:t.custom_modal_title.replace})]}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(a.TextInput,{label:"Width",value:t.width,onChange:r=>t.setWidth(r.currentTarget.value),placeholder:"600px / 50vw"}),s.jsx(a.TextInput,{label:"Height",value:t.height,onChange:r=>t.setHeight(r.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),R_=S.observer(({view:e})=>s.jsxs(s.Fragment,{children:[s.jsx($_,{view:e}),s.jsx(W_,{view:e}),s.jsx(N_,{view:e})]})),ns={[L.Division]:"Division",[L.Modal]:"Modal",[L.Tabs]:"Tabs"},Q_=[{label:ns[L.Division],value:L.Division},{label:ns[L.Modal],value:L.Modal},{label:ns[L.Tabs],value:L.Tabs}],U_=S.observer(({view:e})=>e?s.jsxs(a.Stack,{sx:{position:"relative"},children:[s.jsx(a.TextInput,{label:"Name",value:e.name,onChange:t=>{e.setName(t.currentTarget.value)}}),s.jsx(a.Select,{label:"Type",withinPortal:!0,zIndex:320,value:e.type,onChange:e.setType,data:Q_}),s.jsx(R_,{view:e})]}):null),ss=({headers:e,rows:t})=>s.jsxs(a.Table,{fontSize:"xs",highlightOnHover:!0,sx:{tableLayout:"fixed",fontFamily:"monospace"},children:[s.jsx("thead",{children:e}),s.jsx("tbody",{children:t})]}),K_=({content:e})=>{const t=e.views;return!Array.isArray(t)||t.length===0?null:s.jsxs(a.Box,{children:[s.jsx(a.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:"Views"}),s.jsx(ss,{headers:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"160px"},children:"ID"}),s.jsx("th",{children:"Name"}),s.jsx("th",{children:"Type"})]}),rows:t.map(n=>s.jsxs("tr",{children:[s.jsx("td",{children:n.id}),s.jsx("td",{children:n.name}),s.jsx("td",{children:ns[n.type]})]},n.id))})]})},Y_=({content:e})=>{const t=e.filters;return!Array.isArray(t)||t.length===0?null:s.jsxs(a.Box,{children:[s.jsx(a.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:"Filters"}),s.jsx(ss,{headers:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"160px"},children:"ID"}),s.jsx("th",{children:"Key"}),s.jsx("th",{children:"Label"})]}),rows:t.map(n=>s.jsxs("tr",{children:[s.jsx("td",{children:n.id}),s.jsx("td",{children:n.key}),s.jsx("td",{children:n.label})]},n.id))})]})},X_=({content:e})=>{const t=e.panels;return!Array.isArray(t)||t.length===0?null:s.jsxs(a.Box,{children:[s.jsx(a.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:"Panels"}),s.jsx(ss,{headers:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"160px"},children:"ID"}),s.jsx("th",{children:"Name"}),s.jsx("th",{children:"Visualization"})]}),rows:t.map(n=>s.jsxs("tr",{children:[s.jsx("td",{children:n.id}),s.jsx("td",{children:n.name}),s.jsx("td",{children:n.viz.type})]},n.id))})]})},J_=({content:e})=>{var n;const t=(n=e.definition)==null?void 0:n.queries;return!Array.isArray(t)||t.length===0?null:s.jsxs(a.Box,{children:[s.jsx(a.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:"Queries"}),s.jsx(ss,{headers:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"160px"},children:"ID"}),s.jsx("th",{children:"Name"}),s.jsx("th",{style:{width:"140px"},children:"Type"}),s.jsx("th",{style:{width:"260px"},children:"Data Source"})]}),rows:t.map(r=>s.jsxs("tr",{children:[s.jsx("td",{children:r.id}),s.jsx("td",{children:r.name}),s.jsx("td",{children:r.type}),s.jsx("td",{children:r.key})]},r.id))})]})},Z_=({content:e})=>{var n;const t=(n=e.definition)==null?void 0:n.sqlSnippets;return!Array.isArray(t)||t.length===0?null:s.jsxs(a.Box,{children:[s.jsx(a.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:"SQL Snippets"}),s.jsx(a.List,{size:"sm",pl:10,ff:"monospace",icon:s.jsx(_.IconPointFilled,{size:10}),children:t.map(r=>s.jsx(a.List.Item,{children:r.key},r.key))})]})},H_=({content:e})=>{var n;const t=Object.keys(((n=e.definition)==null?void 0:n.mock_context)??{});return t.length===0?null:s.jsxs(a.Box,{children:[s.jsx(a.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:"Mock Context"}),s.jsx(a.List,{size:"sm",pl:10,ff:"monospace",icon:s.jsx(_.IconPointFilled,{size:10}),children:t.map(r=>s.jsx(a.List.Item,{children:r},r))})]})},ek=({content:e})=>e?s.jsxs(a.Box,{children:[s.jsx(a.Divider,{mt:20,mb:10,variant:"dashed"}),s.jsx(a.Text,{ta:"left",c:"dimmed",children:"Preview"}),s.jsxs(a.Stack,{children:[s.jsx(K_,{content:e}),s.jsx(Y_,{content:e}),s.jsx(X_,{content:e}),s.jsx(J_,{content:e}),s.jsx(Z_,{content:e}),s.jsx(H_,{content:e})]})]}):null;function tk(e){if(e.target===null)throw new Error("FileReader failed with null result");if(typeof e.target.result!="string")throw new Error(`Unparsable file content of type: ${typeof e.target.result}`);let t=JSON.parse(e.target.result);if("content"in t&&(t=t.content),t.version!==at)throw new Error("Schema version mismatch");return t}const nk=S.observer(({onSuccess:e,stretchModal:t,shrinkModal:n})=>{var T,D;const r=W(),{handleSubmit:i,formState:{errors:o},setValue:l,watch:c,setError:u,clearErrors:d}=b.useForm({defaultValues:{content:null}}),h=({content:A})=>{try{if(!A)throw new Error("please use a valid json file");r.applyJSONSchema(A),ut.showNotification({title:"Successful",message:"",color:"green"}),e()}catch(N){console.error(N),ut.showNotification({title:"Failed",message:N.message,color:"red"})}},[p,x]=g.useState(null);g.useEffect(()=>{if(!p)return;const A=new FileReader;A.readAsText(p,"UTF-8"),A.onload=N=>{try{const Y=tk(N);l("content",Y),d("content")}catch(Y){console.error(Y),u("content",{type:"custom",message:Y.message})}},A.onabort=()=>console.log("🟨 abort"),A.onerror=()=>{A.error&&(console.error(A.error),u("content",{type:"custom",message:A.error.message}))}},[p]);const[m]=c(["content"]),j=!m,C=(T=o==null?void 0:o.content)==null?void 0:T.message;return g.useEffect(()=>{!m||C?n():t()},[m,C]),s.jsx(a.Box,{mx:"auto",sx:{position:"relative"},children:s.jsxs("form",{onSubmit:i(h),children:[s.jsx(a.FileInput,{label:"JSON File",required:!0,value:p,onChange:x,error:(D=o==null?void 0:o.content)==null?void 0:D.message,sx:{maxWidth:500}}),C?s.jsx(a.Table,{fontSize:12,mt:10,children:s.jsxs("tbody",{children:[s.jsxs("tr",{children:[s.jsx("th",{children:"Dashboard"}),s.jsx("td",{children:at})]}),s.jsxs("tr",{children:[s.jsx("th",{children:"This file"}),s.jsx("td",{style:{color:"red"},children:m==null?void 0:m.version})]})]})}):s.jsxs(s.Fragment,{children:[s.jsx(ek,{content:m}),s.jsx(a.Group,{position:"right",my:"md",children:s.jsx(a.Button,{type:"submit",color:"green",disabled:j,children:"Confirm"})})]})]})})}),wc={height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},sk=S.observer(()=>{var u;const[e,{open:t,close:n}]=re.useDisclosure(!1),[r,{setTrue:i,setFalse:o}]=$.useBoolean(!1),c=((u=X().content.views.VIE)==null?void 0:u.type)===L.Tabs;return c?s.jsx(a.Tooltip,{label:"Please choose a tab first",children:s.jsx(a.Button,{variant:"outline",color:"gray",radius:0,size:"xs",leftIcon:s.jsx(_.IconFileImport,{size:16}),sx:{...wc,transform:"none !important"},children:"Import..."})}):s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"subtle",color:"blue",radius:0,size:"xs",disabled:c||e,onClick:t,leftIcon:s.jsx(_.IconFileImport,{size:16}),sx:{...wc},children:"Import..."}),s.jsx(a.Modal,{opened:e,onClose:n,title:"Import content with schema json",trapFocus:!0,onDragStart:d=>{d.stopPropagation()},withinPortal:!0,zIndex:320,size:r?"90vw":500,children:s.jsx(nk,{onSuccess:n,stretchModal:i,shrinkModal:o})})]})}),rk={position:"fixed",top:60,left:0,right:0,height:30,zIndex:299,borderBottom:"1px solid #e9ecef",background:"rgba(233,236,239, 0.15)"},ik=S.observer(()=>s.jsx(a.Box,{sx:rk,pl:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},children:s.jsxs(a.Group,{position:"apart",align:"center",sx:{height:"30px"},children:[s.jsxs(a.Group,{position:"left",spacing:0,children:[s.jsx(P_,{}),s.jsx(sk,{})]}),s.jsx(B_,{}),s.jsx(a.Group,{position:"right",spacing:0,children:s.jsx(O_,{})})]})})),ak=S.observer(e=>s.jsxs(s.Fragment,{children:[s.jsx(E_,{...e}),s.jsx(ik,{})]})),UI="";function ok(e,t,n){const r=[];return e.filter(i=>"__INTERACTIONS"in i.viz.conf).forEach((i,o)=>{const l=t[i.id];l.data.interactions=y.get(l,"data.interactions",[]);const{__INTERACTIONS:c,__OPERATIONS:u,__TRIGGERS:d}=i.viz.conf;Object.entries(u).forEach(([h,p])=>{const{schemaRef:x,data:m}=p,{config:j}=m;switch(x){case"builtin:op:open-link":let C=j.urlTemplate.substring(0,100);j.urlTemplate.length>=20&&(C+="..."),l.type="interaction",l.data.interactions.push({schemaRef:x,urlTemplate:j.urlTemplate,shortURLTemplate:C});return;case"builtin:op:open_view":r.push({id:`OPERATION--${h}`,source:i.id,target:j.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:x,filters:Object.keys(j.dictionary).map(T=>({key:T,label:n[T]}))});return;case"builtin:op:clear_filter_values":l.type="interaction",l.data.interactions.push({schemaRef:x,filters:j.filter_keys.map(T=>({key:T,label:n[T]}))});return;default:return}})}),r}function lk(e,t){const n=e.filters.keyLabelMap;return{edges:ok(e.panels.list,t,n),edgeNodes:[]}}function Cc(e,t,n){return e*t+e*n}function ck(e,t,n){return e*t+(e-1)*n}const rs=25,li=40,Sc=25,ci=350,uk=150,dk=150,_c=150,kc=300,is=40,Tc=25,pk=300;function hk(e,t){const n=y.keyBy(t,i=>i.id),r=[];return e.current.forEach((i,o)=>{i.panelIDs.forEach((l,c)=>{const u=Cc(c,is,Tc)+li,d=n[l];if(!d){r.push({id:l,_node_type:"panel",parentNode:i.id,data:{label:`!: ${l}`},position:{x:rs,y:u},sourcePosition:ye.Position.Right,targetPosition:ye.Position.Left,style:{width:kc,height:is}});return}const h=d.name;r.push({id:d.id,_node_type:"panel",parentNode:i.id,data:{label:h},position:{x:rs,y:u},sourcePosition:ye.Position.Right,targetPosition:ye.Position.Left,style:{width:kc,height:is}})})}),r}const xk={[L.Division]:"Div",[L.Modal]:"Modal",[L.Tabs]:"Tabs"},fk=oc;function gk(e){return e.current.map((n,r)=>{const i=ck(n.panelIDs.length,is,Tc)+li+Sc;let o=[];return n.type===L.Tabs&&(o=n.config.tabsInOrder.map(c=>c.view_id)),{id:n.id,_node_type:"view-root",_view_type:n.type,_view_level:0,_sub_view_ids:[],_tab_view_ids:o,data:{label:`${xk[n.type]}:${n.name}`},position:{x:0,y:0},sourcePosition:ye.Position.Right,targetPosition:ye.Position.Left,className:"light",style:{backgroundColor:fk[n.type],width:ci,height:i}}})}function mk(e){const t=y.keyBy(e,n=>n.id);e.forEach(n=>{n._node_type!=="view-root"||n._view_type!==L.Tabs||n._tab_view_ids.forEach(r=>{t[r].parentNode=n.id})})}function yk(e){const t=gk(e.views);mk(t);const n=hk(e.views,e.panels.list);return[...t,...n]}function bk({nodeMap:e,nodes:t,edges:n}){t.forEach(r=>{r._node_type!=="view-root"||r._view_type!==L.Tabs||(r.sourcePosition=ye.Position.Bottom,r.style.width=ci+rs*2,r.style.height=Sc+r._tab_view_ids.reduce((i,o)=>{const l=e[o];l.position.y=i,l.position.x=rs;const c=l.style.height;return i+c+20},li))})}function jk({nodeMap:e,nodes:t,edges:n}){n.filter(r=>r.label==="Open View").forEach(r=>{const i=e[r.source],o=e[r.target];if(!i||!o||!i.parentNode)return;const l=e[i.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,i)=>r._node_type==="view-root"&&i._node_type==="view-root"?r._view_level-i._view_level:r._node_type!=="view-root"&&i._node_type!=="view-root"?0:r._node_type==="view-root"?-1:1)}function vk({nodeMap:e,nodes:t,edges:n}){const r={};n.forEach(i=>{if(i.label!=="Open View")return;const o=e[i.source],l=e[i.target];if(o&&l&&o.parentNode){const c=e[o.parentNode],u=c.position.x,d=Number(y.get(l,"style.height",0)),h=Number(c.style.width);l.position.x=u+h+pk,c._view_level===0&&l._sub_view_ids.length===0&&(o.sourcePosition=ye.Position.Left,l.targetPosition=ye.Position.Right,l.position.x*=-1);const x=l.position.x,m=y.get(r,x,0);l.position.y=m,r[x]=m+d+_c}})}function wk({nodeMap:e,nodes:t,edges:n}){const r=new Set,i=new Set;n.forEach(l=>{r.add(l.source),i.add(l.target)}),t.filter(l=>l._node_type!=="view-root"||l.id==="Main"||l.parentNode?!1:!r.has(l.id)&&!i.has(l.id)).forEach((l,c)=>{l.position.x=Cc(c,ci,dk),l.position.y=0-uk-_c})}function Ck({nodeMap:e,nodes:t,edges:n}){const r={nodeMap:e,nodes:t,edges:n};return wk(r),jk(r),bk(r),vk(r),{nodes:t,edges:n}}function Sk(e){const t=yk(e),n=y.keyBy(t,u=>u.id),{edges:r,edgeNodes:i}=lk(e,n),o=[...t,...i],l=y.keyBy(o,u=>u.id),c={edges:y.uniqBy(r,u=>u.id),nodes:o,nodeMap:l};return Ck(c)}const KI="",ui={"builtin:op:open-link":s.jsx(a.ThemeIcon,{color:"blue",size:20,radius:"xl",children:s.jsx(_.IconCircleDashed,{size:14})}),"builtin:op:set_filter_values":s.jsx(a.ThemeIcon,{color:"orange",size:20,radius:"xl",children:s.jsx(_.IconCircleDot,{size:14})}),"builtin:op:clear_filter_values":s.jsx(a.ThemeIcon,{color:"orange",size:20,radius:"xl",children:s.jsx(_.IconCircleOff,{size:14})})};function _k(e){const t=[];return e.forEach(n=>{switch(n.schemaRef){case"builtin:op:open-link":t.push({key:n.urlTemplate,icon:ui[n.schemaRef],text:s.jsxs(a.Group,{spacing:4,children:[s.jsx(a.Text,{children:"Open: "}),s.jsx(a.Text,{color:"dimmed",children:n.shortURLTemplate})]})});return;case"builtin:op:set_filter_values":n.filters.forEach(({key:r,label:i})=>{t.push({key:n.schemaRef+r,icon:ui[n.schemaRef],text:s.jsx(a.Group,{spacing:4,children:s.jsxs(a.Text,{children:["Set Filter: ",i]})})})});return;case"builtin:op:clear_filter_values":n.filters.forEach(({key:r,label:i})=>{t.push({key:n.schemaRef+r,icon:ui[n.schemaRef],text:s.jsx(a.Group,{spacing:4,children:s.jsxs(a.Text,{children:["Clear Filter: ",i]})})})});return}}),t}const kk=g.memo(({data:e,isConnectable:t,sourcePosition:n=ye.Position.Right,targetPosition:r=ye.Position.Left,...i})=>{const o=g.useMemo(()=>_k(e.interactions),[e.interactions]);return s.jsxs(s.Fragment,{children:[s.jsx(ye.Handle,{type:"target",position:r,isConnectable:t}),s.jsx(a.Box,{sx:{position:"absolute",top:0,right:0},children:s.jsx(k.ChevronsUpRight,{size:12})}),s.jsxs(a.HoverCard,{shadow:"xl",withinPortal:!0,children:[s.jsx(a.HoverCard.Target,{children:s.jsx(a.Text,{children:e.label})}),s.jsx(a.HoverCard.Dropdown,{children:s.jsx(a.List,{spacing:"xs",size:"sm",center:!0,children:o.map(l=>s.jsx(a.List.Item,{icon:l.icon,children:l.text},l.key))})})]}),s.jsx(ye.Handle,{type:"source",position:n,isConnectable:t})]})}),YI="",Tk={interaction:kk},Dk=S.observer(()=>{const e=ce(),{edges:t,nodes:n}=Sk(e);return s.jsxs(ye,{nodes:n,edges:t,onNodesChange:y.noop,onEdgesChange:y.noop,onConnect:y.noop,className:"interactions-viewer",fitView:!0,nodeTypes:Tk,children:[s.jsx(ye.MiniMap,{}),s.jsx(ye.Controls,{}),s.jsx(ye.Background,{})]})}),Ik=S.observer(({opened:e,close:t})=>s.jsx(a.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:s.jsx(Dk,{})})),Mk={"> 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 zk({onClick:e,name:t,active:n,openSettings:r}){return s.jsxs(a.Box,{sx:{position:"relative"},children:[s.jsx(a.UnstyledButton,{sx:i=>({display:"block",width:"100%",padding:i.spacing.xs,borderRadius:0,position:"relative",color:i.black,"&:hover":{backgroundColor:i.colors.gray[0]},backgroundColor:n?i.colors.gray[2]:"transparent"}),children:s.jsx(a.Group,{sx:{width:"calc(100% - 28px)"},onClick:e,children:s.jsx(a.Text,{size:"sm",children:t})})}),n&&s.jsx(a.Tooltip,{label:"Edit",position:"right",withinPortal:!0,children:s.jsx(a.ActionIcon,{onClick:r,variant:"light",color:"blue",sx:{position:"absolute",top:0,bottom:0,height:"100%",right:0,zIndex:0,borderRadius:0},children:s.jsx(_.IconAdjustments,{size:16})})})]})}const Ak=S.observer(()=>{const e=X(),t=W(),n=g.useCallback(i=>()=>t.views.setIDOfVIE(i),[t]),r=i=>{e.editor.open(["_VIEWS_",i])};return s.jsxs(a.Box,{sx:{position:"relative"},children:[t.views.options.map(i=>s.jsx(zk,{active:t.views.idOfVIE===i.value,name:i.label,onClick:n(i.value),openSettings:()=>r(i.value)},i.value)),s.jsx(a.Divider,{variant:"dashed"}),s.jsx(a.Button,{variant:"subtle",rightIcon:s.jsx(_.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"})]})}),Ek=S.observer(()=>{const e=X(),t=W(),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])},[i,o]=g.useState(!1),l=()=>o(!0),c=()=>o(!1);return s.jsxs(a.Navbar,{p:0,width:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},zIndex:299,children:[s.jsxs(a.Navbar.Section,{children:[s.jsxs(a.Group,{grow:!0,spacing:0,sx:{...Mk,button:{borderWidth:0,borderBottomWidth:1,borderColor:"#e9ecef"}},children:[s.jsx(a.Tooltip,{label:"Filters",withinPortal:!0,children:s.jsx(a.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:r,children:s.jsx(_.IconFilter,{size:18})})}),s.jsx(a.Tooltip,{label:"Queries",withinPortal:!0,children:s.jsx(a.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:n,children:s.jsx(_.IconDatabase,{size:18})})}),s.jsx(a.Tooltip,{label:"Interactions Viewer",withinPortal:!0,children:s.jsx(a.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:l,children:s.jsx(_.IconLink,{size:18})})})]}),s.jsx(Ik,{opened:i,close:c})]}),s.jsx(a.Navbar.Section,{py:5,sx:{borderBottom:"1px solid #eee"},children:s.jsx(a.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Views"})}),s.jsx(a.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:s.jsx(Ak,{})}),s.jsx(a.Navbar.Section,{children:s.jsx(a.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:s.jsx(a.Button,{size:"xs",leftIcon:s.jsx(_.IconSettings,{size:20}),onClick:()=>e.editor.open([]),children:"Settings"})})})]})}),Pk=["function getDefaultValue(filter, utils, context) {",' return "";',"}"].join(`
454
+ `),Ft=S.observer(({filter:e})=>s.jsx(ho,{label:"",title:"Custom Default Value",triggerLabel:"Default by function",value:e.default_value_func,onChange:e.setDefaultValueFunc,defaultValue:Pk,triggerButtonProps:{size:"xs",color:"grape",sx:{flexGrow:0,alignSelf:"flex-start"},leftIcon:s.jsx(_.IconMathFunction,{size:16})},description:s.jsx(a.Alert,{title:"Tips",color:"gray",mb:16,children:s.jsxs(a.List,{size:13,type:"ordered",children:[s.jsx(a.List.Item,{children:"Function has the highest priority of getting filter's default value"}),s.jsx(a.List.Item,{children:"Leave this editor empty to disable this feature"})]})})})),Lk=S.observer(function({filter:t}){const n=t.config;return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Checkbox,{checked:n.default_value,onChange:r=>n.setDefaultValue(r.currentTarget.checked),label:"Default Checked"}),s.jsx(Ft,{filter:t})]}),s.jsx(ur,{label:"Description",value:n.description,onChange:n.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"}],Ok=S.observer(function({filter:t}){const n=t.config,r=g.useMemo(()=>Dr().map(({value:i,group:o})=>({label:i,value:i,group:o})),[]);return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{children:[s.jsx(a.Checkbox,{checked:n.required,onChange:i=>n.setRequired(i.currentTarget.checked),label:"Required"}),s.jsx(a.Checkbox,{checked:n.allowSingleDateInRange,onChange:i=>n.setAllowSingleDateInRange(i.currentTarget.checked),label:"Allow choosing 1 day"})]}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(a.Select,{data:Bk,label:"Display Format",value:n.inputFormat,onChange:n.setInputFormat}),s.jsx(a.NumberInput,{label:"Max Days",min:0,value:n.max_days,onChange:n.setMaxDays,hideControls:!0})]}),s.jsxs(a.Group,{children:[s.jsx(ll,{label:"Default Value",config:n,value:n.default_value,onChange:n.setDefaultValue,disabled:!!n.default_shortcut}),s.jsx(a.Select,{data:r,label:"Default by Shortcut",value:n.default_shortcut,onChange:n.setDefaultShortcut,placeholder:"Priors default value",clearable:!0,sx:{flexGrow:1},maxDropdownHeight:500})]}),s.jsx(Ft,{filter:t})]})}),di=S.observer(({value:e,onChange:t})=>{const n=X(),r=W(),i=g.useMemo(()=>r.queries.options,[r.queries.current]),o=i.length===0,l=c=>{n.editor.setPath(["_QUERIES_",c])};return s.jsx(a.Select,{label:s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Text,{children:"Use query data as options"}),e&&s.jsx(a.Button,{size:"xs",leftIcon:s.jsx(_.IconArrowCurveRight,{size:16}),variant:"subtle",color:"blue",onClick:()=>l(e),children:"Open this query"})]}),data:i,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"}}})}),$k=`
455
455
  // row
456
456
  {
457
457
  label: string;
458
458
  value: string;
459
459
  description?: string; // optional
460
460
  }
461
- `,Tu=()=>{const[e,t]=g.useState(!1);return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"subtle",compact:!0,onClick:()=>t(n=>!n),children:e?"Close":"Click to see expected data structure"}),s.jsx(a.Collapse,{in:e,children:s.jsx(pt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:Ok})})]})},$k=S.observer(function({filter:t}){const n=t.config,r=()=>{n.addStaticOption({label:"",value:""})},i=n.static_options,o=[...i];return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Checkbox,{checked:n.required,onChange:l=>n.setRequired(l.currentTarget.checked),label:"Required"}),s.jsx(Gt,{filter:t})]}),s.jsx(a.TextInput,{label:"Width",description:"At least 160px",value:n.min_width,onChange:l=>n.setMinWidth(l.currentTarget.value),placeholder:"default: 200px"}),s.jsx(a.Divider,{label:"Configure options",labelPosition:"center"}),s.jsxs(a.Stack,{spacing:10,sx:{position:"relative",minHeight:"50px"},children:[n.usingQuery&&s.jsxs(s.Fragment,{children:[s.jsx(a.Overlay,{opacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),s.jsx(a.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:s.jsx(a.Text,{color:"white",size:16,children:"Using query"})})]}),i.length>0&&s.jsx(a.MultiSelect,{label:"Default Selection",data:o,value:[...n.default_value],onChange:n.setDefaultValue}),i.map((l,u)=>s.jsxs(a.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[s.jsx(a.TextInput,{label:"Label",required:!0,value:n.static_options[u].label,onChange:c=>{n.static_options[u].setLabel(c.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(a.TextInput,{label:"Value",required:!0,value:n.static_options[u].value,onChange:c=>{n.static_options[u].setValue(c.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(a.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n.removeStaticOption(u),sx:{position:"absolute",top:28,right:5},children:s.jsx(k.Trash,{size:16})})]},u)),s.jsx(a.Button,{mt:10,size:"xs",color:"blue",leftIcon:s.jsx(k.PlaylistAdd,{size:20}),onClick:r,sx:{width:"50%"},mx:"auto",children:"Add an Option"})]}),s.jsx(a.Divider,{label:"Or fetch options from database",labelPosition:"center"}),s.jsx(a.NumberInput,{value:n.default_selection_count,onChange:n.setDefaultSelectionCount,label:"Select first N options by default"}),s.jsx(pi,{value:n.options_query_id,onChange:n.setOptionsQueryID}),s.jsx(Tu,{})]})}),Vk=S.observer(function({filter:t}){const n=t.config,r=()=>{n.addStaticOption({label:"",value:""})},i=n.static_options,o=[{label:"No default selection",value:""},...i];return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Checkbox,{checked:n.required,onChange:l=>n.setRequired(l.currentTarget.checked),label:"Required"}),s.jsx(Gt,{filter:t})]}),s.jsx(a.TextInput,{label:"Width",value:n.width,onChange:l=>n.setWidth(l.currentTarget.value),placeholder:"200px"}),s.jsx(a.Divider,{label:"Configure options",labelPosition:"center"}),s.jsxs(a.Stack,{spacing:10,sx:{position:"relative",minHeight:"50px"},children:[n.usingQuery&&s.jsxs(s.Fragment,{children:[s.jsx(a.Overlay,{opacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),s.jsx(a.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:s.jsx(a.Text,{color:"white",size:16,children:"Using query"})})]}),i.length>0&&s.jsx(a.Select,{label:"Default Selection",data:o,value:n.default_value,onChange:n.setDefaultValue}),i.map((l,u)=>s.jsxs(a.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[s.jsx(a.TextInput,{label:"Label",required:!0,value:n.static_options[u].label,onChange:c=>{n.static_options[u].setLabel(c.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(a.TextInput,{label:"Value",required:!0,value:n.static_options[u].value,onChange:c=>{n.static_options[u].setValue(c.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(a.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n.removeStaticOption(u),sx:{position:"absolute",top:28,right:5},children:s.jsx(k.Trash,{size:16})})]},u)),s.jsx(a.Button,{size:"xs",color:"blue",leftIcon:s.jsx(k.PlaylistAdd,{size:20}),onClick:r,sx:{width:"50%"},mx:"auto",children:"Add an Option"})]}),s.jsx(a.Divider,{label:"Or fetch options from database",labelPosition:"center"}),s.jsx(a.Checkbox,{checked:n.default_selection_count===1,onChange:l=>n.setDefaultSelectionCount(l.currentTarget.checked?1:0),label:"Select the first option by default"}),s.jsx(pi,{value:n.options_query_id,onChange:n.setOptionsQueryID}),s.jsx(Tu,{})]})}),qk=S.observer(function({filter:t}){const n=t.config;return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{children:[s.jsx(a.TextInput,{label:"Default Value",value:n.default_value,onChange:r=>{n.setDefaultValue(r.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(a.Box,{mt:22,children:s.jsx(Gt,{filter:t})})]}),s.jsx(a.Checkbox,{checked:n.required,onChange:r=>n.setRequired(r.currentTarget.checked),label:"Required"})]})}),Nk=`
461
+ `,Dc=()=>{const[e,t]=g.useState(!1);return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"subtle",compact:!0,onClick:()=>t(n=>!n),children:e?"Close":"Click to see expected data structure"}),s.jsx(a.Collapse,{in:e,children:s.jsx(dt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:$k})})]})},Vk=S.observer(function({filter:t}){const n=t.config,r=()=>{n.addStaticOption({label:"",value:""})},i=n.static_options,o=[...i];return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Checkbox,{checked:n.required,onChange:l=>n.setRequired(l.currentTarget.checked),label:"Required"}),s.jsx(Ft,{filter:t})]}),s.jsx(a.TextInput,{label:"Width",description:"At least 160px",value:n.min_width,onChange:l=>n.setMinWidth(l.currentTarget.value),placeholder:"default: 200px"}),s.jsx(a.Divider,{label:"Configure options",labelPosition:"center"}),s.jsxs(a.Stack,{spacing:10,sx:{position:"relative",minHeight:"50px"},children:[n.usingQuery&&s.jsxs(s.Fragment,{children:[s.jsx(a.Overlay,{opacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),s.jsx(a.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:s.jsx(a.Text,{color:"white",size:16,children:"Using query"})})]}),i.length>0&&s.jsx(a.MultiSelect,{label:"Default Selection",data:o,value:[...n.default_value],onChange:n.setDefaultValue}),i.map((l,c)=>s.jsxs(a.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[s.jsx(a.TextInput,{label:"Label",required:!0,value:n.static_options[c].label,onChange:u=>{n.static_options[c].setLabel(u.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(a.TextInput,{label:"Value",required:!0,value:n.static_options[c].value,onChange:u=>{n.static_options[c].setValue(u.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(a.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n.removeStaticOption(c),sx:{position:"absolute",top:28,right:5},children:s.jsx(k.Trash,{size:16})})]},c)),s.jsx(a.Button,{mt:10,size:"xs",color:"blue",leftIcon:s.jsx(k.PlaylistAdd,{size:20}),onClick:r,sx:{width:"50%"},mx:"auto",children:"Add an Option"})]}),s.jsx(a.Divider,{label:"Or fetch options from database",labelPosition:"center"}),s.jsx(a.NumberInput,{value:n.default_selection_count,onChange:n.setDefaultSelectionCount,label:"Select first N options by default"}),s.jsx(di,{value:n.options_query_id,onChange:n.setOptionsQueryID}),s.jsx(Dc,{})]})}),qk=S.observer(function({filter:t}){const n=t.config,r=()=>{n.addStaticOption({label:"",value:""})},i=n.static_options,o=[{label:"No default selection",value:""},...i];return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Checkbox,{checked:n.required,onChange:l=>n.setRequired(l.currentTarget.checked),label:"Required"}),s.jsx(Ft,{filter:t})]}),s.jsx(a.TextInput,{label:"Width",value:n.width,onChange:l=>n.setWidth(l.currentTarget.value),placeholder:"200px"}),s.jsx(a.Divider,{label:"Configure options",labelPosition:"center"}),s.jsxs(a.Stack,{spacing:10,sx:{position:"relative",minHeight:"50px"},children:[n.usingQuery&&s.jsxs(s.Fragment,{children:[s.jsx(a.Overlay,{opacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),s.jsx(a.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:s.jsx(a.Text,{color:"white",size:16,children:"Using query"})})]}),i.length>0&&s.jsx(a.Select,{label:"Default Selection",data:o,value:n.default_value,onChange:n.setDefaultValue}),i.map((l,c)=>s.jsxs(a.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[s.jsx(a.TextInput,{label:"Label",required:!0,value:n.static_options[c].label,onChange:u=>{n.static_options[c].setLabel(u.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(a.TextInput,{label:"Value",required:!0,value:n.static_options[c].value,onChange:u=>{n.static_options[c].setValue(u.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(a.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n.removeStaticOption(c),sx:{position:"absolute",top:28,right:5},children:s.jsx(k.Trash,{size:16})})]},c)),s.jsx(a.Button,{size:"xs",color:"blue",leftIcon:s.jsx(k.PlaylistAdd,{size:20}),onClick:r,sx:{width:"50%"},mx:"auto",children:"Add an Option"})]}),s.jsx(a.Divider,{label:"Or fetch options from database",labelPosition:"center"}),s.jsx(a.Checkbox,{checked:n.default_selection_count===1,onChange:l=>n.setDefaultSelectionCount(l.currentTarget.checked?1:0),label:"Select the first option by default"}),s.jsx(di,{value:n.options_query_id,onChange:n.setOptionsQueryID}),s.jsx(Dc,{})]})}),Nk=S.observer(function({filter:t}){const n=t.config;return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{children:[s.jsx(a.TextInput,{label:"Default Value",value:n.default_value,onChange:r=>{n.setDefaultValue(r.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(a.Box,{mt:22,children:s.jsx(Ft,{filter:t})})]}),s.jsx(a.Checkbox,{checked:n.required,onChange:r=>n.setRequired(r.currentTarget.checked),label:"Required"})]})}),Fk=`
462
462
  // row
463
463
  {
464
464
  label: string;
@@ -466,7 +466,7 @@ Check the top-level render call using <`+E+">.")}return I}}function rc(w,I){{if(
466
466
  parent_value: string;
467
467
  description?: string;
468
468
  }
469
- `,Fk=()=>{const[e,t]=g.useState(!1);return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"subtle",compact:!0,onClick:()=>t(n=>!n),children:e?"Close":"Click to see expected data structure"}),s.jsx(a.Collapse,{in:e,children:s.jsx(pt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:Nk})})]})},Gk=S.observer(function({filter:t}){const n=t.config;return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Checkbox,{checked:n.required,onChange:r=>n.setRequired(r.currentTarget.checked),label:"Required"}),s.jsx(Gt,{filter:t})]}),s.jsx(a.TextInput,{label:"Min-width",value:n.min_width,onChange:r=>n.setMinWidth(r.currentTarget.value),placeholder:"200px"}),s.jsx(a.Divider,{label:"Fetch options from database",labelPosition:"center"}),s.jsx(a.Checkbox,{checked:n.treeCheckStrictly,onChange:r=>n.setTreeCheckStrictly(r.currentTarget.checked),label:"Parent and children nodes are not associated"}),s.jsx(a.NumberInput,{value:n.default_selection_count,onChange:n.setDefaultSelectionCount,label:"Select first N options by default"}),s.jsx(pi,{value:n.options_query_id,onChange:n.setOptionsQueryID}),s.jsx(Fk,{})]})}),Wk=S.observer(function({filter:t}){return s.jsxs(a.Box,{sx:{maxWidth:"480px"},children:[s.jsx(a.Text,{pt:"0",pb:"md",color:"gray",children:"Config"}),s.jsx(pt.Prism,{mt:22,language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(t,null,4)})]})}),Rk={select:Vk,"multi-select":$k,"tree-select":Gk,"text-input":qk,checkbox:Lk,"date-range":Bk},yt={select:"Select","multi-select":"Multi Select","tree-select":"Tree Select","text-input":"Text Input",checkbox:"Checkbox","date-range":"Date Range"},Qk=[{label:yt.select,value:"select"},{label:yt["multi-select"],value:"multi-select"},{label:yt["tree-select"],value:"tree-select"},{label:yt["text-input"],value:"text-input"},{label:yt.checkbox,value:"checkbox"},{label:yt["date-range"],value:"date-range"}],Uk=S.observer(function({filter:t}){const n=R(),r=g.useMemo(()=>Rk[t.type],[t.type]);return s.jsxs(a.Group,{grow:!0,spacing:20,align:"top",children:[s.jsxs(a.Box,{sx:{maxWidth:"600px"},children:[s.jsx(a.Text,{pb:"md",color:"gray",children:"Edit"}),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{noWrap:!0,children:[s.jsx(a.NumberInput,{label:"Placement Order",required:!0,value:t.order,onChange:t.setOrder,hideControls:!0,sx:{flexGrow:"1 !important"}}),t.auto_submit_supported&&s.jsx(a.Checkbox,{label:"Submit automatically",checked:t.auto_submit,onChange:i=>t.setAutoSubmit(i.currentTarget.checked),mt:22})]}),s.jsx(a.MultiSelect,{label:"Visible in...",data:n.views.options,value:[...t.visibleInViewsIDs],onChange:t.setVisibleInViewsIDs}),s.jsx(a.TextInput,{label:"Key",placeholder:"A unique key to refer",required:!0,value:t.key,onChange:i=>{t.setKey(i.currentTarget.value)}}),s.jsx(a.TextInput,{label:"Label",placeholder:"Label for this field",required:!0,value:t.label,onChange:i=>{t.setLabel(i.currentTarget.value)}}),s.jsx(a.Select,{label:"Widget",data:Qk,required:!0,value:t.type,onChange:t.setType,maxDropdownHeight:500}),s.jsx(a.Divider,{mb:0,mt:10,variant:"dashed",label:`${yt[t.type]} Settings`,labelPosition:"center"}),s.jsx(r,{filter:t})]})]}),s.jsx(Wk,{filter:t})]})}),Kk=S.observer(({id:e})=>{const t=Le.useModals(),n=Z(),r=R();if(e==="")return null;const i=r.filters.findByID(e);if(!i)return s.jsxs(a.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 s.jsxs(a.Stack,{sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",pb:30,children:[s.jsx(a.Group,{position:"right",pt:10,children:s.jsx(a.Button,{size:"xs",color:"red",leftIcon:s.jsx(k.Trash,{size:16}),onClick:l,children:"Delete this filter"})}),s.jsx(a.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:s.jsx(Uk,{filter:i})})]})}),Yk=S.observer(()=>{const[e,t]=g.useState([]),n=Z(),r=c=>{n.editor.setPath(["_FILTERS_",c])},i=()=>{n.content.filters.downloadSchema(e)},o=g.useMemo(()=>n.content.filters.sortedList.map(c=>c.id),[n.content.filters.sortedList]),l=()=>{t(o)},u=()=>{t([])};return s.jsxs(a.Stack,{sx:{height:"100%"},spacing:"sm",pb:"59px",children:[s.jsx(a.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:s.jsx(a.Text,{px:"md",align:"left",sx:{userSelect:"none",cursor:"default"},children:"Manage Filters"})}),s.jsx(a.Flex,{justify:"space-between",align:"center",px:12,children:s.jsxs(a.Group,{position:"left",children:[s.jsxs(a.Button.Group,{children:[s.jsx(a.Button,{variant:"default",size:"xs",onClick:l,children:"Select All"}),s.jsx(a.Button,{variant:"default",size:"xs",onClick:u,children:"Clear Selection"})]}),s.jsx(a.Button,{size:"xs",color:"blue",leftIcon:s.jsx(_.IconCode,{size:14}),disabled:e.length===0,onClick:i,children:"Download Schema"})]})}),s.jsx(a.Box,{sx:{flexGrow:1,overflow:"auto"},children:s.jsx(a.Checkbox.Group,{size:"xs",value:e,onChange:t,children:s.jsxs(a.Table,{fontSize:"sm",highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"40px"}}),s.jsx("th",{style:{width:"300px"},children:"Label"}),s.jsx("th",{children:"Key"}),s.jsx("th",{style:{width:"100px"},children:"Widget"}),s.jsx("th",{style:{width:"300px",paddingLeft:"24px"},children:"Action"})]})}),s.jsx("tbody",{children:n.content.filters.sortedList.map(c=>s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx(a.Checkbox,{value:c.id,styles:{input:{cursor:"pointer"}}})}),s.jsx("td",{children:c.label}),s.jsx("td",{children:c.key}),s.jsx("td",{children:yt[c.type]}),s.jsx("td",{children:s.jsx(a.Button,{variant:"subtle",size:"xs",onClick:()=>r(c.id),children:"Open"})})]},c.id))})]})})})]})}),Xk=S.observer(()=>{const e=R(),[t,n]=g.useState(()=>JSON.stringify(e.mock_context.current,null,4)),r=()=>{try{e.mock_context.replace(JSON.parse(t))}catch(o){dt.showNotification({title:"Failed",message:o.message,color:"red"})}},i=g.useMemo(()=>{try{return JSON.stringify(JSON.parse(t))!==JSON.stringify(e.mock_context.current)}catch{return!1}},[t,e.mock_context.current]);return s.jsxs(a.Stack,{sx:{border:"1px solid #eee",borderLeft:"none",borderRight:"none",flexGrow:1,maxWidth:"unset"},children:[s.jsx(a.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:s.jsx(a.Text,{weight:500,children:"Mock Context"})}),s.jsxs(a.Group,{grow:!0,px:"md",pb:"md",pt:0,sx:{flexGrow:1,position:"relative",alignItems:"flex-start"},children:[s.jsxs(a.Stack,{spacing:10,sx:{maxWidth:"unset !important"},children:[s.jsx(a.Text,{children:"A valid json string is required"}),s.jsx(a.JsonInput,{validationError:"Invalid json",formatOnBlur:!0,autosize:!0,minRows:30,value:t,onChange:n,sx:{flexGrow:1}})]}),s.jsx(a.ActionIcon,{mr:5,variant:"filled",color:"blue",sx:{position:"absolute",right:12,top:0},disabled:!i,onClick:r,children:s.jsx(k.DeviceFloppy,{size:20})})]})]})}),Jk=S.observer(()=>{const{panel:e}=Be();return s.jsx(dr,{label:"Description",value:e.description,onChange:e.setDescription,styles:{root:{flexGrow:1}}})}),Zk=S.observer(()=>{const{panel:e}=Be(),t=pe().layouts.findItemByPanelID(e.id),{style:n}=e;return s.jsxs(s.Fragment,{children:[s.jsx(a.Divider,{mb:-10,label:"Style",labelPosition:"center",variant:"dashed"}),s.jsxs(a.Stack,{spacing:20,children:[s.jsxs(a.Group,{grow:!0,align:"top",children:[s.jsx(a.NumberInput,{label:"Width",min:1,max:36,step:1,precision:0,rightSection:s.jsx(a.Text,{size:12,children:"of 36 columns"}),styles:{rightSection:{width:"110px"}},value:t.w,onChange:r=>{r&&t.setWidth(r)}}),s.jsx(a.NumberInput,{label:"Height",rightSection:s.jsx(a.Text,{size:12,children:"px"}),styles:{rightSection:{width:"40px"}},value:t.h,onChange:r=>{r&&t.setHeight(r)}})]}),s.jsx(a.Checkbox,{ml:6,label:"Border",checked:n.border.enabled,onChange:r=>n.border.setEnabled(r.currentTarget.checked)})]})]})}),Hk=()=>s.jsxs("span",{className:"mantine-103svbs mantine-InputWrapper-required mantine-Select-required","aria-hidden":"true",children:[" ","*"]}),eT=S.observer(()=>{const{panel:e}=Be(),{name:t}=e,[n,r]=oe.useInputState(t),i=t!==n,o=g.useCallback(()=>{i&&e.setName(n)},[i,n]);g.useEffect(()=>{r(t)},[t]);const l=!n.trim();return s.jsxs(a.Stack,{spacing:4,children:[s.jsxs(a.Group,{align:"center",children:[s.jsxs(a.Text,{size:14,fw:500,children:["Panel Name",s.jsx(Hk,{})]}),s.jsx(a.ActionIcon,{variant:"subtle",color:"blue",disabled:!i||l,onClick:o,children:s.jsx(_.IconDeviceFloppy,{size:18})})]}),s.jsx(a.TextInput,{value:n,onChange:r,required:!0})]})}),tT=S.observer(()=>{const{panel:e}=Be();return s.jsx(a.Stack,{spacing:6,mb:10,children:s.jsxs(a.Group,{pl:6,position:"left",spacing:20,children:[s.jsx(a.Checkbox,{size:"sm",checked:e.title.show,onChange:t=>e.title.setShow(t.currentTarget.checked),label:"Show Title",sx:{userSelect:"none"}}),s.jsx(a.Checkbox,{size:"sm",checked:!0,disabled:!0,label:"Use name as title"})]})})});function nT(){return s.jsxs(a.Stack,{sx:{height:"100%"},children:[s.jsx(Zk,{}),s.jsx(a.Divider,{label:"Info",labelPosition:"center",variant:"dashed"}),s.jsx(eT,{}),s.jsx(tT,{}),s.jsx(Jk,{})]})}const sT={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 Du({data:e}){const t=g.useMemo(()=>{if(!Array.isArray(e)||e.length===0)return[];const r=Re.createColumnHelper();return Object.keys(e[0]).map(i=>r.accessor(i,{cell:o=>o.getValue()}))},[e]),n=Re.useReactTable({data:e,columns:t,columnResizeMode:"onChange",getCoreRowModel:Re.getCoreRowModel()});return e.length===0?s.jsx(a.Box,{sx:{height:"5em"}}):s.jsx(we,{children:s.jsxs(a.Table,{sx:sT,children:[s.jsx("thead",{children:n.getHeaderGroups().map(r=>s.jsx("tr",{children:r.headers.map(i=>s.jsxs("th",{style:{width:i.getSize()},children:[i.isPlaceholder?null:Re.flexRender(i.column.columnDef.header,i.getContext()),s.jsx(a.ActionIcon,{onMouseDown:i.getResizeHandler(),onTouchStart:i.getResizeHandler(),className:`resizer ${i.column.getIsResizing()?"isResizing":""}`,children:s.jsx(k.ArrowBarToRight,{})})]},i.id))},r.id))}),s.jsx("tbody",{children:n.getRowModel().rows.map(r=>s.jsx("tr",{children:r.getVisibleCells().map(i=>s.jsx("td",{children:s.jsx(we,{children:Re.flexRender(i.column.columnDef.cell,i.getContext())})},i.id))},r.id))})]})})}const rT=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],iT={icon:{width:"80px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"80px"}}},aT=({data:e,page:t,setPage:n,limit:r,setLimit:i})=>{const o=e.length,l=Math.ceil(o/r),u=d=>{n(1),i(Number(d))};if(o===0)return null;const c=l===1&&o<=10;return s.jsxs(a.Group,{pt:10,px:10,position:"apart",children:[s.jsxs(a.Group,{position:"left",children:[l>1&&s.jsx(a.Pagination,{size:"sm",value:t,onChange:n,total:l,withEdges:l>7,styles:{control:{height:"30px"}}}),!c&&s.jsx(a.Select,{icon:s.jsx(a.Text,{ta:"center",color:"dimmed",size:14,children:"Page Size"}),size:"xs",styles:iT,data:rT,value:String(r),onChange:u})]}),s.jsx(a.Group,{position:"right",children:s.jsxs(a.Text,{color:"dimmed",my:0,size:14,children:["Total ",o," rows"]})})]})},oT=wd(({data:e,loading:t})=>{const[n,r]=g.useState(1),[i,o]=g.useState(20),l=g.useMemo(()=>{const u=(n-1)*i,c=u+i;return e.slice(u,c)},[e,n,i]);return s.jsxs(we,{children:[s.jsx(aT,{data:e,page:n,setPage:r,limit:i,setLimit:o}),s.jsxs(a.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[s.jsx(a.LoadingOverlay,{visible:t,overlayBlur:2}),s.jsx(Du,{data:l})]})]})}),lT=({queryID:e})=>{const t=pe(),{state:n,error:r}=t.getDataStuffByID(e),i=g.useMemo(()=>t.queries.findByID(e),[t,e]);return n==="loading"?null:r?s.jsx(a.Text,{mt:10,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:r}):i!=null&&i.stateMessage?s.jsx(a.Text,{mt:10,color:"gray",align:"center",children:i.stateMessage}):null},hi=S.observer(({id:e,moreActions:t,refreshOnMount:n})=>{const r=pe(),{data:i,state:o}=r.getDataStuffByID(e),l=o==="loading",u=g.useCallback(()=>{r.queries.refetchDataByQueryID(e)},[e,r]),c=()=>{r.queries.downloadDataByQueryID(e)};g.useEffect(()=>{n&&u()},[u,n]);const d=!Array.isArray(i)||i.length===0;return s.jsxs(a.Stack,{spacing:0,sx:{height:"100%",border:"1px solid #eee"},children:[s.jsxs(a.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Group,{position:"left",children:s.jsx(a.Text,{weight:500,children:"Preview Data"})}),s.jsxs(a.Group,{pr:15,children:[t,s.jsx(a.ActionIcon,{variant:"subtle",color:"blue",disabled:l,onClick:u,children:s.jsx(k.Refresh,{size:16})}),s.jsx(a.ActionIcon,{variant:"subtle",color:"blue",disabled:l||d,onClick:c,children:s.jsx(k.Download,{size:16})})]})]}),s.jsxs(a.Box,{pb:20,sx:{position:"relative",flexGrow:1,overflow:"auto"},children:[s.jsx(lT,{queryID:e}),s.jsx(oT,{data:i,loading:l})]})]})}),uT=S.observer(function(){const t=Z(),n=R(),{panel:r}=Be(),[i,o]=g.useState(!1),l=u=>{t.editor.setPath(["_QUERIES_",u])};return s.jsxs(s.Fragment,{children:[s.jsx(a.Drawer,{opened:i,onClose:()=>o(!1),title:"Choose queries",padding:"xl",size:500,zIndex:320,children:s.jsx(a.Checkbox.Group,{value:[...r.queryIDs],onChange:r.setQueryIDs,children:s.jsx(a.Stack,{spacing:"lg",children:n.queries.options.map(u=>s.jsx(a.Checkbox,{label:u.label,value:u.value},u.value))})})}),s.jsxs(a.Stack,{spacing:6,children:[s.jsx(a.Group,{position:"right",children:s.jsx(a.Button,{variant:"light",size:"sm",leftIcon:s.jsx(_.IconLine,{size:16}),onClick:()=>o(!0),children:"Click me to choose queries for this panel"})}),r.queryIDs.length===1&&s.jsx(hi,{id:r.queryIDs[0],moreActions:s.jsx(a.Tooltip,{label:"Open this query",children:s.jsx(a.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>l(r.queryIDs[0]),children:s.jsx(_.IconArrowCurveRight,{size:16})})})}),r.queryIDs.length>1&&s.jsxs(a.Tabs,{defaultValue:r.queryIDs[0],children:[s.jsx(a.Tabs.List,{children:r.queries.map(u=>s.jsx(a.Tabs.Tab,{value:u.id,children:u.name},u.id))}),r.queries.map(u=>s.jsx(a.Tabs.Panel,{value:u.id,children:s.jsx(hi,{id:u.id,moreActions:s.jsx(a.Tooltip,{label:"Open this query",children:s.jsx(a.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>l(u.id),children:s.jsx(_.IconArrowCurveRight,{size:16})})})})},u.id))]})]})]})}),cT=S.observer(()=>{const{panel:e}=ft();return s.jsx(we,{children:s.jsx(a.Box,{sx:{height:"100%",flexGrow:0,flexShrink:0,width:"600px"},children:s.jsxs(a.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:[s.jsxs(a.Group,{position:"apart",noWrap:!0,sx:{flexGrow:0,flexShrink:0},children:[s.jsx(a.Group,{children:s.jsx(si,{})}),s.jsx(a.Group,{grow:!0,position:"center",children:s.jsx(a.Text,{lineClamp:1,weight:"bold",children:e.title.show?e.name:""})}),s.jsx(a.Group,{position:"right",spacing:0,sx:{height:"28px"}})]}),s.jsx(a.Group,{px:5,pb:5,sx:{flexGrow:1,".panel-viz-section":{height:"calc(100% - 28px)"}},children:s.jsx(ri,{panel:e})})]})})})}),xi={name:"new_var",size:"1rem",weight:"initial",color:{type:"static",staticColor:"Red"},data_field:"",aggregation:{type:"sum",config:{},fallback:"0"},formatter:{output:"number",mantissa:0,trimMantissa:!1,average:!1}};class dT{constructor(t){L(this,"panel");L(this,"selected");this.panel=t,t.variables.length>0&&(this.selected=t.variables[0]),K.makeAutoObservable(this,{},{deep:!1,autoBind:!0})}get variables(){return this.panel.variables}get variableOptions(){return this.panel.variables.map(t=>({label:t.name,value:t.name,description:t.aggregation.type}))}addNew(){const t=this.panel.variables.filter(n=>n.name.startsWith(xi.name)).length;this.panel.addVariable(y.cloneDeep({...xi,name:`${xi.name}${t||""}`})),this.selected=y.last(this.panel.variables)}select(t){this.selected=t}selectByName(t){if(!t){console.warn("Unexpected null name when calling selectByName");return}const n=this.variables.find(r=>r.name===t);if(!n){console.error(`Variable by name[${t}] not found`);return}this.selected=n}remove(t){this.selected===t&&(this.selected=void 0);const n=this.panel.variables.indexOf(t);if(this.panel.removeVariable(t),!this.selected&&!y.isEmpty(this.panel.variables)){const r=Math.min(this.panel.variables.length-1,n);this.selected=this.panel.variables[r]}}}function pT(){const{panel:e}=Be();return V.useCreation(()=>new dT(e),[e])}function hT({label:e,value:t,onChange:n},r){const[i,o]=g.useState(Array.isArray(t)?[...t]:[]),l=g.useCallback(()=>{o(x=>[...x,""])},[o]),u=g.useCallback(x=>{o(m=>(m.splice(x,1),[...m]))},[o]),c=g.useMemo(()=>!y.isEqual(i,t),[i,t]),d=()=>{n(i.map(x=>x.toString()))},h=a.useMantineTheme(),p=g.useMemo(()=>Object.entries(h.colors).map(([x,m])=>m[6]),[h]);return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{position:"left",ref:r,children:[s.jsx(a.Text,{children:e}),s.jsx(a.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!c,onClick:d,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Group,{children:[i.map((x,m)=>s.jsx(a.ColorInput,{value:x,onChange:j=>{o(C=>(C.splice(m,1,j),[...C]))},swatches:p,rightSection:s.jsx(a.ActionIcon,{onClick:()=>u(m),color:"red",children:s.jsx(k.Trash,{size:14})}),sx:{width:"45%"}})),s.jsx(a.ActionIcon,{onClick:l,color:"blue",variant:"outline",children:s.jsx(k.PlaylistAdd,{size:20})})]})]})}const xT=g.forwardRef(hT);function fT({label:e,value:t,onChange:n,type:r},i){const[o,l]=g.useState(Array.isArray(t)?[...t]:[]),u=g.useCallback(()=>{l(p=>[...p,""])},[l]),c=g.useCallback(p=>{l(x=>(x.splice(p,1),[...x]))},[l]),d=g.useMemo(()=>!y.isEqual(o.map(String),t.map(String)),[o,t]),h=()=>{n(o.map(p=>r==="number"?Number(p):p.toString()))};return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{position:"left",ref:i,children:[s.jsx(a.Text,{children:e}),s.jsx(a.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!d,onClick:h,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Group,{children:[o.map((p,x)=>s.jsx(a.TextInput,{type:r,value:p,onChange:m=>{const j=m.currentTarget.value;l(C=>(C.splice(x,1,j),[...C]))},rightSection:s.jsx(a.ActionIcon,{onClick:()=>c(x),color:"red",children:s.jsx(k.Trash,{size:14})}),sx:{width:"45%"}})),s.jsx(a.ActionIcon,{onClick:u,color:"blue",variant:"outline",children:s.jsx(k.PlaylistAdd,{size:20})})]})]})}const gT=g.forwardRef(fT),mT=g.forwardRef(function({value:t,onChange:n},r){const i=t.color.type,o=(u,c)=>{const d=y.cloneDeep(t);y.set(d,u,c),n(d)},l=u=>{if(u==="static"){n({...t,color:{type:"static",staticColor:"#25262B"}});return}n({...t,color:{type:"continuous",colorRange:[],valueRange:[]}})};return s.jsxs(s.Fragment,{children:[s.jsx(a.Stack,{children:s.jsx(a.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1},value:t.size,onChange:u=>o("size",u.currentTarget.value)})}),s.jsx(a.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:s.jsx(Qo,{label:"Font Weight",value:t.weight,onChange:u=>o("weight",u)})}),s.jsx(a.Divider,{mt:"lg",mb:0,variant:"dashed",label:"Style",labelPosition:"center"}),s.jsxs(a.Stack,{children:[s.jsx(a.Select,{label:"Color Type",data:[{label:"Static Color",value:"static"},{label:"Continuous Color",value:"continuous"}],value:t.color.type,onChange:l}),i==="static"&&s.jsx(ke,{value:t.color.staticColor,onChange:u=>o("color.staticColor",u)}),i==="continuous"&&s.jsxs(s.Fragment,{children:[s.jsx(gT,{label:"Value Range",value:t.color.valueRange,type:"number",onChange:u=>o("color.valueRange",u)}),s.jsx(xT,{label:"Color Range",value:t.color.colorRange,onChange:u=>o("color.colorRange",u)})]})]})]})}),yT=g.forwardRef(function({value:t,onChange:n,withStyle:r=!0,remove:i},o){const l=(u,c)=>{const d=y.cloneDeep(t);y.set(d,u,c),n(d)};return s.jsxs(a.Stack,{ref:o,children:[s.jsxs(a.Stack,{spacing:"xs",px:"sm",py:"md",sx:{border:"1px solid #e9ecef"},children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(a.TextInput,{label:"Name",required:!0,value:t.name,onChange:u=>l("name",u.currentTarget.value)}),s.jsx(O,{label:"Data Field",required:!0,value:t.data_field,onChange:u=>l("data_field",u)})]}),s.jsx(rr,{label:"Aggregation",pt:0,value:t.aggregation,onChange:u=>l("aggregation",u),withFallback:!0}),t.aggregation.type!=="custom"&&s.jsxs(s.Fragment,{children:[s.jsx(a.Divider,{mt:"xl",mb:0,label:"Format",labelPosition:"center",variant:"dashed"}),s.jsx(Fe,{value:t.formatter,onChange:u=>l("formatter",u)})]})]}),r&&s.jsx(a.Accordion,{variant:"contained",children:s.jsxs(a.Accordion.Item,{value:"Styles",children:[s.jsx(a.Accordion.Control,{icon:s.jsx(a.Text,{size:"xl",children:"🖼️"}),children:"Styles"}),s.jsx(a.Accordion.Panel,{children:s.jsx(mT,{value:t,onChange:n})})]})}),s.jsx(a.Button,{mt:20,leftIcon:s.jsx(_.IconTrash,{size:16}),color:"red",variant:"light",onClick:i,children:"Delete this Variable"})]})}),bT=S.observer(e=>{const t=V.useCreation(()=>Wl(e.variable),[e.variable]),n=()=>e.uiModel.remove(e.variable);return s.jsxs(a.Stack,{"data-testid":"variable-editor",align:"stretch",children:[s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{variant:"subtle",size:"xs",disabled:!t.changed,color:"red",onClick:t.reset,leftIcon:s.jsx(_.IconRecycle,{size:18}),children:"Revert Changes"}),s.jsx(a.Button,{variant:"filled",size:"xs",disabled:!t.changed,color:"green",onClick:t.commit,leftIcon:s.jsx(_.IconDeviceFloppy,{size:18}),children:"Save Changes"})]}),s.jsx(yT,{value:f.getSnapshot(t.copy),onChange:t.update,remove:n})]})});S.observer(e=>{const{uiModel:t}=e;return s.jsx(a.Stack,{className:"var-list",children:t.variables.map(n=>s.jsx(a.Button,{variant:t.selected===n?"filled":"subtle",color:"gray",onClick:()=>t.select(n),children:n.name},n.name))})});const jT=S.observer(({model:e})=>s.jsx(a.Overlay,{color:"#fff",opacity:1,sx:{position:"absolute"},children:s.jsx(a.Button,{variant:"light",size:"xs",leftIcon:s.jsx(_.IconPlus,{size:16}),onClick:e.addNew,sx:{flexGrow:0,flexShrink:0,alignSelf:"flex-end",height:"38px"},children:"Add a Variable"})})),vT=S.observer(()=>{var t;const e=pT();return e.variableOptions.length===0?s.jsx(jT,{model:e}):s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{position:"left",children:[s.jsx(a.Select,{label:"Variables",data:e.variableOptions,value:(t=e.selected)==null?void 0:t.name,onChange:e.selectByName,maxDropdownHeight:600,sx:{flexGrow:1}}),s.jsx(a.Button,{variant:"light",size:"xs",leftIcon:s.jsx(_.IconPlus,{size:16}),onClick:e.addNew,sx:{flexGrow:0,flexShrink:0,alignSelf:"flex-end",height:"38px"},children:"Add a Variable"})]}),s.jsx(a.Divider,{variant:"dashed"}),e.selected?s.jsx(bT,{uiModel:e,variable:e.selected}):s.jsx("span",{children:"Select or create a new variable on right side"})]})}),wT=S.observer(()=>{const{panel:e}=Be();return Object.keys(e.variableStrings).length===0?null:s.jsxs(a.Stack,{mt:22,spacing:4,children:[s.jsx(a.Text,{size:"sm",fw:500,color:"dimmed",children:"Variables"}),s.jsx(pt.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(e.variableStrings,null,4)})]})});function CT(){const{vizManager:e}=g.useContext(tt);return g.useMemo(()=>{const t=e.availableVizList.map(n=>({value:n.name,label:n.displayName??n.name,group:n.displayGroup??""}));return y.orderBy(t,[n=>n.group,n=>n.label],["asc","asc"])},[e])}const ST=S.observer(({value:e,submit:t})=>{const[n,r]=oe.useInputState(e);g.useEffect(()=>{r(e)},[e]);const i=CT(),o=e!==n;return s.jsx(a.Select,{label:"Visualization",value:n,searchable:!0,onChange:r,data:i,rightSection:s.jsx(a.ActionIcon,{disabled:!o,onClick:()=>t(n),children:s.jsx(k.DeviceFloppy,{size:20})}),maxDropdownHeight:600})}),Iu=[];function _T(e,t){try{return e.resolveComponent(t).createConfig()}catch{return null}}function kT(){const{data:e,panel:{variables:t,viz:n,title:r,name:i,queryIDs:o,description:l,id:u}}=Be(),{vizManager:c}=g.useContext(tt),d={name:i,title:r,description:l,viz:n,queryIDs:o,id:u},h=Ql(d);try{return c.resolveComponent(d.viz.type),s.jsx(Jn,{configure:h,children:s.jsx(G1,{variables:t,setVizConf:n.setConf,panel:d,vizManager:c,data:e})})}catch(p){return console.info(y.get(p,"message")),null}}const TT=S.observer(()=>{const{data:e,panel:{viz:t}}=Be(),{vizManager:n}=g.useContext(tt),r=g.useCallback(d=>{if(d===t.type)return;const h=_T(n,d);t.setType(d),t.setConf(h||{})},[t.type]),i=d=>{try{t.setConf(JSON.parse(d))}catch(h){console.error(h)}},o=g.useMemo(()=>{var d;return(d=Iu.find(h=>h.value===t.type))==null?void 0:d.Panel},[t.type,Iu]),l=kT(),u=o?g.createElement(o,{data:e,conf:t.conf,setConf:t.setConf}):null,c=l||u;return s.jsxs(a.Stack,{align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[s.jsx(ST,{submit:r,value:t.type}),s.jsxs(we,{children:[s.jsx(a.Stack,{pb:10,sx:{flexGrow:1,maxHeight:"100%",overflow:"auto"},children:c}),!c&&s.jsx(a.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(t.conf,null,2),onChange:i})]})]})}),DT=S.observer(({panel:e,sourceViewID:t})=>{const n=R(),[r,i]=g.useState(t);g.useEffect(()=>{i(t)},[t]);const[o,{open:l,close:u}]=oe.useDisclosure(!1),c=()=>{e.moveToView(t,r),u()};return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{size:"xs",variant:"subtle",color:"blue",onClick:l,leftIcon:s.jsx(_.IconBoxMultiple,{size:14}),children:"Move into Another View"}),s.jsx(a.Modal,{opened:o,onClose:u,title:"Move panel into another view",zIndex:320,children:s.jsxs(a.Stack,{sx:{maxHeight:"calc(100vh - 185px)",overflow:"hidden"},children:[s.jsx(a.Radio.Group,{value:r,onChange:i,pb:10,sx:{flexGrow:1,maxHeight:"calc(100vh - 185px - 30px)",overflow:"auto"},children:s.jsx(a.Stack,{spacing:"xs",children:n.views.options.map(d=>s.jsx(a.Radio,{value:d.value,label:d.label},d.value))})}),s.jsxs(a.Group,{noWrap:!0,position:"apart",sx:{flexGrow:0,flexShrink:0},children:[s.jsx(a.Button,{size:"xs",color:"red",leftIcon:s.jsx(_.IconX,{size:14}),onClick:u,children:"Cancel"}),s.jsx(a.Button,{size:"xs",color:"blue",leftIcon:s.jsx(_.IconDeviceFloppy,{size:14}),onClick:c,disabled:r===t,children:"Confirm"})]})]})})]})}),IT={root:{flexGrow:1,width:"100%",minWidth:"1200px",overflow:"hidden"},panel:{width:"100%",minWidth:"1200px",height:"calc(100% - 44px)",padding:10,overflow:"auto"}},fi=({children:e})=>s.jsxs(a.Group,{noWrap:!0,grow:!0,position:"left",spacing:20,sx:{width:"100%",height:"100%",position:"relative"},children:[s.jsx(a.Box,{sx:{maxWidth:"calc(100% - 610px - 10px)",height:"100%",overflow:"auto"},children:e}),s.jsxs(a.Stack,{justify:"flex-start",sx:{alignSelf:"flex-start",width:"600px",flexGrow:0,flexShrink:0},children:[s.jsx(cT,{}),s.jsx(a.Box,{sx:{flexGrow:1},children:s.jsx(wT,{})})]})]});function MT(e){return!["richText","button"].includes(e)}const zT=S.observer(({panel:e})=>{const t=Le.useModals(),n=Z(),r=R(),[i,o]=g.useState("Data"),l=e.queries,c=MT(e.viz.type)&&e.dataLoading,d=c||e.queryErrors.length>0||e.queryStateMessages!==""||l.length===0,h=n.editor.path[1];g.useEffect(()=>{o(m=>d&&m==="Visualization"?"Data":m)},[e.id,d]);const p=()=>{n.editor.setPath(["_VIEWS_",h])},x=()=>t.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.removePanelByID(e.id,h),p()},confirmProps:{color:"red"},zIndex:320});return s.jsxs(Ds,{value:{panel:e,data:e.data,loading:c,errors:e.queryErrors,downloadPanelScreenshot:()=>{}},children:[s.jsxs(a.Group,{px:16,position:"apart",sx:{borderBottom:"1px solid #eee"},children:[s.jsx(a.Text,{pt:9,pb:8,children:e.name}),s.jsxs(a.Group,{position:"right",noWrap:!0,children:[s.jsx(DT,{panel:e,sourceViewID:h}),s.jsx(a.Button,{size:"xs",variant:"subtle",color:"red",onClick:x,leftIcon:s.jsx(_.IconTrash,{size:14}),children:"Delete This Panel"})]})]}),s.jsxs(a.Tabs,{value:i,onTabChange:o,keepMounted:!1,styles:IT,children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"Data",disabled:c,children:"Data"}),s.jsx(a.Tabs.Tab,{value:"Panel",children:"Panel"}),s.jsx(a.Tabs.Tab,{value:"Variables",disabled:d,children:s.jsx(a.Tooltip,{label:"Requires data",disabled:!d,withinPortal:!0,zIndex:310,children:s.jsx(a.Text,{children:"Variables"})})}),s.jsx(a.Tabs.Tab,{value:"Visualization",disabled:d,children:s.jsx(a.Tooltip,{label:"Requires data",disabled:!d,withinPortal:!0,zIndex:310,children:s.jsx(a.Text,{children:"Visualization"})})}),s.jsx(a.Tabs.Tab,{value:"Interactions",children:"Interactions"})]}),s.jsxs(a.Tabs.Panel,{value:"Data",children:[s.jsx(a.LoadingOverlay,{visible:c,exitTransitionDuration:0}),s.jsx(uT,{})]}),s.jsx(a.Tabs.Panel,{value:"Panel",children:s.jsx(fi,{children:s.jsx(nT,{})})}),s.jsx(a.Tabs.Panel,{value:"Variables",children:s.jsx(fi,{children:s.jsx(vT,{})})}),s.jsx(a.Tabs.Panel,{value:"Visualization",children:s.jsx(we,{children:s.jsx(fi,{children:s.jsx(TT,{})})})}),s.jsx(a.Tabs.Panel,{value:"Interactions",children:s.jsx(we,{children:s.jsx(Fp,{})})})]})]})}),AT=S.observer(({viewID:e,panelID:t})=>{const n=R();if(!n.views.findByID(e))return s.jsxs(a.Text,{size:14,children:["View by ID[",e,"] is not found"]});const i=n.panels.findByID(t);return i?s.jsx(zT,{panel:i}):s.jsxs(a.Text,{size:14,children:["Panel by ID[",t,"] is not found"]})}),ET=S.observer(()=>{const[e,t]=g.useState([]),n=Le.useModals(),r=Z(),i=p=>{r.editor.setPath(["_QUERIES_",p])},o=()=>{n.openConfirmModal({title:"Delete ununsed queries?",children:s.jsx(a.Text,{size:"sm",children:"This action cannot be undone."}),labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>r.content.removeUnusedQueries(),confirmProps:{color:"red"},zIndex:320})},l=()=>{r.content.queries.downloadSchema(e)},u=g.useMemo(()=>r.content.queries.sortedList.map(p=>p.id),[r.content.queries.sortedList]),c=()=>{t(u)},d=()=>{t([])},h=r.content.queriesUsage;return s.jsxs(a.Stack,{sx:{height:"100%"},spacing:"sm",pb:"59px",children:[s.jsx(a.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:s.jsx(a.Text,{px:"md",align:"left",sx:{userSelect:"none",cursor:"default"},children:"Manage Queries"})}),s.jsxs(a.Flex,{justify:"space-between",align:"center",px:12,children:[s.jsxs(a.Group,{position:"left",children:[s.jsxs(a.Button.Group,{children:[s.jsx(a.Button,{variant:"default",size:"xs",onClick:c,children:"Select All"}),s.jsx(a.Button,{variant:"default",size:"xs",onClick:d,children:"Clear Selection"})]}),s.jsx(a.Button,{size:"xs",color:"blue",leftIcon:s.jsx(_.IconCode,{size:14}),disabled:e.length===0,onClick:l,children:"Download Schema"})]}),s.jsx(a.Button,{variant:"subtle",size:"xs",color:"red",leftIcon:s.jsx(_.IconTrash,{size:14}),disabled:!r.content.hasUnusedQueries,onClick:o,children:"Delete unused queries"})]}),s.jsx(a.Box,{sx:{flexGrow:1,overflow:"auto"},children:s.jsx(a.Checkbox.Group,{size:"xs",value:e,onChange:t,children:s.jsxs(a.Table,{fontSize:"sm",highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"40px"}}),s.jsx("th",{children:"Name"}),s.jsx("th",{style:{width:"200px"},children:"Data Source"}),s.jsx("th",{style:{width:"100px",textAlign:"right"},children:"Type"}),s.jsx("th",{style:{width:"100px",textAlign:"center"},children:"Usage"}),s.jsx("th",{style:{width:"300px",paddingLeft:"24px"},children:"Action"})]})}),s.jsx("tbody",{children:r.content.queries.sortedList.map(p=>{var m;const x=((m=h[p.id])==null?void 0:m.length)??0;return s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx(a.Checkbox,{value:p.id,styles:{input:{cursor:"pointer"}}})}),s.jsx("td",{children:p.name}),s.jsx("td",{children:p.key}),s.jsx("td",{style:{textAlign:"right"},children:p.type}),s.jsx("td",{style:{color:x===0?"#ff0000":"#000",fontWeight:x===0?"bold":"normal",textAlign:"center"},children:x}),s.jsx("td",{children:s.jsx(a.Button,{variant:"subtle",size:"xs",onClick:()=>i(p.id),children:"Open"})})]},p.id)})})]})})})]})}),LT=e=>{const{queryModel:t}=e,n=Z(),r=R(),o=r.findQueryUsage(t.id).length>0,l=Le.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?s.jsx(a.Tooltip,{label:"Can't delete this query for it's being used, check out Usage tab for details",withArrow:!0,events:{hover:!0,focus:!1,touch:!1},withinPortal:!0,children:s.jsx(a.Button,{color:"gray",size:"xs",leftIcon:s.jsx(_.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})}):s.jsx(a.Button,{color:"red",size:"xs",onClick:u,leftIcon:s.jsx(_.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})},PT=S.observer(LT),Mu=({width:e="calc(100% - 32px)",lastWidth:t="50%",height:n,count:r,spacing:i=16,pl:o=0})=>s.jsxs(a.Stack,{spacing:i,mt:6,pl:o,children:[Array.from(new Array(r-1),(l,u)=>s.jsx(a.Skeleton,{width:e,height:n,radius:"xs"},u)),s.jsx(a.Skeleton,{width:t,height:n,radius:"xs"})]}),cn=({value:e})=>e===null||e===""?null:s.jsx(a.Tooltip,{label:e,disabled:!e,multiline:!0,children:s.jsx(a.ActionIcon,{children:s.jsx(_.IconInfoCircle,{size:14})})}),BT=({column:e})=>{const{column_key:t,column_key_text:n}=e;return t?s.jsx(a.Tooltip,{label:n,disabled:!n,children:s.jsx(a.Badge,{children:t})}):null},OT=S.observer(({dataSource:e})=>{const{columns:t}=e;return t.loading?s.jsx(Mu,{height:"24px",width:"100%",lastWidth:"100%",count:20,pl:6}):t.empty?null:s.jsxs(a.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"1000px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[s.jsxs("colgroup",{children:[s.jsx("col",{style:{width:50}}),s.jsx("col",{style:{minWidth:300}}),s.jsx("col",{style:{width:30}}),s.jsx("col",{style:{width:70}}),s.jsx("col",{style:{minWidth:300}}),s.jsx("col",{style:{minWidth:80,width:80}}),s.jsx("col",{style:{minWidth:120,width:120}})]}),s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"#"}),s.jsx("th",{children:"Column Name"}),s.jsx("th",{}),s.jsx("th",{}),s.jsx("th",{children:"Type"}),s.jsx("th",{children:"Nullable"}),s.jsx("th",{children:"Default Value"})]})}),s.jsx("tbody",{children:t.data.map(n=>s.jsxs("tr",{children:[s.jsx("td",{children:n.ordinal_position}),s.jsx("td",{children:n.column_name}),s.jsx("td",{children:s.jsx(cn,{value:n.column_comment})}),s.jsx("td",{children:s.jsx(BT,{column:n})}),s.jsx("td",{children:n.column_type}),s.jsx("td",{children:n.is_nullable}),s.jsx("td",{children:s.jsx(cn,{value:n.column_default})})]},n.column_name))})]})}),$T=S.observer(({dataSource:e})=>{const{indexes:t}=e,n=t.data;return s.jsxs(a.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"950px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[s.jsxs("colgroup",{children:[s.jsx("col",{style:{width:100}}),s.jsx("col",{style:{minWidth:300}}),s.jsx("col",{style:{width:150}}),s.jsx("col",{style:{width:150}}),s.jsx("col",{style:{width:250}})]}),s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Index Length"}),s.jsx("th",{children:"Index Name"}),s.jsx("th",{children:"Index Algorithm"}),s.jsx("th",{children:"Unique"}),s.jsx("th",{children:"Column Name"})]})}),s.jsx("tbody",{children:n.map(r=>s.jsxs("tr",{children:[s.jsx("td",{children:r.index_length}),s.jsx("td",{children:r.index_name}),s.jsx("td",{children:r.index_algorithm}),s.jsx("td",{children:r.is_unique?"YES":"NO"}),s.jsx("td",{children:r.column_name})]},r.index_name))})]})}),VT=S.observer(({dataSource:e})=>{const{indexes:t}=e,n=t.data;return s.jsxs(a.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"850px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[s.jsxs("colgroup",{children:[s.jsx("col",{style:{minWidth:300}}),s.jsx("col",{style:{width:150}}),s.jsx("col",{style:{width:100}}),s.jsx("col",{style:{width:100}}),s.jsx("col",{style:{width:100}}),s.jsx("col",{style:{width:100}})]}),s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Index Name"}),s.jsx("th",{children:"Index Algorithm"}),s.jsx("th",{children:"Unique"}),s.jsx("th",{children:"Definition"}),s.jsx("th",{children:"Condition"}),s.jsx("th",{children:"Comment"})]})}),s.jsx("tbody",{children:n.map(r=>s.jsxs("tr",{children:[s.jsx("td",{children:r.index_name}),s.jsx("td",{children:r.index_algorithm}),s.jsx("td",{children:r.is_unique?"YES":"NO"}),s.jsx("td",{children:s.jsx(cn,{value:r.index_definition})}),s.jsx("td",{children:s.jsx(cn,{value:r.condition})}),s.jsx("td",{children:s.jsx(cn,{value:r.comment})})]},r.index_name))})]})}),qT=S.observer(({dataSource:e})=>{const{indexes:t}=e;return t.loading||t.empty?null:e.type===ce.MySQL?s.jsx($T,{dataSource:e}):e.type===ce.Postgresql?s.jsx(VT,{dataSource:e}):null}),NT=S.observer(({dataSource:e})=>s.jsxs(a.Stack,{spacing:40,pt:10,sx:{flexGrow:1,overflow:"auto",position:"relative"},children:[s.jsx(we,{children:s.jsx(OT,{dataSource:e})}),s.jsx(we,{children:s.jsx(qT,{dataSource:e})})]}));function FT({table_type:e}){return e==="VIEW"?s.jsx(_.IconEye,{size:14}):e==="BASE TABLE"?s.jsx(_.IconTable,{size:14}):null}const GT=S.observer(({dataSource:e})=>{const{tables:t}=e;return t.loading?s.jsx(Mu,{height:"24px",lastWidth:"50%",count:15}):s.jsx(a.Box,{h:"100%",sx:{overflow:"auto",".mantine-NavLink-label":{fontFamily:"monospace"}},children:Object.entries(t.data).map(([n,r])=>s.jsx(a.NavLink,{label:n,icon:s.jsx(_.IconDatabase,{size:14}),defaultOpened:e.table_schema===n,pl:0,childrenOffset:14,children:r.map(i=>s.jsx(a.NavLink,{label:i.table_name,icon:s.jsx(FT,{table_type:i.table_type}),onClick:()=>{e.setKeywords(n,i.table_name)},active:e.table_name===i.table_name},i.table_name))},n))})}),WT=({visible:e})=>s.jsx(a.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:s.jsx(a.LoadingOverlay,{visible:e})}),RT=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],QT={icon:{width:"50px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"50px"}}},UT=S.observer(({dataSource:e})=>{const{tableData:t}=e;return s.jsxs(a.Group,{pt:10,px:10,position:"apart",children:[s.jsxs(a.Group,{position:"left",children:[t.maxPage>1&&s.jsx(a.Pagination,{size:"sm",value:t.page,onChange:t.setPage,total:t.maxPage,withEdges:t.maxPage>7,styles:{control:{height:"30px"}}}),s.jsx(a.Select,{icon:s.jsx(a.Text,{ta:"center",color:"dimmed",size:14,children:"Limit"}),size:"xs",styles:QT,data:RT,value:String(t.limit),onChange:n=>t.setLimit(Number(n))})]}),s.jsx(a.Group,{position:"right",children:s.jsxs(a.Text,{color:"dimmed",my:0,size:14,children:["Total ",t.total," rows"]})})]})}),KT=S.observer(({dataSource:e})=>{const t=e.tableData;return t.maxPage===0?s.jsx(a.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:"This table is empty"}):t.error?s.jsx(a.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:t.error}):t.page===1&&t.loading?s.jsx(WT,{visible:!0}):s.jsxs(we,{children:[s.jsx(UT,{dataSource:e}),s.jsxs(a.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[s.jsx(a.LoadingOverlay,{visible:t.loading,overlayBlur:2}),s.jsx(Du,{data:t.data})]})]})}),YT={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},XT=S.observer(({dataSource:e})=>(g.useEffect(()=>{e.loadTablesIfEmpty()},[e]),e.tables.error?s.jsx(a.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:e.tables.error}):s.jsxs(a.Flex,{sx:{height:"100%"},children:[s.jsx(a.Box,{w:300,sx:{flexGrow:0,flexShrink:0,position:"relative"},children:s.jsx(we,{children:s.jsx(GT,{dataSource:e})})}),s.jsxs(a.Tabs,{defaultValue:"structure",styles:YT,children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"structure",icon:s.jsx(_.IconColumns,{size:14}),children:"Structure"}),s.jsx(a.Tabs.Tab,{value:"data",icon:s.jsx(_.IconDatabase,{size:14}),children:"Data"})]}),s.jsx(a.Tabs.Panel,{value:"structure",children:s.jsx(NT,{dataSource:e})}),s.jsx(a.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:s.jsx(KT,{dataSource:e})})]})]}))),JT={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"}},zu=S.observer(({dataSource:e,triggerButtonProps:t={}})=>{const[n,r]=g.useState(!1);return e.type==="http"?null:s.jsxs(s.Fragment,{children:[s.jsx(a.Modal,{opened:n,onClose:()=>r(!1),title:s.jsxs(a.Group,{position:"apart",sx:{flexGrow:1},children:[s.jsx(a.Text,{fw:500,children:"Explorer Data Source"}),s.jsxs(a.Group,{spacing:7,children:[s.jsx(a.Badge,{variant:"gradient",gradient:{from:"indigo",to:"cyan"},children:e.key}),s.jsx(a.Badge,{variant:"gradient",gradient:{from:"orange",to:"red"},children:e.type})]})]}),zIndex:320,size:"96vw",styles:JT,children:s.jsx(a.Box,{sx:{height:"calc(100vh - 220px)"},children:s.jsx(XT,{dataSource:e})})}),s.jsx(a.Button,{variant:"subtle",onClick:()=>r(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},...t,children:"See Table Structure"})]})}),ZT=g.forwardRef(({label:e,type:t,...n},r)=>t===ce.Transform?s.jsxs(a.Group,{className:"transform-query-option",position:"left",ref:r,...n,sx:{'&[data-selected="true"]':{".mantine-Text-root":{color:"white"},svg:{stroke:"white"}}},children:[s.jsx(_.IconVectorTriangle,{size:14,color:"#228be6"}),s.jsx(a.Text,{color:"blue",children:e})]}):s.jsxs(a.Group,{position:"apart",ref:r,...n,children:[s.jsx(a.Text,{children:e}),s.jsx(a.Text,{children:t})]})),HT=S.observer(({value:e,onChange:t})=>{const n=Z(),{data:r=[],loading:i}=V.useRequest(vs,{refreshDeps:[]},[]),o=g.useMemo(()=>{const d=r.map(h=>({label:h.key,value:h.key,type:h.type}));return d.push({label:"Use other queries' data",value:ce.Transform,type:ce.Transform}),d},[r]),l=g.useMemo(()=>o.reduce((d,h)=>(d[h.value]=h.type,d),{}),[o]),u=d=>{d!==null&&t({key:d,type:l[d]})},c=g.useMemo(()=>n.datasources.find(e),[n,e]);return s.jsx(a.Select,{data:o,label:s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Box,{children:"Data Source"}),c&&s.jsx(zu,{dataSource:c,triggerButtonProps:{compact:!0,size:"xs",px:10}})]}),itemComponent:ZT,rightSection:c?s.jsx(a.Text,{size:"xs",color:"dimmed",children:c.type}):void 0,rightSectionWidth:85,maxDropdownHeight:500,styles:{root:{flex:1},label:{display:"block"},rightSection:{pointerEvents:"none",justifyContent:"flex-end",paddingRight:"10px",".mantine-Text-root":{userSelect:"none"}}},disabled:i,value:e.key,onChange:u})}),Au=g.forwardRef((e,t)=>{const{label:n,description:r,...i}=e;return s.jsx("div",{ref:t,...i,children:s.jsxs(a.Group,{position:"apart",noWrap:!0,children:[s.jsx(a.Text,{children:n}),s.jsx(a.Text,{size:"xs",color:"dimmed",children:r})]})})}),eD=S.observer(({queryModel:e})=>{const[t,n]=g.useState(e.name);return g.useEffect(()=>{n(e.name)},[e.name]),s.jsx(a.Center,{ml:20,mt:20,sx:{maxWidth:"600px"},children:s.jsxs(a.Stack,{spacing:10,sx:{width:"100%"},children:[s.jsx(a.Divider,{mb:-10,variant:"dashed",label:"Basics",labelPosition:"center"}),s.jsx(a.TextInput,{placeholder:"A unique name",label:"Name",required:!0,sx:{flex:1},value:t,onChange:r=>{n(r.currentTarget.value)},rightSection:s.jsx(a.ActionIcon,{variant:"filled",color:"blue",size:"sm",onClick:()=>e.setName(t),disabled:t===e.name,children:s.jsx(_.IconDeviceFloppy,{size:16})}),onBlur:()=>{e.setName(t)}}),s.jsx(HT,{value:{type:e.type,key:e.key},onChange:({type:r,key:i})=>{e.setKey(i),e.setType(r)}}),s.jsx(a.Divider,{mt:10,mb:-10,variant:"dashed",label:"Conditions",labelPosition:"center"}),s.jsx(a.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:Au,maxDropdownHeight:500}),e.typedAsHTTP&&s.jsx(a.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:Au,maxDropdownHeight:500}),s.jsx(a.Divider,{mt:20,mb:10,variant:"dashed"}),s.jsx(PT,{queryModel:e})]})})});function tD({content:e}){return s.jsxs(a.HoverCard,{width:"60vw",shadow:"md",children:[s.jsx(a.HoverCard.Target,{children:s.jsx(a.ActionIcon,{size:16,color:"blue",children:s.jsx(_.IconEye,{})})}),s.jsx(a.HoverCard.Dropdown,{children:s.jsx(pt.Prism,{language:"sql",noCopy:!0,withLineNumbers:!0,children:e})})]})}const nD=S.observer(()=>{const t=[...Z().globalSQLSnippets.list];return t.length===0?null:s.jsxs(a.Table,{horizontalSpacing:"xs",verticalSpacing:"xs",fontSize:"sm",highlightOnHover:!0,children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Key"}),s.jsx("th",{children:"Value"})]})}),s.jsx("tbody",{children:t.map(n=>{const{id:r,content:i}=n;return s.jsxs("tr",{children:[s.jsx("td",{children:r}),s.jsx("td",{width:200,children:s.jsx(tD,{content:i})})]},r)})})]})}),sD=`
469
+ `,Gk=()=>{const[e,t]=g.useState(!1);return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"subtle",compact:!0,onClick:()=>t(n=>!n),children:e?"Close":"Click to see expected data structure"}),s.jsx(a.Collapse,{in:e,children:s.jsx(dt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:Fk})})]})},Wk=S.observer(function({filter:t}){const n=t.config;return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Checkbox,{checked:n.required,onChange:r=>n.setRequired(r.currentTarget.checked),label:"Required"}),s.jsx(Ft,{filter:t})]}),s.jsx(a.TextInput,{label:"Min-width",value:n.min_width,onChange:r=>n.setMinWidth(r.currentTarget.value),placeholder:"200px"}),s.jsx(a.Divider,{label:"Fetch options from database",labelPosition:"center"}),s.jsx(a.Checkbox,{checked:n.treeCheckStrictly,onChange:r=>n.setTreeCheckStrictly(r.currentTarget.checked),label:"Parent and children nodes are not associated"}),s.jsx(a.NumberInput,{value:n.default_selection_count,onChange:n.setDefaultSelectionCount,label:"Select first N options by default"}),s.jsx(di,{value:n.options_query_id,onChange:n.setOptionsQueryID}),s.jsx(Gk,{})]})}),Rk=S.observer(function({filter:t}){return s.jsxs(a.Box,{sx:{maxWidth:"480px"},children:[s.jsx(a.Text,{pt:"0",pb:"md",color:"gray",children:"Config"}),s.jsx(dt.Prism,{mt:22,language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(t,null,4)})]})}),Qk={select:qk,"multi-select":Vk,"tree-select":Wk,"text-input":Nk,checkbox:Lk,"date-range":Ok},mt={select:"Select","multi-select":"Multi Select","tree-select":"Tree Select","text-input":"Text Input",checkbox:"Checkbox","date-range":"Date Range"},Uk=[{label:mt.select,value:"select"},{label:mt["multi-select"],value:"multi-select"},{label:mt["tree-select"],value:"tree-select"},{label:mt["text-input"],value:"text-input"},{label:mt.checkbox,value:"checkbox"},{label:mt["date-range"],value:"date-range"}],Kk=S.observer(function({filter:t}){const n=W(),r=g.useMemo(()=>Qk[t.type],[t.type]);return s.jsxs(a.Group,{grow:!0,spacing:20,align:"top",children:[s.jsxs(a.Box,{sx:{maxWidth:"600px"},children:[s.jsx(a.Text,{pb:"md",color:"gray",children:"Edit"}),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{noWrap:!0,children:[s.jsx(a.NumberInput,{label:"Placement Order",required:!0,value:t.order,onChange:t.setOrder,hideControls:!0,sx:{flexGrow:"1 !important"}}),t.auto_submit_supported&&s.jsx(a.Checkbox,{label:"Submit automatically",checked:t.auto_submit,onChange:i=>t.setAutoSubmit(i.currentTarget.checked),mt:22})]}),s.jsx(a.MultiSelect,{label:"Visible in...",data:n.views.options,value:[...t.visibleInViewsIDs],onChange:t.setVisibleInViewsIDs}),s.jsx(a.TextInput,{label:"Key",placeholder:"A unique key to refer",required:!0,value:t.key,onChange:i=>{t.setKey(i.currentTarget.value)}}),s.jsx(a.TextInput,{label:"Label",placeholder:"Label for this field",required:!0,value:t.label,onChange:i=>{t.setLabel(i.currentTarget.value)}}),s.jsx(a.Select,{label:"Widget",data:Uk,required:!0,value:t.type,onChange:t.setType,maxDropdownHeight:500}),s.jsx(a.Divider,{mb:0,mt:10,variant:"dashed",label:`${mt[t.type]} Settings`,labelPosition:"center"}),s.jsx(r,{filter:t})]})]}),s.jsx(Rk,{filter:t})]})}),Yk=S.observer(({id:e})=>{const t=ze.useModals(),n=X(),r=W();if(e==="")return null;const i=r.filters.findByID(e);if(!i)return s.jsxs(a.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 s.jsxs(a.Stack,{sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",pb:30,children:[s.jsx(a.Group,{position:"right",pt:10,children:s.jsx(a.Button,{size:"xs",color:"red",leftIcon:s.jsx(k.Trash,{size:16}),onClick:l,children:"Delete this filter"})}),s.jsx(a.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:s.jsx(Kk,{filter:i})})]})}),Xk=S.observer(()=>{const[e,t]=g.useState([]),n=X(),r=u=>{n.editor.setPath(["_FILTERS_",u])},i=()=>{n.content.filters.downloadSchema(e)},o=g.useMemo(()=>n.content.filters.sortedList.map(u=>u.id),[n.content.filters.sortedList]),l=()=>{t(o)},c=()=>{t([])};return s.jsxs(a.Stack,{sx:{height:"100%"},spacing:"sm",pb:"59px",children:[s.jsx(a.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:s.jsx(a.Text,{px:"md",align:"left",sx:{userSelect:"none",cursor:"default"},children:"Manage Filters"})}),s.jsx(a.Flex,{justify:"space-between",align:"center",px:12,children:s.jsxs(a.Group,{position:"left",children:[s.jsxs(a.Button.Group,{children:[s.jsx(a.Button,{variant:"default",size:"xs",onClick:l,children:"Select All"}),s.jsx(a.Button,{variant:"default",size:"xs",onClick:c,children:"Clear Selection"})]}),s.jsx(a.Button,{size:"xs",color:"blue",leftIcon:s.jsx(_.IconCode,{size:14}),disabled:e.length===0,onClick:i,children:"Download Schema"})]})}),s.jsx(a.Box,{sx:{flexGrow:1,overflow:"auto"},children:s.jsx(a.Checkbox.Group,{size:"xs",value:e,onChange:t,children:s.jsxs(a.Table,{fontSize:"sm",highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"40px"}}),s.jsx("th",{style:{width:"300px"},children:"Label"}),s.jsx("th",{children:"Key"}),s.jsx("th",{style:{width:"100px"},children:"Widget"}),s.jsx("th",{style:{width:"300px",paddingLeft:"24px"},children:"Action"})]})}),s.jsx("tbody",{children:n.content.filters.sortedList.map(u=>s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx(a.Checkbox,{value:u.id,styles:{input:{cursor:"pointer"}}})}),s.jsx("td",{children:u.label}),s.jsx("td",{children:u.key}),s.jsx("td",{children:mt[u.type]}),s.jsx("td",{children:s.jsx(a.Button,{variant:"subtle",size:"xs",onClick:()=>r(u.id),children:"Open"})})]},u.id))})]})})})]})}),Jk=S.observer(()=>{const e=W(),[t,n]=g.useState(()=>JSON.stringify(e.mock_context.current,null,4)),r=()=>{try{e.mock_context.replace(JSON.parse(t))}catch(o){ut.showNotification({title:"Failed",message:o.message,color:"red"})}},i=g.useMemo(()=>{try{return JSON.stringify(JSON.parse(t))!==JSON.stringify(e.mock_context.current)}catch{return!1}},[t,e.mock_context.current]);return s.jsxs(a.Stack,{sx:{border:"1px solid #eee",borderLeft:"none",borderRight:"none",flexGrow:1,maxWidth:"unset"},children:[s.jsx(a.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:s.jsx(a.Text,{weight:500,children:"Mock Context"})}),s.jsxs(a.Group,{grow:!0,px:"md",pb:"md",pt:0,sx:{flexGrow:1,position:"relative",alignItems:"flex-start"},children:[s.jsxs(a.Stack,{spacing:10,sx:{maxWidth:"unset !important"},children:[s.jsx(a.Text,{children:"A valid json string is required"}),s.jsx(a.JsonInput,{validationError:"Invalid json",formatOnBlur:!0,autosize:!0,minRows:30,value:t,onChange:n,sx:{flexGrow:1}})]}),s.jsx(a.ActionIcon,{mr:5,variant:"filled",color:"blue",sx:{position:"absolute",right:12,top:0},disabled:!i,onClick:r,children:s.jsx(k.DeviceFloppy,{size:20})})]})]})}),Zk=S.observer(()=>{const{panel:e}=Ee();return s.jsx(ur,{label:"Description",value:e.description,onChange:e.setDescription,styles:{root:{flexGrow:1}}})}),Hk=S.observer(()=>{const{panel:e}=Ee(),t=ce().layouts.findItemByPanelID(e.id),{style:n}=e;return s.jsxs(s.Fragment,{children:[s.jsx(a.Divider,{mb:-10,label:"Style",labelPosition:"center",variant:"dashed"}),s.jsxs(a.Stack,{spacing:20,children:[s.jsxs(a.Group,{grow:!0,align:"top",children:[s.jsx(a.NumberInput,{label:"Width",min:1,max:36,step:1,precision:0,rightSection:s.jsx(a.Text,{size:12,children:"of 36 columns"}),styles:{rightSection:{width:"110px"}},value:t.w,onChange:r=>{r&&t.setWidth(r)}}),s.jsx(a.NumberInput,{label:"Height",rightSection:s.jsx(a.Text,{size:12,children:"px"}),styles:{rightSection:{width:"40px"}},value:t.h,onChange:r=>{r&&t.setHeight(r)}})]}),s.jsx(a.Checkbox,{ml:6,label:"Border",checked:n.border.enabled,onChange:r=>n.border.setEnabled(r.currentTarget.checked)})]})]})}),eT=()=>s.jsxs("span",{className:"mantine-103svbs mantine-InputWrapper-required mantine-Select-required","aria-hidden":"true",children:[" ","*"]}),tT=S.observer(()=>{const{panel:e}=Ee(),{name:t}=e,[n,r]=re.useInputState(t),i=t!==n,o=g.useCallback(()=>{i&&e.setName(n)},[i,n]);g.useEffect(()=>{r(t)},[t]);const l=!n.trim();return s.jsxs(a.Stack,{spacing:4,children:[s.jsxs(a.Group,{align:"center",children:[s.jsxs(a.Text,{size:14,fw:500,children:["Panel Name",s.jsx(eT,{})]}),s.jsx(a.ActionIcon,{variant:"subtle",color:"blue",disabled:!i||l,onClick:o,children:s.jsx(_.IconDeviceFloppy,{size:18})})]}),s.jsx(a.TextInput,{value:n,onChange:r,required:!0})]})}),nT=S.observer(()=>{const{panel:e}=Ee();return s.jsx(a.Stack,{spacing:6,mb:10,children:s.jsxs(a.Group,{pl:6,position:"left",spacing:20,children:[s.jsx(a.Checkbox,{size:"sm",checked:e.title.show,onChange:t=>e.title.setShow(t.currentTarget.checked),label:"Show Title",sx:{userSelect:"none"}}),s.jsx(a.Checkbox,{size:"sm",checked:!0,disabled:!0,label:"Use name as title"})]})})});function sT(){return s.jsxs(a.Stack,{sx:{height:"100%"},children:[s.jsx(Hk,{}),s.jsx(a.Divider,{label:"Info",labelPosition:"center",variant:"dashed"}),s.jsx(tT,{}),s.jsx(nT,{}),s.jsx(Zk,{})]})}const rT={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 Ic({data:e}){const t=g.useMemo(()=>{if(!Array.isArray(e)||e.length===0)return[];const r=Fe.createColumnHelper();return Object.keys(e[0]).map(i=>r.accessor(i,{cell:o=>o.getValue()}))},[e]),n=Fe.useReactTable({data:e,columns:t,columnResizeMode:"onChange",getCoreRowModel:Fe.getCoreRowModel()});return e.length===0?s.jsx(a.Box,{sx:{height:"5em"}}):s.jsx(je,{children:s.jsxs(a.Table,{sx:rT,children:[s.jsx("thead",{children:n.getHeaderGroups().map(r=>s.jsx("tr",{children:r.headers.map(i=>s.jsxs("th",{style:{width:i.getSize()},children:[i.isPlaceholder?null:Fe.flexRender(i.column.columnDef.header,i.getContext()),s.jsx(a.ActionIcon,{onMouseDown:i.getResizeHandler(),onTouchStart:i.getResizeHandler(),className:`resizer ${i.column.getIsResizing()?"isResizing":""}`,children:s.jsx(k.ArrowBarToRight,{})})]},i.id))},r.id))}),s.jsx("tbody",{children:n.getRowModel().rows.map(r=>s.jsx("tr",{children:r.getVisibleCells().map(i=>s.jsx("td",{children:s.jsx(je,{children:Fe.flexRender(i.column.columnDef.cell,i.getContext())})},i.id))},r.id))})]})})}const iT=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],aT={icon:{width:"80px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"80px"}}},oT=({data:e,page:t,setPage:n,limit:r,setLimit:i})=>{const o=e.length,l=Math.ceil(o/r),c=d=>{n(1),i(Number(d))};if(o===0)return null;const u=l===1&&o<=10;return s.jsxs(a.Group,{pt:10,px:10,position:"apart",children:[s.jsxs(a.Group,{position:"left",children:[l>1&&s.jsx(a.Pagination,{size:"sm",value:t,onChange:n,total:l,withEdges:l>7,styles:{control:{height:"30px"}}}),!u&&s.jsx(a.Select,{icon:s.jsx(a.Text,{ta:"center",color:"dimmed",size:14,children:"Page Size"}),size:"xs",styles:aT,data:iT,value:String(r),onChange:c})]}),s.jsx(a.Group,{position:"right",children:s.jsxs(a.Text,{color:"dimmed",my:0,size:14,children:["Total ",o," rows"]})})]})},lT=Cd(({data:e,loading:t})=>{const[n,r]=g.useState(1),[i,o]=g.useState(20),l=g.useMemo(()=>{const c=(n-1)*i,u=c+i;return e.slice(c,u)},[e,n,i]);return s.jsxs(je,{children:[s.jsx(oT,{data:e,page:n,setPage:r,limit:i,setLimit:o}),s.jsxs(a.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[s.jsx(a.LoadingOverlay,{visible:t,overlayBlur:2}),s.jsx(Ic,{data:l})]})]})}),cT=({queryID:e})=>{const t=ce(),{state:n,error:r}=t.getDataStuffByID(e),i=g.useMemo(()=>t.queries.findByID(e),[t,e]);return n==="loading"?null:r?s.jsx(a.Text,{mt:10,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:r}):i!=null&&i.stateMessage?s.jsx(a.Text,{mt:10,color:"gray",align:"center",children:i.stateMessage}):null},pi=S.observer(({id:e,moreActions:t,refreshOnMount:n})=>{const r=ce(),{data:i,state:o}=r.getDataStuffByID(e),l=o==="loading",c=g.useCallback(()=>{r.queries.refetchDataByQueryID(e)},[e,r]),u=()=>{r.queries.downloadDataByQueryID(e)};g.useEffect(()=>{n&&c()},[c,n]);const d=!Array.isArray(i)||i.length===0;return s.jsxs(a.Stack,{spacing:0,sx:{height:"100%",border:"1px solid #eee"},children:[s.jsxs(a.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Group,{position:"left",children:s.jsx(a.Text,{weight:500,children:"Preview Data"})}),s.jsxs(a.Group,{pr:15,children:[t,s.jsx(a.ActionIcon,{variant:"subtle",color:"blue",disabled:l,onClick:c,children:s.jsx(k.Refresh,{size:16})}),s.jsx(a.ActionIcon,{variant:"subtle",color:"blue",disabled:l||d,onClick:u,children:s.jsx(k.Download,{size:16})})]})]}),s.jsxs(a.Box,{pb:20,sx:{position:"relative",flexGrow:1,overflow:"auto"},children:[s.jsx(cT,{queryID:e}),s.jsx(lT,{data:i,loading:l})]})]})}),uT=S.observer(function(){const t=X(),n=W(),{panel:r}=Ee(),[i,o]=g.useState(!1),l=c=>{t.editor.setPath(["_QUERIES_",c])};return s.jsxs(s.Fragment,{children:[s.jsx(a.Drawer,{opened:i,onClose:()=>o(!1),title:"Choose queries",padding:"xl",size:500,zIndex:320,children:s.jsx(a.Checkbox.Group,{value:[...r.queryIDs],onChange:r.setQueryIDs,children:s.jsx(a.Stack,{spacing:"lg",children:n.queries.options.map(c=>s.jsx(a.Checkbox,{label:c.label,value:c.value},c.value))})})}),s.jsxs(a.Stack,{spacing:6,children:[s.jsx(a.Group,{position:"right",children:s.jsx(a.Button,{variant:"light",size:"sm",leftIcon:s.jsx(_.IconLine,{size:16}),onClick:()=>o(!0),children:"Click me to choose queries for this panel"})}),r.queryIDs.length===1&&s.jsx(pi,{id:r.queryIDs[0],moreActions:s.jsx(a.Tooltip,{label:"Open this query",children:s.jsx(a.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>l(r.queryIDs[0]),children:s.jsx(_.IconArrowCurveRight,{size:16})})})}),r.queryIDs.length>1&&s.jsxs(a.Tabs,{defaultValue:r.queryIDs[0],children:[s.jsx(a.Tabs.List,{children:r.queries.map(c=>s.jsx(a.Tabs.Tab,{value:c.id,children:c.name},c.id))}),r.queries.map(c=>s.jsx(a.Tabs.Panel,{value:c.id,children:s.jsx(pi,{id:c.id,moreActions:s.jsx(a.Tooltip,{label:"Open this query",children:s.jsx(a.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>l(c.id),children:s.jsx(_.IconArrowCurveRight,{size:16})})})})},c.id))]})]})]})}),dT=S.observer(()=>{const{panel:e}=xt();return s.jsx(je,{children:s.jsx(a.Box,{sx:{height:"100%",flexGrow:0,flexShrink:0,width:"600px"},children:s.jsxs(a.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:[s.jsxs(a.Group,{position:"apart",noWrap:!0,sx:{flexGrow:0,flexShrink:0},children:[s.jsx(a.Group,{children:s.jsx(ni,{})}),s.jsx(a.Group,{grow:!0,position:"center",children:s.jsx(a.Text,{lineClamp:1,weight:"bold",children:e.title.show?e.name:""})}),s.jsx(a.Group,{position:"right",spacing:0,sx:{height:"28px"}})]}),s.jsx(a.Group,{px:5,pb:5,sx:{flexGrow:1,".panel-viz-section":{height:"calc(100% - 28px)"}},children:s.jsx(si,{panel:e})})]})})})}),hi={name:"new_var",size:"1rem",weight:"initial",color:{type:"static",staticColor:"Red"},data_field:"",aggregation:{type:"sum",config:{},fallback:"0"},formatter:{output:"number",mantissa:0,trimMantissa:!1,average:!1}};class pT{constructor(t){P(this,"panel");P(this,"selected");this.panel=t,t.variables.length>0&&(this.selected=t.variables[0]),U.makeAutoObservable(this,{},{deep:!1,autoBind:!0})}get variables(){return this.panel.variables}get variableOptions(){return this.panel.variables.map(t=>({label:t.name,value:t.name,description:t.aggregation.type}))}addNew(){const t=this.panel.variables.filter(n=>n.name.startsWith(hi.name)).length;this.panel.addVariable(y.cloneDeep({...hi,name:`${hi.name}${t||""}`})),this.selected=y.last(this.panel.variables)}select(t){this.selected=t}selectByName(t){if(!t){console.warn("Unexpected null name when calling selectByName");return}const n=this.variables.find(r=>r.name===t);if(!n){console.error(`Variable by name[${t}] not found`);return}this.selected=n}remove(t){this.selected===t&&(this.selected=void 0);const n=this.panel.variables.indexOf(t);if(this.panel.removeVariable(t),!this.selected&&!y.isEmpty(this.panel.variables)){const r=Math.min(this.panel.variables.length-1,n);this.selected=this.panel.variables[r]}}}function hT(){const{panel:e}=Ee();return $.useCreation(()=>new pT(e),[e])}function xT({label:e,value:t,onChange:n},r){const[i,o]=g.useState(Array.isArray(t)?[...t]:[]),l=g.useCallback(()=>{o(x=>[...x,""])},[o]),c=g.useCallback(x=>{o(m=>(m.splice(x,1),[...m]))},[o]),u=g.useMemo(()=>!y.isEqual(i,t),[i,t]),d=()=>{n(i.map(x=>x.toString()))},h=a.useMantineTheme(),p=g.useMemo(()=>Object.entries(h.colors).map(([x,m])=>m[6]),[h]);return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{position:"left",ref:r,children:[s.jsx(a.Text,{children:e}),s.jsx(a.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!u,onClick:d,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Group,{children:[i.map((x,m)=>s.jsx(a.ColorInput,{value:x,onChange:j=>{o(C=>(C.splice(m,1,j),[...C]))},swatches:p,rightSection:s.jsx(a.ActionIcon,{onClick:()=>c(m),color:"red",children:s.jsx(k.Trash,{size:14})}),sx:{width:"45%"}})),s.jsx(a.ActionIcon,{onClick:l,color:"blue",variant:"outline",children:s.jsx(k.PlaylistAdd,{size:20})})]})]})}const fT=g.forwardRef(xT);function gT({label:e,value:t,onChange:n,type:r},i){const[o,l]=g.useState(Array.isArray(t)?[...t]:[]),c=g.useCallback(()=>{l(p=>[...p,""])},[l]),u=g.useCallback(p=>{l(x=>(x.splice(p,1),[...x]))},[l]),d=g.useMemo(()=>!y.isEqual(o.map(String),t.map(String)),[o,t]),h=()=>{n(o.map(p=>r==="number"?Number(p):p.toString()))};return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{position:"left",ref:i,children:[s.jsx(a.Text,{children:e}),s.jsx(a.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!d,onClick:h,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Group,{children:[o.map((p,x)=>s.jsx(a.TextInput,{type:r,value:p,onChange:m=>{const j=m.currentTarget.value;l(C=>(C.splice(x,1,j),[...C]))},rightSection:s.jsx(a.ActionIcon,{onClick:()=>u(x),color:"red",children:s.jsx(k.Trash,{size:14})}),sx:{width:"45%"}})),s.jsx(a.ActionIcon,{onClick:c,color:"blue",variant:"outline",children:s.jsx(k.PlaylistAdd,{size:20})})]})]})}const mT=g.forwardRef(gT),yT=g.forwardRef(function({value:t,onChange:n},r){const i=t.color.type,o=(c,u)=>{const d=y.cloneDeep(t);y.set(d,c,u),n(d)},l=c=>{if(c==="static"){n({...t,color:{type:"static",staticColor:"#25262B"}});return}n({...t,color:{type:"continuous",colorRange:[],valueRange:[]}})};return s.jsxs(s.Fragment,{children:[s.jsx(a.Stack,{children:s.jsx(a.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1},value:t.size,onChange:c=>o("size",c.currentTarget.value)})}),s.jsx(a.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:s.jsx(Uo,{label:"Font Weight",value:t.weight,onChange:c=>o("weight",c)})}),s.jsx(a.Divider,{mt:"lg",mb:0,variant:"dashed",label:"Style",labelPosition:"center"}),s.jsxs(a.Stack,{children:[s.jsx(a.Select,{label:"Color Type",data:[{label:"Static Color",value:"static"},{label:"Continuous Color",value:"continuous"}],value:t.color.type,onChange:l}),i==="static"&&s.jsx(Ce,{value:t.color.staticColor,onChange:c=>o("color.staticColor",c)}),i==="continuous"&&s.jsxs(s.Fragment,{children:[s.jsx(mT,{label:"Value Range",value:t.color.valueRange,type:"number",onChange:c=>o("color.valueRange",c)}),s.jsx(fT,{label:"Color Range",value:t.color.colorRange,onChange:c=>o("color.colorRange",c)})]})]})]})}),bT=g.forwardRef(function({value:t,onChange:n,withStyle:r=!0,remove:i},o){const l=(c,u)=>{const d=y.cloneDeep(t);y.set(d,c,u),n(d)};return s.jsxs(a.Stack,{ref:o,children:[s.jsxs(a.Stack,{spacing:"xs",px:"sm",py:"md",sx:{border:"1px solid #e9ecef"},children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(a.TextInput,{label:"Name",required:!0,value:t.name,onChange:c=>l("name",c.currentTarget.value)}),s.jsx(B,{label:"Data Field",required:!0,value:t.data_field,onChange:c=>l("data_field",c)})]}),s.jsx(sr,{label:"Aggregation",pt:0,value:t.aggregation,onChange:c=>l("aggregation",c),withFallback:!0}),t.aggregation.type!=="custom"&&s.jsxs(s.Fragment,{children:[s.jsx(a.Divider,{mt:"xl",mb:0,label:"Format",labelPosition:"center",variant:"dashed"}),s.jsx(Ve,{value:t.formatter,onChange:c=>l("formatter",c)})]})]}),r&&s.jsx(a.Accordion,{variant:"contained",children:s.jsxs(a.Accordion.Item,{value:"Styles",children:[s.jsx(a.Accordion.Control,{icon:s.jsx(a.Text,{size:"xl",children:"🖼️"}),children:"Styles"}),s.jsx(a.Accordion.Panel,{children:s.jsx(yT,{value:t,onChange:n})})]})}),s.jsx(a.Button,{mt:20,leftIcon:s.jsx(_.IconTrash,{size:16}),color:"red",variant:"light",onClick:i,children:"Delete this Variable"})]})}),jT=S.observer(e=>{const t=$.useCreation(()=>Rl(e.variable),[e.variable]),n=()=>e.uiModel.remove(e.variable);return s.jsxs(a.Stack,{"data-testid":"variable-editor",align:"stretch",children:[s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{variant:"subtle",size:"xs",disabled:!t.changed,color:"red",onClick:t.reset,leftIcon:s.jsx(_.IconRecycle,{size:18}),children:"Revert Changes"}),s.jsx(a.Button,{variant:"filled",size:"xs",disabled:!t.changed,color:"green",onClick:t.commit,leftIcon:s.jsx(_.IconDeviceFloppy,{size:18}),children:"Save Changes"})]}),s.jsx(bT,{value:f.getSnapshot(t.copy),onChange:t.update,remove:n})]})});S.observer(e=>{const{uiModel:t}=e;return s.jsx(a.Stack,{className:"var-list",children:t.variables.map(n=>s.jsx(a.Button,{variant:t.selected===n?"filled":"subtle",color:"gray",onClick:()=>t.select(n),children:n.name},n.name))})});const vT=S.observer(({model:e})=>s.jsx(a.Overlay,{color:"#fff",opacity:1,sx:{position:"absolute"},children:s.jsx(a.Button,{variant:"light",size:"xs",leftIcon:s.jsx(_.IconPlus,{size:16}),onClick:e.addNew,sx:{flexGrow:0,flexShrink:0,alignSelf:"flex-end",height:"38px"},children:"Add a Variable"})})),wT=S.observer(()=>{var t;const e=hT();return e.variableOptions.length===0?s.jsx(vT,{model:e}):s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{position:"left",children:[s.jsx(a.Select,{label:"Variables",data:e.variableOptions,value:(t=e.selected)==null?void 0:t.name,onChange:e.selectByName,maxDropdownHeight:600,sx:{flexGrow:1}}),s.jsx(a.Button,{variant:"light",size:"xs",leftIcon:s.jsx(_.IconPlus,{size:16}),onClick:e.addNew,sx:{flexGrow:0,flexShrink:0,alignSelf:"flex-end",height:"38px"},children:"Add a Variable"})]}),s.jsx(a.Divider,{variant:"dashed"}),e.selected?s.jsx(jT,{uiModel:e,variable:e.selected}):s.jsx("span",{children:"Select or create a new variable on right side"})]})}),CT=S.observer(()=>{const{panel:e}=Ee();return Object.keys(e.variableStrings).length===0?null:s.jsxs(a.Stack,{mt:22,spacing:4,children:[s.jsx(a.Text,{size:"sm",fw:500,color:"dimmed",children:"Variables"}),s.jsx(dt.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(e.variableStrings,null,4)})]})});function ST(){const{vizManager:e}=g.useContext(Ze);return g.useMemo(()=>{const t=e.availableVizList.map(n=>({value:n.name,label:n.displayName??n.name,group:n.displayGroup??""}));return y.orderBy(t,[n=>n.group,n=>n.label],["asc","asc"])},[e])}const _T=S.observer(({value:e,submit:t})=>{const[n,r]=re.useInputState(e);g.useEffect(()=>{r(e)},[e]);const i=ST(),o=e!==n;return s.jsx(a.Select,{label:"Visualization",value:n,searchable:!0,onChange:r,data:i,rightSection:s.jsx(a.ActionIcon,{disabled:!o,onClick:()=>t(n),children:s.jsx(k.DeviceFloppy,{size:20})}),maxDropdownHeight:600})}),Mc=[];function kT(e,t){try{return e.resolveComponent(t).createConfig()}catch{return null}}function TT(){const{data:e,panel:{variables:t,viz:n,title:r,name:i,queryIDs:o,description:l,id:c}}=Ee(),{vizManager:u}=g.useContext(Ze),d={name:i,title:r,description:l,viz:n,queryIDs:o,id:c},h=Ul(d);try{return u.resolveComponent(d.viz.type),s.jsx(Xn,{configure:h,children:s.jsx(W1,{variables:t,setVizConf:n.setConf,panel:d,vizManager:u,data:e})})}catch(p){return console.info(y.get(p,"message")),null}}const DT=S.observer(()=>{const{data:e,panel:{viz:t}}=Ee(),{vizManager:n}=g.useContext(Ze),r=g.useCallback(d=>{if(d===t.type)return;const h=kT(n,d);t.setType(d),t.setConf(h||{})},[t.type]),i=d=>{try{t.setConf(JSON.parse(d))}catch(h){console.error(h)}},o=g.useMemo(()=>{var d;return(d=Mc.find(h=>h.value===t.type))==null?void 0:d.Panel},[t.type,Mc]),l=TT(),c=o?g.createElement(o,{data:e,conf:t.conf,setConf:t.setConf}):null,u=l||c;return s.jsxs(a.Stack,{align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[s.jsx(_T,{submit:r,value:t.type}),s.jsxs(je,{children:[s.jsx(a.Stack,{pb:10,sx:{flexGrow:1,maxHeight:"100%",overflow:"auto"},children:u}),!u&&s.jsx(a.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(t.conf,null,2),onChange:i})]})]})}),IT=S.observer(({panel:e,sourceViewID:t})=>{const n=W(),[r,i]=g.useState(t);g.useEffect(()=>{i(t)},[t]);const[o,{open:l,close:c}]=re.useDisclosure(!1),u=()=>{e.moveToView(t,r),c()};return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{size:"xs",variant:"subtle",color:"blue",onClick:l,leftIcon:s.jsx(_.IconBoxMultiple,{size:14}),children:"Move into Another View"}),s.jsx(a.Modal,{opened:o,onClose:c,title:"Move panel into another view",zIndex:320,children:s.jsxs(a.Stack,{sx:{maxHeight:"calc(100vh - 185px)",overflow:"hidden"},children:[s.jsx(a.Radio.Group,{value:r,onChange:i,pb:10,sx:{flexGrow:1,maxHeight:"calc(100vh - 185px - 30px)",overflow:"auto"},children:s.jsx(a.Stack,{spacing:"xs",children:n.views.options.map(d=>s.jsx(a.Radio,{value:d.value,label:d.label},d.value))})}),s.jsxs(a.Group,{noWrap:!0,position:"apart",sx:{flexGrow:0,flexShrink:0},children:[s.jsx(a.Button,{size:"xs",color:"red",leftIcon:s.jsx(_.IconX,{size:14}),onClick:c,children:"Cancel"}),s.jsx(a.Button,{size:"xs",color:"blue",leftIcon:s.jsx(_.IconDeviceFloppy,{size:14}),onClick:u,disabled:r===t,children:"Confirm"})]})]})})]})}),MT={root:{flexGrow:1,width:"100%",minWidth:"1200px",overflow:"hidden"},panel:{width:"100%",minWidth:"1200px",height:"calc(100% - 44px)",padding:10,overflow:"auto"}},xi=({children:e})=>s.jsxs(a.Group,{noWrap:!0,grow:!0,position:"left",spacing:20,sx:{width:"100%",height:"100%",position:"relative"},children:[s.jsx(a.Box,{sx:{maxWidth:"calc(100% - 610px - 10px)",height:"100%",overflow:"auto"},children:e}),s.jsxs(a.Stack,{justify:"flex-start",sx:{alignSelf:"flex-start",width:"600px",flexGrow:0,flexShrink:0},children:[s.jsx(dT,{}),s.jsx(a.Box,{sx:{flexGrow:1},children:s.jsx(CT,{})})]})]});function zT(e){return!["richText","button"].includes(e)}const AT=S.observer(({panel:e})=>{const t=ze.useModals(),n=X(),r=W(),[i,o]=g.useState("Data"),l=e.queries,u=zT(e.viz.type)&&e.dataLoading,d=u||e.queryErrors.length>0||e.queryStateMessages!==""||l.length===0,h=n.editor.path[1];g.useEffect(()=>{o(m=>d&&m==="Visualization"?"Data":m)},[e.id,d]);const p=()=>{n.editor.setPath(["_VIEWS_",h])},x=()=>t.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.removePanelByID(e.id,h),p()},confirmProps:{color:"red"},zIndex:320});return s.jsxs(Ts,{value:{panel:e,data:e.data,loading:u,errors:e.queryErrors,downloadPanelScreenshot:()=>{}},children:[s.jsxs(a.Group,{px:16,position:"apart",sx:{borderBottom:"1px solid #eee"},children:[s.jsx(a.Text,{pt:9,pb:8,children:e.name}),s.jsxs(a.Group,{position:"right",noWrap:!0,children:[s.jsx(IT,{panel:e,sourceViewID:h}),s.jsx(a.Button,{size:"xs",variant:"subtle",color:"red",onClick:x,leftIcon:s.jsx(_.IconTrash,{size:14}),children:"Delete This Panel"})]})]}),s.jsxs(a.Tabs,{value:i,onTabChange:o,keepMounted:!1,styles:MT,children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"Data",disabled:u,children:"Data"}),s.jsx(a.Tabs.Tab,{value:"Panel",children:"Panel"}),s.jsx(a.Tabs.Tab,{value:"Variables",disabled:d,children:s.jsx(a.Tooltip,{label:"Requires data",disabled:!d,withinPortal:!0,zIndex:310,children:s.jsx(a.Text,{children:"Variables"})})}),s.jsx(a.Tabs.Tab,{value:"Visualization",disabled:d,children:s.jsx(a.Tooltip,{label:"Requires data",disabled:!d,withinPortal:!0,zIndex:310,children:s.jsx(a.Text,{children:"Visualization"})})}),s.jsx(a.Tabs.Tab,{value:"Interactions",children:"Interactions"})]}),s.jsxs(a.Tabs.Panel,{value:"Data",children:[s.jsx(a.LoadingOverlay,{visible:u,exitTransitionDuration:0}),s.jsx(uT,{})]}),s.jsx(a.Tabs.Panel,{value:"Panel",children:s.jsx(xi,{children:s.jsx(sT,{})})}),s.jsx(a.Tabs.Panel,{value:"Variables",children:s.jsx(xi,{children:s.jsx(wT,{})})}),s.jsx(a.Tabs.Panel,{value:"Visualization",children:s.jsx(je,{children:s.jsx(xi,{children:s.jsx(DT,{})})})}),s.jsx(a.Tabs.Panel,{value:"Interactions",children:s.jsx(je,{children:s.jsx(Gp,{})})})]})]})}),ET=S.observer(({viewID:e,panelID:t})=>{const n=W();if(!n.views.findByID(e))return s.jsxs(a.Text,{size:14,children:["View by ID[",e,"] is not found"]});const i=n.panels.findByID(t);return i?s.jsx(AT,{panel:i}):s.jsxs(a.Text,{size:14,children:["Panel by ID[",t,"] is not found"]})}),PT=S.observer(()=>{const[e,t]=g.useState([]),n=ze.useModals(),r=X(),i=p=>{r.editor.setPath(["_QUERIES_",p])},o=()=>{n.openConfirmModal({title:"Delete ununsed queries?",children:s.jsx(a.Text,{size:"sm",children:"This action cannot be undone."}),labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>r.content.removeUnusedQueries(),confirmProps:{color:"red"},zIndex:320})},l=()=>{r.content.queries.downloadSchema(e)},c=g.useMemo(()=>r.content.queries.sortedList.map(p=>p.id),[r.content.queries.sortedList]),u=()=>{t(c)},d=()=>{t([])},h=r.content.queriesUsage;return s.jsxs(a.Stack,{sx:{height:"100%"},spacing:"sm",pb:"59px",children:[s.jsx(a.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:s.jsx(a.Text,{px:"md",align:"left",sx:{userSelect:"none",cursor:"default"},children:"Manage Queries"})}),s.jsxs(a.Flex,{justify:"space-between",align:"center",px:12,children:[s.jsxs(a.Group,{position:"left",children:[s.jsxs(a.Button.Group,{children:[s.jsx(a.Button,{variant:"default",size:"xs",onClick:u,children:"Select All"}),s.jsx(a.Button,{variant:"default",size:"xs",onClick:d,children:"Clear Selection"})]}),s.jsx(a.Button,{size:"xs",color:"blue",leftIcon:s.jsx(_.IconCode,{size:14}),disabled:e.length===0,onClick:l,children:"Download Schema"})]}),s.jsx(a.Button,{variant:"subtle",size:"xs",color:"red",leftIcon:s.jsx(_.IconTrash,{size:14}),disabled:!r.content.hasUnusedQueries,onClick:o,children:"Delete unused queries"})]}),s.jsx(a.Box,{sx:{flexGrow:1,overflow:"auto"},children:s.jsx(a.Checkbox.Group,{size:"xs",value:e,onChange:t,children:s.jsxs(a.Table,{fontSize:"sm",highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"40px"}}),s.jsx("th",{children:"Name"}),s.jsx("th",{style:{width:"200px"},children:"Data Source"}),s.jsx("th",{style:{width:"100px",textAlign:"right"},children:"Type"}),s.jsx("th",{style:{width:"100px",textAlign:"center"},children:"Usage"}),s.jsx("th",{style:{width:"300px",paddingLeft:"24px"},children:"Action"})]})}),s.jsx("tbody",{children:r.content.queries.sortedList.map(p=>{var m;const x=((m=h[p.id])==null?void 0:m.length)??0;return s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx(a.Checkbox,{value:p.id,styles:{input:{cursor:"pointer"}}})}),s.jsx("td",{children:p.name}),s.jsx("td",{children:p.key}),s.jsx("td",{style:{textAlign:"right"},children:p.type}),s.jsx("td",{style:{color:x===0?"#ff0000":"#000",fontWeight:x===0?"bold":"normal",textAlign:"center"},children:x}),s.jsx("td",{children:s.jsx(a.Button,{variant:"subtle",size:"xs",onClick:()=>i(p.id),children:"Open"})})]},p.id)})})]})})})]})}),LT=e=>{const{queryModel:t}=e,n=X(),r=W(),o=r.findQueryUsage(t.id).length>0,l=ze.useModals(),c=()=>{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?s.jsx(a.Tooltip,{label:"Can't delete this query for it's being used, check out Usage tab for details",withArrow:!0,events:{hover:!0,focus:!1,touch:!1},withinPortal:!0,children:s.jsx(a.Button,{color:"gray",size:"xs",leftIcon:s.jsx(_.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})}):s.jsx(a.Button,{color:"red",size:"xs",onClick:c,leftIcon:s.jsx(_.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})},BT=S.observer(LT),zc=({width:e="calc(100% - 32px)",lastWidth:t="50%",height:n,count:r,spacing:i=16,pl:o=0})=>s.jsxs(a.Stack,{spacing:i,mt:6,pl:o,children:[Array.from(new Array(r-1),(l,c)=>s.jsx(a.Skeleton,{width:e,height:n,radius:"xs"},c)),s.jsx(a.Skeleton,{width:t,height:n,radius:"xs"})]}),cn=({value:e})=>e===null||e===""?null:s.jsx(a.Tooltip,{label:e,disabled:!e,multiline:!0,children:s.jsx(a.ActionIcon,{children:s.jsx(_.IconInfoCircle,{size:14})})}),OT=({column:e})=>{const{column_key:t,column_key_text:n}=e;return t?s.jsx(a.Tooltip,{label:n,disabled:!n,children:s.jsx(a.Badge,{children:t})}):null},$T=S.observer(({dataSource:e})=>{const{columns:t}=e;return t.loading?s.jsx(zc,{height:"24px",width:"100%",lastWidth:"100%",count:20,pl:6}):t.empty?null:s.jsxs(a.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"1000px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[s.jsxs("colgroup",{children:[s.jsx("col",{style:{width:50}}),s.jsx("col",{style:{minWidth:300}}),s.jsx("col",{style:{width:30}}),s.jsx("col",{style:{width:70}}),s.jsx("col",{style:{minWidth:300}}),s.jsx("col",{style:{minWidth:80,width:80}}),s.jsx("col",{style:{minWidth:120,width:120}})]}),s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"#"}),s.jsx("th",{children:"Column Name"}),s.jsx("th",{}),s.jsx("th",{}),s.jsx("th",{children:"Type"}),s.jsx("th",{children:"Nullable"}),s.jsx("th",{children:"Default Value"})]})}),s.jsx("tbody",{children:t.data.map(n=>s.jsxs("tr",{children:[s.jsx("td",{children:n.ordinal_position}),s.jsx("td",{children:n.column_name}),s.jsx("td",{children:s.jsx(cn,{value:n.column_comment})}),s.jsx("td",{children:s.jsx(OT,{column:n})}),s.jsx("td",{children:n.column_type}),s.jsx("td",{children:n.is_nullable}),s.jsx("td",{children:s.jsx(cn,{value:n.column_default})})]},n.column_name))})]})}),VT=S.observer(({dataSource:e})=>{const{indexes:t}=e,n=t.data;return s.jsxs(a.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"950px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[s.jsxs("colgroup",{children:[s.jsx("col",{style:{width:100}}),s.jsx("col",{style:{minWidth:300}}),s.jsx("col",{style:{width:150}}),s.jsx("col",{style:{width:150}}),s.jsx("col",{style:{width:250}})]}),s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Index Length"}),s.jsx("th",{children:"Index Name"}),s.jsx("th",{children:"Index Algorithm"}),s.jsx("th",{children:"Unique"}),s.jsx("th",{children:"Column Name"})]})}),s.jsx("tbody",{children:n.map(r=>s.jsxs("tr",{children:[s.jsx("td",{children:r.index_length}),s.jsx("td",{children:r.index_name}),s.jsx("td",{children:r.index_algorithm}),s.jsx("td",{children:r.is_unique?"YES":"NO"}),s.jsx("td",{children:r.column_name})]},r.index_name))})]})}),qT=S.observer(({dataSource:e})=>{const{indexes:t}=e,n=t.data;return s.jsxs(a.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"850px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[s.jsxs("colgroup",{children:[s.jsx("col",{style:{minWidth:300}}),s.jsx("col",{style:{width:150}}),s.jsx("col",{style:{width:100}}),s.jsx("col",{style:{width:100}}),s.jsx("col",{style:{width:100}}),s.jsx("col",{style:{width:100}})]}),s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Index Name"}),s.jsx("th",{children:"Index Algorithm"}),s.jsx("th",{children:"Unique"}),s.jsx("th",{children:"Definition"}),s.jsx("th",{children:"Condition"}),s.jsx("th",{children:"Comment"})]})}),s.jsx("tbody",{children:n.map(r=>s.jsxs("tr",{children:[s.jsx("td",{children:r.index_name}),s.jsx("td",{children:r.index_algorithm}),s.jsx("td",{children:r.is_unique?"YES":"NO"}),s.jsx("td",{children:s.jsx(cn,{value:r.index_definition})}),s.jsx("td",{children:s.jsx(cn,{value:r.condition})}),s.jsx("td",{children:s.jsx(cn,{value:r.comment})})]},r.index_name))})]})}),NT=S.observer(({dataSource:e})=>{const{indexes:t}=e;return t.loading||t.empty?null:e.type===oe.MySQL?s.jsx(VT,{dataSource:e}):e.type===oe.Postgresql?s.jsx(qT,{dataSource:e}):null}),FT=S.observer(({dataSource:e})=>s.jsxs(a.Stack,{spacing:40,pt:10,sx:{flexGrow:1,overflow:"auto",position:"relative"},children:[s.jsx(je,{children:s.jsx($T,{dataSource:e})}),s.jsx(je,{children:s.jsx(NT,{dataSource:e})})]}));function GT({table_type:e}){return e==="VIEW"?s.jsx(_.IconEye,{size:14}):e==="BASE TABLE"?s.jsx(_.IconTable,{size:14}):null}const WT=S.observer(({dataSource:e})=>{const{tables:t}=e;return t.loading?s.jsx(zc,{height:"24px",lastWidth:"50%",count:15}):s.jsx(a.Box,{h:"100%",sx:{overflow:"auto",".mantine-NavLink-label":{fontFamily:"monospace"}},children:Object.entries(t.data).map(([n,r])=>s.jsx(a.NavLink,{label:n,icon:s.jsx(_.IconDatabase,{size:14}),defaultOpened:e.table_schema===n,pl:0,childrenOffset:14,children:r.map(i=>s.jsx(a.NavLink,{label:i.table_name,icon:s.jsx(GT,{table_type:i.table_type}),onClick:()=>{e.setKeywords(n,i.table_name)},active:e.table_name===i.table_name},i.table_name))},n))})}),RT=({visible:e})=>s.jsx(a.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:s.jsx(a.LoadingOverlay,{visible:e})}),QT=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],UT={icon:{width:"50px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"50px"}}},KT=S.observer(({dataSource:e})=>{const{tableData:t}=e;return s.jsxs(a.Group,{pt:10,px:10,position:"apart",children:[s.jsxs(a.Group,{position:"left",children:[t.maxPage>1&&s.jsx(a.Pagination,{size:"sm",value:t.page,onChange:t.setPage,total:t.maxPage,withEdges:t.maxPage>7,styles:{control:{height:"30px"}}}),s.jsx(a.Select,{icon:s.jsx(a.Text,{ta:"center",color:"dimmed",size:14,children:"Limit"}),size:"xs",styles:UT,data:QT,value:String(t.limit),onChange:n=>t.setLimit(Number(n))})]}),s.jsx(a.Group,{position:"right",children:s.jsxs(a.Text,{color:"dimmed",my:0,size:14,children:["Total ",t.total," rows"]})})]})}),YT=S.observer(({dataSource:e})=>{const t=e.tableData;return t.maxPage===0?s.jsx(a.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:"This table is empty"}):t.error?s.jsx(a.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:t.error}):t.page===1&&t.loading?s.jsx(RT,{visible:!0}):s.jsxs(je,{children:[s.jsx(KT,{dataSource:e}),s.jsxs(a.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[s.jsx(a.LoadingOverlay,{visible:t.loading,overlayBlur:2}),s.jsx(Ic,{data:t.data})]})]})}),XT={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},JT=S.observer(({dataSource:e})=>(g.useEffect(()=>{e.loadTablesIfEmpty()},[e]),e.tables.error?s.jsx(a.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:e.tables.error}):s.jsxs(a.Flex,{sx:{height:"100%"},children:[s.jsx(a.Box,{w:300,sx:{flexGrow:0,flexShrink:0,position:"relative"},children:s.jsx(je,{children:s.jsx(WT,{dataSource:e})})}),s.jsxs(a.Tabs,{defaultValue:"structure",styles:XT,children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"structure",icon:s.jsx(_.IconColumns,{size:14}),children:"Structure"}),s.jsx(a.Tabs.Tab,{value:"data",icon:s.jsx(_.IconDatabase,{size:14}),children:"Data"})]}),s.jsx(a.Tabs.Panel,{value:"structure",children:s.jsx(FT,{dataSource:e})}),s.jsx(a.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:s.jsx(YT,{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"}},Ac=S.observer(({dataSource:e,triggerButtonProps:t={}})=>{const[n,r]=g.useState(!1);return e.type==="http"?null:s.jsxs(s.Fragment,{children:[s.jsx(a.Modal,{opened:n,onClose:()=>r(!1),title:s.jsxs(a.Group,{position:"apart",sx:{flexGrow:1},children:[s.jsx(a.Text,{fw:500,children:"Explorer Data Source"}),s.jsxs(a.Group,{spacing:7,children:[s.jsx(a.Badge,{variant:"gradient",gradient:{from:"indigo",to:"cyan"},children:e.key}),s.jsx(a.Badge,{variant:"gradient",gradient:{from:"orange",to:"red"},children:e.type})]})]}),zIndex:320,size:"96vw",styles:ZT,children:s.jsx(a.Box,{sx:{height:"calc(100vh - 220px)"},children:s.jsx(JT,{dataSource:e})})}),s.jsx(a.Button,{variant:"subtle",onClick:()=>r(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},...t,children:"See Table Structure"})]})}),HT=g.forwardRef(({label:e,type:t,...n},r)=>t===oe.Transform?s.jsxs(a.Group,{className:"transform-query-option",position:"left",ref:r,...n,sx:{'&[data-selected="true"]':{".mantine-Text-root":{color:"white"},svg:{stroke:"white"}}},children:[s.jsx(_.IconVectorTriangle,{size:14,color:"#228be6"}),s.jsx(a.Text,{color:"blue",children:e})]}):s.jsxs(a.Group,{position:"apart",ref:r,...n,children:[s.jsx(a.Text,{children:e}),s.jsx(a.Text,{children:t})]})),eD=S.observer(({value:e,onChange:t})=>{const n=X(),{data:r=[],loading:i}=$.useRequest(js,{refreshDeps:[]},[]),o=g.useMemo(()=>{const d=r.map(h=>({label:h.key,value:h.key,type:h.type}));return d.push({label:"Use other queries' data",value:oe.Transform,type:oe.Transform}),d},[r]),l=g.useMemo(()=>o.reduce((d,h)=>(d[h.value]=h.type,d),{}),[o]),c=d=>{d!==null&&t({key:d,type:l[d]})},u=g.useMemo(()=>n.datasources.find(e),[n,e]);return s.jsx(a.Select,{data:o,label:s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Box,{children:"Data Source"}),u&&s.jsx(Ac,{dataSource:u,triggerButtonProps:{compact:!0,size:"xs",px:10}})]}),itemComponent:HT,rightSection:u?s.jsx(a.Text,{size:"xs",color:"dimmed",children:u.type}):void 0,rightSectionWidth:85,maxDropdownHeight:500,styles:{root:{flex:1},label:{display:"block"},rightSection:{pointerEvents:"none",justifyContent:"flex-end",paddingRight:"10px",".mantine-Text-root":{userSelect:"none"}}},disabled:i,value:e.key,onChange:c})}),Ec=g.forwardRef((e,t)=>{const{label:n,description:r,...i}=e;return s.jsx("div",{ref:t,...i,children:s.jsxs(a.Group,{position:"apart",noWrap:!0,children:[s.jsx(a.Text,{children:n}),s.jsx(a.Text,{size:"xs",color:"dimmed",children:r})]})})}),tD=S.observer(({queryModel:e})=>{const[t,n]=g.useState(e.name);return g.useEffect(()=>{n(e.name)},[e.name]),s.jsx(a.Center,{ml:20,mt:20,sx:{maxWidth:"600px"},children:s.jsxs(a.Stack,{spacing:10,sx:{width:"100%"},children:[s.jsx(a.Divider,{mb:-10,variant:"dashed",label:"Basics",labelPosition:"center"}),s.jsx(a.TextInput,{placeholder:"A unique name",label:"Name",required:!0,sx:{flex:1},value:t,onChange:r=>{n(r.currentTarget.value)},rightSection:s.jsx(a.ActionIcon,{variant:"filled",color:"blue",size:"sm",onClick:()=>e.setName(t),disabled:t===e.name,children:s.jsx(_.IconDeviceFloppy,{size:16})}),onBlur:()=>{e.setName(t)}}),s.jsx(eD,{value:{type:e.type,key:e.key},onChange:({type:r,key:i})=>{e.setKey(i),e.setType(r)}}),s.jsx(a.Divider,{mt:10,mb:-10,variant:"dashed",label:"Conditions",labelPosition:"center"}),s.jsx(a.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:Ec,maxDropdownHeight:500}),e.typedAsHTTP&&s.jsx(a.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:Ec,maxDropdownHeight:500}),s.jsx(a.Divider,{mt:20,mb:10,variant:"dashed"}),s.jsx(BT,{queryModel:e})]})})});function nD({content:e}){return s.jsxs(a.HoverCard,{width:"60vw",shadow:"md",children:[s.jsx(a.HoverCard.Target,{children:s.jsx(a.ActionIcon,{size:16,color:"blue",children:s.jsx(_.IconEye,{})})}),s.jsx(a.HoverCard.Dropdown,{children:s.jsx(dt.Prism,{language:"sql",noCopy:!0,withLineNumbers:!0,children:e})})]})}const sD=S.observer(()=>{const t=[...X().globalSQLSnippets.list];return t.length===0?null:s.jsxs(a.Table,{horizontalSpacing:"xs",verticalSpacing:"xs",fontSize:"sm",highlightOnHover:!0,children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Key"}),s.jsx("th",{children:"Value"})]})}),s.jsx("tbody",{children:t.map(n=>{const{id:r,content:i}=n;return s.jsxs("tr",{children:[s.jsx("td",{children:r}),s.jsx("td",{width:200,children:s.jsx(nD,{content:i})})]},r)})})]})}),rD=`
470
470
  -- You may reference query variables in SQL or VizConfig.
471
471
  SELECT *
472
472
  FROM commit
@@ -479,9 +479,9 @@ WHERE
479
479
  AND \${sql_snippets.author_email_condition}
480
480
  -- Global SQL snippets (shared between dashboards)
481
481
  AND \${global_sql_snippets.account_condition}
482
- `,Eu=S.observer(function({showSQLSnippets:t=!0,sx:n={}}){const r=Z(),i=R(),o=r.context.current,l=(()=>{const u={context:{...i.mock_context.current,...o},filters:i.filters.previewValues};return t&&(u.sql_snippets=i.sqlSnippets.record),JSON.stringify(u,null,2)})();return s.jsx(a.Stack,{sx:{overflow:"hidden",...n},children:s.jsxs(a.Tabs,{defaultValue:"guide",keepMounted:!1,children:[s.jsxs(a.Tabs.List,{grow:!0,children:[s.jsx(a.Tabs.Tab,{value:"guide",icon:s.jsx(_.IconAlertCircle,{size:14}),children:"Guide"}),s.jsx(a.Tabs.Tab,{value:"local_query_vars",icon:s.jsx(_.IconVariable,{size:14}),children:"Variables in this dashboard"}),s.jsx(a.Tabs.Tab,{value:"global_sql_snippets",icon:s.jsx(_.IconVariablePlus,{size:14}),children:"Global SQL Snippets"})]}),s.jsx(a.Tabs.Panel,{value:"guide",pt:"xs",children:s.jsx(pt.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:sD})}),s.jsx(a.Tabs.Panel,{value:"local_query_vars",pt:"xs",children:s.jsx(pt.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:l})}),s.jsx(a.Tabs.Panel,{value:"global_sql_snippets",pt:"xs",children:s.jsxs(a.Stack,{spacing:10,children:[s.jsx(a.Alert,{icon:s.jsx(_.IconAlertCircle,{size:16}),title:"Global SQL Snippets",children:"SQL snippets worth sharing between dashboards are managed in System Settings by admins."}),s.jsx(nD,{})]})})]})})}),gi=S.observer(()=>{const[e,t]=g.useState(!1);return s.jsxs(s.Fragment,{children:[s.jsx(a.Modal,{opened:e,onClose:()=>t(!1),title:"Query Variables",zIndex:320,size:"800px",children:s.jsx(Eu,{})}),s.jsx(a.Button,{variant:"subtle",onClick:()=>t(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},children:"See Query Variables"})]})}),Lu={pre:["function build_request({ context, filters }, utils) {"," // build the quest"," return { method: 'POST', url: '/', params: {}, headers: {}, data: {} }","}"].join(`
482
+ `,Pc=S.observer(function({showSQLSnippets:t=!0,sx:n={}}){const r=X(),i=W(),o=r.context.current,l=(()=>{const c={context:{...i.mock_context.current,...o},filters:i.filters.previewValues};return t&&(c.sql_snippets=i.sqlSnippets.record),JSON.stringify(c,null,2)})();return s.jsx(a.Stack,{sx:{overflow:"hidden",...n},children:s.jsxs(a.Tabs,{defaultValue:"guide",keepMounted:!1,children:[s.jsxs(a.Tabs.List,{grow:!0,children:[s.jsx(a.Tabs.Tab,{value:"guide",icon:s.jsx(_.IconAlertCircle,{size:14}),children:"Guide"}),s.jsx(a.Tabs.Tab,{value:"local_query_vars",icon:s.jsx(_.IconVariable,{size:14}),children:"Variables in this dashboard"}),s.jsx(a.Tabs.Tab,{value:"global_sql_snippets",icon:s.jsx(_.IconVariablePlus,{size:14}),children:"Global SQL Snippets"})]}),s.jsx(a.Tabs.Panel,{value:"guide",pt:"xs",children:s.jsx(dt.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:rD})}),s.jsx(a.Tabs.Panel,{value:"local_query_vars",pt:"xs",children:s.jsx(dt.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:l})}),s.jsx(a.Tabs.Panel,{value:"global_sql_snippets",pt:"xs",children:s.jsxs(a.Stack,{spacing:10,children:[s.jsx(a.Alert,{icon:s.jsx(_.IconAlertCircle,{size:16}),title:"Global SQL Snippets",children:"SQL snippets worth sharing between dashboards are managed in System Settings by admins."}),s.jsx(sD,{})]})})]})})}),fi=S.observer(()=>{const[e,t]=g.useState(!1);return s.jsxs(s.Fragment,{children:[s.jsx(a.Modal,{opened:e,onClose:()=>t(!1),title:"Query Variables",zIndex:320,size:"800px",children:s.jsx(Pc,{})}),s.jsx(a.Button,{variant:"subtle",onClick:()=>t(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},children:"See Query Variables"})]})}),Lc={pre:["function build_request({ context, filters }, utils) {"," // build the quest"," return { method: 'POST', url: '/', params: {}, headers: {}, data: {} }","}"].join(`
483
483
  `),post:["function process_result(res, utils, state) {"," // your code goes here"," return data","}"].join(`
484
- `)},rD=S.observer(({queryModel:e})=>e.typedAsHTTP?s.jsxs(a.Tabs,{defaultValue:"pre_process",orientation:"vertical",sx:{flexGrow:1},children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"pre_process",children:"Build Request"}),s.jsx(a.Tabs.Tab,{value:"post_process",children:"Process Result"}),s.jsx(gi,{})]}),s.jsx(a.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:s.jsx($t,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:Lu.pre})}),s.jsx(a.Tabs.Panel,{value:"post_process",p:"sm",children:s.jsx($t,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:Lu.post})})]}):null),iD=S.observer(({queryID:e,usage:t})=>{const n=Z().editor,r=o=>{if(o.type==="filter"){n.setPath(["_FILTERS_",o.id]);return}if(o.type==="panel"){const l=o.views[0].id;n.setPath(["_VIEWS_",l,"_PANELS_",o.id]);return}},i=o=>{n.setPath(["_VIEWS_",o])};return s.jsx(a.Stack,{py:"sm",px:"md",children:s.jsxs(a.Table,{highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{style:{width:100},children:"Type"}),s.jsx("th",{style:{width:"calc(50% - 50px)"},children:"Name"}),s.jsx("th",{children:"In View(s)"})]})}),s.jsx("tbody",{children:t.map(o=>s.jsxs("tr",{children:[s.jsx("td",{children:y.capitalize(o.type)}),s.jsx("td",{children:s.jsx(a.Anchor,{component:"button",type:"button",onClick:()=>r(o),children:o.label})}),s.jsx("td",{children:s.jsxs(a.Stack,{align:"flex-start",justify:"flex-start",spacing:2,children:[o.views.map(l=>s.jsx(a.Anchor,{component:"button",type:"button",onClick:()=>i(l.id),children:s.jsx(a.Box,{children:l.label})},l.id)),o.views.length===0&&s.jsx(a.Box,{children:"--"})]})})]},o.id))})]})})}),mi=({value:e,onChange:t,height:n="200px",defaultLanguage:r="sql",theme:i="vs-dark"})=>{const o=u=>{t==null||t(u??"")},l=!t;return s.jsx(ye,{className:"minimal-monaco-editor",height:n,defaultLanguage:r,value:e,onChange:l?void 0:o,theme:i,options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1},readOnly:l||!t,"semanticHighlighting.enabled":!0}})},aD=S.observer(({queryModel:e})=>{const t=g.useMemo(()=>y.groupBy(e.dependencies,"type"),[e.dependencies]),n=g.useMemo(()=>e.dependencies.some(i=>!i.valid),[e.dependencies]),r=e.dependencies.length>0;return r?s.jsxs(a.HoverCard,{withinPortal:!0,zIndex:340,shadow:"md",disabled:!r,children:[s.jsx(a.HoverCard.Target,{children:s.jsx(a.Button,{size:"xs",variant:"subtle",color:n?"red":"green",disabled:!r,leftIcon:n?s.jsx(_.IconAlertTriangle,{size:16}):s.jsx(_.IconDiscountCheckFilled,{size:16}),children:"Dependency"})}),s.jsx(a.HoverCard.Dropdown,{children:s.jsx(a.List,{spacing:"md",size:14,listStyleType:"none",children:Object.entries(t).map(([i,o])=>s.jsxs(a.List.Item,{children:[s.jsx(a.Text,{fw:"bold",ff:"monospace",children:i}),s.jsx(a.List,{withPadding:!0,size:14,sx:{fontFamily:"monospace",svg:{verticalAlign:"middle"}},children:o.map(l=>s.jsx(a.List.Item,{icon:s.jsx(a.Box,{sx:{path:{fill:l.valid?"rgb(18, 184, 134)":"rgb(250, 82, 82)"}},children:s.jsx(_.IconPointFilled,{size:12})}),children:l.key},l.key))})]},i))})})]}):s.jsx(a.Tooltip,{label:"This query has no dependency",children:s.jsx(a.Button,{size:"xs",variant:"subtle",color:"gray",leftIcon:s.jsx(_.IconHierarchy,{size:16,style:{transform:"rotate(180deg)"}}),sx:{transform:"none !important"},children:"Dependency"})})}),oD="SELECT 1",lD=S.observer(({queryModel:e})=>{const[t,n]=g.useState(e.sql),r=()=>{e.setSQL(t)},i=()=>{n(e.sql)},o=()=>{n(oD)};g.useEffect(()=>{n(e.sql)},[e.sql]);const l=t!==e.sql;return s.jsxs(a.Stack,{spacing:4,sx:{height:"100%"},children:[s.jsxs(a.Group,{mb:6,position:"apart",sx:{flexShrink:0,flexGrow:0},children:[s.jsx(a.Group,{position:"left",children:s.jsx(aD,{queryModel:e})}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:o,size:"xs",variant:"default",leftIcon:s.jsx(_.IconPlayerSkipBack,{size:16}),children:"Reset to default"}),s.jsx(a.Button,{onClick:i,color:"red",size:"xs",disabled:!l,leftIcon:s.jsx(_.IconRecycle,{size:16}),children:"Revert Changes"}),s.jsx(a.Button,{size:"xs",onClick:r,disabled:!l,leftIcon:s.jsx(_.IconDeviceFloppy,{size:16}),children:"Confirm Changes"})]})]}),s.jsx(mi,{height:"100%",value:t,onChange:n,theme:"sql-dark",defaultLanguage:"sql"})]})}),uD=({value:e,height:t="200px",defaultLanguage:n="sql"})=>s.jsx(ye,{className:"preview-sql-in-monaco-editor",height:t,defaultLanguage:n,value:e,onChange:void 0,theme:"vs-light",options:{lineNumbers:"on",folding:!0,lineDecorationsWidth:20,wordWrap:"on",minimap:{enabled:!1},readOnly:!0}}),cD=S.observer(({value:e})=>{const n=pe().payloadForSQL,r=g.useMemo(()=>fs(e,n),[e,n]);return s.jsx(uD,{height:"100%",value:r})}),Pu={pre:["function process_request({ context, filters, sql }, utils) {"," // modify and return sql"," return sql","}"].join(`
484
+ `)},iD=S.observer(({queryModel:e})=>e.typedAsHTTP?s.jsxs(a.Tabs,{defaultValue:"pre_process",orientation:"vertical",sx:{flexGrow:1},children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"pre_process",children:"Build Request"}),s.jsx(a.Tabs.Tab,{value:"post_process",children:"Process Result"}),s.jsx(fi,{})]}),s.jsx(a.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:s.jsx(Ot,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:Lc.pre})}),s.jsx(a.Tabs.Panel,{value:"post_process",p:"sm",children:s.jsx(Ot,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:Lc.post})})]}):null),aD=S.observer(({queryID:e,usage:t})=>{const n=X().editor,r=o=>{if(o.type==="filter"){n.setPath(["_FILTERS_",o.id]);return}if(o.type==="panel"){const l=o.views[0].id;n.setPath(["_VIEWS_",l,"_PANELS_",o.id]);return}},i=o=>{n.setPath(["_VIEWS_",o])};return s.jsx(a.Stack,{py:"sm",px:"md",children:s.jsxs(a.Table,{highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{style:{width:100},children:"Type"}),s.jsx("th",{style:{width:"calc(50% - 50px)"},children:"Name"}),s.jsx("th",{children:"In View(s)"})]})}),s.jsx("tbody",{children:t.map(o=>s.jsxs("tr",{children:[s.jsx("td",{children:y.capitalize(o.type)}),s.jsx("td",{children:s.jsx(a.Anchor,{component:"button",type:"button",onClick:()=>r(o),children:o.label})}),s.jsx("td",{children:s.jsxs(a.Stack,{align:"flex-start",justify:"flex-start",spacing:2,children:[o.views.map(l=>s.jsx(a.Anchor,{component:"button",type:"button",onClick:()=>i(l.id),children:s.jsx(a.Box,{children:l.label})},l.id)),o.views.length===0&&s.jsx(a.Box,{children:"--"})]})})]},o.id))})]})})}),gi=({value:e,onChange:t,height:n="200px",defaultLanguage:r="sql",theme:i="vs-dark"})=>{const o=c=>{t==null||t(c??"")},l=!t;return s.jsx(fe,{className:"minimal-monaco-editor",height:n,defaultLanguage:r,value:e,onChange:l?void 0:o,theme:i,options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1},readOnly:l||!t,"semanticHighlighting.enabled":!0}})},oD=S.observer(({queryModel:e})=>{const t=g.useMemo(()=>y.groupBy(e.dependencies,"type"),[e.dependencies]),n=g.useMemo(()=>e.dependencies.some(i=>!i.valid),[e.dependencies]),r=e.dependencies.length>0;return r?s.jsxs(a.HoverCard,{withinPortal:!0,zIndex:340,shadow:"md",disabled:!r,children:[s.jsx(a.HoverCard.Target,{children:s.jsx(a.Button,{size:"xs",variant:"subtle",color:n?"red":"green",disabled:!r,leftIcon:n?s.jsx(_.IconAlertTriangle,{size:16}):s.jsx(_.IconDiscountCheckFilled,{size:16}),children:"Dependency"})}),s.jsx(a.HoverCard.Dropdown,{children:s.jsx(a.List,{spacing:"md",size:14,listStyleType:"none",children:Object.entries(t).map(([i,o])=>s.jsxs(a.List.Item,{children:[s.jsx(a.Text,{fw:"bold",ff:"monospace",children:i}),s.jsx(a.List,{withPadding:!0,size:14,sx:{fontFamily:"monospace",svg:{verticalAlign:"middle"}},children:o.map(l=>s.jsx(a.List.Item,{icon:s.jsx(a.Box,{sx:{path:{fill:l.valid?"rgb(18, 184, 134)":"rgb(250, 82, 82)"}},children:s.jsx(_.IconPointFilled,{size:12})}),children:l.key},l.key))})]},i))})})]}):s.jsx(a.Tooltip,{label:"This query has no dependency",children:s.jsx(a.Button,{size:"xs",variant:"subtle",color:"gray",leftIcon:s.jsx(_.IconHierarchy,{size:16,style:{transform:"rotate(180deg)"}}),sx:{transform:"none !important"},children:"Dependency"})})}),lD="SELECT 1",cD=S.observer(({queryModel:e})=>{const[t,n]=g.useState(e.sql),r=()=>{e.setSQL(t)},i=()=>{n(e.sql)},o=()=>{n(lD)};g.useEffect(()=>{n(e.sql)},[e.sql]);const l=t!==e.sql;return s.jsxs(a.Stack,{spacing:4,sx:{height:"100%"},children:[s.jsxs(a.Group,{mb:6,position:"apart",sx:{flexShrink:0,flexGrow:0},children:[s.jsx(a.Group,{position:"left",children:s.jsx(oD,{queryModel:e})}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:o,size:"xs",variant:"default",leftIcon:s.jsx(_.IconPlayerSkipBack,{size:16}),children:"Reset to default"}),s.jsx(a.Button,{onClick:i,color:"red",size:"xs",disabled:!l,leftIcon:s.jsx(_.IconRecycle,{size:16}),children:"Revert Changes"}),s.jsx(a.Button,{size:"xs",onClick:r,disabled:!l,leftIcon:s.jsx(_.IconDeviceFloppy,{size:16}),children:"Confirm Changes"})]})]}),s.jsx(gi,{height:"100%",value:t,onChange:n,theme:"sql-dark",defaultLanguage:"sql"})]})}),uD=({value:e,height:t="200px",defaultLanguage:n="sql"})=>s.jsx(fe,{className:"preview-sql-in-monaco-editor",height:t,defaultLanguage:n,value:e,onChange:void 0,theme:"vs-light",options:{lineNumbers:"on",folding:!0,lineDecorationsWidth:20,wordWrap:"on",minimap:{enabled:!1},readOnly:!0}}),dD=S.observer(({value:e})=>{const n=ce().payloadForSQL,r=g.useMemo(()=>xs(e,n),[e,n]);return s.jsx(uD,{height:"100%",value:r})}),Bc={pre:["function process_request({ context, filters, sql }, utils) {"," // modify and return sql"," return sql","}"].join(`
485
485
  `),post:["function process_result(data, utils, state) {"," // process data and return the result"," return data","}"].join(`
486
- `)},dD=S.observer(({queryModel:e})=>e.typedAsSQL?s.jsxs(a.Tabs,{defaultValue:"Edit",orientation:"vertical",sx:{flexGrow:1},styles:{tabLabel:{width:"100%",height:"28px",lineHeight:"28px"}},keepMounted:!1,children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"Edit",children:s.jsx(a.Group,{spacing:14,position:"apart",children:"Edit SQL"})}),s.jsx(a.Tabs.Tab,{value:"Preview",children:"Preview SQL"}),s.jsx(a.Tabs.Tab,{value:"pre_process",children:"Process Request"}),s.jsx(a.Tabs.Tab,{value:"post_process",children:"Process Result"}),s.jsx(gi,{}),e.datasource&&s.jsx(zu,{dataSource:e.datasource})]}),s.jsx(a.Tabs.Panel,{value:"Edit",sx:{position:"relative"},p:"sm",children:s.jsx(lD,{queryModel:e})}),s.jsx(a.Tabs.Panel,{value:"Preview",p:0,pl:4,children:s.jsx(cD,{value:e.sql})}),s.jsx(a.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:s.jsx($t,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:Pu.pre})}),s.jsx(a.Tabs.Panel,{value:"post_process",p:"sm",children:s.jsx($t,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:Pu.post})})]}):null),pD={pre:["function transform(queries, state, utils) {"," // use queries & dashboar state to build new data"," const data = []"," return data","}"].join(`
487
- `),post:""},hD=S.observer(({queryModel:e})=>{const t=R();return e.isTransform?s.jsxs(a.Stack,{py:20,px:20,sx:{height:"100%"},children:[s.jsx(a.Text,{size:"md",children:"Step 1: Pick queries for data input"}),s.jsx(a.MultiSelect,{data:t.queries.optionsWithoutTransform,value:[...e.dep_query_ids],onChange:e.setDependantQueryIDs,maxDropdownHeight:800}),s.jsx(a.Text,{size:"md",children:"Write a function for making new data"}),s.jsx(a.Box,{sx:{flexGrow:1},children:s.jsx($t,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:pD.pre})})]}):null}),dn={height:"calc(100% - 44px)",padding:0},xD=S.observer(({queryModel:e})=>{const t=R(),n=g.useMemo(()=>e.datasource?e.typedAsHTTP?"HTTP":"SQL":"Configurations",[e.datasource,e.typedAsHTTP]),[r,i]=g.useState(n);g.useEffect(()=>{i(u=>u!=="Configurations"&&n==="Configurations"?"Configurations":u)},[n]);const o=t.findQueryUsage(e.id),l=o.length===0;return s.jsxs(a.Tabs,{value:r,onTabChange:i,defaultValue:n,orientation:"horizontal",keepMounted:!1,sx:{height:"100vh"},children:[s.jsxs(a.Tabs.List,{grow:!0,children:[s.jsx(a.Tabs.Tab,{value:"Configurations",children:"Configurations"}),e.typedAsSQL&&s.jsx(a.Tabs.Tab,{value:"SQL",children:"Request"}),e.typedAsHTTP&&s.jsx(a.Tabs.Tab,{value:"HTTP",children:"Request"}),e.isTransform&&s.jsx(a.Tabs.Tab,{value:"Transform",children:"Transform"}),s.jsx(a.Tabs.Tab,{value:"Data",disabled:!e.canPreviewData,children:s.jsx(a.Tooltip,{label:e.guideToPreviewData,disabled:e.canPreviewData,withinPortal:!0,children:s.jsx(a.Text,{children:"Data"})})}),s.jsx(a.Tabs.Tab,{value:"Usage",disabled:l,children:s.jsx(a.Tooltip,{label:"This query is not used for any filter or panel",disabled:!l,withinPortal:!0,children:s.jsx(a.Text,{children:"Usage"})})})]}),s.jsx(a.Tabs.Panel,{value:"Configurations",pt:0,p:0,children:s.jsx(eD,{queryModel:e})}),e.typedAsSQL&&s.jsx(a.Tabs.Panel,{value:"SQL",sx:dn,children:s.jsx(a.Stack,{sx:{height:"100%"},children:s.jsx(dD,{queryModel:e})})}),e.typedAsHTTP&&s.jsx(a.Tabs.Panel,{value:"HTTP",sx:dn,children:s.jsx(a.Stack,{sx:{height:"100%"},children:s.jsx(rD,{queryModel:e})})}),e.isTransform&&s.jsx(a.Tabs.Panel,{value:"Transform",sx:dn,children:s.jsx(a.Stack,{sx:{height:"100%"},children:s.jsx(hD,{queryModel:e})})}),s.jsx(a.Tabs.Panel,{value:"Data",sx:{...dn,overflow:"hidden"},children:s.jsx(hi,{id:e.id,moreActions:null,refreshOnMount:!0})}),s.jsx(a.Tabs.Panel,{value:"Usage",sx:{...dn,overflow:"hidden"},children:s.jsx(iD,{queryID:e.id,usage:o})})]})}),fD=S.observer(({id:e})=>{const n=R().queries.findByID(e);return e===""?null:n?s.jsx(xD,{queryModel:n}):s.jsx(a.Text,{size:14,color:"red",children:"Invalid Query ID"})}),gD=S.observer(({value:e})=>{const n=pe().payloadForSQL,r=g.useMemo(()=>fs(e,n),[e,n]);return s.jsx(mi,{height:"100%",value:r})}),mD=S.observer(({item:e,remove:t,onKeyChanged:n})=>{const[r,i]=g.useState("SQL"),[o,l]=g.useState(e.key),u=()=>{e.setKey(o),n(o)},c=o!==e.key,d=e.isADuplicatedKey(o),[h,p]=g.useState(e.value),x=()=>{e.setValue(h)};g.useEffect(()=>{l(e.key),p(e.value)},[e]);const m=h!==e.value,j=Le.useModals(),C=()=>{j.openConfirmModal({title:"Delete this SQL snippet?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:t,confirmProps:{color:"red"},zIndex:320})};return s.jsxs(a.Stack,{p:20,sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",children:[s.jsxs(a.Group,{sx:{alignItems:"end"},spacing:40,children:[s.jsx(a.TextInput,{label:d?"This key is occupied by another snippet":"Key",value:o,onChange:T=>{l(T.currentTarget.value)},sx:{flexGrow:"1 !important"},rightSection:s.jsx(a.ActionIcon,{color:"blue",variant:"subtle",onClick:u,disabled:!c||d,children:s.jsx(k.DeviceFloppy,{size:16})}),error:d}),s.jsx(a.Button,{leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:C,children:"Delete this SQL Snippet"})]}),s.jsxs(a.Tabs,{value:r,onTabChange:i,sx:{flexGrow:1},styles:{panel:{height:"calc(100% - 50px)"}},children:[s.jsxs(a.Tabs.List,{sx:{position:"relative"},children:[s.jsx(a.Tabs.Tab,{value:"SQL",children:"SQL"}),s.jsx(a.Tabs.Tab,{value:"Preview",children:"Preview"}),s.jsx(gi,{}),s.jsx(a.ActionIcon,{color:"blue",variant:"filled",onClick:x,disabled:!m,sx:{position:"absolute",top:0,right:10},children:s.jsx(k.DeviceFloppy,{size:18})})]}),s.jsx(a.Tabs.Panel,{value:"SQL",pt:"sm",children:s.jsx(mi,{height:"100%",value:h,onChange:p,defaultLanguage:"sql",theme:"sql-dark"})}),s.jsx(a.Tabs.Panel,{value:"Preview",pt:"sm",children:s.jsx(gD,{value:h})})]})]})}),yD=S.observer(({id:e})=>{const t=Z(),n=R(),r=g.useMemo(()=>n.sqlSnippets.findByKey(e),[e]);if(!e)return null;if(!r)return s.jsxs(a.Text,{size:14,children:["SQL Snippet by key[",e,"] is not found"]});const i=()=>{t.editor.setPath(["_SQL_SNIPPETS_",""])},o=()=>{n.sqlSnippets.removeByKey(e),i()},l=u=>{t.editor.setPath(["_SQL_SNIPPETS_",u])};return s.jsx(mD,{item:r,remove:o,onKeyChanged:l})}),bD=S.observer(()=>{const[e,t]=g.useState([]),n=Le.useModals(),r=Z(),i=p=>{r.editor.setPath(["_SQL_SNIPPETS_",p])},o=()=>{n.openConfirmModal({title:"Delete ununsed SQL snippets?",children:s.jsx(a.Text,{size:"sm",children:"This action cannot be undone."}),labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>r.content.removeUnusedSQLSnippets(),confirmProps:{color:"red"},zIndex:320})},l=()=>{r.content.sqlSnippets.downloadSchema(e)},u=g.useMemo(()=>r.content.sqlSnippets.sortedList.map(p=>p.key),[r.content.sqlSnippets.sortedList]),c=()=>{t(u)},d=()=>{t([])},h=r.content.sqlSnippetsUsage;return s.jsxs(a.Stack,{sx:{height:"100%"},spacing:"sm",pb:"59px",children:[s.jsx(a.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:s.jsx(a.Text,{px:"md",align:"left",sx:{userSelect:"none",cursor:"default"},children:"Manage SQL Snippets"})}),s.jsxs(a.Flex,{justify:"space-between",align:"center",px:12,children:[s.jsxs(a.Group,{position:"left",children:[s.jsxs(a.Button.Group,{children:[s.jsx(a.Button,{variant:"default",size:"xs",onClick:c,children:"Select All"}),s.jsx(a.Button,{variant:"default",size:"xs",onClick:d,children:"Clear Selection"})]}),s.jsx(a.Button,{size:"xs",color:"blue",leftIcon:s.jsx(_.IconCode,{size:14}),disabled:e.length===0,onClick:l,children:"Download Schema"})]}),s.jsx(a.Button,{variant:"subtle",size:"xs",color:"red",leftIcon:s.jsx(_.IconTrash,{size:14}),disabled:!r.content.hasUnusedSQLSnippets,onClick:o,children:"Delete unused SQL snippets"})]}),s.jsx(a.Box,{sx:{flexGrow:1,overflow:"auto"},children:s.jsx(a.Checkbox.Group,{size:"xs",value:e,onChange:t,children:s.jsxs(a.Table,{fontSize:"sm",highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"40px"}}),s.jsx("th",{children:"Key"}),s.jsx("th",{style:{width:"100px",textAlign:"center"},children:"Usage"}),s.jsx("th",{style:{width:"300px",paddingLeft:"24px"},children:"Action"})]})}),s.jsx("tbody",{children:r.content.sqlSnippets.sortedList.map(p=>{var m;const x=((m=h[p.key])==null?void 0:m.length)??0;return s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx(a.Checkbox,{value:p.key,styles:{input:{cursor:"pointer"}}})}),s.jsx("td",{children:p.key}),s.jsx("td",{style:{color:x===0?"#ff0000":"#000",fontWeight:x===0?"bold":"normal",textAlign:"center"},children:x}),s.jsx("td",{children:s.jsx(a.Button,{variant:"subtle",size:"xs",onClick:()=>i(p.key),children:"Open"})})]},p.key)})})]})})})]})}),jD=S.observer(({id:e})=>{const t=Le.useModals(),n=Z(),r=R();if(e==="")return null;const i=r.views.findByID(e);if(!i)return s.jsxs(a.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 s.jsxs(a.Stack,{sx:{maxWidth:"600px",height:"100%"},spacing:"sm",children:[s.jsx(a.Group,{position:"right",pt:10,children:s.jsx(a.Button,{size:"xs",color:"red",leftIcon:s.jsx(k.Trash,{size:16}),onClick:l,children:"Delete this view"})}),s.jsx(a.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:s.jsx(Q_,{view:i})})]})});function vD(e){return e.length===1&&e[0]==="_QUERY_VARS_"}function wD(e){return e.length===1&&e[0]==="_MOCK_CONTEXT_"}function CD(e){return e.length===1&&e[0]==="_FILTERS_"}function SD(e){return e.length===2&&e[0]==="_FILTERS_"}function _D(e){return e.length===1&&e[0]==="_SQL_SNIPPETS_"}function kD(e){return e.length===2&&e[0]==="_SQL_SNIPPETS_"}function TD(e){return e.length===2&&e[0]==="_QUERIES_"}function DD(e){return e.length===1&&e[0]==="_QUERIES_"}function ID(e){return e.length===2&&e[0]==="_VIEWS_"}function MD(e){return e.length===4&&e[0]==="_VIEWS_"&&e[2]==="_PANELS_"}const zD=S.observer(()=>s.jsx(a.Stack,{sx:{height:"100%"},p:"sm",children:s.jsx(Eu,{})})),AD=S.observer(()=>{const e=Z().editor,t=e.path;return vD(t)?s.jsx(zD,{}):wD(t)?s.jsx(Xk,{}):CD(t)?s.jsx(Yk,{}):SD(t)?s.jsx(a.Box,{p:"xs",pl:20,children:s.jsx(Kk,{id:t[1]})}):_D(t)?s.jsx(bD,{}):kD(t)?s.jsx(yD,{id:t[1]}):DD(t)?s.jsx(ET,{}):TD(t)?s.jsx(fD,{id:t[1]}):ID(t)?s.jsx(a.Box,{p:"xs",pl:20,children:s.jsx(jD,{id:t[1]})}):MD(t)?s.jsx(AT,{viewID:t[1],panelID:t[3]}):s.jsx(a.Box,{children:e.path})}),ED=S.observer(()=>s.jsx(AD,{})),LD=S.observer(()=>{const e=Z(),t=()=>{const n=new Date().getTime().toString(),r={id:n,key:n,label:n,order:e.content.filters.current.length+1,type:xe.TextInput,config:$r(),visibleInViewsIDs:["Main"],auto_submit:!1};e.content.filters.append(r),e.editor.setPath(["_FILTERS_",n])};return s.jsx(a.Button,{variant:"subtle",leftIcon:s.jsx(_.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"})}),PD=S.observer(({parentID:e})=>{const t=R();if(!e)return null;const n=t.views.findByID(e);return!n||n.type===P.Tabs?null:s.jsx(a.Button,{variant:"subtle",leftIcon:s.jsx(_.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"})}),BD=S.observer(()=>{const e=Z(),t=()=>{const n=new Date().getTime().toString(),r={id:n,name:n,type:ce.Postgresql,key:"",sql:""};e.content.queries.append(r),e.editor.setPath(["_QUERIES_",n])};return s.jsx(a.Button,{variant:"subtle",leftIcon:s.jsx(_.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"})}),OD=S.observer(()=>{const e=Z(),t=()=>{const n=new Date().getTime().toString(),r={key:n,value:""};e.content.sqlSnippets.append(r),e.editor.setPath(["_SQL_SNIPPETS_",n])};return s.jsx(a.Button,{variant:"subtle",leftIcon:s.jsx(_.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=S.observer(()=>{const e=R();return s.jsx(a.Button,{variant:"subtle",leftIcon:s.jsx(_.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"})}),VD=S.observer(()=>{const e=Z();return s.jsx(a.Button,{variant:"subtle",rightIcon:s.jsx(_.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"})}),qD=S.observer(()=>{const e=Z();return s.jsx(a.Button,{variant:"subtle",rightIcon:s.jsx(_.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"})}),ND=S.observer(()=>{const e=Z();return s.jsx(a.Button,{variant:"subtle",rightIcon:s.jsx(_.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>e.editor.setPath(["_FILTERS_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:"Manage Filters"})}),FD=S.observer(({action_type:e,parentID:t})=>e==="_Add_A_Filter_"?s.jsx(LD,{}):e==="_Add_A_SQL_SNIPPET_"?s.jsx(OD,{}):e==="_Add_A_QUERY_"?s.jsx(BD,{}):e==="_Add_A_VIEW_"?s.jsx($D,{}):e==="_Add_A_PANEL_"?s.jsx(PD,{parentID:t}):e==="_QUERIES_SETTINGS_"?s.jsx(VD,{}):e==="_SQL_SNIPPETS_SETTINGS_"?s.jsx(qD,{}):e==="_FILTERS_SETTINGS_"?s.jsx(ND,{}):null),Bu=S.observer(({option:e})=>{var d;const t=Z().editor,n=t.isOptionActive,r=n(t.path,e),i=t.isOptionOpened,o=t.navigate,l=i(e),[u,c]=g.useState(l);return g.useEffect(()=>{c(l)},[l]),s.jsx(a.NavLink,{active:r,defaultOpened:l,opened:u,onChange:c,label:e.label,onClick:()=>o(e),icon:e.Icon?s.jsx(e.Icon,{size:18}):null,children:(d=e.children)==null?void 0:d.map(h=>h._type==="ACTION"?s.jsx(FD,{action_type:h._action_type,parentID:h.parentID},`_ADD_${h.value}_`):s.jsx(Bu,{option:h},h.value))},e.label)}),GD=S.observer(()=>{const e=Z();return s.jsx(a.Box,{sx:{position:"relative"},children:e.editor.navOptions.map(t=>s.jsx(Bu,{option:t},t.value))})}),WD=S.observer(()=>{const e=Z();return s.jsxs(a.Navbar,{p:0,width:{base:220,xs:220,sm:240,md:260,lg:300,xl:320},sx:{height:"100vh - 60px - 60px",".mantine-NavLink-body":{wordWrap:"break-word"}},children:[s.jsx(a.Navbar.Section,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:s.jsx(a.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Settings"})}),s.jsx(a.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:s.jsx(GD,{})}),s.jsx(a.Navbar.Section,{children:s.jsx(a.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:s.jsx(a.Button,{size:"xs",color:"red",leftIcon:s.jsx(_.IconX,{size:18}),onClick:()=>e.editor.close(),children:"Close"})})})]})}),RD={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden",minWidth:"calc(var(--mantine-navbar-width, 0px) + 1200px)"},body:{flexGrow:1,nav:{top:0,height:"100vh"}},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:0,height:"100vh"}},QD=S.observer(()=>{const e=Z().editor;return s.jsx(a.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:s.jsx(a.AppShell,{padding:0,navbar:s.jsx(WD,{}),styles:RD,children:s.jsx(ED,{})})})}),UD=e=>e.replace(/([^:])(\/\/+)/g,"$1/");function KD(e){g.useEffect(()=>{if(ye.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const n=UD(e);ye.loader.config({paths:{vs:n}}),ye.loader.init().then(r=>console.log("monaco instance:",r))},[])}sa();const YD={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:60+30,height:"100vh"}},XD=({context:e,dashboard:t,content:n,update:r,className:i="dashboard",config:o,onChange:l,headerSlot:u,filterValues:c,onFilterValuesChange:d,onExit:h},p)=>{KD(o.monacoPath),gs(o);const{data:x=[]}=V.useRequest(vs),{data:m=[]}=V.useRequest(ia),j=g.useMemo(()=>gu(t,n,x,m,e,c??{}),[t,n]);g.useImperativeHandle(p,()=>j,[j]),mu(j.content,!0),g.useEffect(()=>{j.context.replace(e)},[e]),g.useEffect(()=>{j.datasources.replace(x)},[x]),g.useEffect(()=>{j.globalSQLSnippets.replace(m)},[m]),g.useEffect(()=>{d==null||d(j.content.filters.values)},[d,j.content.filters.values]),g.useEffect(()=>{c&&j.content.filters.patchValues(c)},[c,j.content.filters.patchValues]),g.useEffect(()=>K.reaction(()=>K.toJS(j.json),A=>{l==null||l(A)}),[j]);const C=async()=>{await r(j.json,j.content.json)},T=V.useCreation(Tr,[]),D=yu(T);return s.jsx(Le.ModalsProvider,{children:s.jsx(ks,{value:{searchButtonProps:o.searchButtonProps},children:s.jsx(Ss,{value:j,children:s.jsx(Ts,{value:j.content,children:s.jsx(Cn.Provider,{value:{inEditMode:!0},children:s.jsx(tt.Provider,{value:T,children:s.jsxs(Jn,{configure:D,children:[s.jsx(a.AppShell,{padding:0,header:s.jsx(ik,{onExit:h,saveDashboardChanges:C,headerSlot:u}),navbar:s.jsx(Ak,{}),styles:YD,children:s.jsx(a.Box,{className:`${i} dashboard-root`,sx:{position:"relative"},children:j.content.views.visibleViews.map(A=>s.jsx(ru,{view:A},A.id))})}),s.jsx(QD,{})]})})})})})})})},JD=S.observer(g.forwardRef(XD)),YI="",yi=f.types.model({id:f.types.string,name:f.types.string,dashboard_id:f.types.string,create_time:f.types.string,update_time:f.types.string,version:f.types.string,filters:Jr,queries:ei,sqlSnippets:ni,views:Kr,panels:Xr,layouts:ti,mock_context:Mr}).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,layouts:e.layouts.json,definition:{queries:e.queries.json,sqlSnippets:e.sqlSnippets.json,mock_context:e.mock_context.current}}}},get contentJSON(){return this.json.content},get payloadForSQL(){const t=f.getParent(e).context.current,n=f.getParent(e).globalSQLSnippets,r={context:{...e.mock_context.current,...t},filters:e.filters.values};return{...r,sql_snippets:un(e.sqlSnippets.current,"key","value",r),global_sql_snippets:un(n.list,"id","content",r)}},get payloadForViz(){const t=f.getParent(e).context.current;return{context:{...e.mock_context.current,...t},filters:e.filters.values}},get dashboardState(){return js(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 Ou({id:e,name:t,dashboard_id:n,create_time:r,update_time:i,content:o},l,u){if(!o)throw new Error("unexpected null content when creating a content model");const{version:c,filters:d,views:h,panels:p,layouts:x,definition:{queries:m,sqlSnippets:j,mock_context:C={}}}=o;return yi.create({id:e,name:t,dashboard_id:n,create_time:r,update_time:i,version:c,filters:Zr(d,l,C,u),queries:Vl(m),sqlSnippets:Fl(j),mock_context:zr(C),views:zl(h),panels:{list:p},layouts:{list:x,currentBreakpoint:x[0].id}})}const $u=f.types.model({id:f.types.identifier,name:f.types.string,group:f.types.string,content:yi,content_id:f.types.string,datasources:Il,globalSQLSnippets:Rr,context:es});function Vu({id:e,name:t,group:n,content_id:r},i,o,l,u,c){return $u.create({id:e,name:t,group:n,content_id:r,content:Ou(i,u,c),datasources:{list:o},globalSQLSnippets:{list:l},context:Qr(u)})}sa();const ZD=({context:e,dashboard:t,content:n,className:r="dashboard",config:i,fullScreenPanelID:o,setFullScreenPanelID:l,filterValues:u,onFilterValuesChange:c})=>{gs(i);const{data:d=[]}=V.useRequest(vs),{data:h=[]}=V.useRequest(ia),p=g.useMemo(()=>Vu(t,n,d,h,e,u??{}),[t,n]);mu(p.content,!1),g.useEffect(()=>{p.context.replace(e)},[e]),g.useEffect(()=>{p.datasources.replace(d)},[d]),g.useEffect(()=>{p.globalSQLSnippets.replace(h)},[h]),g.useEffect(()=>{c==null||c(p.content.filters.values)},[c,p.content.filters.values]),g.useEffect(()=>{u&&p.content.filters.patchValues(u)},[u,p.content.filters.patchValues]);const x=V.useCreation(Tr,[]),m=yu(x);return s.jsx(Le.ModalsProvider,{children:s.jsx(ks,{value:{searchButtonProps:i.searchButtonProps},children:s.jsx(Ss,{value:p,children:s.jsx(Ts,{value:p.content,children:s.jsx(Is.Provider,{value:{fullScreenPanelID:o,setFullScreenPanelID:l},children:s.jsx(Cn.Provider,{value:{inEditMode:!1},children:s.jsx(a.Box,{className:`${r} dashboard-root`,children:s.jsx(tt.Provider,{value:x,children:s.jsx(Jn,{configure:m,children:p.content.views.visibleViews.map(j=>s.jsx(ns,{view:j},j.id))})})})})})})})})})},HD=S.observer(ZD);M.extend(gc),M.extend(mc),M.extend(yc),M.extend(bc),M.extend(jc),M.extend(vc),M.extend(wc),M.extend(Cc),M.extend(Sc),M.extend(_c),M.extend(Dc),M.extend(Ic),M.extend(Mc),M.extend(zc),M.extend(Ac),M.extend(kc),M.extend(Tc),M.extend(Ec),M.extend(Lc),M.extend(Pc),M.extend(Bc),M.extend(Oc),M.extend($c),M.extend(Vc),M.extend(qc),M.extend(Nc),M.extend(Fc),M.extend(Gc),M.extend(Wc),M.extend(Rc),M.extend(Uc),M.extend(Kc),M.extend(Qc),M.tz.setDefault("UTC"),M.updateLocale("en",{weekStart:1});const eI=()=>Promise.resolve().then(()=>Fd).then(({version:e})=>(console.log(`[@devtable/dashboard] version: ${e}`),e));v.APIClient=Je,v.CURRENT_SCHEMA_VERSION=lt,v.ContentModel=li,v.ContentModelContextProvider=Ts,v.ContentRenderModel=yi,v.ContextMeta=es,v.DEFAULT_CUSTOM_MODAL_TITLE=Hn,v.DashboardApiClient=Zi,v.DashboardApiFacadeClient=Hi,v.DashboardEditor=JD,v.DashboardFilterType=xe,v.DashboardMode=iu,v.DashboardModel=fu,v.DashboardModelContextProvider=Ss,v.DashboardRenderModel=$u,v.DashboardThemeContextProvider=ks,v.DashboardViewEditor=ru,v.DashboardViewRender=ns,v.DataSourceMetaModel=Wr,v.DataSourceType=ce,v.DataSourcesMetaModel=Il,v.DefaultApiClient=Ji,v.DescriptionPopover=si,v.DraftModel=Gl,v.EViewComponentType=P,v.FacadeApiClient=ad,v.FilterCheckboxConfigMeta=Ar,v.FilterDateRangeConfigMeta=Er,v.FilterMeta=qr,v.FilterMultiSelectConfigMeta=Pr,v.FilterSelectConfigMeta=Br,v.FilterTextInputConfigMeta=Or,v.FilterTreeSelectConfigMeta=Vr,v.FiltersModel=ou,v.FiltersRenderModel=Jr,v.FullScreenPanel=Hl,v.FullScreenPanelContext=Is,v.GlobalSQLSnippetMeta=Ml,v.GlobalSQLSnippetsMeta=Rr,v.LayoutItemMeta=gl,v.LayoutSetMeta=ml,v.LayoutStateContext=Cn,v.LayoutsRenderModel=ti,v.MockContextMeta=Mr,v.MuteQueryModel=$l,v.Panel=Zl,v.PanelContextProvider=Ds,v.PanelErrorOrStateMessage=Xl,v.PanelMeta=xl,v.PanelModel=du,v.PanelRender=ii,v.PanelRenderModel=Yr,v.PanelStyleMeta=cl,v.PanelTitleMeta=dl,v.PanelVizMeta=hl,v.PanelVizSection=ri,v.PanelsModel=pu,v.PanelsRenderModel=Xr,v.QueriesModel=uu,v.QueriesRenderModel=ei,v.QueryMeta=fl,v.QueryModel=lu,v.QueryRenderModel=Hr,v.ReadOnlyDashboard=HD,v.SQLSnippetMeta=yl,v.SQLSnippetRenderModel=Nl,v.SQLSnippetsModel=cu,v.SQLSnippetsRenderModel=ni,v.VariableMeta=pl,v.ViewComponentTypeBackground=au,v.ViewComponentTypeColor=m_,v.ViewComponentTypeName=g_,v.ViewDivisionConfig=Nr,v.ViewMeta=Dl,v.ViewModalConfig=Fr,v.ViewRenderModel=Ur,v.ViewTabsConfig=Gr,v.ViewsModel=hu,v.ViewsRenderModel=Kr,v.Viz=Yl,v.applyPartialDashboard=M_,v.configureAPIClient=gs,v.createContentModel=xu,v.createContentRenderModel=Ou,v.createContextMeta=Qr,v.createDashboardModel=gu,v.createDashboardRenderModel=Vu,v.createDraft=Wl,v.createFilterCheckboxConfig=bl,v.createFilterDateRangeConfig=vl,v.createFilterMultiSelectConfig=wl,v.createFilterSelectConfig=Cl,v.createFilterTextInputConfig=$r,v.createFilterTreeSelectConfig=Sl,v.createViewDivisionConfig=_l,v.createViewModalConfig=kl,v.createViewTabsConfig=Tl,v.facadeApiClient=ea,v.formatSQLSnippet=un,v.getInitialDashboardViewsModel=oi,v.getInitialFiltersConfig=Zr,v.getInitialMockContextMeta=zr,v.getInitialQueriesRenderModel=Vl,v.getInitialSQLSnippetsRenderModel=Fl,v.getInitialViewsRenderModel=zl,v.getNewPanel=Ll,v.getVersion=eI,v.initialDashboardContent=L1,v.useDashboardContext=_s,v.useDashboardThemeContext=ha,v.useEditContentModelContext=R,v.useEditDashboardContext=Z,v.useEditPanelContext=Be,v.useFullScreenPanelContext=ya,v.usePanelFullScreen=eu,v.useRenderContentModelContext=pe,v.useRenderDashboardContext=da,v.useRenderPanelContext=ft,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
486
+ `)},pD=S.observer(({queryModel:e})=>e.typedAsSQL?s.jsxs(a.Tabs,{defaultValue:"Edit",orientation:"vertical",sx:{flexGrow:1},styles:{tabLabel:{width:"100%",height:"28px",lineHeight:"28px"}},keepMounted:!1,children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"Edit",children:s.jsx(a.Group,{spacing:14,position:"apart",children:"Edit SQL"})}),s.jsx(a.Tabs.Tab,{value:"Preview",children:"Preview SQL"}),s.jsx(a.Tabs.Tab,{value:"pre_process",children:"Process Request"}),s.jsx(a.Tabs.Tab,{value:"post_process",children:"Process Result"}),s.jsx(fi,{}),e.datasource&&s.jsx(Ac,{dataSource:e.datasource})]}),s.jsx(a.Tabs.Panel,{value:"Edit",sx:{position:"relative"},p:"sm",children:s.jsx(cD,{queryModel:e})}),s.jsx(a.Tabs.Panel,{value:"Preview",p:0,pl:4,children:s.jsx(dD,{value:e.sql})}),s.jsx(a.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:s.jsx(Ot,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:Bc.pre})}),s.jsx(a.Tabs.Panel,{value:"post_process",p:"sm",children:s.jsx(Ot,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:Bc.post})})]}):null),hD={pre:["function transform(queries, state, utils) {"," // use queries & dashboar state to build new data"," const data = []"," return data","}"].join(`
487
+ `),post:""},xD=S.observer(({queryModel:e})=>{const t=W();return e.isTransform?s.jsxs(a.Stack,{py:20,px:20,sx:{height:"100%"},children:[s.jsx(a.Text,{size:"md",children:"Step 1: Pick queries for data input"}),s.jsx(a.MultiSelect,{data:t.queries.optionsWithoutTransform,value:[...e.dep_query_ids],onChange:e.setDependantQueryIDs,maxDropdownHeight:800}),s.jsx(a.Text,{size:"md",children:"Write a function for making new data"}),s.jsx(a.Box,{sx:{flexGrow:1},children:s.jsx(Ot,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:hD.pre})})]}):null}),un={height:"calc(100% - 44px)",padding:0},fD=S.observer(({queryModel:e})=>{const t=W(),n=g.useMemo(()=>e.datasource?e.typedAsHTTP?"HTTP":"SQL":"Configurations",[e.datasource,e.typedAsHTTP]),[r,i]=g.useState(n);g.useEffect(()=>{i(c=>c!=="Configurations"&&n==="Configurations"?"Configurations":c)},[n]);const o=t.findQueryUsage(e.id),l=o.length===0;return s.jsxs(a.Tabs,{value:r,onTabChange:i,defaultValue:n,orientation:"horizontal",keepMounted:!1,sx:{height:"100vh"},children:[s.jsxs(a.Tabs.List,{grow:!0,children:[s.jsx(a.Tabs.Tab,{value:"Configurations",children:"Configurations"}),e.typedAsSQL&&s.jsx(a.Tabs.Tab,{value:"SQL",children:"Request"}),e.typedAsHTTP&&s.jsx(a.Tabs.Tab,{value:"HTTP",children:"Request"}),e.isTransform&&s.jsx(a.Tabs.Tab,{value:"Transform",children:"Transform"}),s.jsx(a.Tabs.Tab,{value:"Data",disabled:!e.canPreviewData,children:s.jsx(a.Tooltip,{label:e.guideToPreviewData,disabled:e.canPreviewData,withinPortal:!0,children:s.jsx(a.Text,{children:"Data"})})}),s.jsx(a.Tabs.Tab,{value:"Usage",disabled:l,children:s.jsx(a.Tooltip,{label:"This query is not used for any filter or panel",disabled:!l,withinPortal:!0,children:s.jsx(a.Text,{children:"Usage"})})})]}),s.jsx(a.Tabs.Panel,{value:"Configurations",pt:0,p:0,children:s.jsx(tD,{queryModel:e})}),e.typedAsSQL&&s.jsx(a.Tabs.Panel,{value:"SQL",sx:un,children:s.jsx(a.Stack,{sx:{height:"100%"},children:s.jsx(pD,{queryModel:e})})}),e.typedAsHTTP&&s.jsx(a.Tabs.Panel,{value:"HTTP",sx:un,children:s.jsx(a.Stack,{sx:{height:"100%"},children:s.jsx(iD,{queryModel:e})})}),e.isTransform&&s.jsx(a.Tabs.Panel,{value:"Transform",sx:un,children:s.jsx(a.Stack,{sx:{height:"100%"},children:s.jsx(xD,{queryModel:e})})}),s.jsx(a.Tabs.Panel,{value:"Data",sx:{...un,overflow:"hidden"},children:s.jsx(pi,{id:e.id,moreActions:null,refreshOnMount:!0})}),s.jsx(a.Tabs.Panel,{value:"Usage",sx:{...un,overflow:"hidden"},children:s.jsx(aD,{queryID:e.id,usage:o})})]})}),gD=S.observer(({id:e})=>{const n=W().queries.findByID(e);return e===""?null:n?s.jsx(fD,{queryModel:n}):s.jsx(a.Text,{size:14,color:"red",children:"Invalid Query ID"})}),mD=S.observer(({value:e})=>{const n=ce().payloadForSQL,r=g.useMemo(()=>xs(e,n),[e,n]);return s.jsx(gi,{height:"100%",value:r})}),yD=S.observer(({item:e,remove:t,onKeyChanged:n})=>{const[r,i]=g.useState("SQL"),[o,l]=g.useState(e.key),c=()=>{e.setKey(o),n(o)},u=o!==e.key,d=e.isADuplicatedKey(o),[h,p]=g.useState(e.value),x=()=>{e.setValue(h)};g.useEffect(()=>{l(e.key),p(e.value)},[e]);const m=h!==e.value,j=ze.useModals(),C=()=>{j.openConfirmModal({title:"Delete this SQL snippet?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:t,confirmProps:{color:"red"},zIndex:320})};return s.jsxs(a.Stack,{p:20,sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",children:[s.jsxs(a.Group,{sx:{alignItems:"end"},spacing:40,children:[s.jsx(a.TextInput,{label:d?"This key is occupied by another snippet":"Key",value:o,onChange:T=>{l(T.currentTarget.value)},sx:{flexGrow:"1 !important"},rightSection:s.jsx(a.ActionIcon,{color:"blue",variant:"subtle",onClick:c,disabled:!u||d,children:s.jsx(k.DeviceFloppy,{size:16})}),error:d}),s.jsx(a.Button,{leftIcon:s.jsx(k.Trash,{size:16}),color:"red",variant:"light",onClick:C,children:"Delete this SQL Snippet"})]}),s.jsxs(a.Tabs,{value:r,onTabChange:i,sx:{flexGrow:1},styles:{panel:{height:"calc(100% - 50px)"}},children:[s.jsxs(a.Tabs.List,{sx:{position:"relative"},children:[s.jsx(a.Tabs.Tab,{value:"SQL",children:"SQL"}),s.jsx(a.Tabs.Tab,{value:"Preview",children:"Preview"}),s.jsx(fi,{}),s.jsx(a.ActionIcon,{color:"blue",variant:"filled",onClick:x,disabled:!m,sx:{position:"absolute",top:0,right:10},children:s.jsx(k.DeviceFloppy,{size:18})})]}),s.jsx(a.Tabs.Panel,{value:"SQL",pt:"sm",children:s.jsx(gi,{height:"100%",value:h,onChange:p,defaultLanguage:"sql",theme:"sql-dark"})}),s.jsx(a.Tabs.Panel,{value:"Preview",pt:"sm",children:s.jsx(mD,{value:h})})]})]})}),bD=S.observer(({id:e})=>{const t=X(),n=W(),r=g.useMemo(()=>n.sqlSnippets.findByKey(e),[e]);if(!e)return null;if(!r)return s.jsxs(a.Text,{size:14,children:["SQL Snippet by key[",e,"] is not found"]});const i=()=>{t.editor.setPath(["_SQL_SNIPPETS_",""])},o=()=>{n.sqlSnippets.removeByKey(e),i()},l=c=>{t.editor.setPath(["_SQL_SNIPPETS_",c])};return s.jsx(yD,{item:r,remove:o,onKeyChanged:l})}),jD=S.observer(()=>{const[e,t]=g.useState([]),n=ze.useModals(),r=X(),i=p=>{r.editor.setPath(["_SQL_SNIPPETS_",p])},o=()=>{n.openConfirmModal({title:"Delete ununsed SQL snippets?",children:s.jsx(a.Text,{size:"sm",children:"This action cannot be undone."}),labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>r.content.removeUnusedSQLSnippets(),confirmProps:{color:"red"},zIndex:320})},l=()=>{r.content.sqlSnippets.downloadSchema(e)},c=g.useMemo(()=>r.content.sqlSnippets.sortedList.map(p=>p.key),[r.content.sqlSnippets.sortedList]),u=()=>{t(c)},d=()=>{t([])},h=r.content.sqlSnippetsUsage;return s.jsxs(a.Stack,{sx:{height:"100%"},spacing:"sm",pb:"59px",children:[s.jsx(a.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:s.jsx(a.Text,{px:"md",align:"left",sx:{userSelect:"none",cursor:"default"},children:"Manage SQL Snippets"})}),s.jsxs(a.Flex,{justify:"space-between",align:"center",px:12,children:[s.jsxs(a.Group,{position:"left",children:[s.jsxs(a.Button.Group,{children:[s.jsx(a.Button,{variant:"default",size:"xs",onClick:u,children:"Select All"}),s.jsx(a.Button,{variant:"default",size:"xs",onClick:d,children:"Clear Selection"})]}),s.jsx(a.Button,{size:"xs",color:"blue",leftIcon:s.jsx(_.IconCode,{size:14}),disabled:e.length===0,onClick:l,children:"Download Schema"})]}),s.jsx(a.Button,{variant:"subtle",size:"xs",color:"red",leftIcon:s.jsx(_.IconTrash,{size:14}),disabled:!r.content.hasUnusedSQLSnippets,onClick:o,children:"Delete unused SQL snippets"})]}),s.jsx(a.Box,{sx:{flexGrow:1,overflow:"auto"},children:s.jsx(a.Checkbox.Group,{size:"xs",value:e,onChange:t,children:s.jsxs(a.Table,{fontSize:"sm",highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"40px"}}),s.jsx("th",{children:"Key"}),s.jsx("th",{style:{width:"100px",textAlign:"center"},children:"Usage"}),s.jsx("th",{style:{width:"300px",paddingLeft:"24px"},children:"Action"})]})}),s.jsx("tbody",{children:r.content.sqlSnippets.sortedList.map(p=>{var m;const x=((m=h[p.key])==null?void 0:m.length)??0;return s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx(a.Checkbox,{value:p.key,styles:{input:{cursor:"pointer"}}})}),s.jsx("td",{children:p.key}),s.jsx("td",{style:{color:x===0?"#ff0000":"#000",fontWeight:x===0?"bold":"normal",textAlign:"center"},children:x}),s.jsx("td",{children:s.jsx(a.Button,{variant:"subtle",size:"xs",onClick:()=>i(p.key),children:"Open"})})]},p.key)})})]})})})]})}),vD=S.observer(({id:e})=>{const t=ze.useModals(),n=X(),r=W();if(e==="")return null;const i=r.views.findByID(e);if(!i)return s.jsxs(a.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 s.jsxs(a.Stack,{sx:{maxWidth:"600px",height:"100%"},spacing:"sm",children:[s.jsx(a.Group,{position:"right",pt:10,children:s.jsx(a.Button,{size:"xs",color:"red",leftIcon:s.jsx(k.Trash,{size:16}),onClick:l,children:"Delete this view"})}),s.jsx(a.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:s.jsx(U_,{view:i})})]})});function wD(e){return e.length===1&&e[0]==="_QUERY_VARS_"}function CD(e){return e.length===1&&e[0]==="_MOCK_CONTEXT_"}function SD(e){return e.length===1&&e[0]==="_FILTERS_"}function _D(e){return e.length===2&&e[0]==="_FILTERS_"}function kD(e){return e.length===1&&e[0]==="_SQL_SNIPPETS_"}function TD(e){return e.length===2&&e[0]==="_SQL_SNIPPETS_"}function DD(e){return e.length===2&&e[0]==="_QUERIES_"}function ID(e){return e.length===1&&e[0]==="_QUERIES_"}function MD(e){return e.length===2&&e[0]==="_VIEWS_"}function zD(e){return e.length===4&&e[0]==="_VIEWS_"&&e[2]==="_PANELS_"}const AD=S.observer(()=>s.jsx(a.Stack,{sx:{height:"100%"},p:"sm",children:s.jsx(Pc,{})})),ED=S.observer(()=>{const e=X().editor,t=e.path;return wD(t)?s.jsx(AD,{}):CD(t)?s.jsx(Jk,{}):SD(t)?s.jsx(Xk,{}):_D(t)?s.jsx(a.Box,{p:"xs",pl:20,children:s.jsx(Yk,{id:t[1]})}):kD(t)?s.jsx(jD,{}):TD(t)?s.jsx(bD,{id:t[1]}):ID(t)?s.jsx(PT,{}):DD(t)?s.jsx(gD,{id:t[1]}):MD(t)?s.jsx(a.Box,{p:"xs",pl:20,children:s.jsx(vD,{id:t[1]})}):zD(t)?s.jsx(ET,{viewID:t[1],panelID:t[3]}):s.jsx(a.Box,{children:e.path})}),PD=S.observer(()=>s.jsx(ED,{})),LD=S.observer(()=>{const e=X(),t=()=>{const n=new Date().getTime().toString(),r={id:n,key:n,label:n,order:e.content.filters.current.length+1,type:de.TextInput,config:Or(),visibleInViewsIDs:["Main"],auto_submit:!1};e.content.filters.append(r),e.editor.setPath(["_FILTERS_",n])};return s.jsx(a.Button,{variant:"subtle",leftIcon:s.jsx(_.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"})}),BD=S.observer(({parentID:e})=>{const t=W();if(!e)return null;const n=t.views.findByID(e);return!n||n.type===L.Tabs?null:s.jsx(a.Button,{variant:"subtle",leftIcon:s.jsx(_.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"})}),OD=S.observer(()=>{const e=X(),t=()=>{const n=new Date().getTime().toString(),r={id:n,name:n,type:oe.Postgresql,key:"",sql:""};e.content.queries.append(r),e.editor.setPath(["_QUERIES_",n])};return s.jsx(a.Button,{variant:"subtle",leftIcon:s.jsx(_.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"})}),$D=S.observer(()=>{const e=X(),t=()=>{const n=new Date().getTime().toString(),r={key:n,value:""};e.content.sqlSnippets.append(r),e.editor.setPath(["_SQL_SNIPPETS_",n])};return s.jsx(a.Button,{variant:"subtle",leftIcon:s.jsx(_.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"})}),VD=S.observer(()=>{const e=W();return s.jsx(a.Button,{variant:"subtle",leftIcon:s.jsx(_.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"})}),qD=S.observer(()=>{const e=X();return s.jsx(a.Button,{variant:"subtle",rightIcon:s.jsx(_.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"})}),ND=S.observer(()=>{const e=X();return s.jsx(a.Button,{variant:"subtle",rightIcon:s.jsx(_.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"})}),FD=S.observer(()=>{const e=X();return s.jsx(a.Button,{variant:"subtle",rightIcon:s.jsx(_.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>e.editor.setPath(["_FILTERS_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:"Manage Filters"})}),GD=S.observer(({action_type:e,parentID:t})=>e==="_Add_A_Filter_"?s.jsx(LD,{}):e==="_Add_A_SQL_SNIPPET_"?s.jsx($D,{}):e==="_Add_A_QUERY_"?s.jsx(OD,{}):e==="_Add_A_VIEW_"?s.jsx(VD,{}):e==="_Add_A_PANEL_"?s.jsx(BD,{parentID:t}):e==="_QUERIES_SETTINGS_"?s.jsx(qD,{}):e==="_SQL_SNIPPETS_SETTINGS_"?s.jsx(ND,{}):e==="_FILTERS_SETTINGS_"?s.jsx(FD,{}):null),Oc=S.observer(({option:e})=>{var d;const t=X().editor,n=t.isOptionActive,r=n(t.path,e),i=t.isOptionOpened,o=t.navigate,l=i(e),[c,u]=g.useState(l);return g.useEffect(()=>{u(l)},[l]),s.jsx(a.NavLink,{active:r,defaultOpened:l,opened:c,onChange:u,label:e.label,onClick:()=>o(e),icon:e.Icon?s.jsx(e.Icon,{size:18}):null,children:(d=e.children)==null?void 0:d.map(h=>h._type==="ACTION"?s.jsx(GD,{action_type:h._action_type,parentID:h.parentID},`_ADD_${h.value}_`):s.jsx(Oc,{option:h},h.value))},e.label)}),WD=S.observer(()=>{const e=X();return s.jsx(a.Box,{sx:{position:"relative"},children:e.editor.navOptions.map(t=>s.jsx(Oc,{option:t},t.value))})}),RD=S.observer(()=>{const e=X();return s.jsxs(a.Navbar,{p:0,width:{base:220,xs:220,sm:240,md:260,lg:300,xl:320},sx:{height:"100vh - 60px - 60px",".mantine-NavLink-body":{wordWrap:"break-word"}},children:[s.jsx(a.Navbar.Section,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:s.jsx(a.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Settings"})}),s.jsx(a.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:s.jsx(WD,{})}),s.jsx(a.Navbar.Section,{children:s.jsx(a.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:s.jsx(a.Button,{size:"xs",color:"red",leftIcon:s.jsx(_.IconX,{size:18}),onClick:()=>e.editor.close(),children:"Close"})})})]})}),QD={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden",minWidth:"calc(var(--mantine-navbar-width, 0px) + 1200px)"},body:{flexGrow:1,nav:{top:0,height:"100vh"}},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:0,height:"100vh"}},UD=S.observer(()=>{const e=X().editor;return s.jsx(a.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:s.jsx(a.AppShell,{padding:0,navbar:s.jsx(RD,{}),styles:QD,children:s.jsx(PD,{})})})}),KD=e=>e.replace(/([^:])(\/\/+)/g,"$1/");function YD(e){g.useEffect(()=>{if(fe.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const n=KD(e);fe.loader.config({paths:{vs:n}}),fe.loader.init().then(r=>console.log("monaco instance:",r))},[])}sa(),ia();const XD={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:60+30,height:"100vh"}},JD=({context:e,dashboard:t,content:n,update:r,className:i="dashboard",config:o,onChange:l,headerSlot:c,filterValues:u,onFilterValuesChange:d,onExit:h},p)=>{YD(o.monacoPath),fs(o);const{data:x=[]}=$.useRequest(js),{data:m=[]}=$.useRequest(aa),j=g.useMemo(()=>mc(t,n,x,m,e,u??{}),[t,n]);g.useImperativeHandle(p,()=>j,[j]),yc(j.content,!0),g.useEffect(()=>{j.context.replace(e)},[e]),g.useEffect(()=>{j.datasources.replace(x)},[x]),g.useEffect(()=>{j.globalSQLSnippets.replace(m)},[m]),g.useEffect(()=>{d==null||d(j.content.filters.values)},[d,j.content.filters.values]),g.useEffect(()=>{u&&j.content.filters.patchValues(u)},[u,j.content.filters.patchValues]),g.useEffect(()=>U.reaction(()=>U.toJS(j.json),A=>{l==null||l(A)}),[j]);const C=async()=>{await r(j.json,j.content.json)},T=$.useCreation(kr,[]),D=bc(T);return s.jsx(ze.ModalsProvider,{children:s.jsx(_s,{value:{searchButtonProps:o.searchButtonProps},children:s.jsx(Cs,{value:j,children:s.jsx(ks,{value:j.content,children:s.jsx(wn.Provider,{value:{inEditMode:!0},children:s.jsx(Ze.Provider,{value:T,children:s.jsxs(Xn,{configure:D,children:[s.jsx(a.AppShell,{padding:0,header:s.jsx(ak,{onExit:h,saveDashboardChanges:C,headerSlot:c}),navbar:s.jsx(Ek,{}),styles:XD,children:s.jsx(a.Box,{className:`${i} dashboard-root`,sx:{position:"relative"},children:j.content.views.visibleViews.map(A=>s.jsx(ic,{view:A},A.id))})}),s.jsx(UD,{})]})})})})})})})},ZD=S.observer(g.forwardRef(JD)),XI="",mi=f.types.model({id:f.types.string,name:f.types.string,dashboard_id:f.types.string,create_time:f.types.string,update_time:f.types.string,version:f.types.string,filters:Xr,queries:Hr,sqlSnippets:ti,views:Ur,panels:Yr,layouts:ei,mock_context:Ir}).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,layouts:e.layouts.json,definition:{queries:e.queries.json,sqlSnippets:e.sqlSnippets.json,mock_context:e.mock_context.current}}}},get contentJSON(){return this.json.content},get payloadForSQL(){const t=f.getParent(e).context.current,n=f.getParent(e).globalSQLSnippets,r={context:{...e.mock_context.current,...t},filters:e.filters.values};return{...r,sql_snippets:ln(e.sqlSnippets.current,"key","value",r),global_sql_snippets:ln(n.list,"id","content",r)}},get payloadForViz(){const t=f.getParent(e).context.current;return{context:{...e.mock_context.current,...t},filters:e.filters.values}},get dashboardState(){return bs(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 $c({id:e,name:t,dashboard_id:n,create_time:r,update_time:i,content:o},l,c){if(!o)throw new Error("unexpected null content when creating a content model");const{version:u,filters:d,views:h,panels:p,layouts:x,definition:{queries:m,sqlSnippets:j,mock_context:C={}}}=o;return mi.create({id:e,name:t,dashboard_id:n,create_time:r,update_time:i,version:u,filters:Jr(d,l,C,c),queries:ql(m),sqlSnippets:Gl(j),mock_context:Mr(C),views:Al(h),panels:{list:p},layouts:{list:x,currentBreakpoint:x[0].id}})}const Vc=f.types.model({id:f.types.identifier,name:f.types.string,group:f.types.string,content:mi,content_id:f.types.string,datasources:Ml,globalSQLSnippets:Wr,context:Hn});function qc({id:e,name:t,group:n,content_id:r},i,o,l,c,u){return Vc.create({id:e,name:t,group:n,content_id:r,content:$c(i,c,u),datasources:{list:o},globalSQLSnippets:{list:l},context:Rr(c)})}sa(),ia();const HD=({context:e,dashboard:t,content:n,className:r="dashboard",config:i,fullScreenPanelID:o,setFullScreenPanelID:l,filterValues:c,onFilterValuesChange:u})=>{fs(i);const{data:d=[]}=$.useRequest(js),{data:h=[]}=$.useRequest(aa),p=g.useMemo(()=>qc(t,n,d,h,e,c??{}),[t,n]);yc(p.content,!1),g.useEffect(()=>{p.context.replace(e)},[e]),g.useEffect(()=>{p.datasources.replace(d)},[d]),g.useEffect(()=>{p.globalSQLSnippets.replace(h)},[h]),g.useEffect(()=>{u==null||u(p.content.filters.values)},[u,p.content.filters.values]),g.useEffect(()=>{c&&p.content.filters.patchValues(c)},[c,p.content.filters.patchValues]);const x=$.useCreation(kr,[]),m=bc(x);return s.jsx(ze.ModalsProvider,{children:s.jsx(_s,{value:{searchButtonProps:i.searchButtonProps},children:s.jsx(Cs,{value:p,children:s.jsx(ks,{value:p.content,children:s.jsx(Ds.Provider,{value:{fullScreenPanelID:o,setFullScreenPanelID:l},children:s.jsx(wn.Provider,{value:{inEditMode:!1},children:s.jsx(a.Box,{className:`${r} dashboard-root`,children:s.jsx(Ze.Provider,{value:x,children:s.jsx(Xn,{configure:m,children:p.content.views.visibleViews.map(j=>s.jsx(ts,{view:j},j.id))})})})})})})})})})},eI=S.observer(HD);M.extend(mu),M.extend(yu),M.extend(bu),M.extend(ju),M.extend(vu),M.extend(wu),M.extend(Cu),M.extend(Su),M.extend(_u),M.extend(ku),M.extend(Iu),M.extend(Mu),M.extend(zu),M.extend(Au),M.extend(Eu),M.extend(Tu),M.extend(Du),M.extend(Pu),M.extend(Lu),M.extend(Bu),M.extend(Ou),M.extend($u),M.extend(Vu),M.extend(qu),M.extend(Nu),M.extend(Fu),M.extend(Gu),M.extend(Wu),M.extend(Ru),M.extend(Qu),M.extend(Ku),M.extend(Yu),M.extend(Uu),M.tz.setDefault("UTC"),M.updateLocale("en",{weekStart:1});const tI=()=>Promise.resolve().then(()=>Gd).then(({version:e})=>(console.log(`[@devtable/dashboard] version: ${e}`),e));v.APIClient=Ke,v.CURRENT_SCHEMA_VERSION=at,v.ContentModel=oi,v.ContentModelContextProvider=ks,v.ContentRenderModel=mi,v.ContextMeta=Hn,v.DEFAULT_CUSTOM_MODAL_TITLE=Zn,v.DashboardApiClient=Zi,v.DashboardApiFacadeClient=Hi,v.DashboardEditor=ZD,v.DashboardFilterType=de,v.DashboardMode=ac,v.DashboardModel=gc,v.DashboardModelContextProvider=Cs,v.DashboardRenderModel=Vc,v.DashboardThemeContextProvider=_s,v.DashboardViewEditor=ic,v.DashboardViewRender=ts,v.DataSourceMetaModel=Gr,v.DataSourceType=oe,v.DataSourcesMetaModel=Ml,v.DefaultApiClient=Ji,v.DescriptionPopover=ni,v.DraftModel=Wl,v.EViewComponentType=L,v.FacadeApiClient=od,v.FilterCheckboxConfigMeta=zr,v.FilterDateRangeConfigMeta=Ar,v.FilterMeta=Vr,v.FilterMultiSelectConfigMeta=Pr,v.FilterSelectConfigMeta=Lr,v.FilterTextInputConfigMeta=Br,v.FilterTreeSelectConfigMeta=$r,v.FiltersModel=lc,v.FiltersRenderModel=Xr,v.FullScreenPanel=ec,v.FullScreenPanelContext=Ds,v.GlobalSQLSnippetMeta=zl,v.GlobalSQLSnippetsMeta=Wr,v.LayoutItemMeta=ml,v.LayoutSetMeta=yl,v.LayoutStateContext=wn,v.LayoutsRenderModel=ei,v.MockContextMeta=Ir,v.MuteQueryModel=Vl,v.Panel=Hl,v.PanelContextProvider=Ts,v.PanelErrorOrStateMessage=Jl,v.PanelMeta=fl,v.PanelModel=pc,v.PanelRender=ri,v.PanelRenderModel=Kr,v.PanelStyleMeta=dl,v.PanelTitleMeta=pl,v.PanelVizMeta=xl,v.PanelVizSection=si,v.PanelsModel=hc,v.PanelsRenderModel=Yr,v.QueriesModel=uc,v.QueriesRenderModel=Hr,v.QueryMeta=gl,v.QueryModel=cc,v.QueryRenderModel=Zr,v.ReadOnlyDashboard=eI,v.SQLSnippetMeta=bl,v.SQLSnippetRenderModel=Fl,v.SQLSnippetsModel=dc,v.SQLSnippetsRenderModel=ti,v.VariableMeta=hl,v.ViewComponentTypeBackground=oc,v.ViewComponentTypeColor=y_,v.ViewComponentTypeName=m_,v.ViewDivisionConfig=qr,v.ViewMeta=Il,v.ViewModalConfig=Nr,v.ViewRenderModel=Qr,v.ViewTabsConfig=Fr,v.ViewsModel=xc,v.ViewsRenderModel=Ur,v.Viz=Xl,v.applyPartialDashboard=z_,v.configureAPIClient=fs,v.createContentModel=fc,v.createContentRenderModel=$c,v.createContextMeta=Rr,v.createDashboardModel=mc,v.createDashboardRenderModel=qc,v.createDraft=Rl,v.createFilterCheckboxConfig=jl,v.createFilterDateRangeConfig=wl,v.createFilterMultiSelectConfig=Cl,v.createFilterSelectConfig=Sl,v.createFilterTextInputConfig=Or,v.createFilterTreeSelectConfig=_l,v.createViewDivisionConfig=kl,v.createViewModalConfig=Tl,v.createViewTabsConfig=Dl,v.facadeApiClient=ea,v.formatSQLSnippet=ln,v.getInitialDashboardViewsModel=ai,v.getInitialFiltersConfig=Jr,v.getInitialMockContextMeta=Mr,v.getInitialQueriesRenderModel=ql,v.getInitialSQLSnippetsRenderModel=Gl,v.getInitialViewsRenderModel=Al,v.getNewPanel=Ll,v.getVersion=tI,v.initialDashboardContent=L1,v.useDashboardContext=Ss,v.useDashboardThemeContext=xa,v.useEditContentModelContext=W,v.useEditDashboardContext=X,v.useEditPanelContext=Ee,v.useFullScreenPanelContext=ba,v.usePanelFullScreen=tc,v.useRenderContentModelContext=ce,v.useRenderDashboardContext=pa,v.useRenderPanelContext=xt,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});