@devtable/dashboard 10.49.0 → 10.50.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/dist/components/panel/panel-render/full-screen-render/use-panel-full-screen.d.ts +456 -0
  2. package/dist/components/panel/settings/common/aggregation-selector.d.ts +1 -0
  3. package/dist/components/plugins/plugin-context.d.ts +455 -0
  4. package/dist/contexts/panel-context.d.ts +910 -0
  5. package/dist/dashboard-editor/model/panels/panel.d.ts +209 -0
  6. package/dist/dashboard-editor/model/views/index.d.ts +857 -857
  7. package/dist/dashboard-editor/model/views/view.d.ts +14 -14
  8. package/dist/dashboard-editor/ui/settings/content/edit-panel/variable-config/index.d.ts +2 -0
  9. package/dist/dashboard-editor/ui/settings/content/edit-panel/variable-config/model.d.ts +86 -81
  10. package/dist/dashboard-editor/ui/settings/content/edit-panel/variable-config/preview-variables.d.ts +3 -0
  11. package/dist/dashboard-editor/ui/settings/content/edit-panel/variable-config/variable-editor.d.ts +8 -0
  12. package/dist/dashboard-editor/ui/settings/content/edit-panel/variable-config/variable-field.d.ts +1 -1
  13. package/dist/{utils/template/editor → dashboard-editor/ui/settings/content/edit-panel/variable-config}/variable-style.d.ts +1 -1
  14. package/dist/dashboard-editor/ui/settings/content/edit-panel/variable-config/variables-editor.d.ts +11 -0
  15. package/dist/dashboard-editor/ui/settings/content/edit-view/edit-view-form/index.d.ts +141 -141
  16. package/dist/dashboard.es.js +9719 -9703
  17. package/dist/dashboard.umd.js +82 -82
  18. package/dist/model/meta-model/dashboard/content/panel/panel.d.ts +69 -0
  19. package/dist/model/meta-model/dashboard/content/panel/variable.d.ts +39 -0
  20. package/dist/model/meta-model/dashboard/content/view/view.d.ts +12 -12
  21. package/dist/model/render-model/dashboard/content/panels/panel.d.ts +209 -0
  22. package/dist/model/render-model/dashboard/content/views/view.d.ts +12 -12
  23. package/dist/model/render-model/dashboard/content/views/views.d.ts +586 -586
  24. package/dist/model/utils/draft.d.ts +1 -0
  25. package/dist/stats.html +1 -1
  26. package/dist/utils/aggregation.d.ts +11 -7
  27. package/dist/utils/template/editor/index.d.ts +0 -1
  28. package/dist/utils/template/render/render-string.d.ts +3 -0
  29. package/package.json +1 -1
  30. package/dist/dashboard-editor/ui/settings/content/edit-panel/variable-config/styles.d.ts +0 -8
  31. package/dist/dashboard-editor/ui/settings/content/edit-panel/variable-config/variable-config-panel.d.ts +0 -10
  32. package/dist/model/render-model/dashboard/content/panels/panels.d.ts +0 -15393
  33. package/dist/utils/template/editor/variable-field.d.ts +0 -9
@@ -1,4 +1,4 @@
1
- (function(w,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("eventemitter2"),require("chroma-js"),require("echarts-for-react/lib/core"),require("echarts-gl"),require("echarts/components"),require("echarts/core"),require("echarts/renderers"),require("react-hook-form"),require("tabler-icons-react"),require("echarts/charts"),require("@tabler/icons-react"),require("@mantine/hooks"),require("@mantine/notifications"),require("@mantine/tiptap"),require("@tiptap/extension-color"),require("@tiptap/extension-highlight"),require("@tiptap/extension-placeholder"),require("@tiptap/extension-subscript"),require("@tiptap/extension-superscript"),require("@tiptap/extension-text-align"),require("@tiptap/extension-text-style"),require("@tiptap/extension-table"),require("@tiptap/extension-table-cell"),require("@tiptap/extension-table-header"),require("@tiptap/extension-table-row"),require("@tiptap/extension-underline"),require("@tiptap/react"),require("@tiptap/starter-kit"),require("prosemirror-keymap"),require("prosemirror-commands"),require("prosemirror-schema-list"),require("@monaco-editor/react"),require("popmotion"),require("d3-regression"),require("@mantine/prism"),require("@tanstack/react-table"),require("react-virtual"),require("@mantine/dates"),require("rc-select"),require("rc-tree-select"),require("react-grid-layout"),require("mobx-state-tree"),require("performant-array-to-tree"),require("@json2csv/whatwg"),require("file-saver"),require("jszip"),require("dom-to-image-more"),require("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","eventemitter2","chroma-js","echarts-for-react/lib/core","echarts-gl","echarts/components","echarts/core","echarts/renderers","react-hook-form","tabler-icons-react","echarts/charts","@tabler/icons-react","@mantine/hooks","@mantine/notifications","@mantine/tiptap","@tiptap/extension-color","@tiptap/extension-highlight","@tiptap/extension-placeholder","@tiptap/extension-subscript","@tiptap/extension-superscript","@tiptap/extension-text-align","@tiptap/extension-text-style","@tiptap/extension-table","@tiptap/extension-table-cell","@tiptap/extension-table-header","@tiptap/extension-table-row","@tiptap/extension-underline","@tiptap/react","@tiptap/starter-kit","prosemirror-keymap","prosemirror-commands","prosemirror-schema-list","@monaco-editor/react","popmotion","d3-regression","@mantine/prism","@tanstack/react-table","react-virtual","@mantine/dates","rc-select","rc-tree-select","react-grid-layout","mobx-state-tree","performant-array-to-tree","@json2csv/whatwg","file-saver","jszip","dom-to-image-more","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):(w=typeof globalThis<"u"?globalThis:w||self,f(w.dashboard={},w.react,w["@mantine/core"],w["@mantine/modals"],w.ahooks,w.mobx,w["mobx-react-lite"],w.CryptoJS,w.dayjs,w._,w.numbro,w["d3-array"],w.mathjs,w["@faker-js/faker"],w.axios,w.eventemitter2,w["chroma-js"],w["echarts-for-react/lib/core"],w["echarts-gl"],w["echarts/components"],w["echarts/core"],w["echarts/renderers"],w["react-hook-form"],w["tabler-icons-react"],w["echarts/charts"],w["@tabler/icons-react"],w["@mantine/hooks"],w["@mantine/notifications"],w["@mantine/tiptap"],w["@tiptap/extension-color"],w["@tiptap/extension-highlight"],w["@tiptap/extension-placeholder"],w["@tiptap/extension-subscript"],w["@tiptap/extension-superscript"],w["@tiptap/extension-text-align"],w["@tiptap/extension-text-style"],w["@tiptap/extension-table"],w["@tiptap/extension-table-cell"],w["@tiptap/extension-table-header"],w["@tiptap/extension-table-row"],w["@tiptap/extension-underline"],w["@tiptap/react"],w["@tiptap/starter-kit"],w["prosemirror-keymap"],w["prosemirror-commands"],w["prosemirror-schema-list"],w["@monaco-editor/react"],w.popmotion,w["d3-regression"],w["@mantine/prism"],w["@tanstack/react-table"],w["react-virtual"],w["@mantine/dates"],w["rc-select"],w["rc-tree-select"],w["react-grid-layout"],w["mobx-state-tree"],w["performant-array-to-tree"],w["@json2csv/whatwg"],w["file-saver"],w.jszip,w["dom-to-image-more"],w.uuid,w["dayjs/plugin/advancedFormat"],w["dayjs/plugin/arraySupport"],w["dayjs/plugin/buddhistEra"],w["dayjs/plugin/calendar"],w["dayjs/plugin/customParseFormat"],w["dayjs/plugin/dayOfYear"],w["dayjs/plugin/duration"],w["dayjs/plugin/isBetween"],w["dayjs/plugin/isLeapYear"],w["dayjs/plugin/isMoment"],w["dayjs/plugin/isoWeek"],w["dayjs/plugin/isoWeeksInYear"],w["dayjs/plugin/isSameOrAfter"],w["dayjs/plugin/isSameOrBefore"],w["dayjs/plugin/isToday"],w["dayjs/plugin/isTomorrow"],w["dayjs/plugin/isYesterday"],w["dayjs/plugin/localeData"],w["dayjs/plugin/localizedFormat"],w["dayjs/plugin/minMax"],w["dayjs/plugin/objectSupport"],w["dayjs/plugin/pluralGetSet"],w["dayjs/plugin/preParsePostFormat"],w["dayjs/plugin/quarterOfYear"],w["dayjs/plugin/relativeTime"],w["dayjs/plugin/timezone"],w["dayjs/plugin/toArray"],w["dayjs/plugin/toObject"],w["dayjs/plugin/updateLocale"],w["dayjs/plugin/utc"],w["dayjs/plugin/weekday"],w["dayjs/plugin/weekOfYear"],w["dayjs/plugin/weekYear"],w["react-router-dom"],w.reactflow))})(this,function(w,f,a,Me,$,W,S,Kr,V,y,F,Nt,dc,pc,tt,Ur,nt,ve,$I,P,hc,we,b,_,te,k,pe,ht,q,Xr,Jr,Zr,Hr,ei,ti,ni,si,ri,ii,ai,oi,li,ci,VI,ge,rs,me,xt,xc,ft,Ge,fc,gc,ui,di,ln,g,mc,yc,is,bc,pi,as,jc,vc,wc,Cc,Sc,_c,kc,Tc,Ic,Dc,Mc,Ac,zc,Ec,Pc,Lc,Bc,Oc,$c,Vc,Nc,qc,Fc,Gc,Wc,Rc,Qc,Yc,Kc,Uc,Xc,Jc,Zc,Hc,be){"use strict";var BI=Object.defineProperty;var OI=(w,f,a)=>f in w?BI(w,f,{enumerable:!0,configurable:!0,writable:!0,value:a}):w[f]=a;var z=(w,f,a)=>(OI(w,typeof f!="symbol"?f+"":f,a),a);function qt(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:()=>t[n]})}}return e.default=t,Object.freeze(e)}const eu=qt(Kr),tu=qt(Nt),cn=qt(dc),K=qt(hc),ct=qt(xc);var os={exports:{}},Ft={};/**
1
+ (function(w,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("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","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):(w=typeof globalThis<"u"?globalThis:w||self,f(w.dashboard={},w.react,w["@mantine/core"],w["@mantine/modals"],w.ahooks,w.mobx,w["mobx-react-lite"],w.CryptoJS,w.dayjs,w._,w.numbro,w["d3-array"],w.mathjs,w["@faker-js/faker"],w.axios,w.eventemitter2,w["chroma-js"],w["echarts-for-react/lib/core"],w["echarts-gl"],w["echarts/components"],w["echarts/core"],w["echarts/renderers"],w["react-hook-form"],w["tabler-icons-react"],w["echarts/charts"],w["@tabler/icons-react"],w["@mantine/hooks"],w["@mantine/notifications"],w.popmotion,w["@monaco-editor/react"],w["d3-regression"],w["@mantine/tiptap"],w["@tiptap/extension-color"],w["@tiptap/extension-highlight"],w["@tiptap/extension-placeholder"],w["@tiptap/extension-subscript"],w["@tiptap/extension-superscript"],w["@tiptap/extension-text-align"],w["@tiptap/extension-text-style"],w["@tiptap/extension-table"],w["@tiptap/extension-table-cell"],w["@tiptap/extension-table-header"],w["@tiptap/extension-table-row"],w["@tiptap/extension-underline"],w["@tiptap/react"],w["@tiptap/starter-kit"],w["prosemirror-keymap"],w["prosemirror-commands"],w["prosemirror-schema-list"],w["@mantine/prism"],w["@tanstack/react-table"],w["react-virtual"],w["@mantine/dates"],w["rc-select"],w["rc-tree-select"],w["react-grid-layout"],w["mobx-state-tree"],w["performant-array-to-tree"],w["@json2csv/whatwg"],w["file-saver"],w.jszip,w["dom-to-image-more"],w.uuid,w["dayjs/plugin/advancedFormat"],w["dayjs/plugin/arraySupport"],w["dayjs/plugin/buddhistEra"],w["dayjs/plugin/calendar"],w["dayjs/plugin/customParseFormat"],w["dayjs/plugin/dayOfYear"],w["dayjs/plugin/duration"],w["dayjs/plugin/isBetween"],w["dayjs/plugin/isLeapYear"],w["dayjs/plugin/isMoment"],w["dayjs/plugin/isoWeek"],w["dayjs/plugin/isoWeeksInYear"],w["dayjs/plugin/isSameOrAfter"],w["dayjs/plugin/isSameOrBefore"],w["dayjs/plugin/isToday"],w["dayjs/plugin/isTomorrow"],w["dayjs/plugin/isYesterday"],w["dayjs/plugin/localeData"],w["dayjs/plugin/localizedFormat"],w["dayjs/plugin/minMax"],w["dayjs/plugin/objectSupport"],w["dayjs/plugin/pluralGetSet"],w["dayjs/plugin/preParsePostFormat"],w["dayjs/plugin/quarterOfYear"],w["dayjs/plugin/relativeTime"],w["dayjs/plugin/timezone"],w["dayjs/plugin/toArray"],w["dayjs/plugin/toObject"],w["dayjs/plugin/updateLocale"],w["dayjs/plugin/utc"],w["dayjs/plugin/weekday"],w["dayjs/plugin/weekOfYear"],w["dayjs/plugin/weekYear"],w["react-router-dom"],w.reactflow))})(this,function(w,f,a,Me,$,W,S,Kr,V,y,F,Nt,uc,dc,tt,Xr,nt,ve,PI,P,pc,we,b,_,te,k,pe,xt,ft,ge,hc,q,Jr,Zr,Hr,ei,ti,ni,si,ri,ii,ai,oi,li,ci,ui,LI,me,ss,ct,Ge,xc,fc,di,pi,ln,g,gc,mc,rs,yc,hi,is,bc,jc,vc,wc,Cc,Sc,_c,kc,Tc,Ic,Dc,Mc,Ac,zc,Ec,Pc,Lc,Bc,Oc,$c,Vc,Nc,qc,Fc,Gc,Wc,Rc,Qc,Uc,Yc,Kc,Xc,Jc,Zc,be){"use strict";var zI=Object.defineProperty;var EI=(w,f,a)=>f in w?zI(w,f,{enumerable:!0,configurable:!0,writable:!0,value:a}):w[f]=a;var z=(w,f,a)=>(EI(w,typeof f!="symbol"?f+"":f,a),a);function qt(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:()=>t[n]})}}return e.default=t,Object.freeze(e)}const Hc=qt(Kr),eu=qt(Nt),cn=qt(uc),Y=qt(pc),ut=qt(hc);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 hi;function nu(){if(hi)return Ft;hi=1;var t=f,e=Symbol.for("react.element"),n=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,i=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function l(c,u,d){var h,p={},x=null,m=null;d!==void 0&&(x=""+d),u.key!==void 0&&(x=""+u.key),u.ref!==void 0&&(m=u.ref);for(h in u)r.call(u,h)&&!o.hasOwnProperty(h)&&(p[h]=u[h]);if(c&&c.defaultProps)for(h in u=c.defaultProps,u)p[h]===void 0&&(p[h]=u[h]);return{$$typeof:e,type:c,key:x,ref:m,props:p,_owner:i.current}}return Ft.Fragment=n,Ft.jsx=l,Ft.jsxs=l,Ft}var Gt={};/**
9
+ */var xi;function tu(){if(xi)return Ft;xi=1;var t=f,e=Symbol.for("react.element"),n=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,i=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function l(c,u,d){var p,h={},x=null,m=null;d!==void 0&&(x=""+d),u.key!==void 0&&(x=""+u.key),u.ref!==void 0&&(m=u.ref);for(p in u)r.call(u,p)&&!o.hasOwnProperty(p)&&(h[p]=u[p]);if(c&&c.defaultProps)for(p in u=c.defaultProps,u)h[p]===void 0&&(h[p]=u[p]);return{$$typeof:e,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 xi;function su(){return xi||(xi=1,process.env.NODE_ENV!=="production"&&function(){var t=f,e=Symbol.for("react.element"),n=Symbol.for("react.portal"),r=Symbol.for("react.fragment"),i=Symbol.for("react.strict_mode"),o=Symbol.for("react.profiler"),l=Symbol.for("react.provider"),c=Symbol.for("react.context"),u=Symbol.for("react.forward_ref"),d=Symbol.for("react.suspense"),h=Symbol.for("react.suspense_list"),p=Symbol.for("react.memo"),x=Symbol.for("react.lazy"),m=Symbol.for("react.offscreen"),j=Symbol.iterator,C="@@iterator";function T(v){if(v===null||typeof v!="object")return null;var I=j&&v[j]||v[C];return typeof I=="function"?I:null}var A=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function L(v){{for(var I=arguments.length,M=new Array(I>1?I-1:0),N=1;N<I;N++)M[N-1]=arguments[N];Y("error",v,M)}}function Y(v,I,M){{var N=A.ReactDebugCurrentFrame,Z=N.getStackAddendum();Z!==""&&(I+="%s",M=M.concat([Z]));var ee=M.map(function(R){return String(R)});ee.unshift("Warning: "+I),Function.prototype.apply.call(console[v],console,ee)}}var se=!1,Q=!1,ie=!1,ue=!1,fe=!1,kt;kt=Symbol.for("react.module.reference");function Ke(v){return!!(typeof v=="string"||typeof v=="function"||v===r||v===o||fe||v===i||v===d||v===h||ue||v===m||se||Q||ie||typeof v=="object"&&v!==null&&(v.$$typeof===x||v.$$typeof===p||v.$$typeof===l||v.$$typeof===c||v.$$typeof===u||v.$$typeof===kt||v.getModuleId!==void 0))}function Vr(v,I,M){var N=v.displayName;if(N)return N;var Z=I.displayName||I.name||"";return Z!==""?M+"("+Z+")":M}function rn(v){return v.displayName||"Context"}function ot(v){if(v==null)return null;if(typeof v.tag=="number"&&L("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 d:return"Suspense";case h:return"SuspenseList"}if(typeof v=="object")switch(v.$$typeof){case c:var I=v;return rn(I)+".Consumer";case l:var M=v;return rn(M._context)+".Provider";case u:return Vr(v,v.render,"ForwardRef");case p: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,Gl,Wl,Rl,Ql,Yl,Kl,Ul;function Xl(){}Xl.__reactDisabledLog=!0;function dI(){{if(an===0){Gl=console.log,Wl=console.info,Rl=console.warn,Ql=console.error,Yl=console.group,Kl=console.groupCollapsed,Ul=console.groupEnd;var v={configurable:!0,enumerable:!0,value:Xl,writable:!0};Object.defineProperties(console,{info:v,log:v,warn:v,error:v,group:v,groupCollapsed:v,groupEnd:v})}an++}}function pI(){{if(an--,an===0){var v={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:Tt({},v,{value:Gl}),info:Tt({},v,{value:Wl}),warn:Tt({},v,{value:Rl}),error:Tt({},v,{value:Ql}),group:Tt({},v,{value:Yl}),groupCollapsed:Tt({},v,{value:Kl}),groupEnd:Tt({},v,{value:Ul})})}an<0&&L("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var Nr=A.ReactCurrentDispatcher,qr;function Hn(v,I,M){{if(qr===void 0)try{throw Error()}catch(Z){var N=Z.stack.trim().match(/\n( *(at )?)/);qr=N&&N[1]||""}return`
18
- `+qr+v}}var Fr=!1,es;{var hI=typeof WeakMap=="function"?WeakMap:Map;es=new hI}function Jl(v,I){if(!v||Fr)return"";{var M=es.get(v);if(M!==void 0)return M}var N;Fr=!0;var Z=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var ee;ee=Nr.current,Nr.current=null,dI();try{if(I){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(`
17
+ */var fi;function nu(){return fi||(fi=1,process.env.NODE_ENV!=="production"&&function(){var t=f,e=Symbol.for("react.element"),n=Symbol.for("react.portal"),r=Symbol.for("react.fragment"),i=Symbol.for("react.strict_mode"),o=Symbol.for("react.profiler"),l=Symbol.for("react.provider"),c=Symbol.for("react.context"),u=Symbol.for("react.forward_ref"),d=Symbol.for("react.suspense"),p=Symbol.for("react.suspense_list"),h=Symbol.for("react.memo"),x=Symbol.for("react.lazy"),m=Symbol.for("react.offscreen"),j=Symbol.iterator,C="@@iterator";function T(v){if(v===null||typeof v!="object")return null;var I=j&&v[j]||v[C];return typeof I=="function"?I:null}var A=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function L(v){{for(var I=arguments.length,M=new Array(I>1?I-1:0),N=1;N<I;N++)M[N-1]=arguments[N];U("error",v,M)}}function U(v,I,M){{var N=A.ReactDebugCurrentFrame,Z=N.getStackAddendum();Z!==""&&(I+="%s",M=M.concat([Z]));var ee=M.map(function(R){return String(R)});ee.unshift("Warning: "+I),Function.prototype.apply.call(console[v],console,ee)}}var se=!1,Q=!1,ie=!1,ue=!1,fe=!1,kt;kt=Symbol.for("react.module.reference");function Ye(v){return!!(typeof v=="string"||typeof v=="function"||v===r||v===o||fe||v===i||v===d||v===p||ue||v===m||se||Q||ie||typeof v=="object"&&v!==null&&(v.$$typeof===x||v.$$typeof===h||v.$$typeof===l||v.$$typeof===c||v.$$typeof===u||v.$$typeof===kt||v.getModuleId!==void 0))}function Nr(v,I,M){var N=v.displayName;if(N)return N;var Z=I.displayName||I.name||"";return Z!==""?M+"("+Z+")":M}function rn(v){return v.displayName||"Context"}function ot(v){if(v==null)return null;if(typeof v.tag=="number"&&L("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 d:return"Suspense";case p:return"SuspenseList"}if(typeof v=="object")switch(v.$$typeof){case c:var I=v;return rn(I)+".Consumer";case l:var M=v;return rn(M._context)+".Provider";case u:return Nr(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,Fl,Gl,Wl,Rl,Ql,Ul,Yl;function Kl(){}Kl.__reactDisabledLog=!0;function oI(){{if(an===0){Fl=console.log,Gl=console.info,Wl=console.warn,Rl=console.error,Ql=console.group,Ul=console.groupCollapsed,Yl=console.groupEnd;var v={configurable:!0,enumerable:!0,value:Kl,writable:!0};Object.defineProperties(console,{info:v,log:v,warn:v,error:v,group:v,groupCollapsed:v,groupEnd:v})}an++}}function lI(){{if(an--,an===0){var v={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:Tt({},v,{value:Fl}),info:Tt({},v,{value:Gl}),warn:Tt({},v,{value:Wl}),error:Tt({},v,{value:Rl}),group:Tt({},v,{value:Ql}),groupCollapsed:Tt({},v,{value:Ul}),groupEnd:Tt({},v,{value:Yl})})}an<0&&L("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var qr=A.ReactCurrentDispatcher,Fr;function Zn(v,I,M){{if(Fr===void 0)try{throw Error()}catch(Z){var N=Z.stack.trim().match(/\n( *(at )?)/);Fr=N&&N[1]||""}return`
18
+ `+Fr+v}}var Gr=!1,Hn;{var cI=typeof WeakMap=="function"?WeakMap:Map;Hn=new cI}function Xl(v,I){if(!v||Gr)return"";{var M=Hn.get(v);if(M!==void 0)return M}var N;Gr=!0;var Z=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var ee;ee=qr.current,qr.current=null,oI();try{if(I){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
19
  `),_e=N.stack.split(`
20
20
  `),ae=G.length-1,de=_e.length-1;ae>=1&&de>=0&&G[ae]!==_e[de];)de--;for(;ae>=1&&de>=0;ae--,de--)if(G[ae]!==_e[de]){if(ae!==1||de!==1)do if(ae--,de--,de<0||G[ae]!==_e[de]){var Fe=`
21
- `+G[ae].replace(" at new "," at ");return v.displayName&&Fe.includes("<anonymous>")&&(Fe=Fe.replace("<anonymous>",v.displayName)),typeof v=="function"&&es.set(v,Fe),Fe}while(ae>=1&&de>=0);break}}}finally{Fr=!1,Nr.current=ee,pI(),Error.prepareStackTrace=Z}var Vt=v?v.displayName||v.name:"",uc=Vt?Hn(Vt):"";return typeof v=="function"&&es.set(v,uc),uc}function xI(v,I,M){return Jl(v,!1)}function fI(v){var I=v.prototype;return!!(I&&I.isReactComponent)}function ts(v,I,M){if(v==null)return"";if(typeof v=="function")return Jl(v,fI(v));if(typeof v=="string")return Hn(v);switch(v){case d:return Hn("Suspense");case h:return Hn("SuspenseList")}if(typeof v=="object")switch(v.$$typeof){case u:return xI(v.render);case p:return ts(v.type,I,M);case x:{var N=v,Z=N._payload,ee=N._init;try{return ts(ee(Z),I,M)}catch{}}}return""}var ns=Object.prototype.hasOwnProperty,Zl={},Hl=A.ReactDebugCurrentFrame;function ss(v){if(v){var I=v._owner,M=ts(v.type,v._source,I?I.type:null);Hl.setExtraStackFrame(M)}else Hl.setExtraStackFrame(null)}function gI(v,I,M,N,Z){{var ee=Function.call.bind(ns);for(var R in v)if(ee(v,R)){var G=void 0;try{if(typeof v[R]!="function"){var _e=Error((N||"React class")+": "+M+" 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 _e.name="Invariant Violation",_e}G=v[R](I,R,N,M,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(ae){G=ae}G&&!(G instanceof Error)&&(ss(Z),L("%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",M,R,typeof G),ss(null)),G instanceof Error&&!(G.message in Zl)&&(Zl[G.message]=!0,ss(Z),L("Failed %s type: %s",M,G.message),ss(null))}}}var mI=Array.isArray;function Gr(v){return mI(v)}function yI(v){{var I=typeof Symbol=="function"&&Symbol.toStringTag,M=I&&v[Symbol.toStringTag]||v.constructor.name||"Object";return M}}function bI(v){try{return ec(v),!1}catch{return!0}}function ec(v){return""+v}function tc(v){if(bI(v))return L("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",yI(v)),ec(v)}var on=A.ReactCurrentOwner,jI={key:!0,ref:!0,__self:!0,__source:!0},nc,sc,Wr;Wr={};function vI(v){if(ns.call(v,"ref")){var I=Object.getOwnPropertyDescriptor(v,"ref").get;if(I&&I.isReactWarning)return!1}return v.ref!==void 0}function wI(v){if(ns.call(v,"key")){var I=Object.getOwnPropertyDescriptor(v,"key").get;if(I&&I.isReactWarning)return!1}return v.key!==void 0}function CI(v,I){if(typeof v.ref=="string"&&on.current&&I&&on.current.stateNode!==I){var M=ot(on.current.type);Wr[M]||(L('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),Wr[M]=!0)}}function SI(v,I){{var M=function(){nc||(nc=!0,L("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",I))};M.isReactWarning=!0,Object.defineProperty(v,"key",{get:M,configurable:!0})}}function _I(v,I){{var M=function(){sc||(sc=!0,L("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",I))};M.isReactWarning=!0,Object.defineProperty(v,"ref",{get:M,configurable:!0})}}var kI=function(v,I,M,N,Z,ee,R){var G={$$typeof:e,type:v,key:I,ref:M,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 TI(v,I,M,N,Z){{var ee,R={},G=null,_e=null;M!==void 0&&(tc(M),G=""+M),wI(I)&&(tc(I.key),G=""+I.key),vI(I)&&(_e=I.ref,CI(I,Z));for(ee in I)ns.call(I,ee)&&!jI.hasOwnProperty(ee)&&(R[ee]=I[ee]);if(v&&v.defaultProps){var ae=v.defaultProps;for(ee in ae)R[ee]===void 0&&(R[ee]=ae[ee])}if(G||_e){var de=typeof v=="function"?v.displayName||v.name||"Unknown":v;G&&SI(R,de),_e&&_I(R,de)}return kI(v,G,_e,Z,N,on.current,R)}}var Rr=A.ReactCurrentOwner,rc=A.ReactDebugCurrentFrame;function $t(v){if(v){var I=v._owner,M=ts(v.type,v._source,I?I.type:null);rc.setExtraStackFrame(M)}else rc.setExtraStackFrame(null)}var Qr;Qr=!1;function Yr(v){return typeof v=="object"&&v!==null&&v.$$typeof===e}function ic(){{if(Rr.current){var v=ot(Rr.current.type);if(v)return`
21
+ `+G[ae].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(ae>=1&&de>=0);break}}}finally{Gr=!1,qr.current=ee,lI(),Error.prepareStackTrace=Z}var Vt=v?v.displayName||v.name:"",cc=Vt?Zn(Vt):"";return typeof v=="function"&&Hn.set(v,cc),cc}function uI(v,I,M){return Xl(v,!1)}function dI(v){var I=v.prototype;return!!(I&&I.isReactComponent)}function es(v,I,M){if(v==null)return"";if(typeof v=="function")return Xl(v,dI(v));if(typeof v=="string")return Zn(v);switch(v){case d:return Zn("Suspense");case p:return Zn("SuspenseList")}if(typeof v=="object")switch(v.$$typeof){case u:return uI(v.render);case h:return es(v.type,I,M);case x:{var N=v,Z=N._payload,ee=N._init;try{return es(ee(Z),I,M)}catch{}}}return""}var ts=Object.prototype.hasOwnProperty,Jl={},Zl=A.ReactDebugCurrentFrame;function ns(v){if(v){var I=v._owner,M=es(v.type,v._source,I?I.type:null);Zl.setExtraStackFrame(M)}else Zl.setExtraStackFrame(null)}function pI(v,I,M,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 _e=Error((N||"React class")+": "+M+" 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 _e.name="Invariant Violation",_e}G=v[R](I,R,N,M,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(ae){G=ae}G&&!(G instanceof Error)&&(ns(Z),L("%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",M,R,typeof G),ns(null)),G instanceof Error&&!(G.message in Jl)&&(Jl[G.message]=!0,ns(Z),L("Failed %s type: %s",M,G.message),ns(null))}}}var hI=Array.isArray;function Wr(v){return hI(v)}function xI(v){{var I=typeof Symbol=="function"&&Symbol.toStringTag,M=I&&v[Symbol.toStringTag]||v.constructor.name||"Object";return M}}function fI(v){try{return Hl(v),!1}catch{return!0}}function Hl(v){return""+v}function ec(v){if(fI(v))return L("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",xI(v)),Hl(v)}var on=A.ReactCurrentOwner,gI={key:!0,ref:!0,__self:!0,__source:!0},tc,nc,Rr;Rr={};function mI(v){if(ts.call(v,"ref")){var I=Object.getOwnPropertyDescriptor(v,"ref").get;if(I&&I.isReactWarning)return!1}return v.ref!==void 0}function yI(v){if(ts.call(v,"key")){var I=Object.getOwnPropertyDescriptor(v,"key").get;if(I&&I.isReactWarning)return!1}return v.key!==void 0}function bI(v,I){if(typeof v.ref=="string"&&on.current&&I&&on.current.stateNode!==I){var M=ot(on.current.type);Rr[M]||(L('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),Rr[M]=!0)}}function jI(v,I){{var M=function(){tc||(tc=!0,L("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",I))};M.isReactWarning=!0,Object.defineProperty(v,"key",{get:M,configurable:!0})}}function vI(v,I){{var M=function(){nc||(nc=!0,L("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",I))};M.isReactWarning=!0,Object.defineProperty(v,"ref",{get:M,configurable:!0})}}var wI=function(v,I,M,N,Z,ee,R){var G={$$typeof:e,type:v,key:I,ref:M,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 CI(v,I,M,N,Z){{var ee,R={},G=null,_e=null;M!==void 0&&(ec(M),G=""+M),yI(I)&&(ec(I.key),G=""+I.key),mI(I)&&(_e=I.ref,bI(I,Z));for(ee in I)ts.call(I,ee)&&!gI.hasOwnProperty(ee)&&(R[ee]=I[ee]);if(v&&v.defaultProps){var ae=v.defaultProps;for(ee in ae)R[ee]===void 0&&(R[ee]=ae[ee])}if(G||_e){var de=typeof v=="function"?v.displayName||v.name||"Unknown":v;G&&jI(R,de),_e&&vI(R,de)}return wI(v,G,_e,Z,N,on.current,R)}}var Qr=A.ReactCurrentOwner,sc=A.ReactDebugCurrentFrame;function $t(v){if(v){var I=v._owner,M=es(v.type,v._source,I?I.type:null);sc.setExtraStackFrame(M)}else sc.setExtraStackFrame(null)}var Ur;Ur=!1;function Yr(v){return typeof v=="object"&&v!==null&&v.$$typeof===e}function rc(){{if(Qr.current){var v=ot(Qr.current.type);if(v)return`
22
22
 
23
- Check the render method of \``+v+"`."}return""}}function II(v){{if(v!==void 0){var I=v.fileName.replace(/^.*[\\\/]/,""),M=v.lineNumber;return`
23
+ Check the render method of \``+v+"`."}return""}}function SI(v){{if(v!==void 0){var I=v.fileName.replace(/^.*[\\\/]/,""),M=v.lineNumber;return`
24
24
 
25
- Check your code at `+I+":"+M+"."}return""}}var ac={};function DI(v){{var I=ic();if(!I){var M=typeof v=="string"?v:v.displayName||v.name;M&&(I=`
25
+ Check your code at `+I+":"+M+"."}return""}}var ic={};function _I(v){{var I=rc();if(!I){var M=typeof v=="string"?v:v.displayName||v.name;M&&(I=`
26
26
 
27
- Check the top-level render call using <`+M+">.")}return I}}function oc(v,I){{if(!v._store||v._store.validated||v.key!=null)return;v._store.validated=!0;var M=DI(I);if(ac[M])return;ac[M]=!0;var N="";v&&v._owner&&v._owner!==Rr.current&&(N=" It was passed a child from "+ot(v._owner.type)+"."),$t(v),L('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',M,N),$t(null)}}function lc(v,I){{if(typeof v!="object")return;if(Gr(v))for(var M=0;M<v.length;M++){var N=v[M];Yr(N)&&oc(N,I)}else if(Yr(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;)Yr(R.value)&&oc(R.value,I)}}}function MI(v){{var I=v.type;if(I==null||typeof I=="string")return;var M;if(typeof I=="function")M=I.propTypes;else if(typeof I=="object"&&(I.$$typeof===u||I.$$typeof===p))M=I.propTypes;else return;if(M){var N=ot(I);gI(M,v.props,"prop",N,v)}else if(I.PropTypes!==void 0&&!Qr){Qr=!0;var Z=ot(I);L("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",Z||"Unknown")}typeof I.getDefaultProps=="function"&&!I.getDefaultProps.isReactClassApproved&&L("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function AI(v){{for(var I=Object.keys(v.props),M=0;M<I.length;M++){var N=I[M];if(N!=="children"&&N!=="key"){$t(v),L("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),L("Invalid attribute `ref` supplied to `React.Fragment`."),$t(null))}}function cc(v,I,M,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 _e=II(Z);_e?G+=_e:G+=ic();var ae;v===null?ae="null":Gr(v)?ae="array":v!==void 0&&v.$$typeof===e?(ae="<"+(ot(v.type)||"Unknown")+" />",G=" Did you accidentally export a JSX literal instead of a component?"):ae=typeof v,L("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",ae,G)}var de=TI(v,I,M,Z,ee);if(de==null)return de;if(R){var Fe=I.children;if(Fe!==void 0)if(N)if(Gr(Fe)){for(var Vt=0;Vt<Fe.length;Vt++)lc(Fe[Vt],v);Object.freeze&&Object.freeze(Fe)}else L("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 lc(Fe,v)}return v===r?AI(de):MI(de),de}}function zI(v,I,M){return cc(v,I,M,!0)}function EI(v,I,M){return cc(v,I,M,!1)}var PI=EI,LI=zI;Gt.Fragment=r,Gt.jsx=PI,Gt.jsxs=LI}()),Gt}process.env.NODE_ENV==="production"?os.exports=nu():os.exports=su();var s=os.exports;const gt={CryptoJS:Kr,d3Array:tu,dayjs:V,lodash:y,numbro:F,mathjs:cn,faker:pc.faker},ru=[{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"}],iu=t=>`
27
+ Check the top-level render call using <`+M+">.")}return I}}function ac(v,I){{if(!v._store||v._store.validated||v.key!=null)return;v._store.validated=!0;var M=_I(I);if(ic[M])return;ic[M]=!0;var N="";v&&v._owner&&v._owner!==Qr.current&&(N=" It was passed a child from "+ot(v._owner.type)+"."),$t(v),L('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',M,N),$t(null)}}function oc(v,I){{if(typeof v!="object")return;if(Wr(v))for(var M=0;M<v.length;M++){var N=v[M];Yr(N)&&ac(N,I)}else if(Yr(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;)Yr(R.value)&&ac(R.value,I)}}}function kI(v){{var I=v.type;if(I==null||typeof I=="string")return;var M;if(typeof I=="function")M=I.propTypes;else if(typeof I=="object"&&(I.$$typeof===u||I.$$typeof===h))M=I.propTypes;else return;if(M){var N=ot(I);pI(M,v.props,"prop",N,v)}else if(I.PropTypes!==void 0&&!Ur){Ur=!0;var Z=ot(I);L("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",Z||"Unknown")}typeof I.getDefaultProps=="function"&&!I.getDefaultProps.isReactClassApproved&&L("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function TI(v){{for(var I=Object.keys(v.props),M=0;M<I.length;M++){var N=I[M];if(N!=="children"&&N!=="key"){$t(v),L("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),L("Invalid attribute `ref` supplied to `React.Fragment`."),$t(null))}}function lc(v,I,M,N,Z,ee){{var R=Ye(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 _e=SI(Z);_e?G+=_e:G+=rc();var ae;v===null?ae="null":Wr(v)?ae="array":v!==void 0&&v.$$typeof===e?(ae="<"+(ot(v.type)||"Unknown")+" />",G=" Did you accidentally export a JSX literal instead of a component?"):ae=typeof v,L("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",ae,G)}var de=CI(v,I,M,Z,ee);if(de==null)return de;if(R){var Fe=I.children;if(Fe!==void 0)if(N)if(Wr(Fe)){for(var Vt=0;Vt<Fe.length;Vt++)oc(Fe[Vt],v);Object.freeze&&Object.freeze(Fe)}else L("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 oc(Fe,v)}return v===r?TI(de):kI(de),de}}function II(v,I,M){return lc(v,I,M,!0)}function DI(v,I,M){return lc(v,I,M,!1)}var MI=DI,AI=II;Gt.Fragment=r,Gt.jsx=MI,Gt.jsxs=AI}()),Gt}process.env.NODE_ENV==="production"?as.exports=tu():as.exports=nu();var s=as.exports;const gt={CryptoJS:Kr,d3Array:eu,dayjs:V,lodash:y,numbro:F,mathjs:cn,faker:dc.faker},su=[{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"}],ru=t=>`
28
28
  <tr>
29
29
  <td><code>${t.name}</code></td>
30
30
  <td>
@@ -36,7 +36,7 @@ Check the top-level render call using <`+M+">.")}return I}}function oc(v,I){{if(
36
36
  >
37
37
  </td>
38
38
  </tr>
39
- `,au=`
39
+ `,iu=`
40
40
  <p>
41
41
  Parameter <code>utils</code> is <code>functionUtils</code>, which contains:
42
42
  </p>
@@ -48,30 +48,30 @@ Check the top-level render call using <`+M+">.")}return I}}function oc(v,I){{if(
48
48
  </tr>
49
49
  </thead>
50
50
  <tbody>
51
- ${ru.map(iu).join("")}
51
+ ${su.map(ru).join("")}
52
52
  </tbody>
53
53
  </table>
54
- `;function ls(t,e){const n=Object.keys(e),r=Object.values(e);try{return new Function(...n,`return \`${t}\`;`)(...r)}catch(i){throw n.length===0&&t.includes("$")?new Error("[formatSQL] insufficient payload"):i}}function cs(t,e){try{return ls(t,e)}catch(n){return console.error(n),n.message}}function ou({sql:t,pre_process:e}){if(!e.trim())return t;try{return new Function(`return ${e}`)()({sql:t},gt)}catch(n){return console.error(n),t}}function lu(t,e,n){if(!t.trim())return e;try{return new Function(`return ${t}`)()(e,gt,n)}catch(r){return console.error(r),e}}function cu(t){t=t||{};const e=Object.keys(t).sort(),n=[];for(let r=0;r<e.length;r++){const i=e[r];if(i!="authentication"&&t[i])n.push(e[r]+"="+(typeof t[i]=="object"?JSON.stringify(t[i]):t[i]));else{const o=Object.keys(t[i]).sort();for(let l=0;l<o.length;l++){const c=o[l];c!="sign"&&t[i][c]&&n.push(o[l]+"="+(typeof t[i][c]=="object"?JSON.stringify(t[i][c]):t[i][c]))}}}return n.sort().join("&")}function uu(t,e){let n=cu(t);return n+="&key="+e,eu.MD5(n).toString().toUpperCase()}class fi{constructor(){this.type="default_api_client",this.baseURL="http://localhost:31200",this.app_id="",this.app_secret=""}getAuthentication(e){if(!this.app_id||!this.app_secret)return;const n=new Date().getTime().toString();return{app_id:this.app_id,nonce_str:n,sign:uu({app_id:this.app_id,nonce_str:n,...e},this.app_secret)}}getRequest(e,n){return(r,i,o,l)=>{const c=this.buildHeader(o),u=this.buildAxiosConfig(e,r,i,o,c,n);return tt(u).then(d=>l?d:d.data).catch(d=>Promise.reject(d))}}get(e){return this.getRequest("GET",e)}post(e){return this.getRequest("POST",e)}put(e){return this.getRequest("PUT",e)}buildAxiosConfig(e,n,r,i,o,l){const c={baseURL:this.baseURL,method:e,url:n,params:e==="GET"?r:i.params,headers:o,signal:l};return["POST","PUT"].includes(e)&&(c.data=i.string?JSON.stringify(r):r,c.data.authentication=this.getAuthentication(c.data)),c}buildHeader(e){const n=window.localStorage.getItem("token");return{"X-Requested-With":"XMLHttpRequest","Content-Type":e.string?"application/x-www-form-urlencoded":"application/json",authorization:n?`bearer ${n}`:"",...e.headers}}}class du{constructor(e){this.implementation=e}getRequest(e,n){return this.implementation.getRequest(e,n)}get(e){return this.getRequest("GET",e)}post(e){return this.getRequest("POST",e)}put(e){return this.getRequest("PUT",e)}}class gi extends fi{constructor(){super(...arguments);z(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 mi{constructor(e){this.implementation=e}query(e){return this.implementation.query(e)}httpDataSourceQuery(e){return this.implementation.httpDataSourceQuery(e)}structure(e){return this.implementation.structure(e)}getRequest(e,n){return this.implementation.getRequest(e,n)}get(e){return this.getRequest("GET",e)}post(e){return this.getRequest("POST",e)}put(e){return this.getRequest("PUT",e)}}const It=new gi;function us(t){It.baseURL!==t.apiBaseURL&&(It.baseURL=t.apiBaseURL),t.app_id&&(It.app_id=t.app_id),t.app_secret&&(It.app_secret=t.app_secret),t.makeQueryENV&&(It.makeQueryENV=t.makeQueryENV)}const yi=new mi(It),Ue=yi;function bi(){return{filters:{},context:{}}}function ds(t){const e=bi();if(!t)return bi();const{filters:n=e.filters,context:r=e.context}=t;return{filters:n,context:r}}async function pu({query:t,name:e,payload:n,additionals:r},i){if(!t.sql)return[];const{type:o,key:l,sql:c,pre_process:u,post_process:d}=t,h=ls(c,n),p=ou({sql:h,pre_process:u});let x=await Ue.query(i)({type:o,key:l,query:p,...r},{params:{name:e}});return x=lu(d,x,ds(n)),x}async function hu({type:t,key:e,configString:n,name:r,additionals:i},o){try{return await Ue.httpDataSourceQuery(o)({type:t,key:e,query:n,...i},{params:{name:r}})}catch(l){if(tt.isCancel(l))throw l;return console.error(l),l}}async function ps(){try{return(await Ue.post()("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}},{})).data}catch(t){return console.error(t),[]}}async function ji(){try{return(await Ue.post()("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}},{})).data}catch(t){return console.error(t),[]}}class vi{constructor(e){z(this,"rootRef");this.rootRef=W.observable({current:e})}async deleteItem(e){W.runInAction(()=>{y.unset(this.rootRef.current,[e])})}getItem(e){const n=this.getValueFromRoot(e);return Promise.resolve(n)}getValueFromRoot(e){return e===null?W.toJS(this.rootRef.current):y.get(this.rootRef.current,[e])}setItem(e,n){if(e===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,[e],n)});return Promise.resolve(this.getItem(e))}watchItem(e,n,r){return W.reaction(()=>this.getValueFromRoot(e),(i,o)=>{n(i,o)},{requiresObservable:!0,fireImmediately:y.get(r,"fireImmediately",!1)})}}class xu{constructor(){z(this,"channels",new Map);z(this,"globalChannel",new Ur)}getChannel(e){const n=this.channels.get(e);if(n)return n;const r=new Ur;return this.channels.set(e,r),r}}class fu{constructor(e){z(this,"instances",new Map);this.pluginManager=e}get availableVizList(){return this.pluginManager.installedPlugins.flatMap(e=>e.manifest.viz)}resolveComponent(e){return this.pluginManager.factory.viz(e)}getOrCreateInstance(e){const n=this.instances.get(e.id);if(n)return n;const r={id:e.id,name:e.viz.type,type:e.viz.type,messageChannels:new xu,instanceData:new vi(e.viz.conf)};return this.instances.set(e.id,r),r}}function wi(t,e,n,r){return{vizManager:n,locale:"zh",msgChannels:t.messageChannels,instanceData:t.instanceData,pluginData:new vi({}),colorPalette:{getColor(){return()=>""}},data:e,variables:r}}const gu=t=>{const{panel:e,vizManager:n,data:r,variables:i}=t,o=n.resolveComponent(e.viz.type),l=n.getOrCreateInstance(e),c={...wi(l,r,n,i),viewport:{width:e.layout.w,height:e.layout.h}},u=o.viewRender;return s.jsx(u,{context:c,instance:l,...y.omit(t,["panel","vizManager","data"])})},mu=t=>{const{vizManager:e,panel:n,data:r,variables:i}=t,o=e.resolveComponent(n.viz.type),l=e.getOrCreateInstance(n),c={...wi(l,r,e,i)},u=o.configRender;return s.jsx(u,{context:c,instance:l,...y.omit(t,["panel","vizManager","data"])})},Ci=(t,e)=>{const n=nt.bezier(t),r=nt.bezier(e);return function(i){return i<50?n(i*2/100).hex():r((i-50)*2/100).hex()}},un=t=>{const e=nt.bezier(t);return function(n){return e(n/100).hex()}},yu={type:"interpolation",displayName:"Red / Green",getColor:Ci(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},bu={type:"interpolation",displayName:"Yellow / Blue",getColor:Ci(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},ju={type:"interpolation",displayName:"Red",getColor:un(["#fff7f1","darkred"]),name:"red",category:"sequential"},vu={type:"interpolation",displayName:"Green",getColor:un(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},wu={type:"interpolation",displayName:"Blue",getColor:un(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},Cu={type:"interpolation",displayName:"Orange",getColor:un(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class Su{constructor(e){z(this,"symbol");this.symbol=Symbol(e)}}function st(t){return new Su(t)}class hs{constructor(){z(this,"parent");z(this,"factoryRegistry",new Map);z(this,"instanceRegistry",new Map)}createScoped(){const e=new hs;return e.parent=this,e}getRequired(e){return this.get(e)}get(e){if(this.instanceRegistry.has(e.symbol))return this.instanceRegistry.get(e.symbol);const n=this.factoryRegistry.get(e.symbol);if(n){const r=n(this);return this.instanceRegistry.set(e.symbol,r),r}if(this.parent)return this.parent.get(e)}provideFactory(e,n){return this.factoryRegistry.has(e.symbol)?console.warn(`Token ${e.symbol.toString()} is already registered`):this.factoryRegistry.set(e.symbol,n),this}provideValue(e,n){return this.factoryRegistry.has(e.symbol)?console.warn(`Token ${e.symbol.toString()} is already registered`):this.factoryRegistry.set(e.symbol,()=>n),this}dispose(){this.instanceRegistry.forEach(e=>{const n=y.get(e,"dispose");y.isFunction(n)&&n.bind(e)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}const Si="10.49.0",_u=Object.freeze(Object.defineProperty({__proto__:null,version:Si},Symbol.toStringTag,{value:"Module"}));class ku{constructor(e){z(this,"staticColors",new Map);z(this,"interpolations",new Map);e.installedPlugins.forEach(n=>{n.manifest.color.forEach(r=>{this.register(r)})})}getStaticColors(){return Array.from(this.staticColors.values())}register(e){const n=this.encodeColor(e);e.type==="single"?(this.staticColors.has(n)&&console.warn(`the color '${e.name}' has been registered under '${e.category}', previous registered value will be overridden`),this.staticColors.set(n,e)):e.type==="interpolation"&&(this.interpolations.has(n)&&console.warn(`the interpolation '${e.name}' has been registered under '${e.category}', previous registered value will be overridden`,`the interpolation '${e.name}' has been registered under '${e.category}', previous registered value will be overridden`),this.interpolations.set(n,e))}decodeStaticColor(e){return this.staticColors.get(e)}encodeColor(e){return`\${${e.category}}.{${e.name}}`}decodeInterpolation(e){return this.interpolations.get(e)}getColorInterpolations(){return Array.from(this.interpolations.values())}}class Tu{constructor(){z(this,"plugins",new Map);z(this,"vizComponents",new Map);z(this,"factory",{viz:e=>{const n=this.vizComponents.get(e);if(n)return n;throw new Error(`Viz Component (${e}) not found`)}})}install(e){if(this.plugins.has(e.id))throw new Error(`Plugin (${e.id}) has been installed before`);this.plugins.set(e.id,e);for(const n of e.manifest.viz){if(this.vizComponents.has(n.name))throw new Error(`Viz Component (${n.name}) has been installed before`);this.vizComponents.set(n.name,n)}}get installedPlugins(){return Array.from(this.plugins.values())}}class Iu{constructor(){z(this,"migrations",[])}version(e,n){return this.migrations.push({version:e,handler:n}),this}run(e,n,r){var l;if(e.from===e.to)return n;if(e.from>e.to)throw new Error(`Can not downgrade from version '${e.from}' to (${e.to})`);const i=this.migrations.filter(c=>c.version>e.from&&c.version<=e.to),o=y.orderBy(i,"version","asc");if(((l=y.last(o))==null?void 0:l.version)!==e.to)throw new Error(`Migration to version ${e.to} not found`);return o.reduce((c,u)=>u.handler(c,r),n)}}class re extends Iu{constructor(){super(),this.configVersions()}version(e,n){return super.version(e,(r,i)=>({version:e,...n(r,i)}))}async migrate({configData:e,panelModel:n}){const r=await e.getItem(null),i=y.get(r,"version",0),o=this.run({from:i,to:this.VERSION},r,{panelModel:n});await e.setItem(null,o)}async needMigration({configData:e}){const n=await e.getItem(null);return y.get(n,"version",0)<this.VERSION}}const O=(t,e)=>{const[n,{setFalse:r}]=$.useBoolean(!0),[i,o]=f.useState();f.useEffect(()=>(t.getItem(e).then(c=>{o(c),r()}),t.watchItem(e,c=>{o(c)})));const l=f.useCallback(async c=>{await t.setItem(e,c),o(c)},[t,e]);return{loading:n,value:i,set:l}},ke={top:16,right:16,bottom:16,left:16},We=t=>Math.max(0,t-ke.left-ke.right),Re=t=>Math.max(0,t-ke.top-ke.bottom),Wt=(t,e)=>({width:We(t),height:Re(e)}),Te=({width:t,height:e,children:n})=>s.jsx(a.Box,{pt:ke.top,pr:ke.right,pb:ke.bottom,pl:ke.left,sx:{width:t,height:e,overflow:"hidden",position:"relative"},children:n});function D(t){const[e,n]=t.split(".");return{queryID:e,columnKey:n}}function Du(t){return t.includes(".")?D(t):{queryID:"",columnKey:t}}function rt(t,e){var i;const{queryID:n,columnKey:r}=D(e);return n?r?((i=t[n])==null?void 0:i.map(o=>o[r]))??[]:t[n]:[]}function Rt(t,e){const{queryID:n}=D(e);return n?t[n]:[]}function Mu(t){return Object.values(t)[0]}function dn(t,e){const{queryID:n,columnKey:r}=D(e);return t[r]}const xs={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"}};K.use([P.GridComponent,P.VisualMapComponent,P.LegendComponent,P.TooltipComponent,we.CanvasRenderer]);function Au({context:t}){const{value:e}=O(t.instanceData,"config"),n=t.data,{width:r,height:i}=t.viewport,{x_axis_data_key:o,y_axis_data_key:l,z_axis_data_key:c,xAxis3D:u,yAxis3D:d,zAxis3D:h}=y.defaults({},e,xs),p=f.useMemo(()=>Rt(n,o),[n,o]),{x,y:m,z:j}=f.useMemo(()=>({x:D(o),y:D(l),z:D(c)}),[o,l,c]),{min:C,max:T}=f.useMemo(()=>{const L=y.minBy(p,se=>se[j.columnKey]),Y=y.maxBy(p,se=>se[j.columnKey]);return{min:y.get(L,j.columnKey),max:y.get(Y,j.columnKey)}},[p,j]),A={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:C,max:T,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:u,yAxis3D:d,zAxis3D:h,grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}},series:[{type:"bar3D",wireframe:{},data:p.map(L=>[L[x.columnKey],L[m.columnKey],L[j.columnKey]])}]};return e?s.jsx(Te,{width:r,height:i,children:s.jsx(ve,{echarts:K,option:A,style:Wt(r,i),notMerge:!0,theme:"merico-light"})}):null}const _i=f.createContext(null),fs=_i.Provider;function gs(){const t=f.useContext(_i);if(!t)throw new Error("Please use DashboardModelContextProvider");return t}const U=()=>gs(),ms=()=>gs(),ki=f.createContext({searchButtonProps:{}}),ys=ki.Provider;function Ti(){return f.useContext(ki)}const Ii=f.createContext(null),bs=Ii.Provider;function Di(){const t=f.useContext(Ii);if(!t)throw new Error("Please use ContentModelContextProvider");return t}const X=()=>Di(),oe=()=>Di(),zu={inEditMode:!1},pn=f.createContext(zu),Mi=f.createContext({panel:null,data:{},loading:!1,errors:[],downloadPanelScreenshot:()=>{}}),js=Mi.Provider;function Ai(){const t=f.useContext(Mi);if(!t.panel)throw new Error("Please use PanelContextProvider");return t}const ut=()=>Ai(),Be=()=>Ai(),Eu={fullScreenPanelID:"",setFullScreenPanelID:y.noop},vs=f.createContext(Eu);function zi(){const t=f.useContext(vs);if(!t)throw new Error("Please use FullScreenPanelContext.Provider");return t}const B=S.observer(f.forwardRef(({label:t,required:e,value:n,onChange:r,clearable:i=!1,sx:o,...l},c)=>{const{panel:u}=Be(),d=f.useMemo(()=>{const h=[...u.dataFieldOptions];return i&&h.unshift({label:"unset",value:"",group:""}),h},[u.dataFieldOptions]);return s.jsx(a.Select,{ref:c,label:t,data:d,value:n,onChange:r,required:e,sx:o,maxDropdownHeight:500,...l})}));function Pu({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=y.defaults({},e,xs),{control:i,handleSubmit:o,reset:l}=b.useForm({defaultValues:r});return f.useEffect(()=>{l(r)},[e]),e?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 Lu(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis_data_key:i,y_axis_data_key:o,z_axis_data_key:l,...c}=t;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 Bu extends re{constructor(){super(...arguments);z(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:Lu(i,r)}})}}const Ou={displayName:"Bar Chart (3D)",displayGroup:"ECharts-based charts",migrator:new Bu,name:"bar-3d",viewRender:Au,configRender:Pu,createConfig(){return{version:2,config:y.cloneDeep(xs)}}};class Ce extends f.Component{constructor(e){super(e),this.state={error:null}}componentDidCatch(e){this.setState({error:e})}render(){var e;if(this.state.error){const n=()=>{this.setState({error:null})};return s.jsxs(a.Box,{children:[s.jsx(a.Text,{size:"xs",children:(e=this.state.error)==null?void 0:e.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};function $u({value:t,onChange:e},n){const r=c=>{e({...t,output:c})},i=c=>{const u=c===0?!1:t.trimMantissa;e({...t,mantissa:c,trimMantissa:u})},o=c=>{e({...t,trimMantissa:c.currentTarget.checked})},l=c=>{e({...t,average:c.currentTarget.checked})};return 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:t.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:t.average,onChange:l,disabled:t.output!=="number",sx:{flexGrow:1},styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}}})]}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(a.NumberInput,{label:"Mantissa",defaultValue:0,min:0,step:1,max:4,value:t.mantissa,onChange:i}),s.jsx(a.Switch,{label:"Trim mantissa",checked:t.trimMantissa,onChange:o,disabled:t.mantissa===0,styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"}}})]}),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(t)]}),s.jsxs(a.Text,{size:12,color:"gray",children:["1234 ",s.jsx(_.ArrowRight,{size:9})," ",F(1234).format(t)]}),s.jsxs(a.Text,{size:12,color:"gray",children:["0.1234 ",s.jsx(_.ArrowRight,{size:9})," ",F(.1234).format(t)]})]})})]})]})}const Ae=f.forwardRef($u),Oe={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
55
- `)},Ei={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:Nu,configRender:Vu,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 Vu(t){return s.jsx(s.Fragment,{})}function Nu(t){return s.jsx(a.Text,{children:"Click chart's series"})}const qu=[{label:"Truncate",value:"truncate"},{label:"Break Line",value:"break"},{label:"Break Word",value:"breakAll"}],hn=f.forwardRef(({sectionTitle:t,value:e,onChange:n},r)=>{const i=o=>l=>{const c=y.cloneDeep(e);y.set(c,o,l),n(c)};return s.jsxs(a.Stack,{spacing:0,children:[t&&s.jsx(a.Divider,{mb:-5,mt:5,variant:"dotted",label:t,labelPosition:"right",labelProps:{color:"dimmed"}}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(a.NumberInput,{label:"Max Width",hideControls:!0,value:e.width,onChange:i("width")}),s.jsx(a.Select,{label:"Overflow",data:qu,value:e.overflow,onChange:i("overflow")}),s.jsx(a.TextInput,{label:"Ellipsis",value:e.ellipsis,disabled:!0})]})]})}),Xe=f.forwardRef(({value:t,onChange:e},n)=>{const r=o=>{e({...t,on_axis:o})},i=o=>{e({...t,in_tooltip:o})};return s.jsxs(a.Stack,{ref:n,spacing:0,children:[s.jsx(hn,{sectionTitle:"Overflow on Axis",value:t.on_axis,onChange:r}),s.jsx(hn,{sectionTitle:"Overflow in Tooltip",value:t.in_tooltip,onChange:i})]})}),ze={on_axis:{width:80,overflow:"truncate",ellipsis:"..."},in_tooltip:{width:200,overflow:"break",ellipsis:"..."}};function Je({overflow:t,width:e}){const n={truncate:"initial",break:"break-all",breakAll:"break-word"}[t],r=t==="truncate"?"nowrap":"initial",i={truncate:"ellipsis",break:"clip",breakAll:"clip"}[t];return`
54
+ `;function os(t,e){const n=Object.keys(e),r=Object.values(e);try{return new Function(...n,`return \`${t}\`;`)(...r)}catch(i){throw n.length===0&&t.includes("$")?new Error("[formatSQL] insufficient payload"):i}}function ls(t,e){try{return os(t,e)}catch(n){return console.error(n),n.message}}function au({sql:t,pre_process:e}){if(!e.trim())return t;try{return new Function(`return ${e}`)()({sql:t},gt)}catch(n){return console.error(n),t}}function ou(t,e,n){if(!t.trim())return e;try{return new Function(`return ${t}`)()(e,gt,n)}catch(r){return console.error(r),e}}function lu(t){t=t||{};const e=Object.keys(t).sort(),n=[];for(let r=0;r<e.length;r++){const i=e[r];if(i!="authentication"&&t[i])n.push(e[r]+"="+(typeof t[i]=="object"?JSON.stringify(t[i]):t[i]));else{const o=Object.keys(t[i]).sort();for(let l=0;l<o.length;l++){const c=o[l];c!="sign"&&t[i][c]&&n.push(o[l]+"="+(typeof t[i][c]=="object"?JSON.stringify(t[i][c]):t[i][c]))}}}return n.sort().join("&")}function cu(t,e){let n=lu(t);return n+="&key="+e,Hc.MD5(n).toString().toUpperCase()}class gi{constructor(){this.type="default_api_client",this.baseURL="http://localhost:31200",this.app_id="",this.app_secret=""}getAuthentication(e){if(!this.app_id||!this.app_secret)return;const n=new Date().getTime().toString();return{app_id:this.app_id,nonce_str:n,sign:cu({app_id:this.app_id,nonce_str:n,...e},this.app_secret)}}getRequest(e,n){return(r,i,o,l)=>{const c=this.buildHeader(o),u=this.buildAxiosConfig(e,r,i,o,c,n);return tt(u).then(d=>l?d:d.data).catch(d=>Promise.reject(d))}}get(e){return this.getRequest("GET",e)}post(e){return this.getRequest("POST",e)}put(e){return this.getRequest("PUT",e)}buildAxiosConfig(e,n,r,i,o,l){const c={baseURL:this.baseURL,method:e,url:n,params:e==="GET"?r:i.params,headers:o,signal:l};return["POST","PUT"].includes(e)&&(c.data=i.string?JSON.stringify(r):r,c.data.authentication=this.getAuthentication(c.data)),c}buildHeader(e){const n=window.localStorage.getItem("token");return{"X-Requested-With":"XMLHttpRequest","Content-Type":e.string?"application/x-www-form-urlencoded":"application/json",authorization:n?`bearer ${n}`:"",...e.headers}}}class uu{constructor(e){this.implementation=e}getRequest(e,n){return this.implementation.getRequest(e,n)}get(e){return this.getRequest("GET",e)}post(e){return this.getRequest("POST",e)}put(e){return this.getRequest("PUT",e)}}class mi extends gi{constructor(){super(...arguments);z(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 yi{constructor(e){this.implementation=e}query(e){return this.implementation.query(e)}httpDataSourceQuery(e){return this.implementation.httpDataSourceQuery(e)}structure(e){return this.implementation.structure(e)}getRequest(e,n){return this.implementation.getRequest(e,n)}get(e){return this.getRequest("GET",e)}post(e){return this.getRequest("POST",e)}put(e){return this.getRequest("PUT",e)}}const It=new mi;function cs(t){It.baseURL!==t.apiBaseURL&&(It.baseURL=t.apiBaseURL),t.app_id&&(It.app_id=t.app_id),t.app_secret&&(It.app_secret=t.app_secret),t.makeQueryENV&&(It.makeQueryENV=t.makeQueryENV)}const bi=new yi(It),Ke=bi;function ji(){return{filters:{},context:{}}}function us(t){const e=ji();if(!t)return ji();const{filters:n=e.filters,context:r=e.context}=t;return{filters:n,context:r}}async function du({query:t,name:e,payload:n,additionals:r},i){if(!t.sql)return[];const{type:o,key:l,sql:c,pre_process:u,post_process:d}=t,p=os(c,n),h=au({sql:p,pre_process:u});let x=await Ke.query(i)({type:o,key:l,query:h,...r},{params:{name:e}});return x=ou(d,x,us(n)),x}async function pu({type:t,key:e,configString:n,name:r,additionals:i},o){try{return await Ke.httpDataSourceQuery(o)({type:t,key:e,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 Ke.post()("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}},{})).data}catch(t){return console.error(t),[]}}async function vi(){try{return(await Ke.post()("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}},{})).data}catch(t){return console.error(t),[]}}class wi{constructor(e){z(this,"rootRef");this.rootRef=W.observable({current:e})}async deleteItem(e){W.runInAction(()=>{y.unset(this.rootRef.current,[e])})}getItem(e){const n=this.getValueFromRoot(e);return Promise.resolve(n)}getValueFromRoot(e){return e===null?W.toJS(this.rootRef.current):y.get(this.rootRef.current,[e])}setItem(e,n){if(e===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,[e],n)});return Promise.resolve(this.getItem(e))}watchItem(e,n,r){return W.reaction(()=>this.getValueFromRoot(e),(i,o)=>{n(i,o)},{requiresObservable:!0,fireImmediately:y.get(r,"fireImmediately",!1)})}}class hu{constructor(){z(this,"channels",new Map);z(this,"globalChannel",new Xr)}getChannel(e){const n=this.channels.get(e);if(n)return n;const r=new Xr;return this.channels.set(e,r),r}}class xu{constructor(e){z(this,"instances",new Map);this.pluginManager=e}get availableVizList(){return this.pluginManager.installedPlugins.flatMap(e=>e.manifest.viz)}resolveComponent(e){return this.pluginManager.factory.viz(e)}getOrCreateInstance(e){const n=this.instances.get(e.id);if(n)return n;const r={id:e.id,name:e.viz.type,type:e.viz.type,messageChannels:new hu,instanceData:new wi(e.viz.conf)};return this.instances.set(e.id,r),r}}function Ci(t,e,n,r){return{vizManager:n,locale:"zh",msgChannels:t.messageChannels,instanceData:t.instanceData,pluginData:new wi({}),colorPalette:{getColor(){return()=>""}},data:e,variables:r}}const fu=t=>{const{panel:e,vizManager:n,data:r,variables:i}=t,o=n.resolveComponent(e.viz.type),l=n.getOrCreateInstance(e),c={...Ci(l,r,n,i),viewport:{width:e.layout.w,height:e.layout.h}},u=o.viewRender;return s.jsx(u,{context:c,instance:l,...y.omit(t,["panel","vizManager","data"])})},gu=t=>{const{vizManager:e,panel:n,data:r,variables:i}=t,o=e.resolveComponent(n.viz.type),l=e.getOrCreateInstance(n),c={...Ci(l,r,e,i)},u=o.configRender;return s.jsx(u,{context:c,instance:l,...y.omit(t,["panel","vizManager","data"])})},Si=(t,e)=>{const n=nt.bezier(t),r=nt.bezier(e);return function(i){return i<50?n(i*2/100).hex():r((i-50)*2/100).hex()}},un=t=>{const e=nt.bezier(t);return function(n){return e(n/100).hex()}},mu={type:"interpolation",displayName:"Red / Green",getColor:Si(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},yu={type:"interpolation",displayName:"Yellow / Blue",getColor:Si(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},bu={type:"interpolation",displayName:"Red",getColor:un(["#fff7f1","darkred"]),name:"red",category:"sequential"},ju={type:"interpolation",displayName:"Green",getColor:un(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},vu={type:"interpolation",displayName:"Blue",getColor:un(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},wu={type:"interpolation",displayName:"Orange",getColor:un(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class Cu{constructor(e){z(this,"symbol");this.symbol=Symbol(e)}}function st(t){return new Cu(t)}class ps{constructor(){z(this,"parent");z(this,"factoryRegistry",new Map);z(this,"instanceRegistry",new Map)}createScoped(){const e=new ps;return e.parent=this,e}getRequired(e){return this.get(e)}get(e){if(this.instanceRegistry.has(e.symbol))return this.instanceRegistry.get(e.symbol);const n=this.factoryRegistry.get(e.symbol);if(n){const r=n(this);return this.instanceRegistry.set(e.symbol,r),r}if(this.parent)return this.parent.get(e)}provideFactory(e,n){return this.factoryRegistry.has(e.symbol)?console.warn(`Token ${e.symbol.toString()} is already registered`):this.factoryRegistry.set(e.symbol,n),this}provideValue(e,n){return this.factoryRegistry.has(e.symbol)?console.warn(`Token ${e.symbol.toString()} is already registered`):this.factoryRegistry.set(e.symbol,()=>n),this}dispose(){this.instanceRegistry.forEach(e=>{const n=y.get(e,"dispose");y.isFunction(n)&&n.bind(e)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}const _i="10.50.0",Su=Object.freeze(Object.defineProperty({__proto__:null,version:_i},Symbol.toStringTag,{value:"Module"}));class _u{constructor(e){z(this,"staticColors",new Map);z(this,"interpolations",new Map);e.installedPlugins.forEach(n=>{n.manifest.color.forEach(r=>{this.register(r)})})}getStaticColors(){return Array.from(this.staticColors.values())}register(e){const n=this.encodeColor(e);e.type==="single"?(this.staticColors.has(n)&&console.warn(`the color '${e.name}' has been registered under '${e.category}', previous registered value will be overridden`),this.staticColors.set(n,e)):e.type==="interpolation"&&(this.interpolations.has(n)&&console.warn(`the interpolation '${e.name}' has been registered under '${e.category}', previous registered value will be overridden`,`the interpolation '${e.name}' has been registered under '${e.category}', previous registered value will be overridden`),this.interpolations.set(n,e))}decodeStaticColor(e){return this.staticColors.get(e)}encodeColor(e){return`\${${e.category}}.{${e.name}}`}decodeInterpolation(e){return this.interpolations.get(e)}getColorInterpolations(){return Array.from(this.interpolations.values())}}class ku{constructor(){z(this,"plugins",new Map);z(this,"vizComponents",new Map);z(this,"factory",{viz:e=>{const n=this.vizComponents.get(e);if(n)return n;throw new Error(`Viz Component (${e}) not found`)}})}install(e){if(this.plugins.has(e.id))throw new Error(`Plugin (${e.id}) has been installed before`);this.plugins.set(e.id,e);for(const n of e.manifest.viz){if(this.vizComponents.has(n.name))throw new Error(`Viz Component (${n.name}) has been installed before`);this.vizComponents.set(n.name,n)}}get installedPlugins(){return Array.from(this.plugins.values())}}class Tu{constructor(){z(this,"migrations",[])}version(e,n){return this.migrations.push({version:e,handler:n}),this}run(e,n,r){var l;if(e.from===e.to)return n;if(e.from>e.to)throw new Error(`Can not downgrade from version '${e.from}' to (${e.to})`);const i=this.migrations.filter(c=>c.version>e.from&&c.version<=e.to),o=y.orderBy(i,"version","asc");if(((l=y.last(o))==null?void 0:l.version)!==e.to)throw new Error(`Migration to version ${e.to} not found`);return o.reduce((c,u)=>u.handler(c,r),n)}}class re extends Tu{constructor(){super(),this.configVersions()}version(e,n){return super.version(e,(r,i)=>({version:e,...n(r,i)}))}async migrate({configData:e,panelModel:n}){const r=await e.getItem(null),i=y.get(r,"version",0),o=this.run({from:i,to:this.VERSION},r,{panelModel:n});await e.setItem(null,o)}async needMigration({configData:e}){const n=await e.getItem(null);return y.get(n,"version",0)<this.VERSION}}const O=(t,e)=>{const[n,{setFalse:r}]=$.useBoolean(!0),[i,o]=f.useState();f.useEffect(()=>(t.getItem(e).then(c=>{o(c),r()}),t.watchItem(e,c=>{o(c)})));const l=f.useCallback(async c=>{await t.setItem(e,c),o(c)},[t,e]);return{loading:n,value:i,set:l}},ke={top:16,right:16,bottom:16,left:16},We=t=>Math.max(0,t-ke.left-ke.right),Re=t=>Math.max(0,t-ke.top-ke.bottom),Wt=(t,e)=>({width:We(t),height:Re(e)}),Te=({width:t,height:e,children:n})=>s.jsx(a.Box,{pt:ke.top,pr:ke.right,pb:ke.bottom,pl:ke.left,sx:{width:t,height:e,overflow:"hidden",position:"relative"},children:n});function D(t){const[e,n]=t.split(".");return{queryID:e,columnKey:n}}function Iu(t){return t.includes(".")?D(t):{queryID:"",columnKey:t}}function rt(t,e){var i;const{queryID:n,columnKey:r}=D(e);return n?r?((i=t[n])==null?void 0:i.map(o=>o[r]))??[]:t[n]:[]}function Rt(t,e){const{queryID:n}=D(e);return n?t[n]:[]}function Du(t){return Object.values(t)[0]}function dn(t,e){const{queryID:n,columnKey:r}=D(e);return t[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([P.GridComponent,P.VisualMapComponent,P.LegendComponent,P.TooltipComponent,we.CanvasRenderer]);function Mu({context:t}){const{value:e}=O(t.instanceData,"config"),n=t.data,{width:r,height:i}=t.viewport,{x_axis_data_key:o,y_axis_data_key:l,z_axis_data_key:c,xAxis3D:u,yAxis3D:d,zAxis3D:p}=y.defaults({},e,hs),h=f.useMemo(()=>Rt(n,o),[n,o]),{x,y:m,z:j}=f.useMemo(()=>({x:D(o),y:D(l),z:D(c)}),[o,l,c]),{min:C,max:T}=f.useMemo(()=>{const L=y.minBy(h,se=>se[j.columnKey]),U=y.maxBy(h,se=>se[j.columnKey]);return{min:y.get(L,j.columnKey),max:y.get(U,j.columnKey)}},[h,j]),A={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:C,max:T,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:u,yAxis3D:d,zAxis3D:p,grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}},series:[{type:"bar3D",wireframe:{},data:h.map(L=>[L[x.columnKey],L[m.columnKey],L[j.columnKey]])}]};return e?s.jsx(Te,{width:r,height:i,children:s.jsx(ve,{echarts:Y,option:A,style:Wt(r,i),notMerge:!0,theme:"merico-light"})}):null}const ki=f.createContext(null),xs=ki.Provider;function fs(){const t=f.useContext(ki);if(!t)throw new Error("Please use DashboardModelContextProvider");return t}const K=()=>fs(),gs=()=>fs(),Ti=f.createContext({searchButtonProps:{}}),ms=Ti.Provider;function Ii(){return f.useContext(Ti)}const Di=f.createContext(null),ys=Di.Provider;function Mi(){const t=f.useContext(Di);if(!t)throw new Error("Please use ContentModelContextProvider");return t}const X=()=>Mi(),oe=()=>Mi(),Au={inEditMode:!1},pn=f.createContext(Au),Ai=f.createContext({panel:null,data:{},loading:!1,errors:[],downloadPanelScreenshot:()=>{}}),bs=Ai.Provider;function zi(){const t=f.useContext(Ai);if(!t.panel)throw new Error("Please use PanelContextProvider");return t}const dt=()=>zi(),Le=()=>zi(),zu={fullScreenPanelID:"",setFullScreenPanelID:y.noop},js=f.createContext(zu);function Ei(){const t=f.useContext(js);if(!t)throw new Error("Please use FullScreenPanelContext.Provider");return t}const B=S.observer(f.forwardRef(({label:t,required:e,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:t,data:d,value:n,onChange:r,required:e,sx:o,maxDropdownHeight:500,...l})}));function Eu({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=y.defaults({},e,hs),{control:i,handleSubmit:o,reset:l}=b.useForm({defaultValues:r});return f.useEffect(()=>{l(r)},[e]),e?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 Pu(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis_data_key:i,y_axis_data_key:o,z_axis_data_key:l,...c}=t;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 Lu extends re{constructor(){super(...arguments);z(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:Pu(i,r)}})}}const Bu={displayName:"Bar Chart (3D)",displayGroup:"ECharts-based charts",migrator:new Lu,name:"bar-3d",viewRender:Mu,configRender:Eu,createConfig(){return{version:2,config:y.cloneDeep(hs)}}};class Ce extends f.Component{constructor(e){super(e),this.state={error:null}}componentDidCatch(e){this.setState({error:e})}render(){var e;if(this.state.error){const n=()=>{this.setState({error:null})};return s.jsxs(a.Box,{children:[s.jsx(a.Text,{size:"xs",children:(e=this.state.error)==null?void 0:e.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},Pi={root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}};function Ou({value:t,onChange:e},n){const r=c=>{e({...t,output:c})},i=c=>{const u=c===0?!1:t.trimMantissa;e({...t,mantissa:c,trimMantissa:u})},o=c=>{e({...t,trimMantissa:c.currentTarget.checked})},l=c=>{e({...t,average:c.currentTarget.checked})};return 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:t.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:t.average,onChange:l,disabled:t.output!=="number",sx:{flexGrow:1},styles:Pi})]}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(a.NumberInput,{label:"Mantissa",defaultValue:0,min:0,step:1,max:4,value:t.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:t.trimMantissa,onChange:o,disabled:t.mantissa===0,styles:Pi})]}),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(t)]}),s.jsxs(a.Text,{size:12,color:"gray",children:["1234 ",s.jsx(_.ArrowRight,{size:9})," ",F(1234).format(t)]}),s.jsxs(a.Text,{size:12,color:"gray",children:["0.1234 ",s.jsx(_.ArrowRight,{size:9})," ",F(.1234).format(t)]})]})})]})]})}const Be=f.forwardRef(Ou),Oe={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
55
+ `)},Li={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:Vu,configRender:$u,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 $u(t){return s.jsx(s.Fragment,{})}function Vu(t){return s.jsx(a.Text,{children:"Click chart's series"})}const Nu=[{label:"Truncate",value:"truncate"},{label:"Break Line",value:"break"},{label:"Break Word",value:"breakAll"}],hn=f.forwardRef(({sectionTitle:t,value:e,onChange:n},r)=>{const i=o=>l=>{const c=y.cloneDeep(e);y.set(c,o,l),n(c)};return s.jsxs(a.Stack,{spacing:0,children:[t&&s.jsx(a.Divider,{mb:-5,mt:5,variant:"dotted",label:t,labelPosition:"right",labelProps:{color:"dimmed"}}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(a.NumberInput,{label:"Max Width",hideControls:!0,value:e.width,onChange:i("width")}),s.jsx(a.Select,{label:"Overflow",data:Nu,value:e.overflow,onChange:i("overflow")}),s.jsx(a.TextInput,{label:"Ellipsis",value:e.ellipsis,disabled:!0})]})]})}),Xe=f.forwardRef(({value:t,onChange:e},n)=>{const r=o=>{e({...t,on_axis:o})},i=o=>{e({...t,in_tooltip:o})};return s.jsxs(a.Stack,{ref:n,spacing:0,children:[s.jsx(hn,{sectionTitle:"Overflow on Axis",value:t.on_axis,onChange:r}),s.jsx(hn,{sectionTitle:"Overflow in Tooltip",value:t.in_tooltip,onChange:i})]})}),Ae={on_axis:{width:80,overflow:"truncate",ellipsis:"..."},in_tooltip:{width:200,overflow:"break",ellipsis:"..."}};function Je({overflow:t,width:e}){const n={truncate:"initial",break:"break-all",breakAll:"break-word"}[t],r=t==="truncate"?"nowrap":"initial",i={truncate:"ellipsis",break:"clip",breakAll:"clip"}[t];return`
56
56
  max-width: ${e}px;
57
57
  word-break: ${n};
58
58
  white-space: ${r};
59
59
  overflow: hidden;
60
60
  text-overflow: ${i};
61
- `}function Qe(t){return{width:t.width,overflow:t.overflow,ellipsis:t.ellipsis}}const ws={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...Oe},overflow:ze}},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(t,e){return f.useMemo(()=>{const{queryID:n,columnKey:r}=D(e);return y.keyBy(t[n],r)},[t,e])}const $e=(t,e)=>{const[n,r]=f.useState([]);return f.useEffect(()=>t.watchTriggerSnapshotList(i=>r(i.filter(o=>o.schemaRef===e))),[]),n};class Dt{constructor(e,n){this.root=e,this.path=n}async deleteItem(e){e===null&&await this.root.deleteItem(this.path);const n=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,y.omit(n,e))}async getItem(e){const n=await this.root.getItem(this.path);return e===null?n:y.get(n,e)}async setItem(e,n){if(e===null)await this.root.setItem(this.path,n);else{const r=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,{...r,[e]:n})}return await this.getItem(e)}watchItem(e,n,r){return e===null?this.root.watchItem(this.path,(i,o)=>{n(i,o)},r):this.root.watchItem(this.path,(i,o)=>{const l=y.get(i,e),c=y.get(o,e);l!==c&&n(l,c)},r)}}class Cs{constructor(e,n,r){z(this,"attachmentStorage");this.instance=e,this.attachmentKey=n,this.constructInstance=r,this.attachmentStorage=new Dt(e.instanceData,n)}async getInstance(e){if(await this.attachmentStorage.getItem(e))return this.constructInstance(new Dt(this.attachmentStorage,e))}async create(e,n){return await this.attachmentStorage.setItem(e,n),this.constructInstance(new Dt(this.attachmentStorage,e))}async remove(e){await this.attachmentStorage.deleteItem(e)}async list(){const e=await this.attachmentStorage.getItem(null);return Promise.all(y.values(e).map(n=>this.constructInstance(new Dt(this.attachmentStorage,n.id))))}}function Fu(t,e){const{value:n,set:r}=O(t.operation.operationData,"config"),[i,o]=f.useState(y.defaults({},n,e)),l=async()=>{await r(i)};return f.useEffect(()=>{o(y.defaults({},n,e))},[n]),{config:i,setConfig:o,commit:l}}function Gu(t){const{config:e,setConfig:n,commit:r}=Fu(t,{urlTemplate:"",openInNewTab:!0});async function i(){await r()}async function o(c){n({...e,openInNewTab:c}),await r()}const l=c=>n({...e,urlTemplate:c.currentTarget.value});return s.jsxs(a.Stack,{children:[s.jsx(a.TextInput,{label:"Url",value:e.urlTemplate,onChange:l,onBlur:i}),s.jsx(a.Switch,{label:"Open in new Tab",checked:e.openInNewTab,onChange:c=>o(c.currentTarget.checked)})]})}async function Wu(t,e){const{urlTemplate:n,openInNewTab:r}=await e.operationData.getItem("config");window.dispatchEvent(new CustomEvent("open-link",{detail:{urlTemplate:n,openInNewTab:r,payload:t}}))}class Ru extends re{constructor(){super(...arguments);z(this,"VERSION",1)}configVersions(){this.version(1,n=>n)}}const Qu={displayName:"Open Link",id:"builtin:op:open-link",configRender:Gu,run:Wu,migrator:new Ru,createDefaultConfig:()=>({version:1,config:{urlTemplate:"",openInNewTab:!0}})};function Yu(t){const{value:e,set:n}=O(t.operationData,"config"),r=i=>void n({template:i});return[(e==null?void 0:e.template)||"",r]}function Ku(t){const[e,n]=Yu(t.operation);return s.jsx(a.TextInput,{defaultValue:e,onBlur:r=>n(r.currentTarget.value),label:"console.log"})}async function Uu(t,e){const n=await e.operationData.getItem("config"),r=y.template(n.template||"");console.log("run with payload",t),console.log(r(t))}const Xu={displayName:"console.log (debug)",id:"builtin:op:debug",configRender:Ku,run:Uu},Ju=S.observer(t=>{const e=X(),{value:n,set:r}=O(t.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:e.views.options,withinPortal:!0,zIndex:340,maxDropdownHeight:500})});async function Zu(t,e){const r=(await e.operationData.getItem("config")).viewID;window.dispatchEvent(new CustomEvent("open-view",{detail:{viewID:r}}))}const Hu={displayName:"Open View",id:"builtin:op:open_view",configRender:Ju,run:Zu},ed={"tbody tr":{opacity:.5,transition:"opacity 200ms ease"},"tr[data-affected=true]":{opacity:1}},td=({value:t="",onChange:e})=>{const[n,r]=f.useState(t);f.useEffect(()=>{r(t)},[t]);const i=()=>{e(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===t,children:s.jsx(k.IconDeviceFloppy,{})})})},nd={dictionary:{}},sd=S.observer(t=>{const e=X(),{value:n=nd,set:r}=O(t.operation.operationData,"config"),{dictionary:i={}}=n;console.log({value:{...n},dictionary:{...i},filters:[...e.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:ed,children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Set filter"}),s.jsx("th",{children:"with"})]})}),s.jsx("tbody",{children:[...e.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(td,{value:i[l.value],onChange:u=>o(l.value,u)})})]},l.value)})})]})});async function rd(t,e){const r=(await e.operationData.getItem("config")).dictionary;window.dispatchEvent(new CustomEvent("set-filter-values",{detail:{dictionary:r,payload:t}}))}const id={displayName:"Set Filter Values",id:"builtin:op:set_filter_values",configRender:sd,run:rd},ad={filter_keys:[]},od=S.observer(t=>{const e=X(),{value:n=ad,set:r}=O(t.operation.operationData,"config"),{filter_keys:i=[]}=n,o=c=>{r({filter_keys:[...c]})},l=f.useMemo(()=>e.filters.current.map(c=>({label:c.label,value:c.key})),[e.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 ld(t,e){const r=(await e.operationData.getItem("config")).filter_keys;window.dispatchEvent(new CustomEvent("clear-filter-values",{detail:{filter_keys:r,payload:t}}))}const xn=[Xu,Qu,Hu,id,{displayName:"Clear Filter Values",id:"builtin:op:clear_filter_values",configRender:od,run:ld}];class cd{constructor(e,n=xn){z(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 Dt(i,"data")}};this.attachments=new Cs(e,"__OPERATIONS",r)}async runOperation(e,n){const r=await this.attachments.getInstance(e);if(!r){console.warn(`Operation '${e}' is not defined`);return}const i=this.tryGetSchema(r.schemaRef);if(!i){console.warn(`Operation schema '${r.schemaRef}' is not defined`);return}await i.run(n,r)}tryGetSchema(e){return this.operations.find(n=>n.id===e)}async needMigration(){const n=(await this.attachments.list()).map(async r=>{const 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(e,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(e);return!i||i.schemaRef!==n.id?await this.attachments.create(e,{id:e,schemaRef:n.id,data:((l=n.createDefaultConfig)==null?void 0:l.call(n))??{}}):i}getOperationList(){return this.attachments.list()}getOperationSchemaList(){return this.operations}removeOperation(e){return this.attachments.remove(e)}async retrieveTrigger(e){return await this.attachments.getInstance(e)}}const Pi="__TRIGGERS";class ud{constructor(e,n){z(this,"attachments");this.instance=e,this.component=n;const r=async i=>{const{id:o,schemaRef:l}=await i.getItem(null);return{id:o,schemaRef:l,triggerData:new Dt(i,"data")}};this.attachments=new Cs(e,Pi,r)}watchTriggerSnapshotList(e){return this.instance.instanceData.watchItem(Pi,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"))}));e(r)},{fireImmediately:!0})}async createOrGetTrigger(e,n,r={recreate:!1}){var c;if(!this.getTriggerSchemaList().some(u=>u.id===n.id))throw new Error(`Trigger schema '${n.id}' is not defined in component '${this.component.name}'`);const o=await this.attachments.getInstance(e);return!o||r.recreate||o.schemaRef!==n.id?await this.attachments.create(e,{id:e,schemaRef:n.id,data:((c=n==null?void 0:n.createDefaultConfig)==null?void 0:c.call(n))||{}}):o}async getTriggerList(){return await this.attachments.list()}getTriggerSchemaList(){return this.component.triggers||[]}async removeTrigger(e){await this.attachments.remove(e)}async retrieveTrigger(e){return await this.attachments.getInstance(e)}async getMigrationTasks(){const n=(await this.getTriggerList()).map(async r=>{const 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 e=await this.getMigrationTasks();await Promise.all(e.map(n=>n()))}}class Ss{constructor(e,n,r){z(this,"operationManager");z(this,"triggerManager");z(this,"attachments");this.operationManager=new cd(e,r),this.triggerManager=new ud(e,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 Cs(e,"__INTERACTIONS",i)}async addInteraction(e,n){const r=e.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(e){const n=await this.attachments.getInstance(e);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(e)}async getOperationRefCount(e){return(await this.getInteractionList()).filter(r=>r.operationRef===e).length}async getTriggerRefCount(e){return(await this.getInteractionList()).filter(r=>r.triggerRef===e).length}async runInteraction(e,n){const i=(await this.getInteractionList()).filter(o=>o.triggerRef===e);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:t,instance:e})=>$.useCreation(()=>new Ss(e,t.resolveComponent(e.type),xn),[e,t]),Li=t=>{const{title:e="Variables",variables:n}=t,r=pe.useClipboard(),i=o=>{r.copy(o),ht.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:e}),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 dd{constructor(e,n){z(this,"operationId");z(this,"operation");z(this,"operationSchema");z(this,"variables",[]);this.operationManager=e,this.instance=n,W.makeAutoObservable(this)}get schemaList(){return this.operationManager.getOperationSchemaList()}async configOperation(e,n){const r=await this.operationManager.retrieveTrigger(e),i=this.operationManager.getOperationSchemaList().find(o=>o.id===(r==null?void 0:r.schemaRef));W.runInAction(()=>{this.operationId=e,this.operation=r,this.operationSchema=i,this.variables=n})}async changeSchema(e){this.operationId&&(await this.operationManager.createOrGetOperation(this.operationId,e),await this.configOperation(this.operationId,this.variables))}}function pd(t){return!!t.operationId}const hd=S.observer(({model:t,onClick:e})=>{var r;const n=(r=t.operationSchema)==null?void 0:r.displayName;return s.jsx(a.Button,{variant:"outline",onClick:e,children:n})}),xd=S.observer(({model:t})=>{const e={operation:t.operation,instance:t.instance,variables:[]};return f.createElement(t.operationSchema.configRender,e)}),fd=S.observer(({model:t})=>{const e=t.schemaList,n=e.map(i=>({label:i.displayName,value:i.id}));async function r(i){await t.changeSchema(e.find(o=>o.id===i))}return s.jsx(a.Select,{label:"Operation",data:n,onChange:r,value:t.operationSchema.id,withinPortal:!0,zIndex:340})}),gd=S.observer(t=>{const[e,{setTrue:n,setFalse:r}]=$.useBoolean(!1),{operationManager:i,operationId:o,instance:l,variables:c}=t,u=$.useCreation(()=>new dd(i,l),[i,l]);return $.useAsyncEffect(async()=>{await u.configOperation(o,c)},[o,u]),pd(u)?s.jsxs(s.Fragment,{children:[s.jsx(hd,{model:u,onClick:n}),s.jsx(a.Modal,{size:600,opened:e,onClose:r,title:"Operation Settings",zIndex:320,children:s.jsxs(a.Stack,{children:[s.jsx(fd,{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(xd,{model:u})}),s.jsx(a.Tabs.Panel,{value:"variables",pt:10,children:s.jsx(Li,{title:"Variables",variables:u.variables})})]})]})})]}):null});class md{constructor(e,n){z(this,"triggerId");z(this,"trigger");z(this,"triggerSchema");z(this,"sampleData");this.triggerManager=e,this.instance=n,W.makeAutoObservable(this)}get schemaList(){return this.triggerManager.getTriggerSchemaList()}async configTrigger(e,n){const r=await this.triggerManager.retrieveTrigger(e),i=this.triggerManager.getTriggerSchemaList().find(o=>o.id===(r==null?void 0:r.schemaRef));W.runInAction(()=>{this.triggerId=e,this.trigger=r,this.triggerSchema=i,this.sampleData=n})}async changeSchema(e){this.triggerId&&(await this.triggerManager.createOrGetTrigger(this.triggerId,e),await this.configTrigger(this.triggerId,this.sampleData))}isReady(){return yd(this)}}function yd(t){return!!t.triggerId&&!!t.triggerSchema}function bd(t,e){return $.useCreation(()=>new md(t,e),[t,e])}const jd=S.observer(({model:t,onClick:e})=>{const n=t.triggerSchema.nameRender,r={trigger:t.trigger,instance:t.instance,sampleData:t.sampleData};return s.jsx(a.Button,{variant:"outline",onClick:e,children:f.createElement(n,r)})}),vd=S.observer(({model:t})=>{const e=t.schemaList,n=e.map(i=>({label:i.displayName,value:i.id}));async function r(i){await t.changeSchema(e.find(o=>o.id===i))}return s.jsx(a.Select,{label:"Trigger",data:n,value:t.triggerSchema.id,onChange:r})}),wd=S.observer(({model:t})=>{const e={trigger:t.trigger,instance:t.instance,sampleData:t.sampleData};return f.createElement(t.triggerSchema.configRender,e)}),Cd=S.observer(t=>{const[e,{setTrue:n,setFalse:r}]=$.useBoolean(!1),i=t.model;return s.jsxs(s.Fragment,{children:[s.jsx(a.Modal,{opened:e,onClose:r,title:"Setup Trigger",zIndex:320,children:s.jsxs(a.Stack,{children:[s.jsx(vd,{model:i}),s.jsx(wd,{model:i}),s.jsx(Li,{title:"Payload",variables:i.triggerSchema.payload})]})}),s.jsx(jd,{onClick:n,model:i})]})});function Sd(t,e){const[n,r]=f.useState([]);return $.useAsyncEffect(async()=>{const i=await t.getInteractionList();r(i)},[e,t]),n}const _d=S.observer(({item:t,manager:e,instance:n,sampleData:r,variables:i,onRemove:o})=>{const{triggerRef:l,operationRef:c}=t,u=bd(e.triggerManager,n);if($.useAsyncEffect(async()=>{await u.configTrigger(l,r)},[u,l,r]),u.isReady()){const d=[...u.triggerSchema.payload,...i];return s.jsxs(a.Group,{children:[s.jsx(Cd,{model:u}),s.jsx(gd,{instance:n,operationId:c,variables:d,operationManager:e.operationManager}),s.jsx(a.ActionIcon,{"aria-label":"delete-interaction",variant:"filled",color:"red",onClick:()=>o(t),children:s.jsx(_.Trash,{size:16})})]})}return null}),kd=t=>{const[e,n]=f.useState(0),{interactionManager:r,instance:i,sampleData:o,variables:l}=t,c=Sd(r,e),u=async()=>{const x=await r.triggerManager.createOrGetTrigger(pe.randomId(),r.triggerManager.getTriggerSchemaList()[0]),m=await r.operationManager.createOrGetOperation(pe.randomId(),r.operationManager.getOperationSchemaList()[0]);await r.addInteraction(x,m),n(j=>j+1)};async function d(x){await r.removeInteraction(x.id),n(m=>m+1)}const{data:h=0,loading:p}=$.useRequest(async()=>{try{return(await r.triggerManager.getTriggerSchemaList()).length}catch{return 0}});return s.jsxs(a.Stack,{children:[s.jsx(a.LoadingOverlay,{visible:p}),h===0&&s.jsx(a.Alert,{icon:s.jsx(_.AlertCircle,{size:16}),title:"Unavailable",color:"gray",children:"This visualization does not have available interactions to choose from"}),c.map(x=>s.jsx(_d,{onRemove:d,instance:i,sampleData:o,variables:l,item:x,manager:t.interactionManager},x.id)),s.jsx(a.Button,{style:{width:"fit-content"},onClick:()=>u(),disabled:h===0,children:"Add interaction"})]})},Td=()=>{const{panel:t,data:e}=ut(),n=t.viz,{vizManager:r}=f.useContext(et),i=t.json,o=$.useCreation(()=>r.getOrCreateInstance(i),[r,i]),l=$.useCreation(()=>new Ss(o,r.resolveComponent(n.type),xn),[o,n.type]);return f.useEffect(()=>o.instanceData.watchItem(null,y.throttle(c=>{t.viz.setConf(c)},100,{leading:!1,trailing:!0})),[o]),{instance:o,vizManager:r,interactionManager:l,sampleData:e,variables:[]}},Id=()=>{const t=Td();return s.jsx(kd,{...t})};function Mt({enabled:t,func_content:e}){return(n,r)=>{if(!t)return n;try{return new Function(`return ${e}`)()(n,r)}catch(i){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${i.message}`),n}}}function Dd(t,e){return Object.entries(t).map(([r,i])=>{const o=i.map(T=>T[e]).sort((T,A)=>T-A),l=Nt.quantile(o,.25)??0,c=Nt.quantile(o,.5)??0,u=Nt.quantile(o,.75)??0,d=u-l,h=l-1.5*d,p=u+1.5*d,x=Math.max(o[0],h),m=Math.min(y.last(o)??0,p),j=i.filter(T=>{const A=T[e];return A<x||A>m}).map(T=>[r,T[e],T]);return{name:r,min:x,q1:l,median:c,q3:u,max:m,outliers:j}})}function Md(t,e){const{x_axis:n,y_axis:r}=t;if(!n.data_key||!r.data_key)return[];const i=D(n.data_key),o=D(r.data_key);if(i.queryID!==o.queryID)throw new Error("Please use the same query for X & Y axis");const l=y.groupBy(e[i.queryID],i.columnKey),c=Dd(l,o.columnKey),u=c.map(d=>d.outliers).flat();return[{source:c},{source:u}]}function Ad({config:t}){return{...t.legend,data:[{name:"Box",icon:"roundRect",itemStyle:{color:t.color}},{name:"Outlier",icon:"circle",itemStyle:{color:"#ED6A45"}}]}}const _s=["max","q3","median","q1","min"];function zd(t){const{color:e}=t;return[{name:"Box",type:"boxplot",itemStyle:{color:e,borderColor:"#2F8CC0",borderWidth:2},emphasis:{disabled:!0},boxWidth:[10,40],datasetIndex:0,encode:{y:_s,x:"name",itemName:["name"],tooltip:_s}},{name:"Outlier",type:"scatter",symbolSize:7,itemStyle:{color:"#ED6A45"},emphasis:{scale:2},datasetIndex:1}]}function Ed(t){const{outliers:e,min:n,max:r}=t,i=e.filter(c=>c[1]<n).length,o=e.filter(c=>c[1]>r).length,l=(c,u)=>`
61
+ `}function Qe(t){return{width:t.width,overflow:t.overflow,ellipsis:t.ellipsis}}const vs={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...Oe},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(t,e){return f.useMemo(()=>{const{queryID:n,columnKey:r}=D(e);return y.keyBy(t[n],r)},[t,e])}const $e=(t,e)=>{const[n,r]=f.useState([]);return f.useEffect(()=>t.watchTriggerSnapshotList(i=>r(i.filter(o=>o.schemaRef===e))),[]),n};class Dt{constructor(e,n){this.root=e,this.path=n}async deleteItem(e){e===null&&await this.root.deleteItem(this.path);const n=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,y.omit(n,e))}async getItem(e){const n=await this.root.getItem(this.path);return e===null?n:y.get(n,e)}async setItem(e,n){if(e===null)await this.root.setItem(this.path,n);else{const r=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,{...r,[e]:n})}return await this.getItem(e)}watchItem(e,n,r){return e===null?this.root.watchItem(this.path,(i,o)=>{n(i,o)},r):this.root.watchItem(this.path,(i,o)=>{const l=y.get(i,e),c=y.get(o,e);l!==c&&n(l,c)},r)}}class ws{constructor(e,n,r){z(this,"attachmentStorage");this.instance=e,this.attachmentKey=n,this.constructInstance=r,this.attachmentStorage=new Dt(e.instanceData,n)}async getInstance(e){if(await this.attachmentStorage.getItem(e))return this.constructInstance(new Dt(this.attachmentStorage,e))}async create(e,n){return await this.attachmentStorage.setItem(e,n),this.constructInstance(new Dt(this.attachmentStorage,e))}async remove(e){await this.attachmentStorage.deleteItem(e)}async list(){const e=await this.attachmentStorage.getItem(null);return Promise.all(y.values(e).map(n=>this.constructInstance(new Dt(this.attachmentStorage,n.id))))}}function qu(t,e){const{value:n,set:r}=O(t.operation.operationData,"config"),[i,o]=f.useState(y.defaults({},n,e)),l=async()=>{await r(i)};return f.useEffect(()=>{o(y.defaults({},n,e))},[n]),{config:i,setConfig:o,commit:l}}function Fu(t){const{config:e,setConfig:n,commit:r}=qu(t,{urlTemplate:"",openInNewTab:!0});async function i(){await r()}async function o(c){n({...e,openInNewTab:c}),await r()}const l=c=>n({...e,urlTemplate:c.currentTarget.value});return s.jsxs(a.Stack,{children:[s.jsx(a.TextInput,{label:"Url",value:e.urlTemplate,onChange:l,onBlur:i}),s.jsx(a.Switch,{label:"Open in new Tab",checked:e.openInNewTab,onChange:c=>o(c.currentTarget.checked)})]})}async function Gu(t,e){const{urlTemplate:n,openInNewTab:r}=await e.operationData.getItem("config");window.dispatchEvent(new CustomEvent("open-link",{detail:{urlTemplate:n,openInNewTab:r,payload:t}}))}class Wu extends re{constructor(){super(...arguments);z(this,"VERSION",1)}configVersions(){this.version(1,n=>n)}}const Ru={displayName:"Open Link",id:"builtin:op:open-link",configRender:Fu,run:Gu,migrator:new Wu,createDefaultConfig:()=>({version:1,config:{urlTemplate:"",openInNewTab:!0}})};function Qu(t){const{value:e,set:n}=O(t.operationData,"config"),r=i=>void n({template:i});return[(e==null?void 0:e.template)||"",r]}function Uu(t){const[e,n]=Qu(t.operation);return s.jsx(a.TextInput,{defaultValue:e,onBlur:r=>n(r.currentTarget.value),label:"console.log"})}async function Yu(t,e){const n=await e.operationData.getItem("config"),r=y.template(n.template||"");console.log("run with payload",t),console.log(r(t))}const Ku={displayName:"console.log (debug)",id:"builtin:op:debug",configRender:Uu,run:Yu},Xu=S.observer(t=>{const e=X(),{value:n,set:r}=O(t.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:e.views.options,withinPortal:!0,zIndex:340,maxDropdownHeight:500})});async function Ju(t,e){const r=(await e.operationData.getItem("config")).viewID;window.dispatchEvent(new CustomEvent("open-view",{detail:{viewID:r}}))}const Zu={displayName:"Open View",id:"builtin:op:open_view",configRender:Xu,run:Ju},Hu={"tbody tr":{opacity:.5,transition:"opacity 200ms ease"},"tr[data-affected=true]":{opacity:1}},ed=({value:t="",onChange:e})=>{const[n,r]=f.useState(t);f.useEffect(()=>{r(t)},[t]);const i=()=>{e(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===t,children:s.jsx(k.IconDeviceFloppy,{})})})},td={dictionary:{}},nd=S.observer(t=>{const e=X(),{value:n=td,set:r}=O(t.operation.operationData,"config"),{dictionary:i={}}=n;console.log({value:{...n},dictionary:{...i},filters:[...e.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:Hu,children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Set filter"}),s.jsx("th",{children:"with"})]})}),s.jsx("tbody",{children:[...e.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(ed,{value:i[l.value],onChange:u=>o(l.value,u)})})]},l.value)})})]})});async function sd(t,e){const r=(await e.operationData.getItem("config")).dictionary;window.dispatchEvent(new CustomEvent("set-filter-values",{detail:{dictionary:r,payload:t}}))}const rd={displayName:"Set Filter Values",id:"builtin:op:set_filter_values",configRender:nd,run:sd},id={filter_keys:[]},ad=S.observer(t=>{const e=X(),{value:n=id,set:r}=O(t.operation.operationData,"config"),{filter_keys:i=[]}=n,o=c=>{r({filter_keys:[...c]})},l=f.useMemo(()=>e.filters.current.map(c=>({label:c.label,value:c.key})),[e.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 od(t,e){const r=(await e.operationData.getItem("config")).filter_keys;window.dispatchEvent(new CustomEvent("clear-filter-values",{detail:{filter_keys:r,payload:t}}))}const xn=[Ku,Ru,Zu,rd,{displayName:"Clear Filter Values",id:"builtin:op:clear_filter_values",configRender:ad,run:od}];class ld{constructor(e,n=xn){z(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 Dt(i,"data")}};this.attachments=new ws(e,"__OPERATIONS",r)}async runOperation(e,n){const r=await this.attachments.getInstance(e);if(!r){console.warn(`Operation '${e}' is not defined`);return}const i=this.tryGetSchema(r.schemaRef);if(!i){console.warn(`Operation schema '${r.schemaRef}' is not defined`);return}await i.run(n,r)}tryGetSchema(e){return this.operations.find(n=>n.id===e)}async needMigration(){const n=(await this.attachments.list()).map(async r=>{const 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(e,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(e);return!i||i.schemaRef!==n.id?await this.attachments.create(e,{id:e,schemaRef:n.id,data:((l=n.createDefaultConfig)==null?void 0:l.call(n))??{}}):i}getOperationList(){return this.attachments.list()}getOperationSchemaList(){return this.operations}removeOperation(e){return this.attachments.remove(e)}async retrieveTrigger(e){return await this.attachments.getInstance(e)}}const Bi="__TRIGGERS";class cd{constructor(e,n){z(this,"attachments");this.instance=e,this.component=n;const r=async i=>{const{id:o,schemaRef:l}=await i.getItem(null);return{id:o,schemaRef:l,triggerData:new Dt(i,"data")}};this.attachments=new ws(e,Bi,r)}watchTriggerSnapshotList(e){return this.instance.instanceData.watchItem(Bi,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"))}));e(r)},{fireImmediately:!0})}async createOrGetTrigger(e,n,r={recreate:!1}){var c;if(!this.getTriggerSchemaList().some(u=>u.id===n.id))throw new Error(`Trigger schema '${n.id}' is not defined in component '${this.component.name}'`);const o=await this.attachments.getInstance(e);return!o||r.recreate||o.schemaRef!==n.id?await this.attachments.create(e,{id:e,schemaRef:n.id,data:((c=n==null?void 0:n.createDefaultConfig)==null?void 0:c.call(n))||{}}):o}async getTriggerList(){return await this.attachments.list()}getTriggerSchemaList(){return this.component.triggers||[]}async removeTrigger(e){await this.attachments.remove(e)}async retrieveTrigger(e){return await this.attachments.getInstance(e)}async getMigrationTasks(){const n=(await this.getTriggerList()).map(async r=>{const 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 e=await this.getMigrationTasks();await Promise.all(e.map(n=>n()))}}class Cs{constructor(e,n,r){z(this,"operationManager");z(this,"triggerManager");z(this,"attachments");this.operationManager=new ld(e,r),this.triggerManager=new cd(e,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(e,"__INTERACTIONS",i)}async addInteraction(e,n){const r=e.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(e){const n=await this.attachments.getInstance(e);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(e)}async getOperationRefCount(e){return(await this.getInteractionList()).filter(r=>r.operationRef===e).length}async getTriggerRefCount(e){return(await this.getInteractionList()).filter(r=>r.triggerRef===e).length}async runInteraction(e,n){const i=(await this.getInteractionList()).filter(o=>o.triggerRef===e);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:t,instance:e})=>$.useCreation(()=>new Cs(e,t.resolveComponent(e.type),xn),[e,t]),Oi=t=>{const{title:e="Variables",variables:n}=t,r=pe.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:e}),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 ud{constructor(e,n){z(this,"operationId");z(this,"operation");z(this,"operationSchema");z(this,"variables",[]);this.operationManager=e,this.instance=n,W.makeAutoObservable(this)}get schemaList(){return this.operationManager.getOperationSchemaList()}async configOperation(e,n){const r=await this.operationManager.retrieveTrigger(e),i=this.operationManager.getOperationSchemaList().find(o=>o.id===(r==null?void 0:r.schemaRef));W.runInAction(()=>{this.operationId=e,this.operation=r,this.operationSchema=i,this.variables=n})}async changeSchema(e){this.operationId&&(await this.operationManager.createOrGetOperation(this.operationId,e),await this.configOperation(this.operationId,this.variables))}}function dd(t){return!!t.operationId}const pd=S.observer(({model:t,onClick:e})=>{var r;const n=(r=t.operationSchema)==null?void 0:r.displayName;return s.jsx(a.Button,{variant:"outline",onClick:e,children:n})}),hd=S.observer(({model:t})=>{const e={operation:t.operation,instance:t.instance,variables:[]};return f.createElement(t.operationSchema.configRender,e)}),xd=S.observer(({model:t})=>{const e=t.schemaList,n=e.map(i=>({label:i.displayName,value:i.id}));async function r(i){await t.changeSchema(e.find(o=>o.id===i))}return s.jsx(a.Select,{label:"Operation",data:n,onChange:r,value:t.operationSchema.id,withinPortal:!0,zIndex:340})}),fd=S.observer(t=>{const[e,{setTrue:n,setFalse:r}]=$.useBoolean(!1),{operationManager:i,operationId:o,instance:l,variables:c}=t,u=$.useCreation(()=>new ud(i,l),[i,l]);return $.useAsyncEffect(async()=>{await u.configOperation(o,c)},[o,u]),dd(u)?s.jsxs(s.Fragment,{children:[s.jsx(pd,{model:u,onClick:n}),s.jsx(a.Modal,{size:600,opened:e,onClose:r,title:"Operation Settings",zIndex:320,children:s.jsxs(a.Stack,{children:[s.jsx(xd,{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(hd,{model:u})}),s.jsx(a.Tabs.Panel,{value:"variables",pt:10,children:s.jsx(Oi,{title:"Variables",variables:u.variables})})]})]})})]}):null});class gd{constructor(e,n){z(this,"triggerId");z(this,"trigger");z(this,"triggerSchema");z(this,"sampleData");this.triggerManager=e,this.instance=n,W.makeAutoObservable(this)}get schemaList(){return this.triggerManager.getTriggerSchemaList()}async configTrigger(e,n){const r=await this.triggerManager.retrieveTrigger(e),i=this.triggerManager.getTriggerSchemaList().find(o=>o.id===(r==null?void 0:r.schemaRef));W.runInAction(()=>{this.triggerId=e,this.trigger=r,this.triggerSchema=i,this.sampleData=n})}async changeSchema(e){this.triggerId&&(await this.triggerManager.createOrGetTrigger(this.triggerId,e),await this.configTrigger(this.triggerId,this.sampleData))}isReady(){return md(this)}}function md(t){return!!t.triggerId&&!!t.triggerSchema}function yd(t,e){return $.useCreation(()=>new gd(t,e),[t,e])}const bd=S.observer(({model:t,onClick:e})=>{const n=t.triggerSchema.nameRender,r={trigger:t.trigger,instance:t.instance,sampleData:t.sampleData};return s.jsx(a.Button,{variant:"outline",onClick:e,children:f.createElement(n,r)})}),jd=S.observer(({model:t})=>{const e=t.schemaList,n=e.map(i=>({label:i.displayName,value:i.id}));async function r(i){await t.changeSchema(e.find(o=>o.id===i))}return s.jsx(a.Select,{label:"Trigger",data:n,value:t.triggerSchema.id,onChange:r})}),vd=S.observer(({model:t})=>{const e={trigger:t.trigger,instance:t.instance,sampleData:t.sampleData};return f.createElement(t.triggerSchema.configRender,e)}),wd=S.observer(t=>{const[e,{setTrue:n,setFalse:r}]=$.useBoolean(!1),i=t.model;return s.jsxs(s.Fragment,{children:[s.jsx(a.Modal,{opened:e,onClose:r,title:"Setup Trigger",zIndex:320,children:s.jsxs(a.Stack,{children:[s.jsx(jd,{model:i}),s.jsx(vd,{model:i}),s.jsx(Oi,{title:"Payload",variables:i.triggerSchema.payload})]})}),s.jsx(bd,{onClick:n,model:i})]})});function Cd(t,e){const[n,r]=f.useState([]);return $.useAsyncEffect(async()=>{const i=await t.getInteractionList();r(i)},[e,t]),n}const Sd=S.observer(({item:t,manager:e,instance:n,sampleData:r,variables:i,onRemove:o})=>{const{triggerRef:l,operationRef:c}=t,u=yd(e.triggerManager,n);if($.useAsyncEffect(async()=>{await u.configTrigger(l,r)},[u,l,r]),u.isReady()){const d=[...u.triggerSchema.payload,...i];return s.jsxs(a.Group,{children:[s.jsx(wd,{model:u}),s.jsx(fd,{instance:n,operationId:c,variables:d,operationManager:e.operationManager}),s.jsx(a.ActionIcon,{"aria-label":"delete-interaction",variant:"filled",color:"red",onClick:()=>o(t),children:s.jsx(_.Trash,{size:16})})]})}return null}),_d=t=>{const[e,n]=f.useState(0),{interactionManager:r,instance:i,sampleData:o,variables:l}=t,c=Cd(r,e),u=async()=>{const x=await r.triggerManager.createOrGetTrigger(pe.randomId(),r.triggerManager.getTriggerSchemaList()[0]),m=await r.operationManager.createOrGetOperation(pe.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}=$.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(Sd,{onRemove:d,instance:i,sampleData:o,variables:l,item:x,manager:t.interactionManager},x.id)),s.jsx(a.Button,{style:{width:"fit-content"},onClick:()=>u(),disabled:p===0,children:"Add interaction"})]})},kd=()=>{const{panel:t,data:e}=dt(),n=t.viz,{vizManager:r}=f.useContext(et),i=t.json,o=$.useCreation(()=>r.getOrCreateInstance(i),[r,i]),l=$.useCreation(()=>new Cs(o,r.resolveComponent(n.type),xn),[o,n.type]);return f.useEffect(()=>o.instanceData.watchItem(null,y.throttle(c=>{t.viz.setConf(c)},100,{leading:!1,trailing:!0})),[o]),{instance:o,vizManager:r,interactionManager:l,sampleData:e,variables:[]}},Td=()=>{const t=kd();return s.jsx(_d,{...t})};function Mt({enabled:t,func_content:e}){return(n,r)=>{if(!t)return n;try{return new Function(`return ${e}`)()(n,r)}catch(i){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${i.message}`),n}}}function Id(t,e){return Object.entries(t).map(([r,i])=>{const o=i.map(T=>T[e]).sort((T,A)=>T-A),l=Nt.quantile(o,.25)??0,c=Nt.quantile(o,.5)??0,u=Nt.quantile(o,.75)??0,d=u-l,p=l-1.5*d,h=u+1.5*d,x=Math.max(o[0],p),m=Math.min(y.last(o)??0,h),j=i.filter(T=>{const A=T[e];return A<x||A>m}).map(T=>[r,T[e],T]);return{name:r,min:x,q1:l,median:c,q3:u,max:m,outliers:j}})}function Dd(t,e){const{x_axis:n,y_axis:r}=t;if(!n.data_key||!r.data_key)return[];const i=D(n.data_key),o=D(r.data_key);if(i.queryID!==o.queryID)throw new Error("Please use the same query for X & Y axis");const l=y.groupBy(e[i.queryID],i.columnKey),c=Id(l,o.columnKey),u=c.map(d=>d.outliers).flat();return[{source:c},{source:u}]}function Md({config:t}){return{...t.legend,data:[{name:"Box",icon:"roundRect",itemStyle:{color:t.color}},{name:"Outlier",icon:"circle",itemStyle:{color:"#ED6A45"}}]}}const Ss=["max","q3","median","q1","min"];function Ad(t){const{color:e}=t;return[{name:"Box",type:"boxplot",itemStyle:{color:e,borderColor:"#2F8CC0",borderWidth:2},emphasis:{disabled:!0},boxWidth:[10,40],datasetIndex:0,encode:{y:Ss,x:"name",itemName:["name"],tooltip:Ss}},{name:"Outlier",type:"scatter",symbolSize:7,itemStyle:{color:"#ED6A45"},emphasis:{scale:2},datasetIndex:1}]}function zd(t){const{outliers:e,min:n,max:r}=t,i=e.filter(c=>c[1]<n).length,o=e.filter(c=>c[1]>r).length,l=(c,u)=>`
62
62
  <tr>
63
63
  <th style="text-align: right; padding: 0 1em;">${c}</th>
64
64
  <td style="text-align: left; padding: 0 1em;">
65
65
  ${u}
66
66
  </td>
67
67
  </tr>
68
- `;return{greater:l("Outliers ⬆",o),less:l("Outliers ⬇",i)}}const Pd=(t,e)=>{const n=_s.map(l=>`
68
+ `;return{greater:l("Outliers ⬆",o),less:l("Outliers ⬇",i)}}const Ed=(t,e)=>{const n=Ss.map(l=>`
69
69
  <tr>
70
70
  <th style="text-align: right; padding: 0 1em;">${y.capitalize(l)}</th>
71
71
  <td style="text-align: left; padding: 0 1em;">
72
72
  ${F(e[l]).format(t.y_axis.label_formatter)}
73
73
  </td>
74
- </tr>`),r=Ed(e);return n.unshift(r.greater),n.push(r.less),`
74
+ </tr>`),r=zd(e);return n.unshift(r.greater),n.push(r.less),`
75
75
  <div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
76
76
  <div style="${Je(t.x_axis.axisLabel.overflow.in_tooltip)}">${e.name}</div>
77
77
  </div>
@@ -80,14 +80,14 @@ Check the top-level render call using <`+M+">.")}return I}}function oc(v,I){{if(
80
80
  ${n.join("")}
81
81
  </tbody>
82
82
  </table>
83
- `},Ld=t=>{try{return F(t).format({trimMantissa:!0,mantissa:2})}catch{return t}};function Bd(t,e){const n=Je(t.x_axis.axisLabel.overflow.in_tooltip),r=[`<tr>
83
+ `},Pd=t=>{try{return F(t).format({trimMantissa:!0,mantissa:2})}catch{return t}};function Ld(t,e){const n=Je(t.x_axis.axisLabel.overflow.in_tooltip),r=[`<tr>
84
84
  <th style="text-align: right; padding: 0 1em;">Outlier</th>
85
85
  <td style="text-align: left; padding: 0 1em;">${e[1]}</td>
86
86
  </tr>
87
87
  `],i=t.tooltip.metrics.map(l=>{const c=D(l.data_key);return`
88
88
  <tr>
89
89
  <th style="text-align: right; padding: 0 1em;">${l.name}</th>
90
- <td style="text-align: left; padding: 0 1em;">${Ld(e[2][c.columnKey])}</td>
90
+ <td style="text-align: left; padding: 0 1em;">${Pd(e[2][c.columnKey])}</td>
91
91
  </tr>`});return r.push(...i),`
92
92
  <div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
93
93
  <div style="${n}">${e[0]}</div>
@@ -97,19 +97,15 @@ Check the top-level render call using <`+M+">.")}return I}}function oc(v,I){{if(
97
97
  ${r.join("")}
98
98
  </tbody>
99
99
  </table>
100
- `}const Od=t=>e=>{const{componentSubType:n,value:r}=e;return n==="scatter"?Bd(t,r):Pd(t,r)};function $d({config:t}){return{trigger:"item",confine:!0,formatter:Od(t)}}const Qt=f.forwardRef(function({value:e,onChange:n,...r},i){return s.jsx(a.TextInput,{ref:i,value:e,onChange:n,...r})}),ks={fontSize:"14px",lineHeight:"32px",color:"#3D3E45",ul:{paddingLeft:"2em",margin:"6px 0 0"},p:{margin:0},a:{WebkitTapHighlightColor:"transparent",color:"rgb(34, 139, 230)",textDecoration:"none","&:hover":{textDecoration:"underline"},"&:active, &:hover":{outlineWidth:0}},table:{tr:{"th, td":{padding:"0 .5em"}}},"table.rich-text-table-render, div.tableWrapper table":{"th, td":{border:"1px solid #eaeaea"},"tr:last-of-type td":{borderBottom:"1px solid #eaeaea"}},".resize-cursor":{cursor:"col-resize"},details:{summary:{listStyle:"none",cursor:"pointer",transition:"color 300ms ease",userSelect:"none"},"summary::-webkit-details-marker":{display:"none"},"summary:hover":{color:"black","&::before":{opacity:1}},"summary::before":{content:'"►"',fontSize:"10px",margin:"0px 5px",opacity:.5,display:"inline-block",transition:"opacity 300ms ease, transform 300ms ease"}},"details[open] summary::before":{transform:"rotate(90deg)"},"details + details":{marginTop:"10px"},blockquote:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45",margin:"0 0 14px"}};function Bi(t,e,n){for(let r=0;;r++){if(r==t.childCount||r==e.childCount)return t.childCount==e.childCount?null:n;let i=t.child(r),o=e.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=Bi(i.content,o.content,n+1);if(l!=null)return l}n+=i.nodeSize}}function Oi(t,e,n,r){for(let i=t.childCount,o=e.childCount;;){if(i==0||o==0)return i==o?null:{a:n,b:r};let l=t.child(--i),c=e.child(--o),u=l.nodeSize;if(l==c){n-=u,r-=u;continue}if(!l.sameMarkup(c))return{a:n,b:r};if(l.isText&&l.text!=c.text){let d=0,h=Math.min(l.text.length,c.text.length);for(;d<h&&l.text[l.text.length-d-1]==c.text[c.text.length-d-1];)d++,n--,r--;return{a:n,b:r}}if(l.content.size||c.content.size){let d=Oi(l.content,c.content,n-1,r-1);if(d)return d}n-=u,r-=u}}class J{constructor(e,n){if(this.content=e,this.size=n||0,n==null)for(let r=0;r<e.length;r++)this.size+=e[r].nodeSize}nodesBetween(e,n,r,i=0,o){for(let l=0,c=0;c<n;l++){let u=this.content[l],d=c+u.nodeSize;if(d>e&&r(u,i+c,o||null,l)!==!1&&u.content.size){let h=c+1;u.nodesBetween(Math.max(0,e-h),Math.min(u.content.size,n-h),r,i+h)}c=d}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,n,r,i){let o="",l=!0;return this.nodesBetween(e,n,(c,u)=>{c.isText?(o+=c.text.slice(Math.max(e,u)-u,n-u),l=!r):c.isLeaf?(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(e){if(!e.size)return this;if(!this.size)return e;let n=this.lastChild,r=e.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<e.content.length;o++)i.push(e.content[o]);return new J(i,this.size+e.size)}cut(e,n=this.size){if(e==0&&n==this.size)return this;let r=[],i=0;if(n>e)for(let o=0,l=0;l<n;o++){let c=this.content[o],u=l+c.nodeSize;u>e&&((l<e||u>n)&&(c.isText?c=c.cut(Math.max(0,e-l),Math.min(c.text.length,n-l)):c=c.cut(Math.max(0,e-l-1),Math.min(c.content.size,n-l-1))),r.push(c),i+=c.nodeSize),l=u}return new J(r,i)}cutByIndex(e,n){return e==n?J.empty:e==0&&n==this.content.length?this:new J(this.content.slice(e,n))}replaceChild(e,n){let r=this.content[e];if(r==n)return this;let i=this.content.slice(),o=this.size+n.nodeSize-r.nodeSize;return i[e]=n,new J(i,o)}addToStart(e){return new J([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new J(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let n=0;n<this.content.length;n++)if(!this.content[n].eq(e.content[n]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let n=this.content[e];if(!n)throw new RangeError("Index "+e+" out of range for "+this);return n}maybeChild(e){return this.content[e]||null}forEach(e){for(let n=0,r=0;n<this.content.length;n++){let i=this.content[n];e(i,r,n),r+=i.nodeSize}}findDiffStart(e,n=0){return Bi(this,e,n)}findDiffEnd(e,n=this.size,r=e.size){return Oi(this,e,n,r)}findIndex(e,n=-1){if(e==0)return fn(0,e);if(e==this.size)return fn(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,i=0;;r++){let o=this.child(r),l=i+o.nodeSize;if(l>=e)return l==e||n>0?fn(r+1,l):fn(r,i);i=l}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,n){if(!n)return J.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new J(n.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return J.empty;let n,r=0;for(let i=0;i<e.length;i++){let o=e[i];r+=o.nodeSize,i&&o.isText&&e[i-1].sameMarkup(o)?(n||(n=e.slice(0,i)),n[n.length-1]=o.withText(n[n.length-1].text+o.text)):n&&n.push(o)}return new J(n||e,r)}static from(e){if(!e)return J.empty;if(e instanceof J)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new J([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}J.empty=new J([],0);const Ts={index:0,offset:0};function fn(t,e){return Ts.index=t,Ts.offset=e,Ts}function Is(t,e){if(t===e)return!0;if(!(t&&typeof t=="object")||!(e&&typeof e=="object"))return!1;let n=Array.isArray(t);if(Array.isArray(e)!=n)return!1;if(n){if(t.length!=e.length)return!1;for(let r=0;r<t.length;r++)if(!Is(t[r],e[r]))return!1}else{for(let r in t)if(!(r in e)||!Is(t[r],e[r]))return!1;for(let r in e)if(!(r in t))return!1}return!0}class Ee{constructor(e,n){this.type=e,this.attrs=n}addToSet(e){let n,r=!1;for(let i=0;i<e.length;i++){let o=e[i];if(this.eq(o))return e;if(this.type.excludes(o.type))n||(n=e.slice(0,i));else{if(o.type.excludes(this.type))return e;!r&&o.type.rank>this.type.rank&&(n||(n=e.slice(0,i)),n.push(this),r=!0),n&&n.push(o)}}return n||(n=e.slice()),r||n.push(this),n}removeFromSet(e){for(let n=0;n<e.length;n++)if(this.eq(e[n]))return e.slice(0,n).concat(e.slice(n+1));return e}isInSet(e){for(let n=0;n<e.length;n++)if(this.eq(e[n]))return!0;return!1}eq(e){return this==e||this.type==e.type&&Is(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let n in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Mark.fromJSON");let r=e.marks[n.type];if(!r)throw new RangeError(`There is no mark type ${n.type} in this schema`);return r.create(n.attrs)}static sameSet(e,n){if(e==n)return!0;if(e.length!=n.length)return!1;for(let r=0;r<e.length;r++)if(!e[r].eq(n[r]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&e.length==0)return Ee.none;if(e instanceof Ee)return[e];let n=e.slice();return n.sort((r,i)=>r.type.rank-i.type.rank),n}}Ee.none=[];class Vd extends Error{}class H{constructor(e,n,r){this.content=e,this.openStart=n,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,n){let r=Vi(this.content,e+this.openStart,n);return r&&new H(r,this.openStart,this.openEnd)}removeBetween(e,n){return new H($i(this.content,e+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,n){if(!n)return 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(e,n.content),r,i)}static maxOpen(e,n=!0){let r=0,i=0;for(let o=e.firstChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=e.lastChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.lastChild)i++;return new H(e,r,i)}}H.empty=new H(J.empty,0,0);function $i(t,e,n){let{index:r,offset:i}=t.findIndex(e),o=t.maybeChild(r),{index:l,offset:c}=t.findIndex(n);if(i==e||o.isText){if(c!=n&&!t.child(l).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(n))}if(r!=l)throw new RangeError("Removing non-flat range");return t.replaceChild(r,o.copy($i(o.content,e-i-1,n-i-1)))}function Vi(t,e,n,r){let{index:i,offset:o}=t.findIndex(e),l=t.maybeChild(i);if(o==e||l.isText)return r&&!r.canReplace(i,i,n)?null:t.cut(0,e).append(n).append(t.cut(e));let c=Vi(l.content,e-o-1,n);return c&&t.replaceChild(i,l.copy(c))}class gn{constructor(e,n){this.schema=e,this.rules=n,this.tags=[],this.styles=[],n.forEach(r=>{r.tag?this.tags.push(r):r.style&&this.styles.push(r)}),this.normalizeLists=!this.tags.some(r=>{if(!/^(ul|ol)\b/.test(r.tag)||!r.node)return!1;let i=e.nodes[r.node];return i.contentMatch.matchType(i)})}parse(e,n={}){let r=new Gi(this,n,!1);return r.addAll(e,n.from,n.to),r.finish()}parseSlice(e,n={}){let r=new Gi(this,n,!0);return r.addAll(e,n.from,n.to),H.maxOpen(r.finish())}matchTag(e,n,r){for(let i=r?this.tags.indexOf(r)+1:0;i<this.tags.length;i++){let o=this.tags[i];if(Fd(e,o.tag)&&(o.namespace===void 0||e.namespaceURI==o.namespace)&&(!o.context||n.matchesContext(o.context))){if(o.getAttrs){let l=o.getAttrs(e);if(l===!1)continue;o.attrs=l||void 0}return o}}}matchStyle(e,n,r,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(e)!=0||l.context&&!r.matchesContext(l.context)||c.length>e.length&&(c.charCodeAt(e.length)!=61||c.slice(e.length+1)!=n))){if(l.getAttrs){let u=l.getAttrs(n);if(u===!1)continue;l.attrs=u||void 0}return l}}}static schemaRules(e){let n=[];function r(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 e.marks){let o=e.marks[i].spec.parseDOM;o&&o.forEach(l=>{r(l=Wi(l)),l.mark||l.ignore||l.clearMark||(l.mark=i)})}for(let i in e.nodes){let o=e.nodes[i].spec.parseDOM;o&&o.forEach(l=>{r(l=Wi(l)),l.node||l.ignore||l.mark||(l.node=i)})}return n}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new gn(e,gn.schemaRules(e)))}}const Ni={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},Nd={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},qi={ol:!0,ul:!0},mn=1,yn=2,Yt=4;function Fi(t,e,n){return e!=null?(e?mn:0)|(e==="full"?yn:0):t&&t.whitespace=="pre"?mn|yn:n&~Yt}class bn{constructor(e,n,r,i,o,l,c){this.type=e,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:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(J.from(e));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&mn)){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!e&&this.match&&(n=n.append(this.match.fillBefore(J.empty,!0))),this.type?this.type.create(this.attrs,n,this.marks):n}popFromStashMark(e){for(let n=this.stashMarks.length-1;n>=0;n--)if(e.eq(this.stashMarks[n]))return this.stashMarks.splice(n,1)[0]}applyPending(e){for(let n=0,r=this.pendingMarks;n<r.length;n++){let i=r[n];(this.type?this.type.allowsMarkType(i.type):Wd(i.type,e))&&!i.isInSet(this.activeMarks)&&(this.activeMarks=i.addToSet(this.activeMarks),this.pendingMarks=i.removeFromSet(this.pendingMarks))}}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!Ni.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class Gi{constructor(e,n,r){this.parser=e,this.options=n,this.isOpen=r,this.open=0;let i=n.topNode,o,l=Fi(null,n.preserveWhitespace,0)|(r?Yt:0);i?o=new bn(i.type,i.attrs,Ee.none,Ee.none,!0,n.topMatch||i.type.contentMatch,l):r?o=new bn(null,null,Ee.none,Ee.none,!0,null,l):o=new bn(e.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(e){if(e.nodeType==3)this.addTextNode(e);else if(e.nodeType==1){let n=e.getAttribute("style");if(!n)this.addElement(e);else{let r=this.readStyles(Gd(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(e);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(e){let n=e.nodeValue,r=this.top;if(r.options&yn||r.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(r.options&mn)r.options&yn?n=n.replace(/\r\n?/g,`
101
- `):n=n.replace(/\r?\n|\r/g," ");else if(n=n.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let i=r.content[r.content.length-1],o=e.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(e)}else this.findInside(e)}addElement(e,n){let r=e.nodeName.toLowerCase(),i;qi.hasOwnProperty(r)&&this.parser.normalizeLists&&qd(e);let o=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(i=this.parser.matchTag(e,this,n));if(o?o.ignore:Nd.hasOwnProperty(r))this.findInside(e),this.ignoreFallback(e);else if(!o||o.skip||o.closeParent){o&&o.closeParent?this.open=Math.max(0,this.open-1):o&&o.skip.nodeType&&(e=o.skip);let l,c=this.top,u=this.needsBlock;if(Ni.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(!e.firstChild){this.leafFallback(e);return}this.addAll(e),l&&this.sync(c),this.needsBlock=u}else this.addElementByRule(e,o,o.consuming===!1?i:void 0)}leafFallback(e){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(`
102
- `))}ignoreFallback(e){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"))}readStyles(e){let n=Ee.none,r=Ee.none;for(let i=0;i<e.length;i+=2)for(let o=void 0;;){let l=this.parser.matchStyle(e[i],e[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(e,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(e):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(e);else if(r)this.addElement(e,r);else if(n.getContent)this.findInside(e),n.getContent(e,this.parser.schema).forEach(u=>this.insertNode(u));else{let u=e;typeof n.contentElement=="string"?u=e.querySelector(n.contentElement):typeof n.contentElement=="function"?u=n.contentElement(e):n.contentElement&&(u=n.contentElement),this.findAround(e,u,!0),this.addAll(u)}i&&this.sync(c)&&this.open--,l&&this.removePendingMark(l,c)}addAll(e,n,r){let i=n||0;for(let o=n?e.childNodes[n]:e.firstChild,l=r==null?null:e.childNodes[r];o!=l;o=o.nextSibling,++i)this.findAtPoint(e,i),this.addDOM(o);this.findAtPoint(e,i)}findPlace(e){let n,r;for(let i=this.open;i>=0;i--){let o=this.nodes[i],l=o.findWrapping(e);if(l&&(!n||n.length>l.length)&&(n=l,r=o,!l.length)||o.solid)break}if(!n)return!1;this.sync(r);for(let i=0;i<n.length;i++)this.enterInner(n[i],null,!1);return!0}insertNode(e){if(e.isInline&&this.needsBlock&&!this.top.type){let n=this.textblockFromContext();n&&this.enterInner(n)}if(this.findPlace(e)){this.closeExtra();let n=this.top;n.applyPending(e.type),n.match&&(n.match=n.match.matchType(e.type));let r=n.activeMarks;for(let i=0;i<e.marks.length;i++)(!n.type||n.type.allowsMarkType(e.marks[i].type))&&(r=e.marks[i].addToSet(r));return n.content.push(e.mark(r)),!0}return!1}enter(e,n,r){let i=this.findPlace(e.create(n));return i&&this.enterInner(e,n,!0,r),i}enterInner(e,n=null,r=!1,i){this.closeExtra();let o=this.top;o.applyPending(e),o.match=o.match&&o.match.matchType(e);let l=Fi(e,i,o.options);o.options&Yt&&o.content.length==0&&(l|=Yt),this.nodes.push(new bn(e,n,o.activeMarks,o.pendingMarks,r,null,l)),this.open++}closeExtra(e=!1){let n=this.nodes.length-1;if(n>this.open){for(;n>this.open;n--)this.nodes[n-1].content.push(this.nodes[n].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(e){for(let n=this.open;n>=0;n--)if(this.nodes[n]==e)return this.open=n,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let n=this.open;n>=0;n--){let r=this.nodes[n].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;n&&e++}return e}findAtPoint(e,n){if(this.find)for(let r=0;r<this.find.length;r++)this.find[r].node==e&&this.find[r].offset==n&&(this.find[r].pos=this.currentPos)}findInside(e){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].pos==null&&e.nodeType==1&&e.contains(this.find[n].node)&&(this.find[n].pos=this.currentPos)}findAround(e,n,r){if(e!=n&&this.find)for(let i=0;i<this.find.length;i++)this.find[i].pos==null&&e.nodeType==1&&e.contains(this.find[i].node)&&n.compareDocumentPosition(this.find[i].node)&(r?2:4)&&(this.find[i].pos=this.currentPos)}findInText(e){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==e&&(this.find[n].pos=this.currentPos-(e.nodeValue.length-this.find[n].offset))}matchesContext(e){if(e.indexOf("|")>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let n=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),o=-(r?r.depth+1:0)+(i?0:1),l=(c,u)=>{for(;c>=0;c--){let d=n[c];if(d==""){if(c==n.length-1||c==0)continue;for(;u>=o;u--)if(l(c-1,u))return!0;return!1}else{let h=u>0||u==0&&i?this.nodes[u].type:r&&u>=o?r.node(u-o).type:null;if(!h||h.name!=d&&h.groups.indexOf(d)==-1)return!1;u--}}return!0};return l(n.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let n=e.depth;n>=0;n--){let r=e.node(n).contentMatchAt(e.indexAfter(n)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let n in this.parser.schema.nodes){let r=this.parser.schema.nodes[n];if(r.isTextblock&&r.defaultAttrs)return r}}addPendingMark(e){let n=Rd(e,this.top.pendingMarks);n&&this.top.stashMarks.push(n),this.top.pendingMarks=e.addToSet(this.top.pendingMarks)}removePendingMark(e,n){for(let r=this.open;r>=0;r--){let i=this.nodes[r];if(i.pendingMarks.lastIndexOf(e)>-1)i.pendingMarks=e.removeFromSet(i.pendingMarks);else{i.activeMarks=e.removeFromSet(i.activeMarks);let l=i.popFromStashMark(e);l&&i.type&&i.type.allowsMarkType(l.type)&&(i.activeMarks=l.addToSet(i.activeMarks))}if(i==n)break}}}function qd(t){for(let e=t.firstChild,n=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&qi.hasOwnProperty(r)&&n?(n.appendChild(e),e=n):r=="li"?n=e:r&&(n=null)}}function Fd(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function Gd(t){let e=/\s*([\w-]+)\s*:\s*([^;]+)/g,n,r=[];for(;n=e.exec(t);)r.push(n[1],n[2].trim());return r}function Wi(t){let e={};for(let n in t)e[n]=t[n];return e}function Wd(t,e){let n=e.schema.nodes;for(let r in n){let i=n[r];if(!i.allowsMarkType(t))continue;let o=[],l=c=>{o.push(c);for(let u=0;u<c.edgeCount;u++){let{type:d,next:h}=c.edge(u);if(d==e||o.indexOf(h)<0&&l(h))return!0}};if(l(i.contentMatch))return!0}}function Rd(t,e){for(let n=0;n<e.length;n++)if(t.eq(e[n]))return e[n]}const Ri=65535,Qi=Math.pow(2,16);function Qd(t,e){return t+e*Qi}function Yi(t){return t&Ri}function Yd(t){return(t-(t&Ri))/Qi}const Ki=1,Ui=2,jn=4,Xi=8;class Ji{constructor(e,n,r){this.pos=e,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&Xi)>0}get deletedBefore(){return(this.delInfo&(Ki|jn))>0}get deletedAfter(){return(this.delInfo&(Ui|jn))>0}get deletedAcross(){return(this.delInfo&jn)>0}}class Ne{constructor(e,n=!1){if(this.ranges=e,this.inverted=n,!e.length&&Ne.empty)return Ne.empty}recover(e){let n=0,r=Yi(e);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+Yd(e)}mapResult(e,n=1){return this._map(e,n,!1)}map(e,n=1){return this._map(e,n,!0)}_map(e,n,r){let 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>e)break;let d=this.ranges[c+o],h=this.ranges[c+l],p=u+d;if(e<=p){let x=d?e==u?-1:e==p?1:n:n,m=u+i+(x<0?0:h);if(r)return m;let j=e==(n<0?u:p)?null:Qd(c/3,e-u),C=e==u?Ui:e==p?Ki:jn;return(n<0?e!=u:e!=p)&&(C|=Xi),new Ji(m,C,j)}i+=h-d}return r?e+i:new Ji(e+i,0,null)}touches(e,n){let r=0,i=Yi(n),o=this.inverted?2:1,l=this.inverted?1:2;for(let c=0;c<this.ranges.length;c+=3){let u=this.ranges[c]-(this.inverted?r:0);if(u>e)break;let d=this.ranges[c+o],h=u+d;if(e<=h&&c==i*3)return!0;r+=this.ranges[c+l]-d}return!1}forEach(e){let n=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i<this.ranges.length;i+=3){let l=this.ranges[i],c=l-(this.inverted?o:0),u=l+(this.inverted?0:o),d=this.ranges[i+n],h=this.ranges[i+r];e(c,c+d,u,u+h),o+=h-d}}invert(){return new Ne(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?Ne.empty:new Ne(e<0?[0,-e,0]:[0,0,e])}}Ne.empty=new Ne([]);const Ds=Object.create(null);class Ie{getMap(){return Ne.empty}merge(e){return null}static fromJSON(e,n){if(!n||!n.stepType)throw new RangeError("Invalid input for Step.fromJSON");let r=Ds[n.stepType];if(!r)throw new RangeError(`No step type ${n.stepType} defined`);return r.fromJSON(e,n)}static jsonID(e,n){if(e in Ds)throw new RangeError("Duplicate use of step JSON ID "+e);return Ds[e]=n,n.prototype.jsonID=e,n}}class he{constructor(e,n){this.doc=e,this.failed=n}static ok(e){return new he(e,null)}static fail(e){return new he(null,e)}static fromReplace(e,n,r,i){try{return he.ok(e.replace(n,r,i))}catch(o){if(o instanceof Vd)return he.fail(o.message);throw o}}}function Ms(t,e,n){let r=[];for(let i=0;i<t.childCount;i++){let o=t.child(i);o.content.size&&(o=o.copy(Ms(o.content,e,o))),o.isInline&&(o=e(o,n,i)),r.push(o)}return J.fromArray(r)}class yt extends Ie{constructor(e,n,r){super(),this.from=e,this.to=n,this.mark=r}apply(e){let n=e.slice(this.from,this.to),r=e.resolve(this.from),i=r.node(r.sharedDepth(this.to)),o=new H(Ms(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(e,this.from,this.to,o)}invert(){return new bt(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new yt(n.pos,r.pos,this.mark)}merge(e){return e instanceof yt&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new yt(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new yt(n.from,n.to,e.markFromJSON(n.mark))}}Ie.jsonID("addMark",yt);class bt extends Ie{constructor(e,n,r){super(),this.from=e,this.to=n,this.mark=r}apply(e){let n=e.slice(this.from,this.to),r=new H(Ms(n.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),n.openStart,n.openEnd);return he.fromReplace(e,this.from,this.to,r)}invert(){return new yt(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new bt(n.pos,r.pos,this.mark)}merge(e){return e instanceof bt&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new bt(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new bt(n.from,n.to,e.markFromJSON(n.mark))}}Ie.jsonID("removeMark",bt);class jt extends Ie{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.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(e,this.pos,this.pos+1,new H(J.from(r),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);if(n){let r=this.mark.addToSet(n.marks);if(r.length==n.marks.length){for(let 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(e){let n=e.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(e,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new jt(n.pos,e.markFromJSON(n.mark))}}Ie.jsonID("addNodeMark",jt);class Kt extends Ie{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.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(e,this.pos,this.pos+1,new H(J.from(r),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);return!n||!this.mark.isInSet(n.marks)?this:new jt(this.pos,this.mark)}map(e){let n=e.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(e,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new Kt(n.pos,e.markFromJSON(n.mark))}}Ie.jsonID("removeNodeMark",Kt);class Ze extends Ie{constructor(e,n,r,i=!1){super(),this.from=e,this.to=n,this.slice=r,this.structure=i}apply(e){return this.structure&&As(e,this.from,this.to)?he.fail("Structure replace would overwrite content"):he.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new Ne([this.from,this.to-this.from,this.slice.size])}invert(e){return new Ze(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deletedAcross&&r.deletedAcross?null:new Ze(n.pos,Math.max(n.pos,r.pos),this.slice)}merge(e){if(!(e instanceof Ze)||e.structure||this.structure)return null;if(this.from+this.slice.size==e.from&&!this.slice.openEnd&&!e.slice.openStart){let n=this.slice.size+e.slice.size==0?H.empty:new H(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new Ze(this.from,this.to+(e.to-e.from),n,this.structure)}else if(e.to==this.from&&!this.slice.openStart&&!e.slice.openEnd){let n=this.slice.size+e.slice.size==0?H.empty:new H(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new Ze(e.from,this.to,n,this.structure)}else return null}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new Ze(n.from,n.to,H.fromJSON(e,n.slice),!!n.structure)}}Ie.jsonID("replace",Ze);class vt extends Ie{constructor(e,n,r,i,o,l,c=!1){super(),this.from=e,this.to=n,this.gapFrom=r,this.gapTo=i,this.slice=o,this.insert=l,this.structure=c}apply(e){if(this.structure&&(As(e,this.from,this.gapFrom)||As(e,this.gapTo,this.to)))return he.fail("Structure gap-replace would overwrite content");let n=e.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(e,this.from,this.to,r):he.fail("Content does not fit in gap")}getMap(){return new Ne([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let n=this.gapTo-this.gapFrom;return new vt(this.from,this.from+this.slice.size+n,this.from+this.insert,this.from+this.insert+n,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1),i=e.map(this.gapFrom,-1),o=e.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 e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number"||typeof n.gapFrom!="number"||typeof n.gapTo!="number"||typeof n.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new vt(n.from,n.to,n.gapFrom,n.gapTo,H.fromJSON(e,n.slice),n.insert,!!n.structure)}}Ie.jsonID("replaceAround",vt);function As(t,e,n){let r=t.resolve(e),i=n-e,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 Kd(t,e,n){return(e==0||t.canReplace(e,t.childCount))&&(n==t.childCount||t.canReplace(0,n))}function Ud(t){let n=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let r=t.depth;;--r){let i=t.$from.node(r),o=t.$from.index(r),l=t.$to.indexAfter(r);if(r<t.depth&&i.canReplace(o,l,n))return r;if(r==0||i.type.spec.isolating||!Kd(i,o,l))break}return null}function vn(t,e,n=1,r){let i=t.resolve(e),o=i.depth-n,l=r&&r[r.length-1]||i.parent;if(o<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!l.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let d=i.depth-1,h=n-2;d>o;d--,h--){let p=i.node(d),x=i.index(d);if(p.type.spec.isolating)return!1;let m=p.content.cutByIndex(x,p.childCount),j=r&&r[h+1];j&&(m=m.replaceChild(0,j.type.create(j.attrs)));let C=r&&r[h]||p;if(!p.canReplace(x+1,p.childCount)||!C.type.validContent(m))return!1}let c=i.indexAfter(o),u=r&&r[0];return i.node(o).canReplaceWith(c,c,u?u.type:i.node(o+1).type)}function Zi(t,e){let n=t.resolve(e),r=n.index();return Xd(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function Xd(t,e){return!!(t&&e&&!t.isLeaf&&t.canAppend(e))}class Ut extends Ie{constructor(e,n,r){super(),this.pos=e,this.attr=n,this.value=r}apply(e){let n=e.nodeAt(this.pos);if(!n)return 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(e,this.pos,this.pos+1,new H(J.from(i),0,n.isLeaf?0:1))}getMap(){return Ne.empty}invert(e){return new Ut(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new Ut(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.pos!="number"||typeof n.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new Ut(n.pos,n.attr,n.value)}}Ie.jsonID("attr",Ut);let Xt=class extends Error{};Xt=function t(e){let n=Error.call(this,e);return n.__proto__=t.prototype,n},Xt.prototype=Object.create(Error.prototype),Xt.prototype.constructor=Xt,Xt.prototype.name="TransformError";const zs=Object.create(null);class ne{constructor(e,n,r){this.$anchor=e,this.$head=n,this.ranges=r||[new Jd(e.min(n),e.max(n))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let n=0;n<e.length;n++)if(e[n].$from.pos!=e[n].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(e,n=H.empty){let r=n.content.lastChild,i=null;for(let c=0;c<n.openEnd;c++)i=r,r=r.lastChild;let o=e.steps.length,l=this.ranges;for(let c=0;c<l.length;c++){let{$from:u,$to:d}=l[c],h=e.mapping.slice(o);e.replaceRange(h.map(u.pos),h.map(d.pos),c?H.empty:n),c==0&&ta(e,o,(r?r.isInline:i&&i.isTextblock)?-1:1)}}replaceWith(e,n){let r=e.steps.length,i=this.ranges;for(let o=0;o<i.length;o++){let{$from:l,$to:c}=i[o],u=e.mapping.slice(r),d=u.map(l.pos),h=u.map(c.pos);o?e.deleteRange(d,h):(e.replaceRangeWith(d,h,n),ta(e,r,n.isInline?-1:1))}}static findFrom(e,n,r=!1){let i=e.parent.inlineContent?new xe(e):At(e.node(0),e.parent,e.pos,e.index(),n,r);if(i)return i;for(let o=e.depth-1;o>=0;o--){let l=n<0?At(e.node(0),e.node(o),e.before(o+1),e.index(o),n,r):At(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,n,r);if(l)return l}return null}static near(e,n=1){return this.findFrom(e,n)||this.findFrom(e,-n)||new it(e.node(0))}static atStart(e){return At(e,e,0,0,1)||new it(e)}static atEnd(e){return At(e,e,e.content.size,e.childCount,-1)||new it(e)}static fromJSON(e,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=zs[n.type];if(!r)throw new RangeError(`No selection type ${n.type} defined`);return r.fromJSON(e,n)}static jsonID(e,n){if(e in zs)throw new RangeError("Duplicate use of selection JSON ID "+e);return zs[e]=n,n.prototype.jsonID=e,n}getBookmark(){return xe.between(this.$anchor,this.$head).getBookmark()}}ne.prototype.visible=!0;class Jd{constructor(e,n){this.$from=e,this.$to=n}}let Hi=!1;function ea(t){!Hi&&!t.parent.inlineContent&&(Hi=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")"))}class xe extends ne{constructor(e,n=e){ea(e),ea(n),super(e,n)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,n){let r=e.resolve(n.map(this.head));if(!r.parent.inlineContent)return ne.near(r);let i=e.resolve(n.map(this.anchor));return new xe(i.parent.inlineContent?i:r,r)}replace(e,n=H.empty){if(super.replace(e,n),n==H.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof xe&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new wn(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,n){if(typeof n.anchor!="number"||typeof n.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new xe(e.resolve(n.anchor),e.resolve(n.head))}static create(e,n,r=n){let i=e.resolve(n);return new this(i,r==n?i:e.resolve(r))}static between(e,n,r){let i=e.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 e.parent.inlineContent||(i==0?e=n:(e=(ne.findFrom(e,-r,!0)||ne.findFrom(e,r,!0)).$anchor,e.pos<n.pos!=i<0&&(e=n))),new xe(e,n)}}ne.jsonID("text",xe);class wn{constructor(e,n){this.anchor=e,this.head=n}map(e){return new wn(e.map(this.anchor),e.map(this.head))}resolve(e){return xe.between(e.resolve(this.anchor),e.resolve(this.head))}}class Pe extends ne{constructor(e){let n=e.nodeAfter,r=e.node(0).resolve(e.pos+n.nodeSize);super(e,r),this.node=n}map(e,n){let{deleted:r,pos:i}=n.mapResult(this.anchor),o=e.resolve(i);return r?ne.near(o):new Pe(o)}content(){return new H(J.from(this.node),0,0)}eq(e){return e instanceof Pe&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new Es(this.anchor)}static fromJSON(e,n){if(typeof n.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new Pe(e.resolve(n.anchor))}static create(e,n){return new Pe(e.resolve(n))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}}Pe.prototype.visible=!1,ne.jsonID("node",Pe);class Es{constructor(e){this.anchor=e}map(e){let{deleted:n,pos:r}=e.mapResult(this.anchor);return n?new wn(r,r):new Es(r)}resolve(e){let n=e.resolve(this.anchor),r=n.nodeAfter;return r&&Pe.isSelectable(r)?new Pe(n):ne.near(n)}}class it extends ne{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,n=H.empty){if(n==H.empty){e.delete(0,e.doc.content.size);let r=ne.atStart(e.doc);r.eq(e.selection)||e.setSelection(r)}else super.replace(e,n)}toJSON(){return{type:"all"}}static fromJSON(e){return new it(e)}map(e){return new it(e)}eq(e){return e instanceof it}getBookmark(){return Zd}}ne.jsonID("all",it);const Zd={map(){return this},resolve(t){return new it(t)}};function At(t,e,n,r,i,o=!1){if(e.inlineContent)return xe.create(t,n);for(let l=r-(i>0?0:1);i>0?l<e.childCount:l>=0;l+=i){let c=e.child(l);if(c.isAtom){if(!o&&Pe.isSelectable(c))return Pe.create(t,n-(i<0?c.nodeSize:0))}else{let u=At(t,c,n+i,i<0?c.childCount:0,i,o);if(u)return u}n+=c.nodeSize*i}return null}function ta(t,e,n){let r=t.steps.length-1;if(r<e)return;let i=t.steps[r];if(!(i instanceof Ze||i instanceof vt))return;let o=t.mapping.maps[r],l;o.forEach((c,u,d,h)=>{l==null&&(l=h)}),t.setSelection(ne.near(t.doc.resolve(l),n))}function na(t,e){return!e||!t?t:t.bind(e)}class Cn{constructor(e,n,r){this.name=e,this.init=na(n.init,r),this.apply=na(n.apply,r)}}new Cn("doc",{init(t){return t.doc||t.schema.topNodeType.createAndFill()},apply(t){return t.doc}}),new Cn("selection",{init(t,e){return t.selection||ne.atStart(e.doc)},apply(t){return t.selection}}),new Cn("storedMarks",{init(t){return t.storedMarks||null},apply(t,e,n,r){return r.selection.$cursor?t.storedMarks:null}}),new Cn("scrollToSelection",{init(){return 0},apply(t,e){return t.scrolledIntoView?e+1:e}});function sa(t,e,n){for(let r in t){let i=t[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=sa(i,e,{})),n[r]=i}return n}class Jt{constructor(e){this.spec=e,this.props={},e.props&&sa(e.props,this,this.props),this.key=e.key?e.key.key:ra("plugin")}getState(e){return e[this.key]}}const Ps=Object.create(null);function ra(t){return t in Ps?t+"$"+ ++Ps[t]:(Ps[t]=0,t+"$")}class Zt{constructor(e="key"){this.key=ra(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}function ia(t){const{state:e,transaction:n}=t;let{selection:r}=n,{doc:i}=n,{storedMarks:o}=n;return{...e,apply:e.apply.bind(e),applyTransaction:e.applyTransaction.bind(e),filterTransaction:e.filterTransaction,plugins:e.plugins,schema:e.schema,reconfigure:e.reconfigure.bind(e),toJSON:e.toJSON.bind(e),get storedMarks(){return o},get selection(){return r},get doc(){return i},get tr(){return r=n.selection,i=n.doc,o=n.storedMarks,n}}}class Hd{constructor(e){this.editor=e.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=e.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){const{rawCommands:e,editor:n,state:r}=this,{view:i}=n,{tr:o}=r,l=this.buildProps(o);return Object.fromEntries(Object.entries(e).map(([c,u])=>[c,(...h)=>{const p=u(...h)(l);return!o.getMeta("preventDispatch")&&!this.hasCustomState&&i.dispatch(o),p}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,n=!0){const{rawCommands:r,editor:i,state:o}=this,{view:l}=i,c=[],u=!!e,d=e||o.tr,h=()=>(!u&&n&&!d.getMeta("preventDispatch")&&!this.hasCustomState&&l.dispatch(d),c.every(x=>x===!0)),p={...Object.fromEntries(Object.entries(r).map(([x,m])=>[x,(...C)=>{const T=this.buildProps(d,n),A=m(...C)(T);return c.push(A),p}])),run:h};return p}createCan(e){const{rawCommands:n,state:r}=this,i=!1,o=e||r.tr,l=this.buildProps(o,i);return{...Object.fromEntries(Object.entries(n).map(([u,d])=>[u,(...h)=>d(...h)({...l,dispatch:void 0})])),chain:()=>this.createChain(o,i)}}buildProps(e,n=!0){const{rawCommands:r,editor:i,state:o}=this,{view:l}=i;o.storedMarks&&e.setStoredMarks(o.storedMarks);const c={tr:e,editor:i,view:l,state:ia({state:o,transaction:e}),dispatch:n?()=>{}:void 0,chain:()=>this.createChain(e),can:()=>this.createCan(e),get commands(){return Object.fromEntries(Object.entries(r).map(([u,d])=>[u,(...h)=>d(...h)(c)]))}};return c}}function dt(t,e,n){return t.config[e]===void 0&&t.parent?dt(t.parent,e,n):typeof t.config[e]=="function"?t.config[e].bind({...n,parent:t.parent?dt(t.parent,e,n):null}):t.config[e]}function ep(t){const e=t.filter(i=>i.type==="extension"),n=t.filter(i=>i.type==="node"),r=t.filter(i=>i.type==="mark");return{baseExtensions:e,nodeExtensions:n,markExtensions:r}}function je(t,e){if(typeof t=="string"){if(!e.nodes[t])throw Error(`There is no node type named '${t}'. Maybe you forgot to add the extension?`);return e.nodes[t]}return t}function tp(t){return typeof t=="function"}function zt(t,e=void 0,...n){return tp(t)?e?t.bind(e)(...n):t(...n):t}function np(t){return Object.prototype.toString.call(t)==="[object RegExp]"}function sp(t){return Object.prototype.toString.call(t).slice(8,-1)}function Ls(t){return sp(t)!=="Object"?!1:t.constructor===Object&&Object.getPrototypeOf(t)===Object.prototype}function aa(t,e){const n={...t};return Ls(t)&&Ls(e)&&Object.keys(e).forEach(r=>{Ls(e[r])?r in t?n[r]=aa(t[r],e[r]):Object.assign(n,{[r]:e[r]}):Object.assign(n,{[r]:e[r]})}),n}class He{constructor(e={}){this.type="extension",this.name="extension",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=zt(dt(this,"addOptions",{name:this.name}))),this.storage=zt(dt(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new He(e)}configure(e={}){const n=this.extend();return n.options=aa(this.options,e),n.storage=zt(dt(n,"addStorage",{name:n.name,options:n.options})),n}extend(e={}){const n=new He(e);return n.parent=this,this.child=n,n.name=e.name?e.name:n.parent.name,e.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${n.name}".`),n.options=zt(dt(n,"addOptions",{name:n.name})),n.storage=zt(dt(n,"addStorage",{name:n.name,options:n.options})),n}}function rp(t,e,n){const{from:r,to:i}=e,{blockSeparator:o=`
103
-
104
- `,textSerializers:l={}}=n||{};let c="",u=!0;return t.nodesBetween(r,i,(d,h,p,x)=>{var m;const j=l==null?void 0:l[d.type.name];j?(d.isBlock&&!u&&(c+=o,u=!0),p&&(c+=j({node:d,pos:h,parent:p,index:x,range:e}))):d.isText?(c+=(m=d==null?void 0:d.text)===null||m===void 0?void 0:m.slice(Math.max(r,h)-h,i-h),u=!1):d.isBlock&&!u&&(c+=o,u=!0)}),c}function ip(t){return Object.fromEntries(Object.entries(t.nodes).filter(([,e])=>e.spec.toText).map(([e,n])=>[e,n.spec.toText]))}He.create({name:"clipboardTextSerializer",addProseMirrorPlugins(){return[new Jt({key:new Zt("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:t}=this,{state:e,schema:n}=t,{doc:r,selection:i}=e,{ranges:o}=i,l=Math.min(...o.map(h=>h.$from.pos)),c=Math.max(...o.map(h=>h.$to.pos)),u=ip(n);return rp(r,{from:l,to:c},{textSerializers:u})}}})]}});const ap=()=>({editor:t,view:e})=>(requestAnimationFrame(()=>{var n;t.isDestroyed||(e.dom.blur(),(n=window==null?void 0:window.getSelection())===null||n===void 0||n.removeAllRanges())}),!0),op=(t=!1)=>({commands:e})=>e.setContent("",t),lp=()=>({state:t,tr:e,dispatch:n})=>{const{selection:r}=e,{ranges:i}=r;return n&&i.forEach(({$from:o,$to:l})=>{t.doc.nodesBetween(o.pos,l.pos,(c,u)=>{if(c.type.isText)return;const{doc:d,mapping:h}=e,p=d.resolve(h.map(u)),x=d.resolve(h.map(u+c.nodeSize)),m=p.blockRange(x);if(!m)return;const j=Ud(m);if(c.type.isTextblock){const{defaultType:C}=p.parent.contentMatchAt(p.index());e.setNodeMarkup(m.start,C)}(j||j===0)&&e.lift(m,j)})}),!0},cp=t=>e=>t(e),up=()=>({state:t,dispatch:e})=>ge.createParagraphNear(t,e),dp=()=>({tr:t,dispatch:e})=>{const{selection:n}=t,r=n.$anchor.node();if(r.content.size>0)return!1;const i=t.selection.$anchor;for(let o=i.depth;o>0;o-=1)if(i.node(o).type===r.type){if(e){const c=i.before(o),u=i.after(o);t.delete(c,u).scrollIntoView()}return!0}return!1},pp=t=>({tr:e,state:n,dispatch:r})=>{const i=je(t,n.schema),o=e.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);e.delete(u,d).scrollIntoView()}return!0}return!1},hp=t=>({tr:e,dispatch:n})=>{const{from:r,to:i}=t;return n&&e.delete(r,i),!0},xp=()=>({state:t,dispatch:e})=>ge.deleteSelection(t,e),fp=()=>({commands:t})=>t.keyboardShortcut("Enter"),gp=()=>({state:t,dispatch:e})=>ge.exitCode(t,e);function Sn(t,e,n={strict:!0}){const r=Object.keys(e);return r.length?r.every(i=>n.strict?e[i]===t[i]:np(e[i])?e[i].test(t[i]):e[i]===t[i]):!0}function Bs(t,e,n={}){return t.find(r=>r.type===e&&Sn(r.attrs,n))}function mp(t,e,n={}){return!!Bs(t,e,n)}function oa(t,e,n={}){if(!t||!e)return;let r=t.parent.childAfter(t.parentOffset);if(t.parentOffset===r.offset&&r.offset!==0&&(r=t.parent.childBefore(t.parentOffset)),!r.node)return;const i=Bs([...r.node.marks],e,n);if(!i)return;let o=r.index,l=t.start()+r.offset,c=o+1,u=l+r.node.nodeSize;for(Bs([...r.node.marks],e,n);o>0&&i.isInSet(t.parent.child(o-1).marks);)o-=1,l-=t.parent.child(o).nodeSize;for(;c<t.parent.childCount&&mp([...t.parent.child(c).marks],e,n);)u+=t.parent.child(c).nodeSize,c+=1;return{from:l,to:u}}function pt(t,e){if(typeof t=="string"){if(!e.marks[t])throw Error(`There is no mark type named '${t}'. Maybe you forgot to add the extension?`);return e.marks[t]}return t}const yp=(t,e={})=>({tr:n,state:r,dispatch:i})=>{const o=pt(t,r.schema),{doc:l,selection:c}=n,{$from:u,from:d,to:h}=c;if(i){const p=oa(u,o,e);if(p&&p.from<=d&&p.to>=h){const x=xe.create(l,p.from,p.to);n.setSelection(x)}}return!0},bp=t=>e=>{const n=typeof t=="function"?t(e):t;for(let r=0;r<n.length;r+=1)if(n[r](e))return!0;return!1};function la(t){return t instanceof xe}function wt(t=0,e=0,n=0){return Math.min(Math.max(t,e),n)}function jp(t,e=null){if(!e)return null;const n=ne.atStart(t),r=ne.atEnd(t);if(e==="start"||e===!0)return n;if(e==="end")return r;const i=n.from,o=r.to;return e==="all"?xe.create(t,wt(0,i,o),wt(t.content.size,i,o)):xe.create(t,wt(e,i,o),wt(e,i,o))}function Os(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}const vp=(t=null,e={})=>({editor:n,view:r,tr:i,dispatch:o})=>{e={scrollIntoView:!0,...e};const l=()=>{Os()&&r.dom.focus(),requestAnimationFrame(()=>{n.isDestroyed||(r.focus(),e!=null&&e.scrollIntoView&&n.commands.scrollIntoView())})};if(r.hasFocus()&&t===null||t===!1)return!0;if(o&&t===null&&!la(n.state.selection))return l(),!0;const c=jp(i.doc,t)||n.state.selection,u=n.state.selection.eq(c);return o&&(u||i.setSelection(c),u&&i.storedMarks&&i.setStoredMarks(i.storedMarks),l()),!0},wp=(t,e)=>n=>t.every((r,i)=>e(r,{...n,index:i})),Cp=(t,e)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},t,e);function ca(t){const e=`<body>${t}</body>`;return new window.DOMParser().parseFromString(e,"text/html").body}function _n(t,e,n){if(n={slice:!0,parseOptions:{},...n},typeof t=="object"&&t!==null)try{return Array.isArray(t)&&t.length>0?J.fromArray(t.map(r=>e.nodeFromJSON(r))):e.nodeFromJSON(t)}catch(r){return console.warn("[tiptap warn]: Invalid content.","Passed value:",t,"Error:",r),_n("",e,n)}if(typeof t=="string"){const r=gn.fromSchema(e);return n.slice?r.parseSlice(ca(t),n.parseOptions).content:r.parse(ca(t),n.parseOptions)}return _n("",e,n)}function Sp(t,e,n){const r=t.steps.length-1;if(r<e)return;const i=t.steps[r];if(!(i instanceof Ze||i instanceof vt))return;const o=t.mapping.maps[r];let l=0;o.forEach((c,u,d,h)=>{l===0&&(l=h)}),t.setSelection(ne.near(t.doc.resolve(l),n))}const _p=t=>t.toString().startsWith("<"),kp=(t,e,n)=>({tr:r,dispatch:i,editor:o})=>{if(i){n={parseOptions:{},updateSelection:!0,...n};const l=_n(e,o.schema,{parseOptions:{preserveWhitespace:"full",...n.parseOptions}});if(l.toString()==="<>")return!0;let{from:c,to:u}=typeof t=="number"?{from:t,to:t}:t,d=!0,h=!0;if((_p(l)?l:[l]).forEach(x=>{x.check(),d=d?x.isText&&x.marks.length===0:!1,h=h?x.isBlock:!1}),c===u&&h){const{parent:x}=r.doc.resolve(c);x.isTextblock&&!x.type.spec.code&&!x.childCount&&(c-=1,u+=1)}d?Array.isArray(e)?r.insertText(e.map(x=>x.text||"").join(""),c,u):typeof e=="object"&&e&&e.text?r.insertText(e.text,c,u):r.insertText(e,c,u):r.replaceWith(c,u,l),n.updateSelection&&Sp(r,r.steps.length-1,-1)}return!0},Tp=()=>({state:t,dispatch:e})=>ge.joinUp(t,e),Ip=()=>({state:t,dispatch:e})=>ge.joinDown(t,e),Dp=()=>({state:t,dispatch:e})=>ge.joinBackward(t,e),Mp=()=>({state:t,dispatch:e})=>ge.joinForward(t,e);function ua(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function Ap(t){const e=t.split(/-(?!$)/);let n=e[e.length-1];n==="Space"&&(n=" ");let r,i,o,l;for(let c=0;c<e.length-1;c+=1){const u=e[c];if(/^(cmd|meta|m)$/i.test(u))l=!0;else if(/^a(lt)?$/i.test(u))r=!0;else if(/^(c|ctrl|control)$/i.test(u))i=!0;else if(/^s(hift)?$/i.test(u))o=!0;else if(/^mod$/i.test(u))Os()||ua()?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 zp=t=>({editor:e,view:n,tr:r,dispatch:i})=>{const o=Ap(t).split(/-(?!$)/),l=o.find(d=>!["Alt","Ctrl","Meta","Shift"].includes(d)),c=new KeyboardEvent("keydown",{key:l==="Space"?" ":l,altKey:o.includes("Alt"),ctrlKey:o.includes("Ctrl"),metaKey:o.includes("Meta"),shiftKey:o.includes("Shift"),bubbles:!0,cancelable:!0}),u=e.captureTransaction(()=>{n.someProp("handleKeyDown",d=>d(n,c))});return u==null||u.steps.forEach(d=>{const h=d.map(r.mapping);h&&i&&r.maybeStep(h)}),!0};function $s(t,e,n={}){const{from:r,to:i,empty:o}=t.selection,l=e?je(e,t.schema):null,c=[];t.doc.nodesBetween(r,i,(p,x)=>{if(p.isText)return;const m=Math.max(r,x),j=Math.min(i,x+p.nodeSize);c.push({node:p,from:m,to:j})});const u=i-r,d=c.filter(p=>l?l.name===p.node.type.name:!0).filter(p=>Sn(p.node.attrs,n,{strict:!1}));return o?!!d.length:d.reduce((p,x)=>p+x.to-x.from,0)>=u}const Ep=(t,e={})=>({state:n,dispatch:r})=>{const i=je(t,n.schema);return $s(n,i,e)?ge.lift(n,r):!1},Pp=()=>({state:t,dispatch:e})=>ge.liftEmptyBlock(t,e),Lp=t=>({state:e,dispatch:n})=>{const r=je(t,e.schema);return rs.liftListItem(r)(e,n)},Bp=()=>({state:t,dispatch:e})=>ge.newlineInCode(t,e);function da(t,e){return e.nodes[t]?"node":e.marks[t]?"mark":null}function pa(t,e){const n=typeof e=="string"?[e]:e;return Object.keys(t).reduce((r,i)=>(n.includes(i)||(r[i]=t[i]),r),{})}const Op=(t,e)=>({tr:n,state:r,dispatch:i})=>{let o=null,l=null;const c=da(typeof t=="string"?t:t.name,r.schema);return c?(c==="node"&&(o=je(t,r.schema)),c==="mark"&&(l=pt(t,r.schema)),i&&n.selection.ranges.forEach(u=>{r.doc.nodesBetween(u.$from.pos,u.$to.pos,(d,h)=>{o&&o===d.type&&n.setNodeMarkup(h,void 0,pa(d.attrs,e)),l&&d.marks.length&&d.marks.forEach(p=>{l===p.type&&n.addMark(h,h+d.nodeSize,l.create(pa(p.attrs,e)))})})}),!0):!1},$p=()=>({tr:t,dispatch:e})=>(e&&t.scrollIntoView(),!0),Vp=()=>({tr:t,commands:e})=>e.setTextSelection({from:0,to:t.doc.content.size}),Np=()=>({state:t,dispatch:e})=>ge.selectNodeBackward(t,e),qp=()=>({state:t,dispatch:e})=>ge.selectNodeForward(t,e),Fp=()=>({state:t,dispatch:e})=>ge.selectParentNode(t,e),Gp=()=>({state:t,dispatch:e})=>ge.selectTextblockEnd(t,e),Wp=()=>({state:t,dispatch:e})=>ge.selectTextblockStart(t,e);function Rp(t,e,n={}){return _n(t,e,{slice:!1,parseOptions:n})}const Qp=(t,e=!1,n={})=>({tr:r,editor:i,dispatch:o})=>{const{doc:l}=r,c=Rp(t,i.schema,n);return o&&r.replaceWith(0,l.content.size,c).setMeta("preventUpdate",!e),!0};function Yp(t){for(let e=0;e<t.edgeCount;e+=1){const{type:n}=t.edge(e);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}function Kp(t,e){for(let n=t.depth;n>0;n-=1){const r=t.node(n);if(e(r))return{pos:n>0?t.before(n):0,start:t.start(n),depth:n,node:r}}}function Vs(t){return e=>Kp(e.$from,t)}function Up(t,e){const n=pt(e,t.schema),{from:r,to:i,empty:o}=t.selection,l=[];o?(t.storedMarks&&l.push(...t.storedMarks),l.push(...t.selection.$head.marks())):t.doc.nodesBetween(r,i,u=>{l.push(...u.marks)});const c=l.find(u=>u.type.name===n.name);return c?{...c.attrs}:{}}function kn(t,e,n){return Object.fromEntries(Object.entries(n).filter(([r])=>{const i=t.find(o=>o.type===e&&o.name===r);return i?i.attribute.keepOnSplit:!1}))}function Xp(t,e,n={}){const{empty:r,ranges:i}=t.selection,o=e?pt(e,t.schema):null;if(r)return!!(t.storedMarks||t.selection.$from.marks()).filter(p=>o?o.name===p.type.name:!0).find(p=>Sn(p.attrs,n,{strict:!1}));let l=0;const c=[];if(i.forEach(({$from:p,$to:x})=>{const m=p.pos,j=x.pos;t.doc.nodesBetween(m,j,(C,T)=>{if(!C.isText&&!C.marks.length)return;const A=Math.max(m,T),L=Math.min(j,T+C.nodeSize),Y=L-A;l+=Y,c.push(...C.marks.map(se=>({mark:se,from:A,to:L})))})}),l===0)return!1;const u=c.filter(p=>o?o.name===p.mark.type.name:!0).filter(p=>Sn(p.mark.attrs,n,{strict:!1})).reduce((p,x)=>p+x.to-x.from,0),d=c.filter(p=>o?p.mark.type!==o&&p.mark.type.excludes(o):!0).reduce((p,x)=>p+x.to-x.from,0);return(u>0?u+d:u)>=l}function ha(t,e){const{nodeExtensions:n}=ep(e),r=n.find(l=>l.name===t);if(!r)return!1;const i={name:r.name,options:r.options,storage:r.storage},o=zt(dt(r,"group",i));return typeof o!="string"?!1:o.split(" ").includes("list")}function Jp(t,e,n){var r;const{selection:i}=e;let o=null;if(la(i)&&(o=i.$cursor),o){const c=(r=t.storedMarks)!==null&&r!==void 0?r:o.marks();return!!n.isInSet(c)||!c.some(u=>u.type.excludes(n))}const{ranges:l}=i;return l.some(({$from:c,$to:u})=>{let d=c.depth===0?t.doc.inlineContent&&t.doc.type.allowsMarkType(n):!1;return t.doc.nodesBetween(c.pos,u.pos,(h,p,x)=>{if(d)return!1;if(h.isInline){const m=!x||x.type.allowsMarkType(n),j=!!n.isInSet(h.marks)||!h.marks.some(C=>C.type.excludes(n));d=m&&j}return!d}),d})}const Zp=(t,e={})=>({tr:n,state:r,dispatch:i})=>{const{selection:o}=n,{empty:l,ranges:c}=o,u=pt(t,r.schema);if(i)if(l){const d=Up(r,u);n.addStoredMark(u.create({...d,...e}))}else c.forEach(d=>{const h=d.$from.pos,p=d.$to.pos;r.doc.nodesBetween(h,p,(x,m)=>{const j=Math.max(m,h),C=Math.min(m+x.nodeSize,p);x.marks.find(A=>A.type===u)?x.marks.forEach(A=>{u===A.type&&n.addMark(j,C,u.create({...A.attrs,...e}))}):n.addMark(j,C,u.create(e))})});return Jp(r,n,u)},Hp=(t,e)=>({tr:n})=>(n.setMeta(t,e),!0),eh=(t,e={})=>({state:n,dispatch:r,chain:i})=>{const o=je(t,n.schema);return o.isTextblock?i().command(({commands:l})=>ge.setBlockType(o,e)(n)?!0:l.clearNodes()).command(({state:l})=>ge.setBlockType(o,e)(l,r)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},th=t=>({tr:e,dispatch:n})=>{if(n){const{doc:r}=e,i=wt(t,0,r.content.size),o=Pe.create(r,i);e.setSelection(o)}return!0},nh=t=>({tr:e,dispatch:n})=>{if(n){const{doc:r}=e,{from:i,to:o}=typeof t=="number"?{from:t,to:t}:t,l=xe.atStart(r).from,c=xe.atEnd(r).to,u=wt(i,l,c),d=wt(o,l,c),h=xe.create(r,u,d);e.setSelection(h)}return!0},sh=t=>({state:e,dispatch:n})=>{const r=je(t,e.schema);return rs.sinkListItem(r)(e,n)};function xa(t,e){const n=t.storedMarks||t.selection.$to.parentOffset&&t.selection.$from.marks();if(n){const r=n.filter(i=>e==null?void 0:e.includes(i.type.name));t.tr.ensureMarks(r)}}const rh=({keepMarks:t=!0}={})=>({tr:e,state:n,dispatch:r,editor:i})=>{const{selection:o,doc:l}=e,{$from:c,$to:u}=o,d=i.extensionManager.attributes,h=kn(d,c.node().type.name,c.node().attrs);if(o instanceof Pe&&o.node.isBlock)return!c.parentOffset||!vn(l,c.pos)?!1:(r&&(t&&xa(n,i.extensionManager.splittableMarks),e.split(c.pos).scrollIntoView()),!0);if(!c.parent.isBlock)return!1;if(r){const p=u.parentOffset===u.parent.content.size;o instanceof xe&&e.deleteSelection();const x=c.depth===0?void 0:Yp(c.node(-1).contentMatchAt(c.indexAfter(-1)));let m=p&&x?[{type:x,attrs:h}]:void 0,j=vn(e.doc,e.mapping.map(c.pos),1,m);if(!m&&!j&&vn(e.doc,e.mapping.map(c.pos),1,x?[{type:x}]:void 0)&&(j=!0,m=x?[{type:x,attrs:h}]:void 0),j&&(e.split(e.mapping.map(c.pos),1,m),x&&!p&&!c.parentOffset&&c.parent.type!==x)){const C=e.mapping.map(c.before()),T=e.doc.resolve(C);c.node(-1).canReplaceWith(T.index(),T.index()+1,x)&&e.setNodeMarkup(e.mapping.map(c.before()),x)}t&&xa(n,i.extensionManager.splittableMarks),e.scrollIntoView()}return!0},ih=t=>({tr:e,state:n,dispatch:r,editor:i})=>{var o;const l=je(t,n.schema),{$from:c,$to:u}=n.selection,d=n.selection.node;if(d&&d.isBlock||c.depth<2||!c.sameParent(u))return!1;const h=c.node(-1);if(h.type!==l)return!1;const p=i.extensionManager.attributes;if(c.parent.content.size===0&&c.node(-1).childCount===c.indexAfter(-1)){if(c.depth===2||c.node(-3).type!==l||c.index(-2)!==c.node(-2).childCount-1)return!1;if(r){let T=J.empty;const A=c.index(-1)?1:c.index(-2)?2:3;for(let ue=c.depth-A;ue>=c.depth-3;ue-=1)T=J.from(c.node(ue).copy(T));const L=c.indexAfter(-1)<c.node(-2).childCount?1:c.indexAfter(-2)<c.node(-3).childCount?2:3,Y=kn(p,c.node().type.name,c.node().attrs),se=((o=l.contentMatch.defaultType)===null||o===void 0?void 0:o.createAndFill(Y))||void 0;T=T.append(J.from(l.createAndFill(null,se)||void 0));const Q=c.before(c.depth-(A-1));e.replace(Q,c.after(-L),new H(T,4-A,0));let ie=-1;e.doc.nodesBetween(Q,e.doc.content.size,(ue,fe)=>{if(ie>-1)return!1;ue.isTextblock&&ue.content.size===0&&(ie=fe+1)}),ie>-1&&e.setSelection(xe.near(e.doc.resolve(ie))),e.scrollIntoView()}return!0}const x=u.pos===c.end()?h.contentMatchAt(0).defaultType:null,m=kn(p,h.type.name,h.attrs),j=kn(p,c.node().type.name,c.node().attrs);e.delete(c.pos,u.pos);const C=x?[{type:l,attrs:m},{type:x,attrs:j}]:[{type:l,attrs:m}];if(!vn(e.doc,c.pos,2))return!1;if(r){const{selection:T,storedMarks:A}=n,{splittableMarks:L}=i.extensionManager,Y=A||T.$to.parentOffset&&T.$from.marks();if(e.split(c.pos,2,C).scrollIntoView(),!Y||!r)return!0;const se=Y.filter(Q=>L.includes(Q.type.name));e.ensureMarks(se)}return!0},Ns=(t,e)=>{const n=Vs(l=>l.type===e)(t.selection);if(!n)return!0;const r=t.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(r===void 0)return!0;const i=t.doc.nodeAt(r);return n.node.type===(i==null?void 0:i.type)&&Zi(t.doc,n.pos)&&t.join(n.pos),!0},qs=(t,e)=>{const n=Vs(l=>l.type===e)(t.selection);if(!n)return!0;const r=t.doc.resolve(n.start).after(n.depth);if(r===void 0)return!0;const i=t.doc.nodeAt(r);return n.node.type===(i==null?void 0:i.type)&&Zi(t.doc,r)&&t.join(r),!0};var ah=Object.freeze({__proto__:null,blur:ap,clearContent:op,clearNodes:lp,command:cp,createParagraphNear:up,deleteCurrentNode:dp,deleteNode:pp,deleteRange:hp,deleteSelection:xp,enter:fp,exitCode:gp,extendMarkRange:yp,first:bp,focus:vp,forEach:wp,insertContent:Cp,insertContentAt:kp,joinUp:Tp,joinDown:Ip,joinBackward:Dp,joinForward:Mp,keyboardShortcut:zp,lift:Ep,liftEmptyBlock:Pp,liftListItem:Lp,newlineInCode:Bp,resetAttributes:Op,scrollIntoView:$p,selectAll:Vp,selectNodeBackward:Np,selectNodeForward:qp,selectParentNode:Fp,selectTextblockEnd:Gp,selectTextblockStart:Wp,setContent:Qp,setMark:Zp,setMeta:Hp,setNode:eh,setNodeSelection:th,setTextSelection:nh,sinkListItem:sh,splitBlock:rh,splitListItem:ih,toggleList:(t,e,n,r={})=>({editor:i,tr:o,state:l,dispatch:c,chain:u,commands:d,can:h})=>{const{extensions:p,splittableMarks:x}=i.extensionManager,m=je(t,l.schema),j=je(e,l.schema),{selection:C,storedMarks:T}=l,{$from:A,$to:L}=C,Y=A.blockRange(L),se=T||C.$to.parentOffset&&C.$from.marks();if(!Y)return!1;const Q=Vs(ie=>ha(ie.type.name,p))(C);if(Y.depth>=1&&Q&&Y.depth-Q.depth<=1){if(Q.node.type===m)return d.liftListItem(j);if(ha(Q.node.type.name,p)&&m.validContent(Q.node.content)&&c)return u().command(()=>(o.setNodeMarkup(Q.pos,m),!0)).command(()=>Ns(o,m)).command(()=>qs(o,m)).run()}return!n||!se||!c?u().command(()=>h().wrapInList(m,r)?!0:d.clearNodes()).wrapInList(m,r).command(()=>Ns(o,m)).command(()=>qs(o,m)).run():u().command(()=>{const ie=h().wrapInList(m,r),ue=se.filter(fe=>x.includes(fe.type.name));return o.ensureMarks(ue),ie?!0:d.clearNodes()}).wrapInList(m,r).command(()=>Ns(o,m)).command(()=>qs(o,m)).run()},toggleMark:(t,e={},n={})=>({state:r,commands:i})=>{const{extendEmptyMarkRange:o=!1}=n,l=pt(t,r.schema);return Xp(r,l,e)?i.unsetMark(l,{extendEmptyMarkRange:o}):i.setMark(l,e)},toggleNode:(t,e,n={})=>({state:r,commands:i})=>{const o=je(t,r.schema),l=je(e,r.schema);return $s(r,o,n)?i.setNode(l):i.setNode(o,n)},toggleWrap:(t,e={})=>({state:n,commands:r})=>{const i=je(t,n.schema);return $s(n,i,e)?r.lift(i):r.wrapIn(i,e)},undoInputRule:()=>({state:t,dispatch:e})=>{const n=t.plugins;for(let r=0;r<n.length;r+=1){const i=n[r];let o;if(i.spec.isInputRules&&(o=i.getState(t))){if(e){const l=t.tr,c=o.transform;for(let u=c.steps.length-1;u>=0;u-=1)l.step(c.steps[u].invert(c.docs[u]));if(o.text){const u=l.doc.resolve(o.from).marks();l.replaceWith(o.from,o.to,t.schema.text(o.text,u))}else l.delete(o.from,o.to)}return!0}}return!1},unsetAllMarks:()=>({tr:t,dispatch:e})=>{const{selection:n}=t,{empty:r,ranges:i}=n;return r||e&&i.forEach(o=>{t.removeMark(o.$from.pos,o.$to.pos)}),!0},unsetMark:(t,e={})=>({tr:n,state:r,dispatch:i})=>{var o;const{extendEmptyMarkRange:l=!1}=e,{selection:c}=n,u=pt(t,r.schema),{$from:d,empty:h,ranges:p}=c;if(!i)return!0;if(h&&l){let{from:x,to:m}=c;const j=(o=d.marks().find(T=>T.type===u))===null||o===void 0?void 0:o.attrs,C=oa(d,u,j);C&&(x=C.from,m=C.to),n.removeMark(x,m,u)}else p.forEach(x=>{n.removeMark(x.$from.pos,x.$to.pos,u)});return n.removeStoredMark(u),!0},updateAttributes:(t,e={})=>({tr:n,state:r,dispatch:i})=>{let o=null,l=null;const c=da(typeof t=="string"?t:t.name,r.schema);return c?(c==="node"&&(o=je(t,r.schema)),c==="mark"&&(l=pt(t,r.schema)),i&&n.selection.ranges.forEach(u=>{const d=u.$from.pos,h=u.$to.pos;r.doc.nodesBetween(d,h,(p,x)=>{o&&o===p.type&&n.setNodeMarkup(x,void 0,{...p.attrs,...e}),l&&p.marks.length&&p.marks.forEach(m=>{if(l===m.type){const j=Math.max(x,d),C=Math.min(x+p.nodeSize,h);n.addMark(j,C,l.create({...m.attrs,...e}))}})})}),!0):!1},wrapIn:(t,e={})=>({state:n,dispatch:r})=>{const i=je(t,n.schema);return ge.wrapIn(i,e)(n,r)},wrapInList:(t,e={})=>({state:n,dispatch:r})=>{const i=je(t,n.schema);return rs.wrapInList(i,e)(n,r)}});He.create({name:"commands",addCommands(){return{...ah}}}),He.create({name:"editable",addProseMirrorPlugins(){return[new Jt({key:new Zt("editable"),props:{editable:()=>this.editor.options.editable}})]}}),He.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:t}=this;return[new Jt({key:new Zt("focusEvents"),props:{handleDOMEvents:{focus:(e,n)=>{t.isFocused=!0;const r=t.state.tr.setMeta("focus",{event:n}).setMeta("addToHistory",!1);return e.dispatch(r),!1},blur:(e,n)=>{t.isFocused=!1;const r=t.state.tr.setMeta("blur",{event:n}).setMeta("addToHistory",!1);return e.dispatch(r),!1}}}})]}}),He.create({name:"keymap",addKeyboardShortcuts(){const t=()=>this.editor.commands.first(({commands:l})=>[()=>l.undoInputRule(),()=>l.command(({tr:c})=>{const{selection:u,doc:d}=c,{empty:h,$anchor:p}=u,{pos:x,parent:m}=p,j=ne.atStart(d).from===x;return!h||!j||!m.type.isTextblock||m.textContent.length?!1:l.clearNodes()}),()=>l.deleteSelection(),()=>l.joinBackward(),()=>l.selectNodeBackward()]),e=()=>this.editor.commands.first(({commands:l})=>[()=>l.deleteSelection(),()=>l.deleteCurrentNode(),()=>l.joinForward(),()=>l.selectNodeForward()]),r={Enter:()=>this.editor.commands.first(({commands:l})=>[()=>l.newlineInCode(),()=>l.createParagraphNear(),()=>l.liftEmptyBlock(),()=>l.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:t,"Mod-Backspace":t,"Shift-Backspace":t,Delete:e,"Mod-Delete":e,"Mod-a":()=>this.editor.commands.selectAll()},i={...r},o={...r,"Ctrl-h":t,"Alt-Backspace":t,"Ctrl-d":e,"Ctrl-Alt-Backspace":e,"Alt-Delete":e,"Alt-d":e,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return Os()||ua()?o:i},addProseMirrorPlugins(){return[new Jt({key:new Zt("clearDocument"),appendTransaction:(t,e,n)=>{if(!(t.some(j=>j.docChanged)&&!e.doc.eq(n.doc)))return;const{empty:i,from:o,to:l}=e.selection,c=ne.atStart(e.doc).from,u=ne.atEnd(e.doc).to;if(i||!(o===c&&l===u)||!(n.doc.textBetween(0,n.doc.content.size," "," ").length===0))return;const p=n.tr,x=ia({state:n,transaction:p}),{commands:m}=new Hd({editor:this.editor,state:x});if(m.clearNodes(),!!p.steps.length)return p}})]}}),He.create({name:"tabindex",addProseMirrorPlugins(){return[new Jt({key:new Zt("tabindex"),props:{attributes:this.editor.isEditable?{tabindex:"0"}:{}}})]}});const fa=He.create({name:"fontSize",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{fontSize:{default:null,parseHTML:t=>t.style.fontSize.replace(/['"]+/g,""),renderHTML:t=>t.fontSize?{style:`font-size: ${t.fontSize}`}:{}}}}]},addCommands(){return{setFontSize:t=>({chain:e})=>e().setMark("textStyle",{fontSize:t}).run(),unsetFontSize:()=>({chain:t})=>t().setMark("textStyle",{fontSize:null}).removeEmptyTextStyle().run()}}}),oh=["8","10","12","14","16","18","20","24","30","36","48","60","72"].map(t=>`${t}px`),lh=[{label:"auto",value:""}].concat(oh.map(t=>({label:t,value:t}))),ch={input:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important"}},uh=({editor:t})=>{const e=t.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:lh,styles:ch,value:e||"",onChange:n=>{const r=n.currentTarget.value;r?t.chain().focus().setFontSize(r).run():t.chain().focus().unsetFontSize().run()}})})},Tn=({value:t,styles:e={}})=>{const n=li.useEditor({extensions:[ci,oi,q.Link,ei,Hr,Jr,si.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),ai,ii,ri,ti.configure({types:["heading","paragraph"]}),Zr.configure({placeholder:"This is placeholder"}),ni,Xr.Color,fa],content:t,editable:!1});f.useEffect(()=>{n==null||n.commands.setContent(t)},[t,n]);const r=f.useMemo(()=>y.defaultsDeep({},{content:ks},e),[e]);return s.jsx(q.RichTextEditor,{editor:n,styles:r,children:s.jsx(q.RichTextEditor.Content,{})})};function dh(){const[t,{open:e,close:n}]=pe.useDisclosure(!1);return s.jsxs(s.Fragment,{children:[s.jsx(a.Modal,{opened:t,onClose:n,title:"About FunctionUtils",zIndex:330,withinPortal:!0,children:s.jsx(Tn,{value:au,styles:{root:{border:"none"},content:{padding:0,table:{marginBottom:0}}}})}),s.jsx(a.Button,{variant:"light",color:"violet",size:"xs",onClick:e,leftIcon:s.jsx(k.IconInfoCircle,{size:16}),children:"About parameter 'utils'"})]})}const ph=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return s.jsx(a.Box,{sx:{position:"relative",flexGrow:1},children:s.jsx(me,{className:"function-editor",height:"100%",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1}}})})},Ht=f.forwardRef(({value:t,onChange:e,label:n,defaultValue:r},i)=>{const[o,l]=f.useState(t),c=()=>{e(o)},u=()=>{l(t)},d=()=>{l(r)};f.useEffect(()=>{l(t)},[t]);const h=o!==t;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(dh,{})}),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:!h,leftIcon:s.jsx(k.IconRecycle,{size:16}),children:"Revert Changes"}),s.jsx(a.Button,{size:"xs",onClick:c,disabled:!h,leftIcon:s.jsx(k.IconDeviceFloppy,{size:16}),children:"Confirm Changes"})]})]}),s.jsx(a.Text,{size:14,children:n}),s.jsx(ph,{value:o,onChange:l})]})}),hh=f.forwardRef(({value:t,onChange:e,label:n,triggerLabel:r="Edit",triggerButtonProps:i={},defaultValue:o},l)=>{const[c,{open:u,close:d}]=pe.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(Ht,{value:t,onChange:e,defaultValue:o,label:n})})}),s.jsx(a.Button,{onClick:u,...i,children:r})]})}),ga=["function aggregation({ queryData }, utils) {",' return "Aggregation Result";',"}"].join(`
105
- `),Et={type:"none",config:{}};function xh(t){const e=Array.from(t).sort((r,i)=>r-i),n=Math.floor(e.length/2);return e.length%2===0?(e[n-1]+e[n])/2:e[n]}function fh(t){const e=Number(t);return isFinite(e)?e:0}function gh(t,e){switch(e.type){case"sum":return y.sum(t);case"mean":return y.mean(t);case"median":return xh(t);case"max":return y.max(t)??0;case"min":return y.min(t)??0;case"quantile":return Nt.quantile(t,e.config.p)??0;case"CV":const n=cn.std(...t),r=cn.mean(...t);return r?n/r:"N/A";case"std":return cn.std(...t);default:return t}}function Fs(t,e){const n=t.map(fh);return gh(n,e)}function mh(t,e,n){try{const r=Rt(t,e);return new Function(`return ${n.config.func}`)()({queryData:r},gt)}catch(r){return console.error(r),r.message}}function In(t,e,n){try{return n.type==="custom"?mh(t,e,n):Fs(rt(t,e),n)}catch(r){return console.error(r),null}}const yh=[{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 bh({label:t,value:e,onChange:n,pt:r="sm"},i){f.useEffect(()=>{typeof e=="string"&&n({type:e,config:{}})},[e,n]);const o=u=>{n(u==="quantile"?{type:"quantile",config:{p:.99}}:u==="custom"?{type:"custom",config:{func:ga}}:{type:u,config:{}})},l=u=>{n({type:"quantile",config:{p:u}})},c=u=>{n({type:"custom",config:{func:u}})};return s.jsxs(a.Group,{grow:!0,noWrap:!0,pt:r,children:[s.jsx(a.Select,{ref:i,label:t,data:yh,value:e.type,onChange:o}),e.type==="quantile"&&s.jsx(a.NumberInput,{label:"p",value:e.config.p,onChange:l,precision:2,min:.05,step:.05,max:1}),e.type==="custom"&&s.jsx(hh,{label:"",triggerLabel:"Edit Function",value:e.config.func,onChange:c,defaultValue:ga,triggerButtonProps:{size:"xs",sx:{flexGrow:0,alignSelf:"center",marginTop:"22px"},leftIcon:s.jsx(k.IconMathFunction,{size:16})}})]})}const Dn=f.forwardRef(bh);function jh({label:t,value:e,onChange:n},r){const[i,o]=f.useState(Array.isArray(e)?[...e]:[]),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,e),[i,e]),d=()=>{n(i.map(x=>x.toString()))},h=a.useMantineTheme(),p=f.useMemo(()=>Object.entries(h.colors).map(([x,m])=>m[6]),[h]);return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{position:"left",ref:r,children:[s.jsx(a.Text,{children:t}),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(C=>(C.splice(m,1,j),[...C]))},swatches:p,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 vh=f.forwardRef(jh);function wh({value:t,onChange:e},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===t),[t,i]);return s.jsxs(a.Group,{position:"apart",spacing:4,ref:n,children:[s.jsx(a.TextInput,{placeholder:"Set any color",value:o?"":t,onChange:l=>e(l.currentTarget.value),rightSection:s.jsx(a.ColorSwatch,{color:o?"transparent":t,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:t,onChange:e,variant:o?"default":"filled",placeholder:"Pick a theme color",icon:s.jsx(a.ColorSwatch,{color:o?t:"transparent",radius:4}),sx:{maxWidth:"46%",flexGrow:1}})]})}const Se=f.forwardRef(wh),Mn=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function Ch({label:t,value:e,onChange:n},r){var l;const[i,o]=f.useState(((l=Mn.find(c=>c.label===e))==null?void 0:l.value)??Mn[0].value);return f.useEffect(()=>{const c=Mn.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:t}),s.jsx(a.Slider,{label:null,marks:Mn,value:i,onChange:o,step:25,placeholder:"Pick a font size",px:"1em",ref:r})]})}const ma=f.forwardRef(Ch);function Sh({label:t,value:e,onChange:n,type:r},i){const[o,l]=f.useState(Array.isArray(e)?[...e]:[]),c=f.useCallback(()=>{l(p=>[...p,""])},[l]),u=f.useCallback(p=>{l(x=>(x.splice(p,1),[...x]))},[l]),d=f.useMemo(()=>!y.isEqual(o.map(String),e.map(String)),[o,e]),h=()=>{n(o.map(p=>r==="number"?Number(p):p.toString()))};return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{position:"left",ref:i,children:[s.jsx(a.Text,{children:t}),s.jsx(a.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!d,onClick:h,children:s.jsx(_.DeviceFloppy,{size:20})})]}),s.jsxs(a.Group,{children:[o.map((p,x)=>s.jsx(a.TextInput,{type:r,value:p,onChange:m=>{const j=m.currentTarget.value;l(C=>(C.splice(x,1,j),[...C]))},rightSection:s.jsx(a.ActionIcon,{onClick:()=>u(x),color:"red",children:s.jsx(_.Trash,{size:14})}),sx:{width:"45%"}})),s.jsx(a.ActionIcon,{onClick:c,color:"blue",variant:"outline",children:s.jsx(_.PlaylistAdd,{size:20})})]})]})}const _h=f.forwardRef(Sh),ya=f.forwardRef(function({value:e,onChange:n},r){const i=e.color.type,o=(c,u)=>{const d=y.cloneDeep(e);y.set(d,c,u),n(d)},l=c=>{if(c==="static"){n({...e,color:{type:"static",staticColor:"#25262B"}});return}n({...e,color:{type:"continuous",colorRange:[],valueRange:[]}})};return s.jsxs(s.Fragment,{children:[s.jsx(a.Divider,{my:"xs",label:"Typography",labelPosition:"center"}),s.jsx(a.Stack,{children:s.jsx(a.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1},value:e.size,onChange:c=>o("size",c.currentTarget.value)})}),s.jsx(a.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:s.jsx(ma,{label:"Font Weight",value:e.weight,onChange:c=>o("weight",c)})}),s.jsx(a.Divider,{my:"xs",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:e.color.type,onChange:l}),i==="static"&&s.jsx(Se,{value:e.color.staticColor,onChange:c=>o("color.staticColor",c)}),i==="continuous"&&s.jsxs(s.Fragment,{children:[s.jsx(_h,{label:"Value Range",value:e.color.valueRange,type:"number",onChange:c=>o("color.valueRange",c)}),s.jsx(vh,{label:"Color Range",value:e.color.colorRange,onChange:c=>o("color.colorRange",c)})]})]})]})});f.forwardRef(function({value:e,onChange:n,withStyle:r=!0},i){const o=(l,c)=>{const u=y.cloneDeep(e);y.set(u,l,c),n(u)};return s.jsxs(a.Box,{px:"sm",py:"md",ref:i,children:[s.jsx(a.Text,{weight:"bold",pb:0,children:e.name}),s.jsx(a.Divider,{my:"xs",label:"Data",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(a.TextInput,{label:"Name",required:!0,value:e.name,onChange:l=>o("name",l.currentTarget.value)}),s.jsx(B,{label:"Data Field",required:!0,value:e.data_field,onChange:l=>o("data_field",l)})]}),s.jsx(Dn,{label:"Aggregation",value:e.aggregation,onChange:l=>o("aggregation",l)}),s.jsx(a.Divider,{my:"xs",label:"Format",labelPosition:"center"}),e.aggregation.type!=="custom"&&s.jsx(Ae,{value:e.formatter,onChange:l=>o("formatter",l)}),r&&s.jsx(ya,{value:e,onChange:n})]})});class kh{constructor({valueRange:e,colorRange:n}){z(this,"mapper");this.mapper=xt.interpolate(e,n)}getColor(e){return this.mapper(e)}}function Th(t){return t===null?"null":t===void 0?"undefined":Array.isArray(t)?`Array(${t.length})`:t.toString()}function at({data_field:t,aggregation:e},n){return In(n,t,e)}function qe({formatter:t,aggregation:e},n){if(!["string","number"].includes(typeof n))return Th(n);if(e.type==="custom")return n;try{return F(n).format(t)}catch(r){return console.error(r),n}}function Ih(t,e){if(t.type==="static")return t.staticColor;if(t.type==="continuous")try{if(typeof e!="number")throw new Error(`[getColorByColorConf] Invalid type of aggregated value: ${e}`);return new kh(t).getColor(e)}catch(n){return console.error(n),"black"}return"black"}function ba(t,e){const{color:n,data_field:r,aggregation:i,size:o,weight:l}=t,c=In(e,r,i),u=qe(t,c);return s.jsx(a.Text,{sx:{fontSize:o,display:"inline"},color:Ih(n,c),weight:l,children:u})}function Dh(t,e){const n={};return t.forEach(r=>{const i=r.name;n[i]=ba(r,e)}),n}function Mh(t){return t.split(" ").map((e,n)=>s.jsxs(f.Fragment,{children:[e," "]},n))}function Ah(t){const n=t.replaceAll("<br />","<br/>").replaceAll(`
106
- `,"<br/>").split("<br/>");return n.map((i,o)=>{const l=[Mh(i)];return o!==n.length-1&&l.push(s.jsx("br",{},`br-${o}`)),l}).flat().filter(i=>i!==void 0)}function Gs(t){return Ah(t)}function en(t,e,n){const r=Dh(e,n),i=/^\{(.+)\}(.*)$/;return t.split("$").map((o,l)=>{const c=i.exec(o);if(!c)return Gs(o);const u=r[c[1]];if(!u)return Gs(o);const d=c[2]??"";return s.jsxs(f.Fragment,{children:[u,Gs(d)]},`${o}-${l}`)})}function zh(t,e){const n={};return t.forEach(r=>{const{name:i,data_field:o,aggregation:l}=r,c=In(e,o,l);n[i]=qe(r,c)}),n}function An(t,e,n){const r=zh(e,n),i=/^\{(.+)\}(.*)$/;return t.split("$").map(o=>{const l=i.exec(o);if(!l)return o;const c=r[l[1]];if(!c)return o;const u=l[2]??"";return`${c}${u}`}).join("")}function Eh(t,e,n){const r=e.reduce((i,o)=>{const l=at(o,n);return i[o.name]=qe(o,l),i},{});return t.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 An(i.template,e,n)},position:"insideEndTop"}}}))}function Ph(t){const e={top:30,left:20,right:15,bottom:25,containLabel:!0};return t.legend.orient==="vertical"&&(e.right=80),e}const ja={axisTick:{show:!0,alignWithLabel:!0,lineStyle:{width:2}},axisLine:{show:!0,lineStyle:{width:3}},splitLine:{show:!1},z:3};function Lh(t){return y.defaultsDeep({},t,ja)}const Bh=Object.freeze(Object.defineProperty({__proto__:null,getXAxis:Lh,xAxis:ja},Symbol.toStringTag,{value:"Module"})),va={axisTick:{show:!1},axisLine:{show:!1,lineStyle:{width:3}},splitLine:{show:!0,lineStyle:{type:"dashed"}}};function Oh(t){return y.defaultsDeep({},t,va)}const Le={...Bh,...Object.freeze(Object.defineProperty({__proto__:null,getYAxis:Oh,yAxis:va},Symbol.toStringTag,{value:"Module"}))};function $h({config:t,data:e,variables:n}){const{x_axis:r,y_axis:i,reference_lines:o}=t,l=Md(t,e),c=Qe(r.axisLabel.overflow.on_axis),u=zd(t);return{grid:Ph(t),dataset:l,legend:Ad({config:t}),tooltip:$d({config:t}),xAxis:[Le.getXAxis({type:"category",name:r.name,nameGap:25,nameLocation:"center",nameTextStyle:{align:"center"},axisLabel:{...r.axisLabel,...c,formatter:Mt(r.axisLabel.formatter)}})],yAxis:[Le.getYAxis({name:i.name,minInterval:1,axisLabel:{formatter:function(d){return F(d).format(i.label_formatter)}}})],series:[...u,...Eh(o,n,e)]}}K.use([P.DataZoomComponent,te.BoxplotChart,P.MarkLineComponent,P.GridComponent,P.LegendComponent,P.TooltipComponent,we.CanvasRenderer]);function Vh({context:t,instance:e}){const{value:n}=O(t.instanceData,"config"),{variables:r}=t,i=t.data,{width:o,height:l}=t.viewport,c=y.defaults({},n,ws),u=Ve({vizManager:t.vizManager,instance:e}),d=$e(u.triggerManager,Ei.id),h=mt(i,c.x_axis.data_key),p=f.useCallback(j=>{const C=y.get(h,j.name,{error:"rowData is not found"});d.forEach(T=>{u.runInteraction(T.id,{...j,rowData:C})})},[h,d,u]),x=f.useMemo(()=>({click:p}),[p]),m=f.useMemo(()=>$h({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:K,option:m,style:Wt(o,l),onEvents:x,notMerge:!0,theme:"merico-light"})})}function Nh({control:t,index:e,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.${e}.name`,control:t,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.${e}.variable_key`,control:t,render:({field:i})=>s.jsx(a.Select,{label:"Value",required:!0,data:r,sx:{flex:1},...i})})]}),s.jsx(b.Controller,{name:`reference_lines.${e}.template`,control:t,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(e),sx:{position:"absolute",top:15,right:5},children:s.jsx(_.Trash,{size:16})})]})}function qh({control:t,watch:e,variables:n}){const{fields:r,append:i,remove:o}=b.useFieldArray({control:t,name:"reference_lines"}),l=e("reference_lines"),c=r.map((h,p)=>({...h,...l[p]})),u=()=>i({name:"",template:"",variable_key:""}),d=f.useMemo(()=>n.map(h=>({label:h.name,value:h.name})),[n]);return s.jsxs(a.Stack,{children:[c.map((h,p)=>s.jsx(Nh,{control:t,index:p,remove:o,variableOptions:d},h.id)),s.jsx(a.Group,{position:"center",mt:"xs",children:s.jsx(a.Button,{onClick:u,children:"Add a Reference Line"})})]})}const Fh=({disabled:t,value:e,onChange:n})=>{const r=i=>{i&&n(i)};return s.jsxs(a.Box,{sx:{position:"relative"},children:[t&&s.jsx(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),s.jsx(me,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},zn=f.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:i,setFalse:o}]=$.useBoolean(),[l,c]=f.useState(t);f.useEffect(()=>{c(t)},[t]);const u=m=>{c({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:j}=l,C={enabled:m,func_content:j};c(C),e(C)},h=()=>{o(),c(t)},p=m=>{c(j=>({...j,func_content:m}))},x=()=>{p(Oe.func_content)};return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"filled",mt:24,onClick:i,sx:{flexGrow:0},children:"Customize Label"}),s.jsx(a.Modal,{size:800,title:"Customize label content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&s.jsxs(a.Stack,{children:[s.jsx(a.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:m=>u(m.currentTarget.checked)}),s.jsx(Fh,{value:l.func_content,onChange:p,disabled:!l.enabled}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:x,color:"red",leftIcon:s.jsx(_.Recycle,{size:20}),children:"Reset"}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:h,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:d,children:"OK"})]})]})]})})]})}),Gh=({control:t,watch:e})=>(e(["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:t,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:t,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:t,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:t,render:({field:n})=>s.jsx(zn,{...n})})]}),s.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>s.jsx(Xe,{...n})})]})),Wh=({control:t,watch:e})=>(e(["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:t,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:t,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:t,render:({field:n})=>s.jsx(Ae,{...n})})]})]})),Rh=({control:t,index:e,remove:n})=>s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`tooltip.metrics.${e}.name`,control:t,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`tooltip.metrics.${e}.data_key`,control:t,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(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),Qh=({control:t,watch:e})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:t,name:"tooltip.metrics"}),o=e("tooltip.metrics"),l=n.map((p,x)=>({...p,...o[x]})),c=()=>r({id:Date.now().toString(),data_key:"",name:""}),u=e("tooltip.metrics.0.id"),[d,h]=f.useState(()=>u??null);return f.useEffect(()=>{u&&h(p=>p!==null?p:u)},[u]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(_.InfoCircle,{size:14,color:"#888"}),s.jsx(a.Text,{size:14,color:"#888",children:"Set additional metrics to show in scatter's tooltip"})]}),s.jsxs(a.Tabs,{value:d,onTabChange:p=>h(p),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((p,x)=>s.jsx(a.Tabs.Tab,{value:p.id,children:p.name?p.name:x},p.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),l.map((p,x)=>s.jsx(a.Tabs.Panel,{value:p.id,children:s.jsx(Rh,{control:t,index:x,remove:i},p.id)},p.id))]})]})};function Yh({control:t,watch:e}){return s.jsx(a.Stack,{children:s.jsx(Qh,{control:t,watch:e})})}const Kh=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}],Uh=({control:t,watch:e})=>{const n=e("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:t,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:t,render:({field:i})=>s.jsx(a.Select,{label:"Orientation",data:Kh,sx:{flex:1},value:i.value.orient,onChange:o=>{r(o,i.onChange)},disabled:!n.show})})})]})};function Xh({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),{variables:r}=t,i=f.useMemo(()=>y.defaults({},e,ws),[e]),{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 h=u(),p=f.useMemo(()=>!y.isEqual(h,e),[h,e]);return s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:l(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Chart Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(_.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(Gh,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Y Axis",children:s.jsx(Wh,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Legend",children:s.jsx(Uh,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(Yh,{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(qh,{variables:r,control:o,watch:c})})]})]})})}function Jh(t){return y.omit(t,"variables")}function Zh(t){const{label_formatter:e=ye,...n}=t.y_axis;return{...t,y_axis:{...n,label_formatter:e}}}function Hh(t){const e={rotate:0,formatter:{...Oe}},{axisLabel:n=e,...r}=t.x_axis;return{...t,x_axis:{...r,axisLabel:n}}}function ex(t){const e={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return y.defaultsDeep(e,t)}function tx(t){delete t.config;const{x_axis:e,tooltip:n}=t.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:e,in_tooltip:n}}}};return y.defaultsDeep(r,t)}function nx(t){const e={tooltip:{metrics:[]}};return y.defaultsDeep(e,t)}function sx(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis:i,y_axis:o,tooltip:l,...c}=t;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 rx(t){const e={legend:{show:!0,top:"0",right:"10",left:"auto",bottom:"auto",orient:"horizontal",type:"scroll"}};return y.defaultsDeep(e,t)}class ix extends re{constructor(){super(...arguments);z(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:Jh(i)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:Zh(r)}}),this.version(4,n=>{const{config:r}=n;return{...n,version:4,config:Hh(r)}}),this.version(5,n=>{const{config:r}=n;return{...n,version:5,config:ex(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:tx(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:nx(r)}}),this.version(8,(n,r)=>{const{config:i}=n;return{...n,version:8,config:sx(i,r)}}),this.version(9,n=>{const{config:r}=n;return{...n,version:9,config:rx(r)}})}}const ax={displayName:"Boxplot Chart",displayGroup:"ECharts-based charts",migrator:new ix,name:"boxplot",viewRender:Vh,configRender:Xh,createConfig(){return{version:9,config:y.cloneDeep(ws)}},triggers:[Ei]},wa={id:"builtin:button:click-button",displayName:"Click Button",nameRender:lx,configRender:ox,payload:[]};function ox(t){return s.jsx(s.Fragment,{})}function lx(t){return s.jsx(a.Text,{children:"Click this button"})}const Ws={content:"Button",variant:"filled",color:"blue",size:"xs",compact:!1,horizontal_align:"left",vertical_align:"center"},cx={left:"flex-start",center:"center",right:"flex-end"},ux={top:"flex-start",center:"center",bottom:"flex-end"},dx=S.observer(({context:t,instance:e})=>{const n=Ve({vizManager:t.vizManager,instance:e}),r=$e(n.triggerManager,wa.id),i=oe(),{value:o}=O(t.instanceData,"config"),l=f.useMemo(()=>y.defaultsDeep({},o,Ws),[o]),{content:c,horizontal_align:u,vertical_align:d,...h}=l,{width:p,height:x}=t.viewport,m=i.payloadForSQL,j=()=>{r.forEach(C=>{n.runInteraction(C.id,{})})};return s.jsx(a.Center,{sx:{width:p,height:x,justifyContent:cx[u],alignItems:ux[d]},children:s.jsx(a.Button,{...h,onClick:j,children:y.template(c)(m)})})}),px=({value:t,onChange:e,label:n})=>{const r=a.useMantineTheme(),i=f.useCallback(l=>()=>e(l),[e]),o=l=>t===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)})})]})},hx=a.MANTINE_SIZES.map(t=>({label:t.toUpperCase(),value:t})),xx=({label:t,value:e,onChange:n})=>s.jsx(a.Select,{data:hx,label:t,value:e,onChange:n}),fx=[{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}],gx=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],mx=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function yx({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},e,Ws),[e]),i=r;f.useEffect(()=>{!y.isEqual(r,i)&&(console.log("config malformed, resetting to defaults",r,i),n(i))},[r,i]);const{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=b.useForm({defaultValues:i});f.useEffect(()=>{d(i)},[i]);const h=u(),p=f.useMemo(()=>!y.isEqual(h,r),[h,r]);return c(["content","variant","color","size","compact","horizontal_align","vertical_align"]),s.jsxs("form",{onSubmit:l(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Chart Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(_.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:fx,...x})}),s.jsx(b.Controller,{control:o,name:"color",render:({field:x})=>s.jsx(px,{label:"Theme",...x})})]}),s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(b.Controller,{control:o,name:"size",render:({field:x})=>s.jsx(xx,{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:gx,...x})}),s.jsx(b.Controller,{control:o,name:"vertical_align",render:({field:x})=>s.jsx(a.Select,{label:"Vertical Alignment",data:mx,...x})})]})]})]})}class bx extends re{constructor(){super(...arguments);z(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 jx={displayName:"Button",displayGroup:"Others",migrator:new bx,name:"button",viewRender:dx,configRender:yx,createConfig(){return{version:2,config:y.cloneDeep(Ws)}},triggers:[wa]},Rs={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:wx,configRender:vx,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 vx(t){return s.jsx(s.Fragment,{})}function wx(t){return s.jsx(a.Text,{children:"Click chart's series"})}const Pt={x_axis_scroll:!1,y_axis_scroll:!1,x_axis_slider:!1,y_axis_slider:!1},Qs={regressions:[],series:[],stats:{templates:{bottom:"",top:""}},x_axis:{type:"category",axisLabel:{rotate:0,formatter:{...Oe},overflow:ze}},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:Pt};function Ys(t){const e=[];return t.x_axis_scroll&&e.push({type:"inside",xAxisIndex:[0],filterMode:"none",minSpan:1}),t.y_axis_scroll&&e.push({type:"inside",yAxisIndex:[0],filterMode:"none",minSpan:1}),t.x_axis_slider&&e.push({type:"slider",xAxisIndex:[0],filterMode:"none",bottom:"auto",top:0,height:15,moveHandleSize:0,showDataShadow:!1,minSpan:1}),e}function Cx(t){const e=t.y_axes.some(i=>!!i.name);let n=15;e&&(n+=20),t.dataZoom.x_axis_slider&&(n+=20);let r=5;return t.x_axis_name&&(r+=15),t.series.some(i=>!i.hide_in_legend)&&(r+=20),{top:n,right:15,bottom:r,left:20,containLabel:!0}}function Sx(t){return t!=="line"?{}:{itemStyle:{opacity:0}}}function _x(t){switch(t){case"line":return;case"bar":return"roundRect";case"scatter":return"circle"}}function kx(t){const e={show:!0,bottom:0,left:"center",type:"scroll"};return e.data=t.filter(n=>!n.hide_in_legend).map(({name:n,type:r})=>({name:n,icon:_x(r),...Sx(r)})),e}function En(t,e){switch(t.config.method){case"linear":return[...ct.regressionLinear()(e)];case"exponential":return[...ct.regressionExp()(e)];case"logarithmic":return[...ct.regressionLog()(e)];case"polynomial":return[...ct.regressionPoly().order(t.config.order)(e)];default:return[]}}function Tx(t,e,n,r){const{transform:i,plot:o}=t,l={...o,name:e,data:En(i,r),showSymbol:!1,tooltip:{show:!1},smooth:!1,custom:{}};return n&&(l.custom={type:"regression-line",targetSeries:n}),l}function Ix({regressions:t=[],x_axis_data_key:e},n){const r=[];if(Object.keys(n).length===0)return r;function i(o,l,c,u){const d=Tx(o,l,c,u);r.push(d)}return t.forEach(o=>{const{name:l,group_by_key:c}=o;if(!c||c===e){const p=rt(n,o.y_axis_data_key).map((x,m)=>[m,Number(x)]);i(o,l,"",p);return}const{columnKey:u}=D(o.y_axis_data_key),d=y.groupBy(Rt(n,o.y_axis_data_key),c);Object.entries(d).forEach(([h,p])=>{const x=p.map((j,C)=>[C,Number(j[u])]);i(o,h,h,x)})}),r}function Dx(t,e){return t.map(n=>({name:"",type:"line",hide_in_legend:!0,data:[],markArea:{itemStyle:{color:n.color},data:[[{yAxis:e[n.y_keys.upper]},{yAxis:e[n.y_keys.lower]}]],silent:!0}}))}function Mx(t,e,n,r){return e?r==="value"?[[n[0],t]]:[t]:[]}function Ax(t,e,n,r,i,o){return t.map(l=>{const c=n[l.variable_key],u=l.orientation==="horizontal",d=u?"yAxis":"xAxis",h=u?"insideEndTop":"end",p=Mx(c,u,i,o);return{name:l.name,type:"scatter",hide_in_legend:!l.show_in_legend,xAxisId:"main-x-axis",yAxisIndex:l.yAxisIndex,data:p,symbol:"none",silent:!0,tooltip:{show:!1},markLine:{data:[{name:l.name,[d]:c}],silent:!0,symbol:["none","none"],lineStyle:l.lineStyle,label:{formatter:function(){return l.template?An(l.template,e,r):""},position:h}}}})}function zx({type:t,...e},n,r,i){if(!t)return 10;if(t==="static"){const{size:d}=e;return d}const{func_content:o}=e,{queryID:l,columnKey:c}=D(r),u=y.keyBy(Rt(n,l),c);return(d,h)=>{let p;h.name?p=u[h.name]:p=n[h.dataIndex];try{return new Function(`return ${o}`)()({rowData:p,params:h,variables:i},{lodash:y,interpolate:xt.interpolate})}catch(x){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${x.message}`),10}}}function Ks(t,e,n){const r=rt(t,e),i=rt(t,n);return y.zip(r,i)}function Ex(t,e,n,r){const i=Ks(e,n,r);return y.unionBy(i,t,0)}function Px({dataTemplate:t,data:e,x_axis_data_key:n,y_axis_data_key:r,valueTypedXAxis:i}){return i?Ex(t,e,n,r):rt(e,r)}function Lx({dataTemplate:t,data:e,aggregation_on_value:n,x_axis_data_key:r,y_axis_data_key:i,valueTypedXAxis:o}){if(!n||n.type==="none")return Px({dataTemplate:t,data:e,x_axis_data_key:r,y_axis_data_key:i,valueTypedXAxis:o});const l=Ks(e,r,i),c=y.groupBy(l,"0");return t.map(([d])=>{const p=c[d].map(m=>m[1]),x=Fs(p,n);return[d,x]})}function Bx({group_by_key:t,data:e,x_axis_data_key:n,y_axis_data_key:r}){const{queryID:i,columnKey:o}=D(t),l=y.groupBy(e[i],o);return Object.entries(l).forEach(([c,u])=>{l[c]=Ks({[i]:u},n,r)}),l}function Ox({x_axis_data_key:t,x_axis:e},{y_axis_data_key:n,yAxisIndex:r,label_position:i,name:o,group_by_key:l,aggregation_on_value:c,stack:u,color:d,display_name_on_line:h,symbolSize:p,hide_in_legend:x,...m},j,C,T,A){const L=e.type!=="category",Y={label:{show:!!i,position:i,formatter:A[r??"default"]},name:o,xAxisId:"main-x-axis",yAxisIndex:r,stack:u,color:d,symbolSize:zx(p,C,t,T),hide_in_legend:x,labelLayout:{hideOverlap:!0},...m};if(m.type==="line"&&(Y.lineStyle={shadowColor:"rgba(255,255,255,1)",shadowBlur:0,shadowOffsetX:0,shadowOffsetY:3}),h&&(Y.endLabel={show:!0,formatter:o,offset:[-12,12],align:"right"}),!l||l===t)return Y.data=Lx({dataTemplate:j,data:C,aggregation_on_value:c,x_axis_data_key:t,y_axis_data_key:n,valueTypedXAxis:L}),Y;const se=Bx({group_by_key:l,data:C,x_axis_data_key:t,y_axis_data_key:n});return Object.entries(se).map(([Q,ie])=>{const ue=y.cloneDeep(Y);return ue.name=Q,ue.color=void 0,ue.data=ie,ue})}function $x(t,e,n,r,i,o){const l=e.map(u=>[u,0]);return t.series.map(u=>Ox(t,u,l,n,o,r)).flat().concat(Ax(t.reference_lines,i,o,n,e,t.x_axis.type)).concat(Dx(t.reference_areas,o))}function Vx(t,e){const n=t.find(o=>o.axisDim==="x"&&o.axisId==="main-x-axis");if(!n)return"";const{axisValue:r,axisIndex:i}=n;return Mt(e.x_axis.axisLabel.formatter)(r,i)}function Nx(t,e,n){const r=e.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:h,value:p})=>{if(Array.isArray(p)&&p.length===2&&(p=p[1]),!d)return p;const x=r[d],m=n[x]??n.default;return`
100
+ `}const Bd=t=>e=>{const{componentSubType:n,value:r}=e;return n==="scatter"?Ld(t,r):Ed(t,r)};function Od({config:t}){return{trigger:"item",confine:!0,formatter:Bd(t)}}const Qt=f.forwardRef(function({value:e,onChange:n,...r},i){return s.jsx(a.TextInput,{ref:i,value:e,onChange:n,...r})}),$i=["function aggregation({ queryData }, utils) {",' return "Aggregation Result";',"}"].join(`
101
+ `),At={type:"none",config:{},fallback:"0"};function $d(t){const e=Array.from(t).sort((r,i)=>r-i),n=Math.floor(e.length/2);return e.length%2===0?(e[n-1]+e[n])/2:e[n]}function Vd(t,e){switch(e.type){case"sum":return y.sum(t);case"mean":return y.mean(t);case"median":return $d(t);case"max":return y.max(t);case"min":return y.min(t);case"quantile":return Nt.quantile(t,e.config.p);case"CV":const n=cn.std(...t),r=cn.mean(...t);return r?n/r:Number.NaN;case"std":return cn.std(...t);default:return t}}function _s(t,e){const n=t.map(Number),r=Vd(n,e);return typeof r=="number"?Number.isFinite(r)?r:e.fallback:r??e.fallback}function Nd(t,e,n){try{const r=Rt(t,e);return new Function(`return ${n.config.func}`)()({queryData:r},gt)}catch(r){return console.error(r),r.message}}function fn(t,e,n){try{return n.type==="custom"?Nd(t,e,n):_s(rt(t,e),n)}catch(r){return console.error(r),null}}class qd{constructor({valueRange:e,colorRange:n}){z(this,"mapper");this.mapper=ft.interpolate(e,n)}getColor(e){return this.mapper(e)}}function Fd(t){return t===null?"null":t===void 0?"undefined":Array.isArray(t)?`Array(${t.length})`:t.toString()}function it({data_field:t,aggregation:e},n){return fn(n,t,e)}function Ne({formatter:t,aggregation:e},n){if(!["string","number"].includes(typeof n))return Fd(n);if(e.type==="custom")return n;try{return F(n).format(t)}catch(r){return console.error(r),n}}function Gd(t,e){if(t.type==="static")return t.staticColor;if(t.type==="continuous")try{if(typeof e!="number")throw new Error(`[getColorByColorConf] Invalid type of aggregated value: ${e}`);return new qd(t).getColor(e)}catch(n){return console.error(n),"black"}return"black"}function Wd(t,e){const{color:n,data_field:r,aggregation:i,size:o,weight:l}=t,c=fn(e,r,i),u=Ne(t,c);return s.jsx(a.Text,{sx:{fontSize:o,display:"inline"},color:Gd(n,c),weight:l,children:u})}function Rd(t,e){const n={};return t.forEach(r=>{const i=r.name;n[i]=Wd(r,e)}),n}function Qd(t){return t.split(" ").map((e,n)=>s.jsxs(f.Fragment,{children:[e," "]},n))}function Ud(t){const n=t.replaceAll("<br />","<br/>").replaceAll(`
102
+ `,"<br/>").split("<br/>");return n.map((i,o)=>{const l=[Qd(i)];return o!==n.length-1&&l.push(s.jsx("br",{},`br-${o}`)),l}).flat().filter(i=>i!==void 0)}function ks(t){return Ud(t)}function Ut(t,e,n){const r=Rd(e,n),i=/^\{(.+)\}(.*)$/;return t.split("$").map((o,l)=>{const c=i.exec(o);if(!c)return ks(o);const u=r[c[1]];if(!u)return ks(o);const d=c[2]??"";return s.jsxs(f.Fragment,{children:[u,ks(d)]},`${o}-${l}`)})}function Yd(t,e){const{data_field:n,aggregation:r}=t,i=fn(e,n,r);return Ne(t,i)}function Vi(t,e){const n={};return t.forEach(r=>{n[r.name]=Yd(r,e)}),n}function gn(t,e,n){const r=Vi(e,n),i=/^\{(.+)\}(.*)$/;return t.split("$").map(o=>{const l=i.exec(o);if(!l)return o;const c=r[l[1]];if(!c)return o;const u=l[2]??"";return`${c}${u}`}).join("")}function Kd(t,e,n){const r=e.reduce((i,o)=>{const l=it(o,n);return i[o.name]=Ne(o,l),i},{});return t.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,e,n)},position:"insideEndTop"}}}))}function Xd(t){const e={top:30,left:20,right:15,bottom:25,containLabel:!0};return t.legend.orient==="vertical"&&(e.right=80),e}const Ni={axisTick:{show:!0,alignWithLabel:!0,lineStyle:{width:2}},axisLine:{show:!0,lineStyle:{width:3}},splitLine:{show:!1},z:3};function Jd(t){return y.defaultsDeep({},t,Ni)}const Zd=Object.freeze(Object.defineProperty({__proto__:null,getXAxis:Jd,xAxis:Ni},Symbol.toStringTag,{value:"Module"})),qi={axisTick:{show:!1},axisLine:{show:!1,lineStyle:{width:3}},splitLine:{show:!0,lineStyle:{type:"dashed"}}};function Hd(t){return y.defaultsDeep({},t,qi)}const ze={...Zd,...Object.freeze(Object.defineProperty({__proto__:null,getYAxis:Hd,yAxis:qi},Symbol.toStringTag,{value:"Module"}))};function ep({config:t,data:e,variables:n}){const{x_axis:r,y_axis:i,reference_lines:o}=t,l=Dd(t,e),c=Qe(r.axisLabel.overflow.on_axis),u=Ad(t);return{grid:Xd(t),dataset:l,legend:Md({config:t}),tooltip:Od({config:t}),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,...Kd(o,n,e)]}}Y.use([P.DataZoomComponent,te.BoxplotChart,P.MarkLineComponent,P.GridComponent,P.LegendComponent,P.TooltipComponent,we.CanvasRenderer]);function tp({context:t,instance:e}){const{value:n}=O(t.instanceData,"config"),{variables:r}=t,i=t.data,{width:o,height:l}=t.viewport,c=y.defaults({},n,vs),u=Ve({vizManager:t.vizManager,instance:e}),d=$e(u.triggerManager,Li.id),p=mt(i,c.x_axis.data_key),h=f.useCallback(j=>{const C=y.get(p,j.name,{error:"rowData is not found"});d.forEach(T=>{u.runInteraction(T.id,{...j,rowData:C})})},[p,d,u]),x=f.useMemo(()=>({click:h}),[h]),m=f.useMemo(()=>ep({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 np({value:t,onChange:e},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===t),[t,i]);return s.jsxs(a.Group,{position:"apart",spacing:4,ref:n,children:[s.jsx(a.TextInput,{placeholder:"Set any color",value:o?"":t,onChange:l=>e(l.currentTarget.value),rightSection:s.jsx(a.ColorSwatch,{color:o?"transparent":t,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:t,onChange:e,variant:o?"default":"filled",placeholder:"Pick a theme color",icon:s.jsx(a.ColorSwatch,{color:o?t:"transparent",radius:4}),sx:{maxWidth:"46%",flexGrow:1}})]})}const Se=f.forwardRef(np);function sp({control:t,index:e,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.${e}.name`,control:t,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.${e}.variable_key`,control:t,render:({field:i})=>s.jsx(a.Select,{label:"Value",required:!0,data:r,sx:{flex:1},...i})})]}),s.jsx(b.Controller,{name:`reference_lines.${e}.template`,control:t,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(e),sx:{position:"absolute",top:15,right:5},children:s.jsx(_.Trash,{size:16})})]})}function rp({control:t,watch:e,variables:n}){const{fields:r,append:i,remove:o}=b.useFieldArray({control:t,name:"reference_lines"}),l=e("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(sp,{control:t,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 ip=({disabled:t,value:e,onChange:n})=>{const r=i=>{i&&n(i)};return s.jsxs(a.Box,{sx:{position:"relative"},children:[t&&s.jsx(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),s.jsx(ge,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},mn=f.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:i,setFalse:o}]=$.useBoolean(),[l,c]=f.useState(t);f.useEffect(()=>{c(t)},[t]);const u=m=>{c({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:j}=l,C={enabled:m,func_content:j};c(C),e(C)},p=()=>{o(),c(t)},h=m=>{c(j=>({...j,func_content:m}))},x=()=>{h(Oe.func_content)};return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"filled",mt:24,onClick:i,sx:{flexGrow:0},children:"Customize Label"}),s.jsx(a.Modal,{size:800,title:"Customize label content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&s.jsxs(a.Stack,{children:[s.jsx(a.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:m=>u(m.currentTarget.checked)}),s.jsx(ip,{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"})]})]})]})})]})}),ap=({control:t,watch:e})=>(e(["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:t,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:t,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:t,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:t,render:({field:n})=>s.jsx(mn,{...n})})]}),s.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>s.jsx(Xe,{...n})})]})),op=({control:t,watch:e})=>(e(["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:t,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:t,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:t,render:({field:n})=>s.jsx(Be,{...n})})]})]})),lp=({control:t,index:e,remove:n})=>s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`tooltip.metrics.${e}.name`,control:t,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`tooltip.metrics.${e}.data_key`,control:t,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(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),cp=({control:t,watch:e})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:t,name:"tooltip.metrics"}),o=e("tooltip.metrics"),l=n.map((h,x)=>({...h,...o[x]})),c=()=>r({id:Date.now().toString(),data_key:"",name:""}),u=e("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(lp,{control:t,index:x,remove:i},h.id)},h.id))]})]})};function up({control:t,watch:e}){return s.jsx(a.Stack,{children:s.jsx(cp,{control:t,watch:e})})}const dp=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}],pp=({control:t,watch:e})=>{const n=e("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:t,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:t,render:({field:i})=>s.jsx(a.Select,{label:"Orientation",data:dp,sx:{flex:1},value:i.value.orient,onChange:o=>{r(o,i.onChange)},disabled:!n.show})})})]})};function hp({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),{variables:r}=t,i=f.useMemo(()=>y.defaults({},e,vs),[e]),{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,e),[p,e]);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(ap,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Y Axis",children:s.jsx(op,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Legend",children:s.jsx(pp,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(up,{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(rp,{variables:r,control:o,watch:c})})]})]})})}function xp(t){return y.omit(t,"variables")}function fp(t){const{label_formatter:e=ye,...n}=t.y_axis;return{...t,y_axis:{...n,label_formatter:e}}}function gp(t){const e={rotate:0,formatter:{...Oe}},{axisLabel:n=e,...r}=t.x_axis;return{...t,x_axis:{...r,axisLabel:n}}}function mp(t){const e={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return y.defaultsDeep(e,t)}function yp(t){delete t.config;const{x_axis:e,tooltip:n}=t.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:e,in_tooltip:n}}}};return y.defaultsDeep(r,t)}function bp(t){const e={tooltip:{metrics:[]}};return y.defaultsDeep(e,t)}function jp(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis:i,y_axis:o,tooltip:l,...c}=t;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 vp(t){const e={legend:{show:!0,top:"0",right:"10",left:"auto",bottom:"auto",orient:"horizontal",type:"scroll"}};return y.defaultsDeep(e,t)}class wp extends re{constructor(){super(...arguments);z(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:xp(i)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:fp(r)}}),this.version(4,n=>{const{config:r}=n;return{...n,version:4,config:gp(r)}}),this.version(5,n=>{const{config:r}=n;return{...n,version:5,config:mp(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:yp(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:bp(r)}}),this.version(8,(n,r)=>{const{config:i}=n;return{...n,version:8,config:jp(i,r)}}),this.version(9,n=>{const{config:r}=n;return{...n,version:9,config:vp(r)}})}}const Cp={displayName:"Boxplot Chart",displayGroup:"ECharts-based charts",migrator:new wp,name:"boxplot",viewRender:tp,configRender:hp,createConfig(){return{version:9,config:y.cloneDeep(vs)}},triggers:[Li]},Fi={id:"builtin:button:click-button",displayName:"Click Button",nameRender:_p,configRender:Sp,payload:[]};function Sp(t){return s.jsx(s.Fragment,{})}function _p(t){return s.jsx(a.Text,{children:"Click this button"})}const Ts={content:"Button",variant:"filled",color:"blue",size:"xs",compact:!1,horizontal_align:"left",vertical_align:"center"},kp={left:"flex-start",center:"center",right:"flex-end"},Tp={top:"flex-start",center:"center",bottom:"flex-end"},Ip=S.observer(({context:t,instance:e})=>{const n=Ve({vizManager:t.vizManager,instance:e}),r=$e(n.triggerManager,Fi.id),i=oe(),{value:o}=O(t.instanceData,"config"),l=f.useMemo(()=>y.defaultsDeep({},o,Ts),[o]),{content:c,horizontal_align:u,vertical_align:d,...p}=l,{width:h,height:x}=t.viewport,m=i.payloadForSQL,j=()=>{r.forEach(C=>{n.runInteraction(C.id,{})})};return s.jsx(a.Center,{sx:{width:h,height:x,justifyContent:kp[u],alignItems:Tp[d]},children:s.jsx(a.Button,{...p,onClick:j,children:y.template(c)(m)})})}),Dp=({value:t,onChange:e,label:n})=>{const r=a.useMantineTheme(),i=f.useCallback(l=>()=>e(l),[e]),o=l=>t===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)})})]})},Mp=a.MANTINE_SIZES.map(t=>({label:t.toUpperCase(),value:t})),Ap=({label:t,value:e,onChange:n})=>s.jsx(a.Select,{data:Mp,label:t,value:e,onChange:n}),zp=[{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}],Ep=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Pp=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function Lp({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},e,Ts),[e]),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:zp,...x})}),s.jsx(b.Controller,{control:o,name:"color",render:({field:x})=>s.jsx(Dp,{label:"Theme",...x})})]}),s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(b.Controller,{control:o,name:"size",render:({field:x})=>s.jsx(Ap,{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:Ep,...x})}),s.jsx(b.Controller,{control:o,name:"vertical_align",render:({field:x})=>s.jsx(a.Select,{label:"Vertical Alignment",data:Pp,...x})})]})]})]})}class Bp extends re{constructor(){super(...arguments);z(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 Op={displayName:"Button",displayGroup:"Others",migrator:new Bp,name:"button",viewRender:Ip,configRender:Lp,createConfig(){return{version:2,config:y.cloneDeep(Ts)}},triggers:[Fi]},Is={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:Vp,configRender:$p,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 $p(t){return s.jsx(s.Fragment,{})}function Vp(t){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},Ds={regressions:[],series:[],stats:{templates:{bottom:"",top:""}},x_axis:{type:"category",axisLabel:{rotate:0,formatter:{...Oe},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 Ms(t){const e=[];return t.x_axis_scroll&&e.push({type:"inside",xAxisIndex:[0],filterMode:"none",minSpan:1}),t.y_axis_scroll&&e.push({type:"inside",yAxisIndex:[0],filterMode:"none",minSpan:1}),t.x_axis_slider&&e.push({type:"slider",xAxisIndex:[0],filterMode:"none",bottom:"auto",top:0,height:15,moveHandleSize:0,showDataShadow:!1,minSpan:1}),e}function Np(t){const e=t.y_axes.some(i=>!!i.name);let n=15;e&&(n+=20),t.dataZoom.x_axis_slider&&(n+=20);let r=5;return t.x_axis_name&&(r+=15),t.series.some(i=>!i.hide_in_legend)&&(r+=20),{top:n,right:15,bottom:r,left:20,containLabel:!0}}function qp(t){return t!=="line"?{}:{itemStyle:{opacity:0}}}function Fp(t){switch(t){case"line":return;case"bar":return"roundRect";case"scatter":return"circle"}}function Gp(t){const e={show:!0,bottom:0,left:"center",type:"scroll"};return e.data=t.filter(n=>!n.hide_in_legend).map(({name:n,type:r})=>({name:n,icon:Fp(r),...qp(r)})),e}function yn(t,e){switch(t.config.method){case"linear":return[...ut.regressionLinear()(e)];case"exponential":return[...ut.regressionExp()(e)];case"logarithmic":return[...ut.regressionLog()(e)];case"polynomial":return[...ut.regressionPoly().order(t.config.order)(e)];default:return[]}}function Wp(t,e,n,r){const{transform:i,plot:o}=t,l={...o,name:e,data:yn(i,r),showSymbol:!1,tooltip:{show:!1},smooth:!1,custom:{}};return n&&(l.custom={type:"regression-line",targetSeries:n}),l}function Rp({regressions:t=[],x_axis_data_key:e},n){const r=[];if(Object.keys(n).length===0)return r;function i(o,l,c,u){const d=Wp(o,l,c,u);r.push(d)}return t.forEach(o=>{const{name:l,group_by_key:c}=o;if(!c||c===e){const h=rt(n,o.y_axis_data_key).map((x,m)=>[m,Number(x)]);i(o,l,"",h);return}const{columnKey:u}=D(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,C)=>[C,Number(j[u])]);i(o,p,p,x)})}),r}function Qp(t,e){return t.map(n=>({name:"",type:"line",hide_in_legend:!0,data:[],markArea:{itemStyle:{color:n.color},data:[[{yAxis:e[n.y_keys.upper]},{yAxis:e[n.y_keys.lower]}]],silent:!0}}))}function Up(t,e,n,r){return e?r==="value"?[[n[0],t]]:[t]:[]}function Yp(t,e,n,r,i,o){return t.map(l=>{const c=n[l.variable_key],u=l.orientation==="horizontal",d=u?"yAxis":"xAxis",p=u?"insideEndTop":"end",h=Up(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,e,r):""},position:p}}}})}function Kp({type:t,...e},n,r,i){if(!t)return 10;if(t==="static"){const{size:d}=e;return d}const{func_content:o}=e,{queryID:l,columnKey:c}=D(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 As(t,e,n){const r=rt(t,e),i=rt(t,n);return y.zip(r,i)}function Xp(t,e,n,r){const i=As(e,n,r);return y.unionBy(i,t,0)}function Jp({dataTemplate:t,data:e,x_axis_data_key:n,y_axis_data_key:r,valueTypedXAxis:i}){return i?Xp(t,e,n,r):rt(e,r)}function Zp({dataTemplate:t,data:e,aggregation_on_value:n,x_axis_data_key:r,y_axis_data_key:i,valueTypedXAxis:o}){if(!n||n.type==="none")return Jp({dataTemplate:t,data:e,x_axis_data_key:r,y_axis_data_key:i,valueTypedXAxis:o});const l=As(e,r,i),c=y.groupBy(l,"0");return t.map(([d])=>{const h=c[d].map(m=>m[1]),x=_s(h,n);return[d,x]})}function Hp({group_by_key:t,data:e,x_axis_data_key:n,y_axis_data_key:r}){const{queryID:i,columnKey:o}=D(t),l=y.groupBy(e[i],o);return Object.entries(l).forEach(([c,u])=>{l[c]=As({[i]:u},n,r)}),l}function eh({x_axis_data_key:t,x_axis:e},{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,C,T,A){const L=e.type!=="category",U={label:{show:!!i,position:i,formatter:A[r??"default"]},name:o,xAxisId:"main-x-axis",yAxisIndex:r,stack:u,color:d,symbolSize:Kp(h,C,t,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===t)return U.data=Zp({dataTemplate:j,data:C,aggregation_on_value:c,x_axis_data_key:t,y_axis_data_key:n,valueTypedXAxis:L}),U;const se=Hp({group_by_key:l,data:C,x_axis_data_key:t,y_axis_data_key:n});return Object.entries(se).map(([Q,ie])=>{const ue=y.cloneDeep(U);return ue.name=Q,ue.color=void 0,ue.data=ie,ue})}function th(t,e,n,r,i,o){const l=e.map(u=>[u,0]);return t.series.map(u=>eh(t,u,l,n,o,r)).flat().concat(Yp(t.reference_lines,i,o,n,e,t.x_axis.type)).concat(Qp(t.reference_areas,o))}function nh(t,e){const n=t.find(o=>o.axisDim==="x"&&o.axisId==="main-x-axis");if(!n)return"";const{axisValue:r,axisIndex:i}=n;return Mt(e.x_axis.axisLabel.formatter)(r,i)}function sh(t,e,n){const r=e.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`
107
103
  <tr>
108
- <td>${h}</td>
104
+ <td>${p}</td>
109
105
  <th style="text-align: right; padding: 0 1em;">${d}</th>
110
- <td style="text-align: left; padding: 0 1em;">${m({value:p})}</td>
106
+ <td style="text-align: left; padding: 0 1em;">${m({value:h})}</td>
111
107
  </tr>
112
- `}),c=Je(t.x_axis.axisLabel.overflow.in_tooltip),u=Vx(o,t);return`
108
+ `}),c=Je(t.x_axis.axisLabel.overflow.in_tooltip),u=nh(o,t);return`
113
109
  <div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
114
110
  <div style="${c}">${u}</div>
115
111
  </div>
@@ -118,14 +114,18 @@ Check the top-level render call using <`+M+">.")}return I}}function oc(v,I){{if(
118
114
  ${l.join("")}
119
115
  </tbody>
120
116
  </table>
121
- `}}}function qx(t){return t.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 Ca(t,e){const n={};return e.map(r=>{const i=at(r,t);n[r.name]=qe(r,i)}),n}function Fx(t,e){const{overflow:n,...r}=t.x_axis.axisLabel,i=Qe(n.on_axis),o=e.length===0;return[Le.getXAxis({data:e,name:t.x_axis_name??"",nameGap:o?5:void 0,id:"main-x-axis",type:t.x_axis.type,axisLabel:{...r,...i,formatter:Mt(r.formatter)}})]}function Gx(t){var e;try{return Array.isArray(t[0])&&((e=t[0])==null?void 0:e.length)>=2?t.map(r=>Number(r[1])):[...t]}catch(n){return console.error(n),[...t]}}function Wx(t){if(t.length===0)return{};const e={},n={};return t.forEach(r=>{const i=Gx(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&&(e[r]=1)}),e}function Rx(t,e,n){const r=Wx(n);return t.y_axes.map(({nameAlignment:i,min:o,max:l,show:c,...u},d)=>{let h=u.position;return h||(h=d>0?"right":"left"),Le.getYAxis({...u,minInterval:r[d]??0,show:c,min:o||void 0,max:l||void 0,position:h,axisLabel:{show:c,formatter:e[d]??e.default},nameTextStyle:{align:i},nameLocation:"end",nameGap:c?15:0,splitLine:{show:d===0}})})}const Qx={xAxis:[{type:"category",nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0}}]};function Yx(t,e,n){const r=Ca(e,n),i=qx(t),o=y.uniq(rt(e,t.x_axis_data_key)),l=$x(t,o,e,i,n,r),c=Ix(t,e),u={xAxis:Fx(t,o),yAxis:Rx(t,i,l),series:[...l,...c],tooltip:Nx(t,l,i),grid:Cx(t),legend:kx(l),dataZoom:Ys(t.dataZoom)};return y.defaultsDeep({},u,Qx)}function Sa(t){const e=t.getModel(),n=e.getSeries().map(r=>{if(!r.option.custom)return r.option;const i=e.getColorFromPalette(r.option.custom.targetSeries,null);return r.option.color=i,r.option});t.setOption({...t.getOption(),series:n})}K.use([P.DataZoomComponent,te.BarChart,te.LineChart,te.ScatterChart,P.GridComponent,P.LegendComponent,P.TooltipComponent,we.CanvasRenderer,P.MarkLineComponent,P.MarkAreaComponent]);function _a(t){return t.trim().length>0}function Kx({conf:t,data:e,width:n,height:r,interactionManager:i,variables:o}){const l=mt(e,t.x_axis_data_key),c=$e(i.triggerManager,Rs.id),u=f.useCallback(m=>{const j=y.get(l,m.name,{error:"rowData is not found"});c.forEach(C=>{i.runInteraction(C.id,{...m,rowData:j})})},[l,c,i]),d=f.useMemo(()=>Yx(t,e,o),[t,e]),h=f.useRef(),p=f.useMemo(()=>({click:u}),[u]),x=m=>{h.current=m,Sa(m)};return f.useEffect(()=>{h.current&&Sa(h.current)},[d]),!n||!r?null:s.jsx(ve,{echarts:K,option:d,style:{width:n,height:r},onEvents:p,onChartReady:x,notMerge:!0,theme:"merico-light"})}function Ux({context:t,instance:e}){const n=Ve({vizManager:t.vizManager,instance:e}),{value:r}=O(t.instanceData,"config"),{variables:i}=t,o=f.useMemo(()=>y.defaults({},r,Qs),[r]),l=t.data,{width:c,height:u}=t.viewport,{ref:d,height:h}=pe.useElementSize(),{ref:p,height:x}=pe.useElementSize(),m=f.useMemo(()=>{const{stats:{templates:T}}=o;return{top:en(T.top,i,l),bottom:en(T.bottom,i,l)}},[o,l]),j=Math.max(0,Re(u)-h-x),C=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:_a(o.stats.templates.top)?"block":"none"},children:Object.values(m.top).map((T,A)=>s.jsx(f.Fragment,{children:T},A))}),s.jsx(Kx,{variables:i,width:C,height:j,data:l,conf:o,interactionManager:n}),s.jsx(a.Text,{ref:p,align:"left",size:"xs",pl:"sm",sx:{display:_a(o.stats.templates.bottom)?"block":"none"},children:Object.values(m.bottom).map((T,A)=>s.jsx(f.Fragment,{children:T},A))})]})}const Us=f.forwardRef(({value:t,onChange:e},n)=>{const r=i=>o=>{e({...t,[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:t.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:t.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:t.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:!t.y_axis_slider,checked:t.y_axis_slider,onChange:i=>r("y_axis_slider")(i.currentTarget.checked)})})})]})]})}),Xx=[{label:"Rectangle",value:"rectangle"}],Jx=[{label:"Horizontal",value:"horizontal"}];function Zx({control:t,index:e,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.${e}.name`,control:t,render:({field:i})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})}),s.jsx(b.Controller,{name:`reference_areas.${e}.color`,control:t,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.${e}.type`,control:t,render:({field:i})=>s.jsx(a.Select,{label:"Type",required:!0,data:Xx,sx:{flex:1},...i})}),s.jsx(b.Controller,{name:`reference_areas.${e}.direction`,control:t,render:({field:i})=>s.jsx(a.Select,{label:"Direction",required:!0,data:Jx,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.${e}.y_keys.upper`,control:t,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.${e}.y_keys.lower`,control:t,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(e),sx:{top:15,right:5},children:"Delete this Reference Area"})]})}function Hx({control:t,watch:e,variables:n}){const{fields:r,append:i,remove:o}=b.useFieldArray({control:t,name:"reference_areas"}),l=e("reference_areas"),c=r.map((h,p)=>({...h,...l[p]})),u=()=>i({name:"",color:"rgba(0,0,0,0.1)",type:"rectangle",direction:"horizontal",y_keys:{upper:"",lower:""}}),d=f.useMemo(()=>n.map(h=>({label:h.name,value:h.name})),[n]);return s.jsxs(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"6px 0px 0px"}},children:[s.jsxs(a.Tabs.List,{children:[c.map((h,p)=>s.jsx(a.Tabs.Tab,{value:p.toString(),children:p+1},h.id)),s.jsx(a.Tabs.Tab,{onClick:u,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),c.map((h,p)=>s.jsx(a.Tabs.Panel,{value:p.toString(),children:s.jsx(Zx,{control:t,index:p,remove:o,variableOptions:d})},h.id))]})}const ef=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],tf=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function nf({control:t,index:e,remove:n,watch:r,variableOptions:i,yAxisOptions:o}){const l=r(`reference_lines.${e}.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.${e}.name`,control:t,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.${e}.variable_key`,control:t,render:({field:c})=>s.jsx(a.Select,{label:"Value",required:!0,data:i,sx:{flex:1},...c})})]}),s.jsx(b.Controller,{name:`reference_lines.${e}.template`,control:t,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.${e}.orientation`,control:t,render:({field:c})=>s.jsx(a.Select,{label:"Orientation",data:tf,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.${e}.yAxisIndex`,control:t,render:({field:{value:c,onChange:u,...d}})=>s.jsx(a.Select,{label:"Y Axis",data:o,disabled:o.length===0,...d,value:(c==null?void 0:c.toString())??"",onChange:h=>{if(!h){u(0);return}u(Number(h))},sx:{flex:1}})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:`reference_lines.${e}.lineStyle.type`,control:t,render:({field:c})=>s.jsx(a.Select,{label:"Line Type",data:ef,sx:{flexGrow:1},...c})}),s.jsx(b.Controller,{name:`reference_lines.${e}.lineStyle.width`,control:t,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.${e}.lineStyle.color`,control:t,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.${e}.show_in_legend`,control:t,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(e),sx:{top:15,right:5},children:"Delete this Reference Line"})]})}function sf({control:t,watch:e,variables:n}){const{fields:r,append:i,remove:o}=b.useFieldArray({control:t,name:"reference_lines"}),l=e("reference_lines"),c=r.map((x,m)=>({...x,...l[m]})),u=()=>{i({name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,yAxisIndex:0})},d=f.useMemo(()=>n.map(x=>({label:x.name,value:x.name})),[n]),h=e("y_axes"),p=f.useMemo(()=>h.map(({name:x},m)=>({label:x,value:m.toString()})),[h]);return s.jsxs(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[s.jsxs(a.Tabs.List,{children:[c.map((x,m)=>s.jsx(a.Tabs.Tab,{value:m.toString(),children:m+1},x.id)),s.jsx(a.Tabs.Tab,{onClick:u,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),c.map((x,m)=>s.jsx(a.Tabs.Panel,{value:m.toString(),children:s.jsx(nf,{control:t,index:m,remove:o,watch:e,variableOptions:d,yAxisOptions:p})},x.id))]})}const rf=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}],af=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function of({control:t,regressionItem:e,index:n,remove:r,yAxisOptions:i}){const o=e.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:t,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:t,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:t,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:t,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:t,render:({field:l})=>s.jsx(a.Select,{label:"Method",data:rf,sx:{flex:1},...l})}),o==="polynomial"&&s.jsx(b.Controller,{name:`regressions.${n}.transform.config.order`,control:t,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:t,render:({field:l})=>s.jsx(a.Select,{label:"Line Type",data:af,sx:{flexGrow:1},...l})}),s.jsx(b.Controller,{name:`regressions.${n}.plot.lineStyle.width`,control:t,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:t,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 lf({control:t,watch:e}){const{fields:n,append:r,remove:i}=b.useFieldArray({control:t,name:"regressions"}),o=e("regressions"),l=n.map((h,p)=>({...h,...o[p]})),c=e("y_axes"),u=f.useMemo(()=>c.map(({name:h},p)=>({label:h,value:p.toString()})),[c]),d=()=>r({transform:{type:"ecStat:regression",config:{method:"linear",order:1,formulaOn:"end"}},group_by_key:"",name:"",y_axis_data_key:"",plot:{type:"line",yAxisIndex:0,color:"#666666",lineStyle:{type:"solid",width:1}}});return s.jsxs(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((h,p)=>s.jsx(a.Tabs.Tab,{value:p.toString(),children:p+1},h.id)),s.jsx(a.Tabs.Tab,{onClick:d,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),l.map((h,p)=>s.jsx(a.Tabs.Panel,{value:p.toString(),children:s.jsx(of,{regressionItem:h,control:t,index:p,remove:i,yAxisOptions:u})},h.id))]})}const Xs={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
122
- `)}},cf=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function uf({control:t,index:e,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.${e}.stack`,control:t,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.${e}.barGap`,control:t,render:({field:i})=>s.jsx(a.Select,{label:"Bar Gap",data:cf,sx:{flexGrow:1},...i})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${e}.barMinWidth`,control:t,render:({field:i})=>s.jsx(a.TextInput,{label:"Bar Width(Min)",disabled:r,sx:{flexGrow:1},...i})}),s.jsx(b.Controller,{name:`series.${e}.barWidth`,control:t,render:({field:i})=>s.jsx(a.TextInput,{label:"Bar Width",sx:{flexGrow:1},...i})}),s.jsx(b.Controller,{name:`series.${e}.barMaxWidth`,control:t,render:({field:i})=>s.jsx(a.TextInput,{label:"Bar Width(Max)",disabled:r,sx:{flexGrow:1},...i})})]})]})}const df=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return s.jsx(a.Box,{children:s.jsx(me,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},pf=({value:t,onChange:e})=>{const[n,{setTrue:r,setFalse:i}]=$.useBoolean(),[o,l]=f.useState(t),c=()=>{i();const{type:p,func_content:x}=o,m={type:p,func_content:x};l(m),e(m)},u=()=>{i(),l(t)},d=p=>{l(x=>({...x,func_content:p}))},h=()=>{d(Xs.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(df,{value:o.func_content,onChange:d}),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:c,children:"OK"})]})]})]})})]})},hf=({value:t,onChange:e})=>t.type!=="dynamic"?null:s.jsx(pf,{value:t,onChange:e}),xf=({value:t,onChange:e})=>{if(t.type!=="static")return null;const n=r=>{e({...t,size:r})};return s.jsx(s.Fragment,{children:s.jsx(a.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:t.size,onChange:n})})},ff=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],ka=f.forwardRef(({label:t="Size",value:e,onChange:n},r)=>{const i=o=>{n({...Xs[o]})};return s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(a.Select,{ref:r,label:t,data:ff,value:e.type,onChange:i,sx:{flexGrow:1}}),s.jsx(xf,{value:e,onChange:n}),s.jsx(hf,{value:e,onChange:n})]})}),gf=[{label:"off",value:"false"},{label:"start",value:"start"},{label:"middle",value:"middle"},{label:"end",value:"end"}],mf=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function yf({control:t,index:e,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.${e}.lineStyle.type`,control:t,render:({field:i})=>s.jsx(a.Select,{label:"Line Type",data:mf,sx:{flexGrow:1},...i})}),s.jsx(b.Controller,{name:`series.${e}.lineStyle.width`,control:t,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.${e}.step`,control:t,render:({field:i})=>s.jsx(a.Select,{label:"Step",data:gf,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.${e}.smooth`,control:t,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.${e}.display_name_on_line`,control:t,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.${e}.showSymbol`,control:t,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.${e}.symbolSize`,control:t,render:({field:i})=>s.jsx(ka,{label:"Symbol Size",...i})})]})]})}function bf({control:t,index:e}){return s.jsx(b.Controller,{name:`series.${e}.symbolSize`,control:t,render:({field:n})=>s.jsx(ka,{label:"Size",...n})})}const jf=[{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 vf({control:t,index:e,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.${e}.type`,control:t,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.${e}.name`,control:t,render:({field:l})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...l})}),s.jsx(b.Controller,{name:`series.${e}.yAxisIndex`,control:t,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.${e}.y_axis_data_key`,control:t,render:({field:l})=>s.jsx(B,{label:"Value Field",required:!0,sx:{flex:1},...l})}),s.jsx(b.Controller,{name:`series.${e}.aggregation_on_value`,control:t,render:({field:l})=>s.jsx(Dn,{label:"Aggregation on Value",value:l.value??Et,onChange:l.onChange,pt:0})})]}),s.jsx(a.Group,{grow:!0,children:s.jsx(b.Controller,{name:`series.${e}.group_by_key`,control:t,render:({field:l})=>s.jsx(B,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...l})})}),o==="line"&&s.jsx(yf,{index:e,control:t,seriesItem:r}),o==="bar"&&s.jsx(uf,{index:e,control:t,seriesItem:r}),o==="scatter"&&s.jsx(bf,{index:e,control:t}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),s.jsx(b.Controller,{name:`series.${e}.label_position`,control:t,render:({field:l})=>s.jsx(a.Select,{label:"Label Position",data:jf,...l})}),s.jsxs(a.Stack,{spacing:4,children:[s.jsx(a.Text,{size:"sm",children:"Color"}),s.jsx(b.Controller,{name:`series.${e}.color`,control:t,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.${e}.hide_in_legend`,control:t,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(e),sx:{top:15,right:5},children:"Delete this Series"})]})}function wf({control:t,watch:e}){const{fields:n,append:r,remove:i}=b.useFieldArray({control:t,name:"series"}),o=e("series"),l=n.map((h,p)=>({...h,...o[p]})),c=()=>{const h={type:"bar",name:pe.randomId(),showSymbol:!1,symbolSize:Xs.static,y_axis_data_key:"value",yAxisIndex:0,label_position:"top",display_name_on_line:!1,stack:"",color:"#000",step:!1,smooth:!1,barMinWidth:"1",barWidth:"10%",barMaxWidth:"10",barGap:"0%",lineStyle:{type:"solid",width:1},hide_in_legend:!1,group_by_key:""};r(h)},u=e("y_axes"),d=f.useMemo(()=>u.map(({name:h},p)=>({label:h,value:p.toString()})),[u]);return s.jsxs(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((h,p)=>s.jsx(a.Tabs.Tab,{value:p.toString(),children:p+1},h.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),l.map((h,p)=>s.jsx(a.Tabs.Panel,{value:p.toString(),children:s.jsx(vf,{control:t,index:p,remove:i,seriesItem:h,yAxisOptions:d},h.id)},h.id))]})}function Cf({control:t,watch:e}){return e("stats"),s.jsx(a.Stack,{children:s.jsxs(a.Stack,{spacing:0,children:[s.jsx(b.Controller,{name:"stats.templates.top",control:t,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:t,render:({field:n})=>s.jsx(Qt,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const Sf=()=>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"]})})]})]}),_f=[{label:"Value",value:"value"},{label:"Category",value:"category"},{label:"Time",value:"time"},{label:"Log",value:"log"}];function kf({control:t,watch:e}){return e(["x_axis_data_key","x_axis_name","x_axis"]),s.jsxs(a.Stack,{children:[s.jsx(b.Controller,{name:"x_axis_name",control:t,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:t,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:t,render:({field:n})=>s.jsx(a.Select,{label:s.jsx(Sf,{}),required:!0,data:_f,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:t,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:t,render:({field:n})=>s.jsx(zn,{...n})})]}),s.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>s.jsx(Xe,{...n})})]})}const Tf=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],If=[{label:"left",value:"left"},{label:"right",value:"right"}];function Df({control:t,index:e,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.${e}.name`,control:t,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`y_axes.${e}.nameAlignment`,control:t,render:({field:r})=>s.jsx(a.Select,{label:"Name Anchor",required:!0,data:Tf,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.${e}.position`,control:t,render:({field:r})=>s.jsx(a.Select,{label:"Position",required:!0,data:If,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.${e}.label_formatter`,control:t,render:({field:r})=>s.jsx(Ae,{...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.${e}.min`,control:t,render:({field:r})=>s.jsx(a.TextInput,{label:"Min",...r})}),s.jsx(b.Controller,{name:`y_axes.${e}.max`,control:t,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.${e}.show`,control:t,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(e),disabled:e===0,children:"Delete this YAxis"})]})}function Mf({control:t,watch:e}){const{fields:n,append:r,remove:i}=b.useFieldArray({control:t,name:"y_axes"}),o=e("y_axes"),l=n.map((u,d)=>({...u,...o[d]})),c=()=>r({name:"",position:"left",nameAlignment:"left",label_formatter: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(Df,{control:t,index:d,remove:i})},u.id))]})}function Af({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),{variables:r}=t,i=f.useMemo(()=>y.defaultsDeep({},e,Qs),[e]),{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=b.useForm({defaultValues:i});f.useEffect(()=>{d(i)},[i]);const h=u(),p=f.useMemo(()=>!y.isEqual(h,i),[h,i]);return c(["dataZoom"]),s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:l(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Chart Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(_.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(kf,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Y Axes",children:s.jsx(Mf,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Series",children:s.jsx(wf,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Regression Lines",children:s.jsx(lf,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Stats",children:s.jsx(Cf,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Reference Lines",children:s.jsx(sf,{variables:r,control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Reference Areas",children:s.jsx(Hx,{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(Us,{...x})})})]})]})})}function zf(t){const e=y.cloneDeep(y.omit(t,"variables"));return e.stats=y.omit(e.stats,"variables"),e}function Ef(t){const{rotate:e,formatter:n=Oe}=t.x_axis.axisLabel;return{...t,x_axis:{...t.x_axis,axisLabel:{rotate:e,formatter:n}}}}function Pf(t){const{dataZoom:e=Pt,...n}=t;return{...n,dataZoom:e}}function Lf(t){const e={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return y.defaultsDeep(e,t)}function Bf(t){const e=t.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{...t,reference_lines:e}}function Of(t){const e=t.reference_lines.map(n=>{const{yAxisIndex:r=0}=n;return{...n,yAxisIndex:r}});return{...t,reference_lines:e}}function $f(t){const e=t.series.map(n=>{const{aggregation_on_group:r=Et}=n;return{...n,aggregation_on_group:r}});return{...t,series:e}}function Vf(t){const e=t.series.map(n=>{const{aggregation_on_value:r=Et}=n;return{...n,aggregation_on_value:r}});return{...t,series:e}}function Nf(t){delete t.config;const{x_axis:e,tooltip:n}=t.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:e,in_tooltip:n}}}};return y.defaultsDeep(r,t)}function qf(t){const{series:e,...n}=t;return{...n,series:e.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 Ff(t){const{y_axes:e,...n}=t;return{...n,y_axes:e.map(r=>{const{min:i="",max:o=""}=r;return{...r,min:i,max:o}})}}function Gf(t){const{y_axes:e,...n}=t;return{...n,y_axes:e.map(r=>{const{nameAlignment:i="left"}=r;return{...r,nameAlignment:i}})}}function Wf(t){const{y_axes:e,...n}=t;return{...n,y_axes:e.map(r=>{const{show:i=!0}=r;return{...r,show:i}})}}function Rf(t){const{regressions:e,...n}=t;return{...n,regressions:e.map(r=>{const{group_by_key:i=""}=r;return{...r,group_by_key:i}})}}function Qf(t){const{series:e,y_axes:n,...r}=t;return{...r,series:e.map(i=>{const{hide_in_legend:o=!1,aggregation_on_value:l=Et}=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 Yf(t){const{type:e="category",...n}=t.x_axis;return{...t,x_axis:{...n,type:e}}}function Kf(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis_data_key:i,series:o,regressions:l,...c}=t;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 Uf extends re{constructor(){super(...arguments);z(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:zf(i)}}),this.version(3,n=>({...n,version:3,config:Ef(n.config)})),this.version(4,n=>({...n,version:4,config:Pf(n.config)})),this.version(5,n=>({...n,version:5,config:Lf(n.config)})),this.version(6,n=>({...n,version:6,config:Bf(n.config)})),this.version(7,n=>({...n,version:7,config:Of(n.config)})),this.version(8,n=>({...n,version:8,config:$f(n.config)})),this.version(9,n=>({...n,version:9,config:Vf(n.config)})),this.version(10,n=>({...n,version:10,config:Nf(n.config)})),this.version(11,n=>({...n,version:11,config:qf(n.config)})),this.version(12,n=>({...n,version:12,config:Ff(n.config)})),this.version(13,n=>({...n,version:13,config:Gf(n.config)})),this.version(14,n=>({...n,version:14,config:Wf(n.config)})),this.version(15,n=>({...n,version:15,config:Rf(n.config)})),this.version(16,n=>({...n,version:16,config:Qf(n.config)})),this.version(17,n=>({...n,version:17,config:Yf(n.config)})),this.version(18,(n,r)=>({...n,version:18,config:Kf(n.config,r)}))}}const Xf={displayName:"Cartesian Chart",displayGroup:"ECharts-based charts",migrator:new Uf,name:"cartesian",viewRender:Ux,configRender:Af,createConfig(){return{version:18,config:y.cloneDeep(Qs)}},triggers:[Rs]};function Jf(t){if(t.enable_value)return t.value}function Zf(t){if(t.enable_value)return t.value}function Hf(t){const e=t.axisLabel.overflow.on_axis.width,n=t.axisLabel.position,r={top:5,left:5,right:5,bottom:5};return t.orient==="vertical"&&y.get(r,n)&&n===t.funnelAlign&&y.set(r,n,e),r}function eg(t,e){return t.series.map(n=>{const{level_name_data_key:r,level_value_data_key:i,axisLabel:o,min:l,max:c,funnelAlign:u,orient:d,...h}=n;if(!r||!i)return{};const p=D(r),x=D(i),m=e[p.queryID].map(C=>({name:C[p.columnKey],value:C[x.columnKey]})),j=Qe(o.overflow.on_axis);return{type:"funnel",...Hf(n),min:Jf(l),max:Zf(c),minSize:l.size,maxSize:c.size,...h,label:{show:!0,position:o.position,...j},orient:d,funnelAlign:d==="horizontal"?"center":u,data:m}})}function tg({conf:t,params:e,max:n}){const{name:r,value:i}=e.data,o=F(i/n).format({output:"percent",mantissa:2,trimMantissa:!0});return[{label:`${e.marker} ${r}`,value:`${i} (${o})`,style:{label:"",value:""}}]}function ng(t,e){var o;const n=D(t.series[0].level_name_data_key),r=D(t.series[0].level_value_data_key),i=(o=y.maxBy(e[n.queryID],r.columnKey))==null?void 0:o[r.columnKey];return l=>{const u=tg({conf:t,params:l,max:i}).map(h=>`
117
+ `}}}function rh(t){return t.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 Gi(t,e){const n={};return e.map(r=>{const i=it(r,t);n[r.name]=Ne(r,i)}),n}function ih(t,e){const{overflow:n,...r}=t.x_axis.axisLabel,i=Qe(n.on_axis),o=e.length===0;return[ze.getXAxis({data:e,name:t.x_axis_name??"",nameGap:o?5:void 0,id:"main-x-axis",type:t.x_axis.type,axisLabel:{...r,...i,formatter:Mt(r.formatter)}})]}function ah(t){var e;try{return Array.isArray(t[0])&&((e=t[0])==null?void 0:e.length)>=2?t.map(r=>Number(r[1])):[...t]}catch(n){return console.error(n),[...t]}}function oh(t){if(t.length===0)return{};const e={},n={};return t.forEach(r=>{const i=ah(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&&(e[r]=1)}),e}function lh(t,e,n){const r=oh(n);return t.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:e[d]??e.default},nameTextStyle:{align:i},nameLocation:"end",nameGap:c?15:0,splitLine:{show:d===0}})})}const ch={xAxis:[{type:"category",nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0}}]};function uh(t,e,n){const r=Gi(e,n),i=rh(t),o=y.uniq(rt(e,t.x_axis_data_key)),l=th(t,o,e,i,n,r),c=Rp(t,e),u={xAxis:ih(t,o),yAxis:lh(t,i,l),series:[...l,...c],tooltip:sh(t,l,i),grid:Np(t),legend:Gp(l),dataZoom:Ms(t.dataZoom)};return y.defaultsDeep({},u,ch)}function Wi(t){const e=t.getModel(),n=e.getSeries().map(r=>{if(!r.option.custom)return r.option;const i=e.getColorFromPalette(r.option.custom.targetSeries,null);return r.option.color=i,r.option});t.setOption({...t.getOption(),series:n})}Y.use([P.DataZoomComponent,te.BarChart,te.LineChart,te.ScatterChart,P.GridComponent,P.LegendComponent,P.TooltipComponent,we.CanvasRenderer,P.MarkLineComponent,P.MarkAreaComponent]);function Ri(t){return t.trim().length>0}function dh({conf:t,data:e,width:n,height:r,interactionManager:i,variables:o}){const l=mt(e,t.x_axis_data_key),c=$e(i.triggerManager,Is.id),u=f.useCallback(m=>{const j=y.get(l,m.name,{error:"rowData is not found"});c.forEach(C=>{i.runInteraction(C.id,{...m,rowData:j})})},[l,c,i]),d=f.useMemo(()=>uh(t,e,o),[t,e]),p=f.useRef(),h=f.useMemo(()=>({click:u}),[u]),x=m=>{p.current=m,Wi(m)};return f.useEffect(()=>{p.current&&Wi(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 ph({context:t,instance:e}){const n=Ve({vizManager:t.vizManager,instance:e}),{value:r}=O(t.instanceData,"config"),{variables:i}=t,o=f.useMemo(()=>y.defaults({},r,Ds),[r]),l=t.data,{width:c,height:u}=t.viewport,{ref:d,height:p}=pe.useElementSize(),{ref:h,height:x}=pe.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),C=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:Ri(o.stats.templates.top)?"block":"none"},children:Object.values(m.top).map((T,A)=>s.jsx(f.Fragment,{children:T},A))}),s.jsx(dh,{variables:i,width:C,height:j,data:l,conf:o,interactionManager:n}),s.jsx(a.Text,{ref:h,align:"left",size:"xs",pl:"sm",sx:{display:Ri(o.stats.templates.bottom)?"block":"none"},children:Object.values(m.bottom).map((T,A)=>s.jsx(f.Fragment,{children:T},A))})]})}const zs=f.forwardRef(({value:t,onChange:e},n)=>{const r=i=>o=>{e({...t,[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:t.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:t.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:t.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:!t.y_axis_slider,checked:t.y_axis_slider,onChange:i=>r("y_axis_slider")(i.currentTarget.checked)})})})]})]})}),hh=[{label:"Rectangle",value:"rectangle"}],xh=[{label:"Horizontal",value:"horizontal"}];function fh({control:t,index:e,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.${e}.name`,control:t,render:({field:i})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})}),s.jsx(b.Controller,{name:`reference_areas.${e}.color`,control:t,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.${e}.type`,control:t,render:({field:i})=>s.jsx(a.Select,{label:"Type",required:!0,data:hh,sx:{flex:1},...i})}),s.jsx(b.Controller,{name:`reference_areas.${e}.direction`,control:t,render:({field:i})=>s.jsx(a.Select,{label:"Direction",required:!0,data:xh,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.${e}.y_keys.upper`,control:t,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.${e}.y_keys.lower`,control:t,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(e),sx:{top:15,right:5},children:"Delete this Reference Area"})]})}function gh({control:t,watch:e,variables:n}){const{fields:r,append:i,remove:o}=b.useFieldArray({control:t,name:"reference_areas"}),l=e("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(fh,{control:t,index:h,remove:o,variableOptions:d})},p.id))]})}const mh=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],yh=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function bh({control:t,index:e,remove:n,watch:r,variableOptions:i,yAxisOptions:o}){const l=r(`reference_lines.${e}.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.${e}.name`,control:t,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.${e}.variable_key`,control:t,render:({field:c})=>s.jsx(a.Select,{label:"Value",required:!0,data:i,sx:{flex:1},...c})})]}),s.jsx(b.Controller,{name:`reference_lines.${e}.template`,control:t,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.${e}.orientation`,control:t,render:({field:c})=>s.jsx(a.Select,{label:"Orientation",data:yh,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.${e}.yAxisIndex`,control:t,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.${e}.lineStyle.type`,control:t,render:({field:c})=>s.jsx(a.Select,{label:"Line Type",data:mh,sx:{flexGrow:1},...c})}),s.jsx(b.Controller,{name:`reference_lines.${e}.lineStyle.width`,control:t,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.${e}.lineStyle.color`,control:t,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.${e}.show_in_legend`,control:t,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(e),sx:{top:15,right:5},children:"Delete this Reference Line"})]})}function jh({control:t,watch:e,variables:n}){const{fields:r,append:i,remove:o}=b.useFieldArray({control:t,name:"reference_lines"}),l=e("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=e("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(bh,{control:t,index:m,remove:o,watch:e,variableOptions:d,yAxisOptions:h})},x.id))]})}const vh=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}],wh=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function Ch({control:t,regressionItem:e,index:n,remove:r,yAxisOptions:i}){const o=e.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:t,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:t,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:t,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:t,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:t,render:({field:l})=>s.jsx(a.Select,{label:"Method",data:vh,sx:{flex:1},...l})}),o==="polynomial"&&s.jsx(b.Controller,{name:`regressions.${n}.transform.config.order`,control:t,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:t,render:({field:l})=>s.jsx(a.Select,{label:"Line Type",data:wh,sx:{flexGrow:1},...l})}),s.jsx(b.Controller,{name:`regressions.${n}.plot.lineStyle.width`,control:t,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:t,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 Sh({control:t,watch:e}){const{fields:n,append:r,remove:i}=b.useFieldArray({control:t,name:"regressions"}),o=e("regressions"),l=n.map((p,h)=>({...p,...o[h]})),c=e("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(Ch,{regressionItem:p,control:t,index:h,remove:i,yAxisOptions:u})},p.id))]})}const Es={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
118
+ `)}},Ps={fontSize:"14px",lineHeight:"32px",color:"#3D3E45",ul:{paddingLeft:"2em",margin:"6px 0 0"},p:{margin:0},a:{WebkitTapHighlightColor:"transparent",color:"rgb(34, 139, 230)",textDecoration:"none","&:hover":{textDecoration:"underline"},"&:active, &:hover":{outlineWidth:0}},table:{tr:{"th, td":{padding:"0 .5em"}}},"table.rich-text-table-render, div.tableWrapper table":{"th, td":{border:"1px solid #eaeaea"},"tr:last-of-type td":{borderBottom:"1px solid #eaeaea"}},".resize-cursor":{cursor:"col-resize"},details:{summary:{listStyle:"none",cursor:"pointer",transition:"color 300ms ease",userSelect:"none"},"summary::-webkit-details-marker":{display:"none"},"summary:hover":{color:"black","&::before":{opacity:1}},"summary::before":{content:'"►"',fontSize:"10px",margin:"0px 5px",opacity:.5,display:"inline-block",transition:"opacity 300ms ease, transform 300ms ease"}},"details[open] summary::before":{transform:"rotate(90deg)"},"details + details":{marginTop:"10px"},blockquote:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45",margin:"0 0 14px"}};function Qi(t,e,n){for(let r=0;;r++){if(r==t.childCount||r==e.childCount)return t.childCount==e.childCount?null:n;let i=t.child(r),o=e.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=Qi(i.content,o.content,n+1);if(l!=null)return l}n+=i.nodeSize}}function Ui(t,e,n,r){for(let i=t.childCount,o=e.childCount;;){if(i==0||o==0)return i==o?null:{a:n,b:r};let l=t.child(--i),c=e.child(--o),u=l.nodeSize;if(l==c){n-=u,r-=u;continue}if(!l.sameMarkup(c))return{a:n,b:r};if(l.isText&&l.text!=c.text){let d=0,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=Ui(l.content,c.content,n-1,r-1);if(d)return d}n-=u,r-=u}}class J{constructor(e,n){if(this.content=e,this.size=n||0,n==null)for(let r=0;r<e.length;r++)this.size+=e[r].nodeSize}nodesBetween(e,n,r,i=0,o){for(let l=0,c=0;c<n;l++){let u=this.content[l],d=c+u.nodeSize;if(d>e&&r(u,i+c,o||null,l)!==!1&&u.content.size){let p=c+1;u.nodesBetween(Math.max(0,e-p),Math.min(u.content.size,n-p),r,i+p)}c=d}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,n,r,i){let o="",l=!0;return this.nodesBetween(e,n,(c,u)=>{c.isText?(o+=c.text.slice(Math.max(e,u)-u,n-u),l=!r):c.isLeaf?(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(e){if(!e.size)return this;if(!this.size)return e;let n=this.lastChild,r=e.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<e.content.length;o++)i.push(e.content[o]);return new J(i,this.size+e.size)}cut(e,n=this.size){if(e==0&&n==this.size)return this;let r=[],i=0;if(n>e)for(let o=0,l=0;l<n;o++){let c=this.content[o],u=l+c.nodeSize;u>e&&((l<e||u>n)&&(c.isText?c=c.cut(Math.max(0,e-l),Math.min(c.text.length,n-l)):c=c.cut(Math.max(0,e-l-1),Math.min(c.content.size,n-l-1))),r.push(c),i+=c.nodeSize),l=u}return new J(r,i)}cutByIndex(e,n){return e==n?J.empty:e==0&&n==this.content.length?this:new J(this.content.slice(e,n))}replaceChild(e,n){let r=this.content[e];if(r==n)return this;let i=this.content.slice(),o=this.size+n.nodeSize-r.nodeSize;return i[e]=n,new J(i,o)}addToStart(e){return new J([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new J(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let n=0;n<this.content.length;n++)if(!this.content[n].eq(e.content[n]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let n=this.content[e];if(!n)throw new RangeError("Index "+e+" out of range for "+this);return n}maybeChild(e){return this.content[e]||null}forEach(e){for(let n=0,r=0;n<this.content.length;n++){let i=this.content[n];e(i,r,n),r+=i.nodeSize}}findDiffStart(e,n=0){return Qi(this,e,n)}findDiffEnd(e,n=this.size,r=e.size){return Ui(this,e,n,r)}findIndex(e,n=-1){if(e==0)return bn(0,e);if(e==this.size)return bn(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,i=0;;r++){let o=this.child(r),l=i+o.nodeSize;if(l>=e)return l==e||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(e=>e.toJSON()):null}static fromJSON(e,n){if(!n)return J.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new J(n.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return J.empty;let n,r=0;for(let i=0;i<e.length;i++){let o=e[i];r+=o.nodeSize,i&&o.isText&&e[i-1].sameMarkup(o)?(n||(n=e.slice(0,i)),n[n.length-1]=o.withText(n[n.length-1].text+o.text)):n&&n.push(o)}return new J(n||e,r)}static from(e){if(!e)return J.empty;if(e instanceof J)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new J([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}J.empty=new J([],0);const Ls={index:0,offset:0};function bn(t,e){return Ls.index=t,Ls.offset=e,Ls}function Bs(t,e){if(t===e)return!0;if(!(t&&typeof t=="object")||!(e&&typeof e=="object"))return!1;let n=Array.isArray(t);if(Array.isArray(e)!=n)return!1;if(n){if(t.length!=e.length)return!1;for(let r=0;r<t.length;r++)if(!Bs(t[r],e[r]))return!1}else{for(let r in t)if(!(r in e)||!Bs(t[r],e[r]))return!1;for(let r in e)if(!(r in t))return!1}return!0}class Ee{constructor(e,n){this.type=e,this.attrs=n}addToSet(e){let n,r=!1;for(let i=0;i<e.length;i++){let o=e[i];if(this.eq(o))return e;if(this.type.excludes(o.type))n||(n=e.slice(0,i));else{if(o.type.excludes(this.type))return e;!r&&o.type.rank>this.type.rank&&(n||(n=e.slice(0,i)),n.push(this),r=!0),n&&n.push(o)}}return n||(n=e.slice()),r||n.push(this),n}removeFromSet(e){for(let n=0;n<e.length;n++)if(this.eq(e[n]))return e.slice(0,n).concat(e.slice(n+1));return e}isInSet(e){for(let n=0;n<e.length;n++)if(this.eq(e[n]))return!0;return!1}eq(e){return this==e||this.type==e.type&&Bs(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let n in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Mark.fromJSON");let r=e.marks[n.type];if(!r)throw new RangeError(`There is no mark type ${n.type} in this schema`);return r.create(n.attrs)}static sameSet(e,n){if(e==n)return!0;if(e.length!=n.length)return!1;for(let r=0;r<e.length;r++)if(!e[r].eq(n[r]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&e.length==0)return Ee.none;if(e instanceof Ee)return[e];let n=e.slice();return n.sort((r,i)=>r.type.rank-i.type.rank),n}}Ee.none=[];class _h extends Error{}class H{constructor(e,n,r){this.content=e,this.openStart=n,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,n){let r=Ki(this.content,e+this.openStart,n);return r&&new H(r,this.openStart,this.openEnd)}removeBetween(e,n){return new H(Yi(this.content,e+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,n){if(!n)return 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(e,n.content),r,i)}static maxOpen(e,n=!0){let r=0,i=0;for(let o=e.firstChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=e.lastChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.lastChild)i++;return new H(e,r,i)}}H.empty=new H(J.empty,0,0);function Yi(t,e,n){let{index:r,offset:i}=t.findIndex(e),o=t.maybeChild(r),{index:l,offset:c}=t.findIndex(n);if(i==e||o.isText){if(c!=n&&!t.child(l).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(n))}if(r!=l)throw new RangeError("Removing non-flat range");return t.replaceChild(r,o.copy(Yi(o.content,e-i-1,n-i-1)))}function Ki(t,e,n,r){let{index:i,offset:o}=t.findIndex(e),l=t.maybeChild(i);if(o==e||l.isText)return r&&!r.canReplace(i,i,n)?null:t.cut(0,e).append(n).append(t.cut(e));let c=Ki(l.content,e-o-1,n);return c&&t.replaceChild(i,l.copy(c))}class jn{constructor(e,n){this.schema=e,this.rules=n,this.tags=[],this.styles=[],n.forEach(r=>{r.tag?this.tags.push(r):r.style&&this.styles.push(r)}),this.normalizeLists=!this.tags.some(r=>{if(!/^(ul|ol)\b/.test(r.tag)||!r.node)return!1;let i=e.nodes[r.node];return i.contentMatch.matchType(i)})}parse(e,n={}){let r=new Hi(this,n,!1);return r.addAll(e,n.from,n.to),r.finish()}parseSlice(e,n={}){let r=new Hi(this,n,!0);return r.addAll(e,n.from,n.to),H.maxOpen(r.finish())}matchTag(e,n,r){for(let i=r?this.tags.indexOf(r)+1:0;i<this.tags.length;i++){let o=this.tags[i];if(Ih(e,o.tag)&&(o.namespace===void 0||e.namespaceURI==o.namespace)&&(!o.context||n.matchesContext(o.context))){if(o.getAttrs){let l=o.getAttrs(e);if(l===!1)continue;o.attrs=l||void 0}return o}}}matchStyle(e,n,r,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(e)!=0||l.context&&!r.matchesContext(l.context)||c.length>e.length&&(c.charCodeAt(e.length)!=61||c.slice(e.length+1)!=n))){if(l.getAttrs){let u=l.getAttrs(n);if(u===!1)continue;l.attrs=u||void 0}return l}}}static schemaRules(e){let n=[];function r(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 e.marks){let o=e.marks[i].spec.parseDOM;o&&o.forEach(l=>{r(l=ea(l)),l.mark||l.ignore||l.clearMark||(l.mark=i)})}for(let i in e.nodes){let o=e.nodes[i].spec.parseDOM;o&&o.forEach(l=>{r(l=ea(l)),l.node||l.ignore||l.mark||(l.node=i)})}return n}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new jn(e,jn.schemaRules(e)))}}const Xi={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},kh={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Ji={ol:!0,ul:!0},vn=1,wn=2,Yt=4;function Zi(t,e,n){return e!=null?(e?vn:0)|(e==="full"?wn:0):t&&t.whitespace=="pre"?vn|wn:n&~Yt}class Cn{constructor(e,n,r,i,o,l,c){this.type=e,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:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(J.from(e));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){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!e&&this.match&&(n=n.append(this.match.fillBefore(J.empty,!0))),this.type?this.type.create(this.attrs,n,this.marks):n}popFromStashMark(e){for(let n=this.stashMarks.length-1;n>=0;n--)if(e.eq(this.stashMarks[n]))return this.stashMarks.splice(n,1)[0]}applyPending(e){for(let n=0,r=this.pendingMarks;n<r.length;n++){let i=r[n];(this.type?this.type.allowsMarkType(i.type):Mh(i.type,e))&&!i.isInSet(this.activeMarks)&&(this.activeMarks=i.addToSet(this.activeMarks),this.pendingMarks=i.removeFromSet(this.pendingMarks))}}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!Xi.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class Hi{constructor(e,n,r){this.parser=e,this.options=n,this.isOpen=r,this.open=0;let i=n.topNode,o,l=Zi(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(e.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(e){if(e.nodeType==3)this.addTextNode(e);else if(e.nodeType==1){let n=e.getAttribute("style");if(!n)this.addElement(e);else{let r=this.readStyles(Dh(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(e);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(e){let n=e.nodeValue,r=this.top;if(r.options&wn||r.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(r.options&vn)r.options&wn?n=n.replace(/\r\n?/g,`
119
+ `):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=e.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(e)}else this.findInside(e)}addElement(e,n){let r=e.nodeName.toLowerCase(),i;Ji.hasOwnProperty(r)&&this.parser.normalizeLists&&Th(e);let o=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(i=this.parser.matchTag(e,this,n));if(o?o.ignore:kh.hasOwnProperty(r))this.findInside(e),this.ignoreFallback(e);else if(!o||o.skip||o.closeParent){o&&o.closeParent?this.open=Math.max(0,this.open-1):o&&o.skip.nodeType&&(e=o.skip);let l,c=this.top,u=this.needsBlock;if(Xi.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(!e.firstChild){this.leafFallback(e);return}this.addAll(e),l&&this.sync(c),this.needsBlock=u}else this.addElementByRule(e,o,o.consuming===!1?i:void 0)}leafFallback(e){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(`
120
+ `))}ignoreFallback(e){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"))}readStyles(e){let n=Ee.none,r=Ee.none;for(let i=0;i<e.length;i+=2)for(let o=void 0;;){let l=this.parser.matchStyle(e[i],e[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(e,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(e):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(e);else if(r)this.addElement(e,r);else if(n.getContent)this.findInside(e),n.getContent(e,this.parser.schema).forEach(u=>this.insertNode(u));else{let u=e;typeof n.contentElement=="string"?u=e.querySelector(n.contentElement):typeof n.contentElement=="function"?u=n.contentElement(e):n.contentElement&&(u=n.contentElement),this.findAround(e,u,!0),this.addAll(u)}i&&this.sync(c)&&this.open--,l&&this.removePendingMark(l,c)}addAll(e,n,r){let i=n||0;for(let o=n?e.childNodes[n]:e.firstChild,l=r==null?null:e.childNodes[r];o!=l;o=o.nextSibling,++i)this.findAtPoint(e,i),this.addDOM(o);this.findAtPoint(e,i)}findPlace(e){let n,r;for(let i=this.open;i>=0;i--){let o=this.nodes[i],l=o.findWrapping(e);if(l&&(!n||n.length>l.length)&&(n=l,r=o,!l.length)||o.solid)break}if(!n)return!1;this.sync(r);for(let i=0;i<n.length;i++)this.enterInner(n[i],null,!1);return!0}insertNode(e){if(e.isInline&&this.needsBlock&&!this.top.type){let n=this.textblockFromContext();n&&this.enterInner(n)}if(this.findPlace(e)){this.closeExtra();let n=this.top;n.applyPending(e.type),n.match&&(n.match=n.match.matchType(e.type));let r=n.activeMarks;for(let i=0;i<e.marks.length;i++)(!n.type||n.type.allowsMarkType(e.marks[i].type))&&(r=e.marks[i].addToSet(r));return n.content.push(e.mark(r)),!0}return!1}enter(e,n,r){let i=this.findPlace(e.create(n));return i&&this.enterInner(e,n,!0,r),i}enterInner(e,n=null,r=!1,i){this.closeExtra();let o=this.top;o.applyPending(e),o.match=o.match&&o.match.matchType(e);let l=Zi(e,i,o.options);o.options&Yt&&o.content.length==0&&(l|=Yt),this.nodes.push(new Cn(e,n,o.activeMarks,o.pendingMarks,r,null,l)),this.open++}closeExtra(e=!1){let n=this.nodes.length-1;if(n>this.open){for(;n>this.open;n--)this.nodes[n-1].content.push(this.nodes[n].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(e){for(let n=this.open;n>=0;n--)if(this.nodes[n]==e)return this.open=n,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let n=this.open;n>=0;n--){let r=this.nodes[n].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;n&&e++}return e}findAtPoint(e,n){if(this.find)for(let r=0;r<this.find.length;r++)this.find[r].node==e&&this.find[r].offset==n&&(this.find[r].pos=this.currentPos)}findInside(e){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].pos==null&&e.nodeType==1&&e.contains(this.find[n].node)&&(this.find[n].pos=this.currentPos)}findAround(e,n,r){if(e!=n&&this.find)for(let i=0;i<this.find.length;i++)this.find[i].pos==null&&e.nodeType==1&&e.contains(this.find[i].node)&&n.compareDocumentPosition(this.find[i].node)&(r?2:4)&&(this.find[i].pos=this.currentPos)}findInText(e){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==e&&(this.find[n].pos=this.currentPos-(e.nodeValue.length-this.find[n].offset))}matchesContext(e){if(e.indexOf("|")>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let n=e.split("/"),r=this.options.context,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 e=this.options.context;if(e)for(let n=e.depth;n>=0;n--){let r=e.node(n).contentMatchAt(e.indexAfter(n)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let n in this.parser.schema.nodes){let r=this.parser.schema.nodes[n];if(r.isTextblock&&r.defaultAttrs)return r}}addPendingMark(e){let n=Ah(e,this.top.pendingMarks);n&&this.top.stashMarks.push(n),this.top.pendingMarks=e.addToSet(this.top.pendingMarks)}removePendingMark(e,n){for(let r=this.open;r>=0;r--){let i=this.nodes[r];if(i.pendingMarks.lastIndexOf(e)>-1)i.pendingMarks=e.removeFromSet(i.pendingMarks);else{i.activeMarks=e.removeFromSet(i.activeMarks);let l=i.popFromStashMark(e);l&&i.type&&i.type.allowsMarkType(l.type)&&(i.activeMarks=l.addToSet(i.activeMarks))}if(i==n)break}}}function Th(t){for(let e=t.firstChild,n=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&Ji.hasOwnProperty(r)&&n?(n.appendChild(e),e=n):r=="li"?n=e:r&&(n=null)}}function Ih(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function Dh(t){let e=/\s*([\w-]+)\s*:\s*([^;]+)/g,n,r=[];for(;n=e.exec(t);)r.push(n[1],n[2].trim());return r}function ea(t){let e={};for(let n in t)e[n]=t[n];return e}function Mh(t,e){let n=e.schema.nodes;for(let r in n){let i=n[r];if(!i.allowsMarkType(t))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==e||o.indexOf(p)<0&&l(p))return!0}};if(l(i.contentMatch))return!0}}function Ah(t,e){for(let n=0;n<e.length;n++)if(t.eq(e[n]))return e[n]}const ta=65535,na=Math.pow(2,16);function zh(t,e){return t+e*na}function sa(t){return t&ta}function Eh(t){return(t-(t&ta))/na}const ra=1,ia=2,Sn=4,aa=8;class oa{constructor(e,n,r){this.pos=e,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&aa)>0}get deletedBefore(){return(this.delInfo&(ra|Sn))>0}get deletedAfter(){return(this.delInfo&(ia|Sn))>0}get deletedAcross(){return(this.delInfo&Sn)>0}}class qe{constructor(e,n=!1){if(this.ranges=e,this.inverted=n,!e.length&&qe.empty)return qe.empty}recover(e){let n=0,r=sa(e);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+Eh(e)}mapResult(e,n=1){return this._map(e,n,!1)}map(e,n=1){return this._map(e,n,!0)}_map(e,n,r){let 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>e)break;let d=this.ranges[c+o],p=this.ranges[c+l],h=u+d;if(e<=h){let x=d?e==u?-1:e==h?1:n:n,m=u+i+(x<0?0:p);if(r)return m;let j=e==(n<0?u:h)?null:zh(c/3,e-u),C=e==u?ia:e==h?ra:Sn;return(n<0?e!=u:e!=h)&&(C|=aa),new oa(m,C,j)}i+=p-d}return r?e+i:new oa(e+i,0,null)}touches(e,n){let r=0,i=sa(n),o=this.inverted?2:1,l=this.inverted?1:2;for(let c=0;c<this.ranges.length;c+=3){let u=this.ranges[c]-(this.inverted?r:0);if(u>e)break;let d=this.ranges[c+o],p=u+d;if(e<=p&&c==i*3)return!0;r+=this.ranges[c+l]-d}return!1}forEach(e){let n=this.inverted?2:1,r=this.inverted?1:2;for(let 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];e(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(e){return e==0?qe.empty:new qe(e<0?[0,-e,0]:[0,0,e])}}qe.empty=new qe([]);const Os=Object.create(null);class Ie{getMap(){return qe.empty}merge(e){return null}static fromJSON(e,n){if(!n||!n.stepType)throw new RangeError("Invalid input for Step.fromJSON");let r=Os[n.stepType];if(!r)throw new RangeError(`No step type ${n.stepType} defined`);return r.fromJSON(e,n)}static jsonID(e,n){if(e in Os)throw new RangeError("Duplicate use of step JSON ID "+e);return Os[e]=n,n.prototype.jsonID=e,n}}class he{constructor(e,n){this.doc=e,this.failed=n}static ok(e){return new he(e,null)}static fail(e){return new he(null,e)}static fromReplace(e,n,r,i){try{return he.ok(e.replace(n,r,i))}catch(o){if(o instanceof _h)return he.fail(o.message);throw o}}}function $s(t,e,n){let r=[];for(let i=0;i<t.childCount;i++){let o=t.child(i);o.content.size&&(o=o.copy($s(o.content,e,o))),o.isInline&&(o=e(o,n,i)),r.push(o)}return J.fromArray(r)}class yt extends Ie{constructor(e,n,r){super(),this.from=e,this.to=n,this.mark=r}apply(e){let n=e.slice(this.from,this.to),r=e.resolve(this.from),i=r.node(r.sharedDepth(this.to)),o=new H($s(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(e,this.from,this.to,o)}invert(){return new bt(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new yt(n.pos,r.pos,this.mark)}merge(e){return e instanceof yt&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new yt(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new yt(n.from,n.to,e.markFromJSON(n.mark))}}Ie.jsonID("addMark",yt);class bt extends Ie{constructor(e,n,r){super(),this.from=e,this.to=n,this.mark=r}apply(e){let n=e.slice(this.from,this.to),r=new H($s(n.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),n.openStart,n.openEnd);return he.fromReplace(e,this.from,this.to,r)}invert(){return new yt(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new bt(n.pos,r.pos,this.mark)}merge(e){return e instanceof bt&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new bt(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new bt(n.from,n.to,e.markFromJSON(n.mark))}}Ie.jsonID("removeMark",bt);class jt extends Ie{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.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(e,this.pos,this.pos+1,new H(J.from(r),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);if(n){let r=this.mark.addToSet(n.marks);if(r.length==n.marks.length){for(let 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(e){let n=e.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(e,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new jt(n.pos,e.markFromJSON(n.mark))}}Ie.jsonID("addNodeMark",jt);class Kt extends Ie{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.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(e,this.pos,this.pos+1,new H(J.from(r),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);return!n||!this.mark.isInSet(n.marks)?this:new jt(this.pos,this.mark)}map(e){let n=e.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(e,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new Kt(n.pos,e.markFromJSON(n.mark))}}Ie.jsonID("removeNodeMark",Kt);class Ze extends Ie{constructor(e,n,r,i=!1){super(),this.from=e,this.to=n,this.slice=r,this.structure=i}apply(e){return this.structure&&Vs(e,this.from,this.to)?he.fail("Structure replace would overwrite content"):he.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new qe([this.from,this.to-this.from,this.slice.size])}invert(e){return new Ze(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deletedAcross&&r.deletedAcross?null:new Ze(n.pos,Math.max(n.pos,r.pos),this.slice)}merge(e){if(!(e instanceof Ze)||e.structure||this.structure)return null;if(this.from+this.slice.size==e.from&&!this.slice.openEnd&&!e.slice.openStart){let n=this.slice.size+e.slice.size==0?H.empty:new H(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new Ze(this.from,this.to+(e.to-e.from),n,this.structure)}else if(e.to==this.from&&!this.slice.openStart&&!e.slice.openEnd){let n=this.slice.size+e.slice.size==0?H.empty:new H(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new Ze(e.from,this.to,n,this.structure)}else return null}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new Ze(n.from,n.to,H.fromJSON(e,n.slice),!!n.structure)}}Ie.jsonID("replace",Ze);class vt extends Ie{constructor(e,n,r,i,o,l,c=!1){super(),this.from=e,this.to=n,this.gapFrom=r,this.gapTo=i,this.slice=o,this.insert=l,this.structure=c}apply(e){if(this.structure&&(Vs(e,this.from,this.gapFrom)||Vs(e,this.gapTo,this.to)))return he.fail("Structure gap-replace would overwrite content");let n=e.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(e,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(e){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,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1),i=e.map(this.gapFrom,-1),o=e.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 e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number"||typeof n.gapFrom!="number"||typeof n.gapTo!="number"||typeof n.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new vt(n.from,n.to,n.gapFrom,n.gapTo,H.fromJSON(e,n.slice),n.insert,!!n.structure)}}Ie.jsonID("replaceAround",vt);function Vs(t,e,n){let r=t.resolve(e),i=n-e,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 Ph(t,e,n){return(e==0||t.canReplace(e,t.childCount))&&(n==t.childCount||t.canReplace(0,n))}function Lh(t){let n=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let r=t.depth;;--r){let i=t.$from.node(r),o=t.$from.index(r),l=t.$to.indexAfter(r);if(r<t.depth&&i.canReplace(o,l,n))return r;if(r==0||i.type.spec.isolating||!Ph(i,o,l))break}return null}function _n(t,e,n=1,r){let i=t.resolve(e),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 C=r&&r[p]||h;if(!h.canReplace(x+1,h.childCount)||!C.type.validContent(m))return!1}let c=i.indexAfter(o),u=r&&r[0];return i.node(o).canReplaceWith(c,c,u?u.type:i.node(o+1).type)}function la(t,e){let n=t.resolve(e),r=n.index();return Bh(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function Bh(t,e){return!!(t&&e&&!t.isLeaf&&t.canAppend(e))}class Xt extends Ie{constructor(e,n,r){super(),this.pos=e,this.attr=n,this.value=r}apply(e){let n=e.nodeAt(this.pos);if(!n)return 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(e,this.pos,this.pos+1,new H(J.from(i),0,n.isLeaf?0:1))}getMap(){return qe.empty}invert(e){return new Xt(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new Xt(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.pos!="number"||typeof n.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new Xt(n.pos,n.attr,n.value)}}Ie.jsonID("attr",Xt);let Jt=class extends Error{};Jt=function t(e){let n=Error.call(this,e);return n.__proto__=t.prototype,n},Jt.prototype=Object.create(Error.prototype),Jt.prototype.constructor=Jt,Jt.prototype.name="TransformError";const Ns=Object.create(null);class ne{constructor(e,n,r){this.$anchor=e,this.$head=n,this.ranges=r||[new Oh(e.min(n),e.max(n))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let n=0;n<e.length;n++)if(e[n].$from.pos!=e[n].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(e,n=H.empty){let r=n.content.lastChild,i=null;for(let c=0;c<n.openEnd;c++)i=r,r=r.lastChild;let o=e.steps.length,l=this.ranges;for(let c=0;c<l.length;c++){let{$from:u,$to:d}=l[c],p=e.mapping.slice(o);e.replaceRange(p.map(u.pos),p.map(d.pos),c?H.empty:n),c==0&&da(e,o,(r?r.isInline:i&&i.isTextblock)?-1:1)}}replaceWith(e,n){let r=e.steps.length,i=this.ranges;for(let o=0;o<i.length;o++){let{$from:l,$to:c}=i[o],u=e.mapping.slice(r),d=u.map(l.pos),p=u.map(c.pos);o?e.deleteRange(d,p):(e.replaceRangeWith(d,p,n),da(e,r,n.isInline?-1:1))}}static findFrom(e,n,r=!1){let i=e.parent.inlineContent?new xe(e):Et(e.node(0),e.parent,e.pos,e.index(),n,r);if(i)return i;for(let o=e.depth-1;o>=0;o--){let l=n<0?Et(e.node(0),e.node(o),e.before(o+1),e.index(o),n,r):Et(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,n,r);if(l)return l}return null}static near(e,n=1){return this.findFrom(e,n)||this.findFrom(e,-n)||new at(e.node(0))}static atStart(e){return Et(e,e,0,0,1)||new at(e)}static atEnd(e){return Et(e,e,e.content.size,e.childCount,-1)||new at(e)}static fromJSON(e,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=Ns[n.type];if(!r)throw new RangeError(`No selection type ${n.type} defined`);return r.fromJSON(e,n)}static jsonID(e,n){if(e in Ns)throw new RangeError("Duplicate use of selection JSON ID "+e);return Ns[e]=n,n.prototype.jsonID=e,n}getBookmark(){return xe.between(this.$anchor,this.$head).getBookmark()}}ne.prototype.visible=!0;class Oh{constructor(e,n){this.$from=e,this.$to=n}}let ca=!1;function ua(t){!ca&&!t.parent.inlineContent&&(ca=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")"))}class xe extends ne{constructor(e,n=e){ua(e),ua(n),super(e,n)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,n){let r=e.resolve(n.map(this.head));if(!r.parent.inlineContent)return ne.near(r);let i=e.resolve(n.map(this.anchor));return new xe(i.parent.inlineContent?i:r,r)}replace(e,n=H.empty){if(super.replace(e,n),n==H.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof xe&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new kn(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,n){if(typeof n.anchor!="number"||typeof n.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new xe(e.resolve(n.anchor),e.resolve(n.head))}static create(e,n,r=n){let i=e.resolve(n);return new this(i,r==n?i:e.resolve(r))}static between(e,n,r){let i=e.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 e.parent.inlineContent||(i==0?e=n:(e=(ne.findFrom(e,-r,!0)||ne.findFrom(e,r,!0)).$anchor,e.pos<n.pos!=i<0&&(e=n))),new xe(e,n)}}ne.jsonID("text",xe);class kn{constructor(e,n){this.anchor=e,this.head=n}map(e){return new kn(e.map(this.anchor),e.map(this.head))}resolve(e){return xe.between(e.resolve(this.anchor),e.resolve(this.head))}}class Pe extends ne{constructor(e){let n=e.nodeAfter,r=e.node(0).resolve(e.pos+n.nodeSize);super(e,r),this.node=n}map(e,n){let{deleted:r,pos:i}=n.mapResult(this.anchor),o=e.resolve(i);return r?ne.near(o):new Pe(o)}content(){return new H(J.from(this.node),0,0)}eq(e){return e instanceof Pe&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new qs(this.anchor)}static fromJSON(e,n){if(typeof n.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new Pe(e.resolve(n.anchor))}static create(e,n){return new Pe(e.resolve(n))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}}Pe.prototype.visible=!1,ne.jsonID("node",Pe);class qs{constructor(e){this.anchor=e}map(e){let{deleted:n,pos:r}=e.mapResult(this.anchor);return n?new kn(r,r):new qs(r)}resolve(e){let n=e.resolve(this.anchor),r=n.nodeAfter;return r&&Pe.isSelectable(r)?new Pe(n):ne.near(n)}}class at extends ne{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,n=H.empty){if(n==H.empty){e.delete(0,e.doc.content.size);let r=ne.atStart(e.doc);r.eq(e.selection)||e.setSelection(r)}else super.replace(e,n)}toJSON(){return{type:"all"}}static fromJSON(e){return new at(e)}map(e){return new at(e)}eq(e){return e instanceof at}getBookmark(){return $h}}ne.jsonID("all",at);const $h={map(){return this},resolve(t){return new at(t)}};function Et(t,e,n,r,i,o=!1){if(e.inlineContent)return xe.create(t,n);for(let l=r-(i>0?0:1);i>0?l<e.childCount:l>=0;l+=i){let c=e.child(l);if(c.isAtom){if(!o&&Pe.isSelectable(c))return Pe.create(t,n-(i<0?c.nodeSize:0))}else{let u=Et(t,c,n+i,i<0?c.childCount:0,i,o);if(u)return u}n+=c.nodeSize*i}return null}function da(t,e,n){let r=t.steps.length-1;if(r<e)return;let i=t.steps[r];if(!(i instanceof Ze||i instanceof vt))return;let o=t.mapping.maps[r],l;o.forEach((c,u,d,p)=>{l==null&&(l=p)}),t.setSelection(ne.near(t.doc.resolve(l),n))}function pa(t,e){return!e||!t?t:t.bind(e)}class Tn{constructor(e,n,r){this.name=e,this.init=pa(n.init,r),this.apply=pa(n.apply,r)}}new Tn("doc",{init(t){return t.doc||t.schema.topNodeType.createAndFill()},apply(t){return t.doc}}),new Tn("selection",{init(t,e){return t.selection||ne.atStart(e.doc)},apply(t){return t.selection}}),new Tn("storedMarks",{init(t){return t.storedMarks||null},apply(t,e,n,r){return r.selection.$cursor?t.storedMarks:null}}),new Tn("scrollToSelection",{init(){return 0},apply(t,e){return t.scrolledIntoView?e+1:e}});function ha(t,e,n){for(let r in t){let i=t[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=ha(i,e,{})),n[r]=i}return n}class Zt{constructor(e){this.spec=e,this.props={},e.props&&ha(e.props,this,this.props),this.key=e.key?e.key.key:xa("plugin")}getState(e){return e[this.key]}}const Fs=Object.create(null);function xa(t){return t in Fs?t+"$"+ ++Fs[t]:(Fs[t]=0,t+"$")}class Ht{constructor(e="key"){this.key=xa(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}function fa(t){const{state:e,transaction:n}=t;let{selection:r}=n,{doc:i}=n,{storedMarks:o}=n;return{...e,apply:e.apply.bind(e),applyTransaction:e.applyTransaction.bind(e),filterTransaction:e.filterTransaction,plugins:e.plugins,schema:e.schema,reconfigure:e.reconfigure.bind(e),toJSON:e.toJSON.bind(e),get storedMarks(){return o},get selection(){return r},get doc(){return i},get tr(){return r=n.selection,i=n.doc,o=n.storedMarks,n}}}class Vh{constructor(e){this.editor=e.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=e.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){const{rawCommands:e,editor:n,state:r}=this,{view:i}=n,{tr:o}=r,l=this.buildProps(o);return Object.fromEntries(Object.entries(e).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(e,n=!0){const{rawCommands:r,editor:i,state:o}=this,{view:l}=i,c=[],u=!!e,d=e||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,(...C)=>{const T=this.buildProps(d,n),A=m(...C)(T);return c.push(A),h}])),run:p};return h}createCan(e){const{rawCommands:n,state:r}=this,i=!1,o=e||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(e,n=!0){const{rawCommands:r,editor:i,state:o}=this,{view:l}=i;o.storedMarks&&e.setStoredMarks(o.storedMarks);const c={tr:e,editor:i,view:l,state:fa({state:o,transaction:e}),dispatch:n?()=>{}:void 0,chain:()=>this.createChain(e),can:()=>this.createCan(e),get commands(){return Object.fromEntries(Object.entries(r).map(([u,d])=>[u,(...p)=>d(...p)(c)]))}};return c}}function pt(t,e,n){return t.config[e]===void 0&&t.parent?pt(t.parent,e,n):typeof t.config[e]=="function"?t.config[e].bind({...n,parent:t.parent?pt(t.parent,e,n):null}):t.config[e]}function Nh(t){const e=t.filter(i=>i.type==="extension"),n=t.filter(i=>i.type==="node"),r=t.filter(i=>i.type==="mark");return{baseExtensions:e,nodeExtensions:n,markExtensions:r}}function je(t,e){if(typeof t=="string"){if(!e.nodes[t])throw Error(`There is no node type named '${t}'. Maybe you forgot to add the extension?`);return e.nodes[t]}return t}function qh(t){return typeof t=="function"}function Pt(t,e=void 0,...n){return qh(t)?e?t.bind(e)(...n):t(...n):t}function Fh(t){return Object.prototype.toString.call(t)==="[object RegExp]"}function Gh(t){return Object.prototype.toString.call(t).slice(8,-1)}function Gs(t){return Gh(t)!=="Object"?!1:t.constructor===Object&&Object.getPrototypeOf(t)===Object.prototype}function ga(t,e){const n={...t};return Gs(t)&&Gs(e)&&Object.keys(e).forEach(r=>{Gs(e[r])?r in t?n[r]=ga(t[r],e[r]):Object.assign(n,{[r]:e[r]}):Object.assign(n,{[r]:e[r]})}),n}class He{constructor(e={}){this.type="extension",this.name="extension",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=Pt(pt(this,"addOptions",{name:this.name}))),this.storage=Pt(pt(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new He(e)}configure(e={}){const n=this.extend();return n.options=ga(this.options,e),n.storage=Pt(pt(n,"addStorage",{name:n.name,options:n.options})),n}extend(e={}){const n=new He(e);return n.parent=this,this.child=n,n.name=e.name?e.name:n.parent.name,e.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${n.name}".`),n.options=Pt(pt(n,"addOptions",{name:n.name})),n.storage=Pt(pt(n,"addStorage",{name:n.name,options:n.options})),n}}function Wh(t,e,n){const{from:r,to:i}=e,{blockSeparator:o=`
121
+
122
+ `,textSerializers:l={}}=n||{};let c="",u=!0;return t.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:e}))):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 Rh(t){return Object.fromEntries(Object.entries(t.nodes).filter(([,e])=>e.spec.toText).map(([e,n])=>[e,n.spec.toText]))}He.create({name:"clipboardTextSerializer",addProseMirrorPlugins(){return[new Zt({key:new Ht("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:t}=this,{state:e,schema:n}=t,{doc:r,selection:i}=e,{ranges:o}=i,l=Math.min(...o.map(p=>p.$from.pos)),c=Math.max(...o.map(p=>p.$to.pos)),u=Rh(n);return Wh(r,{from:l,to:c},{textSerializers:u})}}})]}});const Qh=()=>({editor:t,view:e})=>(requestAnimationFrame(()=>{var n;t.isDestroyed||(e.dom.blur(),(n=window==null?void 0:window.getSelection())===null||n===void 0||n.removeAllRanges())}),!0),Uh=(t=!1)=>({commands:e})=>e.setContent("",t),Yh=()=>({state:t,tr:e,dispatch:n})=>{const{selection:r}=e,{ranges:i}=r;return n&&i.forEach(({$from:o,$to:l})=>{t.doc.nodesBetween(o.pos,l.pos,(c,u)=>{if(c.type.isText)return;const{doc:d,mapping:p}=e,h=d.resolve(p.map(u)),x=d.resolve(p.map(u+c.nodeSize)),m=h.blockRange(x);if(!m)return;const j=Lh(m);if(c.type.isTextblock){const{defaultType:C}=h.parent.contentMatchAt(h.index());e.setNodeMarkup(m.start,C)}(j||j===0)&&e.lift(m,j)})}),!0},Kh=t=>e=>t(e),Xh=()=>({state:t,dispatch:e})=>me.createParagraphNear(t,e),Jh=()=>({tr:t,dispatch:e})=>{const{selection:n}=t,r=n.$anchor.node();if(r.content.size>0)return!1;const i=t.selection.$anchor;for(let o=i.depth;o>0;o-=1)if(i.node(o).type===r.type){if(e){const c=i.before(o),u=i.after(o);t.delete(c,u).scrollIntoView()}return!0}return!1},Zh=t=>({tr:e,state:n,dispatch:r})=>{const i=je(t,n.schema),o=e.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);e.delete(u,d).scrollIntoView()}return!0}return!1},Hh=t=>({tr:e,dispatch:n})=>{const{from:r,to:i}=t;return n&&e.delete(r,i),!0},ex=()=>({state:t,dispatch:e})=>me.deleteSelection(t,e),tx=()=>({commands:t})=>t.keyboardShortcut("Enter"),nx=()=>({state:t,dispatch:e})=>me.exitCode(t,e);function In(t,e,n={strict:!0}){const r=Object.keys(e);return r.length?r.every(i=>n.strict?e[i]===t[i]:Fh(e[i])?e[i].test(t[i]):e[i]===t[i]):!0}function Ws(t,e,n={}){return t.find(r=>r.type===e&&In(r.attrs,n))}function sx(t,e,n={}){return!!Ws(t,e,n)}function ma(t,e,n={}){if(!t||!e)return;let r=t.parent.childAfter(t.parentOffset);if(t.parentOffset===r.offset&&r.offset!==0&&(r=t.parent.childBefore(t.parentOffset)),!r.node)return;const i=Ws([...r.node.marks],e,n);if(!i)return;let o=r.index,l=t.start()+r.offset,c=o+1,u=l+r.node.nodeSize;for(Ws([...r.node.marks],e,n);o>0&&i.isInSet(t.parent.child(o-1).marks);)o-=1,l-=t.parent.child(o).nodeSize;for(;c<t.parent.childCount&&sx([...t.parent.child(c).marks],e,n);)u+=t.parent.child(c).nodeSize,c+=1;return{from:l,to:u}}function ht(t,e){if(typeof t=="string"){if(!e.marks[t])throw Error(`There is no mark type named '${t}'. Maybe you forgot to add the extension?`);return e.marks[t]}return t}const rx=(t,e={})=>({tr:n,state:r,dispatch:i})=>{const o=ht(t,r.schema),{doc:l,selection:c}=n,{$from:u,from:d,to:p}=c;if(i){const h=ma(u,o,e);if(h&&h.from<=d&&h.to>=p){const x=xe.create(l,h.from,h.to);n.setSelection(x)}}return!0},ix=t=>e=>{const n=typeof t=="function"?t(e):t;for(let r=0;r<n.length;r+=1)if(n[r](e))return!0;return!1};function ya(t){return t instanceof xe}function wt(t=0,e=0,n=0){return Math.min(Math.max(t,e),n)}function ax(t,e=null){if(!e)return null;const n=ne.atStart(t),r=ne.atEnd(t);if(e==="start"||e===!0)return n;if(e==="end")return r;const i=n.from,o=r.to;return e==="all"?xe.create(t,wt(0,i,o),wt(t.content.size,i,o)):xe.create(t,wt(e,i,o),wt(e,i,o))}function Rs(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}const ox=(t=null,e={})=>({editor:n,view:r,tr:i,dispatch:o})=>{e={scrollIntoView:!0,...e};const l=()=>{Rs()&&r.dom.focus(),requestAnimationFrame(()=>{n.isDestroyed||(r.focus(),e!=null&&e.scrollIntoView&&n.commands.scrollIntoView())})};if(r.hasFocus()&&t===null||t===!1)return!0;if(o&&t===null&&!ya(n.state.selection))return l(),!0;const c=ax(i.doc,t)||n.state.selection,u=n.state.selection.eq(c);return o&&(u||i.setSelection(c),u&&i.storedMarks&&i.setStoredMarks(i.storedMarks),l()),!0},lx=(t,e)=>n=>t.every((r,i)=>e(r,{...n,index:i})),cx=(t,e)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},t,e);function ba(t){const e=`<body>${t}</body>`;return new window.DOMParser().parseFromString(e,"text/html").body}function Dn(t,e,n){if(n={slice:!0,parseOptions:{},...n},typeof t=="object"&&t!==null)try{return Array.isArray(t)&&t.length>0?J.fromArray(t.map(r=>e.nodeFromJSON(r))):e.nodeFromJSON(t)}catch(r){return console.warn("[tiptap warn]: Invalid content.","Passed value:",t,"Error:",r),Dn("",e,n)}if(typeof t=="string"){const r=jn.fromSchema(e);return n.slice?r.parseSlice(ba(t),n.parseOptions).content:r.parse(ba(t),n.parseOptions)}return Dn("",e,n)}function ux(t,e,n){const r=t.steps.length-1;if(r<e)return;const i=t.steps[r];if(!(i instanceof Ze||i instanceof vt))return;const o=t.mapping.maps[r];let l=0;o.forEach((c,u,d,p)=>{l===0&&(l=p)}),t.setSelection(ne.near(t.doc.resolve(l),n))}const dx=t=>t.toString().startsWith("<"),px=(t,e,n)=>({tr:r,dispatch:i,editor:o})=>{if(i){n={parseOptions:{},updateSelection:!0,...n};const l=Dn(e,o.schema,{parseOptions:{preserveWhitespace:"full",...n.parseOptions}});if(l.toString()==="<>")return!0;let{from:c,to:u}=typeof t=="number"?{from:t,to:t}:t,d=!0,p=!0;if((dx(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(e)?r.insertText(e.map(x=>x.text||"").join(""),c,u):typeof e=="object"&&e&&e.text?r.insertText(e.text,c,u):r.insertText(e,c,u):r.replaceWith(c,u,l),n.updateSelection&&ux(r,r.steps.length-1,-1)}return!0},hx=()=>({state:t,dispatch:e})=>me.joinUp(t,e),xx=()=>({state:t,dispatch:e})=>me.joinDown(t,e),fx=()=>({state:t,dispatch:e})=>me.joinBackward(t,e),gx=()=>({state:t,dispatch:e})=>me.joinForward(t,e);function ja(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function mx(t){const e=t.split(/-(?!$)/);let n=e[e.length-1];n==="Space"&&(n=" ");let r,i,o,l;for(let c=0;c<e.length-1;c+=1){const u=e[c];if(/^(cmd|meta|m)$/i.test(u))l=!0;else if(/^a(lt)?$/i.test(u))r=!0;else if(/^(c|ctrl|control)$/i.test(u))i=!0;else if(/^s(hift)?$/i.test(u))o=!0;else if(/^mod$/i.test(u))Rs()||ja()?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 yx=t=>({editor:e,view:n,tr:r,dispatch:i})=>{const o=mx(t).split(/-(?!$)/),l=o.find(d=>!["Alt","Ctrl","Meta","Shift"].includes(d)),c=new KeyboardEvent("keydown",{key:l==="Space"?" ":l,altKey:o.includes("Alt"),ctrlKey:o.includes("Ctrl"),metaKey:o.includes("Meta"),shiftKey:o.includes("Shift"),bubbles:!0,cancelable:!0}),u=e.captureTransaction(()=>{n.someProp("handleKeyDown",d=>d(n,c))});return u==null||u.steps.forEach(d=>{const p=d.map(r.mapping);p&&i&&r.maybeStep(p)}),!0};function Qs(t,e,n={}){const{from:r,to:i,empty:o}=t.selection,l=e?je(e,t.schema):null,c=[];t.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=>In(h.node.attrs,n,{strict:!1}));return o?!!d.length:d.reduce((h,x)=>h+x.to-x.from,0)>=u}const bx=(t,e={})=>({state:n,dispatch:r})=>{const i=je(t,n.schema);return Qs(n,i,e)?me.lift(n,r):!1},jx=()=>({state:t,dispatch:e})=>me.liftEmptyBlock(t,e),vx=t=>({state:e,dispatch:n})=>{const r=je(t,e.schema);return ss.liftListItem(r)(e,n)},wx=()=>({state:t,dispatch:e})=>me.newlineInCode(t,e);function va(t,e){return e.nodes[t]?"node":e.marks[t]?"mark":null}function wa(t,e){const n=typeof e=="string"?[e]:e;return Object.keys(t).reduce((r,i)=>(n.includes(i)||(r[i]=t[i]),r),{})}const Cx=(t,e)=>({tr:n,state:r,dispatch:i})=>{let o=null,l=null;const c=va(typeof t=="string"?t:t.name,r.schema);return c?(c==="node"&&(o=je(t,r.schema)),c==="mark"&&(l=ht(t,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,wa(d.attrs,e)),l&&d.marks.length&&d.marks.forEach(h=>{l===h.type&&n.addMark(p,p+d.nodeSize,l.create(wa(h.attrs,e)))})})}),!0):!1},Sx=()=>({tr:t,dispatch:e})=>(e&&t.scrollIntoView(),!0),_x=()=>({tr:t,commands:e})=>e.setTextSelection({from:0,to:t.doc.content.size}),kx=()=>({state:t,dispatch:e})=>me.selectNodeBackward(t,e),Tx=()=>({state:t,dispatch:e})=>me.selectNodeForward(t,e),Ix=()=>({state:t,dispatch:e})=>me.selectParentNode(t,e),Dx=()=>({state:t,dispatch:e})=>me.selectTextblockEnd(t,e),Mx=()=>({state:t,dispatch:e})=>me.selectTextblockStart(t,e);function Ax(t,e,n={}){return Dn(t,e,{slice:!1,parseOptions:n})}const zx=(t,e=!1,n={})=>({tr:r,editor:i,dispatch:o})=>{const{doc:l}=r,c=Ax(t,i.schema,n);return o&&r.replaceWith(0,l.content.size,c).setMeta("preventUpdate",!e),!0};function Ex(t){for(let e=0;e<t.edgeCount;e+=1){const{type:n}=t.edge(e);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}function Px(t,e){for(let n=t.depth;n>0;n-=1){const r=t.node(n);if(e(r))return{pos:n>0?t.before(n):0,start:t.start(n),depth:n,node:r}}}function Us(t){return e=>Px(e.$from,t)}function Lx(t,e){const n=ht(e,t.schema),{from:r,to:i,empty:o}=t.selection,l=[];o?(t.storedMarks&&l.push(...t.storedMarks),l.push(...t.selection.$head.marks())):t.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(t,e,n){return Object.fromEntries(Object.entries(n).filter(([r])=>{const i=t.find(o=>o.type===e&&o.name===r);return i?i.attribute.keepOnSplit:!1}))}function Bx(t,e,n={}){const{empty:r,ranges:i}=t.selection,o=e?ht(e,t.schema):null;if(r)return!!(t.storedMarks||t.selection.$from.marks()).filter(h=>o?o.name===h.type.name:!0).find(h=>In(h.attrs,n,{strict:!1}));let l=0;const c=[];if(i.forEach(({$from:h,$to:x})=>{const m=h.pos,j=x.pos;t.doc.nodesBetween(m,j,(C,T)=>{if(!C.isText&&!C.marks.length)return;const A=Math.max(m,T),L=Math.min(j,T+C.nodeSize),U=L-A;l+=U,c.push(...C.marks.map(se=>({mark:se,from:A,to:L})))})}),l===0)return!1;const u=c.filter(h=>o?o.name===h.mark.type.name:!0).filter(h=>In(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 Ca(t,e){const{nodeExtensions:n}=Nh(e),r=n.find(l=>l.name===t);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 Ox(t,e,n){var r;const{selection:i}=e;let o=null;if(ya(i)&&(o=i.$cursor),o){const c=(r=t.storedMarks)!==null&&r!==void 0?r:o.marks();return!!n.isInSet(c)||!c.some(u=>u.type.excludes(n))}const{ranges:l}=i;return l.some(({$from:c,$to:u})=>{let d=c.depth===0?t.doc.inlineContent&&t.doc.type.allowsMarkType(n):!1;return t.doc.nodesBetween(c.pos,u.pos,(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(C=>C.type.excludes(n));d=m&&j}return!d}),d})}const $x=(t,e={})=>({tr:n,state:r,dispatch:i})=>{const{selection:o}=n,{empty:l,ranges:c}=o,u=ht(t,r.schema);if(i)if(l){const d=Lx(r,u);n.addStoredMark(u.create({...d,...e}))}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),C=Math.min(m+x.nodeSize,h);x.marks.find(A=>A.type===u)?x.marks.forEach(A=>{u===A.type&&n.addMark(j,C,u.create({...A.attrs,...e}))}):n.addMark(j,C,u.create(e))})});return Ox(r,n,u)},Vx=(t,e)=>({tr:n})=>(n.setMeta(t,e),!0),Nx=(t,e={})=>({state:n,dispatch:r,chain:i})=>{const o=je(t,n.schema);return o.isTextblock?i().command(({commands:l})=>me.setBlockType(o,e)(n)?!0:l.clearNodes()).command(({state:l})=>me.setBlockType(o,e)(l,r)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},qx=t=>({tr:e,dispatch:n})=>{if(n){const{doc:r}=e,i=wt(t,0,r.content.size),o=Pe.create(r,i);e.setSelection(o)}return!0},Fx=t=>({tr:e,dispatch:n})=>{if(n){const{doc:r}=e,{from:i,to:o}=typeof t=="number"?{from:t,to:t}:t,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);e.setSelection(p)}return!0},Gx=t=>({state:e,dispatch:n})=>{const r=je(t,e.schema);return ss.sinkListItem(r)(e,n)};function Sa(t,e){const n=t.storedMarks||t.selection.$to.parentOffset&&t.selection.$from.marks();if(n){const r=n.filter(i=>e==null?void 0:e.includes(i.type.name));t.tr.ensureMarks(r)}}const Wx=({keepMarks:t=!0}={})=>({tr:e,state:n,dispatch:r,editor:i})=>{const{selection:o,doc:l}=e,{$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&&(t&&Sa(n,i.extensionManager.splittableMarks),e.split(c.pos).scrollIntoView()),!0);if(!c.parent.isBlock)return!1;if(r){const h=u.parentOffset===u.parent.content.size;o instanceof xe&&e.deleteSelection();const x=c.depth===0?void 0:Ex(c.node(-1).contentMatchAt(c.indexAfter(-1)));let m=h&&x?[{type:x,attrs:p}]:void 0,j=_n(e.doc,e.mapping.map(c.pos),1,m);if(!m&&!j&&_n(e.doc,e.mapping.map(c.pos),1,x?[{type:x}]:void 0)&&(j=!0,m=x?[{type:x,attrs:p}]:void 0),j&&(e.split(e.mapping.map(c.pos),1,m),x&&!h&&!c.parentOffset&&c.parent.type!==x)){const C=e.mapping.map(c.before()),T=e.doc.resolve(C);c.node(-1).canReplaceWith(T.index(),T.index()+1,x)&&e.setNodeMarkup(e.mapping.map(c.before()),x)}t&&Sa(n,i.extensionManager.splittableMarks),e.scrollIntoView()}return!0},Rx=t=>({tr:e,state:n,dispatch:r,editor:i})=>{var o;const l=je(t,n.schema),{$from:c,$to:u}=n.selection,d=n.selection.node;if(d&&d.isBlock||c.depth<2||!c.sameParent(u))return!1;const 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 A=c.index(-1)?1:c.index(-2)?2:3;for(let ue=c.depth-A;ue>=c.depth-3;ue-=1)T=J.from(c.node(ue).copy(T));const L=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-(A-1));e.replace(Q,c.after(-L),new H(T,4-A,0));let ie=-1;e.doc.nodesBetween(Q,e.doc.content.size,(ue,fe)=>{if(ie>-1)return!1;ue.isTextblock&&ue.content.size===0&&(ie=fe+1)}),ie>-1&&e.setSelection(xe.near(e.doc.resolve(ie))),e.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);e.delete(c.pos,u.pos);const C=x?[{type:l,attrs:m},{type:x,attrs:j}]:[{type:l,attrs:m}];if(!_n(e.doc,c.pos,2))return!1;if(r){const{selection:T,storedMarks:A}=n,{splittableMarks:L}=i.extensionManager,U=A||T.$to.parentOffset&&T.$from.marks();if(e.split(c.pos,2,C).scrollIntoView(),!U||!r)return!0;const se=U.filter(Q=>L.includes(Q.type.name));e.ensureMarks(se)}return!0},Ys=(t,e)=>{const n=Us(l=>l.type===e)(t.selection);if(!n)return!0;const r=t.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(r===void 0)return!0;const i=t.doc.nodeAt(r);return n.node.type===(i==null?void 0:i.type)&&la(t.doc,n.pos)&&t.join(n.pos),!0},Ks=(t,e)=>{const n=Us(l=>l.type===e)(t.selection);if(!n)return!0;const r=t.doc.resolve(n.start).after(n.depth);if(r===void 0)return!0;const i=t.doc.nodeAt(r);return n.node.type===(i==null?void 0:i.type)&&la(t.doc,r)&&t.join(r),!0};var Qx=Object.freeze({__proto__:null,blur:Qh,clearContent:Uh,clearNodes:Yh,command:Kh,createParagraphNear:Xh,deleteCurrentNode:Jh,deleteNode:Zh,deleteRange:Hh,deleteSelection:ex,enter:tx,exitCode:nx,extendMarkRange:rx,first:ix,focus:ox,forEach:lx,insertContent:cx,insertContentAt:px,joinUp:hx,joinDown:xx,joinBackward:fx,joinForward:gx,keyboardShortcut:yx,lift:bx,liftEmptyBlock:jx,liftListItem:vx,newlineInCode:wx,resetAttributes:Cx,scrollIntoView:Sx,selectAll:_x,selectNodeBackward:kx,selectNodeForward:Tx,selectParentNode:Ix,selectTextblockEnd:Dx,selectTextblockStart:Mx,setContent:zx,setMark:$x,setMeta:Vx,setNode:Nx,setNodeSelection:qx,setTextSelection:Fx,sinkListItem:Gx,splitBlock:Wx,splitListItem:Rx,toggleList:(t,e,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(t,l.schema),j=je(e,l.schema),{selection:C,storedMarks:T}=l,{$from:A,$to:L}=C,U=A.blockRange(L),se=T||C.$to.parentOffset&&C.$from.marks();if(!U)return!1;const Q=Us(ie=>Ca(ie.type.name,h))(C);if(U.depth>=1&&Q&&U.depth-Q.depth<=1){if(Q.node.type===m)return d.liftListItem(j);if(Ca(Q.node.type.name,h)&&m.validContent(Q.node.content)&&c)return u().command(()=>(o.setNodeMarkup(Q.pos,m),!0)).command(()=>Ys(o,m)).command(()=>Ks(o,m)).run()}return!n||!se||!c?u().command(()=>p().wrapInList(m,r)?!0:d.clearNodes()).wrapInList(m,r).command(()=>Ys(o,m)).command(()=>Ks(o,m)).run():u().command(()=>{const ie=p().wrapInList(m,r),ue=se.filter(fe=>x.includes(fe.type.name));return o.ensureMarks(ue),ie?!0:d.clearNodes()}).wrapInList(m,r).command(()=>Ys(o,m)).command(()=>Ks(o,m)).run()},toggleMark:(t,e={},n={})=>({state:r,commands:i})=>{const{extendEmptyMarkRange:o=!1}=n,l=ht(t,r.schema);return Bx(r,l,e)?i.unsetMark(l,{extendEmptyMarkRange:o}):i.setMark(l,e)},toggleNode:(t,e,n={})=>({state:r,commands:i})=>{const o=je(t,r.schema),l=je(e,r.schema);return Qs(r,o,n)?i.setNode(l):i.setNode(o,n)},toggleWrap:(t,e={})=>({state:n,commands:r})=>{const i=je(t,n.schema);return Qs(n,i,e)?r.lift(i):r.wrapIn(i,e)},undoInputRule:()=>({state:t,dispatch:e})=>{const n=t.plugins;for(let r=0;r<n.length;r+=1){const i=n[r];let o;if(i.spec.isInputRules&&(o=i.getState(t))){if(e){const l=t.tr,c=o.transform;for(let u=c.steps.length-1;u>=0;u-=1)l.step(c.steps[u].invert(c.docs[u]));if(o.text){const u=l.doc.resolve(o.from).marks();l.replaceWith(o.from,o.to,t.schema.text(o.text,u))}else l.delete(o.from,o.to)}return!0}}return!1},unsetAllMarks:()=>({tr:t,dispatch:e})=>{const{selection:n}=t,{empty:r,ranges:i}=n;return r||e&&i.forEach(o=>{t.removeMark(o.$from.pos,o.$to.pos)}),!0},unsetMark:(t,e={})=>({tr:n,state:r,dispatch:i})=>{var o;const{extendEmptyMarkRange:l=!1}=e,{selection:c}=n,u=ht(t,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,C=ma(d,u,j);C&&(x=C.from,m=C.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:(t,e={})=>({tr:n,state:r,dispatch:i})=>{let o=null,l=null;const c=va(typeof t=="string"?t:t.name,r.schema);return c?(c==="node"&&(o=je(t,r.schema)),c==="mark"&&(l=ht(t,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,...e}),l&&h.marks.length&&h.marks.forEach(m=>{if(l===m.type){const j=Math.max(x,d),C=Math.min(x+h.nodeSize,p);n.addMark(j,C,l.create({...m.attrs,...e}))}})})}),!0):!1},wrapIn:(t,e={})=>({state:n,dispatch:r})=>{const i=je(t,n.schema);return me.wrapIn(i,e)(n,r)},wrapInList:(t,e={})=>({state:n,dispatch:r})=>{const i=je(t,n.schema);return ss.wrapInList(i,e)(n,r)}});He.create({name:"commands",addCommands(){return{...Qx}}}),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:t}=this;return[new Zt({key:new Ht("focusEvents"),props:{handleDOMEvents:{focus:(e,n)=>{t.isFocused=!0;const r=t.state.tr.setMeta("focus",{event:n}).setMeta("addToHistory",!1);return e.dispatch(r),!1},blur:(e,n)=>{t.isFocused=!1;const r=t.state.tr.setMeta("blur",{event:n}).setMeta("addToHistory",!1);return e.dispatch(r),!1}}}})]}}),He.create({name:"keymap",addKeyboardShortcuts(){const t=()=>this.editor.commands.first(({commands:l})=>[()=>l.undoInputRule(),()=>l.command(({tr:c})=>{const{selection:u,doc:d}=c,{empty: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()]),e=()=>this.editor.commands.first(({commands:l})=>[()=>l.deleteSelection(),()=>l.deleteCurrentNode(),()=>l.joinForward(),()=>l.selectNodeForward()]),r={Enter:()=>this.editor.commands.first(({commands:l})=>[()=>l.newlineInCode(),()=>l.createParagraphNear(),()=>l.liftEmptyBlock(),()=>l.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:t,"Mod-Backspace":t,"Shift-Backspace":t,Delete:e,"Mod-Delete":e,"Mod-a":()=>this.editor.commands.selectAll()},i={...r},o={...r,"Ctrl-h":t,"Alt-Backspace":t,"Ctrl-d":e,"Ctrl-Alt-Backspace":e,"Alt-Delete":e,"Alt-d":e,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return Rs()||ja()?o:i},addProseMirrorPlugins(){return[new Zt({key:new Ht("clearDocument"),appendTransaction:(t,e,n)=>{if(!(t.some(j=>j.docChanged)&&!e.doc.eq(n.doc)))return;const{empty:i,from:o,to:l}=e.selection,c=ne.atStart(e.doc).from,u=ne.atEnd(e.doc).to;if(i||!(o===c&&l===u)||!(n.doc.textBetween(0,n.doc.content.size," "," ").length===0))return;const h=n.tr,x=fa({state:n,transaction:h}),{commands:m}=new Vh({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 _a=He.create({name:"fontSize",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{fontSize:{default:null,parseHTML:t=>t.style.fontSize.replace(/['"]+/g,""),renderHTML:t=>t.fontSize?{style:`font-size: ${t.fontSize}`}:{}}}}]},addCommands(){return{setFontSize:t=>({chain:e})=>e().setMark("textStyle",{fontSize:t}).run(),unsetFontSize:()=>({chain:t})=>t().setMark("textStyle",{fontSize:null}).removeEmptyTextStyle().run()}}}),Ux=["8","10","12","14","16","18","20","24","30","36","48","60","72"].map(t=>`${t}px`),Yx=[{label:"auto",value:""}].concat(Ux.map(t=>({label:t,value:t}))),Kx={input:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important"}},Xx=({editor:t})=>{const e=t.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:Yx,styles:Kx,value:e||"",onChange:n=>{const r=n.currentTarget.value;r?t.chain().focus().setFontSize(r).run():t.chain().focus().unsetFontSize().run()}})})},An=({value:t,styles:e={}})=>{const n=ci.useEditor({extensions:[ui,li,q.Link,ti,ei,Zr,ri.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),oi,ai,ii,ni.configure({types:["heading","paragraph"]}),Hr.configure({placeholder:"This is placeholder"}),si,Jr.Color,_a],content:t,editable:!1});f.useEffect(()=>{n==null||n.commands.setContent(t)},[t,n]);const r=f.useMemo(()=>y.defaultsDeep({},{content:Ps},e),[e]);return s.jsx(q.RichTextEditor,{editor:n,styles:r,children:s.jsx(q.RichTextEditor.Content,{})})};function Jx(){const[t,{open:e,close:n}]=pe.useDisclosure(!1);return s.jsxs(s.Fragment,{children:[s.jsx(a.Modal,{opened:t,onClose:n,title:"About FunctionUtils",zIndex:330,withinPortal:!0,children:s.jsx(An,{value:iu,styles:{root:{border:"none"},content:{padding:0,table:{marginBottom:0}}}})}),s.jsx(a.Button,{variant:"light",color:"violet",size:"xs",onClick:e,leftIcon:s.jsx(k.IconInfoCircle,{size:16}),children:"About parameter 'utils'"})]})}const Zx=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return s.jsx(a.Box,{sx:{position:"relative",flexGrow:1},children:s.jsx(ge,{className:"function-editor",height:"100%",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1}}})})},en=f.forwardRef(({value:t,onChange:e,label:n,defaultValue:r},i)=>{const[o,l]=f.useState(t),c=()=>{e(o)},u=()=>{l(t)},d=()=>{l(r)};f.useEffect(()=>{l(t)},[t]);const p=o!==t;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(Jx,{})}),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(Zx,{value:o,onChange:l})]})}),Hx=f.forwardRef(({value:t,onChange:e,label:n,triggerLabel:r="Edit",triggerButtonProps:i={},defaultValue:o},l)=>{const[c,{open:u,close:d}]=pe.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:t,onChange:e,defaultValue:o,label:n})})}),s.jsx(a.Button,{onClick:u,...i,children:r})]})}),ef=[{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 tf({label:t,value:e,onChange:n,pt:r="sm",withFallback:i},o){f.useEffect(()=>{typeof e=="string"&&n({type:e,config:{},fallback:"0"})},[e,n]);const l=p=>{n(p==="quantile"?{type:"quantile",config:{p:.99},fallback:e.fallback}:p==="custom"?{type:"custom",config:{func:$i},fallback:e.fallback}:{type:p,config:{},fallback:e.fallback})},c=p=>{n({type:"quantile",config:{p},fallback:e.fallback})},u=p=>{n({type:"custom",config:{func:p},fallback:e.fallback})},d=p=>{n({...e,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:t,data:ef,value:e.type,onChange:l,maxDropdownHeight:600}),e.type==="quantile"&&s.jsx(a.NumberInput,{label:"p",value:e.config.p,onChange:c,precision:2,min:.05,step:.05,max:1}),e.type==="custom"&&s.jsx(Hx,{label:"",triggerLabel:"Edit Function",value:e.config.func,onChange:u,defaultValue:$i,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:e.fallback,onChange:d})]})}const Xs=f.forwardRef(tf),nf=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function sf({control:t,index:e,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.${e}.stack`,control:t,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.${e}.barGap`,control:t,render:({field:i})=>s.jsx(a.Select,{label:"Bar Gap",data:nf,sx:{flexGrow:1},...i})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${e}.barMinWidth`,control:t,render:({field:i})=>s.jsx(a.TextInput,{label:"Bar Width(Min)",disabled:r,sx:{flexGrow:1},...i})}),s.jsx(b.Controller,{name:`series.${e}.barWidth`,control:t,render:({field:i})=>s.jsx(a.TextInput,{label:"Bar Width",sx:{flexGrow:1},...i})}),s.jsx(b.Controller,{name:`series.${e}.barMaxWidth`,control:t,render:({field:i})=>s.jsx(a.TextInput,{label:"Bar Width(Max)",disabled:r,sx:{flexGrow:1},...i})})]})]})}const rf=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return s.jsx(a.Box,{children:s.jsx(ge,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},af=({value:t,onChange:e})=>{const[n,{setTrue:r,setFalse:i}]=$.useBoolean(),[o,l]=f.useState(t),c=()=>{i();const{type:h,func_content:x}=o,m={type:h,func_content:x};l(m),e(m)},u=()=>{i(),l(t)},d=h=>{l(x=>({...x,func_content:h}))},p=()=>{d(Es.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(rf,{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"})]})]})]})})]})},of=({value:t,onChange:e})=>t.type!=="dynamic"?null:s.jsx(af,{value:t,onChange:e}),lf=({value:t,onChange:e})=>{if(t.type!=="static")return null;const n=r=>{e({...t,size:r})};return s.jsx(s.Fragment,{children:s.jsx(a.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:t.size,onChange:n})})},cf=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],ka=f.forwardRef(({label:t="Size",value:e,onChange:n},r)=>{const i=o=>{n({...Es[o]})};return s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(a.Select,{ref:r,label:t,data:cf,value:e.type,onChange:i,sx:{flexGrow:1}}),s.jsx(lf,{value:e,onChange:n}),s.jsx(of,{value:e,onChange:n})]})}),uf=[{label:"off",value:"false"},{label:"start",value:"start"},{label:"middle",value:"middle"},{label:"end",value:"end"}],df=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function pf({control:t,index:e,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.${e}.lineStyle.type`,control:t,render:({field:i})=>s.jsx(a.Select,{label:"Line Type",data:df,sx:{flexGrow:1},...i})}),s.jsx(b.Controller,{name:`series.${e}.lineStyle.width`,control:t,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.${e}.step`,control:t,render:({field:i})=>s.jsx(a.Select,{label:"Step",data:uf,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.${e}.smooth`,control:t,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.${e}.display_name_on_line`,control:t,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.${e}.showSymbol`,control:t,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.${e}.symbolSize`,control:t,render:({field:i})=>s.jsx(ka,{label:"Symbol Size",...i})})]})]})}function hf({control:t,index:e}){return s.jsx(b.Controller,{name:`series.${e}.symbolSize`,control:t,render:({field:n})=>s.jsx(ka,{label:"Size",...n})})}const xf=[{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 ff({control:t,index:e,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.${e}.type`,control:t,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.${e}.name`,control:t,render:({field:l})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...l})}),s.jsx(b.Controller,{name:`series.${e}.yAxisIndex`,control:t,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.${e}.y_axis_data_key`,control:t,render:({field:l})=>s.jsx(B,{label:"Value Field",required:!0,sx:{flex:1},...l})}),s.jsx(b.Controller,{name:`series.${e}.aggregation_on_value`,control:t,render:({field:l})=>s.jsx(Xs,{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.${e}.group_by_key`,control:t,render:({field:l})=>s.jsx(B,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...l})})}),o==="line"&&s.jsx(pf,{index:e,control:t,seriesItem:r}),o==="bar"&&s.jsx(sf,{index:e,control:t,seriesItem:r}),o==="scatter"&&s.jsx(hf,{index:e,control:t}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),s.jsx(b.Controller,{name:`series.${e}.label_position`,control:t,render:({field:l})=>s.jsx(a.Select,{label:"Label Position",data:xf,...l})}),s.jsxs(a.Stack,{spacing:4,children:[s.jsx(a.Text,{size:"sm",children:"Color"}),s.jsx(b.Controller,{name:`series.${e}.color`,control:t,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.${e}.hide_in_legend`,control:t,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(e),sx:{top:15,right:5},children:"Delete this Series"})]})}function gf({control:t,watch:e}){const{fields:n,append:r,remove:i}=b.useFieldArray({control:t,name:"series"}),o=e("series"),l=n.map((p,h)=>({...p,...o[h]})),c=()=>{const p={type:"bar",name:pe.randomId(),showSymbol:!1,symbolSize:Es.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=e("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(ff,{control:t,index:h,remove:i,seriesItem:p,yAxisOptions:d},p.id)},p.id))]})}function mf({control:t,watch:e}){return e("stats"),s.jsx(a.Stack,{children:s.jsxs(a.Stack,{spacing:0,children:[s.jsx(b.Controller,{name:"stats.templates.top",control:t,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:t,render:({field:n})=>s.jsx(Qt,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const yf=()=>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"]})})]})]}),bf=[{label:"Value",value:"value"},{label:"Category",value:"category"},{label:"Time",value:"time"},{label:"Log",value:"log"}];function jf({control:t,watch:e}){return e(["x_axis_data_key","x_axis_name","x_axis"]),s.jsxs(a.Stack,{children:[s.jsx(b.Controller,{name:"x_axis_name",control:t,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:t,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:t,render:({field:n})=>s.jsx(a.Select,{label:s.jsx(yf,{}),required:!0,data:bf,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:t,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:t,render:({field:n})=>s.jsx(mn,{...n})})]}),s.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>s.jsx(Xe,{...n})})]})}const vf=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],wf=[{label:"left",value:"left"},{label:"right",value:"right"}];function Cf({control:t,index:e,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.${e}.name`,control:t,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`y_axes.${e}.nameAlignment`,control:t,render:({field:r})=>s.jsx(a.Select,{label:"Name Anchor",required:!0,data:vf,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.${e}.position`,control:t,render:({field:r})=>s.jsx(a.Select,{label:"Position",required:!0,data:wf,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.${e}.label_formatter`,control:t,render:({field:r})=>s.jsx(Be,{...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.${e}.min`,control:t,render:({field:r})=>s.jsx(a.TextInput,{label:"Min",...r})}),s.jsx(b.Controller,{name:`y_axes.${e}.max`,control:t,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.${e}.show`,control:t,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(e),disabled:e===0,children:"Delete this YAxis"})]})}function Sf({control:t,watch:e}){const{fields:n,append:r,remove:i}=b.useFieldArray({control:t,name:"y_axes"}),o=e("y_axes"),l=n.map((u,d)=>({...u,...o[d]})),c=()=>r({name:"",position:"left",nameAlignment:"left",label_formatter: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(Cf,{control:t,index:d,remove:i})},u.id))]})}function _f({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),{variables:r}=t,i=f.useMemo(()=>y.defaultsDeep({},e,Ds),[e]),{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(jf,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Y Axes",children:s.jsx(Sf,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Series",children:s.jsx(gf,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Regression Lines",children:s.jsx(Sh,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Stats",children:s.jsx(mf,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Reference Lines",children:s.jsx(jh,{variables:r,control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Reference Areas",children:s.jsx(gh,{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(zs,{...x})})})]})]})})}function kf(t){const e=y.cloneDeep(y.omit(t,"variables"));return e.stats=y.omit(e.stats,"variables"),e}function Tf(t){const{rotate:e,formatter:n=Oe}=t.x_axis.axisLabel;return{...t,x_axis:{...t.x_axis,axisLabel:{rotate:e,formatter:n}}}}function If(t){const{dataZoom:e=zt,...n}=t;return{...n,dataZoom:e}}function Df(t){const e={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return y.defaultsDeep(e,t)}function Mf(t){const e=t.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{...t,reference_lines:e}}function Af(t){const e=t.reference_lines.map(n=>{const{yAxisIndex:r=0}=n;return{...n,yAxisIndex:r}});return{...t,reference_lines:e}}function zf(t){const e=t.series.map(n=>{const{aggregation_on_group:r=At}=n;return{...n,aggregation_on_group:r}});return{...t,series:e}}function Ef(t){const e=t.series.map(n=>{const{aggregation_on_value:r=At}=n;return{...n,aggregation_on_value:r}});return{...t,series:e}}function Pf(t){delete t.config;const{x_axis:e,tooltip:n}=t.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:e,in_tooltip:n}}}};return y.defaultsDeep(r,t)}function Lf(t){const{series:e,...n}=t;return{...n,series:e.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 Bf(t){const{y_axes:e,...n}=t;return{...n,y_axes:e.map(r=>{const{min:i="",max:o=""}=r;return{...r,min:i,max:o}})}}function Of(t){const{y_axes:e,...n}=t;return{...n,y_axes:e.map(r=>{const{nameAlignment:i="left"}=r;return{...r,nameAlignment:i}})}}function $f(t){const{y_axes:e,...n}=t;return{...n,y_axes:e.map(r=>{const{show:i=!0}=r;return{...r,show:i}})}}function Vf(t){const{regressions:e,...n}=t;return{...n,regressions:e.map(r=>{const{group_by_key:i=""}=r;return{...r,group_by_key:i}})}}function Nf(t){const{series:e,y_axes:n,...r}=t;return{...r,series:e.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 qf(t){const{type:e="category",...n}=t.x_axis;return{...t,x_axis:{...n,type:e}}}function Ff(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis_data_key:i,series:o,regressions:l,...c}=t;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 Gf extends re{constructor(){super(...arguments);z(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:kf(i)}}),this.version(3,n=>({...n,version:3,config:Tf(n.config)})),this.version(4,n=>({...n,version:4,config:If(n.config)})),this.version(5,n=>({...n,version:5,config:Df(n.config)})),this.version(6,n=>({...n,version:6,config:Mf(n.config)})),this.version(7,n=>({...n,version:7,config:Af(n.config)})),this.version(8,n=>({...n,version:8,config:zf(n.config)})),this.version(9,n=>({...n,version:9,config:Ef(n.config)})),this.version(10,n=>({...n,version:10,config:Pf(n.config)})),this.version(11,n=>({...n,version:11,config:Lf(n.config)})),this.version(12,n=>({...n,version:12,config:Bf(n.config)})),this.version(13,n=>({...n,version:13,config:Of(n.config)})),this.version(14,n=>({...n,version:14,config:$f(n.config)})),this.version(15,n=>({...n,version:15,config:Vf(n.config)})),this.version(16,n=>({...n,version:16,config:Nf(n.config)})),this.version(17,n=>({...n,version:17,config:qf(n.config)})),this.version(18,(n,r)=>({...n,version:18,config:Ff(n.config,r)}))}}const Wf={displayName:"Cartesian Chart",displayGroup:"ECharts-based charts",migrator:new Gf,name:"cartesian",viewRender:ph,configRender:_f,createConfig(){return{version:18,config:y.cloneDeep(Ds)}},triggers:[Is]};function Rf(t){if(t.enable_value)return t.value}function Qf(t){if(t.enable_value)return t.value}function Uf(t){const e=t.axisLabel.overflow.on_axis.width,n=t.axisLabel.position,r={top:5,left:5,right:5,bottom:5};return t.orient==="vertical"&&y.get(r,n)&&n===t.funnelAlign&&y.set(r,n,e),r}function Yf(t,e){return t.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=D(r),x=D(i),m=e[h.queryID].map(C=>({name:C[h.columnKey],value:C[x.columnKey]})),j=Qe(o.overflow.on_axis);return{type:"funnel",...Uf(n),min:Rf(l),max:Qf(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 Kf({conf:t,params:e,max:n}){const{name:r,value:i}=e.data,o=F(i/n).format({output:"percent",mantissa:2,trimMantissa:!0});return[{label:`${e.marker} ${r}`,value:`${i} (${o})`,style:{label:"",value:""}}]}function Xf(t,e){var o;const n=D(t.series[0].level_name_data_key),r=D(t.series[0].level_value_data_key),i=(o=y.maxBy(e[n.queryID],r.columnKey))==null?void 0:o[r.columnKey];return l=>{const u=Kf({conf:t,params:l,max:i}).map(p=>`
123
123
  <tr>
124
124
  <th style="text-align: right;">
125
- <div style="${h.style.label}">${h.label}</div>
125
+ <div style="${p.style.label}">${p.label}</div>
126
126
  </th>
127
127
  <td style="text-align: right; padding: 0 1em;">
128
- <div style="${h.style.value}">${h.value}
128
+ <div style="${p.style.value}">${p.value}
129
129
  </td>
130
130
  </tr>
131
131
  `);return`
@@ -135,7 +135,7 @@ Check the top-level render call using <`+M+">.")}return I}}function oc(v,I){{if(
135
135
  <table style="width: auto">
136
136
  <tbody>${u.join("")}</tbody>
137
137
  </table>
138
- `}}function sg(t,e){return{trigger:"item",confine:!0,formatter:ng(t,e)}}function rg(t,e){return{grid:{top:0,left:0,right:0,bottom:0},tooltip:sg(t,e),series:eg(t,e)}}function ig(t){return t||(t=Date.now().toString()),{id:t,name:t,level_name_data_key:"",level_value_data_key:"",min:{value:0,enable_value:!1,size:"0%"},max:{value:0,enable_value:!1,size:"100%"},gap:2,axisLabel:{show:!0,position:"inside",overflow:ze},sort:"descending",orient:"vertical",funnelAlign:"center"}}const Js={series:[ig("Funnel")]};K.use([te.FunnelChart,P.DataZoomComponent,P.GridComponent,P.LegendComponent,P.TooltipComponent,we.CanvasRenderer]);function ag({conf:t,data:e,width:n,height:r}){const i=f.useMemo(()=>rg(t,e),[t,e]);return s.jsx(ve,{echarts:K,option:i,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})}function og({context:t}){const{value:e}=O(t.instanceData,"config"),n=f.useMemo(()=>y.defaults({},e,Js),[e]),r=t.data,{width:i,height:o}=t.viewport;return!i||!o?null:s.jsx(Te,{width:i,height:o,children:s.jsx(ag,{width:We(i),height:Re(o),data:r,conf:n})})}const lg=[{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"}],Zs=f.forwardRef(({label:t,value:e,onChange:n,options:r=lg},i)=>s.jsx(a.Select,{ref:i,label:t,data:r,value:e,onChange:n})),cg=[{label:"Ascending",value:"ascending"},{label:"Descending",value:"descending"},{label:"Use original data order",value:"0"}],ug=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],dg=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}],pg={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"}]},hg=({item:t,control:e,index:n,remove:r})=>{const i=t.min.enable_value,o=t.max.enable_value,{orient:l}=t;return s.jsxs(a.Stack,{children:[s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:`series.${n}.name`,control:e,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:e,render:({field:c})=>s.jsx(B,{label:"Level Name Field",...c})}),s.jsx(b.Controller,{name:`series.${n}.level_value_data_key`,control:e,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:e,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:e,render:({field:u})=>s.jsx(a.Checkbox,{size:"xs",checked:u.value,onChange:d=>u.onChange(d.currentTarget.checked)})})})})]}),...c})}),s.jsx(b.Controller,{name:`series.${n}.min.size`,control:e,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:e,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:e,render:({field:u})=>s.jsx(a.Checkbox,{size:"xs",checked:u.value,onChange:d=>u.onChange(d.currentTarget.checked)})})})})]}),...c})}),s.jsx(b.Controller,{name:`series.${n}.max.size`,control:e,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:e,render:({field:c})=>s.jsx(a.Select,{label:"Orientation",data:dg,...c})}),s.jsx(b.Controller,{name:`series.${n}.sort`,control:e,render:({field:c})=>s.jsx(a.Select,{label:"Sort",data:cg,...c})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${n}.funnelAlign`,control:e,render:({field:c})=>s.jsx(a.Select,{label:"Align",disabled:l==="horizontal",data:ug,...c})}),s.jsx(b.Controller,{name:`series.${n}.gap`,control:e,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:e,render:({field:c})=>s.jsx(Zs,{label:"Position",options:pg[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:e,render:({field:c})=>s.jsx(Xe,{...c})})})]})},xg=({control:t,watch:e})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:t,name:"series"}),o=e("series"),l=n.map((h,p)=>({...h,...o[p]})),c=y.get(l,"0.id"),[u,d]=f.useState(c??null);return f.useEffect(()=>{c&&d(h=>h!==null?h:c)},[c]),s.jsxs(a.Tabs,{value:u,onTabChange:h=>d(h),styles:{panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((h,p)=>s.jsx(a.Tabs.Tab,{value:h.id,children:h.name},h.id)),s.jsx(a.Tabs.Tab,{value:"add",disabled:!0,children:s.jsx(a.Tooltip,{label:"TODO",children:s.jsx(a.Center,{children:s.jsx(k.IconPlus,{size:18,color:"#228be6"})})})})]}),l.map((h,p)=>s.jsx(a.Tabs.Panel,{value:h.id,children:s.jsx(hg,{item:h,control:t,index:p,remove:i})},h.id))]})};function fg({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},e,Js),[e]),{control:i,handleSubmit:o,watch:l,getValues:c,reset:u}=b.useForm({defaultValues:r});f.useEffect(()=>{u(r)},[r]),l([]);const d=c(),h=f.useMemo(()=>!y.isEqual(d,r),[d,r]);return s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:o(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Funnel Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:s.jsx(_.DeviceFloppy,{size:20})})]}),s.jsx(xg,{control:i,watch:l})]})})}function gg(t){return{series:t.series.map(e=>{const{min:n,minSize:r,max:i,maxSize:o,...l}=e;return{...l,min:{value:n,use_data_min:!1,size:r},max:{value:i,use_data_max:!1,size:o}}})}}function mg(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=l=>l&&`${n}.${l}`,{series:i,...o}=t;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 yg extends re{constructor(){super(...arguments);z(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:gg(r)}}),this.version(3,(n,r)=>{const{config:i}=n;return{...n,version:3,config:mg(i,r)}})}}const bg={displayName:"Funnel Chart",displayGroup:"ECharts-based charts",migrator:new yg,name:"funnel",viewRender:og,configRender:fg,createConfig:()=>({version:3,config:Js})};function Ta({enabled:t,func_content:e}){return(n,r)=>{if(!t)return n;try{return new Function(`return ${e}`)()(n,r)}catch(i){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${i.message}`),n}}}function jg(t){const e=Ta(t.x_axis.axisLabel.formatter),n=Ta(t.y_axis.axisLabel.formatter);return{x_axis:e,y_axis:n}}function vg(t){return{heat_block:function(r){if(!t.heat_block.value_formatter)return r;try{return F(r).format(t.heat_block.value_formatter)}catch(i){return console.error(i),r}}}}function wg(t){let e=0;return t.x_axis.name&&(e+=20),{top:45,left:5,right:5,bottom:e,containLabel:!0}}function Cg(t,e,n){const{heat_block:r}=t;return{type:"heatmap",name:r.name,xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{borderColor:"white",borderWidth:n},data:e,label:r.label,labelLayout:{hideOverlap:!0}}}const Sg=t=>{try{return F(t).format({trimMantissa:!0,mantissa:2})}catch{return t}};function _g({conf:t,labelFormatters:e,valueFormatters:n,dataDict:r,params:i}){const{value:o,dataIndex:l}=i,[c,u,d]=o,h={label:t.x_axis.name?t.x_axis.name:"X Axis",value:e.x_axis(c,l),style:{label:"",value:Je(t.x_axis.axisLabel.overflow.in_tooltip)}},p={label:t.y_axis.name?t.y_axis.name:"Y Axis",value:e.y_axis(u,l),style:{label:"",value:Je(t.y_axis.axisLabel.overflow.in_tooltip)}},x={label:t.heat_block.name,value:n.heat_block(d),style:{label:"",value:""}},m=[h,p,x],j=r[`${c}---${u}`];return j&&t.tooltip.metrics.forEach(C=>{const T=D(C.data_key);m.push({label:C.name,value:Sg(y.get(j,T.columnKey,"")),style:{label:"",value:""}})}),m}function kg(t,e,n,r){const{x_axis:i,y_axis:o,heat_block:l}=t,c=D(i.data_key),u=D(o.data_key);D(l.data_key);const d=y.keyBy(e[c.queryID],h=>`${h[c.columnKey]}---${h[u.columnKey]}`);return{confine:!0,formatter:function(h){const x=_g({conf:t,labelFormatters:n,valueFormatters:r,dataDict:d,params:h}).map(j=>`
138
+ `}}function Jf(t,e){return{trigger:"item",confine:!0,formatter:Xf(t,e)}}function Zf(t,e){return{grid:{top:0,left:0,right:0,bottom:0},tooltip:Jf(t,e),series:Yf(t,e)}}function Hf(t){return t||(t=Date.now().toString()),{id:t,name:t,level_name_data_key:"",level_value_data_key:"",min:{value:0,enable_value:!1,size:"0%"},max:{value:0,enable_value:!1,size:"100%"},gap:2,axisLabel:{show:!0,position:"inside",overflow:Ae},sort:"descending",orient:"vertical",funnelAlign:"center"}}const Js={series:[Hf("Funnel")]};Y.use([te.FunnelChart,P.DataZoomComponent,P.GridComponent,P.LegendComponent,P.TooltipComponent,we.CanvasRenderer]);function eg({conf:t,data:e,width:n,height:r}){const i=f.useMemo(()=>Zf(t,e),[t,e]);return s.jsx(ve,{echarts:Y,option:i,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})}function tg({context:t}){const{value:e}=O(t.instanceData,"config"),n=f.useMemo(()=>y.defaults({},e,Js),[e]),r=t.data,{width:i,height:o}=t.viewport;return!i||!o?null:s.jsx(Te,{width:i,height:o,children:s.jsx(eg,{width:We(i),height:Re(o),data:r,conf:n})})}const ng=[{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"}],Zs=f.forwardRef(({label:t,value:e,onChange:n,options:r=ng},i)=>s.jsx(a.Select,{ref:i,label:t,data:r,value:e,onChange:n})),sg=[{label:"Ascending",value:"ascending"},{label:"Descending",value:"descending"},{label:"Use original data order",value:"0"}],rg=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],ig=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}],ag={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"}]},og=({item:t,control:e,index:n,remove:r})=>{const i=t.min.enable_value,o=t.max.enable_value,{orient:l}=t;return s.jsxs(a.Stack,{children:[s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:`series.${n}.name`,control:e,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:e,render:({field:c})=>s.jsx(B,{label:"Level Name Field",...c})}),s.jsx(b.Controller,{name:`series.${n}.level_value_data_key`,control:e,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:e,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:e,render:({field:u})=>s.jsx(a.Checkbox,{size:"xs",checked:u.value,onChange:d=>u.onChange(d.currentTarget.checked)})})})})]}),...c})}),s.jsx(b.Controller,{name:`series.${n}.min.size`,control:e,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:e,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:e,render:({field:u})=>s.jsx(a.Checkbox,{size:"xs",checked:u.value,onChange:d=>u.onChange(d.currentTarget.checked)})})})})]}),...c})}),s.jsx(b.Controller,{name:`series.${n}.max.size`,control:e,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:e,render:({field:c})=>s.jsx(a.Select,{label:"Orientation",data:ig,...c})}),s.jsx(b.Controller,{name:`series.${n}.sort`,control:e,render:({field:c})=>s.jsx(a.Select,{label:"Sort",data:sg,...c})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${n}.funnelAlign`,control:e,render:({field:c})=>s.jsx(a.Select,{label:"Align",disabled:l==="horizontal",data:rg,...c})}),s.jsx(b.Controller,{name:`series.${n}.gap`,control:e,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:e,render:({field:c})=>s.jsx(Zs,{label:"Position",options:ag[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:e,render:({field:c})=>s.jsx(Xe,{...c})})})]})},lg=({control:t,watch:e})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:t,name:"series"}),o=e("series"),l=n.map((p,h)=>({...p,...o[h]})),c=y.get(l,"0.id"),[u,d]=f.useState(c??null);return f.useEffect(()=>{c&&d(p=>p!==null?p:c)},[c]),s.jsxs(a.Tabs,{value:u,onTabChange:p=>d(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(og,{item:p,control:t,index:h,remove:i})},p.id))]})};function cg({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},e,Js),[e]),{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:"Funnel Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(_.DeviceFloppy,{size:20})})]}),s.jsx(lg,{control:i,watch:l})]})})}function ug(t){return{series:t.series.map(e=>{const{min:n,minSize:r,max:i,maxSize:o,...l}=e;return{...l,min:{value:n,use_data_min:!1,size:r},max:{value:i,use_data_max:!1,size:o}}})}}function dg(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=l=>l&&`${n}.${l}`,{series:i,...o}=t;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 pg extends re{constructor(){super(...arguments);z(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:ug(r)}}),this.version(3,(n,r)=>{const{config:i}=n;return{...n,version:3,config:dg(i,r)}})}}const hg={displayName:"Funnel Chart",displayGroup:"ECharts-based charts",migrator:new pg,name:"funnel",viewRender:tg,configRender:cg,createConfig:()=>({version:3,config:Js})};function Ta({enabled:t,func_content:e}){return(n,r)=>{if(!t)return n;try{return new Function(`return ${e}`)()(n,r)}catch(i){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${i.message}`),n}}}function xg(t){const e=Ta(t.x_axis.axisLabel.formatter),n=Ta(t.y_axis.axisLabel.formatter);return{x_axis:e,y_axis:n}}function fg(t){return{heat_block:function(r){if(!t.heat_block.value_formatter)return r;try{return F(r).format(t.heat_block.value_formatter)}catch(i){return console.error(i),r}}}}function gg(t){let e=0;return t.x_axis.name&&(e+=20),{top:45,left:5,right:5,bottom:e,containLabel:!0}}function mg(t,e,n){const{heat_block:r}=t;return{type:"heatmap",name:r.name,xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{borderColor:"white",borderWidth:n},data:e,label:r.label,labelLayout:{hideOverlap:!0}}}const yg=t=>{try{return F(t).format({trimMantissa:!0,mantissa:2})}catch{return t}};function bg({conf:t,labelFormatters:e,valueFormatters:n,dataDict:r,params:i}){const{value:o,dataIndex:l}=i,[c,u,d]=o,p={label:t.x_axis.name?t.x_axis.name:"X Axis",value:e.x_axis(c,l),style:{label:"",value:Je(t.x_axis.axisLabel.overflow.in_tooltip)}},h={label:t.y_axis.name?t.y_axis.name:"Y Axis",value:e.y_axis(u,l),style:{label:"",value:Je(t.y_axis.axisLabel.overflow.in_tooltip)}},x={label:t.heat_block.name,value:n.heat_block(d),style:{label:"",value:""}},m=[p,h,x],j=r[`${c}---${u}`];return j&&t.tooltip.metrics.forEach(C=>{const T=D(C.data_key);m.push({label:C.name,value:yg(y.get(j,T.columnKey,"")),style:{label:"",value:""}})}),m}function jg(t,e,n,r){const{x_axis:i,y_axis:o,heat_block:l}=t,c=D(i.data_key),u=D(o.data_key);D(l.data_key);const d=y.keyBy(e[c.queryID],p=>`${p[c.columnKey]}---${p[u.columnKey]}`);return{confine:!0,formatter:function(p){const x=bg({conf:t,labelFormatters:n,valueFormatters:r,dataDict:d,params:p}).map(j=>`
139
139
  <tr>
140
140
  <th style="text-align: right;">
141
141
  <div style="${j.style.label}">${j.label}</div>
@@ -150,18 +150,18 @@ Check the top-level render call using <`+M+">.")}return I}}function oc(v,I){{if(
150
150
  <tr colspan="2">
151
151
  <div style="
152
152
  width: 100%; height: 4px; border-radius: 2px; margin-bottom: 6px;
153
- background-color: ${h.color};"
153
+ background-color: ${p.color};"
154
154
  />
155
155
  </tr>
156
156
  </thead>
157
157
  <tbody>${x.join("")}</tbody>
158
158
  </table>
159
- `}}}const Tg=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return s.jsx(a.Box,{children:s.jsx(me,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Ia={static:{type:"static",value:10},dynamic:{type:"dynamic",value:["function getValue({ variables }, { lodash, interpolate }) {"," // your code goes here"," return 100;","}"].join(`
160
- `)}},Ig=({value:t,onChange:e})=>{const[n,{setTrue:r,setFalse:i}]=$.useBoolean(),[o,l]=f.useState(t),c=()=>{i();const{type:p,value:x}=o,m={type:p,value:x};l(m),e(m)},u=()=>{i(),l(t)},d=p=>{l(x=>({...x,value:p}))},h=()=>{d(Ia.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(Tg,{value:o.value,onChange:d}),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:c,children:"OK"})]})]})]})})]})},Dg=({value:t,onChange:e})=>t.type!=="dynamic"?null:s.jsx(Ig,{value:t,onChange:e}),Mg=({value:t,onChange:e})=>{if(t.type!=="static")return null;const n=r=>{e({...t,value:r})};return s.jsx(a.NumberInput,{defaultValue:18,label:" ",hideControls:!0,value:t.value,onChange:n})},Ag=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Lt=f.forwardRef(({label:t="Value",value:e,onChange:n},r)=>{const i=o=>{n({...Ia[o]})};return s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(a.Select,{ref:r,label:t,data:Ag,value:e.type,onChange:i,sx:{flexGrow:1}}),s.jsx(Mg,{value:e,onChange:n}),s.jsx(Dg,{value:e,onChange:n})]})});function Bt(t,e,n){if(!t.type)return n;if(t.type==="static"){const{value:i}=t;return i}const{value:r}=t;try{return new Function(`return ${r}`)()({variables:e},{lodash:y,interpolate:xt.interpolate})}catch(i){return console.error(`[getNumberOrDynamicValue] failed parsing custom function, error: ${i.message}`),10}}function zg(t,e){const n=Bt(t.heat_block.min,e),r=Bt(t.heat_block.max,e);return{min:n,max:r,calculable:!0,orient:"horizontal",left:"center",top:0,itemWidth:15}}function Eg(t,e,n){const{overflow:r,rotate:i}=t.x_axis.axisLabel,o=Qe(r.on_axis);return{id:"main-x-axis",type:"category",data:e,name:t.x_axis.name??"",align:"center",axisTick:{show:!0,alignWithLabel:!0},axisLabel:{rotate:i,...o,formatter:n},splitArea:{show:!0},nameLocation:"center",nameGap:25,nameTextStyle:{fontWeight:"bold",align:"center"},z:2}}function Pg(t,e,n){const{nameAlignment:r,data_key:i,...o}=t.y_axis,{overflow:l,rotate:c}=t.y_axis.axisLabel,u=Qe(l.on_axis);return{...o,type:"category",data:e,axisLabel:{rotate:c,...u,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}}const Lg={tooltip:{confine:!0}};function Bg(t,e,n,r){return n<t*10||r<e*10?0:n<t*20||r<e*20?1:2}function Og(t,e,n,r,i){if(!t.x_axis.data_key||!t.y_axis.data_key||!t.heat_block.data_key)return{};const o=n.reduce((T,A)=>{const L=at(A,e);return T[A.name]=qe(A,L),T},{}),l=jg(t),c=vg(t),u=D(t.x_axis.data_key),d=D(t.y_axis.data_key),h=D(t.heat_block.data_key),p=y.uniq(e[u.queryID].map(T=>T[u.columnKey])),x=y.uniq(e[u.queryID].map(T=>T[d.columnKey])),m=e[u.queryID].map(T=>[y.get(T,u.columnKey),y.get(T,d.columnKey),y.get(T,h.columnKey)]),j=Bg(p.length,x.length,r,i),C={xAxis:Eg(t,p,l.x_axis),yAxis:Pg(t,x,l.y_axis),series:Cg(t,m,j),tooltip:kg(t,e,l,c),grid:wg(t),visualMap:zg(t,o)};return y.defaultsDeep({},C,Lg)}function $g(t){return s.jsx(s.Fragment,{})}function Vg(t){return s.jsx(a.Text,{children:"Click heat block"})}const Da={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:Vg,configRender:$g,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"}]},Hs={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,overflow:ze,formatter:{...Oe}}},y_axis:{name:"Y Axis",data_key:"",nameAlignment:"center",axisLabel:{rotate:0,overflow:ze,formatter:{...Oe}}},heat_block:{min:{type:"static",value:0},max:{type:"static",value:100},name:"Value",data_key:"",value_formatter:ye,label:{show:!1,fontSize:10}},tooltip:{metrics:[]}};K.use([P.DataZoomComponent,te.HeatmapChart,P.GridComponent,P.LegendComponent,P.TooltipComponent,P.VisualMapComponent,we.CanvasRenderer]);function Ng({conf:t,data:e,width:n,height:r,interactionManager:i,variables:o}){const l=f.useMemo(()=>{const p=D(t.x_axis.data_key),x=D(t.y_axis.data_key);return y.keyBy(e[p.queryID],m=>`${m[p.columnKey]}---${m[x.columnKey]}`)},[e,t.x_axis.data_key,t.y_axis.data_key]),c=$e(i.triggerManager,Da.id),u=f.useCallback(p=>{const[x,m]=p.value,j=y.get(l,`${x}---${m}`,{error:"rowData is not found"});c.forEach(C=>{i.runInteraction(C.id,{...p,rowData:j})})},[l,c,i]),d=f.useMemo(()=>({click:u}),[u]),h=f.useMemo(()=>Og(t,e,o,n,r),[t,e,n,r]);return s.jsx(ve,{echarts:K,option:h,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function qg({context:t,instance:e}){const n=Ve({vizManager:t.vizManager,instance:e}),{value:r}=O(t.instanceData,"config"),{variables:i}=t,o=f.useMemo(()=>y.defaults({},r,Hs),[r]),l=t.data,{width:c,height:u}=t.viewport;return!c||!u?null:s.jsx(Te,{width:c,height:u,children:s.jsx(Ng,{variables:i,width:We(c),height:Re(u),data:l,conf:o,interactionManager:n})})}function Fg({control:t,watch:e}){e(["heat_block"]);const n=e("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:t,render:({field:r})=>s.jsx(B,{label:"Data Field",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:"heat_block.name",control:t,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:t,render:({field:r})=>s.jsx(Lt,{label:"Min Value",...r})}),s.jsx(b.Controller,{name:"heat_block.max",control:t,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:t,render:({field:r})=>s.jsx(Ae,{...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:t,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:t,render:({field:r})=>s.jsx(a.NumberInput,{size:"xs",icon:s.jsx(k.IconTextSize,{size:16}),disabled:!n,...r})})]})]})}const Gg=({control:t,index:e,remove:n})=>s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`tooltip.metrics.${e}.name`,control:t,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`tooltip.metrics.${e}.data_key`,control:t,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(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),Wg=({control:t,watch:e})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:t,name:"tooltip.metrics"}),o=e("tooltip.metrics"),l=n.map((p,x)=>({...p,...o[x]})),c=()=>r({id:Date.now().toString(),data_key:"",name:""}),u=e("tooltip.metrics.0.id"),[d,h]=f.useState(()=>u??null);return f.useEffect(()=>{u&&h(p=>p!==null?p:u)},[u]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(_.InfoCircle,{size:14,color:"#888"}),s.jsx(a.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),s.jsx(a.Divider,{variant:"dashed",my:10}),s.jsxs(a.Tabs,{value:d,onTabChange:p=>h(p),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((p,x)=>s.jsx(a.Tabs.Tab,{value:p.id,children:p.name?p.name:x},p.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),l.map((p,x)=>s.jsx(a.Tabs.Panel,{value:p.id,children:s.jsx(Gg,{control:t,index:x,remove:i},p.id)},p.id))]})]})};function Rg({control:t,watch:e}){return s.jsx(Wg,{control:t,watch:e})}const Qg=({disabled:t,value:e,onChange:n})=>{const r=i=>{i&&n(i)};return s.jsxs(a.Box,{sx:{position:"relative"},children:[t&&s.jsx(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),s.jsx(me,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},Yg={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
161
- `)},Ma=f.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:i,setFalse:o}]=$.useBoolean(),[l,c]=f.useState(t);f.useEffect(()=>{c(t)},[t]);const u=m=>{c({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:j}=l,C={enabled:m,func_content:j};c(C),e(C)},h=()=>{o(),c(t)},p=m=>{c(j=>({...j,func_content:m}))},x=()=>{p(Yg.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(Qg,{value:l.func_content,onChange:p,disabled:!l.enabled}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:x,color:"red",leftIcon:s.jsx(_.Recycle,{size:20}),children:"Reset"}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:h,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:d,children:"OK"})]})]})]})})]})});function Kg({control:t,watch:e}){return e(["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:t,render:({field:n})=>s.jsx(B,{label:"Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"x_axis.name",control:t,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:t,render:({field:n})=>s.jsx(Xe,{...n})}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:t,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:t,render:({field:n})=>s.jsx(Ma,{...n})})]})]})}const Ug=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function Xg({control:t,watch:e}){return e(["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:t,render:({field:n})=>s.jsx(B,{label:"Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"y_axis.name",control:t,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:t,render:({field:n})=>s.jsx(a.Select,{label:"Name Alignment",required:!0,data:Ug,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:t,render:({field:n})=>s.jsx(Xe,{...n})}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"y_axis.axisLabel.rotate",control:t,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:t,render:({field:n})=>s.jsx(Ma,{...n})})]})]})}function Jg({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},e,Hs),[e]),i=f.useMemo(()=>y.cloneDeep(r),[r]);f.useEffect(()=>{!y.isEqual(r,i)&&(console.log("config malformed, resetting to defaults",r,i),n(i))},[r,i]);const{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=b.useForm({defaultValues:i});f.useEffect(()=>{d(i)},[i]);const h=u(),p=f.useMemo(()=>!y.isEqual(h,r),[h,r]);return s.jsx("form",{onSubmit:l(n),style:{flexGrow:1},children:s.jsxs(a.Stack,{spacing:"xs",sx:{height:"100%"},children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Chart Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(_.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(Kg,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Y Axis",children:s.jsx(Xg,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Heat Block",children:s.jsx(Fg,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(Rg,{control:o,watch:c})})]})]})})}function Zg(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=d=>d&&`${n}.${d}`,{x_axis:i,y_axis:o,heat_block:l,tooltip:c,...u}=t;return{...u,x_axis:{...i,data_key:r(i.data_key)},y_axis:{...o,data_key:r(o.data_key)},heat_block:{...l,data_key:r(l.data_key)},tooltip:{...c,metrics:c.metrics.map(d=>({...d,data_key:r(d.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}function Hg(t){return y.defaultsDeep({},t,{heat_block:{label:{show:!1,fontSize:10}}})}function em(t){const{heat_block:e}=t;let{min:n,max:r}=e;return typeof n!="number"&&(n=0),typeof r!="number"&&(r=100),{...t,heat_block:{...e,min:{type:"static",value:n},max:{type:"static",value:r}}}}class tm extends re{constructor(){super(...arguments);z(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:Zg(n.config,r)})),this.version(3,n=>({...n,version:3,config:Hg(n.config)})),this.version(4,n=>({...n,version:4,config:em(n.config)}))}}const nm={displayName:"Heatmap",displayGroup:"ECharts-based charts",migrator:new tm,name:"heatmap",viewRender:qg,configRender:Jg,createConfig:()=>({version:4,config:Hs}),triggers:[Da]},Aa={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:rm,configRender:sm,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 sm(t){return s.jsx(s.Fragment,{})}function rm(t){return s.jsx(a.Text,{children:"Click chart's series"})}const za={label_template:"${percentage.x} of ${x_axis.name} causes ${percentage.y} of ${bar.name}",color:"#789AB4"},er={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...Oe},overflow:ze}},data_key:"value",bar:{name:"Value",nameAlignment:"left",color:"#228be6",label_formatter:ye},line:{name:"Value",nameAlignment:"right",color:"red"},dataZoom:Pt,markLine:za};function Pn(t){return F(t).format({output:"percent",mantissa:0})}function im(t){const e=t.value[1];try{return Pn(e)}catch(n){return console.error(n),e}}function am(t){function e(n){let r=n;if(typeof n=="object"&&(Array.isArray(n.value)&&n.value.length===2?r=n.value[1]:r=n.value),!t.bar.label_formatter)return r;try{return F(r).format(t.bar.label_formatter)}catch(i){return console.error(i),r}}return{bar:e,line:im,lineValue:Pn}}function om(t,e,n){const{label_template:r}=t.markLine;if(!r)return"";const i={...t,percentage:e,count:n},o=Object.keys(i),l=Object.values(i);return new Function(...o,`return \`${r}\`;`)(...l)}function lm(t,e){if(e.length===0)return{};const n=e.findIndex(c=>c[1]>=.8);if(n===-1)return{};const r=e[n],i={x:Pn((n+1)/e.length),y:Pn(r[1])},o={left:n+1,right:e.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:t.markLine.color},label:{formatter:om(t,i,o)}}]},markArea:{name:"",silent:!0,itemStyle:{color:"rgba(47, 140, 192, 0.05)"},data:[[{type:"min"},{xAxis:l}]]}}:{}}function cm(t,e,n){const{x_axis:r,data_key:i}=t;if(!r.data_key||!i)return[];const o=D(r.data_key),l=D(i);if(o.queryID!==l.queryID)throw new Error("Please use the same query for X & Y axis");const c=e[o.queryID].map(x=>[x[o.columnKey],Number(x[l.columnKey])]).sort((x,m)=>m[1]-x[1]),u=c.reduce((x,m)=>x+m[1],0),d=c.reduce((x,m,j)=>{const C=j===0?0:x[j-1][1];return x.push([m[0],C+m[1]]),x},[]).map(x=>[x[0],x[1]/u]),{markLine:h,markArea:p}=lm(t,d);return[{name:t.bar.name,type:"bar",barMaxWidth:20,itemStyle:{color:t.bar.color},label:{show:!1,position:"top",formatter:n.bar},yAxisIndex:0,data:c},{name:t.line.name,type:"line",itemStyle:{color:t.line.color},symbolSize:2,lineStyle:{width:1,shadowColor:"rgba(255,255,255,1)",shadowBlur:0,shadowOffsetX:0,shadowOffsetY:1},label:{show:!1,position:"top",formatter:n.line},yAxisIndex:1,data:d,markLine:h,markArea:p}]}const um=(t,e)=>n=>{const r=Array.isArray(n)?n:[n];if(r.length===0)return"";const i=r.map((c,u)=>{const d=c.seriesName,[h,p]=c.value;if(!d)return p;const x=u===0?e.bar:e.lineValue;return`
159
+ `}}}const vg=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return s.jsx(a.Box,{children:s.jsx(ge,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Ia={static:{type:"static",value:10},dynamic:{type:"dynamic",value:["function getValue({ variables }, { lodash, interpolate }) {"," // your code goes here"," return 100;","}"].join(`
160
+ `)}},wg=({value:t,onChange:e})=>{const[n,{setTrue:r,setFalse:i}]=$.useBoolean(),[o,l]=f.useState(t),c=()=>{i();const{type:h,value:x}=o,m={type:h,value:x};l(m),e(m)},u=()=>{i(),l(t)},d=h=>{l(x=>({...x,value:h}))},p=()=>{d(Ia.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(vg,{value:o.value,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"})]})]})]})})]})},Cg=({value:t,onChange:e})=>t.type!=="dynamic"?null:s.jsx(wg,{value:t,onChange:e}),Sg=({value:t,onChange:e})=>{if(t.type!=="static")return null;const n=r=>{e({...t,value:r})};return s.jsx(a.NumberInput,{defaultValue:18,label:" ",hideControls:!0,value:t.value,onChange:n})},_g=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Lt=f.forwardRef(({label:t="Value",value:e,onChange:n},r)=>{const i=o=>{n({...Ia[o]})};return s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(a.Select,{ref:r,label:t,data:_g,value:e.type,onChange:i,sx:{flexGrow:1}}),s.jsx(Sg,{value:e,onChange:n}),s.jsx(Cg,{value:e,onChange:n})]})});function Bt(t,e,n){if(!t.type)return n;if(t.type==="static"){const{value:i}=t;return i}const{value:r}=t;try{return new Function(`return ${r}`)()({variables:e},{lodash:y,interpolate:ft.interpolate})}catch(i){return console.error(`[getNumberOrDynamicValue] failed parsing custom function, error: ${i.message}`),10}}function kg(t,e){const n=Bt(t.heat_block.min,e),r=Bt(t.heat_block.max,e);return{min:n,max:r,calculable:!0,orient:"horizontal",left:"center",top:0,itemWidth:15}}function Tg(t,e,n){const{overflow:r,rotate:i}=t.x_axis.axisLabel,o=Qe(r.on_axis);return{id:"main-x-axis",type:"category",data:e,name:t.x_axis.name??"",align:"center",axisTick:{show:!0,alignWithLabel:!0},axisLabel:{rotate:i,...o,formatter:n},splitArea:{show:!0},nameLocation:"center",nameGap:25,nameTextStyle:{fontWeight:"bold",align:"center"},z:2}}function Ig(t,e,n){const{nameAlignment:r,data_key:i,...o}=t.y_axis,{overflow:l,rotate:c}=t.y_axis.axisLabel,u=Qe(l.on_axis);return{...o,type:"category",data:e,axisLabel:{rotate:c,...u,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}}const Dg={tooltip:{confine:!0}};function Mg(t,e,n,r){return n<t*10||r<e*10?0:n<t*20||r<e*20?1:2}function Ag(t,e,n,r,i){if(!t.x_axis.data_key||!t.y_axis.data_key||!t.heat_block.data_key)return{};const o=n.reduce((T,A)=>{const L=it(A,e);return T[A.name]=Ne(A,L),T},{}),l=xg(t),c=fg(t),u=D(t.x_axis.data_key),d=D(t.y_axis.data_key),p=D(t.heat_block.data_key),h=y.uniq(e[u.queryID].map(T=>T[u.columnKey])),x=y.uniq(e[u.queryID].map(T=>T[d.columnKey])),m=e[u.queryID].map(T=>[y.get(T,u.columnKey),y.get(T,d.columnKey),y.get(T,p.columnKey)]),j=Mg(h.length,x.length,r,i),C={xAxis:Tg(t,h,l.x_axis),yAxis:Ig(t,x,l.y_axis),series:mg(t,m,j),tooltip:jg(t,e,l,c),grid:gg(t),visualMap:kg(t,o)};return y.defaultsDeep({},C,Dg)}function zg(t){return s.jsx(s.Fragment,{})}function Eg(t){return s.jsx(a.Text,{children:"Click heat block"})}const Da={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:Eg,configRender:zg,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"}]},Hs={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,overflow:Ae,formatter:{...Oe}}},y_axis:{name:"Y Axis",data_key:"",nameAlignment:"center",axisLabel:{rotate:0,overflow:Ae,formatter:{...Oe}}},heat_block:{min:{type:"static",value:0},max:{type:"static",value:100},name:"Value",data_key:"",value_formatter:ye,label:{show:!1,fontSize:10}},tooltip:{metrics:[]}};Y.use([P.DataZoomComponent,te.HeatmapChart,P.GridComponent,P.LegendComponent,P.TooltipComponent,P.VisualMapComponent,we.CanvasRenderer]);function Pg({conf:t,data:e,width:n,height:r,interactionManager:i,variables:o}){const l=f.useMemo(()=>{const h=D(t.x_axis.data_key),x=D(t.y_axis.data_key);return y.keyBy(e[h.queryID],m=>`${m[h.columnKey]}---${m[x.columnKey]}`)},[e,t.x_axis.data_key,t.y_axis.data_key]),c=$e(i.triggerManager,Da.id),u=f.useCallback(h=>{const[x,m]=h.value,j=y.get(l,`${x}---${m}`,{error:"rowData is not found"});c.forEach(C=>{i.runInteraction(C.id,{...h,rowData:j})})},[l,c,i]),d=f.useMemo(()=>({click:u}),[u]),p=f.useMemo(()=>Ag(t,e,o,n,r),[t,e,n,r]);return s.jsx(ve,{echarts:Y,option:p,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function Lg({context:t,instance:e}){const n=Ve({vizManager:t.vizManager,instance:e}),{value:r}=O(t.instanceData,"config"),{variables:i}=t,o=f.useMemo(()=>y.defaults({},r,Hs),[r]),l=t.data,{width:c,height:u}=t.viewport;return!c||!u?null:s.jsx(Te,{width:c,height:u,children:s.jsx(Pg,{variables:i,width:We(c),height:Re(u),data:l,conf:o,interactionManager:n})})}function Bg({control:t,watch:e}){e(["heat_block"]);const n=e("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:t,render:({field:r})=>s.jsx(B,{label:"Data Field",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:"heat_block.name",control:t,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:t,render:({field:r})=>s.jsx(Lt,{label:"Min Value",...r})}),s.jsx(b.Controller,{name:"heat_block.max",control:t,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:t,render:({field:r})=>s.jsx(Be,{...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:t,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:t,render:({field:r})=>s.jsx(a.NumberInput,{size:"xs",icon:s.jsx(k.IconTextSize,{size:16}),disabled:!n,...r})})]})]})}const Og=({control:t,index:e,remove:n})=>s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`tooltip.metrics.${e}.name`,control:t,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`tooltip.metrics.${e}.data_key`,control:t,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(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),$g=({control:t,watch:e})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:t,name:"tooltip.metrics"}),o=e("tooltip.metrics"),l=n.map((h,x)=>({...h,...o[x]})),c=()=>r({id:Date.now().toString(),data_key:"",name:""}),u=e("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(Og,{control:t,index:x,remove:i},h.id)},h.id))]})]})};function Vg({control:t,watch:e}){return s.jsx($g,{control:t,watch:e})}const Ng=({disabled:t,value:e,onChange:n})=>{const r=i=>{i&&n(i)};return s.jsxs(a.Box,{sx:{position:"relative"},children:[t&&s.jsx(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),s.jsx(ge,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},qg={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
161
+ `)},Ma=f.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:i,setFalse:o}]=$.useBoolean(),[l,c]=f.useState(t);f.useEffect(()=>{c(t)},[t]);const u=m=>{c({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:j}=l,C={enabled:m,func_content:j};c(C),e(C)},p=()=>{o(),c(t)},h=m=>{c(j=>({...j,func_content:m}))},x=()=>{h(qg.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(Ng,{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 Fg({control:t,watch:e}){return e(["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:t,render:({field:n})=>s.jsx(B,{label:"Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"x_axis.name",control:t,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:t,render:({field:n})=>s.jsx(Xe,{...n})}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:t,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:t,render:({field:n})=>s.jsx(Ma,{...n})})]})]})}const Gg=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function Wg({control:t,watch:e}){return e(["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:t,render:({field:n})=>s.jsx(B,{label:"Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"y_axis.name",control:t,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:t,render:({field:n})=>s.jsx(a.Select,{label:"Name Alignment",required:!0,data:Gg,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:t,render:({field:n})=>s.jsx(Xe,{...n})}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"y_axis.axisLabel.rotate",control:t,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:t,render:({field:n})=>s.jsx(Ma,{...n})})]})]})}function Rg({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},e,Hs),[e]),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("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(Fg,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Y Axis",children:s.jsx(Wg,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Heat Block",children:s.jsx(Bg,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(Vg,{control:o,watch:c})})]})]})})}function Qg(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=d=>d&&`${n}.${d}`,{x_axis:i,y_axis:o,heat_block:l,tooltip:c,...u}=t;return{...u,x_axis:{...i,data_key:r(i.data_key)},y_axis:{...o,data_key:r(o.data_key)},heat_block:{...l,data_key:r(l.data_key)},tooltip:{...c,metrics:c.metrics.map(d=>({...d,data_key:r(d.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}function Ug(t){return y.defaultsDeep({},t,{heat_block:{label:{show:!1,fontSize:10}}})}function Yg(t){const{heat_block:e}=t;let{min:n,max:r}=e;return typeof n!="number"&&(n=0),typeof r!="number"&&(r=100),{...t,heat_block:{...e,min:{type:"static",value:n},max:{type:"static",value:r}}}}class Kg extends re{constructor(){super(...arguments);z(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:Qg(n.config,r)})),this.version(3,n=>({...n,version:3,config:Ug(n.config)})),this.version(4,n=>({...n,version:4,config:Yg(n.config)}))}}const Xg={displayName:"Heatmap",displayGroup:"ECharts-based charts",migrator:new Kg,name:"heatmap",viewRender:Lg,configRender:Rg,createConfig:()=>({version:4,config:Hs}),triggers:[Da]},Aa={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:Zg,configRender:Jg,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 Jg(t){return s.jsx(s.Fragment,{})}function Zg(t){return s.jsx(a.Text,{children:"Click chart's series"})}const za={label_template:"${percentage.x} of ${x_axis.name} causes ${percentage.y} of ${bar.name}",color:"#789AB4"},er={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...Oe},overflow:Ae}},data_key:"value",bar:{name:"Value",nameAlignment:"left",color:"#228be6",label_formatter:ye},line:{name:"Value",nameAlignment:"right",color:"red"},dataZoom:zt,markLine:za};function zn(t){return F(t).format({output:"percent",mantissa:0})}function Hg(t){const e=t.value[1];try{return zn(e)}catch(n){return console.error(n),e}}function em(t){function e(n){let r=n;if(typeof n=="object"&&(Array.isArray(n.value)&&n.value.length===2?r=n.value[1]:r=n.value),!t.bar.label_formatter)return r;try{return F(r).format(t.bar.label_formatter)}catch(i){return console.error(i),r}}return{bar:e,line:Hg,lineValue:zn}}function tm(t,e,n){const{label_template:r}=t.markLine;if(!r)return"";const i={...t,percentage:e,count:n},o=Object.keys(i),l=Object.values(i);return new Function(...o,`return \`${r}\`;`)(...l)}function nm(t,e){if(e.length===0)return{};const n=e.findIndex(c=>c[1]>=.8);if(n===-1)return{};const r=e[n],i={x:zn((n+1)/e.length),y:zn(r[1])},o={left:n+1,right:e.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:t.markLine.color},label:{formatter:tm(t,i,o)}}]},markArea:{name:"",silent:!0,itemStyle:{color:"rgba(47, 140, 192, 0.05)"},data:[[{type:"min"},{xAxis:l}]]}}:{}}function sm(t,e,n){const{x_axis:r,data_key:i}=t;if(!r.data_key||!i)return[];const o=D(r.data_key),l=D(i);if(o.queryID!==l.queryID)throw new Error("Please use the same query for X & Y axis");const c=e[o.queryID].map(x=>[x[o.columnKey],Number(x[l.columnKey])]).sort((x,m)=>m[1]-x[1]),u=c.reduce((x,m)=>x+m[1],0),d=c.reduce((x,m,j)=>{const C=j===0?0:x[j-1][1];return x.push([m[0],C+m[1]]),x},[]).map(x=>[x[0],x[1]/u]),{markLine:p,markArea:h}=nm(t,d);return[{name:t.bar.name,type:"bar",barMaxWidth:20,itemStyle:{color:t.bar.color},label:{show:!1,position:"top",formatter:n.bar},yAxisIndex:0,data:c},{name:t.line.name,type:"line",itemStyle:{color:t.line.color},symbolSize:2,lineStyle:{width:1,shadowColor:"rgba(255,255,255,1)",shadowBlur:0,shadowOffsetX:0,shadowOffsetY:1},label:{show:!1,position:"top",formatter:n.line},yAxisIndex:1,data:d,markLine:p,markArea:h}]}const rm=(t,e)=>n=>{const r=Array.isArray(n)?n:[n];if(r.length===0)return"";const i=r.map((c,u)=>{const d=c.seriesName,[p,h]=c.value;if(!d)return h;const x=u===0?e.bar:e.lineValue;return`
162
162
  <tr>
163
163
  <th style="text-align: right; padding: 0 1em;">${d}</th>
164
- <td style="text-align: left; padding: 0 1em;">${x(p)}</td>
164
+ <td style="text-align: left; padding: 0 1em;">${x(h)}</td>
165
165
  </tr>
166
166
  `}),o=Je(t.x_axis.axisLabel.overflow.in_tooltip),l=r[0].name;return`
167
167
  <div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
@@ -172,7 +172,7 @@ Check the top-level render call using <`+M+">.")}return I}}function oc(v,I){{if(
172
172
  ${i.join("")}
173
173
  </tbody>
174
174
  </table>
175
- `};function dm(t,e){return{trigger:"axis",formatter:um(t,e)}}function pm(t){const{name:e,axisLabel:n}=t.x_axis,r=Qe(n.overflow.on_axis);return[Le.getXAxis({type:"category",name:e,nameLocation:"middle",nameGap:30,nameTextStyle:{align:"right"},axisLabel:{...n,...r,formatter:Mt(n.formatter)}})]}function hm(t,e){return[Le.getYAxis({name:t.bar.name,nameGap:20,minInterval:1,nameTextStyle:{align:t.bar.nameAlignment},position:"left",axisLabel:{show:!0,formatter:e.bar},splitLine:{show:!1}}),Le.getYAxis({name:t.line.name,nameGap:20,nameTextStyle:{align:t.line.nameAlignment},position:"right",axisLabel:{show:!0,formatter:e.lineValue}})]}function xm(t,e,n){const r=am(t);return{dataZoom:Ys(t.dataZoom),tooltip:dm(t,r),xAxis:pm(t),yAxis:hm(t,r),series:cm(t,e,r),grid:{top:50,left:30,right:15,bottom:5,containLabel:!0}}}K.use([te.BarChart,te.LineChart,P.DataZoomComponent,P.GridComponent,P.LegendComponent,P.TooltipComponent,we.CanvasRenderer]);function fm({context:t,instance:e}){const{value:n}=O(t.instanceData,"config"),r=t.data,{width:i,height:o}=t.viewport,l=y.defaults({},n,er),c=xm(l,r),u=Ve({vizManager:t.vizManager,instance:e}),d=$e(u.triggerManager,Aa.id),h=mt(r,l.x_axis.data_key),p=f.useCallback(m=>{const j=y.get(h,m.name,{error:"rowData is not found"});d.forEach(C=>{u.runInteraction(C.id,{...m,rowData:j})})},[h,d,u]),x=f.useMemo(()=>({click:p}),[p]);return!l||!i||!o?null:s.jsx(Te,{width:i,height:o,children:s.jsx(ve,{echarts:K,option:c,style:Wt(i,o),onEvents:x,notMerge:!0,theme:"merico-light"})})}const gm=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function mm({control:t,watch:e}){return e(["bar"]),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:"bar.name",control:t,render:({field:n})=>s.jsx(a.TextInput,{label:"Bar Name",sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"bar.nameAlignment",control:t,render:({field:n})=>s.jsx(a.Select,{label:"Align",required:!0,data:gm,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:t,render:({field:n})=>s.jsx(Se,{...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:t,render:({field:n})=>s.jsx(Ae,{...n})})]})]})}const ym=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function bm({control:t,watch:e}){return e(["line"]),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:"line.name",control:t,render:({field:n})=>s.jsx(a.TextInput,{label:"Line Name",sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"line.nameAlignment",control:t,render:({field:n})=>s.jsx(a.Select,{label:"Align",required:!0,data:ym,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:t,render:({field:n})=>s.jsx(Se,{...n})})]})]})}const jm=`
175
+ `};function im(t,e){return{trigger:"axis",formatter:rm(t,e)}}function am(t){const{name:e,axisLabel:n}=t.x_axis,r=Qe(n.overflow.on_axis);return[ze.getXAxis({type:"category",name:e,nameLocation:"middle",nameGap:30,nameTextStyle:{align:"right"},axisLabel:{...n,...r,formatter:Mt(n.formatter)}})]}function om(t,e){return[ze.getYAxis({name:t.bar.name,nameGap:20,minInterval:1,nameTextStyle:{align:t.bar.nameAlignment},position:"left",axisLabel:{show:!0,formatter:e.bar},splitLine:{show:!1}}),ze.getYAxis({name:t.line.name,nameGap:20,nameTextStyle:{align:t.line.nameAlignment},position:"right",axisLabel:{show:!0,formatter:e.lineValue}})]}function lm(t,e,n){const r=em(t);return{dataZoom:Ms(t.dataZoom),tooltip:im(t,r),xAxis:am(t),yAxis:om(t,r),series:sm(t,e,r),grid:{top:50,left:30,right:15,bottom:5,containLabel:!0}}}Y.use([te.BarChart,te.LineChart,P.DataZoomComponent,P.GridComponent,P.LegendComponent,P.TooltipComponent,we.CanvasRenderer]);function cm({context:t,instance:e}){const{value:n}=O(t.instanceData,"config"),r=t.data,{width:i,height:o}=t.viewport,l=y.defaults({},n,er),c=lm(l,r),u=Ve({vizManager:t.vizManager,instance:e}),d=$e(u.triggerManager,Aa.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"});d.forEach(C=>{u.runInteraction(C.id,{...m,rowData:j})})},[p,d,u]),x=f.useMemo(()=>({click:h}),[h]);return!l||!i||!o?null:s.jsx(Te,{width:i,height:o,children:s.jsx(ve,{echarts:Y,option:c,style:Wt(i,o),onEvents:x,notMerge:!0,theme:"merico-light"})})}const um=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function dm({control:t,watch:e}){return e(["bar"]),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:"bar.name",control:t,render:({field:n})=>s.jsx(a.TextInput,{label:"Bar Name",sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"bar.nameAlignment",control:t,render:({field:n})=>s.jsx(a.Select,{label:"Align",required:!0,data:um,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:t,render:({field:n})=>s.jsx(Se,{...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:t,render:({field:n})=>s.jsx(Be,{...n})})]})]})}const pm=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function hm({control:t,watch:e}){return e(["line"]),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:"line.name",control:t,render:({field:n})=>s.jsx(a.TextInput,{label:"Line Name",sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"line.nameAlignment",control:t,render:({field:n})=>s.jsx(a.Select,{label:"Align",required:!0,data:pm,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:t,render:({field:n})=>s.jsx(Se,{...n})})]})]})}const xm=`
176
176
  {
177
177
  // 80-20 line stuff
178
178
  percentage: {
@@ -195,8 +195,8 @@ Check the top-level render call using <`+M+">.")}return I}}function oc(v,I){{if(
195
195
  name: string;
196
196
  };
197
197
  }
198
- `,vm=()=>{const[t,e]=f.useState(!1);return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"subtle",compact:!0,onClick:()=>e(n=>!n),children:t?"Close":"Click to see params for Label Template"}),s.jsx(a.Collapse,{in:t,children:s.jsx(ft.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:jm})})]})};function wm({control:t,watch:e}){return e(["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:t,render:({field:n})=>s.jsx(Se,{...n})})]}),s.jsxs(a.Stack,{spacing:4,children:[s.jsx(b.Controller,{name:"markLine.label_template",control:t,render:({field:n})=>s.jsx(a.Textarea,{autosize:!0,minRows:2,maxRows:4,label:"Label Template",sx:{flex:1},...n})}),s.jsx(vm,{})]})]})}function Cm({control:t,watch:e}){return e(["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:t,render:({field:n})=>s.jsx(B,{label:"Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"x_axis.name",control:t,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:t,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:t,render:({field:n})=>s.jsx(zn,{...n})})]}),s.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>s.jsx(Xe,{...n})})]})}function Sm({control:t,watch:e}){return e(["data_key"]),s.jsx(a.Stack,{children:s.jsx(b.Controller,{name:"data_key",control:t,render:({field:n})=>s.jsx(B,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})})})}function _m({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=f.useMemo(()=>y.defaults({},e,er),[e]),{control:i,handleSubmit:o,watch:l,getValues:c,reset:u}=b.useForm({defaultValues:r});f.useEffect(()=>{u(r)},[r]),l(["x_axis","data_key","bar","line","dataZoom"]);const d=c(),h=f.useMemo(()=>!y.isEqual(d,e),[d,e]);return s.jsxs("form",{onSubmit:o(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Chart Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:s.jsx(_.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(Cm,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Y Axis",children:s.jsx(Sm,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Bar",children:s.jsx(mm,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Line",children:s.jsx(bm,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"80-20 Line",children:s.jsx(wm,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Zooming",children:s.jsx(b.Controller,{name:"dataZoom",control:i,render:({field:p})=>s.jsx(Us,{...p})})})]})]})}function km(t){const{dataZoom:e=Pt,...n}=t;return{...n,dataZoom:e}}function Tm(t){const{markLine:e=za,...n}=t;return{...n,markLine:e}}function Im(t){const e=y.defaultsDeep({},t.x_axis.axisLabel,{rotate:0,formatter:{...Oe}});return{...t,x_axis:{...t.x_axis,axisLabel:e}}}function Dm(t){const{label_formatter:e=ye}=t.bar;return{...t,bar:{...t.bar,label_formatter:e}}}function Mm(t){const e={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return y.defaultsDeep(e,t)}function Am(t){const e={bar:{nameAlignment:"left"},line:{nameAlignment:"right"}};return y.defaultsDeep(e,t)}function zm(t){console.log(t);const{x_axis:e,tooltip:n}=t.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:e,in_tooltip:n}}}};return y.defaultsDeep(r,t)}function Em(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:i,data_key:o,...l}=t;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 Pm extends re{constructor(){super(...arguments);z(this,"VERSION",9)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:km(n.config)})),this.version(3,n=>({...n,version:3,config:Tm(n.config)})),this.version(4,n=>({...n,version:4,config:Im(n.config)})),this.version(5,n=>({...n,version:5,config:Dm(n.config)})),this.version(6,n=>({...n,version:6,config:Mm(n.config)})),this.version(7,n=>({...n,version:7,config:Am(n.config)})),this.version(8,n=>({...n,version:8,config:zm(n.config)})),this.version(9,(n,r)=>({...n,version:9,config:Em(n.config,r)}))}}const Lm={displayName:"Pareto Chart",displayGroup:"ECharts-based charts",migrator:new Pm,name:"paretoChart",viewRender:fm,configRender:_m,createConfig(){return{version:9,config:y.cloneDeep(er)}},triggers:[Aa]},tr={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 Bm(){K.registerTheme("merico-light",{color:Object.values(tr.graphics.multiple),visualMap:{color:Object.values(tr.graphics.depth).reverse()},axes:[{type:"all",name:"通用坐标轴",axisLineColor:"#97999D",axisTickColor:"#97999D",axisLabelShow:!0,axisLabelColor:"#818388",splitLineShow:!0,splitLineColor:["#E0E6F1"]}]})}function Ea(){Bm()}function*Om(t){const e=tr.graphics[t];if(!e)throw new Error("Invalid palette key provided");const n=Object.values(e);let r=0;for(;;)yield n[r%n.length],r++}function $m(t,e,n){const{label_field:r,value_field:i,color_field:o}=t;if(!r||!i)return{};const l=D(r),c=D(i),u=D(o),d=e[l.queryID].map(p=>({name:p[l.columnKey],value:Number(p[c.columnKey]),color:u.columnKey?p[u.columnKey]:void 0})),h=Om("multiple");return{type:"pie",name:"pie",radius:["50%","80%"],itemStyle:{color:({data:p})=>p.color?p.color:h.next().value},label:{position:"outer",alignTo:"edge",formatter:`{name|{b}}
199
- {percentage|{d}%}`,minMargin:5,edgeDistance:10,lineHeight:15,rich:{percentage:{color:"#999"}},margin:20},labelLine:{length:15,length2:0,maxSurfaceAngle:80,showAbove:!0},labelLayout:function(p){const x=p.labelRect.x<n/2,m=p.labelLinePoints;return y.set(m,[2,0],x?p.labelRect.x:p.labelRect.x+p.labelRect.width),{labelLinePoints:m}},data:d,top:10,bottom:10,left:10,right:10}}function Vm(t,e,n){return{tooltip:{show:!0,confine:!0},series:$m(t,e,n)}}const Pa={id:"builtin:echarts:click-pie-chart:series",displayName:"Click Pie Series",nameRender:qm,configRender:Nm,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 Nm(t){return s.jsx(s.Fragment,{})}function qm(t){return s.jsx(a.Text,{children:"Click chart's series"})}const nr={label_field:"",value_field:"",color_field:""};K.use([te.PieChart,we.CanvasRenderer]);function Fm({conf:t,data:e,width:n,height:r,interactionManager:i}){const o=mt(e,t.label_field),l=$e(i.triggerManager,Pa.id),c=f.useCallback(h=>{const p=y.get(o,h.name,{error:"rowData is not found"});l.forEach(x=>{i.runInteraction(x.id,{...h,rowData:p})})},[o,l,i]),u=f.useMemo(()=>Vm(t,e,n),[t,e,n]),d=f.useMemo(()=>({click:c}),[c]);return!n||!r||!u.series.name?null:s.jsx(ve,{echarts:K,option:u,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function Gm({context:t,instance:e}){const n=Ve({vizManager:t.vizManager,instance:e}),{value:r}=O(t.instanceData,"config"),i=f.useMemo(()=>y.defaults({},r,nr),[r]),o=t.data,{width:l,height:c}=t.viewport;return!l||!c?null:s.jsx(Te,{width:l,height:c,children:s.jsx(Fm,{conf:i,width:We(l),height:Re(c),data:o,interactionManager:n})})}function Wm({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},e,nr),[e]),i=f.useMemo(()=>y.clone(r),[r]),{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=b.useForm({defaultValues:i});f.useEffect(()=>{d(i)},[i]);const h=u(),p=f.useMemo(()=>!y.isEqual(h,r),[h,r]);return c(["label_field","value_field","color_field"]),s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:l(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Pie Chart Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(_.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 Rm(t){const{color_field:e="",...n}=t;return{...n,color_field:e}}function Qm(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{label_field:i,value_field:o,color_field:l}=t;return{label_field:r(i),value_field:r(o),color_field:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class Ym extends re{constructor(){super(...arguments);z(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:Rm(n.config)})),this.version(3,(n,r)=>({...n,version:3,config:Qm(n.config,r)}))}}const Km={displayName:"Pie Chart",displayGroup:"ECharts-based charts",migrator:new Ym,name:"pie",viewRender:Gm,configRender:Wm,createConfig(){return{version:3,config:y.cloneDeep(nr)}},triggers:[Pa]};function Um(t){return s.jsx(s.Fragment,{})}function Xm(t){return s.jsx(a.Text,{children:"Click heat block"})}const La={id:"builtin:echarts:click-radar-chart:series",displayName:"Click radar chart series",nameRender:Xm,configRender:Um,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"}]},Ln={series_name_key:"",additional_series:[],background:{enabled:!0},label:{enabled:!0},dimensions:[]};function Ba(t){return t?e=>{try{return F(e).format(t)}catch(n){return console.error(n),e}}:e=>e}function Oa(t){return{show:t.label.enabled,formatter:({dimensionIndex:e,value:n})=>Ba(t.dimensions[e].formatter)(n)}}function $a(t,e){return e.map(({data_key:n})=>{const r=D(n);return t[r.columnKey]})}function Jm(t,e,n){const r=D(e);return t[r.queryID].map(i=>({value:$a(i,n),name:i[r.columnKey]}))}function Zm(t,e){const{series_name_key:n,dimensions:r}=e;return[{type:"radar",name:"main-radar",data:Jm(t,n,r),symbolSize:4,lineStyle:{width:1},emphasis:{lineStyle:{width:4}},areaStyle:e.background.enabled?{opacity:.4}:void 0,label:Oa(e)}]}function Hm(t,e){const{additional_series:n,dimensions:r}=e;return n.map(o=>{const l=D(o.name_key),c=D(o.color_key);return{type:"radar",colorBy:"data",data:t[l.queryID].map(h=>{const p=h[l.columnKey],x=h[c.columnKey];return{name:p,value:$a(h,r),itemStyle:{color:x}}}),symbolSize:4,lineStyle:{width:1},emphasis:{lineStyle:{width:4}},areaStyle:e.background.enabled?{opacity:.4}:void 0,label:Oa(e)}}).flat()}function ey(t,e){return[...Zm(t,e),...Hm(t,e)]}function ty(t){return({name:e,marker:n,value:r})=>{if(r.length===0)return"";const i=r.map((o,l)=>{const c=t.dimensions[l],u=Ba(c.formatter);return`
198
+ `,fm=()=>{const[t,e]=f.useState(!1);return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"subtle",compact:!0,onClick:()=>e(n=>!n),children:t?"Close":"Click to see params for Label Template"}),s.jsx(a.Collapse,{in:t,children:s.jsx(ct.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:xm})})]})};function gm({control:t,watch:e}){return e(["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:t,render:({field:n})=>s.jsx(Se,{...n})})]}),s.jsxs(a.Stack,{spacing:4,children:[s.jsx(b.Controller,{name:"markLine.label_template",control:t,render:({field:n})=>s.jsx(a.Textarea,{autosize:!0,minRows:2,maxRows:4,label:"Label Template",sx:{flex:1},...n})}),s.jsx(fm,{})]})]})}function mm({control:t,watch:e}){return e(["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:t,render:({field:n})=>s.jsx(B,{label:"Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"x_axis.name",control:t,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:t,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:t,render:({field:n})=>s.jsx(mn,{...n})})]}),s.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>s.jsx(Xe,{...n})})]})}function ym({control:t,watch:e}){return e(["data_key"]),s.jsx(a.Stack,{children:s.jsx(b.Controller,{name:"data_key",control:t,render:({field:n})=>s.jsx(B,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})})})}function bm({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=f.useMemo(()=>y.defaults({},e,er),[e]),{control:i,handleSubmit:o,watch:l,getValues:c,reset:u}=b.useForm({defaultValues:r});f.useEffect(()=>{u(r)},[r]),l(["x_axis","data_key","bar","line","dataZoom"]);const d=c(),p=f.useMemo(()=>!y.isEqual(d,e),[d,e]);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(mm,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Y Axis",children:s.jsx(ym,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Bar",children:s.jsx(dm,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Line",children:s.jsx(hm,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"80-20 Line",children:s.jsx(gm,{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(zs,{...h})})})]})]})}function jm(t){const{dataZoom:e=zt,...n}=t;return{...n,dataZoom:e}}function vm(t){const{markLine:e=za,...n}=t;return{...n,markLine:e}}function wm(t){const e=y.defaultsDeep({},t.x_axis.axisLabel,{rotate:0,formatter:{...Oe}});return{...t,x_axis:{...t.x_axis,axisLabel:e}}}function Cm(t){const{label_formatter:e=ye}=t.bar;return{...t,bar:{...t.bar,label_formatter:e}}}function Sm(t){const e={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return y.defaultsDeep(e,t)}function _m(t){const e={bar:{nameAlignment:"left"},line:{nameAlignment:"right"}};return y.defaultsDeep(e,t)}function km(t){console.log(t);const{x_axis:e,tooltip:n}=t.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:e,in_tooltip:n}}}};return y.defaultsDeep(r,t)}function Tm(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:i,data_key:o,...l}=t;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 Im extends re{constructor(){super(...arguments);z(this,"VERSION",9)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:jm(n.config)})),this.version(3,n=>({...n,version:3,config:vm(n.config)})),this.version(4,n=>({...n,version:4,config:wm(n.config)})),this.version(5,n=>({...n,version:5,config:Cm(n.config)})),this.version(6,n=>({...n,version:6,config:Sm(n.config)})),this.version(7,n=>({...n,version:7,config:_m(n.config)})),this.version(8,n=>({...n,version:8,config:km(n.config)})),this.version(9,(n,r)=>({...n,version:9,config:Tm(n.config,r)}))}}const Dm={displayName:"Pareto Chart",displayGroup:"ECharts-based charts",migrator:new Im,name:"paretoChart",viewRender:cm,configRender:bm,createConfig(){return{version:9,config:y.cloneDeep(er)}},triggers:[Aa]},tr={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 Mm(){Y.registerTheme("merico-light",{color:Object.values(tr.graphics.multiple),visualMap:{color:Object.values(tr.graphics.depth).reverse()},axes:[{type:"all",name:"通用坐标轴",axisLineColor:"#97999D",axisTickColor:"#97999D",axisLabelShow:!0,axisLabelColor:"#818388",splitLineShow:!0,splitLineColor:["#E0E6F1"]}]})}function Ea(){Mm()}function*Am(t){const e=tr.graphics[t];if(!e)throw new Error("Invalid palette key provided");const n=Object.values(e);let r=0;for(;;)yield n[r%n.length],r++}function zm(t,e,n){const{label_field:r,value_field:i,color_field:o}=t;if(!r||!i)return{};const l=D(r),c=D(i),u=D(o),d=e[l.queryID].map(h=>({name:h[l.columnKey],value:Number(h[c.columnKey]),color:u.columnKey?h[u.columnKey]:void 0})),p=Am("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}}
199
+ {percentage|{d}%}`,minMargin:5,edgeDistance:10,lineHeight:15,rich:{percentage:{color:"#999"}},margin:20},labelLine:{length:15,length2:0,maxSurfaceAngle:80,showAbove:!0},labelLayout:function(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:d,top:10,bottom:10,left:10,right:10}}function Em(t,e,n){return{tooltip:{show:!0,confine:!0},series:zm(t,e,n)}}const Pa={id:"builtin:echarts:click-pie-chart:series",displayName:"Click Pie Series",nameRender:Lm,configRender:Pm,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 Pm(t){return s.jsx(s.Fragment,{})}function Lm(t){return s.jsx(a.Text,{children:"Click chart's series"})}const nr={label_field:"",value_field:"",color_field:""};Y.use([te.PieChart,we.CanvasRenderer]);function Bm({conf:t,data:e,width:n,height:r,interactionManager:i}){const o=mt(e,t.label_field),l=$e(i.triggerManager,Pa.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]),u=f.useMemo(()=>Em(t,e,n),[t,e,n]),d=f.useMemo(()=>({click:c}),[c]);return!n||!r||!u.series.name?null:s.jsx(ve,{echarts:Y,option:u,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function Om({context:t,instance:e}){const n=Ve({vizManager:t.vizManager,instance:e}),{value:r}=O(t.instanceData,"config"),i=f.useMemo(()=>y.defaults({},r,nr),[r]),o=t.data,{width:l,height:c}=t.viewport;return!l||!c?null:s.jsx(Te,{width:l,height:c,children:s.jsx(Bm,{conf:i,width:We(l),height:Re(c),data:o,interactionManager:n})})}function $m({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},e,nr),[e]),i=f.useMemo(()=>y.clone(r),[r]),{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=b.useForm({defaultValues:i});f.useEffect(()=>{d(i)},[i]);const p=u(),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 Vm(t){const{color_field:e="",...n}=t;return{...n,color_field:e}}function Nm(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{label_field:i,value_field:o,color_field:l}=t;return{label_field:r(i),value_field:r(o),color_field:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class qm extends re{constructor(){super(...arguments);z(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:Vm(n.config)})),this.version(3,(n,r)=>({...n,version:3,config:Nm(n.config,r)}))}}const Fm={displayName:"Pie Chart",displayGroup:"ECharts-based charts",migrator:new qm,name:"pie",viewRender:Om,configRender:$m,createConfig(){return{version:3,config:y.cloneDeep(nr)}},triggers:[Pa]};function Gm(t){return s.jsx(s.Fragment,{})}function Wm(t){return s.jsx(a.Text,{children:"Click heat block"})}const La={id:"builtin:echarts:click-radar-chart:series",displayName:"Click radar chart series",nameRender:Wm,configRender:Gm,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 Ba(t){return t?e=>{try{return F(e).format(t)}catch(n){return console.error(n),e}}:e=>e}function Oa(t){return{show:t.label.enabled,formatter:({dimensionIndex:e,value:n})=>Ba(t.dimensions[e].formatter)(n)}}function $a(t,e){return e.map(({data_key:n})=>{const r=D(n);return t[r.columnKey]})}function Rm(t,e,n){const r=D(e);return t[r.queryID].map(i=>({value:$a(i,n),name:i[r.columnKey]}))}function Qm(t,e){const{series_name_key:n,dimensions:r}=e;return[{type:"radar",name:"main-radar",data:Rm(t,n,r),symbolSize:4,lineStyle:{width:1},emphasis:{lineStyle:{width:4}},areaStyle:e.background.enabled?{opacity:.4}:void 0,label:Oa(e)}]}function Um(t,e){const{additional_series:n,dimensions:r}=e;return n.map(o=>{const l=D(o.name_key),c=D(o.color_key);return{type:"radar",colorBy:"data",data:t[l.queryID].map(p=>{const h=p[l.columnKey],x=p[c.columnKey];return{name:h,value:$a(p,r),itemStyle:{color:x}}}),symbolSize:4,lineStyle:{width:1},emphasis:{lineStyle:{width:4}},areaStyle:e.background.enabled?{opacity:.4}:void 0,label:Oa(e)}}).flat()}function Ym(t,e){return[...Qm(t,e),...Um(t,e)]}function Km(t){return({name:e,marker:n,value:r})=>{if(r.length===0)return"";const i=r.map((o,l)=>{const c=t.dimensions[l],u=Ba(c.formatter);return`
200
200
  <tr>
201
201
  <td style="padding-left: 18px;">${c.name}</td>
202
202
  <td style="text-align: right; "><strong>${u(o)}</strong></td>
@@ -224,7 +224,7 @@ Check the top-level render call using <`+M+">.")}return I}}function oc(v,I){{if(
224
224
  ${i.join("")}
225
225
  </tbody>
226
226
  </table>
227
- `}}const ny={legend:{show:!0,bottom:0,left:0},tooltip:{trigger:"item"}},sy=["#66B4DB","#39BFA2","#E46464","#33A678","#EEBA00","#9D88CB","#939943","#E49792","#09A2B8","#AF5F6B","#6CA157","#09A2B8","#6398C7","#E692BA","#97B566","#8CACE2","#CA79AC","#6DBC80","#B08F4B","#826BAF"];function ry(t,e){const{series_name_key:n,dimensions:r,additional_series:i}=t;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:ty(t)},legend:{show:!0,bottom:0,left:"center",type:"scroll"},series:ey(e,t),color:sy};return y.merge({},ny,l)}K.use([te.RadarChart,P.GridComponent,P.LegendComponent,P.TooltipComponent,we.CanvasRenderer]);function iy({conf:t,data:e,width:n,height:r,interactionManager:i,variables:o}){const l=f.useMemo(()=>{const{queryID:p,columnKey:x}=D(t.series_name_key),m=y.keyBy(e[p],x),j=t.additional_series.reduce((C,T)=>{const A=D(T.name_key),L=y.keyBy(e[A.queryID],A.columnKey);return{...C,...L}},m);return{...m,...j}},[e,t.series_name_key,t.additional_series]),c=$e(i.triggerManager,La.id),u=f.useCallback(p=>{const x=y.get(l,p.name,{error:"rowData is not found"});c.forEach(m=>{i.runInteraction(m.id,{...p,rowData:x})})},[l,c,i]),d=f.useMemo(()=>({click:u}),[u]),h=f.useMemo(()=>ry(y.defaultsDeep({},t,Ln),e),[t,e]);return!n||!r?null:s.jsx(ve,{echarts:K,option:h,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function ay({context:t,instance:e}){const n=Ve({vizManager:t.vizManager,instance:e}),{value:r}=O(t.instanceData,"config"),{variables:i}=t,o=f.useMemo(()=>y.defaults({},r,Ln),[r]),l=t.data,{width:c,height:u}=t.viewport;return!c||!u||!o||y.isEmpty(o==null?void 0:o.dimensions)?null:s.jsx(Te,{width:c,height:u,children:s.jsx(iy,{variables:i,width:We(c),height:Re(u),data:l,conf:o,interactionManager:n})})}function oy({control:t,index:e,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.${e}.name_key`,control:t,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.${e}.color_key`,control:t,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(e),children:"Delete"})]})}function ly({control:t,watch:e}){const{fields:n,append:r,remove:i}=b.useFieldArray({control:t,name:"additional_series"}),o=e("additional_series"),l=n.map((x,m)=>({...x,...o[m]})),c=()=>{const x=new Date().getTime().toString();r({id:x,name_key:"",color_key:""})},u=y.get(l,"0.id",null),[d,h]=f.useState(u);f.useEffect(()=>{h(x=>x||u)},[u]);const p=x=>{i(x);const m=y.get(l,"0.id",null);h(m)};return s.jsxs(s.Fragment,{children:[s.jsxs(a.Alert,{icon:s.jsx(k.IconInfoCircle,{size:16}),title:"Additional Series",children:["By setting ",s.jsx(a.Mark,{children:"Series Name Key"}),", you may add series from more queries to the chart."]}),s.jsxs(a.Tabs,{value:d,onTabChange:h,styles:{tab:{paddingBottom:"0px"},panel:{padding:"0px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((x,m)=>s.jsx(a.Tabs.Tab,{value:x.id,children:m+1},x.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(k.IconPlus,{size:18,color:"#228be6"})})]}),l.map((x,m)=>s.jsx(a.Tabs.Panel,{value:x.id,children:s.jsx(oy,{control:t,index:m,remove:p})},x.id))]})]})}function cy({control:t,index:e,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.${e}.name`,control:t,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`dimensions.${e}.data_key`,control:t,render:({field:r})=>s.jsx(B,{label:"Data Key",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`dimensions.${e}.max`,control:t,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.${e}.formatter`,control:t,render:({field:r})=>s.jsx(Ae,{...r})})]}),s.jsx(a.Button,{mt:20,leftIcon:s.jsx(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),disabled:e===0,children:"Delete this Metric"})]})}function uy({control:t,watch:e}){const{fields:n,append:r,remove:i}=b.useFieldArray({control:t,name:"dimensions"}),o=e("dimensions"),l=n.map((x,m)=>({...x,...o[m]})),c=()=>{const x=new Date().getTime().toString();r({id:x,name:x,data_key:"",max:"100",formatter:ye})},u=y.get(l,"0.id",null),[d,h]=f.useState(u);f.useEffect(()=>{h(x=>x||u)},[u]);const p=x=>{i(x);const m=y.get(l,"0.id",null);h(m)};return s.jsx(s.Fragment,{children:s.jsxs(a.Tabs,{value:d,onTabChange:h,styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((x,m)=>s.jsx(a.Tabs.Tab,{value:x.id,children:x.name?x.name:m+1},x.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(k.IconPlus,{size:18,color:"#228be6"})})]}),l.map((x,m)=>s.jsx(a.Tabs.Panel,{value:x.id,children:s.jsx(cy,{control:t,index:m,remove:p})},x.id))]})})}function dy({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},e,Ln),[e]),{control:i,handleSubmit:o,watch:l,getValues:c,reset:u,formState:d}=b.useForm({defaultValues:r,mode:"all"});f.useEffect(()=>{u(r)},[r]),l(["series_name_key","background","label"]);const h=c(),p=f.useMemo(()=>!y.isEqual(h,r),[h,r]);return s.jsx("form",{onSubmit:o(n),children:s.jsxs(a.Stack,{spacing:"xs",children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Radar Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p||!d.isValid,children:s.jsx(_.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(uy,{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(ly,{control:i,watch:l})})]})]})})}function py(t){const{dimensions:e=[],...n}=t;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:e.map(r)}}function hy(t){const{dimensions:e=[],...n}=t;return{...n,dimensions:e.map(r=>({...r,id:r.id??r.name}))}}function xy(t){const e={background:{enabled:!0},label:{enabled:!0}};return y.defaultsDeep(e,t)}function fy(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{series_name_key:i,dimensions:o,...l}=t;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 gy(t){const e={additional_series:[]};return y.defaultsDeep(e,t)}function my(t){const e={...t,dimensions:t.dimensions.map(n=>({...n,max:String(n.max)}))};return delete e.additionalSeries,e}class yy extends re{constructor(){super(...arguments);z(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:py(r)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:hy(r)}}),this.version(4,n=>{const{config:r}=n;return{...n,version:4,config:xy(r)}}),this.version(5,(n,r)=>{const{config:i}=n;return{...n,version:5,config:fy(i,r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:gy(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:my(r)}})}}const by={displayName:"Radar Chart",displayGroup:"ECharts-based charts",migrator:new yy,name:"radar",viewRender:ay,configRender:dy,createConfig:()=>({version:7,config:Ln}),triggers:[La]};function jy(t,e){const{plot:n,transform:r}=t.regression;return e.map(i=>({...n,id:`reg-for-${i.name}`,name:i.name,data:En(r,i.data),color:i.color,showSymbol:!1,smooth:!0,tooltip:{show:!1},custom:{type:"regression-line",targetSeries:i.name}}))}function Va(t,e){const n=D(t.x_axis.data_key),r=D(t.regression.y_axis_data_key);return y.uniqBy(e.map(i=>[i[n.columnKey],i[r.columnKey]]),0)}function vy(t,e){const{plot:n,transform:r}=t.regression,i=Va(t,e);return[{type:"scatter",name:t.y_axis.name,data:i,symbolSize:4,color:"red",markLine:{...n,data:[En(r,i)],color:"blue",smooth:!0,silent:!0,symbol:["none","none"]}}]}function wy(t,e){const{plot:n,transform:r,group_by_key:i}=t.regression,o=D(i),l=y.groupBy(e,o.columnKey);return Object.entries(l).map(([c,u])=>{const d=Va(t,u);return{type:"scatter",name:c,data:d,symbolSize:4,markLine:{...n,data:[En(r,d)],smooth:!0,silent:!0,symbol:["none","none"]}}})}function Cy(t,e){if(e.length===0)return[];const{group_by_key:n}=t.regression;return n?wy(t,e):vy(t,e)}function Sy(t){return Array.isArray(t)||(t=[t]),t.map(e=>({marker:e.marker,label:e.seriesName,x:e.value[0],y:e.value[1]}))}function _y(t){return{confine:!0,trigger:"axis",formatter:e=>{const n=Sy(e);return n.length===0?"":`
227
+ `}}const Xm={legend:{show:!0,bottom:0,left:0},tooltip:{trigger:"item"}},Jm=["#66B4DB","#39BFA2","#E46464","#33A678","#EEBA00","#9D88CB","#939943","#E49792","#09A2B8","#AF5F6B","#6CA157","#09A2B8","#6398C7","#E692BA","#97B566","#8CACE2","#CA79AC","#6DBC80","#B08F4B","#826BAF"];function Zm(t,e){const{series_name_key:n,dimensions:r,additional_series:i}=t;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:Km(t)},legend:{show:!0,bottom:0,left:"center",type:"scroll"},series:Ym(e,t),color:Jm};return y.merge({},Xm,l)}Y.use([te.RadarChart,P.GridComponent,P.LegendComponent,P.TooltipComponent,we.CanvasRenderer]);function Hm({conf:t,data:e,width:n,height:r,interactionManager:i,variables:o}){const l=f.useMemo(()=>{const{queryID:h,columnKey:x}=D(t.series_name_key),m=y.keyBy(e[h],x),j=t.additional_series.reduce((C,T)=>{const A=D(T.name_key),L=y.keyBy(e[A.queryID],A.columnKey);return{...C,...L}},m);return{...m,...j}},[e,t.series_name_key,t.additional_series]),c=$e(i.triggerManager,La.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(()=>Zm(y.defaultsDeep({},t,En),e),[t,e]);return!n||!r?null:s.jsx(ve,{echarts:Y,option:p,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function ey({context:t,instance:e}){const n=Ve({vizManager:t.vizManager,instance:e}),{value:r}=O(t.instanceData,"config"),{variables:i}=t,o=f.useMemo(()=>y.defaults({},r,En),[r]),l=t.data,{width:c,height:u}=t.viewport;return!c||!u||!o||y.isEmpty(o==null?void 0:o.dimensions)?null:s.jsx(Te,{width:c,height:u,children:s.jsx(Hm,{variables:i,width:We(c),height:Re(u),data:l,conf:o,interactionManager:n})})}function ty({control:t,index:e,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.${e}.name_key`,control:t,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.${e}.color_key`,control:t,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(e),children:"Delete"})]})}function ny({control:t,watch:e}){const{fields:n,append:r,remove:i}=b.useFieldArray({control:t,name:"additional_series"}),o=e("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(ty,{control:t,index:m,remove:h})},x.id))]})]})}function sy({control:t,index:e,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.${e}.name`,control:t,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`dimensions.${e}.data_key`,control:t,render:({field:r})=>s.jsx(B,{label:"Data Key",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`dimensions.${e}.max`,control:t,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.${e}.formatter`,control:t,render:({field:r})=>s.jsx(Be,{...r})})]}),s.jsx(a.Button,{mt:20,leftIcon:s.jsx(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),disabled:e===0,children:"Delete this Metric"})]})}function ry({control:t,watch:e}){const{fields:n,append:r,remove:i}=b.useFieldArray({control:t,name:"dimensions"}),o=e("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(sy,{control:t,index:m,remove:h})},x.id))]})})}function iy({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},e,En),[e]),{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(ry,{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(ny,{control:i,watch:l})})]})]})})}function ay(t){const{dimensions:e=[],...n}=t;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:e.map(r)}}function oy(t){const{dimensions:e=[],...n}=t;return{...n,dimensions:e.map(r=>({...r,id:r.id??r.name}))}}function ly(t){const e={background:{enabled:!0},label:{enabled:!0}};return y.defaultsDeep(e,t)}function cy(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{series_name_key:i,dimensions:o,...l}=t;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 uy(t){const e={additional_series:[]};return y.defaultsDeep(e,t)}function dy(t){const e={...t,dimensions:t.dimensions.map(n=>({...n,max:String(n.max)}))};return delete e.additionalSeries,e}class py extends re{constructor(){super(...arguments);z(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:ay(r)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:oy(r)}}),this.version(4,n=>{const{config:r}=n;return{...n,version:4,config:ly(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:uy(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:dy(r)}})}}const hy={displayName:"Radar Chart",displayGroup:"ECharts-based charts",migrator:new py,name:"radar",viewRender:ey,configRender:iy,createConfig:()=>({version:7,config:En}),triggers:[La]};function xy(t,e){const{plot:n,transform:r}=t.regression;return e.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 Va(t,e){const n=D(t.x_axis.data_key),r=D(t.regression.y_axis_data_key);return y.uniqBy(e.map(i=>[i[n.columnKey],i[r.columnKey]]),0)}function fy(t,e){const{plot:n,transform:r}=t.regression,i=Va(t,e);return[{type:"scatter",name:t.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 gy(t,e){const{plot:n,transform:r,group_by_key:i}=t.regression,o=D(i),l=y.groupBy(e,o.columnKey);return Object.entries(l).map(([c,u])=>{const d=Va(t,u);return{type:"scatter",name:c,data:d,symbolSize:4,markLine:{...n,data:[yn(r,d)],smooth:!0,silent:!0,symbol:["none","none"]}}})}function my(t,e){if(e.length===0)return[];const{group_by_key:n}=t.regression;return n?gy(t,e):fy(t,e)}function yy(t){return Array.isArray(t)||(t=[t]),t.map(e=>({marker:e.marker,label:e.seriesName,x:e.value[0],y:e.value[1]}))}function by(t){return{confine:!0,trigger:"axis",formatter:e=>{const n=yy(e);return n.length===0?"":`
228
228
  <table style="width: auto">
229
229
  <thead>
230
230
  <tr>
@@ -243,20 +243,20 @@ Check the top-level render call using <`+M+">.")}return I}}function oc(v,I){{if(
243
243
  </tr>
244
244
  </tbody>
245
245
  </table>
246
- `}}}function Na({enabled:t,func_content:e}){return(n,r)=>{if(!t)return n;try{return new Function(`return ${e}`)()(n,r)}catch(i){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${i.message}`),n}}}function ky(t){const{overflow:e,format:n,formatter:r,...i}=t.x_axis.axisLabel,o=Qe(e.on_axis);return Le.getXAxis({type:"value",name:t.x_axis.name??"",nameLocation:"middle",nameGap:25,axisLabel:{...i,...o,formatter:(l,c)=>{let u=l;try{u=F(l).format(n)}catch{}return Na(r)(u,c)}}})}const Ty={tooltip:{trigger:"axis"},grid:{top:50,left:5,right:10,bottom:20,containLabel:!0},dataZoom:[{type:"inside",xAxisIndex:[0]},{type:"inside",yAxisIndex:[0]}]};function Iy(t,e){const n=Cy(t,e),r=jy(t,n),i={xAxis:ky(t),yAxis:Le.getYAxis({name:t.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"left"},nameGap:5}),series:[...n,...r],tooltip:_y(t),legend:{show:!0,type:"scroll",orient:"horizontal",align:"left",right:0,top:0,left:"auto",itemGap:20,padding:[4,8,0,140],data:n.map(o=>o.name)}};return y.defaultsDeep({},i,Ty)}function Bn(t,e,n){return 1-(1-t)*(e-1)/(e-n-1)}function Dy(t,e,n,r){const{x_axis:i,y_axis:o}=r,l=ct.regressionLinear()(n),{a:c,b:u,rSquared:d}=l;return{name:t,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(u).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:d,adjustedRSquared:Bn(d,e.length,1)}}function My(t,e,n,r){const{x_axis:i,y_axis:o}=r,{a:l,b:c,rSquared:u}=ct.regressionExp()(n);return{name:t,expression:s.jsxs(a.Group,{position:"center",noWrap:!0,spacing:10,children:[s.jsx(a.Text,{children:o.name}),s.jsx(a.Text,{children:"="}),s.jsx(a.Text,{weight:"bold",color:"gray",children:l}),s.jsx(a.Text,{children:"×"}),s.jsxs(a.Group,{position:"left",noWrap:!0,spacing:2,children:[s.jsx(a.Text,{children:"Math.exp("}),s.jsx(a.Text,{weight:"bold",color:"gray",children:c}),s.jsx(a.Text,{children:"×"}),s.jsx(a.Text,{children:i.name}),s.jsx(a.Text,{children:")"})]})]}),rSquared:u,adjustedRSquared:Bn(u,e.length,1)}}function Ay(t,e,n,r){const{x_axis:i,y_axis:o}=r,{a:l,b:c,rSquared:u}=ct.regressionLog()(n);return{name:t,expression:s.jsxs(a.Group,{position:"center",noWrap:!0,spacing:10,children:[s.jsx(a.Text,{children:o.name}),s.jsx(a.Text,{children:"="}),s.jsx(a.Text,{weight:"bold",color:"gray",children:l}),s.jsx(a.Text,{children:"×"}),s.jsxs(a.Group,{position:"left",noWrap:!0,spacing:2,children:[s.jsx(a.Text,{children:"Math.log("}),s.jsx(a.Text,{children:i.name}),s.jsx(a.Text,{children:")"}),s.jsx(a.Text,{children:"+"}),s.jsx(a.Text,{weight:"bold",color:"gray",children:c})]})]}),rSquared:u,adjustedRSquared:Bn(u,e.length,1)}}function zy(t,e,n,r){const{x_axis:i,y_axis:o,regression:l}=r,c=ct.regressionPoly().order(l.transform.config.order)(n),{rSquared:u}=c;return console.log(c),{name:t,expression:"",rSquared:u,adjustedRSquared:Bn(u,e.length,1)}}function qa(t,e,n){const{regression:r,x_axis:i}=n,o=D(i.data_key),l=D(r.y_axis_data_key),c=e.map(u=>[u[o.columnKey],u[l.columnKey]]);return r.transform.config.method==="linear"?Dy(t,e,c,n):r.transform.config.method==="exponential"?My(t,e,c,n):r.transform.config.method==="logarithmic"?Ay(t,e,c,n):r.transform.config.method==="polynomial"?zy(t,e,c,n):{name:t,expression:"",rSquared:0,adjustedRSquared:0}}function Ey(t,e){if(!e)return[{name:"",expression:"",rSquared:0,adjustedRSquared:0}];if(!e.regression.group_by_key)return[qa("",t,e)];const n=D(e.regression.group_by_key),r=y.groupBy(t,n.columnKey);return Object.entries(r).map(([i,o])=>qa(i,o,e))}const Py={marginTop:"10px","tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function Fa({desc:t}){const{expression:e,rSquared:n,adjustedRSquared:r}=t;return e?s.jsx(a.Table,{fontSize:14,sx:Py,children:s.jsxs("tbody",{children:[s.jsx("tr",{children:s.jsx("td",{colSpan:2,children:s.jsx(a.Text,{align:"center",children:e})})}),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 Ly({conf:t,queryData:e}){var r;const n=f.useMemo(()=>Ey(e,t),[t,e]);return t.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(Fa,{desc:i})},i.name))]})):s.jsx(Fa,{desc:n[0]})}function By({conf:t,queryData:e}){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(Ce,{children:s.jsx(Ly,{conf:t,queryData:e})})})]})}function Oy(t){return s.jsx(a.Group,{position:"apart",sx:{position:"absolute",top:0,left:ke.left,right:ke.right,height:"22px",zIndex:1},children:s.jsx(By,{...t})})}const On={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
247
- `)},sr={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,format:ye,overflow:ze,formatter:{...On}}},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"}};K.use([P.DataZoomComponent,te.ScatterChart,P.GridComponent,P.LegendComponent,P.TooltipComponent,we.CanvasRenderer]);function $y({context:t}){const{value:e}=O(t.instanceData,"config"),{width:n,height:r}=t.viewport,i=f.useMemo(()=>{var m;const u=t.data,d=e==null?void 0:e.x_axis.data_key,h=(m=e==null?void 0:e.regression)==null?void 0:m.y_axis_data_key;if(!d||!h)return[];const p=D(d),x=D(h);return u[p.queryID].map(j=>typeof j[x.columnKey]=="number"?j:{...j,[x.columnKey]:Number(j[x.columnKey])})},[t.data,e==null?void 0:e.regression.y_axis_data_key]),o=f.useMemo(()=>Iy(y.defaultsDeep({},e,sr),i),[e,i]),l=f.useRef(null),c=u=>{l.current=u};return!n||!r||!e?null:s.jsxs(Te,{width:n,height:r,children:[s.jsx(Oy,{conf:e,queryData:i}),s.jsx(ve,{echarts:K,onChartReady:c,option:o,style:Wt(n,r),notMerge:!0,theme:"merico-light"})]})}const Vy=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}];function Ny({control:t,watch:e}){e("regression");const n=e("regression.transform.config.method"),r=e("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:t,render:({field:i})=>s.jsx(a.TextInput,{label:"回归线名称",sx:{flex:1},...i})})}),s.jsx(b.Controller,{name:"regression.group_by_key",control:t,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:t,render:({field:i})=>s.jsx(a.Select,{label:"回归方法",data:Vy,sx:{flex:1},...i})}),n==="polynomial"&&s.jsx(b.Controller,{name:"regression.transform.config.order",control:t,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:t,render:({field:i})=>s.jsx(Se,{...i})})]})]})}const qy=({disabled:t,value:e,onChange:n})=>{const r=i=>{i&&n(i)};return s.jsxs(a.Box,{sx:{position:"relative"},children:[t&&s.jsx(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),s.jsx(me,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},Ga=f.forwardRef(({value:t,onChange:e,triggerButtonText:n="Customize Label"},r)=>{const[i,{setTrue:o,setFalse:l}]=$.useBoolean(),[c,u]=f.useState(t);f.useEffect(()=>{u(t)},[t]);const d=j=>{u({...c,enabled:j})},h=()=>{l();const{enabled:j,func_content:C}=c,T={enabled:j,func_content:C};u(T),e(T)},p=()=>{l(),u(t)},x=j=>{u(C=>({...C,func_content:j}))},m=()=>{x(On.func_content)};return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"filled",mt:24,onClick:o,sx:{flexGrow:0},children:n}),s.jsx(a.Modal,{size:800,title:"Customize label content",opened:i,onClose:l,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:i&&s.jsxs(a.Stack,{children:[s.jsx(a.Checkbox,{mt:10,label:"Enabled",checked:c.enabled,onChange:j=>d(j.currentTarget.checked)}),s.jsx(qy,{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:p,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:h,children:"OK"})]})]})]})})]})});function Fy({control:t,watch:e}){return e(["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:t,render:({field:n})=>s.jsx(a.TextInput,{label:"X轴名称",sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"x_axis.data_key",control:t,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:t,render:({field:n})=>s.jsx(Ae,{...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:t,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:t,render:({field:n})=>s.jsx(Ga,{triggerButtonText:"自定义标签文案内容",...n})})]}),s.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>s.jsx(Xe,{...n})})]})}function Gy({control:t,watch:e}){return e(["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:t,render:({field:n})=>s.jsx(a.TextInput,{label:"Y轴名称",sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"regression.y_axis_data_key",control:t,render:({field:n})=>s.jsx(B,{label:"Y轴数据字段",required:!0,sx:{flex:1},...n})})]})})}function Wy({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=f.useMemo(()=>y.defaults({},e,sr),[e]),{control:i,handleSubmit:o,watch:l,getValues:c,reset:u}=b.useForm({defaultValues:r});f.useEffect(()=>{u(r)},[r]),l(["x_axis","y_axis","regression"]);const d=c(),h=f.useMemo(()=>!y.isEqual(d,e),[d,e]);return s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:o(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Chart Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:s.jsx(_.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(Fy,{watch:l,control:i})}),s.jsx(a.Tabs.Panel,{value:"Y轴",children:s.jsx(Gy,{watch:l,control:i})}),s.jsx(a.Tabs.Panel,{value:"回归",children:s.jsx(Ny,{control:i,watch:l})})]})]})})}function Ry(t){const e={x_axis:{axisLabel:{rotate:0,format:ye,overflow:ze,formatter:On}},regression:{group_by_key:""}};return y.defaultsDeep(e,t)}function Qy(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:i,regression:o,...l}=t;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 Yy extends re{constructor(){super(...arguments);z(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:Ry(n.config)})),this.version(3,(n,r)=>{const{config:i}=n;return{...n,version:3,config:Qy(i,r)}})}}const Ky={displayName:"Regression Chart",displayGroup:"Merico suite",migrator:new Yy,name:"regressionChart",viewRender:$y,configRender:Wy,createConfig(){return{version:3,config:y.cloneDeep(sr)}}},$n={content:""};function Uy(t,e){const n={};return t.forEach(r=>{const{name:i,data_field:o,aggregation:l}=r,c=In(e,o,l);n[i]=qe(r,c)}),n}function Xy(t){const e=document.createElement("span");return e.innerHTML=t,e.innerText}function Jy(t,e,n){try{return new Function("payload",`
246
+ `}}}function Na({enabled:t,func_content:e}){return(n,r)=>{if(!t)return n;try{return new Function(`return ${e}`)()(n,r)}catch(i){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${i.message}`),n}}}function jy(t){const{overflow:e,format:n,formatter:r,...i}=t.x_axis.axisLabel,o=Qe(e.on_axis);return ze.getXAxis({type:"value",name:t.x_axis.name??"",nameLocation:"middle",nameGap:25,axisLabel:{...i,...o,formatter:(l,c)=>{let u=l;try{u=F(l).format(n)}catch{}return Na(r)(u,c)}}})}const vy={tooltip:{trigger:"axis"},grid:{top:50,left:5,right:10,bottom:20,containLabel:!0},dataZoom:[{type:"inside",xAxisIndex:[0]},{type:"inside",yAxisIndex:[0]}]};function wy(t,e){const n=my(t,e),r=xy(t,n),i={xAxis:jy(t),yAxis:ze.getYAxis({name:t.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"left"},nameGap:5}),series:[...n,...r],tooltip:by(t),legend:{show:!0,type:"scroll",orient:"horizontal",align:"left",right:0,top:0,left:"auto",itemGap:20,padding:[4,8,0,140],data:n.map(o=>o.name)}};return y.defaultsDeep({},i,vy)}function Pn(t,e,n){return 1-(1-t)*(e-1)/(e-n-1)}function Cy(t,e,n,r){const{x_axis:i,y_axis:o}=r,l=ut.regressionLinear()(n),{a:c,b:u,rSquared:d}=l;return{name:t,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(u).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:d,adjustedRSquared:Pn(d,e.length,1)}}function Sy(t,e,n,r){const{x_axis:i,y_axis:o}=r,{a:l,b:c,rSquared:u}=ut.regressionExp()(n);return{name:t,expression:s.jsxs(a.Group,{position:"center",noWrap:!0,spacing:10,children:[s.jsx(a.Text,{children:o.name}),s.jsx(a.Text,{children:"="}),s.jsx(a.Text,{weight:"bold",color:"gray",children:l}),s.jsx(a.Text,{children:"×"}),s.jsxs(a.Group,{position:"left",noWrap:!0,spacing:2,children:[s.jsx(a.Text,{children:"Math.exp("}),s.jsx(a.Text,{weight:"bold",color:"gray",children:c}),s.jsx(a.Text,{children:"×"}),s.jsx(a.Text,{children:i.name}),s.jsx(a.Text,{children:")"})]})]}),rSquared:u,adjustedRSquared:Pn(u,e.length,1)}}function _y(t,e,n,r){const{x_axis:i,y_axis:o}=r,{a:l,b:c,rSquared:u}=ut.regressionLog()(n);return{name:t,expression:s.jsxs(a.Group,{position:"center",noWrap:!0,spacing:10,children:[s.jsx(a.Text,{children:o.name}),s.jsx(a.Text,{children:"="}),s.jsx(a.Text,{weight:"bold",color:"gray",children:l}),s.jsx(a.Text,{children:"×"}),s.jsxs(a.Group,{position:"left",noWrap:!0,spacing:2,children:[s.jsx(a.Text,{children:"Math.log("}),s.jsx(a.Text,{children:i.name}),s.jsx(a.Text,{children:")"}),s.jsx(a.Text,{children:"+"}),s.jsx(a.Text,{weight:"bold",color:"gray",children:c})]})]}),rSquared:u,adjustedRSquared:Pn(u,e.length,1)}}function ky(t,e,n,r){const{x_axis:i,y_axis:o,regression:l}=r,c=ut.regressionPoly().order(l.transform.config.order)(n),{rSquared:u}=c;return console.log(c),{name:t,expression:"",rSquared:u,adjustedRSquared:Pn(u,e.length,1)}}function qa(t,e,n){const{regression:r,x_axis:i}=n,o=D(i.data_key),l=D(r.y_axis_data_key),c=e.map(u=>[u[o.columnKey],u[l.columnKey]]);return r.transform.config.method==="linear"?Cy(t,e,c,n):r.transform.config.method==="exponential"?Sy(t,e,c,n):r.transform.config.method==="logarithmic"?_y(t,e,c,n):r.transform.config.method==="polynomial"?ky(t,e,c,n):{name:t,expression:"",rSquared:0,adjustedRSquared:0}}function Ty(t,e){if(!e)return[{name:"",expression:"",rSquared:0,adjustedRSquared:0}];if(!e.regression.group_by_key)return[qa("",t,e)];const n=D(e.regression.group_by_key),r=y.groupBy(t,n.columnKey);return Object.entries(r).map(([i,o])=>qa(i,o,e))}const Iy={marginTop:"10px","tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function Fa({desc:t}){const{expression:e,rSquared:n,adjustedRSquared:r}=t;return e?s.jsx(a.Table,{fontSize:14,sx:Iy,children:s.jsxs("tbody",{children:[s.jsx("tr",{children:s.jsx("td",{colSpan:2,children:s.jsx(a.Text,{align:"center",children:e})})}),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 Dy({conf:t,queryData:e}){var r;const n=f.useMemo(()=>Ty(e,t),[t,e]);return t.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(Fa,{desc:i})},i.name))]})):s.jsx(Fa,{desc:n[0]})}function My({conf:t,queryData:e}){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(Ce,{children:s.jsx(Dy,{conf:t,queryData:e})})})]})}function Ay(t){return s.jsx(a.Group,{position:"apart",sx:{position:"absolute",top:0,left:ke.left,right:ke.right,height:"22px",zIndex:1},children:s.jsx(My,{...t})})}const Ln={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
247
+ `)},sr={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,format:ye,overflow:Ae,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([P.DataZoomComponent,te.ScatterChart,P.GridComponent,P.LegendComponent,P.TooltipComponent,we.CanvasRenderer]);function zy({context:t}){const{value:e}=O(t.instanceData,"config"),{width:n,height:r}=t.viewport,i=f.useMemo(()=>{var m;const u=t.data,d=e==null?void 0:e.x_axis.data_key,p=(m=e==null?void 0:e.regression)==null?void 0:m.y_axis_data_key;if(!d||!p)return[];const h=D(d),x=D(p);return u[h.queryID].map(j=>typeof j[x.columnKey]=="number"?j:{...j,[x.columnKey]:Number(j[x.columnKey])})},[t.data,e==null?void 0:e.regression.y_axis_data_key]),o=f.useMemo(()=>wy(y.defaultsDeep({},e,sr),i),[e,i]),l=f.useRef(null),c=u=>{l.current=u};return!n||!r||!e?null:s.jsxs(Te,{width:n,height:r,children:[s.jsx(Ay,{conf:e,queryData:i}),s.jsx(ve,{echarts:Y,onChartReady:c,option:o,style:Wt(n,r),notMerge:!0,theme:"merico-light"})]})}const Ey=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}];function Py({control:t,watch:e}){e("regression");const n=e("regression.transform.config.method"),r=e("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:t,render:({field:i})=>s.jsx(a.TextInput,{label:"回归线名称",sx:{flex:1},...i})})}),s.jsx(b.Controller,{name:"regression.group_by_key",control:t,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:t,render:({field:i})=>s.jsx(a.Select,{label:"回归方法",data:Ey,sx:{flex:1},...i})}),n==="polynomial"&&s.jsx(b.Controller,{name:"regression.transform.config.order",control:t,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:t,render:({field:i})=>s.jsx(Se,{...i})})]})]})}const Ly=({disabled:t,value:e,onChange:n})=>{const r=i=>{i&&n(i)};return s.jsxs(a.Box,{sx:{position:"relative"},children:[t&&s.jsx(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),s.jsx(ge,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},Ga=f.forwardRef(({value:t,onChange:e,triggerButtonText:n="Customize Label"},r)=>{const[i,{setTrue:o,setFalse:l}]=$.useBoolean(),[c,u]=f.useState(t);f.useEffect(()=>{u(t)},[t]);const d=j=>{u({...c,enabled:j})},p=()=>{l();const{enabled:j,func_content:C}=c,T={enabled:j,func_content:C};u(T),e(T)},h=()=>{l(),u(t)},x=j=>{u(C=>({...C,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=>d(j.currentTarget.checked)}),s.jsx(Ly,{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 By({control:t,watch:e}){return e(["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:t,render:({field:n})=>s.jsx(a.TextInput,{label:"X轴名称",sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"x_axis.data_key",control:t,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:t,render:({field:n})=>s.jsx(Be,{...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:t,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:t,render:({field:n})=>s.jsx(Ga,{triggerButtonText:"自定义标签文案内容",...n})})]}),s.jsx(b.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>s.jsx(Xe,{...n})})]})}function Oy({control:t,watch:e}){return e(["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:t,render:({field:n})=>s.jsx(a.TextInput,{label:"Y轴名称",sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"regression.y_axis_data_key",control:t,render:({field:n})=>s.jsx(B,{label:"Y轴数据字段",required:!0,sx:{flex:1},...n})})]})})}function $y({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=f.useMemo(()=>y.defaults({},e,sr),[e]),{control:i,handleSubmit:o,watch:l,getValues:c,reset:u}=b.useForm({defaultValues:r});f.useEffect(()=>{u(r)},[r]),l(["x_axis","y_axis","regression"]);const d=c(),p=f.useMemo(()=>!y.isEqual(d,e),[d,e]);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(By,{watch:l,control:i})}),s.jsx(a.Tabs.Panel,{value:"Y轴",children:s.jsx(Oy,{watch:l,control:i})}),s.jsx(a.Tabs.Panel,{value:"回归",children:s.jsx(Py,{control:i,watch:l})})]})]})})}function Vy(t){const e={x_axis:{axisLabel:{rotate:0,format:ye,overflow:Ae,formatter:Ln}},regression:{group_by_key:""}};return y.defaultsDeep(e,t)}function Ny(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:i,regression:o,...l}=t;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 qy extends re{constructor(){super(...arguments);z(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:Vy(n.config)})),this.version(3,(n,r)=>{const{config:i}=n;return{...n,version:3,config:Ny(i,r)}})}}const Fy={displayName:"Regression Chart",displayGroup:"Merico suite",migrator:new qy,name:"regressionChart",viewRender:zy,configRender:$y,createConfig(){return{version:3,config:y.cloneDeep(sr)}}},Bn={content:""};function Gy(t,e){const n={};return t.forEach(r=>{const{name:i,data_field:o,aggregation:l}=r,c=fn(e,o,l);n[i]=Ne(r,c)}),n}function Wy(t){const e=document.createElement("span");return e.innerHTML=t,e.innerText}function Ry(t,e,n){try{return new Function("payload",`
248
248
  const filters = payload.filters;
249
249
  const context = payload.context;
250
250
  ${Object.entries(e).map(([r,i])=>`const ${r} = '${i}';`).join(`
251
251
  `)}
252
252
  return ${t};
253
- `)(n)}catch(r){return console.error(r),console.log(t),t}}function Zy(t,e,n,r){const i=Uy(e,r),o=/^(.+)\}\}(.*)$/;return t.split("{{").map(l=>{const c=o.exec(l);if(!c)return l;const u=i[c[1]];if(u){const h=c[2]??"";return`${u}${h}`}const d=Xy(c[1]);return`${Jy(d,i,n)}${c[2]}`}).join("")}const Hy=S.observer(({context:t})=>{const e=oe(),{value:n}=O(t.instanceData,"config"),{variables:r,data:i}=t,o=f.useMemo(()=>{const l=y.defaults({},n,$n);return l.content?Zy(l.content,r,e.payloadForViz,i):""},[n,r,e.payloadForViz]);return o?s.jsx(Tn,{value:o,styles:{root:{border:"none",height:"100%"},content:{padding:0}}}):null});function eb(){const{editor:t}=q.useRichTextEditorContext();return s.jsx(q.RichTextEditor.Control,{onClick:()=>t==null?void 0:t.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 rr=f.forwardRef(({value:t,onChange:e,styles:n={},label:r,onSubmit:i},o)=>{const[l,c]=f.useState(t),u=li.useEditor({extensions:[ci,oi,q.Link,ei,Hr,Jr,si.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),ai,ii,ri,ti.configure({types:["heading","paragraph"]}),Zr.configure({placeholder:"This is placeholder"}),ni,Xr.Color,fa],content:l,onUpdate:({editor:x})=>{c(x.getHTML())}});f.useEffect(()=>{c(t),u==null||u.commands.setContent(t)},[t]);const d=()=>{e(l),i==null||i()},h=t!==l,p=f.useMemo(()=>y.defaultsDeep({},{content:ks},n),[n]);return u?s.jsxs(a.Stack,{spacing:4,sx:{flexGrow:1,position:"relative"},children:[s.jsxs(a.Group,{align:"center",children:[s.jsx(a.Text,{size:14,fw:500,children:r}),s.jsx(a.ActionIcon,{color:"blue",disabled:!h,onClick:d,children:s.jsx(k.IconDeviceFloppy,{size:18})})]}),s.jsxs(q.RichTextEditor,{editor:u,styles:p,children:[s.jsxs(q.RichTextEditor.Toolbar,{sticky:!0,stickyOffset:0,children:[s.jsx(q.RichTextEditor.ControlsGroup,{children:s.jsx(q.RichTextEditor.ColorPicker,{colors:["#25262b","#868e96","#fa5252","#e64980","#be4bdb","#7950f2","#4c6ef5","#228be6","#15aabf","#12b886","#40c057","#82c91e","#fab005","#fd7e14"],popoverProps:{zIndex:320}})}),s.jsxs(q.RichTextEditor.ControlsGroup,{children:[s.jsx(q.RichTextEditor.Bold,{}),s.jsx(q.RichTextEditor.Italic,{}),s.jsx(q.RichTextEditor.Underline,{}),s.jsx(q.RichTextEditor.ClearFormatting,{}),s.jsx(q.RichTextEditor.Highlight,{}),s.jsx(q.RichTextEditor.Code,{})]}),s.jsxs(q.RichTextEditor.ControlsGroup,{children:[s.jsx(q.RichTextEditor.H1,{}),s.jsx(q.RichTextEditor.H2,{}),s.jsx(q.RichTextEditor.H3,{}),s.jsx(q.RichTextEditor.H4,{})]}),s.jsxs(q.RichTextEditor.ControlsGroup,{children:[s.jsx(q.RichTextEditor.Blockquote,{}),s.jsx(q.RichTextEditor.Hr,{}),s.jsx(q.RichTextEditor.BulletList,{}),s.jsx(q.RichTextEditor.OrderedList,{}),s.jsx(q.RichTextEditor.Subscript,{}),s.jsx(q.RichTextEditor.Superscript,{})]}),s.jsxs(q.RichTextEditor.ControlsGroup,{children:[s.jsx(q.RichTextEditor.Link,{}),s.jsx(q.RichTextEditor.Unlink,{})]}),s.jsxs(q.RichTextEditor.ControlsGroup,{children:[s.jsx(q.RichTextEditor.AlignLeft,{}),s.jsx(q.RichTextEditor.AlignCenter,{}),s.jsx(q.RichTextEditor.AlignJustify,{}),s.jsx(q.RichTextEditor.AlignRight,{})]}),s.jsx(q.RichTextEditor.ControlsGroup,{children:s.jsx(eb,{})}),s.jsx(uh,{editor:u})]}),s.jsx(q.RichTextEditor.Content,{})]})]}):null});function tb({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=f.useMemo(()=>y.defaults({},e,$n),[e]),{control:i,handleSubmit:o,watch:l,reset:c}=b.useForm({defaultValues:r});l("content"),f.useEffect(()=>{c(r)},[r]);const u=f.useRef(null),d=()=>{var h;return(h=u.current)==null?void 0:h.click()};return s.jsx("form",{onSubmit:o(n),style:{flexGrow:1,display:"flex",flexDirection:"column"},children:s.jsxs(a.Stack,{spacing:"xs",sx:{flexGrow:1},children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",display:"none"},children:[s.jsx(a.Text,{children:"Content"}),s.jsx(a.ActionIcon,{ref:u,type:"submit",mr:5,variant:"filled",color:"blue",children:s.jsx(_.DeviceFloppy,{size:20})})]}),s.jsx(b.Controller,{name:"content",control:i,render:({field:h})=>s.jsx(rr,{...h,styles:{root:{flexGrow:1}},label:"Content",onSubmit:d})})]})})}class nb extends re{constructor(){super(...arguments);z(this,"VERSION",1)}fixMalformedConfig(n){return y.defaults({},n,$n)}configVersions(){this.version(1,n=>({version:1,config:this.fixMalformedConfig(n)}))}}const sb={displayName:"Rich Text",displayGroup:"Others",migrator:new nb,name:"richText",viewRender:Hy,configRender:tb,createConfig(){return{version:1,config:y.cloneDeep($n)}}},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(`
254
- `)}},Wa={id:"builtin:echarts:click-scatter-chart:series",displayName:"Click Scatter",nameRender:ib,configRender:rb,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 rb(t){return s.jsx(s.Fragment,{})}function ib(t){return s.jsx(a.Text,{children:"Click scatter"})}const Ra={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
255
- `)},Qa={label:ze.on_axis,tooltip:ze.in_tooltip},ir={scatter:{y_data_key:"",name_data_key:"",symbolSize:{type:"static",size:10},color:tn.static,label_position:"right",label_overflow:Qa},stats:{templates:{top:"",bottom:""}},x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...Ra}}},y_axes:[{name:"Y Axis",position:"left",nameAlignment:"center",label_formatter:ye,min:"",max:"",show:!0}],tooltip:{trigger:"item",metrics:[]},reference_lines:[],reference_areas:[],dataZoom:Pt};function ab(t,e){if(!t.x_axis.data_key)return[];const n=D(t.x_axis.data_key);return[{source:e[n.queryID]}]}function ob(t){const e=t.y_axes.some(i=>!!i.name);let n=15;e&&(n+=20),t.dataZoom.x_axis_slider&&(n+=20);let r=5;return t.x_axis.name&&(r+=15),{top:n,bottom:r}}function lb(){return{show:!1,bottom:0,left:"center",type:"scroll"}}function Vn(t,e){if(t)return e[t]??void 0}function cb({reference_areas:t,variableValueMap:e}){const n=t.map(r=>[{name:r.content.text,value:r.content.text,itemStyle:r.itemStyle,label:r.label,xAxis:Vn(r.leftBottomPoint.x_data_key,e),yAxis:Vn(r.leftBottomPoint.y_data_key,e)},{xAxis:Vn(r.rightTopPoint.x_data_key,e),yAxis:Vn(r.rightTopPoint.y_data_key,e)}]);return{type:"scatter",name:"ref_areas",silent:!0,data:[],markArea:{data:n}}}function ub({type:t,...e},n){if(!t)return 10;if(t==="static"){const{size:i}=e;return i}const{func_content:r}=e;return(i,o)=>{const l=o.data;try{return new Function(`return ${r}`)()({rowData:l,params:o,variables:n},{lodash:y,interpolate:xt.interpolate})}catch(c){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${c.message}`),10}}}function db({type:t,...e},n){if(!t)return tn.static.color;if(t==="static"){const{color:i}=e;return i}const{func_content:r}=e;return({value:i})=>{try{return new Function(`return ${r}`)()({rowData:i,variables:n},{lodash:y,interpolate:xt.interpolate})}catch(o){return console.error(`[getSeriesColor] failed parsing custom function, error: ${o.message}`),10}}}function pb(t,e,n,r){return t.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?An(i.template,e,r):""},position:c}}}})}function hb({x_axis:t,scatter:e},n){const r=D(t.data_key),i=D(e.y_data_key),o=D(e.name_data_key);return{label:{show:!!e.label_position,position:e.label_position,...Qe(e.label_overflow.label),formatter:({value:l})=>l[o.columnKey]},type:"scatter",name:"",xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{color:db(e.color,n)},symbolSize:ub(e.symbolSize,n),encode:{x:r.columnKey,y:i.columnKey}}}function xb(t,e,n,r){return[hb(t,r)].concat(pb(t.reference_lines,n,r,e)).concat(cb({reference_areas:t.reference_areas,variableValueMap:r}))}function Ya({enabled:t,func_content:e}){return(n,r)=>{if(!t)return n;try{return new Function(`return ${e}`)()(n,r)}catch(i){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${i.message}`),n}}}function Ka(t,e,n){const{x_axis:r}=n;return r.axisLabel.formatter.enabled?Ya(r.axisLabel.formatter)(t,e):t}function fb(t,e){const{x_axis:n,tooltip:r}=e;if(r.trigger==="item"){const c=dn(t[0].data,n.data_key);return Ka(c,0,e)}const i=t.find(c=>c.axisDim==="x"&&c.axisId==="main-x-axis");if(!i)return"";const{axisValue:o,axisIndex:l}=i;return Ka(o,l,e)}const gb=t=>{try{return F(t).format({trimMantissa:!0,mantissa:2})}catch{return t}};function mb(t,e){const{scatter:n,tooltip:r}=t;return{confine:!0,trigger:r.trigger,formatter:function(i){const o=e[0]??e.default,l=Array.isArray(i)?i:[i];if(l.length===0)return"";const c=fb(l,t),u=Je(t.scatter.label_overflow.tooltip),d=l.map(({value:m})=>`
253
+ `)(n)}catch(r){return console.error(r),console.log(t),t}}function Qy(t,e,n,r){const i=Gy(e,r),o=/^(.+)\}\}(.*)$/;return t.split("{{").map(l=>{const c=o.exec(l);if(!c)return l;const u=i[c[1]];if(u){const p=c[2]??"";return`${u}${p}`}const d=Wy(c[1]);return`${Ry(d,i,n)}${c[2]}`}).join("")}const Uy=S.observer(({context:t})=>{const e=oe(),{value:n}=O(t.instanceData,"config"),{variables:r,data:i}=t,o=f.useMemo(()=>{const l=y.defaults({},n,Bn);return l.content?Qy(l.content,r,e.payloadForViz,i):""},[n,r,e.payloadForViz]);return o?s.jsx(An,{value:o,styles:{root:{border:"none",height:"100%"},content:{padding:0}}}):null});function Yy(){const{editor:t}=q.useRichTextEditorContext();return s.jsx(q.RichTextEditor.Control,{onClick:()=>t==null?void 0:t.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 rr=f.forwardRef(({value:t,onChange:e,styles:n={},label:r,onSubmit:i},o)=>{const[l,c]=f.useState(t),u=ci.useEditor({extensions:[ui,li,q.Link,ti,ei,Zr,ri.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),oi,ai,ii,ni.configure({types:["heading","paragraph"]}),Hr.configure({placeholder:"This is placeholder"}),si,Jr.Color,_a],content:l,onUpdate:({editor:x})=>{c(x.getHTML())}});f.useEffect(()=>{c(t),u==null||u.commands.setContent(t)},[t]);const d=()=>{e(l),i==null||i()},p=t!==l,h=f.useMemo(()=>y.defaultsDeep({},{content:Ps},n),[n]);return u?s.jsxs(a.Stack,{spacing:4,sx:{flexGrow:1,position:"relative"},children:[s.jsxs(a.Group,{align:"center",children:[s.jsx(a.Text,{size:14,fw:500,children:r}),s.jsx(a.ActionIcon,{color:"blue",disabled:!p,onClick:d,children:s.jsx(k.IconDeviceFloppy,{size:18})})]}),s.jsxs(q.RichTextEditor,{editor:u,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(Yy,{})}),s.jsx(Xx,{editor:u})]}),s.jsx(q.RichTextEditor.Content,{})]})]}):null});function Ky({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=f.useMemo(()=>y.defaults({},e,Bn),[e]),{control:i,handleSubmit:o,watch:l,reset:c}=b.useForm({defaultValues:r});l("content"),f.useEffect(()=>{c(r)},[r]);const u=f.useRef(null),d=()=>{var p;return(p=u.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:u,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(rr,{...p,styles:{root:{flexGrow:1}},label:"Content",onSubmit:d})})]})})}class Xy extends re{constructor(){super(...arguments);z(this,"VERSION",1)}fixMalformedConfig(n){return y.defaults({},n,Bn)}configVersions(){this.version(1,n=>({version:1,config:this.fixMalformedConfig(n)}))}}const Jy={displayName:"Rich Text",displayGroup:"Others",migrator:new Xy,name:"richText",viewRender:Uy,configRender:Ky,createConfig(){return{version:1,config:y.cloneDeep(Bn)}}},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(`
254
+ `)}},Wa={id:"builtin:echarts:click-scatter-chart:series",displayName:"Click Scatter",nameRender:Hy,configRender:Zy,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 Zy(t){return s.jsx(s.Fragment,{})}function Hy(t){return s.jsx(a.Text,{children:"Click scatter"})}const Ra={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
255
+ `)},Qa={label:Ae.on_axis,tooltip:Ae.in_tooltip},ir={scatter:{y_data_key:"",name_data_key:"",symbolSize:{type:"static",size:10},color:tn.static,label_position:"right",label_overflow:Qa},stats:{templates:{top:"",bottom:""}},x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...Ra}}},y_axes:[{name:"Y Axis",position:"left",nameAlignment:"center",label_formatter:ye,min:"",max:"",show:!0}],tooltip:{trigger:"item",metrics:[]},reference_lines:[],reference_areas:[],dataZoom:zt};function eb(t,e){if(!t.x_axis.data_key)return[];const n=D(t.x_axis.data_key);return[{source:e[n.queryID]}]}function tb(t){const e=t.y_axes.some(i=>!!i.name);let n=15;e&&(n+=20),t.dataZoom.x_axis_slider&&(n+=20);let r=5;return t.x_axis.name&&(r+=15),{top:n,bottom:r}}function nb(){return{show:!1,bottom:0,left:"center",type:"scroll"}}function On(t,e){if(t)return e[t]??void 0}function sb({reference_areas:t,variableValueMap:e}){const n=t.map(r=>[{name:r.content.text,value:r.content.text,itemStyle:r.itemStyle,label:r.label,xAxis:On(r.leftBottomPoint.x_data_key,e),yAxis:On(r.leftBottomPoint.y_data_key,e)},{xAxis:On(r.rightTopPoint.x_data_key,e),yAxis:On(r.rightTopPoint.y_data_key,e)}]);return{type:"scatter",name:"ref_areas",silent:!0,data:[],markArea:{data:n}}}function rb({type:t,...e},n){if(!t)return 10;if(t==="static"){const{size:i}=e;return i}const{func_content:r}=e;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 ib({type:t,...e},n){if(!t)return tn.static.color;if(t==="static"){const{color:i}=e;return i}const{func_content:r}=e;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 ab(t,e,n,r){return t.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,e,r):""},position:c}}}})}function ob({x_axis:t,scatter:e},n){const r=D(t.data_key),i=D(e.y_data_key),o=D(e.name_data_key);return{label:{show:!!e.label_position,position:e.label_position,...Qe(e.label_overflow.label),formatter:({value:l})=>l[o.columnKey]},type:"scatter",name:"",xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{color:ib(e.color,n)},symbolSize:rb(e.symbolSize,n),encode:{x:r.columnKey,y:i.columnKey}}}function lb(t,e,n,r){return[ob(t,r)].concat(ab(t.reference_lines,n,r,e)).concat(sb({reference_areas:t.reference_areas,variableValueMap:r}))}function Ua({enabled:t,func_content:e}){return(n,r)=>{if(!t)return n;try{return new Function(`return ${e}`)()(n,r)}catch(i){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${i.message}`),n}}}function Ya(t,e,n){const{x_axis:r}=n;return r.axisLabel.formatter.enabled?Ua(r.axisLabel.formatter)(t,e):t}function cb(t,e){const{x_axis:n,tooltip:r}=e;if(r.trigger==="item"){const c=dn(t[0].data,n.data_key);return Ya(c,0,e)}const i=t.find(c=>c.axisDim==="x"&&c.axisId==="main-x-axis");if(!i)return"";const{axisValue:o,axisIndex:l}=i;return Ya(o,l,e)}const ub=t=>{try{return F(t).format({trimMantissa:!0,mantissa:2})}catch{return t}};function db(t,e){const{scatter:n,tooltip:r}=t;return{confine:!0,trigger:r.trigger,formatter:function(i){const o=e[0]??e.default,l=Array.isArray(i)?i:[i];if(l.length===0)return"";const c=cb(l,t),u=Je(t.scatter.label_overflow.tooltip),d=l.map(({value:m})=>`
256
256
  <th style="text-align: right; padding-right: 1em">
257
257
  <div style="${u}">${dn(m,n.name_data_key)}</div>
258
258
  </th>
259
- `);d.unshift("<th></th>");const h=[`<tr>
259
+ `);d.unshift("<th></th>");const p=[`<tr>
260
260
  <th style="text-align: right;">${t.x_axis.name}</th>
261
261
  ${l.map(m=>`<td style="text-align: right; padding: 0 1em;">${c}</td>`).join("")}
262
262
  </tr>`,`<tr>
@@ -265,22 +265,22 @@ Check the top-level render call using <`+M+">.")}return I}}function oc(v,I){{if(
265
265
  <td style="text-align: right; padding: 0 1em;">
266
266
  ${o(dn(m,n.y_data_key))}
267
267
  </td>`).join("")}
268
- </tr>`],p=t.tooltip.metrics.map(m=>`<tr>
268
+ </tr>`],h=t.tooltip.metrics.map(m=>`<tr>
269
269
  <th style="text-align: right;">${m.name}</th>
270
- ${l.map(({value:j})=>`<td style="text-align: right; padding: 0 1em;">${gb(dn(j,m.data_key))}</td>`).join("")}
271
- </tr>`);return h.push(...p),`
270
+ ${l.map(({value:j})=>`<td style="text-align: right; padding: 0 1em;">${ub(dn(j,m.data_key))}</td>`).join("")}
271
+ </tr>`);return p.push(...h),`
272
272
  <table style="width: auto">
273
273
  <thead><tr>${d.join("")}</tr></thead>
274
- <tbody>${h.join("")}</tbody>
274
+ <tbody>${p.join("")}</tbody>
275
275
  </table>
276
- `}}}function yb(t,e){const n=e.every(o=>!Number.isNaN(Number(o))),{axisLabel:r}=t.x_axis,i=e.length===0;return[Le.getXAxis({data:e,name:t.x_axis.name??"",nameGap:i?5:void 0,id:"main-x-axis",type:n?"value":"category",axisLabel:{...r,formatter:Ya(r.formatter)}})]}function bb(t,e){return t.y_axes.map(({nameAlignment:n,min:r,max:i,...o},l)=>{let c=o.position;return c||(c=l>0?"right":"left"),Le.getYAxis({...o,minInterval:1,min:r||void 0,max:i||void 0,position:c,axisLine:{show:!0},axisLabel:{show:!0,formatter:e[l]??e.default},nameTextStyle:{align:n},nameLocation:"end",nameGap:15,splitLine:{show:!1}})})}const jb={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 vb(t,e,n){const r=n.reduce((u,d)=>{const h=at(d,e);return u[d.name]=qe(d,h),u},{}),i=t.y_axes.reduce((u,{label_formatter:d},h)=>(u[h]=function(x){let m=x;if(typeof x=="object"&&(Array.isArray(x.value)&&x.value.length===2?m=x.value[1]:m=x.value),!d)return m;try{return F(m).format(d)}catch(j){return console.error(j),m}},u),{default:({value:u})=>u}),o=y.uniq(rt(e,t.x_axis.data_key)),l=xb(t,e,n,r),c={xAxis:yb(t,o),yAxis:bb(t,i),series:l,dataset:ab(t,e),tooltip:mb(t,i),grid:ob(t),legend:lb(),dataZoom:Ys(t.dataZoom)};return y.defaultsDeep({},c,jb)}K.use([P.DataZoomComponent,te.BarChart,te.LineChart,te.ScatterChart,P.GridComponent,P.LegendComponent,P.TooltipComponent,we.CanvasRenderer,P.MarkLineComponent,P.MarkAreaComponent]);function Ua(t){return t.trim().length>0}function wb({conf:t,data:e,width:n,height:r,interactionManager:i,variables:o}){const l=mt(e,t.x_axis.data_key),c=$e(i.triggerManager,Wa.id),u=f.useCallback(p=>{const x=p.data;c.forEach(m=>{i.runInteraction(m.id,{...p,rowData:x})})},[l,c,i]),d=f.useMemo(()=>({click:u}),[u]),h=f.useMemo(()=>vb(t,e,o),[t,e]);return s.jsx(ve,{echarts:K,option:h,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function Cb({context:t,instance:e}){const n=Ve({vizManager:t.vizManager,instance:e}),{value:r}=O(t.instanceData,"config"),{variables:i}=t,o=f.useMemo(()=>y.defaults({},r,ir),[r]),l=t.data,{width:c,height:u}=t.viewport,{ref:d,height:h}=pe.useElementSize(),{ref:p,height:x}=pe.useElementSize(),m=f.useMemo(()=>{const{stats:{templates:C}}=o;return{top:en(C.top,i,l),bottom:en(C.bottom,i,l)}},[o,l]),j=Math.max(0,Re(u)-h-x);return!c||!u?null:s.jsxs(Te,{width:c,height:u,children:[s.jsx(a.Text,{ref:d,align:"left",size:"xs",pl:"sm",sx:{display:Ua(o.stats.templates.top)?"block":"none"},children:Object.values(m.top).map(C=>C)}),s.jsx(wb,{variables:i,width:We(c),height:j,data:l,conf:o,interactionManager:n}),s.jsx(a.Text,{ref:p,align:"left",size:"xs",pl:"sm",sx:{display:Ua(o.stats.templates.bottom)?"block":"none"},children:Object.values(m.bottom).map(C=>C)})]})}const Sb=f.forwardRef(({value:t,onChange:e,xAxisOptions:n,yAxisOptions:r,variableOptions:i},o)=>{const l=(c,u)=>{const d=y.cloneDeep(t);y.set(d,c,u),e(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:t.content.text,onChange:c=>l("content.text",c.currentTarget.value)}),s.jsx(Zs,{label:"Text Position",value:t.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:t.xAxisIndex,onChange:c=>l("xAxisIndex",c)}),r&&s.jsx(a.Select,{label:"Y Axis",data:r,value:t.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:t.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:t.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:t.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:t.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:t.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:t.label.color,onChange:c=>l("label.color",c)})]})]})});function _b(){const t=new Date().getTime().toString();return{id:t,content:{text:t},itemStyle:{color:"rgba(0,0,0,0.05)"},label:{position:"inside",color:"rgba(0,0,0,0.5)"},leftBottomPoint:{x_data_key:"",y_data_key:""},rightTopPoint:{x_data_key:"",y_data_key:""},xAxisIndex:"0",yAxisIndex:"0"}}function kb({control:t,watch:e,variables:n}){const{fields:r,append:i,remove:o}=b.useFieldArray({control:t,name:"reference_areas"}),l=e("reference_areas"),c=r.map((x,m)=>({...x,...l[m]})),u=()=>{const x=_b();i(x)},d=f.useMemo(()=>n.map(x=>({label:x.name,value:x.name})),[n]),h=e("y_axes"),p=f.useMemo(()=>h.map(({name:x},m)=>({label:x,value:m.toString()})),[h]);return s.jsxs(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[s.jsxs(a.Tabs.List,{children:[c.map((x,m)=>s.jsx(a.Tabs.Tab,{value:m.toString(),children:m+1},x.id)),s.jsx(a.Tabs.Tab,{onClick:u,value:"add",children:s.jsx(_.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:t,render:({field:j})=>s.jsxs(a.Stack,{children:[s.jsx(Sb,{variableOptions:d,yAxisOptions:p,...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 Tb=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Ib=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Db({control:t,index:e,remove:n,watch:r,variableOptions:i,yAxisOptions:o}){const l=r(`reference_lines.${e}.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.${e}.name`,control:t,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.${e}.variable_key`,control:t,render:({field:c})=>s.jsx(a.Select,{label:"Value",required:!0,data:i,sx:{flex:1},...c})})]}),s.jsx(b.Controller,{name:`reference_lines.${e}.template`,control:t,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.${e}.orientation`,control:t,render:({field:c})=>s.jsx(a.Select,{label:"Orientation",data:Ib,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.${e}.yAxisIndex`,control:t,render:({field:{value:c,onChange:u,...d}})=>s.jsx(a.Select,{label:"Y Axis",data:o,disabled:o.length===0,...d,value:(c==null?void 0:c.toString())??"",onChange:h=>{if(!h){u(0);return}u(Number(h))},sx:{flex:1}})})]}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:`reference_lines.${e}.lineStyle.type`,control:t,render:({field:c})=>s.jsx(a.Select,{label:"Line Type",data:Tb,sx:{flexGrow:1},...c})}),s.jsx(b.Controller,{name:`reference_lines.${e}.lineStyle.width`,control:t,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.${e}.lineStyle.color`,control:t,render:({field:c})=>s.jsx(Se,{...c})})]}),s.jsx(a.Button,{leftIcon:s.jsx(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Reference Line"})]})}function Mb({control:t,watch:e,variables:n}){const{fields:r,append:i,remove:o}=b.useFieldArray({control:t,name:"reference_lines"}),l=e("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]),h=e("y_axes"),p=f.useMemo(()=>h.map(({name:x},m)=>({label:x,value:m.toString()})),[h]);return s.jsxs(a.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[s.jsxs(a.Tabs.List,{children:[c.map((x,m)=>s.jsx(a.Tabs.Tab,{value:m.toString(),children:m+1},x.id)),s.jsx(a.Tabs.Tab,{onClick:u,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),c.map((x,m)=>s.jsx(a.Tabs.Panel,{value:m.toString(),children:s.jsx(Db,{control:t,index:m,remove:o,watch:e,variableOptions:d,yAxisOptions:p})},x.id))]})}const Ab=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return s.jsx(a.Box,{children:s.jsx(me,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},zb=({value:t,onChange:e})=>{const[n,{setTrue:r,setFalse:i}]=$.useBoolean(),[o,l]=f.useState(t),c=()=>{i();const{type:p,func_content:x}=o,m={type:p,func_content:x};l(m),e(m)},u=()=>{i(),l(t)},d=p=>{l(x=>({...x,func_content:p}))},h=()=>{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(Ab,{value:o.func_content,onChange:d}),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:c,children:"OK"})]})]})]})})]})},Eb=({value:t,onChange:e})=>t.type!=="dynamic"?null:s.jsx(zb,{value:t,onChange:e}),Pb=({value:t,onChange:e})=>{if(t.type!=="static")return null;const n=r=>{e({...t,color:r})};return s.jsx(a.ColorInput,{label:" ",format:"rgb",value:t.color,onChange:n})},Lb=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Bb=f.forwardRef(({label:t="Color",value:e,onChange:n},r)=>{const i=o=>{n({...tn[o]})};return s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(a.Select,{ref:r,label:t,data:Lb,value:e.type,onChange:i,sx:{flexGrow:1}}),s.jsx(Pb,{value:e,onChange:n}),s.jsx(Eb,{value:e,onChange:n})]})}),Ob=f.forwardRef(({value:t,onChange:e},n)=>{const r=o=>{e({...t,label:o})},i=o=>{e({...t,tooltip:o})};return s.jsxs(a.Stack,{ref:n,spacing:0,children:[s.jsx(hn,{sectionTitle:"Overflow on Chart",value:t.label,onChange:r}),s.jsx(hn,{sectionTitle:"Overflow in Tooltip",value:t.tooltip,onChange:i})]})}),$b=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return s.jsx(a.Box,{children:s.jsx(me,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Xa={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
277
- `)}},Vb=({value:t,onChange:e})=>{const[n,{setTrue:r,setFalse:i}]=$.useBoolean(),[o,l]=f.useState(t),c=()=>{i();const{type:p,func_content:x}=o,m={type:p,func_content:x};l(m),e(m)},u=()=>{i(),l(t)},d=p=>{l(x=>({...x,func_content:p}))},h=()=>{d(Xa.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($b,{value:o.func_content,onChange:d}),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:c,children:"OK"})]})]})]})})]})},Nb=({value:t,onChange:e})=>t.type!=="dynamic"?null:s.jsx(Vb,{value:t,onChange:e}),qb=({value:t,onChange:e})=>{if(t.type!=="static")return null;const n=r=>{e({...t,size:r})};return s.jsx(s.Fragment,{children:s.jsx(a.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:t.size,onChange:n})})},Fb=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Gb=f.forwardRef(({label:t="Size",value:e,onChange:n},r)=>{const i=o=>{n({...Xa[o]})};return s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(a.Select,{ref:r,label:t,data:Fb,value:e.type,onChange:i,sx:{flexGrow:1}}),s.jsx(qb,{value:e,onChange:n}),s.jsx(Nb,{value:e,onChange:n})]})}),Wb=[{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 Rb({control:t,watch:e}){return e(["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:t,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:t,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:t,render:({field:n})=>s.jsx(Gb,{label:"Size",...n})}),s.jsx(b.Controller,{name:"scatter.color",control:t,render:({field:n})=>s.jsx(Bb,{...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:t,render:({field:n})=>s.jsx(a.Select,{label:"Label Position",data:Wb,...n})})}),s.jsx(b.Controller,{name:"scatter.label_overflow",control:t,render:({field:n})=>s.jsx(Ob,{...n})})]})}function Qb({control:t,watch:e}){return e("stats"),s.jsx(a.Stack,{children:s.jsxs(a.Stack,{spacing:0,children:[s.jsx(b.Controller,{name:"stats.templates.top",control:t,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:t,render:({field:n})=>s.jsx(Qt,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const Yb=({control:t,index:e,remove:n})=>s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`tooltip.metrics.${e}.name`,control:t,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`tooltip.metrics.${e}.data_key`,control:t,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(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),Kb=({control:t,watch:e})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:t,name:"tooltip.metrics"}),o=e("tooltip.metrics"),l=n.map((p,x)=>({...p,...o[x]})),c=()=>r({id:Date.now().toString(),data_key:"",name:""}),u=e("tooltip.metrics.0.id"),[d,h]=f.useState(()=>u??null);return f.useEffect(()=>{u&&h(p=>p!==null?p:u)},[u]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(_.InfoCircle,{size:14,color:"#888"}),s.jsx(a.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),s.jsxs(a.Tabs,{value:d,onTabChange:p=>h(p),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((p,x)=>s.jsx(a.Tabs.Tab,{value:p.id,children:p.name?p.name:x},p.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),l.map((p,x)=>s.jsx(a.Tabs.Panel,{value:p.id,children:s.jsx(Yb,{control:t,index:x,remove:i},p.id)},p.id))]})]})},Ub=[{label:"Scatter Point",value:"item"},{label:"X Axis",value:"axis"}];function Xb({control:t,watch:e}){return e("tooltip.trigger"),s.jsxs(a.Stack,{children:[s.jsx(b.Controller,{name:"tooltip.trigger",control:t,render:({field:n})=>s.jsx(a.Select,{label:"Trigger",data:Ub,sx:{flexGrow:1},...n})}),s.jsx(a.Divider,{variant:"dashed"}),s.jsx(Kb,{control:t,watch:e})]})}const Jb=({disabled:t,value:e,onChange:n})=>{const r=i=>{i&&n(i)};return s.jsxs(a.Box,{sx:{position:"relative"},children:[t&&s.jsx(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),s.jsx(me,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},Zb=f.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:i,setFalse:o}]=$.useBoolean(),[l,c]=f.useState(t);f.useEffect(()=>{c(t)},[t]);const u=m=>{c({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:j}=l,C={enabled:m,func_content:j};c(C),e(C)},h=()=>{o(),c(t)},p=m=>{c(j=>({...j,func_content:m}))},x=()=>{p(Ra.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(Jb,{value:l.func_content,onChange:p,disabled:!l.enabled}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:x,color:"red",leftIcon:s.jsx(_.Recycle,{size:20}),children:"Reset"}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:h,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:d,children:"OK"})]})]})]})})]})});function Hb({control:t,watch:e}){return e(["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:t,render:({field:n})=>s.jsx(B,{label:"Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"x_axis.name",control:t,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:t,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:t,render:({field:n})=>s.jsx(Zb,{...n})})]})]})}const ej=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],tj=[{label:"left",value:"left"},{label:"right",value:"right"}];function nj({control:t,index:e,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.${e}.name`,control:t,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`y_axes.${e}.nameAlignment`,control:t,render:({field:r})=>s.jsx(a.Select,{label:"Align",required:!0,data:ej,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.${e}.position`,control:t,render:({field:r})=>s.jsx(a.Select,{label:"Position",required:!0,data:tj,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.${e}.label_formatter`,control:t,render:({field:r})=>s.jsx(Ae,{...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.${e}.min`,control:t,render:({field:r})=>s.jsx(a.TextInput,{label:"Min",...r})}),s.jsx(b.Controller,{name:`y_axes.${e}.max`,control:t,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(e),disabled:e===0,children:"Delete this YAxis"})]})}function sj({control:t,watch:e}){const{fields:n,append:r,remove:i}=b.useFieldArray({control:t,name:"y_axes"}),o=e("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(nj,{control:t,index:d,remove:i})},u.id))]})}function rj(t){return t||{templates:{top:"",bottom:""}}}function ij({reference_lines:t=[],stats:e,...n}){return{reference_lines:t,stats:rj(e),...n}}function aj({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),{variables:r}=t,i=f.useMemo(()=>y.defaultsDeep({},e,ir),[e]),o=f.useMemo(()=>ij(i),[i]);f.useEffect(()=>{!y.isEqual(i,o)&&(console.log("config malformed, resetting to defaults",i,o),n(o))},[i,o]);const{control:l,handleSubmit:c,watch:u,getValues:d,reset:h}=b.useForm({defaultValues:o});f.useEffect(()=>{h(o)},[o]);const p=d(),x=f.useMemo(()=>!y.isEqual(p,i),[p,i]);return u(["dataZoom"]),s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:c(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Chart Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!x,children:s.jsx(_.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(Hb,{control:l,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Y Axes",children:s.jsx(sj,{control:l,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Scatter",children:s.jsx(Rb,{control:l,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(Xb,{control:l,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Stats",children:s.jsx(Qb,{control:l,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Reference Lines",children:s.jsx(Mb,{variables:r,control:l,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Reference Areas",children:s.jsx(kb,{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(Us,{...m})})})]})]})})}function oj(t){const{dataZoom:e=Pt,...n}=t;return{...n,dataZoom:e}}function lj(t){const e={scatter:{label_overflow:Qa}};return y.defaultsDeep(e,t)}function cj(t){const{color:e}=t.scatter;return typeof e=="string"?{...t,scatter:{...t.scatter,color:{...tn.static,color:e}}}:t}function uj(t){const e=t.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{...t,reference_lines:e}}function dj(t){const e={tooltip:{trigger:"item"}};return y.defaultsDeep({},t,e)}function pj(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis:i,scatter:o,tooltip:l,...c}=t;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 hj extends re{constructor(){super(...arguments);z(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:oj(n.config)})),this.version(4,n=>{const{config:r}=n;return{...n,version:5,config:lj(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:cj(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:uj(r)}}),this.version(8,n=>{const{config:r}=n;return{...n,version:8,config:dj(r)}}),this.version(9,(n,r)=>{const{config:i}=n;return{...n,version:9,config:pj(i,r)}})}}const xj={displayName:"Scatter Chart",displayGroup:"ECharts-based charts",migrator:new hj,name:"scatterChart",viewRender:Cb,configRender:aj,createConfig(){return{version:9,config:y.cloneDeep(ir)}},triggers:[Wa]},ar={template:"The variable ${value} is defined in Variables section",vertical_align:"center",horizontal_align:"left"};function fj(t){if("variables"in t)return t;const{align:e,size:n,weight:r,color:i,content:{prefix:o="",data_field:l="value",formatter:c={output:"number",mantissa:0},postfix:u=""}={}}=t;return{align:e,template:`${o} \${value} ${u}`,variables:[{name:"value",data_field:l,aggregation:{type:"none",config:{}},formatter:c,color:i,weight:r,size:n}]}}function gj(t){return y.omit(t,["variables"])}function mj(t){const{align:e,...n}=t;return{horizontal_align:e,vertical_align:"center",...n}}function yj(t){const e=y.cloneDeep(t),n=y.get(e,"color.valueRange");return n!==void 0&&y.set(e,"color.valueRange",n.map(r=>Number(r))),e}class bj extends re{constructor(){super(...arguments);z(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:fj(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(yj(l))}),{...n,version:2,config:gj(i)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:mj(r)}})}}const jj={left:"flex-start",center:"center",right:"flex-end"},vj={top:"flex-start",center:"center",bottom:"flex-end"},wj=S.observer(({context:t})=>{const e=oe(),{value:n=ar}=O(t.instanceData,"config"),{variables:r}=t,{template:i,horizontal_align:o,vertical_align:l}=n,{width:c,height:u}=t.viewport,d=f.useMemo(()=>{try{return y.template(i)(e.payloadForSQL)}catch{return i}},[e.payloadForSQL,i]),h=f.useMemo(()=>en(d,r,t.data),[d,r,t.data,t]);return s.jsx(a.Center,{sx:{width:c,height:u,justifyContent:jj[o],alignItems:vj[l]},children:s.jsx(a.Box,{children:Object.values(h).map((p,x)=>s.jsx(f.Fragment,{children:p},x))})})}),Cj=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Sj=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function _j({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},e,ar),[e]),{control:i,handleSubmit:o,watch:l,getValues:c,reset:u}=b.useForm({defaultValues:r});f.useEffect(()=>{u(r)},[r]),l(["template","horizontal_align","vertical_align"]);const d=c(),h=f.useMemo(()=>!y.isEqual(d,e),[d,e]);return s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:o(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{weight:500,children:"Stats Configurations"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:s.jsx(_.DeviceFloppy,{size:20})})]}),s.jsx(b.Controller,{name:"template",control:i,render:({field:p})=>s.jsx(Qt,{label:"Template",py:"md",sx:{flexGrow:1},...p})}),s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(b.Controller,{name:"horizontal_align",control:i,render:({field:p})=>s.jsx(a.Select,{label:"Horizontal Alignment",data:Cj,...p})}),s.jsx(b.Controller,{control:i,name:"vertical_align",render:({field:p})=>s.jsx(a.Select,{label:"Vertical Alignment",data:Sj,...p})})]})]})})}const kj={createConfig(){return{version:3,config:ar}},displayName:"Stats",displayGroup:"Others",migrator:new bj,name:"stats",viewRender:wj,configRender:_j},or={label_key:"",value_key:"",group_key:"",levels:[]};function Tj(t){const e=new Set(t.map(r=>r.parent_id)),n=new Set(t.map(r=>r.id));return e.forEach(r=>{r===null||n.has(r)||t.push({id:r,name:r,parent_id:null})}),t}function Ij(t){const e=Tj(t).map(i=>({...i,children:[]})),n=y.keyBy(e,i=>i.id),r=[];return e.forEach(i=>{if(!i.parent_id||!n[i.parent_id]){r.push(i);return}n[i.parent_id].children.push(i)}),r}function Dj(t,e){const{label_key:n,value_key:r,group_key:i}=t;if(!n||!r)return[];const o=D(n),l=D(r),c=D(i),u=e[o.queryID].map(d=>({...d,id:d[o.columnKey],parent_id:d[c.columnKey],name:d[o.columnKey],value:d[l.columnKey]?Number(d[l.columnKey]):d[l.columnKey]}));return i?Ij(u):u}const Mj=t=>({treePathInfo:e,name:n,value:r})=>{if(e.length===1||!t)return n;try{const i=e[e.length-2].value;if(r/i<t)return" "}catch{return n}};function Aj(t){const{levels:e}=t;return e.map(n=>{const{show_label_tolerance:r,...i}=n.label;return{...n,label:{...i,formatter:Mj(r)}}})}function zj(){return({treePathInfo:t,name:e,value:n,color:r,marker:i,...o})=>{const l=t.slice(0,t.length-1),c=[`<tr>
276
+ `}}}function pb(t,e){const n=e.every(o=>!Number.isNaN(Number(o))),{axisLabel:r}=t.x_axis,i=e.length===0;return[ze.getXAxis({data:e,name:t.x_axis.name??"",nameGap:i?5:void 0,id:"main-x-axis",type:n?"value":"category",axisLabel:{...r,formatter:Ua(r.formatter)}})]}function hb(t,e){return t.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:e[l]??e.default},nameTextStyle:{align:n},nameLocation:"end",nameGap:15,splitLine:{show:!1}})})}const xb={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 fb(t,e,n){const r=n.reduce((u,d)=>{const p=it(d,e);return u[d.name]=Ne(d,p),u},{}),i=t.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(e,t.x_axis.data_key)),l=lb(t,e,n,r),c={xAxis:pb(t,o),yAxis:hb(t,i),series:l,dataset:eb(t,e),tooltip:db(t,i),grid:tb(t),legend:nb(),dataZoom:Ms(t.dataZoom)};return y.defaultsDeep({},c,xb)}Y.use([P.DataZoomComponent,te.BarChart,te.LineChart,te.ScatterChart,P.GridComponent,P.LegendComponent,P.TooltipComponent,we.CanvasRenderer,P.MarkLineComponent,P.MarkAreaComponent]);function Ka(t){return t.trim().length>0}function gb({conf:t,data:e,width:n,height:r,interactionManager:i,variables:o}){const l=mt(e,t.x_axis.data_key),c=$e(i.triggerManager,Wa.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(()=>fb(t,e,o),[t,e]);return s.jsx(ve,{echarts:Y,option:p,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function mb({context:t,instance:e}){const n=Ve({vizManager:t.vizManager,instance:e}),{value:r}=O(t.instanceData,"config"),{variables:i}=t,o=f.useMemo(()=>y.defaults({},r,ir),[r]),l=t.data,{width:c,height:u}=t.viewport,{ref:d,height:p}=pe.useElementSize(),{ref:h,height:x}=pe.useElementSize(),m=f.useMemo(()=>{const{stats:{templates:C}}=o;return{top:Ut(C.top,i,l),bottom:Ut(C.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:Ka(o.stats.templates.top)?"block":"none"},children:Object.values(m.top).map(C=>C)}),s.jsx(gb,{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:Ka(o.stats.templates.bottom)?"block":"none"},children:Object.values(m.bottom).map(C=>C)})]})}const yb=f.forwardRef(({value:t,onChange:e,xAxisOptions:n,yAxisOptions:r,variableOptions:i},o)=>{const l=(c,u)=>{const d=y.cloneDeep(t);y.set(d,c,u),e(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:t.content.text,onChange:c=>l("content.text",c.currentTarget.value)}),s.jsx(Zs,{label:"Text Position",value:t.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:t.xAxisIndex,onChange:c=>l("xAxisIndex",c)}),r&&s.jsx(a.Select,{label:"Y Axis",data:r,value:t.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:t.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:t.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:t.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:t.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:t.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:t.label.color,onChange:c=>l("label.color",c)})]})]})});function bb(){const t=new Date().getTime().toString();return{id:t,content:{text:t},itemStyle:{color:"rgba(0,0,0,0.05)"},label:{position:"inside",color:"rgba(0,0,0,0.5)"},leftBottomPoint:{x_data_key:"",y_data_key:""},rightTopPoint:{x_data_key:"",y_data_key:""},xAxisIndex:"0",yAxisIndex:"0"}}function jb({control:t,watch:e,variables:n}){const{fields:r,append:i,remove:o}=b.useFieldArray({control:t,name:"reference_areas"}),l=e("reference_areas"),c=r.map((x,m)=>({...x,...l[m]})),u=()=>{const x=bb();i(x)},d=f.useMemo(()=>n.map(x=>({label:x.name,value:x.name})),[n]),p=e("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:t,render:({field:j})=>s.jsxs(a.Stack,{children:[s.jsx(yb,{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 vb=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],wb=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Cb({control:t,index:e,remove:n,watch:r,variableOptions:i,yAxisOptions:o}){const l=r(`reference_lines.${e}.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.${e}.name`,control:t,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.${e}.variable_key`,control:t,render:({field:c})=>s.jsx(a.Select,{label:"Value",required:!0,data:i,sx:{flex:1},...c})})]}),s.jsx(b.Controller,{name:`reference_lines.${e}.template`,control:t,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.${e}.orientation`,control:t,render:({field:c})=>s.jsx(a.Select,{label:"Orientation",data:wb,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.${e}.yAxisIndex`,control:t,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.${e}.lineStyle.type`,control:t,render:({field:c})=>s.jsx(a.Select,{label:"Line Type",data:vb,sx:{flexGrow:1},...c})}),s.jsx(b.Controller,{name:`reference_lines.${e}.lineStyle.width`,control:t,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.${e}.lineStyle.color`,control:t,render:({field:c})=>s.jsx(Se,{...c})})]}),s.jsx(a.Button,{leftIcon:s.jsx(_.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Reference Line"})]})}function Sb({control:t,watch:e,variables:n}){const{fields:r,append:i,remove:o}=b.useFieldArray({control:t,name:"reference_lines"}),l=e("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=e("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(Cb,{control:t,index:m,remove:o,watch:e,variableOptions:d,yAxisOptions:h})},x.id))]})}const _b=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return s.jsx(a.Box,{children:s.jsx(ge,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},kb=({value:t,onChange:e})=>{const[n,{setTrue:r,setFalse:i}]=$.useBoolean(),[o,l]=f.useState(t),c=()=>{i();const{type:h,func_content:x}=o,m={type:h,func_content:x};l(m),e(m)},u=()=>{i(),l(t)},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(_b,{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"})]})]})]})})]})},Tb=({value:t,onChange:e})=>t.type!=="dynamic"?null:s.jsx(kb,{value:t,onChange:e}),Ib=({value:t,onChange:e})=>{if(t.type!=="static")return null;const n=r=>{e({...t,color:r})};return s.jsx(a.ColorInput,{label:" ",format:"rgb",value:t.color,onChange:n})},Db=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Mb=f.forwardRef(({label:t="Color",value:e,onChange:n},r)=>{const i=o=>{n({...tn[o]})};return s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(a.Select,{ref:r,label:t,data:Db,value:e.type,onChange:i,sx:{flexGrow:1}}),s.jsx(Ib,{value:e,onChange:n}),s.jsx(Tb,{value:e,onChange:n})]})}),Ab=f.forwardRef(({value:t,onChange:e},n)=>{const r=o=>{e({...t,label:o})},i=o=>{e({...t,tooltip:o})};return s.jsxs(a.Stack,{ref:n,spacing:0,children:[s.jsx(hn,{sectionTitle:"Overflow on Chart",value:t.label,onChange:r}),s.jsx(hn,{sectionTitle:"Overflow in Tooltip",value:t.tooltip,onChange:i})]})}),zb=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return s.jsx(a.Box,{children:s.jsx(ge,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Xa={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
277
+ `)}},Eb=({value:t,onChange:e})=>{const[n,{setTrue:r,setFalse:i}]=$.useBoolean(),[o,l]=f.useState(t),c=()=>{i();const{type:h,func_content:x}=o,m={type:h,func_content:x};l(m),e(m)},u=()=>{i(),l(t)},d=h=>{l(x=>({...x,func_content:h}))},p=()=>{d(Xa.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(zb,{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"})]})]})]})})]})},Pb=({value:t,onChange:e})=>t.type!=="dynamic"?null:s.jsx(Eb,{value:t,onChange:e}),Lb=({value:t,onChange:e})=>{if(t.type!=="static")return null;const n=r=>{e({...t,size:r})};return s.jsx(s.Fragment,{children:s.jsx(a.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:t.size,onChange:n})})},Bb=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Ob=f.forwardRef(({label:t="Size",value:e,onChange:n},r)=>{const i=o=>{n({...Xa[o]})};return s.jsxs(a.SimpleGrid,{cols:2,children:[s.jsx(a.Select,{ref:r,label:t,data:Bb,value:e.type,onChange:i,sx:{flexGrow:1}}),s.jsx(Lb,{value:e,onChange:n}),s.jsx(Pb,{value:e,onChange:n})]})}),$b=[{label:"off",value:""},{label:"top",value:"top"},{label:"left",value:"left"},{label:"right",value:"right"},{label:"bottom",value:"bottom"},{label:"inside",value:"inside"},{label:"insideLeft",value:"insideLeft"},{label:"insideRight",value:"insideRight"},{label:"insideTop",value:"insideTop"},{label:"insideBottom",value:"insideBottom"},{label:"insideTopLeft",value:"insideTopLeft"},{label:"insideBottomLeft",value:"insideBottomLeft"},{label:"insideTopRight",value:"insideTopRight"},{label:"insideBottomRight",value:"insideBottomRight"}];function Vb({control:t,watch:e}){return e(["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:t,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:t,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:t,render:({field:n})=>s.jsx(Ob,{label:"Size",...n})}),s.jsx(b.Controller,{name:"scatter.color",control:t,render:({field:n})=>s.jsx(Mb,{...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:t,render:({field:n})=>s.jsx(a.Select,{label:"Label Position",data:$b,...n})})}),s.jsx(b.Controller,{name:"scatter.label_overflow",control:t,render:({field:n})=>s.jsx(Ab,{...n})})]})}function Nb({control:t,watch:e}){return e("stats"),s.jsx(a.Stack,{children:s.jsxs(a.Stack,{spacing:0,children:[s.jsx(b.Controller,{name:"stats.templates.top",control:t,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:t,render:({field:n})=>s.jsx(Qt,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const qb=({control:t,index:e,remove:n})=>s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`tooltip.metrics.${e}.name`,control:t,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`tooltip.metrics.${e}.data_key`,control:t,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(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),Fb=({control:t,watch:e})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:t,name:"tooltip.metrics"}),o=e("tooltip.metrics"),l=n.map((h,x)=>({...h,...o[x]})),c=()=>r({id:Date.now().toString(),data_key:"",name:""}),u=e("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(qb,{control:t,index:x,remove:i},h.id)},h.id))]})]})},Gb=[{label:"Scatter Point",value:"item"},{label:"X Axis",value:"axis"}];function Wb({control:t,watch:e}){return e("tooltip.trigger"),s.jsxs(a.Stack,{children:[s.jsx(b.Controller,{name:"tooltip.trigger",control:t,render:({field:n})=>s.jsx(a.Select,{label:"Trigger",data:Gb,sx:{flexGrow:1},...n})}),s.jsx(a.Divider,{variant:"dashed"}),s.jsx(Fb,{control:t,watch:e})]})}const Rb=({disabled:t,value:e,onChange:n})=>{const r=i=>{i&&n(i)};return s.jsxs(a.Box,{sx:{position:"relative"},children:[t&&s.jsx(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),s.jsx(ge,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},Qb=f.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:i,setFalse:o}]=$.useBoolean(),[l,c]=f.useState(t);f.useEffect(()=>{c(t)},[t]);const u=m=>{c({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:j}=l,C={enabled:m,func_content:j};c(C),e(C)},p=()=>{o(),c(t)},h=m=>{c(j=>({...j,func_content:m}))},x=()=>{h(Ra.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(Rb,{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 Ub({control:t,watch:e}){return e(["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:t,render:({field:n})=>s.jsx(B,{label:"Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"x_axis.name",control:t,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:t,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:t,render:({field:n})=>s.jsx(Qb,{...n})})]})]})}const Yb=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],Kb=[{label:"left",value:"left"},{label:"right",value:"right"}];function Xb({control:t,index:e,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.${e}.name`,control:t,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`y_axes.${e}.nameAlignment`,control:t,render:({field:r})=>s.jsx(a.Select,{label:"Align",required:!0,data:Yb,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.${e}.position`,control:t,render:({field:r})=>s.jsx(a.Select,{label:"Position",required:!0,data:Kb,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.${e}.label_formatter`,control:t,render:({field:r})=>s.jsx(Be,{...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.${e}.min`,control:t,render:({field:r})=>s.jsx(a.TextInput,{label:"Min",...r})}),s.jsx(b.Controller,{name:`y_axes.${e}.max`,control:t,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(e),disabled:e===0,children:"Delete this YAxis"})]})}function Jb({control:t,watch:e}){const{fields:n,append:r,remove:i}=b.useFieldArray({control:t,name:"y_axes"}),o=e("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(Xb,{control:t,index:d,remove:i})},u.id))]})}function Zb(t){return t||{templates:{top:"",bottom:""}}}function Hb({reference_lines:t=[],stats:e,...n}){return{reference_lines:t,stats:Zb(e),...n}}function ej({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),{variables:r}=t,i=f.useMemo(()=>y.defaultsDeep({},e,ir),[e]),o=f.useMemo(()=>Hb(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(Ub,{control:l,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Y Axes",children:s.jsx(Jb,{control:l,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Scatter",children:s.jsx(Vb,{control:l,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(Wb,{control:l,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Stats",children:s.jsx(Nb,{control:l,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Reference Lines",children:s.jsx(Sb,{variables:r,control:l,watch:u})}),s.jsx(a.Tabs.Panel,{value:"Reference Areas",children:s.jsx(jb,{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(zs,{...m})})})]})]})})}function tj(t){const{dataZoom:e=zt,...n}=t;return{...n,dataZoom:e}}function nj(t){const e={scatter:{label_overflow:Qa}};return y.defaultsDeep(e,t)}function sj(t){const{color:e}=t.scatter;return typeof e=="string"?{...t,scatter:{...t.scatter,color:{...tn.static,color:e}}}:t}function rj(t){const e=t.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{...t,reference_lines:e}}function ij(t){const e={tooltip:{trigger:"item"}};return y.defaultsDeep({},t,e)}function aj(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis:i,scatter:o,tooltip:l,...c}=t;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 oj extends re{constructor(){super(...arguments);z(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:tj(n.config)})),this.version(4,n=>{const{config:r}=n;return{...n,version:5,config:nj(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:sj(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:rj(r)}}),this.version(8,n=>{const{config:r}=n;return{...n,version:8,config:ij(r)}}),this.version(9,(n,r)=>{const{config:i}=n;return{...n,version:9,config:aj(i,r)}})}}const lj={displayName:"Scatter Chart",displayGroup:"ECharts-based charts",migrator:new oj,name:"scatterChart",viewRender:mb,configRender:ej,createConfig(){return{version:9,config:y.cloneDeep(ir)}},triggers:[Wa]},ar={template:"The variable ${value} is defined in Variables section",vertical_align:"center",horizontal_align:"left"};function cj(t){if("variables"in t)return t;const{align:e,size:n,weight:r,color:i,content:{prefix:o="",data_field:l="value",formatter:c={output:"number",mantissa:0},postfix:u=""}={}}=t;return{align:e,template:`${o} \${value} ${u}`,variables:[{name:"value",data_field:l,aggregation:{type:"none",config:{}},formatter:c,color:i,weight:r,size:n}]}}function uj(t){return y.omit(t,["variables"])}function dj(t){const{align:e,...n}=t;return{horizontal_align:e,vertical_align:"center",...n}}function pj(t){const e=y.cloneDeep(t),n=y.get(e,"color.valueRange");return n!==void 0&&y.set(e,"color.valueRange",n.map(r=>Number(r))),e}class hj extends re{constructor(){super(...arguments);z(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(pj(l))}),{...n,version:2,config:uj(i)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:dj(r)}})}}const xj={left:"flex-start",center:"center",right:"flex-end"},fj={top:"flex-start",center:"center",bottom:"flex-end"},gj=S.observer(({context:t})=>{const e=oe(),{value:n=ar}=O(t.instanceData,"config"),{variables:r}=t,{template:i,horizontal_align:o,vertical_align:l}=n,{width:c,height:u}=t.viewport,d=f.useMemo(()=>{try{return y.template(i)(e.payloadForSQL)}catch{return i}},[e.payloadForSQL,i]),p=f.useMemo(()=>Ut(d,r,t.data),[d,r,t.data,t]);return s.jsx(a.Center,{sx:{width:c,height:u,justifyContent:xj[o],alignItems:fj[l]},children:s.jsx(a.Box,{children:Object.values(p).map((h,x)=>s.jsx(f.Fragment,{children:h},x))})})}),mj=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],yj=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function bj({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},e,ar),[e]),{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,e),[d,e]);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:mj,...h})}),s.jsx(b.Controller,{control:i,name:"vertical_align",render:({field:h})=>s.jsx(a.Select,{label:"Vertical Alignment",data:yj,...h})})]})]})})}const jj={createConfig(){return{version:3,config:ar}},displayName:"Stats",displayGroup:"Others",migrator:new hj,name:"stats",viewRender:gj,configRender:bj},or={label_key:"",value_key:"",group_key:"",levels:[]};function vj(t){const e=new Set(t.map(r=>r.parent_id)),n=new Set(t.map(r=>r.id));return e.forEach(r=>{r===null||n.has(r)||t.push({id:r,name:r,parent_id:null})}),t}function wj(t){const e=vj(t).map(i=>({...i,children:[]})),n=y.keyBy(e,i=>i.id),r=[];return e.forEach(i=>{if(!i.parent_id||!n[i.parent_id]){r.push(i);return}n[i.parent_id].children.push(i)}),r}function Cj(t,e){const{label_key:n,value_key:r,group_key:i}=t;if(!n||!r)return[];const o=D(n),l=D(r),c=D(i),u=e[o.queryID].map(d=>({...d,id:d[o.columnKey],parent_id:d[c.columnKey],name:d[o.columnKey],value:d[l.columnKey]?Number(d[l.columnKey]):d[l.columnKey]}));return i?wj(u):u}const Sj=t=>({treePathInfo:e,name:n,value:r})=>{if(e.length===1||!t)return n;try{const i=e[e.length-2].value;if(r/i<t)return" "}catch{return n}};function _j(t){const{levels:e}=t;return e.map(n=>{const{show_label_tolerance:r,...i}=n.label;return{...n,label:{...i,formatter:Sj(r)}}})}function kj(){return({treePathInfo:t,name:e,value:n,color:r,marker:i,...o})=>{const l=t.slice(0,t.length-1),c=[`<tr>
278
278
  <th style="text-align: right; padding: 0 1em;">Value</th>
279
279
  <td style="text-align: left; padding: 0 1em;">${n}</td>
280
280
  </tr>
281
- `];return l.reverse().forEach(({value:d,name:h})=>{c.push(`
281
+ `];return l.reverse().forEach(({value:d,name:p})=>{c.push(`
282
282
  <tr>
283
- <th style="text-align: right; padding: 0 1em;">${h||"Total"}</th>
283
+ <th style="text-align: right; padding: 0 1em;">${p||"Total"}</th>
284
284
  <td style="text-align: left; padding: 0 1em;">
285
285
  ${F(n/d).format({output:"percent",mantissa:2,trimMantissa:!0})}
286
286
  </td>
@@ -292,15 +292,15 @@ Check the top-level render call using <`+M+">.")}return I}}function oc(v,I){{if(
292
292
  <table style="width: auto">
293
293
  <tbody>${c.join("")}</tbody>
294
294
  </table>
295
- `}}function Ej(){return{show:!0,trigger:"item",confine:!0,formatter:zj()}}const Pj={tooltip:{show:!0},series:{type:"sunburst",radius:[0,"90%"],emphasis:{focus:"ancestor"}}};function Lj(t,e,n){n.reduce((o,l)=>{const c=at(l,e);return o[l.name]=qe(l,c),o},{});const i={series:{data:Dj(t,e),levels:Aj(t)},tooltip:Ej()};return y.defaultsDeep({},i,Pj)}K.use([te.SunburstChart,we.CanvasRenderer]);function Bj({context:t}){const{variables:e}=t,{value:n}=O(t.instanceData,"config"),r=f.useMemo(()=>y.defaults({},n,or),[n]),i=t.data,{width:o,height:l}=t.viewport,c=f.useMemo(()=>Lj(r,i,e),[r,i,e]);return!o||!l?null:s.jsx(Te,{width:o,height:l,children:s.jsx(ve,{echarts:K,option:c,style:Wt(o,l),notMerge:!0,theme:"merico-light"})})}function Oj({control:t,watch:e}){return e(["label_key","value_key","group_key"]),s.jsxs(a.Stack,{children:[s.jsx(b.Controller,{name:"label_key",control:t,render:({field:n})=>s.jsx(B,{label:"Label Key",required:!0,...n})}),s.jsx(b.Controller,{name:"value_key",control:t,render:({field:n})=>s.jsx(B,{label:"Value Key",required:!0,...n})}),s.jsx(b.Controller,{name:"group_key",control:t,render:({field:n})=>s.jsx(B,{label:"Group Key",clearable:!0,...n})})]})}const $j=[{label:"Radial",value:"radial"},{label:"Tangential",value:"tangential"},{label:"None",value:"0"}],Vj=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Nj=({control:t,index:e,remove:n})=>s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`levels.${e}.r0`,control:t,render:({field:r})=>s.jsx(a.TextInput,{label:"Inside Radius",placeholder:"0%",...r})}),s.jsx(b.Controller,{name:`levels.${e}.r`,control:t,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.${e}.label.show_label_tolerance`,control:t,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.${e}.label.rotate`,control:t,render:({field:r})=>s.jsx(a.Select,{label:"Rotate",data:$j,...r})}),s.jsx(b.Controller,{name:`levels.${e}.label.align`,control:t,render:({field:r})=>s.jsx(a.Select,{label:"Align",data:Vj,...r})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`levels.${e}.label.position`,control:t,render:({field:r})=>s.jsx(Zs,{label:"Position",...r})}),s.jsx(b.Controller,{name:`levels.${e}.label.padding`,control:t,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(e),sx:{top:15,right:5},children:"Delete this Level"})]}),qj=({control:t,watch:e})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:t,name:"levels"}),o=e("levels"),l=n.map((p,x)=>({...p,...o[x]})),c=()=>r({id:Date.now().toString(),r0:"",r:"",label:{show_label_tolerance:.001,rotate:"0",align:"center",position:"inside",padding:0}}),u=e("levels.0.id"),[d,h]=f.useState(()=>u??null);return f.useEffect(()=>{u&&h(p=>p!==null?p:u)},[u]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(_.InfoCircle,{size:14,color:"#888"}),s.jsx(a.Text,{size:14,color:"#888",children:"Configure ring style on each level"})]}),s.jsx(a.Divider,{variant:"dashed",my:10}),s.jsxs(a.Tabs,{value:d,onTabChange:p=>h(p),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((p,x)=>s.jsx(a.Tabs.Tab,{value:p.id,children:x},p.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),l.map((p,x)=>s.jsx(a.Tabs.Panel,{value:p.id,children:s.jsx(Nj,{control:t,index:x,remove:i},p.id)},p.id))]})]})};function Fj({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},e,or),[e]),i=f.useMemo(()=>y.clone(r),[r]),{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=b.useForm({defaultValues:i});f.useEffect(()=>{d(i)},[i]);const h=u(),p=f.useMemo(()=>!y.isEqual(h,r),[h,r]);c(["label_key","value_key","group_key","levels"]);const[x,m]=f.useState("Data");return s.jsx("form",{onSubmit:l(n),children:s.jsxs(a.Stack,{spacing:"xs",children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Sunburst Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(_.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(Oj,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Levels",children:s.jsx(qj,{control:o,watch:c})})]})]})})}function Gj(t){const{label_field:e,value_field:n,...r}=t;return{...r,label_key:e,value_key:n}}function Wj(t){const{group_key:e="",...n}=t;return{...n,group_key:e}}function Rj(t){const{levels:e=[],...n}=t;return{...n,levels:e}}function Qj(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{label_key:i,value_key:o,group_key:l,...c}=t;return{...c,label_key:r(i),value_key:r(o),group_key:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class Yj extends re{constructor(){super(...arguments);z(this,"VERSION",5)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:Gj(n.config)})),this.version(3,n=>({...n,version:3,config:Wj(n.config)})),this.version(4,n=>({...n,version:4,config:Rj(n.config)})),this.version(5,(n,r)=>({...n,version:5,config:Qj(n.config,r)}))}}const Kj={displayName:"Sunburst Chart",displayGroup:"ECharts-based charts",migrator:new Yj,name:"sunburst",viewRender:Bj,configRender:Fj,createConfig(){return{version:5,config:y.cloneDeep(or)}}};var Ye=(t=>(t.string="string",t.number="number",t.eloc="eloc",t.percentage="percentage",t.custom="custom",t))(Ye||{});const Ja=["function text({ value }) {"," // your code goes here"," return value","}"].join(`
296
- `),Za={columns:[],fontSize:"14px",highlightOnHover:!0,horizontalSpacing:"14px",id_field:"",striped:!0,use_raw_columns:!0,verticalSpacing:"14px"},Ha={left:"flex-start",center:"center",right:"flex-end"},Uj=({header:t,cx:e})=>{const n=y.get(t.column.columnDef.meta,"align","left");return s.jsxs(a.Text,{className:e("table-head-cell",{"table-head-cell--sortable":t.column.getCanSort()}),onClick:t.column.getToggleSortingHandler(),align:n,sx:{justifyContent:Ha[n]},children:[t.isPlaceholder?null:Ge.flexRender(t.column.columnDef.header,t.getContext()),s.jsx(Xj,{direction:t.column.getIsSorted()})]})},Xj=({direction:t})=>{switch(t){case"asc":return s.jsx(k.IconArrowUp,{size:16});case"desc":return s.jsx(k.IconArrowDown,{size:"1em"});default:return null}},Jj=a.createStyles(t=>({root:{overflow:"auto",position:"relative","& .table-head-cell":{display:"flex",flexFlow:"row nowrap",alignItems:"center",whiteSpace:"nowrap","&.table-head-cell--sortable":{cursor:"pointer",userSelect:"none"}},"&.table-highlight-on-hover tr":{transition:"background-color 0.2s","&:hover":{backgroundColor:t.colorScheme==="dark"?t.colors.dark[5]:t.colors.gray[0]}}},thead:{background:t.colorScheme==="dark"?t.colors.dark[7]:t.white,position:"sticky",top:24,transform:"translateY(-1px)",zIndex:10},info_bar:{position:"sticky",top:0,left:0,right:0,zIndex:10,background:"white"}})),Zj={tableLayout:"fixed","thead, tbody":{tr:{"th, td":{padding:"2px 10px",div:{overflow:"hidden",textOverflow:"ellipsis"},"&:first-of-type":{paddingLeft:2,paddingRight:2}}}}},Hj=a.createStyles((t,e)=>({content:{display:"flex",alignItems:"center",justifyContent:Ha[e.align],".table-cell-text":{whiteSpace:"nowrap",cursor:e.clickable?"pointer":"default",textDecoration:e.clickable?"underline":"none"}}}));function ev(t){return t?nt(t).oklch()[0]>.7?"black":"white":"inherit"}function tv(t){const e=t.tableCellContext.bgColor;return{backgroundColor:e,color:ev(e)}}function Ot(t){const e=t.tableCellContext.isClickable(),n=Hj({clickable:e,align:t.align});return s.jsx("div",{className:n.classes.content,style:{...tv(t)},children:s.jsx(a.Text,{className:"table-cell-text",onClick:t.tableCellContext.getClickHandler(),children:s.jsx("span",{title:t.children,children:t.children})})})}function nv(t){return s.jsx(Ot,{...t,children:t.value})}function sv(t){const e=F(t.value).format({average:!0,mantissa:2,trimMantissa:!0});return s.jsx(Ot,{...t,children:e})}function rv(t){const e=F(t.value).format({thousandSeparated:!0});return s.jsx(Ot,{...t,children:e})}function iv(t){const e=F(t.value).format({output:"percent",mantissa:3,trimMantissa:!0});return s.jsx(Ot,{...t,children:e})}function av(t){const e=t.value,n=t.func_content;if(!n)return s.jsx(Ot,{...t,children:e});const r=new Function(`return ${n}`)()({value:e});return s.jsx(Ot,{...t,children:r})}function ov(t){switch(t.type){case Ye.string:return s.jsx(nv,{...t});case Ye.eloc:return s.jsx(sv,{...t});case Ye.number:return s.jsx(rv,{...t});case Ye.percentage:return s.jsx(iv,{...t});case Ye.custom:return s.jsx(av,{...t})}}function lv({tableContainerRef:t,rows:e}){var c,u;const n=fc.useVirtual({parentRef:t,size:e.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 $.useWhyDidYouUpdate("TableBody",{tableContainerRef:t,rows:e}),s.jsxs("tbody",{children:[o>0&&s.jsx("tr",{children:s.jsx("td",{style:{height:`${o}px`}})}),r.map(d=>{const h=e[d.index];return s.jsx("tr",{children:h.getVisibleCells().map(p=>s.jsx("td",{children:Ge.flexRender(p.column.columnDef.cell,p.getContext())},p.id))},h.id)}),l>0&&s.jsx("tr",{children:s.jsx("td",{style:{height:`${l}px`}})})]})}const lr={id:"builtin:table:click-cell-content",displayName:"Click Cell Content",nameRender:pv,configRender:uv,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"}]},cv={column:""};function eo(t,e){const{value:n}=O(t.instanceData,"config"),r={columnsFromConfig:[],columnsFromData:[]};if(n&&(r.columnsFromConfig=n.columns.map((i,o)=>({label:i.label,value:o.toString()}))),!e)return r;if(n!=null&&n.id_field){const i=Rt(e,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 uv(t){const{columnsFromConfig:e,columnsFromData:n}=eo(t.instance,t.sampleData),r=e.length>0?e:n,{value:i,set:o}=O(t.trigger.triggerData,"config"),{column:l}=y.defaults({},i,cv),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 dv(t,e){return t?y.isNumber(t.column)?`Click cell of ${e[t.column].label}`:`Click cell of ${t.column}`:"Click cell content (click to config)"}function pv(t){const{columnsFromConfig:e}=eo(t.instance),{value:n}=O(t.trigger.triggerData,"config");return s.jsx(a.Text,{children:dv(n,e)})}function to(t,e,n){return Math.min(Math.max(t,e),n)}class hv{constructor(e){this.steps=e;const n=[],r=new Set;for(const i of e)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(e,n){const r=(n.to-e.to)/(n.from-e.from),i=e.to-r*e.from;return o=>r*o+i}getStepFunctionForValue(e){let n=y.findLastIndex(this.steps,r=>r.from<=e);return n=to(n,0,this.steps.length-2),this.getLinearFunction(this.steps[n],this.steps[n+1])}mapValue(e){return to(this.getStepFunctionForValue(e)(e),0,100)}}class xv{constructor(e,n,r,i,o){this.getColIndex=e,this.cell=n,this.triggers=r,this.interactionManager=i,this.colorManager=o}getClickHandler(){const e=this.getRelatedTrigger();if(e.length!==0)return()=>{const n={row_data:this.cell.row.original,row_index:this.cell.row.index,col_index:this.getColIndex(this.cell)};for(const r of e)this.interactionManager.runInteraction(r.id,n)}}getRelatedTrigger(){return this.triggers.filter(n=>n.schemaRef===lr.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 e=this.columnConf.cellBackgroundColor;if(!e||e==="none")return;if(y.isString(e))return e;const n=+this.cell.getValue();if(isFinite(n)){const r=this.colorManager.decodeInterpolation(e.interpolation),o=new hv(e.steps).mapValue(n);return r==null?void 0:r.getColor(o)}}}const fv=t=>{const e=Ve(t),n=$e(e.triggerManager,lr.id),{colorManager:r}=f.useContext(et);return f.useCallback(i=>new xv(t.getColIndex,i,n,e,r),[n,e,t.getColIndex])};function gv({queryData:t,width:e,height:n,conf:r,context:i,instance:o}){const{id_field:l,use_raw_columns:c,columns:u,...d}=r,{classes:h,cx:p}=Jj(),x=f.useMemo(()=>c?!Array.isArray(t)||t.length===0?[]:Object.keys(t[0]).map(fe=>({id:fe,label:fe,value_field:fe,value_type:Ye.string,align:"left",width:"",cellBackgroundColor:""})):u,[c,u,t]),m=fv({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 Vr=Du(Ke.value_field);return fe.accessor(Vr.columnKey,{cell:rn=>s.jsx(ov,{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]),[C,T]=f.useState([]),A=Ge.useReactTable({data:t,state:{sorting:C},onSortingChange:T,columns:j,getCoreRowModel:Ge.getCoreRowModel(),getSortedRowModel:Ge.getSortedRowModel()}),{rows:L}=A.getRowModel(),Y=f.useRef(null),se=L.length,Q=se>0,ie=Q?n-22:n,ue=Q?22:0;return $.useWhyDidYouUpdate("VizTableComponent",{queryData:t,width:e,height:n,conf:r,context:i,instance:o,finalColumns:x,getCellContext:m,tableColumns:j,table:A,rows:L,tableContainerRef:Y}),s.jsxs("div",{ref:Y,style:{height:n,width:e,padding:"0 5px"},"data-enable-scrollbar":!0,className:p(h.root,{"table-highlight-on-hover":r.highlightOnHover}),children:[se>0&&s.jsx(a.Box,{className:h.info_bar,sx:{height:22},children:s.jsxs(a.Text,{align:"right",pr:6,size:14,color:"dimmed",fw:"normal",children:["Total: ",se]})}),s.jsxs(a.Table,{sx:{...Zj,maxHeight:ie},...d,striped:r.striped,children:[s.jsx("thead",{className:h.thead,style:{top:ue},children:A.getHeaderGroups().map(fe=>s.jsx("tr",{children:fe.headers.map(kt=>s.jsx("th",{style:{width:kt.getSize()},children:s.jsx(Uj,{header:kt,cx:p})},kt.id))},fe.id))}),s.jsx(lv,{tableContainerRef:Y,rows:L})]})]})}function mv({data:t,width:e,height:n,conf:r,context:i,instance:o}){const{id_field:l,use_raw_columns:c,columns:u}=r,d=f.useMemo(()=>{if(!l)return[];const h=D(l);return t[h.queryID]},[t,l]);return!Array.isArray(d)||d.length===0?s.jsx(a.Text,{color:"gray",align:"center",children:"Empty Data"}):s.jsx(gv,{queryData:d,width:e,height:n,conf:r,context:i,instance:o})}function yv({context:t,instance:e}){const n=t.data,{height:r,width:i}=t.viewport,{value:o}=O(t.instanceData,"config");return o?o.id_field?s.jsx(mv,{data:n,width:i,height:r,conf:o,context:t,instance:e}):s.jsx(a.Text,{color:"red",align:"center",children:"ID Field is not set, can't render a table without it"}):null}const no=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)"}}}})),bv=[{from:0,to:0},{from:100,to:100}];class jv{constructor(){z(this,"steps",new Map);z(this,"interpolation");z(this,"onChange");W.makeAutoObservable(this,{steps:W.observable},{deep:!1}),W.reaction(()=>W.toJS(this.steps),()=>{this.notifyStepChange()})}setSteps(e){for(const n of e)this.steps.set(n.to,n.from)}notifyStepChange(){var e;(e=this.onChange)==null||e.call(this,Array.from(this.steps.entries()).map(([n,r])=>({to:n,from:r})).sort((n,r)=>n.to-r.to||n.from-r.from))}fromProps(e){e.steps.length<2?this.setSteps(bv):this.setSteps(e.steps),this.interpolation=e.interpolation,this.onChange=e.onChange}changeStep(e,n){e==null?this.steps.delete(n):this.steps.set(n,e)}getStepFromValue(e){return this.steps.get(e)}}function vv(t){const{onChange:e,color:n,index:r,value:i}=t,{classes:o}=no(),[l,c]=f.useState(i),[u,{setTrue:d,setFalse:h}]=$.useBoolean(!1),p=r%2===1,x=p&&i!=null,m=!p&&i!=null,j=`map ${i} to color ${r}`,C=()=>{c(i),h()},T=()=>{h(),e==null||e(l)},A=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:A}),s.jsxs(a.Popover,{width:200,trapFocus:!0,opened:u,onClose:h,children:[s.jsx(a.Popover.Target,{children:s.jsx("div",{"data-testid":"palette-item-target",className:"palette-item",onClick:d,style:{"--shadow-color":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:C,children:"Cancel"}),s.jsx(a.Button,{"data-testid":"palette-item-ok",size:"xs",onClick:T,children:"OK"})]})]})})]}),s.jsx(a.Text,{title:j,style:{opacity:m?1:0},color:"dimmed",size:"sm",className:"palette-value--bottom palette-value",children:A})]})}const wv=S.observer(({model:t})=>{const{classes:e}=no(),n=y.range(0,13,1).map(r=>100/12*r).map(r=>[t.interpolation.getColor(r),r]);return s.jsx("div",{className:e.palette,children:n.map(([r,i],o)=>s.jsx(vv,{index:o,color:r,value:t.getStepFromValue(i),onChange:l=>t.changeStep(l,i)},r))})}),Cv=S.observer(function(e){const n=$.useCreation(()=>new jv,[]);return f.useEffect(()=>{n.fromProps(e)}),n.interpolation==null?null:s.jsx(wv,{model:n})}),Sv=t=>{const{value:e,onChange:n,colorManager:r}=t,i=r.getColorInterpolations(),[o,l]=f.useState(e),c=r.decodeInterpolation(o.interpolation)||i[0],[u,{setTrue:d,setFalse:h}]=$.useBoolean(),p=i.map(T=>({label:T.displayName,value:r.encodeColor(T),group:T.category}));function x(T){T&&l(A=>({...A,interpolation:T}))}const m=()=>{h(),n==null||n(W.toJS(o))};function j(T){l(A=>({...A,steps:T}))}const C=()=>{h(),l(e)};return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"outline",onClick:d,children:c==null?void 0:c.displayName}),s.jsx(a.Modal,{size:508,title:"Setup color interpolation",opened:u,onClose:h,zIndex:320,children:u&&s.jsxs(a.Stack,{"data-testid":"color-interpolation-modal",children:[s.jsx(a.Select,{label:"Color style",value:o.interpolation,data:p,onChange:x,withinPortal:!0,zIndex:340,maxDropdownHeight:500}),s.jsx(Cv,{steps:o.steps,interpolation:c,onChange:j}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:C,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:m,children:"OK"})]})]})})]})},_v=["static","interpolation","none"].map(t=>({label:y.capitalize(t),value:t})),kv=[{from:0,to:0},{from:100,to:100}];function so(t){return t?y.isString(t)?t==="none"?"none":"static":"interpolation":"none"}function Tv(t,e){var n;return so(e)==="static"?e:(n=t.getStaticColors()[0])==null?void 0:n.value}function Iv(t,e){return y.isObject(e)?e:{steps:kv,interpolation:t.encodeColor(t.getColorInterpolations()[0])}}const Dv=f.forwardRef((t,e)=>{const{colorManager:n}=f.useContext(et),[r,i]=f.useState(so(t.value)),[o,l]=f.useState(Tv(n,t.value)),c=$.useLatest(o),[u,d]=f.useState(Iv(n,t.value)),h=$.useLatest(u),p=j=>{var C,T,A;i(j||"none"),j==="static"?(C=t.onChange)==null||C.call(t,c.current):j==="none"||!j?(T=t.onChange)==null||T.call(t,"none"):(A=t.onChange)==null||A.call(t,h.current)},x=j=>{var C;l(j),(C=t.onChange)==null||C.call(t,j)},m=j=>{var C;d(j),(C=t.onChange)==null||C.call(t,j)};return s.jsxs(a.Stack,{align:"stretch",children:[s.jsx(a.Select,{label:"Cell background",value:r||"none",onChange:p,data:_v}),r==="static"&&s.jsx(Se,{value:o,onChange:x}),r==="interpolation"&&s.jsx(Sv,{colorManager:n,value:u,onChange:m})]})}),Mv={[Ye.eloc]:"ELOC"},Av=Object.values(Ye).map(t=>({label:y.get(Mv,t,y.capitalize(t)),value:t})),zv=f.forwardRef(({label:t,value:e,onChange:n,sx:r},i)=>s.jsx(a.Select,{ref:i,label:t,data:Av,value:e,onChange:n,sx:r})),Ev=f.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:i,setFalse:o}]=$.useBoolean(),[l,c]=f.useState(t),u=()=>{o(),e(l)},d=()=>{o(),c(t)},h=()=>{c(Ja)};return f.useEffect(()=>{c(t)},[t]),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:p=>c(p??""),theme:"vs-dark",options:{minimap:{enabled:!1}}})}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:h,color:"red",leftIcon:s.jsx(_.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"})]})]})]})})]})}),Pv=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],cr=()=>s.jsx(a.Text,{color:"dimmed",size:12,children:"px"}),Lv=({control:t,index:e,watch:n,remove:r,column:i})=>{const o=n(`columns.${e}.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.${e}.label`,control:t,render:({field:l})=>s.jsx(a.TextInput,{label:"Label",required:!0,id:`col-label-${e}`,sx:{flex:1},...l})}),s.jsx(b.Controller,{name:`columns.${e}.value_field`,control:t,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.${e}.value_type`,control:t,render:({field:l})=>s.jsx(zv,{label:"Value Type",sx:{flex:1},...l})}),o===Ye.custom&&s.jsx(b.Controller,{name:`columns.${e}.func_content`,control:t,render:({field:l})=>s.jsx(Ev,{value:l.value??Ja,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(cr,{}),disabled:!0}),s.jsx(b.Controller,{name:`columns.${e}.width`,control:t,render:({field:l})=>s.jsx(a.NumberInput,{hideControls:!0,label:"Width",rightSection:s.jsx(cr,{}),...l})}),s.jsx(a.NumberInput,{hideControls:!0,label:"Max Width",rightSection:s.jsx(cr,{}),disabled:!0})]}),s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:`columns.${e}.align`,control:t,render:({field:l})=>s.jsx(a.Select,{label:"Alignment",data:Pv,...l})})}),s.jsx(b.Controller,{name:`columns.${e}.cellBackgroundColor`,control:t,render:({field:l})=>s.jsx(Dv,{...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(e),children:"Delete this column"})]})},Bv=({control:t,watch:e})=>{const{fields:n,append:r,remove:i,update:o}=b.useFieldArray({control:t,name:"columns"}),l=()=>{const u=pe.randomId();r({id:u,label:u,align:"center",value_field:"",value_type:Ye.string,width:""})};e("columns");const c=e("use_raw_columns");return s.jsxs(s.Fragment,{children:[s.jsx(b.Controller,{name:"use_raw_columns",control:t,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(Lv,{control:t,watch:e,index:d,column:u,remove:i})},u.id))]})})]})};function Ov({control:t,watch:e}){return e(["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:t,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:t,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:t,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:t,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:t,render:({field:n})=>s.jsx(a.Switch,{label:"Highlight on hover",checked:n.value,onChange:r=>n.onChange(r.currentTarget.checked)})})]})]})}function $v({columns:t,...e}){return{...e,columns:t.map(({id:n,...r})=>({id:n??pe.randomId(),...r}))}}function Vv({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},e,Za),[e]),i=f.useMemo(()=>$v(r),[r]);f.useEffect(()=>{!y.isEqual(r,i)&&(console.log("config malformed, resetting to defaults",r,i),n(i))},[r,i]);const{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=b.useForm({defaultValues:i});f.useEffect(()=>{d(i)},[i]);const h=u(),p=f.useMemo(()=>!y.isEqual(h,r),[h,r]);return c(["id_field"]),s.jsxs("form",{onSubmit:l(n),children:[s.jsxs(a.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Table Config"}),s.jsx(a.ActionIcon,{type:"submit","aria-label":"save config",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(_.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(Bv,{control:o,watch:c})]}),s.jsx(a.Tabs.Panel,{value:"Style",children:s.jsx(Ov,{control:o,watch:c})})]})]})}function Nv(t){const{columns:e,...n}=t;return{...t,columns:e.map(r=>({...r,align:r.align??"left"}))}}function qv(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{id_field:i,columns:o,...l}=t;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 Fv(t){const{columns:e,...n}=t;return{...n,columns:e.map(r=>({...r,align:r.align??"left",cellBackgroundColor:r.cellBackgroundColor??"",width:r.width??""}))}}class Gv extends re{constructor(){super(...arguments);z(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??pe.randomId(),...l}))}}}),this.version(3,n=>({...n,version:3,config:Nv(n.config)})),this.version(4,(n,r)=>({...n,version:4,config:qv(n.config,r)})),this.version(5,n=>({...n,version:5,config:Fv(n.config)}))}}const ur={createConfig(){return{version:5,config:y.cloneDeep(Za)}},displayName:"Table",displayGroup:"Others",migrator:new Gv,name:"table",viewRender:yv,configRender:Vv,triggers:[lr]},ro=["function text({ data, variables, filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
297
- `),dr={func_content:ro,horizontal_align:"left",font_size:"14px",font_weight:"normal"},Wv=S.observer(({context:t})=>{const e=oe(),{value:n=dr}=O(t.instanceData,"config"),{variables:r}=t,i=t.data,{func_content:o,horizontal_align:l,font_size:c,font_weight:u}=n,d=f.useMemo(()=>r.reduce((p,x)=>{const m=at(x,i);return p[x.name]=qe(x,m),p},{}),[r,i]),h=f.useMemo(()=>new Function(`return ${o}`)()({data:i,variables:d,filters:e.payloadForSQL.filters,context:e.payloadForSQL.context}),[o,i,d,e.payloadForSQL]);return s.jsx(a.Text,{align:l,weight:u,sx:{fontSize:c},children:h})}),Rv=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return s.jsx(a.Box,{sx:{position:"relative"},children:s.jsx(me,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Qv=f.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:i,setFalse:o}]=$.useBoolean(),[l,c]=f.useState(t),u=()=>{o(),e(l)},d=()=>{o(),c(t)},h=()=>{c(ro)};return f.useEffect(()=>{c(t)},[t]),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(Rv,{value:l,onChange:c}),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"})]})]})]})})]})}),Yv=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}];function Kv({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},e,dr),[e]),i=f.useMemo(()=>{const{func_content:x,horizontal_align:m,font_size:j,font_weight:C}=r;return{func_content:x,horizontal_align:m,font_size:j,font_weight:C}},[r]);f.useEffect(()=>{!y.isEqual(r,i)&&(console.log("config malformed, resetting to defaults",r,i),n(i))},[r,i]);const{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=b.useForm({defaultValues:i});f.useEffect(()=>{d(i)},[i]),c(["func_content","horizontal_align","font_size","font_weight"]);const h=u(),p=f.useMemo(()=>!y.isEqual(h,r),[h,r]);return s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:l(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{weight:500,children:"Configurations"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(_.DeviceFloppy,{size:20})})]}),s.jsxs(a.Stack,{spacing:10,children:[s.jsx(b.Controller,{name:"func_content",control:o,render:({field:x})=>s.jsx(Qv,{...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:Yv,...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(ma,{label:"Font Weight",...x})})})]})]})})}class Uv extends re{constructor(){super(...arguments);z(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const Xv={displayName:"Text",displayGroup:"Others",migrator:new Uv,name:"text",viewRender:Wv,configRender:Kv,createConfig(){return{version:1,config:y.cloneDeep(dr)}}},Jv=()=>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 io(t,e){const n=y.get(t,e,"");if(n)throw new Error(n)}async function Zv(t,e,n,r={}){const i={"X-Requested-With":"XMLHttpRequest","Content-Type":r.string?"application/x-www-form-urlencoded":"application/json",...r.headers},o={baseURL:t,method:"POST",url:e,params:r.params,headers:i};return o.data=r.string?JSON.stringify(n):n,tt(o).then(l=>l.data).catch(l=>Promise.reject(l))}const Hv=({conf:t,panelData:e})=>async()=>{const{expertSystemURL:n,path:r,goal:i,question:o}=t;if(!r||!i||!o)return;const l=Mu(e);if(!l)return;const c={dashboard:i,panel:o,data:l};try{const u=n.startsWith("http")?n:window.location.origin;return await Zv(u,`/expert/v3/devtable/${r}`,c,{})}catch(u){throw io(u,"response.data.detail"),io(u,"response.data.error"),console.error(u),u}},pr={expertSystemURL:"",path:"",goal:"",question:""},hr={height:"100%",overflowY:"auto",...ks},ao=({message:t})=>s.jsx(a.Box,{sx:hr,children:s.jsx("div",{dangerouslySetInnerHTML:{__html:t},style:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45"}})}),ew=({error:t,width:e,height:n})=>{const r=t.message;if(r.startsWith("<"))return s.jsx(ao,{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(Jv,{}),s.jsx(ao,{message:r})]})})};function tw({context:t}){const{value:e}=O(t.instanceData,"config"),n=f.useMemo(()=>y.defaultsDeep({},e,pr),[e]),{width:r,height:i}=t.viewport,o=t.data,{data:l,error:c,loading:u}=$.useRequest(Hv({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:hr,"data-enable-scrollbar":!0,children:s.jsx(ew,{error:c,width:r,height:i})}):!l||!Array.isArray(l.replies)||l.replies.length===0?null:s.jsx(a.Box,{sx:hr,"data-enable-scrollbar":!0,children:l.replies.map((d,h)=>s.jsx("div",{dangerouslySetInnerHTML:{__html:d.interpretation.html}},h))})}function nw({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},e,pr),[e]),{control:i,handleSubmit:o,watch:l,getValues:c,reset:u}=b.useForm({defaultValues:r});f.useEffect(()=>{u(r)},[r]),l(["expertSystemURL","goal","path","question"]);const d=c(),h=f.useMemo(()=>!y.isEqual(d,r),[d,r]);return s.jsx("form",{onSubmit:o(n),children:s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:"expertSystemURL",control:i,render:({field:p})=>s.jsx(a.TextInput,{label:"Expert System URL",...p})}),s.jsx(b.Controller,{name:"path",control:i,render:({field:p})=>s.jsx(a.TextInput,{label:"Path",required:!0,...p})})]}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(b.Controller,{name:"goal",control:i,render:({field:p})=>s.jsx(a.TextInput,{label:"Goal",required:!0,...p})}),s.jsx(b.Controller,{name:"question",control:i,render:({field:p})=>s.jsx(a.TextInput,{label:"Question",required:!0,...p})})]}),s.jsx(a.Divider,{variant:"dashed",mt:16,mb:8}),s.jsx(a.Button,{type:"submit",variant:"filled",color:"blue",leftIcon:s.jsx(_.DeviceFloppy,{size:20}),disabled:!h,sx:{alignSelf:"flex-end"},children:"Submit Changes"})]})})}class sw extends re{constructor(){super(...arguments);z(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const rw={displayName:"Merico GQM",displayGroup:"Merico suite",migrator:new sw,name:"mericoGQM",viewRender:tw,configRender:nw,createConfig(){return{version:1,config:y.cloneDeep(pr)}}};function iw(t,e,n){if(!t)return n[0];try{return[e,V(e).add(1,"year").subtract(1,"day").valueOf()]}catch(r){return console.error(r),n[0]}}function aw(t,e,n){const r=iw(t,e,n);return{top:50,left:25,right:5,cellSize:["auto",13],range:r,itemStyle:{borderColor:"#eee"},splitLine:{show:!0},dayLabel:{firstDay:1},monthLabel:{position:"end"},yearLabel:{show:!0}}}function ow(t){return{heat_block:function(r){if(!t.heat_block.value_formatter)return r;try{return F(r).format(t.heat_block.value_formatter)}catch(i){return console.error(i),r}}}}function lw(t,e){return{show:!t,selectedMode:"single",top:5,right:5,data:e.map(n=>({name:n,icon:"circle"}))}}function cw(t,e,n,r){const{calendar:i,heat_block:o}=t,l=D(i.data_key),c=D(o.data_key);return e?{type:"heatmap",name:"heatmap",coordinateSystem:"calendar",calendarIndex:0,data:r[l.queryID].map(u=>[y.get(u,l.columnKey),y.get(u,c.columnKey)])}:Object.entries(n).map(([u,d])=>({type:"heatmap",name:u,coordinateSystem:"calendar",calendarIndex:0,data:d.map(h=>[y.get(h,l.columnKey),y.get(h,c.columnKey)])}))}const uw=t=>{try{return F(t).format({trimMantissa:!0,mantissa:2})}catch{return t}};function dw({conf:t,valueFormatters:e,dataDict:n,params:r}){const{value:i}=r,[o,l]=i,u=[{label:t.heat_block.name,value:e.heat_block(l),style:{label:"",value:""}}],d=n[o];return d&&t.tooltip.metrics.forEach(h=>{const p=D(h.data_key);u.push({label:h.name,value:uw(y.get(d,p.columnKey,"")),style:{label:"",value:""}})}),u}function pw(t,e,n){const r=D(t.calendar.data_key),i=y.keyBy(e[r.queryID],r.columnKey);return{confine:!0,formatter:function(o){const c=dw({conf:t,valueFormatters:n,dataDict:i,params:o}).map(h=>`
295
+ `}}function Tj(){return{show:!0,trigger:"item",confine:!0,formatter:kj()}}const Ij={tooltip:{show:!0},series:{type:"sunburst",radius:[0,"90%"],emphasis:{focus:"ancestor"}}};function Dj(t,e,n){n.reduce((o,l)=>{const c=it(l,e);return o[l.name]=Ne(l,c),o},{});const i={series:{data:Cj(t,e),levels:_j(t)},tooltip:Tj()};return y.defaultsDeep({},i,Ij)}Y.use([te.SunburstChart,we.CanvasRenderer]);function Mj({context:t}){const{variables:e}=t,{value:n}=O(t.instanceData,"config"),r=f.useMemo(()=>y.defaults({},n,or),[n]),i=t.data,{width:o,height:l}=t.viewport,c=f.useMemo(()=>Dj(r,i,e),[r,i,e]);return!o||!l?null:s.jsx(Te,{width:o,height:l,children:s.jsx(ve,{echarts:Y,option:c,style:Wt(o,l),notMerge:!0,theme:"merico-light"})})}function Aj({control:t,watch:e}){return e(["label_key","value_key","group_key"]),s.jsxs(a.Stack,{children:[s.jsx(b.Controller,{name:"label_key",control:t,render:({field:n})=>s.jsx(B,{label:"Label Key",required:!0,...n})}),s.jsx(b.Controller,{name:"value_key",control:t,render:({field:n})=>s.jsx(B,{label:"Value Key",required:!0,...n})}),s.jsx(b.Controller,{name:"group_key",control:t,render:({field:n})=>s.jsx(B,{label:"Group Key",clearable:!0,...n})})]})}const zj=[{label:"Radial",value:"radial"},{label:"Tangential",value:"tangential"},{label:"None",value:"0"}],Ej=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Pj=({control:t,index:e,remove:n})=>s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`levels.${e}.r0`,control:t,render:({field:r})=>s.jsx(a.TextInput,{label:"Inside Radius",placeholder:"0%",...r})}),s.jsx(b.Controller,{name:`levels.${e}.r`,control:t,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.${e}.label.show_label_tolerance`,control:t,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.${e}.label.rotate`,control:t,render:({field:r})=>s.jsx(a.Select,{label:"Rotate",data:zj,...r})}),s.jsx(b.Controller,{name:`levels.${e}.label.align`,control:t,render:({field:r})=>s.jsx(a.Select,{label:"Align",data:Ej,...r})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`levels.${e}.label.position`,control:t,render:({field:r})=>s.jsx(Zs,{label:"Position",...r})}),s.jsx(b.Controller,{name:`levels.${e}.label.padding`,control:t,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(e),sx:{top:15,right:5},children:"Delete this Level"})]}),Lj=({control:t,watch:e})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:t,name:"levels"}),o=e("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}}),u=e("levels.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 ring style on each level"})]}),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: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(Pj,{control:t,index:x,remove:i},h.id)},h.id))]})]})};function Bj({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},e,or),[e]),i=f.useMemo(()=>y.clone(r),[r]),{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=b.useForm({defaultValues:i});f.useEffect(()=>{d(i)},[i]);const p=u(),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(Aj,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Levels",children:s.jsx(Lj,{control:o,watch:c})})]})]})})}function Oj(t){const{label_field:e,value_field:n,...r}=t;return{...r,label_key:e,value_key:n}}function $j(t){const{group_key:e="",...n}=t;return{...n,group_key:e}}function Vj(t){const{levels:e=[],...n}=t;return{...n,levels:e}}function Nj(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{label_key:i,value_key:o,group_key:l,...c}=t;return{...c,label_key:r(i),value_key:r(o),group_key:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class qj extends re{constructor(){super(...arguments);z(this,"VERSION",5)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:Oj(n.config)})),this.version(3,n=>({...n,version:3,config:$j(n.config)})),this.version(4,n=>({...n,version:4,config:Vj(n.config)})),this.version(5,(n,r)=>({...n,version:5,config:Nj(n.config,r)}))}}const Fj={displayName:"Sunburst Chart",displayGroup:"ECharts-based charts",migrator:new qj,name:"sunburst",viewRender:Mj,configRender:Bj,createConfig(){return{version:5,config:y.cloneDeep(or)}}};var Ue=(t=>(t.string="string",t.number="number",t.eloc="eloc",t.percentage="percentage",t.custom="custom",t))(Ue||{});const Ja=["function text({ value }) {"," // your code goes here"," return value","}"].join(`
296
+ `),Za={columns:[],fontSize:"14px",highlightOnHover:!0,horizontalSpacing:"14px",id_field:"",striped:!0,use_raw_columns:!0,verticalSpacing:"14px"},Ha={left:"flex-start",center:"center",right:"flex-end"},Gj=({header:t,cx:e})=>{const n=y.get(t.column.columnDef.meta,"align","left");return s.jsxs(a.Text,{className:e("table-head-cell",{"table-head-cell--sortable":t.column.getCanSort()}),onClick:t.column.getToggleSortingHandler(),align:n,sx:{justifyContent:Ha[n]},children:[t.isPlaceholder?null:Ge.flexRender(t.column.columnDef.header,t.getContext()),s.jsx(Wj,{direction:t.column.getIsSorted()})]})},Wj=({direction:t})=>{switch(t){case"asc":return s.jsx(k.IconArrowUp,{size:16});case"desc":return s.jsx(k.IconArrowDown,{size:"1em"});default:return null}},Rj=a.createStyles(t=>({root:{overflow:"auto",position:"relative","& .table-head-cell":{display:"flex",flexFlow:"row nowrap",alignItems:"center",whiteSpace:"nowrap","&.table-head-cell--sortable":{cursor:"pointer",userSelect:"none"}},"&.table-highlight-on-hover tr":{transition:"background-color 0.2s","&:hover":{backgroundColor:t.colorScheme==="dark"?t.colors.dark[5]:t.colors.gray[0]}}},thead:{background:t.colorScheme==="dark"?t.colors.dark[7]:t.white,position:"sticky",top:24,transform:"translateY(-1px)",zIndex:10},info_bar:{position:"sticky",top:0,left:0,right:0,zIndex:10,background:"white"}})),Qj={tableLayout:"fixed","thead, tbody":{tr:{"th, td":{padding:"2px 10px",div:{overflow:"hidden",textOverflow:"ellipsis"},"&:first-of-type":{paddingLeft:2,paddingRight:2}}}}},Uj=a.createStyles((t,e)=>({content:{display:"flex",alignItems:"center",justifyContent:Ha[e.align],".table-cell-text":{whiteSpace:"nowrap",cursor:e.clickable?"pointer":"default",textDecoration:e.clickable?"underline":"none"}}}));function Yj(t){return t?nt(t).oklch()[0]>.7?"black":"white":"inherit"}function Kj(t){const e=t.tableCellContext.bgColor;return{backgroundColor:e,color:Yj(e)}}function Ot(t){const e=t.tableCellContext.isClickable(),n=Uj({clickable:e,align:t.align});return s.jsx("div",{className:n.classes.content,style:{...Kj(t)},children:s.jsx(a.Text,{className:"table-cell-text",onClick:t.tableCellContext.getClickHandler(),children:s.jsx("span",{title:t.children,children:t.children})})})}function Xj(t){return s.jsx(Ot,{...t,children:t.value})}function Jj(t){const e=F(t.value).format({average:!0,mantissa:2,trimMantissa:!0});return s.jsx(Ot,{...t,children:e})}function Zj(t){const e=F(t.value).format({thousandSeparated:!0});return s.jsx(Ot,{...t,children:e})}function Hj(t){const e=F(t.value).format({output:"percent",mantissa:3,trimMantissa:!0});return s.jsx(Ot,{...t,children:e})}function ev(t){const e=t.value,n=t.func_content;if(!n)return s.jsx(Ot,{...t,children:e});const r=new Function(`return ${n}`)()({value:e});return s.jsx(Ot,{...t,children:r})}function tv(t){switch(t.type){case Ue.string:return s.jsx(Xj,{...t});case Ue.eloc:return s.jsx(Jj,{...t});case Ue.number:return s.jsx(Zj,{...t});case Ue.percentage:return s.jsx(Hj,{...t});case Ue.custom:return s.jsx(ev,{...t})}}function nv({tableContainerRef:t,rows:e}){var c,u;const n=xc.useVirtual({parentRef:t,size:e.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 $.useWhyDidYouUpdate("TableBody",{tableContainerRef:t,rows:e}),s.jsxs("tbody",{children:[o>0&&s.jsx("tr",{children:s.jsx("td",{style:{height:`${o}px`}})}),r.map(d=>{const p=e[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 lr={id:"builtin:table:click-cell-content",displayName:"Click Cell Content",nameRender:av,configRender:rv,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"}]},sv={column:""};function eo(t,e){const{value:n}=O(t.instanceData,"config"),r={columnsFromConfig:[],columnsFromData:[]};if(n&&(r.columnsFromConfig=n.columns.map((i,o)=>({label:i.label,value:o.toString()}))),!e)return r;if(n!=null&&n.id_field){const i=Rt(e,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 rv(t){const{columnsFromConfig:e,columnsFromData:n}=eo(t.instance,t.sampleData),r=e.length>0?e:n,{value:i,set:o}=O(t.trigger.triggerData,"config"),{column:l}=y.defaults({},i,sv),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 iv(t,e){return t?y.isNumber(t.column)?`Click cell of ${e[t.column].label}`:`Click cell of ${t.column}`:"Click cell content (click to config)"}function av(t){const{columnsFromConfig:e}=eo(t.instance),{value:n}=O(t.trigger.triggerData,"config");return s.jsx(a.Text,{children:iv(n,e)})}function to(t,e,n){return Math.min(Math.max(t,e),n)}class ov{constructor(e){this.steps=e;const n=[],r=new Set;for(const i of e)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(e,n){const r=(n.to-e.to)/(n.from-e.from),i=e.to-r*e.from;return o=>r*o+i}getStepFunctionForValue(e){let n=y.findLastIndex(this.steps,r=>r.from<=e);return n=to(n,0,this.steps.length-2),this.getLinearFunction(this.steps[n],this.steps[n+1])}mapValue(e){return to(this.getStepFunctionForValue(e)(e),0,100)}}class lv{constructor(e,n,r,i,o){this.getColIndex=e,this.cell=n,this.triggers=r,this.interactionManager=i,this.colorManager=o}getClickHandler(){const e=this.getRelatedTrigger();if(e.length!==0)return()=>{const n={row_data:this.cell.row.original,row_index:this.cell.row.index,col_index:this.getColIndex(this.cell)};for(const r of e)this.interactionManager.runInteraction(r.id,n)}}getRelatedTrigger(){return this.triggers.filter(n=>n.schemaRef===lr.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 e=this.columnConf.cellBackgroundColor;if(!e||e==="none")return;if(y.isString(e))return e;const n=+this.cell.getValue();if(isFinite(n)){const r=this.colorManager.decodeInterpolation(e.interpolation),o=new ov(e.steps).mapValue(n);return r==null?void 0:r.getColor(o)}}}const cv=t=>{const e=Ve(t),n=$e(e.triggerManager,lr.id),{colorManager:r}=f.useContext(et);return f.useCallback(i=>new lv(t.getColIndex,i,n,e,r),[n,e,t.getColIndex])};function uv({queryData:t,width:e,height:n,conf:r,context:i,instance:o}){const{id_field:l,use_raw_columns:c,columns:u,...d}=r,{classes:p,cx:h}=Rj(),x=f.useMemo(()=>c?!Array.isArray(t)||t.length===0?[]:Object.keys(t[0]).map(fe=>({id:fe,label:fe,value_field:fe,value_type:Ue.string,align:"left",width:"",cellBackgroundColor:""})):u,[c,u,t]),m=cv({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(Ye=>{const Nr=Iu(Ye.value_field);return fe.accessor(Nr.columnKey,{cell:rn=>s.jsx(tv,{tableCellContext:m(rn.cell),value:rn.getValue(),type:Ye.value_type,...Ye}),header:Ye.label,enableSorting:!0,meta:Ye,size:typeof Ye.width=="number"?Ye.width:void 0,minSize:typeof Ye.width=="number"?Ye.width:void 0})})},[x,m]),[C,T]=f.useState([]),A=Ge.useReactTable({data:t,state:{sorting:C},onSortingChange:T,columns:j,getCoreRowModel:Ge.getCoreRowModel(),getSortedRowModel:Ge.getSortedRowModel()}),{rows:L}=A.getRowModel(),U=f.useRef(null),se=L.length,Q=se>0,ie=Q?n-22:n,ue=Q?22:0;return $.useWhyDidYouUpdate("VizTableComponent",{queryData:t,width:e,height:n,conf:r,context:i,instance:o,finalColumns:x,getCellContext:m,tableColumns:j,table:A,rows:L,tableContainerRef:U}),s.jsxs("div",{ref:U,style:{height:n,width:e,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:{...Qj,maxHeight:ie},...d,striped:r.striped,children:[s.jsx("thead",{className:p.thead,style:{top:ue},children:A.getHeaderGroups().map(fe=>s.jsx("tr",{children:fe.headers.map(kt=>s.jsx("th",{style:{width:kt.getSize()},children:s.jsx(Gj,{header:kt,cx:h})},kt.id))},fe.id))}),s.jsx(nv,{tableContainerRef:U,rows:L})]})]})}function dv({data:t,width:e,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=D(l);return t[p.queryID]},[t,l]);return!Array.isArray(d)||d.length===0?s.jsx(a.Text,{color:"gray",align:"center",children:"Empty Data"}):s.jsx(uv,{queryData:d,width:e,height:n,conf:r,context:i,instance:o})}function pv({context:t,instance:e}){const n=t.data,{height:r,width:i}=t.viewport,{value:o}=O(t.instanceData,"config");return o?o.id_field?s.jsx(dv,{data:n,width:i,height:r,conf:o,context:t,instance:e}):s.jsx(a.Text,{color:"red",align:"center",children:"ID Field is not set, can't render a table without it"}):null}const no=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)"}}}})),hv=[{from:0,to:0},{from:100,to:100}];class xv{constructor(){z(this,"steps",new Map);z(this,"interpolation");z(this,"onChange");W.makeAutoObservable(this,{steps:W.observable},{deep:!1}),W.reaction(()=>W.toJS(this.steps),()=>{this.notifyStepChange()})}setSteps(e){for(const n of e)this.steps.set(n.to,n.from)}notifyStepChange(){var e;(e=this.onChange)==null||e.call(this,Array.from(this.steps.entries()).map(([n,r])=>({to:n,from:r})).sort((n,r)=>n.to-r.to||n.from-r.from))}fromProps(e){e.steps.length<2?this.setSteps(hv):this.setSteps(e.steps),this.interpolation=e.interpolation,this.onChange=e.onChange}changeStep(e,n){e==null?this.steps.delete(n):this.steps.set(n,e)}getStepFromValue(e){return this.steps.get(e)}}function fv(t){const{onChange:e,color:n,index:r,value:i}=t,{classes:o}=no(),[l,c]=f.useState(i),[u,{setTrue:d,setFalse:p}]=$.useBoolean(!1),h=r%2===1,x=h&&i!=null,m=!h&&i!=null,j=`map ${i} to color ${r}`,C=()=>{c(i),p()},T=()=>{p(),e==null||e(l)},A=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:A}),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:C,children:"Cancel"}),s.jsx(a.Button,{"data-testid":"palette-item-ok",size:"xs",onClick:T,children:"OK"})]})]})})]}),s.jsx(a.Text,{title:j,style:{opacity:m?1:0},color:"dimmed",size:"sm",className:"palette-value--bottom palette-value",children:A})]})}const gv=S.observer(({model:t})=>{const{classes:e}=no(),n=y.range(0,13,1).map(r=>100/12*r).map(r=>[t.interpolation.getColor(r),r]);return s.jsx("div",{className:e.palette,children:n.map(([r,i],o)=>s.jsx(fv,{index:o,color:r,value:t.getStepFromValue(i),onChange:l=>t.changeStep(l,i)},r))})}),mv=S.observer(function(e){const n=$.useCreation(()=>new xv,[]);return f.useEffect(()=>{n.fromProps(e)}),n.interpolation==null?null:s.jsx(gv,{model:n})}),yv=t=>{const{value:e,onChange:n,colorManager:r}=t,i=r.getColorInterpolations(),[o,l]=f.useState(e),c=r.decodeInterpolation(o.interpolation)||i[0],[u,{setTrue:d,setFalse:p}]=$.useBoolean(),h=i.map(T=>({label:T.displayName,value:r.encodeColor(T),group:T.category}));function x(T){T&&l(A=>({...A,interpolation:T}))}const m=()=>{p(),n==null||n(W.toJS(o))};function j(T){l(A=>({...A,steps:T}))}const C=()=>{p(),l(e)};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(mv,{steps:o.steps,interpolation:c,onChange:j}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:C,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:m,children:"OK"})]})]})})]})},bv=["static","interpolation","none"].map(t=>({label:y.capitalize(t),value:t})),jv=[{from:0,to:0},{from:100,to:100}];function so(t){return t?y.isString(t)?t==="none"?"none":"static":"interpolation":"none"}function vv(t,e){var n;return so(e)==="static"?e:(n=t.getStaticColors()[0])==null?void 0:n.value}function wv(t,e){return y.isObject(e)?e:{steps:jv,interpolation:t.encodeColor(t.getColorInterpolations()[0])}}const Cv=f.forwardRef((t,e)=>{const{colorManager:n}=f.useContext(et),[r,i]=f.useState(so(t.value)),[o,l]=f.useState(vv(n,t.value)),c=$.useLatest(o),[u,d]=f.useState(wv(n,t.value)),p=$.useLatest(u),h=j=>{var C,T,A;i(j||"none"),j==="static"?(C=t.onChange)==null||C.call(t,c.current):j==="none"||!j?(T=t.onChange)==null||T.call(t,"none"):(A=t.onChange)==null||A.call(t,p.current)},x=j=>{var C;l(j),(C=t.onChange)==null||C.call(t,j)},m=j=>{var C;d(j),(C=t.onChange)==null||C.call(t,j)};return s.jsxs(a.Stack,{align:"stretch",children:[s.jsx(a.Select,{label:"Cell background",value:r||"none",onChange:h,data:bv}),r==="static"&&s.jsx(Se,{value:o,onChange:x}),r==="interpolation"&&s.jsx(yv,{colorManager:n,value:u,onChange:m})]})}),Sv={[Ue.eloc]:"ELOC"},_v=Object.values(Ue).map(t=>({label:y.get(Sv,t,y.capitalize(t)),value:t})),kv=f.forwardRef(({label:t,value:e,onChange:n,sx:r},i)=>s.jsx(a.Select,{ref:i,label:t,data:_v,value:e,onChange:n,sx:r})),Tv=f.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:i,setFalse:o}]=$.useBoolean(),[l,c]=f.useState(t),u=()=>{o(),e(l)},d=()=>{o(),c(t)},p=()=>{c(Ja)};return f.useEffect(()=>{c(t)},[t]),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"})]})]})]})})]})}),Iv=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],cr=()=>s.jsx(a.Text,{color:"dimmed",size:12,children:"px"}),Dv=({control:t,index:e,watch:n,remove:r,column:i})=>{const o=n(`columns.${e}.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.${e}.label`,control:t,render:({field:l})=>s.jsx(a.TextInput,{label:"Label",required:!0,id:`col-label-${e}`,sx:{flex:1},...l})}),s.jsx(b.Controller,{name:`columns.${e}.value_field`,control:t,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.${e}.value_type`,control:t,render:({field:l})=>s.jsx(kv,{label:"Value Type",sx:{flex:1},...l})}),o===Ue.custom&&s.jsx(b.Controller,{name:`columns.${e}.func_content`,control:t,render:({field:l})=>s.jsx(Tv,{value:l.value??Ja,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(cr,{}),disabled:!0}),s.jsx(b.Controller,{name:`columns.${e}.width`,control:t,render:({field:l})=>s.jsx(a.NumberInput,{hideControls:!0,label:"Width",rightSection:s.jsx(cr,{}),...l})}),s.jsx(a.NumberInput,{hideControls:!0,label:"Max Width",rightSection:s.jsx(cr,{}),disabled:!0})]}),s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:`columns.${e}.align`,control:t,render:({field:l})=>s.jsx(a.Select,{label:"Alignment",data:Iv,...l})})}),s.jsx(b.Controller,{name:`columns.${e}.cellBackgroundColor`,control:t,render:({field:l})=>s.jsx(Cv,{...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(e),children:"Delete this column"})]})},Mv=({control:t,watch:e})=>{const{fields:n,append:r,remove:i,update:o}=b.useFieldArray({control:t,name:"columns"}),l=()=>{const u=pe.randomId();r({id:u,label:u,align:"center",value_field:"",value_type:Ue.string,width:""})};e("columns");const c=e("use_raw_columns");return s.jsxs(s.Fragment,{children:[s.jsx(b.Controller,{name:"use_raw_columns",control:t,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(Dv,{control:t,watch:e,index:d,column:u,remove:i})},u.id))]})})]})};function Av({control:t,watch:e}){return e(["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:t,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:t,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:t,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:t,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:t,render:({field:n})=>s.jsx(a.Switch,{label:"Highlight on hover",checked:n.value,onChange:r=>n.onChange(r.currentTarget.checked)})})]})]})}function zv({columns:t,...e}){return{...e,columns:t.map(({id:n,...r})=>({id:n??pe.randomId(),...r}))}}function Ev({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},e,Za),[e]),i=f.useMemo(()=>zv(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(Mv,{control:o,watch:c})]}),s.jsx(a.Tabs.Panel,{value:"Style",children:s.jsx(Av,{control:o,watch:c})})]})]})}function Pv(t){const{columns:e,...n}=t;return{...t,columns:e.map(r=>({...r,align:r.align??"left"}))}}function Lv(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{id_field:i,columns:o,...l}=t;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 Bv(t){const{columns:e,...n}=t;return{...n,columns:e.map(r=>({...r,align:r.align??"left",cellBackgroundColor:r.cellBackgroundColor??"",width:r.width??""}))}}class Ov extends re{constructor(){super(...arguments);z(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??pe.randomId(),...l}))}}}),this.version(3,n=>({...n,version:3,config:Pv(n.config)})),this.version(4,(n,r)=>({...n,version:4,config:Lv(n.config,r)})),this.version(5,n=>({...n,version:5,config:Bv(n.config)}))}}const ur={createConfig(){return{version:5,config:y.cloneDeep(Za)}},displayName:"Table",displayGroup:"Others",migrator:new Ov,name:"table",viewRender:pv,configRender:Ev,triggers:[lr]},ro=["function text({ data, variables, filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
297
+ `),dr={func_content:ro,horizontal_align:"left",font_size:"14px",font_weight:"normal"},$v=S.observer(({context:t})=>{const e=oe(),{value:n=dr}=O(t.instanceData,"config"),{variables:r}=t,i=t.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:e.payloadForSQL.filters,context:e.payloadForSQL.context}),[o,i,d,e.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 Vv({label:t,value:e,onChange:n},r){var l;const[i,o]=f.useState(((l=$n.find(c=>c.label===e))==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:t}),s.jsx(a.Slider,{label:null,marks:$n,value:i,onChange:o,step:25,placeholder:"Pick a font size",mx:"1em",ref:r})]})}const io=f.forwardRef(Vv),Nv=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return s.jsx(a.Box,{sx:{position:"relative"},children:s.jsx(ge,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},qv=f.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:i,setFalse:o}]=$.useBoolean(),[l,c]=f.useState(t),u=()=>{o(),e(l)},d=()=>{o(),c(t)},p=()=>{c(ro)};return f.useEffect(()=>{c(t)},[t]),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(Nv,{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"})]})]})]})})]})}),Fv=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}];function Gv({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},e,dr),[e]),i=f.useMemo(()=>{const{func_content:x,horizontal_align:m,font_size:j,font_weight:C}=r;return{func_content:x,horizontal_align:m,font_size:j,font_weight:C}},[r]);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(qv,{...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:Fv,...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(io,{label:"Font Weight",...x})})})]})]})})}class Wv extends re{constructor(){super(...arguments);z(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const Rv={displayName:"Text",displayGroup:"Others",migrator:new Wv,name:"text",viewRender:$v,configRender:Gv,createConfig(){return{version:1,config:y.cloneDeep(dr)}}},Qv=()=>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 ao(t,e){const n=y.get(t,e,"");if(n)throw new Error(n)}async function Uv(t,e,n,r={}){const i={"X-Requested-With":"XMLHttpRequest","Content-Type":r.string?"application/x-www-form-urlencoded":"application/json",...r.headers},o={baseURL:t,method:"POST",url:e,params:r.params,headers:i};return o.data=r.string?JSON.stringify(n):n,tt(o).then(l=>l.data).catch(l=>Promise.reject(l))}const Yv=({conf:t,panelData:e})=>async()=>{const{expertSystemURL:n,path:r,goal:i,question:o}=t;if(!r||!i||!o)return;const l=Du(e);if(!l)return;const c={dashboard:i,panel:o,data:l};try{const u=n.startsWith("http")?n:window.location.origin;return await Uv(u,`/expert/v3/devtable/${r}`,c,{})}catch(u){throw ao(u,"response.data.detail"),ao(u,"response.data.error"),console.error(u),u}},pr={expertSystemURL:"",path:"",goal:"",question:""},hr={height:"100%",overflowY:"auto",...Ps},oo=({message:t})=>s.jsx(a.Box,{sx:hr,children:s.jsx("div",{dangerouslySetInnerHTML:{__html:t},style:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45"}})}),Kv=({error:t,width:e,height:n})=>{const r=t.message;if(r.startsWith("<"))return s.jsx(oo,{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(Qv,{}),s.jsx(oo,{message:r})]})})};function Xv({context:t}){const{value:e}=O(t.instanceData,"config"),n=f.useMemo(()=>y.defaultsDeep({},e,pr),[e]),{width:r,height:i}=t.viewport,o=t.data,{data:l,error:c,loading:u}=$.useRequest(Yv({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:hr,"data-enable-scrollbar":!0,children:s.jsx(Kv,{error:c,width:r,height:i})}):!l||!Array.isArray(l.replies)||l.replies.length===0?null:s.jsx(a.Box,{sx:hr,"data-enable-scrollbar":!0,children:l.replies.map((d,p)=>s.jsx("div",{dangerouslySetInnerHTML:{__html:d.interpretation.html}},p))})}function Jv({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},e,pr),[e]),{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 Zv extends re{constructor(){super(...arguments);z(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const Hv={displayName:"Merico GQM",displayGroup:"Merico suite",migrator:new Zv,name:"mericoGQM",viewRender:Xv,configRender:Jv,createConfig(){return{version:1,config:y.cloneDeep(pr)}}};function ew(t,e,n){if(!t)return n[0];try{return[e,V(e).add(1,"year").subtract(1,"day").valueOf()]}catch(r){return console.error(r),n[0]}}function tw(t,e,n){const r=ew(t,e,n);return{top:50,left:25,right:5,cellSize:["auto",13],range:r,itemStyle:{borderColor:"#eee"},splitLine:{show:!0},dayLabel:{firstDay:1},monthLabel:{position:"end"},yearLabel:{show:!0}}}function nw(t){return{heat_block:function(r){if(!t.heat_block.value_formatter)return r;try{return F(r).format(t.heat_block.value_formatter)}catch(i){return console.error(i),r}}}}function sw(t,e){return{show:!t,selectedMode:"single",top:5,right:5,data:e.map(n=>({name:n,icon:"circle"}))}}function rw(t,e,n,r){const{calendar:i,heat_block:o}=t,l=D(i.data_key),c=D(o.data_key);return e?{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 iw=t=>{try{return F(t).format({trimMantissa:!0,mantissa:2})}catch{return t}};function aw({conf:t,valueFormatters:e,dataDict:n,params:r}){const{value:i}=r,[o,l]=i,u=[{label:t.heat_block.name,value:e.heat_block(l),style:{label:"",value:""}}],d=n[o];return d&&t.tooltip.metrics.forEach(p=>{const h=D(p.data_key);u.push({label:p.name,value:iw(y.get(d,h.columnKey,"")),style:{label:"",value:""}})}),u}function ow(t,e,n){const r=D(t.calendar.data_key),i=y.keyBy(e[r.queryID],r.columnKey);return{confine:!0,formatter:function(o){const c=aw({conf:t,valueFormatters:n,dataDict:i,params:o}).map(p=>`
298
298
  <tr>
299
299
  <th style="text-align: right;">
300
- <div style="${h.style.label}">${h.label}</div>
300
+ <div style="${p.style.label}">${p.label}</div>
301
301
  </th>
302
302
  <td style="text-align: right; padding: 0 1em;">
303
- <div style="${h.style.value}">${h.value}
303
+ <div style="${p.style.value}">${p.value}
304
304
  </td>
305
305
  </tr>
306
306
  `),u=y.get(o.value,0);return`
@@ -320,13 +320,13 @@ Check the top-level render call using <`+M+">.")}return I}}function oc(v,I){{if(
320
320
  </thead>
321
321
  <tbody>${c.join("")}</tbody>
322
322
  </table>
323
- `}}}function hw(t,e,n){const r=Bt(t.heat_block.min,n),i=Bt(t.heat_block.max,n);return{min:r,max:i,calculable:!0,orient:"horizontal",left:e?"center":5,top:0,itemWidth:15}}const xw={tooltip:{confine:!0},grid:{containLabel:!0}},fw=t=>V(t).get("year");function gw(t,e){const n=D(t.calendar.data_key),r=e[n.queryID],i=y.groupBy(r,d=>fw(d[n.columnKey])),o=Object.keys(i),l=r.map(d=>V(d[n.columnKey]).valueOf()),c=y.min(l),u=y.max(l);return{minDate:c??0,maxDate:u??0,dateSpan:V(u).diff(c,"day"),dataByYear:i,years:o}}function mw(t,e,n){const r=n.reduce((p,x)=>{const m=at(x,e);return p[x.name]=qe(x,m),p},{}),i=ow(t),{dateSpan:o,minDate:l,dataByYear:c,years:u}=gw(t,e),d=o<=366,h={calendar:aw(d,l,u),series:cw(t,d,c,e),tooltip:pw(t,e,i),visualMap:hw(t,d,r),legend:lw(d,u)};return y.defaultsDeep({},h,xw)}function yw(t){return s.jsx(s.Fragment,{})}function bw(t){return s.jsx(a.Text,{children:"Click heat block"})}const oo={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:bw,configRender:yw,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"}]},xr={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:[]}};K.use([P.DataZoomComponent,te.BarChart,te.LineChart,te.HeatmapChart,P.CalendarComponent,P.GridComponent,P.LegendComponent,P.TooltipComponent,P.VisualMapComponent,we.CanvasRenderer]);function jw({name:t},e){const n=e.getOption();n.calendar.forEach(r=>{r.range=t}),e.setOption(n)}function vw({conf:t,data:e,width:n,height:r,interactionManager:i,variables:o}){const l=mt(e,t.calendar.data_key),c=$e(i.triggerManager,oo.id),u=f.useCallback(p=>{const[x,m]=p.value,j=y.get(l,x,{error:"rowData is not found"});c.forEach(C=>{i.runInteraction(C.id,{...p,rowData:j})})},[l,c,i]),d=f.useMemo(()=>({click:u,legendselectchanged:jw}),[u]),h=f.useMemo(()=>mw(t,e,o),[t,e]);return s.jsx(ve,{echarts:K,option:h,style:{width:n,height:r},onEvents:d,notMerge:!0,opts:{locale:t.calendar.locale},theme:"merico-light"})}function ww({context:t,instance:e}){const n=Ve({vizManager:t.vizManager,instance:e}),{value:r}=O(t.instanceData,"config"),{variables:i}=t,o=f.useMemo(()=>y.defaults({},r,xr),[r]),l=t.data,{width:c,height:u}=t.viewport;return!o.calendar.data_key||!o.heat_block.data_key||!c||!u?null:s.jsx(Te,{width:c,height:u,children:s.jsx(vw,{variables:i,width:We(c),height:Re(u),data:l,conf:o,interactionManager:n})})}function Cw({control:t,watch:e}){return e(["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:t,render:({field:n})=>s.jsx(B,{label:"Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"heat_block.name",control:t,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:t,render:({field:n})=>s.jsx(Lt,{label:"Min Value",...n})}),s.jsx(b.Controller,{name:"heat_block.max",control:t,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:t,render:({field:n})=>s.jsx(Ae,{...n})})]})}const Sw=({control:t,index:e,remove:n})=>s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`tooltip.metrics.${e}.name`,control:t,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`tooltip.metrics.${e}.data_key`,control:t,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(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),_w=({control:t,watch:e})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:t,name:"tooltip.metrics"}),o=e("tooltip.metrics"),l=n.map((p,x)=>({...p,...o[x]})),c=()=>r({id:Date.now().toString(),data_key:"",name:""}),u=e("tooltip.metrics.0.id"),[d,h]=f.useState(()=>u??null);return f.useEffect(()=>{u&&h(p=>p!==null?p:u)},[u]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(_.InfoCircle,{size:14,color:"#888"}),s.jsx(a.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),s.jsx(a.Divider,{variant:"dashed",my:10}),s.jsxs(a.Tabs,{value:d,onTabChange:p=>h(p),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((p,x)=>s.jsx(a.Tabs.Tab,{value:p.id,children:p.name?p.name:x},p.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),l.map((p,x)=>s.jsx(a.Tabs.Panel,{value:p.id,children:s.jsx(Sw,{control:t,index:x,remove:i},p.id)},p.id))]})]})};function kw({control:t,watch:e}){return s.jsx(_w,{control:t,watch:e})}const Tw=[{label:"Chinese",value:"ZH"},{label:"English",value:"EN"}];function Iw({control:t,watch:e}){return e(["calendar"]),s.jsxs(a.Stack,{children:[s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:"calendar.data_key",control:t,render:({field:n})=>s.jsx(B,{label:"Data Field",required:!0,sx:{flex:1},...n})})}),s.jsx(b.Controller,{name:"calendar.locale",control:t,render:({field:n})=>s.jsx(a.Select,{label:"Language",required:!0,data:Tw,sx:{flex:1},...n})})]})}function Dw({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},e,xr),[e]),i=f.useMemo(()=>y.cloneDeep(r),[r]);f.useEffect(()=>{!y.isEqual(r,i)&&(console.log("config malformed, resetting to defaults",r,i),n(i))},[r,i]);const{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=b.useForm({defaultValues:i});f.useEffect(()=>{d(i)},[i]);const h=u(),p=f.useMemo(()=>!y.isEqual(h,r),[h,r]);return s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:l(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Calendar Heatmap Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(_.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(Iw,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Heat Block",children:s.jsx(Cw,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(kw,{control:o,watch:c})})]})]})})}function Mw(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{calendar:i,heat_block:o,tooltip:l,...c}=t;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 Aw(t){const{heat_block:e}=t;let{min:n,max:r}=e;return typeof n!="number"&&(n=0),typeof r!="number"&&(r=100),{...t,heat_block:{...e,min:{type:"static",value:n},max:{type:"static",value:r}}}}class zw extends re{constructor(){super(...arguments);z(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>({...n,version:2,config:Mw(n.config,r)})),this.version(3,n=>({...n,version:3,config:Aw(n.config)}))}}const Ew={displayName:"Heatmap(Calendar)",displayGroup:"ECharts-based charts",migrator:new zw,name:"calendarHeatmap",viewRender:ww,configRender:Dw,createConfig:()=>({version:3,config:xr}),triggers:[oo]},fr={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:{...Oe},overflow:ze},nameAlignment:"center"},series:[],tooltip:{metrics:[]},reference_lines:[]};function Pw(){const t=new Date().getTime().toString();return{id:t,min:"",max:"",name:t,data_key:"",position:"bottom",label_formatter:ye,show:!0}}function Lw(){const t=new Date().getTime().toString();return{id:t,type:"bar",name:t,stack:"",color:"",barGap:"0%",data_key:"",barWidth:"",barMinWidth:"1",barMaxWidth:"10",group_by_key:"",hide_in_legend:!1,invisible:!1,label_position:"right",aggregation_on_value:Et,xAxisIndex:"0"}}function Bw(){const t=new Date().getTime().toString();return{id:t,name:t,template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,xAxisIndex:"0"}}function Ow(t){const e=t.x_axes.some(o=>o.position==="top"&&!!o.name&&o.show);let n=0;e&&(n+=15);const r=t.x_axes.some(o=>o.position==="bottom"&&!!o.name&&o.show);let i=0;return r&&(i+=15),t.series.some(o=>!o.hide_in_legend)&&(i+=20),{top:n,right:5,bottom:i,left:5,containLabel:!0}}function $w(t){switch(t){case"bar":return"roundRect";case"scatter":return"circle"}}function Vw(t){const e={show:!0,bottom:0,left:"center",type:"scroll"};return e.data=t.filter(n=>!n.hide_in_legend).map(({name:n,type:r})=>({name:n,icon:$w(r)})),e}function Nw(t,e,n,r){return t.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?An(i.template,e,r):""},position:c}}}})}function Nn(t,e,n){const r=rt(t,e),i=rt(t,n);return y.zip(i,r)}function qw(t,e,n,r){const i=Nn(e,n,r);return y.unionBy(i,t,0)}function Fw({dataTemplate:t,data:e,name_data_key:n,value_data_key:r,valueTypedXAxis:i}){return i?qw(t,e,n,r):Nn(e,n,r)}function Gw({dataTemplate:t,data:e,aggregation_on_value:n,name_data_key:r,value_data_key:i,valueTypedXAxis:o}){if(!n||n.type==="none")return Fw({dataTemplate:t,data:e,name_data_key:r,value_data_key:i,valueTypedXAxis:o});const l=Nn(e,r,i),c=y.groupBy(l,"0");return t.map(([d])=>{const p=c[d].map(m=>m[1]),x=Fs(p,n);return[d,x]})}function Ww({group_by_key:t,data:e,value_data_key:n,name_data_key:r}){const{queryID:i,columnKey:o}=D(t),l=y.groupBy(e[i],o);return Object.entries(l).forEach(([c,u])=>{l[c]=Nn({[i]:u},r,n)}),l}function Rw({y_axis:t},{data_key:e,xAxisIndex:n,label_position:r,name:i,group_by_key:o,aggregation_on_value:l,stack:c,color:u,hide_in_legend:d,invisible:h,id:p,...x},m,j,C,T,A){const L={label:{show:!!r,position:r,formatter:A[n??"default"]},name:i,yAxisId:"main-y-axis",xAxisIndex:n,stack:c,color:h?"transparent":u,hide_in_legend:d,labelLayout:{hideOverlap:!0},emphasis:{disabled:!0},...x};if(!o||o===t.data_key)return L.data=Gw({dataTemplate:m,data:C,aggregation_on_value:l,name_data_key:t.data_key,value_data_key:e,valueTypedXAxis:j}),L;const Y=Ww({group_by_key:o,data:C,name_data_key:t.data_key,value_data_key:e});return Object.entries(Y).map(([se,Q])=>{const ie=y.cloneDeep(L);return ie.name=se,ie.color=void 0,ie.data=Q,ie})}function Qw(t,e,n,r,i,o,l){const c=e.map(d=>[d,0]);return t.series.map(d=>Rw(t,d,c,n,r,l,i)).flat().concat(Nw(t.reference_lines,o,l,r))}function Yw(t,e){const n=t.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(e.y_axis.axisLabel.formatter)(o,l)}function Kw(t,e,n){const r=e.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:h,value:p})=>{if(Array.isArray(p)&&p.length===2&&(p=p[0]),!d)return p;const x=r[d],m=n[x]??n.default;return`
323
+ `}}}function lw(t,e,n){const r=Bt(t.heat_block.min,n),i=Bt(t.heat_block.max,n);return{min:r,max:i,calculable:!0,orient:"horizontal",left:e?"center":5,top:0,itemWidth:15}}const cw={tooltip:{confine:!0},grid:{containLabel:!0}},uw=t=>V(t).get("year");function dw(t,e){const n=D(t.calendar.data_key),r=e[n.queryID],i=y.groupBy(r,d=>uw(d[n.columnKey])),o=Object.keys(i),l=r.map(d=>V(d[n.columnKey]).valueOf()),c=y.min(l),u=y.max(l);return{minDate:c??0,maxDate:u??0,dateSpan:V(u).diff(c,"day"),dataByYear:i,years:o}}function pw(t,e,n){const r=n.reduce((h,x)=>{const m=it(x,e);return h[x.name]=Ne(x,m),h},{}),i=nw(t),{dateSpan:o,minDate:l,dataByYear:c,years:u}=dw(t,e),d=o<=366,p={calendar:tw(d,l,u),series:rw(t,d,c,e),tooltip:ow(t,e,i),visualMap:lw(t,d,r),legend:sw(d,u)};return y.defaultsDeep({},p,cw)}function hw(t){return s.jsx(s.Fragment,{})}function xw(t){return s.jsx(a.Text,{children:"Click heat block"})}const lo={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:xw,configRender:hw,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"}]},xr={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([P.DataZoomComponent,te.BarChart,te.LineChart,te.HeatmapChart,P.CalendarComponent,P.GridComponent,P.LegendComponent,P.TooltipComponent,P.VisualMapComponent,we.CanvasRenderer]);function fw({name:t},e){const n=e.getOption();n.calendar.forEach(r=>{r.range=t}),e.setOption(n)}function gw({conf:t,data:e,width:n,height:r,interactionManager:i,variables:o}){const l=mt(e,t.calendar.data_key),c=$e(i.triggerManager,lo.id),u=f.useCallback(h=>{const[x,m]=h.value,j=y.get(l,x,{error:"rowData is not found"});c.forEach(C=>{i.runInteraction(C.id,{...h,rowData:j})})},[l,c,i]),d=f.useMemo(()=>({click:u,legendselectchanged:fw}),[u]),p=f.useMemo(()=>pw(t,e,o),[t,e]);return s.jsx(ve,{echarts:Y,option:p,style:{width:n,height:r},onEvents:d,notMerge:!0,opts:{locale:t.calendar.locale},theme:"merico-light"})}function mw({context:t,instance:e}){const n=Ve({vizManager:t.vizManager,instance:e}),{value:r}=O(t.instanceData,"config"),{variables:i}=t,o=f.useMemo(()=>y.defaults({},r,xr),[r]),l=t.data,{width:c,height:u}=t.viewport;return!o.calendar.data_key||!o.heat_block.data_key||!c||!u?null:s.jsx(Te,{width:c,height:u,children:s.jsx(gw,{variables:i,width:We(c),height:Re(u),data:l,conf:o,interactionManager:n})})}function yw({control:t,watch:e}){return e(["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:t,render:({field:n})=>s.jsx(B,{label:"Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"heat_block.name",control:t,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:t,render:({field:n})=>s.jsx(Lt,{label:"Min Value",...n})}),s.jsx(b.Controller,{name:"heat_block.max",control:t,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:t,render:({field:n})=>s.jsx(Be,{...n})})]})}const bw=({control:t,index:e,remove:n})=>s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`tooltip.metrics.${e}.name`,control:t,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`tooltip.metrics.${e}.data_key`,control:t,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(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),jw=({control:t,watch:e})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:t,name:"tooltip.metrics"}),o=e("tooltip.metrics"),l=n.map((h,x)=>({...h,...o[x]})),c=()=>r({id:Date.now().toString(),data_key:"",name:""}),u=e("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(bw,{control:t,index:x,remove:i},h.id)},h.id))]})]})};function vw({control:t,watch:e}){return s.jsx(jw,{control:t,watch:e})}const ww=[{label:"Chinese",value:"ZH"},{label:"English",value:"EN"}];function Cw({control:t,watch:e}){return e(["calendar"]),s.jsxs(a.Stack,{children:[s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:"calendar.data_key",control:t,render:({field:n})=>s.jsx(B,{label:"Data Field",required:!0,sx:{flex:1},...n})})}),s.jsx(b.Controller,{name:"calendar.locale",control:t,render:({field:n})=>s.jsx(a.Select,{label:"Language",required:!0,data:ww,sx:{flex:1},...n})})]})}function Sw({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},e,xr),[e]),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(Cw,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Heat Block",children:s.jsx(yw,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(vw,{control:o,watch:c})})]})]})})}function _w(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{calendar:i,heat_block:o,tooltip:l,...c}=t;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 kw(t){const{heat_block:e}=t;let{min:n,max:r}=e;return typeof n!="number"&&(n=0),typeof r!="number"&&(r=100),{...t,heat_block:{...e,min:{type:"static",value:n},max:{type:"static",value:r}}}}class Tw extends re{constructor(){super(...arguments);z(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>({...n,version:2,config:_w(n.config,r)})),this.version(3,n=>({...n,version:3,config:kw(n.config)}))}}const Iw={displayName:"Heatmap(Calendar)",displayGroup:"ECharts-based charts",migrator:new Tw,name:"calendarHeatmap",viewRender:mw,configRender:Sw,createConfig:()=>({version:3,config:xr}),triggers:[lo]},fr={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:{...Oe},overflow:Ae},nameAlignment:"center"},series:[],tooltip:{metrics:[]},reference_lines:[]};function Dw(){const t=new Date().getTime().toString();return{id:t,min:"",max:"",name:t,data_key:"",position:"bottom",label_formatter:ye,show:!0}}function Mw(){const t=new Date().getTime().toString();return{id:t,type:"bar",name:t,stack:"",color:"",barGap:"0%",data_key:"",barWidth:"",barMinWidth:"1",barMaxWidth:"10",group_by_key:"",hide_in_legend:!1,invisible:!1,label_position:"right",aggregation_on_value:At,xAxisIndex:"0"}}function Aw(){const t=new Date().getTime().toString();return{id:t,name:t,template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,xAxisIndex:"0"}}function zw(t){const e=t.x_axes.some(o=>o.position==="top"&&!!o.name&&o.show);let n=0;e&&(n+=15);const r=t.x_axes.some(o=>o.position==="bottom"&&!!o.name&&o.show);let i=0;return r&&(i+=15),t.series.some(o=>!o.hide_in_legend)&&(i+=20),{top:n,right:5,bottom:i,left:5,containLabel:!0}}function Ew(t){switch(t){case"bar":return"roundRect";case"scatter":return"circle"}}function Pw(t){const e={show:!0,bottom:0,left:"center",type:"scroll"};return e.data=t.filter(n=>!n.hide_in_legend).map(({name:n,type:r})=>({name:n,icon:Ew(r)})),e}function Lw(t,e,n,r){return t.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,e,r):""},position:c}}}})}function Vn(t,e,n){const r=rt(t,e),i=rt(t,n);return y.zip(i,r)}function Bw(t,e,n,r){const i=Vn(e,n,r);return y.unionBy(i,t,0)}function Ow({dataTemplate:t,data:e,name_data_key:n,value_data_key:r,valueTypedXAxis:i}){return i?Bw(t,e,n,r):Vn(e,n,r)}function $w({dataTemplate:t,data:e,aggregation_on_value:n,name_data_key:r,value_data_key:i,valueTypedXAxis:o}){if(!n||n.type==="none")return Ow({dataTemplate:t,data:e,name_data_key:r,value_data_key:i,valueTypedXAxis:o});const l=Vn(e,r,i),c=y.groupBy(l,"0");return t.map(([d])=>{const h=c[d].map(m=>m[1]),x=_s(h,n);return[d,x]})}function Vw({group_by_key:t,data:e,value_data_key:n,name_data_key:r}){const{queryID:i,columnKey:o}=D(t),l=y.groupBy(e[i],o);return Object.entries(l).forEach(([c,u])=>{l[c]=Vn({[i]:u},r,n)}),l}function Nw({y_axis:t},{data_key:e,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,C,T,A){const L={label:{show:!!r,position:r,formatter:A[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===t.data_key)return L.data=$w({dataTemplate:m,data:C,aggregation_on_value:l,name_data_key:t.data_key,value_data_key:e,valueTypedXAxis:j}),L;const U=Vw({group_by_key:o,data:C,name_data_key:t.data_key,value_data_key:e});return Object.entries(U).map(([se,Q])=>{const ie=y.cloneDeep(L);return ie.name=se,ie.color=void 0,ie.data=Q,ie})}function qw(t,e,n,r,i,o,l){const c=e.map(d=>[d,0]);return t.series.map(d=>Nw(t,d,c,n,r,l,i)).flat().concat(Lw(t.reference_lines,o,l,r))}function Fw(t,e){const n=t.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(e.y_axis.axisLabel.formatter)(o,l)}function Gw(t,e,n){const r=e.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`
324
324
  <tr>
325
- <td>${h}</td>
325
+ <td>${p}</td>
326
326
  <th style="text-align: right; padding: 0 1em;">${d}</th>
327
- <td style="text-align: left; padding: 0 1em;">${m({value:p})}</td>
327
+ <td style="text-align: left; padding: 0 1em;">${m({value:h})}</td>
328
328
  </tr>
329
- `}),c=Je(t.y_axis.axisLabel.overflow.in_tooltip),u=Yw(o,t);return`
329
+ `}),c=Je(t.y_axis.axisLabel.overflow.in_tooltip),u=Fw(o,t);return`
330
330
  <div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
331
331
  <div style="${c}">${u}</div>
332
332
  </div>
@@ -335,7 +335,7 @@ Check the top-level render call using <`+M+">.")}return I}}function oc(v,I){{if(
335
335
  ${l.join("")}
336
336
  </tbody>
337
337
  </table>
338
- `}}}function Uw(t){return t.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 Xw(t,e){const n={};return e.map(r=>{const i=at(r,t);n[r.name]=qe(r,i)}),n}function Jw(t,e){return t.x_axes.map(({min:n,max:r,...i},o)=>{let l=i.position;return l||(l=o>0?"bottom":"top"),Le.getYAxis({...i,type:"value",min:n||void 0,max:r||void 0,position:l,axisLabel:{show:!0,margin:2,formatter:e[o]??e.default},nameLocation:"center",nameGap:15})})}function Zw(t,e){const n=e.every(l=>!Number.isNaN(Number(l))),{overflow:r,...i}=t.y_axis.axisLabel,o=Qe(r.on_axis);return[Le.getXAxis({data:e,name:t.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 Hw(t,e,n){if(!t.y_axis.data_key)return{};const r=Xw(e,n),i=Uw(t),o=D(t.y_axis.data_key),l=y.uniq(e[o.queryID].map(h=>h[o.columnKey])),c=l.every(h=>!Number.isNaN(Number(h))),u=Qw(t,l,c,e,i,n,r);return{xAxis:Jw(t,i),yAxis:Zw(t,l),series:u,tooltip:Kw(t,u,i),grid:Ow(t),legend:Vw(u)}}K.use([P.DataZoomComponent,te.BarChart,te.LineChart,te.ScatterChart,P.GridComponent,P.LegendComponent,P.TooltipComponent,we.CanvasRenderer,P.MarkLineComponent,P.MarkAreaComponent]);function e0({conf:t,data:e,width:n,height:r,interactionManager:i,variables:o}){const l=mt(e,t.y_axis.data_key),c=$e(i.triggerManager,Rs.id),u=f.useCallback(p=>{const x=y.get(l,p.name,{error:"rowData is not found"});c.forEach(m=>{i.runInteraction(m.id,{...p,rowData:x})})},[l,c,i]),d=f.useMemo(()=>({click:u}),[u]),h=f.useMemo(()=>Hw(t,e,o),[t,e]);return s.jsx(ve,{echarts:K,option:h,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function t0({context:t,instance:e}){const n=Ve({vizManager:t.vizManager,instance:e}),{value:r}=O(t.instanceData,"config"),{variables:i}=t,o=f.useMemo(()=>y.defaults({},r,fr),[r]),l=t.data,{width:c,height:u}=t.viewport;return!c||!u?null:s.jsx(Te,{width:c,height:u,children:s.jsx(e0,{variables:i,width:We(c),height:Re(u),data:l,conf:o,interactionManager:n})})}const n0=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],s0=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function r0({control:t,index:e,remove:n,watch:r,variableOptions:i,xAxisOptions:o}){const l=r(`reference_lines.${e}.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.${e}.name`,control:t,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.${e}.variable_key`,control:t,render:({field:c})=>s.jsx(a.Select,{label:"Value",required:!0,data:i,sx:{flex:1},...c})})]}),s.jsx(b.Controller,{name:`reference_lines.${e}.template`,control:t,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.${e}.orientation`,control:t,render:({field:c})=>s.jsx(a.Select,{label:"Orientation",data:s0,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.${e}.xAxisIndex`,control:t,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.${e}.lineStyle.type`,control:t,render:({field:c})=>s.jsx(a.Select,{label:"Line Type",data:n0,sx:{flexGrow:1},...c})}),s.jsx(b.Controller,{name:`reference_lines.${e}.lineStyle.width`,control:t,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.${e}.lineStyle.color`,control:t,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.${e}.show_in_legend`,control:t,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(e),sx:{top:15,right:5},children:"Delete this Reference Line"})]})}function i0({control:t,watch:e,variables:n}){const{fields:r,append:i,remove:o}=b.useFieldArray({control:t,name:"reference_lines"}),l=e("reference_lines"),c=r.map((m,j)=>({...m,...l[j]})),u=()=>{const m=Bw();i(m)},d=f.useMemo(()=>n.map(m=>({label:m.name,value:m.name})),[n]),h=e("x_axes"),p=f.useMemo(()=>h.map(({name:m},j)=>({label:m,value:j.toString()})),[h]),x=c.length>0?c[0].id:"0";return s.jsxs(a.Tabs,{defaultValue:x,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},children:[s.jsxs(a.Tabs.List,{children:[c.map((m,j)=>s.jsx(a.Tabs.Tab,{value:m.id,children:m.name},m.id)),s.jsx(a.Tabs.Tab,{onClick:u,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),c.map((m,j)=>s.jsx(a.Tabs.Panel,{value:m.id,children:s.jsx(r0,{control:t,index:j,remove:o,watch:e,variableOptions:d,xAxisOptions:p})},m.id))]})}function a0(t){const[e,n]=f.useState(t);return f.useEffect(()=>{n(t)},[t]),{tab:e,setTab:n}}const o0=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function l0({control:t,index:e,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.${e}.stack`,control:t,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.${e}.barGap`,control:t,render:({field:i})=>s.jsx(a.Select,{label:"Bar Gap",data:o0,sx:{flexGrow:1},...i})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${e}.barMinWidth`,control:t,render:({field:i})=>s.jsx(a.TextInput,{label:"Bar Width(Min)",disabled:r,sx:{flexGrow:1},...i})}),s.jsx(b.Controller,{name:`series.${e}.barWidth`,control:t,render:({field:i})=>s.jsx(a.TextInput,{label:"Bar Width",sx:{flexGrow:1},...i})}),s.jsx(b.Controller,{name:`series.${e}.barMaxWidth`,control:t,render:({field:i})=>s.jsx(a.TextInput,{label:"Bar Width(Max)",disabled:r,sx:{flexGrow:1},...i})})]})]})}const c0=[{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 u0({control:t,index:e,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.${e}.name`,control:t,render:({field:o})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...o})}),s.jsx(b.Controller,{name:`series.${e}.xAxisIndex`,control:t,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.${e}.data_key`,control:t,render:({field:o})=>s.jsx(B,{label:"Value Field",required:!0,sx:{flex:1},...o})}),s.jsx(b.Controller,{name:`series.${e}.aggregation_on_value`,control:t,render:({field:o})=>s.jsx(Dn,{label:"Aggregation on Value",value:o.value??Et,onChange:o.onChange,pt:0})})]}),s.jsx(a.Group,{grow:!0,children:s.jsx(b.Controller,{name:`series.${e}.group_by_key`,control:t,render:({field:o})=>s.jsx(B,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...o})})}),s.jsx(l0,{index:e,control:t,seriesItem:r}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),s.jsx(b.Controller,{name:`series.${e}.label_position`,control:t,render:({field:o})=>s.jsx(a.Select,{label:"Label Position",data:c0,...o})}),s.jsxs(a.Stack,{spacing:4,children:[s.jsx(a.Text,{size:"sm",children:"Color"}),s.jsx(b.Controller,{name:`series.${e}.color`,control:t,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.${e}.hide_in_legend`,control:t,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.${e}.invisible`,control:t,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(e),sx:{top:15,right:5},children:"Delete this Series"})]})}function d0({control:t,watch:e}){var x;const{fields:n,append:r,remove:i}=b.useFieldArray({control:t,name:"series"}),o=e("series"),l=n.map((m,j)=>({...m,...o[j]})),c=()=>{const m=Lw();r(m)},u=e("x_axes"),d=f.useMemo(()=>u.map(({name:m},j)=>({label:m,value:j.toString()})),[u]),{tab:h,setTab:p}=a0((x=l[0])==null?void 0:x.id);return s.jsxs(a.Tabs,{value:h,onTabChange:p,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map(m=>s.jsx(a.Tabs.Tab,{value:m.id,children:m.name},m.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),l.map((m,j)=>s.jsx(a.Tabs.Panel,{value:m.id,children:s.jsx(u0,{control:t,index:j,remove:i,seriesItem:m,xAxisOptions:d},m.id)},m.id))]})}const p0=[{label:"Top",value:"top"},{label:"Bottom",value:"bottom"}];function h0({control:t,index:e,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.${e}.name`,control:t,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.${e}.position`,control:t,render:({field:r})=>s.jsx(a.Select,{label:"Position",required:!0,data:p0,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.${e}.label_formatter`,control:t,render:({field:r})=>s.jsx(Ae,{...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.${e}.min`,control:t,render:({field:r})=>s.jsx(a.TextInput,{label:"Min",...r})}),s.jsx(b.Controller,{name:`x_axes.${e}.max`,control:t,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.${e}.show`,control:t,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(e),disabled:e===0,children:"Delete this X Axis"})]})}function x0({control:t,watch:e}){const{fields:n,append:r,remove:i}=b.useFieldArray({control:t,name:"x_axes"}),o=e("x_axes"),l=n.map((d,h)=>({...d,...o[h]})),c=()=>{const d=Pw();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,h)=>s.jsx(a.Tabs.Panel,{value:d.id,children:s.jsx(h0,{control:t,index:h,remove:i})},d.id))]})}function f0({control:t,watch:e}){return e(["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:t,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:t,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:t,render:({field:n})=>s.jsx(zn,{...n})})}),s.jsx(b.Controller,{name:"y_axis.axisLabel.overflow",control:t,render:({field:n})=>s.jsx(Xe,{...n})})]})}function g0({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),{variables:r}=t,i=f.useMemo(()=>y.defaultsDeep({},e,fr),[e]),{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=b.useForm({defaultValues:i});f.useEffect(()=>{d(i)},[i]),c([]);const h=u(),p=f.useMemo(()=>!y.isEqual(h,i),[h,i]);return s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:l(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Horizontal Bar Chart Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(_.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(x0,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Y Axis",children:s.jsx(f0,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Series",children:s.jsx(d0,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Reference Lines",children:s.jsx(i0,{variables:r,control:o,watch:c})})]})]})})}function m0(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis:i,y_axis:o,series:l,...c}=t;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 y0 extends re{constructor(){super(...arguments);z(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:m0(i,r)}})}}const b0={displayName:"Horizontal Bar Chart",displayGroup:"ECharts-based charts",migrator:new y0,name:"horizontalBarChart",viewRender:t0,configRender:g0,createConfig:()=>({version:2,config:fr})},gr={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...On}}},deviation:{name:"",data_keys:{estimated_value:"",actual_value:""}},metrics:[]};function j0(){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 lo=({value:t})=>{try{return F(t[2]).format({output:"percent",mantissa:0})}catch(e){return console.error(e),t}};function v0(t,e,n){return{type:"heatmap",name:"准确估算比例",xAxisIndex:0,yAxisIndex:0,data:e.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:lo},labelLayout:{hideOverlap:!0},visualMapIndex:0,tooltip:{trigger:"item",formatter:({color:i,value:o})=>`
338
+ `}}}function Ww(t){return t.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 Rw(t,e){const n={};return e.map(r=>{const i=it(r,t);n[r.name]=Ne(r,i)}),n}function Qw(t,e){return t.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:e[o]??e.default},nameLocation:"center",nameGap:15})})}function Uw(t,e){const n=e.every(l=>!Number.isNaN(Number(l))),{overflow:r,...i}=t.y_axis.axisLabel,o=Qe(r.on_axis);return[ze.getXAxis({data:e,name:t.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 Yw(t,e,n){if(!t.y_axis.data_key)return{};const r=Rw(e,n),i=Ww(t),o=D(t.y_axis.data_key),l=y.uniq(e[o.queryID].map(p=>p[o.columnKey])),c=l.every(p=>!Number.isNaN(Number(p))),u=qw(t,l,c,e,i,n,r);return{xAxis:Qw(t,i),yAxis:Uw(t,l),series:u,tooltip:Gw(t,u,i),grid:zw(t),legend:Pw(u)}}Y.use([P.DataZoomComponent,te.BarChart,te.LineChart,te.ScatterChart,P.GridComponent,P.LegendComponent,P.TooltipComponent,we.CanvasRenderer,P.MarkLineComponent,P.MarkAreaComponent]);function Kw({conf:t,data:e,width:n,height:r,interactionManager:i,variables:o}){const l=mt(e,t.y_axis.data_key),c=$e(i.triggerManager,Is.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(()=>Yw(t,e,o),[t,e]);return s.jsx(ve,{echarts:Y,option:p,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function Xw({context:t,instance:e}){const n=Ve({vizManager:t.vizManager,instance:e}),{value:r}=O(t.instanceData,"config"),{variables:i}=t,o=f.useMemo(()=>y.defaults({},r,fr),[r]),l=t.data,{width:c,height:u}=t.viewport;return!c||!u?null:s.jsx(Te,{width:c,height:u,children:s.jsx(Kw,{variables:i,width:We(c),height:Re(u),data:l,conf:o,interactionManager:n})})}const Jw=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Zw=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Hw({control:t,index:e,remove:n,watch:r,variableOptions:i,xAxisOptions:o}){const l=r(`reference_lines.${e}.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.${e}.name`,control:t,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.${e}.variable_key`,control:t,render:({field:c})=>s.jsx(a.Select,{label:"Value",required:!0,data:i,sx:{flex:1},...c})})]}),s.jsx(b.Controller,{name:`reference_lines.${e}.template`,control:t,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.${e}.orientation`,control:t,render:({field:c})=>s.jsx(a.Select,{label:"Orientation",data:Zw,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.${e}.xAxisIndex`,control:t,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.${e}.lineStyle.type`,control:t,render:({field:c})=>s.jsx(a.Select,{label:"Line Type",data:Jw,sx:{flexGrow:1},...c})}),s.jsx(b.Controller,{name:`reference_lines.${e}.lineStyle.width`,control:t,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.${e}.lineStyle.color`,control:t,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.${e}.show_in_legend`,control:t,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(e),sx:{top:15,right:5},children:"Delete this Reference Line"})]})}function e0({control:t,watch:e,variables:n}){const{fields:r,append:i,remove:o}=b.useFieldArray({control:t,name:"reference_lines"}),l=e("reference_lines"),c=r.map((m,j)=>({...m,...l[j]})),u=()=>{const m=Aw();i(m)},d=f.useMemo(()=>n.map(m=>({label:m.name,value:m.name})),[n]),p=e("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(Hw,{control:t,index:j,remove:o,watch:e,variableOptions:d,xAxisOptions:h})},m.id))]})}function t0(t){const[e,n]=f.useState(t);return f.useEffect(()=>{n(t)},[t]),{tab:e,setTab:n}}const n0=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function s0({control:t,index:e,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.${e}.stack`,control:t,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.${e}.barGap`,control:t,render:({field:i})=>s.jsx(a.Select,{label:"Bar Gap",data:n0,sx:{flexGrow:1},...i})})]}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`series.${e}.barMinWidth`,control:t,render:({field:i})=>s.jsx(a.TextInput,{label:"Bar Width(Min)",disabled:r,sx:{flexGrow:1},...i})}),s.jsx(b.Controller,{name:`series.${e}.barWidth`,control:t,render:({field:i})=>s.jsx(a.TextInput,{label:"Bar Width",sx:{flexGrow:1},...i})}),s.jsx(b.Controller,{name:`series.${e}.barMaxWidth`,control:t,render:({field:i})=>s.jsx(a.TextInput,{label:"Bar Width(Max)",disabled:r,sx:{flexGrow:1},...i})})]})]})}const r0=[{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 i0({control:t,index:e,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.${e}.name`,control:t,render:({field:o})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...o})}),s.jsx(b.Controller,{name:`series.${e}.xAxisIndex`,control:t,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.${e}.data_key`,control:t,render:({field:o})=>s.jsx(B,{label:"Value Field",required:!0,sx:{flex:1},...o})}),s.jsx(b.Controller,{name:`series.${e}.aggregation_on_value`,control:t,render:({field:o})=>s.jsx(Xs,{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.${e}.group_by_key`,control:t,render:({field:o})=>s.jsx(B,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...o})})}),s.jsx(s0,{index:e,control:t,seriesItem:r}),s.jsx(a.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),s.jsx(b.Controller,{name:`series.${e}.label_position`,control:t,render:({field:o})=>s.jsx(a.Select,{label:"Label Position",data:r0,...o})}),s.jsxs(a.Stack,{spacing:4,children:[s.jsx(a.Text,{size:"sm",children:"Color"}),s.jsx(b.Controller,{name:`series.${e}.color`,control:t,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.${e}.hide_in_legend`,control:t,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.${e}.invisible`,control:t,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(e),sx:{top:15,right:5},children:"Delete this Series"})]})}function a0({control:t,watch:e}){var x;const{fields:n,append:r,remove:i}=b.useFieldArray({control:t,name:"series"}),o=e("series"),l=n.map((m,j)=>({...m,...o[j]})),c=()=>{const m=Mw();r(m)},u=e("x_axes"),d=f.useMemo(()=>u.map(({name:m},j)=>({label:m,value:j.toString()})),[u]),{tab:p,setTab:h}=t0((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(i0,{control:t,index:j,remove:i,seriesItem:m,xAxisOptions:d},m.id)},m.id))]})}const o0=[{label:"Top",value:"top"},{label:"Bottom",value:"bottom"}];function l0({control:t,index:e,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.${e}.name`,control:t,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.${e}.position`,control:t,render:({field:r})=>s.jsx(a.Select,{label:"Position",required:!0,data:o0,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.${e}.label_formatter`,control:t,render:({field:r})=>s.jsx(Be,{...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.${e}.min`,control:t,render:({field:r})=>s.jsx(a.TextInput,{label:"Min",...r})}),s.jsx(b.Controller,{name:`x_axes.${e}.max`,control:t,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.${e}.show`,control:t,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(e),disabled:e===0,children:"Delete this X Axis"})]})}function c0({control:t,watch:e}){const{fields:n,append:r,remove:i}=b.useFieldArray({control:t,name:"x_axes"}),o=e("x_axes"),l=n.map((d,p)=>({...d,...o[p]})),c=()=>{const d=Dw();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(l0,{control:t,index:p,remove:i})},d.id))]})}function u0({control:t,watch:e}){return e(["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:t,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:t,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:t,render:({field:n})=>s.jsx(mn,{...n})})}),s.jsx(b.Controller,{name:"y_axis.axisLabel.overflow",control:t,render:({field:n})=>s.jsx(Xe,{...n})})]})}function d0({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),{variables:r}=t,i=f.useMemo(()=>y.defaultsDeep({},e,fr),[e]),{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(c0,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Y Axis",children:s.jsx(u0,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Series",children:s.jsx(a0,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Reference Lines",children:s.jsx(e0,{variables:r,control:o,watch:c})})]})]})})}function p0(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis:i,y_axis:o,series:l,...c}=t;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 h0 extends re{constructor(){super(...arguments);z(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:p0(i,r)}})}}const x0={displayName:"Horizontal Bar Chart",displayGroup:"ECharts-based charts",migrator:new h0,name:"horizontalBarChart",viewRender:Xw,configRender:d0,createConfig:()=>({version:2,config:fr})},gr={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...Ln}}},deviation:{name:"",data_keys:{estimated_value:"",actual_value:""}},metrics:[]};function f0(){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 co=({value:t})=>{try{return F(t[2]).format({output:"percent",mantissa:0})}catch(e){return console.error(e),t}};function g0(t,e,n){return{type:"heatmap",name:"准确估算比例",xAxisIndex:0,yAxisIndex:0,data:e.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:co},labelLayout:{hideOverlap:!0},visualMapIndex:0,tooltip:{trigger:"item",formatter:({color:i,value:o})=>`
339
339
  <table style="width: auto">
340
340
  <thead>
341
341
  <tr colspan="2">
@@ -353,17 +353,17 @@ Check the top-level render call using <`+M+">.")}return I}}function oc(v,I){{if(
353
353
  <tbody>
354
354
  <tr>
355
355
  <th style="text-align: right;">准确估算比例</th>
356
- <td style="text-align: left; padding: 0 1em;">${lo({value:o})}</td>
356
+ <td style="text-align: left; padding: 0 1em;">${co({value:o})}</td>
357
357
  </tr>
358
358
  </tbody>
359
359
  </table>
360
- `},show_in_legend:!1}}function co(t){const e=[`background-color: ${t}`];return t==="rgba(255, 255, 255, 1)"&&e.push("box-shadow: 0px 0px 1px 0px rgba(0,0,0,.5)"),e.join(";")}function w0([t,e]){const n={x:t,v:`${e}`};try{n.v=F(e).format({output:"number",mantissa:2,trimMantissa:!0})}catch{}return n}function C0(t,e,n,r){var u,d;const i=e.map(h=>{const p=n[h],x=y.sumBy(p,m=>m.level.diff);return[h,x/p.length]}),o=Number(((u=y.maxBy(i,h=>h[1]))==null?void 0:u[1])??0),l=Number(((d=y.minBy(i,h=>h[1]))==null?void 0:d[1])??0),c=xt.interpolate([o,0,l],["#D15A40","#FFF","#418AAF"]);return{type:"bar",name:"平均偏差",xAxisIndex:1,yAxisIndex:1,...r,data:i,itemStyle:{color:({value:h})=>{try{return c(h[1])}catch{return"#FFF"}}},label:{position:"outside",show:!0,formatter:({value:h})=>{try{return F(h[1]).format({output:"number",mantissa:1,trimMantissa:!0})}catch{return h[1]}}},tooltip:{trigger:"item",formatter:({color:h,value:p})=>{const{x,v:m}=w0(p);return`
360
+ `},show_in_legend:!1}}function uo(t){const e=[`background-color: ${t}`];return t==="rgba(255, 255, 255, 1)"&&e.push("box-shadow: 0px 0px 1px 0px rgba(0,0,0,.5)"),e.join(";")}function m0([t,e]){const n={x:t,v:`${e}`};try{n.v=F(e).format({output:"number",mantissa:2,trimMantissa:!0})}catch{}return n}function y0(t,e,n,r){var u,d;const i=e.map(p=>{const h=n[p],x=y.sumBy(h,m=>m.level.diff);return[p,x/h.length]}),o=Number(((u=y.maxBy(i,p=>p[1]))==null?void 0:u[1])??0),l=Number(((d=y.minBy(i,p=>p[1]))==null?void 0:d[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}=m0(h);return`
361
361
  <table style="width: auto">
362
362
  <thead>
363
363
  <tr colspan="2">
364
364
  <div style="
365
365
  width: 100%; height: 4px; border-radius: 2px; margin-bottom: 6px;
366
- ${co(h)}
366
+ ${uo(p)}
367
367
  "/>
368
368
  </tr>
369
369
  <tr>
@@ -379,13 +379,13 @@ Check the top-level render call using <`+M+">.")}return I}}function oc(v,I){{if(
379
379
  </tr>
380
380
  </tbody>
381
381
  </table>
382
- `}},show_in_legend:!1}}function S0([t,e,n,r]){const i={x:t,percentage:`${e}`,count:n,sum:r};try{i.percentage=F(e).format({output:"percent",mantissa:2,trimMantissa:!0})}catch{}return i}function _0(t,e,n,r){const i={};e.forEach(h=>{const p=y.countBy(n[h],m=>m.level.diff),x=y.sum(Object.values(p));Object.entries(p).forEach(([m,j])=>{i[m]||(i[m]=[]);const C=j/x;i[m].push([h,C,j,x])})});const o=Object.entries(i).map(([h])=>Number(h)).sort((h,p)=>h-p),l=Math.max(...o),c=Math.min(...o),u=xt.interpolate([l,0,c],["#D15A40","#FFF","#418AAF"]);return o.map(h=>({type:"bar",name:h,xAxisIndex:2,yAxisIndex:2,stack:1,...r,color:u(h),data:i[h],tooltip:{trigger:"item",formatter:({color:p,value:x})=>{const{x:m,percentage:j,count:C,sum:T}=S0(x);return`
382
+ `}},show_in_legend:!1}}function b0([t,e,n,r]){const i={x:t,percentage:`${e}`,count:n,sum:r};try{i.percentage=F(e).format({output:"percent",mantissa:2,trimMantissa:!0})}catch{}return i}function j0(t,e,n,r){const i={};e.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 C=j/x;i[m].push([p,C,j,x])})});const o=Object.entries(i).map(([p])=>Number(p)).sort((p,h)=>p-h),l=Math.max(...o),c=Math.min(...o),u=ft.interpolate([l,0,c],["#D15A40","#FFF","#418AAF"]);return o.map(p=>({type:"bar",name:p,xAxisIndex:2,yAxisIndex:2,stack:1,...r,color:u(p),data:i[p],tooltip:{trigger:"item",formatter:({color:h,value:x})=>{const{x:m,percentage:j,count:C,sum:T}=b0(x);return`
383
383
  <table style="width: auto">
384
384
  <thead>
385
385
  <tr colspan="2">
386
386
  <div style="
387
387
  width: 100%; height: 4px; border-radius: 2px; margin-bottom: 6px;
388
- ${co(p)}
388
+ ${uo(h)}
389
389
  "
390
390
  />
391
391
  </tr>
@@ -398,7 +398,7 @@ Check the top-level render call using <`+M+">.")}return I}}function oc(v,I){{if(
398
398
  <tbody>
399
399
  <tr>
400
400
  <th style="text-align: right;">偏差档位</th>
401
- <td style="text-align: left; padding: 0 1em;">${h}</td>
401
+ <td style="text-align: left; padding: 0 1em;">${p}</td>
402
402
  </tr>
403
403
  <tr>
404
404
  <th style="text-align: right;">占比</th>
@@ -414,8 +414,8 @@ Check the top-level render call using <`+M+">.")}return I}}function oc(v,I){{if(
414
414
  </tr>
415
415
  </tbody>
416
416
  </table>
417
- `}},show_in_legend:!0}))}function k0(t,e,n,r){const i=D(e.data_key),o=e.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 T0(t,e,n,r){const l={barMinWidth:5,barMaxWidth:20};return[v0(t,n,r),C0(t,n,r,l),..._0(t,n,r,l),k0(t,e,n,r)]}function I0(t,e){const{axisLabel:n}=t.x_axis;return[{data:e,id:"准确估算比例",gridIndex:0,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:e,id:"平均偏差",gridIndex:1,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!0,lineStyle:{color:"#FFFFFF",width:2}},type:"category"},{data:e,id:"数量占比",gridIndex:2,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:e,id:"代码当量",gridIndex:3,axisTick:{show:!1},type:"category",axisLabel:{...n,formatter:Na(n.formatter)},axisLine:{show:!1}}]}function D0(t){return[{type:"category",name:"准确估算比例",nameRotate:0,nameGap:5,nameLocation:"end",nameTextStyle:{align:"left"},gridIndex:0,axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:"平均偏差",nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:1,boundaryGap:[1,1],axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:"数量占比",nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:2,axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1},min:0,max:1},{type:"value",gridIndex:3,position:"right",splitNumber:3,axisLabel:{show:!0,verticalAlign:"top",showMinLabel:!1,lineHeight:14},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:t.name,nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:3,position:"left",axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}}]}function mr(t){return t==1||t==2?1:mr(t-2)+mr(t-1)}const M0=Array.from(new Array(20),(t,e)=>mr(e+1));function uo(t){return t<=1?t:M0.findIndex(e=>t<=e)-1}function A0(t,e){const{x_axis:n,deviation:r}=t,i=D(n.data_key),o=D(r.data_keys.estimated_value),l=D(r.data_keys.actual_value);return e[i.queryID].map(c=>{const u=uo(c[o.columnKey]),d=uo(c[l.columnKey]),h=u-d;return{...c,level:{estimated:u,actual:d,diff:h}}})}function z0(t){return t==="rgba(255, 255, 255, 1)"?{borderColor:"rgba(0,0,0,.1)",borderWidth:1}:{}}function E0(t){return{show:!0,orient:"vertical",top:"middle",right:0,data:t.filter(n=>n.show_in_legend).reverse().map(n=>({name:`${n.name}`,color:n.color,itemStyle:z0(n.color)})),tooltip:{show:!0,formatter:"档位偏差:{a}"}}}const P0={tooltip:{trigger:"axis"}};function L0(t,e){const{deviation:n,metrics:r}=t,i=r.find(l=>l.data_key===e);if(i)return i;const o=n.data_keys.actual_value;return{id:o,name:n.name,data_key:o}}function B0(t,e,n){const r=A0(t,n),i=D(t.x_axis.data_key),o=y.uniqBy(n[i.queryID],i.columnKey).map(h=>h[i.columnKey]),l=y.groupBy(r,i.columnKey),c=L0(t,e),u=T0(t,c,o,l),d={xAxis:I0(t,o),yAxis:D0(c),series:u,grid:j0(),visualMap:[{min:0,max:1,calculable:!0,show:!1,seriesIndex:0,color:["#F0F0F0","#418AAF"]}],legend:E0(u)};return y.defaultsDeep({},d,P0)}const O0={input:{border:"none !important",paddingLeft:0,lineHeight:"1.55 !important"}},$0=({conf:t,metricKey:e,setMetricKey:n})=>{const{deviation:r,metrics:i}=t,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:e,onChange:l=>n(l.currentTarget.value),styles:O0})]})},V0={"tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function N0(){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:V0,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 q0(t){return s.jsxs(a.Group,{position:"apart",children:[s.jsx(N0,{}),s.jsx($0,{...t})]})}K.use([te.BarChart,te.LineChart,te.HeatmapChart,P.GridComponent,P.LegendComponent,P.TooltipComponent,we.CanvasRenderer,P.VisualMapComponent]);function F0({conf:t,data:e,width:n,height:r,metricKey:i}){const o=f.useMemo(()=>B0(t,i,e),[t,e,i]);return s.jsx(ve,{echarts:K,option:o,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})}function G0({context:t}){const{value:e}=O(t.instanceData,"config"),n=f.useMemo(()=>y.defaults({},e,gr),[e]),r=t.data,{width:i,height:o}=t.viewport,{x_axis:l,deviation:c}=n,{estimated_value:u,actual_value:d}=c.data_keys,[h,p]=f.useState(d);if(f.useEffect(()=>{p(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(q0,{conf:n,metricKey:h,setMetricKey:p}),s.jsx(F0,{width:x,height:m-30,data:r,conf:n,metricKey:h})]})}function W0({control:t,watch:e}){return e(["deviation"]),s.jsxs(a.Stack,{children:[s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:"deviation.name",control:t,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:t,render:({field:n})=>s.jsx(B,{label:"估算值字段",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"deviation.data_keys.actual_value",control:t,render:({field:n})=>s.jsx(B,{label:"实际值字段",required:!0,sx:{flex:1},...n})})]})]})}const R0=({control:t,index:e,remove:n})=>s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`metrics.${e}.name`,control:t,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`metrics.${e}.data_key`,control:t,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(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),Q0=({control:t,watch:e})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:t,name:"metrics"}),o=e("metrics"),l=n.map((p,x)=>({...p,...o[x]})),c=()=>r({id:Date.now().toString(),data_key:"",name:""}),u=e("metrics.0.id"),[d,h]=f.useState(()=>u??null);return f.useEffect(()=>{u&&h(p=>p!==null?p:u)},[u]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(_.InfoCircle,{size:14,color:"#888"}),s.jsx(a.Text,{size:14,color:"#888",children:"设置可以展示在基线图的指标,例如代码当量"})]}),s.jsx(a.Divider,{variant:"dashed",my:10}),s.jsxs(a.Tabs,{value:d,onTabChange:p=>h(p),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((p,x)=>s.jsx(a.Tabs.Tab,{value:p.id,children:p.name?p.name:x},p.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),l.map((p,x)=>s.jsx(a.Tabs.Panel,{value:p.id,children:s.jsx(R0,{control:t,index:x,remove:i},p.id)},p.id))]})]})};function Y0({control:t,watch:e}){return e(["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:t,render:({field:n})=>s.jsx(B,{label:"数据字段",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"x_axis.name",control:t,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:t,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:t,render:({field:n})=>s.jsx(Ga,{...n})})]})]})}function K0({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},e,gr),[e]),{control:i,handleSubmit:o,watch:l,getValues:c,reset:u}=b.useForm({defaultValues:r});f.useEffect(()=>{u(r)},[r]),l([]);const d=c(),h=f.useMemo(()=>!y.isEqual(d,r),[d,r]);return s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:o(n),children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Merico Estimation Chart Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:s.jsx(_.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(Y0,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Deviation",children:s.jsx(W0,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Additional Metrics",children:s.jsx(Q0,{control:i,watch:l})})]})]})})}function U0(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis:i,deviation:o,metrics:l,...c}=t;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 X0 extends re{constructor(){super(...arguments);z(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:U0(i,r)}})}}const J0={displayName:"Merico Estimation Chart",displayGroup:"Merico suite",migrator:new X0,name:"mericoEstimationChart",viewRender:G0,configRender:K0,createConfig:()=>({version:2,config:gr})},yr={styles:{justify:"space-around",align:"start"},metrics:[]};function Z0(){return{id:new Date().getTime().toString(),names:{value:"Value",basis:"Basis"},data_keys:{value:"",basis:""},formatter:ye,postfix:{type:"text",value:""}}}const po=({postfix:t})=>t?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:t})]}):null,H0=S.observer(({metric:t,variableValueMap:e})=>{const{names:n,data_keys:r,formatter:i,postfix:o}=t,l=oe(),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(e[r.value]).format(i)}),s.jsx(po,{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(e[r.basis]).format(i)}),s.jsx(po,{postfix:c})]})]})]})}),eC=S.observer(({context:t,instance:e})=>{const{value:n}=O(t.instanceData,"config"),{variables:r}=t,i=f.useMemo(()=>y.defaults({},n,yr),[n]),o=t.data,l=f.useMemo(()=>Ca(o,r),[r,o]),{width:c,height:u}=t.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(H0,{metric:d,variableValueMap:l},d.id))})}),tC=[{label:"Text",value:"text"},{label:"Filter Option Label",value:"filter-option-label"}],nC=S.observer(f.forwardRef(({value:t,onChange:e},n)=>{const i=X().filters.selects,o=c=>{e({type:c,value:t.value})},l=c=>{e({type:t.type,value:c})};return s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(a.Select,{label:"Postfix Type",data:tC,value:t.type,onChange:o}),t.type==="text"&&s.jsx(a.TextInput,{label:"Postfix Content",value:t.value,onChange:c=>{l(c.currentTarget.value)}}),t.type==="filter-option-label"&&s.jsx(a.Select,{label:"Filter",value:t.value,onChange:l,data:i})]})}));function sC({control:t,index:e,remove:n,watch:r,variableOptions:i}){return r(`metrics.${e}.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.${e}.names.value`,control:t,render:({field:o})=>s.jsx(a.TextInput,{label:"Metric Name",required:!0,sx:{flex:1},...o})}),s.jsx(b.Controller,{name:`metrics.${e}.data_keys.value`,control:t,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.${e}.names.basis`,control:t,render:({field:o})=>s.jsx(a.TextInput,{label:"Basis Name",required:!0,sx:{flex:1},...o})}),s.jsx(b.Controller,{name:`metrics.${e}.data_keys.basis`,control:t,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.${e}.formatter`,control:t,render:({field:o})=>s.jsx(Ae,{...o})}),s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Others",labelPosition:"center"}),s.jsx(b.Controller,{name:`metrics.${e}.postfix`,control:t,render:({field:o})=>s.jsx(nC,{...o})}),s.jsx(a.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(e),sx:{position:"absolute",top:15,right:5},disabled:e===0,children:s.jsx(_.Trash,{size:16})})]})}const rC=({control:t,watch:e,variables:n})=>{const{fields:r,append:i,remove:o}=b.useFieldArray({control:t,name:"metrics"}),l=e("metrics"),c=r.map((j,C)=>({...j,...l[C]})),u=()=>{i(Z0())},d=f.useMemo(()=>n.map(j=>({label:j.name,value:j.name})),[n]),h=y.get(c,"0.id",null),[p,x]=f.useState(h);f.useEffect(()=>{x(j=>j||h)},[h]);const m=j=>{o(j);const C=y.get(c,"0.id",null);x(C)};return s.jsxs(s.Fragment,{children:[s.jsx(a.Divider,{mt:15,variant:"dashed",label:"Metrics",labelPosition:"center"}),s.jsxs(a.Tabs,{value:p,onTabChange:x,styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[s.jsxs(a.Tabs.List,{children:[c.map((j,C)=>s.jsx(a.Tabs.Tab,{value:j.id,children:j.names.value?j.names.value:C+1},j.id)),s.jsx(a.Tabs.Tab,{onClick:u,value:"add",children:s.jsx(k.IconPlus,{size:18,color:"#228be6"})})]}),c.map((j,C)=>s.jsx(a.Tabs.Panel,{value:j.id,children:s.jsx(sC,{control:t,index:C,remove:m,variableOptions:d,watch:e})},j.id))]})]})},iC=[{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"}],aC=[{label:"Start",value:"start"},{label:"Center",value:"center"},{label:"End",value:"end"},{label:"Stretch",value:"stretch"}];function oC({control:t,watch:e}){return e("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:t,render:({field:n})=>s.jsx(a.Select,{label:"Justify Content",required:!0,data:iC,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"styles.align",control:t,render:({field:n})=>s.jsx(a.Select,{label:"Align",required:!0,data:aC,sx:{flex:1},...n})})]})]})}function lC({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),{variables:r}=t,i=f.useMemo(()=>y.defaultsDeep({},e,yr),[e]),{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=b.useForm({defaultValues:i});f.useEffect(()=>{d(i)},[i]);const h=u(),p=f.useMemo(()=>!y.isEqual(h,i),[h,i]);return s.jsx("form",{onSubmit:l(n),children:s.jsxs(a.Stack,{spacing:"xs",children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Merico Stats Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(_.DeviceFloppy,{size:20})})]}),s.jsx(oC,{control:o,watch:c}),s.jsx(rC,{control:o,watch:c,variables:r})]})})}function cC(t){const{metrics:e,...n}=t;return{...n,metrics:e.map(r=>({...r,postfix:r.postfix??{type:"text",value:""}}))}}class uC extends re{constructor(){super(...arguments);z(this,"VERSION",2)}configVersions(){this.version(1,n=>({...n,version:1,config:n.config})),this.version(2,n=>({...n,version:2,config:cC(n.config)}))}}const dC={displayName:"Merico Stats",displayGroup:"Merico suite",migrator:new uC,name:"merico-stats",viewRender:eC,configRender:lC,createConfig:()=>({version:2,config:yr})};function pC({control:t,watch:e}){e(["heat_block"]);const n=e("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:t,render:({field:r})=>s.jsx(B,{label:"Data Field",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:"heat_block.name",control:t,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:t,render:({field:r})=>s.jsx(Lt,{label:"Min Value",...r})}),s.jsx(b.Controller,{name:"heat_block.max",control:t,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:t,render:({field:r})=>s.jsx(Ae,{...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:t,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:t,render:({field:r})=>s.jsx(a.NumberInput,{size:"xs",icon:s.jsx(k.IconTextSize,{size:16}),disabled:!n,...r})})]})]})}const hC=({control:t,index:e,remove:n})=>s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`tooltip.metrics.${e}.name`,control:t,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`tooltip.metrics.${e}.data_key`,control:t,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(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),xC=({control:t,watch:e})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:t,name:"tooltip.metrics"}),o=e("tooltip.metrics"),l=n.map((p,x)=>({...p,...o[x]})),c=()=>r({id:Date.now().toString(),data_key:"",name:""}),u=e("tooltip.metrics.0.id"),[d,h]=f.useState(()=>u??null);return f.useEffect(()=>{u&&h(p=>p!==null?p:u)},[u]),s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[s.jsx(_.InfoCircle,{size:14,color:"#888"}),s.jsx(a.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),s.jsx(a.Divider,{variant:"dashed",my:10}),s.jsxs(a.Tabs,{value:d,onTabChange:p=>h(p),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[s.jsxs(a.Tabs.List,{children:[l.map((p,x)=>s.jsx(a.Tabs.Tab,{value:p.id,children:p.name?p.name:x},p.id)),s.jsx(a.Tabs.Tab,{onClick:c,value:"add",children:s.jsx(_.Plus,{size:18,color:"#228be6"})})]}),l.map((p,x)=>s.jsx(a.Tabs.Panel,{value:p.id,children:s.jsx(hC,{control:t,index:x,remove:i},p.id)},p.id))]})]})};function fC({control:t,watch:e}){return s.jsx(xC,{control:t,watch:e})}const gC=({disabled:t,value:e,onChange:n})=>{const r=i=>{i&&n(i)};return s.jsxs(a.Box,{sx:{position:"relative"},children:[t&&s.jsx(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),s.jsx(me,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},mC={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
418
- `)},ho=f.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:i,setFalse:o}]=$.useBoolean(),[l,c]=f.useState(t);f.useEffect(()=>{c(t)},[t]);const u=m=>{c({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:j}=l,C={enabled:m,func_content:j};c(C),e(C)},h=()=>{o(),c(t)},p=m=>{c(j=>({...j,func_content:m}))},x=()=>{p(mC.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(gC,{value:l.func_content,onChange:p,disabled:!l.enabled}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:x,color:"red",leftIcon:s.jsx(_.Recycle,{size:20}),children:"Reset"}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:h,variant:"subtle",children:"Cancel"}),s.jsx(a.Button,{onClick:d,children:"OK"})]})]})]})})]})});function yC({control:t,watch:e}){return e(["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:t,render:({field:n})=>s.jsx(B,{label:"Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"x_axis.name",control:t,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:t,render:({field:n})=>s.jsx(Xe,{...n})}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:t,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:t,render:({field:n})=>s.jsx(ho,{...n})})]})]})}const bC=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function jC({control:t,watch:e}){return e(["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:t,render:({field:n})=>s.jsx(B,{label:"Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"y_axis.name",control:t,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:t,render:({field:n})=>s.jsx(a.Select,{label:"Name Alignment",required:!0,data:bC,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:t,render:({field:n})=>s.jsx(Xe,{...n})}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"y_axis.axisLabel.rotate",control:t,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:t,render:({field:n})=>s.jsx(ho,{...n})})]})]})}const br={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,overflow:ze,formatter:{...Oe}}},y_axis:{name:"Y Axis",data_key:"",nameAlignment:"center",axisLabel:{rotate:0,overflow:ze,formatter:{...Oe}}},heat_block:{min:{type:"static",value:0},max:{type:"static",value:100},name:"Value",data_key:"",value_formatter:ye,label:{show:!1,fontSize:10}},tooltip:{metrics:[]}};function vC({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},e,br),[e]),i=f.useMemo(()=>y.cloneDeep(r),[r]);f.useEffect(()=>{!y.isEqual(r,i)&&(console.log("config malformed, resetting to defaults",r,i),n(i))},[r,i]);const{control:o,handleSubmit:l,watch:c,getValues:u,reset:d}=b.useForm({defaultValues:i});f.useEffect(()=>{d(i)},[i]);const h=u(),p=f.useMemo(()=>!y.isEqual(h,r),[h,r]);return s.jsx("form",{onSubmit:l(n),style:{flexGrow:1},children:s.jsxs(a.Stack,{spacing:"xs",sx:{height:"100%"},children:[s.jsxs(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Text,{children:"Chart Config"}),s.jsx(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!p,children:s.jsx(_.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(yC,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Y Axis",children:s.jsx(jC,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Heat Block",children:s.jsx(pC,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(fC,{control:o,watch:c})})]})]})})}function wC(t){return s.jsx(s.Fragment,{})}function CC(t){return s.jsx(a.Text,{children:"Click heat block"})}const xo={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:CC,configRender:wC,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 fo({enabled:t,func_content:e}){return(n,r)=>{if(!t)return n;try{return new Function(`return ${e}`)()(n,r)}catch(i){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${i.message}`),n}}}function SC(t){const e=fo(t.x_axis.axisLabel.formatter),n=fo(t.y_axis.axisLabel.formatter);return{x_axis:e,y_axis:n}}function _C(t){return{heat_block:function(r){if(!t.heat_block.value_formatter)return r;try{return F(r).format(t.heat_block.value_formatter)}catch(i){return console.error(i),r}}}}function kC(t){let e=0;return t.x_axis.name&&(e+=20),{top:45,left:5,right:5,bottom:e,containLabel:!0}}function TC(t,e){const{x_axis:n,y_axis:r,heat_block:i}=t,o=D(n.data_key),l=D(r.data_key),c=D(i.data_key),u=e[o.queryID].map(d=>[y.get(d,o.columnKey),y.get(d,l.columnKey),y.get(d,c.columnKey)]);return{type:"heatmap",name:i.name,xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{borderWidth:0},data:u,label:i.label,labelLayout:{hideOverlap:!0}}}const IC=t=>{try{return F(t).format({trimMantissa:!0,mantissa:2})}catch{return t}};function DC({conf:t,labelFormatters:e,valueFormatters:n,dataDict:r,params:i}){const{value:o,dataIndex:l}=i,[c,u,d]=o,h={label:t.x_axis.name?t.x_axis.name:"X Axis",value:e.x_axis(c,l),style:{label:"",value:Je(t.x_axis.axisLabel.overflow.in_tooltip)}},p={label:t.y_axis.name?t.y_axis.name:"Y Axis",value:e.y_axis(u,l),style:{label:"",value:Je(t.y_axis.axisLabel.overflow.in_tooltip)}},x={label:t.heat_block.name,value:n.heat_block(d),style:{label:"",value:""}},m=[h,p,x],j=r[`${c}---${u}`];return j&&t.tooltip.metrics.forEach(C=>{const T=D(C.data_key);m.push({label:C.name,value:IC(y.get(j,T.columnKey,"")),style:{label:"",value:""}})}),m}function MC(t,e,n,r){const{x_axis:i,y_axis:o,heat_block:l}=t,c=D(i.data_key),u=D(o.data_key);D(l.data_key);const d=y.keyBy(e[c.queryID],h=>`${h[c.columnKey]}---${h[u.columnKey]}`);return{confine:!0,formatter:function(h){const x=DC({conf:t,labelFormatters:n,valueFormatters:r,dataDict:d,params:h}).map(j=>`
417
+ `}},show_in_legend:!0}))}function v0(t,e,n,r){const i=D(e.data_key),o=e.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 w0(t,e,n,r){const l={barMinWidth:5,barMaxWidth:20};return[g0(t,n,r),y0(t,n,r,l),...j0(t,n,r,l),v0(t,e,n,r)]}function C0(t,e){const{axisLabel:n}=t.x_axis;return[{data:e,id:"准确估算比例",gridIndex:0,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:e,id:"平均偏差",gridIndex:1,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!0,lineStyle:{color:"#FFFFFF",width:2}},type:"category"},{data:e,id:"数量占比",gridIndex:2,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:e,id:"代码当量",gridIndex:3,axisTick:{show:!1},type:"category",axisLabel:{...n,formatter:Na(n.formatter)},axisLine:{show:!1}}]}function S0(t){return[{type:"category",name:"准确估算比例",nameRotate:0,nameGap:5,nameLocation:"end",nameTextStyle:{align:"left"},gridIndex:0,axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:"平均偏差",nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:1,boundaryGap:[1,1],axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:"数量占比",nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:2,axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1},min:0,max:1},{type:"value",gridIndex:3,position:"right",splitNumber:3,axisLabel:{show:!0,verticalAlign:"top",showMinLabel:!1,lineHeight:14},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:t.name,nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:3,position:"left",axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}}]}function mr(t){return t==1||t==2?1:mr(t-2)+mr(t-1)}const _0=Array.from(new Array(20),(t,e)=>mr(e+1));function po(t){return t<=1?t:_0.findIndex(e=>t<=e)-1}function k0(t,e){const{x_axis:n,deviation:r}=t,i=D(n.data_key),o=D(r.data_keys.estimated_value),l=D(r.data_keys.actual_value);return e[i.queryID].map(c=>{const u=po(c[o.columnKey]),d=po(c[l.columnKey]),p=u-d;return{...c,level:{estimated:u,actual:d,diff:p}}})}function T0(t){return t==="rgba(255, 255, 255, 1)"?{borderColor:"rgba(0,0,0,.1)",borderWidth:1}:{}}function I0(t){return{show:!0,orient:"vertical",top:"middle",right:0,data:t.filter(n=>n.show_in_legend).reverse().map(n=>({name:`${n.name}`,color:n.color,itemStyle:T0(n.color)})),tooltip:{show:!0,formatter:"档位偏差:{a}"}}}const D0={tooltip:{trigger:"axis"}};function M0(t,e){const{deviation:n,metrics:r}=t,i=r.find(l=>l.data_key===e);if(i)return i;const o=n.data_keys.actual_value;return{id:o,name:n.name,data_key:o}}function A0(t,e,n){const r=k0(t,n),i=D(t.x_axis.data_key),o=y.uniqBy(n[i.queryID],i.columnKey).map(p=>p[i.columnKey]),l=y.groupBy(r,i.columnKey),c=M0(t,e),u=w0(t,c,o,l),d={xAxis:C0(t,o),yAxis:S0(c),series:u,grid:f0(),visualMap:[{min:0,max:1,calculable:!0,show:!1,seriesIndex:0,color:["#F0F0F0","#418AAF"]}],legend:I0(u)};return y.defaultsDeep({},d,D0)}const z0={input:{border:"none !important",paddingLeft:0,lineHeight:"1.55 !important"}},E0=({conf:t,metricKey:e,setMetricKey:n})=>{const{deviation:r,metrics:i}=t,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:e,onChange:l=>n(l.currentTarget.value),styles:z0})]})},P0={"tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function L0(){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:P0,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 B0(t){return s.jsxs(a.Group,{position:"apart",children:[s.jsx(L0,{}),s.jsx(E0,{...t})]})}Y.use([te.BarChart,te.LineChart,te.HeatmapChart,P.GridComponent,P.LegendComponent,P.TooltipComponent,we.CanvasRenderer,P.VisualMapComponent]);function O0({conf:t,data:e,width:n,height:r,metricKey:i}){const o=f.useMemo(()=>A0(t,i,e),[t,e,i]);return s.jsx(ve,{echarts:Y,option:o,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})}function $0({context:t}){const{value:e}=O(t.instanceData,"config"),n=f.useMemo(()=>y.defaults({},e,gr),[e]),r=t.data,{width:i,height:o}=t.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(B0,{conf:n,metricKey:p,setMetricKey:h}),s.jsx(O0,{width:x,height:m-30,data:r,conf:n,metricKey:p})]})}function V0({control:t,watch:e}){return e(["deviation"]),s.jsxs(a.Stack,{children:[s.jsx(a.Group,{grow:!0,noWrap:!0,children:s.jsx(b.Controller,{name:"deviation.name",control:t,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:t,render:({field:n})=>s.jsx(B,{label:"估算值字段",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"deviation.data_keys.actual_value",control:t,render:({field:n})=>s.jsx(B,{label:"实际值字段",required:!0,sx:{flex:1},...n})})]})]})}const N0=({control:t,index:e,remove:n})=>s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`metrics.${e}.name`,control:t,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`metrics.${e}.data_key`,control:t,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(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),q0=({control:t,watch:e})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:t,name:"metrics"}),o=e("metrics"),l=n.map((h,x)=>({...h,...o[x]})),c=()=>r({id:Date.now().toString(),data_key:"",name:""}),u=e("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(N0,{control:t,index:x,remove:i},h.id)},h.id))]})]})};function F0({control:t,watch:e}){return e(["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:t,render:({field:n})=>s.jsx(B,{label:"数据字段",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"x_axis.name",control:t,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:t,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:t,render:({field:n})=>s.jsx(Ga,{...n})})]})]})}function G0({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},e,gr),[e]),{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(F0,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Deviation",children:s.jsx(V0,{control:i,watch:l})}),s.jsx(a.Tabs.Panel,{value:"Additional Metrics",children:s.jsx(q0,{control:i,watch:l})})]})]})})}function W0(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis:i,deviation:o,metrics:l,...c}=t;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 R0 extends re{constructor(){super(...arguments);z(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:W0(i,r)}})}}const Q0={displayName:"Merico Estimation Chart",displayGroup:"Merico suite",migrator:new R0,name:"mericoEstimationChart",viewRender:$0,configRender:G0,createConfig:()=>({version:2,config:gr})},yr={styles:{justify:"space-around",align:"start"},metrics:[]};function U0(){return{id:new Date().getTime().toString(),names:{value:"Value",basis:"Basis"},data_keys:{value:"",basis:""},formatter:ye,postfix:{type:"text",value:""}}}const ho=({postfix:t})=>t?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:t})]}):null,Y0=S.observer(({metric:t,variableValueMap:e})=>{const{names:n,data_keys:r,formatter:i,postfix:o}=t,l=oe(),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(e[r.value]).format(i)}),s.jsx(ho,{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(e[r.basis]).format(i)}),s.jsx(ho,{postfix:c})]})]})]})}),K0=S.observer(({context:t,instance:e})=>{const{value:n}=O(t.instanceData,"config"),{variables:r}=t,i=f.useMemo(()=>y.defaults({},n,yr),[n]),o=t.data,l=f.useMemo(()=>Gi(o,r),[r,o]),{width:c,height:u}=t.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(Y0,{metric:d,variableValueMap:l},d.id))})}),X0=[{label:"Text",value:"text"},{label:"Filter Option Label",value:"filter-option-label"}],J0=S.observer(f.forwardRef(({value:t,onChange:e},n)=>{const i=X().filters.selects,o=c=>{e({type:c,value:t.value})},l=c=>{e({type:t.type,value:c})};return s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(a.Select,{label:"Postfix Type",data:X0,value:t.type,onChange:o}),t.type==="text"&&s.jsx(a.TextInput,{label:"Postfix Content",value:t.value,onChange:c=>{l(c.currentTarget.value)}}),t.type==="filter-option-label"&&s.jsx(a.Select,{label:"Filter",value:t.value,onChange:l,data:i})]})}));function Z0({control:t,index:e,remove:n,watch:r,variableOptions:i}){return r(`metrics.${e}.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.${e}.names.value`,control:t,render:({field:o})=>s.jsx(a.TextInput,{label:"Metric Name",required:!0,sx:{flex:1},...o})}),s.jsx(b.Controller,{name:`metrics.${e}.data_keys.value`,control:t,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.${e}.names.basis`,control:t,render:({field:o})=>s.jsx(a.TextInput,{label:"Basis Name",required:!0,sx:{flex:1},...o})}),s.jsx(b.Controller,{name:`metrics.${e}.data_keys.basis`,control:t,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.${e}.formatter`,control:t,render:({field:o})=>s.jsx(Be,{...o})}),s.jsx(a.Divider,{mb:-15,variant:"dashed",label:"Others",labelPosition:"center"}),s.jsx(b.Controller,{name:`metrics.${e}.postfix`,control:t,render:({field:o})=>s.jsx(J0,{...o})}),s.jsx(a.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(e),sx:{position:"absolute",top:15,right:5},disabled:e===0,children:s.jsx(_.Trash,{size:16})})]})}const H0=({control:t,watch:e,variables:n})=>{const{fields:r,append:i,remove:o}=b.useFieldArray({control:t,name:"metrics"}),l=e("metrics"),c=r.map((j,C)=>({...j,...l[C]})),u=()=>{i(U0())},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 C=y.get(c,"0.id",null);x(C)};return s.jsxs(s.Fragment,{children:[s.jsx(a.Divider,{mt:15,variant:"dashed",label:"Metrics",labelPosition:"center"}),s.jsxs(a.Tabs,{value:h,onTabChange:x,styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[s.jsxs(a.Tabs.List,{children:[c.map((j,C)=>s.jsx(a.Tabs.Tab,{value:j.id,children:j.names.value?j.names.value:C+1},j.id)),s.jsx(a.Tabs.Tab,{onClick:u,value:"add",children:s.jsx(k.IconPlus,{size:18,color:"#228be6"})})]}),c.map((j,C)=>s.jsx(a.Tabs.Panel,{value:j.id,children:s.jsx(Z0,{control:t,index:C,remove:m,variableOptions:d,watch:e})},j.id))]})]})},eC=[{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"}],tC=[{label:"Start",value:"start"},{label:"Center",value:"center"},{label:"End",value:"end"},{label:"Stretch",value:"stretch"}];function nC({control:t,watch:e}){return e("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:t,render:({field:n})=>s.jsx(a.Select,{label:"Justify Content",required:!0,data:eC,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"styles.align",control:t,render:({field:n})=>s.jsx(a.Select,{label:"Align",required:!0,data:tC,sx:{flex:1},...n})})]})]})}function sC({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),{variables:r}=t,i=f.useMemo(()=>y.defaultsDeep({},e,yr),[e]),{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(nC,{control:o,watch:c}),s.jsx(H0,{control:o,watch:c,variables:r})]})})}function rC(t){const{metrics:e,...n}=t;return{...n,metrics:e.map(r=>({...r,postfix:r.postfix??{type:"text",value:""}}))}}class iC extends re{constructor(){super(...arguments);z(this,"VERSION",2)}configVersions(){this.version(1,n=>({...n,version:1,config:n.config})),this.version(2,n=>({...n,version:2,config:rC(n.config)}))}}const aC={displayName:"Merico Stats",displayGroup:"Merico suite",migrator:new iC,name:"merico-stats",viewRender:K0,configRender:sC,createConfig:()=>({version:2,config:yr})};function oC({control:t,watch:e}){e(["heat_block"]);const n=e("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:t,render:({field:r})=>s.jsx(B,{label:"Data Field",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:"heat_block.name",control:t,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:t,render:({field:r})=>s.jsx(Lt,{label:"Min Value",...r})}),s.jsx(b.Controller,{name:"heat_block.max",control:t,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:t,render:({field:r})=>s.jsx(Be,{...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:t,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:t,render:({field:r})=>s.jsx(a.NumberInput,{size:"xs",icon:s.jsx(k.IconTextSize,{size:16}),disabled:!n,...r})})]})]})}const lC=({control:t,index:e,remove:n})=>s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:`tooltip.metrics.${e}.name`,control:t,render:({field:r})=>s.jsx(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),s.jsx(b.Controller,{name:`tooltip.metrics.${e}.data_key`,control:t,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(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),cC=({control:t,watch:e})=>{const{fields:n,append:r,remove:i}=b.useFieldArray({control:t,name:"tooltip.metrics"}),o=e("tooltip.metrics"),l=n.map((h,x)=>({...h,...o[x]})),c=()=>r({id:Date.now().toString(),data_key:"",name:""}),u=e("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(lC,{control:t,index:x,remove:i},h.id)},h.id))]})]})};function uC({control:t,watch:e}){return s.jsx(cC,{control:t,watch:e})}const dC=({disabled:t,value:e,onChange:n})=>{const r=i=>{i&&n(i)};return s.jsxs(a.Box,{sx:{position:"relative"},children:[t&&s.jsx(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),s.jsx(ge,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},pC={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
418
+ `)},xo=f.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:i,setFalse:o}]=$.useBoolean(),[l,c]=f.useState(t);f.useEffect(()=>{c(t)},[t]);const u=m=>{c({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:j}=l,C={enabled:m,func_content:j};c(C),e(C)},p=()=>{o(),c(t)},h=m=>{c(j=>({...j,func_content:m}))},x=()=>{h(pC.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(dC,{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 hC({control:t,watch:e}){return e(["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:t,render:({field:n})=>s.jsx(B,{label:"Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"x_axis.name",control:t,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:t,render:({field:n})=>s.jsx(Xe,{...n})}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"x_axis.axisLabel.rotate",control:t,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:t,render:({field:n})=>s.jsx(xo,{...n})})]})]})}const xC=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function fC({control:t,watch:e}){return e(["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:t,render:({field:n})=>s.jsx(B,{label:"Data Field",required:!0,sx:{flex:1},...n})}),s.jsx(b.Controller,{name:"y_axis.name",control:t,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:t,render:({field:n})=>s.jsx(a.Select,{label:"Name Alignment",required:!0,data:xC,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:t,render:({field:n})=>s.jsx(Xe,{...n})}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(b.Controller,{name:"y_axis.axisLabel.rotate",control:t,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:t,render:({field:n})=>s.jsx(xo,{...n})})]})]})}const br={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,overflow:Ae,formatter:{...Oe}}},y_axis:{name:"Y Axis",data_key:"",nameAlignment:"center",axisLabel:{rotate:0,overflow:Ae,formatter:{...Oe}}},heat_block:{min:{type:"static",value:0},max:{type:"static",value:100},name:"Value",data_key:"",value_formatter:ye,label:{show:!1,fontSize:10}},tooltip:{metrics:[]}};function gC({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=f.useMemo(()=>y.defaultsDeep({},e,br),[e]),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("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(hC,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Y Axis",children:s.jsx(fC,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Heat Block",children:s.jsx(oC,{control:o,watch:c})}),s.jsx(a.Tabs.Panel,{value:"Tooltip",children:s.jsx(uC,{control:o,watch:c})})]})]})})}function mC(t){return s.jsx(s.Fragment,{})}function yC(t){return s.jsx(a.Text,{children:"Click heat block"})}const fo={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:yC,configRender:mC,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 go({enabled:t,func_content:e}){return(n,r)=>{if(!t)return n;try{return new Function(`return ${e}`)()(n,r)}catch(i){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${i.message}`),n}}}function bC(t){const e=go(t.x_axis.axisLabel.formatter),n=go(t.y_axis.axisLabel.formatter);return{x_axis:e,y_axis:n}}function jC(t){return{heat_block:function(r){if(!t.heat_block.value_formatter)return r;try{return F(r).format(t.heat_block.value_formatter)}catch(i){return console.error(i),r}}}}function vC(t){let e=0;return t.x_axis.name&&(e+=20),{top:45,left:5,right:5,bottom:e,containLabel:!0}}function wC(t,e){const{x_axis:n,y_axis:r,heat_block:i}=t,o=D(n.data_key),l=D(r.data_key),c=D(i.data_key),u=e[o.queryID].map(d=>[y.get(d,o.columnKey),y.get(d,l.columnKey),y.get(d,c.columnKey)]);return{type:"heatmap",name:i.name,xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{borderWidth:0},data:u,label:i.label,labelLayout:{hideOverlap:!0}}}const CC=t=>{try{return F(t).format({trimMantissa:!0,mantissa:2})}catch{return t}};function SC({conf:t,labelFormatters:e,valueFormatters:n,dataDict:r,params:i}){const{value:o,dataIndex:l}=i,[c,u,d]=o,p={label:t.x_axis.name?t.x_axis.name:"X Axis",value:e.x_axis(c,l),style:{label:"",value:Je(t.x_axis.axisLabel.overflow.in_tooltip)}},h={label:t.y_axis.name?t.y_axis.name:"Y Axis",value:e.y_axis(u,l),style:{label:"",value:Je(t.y_axis.axisLabel.overflow.in_tooltip)}},x={label:t.heat_block.name,value:n.heat_block(d),style:{label:"",value:""}},m=[p,h,x],j=r[`${c}---${u}`];return j&&t.tooltip.metrics.forEach(C=>{const T=D(C.data_key);m.push({label:C.name,value:CC(y.get(j,T.columnKey,"")),style:{label:"",value:""}})}),m}function _C(t,e,n,r){const{x_axis:i,y_axis:o,heat_block:l}=t,c=D(i.data_key),u=D(o.data_key);D(l.data_key);const d=y.keyBy(e[c.queryID],p=>`${p[c.columnKey]}---${p[u.columnKey]}`);return{confine:!0,formatter:function(p){const x=SC({conf:t,labelFormatters:n,valueFormatters:r,dataDict:d,params:p}).map(j=>`
419
419
  <tr>
420
420
  <th style="text-align: right;">
421
421
  <div style="${j.style.label}">${j.label}</div>
@@ -430,24 +430,24 @@ Check the top-level render call using <`+M+">.")}return I}}function oc(v,I){{if(
430
430
  <tr colspan="2">
431
431
  <div style="
432
432
  width: 100%; height: 4px; border-radius: 2px; margin-bottom: 6px;
433
- background-color: ${h.color};"
433
+ background-color: ${p.color};"
434
434
  />
435
435
  </tr>
436
436
  </thead>
437
437
  <tbody>${x.join("")}</tbody>
438
438
  </table>
439
- `}}}function AC(t,e){const n=Bt(t.heat_block.min,e),r=Bt(t.heat_block.max,e);return{min:n,max:r,calculable:!0,orient:"horizontal",left:"center",top:0,itemWidth:15}}function zC(t,e,n){const r=D(t.x_axis.data_key),i=y.uniq(e[r.queryID].map(u=>u[r.columnKey])),{overflow:o,rotate:l}=t.x_axis.axisLabel,c=Qe(o.on_axis);return{id:"main-x-axis",type:"category",data:i,name:t.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 EC(t,e,n){const r=D(t.x_axis.data_key),i=D(t.y_axis.data_key),{nameAlignment:o,data_key:l,...c}=t.y_axis,u=y.uniq(e[r.queryID].map(x=>x[i.columnKey])),{overflow:d,rotate:h}=t.y_axis.axisLabel,p=Qe(d.on_axis);return{...c,type:"category",data:u,axisLabel:{rotate:h,...p,formatter:n},axisLine:{show:!0,color:"blue"},axisTick:{show:!0,alignWithLabel:!0},splitArea:{show:!0},nameTextStyle:{fontWeight:"bold",align:o},nameLocation:"end",nameGap:15,z:2}}const PC={tooltip:{confine:!0}};function LC(t,e,n){if(!t.x_axis.data_key||!t.y_axis.data_key||!t.heat_block.data_key)return{};const r=n.reduce((c,u)=>{const d=at(u,e);return c[u.name]=qe(u,d),c},{}),i=SC(t),o=_C(t),l={xAxis:zC(t,e,i.x_axis),yAxis:EC(t,e,i.y_axis),series:TC(t,e),tooltip:MC(t,e,i,o),grid:kC(t),visualMap:AC(t,r)};return y.defaultsDeep({},l,PC)}K.use([P.DataZoomComponent,te.HeatmapChart,P.GridComponent,P.LegendComponent,P.TooltipComponent,P.VisualMapComponent,we.CanvasRenderer]);function BC({conf:t,data:e,width:n,height:r,interactionManager:i,variables:o}){const l=f.useMemo(()=>{const p=D(t.x_axis.data_key),x=D(t.y_axis.data_key);return y.keyBy(e[p.queryID],m=>`${m[p.columnKey]}---${m[x.columnKey]}`)},[e,t.x_axis.data_key,t.y_axis.data_key]),c=$e(i.triggerManager,xo.id),u=f.useCallback(p=>{const[x,m]=p.value,j=y.get(l,`${x}---${m}`,{error:"rowData is not found"});c.forEach(C=>{i.runInteraction(C.id,{...p,rowData:j})})},[l,c,i]),d=f.useMemo(()=>({click:u}),[u]),h=f.useMemo(()=>LC(t,e,o),[t,e]);return s.jsx(ve,{echarts:K,option:h,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function OC({context:t,instance:e}){const n=Ve({vizManager:t.vizManager,instance:e}),{value:r}=O(t.instanceData,"config"),{variables:i}=t,o=f.useMemo(()=>y.defaults({},r,br),[r]),l=t.data,{width:c,height:u}=t.viewport;return!c||!u?null:s.jsx(Te,{width:c,height:u,children:s.jsx(BC,{variables:i,width:We(c),height:Re(u),data:l,conf:o,interactionManager:n})})}class $C extends re{constructor(){super(...arguments);z(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const VC={displayName:"Merico Heatmap",displayGroup:"Merico suite",migrator:new $C,name:"merico-heatmap",viewRender:OC,configRender:vC,createConfig:()=>({version:1,config:br}),triggers:[xo]},NC=[{value:"#25262B",name:"Dark"},{value:"#868E96",name:"Gray"},{value:"#FA5252",name:"Red"},{value:"#E64980",name:"Pink"},{value:"#BE4BDB",name:"Grape"},{value:"#7950F2",name:"Violet"},{value:"#4C6EF5",name:"Indigo"},{value:"#228BE6",name:"Blue"},{value:"#15AABF",name:"Cyan"},{value:"#12B886",name:"Teal"},{value:"#40C057",name:"Green"},{value:"#82C91E",name:"Lime"},{value:"#FAB005",name:"Yellow"},{value:"#FD7E14",name:"Orange"}].map(t=>({name:t.name,value:t.value,type:"single",category:"basic"})),qC=[yu,bu,wu,vu,ju,Cu],go=()=>({id:"dashboard",version:Si,manifest:{viz:[ur,kj,Xv,sb,Kj,Km,b0,Ou,ax,bg,nm,Ew,Lm,Xf,xj,by,Ky,rw,J0,VC,dC,jx],color:[...NC,...qC]}}),nn=new Tu,le={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")}},jr=()=>{try{nn.install(go())}catch{}const t=new fu(nn),e=new ku(nn);return{pluginManager:nn,vizManager:t,colorManager:e}},et=f.createContext(jr());try{nn.install(go())}catch{}const vr=f.createContext(null);function qn(t){const e=f.useContext(vr),n=$.useCreation(()=>t.configure(e||new hs),[t.configure]),r=$.usePrevious(n);return r&&r!==n&&r.dispose(),s.jsx(vr.Provider,{value:n,children:t.children})}function mo(){return f.useContext(vr)}const FC=({description:t,isDescriptionEmpty:e})=>e?null:s.jsx(a.Tooltip,{color:"white",label:s.jsx(Tn,{value:t,styles:{root:{border:"none"},content:{padding:0}}}),styles:{tooltip:{border:"0.0625rem solid rgb(233, 236, 239)",boxShadow:"rgb(0 0 0 / 5%) 0px 0.0625rem 0.1875rem, rgb(0 0 0 / 5%) 0px 1.25rem 1.5625rem -0.3125rem, rgb(0 0 0 / 4%) 0px 0.625rem 0.625rem -0.3125rem"}},withArrow:!0,children:s.jsx(a.Box,{sx:{height:"16px",alignSelf:"center"},children:s.jsx(k.IconInfoCircle,{size:16,color:"gray"})})}),GC=S.observer(({label:t,config:{default_value:e,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:t}),s.jsx(FC,{description:n,isDescriptionEmpty:r})]}),checked:o||!1,onChange:c=>l(c.currentTarget.checked),...i,pt:".4em",styles:{input:{borderColor:"#e9ecef"}}})]})),yo=S.observer(({label:t,config:e,value:n=[null,null],onChange:r})=>{const{inputFormat:i,...o}=e,l=Array.isArray(n)?n.map(h=>h?V(h).toDate():null):[null,null],c=h=>{r(h.map(p=>p&&V(p).format(i)))},u=e.getMinDate(l[0]),d=e.getMaxDate(l[0]);return s.jsx(gc.DatePickerInput,{type:"range",label:t,value:l,onChange:c,icon:s.jsx(_.Calendar,{size:16}),sx:{minWidth:"16em"},minDate:u,maxDate:d,valueFormat:i,styles:{input:{borderColor:"#e9ecef"}},...o})}),WC=a.createStyles((t,{radius:e=4})=>({root:{borderRadius:t.fn.radius(e),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-select.rc-select-open":{borderColor:"#228be6 !important",".rc-select-selection-overflow-item-rest":{display:"none"},".rc-select-selection-overflow-item-suffix":{display:"block"}},".rc-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-select-selection-search-mirror":{display:"none"},".rc-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:t.fontSizes.sm,fontWeight:500,color:"#212529"},required:{color:"#fa5252",paddingLeft:"3px"},dropdown:{fontSize:t.fontSizes.xs,zIndex:300,backgroundColor:"#fff",border:"1px solid #e9ecef",marginTop:6,padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px","&.rc-select-dropdown-slide-up-leave-active":{display:"none"},".rc-select-item-empty":{padding:"8px 12px"},".rc-select-item-option":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"8px 12px 8px 2px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},flexDirection:"row-reverse",".rc-select-item-option-state":{flexGrow:0,flexShrink:0,width:"30px",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},".rc-select-item-option-content":{width:"calc(100% - 30px)",overflow:"hidden",'div[data-role="label"]':{overflowWrap:"break-word"}}},".rc-virtual-list-holder-inner":{alignItems:"flex-start"}}})),bo=({errorMessage:t})=>t?s.jsx(a.Text,{color:"red",size:12,children:t}):s.jsx(a.Text,{color:"dimmed",size:12,children:"Not found"}),RC=({disabled:t,classNames:e,styles:n,unstyled:r,radius:i,style:o,label:l,value:c,onChange:u,options:d,errorMessage:h,required:p})=>{const{classes:x,cx:m}=WC({radius:i},{name:"MultiSelectWidget",classNames:e,styles:n,unstyled:r}),[j,C]=f.useState(!1),T=Q=>{C(Q)},A=j&&(c==null?void 0:c.length)>0,[L,Y]=f.useState(""),se=f.useMemo(()=>{if(!L)return d;const Q=L.toLowerCase(),ie=ue=>{var fe;return((fe=ue.description)==null?void 0:fe.toLowerCase().includes(Q))||ue.label.toLowerCase().includes(Q)};return d.filter(ie)},[L,d]);return s.jsxs(a.Stack,{spacing:3,children:[s.jsxs(a.Group,{position:"apart",children:[s.jsxs(a.Text,{className:x.label,children:[l,p&&s.jsx("span",{className:x.required,"aria-hidden":"true",children:"*"})]}),A&&s.jsx(a.Tooltip,{label:`${c.length} selected`,children:s.jsx(a.Badge,{children:c.length})})]}),s.jsx(ui,{disabled:t,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(bo,{errorMessage:h}),maxTagTextLength:10,maxTagPlaceholder:Q=>`${Q.length} selected`,searchValue:L,onSearch:Y,filterOption:!1,children:se.map(Q=>s.jsxs(ui.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))})]})},QC=S.observer(({label:t,config:e,value:n,onChange:r})=>{const i=oe(),o=!!e.options_query_id,{state:l,error:c}=i.getDataStuffByID(e.options_query_id),u=l==="loading",d=e.min_width?e.min_width:"200px",h=o?u:!1,p=x=>r(x,!1);return s.jsx(RC,{label:t,options:e.options,style:{minWidth:"160px",width:d,maxWidth:h?d:"unset",borderColor:"#e9ecef"},disabled:h,value:n,onChange:p,errorMessage:c,required:e.required})}),YC=f.forwardRef(({label:t,description:e,...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:t}),s.jsx(a.Text,{size:"xs",color:"dimmed","data-role":"description",children:e})]})})})),KC=S.observer(({label:t,config:e,value:n,onChange:r})=>{const i=oe(),o=!!e.options_query_id,{state:l,error:c}=i.getDataStuffByID(e.options_query_id),u=l==="loading";return s.jsx(a.Select,{label:t,data:e.options,disabled:o?u:!1,value:n,onChange:r,error:!!c,placeholder:c,maxDropdownHeight:500,styles:{root:{width:e.width?e.width:"200px"},input:{borderColor:"#e9ecef"}},sx:{".mantine-Select-item[data-selected] .mantine-Text-root[data-role=description]":{color:"rgba(255,255,255,.7)"}},itemComponent:YC})});function UC({label:t,config:e,value:n,onChange:r}){return s.jsx(a.TextInput,{label:t,value:n||"",onChange:i=>r(i.currentTarget.value),...e,styles:{input:{borderColor:"#e9ecef"}}})}const XC=({rotate:t,onClick:e})=>s.jsx("svg",{onClick:e,className:"caret-icon",viewBox:"0 0 1024 1024",focusable:"false","data-icon":"caret-down",width:"14px",height:"14px",fill:"currentColor","aria-hidden":"true",transform:`rotate(${t})`,children: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"})}),JC=({expanded:t,isLeaf:e,value:n,onClick:r,...i})=>(n==="0-0-value"&&console.log(i),e?s.jsx("span",{style:{width:"14px",display:"inline-block"}}):s.jsx(XC,{rotate:t?"0":"-90",onClick:r,...i})),ZC=({onClick:t})=>s.jsxs("svg",{onClick:t,className:"checkbox-icon",width:"16",height:"16",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[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"})]}),HC=({onClick:t,...e})=>s.jsx(ZC,{onClick:t,...e}),eS=a.createStyles((t,{radius:e=4})=>({root:{borderRadius:t.fn.radius(e),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-tree-select.rc-tree-select-open":{borderColor:"#228be6 !important",".rc-tree-select-selection-overflow-item-rest":{display:"none"},".rc-tree-select-selection-overflow-item-suffix":{display:"block"}},".rc-tree-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-tree-select-selection-search-mirror":{display:"none"},".rc-tree-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-tree-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-tree-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-tree-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-tree-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-tree-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-tree-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-tree-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:t.fontSizes.sm,fontWeight:500,color:"#212529"},required:{color:"#fa5252",paddingLeft:"3px"},dropdown:{fontSize:t.fontSizes.xs,zIndex:300,paddingTop:"6px","&.rc-tree-select-dropdown-slide-up-leave-active":{display:"none"},".rc-tree-select-tree-list .rc-tree-select-tree-list-holder":{},".rc-tree-select-tree-list, .rc-tree-select-empty":{backgroundColor:"#fff",border:"1px solid #e9ecef",padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px"},".rc-tree-select-empty":{padding:"8px 12px"},".rc-tree-select-tree-treenode":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"8px 12px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},"&.rc-tree-select-tree-treenode-checkbox-checked":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-checked":{stroke:"rgb(64, 192, 87)",animation:"check 200ms linear forwards"}},"&.rc-tree-select-tree-treenode-checkbox-indeterminate":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-indeterminate":{fill:"rgb(64, 192, 87)"}},".rc-tree-select-tree-switcher":{height:"16px",alignSelf:"center",paddingRight:"2px",transition:"color 200ms ease","&:hover":{color:"#228be6","svg.caret-icon":{color:"#228be6"}},"svg.caret-icon":{color:"#ced4da",transition:"all 200ms ease"}},".rc-tree-select-tree-node-content-wrapper":{display:"flex",flexWrap:"nowrap",overflow:"hidden",alignItems:"center",gap:"8px",transition:"color 200ms ease","&:hover":{color:"#228be6"}},".rc-tree-select-tree-iconEle":{height:"16px","svg .border":{stroke:"#ced4da"},".checkbox-icon .checkmark-indeterminate":{fill:"transparent",transition:"fill 200ms ease"},".checkbox-icon .checkmark-checked":{transform:"scale(1.2)",transformOrigin:"center center",strokeDasharray:10,strokeDashoffset:-10},"@keyframes check":{"0%":{strokeDashoffset:10},"100%":{strokeDashoffset:0}}},".rc-tree-select-tree-title":{textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden",".rc-tree-select-tree-title-desc":{fontSize:"12px",maxWidth:"100%",textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden"}},".rc-tree-select-tree-indent":{flexGrow:0,height:0,verticalAlign:"bottom"},".rc-tree-select-tree-indent-unit":{display:"inline-block",width:"1em"}}}})),tS=({disabled:t,classNames:e,styles:n,unstyled:r,radius:i,style:o,label:l,value:c,onChange:u,treeData:d,errorMessage:h,required:p,treeCheckStrictly:x})=>{const{classes:m,cx:j}=eS({radius:i},{name:"FilterTreeSelectWidget",classNames:e,styles:n,unstyled:r}),[C,T]=f.useState(!1),A=Y=>{T(Y)},L=C&&(c==null?void 0:c.length)>0;return s.jsxs(a.Stack,{spacing:3,children:[s.jsxs(a.Group,{position:"apart",children:[s.jsxs(a.Text,{className:m.label,children:[l,p&&s.jsx("span",{className:m.required,"aria-hidden":"true",children:"*"})]}),L&&s.jsx(a.Tooltip,{label:`${c.length} selected`,children:s.jsx(a.Badge,{children:c.length})})]}),s.jsx(di,{disabled:t,allowClear:!0,treeCheckStrictly:x,className:j(m.root,"check-select"),dropdownClassName:j(m.dropdown,""),onDropdownVisibleChange:A,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:JC,treeIcon:HC,maxTagTextLength:10,value:c,treeData:d,notFoundContent:s.jsx(bo,{errorMessage:h}),treeNodeFilterProp:"filterBasis",treeCheckable:!0,showCheckedStrategy:di.SHOW_PARENT,onChange:u,onSelect:console.log,maxTagCount:0,maxTagPlaceholder:Y=>`${Y.length} selected`})]})},nS=S.observer(({label:t,config:e,value:n,onChange:r})=>{const{treeData:i,treeDataLoading:o,errorMessage:l}=e,c=e.min_width?e.min_width:"200px",d=!!e.options_query_id?o:!1;return s.jsx(tS,{disabled:d,style:{minWidth:"160px",width:c,maxWidth:d?c:"unset",borderColor:"#e9ecef"},value:n,onChange:h=>r(h,!1),treeData:i,errorMessage:l,label:t,required:e.required,treeCheckStrictly:e.treeCheckStrictly})}),sS=S.observer(({filter:{type:t,config:e,key:n,...r},formFieldProps:i})=>{switch(t){case"select":return s.jsx(KC,{...r,...i,config:e});case"multi-select":return s.jsx(QC,{...r,...i,config:e});case"tree-select":return s.jsx(nS,{...r,...i,config:e});case"text-input":return s.jsx(UC,{...r,...i,config:e});case"date-range":return s.jsx(yo,{...r,...i,config:e});case"checkbox":return s.jsx(GC,{...r,...i,config:e});default:return null}}),rS=S.observer(f.forwardRef(({filter:t,...e},n)=>s.jsx("div",{className:"filter-root",ref:n,children:s.jsx(Ce,{children:s.jsx(sS,{filter:t,formFieldProps:e})})}))),iS=({disabled:t})=>{const{searchButtonProps:e}=Ti(),{children:n="Search",type:r,...i}=e;return s.jsx(a.Button,{color:"blue",size:"sm",type:"submit",...i,disabled:t||i.disabled,children:n})};function aS(t){const e=X();f.useEffect(()=>{var n,r;(r=(n=e.filters).updatePreviewValues)==null||r.call(n,t)},[t])}const jo=S.observer(function({view:e}){const n=oe(),{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]),aS(l);const c=n.filters.visibleInView(e.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]),h=f.useMemo(()=>d.length===0?!1:d.some(x=>!x.requiredAndPass(l[x.key])),[l,d]);if(c.length===0)return null;const p=(x,m)=>(j,C)=>{m(j),(x.should_auto_submit||C)&&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(rS,{filter:x,value:m.value,onChange:p(x,m.onChange)})},x.id))}),!u&&s.jsx(a.Group,{sx:{alignSelf:"flex-end"},children:s.jsx(iS,{disabled:h})})]})})}),oS={viewPanelInFullScreen:y.noop,inFullScreen:!1},Fn=f.createContext(oS),vo=g.types.model("MockContextMeta",{current:g.types.optional(g.types.frozen(),{})}).views(t=>({get keys(){return Object.keys(t.current)},get keySet(){return new Set(this.keys)},get entries(){return Object.entries(t.current)}})).actions(t=>({replace(e){t.current=e},defaults(e){t.current={...e,...t.current}},get(e){return t.current[e]},set(e,n){t.current[e]=n}}));function wo(t){return{current:t}}const lS=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(t=>({get json(){const{x:e,y:n,w:r,h:i,moved:o}=t;return{h:i,w:r,x:e,y:n===null?0:n,moved:o,static:t.static}}})).actions(t=>({set(e){const{x:n,y:r,w:i,h:o,moved:l}=e;t.x=n,t.y=r,t.w=i,t.h=o,t.moved=!!l,t.static=!!e.static},setWidth(e){t.w=e},setHeight(e){t.h=e}})),cS=g.types.model("PanelStyleBorderMeta",{enabled:g.types.boolean}).views(t=>({get json(){const{enabled:e}=t;return{enabled:e}}})).actions(t=>({setEnabled(e){t.enabled=e}})),uS=g.types.model("PanelStyleMeta",{border:cS}).views(t=>({get json(){const{border:e}=t;return{border:e.json}}})).actions(t=>({})),dS=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()}),g.types.model({type:g.types.literal("quantile"),config:g.types.model({p:g.types.number})}),g.types.model({type:g.types.literal("custom"),config:g.types.model({func:g.types.string})}))}).views(t=>({get json(){const{name:e,size:n,weight:r,color:i,formatter:o,data_field:l,aggregation:c}=t;return y.cloneDeep({name:e,size:n,color:i,weight:r,formatter:o,data_field:l,aggregation:c})}})),pS=g.types.model("PanelVizMeta",{type:g.types.string,conf:g.types.frozen()}).views(t=>({get json(){return{conf:t.conf,type:t.type}}})).actions(t=>({setType(e){t.type=e},setConf(e){t.conf=e}})),hS=g.types.model("PanelTitleMeta",{show:g.types.optional(g.types.boolean,!0)}).views(t=>({get json(){const{show:e}=t;return{show:e}}})).actions(t=>({setShow(e){t.show=e}})),xS=g.types.model({id:g.types.string,name:g.types.optional(g.types.string,""),title:hS,description:g.types.string,layout:lS,queryIDs:g.types.array(g.types.string),viz:pS,style:uS,variables:g.types.optional(g.types.array(dS),[])}).views(t=>({get json(){const{id:e,name:n,title:r,description:i,queryIDs:o}=t;return{id:e,viz:t.viz.json,name:n,style:t.style.json,title:r.json,layout:t.layout.json,queryIDs:[...o],variables:t.variables.map(l=>l.json),description:i}},get queryIDSet(){return new Set(t.queryIDs)}})).actions(t=>({setID(e){t.id=e},setName(e){t.name=e},setDescription(e){t.description=e},addQueryID(e){t.queryIDSet.has(e)||t.queryIDs.push(e)},removeQueryID(e){if(!t.queryIDSet.has(e))return;const n=new Set(t.queryIDSet);n.delete(e),t.queryIDs=g.cast(Array.from(n))},setQueryIDs(e){t.queryIDs=g.cast(e)},addVariable(e){t.variables.push(e)},removeVariable(e){t.variables.remove(e)}})),Gn=t=>y.cloneDeepWith(t,(e,n)=>{if(n!==void 0&&e)return W.toJS(e)});var De=(t=>(t.Postgresql="postgresql",t.MySQL="mysql",t.HTTP="http",t))(De||{});const fS=g.types.model("QueryMeta",{id:g.types.string,name:g.types.string,type:g.types.enumeration("DataSourceType",[De.Postgresql,De.MySQL,De.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(t=>({get valid(){return t.id&&t.type&&t.key&&t.name?t.type===De.HTTP?!!t.pre_process:!!t.sql:!1},get json(){const{id:e,name:n,type:r,key:i,sql:o,run_by:l,react_to:c,pre_process:u,post_process:d}=t;return Gn({id:e,key:i,sql:o,name:n,type:r,run_by:l,react_to:c,pre_process:u,post_process:d})}})).actions(t=>({setName(e){t.name=e},setKey(e){t.key=e},setType(e){t.type=e},setSQL(e){t.sql=e},setRunBy(e){t.run_by.length=0,t.run_by.push(...e)},setReactTo(e){t.react_to.length=0,t.react_to.push(...e)},setPreProcess(e){t.pre_process=e},setPostProcess(e){t.post_process=e}})),gS=g.types.model("SQLSnippetMeta",{key:g.types.string,value:g.types.string}).views(t=>({get json(){const{key:e,value:n}=t;return{key:e,value:n}}})).actions(t=>({setKey(e){t.key=e},setValue(e){t.value=e}}));var ce=(t=>(t.Select="select",t.MultiSelect="multi-select",t.TreeSelect="tree-select",t.TextInput="text-input",t.Checkbox="checkbox",t.DateRange="date-range",t))(ce||{});const Co=g.types.model("FilterCheckboxConfigMeta",{_name:g.types.literal("checkbox"),description:g.types.optional(g.types.string,""),default_value:g.types.boolean}).views(t=>({get json(){const{_name:e,description:n,default_value:r}=t;return{_name:e,description:n,default_value:r}},get isDescriptionEmpty(){const{description:e}=t;return e===""||e==="<p></p>"}})).actions(t=>({setDefaultValue(e){t.default_value=e},setDescription(e){t.description=e}})),mS=()=>Co.create({_name:"checkbox",description:"",default_value:!1});function So(t,e){return t.map(n=>{try{return n?V.tz(n,"UTC").format(e):null}catch{return console.log(`[date-range] failed parsing ${n}`),null}})}const yS=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(t=>({get json(){const{_name:e,max_days:n,required:r,clearable:i,inputFormat:o,default_value:l,allowSingleDateInRange:c}=t;return{_name:e,max_days:n,required:r,clearable:i,inputFormat:o,default_value:So(l,o),allowSingleDateInRange:c}},truthy(e){return Array.isArray(e)&&e.length===2&&e.every(n=>!!n)}})).views(t=>({getMaxDate(e){const{max_days:n}=t;if(!(!n||!e))return V(e).startOf("day").add(n,"days").toDate()},getMinDate(e){const{max_days:n}=t;if(!(!n||!e))return V(e).startOf("day").subtract(n,"days").toDate()}})).actions(t=>({setFilterValue(e){try{const n=g.getParent(t);g.getRoot(t).filters.setValueByKey(n.key,e)}catch(n){console.error(n)}}})).actions(t=>({setRequired(e){t.required=e},setClearable(e){t.clearable=e},setInputFormat(e){t.inputFormat=e},setDefaultValue(e){t.default_value.length=0,t.default_value.push(...e),t.setFilterValue(e)},setMaxDays(e){t.max_days=e,e>0&&(t.clearable=!0)},setAllowSingleDateInRange(e){t.allowSingleDateInRange=e}})),_o=g.types.snapshotProcessor(yS,{preProcessor({default_value:t,...e}){return{...e,default_value:t.map(n=>n===null?null:V.tz(n,"UTC").toISOString())}},postProcessor(t){const{default_value:e,...n}=t;return{...n,default_value:So(e,n.inputFormat)}}}),bS=()=>_o.create({_name:"date-range",required:!1,inputFormat:"YYYY-MM-DD",clearable:!1,default_value:[null,null]}),jS=g.types.model({label:g.types.string,value:g.types.string}).actions(t=>({setLabel(e){t.label=e},setValue(e){t.value=e}})),wr=g.types.model("FilterConfigModel_BaseSelect",{static_options:g.types.optional(g.types.array(jS),[]),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(t=>({get contentModel(){return g.getRoot(t).content},get usingQuery(){return!!t.options_query_id}})).views(t=>({get options(){if(!t.usingQuery)return t.static_options;const{data:e,state:n,error:r}=t.contentModel.getDataStuffByID(t.options_query_id);return n==="idle"?Array.isArray(e)?e:[]:[]}})).actions(t=>({setRequired(e){t.required=e},addStaticOption(e){t.static_options.push(e)},removeStaticOption(e){t.static_options.splice(e,1)},setDefaultSelectionCount(e){t.default_selection_count=e},setOptionsQueryID(e){t.options_query_id=e??""}})),ko=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),[])}),wr).views(t=>({get json(){const{_name:e,default_value:n,required:r,min_width:i,static_options:o,options_query_id:l,default_selection_count:c}=t;return Gn({_name:e,required:!!r,min_width:i,default_value:n,static_options:o,options_query_id:l,default_selection_count:c})},get default_selection(){return t.usingQuery?t.options.slice(0,t.default_selection_count).map(e=>e.value):t.default_value},truthy(e){return Array.isArray(e)&&e.length>0}})).actions(t=>({setDefaultValue(e){t.default_value=g.cast(e)},setMinWidth(e){t.min_width=e},setDefaultSelection(){const e=g.getRoot(t).content.filters,n=g.getParent(t).key;e.setValueByKey(n,t.default_selection)}})).actions(t=>({afterCreate(){g.addDisposer(t,W.reaction(()=>W.toJS(t.default_selection),t.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),vS=()=>ko.create({_name:"multi-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),To=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,"")}),wr).views(t=>({get json(){const{_name:e,default_value:n,required:r,width:i,static_options:o,options_query_id:l,default_selection_count:c}=t;return Gn({_name:e,width:i,required:r,default_value:n,static_options:o,options_query_id:l,default_selection_count:c})},truthy(e){return!!e},getSelectOption(e){return t.options.find(n=>n.value===e)},get default_selection(){return t.usingQuery?t.default_selection_count>0&&t.options.length>0?t.options[0].value:"":t.default_value}})).actions(t=>({setDefaultValue(e){t.default_value=e},setWidth(e){t.width=e},setDefaultSelection(){const e=g.getRoot(t).content.filters,n=g.getParent(t).key;e.setValueByKey(n,t.default_selection)}})).actions(t=>({afterCreate(){g.addDisposer(t,W.reaction(()=>W.toJS(t.default_selection),t.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),wS=()=>To.create({_name:"select",required:!1,default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),Io=g.types.model("FilterTextInputConfigMeta",{_name:g.types.literal("text-input"),required:g.types.boolean,default_value:g.types.string}).views(t=>({get json(){const{_name:e,required:n,default_value:r}=t;return{_name:e,required:n,default_value:r}},truthy(e){return typeof e!="string"?!1:!!e.trim()}})).actions(t=>({setRequired(e){t.required=e},setDefaultValue(e){t.default_value=e}})),Do=()=>Io.create({_name:"text-input",required:!1,default_value:""});function CS(t){return mc.arrayToTree(t,{id:"value",parentId:"parent_value",childrenField:"children",dataField:null})}function SS(t){return t.map(e=>{const{label:n,description:r,...i}=e,o={...i,filterBasis:`${n}___${r??""}`,description:r,label:n};return r&&(o.label=f.createElement("div",{},[f.createElement(a.Text,{key:0,title:e.label},e.label),f.createElement(a.Text,{key:1,className:"rc-tree-select-tree-title-desc",color:"dimmed",title:e.description},e.description)])),o})}const Mo=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)}),wr).views(t=>({get json(){const{_name:e,default_value:n,required:r,min_width:i,static_options:o,options_query_id:l,default_selection_count:c,treeCheckStrictly:u}=t;return{_name:e,required:!!r,min_width:i,default_value:n,static_options:o,options_query_id:l,treeCheckStrictly:u,default_selection_count:c}},get treeData(){const{data:e}=g.getRoot(t).content.getDataStuffByID(t.options_query_id),n=SS(e);return CS(n)},get errorMessage(){const{error:e}=g.getRoot(t).content.getDataStuffByID(t.options_query_id);return e},get treeDataLoading(){const{state:e}=g.getRoot(t).content.getDataStuffByID(t.options_query_id);return e==="loading"},get defaultSelection(){const{default_selection_count:e}=t;return e?this.treeData.slice(0,e).map(r=>r.value):[]},truthy(e){return Array.isArray(e)&&e.length>0}})).actions(t=>({setDefaultValue(e){t.default_value=g.cast(e)},setMinWidth(e){t.min_width=e},setTreeCheckStrictly(e){t.treeCheckStrictly=e},applyDefaultSelection(){const e=g.getParent(t,1).key;g.getRoot(t).content.filters.setValueByKey(e,t.defaultSelection)},afterCreate(){g.addDisposer(t,W.reaction(()=>JSON.stringify(t.defaultSelection),this.applyDefaultSelection,{fireImmediately:!0,delay:0}))}})),_S=()=>Mo.create({_name:"tree-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),Ao=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",[ce.Select,ce.MultiSelect,ce.TreeSelect,ce.TextInput,ce.Checkbox,ce.DateRange]),config:g.types.union(To,ko,Mo,Io,Co,_o)}).views(t=>({get plainDefaultValue(){const e=t.config.default_value;return Array.isArray(e)?[...e]:e},get usingDefaultValue(){return t.type!==ce.TreeSelect},get auto_submit_supported(){return[ce.Select,ce.Checkbox,ce.DateRange].includes(t.type)}})).views(t=>({get json(){const{id:e,key:n,label:r,order:i,visibleInViewsIDs:o,auto_submit:l,type:c,config:u}=t;return{id:e,key:n,type:c,label:r,order:i,config:u.json,auto_submit:l,visibleInViewsIDs:W.toJS(o)}},get visibleInViewsIDSet(){return new Set(t.visibleInViewsIDs)},get should_auto_submit(){return t.auto_submit_supported&&t.auto_submit},requiredAndPass(e){return y.get(t.config,"required",!1)?y.get(t.config,"truthy",()=>!0)(e):!1}})).actions(t=>({setKey(e){t.key=e},setLabel(e){t.label=e},setOrder(e){t.order=e},setType(e){switch(e){case ce.Select:t.config=wS();break;case ce.MultiSelect:t.config=vS();break;case ce.TreeSelect:t.config=_S();break;case ce.TextInput:t.config=Do();break;case ce.Checkbox:t.config=mS();break;case ce.DateRange:t.config=bS();break}t.type=e},setVisibleInViewsIDs(e){t.visibleInViewsIDs.length=0,t.visibleInViewsIDs.push(...e)},setAutoSubmit(e){t.auto_submit=t.auto_submit_supported&&e}}));var E=(t=>(t.Division="div",t.Modal="modal",t.Tabs="tabs",t))(E||{});const zo=g.types.model("ViewDivisionConfig",{_name:g.types.literal(E.Division)}).views(t=>({get json(){const{_name:e}=t;return{_name:e}}})),kS=()=>zo.create({_name:E.Division}),TS=g.types.model("CustomModalTitleModel",{enabled:g.types.optional(g.types.boolean,!1),func_content:g.types.optional(g.types.string,"")}).views(t=>({get json(){const{enabled:e,func_content:n}=t;return{enabled:e,func_content:n}},get value(){const{enabled:e,func_content:n}=t,r=g.getParent(t,2),i=g.getRoot(t);if(!e)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(t=>({setEnabled(e){t.enabled=e},setFuncContent(e){t.func_content=e},replace({enabled:e,func_content:n}){t.enabled=e,t.func_content=n}})),Cr={enabled:!1,func_content:["function text({ filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
440
- `)},Eo=g.types.model("ViewModalConfig",{_name:g.types.literal(E.Modal),width:g.types.string,height:g.types.string,custom_modal_title:g.types.optional(TS,Cr)}).views(t=>({get json(){const{_name:e,width:n,height:r,custom_modal_title:i}=t;return{_name:e,width:n,height:r,custom_modal_title:i.json}}})).actions(t=>({setWidth(e){t.width=e},setHeight(e){t.height=e}})),IS=()=>Eo.create({_name:E.Modal,width:"90vw",height:"90vh"}),DS=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(t=>({get json(){const{id:e,name:n,view_id:r,color:i}=t;return{id:e,name:n,color:i,view_id:r}}})).actions(t=>({setName(e){t.name=e},setViewID(e){t.view_id=e},setColor(e){t.color=e}})),Po=g.types.model("ViewTabsConfig",{_name:g.types.literal(E.Modal),tabs:g.types.optional(g.types.array(DS),[]),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(t=>({get json(){const{_name:e,variant:n,orientation:r,tabs:i,grow:o}=t;return{grow:o,tabs:i.map(l=>l.json),_name:e,variant:n,orientation:r}}})).actions(t=>({setVariant(e){t.variant=e},setOrientation(e){t.orientation=e},setGrow(e){t.grow=e},setTabs(e){t.tabs.length=0,t.tabs=g.cast(e)},addTab(){const e=pe.randomId(),n={id:e,name:e,view_id:""};t.tabs.push(n)},removeTab(e){t.tabs.splice(e,1)}})),MS=()=>Po.create({_name:E.Modal,tabs:[]}),AS=g.types.model({id:g.types.identifier,name:g.types.string,type:g.types.enumeration("EViewComponentType",[E.Division,E.Modal,E.Tabs]),config:g.types.union(zo,Eo,Po),panelIDs:g.types.optional(g.types.array(g.types.string),[])}).views(t=>({get json(){const{id:e,name:n,type:r,config:i}=t;return{id:e,name:n,type:r,config:i.json,panelIDs:t.panelIDs.map(o=>o)}}})).actions(t=>({setName(e){t.name=e},setType(e){if(t.type!==e){switch(e){case E.Division:t.config=kS();break;case E.Modal:t.config=IS();break;case E.Tabs:t.config=MS();break}t.type=e}},appendPanelID(e){t.panelIDs.push(e)},appendPanelIDs(e){t.panelIDs.push(...e)},removePanelID(e){const n=t.panelIDs.filter(r=>r!==e);t.panelIDs.length=0,t.panelIDs.push(...n)}})),Lo=g.types.model("DataSourceMetaModel",{id:g.types.string,type:g.types.enumeration("DataSourceType",[De.HTTP,De.MySQL,De.Postgresql]),key:g.types.string,config:g.types.frozen()}),zS=g.types.model("DataSourcesMetaModel",{list:g.types.optional(g.types.array(Lo),[])}).views(t=>({find({type:e,key:n}){return t.list.find(r=>r.key===n&&r.type===e)},get options(){return t.list.map(e=>({value:e.key,label:e.key}))}})).actions(t=>({replace(e){t.list.length=0,t.list.push(...e)}})),ES=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}),Bo=g.types.model("GlobalSQLSnippetsMeta",{list:g.types.optional(g.types.array(ES),[])}).views(t=>({find(e){return t.list.find(n=>n.id===e)},get options(){return t.list.map(e=>({value:e.id,label:e.id}))}})).actions(t=>({replace(e){t.list.length=0,t.list.push(...e)}})),Sr=g.types.model("ContextMeta",{current:g.types.optional(g.types.frozen(),{})}).views(t=>({get keys(){return Object.keys(t.current)},get entries(){return Object.entries(t.current)}})).actions(t=>({replace(e){t.current=e},get(e){return t.current[e]},set(e,n){t.current[e]=n}}));function Oo(t){return Sr.create({current:t})}const $o=g.types.compose("ViewRenderModel",AS,g.types.model({tab:g.types.optional(g.types.string,"")})).views(t=>({get defaultTab(){if(t.type!==E.Tabs)return"";const e=t.config;return e.tabs.length>0?e.tabs[0].id:""},get tabViewID(){var n;return t.type!==E.Tabs?"":((n=t.config.tabs.find(r=>r.id===t.tab))==null?void 0:n.view_id)??""},get contentModel(){return g.getParent(t,3)},get panels(){if(t.type!==E.Tabs)return this.contentModel.panels.panelsByIDs(t.panelIDs).panels;const e=this.tabViewID;return this.contentModel.views.findByID(e).panels},get renderViewIDs(){const e=[t.id];return t.type===E.Tabs&&e.push(this.tabViewID),e}})).actions(t=>({setTab(e){t.tab=e??""},afterCreate(){g.addDisposer(t,W.reaction(()=>t.defaultTab,e=>this.setTab(e),{fireImmediately:!0,delay:0}))}})),Vo=g.types.model("ViewsRenderModel",{current:g.types.optional(g.types.array($o),[]),visibleViewIDs:g.types.array(g.types.string)}).views(t=>({get json(){return t.current.map(e=>Gn(e.json))},get idMap(){const e=new Map;return t.current.forEach(n=>{e.set(n.id,n)}),e},findByID(e){return t.current.find(n=>n.id===e)},get firstVisibleView(){const[e]=t.visibleViewIDs;return t.current.find(({id:n})=>n===e)},get visibleViews(){const e=new Set(t.visibleViewIDs);return t.current.filter(({id:n})=>e.has(n))}})).actions(t=>({appendToVisibles(e){new Set(t.visibleViewIDs.map(r=>r)).has(e)||t.visibleViewIDs.push(e)},rmVisibleViewID(e){const n=t.visibleViewIDs.findIndex(r=>r===e);n!==-1&&t.visibleViewIDs.splice(n,1)}}));function PS(t){const e=t.length>0?[t[0].id]:[];return{current:t.map(r=>{const{_name:i=r.type}=r.config;return{...r,config:{...r.config,_name:i},panelIDs:r.panelIDs}}),visibleViewIDs:e}}const LS=new yc.AsyncParser({withBOM:!0});async function No(t){return!Array.isArray(t)||t.length===0?"":await LS.parse(t).promise()}async function BS(t,e){const n=await No(e),r=new Blob([n],{type:"text/csv"});is.saveAs(r,`${t}.csv`)}function qo(t){const e=new bc,n=t.map(async({id:r,data:i})=>{const o=await No(i);e.file(`${r}.csv`,o)});Promise.all(n).then(()=>{e.generateAsync({type:"blob"}).then(r=>{is.saveAs(r,"dashboard_data.zip")})}).catch(r=>{console.error(r),ht.notifications.show({color:"red",title:"Failed to download data",message:r.message})})}function Ct(t,e){const n=new Blob([e],{type:"application/json"});is.saveAs(n,`${t}.json`)}const Fo=xS.views(t=>({get contentModel(){return g.getRoot(t).content}})).views(t=>({get queries(){return t.contentModel.queries.findByIDSet(t.queryIDSet)},get data(){return this.queries.reduce((e,n)=>(e[n.id]=n.data,e),{})},get dataLoading(){return this.queries.some(e=>e.state==="loading")},get queryStateMessages(){const e=this.queries.filter(o=>!o.runByConditionsMet);if(e.length===0)return"";const n=new Set,r=new Set;e.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(e=>e.error).filter(e=>!!e)},get canRenderViz(){return this.queryErrors.length===0&&this.queryStateMessages===""&&!this.dataLoading}})).actions(t=>({refreshData(){t.queries.forEach(e=>e.fetchData(!0))},downloadData(){t.contentModel.queries.downloadDataByQueryIDs(t.queryIDs)},getSchema(){const e=t.json;return e.viz.conf={...e.viz.conf,__INTERACTIONS:{},__OPERATIONS:{},__TRIGGERS:{}},{panel:e,queries:t.queries.map(n=>n.json)}},downloadSchema(){const{panel:e,queries:n}=this.getSchema(),i=JSON.stringify({panels:[e],definition:{queries:n}},null,2),o=t.name;Ct(o,i)}}));function OS(t){return{id:t,name:t,layout:{x:0,y:1/0,w:18,h:300},title:{show:!0},description:"<p></p>",queryIDs:[],viz:{type:ur.name,conf:ur.createConfig()},style:{border:{enabled:!0}}}}const Go=g.types.model("PanelsRenderModel",{list:g.types.optional(g.types.array(Fo),[])}).views(t=>({get json(){return t.list.map(e=>e.json)},findByID(e){return t.list.find(n=>n.id===e)},get idMap(){const e=new Map;return t.list.forEach(n=>{e.set(n.id,n)}),e}})).views(t=>({panelsByIDs(e){const n=[];e.forEach(i=>{const o=t.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 Wo(t,e){if(t===void 0)return t;if(e._name==="date-range")try{const[...n]=t;return n.map(r=>r===null?r:V.tz(r,"UTC").format(e.inputFormat)??r)}catch(n){return console.error(n),t}return t}function $S(t){return t.reduce((e,n)=>(e[n.key]=Wo(n.config.default_value,n.config),e),{})}const Ro=g.types.model("FiltersRenderModel",{current:g.types.optional(g.types.array(Ao),[]),values:g.types.optional(g.types.frozen(),{})}).views(t=>({get json(){return t.current.map(e=>e.json)},get firstID(){if(t.current.length!==0)return t.current[0].id},findByID(e){return t.current.find(n=>n.id===e)},findByIDSet(e){return t.current.filter(n=>e.has(n.id))},get inOrder(){return y.sortBy(t.current,"order")},get empty(){return t.current.length===0},visibleInView(e){return y.sortBy(t.current.filter(n=>n.visibleInViewsIDSet.has(e)),"order")},get firstFilterValueKey(){return Object.keys(t.values)[0]??""},get keySet(){return new Set(t.current.map(e=>e.key))},get keyLabelMap(){return t.current.reduce((e,n)=>(e[n.key]=n.label,e),{})},getSelectOption(e){const n=this.findByID(e);if(!n||!("getSelectOption"in n.config))return null;const r=t.values[n.key];return n.config.getSelectOption(r)}})).actions(t=>({setValues(e){t.values=e},setValueByKey(e,n){t.values={...t.values,[e]:n}},getValueByKey(e){return t.values[e]},getSchema(e,n){return{filters:t.findByIDSet(new Set(e)).map(o=>({...o.json,visibleInViewsIDs:n?o.json.visibleInViewsIDs:[]}))}},downloadSchema(e){const n=JSON.stringify(this.getSchema(e,!1),null,2);Ct("Filters",n)}}));function Qo(t){return{current:t,values:$S(t)}}function VS(t,e){return new Function(`return ${t}`)()(e,gt)}function NS(t,e,n){return VS(t,{context:e,filters:n})}function qS(t,e){try{return new Function(`return ${t.config.processing.pre}`)()(e,gt)}catch(n){return console.error(n),e}}function FS(t,e){return new Function(`return ${t.config.processing.post}`)()(e,gt)}function GS(t,e,n){return t?new Function(`return ${t}`)()(e,gt,n):e}const Wn={sqlSnippet:new RegExp("(?<=sql_snippets\\.)([^\\?}.]+)","gm"),context:new RegExp("(?<=context\\.)([^\\?}.]+)","gm"),filter:new RegExp("(?<=filters\\.)([^\\?}.]+)","gm")},WS=fS.views(t=>({get rootModel(){return g.getRoot(t)},get contentModel(){return this.rootModel.content},get conditionOptions(){if(!g.isAlive(t))return[];const e=g.getRoot(t).content,{context:n}=e.payloadForSQL,r=Object.keys(n).map(o=>({group:"Context",label:o,value:`context.${o}`,description:void 0})),i=e.filters.keyLabelOptions.map(o=>({group:"Filters",label:o.label,value:`filters.${o.value}`,description:o.value}));return[...r,...i]},get unmetRunByConditions(){if(!g.isAlive(t))return[];const{run_by:e}=t;if(e.length===0)return[];const n=g.getRoot(t).content.payloadForSQL;return e.filter(r=>{const i=y.get(n,r);return Array.isArray(i)?i.length===0:typeof i=="number"?Number.isNaN(i):!i})}})).views(t=>({get payload(){return t.contentModel.payloadForSQL},get formattedSQL(){return cs(t.sql,this.payload)},get httpConfigString(){const{context:e,filters:n}=this.payload,{name:r,pre_process:i}=t.json,o=NS(i,e,n);return console.groupCollapsed(`Request config for: ${r}`),console.log(o),console.groupEnd(),JSON.stringify(o)},get typedAsSQL(){return[De.Postgresql,De.MySQL].includes(t.type)},get typedAsHTTP(){return[De.HTTP].includes(t.type)},get reQueryKey(){const{react_to:e=[]}=t;if(e.length===0)return"";const n=g.getRoot(t).content.payloadForSQL,r=[...e].reduce((i,o)=>(i[o]=y.get(n,o),i),{});return JSON.stringify(r)},get runByConditionsMet(){return t.unmetRunByConditions.length===0},get conditionNames(){if(t.unmetRunByConditions.length===0)return{context:[],filters:[]};const{keyLabelMap:e}=g.getRoot(t).content.filters,n=t.unmetRunByConditions.filter(i=>i.startsWith("context.")).map(i=>i.split("context.")[0]),r=t.unmetRunByConditions.filter(i=>i.startsWith("filters.")).map(i=>y.get({filters:e},i)).filter(i=>!!i);return{context:n,filters:r}},get queries(){return g.getParent(t,2)},get inUse(){return this.queries.isQueryInUse(t.id)},get dependencies(){if(!this.typedAsSQL)return[];const e=y.uniq(t.sql.match(Wn.sqlSnippet)),n=y.uniq(t.sql.match(Wn.filter)),r=y.uniq(t.sql.match(Wn.context)),i=[];return e.forEach(o=>{i.push({type:"SQL Snippet",key:o,valid:t.contentModel.sqlSnippets.keySet.has(o)})}),n.forEach(o=>{i.push({type:"Filter",key:o,valid:t.contentModel.filters.keySet.has(o)})}),r.forEach(o=>{i.push({type:"Context",key:o,valid:t.contentModel.mock_context.keySet.has(o)})}),i}})),RS=g.types.compose("QueryRenderModel",WS,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(t=>({get datasource(){const{key:e,type:n}=t;return t.rootModel.datasources.find({type:n,key:e})},get additionalQueryInfo(){return t.contentModel.getAdditionalQueryInfo(t.id)}})).views(t=>({get stateMessage(){if(t.state!=="idle")return"";if(!t.runByConditionsMet){const{context:e,filters:n}=t.conditionNames;if(e.length===0&&n.length===0)return"Waiting";const r=[];return e.length>0&&r.push(`context: ${e.join(", ")}`),n.length>0&&r.push(`filter${n.length>1?"s":""}: ${n.join(", ")}`),r.length===2&&r.splice(1,0,"and"),r.unshift("Waiting for"),r.join(" ")}return t.data.length>0?"":"Empty Data"}})).volatile(()=>({controller:new AbortController})).actions(t=>({runSQL:g.flow(function*(){var e;if(t.valid&&((e=t.controller)==null||e.abort(),!!t.runByConditionsMet)){t.controller=new AbortController,t.state="loading";try{const n=t.payload;t.data=yield*g.toGenerator(pu({payload:n,name:t.name,query:t.json,additionals:t.additionalQueryInfo},t.controller.signal)),t.state="idle",t.error=null}catch(n){if(!tt.isCancel(n)){t.data=[];const r=y.get(n,"message","unkown error");t.error=y.get(n,"response.data.detail.message",r),t.state="error"}}}}),runHTTP:g.flow(function*(){var e;if(!(!t.valid||!t.datasource)&&((e=t.controller)==null||e.abort(),!!t.runByConditionsMet)){t.controller=new AbortController,t.state="loading";try{const{type:n,key:r,post_process:i}=t.json;let o=JSON.parse(t.httpConfigString);o=qS(t.datasource,o);const l=yield*g.toGenerator(hu({type:n,key:r,configString:JSON.stringify(o),name:t.name,additionals:t.additionalQueryInfo},t.controller.signal)),c=FS(t.datasource,l),u=GS(i,c,t.contentModel.dashboardState);t.data=u,t.state="idle",t.error=null}catch(n){if(console.error(n),!tt.isCancel(n)){t.data=[];const r=y.get(n,"message","unkown error");t.error=y.get(n,"response.data.detail.message",r),t.state="error"}}}})})).actions(t=>({fetchData:e=>{if(!t.inUse&&!e){console.debug(`Skipping query[${t.name}]`);return}return t.typedAsHTTP?t.runHTTP():t.runSQL()},beforeDestroy(){var e;(e=t.controller)==null||e.abort()}})).actions(t=>({afterCreate(){g.addDisposer(t,W.reaction(()=>{var n;return t.typedAsHTTP?`${t.inUse}--${t.id}--${t.key}--${t.reQueryKey}--${(n=t.datasource)==null?void 0:n.id}`:[t.inUse,t.id,t.key,t.formattedSQL,t.pre_process,t.post_process].join("--")},()=>t.fetchData(!1),{fireImmediately:!0,delay:0}))}})),Yo=g.types.model("QueriesRenderModel",{current:g.types.optional(g.types.array(RS),[])}).views(t=>({get idSet(){return new Set(t.current.map(e=>e.id))},get firstID(){if(t.current.length!==0)return t.current[0].id},findByID(e){return t.current.find(n=>n.id===e)},findByIDSet(e){return t.current.filter(n=>e.has(n.id))},get json(){return t.current.filter(e=>e.id&&e.key).map(e=>e.json)},get contentModel(){return g.getParent(t,1)},get visibleQueryIDSet(){const{views:e,filters:n}=this.contentModel,r=[];e.visibleViews.forEach(l=>{l.panels.forEach(c=>{r.push(...c.queryIDs)})});const i=y.uniq(e.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(e){return this.visibleQueryIDSet.has(e)}})).actions(t=>({downloadAllData(){const e=t.current.map(({name:n,data:r})=>({id:n,data:r}));qo(e)},downloadDataByQueryIDs(e){const n=new Set(e),r=t.current.filter(i=>n.has(i.id)).map(({name:i,data:o})=>({id:i,data:o}));qo(r)},downloadDataByQueryID(e){const n=t.findByID(e);if(!n){console.log("[downloadDataByQueryID] query not found");return}const{name:r,data:i}=n;BS(r,i)},refetchDataByQueryID(e){const n=t.findByID(e);if(!n){console.error(new Error(`[downloadDataByQueryID] query by ID[${e}] not found`));return}return n.fetchData(!0)},getSchema(e){return{definition:{queries:t.findByIDSet(new Set(e)).map(i=>i.json)}}},downloadSchema(e){const n=JSON.stringify(this.getSchema(e),null,2);Ct("Queries",n)}}));function QS(t){return{current:t}}const YS=gS.views(t=>({isADuplicatedKey(e){return!e||e===t.key?!1:!!g.getParent(t,2).findByKey(e)}})),Ko=g.types.model("SQLSnippetsRenderModel",{current:g.types.optional(g.types.array(YS),[])}).views(t=>({get json(){return t.current.map(e=>e.json)},get record(){return t.current.reduce((e,n)=>(e[n.key]=n.value,e),{})},get keySet(){return new Set(t.current.map(e=>e.key))},get firstKey(){if(t.current.length!==0)return t.current[0].key},findByKey(e){return t.current.find(n=>n.key===e)},findByKeySet(e){return t.current.filter(n=>e.has(n.key))}})).actions(t=>({getSchema(e){return{definition:{sqlSnippets:t.findByKeySet(new Set(e)).map(i=>i.json)}}},downloadSchema(e){const n=JSON.stringify(this.getSchema(e),null,2);Ct("SQL Snippets",n)}}));function KS(t){return{current:t}}function Rn(t,e,n,r){return t.reduce((i,o)=>{try{i[o[e]]=ls(o[n],r)}catch(l){i[o[e]]=l.message}return i},{})}class US{constructor(e){z(this,"origin");z(this,"copy");this.origin=e,this.copy=g.clone(e),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))}update(e){g.applySnapshot(this.copy,e)}}const XS=t=>new US(t),JS=S.observer(({view:t})=>{const e=U(),n=X(),r=Me.useModals(),{panel:i,downloadPanelScreenshot:o}=Be(),{id:l}=i,{viewPanelInFullScreen:c,inFullScreen:u}=f.useContext(Fn),d=()=>{n.duplicatePanelByID(l,t.id)},h=()=>{e.editor.open(["_VIEWS_",t.id,"_PANELS_",l])},p=()=>r.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>n.removePanelByID(l,t.id),confirmProps:{color:"red"},zIndex:320}),x=f.useCallback(()=>{c(l)},[l,c]),m=!u&&t.type!==E.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:h,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:p,icon:s.jsx(_.Trash,{size:14}),children:"Delete"})]})]})})})});function ZS(t){return t?["<p><br></p>","<p></p>"].includes(t):!0}const _r=S.observer(()=>{const[t,e]=f.useState(!1),{panel:n}=ut();return ZS(n.description)?null:s.jsxs(s.Fragment,{children:[s.jsx(a.Modal,{opened:t,onClose:()=>e(!1),title:n.name,withCloseButton:!1,withinPortal:!0,zIndex:310,children:s.jsx(Tn,{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:()=>e(r=>!r),sx:{verticalAlign:"baseline",cursor:"pointer"},children:s.jsx(_.InfoCircle,{size:20})})})]})}),ZI="",HS=S.observer(function(){const{panel:e}=ut(),{name:n,title:r}=e;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 e1(t){const e=f.useRef(null);return{ref:e,downloadPanelScreenshot:()=>{const r=e.current;if(!r)return;const i=r.offsetWidth*2,o=r.offsetHeight*2;pi.toBlob(e.current,{bgcolor:"white",width:i,height:o,style:{border:"none",borderRadius:0,transformOrigin:"0 0",transform:"scale(2)"}}).then(l=>{window.saveAs(l,`${t.name?t.name:t.viz.type}.png`)})}}}var Uo=(t=>(t.migrated="migrated",t.nothingToMigrate="nothingToMigrate",t.checkFailed="checkFailed",t.migrationFailed="migrationFailed",t))(Uo||{}),Qn=(t=>(t.notStarted="notStarted",t.inProgress="inProgress",t.done="done",t))(Qn||{});class t1{constructor(e){z(this,"vizInstance");z(this,"operationManager");z(this,"triggerManager");z(this,"vizManager");z(this,"runningMigration");z(this,"panelModel");z(this,"status","notStarted");this.panelModel=e.getRequired(le.instanceScope.panelModel),this.vizInstance=e.getRequired(le.instanceScope.vizInstance),this.operationManager=e.getRequired(le.instanceScope.operationManager),this.triggerManager=e.getRequired(le.instanceScope.triggerManager),this.vizManager=e.getRequired(le.vizManager)}async createMigrationTask(){const e=[];try{await this.instanceNeedMigration()&&e.push(()=>this.runInstanceMigration()),await this.interactionNeedMigration()&&e.push(()=>this.runInteractionMigration())}catch(n){return console.warn("check migration failed",n),"checkFailed"}if(e.length===0)return"nothingToMigrate";try{return await Promise.all(e.map(n=>n())),"migrated"}catch(n){return console.warn("migration failed",n),"migrationFailed"}}async runMigration(){return this.runningMigration||(this.status="inProgress",this.runningMigration=this.createMigrationTask().then(e=>(this.status="done",e))),this.runningMigration}async runInteractionMigration(){await this.operationManager.runMigration(),await this.triggerManager.runMigration()}async runInstanceMigration(){const e=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData,panelModel:this.panelModel};await e.migrator.migrate(n)}async instanceNeedMigration(){const e=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData};return e.migrator.needMigration(n)}async interactionNeedMigration(){return await this.operationManager.needMigration()||await this.triggerManager.needMigration()}}function Xo(t){const{panel:e}=ut();return f.useCallback(n=>{const r=n.getRequired(le.vizManager),i=r.resolveComponent(t.viz.type);return n.createScoped().provideFactory(le.instanceScope.vizInstance,()=>r.getOrCreateInstance(t)).provideFactory(le.instanceScope.interactionManager,o=>{const l=o.getRequired(le.instanceScope.vizInstance);return new Ss(l,i,xn)}).provideFactory(le.instanceScope.operationManager,o=>o.getRequired(le.instanceScope.interactionManager).operationManager).provideFactory(le.instanceScope.triggerManager,o=>o.getRequired(le.instanceScope.interactionManager).triggerManager).provideValue(le.instanceScope.panelModel,e).provideFactory(le.instanceScope.migrator,o=>new t1(o))},[t.viz.type,t.viz.conf])}function Jo(t){const[e,n]=f.useState(!1),r=mo().getRequired(le.instanceScope.migrator);return $.useAsyncEffect(async()=>{const i=r.status===Qn.notStarted;n(r.status===Qn.done),r.status===Qn.notStarted&&r.runMigration().then(o=>{o===Uo.migrated&&i&&(t==null||t())}).finally(()=>{n(!0)})},[r]),e}function Zo(t,e){const n=mo().getRequired(le.instanceScope.vizInstance);return f.useEffect(()=>(n.instanceData.setItem(null,e.viz.conf),n.instanceData.watchItem(null,r=>{t(r)})),[t,e.viz.type]),n}function n1({setVizConf:t,...e}){const{panel:n}=e,r=Zo(t,n),i=Jo(()=>{ht.showNotification({title:`${n.name} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})});return $.useAsyncEffect(async()=>{await r.instanceData.setItem(null,n.viz.conf)},[r,n.viz.type]),i?s.jsx(mu,{...e}):s.jsx(a.Text,{children:"Checking update..."})}function s1(t){const{panel:e,setVizConf:n}=t;Zo(n,e);const{inEditMode:r}=f.useContext(pn);return Jo(()=>{r&&ht.showNotification({title:`${e.name} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?s.jsx(gu,{...t}):s.jsx(a.Text,{children:"Checking update"})}const HI="";function r1(t,e){const{vizManager:n}=f.useContext(et),{panel:{viz:r,title:i,id:o,name:l,description:c,queryIDs:u,variables:d}}=ut(),h={id:o,name:l,title:i,description:c,queryIDs:u,viz:r,layout:e},p=Xo(h);try{return n.resolveComponent(r.type),s.jsx(qn,{configure:p,children:s.jsx(s1,{setVizConf:r.setConf,panel:h,data:t,variables:d,vizManager:n})})}catch(x){return console.info(y.get(x,"message")),null}}const Ho=S.observer(function({data:e}){const{ref:n,width:r,height:i}=pe.useElementSize(),o=r1(e,{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})})})}),el=S.observer(({panel:t})=>s.jsxs(a.Stack,{children:[t.queryErrors.map((e,n)=>s.jsx(a.Text,{color:"red",size:"sm",align:"center",sx:{fontFamily:"monospace"},children:e},`${n}-${e}`)),s.jsx(a.Text,{color:"gray",align:"center",size:"sm",children:t.queryStateMessages})]})),kr=S.observer(({panel:t})=>s.jsxs(a.Flex,{className:"panel-viz-section",direction:"column",sx:{position:"relative",width:"100%"},children:[s.jsx(a.LoadingOverlay,{visible:t.dataLoading,exitTransitionDuration:0}),!t.canRenderViz&&s.jsx(el,{panel:t}),t.canRenderViz&&s.jsx(Ho,{data:t.data})]})),i1={border:"1px solid #e9ecef"},tl=S.observer(({panel:t,panelStyle:e,dropdownContent:n})=>{const{ref:r,downloadPanelScreenshot:i}=e1(t);return t.title.show,s.jsx(js,{value:{panel:t,data:t.data,loading:t.dataLoading,errors:t.queryErrors,downloadPanelScreenshot:i},children:s.jsxs(a.Box,{className:`panel-root ${t.title.show?"panel-root--show-title":""}`,ref:r,p:0,sx:{...i1,...e},children:[s.jsx(a.Box,{className:"panel-description-popover-wrapper",children:s.jsx(_r,{})}),n,s.jsx(HS,{}),s.jsx(kr,{panel:t})]})})}),a1={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function o1(t){return t.style.border.enabled?{}:a1}const nl=S.observer(function({panel:e,view:n}){const r=o1(e);return s.jsx(tl,{panel:e,panelStyle:r,dropdownContent:s.jsx(JS,{view:n})})});function l1(t){return!["richText","button"].includes(t)}const c1=S.observer(({view:t})=>{const{panel:e,downloadPanelScreenshot:n}=ut(),{id:r}=e,{viewPanelInFullScreen:i,inFullScreen:o}=f.useContext(Fn),l=f.useCallback(()=>{i(r)},[r,i]),c=!o&&t.type!==E.Modal;return l1(e.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:e.refreshData,icon:s.jsx(_.Refresh,{size:14}),children:"Refresh"}),s.jsx(a.Menu.Item,{onClick:e.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 u1(t){return t.style.border.enabled?{}:{border:"1px dashed transparent"}}const Tr=S.observer(({panel:t,view:e})=>{const n=u1(t);return s.jsx(tl,{panel:t,panelStyle:n,dropdownContent:s.jsx(c1,{view:e})})}),d1={modal:{display:"flex",flexDirection:"column",flexWrap:"nowrap"},body:{display:"flex",height:"calc(100vh - 88px)"}},sl=S.observer(function({view:e,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:d1,children:s.jsx(a.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:s.jsx(Tr,{view:e,panel:n})})})});function rl(t,e,n){const{panels:r}=oe(),i=t.id==="Main",[o,l]=f.useState(()=>i&&r.findByID(e)?e:null),c=f.useCallback(p=>{l(p),i&&n(p)},[i,n]),u=f.useCallback(()=>{l(null),i&&n("")},[i,n]),d=o?r.findByID(o):null;return{viewPanelInFullScreen:c,exitFullScreen:u,inFullScreen:!!d,fullScreenPanel:d}}const eD="",p1=f.forwardRef(({h:t},e)=>s.jsx(a.ActionIcon,{ref:e,className:"react-grid-customDragHandle",sx:{userSelect:"none",cursor:"grab",position:"absolute",top:5,right:t>38?5:20,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",children:s.jsx(_.ArrowsMove,{size:16})})),h1=f.forwardRef(({handleAxis:t,...e},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",...e,children:s.jsx(_.ChevronDownRight,{size:16})})),x1=ln.WidthProvider(ln),f1=S.observer(({view:t,className:e="layout"})=>{const n=oe(),{panels:r,layouts:i}=n.panels.panelsByIDs(t.panelIDs),o=f.useCallback(c=>{c.forEach(({i:u,...d})=>{const h=n.panels.findByID(u);h&&h.layout.set(d)})},[n]),l=(c,u,d,h)=>{d.h<30&&(d.h=30,h.h=30),d.w<4&&(d.w=4,h.w=4)};return s.jsx(x1,{onLayoutChange:o,className:`dashboard-layout ${e}`,rowHeight:1,cols:36,margin:[0,0],isBounded:!0,isDraggable:!0,isResizable:!0,layout:i,draggableHandle:".react-grid-customDragHandle",resizeHandle:s.jsx(h1,{}),onResize:l,children:r.map((c,u)=>s.jsxs("div",{"data-grid":{...c.layout},className:"panel-grid-item",children:[s.jsx(p1,{h:c.layout.h}),s.jsx(nl,{view:t,panel:c})]},c.id))})}),g1=ln.WidthProvider(ln),m1=S.observer(function({view:e,className:n="layout"}){const{panels:r,layouts:i}=oe().panels.panelsByIDs(e.panelIDs);return s.jsx(g1,{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(Tr,{view:e,panel:o})},o.id))})});function Ir(t){const e=f.useRef(null);return{ref:e,downloadScreenshot:()=>{var l;const r=(l=e.current)==null?void 0:l.querySelector(".react-grid-layout");if(!r)return;const i=r.offsetWidth*2+10,o=r.offsetHeight*2+10;pi.toBlob(r,{bgcolor:"white",width:i,height:o,style:{transformOrigin:"0 0",transform:"scale(2)"}}).then(c=>{window.saveAs(c,`${t.name}.png`)})}}}const y1=S.observer(({downloadScreenShot:t})=>{const[e,{setTrue:n,setFalse:r}]=$.useBoolean(!1),i=ms(),o=oe(),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:e?1:.6,transform:`translateX(${e?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:t,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"})]})]})}),il=S.observer(({children:t,view:e,sx:n={}})=>{const{ref:r,downloadScreenshot:i}=Ir(e);return s.jsxs(s.Fragment,{children:[s.jsx(a.Box,{ref:r,sx:n,children:t}),s.jsx(y1,{downloadScreenShot:i})]})}),al=S.observer(({downloadScreenshot:t})=>s.jsx(a.ActionIcon,{className:"download-screenshot-button",color:"blue",onClick:t,children:s.jsx(k.IconCamera,{size:14})})),b1=S.observer(({children:t,view:e})=>{const n=oe(),r=e.config,i=n.views.visibleViewIDs.includes(e.id),o=()=>n.views.rmVisibleViewID(e.id),{ref:l,downloadScreenshot:c}=Ir(e);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(al,{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:t})})}),j1=t=>t.color?{"&[data-active], &[data-active]:hover":{borderColor:t.color?t.color:"..."}}:{},v1=S.observer(({view:t})=>{const e=oe(),n=t.config;return s.jsxs(a.Tabs,{className:"render-view-tabs",variant:n.variant,orientation:n.orientation,value:t.tab,onTabChange:t.setTab,styles:{root:{height:"100%",overflow:n.orientation==="horizontal"?"hidden":"auto"},panel:{padding:n.orientation==="horizontal"?"8px 0px 8px":"0",height:"100%",overflow:"auto"}},keepMounted:!1,children:[s.jsx(a.Tabs.List,{grow:n.grow,children:n.tabs.map(r=>s.jsx(a.Tabs.Tab,{value:r.id,sx:j1(r),disabled:!r.view_id,children:r.name??r.id},r.id))}),n.tabs.map(r=>{const i=e.views.findByID(r.view_id);return i?s.jsx(a.Tabs.Panel,{value:r.id,children:s.jsx(Yn,{view:i})},r.id):null})]})}),w1=S.observer(({view:t,children:e})=>{switch(t.type){case E.Modal:return s.jsx(b1,{view:t,children:e});case E.Tabs:return s.jsx(v1,{view:t});case E.Division:default:return s.jsx(il,{view:t,children:e})}}),C1=S.observer(({children:t,view:e})=>s.jsx(il,{sx:{paddingTop:"10px",paddingBottom:"100px"},view:e,children:t}));function ol(t){return t.replace(/(vw|vh)/,"%")}const S1=S.observer(({children:t,view:e})=>{const n=e.config,{width:r,height:i}=f.useMemo(()=>({width:ol(n.width),height:ol(n.height)}),[n.width,n.height]),{ref:o,downloadScreenshot:l}=Ir(e);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(al,{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:t})})})}),_1=({variant:t,orientation:e})=>{const n={root:{height:"100%",overflow:"hidden"},tab:{},panel:{padding:"16px"}};return t==="pills"&&e==="horizontal"&&(n.tab.paddingTop="6px",n.tab.paddingBottom="6px"),e==="vertical"&&(n.tab["&.add-a-tab"]={paddingTop:"1px",paddingBottom:"1px"},n.tab["&.add-a-tab .mantine-Tabs-tabLabel"]={marginLeft:"auto",marginRight:"auto"}),n},k1=t=>t.color?{"&[data-active], &[data-active]:hover":{borderColor:t.color?t.color:"..."}}:{},T1=S.observer(({view:t})=>{const e=Me.useModals(),n=X(),r=f.useMemo(()=>n.views.options.filter(c=>c.type===E.Division),[t.id,n.views.options]),i=t.config,o=c=>e.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:t.tab,onTabChange:t.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:k1(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:h=>c.setName(h.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(Yn,{view:d})]},c.id)})]})}),I1=S.observer(({view:t,children:e})=>{switch(t.type){case E.Modal:return s.jsx(S1,{view:t,children:e});case E.Tabs:return s.jsx(T1,{view:t});case E.Division:default:return s.jsx(C1,{view:t,children:e})}}),ll=S.observer(function({view:e}){return s.jsx(Fn.Provider,{value:{viewPanelInFullScreen:y.noop,inFullScreen:!1},children:s.jsx(a.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:s.jsx(I1,{view:e,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(jo,{view:e})}),s.jsx(f1,{view:e})]})})})})}),Yn=S.observer(function({view:e}){const{fullScreenPanelID:n,setFullScreenPanelID:r}=zi(),{viewPanelInFullScreen:i,exitFullScreen:o,inFullScreen:l,fullScreenPanel:c}=rl(e,n,r);return s.jsx(Fn.Provider,{value:{viewPanelInFullScreen:i,inFullScreen:l},children:s.jsxs(a.Box,{className:"dashboard-view","data-enable-scrollbar":!0,sx:{height:e.type===E.Modal?"0 !important":"100%"},children:[l&&s.jsx(sl,{view:e,panel:c,exitFullScreen:o}),s.jsx(w1,{view:e,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(jo,{view:e})}),!l&&s.jsx(m1,{view:e})]})})]})})});var cl=(t=>(t.Use="use",t.Edit="edit",t))(cl||{});const D1={[E.Division]:"Division",[E.Tabs]:"Tabs",[E.Modal]:"Modal"},ul={[E.Division]:"rgba(255, 0, 0, 0.2)",[E.Modal]:"rgba(0, 0, 0, 0.2)",[E.Tabs]:"rgba(255, 200, 100, 0.4)"},M1={[E.Division]:"#ff4000",[E.Modal]:"#000",[E.Tabs]:"#ffad18"},A1={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:E.Division,config:{},panelIDs:[]}],panels:[],filters:[],version:"9.19.0"};function z1(t,e,n){g.addDisposer(t,g.addMiddleware(t,(r,i)=>{i(r,()=>{g.getType(r.context)===e&&r.type==="action"&&n(r.name,r.context)})}))}const dl=g.types.compose("FiltersModel",Ro,g.types.model("FiltersModel",{previewValues:g.types.optional(g.types.frozen(),{})})).views(t=>({get idSet(){return new Set(t.current.map(e=>e.id))},get keySet(){return new Set(t.current.map(e=>e.key))},get options(){return t.current.map(e=>({label:e.label??e.id,value:e.id,_type:"filter"}))},get selects(){return t.current.filter(e=>e.type===ce.Select).map(e=>({label:e.label??e.id,value:e.id}))},get keyLabelOptions(){return t.current.map(e=>({label:e.label??e.key,value:e.key}))},get sortedList(){return y.sortBy(t.current,e=>e.label.toLowerCase())}})).actions(t=>({replace(e){t.current=g.cast(e)},append(e){t.current.push(e)},appendMultiple(e){if(e.length===0)return;const n=e.filter(r=>!t.idSet.has(r.id));t.current.push(...n)},remove(e){t.current.splice(e,1)},removeByID(e){const n=t.current.findIndex(r=>r.id===e);n>=0&&t.current.splice(n,1)},updatePreviewValues(e){t.previewValues=e}})).actions(t=>{function e(){z1(t.current,Ao,(n,r)=>{if(n==="setType"){const i=Wo(r.config.default_value,r.config);t.setValueByKey(r.key,i),t.updatePreviewValues({...t.previewValues,[r.key]:i})}})}return{afterCreate(){e()}}}),pl=Yo.views(t=>({get options(){const e=t.current.map(n=>({value:n.id,label:n.name,_type:"query"}));return y.sortBy(e,n=>n.label.toLowerCase())},get sortedList(){return y.sortBy(t.current,e=>e.name.toLowerCase())}})).actions(t=>({replace(e){t.current=g.cast(e)},append(e){t.current.push(e)},appendMultiple(e){if(e.length===0)return;const n=e.filter(r=>!t.idSet.has(r.id));t.current.push(...n)},remove(e){t.current.splice(e,1)},replaceByIndex(e,n){t.current.splice(e,1,n)},removeQuery(e){const n=t.current.find(r=>r.id===e);n&&(g.detach(n),t.current.remove(n))},removeQueries(e){const n=new Set(e);t.current.forEach(i=>{n.has(i.id)&&g.detach(i)});const r=[...t.current];y.remove(r,i=>n.has(i.id)),t.current=g.cast(r)}})),hl=Ko.views(t=>({get sortedList(){return y.sortBy(t.current,e=>e.key.toLowerCase())},get options(){const e=t.current.map(n=>({label:n.key,value:n.key,_type:"sql_snippet"}));return y.sortBy(e,n=>n.label.toLowerCase())}})).actions(t=>({replace(e){t.current=g.cast(e)},append(e){t.current.push(e)},appendMultiple(e){if(e.length===0)return;const n=e.filter(r=>!t.keySet.has(r.key));t.current.push(...n)},remove(e){t.current.splice(e,1)},removeByKey(e){const n=t.current.findIndex(r=>r.key===e);n>=0&&t.current.splice(n,1)},removeByKeys(e){const n=new Set(e);t.current.forEach(i=>{n.has(i.key)&&g.detach(i)});const r=[...t.current];y.remove(r,i=>n.has(i.key)),t.current=g.cast(r)},replaceByIndex(e,n){t.current.splice(e,1,n)}})),E1=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(t=>({get loading(){return t.state==="loading"},get empty(){return t.data.length===0}})),P1=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(t=>({get loading(){return t.state==="loading"},get empty(){return t.data.length===0}})),L1=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(t=>({get keywords(){return g.getParent(t,1)},get keywordString(){const{table_name:e,table_schema:n}=g.getParent(t,1);return`${n}||${e}`}})).views(t=>({get loading(){return t.state==="loading"},get empty(){return t.data.length===0},get maxPage(){return Math.ceil(t.total/t.limit)},get offset(){return(t.page-1)*t.limit},get countSql(){const{table_name:e,table_schema:n}=t.keywords;return`
439
+ `}}}function kC(t,e){const n=Bt(t.heat_block.min,e),r=Bt(t.heat_block.max,e);return{min:n,max:r,calculable:!0,orient:"horizontal",left:"center",top:0,itemWidth:15}}function TC(t,e,n){const r=D(t.x_axis.data_key),i=y.uniq(e[r.queryID].map(u=>u[r.columnKey])),{overflow:o,rotate:l}=t.x_axis.axisLabel,c=Qe(o.on_axis);return{id:"main-x-axis",type:"category",data:i,name:t.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 IC(t,e,n){const r=D(t.x_axis.data_key),i=D(t.y_axis.data_key),{nameAlignment:o,data_key:l,...c}=t.y_axis,u=y.uniq(e[r.queryID].map(x=>x[i.columnKey])),{overflow:d,rotate:p}=t.y_axis.axisLabel,h=Qe(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 DC={tooltip:{confine:!0}};function MC(t,e,n){if(!t.x_axis.data_key||!t.y_axis.data_key||!t.heat_block.data_key)return{};const r=n.reduce((c,u)=>{const d=it(u,e);return c[u.name]=Ne(u,d),c},{}),i=bC(t),o=jC(t),l={xAxis:TC(t,e,i.x_axis),yAxis:IC(t,e,i.y_axis),series:wC(t,e),tooltip:_C(t,e,i,o),grid:vC(t),visualMap:kC(t,r)};return y.defaultsDeep({},l,DC)}Y.use([P.DataZoomComponent,te.HeatmapChart,P.GridComponent,P.LegendComponent,P.TooltipComponent,P.VisualMapComponent,we.CanvasRenderer]);function AC({conf:t,data:e,width:n,height:r,interactionManager:i,variables:o}){const l=f.useMemo(()=>{const h=D(t.x_axis.data_key),x=D(t.y_axis.data_key);return y.keyBy(e[h.queryID],m=>`${m[h.columnKey]}---${m[x.columnKey]}`)},[e,t.x_axis.data_key,t.y_axis.data_key]),c=$e(i.triggerManager,fo.id),u=f.useCallback(h=>{const[x,m]=h.value,j=y.get(l,`${x}---${m}`,{error:"rowData is not found"});c.forEach(C=>{i.runInteraction(C.id,{...h,rowData:j})})},[l,c,i]),d=f.useMemo(()=>({click:u}),[u]),p=f.useMemo(()=>MC(t,e,o),[t,e]);return s.jsx(ve,{echarts:Y,option:p,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function zC({context:t,instance:e}){const n=Ve({vizManager:t.vizManager,instance:e}),{value:r}=O(t.instanceData,"config"),{variables:i}=t,o=f.useMemo(()=>y.defaults({},r,br),[r]),l=t.data,{width:c,height:u}=t.viewport;return!c||!u?null:s.jsx(Te,{width:c,height:u,children:s.jsx(AC,{variables:i,width:We(c),height:Re(u),data:l,conf:o,interactionManager:n})})}class EC extends re{constructor(){super(...arguments);z(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const PC={displayName:"Merico Heatmap",displayGroup:"Merico suite",migrator:new EC,name:"merico-heatmap",viewRender:zC,configRender:gC,createConfig:()=>({version:1,config:br}),triggers:[fo]},LC=[{value:"#25262B",name:"Dark"},{value:"#868E96",name:"Gray"},{value:"#FA5252",name:"Red"},{value:"#E64980",name:"Pink"},{value:"#BE4BDB",name:"Grape"},{value:"#7950F2",name:"Violet"},{value:"#4C6EF5",name:"Indigo"},{value:"#228BE6",name:"Blue"},{value:"#15AABF",name:"Cyan"},{value:"#12B886",name:"Teal"},{value:"#40C057",name:"Green"},{value:"#82C91E",name:"Lime"},{value:"#FAB005",name:"Yellow"},{value:"#FD7E14",name:"Orange"}].map(t=>({name:t.name,value:t.value,type:"single",category:"basic"})),BC=[mu,yu,vu,ju,bu,wu],mo=()=>({id:"dashboard",version:_i,manifest:{viz:[ur,jj,Rv,Jy,Fj,Fm,x0,Bu,Cp,hg,Xg,Iw,Dm,Wf,lj,hy,Fy,Hv,Q0,PC,aC,Op],color:[...LC,...BC]}}),nn=new ku,le={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")}},jr=()=>{try{nn.install(mo())}catch{}const t=new xu(nn),e=new _u(nn);return{pluginManager:nn,vizManager:t,colorManager:e}},et=f.createContext(jr());try{nn.install(mo())}catch{}const vr=f.createContext(null);function Nn(t){const e=f.useContext(vr),n=$.useCreation(()=>t.configure(e||new ps),[t.configure]),r=$.usePrevious(n);return r&&r!==n&&r.dispose(),s.jsx(vr.Provider,{value:n,children:t.children})}function yo(){return f.useContext(vr)}const OC=({description:t,isDescriptionEmpty:e})=>e?null:s.jsx(a.Tooltip,{color:"white",label:s.jsx(An,{value:t,styles:{root:{border:"none"},content:{padding:0}}}),styles:{tooltip:{border:"0.0625rem solid rgb(233, 236, 239)",boxShadow:"rgb(0 0 0 / 5%) 0px 0.0625rem 0.1875rem, rgb(0 0 0 / 5%) 0px 1.25rem 1.5625rem -0.3125rem, rgb(0 0 0 / 4%) 0px 0.625rem 0.625rem -0.3125rem"}},withArrow:!0,children:s.jsx(a.Box,{sx:{height:"16px",alignSelf:"center"},children:s.jsx(k.IconInfoCircle,{size:16,color:"gray"})})}),$C=S.observer(({label:t,config:{default_value:e,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:t}),s.jsx(OC,{description:n,isDescriptionEmpty:r})]}),checked:o||!1,onChange:c=>l(c.currentTarget.checked),...i,pt:".4em",styles:{input:{borderColor:"#e9ecef"}}})]})),bo=S.observer(({label:t,config:e,value:n=[null,null],onChange:r})=>{const{inputFormat:i,...o}=e,l=Array.isArray(n)?n.map(p=>p?V(p).toDate():null):[null,null],c=p=>{r(p.map(h=>h&&V(h).format(i)))},u=e.getMinDate(l[0]),d=e.getMaxDate(l[0]);return s.jsx(fc.DatePickerInput,{type:"range",label:t,value:l,onChange:c,icon:s.jsx(_.Calendar,{size:16}),sx:{minWidth:"16em"},minDate:u,maxDate:d,valueFormat:i,styles:{input:{borderColor:"#e9ecef"}},...o})}),VC=a.createStyles((t,{radius:e=4})=>({root:{borderRadius:t.fn.radius(e),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-select.rc-select-open":{borderColor:"#228be6 !important",".rc-select-selection-overflow-item-rest":{display:"none"},".rc-select-selection-overflow-item-suffix":{display:"block"}},".rc-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-select-selection-search-mirror":{display:"none"},".rc-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:t.fontSizes.sm,fontWeight:500,color:"#212529"},required:{color:"#fa5252",paddingLeft:"3px"},dropdown:{fontSize:t.fontSizes.xs,zIndex:300,backgroundColor:"#fff",border:"1px solid #e9ecef",marginTop:6,padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px","&.rc-select-dropdown-slide-up-leave-active":{display:"none"},".rc-select-item-empty":{padding:"8px 12px"},".rc-select-item-option":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"8px 12px 8px 2px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},flexDirection:"row-reverse",".rc-select-item-option-state":{flexGrow:0,flexShrink:0,width:"30px",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},".rc-select-item-option-content":{width:"calc(100% - 30px)",overflow:"hidden",'div[data-role="label"]':{overflowWrap:"break-word"}}},".rc-virtual-list-holder-inner":{alignItems:"flex-start"}}})),jo=({errorMessage:t})=>t?s.jsx(a.Text,{color:"red",size:12,children:t}):s.jsx(a.Text,{color:"dimmed",size:12,children:"Not found"}),NC=({disabled:t,classNames:e,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}=VC({radius:i},{name:"MultiSelectWidget",classNames:e,styles:n,unstyled:r}),[j,C]=f.useState(!1),T=Q=>{C(Q)},A=j&&(c==null?void 0:c.length)>0,[L,U]=f.useState(""),se=f.useMemo(()=>{if(!L)return d;const Q=L.toLowerCase(),ie=ue=>{var fe;return((fe=ue.description)==null?void 0:fe.toLowerCase().includes(Q))||ue.label.toLowerCase().includes(Q)};return d.filter(ie)},[L,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:"*"})]}),A&&s.jsx(a.Tooltip,{label:`${c.length} selected`,children:s.jsx(a.Badge,{children:c.length})})]}),s.jsx(di,{disabled:t,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(jo,{errorMessage:p}),maxTagTextLength:10,maxTagPlaceholder:Q=>`${Q.length} selected`,searchValue:L,onSearch:U,filterOption:!1,children:se.map(Q=>s.jsxs(di.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))})]})},qC=S.observer(({label:t,config:e,value:n,onChange:r})=>{const i=oe(),o=!!e.options_query_id,{state:l,error:c}=i.getDataStuffByID(e.options_query_id),u=l==="loading",d=e.min_width?e.min_width:"200px",p=o?u:!1,h=x=>r(x,!1);return s.jsx(NC,{label:t,options:e.options,style:{minWidth:"160px",width:d,maxWidth:p?d:"unset",borderColor:"#e9ecef"},disabled:p,value:n,onChange:h,errorMessage:c,required:e.required})}),FC=f.forwardRef(({label:t,description:e,...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:t}),s.jsx(a.Text,{size:"xs",color:"dimmed","data-role":"description",children:e})]})})})),GC=S.observer(({label:t,config:e,value:n,onChange:r})=>{const i=oe(),o=!!e.options_query_id,{state:l,error:c}=i.getDataStuffByID(e.options_query_id),u=l==="loading";return s.jsx(a.Select,{label:t,data:e.options,disabled:o?u:!1,value:n,onChange:r,error:!!c,placeholder:c,maxDropdownHeight:500,styles:{root:{width:e.width?e.width:"200px"},input:{borderColor:"#e9ecef"}},sx:{".mantine-Select-item[data-selected] .mantine-Text-root[data-role=description]":{color:"rgba(255,255,255,.7)"}},itemComponent:FC})});function WC({label:t,config:e,value:n,onChange:r}){return s.jsx(a.TextInput,{label:t,value:n||"",onChange:i=>r(i.currentTarget.value),...e,styles:{input:{borderColor:"#e9ecef"}}})}const RC=({rotate:t,onClick:e})=>s.jsx("svg",{onClick:e,className:"caret-icon",viewBox:"0 0 1024 1024",focusable:"false","data-icon":"caret-down",width:"14px",height:"14px",fill:"currentColor","aria-hidden":"true",transform:`rotate(${t})`,children: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"})}),QC=({expanded:t,isLeaf:e,value:n,onClick:r,...i})=>(n==="0-0-value"&&console.log(i),e?s.jsx("span",{style:{width:"14px",display:"inline-block"}}):s.jsx(RC,{rotate:t?"0":"-90",onClick:r,...i})),UC=({onClick:t})=>s.jsxs("svg",{onClick:t,className:"checkbox-icon",width:"16",height:"16",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[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"})]}),YC=({onClick:t,...e})=>s.jsx(UC,{onClick:t,...e}),KC=a.createStyles((t,{radius:e=4})=>({root:{borderRadius:t.fn.radius(e),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-tree-select.rc-tree-select-open":{borderColor:"#228be6 !important",".rc-tree-select-selection-overflow-item-rest":{display:"none"},".rc-tree-select-selection-overflow-item-suffix":{display:"block"}},".rc-tree-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-tree-select-selection-search-mirror":{display:"none"},".rc-tree-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-tree-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-tree-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-tree-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-tree-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-tree-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-tree-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-tree-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:t.fontSizes.sm,fontWeight:500,color:"#212529"},required:{color:"#fa5252",paddingLeft:"3px"},dropdown:{fontSize:t.fontSizes.xs,zIndex:300,paddingTop:"6px","&.rc-tree-select-dropdown-slide-up-leave-active":{display:"none"},".rc-tree-select-tree-list .rc-tree-select-tree-list-holder":{},".rc-tree-select-tree-list, .rc-tree-select-empty":{backgroundColor:"#fff",border:"1px solid #e9ecef",padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px"},".rc-tree-select-empty":{padding:"8px 12px"},".rc-tree-select-tree-treenode":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"8px 12px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},"&.rc-tree-select-tree-treenode-checkbox-checked":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-checked":{stroke:"rgb(64, 192, 87)",animation:"check 200ms linear forwards"}},"&.rc-tree-select-tree-treenode-checkbox-indeterminate":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-indeterminate":{fill:"rgb(64, 192, 87)"}},".rc-tree-select-tree-switcher":{height:"16px",alignSelf:"center",paddingRight:"2px",transition:"color 200ms ease","&:hover":{color:"#228be6","svg.caret-icon":{color:"#228be6"}},"svg.caret-icon":{color:"#ced4da",transition:"all 200ms ease"}},".rc-tree-select-tree-node-content-wrapper":{display:"flex",flexWrap:"nowrap",overflow:"hidden",alignItems:"center",gap:"8px",transition:"color 200ms ease","&:hover":{color:"#228be6"}},".rc-tree-select-tree-iconEle":{height:"16px","svg .border":{stroke:"#ced4da"},".checkbox-icon .checkmark-indeterminate":{fill:"transparent",transition:"fill 200ms ease"},".checkbox-icon .checkmark-checked":{transform:"scale(1.2)",transformOrigin:"center center",strokeDasharray:10,strokeDashoffset:-10},"@keyframes check":{"0%":{strokeDashoffset:10},"100%":{strokeDashoffset:0}}},".rc-tree-select-tree-title":{textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden",".rc-tree-select-tree-title-desc":{fontSize:"12px",maxWidth:"100%",textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden"}},".rc-tree-select-tree-indent":{flexGrow:0,height:0,verticalAlign:"bottom"},".rc-tree-select-tree-indent-unit":{display:"inline-block",width:"1em"}}}})),XC=({disabled:t,classNames:e,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}=KC({radius:i},{name:"FilterTreeSelectWidget",classNames:e,styles:n,unstyled:r}),[C,T]=f.useState(!1),A=U=>{T(U)},L=C&&(c==null?void 0:c.length)>0;return s.jsxs(a.Stack,{spacing:3,children:[s.jsxs(a.Group,{position:"apart",children:[s.jsxs(a.Text,{className:m.label,children:[l,h&&s.jsx("span",{className:m.required,"aria-hidden":"true",children:"*"})]}),L&&s.jsx(a.Tooltip,{label:`${c.length} selected`,children:s.jsx(a.Badge,{children:c.length})})]}),s.jsx(pi,{disabled:t,allowClear:!0,treeCheckStrictly:x,className:j(m.root,"check-select"),dropdownClassName:j(m.dropdown,""),onDropdownVisibleChange:A,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:QC,treeIcon:YC,maxTagTextLength:10,value:c,treeData:d,notFoundContent:s.jsx(jo,{errorMessage:p}),treeNodeFilterProp:"filterBasis",treeCheckable:!0,showCheckedStrategy:pi.SHOW_PARENT,onChange:u,onSelect:console.log,maxTagCount:0,maxTagPlaceholder:U=>`${U.length} selected`})]})},JC=S.observer(({label:t,config:e,value:n,onChange:r})=>{const{treeData:i,treeDataLoading:o,errorMessage:l}=e,c=e.min_width?e.min_width:"200px",d=!!e.options_query_id?o:!1;return s.jsx(XC,{disabled:d,style:{minWidth:"160px",width:c,maxWidth:d?c:"unset",borderColor:"#e9ecef"},value:n,onChange:p=>r(p,!1),treeData:i,errorMessage:l,label:t,required:e.required,treeCheckStrictly:e.treeCheckStrictly})}),ZC=S.observer(({filter:{type:t,config:e,key:n,...r},formFieldProps:i})=>{switch(t){case"select":return s.jsx(GC,{...r,...i,config:e});case"multi-select":return s.jsx(qC,{...r,...i,config:e});case"tree-select":return s.jsx(JC,{...r,...i,config:e});case"text-input":return s.jsx(WC,{...r,...i,config:e});case"date-range":return s.jsx(bo,{...r,...i,config:e});case"checkbox":return s.jsx($C,{...r,...i,config:e});default:return null}}),HC=S.observer(f.forwardRef(({filter:t,...e},n)=>s.jsx("div",{className:"filter-root",ref:n,children:s.jsx(Ce,{children:s.jsx(ZC,{filter:t,formFieldProps:e})})}))),eS=({disabled:t})=>{const{searchButtonProps:e}=Ii(),{children:n="Search",type:r,...i}=e;return s.jsx(a.Button,{color:"blue",size:"sm",type:"submit",...i,disabled:t||i.disabled,children:n})};function tS(t){const e=X();f.useEffect(()=>{var n,r;(r=(n=e.filters).updatePreviewValues)==null||r.call(n,t)},[t])}const vo=S.observer(function({view:e}){const n=oe(),{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]),tS(l);const c=n.filters.visibleInView(e.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,C)=>{m(j),(x.should_auto_submit||C)&&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(HC,{filter:x,value:m.value,onChange:h(x,m.onChange)})},x.id))}),!u&&s.jsx(a.Group,{sx:{alignSelf:"flex-end"},children:s.jsx(eS,{disabled:p})})]})})}),nS={viewPanelInFullScreen:y.noop,inFullScreen:!1},qn=f.createContext(nS),wo=g.types.model("MockContextMeta",{current:g.types.optional(g.types.frozen(),{})}).views(t=>({get keys(){return Object.keys(t.current)},get keySet(){return new Set(this.keys)},get entries(){return Object.entries(t.current)}})).actions(t=>({replace(e){t.current=e},defaults(e){t.current={...e,...t.current}},get(e){return t.current[e]},set(e,n){t.current[e]=n}}));function Co(t){return{current:t}}const sS=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(t=>({get json(){const{x:e,y:n,w:r,h:i,moved:o}=t;return{h:i,w:r,x:e,y:n===null?0:n,moved:o,static:t.static}}})).actions(t=>({set(e){const{x:n,y:r,w:i,h:o,moved:l}=e;t.x=n,t.y=r,t.w=i,t.h=o,t.moved=!!l,t.static=!!e.static},setWidth(e){t.w=e},setHeight(e){t.h=e}})),rS=g.types.model("PanelStyleBorderMeta",{enabled:g.types.boolean}).views(t=>({get json(){const{enabled:e}=t;return{enabled:e}}})).actions(t=>({setEnabled(e){t.enabled=e}})),iS=g.types.model("PanelStyleMeta",{border:rS}).views(t=>({get json(){const{border:e}=t;return{border:e.json}}})).actions(t=>({})),aS=g.types.model("PanelTitleMeta",{show:g.types.optional(g.types.boolean,!0)}).views(t=>({get json(){const{show:e}=t;return{show:e}}})).actions(t=>({setShow(e){t.show=e}})),oS=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(t=>({get json(){const{name:e,size:n,weight:r,color:i,formatter:o,data_field:l,aggregation:c}=t;return y.cloneDeep({name:e,size:n,color:i,weight:r,formatter:o,data_field:l,aggregation:c})}})),lS=g.types.model("PanelVizMeta",{type:g.types.string,conf:g.types.frozen()}).views(t=>({get json(){return{conf:t.conf,type:t.type}}})).actions(t=>({setType(e){t.type=e},setConf(e){t.conf=e}})),cS=g.types.model({id:g.types.string,name:g.types.optional(g.types.string,""),title:aS,description:g.types.string,layout:sS,queryIDs:g.types.array(g.types.string),viz:lS,style:iS,variables:g.types.optional(g.types.array(oS),[])}).views(t=>({get json(){const{id:e,name:n,title:r,description:i,queryIDs:o}=t;return{id:e,viz:t.viz.json,name:n,style:t.style.json,title:r.json,layout:t.layout.json,queryIDs:[...o],variables:t.variables.map(l=>l.json),description:i}},get queryIDSet(){return new Set(t.queryIDs)}})).actions(t=>({setID(e){t.id=e},setName(e){t.name=e},setDescription(e){t.description=e},addQueryID(e){t.queryIDSet.has(e)||t.queryIDs.push(e)},removeQueryID(e){if(!t.queryIDSet.has(e))return;const n=new Set(t.queryIDSet);n.delete(e),t.queryIDs=g.cast(Array.from(n))},setQueryIDs(e){t.queryIDs=g.cast(e)},addVariable(e){t.variables.push(e)},removeVariable(e){t.variables.remove(e)}})),Fn=t=>y.cloneDeepWith(t,(e,n)=>{if(n!==void 0&&e)return W.toJS(e)});var De=(t=>(t.Postgresql="postgresql",t.MySQL="mysql",t.HTTP="http",t))(De||{});const uS=g.types.model("QueryMeta",{id:g.types.string,name:g.types.string,type:g.types.enumeration("DataSourceType",[De.Postgresql,De.MySQL,De.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(t=>({get valid(){return t.id&&t.type&&t.key&&t.name?t.type===De.HTTP?!!t.pre_process:!!t.sql:!1},get json(){const{id:e,name:n,type:r,key:i,sql:o,run_by:l,react_to:c,pre_process:u,post_process:d}=t;return Fn({id:e,key:i,sql:o,name:n,type:r,run_by:l,react_to:c,pre_process:u,post_process:d})}})).actions(t=>({setName(e){t.name=e},setKey(e){t.key=e},setType(e){t.type=e},setSQL(e){t.sql=e},setRunBy(e){t.run_by.length=0,t.run_by.push(...e)},setReactTo(e){t.react_to.length=0,t.react_to.push(...e)},setPreProcess(e){t.pre_process=e},setPostProcess(e){t.post_process=e}})),dS=g.types.model("SQLSnippetMeta",{key:g.types.string,value:g.types.string}).views(t=>({get json(){const{key:e,value:n}=t;return{key:e,value:n}}})).actions(t=>({setKey(e){t.key=e},setValue(e){t.value=e}}));var ce=(t=>(t.Select="select",t.MultiSelect="multi-select",t.TreeSelect="tree-select",t.TextInput="text-input",t.Checkbox="checkbox",t.DateRange="date-range",t))(ce||{});const So=g.types.model("FilterCheckboxConfigMeta",{_name:g.types.literal("checkbox"),description:g.types.optional(g.types.string,""),default_value:g.types.boolean}).views(t=>({get json(){const{_name:e,description:n,default_value:r}=t;return{_name:e,description:n,default_value:r}},get isDescriptionEmpty(){const{description:e}=t;return e===""||e==="<p></p>"}})).actions(t=>({setDefaultValue(e){t.default_value=e},setDescription(e){t.description=e}})),pS=()=>So.create({_name:"checkbox",description:"",default_value:!1});function _o(t,e){return t.map(n=>{try{return n?V.tz(n,"UTC").format(e):null}catch{return console.log(`[date-range] failed parsing ${n}`),null}})}const hS=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(t=>({get json(){const{_name:e,max_days:n,required:r,clearable:i,inputFormat:o,default_value:l,allowSingleDateInRange:c}=t;return{_name:e,max_days:n,required:r,clearable:i,inputFormat:o,default_value:_o(l,o),allowSingleDateInRange:c}},truthy(e){return Array.isArray(e)&&e.length===2&&e.every(n=>!!n)}})).views(t=>({getMaxDate(e){const{max_days:n}=t;if(!(!n||!e))return V(e).startOf("day").add(n,"days").toDate()},getMinDate(e){const{max_days:n}=t;if(!(!n||!e))return V(e).startOf("day").subtract(n,"days").toDate()}})).actions(t=>({setFilterValue(e){try{const n=g.getParent(t);g.getRoot(t).filters.setValueByKey(n.key,e)}catch(n){console.error(n)}}})).actions(t=>({setRequired(e){t.required=e},setClearable(e){t.clearable=e},setInputFormat(e){t.inputFormat=e},setDefaultValue(e){t.default_value.length=0,t.default_value.push(...e),t.setFilterValue(e)},setMaxDays(e){t.max_days=e,e>0&&(t.clearable=!0)},setAllowSingleDateInRange(e){t.allowSingleDateInRange=e}})),ko=g.types.snapshotProcessor(hS,{preProcessor({default_value:t,...e}){return{...e,default_value:t.map(n=>n===null?null:V.tz(n,"UTC").toISOString())}},postProcessor(t){const{default_value:e,...n}=t;return{...n,default_value:_o(e,n.inputFormat)}}}),xS=()=>ko.create({_name:"date-range",required:!1,inputFormat:"YYYY-MM-DD",clearable:!1,default_value:[null,null]}),fS=g.types.model({label:g.types.string,value:g.types.string}).actions(t=>({setLabel(e){t.label=e},setValue(e){t.value=e}})),wr=g.types.model("FilterConfigModel_BaseSelect",{static_options:g.types.optional(g.types.array(fS),[]),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(t=>({get contentModel(){return g.getRoot(t).content},get usingQuery(){return!!t.options_query_id}})).views(t=>({get options(){if(!t.usingQuery)return t.static_options;const{data:e,state:n,error:r}=t.contentModel.getDataStuffByID(t.options_query_id);return n==="idle"?Array.isArray(e)?e:[]:[]}})).actions(t=>({setRequired(e){t.required=e},addStaticOption(e){t.static_options.push(e)},removeStaticOption(e){t.static_options.splice(e,1)},setDefaultSelectionCount(e){t.default_selection_count=e},setOptionsQueryID(e){t.options_query_id=e??""}})),To=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),[])}),wr).views(t=>({get json(){const{_name:e,default_value:n,required:r,min_width:i,static_options:o,options_query_id:l,default_selection_count:c}=t;return Fn({_name:e,required:!!r,min_width:i,default_value:n,static_options:o,options_query_id:l,default_selection_count:c})},get default_selection(){return t.usingQuery?t.options.slice(0,t.default_selection_count).map(e=>e.value):t.default_value},truthy(e){return Array.isArray(e)&&e.length>0}})).actions(t=>({setDefaultValue(e){t.default_value=g.cast(e)},setMinWidth(e){t.min_width=e},setDefaultSelection(){const e=g.getRoot(t).content.filters,n=g.getParent(t).key;e.setValueByKey(n,t.default_selection)}})).actions(t=>({afterCreate(){g.addDisposer(t,W.reaction(()=>W.toJS(t.default_selection),t.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),gS=()=>To.create({_name:"multi-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),Io=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,"")}),wr).views(t=>({get json(){const{_name:e,default_value:n,required:r,width:i,static_options:o,options_query_id:l,default_selection_count:c}=t;return Fn({_name:e,width:i,required:r,default_value:n,static_options:o,options_query_id:l,default_selection_count:c})},truthy(e){return!!e},getSelectOption(e){return t.options.find(n=>n.value===e)},get default_selection(){return t.usingQuery?t.default_selection_count>0&&t.options.length>0?t.options[0].value:"":t.default_value}})).actions(t=>({setDefaultValue(e){t.default_value=e},setWidth(e){t.width=e},setDefaultSelection(){const e=g.getRoot(t).content.filters,n=g.getParent(t).key;e.setValueByKey(n,t.default_selection)}})).actions(t=>({afterCreate(){g.addDisposer(t,W.reaction(()=>W.toJS(t.default_selection),t.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),mS=()=>Io.create({_name:"select",required:!1,default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),Do=g.types.model("FilterTextInputConfigMeta",{_name:g.types.literal("text-input"),required:g.types.boolean,default_value:g.types.string}).views(t=>({get json(){const{_name:e,required:n,default_value:r}=t;return{_name:e,required:n,default_value:r}},truthy(e){return typeof e!="string"?!1:!!e.trim()}})).actions(t=>({setRequired(e){t.required=e},setDefaultValue(e){t.default_value=e}})),Mo=()=>Do.create({_name:"text-input",required:!1,default_value:""});function yS(t){return gc.arrayToTree(t,{id:"value",parentId:"parent_value",childrenField:"children",dataField:null})}function bS(t){return t.map(e=>{const{label:n,description:r,...i}=e,o={...i,filterBasis:`${n}___${r??""}`,description:r,label:n};return r&&(o.label=f.createElement("div",{},[f.createElement(a.Text,{key:0,title:e.label},e.label),f.createElement(a.Text,{key:1,className:"rc-tree-select-tree-title-desc",color:"dimmed",title:e.description},e.description)])),o})}const Ao=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)}),wr).views(t=>({get json(){const{_name:e,default_value:n,required:r,min_width:i,static_options:o,options_query_id:l,default_selection_count:c,treeCheckStrictly:u}=t;return{_name:e,required:!!r,min_width:i,default_value:n,static_options:o,options_query_id:l,treeCheckStrictly:u,default_selection_count:c}},get treeData(){const{data:e}=g.getRoot(t).content.getDataStuffByID(t.options_query_id),n=bS(e);return yS(n)},get errorMessage(){const{error:e}=g.getRoot(t).content.getDataStuffByID(t.options_query_id);return e},get treeDataLoading(){const{state:e}=g.getRoot(t).content.getDataStuffByID(t.options_query_id);return e==="loading"},get defaultSelection(){const{default_selection_count:e}=t;return e?this.treeData.slice(0,e).map(r=>r.value):[]},truthy(e){return Array.isArray(e)&&e.length>0}})).actions(t=>({setDefaultValue(e){t.default_value=g.cast(e)},setMinWidth(e){t.min_width=e},setTreeCheckStrictly(e){t.treeCheckStrictly=e},applyDefaultSelection(){const e=g.getParent(t,1).key;g.getRoot(t).content.filters.setValueByKey(e,t.defaultSelection)},afterCreate(){g.addDisposer(t,W.reaction(()=>JSON.stringify(t.defaultSelection),this.applyDefaultSelection,{fireImmediately:!0,delay:0}))}})),jS=()=>Ao.create({_name:"tree-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),zo=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",[ce.Select,ce.MultiSelect,ce.TreeSelect,ce.TextInput,ce.Checkbox,ce.DateRange]),config:g.types.union(Io,To,Ao,Do,So,ko)}).views(t=>({get plainDefaultValue(){const e=t.config.default_value;return Array.isArray(e)?[...e]:e},get usingDefaultValue(){return t.type!==ce.TreeSelect},get auto_submit_supported(){return[ce.Select,ce.Checkbox,ce.DateRange].includes(t.type)}})).views(t=>({get json(){const{id:e,key:n,label:r,order:i,visibleInViewsIDs:o,auto_submit:l,type:c,config:u}=t;return{id:e,key:n,type:c,label:r,order:i,config:u.json,auto_submit:l,visibleInViewsIDs:W.toJS(o)}},get visibleInViewsIDSet(){return new Set(t.visibleInViewsIDs)},get should_auto_submit(){return t.auto_submit_supported&&t.auto_submit},requiredAndPass(e){return y.get(t.config,"required",!1)?y.get(t.config,"truthy",()=>!0)(e):!1}})).actions(t=>({setKey(e){t.key=e},setLabel(e){t.label=e},setOrder(e){t.order=e},setType(e){switch(e){case ce.Select:t.config=mS();break;case ce.MultiSelect:t.config=gS();break;case ce.TreeSelect:t.config=jS();break;case ce.TextInput:t.config=Mo();break;case ce.Checkbox:t.config=pS();break;case ce.DateRange:t.config=xS();break}t.type=e},setVisibleInViewsIDs(e){t.visibleInViewsIDs.length=0,t.visibleInViewsIDs.push(...e)},setAutoSubmit(e){t.auto_submit=t.auto_submit_supported&&e}}));var E=(t=>(t.Division="div",t.Modal="modal",t.Tabs="tabs",t))(E||{});const Eo=g.types.model("ViewDivisionConfig",{_name:g.types.literal(E.Division)}).views(t=>({get json(){const{_name:e}=t;return{_name:e}}})),vS=()=>Eo.create({_name:E.Division}),wS=g.types.model("CustomModalTitleModel",{enabled:g.types.optional(g.types.boolean,!1),func_content:g.types.optional(g.types.string,"")}).views(t=>({get json(){const{enabled:e,func_content:n}=t;return{enabled:e,func_content:n}},get value(){const{enabled:e,func_content:n}=t,r=g.getParent(t,2),i=g.getRoot(t);if(!e)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(t=>({setEnabled(e){t.enabled=e},setFuncContent(e){t.func_content=e},replace({enabled:e,func_content:n}){t.enabled=e,t.func_content=n}})),Cr={enabled:!1,func_content:["function text({ filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
440
+ `)},Po=g.types.model("ViewModalConfig",{_name:g.types.literal(E.Modal),width:g.types.string,height:g.types.string,custom_modal_title:g.types.optional(wS,Cr)}).views(t=>({get json(){const{_name:e,width:n,height:r,custom_modal_title:i}=t;return{_name:e,width:n,height:r,custom_modal_title:i.json}}})).actions(t=>({setWidth(e){t.width=e},setHeight(e){t.height=e}})),CS=()=>Po.create({_name:E.Modal,width:"90vw",height:"90vh"}),SS=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(t=>({get json(){const{id:e,name:n,view_id:r,color:i}=t;return{id:e,name:n,color:i,view_id:r}}})).actions(t=>({setName(e){t.name=e},setViewID(e){t.view_id=e},setColor(e){t.color=e}})),Lo=g.types.model("ViewTabsConfig",{_name:g.types.literal(E.Modal),tabs:g.types.optional(g.types.array(SS),[]),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(t=>({get json(){const{_name:e,variant:n,orientation:r,tabs:i,grow:o}=t;return{grow:o,tabs:i.map(l=>l.json),_name:e,variant:n,orientation:r}}})).actions(t=>({setVariant(e){t.variant=e},setOrientation(e){t.orientation=e},setGrow(e){t.grow=e},setTabs(e){t.tabs.length=0,t.tabs=g.cast(e)},addTab(){const e=pe.randomId(),n={id:e,name:e,view_id:""};t.tabs.push(n)},removeTab(e){t.tabs.splice(e,1)}})),_S=()=>Lo.create({_name:E.Modal,tabs:[]}),kS=g.types.model({id:g.types.identifier,name:g.types.string,type:g.types.enumeration("EViewComponentType",[E.Division,E.Modal,E.Tabs]),config:g.types.union(Eo,Po,Lo),panelIDs:g.types.optional(g.types.array(g.types.string),[])}).views(t=>({get json(){const{id:e,name:n,type:r,config:i}=t;return{id:e,name:n,type:r,config:i.json,panelIDs:t.panelIDs.map(o=>o)}}})).actions(t=>({setName(e){t.name=e},setType(e){if(t.type!==e){switch(e){case E.Division:t.config=vS();break;case E.Modal:t.config=CS();break;case E.Tabs:t.config=_S();break}t.type=e}},appendPanelID(e){t.panelIDs.push(e)},appendPanelIDs(e){t.panelIDs.push(...e)},removePanelID(e){const n=t.panelIDs.filter(r=>r!==e);t.panelIDs.length=0,t.panelIDs.push(...n)}})),Bo=g.types.model("DataSourceMetaModel",{id:g.types.string,type:g.types.enumeration("DataSourceType",[De.HTTP,De.MySQL,De.Postgresql]),key:g.types.string,config:g.types.frozen()}),TS=g.types.model("DataSourcesMetaModel",{list:g.types.optional(g.types.array(Bo),[])}).views(t=>({find({type:e,key:n}){return t.list.find(r=>r.key===n&&r.type===e)},get options(){return t.list.map(e=>({value:e.key,label:e.key}))}})).actions(t=>({replace(e){t.list.length=0,t.list.push(...e)}})),IS=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}),Oo=g.types.model("GlobalSQLSnippetsMeta",{list:g.types.optional(g.types.array(IS),[])}).views(t=>({find(e){return t.list.find(n=>n.id===e)},get options(){return t.list.map(e=>({value:e.id,label:e.id}))}})).actions(t=>({replace(e){t.list.length=0,t.list.push(...e)}})),Sr=g.types.model("ContextMeta",{current:g.types.optional(g.types.frozen(),{})}).views(t=>({get keys(){return Object.keys(t.current)},get entries(){return Object.entries(t.current)}})).actions(t=>({replace(e){t.current=e},get(e){return t.current[e]},set(e,n){t.current[e]=n}}));function $o(t){return Sr.create({current:t})}const Vo=g.types.compose("ViewRenderModel",kS,g.types.model({tab:g.types.optional(g.types.string,"")})).views(t=>({get defaultTab(){if(t.type!==E.Tabs)return"";const e=t.config;return e.tabs.length>0?e.tabs[0].id:""},get tabViewID(){var n;return t.type!==E.Tabs?"":((n=t.config.tabs.find(r=>r.id===t.tab))==null?void 0:n.view_id)??""},get contentModel(){return g.getParent(t,3)},get panels(){if(t.type!==E.Tabs)return this.contentModel.panels.panelsByIDs(t.panelIDs).panels;const e=this.tabViewID;return this.contentModel.views.findByID(e).panels},get renderViewIDs(){const e=[t.id];return t.type===E.Tabs&&e.push(this.tabViewID),e}})).actions(t=>({setTab(e){t.tab=e??""},afterCreate(){g.addDisposer(t,W.reaction(()=>t.defaultTab,e=>this.setTab(e),{fireImmediately:!0,delay:0}))}})),No=g.types.model("ViewsRenderModel",{current:g.types.optional(g.types.array(Vo),[]),visibleViewIDs:g.types.array(g.types.string)}).views(t=>({get json(){return t.current.map(e=>Fn(e.json))},get idMap(){const e=new Map;return t.current.forEach(n=>{e.set(n.id,n)}),e},findByID(e){return t.current.find(n=>n.id===e)},get firstVisibleView(){const[e]=t.visibleViewIDs;return t.current.find(({id:n})=>n===e)},get visibleViews(){const e=new Set(t.visibleViewIDs);return t.current.filter(({id:n})=>e.has(n))}})).actions(t=>({appendToVisibles(e){new Set(t.visibleViewIDs.map(r=>r)).has(e)||t.visibleViewIDs.push(e)},rmVisibleViewID(e){const n=t.visibleViewIDs.findIndex(r=>r===e);n!==-1&&t.visibleViewIDs.splice(n,1)}}));function DS(t){const e=t.length>0?[t[0].id]:[];return{current:t.map(r=>{const{_name:i=r.type}=r.config;return{...r,config:{...r.config,_name:i},panelIDs:r.panelIDs}}),visibleViewIDs:e}}const MS=new mc.AsyncParser({withBOM:!0});async function qo(t){return!Array.isArray(t)||t.length===0?"":await MS.parse(t).promise()}async function AS(t,e){const n=await qo(e),r=new Blob([n],{type:"text/csv"});rs.saveAs(r,`${t}.csv`)}function Fo(t){const e=new yc,n=t.map(async({id:r,data:i})=>{const o=await qo(i);e.file(`${r}.csv`,o)});Promise.all(n).then(()=>{e.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(t,e){const n=new Blob([e],{type:"application/json"});rs.saveAs(n,`${t}.json`)}const Go=cS.views(t=>({get contentModel(){return g.getRoot(t).content}})).views(t=>({get queries(){return t.contentModel.queries.findByIDSet(t.queryIDSet)},get data(){return this.queries.reduce((e,n)=>(e[n.id]=n.data,e),{})},get variableStrings(){return Vi(t.variables,this.data)},get dataLoading(){return this.queries.some(e=>e.state==="loading")},get queryStateMessages(){const e=this.queries.filter(o=>!o.runByConditionsMet);if(e.length===0)return"";const n=new Set,r=new Set;e.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(e=>e.error).filter(e=>!!e)},get canRenderViz(){return this.queryErrors.length===0&&this.queryStateMessages===""&&!this.dataLoading}})).actions(t=>({refreshData(){t.queries.forEach(e=>e.fetchData(!0))},downloadData(){t.contentModel.queries.downloadDataByQueryIDs(t.queryIDs)},getSchema(){const e=t.json;return e.viz.conf={...e.viz.conf,__INTERACTIONS:{},__OPERATIONS:{},__TRIGGERS:{}},{panel:e,queries:t.queries.map(n=>n.json)}},downloadSchema(){const{panel:e,queries:n}=this.getSchema(),i=JSON.stringify({panels:[e],definition:{queries:n}},null,2),o=t.name;Ct(o,i)}}));function zS(t){return{id:t,name:t,layout:{x:0,y:1/0,w:18,h:300},title:{show:!0},description:"<p></p>",queryIDs:[],viz:{type:ur.name,conf:ur.createConfig()},style:{border:{enabled:!0}}}}const Wo=g.types.model("PanelsRenderModel",{list:g.types.optional(g.types.array(Go),[])}).views(t=>({get json(){return t.list.map(e=>e.json)},findByID(e){return t.list.find(n=>n.id===e)},get idMap(){const e=new Map;return t.list.forEach(n=>{e.set(n.id,n)}),e}})).views(t=>({panelsByIDs(e){const n=[];e.forEach(i=>{const o=t.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 Ro(t,e){if(t===void 0)return t;if(e._name==="date-range")try{const[...n]=t;return n.map(r=>r===null?r:V.tz(r,"UTC").format(e.inputFormat)??r)}catch(n){return console.error(n),t}return t}function ES(t){return t.reduce((e,n)=>(e[n.key]=Ro(n.config.default_value,n.config),e),{})}const Qo=g.types.model("FiltersRenderModel",{current:g.types.optional(g.types.array(zo),[]),values:g.types.optional(g.types.frozen(),{})}).views(t=>({get json(){return t.current.map(e=>e.json)},get firstID(){if(t.current.length!==0)return t.current[0].id},findByID(e){return t.current.find(n=>n.id===e)},findByIDSet(e){return t.current.filter(n=>e.has(n.id))},get inOrder(){return y.sortBy(t.current,"order")},get empty(){return t.current.length===0},visibleInView(e){return y.sortBy(t.current.filter(n=>n.visibleInViewsIDSet.has(e)),"order")},get firstFilterValueKey(){return Object.keys(t.values)[0]??""},get keySet(){return new Set(t.current.map(e=>e.key))},get keyLabelMap(){return t.current.reduce((e,n)=>(e[n.key]=n.label,e),{})},getSelectOption(e){const n=this.findByID(e);if(!n||!("getSelectOption"in n.config))return null;const r=t.values[n.key];return n.config.getSelectOption(r)}})).actions(t=>({setValues(e){t.values=e},setValueByKey(e,n){t.values={...t.values,[e]:n}},getValueByKey(e){return t.values[e]},getSchema(e,n){return{filters:t.findByIDSet(new Set(e)).map(o=>({...o.json,visibleInViewsIDs:n?o.json.visibleInViewsIDs:[]}))}},downloadSchema(e){const n=JSON.stringify(this.getSchema(e,!1),null,2);Ct("Filters",n)}}));function Uo(t){return{current:t,values:ES(t)}}function PS(t,e){return new Function(`return ${t}`)()(e,gt)}function LS(t,e,n){return PS(t,{context:e,filters:n})}function BS(t,e){try{return new Function(`return ${t.config.processing.pre}`)()(e,gt)}catch(n){return console.error(n),e}}function OS(t,e){return new Function(`return ${t.config.processing.post}`)()(e,gt)}function $S(t,e,n){return t?new Function(`return ${t}`)()(e,gt,n):e}const Gn={sqlSnippet:new RegExp("(?<=sql_snippets\\.)([^\\?}.]+)","gm"),context:new RegExp("(?<=context\\.)([^\\?}.]+)","gm"),filter:new RegExp("(?<=filters\\.)([^\\?}.]+)","gm")},VS=uS.views(t=>({get rootModel(){return g.getRoot(t)},get contentModel(){return this.rootModel.content},get conditionOptions(){if(!g.isAlive(t))return[];const e=g.getRoot(t).content,{context:n}=e.payloadForSQL,r=Object.keys(n).map(o=>({group:"Context",label:o,value:`context.${o}`,description:void 0})),i=e.filters.keyLabelOptions.map(o=>({group:"Filters",label:o.label,value:`filters.${o.value}`,description:o.value}));return[...r,...i]},get unmetRunByConditions(){if(!g.isAlive(t))return[];const{run_by:e}=t;if(e.length===0)return[];const n=g.getRoot(t).content.payloadForSQL;return e.filter(r=>{const i=y.get(n,r);return Array.isArray(i)?i.length===0:typeof i=="number"?Number.isNaN(i):!i})}})).views(t=>({get payload(){return t.contentModel.payloadForSQL},get formattedSQL(){return ls(t.sql,this.payload)},get httpConfigString(){const{context:e,filters:n}=this.payload,{name:r,pre_process:i}=t.json,o=LS(i,e,n);return console.groupCollapsed(`Request config for: ${r}`),console.log(o),console.groupEnd(),JSON.stringify(o)},get typedAsSQL(){return[De.Postgresql,De.MySQL].includes(t.type)},get typedAsHTTP(){return[De.HTTP].includes(t.type)},get reQueryKey(){const{react_to:e=[]}=t;if(e.length===0)return"";const n=g.getRoot(t).content.payloadForSQL,r=[...e].reduce((i,o)=>(i[o]=y.get(n,o),i),{});return JSON.stringify(r)},get runByConditionsMet(){return t.unmetRunByConditions.length===0},get conditionNames(){if(t.unmetRunByConditions.length===0)return{context:[],filters:[]};const{keyLabelMap:e}=g.getRoot(t).content.filters,n=t.unmetRunByConditions.filter(i=>i.startsWith("context.")).map(i=>i.split("context.")[0]),r=t.unmetRunByConditions.filter(i=>i.startsWith("filters.")).map(i=>y.get({filters:e},i)).filter(i=>!!i);return{context:n,filters:r}},get queries(){return g.getParent(t,2)},get inUse(){return this.queries.isQueryInUse(t.id)},get dependencies(){if(!this.typedAsSQL)return[];const e=y.uniq(t.sql.match(Gn.sqlSnippet)),n=y.uniq(t.sql.match(Gn.filter)),r=y.uniq(t.sql.match(Gn.context)),i=[];return e.forEach(o=>{i.push({type:"SQL Snippet",key:o,valid:t.contentModel.sqlSnippets.keySet.has(o)})}),n.forEach(o=>{i.push({type:"Filter",key:o,valid:t.contentModel.filters.keySet.has(o)})}),r.forEach(o=>{i.push({type:"Context",key:o,valid:t.contentModel.mock_context.keySet.has(o)})}),i}})),NS=g.types.compose("QueryRenderModel",VS,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(t=>({get datasource(){const{key:e,type:n}=t;return t.rootModel.datasources.find({type:n,key:e})},get additionalQueryInfo(){return t.contentModel.getAdditionalQueryInfo(t.id)}})).views(t=>({get stateMessage(){if(t.state!=="idle")return"";if(!t.runByConditionsMet){const{context:e,filters:n}=t.conditionNames;if(e.length===0&&n.length===0)return"Waiting";const r=[];return e.length>0&&r.push(`context: ${e.join(", ")}`),n.length>0&&r.push(`filter${n.length>1?"s":""}: ${n.join(", ")}`),r.length===2&&r.splice(1,0,"and"),r.unshift("Waiting for"),r.join(" ")}return t.data.length>0?"":"Empty Data"}})).volatile(()=>({controller:new AbortController})).actions(t=>({runSQL:g.flow(function*(){var e;if(t.valid&&((e=t.controller)==null||e.abort(),!!t.runByConditionsMet)){t.controller=new AbortController,t.state="loading";try{const n=t.payload;t.data=yield*g.toGenerator(du({payload:n,name:t.name,query:t.json,additionals:t.additionalQueryInfo},t.controller.signal)),t.state="idle",t.error=null}catch(n){if(!tt.isCancel(n)){t.data=[];const r=y.get(n,"message","unkown error");t.error=y.get(n,"response.data.detail.message",r),t.state="error"}}}}),runHTTP:g.flow(function*(){var e;if(!(!t.valid||!t.datasource)&&((e=t.controller)==null||e.abort(),!!t.runByConditionsMet)){t.controller=new AbortController,t.state="loading";try{const{type:n,key:r,post_process:i}=t.json;let o=JSON.parse(t.httpConfigString);o=BS(t.datasource,o);const l=yield*g.toGenerator(pu({type:n,key:r,configString:JSON.stringify(o),name:t.name,additionals:t.additionalQueryInfo},t.controller.signal)),c=OS(t.datasource,l),u=$S(i,c,t.contentModel.dashboardState);t.data=u,t.state="idle",t.error=null}catch(n){if(console.error(n),!tt.isCancel(n)){t.data=[];const r=y.get(n,"message","unkown error");t.error=y.get(n,"response.data.detail.message",r),t.state="error"}}}})})).actions(t=>({fetchData:e=>{if(!t.inUse&&!e){console.debug(`Skipping query[${t.name}]`);return}return t.typedAsHTTP?t.runHTTP():t.runSQL()},beforeDestroy(){var e;(e=t.controller)==null||e.abort()}})).actions(t=>({afterCreate(){g.addDisposer(t,W.reaction(()=>{var n;return t.typedAsHTTP?`${t.inUse}--${t.id}--${t.key}--${t.reQueryKey}--${(n=t.datasource)==null?void 0:n.id}`:[t.inUse,t.id,t.key,t.formattedSQL,t.pre_process,t.post_process].join("--")},()=>t.fetchData(!1),{fireImmediately:!0,delay:0}))}})),Yo=g.types.model("QueriesRenderModel",{current:g.types.optional(g.types.array(NS),[])}).views(t=>({get idSet(){return new Set(t.current.map(e=>e.id))},get firstID(){if(t.current.length!==0)return t.current[0].id},findByID(e){return t.current.find(n=>n.id===e)},findByIDSet(e){return t.current.filter(n=>e.has(n.id))},get json(){return t.current.filter(e=>e.id&&e.key).map(e=>e.json)},get contentModel(){return g.getParent(t,1)},get visibleQueryIDSet(){const{views:e,filters:n}=this.contentModel,r=[];e.visibleViews.forEach(l=>{l.panels.forEach(c=>{r.push(...c.queryIDs)})});const i=y.uniq(e.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(e){return this.visibleQueryIDSet.has(e)}})).actions(t=>({downloadAllData(){const e=t.current.map(({name:n,data:r})=>({id:n,data:r}));Fo(e)},downloadDataByQueryIDs(e){const n=new Set(e),r=t.current.filter(i=>n.has(i.id)).map(({name:i,data:o})=>({id:i,data:o}));Fo(r)},downloadDataByQueryID(e){const n=t.findByID(e);if(!n){console.log("[downloadDataByQueryID] query not found");return}const{name:r,data:i}=n;AS(r,i)},refetchDataByQueryID(e){const n=t.findByID(e);if(!n){console.error(new Error(`[downloadDataByQueryID] query by ID[${e}] not found`));return}return n.fetchData(!0)},getSchema(e){return{definition:{queries:t.findByIDSet(new Set(e)).map(i=>i.json)}}},downloadSchema(e){const n=JSON.stringify(this.getSchema(e),null,2);Ct("Queries",n)}}));function qS(t){return{current:t}}const FS=dS.views(t=>({isADuplicatedKey(e){return!e||e===t.key?!1:!!g.getParent(t,2).findByKey(e)}})),Ko=g.types.model("SQLSnippetsRenderModel",{current:g.types.optional(g.types.array(FS),[])}).views(t=>({get json(){return t.current.map(e=>e.json)},get record(){return t.current.reduce((e,n)=>(e[n.key]=n.value,e),{})},get keySet(){return new Set(t.current.map(e=>e.key))},get firstKey(){if(t.current.length!==0)return t.current[0].key},findByKey(e){return t.current.find(n=>n.key===e)},findByKeySet(e){return t.current.filter(n=>e.has(n.key))}})).actions(t=>({getSchema(e){return{definition:{sqlSnippets:t.findByKeySet(new Set(e)).map(i=>i.json)}}},downloadSchema(e){const n=JSON.stringify(this.getSchema(e),null,2);Ct("SQL Snippets",n)}}));function GS(t){return{current:t}}function Wn(t,e,n,r){return t.reduce((i,o)=>{try{i[o[e]]=os(o[n],r)}catch(l){i[o[e]]=l.message}return i},{})}class WS{constructor(e){z(this,"origin");z(this,"copy");this.origin=e,this.copy=g.clone(e),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(e){g.applySnapshot(this.copy,e)}}const RS=t=>new WS(t),QS=S.observer(({view:t})=>{const e=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,t.id)},p=()=>{e.editor.open(["_VIEWS_",t.id,"_PANELS_",l])},h=()=>r.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>n.removePanelByID(l,t.id),confirmProps:{color:"red"},zIndex:320}),x=f.useCallback(()=>{c(l)},[l,c]),m=!u&&t.type!==E.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 US(t){return t?["<p><br></p>","<p></p>"].includes(t):!0}const _r=S.observer(()=>{const[t,e]=f.useState(!1),{panel:n}=dt();return US(n.description)?null:s.jsxs(s.Fragment,{children:[s.jsx(a.Modal,{opened:t,onClose:()=>e(!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:()=>e(r=>!r),sx:{verticalAlign:"baseline",cursor:"pointer"},children:s.jsx(_.InfoCircle,{size:20})})})]})}),YI="",YS=S.observer(function(){const{panel:e}=dt(),{name:n,title:r}=e;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 KS(t){const e=f.useRef(null);return{ref:e,downloadPanelScreenshot:()=>{const r=e.current;if(!r)return;const i=r.offsetWidth*2,o=r.offsetHeight*2;hi.toBlob(e.current,{bgcolor:"white",width:i,height:o,style:{border:"none",borderRadius:0,transformOrigin:"0 0",transform:"scale(2)"}}).then(l=>{window.saveAs(l,`${t.name?t.name:t.viz.type}.png`)})}}}var Xo=(t=>(t.migrated="migrated",t.nothingToMigrate="nothingToMigrate",t.checkFailed="checkFailed",t.migrationFailed="migrationFailed",t))(Xo||{}),Rn=(t=>(t.notStarted="notStarted",t.inProgress="inProgress",t.done="done",t))(Rn||{});class XS{constructor(e){z(this,"vizInstance");z(this,"operationManager");z(this,"triggerManager");z(this,"vizManager");z(this,"runningMigration");z(this,"panelModel");z(this,"status","notStarted");this.panelModel=e.getRequired(le.instanceScope.panelModel),this.vizInstance=e.getRequired(le.instanceScope.vizInstance),this.operationManager=e.getRequired(le.instanceScope.operationManager),this.triggerManager=e.getRequired(le.instanceScope.triggerManager),this.vizManager=e.getRequired(le.vizManager)}async createMigrationTask(){const e=[];try{await this.instanceNeedMigration()&&e.push(()=>this.runInstanceMigration()),await this.interactionNeedMigration()&&e.push(()=>this.runInteractionMigration())}catch(n){return console.warn("check migration failed",n),"checkFailed"}if(e.length===0)return"nothingToMigrate";try{return await Promise.all(e.map(n=>n())),"migrated"}catch(n){return console.warn("migration failed",n),"migrationFailed"}}async runMigration(){return this.runningMigration||(this.status="inProgress",this.runningMigration=this.createMigrationTask().then(e=>(this.status="done",e))),this.runningMigration}async runInteractionMigration(){await this.operationManager.runMigration(),await this.triggerManager.runMigration()}async runInstanceMigration(){const e=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData,panelModel:this.panelModel};await e.migrator.migrate(n)}async instanceNeedMigration(){const e=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData};return e.migrator.needMigration(n)}async interactionNeedMigration(){return await this.operationManager.needMigration()||await this.triggerManager.needMigration()}}function Jo(t){const{panel:e}=dt();return f.useCallback(n=>{const r=n.getRequired(le.vizManager),i=r.resolveComponent(t.viz.type);return n.createScoped().provideFactory(le.instanceScope.vizInstance,()=>r.getOrCreateInstance(t)).provideFactory(le.instanceScope.interactionManager,o=>{const l=o.getRequired(le.instanceScope.vizInstance);return new Cs(l,i,xn)}).provideFactory(le.instanceScope.operationManager,o=>o.getRequired(le.instanceScope.interactionManager).operationManager).provideFactory(le.instanceScope.triggerManager,o=>o.getRequired(le.instanceScope.interactionManager).triggerManager).provideValue(le.instanceScope.panelModel,e).provideFactory(le.instanceScope.migrator,o=>new XS(o))},[t.viz.type,t.viz.conf])}function Zo(t){const[e,n]=f.useState(!1),r=yo().getRequired(le.instanceScope.migrator);return $.useAsyncEffect(async()=>{const i=r.status===Rn.notStarted;n(r.status===Rn.done),r.status===Rn.notStarted&&r.runMigration().then(o=>{o===Xo.migrated&&i&&(t==null||t())}).finally(()=>{n(!0)})},[r]),e}function Ho(t,e){const n=yo().getRequired(le.instanceScope.vizInstance);return f.useEffect(()=>(n.instanceData.setItem(null,e.viz.conf),n.instanceData.watchItem(null,r=>{t(r)})),[t,e.viz.type]),n}function JS({setVizConf:t,...e}){const{panel:n}=e,r=Ho(t,n),i=Zo(()=>{xt.showNotification({title:`${n.name} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})});return $.useAsyncEffect(async()=>{await r.instanceData.setItem(null,n.viz.conf)},[r,n.viz.type]),i?s.jsx(gu,{...e}):s.jsx(a.Text,{children:"Checking update..."})}function ZS(t){const{panel:e,setVizConf:n}=t;Ho(n,e);const{inEditMode:r}=f.useContext(pn);return Zo(()=>{r&&xt.showNotification({title:`${e.name} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?s.jsx(fu,{...t}):s.jsx(a.Text,{children:"Checking update"})}const KI="";function HS(t,e){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:e},h=Jo(p);try{return n.resolveComponent(r.type),s.jsx(Nn,{configure:h,children:s.jsx(ZS,{setVizConf:r.setConf,panel:p,data:t,variables:d,vizManager:n})})}catch(x){return console.info(y.get(x,"message")),null}}const el=S.observer(function({data:e}){const{ref:n,width:r,height:i}=pe.useElementSize(),o=HS(e,{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})})})}),tl=S.observer(({panel:t})=>s.jsxs(a.Stack,{children:[t.queryErrors.map((e,n)=>s.jsx(a.Text,{color:"red",size:"sm",align:"center",sx:{fontFamily:"monospace"},children:e},`${n}-${e}`)),s.jsx(a.Text,{color:"gray",align:"center",size:"sm",children:t.queryStateMessages})]})),kr=S.observer(({panel:t})=>s.jsxs(a.Flex,{className:"panel-viz-section",direction:"column",sx:{position:"relative",width:"100%"},children:[s.jsx(a.LoadingOverlay,{visible:t.dataLoading,exitTransitionDuration:0}),!t.canRenderViz&&s.jsx(tl,{panel:t}),t.canRenderViz&&s.jsx(el,{data:t.data})]})),e1={border:"1px solid #e9ecef"},nl=S.observer(({panel:t,panelStyle:e,dropdownContent:n})=>{const{ref:r,downloadPanelScreenshot:i}=KS(t);return t.title.show,s.jsx(bs,{value:{panel:t,data:t.data,loading:t.dataLoading,errors:t.queryErrors,downloadPanelScreenshot:i},children:s.jsxs(a.Box,{className:`panel-root ${t.title.show?"panel-root--show-title":""}`,ref:r,p:0,sx:{...e1,...e},children:[s.jsx(a.Box,{className:"panel-description-popover-wrapper",children:s.jsx(_r,{})}),n,s.jsx(YS,{}),s.jsx(kr,{panel:t})]})})}),t1={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function n1(t){return t.style.border.enabled?{}:t1}const sl=S.observer(function({panel:e,view:n}){const r=n1(e);return s.jsx(nl,{panel:e,panelStyle:r,dropdownContent:s.jsx(QS,{view:n})})});function s1(t){return!["richText","button"].includes(t)}const r1=S.observer(({view:t})=>{const{panel:e,downloadPanelScreenshot:n}=dt(),{id:r}=e,{viewPanelInFullScreen:i,inFullScreen:o}=f.useContext(qn),l=f.useCallback(()=>{i(r)},[r,i]),c=!o&&t.type!==E.Modal;return s1(e.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:e.refreshData,icon:s.jsx(_.Refresh,{size:14}),children:"Refresh"}),s.jsx(a.Menu.Item,{onClick:e.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 i1(t){return t.style.border.enabled?{}:{border:"1px dashed transparent"}}const Tr=S.observer(({panel:t,view:e})=>{const n=i1(t);return s.jsx(nl,{panel:t,panelStyle:n,dropdownContent:s.jsx(r1,{view:e})})}),a1={modal:{display:"flex",flexDirection:"column",flexWrap:"nowrap"},body:{display:"flex",height:"calc(100vh - 88px)"}},rl=S.observer(function({view:e,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:a1,children:s.jsx(a.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:s.jsx(Tr,{view:e,panel:n})})})});function il(t,e,n){const{panels:r}=oe(),i=t.id==="Main",[o,l]=f.useState(()=>i&&r.findByID(e)?e: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="",o1=f.forwardRef(({h:t},e)=>s.jsx(a.ActionIcon,{ref:e,className:"react-grid-customDragHandle",sx:{userSelect:"none",cursor:"grab",position:"absolute",top:5,right:t>38?5:20,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",children:s.jsx(_.ArrowsMove,{size:16})})),l1=f.forwardRef(({handleAxis:t,...e},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",...e,children:s.jsx(_.ChevronDownRight,{size:16})})),c1=ln.WidthProvider(ln),u1=S.observer(({view:t,className:e="layout"})=>{const n=oe(),{panels:r,layouts:i}=n.panels.panelsByIDs(t.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(c1,{onLayoutChange:o,className:`dashboard-layout ${e}`,rowHeight:1,cols:36,margin:[0,0],isBounded:!0,isDraggable:!0,isResizable:!0,layout:i,draggableHandle:".react-grid-customDragHandle",resizeHandle:s.jsx(l1,{}),onResize:l,children:r.map((c,u)=>s.jsxs("div",{"data-grid":{...c.layout},className:"panel-grid-item",children:[s.jsx(o1,{h:c.layout.h}),s.jsx(sl,{view:t,panel:c})]},c.id))})}),d1=ln.WidthProvider(ln),p1=S.observer(function({view:e,className:n="layout"}){const{panels:r,layouts:i}=oe().panels.panelsByIDs(e.panelIDs);return s.jsx(d1,{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(Tr,{view:e,panel:o})},o.id))})});function Ir(t){const e=f.useRef(null);return{ref:e,downloadScreenshot:()=>{var l;const r=(l=e.current)==null?void 0:l.querySelector(".react-grid-layout");if(!r)return;const i=r.offsetWidth*2+10,o=r.offsetHeight*2+10;hi.toBlob(r,{bgcolor:"white",width:i,height:o,style:{transformOrigin:"0 0",transform:"scale(2)"}}).then(c=>{window.saveAs(c,`${t.name}.png`)})}}}const h1=S.observer(({downloadScreenShot:t})=>{const[e,{setTrue:n,setFalse:r}]=$.useBoolean(!1),i=gs(),o=oe(),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:e?1:.6,transform:`translateX(${e?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:t,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"})]})]})}),al=S.observer(({children:t,view:e,sx:n={}})=>{const{ref:r,downloadScreenshot:i}=Ir(e);return s.jsxs(s.Fragment,{children:[s.jsx(a.Box,{ref:r,sx:n,children:t}),s.jsx(h1,{downloadScreenShot:i})]})}),ol=S.observer(({downloadScreenshot:t})=>s.jsx(a.ActionIcon,{className:"download-screenshot-button",color:"blue",onClick:t,children:s.jsx(k.IconCamera,{size:14})})),x1=S.observer(({children:t,view:e})=>{const n=oe(),r=e.config,i=n.views.visibleViewIDs.includes(e.id),o=()=>n.views.rmVisibleViewID(e.id),{ref:l,downloadScreenshot:c}=Ir(e);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(ol,{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:t})})}),f1=t=>t.color?{"&[data-active], &[data-active]:hover":{borderColor:t.color?t.color:"..."}}:{},g1=S.observer(({view:t})=>{const e=oe(),n=t.config;return s.jsxs(a.Tabs,{className:"render-view-tabs",variant:n.variant,orientation:n.orientation,value:t.tab,onTabChange:t.setTab,styles:{root:{height:"100%",overflow:n.orientation==="horizontal"?"hidden":"auto"},panel:{padding:n.orientation==="horizontal"?"8px 0px 8px":"0",height:"100%",overflow:"auto"}},keepMounted:!1,children:[s.jsx(a.Tabs.List,{grow:n.grow,children:n.tabs.map(r=>s.jsx(a.Tabs.Tab,{value:r.id,sx:f1(r),disabled:!r.view_id,children:r.name??r.id},r.id))}),n.tabs.map(r=>{const i=e.views.findByID(r.view_id);return i?s.jsx(a.Tabs.Panel,{value:r.id,children:s.jsx(Qn,{view:i})},r.id):null})]})}),m1=S.observer(({view:t,children:e})=>{switch(t.type){case E.Modal:return s.jsx(x1,{view:t,children:e});case E.Tabs:return s.jsx(g1,{view:t});case E.Division:default:return s.jsx(al,{view:t,children:e})}}),y1=S.observer(({children:t,view:e})=>s.jsx(al,{sx:{paddingTop:"10px",paddingBottom:"100px"},view:e,children:t}));function ll(t){return t.replace(/(vw|vh)/,"%")}const b1=S.observer(({children:t,view:e})=>{const n=e.config,{width:r,height:i}=f.useMemo(()=>({width:ll(n.width),height:ll(n.height)}),[n.width,n.height]),{ref:o,downloadScreenshot:l}=Ir(e);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(ol,{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:t})})})}),j1=({variant:t,orientation:e})=>{const n={root:{height:"100%",overflow:"hidden"},tab:{},panel:{padding:"16px"}};return t==="pills"&&e==="horizontal"&&(n.tab.paddingTop="6px",n.tab.paddingBottom="6px"),e==="vertical"&&(n.tab["&.add-a-tab"]={paddingTop:"1px",paddingBottom:"1px"},n.tab["&.add-a-tab .mantine-Tabs-tabLabel"]={marginLeft:"auto",marginRight:"auto"}),n},v1=t=>t.color?{"&[data-active], &[data-active]:hover":{borderColor:t.color?t.color:"..."}}:{},w1=S.observer(({view:t})=>{const e=Me.useModals(),n=X(),r=f.useMemo(()=>n.views.options.filter(c=>c.type===E.Division),[t.id,n.views.options]),i=t.config,o=c=>e.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:t.tab,onTabChange:t.setTab,styles:j1(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)})]})}),C1=S.observer(({view:t,children:e})=>{switch(t.type){case E.Modal:return s.jsx(b1,{view:t,children:e});case E.Tabs:return s.jsx(w1,{view:t});case E.Division:default:return s.jsx(y1,{view:t,children:e})}}),cl=S.observer(function({view:e}){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(C1,{view:e,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(vo,{view:e})}),s.jsx(u1,{view:e})]})})})})}),Qn=S.observer(function({view:e}){const{fullScreenPanelID:n,setFullScreenPanelID:r}=Ei(),{viewPanelInFullScreen:i,exitFullScreen:o,inFullScreen:l,fullScreenPanel:c}=il(e,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:e.type===E.Modal?"0 !important":"100%"},children:[l&&s.jsx(rl,{view:e,panel:c,exitFullScreen:o}),s.jsx(m1,{view:e,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(vo,{view:e})}),!l&&s.jsx(p1,{view:e})]})})]})})});var ul=(t=>(t.Use="use",t.Edit="edit",t))(ul||{});const S1={[E.Division]:"Division",[E.Tabs]:"Tabs",[E.Modal]:"Modal"},dl={[E.Division]:"rgba(255, 0, 0, 0.2)",[E.Modal]:"rgba(0, 0, 0, 0.2)",[E.Tabs]:"rgba(255, 200, 100, 0.4)"},_1={[E.Division]:"#ff4000",[E.Modal]:"#000",[E.Tabs]:"#ffad18"},k1={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:E.Division,config:{},panelIDs:[]}],panels:[],filters:[],version:"9.19.0"};function T1(t,e,n){g.addDisposer(t,g.addMiddleware(t,(r,i)=>{i(r,()=>{g.getType(r.context)===e&&r.type==="action"&&n(r.name,r.context)})}))}const pl=g.types.compose("FiltersModel",Qo,g.types.model("FiltersModel",{previewValues:g.types.optional(g.types.frozen(),{})})).views(t=>({get idSet(){return new Set(t.current.map(e=>e.id))},get keySet(){return new Set(t.current.map(e=>e.key))},get options(){return t.current.map(e=>({label:e.label??e.id,value:e.id,_type:"filter"}))},get selects(){return t.current.filter(e=>e.type===ce.Select).map(e=>({label:e.label??e.id,value:e.id}))},get keyLabelOptions(){return t.current.map(e=>({label:e.label??e.key,value:e.key}))},get sortedList(){return y.sortBy(t.current,e=>e.label.toLowerCase())}})).actions(t=>({replace(e){t.current=g.cast(e)},append(e){t.current.push(e)},appendMultiple(e){if(e.length===0)return;const n=e.filter(r=>!t.idSet.has(r.id));t.current.push(...n)},remove(e){t.current.splice(e,1)},removeByID(e){const n=t.current.findIndex(r=>r.id===e);n>=0&&t.current.splice(n,1)},updatePreviewValues(e){t.previewValues=e}})).actions(t=>{function e(){T1(t.current,zo,(n,r)=>{if(n==="setType"){const i=Ro(r.config.default_value,r.config);t.setValueByKey(r.key,i),t.updatePreviewValues({...t.previewValues,[r.key]:i})}})}return{afterCreate(){e()}}}),hl=Yo.views(t=>({get options(){const e=t.current.map(n=>({value:n.id,label:n.name,_type:"query"}));return y.sortBy(e,n=>n.label.toLowerCase())},get sortedList(){return y.sortBy(t.current,e=>e.name.toLowerCase())}})).actions(t=>({replace(e){t.current=g.cast(e)},append(e){t.current.push(e)},appendMultiple(e){if(e.length===0)return;const n=e.filter(r=>!t.idSet.has(r.id));t.current.push(...n)},remove(e){t.current.splice(e,1)},replaceByIndex(e,n){t.current.splice(e,1,n)},removeQuery(e){const n=t.current.find(r=>r.id===e);n&&(g.detach(n),t.current.remove(n))},removeQueries(e){const n=new Set(e);t.current.forEach(i=>{n.has(i.id)&&g.detach(i)});const r=[...t.current];y.remove(r,i=>n.has(i.id)),t.current=g.cast(r)}})),xl=Ko.views(t=>({get sortedList(){return y.sortBy(t.current,e=>e.key.toLowerCase())},get options(){const e=t.current.map(n=>({label:n.key,value:n.key,_type:"sql_snippet"}));return y.sortBy(e,n=>n.label.toLowerCase())}})).actions(t=>({replace(e){t.current=g.cast(e)},append(e){t.current.push(e)},appendMultiple(e){if(e.length===0)return;const n=e.filter(r=>!t.keySet.has(r.key));t.current.push(...n)},remove(e){t.current.splice(e,1)},removeByKey(e){const n=t.current.findIndex(r=>r.key===e);n>=0&&t.current.splice(n,1)},removeByKeys(e){const n=new Set(e);t.current.forEach(i=>{n.has(i.key)&&g.detach(i)});const r=[...t.current];y.remove(r,i=>n.has(i.key)),t.current=g.cast(r)},replaceByIndex(e,n){t.current.splice(e,1,n)}})),I1=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(t=>({get loading(){return t.state==="loading"},get empty(){return t.data.length===0}})),D1=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(t=>({get loading(){return t.state==="loading"},get empty(){return t.data.length===0}})),M1=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(t=>({get keywords(){return g.getParent(t,1)},get keywordString(){const{table_name:e,table_schema:n}=g.getParent(t,1);return`${n}||${e}`}})).views(t=>({get loading(){return t.state==="loading"},get empty(){return t.data.length===0},get maxPage(){return Math.ceil(t.total/t.limit)},get offset(){return(t.page-1)*t.limit},get countSql(){const{table_name:e,table_schema:n}=t.keywords;return`
441
441
  SELECT count(*) AS total
442
442
  FROM ${n}.${e}
443
- `}})).actions(t=>({setPage(e){t.page=e},resetPage(){t.page=1},setLimit(e){t.limit=e}})).actions(t=>({afterCreate(){g.addDisposer(t,W.reaction(()=>t.keywordString,t.resetPage,{fireImmediately:!1,delay:0})),g.addDisposer(t,W.reaction(()=>t.limit,t.resetPage,{fireImmediately:!1,delay:0}))}})),B1=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(t=>({get loading(){return t.state==="loading"},get empty(){return Object.keys(t.data).length===0}})),O1=g.types.compose("DataSourceModel",Lo,g.types.model({tables:g.types.optional(B1,{}),columns:g.types.optional(E1,{}),tableData:g.types.optional(L1,{}),indexes:g.types.optional(P1,{}),table_schema:g.types.optional(g.types.string,""),table_name:g.types.optional(g.types.string,"")})).views(t=>({get sqlDataSourceType(){return t.type},get reloadConditionString(){const{type:e,table_name:n,table_schema:r}=t;return`${e};${n};${r}`}})).volatile(()=>({controllers:{tables:new AbortController,columns:new AbortController,indexes:new AbortController,tableData:new AbortController}})).actions(t=>({setKeywords(e,n){t.table_schema=e,t.table_name=n}})).actions(t=>({initKeywords(){if(t.tables.empty)return;const e=Object.keys(t.tables.data)[0],n=t.tables.data[e][0].table_name;t.setKeywords(e,n)}})).actions(t=>{const e=g.flow(function*(){var n;(n=t.controllers.tables)==null||n.abort(),t.controllers.tables=new AbortController,t.tables.state="loading";try{const r=yield*g.toGenerator(Ue.structure(t.controllers.tables.signal)({query_type:"TABLES",type:t.sqlDataSourceType,key:t.key,table_schema:"",table_name:""},{params:{query_type:"TABLES"}}));t.tables.data=y.groupBy(r,"table_schema"),t.tables.state="idle",t.tables.error=null,t.initKeywords()}catch(r){if(!tt.isCancel(r)){t.tables.data={};const i=y.get(r,"message","unkown error");t.tables.error=y.get(r,"response.data.detail.message",i),t.tables.state="error"}}});return{loadTables:e,loadTablesIfEmpty(){t.tables.empty&&e()},loadColumns:g.flow(function*(){var n;(n=t.controllers.columns)==null||n.abort(),t.controllers.columns=new AbortController,t.columns.state="loading";try{t.columns.data=yield*g.toGenerator(Ue.structure(t.controllers.columns.signal)({query_type:"COLUMNS",type:t.sqlDataSourceType,key:t.key,table_schema:t.table_schema,table_name:t.table_name},{params:{query_type:"COLUMNS"}})),t.columns.state="idle",t.columns.error=null}catch(r){if(tt.isCancel(r))t.columns.state="idle",t.columns.error=null;else{t.columns.data=[];const i=y.get(r,"message","unkown error");t.columns.error=y.get(r,"response.data.detail.message",i),t.columns.state="error"}}}),loadIndexes:g.flow(function*(){var n;(n=t.controllers.indexes)==null||n.abort(),t.controllers.indexes=new AbortController,t.indexes.state="loading";try{t.indexes.data=yield*g.toGenerator(Ue.structure(t.controllers.indexes.signal)({query_type:"INDEXES",type:t.sqlDataSourceType,key:t.key,table_schema:t.table_schema,table_name:t.table_name},{params:{query_type:"INDEXES"}})),t.indexes.state="idle",t.indexes.error=null}catch(r){if(tt.isCancel(r))t.indexes.state="idle",t.indexes.error=null;else{t.indexes.data=[];const i=y.get(r,"message","unkown error");t.indexes.error=y.get(r,"response.data.detail.message",i),t.indexes.state="error"}}}),loadTableData:g.flow(function*(){var r;(r=t.controllers.tableData)==null||r.abort(),t.controllers.tableData=new AbortController;const n=t.tableData;n.state="loading";try{n.data=yield*g.toGenerator(Ue.structure(t.controllers.tableData.signal)({query_type:"DATA",type:t.sqlDataSourceType,key:t.key,table_schema:t.table_schema,table_name:t.table_name,limit:n.limit,offset:n.offset},{params:{query_type:"DATA"}}));const[{total:i}]=yield*g.toGenerator(Ue.structure(t.controllers.tableData.signal)({query_type:"COUNT",type:t.sqlDataSourceType,key:t.key,table_schema:t.table_schema,table_name:t.table_name},{params:{query_type:"COUNT"}}));n.total=Number(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(t=>({afterCreate(){g.addDisposer(t,W.reaction(()=>t.reloadConditionString,t.loadColumns,{fireImmediately:!1,delay:500}))}})).actions(t=>({afterCreate(){g.addDisposer(t,W.reaction(()=>t.reloadConditionString,t.loadIndexes,{fireImmediately:!1,delay:500})),g.addDisposer(t,W.reaction(()=>`${t.reloadConditionString};limit:${t.tableData.limit};offset:${t.tableData.offset}`,t.loadTableData,{fireImmediately:!1,delay:0}))}})),$1=g.types.model("DataSourcesModel",{list:g.types.optional(g.types.array(O1),[])}).views(t=>({find({type:e,key:n}){return t.list.find(r=>r.key===n&&r.type===e)},get options(){return t.list.map(e=>({value:e.key,label:e.key}))}})).actions(t=>({replace(e){t.list.length=0,t.list.push(...e)}}));function St(t){return{label:t,value:t,_type:"ACTION",_action_type:t,Icon:null,children:null}}function V1(t){switch(t._type){case"GROUP":case"ACTION":return null;case"query_variables":return["_QUERY_VARS_"];case"mock_context":return["_MOCK_CONTEXT_"];case"filter":return["_FILTERS_",t.value];case"sql_snippet":return["_SQL_SNIPPETS_",t.value];case"query":return["_QUERIES_",t.value];case"view":return["_VIEWS_",t.value];case"panel":return t.parentID?["_VIEWS_",t.parentID,"_PANELS_",t.value]:(console.error("[getPathFromOption] parentID is required"),null)}}const N1=g.types.model("EditorModel",{path:g.types.optional(g.types.frozen(),[]),settings_open:g.types.optional(g.types.boolean,!1)}).views(t=>({get navOptions(){const{content:e}=g.getRoot(t),{filters:n,views:r,sqlSnippets:i,queries:o}=e;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(e,n){return e.length===0?!1:e[e.length-1]===n.value},isOptionOpened(e){const{path:n}=t;return n.length===0||!e.children||e.children.length===0?!1:n.includes(e.value)}})).actions(t=>({setPath(e){t.path=e},setSettingsOpen(e){t.settings_open=e}})).actions(t=>({open(e){t.setPath(e),t.setSettingsOpen(!0)},close(){t.setSettingsOpen(!1)},navigate(e){const n=V1(e);n&&t.setPath(n)}})),xl=Fo.views(t=>({get dataFieldOptions(){return t.queryIDs.length===0?[]:t.queries.map(e=>{const n=e.data;return n.length===0?[]:Object.keys(n[0]).map(i=>({label:i,value:`${e.id}.${i}`,group:e.name}))}).flat()}})).actions(t=>({removeSelf(){g.getParent(t,2).removeByID(t.id)}})).actions(t=>({moveToView(e,n){g.getRoot(t).content.views.findByID(e).removePanelID(t.id),g.getRoot(t).content.views.findByID(n).appendPanelID(t.id),g.getRoot(t).editor.setPath(["_VIEWS_",n,"_PANELS_",t.id])}})),fl=g.types.compose("PanelsModel",Go,g.types.model({list:g.types.optional(g.types.array(xl),[])})).views(t=>({editorOptions(e,n){const{panels:r}=t.panelsByIDs(n);r.length!==n.length&&console.warn(`Unfulfilled panels for View[${e}]`);const i=r.map(l=>({label:l.name,value:l.id,_type:"panel",parentID:e})),o="_Add_A_PANEL_";return i.push({label:o,value:o,_type:"ACTION",_action_type:o,parentID:e,Icon:null,children:null}),i}})).actions(t=>({replace(e){t.list=g.castToSnapshot(e)},append(e){t.list.push(e)},appendMultiple(e){e.length!==0&&t.list.push(...e)},remove(e){t.list.splice(e,1)},removeByID(e){const n=t.list.findIndex(r=>r.id===e);n!==-1&&t.list.splice(n,1)},removeByIDs(e){e.forEach(n=>{this.removeByID(n)})},duplicateByID(e){const n=t.list.find(i=>i.id===e);if(!n){console.error(new Error(`[duplicate panel] Can't find a panel by id[${e}]`));return}const r=new Date().getTime().toString();return t.list.push({...n.json,id:r,title:{...n.json.title},layout:{...n.layout,y:1/0,moved:!1}}),r},replaceByIndex(e,n){t.list.splice(e,1,n)}})),q1=$o.actions(t=>({getSchema(){const e=t.json,n=[],r=[];return t.panels.forEach(o=>{const l=o.getSchema();n.push(l.panel),l.queries.length>0&&r.push(...l.queries)}),{views:[e],panels:n,definition:{queries:y.uniqBy(r,o=>o.id)}}},downloadSchema(){if(t.type===E.Tabs){console.error(new Error("Please choose a tab first"));return}const e=JSON.stringify(this.getSchema(),null,2),n=t.name;Ct(n,e)}})),gl=g.types.compose("ViewsModel",Vo,g.types.model({current:g.types.optional(g.types.array(q1),[]),idOfVIE:g.types.string})).views(t=>({get isVIETheFirstView(){return t.current.length===0||!t.idOfVIE?!1:t.current[0].id===t.idOfVIE},get VIE(){return t.current.find(({id:e})=>e===t.idOfVIE)},get options(){return t.current.map(e=>({label:e.name,value:e.id,type:e.type}))},get editorOptions(){const e=g.getRoot(t).content.panels;return t.current.map(n=>({label:n.name,value:n.id,_type:"view",children:e.editorOptions(n.id,n.panelIDs)}))}})).actions(t=>({setIDOfVIE(e){t.idOfVIE=e,t.visibleViewIDs.length=0,t.visibleViewIDs.push(e)},replace(e){t.current.replace(e)},addANewView(e,n,r,i){t.current.push({id:e,name:n,type:r,config:i,panelIDs:[]})},append(e){t.current.push(e)},appendMultiple(e){e.length!==0&&t.current.push(...e)},remove(e){t.current.splice(e,1)},removeByID(e){const n=t.current.findIndex(o=>o.id===e);if(n===-1)return;const r=t.current[n];g.getRoot(t).content.panels.removeByIDs(r.panelIDs),t.current.splice(n,1)},replaceByIndex(e,n){t.current.splice(e,1,n)},addARandomNewView(){const e=new Date().getTime().toString();this.addANewView(e,E.Division,E.Division,{_name:E.Division}),this.setIDOfVIE(e)},removeVIE(){t.current.length!==1&&(this.removeByID(t.idOfVIE),this.setIDOfVIE(t.current[0].id))}}));function Dr(t){const e=t.length>0?[t[0].id]:[],n=t.length>0?t[0].id:"";return{current:t.map(i=>{const{_name:o=i.type}=i.config;return{...i,config:{...i.config,_name:o},panelIDs:i.panelIDs}}),visibleViewIDs:e,idOfVIE:n}}const F1=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:dl,queries:pl,sqlSnippets:hl,views:gl,panels:fl,mock_context:vo,origin:g.types.maybe(g.types.frozen())}).views(t=>({get json(){return{id:t.id,name:t.name,create_time:t.create_time,update_time:t.update_time,dashboard_id:t.dashboard_id,content:{views:t.views.json,panels:t.panels.json,filters:t.filters.json,version:t.version,definition:{queries:t.queries.json,sqlSnippets:t.sqlSnippets.json,mock_context:t.mock_context.current}}}},get contentJSON(){return this.json.content},get filtersChanged(){const e="filters.current";return!y.isEqual(g.getSnapshot(y.get(t,e)),y.get(t.origin,e))},get queriesChanged(){const e="queries.current",n=g.getSnapshot(y.get(t,e)).map(r=>y.pick(r,["id","name","key","type","sql","run_by","react_to","pre_process","post_process"]));return!y.isEqual(n,y.get(t.origin,e))},get sqlSnippetsChanged(){const e="sqlSnippets.current";return!y.isEqual(g.getSnapshot(y.get(t,e)),y.get(t.origin,e))},get viewsChanged(){const e="views.current";return!y.isEqual(t.views.json,y.get(t.origin,e))},get panelsChanged(){const e="panels.list";return!y.isEqual(g.getSnapshot(y.get(t,e)),y.get(t.origin,e))},get mockContextChanged(){const e="mock_context.current";return!y.isEqual(y.get(t,e),y.get(t.origin,e))},get payloadForSQL(){const e=g.getParent(t).context.current,n=g.getParent(t).globalSQLSnippets,r={context:{...t.mock_context.current,...e},filters:t.filters.values};return{...r,sql_snippets:Rn(t.sqlSnippets.current,"key","value",r),global_sql_snippets:Rn(n.list,"id","content",r)}},get payloadForViz(){const e=g.getParent(t).context.current;return{context:{...t.mock_context.current,...e},filters:t.filters.values}},get dashboardState(){return ds(this.payloadForSQL)},getAdditionalQueryInfo(e){return{content_id:t.id,query_id:e,params:this.dashboardState}},get changed(){return this.filtersChanged||this.queriesChanged||this.sqlSnippetsChanged||this.viewsChanged||this.panelsChanged||this.mockContextChanged},get data(){return t.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(e){const n=t.queries.findByID(e);return n?{data:n.data,len:n.data.length,state:n.state,error:n.error}:{data:[],len:0,state:"idle",error:void 0}}})).views(t=>({get queriesUsage(){const e=t.panels.idMap,n=[];t.views.current.forEach(i=>{i.panelIDs.forEach(o=>{const l=e.get(o);if(!l)return;const c="panel",u=l.name,d=[{id:i.id,label:i.name}];l.queryIDs.forEach(h=>{n.push({id:o,queryID:h,type:c,label:u,views:d})})})});const r=t.views.idMap;return t.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 t.queries.current.length>Object.keys(this.queriesUsage).length},findQueryUsage(e){return this.queriesUsage[e]??[]},get sqlSnippetsUsage(){const e=[];return t.queries.current.forEach(n=>{if(!n.typedAsSQL)return;y.uniq(n.sql.match(Wn.sqlSnippet)).forEach(i=>{e.push({queryID:n.id,sqlSnippetKey:i,queryName:n.name})})}),y.groupBy(e,"sqlSnippetKey")},get hasUnusedSQLSnippets(){return t.sqlSnippets.current.length>Object.keys(this.sqlSnippetsUsage).length},findSQLSnippetUsage(e){return this.sqlSnippetsUsage[e]??[]}})).actions(t=>({removeUnusedQueries(){const e=new Set(Object.keys(t.queriesUsage)),n=t.queries.current.filter(r=>!e.has(r.id)).map(r=>r.id);t.queries.removeQueries(n)},removeUnusedSQLSnippets(){const e=new Set(Object.keys(t.sqlSnippetsUsage)),n=t.sqlSnippets.current.filter(r=>!e.has(r.key)).map(r=>r.key);t.sqlSnippets.removeByKeys(n)},duplicatePanelByID(e,n){var i;const r=t.panels.duplicateByID(e);r&&((i=t.views.findByID(n))==null||i.appendPanelID(r))},removePanelByID(e,n){var r;t.panels.removeByID(e),(r=t.views.findByID(n))==null||r.removePanelID(e)},addANewPanel(e){var r;const n=as.v4();t.panels.append(OS(n)),(r=t.views.findByID(e))==null||r.appendPanelID(n)},applyJSONSchema(e){var h;const{views:n,panels:r,filters:i,definition:o={}}=e,{queries:l,sqlSnippets:c,mock_context:u}=o,d=new Map;if(Array.isArray(r)){const p=r.map(x=>{const m=as.v4();return d.set(x.id,m),{...x,id:m}});if(t.panels.appendMultiple(p),!Array.isArray(n)||n.length===0){const x=p.map(m=>m.id);(h=t.views.VIE)==null||h.appendPanelIDs(x)}}if(Array.isArray(n)){const p=n.map(x=>{const m=x.panelIDs.map(j=>d.get(j)??j);return{...x,id:as.v4(),panelIDs:m}});t.views.appendMultiple(p)}Array.isArray(i)&&t.filters.appendMultiple(i),Array.isArray(l)&&t.queries.appendMultiple(l),Array.isArray(c)&&t.sqlSnippets.appendMultiple(c),u&&Object.keys(u).length>0&&t.mock_context.defaults(u)}})).actions(t=>({reset(){g.applySnapshot(t.filters.current,t.origin.filters.current),g.applySnapshot(t.queries.current,t.origin.queries.current),g.applySnapshot(t.sqlSnippets.current,t.origin.sqlSnippets.current),g.applySnapshot(t.views.current,t.origin.views.current),g.applySnapshot(t.panels.list,t.origin.panels.list),t.mock_context.current=t.origin.mock_context.current},resetFilters(){g.applySnapshot(t.filters.current,t.origin.filters.current)},updateCurrent(e){const{id:n,name:r,content:i}=e;if(!i)throw new Error("unexpected null content when updating a content model");const{version:o,filters:l,views:c,panels:u,definition:{queries:d,sqlSnippets:h,mock_context:p={}}}=i;t.id=n,t.name=r,t.version=o,g.applySnapshot(t.filters.current,l),g.applySnapshot(t.views.current,Dr(c).current),g.applySnapshot(t.panels.list,u),g.applySnapshot(t.queries.current,d),g.applySnapshot(t.sqlSnippets.current,h),t.mock_context.current=p}})),Mr=g.types.snapshotProcessor(F1,{preProcessor(t){return{...t,origin:t}},postProcessor(t){delete t.origin;const e=g.castToSnapshot(t.queries.current.map(n=>y.pick(n,["id","key","type","sql"])));return y.defaults({},{queries:{current:e}},t)}});function G1(t,e){e.filters&&g.applySnapshot(t.filters.current,e.filters)}function ml({id:t,name:e,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:h,sqlSnippets:p,mock_context:x={}}}=o;return Mr.create({id:t,name:e,dashboard_id:n,create_time:r,update_time:i,version:l,filters:Qo(c),queries:{current:h},sqlSnippets:{current:p},mock_context:wo(x),views:Dr(u),panels:{list:d}})}const yl=g.types.model({id:g.types.identifier,name:g.types.string,group:g.types.string,content:Mr,content_id:g.types.string,datasources:$1,globalSQLSnippets:Bo,context:Sr,editor:N1}).views(t=>({get json(){return{id:t.id,name:t.name,group:t.group,content_id:t.content_id}}})).actions(t=>({updateCurrentContent(e){t.content.updateCurrent(e)},updateCurrent(e,n){const{id:r,name:i,group:o,content_id:l}=e;t.id=r,t.name=i,t.group=o,t.content_id=l,this.updateCurrentContent(n)}}));function bl({id:t,name:e,group:n,content_id:r},i,o,l,c){return yl.create({id:t,name:e,group:n,content_id:r,content:ml(i),datasources:{list:o},globalSQLSnippets:{list:l},context:Oo(c),editor:{}})}function jl(t,e){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}t.views.appendToVisibles(i),e&&t.views.setIDOfVIE(i)};return window.addEventListener("open-view",n),()=>{window.removeEventListener("open-view",n)}},[t,e]),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])=>{t.filters.setValueByKey(l,y.get(o,c))})};return window.addEventListener("set-filter-values",n),()=>{window.removeEventListener("set-filter-values",n)}},[t]),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(t.filters.values,l),u=n(c);console.log(`${l}: ${u}`),t.filters.setValueByKey(l,u)})};return window.addEventListener("clear-filter-values",r),()=>{window.removeEventListener("clear-filter-values",r)}},[t]),f.useEffect(()=>{const n=r=>{console.log(r);const{urlTemplate:i,openInNewTab:o,enableEncoding:l=!1,payload:c}=r.detail;if(!i){console.error(new Error("[Open Link] URL is empty"));return}function u(p){return y.cloneDeepWith(p,m=>{if(l&&typeof m=="string")return encodeURIComponent(m)})}const h=y.template(i||"")(u({...c,filters:t.payloadForSQL.filters,context:t.payloadForSQL.context}));window.open(h,o?"_blank":"_self","noopener")};return window.addEventListener("open-link",n),()=>{window.removeEventListener("open-link",n)}},[t])}function vl(t){return f.useCallback(e=>e.provideValue(le.pluginManager,t.pluginManager).provideValue(le.vizManager,t.vizManager).provideValue(le.colorManager,t.colorManager),[])}const tD="",W1=S.observer(()=>{const t=ms(),e=X(),n=()=>{const r=JSON.stringify(e.contentJSON,null,2),i=`${t.name}__${e.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:e.queries.downloadAllData,children:"Download Data"}),s.jsx(a.Menu.Item,{icon:s.jsx(k.IconCode,{size:14}),onClick:n,children:"Download Schema"})]})]})}),R1=S.observer(({saveDashboardChanges:t})=>{const e=Me.useModals(),n=X(),r=()=>{e.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:t,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"})})]})]})}),Q1=S.observer(({saveDashboardChanges:t,headerSlot:e=null})=>{const n=Hc.useNavigate(),r=U(),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(R1,{saveDashboardChanges:t})]}),s.jsxs(a.Group,{position:"right",sx:{flexGrow:1},children:[e,s.jsx(W1,{})]})]})})}),wl={height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},Y1=S.observer(()=>{var r;const t=X(),e=((r=t.views.VIE)==null?void 0:r.type)===E.Tabs,n=()=>t.addANewPanel(t.views.idOfVIE);return e?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:{...wl,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:{...wl,background:"rgb(231, 245, 255)"},children:"Add a Panel"})});function K1(t){if(t.target===null)throw new Error("FileReader failed with null result");if(typeof t.target.result!="string")throw new Error(`Unparsable file content of type: ${typeof t.target.result}`);let e=JSON.parse(t.target.result);return"content"in e&&(e=e.content),e}const U1=S.observer(({view:t})=>!t||t.type!==E.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"})]})),X1=[{value:"default",label:"Default"},{value:"outline",label:"Outline"},{value:"pills",label:"Pills"}],J1=[{value:"horizontal",label:"Horizontal"},{value:"vertical",label:"Vertical"}],Z1=S.observer(({view:t})=>{if(!t||t.type!==E.Tabs)return null;const e=t.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:e.variant,onChange:e.setVariant,data:X1}),s.jsx(a.Select,{label:"Orientation",value:e.orientation,onChange:e.setOrientation,data:J1}),s.jsx(a.Switch,{label:"Grow Tabs",checked:e.grow,onChange:n=>e.setGrow(n.currentTarget.checked)})]})}),H1=({disabled:t,value:e,onChange:n})=>{const r=i=>{i&&n(i)};return s.jsxs(a.Box,{sx:{position:"relative"},children:[t&&s.jsx(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),s.jsx(me,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},e_=({value:t,onChange:e})=>{const[n,{setTrue:r,setFalse:i}]=$.useBoolean(),[o,l]=f.useState(t??Cr),c=x=>{l({...o,enabled:x})},u=()=>{i();const{enabled:x,func_content:m}=o,j={enabled:x,func_content:m};l(j),e(j)},d=()=>{i(),l(t)},h=x=>{l(m=>({...m,func_content:x}))},p=()=>{h(Cr.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(H1,{value:o.func_content,onChange:h,disabled:!o.enabled}),s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{onClick:p,color:"red",leftIcon:s.jsx(_.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"})]})]})]})})]})},t_=S.observer(({view:t})=>{if(!t||t.type!==E.Modal)return null;const e=t.config,n=e.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(e_,{value:e.custom_modal_title,onChange:e.custom_modal_title.replace})]}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(a.TextInput,{label:"Width",value:e.width,onChange:r=>e.setWidth(r.currentTarget.value),placeholder:"600px / 50vw"}),s.jsx(a.TextInput,{label:"Height",value:e.height,onChange:r=>e.setHeight(r.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),n_=S.observer(({view:t})=>s.jsxs(s.Fragment,{children:[s.jsx(U1,{view:t}),s.jsx(t_,{view:t}),s.jsx(Z1,{view:t})]})),Kn={[E.Division]:"Division",[E.Modal]:"Modal",[E.Tabs]:"Tabs"},s_=[{label:Kn[E.Division],value:E.Division},{label:Kn[E.Modal],value:E.Modal},{label:Kn[E.Tabs],value:E.Tabs}],r_=S.observer(({view:t})=>t?s.jsxs(a.Stack,{sx:{position:"relative"},children:[s.jsx(a.TextInput,{label:"Name",value:t.name,onChange:e=>{t.setName(e.currentTarget.value)}}),s.jsx(a.Select,{label:"Type",withinPortal:!0,zIndex:320,value:t.type,onChange:t.setType,data:s_}),s.jsx(n_,{view:t})]}):null),Un=({headers:t,rows:e})=>s.jsxs(a.Table,{fontSize:"xs",highlightOnHover:!0,sx:{tableLayout:"fixed",fontFamily:"monospace"},children:[s.jsx("thead",{children:t}),s.jsx("tbody",{children:e})]}),i_=({content:t})=>{const e=t.views;return!Array.isArray(e)||e.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(Un,{headers:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"160px"},children:"ID"}),s.jsx("th",{children:"Name"}),s.jsx("th",{children:"Type"})]}),rows:e.map(n=>s.jsxs("tr",{children:[s.jsx("td",{children:n.id}),s.jsx("td",{children:n.name}),s.jsx("td",{children:Kn[n.type]})]},n.id))})]})},a_=({content:t})=>{const e=t.filters;return!Array.isArray(e)||e.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(Un,{headers:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"160px"},children:"ID"}),s.jsx("th",{children:"Key"}),s.jsx("th",{children:"Label"})]}),rows:e.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))})]})},o_=({content:t})=>{const e=t.panels;return!Array.isArray(e)||e.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(Un,{headers:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"160px"},children:"ID"}),s.jsx("th",{children:"Name"}),s.jsx("th",{children:"Visualization"})]}),rows:e.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))})]})},l_=({content:t})=>{var n;const e=(n=t.definition)==null?void 0:n.queries;return!Array.isArray(e)||e.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(Un,{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:e.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:t})=>{var n;const e=(n=t.definition)==null?void 0:n.sqlSnippets;return!Array.isArray(e)||e.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:e.map(r=>s.jsx(a.List.Item,{children:r.key},r.key))})]})},u_=({content:t})=>{var n;const e=Object.keys(((n=t.definition)==null?void 0:n.mock_context)??{});return e.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:e.map(r=>s.jsx(a.List.Item,{children:r},r))})]})},d_=({content:t})=>t?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(i_,{content:t}),s.jsx(a_,{content:t}),s.jsx(o_,{content:t}),s.jsx(l_,{content:t}),s.jsx(c_,{content:t}),s.jsx(u_,{content:t})]})]}):null,p_=S.observer(({onSuccess:t,stretchModal:e,shrinkModal:n})=>{var C;const r=X(),{handleSubmit:i,formState:{errors:o},setValue:l,watch:c,setError:u,clearErrors:d}=b.useForm({defaultValues:{content:null}}),h=({content:T})=>{try{if(!T)throw new Error("please use a valid json file");r.applyJSONSchema(T),ht.showNotification({title:"Successful",message:"",color:"green"}),t()}catch(A){console.error(A),ht.showNotification({title:"Failed",message:A.message,color:"red"})}},[p,x]=f.useState(null);f.useEffect(()=>{if(!p)return;const T=new FileReader;T.readAsText(p,"UTF-8"),T.onload=A=>{try{const L=K1(A);l("content",L),d("content")}catch(L){console.error(L),u("content",{type:"custom",message:L.message})}},T.onabort=()=>console.log("🟨 abort"),T.onerror=()=>{T.error&&(console.error(T.error),u("content",{type:"custom",message:T.error.message}))}},[p]);const[m]=c(["content"]),j=!m;return f.useEffect(()=>{m?e():n()},[m]),s.jsx(a.Box,{mx:"auto",sx:{position:"relative"},children:s.jsxs("form",{onSubmit:i(h),children:[s.jsx(a.FileInput,{label:"JSON File",required:!0,value:p,onChange:x,error:(C=o==null?void 0:o.content)==null?void 0:C.message,sx:{maxWidth:500}}),s.jsx(d_,{content:m}),s.jsx(a.Group,{position:"right",my:"md",children:s.jsx(a.Button,{type:"submit",color:"green",disabled:j,children:"Confirm"})})]})})}),Cl={height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},h_=S.observer(()=>{var u;const[t,{open:e,close:n}]=pe.useDisclosure(!1),[r,{setTrue:i,setFalse:o}]=$.useBoolean(!1),c=((u=U().content.views.VIE)==null?void 0:u.type)===E.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:{...Cl,transform:"none !important"},children:"Import..."})}):s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"subtle",color:"blue",radius:0,size:"xs",disabled:c||t,onClick:e,leftIcon:s.jsx(k.IconFileImport,{size:16}),sx:{...Cl},children:"Import..."}),s.jsx(a.Modal,{opened:t,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(p_,{onSuccess:n,stretchModal:i,shrinkModal:o})})]})}),Sl={height:"30px",borderRight:"none",borderTop:"none",borderLeft:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},x_=S.observer(()=>{var r;const t=X(),e=((r=t.views.VIE)==null?void 0:r.type)===E.Tabs,n=()=>{var i;return(i=t.views.VIE)==null?void 0:i.downloadSchema()};return e?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:{...Sl,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:{...Sl},children:"Download this View"})}),f_={position:"fixed",top:60,left:0,right:0,height:30,zIndex:299,borderBottom:"1px solid #e9ecef",background:"rgba(233,236,239, 0.15)"},g_=S.observer(()=>s.jsx(a.Box,{sx:f_,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(Y1,{}),s.jsx(h_,{})]}),s.jsx(a.Box,{}),s.jsx(a.Group,{position:"right",spacing:0,children:s.jsx(x_,{})})]})})),m_=S.observer(t=>s.jsxs(s.Fragment,{children:[s.jsx(Q1,{...t}),s.jsx(g_,{})]})),nD="";function y_(t,e,n){const r=[];return t.filter(i=>"__INTERACTIONS"in i.viz.conf).forEach((i,o)=>{const l=e[i.id];l.data.interactions=y.get(l,"data.interactions",[]);const{__INTERACTIONS:c,__OPERATIONS:u,__TRIGGERS:d}=i.viz.conf;Object.entries(u).forEach(([h,p])=>{const{schemaRef:x,data:m}=p,{config:j}=m;switch(x){case"builtin:op:open-link":let C=j.urlTemplate.substring(0,100);j.urlTemplate.length>=20&&(C+="..."),l.type="interaction",l.data.interactions.push({schemaRef:x,urlTemplate:j.urlTemplate,shortURLTemplate:C});return;case"builtin:op:open_view":r.push({id:`OPERATION--${h}`,source:i.id,target:j.viewID,label:"Open View",style:{stroke:"rgba(0,0,0,0.8)"},type:"default"});return;case"builtin:op:set_filter_values":l.type="interaction",l.data.interactions.push({schemaRef:x,filters:Object.keys(j.dictionary).map(T=>({key:T,label:n[T]}))});return;case"builtin:op:clear_filter_values":l.type="interaction",l.data.interactions.push({schemaRef:x,filters:j.filter_keys.map(T=>({key:T,label:n[T]}))});return;default:return}})}),r}function b_(t,e){const n=t.filters.keyLabelMap;return{edges:y_(t.panels.list,e,n),edgeNodes:[]}}function _l(t,e,n){return t*e+t*n}function j_(t,e,n){return t*e+(t-1)*n}const Xn=25,Ar=40,kl=25,zr=350,v_=150,w_=150,Tl=150,Il=300,Jn=40,Dl=25,C_=300;function S_(t,e){const n=y.keyBy(e,i=>i.id),r=[];return t.current.forEach((i,o)=>{i.panelIDs.forEach((l,c)=>{const u=_l(c,Jn,Dl)+Ar,d=n[l];if(!d){r.push({id:l,_node_type:"panel",parentNode:i.id,data:{label:`!: ${l}`},position:{x:Xn,y:u},sourcePosition:be.Position.Right,targetPosition:be.Position.Left,style:{width:Il,height:Jn}});return}const h=d.name;r.push({id:d.id,_node_type:"panel",parentNode:i.id,data:{label:h},position:{x:Xn,y:u},sourcePosition:be.Position.Right,targetPosition:be.Position.Left,style:{width:Il,height:Jn}})})}),r}const __={[E.Division]:"Div",[E.Modal]:"Modal",[E.Tabs]:"Tabs"},k_=ul;function T_(t){return t.current.map((n,r)=>{const i=j_(n.panelIDs.length,Jn,Dl)+Ar+kl;let o=[];return n.type===E.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:k_[n.type],width:zr,height:i}}})}function I_(t){const e=y.keyBy(t,n=>n.id);t.forEach(n=>{n._node_type!=="view-root"||n._view_type!==E.Tabs||n._tab_view_ids.forEach(r=>{e[r].parentNode=n.id})})}function D_(t){const e=T_(t.views);I_(e);const n=S_(t.views,t.panels.list);return[...e,...n]}function M_({nodeMap:t,nodes:e,edges:n}){e.forEach(r=>{r._node_type!=="view-root"||r._view_type!==E.Tabs||(r.sourcePosition=be.Position.Bottom,r.style.width=zr+Xn*2,r.style.height=kl+r._tab_view_ids.reduce((i,o)=>{const l=t[o];l.position.y=i,l.position.x=Xn;const c=l.style.height;return i+c+20},Ar))})}function A_({nodeMap:t,nodes:e,edges:n}){n.filter(r=>r.label==="Open View").forEach(r=>{const i=t[r.source],o=t[r.target];if(!i||!o||!i.parentNode)return;const l=t[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))}),e.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 z_({nodeMap:t,nodes:e,edges:n}){const r={};n.forEach(i=>{if(i.label!=="Open View")return;const o=t[i.source],l=t[i.target];if(o&&l&&o.parentNode){const c=t[o.parentNode],u=c.position.x,d=Number(y.get(l,"style.height",0)),h=Number(c.style.width);l.position.x=u+h+C_,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+Tl}})}function E_({nodeMap:t,nodes:e,edges:n}){const r=new Set,i=new Set;n.forEach(l=>{r.add(l.source),i.add(l.target)}),e.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=_l(c,zr,w_),l.position.y=0-v_-Tl})}function P_({nodeMap:t,nodes:e,edges:n}){const r={nodeMap:t,nodes:e,edges:n};return E_(r),A_(r),M_(r),z_(r),{nodes:e,edges:n}}function L_(t){const e=D_(t),n=y.keyBy(e,u=>u.id),{edges:r,edgeNodes:i}=b_(t,n),o=[...e,...i],l=y.keyBy(o,u=>u.id),c={edges:y.uniqBy(r,u=>u.id),nodes:o,nodeMap:l};return P_(c)}const sD="",Er={"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 B_(t){const e=[];return t.forEach(n=>{switch(n.schemaRef){case"builtin:op:open-link":e.push({key:n.urlTemplate,icon:Er[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})=>{e.push({key:n.schemaRef+r,icon:Er[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})=>{e.push({key:n.schemaRef+r,icon:Er[n.schemaRef],text:s.jsx(a.Group,{spacing:4,children:s.jsxs(a.Text,{children:["Clear Filter: ",i]})})})});return}}),e}const O_=f.memo(({data:t,isConnectable:e,sourcePosition:n=be.Position.Right,targetPosition:r=be.Position.Left,...i})=>{const o=f.useMemo(()=>B_(t.interactions),[t.interactions]);return s.jsxs(s.Fragment,{children:[s.jsx(be.Handle,{type:"target",position:r,isConnectable:e}),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:t.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:e})]})}),rD="",$_={interaction:O_},V_=S.observer(()=>{const t=oe(),{edges:e,nodes:n}=L_(t);return s.jsxs(be,{nodes:n,edges:e,onNodesChange:y.noop,onEdgesChange:y.noop,onConnect:y.noop,className:"interactions-viewer",fitView:!0,nodeTypes:$_,children:[s.jsx(be.MiniMap,{}),s.jsx(be.Controls,{}),s.jsx(be.Background,{})]})}),N_=S.observer(({opened:t,close:e})=>s.jsx(a.Modal,{size:"96vw",opened:t,onClose:e,title:"Interactions",trapFocus:!0,onDragStart:n=>{n.stopPropagation()},styles:{body:{height:"calc(90vh - 54px)"},content:{transform:"none !important"}},zIndex:300,children:s.jsx(V_,{})})),q_={"> 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 F_({onClick:t,name:e,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:t,children:s.jsx(a.Text,{size:"sm",children:e})})}),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 G_=S.observer(()=>{const t=U(),e=X(),n=f.useCallback(i=>()=>e.views.setIDOfVIE(i),[e]),r=i=>{t.editor.open(["_VIEWS_",i])};return s.jsxs(a.Box,{sx:{position:"relative"},children:[e.views.options.map(i=>s.jsx(F_,{active:e.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:e.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"space-between"}},children:"Add a View"})]})}),W_=S.observer(()=>{const t=U(),e=X(),n=()=>{if(!e.queries.firstID){t.editor.open(["_QUERIES_",""]);return}t.editor.open(["_QUERIES_",e.queries.firstID])},r=()=>{if(!e.filters.firstID){t.editor.open(["_FILTERS_",""]);return}t.editor.open(["_FILTERS_",e.filters.firstID])},[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:{...q_,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(N_,{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(G_,{})}),s.jsx(a.Navbar.Section,{children:s.jsx(a.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:s.jsx(a.Button,{size:"xs",leftIcon:s.jsx(k.IconSettings,{size:20}),onClick:()=>t.editor.open([]),children:"Settings"})})})]})}),R_=S.observer(function({config:e}){return s.jsxs(s.Fragment,{children:[s.jsx(a.Checkbox,{checked:e.default_value,onChange:n=>e.setDefaultValue(n.currentTarget.checked),label:"Default Checked"}),s.jsx(rr,{label:"Description",value:e.description,onChange:e.setDescription,styles:{root:{flexGrow:1,minHeight:"400px"}}})]})}),Q_=[{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"}],Y_=S.observer(function({config:e}){return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{children:[s.jsx(a.Checkbox,{checked:e.required,onChange:n=>e.setRequired(n.currentTarget.checked),label:"Required"}),s.jsx(a.Checkbox,{checked:e.clearable,onChange:n=>e.setClearable(n.currentTarget.checked),disabled:e.max_days>0,label:"Clearable"}),s.jsx(a.Checkbox,{checked:e.allowSingleDateInRange,onChange:n=>e.setAllowSingleDateInRange(n.currentTarget.checked),label:"Allow choosing 1 day"})]}),s.jsx(a.Select,{data:Q_,label:"Display Format",value:e.inputFormat,onChange:e.setInputFormat}),s.jsx(yo,{label:"Default Value",config:e,value:e.default_value,onChange:e.setDefaultValue}),s.jsx(a.NumberInput,{label:"Max Days",description:s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Text,{children:"Set 0 to disable."}),s.jsxs(a.Group,{spacing:4,children:[s.jsx(a.Text,{children:"This feature requires"}),s.jsx(a.Text,{color:"blue",children:"Clearable"}),s.jsx(a.Text,{children:"to be checked"})]})]}),min:0,value:e.max_days,onChange:e.setMaxDays,hideControls:!0})]})}),Pr=S.observer(({value:t,onChange:e})=>{const n=U(),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"}),t&&s.jsx(a.Button,{size:"xs",leftIcon:s.jsx(k.IconArrowCurveRight,{size:16}),variant:"subtle",color:"blue",onClick:()=>l(t),children:"Open this query"})]}),data:i,value:t,onChange:e,allowDeselect:!1,clearable:!0,sx:{flexGrow:1},disabled:o,error:o?"You need to add a query in Data Settings":void 0,styles:{label:{display:"block"}}})}),K_=`
443
+ `}})).actions(t=>({setPage(e){t.page=e},resetPage(){t.page=1},setLimit(e){t.limit=e}})).actions(t=>({afterCreate(){g.addDisposer(t,W.reaction(()=>t.keywordString,t.resetPage,{fireImmediately:!1,delay:0})),g.addDisposer(t,W.reaction(()=>t.limit,t.resetPage,{fireImmediately:!1,delay:0}))}})),A1=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(t=>({get loading(){return t.state==="loading"},get empty(){return Object.keys(t.data).length===0}})),z1=g.types.compose("DataSourceModel",Bo,g.types.model({tables:g.types.optional(A1,{}),columns:g.types.optional(I1,{}),tableData:g.types.optional(M1,{}),indexes:g.types.optional(D1,{}),table_schema:g.types.optional(g.types.string,""),table_name:g.types.optional(g.types.string,"")})).views(t=>({get sqlDataSourceType(){return t.type},get reloadConditionString(){const{type:e,table_name:n,table_schema:r}=t;return`${e};${n};${r}`}})).volatile(()=>({controllers:{tables:new AbortController,columns:new AbortController,indexes:new AbortController,tableData:new AbortController}})).actions(t=>({setKeywords(e,n){t.table_schema=e,t.table_name=n}})).actions(t=>({initKeywords(){if(t.tables.empty)return;const e=Object.keys(t.tables.data)[0],n=t.tables.data[e][0].table_name;t.setKeywords(e,n)}})).actions(t=>{const e=g.flow(function*(){var n;(n=t.controllers.tables)==null||n.abort(),t.controllers.tables=new AbortController,t.tables.state="loading";try{const r=yield*g.toGenerator(Ke.structure(t.controllers.tables.signal)({query_type:"TABLES",type:t.sqlDataSourceType,key:t.key,table_schema:"",table_name:""},{params:{query_type:"TABLES"}}));t.tables.data=y.groupBy(r,"table_schema"),t.tables.state="idle",t.tables.error=null,t.initKeywords()}catch(r){if(!tt.isCancel(r)){t.tables.data={};const i=y.get(r,"message","unkown error");t.tables.error=y.get(r,"response.data.detail.message",i),t.tables.state="error"}}});return{loadTables:e,loadTablesIfEmpty(){t.tables.empty&&e()},loadColumns:g.flow(function*(){var n;(n=t.controllers.columns)==null||n.abort(),t.controllers.columns=new AbortController,t.columns.state="loading";try{t.columns.data=yield*g.toGenerator(Ke.structure(t.controllers.columns.signal)({query_type:"COLUMNS",type:t.sqlDataSourceType,key:t.key,table_schema:t.table_schema,table_name:t.table_name},{params:{query_type:"COLUMNS"}})),t.columns.state="idle",t.columns.error=null}catch(r){if(tt.isCancel(r))t.columns.state="idle",t.columns.error=null;else{t.columns.data=[];const i=y.get(r,"message","unkown error");t.columns.error=y.get(r,"response.data.detail.message",i),t.columns.state="error"}}}),loadIndexes:g.flow(function*(){var n;(n=t.controllers.indexes)==null||n.abort(),t.controllers.indexes=new AbortController,t.indexes.state="loading";try{t.indexes.data=yield*g.toGenerator(Ke.structure(t.controllers.indexes.signal)({query_type:"INDEXES",type:t.sqlDataSourceType,key:t.key,table_schema:t.table_schema,table_name:t.table_name},{params:{query_type:"INDEXES"}})),t.indexes.state="idle",t.indexes.error=null}catch(r){if(tt.isCancel(r))t.indexes.state="idle",t.indexes.error=null;else{t.indexes.data=[];const i=y.get(r,"message","unkown error");t.indexes.error=y.get(r,"response.data.detail.message",i),t.indexes.state="error"}}}),loadTableData:g.flow(function*(){var r;(r=t.controllers.tableData)==null||r.abort(),t.controllers.tableData=new AbortController;const n=t.tableData;n.state="loading";try{n.data=yield*g.toGenerator(Ke.structure(t.controllers.tableData.signal)({query_type:"DATA",type:t.sqlDataSourceType,key:t.key,table_schema:t.table_schema,table_name:t.table_name,limit:n.limit,offset:n.offset},{params:{query_type:"DATA"}}));const[{total:i}]=yield*g.toGenerator(Ke.structure(t.controllers.tableData.signal)({query_type:"COUNT",type:t.sqlDataSourceType,key:t.key,table_schema:t.table_schema,table_name:t.table_name},{params:{query_type:"COUNT"}}));n.total=Number(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(t=>({afterCreate(){g.addDisposer(t,W.reaction(()=>t.reloadConditionString,t.loadColumns,{fireImmediately:!1,delay:500}))}})).actions(t=>({afterCreate(){g.addDisposer(t,W.reaction(()=>t.reloadConditionString,t.loadIndexes,{fireImmediately:!1,delay:500})),g.addDisposer(t,W.reaction(()=>`${t.reloadConditionString};limit:${t.tableData.limit};offset:${t.tableData.offset}`,t.loadTableData,{fireImmediately:!1,delay:0}))}})),E1=g.types.model("DataSourcesModel",{list:g.types.optional(g.types.array(z1),[])}).views(t=>({find({type:e,key:n}){return t.list.find(r=>r.key===n&&r.type===e)},get options(){return t.list.map(e=>({value:e.key,label:e.key}))}})).actions(t=>({replace(e){t.list.length=0,t.list.push(...e)}}));function St(t){return{label:t,value:t,_type:"ACTION",_action_type:t,Icon:null,children:null}}function P1(t){switch(t._type){case"GROUP":case"ACTION":return null;case"query_variables":return["_QUERY_VARS_"];case"mock_context":return["_MOCK_CONTEXT_"];case"filter":return["_FILTERS_",t.value];case"sql_snippet":return["_SQL_SNIPPETS_",t.value];case"query":return["_QUERIES_",t.value];case"view":return["_VIEWS_",t.value];case"panel":return t.parentID?["_VIEWS_",t.parentID,"_PANELS_",t.value]:(console.error("[getPathFromOption] parentID is required"),null)}}const L1=g.types.model("EditorModel",{path:g.types.optional(g.types.frozen(),[]),settings_open:g.types.optional(g.types.boolean,!1)}).views(t=>({get navOptions(){const{content:e}=g.getRoot(t),{filters:n,views:r,sqlSnippets:i,queries:o}=e;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(e,n){return e.length===0?!1:e[e.length-1]===n.value},isOptionOpened(e){const{path:n}=t;return n.length===0||!e.children||e.children.length===0?!1:n.includes(e.value)}})).actions(t=>({setPath(e){t.path=e},setSettingsOpen(e){t.settings_open=e}})).actions(t=>({open(e){t.setPath(e),t.setSettingsOpen(!0)},close(){t.setSettingsOpen(!1)},navigate(e){const n=P1(e);n&&t.setPath(n)}})),fl=Go.views(t=>({get dataFieldOptions(){return t.queryIDs.length===0?[]:t.queries.map(e=>{const n=e.data;return n.length===0?[]:Object.keys(n[0]).map(i=>({label:i,value:`${e.id}.${i}`,group:e.name}))}).flat()}})).actions(t=>({removeSelf(){g.getParent(t,2).removeByID(t.id)}})).actions(t=>({moveToView(e,n){g.getRoot(t).content.views.findByID(e).removePanelID(t.id),g.getRoot(t).content.views.findByID(n).appendPanelID(t.id),g.getRoot(t).editor.setPath(["_VIEWS_",n,"_PANELS_",t.id])}})),gl=g.types.compose("PanelsModel",Wo,g.types.model({list:g.types.optional(g.types.array(fl),[])})).views(t=>({editorOptions(e,n){const{panels:r}=t.panelsByIDs(n);r.length!==n.length&&console.warn(`Unfulfilled panels for View[${e}]`);const i=r.map(l=>({label:l.name,value:l.id,_type:"panel",parentID:e})),o="_Add_A_PANEL_";return i.push({label:o,value:o,_type:"ACTION",_action_type:o,parentID:e,Icon:null,children:null}),i}})).actions(t=>({replace(e){t.list=g.castToSnapshot(e)},append(e){t.list.push(e)},appendMultiple(e){e.length!==0&&t.list.push(...e)},remove(e){t.list.splice(e,1)},removeByID(e){const n=t.list.findIndex(r=>r.id===e);n!==-1&&t.list.splice(n,1)},removeByIDs(e){e.forEach(n=>{this.removeByID(n)})},duplicateByID(e){const n=t.list.find(i=>i.id===e);if(!n){console.error(new Error(`[duplicate panel] Can't find a panel by id[${e}]`));return}const r=new Date().getTime().toString();return t.list.push({...n.json,id:r,title:{...n.json.title},layout:{...n.layout,y:1/0,moved:!1}}),r},replaceByIndex(e,n){t.list.splice(e,1,n)}})),B1=Vo.actions(t=>({getSchema(){const e=t.json,n=[],r=[];return t.panels.forEach(o=>{const l=o.getSchema();n.push(l.panel),l.queries.length>0&&r.push(...l.queries)}),{views:[e],panels:n,definition:{queries:y.uniqBy(r,o=>o.id)}}},downloadSchema(){if(t.type===E.Tabs){console.error(new Error("Please choose a tab first"));return}const e=JSON.stringify(this.getSchema(),null,2),n=t.name;Ct(n,e)}})),ml=g.types.compose("ViewsModel",No,g.types.model({current:g.types.optional(g.types.array(B1),[]),idOfVIE:g.types.string})).views(t=>({get isVIETheFirstView(){return t.current.length===0||!t.idOfVIE?!1:t.current[0].id===t.idOfVIE},get VIE(){return t.current.find(({id:e})=>e===t.idOfVIE)},get options(){return t.current.map(e=>({label:e.name,value:e.id,type:e.type}))},get editorOptions(){const e=g.getRoot(t).content.panels;return t.current.map(n=>({label:n.name,value:n.id,_type:"view",children:e.editorOptions(n.id,n.panelIDs)}))}})).actions(t=>({setIDOfVIE(e){t.idOfVIE=e,t.visibleViewIDs.length=0,t.visibleViewIDs.push(e)},replace(e){t.current.replace(e)},addANewView(e,n,r,i){t.current.push({id:e,name:n,type:r,config:i,panelIDs:[]})},append(e){t.current.push(e)},appendMultiple(e){e.length!==0&&t.current.push(...e)},remove(e){t.current.splice(e,1)},removeByID(e){const n=t.current.findIndex(o=>o.id===e);if(n===-1)return;const r=t.current[n];g.getRoot(t).content.panels.removeByIDs(r.panelIDs),t.current.splice(n,1)},replaceByIndex(e,n){t.current.splice(e,1,n)},addARandomNewView(){const e=new Date().getTime().toString();this.addANewView(e,E.Division,E.Division,{_name:E.Division}),this.setIDOfVIE(e)},removeVIE(){t.current.length!==1&&(this.removeByID(t.idOfVIE),this.setIDOfVIE(t.current[0].id))}}));function Dr(t){const e=t.length>0?[t[0].id]:[],n=t.length>0?t[0].id:"";return{current:t.map(i=>{const{_name:o=i.type}=i.config;return{...i,config:{...i.config,_name:o},panelIDs:i.panelIDs}}),visibleViewIDs:e,idOfVIE:n}}const O1=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:pl,queries:hl,sqlSnippets:xl,views:ml,panels:gl,mock_context:wo,origin:g.types.maybe(g.types.frozen())}).views(t=>({get json(){return{id:t.id,name:t.name,create_time:t.create_time,update_time:t.update_time,dashboard_id:t.dashboard_id,content:{views:t.views.json,panels:t.panels.json,filters:t.filters.json,version:t.version,definition:{queries:t.queries.json,sqlSnippets:t.sqlSnippets.json,mock_context:t.mock_context.current}}}},get contentJSON(){return this.json.content},get filtersChanged(){const e="filters.current";return!y.isEqual(g.getSnapshot(y.get(t,e)),y.get(t.origin,e))},get queriesChanged(){const e="queries.current",n=g.getSnapshot(y.get(t,e)).map(r=>y.pick(r,["id","name","key","type","sql","run_by","react_to","pre_process","post_process"]));return!y.isEqual(n,y.get(t.origin,e))},get sqlSnippetsChanged(){const e="sqlSnippets.current";return!y.isEqual(g.getSnapshot(y.get(t,e)),y.get(t.origin,e))},get viewsChanged(){const e="views.current";return!y.isEqual(t.views.json,y.get(t.origin,e))},get panelsChanged(){const e="panels.list";return!y.isEqual(g.getSnapshot(y.get(t,e)),y.get(t.origin,e))},get mockContextChanged(){const e="mock_context.current";return!y.isEqual(y.get(t,e),y.get(t.origin,e))},get payloadForSQL(){const e=g.getParent(t).context.current,n=g.getParent(t).globalSQLSnippets,r={context:{...t.mock_context.current,...e},filters:t.filters.values};return{...r,sql_snippets:Wn(t.sqlSnippets.current,"key","value",r),global_sql_snippets:Wn(n.list,"id","content",r)}},get payloadForViz(){const e=g.getParent(t).context.current;return{context:{...t.mock_context.current,...e},filters:t.filters.values}},get dashboardState(){return us(this.payloadForSQL)},getAdditionalQueryInfo(e){return{content_id:t.id,query_id:e,params:this.dashboardState}},get changed(){return this.filtersChanged||this.queriesChanged||this.sqlSnippetsChanged||this.viewsChanged||this.panelsChanged||this.mockContextChanged},get data(){return t.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(e){const n=t.queries.findByID(e);return n?{data:n.data,len:n.data.length,state:n.state,error:n.error}:{data:[],len:0,state:"idle",error:void 0}}})).views(t=>({get queriesUsage(){const e=t.panels.idMap,n=[];t.views.current.forEach(i=>{i.panelIDs.forEach(o=>{const l=e.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=t.views.idMap;return t.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 t.queries.current.length>Object.keys(this.queriesUsage).length},findQueryUsage(e){return this.queriesUsage[e]??[]},get sqlSnippetsUsage(){const e=[];return t.queries.current.forEach(n=>{if(!n.typedAsSQL)return;y.uniq(n.sql.match(Gn.sqlSnippet)).forEach(i=>{e.push({queryID:n.id,sqlSnippetKey:i,queryName:n.name})})}),y.groupBy(e,"sqlSnippetKey")},get hasUnusedSQLSnippets(){return t.sqlSnippets.current.length>Object.keys(this.sqlSnippetsUsage).length},findSQLSnippetUsage(e){return this.sqlSnippetsUsage[e]??[]}})).actions(t=>({removeUnusedQueries(){const e=new Set(Object.keys(t.queriesUsage)),n=t.queries.current.filter(r=>!e.has(r.id)).map(r=>r.id);t.queries.removeQueries(n)},removeUnusedSQLSnippets(){const e=new Set(Object.keys(t.sqlSnippetsUsage)),n=t.sqlSnippets.current.filter(r=>!e.has(r.key)).map(r=>r.key);t.sqlSnippets.removeByKeys(n)},duplicatePanelByID(e,n){var i;const r=t.panels.duplicateByID(e);r&&((i=t.views.findByID(n))==null||i.appendPanelID(r))},removePanelByID(e,n){var r;t.panels.removeByID(e),(r=t.views.findByID(n))==null||r.removePanelID(e)},addANewPanel(e){var r;const n=is.v4();t.panels.append(zS(n)),(r=t.views.findByID(e))==null||r.appendPanelID(n)},applyJSONSchema(e){var p;const{views:n,panels:r,filters:i,definition:o={}}=e,{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(t.panels.appendMultiple(h),!Array.isArray(n)||n.length===0){const x=h.map(m=>m.id);(p=t.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}});t.views.appendMultiple(h)}Array.isArray(i)&&t.filters.appendMultiple(i),Array.isArray(l)&&t.queries.appendMultiple(l),Array.isArray(c)&&t.sqlSnippets.appendMultiple(c),u&&Object.keys(u).length>0&&t.mock_context.defaults(u)}})).actions(t=>({reset(){g.applySnapshot(t.filters.current,t.origin.filters.current),g.applySnapshot(t.queries.current,t.origin.queries.current),g.applySnapshot(t.sqlSnippets.current,t.origin.sqlSnippets.current),g.applySnapshot(t.views.current,t.origin.views.current),g.applySnapshot(t.panels.list,t.origin.panels.list),t.mock_context.current=t.origin.mock_context.current},resetFilters(){g.applySnapshot(t.filters.current,t.origin.filters.current)},updateCurrent(e){const{id:n,name:r,content:i}=e;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;t.id=n,t.name=r,t.version=o,g.applySnapshot(t.filters.current,l),g.applySnapshot(t.views.current,Dr(c).current),g.applySnapshot(t.panels.list,u),g.applySnapshot(t.queries.current,d),g.applySnapshot(t.sqlSnippets.current,p),t.mock_context.current=h}})),Mr=g.types.snapshotProcessor(O1,{preProcessor(t){return{...t,origin:t}},postProcessor(t){delete t.origin;const e=g.castToSnapshot(t.queries.current.map(n=>y.pick(n,["id","key","type","sql"])));return y.defaults({},{queries:{current:e}},t)}});function $1(t,e){e.filters&&g.applySnapshot(t.filters.current,e.filters)}function yl({id:t,name:e,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 Mr.create({id:t,name:e,dashboard_id:n,create_time:r,update_time:i,version:l,filters:Uo(c),queries:{current:p},sqlSnippets:{current:h},mock_context:Co(x),views:Dr(u),panels:{list:d}})}const bl=g.types.model({id:g.types.identifier,name:g.types.string,group:g.types.string,content:Mr,content_id:g.types.string,datasources:E1,globalSQLSnippets:Oo,context:Sr,editor:L1}).views(t=>({get json(){return{id:t.id,name:t.name,group:t.group,content_id:t.content_id}}})).actions(t=>({updateCurrentContent(e){t.content.updateCurrent(e)},updateCurrent(e,n){const{id:r,name:i,group:o,content_id:l}=e;t.id=r,t.name=i,t.group=o,t.content_id=l,this.updateCurrentContent(n)}}));function jl({id:t,name:e,group:n,content_id:r},i,o,l,c){return bl.create({id:t,name:e,group:n,content_id:r,content:yl(i),datasources:{list:o},globalSQLSnippets:{list:l},context:$o(c),editor:{}})}function vl(t,e){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}t.views.appendToVisibles(i),e&&t.views.setIDOfVIE(i)};return window.addEventListener("open-view",n),()=>{window.removeEventListener("open-view",n)}},[t,e]),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])=>{t.filters.setValueByKey(l,y.get(o,c))})};return window.addEventListener("set-filter-values",n),()=>{window.removeEventListener("set-filter-values",n)}},[t]),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(t.filters.values,l),u=n(c);console.log(`${l}: ${u}`),t.filters.setValueByKey(l,u)})};return window.addEventListener("clear-filter-values",r),()=>{window.removeEventListener("clear-filter-values",r)}},[t]),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:t.payloadForSQL.filters,context:t.payloadForSQL.context}));window.open(p,o?"_blank":"_self","noopener")};return window.addEventListener("open-link",n),()=>{window.removeEventListener("open-link",n)}},[t])}function wl(t){return f.useCallback(e=>e.provideValue(le.pluginManager,t.pluginManager).provideValue(le.vizManager,t.vizManager).provideValue(le.colorManager,t.colorManager),[])}const JI="",V1=S.observer(()=>{const t=gs(),e=X(),n=()=>{const r=JSON.stringify(e.contentJSON,null,2),i=`${t.name}__${e.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:e.queries.downloadAllData,children:"Download Data"}),s.jsx(a.Menu.Item,{icon:s.jsx(k.IconCode,{size:14}),onClick:n,children:"Download Schema"})]})]})}),N1=S.observer(({saveDashboardChanges:t})=>{const e=Me.useModals(),n=X(),r=()=>{e.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:t,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"})})]})]})}),q1=S.observer(({saveDashboardChanges:t,headerSlot:e=null})=>{const n=Zc.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(N1,{saveDashboardChanges:t})]}),s.jsxs(a.Group,{position:"right",sx:{flexGrow:1},children:[e,s.jsx(V1,{})]})]})})}),Cl={height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},F1=S.observer(()=>{var r;const t=X(),e=((r=t.views.VIE)==null?void 0:r.type)===E.Tabs,n=()=>t.addANewPanel(t.views.idOfVIE);return e?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:{...Cl,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:{...Cl,background:"rgb(231, 245, 255)"},children:"Add a Panel"})});function G1(t){if(t.target===null)throw new Error("FileReader failed with null result");if(typeof t.target.result!="string")throw new Error(`Unparsable file content of type: ${typeof t.target.result}`);let e=JSON.parse(t.target.result);return"content"in e&&(e=e.content),e}const W1=S.observer(({view:t})=>!t||t.type!==E.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"})]})),R1=[{value:"default",label:"Default"},{value:"outline",label:"Outline"},{value:"pills",label:"Pills"}],Q1=[{value:"horizontal",label:"Horizontal"},{value:"vertical",label:"Vertical"}],U1=S.observer(({view:t})=>{if(!t||t.type!==E.Tabs)return null;const e=t.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:e.variant,onChange:e.setVariant,data:R1}),s.jsx(a.Select,{label:"Orientation",value:e.orientation,onChange:e.setOrientation,data:Q1}),s.jsx(a.Switch,{label:"Grow Tabs",checked:e.grow,onChange:n=>e.setGrow(n.currentTarget.checked)})]})}),Y1=({disabled:t,value:e,onChange:n})=>{const r=i=>{i&&n(i)};return s.jsxs(a.Box,{sx:{position:"relative"},children:[t&&s.jsx(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),s.jsx(ge,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},K1=({value:t,onChange:e})=>{const[n,{setTrue:r,setFalse:i}]=$.useBoolean(),[o,l]=f.useState(t??Cr),c=x=>{l({...o,enabled:x})},u=()=>{i();const{enabled:x,func_content:m}=o,j={enabled:x,func_content:m};l(j),e(j)},d=()=>{i(),l(t)},p=x=>{l(m=>({...m,func_content:x}))},h=()=>{p(Cr.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(Y1,{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"})]})]})]})})]})},X1=S.observer(({view:t})=>{if(!t||t.type!==E.Modal)return null;const e=t.config,n=e.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(K1,{value:e.custom_modal_title,onChange:e.custom_modal_title.replace})]}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(a.TextInput,{label:"Width",value:e.width,onChange:r=>e.setWidth(r.currentTarget.value),placeholder:"600px / 50vw"}),s.jsx(a.TextInput,{label:"Height",value:e.height,onChange:r=>e.setHeight(r.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),J1=S.observer(({view:t})=>s.jsxs(s.Fragment,{children:[s.jsx(W1,{view:t}),s.jsx(X1,{view:t}),s.jsx(U1,{view:t})]})),Un={[E.Division]:"Division",[E.Modal]:"Modal",[E.Tabs]:"Tabs"},Z1=[{label:Un[E.Division],value:E.Division},{label:Un[E.Modal],value:E.Modal},{label:Un[E.Tabs],value:E.Tabs}],H1=S.observer(({view:t})=>t?s.jsxs(a.Stack,{sx:{position:"relative"},children:[s.jsx(a.TextInput,{label:"Name",value:t.name,onChange:e=>{t.setName(e.currentTarget.value)}}),s.jsx(a.Select,{label:"Type",withinPortal:!0,zIndex:320,value:t.type,onChange:t.setType,data:Z1}),s.jsx(J1,{view:t})]}):null),Yn=({headers:t,rows:e})=>s.jsxs(a.Table,{fontSize:"xs",highlightOnHover:!0,sx:{tableLayout:"fixed",fontFamily:"monospace"},children:[s.jsx("thead",{children:t}),s.jsx("tbody",{children:e})]}),e_=({content:t})=>{const e=t.views;return!Array.isArray(e)||e.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:e.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))})]})},t_=({content:t})=>{const e=t.filters;return!Array.isArray(e)||e.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:e.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))})]})},n_=({content:t})=>{const e=t.panels;return!Array.isArray(e)||e.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:e.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))})]})},s_=({content:t})=>{var n;const e=(n=t.definition)==null?void 0:n.queries;return!Array.isArray(e)||e.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:e.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))})]})},r_=({content:t})=>{var n;const e=(n=t.definition)==null?void 0:n.sqlSnippets;return!Array.isArray(e)||e.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:e.map(r=>s.jsx(a.List.Item,{children:r.key},r.key))})]})},i_=({content:t})=>{var n;const e=Object.keys(((n=t.definition)==null?void 0:n.mock_context)??{});return e.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:e.map(r=>s.jsx(a.List.Item,{children:r},r))})]})},a_=({content:t})=>t?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(e_,{content:t}),s.jsx(t_,{content:t}),s.jsx(n_,{content:t}),s.jsx(s_,{content:t}),s.jsx(r_,{content:t}),s.jsx(i_,{content:t})]})]}):null,o_=S.observer(({onSuccess:t,stretchModal:e,shrinkModal:n})=>{var C;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"}),t()}catch(A){console.error(A),xt.showNotification({title:"Failed",message:A.message,color:"red"})}},[h,x]=f.useState(null);f.useEffect(()=>{if(!h)return;const T=new FileReader;T.readAsText(h,"UTF-8"),T.onload=A=>{try{const L=G1(A);l("content",L),d("content")}catch(L){console.error(L),u("content",{type:"custom",message:L.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?e():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:(C=o==null?void 0:o.content)==null?void 0:C.message,sx:{maxWidth:500}}),s.jsx(a_,{content:m}),s.jsx(a.Group,{position:"right",my:"md",children:s.jsx(a.Button,{type:"submit",color:"green",disabled:j,children:"Confirm"})})]})})}),Sl={height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},l_=S.observer(()=>{var u;const[t,{open:e,close:n}]=pe.useDisclosure(!1),[r,{setTrue:i,setFalse:o}]=$.useBoolean(!1),c=((u=K().content.views.VIE)==null?void 0:u.type)===E.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:{...Sl,transform:"none !important"},children:"Import..."})}):s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"subtle",color:"blue",radius:0,size:"xs",disabled:c||t,onClick:e,leftIcon:s.jsx(k.IconFileImport,{size:16}),sx:{...Sl},children:"Import..."}),s.jsx(a.Modal,{opened:t,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(o_,{onSuccess:n,stretchModal:i,shrinkModal:o})})]})}),_l={height:"30px",borderRight:"none",borderTop:"none",borderLeft:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},c_=S.observer(()=>{var r;const t=X(),e=((r=t.views.VIE)==null?void 0:r.type)===E.Tabs,n=()=>{var i;return(i=t.views.VIE)==null?void 0:i.downloadSchema()};return e?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:{..._l,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:{..._l},children:"Download this View"})}),u_={position:"fixed",top:60,left:0,right:0,height:30,zIndex:299,borderBottom:"1px solid #e9ecef",background:"rgba(233,236,239, 0.15)"},d_=S.observer(()=>s.jsx(a.Box,{sx:u_,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(F1,{}),s.jsx(l_,{})]}),s.jsx(a.Box,{}),s.jsx(a.Group,{position:"right",spacing:0,children:s.jsx(c_,{})})]})})),p_=S.observer(t=>s.jsxs(s.Fragment,{children:[s.jsx(q1,{...t}),s.jsx(d_,{})]})),ZI="";function h_(t,e,n){const r=[];return t.filter(i=>"__INTERACTIONS"in i.viz.conf).forEach((i,o)=>{const l=e[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 C=j.urlTemplate.substring(0,100);j.urlTemplate.length>=20&&(C+="..."),l.type="interaction",l.data.interactions.push({schemaRef:x,urlTemplate:j.urlTemplate,shortURLTemplate:C});return;case"builtin:op:open_view":r.push({id:`OPERATION--${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 x_(t,e){const n=t.filters.keyLabelMap;return{edges:h_(t.panels.list,e,n),edgeNodes:[]}}function kl(t,e,n){return t*e+t*n}function f_(t,e,n){return t*e+(t-1)*n}const Kn=25,Ar=40,Tl=25,zr=350,g_=150,m_=150,Il=150,Dl=300,Xn=40,Ml=25,y_=300;function b_(t,e){const n=y.keyBy(e,i=>i.id),r=[];return t.current.forEach((i,o)=>{i.panelIDs.forEach((l,c)=>{const u=kl(c,Xn,Ml)+Ar,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:Dl,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:Dl,height:Xn}})})}),r}const j_={[E.Division]:"Div",[E.Modal]:"Modal",[E.Tabs]:"Tabs"},v_=dl;function w_(t){return t.current.map((n,r)=>{const i=f_(n.panelIDs.length,Xn,Ml)+Ar+Tl;let o=[];return n.type===E.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:`${j_[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:zr,height:i}}})}function C_(t){const e=y.keyBy(t,n=>n.id);t.forEach(n=>{n._node_type!=="view-root"||n._view_type!==E.Tabs||n._tab_view_ids.forEach(r=>{e[r].parentNode=n.id})})}function S_(t){const e=w_(t.views);C_(e);const n=b_(t.views,t.panels.list);return[...e,...n]}function __({nodeMap:t,nodes:e,edges:n}){e.forEach(r=>{r._node_type!=="view-root"||r._view_type!==E.Tabs||(r.sourcePosition=be.Position.Bottom,r.style.width=zr+Kn*2,r.style.height=Tl+r._tab_view_ids.reduce((i,o)=>{const l=t[o];l.position.y=i,l.position.x=Kn;const c=l.style.height;return i+c+20},Ar))})}function k_({nodeMap:t,nodes:e,edges:n}){n.filter(r=>r.label==="Open View").forEach(r=>{const i=t[r.source],o=t[r.target];if(!i||!o||!i.parentNode)return;const l=t[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))}),e.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 T_({nodeMap:t,nodes:e,edges:n}){const r={};n.forEach(i=>{if(i.label!=="Open View")return;const o=t[i.source],l=t[i.target];if(o&&l&&o.parentNode){const c=t[o.parentNode],u=c.position.x,d=Number(y.get(l,"style.height",0)),p=Number(c.style.width);l.position.x=u+p+y_,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+Il}})}function I_({nodeMap:t,nodes:e,edges:n}){const r=new Set,i=new Set;n.forEach(l=>{r.add(l.source),i.add(l.target)}),e.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=kl(c,zr,m_),l.position.y=0-g_-Il})}function D_({nodeMap:t,nodes:e,edges:n}){const r={nodeMap:t,nodes:e,edges:n};return I_(r),k_(r),__(r),T_(r),{nodes:e,edges:n}}function M_(t){const e=S_(t),n=y.keyBy(e,u=>u.id),{edges:r,edgeNodes:i}=x_(t,n),o=[...e,...i],l=y.keyBy(o,u=>u.id),c={edges:y.uniqBy(r,u=>u.id),nodes:o,nodeMap:l};return D_(c)}const HI="",Er={"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 A_(t){const e=[];return t.forEach(n=>{switch(n.schemaRef){case"builtin:op:open-link":e.push({key:n.urlTemplate,icon:Er[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})=>{e.push({key:n.schemaRef+r,icon:Er[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})=>{e.push({key:n.schemaRef+r,icon:Er[n.schemaRef],text:s.jsx(a.Group,{spacing:4,children:s.jsxs(a.Text,{children:["Clear Filter: ",i]})})})});return}}),e}const z_=f.memo(({data:t,isConnectable:e,sourcePosition:n=be.Position.Right,targetPosition:r=be.Position.Left,...i})=>{const o=f.useMemo(()=>A_(t.interactions),[t.interactions]);return s.jsxs(s.Fragment,{children:[s.jsx(be.Handle,{type:"target",position:r,isConnectable:e}),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:t.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:e})]})}),eD="",E_={interaction:z_},P_=S.observer(()=>{const t=oe(),{edges:e,nodes:n}=M_(t);return s.jsxs(be,{nodes:n,edges:e,onNodesChange:y.noop,onEdgesChange:y.noop,onConnect:y.noop,className:"interactions-viewer",fitView:!0,nodeTypes:E_,children:[s.jsx(be.MiniMap,{}),s.jsx(be.Controls,{}),s.jsx(be.Background,{})]})}),L_=S.observer(({opened:t,close:e})=>s.jsx(a.Modal,{size:"96vw",opened:t,onClose:e,title:"Interactions",trapFocus:!0,onDragStart:n=>{n.stopPropagation()},styles:{body:{height:"calc(90vh - 54px)"},content:{transform:"none !important"}},zIndex:300,children:s.jsx(P_,{})})),B_={"> 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 O_({onClick:t,name:e,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:t,children:s.jsx(a.Text,{size:"sm",children:e})})}),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 $_=S.observer(()=>{const t=K(),e=X(),n=f.useCallback(i=>()=>e.views.setIDOfVIE(i),[e]),r=i=>{t.editor.open(["_VIEWS_",i])};return s.jsxs(a.Box,{sx:{position:"relative"},children:[e.views.options.map(i=>s.jsx(O_,{active:e.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:e.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"space-between"}},children:"Add a View"})]})}),V_=S.observer(()=>{const t=K(),e=X(),n=()=>{if(!e.queries.firstID){t.editor.open(["_QUERIES_",""]);return}t.editor.open(["_QUERIES_",e.queries.firstID])},r=()=>{if(!e.filters.firstID){t.editor.open(["_FILTERS_",""]);return}t.editor.open(["_FILTERS_",e.filters.firstID])},[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:{...B_,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(L_,{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($_,{})}),s.jsx(a.Navbar.Section,{children:s.jsx(a.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:s.jsx(a.Button,{size:"xs",leftIcon:s.jsx(k.IconSettings,{size:20}),onClick:()=>t.editor.open([]),children:"Settings"})})})]})}),N_=S.observer(function({config:e}){return s.jsxs(s.Fragment,{children:[s.jsx(a.Checkbox,{checked:e.default_value,onChange:n=>e.setDefaultValue(n.currentTarget.checked),label:"Default Checked"}),s.jsx(rr,{label:"Description",value:e.description,onChange:e.setDescription,styles:{root:{flexGrow:1,minHeight:"400px"}}})]})}),q_=[{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"}],F_=S.observer(function({config:e}){return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{children:[s.jsx(a.Checkbox,{checked:e.required,onChange:n=>e.setRequired(n.currentTarget.checked),label:"Required"}),s.jsx(a.Checkbox,{checked:e.clearable,onChange:n=>e.setClearable(n.currentTarget.checked),disabled:e.max_days>0,label:"Clearable"}),s.jsx(a.Checkbox,{checked:e.allowSingleDateInRange,onChange:n=>e.setAllowSingleDateInRange(n.currentTarget.checked),label:"Allow choosing 1 day"})]}),s.jsx(a.Select,{data:q_,label:"Display Format",value:e.inputFormat,onChange:e.setInputFormat}),s.jsx(bo,{label:"Default Value",config:e,value:e.default_value,onChange:e.setDefaultValue}),s.jsx(a.NumberInput,{label:"Max Days",description:s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Text,{children:"Set 0 to disable."}),s.jsxs(a.Group,{spacing:4,children:[s.jsx(a.Text,{children:"This feature requires"}),s.jsx(a.Text,{color:"blue",children:"Clearable"}),s.jsx(a.Text,{children:"to be checked"})]})]}),min:0,value:e.max_days,onChange:e.setMaxDays,hideControls:!0})]})}),Pr=S.observer(({value:t,onChange:e})=>{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"}),t&&s.jsx(a.Button,{size:"xs",leftIcon:s.jsx(k.IconArrowCurveRight,{size:16}),variant:"subtle",color:"blue",onClick:()=>l(t),children:"Open this query"})]}),data:i,value:t,onChange:e,allowDeselect:!1,clearable:!0,sx:{flexGrow:1},disabled:o,error:o?"You need to add a query in Data Settings":void 0,styles:{label:{display:"block"}}})}),G_=`
444
444
  // row
445
445
  {
446
446
  label: string;
447
447
  value: string;
448
448
  description?: string; // optional
449
449
  }
450
- `,Ml=()=>{const[t,e]=f.useState(!1);return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"subtle",compact:!0,onClick:()=>e(n=>!n),children:t?"Close":"Click to see expected data structure"}),s.jsx(a.Collapse,{in:t,children:s.jsx(ft.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:K_})})]})},U_=S.observer(function({config:e}){const n=()=>{e.addStaticOption({label:"",value:""})},r=e.static_options,i=[...r];return s.jsxs(s.Fragment,{children:[s.jsx(a.Checkbox,{checked:e.required,onChange:o=>e.setRequired(o.currentTarget.checked),label:"Required"}),s.jsx(a.TextInput,{label:"Width",description:"At least 160px",value:e.min_width,onChange:o=>e.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:[e.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:[...e.default_value],onChange:e.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:e.static_options[l].label,onChange:c=>{e.static_options[l].setLabel(c.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(a.TextInput,{label:"Value",required:!0,value:e.static_options[l].value,onChange:c=>{e.static_options[l].setValue(c.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(a.ActionIcon,{color:"red",variant:"subtle",onClick:()=>e.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:e.default_selection_count,onChange:e.setDefaultSelectionCount,label:"Select first N options by default"}),s.jsx(Pr,{value:e.options_query_id,onChange:e.setOptionsQueryID}),s.jsx(Ml,{})]})}),X_=S.observer(function({config:e}){const n=()=>{e.addStaticOption({label:"",value:""})},r=e.static_options,i=[{label:"No default selection",value:""},...r];return s.jsxs(s.Fragment,{children:[s.jsx(a.Checkbox,{checked:e.required,onChange:o=>e.setRequired(o.currentTarget.checked),label:"Required"}),s.jsx(a.TextInput,{label:"Width",value:e.width,onChange:o=>e.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:[e.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:e.default_value,onChange:e.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:e.static_options[l].label,onChange:c=>{e.static_options[l].setLabel(c.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(a.TextInput,{label:"Value",required:!0,value:e.static_options[l].value,onChange:c=>{e.static_options[l].setValue(c.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(a.ActionIcon,{color:"red",variant:"subtle",onClick:()=>e.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:e.default_selection_count===1,onChange:o=>e.setDefaultSelectionCount(o.currentTarget.checked?1:0),label:"Select the first option by default"}),s.jsx(Pr,{value:e.options_query_id,onChange:e.setOptionsQueryID}),s.jsx(Ml,{})]})}),J_=S.observer(function({config:e}){return s.jsxs(s.Fragment,{children:[s.jsx(a.TextInput,{label:"Default Value",value:e.default_value,onChange:n=>{e.setDefaultValue(n.currentTarget.value)}}),s.jsx(a.Checkbox,{checked:e.required,onChange:n=>e.setRequired(n.currentTarget.checked),label:"Required"})]})}),Z_=`
450
+ `,Al=()=>{const[t,e]=f.useState(!1);return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"subtle",compact:!0,onClick:()=>e(n=>!n),children:t?"Close":"Click to see expected data structure"}),s.jsx(a.Collapse,{in:t,children:s.jsx(ct.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:G_})})]})},W_=S.observer(function({config:e}){const n=()=>{e.addStaticOption({label:"",value:""})},r=e.static_options,i=[...r];return s.jsxs(s.Fragment,{children:[s.jsx(a.Checkbox,{checked:e.required,onChange:o=>e.setRequired(o.currentTarget.checked),label:"Required"}),s.jsx(a.TextInput,{label:"Width",description:"At least 160px",value:e.min_width,onChange:o=>e.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:[e.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:[...e.default_value],onChange:e.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:e.static_options[l].label,onChange:c=>{e.static_options[l].setLabel(c.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(a.TextInput,{label:"Value",required:!0,value:e.static_options[l].value,onChange:c=>{e.static_options[l].setValue(c.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(a.ActionIcon,{color:"red",variant:"subtle",onClick:()=>e.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:e.default_selection_count,onChange:e.setDefaultSelectionCount,label:"Select first N options by default"}),s.jsx(Pr,{value:e.options_query_id,onChange:e.setOptionsQueryID}),s.jsx(Al,{})]})}),R_=S.observer(function({config:e}){const n=()=>{e.addStaticOption({label:"",value:""})},r=e.static_options,i=[{label:"No default selection",value:""},...r];return s.jsxs(s.Fragment,{children:[s.jsx(a.Checkbox,{checked:e.required,onChange:o=>e.setRequired(o.currentTarget.checked),label:"Required"}),s.jsx(a.TextInput,{label:"Width",value:e.width,onChange:o=>e.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:[e.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:e.default_value,onChange:e.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:e.static_options[l].label,onChange:c=>{e.static_options[l].setLabel(c.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(a.TextInput,{label:"Value",required:!0,value:e.static_options[l].value,onChange:c=>{e.static_options[l].setValue(c.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(a.ActionIcon,{color:"red",variant:"subtle",onClick:()=>e.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:e.default_selection_count===1,onChange:o=>e.setDefaultSelectionCount(o.currentTarget.checked?1:0),label:"Select the first option by default"}),s.jsx(Pr,{value:e.options_query_id,onChange:e.setOptionsQueryID}),s.jsx(Al,{})]})}),Q_=S.observer(function({config:e}){return s.jsxs(s.Fragment,{children:[s.jsx(a.TextInput,{label:"Default Value",value:e.default_value,onChange:n=>{e.setDefaultValue(n.currentTarget.value)}}),s.jsx(a.Checkbox,{checked:e.required,onChange:n=>e.setRequired(n.currentTarget.checked),label:"Required"})]})}),U_=`
451
451
  // row
452
452
  {
453
453
  label: string;
@@ -455,7 +455,7 @@ Check the top-level render call using <`+M+">.")}return I}}function oc(v,I){{if(
455
455
  parent_value: string;
456
456
  description?: string;
457
457
  }
458
- `,H_=()=>{const[t,e]=f.useState(!1);return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"subtle",compact:!0,onClick:()=>e(n=>!n),children:t?"Close":"Click to see expected data structure"}),s.jsx(a.Collapse,{in:t,children:s.jsx(ft.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:Z_})})]})},ek=S.observer(function({config:e}){return s.jsxs(s.Fragment,{children:[s.jsx(a.Checkbox,{checked:e.required,onChange:n=>e.setRequired(n.currentTarget.checked),label:"Required"}),s.jsx(a.TextInput,{label:"Min-width",value:e.min_width,onChange:n=>e.setMinWidth(n.currentTarget.value),placeholder:"200px"}),s.jsx(a.Divider,{label:"Fetch options from database",labelPosition:"center"}),s.jsx(a.Checkbox,{checked:e.treeCheckStrictly,onChange:n=>e.setTreeCheckStrictly(n.currentTarget.checked),label:"Parent and children nodes are not associated"}),s.jsx(a.NumberInput,{value:e.default_selection_count,onChange:e.setDefaultSelectionCount,label:"Select first N options by default"}),s.jsx(Pr,{value:e.options_query_id,onChange:e.setOptionsQueryID}),s.jsx(H_,{})]})}),tk=S.observer(function({filter:e}){return s.jsxs(a.Box,{sx:{maxWidth:"480px"},children:[s.jsx(a.Text,{pt:"0",pb:"md",color:"gray",children:"Config"}),s.jsx(ft.Prism,{mt:22,language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(e,null,4)})]})}),nk={select:X_,"multi-select":U_,"tree-select":ek,"text-input":J_,checkbox:R_,"date-range":Y_},_t={select:"Select","multi-select":"Multi Select","tree-select":"Tree Select","text-input":"Text Input",checkbox:"Checkbox","date-range":"Date Range"},sk=[{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"}],rk=S.observer(function({filter:e}){const n=X(),r=f.useMemo(()=>nk[e.type],[e.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:e.order,onChange:e.setOrder,hideControls:!0,sx:{flexGrow:"1 !important"}}),e.auto_submit_supported&&s.jsx(a.Checkbox,{label:"Submit automatically",checked:e.auto_submit,onChange:i=>e.setAutoSubmit(i.currentTarget.checked),mt:22})]}),s.jsx(a.MultiSelect,{label:"Visible in...",data:n.views.options,value:[...e.visibleInViewsIDs],onChange:e.setVisibleInViewsIDs}),s.jsx(a.TextInput,{label:"Key",placeholder:"A unique key to refer",required:!0,value:e.key,onChange:i=>{e.setKey(i.currentTarget.value)}}),s.jsx(a.TextInput,{label:"Label",placeholder:"Label for this field",required:!0,value:e.label,onChange:i=>{e.setLabel(i.currentTarget.value)}}),s.jsx(a.Select,{label:"Widget",data:sk,required:!0,value:e.type,onChange:e.setType}),s.jsx(r,{config:e.config})]})]}),s.jsx(tk,{filter:e})]})}),ik=S.observer(({id:t})=>{const e=Me.useModals(),n=U(),r=X();if(t==="")return null;const i=r.filters.findByID(t);if(!i)return s.jsxs(a.Text,{size:14,children:["Filter by ID[",t,"] is not found"]});const o=()=>{n.editor.setPath(["_FILTERS_",""])},l=()=>{e.openConfirmModal({title:"Delete this filter?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.filters.removeByID(t),o()},confirmProps:{color:"red"},zIndex:320})};return 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(rk,{filter:i})})]})}),ak=S.observer(()=>{const[t,e]=f.useState([]),n=U(),r=u=>{n.editor.setPath(["_FILTERS_",u])},i=()=>{n.content.filters.downloadSchema(t)},o=f.useMemo(()=>n.content.filters.sortedList.map(u=>u.id),[n.content.filters.sortedList]),l=()=>{e(o)},c=()=>{e([])};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:t.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:t,onChange:e,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))})]})})})]})}),ok=S.observer(()=>{const t=X(),[e,n]=f.useState(()=>JSON.stringify(t.mock_context.current,null,4)),r=()=>{try{t.mock_context.replace(JSON.parse(e))}catch(o){ht.showNotification({title:"Failed",message:o.message,color:"red"})}},i=f.useMemo(()=>{try{return JSON.stringify(JSON.parse(e))!==JSON.stringify(t.mock_context.current)}catch{return!1}},[e,t.mock_context.current]);return s.jsxs(a.Stack,{sx:{border:"1px solid #eee",borderLeft:"none",borderRight:"none",flexGrow:1,maxWidth:"unset"},children:[s.jsx(a.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:s.jsx(a.Text,{weight:500,children:"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:e,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})})]})]})}),lk=S.observer(()=>{const{panel:t}=Be();return s.jsx(rr,{label:"Description",value:t.description,onChange:t.setDescription,styles:{root:{flexGrow:1}}})}),ck=S.observer(()=>{const{panel:t}=Be(),{style:e}=t;return s.jsxs(s.Fragment,{children:[s.jsx(a.Divider,{mb:-10,label:"Style",labelPosition:"center",variant:"dashed"}),s.jsxs(a.Stack,{spacing:20,children:[s.jsxs(a.Group,{grow:!0,align:"top",children:[s.jsx(a.NumberInput,{label:"Width",min:1,max:36,step:1,precision:0,rightSection:s.jsx(a.Text,{size:12,children:"of 36 columns"}),styles:{rightSection:{width:"110px"}},value:t.layout.w,onChange:n=>{n&&t.layout.setWidth(n)}}),s.jsx(a.NumberInput,{label:"Height",rightSection:s.jsx(a.Text,{size:12,children:"px"}),styles:{rightSection:{width:"40px"}},value:t.layout.h,onChange:n=>{n&&t.layout.setHeight(n)}})]}),s.jsx(a.Checkbox,{ml:6,label:"Border",checked:e.border.enabled,onChange:n=>e.border.setEnabled(n.currentTarget.checked)})]})]})}),uk=()=>s.jsxs("span",{className:"mantine-103svbs mantine-InputWrapper-required mantine-Select-required","aria-hidden":"true",children:[" ","*"]}),dk=S.observer(()=>{const{panel:t}=Be(),{name:e}=t,[n,r]=pe.useInputState(e),i=e!==n,o=f.useCallback(()=>{i&&t.setName(n)},[i,n]);f.useEffect(()=>{r(e)},[e]);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(uk,{})]}),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})]})}),pk=S.observer(()=>{const{panel:t}=Be();return s.jsx(a.Stack,{spacing:6,mb:10,children:s.jsxs(a.Group,{pl:6,position:"left",spacing:20,children:[s.jsx(a.Checkbox,{size:"sm",checked:t.title.show,onChange:e=>t.title.setShow(e.currentTarget.checked),label:"Show Title",sx:{userSelect:"none"}}),s.jsx(a.Checkbox,{size:"sm",checked:!0,disabled:!0,label:"Use name as title"})]})})});function hk(){return s.jsxs(a.Stack,{sx:{height:"100%"},children:[s.jsx(ck,{}),s.jsx(a.Divider,{label:"Info",labelPosition:"center",variant:"dashed"}),s.jsx(dk,{}),s.jsx(pk,{}),s.jsx(lk,{})]})}const xk={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 Al({data:t}){const e=f.useMemo(()=>{if(!Array.isArray(t)||t.length===0)return[];const r=Ge.createColumnHelper();return Object.keys(t[0]).map(i=>r.accessor(i,{cell:o=>o.getValue()}))},[t]),n=Ge.useReactTable({data:t,columns:e,columnResizeMode:"onChange",getCoreRowModel:Ge.getCoreRowModel()});return t.length===0?s.jsx(a.Box,{sx:{height:"5em"}}):s.jsx(Ce,{children:s.jsxs(a.Table,{sx:xk,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 fk=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],gk={icon:{width:"80px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"80px"}}},mk=({data:t,page:e,setPage:n,limit:r,setLimit:i})=>{const o=t.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:e,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:gk,data:fk,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"]})})]})},yk=({data:t,loading:e})=>{const[n,r]=f.useState(1),[i,o]=f.useState(20),l=f.useMemo(()=>{const c=(n-1)*i,u=c+i;return t.slice(c,u)},[t,n,i]);return s.jsxs(Ce,{children:[s.jsx(mk,{data:t,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:e,overlayBlur:2}),s.jsx(Al,{data:l})]})]})},bk=({queryID:t})=>{const e=oe(),{state:n,error:r}=e.getDataStuffByID(t),i=f.useMemo(()=>e.queries.findByID(t),[e,t]);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},Lr=S.observer(({id:t,moreActions:e,refreshOnMount:n})=>{const r=oe(),{data:i,state:o}=r.getDataStuffByID(t),l=o==="loading",c=f.useCallback(()=>{r.queries.refetchDataByQueryID(t)},[t,r]),u=()=>{r.queries.downloadDataByQueryID(t)};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:[e,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(bk,{queryID:t}),s.jsx(yk,{data:i,loading:l})]})]})}),jk=S.observer(function(){const e=U(),n=X(),{panel:r}=Be(),[i,o]=f.useState(!1),l=c=>{e.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(Lr,{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(Lr,{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))]})]})]})}),vk=S.observer(()=>{const{panel:t}=ut();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:t.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(_r,{})}),s.jsx(a.Group,{grow:!0,position:"center",children:s.jsx(a.Text,{lineClamp:1,weight:"bold",children:t.title.show?t.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(kr,{panel:t})})]})})})}),Br={name:"new_var",size:"1rem",weight:"initial",color:{type:"static",staticColor:"Red"},data_field:"",aggregation:{type:"sum",config:{}},formatter:{output:"number",mantissa:0,trimMantissa:!1,average:!1}};class wk{constructor(e){z(this,"panel");z(this,"selected");this.panel=e,W.makeAutoObservable(this,{},{deep:!1,autoBind:!0})}get variables(){return this.panel.variables}addNew(){const e=this.panel.variables.filter(n=>n.name.startsWith(Br.name)).length;this.panel.addVariable(y.cloneDeep({...Br,name:`${Br.name}${e||""}`})),this.selected=y.last(this.panel.variables)}select(e){this.selected=e}remove(e){this.selected===e&&(this.selected=void 0);const n=this.panel.variables.indexOf(e);if(this.panel.removeVariable(e),!this.selected&&!y.isEmpty(this.panel.variables)){const r=Math.min(this.panel.variables.length-1,n);this.selected=this.panel.variables[r]}}}function Ck(){const{panel:t}=Be();return $.useCreation(()=>new wk(t),[t])}const zl=a.createStyles(t=>({root:{height:"100%",overflow:"hidden",".var-list-container":{"& > *":{height:"100%"},width:250,height:"100%"},".var-list-actions":{height:"fit-content",flexShrink:0,width:"100%"},".var-list":{flex:"1 1 auto",overflow:"auto",minHeight:0,"& > *":{flex:"0 0 auto"}}},config:{height:"100%",overflow:"auto",paddingRight:10}})),Sk=f.forwardRef(function({value:e,onChange:n,data:r,withStyle:i=!0},o){const l=(c,u)=>{const d=y.cloneDeep(e);y.set(d,c,u),n(d)};return s.jsxs(a.Box,{px:"sm",py:"md",ref:o,children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(a.TextInput,{label:"Name",required:!0,value:e.name,onChange:c=>l("name",c.currentTarget.value)}),s.jsx(B,{label:"Data Field",required:!0,value:e.data_field,onChange:c=>l("data_field",c)})]}),s.jsx(Dn,{label:"Aggregation",value:e.aggregation,onChange:c=>l("aggregation",c)}),e.aggregation.type!=="custom"&&s.jsxs(s.Fragment,{children:[s.jsx(a.Divider,{my:"xs",label:"Format",labelPosition:"center"}),s.jsx(Ae,{value:e.formatter,onChange:c=>l("formatter",c)})]}),i&&s.jsx(ya,{value:e,onChange:n})]})}),_k=t=>{const{uiModel:e}=t;return s.jsx(a.Stack,{className:"var-list",children:e.variables.map(n=>s.jsx(a.Button,{variant:e.selected===n?"filled":"subtle",color:"gray",onClick:()=>e.select(n),children:n.name},n.name))})},kk=S.observer(_k),Tk=({variable:t,data:e})=>s.jsx(a.Group,{style:{minHeight:0,height:"calc(100% - 68px)"},children:s.jsx(a.Paper,{withBorder:!0,p:"md",children:ba(t,e)})}),Ik=S.observer(Tk),Dk=t=>{const e=$.useCreation(()=>XS(t.variable),[t.variable]),{classes:n}=zl(),{data:r}=Be();return s.jsxs(a.Group,{style:{height:"100%"},align:"start",children:[s.jsxs(a.Stack,{"data-testid":"variable-editor",align:"stretch",className:n.config,children:[s.jsxs(a.Group,{position:"right",children:[s.jsx(a.ActionIcon,{variant:"filled",disabled:!e.changed,color:"primary",onClick:e.commit,children:s.jsx(k.IconDeviceFloppy,{size:18})}),s.jsx(a.ActionIcon,{color:"red",onClick:()=>t.uiModel.remove(t.variable),children:s.jsx(k.IconTrash,{size:18})})]}),s.jsx(Sk,{value:g.getSnapshot(e.copy),onChange:e.update,data:r})]}),s.jsx(Ik,{variable:g.getSnapshot(e.copy),data:r})]})},Mk=S.observer(Dk),Ak=()=>{const t=Ck(),{classes:e}=zl();return s.jsxs(a.Group,{className:e.root,noWrap:!0,align:"start",children:[s.jsx(a.Paper,{withBorder:!0,p:"md",className:"var-list-container",children:s.jsxs(a.Stack,{justify:"space-between",children:[s.jsx(a.Box,{className:"var-list-actions",children:s.jsx(a.Button,{variant:"light",size:"sm",onClick:t.addNew,fullWidth:!0,children:"Add Variable"})}),s.jsx(kk,{uiModel:t})]})}),t.selected?s.jsx(s.Fragment,{children:s.jsx(Mk,{uiModel:t,variable:t.selected})}):s.jsx("span",{children:"Select or create a new variable on right side"})]})},zk=S.observer(Ak);function Ek(){const{vizManager:t}=f.useContext(et);return f.useMemo(()=>{const e=t.availableVizList.map(n=>({value:n.name,label:n.displayName??n.name,group:n.displayGroup??""}));return y.orderBy(e,[n=>n.group,n=>n.label],["asc","asc"])},[t])}const Pk=S.observer(({value:t,submit:e})=>{const[n,r]=pe.useInputState(t);f.useEffect(()=>{r(t)},[t]);const i=Ek(),o=t!==n;return s.jsx(a.Select,{label:"Visualization",value:n,searchable:!0,onChange:r,data:i,rightSection:s.jsx(a.ActionIcon,{disabled:!o,onClick:()=>e(n),children:s.jsx(_.DeviceFloppy,{size:20})}),maxDropdownHeight:600})}),El=[];function Lk(t,e){try{return t.resolveComponent(e).createConfig()}catch{return null}}function Bk(){const{data:t,panel:{variables:e,viz:n,title:r,name:i,queryIDs:o,description:l,id:c}}=Be(),{vizManager:u}=f.useContext(et),d={name:i,title:r,description:l,viz:n,queryIDs:o,id:c},h=Xo(d);try{return u.resolveComponent(d.viz.type),s.jsx(qn,{configure:h,children:s.jsx(n1,{variables:e,setVizConf:n.setConf,panel:d,vizManager:u,data:t})})}catch(p){return console.info(y.get(p,"message")),null}}const Ok=S.observer(()=>{const{data:t,panel:{viz:e}}=Be(),{vizManager:n}=f.useContext(et),r=f.useCallback(d=>{if(d===e.type)return;const h=Lk(n,d);e.setType(d),e.setConf(h||{})},[e.type]),i=d=>{try{e.setConf(JSON.parse(d))}catch(h){console.error(h)}},o=f.useMemo(()=>{var d;return(d=El.find(h=>h.value===e.type))==null?void 0:d.Panel},[e.type,El]),l=Bk(),c=o?f.createElement(o,{data:t,conf:e.conf,setConf:e.setConf}):null,u=l||c;return s.jsxs(a.Stack,{align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[s.jsx(Pk,{submit:r,value:e.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(e.conf,null,2),onChange:i})]})]})}),$k=S.observer(({panel:t,sourceViewID:e})=>{const n=X(),[r,i]=f.useState(e);f.useEffect(()=>{i(e)},[e]);const[o,{open:l,close:c}]=pe.useDisclosure(!1),u=()=>{t.moveToView(e,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===e,children:"Confirm"})]})]})})]})}),Vk={root:{flexGrow:1,width:"100%",overflow:"hidden"},panel:{width:"100%",height:"calc(100% - 44px)",padding:10,overflow:"scroll"}},Pl=({children:t})=>s.jsxs(a.Group,{noWrap:!0,grow:!0,position:"left",spacing:20,sx:{width:"100%",height:"100%"},children:[s.jsx(a.Box,{sx:{maxWidth:"calc(100% - 610px - 10px)",height:"100%",overflow:"auto"},children:t}),s.jsx(vk,{})]});function Nk(t){return!["richText","button"].includes(t)}const qk=S.observer(({panel:t})=>{const e=Me.useModals(),n=U(),r=X(),[i,o]=f.useState("Data"),l=t.queries,u=Nk(t.viz.type)&&t.dataLoading,d=u||t.queryErrors.length>0||t.queryStateMessages!==""||l.length===0,h=n.editor.path[1];f.useEffect(()=>{o(m=>d&&m==="Visualization"?"Data":m)},[t.id,d]);const p=()=>{n.editor.setPath(["_VIEWS_",h])},x=()=>e.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.removePanelByID(t.id,h),p()},confirmProps:{color:"red"},zIndex:320});return s.jsxs(js,{value:{panel:t,data:t.data,loading:u,errors:t.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:t.name}),s.jsxs(a.Group,{position:"right",noWrap:!0,children:[s.jsx($k,{panel:t,sourceViewID:h}),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:Vk,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(jk,{})]}),s.jsx(a.Tabs.Panel,{value:"Panel",children:s.jsx(Pl,{children:s.jsx(hk,{})})}),s.jsx(a.Tabs.Panel,{value:"Variables",children:s.jsx(zk,{})}),s.jsx(a.Tabs.Panel,{value:"Visualization",children:s.jsx(Ce,{children:s.jsx(Pl,{children:s.jsx(Ok,{})})})}),s.jsx(a.Tabs.Panel,{value:"Interactions",children:s.jsx(Ce,{children:s.jsx(Id,{})})})]})]})}),Fk=S.observer(({viewID:t,panelID:e})=>{const n=X();if(!n.views.findByID(t))return s.jsxs(a.Text,{size:14,children:["View by ID[",t,"] is not found"]});const i=n.panels.findByID(e);return i?s.jsx(qk,{panel:i}):s.jsxs(a.Text,{size:14,children:["Panel by ID[",e,"] is not found"]})}),Gk=S.observer(()=>{const[t,e]=f.useState([]),n=Me.useModals(),r=U(),i=p=>{r.editor.setPath(["_QUERIES_",p])},o=()=>{n.openConfirmModal({title:"Delete ununsed queries?",children:s.jsx(a.Text,{size:"sm",children:"This action cannot be undone."}),labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>r.content.removeUnusedQueries(),confirmProps:{color:"red"},zIndex:320})},l=()=>{r.content.queries.downloadSchema(t)},c=f.useMemo(()=>r.content.queries.sortedList.map(p=>p.id),[r.content.queries.sortedList]),u=()=>{e(c)},d=()=>{e([])},h=r.content.queriesUsage;return s.jsxs(a.Stack,{sx:{height:"100%"},spacing:"sm",pb:"59px",children:[s.jsx(a.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:s.jsx(a.Text,{px:"md",align:"left",sx:{userSelect:"none",cursor:"default"},children:"Manage Queries"})}),s.jsxs(a.Flex,{justify:"space-between",align:"center",px:12,children:[s.jsxs(a.Group,{position:"left",children:[s.jsxs(a.Button.Group,{children:[s.jsx(a.Button,{variant:"default",size:"xs",onClick:u,children:"Select All"}),s.jsx(a.Button,{variant:"default",size:"xs",onClick:d,children:"Clear Selection"})]}),s.jsx(a.Button,{size:"xs",color:"blue",leftIcon:s.jsx(k.IconCode,{size:14}),disabled:t.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:t,onChange:e,children:s.jsxs(a.Table,{fontSize:"sm",highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"40px"}}),s.jsx("th",{children:"Name"}),s.jsx("th",{style:{width:"200px"},children:"Data Source"}),s.jsx("th",{style:{width:"100px",textAlign:"right"},children:"Type"}),s.jsx("th",{style:{width:"100px",textAlign:"center"},children:"Usage"}),s.jsx("th",{style:{width:"300px",paddingLeft:"24px"},children:"Action"})]})}),s.jsx("tbody",{children:r.content.queries.sortedList.map(p=>{var m;const x=((m=h[p.id])==null?void 0:m.length)??0;return s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx(a.Checkbox,{value:p.id,styles:{input:{cursor:"pointer"}}})}),s.jsx("td",{children:p.name}),s.jsx("td",{children:p.key}),s.jsx("td",{style:{textAlign:"right"},children:p.type}),s.jsx("td",{style:{color:x===0?"#ff0000":"#000",fontWeight:x===0?"bold":"normal",textAlign:"center"},children:x}),s.jsx("td",{children:s.jsx(a.Button,{variant:"subtle",size:"xs",onClick:()=>i(p.id),children:"Open"})})]},p.id)})})]})})})]})}),Wk=t=>{const{queryModel:e}=t,n=U(),r=X(),o=r.findQueryUsage(e.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(e.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"})},Rk=S.observer(Wk),Ll=({width:t="calc(100% - 32px)",lastWidth:e="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:t,height:n,radius:"xs"},c)),s.jsx(a.Skeleton,{width:e,height:n,radius:"xs"})]}),sn=({value:t})=>t===null||t===""?null:s.jsx(a.Tooltip,{label:t,disabled:!t,multiline:!0,children:s.jsx(a.ActionIcon,{children:s.jsx(k.IconInfoCircle,{size:14})})}),Qk=({column:t})=>{const{column_key:e,column_key_text:n}=t;return e?s.jsx(a.Tooltip,{label:n,disabled:!n,children:s.jsx(a.Badge,{children:e})}):null},Yk=S.observer(({dataSource:t})=>{const{columns:e}=t;return e.loading?s.jsx(Ll,{height:"24px",width:"100%",lastWidth:"100%",count:20,pl:6}):e.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:e.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(Qk,{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))})]})}),Kk=S.observer(({dataSource:t})=>{const{indexes:e}=t,n=e.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))})]})}),Uk=S.observer(({dataSource:t})=>{const{indexes:e}=t,n=e.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))})]})}),Xk=S.observer(({dataSource:t})=>{const{indexes:e}=t;return e.loading||e.empty?null:t.type===De.MySQL?s.jsx(Kk,{dataSource:t}):t.type===De.Postgresql?s.jsx(Uk,{dataSource:t}):null}),Jk=S.observer(({dataSource:t})=>s.jsxs(a.Stack,{spacing:40,pt:10,sx:{flexGrow:1,overflow:"auto",position:"relative"},children:[s.jsx(Ce,{children:s.jsx(Yk,{dataSource:t})}),s.jsx(Ce,{children:s.jsx(Xk,{dataSource:t})})]}));function Zk({table_type:t}){return t==="VIEW"?s.jsx(k.IconEye,{size:14}):t==="BASE TABLE"?s.jsx(k.IconTable,{size:14}):null}const Hk=S.observer(({dataSource:t})=>{const{tables:e}=t;return e.loading?s.jsx(Ll,{height:"24px",lastWidth:"50%",count:15}):s.jsx(a.Box,{h:"100%",sx:{overflow:"auto",".mantine-NavLink-label":{fontFamily:"monospace"}},children:Object.entries(e.data).map(([n,r])=>s.jsx(a.NavLink,{label:n,icon:s.jsx(k.IconDatabase,{size:14}),defaultOpened:t.table_schema===n,pl:0,childrenOffset:14,children:r.map(i=>s.jsx(a.NavLink,{label:i.table_name,icon:s.jsx(Zk,{table_type:i.table_type}),onClick:()=>{t.setKeywords(n,i.table_name)},active:t.table_name===i.table_name},i.table_name))},n))})}),eT=({visible:t})=>s.jsx(a.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:s.jsx(a.LoadingOverlay,{visible:t})}),tT=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],nT={icon:{width:"50px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"50px"}}},sT=S.observer(({dataSource:t})=>{const{tableData:e}=t;return s.jsxs(a.Group,{pt:10,px:10,position:"apart",children:[s.jsxs(a.Group,{position:"left",children:[e.maxPage>1&&s.jsx(a.Pagination,{size:"sm",value:e.page,onChange:e.setPage,total:e.maxPage,withEdges:e.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:nT,data:tT,value:String(e.limit),onChange:n=>e.setLimit(Number(n))})]}),s.jsx(a.Group,{position:"right",children:s.jsxs(a.Text,{color:"dimmed",my:0,size:14,children:["Total ",e.total," rows"]})})]})}),rT=S.observer(({dataSource:t})=>{const e=t.tableData;return e.maxPage===0?s.jsx(a.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:"This table is empty"}):e.error?s.jsx(a.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:e.error}):e.page===1&&e.loading?s.jsx(eT,{visible:!0}):s.jsxs(Ce,{children:[s.jsx(sT,{dataSource:t}),s.jsxs(a.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[s.jsx(a.LoadingOverlay,{visible:e.loading,overlayBlur:2}),s.jsx(Al,{data:e.data})]})]})}),iT={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},aT=S.observer(({dataSource:t})=>(f.useEffect(()=>{t.loadTablesIfEmpty()},[t]),t.tables.error?s.jsx(a.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:t.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(Hk,{dataSource:t})})}),s.jsxs(a.Tabs,{defaultValue:"structure",styles:iT,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(Jk,{dataSource:t})}),s.jsx(a.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:s.jsx(rT,{dataSource:t})})]})]}))),oT={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"}},Bl=S.observer(({dataSource:t,triggerButtonProps:e={}})=>{const[n,r]=f.useState(!1);return t.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:t.key}),s.jsx(a.Badge,{variant:"gradient",gradient:{from:"orange",to:"red"},children:t.type})]})]}),zIndex:320,size:"96vw",styles:oT,children:s.jsx(a.Box,{sx:{height:"calc(100vh - 220px)"},children:s.jsx(aT,{dataSource:t})})}),s.jsx(a.Button,{variant:"subtle",onClick:()=>r(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},...e,children:"See Table Structure"})]})}),lT=f.forwardRef(({label:t,type:e,...n},r)=>s.jsxs(a.Group,{position:"apart",ref:r,...n,children:[s.jsx(a.Text,{children:t}),s.jsx(a.Text,{children:e})]})),cT=S.observer(({value:t,onChange:e})=>{const n=U(),{data:r=[],loading:i}=$.useRequest(ps,{refreshDeps:[]},[]),o=f.useMemo(()=>r.map(d=>({label:d.key,value:d.key,type:d.type})),[r]),l=f.useMemo(()=>o.reduce((d,h)=>(d[h.value]=h.type,d),{}),[o]),c=d=>{d!==null&&e({key:d,type:l[d]})},u=f.useMemo(()=>n.datasources.find(t),[n,t]);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(Bl,{dataSource:u,triggerButtonProps:{compact:!0,size:"xs",px:10}})]}),itemComponent:lT,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:t.key,onChange:c})}),Ol=f.forwardRef((t,e)=>{const{label:n,description:r,...i}=t;return s.jsx("div",{ref:e,...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})]})})}),uT=S.observer(({queryModel:t})=>{const[e,n]=f.useState(t.name);return f.useEffect(()=>{n(t.name)},[t.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:e,onChange:r=>{n(r.currentTarget.value)},rightSection:s.jsx(a.ActionIcon,{variant:"filled",color:"blue",size:"sm",onClick:()=>t.setName(e),disabled:e===t.name,children:s.jsx(k.IconDeviceFloppy,{size:16})}),onBlur:()=>{t.setName(e)}}),s.jsx(cT,{value:{type:t.type,key:t.key},onChange:({type:r,key:i})=>{t.setKey(i),t.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:t.conditionOptions,value:[...t.run_by],onChange:t.setRunBy,itemComponent:Ol,maxDropdownHeight:500}),t.typedAsHTTP&&s.jsx(a.MultiSelect,{label:"Re-run query when these changed",placeholder:"Leave it empty to never re-run this query",data:t.conditionOptions,value:[...t.react_to],onChange:t.setReactTo,itemComponent:Ol,maxDropdownHeight:500}),s.jsx(a.Divider,{mt:20,mb:10,variant:"dashed"}),s.jsx(Rk,{queryModel:t})]})})});function dT({content:t}){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(ft.Prism,{language:"sql",noCopy:!0,withLineNumbers:!0,children:t})})]})}const pT=S.observer(()=>{const e=[...U().globalSQLSnippets.list];return e.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:e.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(dT,{content:i})})]},r)})})]})}),hT=`
458
+ `,Y_=()=>{const[t,e]=f.useState(!1);return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"subtle",compact:!0,onClick:()=>e(n=>!n),children:t?"Close":"Click to see expected data structure"}),s.jsx(a.Collapse,{in:t,children:s.jsx(ct.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:U_})})]})},K_=S.observer(function({config:e}){return s.jsxs(s.Fragment,{children:[s.jsx(a.Checkbox,{checked:e.required,onChange:n=>e.setRequired(n.currentTarget.checked),label:"Required"}),s.jsx(a.TextInput,{label:"Min-width",value:e.min_width,onChange:n=>e.setMinWidth(n.currentTarget.value),placeholder:"200px"}),s.jsx(a.Divider,{label:"Fetch options from database",labelPosition:"center"}),s.jsx(a.Checkbox,{checked:e.treeCheckStrictly,onChange:n=>e.setTreeCheckStrictly(n.currentTarget.checked),label:"Parent and children nodes are not associated"}),s.jsx(a.NumberInput,{value:e.default_selection_count,onChange:e.setDefaultSelectionCount,label:"Select first N options by default"}),s.jsx(Pr,{value:e.options_query_id,onChange:e.setOptionsQueryID}),s.jsx(Y_,{})]})}),X_=S.observer(function({filter:e}){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(e,null,4)})]})}),J_={select:R_,"multi-select":W_,"tree-select":K_,"text-input":Q_,checkbox:N_,"date-range":F_},_t={select:"Select","multi-select":"Multi Select","tree-select":"Tree Select","text-input":"Text Input",checkbox:"Checkbox","date-range":"Date Range"},Z_=[{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"}],H_=S.observer(function({filter:e}){const n=X(),r=f.useMemo(()=>J_[e.type],[e.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:e.order,onChange:e.setOrder,hideControls:!0,sx:{flexGrow:"1 !important"}}),e.auto_submit_supported&&s.jsx(a.Checkbox,{label:"Submit automatically",checked:e.auto_submit,onChange:i=>e.setAutoSubmit(i.currentTarget.checked),mt:22})]}),s.jsx(a.MultiSelect,{label:"Visible in...",data:n.views.options,value:[...e.visibleInViewsIDs],onChange:e.setVisibleInViewsIDs}),s.jsx(a.TextInput,{label:"Key",placeholder:"A unique key to refer",required:!0,value:e.key,onChange:i=>{e.setKey(i.currentTarget.value)}}),s.jsx(a.TextInput,{label:"Label",placeholder:"Label for this field",required:!0,value:e.label,onChange:i=>{e.setLabel(i.currentTarget.value)}}),s.jsx(a.Select,{label:"Widget",data:Z_,required:!0,value:e.type,onChange:e.setType}),s.jsx(r,{config:e.config})]})]}),s.jsx(X_,{filter:e})]})}),ek=S.observer(({id:t})=>{const e=Me.useModals(),n=K(),r=X();if(t==="")return null;const i=r.filters.findByID(t);if(!i)return s.jsxs(a.Text,{size:14,children:["Filter by ID[",t,"] is not found"]});const o=()=>{n.editor.setPath(["_FILTERS_",""])},l=()=>{e.openConfirmModal({title:"Delete this filter?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.filters.removeByID(t),o()},confirmProps:{color:"red"},zIndex:320})};return 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(H_,{filter:i})})]})}),tk=S.observer(()=>{const[t,e]=f.useState([]),n=K(),r=u=>{n.editor.setPath(["_FILTERS_",u])},i=()=>{n.content.filters.downloadSchema(t)},o=f.useMemo(()=>n.content.filters.sortedList.map(u=>u.id),[n.content.filters.sortedList]),l=()=>{e(o)},c=()=>{e([])};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:t.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:t,onChange:e,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))})]})})})]})}),nk=S.observer(()=>{const t=X(),[e,n]=f.useState(()=>JSON.stringify(t.mock_context.current,null,4)),r=()=>{try{t.mock_context.replace(JSON.parse(e))}catch(o){xt.showNotification({title:"Failed",message:o.message,color:"red"})}},i=f.useMemo(()=>{try{return JSON.stringify(JSON.parse(e))!==JSON.stringify(t.mock_context.current)}catch{return!1}},[e,t.mock_context.current]);return s.jsxs(a.Stack,{sx:{border:"1px solid #eee",borderLeft:"none",borderRight:"none",flexGrow:1,maxWidth:"unset"},children:[s.jsx(a.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:s.jsx(a.Text,{weight:500,children:"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:e,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})})]})]})}),sk=S.observer(()=>{const{panel:t}=Le();return s.jsx(rr,{label:"Description",value:t.description,onChange:t.setDescription,styles:{root:{flexGrow:1}}})}),rk=S.observer(()=>{const{panel:t}=Le(),{style:e}=t;return s.jsxs(s.Fragment,{children:[s.jsx(a.Divider,{mb:-10,label:"Style",labelPosition:"center",variant:"dashed"}),s.jsxs(a.Stack,{spacing:20,children:[s.jsxs(a.Group,{grow:!0,align:"top",children:[s.jsx(a.NumberInput,{label:"Width",min:1,max:36,step:1,precision:0,rightSection:s.jsx(a.Text,{size:12,children:"of 36 columns"}),styles:{rightSection:{width:"110px"}},value:t.layout.w,onChange:n=>{n&&t.layout.setWidth(n)}}),s.jsx(a.NumberInput,{label:"Height",rightSection:s.jsx(a.Text,{size:12,children:"px"}),styles:{rightSection:{width:"40px"}},value:t.layout.h,onChange:n=>{n&&t.layout.setHeight(n)}})]}),s.jsx(a.Checkbox,{ml:6,label:"Border",checked:e.border.enabled,onChange:n=>e.border.setEnabled(n.currentTarget.checked)})]})]})}),ik=()=>s.jsxs("span",{className:"mantine-103svbs mantine-InputWrapper-required mantine-Select-required","aria-hidden":"true",children:[" ","*"]}),ak=S.observer(()=>{const{panel:t}=Le(),{name:e}=t,[n,r]=pe.useInputState(e),i=e!==n,o=f.useCallback(()=>{i&&t.setName(n)},[i,n]);f.useEffect(()=>{r(e)},[e]);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(ik,{})]}),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})]})}),ok=S.observer(()=>{const{panel:t}=Le();return s.jsx(a.Stack,{spacing:6,mb:10,children:s.jsxs(a.Group,{pl:6,position:"left",spacing:20,children:[s.jsx(a.Checkbox,{size:"sm",checked:t.title.show,onChange:e=>t.title.setShow(e.currentTarget.checked),label:"Show Title",sx:{userSelect:"none"}}),s.jsx(a.Checkbox,{size:"sm",checked:!0,disabled:!0,label:"Use name as title"})]})})});function lk(){return s.jsxs(a.Stack,{sx:{height:"100%"},children:[s.jsx(rk,{}),s.jsx(a.Divider,{label:"Info",labelPosition:"center",variant:"dashed"}),s.jsx(ak,{}),s.jsx(ok,{}),s.jsx(sk,{})]})}const ck={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 zl({data:t}){const e=f.useMemo(()=>{if(!Array.isArray(t)||t.length===0)return[];const r=Ge.createColumnHelper();return Object.keys(t[0]).map(i=>r.accessor(i,{cell:o=>o.getValue()}))},[t]),n=Ge.useReactTable({data:t,columns:e,columnResizeMode:"onChange",getCoreRowModel:Ge.getCoreRowModel()});return t.length===0?s.jsx(a.Box,{sx:{height:"5em"}}):s.jsx(Ce,{children:s.jsxs(a.Table,{sx:ck,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 uk=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],dk={icon:{width:"80px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"80px"}}},pk=({data:t,page:e,setPage:n,limit:r,setLimit:i})=>{const o=t.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:e,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:dk,data:uk,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"]})})]})},hk=({data:t,loading:e})=>{const[n,r]=f.useState(1),[i,o]=f.useState(20),l=f.useMemo(()=>{const c=(n-1)*i,u=c+i;return t.slice(c,u)},[t,n,i]);return s.jsxs(Ce,{children:[s.jsx(pk,{data:t,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:e,overlayBlur:2}),s.jsx(zl,{data:l})]})]})},xk=({queryID:t})=>{const e=oe(),{state:n,error:r}=e.getDataStuffByID(t),i=f.useMemo(()=>e.queries.findByID(t),[e,t]);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},Lr=S.observer(({id:t,moreActions:e,refreshOnMount:n})=>{const r=oe(),{data:i,state:o}=r.getDataStuffByID(t),l=o==="loading",c=f.useCallback(()=>{r.queries.refetchDataByQueryID(t)},[t,r]),u=()=>{r.queries.downloadDataByQueryID(t)};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:[e,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(xk,{queryID:t}),s.jsx(hk,{data:i,loading:l})]})]})}),fk=S.observer(function(){const e=K(),n=X(),{panel:r}=Le(),[i,o]=f.useState(!1),l=c=>{e.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(Lr,{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(Lr,{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))]})]})]})}),gk=S.observer(()=>{const{panel:t}=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:t.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(_r,{})}),s.jsx(a.Group,{grow:!0,position:"center",children:s.jsx(a.Text,{lineClamp:1,weight:"bold",children:t.title.show?t.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(kr,{panel:t})})]})})})}),Br={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 mk{constructor(e){z(this,"panel");z(this,"selected");this.panel=e,e.variables.length>0&&(this.selected=e.variables[0]),W.makeAutoObservable(this,{},{deep:!1,autoBind:!0})}get variables(){return this.panel.variables}get variableOptions(){return this.panel.variables.map(e=>({label:e.name,value:e.name,description:e.aggregation.type}))}addNew(){const e=this.panel.variables.filter(n=>n.name.startsWith(Br.name)).length;this.panel.addVariable(y.cloneDeep({...Br,name:`${Br.name}${e||""}`})),this.selected=y.last(this.panel.variables)}select(e){this.selected=e}selectByName(e){if(!e){console.warn("Unexpected null name when calling selectByName");return}const n=this.variables.find(r=>r.name===e);if(!n){console.error(`Variable by name[${e}] not found`);return}this.selected=n}remove(e){this.selected===e&&(this.selected=void 0);const n=this.panel.variables.indexOf(e);if(this.panel.removeVariable(e),!this.selected&&!y.isEmpty(this.panel.variables)){const r=Math.min(this.panel.variables.length-1,n);this.selected=this.panel.variables[r]}}}function yk(){const{panel:t}=Le();return $.useCreation(()=>new mk(t),[t])}function bk({label:t,value:e,onChange:n},r){const[i,o]=f.useState(Array.isArray(e)?[...e]:[]),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,e),[i,e]),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:t}),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(C=>(C.splice(m,1,j),[...C]))},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 jk=f.forwardRef(bk);function vk({label:t,value:e,onChange:n,type:r},i){const[o,l]=f.useState(Array.isArray(e)?[...e]:[]),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),e.map(String)),[o,e]),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:t}),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(C=>(C.splice(x,1,j),[...C]))},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 wk=f.forwardRef(vk),Ck=f.forwardRef(function({value:e,onChange:n},r){const i=e.color.type,o=(c,u)=>{const d=y.cloneDeep(e);y.set(d,c,u),n(d)},l=c=>{if(c==="static"){n({...e,color:{type:"static",staticColor:"#25262B"}});return}n({...e,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:e.size,onChange:c=>o("size",c.currentTarget.value)})}),s.jsx(a.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:s.jsx(io,{label:"Font Weight",value:e.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:e.color.type,onChange:l}),i==="static"&&s.jsx(Se,{value:e.color.staticColor,onChange:c=>o("color.staticColor",c)}),i==="continuous"&&s.jsxs(s.Fragment,{children:[s.jsx(wk,{label:"Value Range",value:e.color.valueRange,type:"number",onChange:c=>o("color.valueRange",c)}),s.jsx(jk,{label:"Color Range",value:e.color.colorRange,onChange:c=>o("color.colorRange",c)})]})]})]})}),Sk=f.forwardRef(function({value:e,onChange:n,withStyle:r=!0,remove:i},o){const l=(c,u)=>{const d=y.cloneDeep(e);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:e.name,onChange:c=>l("name",c.currentTarget.value)}),s.jsx(B,{label:"Data Field",required:!0,value:e.data_field,onChange:c=>l("data_field",c)})]}),s.jsx(Xs,{label:"Aggregation",pt:0,value:e.aggregation,onChange:c=>l("aggregation",c),withFallback:!0}),e.aggregation.type!=="custom"&&s.jsxs(s.Fragment,{children:[s.jsx(a.Divider,{mt:"xl",mb:0,label:"Format",labelPosition:"center",variant:"dashed"}),s.jsx(Be,{value:e.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(Ck,{value:e,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"})]})}),_k=S.observer(t=>{const e=$.useCreation(()=>RS(t.variable),[t.variable]),n=()=>t.uiModel.remove(t.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:!e.changed,color:"red",onClick:e.reset,leftIcon:s.jsx(k.IconRecycle,{size:18}),children:"Revert Changes"}),s.jsx(a.Button,{variant:"filled",size:"xs",disabled:!e.changed,color:"green",onClick:e.commit,leftIcon:s.jsx(k.IconDeviceFloppy,{size:18}),children:"Save Changes"})]}),s.jsx(Sk,{value:g.getSnapshot(e.copy),onChange:e.update,remove:n})]})});S.observer(t=>{const{uiModel:e}=t;return s.jsx(a.Stack,{className:"var-list",children:e.variables.map(n=>s.jsx(a.Button,{variant:e.selected===n?"filled":"subtle",color:"gray",onClick:()=>e.select(n),children:n.name},n.name))})});const kk=S.observer(({model:t})=>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:t.addNew,sx:{flexGrow:0,flexShrink:0,alignSelf:"flex-end",height:"38px"},children:"Add a Variable"})})),Tk=S.observer(()=>{var e;const t=yk();return t.variableOptions.length===0?s.jsx(kk,{model:t}):s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{position:"left",children:[s.jsx(a.Select,{label:"Variables",data:t.variableOptions,value:(e=t.selected)==null?void 0:e.name,onChange:t.selectByName,maxDropdownHeight:600,sx:{flexGrow:1}}),s.jsx(a.Button,{variant:"light",size:"xs",leftIcon:s.jsx(k.IconPlus,{size:16}),onClick:t.addNew,sx:{flexGrow:0,flexShrink:0,alignSelf:"flex-end",height:"38px"},children:"Add a Variable"})]}),s.jsx(a.Divider,{variant:"dashed"}),t.selected?s.jsx(_k,{uiModel:t,variable:t.selected}):s.jsx("span",{children:"Select or create a new variable on right side"})]})}),Ik=S.observer(()=>{const{panel:t}=Le();return Object.keys(t.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(t.variableStrings,null,4)})]})});function Dk(){const{vizManager:t}=f.useContext(et);return f.useMemo(()=>{const e=t.availableVizList.map(n=>({value:n.name,label:n.displayName??n.name,group:n.displayGroup??""}));return y.orderBy(e,[n=>n.group,n=>n.label],["asc","asc"])},[t])}const Mk=S.observer(({value:t,submit:e})=>{const[n,r]=pe.useInputState(t);f.useEffect(()=>{r(t)},[t]);const i=Dk(),o=t!==n;return s.jsx(a.Select,{label:"Visualization",value:n,searchable:!0,onChange:r,data:i,rightSection:s.jsx(a.ActionIcon,{disabled:!o,onClick:()=>e(n),children:s.jsx(_.DeviceFloppy,{size:20})}),maxDropdownHeight:600})}),El=[];function Ak(t,e){try{return t.resolveComponent(e).createConfig()}catch{return null}}function zk(){const{data:t,panel:{variables:e,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=Jo(d);try{return u.resolveComponent(d.viz.type),s.jsx(Nn,{configure:p,children:s.jsx(JS,{variables:e,setVizConf:n.setConf,panel:d,vizManager:u,data:t})})}catch(h){return console.info(y.get(h,"message")),null}}const Ek=S.observer(()=>{const{data:t,panel:{viz:e}}=Le(),{vizManager:n}=f.useContext(et),r=f.useCallback(d=>{if(d===e.type)return;const p=Ak(n,d);e.setType(d),e.setConf(p||{})},[e.type]),i=d=>{try{e.setConf(JSON.parse(d))}catch(p){console.error(p)}},o=f.useMemo(()=>{var d;return(d=El.find(p=>p.value===e.type))==null?void 0:d.Panel},[e.type,El]),l=zk(),c=o?f.createElement(o,{data:t,conf:e.conf,setConf:e.setConf}):null,u=l||c;return s.jsxs(a.Stack,{align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[s.jsx(Mk,{submit:r,value:e.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(e.conf,null,2),onChange:i})]})]})}),Pk=S.observer(({panel:t,sourceViewID:e})=>{const n=X(),[r,i]=f.useState(e);f.useEffect(()=>{i(e)},[e]);const[o,{open:l,close:c}]=pe.useDisclosure(!1),u=()=>{t.moveToView(e,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===e,children:"Confirm"})]})]})})]})}),Lk={root:{flexGrow:1,width:"100%",minWidth:"1200px",overflow:"hidden"},panel:{width:"100%",minWidth:"1200px",height:"calc(100% - 44px)",padding:10,overflow:"auto"}},Or=({children:t})=>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:t}),s.jsxs(a.Stack,{justify:"flex-start",sx:{alignSelf:"flex-start",width:"600px",flexGrow:0,flexShrink:0},children:[s.jsx(gk,{}),s.jsx(a.Box,{sx:{flexGrow:1},children:s.jsx(Ik,{})})]})]});function Bk(t){return!["richText","button"].includes(t)}const Ok=S.observer(({panel:t})=>{const e=Me.useModals(),n=K(),r=X(),[i,o]=f.useState("Data"),l=t.queries,u=Bk(t.viz.type)&&t.dataLoading,d=u||t.queryErrors.length>0||t.queryStateMessages!==""||l.length===0,p=n.editor.path[1];f.useEffect(()=>{o(m=>d&&m==="Visualization"?"Data":m)},[t.id,d]);const h=()=>{n.editor.setPath(["_VIEWS_",p])},x=()=>e.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.removePanelByID(t.id,p),h()},confirmProps:{color:"red"},zIndex:320});return s.jsxs(bs,{value:{panel:t,data:t.data,loading:u,errors:t.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:t.name}),s.jsxs(a.Group,{position:"right",noWrap:!0,children:[s.jsx(Pk,{panel:t,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:Lk,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(fk,{})]}),s.jsx(a.Tabs.Panel,{value:"Panel",children:s.jsx(Or,{children:s.jsx(lk,{})})}),s.jsx(a.Tabs.Panel,{value:"Variables",children:s.jsx(Or,{children:s.jsx(Tk,{})})}),s.jsx(a.Tabs.Panel,{value:"Visualization",children:s.jsx(Ce,{children:s.jsx(Or,{children:s.jsx(Ek,{})})})}),s.jsx(a.Tabs.Panel,{value:"Interactions",children:s.jsx(Ce,{children:s.jsx(Td,{})})})]})]})}),$k=S.observer(({viewID:t,panelID:e})=>{const n=X();if(!n.views.findByID(t))return s.jsxs(a.Text,{size:14,children:["View by ID[",t,"] is not found"]});const i=n.panels.findByID(e);return i?s.jsx(Ok,{panel:i}):s.jsxs(a.Text,{size:14,children:["Panel by ID[",e,"] is not found"]})}),Vk=S.observer(()=>{const[t,e]=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(t)},c=f.useMemo(()=>r.content.queries.sortedList.map(h=>h.id),[r.content.queries.sortedList]),u=()=>{e(c)},d=()=>{e([])},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:t.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:t,onChange:e,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)})})]})})})]})}),Nk=t=>{const{queryModel:e}=t,n=K(),r=X(),o=r.findQueryUsage(e.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(e.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"})},qk=S.observer(Nk),Pl=({width:t="calc(100% - 32px)",lastWidth:e="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:t,height:n,radius:"xs"},c)),s.jsx(a.Skeleton,{width:e,height:n,radius:"xs"})]}),sn=({value:t})=>t===null||t===""?null:s.jsx(a.Tooltip,{label:t,disabled:!t,multiline:!0,children:s.jsx(a.ActionIcon,{children:s.jsx(k.IconInfoCircle,{size:14})})}),Fk=({column:t})=>{const{column_key:e,column_key_text:n}=t;return e?s.jsx(a.Tooltip,{label:n,disabled:!n,children:s.jsx(a.Badge,{children:e})}):null},Gk=S.observer(({dataSource:t})=>{const{columns:e}=t;return e.loading?s.jsx(Pl,{height:"24px",width:"100%",lastWidth:"100%",count:20,pl:6}):e.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:e.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(Fk,{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))})]})}),Wk=S.observer(({dataSource:t})=>{const{indexes:e}=t,n=e.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))})]})}),Rk=S.observer(({dataSource:t})=>{const{indexes:e}=t,n=e.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))})]})}),Qk=S.observer(({dataSource:t})=>{const{indexes:e}=t;return e.loading||e.empty?null:t.type===De.MySQL?s.jsx(Wk,{dataSource:t}):t.type===De.Postgresql?s.jsx(Rk,{dataSource:t}):null}),Uk=S.observer(({dataSource:t})=>s.jsxs(a.Stack,{spacing:40,pt:10,sx:{flexGrow:1,overflow:"auto",position:"relative"},children:[s.jsx(Ce,{children:s.jsx(Gk,{dataSource:t})}),s.jsx(Ce,{children:s.jsx(Qk,{dataSource:t})})]}));function Yk({table_type:t}){return t==="VIEW"?s.jsx(k.IconEye,{size:14}):t==="BASE TABLE"?s.jsx(k.IconTable,{size:14}):null}const Kk=S.observer(({dataSource:t})=>{const{tables:e}=t;return e.loading?s.jsx(Pl,{height:"24px",lastWidth:"50%",count:15}):s.jsx(a.Box,{h:"100%",sx:{overflow:"auto",".mantine-NavLink-label":{fontFamily:"monospace"}},children:Object.entries(e.data).map(([n,r])=>s.jsx(a.NavLink,{label:n,icon:s.jsx(k.IconDatabase,{size:14}),defaultOpened:t.table_schema===n,pl:0,childrenOffset:14,children:r.map(i=>s.jsx(a.NavLink,{label:i.table_name,icon:s.jsx(Yk,{table_type:i.table_type}),onClick:()=>{t.setKeywords(n,i.table_name)},active:t.table_name===i.table_name},i.table_name))},n))})}),Xk=({visible:t})=>s.jsx(a.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:s.jsx(a.LoadingOverlay,{visible:t})}),Jk=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],Zk={icon:{width:"50px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"50px"}}},Hk=S.observer(({dataSource:t})=>{const{tableData:e}=t;return s.jsxs(a.Group,{pt:10,px:10,position:"apart",children:[s.jsxs(a.Group,{position:"left",children:[e.maxPage>1&&s.jsx(a.Pagination,{size:"sm",value:e.page,onChange:e.setPage,total:e.maxPage,withEdges:e.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:Zk,data:Jk,value:String(e.limit),onChange:n=>e.setLimit(Number(n))})]}),s.jsx(a.Group,{position:"right",children:s.jsxs(a.Text,{color:"dimmed",my:0,size:14,children:["Total ",e.total," rows"]})})]})}),eT=S.observer(({dataSource:t})=>{const e=t.tableData;return e.maxPage===0?s.jsx(a.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:"This table is empty"}):e.error?s.jsx(a.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:e.error}):e.page===1&&e.loading?s.jsx(Xk,{visible:!0}):s.jsxs(Ce,{children:[s.jsx(Hk,{dataSource:t}),s.jsxs(a.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[s.jsx(a.LoadingOverlay,{visible:e.loading,overlayBlur:2}),s.jsx(zl,{data:e.data})]})]})}),tT={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},nT=S.observer(({dataSource:t})=>(f.useEffect(()=>{t.loadTablesIfEmpty()},[t]),t.tables.error?s.jsx(a.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:t.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(Kk,{dataSource:t})})}),s.jsxs(a.Tabs,{defaultValue:"structure",styles:tT,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(Uk,{dataSource:t})}),s.jsx(a.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:s.jsx(eT,{dataSource:t})})]})]}))),sT={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"}},Ll=S.observer(({dataSource:t,triggerButtonProps:e={}})=>{const[n,r]=f.useState(!1);return t.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:t.key}),s.jsx(a.Badge,{variant:"gradient",gradient:{from:"orange",to:"red"},children:t.type})]})]}),zIndex:320,size:"96vw",styles:sT,children:s.jsx(a.Box,{sx:{height:"calc(100vh - 220px)"},children:s.jsx(nT,{dataSource:t})})}),s.jsx(a.Button,{variant:"subtle",onClick:()=>r(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},...e,children:"See Table Structure"})]})}),rT=f.forwardRef(({label:t,type:e,...n},r)=>s.jsxs(a.Group,{position:"apart",ref:r,...n,children:[s.jsx(a.Text,{children:t}),s.jsx(a.Text,{children:e})]})),iT=S.observer(({value:t,onChange:e})=>{const n=K(),{data:r=[],loading:i}=$.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&&e({key:d,type:l[d]})},u=f.useMemo(()=>n.datasources.find(t),[n,t]);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(Ll,{dataSource:u,triggerButtonProps:{compact:!0,size:"xs",px:10}})]}),itemComponent:rT,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:t.key,onChange:c})}),Bl=f.forwardRef((t,e)=>{const{label:n,description:r,...i}=t;return s.jsx("div",{ref:e,...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})]})})}),aT=S.observer(({queryModel:t})=>{const[e,n]=f.useState(t.name);return f.useEffect(()=>{n(t.name)},[t.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:e,onChange:r=>{n(r.currentTarget.value)},rightSection:s.jsx(a.ActionIcon,{variant:"filled",color:"blue",size:"sm",onClick:()=>t.setName(e),disabled:e===t.name,children:s.jsx(k.IconDeviceFloppy,{size:16})}),onBlur:()=>{t.setName(e)}}),s.jsx(iT,{value:{type:t.type,key:t.key},onChange:({type:r,key:i})=>{t.setKey(i),t.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:t.conditionOptions,value:[...t.run_by],onChange:t.setRunBy,itemComponent:Bl,maxDropdownHeight:500}),t.typedAsHTTP&&s.jsx(a.MultiSelect,{label:"Re-run query when these changed",placeholder:"Leave it empty to never re-run this query",data:t.conditionOptions,value:[...t.react_to],onChange:t.setReactTo,itemComponent:Bl,maxDropdownHeight:500}),s.jsx(a.Divider,{mt:20,mb:10,variant:"dashed"}),s.jsx(qk,{queryModel:t})]})})});function oT({content:t}){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:t})})]})}const lT=S.observer(()=>{const e=[...K().globalSQLSnippets.list];return e.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:e.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(oT,{content:i})})]},r)})})]})}),cT=`
459
459
  -- You may reference query variables in SQL or VizConfig.
460
460
  SELECT *
461
461
  FROM commit
@@ -468,8 +468,8 @@ WHERE
468
468
  AND \${sql_snippets.author_email_condition}
469
469
  -- Global SQL snippets (shared between dashboards)
470
470
  AND \${global_sql_snippets.account_condition}
471
- `,$l=S.observer(function({showSQLSnippets:e=!0,sx:n={}}){const r=U(),i=X(),o=r.context.current,l=(()=>{const c={context:{...i.mock_context.current,...o},filters:i.filters.previewValues};return e&&(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(ft.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:hT})}),s.jsx(a.Tabs.Panel,{value:"local_query_vars",pt:"xs",children:s.jsx(ft.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(pT,{})]})})]})})}),Or=S.observer(()=>{const[t,e]=f.useState(!1);return s.jsxs(s.Fragment,{children:[s.jsx(a.Modal,{opened:t,onClose:()=>e(!1),title:"Query Variables",zIndex:320,size:"800px",children:s.jsx($l,{})}),s.jsx(a.Button,{variant:"subtle",onClick:()=>e(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},children:"See Query Variables"})]})}),Vl={pre:["function build_request({ context, filters }, utils) {"," // build the quest"," return { method: 'POST', url: '/', params: {}, headers: {}, data: {} }","}"].join(`
471
+ `,Ol=S.observer(function({showSQLSnippets:e=!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 e&&(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:cT})}),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(lT,{})]})})]})})}),$r=S.observer(()=>{const[t,e]=f.useState(!1);return s.jsxs(s.Fragment,{children:[s.jsx(a.Modal,{opened:t,onClose:()=>e(!1),title:"Query Variables",zIndex:320,size:"800px",children:s.jsx(Ol,{})}),s.jsx(a.Button,{variant:"subtle",onClick:()=>e(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},children:"See Query Variables"})]})}),$l={pre:["function build_request({ context, filters }, utils) {"," // build the quest"," return { method: 'POST', url: '/', params: {}, headers: {}, data: {} }","}"].join(`
472
472
  `),post:["function process_result(res, utils, state) {"," // your code goes here"," return data","}"].join(`
473
- `)},xT=S.observer(({queryModel:t})=>t.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(Or,{})]}),s.jsx(a.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:s.jsx(Ht,{label:"",value:t.pre_process,onChange:t.setPreProcess,defaultValue:Vl.pre})}),s.jsx(a.Tabs.Panel,{value:"post_process",p:"sm",children:s.jsx(Ht,{label:"",value:t.post_process,onChange:t.setPostProcess,defaultValue:Vl.post})})]}):null),fT=S.observer(({queryID:t,usage:e})=>{const n=U().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:e.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))})]})})}),$r=({value:t,onChange:e,height:n="200px",defaultLanguage:r="sql",theme:i="vs-dark"})=>{const o=c=>{e==null||e(c??"")},l=!e;return s.jsx(me,{className:"minimal-monaco-editor",height:n,defaultLanguage:r,value:t,onChange:l?void 0:o,theme:i,options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1},readOnly:l||!e,"semanticHighlighting.enabled":!0}})},gT=S.observer(({queryModel:t})=>{const e=f.useMemo(()=>y.groupBy(t.dependencies,"type"),[t.dependencies]),n=f.useMemo(()=>t.dependencies.some(i=>!i.valid),[t.dependencies]),r=t.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(e).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"})})}),mT="SELECT 1",yT=S.observer(({queryModel:t})=>{const[e,n]=f.useState(t.sql),r=()=>{t.setSQL(e)},i=()=>{n(t.sql)},o=()=>{n(mT)};f.useEffect(()=>{n(t.sql)},[t.sql]);const l=e!==t.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(gT,{queryModel:t})}),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($r,{height:"100%",value:e,onChange:n,theme:"sql-dark",defaultLanguage:"sql"})]})}),bT=({value:t,height:e="200px",defaultLanguage:n="sql"})=>s.jsx(me,{className:"preview-sql-in-monaco-editor",height:e,defaultLanguage:n,value:t,onChange:void 0,theme:"vs-light",options:{lineNumbers:"on",folding:!0,lineDecorationsWidth:20,wordWrap:"on",minimap:{enabled:!1},readOnly:!0}}),jT=S.observer(({value:t})=>{const n=oe().payloadForSQL,r=f.useMemo(()=>cs(t,n),[t,n]);return s.jsx(bT,{height:"100%",value:r})}),Nl={pre:["function process_request({ context, filters, sql }, utils) {"," // modify and return sql"," return sql","}"].join(`
473
+ `)},uT=S.observer(({queryModel:t})=>t.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($r,{})]}),s.jsx(a.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:s.jsx(en,{label:"",value:t.pre_process,onChange:t.setPreProcess,defaultValue:$l.pre})}),s.jsx(a.Tabs.Panel,{value:"post_process",p:"sm",children:s.jsx(en,{label:"",value:t.post_process,onChange:t.setPostProcess,defaultValue:$l.post})})]}):null),dT=S.observer(({queryID:t,usage:e})=>{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:e.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))})]})})}),Vr=({value:t,onChange:e,height:n="200px",defaultLanguage:r="sql",theme:i="vs-dark"})=>{const o=c=>{e==null||e(c??"")},l=!e;return s.jsx(ge,{className:"minimal-monaco-editor",height:n,defaultLanguage:r,value:t,onChange:l?void 0:o,theme:i,options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1},readOnly:l||!e,"semanticHighlighting.enabled":!0}})},pT=S.observer(({queryModel:t})=>{const e=f.useMemo(()=>y.groupBy(t.dependencies,"type"),[t.dependencies]),n=f.useMemo(()=>t.dependencies.some(i=>!i.valid),[t.dependencies]),r=t.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(e).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"})})}),hT="SELECT 1",xT=S.observer(({queryModel:t})=>{const[e,n]=f.useState(t.sql),r=()=>{t.setSQL(e)},i=()=>{n(t.sql)},o=()=>{n(hT)};f.useEffect(()=>{n(t.sql)},[t.sql]);const l=e!==t.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(pT,{queryModel:t})}),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(Vr,{height:"100%",value:e,onChange:n,theme:"sql-dark",defaultLanguage:"sql"})]})}),fT=({value:t,height:e="200px",defaultLanguage:n="sql"})=>s.jsx(ge,{className:"preview-sql-in-monaco-editor",height:e,defaultLanguage:n,value:t,onChange:void 0,theme:"vs-light",options:{lineNumbers:"on",folding:!0,lineDecorationsWidth:20,wordWrap:"on",minimap:{enabled:!1},readOnly:!0}}),gT=S.observer(({value:t})=>{const n=oe().payloadForSQL,r=f.useMemo(()=>ls(t,n),[t,n]);return s.jsx(fT,{height:"100%",value:r})}),Vl={pre:["function process_request({ context, filters, sql }, utils) {"," // modify and return sql"," return sql","}"].join(`
474
474
  `),post:["function process_result(data, utils, state) {"," // process data and return the result"," return data","}"].join(`
475
- `)},vT=S.observer(({queryModel:t})=>t.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(Or,{}),t.datasource&&s.jsx(Bl,{dataSource:t.datasource})]}),s.jsx(a.Tabs.Panel,{value:"Edit",sx:{position:"relative"},p:"sm",children:s.jsx(yT,{queryModel:t})}),s.jsx(a.Tabs.Panel,{value:"Preview",p:0,pl:4,children:s.jsx(jT,{value:t.sql})}),s.jsx(a.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:s.jsx(Ht,{label:"",value:t.pre_process,onChange:t.setPreProcess,defaultValue:Nl.pre})}),s.jsx(a.Tabs.Panel,{value:"post_process",p:"sm",children:s.jsx(Ht,{label:"",value:t.post_process,onChange:t.setPostProcess,defaultValue:Nl.post})})]}):null),Zn={height:"calc(100% - 44px)",padding:0},wT=S.observer(({queryModel:t})=>{const e=X(),n=f.useMemo(()=>t.datasource?t.typedAsHTTP?"HTTP":"SQL":"Configurations",[t.datasource,t.typedAsHTTP]),[r,i]=f.useState(n);f.useEffect(()=>{i(c=>c!=="Configurations"&&n==="Configurations"?"Configurations":c)},[n]);const o=e.findQueryUsage(t.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"}),t.typedAsSQL&&s.jsx(a.Tabs.Tab,{value:"SQL",children:"Request"}),t.typedAsHTTP&&s.jsx(a.Tabs.Tab,{value:"HTTP",children:"Request"}),s.jsx(a.Tabs.Tab,{value:"Data",disabled:!t.datasource,children:s.jsx(a.Tooltip,{label:"Need to pick a Data Source first",disabled:t.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(uT,{queryModel:t})}),t.typedAsSQL&&s.jsx(a.Tabs.Panel,{value:"SQL",sx:Zn,children:s.jsx(a.Stack,{sx:{height:"100%"},children:s.jsx(vT,{queryModel:t})})}),t.typedAsHTTP&&s.jsx(a.Tabs.Panel,{value:"HTTP",sx:Zn,children:s.jsx(a.Stack,{sx:{height:"100%"},children:s.jsx(xT,{queryModel:t})})}),s.jsx(a.Tabs.Panel,{value:"Data",sx:{...Zn,overflow:"hidden"},children:s.jsx(Lr,{id:t.id,moreActions:null,refreshOnMount:!0})}),s.jsx(a.Tabs.Panel,{value:"Usage",sx:{...Zn,overflow:"hidden"},children:s.jsx(fT,{queryID:t.id,usage:o})})]})}),CT=S.observer(({id:t})=>{const n=X().queries.findByID(t);return t===""?null:n?s.jsx(wT,{queryModel:n}):s.jsx(a.Text,{size:14,color:"red",children:"Invalid Query ID"})}),ST=S.observer(({value:t})=>{const n=oe().payloadForSQL,r=f.useMemo(()=>cs(t,n),[t,n]);return s.jsx($r,{height:"100%",value:r})}),_T=S.observer(({item:t,remove:e,onKeyChanged:n})=>{const[r,i]=f.useState("SQL"),[o,l]=f.useState(t.key),c=()=>{t.setKey(o),n(o)},u=o!==t.key,d=t.isADuplicatedKey(o),[h,p]=f.useState(t.value),x=()=>{t.setValue(h)};f.useEffect(()=>{l(t.key),p(t.value)},[t]);const m=h!==t.value,j=Me.useModals(),C=()=>{j.openConfirmModal({title:"Delete this SQL snippet?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:e,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:C,children:"Delete this SQL Snippet"})]}),s.jsxs(a.Tabs,{value:r,onTabChange:i,sx:{flexGrow:1},styles:{panel:{height:"calc(100% - 50px)"}},children:[s.jsxs(a.Tabs.List,{sx:{position:"relative"},children:[s.jsx(a.Tabs.Tab,{value:"SQL",children:"SQL"}),s.jsx(a.Tabs.Tab,{value:"Preview",children:"Preview"}),s.jsx(Or,{}),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($r,{height:"100%",value:h,onChange:p,defaultLanguage:"sql",theme:"sql-dark"})}),s.jsx(a.Tabs.Panel,{value:"Preview",pt:"sm",children:s.jsx(ST,{value:h})})]})]})}),kT=S.observer(({id:t})=>{const e=U(),n=X(),r=f.useMemo(()=>n.sqlSnippets.findByKey(t),[t]);if(!t)return null;if(!r)return s.jsxs(a.Text,{size:14,children:["SQL Snippet by key[",t,"] is not found"]});const i=()=>{e.editor.setPath(["_SQL_SNIPPETS_",""])},o=()=>{n.sqlSnippets.removeByKey(t),i()},l=c=>{e.editor.setPath(["_SQL_SNIPPETS_",c])};return s.jsx(_T,{item:r,remove:o,onKeyChanged:l})}),TT=S.observer(()=>{const[t,e]=f.useState([]),n=Me.useModals(),r=U(),i=p=>{r.editor.setPath(["_SQL_SNIPPETS_",p])},o=()=>{n.openConfirmModal({title:"Delete ununsed SQL snippets?",children:s.jsx(a.Text,{size:"sm",children:"This action cannot be undone."}),labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>r.content.removeUnusedSQLSnippets(),confirmProps:{color:"red"},zIndex:320})},l=()=>{r.content.sqlSnippets.downloadSchema(t)},c=f.useMemo(()=>r.content.sqlSnippets.sortedList.map(p=>p.key),[r.content.sqlSnippets.sortedList]),u=()=>{e(c)},d=()=>{e([])},h=r.content.sqlSnippetsUsage;return s.jsxs(a.Stack,{sx:{height:"100%"},spacing:"sm",pb:"59px",children:[s.jsx(a.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:s.jsx(a.Text,{px:"md",align:"left",sx:{userSelect:"none",cursor:"default"},children:"Manage SQL Snippets"})}),s.jsxs(a.Flex,{justify:"space-between",align:"center",px:12,children:[s.jsxs(a.Group,{position:"left",children:[s.jsxs(a.Button.Group,{children:[s.jsx(a.Button,{variant:"default",size:"xs",onClick:u,children:"Select All"}),s.jsx(a.Button,{variant:"default",size:"xs",onClick:d,children:"Clear Selection"})]}),s.jsx(a.Button,{size:"xs",color:"blue",leftIcon:s.jsx(k.IconCode,{size:14}),disabled:t.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:t,onChange:e,children:s.jsxs(a.Table,{fontSize:"sm",highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"40px"}}),s.jsx("th",{children:"Key"}),s.jsx("th",{style:{width:"100px",textAlign:"center"},children:"Usage"}),s.jsx("th",{style:{width:"300px",paddingLeft:"24px"},children:"Action"})]})}),s.jsx("tbody",{children:r.content.sqlSnippets.sortedList.map(p=>{var m;const x=((m=h[p.key])==null?void 0:m.length)??0;return s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx(a.Checkbox,{value:p.key,styles:{input:{cursor:"pointer"}}})}),s.jsx("td",{children:p.key}),s.jsx("td",{style:{color:x===0?"#ff0000":"#000",fontWeight:x===0?"bold":"normal",textAlign:"center"},children:x}),s.jsx("td",{children:s.jsx(a.Button,{variant:"subtle",size:"xs",onClick:()=>i(p.key),children:"Open"})})]},p.key)})})]})})})]})}),IT=S.observer(({id:t})=>{const e=Me.useModals(),n=U(),r=X();if(t==="")return null;const i=r.views.findByID(t);if(!i)return s.jsxs(a.Text,{size:14,children:["View by ID[",t,"] is not found"]});const o=()=>{n.editor.setPath(["_VIEWS_",""])},l=()=>{e.openConfirmModal({title:"Delete this view?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.views.removeByID(t),o()},zIndex:320})};return 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(r_,{view:i})})]})});function DT(t){return t.length===1&&t[0]==="_QUERY_VARS_"}function MT(t){return t.length===1&&t[0]==="_MOCK_CONTEXT_"}function AT(t){return t.length===1&&t[0]==="_FILTERS_"}function zT(t){return t.length===2&&t[0]==="_FILTERS_"}function ET(t){return t.length===1&&t[0]==="_SQL_SNIPPETS_"}function PT(t){return t.length===2&&t[0]==="_SQL_SNIPPETS_"}function LT(t){return t.length===2&&t[0]==="_QUERIES_"}function BT(t){return t.length===1&&t[0]==="_QUERIES_"}function OT(t){return t.length===2&&t[0]==="_VIEWS_"}function $T(t){return t.length===4&&t[0]==="_VIEWS_"&&t[2]==="_PANELS_"}const VT=S.observer(()=>s.jsx(a.Stack,{sx:{height:"100%"},p:"sm",children:s.jsx($l,{})})),NT=S.observer(()=>{const t=U().editor,e=t.path;return DT(e)?s.jsx(VT,{}):MT(e)?s.jsx(ok,{}):AT(e)?s.jsx(ak,{}):zT(e)?s.jsx(a.Box,{p:"xs",pl:20,children:s.jsx(ik,{id:e[1]})}):ET(e)?s.jsx(TT,{}):PT(e)?s.jsx(kT,{id:e[1]}):BT(e)?s.jsx(Gk,{}):LT(e)?s.jsx(CT,{id:e[1]}):OT(e)?s.jsx(a.Box,{p:"xs",pl:20,children:s.jsx(IT,{id:e[1]})}):$T(e)?s.jsx(Fk,{viewID:e[1],panelID:e[3]}):s.jsx(a.Box,{children:t.path})}),qT=S.observer(()=>s.jsx(NT,{})),FT=S.observer(()=>{const t=U(),e=()=>{const n=new Date().getTime().toString(),r={id:n,key:n,label:n,order:t.content.filters.current.length+1,type:ce.TextInput,config:Do(),visibleInViewsIDs:["Main"],auto_submit:!1};t.content.filters.append(r),t.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:e,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Filter"})}),GT=S.observer(({parentID:t})=>{const e=X();if(!t)return null;const n=e.views.findByID(t);return!n||n.type===E.Tabs?null:s.jsx(a.Button,{variant:"subtle",leftIcon:s.jsx(k.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:()=>e.addANewPanel(n.id),sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Panel"})}),WT=S.observer(()=>{const t=U(),e=()=>{const n=new Date().getTime().toString(),r={id:n,name:n,type:De.Postgresql,key:"",sql:""};t.content.queries.append(r),t.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:e,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Query"})}),RT=S.observer(()=>{const t=U(),e=()=>{const n=new Date().getTime().toString(),r={key:n,value:""};t.content.sqlSnippets.append(r),t.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:e,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a SQL Snippet"})}),QT=S.observer(()=>{const t=X();return s.jsx(a.Button,{variant:"subtle",leftIcon:s.jsx(k.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a View"})}),YT=S.observer(()=>{const t=U();return s.jsx(a.Button,{variant:"subtle",rightIcon:s.jsx(k.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>t.editor.setPath(["_QUERIES_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:"Manage Queries"})}),KT=S.observer(()=>{const t=U();return s.jsx(a.Button,{variant:"subtle",rightIcon:s.jsx(k.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>t.editor.setPath(["_SQL_SNIPPETS_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:"Manage SQL Snippets"})}),UT=S.observer(()=>{const t=U();return s.jsx(a.Button,{variant:"subtle",rightIcon:s.jsx(k.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>t.editor.setPath(["_FILTERS_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:"Manage Filters"})}),XT=S.observer(({action_type:t,parentID:e})=>t==="_Add_A_Filter_"?s.jsx(FT,{}):t==="_Add_A_SQL_SNIPPET_"?s.jsx(RT,{}):t==="_Add_A_QUERY_"?s.jsx(WT,{}):t==="_Add_A_VIEW_"?s.jsx(QT,{}):t==="_Add_A_PANEL_"?s.jsx(GT,{parentID:e}):t==="_QUERIES_SETTINGS_"?s.jsx(YT,{}):t==="_SQL_SNIPPETS_SETTINGS_"?s.jsx(KT,{}):t==="_FILTERS_SETTINGS_"?s.jsx(UT,{}):null),ql=S.observer(({option:t})=>{var d;const e=U().editor,n=e.isOptionActive,r=n(e.path,t),i=e.isOptionOpened,o=e.navigate,l=i(t),[c,u]=f.useState(l);return f.useEffect(()=>{u(l)},[l]),s.jsx(a.NavLink,{active:r,defaultOpened:l,opened:c,onChange:u,label:t.label,onClick:()=>o(t),icon:t.Icon?s.jsx(t.Icon,{size:18}):null,children:(d=t.children)==null?void 0:d.map(h=>h._type==="ACTION"?s.jsx(XT,{action_type:h._action_type,parentID:h.parentID},`_ADD_${h.value}_`):s.jsx(ql,{option:h},h.value))},t.label)}),JT=S.observer(()=>{const t=U();return s.jsx(a.Box,{sx:{position:"relative"},children:t.editor.navOptions.map(e=>s.jsx(ql,{option:e},e.value))})}),ZT=S.observer(()=>{const t=U();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(JT,{})}),s.jsx(a.Navbar.Section,{children:s.jsx(a.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:s.jsx(a.Button,{size:"xs",color:"red",leftIcon:s.jsx(k.IconX,{size:18}),onClick:()=>t.editor.close(),children:"Close"})})})]})}),HT={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden",minWidth:"calc(var(--mantine-navbar-width, 0px) + 1000px)"},body:{flexGrow:1,nav:{top:0,height:"100vh"}},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:0,height:"100vh"}},eI=S.observer(()=>{const t=U().editor;return s.jsx(a.Modal,{onClose:()=>t.setSettingsOpen(!1),closeOnEscape:!1,closeOnClickOutside:!1,opened:t.settings_open,fullScreen:!0,title:null,transitionProps:{duration:0},withCloseButton:!1,withinPortal:!0,zIndex:300,styles:{body:{padding:"0 !important"},content:{overflowY:"hidden !important"}},children:s.jsx(a.AppShell,{padding:0,navbar:s.jsx(ZT,{}),styles:HT,children:s.jsx(qT,{})})})}),tI=t=>t.replace(/([^:])(\/\/+)/g,"$1/");function nI(t){f.useEffect(()=>{if(me.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const n=tI(t);me.loader.config({paths:{vs:n}}),me.loader.init().then(r=>console.log("monaco instance:",r))},[])}Ea();const sI={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:60+30,height:"100vh"}},rI=({context:t,dashboard:e,content:n,update:r,className:i="dashboard",config:o,onChange:l,headerSlot:c},u)=>{nI(o.monacoPath),us(o);const{data:d=[]}=$.useRequest(ps),{data:h=[]}=$.useRequest(ji),p=f.useMemo(()=>bl(e,n,d,h,t),[e,n]);f.useImperativeHandle(u,()=>p,[p]),jl(p.content,!0),f.useEffect(()=>{p.context.replace(t)},[t]),f.useEffect(()=>{p.datasources.replace(d)},[d]),f.useEffect(()=>{p.globalSQLSnippets.replace(h)},[h]),f.useEffect(()=>W.reaction(()=>W.toJS(p.json),C=>{l==null||l(C)}),[p]);const x=async()=>{await r(p.json,p.content.json)},m=$.useCreation(jr,[]),j=vl(m);return s.jsx(Me.ModalsProvider,{children:s.jsx(ys,{value:{searchButtonProps:o.searchButtonProps},children:s.jsx(fs,{value:p,children:s.jsx(bs,{value:p.content,children:s.jsx(pn.Provider,{value:{inEditMode:!0},children:s.jsx(et.Provider,{value:m,children:s.jsxs(qn,{configure:j,children:[s.jsx(a.AppShell,{padding:0,header:s.jsx(m_,{saveDashboardChanges:x,headerSlot:c}),navbar:s.jsx(W_,{}),styles:sI,children:s.jsx(a.Box,{className:`${i} dashboard-root`,sx:{position:"relative"},children:p.content.views.visibleViews.map(C=>s.jsx(ll,{view:C},C.id))})}),s.jsx(eI,{})]})})})})})})})},iI=S.observer(f.forwardRef(rI)),iD="",Fl=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:Ro,queries:Yo,sqlSnippets:Ko,views:Vo,panels:Go,mock_context:vo}).views(t=>({get json(){return{id:t.id,name:t.name,create_time:t.create_time,update_time:t.update_time,dashboard_id:t.dashboard_id,content:{views:t.views.json,panels:t.panels.json,filters:t.filters.json,version:t.version,definition:{queries:t.queries.json,sqlSnippets:t.sqlSnippets.json,mock_context:t.mock_context.current}}}},get contentJSON(){return this.json.content},get payloadForSQL(){const e=g.getParent(t).context.current,n=g.getParent(t).globalSQLSnippets,r={context:{...t.mock_context.current,...e},filters:t.filters.values};return{...r,sql_snippets:Rn(t.sqlSnippets.current,"key","value",r),global_sql_snippets:Rn(n.list,"id","content",r)}},get payloadForViz(){const e=g.getParent(t).context.current;return{context:{...t.mock_context.current,...e},filters:t.filters.values}},get dashboardState(){return ds(this.payloadForSQL)},getAdditionalQueryInfo(e){return{content_id:t.id,query_id:e,params:this.dashboardState}},get data(){return t.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(e){const n=t.queries.findByID(e);return n?{data:n.data,len:n.data.length,state:n.state,error:n.error}:{data:[],len:0,state:"idle",error:void 0}}})).actions(t=>({}));function aI({id:t,name:e,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:h,sqlSnippets:p,mock_context:x={}}}=o;return Fl.create({id:t,name:e,dashboard_id:n,create_time:r,update_time:i,version:l,filters:Qo(c),queries:QS(h),sqlSnippets:KS(p),mock_context:wo(x),views:PS(u),panels:{list:d}})}const oI=g.types.model({id:g.types.identifier,name:g.types.string,group:g.types.string,content:Fl,content_id:g.types.string,datasources:zS,globalSQLSnippets:Bo,context:Sr});function lI({id:t,name:e,group:n,content_id:r},i,o,l,c){return oI.create({id:t,name:e,group:n,content_id:r,content:aI(i),datasources:{list:o},globalSQLSnippets:{list:l},context:Oo(c)})}Ea();const cI=S.observer(({context:t,dashboard:e,content:n,className:r="dashboard",config:i,fullScreenPanelID:o,setFullScreenPanelID:l})=>{us(i);const{data:c=[]}=$.useRequest(ps),{data:u=[]}=$.useRequest(ji),d=f.useMemo(()=>lI(e,n,c,u,t),[e,n]);jl(d.content,!1),f.useEffect(()=>{d.context.replace(t)},[t]),f.useEffect(()=>{d.datasources.replace(c)},[c]),f.useEffect(()=>{d.globalSQLSnippets.replace(u)},[u]);const h=$.useCreation(jr,[]),p=vl(h);return s.jsx(Me.ModalsProvider,{children:s.jsx(ys,{value:{searchButtonProps:i.searchButtonProps},children:s.jsx(fs,{value:d,children:s.jsx(bs,{value:d.content,children:s.jsx(vs.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:h,children:s.jsx(qn,{configure:p,children:d.content.views.visibleViews.map(x=>s.jsx(Yn,{view:x},x.id))})})})})})})})})})});V.extend(jc),V.extend(vc),V.extend(wc),V.extend(Cc),V.extend(Sc),V.extend(_c),V.extend(kc),V.extend(Tc),V.extend(Ic),V.extend(Dc),V.extend(zc),V.extend(Ec),V.extend(Pc),V.extend(Lc),V.extend(Bc),V.extend(Mc),V.extend(Ac),V.extend(Oc),V.extend($c),V.extend(Vc),V.extend(Nc),V.extend(qc),V.extend(Fc),V.extend(Gc),V.extend(Wc),V.extend(Rc),V.extend(Qc),V.extend(Yc),V.extend(Kc),V.extend(Uc),V.extend(Jc),V.extend(Zc),V.extend(Xc),V.tz.setDefault("UTC");const uI=()=>Promise.resolve().then(()=>_u).then(({version:t})=>(console.log(`[@devtable/dashboard] version: ${t}`),t));w.APIClient=Ue,w.ContentModel=Mr,w.ContentModelContextProvider=bs,w.DashboardApiClient=gi,w.DashboardApiFacadeClient=mi,w.DashboardEditor=iI,w.DashboardFilterType=ce,w.DashboardMode=cl,w.DashboardModel=yl,w.DashboardModelContextProvider=fs,w.DashboardThemeContextProvider=ys,w.DashboardViewEditor=ll,w.DashboardViewRender=Yn,w.DefaultApiClient=fi,w.DescriptionPopover=_r,w.FacadeApiClient=du,w.FiltersModel=dl,w.FullScreenPanel=sl,w.FullScreenPanelContext=vs,w.LayoutStateContext=pn,w.Panel=nl,w.PanelContextProvider=js,w.PanelErrorOrStateMessage=el,w.PanelModel=xl,w.PanelRender=Tr,w.PanelVizSection=kr,w.PanelsModel=fl,w.QueriesModel=pl,w.ReadOnlyDashboard=cI,w.SQLSnippetsModel=hl,w.ViewComponentTypeBackground=ul,w.ViewComponentTypeColor=M1,w.ViewComponentTypeName=D1,w.ViewsModel=gl,w.Viz=Ho,w.applyPartialDashboard=G1,w.configureAPIClient=us,w.createContentModel=ml,w.createDashboardModel=bl,w.facadeApiClient=yi,w.getInitialDashboardViewsModel=Dr,w.getVersion=uI,w.initialDashboardContent=A1,w.useDashboardContext=gs,w.useDashboardThemeContext=Ti,w.useEditContentModelContext=X,w.useEditDashboardContext=U,w.useEditPanelContext=Be,w.useFullScreenPanelContext=zi,w.usePanelFullScreen=rl,w.useRenderContentModelContext=oe,w.useRenderDashboardContext=ms,w.useRenderPanelContext=ut,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
475
+ `)},mT=S.observer(({queryModel:t})=>t.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($r,{}),t.datasource&&s.jsx(Ll,{dataSource:t.datasource})]}),s.jsx(a.Tabs.Panel,{value:"Edit",sx:{position:"relative"},p:"sm",children:s.jsx(xT,{queryModel:t})}),s.jsx(a.Tabs.Panel,{value:"Preview",p:0,pl:4,children:s.jsx(gT,{value:t.sql})}),s.jsx(a.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:s.jsx(en,{label:"",value:t.pre_process,onChange:t.setPreProcess,defaultValue:Vl.pre})}),s.jsx(a.Tabs.Panel,{value:"post_process",p:"sm",children:s.jsx(en,{label:"",value:t.post_process,onChange:t.setPostProcess,defaultValue:Vl.post})})]}):null),Jn={height:"calc(100% - 44px)",padding:0},yT=S.observer(({queryModel:t})=>{const e=X(),n=f.useMemo(()=>t.datasource?t.typedAsHTTP?"HTTP":"SQL":"Configurations",[t.datasource,t.typedAsHTTP]),[r,i]=f.useState(n);f.useEffect(()=>{i(c=>c!=="Configurations"&&n==="Configurations"?"Configurations":c)},[n]);const o=e.findQueryUsage(t.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"}),t.typedAsSQL&&s.jsx(a.Tabs.Tab,{value:"SQL",children:"Request"}),t.typedAsHTTP&&s.jsx(a.Tabs.Tab,{value:"HTTP",children:"Request"}),s.jsx(a.Tabs.Tab,{value:"Data",disabled:!t.datasource,children:s.jsx(a.Tooltip,{label:"Need to pick a Data Source first",disabled:t.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(aT,{queryModel:t})}),t.typedAsSQL&&s.jsx(a.Tabs.Panel,{value:"SQL",sx:Jn,children:s.jsx(a.Stack,{sx:{height:"100%"},children:s.jsx(mT,{queryModel:t})})}),t.typedAsHTTP&&s.jsx(a.Tabs.Panel,{value:"HTTP",sx:Jn,children:s.jsx(a.Stack,{sx:{height:"100%"},children:s.jsx(uT,{queryModel:t})})}),s.jsx(a.Tabs.Panel,{value:"Data",sx:{...Jn,overflow:"hidden"},children:s.jsx(Lr,{id:t.id,moreActions:null,refreshOnMount:!0})}),s.jsx(a.Tabs.Panel,{value:"Usage",sx:{...Jn,overflow:"hidden"},children:s.jsx(dT,{queryID:t.id,usage:o})})]})}),bT=S.observer(({id:t})=>{const n=X().queries.findByID(t);return t===""?null:n?s.jsx(yT,{queryModel:n}):s.jsx(a.Text,{size:14,color:"red",children:"Invalid Query ID"})}),jT=S.observer(({value:t})=>{const n=oe().payloadForSQL,r=f.useMemo(()=>ls(t,n),[t,n]);return s.jsx(Vr,{height:"100%",value:r})}),vT=S.observer(({item:t,remove:e,onKeyChanged:n})=>{const[r,i]=f.useState("SQL"),[o,l]=f.useState(t.key),c=()=>{t.setKey(o),n(o)},u=o!==t.key,d=t.isADuplicatedKey(o),[p,h]=f.useState(t.value),x=()=>{t.setValue(p)};f.useEffect(()=>{l(t.key),h(t.value)},[t]);const m=p!==t.value,j=Me.useModals(),C=()=>{j.openConfirmModal({title:"Delete this SQL snippet?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:e,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:C,children:"Delete this SQL Snippet"})]}),s.jsxs(a.Tabs,{value:r,onTabChange:i,sx:{flexGrow:1},styles:{panel:{height:"calc(100% - 50px)"}},children:[s.jsxs(a.Tabs.List,{sx:{position:"relative"},children:[s.jsx(a.Tabs.Tab,{value:"SQL",children:"SQL"}),s.jsx(a.Tabs.Tab,{value:"Preview",children:"Preview"}),s.jsx($r,{}),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(Vr,{height:"100%",value:p,onChange:h,defaultLanguage:"sql",theme:"sql-dark"})}),s.jsx(a.Tabs.Panel,{value:"Preview",pt:"sm",children:s.jsx(jT,{value:p})})]})]})}),wT=S.observer(({id:t})=>{const e=K(),n=X(),r=f.useMemo(()=>n.sqlSnippets.findByKey(t),[t]);if(!t)return null;if(!r)return s.jsxs(a.Text,{size:14,children:["SQL Snippet by key[",t,"] is not found"]});const i=()=>{e.editor.setPath(["_SQL_SNIPPETS_",""])},o=()=>{n.sqlSnippets.removeByKey(t),i()},l=c=>{e.editor.setPath(["_SQL_SNIPPETS_",c])};return s.jsx(vT,{item:r,remove:o,onKeyChanged:l})}),CT=S.observer(()=>{const[t,e]=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(t)},c=f.useMemo(()=>r.content.sqlSnippets.sortedList.map(h=>h.key),[r.content.sqlSnippets.sortedList]),u=()=>{e(c)},d=()=>{e([])},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:t.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:t,onChange:e,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)})})]})})})]})}),ST=S.observer(({id:t})=>{const e=Me.useModals(),n=K(),r=X();if(t==="")return null;const i=r.views.findByID(t);if(!i)return s.jsxs(a.Text,{size:14,children:["View by ID[",t,"] is not found"]});const o=()=>{n.editor.setPath(["_VIEWS_",""])},l=()=>{e.openConfirmModal({title:"Delete this view?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.views.removeByID(t),o()},zIndex:320})};return 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(H1,{view:i})})]})});function _T(t){return t.length===1&&t[0]==="_QUERY_VARS_"}function kT(t){return t.length===1&&t[0]==="_MOCK_CONTEXT_"}function TT(t){return t.length===1&&t[0]==="_FILTERS_"}function IT(t){return t.length===2&&t[0]==="_FILTERS_"}function DT(t){return t.length===1&&t[0]==="_SQL_SNIPPETS_"}function MT(t){return t.length===2&&t[0]==="_SQL_SNIPPETS_"}function AT(t){return t.length===2&&t[0]==="_QUERIES_"}function zT(t){return t.length===1&&t[0]==="_QUERIES_"}function ET(t){return t.length===2&&t[0]==="_VIEWS_"}function PT(t){return t.length===4&&t[0]==="_VIEWS_"&&t[2]==="_PANELS_"}const LT=S.observer(()=>s.jsx(a.Stack,{sx:{height:"100%"},p:"sm",children:s.jsx(Ol,{})})),BT=S.observer(()=>{const t=K().editor,e=t.path;return _T(e)?s.jsx(LT,{}):kT(e)?s.jsx(nk,{}):TT(e)?s.jsx(tk,{}):IT(e)?s.jsx(a.Box,{p:"xs",pl:20,children:s.jsx(ek,{id:e[1]})}):DT(e)?s.jsx(CT,{}):MT(e)?s.jsx(wT,{id:e[1]}):zT(e)?s.jsx(Vk,{}):AT(e)?s.jsx(bT,{id:e[1]}):ET(e)?s.jsx(a.Box,{p:"xs",pl:20,children:s.jsx(ST,{id:e[1]})}):PT(e)?s.jsx($k,{viewID:e[1],panelID:e[3]}):s.jsx(a.Box,{children:t.path})}),OT=S.observer(()=>s.jsx(BT,{})),$T=S.observer(()=>{const t=K(),e=()=>{const n=new Date().getTime().toString(),r={id:n,key:n,label:n,order:t.content.filters.current.length+1,type:ce.TextInput,config:Mo(),visibleInViewsIDs:["Main"],auto_submit:!1};t.content.filters.append(r),t.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:e,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Filter"})}),VT=S.observer(({parentID:t})=>{const e=X();if(!t)return null;const n=e.views.findByID(t);return!n||n.type===E.Tabs?null:s.jsx(a.Button,{variant:"subtle",leftIcon:s.jsx(k.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:()=>e.addANewPanel(n.id),sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Panel"})}),NT=S.observer(()=>{const t=K(),e=()=>{const n=new Date().getTime().toString(),r={id:n,name:n,type:De.Postgresql,key:"",sql:""};t.content.queries.append(r),t.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:e,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Query"})}),qT=S.observer(()=>{const t=K(),e=()=>{const n=new Date().getTime().toString(),r={key:n,value:""};t.content.sqlSnippets.append(r),t.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:e,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a SQL Snippet"})}),FT=S.observer(()=>{const t=X();return s.jsx(a.Button,{variant:"subtle",leftIcon:s.jsx(k.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a View"})}),GT=S.observer(()=>{const t=K();return s.jsx(a.Button,{variant:"subtle",rightIcon:s.jsx(k.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>t.editor.setPath(["_QUERIES_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:"Manage Queries"})}),WT=S.observer(()=>{const t=K();return s.jsx(a.Button,{variant:"subtle",rightIcon:s.jsx(k.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>t.editor.setPath(["_SQL_SNIPPETS_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:"Manage SQL Snippets"})}),RT=S.observer(()=>{const t=K();return s.jsx(a.Button,{variant:"subtle",rightIcon:s.jsx(k.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>t.editor.setPath(["_FILTERS_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:"Manage Filters"})}),QT=S.observer(({action_type:t,parentID:e})=>t==="_Add_A_Filter_"?s.jsx($T,{}):t==="_Add_A_SQL_SNIPPET_"?s.jsx(qT,{}):t==="_Add_A_QUERY_"?s.jsx(NT,{}):t==="_Add_A_VIEW_"?s.jsx(FT,{}):t==="_Add_A_PANEL_"?s.jsx(VT,{parentID:e}):t==="_QUERIES_SETTINGS_"?s.jsx(GT,{}):t==="_SQL_SNIPPETS_SETTINGS_"?s.jsx(WT,{}):t==="_FILTERS_SETTINGS_"?s.jsx(RT,{}):null),Nl=S.observer(({option:t})=>{var d;const e=K().editor,n=e.isOptionActive,r=n(e.path,t),i=e.isOptionOpened,o=e.navigate,l=i(t),[c,u]=f.useState(l);return f.useEffect(()=>{u(l)},[l]),s.jsx(a.NavLink,{active:r,defaultOpened:l,opened:c,onChange:u,label:t.label,onClick:()=>o(t),icon:t.Icon?s.jsx(t.Icon,{size:18}):null,children:(d=t.children)==null?void 0:d.map(p=>p._type==="ACTION"?s.jsx(QT,{action_type:p._action_type,parentID:p.parentID},`_ADD_${p.value}_`):s.jsx(Nl,{option:p},p.value))},t.label)}),UT=S.observer(()=>{const t=K();return s.jsx(a.Box,{sx:{position:"relative"},children:t.editor.navOptions.map(e=>s.jsx(Nl,{option:e},e.value))})}),YT=S.observer(()=>{const t=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(UT,{})}),s.jsx(a.Navbar.Section,{children:s.jsx(a.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:s.jsx(a.Button,{size:"xs",color:"red",leftIcon:s.jsx(k.IconX,{size:18}),onClick:()=>t.editor.close(),children:"Close"})})})]})}),KT={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"}},XT=S.observer(()=>{const t=K().editor;return s.jsx(a.Modal,{onClose:()=>t.setSettingsOpen(!1),closeOnEscape:!1,closeOnClickOutside:!1,opened:t.settings_open,fullScreen:!0,title:null,transitionProps:{duration:0},withCloseButton:!1,withinPortal:!0,zIndex:300,styles:{body:{padding:"0 !important"},content:{overflowY:"hidden !important"}},children:s.jsx(a.AppShell,{padding:0,navbar:s.jsx(YT,{}),styles:KT,children:s.jsx(OT,{})})})}),JT=t=>t.replace(/([^:])(\/\/+)/g,"$1/");function ZT(t){f.useEffect(()=>{if(ge.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const n=JT(t);ge.loader.config({paths:{vs:n}}),ge.loader.init().then(r=>console.log("monaco instance:",r))},[])}Ea();const HT={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:60+30,height:"100vh"}},eI=({context:t,dashboard:e,content:n,update:r,className:i="dashboard",config:o,onChange:l,headerSlot:c},u)=>{ZT(o.monacoPath),cs(o);const{data:d=[]}=$.useRequest(ds),{data:p=[]}=$.useRequest(vi),h=f.useMemo(()=>jl(e,n,d,p,t),[e,n]);f.useImperativeHandle(u,()=>h,[h]),vl(h.content,!0),f.useEffect(()=>{h.context.replace(t)},[t]),f.useEffect(()=>{h.datasources.replace(d)},[d]),f.useEffect(()=>{h.globalSQLSnippets.replace(p)},[p]),f.useEffect(()=>W.reaction(()=>W.toJS(h.json),C=>{l==null||l(C)}),[h]);const x=async()=>{await r(h.json,h.content.json)},m=$.useCreation(jr,[]),j=wl(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(p_,{saveDashboardChanges:x,headerSlot:c}),navbar:s.jsx(V_,{}),styles:HT,children:s.jsx(a.Box,{className:`${i} dashboard-root`,sx:{position:"relative"},children:h.content.views.visibleViews.map(C=>s.jsx(cl,{view:C},C.id))})}),s.jsx(XT,{})]})})})})})})})},tI=S.observer(f.forwardRef(eI)),tD="",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:Qo,queries:Yo,sqlSnippets:Ko,views:No,panels:Wo,mock_context:wo}).views(t=>({get json(){return{id:t.id,name:t.name,create_time:t.create_time,update_time:t.update_time,dashboard_id:t.dashboard_id,content:{views:t.views.json,panels:t.panels.json,filters:t.filters.json,version:t.version,definition:{queries:t.queries.json,sqlSnippets:t.sqlSnippets.json,mock_context:t.mock_context.current}}}},get contentJSON(){return this.json.content},get payloadForSQL(){const e=g.getParent(t).context.current,n=g.getParent(t).globalSQLSnippets,r={context:{...t.mock_context.current,...e},filters:t.filters.values};return{...r,sql_snippets:Wn(t.sqlSnippets.current,"key","value",r),global_sql_snippets:Wn(n.list,"id","content",r)}},get payloadForViz(){const e=g.getParent(t).context.current;return{context:{...t.mock_context.current,...e},filters:t.filters.values}},get dashboardState(){return us(this.payloadForSQL)},getAdditionalQueryInfo(e){return{content_id:t.id,query_id:e,params:this.dashboardState}},get data(){return t.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(e){const n=t.queries.findByID(e);return n?{data:n.data,len:n.data.length,state:n.state,error:n.error}:{data:[],len:0,state:"idle",error:void 0}}})).actions(t=>({}));function nI({id:t,name:e,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:t,name:e,dashboard_id:n,create_time:r,update_time:i,version:l,filters:Uo(c),queries:qS(p),sqlSnippets:GS(h),mock_context:Co(x),views:DS(u),panels:{list:d}})}const sI=g.types.model({id:g.types.identifier,name:g.types.string,group:g.types.string,content:ql,content_id:g.types.string,datasources:TS,globalSQLSnippets:Oo,context:Sr});function rI({id:t,name:e,group:n,content_id:r},i,o,l,c){return sI.create({id:t,name:e,group:n,content_id:r,content:nI(i),datasources:{list:o},globalSQLSnippets:{list:l},context:$o(c)})}Ea();const iI=S.observer(({context:t,dashboard:e,content:n,className:r="dashboard",config:i,fullScreenPanelID:o,setFullScreenPanelID:l})=>{cs(i);const{data:c=[]}=$.useRequest(ds),{data:u=[]}=$.useRequest(vi),d=f.useMemo(()=>rI(e,n,c,u,t),[e,n]);vl(d.content,!1),f.useEffect(()=>{d.context.replace(t)},[t]),f.useEffect(()=>{d.datasources.replace(c)},[c]),f.useEffect(()=>{d.globalSQLSnippets.replace(u)},[u]);const p=$.useCreation(jr,[]),h=wl(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))})})})})})})})})})});V.extend(bc),V.extend(jc),V.extend(vc),V.extend(wc),V.extend(Cc),V.extend(Sc),V.extend(_c),V.extend(kc),V.extend(Tc),V.extend(Ic),V.extend(Ac),V.extend(zc),V.extend(Ec),V.extend(Pc),V.extend(Lc),V.extend(Dc),V.extend(Mc),V.extend(Bc),V.extend(Oc),V.extend($c),V.extend(Vc),V.extend(Nc),V.extend(qc),V.extend(Fc),V.extend(Gc),V.extend(Wc),V.extend(Rc),V.extend(Qc),V.extend(Uc),V.extend(Yc),V.extend(Xc),V.extend(Jc),V.extend(Kc),V.tz.setDefault("UTC");const aI=()=>Promise.resolve().then(()=>Su).then(({version:t})=>(console.log(`[@devtable/dashboard] version: ${t}`),t));w.APIClient=Ke,w.ContentModel=Mr,w.ContentModelContextProvider=ys,w.DashboardApiClient=mi,w.DashboardApiFacadeClient=yi,w.DashboardEditor=tI,w.DashboardFilterType=ce,w.DashboardMode=ul,w.DashboardModel=bl,w.DashboardModelContextProvider=xs,w.DashboardThemeContextProvider=ms,w.DashboardViewEditor=cl,w.DashboardViewRender=Qn,w.DefaultApiClient=gi,w.DescriptionPopover=_r,w.FacadeApiClient=uu,w.FiltersModel=pl,w.FullScreenPanel=rl,w.FullScreenPanelContext=js,w.LayoutStateContext=pn,w.Panel=sl,w.PanelContextProvider=bs,w.PanelErrorOrStateMessage=tl,w.PanelModel=fl,w.PanelRender=Tr,w.PanelVizSection=kr,w.PanelsModel=gl,w.QueriesModel=hl,w.ReadOnlyDashboard=iI,w.SQLSnippetsModel=xl,w.ViewComponentTypeBackground=dl,w.ViewComponentTypeColor=_1,w.ViewComponentTypeName=S1,w.ViewsModel=ml,w.Viz=el,w.applyPartialDashboard=$1,w.configureAPIClient=cs,w.createContentModel=yl,w.createDashboardModel=jl,w.facadeApiClient=bi,w.getInitialDashboardViewsModel=Dr,w.getVersion=aI,w.initialDashboardContent=k1,w.useDashboardContext=fs,w.useDashboardThemeContext=Ii,w.useEditContentModelContext=X,w.useEditDashboardContext=K,w.useEditPanelContext=Le,w.useFullScreenPanelContext=Ei,w.usePanelFullScreen=il,w.useRenderContentModelContext=oe,w.useRenderDashboardContext=gs,w.useRenderPanelContext=dt,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});