@devtable/dashboard 10.54.0 → 10.55.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/plugins/viz-components/boxplot-chart/option/index.d.ts +1 -14
- package/dist/components/plugins/viz-components/boxplot-chart/option/tooltip/index.d.ts +2 -17
- package/dist/components/plugins/viz-components/calendar-heatmap/option/tooltip.d.ts +1 -5
- package/dist/components/plugins/viz-components/cartesian/option/tooltip.d.ts +1 -6
- package/dist/components/plugins/viz-components/funnel/option/index.d.ts +1 -5
- package/dist/components/plugins/viz-components/funnel/option/tooltip.d.ts +1 -6
- package/dist/components/plugins/viz-components/heatmap/option/index.d.ts +1 -1
- package/dist/components/plugins/viz-components/heatmap/option/tooltip.d.ts +1 -5
- package/dist/components/plugins/viz-components/horizontal-bar-chart/option/tooltip.d.ts +1 -8
- package/dist/components/plugins/viz-components/merico-heatmap/render/option/index.d.ts +1 -1
- package/dist/components/plugins/viz-components/merico-heatmap/render/option/tooltip.d.ts +1 -5
- package/dist/components/plugins/viz-components/pareto-chart/option/index.d.ts +1 -4
- package/dist/components/plugins/viz-components/pareto-chart/option/tooltip.d.ts +1 -5
- package/dist/components/plugins/viz-components/pie-chart/option/index.d.ts +1 -4
- package/dist/components/plugins/viz-components/regression-chart/option/tooltip.d.ts +1 -12
- package/dist/components/plugins/viz-components/scatter-chart/option/tooltip.d.ts +1 -6
- package/dist/components/plugins/viz-components/sunburst/option/tooltip.d.ts +1 -7
- package/dist/components/widgets/rich-text-editor/readonly-rich-text-editor.d.ts +3 -1
- package/dist/dashboard.es.js +3342 -3352
- package/dist/dashboard.umd.js +82 -82
- package/dist/stats.html +1 -1
- package/dist/styles/default-echarts-options/index.d.ts +5 -0
- package/dist/styles/default-echarts-options/tooltip.d.ts +6 -0
- package/package.json +1 -1
package/dist/dashboard.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(C,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("crypto-js"),require("dayjs"),require("lodash"),require("numbro"),require("d3-array"),require("mathjs"),require("@faker-js/faker"),require("axios"),require("js-base64"),require("eventemitter2"),require("chroma-js"),require("echarts-for-react/lib/core"),require("echarts-gl"),require("echarts/components"),require("echarts/core"),require("echarts/renderers"),require("react-hook-form"),require("tabler-icons-react"),require("echarts/charts"),require("@tabler/icons-react"),require("@mantine/hooks"),require("@mantine/notifications"),require("popmotion"),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("performant-array-to-tree"),require("@json2csv/whatwg"),require("file-saver"),require("jszip"),require("dom-to-image-more"),require("uuid"),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("react-router-dom"),require("reactflow")):typeof define=="function"&&define.amd?define(["exports","react","@mantine/core","@mantine/modals","ahooks","mobx","mobx-react-lite","crypto-js","dayjs","lodash","numbro","d3-array","mathjs","@faker-js/faker","axios","js-base64","eventemitter2","chroma-js","echarts-for-react/lib/core","echarts-gl","echarts/components","echarts/core","echarts/renderers","react-hook-form","tabler-icons-react","echarts/charts","@tabler/icons-react","@mantine/hooks","@mantine/notifications","popmotion","@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","performant-array-to-tree","@json2csv/whatwg","file-saver","jszip","dom-to-image-more","uuid","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","react-router-dom","reactflow"],f):(C=typeof globalThis<"u"?globalThis:C||self,f(C.dashboard={},C.react,C["@mantine/core"],C["@mantine/modals"],C.ahooks,C.mobx,C["mobx-react-lite"],C.CryptoJS,C.dayjs,C._,C.numbro,C["d3-array"],C.mathjs,C["@faker-js/faker"],C.axios,C["js-base64"],C.eventemitter2,C["chroma-js"],C["echarts-for-react/lib/core"],C["echarts-gl"],C["echarts/components"],C["echarts/core"],C["echarts/renderers"],C["react-hook-form"],C["tabler-icons-react"],C["echarts/charts"],C["@tabler/icons-react"],C["@mantine/hooks"],C["@mantine/notifications"],C.popmotion,C["@monaco-editor/react"],C["d3-regression"],C["@mantine/tiptap"],C["@tiptap/extension-color"],C["@tiptap/extension-highlight"],C["@tiptap/extension-placeholder"],C["@tiptap/extension-subscript"],C["@tiptap/extension-superscript"],C["@tiptap/extension-text-align"],C["@tiptap/extension-text-style"],C["@tiptap/extension-table"],C["@tiptap/extension-table-cell"],C["@tiptap/extension-table-header"],C["@tiptap/extension-table-row"],C["@tiptap/extension-underline"],C["@tiptap/react"],C["@tiptap/starter-kit"],C["prosemirror-keymap"],C["prosemirror-commands"],C["prosemirror-schema-list"],C["@mantine/prism"],C["@tanstack/react-table"],C["react-virtual"],C["@mantine/dates"],C["rc-select"],C["rc-tree-select"],C["react-grid-layout"],C["mobx-state-tree"],C["performant-array-to-tree"],C["@json2csv/whatwg"],C["file-saver"],C.jszip,C["dom-to-image-more"],C.uuid,C["dayjs/plugin/advancedFormat"],C["dayjs/plugin/arraySupport"],C["dayjs/plugin/buddhistEra"],C["dayjs/plugin/calendar"],C["dayjs/plugin/customParseFormat"],C["dayjs/plugin/dayOfYear"],C["dayjs/plugin/duration"],C["dayjs/plugin/isBetween"],C["dayjs/plugin/isLeapYear"],C["dayjs/plugin/isMoment"],C["dayjs/plugin/isoWeek"],C["dayjs/plugin/isoWeeksInYear"],C["dayjs/plugin/isSameOrAfter"],C["dayjs/plugin/isSameOrBefore"],C["dayjs/plugin/isToday"],C["dayjs/plugin/isTomorrow"],C["dayjs/plugin/isYesterday"],C["dayjs/plugin/localeData"],C["dayjs/plugin/localizedFormat"],C["dayjs/plugin/minMax"],C["dayjs/plugin/objectSupport"],C["dayjs/plugin/pluralGetSet"],C["dayjs/plugin/preParsePostFormat"],C["dayjs/plugin/quarterOfYear"],C["dayjs/plugin/relativeTime"],C["dayjs/plugin/timezone"],C["dayjs/plugin/toArray"],C["dayjs/plugin/toObject"],C["dayjs/plugin/updateLocale"],C["dayjs/plugin/utc"],C["dayjs/plugin/weekday"],C["dayjs/plugin/weekOfYear"],C["dayjs/plugin/weekYear"],C["react-router-dom"],C.reactflow))})(this,function(C,f,a,
|
|
1
|
+
(function(C,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("crypto-js"),require("dayjs"),require("lodash"),require("numbro"),require("d3-array"),require("mathjs"),require("@faker-js/faker"),require("axios"),require("js-base64"),require("eventemitter2"),require("chroma-js"),require("echarts-for-react/lib/core"),require("echarts-gl"),require("echarts/components"),require("echarts/core"),require("echarts/renderers"),require("react-hook-form"),require("tabler-icons-react"),require("echarts/charts"),require("@tabler/icons-react"),require("@mantine/hooks"),require("@mantine/notifications"),require("popmotion"),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("performant-array-to-tree"),require("@json2csv/whatwg"),require("file-saver"),require("jszip"),require("dom-to-image-more"),require("uuid"),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("react-router-dom"),require("reactflow")):typeof define=="function"&&define.amd?define(["exports","react","@mantine/core","@mantine/modals","ahooks","mobx","mobx-react-lite","crypto-js","dayjs","lodash","numbro","d3-array","mathjs","@faker-js/faker","axios","js-base64","eventemitter2","chroma-js","echarts-for-react/lib/core","echarts-gl","echarts/components","echarts/core","echarts/renderers","react-hook-form","tabler-icons-react","echarts/charts","@tabler/icons-react","@mantine/hooks","@mantine/notifications","popmotion","@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","performant-array-to-tree","@json2csv/whatwg","file-saver","jszip","dom-to-image-more","uuid","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","react-router-dom","reactflow"],f):(C=typeof globalThis<"u"?globalThis:C||self,f(C.dashboard={},C.react,C["@mantine/core"],C["@mantine/modals"],C.ahooks,C.mobx,C["mobx-react-lite"],C.CryptoJS,C.dayjs,C._,C.numbro,C["d3-array"],C.mathjs,C["@faker-js/faker"],C.axios,C["js-base64"],C.eventemitter2,C["chroma-js"],C["echarts-for-react/lib/core"],C["echarts-gl"],C["echarts/components"],C["echarts/core"],C["echarts/renderers"],C["react-hook-form"],C["tabler-icons-react"],C["echarts/charts"],C["@tabler/icons-react"],C["@mantine/hooks"],C["@mantine/notifications"],C.popmotion,C["@monaco-editor/react"],C["d3-regression"],C["@mantine/tiptap"],C["@tiptap/extension-color"],C["@tiptap/extension-highlight"],C["@tiptap/extension-placeholder"],C["@tiptap/extension-subscript"],C["@tiptap/extension-superscript"],C["@tiptap/extension-text-align"],C["@tiptap/extension-text-style"],C["@tiptap/extension-table"],C["@tiptap/extension-table-cell"],C["@tiptap/extension-table-header"],C["@tiptap/extension-table-row"],C["@tiptap/extension-underline"],C["@tiptap/react"],C["@tiptap/starter-kit"],C["prosemirror-keymap"],C["prosemirror-commands"],C["prosemirror-schema-list"],C["@mantine/prism"],C["@tanstack/react-table"],C["react-virtual"],C["@mantine/dates"],C["rc-select"],C["rc-tree-select"],C["react-grid-layout"],C["mobx-state-tree"],C["performant-array-to-tree"],C["@json2csv/whatwg"],C["file-saver"],C.jszip,C["dom-to-image-more"],C.uuid,C["dayjs/plugin/advancedFormat"],C["dayjs/plugin/arraySupport"],C["dayjs/plugin/buddhistEra"],C["dayjs/plugin/calendar"],C["dayjs/plugin/customParseFormat"],C["dayjs/plugin/dayOfYear"],C["dayjs/plugin/duration"],C["dayjs/plugin/isBetween"],C["dayjs/plugin/isLeapYear"],C["dayjs/plugin/isMoment"],C["dayjs/plugin/isoWeek"],C["dayjs/plugin/isoWeeksInYear"],C["dayjs/plugin/isSameOrAfter"],C["dayjs/plugin/isSameOrBefore"],C["dayjs/plugin/isToday"],C["dayjs/plugin/isTomorrow"],C["dayjs/plugin/isYesterday"],C["dayjs/plugin/localeData"],C["dayjs/plugin/localizedFormat"],C["dayjs/plugin/minMax"],C["dayjs/plugin/objectSupport"],C["dayjs/plugin/pluralGetSet"],C["dayjs/plugin/preParsePostFormat"],C["dayjs/plugin/quarterOfYear"],C["dayjs/plugin/relativeTime"],C["dayjs/plugin/timezone"],C["dayjs/plugin/toArray"],C["dayjs/plugin/toObject"],C["dayjs/plugin/updateLocale"],C["dayjs/plugin/utc"],C["dayjs/plugin/weekday"],C["dayjs/plugin/weekOfYear"],C["dayjs/plugin/weekYear"],C["react-router-dom"],C.reactflow))})(this,function(C,f,a,Ae,V,W,S,Jr,I,y,F,Nt,gc,mc,tt,Zr,Hr,nt,we,HD,O,yc,Ce,b,_,te,k,le,xt,ft,me,bc,q,ei,ti,ni,si,ri,ii,ai,oi,li,ci,di,ui,pi,hi,eI,ye,ss,ct,Ge,jc,vc,xi,fi,ln,g,wc,Cc,rs,Sc,gi,is,_c,kc,Tc,Dc,Ic,Mc,Ac,zc,Ec,Pc,Lc,Oc,Bc,$c,Vc,Nc,qc,Fc,Gc,Wc,Rc,Qc,Uc,Yc,Kc,Xc,Jc,Zc,Hc,ed,td,nd,sd,rd,je){"use strict";var JD=Object.defineProperty;var ZD=(C,f,a)=>f in C?JD(C,f,{enumerable:!0,configurable:!0,writable:!0,value:a}):C[f]=a;var E=(C,f,a)=>(ZD(C,typeof f!="symbol"?f+"":f,a),a);function qt(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const id=qt(Jr),ad=qt(Nt),cn=qt(gc),Y=qt(yc),dt=qt(bc);var as={exports:{}},Ft={};/**
|
|
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 mi;function
|
|
9
|
+
*/var mi;function od(){if(mi)return Ft;mi=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,d,u){var p,h={},x=null,m=null;u!==void 0&&(x=""+u),d.key!==void 0&&(x=""+d.key),d.ref!==void 0&&(m=d.ref);for(p in d)r.call(d,p)&&!o.hasOwnProperty(p)&&(h[p]=d[p]);if(c&&c.defaultProps)for(p in d=c.defaultProps,d)h[p]===void 0&&(h[p]=d[p]);return{$$typeof:t,type:c,key:x,ref:m,props:h,_owner:i.current}}return Ft.Fragment=n,Ft.jsx=l,Ft.jsxs=l,Ft}var Gt={};/**
|
|
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 yi;function
|
|
18
|
-
`+Wr+v}}var Rr=!1,Hn;{var
|
|
19
|
-
`),
|
|
20
|
-
`),
|
|
21
|
-
`+G[
|
|
17
|
+
*/var yi;function ld(){return yi||(yi=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"),d=Symbol.for("react.forward_ref"),u=Symbol.for("react.suspense"),p=Symbol.for("react.suspense_list"),h=Symbol.for("react.memo"),x=Symbol.for("react.lazy"),m=Symbol.for("react.offscreen"),j=Symbol.iterator,w="@@iterator";function T(v){if(v===null||typeof v!="object")return null;var D=j&&v[j]||v[w];return typeof D=="function"?D:null}var M=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function P(v){{for(var D=arguments.length,z=new Array(D>1?D-1:0),N=1;N<D;N++)z[N-1]=arguments[N];U("error",v,z)}}function U(v,D,z){{var N=M.ReactDebugCurrentFrame,Z=N.getStackAddendum();Z!==""&&(D+="%s",z=z.concat([Z]));var ee=z.map(function(R){return String(R)});ee.unshift("Warning: "+D),Function.prototype.apply.call(console[v],console,ee)}}var re=!1,Q=!1,ae=!1,pe=!1,ge=!1,kt;kt=Symbol.for("react.module.reference");function Ke(v){return!!(typeof v=="string"||typeof v=="function"||v===r||v===o||ge||v===i||v===u||v===p||pe||v===m||re||Q||ae||typeof v=="object"&&v!==null&&(v.$$typeof===x||v.$$typeof===h||v.$$typeof===l||v.$$typeof===c||v.$$typeof===d||v.$$typeof===kt||v.getModuleId!==void 0))}function Fr(v,D,z){var N=v.displayName;if(N)return N;var Z=D.displayName||D.name||"";return Z!==""?z+"("+Z+")":z}function rn(v){return v.displayName||"Context"}function ot(v){if(v==null)return null;if(typeof v.tag=="number"&&P("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof v=="function")return v.displayName||v.name||null;if(typeof v=="string")return v;switch(v){case r:return"Fragment";case n:return"Portal";case o:return"Profiler";case i:return"StrictMode";case u:return"Suspense";case p:return"SuspenseList"}if(typeof v=="object")switch(v.$$typeof){case c:var D=v;return rn(D)+".Consumer";case l:var z=v;return rn(z._context)+".Provider";case d:return Fr(v,v.render,"ForwardRef");case h:var N=v.displayName||null;return N!==null?N:ot(v.type)||"Memo";case x:{var Z=v,ee=Z._payload,R=Z._init;try{return ot(R(ee))}catch{return null}}}return null}var Tt=Object.assign,an=0,Yl,Kl,Xl,Jl,Zl,Hl,ec;function tc(){}tc.__reactDisabledLog=!0;function kD(){{if(an===0){Yl=console.log,Kl=console.info,Xl=console.warn,Jl=console.error,Zl=console.group,Hl=console.groupCollapsed,ec=console.groupEnd;var v={configurable:!0,enumerable:!0,value:tc,writable:!0};Object.defineProperties(console,{info:v,log:v,warn:v,error:v,group:v,groupCollapsed:v,groupEnd:v})}an++}}function TD(){{if(an--,an===0){var v={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:Tt({},v,{value:Yl}),info:Tt({},v,{value:Kl}),warn:Tt({},v,{value:Xl}),error:Tt({},v,{value:Jl}),group:Tt({},v,{value:Zl}),groupCollapsed:Tt({},v,{value:Hl}),groupEnd:Tt({},v,{value:ec})})}an<0&&P("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var Gr=M.ReactCurrentDispatcher,Wr;function Zn(v,D,z){{if(Wr===void 0)try{throw Error()}catch(Z){var N=Z.stack.trim().match(/\n( *(at )?)/);Wr=N&&N[1]||""}return`
|
|
18
|
+
`+Wr+v}}var Rr=!1,Hn;{var DD=typeof WeakMap=="function"?WeakMap:Map;Hn=new DD}function nc(v,D){if(!v||Rr)return"";{var z=Hn.get(v);if(z!==void 0)return z}var N;Rr=!0;var Z=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var ee;ee=Gr.current,Gr.current=null,kD();try{if(D){var R=function(){throw Error()};if(Object.defineProperty(R.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(R,[])}catch(lt){N=lt}Reflect.construct(v,[],R)}else{try{R.call()}catch(lt){N=lt}v.call(R.prototype)}}else{try{throw Error()}catch(lt){N=lt}v()}}catch(lt){if(lt&&N&&typeof lt.stack=="string"){for(var G=lt.stack.split(`
|
|
19
|
+
`),ke=N.stack.split(`
|
|
20
|
+
`),oe=G.length-1,he=ke.length-1;oe>=1&&he>=0&&G[oe]!==ke[he];)he--;for(;oe>=1&&he>=0;oe--,he--)if(G[oe]!==ke[he]){if(oe!==1||he!==1)do if(oe--,he--,he<0||G[oe]!==ke[he]){var Fe=`
|
|
21
|
+
`+G[oe].replace(" at new "," at ");return v.displayName&&Fe.includes("<anonymous>")&&(Fe=Fe.replace("<anonymous>",v.displayName)),typeof v=="function"&&Hn.set(v,Fe),Fe}while(oe>=1&&he>=0);break}}}finally{Rr=!1,Gr.current=ee,TD(),Error.prepareStackTrace=Z}var Vt=v?v.displayName||v.name:"",fc=Vt?Zn(Vt):"";return typeof v=="function"&&Hn.set(v,fc),fc}function ID(v,D,z){return nc(v,!1)}function MD(v){var D=v.prototype;return!!(D&&D.isReactComponent)}function es(v,D,z){if(v==null)return"";if(typeof v=="function")return nc(v,MD(v));if(typeof v=="string")return Zn(v);switch(v){case u:return Zn("Suspense");case p:return Zn("SuspenseList")}if(typeof v=="object")switch(v.$$typeof){case d:return ID(v.render);case h:return es(v.type,D,z);case x:{var N=v,Z=N._payload,ee=N._init;try{return es(ee(Z),D,z)}catch{}}}return""}var ts=Object.prototype.hasOwnProperty,sc={},rc=M.ReactDebugCurrentFrame;function ns(v){if(v){var D=v._owner,z=es(v.type,v._source,D?D.type:null);rc.setExtraStackFrame(z)}else rc.setExtraStackFrame(null)}function AD(v,D,z,N,Z){{var ee=Function.call.bind(ts);for(var R in v)if(ee(v,R)){var G=void 0;try{if(typeof v[R]!="function"){var ke=Error((N||"React class")+": "+z+" type `"+R+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof v[R]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw ke.name="Invariant Violation",ke}G=v[R](D,R,N,z,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(oe){G=oe}G&&!(G instanceof Error)&&(ns(Z),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",z,R,typeof G),ns(null)),G instanceof Error&&!(G.message in sc)&&(sc[G.message]=!0,ns(Z),P("Failed %s type: %s",z,G.message),ns(null))}}}var zD=Array.isArray;function Qr(v){return zD(v)}function ED(v){{var D=typeof Symbol=="function"&&Symbol.toStringTag,z=D&&v[Symbol.toStringTag]||v.constructor.name||"Object";return z}}function PD(v){try{return ic(v),!1}catch{return!0}}function ic(v){return""+v}function ac(v){if(PD(v))return P("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",ED(v)),ic(v)}var on=M.ReactCurrentOwner,LD={key:!0,ref:!0,__self:!0,__source:!0},oc,lc,Ur;Ur={};function OD(v){if(ts.call(v,"ref")){var D=Object.getOwnPropertyDescriptor(v,"ref").get;if(D&&D.isReactWarning)return!1}return v.ref!==void 0}function BD(v){if(ts.call(v,"key")){var D=Object.getOwnPropertyDescriptor(v,"key").get;if(D&&D.isReactWarning)return!1}return v.key!==void 0}function $D(v,D){if(typeof v.ref=="string"&&on.current&&D&&on.current.stateNode!==D){var z=ot(on.current.type);Ur[z]||(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',ot(on.current.type),v.ref),Ur[z]=!0)}}function VD(v,D){{var z=function(){oc||(oc=!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)",D))};z.isReactWarning=!0,Object.defineProperty(v,"key",{get:z,configurable:!0})}}function ND(v,D){{var z=function(){lc||(lc=!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)",D))};z.isReactWarning=!0,Object.defineProperty(v,"ref",{get:z,configurable:!0})}}var qD=function(v,D,z,N,Z,ee,R){var G={$$typeof:t,type:v,key:D,ref:z,props:R,_owner:ee};return G._store={},Object.defineProperty(G._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(G,"_self",{configurable:!1,enumerable:!1,writable:!1,value:N}),Object.defineProperty(G,"_source",{configurable:!1,enumerable:!1,writable:!1,value:Z}),Object.freeze&&(Object.freeze(G.props),Object.freeze(G)),G};function FD(v,D,z,N,Z){{var ee,R={},G=null,ke=null;z!==void 0&&(ac(z),G=""+z),BD(D)&&(ac(D.key),G=""+D.key),OD(D)&&(ke=D.ref,$D(D,Z));for(ee in D)ts.call(D,ee)&&!LD.hasOwnProperty(ee)&&(R[ee]=D[ee]);if(v&&v.defaultProps){var oe=v.defaultProps;for(ee in oe)R[ee]===void 0&&(R[ee]=oe[ee])}if(G||ke){var he=typeof v=="function"?v.displayName||v.name||"Unknown":v;G&&VD(R,he),ke&&ND(R,he)}return qD(v,G,ke,Z,N,on.current,R)}}var Yr=M.ReactCurrentOwner,cc=M.ReactDebugCurrentFrame;function $t(v){if(v){var D=v._owner,z=es(v.type,v._source,D?D.type:null);cc.setExtraStackFrame(z)}else cc.setExtraStackFrame(null)}var Kr;Kr=!1;function Xr(v){return typeof v=="object"&&v!==null&&v.$$typeof===t}function dc(){{if(Yr.current){var v=ot(Yr.current.type);if(v)return`
|
|
22
22
|
|
|
23
|
-
Check the render method of \``+v+"`."}return""}}function
|
|
23
|
+
Check the render method of \``+v+"`."}return""}}function GD(v){{if(v!==void 0){var D=v.fileName.replace(/^.*[\\\/]/,""),z=v.lineNumber;return`
|
|
24
24
|
|
|
25
|
-
Check your code at `+D+":"+z+"."}return""}}var uc={};function
|
|
25
|
+
Check your code at `+D+":"+z+"."}return""}}var uc={};function WD(v){{var D=dc();if(!D){var z=typeof v=="string"?v:v.displayName||v.name;z&&(D=`
|
|
26
26
|
|
|
27
|
-
Check the top-level render call using <`+z+">.")}return D}}function
|
|
27
|
+
Check the top-level render call using <`+z+">.")}return D}}function pc(v,D){{if(!v._store||v._store.validated||v.key!=null)return;v._store.validated=!0;var z=WD(D);if(uc[z])return;uc[z]=!0;var N="";v&&v._owner&&v._owner!==Yr.current&&(N=" It was passed a child from "+ot(v._owner.type)+"."),$t(v),P('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',z,N),$t(null)}}function hc(v,D){{if(typeof v!="object")return;if(Qr(v))for(var z=0;z<v.length;z++){var N=v[z];Xr(N)&&pc(N,D)}else if(Xr(v))v._store&&(v._store.validated=!0);else if(v){var Z=T(v);if(typeof Z=="function"&&Z!==v.entries)for(var ee=Z.call(v),R;!(R=ee.next()).done;)Xr(R.value)&&pc(R.value,D)}}}function RD(v){{var D=v.type;if(D==null||typeof D=="string")return;var z;if(typeof D=="function")z=D.propTypes;else if(typeof D=="object"&&(D.$$typeof===d||D.$$typeof===h))z=D.propTypes;else return;if(z){var N=ot(D);AD(z,v.props,"prop",N,v)}else if(D.PropTypes!==void 0&&!Kr){Kr=!0;var Z=ot(D);P("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",Z||"Unknown")}typeof D.getDefaultProps=="function"&&!D.getDefaultProps.isReactClassApproved&&P("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function QD(v){{for(var D=Object.keys(v.props),z=0;z<D.length;z++){var N=D[z];if(N!=="children"&&N!=="key"){$t(v),P("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",N),$t(null);break}}v.ref!==null&&($t(v),P("Invalid attribute `ref` supplied to `React.Fragment`."),$t(null))}}function xc(v,D,z,N,Z,ee){{var R=Ke(v);if(!R){var G="";(v===void 0||typeof v=="object"&&v!==null&&Object.keys(v).length===0)&&(G+=" 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 ke=GD(Z);ke?G+=ke:G+=dc();var oe;v===null?oe="null":Qr(v)?oe="array":v!==void 0&&v.$$typeof===t?(oe="<"+(ot(v.type)||"Unknown")+" />",G=" Did you accidentally export a JSX literal instead of a component?"):oe=typeof v,P("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",oe,G)}var he=FD(v,D,z,Z,ee);if(he==null)return he;if(R){var Fe=D.children;if(Fe!==void 0)if(N)if(Qr(Fe)){for(var Vt=0;Vt<Fe.length;Vt++)hc(Fe[Vt],v);Object.freeze&&Object.freeze(Fe)}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 hc(Fe,v)}return v===r?QD(he):RD(he),he}}function UD(v,D,z){return xc(v,D,z,!0)}function YD(v,D,z){return xc(v,D,z,!1)}var KD=YD,XD=UD;Gt.Fragment=r,Gt.jsx=KD,Gt.jsxs=XD}()),Gt}process.env.NODE_ENV==="production"?as.exports=od():as.exports=ld();var s=as.exports;const gt={CryptoJS:Jr,d3Array:ad,dayjs:I,lodash:y,numbro:F,mathjs:cn,faker:mc.faker},cd=[{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"}],dd=e=>`
|
|
28
28
|
<tr>
|
|
29
29
|
<td><code>${e.name}</code></td>
|
|
30
30
|
<td>
|
|
@@ -36,7 +36,7 @@ Check the top-level render call using <`+z+">.")}return D}}function dc(v,D){{if(
|
|
|
36
36
|
>
|
|
37
37
|
</td>
|
|
38
38
|
</tr>
|
|
39
|
-
`,
|
|
39
|
+
`,ud=`
|
|
40
40
|
<p>
|
|
41
41
|
Parameter <code>utils</code> is <code>functionUtils</code>, which contains:
|
|
42
42
|
</p>
|
|
@@ -48,19 +48,19 @@ Check the top-level render call using <`+z+">.")}return D}}function dc(v,D){{if(
|
|
|
48
48
|
</tr>
|
|
49
49
|
</thead>
|
|
50
50
|
<tbody>
|
|
51
|
-
${
|
|
51
|
+
${cd.map(dd).join("")}
|
|
52
52
|
</tbody>
|
|
53
53
|
</table>
|
|
54
|
-
`;function os(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 ls(e,t){try{return os(e,t)}catch(n){return console.error(n),n.message}}function du({sql:e,pre_process:t}){if(!t.trim())return e;try{return new Function(`return ${t}`)()({sql:e},gt)}catch(n){return console.error(n),e}}function pu(e,t,n){if(!e.trim())return t;try{return new Function(`return ${e}`)()(t,gt,n)}catch(r){return console.error(r),t}}function hu(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 xu(e,t){let n=hu(e);return n+="&key="+t,ru.MD5(n).toString().toUpperCase()}class bi{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:xu({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 tt(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 fu{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 ji extends bi{constructor(){super(...arguments);E(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 vi{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 Dt=new ji;function cs(e){Dt.baseURL!==e.apiBaseURL&&(Dt.baseURL=e.apiBaseURL),e.app_id&&(Dt.app_id=e.app_id),e.app_secret&&(Dt.app_secret=e.app_secret),e.makeQueryENV&&(Dt.makeQueryENV=e.makeQueryENV)}const wi=new vi(Dt),Xe=wi;function Ci(){return{filters:{},context:{}}}function us(e){const t=Ci();if(!e)return Ci();const{filters:n=t.filters,context:r=t.context}=e;return{filters:n,context:r}}function gu(e,t){const n=Zr.decode(t);n!==e&&(console.error("Inconsistent sql"),console.groupCollapsed("Inconsistent sql"),console.table({before:e,after:t,v:n}),console.groupEnd())}async function mu({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,p=os(c,n),h=du({sql:p,pre_process:u}),x=Zr.encode(h);gu(h,x);let m=await Xe.query(i)({type:o,key:l,query:x,...r},{params:{name:t}});return m=pu(d,m,us(n)),m}async function yu({type:e,key:t,configString:n,name:r,additionals:i},o){try{return await Xe.httpDataSourceQuery(o)({type:e,key:t,query:n,...i},{params:{name:r}})}catch(l){if(tt.isCancel(l))throw l;return console.error(l),l}}async function ds(){try{return(await Xe.post()("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}},{})).data}catch(e){return console.error(e),[]}}async function Si(){try{return(await Xe.post()("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}},{})).data}catch(e){return console.error(e),[]}}class _i{constructor(t){E(this,"rootRef");this.rootRef=W.observable({current:t})}async deleteItem(t){W.runInAction(()=>{y.unset(this.rootRef.current,[t])})}getItem(t){const n=this.getValueFromRoot(t);return Promise.resolve(n)}getValueFromRoot(t){return t===null?W.toJS(this.rootRef.current):y.get(this.rootRef.current,[t])}setItem(t,n){if(t===null)if(y.isObject(n))W.runInAction(()=>{this.rootRef.current=n});else throw new Error("Cannot set root value to non-object");else W.runInAction(()=>{y.set(this.rootRef.current,[t],n)});return Promise.resolve(this.getItem(t))}watchItem(t,n,r){return W.reaction(()=>this.getValueFromRoot(t),(i,o)=>{n(i,o)},{requiresObservable:!0,fireImmediately:y.get(r,"fireImmediately",!1)})}}class bu{constructor(){E(this,"channels",new Map);E(this,"globalChannel",new Hr)}getChannel(t){const n=this.channels.get(t);if(n)return n;const r=new Hr;return this.channels.set(t,r),r}}class ju{constructor(t){E(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 bu,instanceData:new _i(t.viz.conf)};return this.instances.set(t.id,r),r}}function ki(e,t,n,r){return{vizManager:n,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new _i({}),colorPalette:{getColor(){return()=>""}},data:t,variables:r}}const vu=e=>{const{panel:t,vizManager:n,data:r,variables:i}=e,o=n.resolveComponent(t.viz.type),l=n.getOrCreateInstance(t),c={...ki(l,r,n,i),viewport:{width:t.layout.w,height:t.layout.h}},u=o.viewRender;return s.jsx(u,{context:c,instance:l,...y.omit(e,["panel","vizManager","data"])})},wu=e=>{const{vizManager:t,panel:n,data:r,variables:i}=e,o=t.resolveComponent(n.viz.type),l=t.getOrCreateInstance(n),c={...ki(l,r,t,i)},u=o.configRender;return s.jsx(u,{context:c,instance:l,...y.omit(e,["panel","vizManager","data"])})},Ti=(e,t)=>{const n=nt.bezier(e),r=nt.bezier(t);return function(i){return i<50?n(i*2/100).hex():r((i-50)*2/100).hex()}},un=e=>{const t=nt.bezier(e);return function(n){return t(n/100).hex()}},Cu={type:"interpolation",displayName:"Red / Green",getColor:Ti(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},Su={type:"interpolation",displayName:"Yellow / Blue",getColor:Ti(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},_u={type:"interpolation",displayName:"Red",getColor:un(["#fff7f1","darkred"]),name:"red",category:"sequential"},ku={type:"interpolation",displayName:"Green",getColor:un(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},Tu={type:"interpolation",displayName:"Blue",getColor:un(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},Du={type:"interpolation",displayName:"Orange",getColor:un(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class Iu{constructor(t){E(this,"symbol");this.symbol=Symbol(t)}}function st(e){return new Iu(e)}class ps{constructor(){E(this,"parent");E(this,"factoryRegistry",new Map);E(this,"instanceRegistry",new Map)}createScoped(){const t=new ps;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 Di="10.54.0",Mu=Object.freeze(Object.defineProperty({__proto__:null,version:Di},Symbol.toStringTag,{value:"Module"}));class Au{constructor(t){E(this,"staticColors",new Map);E(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 zu{constructor(){E(this,"plugins",new Map);E(this,"vizComponents",new Map);E(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 Eu{constructor(){E(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 re extends Eu{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},We=e=>Math.max(0,e-ke.left-ke.right),Re=e=>Math.max(0,e-ke.top-ke.bottom),Wt=(e,t)=>({width:We(e),height:Re(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});function A(e){const[t,n]=e.split(".");return{queryID:t,columnKey:n}}function Pu(e){return e.includes(".")?A(e):{queryID:"",columnKey:e}}function rt(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 Rt(e,t){const{queryID:n}=A(t);return n?e[n]:[]}function Lu(e){return Object.values(e)[0]}function dn(e,t){const{queryID:n,columnKey:r}=A(t);return e[r]}const hs={x_axis_data_key:"",y_axis_data_key:"",z_axis_data_key:"",xAxis3D:{type:"value",name:"X Axis Name"},yAxis3D:{type:"value",name:"Y Axis Name"},zAxis3D:{type:"value",name:"Z Axis Name"}};Y.use([O.GridComponent,O.VisualMapComponent,O.LegendComponent,O.TooltipComponent,we.CanvasRenderer]);function Ou({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:p}=y.defaults({},t,hs),h=f.useMemo(()=>Rt(n,o),[n,o]),{x,y:m,z:j}=f.useMemo(()=>({x:A(o),y:A(l),z:A(c)}),[o,l,c]),{min:w,max:T}=f.useMemo(()=>{const P=y.minBy(h,se=>se[j.columnKey]),U=y.maxBy(h,se=>se[j.columnKey]);return{min:y.get(P,j.columnKey),max:y.get(U,j.columnKey)}},[h,j]),M={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:w,max:T,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:u,yAxis3D:d,zAxis3D:p,grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}},series:[{type:"bar3D",wireframe:{},data:h.map(P=>[P[x.columnKey],P[m.columnKey],P[j.columnKey]])}]};return t?s.jsx(Te,{width:r,height:i,children:s.jsx(ve,{echarts:Y,option:M,style:Wt(r,i),notMerge:!0,theme:"merico-light"})}):null}const Ii=f.createContext(null),xs=Ii.Provider;function fs(){const e=f.useContext(Ii);if(!e)throw new Error("Please use DashboardModelContextProvider");return e}const K=()=>fs(),gs=()=>fs(),Mi=f.createContext({searchButtonProps:{}}),ms=Mi.Provider;function Ai(){return f.useContext(Mi)}const zi=f.createContext(null),ys=zi.Provider;function Ei(){const e=f.useContext(zi);if(!e)throw new Error("Please use ContentModelContextProvider");return e}const X=()=>Ei(),le=()=>Ei(),Bu={inEditMode:!1},pn=f.createContext(Bu),Pi=f.createContext({panel:null,data:{},loading:!1,errors:[],downloadPanelScreenshot:()=>{}}),bs=Pi.Provider;function Li(){const e=f.useContext(Pi);if(!e.panel)throw new Error("Please use PanelContextProvider");return e}const dt=()=>Li(),Le=()=>Li(),$u={fullScreenPanelID:"",setFullScreenPanelID:y.noop},js=f.createContext($u);function Oi(){const e=f.useContext(js);if(!e)throw new Error("Please use FullScreenPanelContext.Provider");return e}const B=S.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(()=>{const p=[...u.dataFieldOptions];return i&&p.unshift({label:"unset",value:"",group:""}),p},[u.dataFieldOptions]);return s.jsx(a.Select,{ref:c,label:e,data:d,value:n,onChange:r,required:t,sx:o,maxDropdownHeight:500,...l})}));function Vu({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=y.defaults({},t,hs),{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(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(_.DeviceFloppy,{size:20}),s.jsx(a.Text,{ml:"md",children:"Save"})]})})]})}):null}function Nu(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 qu extends re{constructor(){super(...arguments);E(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:Nu(i,r)}})}}const Fu={displayName:"Bar Chart (3D)",displayGroup:"ECharts-based charts",migrator:new qu,name:"bar-3d",viewRender:Ou,configRender:Vu,createConfig(){return{version:2,config:y.cloneDeep(hs)}}};class Ce 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}}const ye={mantissa:0,output:"number",trimMantissa:!1,average:!1},Bi={root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}};function Gu({value:e,onChange:t},n){const r=c=>{t({...e,output:c})},i=c=>{const u=c===0?!1:e.trimMantissa;t({...e,mantissa:c,trimMantissa:u})},o=c=>{t({...e,trimMantissa:c.currentTarget.checked})},l=c=>{t({...e,average:c.currentTarget.checked})};return 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:"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:Bi})]}),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:Bi})]}),s.jsxs(a.Stack,{spacing:0,children:[s.jsx(a.Text,{weight:"bold",children:"Preview"}),s.jsx(Ce,{children:s.jsxs(a.Group,{position:"apart",children:[s.jsxs(a.Text,{size:12,color:"gray",children:["123456789 ",s.jsx(_.ArrowRight,{size:9})," ",F(123456789).format(e)]}),s.jsxs(a.Text,{size:12,color:"gray",children:["1234 ",s.jsx(_.ArrowRight,{size:9})," ",F(1234).format(e)]}),s.jsxs(a.Text,{size:12,color:"gray",children:["0.1234 ",s.jsx(_.ArrowRight,{size:9})," ",F(.1234).format(e)]})]})})]})]})}const Oe=f.forwardRef(Gu),Be={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
55
|
-
`)},$i={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:
|
|
54
|
+
`;function os(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 ls(e,t){try{return os(e,t)}catch(n){return console.error(n),n.message}}function pd({sql:e,pre_process:t}){if(!t.trim())return e;try{return new Function(`return ${t}`)()({sql:e},gt)}catch(n){return console.error(n),e}}function hd(e,t,n){if(!e.trim())return t;try{return new Function(`return ${e}`)()(t,gt,n)}catch(r){return console.error(r),t}}function xd(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 fd(e,t){let n=xd(e);return n+="&key="+t,id.MD5(n).toString().toUpperCase()}class bi{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:fd({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),d=this.buildAxiosConfig(t,r,i,o,c,n);return tt(d).then(u=>l?u:u.data).catch(u=>Promise.reject(u))}}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 gd{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 ji extends bi{constructor(){super(...arguments);E(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 vi{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 Dt=new ji;function cs(e){Dt.baseURL!==e.apiBaseURL&&(Dt.baseURL=e.apiBaseURL),e.app_id&&(Dt.app_id=e.app_id),e.app_secret&&(Dt.app_secret=e.app_secret),e.makeQueryENV&&(Dt.makeQueryENV=e.makeQueryENV)}const wi=new vi(Dt),Xe=wi;function Ci(){return{filters:{},context:{}}}function ds(e){const t=Ci();if(!e)return Ci();const{filters:n=t.filters,context:r=t.context}=e;return{filters:n,context:r}}function md(e,t){const n=Zr.decode(t);n!==e&&(console.error("Inconsistent sql"),console.groupCollapsed("Inconsistent sql"),console.table({before:e,after:t,v:n}),console.groupEnd())}async function yd({query:e,name:t,payload:n,additionals:r},i){if(!e.sql)return[];const{type:o,key:l,sql:c,pre_process:d,post_process:u}=e,p=os(c,n),h=pd({sql:p,pre_process:d}),x=Zr.encode(h);md(h,x);let m=await Xe.query(i)({type:o,key:l,query:x,...r},{params:{name:t}});return m=hd(u,m,ds(n)),m}async function bd({type:e,key:t,configString:n,name:r,additionals:i},o){try{return await Xe.httpDataSourceQuery(o)({type:e,key:t,query:n,...i},{params:{name:r}})}catch(l){if(tt.isCancel(l))throw l;return console.error(l),l}}async function us(){try{return(await Xe.post()("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}},{})).data}catch(e){return console.error(e),[]}}async function Si(){try{return(await Xe.post()("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}},{})).data}catch(e){return console.error(e),[]}}class _i{constructor(t){E(this,"rootRef");this.rootRef=W.observable({current:t})}async deleteItem(t){W.runInAction(()=>{y.unset(this.rootRef.current,[t])})}getItem(t){const n=this.getValueFromRoot(t);return Promise.resolve(n)}getValueFromRoot(t){return t===null?W.toJS(this.rootRef.current):y.get(this.rootRef.current,[t])}setItem(t,n){if(t===null)if(y.isObject(n))W.runInAction(()=>{this.rootRef.current=n});else throw new Error("Cannot set root value to non-object");else W.runInAction(()=>{y.set(this.rootRef.current,[t],n)});return Promise.resolve(this.getItem(t))}watchItem(t,n,r){return W.reaction(()=>this.getValueFromRoot(t),(i,o)=>{n(i,o)},{requiresObservable:!0,fireImmediately:y.get(r,"fireImmediately",!1)})}}class jd{constructor(){E(this,"channels",new Map);E(this,"globalChannel",new Hr)}getChannel(t){const n=this.channels.get(t);if(n)return n;const r=new Hr;return this.channels.set(t,r),r}}class vd{constructor(t){E(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 jd,instanceData:new _i(t.viz.conf)};return this.instances.set(t.id,r),r}}function ki(e,t,n,r){return{vizManager:n,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new _i({}),colorPalette:{getColor(){return()=>""}},data:t,variables:r}}const wd=e=>{const{panel:t,vizManager:n,data:r,variables:i}=e,o=n.resolveComponent(t.viz.type),l=n.getOrCreateInstance(t),c={...ki(l,r,n,i),viewport:{width:t.layout.w,height:t.layout.h}},d=o.viewRender;return s.jsx(d,{context:c,instance:l,...y.omit(e,["panel","vizManager","data"])})},Cd=e=>{const{vizManager:t,panel:n,data:r,variables:i}=e,o=t.resolveComponent(n.viz.type),l=t.getOrCreateInstance(n),c={...ki(l,r,t,i)},d=o.configRender;return s.jsx(d,{context:c,instance:l,...y.omit(e,["panel","vizManager","data"])})},Ti=(e,t)=>{const n=nt.bezier(e),r=nt.bezier(t);return function(i){return i<50?n(i*2/100).hex():r((i-50)*2/100).hex()}},dn=e=>{const t=nt.bezier(e);return function(n){return t(n/100).hex()}},Sd={type:"interpolation",displayName:"Red / Green",getColor:Ti(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},_d={type:"interpolation",displayName:"Yellow / Blue",getColor:Ti(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},kd={type:"interpolation",displayName:"Red",getColor:dn(["#fff7f1","darkred"]),name:"red",category:"sequential"},Td={type:"interpolation",displayName:"Green",getColor:dn(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},Dd={type:"interpolation",displayName:"Blue",getColor:dn(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},Id={type:"interpolation",displayName:"Orange",getColor:dn(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class Md{constructor(t){E(this,"symbol");this.symbol=Symbol(t)}}function st(e){return new Md(e)}class ps{constructor(){E(this,"parent");E(this,"factoryRegistry",new Map);E(this,"instanceRegistry",new Map)}createScoped(){const t=new ps;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 Di="10.55.1",Ad=Object.freeze(Object.defineProperty({__proto__:null,version:Di},Symbol.toStringTag,{value:"Module"}));class zd{constructor(t){E(this,"staticColors",new Map);E(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 Ed{constructor(){E(this,"plugins",new Map);E(this,"vizComponents",new Map);E(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 Pd{constructor(){E(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,d)=>d.handler(c,r),n)}}class ie extends Pd{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}},Te={top:16,right:16,bottom:16,left:16},We=e=>Math.max(0,e-Te.left-Te.right),Re=e=>Math.max(0,e-Te.top-Te.bottom),Wt=(e,t)=>({width:We(e),height:Re(t)}),De=({width:e,height:t,children:n})=>s.jsx(a.Box,{pt:Te.top,pr:Te.right,pb:Te.bottom,pl:Te.left,sx:{width:e,height:t,overflow:"hidden",position:"relative"},children:n});function A(e){const[t,n]=e.split(".");return{queryID:t,columnKey:n}}function Ld(e){return e.includes(".")?A(e):{queryID:"",columnKey:e}}function rt(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 Rt(e,t){const{queryID:n}=A(t);return n?e[n]:[]}function Od(e){return Object.values(e)[0]}function un(e,t){const{queryID:n,columnKey:r}=A(t);return e[r]}const hs={x_axis_data_key:"",y_axis_data_key:"",z_axis_data_key:"",xAxis3D:{type:"value",name:"X Axis Name"},yAxis3D:{type:"value",name:"Y Axis Name"},zAxis3D:{type:"value",name:"Z Axis Name"}};Y.use([O.GridComponent,O.VisualMapComponent,O.LegendComponent,O.TooltipComponent,Ce.CanvasRenderer]);function Bd({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:d,yAxis3D:u,zAxis3D:p}=y.defaults({},t,hs),h=f.useMemo(()=>Rt(n,o),[n,o]),{x,y:m,z:j}=f.useMemo(()=>({x:A(o),y:A(l),z:A(c)}),[o,l,c]),{min:w,max:T}=f.useMemo(()=>{const P=y.minBy(h,re=>re[j.columnKey]),U=y.maxBy(h,re=>re[j.columnKey]);return{min:y.get(P,j.columnKey),max:y.get(U,j.columnKey)}},[h,j]),M={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:w,max:T,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:d,yAxis3D:u,zAxis3D:p,grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}},series:[{type:"bar3D",wireframe:{},data:h.map(P=>[P[x.columnKey],P[m.columnKey],P[j.columnKey]])}]};return t?s.jsx(De,{width:r,height:i,children:s.jsx(we,{echarts:Y,option:M,style:Wt(r,i),notMerge:!0,theme:"merico-light"})}):null}const Ii=f.createContext(null),xs=Ii.Provider;function fs(){const e=f.useContext(Ii);if(!e)throw new Error("Please use DashboardModelContextProvider");return e}const K=()=>fs(),gs=()=>fs(),Mi=f.createContext({searchButtonProps:{}}),ms=Mi.Provider;function Ai(){return f.useContext(Mi)}const zi=f.createContext(null),ys=zi.Provider;function Ei(){const e=f.useContext(zi);if(!e)throw new Error("Please use ContentModelContextProvider");return e}const X=()=>Ei(),ce=()=>Ei(),$d={inEditMode:!1},pn=f.createContext($d),Pi=f.createContext({panel:null,data:{},loading:!1,errors:[],downloadPanelScreenshot:()=>{}}),bs=Pi.Provider;function Li(){const e=f.useContext(Pi);if(!e.panel)throw new Error("Please use PanelContextProvider");return e}const ut=()=>Li(),Le=()=>Li(),Vd={fullScreenPanelID:"",setFullScreenPanelID:y.noop},js=f.createContext(Vd);function Oi(){const e=f.useContext(js);if(!e)throw new Error("Please use FullScreenPanelContext.Provider");return e}const B=S.observer(f.forwardRef(({label:e,required:t,value:n,onChange:r,clearable:i=!1,sx:o,...l},c)=>{const{panel:d}=Le(),u=f.useMemo(()=>{const p=[...d.dataFieldOptions];return i&&p.unshift({label:"unset",value:"",group:""}),p},[d.dataFieldOptions]);return s.jsx(a.Select,{ref:c,label:e,data:u,value:n,onChange:r,required:t,sx:o,maxDropdownHeight:500,...l})}));function Nd({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=y.defaults({},t,hs),{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(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(_.DeviceFloppy,{size:20}),s.jsx(a.Text,{ml:"md",children:"Save"})]})})]})}):null}function qd(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_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 Fd extends ie{constructor(){super(...arguments);E(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:qd(i,r)}})}}const Gd={displayName:"Bar Chart (3D)",displayGroup:"ECharts-based charts",migrator:new Fd,name:"bar-3d",viewRender:Bd,configRender:Nd,createConfig(){return{version:2,config:y.cloneDeep(hs)}}};class Se 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}}const be={mantissa:0,output:"number",trimMantissa:!1,average:!1},Bi={root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}};function Wd({value:e,onChange:t},n){const r=c=>{t({...e,output:c})},i=c=>{const d=c===0?!1:e.trimMantissa;t({...e,mantissa:c,trimMantissa:d})},o=c=>{t({...e,trimMantissa:c.currentTarget.checked})},l=c=>{t({...e,average:c.currentTarget.checked})};return 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:"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:Bi})]}),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:Bi})]}),s.jsxs(a.Stack,{spacing:0,children:[s.jsx(a.Text,{weight:"bold",children:"Preview"}),s.jsx(Se,{children:s.jsxs(a.Group,{position:"apart",children:[s.jsxs(a.Text,{size:12,color:"gray",children:["123456789 ",s.jsx(_.ArrowRight,{size:9})," ",F(123456789).format(e)]}),s.jsxs(a.Text,{size:12,color:"gray",children:["1234 ",s.jsx(_.ArrowRight,{size:9})," ",F(1234).format(e)]}),s.jsxs(a.Text,{size:12,color:"gray",children:["0.1234 ",s.jsx(_.ArrowRight,{size:9})," ",F(.1234).format(e)]})]})})]})]})}const Oe=f.forwardRef(Wd),Be={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
55
|
+
`)},$i={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:Qd,configRender:Rd,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 Rd(e){return s.jsx(s.Fragment,{})}function Qd(e){return s.jsx(a.Text,{children:"Click chart's series"})}const Ud=[{label:"Truncate",value:"truncate"},{label:"Break Line",value:"break"},{label:"Break Word",value:"breakAll"}],hn=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:Ud,value:t.overflow,onChange:i("overflow")}),s.jsx(a.TextInput,{label:"Ellipsis",value:t.ellipsis,disabled:!0})]})]})}),Je=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(hn,{sectionTitle:"Overflow on Axis",value:e.on_axis,onChange:r}),s.jsx(hn,{sectionTitle:"Overflow in Tooltip",value:e.in_tooltip,onChange:i})]})}),ze={on_axis:{width:80,overflow:"truncate",ellipsis:"..."},in_tooltip:{width:200,overflow:"break",ellipsis:"..."}};function Qe({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`
|
|
56
56
|
max-width: ${t}px;
|
|
57
57
|
word-break: ${n};
|
|
58
58
|
white-space: ${r};
|
|
59
59
|
overflow: hidden;
|
|
60
60
|
text-overflow: ${i};
|
|
61
|
-
`}function Ue(e){return{width:e.width,overflow:e.overflow,ellipsis:e.ellipsis}}const vs={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...Be},overflow:Ae}},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"}};function mt(e,t){return f.useMemo(()=>{const{queryID:n,columnKey:r}=A(t);return y.keyBy(e[n],r)},[e,t])}const $e=(e,t)=>{const[n,r]=f.useState([]);return f.useEffect(()=>e.watchTriggerSnapshotList(i=>r(i.filter(o=>o.schemaRef===t))),[]),n};class It{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 ws{constructor(t,n,r){E(this,"attachmentStorage");this.instance=t,this.attachmentKey=n,this.constructInstance=r,this.attachmentStorage=new It(t.instanceData,n)}async getInstance(t){if(await this.attachmentStorage.getItem(t))return this.constructInstance(new It(this.attachmentStorage,t))}async create(t,n){return await this.attachmentStorage.setItem(t,n),this.constructInstance(new It(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 It(this.attachmentStorage,n.id))))}}function Uu(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 Yu(e){const{config:t,setConfig:n,commit:r}=Uu(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 Ku(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 Xu extends re{constructor(){super(...arguments);E(this,"VERSION",1)}configVersions(){this.version(1,n=>n)}}const Ju={displayName:"Open Link",id:"builtin:op:open-link",configRender:Yu,run:Ku,migrator:new Xu,createDefaultConfig:()=>({version:1,config:{urlTemplate:"",openInNewTab:!0}})};function Zu(e){const{value:t,set:n}=$(e.operationData,"config"),r=i=>void n({template:i});return[(t==null?void 0:t.template)||"",r]}function Hu(e){const[t,n]=Zu(e.operation);return s.jsx(a.TextInput,{defaultValue:t,onBlur:r=>n(r.currentTarget.value),label:"console.log"})}async function ed(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 td={displayName:"console.log (debug)",id:"builtin:op:debug",configRender:Hu,run:ed},nd=S.observer(e=>{const t=X(),{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 sd(e,t){const r=(await t.operationData.getItem("config")).viewID;window.dispatchEvent(new CustomEvent("open-view",{detail:{viewID:r}}))}const rd={displayName:"Open View",id:"builtin:op:open_view",configRender:nd,run:sd},id={"tbody tr":{opacity:.5,transition:"opacity 200ms ease"},"tr[data-affected=true]":{opacity:1}},ad=({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,{})})})},od={dictionary:{}},ld=S.observer(e=>{const t=X(),{value:n=od,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:id,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(ad,{value:i[l.value],onChange:u=>o(l.value,u)})})]},l.value)})})]})});async function cd(e,t){const r=(await t.operationData.getItem("config")).dictionary;window.dispatchEvent(new CustomEvent("set-filter-values",{detail:{dictionary:r,payload:e}}))}const ud={displayName:"Set Filter Values",id:"builtin:op:set_filter_values",configRender:ld,run:cd},dd={filter_keys:[]},pd=S.observer(e=>{const t=X(),{value:n=dd,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 hd(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 xn=[td,Ju,rd,ud,{displayName:"Clear Filter Values",id:"builtin:op:clear_filter_values",configRender:pd,run:hd}];class xd{constructor(t,n=xn){E(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 It(i,"data")}};this.attachments=new ws(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 Vi="__TRIGGERS";class fd{constructor(t,n){E(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 It(i,"data")}};this.attachments=new ws(t,Vi,r)}watchTriggerSnapshotList(t){return this.instance.instanceData.watchItem(Vi,n=>{const r=y.values(n).map(i=>({id:y.get(i,"id"),schemaRef:y.get(i,"schemaRef"),config:W.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 Cs{constructor(t,n,r){E(this,"operationManager");E(this,"triggerManager");E(this,"attachments");this.operationManager=new xd(t,r),this.triggerManager=new fd(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 ws(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 Cs(t,e.resolveComponent(t.type),xn),[t,e]),Ni=e=>{const{title:t="Variables",variables:n}=e,r=oe.useClipboard(),i=o=>{r.copy(o),xt.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 gd{constructor(t,n){E(this,"operationId");E(this,"operation");E(this,"operationSchema");E(this,"variables",[]);this.operationManager=t,this.instance=n,W.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));W.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 md(e){return!!e.operationId}const yd=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})}),bd=S.observer(({model:e})=>{const t={operation:e.operation,instance:e.instance,variables:[]};return f.createElement(e.operationSchema.configRender,t)}),jd=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})}),vd=S.observer(e=>{const[t,{setTrue:n,setFalse:r}]=V.useBoolean(!1),{operationManager:i,operationId:o,instance:l,variables:c}=e,u=V.useCreation(()=>new gd(i,l),[i,l]);return V.useAsyncEffect(async()=>{await u.configOperation(o,c)},[o,u]),md(u)?s.jsxs(s.Fragment,{children:[s.jsx(yd,{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(jd,{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(bd,{model:u})}),s.jsx(a.Tabs.Panel,{value:"variables",pt:10,children:s.jsx(Ni,{title:"Variables",variables:u.variables})})]})]})})]}):null});class wd{constructor(t,n){E(this,"triggerId");E(this,"trigger");E(this,"triggerSchema");E(this,"sampleData");this.triggerManager=t,this.instance=n,W.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));W.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 Cd(this)}}function Cd(e){return!!e.triggerId&&!!e.triggerSchema}function Sd(e,t){return V.useCreation(()=>new wd(e,t),[e,t])}const _d=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:f.createElement(n,r)})}),kd=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})}),Td=S.observer(({model:e})=>{const t={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return f.createElement(e.triggerSchema.configRender,t)}),Dd=S.observer(e=>{const[t,{setTrue:n,setFalse:r}]=V.useBoolean(!1),i=e.model;return s.jsxs(s.Fragment,{children:[s.jsx(a.Modal,{opened:t,onClose:r,title:"Setup Trigger",zIndex:320,children:s.jsxs(a.Stack,{children:[s.jsx(kd,{model:i}),s.jsx(Td,{model:i}),s.jsx(Ni,{title:"Payload",variables:i.triggerSchema.payload})]})}),s.jsx(_d,{onClick:n,model:i})]})});function Id(e,t){const[n,r]=f.useState([]);return V.useAsyncEffect(async()=>{const i=await e.getInteractionList();r(i)},[t,e]),n}const Md=S.observer(({item:e,manager:t,instance:n,sampleData:r,variables:i,onRemove:o})=>{const{triggerRef:l,operationRef:c}=e,u=Sd(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(Dd,{model:u}),s.jsx(vd,{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(_.Trash,{size:16})})]})}return null}),Ad=e=>{const[t,n]=f.useState(0),{interactionManager:r,instance:i,sampleData:o,variables:l}=e,c=Id(r,t),u=async()=>{const x=await r.triggerManager.createOrGetTrigger(oe.randomId(),r.triggerManager.getTriggerSchemaList()[0]),m=await r.operationManager.createOrGetOperation(oe.randomId(),r.operationManager.getOperationSchemaList()[0]);await r.addInteraction(x,m),n(j=>j+1)};async function d(x){await r.removeInteraction(x.id),n(m=>m+1)}const{data:p=0,loading:h}=V.useRequest(async()=>{try{return(await r.triggerManager.getTriggerSchemaList()).length}catch{return 0}});return s.jsxs(a.Stack,{children:[s.jsx(a.LoadingOverlay,{visible:h}),p===0&&s.jsx(a.Alert,{icon:s.jsx(_.AlertCircle,{size:16}),title:"Unavailable",color:"gray",children:"This visualization does not have available interactions to choose from"}),c.map(x=>s.jsx(Md,{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:p===0,children:"Add interaction"})]})},zd=()=>{const{panel:e,data:t}=dt(),n=e.viz,{vizManager:r}=f.useContext(et),i=e.json,o=V.useCreation(()=>r.getOrCreateInstance(i),[r,i]),l=V.useCreation(()=>new Cs(o,r.resolveComponent(n.type),xn),[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:[]}},Ed=()=>{const e=zd();return s.jsx(Ad,{...e})},qi={axisTick:{show:!0,alignWithLabel:!0,lineStyle:{width:2}},axisLine:{show:!0,lineStyle:{width:3}},splitLine:{show:!1},z:3};function Pd(e){return y.defaultsDeep({},e,qi)}const Ld=Object.freeze(Object.defineProperty({__proto__:null,getXAxis:Pd,xAxis:qi},Symbol.toStringTag,{value:"Module"})),Fi={axisTick:{show:!1},axisLine:{show:!1,lineStyle:{width:3}},splitLine:{show:!0,lineStyle:{type:"dashed"}}};function Od(e){return y.defaultsDeep({},e,Fi)}const ze={...Ld,...Object.freeze(Object.defineProperty({__proto__:null,getYAxis:Od,yAxis:Fi},Symbol.toStringTag,{value:"Module"}))};function Mt({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 Bd(e,t){const n=[],r=[];return{boxplotData:Object.entries(e).map(([o,l])=>{const c=l.map(M=>M[t]).sort((M,P)=>M-P),u=Nt.quantile(c,.25)??0,d=Nt.quantile(c,.5)??0,p=Nt.quantile(c,.75)??0,h=p-u,x=u-1.5*h,m=p+1.5*h,j=Math.max(c[0],x),w=Math.min(y.last(c)??0,m);return l.filter(M=>{const P=M[t];return P<j||P>w}).forEach(M=>n.push([o,M[t],M])),l.filter(M=>{const P=M[t];return P>=j&&P<=w}).forEach(M=>r.push([o,M[t],M])),{name:o,min:j,q1:u,median:d,q3:p,max:w}}),outliersData:n,scatterData:r}}function $d(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}=Bd(l,o.columnKey);return[{source:c},{source:u},{source:d}]}function Vd(e){const t={top:30,left:20,right:15,bottom:25,containLabel:!0};return e.legend.orient==="vertical"&&(t.right=80),t}function Nd({config:e}){return{...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"}}]}}const Qt=f.forwardRef(function({value:t,onChange:n,...r},i){return s.jsx(a.TextInput,{ref:i,value:t,onChange:n,...r})}),Gi=["function aggregation({ queryData }, utils) {",' return "Aggregation Result";',"}"].join(`
|
|
62
|
-
`),At={type:"none",config:{},fallback:"0"};function
|
|
63
|
-
`,"<br/>").split("<br/>");return n.map((i,o)=>{const l=[
|
|
61
|
+
`}function Ue(e){return{width:e.width,overflow:e.overflow,ellipsis:e.ellipsis}}const vs={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...Be},overflow:ze}},y_axis:{name:"Y Axis",data_key:"value",label_formatter:be},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"}};function mt(e,t){return f.useMemo(()=>{const{queryID:n,columnKey:r}=A(t);return y.keyBy(e[n],r)},[e,t])}const $e=(e,t)=>{const[n,r]=f.useState([]);return f.useEffect(()=>e.watchTriggerSnapshotList(i=>r(i.filter(o=>o.schemaRef===t))),[]),n};class It{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 ws{constructor(t,n,r){E(this,"attachmentStorage");this.instance=t,this.attachmentKey=n,this.constructInstance=r,this.attachmentStorage=new It(t.instanceData,n)}async getInstance(t){if(await this.attachmentStorage.getItem(t))return this.constructInstance(new It(this.attachmentStorage,t))}async create(t,n){return await this.attachmentStorage.setItem(t,n),this.constructInstance(new It(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 It(this.attachmentStorage,n.id))))}}function Yd(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 Kd(e){const{config:t,setConfig:n,commit:r}=Yd(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 Xd(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 Jd extends ie{constructor(){super(...arguments);E(this,"VERSION",1)}configVersions(){this.version(1,n=>n)}}const Zd={displayName:"Open Link",id:"builtin:op:open-link",configRender:Kd,run:Xd,migrator:new Jd,createDefaultConfig:()=>({version:1,config:{urlTemplate:"",openInNewTab:!0}})};function Hd(e){const{value:t,set:n}=$(e.operationData,"config"),r=i=>void n({template:i});return[(t==null?void 0:t.template)||"",r]}function eu(e){const[t,n]=Hd(e.operation);return s.jsx(a.TextInput,{defaultValue:t,onBlur:r=>n(r.currentTarget.value),label:"console.log"})}async function tu(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 nu={displayName:"console.log (debug)",id:"builtin:op:debug",configRender:eu,run:tu},su=S.observer(e=>{const t=X(),{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 ru(e,t){const r=(await t.operationData.getItem("config")).viewID;window.dispatchEvent(new CustomEvent("open-view",{detail:{viewID:r}}))}const iu={displayName:"Open View",id:"builtin:op:open_view",configRender:su,run:ru},au={"tbody tr":{opacity:.5,transition:"opacity 200ms ease"},"tr[data-affected=true]":{opacity:1}},ou=({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,{})})})},lu={dictionary:{}},cu=S.observer(e=>{const t=X(),{value:n=lu,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 d={...i};delete d[l],r({dictionary:d});return}r({dictionary:{...i,[l]:c}})};return s.jsxs(a.Table,{sx:au,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(ou,{value:i[l.value],onChange:d=>o(l.value,d)})})]},l.value)})})]})});async function du(e,t){const r=(await t.operationData.getItem("config")).dictionary;window.dispatchEvent(new CustomEvent("set-filter-values",{detail:{dictionary:r,payload:e}}))}const uu={displayName:"Set Filter Values",id:"builtin:op:set_filter_values",configRender:cu,run:du},pu={filter_keys:[]},hu=S.observer(e=>{const t=X(),{value:n=pu,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 xu(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 xn=[nu,Zd,iu,uu,{displayName:"Clear Filter Values",id:"builtin:op:clear_filter_values",configRender:hu,run:xu}];class fu{constructor(t,n=xn){E(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 It(i,"data")}};this.attachments=new ws(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 Vi="__TRIGGERS";class gu{constructor(t,n){E(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 It(i,"data")}};this.attachments=new ws(t,Vi,r)}watchTriggerSnapshotList(t){return this.instance.instanceData.watchItem(Vi,n=>{const r=y.values(n).map(i=>({id:y.get(i,"id"),schemaRef:y.get(i,"schemaRef"),config:W.toJS(y.get(i,"data.config"))}));t(r)},{fireImmediately:!0})}async createOrGetTrigger(t,n,r={recreate:!1}){var c;if(!this.getTriggerSchemaList().some(d=>d.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 Cs{constructor(t,n,r){E(this,"operationManager");E(this,"triggerManager");E(this,"attachments");this.operationManager=new fu(t,r),this.triggerManager=new gu(t,n);const i=async o=>{const{id:l,triggerRef:c,operationRef:d}=await o.getItem(null);return{id:l,triggerRef:c,operationRef:d}};this.attachments=new ws(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 Cs(t,e.resolveComponent(t.type),xn),[t,e]),Ni=e=>{const{title:t="Variables",variables:n}=e,r=le.useClipboard(),i=o=>{r.copy(o),xt.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 mu{constructor(t,n){E(this,"operationId");E(this,"operation");E(this,"operationSchema");E(this,"variables",[]);this.operationManager=t,this.instance=n,W.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));W.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 yu(e){return!!e.operationId}const bu=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})}),ju=S.observer(({model:e})=>{const t={operation:e.operation,instance:e.instance,variables:[]};return f.createElement(e.operationSchema.configRender,t)}),vu=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})}),wu=S.observer(e=>{const[t,{setTrue:n,setFalse:r}]=V.useBoolean(!1),{operationManager:i,operationId:o,instance:l,variables:c}=e,d=V.useCreation(()=>new mu(i,l),[i,l]);return V.useAsyncEffect(async()=>{await d.configOperation(o,c)},[o,d]),yu(d)?s.jsxs(s.Fragment,{children:[s.jsx(bu,{model:d,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(vu,{model:d}),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(ju,{model:d})}),s.jsx(a.Tabs.Panel,{value:"variables",pt:10,children:s.jsx(Ni,{title:"Variables",variables:d.variables})})]})]})})]}):null});class Cu{constructor(t,n){E(this,"triggerId");E(this,"trigger");E(this,"triggerSchema");E(this,"sampleData");this.triggerManager=t,this.instance=n,W.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));W.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 Su(this)}}function Su(e){return!!e.triggerId&&!!e.triggerSchema}function _u(e,t){return V.useCreation(()=>new Cu(e,t),[e,t])}const ku=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:f.createElement(n,r)})}),Tu=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})}),Du=S.observer(({model:e})=>{const t={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return f.createElement(e.triggerSchema.configRender,t)}),Iu=S.observer(e=>{const[t,{setTrue:n,setFalse:r}]=V.useBoolean(!1),i=e.model;return s.jsxs(s.Fragment,{children:[s.jsx(a.Modal,{opened:t,onClose:r,title:"Setup Trigger",zIndex:320,children:s.jsxs(a.Stack,{children:[s.jsx(Tu,{model:i}),s.jsx(Du,{model:i}),s.jsx(Ni,{title:"Payload",variables:i.triggerSchema.payload})]})}),s.jsx(ku,{onClick:n,model:i})]})});function Mu(e,t){const[n,r]=f.useState([]);return V.useAsyncEffect(async()=>{const i=await e.getInteractionList();r(i)},[t,e]),n}const Au=S.observer(({item:e,manager:t,instance:n,sampleData:r,variables:i,onRemove:o})=>{const{triggerRef:l,operationRef:c}=e,d=_u(t.triggerManager,n);if(V.useAsyncEffect(async()=>{await d.configTrigger(l,r)},[d,l,r]),d.isReady()){const u=[...d.triggerSchema.payload,...i];return s.jsxs(a.Group,{children:[s.jsx(Iu,{model:d}),s.jsx(wu,{instance:n,operationId:c,variables:u,operationManager:t.operationManager}),s.jsx(a.ActionIcon,{"aria-label":"delete-interaction",variant:"filled",color:"red",onClick:()=>o(e),children:s.jsx(_.Trash,{size:16})})]})}return null}),zu=e=>{const[t,n]=f.useState(0),{interactionManager:r,instance:i,sampleData:o,variables:l}=e,c=Mu(r,t),d=async()=>{const x=await r.triggerManager.createOrGetTrigger(le.randomId(),r.triggerManager.getTriggerSchemaList()[0]),m=await r.operationManager.createOrGetOperation(le.randomId(),r.operationManager.getOperationSchemaList()[0]);await r.addInteraction(x,m),n(j=>j+1)};async function u(x){await r.removeInteraction(x.id),n(m=>m+1)}const{data:p=0,loading:h}=V.useRequest(async()=>{try{return(await r.triggerManager.getTriggerSchemaList()).length}catch{return 0}});return s.jsxs(a.Stack,{children:[s.jsx(a.LoadingOverlay,{visible:h}),p===0&&s.jsx(a.Alert,{icon:s.jsx(_.AlertCircle,{size:16}),title:"Unavailable",color:"gray",children:"This visualization does not have available interactions to choose from"}),c.map(x=>s.jsx(Au,{onRemove:u,instance:i,sampleData:o,variables:l,item:x,manager:e.interactionManager},x.id)),s.jsx(a.Button,{style:{width:"fit-content"},onClick:()=>d(),disabled:p===0,children:"Add interaction"})]})},Eu=()=>{const{panel:e,data:t}=ut(),n=e.viz,{vizManager:r}=f.useContext(et),i=e.json,o=V.useCreation(()=>r.getOrCreateInstance(i),[r,i]),l=V.useCreation(()=>new Cs(o,r.resolveComponent(n.type),xn),[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:[]}},Pu=()=>{const e=Eu();return s.jsx(zu,{...e})},qi={axisTick:{show:!0,alignWithLabel:!0,lineStyle:{width:2}},axisLine:{show:!0,lineStyle:{width:3}},splitLine:{show:!1},z:3};function Lu(e){return y.defaultsDeep({},e,qi)}const Ou=Object.freeze(Object.defineProperty({__proto__:null,getXAxis:Lu,xAxis:qi},Symbol.toStringTag,{value:"Module"})),Fi={axisTick:{show:!1},axisLine:{show:!1,lineStyle:{width:3}},splitLine:{show:!0,lineStyle:{type:"dashed"}}};function Bu(e){return y.defaultsDeep({},e,Fi)}const $u=Object.freeze(Object.defineProperty({__proto__:null,getYAxis:Bu,yAxis:Fi},Symbol.toStringTag,{value:"Module"})),Gi={confine:!0,appendToBody:!0};function Vu(e){return y.defaultsDeep({},e,Gi)}const ne={...Ou,...$u,...Object.freeze(Object.defineProperty({__proto__:null,getTooltip:Vu,tooltip:Gi},Symbol.toStringTag,{value:"Module"}))};function Mt({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 Nu(e,t){const n=[],r=[];return{boxplotData:Object.entries(e).map(([o,l])=>{const c=l.map(M=>M[t]).sort((M,P)=>M-P),d=Nt.quantile(c,.25)??0,u=Nt.quantile(c,.5)??0,p=Nt.quantile(c,.75)??0,h=p-d,x=d-1.5*h,m=p+1.5*h,j=Math.max(c[0],x),w=Math.min(y.last(c)??0,m);return l.filter(M=>{const P=M[t];return P<j||P>w}).forEach(M=>n.push([o,M[t],M])),l.filter(M=>{const P=M[t];return P>=j&&P<=w}).forEach(M=>r.push([o,M[t],M])),{name:o,min:j,q1:d,median:u,q3:p,max:w}}),outliersData:n,scatterData:r}}function qu(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:d,scatterData:u}=Nu(l,o.columnKey);return[{source:c},{source:d},{source:u}]}function Fu(e){const t={top:30,left:20,right:15,bottom:25,containLabel:!0};return e.legend.orient==="vertical"&&(t.right=80),t}function Gu({config:e}){return{...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"}}]}}const Qt=f.forwardRef(function({value:t,onChange:n,...r},i){return s.jsx(a.TextInput,{ref:i,value:t,onChange:n,...r})}),Wi=["function aggregation({ queryData }, utils) {",' return "Aggregation Result";',"}"].join(`
|
|
62
|
+
`),At={type:"none",config:{},fallback:"0"};function Wu(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 Ru(e,t){switch(t.type){case"sum":return y.sum(e);case"mean":return y.mean(e);case"median":return Wu(e);case"max":return y.max(e);case"min":return y.min(e);case"quantile":return Nt.quantile(e,t.config.p);case"CV":const n=cn.std(...e),r=cn.mean(...e);return r?n/r:Number.NaN;case"std":return cn.std(...e);default:return e}}function Ss(e,t){const n=e.map(Number),r=Ru(n,t);return typeof r=="number"?Number.isFinite(r)?r:t.fallback:r??t.fallback}function Qu(e,t,n){try{const r=Rt(e,t);return new Function(`return ${n.config.func}`)()({queryData:r},gt)}catch(r){return console.error(r),r.message}}function fn(e,t,n){try{return n.type==="custom"?Qu(e,t,n):Ss(rt(e,t),n)}catch(r){return console.error(r),null}}class Uu{constructor({valueRange:t,colorRange:n}){E(this,"mapper");this.mapper=ft.interpolate(t,n)}getColor(t){return this.mapper(t)}}function Yu(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 fn(n,e,t)}function Ne({formatter:e,aggregation:t},n){if(!["string","number"].includes(typeof n))return Yu(n);if(t.type==="custom")return n;try{return F(n).format(e)}catch(r){return console.error(r),n}}function Ku(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 Uu(e).getColor(t)}catch(n){return console.error(n),"black"}return"black"}function Xu(e,t){const{color:n,data_field:r,aggregation:i,size:o,weight:l}=e,c=fn(t,r,i),d=Ne(e,c);return s.jsx(a.Text,{sx:{fontSize:o,display:"inline"},color:Ku(n,c),weight:l,children:d})}function Ju(e,t){const n={};return e.forEach(r=>{const i=r.name;n[i]=Xu(r,t)}),n}function Zu(e){return e.split(" ").map((t,n)=>s.jsxs(f.Fragment,{children:[t," "]},n))}function Hu(e){const n=e.replaceAll("<br />","<br/>").replaceAll(`
|
|
63
|
+
`,"<br/>").split("<br/>");return n.map((i,o)=>{const l=[Zu(i)];return o!==n.length-1&&l.push(s.jsx("br",{},`br-${o}`)),l}).flat().filter(i=>i!==void 0)}function _s(e){return Hu(e)}function Ut(e,t,n){const r=Ju(t,n),i=/^\{(.+)\}(.*)$/;return e.split("$").map((o,l)=>{const c=i.exec(o);if(!c)return _s(o);const d=r[c[1]];if(!d)return _s(o);const u=c[2]??"";return s.jsxs(f.Fragment,{children:[d,_s(u)]},`${o}-${l}`)})}function ep(e,t){const{data_field:n,aggregation:r}=e,i=fn(t,n,r);return Ne(e,i)}function Ri(e,t){const n={};return e.forEach(r=>{n[r.name]=ep(r,t)}),n}function gn(e,t,n){const r=Ri(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 d=l[2]??"";return`${c}${d}`}).join("")}function tp(e,t,n){const r=t.reduce((i,o)=>{const l=it(o,n);return i[o.name]=Ne(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 gn(i.template,t,n)},position:"insideEndTop"}}}))}const ks=["max","q3","median","q1","min"],Ts=[10,40];function Ds(e){return e.barLayout({barMinWidth:Ts[0],barMaxWidth:Ts[1],count:2})}function np(e,t,n){const{itemStyle:{color:r,borderColor:i,borderWidth:o}}=n,l=Ds(t),c=t.value(0),d=e.source[c],{min:u,q1:p,median:h,q3:x,max:m}=d,j={min:t.coord([c,u]),q1:t.coord([c,p]),median:t.coord([c,h]),q3:t.coord([c,x]),max:t.coord([c,m])},w={left:l[1].offset,center:(l[1].offset+l[1].width)/2,right:l[1].width},T={type:"group",children:[]},M=[{x1:j.max[0]+w.left,x2:j.max[0]+w.right,y1:j.max[1],y2:j.max[1]},{x1:j.median[0]+w.left,x2:j.median[0]+w.right,y1:j.median[1],y2:j.median[1]},{x1:j.min[0]+w.left,x2:j.min[0]+w.right,y1:j.min[1],y2:j.min[1]},{x1:j.min[0]+w.center,x2:j.min[0]+w.center,y1:j.min[1],y2:j.q1[1]},{x1:j.max[0]+w.center,x2:j.max[0]+w.center,y1:j.max[1],y2:j.q3[1]}],P={stroke:i,lineWidth:o};return M.forEach(U=>{T.children.push({type:"line",shape:U,style:P})}),T.children.push({type:"rect",shape:{x:j.q1[0]+w.left,y:j.q1[1],width:w.right-w.left,height:j.q3[1]-j.q1[1]},style:{fill:r,stroke:i,lineWidth:o}}),T}function sp(e,t){const{color:n}=t,r={name:"Box",type:"custom",itemStyle:{color:n,borderColor:"#2F8CC0",borderWidth:2},emphasis:{disabled:!0},boxWidth:Ts,datasetIndex:0};return r.renderItem=(i,o)=>np(e,o,r),r}function rp(e){const t=Ds(e),n=t[0].width,r=e.value(0),i=e.value(1),[o,l]=e.coord([r,i]),d=o+t[0].offset+Math.random()*n;return{type:"circle",transition:["shape"],x:d,y:l,shape:{cx:0,cy:0,r:2},style:{fill:e.visual("color"),opacity:.5}}}function ip(){const e={name:"Scatter",type:"custom",itemStyle:{color:"#ED6A45"},emphasis:{scale:2},datasetIndex:2};return e.renderItem=(t,n)=>rp(n),e}function ap(e,t){const n=Ds(e),r=n[0].width,i=e.value(0),o=e.value(1),[l,c]=e.coord([i,o]),u=l+n[0].offset+Math.random()*r;return{type:"circle",transition:["shape"],x:u,y:c,shape:{cx:0,cy:0,r:3},style:{fill:e.visual("color")}}}function op(){const e={name:"Outlier",type:"custom",itemStyle:{color:"#ED6A45"},emphasis:{scale:2},datasetIndex:1};return e.renderItem=(t,n)=>ap(n),e}function lp(e,t){const n=t[0],r=sp(n,e),i=ip(),o=op();return[{name:"Placeholder Box",type:"boxplot",ignore:!0,silent:!0,itemStyle:{color:"none",borderColor:"none",opacity:0},boxWidth:[20,80],datasetIndex:0,encode:{y:ks,x:"name",itemName:["name"],tooltip:ks}},{name:"Placeholder Outlier",type:"scatter",symbolSize:7,itemStyle:{color:"transparent"},ignore:!0,silent:!0,emphasis:{disabled:!0},datasetIndex:1},r,i,o]}const cp=(e,t)=>{const n=ks.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;">
|
|
@@ -75,15 +75,15 @@ Check the top-level render call using <`+z+">.")}return D}}function dc(v,D){{if(
|
|
|
75
75
|
${n.join("")}
|
|
76
76
|
</tbody>
|
|
77
77
|
</table>
|
|
78
|
-
`},
|
|
78
|
+
`},dp=e=>{try{return F(e).format({trimMantissa:!0,mantissa:2})}catch{return e}};function Qi(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;">${dp(t[r.columnKey])}</td>
|
|
82
|
+
</tr>`})}function up(e,t){const n=Qe(e.x_axis.axisLabel.overflow.in_tooltip),r=[`<tr>
|
|
83
83
|
<th style="text-align: right; padding: 0 1em;">${e.y_axis.name}</th>
|
|
84
84
|
<td style="text-align: left; padding: 0 1em;">${t[1]}</td>
|
|
85
85
|
</tr>
|
|
86
|
-
`],i=
|
|
86
|
+
`],i=Qi(e,t[2]);return r.push(...i),`
|
|
87
87
|
<div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
|
|
88
88
|
<div style="${n}">${t[0]}</div>
|
|
89
89
|
</div>
|
|
@@ -92,11 +92,11 @@ Check the top-level render call using <`+z+">.")}return D}}function dc(v,D){{if(
|
|
|
92
92
|
${r.join("")}
|
|
93
93
|
</tbody>
|
|
94
94
|
</table>
|
|
95
|
-
`}function
|
|
95
|
+
`}function pp(e,t){const n=Qe(e.x_axis.axisLabel.overflow.in_tooltip),r=[`<tr>
|
|
96
96
|
<th style="text-align: right; padding: 0 1em;">${e.y_axis.name}</th>
|
|
97
97
|
<td style="text-align: left; padding: 0 1em;">${t[1]}</td>
|
|
98
98
|
</tr>
|
|
99
|
-
`],i=
|
|
99
|
+
`],i=Qi(e,t[2]);return r.push(...i),`
|
|
100
100
|
<div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
|
|
101
101
|
<div style="${n}">${t[0]}</div>
|
|
102
102
|
</div>
|
|
@@ -105,27 +105,27 @@ Check the top-level render call using <`+z+">.")}return D}}function dc(v,D){{if(
|
|
|
105
105
|
${r.join("")}
|
|
106
106
|
</tbody>
|
|
107
107
|
</table>
|
|
108
|
-
`}const up=e=>t=>{const{seriesName:n,value:r}=t;switch(n){case"Box":return ap(e,r);case"Outlier":return lp(e,r);case"Scatter":return cp(e,r)}};function dp({config:e}){return{trigger:"item",confine:!0,formatter:up(e)}}function pp({config:e,data:t,variables:n}){const{x_axis:r,y_axis:i,reference_lines:o}=e,l=$d(e,t),c=Ue(r.axisLabel.overflow.on_axis),u=ip(e,l);return{grid:Vd(e),dataset:l,legend:Nd({config:e}),tooltip:dp({config:e}),xAxis:[ze.getXAxis({type:"category",name:r.name,nameGap:25,nameLocation:"center",nameTextStyle:{align:"center"},axisLabel:{...r.axisLabel,...c,formatter:Mt(r.axisLabel.formatter)}})],yAxis:[ze.getYAxis({name:i.name,minInterval:1,axisLabel:{formatter:function(d){return F(d).format(i.label_formatter)}}})],series:[...u,...Zd(o,n,t)]}}Y.use([O.DataZoomComponent,te.BoxplotChart,te.CustomChart,O.MarkLineComponent,O.GridComponent,O.LegendComponent,O.TooltipComponent,we.CanvasRenderer]);function hp({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,vs),u=Ve({vizManager:e.vizManager,instance:t}),d=$e(u.triggerManager,$i.id),p=mt(i,c.x_axis.data_key),h=f.useCallback(j=>{const w=y.get(p,j.name,{error:"rowData is not found"});d.forEach(T=>{u.runInteraction(T.id,{...j,rowData:w})})},[p,d,u]),x=f.useMemo(()=>({click:h}),[h]),m=f.useMemo(()=>pp({config:c,data:i,variables:r}),[c,i,r]);return!n||!o||!l?null:s.jsx(Te,{width:o,height:l,children:s.jsx(ve,{echarts:Y,option:m,style:Wt(o,l),onEvents:x,notMerge:!0,theme:"merico-light"})})}function xp({value:e,onChange:t},n){const{colorManager:r}=f.useContext(et),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 Se=f.forwardRef(xp);function fp({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(_.Trash,{size:16})})]})}function gp({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((p,h)=>({...p,...l[h]})),u=()=>i({name:"",template:"",variable_key:""}),d=f.useMemo(()=>n.map(p=>({label:p.name,value:p.name})),[n]);return s.jsxs(a.Stack,{children:[c.map((p,h)=>s.jsx(fp,{control:e,index:h,remove:o,variableOptions:d},p.id)),s.jsx(a.Group,{position:"center",mt:"xs",children:s.jsx(a.Button,{onClick:u,children:"Add a Reference Line"})})]})}const mp=({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}})]})},mn=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:j}=l,w={enabled:m,func_content:j};c(w),t(w)},p=()=>{o(),c(e)},h=m=>{c(j=>({...j,func_content:m}))},x=()=>{h(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(mp,{value:l.func_content,onChange:h,disabled:!l.enabled}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:x,color:"red",leftIcon:s.jsx(_.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:d,children:"OK"})]})]})]})})]})}),yp=({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(mn,{...n})})]}),s.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>s.jsx(Je,{...n})})]})),bp=({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(Oe,{...n})})]})]})),jp=({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(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),vp=({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((h,x)=>({...h,...o[x]})),c=()=>r({id:Date.now().toString(),data_key:"",name:""}),u=t("tooltip.metrics.0.id"),[d,p]=f.useState(()=>u??null);return f.useEffect(()=>{u&&p(h=>h!==null?h:u)},[u]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(_.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:h=>p(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((h,x)=>s.jsx(a.Tabs.Tab,{value:h.id,children:h.name?h.name:x},h.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),l.map((h,x)=>s.jsx(a.Tabs.Panel,{value:h.id,children:s.jsx(jp,{control:e,index:x,remove:i},h.id)},h.id))]})]})};function wp({control:e,watch:t}){return s.jsx(a.Stack,{children:s.jsx(vp,{control:e,watch:t})})}const Cp=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}],Sp=({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:Cp,sx:{flex:1},value:i.value.orient,onChange:o=>{r(o,i.onChange)},disabled:!n.show})})})]})};function _p({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),{variables:r}=e,i=f.useMemo(()=>y.defaults({},t,vs),[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"]);const p=u(),h=f.useMemo(()=>!y.isEqual(p,t),[p,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:!h,children:s.jsx(_.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.Panel,{value:"X Axis",children:s.jsx(yp,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Y Axis",children:s.jsx(bp,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Legend",children:s.jsx(Sp,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(wp,{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(Se,{...x})})]})}),s.jsx(a.Tabs.Panel,{value:"Reference Lines",children:s.jsx(gp,{variables:r,control:o,watch:c})})]})]})})}function kp(e){return y.omit(e,"variables")}function Tp(e){const{label_formatter:t=ye,...n}=e.y_axis;return{...e,y_axis:{...n,label_formatter:t}}}function Dp(e){const t={rotate:0,formatter:{...Be}},{axisLabel:n=t,...r}=e.x_axis;return{...e,x_axis:{...r,axisLabel:n}}}function Ip(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 Mp(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 Ap(e){const t={tooltip:{metrics:[]}};return y.defaultsDeep(t,e)}function zp(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 Ep(e){const t={legend:{show:!0,top:"0",right:"10",left:"auto",bottom:"auto",orient:"horizontal",type:"scroll"}};return y.defaultsDeep(t,e)}class Pp extends re{constructor(){super(...arguments);E(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:kp(i)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:Tp(r)}}),this.version(4,n=>{const{config:r}=n;return{...n,version:4,config:Dp(r)}}),this.version(5,n=>{const{config:r}=n;return{...n,version:5,config:Ip(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:Mp(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:Ap(r)}}),this.version(8,(n,r)=>{const{config:i}=n;return{...n,version:8,config:zp(i,r)}}),this.version(9,n=>{const{config:r}=n;return{...n,version:9,config:Ep(r)}})}}const Lp={displayName:"Boxplot Chart",displayGroup:"ECharts-based charts",migrator:new Pp,name:"boxplot",viewRender:hp,configRender:_p,createConfig(){return{version:9,config:y.cloneDeep(vs)}},triggers:[$i]},Qi={id:"builtin:button:click-button",displayName:"Click Button",nameRender:Bp,configRender:Op,payload:[]};function Op(e){return s.jsx(s.Fragment,{})}function Bp(e){return s.jsx(a.Text,{children:"Click this button"})}const Is={content:"Button",variant:"filled",color:"blue",size:"xs",compact:!1,horizontal_align:"left",vertical_align:"center"},$p={left:"flex-start",center:"center",right:"flex-end"},Vp={top:"flex-start",center:"center",bottom:"flex-end"},Np=S.observer(({context:e,instance:t})=>{const n=Ve({vizManager:e.vizManager,instance:t}),r=$e(n.triggerManager,Qi.id),i=le(),{value:o}=$(e.instanceData,"config"),l=f.useMemo(()=>y.defaultsDeep({},o,Is),[o]),{content:c,horizontal_align:u,vertical_align:d,...p}=l,{width:h,height:x}=e.viewport,m=i.payloadForSQL,j=()=>{r.forEach(w=>{n.runInteraction(w.id,{})})};return s.jsx(a.Center,{sx:{width:h,height:x,justifyContent:$p[u],alignItems:Vp[d]},children:s.jsx(a.Button,{...p,onClick:j,children:y.template(c)(m)})})}),qp=({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)})})]})},Fp=a.MANTINE_SIZES.map(e=>({label:e.toUpperCase(),value:e})),Gp=({label:e,value:t,onChange:n})=>s.jsx(a.Select,{data:Fp,label:e,value:t,onChange:n}),Wp=[{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}],Rp=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Qp=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function Up({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},t,Is),[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 p=u(),h=f.useMemo(()=>!y.isEqual(p,r),[p,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:!h,children:s.jsx(_.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:Wp,...x})}),s.jsx(b.Controller,{control:o,name:"color",render:({field:x})=>s.jsx(qp,{label:"Theme",...x})})]}),s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(b.Controller,{control:o,name:"size",render:({field:x})=>s.jsx(Gp,{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:Rp,...x})}),s.jsx(b.Controller,{control:o,name:"vertical_align",render:({field:x})=>s.jsx(a.Select,{label:"Vertical Alignment",data:Qp,...x})})]})]})]})}class Yp extends re{constructor(){super(...arguments);E(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 Kp={displayName:"Button",displayGroup:"Others",migrator:new Yp,name:"button",viewRender:Np,configRender:Up,createConfig(){return{version:2,config:y.cloneDeep(Is)}},triggers:[Qi]},Ms={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:Jp,configRender:Xp,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 Xp(e){return s.jsx(s.Fragment,{})}function Jp(e){return s.jsx(a.Text,{children:"Click chart's series"})}const zt={x_axis_scroll:!1,y_axis_scroll:!1,x_axis_slider:!1,y_axis_slider:!1},As={regressions:[],series:[],stats:{templates:{bottom:"",top:""}},x_axis:{type:"category",axisLabel:{rotate:0,formatter:{...Be},overflow:Ae}},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:zt};function zs(e){const t=[];return e.x_axis_scroll&&t.push({type:"inside",xAxisIndex:[0],filterMode:"none",minSpan:1}),e.y_axis_scroll&&t.push({type:"inside",yAxisIndex:[0],filterMode:"none",minSpan:1}),e.x_axis_slider&&t.push({type:"slider",xAxisIndex:[0],filterMode:"none",bottom:"auto",top:0,height:15,moveHandleSize:0,showDataShadow:!1,minSpan:1}),t}function Zp(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 Hp(e){return e!=="line"?{}:{itemStyle:{opacity:0}}}function eh(e){switch(e){case"line":return;case"bar":return"roundRect";case"scatter":return"circle"}}function th(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:eh(r),...Hp(r)})),t}function yn(e,t){switch(e.config.method){case"linear":return[...ut.regressionLinear()(t)];case"exponential":return[...ut.regressionExp()(t)];case"logarithmic":return[...ut.regressionLog()(t)];case"polynomial":return[...ut.regressionPoly().order(e.config.order)(t)];default:return[]}}function nh(e,t,n,r){const{transform:i,plot:o}=e,l={...o,name:t,data:yn(i,r),showSymbol:!1,tooltip:{show:!1},smooth:!1,custom:{}};return n&&(l.custom={type:"regression-line",targetSeries:n}),l}function sh({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=nh(o,l,c,u);r.push(d)}return e.forEach(o=>{const{name:l,group_by_key:c}=o;if(!c||c===t){const h=rt(n,o.y_axis_data_key).map((x,m)=>[m,Number(x)]);i(o,l,"",h);return}const{columnKey:u}=A(o.y_axis_data_key),d=y.groupBy(Rt(n,o.y_axis_data_key),c);Object.entries(d).forEach(([p,h])=>{const x=h.map((j,w)=>[w,Number(j[u])]);i(o,p,p,x)})}),r}function rh(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 ih(e,t,n,r){return t?r==="value"?[[n[0],e]]:[e]:[]}function ah(e,t,n,r,i,o){return e.map(l=>{const c=n[l.variable_key],u=l.orientation==="horizontal",d=u?"yAxis":"xAxis",p=u?"insideEndTop":"end",h=ih(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:h,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?gn(l.template,t,r):""},position:p}}}})}function oh({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(Rt(n,l),c);return(d,p)=>{let h;p.name?h=u[p.name]:h=n[p.dataIndex];try{return new Function(`return ${o}`)()({rowData:h,params:p,variables:i},{lodash:y,interpolate:ft.interpolate})}catch(x){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${x.message}`),10}}}function Es(e,t,n){const r=rt(e,t),i=rt(e,n);return y.zip(r,i)}function lh(e,t,n,r){const i=Es(t,n,r);return y.unionBy(i,e,0)}function ch({dataTemplate:e,data:t,x_axis_data_key:n,y_axis_data_key:r,valueTypedXAxis:i}){return i?lh(e,t,n,r):rt(t,r)}function uh({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 ch({dataTemplate:e,data:t,x_axis_data_key:r,y_axis_data_key:i,valueTypedXAxis:o});const l=Es(t,r,i),c=y.groupBy(l,"0");return e.map(([d])=>{const h=c[d].map(m=>m[1]),x=Ss(h,n);return[d,x]})}function dh({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]=Es({[i]:u},n,r)}),l}function ph({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:p,symbolSize:h,hide_in_legend:x,...m},j,w,T,M){const P=t.type!=="category",U={label:{show:!!i,position:i,formatter:M[r??"default"]},name:o,xAxisId:"main-x-axis",yAxisIndex:r,stack:u,color:d,symbolSize:oh(h,w,e,T),hide_in_legend:x,labelLayout:{hideOverlap:!0},...m};if(m.type==="line"&&(U.lineStyle={shadowColor:"rgba(255,255,255,1)",shadowBlur:0,shadowOffsetX:0,shadowOffsetY:3}),p&&(U.endLabel={show:!0,formatter:o,offset:[-12,12],align:"right"}),!l||l===e)return U.data=uh({dataTemplate:j,data:w,aggregation_on_value:c,x_axis_data_key:e,y_axis_data_key:n,valueTypedXAxis:P}),U;const se=dh({group_by_key:l,data:w,x_axis_data_key:e,y_axis_data_key:n});return Object.entries(se).map(([Q,ie])=>{const de=y.cloneDeep(U);return de.name=Q,de.color=void 0,de.data=ie,de})}function hh(e,t,n,r,i,o){const l=t.map(u=>[u,0]);return e.series.map(u=>ph(e,u,l,n,o,r)).flat().concat(ah(e.reference_lines,i,o,n,t,e.x_axis.type)).concat(rh(e.reference_areas,o))}function xh(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 Mt(t.x_axis.axisLabel.formatter)(r,i)}function fh(e,t,n){const r=t.reduce((i,{yAxisIndex:o,name:l})=>(i[l]=o,i),{});return{trigger:"axis",confine:!0,formatter:function(i){const o=Array.isArray(i)?i:[i];if(o.length===0)return"";const l=o.map(({seriesName:d,marker:p,value:h})=>{if(Array.isArray(h)&&h.length===2&&(h=h[1]),!d)return h;const x=r[d],m=n[x]??n.default;return`
|
|
108
|
+
`}const hp=e=>t=>{const{seriesName:n,value:r}=t;switch(n){case"Box":return cp(e,r);case"Outlier":return up(e,r);case"Scatter":return pp(e,r)}};function xp({config:e}){return ne.getTooltip({trigger:"item",formatter:hp(e)})}function fp({config:e,data:t,variables:n}){const{x_axis:r,y_axis:i,reference_lines:o}=e,l=qu(e,t),c=Ue(r.axisLabel.overflow.on_axis),d=lp(e,l);return{grid:Fu(e),dataset:l,legend:Gu({config:e}),tooltip:xp({config:e}),xAxis:[ne.getXAxis({type:"category",name:r.name,nameGap:25,nameLocation:"center",nameTextStyle:{align:"center"},axisLabel:{...r.axisLabel,...c,formatter:Mt(r.axisLabel.formatter)}})],yAxis:[ne.getYAxis({name:i.name,minInterval:1,axisLabel:{formatter:function(u){return F(u).format(i.label_formatter)}}})],series:[...d,...tp(o,n,t)]}}Y.use([O.DataZoomComponent,te.BoxplotChart,te.CustomChart,O.MarkLineComponent,O.GridComponent,O.LegendComponent,O.TooltipComponent,Ce.CanvasRenderer]);function gp({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,vs),d=Ve({vizManager:e.vizManager,instance:t}),u=$e(d.triggerManager,$i.id),p=mt(i,c.x_axis.data_key),h=f.useCallback(j=>{const w=y.get(p,j.name,{error:"rowData is not found"});u.forEach(T=>{d.runInteraction(T.id,{...j,rowData:w})})},[p,u,d]),x=f.useMemo(()=>({click:h}),[h]),m=f.useMemo(()=>fp({config:c,data:i,variables:r}),[c,i,r]);return!n||!o||!l?null:s.jsx(De,{width:o,height:l,children:s.jsx(we,{echarts:Y,option:m,style:Wt(o,l),onEvents:x,notMerge:!0,theme:"merico-light"})})}function mp({value:e,onChange:t},n){const{colorManager:r}=f.useContext(et),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(mp);function yp({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(_.Trash,{size:16})})]})}function bp({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((p,h)=>({...p,...l[h]})),d=()=>i({name:"",template:"",variable_key:""}),u=f.useMemo(()=>n.map(p=>({label:p.name,value:p.name})),[n]);return s.jsxs(a.Stack,{children:[c.map((p,h)=>s.jsx(yp,{control:e,index:h,remove:o,variableOptions:u},p.id)),s.jsx(a.Group,{position:"center",mt:"xs",children:s.jsx(a.Button,{onClick:d,children:"Add a Reference Line"})})]})}const jp=({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(me,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},mn=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 d=m=>{c({...l,enabled:m})},u=()=>{o();const{enabled:m,func_content:j}=l,w={enabled:m,func_content:j};c(w),t(w)},p=()=>{o(),c(e)},h=m=>{c(j=>({...j,func_content:m}))},x=()=>{h(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=>d(m.currentTarget.checked)}),s.jsx(jp,{value:l.func_content,onChange:h,disabled:!l.enabled}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:x,color:"red",leftIcon:s.jsx(_.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:u,children:"OK"})]})]})]})})]})}),vp=({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(mn,{...n})})]}),s.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>s.jsx(Je,{...n})})]})),wp=({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(Oe,{...n})})]})]})),Cp=({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(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),Sp=({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((h,x)=>({...h,...o[x]})),c=()=>r({id:Date.now().toString(),data_key:"",name:""}),d=t("tooltip.metrics.0.id"),[u,p]=f.useState(()=>d??null);return f.useEffect(()=>{d&&p(h=>h!==null?h:d)},[d]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(_.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:u,onTabChange:h=>p(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((h,x)=>s.jsx(a.Tabs.Tab,{value:h.id,children:h.name?h.name:x},h.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),l.map((h,x)=>s.jsx(a.Tabs.Panel,{value:h.id,children:s.jsx(Cp,{control:e,index:x,remove:i},h.id)},h.id))]})]})};function _p({control:e,watch:t}){return s.jsx(a.Stack,{children:s.jsx(Sp,{control:e,watch:t})})}const kp=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}],Tp=({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:kp,sx:{flex:1},value:i.value.orient,onChange:o=>{r(o,i.onChange)},disabled:!n.show})})})]})};function Dp({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),{variables:r}=e,i=f.useMemo(()=>y.defaults({},t,vs),[t]),{control:o,handleSubmit:l,watch:c,getValues:d,reset:u}=b.useForm({defaultValues:i});f.useEffect(()=>{u(i)},[i]),c(["x_axis","y_axis","reference_lines","color"]);const p=d(),h=f.useMemo(()=>!y.isEqual(p,t),[p,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:!h,children:s.jsx(_.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.Panel,{value:"X Axis",children:s.jsx(vp,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Y Axis",children:s.jsx(wp,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Legend",children:s.jsx(Tp,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(_p,{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(bp,{variables:r,control:o,watch:c})})]})]})})}function Ip(e){return y.omit(e,"variables")}function Mp(e){const{label_formatter:t=be,...n}=e.y_axis;return{...e,y_axis:{...n,label_formatter:t}}}function Ap(e){const t={rotate:0,formatter:{...Be}},{axisLabel:n=t,...r}=e.x_axis;return{...e,x_axis:{...r,axisLabel:n}}}function zp(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 Ep(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 Pp(e){const t={tooltip:{metrics:[]}};return y.defaultsDeep(t,e)}function Lp(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,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(d=>({...d,data_key:r(d.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}function Op(e){const t={legend:{show:!0,top:"0",right:"10",left:"auto",bottom:"auto",orient:"horizontal",type:"scroll"}};return y.defaultsDeep(t,e)}class Bp extends ie{constructor(){super(...arguments);E(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:Ip(i)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:Mp(r)}}),this.version(4,n=>{const{config:r}=n;return{...n,version:4,config:Ap(r)}}),this.version(5,n=>{const{config:r}=n;return{...n,version:5,config:zp(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:Ep(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:Pp(r)}}),this.version(8,(n,r)=>{const{config:i}=n;return{...n,version:8,config:Lp(i,r)}}),this.version(9,n=>{const{config:r}=n;return{...n,version:9,config:Op(r)}})}}const $p={displayName:"Boxplot Chart",displayGroup:"ECharts-based charts",migrator:new Bp,name:"boxplot",viewRender:gp,configRender:Dp,createConfig(){return{version:9,config:y.cloneDeep(vs)}},triggers:[$i]},Ui={id:"builtin:button:click-button",displayName:"Click Button",nameRender:Np,configRender:Vp,payload:[]};function Vp(e){return s.jsx(s.Fragment,{})}function Np(e){return s.jsx(a.Text,{children:"Click this button"})}const Is={content:"Button",variant:"filled",color:"blue",size:"xs",compact:!1,horizontal_align:"left",vertical_align:"center"},qp={left:"flex-start",center:"center",right:"flex-end"},Fp={top:"flex-start",center:"center",bottom:"flex-end"},Gp=S.observer(({context:e,instance:t})=>{const n=Ve({vizManager:e.vizManager,instance:t}),r=$e(n.triggerManager,Ui.id),i=ce(),{value:o}=$(e.instanceData,"config"),l=f.useMemo(()=>y.defaultsDeep({},o,Is),[o]),{content:c,horizontal_align:d,vertical_align:u,...p}=l,{width:h,height:x}=e.viewport,m=i.payloadForSQL,j=()=>{r.forEach(w=>{n.runInteraction(w.id,{})})};return s.jsx(a.Center,{sx:{width:h,height:x,justifyContent:qp[d],alignItems:Fp[u]},children:s.jsx(a.Button,{...p,onClick:j,children:y.template(c)(m)})})}),Wp=({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)})})]})},Rp=a.MANTINE_SIZES.map(e=>({label:e.toUpperCase(),value:e})),Qp=({label:e,value:t,onChange:n})=>s.jsx(a.Select,{data:Rp,label:e,value:t,onChange:n}),Up=[{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}],Yp=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Kp=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function Xp({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},t,Is),[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:d,reset:u}=b.useForm({defaultValues:i});f.useEffect(()=>{u(i)},[i]);const p=d(),h=f.useMemo(()=>!y.isEqual(p,r),[p,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:!h,children:s.jsx(_.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:Up,...x})}),s.jsx(b.Controller,{control:o,name:"color",render:({field:x})=>s.jsx(Wp,{label:"Theme",...x})})]}),s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(b.Controller,{control:o,name:"size",render:({field:x})=>s.jsx(Qp,{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:Yp,...x})}),s.jsx(b.Controller,{control:o,name:"vertical_align",render:({field:x})=>s.jsx(a.Select,{label:"Vertical Alignment",data:Kp,...x})})]})]})]})}class Jp extends ie{constructor(){super(...arguments);E(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 Zp={displayName:"Button",displayGroup:"Others",migrator:new Jp,name:"button",viewRender:Gp,configRender:Xp,createConfig(){return{version:2,config:y.cloneDeep(Is)}},triggers:[Ui]},Ms={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:eh,configRender:Hp,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 Hp(e){return s.jsx(s.Fragment,{})}function eh(e){return s.jsx(a.Text,{children:"Click chart's series"})}const zt={x_axis_scroll:!1,y_axis_scroll:!1,x_axis_slider:!1,y_axis_slider:!1},As={regressions:[],series:[],stats:{templates:{bottom:"",top:""}},x_axis:{type:"category",axisLabel:{rotate:0,formatter:{...Be},overflow:ze}},x_axis_data_key:"",x_axis_name:"",y_axes:[{min:"",max:"",name:"Y Axis",show:!0,position:"left",nameAlignment:"center",label_formatter:be}],reference_lines:[],reference_areas:[],dataZoom:zt};function zs(e){const t=[];return e.x_axis_scroll&&t.push({type:"inside",xAxisIndex:[0],filterMode:"none",minSpan:1}),e.y_axis_scroll&&t.push({type:"inside",yAxisIndex:[0],filterMode:"none",minSpan:1}),e.x_axis_slider&&t.push({type:"slider",xAxisIndex:[0],filterMode:"none",bottom:"auto",top:0,height:15,moveHandleSize:0,showDataShadow:!1,minSpan:1}),t}function th(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 nh(e){return e!=="line"?{}:{itemStyle:{opacity:0}}}function sh(e){switch(e){case"line":return;case"bar":return"roundRect";case"scatter":return"circle"}}function rh(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:sh(r),...nh(r)})),t}function yn(e,t){switch(e.config.method){case"linear":return[...dt.regressionLinear()(t)];case"exponential":return[...dt.regressionExp()(t)];case"logarithmic":return[...dt.regressionLog()(t)];case"polynomial":return[...dt.regressionPoly().order(e.config.order)(t)];default:return[]}}function ih(e,t,n,r){const{transform:i,plot:o}=e,l={...o,name:t,data:yn(i,r),showSymbol:!1,tooltip:{show:!1},smooth:!1,custom:{}};return n&&(l.custom={type:"regression-line",targetSeries:n}),l}function ah({regressions:e=[],x_axis_data_key:t},n){const r=[];if(Object.keys(n).length===0)return r;function i(o,l,c,d){const u=ih(o,l,c,d);r.push(u)}return e.forEach(o=>{const{name:l,group_by_key:c}=o;if(!c||c===t){const h=rt(n,o.y_axis_data_key).map((x,m)=>[m,Number(x)]);i(o,l,"",h);return}const{columnKey:d}=A(o.y_axis_data_key),u=y.groupBy(Rt(n,o.y_axis_data_key),c);Object.entries(u).forEach(([p,h])=>{const x=h.map((j,w)=>[w,Number(j[d])]);i(o,p,p,x)})}),r}function oh(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 lh(e,t,n,r){return t?r==="value"?[[n[0],e]]:[e]:[]}function ch(e,t,n,r,i,o){return e.map(l=>{const c=n[l.variable_key],d=l.orientation==="horizontal",u=d?"yAxis":"xAxis",p=d?"insideEndTop":"end",h=lh(c,d,i,o);return{name:l.name,type:"scatter",hide_in_legend:!l.show_in_legend,xAxisId:"main-x-axis",yAxisIndex:l.yAxisIndex,data:h,symbol:"none",silent:!0,tooltip:{show:!1},markLine:{data:[{name:l.name,[u]:c}],silent:!0,symbol:["none","none"],lineStyle:l.lineStyle,label:{formatter:function(){return l.template?gn(l.template,t,r):""},position:p}}}})}function dh({type:e,...t},n,r,i){if(!e)return 10;if(e==="static"){const{size:u}=t;return u}const{func_content:o}=t,{queryID:l,columnKey:c}=A(r),d=y.keyBy(Rt(n,l),c);return(u,p)=>{let h;p.name?h=d[p.name]:h=n[p.dataIndex];try{return new Function(`return ${o}`)()({rowData:h,params:p,variables:i},{lodash:y,interpolate:ft.interpolate})}catch(x){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${x.message}`),10}}}function Es(e,t,n){const r=rt(e,t),i=rt(e,n);return y.zip(r,i)}function uh(e,t,n,r){const i=Es(t,n,r);return y.unionBy(i,e,0)}function ph({dataTemplate:e,data:t,x_axis_data_key:n,y_axis_data_key:r,valueTypedXAxis:i}){return i?uh(e,t,n,r):rt(t,r)}function hh({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 ph({dataTemplate:e,data:t,x_axis_data_key:r,y_axis_data_key:i,valueTypedXAxis:o});const l=Es(t,r,i),c=y.groupBy(l,"0");return e.map(([u])=>{const h=c[u].map(m=>m[1]),x=Ss(h,n);return[u,x]})}function xh({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,d])=>{l[c]=Es({[i]:d},n,r)}),l}function fh({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:d,color:u,display_name_on_line:p,symbolSize:h,hide_in_legend:x,...m},j,w,T,M){const P=t.type!=="category",U={label:{show:!!i,position:i,formatter:M[r??"default"]},name:o,xAxisId:"main-x-axis",yAxisIndex:r,stack:d,color:u,symbolSize:dh(h,w,e,T),hide_in_legend:x,labelLayout:{hideOverlap:!0},...m};if(m.type==="line"&&(U.lineStyle={shadowColor:"rgba(255,255,255,1)",shadowBlur:0,shadowOffsetX:0,shadowOffsetY:3}),p&&(U.endLabel={show:!0,formatter:o,offset:[-12,12],align:"right"}),!l||l===e)return U.data=hh({dataTemplate:j,data:w,aggregation_on_value:c,x_axis_data_key:e,y_axis_data_key:n,valueTypedXAxis:P}),U;const re=xh({group_by_key:l,data:w,x_axis_data_key:e,y_axis_data_key:n});return Object.entries(re).map(([Q,ae])=>{const pe=y.cloneDeep(U);return pe.name=Q,pe.color=void 0,pe.data=ae,pe})}function gh(e,t,n,r,i,o){const l=t.map(d=>[d,0]);return e.series.map(d=>fh(e,d,l,n,o,r)).flat().concat(ch(e.reference_lines,i,o,n,t,e.x_axis.type)).concat(oh(e.reference_areas,o))}function mh(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 Mt(t.x_axis.axisLabel.formatter)(r,i)}function yh(e,t,n){const r=t.reduce((i,{yAxisIndex:o,name:l})=>(i[l]=o,i),{});return ne.getTooltip({trigger:"axis",formatter:function(i){const o=Array.isArray(i)?i:[i];if(o.length===0)return"";const l=o.map(({seriesName:u,marker:p,value:h})=>{if(Array.isArray(h)&&h.length===2&&(h=h[1]),!u)return h;const x=r[u],m=n[x]??n.default;return`
|
|
109
109
|
<tr>
|
|
110
110
|
<td>${p}</td>
|
|
111
|
-
<th style="text-align: right; padding: 0 1em;">${
|
|
111
|
+
<th style="text-align: right; padding: 0 1em;">${u}</th>
|
|
112
112
|
<td style="text-align: left; padding: 0 1em;">${m({value:h})}</td>
|
|
113
113
|
</tr>
|
|
114
|
-
`}),c=Qe(e.x_axis.axisLabel.overflow.in_tooltip),
|
|
114
|
+
`}),c=Qe(e.x_axis.axisLabel.overflow.in_tooltip),d=mh(o,e);return`
|
|
115
115
|
<div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
|
|
116
|
-
<div style="${c}">${
|
|
116
|
+
<div style="${c}">${d}</div>
|
|
117
117
|
</div>
|
|
118
118
|
<table style="width: auto">
|
|
119
119
|
<tbody>
|
|
120
120
|
${l.join("")}
|
|
121
121
|
</tbody>
|
|
122
122
|
</table>
|
|
123
|
-
`}}}function gh(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 F(c).format(r)}catch(u){return console.error(u),c}},n),{default:({value:n})=>n})}function Ui(e,t){const n={};return t.map(r=>{const i=it(r,e);n[r.name]=Ne(r,i)}),n}function mh(e,t){const{overflow:n,...r}=e.x_axis.axisLabel,i=Ue(n.on_axis),o=t.length===0;return[ze.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:Mt(r.formatter)}})]}function yh(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 bh(e){if(e.length===0)return{};const t={},n={};return e.forEach(r=>{const i=yh(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 jh(e,t,n){const r=bh(n);return e.y_axes.map(({nameAlignment:i,min:o,max:l,show:c,...u},d)=>{let p=u.position;return p||(p=d>0?"right":"left"),ze.getYAxis({...u,minInterval:r[d]??0,show:c,min:o||void 0,max:l||void 0,position:p,axisLabel:{show:c,formatter:t[d]??t.default},nameTextStyle:{align:i},nameLocation:"end",nameGap:c?15:0,splitLine:{show:d===0}})})}const vh={xAxis:[{type:"category",nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0}}]};function wh(e,t,n){const r=Ui(t,n),i=gh(e),o=y.uniq(rt(t,e.x_axis_data_key)),l=hh(e,o,t,i,n,r),c=sh(e,t),u={xAxis:mh(e,o),yAxis:jh(e,i,l),series:[...l,...c],tooltip:fh(e,l,i),grid:Zp(e),legend:th(l),dataZoom:zs(e.dataZoom)};return y.defaultsDeep({},u,vh)}function Yi(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})}Y.use([O.DataZoomComponent,te.BarChart,te.LineChart,te.ScatterChart,O.GridComponent,O.LegendComponent,O.TooltipComponent,we.CanvasRenderer,O.MarkLineComponent,O.MarkAreaComponent]);function Ki(e){return e.trim().length>0}function Ch({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const l=mt(t,e.x_axis_data_key),c=$e(i.triggerManager,Ms.id),u=f.useCallback(m=>{const j=y.get(l,m.name,{error:"rowData is not found"});c.forEach(w=>{i.runInteraction(w.id,{...m,rowData:j})})},[l,c,i]),d=f.useMemo(()=>wh(e,t,o),[e,t]),p=f.useRef(),h=f.useMemo(()=>({click:u}),[u]),x=m=>{p.current=m,Yi(m)};return f.useEffect(()=>{p.current&&Yi(p.current)},[d]),!n||!r?null:s.jsx(ve,{echarts:Y,option:d,style:{width:n,height:r},onEvents:h,onChartReady:x,notMerge:!0,theme:"merico-light"})}function Sh({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,As),[r]),l=e.data,{width:c,height:u}=e.viewport,{ref:d,height:p}=oe.useElementSize(),{ref:h,height:x}=oe.useElementSize(),m=f.useMemo(()=>{const{stats:{templates:T}}=o;return{top:Ut(T.top,i,l),bottom:Ut(T.bottom,i,l)}},[o,l]),j=Math.max(0,Re(u)-p-x),w=We(c);return s.jsxs(Te,{width:c,height:u,children:[s.jsx(a.Text,{ref:d,align:"left",size:"xs",pl:"sm",sx:{display:Ki(o.stats.templates.top)?"block":"none"},children:Object.values(m.top).map((T,M)=>s.jsx(f.Fragment,{children:T},M))}),s.jsx(Ch,{variables:i,width:w,height:j,data:l,conf:o,interactionManager:n}),s.jsx(a.Text,{ref:h,align:"left",size:"xs",pl:"sm",sx:{display:Ki(o.stats.templates.bottom)?"block":"none"},children:Object.values(m.bottom).map((T,M)=>s.jsx(f.Fragment,{children:T},M))})]})}const Ps=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)})})})]})]})}),_h=[{label:"Rectangle",value:"rectangle"}],kh=[{label:"Horizontal",value:"horizontal"}];function Th({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:_h,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:kh,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(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Area"})]})}function Dh({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((p,h)=>({...p,...l[h]})),u=()=>i({name:"",color:"rgba(0,0,0,0.1)",type:"rectangle",direction:"horizontal",y_keys:{upper:"",lower:""}}),d=f.useMemo(()=>n.map(p=>({label:p.name,value:p.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((p,h)=>s.jsx(a.Tabs.Tab,{value:h.toString(),children:h+1},p.id)),s.jsx(a.Tabs.Tab,{onClick:u,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),c.map((p,h)=>s.jsx(a.Tabs.Panel,{value:h.toString(),children:s.jsx(Th,{control:e,index:h,remove:o,variableOptions:d})},p.id))]})}const Ih=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Mh=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Ah({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:Mh,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:p=>{if(!p){u(0);return}u(Number(p))},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:Ih,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(Se,{...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(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]})}function zh({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]),p=t("y_axes"),h=f.useMemo(()=>p.map(({name:x},m)=>({label:x,value:m.toString()})),[p]);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(_.Plus,{size:18,color:"#228be6"})})]}),c.map((x,m)=>s.jsx(a.Tabs.Panel,{value:m.toString(),children:s.jsx(Ah,{control:e,index:m,remove:o,watch:t,variableOptions:d,yAxisOptions:h})},x.id))]})}const Eh=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}],Ph=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function Lh({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:Eh,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:Ph,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(Se,{...l})})]}),s.jsx(a.Button,{leftIcon:s.jsx(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(n),sx:{top:15,right:5},children:"Delete this Regression Line"})]})}function Oh({control:e,watch:t}){const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"regressions"}),o=t("regressions"),l=n.map((p,h)=>({...p,...o[h]})),c=t("y_axes"),u=f.useMemo(()=>c.map(({name:p},h)=>({label:p,value:h.toString()})),[c]),d=()=>r({transform:{type:"ecStat:regression",config:{method:"linear",order:1,formulaOn:"end"}},group_by_key:"",name:"",y_axis_data_key:"",plot:{type:"line",yAxisIndex:0,color:"#666666",lineStyle:{type:"solid",width:1}}});return 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((p,h)=>s.jsx(a.Tabs.Tab,{value:h.toString(),children:h+1},p.id)),s.jsx(a.Tabs.Tab,{onClick:d,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),l.map((p,h)=>s.jsx(a.Tabs.Panel,{value:h.toString(),children:s.jsx(Lh,{regressionItem:p,control:e,index:h,remove:i,yAxisOptions:u})},p.id))]})}const Ls={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
|
|
124
|
-
`)}},Os={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 Xi(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=Xi(i.content,o.content,n+1);if(l!=null)return l}n+=i.nodeSize}}function Ji(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,p=Math.min(l.text.length,c.text.length);for(;d<p&&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=Ji(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 p=c+1;u.nodesBetween(Math.max(0,t-p),Math.min(u.content.size,n-p),r,i+p)}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 Xi(this,t,n)}findDiffEnd(t,n=this.size,r=t.size){return Ji(this,t,n,r)}findIndex(t,n=-1){if(t==0)return bn(0,t);if(t==this.size)return bn(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?bn(r+1,l):bn(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 Bs={index:0,offset:0};function bn(e,t){return Bs.index=e,Bs.offset=t,Bs}function $s(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(!$s(e[r],t[r]))return!1}else{for(let r in e)if(!(r in t)||!$s(e[r],t[r]))return!1;for(let r in t)if(!(r in e))return!1}return!0}class Ee{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&&$s(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 Ee.none;if(t instanceof Ee)return[t];let n=t.slice();return n.sort((r,i)=>r.type.rank-i.type.rank),n}}Ee.none=[];class Bh extends Error{}class H{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=Hi(this.content,t+this.openStart,n);return r&&new H(r,this.openStart,this.openEnd)}removeBetween(t,n){return new H(Zi(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 H.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 H(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 H(t,r,i)}}H.empty=new H(J.empty,0,0);function Zi(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(Zi(o.content,t-i-1,n-i-1)))}function Hi(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=Hi(l.content,t-o-1,n);return c&&e.replaceChild(i,l.copy(c))}class jn{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 sa(this,n,!1);return r.addAll(t,n.from,n.to),r.finish()}parseSlice(t,n={}){let r=new sa(this,n,!0);return r.addAll(t,n.from,n.to),H.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(Nh(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=ra(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=ra(l)),l.node||l.ignore||l.mark||(l.node=i)})}return n}static fromSchema(t){return t.cached.domParser||(t.cached.domParser=new jn(t,jn.schemaRules(t)))}}const ea={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},$h={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},ta={ol:!0,ul:!0},vn=1,wn=2,Yt=4;function na(e,t,n){return t!=null?(t?vn:0)|(t==="full"?wn:0):e&&e.whitespace=="pre"?vn|wn:n&~Yt}class Cn{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=Ee.none,this.stashMarks=[],this.match=l||(c&Yt?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&vn)){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):Fh(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&&!ea.hasOwnProperty(t.parentNode.nodeName.toLowerCase())}}class sa{constructor(t,n,r){this.parser=t,this.options=n,this.isOpen=r,this.open=0;let i=n.topNode,o,l=na(null,n.preserveWhitespace,0)|(r?Yt:0);i?o=new Cn(i.type,i.attrs,Ee.none,Ee.none,!0,n.topMatch||i.type.contentMatch,l):r?o=new Cn(null,null,Ee.none,Ee.none,!0,null,l):o=new Cn(t.schema.topNodeType,null,Ee.none,Ee.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(qh(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&wn||r.inlineContext(t)||/[^ \t\r\n\u000c]/.test(n)){if(r.options&vn)r.options&wn?n=n.replace(/\r\n?/g,`
|
|
125
|
-
`):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;
|
|
126
|
-
`))}ignoreFallback(t){t.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"))}readStyles(t){let n=Ee.none,r=Ee.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=na(t,i,o.options);o.options&Yt&&o.content.length==0&&(l|=Yt),this.nodes.push(new Cn(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 p=u>0||u==0&&i?this.nodes[u].type:r&&u>=o?r.node(u-o).type:null;if(!p||p.name!=d&&p.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=Gh(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 Vh(e){for(let t=e.firstChild,n=null;t;t=t.nextSibling){let r=t.nodeType==1?t.nodeName.toLowerCase():null;r&&ta.hasOwnProperty(r)&&n?(n.appendChild(t),t=n):r=="li"?n=t:r&&(n=null)}}function Nh(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function qh(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 ra(e){let t={};for(let n in e)t[n]=e[n];return t}function Fh(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:p}=c.edge(u);if(d==t||o.indexOf(p)<0&&l(p))return!0}};if(l(i.contentMatch))return!0}}function Gh(e,t){for(let n=0;n<t.length;n++)if(e.eq(t[n]))return t[n]}const ia=65535,aa=Math.pow(2,16);function Wh(e,t){return e+t*aa}function oa(e){return e&ia}function Rh(e){return(e-(e&ia))/aa}const la=1,ca=2,Sn=4,ua=8;class da{constructor(t,n,r){this.pos=t,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&ua)>0}get deletedBefore(){return(this.delInfo&(la|Sn))>0}get deletedAfter(){return(this.delInfo&(ca|Sn))>0}get deletedAcross(){return(this.delInfo&Sn)>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=oa(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+Rh(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],p=this.ranges[c+l],h=u+d;if(t<=h){let x=d?t==u?-1:t==h?1:n:n,m=u+i+(x<0?0:p);if(r)return m;let j=t==(n<0?u:h)?null:Wh(c/3,t-u),w=t==u?ca:t==h?la:Sn;return(n<0?t!=u:t!=h)&&(w|=ua),new da(m,w,j)}i+=p-d}return r?t+i:new da(t+i,0,null)}touches(t,n){let r=0,i=oa(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],p=u+d;if(t<=p&&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],p=this.ranges[i+r];t(c,c+d,u,u+p),o+=p-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 Vs=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=Vs[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 Vs)throw new RangeError("Duplicate use of step JSON ID "+t);return Vs[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 Bh)return he.fail(o.message);throw o}}}function Ns(e,t,n){let r=[];for(let i=0;i<e.childCount;i++){let o=e.child(i);o.content.size&&(o=o.copy(Ns(o.content,t,o))),o.isInline&&(o=t(o,n,i)),r.push(o)}return J.fromArray(r)}class yt 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 H(Ns(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 bt(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 yt(n.pos,r.pos,this.mark)}merge(t){return t instanceof yt&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new yt(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 yt(n.from,n.to,t.markFromJSON(n.mark))}}De.jsonID("addMark",yt);class bt 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 H(Ns(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 yt(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 bt(n.pos,r.pos,this.mark)}merge(t){return t instanceof bt&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new bt(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 bt(n.from,n.to,t.markFromJSON(n.mark))}}De.jsonID("removeMark",bt);class jt 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 H(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 jt(this.pos,n.marks[i]);return new jt(this.pos,this.mark)}}return new Kt(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new jt(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 jt(n.pos,t.markFromJSON(n.mark))}}De.jsonID("addNodeMark",jt);class Kt 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 H(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 jt(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new Kt(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 Kt(n.pos,t.markFromJSON(n.mark))}}De.jsonID("removeNodeMark",Kt);class Ze 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 Ze(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 Ze(n.pos,Math.max(n.pos,r.pos),this.slice)}merge(t){if(!(t instanceof Ze)||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?H.empty:new H(this.slice.content.append(t.slice.content),this.slice.openStart,t.slice.openEnd);return new Ze(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?H.empty:new H(t.slice.content.append(this.slice.content),t.slice.openStart,this.slice.openEnd);return new Ze(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 Ze(n.from,n.to,H.fromJSON(t,n.slice),!!n.structure)}}De.jsonID("replace",Ze);class vt 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 vt(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 vt(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 vt(n.from,n.to,n.gapFrom,n.gapTo,H.fromJSON(t,n.slice),n.insert,!!n.structure)}}De.jsonID("replaceAround",vt);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 Qh(e,t,n){return(t==0||e.canReplace(t,e.childCount))&&(n==e.childCount||e.canReplace(0,n))}function Uh(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||!Qh(i,o,l))break}return null}function _n(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,p=n-2;d>o;d--,p--){let h=i.node(d),x=i.index(d);if(h.type.spec.isolating)return!1;let m=h.content.cutByIndex(x,h.childCount),j=r&&r[p+1];j&&(m=m.replaceChild(0,j.type.create(j.attrs)));let w=r&&r[p]||h;if(!h.canReplace(x+1,h.childCount)||!w.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 pa(e,t){let n=e.resolve(t),r=n.index();return Yh(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function Yh(e,t){return!!(e&&t&&!e.isLeaf&&e.canAppend(t))}class Xt 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 H(J.from(i),0,n.isLeaf?0:1))}getMap(){return qe.empty}invert(t){return new Xt(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 Xt(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 Xt(n.pos,n.attr,n.value)}}De.jsonID("attr",Xt);let Jt=class extends Error{};Jt=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n},Jt.prototype=Object.create(Error.prototype),Jt.prototype.constructor=Jt,Jt.prototype.name="TransformError";const Fs=Object.create(null);class ne{constructor(t,n,r){this.$anchor=t,this.$head=n,this.ranges=r||[new Kh(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=H.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],p=t.mapping.slice(o);t.replaceRange(p.map(u.pos),p.map(d.pos),c?H.empty:n),c==0&&fa(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),p=u.map(c.pos);o?t.deleteRange(d,p):(t.replaceRangeWith(d,p,n),fa(t,r,n.isInline?-1:1))}}static findFrom(t,n,r=!1){let i=t.parent.inlineContent?new xe(t):Et(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?Et(t.node(0),t.node(o),t.before(o+1),t.index(o),n,r):Et(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 at(t.node(0))}static atStart(t){return Et(t,t,0,0,1)||new at(t)}static atEnd(t){return Et(t,t,t.content.size,t.childCount,-1)||new at(t)}static fromJSON(t,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=Fs[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 Fs)throw new RangeError("Duplicate use of selection JSON ID "+t);return Fs[t]=n,n.prototype.jsonID=t,n}getBookmark(){return xe.between(this.$anchor,this.$head).getBookmark()}}ne.prototype.visible=!0;class Kh{constructor(t,n){this.$from=t,this.$to=n}}let ha=!1;function xa(e){!ha&&!e.parent.inlineContent&&(ha=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+e.parent.type.name+")"))}class xe extends ne{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 ne.near(r);let i=t.resolve(n.map(this.anchor));return new xe(i.parent.inlineContent?i:r,r)}replace(t,n=H.empty){if(super.replace(t,n),n==H.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 kn(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=ne.findFrom(n,r,!0)||ne.findFrom(n,-r,!0);if(o)n=o.$head;else return ne.near(n,r)}return t.parent.inlineContent||(i==0?t=n:(t=(ne.findFrom(t,-r,!0)||ne.findFrom(t,r,!0)).$anchor,t.pos<n.pos!=i<0&&(t=n))),new xe(t,n)}}ne.jsonID("text",xe);class kn{constructor(t,n){this.anchor=t,this.head=n}map(t){return new kn(t.map(this.anchor),t.map(this.head))}resolve(t){return xe.between(t.resolve(this.anchor),t.resolve(this.head))}}class Pe extends ne{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?ne.near(o):new Pe(o)}content(){return new H(J.from(this.node),0,0)}eq(t){return t instanceof Pe&&t.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new Gs(this.anchor)}static fromJSON(t,n){if(typeof n.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new Pe(t.resolve(n.anchor))}static create(t,n){return new Pe(t.resolve(n))}static isSelectable(t){return!t.isText&&t.type.spec.selectable!==!1}}Pe.prototype.visible=!1,ne.jsonID("node",Pe);class Gs{constructor(t){this.anchor=t}map(t){let{deleted:n,pos:r}=t.mapResult(this.anchor);return n?new kn(r,r):new Gs(r)}resolve(t){let n=t.resolve(this.anchor),r=n.nodeAfter;return r&&Pe.isSelectable(r)?new Pe(n):ne.near(n)}}class at extends ne{constructor(t){super(t.resolve(0),t.resolve(t.content.size))}replace(t,n=H.empty){if(n==H.empty){t.delete(0,t.doc.content.size);let r=ne.atStart(t.doc);r.eq(t.selection)||t.setSelection(r)}else super.replace(t,n)}toJSON(){return{type:"all"}}static fromJSON(t){return new at(t)}map(t){return new at(t)}eq(t){return t instanceof at}getBookmark(){return Xh}}ne.jsonID("all",at);const Xh={map(){return this},resolve(e){return new at(e)}};function Et(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&&Pe.isSelectable(c))return Pe.create(e,n-(i<0?c.nodeSize:0))}else{let u=Et(e,c,n+i,i<0?c.childCount:0,i,o);if(u)return u}n+=c.nodeSize*i}return null}function fa(e,t,n){let r=e.steps.length-1;if(r<t)return;let i=e.steps[r];if(!(i instanceof Ze||i instanceof vt))return;let o=e.mapping.maps[r],l;o.forEach((c,u,d,p)=>{l==null&&(l=p)}),e.setSelection(ne.near(e.doc.resolve(l),n))}function ga(e,t){return!t||!e?e:e.bind(t)}class Tn{constructor(t,n,r){this.name=t,this.init=ga(n.init,r),this.apply=ga(n.apply,r)}}new Tn("doc",{init(e){return e.doc||e.schema.topNodeType.createAndFill()},apply(e){return e.doc}}),new Tn("selection",{init(e,t){return e.selection||ne.atStart(t.doc)},apply(e){return e.selection}}),new Tn("storedMarks",{init(e){return e.storedMarks||null},apply(e,t,n,r){return r.selection.$cursor?e.storedMarks:null}}),new Tn("scrollToSelection",{init(){return 0},apply(e,t){return e.scrolledIntoView?t+1:t}});function ma(e,t,n){for(let r in e){let i=e[r];i instanceof Function?i=i.bind(t):r=="handleDOMEvents"&&(i=ma(i,t,{})),n[r]=i}return n}class Zt{constructor(t){this.spec=t,this.props={},t.props&&ma(t.props,this,this.props),this.key=t.key?t.key.key:ya("plugin")}getState(t){return t[this.key]}}const Ws=Object.create(null);function ya(e){return e in Ws?e+"$"+ ++Ws[e]:(Ws[e]=0,e+"$")}class Ht{constructor(t="key"){this.key=ya(t)}get(t){return t.config.pluginsByKey[this.key]}getState(t){return t[this.key]}}function ba(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 Jh{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,(...p)=>{const h=u(...p)(l);return!o.getMeta("preventDispatch")&&!this.hasCustomState&&i.dispatch(o),h}]))}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,p=()=>(!u&&n&&!d.getMeta("preventDispatch")&&!this.hasCustomState&&l.dispatch(d),c.every(x=>x===!0)),h={...Object.fromEntries(Object.entries(r).map(([x,m])=>[x,(...w)=>{const T=this.buildProps(d,n),M=m(...w)(T);return c.push(M),h}])),run:p};return h}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,(...p)=>d(...p)({...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:ba({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,(...p)=>d(...p)(c)]))}};return c}}function pt(e,t,n){return e.config[t]===void 0&&e.parent?pt(e.parent,t,n):typeof e.config[t]=="function"?e.config[t].bind({...n,parent:e.parent?pt(e.parent,t,n):null}):e.config[t]}function Zh(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 je(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 Hh(e){return typeof e=="function"}function Pt(e,t=void 0,...n){return Hh(e)?t?e.bind(t)(...n):e(...n):e}function ex(e){return Object.prototype.toString.call(e)==="[object RegExp]"}function tx(e){return Object.prototype.toString.call(e).slice(8,-1)}function Rs(e){return tx(e)!=="Object"?!1:e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype}function ja(e,t){const n={...e};return Rs(e)&&Rs(t)&&Object.keys(t).forEach(r=>{Rs(t[r])?r in e?n[r]=ja(e[r],t[r]):Object.assign(n,{[r]:t[r]}):Object.assign(n,{[r]:t[r]})}),n}class He{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=Pt(pt(this,"addOptions",{name:this.name}))),this.storage=Pt(pt(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(t={}){return new He(t)}configure(t={}){const n=this.extend();return n.options=ja(this.options,t),n.storage=Pt(pt(n,"addStorage",{name:n.name,options:n.options})),n}extend(t={}){const n=new He(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=Pt(pt(n,"addOptions",{name:n.name})),n.storage=Pt(pt(n,"addStorage",{name:n.name,options:n.options})),n}}function nx(e,t,n){const{from:r,to:i}=t,{blockSeparator:o=`
|
|
123
|
+
`}})}function bh(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 F(c).format(r)}catch(d){return console.error(d),c}},n),{default:({value:n})=>n})}function Yi(e,t){const n={};return t.map(r=>{const i=it(r,e);n[r.name]=Ne(r,i)}),n}function jh(e,t){const{overflow:n,...r}=e.x_axis.axisLabel,i=Ue(n.on_axis),o=t.length===0;return[ne.getXAxis({data:t,name:e.x_axis_name??"",nameGap:o?5:void 0,id:"main-x-axis",type:e.x_axis.type,axisLabel:{...r,...i,formatter:Mt(r.formatter)}})]}function vh(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 wh(e){if(e.length===0)return{};const t={},n={};return e.forEach(r=>{const i=vh(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 Ch(e,t,n){const r=wh(n);return e.y_axes.map(({nameAlignment:i,min:o,max:l,show:c,...d},u)=>{let p=d.position;return p||(p=u>0?"right":"left"),ne.getYAxis({...d,minInterval:r[u]??0,show:c,min:o||void 0,max:l||void 0,position:p,axisLabel:{show:c,formatter:t[u]??t.default},nameTextStyle:{align:i},nameLocation:"end",nameGap:c?15:0,splitLine:{show:u===0}})})}const Sh={xAxis:[{type:"category",nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0}}]};function _h(e,t,n){const r=Yi(t,n),i=bh(e),o=y.uniq(rt(t,e.x_axis_data_key)),l=gh(e,o,t,i,n,r),c=ah(e,t),d={xAxis:jh(e,o),yAxis:Ch(e,i,l),series:[...l,...c],tooltip:yh(e,l,i),grid:th(e),legend:rh(l),dataZoom:zs(e.dataZoom)};return y.defaultsDeep({},d,Sh)}function Ki(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})}Y.use([O.DataZoomComponent,te.BarChart,te.LineChart,te.ScatterChart,O.GridComponent,O.LegendComponent,O.TooltipComponent,Ce.CanvasRenderer,O.MarkLineComponent,O.MarkAreaComponent]);function Xi(e){return e.trim().length>0}function kh({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const l=mt(t,e.x_axis_data_key),c=$e(i.triggerManager,Ms.id),d=f.useCallback(m=>{const j=y.get(l,m.name,{error:"rowData is not found"});c.forEach(w=>{i.runInteraction(w.id,{...m,rowData:j})})},[l,c,i]),u=f.useMemo(()=>_h(e,t,o),[e,t]),p=f.useRef(),h=f.useMemo(()=>({click:d}),[d]),x=m=>{p.current=m,Ki(m)};return f.useEffect(()=>{p.current&&Ki(p.current)},[u]),!n||!r?null:s.jsx(we,{echarts:Y,option:u,style:{width:n,height:r},onEvents:h,onChartReady:x,notMerge:!0,theme:"merico-light"})}function Th({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,As),[r]),l=e.data,{width:c,height:d}=e.viewport,{ref:u,height:p}=le.useElementSize(),{ref:h,height:x}=le.useElementSize(),m=f.useMemo(()=>{const{stats:{templates:T}}=o;return{top:Ut(T.top,i,l),bottom:Ut(T.bottom,i,l)}},[o,l]),j=Math.max(0,Re(d)-p-x),w=We(c);return s.jsxs(De,{width:c,height:d,children:[s.jsx(a.Text,{ref:u,align:"left",size:"xs",pl:"sm",sx:{display:Xi(o.stats.templates.top)?"block":"none"},children:Object.values(m.top).map((T,M)=>s.jsx(f.Fragment,{children:T},M))}),s.jsx(kh,{variables:i,width:w,height:j,data:l,conf:o,interactionManager:n}),s.jsx(a.Text,{ref:h,align:"left",size:"xs",pl:"sm",sx:{display:Xi(o.stats.templates.bottom)?"block":"none"},children:Object.values(m.bottom).map((T,M)=>s.jsx(f.Fragment,{children:T},M))})]})}const Ps=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)})})})]})]})}),Dh=[{label:"Rectangle",value:"rectangle"}],Ih=[{label:"Horizontal",value:"horizontal"}];function Mh({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:Dh,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:Ih,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(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Area"})]})}function Ah({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((p,h)=>({...p,...l[h]})),d=()=>i({name:"",color:"rgba(0,0,0,0.1)",type:"rectangle",direction:"horizontal",y_keys:{upper:"",lower:""}}),u=f.useMemo(()=>n.map(p=>({label:p.name,value:p.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((p,h)=>s.jsx(a.Tabs.Tab,{value:h.toString(),children:h+1},p.id)),s.jsx(a.Tabs.Tab,{onClick:d,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),c.map((p,h)=>s.jsx(a.Tabs.Panel,{value:h.toString(),children:s.jsx(Mh,{control:e,index:h,remove:o,variableOptions:u})},p.id))]})}const zh=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Eh=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Ph({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:Eh,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:d,...u}})=>s.jsx(a.Select,{label:"Y Axis",data:o,disabled:o.length===0,...u,value:(c==null?void 0:c.toString())??"",onChange:p=>{if(!p){d(0);return}d(Number(p))},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:zh,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:d=>c.onChange(d.currentTarget.checked)})}),s.jsx(a.Button,{leftIcon:s.jsx(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]})}function Lh({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]})),d=()=>{i({name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,yAxisIndex:0})},u=f.useMemo(()=>n.map(x=>({label:x.name,value:x.name})),[n]),p=t("y_axes"),h=f.useMemo(()=>p.map(({name:x},m)=>({label:x,value:m.toString()})),[p]);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:d,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),c.map((x,m)=>s.jsx(a.Tabs.Panel,{value:m.toString(),children:s.jsx(Ph,{control:e,index:m,remove:o,watch:t,variableOptions:u,yAxisOptions:h})},x.id))]})}const Oh=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}],Bh=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function $h({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,...d}})=>s.jsx(a.Select,{label:"Y Axis",data:i,disabled:i.length===0,...d,value:(l==null?void 0:l.toString())??"",onChange:u=>{if(!u){c(0);return}c(Number(u))},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:Oh,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:Bh,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(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(n),sx:{top:15,right:5},children:"Delete this Regression Line"})]})}function Vh({control:e,watch:t}){const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"regressions"}),o=t("regressions"),l=n.map((p,h)=>({...p,...o[h]})),c=t("y_axes"),d=f.useMemo(()=>c.map(({name:p},h)=>({label:p,value:h.toString()})),[c]),u=()=>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((p,h)=>s.jsx(a.Tabs.Tab,{value:h.toString(),children:h+1},p.id)),s.jsx(a.Tabs.Tab,{onClick:u,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),l.map((p,h)=>s.jsx(a.Tabs.Panel,{value:h.toString(),children:s.jsx($h,{regressionItem:p,control:e,index:h,remove:i,yAxisOptions:d})},p.id))]})}const Ls={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
|
|
124
|
+
`)}},Os={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 Ji(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=Ji(i.content,o.content,n+1);if(l!=null)return l}n+=i.nodeSize}}function Zi(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),d=l.nodeSize;if(l==c){n-=d,r-=d;continue}if(!l.sameMarkup(c))return{a:n,b:r};if(l.isText&&l.text!=c.text){let u=0,p=Math.min(l.text.length,c.text.length);for(;u<p&&l.text[l.text.length-u-1]==c.text[c.text.length-u-1];)u++,n--,r--;return{a:n,b:r}}if(l.content.size||c.content.size){let u=Zi(l.content,c.content,n-1,r-1);if(u)return u}n-=d,r-=d}}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 d=this.content[l],u=c+d.nodeSize;if(u>t&&r(d,i+c,o||null,l)!==!1&&d.content.size){let p=c+1;d.nodesBetween(Math.max(0,t-p),Math.min(d.content.size,n-p),r,i+p)}c=u}}descendants(t){this.nodesBetween(0,this.size,t)}textBetween(t,n,r,i){let o="",l=!0;return this.nodesBetween(t,n,(c,d)=>{c.isText?(o+=c.text.slice(Math.max(t,d)-d,n-d),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],d=l+c.nodeSize;d>t&&((l<t||d>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=d}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 Ji(this,t,n)}findDiffEnd(t,n=this.size,r=t.size){return Zi(this,t,n,r)}findIndex(t,n=-1){if(t==0)return bn(0,t);if(t==this.size)return bn(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?bn(r+1,l):bn(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 Bs={index:0,offset:0};function bn(e,t){return Bs.index=e,Bs.offset=t,Bs}function $s(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(!$s(e[r],t[r]))return!1}else{for(let r in e)if(!(r in t)||!$s(e[r],t[r]))return!1;for(let r in t)if(!(r in e))return!1}return!0}class Ee{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&&$s(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 Ee.none;if(t instanceof Ee)return[t];let n=t.slice();return n.sort((r,i)=>r.type.rank-i.type.rank),n}}Ee.none=[];class Nh extends Error{}class H{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=ea(this.content,t+this.openStart,n);return r&&new H(r,this.openStart,this.openEnd)}removeBetween(t,n){return new H(Hi(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 H.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 H(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 H(t,r,i)}}H.empty=new H(J.empty,0,0);function Hi(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(Hi(o.content,t-i-1,n-i-1)))}function ea(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=ea(l.content,t-o-1,n);return c&&e.replaceChild(i,l.copy(c))}class jn{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 ra(this,n,!1);return r.addAll(t,n.from,n.to),r.finish()}parseSlice(t,n={}){let r=new ra(this,n,!0);return r.addAll(t,n.from,n.to),H.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(Gh(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 d=l.getAttrs(n);if(d===!1)continue;l.attrs=d||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=ia(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=ia(l)),l.node||l.ignore||l.mark||(l.node=i)})}return n}static fromSchema(t){return t.cached.domParser||(t.cached.domParser=new jn(t,jn.schemaRules(t)))}}const ta={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},qh={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},na={ol:!0,ul:!0},vn=1,wn=2,Yt=4;function sa(e,t,n){return t!=null?(t?vn:0)|(t==="full"?wn:0):e&&e.whitespace=="pre"?vn|wn:n&~Yt}class Cn{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=Ee.none,this.stashMarks=[],this.match=l||(c&Yt?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&vn)){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):Rh(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&&!ta.hasOwnProperty(t.parentNode.nodeName.toLowerCase())}}class ra{constructor(t,n,r){this.parser=t,this.options=n,this.isOpen=r,this.open=0;let i=n.topNode,o,l=sa(null,n.preserveWhitespace,0)|(r?Yt:0);i?o=new Cn(i.type,i.attrs,Ee.none,Ee.none,!0,n.topMatch||i.type.contentMatch,l):r?o=new Cn(null,null,Ee.none,Ee.none,!0,null,l):o=new Cn(t.schema.topNodeType,null,Ee.none,Ee.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(Wh(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&wn||r.inlineContext(t)||/[^ \t\r\n\u000c]/.test(n)){if(r.options&vn)r.options&wn?n=n.replace(/\r\n?/g,`
|
|
125
|
+
`):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;na.hasOwnProperty(r)&&this.parser.normalizeLists&&Fh(t);let o=this.options.ruleFromNode&&this.options.ruleFromNode(t)||(i=this.parser.matchTag(t,this,n));if(o?o.ignore:qh.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,d=this.needsBlock;if(ta.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=d}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(`
|
|
126
|
+
`))}ignoreFallback(t){t.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"))}readStyles(t){let n=Ee.none,r=Ee.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(d=>this.insertNode(d));else{let d=t;typeof n.contentElement=="string"?d=t.querySelector(n.contentElement):typeof n.contentElement=="function"?d=n.contentElement(t):n.contentElement&&(d=n.contentElement),this.findAround(t,d,!0),this.addAll(d)}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=sa(t,i,o.options);o.options&Yt&&o.content.length==0&&(l|=Yt),this.nodes.push(new Cn(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,d)=>{for(;c>=0;c--){let u=n[c];if(u==""){if(c==n.length-1||c==0)continue;for(;d>=o;d--)if(l(c-1,d))return!0;return!1}else{let p=d>0||d==0&&i?this.nodes[d].type:r&&d>=o?r.node(d-o).type:null;if(!p||p.name!=u&&p.groups.indexOf(u)==-1)return!1;d--}}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=Qh(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 Fh(e){for(let t=e.firstChild,n=null;t;t=t.nextSibling){let r=t.nodeType==1?t.nodeName.toLowerCase():null;r&&na.hasOwnProperty(r)&&n?(n.appendChild(t),t=n):r=="li"?n=t:r&&(n=null)}}function Gh(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function Wh(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 ia(e){let t={};for(let n in e)t[n]=e[n];return t}function Rh(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 d=0;d<c.edgeCount;d++){let{type:u,next:p}=c.edge(d);if(u==t||o.indexOf(p)<0&&l(p))return!0}};if(l(i.contentMatch))return!0}}function Qh(e,t){for(let n=0;n<t.length;n++)if(e.eq(t[n]))return t[n]}const aa=65535,oa=Math.pow(2,16);function Uh(e,t){return e+t*oa}function la(e){return e&aa}function Yh(e){return(e-(e&aa))/oa}const ca=1,da=2,Sn=4,ua=8;class pa{constructor(t,n,r){this.pos=t,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&ua)>0}get deletedBefore(){return(this.delInfo&(ca|Sn))>0}get deletedAfter(){return(this.delInfo&(da|Sn))>0}get deletedAcross(){return(this.delInfo&Sn)>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=la(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+Yh(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 d=this.ranges[c]-(this.inverted?i:0);if(d>t)break;let u=this.ranges[c+o],p=this.ranges[c+l],h=d+u;if(t<=h){let x=u?t==d?-1:t==h?1:n:n,m=d+i+(x<0?0:p);if(r)return m;let j=t==(n<0?d:h)?null:Uh(c/3,t-d),w=t==d?da:t==h?ca:Sn;return(n<0?t!=d:t!=h)&&(w|=ua),new pa(m,w,j)}i+=p-u}return r?t+i:new pa(t+i,0,null)}touches(t,n){let r=0,i=la(n),o=this.inverted?2:1,l=this.inverted?1:2;for(let c=0;c<this.ranges.length;c+=3){let d=this.ranges[c]-(this.inverted?r:0);if(d>t)break;let u=this.ranges[c+o],p=d+u;if(t<=p&&c==i*3)return!0;r+=this.ranges[c+l]-u}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),d=l+(this.inverted?0:o),u=this.ranges[i+n],p=this.ranges[i+r];t(c,c+u,d,d+p),o+=p-u}}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 Vs=Object.create(null);class Ie{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=Vs[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 Vs)throw new RangeError("Duplicate use of step JSON ID "+t);return Vs[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 Nh)return xe.fail(o.message);throw o}}}function Ns(e,t,n){let r=[];for(let i=0;i<e.childCount;i++){let o=e.child(i);o.content.size&&(o=o.copy(Ns(o.content,t,o))),o.isInline&&(o=t(o,n,i)),r.push(o)}return J.fromArray(r)}class yt 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 H(Ns(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 bt(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 yt(n.pos,r.pos,this.mark)}merge(t){return t instanceof yt&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new yt(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 yt(n.from,n.to,t.markFromJSON(n.mark))}}Ie.jsonID("addMark",yt);class bt 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 H(Ns(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 yt(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 bt(n.pos,r.pos,this.mark)}merge(t){return t instanceof bt&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new bt(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 bt(n.from,n.to,t.markFromJSON(n.mark))}}Ie.jsonID("removeMark",bt);class jt 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 H(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 jt(this.pos,n.marks[i]);return new jt(this.pos,this.mark)}}return new Kt(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new jt(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 jt(n.pos,t.markFromJSON(n.mark))}}Ie.jsonID("addNodeMark",jt);class Kt 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 H(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 jt(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new Kt(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 Kt(n.pos,t.markFromJSON(n.mark))}}Ie.jsonID("removeNodeMark",Kt);class Ze 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 qe([this.from,this.to-this.from,this.slice.size])}invert(t){return new Ze(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 Ze(n.pos,Math.max(n.pos,r.pos),this.slice)}merge(t){if(!(t instanceof Ze)||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?H.empty:new H(this.slice.content.append(t.slice.content),this.slice.openStart,t.slice.openEnd);return new Ze(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?H.empty:new H(t.slice.content.append(this.slice.content),t.slice.openStart,this.slice.openEnd);return new Ze(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 Ze(n.from,n.to,H.fromJSON(t,n.slice),!!n.structure)}}Ie.jsonID("replace",Ze);class vt 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 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 vt(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 vt(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 vt(n.from,n.to,n.gapFrom,n.gapTo,H.fromJSON(t,n.slice),n.insert,!!n.structure)}}Ie.jsonID("replaceAround",vt);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 Kh(e,t,n){return(t==0||e.canReplace(t,e.childCount))&&(n==e.childCount||e.canReplace(0,n))}function Xh(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||!Kh(i,o,l))break}return null}function _n(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 u=i.depth-1,p=n-2;u>o;u--,p--){let h=i.node(u),x=i.index(u);if(h.type.spec.isolating)return!1;let m=h.content.cutByIndex(x,h.childCount),j=r&&r[p+1];j&&(m=m.replaceChild(0,j.type.create(j.attrs)));let w=r&&r[p]||h;if(!h.canReplace(x+1,h.childCount)||!w.type.validContent(m))return!1}let c=i.indexAfter(o),d=r&&r[0];return i.node(o).canReplaceWith(c,c,d?d.type:i.node(o+1).type)}function ha(e,t){let n=e.resolve(t),r=n.index();return Jh(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function Jh(e,t){return!!(e&&t&&!e.isLeaf&&e.canAppend(t))}class Xt 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 H(J.from(i),0,n.isLeaf?0:1))}getMap(){return qe.empty}invert(t){return new Xt(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 Xt(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 Xt(n.pos,n.attr,n.value)}}Ie.jsonID("attr",Xt);let Jt=class extends Error{};Jt=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n},Jt.prototype=Object.create(Error.prototype),Jt.prototype.constructor=Jt,Jt.prototype.name="TransformError";const Fs=Object.create(null);class se{constructor(t,n,r){this.$anchor=t,this.$head=n,this.ranges=r||[new Zh(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=H.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:d,$to:u}=l[c],p=t.mapping.slice(o);t.replaceRange(p.map(d.pos),p.map(u.pos),c?H.empty:n),c==0&&ga(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],d=t.mapping.slice(r),u=d.map(l.pos),p=d.map(c.pos);o?t.deleteRange(u,p):(t.replaceRangeWith(u,p,n),ga(t,r,n.isInline?-1:1))}}static findFrom(t,n,r=!1){let i=t.parent.inlineContent?new fe(t):Et(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?Et(t.node(0),t.node(o),t.before(o+1),t.index(o),n,r):Et(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 at(t.node(0))}static atStart(t){return Et(t,t,0,0,1)||new at(t)}static atEnd(t){return Et(t,t,t.content.size,t.childCount,-1)||new at(t)}static fromJSON(t,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=Fs[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 Fs)throw new RangeError("Duplicate use of selection JSON ID "+t);return Fs[t]=n,n.prototype.jsonID=t,n}getBookmark(){return fe.between(this.$anchor,this.$head).getBookmark()}}se.prototype.visible=!0;class Zh{constructor(t,n){this.$from=t,this.$to=n}}let xa=!1;function fa(e){!xa&&!e.parent.inlineContent&&(xa=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+e.parent.type.name+")"))}class fe extends se{constructor(t,n=t){fa(t),fa(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 se.near(r);let i=t.resolve(n.map(this.anchor));return new fe(i.parent.inlineContent?i:r,r)}replace(t,n=H.empty){if(super.replace(t,n),n==H.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 kn(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=se.findFrom(n,r,!0)||se.findFrom(n,-r,!0);if(o)n=o.$head;else return se.near(n,r)}return t.parent.inlineContent||(i==0?t=n:(t=(se.findFrom(t,-r,!0)||se.findFrom(t,r,!0)).$anchor,t.pos<n.pos!=i<0&&(t=n))),new fe(t,n)}}se.jsonID("text",fe);class kn{constructor(t,n){this.anchor=t,this.head=n}map(t){return new kn(t.map(this.anchor),t.map(this.head))}resolve(t){return fe.between(t.resolve(this.anchor),t.resolve(this.head))}}class Pe extends se{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?se.near(o):new Pe(o)}content(){return new H(J.from(this.node),0,0)}eq(t){return t instanceof Pe&&t.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new Gs(this.anchor)}static fromJSON(t,n){if(typeof n.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new Pe(t.resolve(n.anchor))}static create(t,n){return new Pe(t.resolve(n))}static isSelectable(t){return!t.isText&&t.type.spec.selectable!==!1}}Pe.prototype.visible=!1,se.jsonID("node",Pe);class Gs{constructor(t){this.anchor=t}map(t){let{deleted:n,pos:r}=t.mapResult(this.anchor);return n?new kn(r,r):new Gs(r)}resolve(t){let n=t.resolve(this.anchor),r=n.nodeAfter;return r&&Pe.isSelectable(r)?new Pe(n):se.near(n)}}class at extends se{constructor(t){super(t.resolve(0),t.resolve(t.content.size))}replace(t,n=H.empty){if(n==H.empty){t.delete(0,t.doc.content.size);let r=se.atStart(t.doc);r.eq(t.selection)||t.setSelection(r)}else super.replace(t,n)}toJSON(){return{type:"all"}}static fromJSON(t){return new at(t)}map(t){return new at(t)}eq(t){return t instanceof at}getBookmark(){return Hh}}se.jsonID("all",at);const Hh={map(){return this},resolve(e){return new at(e)}};function Et(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&&Pe.isSelectable(c))return Pe.create(e,n-(i<0?c.nodeSize:0))}else{let d=Et(e,c,n+i,i<0?c.childCount:0,i,o);if(d)return d}n+=c.nodeSize*i}return null}function ga(e,t,n){let r=e.steps.length-1;if(r<t)return;let i=e.steps[r];if(!(i instanceof Ze||i instanceof vt))return;let o=e.mapping.maps[r],l;o.forEach((c,d,u,p)=>{l==null&&(l=p)}),e.setSelection(se.near(e.doc.resolve(l),n))}function ma(e,t){return!t||!e?e:e.bind(t)}class Tn{constructor(t,n,r){this.name=t,this.init=ma(n.init,r),this.apply=ma(n.apply,r)}}new Tn("doc",{init(e){return e.doc||e.schema.topNodeType.createAndFill()},apply(e){return e.doc}}),new Tn("selection",{init(e,t){return e.selection||se.atStart(t.doc)},apply(e){return e.selection}}),new Tn("storedMarks",{init(e){return e.storedMarks||null},apply(e,t,n,r){return r.selection.$cursor?e.storedMarks:null}}),new Tn("scrollToSelection",{init(){return 0},apply(e,t){return e.scrolledIntoView?t+1:t}});function ya(e,t,n){for(let r in e){let i=e[r];i instanceof Function?i=i.bind(t):r=="handleDOMEvents"&&(i=ya(i,t,{})),n[r]=i}return n}class Zt{constructor(t){this.spec=t,this.props={},t.props&&ya(t.props,this,this.props),this.key=t.key?t.key.key:ba("plugin")}getState(t){return t[this.key]}}const Ws=Object.create(null);function ba(e){return e in Ws?e+"$"+ ++Ws[e]:(Ws[e]=0,e+"$")}class Ht{constructor(t="key"){this.key=ba(t)}get(t){return t.config.pluginsByKey[this.key]}getState(t){return t[this.key]}}function ja(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 ex{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,d])=>[c,(...p)=>{const h=d(...p)(l);return!o.getMeta("preventDispatch")&&!this.hasCustomState&&i.dispatch(o),h}]))}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=[],d=!!t,u=t||o.tr,p=()=>(!d&&n&&!u.getMeta("preventDispatch")&&!this.hasCustomState&&l.dispatch(u),c.every(x=>x===!0)),h={...Object.fromEntries(Object.entries(r).map(([x,m])=>[x,(...w)=>{const T=this.buildProps(u,n),M=m(...w)(T);return c.push(M),h}])),run:p};return h}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(([d,u])=>[d,(...p)=>u(...p)({...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:ja({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(([d,u])=>[d,(...p)=>u(...p)(c)]))}};return c}}function pt(e,t,n){return e.config[t]===void 0&&e.parent?pt(e.parent,t,n):typeof e.config[t]=="function"?e.config[t].bind({...n,parent:e.parent?pt(e.parent,t,n):null}):e.config[t]}function tx(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 nx(e){return typeof e=="function"}function Pt(e,t=void 0,...n){return nx(e)?t?e.bind(t)(...n):e(...n):e}function sx(e){return Object.prototype.toString.call(e)==="[object RegExp]"}function rx(e){return Object.prototype.toString.call(e).slice(8,-1)}function Rs(e){return rx(e)!=="Object"?!1:e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype}function va(e,t){const n={...e};return Rs(e)&&Rs(t)&&Object.keys(t).forEach(r=>{Rs(t[r])?r in e?n[r]=va(e[r],t[r]):Object.assign(n,{[r]:t[r]}):Object.assign(n,{[r]:t[r]})}),n}class He{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=Pt(pt(this,"addOptions",{name:this.name}))),this.storage=Pt(pt(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(t={}){return new He(t)}configure(t={}){const n=this.extend();return n.options=va(this.options,t),n.storage=Pt(pt(n,"addStorage",{name:n.name,options:n.options})),n}extend(t={}){const n=new He(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=Pt(pt(n,"addOptions",{name:n.name})),n.storage=Pt(pt(n,"addStorage",{name:n.name,options:n.options})),n}}function ix(e,t,n){const{from:r,to:i}=t,{blockSeparator:o=`
|
|
127
127
|
|
|
128
|
-
`,textSerializers:l={}}=n||{};let c="",u=!0;return e.nodesBetween(r,i,(d,p,h,x)=>{var m;const j=l==null?void 0:l[d.type.name];j?(d.isBlock&&!u&&(c+=o,u=!0),h&&(c+=j({node:d,pos:p,parent:h,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,p)-p,i-p),u=!1):d.isBlock&&!u&&(c+=o,u=!0)}),c}function sx(e){return Object.fromEntries(Object.entries(e.nodes).filter(([,t])=>t.spec.toText).map(([t,n])=>[t,n.spec.toText]))}He.create({name:"clipboardTextSerializer",addProseMirrorPlugins(){return[new Zt({key:new Ht("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(p=>p.$from.pos)),c=Math.max(...o.map(p=>p.$to.pos)),u=sx(n);return nx(r,{from:l,to:c},{textSerializers:u})}}})]}});const rx=()=>({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),ix=(e=!1)=>({commands:t})=>t.setContent("",e),ax=()=>({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:p}=t,h=d.resolve(p.map(u)),x=d.resolve(p.map(u+c.nodeSize)),m=h.blockRange(x);if(!m)return;const j=Uh(m);if(c.type.isTextblock){const{defaultType:w}=h.parent.contentMatchAt(h.index());t.setNodeMarkup(m.start,w)}(j||j===0)&&t.lift(m,j)})}),!0},ox=e=>t=>e(t),lx=()=>({state:e,dispatch:t})=>me.createParagraphNear(e,t),cx=()=>({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},ux=e=>({tr:t,state:n,dispatch:r})=>{const i=je(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},dx=e=>({tr:t,dispatch:n})=>{const{from:r,to:i}=e;return n&&t.delete(r,i),!0},px=()=>({state:e,dispatch:t})=>me.deleteSelection(e,t),hx=()=>({commands:e})=>e.keyboardShortcut("Enter"),xx=()=>({state:e,dispatch:t})=>me.exitCode(e,t);function Dn(e,t,n={strict:!0}){const r=Object.keys(t);return r.length?r.every(i=>n.strict?t[i]===e[i]:ex(t[i])?t[i].test(e[i]):t[i]===e[i]):!0}function Qs(e,t,n={}){return e.find(r=>r.type===t&&Dn(r.attrs,n))}function fx(e,t,n={}){return!!Qs(e,t,n)}function va(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=Qs([...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(Qs([...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&&fx([...e.parent.child(c).marks],t,n);)u+=e.parent.child(c).nodeSize,c+=1;return{from:l,to:u}}function ht(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 gx=(e,t={})=>({tr:n,state:r,dispatch:i})=>{const o=ht(e,r.schema),{doc:l,selection:c}=n,{$from:u,from:d,to:p}=c;if(i){const h=va(u,o,t);if(h&&h.from<=d&&h.to>=p){const x=xe.create(l,h.from,h.to);n.setSelection(x)}}return!0},mx=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 wa(e){return e instanceof xe}function wt(e=0,t=0,n=0){return Math.min(Math.max(e,t),n)}function yx(e,t=null){if(!t)return null;const n=ne.atStart(e),r=ne.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,wt(0,i,o),wt(e.content.size,i,o)):xe.create(e,wt(t,i,o),wt(t,i,o))}function Us(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}const bx=(e=null,t={})=>({editor:n,view:r,tr:i,dispatch:o})=>{t={scrollIntoView:!0,...t};const l=()=>{Us()&&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&&!wa(n.state.selection))return l(),!0;const c=yx(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},jx=(e,t)=>n=>e.every((r,i)=>t(r,{...n,index:i})),vx=(e,t)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},e,t);function Ca(e){const t=`<body>${e}</body>`;return new window.DOMParser().parseFromString(t,"text/html").body}function In(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),In("",t,n)}if(typeof e=="string"){const r=jn.fromSchema(t);return n.slice?r.parseSlice(Ca(e),n.parseOptions).content:r.parse(Ca(e),n.parseOptions)}return In("",t,n)}function wx(e,t,n){const r=e.steps.length-1;if(r<t)return;const i=e.steps[r];if(!(i instanceof Ze||i instanceof vt))return;const o=e.mapping.maps[r];let l=0;o.forEach((c,u,d,p)=>{l===0&&(l=p)}),e.setSelection(ne.near(e.doc.resolve(l),n))}const Cx=e=>e.toString().startsWith("<"),Sx=(e,t,n)=>({tr:r,dispatch:i,editor:o})=>{if(i){n={parseOptions:{},updateSelection:!0,...n};const l=In(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,p=!0;if((Cx(l)?l:[l]).forEach(x=>{x.check(),d=d?x.isText&&x.marks.length===0:!1,p=p?x.isBlock:!1}),c===u&&p){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&&wx(r,r.steps.length-1,-1)}return!0},_x=()=>({state:e,dispatch:t})=>me.joinUp(e,t),kx=()=>({state:e,dispatch:t})=>me.joinDown(e,t),Tx=()=>({state:e,dispatch:t})=>me.joinBackward(e,t),Dx=()=>({state:e,dispatch:t})=>me.joinForward(e,t);function Sa(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function Ix(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))Us()||Sa()?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 Mx=e=>({editor:t,view:n,tr:r,dispatch:i})=>{const o=Ix(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 p=d.map(r.mapping);p&&i&&r.maybeStep(p)}),!0};function Ys(e,t,n={}){const{from:r,to:i,empty:o}=e.selection,l=t?je(t,e.schema):null,c=[];e.doc.nodesBetween(r,i,(h,x)=>{if(h.isText)return;const m=Math.max(r,x),j=Math.min(i,x+h.nodeSize);c.push({node:h,from:m,to:j})});const u=i-r,d=c.filter(h=>l?l.name===h.node.type.name:!0).filter(h=>Dn(h.node.attrs,n,{strict:!1}));return o?!!d.length:d.reduce((h,x)=>h+x.to-x.from,0)>=u}const Ax=(e,t={})=>({state:n,dispatch:r})=>{const i=je(e,n.schema);return Ys(n,i,t)?me.lift(n,r):!1},zx=()=>({state:e,dispatch:t})=>me.liftEmptyBlock(e,t),Ex=e=>({state:t,dispatch:n})=>{const r=je(e,t.schema);return ss.liftListItem(r)(t,n)},Px=()=>({state:e,dispatch:t})=>me.newlineInCode(e,t);function _a(e,t){return t.nodes[e]?"node":t.marks[e]?"mark":null}function ka(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 Lx=(e,t)=>({tr:n,state:r,dispatch:i})=>{let o=null,l=null;const c=_a(typeof e=="string"?e:e.name,r.schema);return c?(c==="node"&&(o=je(e,r.schema)),c==="mark"&&(l=ht(e,r.schema)),i&&n.selection.ranges.forEach(u=>{r.doc.nodesBetween(u.$from.pos,u.$to.pos,(d,p)=>{o&&o===d.type&&n.setNodeMarkup(p,void 0,ka(d.attrs,t)),l&&d.marks.length&&d.marks.forEach(h=>{l===h.type&&n.addMark(p,p+d.nodeSize,l.create(ka(h.attrs,t)))})})}),!0):!1},Ox=()=>({tr:e,dispatch:t})=>(t&&e.scrollIntoView(),!0),Bx=()=>({tr:e,commands:t})=>t.setTextSelection({from:0,to:e.doc.content.size}),$x=()=>({state:e,dispatch:t})=>me.selectNodeBackward(e,t),Vx=()=>({state:e,dispatch:t})=>me.selectNodeForward(e,t),Nx=()=>({state:e,dispatch:t})=>me.selectParentNode(e,t),qx=()=>({state:e,dispatch:t})=>me.selectTextblockEnd(e,t),Fx=()=>({state:e,dispatch:t})=>me.selectTextblockStart(e,t);function Gx(e,t,n={}){return In(e,t,{slice:!1,parseOptions:n})}const Wx=(e,t=!1,n={})=>({tr:r,editor:i,dispatch:o})=>{const{doc:l}=r,c=Gx(e,i.schema,n);return o&&r.replaceWith(0,l.content.size,c).setMeta("preventUpdate",!t),!0};function Rx(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 Qx(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 Ks(e){return t=>Qx(t.$from,e)}function Ux(e,t){const n=ht(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 Mn(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 Yx(e,t,n={}){const{empty:r,ranges:i}=e.selection,o=t?ht(t,e.schema):null;if(r)return!!(e.storedMarks||e.selection.$from.marks()).filter(h=>o?o.name===h.type.name:!0).find(h=>Dn(h.attrs,n,{strict:!1}));let l=0;const c=[];if(i.forEach(({$from:h,$to:x})=>{const m=h.pos,j=x.pos;e.doc.nodesBetween(m,j,(w,T)=>{if(!w.isText&&!w.marks.length)return;const M=Math.max(m,T),P=Math.min(j,T+w.nodeSize),U=P-M;l+=U,c.push(...w.marks.map(se=>({mark:se,from:M,to:P})))})}),l===0)return!1;const u=c.filter(h=>o?o.name===h.mark.type.name:!0).filter(h=>Dn(h.mark.attrs,n,{strict:!1})).reduce((h,x)=>h+x.to-x.from,0),d=c.filter(h=>o?h.mark.type!==o&&h.mark.type.excludes(o):!0).reduce((h,x)=>h+x.to-x.from,0);return(u>0?u+d:u)>=l}function Ta(e,t){const{nodeExtensions:n}=Zh(t),r=n.find(l=>l.name===e);if(!r)return!1;const i={name:r.name,options:r.options,storage:r.storage},o=Pt(pt(r,"group",i));return typeof o!="string"?!1:o.split(" ").includes("list")}function Kx(e,t,n){var r;const{selection:i}=t;let o=null;if(wa(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,(p,h,x)=>{if(d)return!1;if(p.isInline){const m=!x||x.type.allowsMarkType(n),j=!!n.isInSet(p.marks)||!p.marks.some(w=>w.type.excludes(n));d=m&&j}return!d}),d})}const Xx=(e,t={})=>({tr:n,state:r,dispatch:i})=>{const{selection:o}=n,{empty:l,ranges:c}=o,u=ht(e,r.schema);if(i)if(l){const d=Ux(r,u);n.addStoredMark(u.create({...d,...t}))}else c.forEach(d=>{const p=d.$from.pos,h=d.$to.pos;r.doc.nodesBetween(p,h,(x,m)=>{const j=Math.max(m,p),w=Math.min(m+x.nodeSize,h);x.marks.find(M=>M.type===u)?x.marks.forEach(M=>{u===M.type&&n.addMark(j,w,u.create({...M.attrs,...t}))}):n.addMark(j,w,u.create(t))})});return Kx(r,n,u)},Jx=(e,t)=>({tr:n})=>(n.setMeta(e,t),!0),Zx=(e,t={})=>({state:n,dispatch:r,chain:i})=>{const o=je(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)},Hx=e=>({tr:t,dispatch:n})=>{if(n){const{doc:r}=t,i=wt(e,0,r.content.size),o=Pe.create(r,i);t.setSelection(o)}return!0},ef=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=wt(i,l,c),d=wt(o,l,c),p=xe.create(r,u,d);t.setSelection(p)}return!0},tf=e=>({state:t,dispatch:n})=>{const r=je(e,t.schema);return ss.sinkListItem(r)(t,n)};function Da(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 nf=({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,p=Mn(d,c.node().type.name,c.node().attrs);if(o instanceof Pe&&o.node.isBlock)return!c.parentOffset||!_n(l,c.pos)?!1:(r&&(e&&Da(n,i.extensionManager.splittableMarks),t.split(c.pos).scrollIntoView()),!0);if(!c.parent.isBlock)return!1;if(r){const h=u.parentOffset===u.parent.content.size;o instanceof xe&&t.deleteSelection();const x=c.depth===0?void 0:Rx(c.node(-1).contentMatchAt(c.indexAfter(-1)));let m=h&&x?[{type:x,attrs:p}]:void 0,j=_n(t.doc,t.mapping.map(c.pos),1,m);if(!m&&!j&&_n(t.doc,t.mapping.map(c.pos),1,x?[{type:x}]:void 0)&&(j=!0,m=x?[{type:x,attrs:p}]:void 0),j&&(t.split(t.mapping.map(c.pos),1,m),x&&!h&&!c.parentOffset&&c.parent.type!==x)){const w=t.mapping.map(c.before()),T=t.doc.resolve(w);c.node(-1).canReplaceWith(T.index(),T.index()+1,x)&&t.setNodeMarkup(t.mapping.map(c.before()),x)}e&&Da(n,i.extensionManager.splittableMarks),t.scrollIntoView()}return!0},sf=e=>({tr:t,state:n,dispatch:r,editor:i})=>{var o;const l=je(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 p=c.node(-1);if(p.type!==l)return!1;const h=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 M=c.index(-1)?1:c.index(-2)?2:3;for(let de=c.depth-M;de>=c.depth-3;de-=1)T=J.from(c.node(de).copy(T));const P=c.indexAfter(-1)<c.node(-2).childCount?1:c.indexAfter(-2)<c.node(-3).childCount?2:3,U=Mn(h,c.node().type.name,c.node().attrs),se=((o=l.contentMatch.defaultType)===null||o===void 0?void 0:o.createAndFill(U))||void 0;T=T.append(J.from(l.createAndFill(null,se)||void 0));const Q=c.before(c.depth-(M-1));t.replace(Q,c.after(-P),new H(T,4-M,0));let ie=-1;t.doc.nodesBetween(Q,t.doc.content.size,(de,fe)=>{if(ie>-1)return!1;de.isTextblock&&de.content.size===0&&(ie=fe+1)}),ie>-1&&t.setSelection(xe.near(t.doc.resolve(ie))),t.scrollIntoView()}return!0}const x=u.pos===c.end()?p.contentMatchAt(0).defaultType:null,m=Mn(h,p.type.name,p.attrs),j=Mn(h,c.node().type.name,c.node().attrs);t.delete(c.pos,u.pos);const w=x?[{type:l,attrs:m},{type:x,attrs:j}]:[{type:l,attrs:m}];if(!_n(t.doc,c.pos,2))return!1;if(r){const{selection:T,storedMarks:M}=n,{splittableMarks:P}=i.extensionManager,U=M||T.$to.parentOffset&&T.$from.marks();if(t.split(c.pos,2,w).scrollIntoView(),!U||!r)return!0;const se=U.filter(Q=>P.includes(Q.type.name));t.ensureMarks(se)}return!0},Xs=(e,t)=>{const n=Ks(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)&&pa(e.doc,n.pos)&&e.join(n.pos),!0},Js=(e,t)=>{const n=Ks(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)&&pa(e.doc,r)&&e.join(r),!0};var rf=Object.freeze({__proto__:null,blur:rx,clearContent:ix,clearNodes:ax,command:ox,createParagraphNear:lx,deleteCurrentNode:cx,deleteNode:ux,deleteRange:dx,deleteSelection:px,enter:hx,exitCode:xx,extendMarkRange:gx,first:mx,focus:bx,forEach:jx,insertContent:vx,insertContentAt:Sx,joinUp:_x,joinDown:kx,joinBackward:Tx,joinForward:Dx,keyboardShortcut:Mx,lift:Ax,liftEmptyBlock:zx,liftListItem:Ex,newlineInCode:Px,resetAttributes:Lx,scrollIntoView:Ox,selectAll:Bx,selectNodeBackward:$x,selectNodeForward:Vx,selectParentNode:Nx,selectTextblockEnd:qx,selectTextblockStart:Fx,setContent:Wx,setMark:Xx,setMeta:Jx,setNode:Zx,setNodeSelection:Hx,setTextSelection:ef,sinkListItem:tf,splitBlock:nf,splitListItem:sf,toggleList:(e,t,n,r={})=>({editor:i,tr:o,state:l,dispatch:c,chain:u,commands:d,can:p})=>{const{extensions:h,splittableMarks:x}=i.extensionManager,m=je(e,l.schema),j=je(t,l.schema),{selection:w,storedMarks:T}=l,{$from:M,$to:P}=w,U=M.blockRange(P),se=T||w.$to.parentOffset&&w.$from.marks();if(!U)return!1;const Q=Ks(ie=>Ta(ie.type.name,h))(w);if(U.depth>=1&&Q&&U.depth-Q.depth<=1){if(Q.node.type===m)return d.liftListItem(j);if(Ta(Q.node.type.name,h)&&m.validContent(Q.node.content)&&c)return u().command(()=>(o.setNodeMarkup(Q.pos,m),!0)).command(()=>Xs(o,m)).command(()=>Js(o,m)).run()}return!n||!se||!c?u().command(()=>p().wrapInList(m,r)?!0:d.clearNodes()).wrapInList(m,r).command(()=>Xs(o,m)).command(()=>Js(o,m)).run():u().command(()=>{const ie=p().wrapInList(m,r),de=se.filter(fe=>x.includes(fe.type.name));return o.ensureMarks(de),ie?!0:d.clearNodes()}).wrapInList(m,r).command(()=>Xs(o,m)).command(()=>Js(o,m)).run()},toggleMark:(e,t={},n={})=>({state:r,commands:i})=>{const{extendEmptyMarkRange:o=!1}=n,l=ht(e,r.schema);return Yx(r,l,t)?i.unsetMark(l,{extendEmptyMarkRange:o}):i.setMark(l,t)},toggleNode:(e,t,n={})=>({state:r,commands:i})=>{const o=je(e,r.schema),l=je(t,r.schema);return Ys(r,o,n)?i.setNode(l):i.setNode(o,n)},toggleWrap:(e,t={})=>({state:n,commands:r})=>{const i=je(e,n.schema);return Ys(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=ht(e,r.schema),{$from:d,empty:p,ranges:h}=c;if(!i)return!0;if(p&&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,w=va(d,u,j);w&&(x=w.from,m=w.to),n.removeMark(x,m,u)}else h.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=_a(typeof e=="string"?e:e.name,r.schema);return c?(c==="node"&&(o=je(e,r.schema)),c==="mark"&&(l=ht(e,r.schema)),i&&n.selection.ranges.forEach(u=>{const d=u.$from.pos,p=u.$to.pos;r.doc.nodesBetween(d,p,(h,x)=>{o&&o===h.type&&n.setNodeMarkup(x,void 0,{...h.attrs,...t}),l&&h.marks.length&&h.marks.forEach(m=>{if(l===m.type){const j=Math.max(x,d),w=Math.min(x+h.nodeSize,p);n.addMark(j,w,l.create({...m.attrs,...t}))}})})}),!0):!1},wrapIn:(e,t={})=>({state:n,dispatch:r})=>{const i=je(e,n.schema);return me.wrapIn(i,t)(n,r)},wrapInList:(e,t={})=>({state:n,dispatch:r})=>{const i=je(e,n.schema);return ss.wrapInList(i,t)(n,r)}});He.create({name:"commands",addCommands(){return{...rf}}}),He.create({name:"editable",addProseMirrorPlugins(){return[new Zt({key:new Ht("editable"),props:{editable:()=>this.editor.options.editable}})]}}),He.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:e}=this;return[new Zt({key:new Ht("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}}}})]}}),He.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:p,$anchor:h}=u,{pos:x,parent:m}=h,j=ne.atStart(d).from===x;return!p||!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 Us()||Sa()?o:i},addProseMirrorPlugins(){return[new Zt({key:new Ht("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=ne.atStart(t.doc).from,u=ne.atEnd(t.doc).to;if(i||!(o===c&&l===u)||!(n.doc.textBetween(0,n.doc.content.size," "," ").length===0))return;const h=n.tr,x=ba({state:n,transaction:h}),{commands:m}=new Jh({editor:this.editor,state:x});if(m.clearNodes(),!!h.steps.length)return h}})]}}),He.create({name:"tabindex",addProseMirrorPlugins(){return[new Zt({key:new Ht("tabindex"),props:{attributes:this.editor.isEditable?{tabindex:"0"}:{}}})]}});const Ia=He.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()}}}),af=["8","10","12","14","16","18","20","24","30","36","48","60","72"].map(e=>`${e}px`),of=[{label:"auto",value:""}].concat(af.map(e=>({label:e,value:e}))),lf={input:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important"}},cf=({editor:e})=>{const t=e.getAttributes("textStyle").fontSize;return s.jsx(q.RichTextEditor.ControlsGroup,{children:s.jsx(a.NativeSelect,{size:"xs",icon:s.jsx(k.IconTextSize,{stroke:1.5,size:16}),data:of,styles:lf,value:t||"",onChange:n=>{const r=n.currentTarget.value;r?e.chain().focus().setFontSize(r).run():e.chain().focus().unsetFontSize().run()}})})},An=({value:e,styles:t={}})=>{const n=pi.useEditor({extensions:[hi,di,q.Link,ri,si,ti,oi.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),ui,ci,li,ii.configure({types:["heading","paragraph"]}),ni.configure({placeholder:"This is placeholder"}),ai,ei.Color,Ia],content:e,editable:!1});f.useEffect(()=>{n==null||n.commands.setContent(e)},[e,n]);const r=f.useMemo(()=>y.defaultsDeep({},{content:Os},t),[t]);return s.jsx(q.RichTextEditor,{editor:n,styles:r,children:s.jsx(q.RichTextEditor.Content,{})})};function uf(){const[e,{open:t,close:n}]=oe.useDisclosure(!1);return s.jsxs(s.Fragment,{children:[s.jsx(a.Modal,{opened:e,onClose:n,title:"About FunctionUtils",zIndex:330,withinPortal:!0,children:s.jsx(An,{value:uu,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(k.IconInfoCircle,{size:16}),children:"About parameter 'utils'"})]})}const df=({value:e,onChange:t})=>{const n=r=>{r&&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}}})})},en=f.forwardRef(({value:e,onChange:t,label:n,defaultValue:r},i)=>{const[o,l]=f.useState(e),c=()=>{t(o)},u=()=>{l(e)},d=()=>{l(r)};f.useEffect(()=>{l(e)},[e]);const p=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(uf,{})}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:d,size:"xs",variant:"default",leftIcon:s.jsx(k.IconPlayerSkipBack,{size:16}),children:"Reset to default"}),s.jsx(a.Button,{onClick:u,color:"red",size:"xs",disabled:!p,leftIcon:s.jsx(k.IconRecycle,{size:16}),children:"Revert Changes"}),s.jsx(a.Button,{size:"xs",onClick:c,disabled:!p,leftIcon:s.jsx(k.IconDeviceFloppy,{size:16}),children:"Confirm Changes"})]})]}),s.jsx(a.Text,{size:14,children:n}),s.jsx(df,{value:o,onChange:l})]})}),pf=f.forwardRef(({value:e,onChange:t,label:n,triggerLabel:r="Edit",triggerButtonProps:i={},defaultValue:o},l)=>{const[c,{open:u,close:d}]=oe.useDisclosure(!1);return s.jsxs(s.Fragment,{children:[s.jsx(a.Modal,{opened:c,onClose:d,title:"Authentication",withinPortal:!0,zIndex:320,size:"900px",children:s.jsx(a.Box,{h:600,children:s.jsx(en,{value:e,onChange:t,defaultValue:o,label:n})})}),s.jsx(a.Button,{onClick:u,...i,children:r})]})}),hf=[{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 xf({label:e,value:t,onChange:n,pt:r="sm",withFallback:i},o){f.useEffect(()=>{typeof t=="string"&&n({type:t,config:{},fallback:"0"})},[t,n]);const l=p=>{n(p==="quantile"?{type:"quantile",config:{p:.99},fallback:t.fallback}:p==="custom"?{type:"custom",config:{func:Gi},fallback:t.fallback}:{type:p,config:{},fallback:t.fallback})},c=p=>{n({type:"quantile",config:{p},fallback:t.fallback})},u=p=>{n({type:"custom",config:{func:p},fallback:t.fallback})},d=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:hf,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(pf,{label:"",triggerLabel:"Edit Function",value:t.config.func,onChange:u,defaultValue:Gi,triggerButtonProps:{size:"xs",sx:{flexGrow:0,alignSelf:"center",marginTop:"22px"},leftIcon:s.jsx(k.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 Zs=f.forwardRef(xf),ff=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function gf({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:ff,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 mf=({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}}})})},yf=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:i}]=V.useBoolean(),[o,l]=f.useState(e),c=()=>{i();const{type:h,func_content:x}=o,m={type:h,func_content:x};l(m),t(m)},u=()=>{i(),l(e)},d=h=>{l(x=>({...x,func_content:h}))},p=()=>{d(Ls.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(mf,{value:o.func_content,onChange:d}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:p,color:"red",leftIcon:s.jsx(_.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"})]})]})]})})]})},bf=({value:e,onChange:t})=>e.type!=="dynamic"?null:s.jsx(yf,{value:e,onChange:t}),jf=({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})})},vf=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Ma=f.forwardRef(({label:e="Size",value:t,onChange:n},r)=>{const i=o=>{n({...Ls[o]})};return s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(a.Select,{ref:r,label:e,data:vf,value:t.type,onChange:i,sx:{flexGrow:1}}),s.jsx(jf,{value:t,onChange:n}),s.jsx(bf,{value:t,onChange:n})]})}),wf=[{label:"off",value:"false"},{label:"start",value:"start"},{label:"middle",value:"middle"},{label:"end",value:"end"}],Cf=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function Sf({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:Cf,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:wf,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(Ma,{label:"Symbol Size",...i})})]})]})}function _f({control:e,index:t}){return s.jsx(b.Controller,{name:`series.${t}.symbolSize`,control:e,render:({field:n})=>s.jsx(Ma,{label:"Size",...n})})}const kf=[{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 Tf({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(Zs,{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(B,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...l})})}),o==="line"&&s.jsx(Sf,{index:t,control:e,seriesItem:r}),o==="bar"&&s.jsx(gf,{index:t,control:e,seriesItem:r}),o==="scatter"&&s.jsx(_f,{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:kf,...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(Se,{...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(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Series"})]})}function Df({control:e,watch:t}){const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"series"}),o=t("series"),l=n.map((p,h)=>({...p,...o[h]})),c=()=>{const p={type:"bar",name:oe.randomId(),showSymbol:!1,symbolSize:Ls.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(p)},u=t("y_axes"),d=f.useMemo(()=>u.map(({name:p},h)=>({label:p,value:h.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((p,h)=>s.jsx(a.Tabs.Tab,{value:h.toString(),children:h+1},p.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),l.map((p,h)=>s.jsx(a.Tabs.Panel,{value:h.toString(),children:s.jsx(Tf,{control:e,index:h,remove:i,seriesItem:p,yAxisOptions:d},p.id)},p.id))]})}function If({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(Qt,{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(Qt,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const Mf=()=>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"]})})]})]}),Af=[{label:"Value",value:"value"},{label:"Category",value:"category"},{label:"Time",value:"time"},{label:"Log",value:"log"}];function zf({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(Mf,{}),required:!0,data:Af,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(mn,{...n})})]}),s.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>s.jsx(Je,{...n})})]})}const Ef=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],Pf=[{label:"left",value:"left"},{label:"right",value:"right"}];function Lf({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:Ef,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:Pf,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(Oe,{...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(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this YAxis"})]})}function Of({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(_.Plus,{size:18,color:"#228be6"})})]}),l.map((u,d)=>s.jsx(a.Tabs.Panel,{value:d.toString(),children:s.jsx(Lf,{control:e,index:d,remove:i})},u.id))]})}function Bf({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),{variables:r}=e,i=f.useMemo(()=>y.defaultsDeep({},t,As),[t]),{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=b.useForm({defaultValues:i});f.useEffect(()=>{d(i)},[i]);const p=u(),h=f.useMemo(()=>!y.isEqual(p,i),[p,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:!h,children:s.jsx(_.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:"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(zf,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Y Axes",children:s.jsx(Of,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Series",children:s.jsx(Df,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Regression Lines",children:s.jsx(Oh,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Stats",children:s.jsx(If,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Reference Lines",children:s.jsx(zh,{variables:r,control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Reference Areas",children:s.jsx(Dh,{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(Ps,{...x})})})]})]})})}function $f(e){const t=y.cloneDeep(y.omit(e,"variables"));return t.stats=y.omit(t.stats,"variables"),t}function Vf(e){const{rotate:t,formatter:n=Be}=e.x_axis.axisLabel;return{...e,x_axis:{...e.x_axis,axisLabel:{rotate:t,formatter:n}}}}function Nf(e){const{dataZoom:t=zt,...n}=e;return{...n,dataZoom:t}}function qf(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 Ff(e){const t=e.reference_lines.map(n=>{const{lineStyle:r={type:"dashed",width:1,color:nt.random().css()},show_in_legend:i=!1}=n;return{...n,lineStyle:r,show_in_legend:i}});return{...e,reference_lines:t}}function Gf(e){const t=e.reference_lines.map(n=>{const{yAxisIndex:r=0}=n;return{...n,yAxisIndex:r}});return{...e,reference_lines:t}}function Wf(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 Rf(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 Qf(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 Uf(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 Yf(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 Kf(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(r=>{const{nameAlignment:i="left"}=r;return{...r,nameAlignment:i}})}}function Xf(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(r=>{const{show:i=!0}=r;return{...r,show:i}})}}function Jf(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 Zf(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 Hf(e){const{type:t="category",...n}=e.x_axis;return{...e,x_axis:{...n,type:t}}}function eg(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}}class tg extends re{constructor(){super(...arguments);E(this,"VERSION",18)}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:$f(i)}}),this.version(3,n=>({...n,version:3,config:Vf(n.config)})),this.version(4,n=>({...n,version:4,config:Nf(n.config)})),this.version(5,n=>({...n,version:5,config:qf(n.config)})),this.version(6,n=>({...n,version:6,config:Ff(n.config)})),this.version(7,n=>({...n,version:7,config:Gf(n.config)})),this.version(8,n=>({...n,version:8,config:Wf(n.config)})),this.version(9,n=>({...n,version:9,config:Rf(n.config)})),this.version(10,n=>({...n,version:10,config:Qf(n.config)})),this.version(11,n=>({...n,version:11,config:Uf(n.config)})),this.version(12,n=>({...n,version:12,config:Yf(n.config)})),this.version(13,n=>({...n,version:13,config:Kf(n.config)})),this.version(14,n=>({...n,version:14,config:Xf(n.config)})),this.version(15,n=>({...n,version:15,config:Jf(n.config)})),this.version(16,n=>({...n,version:16,config:Zf(n.config)})),this.version(17,n=>({...n,version:17,config:Hf(n.config)})),this.version(18,(n,r)=>({...n,version:18,config:eg(n.config,r)}))}}const ng={displayName:"Cartesian Chart",displayGroup:"ECharts-based charts",migrator:new tg,name:"cartesian",viewRender:Sh,configRender:Bf,createConfig(){return{version:18,config:y.cloneDeep(As)}},triggers:[Ms]};function sg(e){if(e.enable_value)return e.value}function rg(e){if(e.enable_value)return e.value}function ig(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 ag(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,...p}=n;if(!r||!i)return{};const h=A(r),x=A(i),m=t[h.queryID].map(w=>({name:w[h.columnKey],value:w[x.columnKey]})),j=Ue(o.overflow.on_axis);return{type:"funnel",...ig(n),min:sg(l),max:rg(c),minSize:l.size,maxSize:c.size,...p,label:{show:!0,position:o.position,...j},orient:d,funnelAlign:d==="horizontal"?"center":u,data:m}})}function og({conf:e,params:t,max:n}){const{name:r,value:i}=t.data,o=F(i/n).format({output:"percent",mantissa:2,trimMantissa:!0});return[{label:`${t.marker} ${r}`,value:`${i} (${o})`,style:{label:"",value:""}}]}function lg(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=og({conf:e,params:l,max:i}).map(p=>`
|
|
128
|
+
`,textSerializers:l={}}=n||{};let c="",d=!0;return e.nodesBetween(r,i,(u,p,h,x)=>{var m;const j=l==null?void 0:l[u.type.name];j?(u.isBlock&&!d&&(c+=o,d=!0),h&&(c+=j({node:u,pos:p,parent:h,index:x,range:t}))):u.isText?(c+=(m=u==null?void 0:u.text)===null||m===void 0?void 0:m.slice(Math.max(r,p)-p,i-p),d=!1):u.isBlock&&!d&&(c+=o,d=!0)}),c}function ax(e){return Object.fromEntries(Object.entries(e.nodes).filter(([,t])=>t.spec.toText).map(([t,n])=>[t,n.spec.toText]))}He.create({name:"clipboardTextSerializer",addProseMirrorPlugins(){return[new Zt({key:new Ht("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(p=>p.$from.pos)),c=Math.max(...o.map(p=>p.$to.pos)),d=ax(n);return ix(r,{from:l,to:c},{textSerializers:d})}}})]}});const ox=()=>({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),lx=(e=!1)=>({commands:t})=>t.setContent("",e),cx=()=>({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,d)=>{if(c.type.isText)return;const{doc:u,mapping:p}=t,h=u.resolve(p.map(d)),x=u.resolve(p.map(d+c.nodeSize)),m=h.blockRange(x);if(!m)return;const j=Xh(m);if(c.type.isTextblock){const{defaultType:w}=h.parent.contentMatchAt(h.index());t.setNodeMarkup(m.start,w)}(j||j===0)&&t.lift(m,j)})}),!0},dx=e=>t=>e(t),ux=()=>({state:e,dispatch:t})=>ye.createParagraphNear(e,t),px=()=>({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),d=i.after(o);e.delete(c,d).scrollIntoView()}return!0}return!1},hx=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 d=o.before(l),u=o.after(l);t.delete(d,u).scrollIntoView()}return!0}return!1},xx=e=>({tr:t,dispatch:n})=>{const{from:r,to:i}=e;return n&&t.delete(r,i),!0},fx=()=>({state:e,dispatch:t})=>ye.deleteSelection(e,t),gx=()=>({commands:e})=>e.keyboardShortcut("Enter"),mx=()=>({state:e,dispatch:t})=>ye.exitCode(e,t);function Dn(e,t,n={strict:!0}){const r=Object.keys(t);return r.length?r.every(i=>n.strict?t[i]===e[i]:sx(t[i])?t[i].test(e[i]):t[i]===e[i]):!0}function Qs(e,t,n={}){return e.find(r=>r.type===t&&Dn(r.attrs,n))}function yx(e,t,n={}){return!!Qs(e,t,n)}function wa(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=Qs([...r.node.marks],t,n);if(!i)return;let o=r.index,l=e.start()+r.offset,c=o+1,d=l+r.node.nodeSize;for(Qs([...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&&yx([...e.parent.child(c).marks],t,n);)d+=e.parent.child(c).nodeSize,c+=1;return{from:l,to:d}}function ht(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 bx=(e,t={})=>({tr:n,state:r,dispatch:i})=>{const o=ht(e,r.schema),{doc:l,selection:c}=n,{$from:d,from:u,to:p}=c;if(i){const h=wa(d,o,t);if(h&&h.from<=u&&h.to>=p){const x=fe.create(l,h.from,h.to);n.setSelection(x)}}return!0},jx=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 Ca(e){return e instanceof fe}function wt(e=0,t=0,n=0){return Math.min(Math.max(e,t),n)}function vx(e,t=null){if(!t)return null;const n=se.atStart(e),r=se.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,wt(0,i,o),wt(e.content.size,i,o)):fe.create(e,wt(t,i,o),wt(t,i,o))}function Us(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}const wx=(e=null,t={})=>({editor:n,view:r,tr:i,dispatch:o})=>{t={scrollIntoView:!0,...t};const l=()=>{Us()&&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&&!Ca(n.state.selection))return l(),!0;const c=vx(i.doc,e)||n.state.selection,d=n.state.selection.eq(c);return o&&(d||i.setSelection(c),d&&i.storedMarks&&i.setStoredMarks(i.storedMarks),l()),!0},Cx=(e,t)=>n=>e.every((r,i)=>t(r,{...n,index:i})),Sx=(e,t)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},e,t);function Sa(e){const t=`<body>${e}</body>`;return new window.DOMParser().parseFromString(t,"text/html").body}function In(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),In("",t,n)}if(typeof e=="string"){const r=jn.fromSchema(t);return n.slice?r.parseSlice(Sa(e),n.parseOptions).content:r.parse(Sa(e),n.parseOptions)}return In("",t,n)}function _x(e,t,n){const r=e.steps.length-1;if(r<t)return;const i=e.steps[r];if(!(i instanceof Ze||i instanceof vt))return;const o=e.mapping.maps[r];let l=0;o.forEach((c,d,u,p)=>{l===0&&(l=p)}),e.setSelection(se.near(e.doc.resolve(l),n))}const kx=e=>e.toString().startsWith("<"),Tx=(e,t,n)=>({tr:r,dispatch:i,editor:o})=>{if(i){n={parseOptions:{},updateSelection:!0,...n};const l=In(t,o.schema,{parseOptions:{preserveWhitespace:"full",...n.parseOptions}});if(l.toString()==="<>")return!0;let{from:c,to:d}=typeof e=="number"?{from:e,to:e}:e,u=!0,p=!0;if((kx(l)?l:[l]).forEach(x=>{x.check(),u=u?x.isText&&x.marks.length===0:!1,p=p?x.isBlock:!1}),c===d&&p){const{parent:x}=r.doc.resolve(c);x.isTextblock&&!x.type.spec.code&&!x.childCount&&(c-=1,d+=1)}u?Array.isArray(t)?r.insertText(t.map(x=>x.text||"").join(""),c,d):typeof t=="object"&&t&&t.text?r.insertText(t.text,c,d):r.insertText(t,c,d):r.replaceWith(c,d,l),n.updateSelection&&_x(r,r.steps.length-1,-1)}return!0},Dx=()=>({state:e,dispatch:t})=>ye.joinUp(e,t),Ix=()=>({state:e,dispatch:t})=>ye.joinDown(e,t),Mx=()=>({state:e,dispatch:t})=>ye.joinBackward(e,t),Ax=()=>({state:e,dispatch:t})=>ye.joinForward(e,t);function _a(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function zx(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 d=t[c];if(/^(cmd|meta|m)$/i.test(d))l=!0;else if(/^a(lt)?$/i.test(d))r=!0;else if(/^(c|ctrl|control)$/i.test(d))i=!0;else if(/^s(hift)?$/i.test(d))o=!0;else if(/^mod$/i.test(d))Us()||_a()?l=!0:i=!0;else throw new Error(`Unrecognized modifier name: ${d}`)}return r&&(n=`Alt-${n}`),i&&(n=`Ctrl-${n}`),l&&(n=`Meta-${n}`),o&&(n=`Shift-${n}`),n}const Ex=e=>({editor:t,view:n,tr:r,dispatch:i})=>{const o=zx(e).split(/-(?!$)/),l=o.find(u=>!["Alt","Ctrl","Meta","Shift"].includes(u)),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}),d=t.captureTransaction(()=>{n.someProp("handleKeyDown",u=>u(n,c))});return d==null||d.steps.forEach(u=>{const p=u.map(r.mapping);p&&i&&r.maybeStep(p)}),!0};function Ys(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,(h,x)=>{if(h.isText)return;const m=Math.max(r,x),j=Math.min(i,x+h.nodeSize);c.push({node:h,from:m,to:j})});const d=i-r,u=c.filter(h=>l?l.name===h.node.type.name:!0).filter(h=>Dn(h.node.attrs,n,{strict:!1}));return o?!!u.length:u.reduce((h,x)=>h+x.to-x.from,0)>=d}const Px=(e,t={})=>({state:n,dispatch:r})=>{const i=ve(e,n.schema);return Ys(n,i,t)?ye.lift(n,r):!1},Lx=()=>({state:e,dispatch:t})=>ye.liftEmptyBlock(e,t),Ox=e=>({state:t,dispatch:n})=>{const r=ve(e,t.schema);return ss.liftListItem(r)(t,n)},Bx=()=>({state:e,dispatch:t})=>ye.newlineInCode(e,t);function ka(e,t){return t.nodes[e]?"node":t.marks[e]?"mark":null}function Ta(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 $x=(e,t)=>({tr:n,state:r,dispatch:i})=>{let o=null,l=null;const c=ka(typeof e=="string"?e:e.name,r.schema);return c?(c==="node"&&(o=ve(e,r.schema)),c==="mark"&&(l=ht(e,r.schema)),i&&n.selection.ranges.forEach(d=>{r.doc.nodesBetween(d.$from.pos,d.$to.pos,(u,p)=>{o&&o===u.type&&n.setNodeMarkup(p,void 0,Ta(u.attrs,t)),l&&u.marks.length&&u.marks.forEach(h=>{l===h.type&&n.addMark(p,p+u.nodeSize,l.create(Ta(h.attrs,t)))})})}),!0):!1},Vx=()=>({tr:e,dispatch:t})=>(t&&e.scrollIntoView(),!0),Nx=()=>({tr:e,commands:t})=>t.setTextSelection({from:0,to:e.doc.content.size}),qx=()=>({state:e,dispatch:t})=>ye.selectNodeBackward(e,t),Fx=()=>({state:e,dispatch:t})=>ye.selectNodeForward(e,t),Gx=()=>({state:e,dispatch:t})=>ye.selectParentNode(e,t),Wx=()=>({state:e,dispatch:t})=>ye.selectTextblockEnd(e,t),Rx=()=>({state:e,dispatch:t})=>ye.selectTextblockStart(e,t);function Qx(e,t,n={}){return In(e,t,{slice:!1,parseOptions:n})}const Ux=(e,t=!1,n={})=>({tr:r,editor:i,dispatch:o})=>{const{doc:l}=r,c=Qx(e,i.schema,n);return o&&r.replaceWith(0,l.content.size,c).setMeta("preventUpdate",!t),!0};function Yx(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 Kx(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 Ks(e){return t=>Kx(t.$from,e)}function Xx(e,t){const n=ht(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,d=>{l.push(...d.marks)});const c=l.find(d=>d.type.name===n.name);return c?{...c.attrs}:{}}function Mn(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 Jx(e,t,n={}){const{empty:r,ranges:i}=e.selection,o=t?ht(t,e.schema):null;if(r)return!!(e.storedMarks||e.selection.$from.marks()).filter(h=>o?o.name===h.type.name:!0).find(h=>Dn(h.attrs,n,{strict:!1}));let l=0;const c=[];if(i.forEach(({$from:h,$to:x})=>{const m=h.pos,j=x.pos;e.doc.nodesBetween(m,j,(w,T)=>{if(!w.isText&&!w.marks.length)return;const M=Math.max(m,T),P=Math.min(j,T+w.nodeSize),U=P-M;l+=U,c.push(...w.marks.map(re=>({mark:re,from:M,to:P})))})}),l===0)return!1;const d=c.filter(h=>o?o.name===h.mark.type.name:!0).filter(h=>Dn(h.mark.attrs,n,{strict:!1})).reduce((h,x)=>h+x.to-x.from,0),u=c.filter(h=>o?h.mark.type!==o&&h.mark.type.excludes(o):!0).reduce((h,x)=>h+x.to-x.from,0);return(d>0?d+u:d)>=l}function Da(e,t){const{nodeExtensions:n}=tx(t),r=n.find(l=>l.name===e);if(!r)return!1;const i={name:r.name,options:r.options,storage:r.storage},o=Pt(pt(r,"group",i));return typeof o!="string"?!1:o.split(" ").includes("list")}function Zx(e,t,n){var r;const{selection:i}=t;let o=null;if(Ca(i)&&(o=i.$cursor),o){const c=(r=e.storedMarks)!==null&&r!==void 0?r:o.marks();return!!n.isInSet(c)||!c.some(d=>d.type.excludes(n))}const{ranges:l}=i;return l.some(({$from:c,$to:d})=>{let u=c.depth===0?e.doc.inlineContent&&e.doc.type.allowsMarkType(n):!1;return e.doc.nodesBetween(c.pos,d.pos,(p,h,x)=>{if(u)return!1;if(p.isInline){const m=!x||x.type.allowsMarkType(n),j=!!n.isInSet(p.marks)||!p.marks.some(w=>w.type.excludes(n));u=m&&j}return!u}),u})}const Hx=(e,t={})=>({tr:n,state:r,dispatch:i})=>{const{selection:o}=n,{empty:l,ranges:c}=o,d=ht(e,r.schema);if(i)if(l){const u=Xx(r,d);n.addStoredMark(d.create({...u,...t}))}else c.forEach(u=>{const p=u.$from.pos,h=u.$to.pos;r.doc.nodesBetween(p,h,(x,m)=>{const j=Math.max(m,p),w=Math.min(m+x.nodeSize,h);x.marks.find(M=>M.type===d)?x.marks.forEach(M=>{d===M.type&&n.addMark(j,w,d.create({...M.attrs,...t}))}):n.addMark(j,w,d.create(t))})});return Zx(r,n,d)},ef=(e,t)=>({tr:n})=>(n.setMeta(e,t),!0),tf=(e,t={})=>({state:n,dispatch:r,chain:i})=>{const o=ve(e,n.schema);return o.isTextblock?i().command(({commands:l})=>ye.setBlockType(o,t)(n)?!0:l.clearNodes()).command(({state:l})=>ye.setBlockType(o,t)(l,r)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},nf=e=>({tr:t,dispatch:n})=>{if(n){const{doc:r}=t,i=wt(e,0,r.content.size),o=Pe.create(r,i);t.setSelection(o)}return!0},sf=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,d=wt(i,l,c),u=wt(o,l,c),p=fe.create(r,d,u);t.setSelection(p)}return!0},rf=e=>({state:t,dispatch:n})=>{const r=ve(e,t.schema);return ss.sinkListItem(r)(t,n)};function Ia(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 af=({keepMarks:e=!0}={})=>({tr:t,state:n,dispatch:r,editor:i})=>{const{selection:o,doc:l}=t,{$from:c,$to:d}=o,u=i.extensionManager.attributes,p=Mn(u,c.node().type.name,c.node().attrs);if(o instanceof Pe&&o.node.isBlock)return!c.parentOffset||!_n(l,c.pos)?!1:(r&&(e&&Ia(n,i.extensionManager.splittableMarks),t.split(c.pos).scrollIntoView()),!0);if(!c.parent.isBlock)return!1;if(r){const h=d.parentOffset===d.parent.content.size;o instanceof fe&&t.deleteSelection();const x=c.depth===0?void 0:Yx(c.node(-1).contentMatchAt(c.indexAfter(-1)));let m=h&&x?[{type:x,attrs:p}]:void 0,j=_n(t.doc,t.mapping.map(c.pos),1,m);if(!m&&!j&&_n(t.doc,t.mapping.map(c.pos),1,x?[{type:x}]:void 0)&&(j=!0,m=x?[{type:x,attrs:p}]:void 0),j&&(t.split(t.mapping.map(c.pos),1,m),x&&!h&&!c.parentOffset&&c.parent.type!==x)){const w=t.mapping.map(c.before()),T=t.doc.resolve(w);c.node(-1).canReplaceWith(T.index(),T.index()+1,x)&&t.setNodeMarkup(t.mapping.map(c.before()),x)}e&&Ia(n,i.extensionManager.splittableMarks),t.scrollIntoView()}return!0},of=e=>({tr:t,state:n,dispatch:r,editor:i})=>{var o;const l=ve(e,n.schema),{$from:c,$to:d}=n.selection,u=n.selection.node;if(u&&u.isBlock||c.depth<2||!c.sameParent(d))return!1;const p=c.node(-1);if(p.type!==l)return!1;const h=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 M=c.index(-1)?1:c.index(-2)?2:3;for(let pe=c.depth-M;pe>=c.depth-3;pe-=1)T=J.from(c.node(pe).copy(T));const P=c.indexAfter(-1)<c.node(-2).childCount?1:c.indexAfter(-2)<c.node(-3).childCount?2:3,U=Mn(h,c.node().type.name,c.node().attrs),re=((o=l.contentMatch.defaultType)===null||o===void 0?void 0:o.createAndFill(U))||void 0;T=T.append(J.from(l.createAndFill(null,re)||void 0));const Q=c.before(c.depth-(M-1));t.replace(Q,c.after(-P),new H(T,4-M,0));let ae=-1;t.doc.nodesBetween(Q,t.doc.content.size,(pe,ge)=>{if(ae>-1)return!1;pe.isTextblock&&pe.content.size===0&&(ae=ge+1)}),ae>-1&&t.setSelection(fe.near(t.doc.resolve(ae))),t.scrollIntoView()}return!0}const x=d.pos===c.end()?p.contentMatchAt(0).defaultType:null,m=Mn(h,p.type.name,p.attrs),j=Mn(h,c.node().type.name,c.node().attrs);t.delete(c.pos,d.pos);const w=x?[{type:l,attrs:m},{type:x,attrs:j}]:[{type:l,attrs:m}];if(!_n(t.doc,c.pos,2))return!1;if(r){const{selection:T,storedMarks:M}=n,{splittableMarks:P}=i.extensionManager,U=M||T.$to.parentOffset&&T.$from.marks();if(t.split(c.pos,2,w).scrollIntoView(),!U||!r)return!0;const re=U.filter(Q=>P.includes(Q.type.name));t.ensureMarks(re)}return!0},Xs=(e,t)=>{const n=Ks(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)&&ha(e.doc,n.pos)&&e.join(n.pos),!0},Js=(e,t)=>{const n=Ks(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)&&ha(e.doc,r)&&e.join(r),!0};var lf=Object.freeze({__proto__:null,blur:ox,clearContent:lx,clearNodes:cx,command:dx,createParagraphNear:ux,deleteCurrentNode:px,deleteNode:hx,deleteRange:xx,deleteSelection:fx,enter:gx,exitCode:mx,extendMarkRange:bx,first:jx,focus:wx,forEach:Cx,insertContent:Sx,insertContentAt:Tx,joinUp:Dx,joinDown:Ix,joinBackward:Mx,joinForward:Ax,keyboardShortcut:Ex,lift:Px,liftEmptyBlock:Lx,liftListItem:Ox,newlineInCode:Bx,resetAttributes:$x,scrollIntoView:Vx,selectAll:Nx,selectNodeBackward:qx,selectNodeForward:Fx,selectParentNode:Gx,selectTextblockEnd:Wx,selectTextblockStart:Rx,setContent:Ux,setMark:Hx,setMeta:ef,setNode:tf,setNodeSelection:nf,setTextSelection:sf,sinkListItem:rf,splitBlock:af,splitListItem:of,toggleList:(e,t,n,r={})=>({editor:i,tr:o,state:l,dispatch:c,chain:d,commands:u,can:p})=>{const{extensions:h,splittableMarks:x}=i.extensionManager,m=ve(e,l.schema),j=ve(t,l.schema),{selection:w,storedMarks:T}=l,{$from:M,$to:P}=w,U=M.blockRange(P),re=T||w.$to.parentOffset&&w.$from.marks();if(!U)return!1;const Q=Ks(ae=>Da(ae.type.name,h))(w);if(U.depth>=1&&Q&&U.depth-Q.depth<=1){if(Q.node.type===m)return u.liftListItem(j);if(Da(Q.node.type.name,h)&&m.validContent(Q.node.content)&&c)return d().command(()=>(o.setNodeMarkup(Q.pos,m),!0)).command(()=>Xs(o,m)).command(()=>Js(o,m)).run()}return!n||!re||!c?d().command(()=>p().wrapInList(m,r)?!0:u.clearNodes()).wrapInList(m,r).command(()=>Xs(o,m)).command(()=>Js(o,m)).run():d().command(()=>{const ae=p().wrapInList(m,r),pe=re.filter(ge=>x.includes(ge.type.name));return o.ensureMarks(pe),ae?!0:u.clearNodes()}).wrapInList(m,r).command(()=>Xs(o,m)).command(()=>Js(o,m)).run()},toggleMark:(e,t={},n={})=>({state:r,commands:i})=>{const{extendEmptyMarkRange:o=!1}=n,l=ht(e,r.schema);return Jx(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 Ys(r,o,n)?i.setNode(l):i.setNode(o,n)},toggleWrap:(e,t={})=>({state:n,commands:r})=>{const i=ve(e,n.schema);return Ys(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 d=c.steps.length-1;d>=0;d-=1)l.step(c.steps[d].invert(c.docs[d]));if(o.text){const d=l.doc.resolve(o.from).marks();l.replaceWith(o.from,o.to,e.schema.text(o.text,d))}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,d=ht(e,r.schema),{$from:u,empty:p,ranges:h}=c;if(!i)return!0;if(p&&l){let{from:x,to:m}=c;const j=(o=u.marks().find(T=>T.type===d))===null||o===void 0?void 0:o.attrs,w=wa(u,d,j);w&&(x=w.from,m=w.to),n.removeMark(x,m,d)}else h.forEach(x=>{n.removeMark(x.$from.pos,x.$to.pos,d)});return n.removeStoredMark(d),!0},updateAttributes:(e,t={})=>({tr:n,state:r,dispatch:i})=>{let o=null,l=null;const c=ka(typeof e=="string"?e:e.name,r.schema);return c?(c==="node"&&(o=ve(e,r.schema)),c==="mark"&&(l=ht(e,r.schema)),i&&n.selection.ranges.forEach(d=>{const u=d.$from.pos,p=d.$to.pos;r.doc.nodesBetween(u,p,(h,x)=>{o&&o===h.type&&n.setNodeMarkup(x,void 0,{...h.attrs,...t}),l&&h.marks.length&&h.marks.forEach(m=>{if(l===m.type){const j=Math.max(x,u),w=Math.min(x+h.nodeSize,p);n.addMark(j,w,l.create({...m.attrs,...t}))}})})}),!0):!1},wrapIn:(e,t={})=>({state:n,dispatch:r})=>{const i=ve(e,n.schema);return ye.wrapIn(i,t)(n,r)},wrapInList:(e,t={})=>({state:n,dispatch:r})=>{const i=ve(e,n.schema);return ss.wrapInList(i,t)(n,r)}});He.create({name:"commands",addCommands(){return{...lf}}}),He.create({name:"editable",addProseMirrorPlugins(){return[new Zt({key:new Ht("editable"),props:{editable:()=>this.editor.options.editable}})]}}),He.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:e}=this;return[new Zt({key:new Ht("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}}}})]}}),He.create({name:"keymap",addKeyboardShortcuts(){const e=()=>this.editor.commands.first(({commands:l})=>[()=>l.undoInputRule(),()=>l.command(({tr:c})=>{const{selection:d,doc:u}=c,{empty:p,$anchor:h}=d,{pos:x,parent:m}=h,j=se.atStart(u).from===x;return!p||!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 Us()||_a()?o:i},addProseMirrorPlugins(){return[new Zt({key:new Ht("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=se.atStart(t.doc).from,d=se.atEnd(t.doc).to;if(i||!(o===c&&l===d)||!(n.doc.textBetween(0,n.doc.content.size," "," ").length===0))return;const h=n.tr,x=ja({state:n,transaction:h}),{commands:m}=new ex({editor:this.editor,state:x});if(m.clearNodes(),!!h.steps.length)return h}})]}}),He.create({name:"tabindex",addProseMirrorPlugins(){return[new Zt({key:new Ht("tabindex"),props:{attributes:this.editor.isEditable?{tabindex:"0"}:{}}})]}});const Ma=He.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()}}}),cf=["8","10","12","14","16","18","20","24","30","36","48","60","72"].map(e=>`${e}px`),df=[{label:"auto",value:""}].concat(cf.map(e=>({label:e,value:e}))),uf={input:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important"}},pf=({editor:e})=>{const t=e.getAttributes("textStyle").fontSize;return s.jsx(q.RichTextEditor.ControlsGroup,{children:s.jsx(a.NativeSelect,{size:"xs",icon:s.jsx(k.IconTextSize,{stroke:1.5,size:16}),data:df,styles:uf,value:t||"",onChange:n=>{const r=n.currentTarget.value;r?e.chain().focus().setFontSize(r).run():e.chain().focus().unsetFontSize().run()}})})},An=({value:e,styles:t={},sx:n={}})=>{const r=pi.useEditor({extensions:[hi,ui,q.Link,ri,si,ti,oi.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),di,ci,li,ii.configure({types:["heading","paragraph"]}),ni.configure({placeholder:"This is placeholder"}),ai,ei.Color,Ma],content:e,editable:!1});f.useEffect(()=>{r==null||r.commands.setContent(e)},[e,r]);const i=f.useMemo(()=>y.defaultsDeep({},{content:Os},t),[t]);return s.jsx(q.RichTextEditor,{editor:r,styles:i,sx:n,children:s.jsx(q.RichTextEditor.Content,{})})};function hf(){const[e,{open:t,close:n}]=le.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(An,{value:ud,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(k.IconInfoCircle,{size:16}),children:"About parameter 'utils'"})]})}const xf=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return s.jsx(a.Box,{sx:{position:"relative",flexGrow:1},children:s.jsx(me,{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}}})})},en=f.forwardRef(({value:e,onChange:t,label:n,defaultValue:r},i)=>{const[o,l]=f.useState(e),c=()=>{t(o)},d=()=>{l(e)},u=()=>{l(r)};f.useEffect(()=>{l(e)},[e]);const p=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(hf,{})}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:u,size:"xs",variant:"default",leftIcon:s.jsx(k.IconPlayerSkipBack,{size:16}),children:"Reset to default"}),s.jsx(a.Button,{onClick:d,color:"red",size:"xs",disabled:!p,leftIcon:s.jsx(k.IconRecycle,{size:16}),children:"Revert Changes"}),s.jsx(a.Button,{size:"xs",onClick:c,disabled:!p,leftIcon:s.jsx(k.IconDeviceFloppy,{size:16}),children:"Confirm Changes"})]})]}),s.jsx(a.Text,{size:14,children:n}),s.jsx(xf,{value:o,onChange:l})]})}),ff=f.forwardRef(({value:e,onChange:t,label:n,triggerLabel:r="Edit",triggerButtonProps:i={},defaultValue:o},l)=>{const[c,{open:d,close:u}]=le.useDisclosure(!1);return s.jsxs(s.Fragment,{children:[s.jsx(a.Modal,{opened:c,onClose:u,title:"Authentication",withinPortal:!0,zIndex:320,size:"900px",children:s.jsx(a.Box,{h:600,children:s.jsx(en,{value:e,onChange:t,defaultValue:o,label:n})})}),s.jsx(a.Button,{onClick:d,...i,children:r})]})}),gf=[{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 mf({label:e,value:t,onChange:n,pt:r="sm",withFallback:i},o){f.useEffect(()=>{typeof t=="string"&&n({type:t,config:{},fallback:"0"})},[t,n]);const l=p=>{n(p==="quantile"?{type:"quantile",config:{p:.99},fallback:t.fallback}:p==="custom"?{type:"custom",config:{func:Wi},fallback:t.fallback}:{type:p,config:{},fallback:t.fallback})},c=p=>{n({type:"quantile",config:{p},fallback:t.fallback})},d=p=>{n({type:"custom",config:{func:p},fallback:t.fallback})},u=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:gf,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(ff,{label:"",triggerLabel:"Edit Function",value:t.config.func,onChange:d,defaultValue:Wi,triggerButtonProps:{size:"xs",sx:{flexGrow:0,alignSelf:"center",marginTop:"22px"},leftIcon:s.jsx(k.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:u})]})}const Zs=f.forwardRef(mf),yf=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function bf({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:yf,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 jf=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return s.jsx(a.Box,{children:s.jsx(me,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},vf=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:i}]=V.useBoolean(),[o,l]=f.useState(e),c=()=>{i();const{type:h,func_content:x}=o,m={type:h,func_content:x};l(m),t(m)},d=()=>{i(),l(e)},u=h=>{l(x=>({...x,func_content:h}))},p=()=>{u(Ls.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(jf,{value:o.func_content,onChange:u}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:p,color:"red",leftIcon:s.jsx(_.Recycle,{size:20}),children:"Reset"}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:d,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:c,children:"OK"})]})]})]})})]})},wf=({value:e,onChange:t})=>e.type!=="dynamic"?null:s.jsx(vf,{value:e,onChange:t}),Cf=({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})})},Sf=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Aa=f.forwardRef(({label:e="Size",value:t,onChange:n},r)=>{const i=o=>{n({...Ls[o]})};return s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(a.Select,{ref:r,label:e,data:Sf,value:t.type,onChange:i,sx:{flexGrow:1}}),s.jsx(Cf,{value:t,onChange:n}),s.jsx(wf,{value:t,onChange:n})]})}),_f=[{label:"off",value:"false"},{label:"start",value:"start"},{label:"middle",value:"middle"},{label:"end",value:"end"}],kf=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function Tf({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:kf,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:_f,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(Aa,{label:"Symbol Size",...i})})]})]})}function Df({control:e,index:t}){return s.jsx(b.Controller,{name:`series.${t}.symbolSize`,control:e,render:({field:n})=>s.jsx(Aa,{label:"Size",...n})})}const If=[{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 Mf({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,...d}})=>s.jsx(a.Select,{label:"Y Axis",data:i,disabled:i.length===0,...d,value:(l==null?void 0:l.toString())??"",onChange:u=>{if(!u){c(0);return}c(Number(u))},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(Zs,{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(B,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...l})})}),o==="line"&&s.jsx(Tf,{index:t,control:e,seriesItem:r}),o==="bar"&&s.jsx(bf,{index:t,control:e,seriesItem:r}),o==="scatter"&&s.jsx(Df,{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:If,...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(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Series"})]})}function Af({control:e,watch:t}){const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"series"}),o=t("series"),l=n.map((p,h)=>({...p,...o[h]})),c=()=>{const p={type:"bar",name:le.randomId(),showSymbol:!1,symbolSize:Ls.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(p)},d=t("y_axes"),u=f.useMemo(()=>d.map(({name:p},h)=>({label:p,value:h.toString()})),[d]);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((p,h)=>s.jsx(a.Tabs.Tab,{value:h.toString(),children:h+1},p.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),l.map((p,h)=>s.jsx(a.Tabs.Panel,{value:h.toString(),children:s.jsx(Mf,{control:e,index:h,remove:i,seriesItem:p,yAxisOptions:u},p.id)},p.id))]})}function zf({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(Qt,{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(Qt,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const Ef=()=>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"]})})]})]}),Pf=[{label:"Value",value:"value"},{label:"Category",value:"category"},{label:"Time",value:"time"},{label:"Log",value:"log"}];function Lf({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(Ef,{}),required:!0,data:Pf,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(mn,{...n})})]}),s.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>s.jsx(Je,{...n})})]})}const Of=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],Bf=[{label:"left",value:"left"},{label:"right",value:"right"}];function $f({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:Of,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:Bf,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(Oe,{...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(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this YAxis"})]})}function Vf({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((d,u)=>({...d,...o[u]})),c=()=>r({name:"",position:"left",nameAlignment:"left",label_formatter:be,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((d,u)=>s.jsx(a.Tabs.Tab,{value:u.toString(),children:u+1},d.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),l.map((d,u)=>s.jsx(a.Tabs.Panel,{value:u.toString(),children:s.jsx($f,{control:e,index:u,remove:i})},d.id))]})}function Nf({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),{variables:r}=e,i=f.useMemo(()=>y.defaultsDeep({},t,As),[t]),{control:o,handleSubmit:l,watch:c,getValues:d,reset:u}=b.useForm({defaultValues:i});f.useEffect(()=>{u(i)},[i]);const p=d(),h=f.useMemo(()=>!y.isEqual(p,i),[p,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:!h,children:s.jsx(_.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:"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(Lf,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Y Axes",children:s.jsx(Vf,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Series",children:s.jsx(Af,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Regression Lines",children:s.jsx(Vh,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Stats",children:s.jsx(zf,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Reference Lines",children:s.jsx(Lh,{variables:r,control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Reference Areas",children:s.jsx(Ah,{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(Ps,{...x})})})]})]})})}function qf(e){const t=y.cloneDeep(y.omit(e,"variables"));return t.stats=y.omit(t.stats,"variables"),t}function Ff(e){const{rotate:t,formatter:n=Be}=e.x_axis.axisLabel;return{...e,x_axis:{...e.x_axis,axisLabel:{rotate:t,formatter:n}}}}function Gf(e){const{dataZoom:t=zt,...n}=e;return{...n,dataZoom:t}}function Wf(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 Rf(e){const t=e.reference_lines.map(n=>{const{lineStyle:r={type:"dashed",width:1,color:nt.random().css()},show_in_legend:i=!1}=n;return{...n,lineStyle:r,show_in_legend:i}});return{...e,reference_lines:t}}function Qf(e){const t=e.reference_lines.map(n=>{const{yAxisIndex:r=0}=n;return{...n,yAxisIndex:r}});return{...e,reference_lines:t}}function Uf(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 Yf(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 Kf(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 Xf(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 Jf(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 Zf(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(r=>{const{nameAlignment:i="left"}=r;return{...r,nameAlignment:i}})}}function Hf(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(r=>{const{show:i=!0}=r;return{...r,show:i}})}}function eg(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 tg(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 ng(e){const{type:t="category",...n}=e.x_axis;return{...e,x_axis:{...n,type:t}}}function sg(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_data_key:i,series:o,regressions:l,...c}=e;return{...c,x_axis_data_key:r(i),series:o.map(d=>({...d,y_axis_data_key:r(d.y_axis_data_key),group_by_key:r(d.group_by_key)})),regressions:l.map(d=>({...d,y_axis_data_key:r(d.y_axis_data_key),group_by_key:r(d.group_by_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class rg extends ie{constructor(){super(...arguments);E(this,"VERSION",18)}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(d=>d.name===c.name)||r.addVariable(c)}),(y.get(i,"stats.variables")||[]).forEach(c=>{r.variables.find(d=>d.name===c.name)||r.addVariable(c)}),{...n,version:2,config:qf(i)}}),this.version(3,n=>({...n,version:3,config:Ff(n.config)})),this.version(4,n=>({...n,version:4,config:Gf(n.config)})),this.version(5,n=>({...n,version:5,config:Wf(n.config)})),this.version(6,n=>({...n,version:6,config:Rf(n.config)})),this.version(7,n=>({...n,version:7,config:Qf(n.config)})),this.version(8,n=>({...n,version:8,config:Uf(n.config)})),this.version(9,n=>({...n,version:9,config:Yf(n.config)})),this.version(10,n=>({...n,version:10,config:Kf(n.config)})),this.version(11,n=>({...n,version:11,config:Xf(n.config)})),this.version(12,n=>({...n,version:12,config:Jf(n.config)})),this.version(13,n=>({...n,version:13,config:Zf(n.config)})),this.version(14,n=>({...n,version:14,config:Hf(n.config)})),this.version(15,n=>({...n,version:15,config:eg(n.config)})),this.version(16,n=>({...n,version:16,config:tg(n.config)})),this.version(17,n=>({...n,version:17,config:ng(n.config)})),this.version(18,(n,r)=>({...n,version:18,config:sg(n.config,r)}))}}const ig={displayName:"Cartesian Chart",displayGroup:"ECharts-based charts",migrator:new rg,name:"cartesian",viewRender:Th,configRender:Nf,createConfig(){return{version:18,config:y.cloneDeep(As)}},triggers:[Ms]};function ag(e){if(e.enable_value)return e.value}function og(e){if(e.enable_value)return e.value}function lg(e){const t=e.axisLabel.overflow.on_axis.width,n=e.axisLabel.position,r={top:5,left:5,right:5,bottom:5};return e.orient==="vertical"&&y.get(r,n)&&n===e.funnelAlign&&y.set(r,n,t),r}function cg(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:d,orient:u,...p}=n;if(!r||!i)return{};const h=A(r),x=A(i),m=t[h.queryID].map(w=>({name:w[h.columnKey],value:w[x.columnKey]})),j=Ue(o.overflow.on_axis);return{type:"funnel",...lg(n),min:ag(l),max:og(c),minSize:l.size,maxSize:c.size,...p,label:{show:!0,position:o.position,...j},orient:u,funnelAlign:u==="horizontal"?"center":d,data:m}})}function dg({conf:e,params:t,max:n}){const{name:r,value:i}=t.data,o=F(i/n).format({output:"percent",mantissa:2,trimMantissa:!0});return[{label:`${t.marker} ${r}`,value:`${i} (${o})`,style:{label:"",value:""}}]}function ug(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 d=dg({conf:e,params:l,max:i}).map(p=>`
|
|
129
129
|
<tr>
|
|
130
130
|
<th style="text-align: right;">
|
|
131
131
|
<div style="${p.style.label}">${p.label}</div>
|
|
@@ -139,9 +139,9 @@ Check the top-level render call using <`+z+">.")}return D}}function dc(v,D){{if(
|
|
|
139
139
|
${l.seriesName}
|
|
140
140
|
</div>
|
|
141
141
|
<table style="width: auto">
|
|
142
|
-
<tbody>${
|
|
142
|
+
<tbody>${d.join("")}</tbody>
|
|
143
143
|
</table>
|
|
144
|
-
`}}function
|
|
144
|
+
`}}function pg(e,t){return ne.getTooltip({trigger:"item",formatter:ug(e,t)})}function hg(e,t){return{grid:{top:0,left:0,right:0,bottom:0},tooltip:pg(e,t),series:cg(e,t)}}function xg(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:ze},sort:"descending",orient:"vertical",funnelAlign:"center"}}const Hs={series:[xg("Funnel")]};Y.use([te.FunnelChart,O.DataZoomComponent,O.GridComponent,O.LegendComponent,O.TooltipComponent,Ce.CanvasRenderer]);function fg({conf:e,data:t,width:n,height:r}){const i=f.useMemo(()=>hg(e,t),[e,t]);return s.jsx(we,{echarts:Y,option:i,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})}function gg({context:e}){const{value:t}=$(e.instanceData,"config"),n=f.useMemo(()=>y.defaults({},t,Hs),[t]),r=e.data,{width:i,height:o}=e.viewport;return!i||!o?null:s.jsx(De,{width:i,height:o,children:s.jsx(fg,{width:We(i),height:Re(o),data:r,conf:n})})}const mg=[{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"}],er=f.forwardRef(({label:e,value:t,onChange:n,options:r=mg},i)=>s.jsx(a.Select,{ref:i,label:e,data:r,value:t,onChange:n})),yg=[{label:"Ascending",value:"ascending"},{label:"Descending",value:"descending"},{label:"Use original data order",value:"0"}],bg=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],jg=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}],vg={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"}]},wg=({item:e,control:t,index:n,remove:r})=>{const i=e.min.enable_value,o=e.max.enable_value,{orient:l}=e;return s.jsxs(a.Stack,{children:[s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:`series.${n}.name`,control:t,render:({field:c})=>s.jsx(a.TextInput,{label:"Series Name",...c})})}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${n}.level_name_data_key`,control:t,render:({field:c})=>s.jsx(B,{label:"Level Name Field",...c})}),s.jsx(b.Controller,{name:`series.${n}.level_value_data_key`,control:t,render:({field:c})=>s.jsx(B,{label:"Level Value Field",...c})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Funnel Style",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${n}.min.value`,control:t,render:({field:c})=>s.jsx(a.NumberInput,{disabled:!i,labelProps:{display:"block"},label:s.jsxs(a.Group,{position:"apart",pr:6,sx:{width:"100%"},children:[s.jsx(a.Text,{children:"Min Value"}),s.jsx(a.Tooltip,{label:"Check to enable specific min value",children:s.jsx(a.Box,{children:s.jsx(b.Controller,{name:`series.${n}.min.enable_value`,control:t,render:({field:d})=>s.jsx(a.Checkbox,{size:"xs",checked:d.value,onChange:u=>d.onChange(u.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:d})=>s.jsx(a.Checkbox,{size:"xs",checked:d.value,onChange:u=>d.onChange(u.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:jg,...c})}),s.jsx(b.Controller,{name:`series.${n}.sort`,control:t,render:({field:c})=>s.jsx(a.Select,{label:"Sort",data:yg,...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:bg,...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(er,{label:"Position",options:vg[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(Je,{...c})})})]})},Cg=({control:e,watch:t})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"series"}),o=t("series"),l=n.map((p,h)=>({...p,...o[h]})),c=y.get(l,"0.id"),[d,u]=f.useState(c??null);return f.useEffect(()=>{c&&u(p=>p!==null?p:c)},[c]),s.jsxs(a.Tabs,{value:d,onTabChange:p=>u(p),styles:{panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((p,h)=>s.jsx(a.Tabs.Tab,{value:p.id,children:p.name},p.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((p,h)=>s.jsx(a.Tabs.Panel,{value:p.id,children:s.jsx(wg,{item:p,control:e,index:h,remove:i})},p.id))]})};function Sg({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},t,Hs),[t]),{control:i,handleSubmit:o,watch:l,getValues:c,reset:d}=b.useForm({defaultValues:r});f.useEffect(()=>{d(r)},[r]),l([]);const u=c(),p=f.useMemo(()=>!y.isEqual(u,r),[u,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:!p,children:s.jsx(_.DeviceFloppy,{size:20})})]}),s.jsx(Cg,{control:i,watch:l})]})})}function _g(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 kg(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 Tg extends ie{constructor(){super(...arguments);E(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:_g(r)}}),this.version(3,(n,r)=>{const{config:i}=n;return{...n,version:3,config:kg(i,r)}})}}const Dg={displayName:"Funnel Chart",displayGroup:"ECharts-based charts",migrator:new Tg,name:"funnel",viewRender:gg,configRender:Sg,createConfig:()=>({version:3,config:Hs})};function za({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 Ig(e){const t=za(e.x_axis.axisLabel.formatter),n=za(e.y_axis.axisLabel.formatter);return{x_axis:t,y_axis:n}}function Mg(e){return{heat_block:function(r){if(!e.heat_block.value_formatter)return r;try{return F(r).format(e.heat_block.value_formatter)}catch(i){return console.error(i),r}}}}function Ag(e){let t=0;return e.x_axis.name&&(t+=20),{top:45,left:5,right:5,bottom:t,containLabel:!0}}function zg(e,t,n){const{heat_block:r}=e;return{type:"heatmap",name:r.name,xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{borderColor:"white",borderWidth:n},data:t,label:r.label,labelLayout:{hideOverlap:!0}}}const Eg=e=>{try{return F(e).format({trimMantissa:!0,mantissa:2})}catch{return e}};function Pg({conf:e,labelFormatters:t,valueFormatters:n,dataDict:r,params:i}){const{value:o,dataIndex:l}=i,[c,d,u]=o,p={label:e.x_axis.name?e.x_axis.name:"X Axis",value:t.x_axis(c,l),style:{label:"",value:Qe(e.x_axis.axisLabel.overflow.in_tooltip)}},h={label:e.y_axis.name?e.y_axis.name:"Y Axis",value:t.y_axis(d,l),style:{label:"",value:Qe(e.y_axis.axisLabel.overflow.in_tooltip)}},x={label:e.heat_block.name,value:n.heat_block(u),style:{label:"",value:""}},m=[p,h,x],j=r[`${c}---${d}`];return j&&e.tooltip.metrics.forEach(w=>{const T=A(w.data_key);m.push({label:w.name,value:Eg(y.get(j,T.columnKey,"")),style:{label:"",value:""}})}),m}function Lg(e,t,n,r){const{x_axis:i,y_axis:o,heat_block:l}=e,c=A(i.data_key),d=A(o.data_key);A(l.data_key);const u=y.keyBy(t[c.queryID],p=>`${p[c.columnKey]}---${p[d.columnKey]}`);return ne.getTooltip({formatter:function(p){const x=Pg({conf:e,labelFormatters:n,valueFormatters:r,dataDict:u,params:p}).map(j=>`
|
|
145
145
|
<tr>
|
|
146
146
|
<th style="text-align: right;">
|
|
147
147
|
<div style="${j.style.label}">${j.label}</div>
|
|
@@ -162,11 +162,11 @@ Check the top-level render call using <`+z+">.")}return D}}function dc(v,D){{if(
|
|
|
162
162
|
</thead>
|
|
163
163
|
<tbody>${x.join("")}</tbody>
|
|
164
164
|
</table>
|
|
165
|
-
`}}}const
|
|
166
|
-
`)}},
|
|
167
|
-
`)},
|
|
165
|
+
`}})}const Og=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return s.jsx(a.Box,{children:s.jsx(me,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Ea={static:{type:"static",value:10},dynamic:{type:"dynamic",value:["function getValue({ variables }, { lodash, interpolate }) {"," // your code goes here"," return 100;","}"].join(`
|
|
166
|
+
`)}},Bg=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:i}]=V.useBoolean(),[o,l]=f.useState(e),c=()=>{i();const{type:h,value:x}=o,m={type:h,value:x};l(m),t(m)},d=()=>{i(),l(e)},u=h=>{l(x=>({...x,value:h}))},p=()=>{u(Ea.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(Og,{value:o.value,onChange:u}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:p,color:"red",leftIcon:s.jsx(_.Recycle,{size:20}),children:"Reset"}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:d,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:c,children:"OK"})]})]})]})})]})},$g=({value:e,onChange:t})=>e.type!=="dynamic"?null:s.jsx(Bg,{value:e,onChange:t}),Vg=({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})},Ng=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Lt=f.forwardRef(({label:e="Value",value:t,onChange:n},r)=>{const i=o=>{n({...Ea[o]})};return s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(a.Select,{ref:r,label:e,data:Ng,value:t.type,onChange:i,sx:{flexGrow:1}}),s.jsx(Vg,{value:t,onChange:n}),s.jsx($g,{value:t,onChange:n})]})});function Ot(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:ft.interpolate})}catch(i){return console.error(`[getNumberOrDynamicValue] failed parsing custom function, error: ${i.message}`),10}}function qg(e,t){const n=Ot(e.heat_block.min,t),r=Ot(e.heat_block.max,t);return{min:n,max:r,calculable:!0,orient:"horizontal",left:"center",top:0,itemWidth:15}}function Fg(e,t,n){const{overflow:r,rotate:i}=e.x_axis.axisLabel,o=Ue(r.on_axis);return{id:"main-x-axis",type:"category",data:t,name:e.x_axis.name??"",align:"center",axisTick:{show:!0,alignWithLabel:!0},axisLabel:{rotate:i,...o,formatter:n},splitArea:{show:!0},nameLocation:"center",nameGap:25,nameTextStyle:{fontWeight:"bold",align:"center"},z:2}}function Gg(e,t,n){const{nameAlignment:r,data_key:i,...o}=e.y_axis,{overflow:l,rotate:c}=e.y_axis.axisLabel,d=Ue(l.on_axis);return{...o,type:"category",data:t,axisLabel:{rotate:c,...d,formatter:n},axisLine:{show:!0,color:"blue"},axisTick:{show:!0,alignWithLabel:!0},splitArea:{show:!0},nameTextStyle:{fontWeight:"bold",align:r},nameLocation:"end",nameGap:15,z:2}}function Wg(e,t,n,r){return n<e*10||r<t*10?0:n<e*20||r<t*20?1:2}function Rg(e,t,n,r,i){if(!e.x_axis.data_key||!e.y_axis.data_key||!e.heat_block.data_key)return{};const o=n.reduce((T,M)=>{const P=it(M,t);return T[M.name]=Ne(M,P),T},{}),l=Ig(e),c=Mg(e),d=A(e.x_axis.data_key),u=A(e.y_axis.data_key),p=A(e.heat_block.data_key),h=y.uniq(t[d.queryID].map(T=>T[d.columnKey])),x=y.uniq(t[d.queryID].map(T=>T[u.columnKey])),m=t[d.queryID].map(T=>[y.get(T,d.columnKey),y.get(T,u.columnKey),y.get(T,p.columnKey)]),j=Wg(h.length,x.length,r,i);return{xAxis:Fg(e,h,l.x_axis),yAxis:Gg(e,x,l.y_axis),series:zg(e,m,j),tooltip:Lg(e,t,l,c),grid:Ag(e),visualMap:qg(e,o)}}function Qg(e){return s.jsx(s.Fragment,{})}function Ug(e){return s.jsx(a.Text,{children:"Click heat block"})}const Pa={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:Ug,configRender:Qg,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"}]},tr={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,overflow:ze,formatter:{...Be}}},y_axis:{name:"Y Axis",data_key:"",nameAlignment:"center",axisLabel:{rotate:0,overflow:ze,formatter:{...Be}}},heat_block:{min:{type:"static",value:0},max:{type:"static",value:100},name:"Value",data_key:"",value_formatter:be,label:{show:!1,fontSize:10}},tooltip:{metrics:[]}};Y.use([O.DataZoomComponent,te.HeatmapChart,O.GridComponent,O.LegendComponent,O.TooltipComponent,O.VisualMapComponent,Ce.CanvasRenderer]);function Yg({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const l=f.useMemo(()=>{const h=A(e.x_axis.data_key),x=A(e.y_axis.data_key);return y.keyBy(t[h.queryID],m=>`${m[h.columnKey]}---${m[x.columnKey]}`)},[t,e.x_axis.data_key,e.y_axis.data_key]),c=$e(i.triggerManager,Pa.id),d=f.useCallback(h=>{const[x,m]=h.value,j=y.get(l,`${x}---${m}`,{error:"rowData is not found"});c.forEach(w=>{i.runInteraction(w.id,{...h,rowData:j})})},[l,c,i]),u=f.useMemo(()=>({click:d}),[d]),p=f.useMemo(()=>Rg(e,t,o,n,r),[e,t,n,r]);return s.jsx(we,{echarts:Y,option:p,style:{width:n,height:r},onEvents:u,notMerge:!0,theme:"merico-light"})}function Kg({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,tr),[r]),l=e.data,{width:c,height:d}=e.viewport;return!c||!d?null:s.jsx(De,{width:c,height:d,children:s.jsx(Yg,{variables:i,width:We(c),height:Re(d),data:l,conf:o,interactionManager:n})})}function Xg({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(Lt,{label:"Min Value",...r})}),s.jsx(b.Controller,{name:"heat_block.max",control:e,render:({field:r})=>s.jsx(Lt,{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(Oe,{...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 Jg=({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(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),Zg=({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((h,x)=>({...h,...o[x]})),c=()=>r({id:Date.now().toString(),data_key:"",name:""}),d=t("tooltip.metrics.0.id"),[u,p]=f.useState(()=>d??null);return f.useEffect(()=>{d&&p(h=>h!==null?h:d)},[d]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(_.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:u,onTabChange:h=>p(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((h,x)=>s.jsx(a.Tabs.Tab,{value:h.id,children:h.name?h.name:x},h.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),l.map((h,x)=>s.jsx(a.Tabs.Panel,{value:h.id,children:s.jsx(Jg,{control:e,index:x,remove:i},h.id)},h.id))]})]})};function Hg({control:e,watch:t}){return s.jsx(Zg,{control:e,watch:t})}const em=({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(me,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},tm={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
167
|
+
`)},La=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 d=m=>{c({...l,enabled:m})},u=()=>{o();const{enabled:m,func_content:j}=l,w={enabled:m,func_content:j};c(w),t(w)},p=()=>{o(),c(e)},h=m=>{c(j=>({...j,func_content:m}))},x=()=>{h(tm.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=>d(m.currentTarget.checked)}),s.jsx(em,{value:l.func_content,onChange:h,disabled:!l.enabled}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:x,color:"red",leftIcon:s.jsx(_.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:u,children:"OK"})]})]})]})})]})});function nm({control:e,watch:t}){return t(["x_axis"]),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>s.jsx(B,{label:"Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"x_axis.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"Name",sx:{flex:1},...n})})]}),s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Tick Label",labelPosition:"center"}),s.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>s.jsx(Je,{...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(La,{...n})})]})]})}const sm=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function rm({control:e,watch:t}){return t(["y_axis"]),s.jsxs(a.Stack,{my:0,p:"0",sx:{position:"relative"},children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"y_axis.data_key",control:e,render:({field:n})=>s.jsx(B,{label:"Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"y_axis.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...n})})]}),s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:"y_axis.nameAlignment",control:e,render:({field:n})=>s.jsx(a.Select,{label:"Name Alignment",required:!0,data:sm,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(Je,{...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(La,{...n})})]})]})}function im({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},t,tr),[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:d,reset:u}=b.useForm({defaultValues:i});f.useEffect(()=>{u(i)},[i]);const p=d(),h=f.useMemo(()=>!y.isEqual(p,r),[p,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:!h,children:s.jsx(_.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(nm,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Y Axis",children:s.jsx(rm,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Heat Block",children:s.jsx(Xg,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(Hg,{control:o,watch:c})})]})]})})}function am(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,heat_block:l,tooltip:c,...d}=e;return{...d,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(u=>({...u,data_key:r(u.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}function om(e){return y.defaultsDeep({},e,{heat_block:{label:{show:!1,fontSize:10}}})}function lm(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 cm extends ie{constructor(){super(...arguments);E(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:am(n.config,r)})),this.version(3,n=>({...n,version:3,config:om(n.config)})),this.version(4,n=>({...n,version:4,config:lm(n.config)}))}}const dm={displayName:"Heatmap",displayGroup:"ECharts-based charts",migrator:new cm,name:"heatmap",viewRender:Kg,configRender:im,createConfig:()=>({version:4,config:tr}),triggers:[Pa]},Oa={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:pm,configRender:um,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 um(e){return s.jsx(s.Fragment,{})}function pm(e){return s.jsx(a.Text,{children:"Click chart's series"})}const Ba={label_template:"${percentage.x} of ${x_axis.name} causes ${percentage.y} of ${bar.name}",color:"#789AB4"},nr={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...Be},overflow:ze}},data_key:"value",bar:{name:"Value",nameAlignment:"left",color:"#228be6",label_formatter:be},line:{name:"Value",nameAlignment:"right",color:"red"},dataZoom:zt,markLine:Ba};function zn(e){return F(e).format({output:"percent",mantissa:0})}function hm(e){const t=e.value[1];try{return zn(t)}catch(n){return console.error(n),t}}function xm(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 F(r).format(e.bar.label_formatter)}catch(i){return console.error(i),r}}return{bar:t,line:hm,lineValue:zn}}function fm(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 gm(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:zn((n+1)/t.length),y:zn(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:fm(e,i,o)}}]},markArea:{name:"",silent:!0,itemStyle:{color:"rgba(47, 140, 192, 0.05)"},data:[[{type:"min"},{xAxis:l}]]}}:{}}function mm(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]),d=c.reduce((x,m)=>x+m[1],0),u=c.reduce((x,m,j)=>{const w=j===0?0:x[j-1][1];return x.push([m[0],w+m[1]]),x},[]).map(x=>[x[0],x[1]/d]),{markLine:p,markArea:h}=gm(e,u);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:u,markLine:p,markArea:h}]}const ym=(e,t)=>n=>{const r=Array.isArray(n)?n:[n];if(r.length===0)return"";const i=r.map((c,d)=>{const u=c.seriesName,[p,h]=c.value;if(!u)return h;const x=d===0?t.bar:t.lineValue;return`
|
|
168
168
|
<tr>
|
|
169
|
-
<th style="text-align: right; padding: 0 1em;">${
|
|
169
|
+
<th style="text-align: right; padding: 0 1em;">${u}</th>
|
|
170
170
|
<td style="text-align: left; padding: 0 1em;">${x(h)}</td>
|
|
171
171
|
</tr>
|
|
172
172
|
`}),o=Qe(e.x_axis.axisLabel.overflow.in_tooltip),l=r[0].name;return`
|
|
@@ -178,7 +178,7 @@ Check the top-level render call using <`+z+">.")}return D}}function dc(v,D){{if(
|
|
|
178
178
|
${i.join("")}
|
|
179
179
|
</tbody>
|
|
180
180
|
</table>
|
|
181
|
-
`};function
|
|
181
|
+
`};function bm(e,t){return ne.getTooltip({trigger:"axis",formatter:ym(e,t)})}function jm(e){const{name:t,axisLabel:n}=e.x_axis,r=Ue(n.overflow.on_axis);return[ne.getXAxis({type:"category",name:t,nameLocation:"middle",nameGap:30,nameTextStyle:{align:"right"},axisLabel:{...n,...r,formatter:Mt(n.formatter)}})]}function vm(e,t){return[ne.getYAxis({name:e.bar.name,nameGap:20,minInterval:1,nameTextStyle:{align:e.bar.nameAlignment},position:"left",axisLabel:{show:!0,formatter:t.bar},splitLine:{show:!1}}),ne.getYAxis({name:e.line.name,nameGap:20,nameTextStyle:{align:e.line.nameAlignment},position:"right",axisLabel:{show:!0,formatter:t.lineValue}})]}function wm(e,t,n){const r=xm(e);return{dataZoom:zs(e.dataZoom),tooltip:bm(e,r),xAxis:jm(e),yAxis:vm(e,r),series:mm(e,t,r),grid:{top:50,left:30,right:15,bottom:5,containLabel:!0}}}Y.use([te.BarChart,te.LineChart,O.DataZoomComponent,O.GridComponent,O.LegendComponent,O.TooltipComponent,Ce.CanvasRenderer]);function Cm({context:e,instance:t}){const{value:n}=$(e.instanceData,"config"),r=e.data,{width:i,height:o}=e.viewport,l=y.defaults({},n,nr),c=wm(l,r),d=Ve({vizManager:e.vizManager,instance:t}),u=$e(d.triggerManager,Oa.id),p=mt(r,l.x_axis.data_key),h=f.useCallback(m=>{const j=y.get(p,m.name,{error:"rowData is not found"});u.forEach(w=>{d.runInteraction(w.id,{...m,rowData:j})})},[p,u,d]),x=f.useMemo(()=>({click:h}),[h]);return!l||!i||!o?null:s.jsx(De,{width:i,height:o,children:s.jsx(we,{echarts:Y,option:c,style:Wt(i,o),onEvents:x,notMerge:!0,theme:"merico-light"})})}const Sm=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function _m({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:Sm,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(Oe,{...n})})]})]})}const km=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function Tm({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:km,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 Dm=`
|
|
182
182
|
{
|
|
183
183
|
// 80-20 line stuff
|
|
184
184
|
percentage: {
|
|
@@ -201,11 +201,11 @@ Check the top-level render call using <`+z+">.")}return D}}function dc(v,D){{if(
|
|
|
201
201
|
name: string;
|
|
202
202
|
};
|
|
203
203
|
}
|
|
204
|
-
`,
|
|
205
|
-
{percentage|{d}%}`,minMargin:5,edgeDistance:10,lineHeight:15,rich:{percentage:{color:"#999"}},margin:20},labelLine:{length:15,length2:0,maxSurfaceAngle:80,showAbove:!0},labelLayout:function(h){const x=h.labelRect.x<n/2,m=h.labelLinePoints;return y.set(m,[2,0],x?h.labelRect.x:h.labelRect.x+h.labelRect.width),{labelLinePoints:m}},data:
|
|
204
|
+
`,Im=()=>{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(ct.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:Dm})})]})};function Mm({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(Im,{})]})]})}function Am({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(mn,{...n})})]}),s.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>s.jsx(Je,{...n})})]})}function zm({control:e,watch:t}){return t(["data_key"]),s.jsx(a.Stack,{children:s.jsx(b.Controller,{name:"data_key",control:e,render:({field:n})=>s.jsx(B,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})})})}function Em({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaults({},t,nr),[t]),{control:i,handleSubmit:o,watch:l,getValues:c,reset:d}=b.useForm({defaultValues:r});f.useEffect(()=>{d(r)},[r]),l(["x_axis","data_key","bar","line","dataZoom"]);const u=c(),p=f.useMemo(()=>!y.isEqual(u,t),[u,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:!p,children:s.jsx(_.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(Am,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Y Axis",children:s.jsx(zm,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Bar",children:s.jsx(_m,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Line",children:s.jsx(Tm,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"80-20 Line",children:s.jsx(Mm,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Zooming",children:s.jsx(b.Controller,{name:"dataZoom",control:i,render:({field:h})=>s.jsx(Ps,{...h})})})]})]})}function Pm(e){const{dataZoom:t=zt,...n}=e;return{...n,dataZoom:t}}function Lm(e){const{markLine:t=Ba,...n}=e;return{...n,markLine:t}}function Om(e){const t=y.defaultsDeep({},e.x_axis.axisLabel,{rotate:0,formatter:{...Be}});return{...e,x_axis:{...e.x_axis,axisLabel:t}}}function Bm(e){const{label_formatter:t=be}=e.bar;return{...e,bar:{...e.bar,label_formatter:t}}}function $m(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 Vm(e){const t={bar:{nameAlignment:"left"},line:{nameAlignment:"right"}};return y.defaultsDeep(t,e)}function Nm(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 qm(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 Fm extends ie{constructor(){super(...arguments);E(this,"VERSION",9)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:Pm(n.config)})),this.version(3,n=>({...n,version:3,config:Lm(n.config)})),this.version(4,n=>({...n,version:4,config:Om(n.config)})),this.version(5,n=>({...n,version:5,config:Bm(n.config)})),this.version(6,n=>({...n,version:6,config:$m(n.config)})),this.version(7,n=>({...n,version:7,config:Vm(n.config)})),this.version(8,n=>({...n,version:8,config:Nm(n.config)})),this.version(9,(n,r)=>({...n,version:9,config:qm(n.config,r)}))}}const Gm={displayName:"Pareto Chart",displayGroup:"ECharts-based charts",migrator:new Fm,name:"paretoChart",viewRender:Cm,configRender:Em,createConfig(){return{version:9,config:y.cloneDeep(nr)}},triggers:[Oa]},sr={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 Wm(){Y.registerTheme("merico-light",{color:Object.values(sr.graphics.multiple),visualMap:{color:Object.values(sr.graphics.depth).reverse()},axes:[{type:"all",name:"通用坐标轴",axisLineColor:"#97999D",axisTickColor:"#97999D",axisLabelShow:!0,axisLabelColor:"#818388",splitLineShow:!0,splitLineColor:["#E0E6F1"]}]})}function $a(){Wm()}function*Rm(e){const t=sr.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 Qm(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),d=A(o),u=t[l.queryID].map(h=>({name:h[l.columnKey],value:Number(h[c.columnKey]),color:d.columnKey?h[d.columnKey]:void 0})),p=Rm("multiple");return{type:"pie",name:"pie",radius:["50%","80%"],itemStyle:{color:({data:h})=>h.color?h.color:p.next().value},label:{position:"outer",alignTo:"edge",formatter:`{name|{b}}
|
|
205
|
+
{percentage|{d}%}`,minMargin:5,edgeDistance:10,lineHeight:15,rich:{percentage:{color:"#999"}},margin:20},labelLine:{length:15,length2:0,maxSurfaceAngle:80,showAbove:!0},labelLayout:function(h){const x=h.labelRect.x<n/2,m=h.labelLinePoints;return y.set(m,[2,0],x?h.labelRect.x:h.labelRect.x+h.labelRect.width),{labelLinePoints:m}},data:u,top:10,bottom:10,left:10,right:10}}function Um(e,t,n){return{tooltip:ne.getTooltip({}),series:Qm(e,t,n)}}const Va={id:"builtin:echarts:click-pie-chart:series",displayName:"Click Pie Series",nameRender:Km,configRender:Ym,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 Ym(e){return s.jsx(s.Fragment,{})}function Km(e){return s.jsx(a.Text,{children:"Click chart's series"})}const rr={label_field:"",value_field:"",color_field:""};Y.use([te.PieChart,Ce.CanvasRenderer]);function Xm({conf:e,data:t,width:n,height:r,interactionManager:i}){const o=mt(t,e.label_field),l=$e(i.triggerManager,Va.id),c=f.useCallback(p=>{const h=y.get(o,p.name,{error:"rowData is not found"});l.forEach(x=>{i.runInteraction(x.id,{...p,rowData:h})})},[o,l,i]),d=f.useMemo(()=>Um(e,t,n),[e,t,n]),u=f.useMemo(()=>({click:c}),[c]);return!n||!r||!d.series.name?null:s.jsx(we,{echarts:Y,option:d,style:{width:n,height:r},onEvents:u,notMerge:!0,theme:"merico-light"})}function Jm({context:e,instance:t}){const n=Ve({vizManager:e.vizManager,instance:t}),{value:r}=$(e.instanceData,"config"),i=f.useMemo(()=>y.defaults({},r,rr),[r]),o=e.data,{width:l,height:c}=e.viewport;return!l||!c?null:s.jsx(De,{width:l,height:c,children:s.jsx(Xm,{conf:i,width:We(l),height:Re(c),data:o,interactionManager:n})})}function Zm({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},t,rr),[t]),i=f.useMemo(()=>y.clone(r),[r]),{control:o,handleSubmit:l,watch:c,getValues:d,reset:u}=b.useForm({defaultValues:i});f.useEffect(()=>{u(i)},[i]);const p=d(),h=f.useMemo(()=>!y.isEqual(p,r),[p,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:!h,children:s.jsx(_.DeviceFloppy,{size:20})})]}),s.jsxs(a.Stack,{mt:"md",spacing:"xs",p:"md",mb:"sm",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[s.jsx(b.Controller,{control:o,name:"label_field",render:({field:x})=>s.jsx(B,{label:"Label Key",required:!0,...x})}),s.jsx(b.Controller,{control:o,name:"value_field",render:({field:x})=>s.jsx(B,{label:"Value Key",required:!0,...x})}),s.jsx(b.Controller,{control:o,name:"color_field",render:({field:x})=>s.jsx(B,{label:"Color Key",clearable:!0,...x})})]})]})})}function Hm(e){const{color_field:t="",...n}=e;return{...n,color_field:t}}function ey(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 ty extends ie{constructor(){super(...arguments);E(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:Hm(n.config)})),this.version(3,(n,r)=>({...n,version:3,config:ey(n.config,r)}))}}const ny={displayName:"Pie Chart",displayGroup:"ECharts-based charts",migrator:new ty,name:"pie",viewRender:Jm,configRender:Zm,createConfig(){return{version:3,config:y.cloneDeep(rr)}},triggers:[Va]};function sy(e){return s.jsx(s.Fragment,{})}function ry(e){return s.jsx(a.Text,{children:"Click heat block"})}const Na={id:"builtin:echarts:click-radar-chart:series",displayName:"Click radar chart series",nameRender:ry,configRender:sy,payload:[{name:"seriesType",description:"'radar'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]},En={series_name_key:"",additional_series:[],background:{enabled:!0},label:{enabled:!0},dimensions:[]};function qa(e){return e?t=>{try{return F(t).format(e)}catch(n){return console.error(n),t}}:t=>t}function Fa(e){return{show:e.label.enabled,formatter:({dimensionIndex:t,value:n})=>qa(e.dimensions[t].formatter)(n)}}function Ga(e,t){return t.map(({data_key:n})=>{const r=A(n);return e[r.columnKey]})}function iy(e,t,n){const r=A(t);return e[r.queryID].map(i=>({value:Ga(i,n),name:i[r.columnKey]}))}function ay(e,t){const{series_name_key:n,dimensions:r}=t;return[{type:"radar",name:"main-radar",data:iy(e,n,r),symbolSize:4,lineStyle:{width:1},emphasis:{lineStyle:{width:4}},areaStyle:t.background.enabled?{opacity:.4}:void 0,label:Fa(t)}]}function oy(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(p=>{const h=p[l.columnKey],x=p[c.columnKey];return{name:h,value:Ga(p,r),itemStyle:{color:x}}}),symbolSize:4,lineStyle:{width:1},emphasis:{lineStyle:{width:4}},areaStyle:t.background.enabled?{opacity:.4}:void 0,label:Fa(t)}}).flat()}function ly(e,t){return[...ay(e,t),...oy(e,t)]}function cy(e){return({name:t,marker:n,value:r})=>{if(r.length===0)return"";const i=r.map((o,l)=>{const c=e.dimensions[l],d=qa(c.formatter);return`
|
|
206
206
|
<tr>
|
|
207
207
|
<td style="padding-left: 18px;">${c.name}</td>
|
|
208
|
-
<td style="text-align: right; "><strong>${
|
|
208
|
+
<td style="text-align: right; "><strong>${d(o)}</strong></td>
|
|
209
209
|
</tr>
|
|
210
210
|
`});return`
|
|
211
211
|
<table>
|
|
@@ -230,7 +230,7 @@ Check the top-level render call using <`+z+">.")}return D}}function dc(v,D){{if(
|
|
|
230
230
|
${i.join("")}
|
|
231
231
|
</tbody>
|
|
232
232
|
</table>
|
|
233
|
-
`}}const ly={legend:{show:!0,bottom:0,left:0},tooltip:{trigger:"item"}},cy=["#66B4DB","#39BFA2","#E46464","#33A678","#EEBA00","#9D88CB","#939943","#E49792","#09A2B8","#AF5F6B","#6CA157","#09A2B8","#6398C7","#E692BA","#97B566","#8CACE2","#CA79AC","#6DBC80","#B08F4B","#826BAF"];function uy(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:{confine:!0,backgroundColor:"rgba(255,255,255,0.6)",formatter:oy(e)},legend:{show:!0,bottom:0,left:"center",type:"scroll"},series:ay(t,e),color:cy};return y.merge({},ly,l)}Y.use([te.RadarChart,O.GridComponent,O.LegendComponent,O.TooltipComponent,we.CanvasRenderer]);function dy({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const l=f.useMemo(()=>{const{queryID:h,columnKey:x}=A(e.series_name_key),m=y.keyBy(t[h],x),j=e.additional_series.reduce((w,T)=>{const M=A(T.name_key),P=y.keyBy(t[M.queryID],M.columnKey);return{...w,...P}},m);return{...m,...j}},[t,e.series_name_key,e.additional_series]),c=$e(i.triggerManager,Va.id),u=f.useCallback(h=>{const x=y.get(l,h.name,{error:"rowData is not found"});c.forEach(m=>{i.runInteraction(m.id,{...h,rowData:x})})},[l,c,i]),d=f.useMemo(()=>({click:u}),[u]),p=f.useMemo(()=>uy(y.defaultsDeep({},e,En),t),[e,t]);return!n||!r?null:s.jsx(ve,{echarts:Y,option:p,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function py({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,En),[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(dy,{variables:i,width:We(c),height:Re(u),data:l,conf:o,interactionManager:n})})}function hy({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(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),children:"Delete"})]})}function xy({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,p]=f.useState(u);f.useEffect(()=>{p(x=>x||u)},[u]);const h=x=>{i(x);const m=y.get(l,"0.id",null);p(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:p,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(hy,{control:e,index:m,remove:h})},x.id))]})]})}function fy({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(Oe,{...r})})]}),s.jsx(a.Button,{mt:20,leftIcon:s.jsx(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this Metric"})]})}function gy({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,p]=f.useState(u);f.useEffect(()=>{p(x=>x||u)},[u]);const h=x=>{i(x);const m=y.get(l,"0.id",null);p(m)};return s.jsx(s.Fragment,{children:s.jsxs(a.Tabs,{value:d,onTabChange:p,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(fy,{control:e,index:m,remove:h})},x.id))]})})}function my({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},t,En),[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 p=c(),h=f.useMemo(()=>!y.isEqual(p,r),[p,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:!h||!d.isValid,children:s.jsx(_.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(gy,{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(xy,{control:i,watch:l})})]})]})})}function yy(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 by(e){const{dimensions:t=[],...n}=e;return{...n,dimensions:t.map(r=>({...r,id:r.id??r.name}))}}function jy(e){const t={background:{enabled:!0},label:{enabled:!0}};return y.defaultsDeep(t,e)}function vy(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 wy(e){const t={additional_series:[]};return y.defaultsDeep(t,e)}function Cy(e){const t={...e,dimensions:e.dimensions.map(n=>({...n,max:String(n.max)}))};return delete t.additionalSeries,t}class Sy extends re{constructor(){super(...arguments);E(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:yy(r)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:by(r)}}),this.version(4,n=>{const{config:r}=n;return{...n,version:4,config:jy(r)}}),this.version(5,(n,r)=>{const{config:i}=n;return{...n,version:5,config:vy(i,r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:wy(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:Cy(r)}})}}const _y={displayName:"Radar Chart",displayGroup:"ECharts-based charts",migrator:new Sy,name:"radar",viewRender:py,configRender:my,createConfig:()=>({version:7,config:En}),triggers:[Va]};function ky(e,t){const{plot:n,transform:r}=e.regression;return t.map(i=>({...n,id:`reg-for-${i.name}`,name:i.name,data:yn(r,i.data),color:i.color,showSymbol:!1,smooth:!0,tooltip:{show:!1},custom:{type:"regression-line",targetSeries:i.name}}))}function Ga(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 Ty(e,t){const{plot:n,transform:r}=e.regression,i=Ga(e,t);return[{type:"scatter",name:e.y_axis.name,data:i,symbolSize:4,color:"red",markLine:{...n,data:[yn(r,i)],color:"blue",smooth:!0,silent:!0,symbol:["none","none"]}}]}function Dy(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=Ga(e,u);return{type:"scatter",name:c,data:d,symbolSize:4,markLine:{...n,data:[yn(r,d)],smooth:!0,silent:!0,symbol:["none","none"]}}})}function Iy(e,t){if(t.length===0)return[];const{group_by_key:n}=e.regression;return n?Dy(e,t):Ty(e,t)}function My(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 Ay(e){return{confine:!0,trigger:"axis",formatter:t=>{const n=My(t);return n.length===0?"":`
|
|
233
|
+
`}}const dy={legend:{show:!0,bottom:0,left:0},tooltip:{trigger:"item"}},uy=["#66B4DB","#39BFA2","#E46464","#33A678","#EEBA00","#9D88CB","#939943","#E49792","#09A2B8","#AF5F6B","#6CA157","#09A2B8","#6398C7","#E692BA","#97B566","#8CACE2","#CA79AC","#6DBC80","#B08F4B","#826BAF"];function py(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:d})=>({name:c,max:d})),splitArea:{show:!1}},tooltip:ne.getTooltip({backgroundColor:"rgba(255,255,255,0.6)",formatter:cy(e)}),legend:{show:!0,bottom:0,left:"center",type:"scroll"},series:ly(t,e),color:uy};return y.merge({},dy,l)}Y.use([te.RadarChart,O.GridComponent,O.LegendComponent,O.TooltipComponent,Ce.CanvasRenderer]);function hy({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const l=f.useMemo(()=>{const{queryID:h,columnKey:x}=A(e.series_name_key),m=y.keyBy(t[h],x),j=e.additional_series.reduce((w,T)=>{const M=A(T.name_key),P=y.keyBy(t[M.queryID],M.columnKey);return{...w,...P}},m);return{...m,...j}},[t,e.series_name_key,e.additional_series]),c=$e(i.triggerManager,Na.id),d=f.useCallback(h=>{const x=y.get(l,h.name,{error:"rowData is not found"});c.forEach(m=>{i.runInteraction(m.id,{...h,rowData:x})})},[l,c,i]),u=f.useMemo(()=>({click:d}),[d]),p=f.useMemo(()=>py(y.defaultsDeep({},e,En),t),[e,t]);return!n||!r?null:s.jsx(we,{echarts:Y,option:p,style:{width:n,height:r},onEvents:u,notMerge:!0,theme:"merico-light"})}function xy({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,En),[r]),l=e.data,{width:c,height:d}=e.viewport;return!c||!d||!o||y.isEmpty(o==null?void 0:o.dimensions)?null:s.jsx(De,{width:c,height:d,children:s.jsx(hy,{variables:i,width:We(c),height:Re(d),data:l,conf:o,interactionManager:n})})}function fy({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(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),children:"Delete"})]})}function gy({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:""})},d=y.get(l,"0.id",null),[u,p]=f.useState(d);f.useEffect(()=>{p(x=>x||d)},[d]);const h=x=>{i(x);const m=y.get(l,"0.id",null);p(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:u,onTabChange:p,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(fy,{control:e,index:m,remove:h})},x.id))]})]})}function my({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(Oe,{...r})})]}),s.jsx(a.Button,{mt:20,leftIcon:s.jsx(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this Metric"})]})}function yy({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:be})},d=y.get(l,"0.id",null),[u,p]=f.useState(d);f.useEffect(()=>{p(x=>x||d)},[d]);const h=x=>{i(x);const m=y.get(l,"0.id",null);p(m)};return s.jsx(s.Fragment,{children:s.jsxs(a.Tabs,{value:u,onTabChange:p,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(my,{control:e,index:m,remove:h})},x.id))]})})}function by({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},t,En),[t]),{control:i,handleSubmit:o,watch:l,getValues:c,reset:d,formState:u}=b.useForm({defaultValues:r,mode:"all"});f.useEffect(()=>{d(r)},[r]),l(["series_name_key","background","label"]);const p=c(),h=f.useMemo(()=>!y.isEqual(p,r),[p,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:!h||!u.isValid,children:s.jsx(_.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(yy,{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(gy,{control:i,watch:l})})]})]})})}function jy(e){const{dimensions:t=[],...n}=e;function r({name:i="",data_key:o="",max:l=10,formatter:c=be}){return{name:i,data_key:o,max:l,formatter:c}}return{...n,dimensions:t.map(r)}}function vy(e){const{dimensions:t=[],...n}=e;return{...n,dimensions:t.map(r=>({...r,id:r.id??r.name}))}}function wy(e){const t={background:{enabled:!0},label:{enabled:!0}};return y.defaultsDeep(t,e)}function Cy(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 Sy(e){const t={additional_series:[]};return y.defaultsDeep(t,e)}function _y(e){const t={...e,dimensions:e.dimensions.map(n=>({...n,max:String(n.max)}))};return delete t.additionalSeries,t}class ky extends ie{constructor(){super(...arguments);E(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:jy(r)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:vy(r)}}),this.version(4,n=>{const{config:r}=n;return{...n,version:4,config:wy(r)}}),this.version(5,(n,r)=>{const{config:i}=n;return{...n,version:5,config:Cy(i,r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:Sy(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:_y(r)}})}}const Ty={displayName:"Radar Chart",displayGroup:"ECharts-based charts",migrator:new ky,name:"radar",viewRender:xy,configRender:by,createConfig:()=>({version:7,config:En}),triggers:[Na]};function Dy(e,t){const{plot:n,transform:r}=e.regression;return t.map(i=>({...n,id:`reg-for-${i.name}`,name:i.name,data:yn(r,i.data),color:i.color,showSymbol:!1,smooth:!0,tooltip:{show:!1},custom:{type:"regression-line",targetSeries:i.name}}))}function Wa(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 Iy(e,t){const{plot:n,transform:r}=e.regression,i=Wa(e,t);return[{type:"scatter",name:e.y_axis.name,data:i,symbolSize:4,color:"red",markLine:{...n,data:[yn(r,i)],color:"blue",smooth:!0,silent:!0,symbol:["none","none"]}}]}function My(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,d])=>{const u=Wa(e,d);return{type:"scatter",name:c,data:u,symbolSize:4,markLine:{...n,data:[yn(r,u)],smooth:!0,silent:!0,symbol:["none","none"]}}})}function Ay(e,t){if(t.length===0)return[];const{group_by_key:n}=e.regression;return n?My(e,t):Iy(e,t)}function zy(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 Ey(e){return ne.getTooltip({trigger:"axis",formatter:t=>{const n=zy(t);return n.length===0?"":`
|
|
234
234
|
<table style="width: auto">
|
|
235
235
|
<thead>
|
|
236
236
|
<tr>
|
|
@@ -249,46 +249,46 @@ Check the top-level render call using <`+z+">.")}return D}}function dc(v,D){{if(
|
|
|
249
249
|
</tr>
|
|
250
250
|
</tbody>
|
|
251
251
|
</table>
|
|
252
|
-
`}}}function
|
|
253
|
-
`)},ir={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,format:
|
|
252
|
+
`}})}function Ra({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 Py(e){const{overflow:t,format:n,formatter:r,...i}=e.x_axis.axisLabel,o=Ue(t.on_axis);return ne.getXAxis({type:"value",name:e.x_axis.name??"",nameLocation:"middle",nameGap:25,axisLabel:{...i,...o,formatter:(l,c)=>{let d=l;try{d=F(l).format(n)}catch{}return Ra(r)(d,c)}}})}const Ly={tooltip:{trigger:"axis"},grid:{top:50,left:5,right:10,bottom:20,containLabel:!0},dataZoom:[{type:"inside",xAxisIndex:[0]},{type:"inside",yAxisIndex:[0]}]};function Oy(e,t){const n=Ay(e,t),r=Dy(e,n),i={xAxis:Py(e),yAxis:ne.getYAxis({name:e.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"left"},nameGap:5}),series:[...n,...r],tooltip:Ey(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,Ly)}function Pn(e,t,n){return 1-(1-e)*(t-1)/(t-n-1)}function By(e,t,n,r){const{x_axis:i,y_axis:o}=r,l=dt.regressionLinear()(n),{a:c,b:d,rSquared:u}=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:F(d).format({mantissa:2,trimMantissa:!0})}),s.jsx(a.Text,{children:"+"}),s.jsx(a.Text,{weight:"bold",color:"red",children:F(c).format({mantissa:2,trimMantissa:!0})}),s.jsx(a.Text,{children:"×"}),s.jsx(a.Text,{children:i.name})]}),rSquared:u,adjustedRSquared:Pn(u,t.length,1)}}function $y(e,t,n,r){const{x_axis:i,y_axis:o}=r,{a:l,b:c,rSquared:d}=dt.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:d,adjustedRSquared:Pn(d,t.length,1)}}function Vy(e,t,n,r){const{x_axis:i,y_axis:o}=r,{a:l,b:c,rSquared:d}=dt.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:d,adjustedRSquared:Pn(d,t.length,1)}}function Ny(e,t,n,r){const{x_axis:i,y_axis:o,regression:l}=r,c=dt.regressionPoly().order(l.transform.config.order)(n),{rSquared:d}=c;return console.log(c),{name:e,expression:"",rSquared:d,adjustedRSquared:Pn(d,t.length,1)}}function Qa(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(d=>[d[o.columnKey],d[l.columnKey]]);return r.transform.config.method==="linear"?By(e,t,c,n):r.transform.config.method==="exponential"?$y(e,t,c,n):r.transform.config.method==="logarithmic"?Vy(e,t,c,n):r.transform.config.method==="polynomial"?Ny(e,t,c,n):{name:e,expression:"",rSquared:0,adjustedRSquared:0}}function qy(e,t){if(!t)return[{name:"",expression:"",rSquared:0,adjustedRSquared:0}];if(!t.regression.group_by_key)return[Qa("",e,t)];const n=A(t.regression.group_by_key),r=y.groupBy(e,n.columnKey);return Object.entries(r).map(([i,o])=>Qa(i,o,t))}const Fy={marginTop:"10px","tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function Ua({desc:e}){const{expression:t,rSquared:n,adjustedRSquared:r}=e;return t?s.jsx(a.Table,{fontSize:14,sx:Fy,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:F(n).format({output:"percent",mantissa:1})})]}),s.jsxs("tr",{children:[s.jsx("td",{children:"R-Sq(Adjusted)"}),s.jsx("td",{style:{textAlign:"right"},children:F(r).format({output:"percent",mantissa:1})})]})]})}):s.jsx(a.Text,{children:"Unavailable for this regression method"})}function Gy({conf:e,queryData:t}){var r;const n=f.useMemo(()=>qy(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(Ua,{desc:i})},i.name))]})):s.jsx(Ua,{desc:n[0]})}function Wy({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(Se,{children:s.jsx(Gy,{conf:e,queryData:t})})})]})}function Ry(e){return s.jsx(a.Group,{position:"apart",sx:{position:"absolute",top:0,left:Te.left,right:Te.right,height:"22px",zIndex:1},children:s.jsx(Wy,{...e})})}const Ln={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
253
|
+
`)},ir={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,format:be,overflow:ze,formatter:{...Ln}}},y_axis:{name:"Y Axis"},regression:{transform:{type:"ecStat:regression",config:{method:"linear",order:1,formulaOn:"end"}},plot:{type:"line",yAxisIndex:0,color:"#228be6",lineStyle:{type:"solid",width:1}},name:"regression",group_by_key:"",y_axis_data_key:"value"}};Y.use([O.DataZoomComponent,te.ScatterChart,O.GridComponent,O.LegendComponent,O.TooltipComponent,Ce.CanvasRenderer]);function Qy({context:e}){const{value:t}=$(e.instanceData,"config"),{width:n,height:r}=e.viewport,i=f.useMemo(()=>{var m;const d=e.data,u=t==null?void 0:t.x_axis.data_key,p=(m=t==null?void 0:t.regression)==null?void 0:m.y_axis_data_key;if(!u||!p)return[];const h=A(u),x=A(p);return d[h.queryID].map(j=>typeof j[x.columnKey]=="number"?j:{...j,[x.columnKey]:Number(j[x.columnKey])})},[e.data,t==null?void 0:t.regression.y_axis_data_key]),o=f.useMemo(()=>Oy(y.defaultsDeep({},t,ir),i),[t,i]),l=f.useRef(null),c=d=>{l.current=d};return!n||!r||!t?null:s.jsxs(De,{width:n,height:r,children:[s.jsx(Ry,{conf:t,queryData:i}),s.jsx(we,{echarts:Y,onChartReady:c,option:o,style:Wt(n,r),notMerge:!0,theme:"merico-light"})]})}const Uy=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}];function Yy({control:e,watch:t}){t("regression");const n=t("regression.transform.config.method"),r=t("regression.group_by_key");return s.jsxs(a.Stack,{children:[s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:"regression.name",control:e,render:({field:i})=>s.jsx(a.TextInput,{label:"回归线名称",sx:{flex:1},...i})})}),s.jsx(b.Controller,{name:"regression.group_by_key",control:e,render:({field:i})=>s.jsx(B,{label:"按此字段将数据分为多个系列",clearable:!0,sx:{flex:1},...i})}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"regression.transform.config.method",control:e,render:({field:i})=>s.jsx(a.Select,{label:"回归方法",data:Uy,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 Ky=({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(me,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},Ya=f.forwardRef(({value:e,onChange:t,triggerButtonText:n="Customize Label"},r)=>{const[i,{setTrue:o,setFalse:l}]=V.useBoolean(),[c,d]=f.useState(e);f.useEffect(()=>{d(e)},[e]);const u=j=>{d({...c,enabled:j})},p=()=>{l();const{enabled:j,func_content:w}=c,T={enabled:j,func_content:w};d(T),t(T)},h=()=>{l(),d(e)},x=j=>{d(w=>({...w,func_content:j}))},m=()=>{x(Ln.func_content)};return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"filled",mt:24,onClick:o,sx:{flexGrow:0},children:n}),s.jsx(a.Modal,{size:800,title:"Customize label content",opened:i,onClose:l,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:i&&s.jsxs(a.Stack,{children:[s.jsx(a.Checkbox,{mt:10,label:"Enabled",checked:c.enabled,onChange:j=>u(j.currentTarget.checked)}),s.jsx(Ky,{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(_.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:p,children:"OK"})]})]})]})})]})});function Xy({control:e,watch:t}){return t(["x_axis"]),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"X轴名称",sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>s.jsx(B,{label:"X轴数据字段",required:!0,sx:{flex:1},...n})})]}),s.jsx(a.Divider,{variant:"dashed",labelPosition:"center",label:"格式化数据"}),s.jsx(a.Stack,{children:s.jsx(b.Controller,{name:"x_axis.axisLabel.format",control:e,render:({field:n})=>s.jsx(Oe,{...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(Ya,{triggerButtonText:"自定义标签文案内容",...n})})]}),s.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>s.jsx(Je,{...n})})]})}function Jy({control:e,watch:t}){return t(["y_axis","regression.y_axis_data_key"]),s.jsx(a.Stack,{children:s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"y_axis.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"Y轴名称",sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"regression.y_axis_data_key",control:e,render:({field:n})=>s.jsx(B,{label:"Y轴数据字段",required:!0,sx:{flex:1},...n})})]})})}function Zy({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaults({},t,ir),[t]),{control:i,handleSubmit:o,watch:l,getValues:c,reset:d}=b.useForm({defaultValues:r});f.useEffect(()=>{d(r)},[r]),l(["x_axis","y_axis","regression"]);const u=c(),p=f.useMemo(()=>!y.isEqual(u,t),[u,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:!p,children:s.jsx(_.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(Xy,{watch:l,control:i})}),s.jsx(a.Tabs.Panel,{value:"Y轴",children:s.jsx(Jy,{watch:l,control:i})}),s.jsx(a.Tabs.Panel,{value:"回归",children:s.jsx(Yy,{control:i,watch:l})})]})]})})}function Hy(e){const t={x_axis:{axisLabel:{rotate:0,format:be,overflow:ze,formatter:Ln}},regression:{group_by_key:""}};return y.defaultsDeep(t,e)}function eb(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 tb extends ie{constructor(){super(...arguments);E(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:Hy(n.config)})),this.version(3,(n,r)=>{const{config:i}=n;return{...n,version:3,config:eb(i,r)}})}}const nb={displayName:"Regression Chart",displayGroup:"Merico suite",migrator:new tb,name:"regressionChart",viewRender:Qy,configRender:Zy,createConfig(){return{version:3,config:y.cloneDeep(ir)}}},On={content:""};function sb(e,t){const n={};return e.forEach(r=>{const{name:i,data_field:o,aggregation:l}=r,c=fn(t,o,l);n[i]=Ne(r,c)}),n}function rb(e){const t=document.createElement("span");return t.innerHTML=e,t.innerText}function ib(e,t,n){try{return new Function("payload",`
|
|
254
254
|
const filters = payload.filters;
|
|
255
255
|
const context = payload.context;
|
|
256
256
|
${Object.entries(t).map(([r,i])=>`const ${r} = '${i}';`).join(`
|
|
257
257
|
`)}
|
|
258
258
|
return ${e};
|
|
259
|
-
`)(n)}catch(r){return console.error(r),console.log(e),e}}function
|
|
260
|
-
`)}},
|
|
261
|
-
`)},
|
|
259
|
+
`)(n)}catch(r){return console.error(r),console.log(e),e}}function ab(e,t,n,r){const i=sb(t,r),o=/^(.+)\}\}(.*)$/;return e.split("{{").map(l=>{const c=o.exec(l);if(!c)return l;const d=i[c[1]];if(d){const p=c[2]??"";return`${d}${p}`}const u=rb(c[1]);return`${ib(u,i,n)}${c[2]}`}).join("")}const ob=S.observer(({context:e})=>{const t=ce(),{value:n}=$(e.instanceData,"config"),{variables:r,data:i}=e,o=f.useMemo(()=>{const l=y.defaults({},n,On);return l.content?ab(l.content,r,t.payloadForViz,i):""},[n,r,t.payloadForViz]);return o?s.jsx(An,{value:o,styles:{root:{border:"none",height:"100%"},content:{padding:0}}}):null});function lb(){const{editor:e}=q.useRichTextEditorContext();return s.jsx(q.RichTextEditor.Control,{onClick:()=>e==null?void 0:e.commands.insertTable({rows:3,cols:3,withHeaderRow:!0}),"aria-label":"Insert table",title:"Insert table",children:s.jsx(k.IconBorderAll,{stroke:1.5,size:16})})}const ar=f.forwardRef(({value:e,onChange:t,styles:n={},label:r,onSubmit:i},o)=>{const[l,c]=f.useState(e),d=pi.useEditor({extensions:[hi,ui,q.Link,ri,si,ti,oi.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),di,ci,li,ii.configure({types:["heading","paragraph"]}),ni.configure({placeholder:"This is placeholder"}),ai,ei.Color,Ma],content:l,onUpdate:({editor:x})=>{c(x.getHTML())}});f.useEffect(()=>{c(e),d==null||d.commands.setContent(e)},[e]);const u=()=>{t(l),i==null||i()},p=e!==l,h=f.useMemo(()=>y.defaultsDeep({},{content:Os},n),[n]);return d?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:!p,onClick:u,children:s.jsx(k.IconDeviceFloppy,{size:18})})]}),s.jsxs(q.RichTextEditor,{editor:d,styles:h,children:[s.jsxs(q.RichTextEditor.Toolbar,{sticky:!0,stickyOffset:0,children:[s.jsx(q.RichTextEditor.ControlsGroup,{children:s.jsx(q.RichTextEditor.ColorPicker,{colors:["#25262b","#868e96","#fa5252","#e64980","#be4bdb","#7950f2","#4c6ef5","#228be6","#15aabf","#12b886","#40c057","#82c91e","#fab005","#fd7e14"],popoverProps:{zIndex:320}})}),s.jsxs(q.RichTextEditor.ControlsGroup,{children:[s.jsx(q.RichTextEditor.Bold,{}),s.jsx(q.RichTextEditor.Italic,{}),s.jsx(q.RichTextEditor.Underline,{}),s.jsx(q.RichTextEditor.ClearFormatting,{}),s.jsx(q.RichTextEditor.Highlight,{}),s.jsx(q.RichTextEditor.Code,{})]}),s.jsxs(q.RichTextEditor.ControlsGroup,{children:[s.jsx(q.RichTextEditor.H1,{}),s.jsx(q.RichTextEditor.H2,{}),s.jsx(q.RichTextEditor.H3,{}),s.jsx(q.RichTextEditor.H4,{})]}),s.jsxs(q.RichTextEditor.ControlsGroup,{children:[s.jsx(q.RichTextEditor.Blockquote,{}),s.jsx(q.RichTextEditor.Hr,{}),s.jsx(q.RichTextEditor.BulletList,{}),s.jsx(q.RichTextEditor.OrderedList,{}),s.jsx(q.RichTextEditor.Subscript,{}),s.jsx(q.RichTextEditor.Superscript,{})]}),s.jsxs(q.RichTextEditor.ControlsGroup,{children:[s.jsx(q.RichTextEditor.Link,{}),s.jsx(q.RichTextEditor.Unlink,{})]}),s.jsxs(q.RichTextEditor.ControlsGroup,{children:[s.jsx(q.RichTextEditor.AlignLeft,{}),s.jsx(q.RichTextEditor.AlignCenter,{}),s.jsx(q.RichTextEditor.AlignJustify,{}),s.jsx(q.RichTextEditor.AlignRight,{})]}),s.jsx(q.RichTextEditor.ControlsGroup,{children:s.jsx(lb,{})}),s.jsx(pf,{editor:d})]}),s.jsx(q.RichTextEditor.Content,{})]})]}):null});function cb({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaults({},t,On),[t]),{control:i,handleSubmit:o,watch:l,reset:c}=b.useForm({defaultValues:r});l("content"),f.useEffect(()=>{c(r)},[r]);const d=f.useRef(null),u=()=>{var p;return(p=d.current)==null?void 0:p.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:d,type:"submit",mr:5,variant:"filled",color:"blue",children:s.jsx(_.DeviceFloppy,{size:20})})]}),s.jsx(b.Controller,{name:"content",control:i,render:({field:p})=>s.jsx(ar,{...p,styles:{root:{flexGrow:1}},label:"Content",onSubmit:u})})]})})}class db extends ie{constructor(){super(...arguments);E(this,"VERSION",1)}fixMalformedConfig(n){return y.defaults({},n,On)}configVersions(){this.version(1,n=>({version:1,config:this.fixMalformedConfig(n)}))}}const ub={displayName:"Rich Text",displayGroup:"Others",migrator:new db,name:"richText",viewRender:ob,configRender:cb,createConfig(){return{version:1,config:y.cloneDeep(On)}}},tn={static:{type:"static",color:nt.random().css()},dynamic:{type:"dynamic",func_content:["function getColor({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here",' // return "blue"',"}"].join(`
|
|
260
|
+
`)}},Ka={id:"builtin:echarts:click-scatter-chart:series",displayName:"Click Scatter",nameRender:hb,configRender:pb,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 pb(e){return s.jsx(s.Fragment,{})}function hb(e){return s.jsx(a.Text,{children:"Click scatter"})}const Xa={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
261
|
+
`)},Ja={label:ze.on_axis,tooltip:ze.in_tooltip},or={scatter:{y_data_key:"",name_data_key:"",symbolSize:{type:"static",size:10},color:tn.static,label_position:"right",label_overflow:Ja},stats:{templates:{top:"",bottom:""}},x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...Xa}}},y_axes:[{name:"Y Axis",position:"left",nameAlignment:"center",label_formatter:be,min:"",max:"",show:!0}],tooltip:{trigger:"item",metrics:[]},reference_lines:[],reference_areas:[],dataZoom:zt};function xb(e,t){if(!e.x_axis.data_key)return[];const n=A(e.x_axis.data_key);return[{source:t[n.queryID]}]}function fb(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 gb(){return{show:!1,bottom:0,left:"center",type:"scroll"}}function Bn(e,t){if(e)return t[e]??void 0}function mb({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:Bn(r.leftBottomPoint.x_data_key,t),yAxis:Bn(r.leftBottomPoint.y_data_key,t)},{xAxis:Bn(r.rightTopPoint.x_data_key,t),yAxis:Bn(r.rightTopPoint.y_data_key,t)}]);return{type:"scatter",name:"ref_areas",silent:!0,data:[],markArea:{data:n}}}function yb({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:ft.interpolate})}catch(c){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${c.message}`),10}}}function bb({type:e,...t},n){if(!e)return tn.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:ft.interpolate})}catch(o){return console.error(`[getSeriesColor] failed parsing custom function, error: ${o.message}`),10}}}function jb(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?gn(i.template,t,r):""},position:c}}}})}function vb({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,...Ue(t.label_overflow.label),formatter:({value:l})=>l[o.columnKey]},type:"scatter",name:"",xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{color:bb(t.color,n)},symbolSize:yb(t.symbolSize,n),encode:{x:r.columnKey,y:i.columnKey}}}function wb(e,t,n,r){return[vb(e,r)].concat(jb(e.reference_lines,n,r,t)).concat(mb({reference_areas:e.reference_areas,variableValueMap:r}))}function Za({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 Ha(e,t,n){const{x_axis:r}=n;return r.axisLabel.formatter.enabled?Za(r.axisLabel.formatter)(e,t):e}function Cb(e,t){const{x_axis:n,tooltip:r}=t;if(r.trigger==="item"){const c=un(e[0].data,n.data_key);return Ha(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 Ha(o,l,t)}const Sb=e=>{try{return F(e).format({trimMantissa:!0,mantissa:2})}catch{return e}};function _b(e,t){const{scatter:n,tooltip:r}=e;return ne.getTooltip({trigger:r.trigger,formatter:function(i){const o=t[0]??t.default,l=Array.isArray(i)?i:[i];if(l.length===0)return"";const c=Cb(l,e),d=Qe(e.scatter.label_overflow.tooltip),u=l.map(({value:m})=>`
|
|
262
262
|
<th style="text-align: right; padding-right: 1em">
|
|
263
|
-
<div style="${
|
|
263
|
+
<div style="${d}">${un(m,n.name_data_key)}</div>
|
|
264
264
|
</th>
|
|
265
|
-
`);
|
|
265
|
+
`);u.unshift("<th></th>");const p=[`<tr>
|
|
266
266
|
<th style="text-align: right;">${e.x_axis.name}</th>
|
|
267
267
|
${l.map(m=>`<td style="text-align: right; padding: 0 1em;">${c}</td>`).join("")}
|
|
268
268
|
</tr>`,`<tr>
|
|
269
269
|
<th style="text-align: right;">${e.y_axes[0].name}</th>
|
|
270
270
|
${l.map(({value:m})=>`
|
|
271
271
|
<td style="text-align: right; padding: 0 1em;">
|
|
272
|
-
${o(
|
|
272
|
+
${o(un(m,n.y_data_key))}
|
|
273
273
|
</td>`).join("")}
|
|
274
274
|
</tr>`],h=e.tooltip.metrics.map(m=>`<tr>
|
|
275
275
|
<th style="text-align: right;">${m.name}</th>
|
|
276
|
-
${l.map(({value:j})=>`<td style="text-align: right; padding: 0 1em;">${
|
|
276
|
+
${l.map(({value:j})=>`<td style="text-align: right; padding: 0 1em;">${Sb(un(j,m.data_key))}</td>`).join("")}
|
|
277
277
|
</tr>`);return p.push(...h),`
|
|
278
278
|
<table style="width: auto">
|
|
279
|
-
<thead><tr>${
|
|
279
|
+
<thead><tr>${u.join("")}</tr></thead>
|
|
280
280
|
<tbody>${p.join("")}</tbody>
|
|
281
281
|
</table>
|
|
282
|
-
`}}}function Sb(e,t){const n=t.every(o=>!Number.isNaN(Number(o))),{axisLabel:r}=e.x_axis,i=t.length===0;return[ze.getXAxis({data:t,name:e.x_axis.name??"",nameGap:i?5:void 0,id:"main-x-axis",type:n?"value":"category",axisLabel:{...r,formatter:Ja(r.formatter)}})]}function _b(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"),ze.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 kb={xAxis:[{type:"category",nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0}}],grid:{top:10,left:20,right:15,bottom:25,containLabel:!0}};function Tb(e,t,n){const r=n.reduce((u,d)=>{const p=it(d,t);return u[d.name]=Ne(d,p),u},{}),i=e.y_axes.reduce((u,{label_formatter:d},p)=>(u[p]=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 F(m).format(d)}catch(j){return console.error(j),m}},u),{default:({value:u})=>u}),o=y.uniq(rt(t,e.x_axis.data_key)),l=jb(e,t,n,r),c={xAxis:Sb(e,o),yAxis:_b(e,i),series:l,dataset:pb(e,t),tooltip:Cb(e,i),grid:hb(e),legend:xb(),dataZoom:zs(e.dataZoom)};return y.defaultsDeep({},c,kb)}Y.use([O.DataZoomComponent,te.BarChart,te.LineChart,te.ScatterChart,O.GridComponent,O.LegendComponent,O.TooltipComponent,we.CanvasRenderer,O.MarkLineComponent,O.MarkAreaComponent]);function Ha(e){return e.trim().length>0}function Db({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const l=mt(t,e.x_axis.data_key),c=$e(i.triggerManager,Ya.id),u=f.useCallback(h=>{const x=h.data;c.forEach(m=>{i.runInteraction(m.id,{...h,rowData:x})})},[l,c,i]),d=f.useMemo(()=>({click:u}),[u]),p=f.useMemo(()=>Tb(e,t,o),[e,t]);return s.jsx(ve,{echarts:Y,option:p,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function Ib({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,or),[r]),l=e.data,{width:c,height:u}=e.viewport,{ref:d,height:p}=oe.useElementSize(),{ref:h,height:x}=oe.useElementSize(),m=f.useMemo(()=>{const{stats:{templates:w}}=o;return{top:Ut(w.top,i,l),bottom:Ut(w.bottom,i,l)}},[o,l]),j=Math.max(0,Re(u)-p-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:Ha(o.stats.templates.top)?"block":"none"},children:Object.values(m.top).map(w=>w)}),s.jsx(Db,{variables:i,width:We(c),height:j,data:l,conf:o,interactionManager:n}),s.jsx(a.Text,{ref:h,align:"left",size:"xs",pl:"sm",sx:{display:Ha(o.stats.templates.bottom)?"block":"none"},children:Object.values(m.bottom).map(w=>w)})]})}const Mb=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(er,{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(Se,{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(Se,{value:e.label.color,onChange:c=>l("label.color",c)})]})]})});function Ab(){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 zb({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=Ab();i(x)},d=f.useMemo(()=>n.map(x=>({label:x.name,value:x.name})),[n]),p=t("y_axes"),h=f.useMemo(()=>p.map(({name:x},m)=>({label:x,value:m.toString()})),[p]);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(_.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(Mb,{variableOptions:d,yAxisOptions:h,...j}),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 Eb=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Pb=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Lb({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:Pb,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:p=>{if(!p){u(0);return}u(Number(p))},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:Eb,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(Se,{...c})})]}),s.jsx(a.Button,{leftIcon:s.jsx(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]})}function Ob({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:nt.random().css()},show_in_legend:!1,yAxisIndex:0};i(x)},d=f.useMemo(()=>n.map(x=>({label:x.name,value:x.name})),[n]),p=t("y_axes"),h=f.useMemo(()=>p.map(({name:x},m)=>({label:x,value:m.toString()})),[p]);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(_.Plus,{size:18,color:"#228be6"})})]}),c.map((x,m)=>s.jsx(a.Tabs.Panel,{value:m.toString(),children:s.jsx(Lb,{control:e,index:m,remove:o,watch:t,variableOptions:d,yAxisOptions:h})},x.id))]})}const Bb=({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}}})})},$b=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:i}]=V.useBoolean(),[o,l]=f.useState(e),c=()=>{i();const{type:h,func_content:x}=o,m={type:h,func_content:x};l(m),t(m)},u=()=>{i(),l(e)},d=h=>{l(x=>({...x,func_content:h}))},p=()=>{d(tn.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(Bb,{value:o.func_content,onChange:d}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:p,color:"red",leftIcon:s.jsx(_.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"})]})]})]})})]})},Vb=({value:e,onChange:t})=>e.type!=="dynamic"?null:s.jsx($b,{value:e,onChange:t}),Nb=({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})},qb=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Fb=f.forwardRef(({label:e="Color",value:t,onChange:n},r)=>{const i=o=>{n({...tn[o]})};return s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(a.Select,{ref:r,label:e,data:qb,value:t.type,onChange:i,sx:{flexGrow:1}}),s.jsx(Nb,{value:t,onChange:n}),s.jsx(Vb,{value:t,onChange:n})]})}),Gb=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(hn,{sectionTitle:"Overflow on Chart",value:e.label,onChange:r}),s.jsx(hn,{sectionTitle:"Overflow in Tooltip",value:e.tooltip,onChange:i})]})}),Wb=({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}}})})},eo={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
|
|
283
|
-
`)}},Rb=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:i}]=V.useBoolean(),[o,l]=f.useState(e),c=()=>{i();const{type:h,func_content:x}=o,m={type:h,func_content:x};l(m),t(m)},u=()=>{i(),l(e)},d=h=>{l(x=>({...x,func_content:h}))},p=()=>{d(eo.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(Wb,{value:o.func_content,onChange:d}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:p,color:"red",leftIcon:s.jsx(_.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"})]})]})]})})]})},Qb=({value:e,onChange:t})=>e.type!=="dynamic"?null:s.jsx(Rb,{value:e,onChange:t}),Ub=({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})})},Yb=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Kb=f.forwardRef(({label:e="Size",value:t,onChange:n},r)=>{const i=o=>{n({...eo[o]})};return s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(a.Select,{ref:r,label:e,data:Yb,value:t.type,onChange:i,sx:{flexGrow:1}}),s.jsx(Ub,{value:t,onChange:n}),s.jsx(Qb,{value:t,onChange:n})]})}),Xb=[{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 Jb({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(Kb,{label:"Size",...n})}),s.jsx(b.Controller,{name:"scatter.color",control:e,render:({field:n})=>s.jsx(Fb,{...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:Xb,...n})})}),s.jsx(b.Controller,{name:"scatter.label_overflow",control:e,render:({field:n})=>s.jsx(Gb,{...n})})]})}function Zb({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(Qt,{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(Qt,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const Hb=({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(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),ej=({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((h,x)=>({...h,...o[x]})),c=()=>r({id:Date.now().toString(),data_key:"",name:""}),u=t("tooltip.metrics.0.id"),[d,p]=f.useState(()=>u??null);return f.useEffect(()=>{u&&p(h=>h!==null?h:u)},[u]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(_.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:h=>p(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((h,x)=>s.jsx(a.Tabs.Tab,{value:h.id,children:h.name?h.name:x},h.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),l.map((h,x)=>s.jsx(a.Tabs.Panel,{value:h.id,children:s.jsx(Hb,{control:e,index:x,remove:i},h.id)},h.id))]})]})},tj=[{label:"Scatter Point",value:"item"},{label:"X Axis",value:"axis"}];function nj({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:tj,sx:{flexGrow:1},...n})}),s.jsx(a.Divider,{variant:"dashed"}),s.jsx(ej,{control:e,watch:t})]})}const sj=({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}})]})},rj=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:j}=l,w={enabled:m,func_content:j};c(w),t(w)},p=()=>{o(),c(e)},h=m=>{c(j=>({...j,func_content:m}))},x=()=>{h(Ka.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(sj,{value:l.func_content,onChange:h,disabled:!l.enabled}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:x,color:"red",leftIcon:s.jsx(_.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:d,children:"OK"})]})]})]})})]})});function ij({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(rj,{...n})})]})]})}const aj=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],oj=[{label:"left",value:"left"},{label:"right",value:"right"}];function lj({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:aj,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:oj,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(Oe,{...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(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this YAxis"})]})}function cj({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(_.Plus,{size:18,color:"#228be6"})})]}),l.map((u,d)=>s.jsx(a.Tabs.Panel,{value:d.toString(),children:s.jsx(lj,{control:e,index:d,remove:i})},u.id))]})}function uj(e){return e||{templates:{top:"",bottom:""}}}function dj({reference_lines:e=[],stats:t,...n}){return{reference_lines:e,stats:uj(t),...n}}function pj({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),{variables:r}=e,i=f.useMemo(()=>y.defaultsDeep({},t,or),[t]),o=f.useMemo(()=>dj(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:p}=b.useForm({defaultValues:o});f.useEffect(()=>{p(o)},[o]);const h=d(),x=f.useMemo(()=>!y.isEqual(h,i),[h,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(_.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(ij,{control:l,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Y Axes",children:s.jsx(cj,{control:l,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Scatter",children:s.jsx(Jb,{control:l,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(nj,{control:l,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Stats",children:s.jsx(Zb,{control:l,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Reference Lines",children:s.jsx(Ob,{variables:r,control:l,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Reference Areas",children:s.jsx(zb,{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(Ps,{...m})})})]})]})})}function hj(e){const{dataZoom:t=zt,...n}=e;return{...n,dataZoom:t}}function xj(e){const t={scatter:{label_overflow:Xa}};return y.defaultsDeep(t,e)}function fj(e){const{color:t}=e.scatter;return typeof t=="string"?{...e,scatter:{...e.scatter,color:{...tn.static,color:t}}}:e}function gj(e){const t=e.reference_lines.map(n=>{const{lineStyle:r={type:"dashed",width:1,color:nt.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 mj(e){const t={tooltip:{trigger:"item"}};return y.defaultsDeep({},e,t)}function yj(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}}class bj extends re{constructor(){super(...arguments);E(this,"VERSION",9)}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:hj(n.config)})),this.version(4,n=>{const{config:r}=n;return{...n,version:5,config:xj(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:fj(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:gj(r)}}),this.version(8,n=>{const{config:r}=n;return{...n,version:8,config:mj(r)}}),this.version(9,(n,r)=>{const{config:i}=n;return{...n,version:9,config:yj(i,r)}})}}const jj={displayName:"Scatter Chart",displayGroup:"ECharts-based charts",migrator:new bj,name:"scatterChart",viewRender:Ib,configRender:pj,createConfig(){return{version:9,config:y.cloneDeep(or)}},triggers:[Ya]},lr={template:"The variable ${value} is defined in Variables section",vertical_align:"center",horizontal_align:"left"};function vj(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 wj(e){return y.omit(e,["variables"])}function Cj(e){const{align:t,...n}=e;return{horizontal_align:t,vertical_align:"center",...n}}function Sj(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 _j extends re{constructor(){super(...arguments);E(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:vj(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(Sj(l))}),{...n,version:2,config:wj(i)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:Cj(r)}})}}const kj={left:"flex-start",center:"center",right:"flex-end"},Tj={top:"flex-start",center:"center",bottom:"flex-end"},Dj=S.observer(({context:e})=>{const t=le(),{value:n=lr}=$(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]),p=f.useMemo(()=>Ut(d,r,e.data),[d,r,e.data,e]);return s.jsx(a.Center,{sx:{width:c,height:u,justifyContent:kj[o],alignItems:Tj[l]},children:s.jsx(a.Box,{children:Object.values(p).map((h,x)=>s.jsx(f.Fragment,{children:h},x))})})}),Ij=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Mj=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function Aj({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},t,lr),[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(),p=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:!p,children:s.jsx(_.DeviceFloppy,{size:20})})]}),s.jsx(b.Controller,{name:"template",control:i,render:({field:h})=>s.jsx(Qt,{label:"Template",py:"md",sx:{flexGrow:1},...h})}),s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(b.Controller,{name:"horizontal_align",control:i,render:({field:h})=>s.jsx(a.Select,{label:"Horizontal Alignment",data:Ij,...h})}),s.jsx(b.Controller,{control:i,name:"vertical_align",render:({field:h})=>s.jsx(a.Select,{label:"Vertical Alignment",data:Mj,...h})})]})]})})}const zj={createConfig(){return{version:3,config:lr}},displayName:"Stats",displayGroup:"Others",migrator:new _j,name:"stats",viewRender:Dj,configRender:Aj},cr={label_key:"",value_key:"",group_key:"",levels:[]};function Ej(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 Pj(e){const t=Ej(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 Lj(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?Pj(u):u}const Oj=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 Bj(e){const{levels:t}=e;return t.map(n=>{const{show_label_tolerance:r,...i}=n.label;return{...n,label:{...i,formatter:Oj(r)}}})}function $j(){return({treePathInfo:e,name:t,value:n,color:r,marker:i,...o})=>{const l=e.slice(0,e.length-1),c=[`<tr>
|
|
282
|
+
`}})}function kb(e,t){const n=t.every(o=>!Number.isNaN(Number(o))),{axisLabel:r}=e.x_axis,i=t.length===0;return[ne.getXAxis({data:t,name:e.x_axis.name??"",nameGap:i?5:void 0,id:"main-x-axis",type:n?"value":"category",axisLabel:{...r,formatter:Za(r.formatter)}})]}function Tb(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"),ne.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 Db={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 Ib(e,t,n){const r=n.reduce((d,u)=>{const p=it(u,t);return d[u.name]=Ne(u,p),d},{}),i=e.y_axes.reduce((d,{label_formatter:u},p)=>(d[p]=function(x){let m=x;if(typeof x=="object"&&(Array.isArray(x.value)&&x.value.length===2?m=x.value[1]:m=x.value),!u)return m;try{return F(m).format(u)}catch(j){return console.error(j),m}},d),{default:({value:d})=>d}),o=y.uniq(rt(t,e.x_axis.data_key)),l=wb(e,t,n,r),c={xAxis:kb(e,o),yAxis:Tb(e,i),series:l,dataset:xb(e,t),tooltip:_b(e,i),grid:fb(e),legend:gb(),dataZoom:zs(e.dataZoom)};return y.defaultsDeep({},c,Db)}Y.use([O.DataZoomComponent,te.BarChart,te.LineChart,te.ScatterChart,O.GridComponent,O.LegendComponent,O.TooltipComponent,Ce.CanvasRenderer,O.MarkLineComponent,O.MarkAreaComponent]);function eo(e){return e.trim().length>0}function Mb({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const l=mt(t,e.x_axis.data_key),c=$e(i.triggerManager,Ka.id),d=f.useCallback(h=>{const x=h.data;c.forEach(m=>{i.runInteraction(m.id,{...h,rowData:x})})},[l,c,i]),u=f.useMemo(()=>({click:d}),[d]),p=f.useMemo(()=>Ib(e,t,o),[e,t]);return s.jsx(we,{echarts:Y,option:p,style:{width:n,height:r},onEvents:u,notMerge:!0,theme:"merico-light"})}function Ab({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,or),[r]),l=e.data,{width:c,height:d}=e.viewport,{ref:u,height:p}=le.useElementSize(),{ref:h,height:x}=le.useElementSize(),m=f.useMemo(()=>{const{stats:{templates:w}}=o;return{top:Ut(w.top,i,l),bottom:Ut(w.bottom,i,l)}},[o,l]),j=Math.max(0,Re(d)-p-x);return!c||!d?null:s.jsxs(De,{width:c,height:d,children:[s.jsx(a.Text,{ref:u,align:"left",size:"xs",pl:"sm",sx:{display:eo(o.stats.templates.top)?"block":"none"},children:Object.values(m.top).map(w=>w)}),s.jsx(Mb,{variables:i,width:We(c),height:j,data:l,conf:o,interactionManager:n}),s.jsx(a.Text,{ref:h,align:"left",size:"xs",pl:"sm",sx:{display:eo(o.stats.templates.bottom)?"block":"none"},children:Object.values(m.bottom).map(w=>w)})]})}const zb=f.forwardRef(({value:e,onChange:t,xAxisOptions:n,yAxisOptions:r,variableOptions:i},o)=>{const l=(c,d)=>{const u=y.cloneDeep(e);y.set(u,c,d),t(u)};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(er,{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 Eb(){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 Pb({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]})),d=()=>{const x=Eb();i(x)},u=f.useMemo(()=>n.map(x=>({label:x.name,value:x.name})),[n]),p=t("y_axes"),h=f.useMemo(()=>p.map(({name:x},m)=>({label:x,value:m.toString()})),[p]);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:d,value:"add",children:s.jsx(_.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(zb,{variableOptions:u,yAxisOptions:h,...j}),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 Lb=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Ob=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Bb({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:Ob,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:d,...u}})=>s.jsx(a.Select,{label:"Y Axis",data:o,disabled:o.length===0,...u,value:(c==null?void 0:c.toString())??"",onChange:p=>{if(!p){d(0);return}d(Number(p))},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:Lb,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(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]})}function $b({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]})),d=()=>{const x={name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:nt.random().css()},show_in_legend:!1,yAxisIndex:0};i(x)},u=f.useMemo(()=>n.map(x=>({label:x.name,value:x.name})),[n]),p=t("y_axes"),h=f.useMemo(()=>p.map(({name:x},m)=>({label:x,value:m.toString()})),[p]);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:d,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),c.map((x,m)=>s.jsx(a.Tabs.Panel,{value:m.toString(),children:s.jsx(Bb,{control:e,index:m,remove:o,watch:t,variableOptions:u,yAxisOptions:h})},x.id))]})}const Vb=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return s.jsx(a.Box,{children:s.jsx(me,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Nb=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:i}]=V.useBoolean(),[o,l]=f.useState(e),c=()=>{i();const{type:h,func_content:x}=o,m={type:h,func_content:x};l(m),t(m)},d=()=>{i(),l(e)},u=h=>{l(x=>({...x,func_content:h}))},p=()=>{u(tn.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(Vb,{value:o.func_content,onChange:u}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:p,color:"red",leftIcon:s.jsx(_.Recycle,{size:20}),children:"Reset"}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:d,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:c,children:"OK"})]})]})]})})]})},qb=({value:e,onChange:t})=>e.type!=="dynamic"?null:s.jsx(Nb,{value:e,onChange:t}),Fb=({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})},Gb=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Wb=f.forwardRef(({label:e="Color",value:t,onChange:n},r)=>{const i=o=>{n({...tn[o]})};return s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(a.Select,{ref:r,label:e,data:Gb,value:t.type,onChange:i,sx:{flexGrow:1}}),s.jsx(Fb,{value:t,onChange:n}),s.jsx(qb,{value:t,onChange:n})]})}),Rb=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(hn,{sectionTitle:"Overflow on Chart",value:e.label,onChange:r}),s.jsx(hn,{sectionTitle:"Overflow in Tooltip",value:e.tooltip,onChange:i})]})}),Qb=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return s.jsx(a.Box,{children:s.jsx(me,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},to={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
|
|
283
|
+
`)}},Ub=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:i}]=V.useBoolean(),[o,l]=f.useState(e),c=()=>{i();const{type:h,func_content:x}=o,m={type:h,func_content:x};l(m),t(m)},d=()=>{i(),l(e)},u=h=>{l(x=>({...x,func_content:h}))},p=()=>{u(to.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(Qb,{value:o.func_content,onChange:u}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:p,color:"red",leftIcon:s.jsx(_.Recycle,{size:20}),children:"Reset"}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:d,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:c,children:"OK"})]})]})]})})]})},Yb=({value:e,onChange:t})=>e.type!=="dynamic"?null:s.jsx(Ub,{value:e,onChange:t}),Kb=({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})})},Xb=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Jb=f.forwardRef(({label:e="Size",value:t,onChange:n},r)=>{const i=o=>{n({...to[o]})};return s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(a.Select,{ref:r,label:e,data:Xb,value:t.type,onChange:i,sx:{flexGrow:1}}),s.jsx(Kb,{value:t,onChange:n}),s.jsx(Yb,{value:t,onChange:n})]})}),Zb=[{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 Hb({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(Jb,{label:"Size",...n})}),s.jsx(b.Controller,{name:"scatter.color",control:e,render:({field:n})=>s.jsx(Wb,{...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:Zb,...n})})}),s.jsx(b.Controller,{name:"scatter.label_overflow",control:e,render:({field:n})=>s.jsx(Rb,{...n})})]})}function ej({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(Qt,{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(Qt,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const tj=({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(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),nj=({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((h,x)=>({...h,...o[x]})),c=()=>r({id:Date.now().toString(),data_key:"",name:""}),d=t("tooltip.metrics.0.id"),[u,p]=f.useState(()=>d??null);return f.useEffect(()=>{d&&p(h=>h!==null?h:d)},[d]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(_.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:u,onTabChange:h=>p(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((h,x)=>s.jsx(a.Tabs.Tab,{value:h.id,children:h.name?h.name:x},h.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),l.map((h,x)=>s.jsx(a.Tabs.Panel,{value:h.id,children:s.jsx(tj,{control:e,index:x,remove:i},h.id)},h.id))]})]})},sj=[{label:"Scatter Point",value:"item"},{label:"X Axis",value:"axis"}];function rj({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:sj,sx:{flexGrow:1},...n})}),s.jsx(a.Divider,{variant:"dashed"}),s.jsx(nj,{control:e,watch:t})]})}const ij=({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(me,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},aj=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 d=m=>{c({...l,enabled:m})},u=()=>{o();const{enabled:m,func_content:j}=l,w={enabled:m,func_content:j};c(w),t(w)},p=()=>{o(),c(e)},h=m=>{c(j=>({...j,func_content:m}))},x=()=>{h(Xa.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=>d(m.currentTarget.checked)}),s.jsx(ij,{value:l.func_content,onChange:h,disabled:!l.enabled}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:x,color:"red",leftIcon:s.jsx(_.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:u,children:"OK"})]})]})]})})]})});function oj({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(aj,{...n})})]})]})}const lj=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],cj=[{label:"left",value:"left"},{label:"right",value:"right"}];function dj({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:lj,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:cj,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(Oe,{...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(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this YAxis"})]})}function uj({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((d,u)=>({...d,...o[u]})),c=()=>r({name:"",label_formatter:be,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((d,u)=>s.jsx(a.Tabs.Tab,{value:u.toString(),children:u+1},d.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),l.map((d,u)=>s.jsx(a.Tabs.Panel,{value:u.toString(),children:s.jsx(dj,{control:e,index:u,remove:i})},d.id))]})}function pj(e){return e||{templates:{top:"",bottom:""}}}function hj({reference_lines:e=[],stats:t,...n}){return{reference_lines:e,stats:pj(t),...n}}function xj({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),{variables:r}=e,i=f.useMemo(()=>y.defaultsDeep({},t,or),[t]),o=f.useMemo(()=>hj(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:d,getValues:u,reset:p}=b.useForm({defaultValues:o});f.useEffect(()=>{p(o)},[o]);const h=u(),x=f.useMemo(()=>!y.isEqual(h,i),[h,i]);return d(["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(_.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(oj,{control:l,watch:d})}),s.jsx(a.Tabs.Panel,{value:"Y Axes",children:s.jsx(uj,{control:l,watch:d})}),s.jsx(a.Tabs.Panel,{value:"Scatter",children:s.jsx(Hb,{control:l,watch:d})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(rj,{control:l,watch:d})}),s.jsx(a.Tabs.Panel,{value:"Stats",children:s.jsx(ej,{control:l,watch:d})}),s.jsx(a.Tabs.Panel,{value:"Reference Lines",children:s.jsx($b,{variables:r,control:l,watch:d})}),s.jsx(a.Tabs.Panel,{value:"Reference Areas",children:s.jsx(Pb,{variables:r,control:l,watch:d})}),s.jsx(a.Tabs.Panel,{value:"Zooming",children:s.jsx(b.Controller,{name:"dataZoom",control:l,render:({field:m})=>s.jsx(Ps,{...m})})})]})]})})}function fj(e){const{dataZoom:t=zt,...n}=e;return{...n,dataZoom:t}}function gj(e){const t={scatter:{label_overflow:Ja}};return y.defaultsDeep(t,e)}function mj(e){const{color:t}=e.scatter;return typeof t=="string"?{...e,scatter:{...e.scatter,color:{...tn.static,color:t}}}:e}function yj(e){const t=e.reference_lines.map(n=>{const{lineStyle:r={type:"dashed",width:1,color:nt.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 bj(e){const t={tooltip:{trigger:"item"}};return y.defaultsDeep({},e,t)}function jj(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,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(d=>({...d,data_key:r(d.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}class vj extends ie{constructor(){super(...arguments);E(this,"VERSION",9)}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:fj(n.config)})),this.version(4,n=>{const{config:r}=n;return{...n,version:5,config:gj(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:mj(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:yj(r)}}),this.version(8,n=>{const{config:r}=n;return{...n,version:8,config:bj(r)}}),this.version(9,(n,r)=>{const{config:i}=n;return{...n,version:9,config:jj(i,r)}})}}const wj={displayName:"Scatter Chart",displayGroup:"ECharts-based charts",migrator:new vj,name:"scatterChart",viewRender:Ab,configRender:xj,createConfig(){return{version:9,config:y.cloneDeep(or)}},triggers:[Ka]},lr={template:"The variable ${value} is defined in Variables section",vertical_align:"center",horizontal_align:"left"};function Cj(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:d=""}={}}=e;return{align:t,template:`${o} \${value} ${d}`,variables:[{name:"value",data_field:l,aggregation:{type:"none",config:{}},formatter:c,color:i,weight:r,size:n}]}}function Sj(e){return y.omit(e,["variables"])}function _j(e){const{align:t,...n}=e;return{horizontal_align:t,vertical_align:"center",...n}}function kj(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 Tj extends ie{constructor(){super(...arguments);E(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:Cj(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(kj(l))}),{...n,version:2,config:Sj(i)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:_j(r)}})}}const Dj={left:"flex-start",center:"center",right:"flex-end"},Ij={top:"flex-start",center:"center",bottom:"flex-end"},Mj=S.observer(({context:e})=>{const t=ce(),{value:n=lr}=$(e.instanceData,"config"),{variables:r}=e,{template:i,horizontal_align:o,vertical_align:l}=n,{width:c,height:d}=e.viewport,u=f.useMemo(()=>{try{return y.template(i)(t.payloadForSQL)}catch{return i}},[t.payloadForSQL,i]),p=f.useMemo(()=>Ut(u,r,e.data),[u,r,e.data,e]);return s.jsx(a.Center,{sx:{width:c,height:d,justifyContent:Dj[o],alignItems:Ij[l]},children:s.jsx(a.Box,{children:Object.values(p).map((h,x)=>s.jsx(f.Fragment,{children:h},x))})})}),Aj=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],zj=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function Ej({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},t,lr),[t]),{control:i,handleSubmit:o,watch:l,getValues:c,reset:d}=b.useForm({defaultValues:r});f.useEffect(()=>{d(r)},[r]),l(["template","horizontal_align","vertical_align"]);const u=c(),p=f.useMemo(()=>!y.isEqual(u,t),[u,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:!p,children:s.jsx(_.DeviceFloppy,{size:20})})]}),s.jsx(b.Controller,{name:"template",control:i,render:({field:h})=>s.jsx(Qt,{label:"Template",py:"md",sx:{flexGrow:1},...h})}),s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(b.Controller,{name:"horizontal_align",control:i,render:({field:h})=>s.jsx(a.Select,{label:"Horizontal Alignment",data:Aj,...h})}),s.jsx(b.Controller,{control:i,name:"vertical_align",render:({field:h})=>s.jsx(a.Select,{label:"Vertical Alignment",data:zj,...h})})]})]})})}const Pj={createConfig(){return{version:3,config:lr}},displayName:"Stats",displayGroup:"Others",migrator:new Tj,name:"stats",viewRender:Mj,configRender:Ej},cr={label_key:"",value_key:"",group_key:"",levels:[]};function Lj(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 Oj(e){const t=Lj(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 Bj(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),d=t[o.queryID].map(u=>({...u,id:u[o.columnKey],parent_id:u[c.columnKey],name:u[o.columnKey],value:u[l.columnKey]?Number(u[l.columnKey]):u[l.columnKey]}));return i?Oj(d):d}const $j=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 Vj(e){const{levels:t}=e;return t.map(n=>{const{show_label_tolerance:r,...i}=n.label;return{...n,label:{...i,formatter:$j(r)}}})}function Nj(){return({treePathInfo:e,name:t,value:n,color:r,marker:i,...o})=>{const l=e.slice(0,e.length-1),c=[`<tr>
|
|
284
284
|
<th style="text-align: right; padding: 0 1em;">Value</th>
|
|
285
285
|
<td style="text-align: left; padding: 0 1em;">${n}</td>
|
|
286
286
|
</tr>
|
|
287
|
-
`];return l.reverse().forEach(({value:
|
|
287
|
+
`];return l.reverse().forEach(({value:u,name:p})=>{c.push(`
|
|
288
288
|
<tr>
|
|
289
289
|
<th style="text-align: right; padding: 0 1em;">${p||"Total"}</th>
|
|
290
290
|
<td style="text-align: left; padding: 0 1em;">
|
|
291
|
-
${F(n/
|
|
291
|
+
${F(n/u).format({output:"percent",mantissa:2,trimMantissa:!0})}
|
|
292
292
|
</td>
|
|
293
293
|
</tr>
|
|
294
294
|
`)}),`
|
|
@@ -298,9 +298,9 @@ Check the top-level render call using <`+z+">.")}return D}}function dc(v,D){{if(
|
|
|
298
298
|
<table style="width: auto">
|
|
299
299
|
<tbody>${c.join("")}</tbody>
|
|
300
300
|
</table>
|
|
301
|
-
`}}function
|
|
302
|
-
`),no={columns:[],fontSize:"14px",highlightOnHover:!0,horizontalSpacing:"14px",id_field:"",striped:!0,use_raw_columns:!0,verticalSpacing:"14px"},so={left:"flex-start",center:"center",right:"flex-end"},tv=({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:so[n]},children:[e.isPlaceholder?null:Ge.flexRender(e.column.columnDef.header,e.getContext()),s.jsx(nv,{direction:e.column.getIsSorted()})]})},nv=({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}},sv=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"}})),rv={tableLayout:"fixed","thead, tbody":{tr:{"th, td":{padding:"2px 10px",div:{overflow:"hidden",textOverflow:"ellipsis"},"&:first-of-type":{paddingLeft:2,paddingRight:2}}}}},iv=a.createStyles((e,t)=>({content:{display:"flex",alignItems:"center",justifyContent:so[t.align],".table-cell-text":{whiteSpace:"nowrap",cursor:t.clickable?"pointer":"default",textDecoration:t.clickable?"underline":"none"}}}));function av(e){return e?nt(e).oklch()[0]>.7?"black":"white":"inherit"}function ov(e){const t=e.tableCellContext.bgColor;return{backgroundColor:t,color:av(t)}}function Bt(e){const t=e.tableCellContext.isClickable(),n=iv({clickable:t,align:e.align});return s.jsx("div",{className:n.classes.content,style:{...ov(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 lv(e){return s.jsx(Bt,{...e,children:e.value})}function cv(e){const t=F(e.value).format({average:!0,mantissa:2,trimMantissa:!0});return s.jsx(Bt,{...e,children:t})}function uv(e){const t=F(e.value).format({thousandSeparated:!0});return s.jsx(Bt,{...e,children:t})}function dv(e){const t=F(e.value).format({output:"percent",mantissa:3,trimMantissa:!0});return s.jsx(Bt,{...e,children:t})}function pv(e){const t=e.value,n=e.func_content;if(!n)return s.jsx(Bt,{...e,children:t});const r=new Function(`return ${n}`)()({value:t});return s.jsx(Bt,{...e,children:r})}function hv(e){switch(e.type){case Ye.string:return s.jsx(lv,{...e});case Ye.eloc:return s.jsx(cv,{...e});case Ye.number:return s.jsx(uv,{...e});case Ye.percentage:return s.jsx(dv,{...e});case Ye.custom:return s.jsx(pv,{...e})}}function xv({tableContainerRef:e,rows:t}){var c,u;const n=bc.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 p=t[d.index];return s.jsx("tr",{children:p.getVisibleCells().map(h=>s.jsx("td",{children:Ge.flexRender(h.column.columnDef.cell,h.getContext())},h.id))},p.id)}),l>0&&s.jsx("tr",{children:s.jsx("td",{style:{height:`${l}px`}})})]})}const ur={id:"builtin:table:click-cell-content",displayName:"Click Cell Content",nameRender:yv,configRender:gv,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"}]},fv={column:""};function ro(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=Rt(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 gv(e){const{columnsFromConfig:t,columnsFromData:n}=ro(e.instance,e.sampleData),r=t.length>0?t:n,{value:i,set:o}=$(e.trigger.triggerData,"config"),{column:l}=y.defaults({},i,fv),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 mv(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 yv(e){const{columnsFromConfig:t}=ro(e.instance),{value:n}=$(e.trigger.triggerData,"config");return s.jsx(a.Text,{children:mv(n,t)})}function io(e,t,n){return Math.min(Math.max(e,t),n)}class bv{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=io(n,0,this.steps.length-2),this.getLinearFunction(this.steps[n],this.steps[n+1])}mapValue(t){return io(this.getStepFunctionForValue(t)(t),0,100)}}class jv{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===ur.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 bv(t.steps).mapValue(n);return r==null?void 0:r.getColor(o)}}}const vv=e=>{const t=Ve(e),n=$e(t.triggerManager,ur.id),{colorManager:r}=f.useContext(et);return f.useCallback(i=>new jv(e.getColIndex,i,n,t,r),[n,t,e.getColIndex])};function wv({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:p,cx:h}=sv(),x=f.useMemo(()=>c?!Array.isArray(e)||e.length===0?[]:Object.keys(e[0]).map(fe=>({id:fe,label:fe,value_field:fe,value_type:Ye.string,align:"left",width:"",cellBackgroundColor:""})):u,[c,u,e]),m=vv({getColIndex:f.useCallback(fe=>x.indexOf(fe.column.columnDef.meta),[x]),vizManager:i.vizManager,instance:o}),j=f.useMemo(()=>{const fe=Ge.createColumnHelper();return x.map(Ke=>{const Fr=Pu(Ke.value_field);return fe.accessor(Fr.columnKey,{cell:rn=>s.jsx(hv,{tableCellContext:m(rn.cell),value:rn.getValue(),type:Ke.value_type,...Ke}),header:Ke.label,enableSorting:!0,meta:Ke,size:typeof Ke.width=="number"?Ke.width:void 0,minSize:typeof Ke.width=="number"?Ke.width:void 0})})},[x,m]),[w,T]=f.useState([]),M=Ge.useReactTable({data:e,state:{sorting:w},onSortingChange:T,columns:j,getCoreRowModel:Ge.getCoreRowModel(),getSortedRowModel:Ge.getSortedRowModel()}),{rows:P}=M.getRowModel(),U=f.useRef(null),se=P.length,Q=se>0,ie=Q?n-22:n,de=Q?22:0;return V.useWhyDidYouUpdate("VizTableComponent",{queryData:e,width:t,height:n,conf:r,context:i,instance:o,finalColumns:x,getCellContext:m,tableColumns:j,table:M,rows:P,tableContainerRef:U}),s.jsxs("div",{ref:U,style:{height:n,width:t,padding:"0 5px"},"data-enable-scrollbar":!0,className:h(p.root,{"table-highlight-on-hover":r.highlightOnHover}),children:[se>0&&s.jsx(a.Box,{className:p.info_bar,sx:{height:22},children:s.jsxs(a.Text,{align:"right",pr:6,size:14,color:"dimmed",fw:"normal",children:["Total: ",se]})}),s.jsxs(a.Table,{sx:{...rv,maxHeight:ie},...d,striped:r.striped,children:[s.jsx("thead",{className:p.thead,style:{top:de},children:M.getHeaderGroups().map(fe=>s.jsx("tr",{children:fe.headers.map(kt=>s.jsx("th",{style:{width:kt.getSize()},children:s.jsx(tv,{header:kt,cx:h})},kt.id))},fe.id))}),s.jsx(xv,{tableContainerRef:U,rows:P})]})]})}function Cv({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 p=A(l);return e[p.queryID]},[e,l]);return!Array.isArray(d)||d.length===0?s.jsx(a.Text,{color:"gray",align:"center",children:"Empty Data"}):s.jsx(wv,{queryData:d,width:t,height:n,conf:r,context:i,instance:o})}function Sv({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(Cv,{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 ao=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)"}}}})),_v=[{from:0,to:0},{from:100,to:100}];class kv{constructor(){E(this,"steps",new Map);E(this,"interpolation");E(this,"onChange");W.makeAutoObservable(this,{steps:W.observable},{deep:!1}),W.reaction(()=>W.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(_v):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 Tv(e){const{onChange:t,color:n,index:r,value:i}=e,{classes:o}=ao(),[l,c]=f.useState(i),[u,{setTrue:d,setFalse:p}]=V.useBoolean(!1),h=r%2===1,x=h&&i!=null,m=!h&&i!=null,j=`map ${i} to color ${r}`,w=()=>{c(i),p()},T=()=>{p(),t==null||t(l)},M=F(i).format({average:!0});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:M}),s.jsxs(a.Popover,{width:200,trapFocus:!0,opened:u,onClose:p,children:[s.jsx(a.Popover.Target,{children:s.jsx("div",{"data-testid":"palette-item-target",className:"palette-item",onClick:d,style:{"--shadow-color":nt(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:w,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:M})]})}const Dv=S.observer(({model:e})=>{const{classes:t}=ao(),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(Tv,{index:o,color:r,value:e.getStepFromValue(i),onChange:l=>e.changeStep(l,i)},r))})}),Iv=S.observer(function(t){const n=V.useCreation(()=>new kv,[]);return f.useEffect(()=>{n.fromProps(t)}),n.interpolation==null?null:s.jsx(Dv,{model:n})}),Mv=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:p}]=V.useBoolean(),h=i.map(T=>({label:T.displayName,value:r.encodeColor(T),group:T.category}));function x(T){T&&l(M=>({...M,interpolation:T}))}const m=()=>{p(),n==null||n(W.toJS(o))};function j(T){l(M=>({...M,steps:T}))}const w=()=>{p(),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:p,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:h,onChange:x,withinPortal:!0,zIndex:340,maxDropdownHeight:500}),s.jsx(Iv,{steps:o.steps,interpolation:c,onChange:j}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:w,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:m,children:"OK"})]})]})})]})},Av=["static","interpolation","none"].map(e=>({label:y.capitalize(e),value:e})),zv=[{from:0,to:0},{from:100,to:100}];function oo(e){return e?y.isString(e)?e==="none"?"none":"static":"interpolation":"none"}function Ev(e,t){var n;return oo(t)==="static"?t:(n=e.getStaticColors()[0])==null?void 0:n.value}function Pv(e,t){return y.isObject(t)?t:{steps:zv,interpolation:e.encodeColor(e.getColorInterpolations()[0])}}const Lv=f.forwardRef((e,t)=>{const{colorManager:n}=f.useContext(et),[r,i]=f.useState(oo(e.value)),[o,l]=f.useState(Ev(n,e.value)),c=V.useLatest(o),[u,d]=f.useState(Pv(n,e.value)),p=V.useLatest(u),h=j=>{var w,T,M;i(j||"none"),j==="static"?(w=e.onChange)==null||w.call(e,c.current):j==="none"||!j?(T=e.onChange)==null||T.call(e,"none"):(M=e.onChange)==null||M.call(e,p.current)},x=j=>{var w;l(j),(w=e.onChange)==null||w.call(e,j)},m=j=>{var w;d(j),(w=e.onChange)==null||w.call(e,j)};return s.jsxs(a.Stack,{align:"stretch",children:[s.jsx(a.Select,{label:"Cell background",value:r||"none",onChange:h,data:Av}),r==="static"&&s.jsx(Se,{value:o,onChange:x}),r==="interpolation"&&s.jsx(Mv,{colorManager:n,value:u,onChange:m})]})}),Ov={[Ye.eloc]:"ELOC"},Bv=Object.values(Ye).map(e=>({label:y.get(Ov,e,y.capitalize(e)),value:e})),$v=f.forwardRef(({label:e,value:t,onChange:n,sx:r},i)=>s.jsx(a.Select,{ref:i,label:e,data:Bv,value:t,onChange:n,sx:r})),Vv=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)},p=()=>{c(to)};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:h=>c(h??""),theme:"vs-dark",options:{minimap:{enabled:!1}}})}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:p,color:"red",leftIcon:s.jsx(_.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"})]})]})]})})]})}),Nv=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],dr=()=>s.jsx(a.Text,{color:"dimmed",size:12,children:"px"}),qv=({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($v,{label:"Value Type",sx:{flex:1},...l})}),o===Ye.custom&&s.jsx(b.Controller,{name:`columns.${t}.func_content`,control:e,render:({field:l})=>s.jsx(Vv,{value:l.value??to,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(dr,{}),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(dr,{}),...l})}),s.jsx(a.NumberInput,{hideControls:!0,label:"Max Width",rightSection:s.jsx(dr,{}),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:Nv,...l})})}),s.jsx(b.Controller,{name:`columns.${t}.cellBackgroundColor`,control:e,render:({field:l})=>s.jsx(Lv,{...l})}),s.jsx(a.Divider,{mb:4,mt:12,variant:"dashed"}),s.jsx(a.Button,{leftIcon:s.jsx(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(t),children:"Delete this column"})]})},Fv=({control:e,watch:t})=>{const{fields:n,append:r,remove:i,update:o}=b.useFieldArray({control:e,name:"columns"}),l=()=>{const u=oe.randomId();r({id:u,label:u,align:"center",value_field:"",value_type:Ye.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(_.Plus,{size:18,color:"#228be6"})})]}),n.map((u,d)=>s.jsx(a.Tabs.Panel,{value:d.toString(),children:s.jsx(qv,{control:e,watch:t,index:d,column:u,remove:i})},u.id))]})})]})};function Gv({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 Wv({columns:e,...t}){return{...t,columns:e.map(({id:n,...r})=>({id:n??oe.randomId(),...r}))}}function Rv({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},t,no),[t]),i=f.useMemo(()=>Wv(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 p=u(),h=f.useMemo(()=>!y.isEqual(p,r),[p,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:!h,children:s.jsx(_.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(Fv,{control:o,watch:c})]}),s.jsx(a.Tabs.Panel,{value:"Style",children:s.jsx(Gv,{control:o,watch:c})})]})]})}function Qv(e){const{columns:t,...n}=e;return{...e,columns:t.map(r=>({...r,align:r.align??"left"}))}}function Uv(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 Yv(e){const{columns:t,...n}=e;return{...n,columns:t.map(r=>({...r,align:r.align??"left",cellBackgroundColor:r.cellBackgroundColor??"",width:r.width??""}))}}class Kv extends re{constructor(){super(...arguments);E(this,"VERSION",5)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{columns:r,...i}=n.config;return{...n,version:2,config:{...i,columns:r.map(({id:o,...l})=>({id:o??oe.randomId(),...l}))}}}),this.version(3,n=>({...n,version:3,config:Qv(n.config)})),this.version(4,(n,r)=>({...n,version:4,config:Uv(n.config,r)})),this.version(5,n=>({...n,version:5,config:Yv(n.config)}))}}const pr={createConfig(){return{version:5,config:y.cloneDeep(no)}},displayName:"Table",displayGroup:"Others",migrator:new Kv,name:"table",viewRender:Sv,configRender:Rv,triggers:[ur]},lo=["function text({ data, variables, filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
|
|
303
|
-
`),hr={func_content:lo,horizontal_align:"left",font_size:"14px",font_weight:"normal"},Xv=S.observer(({context:e})=>{const t=le(),{value:n=hr}=$(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((h,x)=>{const m=it(x,i);return h[x.name]=Ne(x,m),h},{}),[r,i]),p=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:p})}),$n=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function Jv({label:e,value:t,onChange:n},r){var l;const[i,o]=f.useState(((l=$n.find(c=>c.label===t))==null?void 0:l.value)??$n[0].value);return f.useEffect(()=>{const c=$n.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:$n,value:i,onChange:o,step:25,placeholder:"Pick a font size",mx:"1em",ref:r})]})}const co=f.forwardRef(Jv),Zv=({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}}})})},Hv=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)},p=()=>{c(lo)};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(Zv,{value:l,onChange:c}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:p,color:"red",leftIcon:s.jsx(_.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"})]})]})]})})]})}),ew=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}];function tw({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},t,hr),[t]),i=f.useMemo(()=>{const{func_content:x,horizontal_align:m,font_size:j,font_weight:w}=r;return{func_content:x,horizontal_align:m,font_size:j,font_weight:w}},[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 p=u(),h=f.useMemo(()=>!y.isEqual(p,r),[p,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:!h,children:s.jsx(_.DeviceFloppy,{size:20})})]}),s.jsxs(a.Stack,{spacing:10,children:[s.jsx(b.Controller,{name:"func_content",control:o,render:({field:x})=>s.jsx(Hv,{...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:ew,...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(co,{label:"Font Weight",...x})})})]})]})})}class nw extends re{constructor(){super(...arguments);E(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const sw={displayName:"Text",displayGroup:"Others",migrator:new nw,name:"text",viewRender:Xv,configRender:tw,createConfig(){return{version:1,config:y.cloneDeep(hr)}}},rw=()=>s.jsxs("svg",{width:"64",height:"64",viewBox:"0 0 64 64",fill:"none",children:[s.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M22.49 27.79H14.47C13.55 27.79 12.81 28.53 12.81 29.45C12.81 30.37 13.55 31.11 14.47 31.11H22.49C23.41 31.11 24.15 30.37 24.15 29.45C24.15 28.54 23.41 27.79 22.49 27.79ZM34.32 31.28C35.22 31.32 35.7 31.82 35.74 32.76C35.78 33.54 35.37 34.3 34.51 35.04C33.52 35.9 33.03 36.95 33.03 38.19V38.81H34.82V38.25C34.78 37.59 35.07 37.02 35.68 36.52C37.12 35.41 37.82 34.15 37.78 32.75C37.66 30.53 36.5 29.35 34.32 29.23C32.3 29.23 31.05 30.46 30.55 32.93L32.53 33.55C32.82 32.04 33.42 31.28 34.32 31.28ZM35 39.93H32.84V42.21H35V39.93ZM14.83 36.42H18.54C19.46 36.42 20.2 37.17 20.2 38.08C20.2 39 19.46 39.74 18.54 39.74H10.52C9.6 39.74 8.86 39 8.86 38.08C8.86 37.61 9.06 37.19 9.37 36.89H5.66C4.74 36.89 4 36.15 4 35.23C4 34.31 4.74 33.57 5.66 33.57H13.68C14.6 33.57 15.34 34.31 15.34 35.23C15.34 35.7 15.14 36.12 14.83 36.42ZM50.94 36.85H58.74C59.66 36.85 60.4 37.59 60.41 38.51C60.41 39.43 59.67 40.17 58.75 40.17H54.26C54.56 40.47 54.74 40.88 54.74 41.34C54.74 42.26 54 43 53.08 43H50.94V36.85Z",fill:"#B8C0CC"}),s.jsx("path",{d:"M18.39 32.28H16.51V35.02H18.39V32.28Z",fill:"#9399A5"}),s.jsx("path",{d:"M46.87 15H20.69C18.38 15 16.5 16.88 16.5 19.19V26.22H18.38V23.45H49.18V47.68H18.38V41.07H16.5V49.55H51.05V19.19C51.06 16.88 49.18 15 46.87 15ZM39.46 20.73C38.81 20.73 38.29 20.2 38.29 19.56C38.29 18.92 38.82 18.39 39.46 18.39C40.11 18.39 40.63 18.92 40.63 19.56C40.63 20.2 40.11 20.73 39.46 20.73ZM43.22 20.73C42.57 20.73 42.05 20.2 42.05 19.56C42.05 18.92 42.58 18.39 43.22 18.39C43.87 18.39 44.39 18.92 44.39 19.56C44.39 20.2 43.87 20.73 43.22 20.73ZM46.97 20.73C46.32 20.73 45.8 20.2 45.8 19.56C45.8 18.92 46.33 18.39 46.97 18.39C47.62 18.39 48.14 18.92 48.14 19.56C48.14 20.2 47.62 20.73 46.97 20.73Z",fill:"#9399A5"})]});function uo(e,t){const n=y.get(e,t,"");if(n)throw new Error(n)}async function iw(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,tt(o).then(l=>l.data).catch(l=>Promise.reject(l))}const aw=({conf:e,panelData:t})=>async()=>{const{expertSystemURL:n,path:r,goal:i,question:o}=e;if(!r||!i||!o)return;const l=Lu(t);if(!l)return;const c={dashboard:i,panel:o,data:l};try{const u=n.startsWith("http")?n:window.location.origin;return await iw(u,`/expert/v3/devtable/${r}`,c,{})}catch(u){throw uo(u,"response.data.detail"),uo(u,"response.data.error"),console.error(u),u}},xr={expertSystemURL:"",path:"",goal:"",question:""},fr={height:"100%",overflowY:"auto",...Os},po=({message:e})=>s.jsx(a.Box,{sx:fr,children:s.jsx("div",{dangerouslySetInnerHTML:{__html:e},style:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45"}})}),ow=({error:e,width:t,height:n})=>{const r=e.message;if(r.startsWith("<"))return s.jsx(po,{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(rw,{}),s.jsx(po,{message:r})]})})};function lw({context:e}){const{value:t}=$(e.instanceData,"config"),n=f.useMemo(()=>y.defaultsDeep({},t,xr),[t]),{width:r,height:i}=e.viewport,o=e.data,{data:l,error:c,loading:u}=V.useRequest(aw({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:fr,"data-enable-scrollbar":!0,children:s.jsx(ow,{error:c,width:r,height:i})}):!l||!Array.isArray(l.replies)||l.replies.length===0?null:s.jsx(a.Box,{sx:fr,"data-enable-scrollbar":!0,children:l.replies.map((d,p)=>s.jsx("div",{dangerouslySetInnerHTML:{__html:d.interpretation.html}},p))})}function cw({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},t,xr),[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(),p=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:h})=>s.jsx(a.TextInput,{label:"Expert System URL",...h})}),s.jsx(b.Controller,{name:"path",control:i,render:({field:h})=>s.jsx(a.TextInput,{label:"Path",required:!0,...h})})]}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:"goal",control:i,render:({field:h})=>s.jsx(a.TextInput,{label:"Goal",required:!0,...h})}),s.jsx(b.Controller,{name:"question",control:i,render:({field:h})=>s.jsx(a.TextInput,{label:"Question",required:!0,...h})})]}),s.jsx(a.Divider,{variant:"dashed",mt:16,mb:8}),s.jsx(a.Button,{type:"submit",variant:"filled",color:"blue",leftIcon:s.jsx(_.DeviceFloppy,{size:20}),disabled:!p,sx:{alignSelf:"flex-end"},children:"Submit Changes"})]})})}class uw extends re{constructor(){super(...arguments);E(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const dw={displayName:"Merico GQM",displayGroup:"Merico suite",migrator:new uw,name:"mericoGQM",viewRender:lw,configRender:cw,createConfig(){return{version:1,config:y.cloneDeep(xr)}}};function pw(e,t,n){if(!e)return n[0];try{return[t,I(t).add(1,"year").subtract(1,"day").valueOf()]}catch(r){return console.error(r),n[0]}}function hw(e,t,n){const r=pw(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 xw(e){return{heat_block:function(r){if(!e.heat_block.value_formatter)return r;try{return F(r).format(e.heat_block.value_formatter)}catch(i){return console.error(i),r}}}}function fw(e,t){return{show:!e,selectedMode:"single",top:5,right:5,data:t.map(n=>({name:n,icon:"circle"}))}}function gw(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(p=>[y.get(p,l.columnKey),y.get(p,c.columnKey)])}))}const mw=e=>{try{return F(e).format({trimMantissa:!0,mantissa:2})}catch{return e}};function yw({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(p=>{const h=A(p.data_key);u.push({label:p.name,value:mw(y.get(d,h.columnKey,"")),style:{label:"",value:""}})}),u}function bw(e,t,n){const r=A(e.calendar.data_key),i=y.keyBy(t[r.queryID],r.columnKey);return{confine:!0,formatter:function(o){const c=yw({conf:e,valueFormatters:n,dataDict:i,params:o}).map(p=>`
|
|
301
|
+
`}}function qj(){return ne.getTooltip({trigger:"item",formatter:Nj()})}const Fj={tooltip:{show:!0},series:{type:"sunburst",radius:[0,"90%"],emphasis:{focus:"ancestor"}}};function Gj(e,t,n){n.reduce((o,l)=>{const c=it(l,t);return o[l.name]=Ne(l,c),o},{});const i={series:{data:Bj(e,t),levels:Vj(e)},tooltip:qj()};return y.defaultsDeep({},i,Fj)}Y.use([te.SunburstChart,Ce.CanvasRenderer]);function Wj({context:e}){const{variables:t}=e,{value:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaults({},n,cr),[n]),i=e.data,{width:o,height:l}=e.viewport,c=f.useMemo(()=>Gj(r,i,t),[r,i,t]);return!o||!l?null:s.jsx(De,{width:o,height:l,children:s.jsx(we,{echarts:Y,option:c,style:Wt(o,l),notMerge:!0,theme:"merico-light"})})}function Rj({control:e,watch:t}){return t(["label_key","value_key","group_key"]),s.jsxs(a.Stack,{children:[s.jsx(b.Controller,{name:"label_key",control:e,render:({field:n})=>s.jsx(B,{label:"Label Key",required:!0,...n})}),s.jsx(b.Controller,{name:"value_key",control:e,render:({field:n})=>s.jsx(B,{label:"Value Key",required:!0,...n})}),s.jsx(b.Controller,{name:"group_key",control:e,render:({field:n})=>s.jsx(B,{label:"Group Key",clearable:!0,...n})})]})}const Qj=[{label:"Radial",value:"radial"},{label:"Tangential",value:"tangential"},{label:"None",value:"0"}],Uj=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Yj=({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:Qj,...r})}),s.jsx(b.Controller,{name:`levels.${t}.label.align`,control:e,render:({field:r})=>s.jsx(a.Select,{label:"Align",data:Uj,...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(er,{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(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Level"})]}),Kj=({control:e,watch:t})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"levels"}),o=t("levels"),l=n.map((h,x)=>({...h,...o[x]})),c=()=>r({id:Date.now().toString(),r0:"",r:"",label:{show_label_tolerance:.001,rotate:"0",align:"center",position:"inside",padding:0}}),d=t("levels.0.id"),[u,p]=f.useState(()=>d??null);return f.useEffect(()=>{d&&p(h=>h!==null?h:d)},[d]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(_.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:u,onTabChange:h=>p(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((h,x)=>s.jsx(a.Tabs.Tab,{value:h.id,children:x},h.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),l.map((h,x)=>s.jsx(a.Tabs.Panel,{value:h.id,children:s.jsx(Yj,{control:e,index:x,remove:i},h.id)},h.id))]})]})};function Xj({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},t,cr),[t]),i=f.useMemo(()=>y.clone(r),[r]),{control:o,handleSubmit:l,watch:c,getValues:d,reset:u}=b.useForm({defaultValues:i});f.useEffect(()=>{u(i)},[i]);const p=d(),h=f.useMemo(()=>!y.isEqual(p,r),[p,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:!h,children:s.jsx(_.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(Rj,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Levels",children:s.jsx(Kj,{control:o,watch:c})})]})]})})}function Jj(e){const{label_field:t,value_field:n,...r}=e;return{...r,label_key:t,value_key:n}}function Zj(e){const{group_key:t="",...n}=e;return{...n,group_key:t}}function Hj(e){const{levels:t=[],...n}=e;return{...n,levels:t}}function ev(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}`,{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 tv extends ie{constructor(){super(...arguments);E(this,"VERSION",5)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:Jj(n.config)})),this.version(3,n=>({...n,version:3,config:Zj(n.config)})),this.version(4,n=>({...n,version:4,config:Hj(n.config)})),this.version(5,(n,r)=>({...n,version:5,config:ev(n.config,r)}))}}const nv={displayName:"Sunburst Chart",displayGroup:"ECharts-based charts",migrator:new tv,name:"sunburst",viewRender:Wj,configRender:Xj,createConfig(){return{version:5,config:y.cloneDeep(cr)}}};var Ye=(e=>(e.string="string",e.number="number",e.eloc="eloc",e.percentage="percentage",e.custom="custom",e))(Ye||{});const no=["function text({ value }) {"," // your code goes here"," return value","}"].join(`
|
|
302
|
+
`),so={columns:[],fontSize:"14px",highlightOnHover:!0,horizontalSpacing:"14px",id_field:"",striped:!0,use_raw_columns:!0,verticalSpacing:"14px"},ro={left:"flex-start",center:"center",right:"flex-end"},sv=({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:ro[n]},children:[e.isPlaceholder?null:Ge.flexRender(e.column.columnDef.header,e.getContext()),s.jsx(rv,{direction:e.column.getIsSorted()})]})},rv=({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}},iv=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"}})),av={tableLayout:"fixed","thead, tbody":{tr:{"th, td":{padding:"2px 10px",div:{overflow:"hidden",textOverflow:"ellipsis"},"&:first-of-type":{paddingLeft:2,paddingRight:2}}}}},ov=a.createStyles((e,t)=>({content:{display:"flex",alignItems:"center",justifyContent:ro[t.align],".table-cell-text":{whiteSpace:"nowrap",cursor:t.clickable?"pointer":"default",textDecoration:t.clickable?"underline":"none"}}}));function lv(e){return e?nt(e).oklch()[0]>.7?"black":"white":"inherit"}function cv(e){const t=e.tableCellContext.bgColor;return{backgroundColor:t,color:lv(t)}}function Bt(e){const t=e.tableCellContext.isClickable(),n=ov({clickable:t,align:e.align});return s.jsx("div",{className:n.classes.content,style:{...cv(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 dv(e){return s.jsx(Bt,{...e,children:e.value})}function uv(e){const t=F(e.value).format({average:!0,mantissa:2,trimMantissa:!0});return s.jsx(Bt,{...e,children:t})}function pv(e){const t=F(e.value).format({thousandSeparated:!0});return s.jsx(Bt,{...e,children:t})}function hv(e){const t=F(e.value).format({output:"percent",mantissa:3,trimMantissa:!0});return s.jsx(Bt,{...e,children:t})}function xv(e){const t=e.value,n=e.func_content;if(!n)return s.jsx(Bt,{...e,children:t});const r=new Function(`return ${n}`)()({value:t});return s.jsx(Bt,{...e,children:r})}function fv(e){switch(e.type){case Ye.string:return s.jsx(dv,{...e});case Ye.eloc:return s.jsx(uv,{...e});case Ye.number:return s.jsx(pv,{...e});case Ye.percentage:return s.jsx(hv,{...e});case Ye.custom:return s.jsx(xv,{...e})}}function gv({tableContainerRef:e,rows:t}){var c,d;const n=jc.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-(((d=r==null?void 0:r[r.length-1])==null?void 0:d.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(u=>{const p=t[u.index];return s.jsx("tr",{children:p.getVisibleCells().map(h=>s.jsx("td",{children:Ge.flexRender(h.column.columnDef.cell,h.getContext())},h.id))},p.id)}),l>0&&s.jsx("tr",{children:s.jsx("td",{style:{height:`${l}px`}})})]})}const dr={id:"builtin:table:click-cell-content",displayName:"Click Cell Content",nameRender:jv,configRender:yv,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"}]},mv={column:""};function io(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=Rt(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 yv(e){const{columnsFromConfig:t,columnsFromData:n}=io(e.instance,e.sampleData),r=t.length>0?t:n,{value:i,set:o}=$(e.trigger.triggerData,"config"),{column:l}=y.defaults({},i,mv),c=d=>{isNaN(+d)?o({column:d}):o({column:+d})};return s.jsx(a.Select,{clearable:!1,data:r,label:"Choose a column",value:l.toString(),onChange:c})}function bv(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 jv(e){const{columnsFromConfig:t}=io(e.instance),{value:n}=$(e.trigger.triggerData,"config");return s.jsx(a.Text,{children:bv(n,t)})}function ao(e,t,n){return Math.min(Math.max(e,t),n)}class vv{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=ao(n,0,this.steps.length-2),this.getLinearFunction(this.steps[n],this.steps[n+1])}mapValue(t){return ao(this.getStepFunctionForValue(t)(t),0,100)}}class wv{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===dr.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 vv(t.steps).mapValue(n);return r==null?void 0:r.getColor(o)}}}const Cv=e=>{const t=Ve(e),n=$e(t.triggerManager,dr.id),{colorManager:r}=f.useContext(et);return f.useCallback(i=>new wv(e.getColIndex,i,n,t,r),[n,t,e.getColIndex])};function Sv({queryData:e,width:t,height:n,conf:r,context:i,instance:o}){const{id_field:l,use_raw_columns:c,columns:d,...u}=r,{classes:p,cx:h}=iv(),x=f.useMemo(()=>c?!Array.isArray(e)||e.length===0?[]:Object.keys(e[0]).map(ge=>({id:ge,label:ge,value_field:ge,value_type:Ye.string,align:"left",width:"",cellBackgroundColor:""})):d,[c,d,e]),m=Cv({getColIndex:f.useCallback(ge=>x.indexOf(ge.column.columnDef.meta),[x]),vizManager:i.vizManager,instance:o}),j=f.useMemo(()=>{const ge=Ge.createColumnHelper();return x.map(Ke=>{const Fr=Ld(Ke.value_field);return ge.accessor(Fr.columnKey,{cell:rn=>s.jsx(fv,{tableCellContext:m(rn.cell),value:rn.getValue(),type:Ke.value_type,...Ke}),header:Ke.label,enableSorting:!0,meta:Ke,size:typeof Ke.width=="number"?Ke.width:void 0,minSize:typeof Ke.width=="number"?Ke.width:void 0})})},[x,m]),[w,T]=f.useState([]),M=Ge.useReactTable({data:e,state:{sorting:w},onSortingChange:T,columns:j,getCoreRowModel:Ge.getCoreRowModel(),getSortedRowModel:Ge.getSortedRowModel()}),{rows:P}=M.getRowModel(),U=f.useRef(null),re=P.length,Q=re>0,ae=Q?n-22:n,pe=Q?22:0;return V.useWhyDidYouUpdate("VizTableComponent",{queryData:e,width:t,height:n,conf:r,context:i,instance:o,finalColumns:x,getCellContext:m,tableColumns:j,table:M,rows:P,tableContainerRef:U}),s.jsxs("div",{ref:U,style:{height:n,width:t,padding:"0 5px"},"data-enable-scrollbar":!0,className:h(p.root,{"table-highlight-on-hover":r.highlightOnHover}),children:[re>0&&s.jsx(a.Box,{className:p.info_bar,sx:{height:22},children:s.jsxs(a.Text,{align:"right",pr:6,size:14,color:"dimmed",fw:"normal",children:["Total: ",re]})}),s.jsxs(a.Table,{sx:{...av,maxHeight:ae},...u,striped:r.striped,children:[s.jsx("thead",{className:p.thead,style:{top:pe},children:M.getHeaderGroups().map(ge=>s.jsx("tr",{children:ge.headers.map(kt=>s.jsx("th",{style:{width:kt.getSize()},children:s.jsx(sv,{header:kt,cx:h})},kt.id))},ge.id))}),s.jsx(gv,{tableContainerRef:U,rows:P})]})]})}function _v({data:e,width:t,height:n,conf:r,context:i,instance:o}){const{id_field:l,use_raw_columns:c,columns:d}=r,u=f.useMemo(()=>{if(!l)return[];const p=A(l);return e[p.queryID]},[e,l]);return!Array.isArray(u)||u.length===0?s.jsx(a.Text,{color:"gray",align:"center",children:"Empty Data"}):s.jsx(Sv,{queryData:u,width:t,height:n,conf:r,context:i,instance:o})}function kv({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(_v,{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 oo=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)"}}}})),Tv=[{from:0,to:0},{from:100,to:100}];class Dv{constructor(){E(this,"steps",new Map);E(this,"interpolation");E(this,"onChange");W.makeAutoObservable(this,{steps:W.observable},{deep:!1}),W.reaction(()=>W.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(Tv):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 Iv(e){const{onChange:t,color:n,index:r,value:i}=e,{classes:o}=oo(),[l,c]=f.useState(i),[d,{setTrue:u,setFalse:p}]=V.useBoolean(!1),h=r%2===1,x=h&&i!=null,m=!h&&i!=null,j=`map ${i} to color ${r}`,w=()=>{c(i),p()},T=()=>{p(),t==null||t(l)},M=F(i).format({average:!0});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:M}),s.jsxs(a.Popover,{width:200,trapFocus:!0,opened:d,onClose:p,children:[s.jsx(a.Popover.Target,{children:s.jsx("div",{"data-testid":"palette-item-target",className:"palette-item",onClick:u,style:{"--shadow-color":nt(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:w,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:M})]})}const Mv=S.observer(({model:e})=>{const{classes:t}=oo(),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(Iv,{index:o,color:r,value:e.getStepFromValue(i),onChange:l=>e.changeStep(l,i)},r))})}),Av=S.observer(function(t){const n=V.useCreation(()=>new Dv,[]);return f.useEffect(()=>{n.fromProps(t)}),n.interpolation==null?null:s.jsx(Mv,{model:n})}),zv=e=>{const{value:t,onChange:n,colorManager:r}=e,i=r.getColorInterpolations(),[o,l]=f.useState(t),c=r.decodeInterpolation(o.interpolation)||i[0],[d,{setTrue:u,setFalse:p}]=V.useBoolean(),h=i.map(T=>({label:T.displayName,value:r.encodeColor(T),group:T.category}));function x(T){T&&l(M=>({...M,interpolation:T}))}const m=()=>{p(),n==null||n(W.toJS(o))};function j(T){l(M=>({...M,steps:T}))}const w=()=>{p(),l(t)};return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"outline",onClick:u,children:c==null?void 0:c.displayName}),s.jsx(a.Modal,{size:508,title:"Setup color interpolation",opened:d,onClose:p,zIndex:320,children:d&&s.jsxs(a.Stack,{"data-testid":"color-interpolation-modal",children:[s.jsx(a.Select,{label:"Color style",value:o.interpolation,data:h,onChange:x,withinPortal:!0,zIndex:340,maxDropdownHeight:500}),s.jsx(Av,{steps:o.steps,interpolation:c,onChange:j}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:w,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:m,children:"OK"})]})]})})]})},Ev=["static","interpolation","none"].map(e=>({label:y.capitalize(e),value:e})),Pv=[{from:0,to:0},{from:100,to:100}];function lo(e){return e?y.isString(e)?e==="none"?"none":"static":"interpolation":"none"}function Lv(e,t){var n;return lo(t)==="static"?t:(n=e.getStaticColors()[0])==null?void 0:n.value}function Ov(e,t){return y.isObject(t)?t:{steps:Pv,interpolation:e.encodeColor(e.getColorInterpolations()[0])}}const Bv=f.forwardRef((e,t)=>{const{colorManager:n}=f.useContext(et),[r,i]=f.useState(lo(e.value)),[o,l]=f.useState(Lv(n,e.value)),c=V.useLatest(o),[d,u]=f.useState(Ov(n,e.value)),p=V.useLatest(d),h=j=>{var w,T,M;i(j||"none"),j==="static"?(w=e.onChange)==null||w.call(e,c.current):j==="none"||!j?(T=e.onChange)==null||T.call(e,"none"):(M=e.onChange)==null||M.call(e,p.current)},x=j=>{var w;l(j),(w=e.onChange)==null||w.call(e,j)},m=j=>{var w;u(j),(w=e.onChange)==null||w.call(e,j)};return s.jsxs(a.Stack,{align:"stretch",children:[s.jsx(a.Select,{label:"Cell background",value:r||"none",onChange:h,data:Ev}),r==="static"&&s.jsx(_e,{value:o,onChange:x}),r==="interpolation"&&s.jsx(zv,{colorManager:n,value:d,onChange:m})]})}),$v={[Ye.eloc]:"ELOC"},Vv=Object.values(Ye).map(e=>({label:y.get($v,e,y.capitalize(e)),value:e})),Nv=f.forwardRef(({label:e,value:t,onChange:n,sx:r},i)=>s.jsx(a.Select,{ref:i,label:e,data:Vv,value:t,onChange:n,sx:r})),qv=f.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:i,setFalse:o}]=V.useBoolean(),[l,c]=f.useState(e),d=()=>{o(),t(l)},u=()=>{o(),c(e)},p=()=>{c(no)};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(me,{height:"500px",defaultLanguage:"javascript",value:l,onChange:h=>c(h??""),theme:"vs-dark",options:{minimap:{enabled:!1}}})}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:p,color:"red",leftIcon:s.jsx(_.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:d,children:"OK"})]})]})]})})]})}),Fv=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],ur=()=>s.jsx(a.Text,{color:"dimmed",size:12,children:"px"}),Gv=({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(Nv,{label:"Value Type",sx:{flex:1},...l})}),o===Ye.custom&&s.jsx(b.Controller,{name:`columns.${t}.func_content`,control:e,render:({field:l})=>s.jsx(qv,{value:l.value??no,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(ur,{}),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(ur,{}),...l})}),s.jsx(a.NumberInput,{hideControls:!0,label:"Max Width",rightSection:s.jsx(ur,{}),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:Fv,...l})})}),s.jsx(b.Controller,{name:`columns.${t}.cellBackgroundColor`,control:e,render:({field:l})=>s.jsx(Bv,{...l})}),s.jsx(a.Divider,{mb:4,mt:12,variant:"dashed"}),s.jsx(a.Button,{leftIcon:s.jsx(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(t),children:"Delete this column"})]})},Wv=({control:e,watch:t})=>{const{fields:n,append:r,remove:i,update:o}=b.useFieldArray({control:e,name:"columns"}),l=()=>{const d=le.randomId();r({id:d,label:d,align:"center",value_field:"",value_type:Ye.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:d})=>s.jsx(a.Switch,{mt:20,mb:20,label:"Use Original Data Columns",checked:d.value,onChange:u=>d.onChange(u.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((d,u)=>s.jsx(a.Tabs.Tab,{value:u.toString(),children:u+1},d.id)),s.jsx(a.Tabs.Tab,{onClick:l,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),n.map((d,u)=>s.jsx(a.Tabs.Panel,{value:u.toString(),children:s.jsx(Gv,{control:e,watch:t,index:u,column:d,remove:i})},d.id))]})})]})};function Rv({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 Qv({columns:e,...t}){return{...t,columns:e.map(({id:n,...r})=>({id:n??le.randomId(),...r}))}}function Uv({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},t,so),[t]),i=f.useMemo(()=>Qv(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:d,reset:u}=b.useForm({defaultValues:i});f.useEffect(()=>{u(i)},[i]);const p=d(),h=f.useMemo(()=>!y.isEqual(p,r),[p,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:!h,children:s.jsx(_.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(Wv,{control:o,watch:c})]}),s.jsx(a.Tabs.Panel,{value:"Style",children:s.jsx(Rv,{control:o,watch:c})})]})]})}function Yv(e){const{columns:t,...n}=e;return{...e,columns:t.map(r=>({...r,align:r.align??"left"}))}}function Kv(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{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 Xv(e){const{columns:t,...n}=e;return{...n,columns:t.map(r=>({...r,align:r.align??"left",cellBackgroundColor:r.cellBackgroundColor??"",width:r.width??""}))}}class Jv extends ie{constructor(){super(...arguments);E(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??le.randomId(),...l}))}}}),this.version(3,n=>({...n,version:3,config:Yv(n.config)})),this.version(4,(n,r)=>({...n,version:4,config:Kv(n.config,r)})),this.version(5,n=>({...n,version:5,config:Xv(n.config)}))}}const pr={createConfig(){return{version:5,config:y.cloneDeep(so)}},displayName:"Table",displayGroup:"Others",migrator:new Jv,name:"table",viewRender:kv,configRender:Uv,triggers:[dr]},co=["function text({ data, variables, filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
|
|
303
|
+
`),hr={func_content:co,horizontal_align:"left",font_size:"14px",font_weight:"normal"},Zv=S.observer(({context:e})=>{const t=ce(),{value:n=hr}=$(e.instanceData,"config"),{variables:r}=e,i=e.data,{func_content:o,horizontal_align:l,font_size:c,font_weight:d}=n,u=f.useMemo(()=>r.reduce((h,x)=>{const m=it(x,i);return h[x.name]=Ne(x,m),h},{}),[r,i]),p=f.useMemo(()=>new Function(`return ${o}`)()({data:i,variables:u,filters:t.payloadForSQL.filters,context:t.payloadForSQL.context}),[o,i,u,t.payloadForSQL]);return s.jsx(a.Text,{align:l,weight:d,sx:{fontSize:c},children:p})}),$n=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function Hv({label:e,value:t,onChange:n},r){var l;const[i,o]=f.useState(((l=$n.find(c=>c.label===t))==null?void 0:l.value)??$n[0].value);return f.useEffect(()=>{const c=$n.find(d=>d.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:$n,value:i,onChange:o,step:25,placeholder:"Pick a font size",mx:"1em",ref:r})]})}const uo=f.forwardRef(Hv),ew=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return s.jsx(a.Box,{sx:{position:"relative"},children:s.jsx(me,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},tw=f.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:i,setFalse:o}]=V.useBoolean(),[l,c]=f.useState(e),d=()=>{o(),t(l)},u=()=>{o(),c(e)},p=()=>{c(co)};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(ew,{value:l,onChange:c}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:p,color:"red",leftIcon:s.jsx(_.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:d,children:"OK"})]})]})]})})]})}),nw=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}];function sw({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},t,hr),[t]),i=f.useMemo(()=>{const{func_content:x,horizontal_align:m,font_size:j,font_weight:w}=r;return{func_content:x,horizontal_align:m,font_size:j,font_weight:w}},[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:d,reset:u}=b.useForm({defaultValues:i});f.useEffect(()=>{u(i)},[i]),c(["func_content","horizontal_align","font_size","font_weight"]);const p=d(),h=f.useMemo(()=>!y.isEqual(p,r),[p,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:!h,children:s.jsx(_.DeviceFloppy,{size:20})})]}),s.jsxs(a.Stack,{spacing:10,children:[s.jsx(b.Controller,{name:"func_content",control:o,render:({field:x})=>s.jsx(tw,{...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:nw,...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 rw extends ie{constructor(){super(...arguments);E(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const iw={displayName:"Text",displayGroup:"Others",migrator:new rw,name:"text",viewRender:Zv,configRender:sw,createConfig(){return{version:1,config:y.cloneDeep(hr)}}},aw=()=>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 po(e,t){const n=y.get(e,t,"");if(n)throw new Error(n)}async function ow(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,tt(o).then(l=>l.data).catch(l=>Promise.reject(l))}const lw=({conf:e,panelData:t})=>async()=>{const{expertSystemURL:n,path:r,goal:i,question:o}=e;if(!r||!i||!o)return;const l=Od(t);if(!l)return;const c={dashboard:i,panel:o,data:l};try{const d=n.startsWith("http")?n:window.location.origin;return await ow(d,`/expert/v3/devtable/${r}`,c,{})}catch(d){throw po(d,"response.data.detail"),po(d,"response.data.error"),console.error(d),d}},xr={expertSystemURL:"",path:"",goal:"",question:""},fr={height:"100%",overflowY:"auto",...Os},ho=({message:e})=>s.jsx(a.Box,{sx:fr,children:s.jsx("div",{dangerouslySetInnerHTML:{__html:e},style:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45"}})}),cw=({error:e,width:t,height:n})=>{const r=e.message;if(r.startsWith("<"))return s.jsx(ho,{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(aw,{}),s.jsx(ho,{message:r})]})})};function dw({context:e}){const{value:t}=$(e.instanceData,"config"),n=f.useMemo(()=>y.defaultsDeep({},t,xr),[t]),{width:r,height:i}=e.viewport,o=e.data,{data:l,error:c,loading:d}=V.useRequest(lw({conf:n,panelData:o}),{refreshDeps:[o,n]});return!r||!i||!n?null:d?s.jsx(a.Box,{sx:{position:"relative",height:i},children:s.jsx(a.LoadingOverlay,{visible:!0})}):c?s.jsx(a.Box,{sx:fr,"data-enable-scrollbar":!0,children:s.jsx(cw,{error:c,width:r,height:i})}):!l||!Array.isArray(l.replies)||l.replies.length===0?null:s.jsx(a.Box,{sx:fr,"data-enable-scrollbar":!0,children:l.replies.map((u,p)=>s.jsx("div",{dangerouslySetInnerHTML:{__html:u.interpretation.html}},p))})}function uw({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},t,xr),[t]),{control:i,handleSubmit:o,watch:l,getValues:c,reset:d}=b.useForm({defaultValues:r});f.useEffect(()=>{d(r)},[r]),l(["expertSystemURL","goal","path","question"]);const u=c(),p=f.useMemo(()=>!y.isEqual(u,r),[u,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:h})=>s.jsx(a.TextInput,{label:"Expert System URL",...h})}),s.jsx(b.Controller,{name:"path",control:i,render:({field:h})=>s.jsx(a.TextInput,{label:"Path",required:!0,...h})})]}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:"goal",control:i,render:({field:h})=>s.jsx(a.TextInput,{label:"Goal",required:!0,...h})}),s.jsx(b.Controller,{name:"question",control:i,render:({field:h})=>s.jsx(a.TextInput,{label:"Question",required:!0,...h})})]}),s.jsx(a.Divider,{variant:"dashed",mt:16,mb:8}),s.jsx(a.Button,{type:"submit",variant:"filled",color:"blue",leftIcon:s.jsx(_.DeviceFloppy,{size:20}),disabled:!p,sx:{alignSelf:"flex-end"},children:"Submit Changes"})]})})}class pw extends ie{constructor(){super(...arguments);E(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const hw={displayName:"Merico GQM",displayGroup:"Merico suite",migrator:new pw,name:"mericoGQM",viewRender:dw,configRender:uw,createConfig(){return{version:1,config:y.cloneDeep(xr)}}};function xw(e,t,n){if(!e)return n[0];try{return[t,I(t).add(1,"year").subtract(1,"day").valueOf()]}catch(r){return console.error(r),n[0]}}function fw(e,t,n){const r=xw(e,t,n);return{top:50,left:25,right:5,cellSize:["auto",13],range:r,itemStyle:{borderColor:"#eee"},splitLine:{show:!0},dayLabel:{firstDay:1},monthLabel:{position:"end"},yearLabel:{show:!0}}}function gw(e){return{heat_block:function(r){if(!e.heat_block.value_formatter)return r;try{return F(r).format(e.heat_block.value_formatter)}catch(i){return console.error(i),r}}}}function mw(e,t){return{show:!e,selectedMode:"single",top:5,right:5,data:t.map(n=>({name:n,icon:"circle"}))}}function yw(e,t,n,r){const{calendar: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(d=>[y.get(d,l.columnKey),y.get(d,c.columnKey)])}:Object.entries(n).map(([d,u])=>({type:"heatmap",name:d,coordinateSystem:"calendar",calendarIndex:0,data:u.map(p=>[y.get(p,l.columnKey),y.get(p,c.columnKey)])}))}const bw=e=>{try{return F(e).format({trimMantissa:!0,mantissa:2})}catch{return e}};function jw({conf:e,valueFormatters:t,dataDict:n,params:r}){const{value:i}=r,[o,l]=i,d=[{label:e.heat_block.name,value:t.heat_block(l),style:{label:"",value:""}}],u=n[o];return u&&e.tooltip.metrics.forEach(p=>{const h=A(p.data_key);d.push({label:p.name,value:bw(y.get(u,h.columnKey,"")),style:{label:"",value:""}})}),d}function vw(e,t,n){const r=A(e.calendar.data_key),i=y.keyBy(t[r.queryID],r.columnKey);return ne.getTooltip({formatter:function(o){const c=jw({conf:e,valueFormatters:n,dataDict:i,params:o}).map(p=>`
|
|
304
304
|
<tr>
|
|
305
305
|
<th style="text-align: right;">
|
|
306
306
|
<div style="${p.style.label}">${p.label}</div>
|
|
@@ -309,7 +309,7 @@ Check the top-level render call using <`+z+">.")}return D}}function dc(v,D){{if(
|
|
|
309
309
|
<div style="${p.style.value}">${p.value}
|
|
310
310
|
</td>
|
|
311
311
|
</tr>
|
|
312
|
-
`),
|
|
312
|
+
`),d=y.get(o.value,0);return`
|
|
313
313
|
<table style="width: auto">
|
|
314
314
|
<thead>
|
|
315
315
|
<tr colspan="2">
|
|
@@ -320,28 +320,28 @@ Check the top-level render call using <`+z+">.")}return D}}function dc(v,D){{if(
|
|
|
320
320
|
</tr>
|
|
321
321
|
<tr>
|
|
322
322
|
<th colspan="2" style="text-align: center;">
|
|
323
|
-
<div>${
|
|
323
|
+
<div>${d}</div>
|
|
324
324
|
</th>
|
|
325
325
|
</tr>
|
|
326
326
|
</thead>
|
|
327
327
|
<tbody>${c.join("")}</tbody>
|
|
328
328
|
</table>
|
|
329
|
-
`}}}function jw(e,t,n){const r=Ot(e.heat_block.min,n),i=Ot(e.heat_block.max,n);return{min:r,max:i,calculable:!0,orient:"horizontal",left:t?"center":5,top:0,itemWidth:15}}const vw={tooltip:{confine:!0},grid:{containLabel:!0}},ww=e=>I(e).get("year");function Cw(e,t){const n=A(e.calendar.data_key),r=t[n.queryID],i=y.groupBy(r,d=>ww(d[n.columnKey])),o=Object.keys(i),l=r.map(d=>I(d[n.columnKey]).valueOf()),c=y.min(l),u=y.max(l);return{minDate:c??0,maxDate:u??0,dateSpan:I(u).diff(c,"day"),dataByYear:i,years:o}}function Sw(e,t,n){const r=n.reduce((h,x)=>{const m=it(x,t);return h[x.name]=Ne(x,m),h},{}),i=xw(e),{dateSpan:o,minDate:l,dataByYear:c,years:u}=Cw(e,t),d=o<=366,p={calendar:hw(d,l,u),series:gw(e,d,c,t),tooltip:bw(e,t,i),visualMap:jw(e,d,r),legend:fw(d,u)};return y.defaultsDeep({},p,vw)}function _w(e){return s.jsx(s.Fragment,{})}function kw(e){return s.jsx(a.Text,{children:"Click heat block"})}const ho={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:kw,configRender:_w,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"}]},gr={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:[]}};Y.use([O.DataZoomComponent,te.BarChart,te.LineChart,te.HeatmapChart,O.CalendarComponent,O.GridComponent,O.LegendComponent,O.TooltipComponent,O.VisualMapComponent,we.CanvasRenderer]);function Tw({name:e},t){const n=t.getOption();n.calendar.forEach(r=>{r.range=e}),t.setOption(n)}function Dw({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const l=mt(t,e.calendar.data_key),c=$e(i.triggerManager,ho.id),u=f.useCallback(h=>{const[x,m]=h.value,j=y.get(l,x,{error:"rowData is not found"});c.forEach(w=>{i.runInteraction(w.id,{...h,rowData:j})})},[l,c,i]),d=f.useMemo(()=>({click:u,legendselectchanged:Tw}),[u]),p=f.useMemo(()=>Sw(e,t,o),[e,t]);return s.jsx(ve,{echarts:Y,option:p,style:{width:n,height:r},onEvents:d,notMerge:!0,opts:{locale:e.calendar.locale},theme:"merico-light"})}function Iw({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,gr),[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(Dw,{variables:i,width:We(c),height:Re(u),data:l,conf:o,interactionManager:n})})}function Mw({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(Lt,{label:"Min Value",...n})}),s.jsx(b.Controller,{name:"heat_block.max",control:e,render:({field:n})=>s.jsx(Lt,{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(Oe,{...n})})]})}const Aw=({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(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),zw=({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((h,x)=>({...h,...o[x]})),c=()=>r({id:Date.now().toString(),data_key:"",name:""}),u=t("tooltip.metrics.0.id"),[d,p]=f.useState(()=>u??null);return f.useEffect(()=>{u&&p(h=>h!==null?h:u)},[u]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(_.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:h=>p(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((h,x)=>s.jsx(a.Tabs.Tab,{value:h.id,children:h.name?h.name:x},h.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),l.map((h,x)=>s.jsx(a.Tabs.Panel,{value:h.id,children:s.jsx(Aw,{control:e,index:x,remove:i},h.id)},h.id))]})]})};function Ew({control:e,watch:t}){return s.jsx(zw,{control:e,watch:t})}const Pw=[{label:"Chinese",value:"ZH"},{label:"English",value:"EN"}];function Lw({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:Pw,sx:{flex:1},...n})})]})}function Ow({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},t,gr),[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 p=u(),h=f.useMemo(()=>!y.isEqual(p,r),[p,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:!h,children:s.jsx(_.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(Lw,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Heat Block",children:s.jsx(Mw,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(Ew,{control:o,watch:c})})]})]})})}function Bw(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 $w(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 Vw extends re{constructor(){super(...arguments);E(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>({...n,version:2,config:Bw(n.config,r)})),this.version(3,n=>({...n,version:3,config:$w(n.config)}))}}const Nw={displayName:"Heatmap(Calendar)",displayGroup:"ECharts-based charts",migrator:new Vw,name:"calendarHeatmap",viewRender:Iw,configRender:Ow,createConfig:()=>({version:3,config:gr}),triggers:[ho]},mr={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:Ae},nameAlignment:"center"},series:[],tooltip:{metrics:[]},reference_lines:[]};function qw(){const e=new Date().getTime().toString();return{id:e,min:"",max:"",name:e,data_key:"",position:"bottom",label_formatter:ye,show:!0}}function Fw(){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 Gw(){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 Ww(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 Rw(e){switch(e){case"bar":return"roundRect";case"scatter":return"circle"}}function Qw(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:Rw(r)})),t}function Uw(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?gn(i.template,t,r):""},position:c}}}})}function Vn(e,t,n){const r=rt(e,t),i=rt(e,n);return y.zip(i,r)}function Yw(e,t,n,r){const i=Vn(t,n,r);return y.unionBy(i,e,0)}function Kw({dataTemplate:e,data:t,name_data_key:n,value_data_key:r,valueTypedXAxis:i}){return i?Yw(e,t,n,r):Vn(t,n,r)}function Xw({dataTemplate:e,data:t,aggregation_on_value:n,name_data_key:r,value_data_key:i,valueTypedXAxis:o}){if(!n||n.type==="none")return Kw({dataTemplate:e,data:t,name_data_key:r,value_data_key:i,valueTypedXAxis:o});const l=Vn(t,r,i),c=y.groupBy(l,"0");return e.map(([d])=>{const h=c[d].map(m=>m[1]),x=Ss(h,n);return[d,x]})}function Jw({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]=Vn({[i]:u},r,n)}),l}function Zw({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:p,id:h,...x},m,j,w,T,M){const P={label:{show:!!r,position:r,formatter:M[n??"default"]},name:i,yAxisId:"main-y-axis",xAxisIndex:n,stack:c,color:p?"transparent":u,hide_in_legend:d,labelLayout:{hideOverlap:!0},emphasis:{disabled:!0},...x};if(!o||o===e.data_key)return P.data=Xw({dataTemplate:m,data:w,aggregation_on_value:l,name_data_key:e.data_key,value_data_key:t,valueTypedXAxis:j}),P;const U=Jw({group_by_key:o,data:w,name_data_key:e.data_key,value_data_key:t});return Object.entries(U).map(([se,Q])=>{const ie=y.cloneDeep(P);return ie.name=se,ie.color=void 0,ie.data=Q,ie})}function Hw(e,t,n,r,i,o,l){const c=t.map(d=>[d,0]);return e.series.map(d=>Zw(e,d,c,n,r,l,i)).flat().concat(Uw(e.reference_lines,o,l,r))}function e0(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:Mt(t.y_axis.axisLabel.formatter)(o,l)}function t0(e,t,n){const r=t.reduce((i,{xAxisIndex:o,name:l})=>(i[l]=o,i),{});return{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:p,value:h})=>{if(Array.isArray(h)&&h.length===2&&(h=h[0]),!d)return h;const x=r[d],m=n[x]??n.default;return`
|
|
329
|
+
`}})}function ww(e,t,n){const r=Ot(e.heat_block.min,n),i=Ot(e.heat_block.max,n);return{min:r,max:i,calculable:!0,orient:"horizontal",left:t?"center":5,top:0,itemWidth:15}}const Cw={grid:{containLabel:!0}},Sw=e=>I(e).get("year");function _w(e,t){const n=A(e.calendar.data_key),r=t[n.queryID],i=y.groupBy(r,u=>Sw(u[n.columnKey])),o=Object.keys(i),l=r.map(u=>I(u[n.columnKey]).valueOf()),c=y.min(l),d=y.max(l);return{minDate:c??0,maxDate:d??0,dateSpan:I(d).diff(c,"day"),dataByYear:i,years:o}}function kw(e,t,n){const r=n.reduce((h,x)=>{const m=it(x,t);return h[x.name]=Ne(x,m),h},{}),i=gw(e),{dateSpan:o,minDate:l,dataByYear:c,years:d}=_w(e,t),u=o<=366,p={calendar:fw(u,l,d),series:yw(e,u,c,t),tooltip:vw(e,t,i),visualMap:ww(e,u,r),legend:mw(u,d)};return y.defaultsDeep({},p,Cw)}function Tw(e){return s.jsx(s.Fragment,{})}function Dw(e){return s.jsx(a.Text,{children:"Click heat block"})}const xo={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:Dw,configRender:Tw,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"}]},gr={calendar:{data_key:"",locale:"EN"},heat_block:{min:{type:"static",value:0},max:{type:"static",value:100},name:"Value",data_key:"",value_formatter:be},tooltip:{metrics:[]}};Y.use([O.DataZoomComponent,te.BarChart,te.LineChart,te.HeatmapChart,O.CalendarComponent,O.GridComponent,O.LegendComponent,O.TooltipComponent,O.VisualMapComponent,Ce.CanvasRenderer]);function Iw({name:e},t){const n=t.getOption();n.calendar.forEach(r=>{r.range=e}),t.setOption(n)}function Mw({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const l=mt(t,e.calendar.data_key),c=$e(i.triggerManager,xo.id),d=f.useCallback(h=>{const[x,m]=h.value,j=y.get(l,x,{error:"rowData is not found"});c.forEach(w=>{i.runInteraction(w.id,{...h,rowData:j})})},[l,c,i]),u=f.useMemo(()=>({click:d,legendselectchanged:Iw}),[d]),p=f.useMemo(()=>kw(e,t,o),[e,t]);return s.jsx(we,{echarts:Y,option:p,style:{width:n,height:r},onEvents:u,notMerge:!0,opts:{locale:e.calendar.locale},theme:"merico-light"})}function Aw({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,gr),[r]),l=e.data,{width:c,height:d}=e.viewport;return!o.calendar.data_key||!o.heat_block.data_key||!c||!d?null:s.jsx(De,{width:c,height:d,children:s.jsx(Mw,{variables:i,width:We(c),height:Re(d),data:l,conf:o,interactionManager:n})})}function zw({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(Lt,{label:"Min Value",...n})}),s.jsx(b.Controller,{name:"heat_block.max",control:e,render:({field:n})=>s.jsx(Lt,{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(Oe,{...n})})]})}const Ew=({control:e,index:t,remove:n})=>s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`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(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),Pw=({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((h,x)=>({...h,...o[x]})),c=()=>r({id:Date.now().toString(),data_key:"",name:""}),d=t("tooltip.metrics.0.id"),[u,p]=f.useState(()=>d??null);return f.useEffect(()=>{d&&p(h=>h!==null?h:d)},[d]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(_.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:u,onTabChange:h=>p(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((h,x)=>s.jsx(a.Tabs.Tab,{value:h.id,children:h.name?h.name:x},h.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),l.map((h,x)=>s.jsx(a.Tabs.Panel,{value:h.id,children:s.jsx(Ew,{control:e,index:x,remove:i},h.id)},h.id))]})]})};function Lw({control:e,watch:t}){return s.jsx(Pw,{control:e,watch:t})}const Ow=[{label:"Chinese",value:"ZH"},{label:"English",value:"EN"}];function Bw({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:Ow,sx:{flex:1},...n})})]})}function $w({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},t,gr),[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:d,reset:u}=b.useForm({defaultValues:i});f.useEffect(()=>{u(i)},[i]);const p=d(),h=f.useMemo(()=>!y.isEqual(p,r),[p,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:!h,children:s.jsx(_.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(Bw,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Heat Block",children:s.jsx(zw,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(Lw,{control:o,watch:c})})]})]})})}function Vw(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}`,{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(d=>({...d,data_key:r(d.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}function Nw(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 qw extends ie{constructor(){super(...arguments);E(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>({...n,version:2,config:Vw(n.config,r)})),this.version(3,n=>({...n,version:3,config:Nw(n.config)}))}}const Fw={displayName:"Heatmap(Calendar)",displayGroup:"ECharts-based charts",migrator:new qw,name:"calendarHeatmap",viewRender:Aw,configRender:$w,createConfig:()=>({version:3,config:gr}),triggers:[xo]},mr={x_axes:[{id:"initial-x",min:"",max:"",name:"X Axis",data_key:"",position:"bottom",label_formatter:be,show:!0}],y_axis:{name:"Y Axis",data_key:"",axisLabel:{formatter:{...Be},overflow:ze},nameAlignment:"center"},series:[],tooltip:{metrics:[]},reference_lines:[]};function Gw(){const e=new Date().getTime().toString();return{id:e,min:"",max:"",name:e,data_key:"",position:"bottom",label_formatter:be,show:!0}}function Ww(){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 Rw(){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 Qw(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 Uw(e){switch(e){case"bar":return"roundRect";case"scatter":return"circle"}}function Yw(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:Uw(r)})),t}function Kw(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?gn(i.template,t,r):""},position:c}}}})}function Vn(e,t,n){const r=rt(e,t),i=rt(e,n);return y.zip(i,r)}function Xw(e,t,n,r){const i=Vn(t,n,r);return y.unionBy(i,e,0)}function Jw({dataTemplate:e,data:t,name_data_key:n,value_data_key:r,valueTypedXAxis:i}){return i?Xw(e,t,n,r):Vn(t,n,r)}function Zw({dataTemplate:e,data:t,aggregation_on_value:n,name_data_key:r,value_data_key:i,valueTypedXAxis:o}){if(!n||n.type==="none")return Jw({dataTemplate:e,data:t,name_data_key:r,value_data_key:i,valueTypedXAxis:o});const l=Vn(t,r,i),c=y.groupBy(l,"0");return e.map(([u])=>{const h=c[u].map(m=>m[1]),x=Ss(h,n);return[u,x]})}function Hw({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,d])=>{l[c]=Vn({[i]:d},r,n)}),l}function e0({y_axis:e},{data_key:t,xAxisIndex:n,label_position:r,name:i,group_by_key:o,aggregation_on_value:l,stack:c,color:d,hide_in_legend:u,invisible:p,id:h,...x},m,j,w,T,M){const P={label:{show:!!r,position:r,formatter:M[n??"default"]},name:i,yAxisId:"main-y-axis",xAxisIndex:n,stack:c,color:p?"transparent":d,hide_in_legend:u,labelLayout:{hideOverlap:!0},emphasis:{disabled:!0},...x};if(!o||o===e.data_key)return P.data=Zw({dataTemplate:m,data:w,aggregation_on_value:l,name_data_key:e.data_key,value_data_key:t,valueTypedXAxis:j}),P;const U=Hw({group_by_key:o,data:w,name_data_key:e.data_key,value_data_key:t});return Object.entries(U).map(([re,Q])=>{const ae=y.cloneDeep(P);return ae.name=re,ae.color=void 0,ae.data=Q,ae})}function t0(e,t,n,r,i,o,l){const c=t.map(u=>[u,0]);return e.series.map(u=>e0(e,u,c,n,r,l,i)).flat().concat(Kw(e.reference_lines,o,l,r))}function n0(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:Mt(t.y_axis.axisLabel.formatter)(o,l)}function s0(e,t,n){const r=t.reduce((i,{xAxisIndex:o,name:l})=>(i[l]=o,i),{});return ne.getTooltip({trigger:"axis",axisPointer:{type:"shadow"},formatter:function(i){const o=Array.isArray(i)?i:[i];if(o.length===0)return"";const l=o.map(({seriesName:u,marker:p,value:h})=>{if(Array.isArray(h)&&h.length===2&&(h=h[0]),!u)return h;const x=r[u],m=n[x]??n.default;return`
|
|
330
330
|
<tr>
|
|
331
331
|
<td>${p}</td>
|
|
332
|
-
<th style="text-align: right; padding: 0 1em;">${
|
|
332
|
+
<th style="text-align: right; padding: 0 1em;">${u}</th>
|
|
333
333
|
<td style="text-align: left; padding: 0 1em;">${m({value:h})}</td>
|
|
334
334
|
</tr>
|
|
335
|
-
`}),c=Qe(e.y_axis.axisLabel.overflow.in_tooltip),
|
|
335
|
+
`}),c=Qe(e.y_axis.axisLabel.overflow.in_tooltip),d=n0(o,e);return`
|
|
336
336
|
<div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
|
|
337
|
-
<div style="${c}">${
|
|
337
|
+
<div style="${c}">${d}</div>
|
|
338
338
|
</div>
|
|
339
339
|
<table style="width: auto">
|
|
340
340
|
<tbody>
|
|
341
341
|
${l.join("")}
|
|
342
342
|
</tbody>
|
|
343
343
|
</table>
|
|
344
|
-
`}}}function n0(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 F(c).format(r)}catch(u){return console.error(u),c}},n),{default:({value:n})=>n})}function s0(e,t){const n={};return t.map(r=>{const i=it(r,e);n[r.name]=Ne(r,i)}),n}function r0(e,t){return e.x_axes.map(({min:n,max:r,...i},o)=>{let l=i.position;return l||(l=o>0?"bottom":"top"),ze.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 i0(e,t){const n=t.every(l=>!Number.isNaN(Number(l))),{overflow:r,...i}=e.y_axis.axisLabel,o=Ue(r.on_axis);return[ze.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:Mt(i.formatter)},z:5})]}function a0(e,t,n){if(!e.y_axis.data_key)return{};const r=s0(t,n),i=n0(e),o=A(e.y_axis.data_key),l=y.uniq(t[o.queryID].map(p=>p[o.columnKey])),c=l.every(p=>!Number.isNaN(Number(p))),u=Hw(e,l,c,t,i,n,r);return{xAxis:r0(e,i),yAxis:i0(e,l),series:u,tooltip:t0(e,u,i),grid:Ww(e),legend:Qw(u)}}Y.use([O.DataZoomComponent,te.BarChart,te.LineChart,te.ScatterChart,O.GridComponent,O.LegendComponent,O.TooltipComponent,we.CanvasRenderer,O.MarkLineComponent,O.MarkAreaComponent]);function o0({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const l=mt(t,e.y_axis.data_key),c=$e(i.triggerManager,Ms.id),u=f.useCallback(h=>{const x=y.get(l,h.name,{error:"rowData is not found"});c.forEach(m=>{i.runInteraction(m.id,{...h,rowData:x})})},[l,c,i]),d=f.useMemo(()=>({click:u}),[u]),p=f.useMemo(()=>a0(e,t,o),[e,t]);return s.jsx(ve,{echarts:Y,option:p,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function l0({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,mr),[r]),l=e.data,{width:c,height:u}=e.viewport;return!c||!u?null:s.jsx(Te,{width:c,height:u,children:s.jsx(o0,{variables:i,width:We(c),height:Re(u),data:l,conf:o,interactionManager:n})})}const c0=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],u0=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function d0({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:u0,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:c0,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(Se,{...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(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]})}function p0({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=Gw();i(m)},d=f.useMemo(()=>n.map(m=>({label:m.name,value:m.name})),[n]),p=t("x_axes"),h=f.useMemo(()=>p.map(({name:m},j)=>({label:m,value:j.toString()})),[p]),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(_.Plus,{size:18,color:"#228be6"})})]}),c.map((m,j)=>s.jsx(a.Tabs.Panel,{value:m.id,children:s.jsx(d0,{control:e,index:j,remove:o,watch:t,variableOptions:d,xAxisOptions:h})},m.id))]})}function h0(e){const[t,n]=f.useState(e);return f.useEffect(()=>{n(e)},[e]),{tab:t,setTab:n}}const x0=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function f0({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:x0,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 g0=[{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 m0({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(Zs,{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(B,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...o})})}),s.jsx(f0,{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:g0,...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(Se,{...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(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Series"})]})}function y0({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=Fw();r(m)},u=t("x_axes"),d=f.useMemo(()=>u.map(({name:m},j)=>({label:m,value:j.toString()})),[u]),{tab:p,setTab:h}=h0((x=l[0])==null?void 0:x.id);return s.jsxs(a.Tabs,{value:p,onTabChange:h,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(_.Plus,{size:18,color:"#228be6"})})]}),l.map((m,j)=>s.jsx(a.Tabs.Panel,{value:m.id,children:s.jsx(m0,{control:e,index:j,remove:i,seriesItem:m,xAxisOptions:d},m.id)},m.id))]})}const b0=[{label:"Top",value:"top"},{label:"Bottom",value:"bottom"}];function j0({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:b0,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(Oe,{...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(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this X Axis"})]})}function v0({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,p)=>({...d,...o[p]})),c=()=>{const d=qw();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(_.Plus,{size:18,color:"#228be6"})})]}),l.map((d,p)=>s.jsx(a.Tabs.Panel,{value:d.id,children:s.jsx(j0,{control:e,index:p,remove:i})},d.id))]})}function w0({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(mn,{...n})})}),s.jsx(b.Controller,{name:"y_axis.axisLabel.overflow",control:e,render:({field:n})=>s.jsx(Je,{...n})})]})}function C0({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),{variables:r}=e,i=f.useMemo(()=>y.defaultsDeep({},t,mr),[t]),{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=b.useForm({defaultValues:i});f.useEffect(()=>{d(i)},[i]),c([]);const p=u(),h=f.useMemo(()=>!y.isEqual(p,i),[p,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:!h,children:s.jsx(_.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(v0,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Y Axis",children:s.jsx(w0,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Series",children:s.jsx(y0,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Reference Lines",children:s.jsx(p0,{variables:r,control:o,watch:c})})]})]})})}function S0(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 _0 extends re{constructor(){super(...arguments);E(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:S0(i,r)}})}}const k0={displayName:"Horizontal Bar Chart",displayGroup:"ECharts-based charts",migrator:new _0,name:"horizontalBarChart",viewRender:l0,configRender:C0,createConfig:()=>({version:2,config:mr})},yr={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...Ln}}},deviation:{name:"",data_keys:{estimated_value:"",actual_value:""}},metrics:[]};function T0(){return[{top:20,left:30,right:60,height:40,containLabel:!0,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0},{top:70,left:30,right:60,height:100,containLabel:!0,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0},{top:180,left:30,right:60,bottom:130,containLabel:!0,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0},{left:30,right:60,bottom:20,height:100,containLabel:!1,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0}]}const xo=({value:e})=>{try{return F(e[2]).format({output:"percent",mantissa:0})}catch(t){return console.error(t),e}};function D0(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:xo},labelLayout:{hideOverlap:!0},visualMapIndex:0,tooltip:{trigger:"item",formatter:({color:i,value:o})=>`
|
|
344
|
+
`}})}function r0(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 F(c).format(r)}catch(d){return console.error(d),c}},n),{default:({value:n})=>n})}function i0(e,t){const n={};return t.map(r=>{const i=it(r,e);n[r.name]=Ne(r,i)}),n}function a0(e,t){return e.x_axes.map(({min:n,max:r,...i},o)=>{let l=i.position;return l||(l=o>0?"bottom":"top"),ne.getYAxis({...i,type:"value",min:n||void 0,max:r||void 0,position:l,axisLabel:{show:!0,margin:2,formatter:t[o]??t.default},nameLocation:"center",nameGap:15})})}function o0(e,t){const n=t.every(l=>!Number.isNaN(Number(l))),{overflow:r,...i}=e.y_axis.axisLabel,o=Ue(r.on_axis);return[ne.getXAxis({data:t,name:e.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"center"},id:"main-y-axis",type:n?"value":"category",axisLabel:{...i,...o,formatter:Mt(i.formatter)},z:5})]}function l0(e,t,n){if(!e.y_axis.data_key)return{};const r=i0(t,n),i=r0(e),o=A(e.y_axis.data_key),l=y.uniq(t[o.queryID].map(p=>p[o.columnKey])),c=l.every(p=>!Number.isNaN(Number(p))),d=t0(e,l,c,t,i,n,r);return{xAxis:a0(e,i),yAxis:o0(e,l),series:d,tooltip:s0(e,d,i),grid:Qw(e),legend:Yw(d)}}Y.use([O.DataZoomComponent,te.BarChart,te.LineChart,te.ScatterChart,O.GridComponent,O.LegendComponent,O.TooltipComponent,Ce.CanvasRenderer,O.MarkLineComponent,O.MarkAreaComponent]);function c0({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const l=mt(t,e.y_axis.data_key),c=$e(i.triggerManager,Ms.id),d=f.useCallback(h=>{const x=y.get(l,h.name,{error:"rowData is not found"});c.forEach(m=>{i.runInteraction(m.id,{...h,rowData:x})})},[l,c,i]),u=f.useMemo(()=>({click:d}),[d]),p=f.useMemo(()=>l0(e,t,o),[e,t]);return s.jsx(we,{echarts:Y,option:p,style:{width:n,height:r},onEvents:u,notMerge:!0,theme:"merico-light"})}function d0({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,mr),[r]),l=e.data,{width:c,height:d}=e.viewport;return!c||!d?null:s.jsx(De,{width:c,height:d,children:s.jsx(c0,{variables:i,width:We(c),height:Re(d),data:l,conf:o,interactionManager:n})})}const u0=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],p0=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function h0({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:p0,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:u0,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:d=>c.onChange(d.currentTarget.checked)})}),s.jsx(a.Button,{leftIcon:s.jsx(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]})}function x0({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]})),d=()=>{const m=Rw();i(m)},u=f.useMemo(()=>n.map(m=>({label:m.name,value:m.name})),[n]),p=t("x_axes"),h=f.useMemo(()=>p.map(({name:m},j)=>({label:m,value:j.toString()})),[p]),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:d,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),c.map((m,j)=>s.jsx(a.Tabs.Panel,{value:m.id,children:s.jsx(h0,{control:e,index:j,remove:o,watch:t,variableOptions:u,xAxisOptions:h})},m.id))]})}function f0(e){const[t,n]=f.useState(e);return f.useEffect(()=>{n(e)},[e]),{tab:t,setTab:n}}const g0=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function m0({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:g0,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 y0=[{label:"off",value:""},{label:"top",value:"top"},{label:"left",value:"left"},{label:"right",value:"right"},{label:"bottom",value:"bottom"},{label:"inside",value:"inside"},{label:"insideLeft",value:"insideLeft"},{label:"insideRight",value:"insideRight"},{label:"insideTop",value:"insideTop"},{label:"insideBottom",value:"insideBottom"},{label:"insideTopLeft",value:"insideTopLeft"},{label:"insideBottomLeft",value:"insideBottomLeft"},{label:"insideTopRight",value:"insideTopRight"},{label:"insideBottomRight",value:"insideBottomRight"}];function b0({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(Zs,{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(B,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...o})})}),s.jsx(m0,{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:y0,...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(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Series"})]})}function j0({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=Ww();r(m)},d=t("x_axes"),u=f.useMemo(()=>d.map(({name:m},j)=>({label:m,value:j.toString()})),[d]),{tab:p,setTab:h}=f0((x=l[0])==null?void 0:x.id);return s.jsxs(a.Tabs,{value:p,onTabChange:h,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(_.Plus,{size:18,color:"#228be6"})})]}),l.map((m,j)=>s.jsx(a.Tabs.Panel,{value:m.id,children:s.jsx(b0,{control:e,index:j,remove:i,seriesItem:m,xAxisOptions:u},m.id)},m.id))]})}const v0=[{label:"Top",value:"top"},{label:"Bottom",value:"bottom"}];function w0({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:v0,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(Oe,{...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(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this X Axis"})]})}function C0({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((u,p)=>({...u,...o[p]})),c=()=>{const u=Gw();r(u)},d=l.length>0?l[0].id:"0";return s.jsxs(a.Tabs,{defaultValue:d,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map(u=>s.jsx(a.Tabs.Tab,{value:u.id,children:u.name},u.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),l.map((u,p)=>s.jsx(a.Tabs.Panel,{value:u.id,children:s.jsx(w0,{control:e,index:p,remove:i})},u.id))]})}function S0({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(mn,{...n})})}),s.jsx(b.Controller,{name:"y_axis.axisLabel.overflow",control:e,render:({field:n})=>s.jsx(Je,{...n})})]})}function _0({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),{variables:r}=e,i=f.useMemo(()=>y.defaultsDeep({},t,mr),[t]),{control:o,handleSubmit:l,watch:c,getValues:d,reset:u}=b.useForm({defaultValues:i});f.useEffect(()=>{u(i)},[i]),c([]);const p=d(),h=f.useMemo(()=>!y.isEqual(p,i),[p,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:!h,children:s.jsx(_.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(C0,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Y Axis",children:s.jsx(S0,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Series",children:s.jsx(j0,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Reference Lines",children:s.jsx(x0,{variables:r,control:o,watch:c})})]})]})})}function k0(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,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(d=>({...d,data_key:r(d.data_key),group_by_key:r(d.group_by_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class T0 extends ie{constructor(){super(...arguments);E(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:k0(i,r)}})}}const D0={displayName:"Horizontal Bar Chart",displayGroup:"ECharts-based charts",migrator:new T0,name:"horizontalBarChart",viewRender:d0,configRender:_0,createConfig:()=>({version:2,config:mr})},yr={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...Ln}}},deviation:{name:"",data_keys:{estimated_value:"",actual_value:""}},metrics:[]};function I0(){return[{top:20,left:30,right:60,height:40,containLabel:!0,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0},{top:70,left:30,right:60,height:100,containLabel:!0,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0},{top:180,left:30,right:60,bottom:130,containLabel:!0,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0},{left:30,right:60,bottom:20,height:100,containLabel:!1,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0}]}const fo=({value:e})=>{try{return F(e[2]).format({output:"percent",mantissa:0})}catch(t){return console.error(t),e}};function M0(e,t,n){return{type:"heatmap",name:"准确估算比例",xAxisIndex:0,yAxisIndex:0,data:t.map(i=>{const o=n[i].length,d=(y.countBy(n[i],u=>u.level.diff===0).true??0)/o;return[i,"_y",d]}),label:{show:!0,formatter:fo},labelLayout:{hideOverlap:!0},visualMapIndex:0,tooltip:{trigger:"item",formatter:({color:i,value:o})=>`
|
|
345
345
|
<table style="width: auto">
|
|
346
346
|
<thead>
|
|
347
347
|
<tr colspan="2">
|
|
@@ -359,17 +359,17 @@ Check the top-level render call using <`+z+">.")}return D}}function dc(v,D){{if(
|
|
|
359
359
|
<tbody>
|
|
360
360
|
<tr>
|
|
361
361
|
<th style="text-align: right;">准确估算比例</th>
|
|
362
|
-
<td style="text-align: left; padding: 0 1em;">${
|
|
362
|
+
<td style="text-align: left; padding: 0 1em;">${fo({value:o})}</td>
|
|
363
363
|
</tr>
|
|
364
364
|
</tbody>
|
|
365
365
|
</table>
|
|
366
|
-
`},show_in_legend:!1}}function
|
|
366
|
+
`},show_in_legend:!1}}function go(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 A0([e,t]){const n={x:e,v:`${t}`};try{n.v=F(t).format({output:"number",mantissa:2,trimMantissa:!0})}catch{}return n}function z0(e,t,n,r){var d,u;const i=t.map(p=>{const h=n[p],x=y.sumBy(h,m=>m.level.diff);return[p,x/h.length]}),o=Number(((d=y.maxBy(i,p=>p[1]))==null?void 0:d[1])??0),l=Number(((u=y.minBy(i,p=>p[1]))==null?void 0:u[1])??0),c=ft.interpolate([o,0,l],["#D15A40","#FFF","#418AAF"]);return{type:"bar",name:"平均偏差",xAxisIndex:1,yAxisIndex:1,...r,data:i,itemStyle:{color:({value:p})=>{try{return c(p[1])}catch{return"#FFF"}}},label:{position:"outside",show:!0,formatter:({value:p})=>{try{return F(p[1]).format({output:"number",mantissa:1,trimMantissa:!0})}catch{return p[1]}}},tooltip:{trigger:"item",formatter:({color:p,value:h})=>{const{x,v:m}=A0(h);return`
|
|
367
367
|
<table style="width: auto">
|
|
368
368
|
<thead>
|
|
369
369
|
<tr colspan="2">
|
|
370
370
|
<div style="
|
|
371
371
|
width: 100%; height: 4px; border-radius: 2px; margin-bottom: 6px;
|
|
372
|
-
${
|
|
372
|
+
${go(p)}
|
|
373
373
|
"/>
|
|
374
374
|
</tr>
|
|
375
375
|
<tr>
|
|
@@ -385,13 +385,13 @@ Check the top-level render call using <`+z+">.")}return D}}function dc(v,D){{if(
|
|
|
385
385
|
</tr>
|
|
386
386
|
</tbody>
|
|
387
387
|
</table>
|
|
388
|
-
`}},show_in_legend:!1}}function
|
|
388
|
+
`}},show_in_legend:!1}}function E0([e,t,n,r]){const i={x:e,percentage:`${t}`,count:n,sum:r};try{i.percentage=F(t).format({output:"percent",mantissa:2,trimMantissa:!0})}catch{}return i}function P0(e,t,n,r){const i={};t.forEach(p=>{const h=y.countBy(n[p],m=>m.level.diff),x=y.sum(Object.values(h));Object.entries(h).forEach(([m,j])=>{i[m]||(i[m]=[]);const w=j/x;i[m].push([p,w,j,x])})});const o=Object.entries(i).map(([p])=>Number(p)).sort((p,h)=>p-h),l=Math.max(...o),c=Math.min(...o),d=ft.interpolate([l,0,c],["#D15A40","#FFF","#418AAF"]);return o.map(p=>({type:"bar",name:p,xAxisIndex:2,yAxisIndex:2,stack:1,...r,color:d(p),data:i[p],tooltip:{trigger:"item",formatter:({color:h,value:x})=>{const{x:m,percentage:j,count:w,sum:T}=E0(x);return`
|
|
389
389
|
<table style="width: auto">
|
|
390
390
|
<thead>
|
|
391
391
|
<tr colspan="2">
|
|
392
392
|
<div style="
|
|
393
393
|
width: 100%; height: 4px; border-radius: 2px; margin-bottom: 6px;
|
|
394
|
-
${
|
|
394
|
+
${go(h)}
|
|
395
395
|
"
|
|
396
396
|
/>
|
|
397
397
|
</tr>
|
|
@@ -420,8 +420,8 @@ Check the top-level render call using <`+z+">.")}return D}}function dc(v,D){{if(
|
|
|
420
420
|
</tr>
|
|
421
421
|
</tbody>
|
|
422
422
|
</table>
|
|
423
|
-
`}},show_in_legend:!0}))}function E0(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 P0(e,t,n,r){const l={barMinWidth:5,barMaxWidth:20};return[D0(e,n,r),M0(e,n,r,l),...z0(e,n,r,l),E0(e,t,n,r)]}function L0(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:Wa(n.formatter)},axisLine:{show:!1}}]}function O0(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 br(e){return e==1||e==2?1:br(e-2)+br(e-1)}const B0=Array.from(new Array(20),(e,t)=>br(t+1));function go(e){return e<=1?e:B0.findIndex(t=>e<=t)-1}function $0(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=go(c[o.columnKey]),d=go(c[l.columnKey]),p=u-d;return{...c,level:{estimated:u,actual:d,diff:p}}})}function V0(e){return e==="rgba(255, 255, 255, 1)"?{borderColor:"rgba(0,0,0,.1)",borderWidth:1}:{}}function N0(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:V0(n.color)})),tooltip:{show:!0,formatter:"档位偏差:{a}"}}}const q0={tooltip:{trigger:"axis"}};function F0(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 G0(e,t,n){const r=$0(e,n),i=A(e.x_axis.data_key),o=y.uniqBy(n[i.queryID],i.columnKey).map(p=>p[i.columnKey]),l=y.groupBy(r,i.columnKey),c=F0(e,t),u=P0(e,c,o,l),d={xAxis:L0(e,o),yAxis:O0(c),series:u,grid:T0(),visualMap:[{min:0,max:1,calculable:!0,show:!1,seriesIndex:0,color:["#F0F0F0","#418AAF"]}],legend:N0(u)};return y.defaultsDeep({},d,q0)}const W0={input:{border:"none !important",paddingLeft:0,lineHeight:"1.55 !important"}},R0=({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:W0})]})},Q0={"tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function U0(){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:Q0,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 Y0(e){return s.jsxs(a.Group,{position:"apart",children:[s.jsx(U0,{}),s.jsx(R0,{...e})]})}Y.use([te.BarChart,te.LineChart,te.HeatmapChart,O.GridComponent,O.LegendComponent,O.TooltipComponent,we.CanvasRenderer,O.VisualMapComponent]);function K0({conf:e,data:t,width:n,height:r,metricKey:i}){const o=f.useMemo(()=>G0(e,i,t),[e,t,i]);return s.jsx(ve,{echarts:Y,option:o,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})}function X0({context:e}){const{value:t}=$(e.instanceData,"config"),n=f.useMemo(()=>y.defaults({},t,yr),[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,[p,h]=f.useState(d);if(f.useEffect(()=>{h(j=>j||d)},[d]),!l.data_key||!u||!d||!i||!o)return null;const x=Math.max(We(i),300),m=Math.max(Re(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(Y0,{conf:n,metricKey:p,setMetricKey:h}),s.jsx(K0,{width:x,height:m-30,data:r,conf:n,metricKey:p})]})}function J0({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 Z0=({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(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),H0=({control:e,watch:t})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"metrics"}),o=t("metrics"),l=n.map((h,x)=>({...h,...o[x]})),c=()=>r({id:Date.now().toString(),data_key:"",name:""}),u=t("metrics.0.id"),[d,p]=f.useState(()=>u??null);return f.useEffect(()=>{u&&p(h=>h!==null?h:u)},[u]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(_.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:h=>p(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((h,x)=>s.jsx(a.Tabs.Tab,{value:h.id,children:h.name?h.name:x},h.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),l.map((h,x)=>s.jsx(a.Tabs.Panel,{value:h.id,children:s.jsx(Z0,{control:e,index:x,remove:i},h.id)},h.id))]})]})};function eC({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(Ua,{...n})})]})]})}function tC({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([]);const d=c(),p=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:!p,children:s.jsx(_.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(eC,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Deviation",children:s.jsx(J0,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Additional Metrics",children:s.jsx(H0,{control:i,watch:l})})]})]})})}function nC(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 sC extends re{constructor(){super(...arguments);E(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:nC(i,r)}})}}const rC={displayName:"Merico Estimation Chart",displayGroup:"Merico suite",migrator:new sC,name:"mericoEstimationChart",viewRender:X0,configRender:tC,createConfig:()=>({version:2,config:yr})},jr={styles:{justify:"space-around",align:"start"},metrics:[]};function iC(){return{id:new Date().getTime().toString(),names:{value:"Value",basis:"Basis"},data_keys:{value:"",basis:""},formatter:ye,postfix:{type:"text",value:""}}}const mo=({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,aC=S.observer(({metric:e,variableValueMap:t})=>{const{names:n,data_keys:r,formatter:i,postfix:o}=e,l=le(),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:F(t[r.value]).format(i)}),s.jsx(mo,{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:F(t[r.basis]).format(i)}),s.jsx(mo,{postfix:c})]})]})]})}),oC=S.observer(({context:e,instance:t})=>{const{value:n}=$(e.instanceData,"config"),{variables:r}=e,i=f.useMemo(()=>y.defaults({},n,jr),[n]),o=e.data,l=f.useMemo(()=>Ui(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(aC,{metric:d,variableValueMap:l},d.id))})}),lC=[{label:"Text",value:"text"},{label:"Filter Option Label",value:"filter-option-label"}],cC=S.observer(f.forwardRef(({value:e,onChange:t},n)=>{const i=X().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:lC,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 uC({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(Oe,{...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(cC,{...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(_.Trash,{size:16})})]})}const dC=({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,w)=>({...j,...l[w]})),u=()=>{i(iC())},d=f.useMemo(()=>n.map(j=>({label:j.name,value:j.name})),[n]),p=y.get(c,"0.id",null),[h,x]=f.useState(p);f.useEffect(()=>{x(j=>j||p)},[p]);const m=j=>{o(j);const w=y.get(c,"0.id",null);x(w)};return s.jsxs(s.Fragment,{children:[s.jsx(a.Divider,{mt:15,variant:"dashed",label:"Metrics",labelPosition:"center"}),s.jsxs(a.Tabs,{value:h,onTabChange:x,styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[s.jsxs(a.Tabs.List,{children:[c.map((j,w)=>s.jsx(a.Tabs.Tab,{value:j.id,children:j.names.value?j.names.value:w+1},j.id)),s.jsx(a.Tabs.Tab,{onClick:u,value:"add",children:s.jsx(k.IconPlus,{size:18,color:"#228be6"})})]}),c.map((j,w)=>s.jsx(a.Tabs.Panel,{value:j.id,children:s.jsx(uC,{control:e,index:w,remove:m,variableOptions:d,watch:t})},j.id))]})]})},pC=[{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"}],hC=[{label:"Start",value:"start"},{label:"Center",value:"center"},{label:"End",value:"end"},{label:"Stretch",value:"stretch"}];function xC({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:pC,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:hC,sx:{flex:1},...n})})]})]})}function fC({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]);const p=u(),h=f.useMemo(()=>!y.isEqual(p,i),[p,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:!h,children:s.jsx(_.DeviceFloppy,{size:20})})]}),s.jsx(xC,{control:o,watch:c}),s.jsx(dC,{control:o,watch:c,variables:r})]})})}function gC(e){const{metrics:t,...n}=e;return{...n,metrics:t.map(r=>({...r,postfix:r.postfix??{type:"text",value:""}}))}}class mC extends re{constructor(){super(...arguments);E(this,"VERSION",2)}configVersions(){this.version(1,n=>({...n,version:1,config:n.config})),this.version(2,n=>({...n,version:2,config:gC(n.config)}))}}const yC={displayName:"Merico Stats",displayGroup:"Merico suite",migrator:new mC,name:"merico-stats",viewRender:oC,configRender:fC,createConfig:()=>({version:2,config:jr})};function bC({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(Lt,{label:"Min Value",...r})}),s.jsx(b.Controller,{name:"heat_block.max",control:e,render:({field:r})=>s.jsx(Lt,{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(Oe,{...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 jC=({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(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),vC=({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((h,x)=>({...h,...o[x]})),c=()=>r({id:Date.now().toString(),data_key:"",name:""}),u=t("tooltip.metrics.0.id"),[d,p]=f.useState(()=>u??null);return f.useEffect(()=>{u&&p(h=>h!==null?h:u)},[u]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(_.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:h=>p(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((h,x)=>s.jsx(a.Tabs.Tab,{value:h.id,children:h.name?h.name:x},h.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),l.map((h,x)=>s.jsx(a.Tabs.Panel,{value:h.id,children:s.jsx(jC,{control:e,index:x,remove:i},h.id)},h.id))]})]})};function wC({control:e,watch:t}){return s.jsx(vC,{control:e,watch:t})}const CC=({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}})]})},SC={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
424
|
-
`)},
|
|
423
|
+
`}},show_in_legend:!0}))}function L0(e,t,n,r){const i=A(t.data_key),o=t.name,l=n.map(c=>{const d=y.sumBy(r[c],i.columnKey);return[c,d]});return{type:"line",name:o,xAxisIndex:3,yAxisIndex:3,color:"#b41529",data:l,show_in_legend:!1}}function O0(e,t,n,r){const l={barMinWidth:5,barMaxWidth:20};return[M0(e,n,r),z0(e,n,r,l),...P0(e,n,r,l),L0(e,t,n,r)]}function B0(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:Ra(n.formatter)},axisLine:{show:!1}}]}function $0(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 br(e){return e==1||e==2?1:br(e-2)+br(e-1)}const V0=Array.from(new Array(20),(e,t)=>br(t+1));function mo(e){return e<=1?e:V0.findIndex(t=>e<=t)-1}function N0(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 d=mo(c[o.columnKey]),u=mo(c[l.columnKey]),p=d-u;return{...c,level:{estimated:d,actual:u,diff:p}}})}function q0(e){return e==="rgba(255, 255, 255, 1)"?{borderColor:"rgba(0,0,0,.1)",borderWidth:1}:{}}function F0(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:q0(n.color)})),tooltip:{show:!0,formatter:"档位偏差:{a}"}}}const G0={tooltip:{trigger:"axis"}};function W0(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 R0(e,t,n){const r=N0(e,n),i=A(e.x_axis.data_key),o=y.uniqBy(n[i.queryID],i.columnKey).map(p=>p[i.columnKey]),l=y.groupBy(r,i.columnKey),c=W0(e,t),d=O0(e,c,o,l),u={xAxis:B0(e,o),yAxis:$0(c),series:d,grid:I0(),visualMap:[{min:0,max:1,calculable:!0,show:!1,seriesIndex:0,color:["#F0F0F0","#418AAF"]}],legend:F0(d)};return y.defaultsDeep({},u,G0)}const Q0={input:{border:"none !important",paddingLeft:0,lineHeight:"1.55 !important"}},U0=({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:Q0})]})},Y0={"tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function K0(){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:Y0,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 X0(e){return s.jsxs(a.Group,{position:"apart",children:[s.jsx(K0,{}),s.jsx(U0,{...e})]})}Y.use([te.BarChart,te.LineChart,te.HeatmapChart,O.GridComponent,O.LegendComponent,O.TooltipComponent,Ce.CanvasRenderer,O.VisualMapComponent]);function J0({conf:e,data:t,width:n,height:r,metricKey:i}){const o=f.useMemo(()=>R0(e,i,t),[e,t,i]);return s.jsx(we,{echarts:Y,option:o,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})}function Z0({context:e}){const{value:t}=$(e.instanceData,"config"),n=f.useMemo(()=>y.defaults({},t,yr),[t]),r=e.data,{width:i,height:o}=e.viewport,{x_axis:l,deviation:c}=n,{estimated_value:d,actual_value:u}=c.data_keys,[p,h]=f.useState(u);if(f.useEffect(()=>{h(j=>j||u)},[u]),!l.data_key||!d||!u||!i||!o)return null;const x=Math.max(We(i),300),m=Math.max(Re(o),370);return s.jsxs(a.Box,{pt:Te.top,pr:Te.right,pb:Te.bottom,pl:Te.left,sx:{overflow:"hidden",height:o,width:i},children:[s.jsx(X0,{conf:n,metricKey:p,setMetricKey:h}),s.jsx(J0,{width:x,height:m-30,data:r,conf:n,metricKey:p})]})}function H0({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 eC=({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(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),tC=({control:e,watch:t})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:e,name:"metrics"}),o=t("metrics"),l=n.map((h,x)=>({...h,...o[x]})),c=()=>r({id:Date.now().toString(),data_key:"",name:""}),d=t("metrics.0.id"),[u,p]=f.useState(()=>d??null);return f.useEffect(()=>{d&&p(h=>h!==null?h:d)},[d]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(_.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:u,onTabChange:h=>p(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((h,x)=>s.jsx(a.Tabs.Tab,{value:h.id,children:h.name?h.name:x},h.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),l.map((h,x)=>s.jsx(a.Tabs.Panel,{value:h.id,children:s.jsx(eC,{control:e,index:x,remove:i},h.id)},h.id))]})]})};function nC({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(Ya,{...n})})]})]})}function sC({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:d}=b.useForm({defaultValues:r});f.useEffect(()=>{d(r)},[r]),l([]);const u=c(),p=f.useMemo(()=>!y.isEqual(u,r),[u,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:!p,children:s.jsx(_.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(nC,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Deviation",children:s.jsx(H0,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Additional Metrics",children:s.jsx(tC,{control:i,watch:l})})]})]})})}function rC(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,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(d=>({...d,data_key:r(d.data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class iC extends ie{constructor(){super(...arguments);E(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:rC(i,r)}})}}const aC={displayName:"Merico Estimation Chart",displayGroup:"Merico suite",migrator:new iC,name:"mericoEstimationChart",viewRender:Z0,configRender:sC,createConfig:()=>({version:2,config:yr})},jr={styles:{justify:"space-around",align:"start"},metrics:[]};function oC(){return{id:new Date().getTime().toString(),names:{value:"Value",basis:"Basis"},data_keys:{value:"",basis:""},formatter:be,postfix:{type:"text",value:""}}}const yo=({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,lC=S.observer(({metric:e,variableValueMap:t})=>{const{names:n,data_keys:r,formatter:i,postfix:o}=e,l=ce(),c=f.useMemo(()=>{if(o.type==="text"&&o.value)return o.value;if(o.type==="filter-option-label"&&o.value){const d=l.filters.getSelectOption(o.value);return d?d.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:F(t[r.value]).format(i)}),s.jsx(yo,{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:F(t[r.basis]).format(i)}),s.jsx(yo,{postfix:c})]})]})]})}),cC=S.observer(({context:e,instance:t})=>{const{value:n}=$(e.instanceData,"config"),{variables:r}=e,i=f.useMemo(()=>y.defaults({},n,jr),[n]),o=e.data,l=f.useMemo(()=>Yi(o,r),[r,o]),{width:c,height:d}=e.viewport;return!c||!d||!i?null:s.jsx(a.Flex,{w:`${c}px`,h:`${d}px`,justify:i.styles.justify,align:i.styles.align,direction:"row",wrap:"nowrap",sx:{overflow:"hidden"},children:i.metrics.map(u=>s.jsx(lC,{metric:u,variableValueMap:l},u.id))})}),dC=[{label:"Text",value:"text"},{label:"Filter Option Label",value:"filter-option-label"}],uC=S.observer(f.forwardRef(({value:e,onChange:t},n)=>{const i=X().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:dC,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 pC({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(Oe,{...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(uC,{...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(_.Trash,{size:16})})]})}const hC=({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,w)=>({...j,...l[w]})),d=()=>{i(oC())},u=f.useMemo(()=>n.map(j=>({label:j.name,value:j.name})),[n]),p=y.get(c,"0.id",null),[h,x]=f.useState(p);f.useEffect(()=>{x(j=>j||p)},[p]);const m=j=>{o(j);const w=y.get(c,"0.id",null);x(w)};return s.jsxs(s.Fragment,{children:[s.jsx(a.Divider,{mt:15,variant:"dashed",label:"Metrics",labelPosition:"center"}),s.jsxs(a.Tabs,{value:h,onTabChange:x,styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[s.jsxs(a.Tabs.List,{children:[c.map((j,w)=>s.jsx(a.Tabs.Tab,{value:j.id,children:j.names.value?j.names.value:w+1},j.id)),s.jsx(a.Tabs.Tab,{onClick:d,value:"add",children:s.jsx(k.IconPlus,{size:18,color:"#228be6"})})]}),c.map((j,w)=>s.jsx(a.Tabs.Panel,{value:j.id,children:s.jsx(pC,{control:e,index:w,remove:m,variableOptions:u,watch:t})},j.id))]})]})},xC=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"},{label:"Space Between",value:"space-between"},{label:"Space Around",value:"space-around"},{label:"Space Evenly",value:"space-evenly"}],fC=[{label:"Start",value:"start"},{label:"Center",value:"center"},{label:"End",value:"end"},{label:"Stretch",value:"stretch"}];function gC({control:e,watch:t}){return t("styles"),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:xC,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:fC,sx:{flex:1},...n})})]})]})}function mC({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:d,reset:u}=b.useForm({defaultValues:i});f.useEffect(()=>{u(i)},[i]);const p=d(),h=f.useMemo(()=>!y.isEqual(p,i),[p,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:!h,children:s.jsx(_.DeviceFloppy,{size:20})})]}),s.jsx(gC,{control:o,watch:c}),s.jsx(hC,{control:o,watch:c,variables:r})]})})}function yC(e){const{metrics:t,...n}=e;return{...n,metrics:t.map(r=>({...r,postfix:r.postfix??{type:"text",value:""}}))}}class bC extends ie{constructor(){super(...arguments);E(this,"VERSION",2)}configVersions(){this.version(1,n=>({...n,version:1,config:n.config})),this.version(2,n=>({...n,version:2,config:yC(n.config)}))}}const jC={displayName:"Merico Stats",displayGroup:"Merico suite",migrator:new bC,name:"merico-stats",viewRender:cC,configRender:mC,createConfig:()=>({version:2,config:jr})};function vC({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(Lt,{label:"Min Value",...r})}),s.jsx(b.Controller,{name:"heat_block.max",control:e,render:({field:r})=>s.jsx(Lt,{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(Oe,{...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 wC=({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(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),CC=({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((h,x)=>({...h,...o[x]})),c=()=>r({id:Date.now().toString(),data_key:"",name:""}),d=t("tooltip.metrics.0.id"),[u,p]=f.useState(()=>d??null);return f.useEffect(()=>{d&&p(h=>h!==null?h:d)},[d]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(_.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:u,onTabChange:h=>p(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((h,x)=>s.jsx(a.Tabs.Tab,{value:h.id,children:h.name?h.name:x},h.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),l.map((h,x)=>s.jsx(a.Tabs.Panel,{value:h.id,children:s.jsx(wC,{control:e,index:x,remove:i},h.id)},h.id))]})]})};function SC({control:e,watch:t}){return s.jsx(CC,{control:e,watch:t})}const _C=({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(me,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},kC={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
424
|
+
`)},bo=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 d=m=>{c({...l,enabled:m})},u=()=>{o();const{enabled:m,func_content:j}=l,w={enabled:m,func_content:j};c(w),t(w)},p=()=>{o(),c(e)},h=m=>{c(j=>({...j,func_content:m}))},x=()=>{h(kC.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=>d(m.currentTarget.checked)}),s.jsx(_C,{value:l.func_content,onChange:h,disabled:!l.enabled}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:x,color:"red",leftIcon:s.jsx(_.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:u,children:"OK"})]})]})]})})]})});function TC({control:e,watch:t}){return t(["x_axis"]),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>s.jsx(B,{label:"Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"x_axis.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"Name",sx:{flex:1},...n})})]}),s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Tick Label",labelPosition:"center"}),s.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>s.jsx(Je,{...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(bo,{...n})})]})]})}const DC=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function IC({control:e,watch:t}){return t(["y_axis"]),s.jsxs(a.Stack,{my:0,p:"0",sx:{position:"relative"},children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"y_axis.data_key",control:e,render:({field:n})=>s.jsx(B,{label:"Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"y_axis.name",control:e,render:({field:n})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...n})})]}),s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:"y_axis.nameAlignment",control:e,render:({field:n})=>s.jsx(a.Select,{label:"Name Alignment",required:!0,data:DC,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(Je,{...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(bo,{...n})})]})]})}const vr={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,overflow:ze,formatter:{...Be}}},y_axis:{name:"Y Axis",data_key:"",nameAlignment:"center",axisLabel:{rotate:0,overflow:ze,formatter:{...Be}}},heat_block:{min:{type:"static",value:0},max:{type:"static",value:100},name:"Value",data_key:"",value_formatter:be,label:{show:!1,fontSize:10}},tooltip:{metrics:[]}};function MC({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:d,reset:u}=b.useForm({defaultValues:i});f.useEffect(()=>{u(i)},[i]);const p=d(),h=f.useMemo(()=>!y.isEqual(p,r),[p,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:!h,children:s.jsx(_.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(TC,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Y Axis",children:s.jsx(IC,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Heat Block",children:s.jsx(vC,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(SC,{control:o,watch:c})})]})]})})}function AC(e){return s.jsx(s.Fragment,{})}function zC(e){return s.jsx(a.Text,{children:"Click heat block"})}const jo={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:zC,configRender:AC,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 vo({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 EC(e){const t=vo(e.x_axis.axisLabel.formatter),n=vo(e.y_axis.axisLabel.formatter);return{x_axis:t,y_axis:n}}function PC(e){return{heat_block:function(r){if(!e.heat_block.value_formatter)return r;try{return F(r).format(e.heat_block.value_formatter)}catch(i){return console.error(i),r}}}}function LC(e){let t=0;return e.x_axis.name&&(t+=20),{top:45,left:5,right:5,bottom:t,containLabel:!0}}function OC(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),d=t[o.queryID].map(u=>[y.get(u,o.columnKey),y.get(u,l.columnKey),y.get(u,c.columnKey)]);return{type:"heatmap",name:i.name,xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{borderWidth:0},data:d,label:i.label,labelLayout:{hideOverlap:!0}}}const BC=e=>{try{return F(e).format({trimMantissa:!0,mantissa:2})}catch{return e}};function $C({conf:e,labelFormatters:t,valueFormatters:n,dataDict:r,params:i}){const{value:o,dataIndex:l}=i,[c,d,u]=o,p={label:e.x_axis.name?e.x_axis.name:"X Axis",value:t.x_axis(c,l),style:{label:"",value:Qe(e.x_axis.axisLabel.overflow.in_tooltip)}},h={label:e.y_axis.name?e.y_axis.name:"Y Axis",value:t.y_axis(d,l),style:{label:"",value:Qe(e.y_axis.axisLabel.overflow.in_tooltip)}},x={label:e.heat_block.name,value:n.heat_block(u),style:{label:"",value:""}},m=[p,h,x],j=r[`${c}---${d}`];return j&&e.tooltip.metrics.forEach(w=>{const T=A(w.data_key);m.push({label:w.name,value:BC(y.get(j,T.columnKey,"")),style:{label:"",value:""}})}),m}function VC(e,t,n,r){const{x_axis:i,y_axis:o,heat_block:l}=e,c=A(i.data_key),d=A(o.data_key);A(l.data_key);const u=y.keyBy(t[c.queryID],p=>`${p[c.columnKey]}---${p[d.columnKey]}`);return ne.getTooltip({formatter:function(p){const x=$C({conf:e,labelFormatters:n,valueFormatters:r,dataDict:u,params:p}).map(j=>`
|
|
425
425
|
<tr>
|
|
426
426
|
<th style="text-align: right;">
|
|
427
427
|
<div style="${j.style.label}">${j.label}</div>
|
|
@@ -442,18 +442,18 @@ Check the top-level render call using <`+z+">.")}return D}}function dc(v,D){{if(
|
|
|
442
442
|
</thead>
|
|
443
443
|
<tbody>${x.join("")}</tbody>
|
|
444
444
|
</table>
|
|
445
|
-
`}}}function $C(e,t){const n=Ot(e.heat_block.min,t),r=Ot(e.heat_block.max,t);return{min:n,max:r,calculable:!0,orient:"horizontal",left:"center",top:0,itemWidth:15}}function VC(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=Ue(o.on_axis);return{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:!0},nameLocation:"center",nameGap:25,nameTextStyle:{fontWeight:"bold",align:"center"},z:2}}function NC(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:p}=e.y_axis.axisLabel,h=Ue(d.on_axis);return{...c,type:"category",data:u,axisLabel:{rotate:p,...h,formatter:n},axisLine:{show:!0,color:"blue"},axisTick:{show:!0,alignWithLabel:!0},splitArea:{show:!0},nameTextStyle:{fontWeight:"bold",align:o},nameLocation:"end",nameGap:15,z:2}}const qC={tooltip:{confine:!0}};function FC(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]=Ne(u,d),c},{}),i=AC(e),o=zC(e),l={xAxis:VC(e,t,i.x_axis),yAxis:NC(e,t,i.y_axis),series:PC(e,t),tooltip:BC(e,t,i,o),grid:EC(e),visualMap:$C(e,r)};return y.defaultsDeep({},l,qC)}Y.use([O.DataZoomComponent,te.HeatmapChart,O.GridComponent,O.LegendComponent,O.TooltipComponent,O.VisualMapComponent,we.CanvasRenderer]);function GC({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const l=f.useMemo(()=>{const h=A(e.x_axis.data_key),x=A(e.y_axis.data_key);return y.keyBy(t[h.queryID],m=>`${m[h.columnKey]}---${m[x.columnKey]}`)},[t,e.x_axis.data_key,e.y_axis.data_key]),c=$e(i.triggerManager,bo.id),u=f.useCallback(h=>{const[x,m]=h.value,j=y.get(l,`${x}---${m}`,{error:"rowData is not found"});c.forEach(w=>{i.runInteraction(w.id,{...h,rowData:j})})},[l,c,i]),d=f.useMemo(()=>({click:u}),[u]),p=f.useMemo(()=>FC(e,t,o),[e,t]);return s.jsx(ve,{echarts:Y,option:p,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function WC({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!c||!u?null:s.jsx(Te,{width:c,height:u,children:s.jsx(GC,{variables:i,width:We(c),height:Re(u),data:l,conf:o,interactionManager:n})})}class RC extends re{constructor(){super(...arguments);E(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const QC={displayName:"Merico Heatmap",displayGroup:"Merico suite",migrator:new RC,name:"merico-heatmap",viewRender:WC,configRender:DC,createConfig:()=>({version:1,config:vr}),triggers:[bo]},UC=[{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"})),YC=[Cu,Su,Tu,ku,_u,Du],vo=()=>({id:"dashboard",version:Di,manifest:{viz:[pr,zj,sw,cb,ev,ey,k0,Fu,Lp,_g,lm,Nw,qm,ng,jj,_y,eb,dw,rC,QC,yC,Kp],color:[...UC,...YC]}}),nn=new zu,ce={pluginManager:st("pluginManager"),vizManager:st("vizManager"),colorManager:st("colorManager"),instanceScope:{panelModel:st("panelModel"),vizInstance:st("vizInstance"),interactionManager:st("interactionManager"),migrator:st("migrator"),operationManager:st("operationManager"),triggerManager:st("triggerManager")}},wr=()=>{try{nn.install(vo())}catch{}const e=new ju(nn),t=new Au(nn);return{pluginManager:nn,vizManager:e,colorManager:t}},et=f.createContext(wr());try{nn.install(vo())}catch{}const Cr=f.createContext(null);function Nn(e){const t=f.useContext(Cr),n=V.useCreation(()=>e.configure(t||new ps),[e.configure]),r=V.usePrevious(n);return r&&r!==n&&r.dispose(),s.jsx(Cr.Provider,{value:n,children:e.children})}function wo(){return f.useContext(Cr)}const KC=({description:e,isDescriptionEmpty:t})=>t?null:s.jsx(a.Tooltip,{color:"white",label:s.jsx(An,{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"})})}),XC=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(KC,{description:n,isDescriptionEmpty:r})]}),checked:o||!1,onChange:c=>l(c.currentTarget.checked),...i,pt:".4em",styles:{input:{borderColor:"#e9ecef"}}})]})),JC=({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 I(o).add(r-1,"days").toDate()},[o,l,r]),p=h=>{const[x,m]=h;t(h),x&&m&&n()};return s.jsx(jc.DatePicker,{defaultDate:c,numberOfColumns:2,type:"range",value:e,onChange:p,onNextMonth:console.log,minDate:u,maxDate:d,allowSingleDateInRange:i})},ZC=({begin:e,end:t})=>{const n=f.useMemo(()=>I(t).diff(I(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})})},HC=({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,eS={last:[{label:"yesterday",value:"yesterday",getRange:()=>{const e=Date.now();return[I(e).subtract(1,"day").startOf("day").toDate(),I(e).subtract(1,"day").endOf("day").toDate()]}},{label:"week",value:"last week",getRange:()=>{const e=Date.now();return[I(e).subtract(1,"week").startOf("week").toDate(),I(e).subtract(1,"week").endOf("week").toDate()]}},{label:"month",value:"last month",getRange:()=>{const e=Date.now();return[I(e).subtract(1,"month").startOf("month").toDate(),I(e).subtract(1,"month").endOf("month").toDate()]}},{label:"2 months",value:"last 2 months",getRange:()=>{const e=Date.now();return[I(e).subtract(2,"month").startOf("month").toDate(),I(e).subtract(1,"month").endOf("month").toDate()]}},{label:"3 months",value:"last 3 months",getRange:()=>{const e=Date.now();return[I(e).subtract(3,"month").startOf("month").toDate(),I(e).subtract(1,"month").endOf("month").toDate()]}},{label:"year",value:"last year",getRange:()=>{const e=Date.now();return[I(e).subtract(1,"year").startOf("year").toDate(),I(e).subtract(1,"year").endOf("year").toDate()]}}],recent:[{label:"7 days",value:"recent 7 days",getRange:()=>{const e=Date.now();return[I(e).subtract(7,"day").startOf("day").toDate(),I(e).subtract(1,"day").endOf("day").toDate()]}},{label:"30 days",value:"recent 30 days",getRange:()=>{const e=Date.now();return[I(e).subtract(30,"day").startOf("day").toDate(),I(e).subtract(1,"day").endOf("day").toDate()]}},{label:"60 days",value:"recent 60 days",getRange:()=>{const e=Date.now();return[I(e).subtract(60,"day").startOf("day").toDate(),I(e).subtract(1,"day").endOf("day").toDate()]}},{label:"90 days",value:"recent 90 days",getRange:()=>{const e=Date.now();return[I(e).subtract(90,"day").startOf("day").toDate(),I(e).subtract(1,"day").endOf("day").toDate()]}},{label:"180 days",value:"recent 180 days",getRange:()=>{const e=Date.now();return[I(e).subtract(180,"day").startOf("day").toDate(),I(e).subtract(1,"day").endOf("day").toDate()]}},{label:"365 days",value:"recent 365 days",getRange:()=>{const e=Date.now();return[I(e).subtract(365,"day").startOf("day").toDate(),I(e).subtract(1,"day").endOf("day").toDate()]}}],this:[{label:"today",value:"today",getRange:()=>{const e=Date.now();return[I(e).startOf("day").toDate(),I(e).endOf("day").toDate()]}},{label:"week",value:"this week",getRange:()=>{const e=Date.now();return[I(e).startOf("week").toDate(),I(e).endOf("week").toDate()]}},{label:"month",value:"this month",getRange:()=>{const e=Date.now();return[I(e).startOf("month").toDate(),I(e).endOf("month").toDate()]}},{label:"2 months",value:"this 2 months",getRange:()=>{const e=Date.now();return[I(e).startOf("month").toDate(),I(e).add(1,"month").endOf("week").toDate()]}},{label:"3 months",value:"this 3 months",getRange:()=>{const e=Date.now();return[I(e).startOf("month").toDate(),I(e).add(2,"month").endOf("week").toDate()]}},{label:"year",value:"this year",getRange:()=>{const e=Date.now();return[I(e).startOf("year").toDate(),I(e).endOf("year").toDate()]}}]},tS=({onChange:e})=>{const t=n=>()=>{const r=n();e(r)};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(eS).map(([n,r])=>s.jsxs("tr",{children:[s.jsx("th",{children:s.jsx(a.Text,{size:"xs",color:"#555",children:n})}),r.map(({label:i,value:o,getRange:l})=>s.jsx("td",{children:s.jsx(a.Button,{compact:!0,size:"xs",variant:"subtle",onClick:t(l),children:i})},i))]},n))})})]})},Co=e=>({label:{display:"block",height:"21.7px"},input:{borderColor:e?"#228be6":"#e9ecef"}}),nS=({label:e,required:t,value:n,onChange:r,max_days:i,allowSingleDateInRange:o,inputFormat:l})=>{const[c,{open:u,close:d}]=oe.useDisclosure(!1),[p,h]=n,x=p?I(p).format(l):"",m=h?I(h).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:Co(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(ZC,{begin:p,end:h})}),icon:s.jsx(k.IconMinus,{size:16}),placeholder:"End date",readOnly:!0,disabled:!p,value:m,onFocus:u,styles:Co(c),sx:{".mantine-Input-icon":{transform:"translateX(-22px)"},".mantine-Input-input":{borderLeft:"none",borderTopLeftRadius:0,borderBottomLeftRadius:0}}})]}),s.jsxs(a.Popover.Dropdown,{p:"sm",children:[s.jsx(HC,{max_days:i}),s.jsx(JC,{value:n,onChange:r,close:d,allowSingleDateInRange:o,max_days:i}),s.jsx(tS,{onChange:r})]})]})},So=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(p=>p?I(p).toDate():null):[null,null],d=p=>{r(p.map(h=>h&&I(h).format(i)))};return s.jsx(nS,{label:e,value:u,onChange:d,inputFormat:i,allowSingleDateInRange:c,max_days:l,required:o})}),sS=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"}}})),_o=({errorMessage:e})=>e?s.jsx(a.Text,{color:"red",size:12,children:e}):s.jsx(a.Text,{color:"dimmed",size:12,children:"Not found"}),rS=({disabled:e,classNames:t,styles:n,unstyled:r,radius:i,style:o,label:l,value:c,onChange:u,options:d,errorMessage:p,required:h})=>{const{classes:x,cx:m}=sS({radius:i},{name:"MultiSelectWidget",classNames:t,styles:n,unstyled:r}),[j,w]=f.useState(!1),T=Q=>{w(Q)},M=j&&(c==null?void 0:c.length)>0,[P,U]=f.useState(""),se=f.useMemo(()=>{if(!P)return d;const Q=P.toLowerCase(),ie=de=>{var fe;return((fe=de.description)==null?void 0:fe.toLowerCase().includes(Q))||de.label.toLowerCase().includes(Q)};return d.filter(ie)},[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,h&&s.jsx("span",{className:x.required,"aria-hidden":"true",children:"*"})]}),M&&s.jsx(a.Tooltip,{label:`${c.length} selected`,children:s.jsx(a.Badge,{children:c.length})})]}),s.jsx(xi,{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(_o,{errorMessage:p}),maxTagTextLength:10,maxTagPlaceholder:Q=>`${Q.length} selected`,searchValue:P,onSearch:U,filterOption:!1,children:se.map(Q=>s.jsxs(xi.Option,{title:Q.label,children:[s.jsx(a.Text,{size:"sm","data-role":"label",children:Q.label}),Q.description&&s.jsx(a.Text,{size:"xs",color:"dimmed","data-role":"description",children:Q.description})]},Q.value))})]})},iS=S.observer(({label:e,config:t,value:n,onChange:r})=>{const i=le(),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",p=o?u:!1,h=x=>r(x,!1);return s.jsx(rS,{label:e,options:t.options,style:{minWidth:"160px",width:d,maxWidth:p?d:"unset",borderColor:"#e9ecef"},disabled:p,value:n,onChange:h,errorMessage:c,required:t.required})}),aS=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})]})})})),oS=S.observer(({label:e,config:t,value:n,onChange:r})=>{const i=le(),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:aS})});function lS({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 cS=({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"})}),uS=({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(cS,{rotate:e?"0":"-90",onClick:r,...i})),dS=({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"})]}),pS=({onClick:e,...t})=>s.jsx(dS,{onClick:e,...t}),hS=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"}}}})),xS=({disabled:e,classNames:t,styles:n,unstyled:r,radius:i,style:o,label:l,value:c,onChange:u,treeData:d,errorMessage:p,required:h,treeCheckStrictly:x})=>{const{classes:m,cx:j}=hS({radius:i},{name:"FilterTreeSelectWidget",classNames:t,styles:n,unstyled:r}),[w,T]=f.useState(!1),M=U=>{T(U)},P=w&&(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,h&&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(fi,{disabled:e,allowClear:!0,treeCheckStrictly:x,labelInValue:!0,className:j(m.root,"check-select"),dropdownClassName:j(m.dropdown,""),onDropdownVisibleChange:M,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:uS,treeIcon:pS,maxTagTextLength:10,value:c,treeData:d,notFoundContent:s.jsx(_o,{errorMessage:p}),treeNodeFilterProp:"filterBasis",treeCheckable:!0,showCheckedStrategy:fi.SHOW_PARENT,onChange:u,onSelect:console.log,maxTagCount:0,maxTagPlaceholder:()=>`${c.length} selected`})]})},fS=S.observer(({label:e,config:t,value:n,onChange:r})=>{const{treeData:i,treeDataLoading:o,errorMessage:l}=t,[c,u]=f.useState(t.valueObjects(n)),d=m=>{u(m);const j=m.map(w=>w.value);r(j,!1)};f.useEffect(()=>{u(t.valueObjects(n))},[n]);const p=t.min_width?t.min_width:"200px",x=!!t.options_query_id?o:!1;return s.jsx(xS,{disabled:x,style:{minWidth:"160px",width:p,maxWidth:x?p:"unset",borderColor:"#e9ecef"},value:c,onChange:d,treeData:i,errorMessage:l,label:e,required:t.required,treeCheckStrictly:t.treeCheckStrictly})}),gS=S.observer(({filter:{type:e,config:t,key:n,...r},formFieldProps:i})=>{switch(e){case"select":return s.jsx(oS,{...r,...i,config:t});case"multi-select":return s.jsx(iS,{...r,...i,config:t});case"tree-select":return s.jsx(fS,{...r,...i,config:t});case"text-input":return s.jsx(lS,{...r,...i,config:t});case"date-range":return s.jsx(So,{...r,...i,config:t});case"checkbox":return s.jsx(XC,{...r,...i,config:t});default:return null}}),mS=S.observer(f.forwardRef(({filter:e,...t},n)=>s.jsx("div",{className:"filter-root",ref:n,children:s.jsx(Ce,{children:s.jsx(gS,{filter:e,formFieldProps:t})})}))),yS=({disabled:e})=>{const{searchButtonProps:t}=Ai(),{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 bS(e){const t=X();f.useEffect(()=>{var n,r;(r=(n=t.filters).updatePreviewValues)==null||r.call(n,e)},[e])}const ko=S.observer(function({view:t}){const n=le(),{control:r,handleSubmit:i,reset:o}=b.useForm({defaultValues:n.filters.values,reValidateMode:"onBlur"}),l=b.useWatch({control:r});f.useEffect(()=>{o(n.filters.values)},[n.filters.values,o]),bS(l);const c=n.filters.visibleInView(t.id),u=f.useMemo(()=>c.every(x=>x.should_auto_submit),[c]),d=f.useMemo(()=>c.filter(x=>y.get(x,"config.required",!1)),[c]),p=f.useMemo(()=>d.length===0?!1:d.some(x=>!x.requiredAndPass(l[x.key])),[l,d]);if(c.length===0)return null;const h=(x,m)=>(j,w)=>{m(j),(x.should_auto_submit||w)&&n.filters.setValueByKey(x.key,j)};return s.jsx("form",{onSubmit:i(n.filters.setValues),children:s.jsxs(a.Group,{className:"dashboard-filters",position:"apart",noWrap:!0,sx:u?{}:{border:"1px solid #e9ecef",borderRadius:"4px",padding:"16px"},children:[s.jsx(a.Group,{align:"flex-start",children:c.map(x=>s.jsx(b.Controller,{name:x.key,control:r,render:({field:m})=>s.jsx(mS,{filter:x,value:m.value,onChange:h(x,m.onChange)})},x.id))}),!u&&s.jsx(a.Group,{sx:{alignSelf:"flex-end"},children:s.jsx(yS,{disabled:p})})]})})}),jS={viewPanelInFullScreen:y.noop,inFullScreen:!1},qn=f.createContext(jS),To=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 Do(e){return{current:e}}const vS=g.types.model("PanelLayoutMeta",{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{x:t,y:n,w:r,h:i,moved:o}=e;return{h:i,w:r,x:t,y:n===null?0:n,moved:o,static:e.static}}})).actions(e=>({set(t){const{x:n,y:r,w:i,h:o,moved:l}=t;e.x=n,e.y=r,e.w=i,e.h=o,e.moved=!!l,e.static=!!t.static},setWidth(t){e.w=t},setHeight(t){e.h=t}})),wS=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}})),CS=g.types.model("PanelStyleMeta",{border:wS}).views(e=>({get json(){const{border:t}=e;return{border:t.json}}})).actions(e=>({})),SS=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}})),_S=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)}),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})}})),kS=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}})),TS=g.types.model({id:g.types.string,name:g.types.optional(g.types.string,""),title:SS,description:g.types.string,layout:vS,queryIDs:g.types.array(g.types.string),viz:kS,style:CS,variables:g.types.optional(g.types.array(_S),[])}).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,layout:e.layout.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)}})),Fn=e=>y.cloneDeepWith(e,(t,n)=>{if(n!==void 0&&t)return W.toJS(t)});var Ie=(e=>(e.Postgresql="postgresql",e.MySQL="mysql",e.HTTP="http",e))(Ie||{});const DS=g.types.model("QueryMeta",{id:g.types.string,name:g.types.string,type:g.types.enumeration("DataSourceType",[Ie.Postgresql,Ie.MySQL,Ie.HTTP]),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),[])}).views(e=>({get valid(){return e.id&&e.type&&e.key&&e.name?e.type===Ie.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}=e;return Fn({id:t,key:i,sql:o,name:n,type:r,run_by:l,react_to:c,pre_process:u,post_process:d})}})).actions(e=>({setName(t){e.name=t},setKey(t){e.key=t},setType(t){e.type=t},setSQL(t){e.sql=t},setRunBy(t){e.run_by.length=0,e.run_by.push(...t)},setReactTo(t){e.react_to.length=0,e.react_to.push(...t)},setPreProcess(t){e.pre_process=t},setPostProcess(t){e.post_process=t}})),IS=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 ue=(e=>(e.Select="select",e.MultiSelect="multi-select",e.TreeSelect="tree-select",e.TextInput="text-input",e.Checkbox="checkbox",e.DateRange="date-range",e))(ue||{});const Io=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}})),MS=()=>Io.create({_name:"checkbox",description:"",default_value:!1});function Mo(e,t){return e.map(n=>{try{return n?I.tz(n,"UTC").format(t):null}catch{return console.log(`[date-range] failed parsing ${n}`),null}})}const AS=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]),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,allowSingleDateInRange:c}=e;return{_name:t,max_days:n,required:r,clearable:i,inputFormat:o,default_value:Mo(l,o),allowSingleDateInRange:c}},truthy(t){return Array.isArray(t)&&t.length===2&&t.every(n=>!!n)}})).actions(e=>({setFilterValue(t){try{const n=g.getParent(e);g.getRoot(e).filters.setValueByKey(n.key,t)}catch(n){console.error(n)}}})).actions(e=>({setRequired(t){e.required=t},setClearable(t){e.clearable=t},setInputFormat(t){e.inputFormat=t},setDefaultValue(t){e.default_value.length=0,e.default_value.push(...t),e.setFilterValue(t)},setMaxDays(t){e.max_days=t,t>0&&(e.clearable=!0)},setAllowSingleDateInRange(t){e.allowSingleDateInRange=t}})),Ao=g.types.snapshotProcessor(AS,{preProcessor({default_value:e,...t}){return{...t,default_value:e.map(n=>n===null?null:I.tz(n,"UTC").toISOString())}},postProcessor(e){const{default_value:t,...n}=e;return{...n,default_value:Mo(t,n.inputFormat)}}}),zS=()=>Ao.create({_name:"date-range",required:!1,inputFormat:"YYYY-MM-DD",clearable:!1,default_value:[null,null]}),ES=g.types.model({label:g.types.string,value:g.types.string}).actions(e=>({setLabel(t){e.label=t},setValue(t){e.value=t}})),Sr=g.types.model("FilterConfigModel_BaseSelect",{static_options:g.types.optional(g.types.array(ES),[]),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 usingQuery(){return!!e.options_query_id}})).views(e=>({get options(){if(!e.usingQuery)return e.static_options;const{data:t,state:n,error:r}=e.contentModel.getDataStuffByID(e.options_query_id);return n==="idle"?Array.isArray(t)?t:[]:[]}})).actions(e=>({setRequired(t){e.required=t},addStaticOption(t){e.static_options.push(t)},removeStaticOption(t){e.static_options.splice(t,1)},setDefaultSelectionCount(t){e.default_selection_count=t},setOptionsQueryID(t){e.options_query_id=t??""}})),zo=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),[])}),Sr).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 Fn({_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.default_value},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;t.setValueByKey(n,e.default_selection)}})).actions(e=>({afterCreate(){g.addDisposer(e,W.reaction(()=>W.toJS(e.default_selection),e.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),PS=()=>zo.create({_name:"multi-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),Eo=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,"")}),Sr).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 Fn({_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.default_value}})).actions(e=>({setDefaultValue(t){e.default_value=t},setWidth(t){e.width=t},setDefaultSelection(){const t=g.getRoot(e).content.filters,n=g.getParent(e).key;t.setValueByKey(n,e.default_selection)}})).actions(e=>({afterCreate(){g.addDisposer(e,W.reaction(()=>W.toJS(e.default_selection),e.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),LS=()=>Eo.create({_name:"select",required:!1,default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),Po=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}})),Lo=()=>Po.create({_name:"text-input",required:!1,default_value:""});function OS(e){return vc.arrayToTree(e,{id:"value",parentId:"parent_value",childrenField:"children",dataField:null})}function BS(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 Oo=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)}),Sr).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=BS(t);return OS(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{default_selection_count:t}=e;return t?this.treeData.slice(0,t).map(r=>r.value):[]},truthy(t){return Array.isArray(t)&&t.length>0},valueObjects(t){const n=new Set(t);return this.plainData.filter(r=>n.has(r.value))}})).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;e.contentModel.filters.setValueByKey(t,e.defaultSelection)},afterCreate(){g.addDisposer(e,W.reaction(()=>JSON.stringify(e.defaultSelection),this.applyDefaultSelection,{fireImmediately:!0,delay:0}))}})),$S=()=>Oo.create({_name:"tree-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),Bo=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),type:g.types.enumeration("DashboardFilterType",[ue.Select,ue.MultiSelect,ue.TreeSelect,ue.TextInput,ue.Checkbox,ue.DateRange]),config:g.types.union(Eo,zo,Oo,Po,Io,Ao)}).views(e=>({get plainDefaultValue(){const t=e.config.default_value;return Array.isArray(t)?[...t]:t},get usingDefaultValue(){return e.type!==ue.TreeSelect},get auto_submit_supported(){return[ue.Select,ue.Checkbox,ue.DateRange].includes(e.type)}})).views(e=>({get json(){const{id:t,key:n,label:r,order:i,visibleInViewsIDs:o,auto_submit:l,type:c,config:u}=e;return{id:t,key:n,type:c,label:r,order:i,config:u.json,auto_submit:l,visibleInViewsIDs:W.toJS(o)}},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 ue.Select:e.config=LS();break;case ue.MultiSelect:e.config=PS();break;case ue.TreeSelect:e.config=$S();break;case ue.TextInput:e.config=Lo();break;case ue.Checkbox:e.config=MS();break;case ue.DateRange:e.config=zS();break}e.type=t},setVisibleInViewsIDs(t){e.visibleInViewsIDs.length=0,e.visibleInViewsIDs.push(...t)},setAutoSubmit(t){e.auto_submit=e.auto_submit_supported&&t}}));var L=(e=>(e.Division="div",e.Modal="modal",e.Tabs="tabs",e))(L||{});const $o=g.types.model("ViewDivisionConfig",{_name:g.types.literal(L.Division)}).views(e=>({get json(){const{_name:t}=e;return{_name:t}}})),VS=()=>$o.create({_name:L.Division}),NS=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}})),_r={enabled:!1,func_content:["function text({ filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
|
|
446
|
-
`)},Vo=g.types.model("ViewModalConfig",{_name:g.types.literal(L.Modal),width:g.types.string,height:g.types.string,custom_modal_title:g.types.optional(NS,_r)}).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}})),qS=()=>Vo.create({_name:L.Modal,width:"90vw",height:"90vh"}),FS=g.types.model("ViewTabsTabModel",{id:g.types.identifier,name:g.types.string,view_id:g.types.string,color:g.types.optional(g.types.string,"")}).views(e=>({get json(){const{id:t,name:n,view_id:r,color:i}=e;return{id:t,name:n,color:i,view_id:r}}})).actions(e=>({setName(t){e.name=t},setViewID(t){e.view_id=t},setColor(t){e.color=t}})),No=g.types.model("ViewTabsConfig",{_name:g.types.literal(L.Modal),tabs:g.types.optional(g.types.array(FS),[]),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}}})).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=oe.randomId(),n={id:t,name:t,view_id:""};e.tabs.push(n)},removeTab(t){e.tabs.splice(t,1)}})),GS=()=>No.create({_name:L.Modal,tabs:[]}),WS=g.types.model({id:g.types.identifier,name:g.types.string,type:g.types.enumeration("EViewComponentType",[L.Division,L.Modal,L.Tabs]),config:g.types.union($o,Vo,No),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 L.Division:e.config=VS();break;case L.Modal:e.config=qS();break;case L.Tabs:e.config=GS();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)}})),qo=g.types.model("DataSourceMetaModel",{id:g.types.string,type:g.types.enumeration("DataSourceType",[Ie.HTTP,Ie.MySQL,Ie.Postgresql]),key:g.types.string,config:g.types.frozen()}),RS=g.types.model("DataSourcesMetaModel",{list:g.types.optional(g.types.array(qo),[])}).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)}})),QS=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}),Fo=g.types.model("GlobalSQLSnippetsMeta",{list:g.types.optional(g.types.array(QS),[])}).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)}})),kr=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 Go(e){return kr.create({current:e})}const Wo=g.types.compose("ViewRenderModel",WS,g.types.model({tab:g.types.optional(g.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 g.getParent(e,3)},get panels(){if(e.type!==L.Tabs)return this.contentModel.panels.panelsByIDs(e.panelIDs).panels;const t=this.tabViewID;return this.contentModel.views.findByID(t).panels},get renderViewIDs(){const t=[e.id];return e.type===L.Tabs&&t.push(this.tabViewID),t}})).actions(e=>({setTab(t){e.tab=t??""},afterCreate(){g.addDisposer(e,W.reaction(()=>e.defaultTab,t=>this.setTab(t),{fireImmediately:!0,delay:0}))}})),Ro=g.types.model("ViewsRenderModel",{current:g.types.optional(g.types.array(Wo),[]),visibleViewIDs:g.types.array(g.types.string)}).views(e=>({get json(){return e.current.map(t=>Fn(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 US(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 YS=new wc.AsyncParser({withBOM:!0});async function Qo(e){return!Array.isArray(e)||e.length===0?"":await YS.parse(e).promise()}async function KS(e,t){const n=await Qo(t),r=new Blob([n],{type:"text/csv"});rs.saveAs(r,`${e}.csv`)}function Uo(e){const t=new Cc,n=e.map(async({id:r,data:i})=>{const o=await Qo(i);t.file(`${r}.csv`,o)});Promise.all(n).then(()=>{t.generateAsync({type:"blob"}).then(r=>{rs.saveAs(r,"dashboard_data.zip")})}).catch(r=>{console.error(r),xt.notifications.show({color:"red",title:"Failed to download data",message:r.message})})}function Ct(e,t){const n=new Blob([t],{type:"application/json"});rs.saveAs(n,`${e}.json`)}const Yo=TS.views(e=>({get contentModel(){return g.getRoot(e).content}})).views(e=>({get queries(){return e.contentModel.queries.findByIDSet(e.queryIDSet)},get data(){return this.queries.reduce((t,n)=>(t[n.id]=n.data,t),{})},get variableStrings(){return Wi(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)}},downloadSchema(){const{panel:t,queries:n}=this.getSchema(),i=JSON.stringify({panels:[t],definition:{queries:n}},null,2),o=e.name;Ct(o,i)}}));function XS(e){return{id:e,name:e,layout:{x:0,y:1/0,w:18,h:300},title:{show:!0},description:"<p></p>",queryIDs:[],viz:{type:pr.name,conf:pr.createConfig()},style:{border:{enabled:!0}}}}const Ko=g.types.model("PanelsRenderModel",{list:g.types.optional(g.types.array(Yo),[])}).views(e=>({get json(){return e.list.map(t=>t.json)},findByID(t){return e.list.find(n=>n.id===t)},get idMap(){const t=new Map;return e.list.forEach(n=>{t.set(n.id,n)}),t}})).views(e=>({panelsByIDs(t){const n=[];t.forEach(i=>{const o=e.idMap.get(i);o?n.push(o):console.warn(`Panel is not found, id:${i}`)});const r=n.map(i=>({...i.layout.json,i:i.id}));return{panels:n,layouts:r}}}));function Xo(e,t){if(e===void 0)return e;if(t._name==="date-range")try{const[...n]=e;return n.map(r=>r===null?r:I.tz(r,"UTC").format(t.inputFormat)??r)}catch(n){return console.error(n),e}return e}function JS(e){return e.reduce((t,n)=>(t[n.key]=Xo(n.config.default_value,n.config),t),{})}const Jo=g.types.model("FiltersRenderModel",{current:g.types.optional(g.types.array(Bo),[]),values:g.types.optional(g.types.frozen(),{})}).views(e=>({get json(){return e.current.map(t=>t.json)},get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(n=>n.id===t)},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},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:[]}))}},downloadSchema(t){const n=JSON.stringify(this.getSchema(t,!1),null,2);Ct("Filters",n)}}));function Zo(e){return{current:e,values:JS(e)}}function ZS(e,t){return new Function(`return ${e}`)()(t,gt)}function HS(e,t,n){return ZS(e,{context:t,filters:n})}function e1(e,t){try{return new Function(`return ${e.config.processing.pre}`)()(t,gt)}catch(n){return console.error(n),t}}function t1(e,t){return new Function(`return ${e.config.processing.post}`)()(t,gt)}function n1(e,t,n){return e?new Function(`return ${e}`)()(t,gt,n):t}const Gn={sqlSnippet:new RegExp("(?<=sql_snippets\\.)([^\\?}.]+)","gm"),context:new RegExp("(?<=context\\.)([^\\?}.]+)","gm"),filter:new RegExp("(?<=filters\\.)([^\\?}.]+)","gm")},s1=DS.views(e=>({get rootModel(){return g.getRoot(e)},get contentModel(){return this.rootModel.content},get conditionOptions(){if(!g.isAlive(e))return[];const t=g.getRoot(e).content,{context:n}=t.payloadForSQL,r=Object.keys(n).map(o=>({group:"Context",label:o,value:`context.${o}`,description:void 0})),i=t.filters.keyLabelOptions.map(o=>({group:"Filters",label:o.label,value:`filters.${o.value}`,description:o.value}));return[...r,...i]},get unmetRunByConditions(){if(!g.isAlive(e))return[];const{run_by:t}=e;if(t.length===0)return[];const n=g.getRoot(e).content.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 ls(e.sql,this.payload)},get httpConfigString(){const{context:t,filters:n}=this.payload,{name:r,pre_process:i}=e.json,o=HS(i,t,n);return console.groupCollapsed(`Request config for: ${r}`),console.log(o),console.groupEnd(),JSON.stringify(o)},get typedAsSQL(){return[Ie.Postgresql,Ie.MySQL].includes(e.type)},get typedAsHTTP(){return[Ie.HTTP].includes(e.type)},get reQueryKey(){const{react_to:t=[]}=e;if(t.length===0)return"";const n=g.getRoot(e).content.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}=g.getRoot(e).content.filters,n=e.unmetRunByConditions.filter(i=>i.startsWith("context.")).map(i=>i.split("context.")[0]),r=e.unmetRunByConditions.filter(i=>i.startsWith("filters.")).map(i=>y.get({filters:t},i)).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(Gn.sqlSnippet)),n=y.uniq(e.sql.match(Gn.filter)),r=y.uniq(e.sql.match(Gn.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}})),r1=g.types.compose("QueryRenderModel",s1,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)}})).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(mu({payload:n,name:e.name,query:e.json,additionals:e.additionalQueryInfo},e.controller.signal)),e.state="idle",e.error=null}catch(n){if(!tt.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=e1(e.datasource,o);const l=yield*g.toGenerator(yu({type:n,key:r,configString:JSON.stringify(o),name:e.name,additionals:e.additionalQueryInfo},e.controller.signal)),c=t1(e.datasource,l),u=n1(i,c,e.contentModel.dashboardState);e.data=u,e.state="idle",e.error=null}catch(n){if(console.error(n),!tt.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"}}}})})).actions(e=>({fetchData:t=>{if(!e.inUse&&!t){console.debug(`Skipping query[${e.name}]`);return}return e.typedAsHTTP?e.runHTTP():e.runSQL()},beforeDestroy(){var t;(t=e.controller)==null||t.abort()}})).actions(e=>({afterCreate(){g.addDisposer(e,W.reaction(()=>{var n;return e.typedAsHTTP?`${e.inUse}--${e.id}--${e.key}--${e.reQueryKey}--${(n=e.datasource)==null?void 0:n.id}`:[e.inUse,e.id,e.key,e.formattedSQL,e.pre_process,e.post_process].join("--")},()=>e.fetchData(!1),{fireImmediately:!0,delay:0}))}})),Ho=g.types.model("QueriesRenderModel",{current:g.types.optional(g.types.array(r1),[])}).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}=this.contentModel,r=[];t.visibleViews.forEach(l=>{l.panels.forEach(c=>{r.push(...c.queryIDs)})});const i=y.uniq(t.visibleViews.map(l=>l.renderViewIDs).flat());n.current.forEach(l=>{const c=y.get(l,"config.options_query_id");if(!c)return;i.some(d=>l.visibleInViewsIDSet.has(d))&&r.push(c)});const o=new Set(r);return console.debug("QueryIDs:",o),o},isQueryInUse(t){return this.visibleQueryIDSet.has(t)}})).actions(e=>({downloadAllData(){const t=e.current.map(({name:n,data:r})=>({id:n,data:r}));Uo(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}));Uo(r)},downloadDataByQueryID(t){const n=e.findByID(t);if(!n){console.log("[downloadDataByQueryID] query not found");return}const{name:r,data:i}=n;KS(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)}}},downloadSchema(t){const n=JSON.stringify(this.getSchema(t),null,2);Ct("Queries",n)}}));function i1(e){return{current:e}}const a1=IS.views(e=>({isADuplicatedKey(t){return!t||t===e.key?!1:!!g.getParent(e,2).findByKey(t)}})),el=g.types.model("SQLSnippetsRenderModel",{current:g.types.optional(g.types.array(a1),[])}).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)}}},downloadSchema(t){const n=JSON.stringify(this.getSchema(t),null,2);Ct("SQL Snippets",n)}}));function o1(e){return{current:e}}function Wn(e,t,n,r){return e.reduce((i,o)=>{try{i[o[t]]=os(o[n],r)}catch(l){i[o[t]]=l.message}return i},{})}class l1{constructor(t){E(this,"origin");E(this,"copy");this.origin=t,this.copy=g.clone(t),W.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 c1=e=>new l1(e),u1=S.observer(({view:e})=>{const t=K(),n=X(),r=Me.useModals(),{panel:i,downloadPanelScreenshot:o}=Le(),{id:l}=i,{viewPanelInFullScreen:c,inFullScreen:u}=f.useContext(qn),d=()=>{n.duplicatePanelByID(l,e.id)},p=()=>{t.editor.open(["_VIEWS_",e.id,"_PANELS_",l])},h=()=>r.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>n.removePanelByID(l,e.id),confirmProps:{color:"red"},zIndex:320}),x=f.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(_.Refresh,{size:14}),children:"Refresh"}),s.jsx(a.Menu.Item,{onClick:i.downloadData,icon:s.jsx(_.Download,{size:14}),children:"Download Data"}),s.jsx(a.Menu.Item,{onClick:i.downloadSchema,icon:s.jsx(k.IconCode,{size:14}),children:"Download Schema"}),s.jsx(a.Menu.Item,{onClick:o,icon:s.jsx(k.IconCamera,{size:14}),children:"Screenshot"}),m&&s.jsx(a.Menu.Item,{onClick:x,icon:s.jsx(_.ArrowsMaximize,{size:14}),disabled:!0,children:"Full Screen"}),s.jsx(a.Divider,{label:"Edit",labelPosition:"center"}),s.jsx(a.Menu.Item,{onClick:p,icon:s.jsx(_.Settings,{size:14}),children:"Settings"}),s.jsx(a.Menu.Item,{onClick:d,icon:s.jsx(_.Copy,{size:14}),children:"Duplicate"}),s.jsx(a.Menu.Item,{color:"red",onClick:h,icon:s.jsx(_.Trash,{size:14}),children:"Delete"})]})]})})})});function d1(e){return e?["<p><br></p>","<p></p>"].includes(e):!0}const Tr=S.observer(()=>{const[e,t]=f.useState(!1),{panel:n}=dt();return d1(n.description)?null:s.jsxs(s.Fragment,{children:[s.jsx(a.Modal,{opened:e,onClose:()=>t(!1),title:n.name,withCloseButton:!1,withinPortal:!0,zIndex:310,children:s.jsx(An,{value:n.description,styles:{root:{border:"none"},content:{padding:0}}})}),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(_.InfoCircle,{size:20})})})]})}),pI="",p1=S.observer(function(){const{panel:t}=dt(),{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 h1(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;gi.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 tl=(e=>(e.migrated="migrated",e.nothingToMigrate="nothingToMigrate",e.checkFailed="checkFailed",e.migrationFailed="migrationFailed",e))(tl||{}),Rn=(e=>(e.notStarted="notStarted",e.inProgress="inProgress",e.done="done",e))(Rn||{});class x1{constructor(t){E(this,"vizInstance");E(this,"operationManager");E(this,"triggerManager");E(this,"vizManager");E(this,"runningMigration");E(this,"panelModel");E(this,"status","notStarted");this.panelModel=t.getRequired(ce.instanceScope.panelModel),this.vizInstance=t.getRequired(ce.instanceScope.vizInstance),this.operationManager=t.getRequired(ce.instanceScope.operationManager),this.triggerManager=t.getRequired(ce.instanceScope.triggerManager),this.vizManager=t.getRequired(ce.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 nl(e){const{panel:t}=dt();return f.useCallback(n=>{const r=n.getRequired(ce.vizManager),i=r.resolveComponent(e.viz.type);return n.createScoped().provideFactory(ce.instanceScope.vizInstance,()=>r.getOrCreateInstance(e)).provideFactory(ce.instanceScope.interactionManager,o=>{const l=o.getRequired(ce.instanceScope.vizInstance);return new Cs(l,i,xn)}).provideFactory(ce.instanceScope.operationManager,o=>o.getRequired(ce.instanceScope.interactionManager).operationManager).provideFactory(ce.instanceScope.triggerManager,o=>o.getRequired(ce.instanceScope.interactionManager).triggerManager).provideValue(ce.instanceScope.panelModel,t).provideFactory(ce.instanceScope.migrator,o=>new x1(o))},[e.viz.type,e.viz.conf])}function sl(e){const[t,n]=f.useState(!1),r=wo().getRequired(ce.instanceScope.migrator);return V.useAsyncEffect(async()=>{const i=r.status===Rn.notStarted;n(r.status===Rn.done),r.status===Rn.notStarted&&r.runMigration().then(o=>{o===tl.migrated&&i&&(e==null||e())}).finally(()=>{n(!0)})},[r]),t}function rl(e,t){const n=wo().getRequired(ce.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 f1({setVizConf:e,...t}){const{panel:n}=t,r=rl(e,n),i=sl(()=>{xt.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(wu,{...t}):s.jsx(a.Text,{children:"Checking update..."})}function g1(e){const{panel:t,setVizConf:n}=e;rl(n,t);const{inEditMode:r}=f.useContext(pn);return sl(()=>{r&&xt.showNotification({title:`${t.name} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?s.jsx(vu,{...e}):s.jsx(a.Text,{children:"Checking update"})}const hI="";function m1(e,t){const{vizManager:n}=f.useContext(et),{panel:{viz:r,title:i,id:o,name:l,description:c,queryIDs:u,variables:d}}=dt(),p={id:o,name:l,title:i,description:c,queryIDs:u,viz:r,layout:t},h=nl(p);try{return n.resolveComponent(r.type),s.jsx(Nn,{configure:h,children:s.jsx(g1,{setVizConf:r.setConf,panel:p,data:e,variables:d,vizManager:n})})}catch(x){return console.info(y.get(x,"message")),null}}const il=S.observer(function({data:t}){const{ref:n,width:r,height:i}=oe.useElementSize(),o=m1(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(Ce,{children:o})})})}),al=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})]})),Dr=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(al,{panel:e}),e.canRenderViz&&s.jsx(il,{data:e.data})]})),y1={border:"1px solid #e9ecef"},ol=S.observer(({panel:e,panelStyle:t,dropdownContent:n})=>{const{ref:r,downloadPanelScreenshot:i}=h1(e);return e.title.show,s.jsx(bs,{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:{...y1,...t},children:[s.jsx(a.Box,{className:"panel-description-popover-wrapper",children:s.jsx(Tr,{})}),n,s.jsx(p1,{}),s.jsx(Dr,{panel:e})]})})}),b1={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function j1(e){return e.style.border.enabled?{}:b1}const ll=S.observer(function({panel:t,view:n}){const r=j1(t);return s.jsx(ol,{panel:t,panelStyle:r,dropdownContent:s.jsx(u1,{view:n})})});function v1(e){return!["richText","button"].includes(e)}const w1=S.observer(({view:e})=>{const{panel:t,downloadPanelScreenshot:n}=dt(),{id:r}=t,{viewPanelInFullScreen:i,inFullScreen:o}=f.useContext(qn),l=f.useCallback(()=>{i(r)},[r,i]),c=!o&&e.type!==L.Modal;return v1(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(_.Refresh,{size:14}),children:"Refresh"}),s.jsx(a.Menu.Item,{onClick:t.downloadData,icon:s.jsx(_.Download,{size:14}),children:"Download Data"}),s.jsx(a.Menu.Item,{onClick:n,icon:s.jsx(k.IconCamera,{size:14}),children:"Screenshot"}),c&&s.jsx(a.Menu.Item,{onClick:l,icon:s.jsx(_.ArrowsMaximize,{size:14}),children:"Full Screen"})]})]})}):null});function C1(e){return e.style.border.enabled?{}:{border:"1px dashed transparent"}}const Ir=S.observer(({panel:e,view:t})=>{const n=C1(e);return s.jsx(ol,{panel:e,panelStyle:n,dropdownContent:s.jsx(w1,{view:t})})}),S1={modal:{display:"flex",flexDirection:"column",flexWrap:"nowrap"},body:{display:"flex",height:"calc(100vh - 88px)"}},cl=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(_.ArrowLeft,{size:20}),children:"Exit fullscreen"}),styles:S1,children:s.jsx(a.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:s.jsx(Ir,{view:t,panel:n})})})});function ul(e,t,n){const{panels:r}=le(),i=e.id==="Main",[o,l]=f.useState(()=>i&&r.findByID(t)?t:null),c=f.useCallback(h=>{l(h),i&&n(h)},[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 xI="",_1=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(_.ArrowsMove,{size:16})})),k1=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(_.ChevronDownRight,{size:16})})),T1=ln.WidthProvider(ln),D1=S.observer(({view:e,className:t="layout"})=>{const n=le(),{panels:r,layouts:i}=n.panels.panelsByIDs(e.panelIDs),o=f.useCallback(c=>{c.forEach(({i:u,...d})=>{const p=n.panels.findByID(u);p&&p.layout.set(d)})},[n]),l=(c,u,d,p)=>{d.h<30&&(d.h=30,p.h=30),d.w<4&&(d.w=4,p.w=4)};return s.jsx(T1,{onLayoutChange:o,className:`dashboard-layout ${t}`,rowHeight:1,cols:36,margin:[0,0],isBounded:!0,isDraggable:!0,isResizable:!0,layout:i,draggableHandle:".react-grid-customDragHandle",resizeHandle:s.jsx(k1,{}),onResize:l,children:r.map((c,u)=>s.jsxs("div",{"data-grid":{...c.layout},className:"panel-grid-item",children:[s.jsx(_1,{h:c.layout.h}),s.jsx(ll,{view:e,panel:c})]},c.id))})}),I1=ln.WidthProvider(ln),M1=S.observer(function({view:t,className:n="layout"}){const{panels:r,layouts:i}=le().panels.panelsByIDs(t.panelIDs);return s.jsx(I1,{className:`dashboard-layout ${n}`,cols:36,rowHeight:1,margin:[0,0],isDraggable:!1,isResizable:!1,layout:i,children:r.map(o=>s.jsx("div",{"data-grid":{...o.layout},className:"panel-grid-item",children:s.jsx(Ir,{view:t,panel:o})},o.id))})});function Mr(e){const t=f.useRef(null);return{ref:t,downloadScreenshot:()=>{var l;const r=(l=t.current)==null?void 0:l.querySelector(".react-grid-layout");if(!r)return;const i=r.offsetWidth*2+10,o=r.offsetHeight*2+10;gi.toBlob(r,{bgcolor:"white",width:i,height:o,style:{transformOrigin:"0 0",transform:"scale(2)"}}).then(c=>{window.saveAs(c,`${e.name}.png`)})}}}const A1=S.observer(({downloadScreenShot:e})=>{const[t,{setTrue:n,setFalse:r}]=V.useBoolean(!1),i=gs(),o=le(),l=()=>{const c=JSON.stringify(o.contentJSON,null,2),u=`${i.name}__${o.name}`;Ct(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(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:"Screenshot"}),s.jsx(a.Menu.Divider,{}),s.jsx(a.Menu.Item,{icon:s.jsx(k.IconDownload,{size:14}),onClick:o.queries.downloadAllData,children:"Download Data"}),s.jsx(a.Menu.Item,{icon:s.jsx(k.IconCode,{size:14}),onClick:l,children:"Download Schema"})]})]})}),dl=S.observer(({children:e,view:t,sx:n={}})=>{const{ref:r,downloadScreenshot:i}=Mr(t);return s.jsxs(s.Fragment,{children:[s.jsx(a.Box,{ref:r,sx:n,children:e}),s.jsx(A1,{downloadScreenShot:i})]})}),pl=S.observer(({downloadScreenshot:e})=>s.jsx(a.ActionIcon,{className:"download-screenshot-button",color:"blue",onClick:e,children:s.jsx(k.IconCamera,{size:14})})),z1=S.observer(({children:e,view:t})=>{const n=le(),r=t.config,i=n.views.visibleViewIDs.includes(t.id),o=()=>n.views.rmVisibleViewID(t.id),{ref:l,downloadScreenshot:c}=Mr(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(pl,{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"},header:{padding:0},title:{flexGrow:1}},transitionProps:{duration:0},children:s.jsx(a.Box,{ref:l,children:e})})}),E1=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},P1=S.observer(({view:e})=>{const t=le(),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"?"8px 0px 8px":"0",height:"100%",overflow:"auto"}},keepMounted:!1,children:[s.jsx(a.Tabs.List,{grow:n.grow,children:n.tabs.map(r=>s.jsx(a.Tabs.Tab,{value:r.id,sx:E1(r),disabled:!r.view_id,children:r.name??r.id},r.id))}),n.tabs.map(r=>{const i=t.views.findByID(r.view_id);return i?s.jsx(a.Tabs.Panel,{value:r.id,children:s.jsx(Qn,{view:i})},r.id):null})]})}),L1=S.observer(({view:e,children:t})=>{switch(e.type){case L.Modal:return s.jsx(z1,{view:e,children:t});case L.Tabs:return s.jsx(P1,{view:e});case L.Division:default:return s.jsx(dl,{view:e,children:t})}}),O1=S.observer(({children:e,view:t})=>s.jsx(dl,{sx:{paddingTop:"10px",paddingBottom:"100px"},view:t,children:e}));function hl(e){return e.replace(/(vw|vh)/,"%")}const B1=S.observer(({children:e,view:t})=>{const n=t.config,{width:r,height:i}=f.useMemo(()=>({width:hl(n.width),height:hl(n.height)}),[n.width,n.height]),{ref:o,downloadScreenshot:l}=Mr(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(pl,{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})})})}),$1=({variant:e,orientation:t})=>{const n={root:{height:"100%",overflow:"hidden"},tab:{},panel:{padding:"16px"}};return e==="pills"&&t==="horizontal"&&(n.tab.paddingTop="6px",n.tab.paddingBottom="6px"),t==="vertical"&&(n.tab["&.add-a-tab"]={paddingTop:"1px",paddingBottom:"1px"},n.tab["&.add-a-tab .mantine-Tabs-tabLabel"]={marginLeft:"auto",marginRight:"auto"}),n},V1=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},N1=S.observer(({view:e})=>{const t=Me.useModals(),n=X(),r=f.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:$1(i),children:[s.jsxs(a.Tabs.List,{grow:i.grow,children:[i.tabs.map(c=>s.jsx(a.Tabs.Tab,{value:c.id,sx:V1(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(_.Plus,{size:18,color:"#228be6"})})]}),i.tabs.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",value:c.name,onChange:p=>c.setName(p.currentTarget.value)}),s.jsx(a.Select,{label:"View",value:c.view_id,onChange:c.setViewID,data:r}),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(k.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(k.IconTrash,{size:14}),children:"Delete This Tab"})]})]}),d&&s.jsx(Qn,{view:d})]},c.id)})]})}),q1=S.observer(({view:e,children:t})=>{switch(e.type){case L.Modal:return s.jsx(B1,{view:e,children:t});case L.Tabs:return s.jsx(N1,{view:e});case L.Division:default:return s.jsx(O1,{view:e,children:t})}}),xl=S.observer(function({view:t}){return s.jsx(qn.Provider,{value:{viewPanelInFullScreen:y.noop,inFullScreen:!1},children:s.jsx(a.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:s.jsx(q1,{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(ko,{view:t})}),s.jsx(D1,{view:t})]})})})})}),Qn=S.observer(function({view:t}){const{fullScreenPanelID:n,setFullScreenPanelID:r}=Oi(),{viewPanelInFullScreen:i,exitFullScreen:o,inFullScreen:l,fullScreenPanel:c}=ul(t,n,r);return s.jsx(qn.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(cl,{view:t,panel:c,exitFullScreen:o}),s.jsx(L1,{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(ko,{view:t})}),!l&&s.jsx(M1,{view:t})]})})]})})});var fl=(e=>(e.Use="use",e.Edit="edit",e))(fl||{});const F1={[L.Division]:"Division",[L.Tabs]:"Tabs",[L.Modal]:"Modal"},gl={[L.Division]:"rgba(255, 0, 0, 0.2)",[L.Modal]:"rgba(0, 0, 0, 0.2)",[L.Tabs]:"rgba(255, 200, 100, 0.4)"},G1={[L.Division]:"#ff4000",[L.Modal]:"#000",[L.Tabs]:"#ffad18"},W1={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:L.Division,config:{},panelIDs:[]}],panels:[],filters:[],version:"9.19.0"};function R1(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 ml=g.types.compose("FiltersModel",Jo,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===ue.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(){R1(e.current,Bo,(n,r)=>{if(n==="setType"){const i=Xo(r.config.default_value,r.config);e.setValueByKey(r.key,i),e.updatePreviewValues({...e.previewValues,[r.key]:i})}})}return{afterCreate(){t()}}}),yl=Ho.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 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)}})),bl=el.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)}})),Q1=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}})),U1=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}})),Y1=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`
|
|
445
|
+
`}})}function NC(e,t){const n=Ot(e.heat_block.min,t),r=Ot(e.heat_block.max,t);return{min:n,max:r,calculable:!0,orient:"horizontal",left:"center",top:0,itemWidth:15}}function qC(e,t,n){const r=A(e.x_axis.data_key),i=y.uniq(t[r.queryID].map(d=>d[r.columnKey])),{overflow:o,rotate:l}=e.x_axis.axisLabel,c=Ue(o.on_axis);return{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:!0},nameLocation:"center",nameGap:25,nameTextStyle:{fontWeight:"bold",align:"center"},z:2}}function FC(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,d=y.uniq(t[r.queryID].map(x=>x[i.columnKey])),{overflow:u,rotate:p}=e.y_axis.axisLabel,h=Ue(u.on_axis);return{...c,type:"category",data:d,axisLabel:{rotate:p,...h,formatter:n},axisLine:{show:!0,color:"blue"},axisTick:{show:!0,alignWithLabel:!0},splitArea:{show:!0},nameTextStyle:{fontWeight:"bold",align:o},nameLocation:"end",nameGap:15,z:2}}function GC(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,d)=>{const u=it(d,t);return c[d.name]=Ne(d,u),c},{}),i=EC(e),o=PC(e);return{xAxis:qC(e,t,i.x_axis),yAxis:FC(e,t,i.y_axis),series:OC(e,t),tooltip:VC(e,t,i,o),grid:LC(e),visualMap:NC(e,r)}}Y.use([O.DataZoomComponent,te.HeatmapChart,O.GridComponent,O.LegendComponent,O.TooltipComponent,O.VisualMapComponent,Ce.CanvasRenderer]);function WC({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const l=f.useMemo(()=>{const h=A(e.x_axis.data_key),x=A(e.y_axis.data_key);return y.keyBy(t[h.queryID],m=>`${m[h.columnKey]}---${m[x.columnKey]}`)},[t,e.x_axis.data_key,e.y_axis.data_key]),c=$e(i.triggerManager,jo.id),d=f.useCallback(h=>{const[x,m]=h.value,j=y.get(l,`${x}---${m}`,{error:"rowData is not found"});c.forEach(w=>{i.runInteraction(w.id,{...h,rowData:j})})},[l,c,i]),u=f.useMemo(()=>({click:d}),[d]),p=f.useMemo(()=>GC(e,t,o),[e,t]);return s.jsx(we,{echarts:Y,option:p,style:{width:n,height:r},onEvents:u,notMerge:!0,theme:"merico-light"})}function RC({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:d}=e.viewport;return!c||!d?null:s.jsx(De,{width:c,height:d,children:s.jsx(WC,{variables:i,width:We(c),height:Re(d),data:l,conf:o,interactionManager:n})})}class QC extends ie{constructor(){super(...arguments);E(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const UC={displayName:"Merico Heatmap",displayGroup:"Merico suite",migrator:new QC,name:"merico-heatmap",viewRender:RC,configRender:MC,createConfig:()=>({version:1,config:vr}),triggers:[jo]},YC=[{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"})),KC=[Sd,_d,Dd,Td,kd,Id],wo=()=>({id:"dashboard",version:Di,manifest:{viz:[pr,Pj,iw,ub,nv,ny,D0,Gd,$p,Dg,dm,Fw,Gm,ig,wj,Ty,nb,hw,aC,UC,jC,Zp],color:[...YC,...KC]}}),nn=new Ed,de={pluginManager:st("pluginManager"),vizManager:st("vizManager"),colorManager:st("colorManager"),instanceScope:{panelModel:st("panelModel"),vizInstance:st("vizInstance"),interactionManager:st("interactionManager"),migrator:st("migrator"),operationManager:st("operationManager"),triggerManager:st("triggerManager")}},wr=()=>{try{nn.install(wo())}catch{}const e=new vd(nn),t=new zd(nn);return{pluginManager:nn,vizManager:e,colorManager:t}},et=f.createContext(wr());try{nn.install(wo())}catch{}const Cr=f.createContext(null);function Nn(e){const t=f.useContext(Cr),n=V.useCreation(()=>e.configure(t||new ps),[e.configure]),r=V.usePrevious(n);return r&&r!==n&&r.dispose(),s.jsx(Cr.Provider,{value:n,children:e.children})}function Co(){return f.useContext(Cr)}const XC=({description:e,isDescriptionEmpty:t})=>t?null:s.jsx(a.Tooltip,{color:"white",label:s.jsx(An,{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"})})}),JC=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(XC,{description:n,isDescriptionEmpty:r})]}),checked:o||!1,onChange:c=>l(c.currentTarget.checked),...i,pt:".4em",styles:{input:{borderColor:"#e9ecef"}}})]})),ZC=({value:e,onChange:t,close:n,max_days:r,allowSingleDateInRange:i})=>{const[o,l]=e,c=f.useMemo(()=>o||new Date,[o]),d=f.useMemo(()=>{if(o&&!l)return o},[o,l]),u=f.useMemo(()=>{if(o&&!l&&r>0)return I(o).add(r-1,"days").toDate()},[o,l,r]),p=h=>{const[x,m]=h;t(h),x&&m&&n()};return s.jsx(vc.DatePicker,{defaultDate:c,numberOfColumns:2,type:"range",value:e,onChange:p,onNextMonth:console.log,minDate:d,maxDate:u,allowSingleDateInRange:i})},HC=({begin:e,end:t})=>{const n=f.useMemo(()=>I(t).diff(I(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})})},eS=({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,tS={last:[{label:"yesterday",value:"yesterday",getRange:()=>{const e=Date.now();return[I(e).subtract(1,"day").startOf("day").toDate(),I(e).subtract(1,"day").endOf("day").toDate()]}},{label:"week",value:"last week",getRange:()=>{const e=Date.now();return[I(e).subtract(1,"week").startOf("week").toDate(),I(e).subtract(1,"week").endOf("week").toDate()]}},{label:"month",value:"last month",getRange:()=>{const e=Date.now();return[I(e).subtract(1,"month").startOf("month").toDate(),I(e).subtract(1,"month").endOf("month").toDate()]}},{label:"2 months",value:"last 2 months",getRange:()=>{const e=Date.now();return[I(e).subtract(2,"month").startOf("month").toDate(),I(e).subtract(1,"month").endOf("month").toDate()]}},{label:"3 months",value:"last 3 months",getRange:()=>{const e=Date.now();return[I(e).subtract(3,"month").startOf("month").toDate(),I(e).subtract(1,"month").endOf("month").toDate()]}},{label:"year",value:"last year",getRange:()=>{const e=Date.now();return[I(e).subtract(1,"year").startOf("year").toDate(),I(e).subtract(1,"year").endOf("year").toDate()]}}],recent:[{label:"7 days",value:"recent 7 days",getRange:()=>{const e=Date.now();return[I(e).subtract(7,"day").startOf("day").toDate(),I(e).subtract(1,"day").endOf("day").toDate()]}},{label:"30 days",value:"recent 30 days",getRange:()=>{const e=Date.now();return[I(e).subtract(30,"day").startOf("day").toDate(),I(e).subtract(1,"day").endOf("day").toDate()]}},{label:"60 days",value:"recent 60 days",getRange:()=>{const e=Date.now();return[I(e).subtract(60,"day").startOf("day").toDate(),I(e).subtract(1,"day").endOf("day").toDate()]}},{label:"90 days",value:"recent 90 days",getRange:()=>{const e=Date.now();return[I(e).subtract(90,"day").startOf("day").toDate(),I(e).subtract(1,"day").endOf("day").toDate()]}},{label:"180 days",value:"recent 180 days",getRange:()=>{const e=Date.now();return[I(e).subtract(180,"day").startOf("day").toDate(),I(e).subtract(1,"day").endOf("day").toDate()]}},{label:"365 days",value:"recent 365 days",getRange:()=>{const e=Date.now();return[I(e).subtract(365,"day").startOf("day").toDate(),I(e).subtract(1,"day").endOf("day").toDate()]}}],this:[{label:"today",value:"today",getRange:()=>{const e=Date.now();return[I(e).startOf("day").toDate(),I(e).endOf("day").toDate()]}},{label:"week",value:"this week",getRange:()=>{const e=Date.now();return[I(e).startOf("week").toDate(),I(e).endOf("week").toDate()]}},{label:"month",value:"this month",getRange:()=>{const e=Date.now();return[I(e).startOf("month").toDate(),I(e).endOf("month").toDate()]}},{label:"2 months",value:"this 2 months",getRange:()=>{const e=Date.now();return[I(e).startOf("month").toDate(),I(e).add(1,"month").endOf("week").toDate()]}},{label:"3 months",value:"this 3 months",getRange:()=>{const e=Date.now();return[I(e).startOf("month").toDate(),I(e).add(2,"month").endOf("week").toDate()]}},{label:"year",value:"this year",getRange:()=>{const e=Date.now();return[I(e).startOf("year").toDate(),I(e).endOf("year").toDate()]}}]},nS=({onChange:e})=>{const t=n=>()=>{const r=n();e(r)};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(tS).map(([n,r])=>s.jsxs("tr",{children:[s.jsx("th",{children:s.jsx(a.Text,{size:"xs",color:"#555",children:n})}),r.map(({label:i,value:o,getRange:l})=>s.jsx("td",{children:s.jsx(a.Button,{compact:!0,size:"xs",variant:"subtle",onClick:t(l),children:i})},i))]},n))})})]})},So=e=>({label:{display:"block",height:"21.7px"},input:{borderColor:e?"#228be6":"#e9ecef"}}),sS=({label:e,required:t,value:n,onChange:r,max_days:i,allowSingleDateInRange:o,inputFormat:l})=>{const[c,{open:d,close:u}]=le.useDisclosure(!1),[p,h]=n,x=p?I(p).format(l):"",m=h?I(h).format(l):"";return s.jsxs(a.Popover,{opened:c,onClose:u,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:d,styles:So(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(HC,{begin:p,end:h})}),icon:s.jsx(k.IconMinus,{size:16}),placeholder:"End date",readOnly:!0,disabled:!p,value:m,onFocus:d,styles:So(c),sx:{".mantine-Input-icon":{transform:"translateX(-22px)"},".mantine-Input-input":{borderLeft:"none",borderTopLeftRadius:0,borderBottomLeftRadius:0}}})]}),s.jsxs(a.Popover.Dropdown,{p:"sm",children:[s.jsx(eS,{max_days:i}),s.jsx(ZC,{value:n,onChange:r,close:u,allowSingleDateInRange:o,max_days:i}),s.jsx(nS,{onChange:r})]})]})},_o=S.observer(({label:e,config:t,value:n=[null,null],onChange:r})=>{const{inputFormat:i,required:o,max_days:l,allowSingleDateInRange:c}=t,d=Array.isArray(n)?n.map(p=>p?I(p).toDate():null):[null,null],u=p=>{r(p.map(h=>h&&I(h).format(i)))};return s.jsx(sS,{label:e,value:d,onChange:u,inputFormat:i,allowSingleDateInRange:c,max_days:l,required:o})}),rS=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"}}})),ko=({errorMessage:e})=>e?s.jsx(a.Text,{color:"red",size:12,children:e}):s.jsx(a.Text,{color:"dimmed",size:12,children:"Not found"}),iS=({disabled:e,classNames:t,styles:n,unstyled:r,radius:i,style:o,label:l,value:c,onChange:d,options:u,errorMessage:p,required:h})=>{const{classes:x,cx:m}=rS({radius:i},{name:"MultiSelectWidget",classNames:t,styles:n,unstyled:r}),[j,w]=f.useState(!1),T=Q=>{w(Q)},M=j&&(c==null?void 0:c.length)>0,[P,U]=f.useState(""),re=f.useMemo(()=>{if(!P)return u;const Q=P.toLowerCase(),ae=pe=>{var ge;return((ge=pe.description)==null?void 0:ge.toLowerCase().includes(Q))||pe.label.toLowerCase().includes(Q)};return u.filter(ae)},[P,u]);return s.jsxs(a.Stack,{spacing:3,children:[s.jsxs(a.Group,{position:"apart",children:[s.jsxs(a.Text,{className:x.label,children:[l,h&&s.jsx("span",{className:x.required,"aria-hidden":"true",children:"*"})]}),M&&s.jsx(a.Tooltip,{label:`${c.length} selected`,children:s.jsx(a.Badge,{children:c.length})})]}),s.jsx(xi,{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:d,onSelect:console.log,mode:"multiple",maxTagCount:0,notFoundContent:s.jsx(ko,{errorMessage:p}),maxTagTextLength:10,maxTagPlaceholder:Q=>`${Q.length} selected`,searchValue:P,onSearch:U,filterOption:!1,children:re.map(Q=>s.jsxs(xi.Option,{title:Q.label,children:[s.jsx(a.Text,{size:"sm","data-role":"label",children:Q.label}),Q.description&&s.jsx(a.Text,{size:"xs",color:"dimmed","data-role":"description",children:Q.description})]},Q.value))})]})},aS=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),d=l==="loading",u=t.min_width?t.min_width:"200px",p=o?d:!1,h=x=>r(x,!1);return s.jsx(iS,{label:e,options:t.options,style:{minWidth:"160px",width:u,maxWidth:p?u:"unset",borderColor:"#e9ecef"},disabled:p,value:n,onChange:h,errorMessage:c,required:t.required})}),oS=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})]})})})),lS=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),d=l==="loading";return s.jsx(a.Select,{label:e,data:t.options,disabled:o?d:!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:oS})});function cS({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 dS=({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"})}),uS=({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(dS,{rotate:e?"0":"-90",onClick:r,...i})),pS=({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"})]}),hS=({onClick:e,...t})=>s.jsx(pS,{onClick:e,...t}),xS=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"}}}})),fS=({disabled:e,classNames:t,styles:n,unstyled:r,radius:i,style:o,label:l,value:c,onChange:d,treeData:u,errorMessage:p,required:h,treeCheckStrictly:x})=>{const{classes:m,cx:j}=xS({radius:i},{name:"FilterTreeSelectWidget",classNames:t,styles:n,unstyled:r}),[w,T]=f.useState(!1),M=U=>{T(U)},P=w&&(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,h&&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(fi,{disabled:e,allowClear:!0,treeCheckStrictly:x,labelInValue:!0,className:j(m.root,"check-select"),dropdownClassName:j(m.dropdown,""),onDropdownVisibleChange:M,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:uS,treeIcon:hS,maxTagTextLength:10,value:c,treeData:u,notFoundContent:s.jsx(ko,{errorMessage:p}),treeNodeFilterProp:"filterBasis",treeCheckable:!0,showCheckedStrategy:fi.SHOW_PARENT,onChange:d,onSelect:console.log,maxTagCount:0,maxTagPlaceholder:()=>`${c.length} selected`})]})},gS=S.observer(({label:e,config:t,value:n,onChange:r})=>{const{treeData:i,treeDataLoading:o,errorMessage:l}=t,[c,d]=f.useState(t.valueObjects(n)),u=m=>{d(m);const j=m.map(w=>w.value);r(j,!1)};f.useEffect(()=>{d(t.valueObjects(n))},[n]);const p=t.min_width?t.min_width:"200px",x=!!t.options_query_id?o:!1;return s.jsx(fS,{disabled:x,style:{minWidth:"160px",width:p,maxWidth:x?p:"unset",borderColor:"#e9ecef"},value:c,onChange:u,treeData:i,errorMessage:l,label:e,required:t.required,treeCheckStrictly:t.treeCheckStrictly})}),mS=S.observer(({filter:{type:e,config:t,key:n,...r},formFieldProps:i})=>{switch(e){case"select":return s.jsx(lS,{...r,...i,config:t});case"multi-select":return s.jsx(aS,{...r,...i,config:t});case"tree-select":return s.jsx(gS,{...r,...i,config:t});case"text-input":return s.jsx(cS,{...r,...i,config:t});case"date-range":return s.jsx(_o,{...r,...i,config:t});case"checkbox":return s.jsx(JC,{...r,...i,config:t});default:return null}}),yS=S.observer(f.forwardRef(({filter:e,...t},n)=>s.jsx("div",{className:"filter-root",ref:n,children:s.jsx(Se,{children:s.jsx(mS,{filter:e,formFieldProps:t})})}))),bS=({disabled:e})=>{const{searchButtonProps:t}=Ai(),{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 jS(e){const t=X();f.useEffect(()=>{var n,r;(r=(n=t.filters).updatePreviewValues)==null||r.call(n,e)},[e])}const To=S.observer(function({view:t}){const n=ce(),{control:r,handleSubmit:i,reset:o}=b.useForm({defaultValues:n.filters.values,reValidateMode:"onBlur"}),l=b.useWatch({control:r});f.useEffect(()=>{o(n.filters.values)},[n.filters.values,o]),jS(l);const c=n.filters.visibleInView(t.id),d=f.useMemo(()=>c.every(x=>x.should_auto_submit),[c]),u=f.useMemo(()=>c.filter(x=>y.get(x,"config.required",!1)),[c]),p=f.useMemo(()=>u.length===0?!1:u.some(x=>!x.requiredAndPass(l[x.key])),[l,u]);if(c.length===0)return null;const h=(x,m)=>(j,w)=>{m(j),(x.should_auto_submit||w)&&n.filters.setValueByKey(x.key,j)};return s.jsx("form",{onSubmit:i(n.filters.setValues),children:s.jsxs(a.Group,{className:"dashboard-filters",position:"apart",noWrap:!0,sx:d?{}:{border:"1px solid #e9ecef",borderRadius:"4px",padding:"16px"},children:[s.jsx(a.Group,{align:"flex-start",children:c.map(x=>s.jsx(b.Controller,{name:x.key,control:r,render:({field:m})=>s.jsx(yS,{filter:x,value:m.value,onChange:h(x,m.onChange)})},x.id))}),!d&&s.jsx(a.Group,{sx:{alignSelf:"flex-end"},children:s.jsx(bS,{disabled:p})})]})})}),vS={viewPanelInFullScreen:y.noop,inFullScreen:!1},qn=f.createContext(vS),Do=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 Io(e){return{current:e}}const wS=g.types.model("PanelLayoutMeta",{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{x:t,y:n,w:r,h:i,moved:o}=e;return{h:i,w:r,x:t,y:n===null?0:n,moved:o,static:e.static}}})).actions(e=>({set(t){const{x:n,y:r,w:i,h:o,moved:l}=t;e.x=n,e.y=r,e.w=i,e.h=o,e.moved=!!l,e.static=!!t.static},setWidth(t){e.w=t},setHeight(t){e.h=t}})),CS=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}})),SS=g.types.model("PanelStyleMeta",{border:CS}).views(e=>({get json(){const{border:t}=e;return{border:t.json}}})).actions(e=>({})),_S=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}})),kS=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)}),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})}})),TS=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}})),DS=g.types.model({id:g.types.string,name:g.types.optional(g.types.string,""),title:_S,description:g.types.string,layout:wS,queryIDs:g.types.array(g.types.string),viz:TS,style:SS,variables:g.types.optional(g.types.array(kS),[])}).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,layout:e.layout.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)}})),Fn=e=>y.cloneDeepWith(e,(t,n)=>{if(n!==void 0&&t)return W.toJS(t)});var Me=(e=>(e.Postgresql="postgresql",e.MySQL="mysql",e.HTTP="http",e))(Me||{});const IS=g.types.model("QueryMeta",{id:g.types.string,name:g.types.string,type:g.types.enumeration("DataSourceType",[Me.Postgresql,Me.MySQL,Me.HTTP]),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),[])}).views(e=>({get valid(){return e.id&&e.type&&e.key&&e.name?e.type===Me.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:d,post_process:u}=e;return Fn({id:t,key:i,sql:o,name:n,type:r,run_by:l,react_to:c,pre_process:d,post_process:u})}})).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}})),MS=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 ue=(e=>(e.Select="select",e.MultiSelect="multi-select",e.TreeSelect="tree-select",e.TextInput="text-input",e.Checkbox="checkbox",e.DateRange="date-range",e))(ue||{});const Mo=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}})),AS=()=>Mo.create({_name:"checkbox",description:"",default_value:!1});function Ao(e,t){return e.map(n=>{try{return n?I.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]),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,allowSingleDateInRange:c}=e;return{_name:t,max_days:n,required:r,clearable:i,inputFormat:o,default_value:Ao(l,o),allowSingleDateInRange:c}},truthy(t){return Array.isArray(t)&&t.length===2&&t.every(n=>!!n)}})).actions(e=>({setFilterValue(t){try{const n=g.getParent(e);g.getRoot(e).filters.setValueByKey(n.key,t)}catch(n){console.error(n)}}})).actions(e=>({setRequired(t){e.required=t},setClearable(t){e.clearable=t},setInputFormat(t){e.inputFormat=t},setDefaultValue(t){e.default_value.length=0,e.default_value.push(...t),e.setFilterValue(t)},setMaxDays(t){e.max_days=t,t>0&&(e.clearable=!0)},setAllowSingleDateInRange(t){e.allowSingleDateInRange=t}})),zo=g.types.snapshotProcessor(zS,{preProcessor({default_value:e,...t}){return{...t,default_value:e.map(n=>n===null?null:I.tz(n,"UTC").toISOString())}},postProcessor(e){const{default_value:t,...n}=e;return{...n,default_value:Ao(t,n.inputFormat)}}}),ES=()=>zo.create({_name:"date-range",required:!1,inputFormat:"YYYY-MM-DD",clearable:!1,default_value:[null,null]}),PS=g.types.model({label:g.types.string,value:g.types.string}).actions(e=>({setLabel(t){e.label=t},setValue(t){e.value=t}})),Sr=g.types.model("FilterConfigModel_BaseSelect",{static_options:g.types.optional(g.types.array(PS),[]),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 usingQuery(){return!!e.options_query_id}})).views(e=>({get options(){if(!e.usingQuery)return e.static_options;const{data:t,state:n,error:r}=e.contentModel.getDataStuffByID(e.options_query_id);return n==="idle"?Array.isArray(t)?t:[]:[]}})).actions(e=>({setRequired(t){e.required=t},addStaticOption(t){e.static_options.push(t)},removeStaticOption(t){e.static_options.splice(t,1)},setDefaultSelectionCount(t){e.default_selection_count=t},setOptionsQueryID(t){e.options_query_id=t??""}})),Eo=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),[])}),Sr).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 Fn({_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.default_value},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;t.setValueByKey(n,e.default_selection)}})).actions(e=>({afterCreate(){g.addDisposer(e,W.reaction(()=>W.toJS(e.default_selection),e.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),LS=()=>Eo.create({_name:"multi-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),Po=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,"")}),Sr).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 Fn({_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.default_value}})).actions(e=>({setDefaultValue(t){e.default_value=t},setWidth(t){e.width=t},setDefaultSelection(){const t=g.getRoot(e).content.filters,n=g.getParent(e).key;t.setValueByKey(n,e.default_selection)}})).actions(e=>({afterCreate(){g.addDisposer(e,W.reaction(()=>W.toJS(e.default_selection),e.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),OS=()=>Po.create({_name:"select",required:!1,default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),Lo=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}})),Oo=()=>Lo.create({_name:"text-input",required:!1,default_value:""});function BS(e){return wc.arrayToTree(e,{id:"value",parentId:"parent_value",childrenField:"children",dataField:null})}function $S(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 Bo=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)}),Sr).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:d}=e;return{_name:t,required:!!r,min_width:i,default_value:n,static_options:o,options_query_id:l,treeCheckStrictly:d,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=$S(t);return BS(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{default_selection_count:t}=e;return t?this.treeData.slice(0,t).map(r=>r.value):[]},truthy(t){return Array.isArray(t)&&t.length>0},valueObjects(t){const n=new Set(t);return this.plainData.filter(r=>n.has(r.value))}})).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;e.contentModel.filters.setValueByKey(t,e.defaultSelection)},afterCreate(){g.addDisposer(e,W.reaction(()=>JSON.stringify(e.defaultSelection),this.applyDefaultSelection,{fireImmediately:!0,delay:0}))}})),VS=()=>Bo.create({_name:"tree-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),$o=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),type:g.types.enumeration("DashboardFilterType",[ue.Select,ue.MultiSelect,ue.TreeSelect,ue.TextInput,ue.Checkbox,ue.DateRange]),config:g.types.union(Po,Eo,Bo,Lo,Mo,zo)}).views(e=>({get plainDefaultValue(){const t=e.config.default_value;return Array.isArray(t)?[...t]:t},get usingDefaultValue(){return e.type!==ue.TreeSelect},get auto_submit_supported(){return[ue.Select,ue.Checkbox,ue.DateRange].includes(e.type)}})).views(e=>({get json(){const{id:t,key:n,label:r,order:i,visibleInViewsIDs:o,auto_submit:l,type:c,config:d}=e;return{id:t,key:n,type:c,label:r,order:i,config:d.json,auto_submit:l,visibleInViewsIDs:W.toJS(o)}},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 ue.Select:e.config=OS();break;case ue.MultiSelect:e.config=LS();break;case ue.TreeSelect:e.config=VS();break;case ue.TextInput:e.config=Oo();break;case ue.Checkbox:e.config=AS();break;case ue.DateRange:e.config=ES();break}e.type=t},setVisibleInViewsIDs(t){e.visibleInViewsIDs.length=0,e.visibleInViewsIDs.push(...t)},setAutoSubmit(t){e.auto_submit=e.auto_submit_supported&&t}}));var L=(e=>(e.Division="div",e.Modal="modal",e.Tabs="tabs",e))(L||{});const Vo=g.types.model("ViewDivisionConfig",{_name:g.types.literal(L.Division)}).views(e=>({get json(){const{_name:t}=e;return{_name:t}}})),NS=()=>Vo.create({_name:L.Division}),qS=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}})),_r={enabled:!1,func_content:["function text({ filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
|
|
446
|
+
`)},No=g.types.model("ViewModalConfig",{_name:g.types.literal(L.Modal),width:g.types.string,height:g.types.string,custom_modal_title:g.types.optional(qS,_r)}).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}})),FS=()=>No.create({_name:L.Modal,width:"90vw",height:"90vh"}),GS=g.types.model("ViewTabsTabModel",{id:g.types.identifier,name:g.types.string,view_id:g.types.string,color:g.types.optional(g.types.string,"")}).views(e=>({get json(){const{id:t,name:n,view_id:r,color:i}=e;return{id:t,name:n,color:i,view_id:r}}})).actions(e=>({setName(t){e.name=t},setViewID(t){e.view_id=t},setColor(t){e.color=t}})),qo=g.types.model("ViewTabsConfig",{_name:g.types.literal(L.Modal),tabs:g.types.optional(g.types.array(GS),[]),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}}})).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=le.randomId(),n={id:t,name:t,view_id:""};e.tabs.push(n)},removeTab(t){e.tabs.splice(t,1)}})),WS=()=>qo.create({_name:L.Modal,tabs:[]}),RS=g.types.model({id:g.types.identifier,name:g.types.string,type:g.types.enumeration("EViewComponentType",[L.Division,L.Modal,L.Tabs]),config:g.types.union(Vo,No,qo),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 L.Division:e.config=NS();break;case L.Modal:e.config=FS();break;case L.Tabs:e.config=WS();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)}})),Fo=g.types.model("DataSourceMetaModel",{id:g.types.string,type:g.types.enumeration("DataSourceType",[Me.HTTP,Me.MySQL,Me.Postgresql]),key:g.types.string,config:g.types.frozen()}),QS=g.types.model("DataSourcesMetaModel",{list:g.types.optional(g.types.array(Fo),[])}).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)}})),US=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}),Go=g.types.model("GlobalSQLSnippetsMeta",{list:g.types.optional(g.types.array(US),[])}).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)}})),kr=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 Wo(e){return kr.create({current:e})}const Ro=g.types.compose("ViewRenderModel",RS,g.types.model({tab:g.types.optional(g.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 g.getParent(e,3)},get panels(){if(e.type!==L.Tabs)return this.contentModel.panels.panelsByIDs(e.panelIDs).panels;const t=this.tabViewID;return this.contentModel.views.findByID(t).panels},get renderViewIDs(){const t=[e.id];return e.type===L.Tabs&&t.push(this.tabViewID),t}})).actions(e=>({setTab(t){e.tab=t??""},afterCreate(){g.addDisposer(e,W.reaction(()=>e.defaultTab,t=>this.setTab(t),{fireImmediately:!0,delay:0}))}})),Qo=g.types.model("ViewsRenderModel",{current:g.types.optional(g.types.array(Ro),[]),visibleViewIDs:g.types.array(g.types.string)}).views(e=>({get json(){return e.current.map(t=>Fn(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 YS(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 KS=new Cc.AsyncParser({withBOM:!0});async function Uo(e){return!Array.isArray(e)||e.length===0?"":await KS.parse(e).promise()}async function XS(e,t){const n=await Uo(t),r=new Blob([n],{type:"text/csv"});rs.saveAs(r,`${e}.csv`)}function Yo(e){const t=new Sc,n=e.map(async({id:r,data:i})=>{const o=await Uo(i);t.file(`${r}.csv`,o)});Promise.all(n).then(()=>{t.generateAsync({type:"blob"}).then(r=>{rs.saveAs(r,"dashboard_data.zip")})}).catch(r=>{console.error(r),xt.notifications.show({color:"red",title:"Failed to download data",message:r.message})})}function Ct(e,t){const n=new Blob([t],{type:"application/json"});rs.saveAs(n,`${e}.json`)}const Ko=DS.views(e=>({get contentModel(){return g.getRoot(e).content}})).views(e=>({get queries(){return e.contentModel.queries.findByIDSet(e.queryIDSet)},get data(){return this.queries.reduce((t,n)=>(t[n.id]=n.data,t),{})},get variableStrings(){return Ri(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)}},downloadSchema(){const{panel:t,queries:n}=this.getSchema(),i=JSON.stringify({panels:[t],definition:{queries:n}},null,2),o=e.name;Ct(o,i)}}));function JS(e){return{id:e,name:e,layout:{x:0,y:1/0,w:18,h:300},title:{show:!0},description:"<p></p>",queryIDs:[],viz:{type:pr.name,conf:pr.createConfig()},style:{border:{enabled:!0}}}}const Xo=g.types.model("PanelsRenderModel",{list:g.types.optional(g.types.array(Ko),[])}).views(e=>({get json(){return e.list.map(t=>t.json)},findByID(t){return e.list.find(n=>n.id===t)},get idMap(){const t=new Map;return e.list.forEach(n=>{t.set(n.id,n)}),t}})).views(e=>({panelsByIDs(t){const n=[];t.forEach(i=>{const o=e.idMap.get(i);o?n.push(o):console.warn(`Panel is not found, id:${i}`)});const r=n.map(i=>({...i.layout.json,i:i.id}));return{panels:n,layouts:r}}}));function Jo(e,t){if(e===void 0)return e;if(t._name==="date-range")try{const[...n]=e;return n.map(r=>r===null?r:I.tz(r,"UTC").format(t.inputFormat)??r)}catch(n){return console.error(n),e}return e}function ZS(e){return e.reduce((t,n)=>(t[n.key]=Jo(n.config.default_value,n.config),t),{})}const Zo=g.types.model("FiltersRenderModel",{current:g.types.optional(g.types.array($o),[]),values:g.types.optional(g.types.frozen(),{})}).views(e=>({get json(){return e.current.map(t=>t.json)},get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(n=>n.id===t)},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},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:[]}))}},downloadSchema(t){const n=JSON.stringify(this.getSchema(t,!1),null,2);Ct("Filters",n)}}));function Ho(e){return{current:e,values:ZS(e)}}function HS(e,t){return new Function(`return ${e}`)()(t,gt)}function e1(e,t,n){return HS(e,{context:t,filters:n})}function t1(e,t){try{return new Function(`return ${e.config.processing.pre}`)()(t,gt)}catch(n){return console.error(n),t}}function n1(e,t){return new Function(`return ${e.config.processing.post}`)()(t,gt)}function s1(e,t,n){return e?new Function(`return ${e}`)()(t,gt,n):t}const Gn={sqlSnippet:new RegExp("(?<=sql_snippets\\.)([^\\?}.]+)","gm"),context:new RegExp("(?<=context\\.)([^\\?}.]+)","gm"),filter:new RegExp("(?<=filters\\.)([^\\?}.]+)","gm")},r1=IS.views(e=>({get rootModel(){return g.getRoot(e)},get contentModel(){return this.rootModel.content},get conditionOptions(){if(!g.isAlive(e))return[];const t=g.getRoot(e).content,{context:n}=t.payloadForSQL,r=Object.keys(n).map(o=>({group:"Context",label:o,value:`context.${o}`,description:void 0})),i=t.filters.keyLabelOptions.map(o=>({group:"Filters",label:o.label,value:`filters.${o.value}`,description:o.value}));return[...r,...i]},get unmetRunByConditions(){if(!g.isAlive(e))return[];const{run_by:t}=e;if(t.length===0)return[];const n=g.getRoot(e).content.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 ls(e.sql,this.payload)},get httpConfigString(){const{context:t,filters:n}=this.payload,{name:r,pre_process:i}=e.json,o=e1(i,t,n);return console.groupCollapsed(`Request config for: ${r}`),console.log(o),console.groupEnd(),JSON.stringify(o)},get typedAsSQL(){return[Me.Postgresql,Me.MySQL].includes(e.type)},get typedAsHTTP(){return[Me.HTTP].includes(e.type)},get reQueryKey(){const{react_to:t=[]}=e;if(t.length===0)return"";const n=g.getRoot(e).content.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}=g.getRoot(e).content.filters,n=e.unmetRunByConditions.filter(i=>i.startsWith("context.")).map(i=>i.split("context.")[0]),r=e.unmetRunByConditions.filter(i=>i.startsWith("filters.")).map(i=>y.get({filters:t},i)).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(Gn.sqlSnippet)),n=y.uniq(e.sql.match(Gn.filter)),r=y.uniq(e.sql.match(Gn.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}})),i1=g.types.compose("QueryRenderModel",r1,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)}})).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(yd({payload:n,name:e.name,query:e.json,additionals:e.additionalQueryInfo},e.controller.signal)),e.state="idle",e.error=null}catch(n){if(!tt.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=t1(e.datasource,o);const l=yield*g.toGenerator(bd({type:n,key:r,configString:JSON.stringify(o),name:e.name,additionals:e.additionalQueryInfo},e.controller.signal)),c=n1(e.datasource,l),d=s1(i,c,e.contentModel.dashboardState);e.data=d,e.state="idle",e.error=null}catch(n){if(console.error(n),!tt.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"}}}})})).actions(e=>({fetchData:t=>{if(!e.inUse&&!t){console.debug(`Skipping query[${e.name}]`);return}return e.typedAsHTTP?e.runHTTP():e.runSQL()},beforeDestroy(){var t;(t=e.controller)==null||t.abort()}})).actions(e=>({afterCreate(){g.addDisposer(e,W.reaction(()=>{var n;return e.typedAsHTTP?`${e.inUse}--${e.id}--${e.key}--${e.reQueryKey}--${(n=e.datasource)==null?void 0:n.id}`:[e.inUse,e.id,e.key,e.formattedSQL,e.pre_process,e.post_process].join("--")},()=>e.fetchData(!1),{fireImmediately:!0,delay:0}))}})),el=g.types.model("QueriesRenderModel",{current:g.types.optional(g.types.array(i1),[])}).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}=this.contentModel,r=[];t.visibleViews.forEach(l=>{l.panels.forEach(c=>{r.push(...c.queryIDs)})});const i=y.uniq(t.visibleViews.map(l=>l.renderViewIDs).flat());n.current.forEach(l=>{const c=y.get(l,"config.options_query_id");if(!c)return;i.some(u=>l.visibleInViewsIDSet.has(u))&&r.push(c)});const o=new Set(r);return console.debug("QueryIDs:",o),o},isQueryInUse(t){return this.visibleQueryIDSet.has(t)}})).actions(e=>({downloadAllData(){const t=e.current.map(({name:n,data:r})=>({id:n,data:r}));Yo(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}));Yo(r)},downloadDataByQueryID(t){const n=e.findByID(t);if(!n){console.log("[downloadDataByQueryID] query not found");return}const{name:r,data:i}=n;XS(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)}}},downloadSchema(t){const n=JSON.stringify(this.getSchema(t),null,2);Ct("Queries",n)}}));function a1(e){return{current:e}}const o1=MS.views(e=>({isADuplicatedKey(t){return!t||t===e.key?!1:!!g.getParent(e,2).findByKey(t)}})),tl=g.types.model("SQLSnippetsRenderModel",{current:g.types.optional(g.types.array(o1),[])}).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)}}},downloadSchema(t){const n=JSON.stringify(this.getSchema(t),null,2);Ct("SQL Snippets",n)}}));function l1(e){return{current:e}}function Wn(e,t,n,r){return e.reduce((i,o)=>{try{i[o[t]]=os(o[n],r)}catch(l){i[o[t]]=l.message}return i},{})}class c1{constructor(t){E(this,"origin");E(this,"copy");this.origin=t,this.copy=g.clone(t),W.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 d1=e=>new c1(e),u1=S.observer(({view:e})=>{const t=K(),n=X(),r=Ae.useModals(),{panel:i,downloadPanelScreenshot:o}=Le(),{id:l}=i,{viewPanelInFullScreen:c,inFullScreen:d}=f.useContext(qn),u=()=>{n.duplicatePanelByID(l,e.id)},p=()=>{t.editor.open(["_VIEWS_",e.id,"_PANELS_",l])},h=()=>r.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>n.removePanelByID(l,e.id),confirmProps:{color:"red"},zIndex:320}),x=f.useCallback(()=>{c(l)},[l,c]),m=!d&&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(_.Refresh,{size:14}),children:"Refresh"}),s.jsx(a.Menu.Item,{onClick:i.downloadData,icon:s.jsx(_.Download,{size:14}),children:"Download Data"}),s.jsx(a.Menu.Item,{onClick:i.downloadSchema,icon:s.jsx(k.IconCode,{size:14}),children:"Download Schema"}),s.jsx(a.Menu.Item,{onClick:o,icon:s.jsx(k.IconCamera,{size:14}),children:"Screenshot"}),m&&s.jsx(a.Menu.Item,{onClick:x,icon:s.jsx(_.ArrowsMaximize,{size:14}),disabled:!0,children:"Full Screen"}),s.jsx(a.Divider,{label:"Edit",labelPosition:"center"}),s.jsx(a.Menu.Item,{onClick:p,icon:s.jsx(_.Settings,{size:14}),children:"Settings"}),s.jsx(a.Menu.Item,{onClick:u,icon:s.jsx(_.Copy,{size:14}),children:"Duplicate"}),s.jsx(a.Menu.Item,{color:"red",onClick:h,icon:s.jsx(_.Trash,{size:14}),children:"Delete"})]})]})})})});function p1(e){return e?["<p><br></p>","<p></p>"].includes(e):!0}const Tr=S.observer(()=>{const[e,t]=f.useState(!1),{panel:n}=ut();return p1(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(An,{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(_.InfoCircle,{size:20})})})]})}),hI="",h1=S.observer(function(){const{panel:t}=ut(),{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 x1(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;gi.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 nl=(e=>(e.migrated="migrated",e.nothingToMigrate="nothingToMigrate",e.checkFailed="checkFailed",e.migrationFailed="migrationFailed",e))(nl||{}),Rn=(e=>(e.notStarted="notStarted",e.inProgress="inProgress",e.done="done",e))(Rn||{});class f1{constructor(t){E(this,"vizInstance");E(this,"operationManager");E(this,"triggerManager");E(this,"vizManager");E(this,"runningMigration");E(this,"panelModel");E(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 sl(e){const{panel:t}=ut();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 Cs(l,i,xn)}).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 f1(o))},[e.viz.type,e.viz.conf])}function rl(e){const[t,n]=f.useState(!1),r=Co().getRequired(de.instanceScope.migrator);return V.useAsyncEffect(async()=>{const i=r.status===Rn.notStarted;n(r.status===Rn.done),r.status===Rn.notStarted&&r.runMigration().then(o=>{o===nl.migrated&&i&&(e==null||e())}).finally(()=>{n(!0)})},[r]),t}function il(e,t){const n=Co().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 g1({setVizConf:e,...t}){const{panel:n}=t,r=il(e,n),i=rl(()=>{xt.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(Cd,{...t}):s.jsx(a.Text,{children:"Checking update..."})}function m1(e){const{panel:t,setVizConf:n}=e;il(n,t);const{inEditMode:r}=f.useContext(pn);return rl(()=>{r&&xt.showNotification({title:`${t.name} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?s.jsx(wd,{...e}):s.jsx(a.Text,{children:"Checking update"})}const xI="";function y1(e,t){const{vizManager:n}=f.useContext(et),{panel:{viz:r,title:i,id:o,name:l,description:c,queryIDs:d,variables:u}}=ut(),p={id:o,name:l,title:i,description:c,queryIDs:d,viz:r,layout:t},h=sl(p);try{return n.resolveComponent(r.type),s.jsx(Nn,{configure:h,children:s.jsx(m1,{setVizConf:r.setConf,panel:p,data:e,variables:u,vizManager:n})})}catch(x){return console.info(y.get(x,"message")),null}}const al=S.observer(function({data:t}){const{ref:n,width:r,height:i}=le.useElementSize(),o=y1(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(Se,{children:o})})})}),ol=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})]})),Dr=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(ol,{panel:e}),e.canRenderViz&&s.jsx(al,{data:e.data})]})),b1={border:"1px solid #e9ecef"},ll=S.observer(({panel:e,panelStyle:t,dropdownContent:n})=>{const{ref:r,downloadPanelScreenshot:i}=x1(e);return e.title.show,s.jsx(bs,{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:{...b1,...t},children:[s.jsx(a.Box,{className:"panel-description-popover-wrapper",children:s.jsx(Tr,{})}),n,s.jsx(h1,{}),s.jsx(Dr,{panel:e})]})})}),j1={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function v1(e){return e.style.border.enabled?{}:j1}const cl=S.observer(function({panel:t,view:n}){const r=v1(t);return s.jsx(ll,{panel:t,panelStyle:r,dropdownContent:s.jsx(u1,{view:n})})});function w1(e){return!["richText","button"].includes(e)}const C1=S.observer(({view:e})=>{const{panel:t,downloadPanelScreenshot:n}=ut(),{id:r}=t,{viewPanelInFullScreen:i,inFullScreen:o}=f.useContext(qn),l=f.useCallback(()=>{i(r)},[r,i]),c=!o&&e.type!==L.Modal;return w1(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(_.Refresh,{size:14}),children:"Refresh"}),s.jsx(a.Menu.Item,{onClick:t.downloadData,icon:s.jsx(_.Download,{size:14}),children:"Download Data"}),s.jsx(a.Menu.Item,{onClick:n,icon:s.jsx(k.IconCamera,{size:14}),children:"Screenshot"}),c&&s.jsx(a.Menu.Item,{onClick:l,icon:s.jsx(_.ArrowsMaximize,{size:14}),children:"Full Screen"})]})]})}):null});function S1(e){return e.style.border.enabled?{}:{border:"1px dashed transparent"}}const Ir=S.observer(({panel:e,view:t})=>{const n=S1(e);return s.jsx(ll,{panel:e,panelStyle:n,dropdownContent:s.jsx(C1,{view:t})})}),_1={modal:{display:"flex",flexDirection:"column",flexWrap:"nowrap"},body:{display:"flex",height:"calc(100vh - 88px)"}},dl=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(_.ArrowLeft,{size:20}),children:"Exit fullscreen"}),styles:_1,children:s.jsx(a.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:s.jsx(Ir,{view:t,panel:n})})})});function ul(e,t,n){const{panels:r}=ce(),i=e.id==="Main",[o,l]=f.useState(()=>i&&r.findByID(t)?t:null),c=f.useCallback(h=>{l(h),i&&n(h)},[i,n]),d=f.useCallback(()=>{l(null),i&&n("")},[i,n]),u=o?r.findByID(o):null;return{viewPanelInFullScreen:c,exitFullScreen:d,inFullScreen:!!u,fullScreenPanel:u}}const fI="",k1=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(_.ArrowsMove,{size:16})})),T1=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(_.ChevronDownRight,{size:16})})),D1=ln.WidthProvider(ln),I1=S.observer(({view:e,className:t="layout"})=>{const n=ce(),{panels:r,layouts:i}=n.panels.panelsByIDs(e.panelIDs),o=f.useCallback(c=>{c.forEach(({i:d,...u})=>{const p=n.panels.findByID(d);p&&p.layout.set(u)})},[n]),l=(c,d,u,p)=>{u.h<30&&(u.h=30,p.h=30),u.w<4&&(u.w=4,p.w=4)};return s.jsx(D1,{onLayoutChange:o,className:`dashboard-layout ${t}`,rowHeight:1,cols:36,margin:[0,0],isBounded:!0,isDraggable:!0,isResizable:!0,layout:i,draggableHandle:".react-grid-customDragHandle",resizeHandle:s.jsx(T1,{}),onResize:l,children:r.map((c,d)=>s.jsxs("div",{"data-grid":{...c.layout},className:"panel-grid-item",children:[s.jsx(k1,{h:c.layout.h}),s.jsx(cl,{view:e,panel:c})]},c.id))})}),M1=ln.WidthProvider(ln),A1=S.observer(function({view:t,className:n="layout"}){const{panels:r,layouts:i}=ce().panels.panelsByIDs(t.panelIDs);return s.jsx(M1,{className:`dashboard-layout ${n}`,cols:36,rowHeight:1,margin:[0,0],isDraggable:!1,isResizable:!1,layout:i,children:r.map(o=>s.jsx("div",{"data-grid":{...o.layout},className:"panel-grid-item",children:s.jsx(Ir,{view:t,panel:o})},o.id))})});function Mr(e){const t=f.useRef(null);return{ref:t,downloadScreenshot:()=>{var l;const r=(l=t.current)==null?void 0:l.querySelector(".react-grid-layout");if(!r)return;const i=r.offsetWidth*2+10,o=r.offsetHeight*2+10;gi.toBlob(r,{bgcolor:"white",width:i,height:o,style:{transformOrigin:"0 0",transform:"scale(2)"}}).then(c=>{window.saveAs(c,`${e.name}.png`)})}}}const z1=S.observer(({downloadScreenShot:e})=>{const[t,{setTrue:n,setFalse:r}]=V.useBoolean(!1),i=gs(),o=ce(),l=()=>{const c=JSON.stringify(o.contentJSON,null,2),d=`${i.name}__${o.name}`;Ct(d,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(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:"Screenshot"}),s.jsx(a.Menu.Divider,{}),s.jsx(a.Menu.Item,{icon:s.jsx(k.IconDownload,{size:14}),onClick:o.queries.downloadAllData,children:"Download Data"}),s.jsx(a.Menu.Item,{icon:s.jsx(k.IconCode,{size:14}),onClick:l,children:"Download Schema"})]})]})}),pl=S.observer(({children:e,view:t,sx:n={}})=>{const{ref:r,downloadScreenshot:i}=Mr(t);return s.jsxs(s.Fragment,{children:[s.jsx(a.Box,{ref:r,sx:n,children:e}),s.jsx(z1,{downloadScreenShot:i})]})}),hl=S.observer(({downloadScreenshot:e})=>s.jsx(a.ActionIcon,{className:"download-screenshot-button",color:"blue",onClick:e,children:s.jsx(k.IconCamera,{size:14})})),E1=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}=Mr(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(hl,{downloadScreenshot:c})]}),trapFocus:!0,onDragStart:d=>{d.stopPropagation()},styles:{root:{position:"fixed",zIndex:200,inset:0},overlay:{zIndex:"unset"},inner:{zIndex:"unset",padding:"0 !important"},content:{border:"1px solid #efefef",maxHeight:"unset !important",overflow:"hidden"},body:{maxHeight:r.height,overflow:"auto",position:"relative"},header:{padding:0},title:{flexGrow:1}},transitionProps:{duration:0},children:s.jsx(a.Box,{ref:l,children:e})})}),P1=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},L1=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"?"8px 0px 8px":"0",height:"100%",overflow:"auto"}},keepMounted:!1,children:[s.jsx(a.Tabs.List,{grow:n.grow,children:n.tabs.map(r=>s.jsx(a.Tabs.Tab,{value:r.id,sx:P1(r),disabled:!r.view_id,children:r.name??r.id},r.id))}),n.tabs.map(r=>{const i=t.views.findByID(r.view_id);return i?s.jsx(a.Tabs.Panel,{value:r.id,children:s.jsx(Qn,{view:i})},r.id):null})]})}),O1=S.observer(({view:e,children:t})=>{switch(e.type){case L.Modal:return s.jsx(E1,{view:e,children:t});case L.Tabs:return s.jsx(L1,{view:e});case L.Division:default:return s.jsx(pl,{view:e,children:t})}}),B1=S.observer(({children:e,view:t})=>s.jsx(pl,{sx:{paddingTop:"10px",paddingBottom:"100px"},view:t,children:e}));function xl(e){return e.replace(/(vw|vh)/,"%")}const $1=S.observer(({children:e,view:t})=>{const n=t.config,{width:r,height:i}=f.useMemo(()=>({width:xl(n.width),height:xl(n.height)}),[n.width,n.height]),{ref:o,downloadScreenshot:l}=Mr(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(hl,{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})})})}),V1=({variant:e,orientation:t})=>{const n={root:{height:"100%",overflow:"hidden"},tab:{},panel:{padding:"16px"}};return e==="pills"&&t==="horizontal"&&(n.tab.paddingTop="6px",n.tab.paddingBottom="6px"),t==="vertical"&&(n.tab["&.add-a-tab"]={paddingTop:"1px",paddingBottom:"1px"},n.tab["&.add-a-tab .mantine-Tabs-tabLabel"]={marginLeft:"auto",marginRight:"auto"}),n},N1=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},q1=S.observer(({view:e})=>{const t=Ae.useModals(),n=X(),r=f.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:V1(i),children:[s.jsxs(a.Tabs.List,{grow:i.grow,children:[i.tabs.map(c=>s.jsx(a.Tabs.Tab,{value:c.id,sx:N1(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(_.Plus,{size:18,color:"#228be6"})})]}),i.tabs.map((c,d)=>{const u=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",value:c.name,onChange:p=>c.setName(p.currentTarget.value)}),s.jsx(a.Select,{label:"View",value:c.view_id,onChange:c.setViewID,data:r}),s.jsx(a.ColorInput,{label:"Color",value:c.color,onChange:c.setColor,disabled:i.variant!=="default"}),u&&s.jsxs(a.Button,{mt:20,variant:"gradient",leftIcon:s.jsx(k.IconArrowsLeftRight,{size:18}),gradient:{from:"cyan",to:"indigo"},onClick:()=>n.views.setIDOfVIE(u.id),children:["Swith to View: ",u.name]}),s.jsx(a.Button,{mt:20,variant:"subtle",color:"red",onClick:()=>o(d),disabled:l,leftIcon:s.jsx(k.IconTrash,{size:14}),children:"Delete This Tab"})]})]}),u&&s.jsx(Qn,{view:u})]},c.id)})]})}),F1=S.observer(({view:e,children:t})=>{switch(e.type){case L.Modal:return s.jsx($1,{view:e,children:t});case L.Tabs:return s.jsx(q1,{view:e});case L.Division:default:return s.jsx(B1,{view:e,children:t})}}),fl=S.observer(function({view:t}){return s.jsx(qn.Provider,{value:{viewPanelInFullScreen:y.noop,inFullScreen:!1},children:s.jsx(a.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:s.jsx(F1,{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(To,{view:t})}),s.jsx(I1,{view:t})]})})})})}),Qn=S.observer(function({view:t}){const{fullScreenPanelID:n,setFullScreenPanelID:r}=Oi(),{viewPanelInFullScreen:i,exitFullScreen:o,inFullScreen:l,fullScreenPanel:c}=ul(t,n,r);return s.jsx(qn.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(dl,{view:t,panel:c,exitFullScreen:o}),s.jsx(O1,{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(To,{view:t})}),!l&&s.jsx(A1,{view:t})]})})]})})});var gl=(e=>(e.Use="use",e.Edit="edit",e))(gl||{});const G1={[L.Division]:"Division",[L.Tabs]:"Tabs",[L.Modal]:"Modal"},ml={[L.Division]:"rgba(255, 0, 0, 0.2)",[L.Modal]:"rgba(0, 0, 0, 0.2)",[L.Tabs]:"rgba(255, 200, 100, 0.4)"},W1={[L.Division]:"#ff4000",[L.Modal]:"#000",[L.Tabs]:"#ffad18"},R1={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:L.Division,config:{},panelIDs:[]}],panels:[],filters:[],version:"9.19.0"};function Q1(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 yl=g.types.compose("FiltersModel",Zo,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===ue.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(){Q1(e.current,$o,(n,r)=>{if(n==="setType"){const i=Jo(r.config.default_value,r.config);e.setValueByKey(r.key,i),e.updatePreviewValues({...e.previewValues,[r.key]:i})}})}return{afterCreate(){t()}}}),bl=el.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 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)}})),jl=tl.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)}})),U1=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}})),Y1=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}})),K1=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`
|
|
447
447
|
SELECT count(*) AS total
|
|
448
448
|
FROM ${n}.${t}
|
|
449
|
-
`}})).actions(e=>({setPage(t){e.page=t},resetPage(){e.page=1},setLimit(t){e.limit=t}})).actions(e=>({afterCreate(){g.addDisposer(e,W.reaction(()=>e.keywordString,e.resetPage,{fireImmediately:!1,delay:0})),g.addDisposer(e,W.reaction(()=>e.limit,e.resetPage,{fireImmediately:!1,delay:0}))}})),K1=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}})),X1=g.types.compose("DataSourceModel",qo,g.types.model({tables:g.types.optional(K1,{}),columns:g.types.optional(Q1,{}),tableData:g.types.optional(Y1,{}),indexes:g.types.optional(U1,{}),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(Xe.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(!tt.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(Xe.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(tt.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(Xe.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(tt.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(Xe.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(Xe.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(tt.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,W.reaction(()=>e.reloadConditionString,e.loadColumns,{fireImmediately:!1,delay:500}))}})).actions(e=>({afterCreate(){g.addDisposer(e,W.reaction(()=>e.reloadConditionString,e.loadIndexes,{fireImmediately:!1,delay:500})),g.addDisposer(e,W.reaction(()=>`${e.reloadConditionString};limit:${e.tableData.limit};offset:${e.tableData.offset}`,e.loadTableData,{fireImmediately:!1,delay:0}))}})),J1=g.types.model("DataSourcesModel",{list:g.types.optional(g.types.array(X1),[])}).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 St(e){return{label:e,value:e,_type:"ACTION",_action_type:e,Icon:null,children:null}}function Z1(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 H1=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 Variables",value:"_QUERY_VARS_",_type:"query_variables",Icon:k.IconVariable},{label:"Mock Context",value:"_MOCK_CONTEXT_",Icon:k.IconCodeDots,_type:"mock_context"},{label:"Filters",value:"_FILTERS_",Icon:k.IconFilter,children:[St("_FILTERS_SETTINGS_"),...n.options,St("_Add_A_Filter_")],_type:"GROUP"},{label:"SQL Snippets",value:"_SQL_SNIPPETS_",Icon:k.IconCopy,children:[St("_SQL_SNIPPETS_SETTINGS_"),...i.options,St("_Add_A_SQL_SNIPPET_")],_type:"GROUP"},{label:"Queries",value:"_QUERIES_",Icon:k.IconDatabase,children:[St("_QUERIES_SETTINGS_"),...o.options,St("_Add_A_QUERY_")],_type:"GROUP"},{label:"Views",value:"_VIEWS_",Icon:k.IconBoxMultiple,children:[...r.editorOptions,St("_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=Z1(t);n&&e.setPath(n)}})),jl=Yo.views(e=>({get dataFieldOptions(){return e.queryIDs.length===0?[]:e.queries.map(t=>{const n=t.data;return n.length===0?[]:Object.keys(n[0]).map(i=>({label:i,value:`${t.id}.${i}`,group:t.name}))}).flat()}})).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])}})),vl=g.types.compose("PanelsModel",Ko,g.types.model({list:g.types.optional(g.types.array(jl),[])})).views(e=>({editorOptions(t,n){const{panels: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},layout:{...n.layout,y:1/0,moved:!1}}),r},replaceByIndex(t,n){e.list.splice(t,1,n)}})),e_=Wo.actions(e=>({getSchema(){const t=e.json,n=[],r=[];return e.panels.forEach(o=>{const l=o.getSchema();n.push(l.panel),l.queries.length>0&&r.push(...l.queries)}),{views:[t],panels:n,definition:{queries:y.uniqBy(r,o=>o.id)}}},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;Ct(n,t)}})),wl=g.types.compose("ViewsModel",Ro,g.types.model({current:g.types.optional(g.types.array(e_),[]),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,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 Ar(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 t_=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:ml,queries:yl,sqlSnippets:bl,views:wl,panels:vl,mock_context:To,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,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"]));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 mockContextChanged(){const t="mock_context.current";return!y.isEqual(y.get(e,t),y.get(e.origin,t))},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:Wn(e.sqlSnippets.current,"key","value",r),global_sql_snippets:Wn(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 us(this.payloadForSQL)},getAdditionalQueryInfo(t){return{content_id:e.id,query_id:t,params:this.dashboardState}},get changed(){return this.filtersChanged||this.queriesChanged||this.sqlSnippetsChanged||this.viewsChanged||this.panelsChanged||this.mockContextChanged},get data(){return e.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(t){const n=e.queries.findByID(t);return n?{data:n.data,len:n.data.length,state:n.state,error:n.error}:{data:[],len:0,state:"idle",error:void 0}}})).views(e=>({get queriesUsage(){const t=e.panels.idMap,n=[];e.views.current.forEach(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(p=>{n.push({id:o,queryID:p,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(Gn.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),(r=e.views.findByID(n))==null||r.removePanelID(t)},addANewPanel(t){var r;const n=is.v4();e.panels.append(XS(n)),(r=e.views.findByID(t))==null||r.appendPanelID(n)},applyJSONSchema(t){var p;const{views:n,panels:r,filters:i,definition:o={}}=t,{queries:l,sqlSnippets:c,mock_context:u}=o,d=new Map;if(Array.isArray(r)){const h=r.map(x=>{const m=is.v4();return d.set(x.id,m),{...x,id:m}});if(e.panels.appendMultiple(h),!Array.isArray(n)||n.length===0){const x=h.map(m=>m.id);(p=e.views.VIE)==null||p.appendPanelIDs(x)}}if(Array.isArray(n)){const h=n.map(x=>{const m=x.panelIDs.map(j=>d.get(j)??j);return{...x,id:is.v4(),panelIDs:m}});e.views.appendMultiple(h)}Array.isArray(i)&&e.filters.appendMultiple(i),Array.isArray(l)&&e.queries.appendMultiple(l),Array.isArray(c)&&e.sqlSnippets.appendMultiple(c),u&&Object.keys(u).length>0&&e.mock_context.defaults(u)}})).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),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:p,mock_context:h={}}}=i;e.id=n,e.name=r,e.version=o,g.applySnapshot(e.filters.current,l),g.applySnapshot(e.views.current,Ar(c).current),g.applySnapshot(e.panels.list,u),g.applySnapshot(e.queries.current,d),g.applySnapshot(e.sqlSnippets.current,p),e.mock_context.current=h}})),zr=g.types.snapshotProcessor(t_,{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 n_(e,t){t.filters&&g.applySnapshot(e.filters.current,t.filters)}function Cl({id:e,name:t,dashboard_id:n,create_time:r,update_time:i,content:o}){if(!o)throw new Error("unexpected null content when creating a content model");const{version:l,filters:c,views:u,panels:d,definition:{queries:p,sqlSnippets:h,mock_context:x={}}}=o;return zr.create({id:e,name:t,dashboard_id:n,create_time:r,update_time:i,version:l,filters:Zo(c),queries:{current:p},sqlSnippets:{current:h},mock_context:Do(x),views:Ar(u),panels:{list:d}})}const Sl=g.types.model({id:g.types.identifier,name:g.types.string,group:g.types.string,content:zr,content_id:g.types.string,datasources:J1,globalSQLSnippets:Fo,context:kr,editor:H1}).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 _l({id:e,name:t,group:n,content_id:r},i,o,l,c){return Sl.create({id:e,name:t,group:n,content_id:r,content:Cl(i),datasources:{list:o},globalSQLSnippets:{list:l},context:Go(c),editor:{}})}function kl(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(h){return y.cloneDeepWith(h,m=>{if(l&&typeof m=="string")return encodeURIComponent(m)})}const p=y.template(i||"")(u({...c,filters:e.payloadForSQL.filters,context:e.payloadForSQL.context}));window.open(p,o?"_blank":"_self","noopener")};return window.addEventListener("open-link",n),()=>{window.removeEventListener("open-link",n)}},[e])}function Tl(e){return f.useCallback(t=>t.provideValue(ce.pluginManager,e.pluginManager).provideValue(ce.vizManager,e.vizManager).provideValue(ce.colorManager,e.colorManager),[])}const fI="",s_=S.observer(()=>{const e=gs(),t=X(),n=()=>{const r=JSON.stringify(t.contentJSON,null,2),i=`${e.name}__${t.name}`;Ct(i,r)};return s.jsxs(a.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:310,children:[s.jsx(a.Menu.Target,{children:s.jsx(a.ActionIcon,{variant:"light",color:"blue",children:s.jsx(k.IconMenu2,{size:14})})}),s.jsxs(a.Menu.Dropdown,{children:[s.jsx(a.Menu.Item,{icon:s.jsx(k.IconDownload,{size:14}),onClick:t.queries.downloadAllData,children:"Download Data"}),s.jsx(a.Menu.Item,{icon:s.jsx(k.IconCode,{size:14}),onClick:n,children:"Download Schema"})]})]})}),r_=S.observer(({saveDashboardChanges:e})=>{const t=Me.useModals(),n=X(),r=()=>{t.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:"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(k.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(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:!i,onClick:r,children:"Revert Changes"})})]})]})}),i_=S.observer(({saveDashboardChanges:e,headerSlot:t=null})=>{const n=su.useNavigate(),r=K(),i=()=>{n(`/dashboard/${r.id}`)},o=Me.useModals(),l=()=>{o.openConfirmModal({title:s.jsxs(a.Group,{position:"left",children:[s.jsx(k.IconAlertTriangle,{size:18,color:"red"}),s.jsx(a.Text,{children:"There are unsaved changes"})]}),labels:{confirm:"Discard",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:i,zIndex:320,withCloseButton:!1})},c=r.content.changed;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:c?"red":"green",leftIcon:s.jsx(k.IconArrowLeft,{size:20}),onClick:c?l:i,children:s.jsxs(a.Group,{spacing:4,children:["End Editing",s.jsx(a.Text,{td:"underline",children:r.name})]})}),s.jsx(r_,{saveDashboardChanges:e})]}),s.jsxs(a.Group,{position:"right",sx:{flexGrow:1},children:[t,s.jsx(s_,{})]})]})})}),Dl={height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},a_=S.observer(()=>{var r;const e=X(),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(k.IconPlaylistAdd,{size:20}),sx:{...Dl,transform:"none !important"},children:"Add a Panel"})}):s.jsx(a.Button,{variant:"outline",color:"blue",radius:0,size:"xs",onClick:n,leftIcon:s.jsx(k.IconPlaylistAdd,{size:20}),sx:{...Dl,background:"rgb(231, 245, 255)"},children:"Add a Panel"})});function o_(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);return"content"in t&&(t=t.content),t}const l_=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"})]})),c_=[{value:"default",label:"Default"},{value:"outline",label:"Outline"},{value:"pills",label:"Pills"}],u_=[{value:"horizontal",label:"Horizontal"},{value:"vertical",label:"Vertical"}],d_=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:c_}),s.jsx(a.Select,{label:"Orientation",value:t.orientation,onChange:t.setOrientation,data:u_}),s.jsx(a.Switch,{label:"Grow Tabs",checked:t.grow,onChange:n=>t.setGrow(n.currentTarget.checked)})]})}),p_=({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}})]})},h_=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:i}]=V.useBoolean(),[o,l]=f.useState(e??_r),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)},p=x=>{l(m=>({...m,func_content:x}))},h=()=>{p(_r.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(_.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(p_,{value:o.func_content,onChange:p,disabled:!o.enabled}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:h,color:"red",leftIcon:s.jsx(_.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"})]})]})]})})]})},x_=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(h_,{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"})]})]})}),f_=S.observer(({view:e})=>s.jsxs(s.Fragment,{children:[s.jsx(l_,{view:e}),s.jsx(x_,{view:e}),s.jsx(d_,{view:e})]})),Un={[L.Division]:"Division",[L.Modal]:"Modal",[L.Tabs]:"Tabs"},g_=[{label:Un[L.Division],value:L.Division},{label:Un[L.Modal],value:L.Modal},{label:Un[L.Tabs],value:L.Tabs}],m_=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:g_}),s.jsx(f_,{view:e})]}):null),Yn=({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})]}),y_=({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(Yn,{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:Un[n.type]})]},n.id))})]})},b_=({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(Yn,{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))})]})},j_=({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(Yn,{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))})]})},v_=({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(Yn,{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))})]})},w_=({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(k.IconPointFilled,{size:10}),children:t.map(r=>s.jsx(a.List.Item,{children:r.key},r.key))})]})},C_=({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(k.IconPointFilled,{size:10}),children:t.map(r=>s.jsx(a.List.Item,{children:r},r))})]})},S_=({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(y_,{content:e}),s.jsx(b_,{content:e}),s.jsx(j_,{content:e}),s.jsx(v_,{content:e}),s.jsx(w_,{content:e}),s.jsx(C_,{content:e})]})]}):null,__=S.observer(({onSuccess:e,stretchModal:t,shrinkModal:n})=>{var w;const r=X(),{handleSubmit:i,formState:{errors:o},setValue:l,watch:c,setError:u,clearErrors:d}=b.useForm({defaultValues:{content:null}}),p=({content:T})=>{try{if(!T)throw new Error("please use a valid json file");r.applyJSONSchema(T),xt.showNotification({title:"Successful",message:"",color:"green"}),e()}catch(M){console.error(M),xt.showNotification({title:"Failed",message:M.message,color:"red"})}},[h,x]=f.useState(null);f.useEffect(()=>{if(!h)return;const T=new FileReader;T.readAsText(h,"UTF-8"),T.onload=M=>{try{const P=o_(M);l("content",P),d("content")}catch(P){console.error(P),u("content",{type:"custom",message:P.message})}},T.onabort=()=>console.log("🟨 abort"),T.onerror=()=>{T.error&&(console.error(T.error),u("content",{type:"custom",message:T.error.message}))}},[h]);const[m]=c(["content"]),j=!m;return f.useEffect(()=>{m?t():n()},[m]),s.jsx(a.Box,{mx:"auto",sx:{position:"relative"},children:s.jsxs("form",{onSubmit:i(p),children:[s.jsx(a.FileInput,{label:"JSON File",required:!0,value:h,onChange:x,error:(w=o==null?void 0:o.content)==null?void 0:w.message,sx:{maxWidth:500}}),s.jsx(S_,{content:m}),s.jsx(a.Group,{position:"right",my:"md",children:s.jsx(a.Button,{type:"submit",color:"green",disabled:j,children:"Confirm"})})]})})}),Il={height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},k_=S.observer(()=>{var u;const[e,{open:t,close:n}]=oe.useDisclosure(!1),[r,{setTrue:i,setFalse:o}]=V.useBoolean(!1),c=((u=K().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(k.IconFileImport,{size:16}),sx:{...Il,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(k.IconFileImport,{size:16}),sx:{...Il},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(__,{onSuccess:n,stretchModal:i,shrinkModal:o})})]})}),Ml={height:"30px",borderRight:"none",borderTop:"none",borderLeft:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},T_=S.observer(()=>{var r;const e=X(),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(k.IconCode,{size:16}),sx:{...Ml,transform:"none !important"},children:"Download this View"})}):s.jsx(a.Button,{variant:"outline",color:"blue",radius:0,size:"xs",onClick:n,leftIcon:s.jsx(k.IconCode,{size:16}),sx:{...Ml},children:"Download this View"})}),D_={position:"fixed",top:60,left:0,right:0,height:30,zIndex:299,borderBottom:"1px solid #e9ecef",background:"rgba(233,236,239, 0.15)"},I_=S.observer(()=>s.jsx(a.Box,{sx:D_,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(a_,{}),s.jsx(k_,{})]}),s.jsx(a.Box,{}),s.jsx(a.Group,{position:"right",spacing:0,children:s.jsx(T_,{})})]})})),M_=S.observer(e=>s.jsxs(s.Fragment,{children:[s.jsx(i_,{...e}),s.jsx(I_,{})]})),gI="";function A_(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(([p,h])=>{const{schemaRef:x,data:m}=h,{config:j}=m;switch(x){case"builtin:op:open-link":let w=j.urlTemplate.substring(0,100);j.urlTemplate.length>=20&&(w+="..."),l.type="interaction",l.data.interactions.push({schemaRef:x,urlTemplate:j.urlTemplate,shortURLTemplate:w});return;case"builtin:op:open_view":r.push({id:`OPERATION--${p}`,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 z_(e,t){const n=e.filters.keyLabelMap;return{edges:A_(e.panels.list,t,n),edgeNodes:[]}}function Al(e,t,n){return e*t+e*n}function E_(e,t,n){return e*t+(e-1)*n}const Kn=25,Er=40,zl=25,Pr=350,P_=150,L_=150,El=150,Pl=300,Xn=40,Ll=25,O_=300;function B_(e,t){const n=y.keyBy(t,i=>i.id),r=[];return e.current.forEach((i,o)=>{i.panelIDs.forEach((l,c)=>{const u=Al(c,Xn,Ll)+Er,d=n[l];if(!d){r.push({id:l,_node_type:"panel",parentNode:i.id,data:{label:`!: ${l}`},position:{x:Kn,y:u},sourcePosition:be.Position.Right,targetPosition:be.Position.Left,style:{width:Pl,height:Xn}});return}const p=d.name;r.push({id:d.id,_node_type:"panel",parentNode:i.id,data:{label:p},position:{x:Kn,y:u},sourcePosition:be.Position.Right,targetPosition:be.Position.Left,style:{width:Pl,height:Xn}})})}),r}const $_={[L.Division]:"Div",[L.Modal]:"Modal",[L.Tabs]:"Tabs"},V_=gl;function N_(e){return e.current.map((n,r)=>{const i=E_(n.panelIDs.length,Xn,Ll)+Er+zl;let o=[];return n.type===L.Tabs&&(o=n.config.tabs.map(c=>c.view_id)),{id:n.id,_node_type:"view-root",_view_type:n.type,_view_level:0,_sub_view_ids:[],_tab_view_ids:o,data:{label:`${$_[n.type]}:${n.name}`},position:{x:0,y:0},sourcePosition:be.Position.Right,targetPosition:be.Position.Left,className:"light",style:{backgroundColor:V_[n.type],width:Pr,height:i}}})}function q_(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 F_(e){const t=N_(e.views);q_(t);const n=B_(e.views,e.panels.list);return[...t,...n]}function G_({nodeMap:e,nodes:t,edges:n}){t.forEach(r=>{r._node_type!=="view-root"||r._view_type!==L.Tabs||(r.sourcePosition=be.Position.Bottom,r.style.width=Pr+Kn*2,r.style.height=zl+r._tab_view_ids.reduce((i,o)=>{const l=e[o];l.position.y=i,l.position.x=Kn;const c=l.style.height;return i+c+20},Er))})}function W_({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 R_({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)),p=Number(c.style.width);l.position.x=u+p+O_,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+El}})}function Q_({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=Al(c,Pr,L_),l.position.y=0-P_-El})}function U_({nodeMap:e,nodes:t,edges:n}){const r={nodeMap:e,nodes:t,edges:n};return Q_(r),W_(r),G_(r),R_(r),{nodes:t,edges:n}}function Y_(e){const t=F_(e),n=y.keyBy(t,u=>u.id),{edges:r,edgeNodes:i}=z_(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 U_(c)}const mI="",Lr={"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 K_(e){const t=[];return e.forEach(n=>{switch(n.schemaRef){case"builtin:op:open-link":t.push({key:n.urlTemplate,icon:Lr[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:Lr[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:Lr[n.schemaRef],text:s.jsx(a.Group,{spacing:4,children:s.jsxs(a.Text,{children:["Clear Filter: ",i]})})})});return}}),t}const X_=f.memo(({data:e,isConnectable:t,sourcePosition:n=be.Position.Right,targetPosition:r=be.Position.Left,...i})=>{const o=f.useMemo(()=>K_(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(_.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})]})}),yI="",J_={interaction:X_},Z_=S.observer(()=>{const e=le(),{edges:t,nodes:n}=Y_(e);return s.jsxs(be,{nodes:n,edges:t,onNodesChange:y.noop,onEdgesChange:y.noop,onConnect:y.noop,className:"interactions-viewer",fitView:!0,nodeTypes:J_,children:[s.jsx(be.MiniMap,{}),s.jsx(be.Controls,{}),s.jsx(be.Background,{})]})}),H_=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(Z_,{})})),ek={"> button":{"&:first-of-type":{borderTopRightRadius:0,borderBottomRightRadius:0,borderRightWidth:.5},":not(:first-of-type):not(:last-of-type)":{borderTopRightRadius:0,borderBottomRightRadius:0,borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeftWidth:.5,borderRightWidth:.5},"&:last-of-type":{borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeftWidth:.5}}};function tk({onClick:e,name:t,active:n,openSettings:r}){return 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 nk=S.observer(()=>{const e=K(),t=X(),n=f.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(tk,{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(k.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"})]})}),sk=S.observer(()=>{const e=K(),t=X(),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]=f.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:{...ek,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(k.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(k.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(k.IconLink,{size:18})})})]}),s.jsx(H_,{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(nk,{})}),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:()=>e.editor.open([]),children:"Settings"})})})]})}),rk=S.observer(function({config:t}){return s.jsxs(s.Fragment,{children:[s.jsx(a.Checkbox,{checked:t.default_value,onChange:n=>t.setDefaultValue(n.currentTarget.checked),label:"Default Checked"}),s.jsx(ar,{label:"Description",value:t.description,onChange:t.setDescription,styles:{root:{flexGrow:1,minHeight:"400px"}}})]})}),ik=[{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"}],ak=S.observer(function({config:t}){return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{children:[s.jsx(a.Checkbox,{checked:t.required,onChange:n=>t.setRequired(n.currentTarget.checked),label:"Required"}),s.jsx(a.Checkbox,{checked:t.allowSingleDateInRange,onChange:n=>t.setAllowSingleDateInRange(n.currentTarget.checked),label:"Allow choosing 1 day"})]}),s.jsx(a.Select,{data:ik,label:"Display Format",value:t.inputFormat,onChange:t.setInputFormat}),s.jsx(So,{label:"Default Value",config:t,value:t.default_value,onChange:t.setDefaultValue}),s.jsx(a.NumberInput,{label:"Max Days",min:0,value:t.max_days,onChange:t.setMaxDays,hideControls:!0,sx:{width:"149px"}})]})}),Or=S.observer(({value:e,onChange:t})=>{const n=K(),r=X(),i=f.useMemo(()=>r.queries.options,[r.queries.current]),o=i.length===0,l=c=>{n.editor.setPath(["_QUERIES_",c])};return s.jsx(a.Select,{label:s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Text,{children:"Use query data as options"}),e&&s.jsx(a.Button,{size:"xs",leftIcon:s.jsx(k.IconArrowCurveRight,{size:16}),variant:"subtle",color:"blue",onClick:()=>l(e),children:"Open this query"})]}),data:i,value:e,onChange:t,allowDeselect:!1,clearable:!0,sx:{flexGrow:1},disabled:o,error:o?"You need to add a query in Data Settings":void 0,styles:{label:{display:"block"}}})}),ok=`
|
|
449
|
+
`}})).actions(e=>({setPage(t){e.page=t},resetPage(){e.page=1},setLimit(t){e.limit=t}})).actions(e=>({afterCreate(){g.addDisposer(e,W.reaction(()=>e.keywordString,e.resetPage,{fireImmediately:!1,delay:0})),g.addDisposer(e,W.reaction(()=>e.limit,e.resetPage,{fireImmediately:!1,delay:0}))}})),X1=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}})),J1=g.types.compose("DataSourceModel",Fo,g.types.model({tables:g.types.optional(X1,{}),columns:g.types.optional(U1,{}),tableData:g.types.optional(K1,{}),indexes:g.types.optional(Y1,{}),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(Xe.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(!tt.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(Xe.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(tt.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(Xe.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(tt.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(Xe.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(Xe.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(tt.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,W.reaction(()=>e.reloadConditionString,e.loadColumns,{fireImmediately:!1,delay:500}))}})).actions(e=>({afterCreate(){g.addDisposer(e,W.reaction(()=>e.reloadConditionString,e.loadIndexes,{fireImmediately:!1,delay:500})),g.addDisposer(e,W.reaction(()=>`${e.reloadConditionString};limit:${e.tableData.limit};offset:${e.tableData.offset}`,e.loadTableData,{fireImmediately:!1,delay:0}))}})),Z1=g.types.model("DataSourcesModel",{list:g.types.optional(g.types.array(J1),[])}).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 St(e){return{label:e,value:e,_type:"ACTION",_action_type:e,Icon:null,children:null}}function H1(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 e_=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 Variables",value:"_QUERY_VARS_",_type:"query_variables",Icon:k.IconVariable},{label:"Mock Context",value:"_MOCK_CONTEXT_",Icon:k.IconCodeDots,_type:"mock_context"},{label:"Filters",value:"_FILTERS_",Icon:k.IconFilter,children:[St("_FILTERS_SETTINGS_"),...n.options,St("_Add_A_Filter_")],_type:"GROUP"},{label:"SQL Snippets",value:"_SQL_SNIPPETS_",Icon:k.IconCopy,children:[St("_SQL_SNIPPETS_SETTINGS_"),...i.options,St("_Add_A_SQL_SNIPPET_")],_type:"GROUP"},{label:"Queries",value:"_QUERIES_",Icon:k.IconDatabase,children:[St("_QUERIES_SETTINGS_"),...o.options,St("_Add_A_QUERY_")],_type:"GROUP"},{label:"Views",value:"_VIEWS_",Icon:k.IconBoxMultiple,children:[...r.editorOptions,St("_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=H1(t);n&&e.setPath(n)}})),vl=Ko.views(e=>({get dataFieldOptions(){return e.queryIDs.length===0?[]:e.queries.map(t=>{const n=t.data;return n.length===0?[]:Object.keys(n[0]).map(i=>({label:i,value:`${t.id}.${i}`,group:t.name}))}).flat()}})).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])}})),wl=g.types.compose("PanelsModel",Xo,g.types.model({list:g.types.optional(g.types.array(vl),[])})).views(e=>({editorOptions(t,n){const{panels: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},layout:{...n.layout,y:1/0,moved:!1}}),r},replaceByIndex(t,n){e.list.splice(t,1,n)}})),t_=Ro.actions(e=>({getSchema(){const t=e.json,n=[],r=[];return e.panels.forEach(o=>{const l=o.getSchema();n.push(l.panel),l.queries.length>0&&r.push(...l.queries)}),{views:[t],panels:n,definition:{queries:y.uniqBy(r,o=>o.id)}}},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;Ct(n,t)}})),Cl=g.types.compose("ViewsModel",Qo,g.types.model({current:g.types.optional(g.types.array(t_),[]),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,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 Ar(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 n_=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:yl,queries:bl,sqlSnippets:jl,views:Cl,panels:wl,mock_context:Do,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,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"]));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 mockContextChanged(){const t="mock_context.current";return!y.isEqual(y.get(e,t),y.get(e.origin,t))},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:Wn(e.sqlSnippets.current,"key","value",r),global_sql_snippets:Wn(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 ds(this.payloadForSQL)},getAdditionalQueryInfo(t){return{content_id:e.id,query_id:t,params:this.dashboardState}},get changed(){return this.filtersChanged||this.queriesChanged||this.sqlSnippetsChanged||this.viewsChanged||this.panelsChanged||this.mockContextChanged},get data(){return e.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(t){const n=e.queries.findByID(t);return n?{data:n.data,len:n.data.length,state:n.state,error:n.error}:{data:[],len:0,state:"idle",error:void 0}}})).views(e=>({get queriesUsage(){const t=e.panels.idMap,n=[];e.views.current.forEach(i=>{i.panelIDs.forEach(o=>{const l=t.get(o);if(!l)return;const c="panel",d=l.name,u=[{id:i.id,label:i.name}];l.queryIDs.forEach(p=>{n.push({id:o,queryID:p,type:c,label:d,views:u})})})});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(Gn.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),(r=e.views.findByID(n))==null||r.removePanelID(t)},addANewPanel(t){var r;const n=is.v4();e.panels.append(JS(n)),(r=e.views.findByID(t))==null||r.appendPanelID(n)},applyJSONSchema(t){var p;const{views:n,panels:r,filters:i,definition:o={}}=t,{queries:l,sqlSnippets:c,mock_context:d}=o,u=new Map;if(Array.isArray(r)){const h=r.map(x=>{const m=is.v4();return u.set(x.id,m),{...x,id:m}});if(e.panels.appendMultiple(h),!Array.isArray(n)||n.length===0){const x=h.map(m=>m.id);(p=e.views.VIE)==null||p.appendPanelIDs(x)}}if(Array.isArray(n)){const h=n.map(x=>{const m=x.panelIDs.map(j=>u.get(j)??j);return{...x,id:is.v4(),panelIDs:m}});e.views.appendMultiple(h)}Array.isArray(i)&&e.filters.appendMultiple(i),Array.isArray(l)&&e.queries.appendMultiple(l),Array.isArray(c)&&e.sqlSnippets.appendMultiple(c),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),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:d,definition:{queries:u,sqlSnippets:p,mock_context:h={}}}=i;e.id=n,e.name=r,e.version=o,g.applySnapshot(e.filters.current,l),g.applySnapshot(e.views.current,Ar(c).current),g.applySnapshot(e.panels.list,d),g.applySnapshot(e.queries.current,u),g.applySnapshot(e.sqlSnippets.current,p),e.mock_context.current=h}})),zr=g.types.snapshotProcessor(n_,{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 s_(e,t){t.filters&&g.applySnapshot(e.filters.current,t.filters)}function Sl({id:e,name:t,dashboard_id:n,create_time:r,update_time:i,content:o}){if(!o)throw new Error("unexpected null content when creating a content model");const{version:l,filters:c,views:d,panels:u,definition:{queries:p,sqlSnippets:h,mock_context:x={}}}=o;return zr.create({id:e,name:t,dashboard_id:n,create_time:r,update_time:i,version:l,filters:Ho(c),queries:{current:p},sqlSnippets:{current:h},mock_context:Io(x),views:Ar(d),panels:{list:u}})}const _l=g.types.model({id:g.types.identifier,name:g.types.string,group:g.types.string,content:zr,content_id:g.types.string,datasources:Z1,globalSQLSnippets:Go,context:kr,editor:e_}).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 kl({id:e,name:t,group:n,content_id:r},i,o,l,c){return _l.create({id:e,name:t,group:n,content_id:r,content:Sl(i),datasources:{list:o},globalSQLSnippets:{list:l},context:Wo(c),editor:{}})}function Tl(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),d=n(c);console.log(`${l}: ${d}`),e.filters.setValueByKey(l,d)})};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 d(h){return y.cloneDeepWith(h,m=>{if(l&&typeof m=="string")return encodeURIComponent(m)})}const p=y.template(i||"")(d({...c,filters:e.payloadForSQL.filters,context:e.payloadForSQL.context}));window.open(p,o?"_blank":"_self","noopener")};return window.addEventListener("open-link",n),()=>{window.removeEventListener("open-link",n)}},[e])}function Dl(e){return f.useCallback(t=>t.provideValue(de.pluginManager,e.pluginManager).provideValue(de.vizManager,e.vizManager).provideValue(de.colorManager,e.colorManager),[])}const gI="",r_=S.observer(()=>{const e=gs(),t=X(),n=()=>{const r=JSON.stringify(t.contentJSON,null,2),i=`${e.name}__${t.name}`;Ct(i,r)};return s.jsxs(a.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:310,children:[s.jsx(a.Menu.Target,{children:s.jsx(a.ActionIcon,{variant:"light",color:"blue",children:s.jsx(k.IconMenu2,{size:14})})}),s.jsxs(a.Menu.Dropdown,{children:[s.jsx(a.Menu.Item,{icon:s.jsx(k.IconDownload,{size:14}),onClick:t.queries.downloadAllData,children:"Download Data"}),s.jsx(a.Menu.Item,{icon:s.jsx(k.IconCode,{size:14}),onClick:n,children:"Download Schema"})]})]})}),i_=S.observer(({saveDashboardChanges:e})=>{const t=Ae.useModals(),n=X(),r=()=>{t.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:"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(k.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(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:!i,onClick:r,children:"Revert Changes"})})]})]})}),a_=S.observer(({saveDashboardChanges:e,headerSlot:t=null})=>{const n=rd.useNavigate(),r=K(),i=()=>{n(`/dashboard/${r.id}`)},o=Ae.useModals(),l=()=>{o.openConfirmModal({title:s.jsxs(a.Group,{position:"left",children:[s.jsx(k.IconAlertTriangle,{size:18,color:"red"}),s.jsx(a.Text,{children:"There are unsaved changes"})]}),labels:{confirm:"Discard",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:i,zIndex:320,withCloseButton:!1})},c=r.content.changed;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:c?"red":"green",leftIcon:s.jsx(k.IconArrowLeft,{size:20}),onClick:c?l:i,children:s.jsxs(a.Group,{spacing:4,children:["End Editing",s.jsx(a.Text,{td:"underline",children:r.name})]})}),s.jsx(i_,{saveDashboardChanges:e})]}),s.jsxs(a.Group,{position:"right",sx:{flexGrow:1},children:[t,s.jsx(r_,{})]})]})})}),Il={height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},o_=S.observer(()=>{var r;const e=X(),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(k.IconPlaylistAdd,{size:20}),sx:{...Il,transform:"none !important"},children:"Add a Panel"})}):s.jsx(a.Button,{variant:"outline",color:"blue",radius:0,size:"xs",onClick:n,leftIcon:s.jsx(k.IconPlaylistAdd,{size:20}),sx:{...Il,background:"rgb(231, 245, 255)"},children:"Add a Panel"})});function l_(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);return"content"in t&&(t=t.content),t}const c_=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"})]})),d_=[{value:"default",label:"Default"},{value:"outline",label:"Outline"},{value:"pills",label:"Pills"}],u_=[{value:"horizontal",label:"Horizontal"},{value:"vertical",label:"Vertical"}],p_=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:d_}),s.jsx(a.Select,{label:"Orientation",value:t.orientation,onChange:t.setOrientation,data:u_}),s.jsx(a.Switch,{label:"Grow Tabs",checked:t.grow,onChange:n=>t.setGrow(n.currentTarget.checked)})]})}),h_=({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(me,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},x_=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:i}]=V.useBoolean(),[o,l]=f.useState(e??_r),c=x=>{l({...o,enabled:x})},d=()=>{i();const{enabled:x,func_content:m}=o,j={enabled:x,func_content:m};l(j),t(j)},u=()=>{i(),l(e)},p=x=>{l(m=>({...m,func_content:x}))},h=()=>{p(_r.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(_.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(h_,{value:o.func_content,onChange:p,disabled:!o.enabled}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:h,color:"red",leftIcon:s.jsx(_.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:d,children:"OK"})]})]})]})})]})},f_=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(x_,{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"})]})]})}),g_=S.observer(({view:e})=>s.jsxs(s.Fragment,{children:[s.jsx(c_,{view:e}),s.jsx(f_,{view:e}),s.jsx(p_,{view:e})]})),Un={[L.Division]:"Division",[L.Modal]:"Modal",[L.Tabs]:"Tabs"},m_=[{label:Un[L.Division],value:L.Division},{label:Un[L.Modal],value:L.Modal},{label:Un[L.Tabs],value:L.Tabs}],y_=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:m_}),s.jsx(g_,{view:e})]}):null),Yn=({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})]}),b_=({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(Yn,{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:Un[n.type]})]},n.id))})]})},j_=({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(Yn,{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))})]})},v_=({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(Yn,{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))})]})},w_=({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(Yn,{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))})]})},C_=({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(k.IconPointFilled,{size:10}),children:t.map(r=>s.jsx(a.List.Item,{children:r.key},r.key))})]})},S_=({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(k.IconPointFilled,{size:10}),children:t.map(r=>s.jsx(a.List.Item,{children:r},r))})]})},__=({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(b_,{content:e}),s.jsx(j_,{content:e}),s.jsx(v_,{content:e}),s.jsx(w_,{content:e}),s.jsx(C_,{content:e}),s.jsx(S_,{content:e})]})]}):null,k_=S.observer(({onSuccess:e,stretchModal:t,shrinkModal:n})=>{var w;const r=X(),{handleSubmit:i,formState:{errors:o},setValue:l,watch:c,setError:d,clearErrors:u}=b.useForm({defaultValues:{content:null}}),p=({content:T})=>{try{if(!T)throw new Error("please use a valid json file");r.applyJSONSchema(T),xt.showNotification({title:"Successful",message:"",color:"green"}),e()}catch(M){console.error(M),xt.showNotification({title:"Failed",message:M.message,color:"red"})}},[h,x]=f.useState(null);f.useEffect(()=>{if(!h)return;const T=new FileReader;T.readAsText(h,"UTF-8"),T.onload=M=>{try{const P=l_(M);l("content",P),u("content")}catch(P){console.error(P),d("content",{type:"custom",message:P.message})}},T.onabort=()=>console.log("🟨 abort"),T.onerror=()=>{T.error&&(console.error(T.error),d("content",{type:"custom",message:T.error.message}))}},[h]);const[m]=c(["content"]),j=!m;return f.useEffect(()=>{m?t():n()},[m]),s.jsx(a.Box,{mx:"auto",sx:{position:"relative"},children:s.jsxs("form",{onSubmit:i(p),children:[s.jsx(a.FileInput,{label:"JSON File",required:!0,value:h,onChange:x,error:(w=o==null?void 0:o.content)==null?void 0:w.message,sx:{maxWidth:500}}),s.jsx(__,{content:m}),s.jsx(a.Group,{position:"right",my:"md",children:s.jsx(a.Button,{type:"submit",color:"green",disabled:j,children:"Confirm"})})]})})}),Ml={height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},T_=S.observer(()=>{var d;const[e,{open:t,close:n}]=le.useDisclosure(!1),[r,{setTrue:i,setFalse:o}]=V.useBoolean(!1),c=((d=K().content.views.VIE)==null?void 0:d.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(k.IconFileImport,{size:16}),sx:{...Ml,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(k.IconFileImport,{size:16}),sx:{...Ml},children:"Import..."}),s.jsx(a.Modal,{opened:e,onClose:n,title:"Import content with schema json",trapFocus:!0,onDragStart:u=>{u.stopPropagation()},withinPortal:!0,zIndex:320,size:r?"90vw":500,children:s.jsx(k_,{onSuccess:n,stretchModal:i,shrinkModal:o})})]})}),Al={height:"30px",borderRight:"none",borderTop:"none",borderLeft:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},D_=S.observer(()=>{var r;const e=X(),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(k.IconCode,{size:16}),sx:{...Al,transform:"none !important"},children:"Download this View"})}):s.jsx(a.Button,{variant:"outline",color:"blue",radius:0,size:"xs",onClick:n,leftIcon:s.jsx(k.IconCode,{size:16}),sx:{...Al},children:"Download this View"})}),I_={position:"fixed",top:60,left:0,right:0,height:30,zIndex:299,borderBottom:"1px solid #e9ecef",background:"rgba(233,236,239, 0.15)"},M_=S.observer(()=>s.jsx(a.Box,{sx:I_,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(o_,{}),s.jsx(T_,{})]}),s.jsx(a.Box,{}),s.jsx(a.Group,{position:"right",spacing:0,children:s.jsx(D_,{})})]})})),A_=S.observer(e=>s.jsxs(s.Fragment,{children:[s.jsx(a_,{...e}),s.jsx(M_,{})]})),mI="";function z_(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:d,__TRIGGERS:u}=i.viz.conf;Object.entries(d).forEach(([p,h])=>{const{schemaRef:x,data:m}=h,{config:j}=m;switch(x){case"builtin:op:open-link":let w=j.urlTemplate.substring(0,100);j.urlTemplate.length>=20&&(w+="..."),l.type="interaction",l.data.interactions.push({schemaRef:x,urlTemplate:j.urlTemplate,shortURLTemplate:w});return;case"builtin:op:open_view":r.push({id:`OPERATION--${p}`,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 E_(e,t){const n=e.filters.keyLabelMap;return{edges:z_(e.panels.list,t,n),edgeNodes:[]}}function zl(e,t,n){return e*t+e*n}function P_(e,t,n){return e*t+(e-1)*n}const Kn=25,Er=40,El=25,Pr=350,L_=150,O_=150,Pl=150,Ll=300,Xn=40,Ol=25,B_=300;function $_(e,t){const n=y.keyBy(t,i=>i.id),r=[];return e.current.forEach((i,o)=>{i.panelIDs.forEach((l,c)=>{const d=zl(c,Xn,Ol)+Er,u=n[l];if(!u){r.push({id:l,_node_type:"panel",parentNode:i.id,data:{label:`!: ${l}`},position:{x:Kn,y:d},sourcePosition:je.Position.Right,targetPosition:je.Position.Left,style:{width:Ll,height:Xn}});return}const p=u.name;r.push({id:u.id,_node_type:"panel",parentNode:i.id,data:{label:p},position:{x:Kn,y:d},sourcePosition:je.Position.Right,targetPosition:je.Position.Left,style:{width:Ll,height:Xn}})})}),r}const V_={[L.Division]:"Div",[L.Modal]:"Modal",[L.Tabs]:"Tabs"},N_=ml;function q_(e){return e.current.map((n,r)=>{const i=P_(n.panelIDs.length,Xn,Ol)+Er+El;let o=[];return n.type===L.Tabs&&(o=n.config.tabs.map(c=>c.view_id)),{id:n.id,_node_type:"view-root",_view_type:n.type,_view_level:0,_sub_view_ids:[],_tab_view_ids:o,data:{label:`${V_[n.type]}:${n.name}`},position:{x:0,y:0},sourcePosition:je.Position.Right,targetPosition:je.Position.Left,className:"light",style:{backgroundColor:N_[n.type],width:Pr,height:i}}})}function F_(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 G_(e){const t=q_(e.views);F_(t);const n=$_(e.views,e.panels.list);return[...t,...n]}function W_({nodeMap:e,nodes:t,edges:n}){t.forEach(r=>{r._node_type!=="view-root"||r._view_type!==L.Tabs||(r.sourcePosition=je.Position.Bottom,r.style.width=Pr+Kn*2,r.style.height=El+r._tab_view_ids.reduce((i,o)=>{const l=e[o];l.position.y=i,l.position.x=Kn;const c=l.style.height;return i+c+20},Er))})}function R_({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 Q_({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],d=c.position.x,u=Number(y.get(l,"style.height",0)),p=Number(c.style.width);l.position.x=d+p+B_,c._view_level===0&&l._sub_view_ids.length===0&&(o.sourcePosition=je.Position.Left,l.targetPosition=je.Position.Right,l.position.x*=-1);const x=l.position.x,m=y.get(r,x,0);l.position.y=m,r[x]=m+u+Pl}})}function U_({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=zl(c,Pr,O_),l.position.y=0-L_-Pl})}function Y_({nodeMap:e,nodes:t,edges:n}){const r={nodeMap:e,nodes:t,edges:n};return U_(r),R_(r),W_(r),Q_(r),{nodes:t,edges:n}}function K_(e){const t=G_(e),n=y.keyBy(t,d=>d.id),{edges:r,edgeNodes:i}=E_(e,n),o=[...t,...i],l=y.keyBy(o,d=>d.id),c={edges:y.uniqBy(r,d=>d.id),nodes:o,nodeMap:l};return Y_(c)}const yI="",Lr={"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 X_(e){const t=[];return e.forEach(n=>{switch(n.schemaRef){case"builtin:op:open-link":t.push({key:n.urlTemplate,icon:Lr[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:Lr[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:Lr[n.schemaRef],text:s.jsx(a.Group,{spacing:4,children:s.jsxs(a.Text,{children:["Clear Filter: ",i]})})})});return}}),t}const J_=f.memo(({data:e,isConnectable:t,sourcePosition:n=je.Position.Right,targetPosition:r=je.Position.Left,...i})=>{const o=f.useMemo(()=>X_(e.interactions),[e.interactions]);return s.jsxs(s.Fragment,{children:[s.jsx(je.Handle,{type:"target",position:r,isConnectable:t}),s.jsx(a.Box,{sx:{position:"absolute",top:0,right:0},children:s.jsx(_.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(je.Handle,{type:"source",position:n,isConnectable:t})]})}),bI="",Z_={interaction:J_},H_=S.observer(()=>{const e=ce(),{edges:t,nodes:n}=K_(e);return s.jsxs(je,{nodes:n,edges:t,onNodesChange:y.noop,onEdgesChange:y.noop,onConnect:y.noop,className:"interactions-viewer",fitView:!0,nodeTypes:Z_,children:[s.jsx(je.MiniMap,{}),s.jsx(je.Controls,{}),s.jsx(je.Background,{})]})}),ek=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(H_,{})})),tk={"> 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 nk({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 sk=S.observer(()=>{const e=K(),t=X(),n=f.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(nk,{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(k.IconPlus,{size:14}),size:"sm",px:"xs",color:"blue",onClick:t.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"space-between"}},children:"Add a View"})]})}),rk=S.observer(()=>{const e=K(),t=X(),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]=f.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:{...tk,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(k.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(k.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(k.IconLink,{size:18})})})]}),s.jsx(ek,{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(sk,{})}),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:()=>e.editor.open([]),children:"Settings"})})})]})}),ik=S.observer(function({config:t}){return s.jsxs(s.Fragment,{children:[s.jsx(a.Checkbox,{checked:t.default_value,onChange:n=>t.setDefaultValue(n.currentTarget.checked),label:"Default Checked"}),s.jsx(ar,{label:"Description",value:t.description,onChange:t.setDescription,styles:{root:{flexGrow:1,minHeight:"400px"}}})]})}),ak=[{label:"2022",value:"YYYY"},{label:"202201",value:"YYYYMM"},{label:"20220101",value:"YYYYMMDD"},{label:"2022-01",value:"YYYY-MM"},{label:"2022-01-01",value:"YYYY-MM-DD"}],ok=S.observer(function({config:t}){return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{children:[s.jsx(a.Checkbox,{checked:t.required,onChange:n=>t.setRequired(n.currentTarget.checked),label:"Required"}),s.jsx(a.Checkbox,{checked:t.allowSingleDateInRange,onChange:n=>t.setAllowSingleDateInRange(n.currentTarget.checked),label:"Allow choosing 1 day"})]}),s.jsx(a.Select,{data:ak,label:"Display Format",value:t.inputFormat,onChange:t.setInputFormat}),s.jsx(_o,{label:"Default Value",config:t,value:t.default_value,onChange:t.setDefaultValue}),s.jsx(a.NumberInput,{label:"Max Days",min:0,value:t.max_days,onChange:t.setMaxDays,hideControls:!0,sx:{width:"149px"}})]})}),Or=S.observer(({value:e,onChange:t})=>{const n=K(),r=X(),i=f.useMemo(()=>r.queries.options,[r.queries.current]),o=i.length===0,l=c=>{n.editor.setPath(["_QUERIES_",c])};return s.jsx(a.Select,{label:s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Text,{children:"Use query data as options"}),e&&s.jsx(a.Button,{size:"xs",leftIcon:s.jsx(k.IconArrowCurveRight,{size:16}),variant:"subtle",color:"blue",onClick:()=>l(e),children:"Open this query"})]}),data:i,value:e,onChange:t,allowDeselect:!1,clearable:!0,sx:{flexGrow:1},disabled:o,error:o?"You need to add a query in Data Settings":void 0,styles:{label:{display:"block"}}})}),lk=`
|
|
450
450
|
// row
|
|
451
451
|
{
|
|
452
452
|
label: string;
|
|
453
453
|
value: string;
|
|
454
454
|
description?: string; // optional
|
|
455
455
|
}
|
|
456
|
-
`,
|
|
456
|
+
`,Bl=()=>{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(ct.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:lk})})]})},ck=S.observer(function({config:t}){const n=()=>{t.addStaticOption({label:"",value:""})},r=t.static_options,i=[...r];return s.jsxs(s.Fragment,{children:[s.jsx(a.Checkbox,{checked:t.required,onChange:o=>t.setRequired(o.currentTarget.checked),label:"Required"}),s.jsx(a.TextInput,{label:"Width",description:"At least 160px",value:t.min_width,onChange:o=>t.setMinWidth(o.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:[t.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"})})]}),r.length>0&&s.jsx(a.MultiSelect,{label:"Default Selection",data:i,value:[...t.default_value],onChange:t.setDefaultValue}),r.map((o,l)=>s.jsxs(a.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[s.jsx(a.TextInput,{label:"Label",required:!0,value:t.static_options[l].label,onChange:c=>{t.static_options[l].setLabel(c.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(a.TextInput,{label:"Value",required:!0,value:t.static_options[l].value,onChange:c=>{t.static_options[l].setValue(c.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(a.ActionIcon,{color:"red",variant:"subtle",onClick:()=>t.removeStaticOption(l),sx:{position:"absolute",top:28,right:5},children:s.jsx(_.Trash,{size:16})})]},l)),s.jsx(a.Button,{mt:10,size:"xs",color:"blue",leftIcon:s.jsx(_.PlaylistAdd,{size:20}),onClick:n,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:t.default_selection_count,onChange:t.setDefaultSelectionCount,label:"Select first N options by default"}),s.jsx(Or,{value:t.options_query_id,onChange:t.setOptionsQueryID}),s.jsx(Bl,{})]})}),dk=S.observer(function({config:t}){const n=()=>{t.addStaticOption({label:"",value:""})},r=t.static_options,i=[{label:"No default selection",value:""},...r];return s.jsxs(s.Fragment,{children:[s.jsx(a.Checkbox,{checked:t.required,onChange:o=>t.setRequired(o.currentTarget.checked),label:"Required"}),s.jsx(a.TextInput,{label:"Width",value:t.width,onChange:o=>t.setWidth(o.currentTarget.value),placeholder:"200px"}),s.jsx(a.Divider,{label:"Configure options",labelPosition:"center"}),s.jsxs(a.Stack,{spacing:10,sx:{position:"relative",minHeight:"50px"},children:[t.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"})})]}),r.length>0&&s.jsx(a.Select,{label:"Default Selection",data:i,value:t.default_value,onChange:t.setDefaultValue}),r.map((o,l)=>s.jsxs(a.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[s.jsx(a.TextInput,{label:"Label",required:!0,value:t.static_options[l].label,onChange:c=>{t.static_options[l].setLabel(c.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(a.TextInput,{label:"Value",required:!0,value:t.static_options[l].value,onChange:c=>{t.static_options[l].setValue(c.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(a.ActionIcon,{color:"red",variant:"subtle",onClick:()=>t.removeStaticOption(l),sx:{position:"absolute",top:28,right:5},children:s.jsx(_.Trash,{size:16})})]},l)),s.jsx(a.Button,{size:"xs",color:"blue",leftIcon:s.jsx(_.PlaylistAdd,{size:20}),onClick:n,sx:{width:"50%"},mx:"auto",children:"Add an Option"})]}),s.jsx(a.Divider,{label:"Or fetch options from database",labelPosition:"center"}),s.jsx(a.Checkbox,{checked:t.default_selection_count===1,onChange:o=>t.setDefaultSelectionCount(o.currentTarget.checked?1:0),label:"Select the first option by default"}),s.jsx(Or,{value:t.options_query_id,onChange:t.setOptionsQueryID}),s.jsx(Bl,{})]})}),uk=S.observer(function({config:t}){return s.jsxs(s.Fragment,{children:[s.jsx(a.TextInput,{label:"Default Value",value:t.default_value,onChange:n=>{t.setDefaultValue(n.currentTarget.value)}}),s.jsx(a.Checkbox,{checked:t.required,onChange:n=>t.setRequired(n.currentTarget.checked),label:"Required"})]})}),pk=`
|
|
457
457
|
// row
|
|
458
458
|
{
|
|
459
459
|
label: string;
|
|
@@ -461,7 +461,7 @@ Check the top-level render call using <`+z+">.")}return D}}function dc(v,D){{if(
|
|
|
461
461
|
parent_value: string;
|
|
462
462
|
description?: string;
|
|
463
463
|
}
|
|
464
|
-
`,pk=()=>{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(ct.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:dk})})]})},hk=S.observer(function({config:t}){return s.jsxs(s.Fragment,{children:[s.jsx(a.Checkbox,{checked:t.required,onChange:n=>t.setRequired(n.currentTarget.checked),label:"Required"}),s.jsx(a.TextInput,{label:"Min-width",value:t.min_width,onChange:n=>t.setMinWidth(n.currentTarget.value),placeholder:"200px"}),s.jsx(a.Divider,{label:"Fetch options from database",labelPosition:"center"}),s.jsx(a.Checkbox,{checked:t.treeCheckStrictly,onChange:n=>t.setTreeCheckStrictly(n.currentTarget.checked),label:"Parent and children nodes are not associated"}),s.jsx(a.NumberInput,{value:t.default_selection_count,onChange:t.setDefaultSelectionCount,label:"Select first N options by default"}),s.jsx(Or,{value:t.options_query_id,onChange:t.setOptionsQueryID}),s.jsx(pk,{})]})}),xk=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(ct.Prism,{mt:22,language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(t,null,4)})]})}),fk={select:ck,"multi-select":lk,"tree-select":hk,"text-input":uk,checkbox:rk,"date-range":ak},_t={select:"Select","multi-select":"Multi Select","tree-select":"Tree Select","text-input":"Text Input",checkbox:"Checkbox","date-range":"Date Range"},gk=[{label:_t.select,value:"select"},{label:_t["multi-select"],value:"multi-select"},{label:_t["tree-select"],value:"tree-select"},{label:_t["text-input"],value:"text-input"},{label:_t.checkbox,value:"checkbox"},{label:_t["date-range"],value:"date-range"}],mk=S.observer(function({filter:t}){const n=X(),r=f.useMemo(()=>fk[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:gk,required:!0,value:t.type,onChange:t.setType}),s.jsx(r,{config:t.config})]})]}),s.jsx(xk,{filter:t})]})}),yk=S.observer(({id:e})=>{const t=Me.useModals(),n=K(),r=X();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(_.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(mk,{filter:i})})]})}),bk=S.observer(()=>{const[e,t]=f.useState([]),n=K(),r=u=>{n.editor.setPath(["_FILTERS_",u])},i=()=>{n.content.filters.downloadSchema(e)},o=f.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(k.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:_t[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=X(),[t,n]=f.useState(()=>JSON.stringify(e.mock_context.current,null,4)),r=()=>{try{e.mock_context.replace(JSON.parse(t))}catch(o){xt.showNotification({title:"Failed",message:o.message,color:"red"})}},i=f.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(_.DeviceFloppy,{size:20})})]})]})}),vk=S.observer(()=>{const{panel:e}=Le();return s.jsx(ar,{label:"Description",value:e.description,onChange:e.setDescription,styles:{root:{flexGrow:1}}})}),wk=S.observer(()=>{const{panel:e}=Le(),{style:t}=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:e.layout.w,onChange:n=>{n&&e.layout.setWidth(n)}}),s.jsx(a.NumberInput,{label:"Height",rightSection:s.jsx(a.Text,{size:12,children:"px"}),styles:{rightSection:{width:"40px"}},value:e.layout.h,onChange:n=>{n&&e.layout.setHeight(n)}})]}),s.jsx(a.Checkbox,{ml:6,label:"Border",checked:t.border.enabled,onChange:n=>t.border.setEnabled(n.currentTarget.checked)})]})]})}),Ck=()=>s.jsxs("span",{className:"mantine-103svbs mantine-InputWrapper-required mantine-Select-required","aria-hidden":"true",children:[" ","*"]}),Sk=S.observer(()=>{const{panel:e}=Le(),{name:t}=e,[n,r]=oe.useInputState(t),i=t!==n,o=f.useCallback(()=>{i&&e.setName(n)},[i,n]);f.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(Ck,{})]}),s.jsx(a.ActionIcon,{variant:"subtle",color:"blue",disabled:!i||l,onClick:o,children:s.jsx(k.IconDeviceFloppy,{size:18})})]}),s.jsx(a.TextInput,{value:n,onChange:r,required:!0})]})}),_k=S.observer(()=>{const{panel:e}=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: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 kk(){return s.jsxs(a.Stack,{sx:{height:"100%"},children:[s.jsx(wk,{}),s.jsx(a.Divider,{label:"Info",labelPosition:"center",variant:"dashed"}),s.jsx(Sk,{}),s.jsx(_k,{}),s.jsx(vk,{})]})}const Tk={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 Bl({data:e}){const t=f.useMemo(()=>{if(!Array.isArray(e)||e.length===0)return[];const r=Ge.createColumnHelper();return Object.keys(e[0]).map(i=>r.accessor(i,{cell:o=>o.getValue()}))},[e]),n=Ge.useReactTable({data:e,columns:t,columnResizeMode:"onChange",getCoreRowModel:Ge.getCoreRowModel()});return e.length===0?s.jsx(a.Box,{sx:{height:"5em"}}):s.jsx(Ce,{children:s.jsxs(a.Table,{sx:Tk,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:Ge.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(_.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(Ce,{children:Ge.flexRender(i.column.columnDef.cell,i.getContext())})},i.id))},r.id))})]})})}const Dk=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],Ik={icon:{width:"80px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"80px"}}},Mk=({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:Ik,data:Dk,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"]})})]})},Ak=({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(Ce,{children:[s.jsx(Mk,{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(Bl,{data:l})]})]})},zk=({queryID:e})=>{const t=le(),{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},Br=S.observer(({id:e,moreActions:t,refreshOnMount:n})=>{const r=le(),{data:i,state:o}=r.getDataStuffByID(e),l=o==="loading",c=f.useCallback(()=>{r.queries.refetchDataByQueryID(e)},[e,r]),u=()=>{r.queries.downloadDataByQueryID(e)};f.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(_.Refresh,{size:16})}),s.jsx(a.ActionIcon,{variant:"subtle",color:"blue",disabled:l||d,onClick:u,children:s.jsx(_.Download,{size:16})})]})]}),s.jsxs(a.Box,{pb:20,sx:{position:"relative",flexGrow:1,overflow:"auto"},children:[s.jsx(zk,{queryID:e}),s.jsx(Ak,{data:i,loading:l})]})]})}),Ek=S.observer(function(){const t=K(),n=X(),{panel:r}=Le(),[i,o]=f.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(k.IconLine,{size:16}),onClick:()=>o(!0),children:"Click me to choose queries for this panel"})}),r.queryIDs.length===1&&s.jsx(Br,{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(k.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(Br,{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(k.IconArrowCurveRight,{size:16})})})})},c.id))]})]})]})}),Pk=S.observer(()=>{const{panel:e}=dt();return s.jsx(Ce,{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(Tr,{})}),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(Dr,{panel:e})})]})})})}),$r={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 Lk{constructor(t){E(this,"panel");E(this,"selected");this.panel=t,t.variables.length>0&&(this.selected=t.variables[0]),W.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($r.name)).length;this.panel.addVariable(y.cloneDeep({...$r,name:`${$r.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 Ok(){const{panel:e}=Le();return V.useCreation(()=>new Lk(e),[e])}function Bk({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()))},p=a.useMantineTheme(),h=f.useMemo(()=>Object.entries(p.colors).map(([x,m])=>m[6]),[p]);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(_.DeviceFloppy,{size:20})})]}),s.jsxs(a.Group,{children:[i.map((x,m)=>s.jsx(a.ColorInput,{value:x,onChange:j=>{o(w=>(w.splice(m,1,j),[...w]))},swatches:h,rightSection:s.jsx(a.ActionIcon,{onClick:()=>c(m),color:"red",children:s.jsx(_.Trash,{size:14})}),sx:{width:"45%"}})),s.jsx(a.ActionIcon,{onClick:l,color:"blue",variant:"outline",children:s.jsx(_.PlaylistAdd,{size:20})})]})]})}const $k=f.forwardRef(Bk);function Vk({label:e,value:t,onChange:n,type:r},i){const[o,l]=f.useState(Array.isArray(t)?[...t]:[]),c=f.useCallback(()=>{l(h=>[...h,""])},[l]),u=f.useCallback(h=>{l(x=>(x.splice(h,1),[...x]))},[l]),d=f.useMemo(()=>!y.isEqual(o.map(String),t.map(String)),[o,t]),p=()=>{n(o.map(h=>r==="number"?Number(h):h.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:p,children:s.jsx(_.DeviceFloppy,{size:20})})]}),s.jsxs(a.Group,{children:[o.map((h,x)=>s.jsx(a.TextInput,{type:r,value:h,onChange:m=>{const j=m.currentTarget.value;l(w=>(w.splice(x,1,j),[...w]))},rightSection:s.jsx(a.ActionIcon,{onClick:()=>u(x),color:"red",children:s.jsx(_.Trash,{size:14})}),sx:{width:"45%"}})),s.jsx(a.ActionIcon,{onClick:c,color:"blue",variant:"outline",children:s.jsx(_.PlaylistAdd,{size:20})})]})]})}const Nk=f.forwardRef(Vk),qk=f.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(co,{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(Se,{value:t.color.staticColor,onChange:c=>o("color.staticColor",c)}),i==="continuous"&&s.jsxs(s.Fragment,{children:[s.jsx(Nk,{label:"Value Range",value:t.color.valueRange,type:"number",onChange:c=>o("color.valueRange",c)}),s.jsx($k,{label:"Color Range",value:t.color.colorRange,onChange:c=>o("color.colorRange",c)})]})]})]})}),Fk=f.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(Zs,{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(Oe,{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(qk,{value:t,onChange:n})})]})}),s.jsx(a.Button,{mt:20,leftIcon:s.jsx(k.IconTrash,{size:16}),color:"red",variant:"light",onClick:i,children:"Delete this Variable"})]})}),Gk=S.observer(e=>{const t=V.useCreation(()=>c1(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(k.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(k.IconDeviceFloppy,{size:18}),children:"Save Changes"})]}),s.jsx(Fk,{value:g.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 Wk=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(k.IconPlus,{size:16}),onClick:e.addNew,sx:{flexGrow:0,flexShrink:0,alignSelf:"flex-end",height:"38px"},children:"Add a Variable"})})),Rk=S.observer(()=>{var t;const e=Ok();return e.variableOptions.length===0?s.jsx(Wk,{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(k.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(Gk,{uiModel:e,variable:e.selected}):s.jsx("span",{children:"Select or create a new variable on right side"})]})}),Qk=S.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(ct.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(e.variableStrings,null,4)})]})});function Uk(){const{vizManager:e}=f.useContext(et);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 Yk=S.observer(({value:e,submit:t})=>{const[n,r]=oe.useInputState(e);f.useEffect(()=>{r(e)},[e]);const i=Uk(),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(_.DeviceFloppy,{size:20})}),maxDropdownHeight:600})}),$l=[];function Kk(e,t){try{return e.resolveComponent(t).createConfig()}catch{return null}}function Xk(){const{data:e,panel:{variables:t,viz:n,title:r,name:i,queryIDs:o,description:l,id:c}}=Le(),{vizManager:u}=f.useContext(et),d={name:i,title:r,description:l,viz:n,queryIDs:o,id:c},p=nl(d);try{return u.resolveComponent(d.viz.type),s.jsx(Nn,{configure:p,children:s.jsx(f1,{variables:t,setVizConf:n.setConf,panel:d,vizManager:u,data:e})})}catch(h){return console.info(y.get(h,"message")),null}}const Jk=S.observer(()=>{const{data:e,panel:{viz:t}}=Le(),{vizManager:n}=f.useContext(et),r=f.useCallback(d=>{if(d===t.type)return;const p=Kk(n,d);t.setType(d),t.setConf(p||{})},[t.type]),i=d=>{try{t.setConf(JSON.parse(d))}catch(p){console.error(p)}},o=f.useMemo(()=>{var d;return(d=$l.find(p=>p.value===t.type))==null?void 0:d.Panel},[t.type,$l]),l=Xk(),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(Yk,{submit:r,value:t.type}),s.jsxs(Ce,{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})]})]})}),Zk=S.observer(({panel:e,sourceViewID:t})=>{const n=X(),[r,i]=f.useState(t);f.useEffect(()=>{i(t)},[t]);const[o,{open:l,close:c}]=oe.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(k.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(k.IconX,{size:14}),onClick:c,children:"Cancel"}),s.jsx(a.Button,{size:"xs",color:"blue",leftIcon:s.jsx(k.IconDeviceFloppy,{size:14}),onClick:u,disabled:r===t,children:"Confirm"})]})]})})]})}),Hk={root:{flexGrow:1,width:"100%",minWidth:"1200px",overflow:"hidden"},panel:{width:"100%",minWidth:"1200px",height:"calc(100% - 44px)",padding:10,overflow:"auto"}},Vr=({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(Pk,{}),s.jsx(a.Box,{sx:{flexGrow:1},children:s.jsx(Qk,{})})]})]});function eT(e){return!["richText","button"].includes(e)}const tT=S.observer(({panel:e})=>{const t=Me.useModals(),n=K(),r=X(),[i,o]=f.useState("Data"),l=e.queries,u=eT(e.viz.type)&&e.dataLoading,d=u||e.queryErrors.length>0||e.queryStateMessages!==""||l.length===0,p=n.editor.path[1];f.useEffect(()=>{o(m=>d&&m==="Visualization"?"Data":m)},[e.id,d]);const h=()=>{n.editor.setPath(["_VIEWS_",p])},x=()=>t.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.removePanelByID(e.id,p),h()},confirmProps:{color:"red"},zIndex:320});return s.jsxs(bs,{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(Zk,{panel:e,sourceViewID:p}),s.jsx(a.Button,{size:"xs",variant:"subtle",color:"red",onClick:x,leftIcon:s.jsx(k.IconTrash,{size:14}),children:"Delete This Panel"})]})]}),s.jsxs(a.Tabs,{value:i,onTabChange:o,keepMounted:!1,styles:Hk,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(Ek,{})]}),s.jsx(a.Tabs.Panel,{value:"Panel",children:s.jsx(Vr,{children:s.jsx(kk,{})})}),s.jsx(a.Tabs.Panel,{value:"Variables",children:s.jsx(Vr,{children:s.jsx(Rk,{})})}),s.jsx(a.Tabs.Panel,{value:"Visualization",children:s.jsx(Ce,{children:s.jsx(Vr,{children:s.jsx(Jk,{})})})}),s.jsx(a.Tabs.Panel,{value:"Interactions",children:s.jsx(Ce,{children:s.jsx(Ed,{})})})]})]})}),nT=S.observer(({viewID:e,panelID:t})=>{const n=X();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(tT,{panel:i}):s.jsxs(a.Text,{size:14,children:["Panel by ID[",t,"] is not found"]})}),sT=S.observer(()=>{const[e,t]=f.useState([]),n=Me.useModals(),r=K(),i=h=>{r.editor.setPath(["_QUERIES_",h])},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=f.useMemo(()=>r.content.queries.sortedList.map(h=>h.id),[r.content.queries.sortedList]),u=()=>{t(c)},d=()=>{t([])},p=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(k.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(k.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(h=>{var m;const x=((m=p[h.id])==null?void 0:m.length)??0;return s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx(a.Checkbox,{value:h.id,styles:{input:{cursor:"pointer"}}})}),s.jsx("td",{children:h.name}),s.jsx("td",{children:h.key}),s.jsx("td",{style:{textAlign:"right"},children:h.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(h.id),children:"Open"})})]},h.id)})})]})})})]})}),rT=e=>{const{queryModel:t}=e,n=K(),r=X(),o=r.findQueryUsage(t.id).length>0,l=Me.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(k.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})}):s.jsx(a.Button,{color:"red",size:"xs",onClick:c,leftIcon:s.jsx(k.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})},iT=S.observer(rT),Vl=({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"})]}),sn=({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})})}),aT=({column:e})=>{const{column_key:t,column_key_text:n}=e;return t?s.jsx(a.Tooltip,{label:n,disabled:!n,children:s.jsx(a.Badge,{children:t})}):null},oT=S.observer(({dataSource:e})=>{const{columns:t}=e;return t.loading?s.jsx(Vl,{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(sn,{value:n.column_comment})}),s.jsx("td",{children:s.jsx(aT,{column:n})}),s.jsx("td",{children:n.column_type}),s.jsx("td",{children:n.is_nullable}),s.jsx("td",{children:s.jsx(sn,{value:n.column_default})})]},n.column_name))})]})}),lT=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))})]})}),cT=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(sn,{value:r.index_definition})}),s.jsx("td",{children:s.jsx(sn,{value:r.condition})}),s.jsx("td",{children:s.jsx(sn,{value:r.comment})})]},r.index_name))})]})}),uT=S.observer(({dataSource:e})=>{const{indexes:t}=e;return t.loading||t.empty?null:e.type===Ie.MySQL?s.jsx(lT,{dataSource:e}):e.type===Ie.Postgresql?s.jsx(cT,{dataSource:e}):null}),dT=S.observer(({dataSource:e})=>s.jsxs(a.Stack,{spacing:40,pt:10,sx:{flexGrow:1,overflow:"auto",position:"relative"},children:[s.jsx(Ce,{children:s.jsx(oT,{dataSource:e})}),s.jsx(Ce,{children:s.jsx(uT,{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 hT=S.observer(({dataSource:e})=>{const{tables:t}=e;return t.loading?s.jsx(Vl,{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))})}),xT=({visible:e})=>s.jsx(a.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:s.jsx(a.LoadingOverlay,{visible:e})}),fT=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],gT={icon:{width:"50px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"50px"}}},mT=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:gT,data:fT,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(xT,{visible:!0}):s.jsxs(Ce,{children:[s.jsx(mT,{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(Bl,{data:t.data})]})]})}),bT={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},jT=S.observer(({dataSource:e})=>(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(Ce,{children:s.jsx(hT,{dataSource:e})})}),s.jsxs(a.Tabs,{defaultValue:"structure",styles:bT,children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"structure",icon:s.jsx(k.IconColumns,{size:14}),children:"Structure"}),s.jsx(a.Tabs.Tab,{value:"data",icon:s.jsx(k.IconDatabase,{size:14}),children:"Data"})]}),s.jsx(a.Tabs.Panel,{value:"structure",children:s.jsx(dT,{dataSource:e})}),s.jsx(a.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:s.jsx(yT,{dataSource:e})})]})]}))),vT={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"}},Nl=S.observer(({dataSource:e,triggerButtonProps:t={}})=>{const[n,r]=f.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:vT,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"})]})}),wT=f.forwardRef(({label:e,type:t,...n},r)=>s.jsxs(a.Group,{position:"apart",ref:r,...n,children:[s.jsx(a.Text,{children:e}),s.jsx(a.Text,{children:t})]})),CT=S.observer(({value:e,onChange:t})=>{const n=K(),{data:r=[],loading:i}=V.useRequest(ds,{refreshDeps:[]},[]),o=f.useMemo(()=>r.map(d=>({label:d.key,value:d.key,type:d.type})),[r]),l=f.useMemo(()=>o.reduce((d,p)=>(d[p.value]=p.type,d),{}),[o]),c=d=>{d!==null&&t({key:d,type:l[d]})},u=f.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(Nl,{dataSource:u,triggerButtonProps:{compact:!0,size:"xs",px:10}})]}),itemComponent:wT,rightSection:u?s.jsx(a.Text,{size:"xs",color:"dimmed",children:u.type}):void 0,rightSectionWidth:85,maxDropdownHeight:280,styles:{root:{flex:1},label:{display:"block"},rightSection:{pointerEvents:"none",justifyContent:"flex-end",paddingRight:"10px",".mantine-Text-root":{userSelect:"none"}}},disabled:i,value:e.key,onChange:c})}),ql=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})]})})}),ST=S.observer(({queryModel:e})=>{const[t,n]=f.useState(e.name);return f.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(k.IconDeviceFloppy,{size:16})}),onBlur:()=>{e.setName(t)}}),s.jsx(CT,{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:ql,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:ql,maxDropdownHeight:500}),s.jsx(a.Divider,{mt:20,mb:10,variant:"dashed"}),s.jsx(iT,{queryModel:e})]})})});function _T({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(ct.Prism,{language:"sql",noCopy:!0,withLineNumbers:!0,children:e})})]})}const kT=S.observer(()=>{const t=[...K().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(_T,{content:i})})]},r)})})]})}),TT=`
|
|
464
|
+
`,hk=()=>{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(ct.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:pk})})]})},xk=S.observer(function({config:t}){return s.jsxs(s.Fragment,{children:[s.jsx(a.Checkbox,{checked:t.required,onChange:n=>t.setRequired(n.currentTarget.checked),label:"Required"}),s.jsx(a.TextInput,{label:"Min-width",value:t.min_width,onChange:n=>t.setMinWidth(n.currentTarget.value),placeholder:"200px"}),s.jsx(a.Divider,{label:"Fetch options from database",labelPosition:"center"}),s.jsx(a.Checkbox,{checked:t.treeCheckStrictly,onChange:n=>t.setTreeCheckStrictly(n.currentTarget.checked),label:"Parent and children nodes are not associated"}),s.jsx(a.NumberInput,{value:t.default_selection_count,onChange:t.setDefaultSelectionCount,label:"Select first N options by default"}),s.jsx(Or,{value:t.options_query_id,onChange:t.setOptionsQueryID}),s.jsx(hk,{})]})}),fk=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(ct.Prism,{mt:22,language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(t,null,4)})]})}),gk={select:dk,"multi-select":ck,"tree-select":xk,"text-input":uk,checkbox:ik,"date-range":ok},_t={select:"Select","multi-select":"Multi Select","tree-select":"Tree Select","text-input":"Text Input",checkbox:"Checkbox","date-range":"Date Range"},mk=[{label:_t.select,value:"select"},{label:_t["multi-select"],value:"multi-select"},{label:_t["tree-select"],value:"tree-select"},{label:_t["text-input"],value:"text-input"},{label:_t.checkbox,value:"checkbox"},{label:_t["date-range"],value:"date-range"}],yk=S.observer(function({filter:t}){const n=X(),r=f.useMemo(()=>gk[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:mk,required:!0,value:t.type,onChange:t.setType}),s.jsx(r,{config:t.config})]})]}),s.jsx(fk,{filter:t})]})}),bk=S.observer(({id:e})=>{const t=Ae.useModals(),n=K(),r=X();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(_.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(yk,{filter:i})})]})}),jk=S.observer(()=>{const[e,t]=f.useState([]),n=K(),r=d=>{n.editor.setPath(["_FILTERS_",d])},i=()=>{n.content.filters.downloadSchema(e)},o=f.useMemo(()=>n.content.filters.sortedList.map(d=>d.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(k.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(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:_t[d.type]}),s.jsx("td",{children:s.jsx(a.Button,{variant:"subtle",size:"xs",onClick:()=>r(d.id),children:"Open"})})]},d.id))})]})})})]})}),vk=S.observer(()=>{const e=X(),[t,n]=f.useState(()=>JSON.stringify(e.mock_context.current,null,4)),r=()=>{try{e.mock_context.replace(JSON.parse(t))}catch(o){xt.showNotification({title:"Failed",message:o.message,color:"red"})}},i=f.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(_.DeviceFloppy,{size:20})})]})]})}),wk=S.observer(()=>{const{panel:e}=Le();return s.jsx(ar,{label:"Description",value:e.description,onChange:e.setDescription,styles:{root:{flexGrow:1}}})}),Ck=S.observer(()=>{const{panel:e}=Le(),{style:t}=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:e.layout.w,onChange:n=>{n&&e.layout.setWidth(n)}}),s.jsx(a.NumberInput,{label:"Height",rightSection:s.jsx(a.Text,{size:12,children:"px"}),styles:{rightSection:{width:"40px"}},value:e.layout.h,onChange:n=>{n&&e.layout.setHeight(n)}})]}),s.jsx(a.Checkbox,{ml:6,label:"Border",checked:t.border.enabled,onChange:n=>t.border.setEnabled(n.currentTarget.checked)})]})]})}),Sk=()=>s.jsxs("span",{className:"mantine-103svbs mantine-InputWrapper-required mantine-Select-required","aria-hidden":"true",children:[" ","*"]}),_k=S.observer(()=>{const{panel:e}=Le(),{name:t}=e,[n,r]=le.useInputState(t),i=t!==n,o=f.useCallback(()=>{i&&e.setName(n)},[i,n]);f.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(Sk,{})]}),s.jsx(a.ActionIcon,{variant:"subtle",color:"blue",disabled:!i||l,onClick:o,children:s.jsx(k.IconDeviceFloppy,{size:18})})]}),s.jsx(a.TextInput,{value:n,onChange:r,required:!0})]})}),kk=S.observer(()=>{const{panel:e}=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: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 Tk(){return s.jsxs(a.Stack,{sx:{height:"100%"},children:[s.jsx(Ck,{}),s.jsx(a.Divider,{label:"Info",labelPosition:"center",variant:"dashed"}),s.jsx(_k,{}),s.jsx(kk,{}),s.jsx(wk,{})]})}const Dk={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 $l({data:e}){const t=f.useMemo(()=>{if(!Array.isArray(e)||e.length===0)return[];const r=Ge.createColumnHelper();return Object.keys(e[0]).map(i=>r.accessor(i,{cell:o=>o.getValue()}))},[e]),n=Ge.useReactTable({data:e,columns:t,columnResizeMode:"onChange",getCoreRowModel:Ge.getCoreRowModel()});return e.length===0?s.jsx(a.Box,{sx:{height:"5em"}}):s.jsx(Se,{children:s.jsxs(a.Table,{sx:Dk,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:Ge.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(_.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(Se,{children:Ge.flexRender(i.column.columnDef.cell,i.getContext())})},i.id))},r.id))})]})})}const Ik=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],Mk={icon:{width:"80px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"80px"}}},Ak=({data:e,page:t,setPage:n,limit:r,setLimit:i})=>{const o=e.length,l=Math.ceil(o/r),c=u=>{n(1),i(Number(u))};if(o===0)return null;const d=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"}}}),!d&&s.jsx(a.Select,{icon:s.jsx(a.Text,{ta:"center",color:"dimmed",size:14,children:"Page Size"}),size:"xs",styles:Mk,data:Ik,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"]})})]})},zk=({data:e,loading:t})=>{const[n,r]=f.useState(1),[i,o]=f.useState(20),l=f.useMemo(()=>{const c=(n-1)*i,d=c+i;return e.slice(c,d)},[e,n,i]);return s.jsxs(Se,{children:[s.jsx(Ak,{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($l,{data:l})]})]})},Ek=({queryID:e})=>{const t=ce(),{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},Br=S.observer(({id:e,moreActions:t,refreshOnMount:n})=>{const r=ce(),{data:i,state:o}=r.getDataStuffByID(e),l=o==="loading",c=f.useCallback(()=>{r.queries.refetchDataByQueryID(e)},[e,r]),d=()=>{r.queries.downloadDataByQueryID(e)};f.useEffect(()=>{n&&c()},[c,n]);const u=!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(_.Refresh,{size:16})}),s.jsx(a.ActionIcon,{variant:"subtle",color:"blue",disabled:l||u,onClick:d,children:s.jsx(_.Download,{size:16})})]})]}),s.jsxs(a.Box,{pb:20,sx:{position:"relative",flexGrow:1,overflow:"auto"},children:[s.jsx(Ek,{queryID:e}),s.jsx(zk,{data:i,loading:l})]})]})}),Pk=S.observer(function(){const t=K(),n=X(),{panel:r}=Le(),[i,o]=f.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(k.IconLine,{size:16}),onClick:()=>o(!0),children:"Click me to choose queries for this panel"})}),r.queryIDs.length===1&&s.jsx(Br,{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(k.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(Br,{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(k.IconArrowCurveRight,{size:16})})})})},c.id))]})]})]})}),Lk=S.observer(()=>{const{panel:e}=ut();return s.jsx(Se,{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(Tr,{})}),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(Dr,{panel:e})})]})})})}),$r={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 Ok{constructor(t){E(this,"panel");E(this,"selected");this.panel=t,t.variables.length>0&&(this.selected=t.variables[0]),W.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($r.name)).length;this.panel.addVariable(y.cloneDeep({...$r,name:`${$r.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 Bk(){const{panel:e}=Le();return V.useCreation(()=>new Ok(e),[e])}function $k({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]),d=f.useMemo(()=>!y.isEqual(i,t),[i,t]),u=()=>{n(i.map(x=>x.toString()))},p=a.useMantineTheme(),h=f.useMemo(()=>Object.entries(p.colors).map(([x,m])=>m[6]),[p]);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:!d,onClick:u,children:s.jsx(_.DeviceFloppy,{size:20})})]}),s.jsxs(a.Group,{children:[i.map((x,m)=>s.jsx(a.ColorInput,{value:x,onChange:j=>{o(w=>(w.splice(m,1,j),[...w]))},swatches:h,rightSection:s.jsx(a.ActionIcon,{onClick:()=>c(m),color:"red",children:s.jsx(_.Trash,{size:14})}),sx:{width:"45%"}})),s.jsx(a.ActionIcon,{onClick:l,color:"blue",variant:"outline",children:s.jsx(_.PlaylistAdd,{size:20})})]})]})}const Vk=f.forwardRef($k);function Nk({label:e,value:t,onChange:n,type:r},i){const[o,l]=f.useState(Array.isArray(t)?[...t]:[]),c=f.useCallback(()=>{l(h=>[...h,""])},[l]),d=f.useCallback(h=>{l(x=>(x.splice(h,1),[...x]))},[l]),u=f.useMemo(()=>!y.isEqual(o.map(String),t.map(String)),[o,t]),p=()=>{n(o.map(h=>r==="number"?Number(h):h.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:!u,onClick:p,children:s.jsx(_.DeviceFloppy,{size:20})})]}),s.jsxs(a.Group,{children:[o.map((h,x)=>s.jsx(a.TextInput,{type:r,value:h,onChange:m=>{const j=m.currentTarget.value;l(w=>(w.splice(x,1,j),[...w]))},rightSection:s.jsx(a.ActionIcon,{onClick:()=>d(x),color:"red",children:s.jsx(_.Trash,{size:14})}),sx:{width:"45%"}})),s.jsx(a.ActionIcon,{onClick:c,color:"blue",variant:"outline",children:s.jsx(_.PlaylistAdd,{size:20})})]})]})}const qk=f.forwardRef(Nk),Fk=f.forwardRef(function({value:t,onChange:n},r){const i=t.color.type,o=(c,d)=>{const u=y.cloneDeep(t);y.set(u,c,d),n(u)},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(_e,{value:t.color.staticColor,onChange:c=>o("color.staticColor",c)}),i==="continuous"&&s.jsxs(s.Fragment,{children:[s.jsx(qk,{label:"Value Range",value:t.color.valueRange,type:"number",onChange:c=>o("color.valueRange",c)}),s.jsx(Vk,{label:"Color Range",value:t.color.colorRange,onChange:c=>o("color.colorRange",c)})]})]})]})}),Gk=f.forwardRef(function({value:t,onChange:n,withStyle:r=!0,remove:i},o){const l=(c,d)=>{const u=y.cloneDeep(t);y.set(u,c,d),n(u)};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(Zs,{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(Oe,{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(Fk,{value:t,onChange:n})})]})}),s.jsx(a.Button,{mt:20,leftIcon:s.jsx(k.IconTrash,{size:16}),color:"red",variant:"light",onClick:i,children:"Delete this Variable"})]})}),Wk=S.observer(e=>{const t=V.useCreation(()=>d1(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(k.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(k.IconDeviceFloppy,{size:18}),children:"Save Changes"})]}),s.jsx(Gk,{value:g.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 Rk=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(k.IconPlus,{size:16}),onClick:e.addNew,sx:{flexGrow:0,flexShrink:0,alignSelf:"flex-end",height:"38px"},children:"Add a Variable"})})),Qk=S.observer(()=>{var t;const e=Bk();return e.variableOptions.length===0?s.jsx(Rk,{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(k.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(Wk,{uiModel:e,variable:e.selected}):s.jsx("span",{children:"Select or create a new variable on right side"})]})}),Uk=S.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(ct.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(e.variableStrings,null,4)})]})});function Yk(){const{vizManager:e}=f.useContext(et);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 Kk=S.observer(({value:e,submit:t})=>{const[n,r]=le.useInputState(e);f.useEffect(()=>{r(e)},[e]);const i=Yk(),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(_.DeviceFloppy,{size:20})}),maxDropdownHeight:600})}),Vl=[];function Xk(e,t){try{return e.resolveComponent(t).createConfig()}catch{return null}}function Jk(){const{data:e,panel:{variables:t,viz:n,title:r,name:i,queryIDs:o,description:l,id:c}}=Le(),{vizManager:d}=f.useContext(et),u={name:i,title:r,description:l,viz:n,queryIDs:o,id:c},p=sl(u);try{return d.resolveComponent(u.viz.type),s.jsx(Nn,{configure:p,children:s.jsx(g1,{variables:t,setVizConf:n.setConf,panel:u,vizManager:d,data:e})})}catch(h){return console.info(y.get(h,"message")),null}}const Zk=S.observer(()=>{const{data:e,panel:{viz:t}}=Le(),{vizManager:n}=f.useContext(et),r=f.useCallback(u=>{if(u===t.type)return;const p=Xk(n,u);t.setType(u),t.setConf(p||{})},[t.type]),i=u=>{try{t.setConf(JSON.parse(u))}catch(p){console.error(p)}},o=f.useMemo(()=>{var u;return(u=Vl.find(p=>p.value===t.type))==null?void 0:u.Panel},[t.type,Vl]),l=Jk(),c=o?f.createElement(o,{data:e,conf:t.conf,setConf:t.setConf}):null,d=l||c;return s.jsxs(a.Stack,{align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[s.jsx(Kk,{submit:r,value:t.type}),s.jsxs(Se,{children:[s.jsx(a.Stack,{pb:10,sx:{flexGrow:1,maxHeight:"100%",overflow:"auto"},children:d}),!d&&s.jsx(a.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(t.conf,null,2),onChange:i})]})]})}),Hk=S.observer(({panel:e,sourceViewID:t})=>{const n=X(),[r,i]=f.useState(t);f.useEffect(()=>{i(t)},[t]);const[o,{open:l,close:c}]=le.useDisclosure(!1),d=()=>{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(k.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(u=>s.jsx(a.Radio,{value:u.value,label:u.label},u.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:c,children:"Cancel"}),s.jsx(a.Button,{size:"xs",color:"blue",leftIcon:s.jsx(k.IconDeviceFloppy,{size:14}),onClick:d,disabled:r===t,children:"Confirm"})]})]})})]})}),eT={root:{flexGrow:1,width:"100%",minWidth:"1200px",overflow:"hidden"},panel:{width:"100%",minWidth:"1200px",height:"calc(100% - 44px)",padding:10,overflow:"auto"}},Vr=({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(Lk,{}),s.jsx(a.Box,{sx:{flexGrow:1},children:s.jsx(Uk,{})})]})]});function tT(e){return!["richText","button"].includes(e)}const nT=S.observer(({panel:e})=>{const t=Ae.useModals(),n=K(),r=X(),[i,o]=f.useState("Data"),l=e.queries,d=tT(e.viz.type)&&e.dataLoading,u=d||e.queryErrors.length>0||e.queryStateMessages!==""||l.length===0,p=n.editor.path[1];f.useEffect(()=>{o(m=>u&&m==="Visualization"?"Data":m)},[e.id,u]);const h=()=>{n.editor.setPath(["_VIEWS_",p])},x=()=>t.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.removePanelByID(e.id,p),h()},confirmProps:{color:"red"},zIndex:320});return s.jsxs(bs,{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(Hk,{panel:e,sourceViewID:p}),s.jsx(a.Button,{size:"xs",variant:"subtle",color:"red",onClick:x,leftIcon:s.jsx(k.IconTrash,{size:14}),children:"Delete This Panel"})]})]}),s.jsxs(a.Tabs,{value:i,onTabChange:o,keepMounted:!1,styles:eT,children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"Data",disabled:d,children:"Data"}),s.jsx(a.Tabs.Tab,{value:"Panel",children:"Panel"}),s.jsx(a.Tabs.Tab,{value:"Variables",disabled:u,children:s.jsx(a.Tooltip,{label:"Requires data",disabled:!u,withinPortal:!0,zIndex:310,children:s.jsx(a.Text,{children:"Variables"})})}),s.jsx(a.Tabs.Tab,{value:"Visualization",disabled:u,children:s.jsx(a.Tooltip,{label:"Requires data",disabled:!u,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:d,exitTransitionDuration:0}),s.jsx(Pk,{})]}),s.jsx(a.Tabs.Panel,{value:"Panel",children:s.jsx(Vr,{children:s.jsx(Tk,{})})}),s.jsx(a.Tabs.Panel,{value:"Variables",children:s.jsx(Vr,{children:s.jsx(Qk,{})})}),s.jsx(a.Tabs.Panel,{value:"Visualization",children:s.jsx(Se,{children:s.jsx(Vr,{children:s.jsx(Zk,{})})})}),s.jsx(a.Tabs.Panel,{value:"Interactions",children:s.jsx(Se,{children:s.jsx(Pu,{})})})]})]})}),sT=S.observer(({viewID:e,panelID:t})=>{const n=X();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(nT,{panel:i}):s.jsxs(a.Text,{size:14,children:["Panel by ID[",t,"] is not found"]})}),rT=S.observer(()=>{const[e,t]=f.useState([]),n=Ae.useModals(),r=K(),i=h=>{r.editor.setPath(["_QUERIES_",h])},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=f.useMemo(()=>r.content.queries.sortedList.map(h=>h.id),[r.content.queries.sortedList]),d=()=>{t(c)},u=()=>{t([])},p=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:d,children:"Select All"}),s.jsx(a.Button,{variant:"default",size:"xs",onClick:u,children:"Clear Selection"})]}),s.jsx(a.Button,{size:"xs",color:"blue",leftIcon:s.jsx(k.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(k.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(h=>{var m;const x=((m=p[h.id])==null?void 0:m.length)??0;return s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx(a.Checkbox,{value:h.id,styles:{input:{cursor:"pointer"}}})}),s.jsx("td",{children:h.name}),s.jsx("td",{children:h.key}),s.jsx("td",{style:{textAlign:"right"},children:h.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(h.id),children:"Open"})})]},h.id)})})]})})})]})}),iT=e=>{const{queryModel:t}=e,n=K(),r=X(),o=r.findQueryUsage(t.id).length>0,l=Ae.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(k.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})}):s.jsx(a.Button,{color:"red",size:"xs",onClick:c,leftIcon:s.jsx(k.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})},aT=S.observer(iT),Nl=({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"})]}),sn=({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})})}),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},lT=S.observer(({dataSource:e})=>{const{columns:t}=e;return t.loading?s.jsx(Nl,{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(sn,{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(sn,{value:n.column_default})})]},n.column_name))})]})}),cT=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))})]})}),dT=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(sn,{value:r.index_definition})}),s.jsx("td",{children:s.jsx(sn,{value:r.condition})}),s.jsx("td",{children:s.jsx(sn,{value:r.comment})})]},r.index_name))})]})}),uT=S.observer(({dataSource:e})=>{const{indexes:t}=e;return t.loading||t.empty?null:e.type===Me.MySQL?s.jsx(cT,{dataSource:e}):e.type===Me.Postgresql?s.jsx(dT,{dataSource:e}):null}),pT=S.observer(({dataSource:e})=>s.jsxs(a.Stack,{spacing:40,pt:10,sx:{flexGrow:1,overflow:"auto",position:"relative"},children:[s.jsx(Se,{children:s.jsx(lT,{dataSource:e})}),s.jsx(Se,{children:s.jsx(uT,{dataSource:e})})]}));function hT({table_type:e}){return e==="VIEW"?s.jsx(k.IconEye,{size:14}):e==="BASE TABLE"?s.jsx(k.IconTable,{size:14}):null}const xT=S.observer(({dataSource:e})=>{const{tables:t}=e;return t.loading?s.jsx(Nl,{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(hT,{table_type:i.table_type}),onClick:()=>{e.setKeywords(n,i.table_name)},active:e.table_name===i.table_name},i.table_name))},n))})}),fT=({visible:e})=>s.jsx(a.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:s.jsx(a.LoadingOverlay,{visible:e})}),gT=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],mT={icon:{width:"50px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"50px"}}},yT=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:mT,data:gT,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"]})})]})}),bT=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(fT,{visible:!0}):s.jsxs(Se,{children:[s.jsx(yT,{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($l,{data:t.data})]})]})}),jT={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},vT=S.observer(({dataSource:e})=>(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(Se,{children:s.jsx(xT,{dataSource:e})})}),s.jsxs(a.Tabs,{defaultValue:"structure",styles:jT,children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"structure",icon:s.jsx(k.IconColumns,{size:14}),children:"Structure"}),s.jsx(a.Tabs.Tab,{value:"data",icon:s.jsx(k.IconDatabase,{size:14}),children:"Data"})]}),s.jsx(a.Tabs.Panel,{value:"structure",children:s.jsx(pT,{dataSource:e})}),s.jsx(a.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:s.jsx(bT,{dataSource:e})})]})]}))),wT={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"}},ql=S.observer(({dataSource:e,triggerButtonProps:t={}})=>{const[n,r]=f.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:wT,children:s.jsx(a.Box,{sx:{height:"calc(100vh - 220px)"},children:s.jsx(vT,{dataSource:e})})}),s.jsx(a.Button,{variant:"subtle",onClick:()=>r(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},...t,children:"See Table Structure"})]})}),CT=f.forwardRef(({label:e,type:t,...n},r)=>s.jsxs(a.Group,{position:"apart",ref:r,...n,children:[s.jsx(a.Text,{children:e}),s.jsx(a.Text,{children:t})]})),ST=S.observer(({value:e,onChange:t})=>{const n=K(),{data:r=[],loading:i}=V.useRequest(us,{refreshDeps:[]},[]),o=f.useMemo(()=>r.map(u=>({label:u.key,value:u.key,type:u.type})),[r]),l=f.useMemo(()=>o.reduce((u,p)=>(u[p.value]=p.type,u),{}),[o]),c=u=>{u!==null&&t({key:u,type:l[u]})},d=f.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"}),d&&s.jsx(ql,{dataSource:d,triggerButtonProps:{compact:!0,size:"xs",px:10}})]}),itemComponent:CT,rightSection:d?s.jsx(a.Text,{size:"xs",color:"dimmed",children:d.type}):void 0,rightSectionWidth:85,maxDropdownHeight:280,styles:{root:{flex:1},label:{display:"block"},rightSection:{pointerEvents:"none",justifyContent:"flex-end",paddingRight:"10px",".mantine-Text-root":{userSelect:"none"}}},disabled:i,value:e.key,onChange:c})}),Fl=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})]})})}),_T=S.observer(({queryModel:e})=>{const[t,n]=f.useState(e.name);return f.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(k.IconDeviceFloppy,{size:16})}),onBlur:()=>{e.setName(t)}}),s.jsx(ST,{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:Fl,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:Fl,maxDropdownHeight:500}),s.jsx(a.Divider,{mt:20,mb:10,variant:"dashed"}),s.jsx(aT,{queryModel:e})]})})});function kT({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(ct.Prism,{language:"sql",noCopy:!0,withLineNumbers:!0,children:e})})]})}const TT=S.observer(()=>{const t=[...K().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(kT,{content:i})})]},r)})})]})}),DT=`
|
|
465
465
|
-- You may reference query variables in SQL or VizConfig.
|
|
466
466
|
SELECT *
|
|
467
467
|
FROM commit
|
|
@@ -474,8 +474,8 @@ WHERE
|
|
|
474
474
|
AND \${sql_snippets.author_email_condition}
|
|
475
475
|
-- Global SQL snippets (shared between dashboards)
|
|
476
476
|
AND \${global_sql_snippets.account_condition}
|
|
477
|
-
`,
|
|
477
|
+
`,Gl=S.observer(function({showSQLSnippets:t=!0,sx:n={}}){const r=K(),i=X(),o=r.context.current,l=(()=>{const c={context:{...i.mock_context.current,...o},filters:i.filters.previewValues};return t&&(c.sql_snippets=i.sqlSnippets.record),JSON.stringify(c,null,2)})();return s.jsx(a.Stack,{sx:{overflow:"hidden",...n},children:s.jsxs(a.Tabs,{defaultValue:"guide",keepMounted:!1,children:[s.jsxs(a.Tabs.List,{grow:!0,children:[s.jsx(a.Tabs.Tab,{value:"guide",icon:s.jsx(k.IconAlertCircle,{size:14}),children:"Guide"}),s.jsx(a.Tabs.Tab,{value:"local_query_vars",icon:s.jsx(k.IconVariable,{size:14}),children:"Variables in this dashboard"}),s.jsx(a.Tabs.Tab,{value:"global_sql_snippets",icon:s.jsx(k.IconVariablePlus,{size:14}),children:"Global SQL Snippets"})]}),s.jsx(a.Tabs.Panel,{value:"guide",pt:"xs",children:s.jsx(ct.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:DT})}),s.jsx(a.Tabs.Panel,{value:"local_query_vars",pt:"xs",children:s.jsx(ct.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:l})}),s.jsx(a.Tabs.Panel,{value:"global_sql_snippets",pt:"xs",children:s.jsxs(a.Stack,{spacing:10,children:[s.jsx(a.Alert,{icon:s.jsx(k.IconAlertCircle,{size:16}),title:"Global SQL Snippets",children:"SQL snippets worth sharing between dashboards are managed in System Settings by admins."}),s.jsx(TT,{})]})})]})})}),Nr=S.observer(()=>{const[e,t]=f.useState(!1);return s.jsxs(s.Fragment,{children:[s.jsx(a.Modal,{opened:e,onClose:()=>t(!1),title:"Query Variables",zIndex:320,size:"800px",children:s.jsx(Gl,{})}),s.jsx(a.Button,{variant:"subtle",onClick:()=>t(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},children:"See Query Variables"})]})}),Wl={pre:["function build_request({ context, filters }, utils) {"," // build the quest"," return { method: 'POST', url: '/', params: {}, headers: {}, data: {} }","}"].join(`
|
|
478
478
|
`),post:["function process_result(res, utils, state) {"," // your code goes here"," return data","}"].join(`
|
|
479
|
-
`)},
|
|
479
|
+
`)},IT=S.observer(({queryModel:e})=>e.typedAsHTTP?s.jsxs(a.Tabs,{defaultValue:"pre_process",orientation:"vertical",sx:{flexGrow:1},children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"pre_process",children:"Build Request"}),s.jsx(a.Tabs.Tab,{value:"post_process",children:"Process Result"}),s.jsx(Nr,{})]}),s.jsx(a.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:s.jsx(en,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:Wl.pre})}),s.jsx(a.Tabs.Panel,{value:"post_process",p:"sm",children:s.jsx(en,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:Wl.post})})]}):null),MT=S.observer(({queryID:e,usage:t})=>{const n=K().editor,r=o=>{if(o.type==="filter"){n.setPath(["_FILTERS_",o.id]);return}if(o.type==="panel"){const l=o.views[0].id;n.setPath(["_VIEWS_",l,"_PANELS_",o.id]);return}},i=o=>{n.setPath(["_VIEWS_",o])};return s.jsx(a.Stack,{py:"sm",px:"md",children:s.jsxs(a.Table,{highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{style:{width:100},children:"Type"}),s.jsx("th",{style:{width:"calc(50% - 50px)"},children:"Name"}),s.jsx("th",{children:"In View(s)"})]})}),s.jsx("tbody",{children:t.map(o=>s.jsxs("tr",{children:[s.jsx("td",{children:y.capitalize(o.type)}),s.jsx("td",{children:s.jsx(a.Anchor,{component:"button",type:"button",onClick:()=>r(o),children:o.label})}),s.jsx("td",{children:s.jsxs(a.Stack,{align:"flex-start",justify:"flex-start",spacing:2,children:[o.views.map(l=>s.jsx(a.Anchor,{component:"button",type:"button",onClick:()=>i(l.id),children:s.jsx(a.Box,{children:l.label})},l.id)),o.views.length===0&&s.jsx(a.Box,{children:"--"})]})})]},o.id))})]})})}),qr=({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(me,{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}})},AT=S.observer(({queryModel:e})=>{const t=f.useMemo(()=>y.groupBy(e.dependencies,"type"),[e.dependencies]),n=f.useMemo(()=>e.dependencies.some(i=>!i.valid),[e.dependencies]),r=e.dependencies.length>0;return r?s.jsxs(a.HoverCard,{withinPortal:!0,zIndex:340,shadow:"md",disabled:!r,children:[s.jsx(a.HoverCard.Target,{children:s.jsx(a.Button,{size:"xs",variant:"subtle",color:n?"red":"green",disabled:!r,leftIcon:n?s.jsx(k.IconAlertTriangle,{size:16}):s.jsx(k.IconDiscountCheckFilled,{size:16}),children:"Dependency"})}),s.jsx(a.HoverCard.Dropdown,{children:s.jsx(a.List,{spacing:"md",size:14,listStyleType:"none",children:Object.entries(t).map(([i,o])=>s.jsxs(a.List.Item,{children:[s.jsx(a.Text,{fw:"bold",ff:"monospace",children:i}),s.jsx(a.List,{withPadding:!0,size:14,sx:{fontFamily:"monospace",svg:{verticalAlign:"middle"}},children:o.map(l=>s.jsx(a.List.Item,{icon:s.jsx(a.Box,{sx:{path:{fill:l.valid?"rgb(18, 184, 134)":"rgb(250, 82, 82)"}},children:s.jsx(k.IconPointFilled,{size:12})}),children:l.key},l.key))})]},i))})})]}):s.jsx(a.Tooltip,{label:"This query has no dependency",children:s.jsx(a.Button,{size:"xs",variant:"subtle",color:"gray",leftIcon:s.jsx(k.IconHierarchy,{size:16,style:{transform:"rotate(180deg)"}}),sx:{transform:"none !important"},children:"Dependency"})})}),zT="SELECT 1",ET=S.observer(({queryModel:e})=>{const[t,n]=f.useState(e.sql),r=()=>{e.setSQL(t)},i=()=>{n(e.sql)},o=()=>{n(zT)};f.useEffect(()=>{n(e.sql)},[e.sql]);const l=t!==e.sql;return s.jsxs(a.Stack,{spacing:4,sx:{height:"100%"},children:[s.jsxs(a.Group,{mb:6,position:"apart",sx:{flexShrink:0,flexGrow:0},children:[s.jsx(a.Group,{position:"left",children:s.jsx(AT,{queryModel:e})}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:o,size:"xs",variant:"default",leftIcon:s.jsx(k.IconPlayerSkipBack,{size:16}),children:"Reset to default"}),s.jsx(a.Button,{onClick:i,color:"red",size:"xs",disabled:!l,leftIcon:s.jsx(k.IconRecycle,{size:16}),children:"Revert Changes"}),s.jsx(a.Button,{size:"xs",onClick:r,disabled:!l,leftIcon:s.jsx(k.IconDeviceFloppy,{size:16}),children:"Confirm Changes"})]})]}),s.jsx(qr,{height:"100%",value:t,onChange:n,theme:"sql-dark",defaultLanguage:"sql"})]})}),PT=({value:e,height:t="200px",defaultLanguage:n="sql"})=>s.jsx(me,{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}}),LT=S.observer(({value:e})=>{const n=ce().payloadForSQL,r=f.useMemo(()=>ls(e,n),[e,n]);return s.jsx(PT,{height:"100%",value:r})}),Rl={pre:["function process_request({ context, filters, sql }, utils) {"," // modify and return sql"," return sql","}"].join(`
|
|
480
480
|
`),post:["function process_result(data, utils, state) {"," // process data and return the result"," return data","}"].join(`
|
|
481
|
-
`)},LT=S.observer(({queryModel:e})=>e.typedAsSQL?s.jsxs(a.Tabs,{defaultValue:"Edit",orientation:"vertical",sx:{flexGrow:1},styles:{tabLabel:{width:"100%",height:"28px",lineHeight:"28px"}},keepMounted:!1,children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"Edit",children:s.jsx(a.Group,{spacing:14,position:"apart",children:"Edit SQL"})}),s.jsx(a.Tabs.Tab,{value:"Preview",children:"Preview SQL"}),s.jsx(a.Tabs.Tab,{value:"pre_process",children:"Process Request"}),s.jsx(a.Tabs.Tab,{value:"post_process",children:"Process Result"}),s.jsx(Nr,{}),e.datasource&&s.jsx(Nl,{dataSource:e.datasource})]}),s.jsx(a.Tabs.Panel,{value:"Edit",sx:{position:"relative"},p:"sm",children:s.jsx(zT,{queryModel:e})}),s.jsx(a.Tabs.Panel,{value:"Preview",p:0,pl:4,children:s.jsx(PT,{value:e.sql})}),s.jsx(a.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:s.jsx(en,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:Wl.pre})}),s.jsx(a.Tabs.Panel,{value:"post_process",p:"sm",children:s.jsx(en,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:Wl.post})})]}):null),Jn={height:"calc(100% - 44px)",padding:0},OT=S.observer(({queryModel:e})=>{const t=X(),n=f.useMemo(()=>e.datasource?e.typedAsHTTP?"HTTP":"SQL":"Configurations",[e.datasource,e.typedAsHTTP]),[r,i]=f.useState(n);f.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"}),s.jsx(a.Tabs.Tab,{value:"Data",disabled:!e.datasource,children:s.jsx(a.Tooltip,{label:"Need to pick a Data Source first",disabled:e.datasource,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(ST,{queryModel:e})}),e.typedAsSQL&&s.jsx(a.Tabs.Panel,{value:"SQL",sx:Jn,children:s.jsx(a.Stack,{sx:{height:"100%"},children:s.jsx(LT,{queryModel:e})})}),e.typedAsHTTP&&s.jsx(a.Tabs.Panel,{value:"HTTP",sx:Jn,children:s.jsx(a.Stack,{sx:{height:"100%"},children:s.jsx(DT,{queryModel:e})})}),s.jsx(a.Tabs.Panel,{value:"Data",sx:{...Jn,overflow:"hidden"},children:s.jsx(Br,{id:e.id,moreActions:null,refreshOnMount:!0})}),s.jsx(a.Tabs.Panel,{value:"Usage",sx:{...Jn,overflow:"hidden"},children:s.jsx(IT,{queryID:e.id,usage:o})})]})}),BT=S.observer(({id:e})=>{const n=X().queries.findByID(e);return e===""?null:n?s.jsx(OT,{queryModel:n}):s.jsx(a.Text,{size:14,color:"red",children:"Invalid Query ID"})}),$T=S.observer(({value:e})=>{const n=le().payloadForSQL,r=f.useMemo(()=>ls(e,n),[e,n]);return s.jsx(qr,{height:"100%",value:r})}),VT=S.observer(({item:e,remove:t,onKeyChanged:n})=>{const[r,i]=f.useState("SQL"),[o,l]=f.useState(e.key),c=()=>{e.setKey(o),n(o)},u=o!==e.key,d=e.isADuplicatedKey(o),[p,h]=f.useState(e.value),x=()=>{e.setValue(p)};f.useEffect(()=>{l(e.key),h(e.value)},[e]);const m=p!==e.value,j=Me.useModals(),w=()=>{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(_.DeviceFloppy,{size:16})}),error:d}),s.jsx(a.Button,{leftIcon:s.jsx(_.Trash,{size:16}),color:"red",variant:"light",onClick:w,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(Nr,{}),s.jsx(a.ActionIcon,{color:"blue",variant:"filled",onClick:x,disabled:!m,sx:{position:"absolute",top:0,right:10},children:s.jsx(_.DeviceFloppy,{size:18})})]}),s.jsx(a.Tabs.Panel,{value:"SQL",pt:"sm",children:s.jsx(qr,{height:"100%",value:p,onChange:h,defaultLanguage:"sql",theme:"sql-dark"})}),s.jsx(a.Tabs.Panel,{value:"Preview",pt:"sm",children:s.jsx($T,{value:p})})]})]})}),NT=S.observer(({id:e})=>{const t=K(),n=X(),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(VT,{item:r,remove:o,onKeyChanged:l})}),qT=S.observer(()=>{const[e,t]=f.useState([]),n=Me.useModals(),r=K(),i=h=>{r.editor.setPath(["_SQL_SNIPPETS_",h])},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=f.useMemo(()=>r.content.sqlSnippets.sortedList.map(h=>h.key),[r.content.sqlSnippets.sortedList]),u=()=>{t(c)},d=()=>{t([])},p=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(k.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(k.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(h=>{var m;const x=((m=p[h.key])==null?void 0:m.length)??0;return s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx(a.Checkbox,{value:h.key,styles:{input:{cursor:"pointer"}}})}),s.jsx("td",{children:h.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(h.key),children:"Open"})})]},h.key)})})]})})})]})}),FT=S.observer(({id:e})=>{const t=Me.useModals(),n=K(),r=X();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(_.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(m_,{view:i})})]})});function GT(e){return e.length===1&&e[0]==="_QUERY_VARS_"}function WT(e){return e.length===1&&e[0]==="_MOCK_CONTEXT_"}function RT(e){return e.length===1&&e[0]==="_FILTERS_"}function QT(e){return e.length===2&&e[0]==="_FILTERS_"}function UT(e){return e.length===1&&e[0]==="_SQL_SNIPPETS_"}function YT(e){return e.length===2&&e[0]==="_SQL_SNIPPETS_"}function KT(e){return e.length===2&&e[0]==="_QUERIES_"}function XT(e){return e.length===1&&e[0]==="_QUERIES_"}function JT(e){return e.length===2&&e[0]==="_VIEWS_"}function ZT(e){return e.length===4&&e[0]==="_VIEWS_"&&e[2]==="_PANELS_"}const HT=S.observer(()=>s.jsx(a.Stack,{sx:{height:"100%"},p:"sm",children:s.jsx(Fl,{})})),eD=S.observer(()=>{const e=K().editor,t=e.path;return GT(t)?s.jsx(HT,{}):WT(t)?s.jsx(jk,{}):RT(t)?s.jsx(bk,{}):QT(t)?s.jsx(a.Box,{p:"xs",pl:20,children:s.jsx(yk,{id:t[1]})}):UT(t)?s.jsx(qT,{}):YT(t)?s.jsx(NT,{id:t[1]}):XT(t)?s.jsx(sT,{}):KT(t)?s.jsx(BT,{id:t[1]}):JT(t)?s.jsx(a.Box,{p:"xs",pl:20,children:s.jsx(FT,{id:t[1]})}):ZT(t)?s.jsx(nT,{viewID:t[1],panelID:t[3]}):s.jsx(a.Box,{children:e.path})}),tD=S.observer(()=>s.jsx(eD,{})),nD=S.observer(()=>{const e=K(),t=()=>{const n=new Date().getTime().toString(),r={id:n,key:n,label:n,order:e.content.filters.current.length+1,type:ue.TextInput,config:Lo(),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(k.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"})}),sD=S.observer(({parentID:e})=>{const t=X();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(k.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:()=>t.addANewPanel(n.id),sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Panel"})}),rD=S.observer(()=>{const e=K(),t=()=>{const n=new Date().getTime().toString(),r={id:n,name:n,type:Ie.Postgresql,key:"",sql:""};e.content.queries.append(r),e.editor.setPath(["_QUERIES_",n])};return s.jsx(a.Button,{variant:"subtle",leftIcon:s.jsx(k.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Query"})}),iD=S.observer(()=>{const e=K(),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(k.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a SQL Snippet"})}),aD=S.observer(()=>{const e=X();return s.jsx(a.Button,{variant:"subtle",leftIcon:s.jsx(k.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"})}),oD=S.observer(()=>{const e=K();return s.jsx(a.Button,{variant:"subtle",rightIcon:s.jsx(k.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"})}),lD=S.observer(()=>{const e=K();return s.jsx(a.Button,{variant:"subtle",rightIcon:s.jsx(k.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"})}),cD=S.observer(()=>{const e=K();return s.jsx(a.Button,{variant:"subtle",rightIcon:s.jsx(k.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"})}),uD=S.observer(({action_type:e,parentID:t})=>e==="_Add_A_Filter_"?s.jsx(nD,{}):e==="_Add_A_SQL_SNIPPET_"?s.jsx(iD,{}):e==="_Add_A_QUERY_"?s.jsx(rD,{}):e==="_Add_A_VIEW_"?s.jsx(aD,{}):e==="_Add_A_PANEL_"?s.jsx(sD,{parentID:t}):e==="_QUERIES_SETTINGS_"?s.jsx(oD,{}):e==="_SQL_SNIPPETS_SETTINGS_"?s.jsx(lD,{}):e==="_FILTERS_SETTINGS_"?s.jsx(cD,{}):null),Rl=S.observer(({option:e})=>{var d;const t=K().editor,n=t.isOptionActive,r=n(t.path,e),i=t.isOptionOpened,o=t.navigate,l=i(e),[c,u]=f.useState(l);return f.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(p=>p._type==="ACTION"?s.jsx(uD,{action_type:p._action_type,parentID:p.parentID},`_ADD_${p.value}_`):s.jsx(Rl,{option:p},p.value))},e.label)}),dD=S.observer(()=>{const e=K();return s.jsx(a.Box,{sx:{position:"relative"},children:e.editor.navOptions.map(t=>s.jsx(Rl,{option:t},t.value))})}),pD=S.observer(()=>{const e=K();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"},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(dD,{})}),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:()=>e.editor.close(),children:"Close"})})})]})}),hD={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"}},xD=S.observer(()=>{const e=K().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(pD,{}),styles:hD,children:s.jsx(tD,{})})})}),fD=e=>e.replace(/([^:])(\/\/+)/g,"$1/");function gD(e){f.useEffect(()=>{if(ge.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const n=fD(e);ge.loader.config({paths:{vs:n}}),ge.loader.init().then(r=>console.log("monaco instance:",r))},[])}Ba();const mD={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},u)=>{gD(o.monacoPath),cs(o);const{data:d=[]}=V.useRequest(ds),{data:p=[]}=V.useRequest(Si),h=f.useMemo(()=>_l(t,n,d,p,e),[t,n]);f.useImperativeHandle(u,()=>h,[h]),kl(h.content,!0),f.useEffect(()=>{h.context.replace(e)},[e]),f.useEffect(()=>{h.datasources.replace(d)},[d]),f.useEffect(()=>{h.globalSQLSnippets.replace(p)},[p]),f.useEffect(()=>W.reaction(()=>W.toJS(h.json),w=>{l==null||l(w)}),[h]);const x=async()=>{await r(h.json,h.content.json)},m=V.useCreation(wr,[]),j=Tl(m);return s.jsx(Me.ModalsProvider,{children:s.jsx(ms,{value:{searchButtonProps:o.searchButtonProps},children:s.jsx(xs,{value:h,children:s.jsx(ys,{value:h.content,children:s.jsx(pn.Provider,{value:{inEditMode:!0},children:s.jsx(et.Provider,{value:m,children:s.jsxs(Nn,{configure:j,children:[s.jsx(a.AppShell,{padding:0,header:s.jsx(M_,{saveDashboardChanges:x,headerSlot:c}),navbar:s.jsx(sk,{}),styles:mD,children:s.jsx(a.Box,{className:`${i} dashboard-root`,sx:{position:"relative"},children:h.content.views.visibleViews.map(w=>s.jsx(xl,{view:w},w.id))})}),s.jsx(xD,{})]})})})})})})})},bD=S.observer(f.forwardRef(yD)),bI="",Ql=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:Jo,queries:Ho,sqlSnippets:el,views:Ro,panels:Ko,mock_context:To}).views(e=>({get json(){return{id:e.id,name:e.name,create_time:e.create_time,update_time:e.update_time,dashboard_id:e.dashboard_id,content:{views:e.views.json,panels:e.panels.json,filters:e.filters.json,version:e.version,definition:{queries:e.queries.json,sqlSnippets:e.sqlSnippets.json,mock_context:e.mock_context.current}}}},get 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:Wn(e.sqlSnippets.current,"key","value",r),global_sql_snippets:Wn(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 us(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 jD({id:e,name:t,dashboard_id:n,create_time:r,update_time:i,content:o}){if(!o)throw new Error("unexpected null content when creating a content model");const{version:l,filters:c,views:u,panels:d,definition:{queries:p,sqlSnippets:h,mock_context:x={}}}=o;return Ql.create({id:e,name:t,dashboard_id:n,create_time:r,update_time:i,version:l,filters:Zo(c),queries:i1(p),sqlSnippets:o1(h),mock_context:Do(x),views:US(u),panels:{list:d}})}const vD=g.types.model({id:g.types.identifier,name:g.types.string,group:g.types.string,content:Ql,content_id:g.types.string,datasources:RS,globalSQLSnippets:Fo,context:kr});function wD({id:e,name:t,group:n,content_id:r},i,o,l,c){return vD.create({id:e,name:t,group:n,content_id:r,content:jD(i),datasources:{list:o},globalSQLSnippets:{list:l},context:Go(c)})}Ba();const CD=S.observer(({context:e,dashboard:t,content:n,className:r="dashboard",config:i,fullScreenPanelID:o,setFullScreenPanelID:l})=>{cs(i);const{data:c=[]}=V.useRequest(ds),{data:u=[]}=V.useRequest(Si),d=f.useMemo(()=>wD(t,n,c,u,e),[t,n]);kl(d.content,!1),f.useEffect(()=>{d.context.replace(e)},[e]),f.useEffect(()=>{d.datasources.replace(c)},[c]),f.useEffect(()=>{d.globalSQLSnippets.replace(u)},[u]);const p=V.useCreation(wr,[]),h=Tl(p);return s.jsx(Me.ModalsProvider,{children:s.jsx(ms,{value:{searchButtonProps:i.searchButtonProps},children:s.jsx(xs,{value:d,children:s.jsx(ys,{value:d.content,children:s.jsx(js.Provider,{value:{fullScreenPanelID:o,setFullScreenPanelID:l},children:s.jsx(pn.Provider,{value:{inEditMode:!1},children:s.jsx(a.Box,{className:`${r} dashboard-root`,children:s.jsx(et.Provider,{value:p,children:s.jsx(Nn,{configure:h,children:d.content.views.visibleViews.map(x=>s.jsx(Qn,{view:x},x.id))})})})})})})})})})});I.extend(Sc),I.extend(_c),I.extend(kc),I.extend(Tc),I.extend(Dc),I.extend(Ic),I.extend(Mc),I.extend(Ac),I.extend(zc),I.extend(Ec),I.extend(Oc),I.extend(Bc),I.extend($c),I.extend(Vc),I.extend(Nc),I.extend(Pc),I.extend(Lc),I.extend(qc),I.extend(Fc),I.extend(Gc),I.extend(Wc),I.extend(Rc),I.extend(Qc),I.extend(Uc),I.extend(Yc),I.extend(Kc),I.extend(Xc),I.extend(Jc),I.extend(Zc),I.extend(Hc),I.extend(tu),I.extend(nu),I.extend(eu),I.tz.setDefault("UTC"),I.updateLocale("en",{weekStart:1});const SD=()=>Promise.resolve().then(()=>Mu).then(({version:e})=>(console.log(`[@devtable/dashboard] version: ${e}`),e));C.APIClient=Xe,C.ContentModel=zr,C.ContentModelContextProvider=ys,C.DashboardApiClient=ji,C.DashboardApiFacadeClient=vi,C.DashboardEditor=bD,C.DashboardFilterType=ue,C.DashboardMode=fl,C.DashboardModel=Sl,C.DashboardModelContextProvider=xs,C.DashboardThemeContextProvider=ms,C.DashboardViewEditor=xl,C.DashboardViewRender=Qn,C.DefaultApiClient=bi,C.DescriptionPopover=Tr,C.FacadeApiClient=fu,C.FiltersModel=ml,C.FullScreenPanel=cl,C.FullScreenPanelContext=js,C.LayoutStateContext=pn,C.Panel=ll,C.PanelContextProvider=bs,C.PanelErrorOrStateMessage=al,C.PanelModel=jl,C.PanelRender=Ir,C.PanelVizSection=Dr,C.PanelsModel=vl,C.QueriesModel=yl,C.ReadOnlyDashboard=CD,C.SQLSnippetsModel=bl,C.ViewComponentTypeBackground=gl,C.ViewComponentTypeColor=G1,C.ViewComponentTypeName=F1,C.ViewsModel=wl,C.Viz=il,C.applyPartialDashboard=n_,C.configureAPIClient=cs,C.createContentModel=Cl,C.createDashboardModel=_l,C.facadeApiClient=wi,C.getInitialDashboardViewsModel=Ar,C.getVersion=SD,C.initialDashboardContent=W1,C.useDashboardContext=fs,C.useDashboardThemeContext=Ai,C.useEditContentModelContext=X,C.useEditDashboardContext=K,C.useEditPanelContext=Le,C.useFullScreenPanelContext=Oi,C.usePanelFullScreen=ul,C.useRenderContentModelContext=le,C.useRenderDashboardContext=gs,C.useRenderPanelContext=dt,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})});
|
|
481
|
+
`)},OT=S.observer(({queryModel:e})=>e.typedAsSQL?s.jsxs(a.Tabs,{defaultValue:"Edit",orientation:"vertical",sx:{flexGrow:1},styles:{tabLabel:{width:"100%",height:"28px",lineHeight:"28px"}},keepMounted:!1,children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"Edit",children:s.jsx(a.Group,{spacing:14,position:"apart",children:"Edit SQL"})}),s.jsx(a.Tabs.Tab,{value:"Preview",children:"Preview SQL"}),s.jsx(a.Tabs.Tab,{value:"pre_process",children:"Process Request"}),s.jsx(a.Tabs.Tab,{value:"post_process",children:"Process Result"}),s.jsx(Nr,{}),e.datasource&&s.jsx(ql,{dataSource:e.datasource})]}),s.jsx(a.Tabs.Panel,{value:"Edit",sx:{position:"relative"},p:"sm",children:s.jsx(ET,{queryModel:e})}),s.jsx(a.Tabs.Panel,{value:"Preview",p:0,pl:4,children:s.jsx(LT,{value:e.sql})}),s.jsx(a.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:s.jsx(en,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:Rl.pre})}),s.jsx(a.Tabs.Panel,{value:"post_process",p:"sm",children:s.jsx(en,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:Rl.post})})]}):null),Jn={height:"calc(100% - 44px)",padding:0},BT=S.observer(({queryModel:e})=>{const t=X(),n=f.useMemo(()=>e.datasource?e.typedAsHTTP?"HTTP":"SQL":"Configurations",[e.datasource,e.typedAsHTTP]),[r,i]=f.useState(n);f.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"}),s.jsx(a.Tabs.Tab,{value:"Data",disabled:!e.datasource,children:s.jsx(a.Tooltip,{label:"Need to pick a Data Source first",disabled:e.datasource,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(_T,{queryModel:e})}),e.typedAsSQL&&s.jsx(a.Tabs.Panel,{value:"SQL",sx:Jn,children:s.jsx(a.Stack,{sx:{height:"100%"},children:s.jsx(OT,{queryModel:e})})}),e.typedAsHTTP&&s.jsx(a.Tabs.Panel,{value:"HTTP",sx:Jn,children:s.jsx(a.Stack,{sx:{height:"100%"},children:s.jsx(IT,{queryModel:e})})}),s.jsx(a.Tabs.Panel,{value:"Data",sx:{...Jn,overflow:"hidden"},children:s.jsx(Br,{id:e.id,moreActions:null,refreshOnMount:!0})}),s.jsx(a.Tabs.Panel,{value:"Usage",sx:{...Jn,overflow:"hidden"},children:s.jsx(MT,{queryID:e.id,usage:o})})]})}),$T=S.observer(({id:e})=>{const n=X().queries.findByID(e);return e===""?null:n?s.jsx(BT,{queryModel:n}):s.jsx(a.Text,{size:14,color:"red",children:"Invalid Query ID"})}),VT=S.observer(({value:e})=>{const n=ce().payloadForSQL,r=f.useMemo(()=>ls(e,n),[e,n]);return s.jsx(qr,{height:"100%",value:r})}),NT=S.observer(({item:e,remove:t,onKeyChanged:n})=>{const[r,i]=f.useState("SQL"),[o,l]=f.useState(e.key),c=()=>{e.setKey(o),n(o)},d=o!==e.key,u=e.isADuplicatedKey(o),[p,h]=f.useState(e.value),x=()=>{e.setValue(p)};f.useEffect(()=>{l(e.key),h(e.value)},[e]);const m=p!==e.value,j=Ae.useModals(),w=()=>{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:u?"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:!d||u,children:s.jsx(_.DeviceFloppy,{size:16})}),error:u}),s.jsx(a.Button,{leftIcon:s.jsx(_.Trash,{size:16}),color:"red",variant:"light",onClick:w,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(Nr,{}),s.jsx(a.ActionIcon,{color:"blue",variant:"filled",onClick:x,disabled:!m,sx:{position:"absolute",top:0,right:10},children:s.jsx(_.DeviceFloppy,{size:18})})]}),s.jsx(a.Tabs.Panel,{value:"SQL",pt:"sm",children:s.jsx(qr,{height:"100%",value:p,onChange:h,defaultLanguage:"sql",theme:"sql-dark"})}),s.jsx(a.Tabs.Panel,{value:"Preview",pt:"sm",children:s.jsx(VT,{value:p})})]})]})}),qT=S.observer(({id:e})=>{const t=K(),n=X(),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(NT,{item:r,remove:o,onKeyChanged:l})}),FT=S.observer(()=>{const[e,t]=f.useState([]),n=Ae.useModals(),r=K(),i=h=>{r.editor.setPath(["_SQL_SNIPPETS_",h])},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=f.useMemo(()=>r.content.sqlSnippets.sortedList.map(h=>h.key),[r.content.sqlSnippets.sortedList]),d=()=>{t(c)},u=()=>{t([])},p=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:d,children:"Select All"}),s.jsx(a.Button,{variant:"default",size:"xs",onClick:u,children:"Clear Selection"})]}),s.jsx(a.Button,{size:"xs",color:"blue",leftIcon:s.jsx(k.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(k.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(h=>{var m;const x=((m=p[h.key])==null?void 0:m.length)??0;return s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx(a.Checkbox,{value:h.key,styles:{input:{cursor:"pointer"}}})}),s.jsx("td",{children:h.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(h.key),children:"Open"})})]},h.key)})})]})})})]})}),GT=S.observer(({id:e})=>{const t=Ae.useModals(),n=K(),r=X();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(_.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(y_,{view:i})})]})});function WT(e){return e.length===1&&e[0]==="_QUERY_VARS_"}function RT(e){return e.length===1&&e[0]==="_MOCK_CONTEXT_"}function QT(e){return e.length===1&&e[0]==="_FILTERS_"}function UT(e){return e.length===2&&e[0]==="_FILTERS_"}function YT(e){return e.length===1&&e[0]==="_SQL_SNIPPETS_"}function KT(e){return e.length===2&&e[0]==="_SQL_SNIPPETS_"}function XT(e){return e.length===2&&e[0]==="_QUERIES_"}function JT(e){return e.length===1&&e[0]==="_QUERIES_"}function ZT(e){return e.length===2&&e[0]==="_VIEWS_"}function HT(e){return e.length===4&&e[0]==="_VIEWS_"&&e[2]==="_PANELS_"}const eD=S.observer(()=>s.jsx(a.Stack,{sx:{height:"100%"},p:"sm",children:s.jsx(Gl,{})})),tD=S.observer(()=>{const e=K().editor,t=e.path;return WT(t)?s.jsx(eD,{}):RT(t)?s.jsx(vk,{}):QT(t)?s.jsx(jk,{}):UT(t)?s.jsx(a.Box,{p:"xs",pl:20,children:s.jsx(bk,{id:t[1]})}):YT(t)?s.jsx(FT,{}):KT(t)?s.jsx(qT,{id:t[1]}):JT(t)?s.jsx(rT,{}):XT(t)?s.jsx($T,{id:t[1]}):ZT(t)?s.jsx(a.Box,{p:"xs",pl:20,children:s.jsx(GT,{id:t[1]})}):HT(t)?s.jsx(sT,{viewID:t[1],panelID:t[3]}):s.jsx(a.Box,{children:e.path})}),nD=S.observer(()=>s.jsx(tD,{})),sD=S.observer(()=>{const e=K(),t=()=>{const n=new Date().getTime().toString(),r={id:n,key:n,label:n,order:e.content.filters.current.length+1,type:ue.TextInput,config:Oo(),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(k.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"})}),rD=S.observer(({parentID:e})=>{const t=X();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(k.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"})}),iD=S.observer(()=>{const e=K(),t=()=>{const n=new Date().getTime().toString(),r={id:n,name:n,type:Me.Postgresql,key:"",sql:""};e.content.queries.append(r),e.editor.setPath(["_QUERIES_",n])};return s.jsx(a.Button,{variant:"subtle",leftIcon:s.jsx(k.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"})}),aD=S.observer(()=>{const e=K(),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(k.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"})}),oD=S.observer(()=>{const e=X();return s.jsx(a.Button,{variant:"subtle",leftIcon:s.jsx(k.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"})}),lD=S.observer(()=>{const e=K();return s.jsx(a.Button,{variant:"subtle",rightIcon:s.jsx(k.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"})}),cD=S.observer(()=>{const e=K();return s.jsx(a.Button,{variant:"subtle",rightIcon:s.jsx(k.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>e.editor.setPath(["_SQL_SNIPPETS_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:"Manage SQL Snippets"})}),dD=S.observer(()=>{const e=K();return s.jsx(a.Button,{variant:"subtle",rightIcon:s.jsx(k.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"})}),uD=S.observer(({action_type:e,parentID:t})=>e==="_Add_A_Filter_"?s.jsx(sD,{}):e==="_Add_A_SQL_SNIPPET_"?s.jsx(aD,{}):e==="_Add_A_QUERY_"?s.jsx(iD,{}):e==="_Add_A_VIEW_"?s.jsx(oD,{}):e==="_Add_A_PANEL_"?s.jsx(rD,{parentID:t}):e==="_QUERIES_SETTINGS_"?s.jsx(lD,{}):e==="_SQL_SNIPPETS_SETTINGS_"?s.jsx(cD,{}):e==="_FILTERS_SETTINGS_"?s.jsx(dD,{}):null),Ql=S.observer(({option:e})=>{var u;const t=K().editor,n=t.isOptionActive,r=n(t.path,e),i=t.isOptionOpened,o=t.navigate,l=i(e),[c,d]=f.useState(l);return f.useEffect(()=>{d(l)},[l]),s.jsx(a.NavLink,{active:r,defaultOpened:l,opened:c,onChange:d,label:e.label,onClick:()=>o(e),icon:e.Icon?s.jsx(e.Icon,{size:18}):null,children:(u=e.children)==null?void 0:u.map(p=>p._type==="ACTION"?s.jsx(uD,{action_type:p._action_type,parentID:p.parentID},`_ADD_${p.value}_`):s.jsx(Ql,{option:p},p.value))},e.label)}),pD=S.observer(()=>{const e=K();return s.jsx(a.Box,{sx:{position:"relative"},children:e.editor.navOptions.map(t=>s.jsx(Ql,{option:t},t.value))})}),hD=S.observer(()=>{const e=K();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"},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(pD,{})}),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:()=>e.editor.close(),children:"Close"})})})]})}),xD={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"}},fD=S.observer(()=>{const e=K().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(hD,{}),styles:xD,children:s.jsx(nD,{})})})}),gD=e=>e.replace(/([^:])(\/\/+)/g,"$1/");function mD(e){f.useEffect(()=>{if(me.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const n=gD(e);me.loader.config({paths:{vs:n}}),me.loader.init().then(r=>console.log("monaco instance:",r))},[])}$a();const yD={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:60+30,height:"100vh"}},bD=({context:e,dashboard:t,content:n,update:r,className:i="dashboard",config:o,onChange:l,headerSlot:c},d)=>{mD(o.monacoPath),cs(o);const{data:u=[]}=V.useRequest(us),{data:p=[]}=V.useRequest(Si),h=f.useMemo(()=>kl(t,n,u,p,e),[t,n]);f.useImperativeHandle(d,()=>h,[h]),Tl(h.content,!0),f.useEffect(()=>{h.context.replace(e)},[e]),f.useEffect(()=>{h.datasources.replace(u)},[u]),f.useEffect(()=>{h.globalSQLSnippets.replace(p)},[p]),f.useEffect(()=>W.reaction(()=>W.toJS(h.json),w=>{l==null||l(w)}),[h]);const x=async()=>{await r(h.json,h.content.json)},m=V.useCreation(wr,[]),j=Dl(m);return s.jsx(Ae.ModalsProvider,{children:s.jsx(ms,{value:{searchButtonProps:o.searchButtonProps},children:s.jsx(xs,{value:h,children:s.jsx(ys,{value:h.content,children:s.jsx(pn.Provider,{value:{inEditMode:!0},children:s.jsx(et.Provider,{value:m,children:s.jsxs(Nn,{configure:j,children:[s.jsx(a.AppShell,{padding:0,header:s.jsx(A_,{saveDashboardChanges:x,headerSlot:c}),navbar:s.jsx(rk,{}),styles:yD,children:s.jsx(a.Box,{className:`${i} dashboard-root`,sx:{position:"relative"},children:h.content.views.visibleViews.map(w=>s.jsx(fl,{view:w},w.id))})}),s.jsx(fD,{})]})})})})})})})},jD=S.observer(f.forwardRef(bD)),jI="",Ul=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:Zo,queries:el,sqlSnippets:tl,views:Qo,panels:Xo,mock_context:Do}).views(e=>({get json(){return{id:e.id,name:e.name,create_time:e.create_time,update_time:e.update_time,dashboard_id:e.dashboard_id,content:{views:e.views.json,panels:e.panels.json,filters:e.filters.json,version:e.version,definition:{queries:e.queries.json,sqlSnippets:e.sqlSnippets.json,mock_context:e.mock_context.current}}}},get 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:Wn(e.sqlSnippets.current,"key","value",r),global_sql_snippets:Wn(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 ds(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 vD({id:e,name:t,dashboard_id:n,create_time:r,update_time:i,content:o}){if(!o)throw new Error("unexpected null content when creating a content model");const{version:l,filters:c,views:d,panels:u,definition:{queries:p,sqlSnippets:h,mock_context:x={}}}=o;return Ul.create({id:e,name:t,dashboard_id:n,create_time:r,update_time:i,version:l,filters:Ho(c),queries:a1(p),sqlSnippets:l1(h),mock_context:Io(x),views:YS(d),panels:{list:u}})}const wD=g.types.model({id:g.types.identifier,name:g.types.string,group:g.types.string,content:Ul,content_id:g.types.string,datasources:QS,globalSQLSnippets:Go,context:kr});function CD({id:e,name:t,group:n,content_id:r},i,o,l,c){return wD.create({id:e,name:t,group:n,content_id:r,content:vD(i),datasources:{list:o},globalSQLSnippets:{list:l},context:Wo(c)})}$a();const SD=S.observer(({context:e,dashboard:t,content:n,className:r="dashboard",config:i,fullScreenPanelID:o,setFullScreenPanelID:l})=>{cs(i);const{data:c=[]}=V.useRequest(us),{data:d=[]}=V.useRequest(Si),u=f.useMemo(()=>CD(t,n,c,d,e),[t,n]);Tl(u.content,!1),f.useEffect(()=>{u.context.replace(e)},[e]),f.useEffect(()=>{u.datasources.replace(c)},[c]),f.useEffect(()=>{u.globalSQLSnippets.replace(d)},[d]);const p=V.useCreation(wr,[]),h=Dl(p);return s.jsx(Ae.ModalsProvider,{children:s.jsx(ms,{value:{searchButtonProps:i.searchButtonProps},children:s.jsx(xs,{value:u,children:s.jsx(ys,{value:u.content,children:s.jsx(js.Provider,{value:{fullScreenPanelID:o,setFullScreenPanelID:l},children:s.jsx(pn.Provider,{value:{inEditMode:!1},children:s.jsx(a.Box,{className:`${r} dashboard-root`,children:s.jsx(et.Provider,{value:p,children:s.jsx(Nn,{configure:h,children:u.content.views.visibleViews.map(x=>s.jsx(Qn,{view:x},x.id))})})})})})})})})})});I.extend(_c),I.extend(kc),I.extend(Tc),I.extend(Dc),I.extend(Ic),I.extend(Mc),I.extend(Ac),I.extend(zc),I.extend(Ec),I.extend(Pc),I.extend(Bc),I.extend($c),I.extend(Vc),I.extend(Nc),I.extend(qc),I.extend(Lc),I.extend(Oc),I.extend(Fc),I.extend(Gc),I.extend(Wc),I.extend(Rc),I.extend(Qc),I.extend(Uc),I.extend(Yc),I.extend(Kc),I.extend(Xc),I.extend(Jc),I.extend(Zc),I.extend(Hc),I.extend(ed),I.extend(nd),I.extend(sd),I.extend(td),I.tz.setDefault("UTC"),I.updateLocale("en",{weekStart:1});const _D=()=>Promise.resolve().then(()=>Ad).then(({version:e})=>(console.log(`[@devtable/dashboard] version: ${e}`),e));C.APIClient=Xe,C.ContentModel=zr,C.ContentModelContextProvider=ys,C.DashboardApiClient=ji,C.DashboardApiFacadeClient=vi,C.DashboardEditor=jD,C.DashboardFilterType=ue,C.DashboardMode=gl,C.DashboardModel=_l,C.DashboardModelContextProvider=xs,C.DashboardThemeContextProvider=ms,C.DashboardViewEditor=fl,C.DashboardViewRender=Qn,C.DefaultApiClient=bi,C.DescriptionPopover=Tr,C.FacadeApiClient=gd,C.FiltersModel=yl,C.FullScreenPanel=dl,C.FullScreenPanelContext=js,C.LayoutStateContext=pn,C.Panel=cl,C.PanelContextProvider=bs,C.PanelErrorOrStateMessage=ol,C.PanelModel=vl,C.PanelRender=Ir,C.PanelVizSection=Dr,C.PanelsModel=wl,C.QueriesModel=bl,C.ReadOnlyDashboard=SD,C.SQLSnippetsModel=jl,C.ViewComponentTypeBackground=ml,C.ViewComponentTypeColor=W1,C.ViewComponentTypeName=G1,C.ViewsModel=Cl,C.Viz=al,C.applyPartialDashboard=s_,C.configureAPIClient=cs,C.createContentModel=Sl,C.createDashboardModel=kl,C.facadeApiClient=wi,C.getInitialDashboardViewsModel=Ar,C.getVersion=_D,C.initialDashboardContent=R1,C.useDashboardContext=fs,C.useDashboardThemeContext=Ai,C.useEditContentModelContext=X,C.useEditDashboardContext=K,C.useEditPanelContext=Le,C.useFullScreenPanelContext=Oi,C.usePanelFullScreen=ul,C.useRenderContentModelContext=ce,C.useRenderDashboardContext=gs,C.useRenderPanelContext=ut,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})});
|