@devtable/dashboard 12.3.1 → 12.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dashboard-editor/dashboard-editor.d.ts +1 -0
- package/dist/dashboard-editor/ui/settings/content/edit-view/edit-view-form/index.d.ts +0 -5
- package/dist/dashboard-render/dashboard-render.d.ts +2 -1
- package/dist/dashboard.es.js +7413 -6544
- package/dist/dashboard.umd.js +85 -85
- package/dist/i18n/en.d.ts +324 -0
- package/dist/i18n/i18n.d.ts +2 -0
- package/dist/i18n/index.d.ts +1 -0
- package/dist/i18n/zh.d.ts +324 -0
- package/dist/stats.html +1 -1
- package/dist/utils/function-utils.d.ts +1 -1
- package/dist/utils/usage.d.ts +1 -1
- package/package.json +5 -1
package/dist/dashboard.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(j,f){typeof exports=="object"&&typeof module<"u"?f(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("react-i18next"),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("i18next"),require("i18next-browser-languagedetector"),require("intl-pluralrules"),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","react-i18next","@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","i18next","i18next-browser-languagedetector","intl-pluralrules","reactflow"],f):(j=typeof globalThis<"u"?globalThis:j||self,f(j.dashboard={},j.react,j["@mantine/core"],j["@mantine/modals"],j.ahooks,j.mobx,j["mobx-react-lite"],j["@faker-js/faker"],j.CryptoJS,j["d3-array"],j.dayjs,j._,j.mathjs,j.numbro,j.axios,j["@mantine/hooks"],j.popmotion,j["echarts/core"],j["echarts/charts"],j["echarts/components"],j["echarts/renderers"],j["js-base64"],j.eventemitter2,j["chroma-js"],j["echarts-for-react/lib/core"],j["echarts-gl"],j["react-hook-form"],j["tabler-icons-react"],j["@tabler/icons-react"],j["react-i18next"],j["@mantine/notifications"],j["@monaco-editor/react"],j["d3-regression"],j["@mantine/tiptap"],j["@tiptap/extension-color"],j["@tiptap/extension-highlight"],j["@tiptap/extension-placeholder"],j["@tiptap/extension-subscript"],j["@tiptap/extension-superscript"],j["@tiptap/extension-text-align"],j["@tiptap/extension-text-style"],j["@tiptap/extension-table"],j["@tiptap/extension-table-cell"],j["@tiptap/extension-table-header"],j["@tiptap/extension-table-row"],j["@tiptap/extension-underline"],j["@tiptap/react"],j["@tiptap/starter-kit"],j["prosemirror-keymap"],j["prosemirror-commands"],j["prosemirror-schema-list"],j["@mantine/prism"],j["@tanstack/react-table"],j["react-virtual"],j["@mantine/dates"],j["rc-select"],j["rc-tree-select"],j["react-grid-layout"],j["mobx-state-tree"],j.uuid,j["performant-array-to-tree"],j["file-saver"],j["dom-to-image-more"],j.jszip,j["@json2csv/whatwg"],j["dayjs/plugin/advancedFormat"],j["dayjs/plugin/arraySupport"],j["dayjs/plugin/buddhistEra"],j["dayjs/plugin/calendar"],j["dayjs/plugin/customParseFormat"],j["dayjs/plugin/dayOfYear"],j["dayjs/plugin/duration"],j["dayjs/plugin/isBetween"],j["dayjs/plugin/isLeapYear"],j["dayjs/plugin/isMoment"],j["dayjs/plugin/isoWeek"],j["dayjs/plugin/isoWeeksInYear"],j["dayjs/plugin/isSameOrAfter"],j["dayjs/plugin/isSameOrBefore"],j["dayjs/plugin/isToday"],j["dayjs/plugin/isTomorrow"],j["dayjs/plugin/isYesterday"],j["dayjs/plugin/localeData"],j["dayjs/plugin/localizedFormat"],j["dayjs/plugin/minMax"],j["dayjs/plugin/objectSupport"],j["dayjs/plugin/pluralGetSet"],j["dayjs/plugin/preParsePostFormat"],j["dayjs/plugin/quarterOfYear"],j["dayjs/plugin/relativeTime"],j["dayjs/plugin/timezone"],j["dayjs/plugin/toArray"],j["dayjs/plugin/toObject"],j["dayjs/plugin/updateLocale"],j["dayjs/plugin/utc"],j["dayjs/plugin/weekday"],j["dayjs/plugin/weekOfYear"],j["dayjs/plugin/weekYear"],j.i18next,j["i18next-browser-languagedetector"],j["intl-pluralrules"],j.reactflow))})(this,function(j,f,a,Ee,V,Y,_,cu,Ti,Qt,z,y,uu,fn,nt,ie,bt,Di,Xe,dt,du,Ii,Mi,st,Ce,II,b,T,k,M,pt,ge,pu,G,zi,Ai,Ei,Pi,Li,Bi,Oi,$i,qi,Vi,Ni,Fi,Gi,Wi,MI,me,ds,ht,We,hu,xu,Ri,Qi,gn,g,xt,fu,mn,Ui,Ki,gu,mu,yu,bu,vu,ju,wu,Cu,_u,Su,ku,Tu,Du,Iu,Mu,zu,Au,Eu,Pu,Lu,Bu,Ou,$u,qu,Vu,Nu,Fu,Gu,Wu,Ru,Qu,Uu,Ku,Yu,Xu,Ju,zI,be){"use strict";var TI=Object.defineProperty;var DI=(j,f,a)=>f in j?TI(j,f,{enumerable:!0,configurable:!0,writable:!0,value:a}):j[f]=a;var L=(j,f,a)=>(DI(j,typeof f!="symbol"?f+"":f,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 Zu=Ut(Ti),Hu=Ut(Qt),Mt=Ut(uu),ve=Ut(Di),ft=Ut(pu);var ps={exports:{}},Kt={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var Yi;function
|
|
9
|
+
*/var Yi;function ed(){if(Yi)return Kt;Yi=1;var e=f,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 Kt.Fragment=n,Kt.jsx=l,Kt.jsxs=l,Kt}var Yt={};/**
|
|
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
|
|
18
|
-
`+
|
|
19
|
-
`),Se=
|
|
20
|
-
`),
|
|
21
|
-
`+
|
|
17
|
+
*/var Xi;function td(){return Xi||(Xi=1,process.env.NODE_ENV!=="production"&&function(){var e=f,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"),v=Symbol.iterator,C="@@iterator";function S(w){if(w===null||typeof w!="object")return null;var I=v&&w[v]||w[C];return typeof I=="function"?I:null}var D=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function P(w){{for(var I=arguments.length,E=new Array(I>1?I-1:0),N=1;N<I;N++)E[N-1]=arguments[N];q("error",w,E)}}function q(w,I,E){{var N=D.ReactDebugCurrentFrame,H=N.getStackAddendum();H!==""&&(I+="%s",E=E.concat([H]));var se=E.map(function(X){return String(X)});se.unshift("Warning: "+I),Function.prototype.apply.call(console[w],console,se)}}var U=!1,F=!1,re=!1,W=!1,te=!1,Ae;Ae=Symbol.for("react.module.reference");function Ye(w){return!!(typeof w=="string"||typeof w=="function"||w===r||w===o||te||w===i||w===d||w===h||W||w===m||U||F||re||typeof w=="object"&&w!==null&&(w.$$typeof===x||w.$$typeof===p||w.$$typeof===l||w.$$typeof===c||w.$$typeof===u||w.$$typeof===Ae||w.getModuleId!==void 0))}function yi(w,I,E){var N=w.displayName;if(N)return N;var H=I.displayName||I.name||"";return H!==""?E+"("+H+")":E}function pn(w){return w.displayName||"Context"}function ct(w){if(w==null)return null;if(typeof w.tag=="number"&&P("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 pn(I)+".Consumer";case l:var E=w;return pn(E._context)+".Provider";case u:return yi(w,w.render,"ForwardRef");case p:var N=w.displayName||null;return N!==null?N:ct(w.type)||"Memo";case x:{var H=w,se=H._payload,X=H._init;try{return ct(X(se))}catch{return null}}}return null}var It=Object.assign,hn=0,Nc,Fc,Gc,Wc,Rc,Qc,Uc;function Kc(){}Kc.__reactDisabledLog=!0;function nI(){{if(hn===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})}hn++}}function sI(){{if(hn--,hn===0){var w={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:It({},w,{value:Nc}),info:It({},w,{value:Fc}),warn:It({},w,{value:Gc}),error:It({},w,{value:Wc}),group:It({},w,{value:Rc}),groupCollapsed:It({},w,{value:Qc}),groupEnd:It({},w,{value:Uc})})}hn<0&&P("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var bi=D.ReactCurrentDispatcher,vi;function as(w,I,E){{if(vi===void 0)try{throw Error()}catch(H){var N=H.stack.trim().match(/\n( *(at )?)/);vi=N&&N[1]||""}return`
|
|
18
|
+
`+vi+w}}var ji=!1,os;{var rI=typeof WeakMap=="function"?WeakMap:Map;os=new rI}function Yc(w,I){if(!w||ji)return"";{var E=os.get(w);if(E!==void 0)return E}var N;ji=!0;var H=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var se;se=bi.current,bi.current=null,nI();try{if(I){var X=function(){throw Error()};if(Object.defineProperty(X.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(X,[])}catch(ut){N=ut}Reflect.construct(w,[],X)}else{try{X.call()}catch(ut){N=ut}w.call(X.prototype)}}else{try{throw Error()}catch(ut){N=ut}w()}}catch(ut){if(ut&&N&&typeof ut.stack=="string"){for(var K=ut.stack.split(`
|
|
19
|
+
`),Se=N.stack.split(`
|
|
20
|
+
`),ce=K.length-1,he=Se.length-1;ce>=1&&he>=0&&K[ce]!==Se[he];)he--;for(;ce>=1&&he>=0;ce--,he--)if(K[ce]!==Se[he]){if(ce!==1||he!==1)do if(ce--,he--,he<0||K[ce]!==Se[he]){var Ge=`
|
|
21
|
+
`+K[ce].replace(" at new "," at ");return w.displayName&&Ge.includes("<anonymous>")&&(Ge=Ge.replace("<anonymous>",w.displayName)),typeof w=="function"&&os.set(w,Ge),Ge}while(ce>=1&&he>=0);break}}}finally{ji=!1,bi.current=se,sI(),Error.prepareStackTrace=H}var Rt=w?w.displayName||w.name:"",lu=Rt?as(Rt):"";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 N=w,H=N._payload,se=N._init;try{return ls(se(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,N,H){{var se=Function.call.bind(cs);for(var X in w)if(se(w,X)){var K=void 0;try{if(typeof w[X]!="function"){var Se=Error((N||"React class")+": "+E+" type `"+X+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof w[X]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw Se.name="Invariant Violation",Se}K=w[X](I,X,N,E,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(ce){K=ce}K&&!(K instanceof Error)&&(us(H),P("%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).",N||"React class",E,X,typeof K),us(null)),K instanceof Error&&!(K.message in Xc)&&(Xc[K.message]=!0,us(H),P("Failed %s type: %s",E,K.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 P("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 xn=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"&&xn.current&&I&&xn.current.stateNode!==I){var E=ct(xn.current.type);Ci[E]||(P('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',ct(xn.current.type),w.ref),Ci[E]=!0)}}function fI(w,I){{var E=function(){eu||(eu=!0,P("%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,P("%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,N,H,se,X){var K={$$typeof:t,type:w,key:I,ref:E,props:X,_owner:se};return K._store={},Object.defineProperty(K._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(K,"_self",{configurable:!1,enumerable:!1,writable:!1,value:N}),Object.defineProperty(K,"_source",{configurable:!1,enumerable:!1,writable:!1,value:H}),Object.freeze&&(Object.freeze(K.props),Object.freeze(K)),K};function yI(w,I,E,N,H){{var se,X={},K=null,Se=null;E!==void 0&&(Hc(E),K=""+E),hI(I)&&(Hc(I.key),K=""+I.key),pI(I)&&(Se=I.ref,xI(I,H));for(se in I)cs.call(I,se)&&!dI.hasOwnProperty(se)&&(X[se]=I[se]);if(w&&w.defaultProps){var ce=w.defaultProps;for(se in ce)X[se]===void 0&&(X[se]=ce[se])}if(K||Se){var he=typeof w=="function"?w.displayName||w.name||"Unknown":w;K&&fI(X,he),Se&&gI(X,he)}return mI(w,K,Se,H,N,xn.current,X)}}var _i=D.ReactCurrentOwner,nu=D.ReactDebugCurrentFrame;function Wt(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 Si;Si=!1;function ki(w){return typeof w=="object"&&w!==null&&w.$$typeof===t}function su(){{if(_i.current){var w=ct(_i.current.type);if(w)return`
|
|
22
22
|
|
|
23
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 ru={};function
|
|
25
|
+
Check your code at `+I+":"+E+"."}return""}}var ru={};function vI(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 iu(w,I){{if(!w._store||w._store.validated||w.key!=null)return;w._store.validated=!0;var 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=vI(I);if(ru[E])return;ru[E]=!0;var N="";w&&w._owner&&w._owner!==_i.current&&(N=" It was passed a child from "+ct(w._owner.type)+"."),Wt(w),P('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',E,N),Wt(null)}}function au(w,I){{if(typeof w!="object")return;if(wi(w))for(var E=0;E<w.length;E++){var N=w[E];ki(N)&&iu(N,I)}else if(ki(w))w._store&&(w._store.validated=!0);else if(w){var H=S(w);if(typeof H=="function"&&H!==w.entries)for(var se=H.call(w),X;!(X=se.next()).done;)ki(X.value)&&iu(X.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===u||I.$$typeof===p))E=I.propTypes;else return;if(E){var N=ct(I);oI(E,w.props,"prop",N,w)}else if(I.PropTypes!==void 0&&!Si){Si=!0;var H=ct(I);P("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",H||"Unknown")}typeof I.getDefaultProps=="function"&&!I.getDefaultProps.isReactClassApproved&&P("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 N=I[E];if(N!=="children"&&N!=="key"){Wt(w),P("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",N),Wt(null);break}}w.ref!==null&&(Wt(w),P("Invalid attribute `ref` supplied to `React.Fragment`."),Wt(null))}}function ou(w,I,E,N,H,se){{var X=Ye(w);if(!X){var K="";(w===void 0||typeof w=="object"&&w!==null&&Object.keys(w).length===0)&&(K+=" 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?K+=Se:K+=su();var ce;w===null?ce="null":wi(w)?ce="array":w!==void 0&&w.$$typeof===t?(ce="<"+(ct(w.type)||"Unknown")+" />",K=" Did you accidentally export a JSX literal instead of a component?"):ce=typeof w,P("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",ce,K)}var he=yI(w,I,E,H,se);if(he==null)return he;if(X){var Ge=I.children;if(Ge!==void 0)if(N)if(wi(Ge)){for(var Rt=0;Rt<Ge.length;Rt++)au(Ge[Rt],w);Object.freeze&&Object.freeze(Ge)}else P("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(Ge,w)}return w===r?wI(he):jI(he),he}}function CI(w,I,E){return ou(w,I,E,!0)}function _I(w,I,E){return ou(w,I,E,!1)}var SI=_I,kI=CI;Yt.Fragment=r,Yt.jsx=SI,Yt.jsxs=kI}()),Yt}process.env.NODE_ENV==="production"?ps.exports=ed():ps.exports=td();var s=ps.exports;const rt={CryptoJS:Ti,d3Array:Hu,dayjs:z,lodash:y,numbro:fn,mathjs:Mt,faker:cu.faker},nd=[{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"}],sd=e=>`
|
|
28
28
|
<tr>
|
|
29
29
|
<td><code>${e.name}</code></td>
|
|
30
30
|
<td>
|
|
@@ -36,50 +36,50 @@ Check the top-level render call using <`+E+">.")}return I}}function iu(w,I){{if(
|
|
|
36
36
|
>
|
|
37
37
|
</td>
|
|
38
38
|
</tr>
|
|
39
|
-
`,
|
|
39
|
+
`,rd=e=>`
|
|
40
40
|
<p>
|
|
41
|
-
|
|
41
|
+
${e("function_utils.description")}
|
|
42
42
|
</p>
|
|
43
43
|
<table>
|
|
44
44
|
<thead>
|
|
45
45
|
<tr>
|
|
46
|
-
<th
|
|
47
|
-
<th
|
|
46
|
+
<th>${e("common.name")}</th>
|
|
47
|
+
<th>${e("function_utils.document")}</th>
|
|
48
48
|
</tr>
|
|
49
49
|
</thead>
|
|
50
50
|
<tbody>
|
|
51
|
-
${
|
|
51
|
+
${nd.map(sd).join("")}
|
|
52
52
|
</tbody>
|
|
53
53
|
</table>
|
|
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
|
|
55
|
-
`),
|
|
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.3.1",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
|
-
`)},
|
|
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 id({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 ad(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 od(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 ld(e,t){let n=od(e);return n+="&key="+t,Zu.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:ld({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 nt(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 cd{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 fs(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=f.forwardRef(function({value:t,onChange:n,...r},i){return s.jsx(a.TextInput,{ref:i,value:t,onChange:n,...r})});function A(e){const[t,n]=e.split(".");return{queryID:t,columnKey:n}}function ud(e){return e.includes(".")?A(e):{queryID:"",columnKey:e}}function Ze(e,t){var i;const{queryID:n,columnKey:r}=A(t);return n?r?((i=e[n])==null?void 0:i.map(o=>o[r]))??[]:e[n]:[]}function Jt(e,t){const{queryID:n}=A(t);return n?e[n]:[]}function dd(e){return Object.values(e)[0]}function yn(e,t){const{queryID:n,columnKey:r}=A(t);return e[r]}const ta=["function aggregation({ queryData }, utils) {",' return "Aggregation Result";',"}"].join(`
|
|
55
|
+
`),At={type:"none",config:{},fallback:"0"};function pd(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 hd(e,t){switch(t.type){case"sum":return y.sum(e);case"mean":return y.mean(e);case"median":return pd(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 gs(e,t){const n=e.map(Number),r=hd(n,t);return typeof r=="number"?Number.isFinite(r)?r:t.fallback:r??t.fallback}function xd(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"?xd(e,t,n):gs(Ze(e,t),n)}catch(r){return console.error(r),null}}class fd{constructor({valueRange:t,colorRange:n}){L(this,"mapper");this.mapper=bt.interpolate(t,n)}getColor(t){return this.mapper(t)}}const ye={mantissa:0,output:"number",trimMantissa:!1,average:!1,absolute:!1};function R(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 gd(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 gd(n);if(t.type==="custom")return n;try{return R(n,e)}catch(r){return console.error(r),n}}function md(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 fd(e).getColor(t)}catch(n){return console.error(n),"black"}return"black"}function yd(e,t){const{color:n,data_field:r,aggregation:i,size:o,weight:l}=e,c=bn(t,r,i),u=Pe(e,c);return s.jsx(a.Text,{sx:{fontSize:o,display:"inline"},color:md(n,c),weight:l,children:u})}function bd(e,t){const n={};return e.forEach(r=>{const i=r.name;n[i]=yd(r,t)}),n}function vd(e){return e.split(" ").map((t,n)=>s.jsxs(f.Fragment,{children:[t," "]},n))}function jd(e){const n=e.replaceAll("<br />","<br/>").replaceAll(`
|
|
56
|
+
`,"<br/>").split("<br/>");return n.map((i,o)=>{const l=[vd(i)];return o!==n.length-1&&l.push(s.jsx("br",{},`br-${o}`)),l}).flat().filter(i=>i!==void 0)}function ms(e){return jd(e)}function Zt(e,t,n){const r=bd(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(f.Fragment,{children:[u,ms(d)]},`${o}-${l}`)})}function wd(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]=wd(r,t)}),n}function vn(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 Cd(){ve.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(){Cd()}function*_d(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 f.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 Sd(e,t={handleError:!0}){return n=>s.jsx(je,{...t,children:s.jsx(e,{...n})})}function kd(e,t){return new Function(`return ${e}`)()(t,rt)}function Td(e,t,n){return kd(e,{context:t,filters:n})}function Dd(e,t){try{return new Function(`return ${e.config.processing.pre}`)()(t,rt)}catch(n){return console.error(n),t}}function Id(e,t){return new Function(`return ${e.config.processing.post}`)()(t,rt)}function Md(e,t,n){return e?new Function(`return ${e}`)()(t,rt,n):t}function ia(){Di.use([du.CanvasRenderer,Xe.BarChart,Xe.BoxplotChart,Xe.CustomChart,Xe.FunnelChart,Xe.HeatmapChart,Xe.LineChart,Xe.PieChart,Xe.RadarChart,Xe.ScatterChart,Xe.SunburstChart,dt.CalendarComponent,dt.DataZoomComponent,dt.GridComponent,dt.LegendComponent,dt.TooltipComponent,dt.MarkLineComponent,dt.MarkAreaComponent,dt.VisualMapComponent])}const Et=e=>y.cloneDeepWith(e,(t,n)=>{if(n!==void 0&&t)return Y.toJS(t)}),jn={sqlSnippet:new RegExp("(?<=sql_snippets\\.)([^\\?}.]+)","gm"),context:new RegExp("(?<=context\\.)([^\\?}.]+)","gm"),filter:new RegExp("(?<=filters\\.)([^\\?}.]+)","gm")};function zd(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 Ad({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=id({sql:h,pre_process:u}),x=Ii.encode(p);zd(p,x);let m=await Je.query(i)({type:o,key:l,query:x,...r},{params:{name:t}});return m=ad(d,m,bs(n)),m}async function Ed({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 aa(){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 oa{constructor(t){L(this,"rootRef");this.rootRef=Y.observable({current:t})}async deleteItem(t){Y.runInAction(()=>{y.unset(this.rootRef.current,[t])})}getItem(t){const n=this.getValueFromRoot(t);return Promise.resolve(n)}getValueFromRoot(t){return t===null?Y.toJS(this.rootRef.current):y.get(this.rootRef.current,[t])}setItem(t,n){if(t===null)if(y.isObject(n))Y.runInAction(()=>{this.rootRef.current=n});else throw new Error("Cannot set root value to non-object");else Y.runInAction(()=>{y.set(this.rootRef.current,[t],n)});return Promise.resolve(this.getItem(t))}watchItem(t,n,r){return Y.reaction(()=>this.getValueFromRoot(t),(i,o)=>{n(i,o)},{requiresObservable:!0,fireImmediately:y.get(r,"fireImmediately",!1)})}}class Pd{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 Ld{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 Pd,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 Bd=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"])})},Od=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=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()}},$d={type:"interpolation",displayName:"Red / Green",getColor:ca(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},qd={type:"interpolation",displayName:"Yellow / Blue",getColor:ca(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},Vd={type:"interpolation",displayName:"Red",getColor:wn(["#fff7f1","darkred"]),name:"red",category:"sequential"},Nd={type:"interpolation",displayName:"Green",getColor:wn(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},Fd={type:"interpolation",displayName:"Blue",getColor:wn(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},Gd={type:"interpolation",displayName:"Orange",getColor:wn(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class Wd{constructor(t){L(this,"symbol");this.symbol=Symbol(t)}}function at(e){return new Wd(e)}class js{constructor(){L(this,"parent");L(this,"factoryRegistry",new Map);L(this,"instanceRegistry",new Map)}createScoped(){const t=new js;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.4.2",Rd=Object.freeze(Object.defineProperty({__proto__:null,version:ua},Symbol.toStringTag,{value:"Module"}));class Qd{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 Ud{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 Kd{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(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 oe extends Kd{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]=f.useState();f.useEffect(()=>(e.getItem(t).then(c=>{o(c),r()}),e.watchItem(t,c=>{o(c)})));const l=f.useCallback(async c=>{await e.setItem(t,c),o(c)},[e,t]);return{loading:n,value:i,set:l}},ke={top:16,right:16,bottom:16,left:16},Re=e=>Math.max(0,e-ke.left-ke.right),Qe=e=>Math.max(0,e-ke.top-ke.bottom),Ht=(e,t)=>({width:Re(e),height:Qe(t)}),Te=({width:e,height:t,children:n})=>s.jsx(a.Box,{pt:ke.top,pr:ke.right,pb:ke.bottom,pl:ke.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 Yd({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:c,xAxis3D:u,yAxis3D:d,zAxis3D:h}=y.defaults({},t,ws),p=f.useMemo(()=>Jt(n,o),[n,o]),{x,y:m,z:v}=f.useMemo(()=>({x:A(o),y:A(l),z:A(c)}),[o,l,c]),{min:C,max:S}=f.useMemo(()=>{const P=y.minBy(p,U=>U[v.columnKey]),q=y.maxBy(p,U=>U[v.columnKey]);return{min:y.get(P,v.columnKey),max:y.get(q,v.columnKey)}},[p,v]),D={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:C,max:S,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(P=>[P[x.columnKey],P[m.columnKey],P[v.columnKey]])}]};return t?s.jsx(Te,{width:r,height:i,children:s.jsx(Ce,{echarts:ve,option:D,style:Ht(r,i),notMerge:!0,theme:"merico-light"})}):null}const da=f.createContext(null),Cs=da.Provider;function _s(){const e=f.useContext(da);if(!e)throw new Error("Please use DashboardModelContextProvider");return e}const J=()=>_s(),pa=()=>_s(),ha=f.createContext({searchButtonProps:{}}),Ss=ha.Provider;function xa(){return f.useContext(ha)}const fa=f.createContext(null),ks=fa.Provider;function ga(){const e=f.useContext(fa);if(!e)throw new Error("Please use ContentModelContextProvider");return e}const Q=()=>ga(),ue=()=>ga(),Xd={inEditMode:!1},Cn=f.createContext(Xd),ma=f.createContext({panel:null,data:{},loading:!1,errors:[],downloadPanelScreenshot:()=>{}}),Ts=ma.Provider;function ya(){const e=f.useContext(ma);if(!e.panel)throw new Error("Please use PanelContextProvider");return e}const gt=()=>ya(),Le=()=>ya(),Jd={fullScreenPanelID:"",setFullScreenPanelID:y.noop},Ds=f.createContext(Jd);function ba(){const e=f.useContext(Ds);if(!e)throw new Error("Please use FullScreenPanelContext.Provider");return e}const O=_.observer(f.forwardRef(({label:e,required:t,value:n,onChange:r,clearable:i=!1,sx:o,...l},c)=>{const{panel:u}=Le(),d=f.useMemo(()=>u.dataFieldOptions(n,i),[n,i]);if(console.log({options:d}),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 Zd({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=y.defaults({},t,ws),{control:i,handleSubmit:o,reset:l}=b.useForm({defaultValues:r});return f.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(O,{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(O,{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(O,{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(T.DeviceFloppy,{size:20}),s.jsx(a.Text,{ml:"md",children:"Save"})]})})]})}):null}function Hd(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 ep extends oe{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:Hd(i,r)}})}}const tp={displayName:"Bar Chart (3D)",displayGroup:"ECharts-based charts",migrator:new ep,name:"bar-3d",viewRender:Yd,configRender:Zd,createConfig(){return{version:2,config:y.cloneDeep(ws)}}},Be={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
57
|
+
`)},va={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:sp,configRender:np,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 np(e){return s.jsx(s.Fragment,{})}function sp(e){return s.jsx(a.Text,{children:"Click chart's series"})}const rp=[{label:"Truncate",value:"truncate"},{label:"Break Line",value:"break"},{label:"Break Word",value:"breakAll"}],_n=f.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:rp,value:t.overflow,onChange:i("overflow")}),s.jsx(a.TextInput,{label:"Ellipsis",value:t.ellipsis,disabled:!0})]})]})}),Ue=f.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(_n,{sectionTitle:"Overflow on Axis",value:e.on_axis,onChange:r}),s.jsx(_n,{sectionTitle:"Overflow in Tooltip",value:e.in_tooltip,onChange:i})]})});function De(){return{on_axis:{width:80,overflow:"truncate",ellipsis:"..."},in_tooltip:{width:200,overflow:"break",ellipsis:"..."}}}function Oe({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 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=>`
|
|
63
|
+
`}function $e(e){return{width:e.width,overflow:e.overflow,ellipsis:e.ellipsis}}const vt={x_axis_scroll:!1,y_axis_scroll:!1,x_axis_slider:!1,y_axis_slider:!1};function ja(){return y.cloneDeep(vt)}const Is={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...Be},overflow:De()}},y_axis:{name:"Y Axis",data_key:"value",label_formatter:ye},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 jt(e,t){return f.useMemo(()=>{const{queryID:n,columnKey:r}=A(t);return y.keyBy(e[n],r)},[e,t])}const qe=(e,t)=>{const[n,r]=f.useState([]);return f.useEffect(()=>e.watchTriggerSnapshotList(i=>r(i.filter(o=>o.schemaRef===t))),[]),n};class Pt{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){L(this,"attachmentStorage");this.instance=t,this.attachmentKey=n,this.constructInstance=r,this.attachmentStorage=new Pt(t.instanceData,n)}async getInstance(t){if(await this.attachmentStorage.getItem(t))return this.constructInstance(new Pt(this.attachmentStorage,t))}async create(t,n){return await this.attachmentStorage.setItem(t,n),this.constructInstance(new Pt(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 Pt(this.attachmentStorage,n.id))))}}function ip(e,t){const{value:n,set:r}=$(e.operation.operationData,"config"),[i,o]=f.useState(y.defaults({},n,t)),l=async()=>{await r(i)};return f.useEffect(()=>{o(y.defaults({},n,t))},[n]),{config:i,setConfig:o,commit:l}}function ap(e){const{config:t,setConfig:n,commit:r}=ip(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 op(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 lp extends oe{constructor(){super(...arguments);L(this,"VERSION",1)}configVersions(){this.version(1,n=>n)}}const cp={displayName:"Open Link",id:"builtin:op:open-link",configRender:ap,run:op,migrator:new lp,createDefaultConfig:()=>({version:1,config:{urlTemplate:"",openInNewTab:!0}})};function up(e){const{value:t,set:n}=$(e.operationData,"config"),r=i=>void n({template:i});return[(t==null?void 0:t.template)||"",r]}function dp(e){const[t,n]=up(e.operation);return s.jsx(a.TextInput,{defaultValue:t,onBlur:r=>n(r.currentTarget.value),label:"console.log"})}async function pp(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 hp={displayName:"console.log (debug)",id:"builtin:op:debug",configRender:dp,run:pp},xp=_.observer(e=>{const t=Q(),{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 fp(e,t){const r=(await t.operationData.getItem("config")).viewID;window.dispatchEvent(new CustomEvent("open-view",{detail:{viewID:r}}))}const gp={displayName:"Open View",id:"builtin:op:open_view",configRender:xp,run:fp},mp={"tbody tr":{opacity:.5,transition:"opacity 200ms ease"},"tr[data-affected=true]":{opacity:1}},yp=({value:e="",onChange:t})=>{const[n,r]=f.useState(e);f.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(k.IconDeviceFloppy,{})})})},bp={dictionary:{}},vp=_.observer(e=>{const t=Q(),{value:n=bp,set:r}=$(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:mp,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(yp,{value:i[l.value],onChange:u=>o(l.value,u)})})]},l.value)})})]})});async function jp(e,t){const r=(await t.operationData.getItem("config")).dictionary;window.dispatchEvent(new CustomEvent("set-filter-values",{detail:{dictionary:r,payload:e}}))}const wp={displayName:"Set Filter Values",id:"builtin:op:set_filter_values",configRender:vp,run:jp},Cp={filter_keys:[]},_p=_.observer(e=>{const t=Q(),{value:n=Cp,set:r}=$(e.operation.operationData,"config"),{filter_keys:i=[]}=n,o=c=>{r({filter_keys:[...c]})},l=f.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 Sp(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=[hp,cp,gp,wp,{displayName:"Clear Filter Values",id:"builtin:op:clear_filter_values",configRender:_p,run:Sp}];class kp{constructor(t,n=Sn){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 Pt(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 Tp{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 Pt(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:Y.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){L(this,"operationManager");L(this,"triggerManager");L(this,"attachments");this.operationManager=new kp(t,r),this.triggerManager=new Tp(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 Ve=({vizManager:e,instance:t})=>V.useCreation(()=>new zs(t,e.resolveComponent(t.type),Sn),[t,e]),Ca=e=>{const{title:t="Variables",variables:n}=e,r=ie.useClipboard(),i=o=>{r.copy(o),pt.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 Dp{constructor(t,n){L(this,"operationId");L(this,"operation");L(this,"operationSchema");L(this,"variables",[]);this.operationManager=t,this.instance=n,Y.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));Y.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 Ip(e){return!!e.operationId}const Mp=_.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})}),zp=_.observer(({model:e})=>{const t={operation:e.operation,instance:e.instance,variables:[]};return f.createElement(e.operationSchema.configRender,t)}),Ap=_.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})}),Ep=_.observer(e=>{const[t,{setTrue:n,setFalse:r}]=V.useBoolean(!1),{operationManager:i,operationId:o,instance:l,variables:c}=e,u=V.useCreation(()=>new Dp(i,l),[i,l]);return V.useAsyncEffect(async()=>{await u.configOperation(o,c)},[o,u]),Ip(u)?s.jsxs(s.Fragment,{children:[s.jsx(Mp,{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(Ap,{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(zp,{model:u})}),s.jsx(a.Tabs.Panel,{value:"variables",pt:10,children:s.jsx(Ca,{title:"Variables",variables:u.variables})})]})]})})]}):null});class Pp{constructor(t,n){L(this,"triggerId");L(this,"trigger");L(this,"triggerSchema");L(this,"sampleData");this.triggerManager=t,this.instance=n,Y.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));Y.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 Lp(this)}}function Lp(e){return!!e.triggerId&&!!e.triggerSchema}function Bp(e,t){return V.useCreation(()=>new Pp(e,t),[e,t])}const Op=_.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:f.createElement(n,r)})}),$p=_.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})}),qp=_.observer(({model:e})=>{const t={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return f.createElement(e.triggerSchema.configRender,t)}),Vp=_.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($p,{model:i}),s.jsx(qp,{model:i}),s.jsx(Ca,{title:"Payload",variables:i.triggerSchema.payload})]})}),s.jsx(Op,{onClick:n,model:i})]})});function Np(e,t){const[n,r]=f.useState([]);return V.useAsyncEffect(async()=>{const i=await e.getInteractionList();r(i)},[t,e]),n}const Fp=_.observer(({item:e,manager:t,instance:n,sampleData:r,variables:i,onRemove:o})=>{const{triggerRef:l,operationRef:c}=e,u=Bp(t.triggerManager,n);if(V.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(Vp,{model:u}),s.jsx(Ep,{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(T.Trash,{size:16})})]})}return null}),Gp=e=>{const{t}=M.useTranslation(),[n,r]=f.useState(0),{interactionManager:i,instance:o,sampleData:l,variables:c}=e,u=Np(i,n),d=async()=>{const m=await i.triggerManager.createOrGetTrigger(ie.randomId(),i.triggerManager.getTriggerSchemaList()[0]),v=await i.operationManager.createOrGetOperation(ie.randomId(),i.operationManager.getOperationSchemaList()[0]);await i.addInteraction(m,v),r(C=>C+1)};async function h(m){await i.removeInteraction(m.id),r(v=>v+1)}const{data:p=0,loading:x}=V.useRequest(async()=>{try{return(await i.triggerManager.getTriggerSchemaList()).length}catch{return 0}});return s.jsxs(a.Stack,{children:[s.jsx(a.LoadingOverlay,{visible:x}),p===0&&s.jsx(a.Alert,{icon:s.jsx(T.AlertCircle,{size:16}),title:"Unavailable",color:"gray",children:"This visualization does not have available interactions to choose from"}),u.map(m=>s.jsx(Fp,{onRemove:h,instance:o,sampleData:l,variables:c,item:m,manager:e.interactionManager},m.id)),s.jsx(a.Button,{style:{width:"fit-content"},onClick:()=>d(),disabled:p===0,children:t("interactions.add")})]})},Wp=()=>{const{panel:e,data:t}=gt(),n=e.viz,{vizManager:r}=f.useContext(tt),i=e.json,o=V.useCreation(()=>r.getOrCreateInstance(i),[r,i]),l=V.useCreation(()=>new zs(o,r.resolveComponent(n.type),Sn),[o,n.type]);return f.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:[]}},Rp=()=>{const e=Wp();return s.jsx(Gp,{...e})},_a={axisTick:{show:!0,alignWithLabel:!0,lineStyle:{width:2}},axisLine:{show:!0,lineStyle:{width:3}},splitLine:{show:!1},z:3};function Qp(e){return y.defaultsDeep({},e,_a)}const Up=Object.freeze(Object.defineProperty({__proto__:null,getXAxis:Qp,xAxis:_a},Symbol.toStringTag,{value:"Module"})),Sa={axisTick:{show:!1},axisLine:{show:!1,lineStyle:{width:3}},splitLine:{show:!0,lineStyle:{type:"dashed"}}};function Kp(e){return y.defaultsDeep({},e,Sa)}const Yp=Object.freeze(Object.defineProperty({__proto__:null,getYAxis:Kp,yAxis:Sa},Symbol.toStringTag,{value:"Module"})),ka={confine:!0,appendToBody:!0};function Xp(e){return y.defaultsDeep({},e,ka)}const ee={...Up,...Yp,...Object.freeze(Object.defineProperty({__proto__:null,getTooltip:Xp,tooltip:ka},Symbol.toStringTag,{value:"Module"}))};function Lt({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 Jp(e,t){const n=[],r=[];return{boxplotData:Object.entries(e).map(([o,l])=>{const c=l.map(D=>D[t]).sort((D,P)=>D-P),u=Qt.quantile(c,.25)??0,d=Qt.quantile(c,.5)??0,h=Qt.quantile(c,.75)??0,p=h-u,x=u-1.5*p,m=h+1.5*p,v=Math.max(c[0],x),C=Math.min(y.last(c)??0,m);return l.filter(D=>{const P=D[t];return P<v||P>C}).forEach(D=>n.push([o,D[t],D])),l.filter(D=>{const P=D[t];return P>=v&&P<=C}).forEach(D=>r.push([o,D[t],D])),{name:o,min:v,q1:u,median:d,q3:h,max:C}}),outliersData:n,scatterData:r}}function Zp(e,t){const{x_axis:n,y_axis:r}=e;if(!n.data_key||!r.data_key)return[];const i=A(n.data_key),o=A(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}=Jp(l,o.columnKey);return[{source:c},{source:u},{source:d}]}function Hp(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 eh({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 th(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 vn(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 nh(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,v={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},S={type:"group",children:[]},D=[{x1:v.max[0]+C.left,x2:v.max[0]+C.right,y1:v.max[1],y2:v.max[1]},{x1:v.median[0]+C.left,x2:v.median[0]+C.right,y1:v.median[1],y2:v.median[1]},{x1:v.min[0]+C.left,x2:v.min[0]+C.right,y1:v.min[1],y2:v.min[1]},{x1:v.min[0]+C.center,x2:v.min[0]+C.center,y1:v.min[1],y2:v.q1[1]},{x1:v.max[0]+C.center,x2:v.max[0]+C.center,y1:v.max[1],y2:v.q3[1]}],P={stroke:i,lineWidth:o};return D.forEach(q=>{S.children.push({type:"line",shape:q,style:P})}),S.children.push({type:"rect",shape:{x:v.q1[0]+C.left,y:v.q1[1],width:C.right-C.left,height:v.q3[1]-v.q1[1]},style:{fill:r,stroke:i,lineWidth:o}}),S}function sh(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)=>nh(e,o,r),r}function rh(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 ih(){const e={name:"Scatter",type:"custom",itemStyle:{color:"#ED6A45"},emphasis:{scale:2},datasetIndex:2};return e.renderItem=(t,n)=>rh(n),e}function ah(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 oh(){const e={name:"Outlier",type:"custom",itemStyle:{color:"#ED6A45"},emphasis:{scale:2},datasetIndex:1};return e.renderItem=(t,n)=>ah(n),e}function lh(e,t){const n=t[0],r=sh(n,e),i=ih(),o=oh();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 ch=(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
|
-
${
|
|
67
|
+
${R(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="${
|
|
71
|
+
<div style="${Oe(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
|
-
`},
|
|
78
|
+
`},uh=e=>R(e,{output:"number",trimMantissa:!0,mantissa:2,absolute:!1});function Ta(e,t){return e.tooltip.metrics.map(n=>{const r=A(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;">${
|
|
82
|
-
</tr>`})}function
|
|
81
|
+
<td style="text-align: left; padding: 0 1em;">${uh(t[r.columnKey])}</td>
|
|
82
|
+
</tr>`})}function dh(e,t){const n=Oe(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>
|
|
@@ -92,7 +92,7 @@ Check the top-level render call using <`+E+">.")}return I}}function iu(w,I){{if(
|
|
|
92
92
|
${r.join("")}
|
|
93
93
|
</tbody>
|
|
94
94
|
</table>
|
|
95
|
-
`}function
|
|
95
|
+
`}function ph(e,t){const n=Oe(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>
|
|
@@ -105,17 +105,17 @@ Check the top-level render call using <`+E+">.")}return I}}function iu(w,I){{if(
|
|
|
105
105
|
${r.join("")}
|
|
106
106
|
</tbody>
|
|
107
107
|
</table>
|
|
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`
|
|
108
|
+
`}const hh=e=>t=>{const{seriesName:n,value:r}=t;switch(n){case"Box":return ch(e,r);case"Outlier":return dh(e,r);case"Scatter":return ph(e,r)}};function xh({config:e}){return ee.getTooltip({trigger:"item",formatter:hh(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 fh({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 gh({config:e,data:t,variables:n}){const{x_axis:r,y_axis:i,reference_lines:o}=e,l=Zp(e,t),c=$e(r.axisLabel.overflow.on_axis),u=lh(e,l);return{dataZoom:kn(e.dataZoom,"filter"),grid:Hp(e),dataset:l,legend:eh({config:e}),tooltip:xh({config:e}),xAxis:[ee.getXAxis({type:"category",name:r.name,nameGap:25,nameLocation:"center",nameTextStyle:{align:"center"},axisLabel:{...r.axisLabel,...c,formatter:Lt(r.axisLabel.formatter)}})],yAxis:[ee.getYAxis({name:i.name,minInterval:1,axisLabel:{formatter:function(d){return R(d,i.label_formatter)}},min:fh})],series:[...u,...th(o,n,t)]}}function mh({context:e,instance:t}){const{value:n}=$(e.instanceData,"config"),{variables:r}=e,i=e.data,{width:o,height:l}=e.viewport,c=y.defaults({},n,Is),u=Ve({vizManager:e.vizManager,instance:t}),d=qe(u.triggerManager,va.id),h=jt(i,c.x_axis.data_key),p=f.useCallback(v=>{const C=y.get(h,v.name,{error:"rowData is not found"});d.forEach(S=>{u.runInteraction(S.id,{...v,rowData:C})})},[h,d,u]),x=f.useMemo(()=>({click:p}),[p]),m=f.useMemo(()=>gh({config:c,data:i,variables:r}),[c,i,r]);return!n||!o||!l?null:s.jsx(Te,{width:o,height:l,children:s.jsx(Ce,{echarts:ve,option:m,style:Ht(o,l),onEvents:x,notMerge:!0,theme:"merico-light"})})}function yh({value:e,onChange:t},n){const{colorManager:r}=f.useContext(tt),i=f.useMemo(()=>r.getStaticColors().map(c=>({label:c.name,group:c.category,value:c.value})),[r]),o=f.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 _e=f.forwardRef(yh);function bh({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(T.Trash,{size:16})})]})}function vh({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=f.useMemo(()=>n.map(h=>({label:h.name,value:h.name})),[n]);return s.jsxs(a.Stack,{children:[c.map((h,p)=>s.jsx(bh,{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 jh=({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(ge,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},Tn=f.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:i,setFalse:o}]=V.useBoolean(),[l,c]=f.useState(e);f.useEffect(()=>{c(e)},[e]);const u=m=>{c({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:v}=l,C={enabled:m,func_content:v};c(C),t(C)},h=()=>{o(),c(e)},p=m=>{c(v=>({...v,func_content:m}))},x=()=>{p(Be.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(jh,{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(T.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"})]})]})]})})]})}),wh=({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(Ue,{...n})})]})),Ls={root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}},Ch=["123456789","1234","1234.56789","1.234","0.123456789","-0.123456789"];function _h({format:e}){const{t}=M.useTranslation(),[n,{toggle:r}]=ie.useDisclosure(!1);return s.jsxs(a.Box,{children:[s.jsx(a.Button,{variant:"subtle",w:"100%",compact:!0,onClick:r,leftIcon:n?s.jsx(k.IconChevronUp,{size:14}):s.jsx(k.IconChevronDown,{size:14}),children:t(n?"numbro.format.preview.close":"numbro.format.preview.open")}),s.jsx(a.Collapse,{in:n,children:n&&s.jsxs(a.Table,{highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:t("numbro.format.preview.input")}),s.jsx("th",{children:t("numbro.format.preview.output")})]})}),s.jsx("tbody",{children:Ch.map(i=>s.jsxs("tr",{children:[s.jsx("td",{children:i}),s.jsx("td",{children:s.jsx(je,{children:R(i,e)})})]},i))})]})})]})}function Sh({value:e,onChange:t},n){const{t:r}=M.useTranslation(),i=d=>{t({...e,output:d})},o=d=>{const h=d===0?!1:e.trimMantissa;t({...e,mantissa:d,trimMantissa:h})},l=d=>{t({...e,trimMantissa:d.currentTarget.checked})},c=d=>{t({...e,average:d.currentTarget.checked})},u=d=>{const h={...e,absolute:d.currentTarget.checked};t(h)};return console.log({value:e}),s.jsxs(a.Stack,{ref:n,children:[s.jsxs(a.Group,{grow:!0,children:[s.jsx(a.Select,{label:r("numbro.format.label"),data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:e.output,onChange:i,sx:{flexGrow:1}}),s.jsx(a.Switch,{label:s.jsxs(a.Stack,{spacing:0,children:[s.jsx(a.Text,{children:r("numbro.format.absolute")}),s.jsx(a.Text,{size:12,color:"gray",children:r("numbro.format.absolute_description")})]}),checked:e.absolute,onChange:u,sx:{flexGrow:1},styles:Ls}),s.jsx(a.Switch,{label:s.jsxs(a.Stack,{spacing:0,children:[s.jsx(a.Text,{children:r("numbro.format.abbreviation")}),s.jsx(a.Text,{size:12,color:"gray",children:r("numbro.format.abbreviation_description")})]}),checked:e.average,onChange:c,disabled:e.output!=="number",sx:{flexGrow:1},styles:Ls})]}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(a.NumberInput,{label:r("numbro.format.mantissa"),defaultValue:0,min:0,step:1,max:4,value:e.mantissa,onChange:o}),s.jsx(a.Switch,{label:s.jsxs(a.Stack,{spacing:0,children:[s.jsx(a.Text,{children:r("numbro.format.trim_mantissa")}),s.jsx(a.Text,{size:12,color:"gray",children:r("numbro.format.trim_mantissa_description")})]}),checked:e.trimMantissa,onChange:l,disabled:e.mantissa===0,styles:Ls}),s.jsx(a.Box,{})]}),s.jsx(_h,{format:e})]})}const Ne=f.forwardRef(Sh),kh=({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(Ne,{...n})})]})]})),Th=({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(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),Dh=({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]=f.useState(()=>u??null);return f.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(T.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(T.Plus,{size:18,color:"#228be6"})})]}),l.map((p,x)=>s.jsx(a.Tabs.Panel,{value:p.id,children:s.jsx(Th,{control:e,index:x,remove:i},p.id)},p.id))]})]})};function Ih({control:e,watch:t}){return s.jsx(a.Stack,{children:s.jsx(Dh,{control:e,watch:t})})}const Mh=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}],zh=({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:Mh,sx:{flex:1},value:i.value.orient,onChange:o=>{r(o,i.onChange)},disabled:!n.show})})})]})},Dn=f.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 Ah({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),{variables:r}=e,i=f.useMemo(()=>y.defaults({},t,Is),[t]),{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=b.useForm({defaultValues:i});f.useEffect(()=>{d(i)},[i]),c(["x_axis","y_axis","reference_lines","color","dataZoom"]);const h=u(),p=f.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(T.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(wh,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Y Axis",children:s.jsx(kh,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Legend",children:s.jsx(zh,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(Ih,{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(_e,{...x})})]})}),s.jsx(a.Tabs.Panel,{value:"Reference Lines",children:s.jsx(vh,{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(Dn,{...x})})})]})]})})}function Eh(e){return y.omit(e,"variables")}function Ph(e){const{label_formatter:t=ye,...n}=e.y_axis;return{...e,y_axis:{...n,label_formatter:t}}}function Lh(e){const t={rotate:0,formatter:{...Be}},{axisLabel:n=t,...r}=e.x_axis;return{...e,x_axis:{...r,axisLabel:n}}}function Bh(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 Oh(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 $h(e){const t={tooltip:{metrics:[]}};return y.defaultsDeep(t,e)}function qh(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 Vh(e){const t={legend:{show:!0,top:"0",right:"10",left:"auto",bottom:"auto",orient:"horizontal",type:"scroll"}};return y.defaultsDeep(t,e)}function Nh(e){const{dataZoom:t,...n}=e;return{...n,dataZoom:t??ja()}}class Fh extends oe{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(c=>c.name===l.name)||r.addVariable(l)}),{...n,version:2,config:Eh(i)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:Ph(r)}}),this.version(4,n=>{const{config:r}=n;return{...n,version:4,config:Lh(r)}}),this.version(5,n=>{const{config:r}=n;return{...n,version:5,config:Bh(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:Oh(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:$h(r)}}),this.version(8,(n,r)=>{const{config:i}=n;return{...n,version:8,config:qh(i,r)}}),this.version(9,n=>{const{config:r}=n;return{...n,version:9,config:Vh(r)}}),this.version(10,n=>{const{config:r}=n;return{...n,version:10,config:Nh(r)}})}}const Gh={displayName:"Boxplot Chart",displayGroup:"ECharts-based charts",migrator:new Fh,name:"boxplot",viewRender:mh,configRender:Ah,createConfig(){return{version:10,config:y.cloneDeep(Is)}},triggers:[va]},Da={id:"builtin:button:click-button",displayName:"Click Button",nameRender:Rh,configRender:Wh,payload:[]};function Wh(e){return s.jsx(s.Fragment,{})}function Rh(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"},Qh={left:"flex-start",center:"center",right:"flex-end"},Uh={top:"flex-start",center:"center",bottom:"flex-end"},Kh=_.observer(({context:e,instance:t})=>{const n=Ve({vizManager:e.vizManager,instance:t}),r=qe(n.triggerManager,Da.id),i=ue(),{value:o}=$(e.instanceData,"config"),l=f.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,v=()=>{r.forEach(C=>{n.runInteraction(C.id,{})})};return s.jsx(a.Center,{sx:{width:p,height:x,justifyContent:Qh[u],alignItems:Uh[d]},children:s.jsx(a.Button,{...h,onClick:v,children:y.template(c)(m)})})}),Yh=({value:e,onChange:t,label:n})=>{const r=a.useMantineTheme(),i=f.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)})})]})},Xh=a.MANTINE_SIZES.map(e=>({label:e.toUpperCase(),value:e})),Jh=({label:e,value:t,onChange:n})=>s.jsx(a.Select,{data:Xh,label:e,value:t,onChange:n}),Zh=[{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}],Hh=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],ex=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function tx({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},t,Bs),[t]),i=r;f.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});f.useEffect(()=>{d(i)},[i]);const h=u(),p=f.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(T.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:Zh,...x})}),s.jsx(b.Controller,{control:o,name:"color",render:({field:x})=>s.jsx(Yh,{label:"Theme",...x})})]}),s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(b.Controller,{control:o,name:"size",render:({field:x})=>s.jsx(Jh,{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:Hh,...x})}),s.jsx(b.Controller,{control:o,name:"vertical_align",render:({field:x})=>s.jsx(a.Select,{label:"Vertical Alignment",data:ex,...x})})]})]})]})}class nx extends oe{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 sx={displayName:"Button",displayGroup:"Others",migrator:new nx,name:"button",viewRender:Kh,configRender:tx,createConfig(){return{version:2,config:y.cloneDeep(Bs)}},triggers:[Da]},Os={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:ix,configRender:rx,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 rx(e){return s.jsx(s.Fragment,{})}function ix(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:{...Be},overflow:De()}},tooltip:{metrics:[]},x_axis_data_key:"",x_axis_name:"",y_axes:[{min:"",max:"",name:"Y Axis",show:!0,position:"left",nameAlignment:"center",label_formatter:ye}],reference_lines:[],reference_areas:[],dataZoom:vt};function ax(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 ox(e){return e!=="line"?{}:{itemStyle:{opacity:0}}}function lx(e){switch(e){case"line":return;case"bar":return"roundRect";case"scatter":return"circle"}}function cx(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:lx(r),...ox(r)})),t}function In(e,t){switch(e.config.method){case"linear":return[...ft.regressionLinear()(t)];case"exponential":return[...ft.regressionExp()(t)];case"logarithmic":return[...ft.regressionLog()(t)];case"polynomial":return[...ft.regressionPoly().order(e.config.order)(t)];default:return[]}}function ux(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 dx({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=ux(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=Ze(n,o.y_axis_data_key).map((x,m)=>[m,Number(x)]);i(o,l,"",p);return}const{columnKey:u}=A(o.y_axis_data_key),d=y.groupBy(Jt(n,o.y_axis_data_key),c);Object.entries(d).forEach(([h,p])=>{const x=p.map((v,C)=>[C,Number(v[u])]);i(o,h,h,x)})}),r}function px(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 hx(e,t,n,r){return t?r==="value"?[[n[0],e]]:[e]:[]}function xx(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=hx(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?vn(l.template,t,r):""},position:h}}}})}function fx({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}=A(r),u=y.keyBy(Jt(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: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 gx(e,t,n,r){const i=qs(t,n,r);return y.unionBy(i,e,0)}function mx({dataTemplate:e,data:t,x_axis_data_key:n,y_axis_data_key:r,valueTypedXAxis:i}){return i?gx(e,t,n,r):Ze(t,r)}function yx({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 mx({dataTemplate:e,data:t,x_axis_data_key:r,y_axis_data_key:i,valueTypedXAxis:o});const l=qs(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 bx({group_by_key:e,data:t,x_axis_data_key:n,y_axis_data_key:r}){const{queryID:i,columnKey:o}=A(e),l=y.groupBy(t[i],o);return Object.entries(l).forEach(([c,u])=>{l[c]=qs({[i]:u},n,r)}),l}function vx({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},v,C,S,D){const P=t.type!=="category",q={label:{show:!!i,position:i,formatter:D[r??"default"]},name:o,xAxisId:"main-x-axis",yAxisIndex:r,stack:u,color:d,symbolSize:fx(p,C,e,S),hide_in_legend:x,labelLayout:{hideOverlap:!0},...m};if(m.type==="line"&&(q.lineStyle={shadowColor:"rgba(255,255,255,1)",shadowBlur:0,shadowOffsetX:0,shadowOffsetY:3}),h&&(q.endLabel={show:!0,formatter:o,offset:[-12,12],align:"right"}),!l||l===e)return q.data=yx({dataTemplate:v,data:C,aggregation_on_value:c,x_axis_data_key:e,y_axis_data_key:n,valueTypedXAxis:P}),q;const U=bx({group_by_key:l,data:C,x_axis_data_key:e,y_axis_data_key:n});return Object.entries(U).map(([F,re])=>{const W=y.cloneDeep(q);return W.name=F,W.color=void 0,W.data=re,W})}function jx(e,t,n,r,i,o){const l=t.map(u=>[u,0]);return e.series.map(u=>vx(e,u,l,n,o,r)).flat().concat(xx(e.reference_lines,i,o,n,t,e.x_axis.type)).concat(px(e.reference_areas,o))}function wx(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 Lt(t.x_axis.axisLabel.formatter)(r,i)}const Cx=e=>R(e,{output:"number",trimMantissa:!0,mantissa:2,absolute:!1});function _x(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 v=i[p],C=r[v]??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
|
-
`}),u=e.tooltip.metrics.map(p=>{const x=
|
|
114
|
+
`}),u=e.tooltip.metrics.map(p=>{const x=Ze(t,p.data_key),m=y.uniq(l.map(({dataIndex:v})=>x[v]));return`<tr>
|
|
115
115
|
<td />
|
|
116
116
|
<th style="text-align: right; padding: 0 1em;">${p.name}</th>
|
|
117
|
-
${m.map(
|
|
118
|
-
</tr>`});c.push(...u);const d=
|
|
117
|
+
${m.map(v=>`<td style="text-align: left; padding: 0 1em;">${Cx(v)}</td>`)}
|
|
118
|
+
</tr>`});c.push(...u);const d=Oe(e.x_axis.axisLabel.overflow.in_tooltip),h=wx(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>
|
|
@@ -124,12 +124,12 @@ Check the top-level render call using <`+E+">.")}return I}}function iu(w,I){{if(
|
|
|
124
124
|
${c.join("")}
|
|
125
125
|
</tbody>
|
|
126
126
|
</table>
|
|
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&&
|
|
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=`
|
|
127
|
+
`}})}function Sx(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 R(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=it(r,e);n[r.name]=Pe(r,i)}),n}function kx(e,t){const{overflow:n,...r}=e.x_axis.axisLabel,i=$e(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:Lt(r.formatter)}})]}function Tx(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 Dx(e){if(e.length===0)return{};const t={},n={};return e.forEach(r=>{const i=Tx(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 Ix(e,t,n){const r=Dx(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 Mx={xAxis:[{type:"category",nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0}}]};function zx(e,t,n){const r=Ia(t,n),i=Sx(e),o=y.uniq(Ze(t,e.x_axis_data_key)),l=jx(e,o,t,i,n,r),c=dx(e,t),u={xAxis:kx(e,o),yAxis:Ix(e,i,l),series:[...l,...c],tooltip:_x(e,t,l,i),grid:ax(e),legend:cx(l),dataZoom:kn(e.dataZoom)};return y.defaultsDeep({},u,Mx)}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 Ax({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const l=jt(t,e.x_axis_data_key),c=qe(i.triggerManager,Os.id),u=f.useCallback(m=>{const v=y.get(l,m.name,{error:"rowData is not found"});c.forEach(C=>{i.runInteraction(C.id,{...m,rowData:v})})},[l,c,i]),d=f.useMemo(()=>zx(e,t,o),[e,t]),h=f.useRef(),p=f.useMemo(()=>({click:u}),[u]),x=m=>{h.current=m,Ma(m)};return f.useEffect(()=>{h.current&&Ma(h.current)},[d]),!n||!r?null:s.jsx(Ce,{echarts:ve,option:d,style:{width:n,height:r},onEvents:p,onChartReady:x,notMerge:!0,theme:"merico-light"})}function Ex({context:e,instance:t}){const n=Ve({vizManager:e.vizManager,instance:t}),{value:r}=$(e.instanceData,"config"),{variables:i}=e,o=f.useMemo(()=>y.defaults({},r,$s),[r]),l=e.data,{width:c,height:u}=e.viewport,{ref:d,height:h}=ie.useElementSize(),{ref:p,height:x}=ie.useElementSize(),m=f.useMemo(()=>{const{stats:{templates:S}}=o;return{top:Zt(S.top,i,l),bottom:Zt(S.bottom,i,l)}},[o,l]),v=Math.max(0,Qe(u)-h-x),C=Re(c);return s.jsxs(Te,{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((S,D)=>s.jsx(f.Fragment,{children:S},D))}),s.jsx(Ax,{variables:i,width:C,height:v,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((S,D)=>s.jsx(f.Fragment,{children:S},D))})]})}const Px=[{label:"Rectangle",value:"rectangle"}],Lx=[{label:"Horizontal",value:"horizontal"}];function Bx({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:Px,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:Lx,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(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Area"})]})}function Ox({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=f.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(T.Plus,{size:18,color:"#228be6"})})]}),c.map((h,p)=>s.jsx(a.Tabs.Panel,{value:p.toString(),children:s.jsx(Bx,{control:e,index:p,remove:o,variableOptions:d})},h.id))]})}const $x=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],qx=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Vx({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:qx,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:$x,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(_e,{...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(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]})}function Nx({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=f.useMemo(()=>n.map(x=>({label:x.name,value:x.name})),[n]),h=t("y_axes"),p=f.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(T.Plus,{size:18,color:"#228be6"})})]}),c.map((x,m)=>s.jsx(a.Tabs.Panel,{value:m.toString(),children:s.jsx(Vx,{control:e,index:m,remove:o,watch:t,variableOptions:d,yAxisOptions:p})},x.id))]})}const Fx=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}],Gx=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function Wx({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: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:Fx,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:Gx,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(_e,{...l})})]}),s.jsx(a.Button,{leftIcon:s.jsx(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(n),sx:{top:15,right:5},children:"Delete this Regression Line"})]})}function Rx({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=f.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(T.Plus,{size:18,color:"#228be6"})})]}),l.map((h,p)=>s.jsx(a.Tabs.Panel,{value:p.toString(),children:s.jsx(Wx,{regressionItem:h,control:e,index:p,remove:i,yAxisOptions:u})},h.id))]})}const Vs={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 Z{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 Z(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 Z(r,i)}cutByIndex(t,n){return t==n?Z.empty:t==0&&n==this.content.length?this:new Z(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 Z(i,o)}addToStart(t){return new Z([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new Z(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 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 Z.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new Z(n.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return Z.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 Z(n||t,r)}static from(t){if(!t)return Z.empty;if(t instanceof Z)return t;if(Array.isArray(t))return this.fromArray(t);if(t.attrs)return new Z([t],t.nodeSize);throw new RangeError("Can not convert "+t+" to a Fragment"+(t.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}Z.empty=new Z([],0);const Fs={index:0,offset:0};function Mn(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 Me{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 Me.none;if(t instanceof Me)return[t];let n=t.slice();return n.sort((r,i)=>r.type.rank-i.type.rank),n}}Me.none=[];class Qx extends Error{}class ne{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 ne(r,this.openStart,this.openEnd)}removeBetween(t,n){return new ne(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 ne.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 ne(Z.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 ne(t,r,i)}}ne.empty=new ne(Z.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 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 qa(this,n,!1);return r.addAll(t,n.from,n.to),r.finish()}parseSlice(t,n={}){let r=new qa(this,n,!0);return r.addAll(t,n.from,n.to),ne.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(Yx(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=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 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},Ux={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Oa={ol:!0,ul:!0},An=1,En=2,en=4;function $a(e,t,n){return t!=null?(t?An:0)|(t==="full"?En:0):e&&e.whitespace=="pre"?An|En:n&~en}class Pn{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=Me.none,this.stashMarks=[],this.match=l||(c&en?null:t.contentMatch)}findWrapping(t){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(Z.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=Z.from(this.content);return!t&&this.match&&(n=n.append(this.match.fillBefore(Z.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):Jx(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 qa{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?en:0);i?o=new Pn(i.type,i.attrs,Me.none,Me.none,!0,n.topMatch||i.type.contentMatch,l):r?o=new Pn(null,null,Me.none,Me.none,!0,null,l):o=new Pn(t.schema.topNodeType,null,Me.none,Me.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(Xx(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&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;Oa.hasOwnProperty(r)&&this.parser.normalizeLists&&Kx(t);let o=this.options.ruleFromNode&&this.options.ruleFromNode(t)||(i=this.parser.matchTag(t,this,n));if(o?o.ignore:Ux.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=Me.none,r=Me.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&en&&o.content.length==0&&(l|=en),this.nodes.push(new Pn(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=Zx(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 Kx(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 Yx(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function Xx(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 Jx(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 Zx(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 Hx(e,t){return e+t*Fa}function Ga(e){return e&Na}function ef(e){return(e-(e&Na))/Fa}const Wa=1,Ra=2,Ln=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|Ln))>0}get deletedAfter(){return(this.delInfo&(Ra|Ln))>0}get deletedAcross(){return(this.delInfo&Ln)>0}}class Fe{constructor(t,n=!1){if(this.ranges=t,this.inverted=n,!t.length&&Fe.empty)return Fe.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+ef(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 v=t==(n<0?u:p)?null:Hx(c/3,t-u),C=t==u?Ra:t==p?Wa:Ln;return(n<0?t!=u:t!=p)&&(C|=Qa),new Ua(m,C,v)}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 Fe(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(t){return t==0?Fe.empty:new Fe(t<0?[0,-t,0]:[0,0,t])}}Fe.empty=new Fe([]);const Ws=Object.create(null);class Ie{getMap(){return Fe.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 xe{constructor(t,n){this.doc=t,this.failed=n}static ok(t){return new xe(t,null)}static fail(t){return new xe(null,t)}static fromReplace(t,n,r,i){try{return xe.ok(t.replace(n,r,i))}catch(o){if(o instanceof Qx)return xe.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 Z.fromArray(r)}class wt extends Ie{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 ne(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 xe.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))}}Ie.jsonID("addMark",wt);class Ct extends Ie{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 ne(Rs(n.content,i=>i.mark(this.mark.removeFromSet(i.marks)),t),n.openStart,n.openEnd);return xe.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))}}Ie.jsonID("removeMark",Ct);class _t extends Ie{constructor(t,n){super(),this.pos=t,this.mark=n}apply(t){let n=t.nodeAt(this.pos);if(!n)return xe.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return xe.fromReplace(t,this.pos,this.pos+1,new ne(Z.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 _t(this.pos,n.marks[i]);return new _t(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 _t(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 _t(n.pos,t.markFromJSON(n.mark))}}Ie.jsonID("addNodeMark",_t);class tn extends Ie{constructor(t,n){super(),this.pos=t,this.mark=n}apply(t){let n=t.nodeAt(this.pos);if(!n)return xe.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.removeFromSet(n.marks));return xe.fromReplace(t,this.pos,this.pos+1,new ne(Z.from(r),0,n.isLeaf?0:1))}invert(t){let n=t.nodeAt(this.pos);return!n||!this.mark.isInSet(n.marks)?this:new _t(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))}}Ie.jsonID("removeNodeMark",tn);class He extends Ie{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)?xe.fail("Structure replace would overwrite content"):xe.fromReplace(t,this.from,this.to,this.slice)}getMap(){return new Fe([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?ne.empty:new ne(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?ne.empty:new ne(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,ne.fromJSON(t,n.slice),!!n.structure)}}Ie.jsonID("replace",He);class St extends Ie{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 xe.fail("Structure gap-replace would overwrite content");let n=t.slice(this.gapFrom,this.gapTo);if(n.openStart||n.openEnd)return xe.fail("Gap is not a flat range");let r=this.slice.insertAt(this.insert,n.content);return r?xe.fromReplace(t,this.from,this.to,r):xe.fail("Content does not fit in gap")}getMap(){return new Fe([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,ne.fromJSON(t,n.slice),n.insert,!!n.structure)}}Ie.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 tf(e,t,n){return(t==0||e.canReplace(t,e.childCount))&&(n==e.childCount||e.canReplace(0,n))}function nf(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||!tf(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),v=r&&r[h+1];v&&(m=m.replaceChild(0,v.type.create(v.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 sf(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function sf(e,t){return!!(e&&t&&!e.isLeaf&&e.canAppend(t))}class nn extends Ie{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 xe.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 xe.fromReplace(t,this.pos,this.pos+1,new ne(Z.from(i),0,n.isLeaf?0:1))}getMap(){return Fe.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)}}Ie.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 Us=Object.create(null);class ae{constructor(t,n,r){this.$anchor=t,this.$head=n,this.ranges=r||[new rf(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=ne.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?ne.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 fe(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=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 fe.between(this.$anchor,this.$head).getBookmark()}}ae.prototype.visible=!0;class rf{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 fe extends ae{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 ae.near(r);let i=t.resolve(n.map(this.anchor));return new fe(i.parent.inlineContent?i:r,r)}replace(t,n=ne.empty){if(super.replace(t,n),n==ne.empty){let r=this.$from.marksAcross(this.$to);r&&t.ensureMarks(r)}}eq(t){return t instanceof fe&&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 fe(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=ae.findFrom(n,r,!0)||ae.findFrom(n,-r,!0);if(o)n=o.$head;else return ae.near(n,r)}return t.parent.inlineContent||(i==0?t=n:(t=(ae.findFrom(t,-r,!0)||ae.findFrom(t,r,!0)).$anchor,t.pos<n.pos!=i<0&&(t=n))),new fe(t,n)}}ae.jsonID("text",fe);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 fe.between(t.resolve(this.anchor),t.resolve(this.head))}}class ze extends ae{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?ae.near(o):new ze(o)}content(){return new ne(Z.from(this.node),0,0)}eq(t){return t instanceof ze&&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 ze(t.resolve(n.anchor))}static create(t,n){return new ze(t.resolve(n))}static isSelectable(t){return!t.isText&&t.type.spec.selectable!==!1}}ze.prototype.visible=!1,ae.jsonID("node",ze);class Ks{constructor(t){this.anchor=t}map(t){let{deleted:n,pos:r}=t.mapResult(this.anchor);return n?new On(r,r):new Ks(r)}resolve(t){let n=t.resolve(this.anchor),r=n.nodeAfter;return r&&ze.isSelectable(r)?new ze(n):ae.near(n)}}class ot extends ae{constructor(t){super(t.resolve(0),t.resolve(t.content.size))}replace(t,n=ne.empty){if(n==ne.empty){t.delete(0,t.doc.content.size);let r=ae.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 af}}ae.jsonID("all",ot);const af={map(){return this},resolve(e){return new ot(e)}};function Bt(e,t,n,r,i,o=!1){if(t.inlineContent)return fe.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&&ze.isSelectable(c))return ze.create(e,n-(i<0?c.nodeSize:0))}else{let u=Bt(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 He||i instanceof St))return;let o=e.mapping.maps[r],l;o.forEach((c,u,d,h)=>{l==null&&(l=h)}),e.setSelection(ae.near(e.doc.resolve(l),n))}function Za(e,t){return!t||!e?e:e.bind(t)}class $n{constructor(t,n,r){this.name=t,this.init=Za(n.init,r),this.apply=Za(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||ae.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 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 rn{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 an{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 of{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 S=this.buildProps(d,n),D=m(...C)(S);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 mt(e,t,n){return e.config[t]===void 0&&e.parent?mt(e.parent,t,n):typeof e.config[t]=="function"?e.config[t].bind({...n,parent:e.parent?mt(e.parent,t,n):null}):e.config[t]}function lf(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 we(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 cf(e){return typeof e=="function"}function Ot(e,t=void 0,...n){return cf(e)?t?e.bind(t)(...n):e(...n):e}function uf(e){return Object.prototype.toString.call(e)==="[object RegExp]"}function df(e){return Object.prototype.toString.call(e).slice(8,-1)}function Xs(e){return df(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 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(mt(this,"addOptions",{name:this.name}))),this.storage=Ot(mt(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(t={}){return new et(t)}configure(t={}){const n=this.extend();return n.options=no(this.options,t),n.storage=Ot(mt(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(mt(n,"addOptions",{name:n.name})),n.storage=Ot(mt(n,"addStorage",{name:n.name,options:n.options})),n}}function pf(e,t,n){const{from:r,to:i}=t,{blockSeparator:o=`
|
|
131
131
|
|
|
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=>`
|
|
132
|
+
`,textSerializers:l={}}=n||{};let c="",u=!0;return e.nodesBetween(r,i,(d,h,p,x)=>{var m;const v=l==null?void 0:l[d.type.name];v?(d.isBlock&&!u&&(c+=o,u=!0),p&&(c+=v({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 hf(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)),c=Math.max(...o.map(h=>h.$to.pos)),u=hf(n);return pf(r,{from:l,to:c},{textSerializers:u})}}})]}});const xf=()=>({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),ff=(e=!1)=>({commands:t})=>t.setContent("",e),gf=()=>({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 v=nf(m);if(c.type.isTextblock){const{defaultType:C}=p.parent.contentMatchAt(p.index());t.setNodeMarkup(m.start,C)}(v||v===0)&&t.lift(m,v)})}),!0},mf=e=>t=>e(t),yf=()=>({state:e,dispatch:t})=>me.createParagraphNear(e,t),bf=()=>({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},vf=e=>({tr:t,state:n,dispatch:r})=>{const i=we(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},jf=e=>({tr:t,dispatch:n})=>{const{from:r,to:i}=e;return n&&t.delete(r,i),!0},wf=()=>({state:e,dispatch:t})=>me.deleteSelection(e,t),Cf=()=>({commands:e})=>e.keyboardShortcut("Enter"),_f=()=>({state:e,dispatch:t})=>me.exitCode(e,t);function qn(e,t,n={strict:!0}){const r=Object.keys(t);return r.length?r.every(i=>n.strict?t[i]===e[i]:uf(t[i])?t[i].test(e[i]):t[i]===e[i]):!0}function Js(e,t,n={}){return e.find(r=>r.type===t&&qn(r.attrs,n))}function Sf(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&&Sf([...e.parent.child(c).marks],t,n);)u+=e.parent.child(c).nodeSize,c+=1;return{from:l,to:u}}function yt(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 kf=(e,t={})=>({tr:n,state:r,dispatch:i})=>{const o=yt(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=fe.create(l,p.from,p.to);n.setSelection(x)}}return!0},Tf=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 fe}function kt(e=0,t=0,n=0){return Math.min(Math.max(e,t),n)}function Df(e,t=null){if(!t)return null;const n=ae.atStart(e),r=ae.atEnd(e);if(t==="start"||t===!0)return n;if(t==="end")return r;const i=n.from,o=r.to;return t==="all"?fe.create(e,kt(0,i,o),kt(e.content.size,i,o)):fe.create(e,kt(t,i,o),kt(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 If=(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=Df(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},Mf=(e,t)=>n=>e.every((r,i)=>t(r,{...n,index:i})),zf=(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?Z.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=zn.fromSchema(t);return n.slice?r.parseSlice(io(e),n.parseOptions).content:r.parse(io(e),n.parseOptions)}return Vn("",t,n)}function Af(e,t,n){const r=e.steps.length-1;if(r<t)return;const i=e.steps[r];if(!(i instanceof He||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(ae.near(e.doc.resolve(l),n))}const Ef=e=>e.toString().startsWith("<"),Pf=(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((Ef(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&&Af(r,r.steps.length-1,-1)}return!0},Lf=()=>({state:e,dispatch:t})=>me.joinUp(e,t),Bf=()=>({state:e,dispatch:t})=>me.joinDown(e,t),Of=()=>({state:e,dispatch:t})=>me.joinBackward(e,t),$f=()=>({state:e,dispatch:t})=>me.joinForward(e,t);function ao(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function qf(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 Vf=e=>({editor:t,view:n,tr:r,dispatch:i})=>{const o=qf(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?we(t,e.schema):null,c=[];e.doc.nodesBetween(r,i,(p,x)=>{if(p.isText)return;const m=Math.max(r,x),v=Math.min(i,x+p.nodeSize);c.push({node:p,from:m,to:v})});const u=i-r,d=c.filter(p=>l?l.name===p.node.type.name:!0).filter(p=>qn(p.node.attrs,n,{strict:!1}));return o?!!d.length:d.reduce((p,x)=>p+x.to-x.from,0)>=u}const Nf=(e,t={})=>({state:n,dispatch:r})=>{const i=we(e,n.schema);return Hs(n,i,t)?me.lift(n,r):!1},Ff=()=>({state:e,dispatch:t})=>me.liftEmptyBlock(e,t),Gf=e=>({state:t,dispatch:n})=>{const r=we(e,t.schema);return ds.liftListItem(r)(t,n)},Wf=()=>({state:e,dispatch:t})=>me.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 Rf=(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=we(e,r.schema)),c==="mark"&&(l=yt(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},Qf=()=>({tr:e,dispatch:t})=>(t&&e.scrollIntoView(),!0),Uf=()=>({tr:e,commands:t})=>t.setTextSelection({from:0,to:e.doc.content.size}),Kf=()=>({state:e,dispatch:t})=>me.selectNodeBackward(e,t),Yf=()=>({state:e,dispatch:t})=>me.selectNodeForward(e,t),Xf=()=>({state:e,dispatch:t})=>me.selectParentNode(e,t),Jf=()=>({state:e,dispatch:t})=>me.selectTextblockEnd(e,t),Zf=()=>({state:e,dispatch:t})=>me.selectTextblockStart(e,t);function Hf(e,t,n={}){return Vn(e,t,{slice:!1,parseOptions:n})}const eg=(e,t=!1,n={})=>({tr:r,editor:i,dispatch:o})=>{const{doc:l}=r,c=Hf(e,i.schema,n);return o&&r.replaceWith(0,l.content.size,c).setMeta("preventUpdate",!t),!0};function tg(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 ng(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=>ng(t.$from,e)}function sg(e,t){const n=yt(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 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 rg(e,t,n={}){const{empty:r,ranges:i}=e.selection,o=t?yt(t,e.schema):null;if(r)return!!(e.storedMarks||e.selection.$from.marks()).filter(p=>o?o.name===p.type.name:!0).find(p=>qn(p.attrs,n,{strict:!1}));let l=0;const c=[];if(i.forEach(({$from:p,$to:x})=>{const m=p.pos,v=x.pos;e.doc.nodesBetween(m,v,(C,S)=>{if(!C.isText&&!C.marks.length)return;const D=Math.max(m,S),P=Math.min(v,S+C.nodeSize),q=P-D;l+=q,c.push(...C.marks.map(U=>({mark:U,from:D,to:P})))})}),l===0)return!1;const u=c.filter(p=>o?o.name===p.mark.type.name:!0).filter(p=>qn(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}=lf(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(mt(r,"group",i));return typeof o!="string"?!1:o.split(" ").includes("list")}function ig(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),v=!!n.isInSet(h.marks)||!h.marks.some(C=>C.type.excludes(n));d=m&&v}return!d}),d})}const ag=(e,t={})=>({tr:n,state:r,dispatch:i})=>{const{selection:o}=n,{empty:l,ranges:c}=o,u=yt(e,r.schema);if(i)if(l){const d=sg(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 v=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(v,C,u.create({...D.attrs,...t}))}):n.addMark(v,C,u.create(t))})});return ig(r,n,u)},og=(e,t)=>({tr:n})=>(n.setMeta(e,t),!0),lg=(e,t={})=>({state:n,dispatch:r,chain:i})=>{const o=we(e,n.schema);return o.isTextblock?i().command(({commands:l})=>me.setBlockType(o,t)(n)?!0:l.clearNodes()).command(({state:l})=>me.setBlockType(o,t)(l,r)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},cg=e=>({tr:t,dispatch:n})=>{if(n){const{doc:r}=t,i=kt(e,0,r.content.size),o=ze.create(r,i);t.setSelection(o)}return!0},ug=e=>({tr:t,dispatch:n})=>{if(n){const{doc:r}=t,{from:i,to:o}=typeof e=="number"?{from:e,to:e}:e,l=fe.atStart(r).from,c=fe.atEnd(r).to,u=kt(i,l,c),d=kt(o,l,c),h=fe.create(r,u,d);t.setSelection(h)}return!0},dg=e=>({state:t,dispatch:n})=>{const r=we(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 pg=({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=Nn(d,c.node().type.name,c.node().attrs);if(o instanceof ze&&o.node.isBlock)return!c.parentOffset||!Bn(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 fe&&t.deleteSelection();const x=c.depth===0?void 0:tg(c.node(-1).contentMatchAt(c.indexAfter(-1)));let m=p&&x?[{type:x,attrs:h}]:void 0,v=Bn(t.doc,t.mapping.map(c.pos),1,m);if(!m&&!v&&Bn(t.doc,t.mapping.map(c.pos),1,x?[{type:x}]:void 0)&&(v=!0,m=x?[{type:x,attrs:h}]:void 0),v&&(t.split(t.mapping.map(c.pos),1,m),x&&!p&&!c.parentOffset&&c.parent.type!==x)){const C=t.mapping.map(c.before()),S=t.doc.resolve(C);c.node(-1).canReplaceWith(S.index(),S.index()+1,x)&&t.setNodeMarkup(t.mapping.map(c.before()),x)}e&&uo(n,i.extensionManager.splittableMarks),t.scrollIntoView()}return!0},hg=e=>({tr:t,state:n,dispatch:r,editor:i})=>{var o;const l=we(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 S=Z.empty;const D=c.index(-1)?1:c.index(-2)?2:3;for(let W=c.depth-D;W>=c.depth-3;W-=1)S=Z.from(c.node(W).copy(S));const P=c.indexAfter(-1)<c.node(-2).childCount?1:c.indexAfter(-2)<c.node(-3).childCount?2:3,q=Nn(p,c.node().type.name,c.node().attrs),U=((o=l.contentMatch.defaultType)===null||o===void 0?void 0:o.createAndFill(q))||void 0;S=S.append(Z.from(l.createAndFill(null,U)||void 0));const F=c.before(c.depth-(D-1));t.replace(F,c.after(-P),new ne(S,4-D,0));let re=-1;t.doc.nodesBetween(F,t.doc.content.size,(W,te)=>{if(re>-1)return!1;W.isTextblock&&W.content.size===0&&(re=te+1)}),re>-1&&t.setSelection(fe.near(t.doc.resolve(re))),t.scrollIntoView()}return!0}const x=u.pos===c.end()?h.contentMatchAt(0).defaultType:null,m=Nn(p,h.type.name,h.attrs),v=Nn(p,c.node().type.name,c.node().attrs);t.delete(c.pos,u.pos);const C=x?[{type:l,attrs:m},{type:x,attrs:v}]:[{type:l,attrs:m}];if(!Bn(t.doc,c.pos,2))return!1;if(r){const{selection:S,storedMarks:D}=n,{splittableMarks:P}=i.extensionManager,q=D||S.$to.parentOffset&&S.$from.marks();if(t.split(c.pos,2,C).scrollIntoView(),!q||!r)return!0;const U=q.filter(F=>P.includes(F.type.name));t.ensureMarks(U)}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 xg=Object.freeze({__proto__:null,blur:xf,clearContent:ff,clearNodes:gf,command:mf,createParagraphNear:yf,deleteCurrentNode:bf,deleteNode:vf,deleteRange:jf,deleteSelection:wf,enter:Cf,exitCode:_f,extendMarkRange:kf,first:Tf,focus:If,forEach:Mf,insertContent:zf,insertContentAt:Pf,joinUp:Lf,joinDown:Bf,joinBackward:Of,joinForward:$f,keyboardShortcut:Vf,lift:Nf,liftEmptyBlock:Ff,liftListItem:Gf,newlineInCode:Wf,resetAttributes:Rf,scrollIntoView:Qf,selectAll:Uf,selectNodeBackward:Kf,selectNodeForward:Yf,selectParentNode:Xf,selectTextblockEnd:Jf,selectTextblockStart:Zf,setContent:eg,setMark:ag,setMeta:og,setNode:lg,setNodeSelection:cg,setTextSelection:ug,sinkListItem:dg,splitBlock:pg,splitListItem:hg,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=we(e,l.schema),v=we(t,l.schema),{selection:C,storedMarks:S}=l,{$from:D,$to:P}=C,q=D.blockRange(P),U=S||C.$to.parentOffset&&C.$from.marks();if(!q)return!1;const F=er(re=>co(re.type.name,p))(C);if(q.depth>=1&&F&&q.depth-F.depth<=1){if(F.node.type===m)return d.liftListItem(v);if(co(F.node.type.name,p)&&m.validContent(F.node.content)&&c)return u().command(()=>(o.setNodeMarkup(F.pos,m),!0)).command(()=>tr(o,m)).command(()=>nr(o,m)).run()}return!n||!U||!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 re=h().wrapInList(m,r),W=U.filter(te=>x.includes(te.type.name));return o.ensureMarks(W),re?!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=yt(e,r.schema);return rg(r,l,t)?i.unsetMark(l,{extendEmptyMarkRange:o}):i.setMark(l,t)},toggleNode:(e,t,n={})=>({state:r,commands:i})=>{const o=we(e,r.schema),l=we(t,r.schema);return Hs(r,o,n)?i.setNode(l):i.setNode(o,n)},toggleWrap:(e,t={})=>({state:n,commands:r})=>{const i=we(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=yt(e,r.schema),{$from:d,empty:h,ranges:p}=c;if(!i)return!0;if(h&&l){let{from:x,to:m}=c;const v=(o=d.marks().find(S=>S.type===u))===null||o===void 0?void 0:o.attrs,C=so(d,u,v);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=we(e,r.schema)),c==="mark"&&(l=yt(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 v=Math.max(x,d),C=Math.min(x+p.nodeSize,h);n.addMark(v,C,l.create({...m.attrs,...t}))}})})}),!0):!1},wrapIn:(e,t={})=>({state:n,dispatch:r})=>{const i=we(e,n.schema);return me.wrapIn(i,t)(n,r)},wrapInList:(e,t={})=>({state:n,dispatch:r})=>{const i=we(e,n.schema);return ds.wrapInList(i,t)(n,r)}});et.create({name:"commands",addCommands(){return{...xg}}}),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:c})=>{const{selection:u,doc:d}=c,{empty:h,$anchor:p}=u,{pos:x,parent:m}=p,v=ae.atStart(d).from===x;return!h||!v||!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 rn({key:new an("clearDocument"),appendTransaction:(e,t,n)=>{if(!(e.some(v=>v.docChanged)&&!t.doc.eq(n.doc)))return;const{empty:i,from:o,to:l}=t.selection,c=ae.atStart(t.doc).from,u=ae.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 of({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 po=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()}}}),fg=["8","10","12","14","16","18","20","24","30","36","48","60","72"].map(e=>`${e}px`),gg=[{label:"auto",value:""}].concat(fg.map(e=>({label:e,value:e}))),mg={input:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important"}},yg=({editor:e})=>{const t=e.getAttributes("textStyle").fontSize;return s.jsx(G.RichTextEditor.ControlsGroup,{children:s.jsx(a.NativeSelect,{size:"xs",icon:s.jsx(k.IconTextSize,{stroke:1.5,size:16}),data:gg,styles:mg,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,G.Link,Li,Pi,Ai,$i.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),Ni,Vi,qi,Bi.configure({types:["heading","paragraph"]}),Ei.configure({placeholder:"This is placeholder"}),Oi,zi.Color,po],content:e,editable:!1});f.useEffect(()=>{r==null||r.commands.setContent(e)},[e,r]);const i=f.useMemo(()=>y.defaultsDeep({},{content:Ns},t),[t]);return s.jsx(G.RichTextEditor,{editor:r,styles:i,sx:n,children:s.jsx(G.RichTextEditor.Content,{})})};function bg(){const{t:e}=M.useTranslation(),[t,{open:n,close:r}]=ie.useDisclosure(!1);return s.jsxs(s.Fragment,{children:[s.jsx(a.Modal,{opened:t,onClose:r,title:e("function_utils.modal_title"),zIndex:330,withinPortal:!0,children:s.jsx(Fn,{value:rd(e),styles:{root:{border:"none"},content:{padding:0,table:{marginBottom:0}}}})}),s.jsx(a.Button,{variant:"light",color:"violet",size:"xs",onClick:n,leftIcon:s.jsx(k.IconInfoCircle,{size:16}),children:e("function_utils.trigger_text")})]})}const vg=({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(ge,{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=f.forwardRef(({value:e,onChange:t,label:n,defaultValue:r},i)=>{const{t:o}=M.useTranslation(),[l,c]=f.useState(e),u=()=>{t(l)},d=()=>{c(e)},h=()=>{c(r)};f.useEffect(()=>{c(e)},[e]);const p=l!==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(bg,{})}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:h,size:"xs",variant:"default",leftIcon:s.jsx(k.IconPlayerSkipBack,{size:16}),children:o("common.actions.reset_to_default")}),s.jsx(a.Button,{onClick:d,color:"red",size:"xs",disabled:!p,leftIcon:s.jsx(k.IconRecycle,{size:16}),children:o("common.actions.revert_changes")}),s.jsx(a.Button,{color:"green",size:"xs",onClick:u,disabled:!p,leftIcon:s.jsx(k.IconDeviceFloppy,{size:16}),children:o("common.actions.save_changes")})]})]}),s.jsx(a.Text,{size:14,children:n}),s.jsx(vg,{value:l,onChange:c})]})}),ho=f.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}]=ie.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:c,label:r})})]}),s.jsx(a.Button,{onClick:h,...l,children:o})]})}),jg=[{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 wg({label:e,value:t,onChange:n,pt:r="sm",withFallback:i},o){const{t:l}=M.useTranslation();f.useEffect(()=>{typeof t=="string"&&n({type:t,config:{},fallback:"0"})},[t,n]);const c=p=>{n(p==="quantile"?{type:"quantile",config:{p:.99},fallback:t.fallback}:p==="custom"?{type:"custom",config:{func:ta},fallback:t.fallback}:{type:p,config:{},fallback:t.fallback})},u=p=>{n({type:"quantile",config:{p},fallback:t.fallback})},d=p=>{n({type:"custom",config:{func:p},fallback:t.fallback})},h=p=>{n({...t,fallback:p.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:jg,value:t.type,onChange:c,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(ho,{title:"Custom Aggregation",label:"",triggerLabel:"Edit Function",value:t.config.func,onChange:d,defaultValue:ta,triggerButtonProps:{size:"xs",sx:{flexGrow:0,alignSelf:"center",marginTop:"22px"},leftIcon:s.jsx(k.IconMathFunction,{size:16})}})]}),i&&s.jsx(a.TextInput,{label:l("panel.variable.aggregation.fallback_value"),description:l("panel.variable.aggregation.fallback_value_description"),value:t.fallback,onChange:h})]})}const sr=f.forwardRef(wg),Cg=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function _g({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:Cg,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 Sg=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return s.jsx(a.Box,{children:s.jsx(ge,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},kg=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:i}]=V.useBoolean(),[o,l]=f.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(Vs.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(Sg,{value:o.func_content,onChange:d}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:h,color:"red",leftIcon:s.jsx(T.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"})]})]})]})})]})},Tg=({value:e,onChange:t})=>e.type!=="dynamic"?null:s.jsx(kg,{value:e,onChange:t}),Dg=({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})})},Ig=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],xo=f.forwardRef(({label:e="Size",value:t,onChange:n},r)=>{const i=o=>{n({...Vs[o]})};return s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(a.Select,{ref:r,label:e,data:Ig,value:t.type,onChange:i,sx:{flexGrow:1}}),s.jsx(Dg,{value:t,onChange:n}),s.jsx(Tg,{value:t,onChange:n})]})}),Mg=[{label:"off",value:"false"},{label:"start",value:"start"},{label:"middle",value:"middle"},{label:"end",value:"end"}],zg=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function Ag({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:zg,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:Mg,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 Eg({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 Pg=[{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 Lg({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(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(sr,{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(Ag,{index:t,control:e,seriesItem:r}),o==="bar"&&s.jsx(_g,{index:t,control:e,seriesItem:r}),o==="scatter"&&s.jsx(Eg,{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:Pg,...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(_e,{...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(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Series"})]})}function Bg({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:ie.randomId(),showSymbol:!1,symbolSize:Vs.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=f.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(T.Plus,{size:18,color:"#228be6"})})]}),l.map((h,p)=>s.jsx(a.Tabs.Panel,{value:p.toString(),children:s.jsx(Lg,{control:e,index:p,remove:i,seriesItem:h,yAxisOptions:d},h.id)},h.id))]})}function Og({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 $g=()=>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(k.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"]})})]})]}),qg=[{label:"Value",value:"value"},{label:"Category",value:"category"},{label:"Time",value:"time"},{label:"Log",value:"log"}];function Vg({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($g,{}),required:!0,data:qg,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(Ue,{...n})})]})}const Ng=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],Fg=[{label:"left",value:"left"},{label:"right",value:"right"}];function Gg({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:Ng,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:Fg,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(Ne,{...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(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this YAxis"})]})}function Wg({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:ye,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(T.Plus,{size:18,color:"#228be6"})})]}),l.map((u,d)=>s.jsx(a.Tabs.Panel,{value:d.toString(),children:s.jsx(Gg,{control:e,index:d,remove:i})},u.id))]})}const Rg=({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(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),Qg=({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]=f.useState(()=>u??null);return f.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(T.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(T.Plus,{size:18,color:"#228be6"})})]}),l.map((p,x)=>s.jsx(a.Tabs.Panel,{value:p.id,children:s.jsx(Rg,{control:e,index:x,remove:i},p.id)},p.id))]})]})};function Ug({control:e,watch:t}){return s.jsx(a.Stack,{children:s.jsx(Qg,{control:e,watch:t})})}function Kg({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),{variables:r}=e,i=f.useMemo(()=>y.defaultsDeep({},t,$s),[t]),{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=b.useForm({defaultValues:i});f.useEffect(()=>{d(i)},[i]);const h=u(),p=f.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(T.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(Vg,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Y Axes",children:s.jsx(Wg,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Series",children:s.jsx(Bg,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Regression Lines",children:s.jsx(Rx,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(Ug,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Stats",children:s.jsx(Og,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Reference Lines",children:s.jsx(Nx,{variables:r,control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Reference Areas",children:s.jsx(Ox,{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(Dn,{...x})})})]})]})})}function Yg(e){const t=y.cloneDeep(y.omit(e,"variables"));return t.stats=y.omit(t.stats,"variables"),t}function Xg(e){const{rotate:t,formatter:n=Be}=e.x_axis.axisLabel;return{...e,x_axis:{...e.x_axis,axisLabel:{rotate:t,formatter:n}}}}function Jg(e){const{dataZoom:t=vt,...n}=e;return{...n,dataZoom:t}}function Zg(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 Hg(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 em(e){const t=e.reference_lines.map(n=>{const{yAxisIndex:r=0}=n;return{...n,yAxisIndex:r}});return{...e,reference_lines:t}}function tm(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 nm(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 sm(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 rm(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 im(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 am(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(r=>{const{nameAlignment:i="left"}=r;return{...r,nameAlignment:i}})}}function om(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(r=>{const{show:i=!0}=r;return{...r,show:i}})}}function lm(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 cm(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:c=!0}=i;return{...i,min:o,max:l,show:c}})}}function um(e){const{type:t="category",...n}=e.x_axis;return{...e,x_axis:{...n,type:t}}}function dm(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 pm(e){const{tooltip:t={metrics:[]},...n}=e;return{...e,tooltip:t}}class hm extends oe{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(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:Yg(i)}}),this.version(3,n=>({...n,version:3,config:Xg(n.config)})),this.version(4,n=>({...n,version:4,config:Jg(n.config)})),this.version(5,n=>({...n,version:5,config:Zg(n.config)})),this.version(6,n=>({...n,version:6,config:Hg(n.config)})),this.version(7,n=>({...n,version:7,config:em(n.config)})),this.version(8,n=>({...n,version:8,config:tm(n.config)})),this.version(9,n=>({...n,version:9,config:nm(n.config)})),this.version(10,n=>({...n,version:10,config:sm(n.config)})),this.version(11,n=>({...n,version:11,config:rm(n.config)})),this.version(12,n=>({...n,version:12,config:im(n.config)})),this.version(13,n=>({...n,version:13,config:am(n.config)})),this.version(14,n=>({...n,version:14,config:om(n.config)})),this.version(15,n=>({...n,version:15,config:lm(n.config)})),this.version(16,n=>({...n,version:16,config:cm(n.config)})),this.version(17,n=>({...n,version:17,config:um(n.config)})),this.version(18,(n,r)=>({...n,version:18,config:dm(n.config,r)})),this.version(19,n=>({...n,version:19,config:pm(n.config)}))}}const xm={displayName:"Cartesian Chart",displayGroup:"ECharts-based charts",migrator:new hm,name:"cartesian",viewRender:Ex,configRender:Kg,createConfig(){return{version:19,config:y.cloneDeep($s)}},triggers:[Os]};function fm(e){if(e.enable_value)return e.value}function gm(e){if(e.enable_value)return e.value}function mm(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 ym(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=A(r),x=A(i),m=t[p.queryID].map(C=>({name:C[p.columnKey],value:C[x.columnKey]})),v=$e(o.overflow.on_axis);return{type:"funnel",...mm(n),min:fm(l),max:gm(c),minSize:l.size,maxSize:c.size,...h,label:{show:!0,position:o.position,...v},orient:d,funnelAlign:d==="horizontal"?"center":u,data:m}})}function bm({conf:e,params:t,max:n}){const{name:r,value:i}=t.data,o=R(i/n,{output:"percent",mantissa:2,trimMantissa:!0,absolute:!1});return[{label:`${t.marker} ${r}`,value:`${i} (${o})`,style:{label:"",value:""}}]}function vm(e,t){var o;const n=A(e.series[0].level_name_data_key),r=A(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=bm({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>
|
|
@@ -145,13 +145,13 @@ Check the top-level render call using <`+E+">.")}return I}}function iu(w,I){{if(
|
|
|
145
145
|
<table style="width: auto">
|
|
146
146
|
<tbody>${u.join("")}</tbody>
|
|
147
147
|
</table>
|
|
148
|
-
`}}function
|
|
148
|
+
`}}function jm(e,t){return ee.getTooltip({trigger:"item",formatter:vm(e,t)})}function wm(e,t){return{grid:{top:0,left:0,right:0,bottom:0},tooltip:jm(e,t),series:ym(e,t)}}function Cm(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:De()},sort:"descending",orient:"vertical",funnelAlign:"center"}}const rr={series:[Cm("Funnel")]};function _m({conf:e,data:t,width:n,height:r}){const i=f.useMemo(()=>wm(e,t),[e,t]);return s.jsx(Ce,{echarts:ve,option:i,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})}function Sm({context:e}){const{value:t}=$(e.instanceData,"config"),n=f.useMemo(()=>y.defaults({},t,rr),[t]),r=e.data,{width:i,height:o}=e.viewport;return!i||!o?null:s.jsx(Te,{width:i,height:o,children:s.jsx(_m,{width:Re(i),height:Qe(o),data:r,conf:n})})}const km=[{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=f.forwardRef(({label:e,value:t,onChange:n,options:r=km},i)=>s.jsx(a.Select,{ref:i,label:e,data:r,value:t,onChange:n})),Tm=[{label:"Ascending",value:"ascending"},{label:"Descending",value:"descending"},{label:"Use original data order",value:"0"}],Dm=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Im=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}],Mm={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"}]},zm=({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(O,{label:"Level Name Field",...c})}),s.jsx(b.Controller,{name:`series.${n}.level_value_data_key`,control:t,render:({field:c})=>s.jsx(O,{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:Im,...c})}),s.jsx(b.Controller,{name:`series.${n}.sort`,control:t,render:({field:c})=>s.jsx(a.Select,{label:"Sort",data:Tm,...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:Dm,...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:Mm[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(Ue,{...c})})})]})},Am=({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]=f.useState(c??null);return f.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(k.IconPlus,{size:18,color:"#228be6"})})})})]}),l.map((h,p)=>s.jsx(a.Tabs.Panel,{value:h.id,children:s.jsx(zm,{item:h,control:e,index:p,remove:i})},h.id))]})};function Em({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},t,rr),[t]),{control:i,handleSubmit:o,watch:l,getValues:c,reset:u}=b.useForm({defaultValues:r});f.useEffect(()=>{u(r)},[r]),l([]);const d=c(),h=f.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(T.DeviceFloppy,{size:20})})]}),s.jsx(Am,{control:i,watch:l})]})})}function Pm(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 Lm(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 Bm extends oe{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:Pm(r)}}),this.version(3,(n,r)=>{const{config:i}=n;return{...n,version:3,config:Lm(i,r)}})}}const Om={displayName:"Funnel Chart",displayGroup:"ECharts-based charts",migrator:new Bm,name:"funnel",viewRender:Sm,configRender:Em,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 $m(e){const t=fo(e.x_axis.axisLabel.formatter),n=fo(e.y_axis.axisLabel.formatter);return{x_axis:t,y_axis:n}}function qm(e){return{heat_block:function(r){if(!e.heat_block.value_formatter)return r;try{return R(r,e.heat_block.value_formatter)}catch(i){return console.error(i),r}}}}function Vm(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 Nm(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 Fm=e=>R(e,{output:"number",trimMantissa:!0,mantissa:2,absolute:!1});function Gm({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:Oe(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:Oe(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],v=r[`${c}---${u}`];return v&&e.tooltip.metrics.forEach(C=>{const S=A(C.data_key);m.push({label:C.name,value:Fm(y.get(v,S.columnKey,"")),style:{label:"",value:""}})}),m}function Wm(e,t,n,r){const{x_axis:i,y_axis:o,heat_block:l}=e,c=A(i.data_key),u=A(o.data_key);A(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=Gm({conf:e,labelFormatters:n,valueFormatters:r,dataDict:d,params:h}).map(v=>`
|
|
149
149
|
<tr>
|
|
150
150
|
<th style="text-align: right;">
|
|
151
|
-
<div style="${
|
|
151
|
+
<div style="${v.style.label}">${v.label}</div>
|
|
152
152
|
</th>
|
|
153
153
|
<td style="text-align: right; padding: 0 1em;">
|
|
154
|
-
<div style="${
|
|
154
|
+
<div style="${v.style.value}">${v.value}
|
|
155
155
|
</td>
|
|
156
156
|
</tr>
|
|
157
157
|
`);return`
|
|
@@ -166,14 +166,14 @@ Check the top-level render call using <`+E+">.")}return I}}function iu(w,I){{if(
|
|
|
166
166
|
</thead>
|
|
167
167
|
<tbody>${x.join("")}</tbody>
|
|
168
168
|
</table>
|
|
169
|
-
`}})}const
|
|
170
|
-
`)}},
|
|
171
|
-
`)},yo=
|
|
169
|
+
`}})}const Rm=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return s.jsx(a.Box,{children:s.jsx(ge,{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
|
+
`)}},Qm=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:i}]=V.useBoolean(),[o,l]=f.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(Rm,{value:o.value,onChange:d}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:h,color:"red",leftIcon:s.jsx(T.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"})]})]})]})})]})},Um=({value:e,onChange:t})=>e.type!=="dynamic"?null:s.jsx(Qm,{value:e,onChange:t}),Km=({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})},Ym=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],qt=f.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:Ym,value:t.type,onChange:i,sx:{flexGrow:1}}),s.jsx(Km,{value:t,onChange:n}),s.jsx(Um,{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:bt.interpolate})}catch(i){return console.error(`[getNumberOrDynamicValue] failed parsing custom function, error: ${i.message}`),10}}function Xm(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 Jm(e,t,n,r){const{overflow:i,rotate:o}=e.x_axis.axisLabel,l=$e(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 Zm(e,t,n,r){const{nameAlignment:i,data_key:o,...l}=e.y_axis,{overflow:c,rotate:u}=e.y_axis.axisLabel,d=$e(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 Hm(e,t,n,r){return n<e*10||r<t*10?0:n<e*20||r<t*20?1:2}function ey(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((S,D)=>{const P=it(D,t);return S[D.name]=Pe(D,P),S},{}),l=$m(e),c=qm(e),u=A(e.x_axis.data_key),d=A(e.y_axis.data_key),h=A(e.heat_block.data_key),p=y.uniq(t[u.queryID].map(S=>S[u.columnKey])),x=y.uniq(t[u.queryID].map(S=>S[d.columnKey])),m=t[u.queryID].map(S=>[y.get(S,u.columnKey),y.get(S,d.columnKey),y.get(S,h.columnKey)]),v=Hm(p.length,x.length,r,i);return{xAxis:Jm(e,p,l.x_axis,v),yAxis:Zm(e,x,l.y_axis,v),series:Nm(e,m,v),tooltip:Wm(e,t,l,c),grid:Vm(e),visualMap:Xm(e,o)}}function ty(e){return s.jsx(s.Fragment,{})}function ny(e){return s.jsx(a.Text,{children:"Click heat block"})}const mo={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:ny,configRender:ty,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:De(),formatter:{...Be}}},y_axis:{name:"Y Axis",data_key:"",nameAlignment:"center",axisLabel:{rotate:0,overflow:De(),formatter:{...Be}}},heat_block:{min:{type:"static",value:0},max:{type:"static",value:100},name:"Value",data_key:"",value_formatter:ye,label:{show:!1,fontSize:10}},tooltip:{metrics:[]}};function sy({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const l=f.useMemo(()=>{const p=A(e.x_axis.data_key),x=A(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=qe(i.triggerManager,mo.id),u=f.useCallback(p=>{const[x,m]=p.value,v=y.get(l,`${x}---${m}`,{error:"rowData is not found"});c.forEach(C=>{i.runInteraction(C.id,{...p,rowData:v})})},[l,c,i]),d=f.useMemo(()=>({click:u}),[u]),h=f.useMemo(()=>ey(e,t,o,n,r),[e,t,n,r]);return s.jsx(Ce,{echarts:ve,option:h,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function ry({context:e,instance:t}){const n=Ve({vizManager:e.vizManager,instance:t}),{value:r}=$(e.instanceData,"config"),{variables:i}=e,o=f.useMemo(()=>y.defaults({},r,ar),[r]),l=e.data,{width:c,height:u}=e.viewport;return!c||!u?null:s.jsx(Te,{width:c,height:u,children:s.jsx(sy,{variables:i,width:Re(c),height:Qe(u),data:l,conf:o,interactionManager:n})})}function iy({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(qt,{label:"Min Value",...r})}),s.jsx(b.Controller,{name:"heat_block.max",control:e,render:({field:r})=>s.jsx(qt,{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(Ne,{...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(k.IconTextSize,{size:16}),disabled:!n,...r})})]})]})}const ay=({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(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),oy=({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]=f.useState(()=>u??null);return f.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(T.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(T.Plus,{size:18,color:"#228be6"})})]}),l.map((p,x)=>s.jsx(a.Tabs.Panel,{value:p.id,children:s.jsx(ay,{control:e,index:x,remove:i},p.id)},p.id))]})]})};function ly({control:e,watch:t}){return s.jsx(oy,{control:e,watch:t})}const cy=({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(ge,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},uy={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
171
|
+
`)},yo=f.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:i,setFalse:o}]=V.useBoolean(),[l,c]=f.useState(e);f.useEffect(()=>{c(e)},[e]);const u=m=>{c({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:v}=l,C={enabled:m,func_content:v};c(C),t(C)},h=()=>{o(),c(e)},p=m=>{c(v=>({...v,func_content:m}))},x=()=>{p(uy.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(cy,{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(T.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 dy({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(Ue,{...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 py=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function hy({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:py,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(Ue,{...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 xy({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},t,ar),[t]),i=f.useMemo(()=>y.cloneDeep(r),[r]);f.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});f.useEffect(()=>{d(i)},[i]);const h=u(),p=f.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(T.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(dy,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Y Axis",children:s.jsx(hy,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Heat Block",children:s.jsx(iy,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(ly,{control:o,watch:c})})]})]})})}function fy(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 gy(e){return y.defaultsDeep({},e,{heat_block:{label:{show:!1,fontSize:10}}})}function my(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 yy extends oe{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:fy(n.config,r)})),this.version(3,n=>({...n,version:3,config:gy(n.config)})),this.version(4,n=>({...n,version:4,config:my(n.config)}))}}const by={displayName:"Heatmap",displayGroup:"ECharts-based charts",migrator:new yy,name:"heatmap",viewRender:ry,configRender:xy,createConfig:()=>({version:4,config:ar}),triggers:[mo]},bo={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:jy,configRender:vy,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 vy(e){return s.jsx(s.Fragment,{})}function jy(e){return s.jsx(a.Text,{children:"Click chart's series"})}const vo={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:{...Be},overflow:De()}},data_key:"value",bar:{name:"Value",nameAlignment:"left",color:"#228be6",label_formatter:ye},line:{name:"Value",nameAlignment:"right",color:"red"},dataZoom:vt,markLine:vo};function Gn(e){return R(e,{output:"percent",mantissa:0,absolute:!1})}function wy(e){const t=e.value[1];try{return Gn(t)}catch(n){return console.error(n),t}}function Cy(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 R(r,e.bar.label_formatter)}catch(i){return console.error(i),r}}return{bar:t,line:wy,lineValue:Gn}}function _y(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 Sy(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: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:_y(e,i,o)}}]},markArea:{name:"",silent:!0,itemStyle:{color:"rgba(47, 140, 192, 0.05)"},data:[[{coord:["min",0]},{xAxis:l}]]}}:{}}function ky(e,t,n){const{x_axis:r,data_key:i}=e;if(!r.data_key||!i)return[];const o=A(r.data_key),l=A(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,v)=>{const C=v===0?0:x[v-1][1];return x.push([m[0],C+m[1]]),x},[]).map(x=>[x[0],x[1]/u]),{markLine:h,markArea:p}=Sy(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 Ty=(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=
|
|
176
|
+
`}),o=Oe(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 iu(w,I){{if(
|
|
|
182
182
|
${i.join("")}
|
|
183
183
|
</tbody>
|
|
184
184
|
</table>
|
|
185
|
-
`};function
|
|
185
|
+
`};function Dy(e,t){return ee.getTooltip({trigger:"axis",formatter:Ty(e,t)})}function Iy(e){const{name:t,axisLabel:n}=e.x_axis,r=$e(n.overflow.on_axis);return[ee.getXAxis({type:"category",name:t,nameLocation:"middle",nameGap:30,nameTextStyle:{align:"right"},axisLabel:{...n,...r,formatter:Lt(n.formatter)}})]}function My(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 zy(e,t,n){const r=Cy(e);return{dataZoom:kn(e.dataZoom),tooltip:Dy(e,r),xAxis:Iy(e),yAxis:My(e,r),series:ky(e,t,r),grid:{top:50,left:30,right:15,bottom:5,containLabel:!0}}}function Ay({context:e,instance:t}){const{value:n}=$(e.instanceData,"config"),r=e.data,{width:i,height:o}=e.viewport,l=y.defaults({},n,or),c=zy(l,r),u=Ve({vizManager:e.vizManager,instance:t}),d=qe(u.triggerManager,bo.id),h=jt(r,l.x_axis.data_key),p=f.useCallback(m=>{const v=y.get(h,m.name,{error:"rowData is not found"});d.forEach(C=>{u.runInteraction(C.id,{...m,rowData:v})})},[h,d,u]),x=f.useMemo(()=>({click:p}),[p]);return!l||!i||!o?null:s.jsx(Te,{width:i,height:o,children:s.jsx(Ce,{echarts:ve,option:c,style:Ht(i,o),onEvents:x,notMerge:!0,theme:"merico-light"})})}const Ey=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function Py({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: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:"bar.color",control:e,render:({field:n})=>s.jsx(_e,{...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(Ne,{...n})})]})]})}const Ly=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function By({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:Ly,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(_e,{...n})})]})]})}const Oy=`
|
|
186
186
|
{
|
|
187
187
|
// 80-20 line stuff
|
|
188
188
|
percentage: {
|
|
@@ -205,8 +205,8 @@ Check the top-level render call using <`+E+">.")}return I}}function iu(w,I){{if(
|
|
|
205
205
|
name: string;
|
|
206
206
|
};
|
|
207
207
|
}
|
|
208
|
-
|
|
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
|
|
208
|
+
`,$y=()=>{const[e,t]=f.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(ht.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:Oy})})]})};function qy({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(_e,{...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($y,{})]})]})}function Vy({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(Ue,{...n})})]})}function Ny({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 Fy({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaults({},t,or),[t]),{control:i,handleSubmit:o,watch:l,getValues:c,reset:u}=b.useForm({defaultValues:r});f.useEffect(()=>{u(r)},[r]),l(["x_axis","data_key","bar","line","dataZoom"]);const d=c(),h=f.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(T.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(Vy,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Y Axis",children:s.jsx(Ny,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Bar",children:s.jsx(Py,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Line",children:s.jsx(By,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"80-20 Line",children:s.jsx(qy,{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 Gy(e){const{dataZoom:t=vt,...n}=e;return{...n,dataZoom:t}}function Wy(e){const{markLine:t=vo,...n}=e;return{...n,markLine:t}}function Ry(e){const t=y.defaultsDeep({},e.x_axis.axisLabel,{rotate:0,formatter:{...Be}});return{...e,x_axis:{...e.x_axis,axisLabel:t}}}function Qy(e){const{label_formatter:t=ye}=e.bar;return{...e,bar:{...e.bar,label_formatter:t}}}function Uy(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 Ky(e){const t={bar:{nameAlignment:"left"},line:{nameAlignment:"right"}};return y.defaultsDeep(t,e)}function Yy(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 Xy(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 Jy extends oe{constructor(){super(...arguments);L(this,"VERSION",9)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:Gy(n.config)})),this.version(3,n=>({...n,version:3,config:Wy(n.config)})),this.version(4,n=>({...n,version:4,config:Ry(n.config)})),this.version(5,n=>({...n,version:5,config:Qy(n.config)})),this.version(6,n=>({...n,version:6,config:Uy(n.config)})),this.version(7,n=>({...n,version:7,config:Ky(n.config)})),this.version(8,n=>({...n,version:8,config:Yy(n.config)})),this.version(9,(n,r)=>({...n,version:9,config:Xy(n.config,r)}))}}const Zy={displayName:"Pareto Chart",displayGroup:"ECharts-based charts",migrator:new Jy,name:"paretoChart",viewRender:Ay,configRender:Fy,createConfig(){return{version:9,config:y.cloneDeep(or)}},triggers:[bo]};function Hy(e,t,n){const{label_field:r,value_field:i,color_field:o}=e;if(!r||!i)return{};const l=A(r),c=A(i),u=A(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=_d("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 eb(e,t,n){return{tooltip:ee.getTooltip({}),series:Hy(e,t,n)}}const jo={id:"builtin:echarts:click-pie-chart:series",displayName:"Click Pie Series",nameRender:nb,configRender:tb,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 tb(e){return s.jsx(s.Fragment,{})}function nb(e){return s.jsx(a.Text,{children:"Click chart's series"})}const lr={label_field:"",value_field:"",color_field:""};function sb({conf:e,data:t,width:n,height:r,interactionManager:i}){const o=jt(t,e.label_field),l=qe(i.triggerManager,jo.id),c=f.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=f.useMemo(()=>eb(e,t,n),[e,t,n]),d=f.useMemo(()=>({click:c}),[c]);return!n||!r||!u.series.name?null:s.jsx(Ce,{echarts:ve,option:u,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function rb({context:e,instance:t}){const n=Ve({vizManager:e.vizManager,instance:t}),{value:r}=$(e.instanceData,"config"),i=f.useMemo(()=>y.defaults({},r,lr),[r]),o=e.data,{width:l,height:c}=e.viewport;return!l||!c?null:s.jsx(Te,{width:l,height:c,children:s.jsx(sb,{conf:i,width:Re(l),height:Qe(c),data:o,interactionManager:n})})}function ib({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},t,lr),[t]),i=f.useMemo(()=>y.clone(r),[r]),{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=b.useForm({defaultValues:i});f.useEffect(()=>{d(i)},[i]);const h=u(),p=f.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(T.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 ab(e){const{color_field:t="",...n}=e;return{...n,color_field:t}}function ob(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 lb extends oe{constructor(){super(...arguments);L(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:ab(n.config)})),this.version(3,(n,r)=>({...n,version:3,config:ob(n.config,r)}))}}const cb={displayName:"Pie Chart",displayGroup:"ECharts-based charts",migrator:new lb,name:"pie",viewRender:rb,configRender:ib,createConfig(){return{version:3,config:y.cloneDeep(lr)}},triggers:[jo]};function ub(e){return s.jsx(s.Fragment,{})}function db(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:db,configRender:ub,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 Co(e){return e?t=>{try{return R(t,e)}catch(n){return console.error(n),t}}:t=>t}function _o(e){return{show:e.label.enabled,formatter:({dimensionIndex:t,value:n})=>Co(e.dimensions[t].formatter)(n)}}function So(e,t){return t.map(({data_key:n})=>{const r=A(n);return e[r.columnKey]})}function pb(e,t,n){const r=A(t);return e[r.queryID].map(i=>({value:So(i,n),name:i[r.columnKey]}))}function hb(e,t){const{series_name_key:n,dimensions:r}=t;return[{type:"radar",name:"main-radar",data:pb(e,n,r),symbolSize:4,lineStyle:{width:1},emphasis:{lineStyle:{width:4}},areaStyle:t.background.enabled?{opacity:.4}:void 0,label:_o(t)}]}function xb(e,t){const{additional_series:n,dimensions:r}=t;return n.map(o=>{const l=A(o.name_key),c=A(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:So(h,r),itemStyle:{color:x}}}),symbolSize:4,lineStyle:{width:1},emphasis:{lineStyle:{width:4}},areaStyle:t.background.enabled?{opacity:.4}:void 0,label:_o(t)}}).flat()}function fb(e,t){return[...hb(e,t),...xb(e,t)]}function gb(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
211
|
<td style="padding-left: 18px;">${c.name}</td>
|
|
212
212
|
<td style="text-align: right; "><strong>${u(o)}</strong></td>
|
|
@@ -234,7 +234,7 @@ Check the top-level render call using <`+E+">.")}return I}}function iu(w,I){{if(
|
|
|
234
234
|
${i.join("")}
|
|
235
235
|
</tbody>
|
|
236
236
|
</table>
|
|
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?"":`
|
|
237
|
+
`}}const mb={legend:{show:!0,bottom:0,left:0},tooltip:{trigger:"item"}},yb=["#66B4DB","#39BFA2","#E46464","#33A678","#EEBA00","#9D88CB","#939943","#E49792","#09A2B8","#AF5F6B","#6CA157","#09A2B8","#6398C7","#E692BA","#97B566","#8CACE2","#CA79AC","#6DBC80","#B08F4B","#826BAF"];function bb(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:gb(e)}),legend:{show:!0,bottom:0,left:"center",type:"scroll"},series:fb(t,e),color:yb};return y.merge({},mb,l)}function vb({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const l=f.useMemo(()=>{const{queryID:p,columnKey:x}=A(e.series_name_key),m=y.keyBy(t[p],x),v=e.additional_series.reduce((C,S)=>{const D=A(S.name_key),P=y.keyBy(t[D.queryID],D.columnKey);return{...C,...P}},m);return{...m,...v}},[t,e.series_name_key,e.additional_series]),c=qe(i.triggerManager,wo.id),u=f.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=f.useMemo(()=>({click:u}),[u]),h=f.useMemo(()=>bb(y.defaultsDeep({},e,Wn),t),[e,t]);return!n||!r?null:s.jsx(Ce,{echarts:ve,option:h,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function jb({context:e,instance:t}){const n=Ve({vizManager:e.vizManager,instance:t}),{value:r}=$(e.instanceData,"config"),{variables:i}=e,o=f.useMemo(()=>y.defaults({},r,Wn),[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(Te,{width:c,height:u,children:s.jsx(vb,{variables:i,width:Re(c),height:Qe(u),data:l,conf:o,interactionManager:n})})}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.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(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),children:"Delete"})]})}function Cb({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]=f.useState(u);f.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(k.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(k.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 _b({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(Ne,{...r})})]}),s.jsx(a.Button,{mt:20,leftIcon:s.jsx(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this Metric"})]})}function Sb({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:ye})},u=y.get(l,"0.id",null),[d,h]=f.useState(u);f.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(k.IconPlus,{size:18,color:"#228be6"})})]}),l.map((x,m)=>s.jsx(a.Tabs.Panel,{value:x.id,children:s.jsx(_b,{control:e,index:m,remove:p})},x.id))]})})}function kb({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},t,Wn),[t]),{control:i,handleSubmit:o,watch:l,getValues:c,reset:u,formState:d}=b.useForm({defaultValues:r,mode:"all"});f.useEffect(()=>{u(r)},[r]),l(["series_name_key","background","label"]);const h=c(),p=f.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(T.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(Sb,{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(Cb,{control:i,watch:l})})]})]})})}function Tb(e){const{dimensions:t=[],...n}=e;function r({name:i="",data_key:o="",max:l=10,formatter:c=ye}){return{name:i,data_key:o,max:l,formatter:c}}return{...n,dimensions:t.map(r)}}function Db(e){const{dimensions:t=[],...n}=e;return{...n,dimensions:t.map(r=>({...r,id:r.id??r.name}))}}function Ib(e){const t={background:{enabled:!0},label:{enabled:!0}};return y.defaultsDeep(t,e)}function Mb(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=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 zb(e){const t={additional_series:[]};return y.defaultsDeep(t,e)}function Ab(e){const t={...e,dimensions:e.dimensions.map(n=>({...n,max:String(n.max)}))};return delete t.additionalSeries,t}class Eb extends oe{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:Tb(r)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:Db(r)}}),this.version(4,n=>{const{config:r}=n;return{...n,version:4,config:Ib(r)}}),this.version(5,(n,r)=>{const{config:i}=n;return{...n,version:5,config:Mb(i,r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:zb(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:Ab(r)}})}}const Pb={displayName:"Radar Chart",displayGroup:"ECharts-based charts",migrator:new Eb,name:"radar",viewRender:jb,configRender:kb,createConfig:()=>({version:7,config:Wn}),triggers:[wo]};function Lb(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 ko(e,t){const n=A(e.x_axis.data_key),r=A(e.regression.y_axis_data_key);return y.uniqBy(t.map(i=>[i[n.columnKey],i[r.columnKey]]),0)}function Bb(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:[In(r,i)],color:"blue",smooth:!0,silent:!0,symbol:["none","none"]}}]}function Ob(e,t){const{plot:n,transform:r,group_by_key:i}=e.regression,o=A(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:[In(r,d)],smooth:!0,silent:!0,symbol:["none","none"]}}})}function $b(e,t){if(t.length===0)return[];const{group_by_key:n}=e.regression;return n?Ob(e,t):Bb(e,t)}function qb(e){return Array.isArray(e)||(e=[e]),e.map(t=>({marker:t.marker,label:t.seriesName,x:t.value[0],y:t.value[1]}))}function Vb(e){return ee.getTooltip({trigger:"axis",formatter:t=>{const n=qb(t);return n.length===0?"":`
|
|
238
238
|
<table style="width: auto">
|
|
239
239
|
<thead>
|
|
240
240
|
<tr>
|
|
@@ -253,38 +253,38 @@ Check the top-level render call using <`+E+">.")}return I}}function iu(w,I){{if(
|
|
|
253
253
|
</tr>
|
|
254
254
|
</tbody>
|
|
255
255
|
</table>
|
|
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
|
|
257
|
-
`)},cr={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,format:
|
|
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 Nb(e){const{overflow:t,format:n,formatter:r,...i}=e.x_axis.axisLabel,o=$e(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=R(l,n)}catch{}return To(r)(u,c)}}})}const Fb={tooltip:{trigger:"axis"},grid:{top:50,left:5,right:10,bottom:20,containLabel:!0},dataZoom:[{type:"inside",xAxisIndex:[0]},{type:"inside",yAxisIndex:[0]}]};function Gb(e,t){const n=$b(e,t),r=Lb(e,n),i={xAxis:Nb(e),yAxis:ee.getYAxis({name:e.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"left"},nameGap:5}),series:[...n,...r],tooltip:Vb(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,Fb)}const Do={output:"number",mantissa:2,trimMantissa:!0,absolute:!1};function Rn(e,t,n){return 1-(1-e)*(t-1)/(t-n-1)}function Wb(e,t,n,r){const{x_axis:i,y_axis:o}=r,l=ft.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:R(u,Do)}),s.jsx(a.Text,{children:"+"}),s.jsx(a.Text,{weight:"bold",color:"red",children:R(c,Do)}),s.jsx(a.Text,{children:"×"}),s.jsx(a.Text,{children:i.name})]}),rSquared:d,adjustedRSquared:Rn(d,t.length,1)}}function Rb(e,t,n,r){const{x_axis:i,y_axis:o}=r,{a:l,b:c,rSquared:u}=ft.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:Rn(u,t.length,1)}}function Qb(e,t,n,r){const{x_axis:i,y_axis:o}=r,{a:l,b:c,rSquared:u}=ft.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:Rn(u,t.length,1)}}function Ub(e,t,n,r){const{x_axis:i,y_axis:o,regression:l}=r,c=ft.regressionPoly().order(l.transform.config.order)(n),{rSquared:u}=c;return console.log(c),{name:e,expression:"",rSquared:u,adjustedRSquared:Rn(u,t.length,1)}}function Io(e,t,n){const{regression:r,x_axis:i}=n,o=A(i.data_key),l=A(r.y_axis_data_key),c=t.map(u=>[u[o.columnKey],u[l.columnKey]]);return r.transform.config.method==="linear"?Wb(e,t,c,n):r.transform.config.method==="exponential"?Rb(e,t,c,n):r.transform.config.method==="logarithmic"?Qb(e,t,c,n):r.transform.config.method==="polynomial"?Ub(e,t,c,n):{name:e,expression:"",rSquared:0,adjustedRSquared:0}}function Kb(e,t){if(!t)return[{name:"",expression:"",rSquared:0,adjustedRSquared:0}];if(!t.regression.group_by_key)return[Io("",e,t)];const n=A(t.regression.group_by_key),r=y.groupBy(e,n.columnKey);return Object.entries(r).map(([i,o])=>Io(i,o,t))}const Yb={marginTop:"10px","tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function Mo({desc:e}){const{expression:t,rSquared:n,adjustedRSquared:r}=e;return t?s.jsx(a.Table,{fontSize:14,sx:Yb,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:R(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:R(r,{output:"percent",mantissa:1,absolute:!1})})]})]})}):s.jsx(a.Text,{children:"Unavailable for this regression method"})}function Xb({conf:e,queryData:t}){var r;const n=f.useMemo(()=>Kb(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 Jb({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(k.IconInfoCircle,{size:14}),children:"Regression Info"})}),s.jsx(a.HoverCard.Dropdown,{children:s.jsx(je,{children:s.jsx(Xb,{conf:e,queryData:t})})})]})}function Zb(e){return s.jsx(a.Group,{position:"apart",sx:{position:"absolute",top:0,left:ke.left,right:ke.right,height:"22px",zIndex:1},children:s.jsx(Jb,{...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:ye,overflow:De(),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"}};function Hb({context:e}){const{value:t}=$(e.instanceData,"config"),{width:n,height:r}=e.viewport,i=f.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=A(d),x=A(h);return u[p.queryID].map(v=>typeof v[x.columnKey]=="number"?v:{...v,[x.columnKey]:Number(v[x.columnKey])})},[e.data,t==null?void 0:t.regression.y_axis_data_key]),o=f.useMemo(()=>Gb(y.defaultsDeep({},t,cr),i),[t,i]),l=f.useRef(null),c=u=>{l.current=u};return!n||!r||!t?null:s.jsxs(Te,{width:n,height:r,children:[s.jsx(Zb,{conf:t,queryData:i}),s.jsx(Ce,{echarts:ve,onChartReady:c,option:o,style:Ht(n,r),notMerge:!0,theme:"merico-light"})]})}const ev=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}];function tv({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:ev,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(_e,{...i})})]})]})}const nv=({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(ge,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},zo=f.forwardRef(({value:e,onChange:t,triggerButtonText:n="Customize Label"},r)=>{const[i,{setTrue:o,setFalse:l}]=V.useBoolean(),[c,u]=f.useState(e);f.useEffect(()=>{u(e)},[e]);const d=v=>{u({...c,enabled:v})},h=()=>{l();const{enabled:v,func_content:C}=c,S={enabled:v,func_content:C};u(S),t(S)},p=()=>{l(),u(e)},x=v=>{u(C=>({...C,func_content:v}))},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:c.enabled,onChange:v=>d(v.currentTarget.checked)}),s.jsx(nv,{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(T.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 sv({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(Ne,{...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(Ue,{...n})})]})}function rv({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 iv({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaults({},t,cr),[t]),{control:i,handleSubmit:o,watch:l,getValues:c,reset:u}=b.useForm({defaultValues:r});f.useEffect(()=>{u(r)},[r]),l(["x_axis","y_axis","regression"]);const d=c(),h=f.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(T.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(sv,{watch:l,control:i})}),s.jsx(a.Tabs.Panel,{value:"Y轴",children:s.jsx(rv,{watch:l,control:i})}),s.jsx(a.Tabs.Panel,{value:"回归",children:s.jsx(tv,{control:i,watch:l})})]})]})})}function av(e){const t={x_axis:{axisLabel:{rotate:0,format:ye,overflow:De(),formatter:Qn}},regression:{group_by_key:""}};return y.defaultsDeep(t,e)}function ov(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 lv extends oe{constructor(){super(...arguments);L(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:av(n.config)})),this.version(3,(n,r)=>{const{config:i}=n;return{...n,version:3,config:ov(i,r)}})}}const cv={displayName:"Regression Chart",displayGroup:"Merico suite",migrator:new lv,name:"regressionChart",viewRender:Hb,configRender:iv,createConfig(){return{version:3,config:y.cloneDeep(cr)}}},Un={content:""};function uv(e,t){const n={};return e.forEach(r=>{const{name:i,data_field:o,aggregation:l}=r,c=bn(t,o,l);n[i]=Pe(r,c)}),n}function dv(e){const t=document.createElement("span");return t.innerHTML=e,t.innerText}function pv(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
|
|
264
|
-
`)}},Ao={id:"builtin:echarts:click-scatter-chart:series",displayName:"Click Scatter",nameRender:
|
|
265
|
-
`)}}function Po(){const{on_axis:e,in_tooltip:t}=
|
|
263
|
+
`)(n)}catch(r){return console.error(r),console.log(e),e}}function hv(e,t,n,r){const i=uv(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=dv(c[1]);return`${pv(d,i,n)}${c[2]}`}).join("")}const xv=_.observer(({context:e})=>{const t=ue(),{value:n}=$(e.instanceData,"config"),{variables:r,data:i}=e,o=f.useMemo(()=>{const l=y.defaults({},n,Un);return l.content?hv(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 fv(){const{editor:e}=G.useRichTextEditorContext();return s.jsx(G.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(k.IconBorderAll,{stroke:1.5,size:16})})}const ur=f.forwardRef(({value:e,onChange:t,styles:n={},label:r,onSubmit:i},o)=>{const[l,c]=f.useState(e),u=Gi.useEditor({extensions:[Wi,Fi,G.Link,Li,Pi,Ai,$i.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),Ni,Vi,qi,Bi.configure({types:["heading","paragraph"]}),Ei.configure({placeholder:"This is placeholder"}),Oi,zi.Color,po],content:l,onUpdate:({editor:x})=>{c(x.getHTML())}});f.useEffect(()=>{c(e),u==null||u.commands.setContent(e)},[e]);const d=()=>{t(l),i==null||i()},h=e!==l,p=f.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(k.IconDeviceFloppy,{size:18})})]}),s.jsxs(G.RichTextEditor,{editor:u,styles:p,children:[s.jsxs(G.RichTextEditor.Toolbar,{sticky:!0,stickyOffset:0,children:[s.jsx(G.RichTextEditor.ControlsGroup,{children:s.jsx(G.RichTextEditor.ColorPicker,{colors:["#25262b","#868e96","#fa5252","#e64980","#be4bdb","#7950f2","#4c6ef5","#228be6","#15aabf","#12b886","#40c057","#82c91e","#fab005","#fd7e14"],popoverProps:{zIndex:320}})}),s.jsxs(G.RichTextEditor.ControlsGroup,{children:[s.jsx(G.RichTextEditor.Bold,{}),s.jsx(G.RichTextEditor.Italic,{}),s.jsx(G.RichTextEditor.Underline,{}),s.jsx(G.RichTextEditor.ClearFormatting,{}),s.jsx(G.RichTextEditor.Highlight,{}),s.jsx(G.RichTextEditor.Code,{})]}),s.jsxs(G.RichTextEditor.ControlsGroup,{children:[s.jsx(G.RichTextEditor.H1,{}),s.jsx(G.RichTextEditor.H2,{}),s.jsx(G.RichTextEditor.H3,{}),s.jsx(G.RichTextEditor.H4,{})]}),s.jsxs(G.RichTextEditor.ControlsGroup,{children:[s.jsx(G.RichTextEditor.Blockquote,{}),s.jsx(G.RichTextEditor.Hr,{}),s.jsx(G.RichTextEditor.BulletList,{}),s.jsx(G.RichTextEditor.OrderedList,{}),s.jsx(G.RichTextEditor.Subscript,{}),s.jsx(G.RichTextEditor.Superscript,{})]}),s.jsxs(G.RichTextEditor.ControlsGroup,{children:[s.jsx(G.RichTextEditor.Link,{}),s.jsx(G.RichTextEditor.Unlink,{})]}),s.jsxs(G.RichTextEditor.ControlsGroup,{children:[s.jsx(G.RichTextEditor.AlignLeft,{}),s.jsx(G.RichTextEditor.AlignCenter,{}),s.jsx(G.RichTextEditor.AlignJustify,{}),s.jsx(G.RichTextEditor.AlignRight,{})]}),s.jsx(G.RichTextEditor.ControlsGroup,{children:s.jsx(fv,{})}),s.jsx(yg,{editor:u})]}),s.jsx(G.RichTextEditor.Content,{})]})]}):null});function gv({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaults({},t,Un),[t]),{control:i,handleSubmit:o,watch:l,reset:c}=b.useForm({defaultValues:r});l("content"),f.useEffect(()=>{c(r)},[r]);const u=f.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(T.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 mv extends oe{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 yv={displayName:"Rich Text",displayGroup:"Others",migrator:new mv,name:"richText",viewRender:xv,configRender:gv,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
|
+
`)}},Ao={id:"builtin:echarts:click-scatter-chart:series",displayName:"Click Scatter",nameRender:vv,configRender:bv,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 bv(e){return s.jsx(s.Fragment,{})}function vv(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}=De();return{label:e,tooltip:t}}const dr={scatter:{y_data_key:"",name_data_key:"",symbolSize:{type:"static",size:10},color:on.static,label_position:"right",label_overflow:Po()},stats:{templates:{top:"",bottom:""}},x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:Eo(),overflow:De()}},y_axes:[{name:"Y Axis",position:"left",nameAlignment:"center",label_formatter:ye,min:"",max:"",show:!0}],tooltip:{trigger:"item",metrics:[]},reference_lines:[],reference_areas:[],dataZoom:vt};function jv(e,t){if(!e.x_axis.data_key)return[];const n=A(e.x_axis.data_key);return[{source:t[n.queryID]}]}function wv(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 Cv(){return{show:!1,bottom:0,left:"center",type:"scroll"}}function Kn(e,t){if(e)return t[e]??void 0}function _v({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 Sv({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(c){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${c.message}`),10}}}function kv({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 Tv(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?vn(i.template,t,r):""},position:c}}}})}function Dv({x_axis:e,scatter:t},n){const r=A(e.data_key),i=A(t.y_data_key),o=A(t.name_data_key);return{label:{show:!!t.label_position,position:t.label_position,...$e(t.label_overflow.label),formatter:({value:l})=>l[o.columnKey]},type:"scatter",name:"",xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{color:kv(t.color,n)},symbolSize:Sv(t.symbolSize,n),encode:{x:r.columnKey,y:i.columnKey}}}function Iv(e,t,n,r){return[Dv(e,r)].concat(Tv(e.reference_lines,n,r,t)).concat(_v({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 Mv(e,t){const{x_axis:n,tooltip:r}=t;if(r.trigger==="item"){const c=yn(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 zv=e=>R(e,{output:"number",trimMantissa:!0,mantissa:2,absolute:!1});function Av(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=Mv(l,e),u=Oe(e.scatter.label_overflow.tooltip),d=l.map(({value:v})=>`
|
|
266
266
|
<th style="text-align: right; padding-right: 1em">
|
|
267
|
-
<div style="${u}">${
|
|
267
|
+
<div style="${u}">${yn(v,n.name_data_key)}</div>
|
|
268
268
|
</th>
|
|
269
|
-
`);d.unshift("<th></th>");const h=
|
|
269
|
+
`);d.unshift("<th></th>");const h=Oe(e.x_axis.axisLabel.overflow.in_tooltip),p=[`<tr>
|
|
270
270
|
<th style="text-align: right;">${e.x_axis.name}</th>
|
|
271
|
-
${l.map(
|
|
271
|
+
${l.map(v=>`<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
|
-
${l.map(({value:
|
|
274
|
+
${l.map(({value:v})=>`
|
|
275
275
|
<td style="text-align: right; padding: 0 1em;">
|
|
276
|
-
${o(
|
|
276
|
+
${o(yn(v,n.y_data_key))}
|
|
277
277
|
</td>`).join("")}
|
|
278
|
-
</tr>`],x=e.tooltip.metrics.map(
|
|
279
|
-
<th style="text-align: right;">${
|
|
280
|
-
${l.map(({value:C})=>`<td style="text-align: right; padding: 0 1em;">${
|
|
278
|
+
</tr>`],x=e.tooltip.metrics.map(v=>`<tr>
|
|
279
|
+
<th style="text-align: right;">${v.name}</th>
|
|
280
|
+
${l.map(({value:C})=>`<td style="text-align: right; padding: 0 1em;">${zv(yn(C,v.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 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>
|
|
286
|
+
`}})}function Ev(e,t){const n=t.every(c=>!Number.isNaN(Number(c))),{overflow:r,...i}=e.x_axis.axisLabel,o=$e(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 Pv(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 Lv={xAxis:[{type:"category",nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0}}],grid:{top:10,left:20,right:15,bottom:25,containLabel:!0}};function Bv(e,t,n){const r=n.reduce((u,d)=>{const h=it(d,t);return u[d.name]=Pe(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 R(m,d)}catch(v){return console.error(v),m}},u),{default:({value:u})=>u}),o=y.uniq(Ze(t,e.x_axis.data_key)),l=Iv(e,t,n,r),c={xAxis:Ev(e,o),yAxis:Pv(e,i),series:l,dataset:jv(e,t),tooltip:Av(e,i),grid:wv(e),legend:Cv(),dataZoom:kn(e.dataZoom)};return y.defaultsDeep({},c,Lv)}function Oo(e){return e.trim().length>0}function Ov({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const l=jt(t,e.x_axis.data_key),c=qe(i.triggerManager,Ao.id),u=f.useCallback(p=>{const x=p.data;c.forEach(m=>{i.runInteraction(m.id,{...p,rowData:x})})},[l,c,i]),d=f.useMemo(()=>({click:u}),[u]),h=f.useMemo(()=>Bv(e,t,o),[e,t]);return s.jsx(Ce,{echarts:ve,option:h,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function $v({context:e,instance:t}){const n=Ve({vizManager:e.vizManager,instance:t}),{value:r}=$(e.instanceData,"config"),{variables:i}=e,o=f.useMemo(()=>y.defaults({},r,dr),[r]),l=e.data,{width:c,height:u}=e.viewport,{ref:d,height:h}=ie.useElementSize(),{ref:p,height:x}=ie.useElementSize(),m=f.useMemo(()=>{const{stats:{templates:C}}=o;return{top:Zt(C.top,i,l),bottom:Zt(C.bottom,i,l)}},[o,l]),v=Math.max(0,Qe(u)-h-x);return!c||!u?null:s.jsxs(Te,{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(Ov,{variables:i,width:Re(c),height:v,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 qv=f.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(_e,{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(_e,{value:e.label.color,onChange:c=>l("label.color",c)})]})]})});function Vv(){const e=new Date().getTime().toString();return{id:e,content:{text:e},itemStyle:{color:"rgba(0,0,0,0.05)"},label:{position:"inside",color:"rgba(0,0,0,0.5)"},leftBottomPoint:{x_data_key:"",y_data_key:""},rightTopPoint:{x_data_key:"",y_data_key:""},xAxisIndex:"0",yAxisIndex:"0"}}function Nv({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=Vv();i(x)},d=f.useMemo(()=>n.map(x=>({label:x.name,value:x.name})),[n]),h=t("y_axes"),p=f.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(T.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:v})=>s.jsxs(a.Stack,{children:[s.jsx(qv,{variableOptions:d,yAxisOptions:p,...v}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed"}),s.jsx(a.Button,{leftIcon:s.jsx(k.IconTrash,{size:16}),color:"red",variant:"light",onClick:()=>o(m),children:"Delete this Reference Area"})]})})},x.id))]})}const Fv=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Gv=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Wv({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:Gv,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:Fv,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(_e,{...c})})]}),s.jsx(a.Button,{leftIcon:s.jsx(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]})}function Rv({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:st.random().css()},show_in_legend:!1,yAxisIndex:0};i(x)},d=f.useMemo(()=>n.map(x=>({label:x.name,value:x.name})),[n]),h=t("y_axes"),p=f.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(T.Plus,{size:18,color:"#228be6"})})]}),c.map((x,m)=>s.jsx(a.Tabs.Panel,{value:m.toString(),children:s.jsx(Wv,{control:e,index:m,remove:o,watch:t,variableOptions:d,yAxisOptions:p})},x.id))]})}const Qv=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return s.jsx(a.Box,{children:s.jsx(ge,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Uv=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:i}]=V.useBoolean(),[o,l]=f.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(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(Qv,{value:o.func_content,onChange:d}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:h,color:"red",leftIcon:s.jsx(T.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"})]})]})]})})]})},Kv=({value:e,onChange:t})=>e.type!=="dynamic"?null:s.jsx(Uv,{value:e,onChange:t}),Yv=({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})},Xv=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Jv=f.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:Xv,value:t.type,onChange:i,sx:{flexGrow:1}}),s.jsx(Yv,{value:t,onChange:n}),s.jsx(Kv,{value:t,onChange:n})]})}),Zv=f.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(_n,{sectionTitle:"Overflow on Chart",value:e.label,onChange:r}),s.jsx(_n,{sectionTitle:"Overflow in Tooltip",value:e.tooltip,onChange:i})]})}),Hv=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return s.jsx(a.Box,{children:s.jsx(ge,{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
|
+
`)}},ej=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:i}]=V.useBoolean(),[o,l]=f.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(Hv,{value:o.func_content,onChange:d}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:h,color:"red",leftIcon:s.jsx(T.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"})]})]})]})})]})},tj=({value:e,onChange:t})=>e.type!=="dynamic"?null:s.jsx(ej,{value:e,onChange:t}),nj=({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})})},sj=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],rj=f.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:sj,value:t.type,onChange:i,sx:{flexGrow:1}}),s.jsx(nj,{value:t,onChange:n}),s.jsx(tj,{value:t,onChange:n})]})}),ij=[{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 aj({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(rj,{label:"Size",...n})}),s.jsx(b.Controller,{name:"scatter.color",control:e,render:({field:n})=>s.jsx(Jv,{...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:ij,...n})})}),s.jsx(b.Controller,{name:"scatter.label_overflow",control:e,render:({field:n})=>s.jsx(Zv,{...n})})]})}function oj({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 lj=({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(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),cj=({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]=f.useState(()=>u??null);return f.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(T.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(T.Plus,{size:18,color:"#228be6"})})]}),l.map((p,x)=>s.jsx(a.Tabs.Panel,{value:p.id,children:s.jsx(lj,{control:e,index:x,remove:i},p.id)},p.id))]})]})},uj=[{label:"Scatter Point",value:"item"},{label:"X Axis",value:"axis"}];function dj({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:uj,sx:{flexGrow:1},...n})}),s.jsx(a.Divider,{variant:"dashed"}),s.jsx(cj,{control:e,watch:t})]})}const pj=({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(ge,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},hj=f.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:i,setFalse:o}]=V.useBoolean(),[l,c]=f.useState(e);f.useEffect(()=>{c(e)},[e]);const u=m=>{c({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:v}=l,C={enabled:m,func_content:v};c(C),t(C)},h=()=>{o(),c(e)},p=m=>{c(v=>({...v,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(pj,{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(T.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 xj({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(hj,{...n})})]}),s.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>s.jsx(Ue,{...n})})]})}const fj=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],gj=[{label:"left",value:"left"},{label:"right",value:"right"}];function mj({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:fj,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:gj,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(Ne,{...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(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this YAxis"})]})}function yj({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:ye,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(T.Plus,{size:18,color:"#228be6"})})]}),l.map((u,d)=>s.jsx(a.Tabs.Panel,{value:d.toString(),children:s.jsx(mj,{control:e,index:d,remove:i})},u.id))]})}function bj(e){return e||{templates:{top:"",bottom:""}}}function vj({reference_lines:e=[],stats:t,...n}){return{reference_lines:e,stats:bj(t),...n}}function jj({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),{variables:r}=e,i=f.useMemo(()=>y.defaultsDeep({},t,dr),[t]),o=f.useMemo(()=>vj(i),[i]);f.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});f.useEffect(()=>{h(o)},[o]);const p=d(),x=f.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(T.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(xj,{control:l,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Y Axes",children:s.jsx(yj,{control:l,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Scatter",children:s.jsx(aj,{control:l,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(dj,{control:l,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Stats",children:s.jsx(oj,{control:l,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Reference Lines",children:s.jsx(Rv,{variables:r,control:l,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Reference Areas",children:s.jsx(Nv,{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(Dn,{...m})})})]})]})})}function wj(e){const{dataZoom:t=vt,...n}=e;return{...n,dataZoom:t}}function Cj(e){const t={scatter:{label_overflow:Po()}};return y.defaultsDeep(t,e)}function _j(e){const{color:t}=e.scatter;return typeof t=="string"?{...e,scatter:{...e.scatter,color:{...on.static,color:t}}}:e}function Sj(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 kj(e){const t={tooltip:{trigger:"item"}};return y.defaultsDeep({},e,t)}function Tj(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 Dj(e){const t={x_axis:{axisLabel:{overflow:De()}}};return y.defaultsDeep(t,e)}class Ij extends oe{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:wj(n.config)})),this.version(4,n=>{const{config:r}=n;return{...n,version:5,config:Cj(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:_j(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:Sj(r)}}),this.version(8,n=>{const{config:r}=n;return{...n,version:8,config:kj(r)}}),this.version(9,(n,r)=>{const{config:i}=n;return{...n,version:9,config:Tj(i,r)}}),this.version(10,(n,r)=>{const{config:i}=n;return{...n,version:10,config:Dj(i)}})}}const Mj={displayName:"Scatter Chart",displayGroup:"ECharts-based charts",migrator:new Ij,name:"scatterChart",viewRender:$v,configRender:jj,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 zj(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 Aj(e){return y.omit(e,["variables"])}function Ej(e){const{align:t,...n}=e;return{horizontal_align:t,vertical_align:"center",...n}}function Pj(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 Lj extends oe{constructor(){super(...arguments);L(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:zj(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(Pj(l))}),{...n,version:2,config:Aj(i)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:Ej(r)}})}}const Bj={left:"flex-start",center:"center",right:"flex-end"},Oj={top:"flex-start",center:"center",bottom:"flex-end"},$j=_.observer(({context:e})=>{const t=ue(),{value:n=pr}=$(e.instanceData,"config"),{variables:r}=e,{template:i,horizontal_align:o,vertical_align:l}=n,{width:c,height:u}=e.viewport,d=f.useMemo(()=>{try{return y.template(i)(t.payloadForSQL)}catch{return i}},[t.payloadForSQL,i]),h=f.useMemo(()=>Zt(d,r,e.data),[d,r,e.data,e]);return s.jsx(a.Center,{sx:{width:c,height:u,justifyContent:Bj[o],alignItems:Oj[l]},children:s.jsx(a.Box,{children:Object.values(h).map((p,x)=>s.jsx(f.Fragment,{children:p},x))})})}),qj=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Vj=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function Nj({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},t,pr),[t]),{control:i,handleSubmit:o,watch:l,getValues:c,reset:u}=b.useForm({defaultValues:r});f.useEffect(()=>{u(r)},[r]),l(["template","horizontal_align","vertical_align"]);const d=c(),h=f.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(T.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:qj,...p})}),s.jsx(b.Controller,{control:i,name:"vertical_align",render:({field:p})=>s.jsx(a.Select,{label:"Vertical Alignment",data:Vj,...p})})]})]})})}const Fj={createConfig(){return{version:3,config:pr}},displayName:"Stats",displayGroup:"Others",migrator:new Lj,name:"stats",viewRender:$j,configRender:Nj},hr={label_key:"",value_key:"",group_key:"",levels:[]};function Gj(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 Wj(e){const t=Gj(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 Rj(e,t){const{label_key:n,value_key:r,group_key:i}=e;if(!n||!r)return[];const o=A(n),l=A(r),c=A(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?Wj(u):u}const Qj=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 Uj(e){const{levels:t}=e;return t.map(n=>{const{show_label_tolerance:r,...i}=n.label;return{...n,label:{...i,formatter:Qj(r)}}})}function Kj(){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>
|
|
@@ -292,7 +292,7 @@ Check the top-level render call using <`+E+">.")}return I}}function iu(w,I){{if(
|
|
|
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
|
-
${
|
|
295
|
+
${R(n/d,{output:"percent",mantissa:2,trimMantissa:!0,absolute:!1})}
|
|
296
296
|
</td>
|
|
297
297
|
</tr>
|
|
298
298
|
`)}),`
|
|
@@ -302,9 +302,9 @@ Check the top-level render call using <`+E+">.")}return I}}function iu(w,I){{if(
|
|
|
302
302
|
<table style="width: auto">
|
|
303
303
|
<tbody>${c.join("")}</tbody>
|
|
304
304
|
</table>
|
|
305
|
-
`}}function
|
|
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=>`
|
|
305
|
+
`}}function Yj(){return ee.getTooltip({trigger:"item",formatter:Kj()})}const Xj={tooltip:{show:!0},series:{type:"sunburst",radius:[0,"90%"],emphasis:{focus:"ancestor"}}};function Jj(e,t,n){n.reduce((o,l)=>{const c=it(l,t);return o[l.name]=Pe(l,c),o},{});const i={series:{data:Rj(e,t),levels:Uj(e)},tooltip:Yj()};return y.defaultsDeep({},i,Xj)}function Zj({context:e}){const{variables:t}=e,{value:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaults({},n,hr),[n]),i=e.data,{width:o,height:l}=e.viewport,c=f.useMemo(()=>Jj(r,i,t),[r,i,t]);return!o||!l?null:s.jsx(Te,{width:o,height:l,children:s.jsx(Ce,{echarts:ve,option:c,style:Ht(o,l),notMerge:!0,theme:"merico-light"})})}function Hj({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 ew=[{label:"Radial",value:"radial"},{label:"Tangential",value:"tangential"},{label:"None",value:"0"}],tw=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],nw=({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:ew,...r})}),s.jsx(b.Controller,{name:`levels.${t}.label.align`,control:e,render:({field:r})=>s.jsx(a.Select,{label:"Align",data:tw,...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(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Level"})]}),sw=({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]=f.useState(()=>u??null);return f.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(T.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(T.Plus,{size:18,color:"#228be6"})})]}),l.map((p,x)=>s.jsx(a.Tabs.Panel,{value:p.id,children:s.jsx(nw,{control:e,index:x,remove:i},p.id)},p.id))]})]})};function rw({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},t,hr),[t]),i=f.useMemo(()=>y.clone(r),[r]),{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=b.useForm({defaultValues:i});f.useEffect(()=>{d(i)},[i]);const h=u(),p=f.useMemo(()=>!y.isEqual(h,r),[h,r]);c(["label_key","value_key","group_key","levels"]);const[x,m]=f.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(T.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(Hj,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Levels",children:s.jsx(sw,{control:o,watch:c})})]})]})})}function iw(e){const{label_field:t,value_field:n,...r}=e;return{...r,label_key:t,value_key:n}}function aw(e){const{group_key:t="",...n}=e;return{...n,group_key:t}}function ow(e){const{levels:t=[],...n}=e;return{...n,levels:t}}function lw(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 cw extends oe{constructor(){super(...arguments);L(this,"VERSION",5)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:iw(n.config)})),this.version(3,n=>({...n,version:3,config:aw(n.config)})),this.version(4,n=>({...n,version:4,config:ow(n.config)})),this.version(5,(n,r)=>({...n,version:5,config:lw(n.config,r)}))}}const uw={displayName:"Sunburst Chart",displayGroup:"ECharts-based charts",migrator:new cw,name:"sunburst",viewRender:Zj,configRender:rw,createConfig(){return{version:5,config:y.cloneDeep(hr)}}};var Ke=(e=>(e.string="string",e.number="number",e.eloc="eloc",e.percentage="percentage",e.custom="custom",e))(Ke||{});const qo=["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"},No={left:"flex-start",center:"center",right:"flex-end"},dw=({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:We.flexRender(e.column.columnDef.header,e.getContext()),s.jsx(pw,{direction:e.column.getIsSorted()})]})},pw=({direction:e})=>{switch(e){case"asc":return s.jsx(k.IconArrowUp,{size:16});case"desc":return s.jsx(k.IconArrowDown,{size:"1em"});default:return null}},hw=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"}})),xw={tableLayout:"fixed","thead, tbody":{tr:{"th, td":{padding:"2px 10px",div:{overflow:"hidden",textOverflow:"ellipsis"},"&:first-of-type":{paddingLeft:2,paddingRight:2}}}}},fw=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 gw(e){return e?st(e).oklch()[0]>.7?"black":"white":"inherit"}function mw(e){const t=e.tableCellContext.bgColor;return{backgroundColor:t,color:gw(t)}}function Nt(e){const t=e.tableCellContext.isClickable(),n=fw({clickable:t,align:e.align});return s.jsx("div",{className:n.classes.content,style:{...mw(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 yw(e){return s.jsx(Nt,{...e,children:e.value})}function bw(e){const t=R(e.value,{output:"number",average:!0,mantissa:2,trimMantissa:!0,absolute:!1});return s.jsx(Nt,{...e,children:t})}function vw(e){const t=R(e.value,{output:"number",mantissa:0,thousandSeparated:!0,absolute:!1});return s.jsx(Nt,{...e,children:t})}function jw(e){const t=R(e.value,{output:"percent",mantissa:3,trimMantissa:!0,absolute:!1});return s.jsx(Nt,{...e,children:t})}function ww(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 Cw(e){switch(e.type){case Ke.string:return s.jsx(yw,{...e});case Ke.eloc:return s.jsx(bw,{...e});case Ke.number:return s.jsx(vw,{...e});case Ke.percentage:return s.jsx(jw,{...e});case Ke.custom:return s.jsx(ww,{...e})}}function _w({tableContainerRef:e,rows:t}){var c,u;const n=hu.useVirtual({parentRef:e,size:t.length,estimateSize:f.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 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:We.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:Dw,configRender:kw,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"}]},Sw={column:""};function Fo(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 kw(e){const{columnsFromConfig:t,columnsFromData:n}=Fo(e.instance,e.sampleData),r=t.length>0?t:n,{value:i,set:o}=$(e.trigger.triggerData,"config"),{column:l}=y.defaults({},i,Sw),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 Tw(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 Dw(e){const{columnsFromConfig:t}=Fo(e.instance),{value:n}=$(e.trigger.triggerData,"config");return s.jsx(a.Text,{children:Tw(n,t)})}function Go(e,t,n){return Math.min(Math.max(e,t),n)}class Iw{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 Mw{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 Iw(t.steps).mapValue(n);return r==null?void 0:r.getColor(o)}}}const zw=e=>{const t=Ve(e),n=qe(t.triggerManager,xr.id),{colorManager:r}=f.useContext(tt);return f.useCallback(i=>new Mw(e.getColIndex,i,n,t,r),[n,t,e.getColIndex])};function Aw({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}=hw(),x=f.useMemo(()=>c?!Array.isArray(e)||e.length===0?[]:Object.keys(e[0]).map(te=>({id:te,label:te,value_field:te,value_type:Ke.string,align:"left",width:"",cellBackgroundColor:""})):u,[c,u,e]),m=zw({getColIndex:f.useCallback(te=>x.indexOf(te.column.columnDef.meta),[x]),vizManager:i.vizManager,instance:o}),v=f.useMemo(()=>{const te=We.createColumnHelper();return x.map(Ye=>{const yi=ud(Ye.value_field);return te.accessor(yi.columnKey,{cell:pn=>s.jsx(Cw,{tableCellContext:m(pn.cell),value:pn.getValue(),type:Ye.value_type,...Ye}),header:Ye.label,enableSorting:!0,meta:Ye,size:typeof Ye.width=="number"?Ye.width:void 0,minSize:typeof Ye.width=="number"?Ye.width:void 0})})},[x,m]),[C,S]=f.useState([]),D=We.useReactTable({data:e,state:{sorting:C},onSortingChange:S,columns:v,getCoreRowModel:We.getCoreRowModel(),getSortedRowModel:We.getSortedRowModel()}),{rows:P}=D.getRowModel(),q=f.useRef(null),U=P.length,F=U>0,re=F?n-22:n,W=F?22:0;return V.useWhyDidYouUpdate("VizTableComponent",{queryData:e,width:t,height:n,conf:r,context:i,instance:o,finalColumns:x,getCellContext:m,tableColumns:v,table:D,rows:P,tableContainerRef:q}),s.jsxs("div",{ref:q,style:{height:n,width:t,padding:"0 5px"},"data-enable-scrollbar":!0,className:p(h.root,{"table-highlight-on-hover":r.highlightOnHover}),children:[U>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: ",U]})}),s.jsxs(a.Table,{sx:{...xw,maxHeight:re},...d,striped:r.striped,children:[s.jsx("thead",{className:h.thead,style:{top:W},children:D.getHeaderGroups().map(te=>s.jsx("tr",{children:te.headers.map(Ae=>s.jsx("th",{style:{width:Ae.getSize()},children:s.jsx(dw,{header:Ae,cx:p})},Ae.id))},te.id))}),s.jsx(_w,{tableContainerRef:q,rows:P})]})]})}function Ew({data:e,width:t,height:n,conf:r,context:i,instance:o}){const{id_field:l,use_raw_columns:c,columns:u}=r,d=f.useMemo(()=>{if(!l)return[];const h=A(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(Aw,{queryData:d,width:t,height:n,conf:r,context:i,instance:o})}function Pw({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(Ew,{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)"}}}})),Lw=[{from:0,to:0},{from:100,to:100}];class Bw{constructor(){L(this,"steps",new Map);L(this,"interpolation");L(this,"onChange");Y.makeAutoObservable(this,{steps:Y.observable},{deep:!1}),Y.reaction(()=>Y.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(Lw):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 Ow(e){const{onChange:t,color:n,index:r,value:i}=e,{classes:o}=Wo(),[l,c]=f.useState(i),[u,{setTrue:d,setFalse:h}]=V.useBoolean(!1),p=r%2===1,x=p&&i!=null,m=!p&&i!=null,v=`map ${i} to color ${r}`,C=()=>{c(i),h()},S=()=>{h(),t==null||t(l)},D=R(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:v,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":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: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:S,children:"OK"})]})]})})]}),s.jsx(a.Text,{title:v,style:{opacity:m?1:0},color:"dimmed",size:"sm",className:"palette-value--bottom palette-value",children:D})]})}const $w=_.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(Ow,{index:o,color:r,value:e.getStepFromValue(i),onChange:l=>e.changeStep(l,i)},r))})}),qw=_.observer(function(t){const n=V.useCreation(()=>new Bw,[]);return f.useEffect(()=>{n.fromProps(t)}),n.interpolation==null?null:s.jsx($w,{model:n})}),Vw=e=>{const{value:t,onChange:n,colorManager:r}=e,i=r.getColorInterpolations(),[o,l]=f.useState(t),c=r.decodeInterpolation(o.interpolation)||i[0],[u,{setTrue:d,setFalse:h}]=V.useBoolean(),p=i.map(S=>({label:S.displayName,value:r.encodeColor(S),group:S.category}));function x(S){S&&l(D=>({...D,interpolation:S}))}const m=()=>{h(),n==null||n(Y.toJS(o))};function v(S){l(D=>({...D,steps:S}))}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(qw,{steps:o.steps,interpolation:c,onChange:v}),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"})]})]})})]})},Nw=["static","interpolation","none"].map(e=>({label:y.capitalize(e),value:e})),Fw=[{from:0,to:0},{from:100,to:100}];function Ro(e){return e?y.isString(e)?e==="none"?"none":"static":"interpolation":"none"}function Gw(e,t){var n;return Ro(t)==="static"?t:(n=e.getStaticColors()[0])==null?void 0:n.value}function Ww(e,t){return y.isObject(t)?t:{steps:Fw,interpolation:e.encodeColor(e.getColorInterpolations()[0])}}const Rw=f.forwardRef((e,t)=>{const{colorManager:n}=f.useContext(tt),[r,i]=f.useState(Ro(e.value)),[o,l]=f.useState(Gw(n,e.value)),c=V.useLatest(o),[u,d]=f.useState(Ww(n,e.value)),h=V.useLatest(u),p=v=>{var C,S,D;i(v||"none"),v==="static"?(C=e.onChange)==null||C.call(e,c.current):v==="none"||!v?(S=e.onChange)==null||S.call(e,"none"):(D=e.onChange)==null||D.call(e,h.current)},x=v=>{var C;l(v),(C=e.onChange)==null||C.call(e,v)},m=v=>{var C;d(v),(C=e.onChange)==null||C.call(e,v)};return s.jsxs(a.Stack,{align:"stretch",children:[s.jsx(a.Select,{label:"Cell background",value:r||"none",onChange:p,data:Nw}),r==="static"&&s.jsx(_e,{value:o,onChange:x}),r==="interpolation"&&s.jsx(Vw,{colorManager:n,value:u,onChange:m})]})}),Qw={[Ke.eloc]:"ELOC"},Uw=Object.values(Ke).map(e=>({label:y.get(Qw,e,y.capitalize(e)),value:e})),Kw=f.forwardRef(({label:e,value:t,onChange:n,sx:r},i)=>s.jsx(a.Select,{ref:i,label:e,data:Uw,value:t,onChange:n,sx:r})),Yw=f.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:i,setFalse:o}]=V.useBoolean(),[l,c]=f.useState(e),u=()=>{o(),t(l)},d=()=>{o(),c(e)},h=()=>{c(qo)};return f.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(ge,{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(T.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"})]})]})]})})]})}),Xw=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],fr=()=>s.jsx(a.Text,{color:"dimmed",size:12,children:"px"}),Jw=({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(Kw,{label:"Value Type",sx:{flex:1},...l})}),o===Ke.custom&&s.jsx(b.Controller,{name:`columns.${t}.func_content`,control:e,render:({field:l})=>s.jsx(Yw,{value:l.value??qo,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:Xw,...l})})}),s.jsx(b.Controller,{name:`columns.${t}.cellBackgroundColor`,control:e,render:({field:l})=>s.jsx(Rw,{...l})}),s.jsx(a.Divider,{mb:4,mt:12,variant:"dashed"}),s.jsx(a.Button,{leftIcon:s.jsx(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(t),children:"Delete this column"})]})},Zw=({control:e,watch:t})=>{const{fields:n,append:r,remove:i,update:o}=b.useFieldArray({control:e,name:"columns"}),l=()=>{const u=ie.randomId();r({id:u,label:u,align:"center",value_field:"",value_type:Ke.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(T.Plus,{size:18,color:"#228be6"})})]}),n.map((u,d)=>s.jsx(a.Tabs.Panel,{value:d.toString(),children:s.jsx(Jw,{control:e,watch:t,index:d,column:u,remove:i})},u.id))]})})]})};function Hw({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 e0({columns:e,...t}){return{...t,columns:e.map(({id:n,...r})=>({id:n??ie.randomId(),...r}))}}function t0({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},t,Vo),[t]),i=f.useMemo(()=>e0(r),[r]);f.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});f.useEffect(()=>{d(i)},[i]);const h=u(),p=f.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(T.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(Zw,{control:o,watch:c})]}),s.jsx(a.Tabs.Panel,{value:"Style",children:s.jsx(Hw,{control:o,watch:c})})]})]})}function n0(e){const{columns:t,...n}=e;return{...e,columns:t.map(r=>({...r,align:r.align??"left"}))}}function s0(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 r0(e){const{columns:t,...n}=e;return{...n,columns:t.map(r=>({...r,align:r.align??"left",cellBackgroundColor:r.cellBackgroundColor??"",width:r.width??""}))}}class i0 extends oe{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??ie.randomId(),...l}))}}}),this.version(3,n=>({...n,version:3,config:n0(n.config)})),this.version(4,(n,r)=>({...n,version:4,config:s0(n.config,r)})),this.version(5,n=>({...n,version:5,config:r0(n.config)}))}}const gr={createConfig(){return{version:5,config:y.cloneDeep(Vo)}},displayName:"Table",displayGroup:"Others",migrator:new i0,name:"table",viewRender:Pw,configRender:t0,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"},a0=_.observer(({context:e})=>{const t=ue(),{value:n=mr}=$(e.instanceData,"config"),{variables:r}=e,i=e.data,{func_content:o,horizontal_align:l,font_size:c,font_weight:u}=n,d=f.useMemo(()=>r.reduce((p,x)=>{const m=it(x,i);return p[x.name]=Pe(x,m),p},{}),[r,i]),h=f.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})}),Yn=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function o0({label:e,value:t,onChange:n},r){var l;const[i,o]=f.useState(((l=Yn.find(c=>c.label===t))==null?void 0:l.value)??Yn[0].value);return f.useEffect(()=>{const c=Yn.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:Yn,value:i,onChange:o,step:25,placeholder:"Pick a font size",mx:"1em",ref:r})]})}const Uo=f.forwardRef(o0),l0=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return s.jsx(a.Box,{sx:{position:"relative"},children:s.jsx(ge,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},c0=f.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:i,setFalse:o}]=V.useBoolean(),[l,c]=f.useState(e),u=()=>{o(),t(l)},d=()=>{o(),c(e)},h=()=>{c(Qo)};return f.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(l0,{value:l,onChange:c}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:h,color:"red",leftIcon:s.jsx(T.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"})]})]})]})})]})}),u0=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}];function d0({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},t,mr),[t]),i=f.useMemo(()=>{const{func_content:x,horizontal_align:m,font_size:v,font_weight:C}=r;return{func_content:x,horizontal_align:m,font_size:v,font_weight:C}},[r]);f.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});f.useEffect(()=>{d(i)},[i]),c(["func_content","horizontal_align","font_size","font_weight"]);const h=u(),p=f.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(T.DeviceFloppy,{size:20})})]}),s.jsxs(a.Stack,{spacing:10,children:[s.jsx(b.Controller,{name:"func_content",control:o,render:({field:x})=>s.jsx(c0,{...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:u0,...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 p0 extends oe{constructor(){super(...arguments);L(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const h0={displayName:"Text",displayGroup:"Others",migrator:new p0,name:"text",viewRender:a0,configRender:d0,createConfig(){return{version:1,config:y.cloneDeep(mr)}}},x0=()=>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 f0(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 g0=({conf:e,panelData:t})=>async()=>{const{expertSystemURL:n,path:r,goal:i,question:o}=e;if(!r||!i||!o)return;const l=dd(t);if(!l)return;const c={dashboard:i,panel:o,data:l};try{const u=n.startsWith("http")?n:window.location.origin;return await f0(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"}})}),m0=({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(x0,{}),s.jsx(Yo,{message:r})]})})};function y0({context:e}){const{value:t}=$(e.instanceData,"config"),n=f.useMemo(()=>y.defaultsDeep({},t,yr),[t]),{width:r,height:i}=e.viewport,o=e.data,{data:l,error:c,loading:u}=V.useRequest(g0({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(m0,{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 b0({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},t,yr),[t]),{control:i,handleSubmit:o,watch:l,getValues:c,reset:u}=b.useForm({defaultValues:r});f.useEffect(()=>{u(r)},[r]),l(["expertSystemURL","goal","path","question"]);const d=c(),h=f.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(T.DeviceFloppy,{size:20}),disabled:!h,sx:{alignSelf:"flex-end"},children:"Submit Changes"})]})})}class v0 extends oe{constructor(){super(...arguments);L(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const j0={displayName:"Merico GQM",displayGroup:"Merico suite",migrator:new v0,name:"mericoGQM",viewRender:y0,configRender:b0,createConfig(){return{version:1,config:y.cloneDeep(yr)}}};function w0(e,t,n){if(!e)return n[0];try{return[t,z(t).add(1,"year").subtract(1,"day").valueOf()]}catch(r){return console.error(r),n[0]}}function C0(e,t,n){const r=w0(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 _0(e){return{heat_block:function(r){if(!e.heat_block.value_formatter)return r;try{return R(r,e.heat_block.value_formatter)}catch(i){return console.error(i),r}}}}function S0(e,t){return{show:!e,selectedMode:"single",top:5,right:5,data:t.map(n=>({name:n,icon:"circle"}))}}function k0(e,t,n,r){const{calendar:i,heat_block:o}=e,l=A(i.data_key),c=A(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 T0=e=>R(e,{output:"number",trimMantissa:!0,mantissa:2,absolute:!1});function D0({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=A(h.data_key);u.push({label:h.name,value:T0(y.get(d,p.columnKey,"")),style:{label:"",value:""}})}),u}function I0(e,t,n){const r=A(e.calendar.data_key),i=y.keyBy(t[r.queryID],r.columnKey);return ee.getTooltip({formatter:function(o){const c=D0({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>
|
|
@@ -330,13 +330,13 @@ Check the top-level render call using <`+E+">.")}return I}}function iu(w,I){{if(
|
|
|
330
330
|
</thead>
|
|
331
331
|
<tbody>${c.join("")}</tbody>
|
|
332
332
|
</table>
|
|
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`
|
|
333
|
+
`}})}function M0(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 z0={grid:{containLabel:!0}},A0=e=>z(e).get("year");function E0(e,t){const n=A(e.calendar.data_key),r=t[n.queryID],i=y.groupBy(r,d=>A0(d[n.columnKey])),o=Object.keys(i),l=r.map(d=>z(d[n.columnKey]).valueOf()),c=y.min(l),u=y.max(l);return{minDate:c??0,maxDate:u??0,dateSpan:z(u).diff(c,"day"),dataByYear:i,years:o}}function P0(e,t,n){const r=n.reduce((p,x)=>{const m=it(x,t);return p[x.name]=Pe(x,m),p},{}),i=_0(e),{dateSpan:o,minDate:l,dataByYear:c,years:u}=E0(e,t),d=o<=366,h={calendar:C0(d,l,u),series:k0(e,d,c,t),tooltip:I0(e,t,i),visualMap:M0(e,d,r),legend:S0(d,u)};return y.defaultsDeep({},h,z0)}function L0(e){return s.jsx(s.Fragment,{})}function B0(e){return s.jsx(a.Text,{children:"Click heat block"})}const Xo={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:B0,configRender:L0,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:ye},tooltip:{metrics:[]}};function O0({name:e},t){const n=t.getOption();n.calendar.forEach(r=>{r.range=e}),t.setOption(n)}function $0({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const l=jt(t,e.calendar.data_key),c=qe(i.triggerManager,Xo.id),u=f.useCallback(p=>{const[x,m]=p.value,v=y.get(l,x,{error:"rowData is not found"});c.forEach(C=>{i.runInteraction(C.id,{...p,rowData:v})})},[l,c,i]),d=f.useMemo(()=>({click:u,legendselectchanged:O0}),[u]),h=f.useMemo(()=>P0(e,t,o),[e,t]);return s.jsx(Ce,{echarts:ve,option:h,style:{width:n,height:r},onEvents:d,notMerge:!0,opts:{locale:e.calendar.locale},theme:"merico-light"})}function q0({context:e,instance:t}){const n=Ve({vizManager:e.vizManager,instance:t}),{value:r}=$(e.instanceData,"config"),{variables:i}=e,o=f.useMemo(()=>y.defaults({},r,vr),[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(Te,{width:c,height:u,children:s.jsx($0,{variables:i,width:Re(c),height:Qe(u),data:l,conf:o,interactionManager:n})})}function V0({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(qt,{label:"Min Value",...n})}),s.jsx(b.Controller,{name:"heat_block.max",control:e,render:({field:n})=>s.jsx(qt,{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(Ne,{...n})})]})}const N0=({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(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),F0=({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]=f.useState(()=>u??null);return f.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(T.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(T.Plus,{size:18,color:"#228be6"})})]}),l.map((p,x)=>s.jsx(a.Tabs.Panel,{value:p.id,children:s.jsx(N0,{control:e,index:x,remove:i},p.id)},p.id))]})]})};function G0({control:e,watch:t}){return s.jsx(F0,{control:e,watch:t})}const W0=[{label:"Chinese",value:"ZH"},{label:"English",value:"EN"}];function R0({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:W0,sx:{flex:1},...n})})]})}function Q0({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},t,vr),[t]),i=f.useMemo(()=>y.cloneDeep(r),[r]);f.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});f.useEffect(()=>{d(i)},[i]);const h=u(),p=f.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(T.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(R0,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Heat Block",children:s.jsx(V0,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(G0,{control:o,watch:c})})]})]})})}function U0(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 K0(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 Y0 extends oe{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:U0(n.config,r)})),this.version(3,n=>({...n,version:3,config:K0(n.config)}))}}const X0={displayName:"Heatmap(Calendar)",displayGroup:"ECharts-based charts",migrator:new Y0,name:"calendarHeatmap",viewRender:q0,configRender:Q0,createConfig:()=>({version:3,config:vr}),triggers:[Xo]},jr={x_axes:[{id:"initial-x",min:"",max:"",name:"X Axis",data_key:"",position:"bottom",label_formatter:ye,show:!0}],y_axis:{name:"Y Axis",data_key:"",axisLabel:{formatter:{...Be},overflow:De()},nameAlignment:"center"},series:[],tooltip:{metrics:[]},reference_lines:[]};function J0(){const e=new Date().getTime().toString();return{id:e,min:"",max:"",name:e,data_key:"",position:"bottom",label_formatter:ye,show:!0}}function Z0(){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 H0(){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 eC(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 tC(e){switch(e){case"bar":return"roundRect";case"scatter":return"circle"}}function nC(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:tC(r)})),t}function sC(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?vn(i.template,t,r):""},position:c}}}})}function Xn(e,t,n){const r=Ze(e,t),i=Ze(e,n);return y.zip(i,r)}function rC(e,t,n,r){const i=Xn(t,n,r);return y.unionBy(i,e,0)}function iC({dataTemplate:e,data:t,name_data_key:n,value_data_key:r,valueTypedXAxis:i}){return i?rC(e,t,n,r):Xn(t,n,r)}function aC({dataTemplate:e,data:t,aggregation_on_value:n,name_data_key:r,value_data_key:i,valueTypedXAxis:o}){if(!n||n.type==="none")return iC({dataTemplate:e,data:t,name_data_key:r,value_data_key:i,valueTypedXAxis:o});const l=Xn(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 oC({group_by_key:e,data:t,value_data_key:n,name_data_key:r}){const{queryID:i,columnKey:o}=A(e),l=y.groupBy(t[i],o);return Object.entries(l).forEach(([c,u])=>{l[c]=Xn({[i]:u},r,n)}),l}function lC({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,v,C,S,D){const P={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 P.data=aC({dataTemplate:m,data:C,aggregation_on_value:l,name_data_key:e.data_key,value_data_key:t,valueTypedXAxis:v}),P;const q=oC({group_by_key:o,data:C,name_data_key:e.data_key,value_data_key:t});return Object.entries(q).map(([U,F])=>{const re=y.cloneDeep(P);return re.name=U,re.color=void 0,re.data=F,re})}function cC(e,t,n,r,i,o,l){const c=t.map(d=>[d,0]);return e.series.map(d=>lC(e,d,c,n,r,l,i)).flat().concat(sC(e.reference_lines,o,l,r))}function uC(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:Lt(t.y_axis.axisLabel.formatter)(o,l)}function dC(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
|
-
`}),c=
|
|
339
|
+
`}),c=Oe(e.y_axis.axisLabel.overflow.in_tooltip),u=uC(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
341
|
<div style="${c}">${u}</div>
|
|
342
342
|
</div>
|
|
@@ -345,7 +345,7 @@ Check the top-level render call using <`+E+">.")}return I}}function iu(w,I){{if(
|
|
|
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 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})=>`
|
|
348
|
+
`}})}function pC(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 R(c,r)}catch(u){return console.error(u),c}},n),{default:({value:n})=>n})}function hC(e,t){const n={};return t.map(r=>{const i=it(r,e);n[r.name]=Pe(r,i)}),n}function xC(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 fC(e,t){const n=t.every(l=>!Number.isNaN(Number(l))),{overflow:r,...i}=e.y_axis.axisLabel,o=$e(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:Lt(i.formatter)},z:5})]}function gC(e,t,n){if(!e.y_axis.data_key)return{};const r=hC(t,n),i=pC(e),o=A(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=cC(e,l,c,t,i,n,r);return{xAxis:xC(e,i),yAxis:fC(e,l),series:u,tooltip:dC(e,u,i),grid:eC(e),legend:nC(u)}}function mC({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const l=jt(t,e.y_axis.data_key),c=qe(i.triggerManager,Os.id),u=f.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=f.useMemo(()=>({click:u}),[u]),h=f.useMemo(()=>gC(e,t,o),[e,t]);return s.jsx(Ce,{echarts:ve,option:h,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function yC({context:e,instance:t}){const n=Ve({vizManager:e.vizManager,instance:t}),{value:r}=$(e.instanceData,"config"),{variables:i}=e,o=f.useMemo(()=>y.defaults({},r,jr),[r]),l=e.data,{width:c,height:u}=e.viewport;return!c||!u?null:s.jsx(Te,{width:c,height:u,children:s.jsx(mC,{variables:i,width:Re(c),height:Qe(u),data:l,conf:o,interactionManager:n})})}const bC=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],vC=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function jC({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:vC,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:bC,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(_e,{...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(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]})}function wC({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,v)=>({...m,...l[v]})),u=()=>{const m=H0();i(m)},d=f.useMemo(()=>n.map(m=>({label:m.name,value:m.name})),[n]),h=t("x_axes"),p=f.useMemo(()=>h.map(({name:m},v)=>({label:m,value:v.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,v)=>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(T.Plus,{size:18,color:"#228be6"})})]}),c.map((m,v)=>s.jsx(a.Tabs.Panel,{value:m.id,children:s.jsx(jC,{control:e,index:v,remove:o,watch:t,variableOptions:d,xAxisOptions:p})},m.id))]})}function CC(e){const[t,n]=f.useState(e);return f.useEffect(()=>{n(e)},[e]),{tab:t,setTab:n}}const _C=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function SC({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:_C,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 kC=[{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 TC({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(sr,{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(SC,{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:kC,...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(_e,{...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(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Series"})]})}function DC({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,v)=>({...m,...o[v]})),c=()=>{const m=Z0();r(m)},u=t("x_axes"),d=f.useMemo(()=>u.map(({name:m},v)=>({label:m,value:v.toString()})),[u]),{tab:h,setTab:p}=CC((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(T.Plus,{size:18,color:"#228be6"})})]}),l.map((m,v)=>s.jsx(a.Tabs.Panel,{value:m.id,children:s.jsx(TC,{control:e,index:v,remove:i,seriesItem:m,xAxisOptions:d},m.id)},m.id))]})}const IC=[{label:"Top",value:"top"},{label:"Bottom",value:"bottom"}];function MC({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:IC,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(Ne,{...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(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this X Axis"})]})}function zC({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=J0();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(T.Plus,{size:18,color:"#228be6"})})]}),l.map((d,h)=>s.jsx(a.Tabs.Panel,{value:d.id,children:s.jsx(MC,{control:e,index:h,remove:i})},d.id))]})}function AC({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(Ue,{...n})})]})}function EC({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),{variables:r}=e,i=f.useMemo(()=>y.defaultsDeep({},t,jr),[t]),{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=b.useForm({defaultValues:i});f.useEffect(()=>{d(i)},[i]),c([]);const h=u(),p=f.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(T.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(zC,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Y Axis",children:s.jsx(AC,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Series",children:s.jsx(DC,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Reference Lines",children:s.jsx(wC,{variables:r,control:o,watch:c})})]})]})})}function PC(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 LC extends oe{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:PC(i,r)}})}}const BC={displayName:"Horizontal Bar Chart",displayGroup:"ECharts-based charts",migrator:new LC,name:"horizontalBarChart",viewRender:yC,configRender:EC,createConfig:()=>({version:2,config:jr})},wr={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...Qn}}},deviation:{name:"",data_keys:{estimated_value:"",actual_value:""}},metrics:[]};function OC(){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 R(e[2],{output:"percent",mantissa:0,absolute:!1})}catch(t){return console.error(t),e}};function $C(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">
|
|
@@ -367,7 +367,7 @@ Check the top-level render call using <`+E+">.")}return I}}function iu(w,I){{if(
|
|
|
367
367
|
</tr>
|
|
368
368
|
</tbody>
|
|
369
369
|
</table>
|
|
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
|
|
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 qC([e,t]){const n={x:e,v:`${t}`};try{n.v=R(t,{output:"number",mantissa:2,trimMantissa:!0,absolute:!1})}catch{}return n}function VC(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=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 c(h[1])}catch{return"#FFF"}}},label:{position:"outside",show:!0,formatter:({value:h})=>{try{return R(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}=qC(p);return`
|
|
371
371
|
<table style="width: auto">
|
|
372
372
|
<thead>
|
|
373
373
|
<tr colspan="2">
|
|
@@ -389,7 +389,7 @@ Check the top-level render call using <`+E+">.")}return I}}function iu(w,I){{if(
|
|
|
389
389
|
</tr>
|
|
390
390
|
</tbody>
|
|
391
391
|
</table>
|
|
392
|
-
`}},show_in_legend:!1}}function
|
|
392
|
+
`}},show_in_legend:!1}}function NC([e,t,n,r]){const i={x:e,percentage:`${t}`,count:n,sum:r};try{i.percentage=R(t,{output:"percent",mantissa:2,trimMantissa:!0,absolute:!1})}catch{}return i}function FC(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,v])=>{i[m]||(i[m]=[]);const C=v/x;i[m].push([h,C,v,x])})});const o=Object.entries(i).map(([h])=>Number(h)).sort((h,p)=>h-p),l=Math.max(...o),c=Math.min(...o),u=bt.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:v,count:C,sum:S}=NC(x);return`
|
|
393
393
|
<table style="width: auto">
|
|
394
394
|
<thead>
|
|
395
395
|
<tr colspan="2">
|
|
@@ -412,7 +412,7 @@ Check the top-level render call using <`+E+">.")}return I}}function iu(w,I){{if(
|
|
|
412
412
|
</tr>
|
|
413
413
|
<tr>
|
|
414
414
|
<th style="text-align: right;">占比</th>
|
|
415
|
-
<td style="text-align: left; padding: 0 1em;">${
|
|
415
|
+
<td style="text-align: left; padding: 0 1em;">${v}</td>
|
|
416
416
|
</tr>
|
|
417
417
|
<tr>
|
|
418
418
|
<th style="text-align: right;">数量</th>
|
|
@@ -420,18 +420,18 @@ Check the top-level render call using <`+E+">.")}return I}}function iu(w,I){{if(
|
|
|
420
420
|
</tr>
|
|
421
421
|
<tr>
|
|
422
422
|
<th style="text-align: right;">总数</th>
|
|
423
|
-
<td style="text-align: left; padding: 0 1em;">${
|
|
423
|
+
<td style="text-align: left; padding: 0 1em;">${S}</td>
|
|
424
424
|
</tr>
|
|
425
425
|
</tbody>
|
|
426
426
|
</table>
|
|
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=
|
|
427
|
+
`}},show_in_legend:!0}))}function GC(e,t,n,r){const i=A(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 WC(e,t,n,r){const l={barMinWidth:5,barMaxWidth:20};return[$C(e,n,r),VC(e,n,r,l),...FC(e,n,r,l),GC(e,t,n,r)]}function RC(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 QC(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 UC=Array.from(new Array(20),(e,t)=>Cr(t+1));function Ho(e){return e<=1?e:UC.findIndex(t=>e<=t)-1}function KC(e,t){const{x_axis:n,deviation:r}=e,i=A(n.data_key),o=A(r.data_keys.estimated_value),l=A(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 YC(e){return e==="rgba(255, 255, 255, 1)"?{borderColor:"rgba(0,0,0,.1)",borderWidth:1}:{}}function XC(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:YC(n.color)})),tooltip:{show:!0,formatter:"档位偏差:{a}"}}}const JC={tooltip:{trigger:"axis"}};function ZC(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 HC(e,t,n){const r=KC(e,n),i=A(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=ZC(e,t),u=WC(e,c,o,l),d={xAxis:RC(e,o),yAxis:QC(c),series:u,grid:OC(),visualMap:[{min:0,max:1,calculable:!0,show:!1,seriesIndex:0,color:["#F0F0F0","#418AAF"]}],legend:XC(u)};return y.defaultsDeep({},d,JC)}const e_={input:{border:"none !important",paddingLeft:0,lineHeight:"1.55 !important"}},t_=({conf:e,metricKey:t,setMetricKey:n})=>{const{deviation:r,metrics:i}=e,o=f.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:e_})]})},n_={"tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function s_(){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(k.IconInfoCircle,{size:14}),children:"指标说明"})}),s.jsx(a.HoverCard.Dropdown,{children:s.jsx(a.Table,{fontSize:14,sx:n_,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 r_(e){return s.jsxs(a.Group,{position:"apart",children:[s.jsx(s_,{}),s.jsx(t_,{...e})]})}function i_({conf:e,data:t,width:n,height:r,metricKey:i}){const o=f.useMemo(()=>HC(e,i,t),[e,t,i]);return s.jsx(Ce,{echarts:ve,option:o,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})}function a_({context:e}){const{value:t}=$(e.instanceData,"config"),n=f.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]=f.useState(d);if(f.useEffect(()=>{p(v=>v||d)},[d]),!l.data_key||!u||!d||!i||!o)return null;const x=Math.max(Re(i),300),m=Math.max(Qe(o),370);return s.jsxs(a.Box,{pt:ke.top,pr:ke.right,pb:ke.bottom,pl:ke.left,sx:{overflow:"hidden",height:o,width:i},children:[s.jsx(r_,{conf:n,metricKey:h,setMetricKey:p}),s.jsx(i_,{width:x,height:m-30,data:r,conf:n,metricKey:h})]})}function o_({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 l_=({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(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),c_=({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]=f.useState(()=>u??null);return f.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(T.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(T.Plus,{size:18,color:"#228be6"})})]}),l.map((p,x)=>s.jsx(a.Tabs.Panel,{value:p.id,children:s.jsx(l_,{control:e,index:x,remove:i},p.id)},p.id))]})]})};function u_({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(zo,{...n})})]})]})}function d_({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},t,wr),[t]),{control:i,handleSubmit:o,watch:l,getValues:c,reset:u}=b.useForm({defaultValues:r});f.useEffect(()=>{u(r)},[r]),l([]);const d=c(),h=f.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(T.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(u_,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Deviation",children:s.jsx(o_,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Additional Metrics",children:s.jsx(c_,{control:i,watch:l})})]})]})})}function p_(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 h_ extends oe{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:p_(i,r)}})}}const x_={displayName:"Merico Estimation Chart",displayGroup:"Merico suite",migrator:new h_,name:"mericoEstimationChart",viewRender:a_,configRender:d_,createConfig:()=>({version:2,config:wr})},_r={styles:{justify:"space-around",align:"start"},metrics:[]};function f_(){return{id:new Date().getTime().toString(),names:{value:"Value",basis:"Basis"},data_keys:{value:"",basis:""},formatter:ye,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,g_=_.observer(({metric:e,variableValueMap:t})=>{const{names:n,data_keys:r,formatter:i,postfix:o}=e,l=ue(),c=f.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:R(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:R(t[r.basis],i)}),s.jsx(el,{postfix:c})]})]})]})}),m_=_.observer(({context:e,instance:t})=>{const{value:n}=$(e.instanceData,"config"),{variables:r}=e,i=f.useMemo(()=>y.defaults({},n,_r),[n]),o=e.data,l=f.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(g_,{metric:d,variableValueMap:l},d.id))})}),y_=[{label:"Text",value:"text"},{label:"Filter Option Label",value:"filter-option-label"}],b_=_.observer(f.forwardRef(({value:e,onChange:t},n)=>{const i=Q().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:y_,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 v_({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(Ne,{...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(b_,{...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(T.Trash,{size:16})})]})}const j_=({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((v,C)=>({...v,...l[C]})),u=()=>{i(f_())},d=f.useMemo(()=>n.map(v=>({label:v.name,value:v.name})),[n]),h=y.get(c,"0.id",null),[p,x]=f.useState(h);f.useEffect(()=>{x(v=>v||h)},[h]);const m=v=>{o(v);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((v,C)=>s.jsx(a.Tabs.Tab,{value:v.id,children:v.names.value?v.names.value:C+1},v.id)),s.jsx(a.Tabs.Tab,{onClick:u,value:"add",children:s.jsx(k.IconPlus,{size:18,color:"#228be6"})})]}),c.map((v,C)=>s.jsx(a.Tabs.Panel,{value:v.id,children:s.jsx(v_,{control:e,index:C,remove:m,variableOptions:d,watch:t})},v.id))]})]})},w_=[{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"}],C_=[{label:"Start",value:"start"},{label:"Center",value:"center"},{label:"End",value:"end"},{label:"Stretch",value:"stretch"}];function __({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:w_,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:C_,sx:{flex:1},...n})})]})]})}function S_({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),{variables:r}=e,i=f.useMemo(()=>y.defaultsDeep({},t,_r),[t]),{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=b.useForm({defaultValues:i});f.useEffect(()=>{d(i)},[i]);const h=u(),p=f.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(T.DeviceFloppy,{size:20})})]}),s.jsx(__,{control:o,watch:c}),s.jsx(j_,{control:o,watch:c,variables:r})]})})}function k_(e){const{metrics:t,...n}=e;return{...n,metrics:t.map(r=>({...r,postfix:r.postfix??{type:"text",value:""}}))}}class T_ extends oe{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:k_(n.config)}))}}const D_={displayName:"Merico Stats",displayGroup:"Merico suite",migrator:new T_,name:"merico-stats",viewRender:m_,configRender:S_,createConfig:()=>({version:2,config:_r})};function I_({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(qt,{label:"Min Value",...r})}),s.jsx(b.Controller,{name:"heat_block.max",control:e,render:({field:r})=>s.jsx(qt,{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(Ne,{...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(k.IconTextSize,{size:16}),disabled:!n,...r})})]})]})}const M_=({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(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),z_=({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]=f.useState(()=>u??null);return f.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(T.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(T.Plus,{size:18,color:"#228be6"})})]}),l.map((p,x)=>s.jsx(a.Tabs.Panel,{value:p.id,children:s.jsx(M_,{control:e,index:x,remove:i},p.id)},p.id))]})]})};function A_({control:e,watch:t}){return s.jsx(z_,{control:e,watch:t})}const E_=({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(ge,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},P_={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
428
|
+
`)},tl=f.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:i,setFalse:o}]=V.useBoolean(),[l,c]=f.useState(e);f.useEffect(()=>{c(e)},[e]);const u=m=>{c({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:v}=l,C={enabled:m,func_content:v};c(C),t(C)},h=()=>{o(),c(e)},p=m=>{c(v=>({...v,func_content:m}))},x=()=>{p(P_.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(E_,{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(T.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 L_({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(Ue,{...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 B_=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function O_({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:B_,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(Ue,{...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 Sr={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,overflow:De(),formatter:{...Be}}},y_axis:{name:"Y Axis",data_key:"",nameAlignment:"center",axisLabel:{rotate:0,overflow:De(),formatter:{...Be}}},heat_block:{min:{type:"static",value:0},max:{type:"static",value:100},name:"Value",data_key:"",value_formatter:ye,label:{show:!1,fontSize:10}},tooltip:{metrics:[]}};function $_({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},t,Sr),[t]),i=f.useMemo(()=>y.cloneDeep(r),[r]);f.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});f.useEffect(()=>{d(i)},[i]);const h=u(),p=f.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(T.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(L_,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Y Axis",children:s.jsx(O_,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Heat Block",children:s.jsx(I_,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(A_,{control:o,watch:c})})]})]})})}function q_(e){return s.jsx(s.Fragment,{})}function V_(e){return s.jsx(a.Text,{children:"Click heat block"})}const nl={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:V_,configRender:q_,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 N_(e){const t=sl(e.x_axis.axisLabel.formatter),n=sl(e.y_axis.axisLabel.formatter);return{x_axis:t,y_axis:n}}function F_(e){return{heat_block:function(r){if(!e.heat_block.value_formatter)return r;try{return R(r,e.heat_block.value_formatter)}catch(i){return console.error(i),r}}}}function G_(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 W_(e,t){const{x_axis:n,y_axis:r,heat_block:i}=e,o=A(n.data_key),l=A(r.data_key),c=A(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 R_=e=>R(e,{output:"number",trimMantissa:!0,mantissa:2,absolute:!1});function Q_({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:Oe(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:Oe(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],v=r[`${c}---${u}`];return v&&e.tooltip.metrics.forEach(C=>{const S=A(C.data_key);m.push({label:C.name,value:R_(y.get(v,S.columnKey,"")),style:{label:"",value:""}})}),m}function U_(e,t,n,r){const{x_axis:i,y_axis:o,heat_block:l}=e,c=A(i.data_key),u=A(o.data_key);A(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=Q_({conf:e,labelFormatters:n,valueFormatters:r,dataDict:d,params:h}).map(v=>`
|
|
429
429
|
<tr>
|
|
430
430
|
<th style="text-align: right;">
|
|
431
|
-
<div style="${
|
|
431
|
+
<div style="${v.style.label}">${v.label}</div>
|
|
432
432
|
</th>
|
|
433
433
|
<td style="text-align: right; padding: 0 1em;">
|
|
434
|
-
<div style="${
|
|
434
|
+
<div style="${v.style.value}">${v.value}
|
|
435
435
|
</td>
|
|
436
436
|
</tr>
|
|
437
437
|
`);return`
|
|
@@ -446,19 +446,19 @@ Check the top-level render call using <`+E+">.")}return I}}function iu(w,I){{if(
|
|
|
446
446
|
</thead>
|
|
447
447
|
<tbody>${x.join("")}</tbody>
|
|
448
448
|
</table>
|
|
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}=e.contentModel.getDataStuffByID(e.options_query_id);return n==="error"?[]: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,r=new Set(e.options.map(o=>o.value)),i=(t.values[n]??[]).filter(o=>r.has(o));i.length>0?t.setValueByKey(n,i):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(){var o;const t=f.getRoot(e).content.filters,n=f.getParent(e).key,r=t.values[n],i=(o=e.options.find(l=>l.value===r))==null?void 0:o.value;i?t.setValueByKey(n,i):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,n=e.contentModel.filters,r=n.values[t],i=new Set(e.plainData.map(l=>l.value)),o=(r??[]).filter(l=>i.has(l));o.length>0?n.setValueByKey(t,o):n.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:y.cloneDeep(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`
|
|
449
|
+
`}})}function K_(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 Y_(e,t,n){const r=A(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=$e(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 X_(e,t,n){const r=A(e.x_axis.data_key),i=A(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=$e(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 J_(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=it(u,t);return c[u.name]=Pe(u,d),c},{}),i=N_(e),o=F_(e);return{xAxis:Y_(e,t,i.x_axis),yAxis:X_(e,t,i.y_axis),series:W_(e,t),tooltip:U_(e,t,i,o),grid:G_(e),visualMap:K_(e,r)}}function Z_({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const l=f.useMemo(()=>{const p=A(e.x_axis.data_key),x=A(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=qe(i.triggerManager,nl.id),u=f.useCallback(p=>{const[x,m]=p.value,v=y.get(l,`${x}---${m}`,{error:"rowData is not found"});c.forEach(C=>{i.runInteraction(C.id,{...p,rowData:v})})},[l,c,i]),d=f.useMemo(()=>({click:u}),[u]),h=f.useMemo(()=>J_(e,t,o),[e,t]);return s.jsx(Ce,{echarts:ve,option:h,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function H_({context:e,instance:t}){const n=Ve({vizManager:e.vizManager,instance:t}),{value:r}=$(e.instanceData,"config"),{variables:i}=e,o=f.useMemo(()=>y.defaults({},r,Sr),[r]),l=e.data,{width:c,height:u}=e.viewport;return!c||!u?null:s.jsx(Te,{width:c,height:u,children:s.jsx(Z_,{variables:i,width:Re(c),height:Qe(u),data:l,conf:o,interactionManager:n})})}class eS extends oe{constructor(){super(...arguments);L(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const tS={displayName:"Merico Heatmap",displayGroup:"Merico suite",migrator:new eS,name:"merico-heatmap",viewRender:H_,configRender:$_,createConfig:()=>({version:1,config:Sr}),triggers:[nl]},nS=[{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"})),sS=[$d,qd,Fd,Nd,Vd,Gd],rl=()=>({id:"dashboard",version:ua,manifest:{viz:[gr,Fj,h0,yv,uw,cb,BC,tp,Gh,Om,by,X0,Zy,xm,Mj,Pb,cv,j0,x_,tS,D_,sx],color:[...nS,...sS]}}),ln=new Ud,de={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")}},kr=()=>{try{ln.install(rl())}catch{}const e=new Ld(ln),t=new Qd(ln);return{pluginManager:ln,vizManager:e,colorManager:t}},tt=f.createContext(kr());try{ln.install(rl())}catch{}const Tr=f.createContext(null);function Jn(e){const t=f.useContext(Tr),n=V.useCreation(()=>e.configure(t||new js),[e.configure]),r=V.usePrevious(n);return r&&r!==n&&r.dispose(),s.jsx(Tr.Provider,{value:n,children:e.children})}function il(){return f.useContext(Tr)}const rS=({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(k.IconInfoCircle,{size:16,color:"gray"})})}),iS=_.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(rS,{description:n,isDescriptionEmpty:r})]}),checked:o||!1,onChange:c=>l(c.currentTarget.checked),...i,pt:".4em",styles:{input:{borderColor:"#e9ecef"}}})]})),aS=({value:e,onChange:t,close:n,max_days:r,allowSingleDateInRange:i})=>{const[o,l]=e,c=f.useMemo(()=>o||new Date,[o]),u=f.useMemo(()=>{if(o&&!l)return o},[o,l]),d=f.useMemo(()=>{if(o&&!l&&r>0)return z(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})},oS=({begin:e,end:t})=>{const n=f.useMemo(()=>z(t).diff(z(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})})},lS=({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[z(e).subtract(1,"day").startOf("day").toDate(),z(e).subtract(1,"day").endOf("day").toDate()]}},{label:"week",value:"last week",group:"last",getRange:()=>{const e=Date.now();return[z(e).subtract(1,"week").startOf("week").toDate(),z(e).subtract(1,"week").endOf("week").toDate()]}},{label:"month",value:"last month",group:"last",getRange:()=>{const e=Date.now();return[z(e).subtract(1,"month").startOf("month").toDate(),z(e).subtract(1,"month").endOf("month").toDate()]}},{label:"2 months",value:"last 2 months",group:"last",getRange:()=>{const e=Date.now();return[z(e).subtract(2,"month").startOf("month").toDate(),z(e).subtract(1,"month").endOf("month").toDate()]}},{label:"3 months",value:"last 3 months",group:"last",getRange:()=>{const e=Date.now();return[z(e).subtract(3,"month").startOf("month").toDate(),z(e).subtract(1,"month").endOf("month").toDate()]}},{label:"year",value:"last year",group:"last",getRange:()=>{const e=Date.now();return[z(e).subtract(1,"year").startOf("year").toDate(),z(e).subtract(1,"year").endOf("year").toDate()]}},{label:"7 days",value:"recent 7 days",group:"recent",getRange:()=>{const e=Date.now();return[z(e).subtract(7,"day").startOf("day").toDate(),z(e).subtract(1,"day").endOf("day").toDate()]}},{label:"30 days",value:"recent 30 days",group:"recent",getRange:()=>{const e=Date.now();return[z(e).subtract(30,"day").startOf("day").toDate(),z(e).subtract(1,"day").endOf("day").toDate()]}},{label:"60 days",value:"recent 60 days",group:"recent",getRange:()=>{const e=Date.now();return[z(e).subtract(60,"day").startOf("day").toDate(),z(e).subtract(1,"day").endOf("day").toDate()]}},{label:"90 days",value:"recent 90 days",group:"recent",getRange:()=>{const e=Date.now();return[z(e).subtract(90,"day").startOf("day").toDate(),z(e).subtract(1,"day").endOf("day").toDate()]}},{label:"180 days",value:"recent 180 days",group:"recent",getRange:()=>{const e=Date.now();return[z(e).subtract(180,"day").startOf("day").toDate(),z(e).subtract(1,"day").endOf("day").toDate()]}},{label:"365 days",value:"recent 365 days",group:"recent",getRange:()=>{const e=Date.now();return[z(e).subtract(365,"day").startOf("day").toDate(),z(e).subtract(1,"day").endOf("day").toDate()]}},{label:"today",value:"today",group:"this",getRange:()=>{const e=Date.now();return[z(e).startOf("day").toDate(),z(e).endOf("day").toDate()]}},{label:"week",value:"this week",group:"this",getRange:()=>{const e=Date.now();return[z(e).startOf("week").toDate(),z(e).endOf("week").toDate()]}},{label:"month",value:"this month",group:"this",getRange:()=>{const e=Date.now();return[z(e).startOf("month").toDate(),z(e).endOf("month").toDate()]}},{label:"2 months",value:"this 2 months",group:"this",getRange:()=>{const e=Date.now();return[z(e).startOf("month").toDate(),z(e).add(1,"month").endOf("week").toDate()]}},{label:"3 months",value:"this 3 months",group:"this",getRange:()=>{const e=Date.now();return[z(e).startOf("month").toDate(),z(e).add(2,"month").endOf("week").toDate()]}},{label:"year",value:"this year",group:"this",getRange:()=>{const e=Date.now();return[z(e).startOf("year").toDate(),z(e).endOf("year").toDate()]}}];function al(e){const n=Dr().find(r=>r.value===e);return n?n.getRange():null}const cS=({onChange:e})=>{const t=r=>()=>{const i=r();e(i)},n=f.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"}}),uS=({label:e,required:t,value:n,onChange:r,max_days:i,allowSingleDateInRange:o,inputFormat:l})=>{const[c,{open:u,close:d}]=ie.useDisclosure(!1),[h,p]=n,x=h?z(h).format(l):"",m=p?z(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(k.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(oS,{begin:h,end:p})}),icon:s.jsx(k.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(lS,{max_days:i}),s.jsx(aS,{value:n,onChange:r,close:d,allowSingleDateInRange:o,max_days:i}),s.jsx(cS,{onChange:r})]})]})},ll=_.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?z(h).toDate():null):[null,null],d=h=>{r(h.map(p=>p&&z(p).format(i)))};return s.jsx(uS,{label:e,value:u,onChange:d,inputFormat:i,allowSingleDateInRange:c,max_days:l,required:o})}),dS=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"}),pS=({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}=dS({radius:i},{name:"MultiSelectWidget",classNames:t,styles:n,unstyled:r}),[v,C]=f.useState(!1),S=F=>{C(F)},D=v&&(c==null?void 0:c.length)>0,[P,q]=f.useState(""),U=f.useMemo(()=>{if(!P)return d;const F=P.toLowerCase(),re=W=>{var te;return((te=W.description)==null?void 0:te.toLowerCase().includes(F))||W.label.toLowerCase().includes(F)};return d.filter(re)},[P,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:S,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:F=>`${F.length} selected`,searchValue:P,onSearch:q,filterOption:!1,children:U.map(F=>s.jsxs(Ri.Option,{title:F.label,children:[s.jsx(a.Text,{size:"sm","data-role":"label",children:F.label}),F.description&&s.jsx(a.Text,{size:"xs",color:"dimmed","data-role":"description",children:F.description})]},F.value))})]})},hS=_.observer(({label:e,config:t,value:n,onChange:r})=>{const i=ue(),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(pS,{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})}),xS=f.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})]})})})),fS=_.observer(({label:e,config:t,value:n,onChange:r})=>{const i=ue(),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:xS})});function gS({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 mS=({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"})}),yS=({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(mS,{rotate:e?"0":"-90",onClick:r,...i})),bS=({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"})]}),vS=({onClick:e,...t})=>s.jsx(bS,{onClick:e,...t}),jS=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"}}}})),wS=({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:v}=jS({radius:i},{name:"FilterTreeSelectWidget",classNames:t,styles:n,unstyled:r}),[C,S]=f.useState(!1),D=q=>{S(q)},P=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:"*"})]}),P&&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:v(m.root,"check-select"),dropdownClassName:v(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:yS,treeIcon:vS,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`})]})},CS=_.observer(({label:e,config:t,value:n,onChange:r})=>{const{treeData:i,treeDataLoading:o,errorMessage:l}=t,c=x=>{const m=x.map(v=>v.value);r(m,!1)},u=f.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(wS,{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})}),_S=_.observer(({filter:{type:e,config:t,key:n,...r},formFieldProps:i})=>{switch(e){case"select":return s.jsx(fS,{...r,...i,config:t});case"multi-select":return s.jsx(hS,{...r,...i,config:t});case"tree-select":return s.jsx(CS,{...r,...i,config:t});case"text-input":return s.jsx(gS,{...r,...i,config:t});case"date-range":return s.jsx(ll,{...r,...i,config:t});case"checkbox":return s.jsx(iS,{...r,...i,config:t});default:return null}}),SS=_.observer(f.forwardRef(({filter:e,...t},n)=>s.jsx("div",{className:"filter-root",ref:n,children:s.jsx(je,{children:s.jsx(_S,{filter:e,formFieldProps:t})})}))),kS=({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 TS(e){const t=Q();f.useEffect(()=>{var n,r;(r=(n=t.filters).updatePreviewValues)==null||r.call(n,e)},[e])}const DS=({opened:e,toggle:t})=>{const{t:n}=M.useTranslation();return 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(k.IconChevronsUp,{size:14}):s.jsx(k.IconChevronsDown,{size:14}),onClick:t,children:n(e?"filter.hide_filters":"filter.show_filters")})})},ul=_.observer(function({view:t}){const[n,{toggle:r}]=ie.useDisclosure(!0),i=ue(),{control:o,handleSubmit:l,reset:c}=b.useForm({defaultValues:i.filters.values,reValidateMode:"onBlur"}),u=b.useWatch({control:o});f.useEffect(()=>{c(i.filters.values)},[i.filters.values,c]),TS(u);const d=i.filters.visibleInView(t.id),h=f.useMemo(()=>d.every(v=>v.should_auto_submit),[d]),p=f.useMemo(()=>d.filter(v=>y.get(v,"config.required",!1)),[d]),x=f.useMemo(()=>p.length===0?!1:p.some(v=>!v.requiredAndPass(u[v.key])),[u,p]);if(d.length===0)return null;const m=(v,C)=>(S,D)=>{C(S),(v.should_auto_submit||D)&&i.filters.setValueByKey(v.key,S)};return s.jsxs("form",{onSubmit:l(i.filters.setValues),children:[s.jsx(DS,{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(v=>s.jsx(b.Controller,{name:v.key,control:o,render:({field:C})=>s.jsx(SS,{filter:v,value:C.value,onChange:m(v,C.onChange)})},v.id))}),!h&&s.jsx(a.Group,{sx:{alignSelf:"flex-end"},children:s.jsx(kS,{disabled:x})})]})})]})}),IS={viewPanelInFullScreen:y.noop,inFullScreen:!1},Zn=f.createContext(IS),Ir=g.types.model("MockContextMeta",{current:g.types.optional(g.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 MS=g.types.model("PanelStyleBorderMeta",{enabled:g.types.boolean}).views(e=>({get json(){const{enabled:t}=e;return{enabled:t}}})).actions(e=>({setEnabled(t){e.enabled=t}})),dl=g.types.model("PanelStyleMeta",{border:MS}).views(e=>({get json(){const{border:t}=e;return{border:t.json}}})).actions(e=>({})),pl=g.types.model("PanelTitleMeta",{show:g.types.optional(g.types.boolean,!0)}).views(e=>({get json(){const{show:t}=e;return{show:t}}})).actions(e=>({setShow(t){e.show=t}})),hl=g.types.model("VariableMeta",{name:g.types.string,size:g.types.string,weight:g.types.string,color:g.types.union(g.types.model({type:g.types.literal("static"),staticColor:g.types.string}),g.types.model({type:g.types.literal("continuous"),valueRange:g.types.array(g.types.number),colorRange:g.types.array(g.types.string)}),g.types.model({type:g.types.literal("piecewise")})),formatter:g.types.model({output:g.types.enumeration("Output",["number","percent"]),average:g.types.optional(g.types.boolean,!1),mantissa:g.types.number,trimMantissa:g.types.optional(g.types.boolean,!1),absolute:g.types.optional(g.types.boolean,!1)}),data_field:g.types.string,aggregation:g.types.union(g.types.model({type:g.types.enumeration(["none","sum","mean","median","min","max","CV","std"]),config:g.types.frozen(),fallback:g.types.optional(g.types.string,"0")}),g.types.model({type:g.types.literal("quantile"),config:g.types.model({p:g.types.number}),fallback:g.types.optional(g.types.string,"0")}),g.types.model({type:g.types.literal("custom"),config:g.types.model({func:g.types.string}),fallback:g.types.optional(g.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=g.types.model("PanelVizMeta",{type:g.types.string,conf:g.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=g.types.model({id:g.types.string,name:g.types.optional(g.types.string,""),title:pl,description:g.types.string,queryIDs:g.types.array(g.types.string),viz:xl,style:dl,variables:g.types.optional(g.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=g.cast(Array.from(n))},setQueryIDs(t){e.queryIDs=g.cast(t)},addVariable(t){e.variables.push(t)},removeVariable(t){e.variables.remove(t)}}));var le=(e=>(e.Postgresql="postgresql",e.MySQL="mysql",e.HTTP="http",e.Transform="transform",e))(le||{});const gl=g.types.model("QueryMeta",{id:g.types.string,name:g.types.string,type:g.types.enumeration("DataSourceType",[le.Postgresql,le.MySQL,le.HTTP,le.Transform]),key:g.types.string,sql:g.types.string,pre_process:g.types.optional(g.types.string,""),post_process:g.types.optional(g.types.string,""),run_by:g.types.optional(g.types.array(g.types.string),[]),react_to:g.types.optional(g.types.array(g.types.string),[]),dep_query_ids:g.types.optional(g.types.array(g.types.string),[])}).views(e=>({get valid(){return e.id&&e.type&&e.key&&e.name?e.type===le.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 Et({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=g.types.model("LayoutItemMeta",{id:g.types.identifier,panelID:g.types.string,x:g.types.number,y:g.types.maybeNull(g.types.number),w:g.types.number,h:g.types.number,moved:g.types.optional(g.types.boolean,!1),static:g.types.optional(g.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 g.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=g.types.model("LayoutSetMeta",{id:g.types.identifier,name:g.types.string,breakpoint:g.types.number,list:g.types.optional(g.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=>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:xt.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=g.types.model("SQLSnippetMeta",{key:g.types.string,value:g.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 pe=(e=>(e.Select="select",e.MultiSelect="multi-select",e.TreeSelect="tree-select",e.TextInput="text-input",e.Checkbox="checkbox",e.DateRange="date-range",e))(pe||{});const zr=g.types.model("FilterCheckboxConfigMeta",{_name:g.types.literal("checkbox"),description:g.types.optional(g.types.string,""),default_value:g.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}})),vl=()=>zr.create({_name:"checkbox",description:"",default_value:!1});function jl(e,t){return e.map(n=>{try{return n?z.tz(n,"UTC").format(t):null}catch{return console.log(`[date-range] failed parsing ${n}`),null}})}const zS=g.types.model("FilterDateRangeConfigMeta",{_name:g.types.literal("date-range"),required:g.types.boolean,inputFormat:g.types.enumeration("DateRangeInputFormat",["YYYY","YYYYMM","YYYYMMDD","YYYY-MM","YYYY-MM-DD"]),default_value:g.types.optional(g.types.array(g.types.union(g.types.string,g.types.null)),[null,null]),default_shortcut:g.types.optional(g.types.string,""),clearable:g.types.boolean,max_days:g.types.optional(g.types.number,0),allowSingleDateInRange:g.types.optional(g.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:jl(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=g.getParent(e);g.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=>z(i).format(e.inputFormat));e.setFilterValue(r)}},setMaxDays(t){e.max_days=t,t>0&&(e.clearable=!0)},setAllowSingleDateInRange(t){e.allowSingleDateInRange=t}})),Ar=g.types.snapshotProcessor(zS,{preProcessor({default_value:e,...t}){return{...t,default_value:e.map(n=>n===null?null:z.tz(n,"UTC").toISOString())}},postProcessor(e){const{default_value:t,...n}=e;return{...n,default_value:jl(t,n.inputFormat)}}}),wl=()=>Ar.create({_name:"date-range",required:!1,inputFormat:"YYYY-MM-DD",clearable:!1,default_value:[null,null]}),AS=g.types.model({label:g.types.string,value:g.types.string}).actions(e=>({setLabel(t){e.label=t},setValue(t){e.value=t}})),Er=g.types.model("FilterConfigModel_BaseSelect",{static_options:g.types.optional(g.types.array(AS),[]),options_query_id:g.types.optional(g.types.string,""),default_selection_count:g.types.optional(g.types.number,0),required:g.types.optional(g.types.boolean,!1)}).views(e=>({get contentModel(){return g.getRoot(e).content},get filter(){return g.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}=e.contentModel.getDataStuffByID(e.options_query_id);return n==="error"?[]: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=g.types.compose("FilterMultiSelectConfigMeta",g.types.model({_name:g.types.literal("multi-select"),min_width:g.types.optional(g.types.string,""),default_value:g.types.optional(g.types.array(g.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 Et({_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=g.cast(t)},setMinWidth(t){e.min_width=t},setDefaultSelection(){const t=g.getRoot(e).content.filters,n=g.getParent(e).key,r=new Set(e.options.map(o=>o.value)),i=(t.values[n]??[]).filter(o=>r.has(o));i.length>0?t.setValueByKey(n,i):t.setValueByKey(n,e.default_selection)}})).actions(e=>({afterCreate(){g.addDisposer(e,Y.reaction(()=>Y.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=g.types.compose("FilterConfigModel_Select",g.types.model({_name:g.types.literal("select"),default_value:g.types.string,width:g.types.optional(g.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 Et({_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(){var o;const t=g.getRoot(e).content.filters,n=g.getParent(e).key,r=t.values[n],i=(o=e.options.find(l=>l.value===r))==null?void 0:o.value;i?t.setValueByKey(n,i):t.setValueByKey(n,e.default_selection)}})).actions(e=>({afterCreate(){g.addDisposer(e,Y.reaction(()=>Y.toJS(e.default_selection),e.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),_l=()=>Lr.create({_name:"select",required:!1,default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),Br=g.types.model("FilterTextInputConfigMeta",{_name:g.types.literal("text-input"),required:g.types.boolean,default_value:g.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 ES(e){return fu.arrayToTree(e,{id:"value",parentId:"parent_value",childrenField:"children",dataField:null})}function PS(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=f.createElement("div",{},[f.createElement(a.Text,{key:0,title:t.label},t.label),f.createElement(a.Text,{key:1,className:"rc-tree-select-tree-title-desc",color:"dimmed",title:t.description},t.description)])),o})}const $r=g.types.compose("FilterTreeSelectConfigMeta",g.types.model({_name:g.types.literal("tree-select"),min_width:g.types.optional(g.types.string,""),default_value:g.types.optional(g.types.array(g.types.string),[]),treeCheckStrictly:g.types.optional(g.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=PS(t);return ES(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=g.cast(t)},setMinWidth(t){e.min_width=t},setTreeCheckStrictly(t){e.treeCheckStrictly=t},applyDefaultSelection(){const t=g.getParent(e,1).key,n=e.contentModel.filters,r=n.values[t],i=new Set(e.plainData.map(l=>l.value)),o=(r??[]).filter(l=>i.has(l));o.length>0?n.setValueByKey(t,o):n.setValueByKey(t,e.defaultSelection)},afterCreate(){g.addDisposer(e,Y.reaction(()=>JSON.stringify(e.defaultSelection),this.applyDefaultSelection,{fireImmediately:!0,delay:0}))}})),Sl=()=>$r.create({_name:"tree-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),qr=g.types.model("FilterMeta",{id:g.types.identifier,key:g.types.string,label:g.types.string,order:g.types.number,visibleInViewsIDs:g.types.array(g.types.string),auto_submit:g.types.optional(g.types.boolean,!1),default_value_func:g.types.optional(g.types.string,""),type:g.types.enumeration("DashboardFilterType",[pe.Select,pe.MultiSelect,pe.TreeSelect,pe.TextInput,pe.Checkbox,pe.DateRange]),config:g.types.union(Lr,Pr,$r,Br,zr,Ar)}).views(e=>({get contentModel(){return g.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!==pe.TreeSelect},get usingDefaultValueFunc(){return!!e.default_value_func},get formattedDefaultValue(){return this.filters.formattedDefaultValues[e.key]},get auto_submit_supported(){return[pe.Select,pe.Checkbox,pe.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:Y.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 pe.Select:e.config=_l();break;case pe.MultiSelect:e.config=Cl();break;case pe.TreeSelect:e.config=Sl();break;case pe.TextInput:e.config=Or();break;case pe.Checkbox:e.config=vl();break;case pe.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 B=(e=>(e.Division="div",e.Modal="modal",e.Tabs="tabs",e))(B||{});const Vr=g.types.model("ViewDivisionConfig",{_name:g.types.literal(B.Division)}).views(e=>({get json(){const{_name:t}=e;return{_name:t}}})),kl=()=>Vr.create({_name:B.Division}),LS=g.types.model("CustomModalTitleModel",{enabled:g.types.optional(g.types.boolean,!1),func_content:g.types.optional(g.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=g.getParent(e,2),i=g.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
|
+
`)},Nr=g.types.model("ViewModalConfig",{_name:g.types.literal(B.Modal),width:g.types.string,height:g.types.string,custom_modal_title:g.types.optional(LS,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}})),Tl=()=>Nr.create({_name:B.Modal,width:"90vw",height:"90vh"}),BS=g.types.model("ViewTabsTabModel",{id:g.types.identifier,name:g.types.string,view_id:g.types.string,color:g.types.optional(g.types.string,""),order:g.types.optional(g.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=g.types.model("ViewTabsConfig",{_name:g.types.literal(B.Modal),tabs:g.types.optional(g.types.array(BS),[]),variant:g.types.optional(g.types.enumeration("variant",["default","outline","pills"]),"default"),orientation:g.types.optional(g.types.enumeration("orientation",["horizontal","vertical"]),"horizontal"),grow:g.types.optional(g.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=g.cast(t)},addTab(){const t=ie.randomId(),n={id:t,name:t,view_id:""};e.tabs.push(n)},removeTab(t){e.tabs.splice(t,1)}})),Dl=()=>Fr.create({_name:B.Modal,tabs:[]}),Il=g.types.model({id:g.types.identifier,name:g.types.string,type:g.types.enumeration("EViewComponentType",[B.Division,B.Modal,B.Tabs]),config:g.types.union(Vr,Nr,Fr),panelIDs:g.types.optional(g.types.array(g.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 B.Division:e.config=kl();break;case B.Modal:e.config=Tl();break;case B.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)}})),lt="11.10.0",OS={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:B.Division,config:{},panelIDs:[]}],panels:[],filters:[],version:lt,layouts:[{id:"basis",name:"basis",list:[],breakpoint:0}]},Gr=g.types.model("DataSourceMetaModel",{id:g.types.string,type:g.types.enumeration("DataSourceType",[le.HTTP,le.MySQL,le.Postgresql]),key:g.types.string,config:g.types.frozen()}),Ml=g.types.model("DataSourcesMetaModel",{list:g.types.optional(g.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=g.types.model({id:g.types.string,content:g.types.string,create_time:g.types.string,update_time:g.types.string,is_preset:g.types.boolean}),Wr=g.types.model("GlobalSQLSnippetsMeta",{list:g.types.optional(g.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)}})),es=g.types.model("ContextMeta",{current:g.types.optional(g.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 es.create({current:e})}const Qr=g.types.compose("ViewRenderModel",Il,g.types.model({tab:g.types.optional(g.types.string,"")})).views(e=>({get defaultTab(){if(e.type!==B.Tabs)return"";const t=e.config;return t.tabs.length>0?t.tabs[0].id:""},get tabViewID(){var n;return e.type!==B.Tabs?"":((n=e.config.tabs.find(r=>r.id===e.tab))==null?void 0:n.view_id)??""},get contentModel(){return g.getParent(e,3)},get panels(){if(e.type!==B.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===B.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=>{mn.saveAs(c,`${e.name}_${o}.zip`)}).catch(c=>{console.error(c),pt.notifications.show({color:"red",title:"Failed to download screenshot with dashboard state",message:c.message})})}})).actions(e=>({setTab(t){e.tab=t??""},afterCreate(){g.addDisposer(e,Y.reaction(()=>e.defaultTab,t=>this.setTab(t),{fireImmediately:!0,delay:0}))}})),Ur=g.types.model("ViewsRenderModel",{current:g.types.optional(g.types.array(Qr),[]),visibleViewIDs:g.types.array(g.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 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 $S=new gu.AsyncParser({withBOM:!0});async function El(e){return!Array.isArray(e)||e.length===0?"":await $S.parse(e).promise()}async function qS(e,t){const n=await El(t),r=new Blob([n],{type:"text/csv"});mn.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=>{mn.saveAs(r,"dashboard_data.zip")})}).catch(r=>{console.error(r),pt.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 Kr=fl.views(e=>({get contentModel(){return g.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: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:gr.name,conf:gr.createConfig()},style:{border:{enabled:!0}}}}const Yr=g.types.model("PanelsRenderModel",{list:g.types.optional(g.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=>z(o).format(t.inputFormat))}const[...r]=n;return r.map(i=>i===null?i:z.tz(i,"UTC").format(t.inputFormat)??i)}catch(r){return console.error(r),n}return n}function VS(e,t){const n=e.default_value_func;try{return new Function(`return ${n}`)()(e,rt,t)}catch(r){return console.error(r),Bl(e)}}function Ol(e,t){var n;return(n=e.default_value_func)!=null&&n.trim()?VS(e,t):Bl(e)}function $l(e,t){return e.reduce((n,r)=>(n[r.key]=Ol(r,t),n),{})}const Xr=g.types.model("FiltersRenderModel",{current:g.types.optional(g.types.array(qr),[]),values:g.types.optional(g.types.frozen(),{})}).views(e=>({get json(){return e.current.map(t=>t.json)},get contentModel(){return g.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:lt}},downloadSchema(t){const n=JSON.stringify(this.getSchema(t,!1),null,2);Ft("Filters",n)}}));function Jr(e,t,n,r){const i=y.defaults({},r,$l(e,{...n,...t}));return{current:e,values:i}}const ql=gl.views(e=>({get rootModel(){return g.getRoot(e)},get contentModel(){return this.rootModel.content},get conditionOptions(){if(!g.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(!g.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=Td(i,t,n);return console.groupCollapsed(`Request config for: ${r}`),console.log(o),console.groupEnd(),JSON.stringify(o)},get typedAsSQL(){return[le.Postgresql,le.MySQL].includes(e.type)},get typedAsHTTP(){return[le.HTTP].includes(e.type)},get isTransform(){return e.type===le.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 g.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=g.types.compose("QueryRenderModel",ql,g.types.model({state:g.types.optional(g.types.enumeration(["idle","loading","error"]),"idle"),data:g.types.optional(g.types.frozen([]),[]),error:g.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:g.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*g.toGenerator(Ad({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:g.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=Dd(e.datasource,o);const l=yield*g.toGenerator(Ed({type:n,key:r,configString:JSON.stringify(o),name:e.name,additionals:e.additionalQueryInfo},e.controller.signal)),c=Id(e.datasource,l),u=Md(i,c,e.contentModel.dashboardState);e.data=u,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:y.cloneDeep(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(){g.addDisposer(e,Y.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=g.types.model("QueriesRenderModel",{current:g.types.optional(g.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 g.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;qS(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 Nl({min:e,max:t}){const n=`${e}px`,r=Number.isFinite(t)?`${t}px`:"∞";return`[${n}, ${r})`}const ei=g.types.model("LayoutsRenderModel",{list:g.types.array(yl),currentBreakpoint:g.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 g.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(){g.addDisposer(e,Y.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:!!g.getParent(e,2).findByKey(t)}})),ti=g.types.model("SQLSnippetsRenderModel",{current:g.types.optional(g.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:lt}},downloadSchema(t){const n=JSON.stringify(this.getSchema(t),null,2);Ft("SQL Snippets",n)}}));function Gl(e){return{current:e}}function cn(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){L(this,"origin");L(this,"copy");this.origin=t,this.copy=g.clone(t),Y.makeAutoObservable(this,{},{autoBind:!0,deep:!1})}get changed(){return!y.isEqual(g.getSnapshot(this.origin),g.getSnapshot(this.copy))}commit(){g.applySnapshot(this.origin,g.getSnapshot(this.copy))}reset(){g.applySnapshot(this.copy,g.getSnapshot(this.origin))}update(t){g.applySnapshot(this.copy,t)}}const Rl=e=>new Wl(e),NS=_.observer(({view:e})=>{const{t}=M.useTranslation(),n=J(),r=Q(),i=Ee.useModals(),{panel:o,downloadPanelScreenshot:l}=Le(),{id:c}=o,{viewPanelInFullScreen:u,inFullScreen:d}=f.useContext(Zn),h=()=>{r.duplicatePanelByID(c,e.id)},p=()=>{n.editor.open(["_VIEWS_",e.id,"_PANELS_",c])},x=()=>i.openConfirmModal({title:`${t("panel.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>r.removePanelByID(c,e.id),confirmProps:{color:"red"},zIndex:320}),m=f.useCallback(()=>{u(c)},[c,u]),v=!d&&e.type!==B.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:o.refreshData,icon:s.jsx(T.Refresh,{size:14}),children:t("common.actions.refresh")}),s.jsx(a.Menu.Item,{onClick:o.downloadData,icon:s.jsx(T.Download,{size:14}),children:t("common.actions.download_data")}),s.jsx(a.Menu.Item,{onClick:o.downloadSchema,icon:s.jsx(k.IconCode,{size:14}),children:t("common.actions.download_schema")}),s.jsx(a.Menu.Item,{onClick:l,icon:s.jsx(k.IconCamera,{size:14}),children:t("common.actions.download_screenshot")}),v&&s.jsx(a.Menu.Item,{onClick:m,icon:s.jsx(T.ArrowsMaximize,{size:14}),disabled:!0,children:t("common.actions.enter_fullscreen")}),s.jsx(a.Divider,{label:"Edit",labelPosition:"center"}),s.jsx(a.Menu.Item,{onClick:p,icon:s.jsx(T.Settings,{size:14}),children:t("common.titles.settings")}),s.jsx(a.Menu.Item,{onClick:h,icon:s.jsx(T.Copy,{size:14}),children:t("common.actions.duplicate")}),s.jsx(a.Menu.Item,{color:"red",onClick:x,icon:s.jsx(T.Trash,{size:14}),children:t("common.actions.delete")})]})]})})})});function FS(e){return e?["<p><br></p>","<p></p>"].includes(e):!0}const ni=_.observer(()=>{const[e,t]=f.useState(!1),{panel:n}=gt();return FS(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(T.InfoCircle,{size:20})})})]})}),WI="",GS=_.observer(function(){const{panel:t}=gt(),{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 WS(e){const t=f.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||{}),ts=(e=>(e.notStarted="notStarted",e.inProgress="inProgress",e.done="done",e))(ts||{});class RS{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(de.instanceScope.panelModel),this.vizInstance=t.getRequired(de.instanceScope.vizInstance),this.operationManager=t.getRequired(de.instanceScope.operationManager),this.triggerManager=t.getRequired(de.instanceScope.triggerManager),this.vizManager=t.getRequired(de.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}=gt();return f.useCallback(n=>{const r=n.getRequired(de.vizManager),i=r.resolveComponent(e.viz.type);return n.createScoped().provideFactory(de.instanceScope.vizInstance,()=>r.getOrCreateInstance(e)).provideFactory(de.instanceScope.interactionManager,o=>{const l=o.getRequired(de.instanceScope.vizInstance);return new zs(l,i,Sn)}).provideFactory(de.instanceScope.operationManager,o=>o.getRequired(de.instanceScope.interactionManager).operationManager).provideFactory(de.instanceScope.triggerManager,o=>o.getRequired(de.instanceScope.interactionManager).triggerManager).provideValue(de.instanceScope.panelModel,t).provideFactory(de.instanceScope.migrator,o=>new RS(o))},[e.viz.type,e.viz.conf])}function Kl(e){const[t,n]=f.useState(!1),r=il().getRequired(de.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===Ql.migrated&&i&&(e==null||e())}).finally(()=>{n(!0)})},[r]),t}function Yl(e,t){const n=il().getRequired(de.instanceScope.vizInstance);return f.useEffect(()=>(n.instanceData.setItem(null,t.viz.conf),n.instanceData.watchItem(null,r=>{e(r)})),[e,t.viz.type]),n}function QS({setVizConf:e,...t}){const{panel:n}=t,r=Yl(e,n),i=Kl(()=>{pt.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(Od,{...t}):s.jsx(a.Text,{children:"Checking update..."})}function US(e){const{panel:t,setVizConf:n}=e;Yl(n,t);const{inEditMode:r}=f.useContext(Cn);return Kl(()=>{r&&pt.showNotification({title:`${t.name} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?s.jsx(Bd,{...e}):s.jsx(a.Text,{children:"Checking update"})}const RI="";function KS(e,t){const{vizManager:n}=f.useContext(tt),{panel:{viz:r,title:i,id:o,name:l,description:c,queryIDs:u,variables:d}}=gt(),h={id:o,name:l,title:i,description:c,queryIDs:u,viz:r},p=Ul(h);try{return n.resolveComponent(r.type),s.jsx(Jn,{configure:p,children:s.jsx(US,{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=_.observer(function({data:t}){const{ref:n,width:r,height:i}=ie.useElementSize(),o=KS(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=_.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=_.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})]})),YS={border:"1px solid #e9ecef"},Zl=_.observer(({panel:e,panelStyle:t,dropdownContent:n})=>{const{ref:r,downloadPanelScreenshot:i}=WS(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:{...YS,...t},children:[s.jsx(a.Box,{className:"panel-description-popover-wrapper",children:s.jsx(ni,{})}),n,s.jsx(GS,{}),s.jsx(si,{panel:e})]})})}),XS={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function JS(e){return e.style.border.enabled?{}:XS}const Hl=_.observer(function({panel:t,view:n}){const r=JS(t);return s.jsx(Zl,{panel:t,panelStyle:r,dropdownContent:s.jsx(NS,{view:n})})});function ZS(e){return!["richText","button"].includes(e)}const HS=_.observer(({view:e})=>{const{t}=M.useTranslation(),{panel:n,downloadPanelScreenshot:r}=gt(),{id:i}=n,{viewPanelInFullScreen:o,inFullScreen:l}=f.useContext(Zn),c=f.useCallback(()=>{o(i)},[i,o]),u=!l&&e.type!==B.Modal;return ZS(n.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:n.refreshData,icon:s.jsx(T.Refresh,{size:14}),children:t("common.actions.refresh")}),s.jsx(a.Menu.Item,{onClick:n.downloadData,icon:s.jsx(T.Download,{size:14}),children:t("common.actions.download_data")}),s.jsx(a.Menu.Item,{onClick:r,icon:s.jsx(k.IconCamera,{size:14}),children:t("common.actions.download_screenshot")}),u&&s.jsx(a.Menu.Item,{onClick:c,icon:s.jsx(T.ArrowsMaximize,{size:14}),children:t("common.actions.enter_fullscreen")})]})]})}):null});function e1(e){return e.style.border.enabled?{}:{border:"1px dashed transparent"}}const ri=_.observer(({panel:e,view:t})=>{const n=e1(e);return s.jsx(Zl,{panel:e,panelStyle:n,dropdownContent:s.jsx(HS,{view:t})})}),t1={modal:{display:"flex",flexDirection:"column",flexWrap:"nowrap"},body:{display:"flex",height:"calc(100vh - 88px)"}},ec=_.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(T.ArrowLeft,{size:20}),children:"Exit fullscreen"}),styles:t1,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}=ue(),i=e.id==="Main",[o,l]=f.useState(()=>i&&r.findByID(t)?t:null),c=f.useCallback(p=>{l(p),i&&n(p)},[i,n]),u=f.useCallback(()=>{l(null),i&&n("")},[i,n]),d=o?r.findByID(o):null;return{viewPanelInFullScreen:c,exitFullScreen:u,inFullScreen:!!d,fullScreenPanel:d}}const QI="",n1=f.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(T.ArrowsMove,{size:16})})),s1=f.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(T.ChevronDownRight,{size:16})})),r1=gn.WidthProvider(gn.Responsive),i1=_.observer(({view:e,className:t="layout"})=>{const r=Q().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(r1,{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(s1,{}),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(n1,{h:d.h}),s.jsx(Hl,{view:e,panel:d.panel})]},d.id))})}),a1=gn.WidthProvider(gn.Responsive),o1=_.observer(({view:e,className:t="layout"})=>{const n=ue(),r=n.layouts.items(e.panelIDs),i=n.layouts.gridLayouts(e.panelIDs);return s.jsx(a1,{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=f.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 l1=_.observer(({downloadScreenshot:e})=>{const{t}=M.useTranslation(),[n,{setTrue:r,setFalse:i}]=V.useBoolean(!1),o=pa(),l=ue(),c=()=>{const u=JSON.stringify(l.contentJSON,null,2),d=`${o.name}__${l.name}`;Ft(d,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:r,onMouseLeave:i,sx:{opacity:n?1:.6,transform:`translateX(${n?0:"2px"})`,transition:"all ease 300ms",borderRadius:"50%"},children:s.jsx(k.IconShare3,{size:"1rem"})})})}),s.jsxs(a.Menu.Dropdown,{children:[s.jsx(a.Menu.Item,{icon:s.jsx(k.IconCamera,{size:14}),onClick:e,children:t("common.actions.download_screenshot")}),s.jsx(a.Menu.Divider,{}),s.jsx(a.Menu.Item,{icon:s.jsx(k.IconDownload,{size:14}),onClick:l.queries.downloadAllData,children:t("common.actions.download_data")}),s.jsx(a.Menu.Item,{icon:s.jsx(k.IconCode,{size:14}),onClick:c,children:t("common.actions.download_schema")})]})]})}),nc=_.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(l1,{downloadScreenshot:i})]})}),sc=_.observer(({downloadScreenshot:e})=>s.jsx(a.ActionIcon,{className:"download-screenshot-button",color:"blue",onClick:e,children:s.jsx(k.IconCamera,{size:14})})),c1=_.observer(({children:e,view:t})=>{const n=ue(),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})})}),u1=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},d1=_.observer(({view:e})=>{const t=ue(),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:u1(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})]})}),p1=_.observer(({view:e,children:t})=>{switch(e.type){case B.Modal:return s.jsx(c1,{view:e,children:t});case B.Tabs:return s.jsx(d1,{view:e});case B.Division:default:return s.jsx(nc,{view:e,children:t})}}),h1=_.observer(({children:e,view:t})=>{const r=Q().layouts,[i,o]=ie.useResizeObserver();return f.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 x1=_.observer(({children:e,view:t})=>{const n=t.config,{width:r,height:i}=f.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})})})}),f1=({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},g1=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},m1=_.observer(({view:e})=>{const{t}=M.useTranslation(),n=Ee.useModals(),r=Q(),i=f.useMemo(()=>r.views.options.filter(u=>u.type===B.Division),[e.id,r.views.options]),o=e.config,l=u=>n.openConfirmModal({title:`${t("view.component.tabs.tab.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{o.removeTab(u)},confirmProps:{color:"red"},zIndex:320}),c=o.tabs.length===0;return s.jsxs(a.Tabs,{className:"preview-view-tabs",variant:o.variant,orientation:o.orientation,value:e.tab,onTabChange:e.setTab,styles:f1(o),children:[s.jsxs(a.Tabs.List,{grow:o.grow,children:[o.tabsInOrder.map(u=>s.jsx(a.Tabs.Tab,{value:u.id,sx:g1(u),children:u.name??u.id},u.id)),s.jsx(a.Tabs.Tab,{onClick:o.addTab,value:"add",className:"add-a-tab",children:s.jsx(T.Plus,{size:18,color:"#228be6"})})]}),o.tabsInOrder.map((u,d)=>{const h=r.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:t("view.component.tabs.tab.name"),required:!0,value:u.name,onChange:p=>u.setName(p.currentTarget.value)}),s.jsx(a.Select,{label:"View",value:u.view_id,onChange:u.setViewID,data:i}),s.jsx(a.NumberInput,{label:t("view.component.tabs.tab.order"),required:!0,value:u.order,onChange:p=>u.setOrder(p||0),min:0,max:1e3,step:1}),s.jsx(a.ColorInput,{label:t("view.component.tabs.tab.color"),value:u.color,onChange:u.setColor,disabled:o.variant!=="default"}),h&&s.jsx(a.Button,{mt:20,variant:"gradient",leftIcon:s.jsx(k.IconArrowsLeftRight,{size:18}),gradient:{from:"cyan",to:"indigo"},onClick:()=>r.views.setIDOfVIE(h.id),children:t("view.component.tabs.tab.switch_to_view",{name:h.name})}),s.jsx(a.Button,{mt:20,variant:"subtle",color:"red",onClick:()=>l(d),disabled:c,leftIcon:s.jsx(k.IconTrash,{size:14}),children:t("view.component.tabs.tab.delete")})]})]}),h&&s.jsx(ns,{view:h})]},u.id)})]})}),y1=_.observer(({view:e,children:t})=>{switch(e.type){case B.Modal:return s.jsx(x1,{view:e,children:t});case B.Tabs:return s.jsx(m1,{view:e});case B.Division:default:return s.jsx(h1,{view:e,children:t})}}),ic=_.observer(function({view:t}){const r=Q().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(y1,{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(i1,{view:t})]})})})})}),ns=_.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(Zn.Provider,{value:{viewPanelInFullScreen:i,inFullScreen:l},children:s.jsxs(a.Box,{className:"dashboard-view","data-enable-scrollbar":!0,sx:{height:t.type===B.Modal?"0 !important":"100%"},children:[l&&s.jsx(ec,{view:t,panel:c,exitFullScreen:o}),s.jsx(p1,{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(o1,{view:t})]})})]})})});var ac=(e=>(e.Use="use",e.Edit="edit",e))(ac||{});const b1={[B.Division]:"Division",[B.Tabs]:"Tabs",[B.Modal]:"Modal"},oc={[B.Division]:"rgba(255, 0, 0, 0.2)",[B.Modal]:"rgba(0, 0, 0, 0.2)",[B.Tabs]:"rgba(255, 200, 100, 0.4)"},v1={[B.Division]:"#ff4000",[B.Modal]:"#000",[B.Tabs]:"#ffad18"};function j1(e,t,n){g.addDisposer(e,g.addMiddleware(e,(r,i)=>{i(r,()=>{g.getType(r.context)===t&&r.type==="action"&&n(r.name,r.context)})}))}const lc=g.types.compose("FiltersModel",Xr,g.types.model("FiltersModel",{previewValues:g.types.optional(g.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===pe.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=g.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(){j1(e.current,qr,(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=g.types.compose("QueriesModel",Hr,g.types.model({current:g.types.optional(g.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!==le.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=g.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&&(g.detach(n),e.current.remove(n))},removeQueries(t){const n=new Set(t);e.current.forEach(i=>{n.has(i.id)&&g.detach(i)});const r=[...e.current];y.remove(r,i=>n.has(i.id)),e.current=g.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=g.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)&&g.detach(i)});const r=[...e.current];y.remove(r,i=>n.has(i.key)),e.current=g.cast(r)},replaceByIndex(t,n){e.current.splice(t,1,n)}})),w1=g.types.model({data:g.types.optional(g.types.frozen(),[]),state:g.types.optional(g.types.enumeration(["idle","loading","error"]),"idle"),error:g.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0}})),C1=g.types.model({data:g.types.optional(g.types.frozen(),[]),state:g.types.optional(g.types.enumeration(["idle","loading","error"]),"idle"),error:g.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0}})),_1=g.types.model({page:g.types.optional(g.types.number,1),limit:g.types.optional(g.types.number,20),data:g.types.optional(g.types.frozen(),[]),total:g.types.optional(g.types.number,0),state:g.types.optional(g.types.enumeration(["idle","loading","error"]),"idle"),error:g.types.frozen()}).views(e=>({get keywords(){return g.getParent(e,1)},get keywordString(){const{table_name:t,table_schema:n}=g.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,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
|
-
`),
|
|
453
|
+
`}})).actions(e=>({setPage(t){e.page=t},resetPage(){e.page=1},setLimit(t){e.limit=t}})).actions(e=>({afterCreate(){g.addDisposer(e,Y.reaction(()=>e.keywordString,e.resetPage,{fireImmediately:!1,delay:0})),g.addDisposer(e,Y.reaction(()=>e.limit,e.resetPage,{fireImmediately:!1,delay:0}))}})),S1=g.types.model({data:g.types.optional(g.types.frozen(),{}),state:g.types.optional(g.types.enumeration(["idle","loading","error"]),"idle"),error:g.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return Object.keys(e.data).length===0}})),k1=g.types.compose("DataSourceModel",Gr,g.types.model({tables:g.types.optional(S1,{}),columns:g.types.optional(w1,{}),tableData:g.types.optional(_1,{}),indexes:g.types.optional(C1,{}),table_schema:g.types.optional(g.types.string,""),table_name:g.types.optional(g.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=g.flow(function*(){var n;(n=e.controllers.tables)==null||n.abort(),e.controllers.tables=new AbortController,e.tables.state="loading";try{const r=yield*g.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:g.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*g.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:g.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*g.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:g.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*g.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*g.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(){g.addDisposer(e,Y.reaction(()=>e.reloadConditionString,e.loadColumns,{fireImmediately:!1,delay:500}))}})).actions(e=>({afterCreate(){g.addDisposer(e,Y.reaction(()=>e.reloadConditionString,e.loadIndexes,{fireImmediately:!1,delay:500})),g.addDisposer(e,Y.reaction(()=>`${e.reloadConditionString};limit:${e.tableData.limit};offset:${e.tableData.offset}`,e.loadTableData,{fireImmediately:!1,delay:0}))}})),T1=g.types.model("DataSourcesModel",{list:g.types.optional(g.types.array(k1),[])}).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 D1(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 I1=g.types.model("EditorModel",{path:g.types.optional(g.types.frozen(),[]),settings_open:g.types.optional(g.types.boolean,!1)}).views(e=>({get navOptions(){const{content:t}=g.getRoot(e),{filters:n,views:r,sqlSnippets:i,queries:o}=t;return[{label:"query_variable.labels",value:"_QUERY_VARS_",_type:"query_variables",Icon:k.IconVariable},{label:"mock_context.label",value:"_MOCK_CONTEXT_",Icon:k.IconCodeDots,_type:"mock_context"},{label:"filter.labels",value:"_FILTERS_",Icon:k.IconFilter,children:[Tt("_FILTERS_SETTINGS_"),...n.options,Tt("_Add_A_Filter_")],_type:"GROUP"},{label:"sql_snippet.labels",value:"_SQL_SNIPPETS_",Icon:k.IconCopy,children:[Tt("_SQL_SNIPPETS_SETTINGS_"),...i.options,Tt("_Add_A_SQL_SNIPPET_")],_type:"GROUP"},{label:"query.labels",value:"_QUERIES_",Icon:k.IconDatabase,children:[Tt("_QUERIES_SETTINGS_"),...o.options,Tt("_Add_A_QUERY_")],_type:"GROUP"},{label:"view.labels",value:"_VIEWS_",Icon:k.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=D1(t);n&&e.setPath(n)}})),M1=g.types.compose("LayoutsModel",ei,g.types.model({currentLayoutWrapperWidth:g.types.optional(g.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:xt.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:xt.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=A(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}=A(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(){g.getParent(e,2).removeByID(e.id)}})).actions(e=>({moveToView(t,n){g.getRoot(e).content.views.findByID(t).removePanelID(e.id),g.getRoot(e).content.views.findByID(n).appendPanelID(e.id),g.getRoot(e).editor.setPath(["_VIEWS_",n,"_PANELS_",e.id])}})),hc=g.types.compose("PanelsModel",Yr,g.types.model({list:g.types.optional(g.types.array(pc),[])})).views(e=>({get contentModel(){return g.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=g.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)}})),z1=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:lt}},downloadSchema(){if(e.type===B.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)}})),xc=g.types.compose("ViewsModel",Ur,g.types.model({current:g.types.optional(g.types.array(z1),[]),idOfVIE:g.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=g.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];g.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,B.Division,B.Division,{_name:B.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 A1=g.types.model({id:g.types.string,name:g.types.string,dashboard_id:g.types.string,create_time:g.types.string,update_time:g.types.string,version:g.types.string,filters:lc,queries:uc,sqlSnippets:dc,views:xc,panels:hc,layouts:M1,mock_context:Ir,origin:g.types.maybe(g.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(g.getSnapshot(y.get(e,t)),y.get(e.origin,t))},get queriesChanged(){const t="queries.current",n=g.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(g.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(g.getSnapshot(y.get(e,t)),y.get(e.origin,t))},get layoutsChanged(){const t="layouts.list";return!y.isEqual(g.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=g.getParent(e).context.current;return{...e.mock_context.current,...t}},get payloadForSQL(){const t=g.getParent(e).globalSQLSnippets,n={context:this.context,filters:e.filters.values};return{...n,sql_snippets:cn(e.sqlSnippets.current,"key","value",n),global_sql_snippets:cn(t.list,"id","content",n)}},get payloadForViz(){const t=g.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=xt.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 v=xt.v4();return h.set(m.id,v),{...m,id:v}});if(e.panels.appendMultiple(x),!Array.isArray(n)||n.length===0){const m=x.map(v=>v.id);(p=e.views.VIE)==null||p.appendPanelIDs(m)}}if(Array.isArray(n)){const x=n.map(m=>{const v=m.panelIDs.map(C=>h.get(C)??C);return{...m,id:xt.v4(),panelIDs:v}});e.views.appendMultiple(x)}if(Array.isArray(l)){const x=(C,S)=>e.layouts.breakpointNameRecord[C]===S;let m=[];const v=l.filter(C=>x(C.name,C.breakpoint));v.forEach(C=>{C.id==="basis"&&(m=C.list),C.list.forEach(S=>{const D=h.get(S.panelID);S.id=xt.v4(),S.panelID=D})}),e.layouts.list.forEach(C=>{const S=v.find(D=>D.name===C.name&&D.breakpoint===C.breakpoint);if(!S){m.forEach(D=>{C.addLayout(D)});return}S.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(){g.applySnapshot(e.filters.current,e.origin.filters.current),g.applySnapshot(e.queries.current,e.origin.queries.current),g.applySnapshot(e.sqlSnippets.current,e.origin.sqlSnippets.current),g.applySnapshot(e.views.current,e.origin.views.current),g.applySnapshot(e.panels.list,e.origin.panels.list),g.applySnapshot(e.layouts.list,e.origin.layouts.list),e.mock_context.current=e.origin.mock_context.current},resetFilters(){g.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,g.applySnapshot(e.filters.current,l),g.applySnapshot(e.views.current,ai(c).current),g.applySnapshot(e.panels.list,u),g.applySnapshot(e.queries.current,d),g.applySnapshot(e.sqlSnippets.current,h),e.mock_context.current=p}})),oi=g.types.snapshotProcessor(A1,{preProcessor(e){return{...e,origin:e}},postProcessor(e){delete e.origin;const t=g.castToSnapshot(e.queries.current.map(n=>y.pick(n,["id","key","type","sql"])));return y.defaults({},{queries:{current:t}},e)}});function E1(e,t){t.filters&&g.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:v,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:v},mock_context:Mr(C),views:ai(h),panels:{list:p},layouts:{list:x,currentBreakpoint:x[0].id}})}const gc=g.types.model({id:g.types.identifier,name:g.types.string,group:g.types.string,content:oi,content_id:g.types.string,datasources:T1,globalSQLSnippets:Wr,context:es,editor:I1}).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){f.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]),f.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]),f.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]),f.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 f.useCallback(t=>t.provideValue(de.pluginManager,e.pluginManager).provideValue(de.vizManager,e.vizManager).provideValue(de.colorManager,e.colorManager),[])}const UI="",P1=_.observer(({saveDashboardChanges:e})=>{const{t}=M.useTranslation(),n=Ee.useModals(),r=Q(),i=()=>{n.openConfirmModal({title:s.jsxs(a.Group,{position:"left",children:[s.jsx(k.IconAlertTriangle,{size:18,color:"red"}),s.jsx(a.Text,{children:"You are reverting changes"})]}),labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:()=>r.reset(),zIndex:320,withCloseButton:!1})},o=r.changed;return s.jsxs(a.Group,{spacing:0,children:[s.jsx(a.Button,{color:"green",variant:"filled",size:"xs",leftIcon:s.jsx(k.IconDeviceFloppy,{size:18}),onClick:e,disabled:!o,sx:{borderTopRightRadius:0,borderBottomRightRadius:0},children:t("common.actions.save_changes")}),s.jsxs(a.Menu,{width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:320,disabled:!o,children:[s.jsx(a.Menu.Target,{children:s.jsx(a.ActionIcon,{variant:"default",disabled:!o,sx:{height:"30px",borderTopLeftRadius:0,borderBottomLeftRadius:0,svg:{fill:"rgb(173, 181, 189)",stroke:"none"}},children:s.jsx(k.IconCaretDown,{size:18})})}),s.jsx(a.Menu.Dropdown,{children:s.jsx(a.Menu.Item,{icon:s.jsx(k.IconRecycle,{size:14,color:"red"}),disabled:!o,onClick:i,children:t("common.actions.revert_changes")})})]})]})}),L1=_.observer(({saveDashboardChanges:e,onExit:t,headerSlot:n=null})=>{M.useTranslation();const r=J(),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(k.IconArrowLeft,{size:20}),onClick:o,children:s.jsx(a.Group,{spacing:4,children:s.jsxs(M.Trans,{i18nKey:"common.actions.end_editing",values:{name:r.name},children:["End Editing ",s.jsx(a.Text,{td:"underline",children:r.name})]})})}),s.jsx(P1,{saveDashboardChanges:e})]}),s.jsx(a.Group,{position:"right",sx:{flexGrow:1},children:n})]})})}),vc={height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},B1=_.observer(()=>{var i;const{t:e}=M.useTranslation(),t=Q(),n=((i=t.views.VIE)==null?void 0:i.type)===B.Tabs,r=()=>t.addANewPanel(t.views.idOfVIE);return n?s.jsx(a.Tooltip,{label:e("common.choose_a_tab_first"),children:s.jsx(a.Button,{variant:"outline",color:"gray",radius:0,size:"xs",leftIcon:s.jsx(k.IconPlaylistAdd,{size:20}),sx:{...vc,transform:"none !important"},children:e("panel.add")})}):s.jsx(a.Button,{variant:"outline",color:"blue",radius:0,size:"xs",onClick:r,leftIcon:s.jsx(k.IconPlaylistAdd,{size:20}),sx:{...vc,background:"rgb(231, 245, 255)"},children:e("panel.add")})}),O1=_.observer(({done:e})=>{var F,re;const{t}=M.useTranslation(),r=Q().layouts,i=f.useMemo(()=>({list:r.breakpointsInfo}),[r.breakpointsInfo]),{control:o,handleSubmit:l,watch:c,getValues:u,reset:d,formState:h}=b.useForm({defaultValues:i}),{fields:p,append:x,remove:m}=b.useFieldArray({control:o,name:"list",rules:{validate:W=>{if(console.log({values:W}),y.uniqBy(W,"breakpoint").length!==W.length)return"Screen sizes should be unique by min width"}}}),v=c("list"),C=p.map((W,te)=>({...W,...v[te]})),S=()=>{x({id:xt.v4(),name:"",breakpoint:""})},D=({list:W})=>{const te=W.filter(Ae=>Number.isFinite(Ae.breakpoint));r.updateLayoutSetsInfo(te),e()},P=u(),q=f.useMemo(()=>{const W={list:P.list.filter(te=>!!te.name&&Number.isFinite(te.breakpoint))};return!y.isEqual(W,i)},[P,i]),U=(re=(F=h.errors.list)==null?void 0:F.root)==null?void 0:re.message;return s.jsx(s.Fragment,{children:s.jsxs("form",{onSubmit:l(D),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:t("common.name")}),s.jsx("th",{style:{width:"160px"},children:t("breakpoint.breakpoint")}),s.jsx("th",{})]})}),s.jsxs("tbody",{children:[C.map((W,te)=>s.jsxs("tr",{children:[s.jsx("th",{children:W.id==="basis"?W.name:s.jsx(b.Controller,{name:`list.${te}.name`,control:o,render:({field:Ae})=>s.jsx(a.TextInput,{size:"xs",label:"",required:!0,sx:{flex:1},...Ae})})}),s.jsx("td",{children:W.id==="basis"?s.jsxs(a.Text,{ff:"monospace",children:[W.breakpoint,"px"]}):s.jsx(b.Controller,{name:`list.${te}.breakpoint`,control:o,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:W.id!=="basis"&&s.jsx(a.ActionIcon,{mx:"auto",size:"xs",variant:"subtle",color:"red",onClick:()=>m(te),children:s.jsx(k.IconTrash,{})})})]},W.id)),s.jsx("tr",{style:{backgroundColor:"transparent"},children:s.jsx("td",{colSpan:3,style:{padding:"0"},children:s.jsx(a.Tooltip,{label:t("breakpoint.add"),children:s.jsx(a.ActionIcon,{variant:"subtle",size:"md",color:"blue",onClick:S,sx:{width:"100%"},children:s.jsx(k.IconPlus,{size:18})})})})})]})]}),s.jsx(a.Text,{mt:6,ta:"right",size:"xs",color:"red",children:U??" "}),s.jsxs(a.Group,{mt:6,position:"apart",children:[s.jsx(a.Button,{color:"orange",size:"xs",onClick:()=>d(),leftIcon:s.jsx(k.IconRecycle,{size:18}),disabled:!q,children:t("common.actions.revert")}),s.jsx(a.Button,{color:"green",size:"xs",type:"submit",leftIcon:s.jsx(k.IconDeviceFloppy,{size:18}),disabled:!q,children:t("common.actions.save_changes")})]})]})})}),$1=_.observer(()=>{const{t:e}=M.useTranslation(),[t,{open:n,close:r}]=ie.useDisclosure(!1),i=Q(),o=i.layouts.currentBreakpoint,l=i.layouts.currentLayoutRange,c=()=>{setTimeout(()=>{window.dispatchEvent(new Event("resize"))},32)},u=()=>{r(),c()};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(k.IconDevices,{size:16}),sx:{borderRadius:0},children:s.jsxs(a.Group,{spacing:6,children:[s.jsx(a.Text,{size:"xs",fw:"normal",children:l.name}),s.jsx(a.Text,{size:"xs",color:"#777",children:i.layouts.currentRangeText})]})})}),s.jsxs(a.Menu.Dropdown,{children:[i.layouts.breakpointRanges.map(d=>s.jsx(a.Menu.Item,{onClick:()=>i.layouts.setCurrentBreakpoint(d.id),disabled:o===d.id,children:s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Text,{size:"sm",children:d.name}),s.jsx(a.Text,{size:"xs",color:"dimmed",children:d.text})]})},d.id)),s.jsx(a.Menu.Divider,{}),s.jsx(a.Menu.Item,{color:"blue",icon:s.jsx(k.IconSettings,{size:14}),onClick:n,children:s.jsx(a.Text,{size:"sm",children:e("breakpoint.manage")})})]})]}),i.layouts.divisionPreviewScale<1&&s.jsx(a.Text,{size:"xs",color:"dimmed",children:fn(i.layouts.divisionPreviewScale).format({output:"percent",mantissa:0})})]}),s.jsx(a.Modal,{opened:t,onClose:u,title:e("breakpoint.label",{count:2}),withinPortal:!0,zIndex:320,size:600,closeOnClickOutside:!1,children:s.jsx(O1,{done:u})})]})}),jc={height:"30px",borderRight:"none",borderTop:"none",borderLeft:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},q1=_.observer(()=>{var i;const{t:e}=M.useTranslation(),t=Q(),n=((i=t.views.VIE)==null?void 0:i.type)===B.Tabs,r=()=>{var o;return(o=t.views.VIE)==null?void 0:o.downloadSchema()};return n?s.jsx(a.Tooltip,{label:e("common.choose_a_tab_first"),children:s.jsx(a.Button,{variant:"outline",color:"gray",radius:0,size:"xs",leftIcon:s.jsx(k.IconCode,{size:16}),sx:{...jc,transform:"none !important"},children:e("view.download_schema")})}):s.jsx(a.Button,{variant:"outline",color:"blue",radius:0,size:"xs",onClick:r,leftIcon:s.jsx(k.IconCode,{size:16}),sx:{...jc},children:e("view.download_schema")})}),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})]}),V1=({content:e})=>{const{t}=M.useTranslation(),n=e.views;return!Array.isArray(n)||n.length===0?null:s.jsxs(a.Box,{children:[s.jsx(a.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:t("view.labels")}),s.jsx(ss,{headers:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"160px"},children:t("common.id")}),s.jsx("th",{children:t("common.name")}),s.jsx("th",{children:t("common.type")})]}),rows:n.map(r=>s.jsxs("tr",{children:[s.jsx("td",{children:r.id}),s.jsx("td",{children:r.name}),s.jsx("td",{children:t(`view.component.${r.type}.label`)})]},r.id))})]})},N1=({content:e})=>{const{t}=M.useTranslation(),n=e.filters;return!Array.isArray(n)||n.length===0?null:s.jsxs(a.Box,{children:[s.jsx(a.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:t("filter.labels")}),s.jsx(ss,{headers:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"160px"},children:t("common.id")}),s.jsx("th",{children:t("common.key")}),s.jsx("th",{children:t("common.label")})]}),rows:n.map(r=>s.jsxs("tr",{children:[s.jsx("td",{children:r.id}),s.jsx("td",{children:r.key}),s.jsx("td",{children:r.label})]},r.id))})]})},F1=({content:e})=>{const{t}=M.useTranslation(),n=e.panels;return!Array.isArray(n)||n.length===0?null:s.jsxs(a.Box,{children:[s.jsx(a.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:t("panel.labels")}),s.jsx(ss,{headers:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"160px"},children:t("common.id")}),s.jsx("th",{children:t("common.name")}),s.jsx("th",{children:t("visualization.component")})]}),rows:n.map(r=>s.jsxs("tr",{children:[s.jsx("td",{children:r.id}),s.jsx("td",{children:r.name}),s.jsx("td",{children:r.viz.type})]},r.id))})]})},G1=({content:e})=>{var r;const{t}=M.useTranslation(),n=(r=e.definition)==null?void 0:r.queries;return!Array.isArray(n)||n.length===0?null:s.jsxs(a.Box,{children:[s.jsx(a.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:t("query.labels")}),s.jsx(ss,{headers:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"160px"},children:t("common.id")}),s.jsx("th",{children:t("common.name")}),s.jsx("th",{style:{width:"140px"},children:t("common.type")}),s.jsx("th",{style:{width:"260px"},children:t("data_source.label")})]}),rows:n.map(i=>s.jsxs("tr",{children:[s.jsx("td",{children:i.id}),s.jsx("td",{children:i.name}),s.jsx("td",{children:i.type}),s.jsx("td",{children:i.key})]},i.id))})]})},W1=({content:e})=>{var r;const{t}=M.useTranslation(),n=(r=e.definition)==null?void 0:r.sqlSnippets;return!Array.isArray(n)||n.length===0?null:s.jsxs(a.Box,{children:[s.jsx(a.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:t("sql_snippet.labels")}),s.jsx(a.List,{size:"sm",pl:10,ff:"monospace",icon:s.jsx(k.IconPointFilled,{size:10}),children:n.map(i=>s.jsx(a.List.Item,{children:i.key},i.key))})]})},R1=({content:e})=>{var r;const{t}=M.useTranslation(),n=Object.keys(((r=e.definition)==null?void 0:r.mock_context)??{});return n.length===0?null:s.jsxs(a.Box,{children:[s.jsx(a.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:t("mock_context.label")}),s.jsx(a.List,{size:"sm",pl:10,ff:"monospace",icon:s.jsx(k.IconPointFilled,{size:10}),children:n.map(i=>s.jsx(a.List.Item,{children:i},i))})]})},Q1=({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(V1,{content:e}),s.jsx(N1,{content:e}),s.jsx(F1,{content:e}),s.jsx(G1,{content:e}),s.jsx(W1,{content:e}),s.jsx(R1,{content:e})]})]}):null;function U1(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 K1=_.observer(({onSuccess:e,stretchModal:t,shrinkModal:n})=>{var D,P;const{t:r}=M.useTranslation(),i=Q(),{handleSubmit:o,formState:{errors:l},setValue:c,watch:u,setError:d,clearErrors:h}=b.useForm({defaultValues:{content:null}}),p=({content:q})=>{try{if(!q)throw new Error("please use a valid json file");i.applyJSONSchema(q),pt.showNotification({title:"Successful",message:"",color:"green"}),e()}catch(U){console.error(U),pt.showNotification({title:"Failed",message:U.message,color:"red"})}},[x,m]=f.useState(null);f.useEffect(()=>{if(!x)return;const q=new FileReader;q.readAsText(x,"UTF-8"),q.onload=U=>{try{const F=U1(U);c("content",F),h("content")}catch(F){console.error(F),d("content",{type:"custom",message:F.message})}},q.onabort=()=>console.log("🟨 abort"),q.onerror=()=>{q.error&&(console.error(q.error),d("content",{type:"custom",message:q.error.message}))}},[x]);const[v]=u(["content"]),C=!v,S=(D=l==null?void 0:l.content)==null?void 0:D.message;return f.useEffect(()=>{!v||S?n():t()},[v,S]),s.jsx(a.Box,{mx:"auto",sx:{position:"relative"},children:s.jsxs("form",{onSubmit:o(p),children:[s.jsx(a.FileInput,{label:r("import.json_file"),required:!0,value:x,onChange:m,error:(P=l==null?void 0:l.content)==null?void 0:P.message,sx:{maxWidth:500}}),S?s.jsx(a.Table,{fontSize:12,mt:10,children:s.jsxs("tbody",{children:[s.jsxs("tr",{children:[s.jsx("th",{children:r("import.this_dashboard")}),s.jsx("td",{children:lt})]}),s.jsxs("tr",{children:[s.jsx("th",{children:r("import.this_file")}),s.jsx("td",{style:{color:"red"},children:v==null?void 0:v.version})]})]})}):s.jsxs(s.Fragment,{children:[s.jsx(Q1,{content:v}),s.jsx(a.Group,{position:"right",my:"md",children:s.jsx(a.Button,{type:"submit",color:"green",disabled:C,children:r("common.actions.confirm")})})]})]})})}),wc={height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},Y1=_.observer(()=>{var d;const{t:e}=M.useTranslation(),[t,{open:n,close:r}]=ie.useDisclosure(!1),[i,{setTrue:o,setFalse:l}]=V.useBoolean(!1),u=((d=J().content.views.VIE)==null?void 0:d.type)===B.Tabs;return u?s.jsx(a.Tooltip,{label:e("common.choose_a_tab_first"),children:s.jsx(a.Button,{variant:"outline",color:"gray",radius:0,size:"xs",leftIcon:s.jsx(k.IconFileImport,{size:16}),sx:{...wc,transform:"none !important"},children:e("import.label")})}):s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"subtle",color:"blue",radius:0,size:"xs",disabled:u||t,onClick:n,leftIcon:s.jsx(k.IconFileImport,{size:16}),sx:{...wc},children:e("import.label")}),s.jsx(a.Modal,{opened:t,onClose:r,title:e("import.title"),trapFocus:!0,onDragStart:h=>{h.stopPropagation()},withinPortal:!0,zIndex:320,size:i?"90vw":500,children:s.jsx(K1,{onSuccess:r,stretchModal:o,shrinkModal:l})})]})}),X1={position:"fixed",top:60,left:0,right:0,height:30,zIndex:299,borderBottom:"1px solid #e9ecef",background:"rgba(233,236,239, 0.15)"},J1=_.observer(()=>s.jsx(a.Box,{sx:X1,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(B1,{}),s.jsx(Y1,{})]}),s.jsx($1,{}),s.jsx(a.Group,{position:"right",spacing:0,children:s.jsx(q1,{})})]})})),Z1=_.observer(e=>s.jsxs(s.Fragment,{children:[s.jsx(L1,{...e}),s.jsx(J1,{})]})),KI="";function H1(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:v}=m;switch(x){case"builtin:op:open-link":let C=v.urlTemplate.substring(0,100);v.urlTemplate.length>=20&&(C+="..."),l.type="interaction",l.data.interactions.push({schemaRef:x,urlTemplate:v.urlTemplate,shortURLTemplate:C});return;case"builtin:op:open_view":r.push({id:`OPERATION--${h}`,source:i.id,target:v.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(v.dictionary).map(S=>({key:S,label:n[S]}))});return;case"builtin:op:clear_filter_values":l.type="interaction",l.data.interactions.push({schemaRef:x,filters:v.filter_keys.map(S=>({key:S,label:n[S]}))});return;default:return}})}),r}function ek(e,t){const n=e.filters.keyLabelMap;return{edges:H1(e.panels.list,t,n),edgeNodes:[]}}function Cc(e,t,n){return e*t+e*n}function tk(e,t,n){return e*t+(e-1)*n}const rs=25,li=40,_c=25,ci=350,nk=150,sk=150,Sc=150,kc=300,is=40,Tc=25,rk=300;function ik(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:be.Position.Right,targetPosition:be.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:be.Position.Right,targetPosition:be.Position.Left,style:{width:kc,height:is}})})}),r}const ak={[B.Division]:"Div",[B.Modal]:"Modal",[B.Tabs]:"Tabs"},ok=oc;function lk(e){return e.current.map((n,r)=>{const i=tk(n.panelIDs.length,is,Tc)+li+_c;let o=[];return n.type===B.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:`${ak[n.type]}:${n.name}`},position:{x:0,y:0},sourcePosition:be.Position.Right,targetPosition:be.Position.Left,className:"light",style:{backgroundColor:ok[n.type],width:ci,height:i}}})}function ck(e){const t=y.keyBy(e,n=>n.id);e.forEach(n=>{n._node_type!=="view-root"||n._view_type!==B.Tabs||n._tab_view_ids.forEach(r=>{t[r].parentNode=n.id})})}function uk(e){const t=lk(e.views);ck(t);const n=ik(e.views,e.panels.list);return[...t,...n]}function dk({nodeMap:e,nodes:t,edges:n}){t.forEach(r=>{r._node_type!=="view-root"||r._view_type!==B.Tabs||(r.sourcePosition=be.Position.Bottom,r.style.width=ci+rs*2,r.style.height=_c+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 pk({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 hk({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+rk,c._view_level===0&&l._sub_view_ids.length===0&&(o.sourcePosition=be.Position.Left,l.targetPosition=be.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+Sc}})}function xk({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,sk),l.position.y=0-nk-Sc})}function fk({nodeMap:e,nodes:t,edges:n}){const r={nodeMap:e,nodes:t,edges:n};return xk(r),pk(r),dk(r),hk(r),{nodes:t,edges:n}}function gk(e){const t=uk(e),n=y.keyBy(t,u=>u.id),{edges:r,edgeNodes:i}=ek(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 fk(c)}const YI="",ui={"builtin:op:open-link":s.jsx(a.ThemeIcon,{color:"blue",size:20,radius:"xl",children:s.jsx(k.IconCircleDashed,{size:14})}),"builtin:op:set_filter_values":s.jsx(a.ThemeIcon,{color:"orange",size:20,radius:"xl",children:s.jsx(k.IconCircleDot,{size:14})}),"builtin:op:clear_filter_values":s.jsx(a.ThemeIcon,{color:"orange",size:20,radius:"xl",children:s.jsx(k.IconCircleOff,{size:14})})};function mk(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 yk=f.memo(({data:e,isConnectable:t,sourcePosition:n=be.Position.Right,targetPosition:r=be.Position.Left,...i})=>{const o=f.useMemo(()=>mk(e.interactions),[e.interactions]);return s.jsxs(s.Fragment,{children:[s.jsx(be.Handle,{type:"target",position:r,isConnectable:t}),s.jsx(a.Box,{sx:{position:"absolute",top:0,right:0},children:s.jsx(T.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(be.Handle,{type:"source",position:n,isConnectable:t})]})}),XI="",bk={interaction:yk},vk=_.observer(()=>{const e=ue(),{edges:t,nodes:n}=gk(e);return s.jsxs(be,{nodes:n,edges:t,onNodesChange:y.noop,onEdgesChange:y.noop,onConnect:y.noop,className:"interactions-viewer",fitView:!0,nodeTypes:bk,children:[s.jsx(be.MiniMap,{}),s.jsx(be.Controls,{}),s.jsx(be.Background,{})]})}),jk=_.observer(({opened:e,close:t})=>{const{t:n}=M.useTranslation();return s.jsx(a.Modal,{size:"96vw",opened:e,onClose:t,title:n("interactions.interactions_viewer"),trapFocus:!0,onDragStart:r=>{r.stopPropagation()},styles:{body:{height:"calc(90vh - 54px)"},content:{transform:"none !important"}},zIndex:300,children:s.jsx(vk,{})})}),wk={"> 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 Ck({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(k.IconAdjustments,{size:16})})})]})}const _k=_.observer(()=>{const{t:e}=M.useTranslation(),t=J(),n=Q(),r=f.useCallback(o=>()=>n.views.setIDOfVIE(o),[n]),i=o=>{t.editor.open(["_VIEWS_",o])};return s.jsxs(a.Box,{sx:{position:"relative"},children:[n.views.options.map(o=>s.jsx(Ck,{active:n.views.idOfVIE===o.value,name:o.label,onClick:r(o.value),openSettings:()=>i(o.value)},o.value)),s.jsx(a.Divider,{variant:"dashed"}),s.jsx(a.Button,{variant:"subtle",rightIcon:s.jsx(k.IconPlus,{size:14}),size:"sm",px:"xs",color:"blue",onClick:n.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"space-between"}},children:e("view.add")})]})}),Sk=_.observer(()=>{const{t:e}=M.useTranslation(),t=J(),n=Q(),r=()=>{if(!n.queries.firstID){t.editor.open(["_QUERIES_",""]);return}t.editor.open(["_QUERIES_",n.queries.firstID])},i=()=>{if(!n.filters.firstID){t.editor.open(["_FILTERS_",""]);return}t.editor.open(["_FILTERS_",n.filters.firstID])},[o,l]=f.useState(!1),c=()=>l(!0),u=()=>l(!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:{...wk,button:{borderWidth:0,borderBottomWidth:1,borderColor:"#e9ecef"}},children:[s.jsx(a.Tooltip,{label:e("filter.labels"),withinPortal:!0,children:s.jsx(a.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:i,children:s.jsx(k.IconFilter,{size:18})})}),s.jsx(a.Tooltip,{label:e("query.labels"),withinPortal:!0,children:s.jsx(a.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:r,children:s.jsx(k.IconDatabase,{size:18})})}),s.jsx(a.Tooltip,{label:e("interactions.interactions_viewer"),withinPortal:!0,children:s.jsx(a.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:c,children:s.jsx(k.IconLink,{size:18})})})]}),s.jsx(jk,{opened:o,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:e("view.labels")})}),s.jsx(a.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:s.jsx(_k,{})}),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(k.IconSettings,{size:20}),onClick:()=>t.editor.open([]),children:e("common.titles.settings")})})})]})}),kk=["function getDefaultValue(filter, utils, context) {",' return "";',"}"].join(`
|
|
454
|
+
`),Gt=_.observer(({filter:e})=>s.jsx(ho,{label:"",title:"Custom Default Value",triggerLabel:"Default by function",value:e.default_value_func,onChange:e.setDefaultValueFunc,defaultValue:kk,triggerButtonProps:{size:"xs",color:"grape",sx:{flexGrow:0,alignSelf:"flex-start"},leftIcon:s.jsx(k.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"})]})})})),Tk=_.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(ur,{label:"Description",value:n.description,onChange:n.setDescription,styles:{root:{flexGrow:1,minHeight:"400px"}}})]})}),Dk=[{label:"2022",value:"YYYY"},{label:"202201",value:"YYYYMM"},{label:"20220101",value:"YYYYMMDD"},{label:"2022-01",value:"YYYY-MM"},{label:"2022-01-01",value:"YYYY-MM-DD"}],Ik=_.observer(function({filter:t}){const n=t.config,r=f.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:Dk,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(Gt,{filter:t})]})}),di=_.observer(({value:e,onChange:t})=>{const{t:n}=M.useTranslation(),r=J(),i=Q(),o=f.useMemo(()=>i.queries.options,[i.queries.current]),l=o.length===0,c=u=>{r.editor.setPath(["_QUERIES_",u])};return s.jsx(a.Select,{label:s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Text,{children:n("filter.widget.common.use_query_data_as_options")}),e&&s.jsx(a.Button,{size:"xs",leftIcon:s.jsx(k.IconArrowCurveRight,{size:16}),variant:"subtle",color:"blue",onClick:()=>c(e),children:n("query.open")})]}),data:o,value:e,onChange:t,allowDeselect:!1,clearable:!0,sx:{flexGrow:1},disabled:l,error:l?"You need to add a query in Data Settings":void 0,styles:{label:{display:"block"}}})}),Mk=`
|
|
455
455
|
// row
|
|
456
456
|
{
|
|
457
457
|
label: string;
|
|
458
458
|
value: string;
|
|
459
459
|
description?: string; // optional
|
|
460
460
|
}
|
|
461
|
-
`,Dc=()=>{const[e,t]=
|
|
461
|
+
`,Dc=()=>{const[e,t]=f.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(ht.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:Mk})})]})},zk=_.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,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(T.Trash,{size:16})})]},c)),s.jsx(a.Button,{mt:10,size:"xs",color:"blue",leftIcon:s.jsx(T.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,{})]})}),Ak=_.observer(function({filter:t}){const{t:n,i18n:r}=M.useTranslation(),i=t.config,o=()=>{i.addStaticOption({label:"",value:""})},l=i.static_options,c=f.useMemo(()=>[{label:n("filter.widget.select.no_default_selection"),value:""},...l],[r.language,l]);return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Checkbox,{checked:i.required,onChange:u=>i.setRequired(u.currentTarget.checked),label:n("filter.widget.select.required")}),s.jsx(Gt,{filter:t})]}),s.jsx(a.TextInput,{label:n("filter.widget.select.width"),value:i.width,onChange:u=>i.setWidth(u.currentTarget.value),placeholder:"200px"}),s.jsx(a.Divider,{label:n("filter.widget.select.configure_options"),labelPosition:"center"}),s.jsxs(a.Stack,{spacing:10,sx:{position:"relative",minHeight:"50px"},children:[i.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"})})]}),l.length>0&&s.jsx(a.Select,{label:n("filter.widget.select.default_selection"),data:c,value:i.default_value,onChange:i.setDefaultValue}),l.map((u,d)=>s.jsxs(a.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[s.jsx(a.TextInput,{label:n("common.label"),required:!0,value:i.static_options[d].label,onChange:h=>{i.static_options[d].setLabel(h.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(a.TextInput,{label:n("common.value"),required:!0,value:i.static_options[d].value,onChange:h=>{i.static_options[d].setValue(h.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(a.ActionIcon,{color:"red",variant:"subtle",onClick:()=>i.removeStaticOption(d),sx:{position:"absolute",top:28,right:5},children:s.jsx(T.Trash,{size:16})})]},d)),s.jsx(a.Button,{size:"xs",color:"blue",leftIcon:s.jsx(T.PlaylistAdd,{size:20}),onClick:o,sx:{width:"50%"},mx:"auto",children:n("common.actions.add_an_option")})]}),s.jsx(a.Divider,{label:n("filter.widget.common.or_fetch_options_from_datasource"),labelPosition:"center"}),s.jsx(a.Checkbox,{checked:i.default_selection_count===1,onChange:u=>i.setDefaultSelectionCount(u.currentTarget.checked?1:0),label:n("filter.widget.select.select_first_option_by_default")}),s.jsx(di,{value:i.options_query_id,onChange:i.setOptionsQueryID}),s.jsx(Dc,{})]})}),Ek=_.observer(function({filter:t}){const{t:n}=M.useTranslation(),r=t.config;return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{children:[s.jsx(a.TextInput,{label:n("filter.widget.text_input.default_value"),value:r.default_value,onChange:i=>{r.setDefaultValue(i.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(a.Box,{mt:22,children:s.jsx(Gt,{filter:t})})]}),s.jsx(a.Checkbox,{checked:r.required,onChange:i=>r.setRequired(i.currentTarget.checked),label:n("filter.widget.text_input.required")})]})}),Pk=`
|
|
462
462
|
// row
|
|
463
463
|
{
|
|
464
464
|
label: string;
|
|
@@ -466,7 +466,7 @@ Check the top-level render call using <`+E+">.")}return I}}function iu(w,I){{if(
|
|
|
466
466
|
parent_value: string;
|
|
467
467
|
description?: string;
|
|
468
468
|
}
|
|
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=`
|
|
469
|
+
`,Lk=()=>{const[e,t]=f.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(ht.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:Pk})})]})},Bk=_.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(di,{value:n.options_query_id,onChange:n.setOptionsQueryID}),s.jsx(Lk,{})]})}),Ok=_.observer(function({filter:t}){const{t:n}=M.useTranslation();return s.jsxs(a.Box,{sx:{maxWidth:"480px"},children:[s.jsx(a.Text,{pt:"0",pb:"md",color:"gray",children:n("common.titles.config")}),s.jsx(ht.Prism,{mt:22,language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(t,null,4)})]})}),$k={select:Ak,"multi-select":zk,"tree-select":Bk,"text-input":Ek,checkbox:Tk,"date-range":Ik},Dt={select:"filter.widget.names.select","multi-select":"filter.widget.names.multi_select","tree-select":"filter.widget.names.tree_select","text-input":"filter.widget.names.text_input",checkbox:"filter.widget.names.checkbox","date-range":"filter.widget.names.date_range"},qk=_.observer(function({filter:t}){const{t:n,i18n:r}=M.useTranslation(),i=Q(),o=f.useMemo(()=>$k[t.type],[t.type]),l=f.useMemo(()=>[{label:n(Dt.select),value:"select"},{label:n(Dt["multi-select"]),value:"multi-select"},{label:n(Dt["tree-select"]),value:"tree-select"},{label:n(Dt["text-input"]),value:"text-input"},{label:n(Dt.checkbox),value:"checkbox"},{label:n(Dt["date-range"]),value:"date-range"}],[r.language]);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:n("common.titles.edit")}),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{noWrap:!0,children:[s.jsx(a.NumberInput,{label:n("filter.field.order"),required:!0,value:t.order,onChange:t.setOrder,hideControls:!0,sx:{flexGrow:"1 !important"}}),t.auto_submit_supported&&s.jsx(a.Checkbox,{label:n("filter.field.auto_submit"),checked:t.auto_submit,onChange:c=>t.setAutoSubmit(c.currentTarget.checked),mt:22})]}),s.jsx(a.MultiSelect,{label:n("filter.field.visible_in"),data:i.views.options,value:[...t.visibleInViewsIDs],onChange:t.setVisibleInViewsIDs}),s.jsx(a.TextInput,{label:n("common.key"),placeholder:n("filter.field.key_placeholder"),required:!0,value:t.key,onChange:c=>{t.setKey(c.currentTarget.value)}}),s.jsx(a.TextInput,{label:n("common.label"),placeholder:n("filter.field.label_placeholder"),required:!0,value:t.label,onChange:c=>{t.setLabel(c.currentTarget.value)}}),s.jsx(a.Select,{label:n("filter.field.widget"),data:l,required:!0,value:t.type,onChange:t.setType,maxDropdownHeight:500}),s.jsx(a.Divider,{mb:0,mt:10,variant:"dashed",labelPosition:"center"}),s.jsx(o,{filter:t})]})]}),s.jsx(Ok,{filter:t})]})}),Vk=_.observer(({id:e})=>{const{t}=M.useTranslation(),n=Ee.useModals(),r=J(),i=Q();if(e==="")return null;const o=i.filters.findByID(e);if(!o)return s.jsxs(a.Text,{size:14,children:["Filter by ID[",e,"] is not found"]});const l=()=>{r.editor.setPath(["_FILTERS_",""])},c=()=>{n.openConfirmModal({title:`${t("filter.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.filters.removeByID(e),l()},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(T.Trash,{size:16}),onClick:c,children:t("filter.delete")})}),s.jsx(a.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:s.jsx(qk,{filter:o})})]})}),Nk=_.observer(()=>{const{t:e}=M.useTranslation(),[t,n]=f.useState([]),r=J(),i=d=>{r.editor.setPath(["_FILTERS_",d])},o=()=>{r.content.filters.downloadSchema(t)},l=f.useMemo(()=>r.content.filters.sortedList.map(d=>d.id),[r.content.filters.sortedList]),c=()=>{n(l)},u=()=>{n([])};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:e("filter.manage")})}),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:c,children:e("common.actions.select_all")}),s.jsx(a.Button,{variant:"default",size:"xs",onClick:u,children:e("common.actions.clear_selection")})]}),s.jsx(a.Button,{size:"xs",color:"blue",leftIcon:s.jsx(k.IconCode,{size:14}),disabled:t.length===0,onClick:o,children:e("common.actions.download_schema")})]})}),s.jsx(a.Box,{sx:{flexGrow:1,overflow:"auto"},children:s.jsx(a.Checkbox.Group,{size:"xs",value:t,onChange:n,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:e("common.label")}),s.jsx("th",{children:e("common.key")}),s.jsx("th",{style:{width:"100px"},children:e("filter.field.widget")}),s.jsx("th",{style:{width:"300px",paddingLeft:"24px"},children:e("common.action")})]})}),s.jsx("tbody",{children:r.content.filters.sortedList.map(d=>s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx(a.Checkbox,{value:d.id,styles:{input:{cursor:"pointer"}}})}),s.jsx("td",{children:d.label}),s.jsx("td",{children:d.key}),s.jsx("td",{children:Dt[d.type]}),s.jsx("td",{children:s.jsx(a.Button,{variant:"subtle",size:"xs",onClick:()=>i(d.id),children:e("common.actions.open")})})]},d.id))})]})})})]})}),Fk=_.observer(()=>{const{t:e}=M.useTranslation(),t=Q(),[n,r]=f.useState(()=>JSON.stringify(t.mock_context.current,null,4)),i=()=>{try{t.mock_context.replace(JSON.parse(n))}catch(l){pt.showNotification({title:"Failed",message:l.message,color:"red"})}},o=f.useMemo(()=>{try{return JSON.stringify(JSON.parse(n))!==JSON.stringify(t.mock_context.current)}catch{return!1}},[n,t.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:e("mock_context.label")})}),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:e("mock_context.hint")}),s.jsx(a.JsonInput,{validationError:"Invalid json",formatOnBlur:!0,autosize:!0,minRows:30,value:n,onChange:r,sx:{flexGrow:1}})]}),s.jsx(a.ActionIcon,{mr:5,variant:"filled",color:"blue",sx:{position:"absolute",right:12,top:0},disabled:!o,onClick:i,children:s.jsx(T.DeviceFloppy,{size:20})})]})]})}),Gk=_.observer(()=>{const{t:e}=M.useTranslation(),{panel:t}=Le();return s.jsx(ur,{label:e("panel.panel_description"),value:t.description,onChange:t.setDescription,styles:{root:{flexGrow:1}}})}),Wk=_.observer(()=>{const{t:e}=M.useTranslation(),{panel:t}=Le(),n=ue().layouts.findItemByPanelID(t.id),{style:r}=t;return s.jsxs(s.Fragment,{children:[s.jsx(a.Divider,{mb:-10,label:e("panel.style.label"),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:e("panel.style.width"),min:1,max:36,step:1,precision:0,rightSection:s.jsx(a.Text,{size:12,children:e("panel.style.width_postfix")}),styles:{rightSection:{width:"110px"}},value:n.w,onChange:i=>{i&&n.setWidth(i)}}),s.jsx(a.NumberInput,{label:e("panel.style.height"),rightSection:s.jsx(a.Text,{size:12,children:e("panel.style.height_postfix")}),styles:{rightSection:{width:"40px"}},value:n.h,onChange:i=>{i&&n.setHeight(i)}})]}),s.jsx(a.Checkbox,{ml:6,label:e("panel.style.border"),checked:r.border.enabled,onChange:i=>r.border.setEnabled(i.currentTarget.checked)})]})]})}),Rk=()=>s.jsxs("span",{className:"mantine-103svbs mantine-InputWrapper-required mantine-Select-required","aria-hidden":"true",children:[" ","*"]}),Qk=_.observer(()=>{const{t:e}=M.useTranslation(),{panel:t}=Le(),{name:n}=t,[r,i]=ie.useInputState(n),o=n!==r,l=f.useCallback(()=>{o&&t.setName(r)},[o,r]);f.useEffect(()=>{i(n)},[n]);const c=!r.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:[e("panel.panel_name"),s.jsx(Rk,{})]}),s.jsx(a.ActionIcon,{variant:"subtle",color:"blue",disabled:!o||c,onClick:l,children:s.jsx(k.IconDeviceFloppy,{size:18})})]}),s.jsx(a.TextInput,{value:r,onChange:i,required:!0})]})}),Uk=_.observer(()=>{const{t:e}=M.useTranslation(),{panel:t}=Le();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:t.title.show,onChange:n=>t.title.setShow(n.currentTarget.checked),label:e("panel.show_title"),sx:{userSelect:"none"}}),s.jsx(a.Checkbox,{size:"sm",checked:!0,disabled:!0,label:e("panel.use_name_as_title")})]})})});function Kk(){const{t:e}=M.useTranslation();return s.jsxs(a.Stack,{sx:{height:"100%"},children:[s.jsx(Wk,{}),s.jsx(a.Divider,{label:e("common.info"),labelPosition:"center",variant:"dashed"}),s.jsx(Qk,{}),s.jsx(Uk,{}),s.jsx(Gk,{})]})}const Yk={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=f.useMemo(()=>{if(!Array.isArray(e)||e.length===0)return[];const r=We.createColumnHelper();return Object.keys(e[0]).map(i=>r.accessor(i,{cell:o=>o.getValue()}))},[e]),n=We.useReactTable({data:e,columns:t,columnResizeMode:"onChange",getCoreRowModel:We.getCoreRowModel()});return e.length===0?s.jsx(a.Box,{sx:{height:"5em"}}):s.jsx(je,{children:s.jsxs(a.Table,{sx:Yk,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:We.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(T.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:We.flexRender(i.column.columnDef.cell,i.getContext())})},i.id))},r.id))})]})})}const Xk=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],Jk={icon:{width:"80px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"80px"}}},Zk=({data:e,page:t,setPage:n,limit:r,setLimit:i})=>{const{t:o}=M.useTranslation(),l=e.length,c=Math.ceil(l/r),u=h=>{n(1),i(Number(h))};if(l===0)return null;const d=c===1&&l<=10;return s.jsxs(a.Group,{pt:10,px:10,position:"apart",children:[s.jsxs(a.Group,{position:"left",children:[c>1&&s.jsx(a.Pagination,{size:"sm",value:t,onChange:n,total:c,withEdges:c>7,styles:{control:{height:"30px"}}}),!d&&s.jsx(a.Select,{icon:s.jsx(a.Text,{ta:"center",color:"dimmed",size:14,children:o("common.pagination.page_size")}),size:"xs",styles:Jk,data:Xk,value:String(r),onChange:u})]}),s.jsx(a.Group,{position:"right",children:s.jsx(a.Text,{color:"dimmed",my:0,size:14,children:o("common.pagination.total_rows",{total:l})})})]})},Hk=Sd(({data:e,loading:t})=>{const[n,r]=f.useState(1),[i,o]=f.useState(20),l=f.useMemo(()=>{const c=(n-1)*i,u=c+i;return e.slice(c,u)},[e,n,i]);return s.jsxs(je,{children:[s.jsx(Zk,{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})]})]})}),eT=({queryID:e})=>{const t=ue(),{state:n,error:r}=t.getDataStuffByID(e),i=f.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=_.observer(({id:e,moreActions:t,refreshOnMount:n})=>{const{t:r}=M.useTranslation(),i=ue(),{data:o,state:l}=i.getDataStuffByID(e),c=l==="loading",u=f.useCallback(()=>{i.queries.refetchDataByQueryID(e)},[e,i]),d=()=>{i.queries.downloadDataByQueryID(e)};f.useEffect(()=>{n&&u()},[u,n]);const h=!Array.isArray(o)||o.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:r("data.preview_data")})}),s.jsxs(a.Group,{pr:15,children:[t,s.jsx(a.ActionIcon,{variant:"subtle",color:"blue",disabled:c,onClick:u,children:s.jsx(T.Refresh,{size:16})}),s.jsx(a.ActionIcon,{variant:"subtle",color:"blue",disabled:c||h,onClick:d,children:s.jsx(T.Download,{size:16})})]})]}),s.jsxs(a.Box,{pb:20,sx:{position:"relative",flexGrow:1,overflow:"auto"},children:[s.jsx(eT,{queryID:e}),s.jsx(Hk,{data:o,loading:c})]})]})}),tT=_.observer(function(){const{t}=M.useTranslation(),n=J(),r=Q(),{panel:i}=Le(),[o,l]=f.useState(!1),c=u=>{n.editor.setPath(["_QUERIES_",u])};return s.jsxs(s.Fragment,{children:[s.jsx(a.Drawer,{opened:o,onClose:()=>l(!1),title:t("panel.settings.choose_queries"),padding:"xl",size:500,zIndex:320,children:s.jsx(a.Checkbox.Group,{value:[...i.queryIDs],onChange:i.setQueryIDs,children:s.jsx(a.Stack,{spacing:"lg",children:r.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(k.IconLine,{size:16}),onClick:()=>l(!0),children:t("panel.settings.choose_queries")})}),i.queryIDs.length===1&&s.jsx(pi,{id:i.queryIDs[0],moreActions:s.jsx(a.Tooltip,{label:t("query.open"),children:s.jsx(a.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>c(i.queryIDs[0]),children:s.jsx(k.IconArrowCurveRight,{size:16})})})}),i.queryIDs.length>1&&s.jsxs(a.Tabs,{defaultValue:i.queryIDs[0],children:[s.jsx(a.Tabs.List,{children:i.queries.map(u=>s.jsx(a.Tabs.Tab,{value:u.id,children:u.name},u.id))}),i.queries.map(u=>s.jsx(a.Tabs.Panel,{value:u.id,children:s.jsx(pi,{id:u.id,moreActions:s.jsx(a.Tooltip,{label:t("query.open"),children:s.jsx(a.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>c(u.id),children:s.jsx(k.IconArrowCurveRight,{size:16})})})})},u.id))]})]})]})}),nT=_.observer(()=>{const{panel:e}=gt();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 sT{constructor(t){L(this,"panel");L(this,"selected");this.panel=t,t.variables.length>0&&(this.selected=t.variables[0]),Y.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 rT(){const{panel:e}=Le();return V.useCreation(()=>new sT(e),[e])}function iT({label:e,value:t,onChange:n},r){const[i,o]=f.useState(Array.isArray(t)?[...t]:[]),l=f.useCallback(()=>{o(x=>[...x,""])},[o]),c=f.useCallback(x=>{o(m=>(m.splice(x,1),[...m]))},[o]),u=f.useMemo(()=>!y.isEqual(i,t),[i,t]),d=()=>{n(i.map(x=>x.toString()))},h=a.useMantineTheme(),p=f.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(T.DeviceFloppy,{size:20})})]}),s.jsxs(a.Group,{children:[i.map((x,m)=>s.jsx(a.ColorInput,{value:x,onChange:v=>{o(C=>(C.splice(m,1,v),[...C]))},swatches:p,rightSection:s.jsx(a.ActionIcon,{onClick:()=>c(m),color:"red",children:s.jsx(T.Trash,{size:14})}),sx:{width:"45%"}})),s.jsx(a.ActionIcon,{onClick:l,color:"blue",variant:"outline",children:s.jsx(T.PlaylistAdd,{size:20})})]})]})}const aT=f.forwardRef(iT);function oT({label:e,value:t,onChange:n,type:r},i){const[o,l]=f.useState(Array.isArray(t)?[...t]:[]),c=f.useCallback(()=>{l(p=>[...p,""])},[l]),u=f.useCallback(p=>{l(x=>(x.splice(p,1),[...x]))},[l]),d=f.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(T.DeviceFloppy,{size:20})})]}),s.jsxs(a.Group,{children:[o.map((p,x)=>s.jsx(a.TextInput,{type:r,value:p,onChange:m=>{const v=m.currentTarget.value;l(C=>(C.splice(x,1,v),[...C]))},rightSection:s.jsx(a.ActionIcon,{onClick:()=>u(x),color:"red",children:s.jsx(T.Trash,{size:14})}),sx:{width:"45%"}})),s.jsx(a.ActionIcon,{onClick:c,color:"blue",variant:"outline",children:s.jsx(T.PlaylistAdd,{size:20})})]})]})}const lT=f.forwardRef(oT),cT=f.forwardRef(function({value:t,onChange:n},r){const{t:i}=M.useTranslation(),o=t.color.type,l=(u,d)=>{const h=y.cloneDeep(t);y.set(h,u,d),n(h)},c=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:i("panel.variable.styles.font_size.label"),placeholder:i("panel.variable.styles.font_size.placeholder"),sx:{flex:1},value:t.size,onChange:u=>l("size",u.currentTarget.value)})}),s.jsx(a.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:s.jsx(Uo,{label:i("panel.variable.styles.font_weight.label"),value:t.weight,onChange:u=>l("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:c}),o==="static"&&s.jsx(_e,{value:t.color.staticColor,onChange:u=>l("color.staticColor",u)}),o==="continuous"&&s.jsxs(s.Fragment,{children:[s.jsx(lT,{label:"Value Range",value:t.color.valueRange,type:"number",onChange:u=>l("color.valueRange",u)}),s.jsx(aT,{label:"Color Range",value:t.color.colorRange,onChange:u=>l("color.colorRange",u)})]})]})]})}),uT=f.forwardRef(function({value:t,onChange:n,withStyle:r=!0,remove:i},o){const{t:l}=M.useTranslation(),c=(u,d)=>{const h=y.cloneDeep(t);y.set(h,u,d),n(h)};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:l("common.name"),required:!0,value:t.name,onChange:u=>c("name",u.currentTarget.value)}),s.jsx(O,{label:l("common.data_field"),required:!0,value:t.data_field,onChange:u=>c("data_field",u)})]}),s.jsx(sr,{label:l("panel.variable.aggregation.label"),pt:0,value:t.aggregation,onChange:u=>c("aggregation",u),withFallback:!0}),t.aggregation.type!=="custom"&&s.jsxs(s.Fragment,{children:[s.jsx(a.Divider,{mt:"xl",mb:0,label:l("numbro.format.label"),labelPosition:"center",variant:"dashed"}),s.jsx(Ne,{value:t.formatter,onChange:u=>c("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:l("panel.variable.styles.label")}),s.jsx(a.Accordion.Panel,{children:s.jsx(cT,{value:t,onChange:n})})]})}),s.jsx(a.Button,{mt:20,leftIcon:s.jsx(k.IconTrash,{size:16}),color:"red",variant:"light",onClick:i,children:l("panel.variable.delete")})]})}),dT=_.observer(e=>{const{t}=M.useTranslation(),n=V.useCreation(()=>Rl(e.variable),[e.variable]),r=()=>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:!n.changed,color:"red",onClick:n.reset,leftIcon:s.jsx(k.IconRecycle,{size:18}),children:t("common.actions.revert_changes")}),s.jsx(a.Button,{variant:"filled",size:"xs",disabled:!n.changed,color:"green",onClick:n.commit,leftIcon:s.jsx(k.IconDeviceFloppy,{size:18}),children:t("common.actions.save_changes")})]}),s.jsx(uT,{value:g.getSnapshot(n.copy),onChange:n.update,remove:r})]})});_.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 pT=_.observer(({model:e})=>{const{t}=M.useTranslation();return s.jsx(a.Overlay,{color:"#fff",opacity:1,sx:{position:"absolute"},children:s.jsx(a.Button,{variant:"light",size:"xs",leftIcon:s.jsx(k.IconPlus,{size:16}),onClick:e.addNew,sx:{flexGrow:0,flexShrink:0,alignSelf:"flex-end",height:"38px"},children:t("panel.variable.add")})})}),hT=_.observer(()=>{var n;const{t:e}=M.useTranslation(),t=rT();return t.variableOptions.length===0?s.jsx(pT,{model:t}):s.jsxs(a.Stack,{pb:20,children:[s.jsxs(a.Group,{position:"left",children:[s.jsx(a.Select,{label:e("panel.variable.labels"),data:t.variableOptions,value:(n=t.selected)==null?void 0:n.name,onChange:t.selectByName,maxDropdownHeight:600,sx:{flexGrow:1}}),s.jsx(a.Button,{variant:"light",size:"xs",leftIcon:s.jsx(k.IconPlus,{size:16}),onClick:t.addNew,sx:{flexGrow:0,flexShrink:0,alignSelf:"flex-end",height:"38px"},children:e("panel.variable.add")})]}),s.jsx(a.Divider,{variant:"dashed"}),t.selected?s.jsx(dT,{uiModel:t,variable:t.selected}):s.jsx("span",{children:"Select or create a new variable on right side"})]})}),xT=_.observer(()=>{const{panel:e}=Le();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(ht.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(e.variableStrings,null,4)})]})});function fT(){const{vizManager:e}=f.useContext(tt);return f.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 gT=_.observer(({value:e,submit:t})=>{const{t:n}=M.useTranslation(),[r,i]=ie.useInputState(e);f.useEffect(()=>{i(e)},[e]);const o=fT(),l=e!==r;return s.jsx(a.Select,{label:n("visualization.component"),value:r,searchable:!0,onChange:i,data:o,rightSection:s.jsx(a.ActionIcon,{disabled:!l,onClick:()=>t(r),children:s.jsx(T.DeviceFloppy,{size:20})}),maxDropdownHeight:600})}),Mc=[];function mT(e,t){try{return e.resolveComponent(t).createConfig()}catch{return null}}function yT(){const{data:e,panel:{variables:t,viz:n,title:r,name:i,queryIDs:o,description:l,id:c}}=Le(),{vizManager:u}=f.useContext(tt),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(Jn,{configure:h,children:s.jsx(QS,{variables:t,setVizConf:n.setConf,panel:d,vizManager:u,data:e})})}catch(p){return console.info(y.get(p,"message")),null}}const bT=_.observer(()=>{const{data:e,panel:{viz:t}}=Le(),{vizManager:n}=f.useContext(tt),r=f.useCallback(d=>{if(d===t.type)return;const h=mT(n,d);t.setType(d),t.setConf(h||{})},[t.type]),i=d=>{try{t.setConf(JSON.parse(d))}catch(h){console.error(h)}},o=f.useMemo(()=>{var d;return(d=Mc.find(h=>h.value===t.type))==null?void 0:d.Panel},[t.type,Mc]),l=yT(),c=o?f.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(gT,{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})]})]})}),vT=_.observer(({panel:e,sourceViewID:t})=>{const{t:n}=M.useTranslation(),r=Q(),[i,o]=f.useState(t);f.useEffect(()=>{o(t)},[t]);const[l,{open:c,close:u}]=ie.useDisclosure(!1),d=()=>{e.moveToView(t,i),u()};return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{size:"xs",variant:"subtle",color:"blue",onClick:c,leftIcon:s.jsx(k.IconBoxMultiple,{size:14}),children:n("panel.settings.change_view")}),s.jsx(a.Modal,{opened:l,onClose:u,title:n("panel.settings.change_view_title"),zIndex:320,children:s.jsxs(a.Stack,{sx:{maxHeight:"calc(100vh - 185px)",overflow:"hidden"},children:[s.jsx(a.Radio.Group,{value:i,onChange:o,pb:10,sx:{flexGrow:1,maxHeight:"calc(100vh - 185px - 30px)",overflow:"auto"},children:s.jsx(a.Stack,{spacing:"xs",children:r.views.options.map(h=>s.jsx(a.Radio,{value:h.value,label:h.label},h.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(k.IconX,{size:14}),onClick:u,children:n("common.actions.cancel")}),s.jsx(a.Button,{size:"xs",color:"blue",leftIcon:s.jsx(k.IconDeviceFloppy,{size:14}),onClick:d,disabled:i===t,children:n("common.actions.confirm")})]})]})})]})}),jT={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(nT,{}),s.jsx(a.Box,{sx:{flexGrow:1},children:s.jsx(xT,{})})]})]});function wT(e){return!["richText","button"].includes(e)}const CT=_.observer(({panel:e})=>{const{t}=M.useTranslation(),n=Ee.useModals(),r=J(),i=Q(),[o,l]=f.useState("Data"),c=e.queries,d=wT(e.viz.type)&&e.dataLoading,h=d||e.queryErrors.length>0||e.queryStateMessages!==""||c.length===0,p=r.editor.path[1];f.useEffect(()=>{l(v=>h&&v==="Visualization"?"Data":v)},[e.id,h]);const x=()=>{r.editor.setPath(["_VIEWS_",p])},m=()=>n.openConfirmModal({title:`${t("panel.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.removePanelByID(e.id,p),x()},confirmProps:{color:"red"},zIndex:320});return s.jsxs(Ts,{value:{panel:e,data:e.data,loading:d,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(vT,{panel:e,sourceViewID:p}),s.jsx(a.Button,{size:"xs",variant:"subtle",color:"red",onClick:m,leftIcon:s.jsx(k.IconTrash,{size:14}),children:t("panel.delete")})]})]}),s.jsxs(a.Tabs,{value:o,onTabChange:l,keepMounted:!1,styles:jT,children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"Data",disabled:d,children:t("data.label")}),s.jsx(a.Tabs.Tab,{value:"Panel",children:t("panel.label")}),s.jsx(a.Tabs.Tab,{value:"Variables",disabled:h,children:s.jsx(a.Tooltip,{label:"Requires data",disabled:!h,withinPortal:!0,zIndex:310,children:s.jsx(a.Text,{children:t("panel.variable.labels")})})}),s.jsx(a.Tabs.Tab,{value:"Visualization",disabled:h,children:s.jsx(a.Tooltip,{label:"Requires data",disabled:!h,withinPortal:!0,zIndex:310,children:s.jsx(a.Text,{children:t("visualization.label")})})}),s.jsx(a.Tabs.Tab,{value:"Interactions",children:t("interactions.label")})]}),s.jsxs(a.Tabs.Panel,{value:"Data",children:[s.jsx(a.LoadingOverlay,{visible:d,exitTransitionDuration:0}),s.jsx(tT,{})]}),s.jsx(a.Tabs.Panel,{value:"Panel",children:s.jsx(xi,{children:s.jsx(Kk,{})})}),s.jsx(a.Tabs.Panel,{value:"Variables",children:s.jsx(xi,{children:s.jsx(hT,{})})}),s.jsx(a.Tabs.Panel,{value:"Visualization",children:s.jsx(je,{children:s.jsx(xi,{children:s.jsx(bT,{})})})}),s.jsx(a.Tabs.Panel,{value:"Interactions",children:s.jsx(je,{children:s.jsx(Rp,{})})})]})]})}),_T=_.observer(({viewID:e,panelID:t})=>{const n=Q();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(CT,{panel:i}):s.jsxs(a.Text,{size:14,children:["Panel by ID[",t,"] is not found"]})}),ST=_.observer(()=>{const{t:e}=M.useTranslation(),[t,n]=f.useState([]),r=Ee.useModals(),i=J(),o=x=>{i.editor.setPath(["_QUERIES_",x])},l=()=>{r.openConfirmModal({title:"Delete ununsed queries?",children:s.jsx(a.Text,{size:"sm",children:"This action cannot be undone."}),labels:{confirm:e("common.actions.confirm"),cancel:e("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>i.content.removeUnusedQueries(),confirmProps:{color:"red"},zIndex:320})},c=()=>{i.content.queries.downloadSchema(t)},u=f.useMemo(()=>i.content.queries.sortedList.map(x=>x.id),[i.content.queries.sortedList]),d=()=>{n(u)},h=()=>{n([])},p=i.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:e("query.manage")})}),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:d,children:e("common.actions.select_all")}),s.jsx(a.Button,{variant:"default",size:"xs",onClick:h,children:e("common.actions.clear_selection")})]}),s.jsx(a.Button,{size:"xs",color:"blue",leftIcon:s.jsx(k.IconCode,{size:14}),disabled:t.length===0,onClick:c,children:e("common.actions.download_schema")})]}),s.jsx(a.Button,{variant:"subtle",size:"xs",color:"red",leftIcon:s.jsx(k.IconTrash,{size:14}),disabled:!i.content.hasUnusedQueries,onClick:l,children:e("query.delete_unused")})]}),s.jsx(a.Box,{sx:{flexGrow:1,overflow:"auto"},children:s.jsx(a.Checkbox.Group,{size:"xs",value:t,onChange:n,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:e("common.name")}),s.jsx("th",{style:{width:"200px"},children:e("data_source.label")}),s.jsx("th",{style:{width:"100px",textAlign:"right"},children:e("common.type")}),s.jsx("th",{style:{width:"100px",textAlign:"center"},children:e("query.usage.label")}),s.jsx("th",{style:{width:"300px",paddingLeft:"24px"},children:e("common.action")})]})}),s.jsx("tbody",{children:i.content.queries.sortedList.map(x=>{var v;const m=((v=p[x.id])==null?void 0:v.length)??0;return s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx(a.Checkbox,{value:x.id,styles:{input:{cursor:"pointer"}}})}),s.jsx("td",{children:x.name}),s.jsx("td",{children:x.key}),s.jsx("td",{style:{textAlign:"right"},children:x.type}),s.jsx("td",{style:{color:m===0?"#ff0000":"#000",fontWeight:m===0?"bold":"normal",textAlign:"center"},children:m}),s.jsx("td",{children:s.jsx(a.Button,{variant:"subtle",size:"xs",onClick:()=>o(x.id),children:e("common.actions.open")})})]},x.id)})})]})})})]})}),kT=e=>{const{t}=M.useTranslation(),{queryModel:n}=e,r=J(),i=Q(),l=i.findQueryUsage(n.id).length>0,c=Ee.useModals(),u=()=>{c.openConfirmModal({title:`${t("query.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.queries.removeQuery(n.id),r.editor.setPath(["_QUERIES_",""])},confirmProps:{color:"red"},zIndex:320})};return l?s.jsx(a.Tooltip,{label:t("query.cant_delete"),withArrow:!0,events:{hover:!0,focus:!1,touch:!1},withinPortal:!0,zIndex:320,position:"top-end",children:s.jsx(a.Box,{sx:{alignSelf:"flex-end"},children:s.jsx(a.Button,{disabled:!0,size:"xs",leftIcon:s.jsx(k.IconTrash,{size:16}),children:t("query.delete")})})}):s.jsx(a.Button,{color:"red",size:"xs",onClick:u,leftIcon:s.jsx(k.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:t("query.delete")})},TT=_.observer(kT),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"})]}),un=({value:e})=>e===null||e===""?null:s.jsx(a.Tooltip,{label:e,disabled:!e,multiline:!0,children:s.jsx(a.ActionIcon,{children:s.jsx(k.IconInfoCircle,{size:14})})}),DT=({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},IT=_.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(un,{value:n.column_comment})}),s.jsx("td",{children:s.jsx(DT,{column:n})}),s.jsx("td",{children:n.column_type}),s.jsx("td",{children:n.is_nullable}),s.jsx("td",{children:s.jsx(un,{value:n.column_default})})]},n.column_name))})]})}),MT=_.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))})]})}),zT=_.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(un,{value:r.index_definition})}),s.jsx("td",{children:s.jsx(un,{value:r.condition})}),s.jsx("td",{children:s.jsx(un,{value:r.comment})})]},r.index_name))})]})}),AT=_.observer(({dataSource:e})=>{const{indexes:t}=e;return t.loading||t.empty?null:e.type===le.MySQL?s.jsx(MT,{dataSource:e}):e.type===le.Postgresql?s.jsx(zT,{dataSource:e}):null}),ET=_.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(IT,{dataSource:e})}),s.jsx(je,{children:s.jsx(AT,{dataSource:e})})]}));function PT({table_type:e}){return e==="VIEW"?s.jsx(k.IconEye,{size:14}):e==="BASE TABLE"?s.jsx(k.IconTable,{size:14}):null}const LT=_.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(k.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(PT,{table_type:i.table_type}),onClick:()=>{e.setKeywords(n,i.table_name)},active:e.table_name===i.table_name},i.table_name))},n))})}),BT=({visible:e})=>s.jsx(a.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:s.jsx(a.LoadingOverlay,{visible:e})}),OT=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],$T={icon:{width:"50px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"50px"}}},qT=_.observer(({dataSource:e})=>{const{t}=M.useTranslation(),{tableData:n}=e;return s.jsxs(a.Group,{pt:10,px:10,position:"apart",children:[s.jsxs(a.Group,{position:"left",children:[n.maxPage>1&&s.jsx(a.Pagination,{size:"sm",value:n.page,onChange:n.setPage,total:n.maxPage,withEdges:n.maxPage>7,styles:{control:{height:"30px"}}}),s.jsx(a.Select,{icon:s.jsx(a.Text,{ta:"center",color:"dimmed",size:14,children:t("common.pagination.page_size")}),size:"xs",styles:$T,data:OT,value:String(n.limit),onChange:r=>n.setLimit(Number(r))})]}),s.jsx(a.Group,{position:"right",children:s.jsx(a.Text,{color:"dimmed",my:0,size:14,children:t("common.pagination.total_rows",{total:n.total})})})]})}),VT=_.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(BT,{visible:!0}):s.jsxs(je,{children:[s.jsx(qT,{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})]})]})}),NT={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},FT=_.observer(({dataSource:e})=>{const{t}=M.useTranslation();return f.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(LT,{dataSource:e})})}),s.jsxs(a.Tabs,{defaultValue:"structure",styles:NT,children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"structure",icon:s.jsx(k.IconColumns,{size:14}),children:t("data_source.table_structure_short")}),s.jsx(a.Tabs.Tab,{value:"data",icon:s.jsx(k.IconDatabase,{size:14}),children:t("data.label")})]}),s.jsx(a.Tabs.Panel,{value:"structure",children:s.jsx(ET,{dataSource:e})}),s.jsx(a.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:s.jsx(VT,{dataSource:e})})]})]})}),GT={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=_.observer(({dataSource:e,triggerButtonProps:t={}})=>{const{t:n}=M.useTranslation(),[r,i]=f.useState(!1);return e.type==="http"?null:s.jsxs(s.Fragment,{children:[s.jsx(a.Modal,{opened:r,onClose:()=>i(!1),title:s.jsxs(a.Group,{position:"apart",sx:{flexGrow:1},children:[s.jsx(a.Text,{fw:500,children:n("data_source.explorer")}),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:GT,children:s.jsx(a.Box,{sx:{height:"calc(100vh - 220px)"},children:s.jsx(FT,{dataSource:e})})}),s.jsx(a.Button,{variant:"subtle",onClick:()=>i(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},...t,children:n("data_source.see_table_structure")})]})}),WT=f.forwardRef(({label:e,type:t,...n},r)=>t===le.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(k.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})]})),RT=_.observer(({value:e,onChange:t})=>{const{t:n}=M.useTranslation(),r=J(),{data:i=[],loading:o}=V.useRequest(vs,{refreshDeps:[]},[]),l=f.useMemo(()=>{const h=i.map(p=>({label:p.key,value:p.key,type:p.type}));return h.push({label:n("query.transform.data_source"),value:le.Transform,type:le.Transform}),h},[i]),c=f.useMemo(()=>l.reduce((h,p)=>(h[p.value]=p.type,h),{}),[l]),u=h=>{h!==null&&t({key:h,type:c[h]})},d=f.useMemo(()=>r.datasources.find(e),[r,e]);return s.jsx(a.Select,{data:l,label:s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Box,{children:n("data_source.label")}),d&&s.jsx(Ac,{dataSource:d,triggerButtonProps:{compact:!0,size:"xs",px:10}})]}),itemComponent:WT,rightSection:d?s.jsx(a.Text,{size:"xs",color:"dimmed",children:d.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:o,value:e.key,onChange:u})}),Ec=f.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})]})})}),QT=_.observer(({queryModel:e})=>{const{t}=M.useTranslation(),[n,r]=f.useState(e.name);return f.useEffect(()=>{r(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:t("query.basics"),labelPosition:"center"}),s.jsx(a.TextInput,{placeholder:t("query.name_description"),label:t("query.name"),required:!0,sx:{flex:1},value:n,onChange:i=>{r(i.currentTarget.value)},rightSection:s.jsx(a.ActionIcon,{variant:"filled",color:"blue",size:"sm",onClick:()=>e.setName(n),disabled:n===e.name,children:s.jsx(k.IconDeviceFloppy,{size:16})}),onBlur:()=>{e.setName(n)}}),s.jsx(RT,{value:{type:e.type,key:e.key},onChange:({type:i,key:o})=>{e.setKey(o),e.setType(i)}}),s.jsx(a.Divider,{mt:10,mb:-10,variant:"dashed",label:t("query.conditions"),labelPosition:"center"}),s.jsx(a.MultiSelect,{label:t("query.run_by_condition.label"),placeholder:t("query.run_by_condition.unset"),data:e.conditionOptions,value:[...e.run_by],onChange:e.setRunBy,itemComponent:Ec,maxDropdownHeight:500}),e.typedAsHTTP&&s.jsx(a.MultiSelect,{label:t("query.re_run_condition.label"),placeholder:t("query.re_run_condition.label"),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(TT,{queryModel:e})]})})});function UT({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(k.IconEye,{})})}),s.jsx(a.HoverCard.Dropdown,{children:s.jsx(ht.Prism,{language:"sql",noCopy:!0,withLineNumbers:!0,children:e})})]})}const KT=_.observer(()=>{const t=[...J().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(UT,{content:i})})]},r)})})]})}),YT=`
|
|
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
|
-
`,Pc=
|
|
482
|
+
`,Pc=_.observer(function({showSQLSnippets:t=!0,sx:n={}}){const{t:r}=M.useTranslation(),i=J(),o=Q(),l=i.context.current,c=(()=>{const u={context:{...o.mock_context.current,...l},filters:o.filters.previewValues};return t&&(u.sql_snippets=o.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(k.IconAlertCircle,{size:14}),children:r("query_variable.guide.tabs.guide")}),s.jsx(a.Tabs.Tab,{value:"local_query_vars",icon:s.jsx(k.IconVariable,{size:14}),children:r("query_variable.guide.tabs.variables_in_this_dashboard")}),s.jsx(a.Tabs.Tab,{value:"global_sql_snippets",icon:s.jsx(k.IconVariablePlus,{size:14}),children:r("query_variable.guide.tabs.global_sql_snippets")})]}),s.jsx(a.Tabs.Panel,{value:"guide",pt:"xs",children:s.jsx(ht.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:YT})}),s.jsx(a.Tabs.Panel,{value:"local_query_vars",pt:"xs",children:s.jsx(ht.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:c})}),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(k.IconAlertCircle,{size:16}),title:r("global_sql_snippet.labels"),children:r("global_sql_snippet.description")}),s.jsx(KT,{})]})})]})})}),fi=_.observer(()=>{const{t:e}=M.useTranslation(),[t,n]=f.useState(!1);return s.jsxs(s.Fragment,{children:[s.jsx(a.Modal,{opened:t,onClose:()=>n(!1),title:e("query_variable.labels"),zIndex:320,size:"800px",children:s.jsx(Pc,{})}),s.jsx(a.Button,{variant:"subtle",onClick:()=>n(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},children:e("query_variable.open")})]})}),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
|
-
`)},
|
|
484
|
+
`)},XT=_.observer(({queryModel:e})=>{const{t}=M.useTranslation();return 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:t("query.build_request")}),s.jsx(a.Tabs.Tab,{value:"post_process",children:t("query.process_result")}),s.jsx(fi,{})]}),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:Lc.pre})}),s.jsx(a.Tabs.Panel,{value:"post_process",p:"sm",children:s.jsx($t,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:Lc.post})})]}):null}),JT=_.observer(({queryID:e,usage:t})=>{const{t:n}=M.useTranslation(),r=J().editor,i=l=>{if(l.type==="filter"){r.setPath(["_FILTERS_",l.id]);return}if(l.type==="panel"){const c=l.views[0].id;r.setPath(["_VIEWS_",c,"_PANELS_",l.id]);return}},o=l=>{r.setPath(["_VIEWS_",l])};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:n("common.type")}),s.jsx("th",{style:{width:"calc(50% - 50px)"},children:n("common.name")}),s.jsx("th",{children:n("query.usage.in_views")})]})}),s.jsx("tbody",{children:t.map(l=>s.jsxs("tr",{children:[s.jsx("td",{children:n(`${l.type}.label`)}),s.jsx("td",{children:s.jsx(a.Anchor,{component:"button",type:"button",onClick:()=>i(l),children:l.label})}),s.jsx("td",{children:s.jsxs(a.Stack,{align:"flex-start",justify:"flex-start",spacing:2,children:[l.views.map(c=>s.jsx(a.Anchor,{component:"button",type:"button",onClick:()=>o(c.id),children:s.jsx(a.Box,{children:c.label})},c.id)),l.views.length===0&&s.jsx(a.Box,{children:"--"})]})})]},l.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(ge,{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}})},ZT=_.observer(({queryModel:e})=>{const{t}=M.useTranslation(),n=f.useMemo(()=>y.groupBy(e.dependencies,"type"),[e.dependencies]),r=f.useMemo(()=>e.dependencies.some(o=>!o.valid),[e.dependencies]),i=e.dependencies.length>0;return i?s.jsxs(a.HoverCard,{withinPortal:!0,zIndex:340,shadow:"md",disabled:!i,children:[s.jsx(a.HoverCard.Target,{children:s.jsx(a.Button,{size:"xs",variant:"subtle",color:r?"red":"green",disabled:!i,leftIcon:r?s.jsx(k.IconAlertTriangle,{size:16}):s.jsx(k.IconDiscountCheckFilled,{size:16}),children:t("query.dependency.label")})}),s.jsx(a.HoverCard.Dropdown,{children:s.jsx(a.List,{spacing:"md",size:14,listStyleType:"none",children:Object.entries(n).map(([o,l])=>s.jsxs(a.List.Item,{children:[s.jsx(a.Text,{fw:"bold",ff:"monospace",children:t(`${o}.label`)}),s.jsx(a.List,{withPadding:!0,size:14,sx:{fontFamily:"monospace",svg:{verticalAlign:"middle"}},children:l.map(c=>s.jsx(a.List.Item,{icon:s.jsx(a.Box,{sx:{path:{fill:c.valid?"rgb(18, 184, 134)":"rgb(250, 82, 82)"}},children:s.jsx(k.IconPointFilled,{size:12})}),children:c.key},c.key))})]},o))})})]}):s.jsx(a.Tooltip,{label:t("query.dependency.has_none"),children:s.jsx(a.Button,{size:"xs",variant:"subtle",color:"gray",leftIcon:s.jsx(k.IconHierarchy,{size:16,style:{transform:"rotate(180deg)"}}),sx:{transform:"none !important"},children:t("query.dependency.label")})})}),HT="SELECT 1",eD=_.observer(({queryModel:e})=>{const{t}=M.useTranslation(),[n,r]=f.useState(e.sql),i=()=>{e.setSQL(n)},o=()=>{r(e.sql)},l=()=>{r(HT)};f.useEffect(()=>{r(e.sql)},[e.sql]);const c=n!==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(ZT,{queryModel:e})}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:l,size:"xs",variant:"default",leftIcon:s.jsx(k.IconPlayerSkipBack,{size:16}),children:t("common.actions.reset_to_default")}),s.jsx(a.Button,{onClick:o,color:"red",size:"xs",disabled:!c,leftIcon:s.jsx(k.IconRecycle,{size:16}),children:t("common.actions.revert_changes")}),s.jsx(a.Button,{color:"green",size:"xs",onClick:i,disabled:!c,leftIcon:s.jsx(k.IconDeviceFloppy,{size:16}),children:t("common.actions.save_changes")})]})]}),s.jsx(gi,{height:"100%",value:n,onChange:r,theme:"sql-dark",defaultLanguage:"sql"})]})}),tD=({value:e,height:t="200px",defaultLanguage:n="sql"})=>s.jsx(ge,{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}}),nD=_.observer(({value:e})=>{const n=ue().payloadForSQL,r=f.useMemo(()=>xs(e,n),[e,n]);return s.jsx(tD,{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
|
-
`)},
|
|
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"})});
|
|
486
|
+
`)},sD=_.observer(({queryModel:e})=>{const{t}=M.useTranslation();return 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:t("query.edit_sql")})}),s.jsx(a.Tabs.Tab,{value:"Preview",children:t("query.preview_sql")}),s.jsx(a.Tabs.Tab,{value:"pre_process",children:t("query.process_request")}),s.jsx(a.Tabs.Tab,{value:"post_process",children:t("query.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(eD,{queryModel:e})}),s.jsx(a.Tabs.Panel,{value:"Preview",p:0,pl:4,children:s.jsx(nD,{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:Bc.pre})}),s.jsx(a.Tabs.Panel,{value:"post_process",p:"sm",children:s.jsx($t,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:Bc.post})})]}):null}),rD={pre:["function transform(queries, state, utils) {"," // use queries & dashboar state to build new data"," const data = []"," return data","}"].join(`
|
|
487
|
+
`),post:""},iD=_.observer(({queryModel:e})=>{const{t}=M.useTranslation(),n=Q();return e.isTransform?s.jsxs(a.Stack,{py:20,px:20,sx:{height:"100%"},children:[s.jsx(a.Text,{size:"sm",children:t("query.transform.guide.pick_queries")}),s.jsx(a.MultiSelect,{data:n.queries.optionsWithoutTransform,value:[...e.dep_query_ids],onChange:e.setDependantQueryIDs,maxDropdownHeight:800}),s.jsx(a.Text,{size:"sm",children:t("query.transform.guide.write_function")}),s.jsx(a.Box,{sx:{flexGrow:1},children:s.jsx($t,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:rD.pre})})]}):null}),dn={height:"calc(100% - 44px)",padding:0},aD=_.observer(({queryModel:e})=>{const{t}=M.useTranslation(),n=Q(),r=f.useMemo(()=>e.datasource?e.typedAsHTTP?"HTTP":"SQL":"Configurations",[e.datasource,e.typedAsHTTP]),[i,o]=f.useState(r);f.useEffect(()=>{o(u=>u!=="Configurations"&&r==="Configurations"?"Configurations":u)},[r]);const l=n.findQueryUsage(e.id),c=l.length===0;return s.jsxs(a.Tabs,{value:i,onTabChange:o,defaultValue:r,orientation:"horizontal",keepMounted:!1,sx:{height:"100vh"},children:[s.jsxs(a.Tabs.List,{grow:!0,children:[s.jsx(a.Tabs.Tab,{value:"Configurations",children:t("query.configurations")}),e.typedAsSQL&&s.jsx(a.Tabs.Tab,{value:"SQL",children:t("query.request")}),e.typedAsHTTP&&s.jsx(a.Tabs.Tab,{value:"HTTP",children:t("query.request")}),e.isTransform&&s.jsx(a.Tabs.Tab,{value:"Transform",children:t("query.transform.label")}),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:t("data.preview_data")})})}),s.jsx(a.Tabs.Tab,{value:"Usage",disabled:c,children:s.jsx(a.Tooltip,{label:t("query.usage.unused_description"),disabled:!c,withinPortal:!0,children:s.jsx(a.Text,{children:t("query.usage.label")})})})]}),s.jsx(a.Tabs.Panel,{value:"Configurations",pt:0,p:0,children:s.jsx(QT,{queryModel:e})}),e.typedAsSQL&&s.jsx(a.Tabs.Panel,{value:"SQL",sx:dn,children:s.jsx(a.Stack,{sx:{height:"100%"},children:s.jsx(sD,{queryModel:e})})}),e.typedAsHTTP&&s.jsx(a.Tabs.Panel,{value:"HTTP",sx:dn,children:s.jsx(a.Stack,{sx:{height:"100%"},children:s.jsx(XT,{queryModel:e})})}),e.isTransform&&s.jsx(a.Tabs.Panel,{value:"Transform",sx:dn,children:s.jsx(a.Stack,{sx:{height:"100%"},children:s.jsx(iD,{queryModel:e})})}),s.jsx(a.Tabs.Panel,{value:"Data",sx:{...dn,overflow:"hidden"},children:s.jsx(pi,{id:e.id,moreActions:null,refreshOnMount:!0})}),s.jsx(a.Tabs.Panel,{value:"Usage",sx:{...dn,overflow:"hidden"},children:s.jsx(JT,{queryID:e.id,usage:l})})]})}),oD=_.observer(({id:e})=>{const n=Q().queries.findByID(e);return e===""?null:n?s.jsx(aD,{queryModel:n}):s.jsx(a.Text,{size:14,color:"red",children:"Invalid Query ID"})}),lD=_.observer(({value:e})=>{const n=ue().payloadForSQL,r=f.useMemo(()=>xs(e,n),[e,n]);return s.jsx(gi,{height:"100%",value:r})}),cD=_.observer(({item:e,remove:t,onKeyChanged:n})=>{const{t:r}=M.useTranslation(),[i,o]=f.useState("SQL"),[l,c]=f.useState(e.key),u=()=>{e.setKey(l),n(l)},d=l!==e.key,h=e.isADuplicatedKey(l),[p,x]=f.useState(e.value),m=()=>{e.setValue(p)};f.useEffect(()=>{c(e.key),x(e.value)},[e]);const v=p!==e.value,C=Ee.useModals(),S=()=>{C.openConfirmModal({title:`${r("sql_snippet.delete")}?`,labels:{confirm:r("common.actions.confirm"),cancel:r("common.actions.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:h?"This key is occupied by another snippet":"Key",value:l,onChange:D=>{c(D.currentTarget.value)},sx:{flexGrow:"1 !important"},rightSection:s.jsx(a.ActionIcon,{color:"blue",variant:"subtle",onClick:u,disabled:!d||h,children:s.jsx(T.DeviceFloppy,{size:16})}),error:h}),s.jsx(a.Button,{leftIcon:s.jsx(T.Trash,{size:16}),color:"red",variant:"light",onClick:S,children:r("sql_snippet.delete")})]}),s.jsxs(a.Tabs,{value:i,onTabChange:o,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:m,disabled:!v,sx:{position:"absolute",top:0,right:10},children:s.jsx(T.DeviceFloppy,{size:18})})]}),s.jsx(a.Tabs.Panel,{value:"SQL",pt:"sm",children:s.jsx(gi,{height:"100%",value:p,onChange:x,defaultLanguage:"sql",theme:"sql-dark"})}),s.jsx(a.Tabs.Panel,{value:"Preview",pt:"sm",children:s.jsx(lD,{value:p})})]})]})}),uD=_.observer(({id:e})=>{const t=J(),n=Q(),r=f.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(cD,{item:r,remove:o,onKeyChanged:l})}),dD=_.observer(()=>{const{t:e}=M.useTranslation(),[t,n]=f.useState([]),r=Ee.useModals(),i=J(),o=x=>{i.editor.setPath(["_SQL_SNIPPETS_",x])},l=()=>{r.openConfirmModal({title:"Delete ununsed SQL snippets?",children:s.jsx(a.Text,{size:"sm",children:"This action cannot be undone."}),labels:{confirm:e("common.actions.confirm"),cancel:e("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>i.content.removeUnusedSQLSnippets(),confirmProps:{color:"red"},zIndex:320})},c=()=>{i.content.sqlSnippets.downloadSchema(t)},u=f.useMemo(()=>i.content.sqlSnippets.sortedList.map(x=>x.key),[i.content.sqlSnippets.sortedList]),d=()=>{n(u)},h=()=>{n([])},p=i.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:e("sql_snippet.manage")})}),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:d,children:e("common.actions.select_all")}),s.jsx(a.Button,{variant:"default",size:"xs",onClick:h,children:e("common.actions.clear_selection")})]}),s.jsx(a.Button,{size:"xs",color:"blue",leftIcon:s.jsx(k.IconCode,{size:14}),disabled:t.length===0,onClick:c,children:e("common.actions.download_schema")})]}),s.jsx(a.Button,{variant:"subtle",size:"xs",color:"red",leftIcon:s.jsx(k.IconTrash,{size:14}),disabled:!i.content.hasUnusedSQLSnippets,onClick:l,children:e("sql_snippet.delete_unused")})]}),s.jsx(a.Box,{sx:{flexGrow:1,overflow:"auto"},children:s.jsx(a.Checkbox.Group,{size:"xs",value:t,onChange:n,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:e("common.key")}),s.jsx("th",{style:{width:"100px",textAlign:"center"},children:e("sql_snippet.usage.label")}),s.jsx("th",{style:{width:"300px",paddingLeft:"24px"},children:e("common.action")})]})}),s.jsx("tbody",{children:i.content.sqlSnippets.sortedList.map(x=>{var v;const m=((v=p[x.key])==null?void 0:v.length)??0;return s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx(a.Checkbox,{value:x.key,styles:{input:{cursor:"pointer"}}})}),s.jsx("td",{children:x.key}),s.jsx("td",{style:{color:m===0?"#ff0000":"#000",fontWeight:m===0?"bold":"normal",textAlign:"center"},children:m}),s.jsx("td",{children:s.jsx(a.Button,{variant:"subtle",size:"xs",onClick:()=>o(x.key),children:e("common.actions.open")})})]},x.key)})})]})})})]})}),pD=_.observer(({view:e})=>!e||e.type!==B.Division?null:s.jsx(a.Stack,{})),hD=_.observer(({view:e})=>{const{t,i18n:n}=M.useTranslation(),r=f.useMemo(()=>[{value:"default",label:t("common.tabs.variant.default")},{value:"outline",label:t("common.tabs.variant.outline")},{value:"pills",label:t("common.tabs.variant.pills")}],[n.language]),i=f.useMemo(()=>[{value:"horizontal",label:t("common.tabs.orientation.horizontal")},{value:"vertical",label:t("common.tabs.orientation.vertical")}],[n.language]);if(!e||e.type!==B.Tabs)return null;const o=e.config;return s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mt:8,mb:0,label:t("view.component.tabs.tabs_settings"),labelPosition:"center"}),s.jsx(a.Select,{label:t("common.tabs.variant.label"),value:o.variant,onChange:o.setVariant,data:r}),s.jsx(a.Select,{label:t("common.tabs.orientation.label"),value:o.orientation,onChange:o.setOrientation,data:i}),s.jsx(a.Switch,{label:t("common.tabs.grow_tabs"),checked:o.grow,onChange:l=>o.setGrow(l.currentTarget.checked)})]})}),xD=({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(ge,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},fD=({value:e,onChange:t})=>{const{t:n}=M.useTranslation(),[r,{setTrue:i,setFalse:o}]=V.useBoolean(),[l,c]=f.useState(e??Hn),u=m=>{c({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:v}=l,C={enabled:m,func_content:v};c(C),t(C)},h=()=>{o(),c(e)},p=m=>{c(v=>({...v,func_content:m}))},x=()=>{p(Hn.func_content)};return s.jsxs(s.Fragment,{children:[s.jsx(a.ActionIcon,{size:"lg",color:"blue",variant:"filled",mt:26,onClick:i,sx:{flexGrow:0},children:s.jsx(T.Settings,{size:14})}),s.jsx(a.Modal,{size:800,title:n("view.component.modal.custom_title"),opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&s.jsxs(a.Stack,{children:[s.jsx(a.Checkbox,{mt:10,label:n("common.enabled"),checked:l.enabled,onChange:m=>u(m.currentTarget.checked)}),s.jsx(xD,{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(T.Recycle,{size:20}),children:n("common.actions.revert")}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:h,variant:"subtle",children:n("common.actions.cancel")}),s.jsx(a.Button,{onClick:d,children:n("common.actions.save")})]})]})]})})]})},gD=_.observer(({view:e})=>{const{t}=M.useTranslation();if(!e||e.type!==B.Modal)return null;const n=e.config,r=n.custom_modal_title.value;return s.jsxs(a.Stack,{children:[s.jsx(a.Divider,{mt:8,label:t("view.component.modal.modal_settings"),labelPosition:"center"}),s.jsxs(a.Flex,{gap:10,children:[s.jsx(a.TextInput,{label:t("view.component.modal.title"),value:r,onChange:y.noop,disabled:!0,sx:{flexGrow:1}}),s.jsx(fD,{value:n.custom_modal_title,onChange:n.custom_modal_title.replace})]}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(a.TextInput,{label:t("view.component.modal.width"),value:n.width,onChange:i=>n.setWidth(i.currentTarget.value),placeholder:"600px / 50vw"}),s.jsx(a.TextInput,{label:t("view.component.modal.height"),value:n.height,onChange:i=>n.setHeight(i.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),mD=_.observer(({view:e})=>s.jsxs(s.Fragment,{children:[s.jsx(pD,{view:e}),s.jsx(gD,{view:e}),s.jsx(hD,{view:e})]})),yD=_.observer(({view:e})=>{const{t,i18n:n}=M.useTranslation(),r=f.useMemo(()=>[{label:t("view.component.div.label"),value:B.Division},{label:t("view.component.modal.label"),value:B.Modal},{label:t("view.component.tabs.label"),value:B.Tabs}],[n.language]);return e?s.jsxs(a.Stack,{sx:{position:"relative"},children:[s.jsx(a.TextInput,{label:t("common.name"),value:e.name,onChange:i=>{e.setName(i.currentTarget.value)}}),s.jsx(a.Select,{label:t("common.type"),withinPortal:!0,zIndex:320,value:e.type,onChange:e.setType,data:r}),s.jsx(mD,{view:e})]}):null}),bD=_.observer(({id:e})=>{const{t}=M.useTranslation(),n=Ee.useModals(),r=J(),i=Q();if(e==="")return null;const o=i.views.findByID(e);if(!o)return s.jsxs(a.Text,{size:14,children:["View by ID[",e,"] is not found"]});const l=()=>{r.editor.setPath(["_VIEWS_",""])},c=()=>{n.openConfirmModal({title:`${t("view.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.views.removeByID(e),l()},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(T.Trash,{size:16}),onClick:c,children:t("view.delete")})}),s.jsx(a.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:s.jsx(yD,{view:o})})]})});function vD(e){return e.length===1&&e[0]==="_QUERY_VARS_"}function jD(e){return e.length===1&&e[0]==="_MOCK_CONTEXT_"}function wD(e){return e.length===1&&e[0]==="_FILTERS_"}function CD(e){return e.length===2&&e[0]==="_FILTERS_"}function _D(e){return e.length===1&&e[0]==="_SQL_SNIPPETS_"}function SD(e){return e.length===2&&e[0]==="_SQL_SNIPPETS_"}function kD(e){return e.length===2&&e[0]==="_QUERIES_"}function TD(e){return e.length===1&&e[0]==="_QUERIES_"}function DD(e){return e.length===2&&e[0]==="_VIEWS_"}function ID(e){return e.length===4&&e[0]==="_VIEWS_"&&e[2]==="_PANELS_"}const MD=_.observer(()=>s.jsx(a.Stack,{sx:{height:"100%"},p:"sm",children:s.jsx(Pc,{})})),zD=_.observer(()=>{const e=J().editor,t=e.path;return vD(t)?s.jsx(MD,{}):jD(t)?s.jsx(Fk,{}):wD(t)?s.jsx(Nk,{}):CD(t)?s.jsx(a.Box,{p:"xs",pl:20,children:s.jsx(Vk,{id:t[1]})}):_D(t)?s.jsx(dD,{}):SD(t)?s.jsx(uD,{id:t[1]}):TD(t)?s.jsx(ST,{}):kD(t)?s.jsx(oD,{id:t[1]}):DD(t)?s.jsx(a.Box,{p:"xs",pl:20,children:s.jsx(bD,{id:t[1]})}):ID(t)?s.jsx(_T,{viewID:t[1],panelID:t[3]}):s.jsx(a.Box,{children:e.path})}),AD=_.observer(()=>s.jsx(zD,{})),ED=_.observer(()=>{const{t:e}=M.useTranslation(),t=J(),n=()=>{const r=new Date().getTime().toString(),i={id:r,key:r,label:r,order:t.content.filters.current.length+1,type:pe.TextInput,config:Or(),visibleInViewsIDs:["Main"],auto_submit:!1};t.content.filters.append(i),t.editor.setPath(["_FILTERS_",r])};return s.jsx(a.Button,{variant:"subtle",leftIcon:s.jsx(k.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:n,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:e("filter.add")})}),PD=_.observer(({parentID:e})=>{const{t}=M.useTranslation(),n=Q();if(!e)return null;const r=n.views.findByID(e);return!r||r.type===B.Tabs?null:s.jsx(a.Button,{variant:"subtle",leftIcon:s.jsx(k.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:()=>n.addANewPanel(r.id),sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:t("panel.add")})}),LD=_.observer(()=>{const{t:e}=M.useTranslation(),t=J(),n=()=>{const r=new Date().getTime().toString(),i={id:r,name:r,type:le.Postgresql,key:"",sql:""};t.content.queries.append(i),t.editor.setPath(["_QUERIES_",r])};return s.jsx(a.Button,{variant:"subtle",leftIcon:s.jsx(k.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:n,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:e("query.add")})}),BD=_.observer(()=>{const{t:e}=M.useTranslation(),t=J(),n=()=>{const r=new Date().getTime().toString(),i={key:r,value:""};t.content.sqlSnippets.append(i),t.editor.setPath(["_SQL_SNIPPETS_",r])};return s.jsx(a.Button,{variant:"subtle",leftIcon:s.jsx(k.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:n,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:e("sql_snippet.add")})}),OD=_.observer(()=>{const{t:e}=M.useTranslation(),t=Q();return s.jsx(a.Button,{variant:"subtle",leftIcon:s.jsx(k.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:e("view.add")})}),$D=_.observer(()=>{const{t:e}=M.useTranslation(),t=J();return s.jsx(a.Button,{variant:"subtle",rightIcon:s.jsx(k.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>t.editor.setPath(["_QUERIES_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:e("query.manage")})}),qD=_.observer(()=>{const{t:e}=M.useTranslation(),t=J();return s.jsx(a.Button,{variant:"subtle",rightIcon:s.jsx(k.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>t.editor.setPath(["_SQL_SNIPPETS_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:e("sql_snippet.manage")})}),VD=_.observer(()=>{const{t:e}=M.useTranslation(),t=J();return s.jsx(a.Button,{variant:"subtle",rightIcon:s.jsx(k.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>t.editor.setPath(["_FILTERS_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:e("filter.manage")})}),ND=_.observer(({action_type:e,parentID:t})=>e==="_Add_A_Filter_"?s.jsx(ED,{}):e==="_Add_A_SQL_SNIPPET_"?s.jsx(BD,{}):e==="_Add_A_QUERY_"?s.jsx(LD,{}):e==="_Add_A_VIEW_"?s.jsx(OD,{}):e==="_Add_A_PANEL_"?s.jsx(PD,{parentID:t}):e==="_QUERIES_SETTINGS_"?s.jsx($D,{}):e==="_SQL_SNIPPETS_SETTINGS_"?s.jsx(qD,{}):e==="_FILTERS_SETTINGS_"?s.jsx(VD,{}):null),Oc=_.observer(({option:e})=>{var h;const{t}=M.useTranslation(),n=J().editor,r=n.isOptionActive,i=r(n.path,e),o=n.isOptionOpened,l=n.navigate,c=o(e),[u,d]=f.useState(c);return f.useEffect(()=>{d(c)},[c]),s.jsx(a.NavLink,{active:i,defaultOpened:c,opened:u,onChange:d,label:t(e.label),onClick:()=>l(e),icon:e.Icon?s.jsx(e.Icon,{size:18}):null,children:(h=e.children)==null?void 0:h.map(p=>p._type==="ACTION"?s.jsx(ND,{action_type:p._action_type,parentID:p.parentID},`_ADD_${p.value}_`):s.jsx(Oc,{option:p},p.value))},e.label)}),FD=_.observer(()=>{const e=J();return s.jsx(a.Box,{sx:{position:"relative"},children:e.editor.navOptions.map(t=>s.jsx(Oc,{option:t},t.value))})}),GD=_.observer(()=>{const{t:e}=M.useTranslation(),t=J();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:e("common.titles.settings")})}),s.jsx(a.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:s.jsx(FD,{})}),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(k.IconX,{size:18}),onClick:()=>t.editor.close(),children:e("common.actions.close")})})})]})}),WD={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"}},RD=_.observer(()=>{const e=J().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(GD,{}),styles:WD,children:s.jsx(AD,{})})})}),QD=e=>e.replace(/([^:])(\/\/+)/g,"$1/");function UD(e){f.useEffect(()=>{if(ge.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const n=QD(e);ge.loader.config({paths:{vs:n}}),ge.loader.init().then(r=>console.log("monaco instance:",r))},[])}sa(),ia();const KD={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:60+30,height:"100vh"}},YD=({context:e,dashboard:t,content:n,update:r,className:i="dashboard",config:o,onChange:l,headerSlot:c,filterValues:u,onFilterValuesChange:d,onExit:h,lang:p},x)=>{UD(o.monacoPath),fs(o);const{i18n:m}=M.useTranslation();f.useEffect(()=>{m.changeLanguage(p)},[p]);const{data:v=[]}=V.useRequest(vs),{data:C=[]}=V.useRequest(aa),S=f.useMemo(()=>mc(t,n,v,C,e,u??{}),[t,n]);f.useImperativeHandle(x,()=>S,[S]),yc(S.content,!0),f.useEffect(()=>{S.context.replace(e)},[e]),f.useEffect(()=>{S.datasources.replace(v)},[v]),f.useEffect(()=>{S.globalSQLSnippets.replace(C)},[C]),f.useEffect(()=>{d==null||d(S.content.filters.values)},[d,S.content.filters.values]),f.useEffect(()=>{u&&S.content.filters.patchValues(u)},[u,S.content.filters.patchValues]),f.useEffect(()=>Y.reaction(()=>Y.toJS(S.json),U=>{l==null||l(U)}),[S]);const D=async()=>{await r(S.json,S.content.json)},P=V.useCreation(kr,[]),q=bc(P);return s.jsx(Ee.ModalsProvider,{children:s.jsx(Ss,{value:{searchButtonProps:o.searchButtonProps},children:s.jsx(Cs,{value:S,children:s.jsx(ks,{value:S.content,children:s.jsx(Cn.Provider,{value:{inEditMode:!0},children:s.jsx(tt.Provider,{value:P,children:s.jsxs(Jn,{configure:q,children:[s.jsx(a.AppShell,{padding:0,header:s.jsx(Z1,{onExit:h,saveDashboardChanges:D,headerSlot:c}),navbar:s.jsx(Sk,{}),styles:KD,children:s.jsx(a.Box,{className:`${i} dashboard-root`,sx:{position:"relative"},children:S.content.views.visibleViews.map(U=>s.jsx(ic,{view:U},U.id))})}),s.jsx(RD,{})]})})})})})})})},XD=_.observer(f.forwardRef(YD)),JI="",mi=g.types.model({id:g.types.string,name:g.types.string,dashboard_id:g.types.string,create_time:g.types.string,update_time:g.types.string,version:g.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=g.getParent(e).context.current,n=g.getParent(e).globalSQLSnippets,r={context:{...e.mock_context.current,...t},filters:e.filters.values};return{...r,sql_snippets:cn(e.sqlSnippets.current,"key","value",r),global_sql_snippets:cn(n.list,"id","content",r)}},get payloadForViz(){const t=g.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:v,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:Vl(m),sqlSnippets:Gl(v),mock_context:Mr(C),views:Al(h),panels:{list:p},layouts:{list:x,currentBreakpoint:x[0].id}})}const qc=g.types.model({id:g.types.identifier,name:g.types.string,group:g.types.string,content:mi,content_id:g.types.string,datasources:Ml,globalSQLSnippets:Wr,context:es});function Vc({id:e,name:t,group:n,content_id:r},i,o,l,c,u){return qc.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 JD=({context:e,dashboard:t,content:n,className:r="dashboard",config:i,fullScreenPanelID:o,setFullScreenPanelID:l,filterValues:c,onFilterValuesChange:u,lang:d})=>{fs(i);const{i18n:h}=M.useTranslation();f.useEffect(()=>{h.changeLanguage(d)},[d]);const{data:p=[]}=V.useRequest(vs),{data:x=[]}=V.useRequest(aa),m=f.useMemo(()=>Vc(t,n,p,x,e,c??{}),[t,n]);yc(m.content,!1),f.useEffect(()=>{m.context.replace(e)},[e]),f.useEffect(()=>{m.datasources.replace(p)},[p]),f.useEffect(()=>{m.globalSQLSnippets.replace(x)},[x]),f.useEffect(()=>{u==null||u(m.content.filters.values)},[u,m.content.filters.values]),f.useEffect(()=>{c&&m.content.filters.patchValues(c)},[c,m.content.filters.patchValues]);const v=V.useCreation(kr,[]),C=bc(v);return s.jsx(Ee.ModalsProvider,{children:s.jsx(Ss,{value:{searchButtonProps:i.searchButtonProps},children:s.jsx(Cs,{value:m,children:s.jsx(ks,{value:m.content,children:s.jsx(Ds.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:v,children:s.jsx(Jn,{configure:C,children:m.content.views.visibleViews.map(S=>s.jsx(ns,{view:S},S.id))})})})})})})})})})},ZD=_.observer(JD);z.extend(mu),z.extend(yu),z.extend(bu),z.extend(vu),z.extend(ju),z.extend(wu),z.extend(Cu),z.extend(_u),z.extend(Su),z.extend(ku),z.extend(Iu),z.extend(Mu),z.extend(zu),z.extend(Au),z.extend(Eu),z.extend(Tu),z.extend(Du),z.extend(Pu),z.extend(Lu),z.extend(Bu),z.extend(Ou),z.extend($u),z.extend(qu),z.extend(Vu),z.extend(Nu),z.extend(Fu),z.extend(Gu),z.extend(Wu),z.extend(Ru),z.extend(Qu),z.extend(Ku),z.extend(Yu),z.extend(Uu),z.tz.setDefault("UTC"),z.updateLocale("en",{weekStart:1});const HD={translation:{filter:{label:"Filter",labels:"Filters",add:"Add a Filter",manage:"Manage Filters",show_filters:"Show Filters",hide_filters:"Hide Filters",field:{widget:"Widget",visible_in:"Visible in...",key_placeholder:"A unique key to refer",label_placeholder:"Label for this field",auto_submit:"Submit automatically",order:"Placement Order"},widget:{names:{select:"Select",multi_select:"Multi Select",tree_select:"Tree Select",text_input:"Text Input",checkbox:"Checkbox",date_range:"Date Range"},common:{use_query_data_as_options:"Use query data as options",or_fetch_options_from_datasource:"Or fetch options from datasource"},text_input:{default_value:"Default Value",required:"Required"},select:{width:"Width",required:"Required",configure_options:"Configure options",default_selection:"Default Selection",no_default_selection:"none",select_first_option_by_default:"Select the first option by default"}}},view:{label:"View",labels:"Views",add:"Add a View",delete:"Delete this View",download_schema:"Download this View",component:{div:{label:"Division"},tabs:{label:"Tabs",tabs_settings:"Tabs Settings",tab:{name:"Tab Name",view:"View",order:"Placement Order",color:"Color",delete:"Delete this tab",switch_to_view:"Swith to View: {{name}}"}},modal:{label:"Modal",modal_settings:"Modal settings",title:"Modal Title",custom_title:"Customize modal title",width:"Width",height:"Height"}}},interactions:{label:"Interactions",add:"Add an interaction",interactions_viewer:"Interactions Viewer"},query_variable:{label:"Query Variable",labels:"Query Variables",add:"Add a Variable",guide:{tabs:{guide:"Guide",variables_in_this_dashboard:"Variables in this dashboard",global_sql_snippets:"Global SQL Snippets"}},open:"See Query Variables"},sql_snippet:{label:"SQL Snippet",labels:"SQL Snippets",add:"Add a SQL Snippet",delete:"Delete this SQL Snippet",delete_unused:"Delete unused SQL Snippets",manage:"Manage SQL Snippets",usage:{label:"Usage"}},global_sql_snippet:{label:"Global SQL Snippet",labels:"Global SQL Snippets",description:"SQL snippets worth sharing between dashboards are managed in System Settings by admins."},common:{titles:{settings:"Settings",edit:"Edit",config:"Config"},pagination:{page_size:"Page Size",total:"Total",total_rows:"Total {total} row"},id:"ID",name:"Name",key:"Key",label:"Label",value:"Value",type:"Type",info:"Info",data_field:"Data Field",enabled:"Enabled",action:"Action",actions:{open:"Open",close:"Close",save:"Save",save_changes:"Save Changes",revert:"Revert",revert_changes:"Revert Changes",reset_to_default:"Reset to default",select_all:"Select All",clear_selection:"Clear Selection",refresh:"Refresh",download_data:"Download Data",download_schema:"Download Schema",download_screenshot:"Screenshot",enter_fullscreen:"Full Screen",duplicate:"Duplicate",delete:"Delete",cancel:"Cancel",confirm:"Confirm",add_an_option:"Add an Option",end_editing:"End editing <1>{{name}}</1>"},tabs:{variant:{label:"Variant",default:"Default",outline:"Outline",pills:"Pills"},orientation:{label:"Orientation",horizontal:"Horizontal",vertical:"Vertical"},grow_tabs:"Grow Tabs"},choose_a_tab_first:"Please choose a tab first"},breakpoint:{label_one:"Screen size",label_other:"Screen sizes",add:"Add a screen size",manage:"Manage screen sizes",breakpoint:"Min Width"},context:{label:"Context"},mock_context:{label:"Mock Context",hint:"A valid json string is required"},panel:{label:"Panel",labels:"Panels",add:"Add a Pane",delete:"Delete This Panel",panel_name:"Panel Name",panel_description:"Description",show_title:"Show title",use_name_as_title:"Use name as title",settings:{change_view:"Move into Another View",change_view_title:"Move panel into another view",choose_queries:"Choose queries"},style:{label:"Style",width:"Width",width_postfix:"of 36 columns",height:"Height",height_postfix:"px",border:"Border"},variable:{label:"Variable",labels:"Variables",add:"Add a Variable",delete:"Delete this Variable",aggregation:{label:"Aggregation",fallback_value:"Fallback Value",fallback_value_description:"Used when data is empty or the aggregation yields NaN"},styles:{label:"Styles",font_size:{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%..."},font_weight:{label:"Font Weight"}}}},query:{label:"Query",labels:"Queries",add:"Add a Query",delete:"Delete this Query",cant_delete:"Can't delete this query for it's being used, check out Usage tab for details",delete_unused:"Delete unused queries",name:"Name",name_description:"A unique name",manage:"Manage Queries",open:"Open this query",configurations:"Configurations",basics:"Basics",conditions:"Conditions",run_by_condition:{label:"Run query when these are truthy",unset:"Always run this query on load"},re_run_condition:{label:"Re-run query when these changed",unset:"Leave it empty to never re-run this query"},dependency:{label:"Dependency",has_none:"This query has no dependency"},edit_sql:"Edit SQL",preview_sql:"Preview SQL",request:"Request",build_request:"Build Request",process_request:"Process Request",process_result:"Process Result",usage:{label:"Usage",in_views:"In View(s)",unused_description:"This query is not used by any filter or panel"},transform:{label:"Transform",data_source:"Use other queries' data",guide:{pick_queries:"Pick queries for data input",write_function:"Write a function for making new data"}}},data:{label:"Data",preview_data:"Preview Data",empty_data:"Empty Data"},data_source:{label:"Data Source",explore:"Explore Data Source",explorer:"Data Source Explorer",table_structure:"Table Structure",table_structure_short:"Structure",see_table_structure:"See Table Structure"},visualization:{label:"Visualization",component:"Visualization",label_short:"Viz"},numbro:{format:{label:"Format",absolute:"Absolute",absolute_description:"Non-negative",abbreviation:"Abbreviation",abbreviation_description:"like 1.23k, 1.23m",mantissa:"Mantissa",trim_mantissa:"Trim mantissa",trim_mantissa_description:"hide trailing zero(s)",preview:{open:"Open Preview",close:"Close Preview",input:"In",output:"Out"}}},import:{label:"Import...",title:"Import content with schema json",json_file:"JSON File",this_dashboard:"This dashboard",this_file:"This file"},function_utils:{trigger_text:"About parameter 'utils'",modal_title:"About FunctionUtils",description:"Parameter <code>utils</code> is <code>FunctionUtils</code>, which contains:",document:"Document"}}},eI={translation:{filter:{label:"筛选器",labels:"筛选器",add:"新增筛选器",manage:"管理筛选器",show_filters:"展开筛选器",hide_filters:"收起筛选器",field:{widget:"控件",visible_in:"在...视图中可见",key_placeholder:"用于引用此筛选器,需保持唯一",label_placeholder:"用于展示的标签文案",auto_submit:"自动提交",order:"排列次序"},widget:{names:{select:"单选",multi_select:"多选",tree_select:"树形选择器",text_input:"文本框",checkbox:"勾选框",date_range:"日期范围"},common:{use_query_data_as_options:"使用所查数据为选项",or_fetch_options_from_datasource:"或从数据源查选项"},text_input:{default_value:"默认值",required:"必填"},select:{width:"控件宽度",required:"必选",configure_options:"配置选项",default_selection:"默认选项",no_default_selection:"无",select_first_option_by_default:"默认选中第一个选项"}}},view:{label:"视图",labels:"视图",add:"新增视图",delete:"删除此视图",download_schema:"下载此视图描述文件",component:{div:{label:"内容"},tabs:{label:"标签页",tabs_settings:"标签页设置",tab:{name:"名称",view:"内容视图",order:"排列次序",color:"颜色",delete:"删除这个标签页",switch_to_view:"打开视图: {{name}}"}},modal:{label:"弹窗",modal_settings:"弹窗设置",title:"弹窗标题",custom_title:"自定义弹窗标题",width:"宽度",height:"高度"}}},interactions:{label:"交互",add:"新增交互",interactions_viewer:"纵览交互"},query_variable:{label:"查询变量",labels:"查询变量",add:"新增变量",guide:{tabs:{guide:"使用指南",variables_in_this_dashboard:"本看板中的查询变量",global_sql_snippets:"全局SQL片段"}},open:"查看查询变量"},sql_snippet:{label:"SQL片段",labels:"SQL片段",add:"新增SQL片段",delete:"删除这个SQL片段",delete_unused:"删除未用到的SQL片段",manage:"管理SQL片段",usage:{label:"使用情况"}},global_sql_snippet:{label:"全局SQL片段",labels:"全局SQL片段",description:"管理员负责在系统设置中维护全局SQL片段"},common:{titles:{settings:"设置",edit:"编辑",config:"配置"},pagination:{page_size:"页容量",total:"共",total_rows:"共 {{total}} 行"},id:"ID",name:"名称",key:"键",label:"标签",value:"值",type:"类型",info:"信息",data_field:"数据字段",enabled:"启用",action:"操作",actions:{open:"打开",close:"关闭",save:"保存",save_changes:"保存改动",revert:"还原",revert_changes:"还原改动",reset_to_default:"重置为初始值",select_all:"全选",clear_selection:"撤销选择",refresh:"刷新",download_data:"下载数据",download_schema:"下载描述文件",download_screenshot:"下载截图",enter_fullscreen:"全屏",duplicate:"复制",delete:"删除",cancel:"取消",confirm:"确认",add_an_option:"新增选项",end_editing:"结束编辑 <1>{{name}}</1>"},tabs:{variant:{label:"风格",default:"默认",outline:"轮廓",pills:"胶囊"},orientation:{label:"朝向",horizontal:"水平",vertical:"垂直"},grow_tabs:"拉伸标签卡宽度"},choose_a_tab_first:"请先选择一个标签页"},breakpoint:{label_one:"屏幕尺寸",label_other:"屏幕尺寸",add:"新增屏幕尺寸",manage:"管理屏幕尺寸",breakpoint:"最小宽度"},context:{label:"上下文"},mock_context:{label:"模拟上下文",hint:"内容格式为JSON"},panel:{label:"卡片",labels:"卡片",add:"新增卡片",delete:"删除这个卡片",panel_name:"卡片名",panel_description:"卡片描述",show_title:"展示卡片标题",use_name_as_title:"使用卡片名作为标题",settings:{change_view:"移至另一个视图下",change_view_title:"移动此卡片至另一个视图下",choose_queries:"关联查询"},style:{label:"样式",width:"宽",width_postfix:"之 36 栏",height:"高",height_postfix:"px",border:"边框"},variable:{label:"变量",labels:"变量",add:"新增变量",delete:"删除此变量",aggregation:{label:"聚合",fallback_value:"兜底值",fallback_value_description:"当数据为空或聚合结果非数字时,使用此兜底值"},styles:{label:"样式",font_size:{label:"字号",placeholder:"10px, 1em, 1rem, 100%..."},font_weight:{label:"字重"}}}},query:{label:"查询",labels:"查询",add:"新增查询",delete:"删除这个查询",cant_delete:"此查询在使用中,不能删除。请查看“使用情况”标签页以了解详情",delete_unused:"删除未用到的查询",name:"名称",name_description:"唯一名称",manage:"管理查询",open:"打开此查询",configurations:"配置",basics:"基本信息",conditions:"条件",run_by_condition:{label:"以下条件满足时,才运行本查询",unset:"看板加载时便运行本查询"},re_run_condition:{label:"当以下条件改变时,重新运行此查询",unset:"留空则永不重新运行此查询"},dependency:{label:"依赖",has_none:"此查询无依赖"},edit_sql:"编辑SQL",preview_sql:"预览SQL",request:"请求",build_request:"构造请求",process_request:"加工请求",process_result:"加工结果",usage:{label:"使用情况",in_views:"所在视图",unused_description:"此查询未被任何筛选器或卡片用到"},transform:{label:"查询变形",data_source:"基于其他查询的数据,加工出新数据",guide:{pick_queries:"选择一至多个查询作为数据输入",write_function:"编写函数,返回新数据"}}},data:{label:"数据",preview_data:"预览数据",empty_data:"无数据"},data_source:{label:"数据源",explore:"查看数据源",explorer:"数据源查看器",table_structure:"数据表结构",table_structure_short:"表结构",see_table_structure:"查看数据表结构"},visualization:{label:"可视化",component:"可视化组件",label_short:"可视化"},numbro:{format:{label:"格式",absolute:"绝对值",absolute_description:"非负",abbreviation:"缩写",abbreviation_description:"如1.23k、1.23m",mantissa:"小数",trim_mantissa:"抹零",trim_mantissa_description:"省略末尾的零",preview:{open:"展开预览",close:"收起预览",input:"输入",output:"输出"}}},import:{label:"导入...",title:"自描述文件导入看板内容",json_file:"描述文件(JSON格式)",this_dashboard:"此看板",this_file:"此文件"},function_utils:{trigger_text:"关于utils参数",modal_title:"关于utils参数",description:"参数 <code>utils</code> 是 <code>FunctionUtils</code>,包含以下内容:",document:"文档"}}};Xu.use(Ju).use(M.initReactI18next).init({debug:!1,fallbackLng:"en",interpolation:{escapeValue:!1},resources:{en:HD,zh:eI}});const tI=()=>Promise.resolve().then(()=>Rd).then(({version:e})=>(console.log(`[@devtable/dashboard] version: ${e}`),e));j.APIClient=Je,j.CURRENT_SCHEMA_VERSION=lt,j.ContentModel=oi,j.ContentModelContextProvider=ks,j.ContentRenderModel=mi,j.ContextMeta=es,j.DEFAULT_CUSTOM_MODAL_TITLE=Hn,j.DashboardApiClient=Zi,j.DashboardApiFacadeClient=Hi,j.DashboardEditor=XD,j.DashboardFilterType=pe,j.DashboardMode=ac,j.DashboardModel=gc,j.DashboardModelContextProvider=Cs,j.DashboardRenderModel=qc,j.DashboardThemeContextProvider=Ss,j.DashboardViewEditor=ic,j.DashboardViewRender=ns,j.DataSourceMetaModel=Gr,j.DataSourceType=le,j.DataSourcesMetaModel=Ml,j.DefaultApiClient=Ji,j.DescriptionPopover=ni,j.DraftModel=Wl,j.EViewComponentType=B,j.FacadeApiClient=cd,j.FilterCheckboxConfigMeta=zr,j.FilterDateRangeConfigMeta=Ar,j.FilterMeta=qr,j.FilterMultiSelectConfigMeta=Pr,j.FilterSelectConfigMeta=Lr,j.FilterTextInputConfigMeta=Br,j.FilterTreeSelectConfigMeta=$r,j.FiltersModel=lc,j.FiltersRenderModel=Xr,j.FullScreenPanel=ec,j.FullScreenPanelContext=Ds,j.GlobalSQLSnippetMeta=zl,j.GlobalSQLSnippetsMeta=Wr,j.LayoutItemMeta=ml,j.LayoutSetMeta=yl,j.LayoutStateContext=Cn,j.LayoutsRenderModel=ei,j.MockContextMeta=Ir,j.MuteQueryModel=ql,j.Panel=Hl,j.PanelContextProvider=Ts,j.PanelErrorOrStateMessage=Jl,j.PanelMeta=fl,j.PanelModel=pc,j.PanelRender=ri,j.PanelRenderModel=Kr,j.PanelStyleMeta=dl,j.PanelTitleMeta=pl,j.PanelVizMeta=xl,j.PanelVizSection=si,j.PanelsModel=hc,j.PanelsRenderModel=Yr,j.QueriesModel=uc,j.QueriesRenderModel=Hr,j.QueryMeta=gl,j.QueryModel=cc,j.QueryRenderModel=Zr,j.ReadOnlyDashboard=ZD,j.SQLSnippetMeta=bl,j.SQLSnippetRenderModel=Fl,j.SQLSnippetsModel=dc,j.SQLSnippetsRenderModel=ti,j.VariableMeta=hl,j.ViewComponentTypeBackground=oc,j.ViewComponentTypeColor=v1,j.ViewComponentTypeName=b1,j.ViewDivisionConfig=Vr,j.ViewMeta=Il,j.ViewModalConfig=Nr,j.ViewRenderModel=Qr,j.ViewTabsConfig=Fr,j.ViewsModel=xc,j.ViewsRenderModel=Ur,j.Viz=Xl,j.applyPartialDashboard=E1,j.configureAPIClient=fs,j.createContentModel=fc,j.createContentRenderModel=$c,j.createContextMeta=Rr,j.createDashboardModel=mc,j.createDashboardRenderModel=Vc,j.createDraft=Rl,j.createFilterCheckboxConfig=vl,j.createFilterDateRangeConfig=wl,j.createFilterMultiSelectConfig=Cl,j.createFilterSelectConfig=_l,j.createFilterTextInputConfig=Or,j.createFilterTreeSelectConfig=Sl,j.createViewDivisionConfig=kl,j.createViewModalConfig=Tl,j.createViewTabsConfig=Dl,j.facadeApiClient=ea,j.formatSQLSnippet=cn,j.getInitialDashboardViewsModel=ai,j.getInitialFiltersConfig=Jr,j.getInitialMockContextMeta=Mr,j.getInitialQueriesRenderModel=Vl,j.getInitialSQLSnippetsRenderModel=Gl,j.getInitialViewsRenderModel=Al,j.getNewPanel=Ll,j.getVersion=tI,j.initialDashboardContent=OS,j.useDashboardContext=_s,j.useDashboardThemeContext=xa,j.useEditContentModelContext=Q,j.useEditDashboardContext=J,j.useEditPanelContext=Le,j.useFullScreenPanelContext=ba,j.usePanelFullScreen=tc,j.useRenderContentModelContext=ue,j.useRenderDashboardContext=pa,j.useRenderPanelContext=gt,Object.defineProperty(j,Symbol.toStringTag,{value:"Module"})});
|