@devtable/dashboard 7.20.3 → 7.21.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.
@@ -21372,7 +21372,7 @@ const Cz = (e) => {
21372
21372
  getColor: ll(["#fff7f1", "darkorange", "#b60000"]),
21373
21373
  name: "orange",
21374
21374
  category: "sequential"
21375
- }, i0 = "@devtable/dashboard", $d = "7.20.3", a0 = "Apache-2.0", s0 = {
21375
+ }, i0 = "@devtable/dashboard", $d = "7.21.0", a0 = "Apache-2.0", s0 = {
21376
21376
  access: "public",
21377
21377
  registry: "https://registry.npmjs.org/"
21378
21378
  }, l0 = [
@@ -29231,12 +29231,7 @@ function E4({
29231
29231
  const {
29232
29232
  value: t,
29233
29233
  set: n
29234
- } = ct(e.instanceData, "config"), r = ce(() => nn({}, t, gl), [t]);
29235
- console.log({
29236
- conf: t,
29237
- defaultValues: r
29238
- });
29239
- const {
29234
+ } = ct(e.instanceData, "config"), r = ce(() => nn({}, t, gl), [t]), {
29240
29235
  control: o,
29241
29236
  handleSubmit: i,
29242
29237
  watch: a,
@@ -34981,9 +34976,9 @@ function ow(e) {
34981
34976
  }
34982
34977
  function iw(e, t) {
34983
34978
  const n = Gg().getRequired(Yt.instanceScope.vizInstance);
34984
- return he(() => n.instanceData.watchItem(null, (r) => {
34979
+ return he(() => (n.instanceData.setItem(null, t.viz.conf), n.instanceData.watchItem(null, (r) => {
34985
34980
  e(r);
34986
- }), [e, t.viz.type]), n;
34981
+ })), [e, t.viz.type]), n;
34987
34982
  }
34988
34983
  function GK({
34989
34984
  setVizConf: e,
@@ -148,7 +148,7 @@ WHERE
148
148
  description?: string;
149
149
  }
150
150
  `,J2=()=>{const[e,t]=x.useState(!1);return b(De,{children:[l(d.Button,{variant:"subtle",compact:!0,onClick:()=>t(n=>!n),children:e?"Close":"Click to see expected data structure"}),l(d.Collapse,{in:e,children:l(Dr.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:Z2})})]})},eL=se.observer(function({config:t}){return b(De,{children:[l(d.TextInput,{label:"Min-width",value:t.min_width,onChange:n=>t.setMinWidth(n.currentTarget.value),placeholder:"200px"}),l(d.Divider,{label:"Fetch options from database",labelPosition:"center"}),l(d.NumberInput,{value:t.default_selection_count,onChange:t.setDefaultSelectionCount,label:"Select first N options by default"}),l(tc,{value:t.options_query_id,onChange:t.setOptionsQueryID}),l(J2,{})]})}),tL=se.observer(function({filter:t}){const n=t.plainDefaultValue,[r,i]=W.default.useState(n);return W.default.useEffect(()=>{!t.usingDefaultValue||i(n)},[n]),b(d.Box,{sx:{maxWidth:"30em"},children:[l(d.Text,{pb:"md",color:"gray",children:"Preview"}),l(Wh,{filter:t,value:r,onChange:i}),l(d.Text,{pt:"lg",pb:"md",color:"gray",children:"Config"}),l(Dr.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(t,null,4)})]})}),nL={select:X2,"multi-select":Y2,"tree-select":eL,"text-input":Q2,checkbox:H2,"date-range":W2},rL=[{label:"Select",value:"select"},{label:"Multi Select",value:"multi-select"},{label:"Tree Select",value:"tree-select"},{label:"Text Input",value:"text-input"},{label:"Checkbox",value:"checkbox"},{label:"Date Range",value:"date-range"}],iL=se.observer(function({filter:t,index:n}){const r=Ze(),i=W.default.useMemo(()=>nL[t.type],[t.type]);return b(d.SimpleGrid,{cols:2,children:[b(d.Box,{pl:"md",children:[l(d.Text,{pb:"md",color:"gray",children:"Edit"}),b(d.Stack,{sx:{maxWidth:"30em"},children:[b(d.Group,{noWrap:!0,children:[l(d.NumberInput,{label:"Placement Order",required:!0,value:t.order,onChange:t.setOrder,hideControls:!0,sx:{flexGrow:"1 !important"}}),t.auto_submit_supported&&l(d.Checkbox,{label:"Submit automatically",checked:t.auto_submit,onChange:o=>t.setAutoSubmit(o.currentTarget.checked),mt:22})]}),l(d.MultiSelect,{label:"Visible in...",data:r.views.options,value:[...t.visibleInViewsIDs],onChange:t.setVisibleInViewsIDs}),l(d.TextInput,{label:"Key",placeholder:"A unique key to refer",required:!0,value:t.key,onChange:o=>{t.setKey(o.currentTarget.value)}}),l(d.TextInput,{label:"Label",placeholder:"Label for this field",required:!0,value:t.label,onChange:o=>{t.setLabel(o.currentTarget.value)}}),l(d.Select,{label:"Widget",data:rL,required:!0,value:t.type,onChange:t.setType}),l(i,{config:t.config,index:n})]})]}),l(tL,{filter:t})]})}),qj="",oL=se.observer(function(){const t=Ze(),n=t.filters.current,r=()=>{const i=wt.randomId(),o={id:i,key:i,label:i,order:n.length+1,type:Ht.TextInput,config:Gm(),visibleInViewsIDs:["Main"],auto_submit:!1};t.filters.append(o)};return b(d.Box,{sx:{height:"90vh",maxHeight:"calc(100vh - 185px)"},p:0,children:[l(d.Group,{sx:{position:"absolute",top:"16px",right:"16px"},children:l(d.Button,{size:"xs",color:"red",leftIcon:l(te.Recycle,{size:20}),disabled:!t.filtersChanged,onClick:t.resetFilters,children:"Revert Changes"})}),l(d.Tabs,{className:"filter-settings-tabs",orientation:"vertical",defaultValue:t.filters.firstID,styles:{root:{display:"block"}},keepMounted:!1,children:b(d.Group,{sx:{height:"100%"},children:[b(d.Stack,{sx:{height:"100%"},children:[l(d.Button,{size:"xs",color:"blue",leftIcon:l(te.PlaylistAdd,{size:20}),onClick:r,children:"Add a Filter"}),l(d.Tabs.List,{position:"left",sx:{flexGrow:1,width:"200px"},children:t.filters.current.map(i=>l(d.Tabs.Tab,{value:i.id,sx:{maxWidth:"100%",overflow:"auto"},children:i.label},i.id))})]}),l(d.Box,{sx:{flexGrow:1,height:"100%"},children:t.filters.current.map((i,o)=>l(d.Tabs.Panel,{value:i.id,sx:{height:"100%"},children:b(d.Stack,{sx:{height:"100%"},spacing:"sm",children:[l(d.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:l(iL,{filter:i,index:o})}),l(d.Group,{position:"right",pt:10,children:l(d.Button,{size:"xs",color:"red",leftIcon:l(te.Trash,{size:20}),onClick:()=>t.filters.remove(o),children:"Delete this filter"})})]})},i.id))})]})})]})}),aL=se.observer(function({opened:t,close:n}){const{freezeLayout:r}=W.default.useContext(_n);return W.default.useEffect(()=>{r(t)},[t]),l(d.Modal,{size:"96vw",overflow:"inside",opened:t,onClose:n,title:"Filters",trapFocus:!0,onDragStart:i=>{i.stopPropagation()},withCloseButton:!1,children:l(oL,{})})}),sL=se.observer(()=>{const t=Ze().views.VIE;return!t||t.type!==Ye.Division?null:b(d.Stack,{children:[l(d.Divider,{mt:8,mb:0,label:"Division settings",labelPosition:"center"}),l(d.Text,{align:"center",size:"xs",color:"dimmed",children:"Under construction"})]})}),lL=[{value:"default",label:"Default"},{value:"outline",label:"Outline"},{value:"pills",label:"Pills"}],uL=[{value:"horizontal",label:"Horizontal"},{value:"vertical",label:"Vertical"}],cL=se.observer(()=>{const t=Ze().views.VIE;if(!t||t.type!==Ye.Tabs)return null;const n=t.config;return b(d.Stack,{children:[l(d.Divider,{mt:8,mb:0,label:"Tabs settings",labelPosition:"center"}),l(d.Select,{label:"Variant",value:n.variant,onChange:n.setVariant,data:lL}),l(d.Select,{label:"Orientation",value:n.orientation,onChange:n.setOrientation,data:uL}),l(d.Switch,{label:"Grow Tabs",checked:n.grow,onChange:r=>n.setGrow(r.currentTarget.checked)})]})}),dL=({disabled:e,value:t,onChange:n})=>{const r=i=>{!i||n(i)};return b(d.Box,{sx:{position:"relative"},children:[e&&l(d.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),l(Pn.default,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1,readOnly:e}}})]})},nc={enabled:!1,func_content:["function text({ filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
151
- `)},fL=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:i}]=nt.useBoolean(),[o,a]=x.useState(e!=null?e:nc),s=p=>{a({...o,enabled:p})},u=()=>{i();const{enabled:p,func_content:g}=o,v={enabled:p,func_content:g};a(v),t(v)},c=()=>{i(),a(e)},f=p=>{a(g=>({...g,func_content:p}))},h=()=>{f(nc.func_content)};return b(De,{children:[l(d.ActionIcon,{size:"lg",color:"blue",variant:"filled",mt:26,onClick:r,sx:{flexGrow:0},children:l(te.Settings,{size:14})}),l(d.Modal,{size:800,title:"Customize modal title",opened:n,onClose:i,closeOnClickOutside:!1,withCloseButton:!1,children:n&&b(d.Stack,{children:[l(d.Checkbox,{mt:10,label:"Enabled",checked:o.enabled,onChange:p=>s(p.currentTarget.checked)}),l(dL,{value:o.func_content,onChange:f,disabled:!o.enabled}),b(d.Group,{position:"apart",children:[l(d.Button,{onClick:h,color:"red",leftIcon:l(te.Recycle,{size:20}),children:"Rest"}),b(d.Group,{position:"right",children:[l(d.Button,{onClick:c,variant:"subtle",children:"Cancel"}),l(d.Button,{onClick:u,children:"OK"})]})]})]})})]})},pL=se.observer(()=>{const t=Ze().views.VIE;if(!t||t.type!==Ye.Modal)return null;const n=t.config,r=n.custom_modal_title.value;return b(d.Stack,{children:[l(d.Divider,{mt:8,label:"Modal settings",labelPosition:"center"}),b(d.Flex,{gap:10,children:[l(d.TextInput,{label:"Modal Title",value:r,onChange:ye.default.noop,disabled:!0,sx:{flexGrow:1}}),l(fL,{value:n.custom_modal_title,onChange:n.custom_modal_title.replace})]}),b(d.Group,{grow:!0,children:[l(d.TextInput,{label:"Width",value:n.width,onChange:i=>n.setWidth(i.currentTarget.value),placeholder:"600px / 50vw"}),l(d.TextInput,{label:"Height",value:n.height,onChange:i=>n.setHeight(i.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),hL=se.observer(()=>b(De,{children:[l(sL,{}),l(pL,{}),l(cL,{})]})),gL=[{label:"Division",value:Ye.Division},{label:"Modal",value:Ye.Modal},{label:"Tabs",value:Ye.Tabs}],vL=se.observer(()=>{const t=Ze().views.VIE;return t?b(d.Stack,{sx:{position:"relative"},children:[l(d.TextInput,{label:"Name",value:t.name,onChange:n=>{t.setName(n.currentTarget.value)}}),l(d.Select,{label:"Type",withinPortal:!0,value:t.type,onChange:t.setType,data:gL}),l(hL,{})]}):null}),mL=se.observer(({opened:e,close:t})=>{var i;const n=Ze(),{freezeLayout:r}=W.default.useContext(_n);return W.default.useEffect(()=>{r(e)},[e]),l(d.Modal,{size:"500px",overflow:"inside",opened:e,onClose:t,withCloseButton:!1,styles:{header:{width:"100%"},title:{width:"100%"}},title:b(d.Group,{position:"apart",children:[b(d.Text,{sx:{flexGrow:1},children:["Editing ",(i=n.views.VIE)==null?void 0:i.name]}),l(d.ActionIcon,{size:18,color:"red",onClick:n.views.removeVIE,disabled:n.views.isVIETheFirstView,children:l(te.Trash,{size:18})})]}),trapFocus:!0,onDragStart:o=>{o.stopPropagation()},children:l(vL,{})})}),yL=x.forwardRef(({label:e,type:t,...n},r)=>t!=="TRIGGER_TO_ADD"?l("div",{ref:r,...n,children:b(d.Group,{noWrap:!0,position:"apart",children:[l(d.Text,{size:"sm","data-role":"label",children:e}),l(d.Text,{size:"xs",color:"dimmed","data-role":"description",children:t})]})}):l("div",{ref:r,...n,children:l(d.Group,{noWrap:!0,grow:!0,children:l(d.Text,{size:"sm",align:"center",color:"#228be6",children:e})})})),Km="TRIGGER_TO_ADD",bL=se.observer(({value:e,onChange:t,triggerAdd:n,triggerEdit:r,options:i})=>{const o=x.useMemo(()=>[...i,{label:"Add a View",value:Km,type:"TRIGGER_TO_ADD"}],[i,n]),a=s=>{s!==Km?t(s):n()};return b(d.Flex,{gap:0,sx:{minWidth:"400px"},children:[l(d.Select,{value:e,onChange:a,placeholder:"Pick a View",itemComponent:yL,data:o,nothingFound:"Empty",sx:{flexGrow:1,".mantine-Select-item[data-selected] .mantine-Text-root[data-role=description]":{color:"rgba(255,255,255,.7)"}},styles:{input:{borderTopRightRadius:0,borderBottomRightRadius:0}}}),l(d.ActionIcon,{onClick:r,variant:"default",size:36,sx:{borderLeft:0,borderTopLeftRadius:0,borderBottomLeftRadius:0,"&:active":{transform:"none",svg:{transform:"translateY(1px)"}}},children:l(te.Settings,{size:20})})]})}),wL=se.observer(()=>{const e=Ze(),[t,n]=x.useState(!1),r=()=>{n(!0)},i=()=>{n(!1)};return b(De,{children:[l(bL,{value:e.views.idOfVIE,onChange:e.views.setIDOfVIE,triggerAdd:e.views.addARandomNewView,triggerEdit:r,options:e.views.options}),l(mL,{opened:t,close:i})]})}),Hm={"> 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}}},qm=se.observer(function({saveChanges:t,inUseMode:n}){const r=Ze(),i=W.default.useCallback(()=>{const S=r.queries.json,E=r.views.json,M=r.sqlSnippets.json,A=r.filters.current,L=r.mock_context.current;return{filters:A,views:E,definition:{sqlSnippets:M,queries:S,mock_context:L},version:r.version}},[r]),o=()=>{r.reset()},a=r.changed,[s,u]=W.default.useState(!1),c=()=>u(!0),f=()=>u(!1),[h,p]=W.default.useState(!1),g=()=>p(!0),v=()=>p(!1),[m,w]=W.default.useState(!1),y=()=>w(!0),_=()=>w(!1),C=()=>{const S=JSON.stringify(i(),null,2);$$(r.name,S)};return n?null:b(d.Group,{position:"apart",pt:0,px:10,pb:"xs",children:[l(d.Group,{position:"left",children:l(wL,{})}),b(d.Group,{position:"right",sx:{button:{minWidth:"40px"}},children:[l(d.Button,{variant:"filled",size:"xs",disabled:!r.views.VIE,onClick:r.views.addAPanelToVIE,leftIcon:l(te.PlaylistAdd,{size:20}),children:"Add a Panel"}),b(d.Group,{spacing:0,sx:Hm,children:[l(d.Tooltip,{label:"Filters",children:l(d.ActionIcon,{variant:"default",size:"md",onClick:g,children:l(te.Filter,{size:20})})}),l(d.Tooltip,{label:"Data Settings",children:l(d.ActionIcon,{variant:"default",size:"md",onClick:c,children:l(te.Database,{size:20})})}),l(d.Tooltip,{label:"Interactions Viewer",children:l(d.ActionIcon,{variant:"default",size:"md",onClick:y,children:l(te.Link,{size:20})})})]}),b(d.Group,{spacing:0,sx:Hm,children:[l(d.Tooltip,{label:"Save Changes",children:l(d.ActionIcon,{variant:"default",size:"md",onClick:t,disabled:!a,children:l(te.DeviceFloppy,{size:20,color:"green"})})}),l(d.Tooltip,{label:"Revert Changes",children:l(d.ActionIcon,{variant:"default",size:"md",disabled:!a,onClick:o,children:l(te.Recycle,{size:20,color:"red"})})})]}),b(d.Menu,{width:180,trigger:"hover",children:[l(d.Menu.Target,{children:l(d.ActionIcon,{variant:"default",size:"md",children:l(te.Share,{size:20})})}),b(d.Menu.Dropdown,{children:[l(d.Menu.Item,{icon:l(te.Download,{size:14}),onClick:r.queries.downloadAllData,children:"Download Data"}),l(d.Menu.Item,{icon:l(te.Code,{size:14}),onClick:C,children:"Download Schema"})]})]})]}),l(aL,{opened:h,close:v}),l(K2,{opened:s,close:f}),l(N$,{opened:m,close:_})]})}),Wj="",Wm=Qt.Mark.create({name:"textStyle",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"span",getAttrs:e=>e.hasAttribute("style")?{}:!1}]},renderHTML({HTMLAttributes:e}){return["span",Qt.mergeAttributes(this.options.HTMLAttributes,e),0]},addCommands(){return{removeEmptyTextStyle:()=>({state:e,commands:t})=>{const n=Qt.getMarkAttributes(e,this.type);return Object.entries(n).some(([,i])=>!!i)?!0:t.unsetMark(this.name)}}}}),Um=Qt.Extension.create({name:"color",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{color:{default:null,parseHTML:e=>{var t;return(t=e.style.color)===null||t===void 0?void 0:t.replace(/['"]+/g,"")},renderHTML:e=>e.color?{style:`color: ${e.color}`}:{}}}}]},addCommands(){return{setColor:e=>({chain:t})=>t().setMark("textStyle",{color:e}).run(),unsetColor:()=>({chain:e})=>e().setMark("textStyle",{color:null}).removeEmptyTextStyle().run()}}}),xL=/(?:^|\s)((?:==)((?:[^~=]+))(?:==))$/,SL=/(?:^|\s)((?:==)((?:[^~=]+))(?:==))/g,Ym=Qt.Mark.create({name:"highlight",addOptions(){return{multicolor:!1,HTMLAttributes:{}}},addAttributes(){return this.options.multicolor?{color:{default:null,parseHTML:e=>e.getAttribute("data-color")||e.style.backgroundColor,renderHTML:e=>e.color?{"data-color":e.color,style:`background-color: ${e.color}; color: inherit`}:{}}}:{}},parseHTML(){return[{tag:"mark"}]},renderHTML({HTMLAttributes:e}){return["mark",Qt.mergeAttributes(this.options.HTMLAttributes,e),0]},addCommands(){return{setHighlight:e=>({commands:t})=>t.setMark(this.name,e),toggleHighlight:e=>({commands:t})=>t.toggleMark(this.name,e),unsetHighlight:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-h":()=>this.editor.commands.toggleHighlight()}},addInputRules(){return[Qt.markInputRule({find:xL,type:this.type})]},addPasteRules(){return[Qt.markPasteRule({find:SL,type:this.type})]}}),Xm=Qt.Extension.create({name:"placeholder",addOptions(){return{emptyEditorClass:"is-editor-empty",emptyNodeClass:"is-empty",placeholder:"Write something \u2026",showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){return[new r0.Plugin({props:{decorations:({doc:e,selection:t})=>{const n=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:r}=t,i=[];if(!n)return null;const o=e.type.createAndFill(),a=(o==null?void 0:o.sameMarkup(e))&&o.content.findDiffStart(e.content)===null;return e.descendants((s,u)=>{const c=r>=u&&r<=u+s.nodeSize,f=!s.isLeaf&&!s.childCount;if((c||!this.options.showOnlyCurrent)&&f){const h=[this.options.emptyNodeClass];a&&h.push(this.options.emptyEditorClass);const p=Wc.Decoration.node(u,u+s.nodeSize,{class:h.join(" "),"data-placeholder":typeof this.options.placeholder=="function"?this.options.placeholder({editor:this.editor,node:s,pos:u,hasAnchor:c}):this.options.placeholder});i.push(p)}return this.options.includeChildren}),Wc.DecorationSet.create(e,i)}}})]}}),Qm=Qt.Mark.create({name:"subscript",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"sub"},{style:"vertical-align",getAttrs(e){return e!=="sub"?!1:null}}]},renderHTML({HTMLAttributes:e}){return["sub",Qt.mergeAttributes(this.options.HTMLAttributes,e),0]},addCommands(){return{setSubscript:()=>({commands:e})=>e.setMark(this.name),toggleSubscript:()=>({commands:e})=>e.toggleMark(this.name),unsetSubscript:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-,":()=>this.editor.commands.toggleSubscript()}}}),Zm=Qt.Mark.create({name:"superscript",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"sup"},{style:"vertical-align",getAttrs(e){return e!=="super"?!1:null}}]},renderHTML({HTMLAttributes:e}){return["sup",Qt.mergeAttributes(this.options.HTMLAttributes,e),0]},addCommands(){return{setSuperscript:()=>({commands:e})=>e.setMark(this.name),toggleSuperscript:()=>({commands:e})=>e.toggleMark(this.name),unsetSuperscript:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-.":()=>this.editor.commands.toggleSuperscript()}}}),Jm=Qt.Extension.create({name:"textAlign",addOptions(){return{types:[],alignments:["left","center","right","justify"],defaultAlignment:"left"}},addGlobalAttributes(){return[{types:this.options.types,attributes:{textAlign:{default:this.options.defaultAlignment,parseHTML:e=>e.style.textAlign||this.options.defaultAlignment,renderHTML:e=>e.textAlign===this.options.defaultAlignment?{}:{style:`text-align: ${e.textAlign}`}}}}]},addCommands(){return{setTextAlign:e=>({commands:t})=>this.options.alignments.includes(e)?this.options.types.every(n=>t.updateAttributes(n,{textAlign:e})):!1,unsetTextAlign:()=>({commands:e})=>this.options.types.every(t=>e.resetAttributes(t,"textAlign"))}},addKeyboardShortcuts(){return{"Mod-Shift-l":()=>this.editor.commands.setTextAlign("left"),"Mod-Shift-e":()=>this.editor.commands.setTextAlign("center"),"Mod-Shift-r":()=>this.editor.commands.setTextAlign("right"),"Mod-Shift-j":()=>this.editor.commands.setTextAlign("justify")}}}),ey=Qt.Mark.create({name:"underline",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"u"},{style:"text-decoration",consuming:!1,getAttrs:e=>e.includes("underline")?{}:!1}]},renderHTML({HTMLAttributes:e}){return["u",Qt.mergeAttributes(this.options.HTMLAttributes,e),0]},addCommands(){return{setUnderline:()=>({commands:e})=>e.setMark(this.name),toggleUnderline:()=>({commands:e})=>e.toggleMark(this.name),unsetUnderline:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-u":()=>this.editor.commands.toggleUnderline(),"Mod-U":()=>this.editor.commands.toggleUnderline()}}}),rc={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"}}},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:'"\u25BA"',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"}},ty=({value:e,styles:t={}})=>{const n=Uc.useEditor({extensions:[Xc.default,ey,rt.Link,Zm,Qm,Ym,Jm.configure({types:["heading","paragraph"]}),Xm.configure({placeholder:"This is placeholder"}),Wm,Um],content:e,editable:!1}),r=x.useMemo(()=>ye.default.defaultsDeep({},{content:rc},t),[t]);return l(rt.RichTextEditor,{editor:n,styles:r,children:l(rt.RichTextEditor.Content,{})})};function CL(e){return e?["<p><br></p>","<p></p>"].includes(e):!0}const ny=se.observer(()=>{const{freezeLayout:e}=W.default.useContext(_n),[t,n]=W.default.useState(!1),{panel:r}=jt();return W.default.useEffect(()=>{e(t)},[t]),CL(r.description)?null:b(De,{children:[l(d.Modal,{opened:t,onClose:()=>n(!1),title:r.title,withCloseButton:!1,children:l(ty,{value:r.description,styles:{root:{border:"none"},content:{padding:0}}})}),l(d.Tooltip,{label:"Click to see description",position:"top-start",withinPortal:!0,children:l(d.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>n(i=>!i),sx:{verticalAlign:"baseline",cursor:"pointer"},children:l(te.InfoCircle,{size:20})})})]})}),ry=e=>{const{title:t="Variables",variables:n}=e,r=wt.useClipboard(),i=o=>{r.copy(o),Po.showNotification({color:"green",message:"Copied to clipboard"})};return b(d.Paper,{withBorder:!0,p:"sm",children:[l(d.Text,{size:"xs",color:"dimmed",mb:"sm",children:t}),l(d.Stack,{style:{maxHeight:"500px"},children:n.map(o=>b(d.Text,{size:"sm",children:[b(d.Code,{color:"teal",children:["// ",o.description]}),l("br",{}),b(d.Code,{onClick:()=>i(o.name),style:{cursor:"pointer"},children:[o.name," : ",o.valueType]})]},o.name))})]})};class _L{constructor(t,n){ke(this,"operationId");ke(this,"operation");ke(this,"operationSchema");ke(this,"variables",[]);this.operationManager=t,this.instance=n,zt.makeAutoObservable(this)}get schemaList(){return this.operationManager.getOperationSchemaList()}async configOperation(t,n){const r=await this.operationManager.retrieveTrigger(t),i=this.operationManager.getOperationSchemaList().find(o=>o.id===(r==null?void 0:r.schemaRef));zt.runInAction(()=>{this.operationId=t,this.operation=r,this.operationSchema=i,this.variables=n})}async changeSchema(t){this.operationId&&(await this.operationManager.createOrGetOperation(this.operationId,t),await this.configOperation(this.operationId,this.variables))}}function EL(e){return!!e.operationId}const TL=se.observer(({model:e,onClick:t})=>{var r;const n=(r=e.operationSchema)==null?void 0:r.displayName;return l(d.Button,{variant:"outline",onClick:t,children:n})}),ML=se.observer(({model:e})=>{const t={operation:e.operation,instance:e.instance,variables:[]};return x.createElement(e.operationSchema.configRender,t)});function OL({model:e}){const t=e.schemaList,n=t.map(i=>({label:i.displayName,value:i.id}));async function r(i){await e.changeSchema(t.find(o=>o.id===i))}return l(d.Select,{label:"Operation",data:n,onChange:r,value:e.operationSchema.id})}const DL=se.observer(e=>{const[t,{setTrue:n,setFalse:r}]=nt.useBoolean(!1),{operationManager:i,operationId:o,instance:a,variables:s}=e,u=nt.useCreation(()=>new _L(i,a),[i,a]);return nt.useAsyncEffect(async()=>{await u.configOperation(o,s)},[o,u]),EL(u)?b(De,{children:[l(TL,{model:u,onClick:n}),l(d.Modal,{size:600,opened:t,onClose:r,title:"Operation Settings",closeButtonLabel:"close",children:b(d.Stack,{children:[l(OL,{model:u}),l(ML,{model:u}),l(ry,{title:"Variables",variables:u.variables})]})})]}):null});class RL{constructor(t,n){ke(this,"triggerId");ke(this,"trigger");ke(this,"triggerSchema");ke(this,"sampleData");this.triggerManager=t,this.instance=n,zt.makeAutoObservable(this)}get schemaList(){return this.triggerManager.getTriggerSchemaList()}async configTrigger(t,n){const r=await this.triggerManager.retrieveTrigger(t),i=this.triggerManager.getTriggerSchemaList().find(o=>o.id===(r==null?void 0:r.schemaRef));zt.runInAction(()=>{this.triggerId=t,this.trigger=r,this.triggerSchema=i,this.sampleData=n})}async changeSchema(t){this.triggerId&&(await this.triggerManager.createOrGetTrigger(this.triggerId,t),await this.configTrigger(this.triggerId,this.sampleData))}isReady(){return kL(this)}}function kL(e){return!!e.triggerId&&!!e.triggerSchema}function AL(e,t){return nt.useCreation(()=>new RL(e,t),[e,t])}const PL=se.observer(({model:e,onClick:t})=>{const n=e.triggerSchema.nameRender,r={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return l(d.Button,{variant:"outline",onClick:t,children:x.createElement(n,r)})}),NL=se.observer(({model:e})=>{const t=e.schemaList,n=t.map(i=>({label:i.displayName,value:i.id}));async function r(i){await e.changeSchema(t.find(o=>o.id===i))}return l(d.Select,{label:"Trigger",data:n,value:e.triggerSchema.id,onChange:r})}),IL=se.observer(({model:e})=>{const t={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return x.createElement(e.triggerSchema.configRender,t)}),$L=se.observer(e=>{const[t,{setTrue:n,setFalse:r}]=nt.useBoolean(!1),i=e.model;return b(De,{children:[l(d.Modal,{opened:t,onClose:r,title:"Setup Trigger",closeButtonLabel:"close setup",children:b(d.Stack,{children:[l(NL,{model:i}),l(IL,{model:i}),l(ry,{title:"Payload",variables:i.triggerSchema.payload})]})}),l(PL,{onClick:n,model:i})]})});class Mi{constructor(t,n){this.root=t,this.path=n}async deleteItem(t){t===null&&await this.root.deleteItem(this.path);const n=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,H.omit(n,t))}async getItem(t){const n=await this.root.getItem(this.path);return t===null?n:H.get(n,t)}async setItem(t,n){if(t===null)await this.root.setItem(this.path,n);else{const r=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,{...r,[t]:n})}return await this.getItem(t)}watchItem(t,n,r){return t===null?this.root.watchItem(this.path,(i,o)=>{n(i,o)},r):this.root.watchItem(this.path,(i,o)=>{const a=H.get(i,t),s=H.get(o,t);a!==s&&n(a,s)},r)}}class ic{constructor(t,n,r){ke(this,"attachmentStorage");this.instance=t,this.attachmentKey=n,this.constructInstance=r,this.attachmentStorage=new Mi(t.instanceData,n)}async getInstance(t){if(await this.attachmentStorage.getItem(t))return this.constructInstance(new Mi(this.attachmentStorage,t))}async create(t,n){return await this.attachmentStorage.setItem(t,n),this.constructInstance(new Mi(this.attachmentStorage,t))}async remove(t){await this.attachmentStorage.deleteItem(t)}async list(){const t=await this.attachmentStorage.getItem(null);return Promise.all(H.values(t).map(n=>this.constructInstance(new Mi(this.attachmentStorage,n.id))))}}class iy{constructor(t){ke(this,"rootRef");this.rootRef=zt.observable({current:t})}async deleteItem(t){zt.runInAction(()=>{H.unset(this.rootRef.current,[t])})}getItem(t){const n=this.getValueFromRoot(t);return Promise.resolve(n)}getValueFromRoot(t){return t===null?zt.toJS(this.rootRef.current):H.get(this.rootRef.current,[t])}setItem(t,n){if(t===null)if(H.isObject(n))zt.runInAction(()=>{this.rootRef.current=n});else throw new Error("Cannot set root value to non-object");else zt.runInAction(()=>{H.set(this.rootRef.current,[t],n)});return Promise.resolve(this.getItem(t))}watchItem(t,n,r){return zt.reaction(()=>this.getValueFromRoot(t),(i,o)=>{n(i,o)},{requiresObservable:!0,fireImmediately:H.get(r,"fireImmediately",!1)})}}class LL{constructor(){ke(this,"channels",new Map);ke(this,"globalChannel",new Qc.default)}getChannel(t){const n=this.channels.get(t);if(n)return n;const r=new Qc.default;return this.channels.set(t,r),r}}class VL{constructor(t){ke(this,"instances",new Map);this.pluginManager=t}get availableVizList(){return this.pluginManager.installedPlugins.flatMap(t=>t.manifest.viz)}resolveComponent(t){return this.pluginManager.factory.viz(t)}getOrCreateInstance(t){const n=this.instances.get(t.id);if(n)return n;const r={id:t.id,name:t.viz.type,type:t.viz.type,messageChannels:new LL,instanceData:new iy(t.viz.conf)};return this.instances.set(t.id,r),r}}function oy(e,t,n,r){return{vizManager:n,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new iy({}),colorPalette:{getColor(){return()=>""}},data:t,variables:r}}const zL=e=>{const{panel:t,vizManager:n,data:r,variables:i}=e,o=n.resolveComponent(t.viz.type),a=n.getOrCreateInstance(t),s={...oy(a,r,n,i),viewport:{width:t.layout.w,height:t.layout.h}},u=o.viewRender;return l(u,{context:s,instance:a,...H.omit(e,["panel","vizManager","data"])})},FL=e=>{const{vizManager:t,panel:n,panelInfoEditor:r,data:i,variables:o}=e,a=t.resolveComponent(n.viz.type),s=t.getOrCreateInstance(n),u={...oy(s,i,t,o),panelInfoEditor:r},c=a.configRender;return l(c,{context:u,instance:s,...H.omit(e,["panel","vizManager","data","panelInfoEditor"])})},ay=(e,t)=>{const n=Ni.default.bezier(e),r=Ni.default.bezier(t);return function(i){return i<50?n(i*2/100).hex():r((i-50)*2/100).hex()}},rs=e=>{const t=Ni.default.bezier(e);return function(n){return t(n/100).hex()}},BL={type:"interpolation",displayName:"Red / Green",getColor:ay(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},GL={type:"interpolation",displayName:"Yellow / Blue",getColor:ay(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},jL={type:"interpolation",displayName:"Red",getColor:rs(["#fff7f1","darkred"]),name:"red",category:"sequential"},KL={type:"interpolation",displayName:"Green",getColor:rs(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},HL={type:"interpolation",displayName:"Blue",getColor:rs(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},qL={type:"interpolation",displayName:"Orange",getColor:rs(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"},sy="@devtable/dashboard",oc="7.20.3",ly="Apache-2.0",uy={access:"public",registry:"https://registry.npmjs.org/"},cy=["dist"],dy="./dist/dashboard.umd.js",fy="./dist/dashboard.es.js",py="./dist/index.d.ts",hy={".":{import:"./dist/dashboard.es.js",require:"./dist/dashboard.umd.js"},"./dist/style.css":{import:"./dist/style.css",require:"./dist/style.css"}},gy={"dev-build":"tsc && vite build --watch",build:"tsc && vite build",preview:"vite preview",test:"vitest","test:ui":"vitest --ui",coverage:"vitest --coverage"},vy={"@monaco-editor/react":"4.4.6","@types/chroma-js":"^2.1.4","file-saver":"2.0.5","performant-array-to-tree":"1.11.0",popmotion:"^11.0.3","rc-tree-select":"5.5.5",reactflow:"^11.5.3"},my={"@mantine/core":"5.9.5","@mantine/dates":"5.9.5","@mantine/form":"5.9.5","@mantine/hooks":"5.9.5","@mantine/modals":"5.9.5","@mantine/notifications":"5.9.5","@mantine/prism":"5.9.5","@mantine/tiptap":"5.9.5","@tabler/icons":"^1.118.0","@testing-library/cypress":"^8.0.3","@testing-library/jest-dom":"^5.16.4","@testing-library/react":"^13.3.0","@testing-library/react-hooks":"^8.0.1","@testing-library/user-event":"^14.3.0","@tiptap/extension-code-block-lowlight":"^2.0.0-beta.209","@tiptap/extension-color":"^2.0.0-beta.209","@tiptap/extension-highlight":"^2.0.0-beta.209","@tiptap/extension-link":"^2.0.0-beta.209","@tiptap/extension-placeholder":"^2.0.0-beta.209","@tiptap/extension-subscript":"^2.0.0-beta.209","@tiptap/extension-superscript":"^2.0.0-beta.209","@tiptap/extension-text-align":"^2.0.0-beta.209","@tiptap/extension-text-style":"^2.0.0-beta.209","@tiptap/extension-underline":"^2.0.0-beta.209","@tiptap/react":"^2.0.0-beta.209","@tiptap/starter-kit":"^2.0.0-beta.209","@types/crypto-js":"v4.1.1","@types/d3-array":"3.0.3","@types/eventemitter2":"^4.1.0","@types/file-saver":"2.0.5","@types/lodash":"^4.14.182","@types/react":"^18.0.0","@types/react-dom":"^18.0.0","@types/react-grid-layout":"^1.3.2",ahooks:"^3.3.11",ajv:"8.11.0",axios:"^0.27.2","crypto-js":"^4.1.1",cypress:"^10.6.0","cypress-wait-until":"^1.7.2",echarts:"^5.3.2","echarts-for-react":"^3.0.2","echarts-gl":"^2.0.9","echarts-stat":"1.2.0",jsdom:"^20.0.0","jsdom-testing-mocks":"^1.5.0",lodash:"^4.17.21",lowlight:"^2.8.0",numbro:"^2.3.6","prosemirror-commands":"^1.5.0","prosemirror-dropcursor":"^1.6.1","prosemirror-gapcursor":"^1.3.1","prosemirror-history":"^1.3.0","prosemirror-keymap":"^1.2.0","prosemirror-schema-list":"^1.2.2","react-grid-layout":"^1.3.4","react-hook-form":"^7.31.2","rollup-plugin-visualizer":"5.6.0","tabler-icons-react":"^1.48.0",typescript:"^4.6.3"},yy={"@emotion/react":"11.10.0","@mantine/core":"5.9.5","@mantine/dates":"5.9.5","@mantine/form":"5.9.5","@mantine/hooks":"5.9.5","@mantine/modals":"5.9.5","@mantine/notifications":"5.9.5","@mantine/prism":"5.9.5","@mantine/tiptap":"5.9.5","@tabler/icons":"^1.118.0","@tanstack/react-table":"^8.5.13","@tiptap/extension-code-block-lowlight":"^2.0.0-beta.209","@tiptap/extension-color":"^2.0.0-beta.209","@tiptap/extension-highlight":"^2.0.0-beta.209","@tiptap/extension-link":"^2.0.0-beta.209","@tiptap/extension-placeholder":"^2.0.0-beta.209","@tiptap/extension-subscript":"^2.0.0-beta.209","@tiptap/extension-superscript":"^2.0.0-beta.209","@tiptap/extension-text-align":"^2.0.0-beta.209","@tiptap/extension-text-style":"^2.0.0-beta.209","@tiptap/extension-underline":"^2.0.0-beta.209","@tiptap/react":"^2.0.0-beta.209","@tiptap/starter-kit":"^2.0.0-beta.209",ahooks:"^3.3.11",axios:"^0.27.2","chroma-js":"^2.4.2","d3-array":"3.2.0","d3-regression":"1.2.8",dayjs:"1.11.6",echarts:"^5.3.2","echarts-for-react":"^3.0.2","echarts-gl":"^2.0.9","echarts-stat":"1.2.0",eventemitter2:"^6.4.6",jszip:"3.10.1",lodash:"^4.17.21",lowlight:"^2.8.0",mobx:"^6.6.1","mobx-react-lite":"^3.4.0","mobx-state-tree":"^5.1.5",numbro:"^2.3.6","prosemirror-commands":"^1.5.0","prosemirror-dropcursor":"^1.6.1","prosemirror-gapcursor":"^1.3.1","prosemirror-history":"^1.3.0","prosemirror-keymap":"^1.2.0","prosemirror-schema-list":"^1.2.2",react:"^16.8.0 || 17.x || 18.x","react-dom":"^16.8.0 || 17.x || 18.x","react-grid-layout":"^1.3.4","react-hook-form":"^7.31.2","react-virtual":"^2.10.4","tabler-icons-react":"^1.48.0"},WL=Object.freeze(Object.defineProperty({__proto__:null,name:sy,version:oc,license:ly,publishConfig:uy,files:cy,main:dy,module:fy,types:py,exports:hy,scripts:gy,dependencies:vy,devDependencies:my,peerDependencies:yy,default:{name:sy,version:oc,license:ly,publishConfig:uy,files:cy,main:dy,module:fy,types:py,exports:hy,scripts:gy,dependencies:vy,devDependencies:my,peerDependencies:yy}},Symbol.toStringTag,{value:"Module"}));class UL{constructor(t){ke(this,"staticColors",new Map);ke(this,"interpolations",new Map);t.installedPlugins.forEach(n=>{n.manifest.color.forEach(r=>{this.register(r)})})}getStaticColors(){return Array.from(this.staticColors.values())}register(t){const n=this.encodeColor(t);t.type==="single"?(this.staticColors.has(n)&&console.warn(`the color '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.staticColors.set(n,t)):t.type==="interpolation"&&(this.interpolations.has(n)&&console.warn(`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`,`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.interpolations.set(n,t))}decodeStaticColor(t){return this.staticColors.get(t)}encodeColor(t){return`\${${t.category}}.{${t.name}}`}decodeInterpolation(t){return this.interpolations.get(t)}getColorInterpolations(){return Array.from(this.interpolations.values())}}class YL{constructor(){ke(this,"plugins",new Map);ke(this,"vizComponents",new Map);ke(this,"factory",{viz:t=>{const n=this.vizComponents.get(t);if(n)return n;throw new Error(`Viz Component (${t}) not found`)}})}install(t){if(this.plugins.has(t.id))throw new Error(`Plugin (${t.id}) has been installed before`);this.plugins.set(t.id,t);for(const n of t.manifest.viz){if(this.vizComponents.has(n.name))throw new Error(`Viz Component (${n.name}) has been installed before`);this.vizComponents.set(n.name,n)}}get installedPlugins(){return Array.from(this.plugins.values())}}class XL{constructor(){ke(this,"migrations",[])}version(t,n){return this.migrations.push({version:t,handler:n}),this}run(t,n,r){var a;if(t.from===t.to)return n;if(t.from>t.to)throw new Error(`Can not downgrade from version '${t.from}' to (${t.to})`);const i=this.migrations.filter(s=>s.version>t.from&&s.version<=t.to),o=H.orderBy(i,"version","asc");if(((a=H.last(o))==null?void 0:a.version)!==t.to)throw new Error(`Migration to version ${t.to} not found`);return o.reduce((s,u)=>u.handler(s,r),n)}}class en extends XL{constructor(){super(),this.configVersions()}version(t,n){return super.version(t,(r,i)=>({version:t,...n(r,i)}))}async migrate({configData:t,panelModel:n}){const r=await t.getItem(null),i=H.get(r,"version",0),o=this.run({from:i,to:this.VERSION},r,{panelModel:n});await t.setItem(null,o)}async needMigration({configData:t}){const n=await t.getItem(null);return H.get(n,"version",0)<this.VERSION}}const et=(e,t)=>{const[n,{setFalse:r}]=nt.useBoolean(!0),[i,o]=x.useState();x.useEffect(()=>(e.getItem(t).then(s=>{o(s),r()}),e.watchItem(t,s=>{o(s)})));const a=x.useCallback(async s=>{await e.setItem(t,s),o(s)},[e,t]);return{loading:n,value:i,set:a}},ac={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"}};Rt.use([ut.GridComponent,ut.VisualMapComponent,ut.LegendComponent,ut.TooltipComponent,Kn.CanvasRenderer]);function QL({context:e}){const{value:t}=et(e.instanceData,"config"),n=e.data,{width:r,height:i}=e.viewport,{x_axis_data_key:o,y_axis_data_key:a,z_axis_data_key:s,xAxis3D:u,yAxis3D:c,zAxis3D:f}=H.defaults({},t,ac),h=x.useMemo(()=>{const v=H.minBy(n,m=>m[s]);return H.get(v,s)},[n,s]),p=x.useMemo(()=>{const v=H.maxBy(n,m=>m[s]);return H.get(v,s)},[n,s]),g={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:h,max:p,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:u,yAxis3D:c,zAxis3D:f,grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}},series:[{type:"bar3D",wireframe:{},data:n.map(v=>[v[o],v[a],v[s]])}]};return t?l(Hn.default,{echarts:Rt,option:g,style:{width:r,height:i}}):null}function ZL({label:e,required:t,value:n,onChange:r,data:i,clearable:o=!1,sx:a,...s},u){const c=W.default.useMemo(()=>{if(!Array.isArray(i)||i.length===0)return[];const h=Object.keys(i[0]).map(p=>({label:p,value:p}));return o?h.concat([{label:"unset",value:""}]):h},[i]);return l(d.Select,{ref:u,label:e,data:c,value:n,onChange:r,required:t,sx:a,...s})}const mt=W.default.forwardRef(ZL);function JL({context:e}){const{value:t,set:n}=et(e.instanceData,"config"),r=e.data,i=H.defaults({},t,ac),{control:o,handleSubmit:a,reset:s}=G.useForm({defaultValues:i});return x.useEffect(()=>{s(i)},[t]),t?l(d.Stack,{mt:"md",spacing:"xs",children:b("form",{onSubmit:a(n),children:[l(d.Text,{children:"X Axis"}),b(d.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[l(G.Controller,{name:"x_axis_data_key",control:o,render:({field:u})=>l(mt,{label:"Data Field",required:!0,data:r,...u})}),l(G.Controller,{name:"xAxis3D.name",control:o,render:({field:u})=>l(d.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),l(d.Text,{mt:"lg",children:"Y Axis"}),b(d.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[l(G.Controller,{name:"y_axis_data_key",control:o,render:({field:u})=>l(mt,{label:"Data Field",required:!0,data:r,...u})}),l(G.Controller,{name:"yAxis3D.name",control:o,render:({field:u})=>l(d.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),l(d.Text,{mt:"lg",children:"Z Axis"}),b(d.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[l(G.Controller,{name:"z_axis_data_key",control:o,render:({field:u})=>l(mt,{label:"Data Field",required:!0,data:r,...u})}),l(G.Controller,{name:"zAxis3D.name",control:o,render:({field:u})=>l(d.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),l(d.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:b(d.Button,{color:"blue",type:"submit",children:[l(te.DeviceFloppy,{size:20}),l(d.Text,{ml:"md",children:"Save"})]})})]})}):null}class eV extends en{constructor(){super(...arguments);ke(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const tV={displayName:"Bar Chart (3D)",migrator:new eV,name:"bar-3d",viewRender:QL,configRender:JL,createConfig(){return{version:1,config:H.cloneDeep(ac)}}},Fn={mantissa:0,output:"number",trimMantissa:!1,average:!1};function nV({value:e,onChange:t},n){const r=s=>{t({...e,output:s})},i=s=>{const u=s===0?!1:e.trimMantissa;t({...e,mantissa:s,trimMantissa:u})},o=s=>{t({...e,trimMantissa:s.currentTarget.checked})},a=s=>{t({...e,average:s.currentTarget.checked})};return b(d.Stack,{ref:n,children:[b(d.Group,{grow:!0,children:[l(d.Select,{label:"Format",data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:e.output,onChange:r,sx:{flexGrow:1}}),l(d.Switch,{label:b(d.Stack,{spacing:0,children:[l(d.Text,{children:"Average"}),l(d.Text,{size:12,color:"gray",children:"like 1.234k, 1.234m"})]}),checked:e.average,onChange:a,disabled:e.output!=="number",sx:{flexGrow:1},styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}}})]}),b(d.Group,{grow:!0,children:[l(d.NumberInput,{label:"Mantissa",defaultValue:0,min:0,step:1,max:4,value:e.mantissa,onChange:i}),l(d.Switch,{label:"Trim mantissa",checked:e.trimMantissa,onChange:o,disabled:e.mantissa===0,styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"}}})]}),b(d.Stack,{spacing:0,children:[l(d.Text,{weight:"bold",children:"Preview"}),l(Wr,{children:b(d.Group,{position:"apart",children:[b(d.Text,{size:12,color:"gray",children:["123456789 ",l(te.ArrowRight,{size:9})," ",Ft.default(123456789).format(e)]}),b(d.Text,{size:12,color:"gray",children:["1234 ",l(te.ArrowRight,{size:9})," ",Ft.default(1234).format(e)]}),b(d.Text,{size:12,color:"gray",children:["0.1234 ",l(te.ArrowRight,{size:9})," ",Ft.default(.1234).format(e)]})]})})]})]})}const jr=W.default.forwardRef(nV),Kr={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
151
+ `)},fL=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:i}]=nt.useBoolean(),[o,a]=x.useState(e!=null?e:nc),s=p=>{a({...o,enabled:p})},u=()=>{i();const{enabled:p,func_content:g}=o,v={enabled:p,func_content:g};a(v),t(v)},c=()=>{i(),a(e)},f=p=>{a(g=>({...g,func_content:p}))},h=()=>{f(nc.func_content)};return b(De,{children:[l(d.ActionIcon,{size:"lg",color:"blue",variant:"filled",mt:26,onClick:r,sx:{flexGrow:0},children:l(te.Settings,{size:14})}),l(d.Modal,{size:800,title:"Customize modal title",opened:n,onClose:i,closeOnClickOutside:!1,withCloseButton:!1,children:n&&b(d.Stack,{children:[l(d.Checkbox,{mt:10,label:"Enabled",checked:o.enabled,onChange:p=>s(p.currentTarget.checked)}),l(dL,{value:o.func_content,onChange:f,disabled:!o.enabled}),b(d.Group,{position:"apart",children:[l(d.Button,{onClick:h,color:"red",leftIcon:l(te.Recycle,{size:20}),children:"Rest"}),b(d.Group,{position:"right",children:[l(d.Button,{onClick:c,variant:"subtle",children:"Cancel"}),l(d.Button,{onClick:u,children:"OK"})]})]})]})})]})},pL=se.observer(()=>{const t=Ze().views.VIE;if(!t||t.type!==Ye.Modal)return null;const n=t.config,r=n.custom_modal_title.value;return b(d.Stack,{children:[l(d.Divider,{mt:8,label:"Modal settings",labelPosition:"center"}),b(d.Flex,{gap:10,children:[l(d.TextInput,{label:"Modal Title",value:r,onChange:ye.default.noop,disabled:!0,sx:{flexGrow:1}}),l(fL,{value:n.custom_modal_title,onChange:n.custom_modal_title.replace})]}),b(d.Group,{grow:!0,children:[l(d.TextInput,{label:"Width",value:n.width,onChange:i=>n.setWidth(i.currentTarget.value),placeholder:"600px / 50vw"}),l(d.TextInput,{label:"Height",value:n.height,onChange:i=>n.setHeight(i.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),hL=se.observer(()=>b(De,{children:[l(sL,{}),l(pL,{}),l(cL,{})]})),gL=[{label:"Division",value:Ye.Division},{label:"Modal",value:Ye.Modal},{label:"Tabs",value:Ye.Tabs}],vL=se.observer(()=>{const t=Ze().views.VIE;return t?b(d.Stack,{sx:{position:"relative"},children:[l(d.TextInput,{label:"Name",value:t.name,onChange:n=>{t.setName(n.currentTarget.value)}}),l(d.Select,{label:"Type",withinPortal:!0,value:t.type,onChange:t.setType,data:gL}),l(hL,{})]}):null}),mL=se.observer(({opened:e,close:t})=>{var i;const n=Ze(),{freezeLayout:r}=W.default.useContext(_n);return W.default.useEffect(()=>{r(e)},[e]),l(d.Modal,{size:"500px",overflow:"inside",opened:e,onClose:t,withCloseButton:!1,styles:{header:{width:"100%"},title:{width:"100%"}},title:b(d.Group,{position:"apart",children:[b(d.Text,{sx:{flexGrow:1},children:["Editing ",(i=n.views.VIE)==null?void 0:i.name]}),l(d.ActionIcon,{size:18,color:"red",onClick:n.views.removeVIE,disabled:n.views.isVIETheFirstView,children:l(te.Trash,{size:18})})]}),trapFocus:!0,onDragStart:o=>{o.stopPropagation()},children:l(vL,{})})}),yL=x.forwardRef(({label:e,type:t,...n},r)=>t!=="TRIGGER_TO_ADD"?l("div",{ref:r,...n,children:b(d.Group,{noWrap:!0,position:"apart",children:[l(d.Text,{size:"sm","data-role":"label",children:e}),l(d.Text,{size:"xs",color:"dimmed","data-role":"description",children:t})]})}):l("div",{ref:r,...n,children:l(d.Group,{noWrap:!0,grow:!0,children:l(d.Text,{size:"sm",align:"center",color:"#228be6",children:e})})})),Km="TRIGGER_TO_ADD",bL=se.observer(({value:e,onChange:t,triggerAdd:n,triggerEdit:r,options:i})=>{const o=x.useMemo(()=>[...i,{label:"Add a View",value:Km,type:"TRIGGER_TO_ADD"}],[i,n]),a=s=>{s!==Km?t(s):n()};return b(d.Flex,{gap:0,sx:{minWidth:"400px"},children:[l(d.Select,{value:e,onChange:a,placeholder:"Pick a View",itemComponent:yL,data:o,nothingFound:"Empty",sx:{flexGrow:1,".mantine-Select-item[data-selected] .mantine-Text-root[data-role=description]":{color:"rgba(255,255,255,.7)"}},styles:{input:{borderTopRightRadius:0,borderBottomRightRadius:0}}}),l(d.ActionIcon,{onClick:r,variant:"default",size:36,sx:{borderLeft:0,borderTopLeftRadius:0,borderBottomLeftRadius:0,"&:active":{transform:"none",svg:{transform:"translateY(1px)"}}},children:l(te.Settings,{size:20})})]})}),wL=se.observer(()=>{const e=Ze(),[t,n]=x.useState(!1),r=()=>{n(!0)},i=()=>{n(!1)};return b(De,{children:[l(bL,{value:e.views.idOfVIE,onChange:e.views.setIDOfVIE,triggerAdd:e.views.addARandomNewView,triggerEdit:r,options:e.views.options}),l(mL,{opened:t,close:i})]})}),Hm={"> 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}}},qm=se.observer(function({saveChanges:t,inUseMode:n}){const r=Ze(),i=W.default.useCallback(()=>{const S=r.queries.json,E=r.views.json,M=r.sqlSnippets.json,A=r.filters.current,L=r.mock_context.current;return{filters:A,views:E,definition:{sqlSnippets:M,queries:S,mock_context:L},version:r.version}},[r]),o=()=>{r.reset()},a=r.changed,[s,u]=W.default.useState(!1),c=()=>u(!0),f=()=>u(!1),[h,p]=W.default.useState(!1),g=()=>p(!0),v=()=>p(!1),[m,w]=W.default.useState(!1),y=()=>w(!0),_=()=>w(!1),C=()=>{const S=JSON.stringify(i(),null,2);$$(r.name,S)};return n?null:b(d.Group,{position:"apart",pt:0,px:10,pb:"xs",children:[l(d.Group,{position:"left",children:l(wL,{})}),b(d.Group,{position:"right",sx:{button:{minWidth:"40px"}},children:[l(d.Button,{variant:"filled",size:"xs",disabled:!r.views.VIE,onClick:r.views.addAPanelToVIE,leftIcon:l(te.PlaylistAdd,{size:20}),children:"Add a Panel"}),b(d.Group,{spacing:0,sx:Hm,children:[l(d.Tooltip,{label:"Filters",children:l(d.ActionIcon,{variant:"default",size:"md",onClick:g,children:l(te.Filter,{size:20})})}),l(d.Tooltip,{label:"Data Settings",children:l(d.ActionIcon,{variant:"default",size:"md",onClick:c,children:l(te.Database,{size:20})})}),l(d.Tooltip,{label:"Interactions Viewer",children:l(d.ActionIcon,{variant:"default",size:"md",onClick:y,children:l(te.Link,{size:20})})})]}),b(d.Group,{spacing:0,sx:Hm,children:[l(d.Tooltip,{label:"Save Changes",children:l(d.ActionIcon,{variant:"default",size:"md",onClick:t,disabled:!a,children:l(te.DeviceFloppy,{size:20,color:"green"})})}),l(d.Tooltip,{label:"Revert Changes",children:l(d.ActionIcon,{variant:"default",size:"md",disabled:!a,onClick:o,children:l(te.Recycle,{size:20,color:"red"})})})]}),b(d.Menu,{width:180,trigger:"hover",children:[l(d.Menu.Target,{children:l(d.ActionIcon,{variant:"default",size:"md",children:l(te.Share,{size:20})})}),b(d.Menu.Dropdown,{children:[l(d.Menu.Item,{icon:l(te.Download,{size:14}),onClick:r.queries.downloadAllData,children:"Download Data"}),l(d.Menu.Item,{icon:l(te.Code,{size:14}),onClick:C,children:"Download Schema"})]})]})]}),l(aL,{opened:h,close:v}),l(K2,{opened:s,close:f}),l(N$,{opened:m,close:_})]})}),Wj="",Wm=Qt.Mark.create({name:"textStyle",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"span",getAttrs:e=>e.hasAttribute("style")?{}:!1}]},renderHTML({HTMLAttributes:e}){return["span",Qt.mergeAttributes(this.options.HTMLAttributes,e),0]},addCommands(){return{removeEmptyTextStyle:()=>({state:e,commands:t})=>{const n=Qt.getMarkAttributes(e,this.type);return Object.entries(n).some(([,i])=>!!i)?!0:t.unsetMark(this.name)}}}}),Um=Qt.Extension.create({name:"color",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{color:{default:null,parseHTML:e=>{var t;return(t=e.style.color)===null||t===void 0?void 0:t.replace(/['"]+/g,"")},renderHTML:e=>e.color?{style:`color: ${e.color}`}:{}}}}]},addCommands(){return{setColor:e=>({chain:t})=>t().setMark("textStyle",{color:e}).run(),unsetColor:()=>({chain:e})=>e().setMark("textStyle",{color:null}).removeEmptyTextStyle().run()}}}),xL=/(?:^|\s)((?:==)((?:[^~=]+))(?:==))$/,SL=/(?:^|\s)((?:==)((?:[^~=]+))(?:==))/g,Ym=Qt.Mark.create({name:"highlight",addOptions(){return{multicolor:!1,HTMLAttributes:{}}},addAttributes(){return this.options.multicolor?{color:{default:null,parseHTML:e=>e.getAttribute("data-color")||e.style.backgroundColor,renderHTML:e=>e.color?{"data-color":e.color,style:`background-color: ${e.color}; color: inherit`}:{}}}:{}},parseHTML(){return[{tag:"mark"}]},renderHTML({HTMLAttributes:e}){return["mark",Qt.mergeAttributes(this.options.HTMLAttributes,e),0]},addCommands(){return{setHighlight:e=>({commands:t})=>t.setMark(this.name,e),toggleHighlight:e=>({commands:t})=>t.toggleMark(this.name,e),unsetHighlight:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-h":()=>this.editor.commands.toggleHighlight()}},addInputRules(){return[Qt.markInputRule({find:xL,type:this.type})]},addPasteRules(){return[Qt.markPasteRule({find:SL,type:this.type})]}}),Xm=Qt.Extension.create({name:"placeholder",addOptions(){return{emptyEditorClass:"is-editor-empty",emptyNodeClass:"is-empty",placeholder:"Write something \u2026",showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){return[new r0.Plugin({props:{decorations:({doc:e,selection:t})=>{const n=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:r}=t,i=[];if(!n)return null;const o=e.type.createAndFill(),a=(o==null?void 0:o.sameMarkup(e))&&o.content.findDiffStart(e.content)===null;return e.descendants((s,u)=>{const c=r>=u&&r<=u+s.nodeSize,f=!s.isLeaf&&!s.childCount;if((c||!this.options.showOnlyCurrent)&&f){const h=[this.options.emptyNodeClass];a&&h.push(this.options.emptyEditorClass);const p=Wc.Decoration.node(u,u+s.nodeSize,{class:h.join(" "),"data-placeholder":typeof this.options.placeholder=="function"?this.options.placeholder({editor:this.editor,node:s,pos:u,hasAnchor:c}):this.options.placeholder});i.push(p)}return this.options.includeChildren}),Wc.DecorationSet.create(e,i)}}})]}}),Qm=Qt.Mark.create({name:"subscript",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"sub"},{style:"vertical-align",getAttrs(e){return e!=="sub"?!1:null}}]},renderHTML({HTMLAttributes:e}){return["sub",Qt.mergeAttributes(this.options.HTMLAttributes,e),0]},addCommands(){return{setSubscript:()=>({commands:e})=>e.setMark(this.name),toggleSubscript:()=>({commands:e})=>e.toggleMark(this.name),unsetSubscript:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-,":()=>this.editor.commands.toggleSubscript()}}}),Zm=Qt.Mark.create({name:"superscript",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"sup"},{style:"vertical-align",getAttrs(e){return e!=="super"?!1:null}}]},renderHTML({HTMLAttributes:e}){return["sup",Qt.mergeAttributes(this.options.HTMLAttributes,e),0]},addCommands(){return{setSuperscript:()=>({commands:e})=>e.setMark(this.name),toggleSuperscript:()=>({commands:e})=>e.toggleMark(this.name),unsetSuperscript:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-.":()=>this.editor.commands.toggleSuperscript()}}}),Jm=Qt.Extension.create({name:"textAlign",addOptions(){return{types:[],alignments:["left","center","right","justify"],defaultAlignment:"left"}},addGlobalAttributes(){return[{types:this.options.types,attributes:{textAlign:{default:this.options.defaultAlignment,parseHTML:e=>e.style.textAlign||this.options.defaultAlignment,renderHTML:e=>e.textAlign===this.options.defaultAlignment?{}:{style:`text-align: ${e.textAlign}`}}}}]},addCommands(){return{setTextAlign:e=>({commands:t})=>this.options.alignments.includes(e)?this.options.types.every(n=>t.updateAttributes(n,{textAlign:e})):!1,unsetTextAlign:()=>({commands:e})=>this.options.types.every(t=>e.resetAttributes(t,"textAlign"))}},addKeyboardShortcuts(){return{"Mod-Shift-l":()=>this.editor.commands.setTextAlign("left"),"Mod-Shift-e":()=>this.editor.commands.setTextAlign("center"),"Mod-Shift-r":()=>this.editor.commands.setTextAlign("right"),"Mod-Shift-j":()=>this.editor.commands.setTextAlign("justify")}}}),ey=Qt.Mark.create({name:"underline",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"u"},{style:"text-decoration",consuming:!1,getAttrs:e=>e.includes("underline")?{}:!1}]},renderHTML({HTMLAttributes:e}){return["u",Qt.mergeAttributes(this.options.HTMLAttributes,e),0]},addCommands(){return{setUnderline:()=>({commands:e})=>e.setMark(this.name),toggleUnderline:()=>({commands:e})=>e.toggleMark(this.name),unsetUnderline:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-u":()=>this.editor.commands.toggleUnderline(),"Mod-U":()=>this.editor.commands.toggleUnderline()}}}),rc={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"}}},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:'"\u25BA"',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"}},ty=({value:e,styles:t={}})=>{const n=Uc.useEditor({extensions:[Xc.default,ey,rt.Link,Zm,Qm,Ym,Jm.configure({types:["heading","paragraph"]}),Xm.configure({placeholder:"This is placeholder"}),Wm,Um],content:e,editable:!1}),r=x.useMemo(()=>ye.default.defaultsDeep({},{content:rc},t),[t]);return l(rt.RichTextEditor,{editor:n,styles:r,children:l(rt.RichTextEditor.Content,{})})};function CL(e){return e?["<p><br></p>","<p></p>"].includes(e):!0}const ny=se.observer(()=>{const{freezeLayout:e}=W.default.useContext(_n),[t,n]=W.default.useState(!1),{panel:r}=jt();return W.default.useEffect(()=>{e(t)},[t]),CL(r.description)?null:b(De,{children:[l(d.Modal,{opened:t,onClose:()=>n(!1),title:r.title,withCloseButton:!1,children:l(ty,{value:r.description,styles:{root:{border:"none"},content:{padding:0}}})}),l(d.Tooltip,{label:"Click to see description",position:"top-start",withinPortal:!0,children:l(d.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>n(i=>!i),sx:{verticalAlign:"baseline",cursor:"pointer"},children:l(te.InfoCircle,{size:20})})})]})}),ry=e=>{const{title:t="Variables",variables:n}=e,r=wt.useClipboard(),i=o=>{r.copy(o),Po.showNotification({color:"green",message:"Copied to clipboard"})};return b(d.Paper,{withBorder:!0,p:"sm",children:[l(d.Text,{size:"xs",color:"dimmed",mb:"sm",children:t}),l(d.Stack,{style:{maxHeight:"500px"},children:n.map(o=>b(d.Text,{size:"sm",children:[b(d.Code,{color:"teal",children:["// ",o.description]}),l("br",{}),b(d.Code,{onClick:()=>i(o.name),style:{cursor:"pointer"},children:[o.name," : ",o.valueType]})]},o.name))})]})};class _L{constructor(t,n){ke(this,"operationId");ke(this,"operation");ke(this,"operationSchema");ke(this,"variables",[]);this.operationManager=t,this.instance=n,zt.makeAutoObservable(this)}get schemaList(){return this.operationManager.getOperationSchemaList()}async configOperation(t,n){const r=await this.operationManager.retrieveTrigger(t),i=this.operationManager.getOperationSchemaList().find(o=>o.id===(r==null?void 0:r.schemaRef));zt.runInAction(()=>{this.operationId=t,this.operation=r,this.operationSchema=i,this.variables=n})}async changeSchema(t){this.operationId&&(await this.operationManager.createOrGetOperation(this.operationId,t),await this.configOperation(this.operationId,this.variables))}}function EL(e){return!!e.operationId}const TL=se.observer(({model:e,onClick:t})=>{var r;const n=(r=e.operationSchema)==null?void 0:r.displayName;return l(d.Button,{variant:"outline",onClick:t,children:n})}),ML=se.observer(({model:e})=>{const t={operation:e.operation,instance:e.instance,variables:[]};return x.createElement(e.operationSchema.configRender,t)});function OL({model:e}){const t=e.schemaList,n=t.map(i=>({label:i.displayName,value:i.id}));async function r(i){await e.changeSchema(t.find(o=>o.id===i))}return l(d.Select,{label:"Operation",data:n,onChange:r,value:e.operationSchema.id})}const DL=se.observer(e=>{const[t,{setTrue:n,setFalse:r}]=nt.useBoolean(!1),{operationManager:i,operationId:o,instance:a,variables:s}=e,u=nt.useCreation(()=>new _L(i,a),[i,a]);return nt.useAsyncEffect(async()=>{await u.configOperation(o,s)},[o,u]),EL(u)?b(De,{children:[l(TL,{model:u,onClick:n}),l(d.Modal,{size:600,opened:t,onClose:r,title:"Operation Settings",closeButtonLabel:"close",children:b(d.Stack,{children:[l(OL,{model:u}),l(ML,{model:u}),l(ry,{title:"Variables",variables:u.variables})]})})]}):null});class RL{constructor(t,n){ke(this,"triggerId");ke(this,"trigger");ke(this,"triggerSchema");ke(this,"sampleData");this.triggerManager=t,this.instance=n,zt.makeAutoObservable(this)}get schemaList(){return this.triggerManager.getTriggerSchemaList()}async configTrigger(t,n){const r=await this.triggerManager.retrieveTrigger(t),i=this.triggerManager.getTriggerSchemaList().find(o=>o.id===(r==null?void 0:r.schemaRef));zt.runInAction(()=>{this.triggerId=t,this.trigger=r,this.triggerSchema=i,this.sampleData=n})}async changeSchema(t){this.triggerId&&(await this.triggerManager.createOrGetTrigger(this.triggerId,t),await this.configTrigger(this.triggerId,this.sampleData))}isReady(){return kL(this)}}function kL(e){return!!e.triggerId&&!!e.triggerSchema}function AL(e,t){return nt.useCreation(()=>new RL(e,t),[e,t])}const PL=se.observer(({model:e,onClick:t})=>{const n=e.triggerSchema.nameRender,r={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return l(d.Button,{variant:"outline",onClick:t,children:x.createElement(n,r)})}),NL=se.observer(({model:e})=>{const t=e.schemaList,n=t.map(i=>({label:i.displayName,value:i.id}));async function r(i){await e.changeSchema(t.find(o=>o.id===i))}return l(d.Select,{label:"Trigger",data:n,value:e.triggerSchema.id,onChange:r})}),IL=se.observer(({model:e})=>{const t={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return x.createElement(e.triggerSchema.configRender,t)}),$L=se.observer(e=>{const[t,{setTrue:n,setFalse:r}]=nt.useBoolean(!1),i=e.model;return b(De,{children:[l(d.Modal,{opened:t,onClose:r,title:"Setup Trigger",closeButtonLabel:"close setup",children:b(d.Stack,{children:[l(NL,{model:i}),l(IL,{model:i}),l(ry,{title:"Payload",variables:i.triggerSchema.payload})]})}),l(PL,{onClick:n,model:i})]})});class Mi{constructor(t,n){this.root=t,this.path=n}async deleteItem(t){t===null&&await this.root.deleteItem(this.path);const n=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,H.omit(n,t))}async getItem(t){const n=await this.root.getItem(this.path);return t===null?n:H.get(n,t)}async setItem(t,n){if(t===null)await this.root.setItem(this.path,n);else{const r=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,{...r,[t]:n})}return await this.getItem(t)}watchItem(t,n,r){return t===null?this.root.watchItem(this.path,(i,o)=>{n(i,o)},r):this.root.watchItem(this.path,(i,o)=>{const a=H.get(i,t),s=H.get(o,t);a!==s&&n(a,s)},r)}}class ic{constructor(t,n,r){ke(this,"attachmentStorage");this.instance=t,this.attachmentKey=n,this.constructInstance=r,this.attachmentStorage=new Mi(t.instanceData,n)}async getInstance(t){if(await this.attachmentStorage.getItem(t))return this.constructInstance(new Mi(this.attachmentStorage,t))}async create(t,n){return await this.attachmentStorage.setItem(t,n),this.constructInstance(new Mi(this.attachmentStorage,t))}async remove(t){await this.attachmentStorage.deleteItem(t)}async list(){const t=await this.attachmentStorage.getItem(null);return Promise.all(H.values(t).map(n=>this.constructInstance(new Mi(this.attachmentStorage,n.id))))}}class iy{constructor(t){ke(this,"rootRef");this.rootRef=zt.observable({current:t})}async deleteItem(t){zt.runInAction(()=>{H.unset(this.rootRef.current,[t])})}getItem(t){const n=this.getValueFromRoot(t);return Promise.resolve(n)}getValueFromRoot(t){return t===null?zt.toJS(this.rootRef.current):H.get(this.rootRef.current,[t])}setItem(t,n){if(t===null)if(H.isObject(n))zt.runInAction(()=>{this.rootRef.current=n});else throw new Error("Cannot set root value to non-object");else zt.runInAction(()=>{H.set(this.rootRef.current,[t],n)});return Promise.resolve(this.getItem(t))}watchItem(t,n,r){return zt.reaction(()=>this.getValueFromRoot(t),(i,o)=>{n(i,o)},{requiresObservable:!0,fireImmediately:H.get(r,"fireImmediately",!1)})}}class LL{constructor(){ke(this,"channels",new Map);ke(this,"globalChannel",new Qc.default)}getChannel(t){const n=this.channels.get(t);if(n)return n;const r=new Qc.default;return this.channels.set(t,r),r}}class VL{constructor(t){ke(this,"instances",new Map);this.pluginManager=t}get availableVizList(){return this.pluginManager.installedPlugins.flatMap(t=>t.manifest.viz)}resolveComponent(t){return this.pluginManager.factory.viz(t)}getOrCreateInstance(t){const n=this.instances.get(t.id);if(n)return n;const r={id:t.id,name:t.viz.type,type:t.viz.type,messageChannels:new LL,instanceData:new iy(t.viz.conf)};return this.instances.set(t.id,r),r}}function oy(e,t,n,r){return{vizManager:n,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new iy({}),colorPalette:{getColor(){return()=>""}},data:t,variables:r}}const zL=e=>{const{panel:t,vizManager:n,data:r,variables:i}=e,o=n.resolveComponent(t.viz.type),a=n.getOrCreateInstance(t),s={...oy(a,r,n,i),viewport:{width:t.layout.w,height:t.layout.h}},u=o.viewRender;return l(u,{context:s,instance:a,...H.omit(e,["panel","vizManager","data"])})},FL=e=>{const{vizManager:t,panel:n,panelInfoEditor:r,data:i,variables:o}=e,a=t.resolveComponent(n.viz.type),s=t.getOrCreateInstance(n),u={...oy(s,i,t,o),panelInfoEditor:r},c=a.configRender;return l(c,{context:u,instance:s,...H.omit(e,["panel","vizManager","data","panelInfoEditor"])})},ay=(e,t)=>{const n=Ni.default.bezier(e),r=Ni.default.bezier(t);return function(i){return i<50?n(i*2/100).hex():r((i-50)*2/100).hex()}},rs=e=>{const t=Ni.default.bezier(e);return function(n){return t(n/100).hex()}},BL={type:"interpolation",displayName:"Red / Green",getColor:ay(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},GL={type:"interpolation",displayName:"Yellow / Blue",getColor:ay(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},jL={type:"interpolation",displayName:"Red",getColor:rs(["#fff7f1","darkred"]),name:"red",category:"sequential"},KL={type:"interpolation",displayName:"Green",getColor:rs(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},HL={type:"interpolation",displayName:"Blue",getColor:rs(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},qL={type:"interpolation",displayName:"Orange",getColor:rs(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"},sy="@devtable/dashboard",oc="7.21.0",ly="Apache-2.0",uy={access:"public",registry:"https://registry.npmjs.org/"},cy=["dist"],dy="./dist/dashboard.umd.js",fy="./dist/dashboard.es.js",py="./dist/index.d.ts",hy={".":{import:"./dist/dashboard.es.js",require:"./dist/dashboard.umd.js"},"./dist/style.css":{import:"./dist/style.css",require:"./dist/style.css"}},gy={"dev-build":"tsc && vite build --watch",build:"tsc && vite build",preview:"vite preview",test:"vitest","test:ui":"vitest --ui",coverage:"vitest --coverage"},vy={"@monaco-editor/react":"4.4.6","@types/chroma-js":"^2.1.4","file-saver":"2.0.5","performant-array-to-tree":"1.11.0",popmotion:"^11.0.3","rc-tree-select":"5.5.5",reactflow:"^11.5.3"},my={"@mantine/core":"5.9.5","@mantine/dates":"5.9.5","@mantine/form":"5.9.5","@mantine/hooks":"5.9.5","@mantine/modals":"5.9.5","@mantine/notifications":"5.9.5","@mantine/prism":"5.9.5","@mantine/tiptap":"5.9.5","@tabler/icons":"^1.118.0","@testing-library/cypress":"^8.0.3","@testing-library/jest-dom":"^5.16.4","@testing-library/react":"^13.3.0","@testing-library/react-hooks":"^8.0.1","@testing-library/user-event":"^14.3.0","@tiptap/extension-code-block-lowlight":"^2.0.0-beta.209","@tiptap/extension-color":"^2.0.0-beta.209","@tiptap/extension-highlight":"^2.0.0-beta.209","@tiptap/extension-link":"^2.0.0-beta.209","@tiptap/extension-placeholder":"^2.0.0-beta.209","@tiptap/extension-subscript":"^2.0.0-beta.209","@tiptap/extension-superscript":"^2.0.0-beta.209","@tiptap/extension-text-align":"^2.0.0-beta.209","@tiptap/extension-text-style":"^2.0.0-beta.209","@tiptap/extension-underline":"^2.0.0-beta.209","@tiptap/react":"^2.0.0-beta.209","@tiptap/starter-kit":"^2.0.0-beta.209","@types/crypto-js":"v4.1.1","@types/d3-array":"3.0.3","@types/eventemitter2":"^4.1.0","@types/file-saver":"2.0.5","@types/lodash":"^4.14.182","@types/react":"^18.0.0","@types/react-dom":"^18.0.0","@types/react-grid-layout":"^1.3.2",ahooks:"^3.3.11",ajv:"8.11.0",axios:"^0.27.2","crypto-js":"^4.1.1",cypress:"^10.6.0","cypress-wait-until":"^1.7.2",echarts:"^5.3.2","echarts-for-react":"^3.0.2","echarts-gl":"^2.0.9","echarts-stat":"1.2.0",jsdom:"^20.0.0","jsdom-testing-mocks":"^1.5.0",lodash:"^4.17.21",lowlight:"^2.8.0",numbro:"^2.3.6","prosemirror-commands":"^1.5.0","prosemirror-dropcursor":"^1.6.1","prosemirror-gapcursor":"^1.3.1","prosemirror-history":"^1.3.0","prosemirror-keymap":"^1.2.0","prosemirror-schema-list":"^1.2.2","react-grid-layout":"^1.3.4","react-hook-form":"^7.31.2","rollup-plugin-visualizer":"5.6.0","tabler-icons-react":"^1.48.0",typescript:"^4.6.3"},yy={"@emotion/react":"11.10.0","@mantine/core":"5.9.5","@mantine/dates":"5.9.5","@mantine/form":"5.9.5","@mantine/hooks":"5.9.5","@mantine/modals":"5.9.5","@mantine/notifications":"5.9.5","@mantine/prism":"5.9.5","@mantine/tiptap":"5.9.5","@tabler/icons":"^1.118.0","@tanstack/react-table":"^8.5.13","@tiptap/extension-code-block-lowlight":"^2.0.0-beta.209","@tiptap/extension-color":"^2.0.0-beta.209","@tiptap/extension-highlight":"^2.0.0-beta.209","@tiptap/extension-link":"^2.0.0-beta.209","@tiptap/extension-placeholder":"^2.0.0-beta.209","@tiptap/extension-subscript":"^2.0.0-beta.209","@tiptap/extension-superscript":"^2.0.0-beta.209","@tiptap/extension-text-align":"^2.0.0-beta.209","@tiptap/extension-text-style":"^2.0.0-beta.209","@tiptap/extension-underline":"^2.0.0-beta.209","@tiptap/react":"^2.0.0-beta.209","@tiptap/starter-kit":"^2.0.0-beta.209",ahooks:"^3.3.11",axios:"^0.27.2","chroma-js":"^2.4.2","d3-array":"3.2.0","d3-regression":"1.2.8",dayjs:"1.11.6",echarts:"^5.3.2","echarts-for-react":"^3.0.2","echarts-gl":"^2.0.9","echarts-stat":"1.2.0",eventemitter2:"^6.4.6",jszip:"3.10.1",lodash:"^4.17.21",lowlight:"^2.8.0",mobx:"^6.6.1","mobx-react-lite":"^3.4.0","mobx-state-tree":"^5.1.5",numbro:"^2.3.6","prosemirror-commands":"^1.5.0","prosemirror-dropcursor":"^1.6.1","prosemirror-gapcursor":"^1.3.1","prosemirror-history":"^1.3.0","prosemirror-keymap":"^1.2.0","prosemirror-schema-list":"^1.2.2",react:"^16.8.0 || 17.x || 18.x","react-dom":"^16.8.0 || 17.x || 18.x","react-grid-layout":"^1.3.4","react-hook-form":"^7.31.2","react-virtual":"^2.10.4","tabler-icons-react":"^1.48.0"},WL=Object.freeze(Object.defineProperty({__proto__:null,name:sy,version:oc,license:ly,publishConfig:uy,files:cy,main:dy,module:fy,types:py,exports:hy,scripts:gy,dependencies:vy,devDependencies:my,peerDependencies:yy,default:{name:sy,version:oc,license:ly,publishConfig:uy,files:cy,main:dy,module:fy,types:py,exports:hy,scripts:gy,dependencies:vy,devDependencies:my,peerDependencies:yy}},Symbol.toStringTag,{value:"Module"}));class UL{constructor(t){ke(this,"staticColors",new Map);ke(this,"interpolations",new Map);t.installedPlugins.forEach(n=>{n.manifest.color.forEach(r=>{this.register(r)})})}getStaticColors(){return Array.from(this.staticColors.values())}register(t){const n=this.encodeColor(t);t.type==="single"?(this.staticColors.has(n)&&console.warn(`the color '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.staticColors.set(n,t)):t.type==="interpolation"&&(this.interpolations.has(n)&&console.warn(`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`,`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.interpolations.set(n,t))}decodeStaticColor(t){return this.staticColors.get(t)}encodeColor(t){return`\${${t.category}}.{${t.name}}`}decodeInterpolation(t){return this.interpolations.get(t)}getColorInterpolations(){return Array.from(this.interpolations.values())}}class YL{constructor(){ke(this,"plugins",new Map);ke(this,"vizComponents",new Map);ke(this,"factory",{viz:t=>{const n=this.vizComponents.get(t);if(n)return n;throw new Error(`Viz Component (${t}) not found`)}})}install(t){if(this.plugins.has(t.id))throw new Error(`Plugin (${t.id}) has been installed before`);this.plugins.set(t.id,t);for(const n of t.manifest.viz){if(this.vizComponents.has(n.name))throw new Error(`Viz Component (${n.name}) has been installed before`);this.vizComponents.set(n.name,n)}}get installedPlugins(){return Array.from(this.plugins.values())}}class XL{constructor(){ke(this,"migrations",[])}version(t,n){return this.migrations.push({version:t,handler:n}),this}run(t,n,r){var a;if(t.from===t.to)return n;if(t.from>t.to)throw new Error(`Can not downgrade from version '${t.from}' to (${t.to})`);const i=this.migrations.filter(s=>s.version>t.from&&s.version<=t.to),o=H.orderBy(i,"version","asc");if(((a=H.last(o))==null?void 0:a.version)!==t.to)throw new Error(`Migration to version ${t.to} not found`);return o.reduce((s,u)=>u.handler(s,r),n)}}class en extends XL{constructor(){super(),this.configVersions()}version(t,n){return super.version(t,(r,i)=>({version:t,...n(r,i)}))}async migrate({configData:t,panelModel:n}){const r=await t.getItem(null),i=H.get(r,"version",0),o=this.run({from:i,to:this.VERSION},r,{panelModel:n});await t.setItem(null,o)}async needMigration({configData:t}){const n=await t.getItem(null);return H.get(n,"version",0)<this.VERSION}}const et=(e,t)=>{const[n,{setFalse:r}]=nt.useBoolean(!0),[i,o]=x.useState();x.useEffect(()=>(e.getItem(t).then(s=>{o(s),r()}),e.watchItem(t,s=>{o(s)})));const a=x.useCallback(async s=>{await e.setItem(t,s),o(s)},[e,t]);return{loading:n,value:i,set:a}},ac={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"}};Rt.use([ut.GridComponent,ut.VisualMapComponent,ut.LegendComponent,ut.TooltipComponent,Kn.CanvasRenderer]);function QL({context:e}){const{value:t}=et(e.instanceData,"config"),n=e.data,{width:r,height:i}=e.viewport,{x_axis_data_key:o,y_axis_data_key:a,z_axis_data_key:s,xAxis3D:u,yAxis3D:c,zAxis3D:f}=H.defaults({},t,ac),h=x.useMemo(()=>{const v=H.minBy(n,m=>m[s]);return H.get(v,s)},[n,s]),p=x.useMemo(()=>{const v=H.maxBy(n,m=>m[s]);return H.get(v,s)},[n,s]),g={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:h,max:p,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:u,yAxis3D:c,zAxis3D:f,grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}},series:[{type:"bar3D",wireframe:{},data:n.map(v=>[v[o],v[a],v[s]])}]};return t?l(Hn.default,{echarts:Rt,option:g,style:{width:r,height:i}}):null}function ZL({label:e,required:t,value:n,onChange:r,data:i,clearable:o=!1,sx:a,...s},u){const c=W.default.useMemo(()=>{if(!Array.isArray(i)||i.length===0)return[];const h=Object.keys(i[0]).map(p=>({label:p,value:p}));return o?h.concat([{label:"unset",value:""}]):h},[i]);return l(d.Select,{ref:u,label:e,data:c,value:n,onChange:r,required:t,sx:a,...s})}const mt=W.default.forwardRef(ZL);function JL({context:e}){const{value:t,set:n}=et(e.instanceData,"config"),r=e.data,i=H.defaults({},t,ac),{control:o,handleSubmit:a,reset:s}=G.useForm({defaultValues:i});return x.useEffect(()=>{s(i)},[t]),t?l(d.Stack,{mt:"md",spacing:"xs",children:b("form",{onSubmit:a(n),children:[l(d.Text,{children:"X Axis"}),b(d.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[l(G.Controller,{name:"x_axis_data_key",control:o,render:({field:u})=>l(mt,{label:"Data Field",required:!0,data:r,...u})}),l(G.Controller,{name:"xAxis3D.name",control:o,render:({field:u})=>l(d.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),l(d.Text,{mt:"lg",children:"Y Axis"}),b(d.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[l(G.Controller,{name:"y_axis_data_key",control:o,render:({field:u})=>l(mt,{label:"Data Field",required:!0,data:r,...u})}),l(G.Controller,{name:"yAxis3D.name",control:o,render:({field:u})=>l(d.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),l(d.Text,{mt:"lg",children:"Z Axis"}),b(d.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[l(G.Controller,{name:"z_axis_data_key",control:o,render:({field:u})=>l(mt,{label:"Data Field",required:!0,data:r,...u})}),l(G.Controller,{name:"zAxis3D.name",control:o,render:({field:u})=>l(d.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),l(d.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:b(d.Button,{color:"blue",type:"submit",children:[l(te.DeviceFloppy,{size:20}),l(d.Text,{ml:"md",children:"Save"})]})})]})}):null}class eV extends en{constructor(){super(...arguments);ke(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const tV={displayName:"Bar Chart (3D)",migrator:new eV,name:"bar-3d",viewRender:QL,configRender:JL,createConfig(){return{version:1,config:H.cloneDeep(ac)}}},Fn={mantissa:0,output:"number",trimMantissa:!1,average:!1};function nV({value:e,onChange:t},n){const r=s=>{t({...e,output:s})},i=s=>{const u=s===0?!1:e.trimMantissa;t({...e,mantissa:s,trimMantissa:u})},o=s=>{t({...e,trimMantissa:s.currentTarget.checked})},a=s=>{t({...e,average:s.currentTarget.checked})};return b(d.Stack,{ref:n,children:[b(d.Group,{grow:!0,children:[l(d.Select,{label:"Format",data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:e.output,onChange:r,sx:{flexGrow:1}}),l(d.Switch,{label:b(d.Stack,{spacing:0,children:[l(d.Text,{children:"Average"}),l(d.Text,{size:12,color:"gray",children:"like 1.234k, 1.234m"})]}),checked:e.average,onChange:a,disabled:e.output!=="number",sx:{flexGrow:1},styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}}})]}),b(d.Group,{grow:!0,children:[l(d.NumberInput,{label:"Mantissa",defaultValue:0,min:0,step:1,max:4,value:e.mantissa,onChange:i}),l(d.Switch,{label:"Trim mantissa",checked:e.trimMantissa,onChange:o,disabled:e.mantissa===0,styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"}}})]}),b(d.Stack,{spacing:0,children:[l(d.Text,{weight:"bold",children:"Preview"}),l(Wr,{children:b(d.Group,{position:"apart",children:[b(d.Text,{size:12,color:"gray",children:["123456789 ",l(te.ArrowRight,{size:9})," ",Ft.default(123456789).format(e)]}),b(d.Text,{size:12,color:"gray",children:["1234 ",l(te.ArrowRight,{size:9})," ",Ft.default(1234).format(e)]}),b(d.Text,{size:12,color:"gray",children:["0.1234 ",l(te.ArrowRight,{size:9})," ",Ft.default(.1234).format(e)]})]})})]})]})}const jr=W.default.forwardRef(nV),Kr={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
152
152
  `)},Er={x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}},by={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:iV,configRender:rV,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 rV(e){return l(De,{})}function iV(e){return l(d.Text,{children:"Click chart's series"})}const sc={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...Kr},overflow:Er}},y_axis:{name:"Y Axis",data_key:"value",label_formatter:Fn},color:"#228be6",reference_lines:[]},Oi=(e,t)=>{const[n,r]=x.useState([]);return x.useEffect(()=>e.watchTriggerSnapshotList(i=>r(i.filter(o=>o.schemaRef===t))),[]),n},Di=({vizManager:e,instance:t})=>nt.useCreation(()=>new zc(t,e.resolveComponent(t.type),ms),[t,e]),wy="__TRIGGERS";class oV{constructor(t,n){ke(this,"attachments");this.instance=t,this.component=n;const r=async i=>{const{id:o,schemaRef:a}=await i.getItem(null);return{id:o,schemaRef:a,triggerData:new Mi(i,"data")}};this.attachments=new ic(t,wy,r)}watchTriggerSnapshotList(t){return this.instance.instanceData.watchItem(wy,n=>{const r=H.values(n).map(i=>({id:H.get(i,"id"),schemaRef:H.get(i,"schemaRef"),config:zt.toJS(H.get(i,"data.config"))}));t(r)},{fireImmediately:!0})}async createOrGetTrigger(t,n,r={recreate:!1}){var s;if(!this.getTriggerSchemaList().some(u=>u.id===n.id))throw new Error(`Trigger schema '${n.id}' is not defined in component '${this.component.name}'`);const o=await this.attachments.getInstance(t);return!o||r.recreate||o.schemaRef!==n.id?await this.attachments.create(t,{id:t,schemaRef:n.id,data:((s=n==null?void 0:n.createDefaultConfig)==null?void 0:s.call(n))||{}}):o}async getTriggerList(){return await this.attachments.list()}getTriggerSchemaList(){return this.component.triggers||[]}async removeTrigger(t){await this.attachments.remove(t)}async retrieveTrigger(t){return await this.attachments.getInstance(t)}async getMigrationTasks(){const n=(await this.getTriggerList()).map(async r=>{const i=this.getTriggerSchemaList().find(s=>s.id===r.schemaRef),o=i==null?void 0:i.migrator,a={configData:r.triggerData};return o&&await o.needMigration(a)?()=>o.migrate(a):null});return Promise.all(n).then(r=>r.filter(i=>i))}async needMigration(){return(await this.getMigrationTasks()).length>0}async runMigration(){const t=await this.getMigrationTasks();await Promise.all(t.map(n=>n()))}}const So=x.forwardRef(function({value:t,onChange:n,...r},i){return l(d.TextInput,{ref:i,value:t,onChange:n,...r})}),aV=[{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:"Quantile(99%, 95%, ...)",value:"quantile"}];function sV({label:e,value:t,onChange:n},r){x.useEffect(()=>{typeof t=="string"&&(console.log(t),n({type:t,config:{}}))},[t,n]);const i=a=>{n(a==="quantile"?{type:"quantile",config:{p:.99}}:{type:a,config:{}})},o=a=>{n({type:"quantile",config:{p:a}})};return b(d.Group,{grow:!0,noWrap:!0,pt:"sm",children:[l(d.Select,{ref:r,label:e,data:aV,value:t.type,onChange:i}),t.type==="quantile"&&l(d.NumberInput,{label:"p",value:t.config.p,onChange:o,precision:2,min:.05,step:.05,max:1})]})}const xy=W.default.forwardRef(sV);function lV({label:e,value:t,onChange:n},r){const[i,o]=W.default.useState(Array.isArray(t)?[...t]:[]),a=W.default.useCallback(()=>{o(p=>[...p,""])},[o]),s=W.default.useCallback(p=>{o(g=>(g.splice(p,1),[...g]))},[o]),u=W.default.useMemo(()=>!ye.default.isEqual(i,t),[i,t]),c=()=>{n(i.map(p=>p.toString()))},f=d.useMantineTheme(),h=W.default.useMemo(()=>Object.entries(f.colors).map(([p,g])=>g[6]),[f]);return b(De,{children:[b(d.Group,{position:"left",ref:r,children:[l(d.Text,{children:e}),l(d.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!u,onClick:c,children:l(te.DeviceFloppy,{size:20})})]}),b(d.Group,{children:[i.map((p,g)=>l(d.ColorInput,{value:p,onChange:v=>{o(m=>(m.splice(g,1,v),[...m]))},swatches:h,rightSection:l(d.ActionIcon,{onClick:()=>s(g),color:"red",children:l(te.Trash,{size:14})}),sx:{width:"45%"}})),l(d.ActionIcon,{onClick:a,color:"blue",variant:"outline",children:l(te.PlaylistAdd,{size:20})})]})]})}const uV=W.default.forwardRef(lV);function cV({value:e,onChange:t},n){const{colorManager:r}=x.useContext(Gn),i=W.default.useMemo(()=>r.getStaticColors().map(s=>({label:s.name,group:s.category,value:s.value})),[r]),o=W.default.useMemo(()=>i.some(a=>a.value===e),[e,i]);return b(d.Group,{position:"apart",spacing:4,ref:n,children:[l(d.TextInput,{placeholder:"Set any color",value:o?"":e,onChange:a=>t(a.currentTarget.value),rightSection:l(d.ColorSwatch,{color:o?"transparent":e,radius:4}),variant:o?"filled":"default",sx:{maxWidth:"46%",flexGrow:1}}),l(d.Text,{sx:{flexGrow:0},children:"or"}),l(d.Select,{data:i,value:e,onChange:t,variant:o?"default":"filled",placeholder:"Pick a theme color",icon:l(d.ColorSwatch,{color:o?e:"transparent",radius:4}),sx:{maxWidth:"46%",flexGrow:1}})]})}const kn=W.default.forwardRef(cV),is=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function dV({label:e,value:t,onChange:n},r){var a,s;const[i,o]=W.default.useState((s=(a=is.find(u=>u.label===t))==null?void 0:a.value)!=null?s:is[0].value);return W.default.useEffect(()=>{const u=is.find(c=>c.value===i);u&&n(u.label)},[i]),b(d.Stack,{spacing:0,mt:"sm",mb:"lg",children:[l(d.Text,{size:"sm",children:e}),l(d.Slider,{label:null,marks:is,value:i,onChange:o,step:25,placeholder:"Pick a font size",px:"1em",ref:r})]})}const Sy=W.default.forwardRef(dV);function fV({label:e,value:t,onChange:n,type:r},i){const[o,a]=W.default.useState(Array.isArray(t)?[...t]:[]),s=W.default.useCallback(()=>{a(h=>[...h,""])},[a]),u=W.default.useCallback(h=>{a(p=>(p.splice(h,1),[...p]))},[a]),c=W.default.useMemo(()=>!ye.default.isEqual(o.map(String),t.map(String)),[o,t]),f=()=>{n(o.map(h=>r==="number"?Number(h):h.toString()))};return b(De,{children:[b(d.Group,{position:"left",ref:i,children:[l(d.Text,{children:e}),l(d.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!c,onClick:f,children:l(te.DeviceFloppy,{size:20})})]}),b(d.Group,{children:[o.map((h,p)=>l(d.TextInput,{type:r,value:h,onChange:g=>{const v=g.currentTarget.value;a(m=>(m.splice(p,1,v),[...m]))},rightSection:l(d.ActionIcon,{onClick:()=>u(p),color:"red",children:l(te.Trash,{size:14})}),sx:{width:"45%"}})),l(d.ActionIcon,{onClick:s,color:"blue",variant:"outline",children:l(te.PlaylistAdd,{size:20})})]})]})}const pV=W.default.forwardRef(fV),Cy=W.default.forwardRef(function({value:t,onChange:n},r){const i=t.color.type,o=(a,s)=>{const u=ye.default.cloneDeep(t);ye.default.set(u,a,s),n(u)};return b(De,{children:[l(d.Divider,{my:"xs",label:"Typography",labelPosition:"center"}),l(d.Stack,{children:l(d.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1},value:t.size,onChange:a=>o("size",a.currentTarget.value)})}),l(d.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:l(Sy,{label:"Font Weight",value:t.weight,onChange:a=>o("weight",a)})}),l(d.Divider,{my:"xs",label:"Style",labelPosition:"center"}),b(d.Stack,{children:[l(d.Select,{label:"Color Type",data:[{label:"Static Color",value:"static"},{label:"Continuous Color",value:"continuous"}],value:t.color.type,onChange:a=>o("color.type",a)}),i==="static"&&l(kn,{value:t.color.staticColor,onChange:a=>o("color.staticColor",a)}),i==="continuous"&&b(De,{children:[l(pV,{label:"Value Range",value:t.color.valueRange,type:"number",onChange:a=>o("color.valueRange",a)}),l(uV,{label:"Color Range",value:t.color.colorRange,onChange:a=>o("color.colorRange",a)})]})]})]})});W.default.forwardRef(function({value:t,onChange:n,data:r,withStyle:i=!0},o){const a=(s,u)=>{const c=ye.default.cloneDeep(t);ye.default.set(c,s,u),n(c)};return b(d.Box,{px:"sm",py:"md",ref:o,children:[l(d.Text,{weight:"bold",pb:0,children:t.name}),l(d.Divider,{my:"xs",label:"Data",labelPosition:"center"}),b(d.Group,{grow:!0,noWrap:!0,children:[l(d.TextInput,{label:"Name",required:!0,value:t.name,onChange:s=>a("name",s.currentTarget.value)}),l(mt,{label:"Data Field",required:!0,data:r,value:t.data_field,onChange:s=>a("data_field",s)})]}),l(xy,{label:"Aggregation",value:t.aggregation,onChange:s=>a("aggregation",s)}),l(d.Divider,{my:"xs",label:"Format",labelPosition:"center"}),l(jr,{value:t.formatter,onChange:s=>a("formatter",s)}),i&&l(Cy,{value:t,onChange:n})]})});function hV(e){const t=Array.from(e).sort((r,i)=>r-i),n=Math.floor(t.length/2);return t.length%2===0?(t[n-1]+t[n])/2:t[n]}function gV(e,t){const n=e[t],r=Number(n);return isFinite(r)?r:0}function lc(e,t,n){var r,i,o;try{const a=e.map(s=>gV(s,t));switch(n.type){case"sum":return ye.default.sum(a);case"mean":return ye.default.mean(a);case"median":return hV(a);case"max":return(r=ye.default.max(a))!=null?r:0;case"min":return(i=ye.default.min(a))!=null?i:0;case"quantile":return(o=No.quantile(a,n.config.p))!=null?o:0;default:return a}}catch(a){return console.error(a),null}}var _y=function(){},Co=function(){};process.env.NODE_ENV!=="production"&&(_y=function(e,t){!e&&typeof console<"u"&&console.warn(t)},Co=function(e,t){if(!e)throw new Error(t)});const vV=(e,t,n)=>Math.min(Math.max(n,e),t),Ey=(e,t,n)=>{const r=t-e;return r===0?1:(n-e)/r},uc=(e,t,n)=>-n*e+n*t+e,Ty=(e,t)=>n=>Math.max(Math.min(n,t),e),_o=e=>e%1?Number(e.toFixed(5)):e,os=/(-)?([\d]*\.?[\d])+/g,cc=/(#[0-9a-f]{6}|#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))/gi,mV=/^(#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))$/i;function Eo(e){return typeof e=="string"}const as={test:e=>typeof e=="number",parse:parseFloat,transform:e=>e},My=Object.assign(Object.assign({},as),{transform:Ty(0,1)});Object.assign(Object.assign({},as),{default:1});const To=(e=>({test:t=>Eo(t)&&t.endsWith(e)&&t.split(" ").length===1,parse:parseFloat,transform:t=>`${t}${e}`}))("%");Object.assign(Object.assign({},To),{parse:e=>To.parse(e)/100,transform:e=>To.transform(e*100)});const dc=(e,t)=>n=>Boolean(Eo(n)&&mV.test(n)&&n.startsWith(e)||t&&Object.prototype.hasOwnProperty.call(n,t)),Oy=(e,t,n)=>r=>{if(!Eo(r))return r;const[i,o,a,s]=r.match(os);return{[e]:parseFloat(i),[t]:parseFloat(o),[n]:parseFloat(a),alpha:s!==void 0?parseFloat(s):1}},Hr={test:dc("hsl","hue"),parse:Oy("hue","saturation","lightness"),transform:({hue:e,saturation:t,lightness:n,alpha:r=1})=>"hsla("+Math.round(e)+", "+To.transform(_o(t))+", "+To.transform(_o(n))+", "+_o(My.transform(r))+")"},yV=Ty(0,255),fc=Object.assign(Object.assign({},as),{transform:e=>Math.round(yV(e))}),Tr={test:dc("rgb","red"),parse:Oy("red","green","blue"),transform:({red:e,green:t,blue:n,alpha:r=1})=>"rgba("+fc.transform(e)+", "+fc.transform(t)+", "+fc.transform(n)+", "+_o(My.transform(r))+")"};function bV(e){let t="",n="",r="",i="";return e.length>5?(t=e.substr(1,2),n=e.substr(3,2),r=e.substr(5,2),i=e.substr(7,2)):(t=e.substr(1,1),n=e.substr(2,1),r=e.substr(3,1),i=e.substr(4,1),t+=t,n+=n,r+=r,i+=i),{red:parseInt(t,16),green:parseInt(n,16),blue:parseInt(r,16),alpha:i?parseInt(i,16)/255:1}}const pc={test:dc("#"),parse:bV,transform:Tr.transform},ss={test:e=>Tr.test(e)||pc.test(e)||Hr.test(e),parse:e=>Tr.test(e)?Tr.parse(e):Hr.test(e)?Hr.parse(e):pc.parse(e),transform:e=>Eo(e)?e:e.hasOwnProperty("red")?Tr.transform(e):Hr.transform(e)},Dy="${c}",Ry="${n}";function wV(e){var t,n,r,i;return isNaN(e)&&Eo(e)&&((n=(t=e.match(os))===null||t===void 0?void 0:t.length)!==null&&n!==void 0?n:0)+((i=(r=e.match(cc))===null||r===void 0?void 0:r.length)!==null&&i!==void 0?i:0)>0}function ky(e){typeof e=="number"&&(e=`${e}`);const t=[];let n=0;const r=e.match(cc);r&&(n=r.length,e=e.replace(cc,Dy),t.push(...r.map(ss.parse)));const i=e.match(os);return i&&(e=e.replace(os,Ry),t.push(...i.map(as.parse))),{values:t,numColors:n,tokenised:e}}function Ay(e){return ky(e).values}function Py(e){const{values:t,numColors:n,tokenised:r}=ky(e),i=t.length;return o=>{let a=r;for(let s=0;s<i;s++)a=a.replace(s<n?Dy:Ry,s<n?ss.transform(o[s]):_o(o[s]));return a}}const xV=e=>typeof e=="number"?0:e;function SV(e){const t=Ay(e);return Py(e)(t.map(xV))}const Ny={test:wV,parse:Ay,createTransformer:Py,getAnimatableNone:SV};function hc(e,t,n){return n<0&&(n+=1),n>1&&(n-=1),n<1/6?e+(t-e)*6*n:n<1/2?t:n<2/3?e+(t-e)*(2/3-n)*6:e}function Iy({hue:e,saturation:t,lightness:n,alpha:r}){e/=360,t/=100,n/=100;let i=0,o=0,a=0;if(!t)i=o=a=n;else{const s=n<.5?n*(1+t):n+t-n*t,u=2*n-s;i=hc(u,s,e+1/3),o=hc(u,s,e),a=hc(u,s,e-1/3)}return{red:Math.round(i*255),green:Math.round(o*255),blue:Math.round(a*255),alpha:r}}const CV=(e,t,n)=>{const r=e*e,i=t*t;return Math.sqrt(Math.max(0,n*(i-r)+r))},_V=[pc,Tr,Hr],$y=e=>_V.find(t=>t.test(e)),Ly=e=>`'${e}' is not an animatable color. Use the equivalent color code instead.`,Vy=(e,t)=>{let n=$y(e),r=$y(t);Co(!!n,Ly(e)),Co(!!r,Ly(t));let i=n.parse(e),o=r.parse(t);n===Hr&&(i=Iy(i),n=Tr),r===Hr&&(o=Iy(o),r=Tr);const a=Object.assign({},i);return s=>{for(const u in a)u!=="alpha"&&(a[u]=CV(i[u],o[u],s));return a.alpha=uc(i.alpha,o.alpha,s),n.transform(a)}},EV=e=>typeof e=="number",TV=(e,t)=>n=>t(e(n)),zy=(...e)=>e.reduce(TV);function Fy(e,t){return EV(e)?n=>uc(e,t,n):ss.test(e)?Vy(e,t):jy(e,t)}const By=(e,t)=>{const n=[...e],r=n.length,i=e.map((o,a)=>Fy(o,t[a]));return o=>{for(let a=0;a<r;a++)n[a]=i[a](o);return n}},MV=(e,t)=>{const n=Object.assign(Object.assign({},e),t),r={};for(const i in n)e[i]!==void 0&&t[i]!==void 0&&(r[i]=Fy(e[i],t[i]));return i=>{for(const o in r)n[o]=r[o](i);return n}};function Gy(e){const t=Ny.parse(e),n=t.length;let r=0,i=0,o=0;for(let a=0;a<n;a++)r||typeof t[a]=="number"?r++:t[a].hue!==void 0?o++:i++;return{parsed:t,numNumbers:r,numRGB:i,numHSL:o}}const jy=(e,t)=>{const n=Ny.createTransformer(t),r=Gy(e),i=Gy(t);return r.numHSL===i.numHSL&&r.numRGB===i.numRGB&&r.numNumbers>=i.numNumbers?zy(By(r.parsed,i.parsed),n):(_y(!0,`Complex values '${e}' and '${t}' too different to mix. Ensure all colors are of the same type, and that each contains the same quantity of number and color values. Falling back to instant transition.`),a=>`${a>0?t:e}`)},OV=(e,t)=>n=>uc(e,t,n);function DV(e){if(typeof e=="number")return OV;if(typeof e=="string")return ss.test(e)?Vy:jy;if(Array.isArray(e))return By;if(typeof e=="object")return MV}function RV(e,t,n){const r=[],i=n||DV(e[0]),o=e.length-1;for(let a=0;a<o;a++){let s=i(e[a],e[a+1]);if(t){const u=Array.isArray(t)?t[a]:t;s=zy(u,s)}r.push(s)}return r}function kV([e,t],[n]){return r=>n(Ey(e,t,r))}function AV(e,t){const n=e.length,r=n-1;return i=>{let o=0,a=!1;if(i<=e[0]?a=!0:i>=e[r]&&(o=r-1,a=!0),!a){let u=1;for(;u<n&&!(e[u]>i||u===r);u++);o=u-1}const s=Ey(e[o],e[o+1],i);return t[o](s)}}function ls(e,t,{clamp:n=!0,ease:r,mixer:i}={}){const o=e.length;Co(o===t.length,"Both input and output ranges must be the same length"),Co(!r||!Array.isArray(r)||r.length===o-1,"Array of easing functions must be of length `input.length - 1`, as it applies to the transitions **between** the defined values."),e[0]>e[o-1]&&(e=[].concat(e),t=[].concat(t),e.reverse(),t.reverse());const a=RV(t,r,i),s=o===2?kV(e,a):AV(e,a);return n?u=>s(vV(e[0],e[o-1],u)):s}class PV{constructor({valueRange:t,colorRange:n}){ke(this,"mapper");this.mapper=ls(t,n)}getColor(t){return this.mapper(t)}}function NV(e){return e===null?"null":e===void 0?"undefined":Array.isArray(e)?`Array(${e.length})`:e.toString()}function us({data_field:e,aggregation:t},n){return lc(n,e,t)}function Ri({formatter:e},t){return["string","number"].includes(typeof t)?Ft.default(t).format(e):NV(t)}function IV(e,t){if(e.type==="static")return e.staticColor;if(e.type==="continuous")try{if(Array.isArray(t)||t===null)throw new Error(`[getColorByColorConf] Invalid type of aggregated value: ${t}`);return new PV(e).getColor(t)}catch(n){return console.error(n),"black"}return"black"}function Ky(e,t){const{color:n,data_field:r,aggregation:i,size:o,weight:a}=e,s=lc(t,r,i),u=Ri(e,s);return l(d.Text,{sx:{fontSize:o,display:"inline"},color:IV(n,s),weight:a,children:u})}function $V(e,t){const n={};return e.forEach(r=>{const i=r.name;n[i]=Ky(r,t)}),n}function LV(e){return e.split(" ").map((t,n)=>b(W.default.Fragment,{children:[t,"\xA0"]},n))}function VV(e){const n=e.replaceAll("<br />","<br/>").replaceAll(`
153
153
  `,"<br/>").split("<br/>");return n.map((i,o)=>{const a=[LV(i)];return o!==n.length-1&&a.push(l("br",{})),a}).flat().filter(i=>i!==void 0)}function gc(e){return VV(e)}function Mo(e,t,n){const r=$V(t,n),i=/^\{(.+)\}(.*)$/;return e.split("$").map(o=>{var c;const a=i.exec(o);if(!a)return gc(o);const s=r[a[1]];if(!s)return gc(o);const u=(c=a[2])!=null?c:"";return b(De,{children:[s,gc(u)]})})}function zV(e,t){const n={};return e.forEach(r=>{const{name:i,data_field:o,aggregation:a}=r,s=lc(t,o,a);n[i]=Ri(r,s)}),n}function vc(e,t,n){const r=zV(t,n),i=/^\{(.+)\}(.*)$/;return e.split("$").map(o=>{var c;const a=i.exec(o);if(!a)return o;const s=r[a[1]];if(!s)return o;const u=(c=a[2])!=null?c:"";return`${s}${u}`}).join("")}function cs({enabled:e,func_content:t}){return(n,r)=>{if(!e)return n;try{return new Function(`return ${t}`)()(n,r)}catch(i){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${i.message}`),n}}}function ds(e){return{width:e.width,overflow:e.overflow,ellipsis:e.ellipsis}}function Oo(e){const t={truncate:"initial",break:"break-all",breakAll:"break-word"}[e.overflow],n=e.overflow==="truncate"?"nowrap":"initial",r={truncate:"ellipsis",break:"clip",breakAll:"clip"}[e.overflow];return`
154
154
  max-width: ${e.width}px;
@@ -264,7 +264,7 @@ WHERE
264
264
  ${i.join("")}
265
265
  </tbody>
266
266
  </table>
267
- `}}const yB={legend:{show:!0,bottom:0,left:0},tooltip:{trigger:"item"}};function bB(e,t){const n=["#66B4DB","#39BFA2","#E46464","#33A678","#EEBA00","#9D88CB","#939943","#E49792","#09A2B8","#AF5F6B","#6CA157","#09A2B8","#6398C7","#E692BA","#97B566","#8CACE2","#CA79AC","#6DBC80","#B08F4B","#826BAF"],r=e.dimensions.map(({name:a,max:s})=>({name:a,max:s})),i=t.map(a=>({value:e.dimensions.map(({data_key:s})=>a[s]),name:a[e.series_name_key]})),o={radar:{indicator:r,splitArea:{show:!1}},tooltip:{confine:!0,formatter:mB(e)},legend:{show:!0,left:"center"},series:{type:"radar",data:i,symbolSize:4,lineStyle:{width:1},areaStyle:{opacity:.4},label:vB(e)},color:n};return ye.default.merge({},yB,o)}const Tc={series_name_key:"name",dimensions:[]};Rt.use([dn.RadarChart,ut.GridComponent,ut.LegendComponent,ut.TooltipComponent,Kn.CanvasRenderer]);function wB({context:e}){const{value:t}=et(e.instanceData,"config"),{width:n,height:r}=e.viewport,i=e.data,o=x.useMemo(()=>bB(H.defaultsDeep({},t,Tc),i),[t,i]);return!n||!r||!t||H.isEmpty(t==null?void 0:t.dimensions)?null:l(d.Box,{children:l(Hn.default,{echarts:Rt,option:o,style:{width:n,height:r}})})}function xB({control:e,index:t,remove:n,data:r}){return b(d.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[b(d.Group,{grow:!0,noWrap:!0,children:[l(G.Controller,{name:`dimensions.${t}.name`,control:e,render:({field:i})=>l(d.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})}),l(G.Controller,{name:`dimensions.${t}.data_key`,control:e,render:({field:i})=>l(mt,{label:"Data Key",required:!0,data:r,sx:{flex:1},...i})}),l(G.Controller,{name:`dimensions.${t}.max`,control:e,render:({field:i})=>l(d.NumberInput,{label:"Max",hideControls:!0,required:!0,sx:{flex:1},...i})})]}),b(d.Stack,{children:[l(d.Divider,{mb:-15,variant:"dashed",label:"Value Formatter",labelPosition:"center"}),l(G.Controller,{name:`dimensions.${t}.formatter`,control:e,render:({field:i})=>l(jr,{...i})})]}),l(d.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(t),sx:{position:"absolute",top:15,right:5},disabled:t===0,children:l(te.Trash,{size:16})})]},t)}function SB({control:e,watch:t,data:n}){const{fields:r,append:i,remove:o}=G.useFieldArray({control:e,name:"dimensions"}),a=t("dimensions"),s=r.map((c,f)=>({...c,...a[f]})),u=()=>i({name:wt.randomId(),data_key:"",max:100,formatter:Fn});return b(d.Stack,{children:[s.map((c,f)=>l(xB,{data:n,control:e,index:f,remove:o})),l(d.Group,{position:"center",mt:"xs",children:l(d.Button,{onClick:u,children:"Add a Dimension"})})]})}function CB(e){function t({name:n="",data_key:r="",max:i=10,formatter:o=Fn}){return{name:n,data_key:r,max:i,formatter:o}}return e.map(t)}function _B({context:e}){const t=e.data,{value:n,set:r}=et(e.instanceData,"config"),i=x.useMemo(()=>H.defaultsDeep({},n,Tc),[n]),{dimensions:o,series_name_key:a}=i,s=x.useMemo(()=>({dimensions:CB(o!=null?o:[]),series_name_key:a}),[o,a]);x.useEffect(()=>{!H.isEqual(i,s)&&r(s)},[i,s]);const{control:u,handleSubmit:c,watch:f,getValues:h,reset:p}=G.useForm({defaultValues:s});x.useEffect(()=>{H.isEqual(h(),s)||p(s)},[i]),f(["series_name_key"]);const g=h(),v=x.useMemo(()=>!H.isEqual(g,i),[g,i]);return l(d.Stack,{mt:"md",spacing:"xs",children:b("form",{onSubmit:c(r),children:[b(d.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[l(d.Text,{children:"Chart Config"}),l(d.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!v,children:l(te.DeviceFloppy,{size:20})})]}),l(d.Box,{py:"sm",children:l(G.Controller,{name:"series_name_key",control:u,render:({field:m})=>l(mt,{label:"Series Name Field",required:!0,data:t,sx:{flex:1},...m})})}),l(SB,{control:u,watch:f,data:t})]})})}class EB extends en{constructor(){super(...arguments);ke(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const TB={displayName:"Radar Chart",migrator:new EB,name:"radar",viewRender:wB,configRender:_B,createConfig(){return{version:1,config:H.cloneDeep(Tc)}}};function MB(e,t){switch(e.config.method){case"linear":return[...lr.regressionLinear()(t)];case"exponential":return[...lr.regressionExp()(t)];case"logarithmic":return[...lr.regressionLog()(t)];case"polynomial":return[...lr.regressionPoly().order(e.config.order)(t)];default:return[]}}function OB({regression:e},t){const n=[],r=[];if(t.length===0)return{regressionSeries:n,regressionXAxes:r};const{transform:i,plot:o,name:a}=e,s=MB(i,t);return n.push({...o,name:a,data:s,showSymbol:!1,smooth:!0,tooltip:{show:!1}}),{regressionSeries:n,regressionXAxes:r}}const DB={tooltip:{trigger:"axis"},grid:{top:10,left:30,right:15,bottom:30,containLabel:!0},dataZoom:[{type:"inside",xAxisIndex:[0]},{type:"inside",yAxisIndex:[0]}]};function RB(e,t){var o,a;const n=ye.default.uniqBy(t.map(s=>[s[e.x_axis.data_key],s[e.regression.y_axis_data_key]]),0),{regressionSeries:r}=OB(e,n),i={xAxis:{type:"category",name:(o=e.x_axis.name)!=null?o:"",axisTick:{show:!0,alignWithLabel:!0}},yAxis:{name:(a=e.y_axis.name)!=null?a:"",axisLine:{show:!0}},series:[{data:n,name:e.y_axis.name,type:"scatter",symbolSize:4,color:"red"},...r]};return H.defaultsDeep({},i,DB)}function hs(e,t,n){return 1-(1-e)*(t-1)/(t-n-1)}function kB(e,t){if(!t)return{expression:"",rSquared:0,adjustedRSquared:0};const{regression:n,x_axis:r,y_axis:i}=t,o=e.map(a=>[a[r.data_key],a[n.y_axis_data_key]]);if(n.transform.config.method==="linear"){const a=lr.regressionLinear()(o),{a:s,b:u,rSquared:c}=a;return{expression:b(d.Group,{position:"center",noWrap:!0,spacing:10,children:[l(d.Text,{children:i.name}),l(d.Text,{children:"="}),l(d.Text,{weight:"bold",color:"gray",children:u}),l(d.Text,{children:"+"}),l(d.Text,{weight:"bold",color:"gray",children:s}),l(d.Text,{children:"\xD7"}),l(d.Text,{children:r.name})]}),rSquared:c,adjustedRSquared:hs(c,e.length,1)}}if(n.transform.config.method==="exponential"){const{a,b:s,rSquared:u}=lr.regressionExp()(o);return{expression:b(d.Group,{position:"center",noWrap:!0,spacing:10,children:[l(d.Text,{children:i.name}),l(d.Text,{children:"="}),l(d.Text,{weight:"bold",color:"gray",children:a}),l(d.Text,{children:"\xD7"}),b(d.Group,{position:"left",noWrap:!0,spacing:2,children:[l(d.Text,{children:"Math.exp("}),l(d.Text,{weight:"bold",color:"gray",children:s}),l(d.Text,{children:"\xD7"}),l(d.Text,{children:r.name}),l(d.Text,{children:")"})]})]}),rSquared:u,adjustedRSquared:hs(u,e.length,1)}}if(n.transform.config.method==="logarithmic"){const{a,b:s,rSquared:u}=lr.regressionLog()(o);return{expression:b(d.Group,{position:"center",noWrap:!0,spacing:10,children:[l(d.Text,{children:i.name}),l(d.Text,{children:"="}),l(d.Text,{weight:"bold",color:"gray",children:a}),l(d.Text,{children:"\xD7"}),b(d.Group,{position:"left",noWrap:!0,spacing:2,children:[l(d.Text,{children:"Math.log("}),l(d.Text,{children:r.name}),l(d.Text,{children:")"}),l(d.Text,{children:"+"}),l(d.Text,{weight:"bold",color:"gray",children:s})]})]}),rSquared:u,adjustedRSquared:hs(u,e.length,1)}}if(n.transform.config.method==="polynomial"){const a=lr.regressionPoly().order(n.transform.config.order)(o),{rSquared:s}=a;return console.log(a),{expression:"",rSquared:s,adjustedRSquared:hs(s,e.length,1)}}return{expression:"",rSquared:0}}const Mc={x_axis:{name:"X Axis",data_key:""},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",y_axis_data_key:"value"}};Rt.use([ut.DataZoomComponent,dn.ScatterChart,ut.GridComponent,ut.LegendComponent,ut.TooltipComponent,Kn.CanvasRenderer]),Rt.registerTransform(Cs.transform.regression);function AB({context:e}){const{value:t}=et(e.instanceData,"config"),{width:n,height:r}=e.viewport,i=x.useMemo(()=>{var p;const f=e.data,h=(p=t==null?void 0:t.regression)==null?void 0:p.y_axis_data_key;return h?f.map(g=>typeof g[h]=="number"?g:{...g,[h]:Number(g[h])}):f},[e.data,t==null?void 0:t.regression.y_axis_data_key]),o=x.useMemo(()=>RB(H.defaultsDeep({},t,Mc),i),[t,i]),{expression:a,rSquared:s,adjustedRSquared:u}=x.useMemo(()=>kB(i,t),[t,i]);if(!n||!r||!t)return null;let c=r;return a&&(c-=20),b(d.Box,{children:[a&&l(d.Text,{align:"center",size:12,children:a}),b(d.Group,{spacing:0,noWrap:!0,align:"start",sx:{"> *":{flexGrow:0,flexShrink:0}},children:[l(Hn.default,{echarts:Rt,option:o,style:{width:n-190,height:c}}),s&&l(d.Table,{mt:20,fontSize:12,sx:{width:180,border:"1px solid #999",td:{padding:"3px 8px"}},children:b("tbody",{children:[b("tr",{children:[l("td",{children:"R-Sq"}),l("td",{style:{textAlign:"right"},children:Ft.default(s).format({output:"percent",mantissa:1})})]}),b("tr",{children:[l("td",{children:"R-Sq(Adjusted)"}),l("td",{style:{textAlign:"right"},children:Ft.default(u).format({output:"percent",mantissa:1})})]})]})})]})]})}const PB=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}];function NB({control:e,watch:t,data:n}){const r=t("regression.transform.config.method");return b(d.Stack,{children:[b(d.Group,{grow:!0,noWrap:!0,children:[l(G.Controller,{name:"regression.name",control:e,render:({field:i})=>l(d.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})}),l(G.Controller,{name:"regression.y_axis_data_key",control:e,render:({field:i})=>l(mt,{label:"Value Field",required:!0,data:n,sx:{flex:1},...i})})]}),b(d.Group,{grow:!0,noWrap:!0,children:[l(G.Controller,{name:"regression.transform.config.method",control:e,render:({field:i})=>l(d.Select,{label:"Method",data:PB,sx:{flex:1},...i})}),r==="polynomial"&&l(G.Controller,{name:"regression.transform.config.order",control:e,render:({field:i})=>l(d.NumberInput,{label:"Order",sx:{flex:1},...i})})]}),b(d.Stack,{spacing:4,children:[l(d.Text,{size:"sm",children:"Color"}),l(G.Controller,{name:"regression.plot.color",control:e,render:({field:i})=>l(kn,{...i})})]})]})}function IB({context:e}){const{value:t,set:n}=et(e.instanceData,"config"),r=e.data,i=x.useMemo(()=>H.defaults({},t,Mc),[t]),{control:o,handleSubmit:a,watch:s,getValues:u,reset:c}=G.useForm({defaultValues:i});x.useEffect(()=>{c(i)},[i]),s(["x_axis","y_axis","regression"]);const f=u(),h=x.useMemo(()=>!H.isEqual(f,t),[f,t]);return l(d.Stack,{mt:"md",spacing:"xs",children:b("form",{onSubmit:a(n),children:[b(d.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[l(d.Text,{children:"Chart Config"}),l(d.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:l(te.DeviceFloppy,{size:20})})]}),b(d.Accordion,{multiple:!0,defaultValue:["Axis","Regression"],children:[b(d.Accordion.Item,{value:"Axis",children:[l(d.Accordion.Control,{children:"Axis"}),b(d.Accordion.Panel,{children:[b(d.Group,{grow:!0,noWrap:!0,children:[l(G.Controller,{name:"x_axis.name",control:o,render:({field:p})=>l(d.TextInput,{label:"X Axis Name",sx:{flex:1},...p})}),l(G.Controller,{name:"x_axis.data_key",control:o,render:({field:p})=>l(mt,{label:"X Axis Data Field",required:!0,data:r,sx:{flex:1},...p})})]}),l(d.Group,{grow:!0,noWrap:!0,children:l(G.Controller,{name:"y_axis.name",control:o,render:({field:p})=>l(d.TextInput,{label:"Y Axis Name",sx:{flex:1},...p})})})]})]}),b(d.Accordion.Item,{value:"Regression",children:[l(d.Accordion.Control,{children:"Regression Line"}),l(d.Accordion.Panel,{children:l(NB,{control:o,watch:s,data:r})})]})]})]})})}class $B extends en{constructor(){super(...arguments);ke(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const LB={displayName:"Regression Chart",migrator:new $B,name:"regressionChart",viewRender:AB,configRender:IB,createConfig(){return{version:1,config:H.cloneDeep(Mc)}}},gs={content:""};function VB({context:e}){const{value:t}=et(e.instanceData,"config"),n=x.useMemo(()=>H.defaults({},t,gs),[t]);return n!=null&&n.content?l(ty,{value:n.content,styles:{root:{border:"none",height:"100%"},content:{padding:0}}}):null}const Jy=x.forwardRef(({value:e,onChange:t,styles:n={},label:r,onSubmit:i},o)=>{const[a,s]=x.useState(e),u=Uc.useEditor({extensions:[Xc.default,ey,rt.Link,Zm,Qm,Ym,Jm.configure({types:["heading","paragraph"]}),Xm.configure({placeholder:"This is placeholder"}),Wm,Um],content:a,onUpdate:({editor:p})=>{s(p.getHTML())}});x.useEffect(()=>{s(e),u==null||u.commands.setContent(e)},[e]);const c=()=>{t(a),i==null||i()},f=e!==a,h=x.useMemo(()=>ye.default.defaultsDeep({},{content:rc},n),[n]);return b(d.Stack,{spacing:4,sx:{flexGrow:1,position:"relative"},children:[b(d.Group,{align:"center",children:[l(d.Text,{size:14,fw:500,children:r}),l(d.ActionIcon,{color:"blue",disabled:!f,onClick:c,children:l(mm,{size:18})})]}),b(rt.RichTextEditor,{editor:u,styles:h,children:[b(rt.RichTextEditor.Toolbar,{sticky:!0,stickyOffset:0,children:[l(rt.RichTextEditor.ControlsGroup,{children:l(rt.RichTextEditor.ColorPicker,{colors:["#25262b","#868e96","#fa5252","#e64980","#be4bdb","#7950f2","#4c6ef5","#228be6","#15aabf","#12b886","#40c057","#82c91e","#fab005","#fd7e14"]})}),b(rt.RichTextEditor.ControlsGroup,{children:[l(rt.RichTextEditor.Bold,{}),l(rt.RichTextEditor.Italic,{}),l(rt.RichTextEditor.Underline,{}),l(rt.RichTextEditor.Strikethrough,{}),l(rt.RichTextEditor.ClearFormatting,{}),l(rt.RichTextEditor.Highlight,{}),l(rt.RichTextEditor.Code,{})]}),b(rt.RichTextEditor.ControlsGroup,{children:[l(rt.RichTextEditor.H1,{}),l(rt.RichTextEditor.H2,{}),l(rt.RichTextEditor.H3,{}),l(rt.RichTextEditor.H4,{})]}),b(rt.RichTextEditor.ControlsGroup,{children:[l(rt.RichTextEditor.Blockquote,{}),l(rt.RichTextEditor.Hr,{}),l(rt.RichTextEditor.BulletList,{}),l(rt.RichTextEditor.OrderedList,{}),l(rt.RichTextEditor.Subscript,{}),l(rt.RichTextEditor.Superscript,{})]}),b(rt.RichTextEditor.ControlsGroup,{children:[l(rt.RichTextEditor.Link,{}),l(rt.RichTextEditor.Unlink,{})]}),b(rt.RichTextEditor.ControlsGroup,{children:[l(rt.RichTextEditor.AlignLeft,{}),l(rt.RichTextEditor.AlignCenter,{}),l(rt.RichTextEditor.AlignJustify,{}),l(rt.RichTextEditor.AlignRight,{})]})]}),l(rt.RichTextEditor.Content,{})]})]})});function zB({context:e}){const{value:t,set:n}=et(e.instanceData,"config"),r=x.useMemo(()=>H.defaults({},t,gs),[t]);console.log({conf:t,defaultValues:r});const{control:i,handleSubmit:o,watch:a,reset:s}=G.useForm({defaultValues:r});a("content"),x.useEffect(()=>{s(r)},[r]);const u=x.useRef(null),c=()=>{var f;return(f=u.current)==null?void 0:f.click()};return l("form",{onSubmit:o(n),style:{flexGrow:1,display:"flex",flexDirection:"column"},children:b(d.Stack,{spacing:"xs",sx:{flexGrow:1},children:[b(d.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",display:"none"},children:[l(d.Text,{children:"Content"}),l(d.ActionIcon,{ref:u,type:"submit",mr:5,variant:"filled",color:"blue",children:l(te.DeviceFloppy,{size:20})})]}),l(G.Controller,{name:"content",control:i,render:({field:f})=>l(Jy,{...f,styles:{root:{flexGrow:1}},label:"Content",onSubmit:c})})]})})}class FB extends en{constructor(){super(...arguments);ke(this,"VERSION",1)}fixMalformedConfig(n){return H.defaults({},n,gs)}configVersions(){this.version(1,n=>({version:1,config:this.fixMalformedConfig(n)}))}}const BB={displayName:"Rich Text",migrator:new FB,name:"richText",viewRender:VB,configRender:zB,createConfig(){return{version:1,config:H.cloneDeep(gs)}}},Oc={align:"center",template:"The variable ${value} is defined in Variables section"};function GB(e){if("variables"in e)return e;const{align:t,size:n,weight:r,color:i,content:{prefix:o="",data_field:a="value",formatter:s={output:"number",mantissa:0},postfix:u=""}={}}=e;return{align:t,template:`${o} \${value} ${u}`,variables:[{name:"value",data_field:a,aggregation:{type:"none",config:{}},formatter:s,color:i,weight:r,size:n}]}}function jB(e){return H.omit(e,["variables"])}function KB(e){const t=H.cloneDeep(e),n=H.get(t,"color.valueRange");return n!==void 0&&H.set(t,"color.valueRange",n.map(r=>Number(r))),t}class HB extends en{constructor(){super(...arguments);ke(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:GB(n)})),this.version(2,(n,{panelModel:r})=>{const{config:i}=n;return(i.variables||[]).forEach(a=>{r.variables.find(s=>s.name===a.name)||r.addVariable(KB(a))}),{...n,version:2,config:jB(i)}})}}const qB=se.observer(({context:e})=>{const t=Ze(),{value:n=Oc}=et(e.instanceData,"config"),{variables:r}=e,{template:i,align:o}=n,a=x.useMemo(()=>{try{const u={filters:t.filters.values,context:t.context.current};return ye.default.template(i)(u)}catch{return i}},[t.filters.values,t.context.current,i]),s=x.useMemo(()=>Mo(a,r,e.data),[a,r,e.data,e]);return l(d.Text,{align:o,children:Object.values(s).map((u,c)=>l(W.default.Fragment,{children:u},c))})}),WB=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}];function UB({context:e}){const{value:t,set:n}=et(e.instanceData,"config"),r=W.default.useMemo(()=>{const{align:h,template:p=""}=H.defaultsDeep({},t,Oc);return{template:p,align:h}},[t]),{control:i,handleSubmit:o,watch:a,getValues:s,reset:u}=G.useForm({defaultValues:r});W.default.useEffect(()=>{u(r)},[r]),a(["template","align"]);const c=s(),f=W.default.useMemo(()=>!ye.default.isEqual(c,t),[c,t]);return l(d.Stack,{mt:"md",spacing:"xs",children:b("form",{onSubmit:o(n),children:[b(d.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[l(d.Text,{weight:500,children:"Stats Configurations"}),l(d.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:l(te.DeviceFloppy,{size:20})})]}),l(G.Controller,{name:"template",control:i,render:({field:h})=>l(So,{label:"Template",py:"md",sx:{flexGrow:1},...h})}),l(G.Controller,{name:"align",control:i,render:({field:h})=>l(d.Select,{label:"Horizontal Alignment",data:WB,...h})})]})})}const YB={createConfig(){return{version:2,config:Oc}},displayName:"Stats",migrator:new HB,name:"stats",viewRender:qB,configRender:UB},Dc={label_key:"",value_key:"",group_key:"",levels:[]};function XB(e){const t=new Set(e.map(r=>r.parent_id)),n=new Set(e.map(r=>r.id));return t.forEach(r=>{r===null||n.has(r)||e.push({id:r,name:r,parent_id:null})}),e}function QB(e){const t=XB(e).map(i=>({...i,children:[]})),n=ye.default.keyBy(t,i=>i.id),r=[];return t.forEach(i=>{if(!i.parent_id||!n[i.parent_id]){r.push(i);return}n[i.parent_id].children.push(i)}),r}function ZB(e,t){const{label_key:n,value_key:r,group_key:i}=e,o=n,a=t.map(s=>({...s,id:s[o],parent_id:s[i],name:s[n],value:s[r]?Number(s[r]):s[r]}));return i?QB(a):a}const JB=e=>({treePathInfo:t,name:n,value:r})=>{if(t.length===1||!e)return n;try{const i=t[t.length-2].value;if(r/i<e)return" "}catch{return n}};function e3(e){const{levels:t}=e;return t.map(n=>{const{show_label_tolerance:r,...i}=n.label;return{...n,label:{...i,formatter:JB(r)}}})}function t3(){return({treePathInfo:e,name:t,value:n,color:r,marker:i,...o})=>{console.log({rest:o});const a=e.slice(0,e.length-1),s=[`<tr>
267
+ `}}const yB={legend:{show:!0,bottom:0,left:0},tooltip:{trigger:"item"}};function bB(e,t){const n=["#66B4DB","#39BFA2","#E46464","#33A678","#EEBA00","#9D88CB","#939943","#E49792","#09A2B8","#AF5F6B","#6CA157","#09A2B8","#6398C7","#E692BA","#97B566","#8CACE2","#CA79AC","#6DBC80","#B08F4B","#826BAF"],r=e.dimensions.map(({name:a,max:s})=>({name:a,max:s})),i=t.map(a=>({value:e.dimensions.map(({data_key:s})=>a[s]),name:a[e.series_name_key]})),o={radar:{indicator:r,splitArea:{show:!1}},tooltip:{confine:!0,formatter:mB(e)},legend:{show:!0,left:"center"},series:{type:"radar",data:i,symbolSize:4,lineStyle:{width:1},areaStyle:{opacity:.4},label:vB(e)},color:n};return ye.default.merge({},yB,o)}const Tc={series_name_key:"name",dimensions:[]};Rt.use([dn.RadarChart,ut.GridComponent,ut.LegendComponent,ut.TooltipComponent,Kn.CanvasRenderer]);function wB({context:e}){const{value:t}=et(e.instanceData,"config"),{width:n,height:r}=e.viewport,i=e.data,o=x.useMemo(()=>bB(H.defaultsDeep({},t,Tc),i),[t,i]);return!n||!r||!t||H.isEmpty(t==null?void 0:t.dimensions)?null:l(d.Box,{children:l(Hn.default,{echarts:Rt,option:o,style:{width:n,height:r}})})}function xB({control:e,index:t,remove:n,data:r}){return b(d.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[b(d.Group,{grow:!0,noWrap:!0,children:[l(G.Controller,{name:`dimensions.${t}.name`,control:e,render:({field:i})=>l(d.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})}),l(G.Controller,{name:`dimensions.${t}.data_key`,control:e,render:({field:i})=>l(mt,{label:"Data Key",required:!0,data:r,sx:{flex:1},...i})}),l(G.Controller,{name:`dimensions.${t}.max`,control:e,render:({field:i})=>l(d.NumberInput,{label:"Max",hideControls:!0,required:!0,sx:{flex:1},...i})})]}),b(d.Stack,{children:[l(d.Divider,{mb:-15,variant:"dashed",label:"Value Formatter",labelPosition:"center"}),l(G.Controller,{name:`dimensions.${t}.formatter`,control:e,render:({field:i})=>l(jr,{...i})})]}),l(d.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(t),sx:{position:"absolute",top:15,right:5},disabled:t===0,children:l(te.Trash,{size:16})})]},t)}function SB({control:e,watch:t,data:n}){const{fields:r,append:i,remove:o}=G.useFieldArray({control:e,name:"dimensions"}),a=t("dimensions"),s=r.map((c,f)=>({...c,...a[f]})),u=()=>i({name:wt.randomId(),data_key:"",max:100,formatter:Fn});return b(d.Stack,{children:[s.map((c,f)=>l(xB,{data:n,control:e,index:f,remove:o})),l(d.Group,{position:"center",mt:"xs",children:l(d.Button,{onClick:u,children:"Add a Dimension"})})]})}function CB(e){function t({name:n="",data_key:r="",max:i=10,formatter:o=Fn}){return{name:n,data_key:r,max:i,formatter:o}}return e.map(t)}function _B({context:e}){const t=e.data,{value:n,set:r}=et(e.instanceData,"config"),i=x.useMemo(()=>H.defaultsDeep({},n,Tc),[n]),{dimensions:o,series_name_key:a}=i,s=x.useMemo(()=>({dimensions:CB(o!=null?o:[]),series_name_key:a}),[o,a]);x.useEffect(()=>{!H.isEqual(i,s)&&r(s)},[i,s]);const{control:u,handleSubmit:c,watch:f,getValues:h,reset:p}=G.useForm({defaultValues:s});x.useEffect(()=>{H.isEqual(h(),s)||p(s)},[i]),f(["series_name_key"]);const g=h(),v=x.useMemo(()=>!H.isEqual(g,i),[g,i]);return l(d.Stack,{mt:"md",spacing:"xs",children:b("form",{onSubmit:c(r),children:[b(d.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[l(d.Text,{children:"Chart Config"}),l(d.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!v,children:l(te.DeviceFloppy,{size:20})})]}),l(d.Box,{py:"sm",children:l(G.Controller,{name:"series_name_key",control:u,render:({field:m})=>l(mt,{label:"Series Name Field",required:!0,data:t,sx:{flex:1},...m})})}),l(SB,{control:u,watch:f,data:t})]})})}class EB extends en{constructor(){super(...arguments);ke(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const TB={displayName:"Radar Chart",migrator:new EB,name:"radar",viewRender:wB,configRender:_B,createConfig(){return{version:1,config:H.cloneDeep(Tc)}}};function MB(e,t){switch(e.config.method){case"linear":return[...lr.regressionLinear()(t)];case"exponential":return[...lr.regressionExp()(t)];case"logarithmic":return[...lr.regressionLog()(t)];case"polynomial":return[...lr.regressionPoly().order(e.config.order)(t)];default:return[]}}function OB({regression:e},t){const n=[],r=[];if(t.length===0)return{regressionSeries:n,regressionXAxes:r};const{transform:i,plot:o,name:a}=e,s=MB(i,t);return n.push({...o,name:a,data:s,showSymbol:!1,smooth:!0,tooltip:{show:!1}}),{regressionSeries:n,regressionXAxes:r}}const DB={tooltip:{trigger:"axis"},grid:{top:10,left:30,right:15,bottom:30,containLabel:!0},dataZoom:[{type:"inside",xAxisIndex:[0]},{type:"inside",yAxisIndex:[0]}]};function RB(e,t){var o,a;const n=ye.default.uniqBy(t.map(s=>[s[e.x_axis.data_key],s[e.regression.y_axis_data_key]]),0),{regressionSeries:r}=OB(e,n),i={xAxis:{type:"category",name:(o=e.x_axis.name)!=null?o:"",axisTick:{show:!0,alignWithLabel:!0}},yAxis:{name:(a=e.y_axis.name)!=null?a:"",axisLine:{show:!0}},series:[{data:n,name:e.y_axis.name,type:"scatter",symbolSize:4,color:"red"},...r]};return H.defaultsDeep({},i,DB)}function hs(e,t,n){return 1-(1-e)*(t-1)/(t-n-1)}function kB(e,t){if(!t)return{expression:"",rSquared:0,adjustedRSquared:0};const{regression:n,x_axis:r,y_axis:i}=t,o=e.map(a=>[a[r.data_key],a[n.y_axis_data_key]]);if(n.transform.config.method==="linear"){const a=lr.regressionLinear()(o),{a:s,b:u,rSquared:c}=a;return{expression:b(d.Group,{position:"center",noWrap:!0,spacing:10,children:[l(d.Text,{children:i.name}),l(d.Text,{children:"="}),l(d.Text,{weight:"bold",color:"gray",children:u}),l(d.Text,{children:"+"}),l(d.Text,{weight:"bold",color:"gray",children:s}),l(d.Text,{children:"\xD7"}),l(d.Text,{children:r.name})]}),rSquared:c,adjustedRSquared:hs(c,e.length,1)}}if(n.transform.config.method==="exponential"){const{a,b:s,rSquared:u}=lr.regressionExp()(o);return{expression:b(d.Group,{position:"center",noWrap:!0,spacing:10,children:[l(d.Text,{children:i.name}),l(d.Text,{children:"="}),l(d.Text,{weight:"bold",color:"gray",children:a}),l(d.Text,{children:"\xD7"}),b(d.Group,{position:"left",noWrap:!0,spacing:2,children:[l(d.Text,{children:"Math.exp("}),l(d.Text,{weight:"bold",color:"gray",children:s}),l(d.Text,{children:"\xD7"}),l(d.Text,{children:r.name}),l(d.Text,{children:")"})]})]}),rSquared:u,adjustedRSquared:hs(u,e.length,1)}}if(n.transform.config.method==="logarithmic"){const{a,b:s,rSquared:u}=lr.regressionLog()(o);return{expression:b(d.Group,{position:"center",noWrap:!0,spacing:10,children:[l(d.Text,{children:i.name}),l(d.Text,{children:"="}),l(d.Text,{weight:"bold",color:"gray",children:a}),l(d.Text,{children:"\xD7"}),b(d.Group,{position:"left",noWrap:!0,spacing:2,children:[l(d.Text,{children:"Math.log("}),l(d.Text,{children:r.name}),l(d.Text,{children:")"}),l(d.Text,{children:"+"}),l(d.Text,{weight:"bold",color:"gray",children:s})]})]}),rSquared:u,adjustedRSquared:hs(u,e.length,1)}}if(n.transform.config.method==="polynomial"){const a=lr.regressionPoly().order(n.transform.config.order)(o),{rSquared:s}=a;return console.log(a),{expression:"",rSquared:s,adjustedRSquared:hs(s,e.length,1)}}return{expression:"",rSquared:0}}const Mc={x_axis:{name:"X Axis",data_key:""},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",y_axis_data_key:"value"}};Rt.use([ut.DataZoomComponent,dn.ScatterChart,ut.GridComponent,ut.LegendComponent,ut.TooltipComponent,Kn.CanvasRenderer]),Rt.registerTransform(Cs.transform.regression);function AB({context:e}){const{value:t}=et(e.instanceData,"config"),{width:n,height:r}=e.viewport,i=x.useMemo(()=>{var p;const f=e.data,h=(p=t==null?void 0:t.regression)==null?void 0:p.y_axis_data_key;return h?f.map(g=>typeof g[h]=="number"?g:{...g,[h]:Number(g[h])}):f},[e.data,t==null?void 0:t.regression.y_axis_data_key]),o=x.useMemo(()=>RB(H.defaultsDeep({},t,Mc),i),[t,i]),{expression:a,rSquared:s,adjustedRSquared:u}=x.useMemo(()=>kB(i,t),[t,i]);if(!n||!r||!t)return null;let c=r;return a&&(c-=20),b(d.Box,{children:[a&&l(d.Text,{align:"center",size:12,children:a}),b(d.Group,{spacing:0,noWrap:!0,align:"start",sx:{"> *":{flexGrow:0,flexShrink:0}},children:[l(Hn.default,{echarts:Rt,option:o,style:{width:n-190,height:c}}),s&&l(d.Table,{mt:20,fontSize:12,sx:{width:180,border:"1px solid #999",td:{padding:"3px 8px"}},children:b("tbody",{children:[b("tr",{children:[l("td",{children:"R-Sq"}),l("td",{style:{textAlign:"right"},children:Ft.default(s).format({output:"percent",mantissa:1})})]}),b("tr",{children:[l("td",{children:"R-Sq(Adjusted)"}),l("td",{style:{textAlign:"right"},children:Ft.default(u).format({output:"percent",mantissa:1})})]})]})})]})]})}const PB=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}];function NB({control:e,watch:t,data:n}){const r=t("regression.transform.config.method");return b(d.Stack,{children:[b(d.Group,{grow:!0,noWrap:!0,children:[l(G.Controller,{name:"regression.name",control:e,render:({field:i})=>l(d.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})}),l(G.Controller,{name:"regression.y_axis_data_key",control:e,render:({field:i})=>l(mt,{label:"Value Field",required:!0,data:n,sx:{flex:1},...i})})]}),b(d.Group,{grow:!0,noWrap:!0,children:[l(G.Controller,{name:"regression.transform.config.method",control:e,render:({field:i})=>l(d.Select,{label:"Method",data:PB,sx:{flex:1},...i})}),r==="polynomial"&&l(G.Controller,{name:"regression.transform.config.order",control:e,render:({field:i})=>l(d.NumberInput,{label:"Order",sx:{flex:1},...i})})]}),b(d.Stack,{spacing:4,children:[l(d.Text,{size:"sm",children:"Color"}),l(G.Controller,{name:"regression.plot.color",control:e,render:({field:i})=>l(kn,{...i})})]})]})}function IB({context:e}){const{value:t,set:n}=et(e.instanceData,"config"),r=e.data,i=x.useMemo(()=>H.defaults({},t,Mc),[t]),{control:o,handleSubmit:a,watch:s,getValues:u,reset:c}=G.useForm({defaultValues:i});x.useEffect(()=>{c(i)},[i]),s(["x_axis","y_axis","regression"]);const f=u(),h=x.useMemo(()=>!H.isEqual(f,t),[f,t]);return l(d.Stack,{mt:"md",spacing:"xs",children:b("form",{onSubmit:a(n),children:[b(d.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[l(d.Text,{children:"Chart Config"}),l(d.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:l(te.DeviceFloppy,{size:20})})]}),b(d.Accordion,{multiple:!0,defaultValue:["Axis","Regression"],children:[b(d.Accordion.Item,{value:"Axis",children:[l(d.Accordion.Control,{children:"Axis"}),b(d.Accordion.Panel,{children:[b(d.Group,{grow:!0,noWrap:!0,children:[l(G.Controller,{name:"x_axis.name",control:o,render:({field:p})=>l(d.TextInput,{label:"X Axis Name",sx:{flex:1},...p})}),l(G.Controller,{name:"x_axis.data_key",control:o,render:({field:p})=>l(mt,{label:"X Axis Data Field",required:!0,data:r,sx:{flex:1},...p})})]}),l(d.Group,{grow:!0,noWrap:!0,children:l(G.Controller,{name:"y_axis.name",control:o,render:({field:p})=>l(d.TextInput,{label:"Y Axis Name",sx:{flex:1},...p})})})]})]}),b(d.Accordion.Item,{value:"Regression",children:[l(d.Accordion.Control,{children:"Regression Line"}),l(d.Accordion.Panel,{children:l(NB,{control:o,watch:s,data:r})})]})]})]})})}class $B extends en{constructor(){super(...arguments);ke(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const LB={displayName:"Regression Chart",migrator:new $B,name:"regressionChart",viewRender:AB,configRender:IB,createConfig(){return{version:1,config:H.cloneDeep(Mc)}}},gs={content:""};function VB({context:e}){const{value:t}=et(e.instanceData,"config"),n=x.useMemo(()=>H.defaults({},t,gs),[t]);return n!=null&&n.content?l(ty,{value:n.content,styles:{root:{border:"none",height:"100%"},content:{padding:0}}}):null}const Jy=x.forwardRef(({value:e,onChange:t,styles:n={},label:r,onSubmit:i},o)=>{const[a,s]=x.useState(e),u=Uc.useEditor({extensions:[Xc.default,ey,rt.Link,Zm,Qm,Ym,Jm.configure({types:["heading","paragraph"]}),Xm.configure({placeholder:"This is placeholder"}),Wm,Um],content:a,onUpdate:({editor:p})=>{s(p.getHTML())}});x.useEffect(()=>{s(e),u==null||u.commands.setContent(e)},[e]);const c=()=>{t(a),i==null||i()},f=e!==a,h=x.useMemo(()=>ye.default.defaultsDeep({},{content:rc},n),[n]);return b(d.Stack,{spacing:4,sx:{flexGrow:1,position:"relative"},children:[b(d.Group,{align:"center",children:[l(d.Text,{size:14,fw:500,children:r}),l(d.ActionIcon,{color:"blue",disabled:!f,onClick:c,children:l(mm,{size:18})})]}),b(rt.RichTextEditor,{editor:u,styles:h,children:[b(rt.RichTextEditor.Toolbar,{sticky:!0,stickyOffset:0,children:[l(rt.RichTextEditor.ControlsGroup,{children:l(rt.RichTextEditor.ColorPicker,{colors:["#25262b","#868e96","#fa5252","#e64980","#be4bdb","#7950f2","#4c6ef5","#228be6","#15aabf","#12b886","#40c057","#82c91e","#fab005","#fd7e14"]})}),b(rt.RichTextEditor.ControlsGroup,{children:[l(rt.RichTextEditor.Bold,{}),l(rt.RichTextEditor.Italic,{}),l(rt.RichTextEditor.Underline,{}),l(rt.RichTextEditor.Strikethrough,{}),l(rt.RichTextEditor.ClearFormatting,{}),l(rt.RichTextEditor.Highlight,{}),l(rt.RichTextEditor.Code,{})]}),b(rt.RichTextEditor.ControlsGroup,{children:[l(rt.RichTextEditor.H1,{}),l(rt.RichTextEditor.H2,{}),l(rt.RichTextEditor.H3,{}),l(rt.RichTextEditor.H4,{})]}),b(rt.RichTextEditor.ControlsGroup,{children:[l(rt.RichTextEditor.Blockquote,{}),l(rt.RichTextEditor.Hr,{}),l(rt.RichTextEditor.BulletList,{}),l(rt.RichTextEditor.OrderedList,{}),l(rt.RichTextEditor.Subscript,{}),l(rt.RichTextEditor.Superscript,{})]}),b(rt.RichTextEditor.ControlsGroup,{children:[l(rt.RichTextEditor.Link,{}),l(rt.RichTextEditor.Unlink,{})]}),b(rt.RichTextEditor.ControlsGroup,{children:[l(rt.RichTextEditor.AlignLeft,{}),l(rt.RichTextEditor.AlignCenter,{}),l(rt.RichTextEditor.AlignJustify,{}),l(rt.RichTextEditor.AlignRight,{})]})]}),l(rt.RichTextEditor.Content,{})]})]})});function zB({context:e}){const{value:t,set:n}=et(e.instanceData,"config"),r=x.useMemo(()=>H.defaults({},t,gs),[t]),{control:i,handleSubmit:o,watch:a,reset:s}=G.useForm({defaultValues:r});a("content"),x.useEffect(()=>{s(r)},[r]);const u=x.useRef(null),c=()=>{var f;return(f=u.current)==null?void 0:f.click()};return l("form",{onSubmit:o(n),style:{flexGrow:1,display:"flex",flexDirection:"column"},children:b(d.Stack,{spacing:"xs",sx:{flexGrow:1},children:[b(d.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",display:"none"},children:[l(d.Text,{children:"Content"}),l(d.ActionIcon,{ref:u,type:"submit",mr:5,variant:"filled",color:"blue",children:l(te.DeviceFloppy,{size:20})})]}),l(G.Controller,{name:"content",control:i,render:({field:f})=>l(Jy,{...f,styles:{root:{flexGrow:1}},label:"Content",onSubmit:c})})]})})}class FB extends en{constructor(){super(...arguments);ke(this,"VERSION",1)}fixMalformedConfig(n){return H.defaults({},n,gs)}configVersions(){this.version(1,n=>({version:1,config:this.fixMalformedConfig(n)}))}}const BB={displayName:"Rich Text",migrator:new FB,name:"richText",viewRender:VB,configRender:zB,createConfig(){return{version:1,config:H.cloneDeep(gs)}}},Oc={align:"center",template:"The variable ${value} is defined in Variables section"};function GB(e){if("variables"in e)return e;const{align:t,size:n,weight:r,color:i,content:{prefix:o="",data_field:a="value",formatter:s={output:"number",mantissa:0},postfix:u=""}={}}=e;return{align:t,template:`${o} \${value} ${u}`,variables:[{name:"value",data_field:a,aggregation:{type:"none",config:{}},formatter:s,color:i,weight:r,size:n}]}}function jB(e){return H.omit(e,["variables"])}function KB(e){const t=H.cloneDeep(e),n=H.get(t,"color.valueRange");return n!==void 0&&H.set(t,"color.valueRange",n.map(r=>Number(r))),t}class HB extends en{constructor(){super(...arguments);ke(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:GB(n)})),this.version(2,(n,{panelModel:r})=>{const{config:i}=n;return(i.variables||[]).forEach(a=>{r.variables.find(s=>s.name===a.name)||r.addVariable(KB(a))}),{...n,version:2,config:jB(i)}})}}const qB=se.observer(({context:e})=>{const t=Ze(),{value:n=Oc}=et(e.instanceData,"config"),{variables:r}=e,{template:i,align:o}=n,a=x.useMemo(()=>{try{const u={filters:t.filters.values,context:t.context.current};return ye.default.template(i)(u)}catch{return i}},[t.filters.values,t.context.current,i]),s=x.useMemo(()=>Mo(a,r,e.data),[a,r,e.data,e]);return l(d.Text,{align:o,children:Object.values(s).map((u,c)=>l(W.default.Fragment,{children:u},c))})}),WB=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}];function UB({context:e}){const{value:t,set:n}=et(e.instanceData,"config"),r=W.default.useMemo(()=>{const{align:h,template:p=""}=H.defaultsDeep({},t,Oc);return{template:p,align:h}},[t]),{control:i,handleSubmit:o,watch:a,getValues:s,reset:u}=G.useForm({defaultValues:r});W.default.useEffect(()=>{u(r)},[r]),a(["template","align"]);const c=s(),f=W.default.useMemo(()=>!ye.default.isEqual(c,t),[c,t]);return l(d.Stack,{mt:"md",spacing:"xs",children:b("form",{onSubmit:o(n),children:[b(d.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[l(d.Text,{weight:500,children:"Stats Configurations"}),l(d.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:l(te.DeviceFloppy,{size:20})})]}),l(G.Controller,{name:"template",control:i,render:({field:h})=>l(So,{label:"Template",py:"md",sx:{flexGrow:1},...h})}),l(G.Controller,{name:"align",control:i,render:({field:h})=>l(d.Select,{label:"Horizontal Alignment",data:WB,...h})})]})})}const YB={createConfig(){return{version:2,config:Oc}},displayName:"Stats",migrator:new HB,name:"stats",viewRender:qB,configRender:UB},Dc={label_key:"",value_key:"",group_key:"",levels:[]};function XB(e){const t=new Set(e.map(r=>r.parent_id)),n=new Set(e.map(r=>r.id));return t.forEach(r=>{r===null||n.has(r)||e.push({id:r,name:r,parent_id:null})}),e}function QB(e){const t=XB(e).map(i=>({...i,children:[]})),n=ye.default.keyBy(t,i=>i.id),r=[];return t.forEach(i=>{if(!i.parent_id||!n[i.parent_id]){r.push(i);return}n[i.parent_id].children.push(i)}),r}function ZB(e,t){const{label_key:n,value_key:r,group_key:i}=e,o=n,a=t.map(s=>({...s,id:s[o],parent_id:s[i],name:s[n],value:s[r]?Number(s[r]):s[r]}));return i?QB(a):a}const JB=e=>({treePathInfo:t,name:n,value:r})=>{if(t.length===1||!e)return n;try{const i=t[t.length-2].value;if(r/i<e)return" "}catch{return n}};function e3(e){const{levels:t}=e;return t.map(n=>{const{show_label_tolerance:r,...i}=n.label;return{...n,label:{...i,formatter:JB(r)}}})}function t3(){return({treePathInfo:e,name:t,value:n,color:r,marker:i,...o})=>{console.log({rest:o});const a=e.slice(0,e.length-1),s=[`<tr>
268
268
  <th style="text-align: right; padding: 0 1em;">Value</th>
269
269
  <td style="text-align: left; padding: 0 1em;">${n}</td>
270
270
  </tr>
@@ -308,4 +308,4 @@ WHERE
308
308
  </table>
309
309
  `}}}function T5(e,t){var i;const n=t.every(o=>!Number.isNaN(Number(o))),{axisLabel:r}=e.x_axis;return[{data:t,name:(i=e.x_axis.name)!=null?i:"",id:"main-x-axis",axisTick:{show:!0,alignWithLabel:!0},type:n?"value":"category",axisLabel:{...r,formatter:cb(r.formatter)}}]}function M5(e,t){return e.y_axes.map(({nameAlignment:n,min:r,max:i,...o},a)=>{var u;let s=o.position;return s||(s=a>0?"right":"left"),{...o,min:r||void 0,max:i||void 0,position:s,axisLabel:{show:!0,formatter:(u=t[a])!=null?u:t.default},axisLine:{show:!0},nameTextStyle:{fontWeight:"bold",align:n},nameLocation:"end",nameGap:15,splitLine:{show:!1}}})}function O5(){return{show:!1,bottom:0,left:"center",type:"scroll"}}const D5={tooltip:{trigger:"axis"},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 R5(e,t,n){const r=n.reduce((c,f)=>{const h=us(f,t);return c[f.name]=Ri(f,h),c},{}),i=e.y_axes.reduce((c,{label_formatter:f},h)=>(c[h]=function(g){let v=g;if(typeof g=="object"&&(Array.isArray(g.value)&&g.value.length===2?v=g.value[1]:v=g.value),!f)return v;try{return Ft.default(v).format(f)}catch(m){return console.error(m),v}},c),{default:({value:c})=>c}),o=ye.default.uniq(t.map(c=>c[e.x_axis.data_key])),a=o.every(c=>!Number.isNaN(Number(c))),s=S5(e,o,a,t,i,n,r),u={xAxis:T5(e,o),yAxis:M5(e,i),series:s,dataset:[{source:t}],tooltip:E5(e,i),grid:v5(e),legend:O5(),dataZoom:xc(e.dataZoom)};return H.defaultsDeep({},u,D5)}Rt.use([ut.DataZoomComponent,dn.BarChart,dn.LineChart,dn.ScatterChart,ut.GridComponent,ut.LegendComponent,ut.TooltipComponent,Kn.CanvasRenderer,ut.MarkLineComponent,ut.MarkAreaComponent]),Rt.registerTransform(Cs.transform.regression);function db(e){return e.trim().length>0}function k5({conf:e,data:t,width:n,height:r,interactionManager:i,variables:o}){const a=x.useMemo(()=>ye.default.keyBy(t,e.x_axis.data_key),[t,e.x_axis.data_key]),s=Oi(i.triggerManager,sb.id),u=x.useCallback(h=>{const p=h.value[0],g=ye.default.get(a,p,{error:"rowData is not found"});s.forEach(v=>{i.runInteraction(v.id,{...h,rowData:g})})},[a,s,i]),c=x.useMemo(()=>({click:u}),[u]),f=W.default.useMemo(()=>R5(e,t,o),[e,t]);return!n||!r?null:l(Hn.default,{echarts:Rt,option:f,style:{width:n,height:r},onEvents:c})}function A5({context:e,instance:t}){const n=Di({vizManager:e.vizManager,instance:t}),{value:r}=et(e.instanceData,"config"),{variables:i}=e,o=x.useMemo(()=>H.defaults({},r,$c),[r]),a=e.data,{width:s,height:u}=e.viewport,{ref:c,height:f}=wt.useElementSize(),{ref:h,height:p}=wt.useElementSize(),g=W.default.useMemo(()=>{const{stats:{templates:m}}=o;return{top:Mo(m.top,i,a),bottom:Mo(m.bottom,i,a)}},[o,a]),v=Math.max(0,u-f-p);return b(d.Box,{children:[l(d.Text,{ref:c,align:"left",size:"xs",pl:"sm",sx:{display:db(o.stats.templates.top)?"block":"none"},children:Object.values(g.top).map(m=>m)}),l(k5,{variables:i,width:s,height:v,data:a,conf:o,interactionManager:n}),l(d.Text,{ref:h,align:"left",size:"xs",pl:"sm",sx:{display:db(o.stats.templates.bottom)?"block":"none"},children:Object.values(g.bottom).map(m=>m)})]})}const P5=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],N5=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function I5({control:e,index:t,remove:n,watch:r,variableOptions:i,yAxisOptions:o}){const a=r(`reference_lines.${t}.orientation`);return b(d.Stack,{my:0,p:0,sx:{position:"relative"},children:[b(d.Group,{grow:!0,noWrap:!0,children:[l(G.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:s})=>l(d.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...s})}),l(G.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:s})=>l(d.Select,{label:"Value",required:!0,data:i,sx:{flex:1},...s})})]}),l(G.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:s})=>l(d.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...s})}),b(d.Group,{grow:!0,children:[b(d.Stack,{children:[l(G.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:s})=>l(d.Select,{label:"Orientation",data:N5,required:!0,sx:{flex:1},...s})}),a==="vertical"&&l(d.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),a==="horizontal"&&l(G.Controller,{name:`reference_lines.${t}.yAxisIndex`,control:e,render:({field:{value:s,onChange:u,...c}})=>{var f;return l(d.Select,{label:"Y Axis",data:o,disabled:o.length===0,...c,value:(f=s==null?void 0:s.toString())!=null?f:"",onChange:h=>{if(!h){u(0);return}u(Number(h))},sx:{flex:1}})}})]}),l(d.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),b(d.Group,{grow:!0,children:[l(G.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:s})=>l(d.Select,{label:"Line Type",data:P5,sx:{flexGrow:1},...s})}),l(G.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:s})=>l(d.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...s})})]}),b(d.Stack,{spacing:4,children:[l(d.Text,{size:"sm",children:"Color"}),l(G.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:s})=>l(kn,{...s})})]}),l(d.Button,{leftIcon:l(te.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]},t)}function $5({control:e,watch:t,variables:n}){const{fields:r,append:i,remove:o}=G.useFieldArray({control:e,name:"reference_lines"}),a=t("reference_lines"),s=r.map((p,g)=>({...p,...a[g]})),u=()=>{const p={name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:qr.random().css()},show_in_legend:!1,yAxisIndex:0};i(p)},c=x.useMemo(()=>n.map(p=>({label:p.name,value:p.name})),[n]),f=t("y_axes"),h=x.useMemo(()=>f.map(({name:p},g)=>({label:p,value:g.toString()})),[f]);return b(d.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[b(d.Tabs.List,{children:[s.map((p,g)=>l(d.Tabs.Tab,{value:g.toString(),children:g+1},g)),l(d.Tabs.Tab,{onClick:u,value:"add",children:l(d.ActionIcon,{children:l(te.Plus,{size:18,color:"#228be6"})})})]}),s.map((p,g)=>l(d.Tabs.Panel,{value:g.toString(),children:l(I5,{control:e,index:g,remove:o,watch:t,variableOptions:c,yAxisOptions:h})},g))]})}const L5=({value:e,onChange:t})=>{const n=r=>{!r||t(r)};return l(d.Box,{children:l(Pn.default,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},V5=({value:e,onChange:t,data:n})=>{const[r,{setTrue:i,setFalse:o}]=nt.useBoolean(),[a,s]=x.useState(e),u=()=>{o();const{type:p,func_content:g}=a,v={type:p,func_content:g};s(v),t(v)},c=()=>{o(),s(e)},f=p=>{s(g=>({...g,func_content:p}))},h=()=>{f(Ro.dynamic.func_content)};return b(De,{children:[l(d.Box,{sx:{width:"50%"},children:l(d.Button,{variant:"filled",mt:24,onClick:i,sx:{flexGrow:0},children:"Setup"})}),l(d.Modal,{size:800,title:"Setup dynamic color",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,children:r&&b(d.Stack,{children:[l(d.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),l(L5,{value:a.func_content,onChange:f}),b(d.Group,{position:"apart",children:[l(d.Button,{onClick:h,color:"red",leftIcon:l(te.Recycle,{size:20}),children:"Rest"}),b(d.Group,{position:"right",children:[l(d.Button,{onClick:c,variant:"subtle",children:"Cancel"}),l(d.Button,{onClick:u,children:"OK"})]})]})]})})]})},z5=({value:e,onChange:t,data:n})=>e.type!=="dynamic"?null:l(V5,{value:e,onChange:t,data:n}),F5=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=r=>{t({...e,color:r})};return l(d.ColorInput,{label:" ",format:"rgb",value:e.color,onChange:n})},B5=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],G5=x.forwardRef(({label:e="Color",value:t,onChange:n,data:r},i)=>{const o=a=>{n({...Ro[a]})};return b(d.SimpleGrid,{cols:2,children:[l(d.Select,{ref:i,label:e,data:B5,value:t.type,onChange:o,sx:{flexGrow:1}}),l(F5,{value:t,onChange:n}),l(z5,{value:t,onChange:n,data:r})]})}),j5=x.forwardRef(({value:e,onChange:t},n)=>{const r=o=>{t({...e,label:o})},i=o=>{t({...e,tooltip:o})};return b(d.Stack,{ref:n,spacing:0,children:[l(fs,{sectionTitle:"Overflow on Chart",value:e.label,onChange:r}),l(fs,{sectionTitle:"Overflow in Tooltip",value:e.tooltip,onChange:i})]})}),K5=({value:e,onChange:t})=>{const n=r=>{!r||t(r)};return l(d.Box,{children:l(Pn.default,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},fb={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
310
310
  `)}},H5=({value:e,onChange:t,data:n})=>{const[r,{setTrue:i,setFalse:o}]=nt.useBoolean(),[a,s]=x.useState(e),u=()=>{o();const{type:p,func_content:g}=a,v={type:p,func_content:g};s(v),t(v)},c=()=>{o(),s(e)},f=p=>{s(g=>({...g,func_content:p}))},h=()=>{f(fb.dynamic.func_content)};return b(De,{children:[l(d.Box,{sx:{width:"50%"},children:l(d.Button,{variant:"filled",mt:24,onClick:i,sx:{flexGrow:0},children:"Setup"})}),l(d.Modal,{size:800,title:"Setup dynamic size",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,children:r&&b(d.Stack,{children:[l(d.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),l(K5,{value:a.func_content,onChange:f}),b(d.Group,{position:"apart",children:[l(d.Button,{onClick:h,color:"red",leftIcon:l(te.Recycle,{size:20}),children:"Rest"}),b(d.Group,{position:"right",children:[l(d.Button,{onClick:c,variant:"subtle",children:"Cancel"}),l(d.Button,{onClick:u,children:"OK"})]})]})]})})]})},q5=({value:e,onChange:t,data:n})=>e.type!=="dynamic"?null:l(H5,{value:e,onChange:t,data:n}),W5=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=r=>{t({...e,size:r})};return l(De,{children:l(d.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:e.size,onChange:n})})},U5=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Y5=x.forwardRef(({label:e="Size",value:t,onChange:n,data:r},i)=>{const o=a=>{n({...fb[a]})};return b(d.SimpleGrid,{cols:2,children:[l(d.Select,{ref:i,label:e,data:U5,value:t.type,onChange:o,sx:{flexGrow:1}}),l(W5,{value:t,onChange:n}),l(q5,{value:t,onChange:n,data:r})]})}),X5=[{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 Q5({data:e,control:t,watch:n}){return n(["scatter"]),b(d.Stack,{children:[b(d.Group,{grow:!0,noWrap:!0,children:[l(G.Controller,{name:"scatter.name_data_key",control:t,render:({field:r})=>l(mt,{label:"Name Data Field",required:!0,data:e,sx:{flex:1},...r})}),l(G.Controller,{name:"scatter.y_data_key",control:t,render:({field:r})=>l(mt,{label:"Value Data Field",required:!0,data:e,sx:{flex:1},...r})})]}),l(d.Divider,{mb:-15,label:"Style",labelPosition:"center"}),l(G.Controller,{name:"scatter.symbolSize",control:t,render:({field:r})=>l(Y5,{label:"Size",data:e,...r})}),l(G.Controller,{name:"scatter.color",control:t,render:({field:r})=>l(G5,{data:e,...r})}),l(d.Divider,{mb:-15,label:"Label",labelPosition:"center"}),l(d.Group,{grow:!0,noWrap:!0,children:l(G.Controller,{name:"scatter.label_position",control:t,render:({field:r})=>l(d.Select,{label:"Label Position",data:X5,...r})})}),l(G.Controller,{name:"scatter.label_overflow",control:t,render:({field:r})=>l(j5,{...r})})]})}function Z5({control:e,watch:t}){return t("stats"),l(d.Stack,{children:b(d.Stack,{spacing:0,children:[l(G.Controller,{name:"stats.templates.top",control:e,render:({field:n})=>l(So,{label:"Template for stats above the chart",py:"md",sx:{flexGrow:1},...n})}),l(G.Controller,{name:"stats.templates.bottom",control:e,render:({field:n})=>l(So,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const J5=({control:e,data:t,index:n,remove:r})=>b(d.Stack,{children:[b(d.Group,{grow:!0,noWrap:!0,children:[l(G.Controller,{name:`tooltip.metrics.${n}.name`,control:e,render:({field:i})=>l(d.TextInput,{label:"Name",required:!0,sx:{flex:1},...i})}),l(G.Controller,{name:`tooltip.metrics.${n}.data_key`,control:e,render:({field:i})=>l(mt,{label:"Value Field",required:!0,data:t,sx:{flex:1},...i})})]}),l(d.Divider,{mb:-10,mt:10,variant:"dashed"}),l(d.Button,{leftIcon:l(te.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(n),sx:{top:15,right:5},children:"Delete this Metric"})]}),e4=({control:e,watch:t,data:n})=>{const{fields:r,append:i,remove:o}=G.useFieldArray({control:e,name:"tooltip.metrics"}),a=t("tooltip.metrics"),s=r.map((p,g)=>({...p,...a[g]})),u=()=>i({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[f,h]=x.useState(()=>c!=null?c:null);return x.useEffect(()=>{c&&h(p=>p!==null?p:c)},[c]),b(De,{children:[b(d.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[l(te.InfoCircle,{size:14,color:"#888"}),l(d.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),l(d.Divider,{variant:"dashed",my:10}),b(d.Tabs,{value:f,onTabChange:p=>h(p),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[b(d.Tabs.List,{children:[s.map((p,g)=>l(d.Tabs.Tab,{value:p.id,children:p.name?p.name:g},p.id)),l(d.Tabs.Tab,{onClick:u,value:"add",children:l(d.ActionIcon,{children:l(te.Plus,{size:18,color:"#228be6"})})})]}),s.map((p,g)=>l(d.Tabs.Panel,{value:p.id,children:l(J5,{control:e,index:g,remove:o,data:n},p.id)},p.id))]})]})};function t4({data:e,control:t,watch:n}){return l(e4,{control:t,watch:n,data:e})}const n4=({disabled:e,value:t,onChange:n})=>{const r=i=>{!i||n(i)};return b(d.Box,{sx:{position:"relative"},children:[e&&l(d.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),l(Pn.default,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1,readOnly:e}}})]})},r4=x.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:i,setFalse:o}]=nt.useBoolean(),[a,s]=x.useState(e),u=g=>{s({...a,enabled:g})},c=()=>{o();const{enabled:g,func_content:v}=a,m={enabled:g,func_content:v};s(m),t(m)},f=()=>{o(),s(e)},h=g=>{s(v=>({...v,func_content:g}))},p=()=>{h(lb.func_content)};return b(De,{children:[l(d.Button,{variant:"filled",mt:24,onClick:i,sx:{flexGrow:0},children:"Customize Label"}),l(d.Modal,{size:800,title:"Customize label content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,children:r&&b(d.Stack,{children:[l(d.Checkbox,{mt:10,label:"Enabled",checked:a.enabled,onChange:g=>u(g.currentTarget.checked)}),l(n4,{value:a.func_content,onChange:h,disabled:!a.enabled}),b(d.Group,{position:"apart",children:[l(d.Button,{onClick:p,color:"red",leftIcon:l(te.Recycle,{size:20}),children:"Rest"}),b(d.Group,{position:"right",children:[l(d.Button,{onClick:f,variant:"subtle",children:"Cancel"}),l(d.Button,{onClick:c,children:"OK"})]})]})]})})]})});function i4({data:e,control:t,watch:n}){return n(["x_axis"]),b(d.Stack,{children:[b(d.Group,{grow:!0,noWrap:!0,children:[l(G.Controller,{name:"x_axis.data_key",control:t,render:({field:r})=>l(mt,{label:"Data Field",required:!0,data:e,sx:{flex:1},...r})}),l(G.Controller,{name:"x_axis.name",control:t,render:({field:r})=>l(d.TextInput,{label:"Name",sx:{flex:1},...r})})]}),l(d.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),b(d.Group,{grow:!0,noWrap:!0,children:[l(G.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:r})=>l(d.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:l(d.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...r})}),l(G.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:r})=>l(r4,{data:e,...r})})]})]})}const o4=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],a4=[{label:"left",value:"left"},{label:"right",value:"right"}];function s4({control:e,index:t,remove:n}){return b(d.Stack,{my:0,p:"0",sx:{position:"relative"},children:[l(d.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),b(d.Group,{grow:!0,noWrap:!0,children:[l(G.Controller,{name:`y_axes.${t}.name`,control:e,render:({field:r})=>l(d.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),l(G.Controller,{name:`y_axes.${t}.nameAlignment`,control:e,render:({field:r})=>l(d.Select,{label:"Align",required:!0,data:o4,sx:{flex:1},...r})})]}),l(d.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),l(d.Group,{grow:!0,noWrap:!0,children:l(G.Controller,{name:`y_axes.${t}.position`,control:e,render:({field:r})=>l(d.Select,{label:"Position",required:!0,data:a4,sx:{flex:1},...r})})}),b(d.Stack,{children:[l(d.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),l(G.Controller,{name:`y_axes.${t}.label_formatter`,control:e,render:({field:r})=>l(jr,{...r})})]}),b(d.Stack,{children:[l(d.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),b(d.Group,{grow:!0,children:[l(G.Controller,{name:`y_axes.${t}.min`,control:e,render:({field:r})=>l(d.TextInput,{label:"Min",...r})}),l(G.Controller,{name:`y_axes.${t}.max`,control:e,render:({field:r})=>l(d.TextInput,{label:"Max",...r})})]})]}),l(d.Button,{mt:20,leftIcon:l(te.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this YAxis"})]})}function l4({control:e,watch:t}){const{fields:n,append:r,remove:i}=G.useFieldArray({control:e,name:"y_axes"}),o=t("y_axes"),a=n.map((u,c)=>({...u,...o[c]})),s=()=>r({name:"",label_formatter:Fn});return b(d.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[b(d.Tabs.List,{children:[a.map((u,c)=>l(d.Tabs.Tab,{value:c.toString(),children:c+1},c)),l(d.Tabs.Tab,{onClick:s,value:"add",children:l(d.ActionIcon,{children:l(te.Plus,{size:18,color:"#228be6"})})})]}),a.map((u,c)=>l(d.Tabs.Panel,{value:c.toString(),children:l(s4,{control:e,index:c,remove:i})},c))]})}function u4(e){return e||{templates:{top:"",bottom:""}}}function c4({reference_lines:e=[],stats:t,...n}){return{reference_lines:e,stats:u4(t),...n}}function d4({context:e}){const{value:t,set:n}=et(e.instanceData,"config"),{variables:r}=e,i=e.data,o=x.useMemo(()=>H.defaultsDeep({},t,$c),[t]),a=x.useMemo(()=>c4(o),[o]);x.useEffect(()=>{!H.isEqual(o,a)&&(console.log("config malformed, resetting to defaults",o,a),n(a))},[o,a]);const{control:s,handleSubmit:u,watch:c,getValues:f,reset:h}=G.useForm({defaultValues:a});x.useEffect(()=>{h(a)},[a]);const p=f(),g=x.useMemo(()=>!H.isEqual(p,o),[p,o]);return c(["dataZoom"]),l(d.Stack,{mt:"md",spacing:"xs",children:b("form",{onSubmit:u(n),children:[b(d.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[l(d.Text,{children:"Chart Config"}),l(d.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!g,children:l(te.DeviceFloppy,{size:20})})]}),b(d.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[b(d.Tabs.List,{children:[l(d.Tabs.Tab,{value:"X Axis",children:"X Axis"}),l(d.Tabs.Tab,{value:"Y Axes",children:"Y Axes"}),l(d.Tabs.Tab,{value:"Scatter",children:"Scatter"}),l(d.Tabs.Tab,{value:"Tooltip",children:"Tooltip"}),l(d.Tabs.Tab,{value:"Stats",children:"Stats"}),l(d.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"}),l(d.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),l(d.Tabs.Panel,{value:"X Axis",children:l(i4,{control:s,watch:c,data:i})}),l(d.Tabs.Panel,{value:"Y Axes",children:l(l4,{control:s,watch:c})}),l(d.Tabs.Panel,{value:"Scatter",children:l(Q5,{control:s,watch:c,data:i})}),l(d.Tabs.Panel,{value:"Tooltip",children:l(t4,{control:s,watch:c,data:i})}),l(d.Tabs.Panel,{value:"Stats",children:l(Z5,{control:s,watch:c,data:i})}),l(d.Tabs.Panel,{value:"Reference Lines",children:l($5,{variables:r,control:s,watch:c})}),l(d.Tabs.Panel,{value:"Zooming",children:l(G.Controller,{name:"dataZoom",control:s,render:({field:v})=>l(Cc,{...v})})})]})]})})}function f4(e){const{dataZoom:t=ki,...n}=e;return{...n,dataZoom:t}}function p4(e){const t={scatter:{label_overflow:ub}};return ye.default.defaultsDeep(t,e)}function h4(e){const{color:t}=e.scatter;return typeof t=="string"?{...e,scatter:{...e.scatter,color:{...Ro.static,color:t}}}:e}function g4(e){const t=e.reference_lines.map(n=>{const{lineStyle:r={type:"dashed",width:1,color:qr.random().css()},show_in_legend:i=!1,yAxisIndex:o=0}=n;return{...n,lineStyle:r,show_in_legend:i,yAxisIndex:o}});return{...e,reference_lines:t}}class v4 extends en{constructor(){super(...arguments);ke(this,"VERSION",7)}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:f4(n.config)})),this.version(4,n=>{const{config:r}=n;return{...n,version:5,config:p4(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:h4(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:g4(r)}})}}const m4={displayName:"Scatter Chart",migrator:new v4,name:"scatterChart",viewRender:A5,configRender:d4,createConfig(){return{version:7,config:H.cloneDeep($c)}},triggers:[sb]},pb=["function text({ data, variables, filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
311
- `),Lc={func_content:pb,horizontal_align:"left",font_size:"14px",font_weight:"normal"},y4=se.observer(({context:e})=>{const t=Ze(),{value:n=Lc}=et(e.instanceData,"config"),{variables:r}=e,{func_content:i,horizontal_align:o,font_size:a,font_weight:s}=n,u=x.useMemo(()=>new Function(`return ${i}`)()({data:e.data,variables:r,filters:t.filters.values,context:t.context.current}),[i,e.data,r,t.filters.values,t.context.current]);return l(d.Text,{align:o,weight:s,sx:{fontSize:a},children:u})}),b4=({value:e,onChange:t})=>{const n=r=>{!r||t(r)};return l(d.Box,{sx:{position:"relative"},children:l(Pn.default,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},w4=x.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:i,setFalse:o}]=nt.useBoolean(),[a,s]=x.useState(e),u=()=>{o(),t(a)},c=()=>{o(),s(e)},f=()=>{s(pb)};return x.useEffect(()=>{s(e)},[e]),b(De,{children:[l(d.Button,{variant:"filled",mt:24,onClick:i,sx:{flexGrow:0},children:"Edit Content"}),l(d.Modal,{size:800,title:"Text content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,children:r&&b(d.Stack,{children:[l(b4,{value:a,onChange:s}),b(d.Group,{position:"apart",children:[l(d.Button,{onClick:f,color:"red",leftIcon:l(te.Recycle,{size:20}),children:"Rest"}),b(d.Group,{position:"right",children:[l(d.Button,{onClick:c,variant:"subtle",children:"Cancel"}),l(d.Button,{onClick:u,children:"OK"})]})]})]})})]})}),x4=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}];function S4({context:e}){const{value:t,set:n}=et(e.instanceData,"config"),r=x.useMemo(()=>H.defaultsDeep({},t,Lc),[t]),i=x.useMemo(()=>{const{func_content:p,horizontal_align:g,font_size:v,font_weight:m}=r;return{func_content:p,horizontal_align:g,font_size:v,font_weight:m}},[r]);x.useEffect(()=>{!H.isEqual(r,i)&&(console.log("config malformed, resetting to defaults",r,i),n(i))},[r,i]);const{control:o,handleSubmit:a,watch:s,getValues:u,reset:c}=G.useForm({defaultValues:i});W.default.useEffect(()=>{c(i)},[i]),s(["func_content","horizontal_align","font_size","font_weight"]);const f=u(),h=W.default.useMemo(()=>!ye.default.isEqual(f,r),[f,r]);return l(d.Stack,{mt:"md",spacing:"xs",children:b("form",{onSubmit:a(n),children:[b(d.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[l(d.Text,{weight:500,children:"Configurations"}),l(d.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:l(te.DeviceFloppy,{size:20})})]}),b(d.Stack,{spacing:10,children:[l(G.Controller,{name:"func_content",control:o,render:({field:p})=>l(w4,{...p})}),l(d.Divider,{mt:10,mb:-10,variant:"dashed",label:"Style",labelPosition:"center"}),l(G.Controller,{name:"horizontal_align",control:o,render:({field:p})=>l(d.Select,{label:"Horizontal Alignment",data:x4,...p})}),l(G.Controller,{name:"font_size",control:o,render:({field:p})=>l(d.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1},...p})}),l(d.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:l(G.Controller,{name:"font_weight",control:o,render:({field:p})=>l(Sy,{label:"Font Weight",...p})})})]})]})})}class C4 extends en{constructor(){super(...arguments);ke(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const _4={displayName:"Text",migrator:new C4,name:"text",viewRender:y4,configRender:S4,createConfig(){return{version:1,config:H.cloneDeep(Lc)}}},E4=[{value:"#25262B",name:"Dark"},{value:"#868E96",name:"Gray"},{value:"#FA5252",name:"Red"},{value:"#E64980",name:"Pink"},{value:"#BE4BDB",name:"Grape"},{value:"#7950F2",name:"Violet"},{value:"#4C6EF5",name:"Indigo"},{value:"#228BE6",name:"Blue"},{value:"#15AABF",name:"Cyan"},{value:"#12B886",name:"Teal"},{value:"#40C057",name:"Green"},{value:"#82C91E",name:"Lime"},{value:"#FAB005",name:"Yellow"},{value:"#FD7E14",name:"Orange"}].map(e=>({name:e.name,value:e.value,type:"single",category:"basic"})),T4=[BL,GL,HL,KL,jL,qL],hb=()=>({id:"dashboard",version:oc,manifest:{viz:[Pc,YB,_4,BB,m3,gB,tV,az,cB,PF,m4,TB,LB,p5,wz],color:[...E4,...T4]}}),ko=new YL,$t={pluginManager:qn("pluginManager"),vizManager:qn("vizManager"),colorManager:qn("colorManager"),instanceScope:{panelModel:qn("panelModel"),vizInstance:qn("vizInstance"),interactionManager:qn("interactionManager"),migrator:qn("migrator"),operationManager:qn("operationManager"),triggerManager:qn("triggerManager")}},Vc=()=>{try{ko.install(hb())}catch{}const e=new VL(ko),t=new UL(ko);return{pluginManager:ko,vizManager:e,colorManager:t}},Gn=x.createContext(Vc());try{ko.install(hb())}catch{}function M4(e,t){const{value:n,set:r}=et(e.operation.operationData,"config"),[i,o]=x.useState(H.defaults({},n,t)),a=async()=>{await r(i)};return x.useEffect(()=>{o(H.defaults({},n,t))},[n]),{config:i,setConfig:o,commit:a}}function O4(e){const{config:t,setConfig:n,commit:r}=M4(e,{urlTemplate:"",openInNewTab:!0});async function i(){await r()}async function o(s){n({...t,openInNewTab:s}),await r()}const a=s=>n({...t,urlTemplate:s.currentTarget.value});return b(d.Stack,{children:[l(d.TextInput,{label:"Url",value:t.urlTemplate,onChange:a,onBlur:i}),l(d.Switch,{label:"Open in new Tab",checked:t.openInNewTab,onChange:s=>o(s.currentTarget.checked)})]})}async function D4(e,t){const{urlTemplate:n,openInNewTab:r}=await t.operationData.getItem("config");window.dispatchEvent(new CustomEvent("open-link",{detail:{urlTemplate:n,openInNewTab:r,payload:e}}))}class R4 extends en{constructor(){super(...arguments);ke(this,"VERSION",1)}configVersions(){this.version(1,n=>n)}}const k4={displayName:"Open Link",id:"builtin:op:open-link",configRender:O4,run:D4,migrator:new R4,createDefaultConfig:()=>({version:1,config:{urlTemplate:"",openInNewTab:!0}})};function A4(e){const{value:t,set:n}=et(e.operationData,"config"),r=i=>void n({template:i});return[(t==null?void 0:t.template)||"",r]}function P4(e){const[t,n]=A4(e.operation);return l(d.TextInput,{defaultValue:t,onBlur:r=>n(r.currentTarget.value),label:"console.log"})}async function N4(e,t){const n=await t.operationData.getItem("config"),r=H.template(n.template||"");console.log("run with payload",e),console.log(r(e))}const I4={displayName:"console.log (debug)",id:"builtin:op:debug",configRender:P4,run:N4},$4=se.observer(e=>{const t=Ze(),{value:n,set:r}=et(e.operation.operationData,"config");console.log({value:n,viewID:n==null?void 0:n.viewID});const i=(n==null?void 0:n.viewID)||"",o=a=>void r({viewID:a});return l(d.Select,{defaultValue:i,value:i,onChange:o,label:"View",data:t.views.options})});async function L4(e,t){const r=(await t.operationData.getItem("config")).viewID;window.dispatchEvent(new CustomEvent("open-view",{detail:{viewID:r}}))}const V4={displayName:"Open View",id:"builtin:op:open_view",configRender:$4,run:L4},z4={dictionary:{}},F4=se.observer(e=>{const t=Ze(),{value:n=z4,set:r}=et(e.operation.operationData,"config"),{dictionary:i={}}=n,o=(u,c)=>{r({dictionary:{...i,[u]:c}})},a=()=>{o(t.filters.firstFilterValueKey,"")},s=u=>{const c={...i};delete c[u],r({dictionary:c})};return b(d.Stack,{spacing:10,children:[l(d.Text,{children:"Mapping Rules"}),Object.entries(i).map(([u,c])=>b(d.Flex,{justify:"space-between",gap:10,children:[l(d.TextInput,{label:"Payload key",value:c,onChange:f=>{o(u,f.currentTarget.value)},sx:{flexGrow:1}}),l(mt,{data:[t.filters.values],value:u,onChange:f=>{o(f,c)},label:"Filter key",sx:{flexGrow:1}}),l(d.ActionIcon,{onClick:()=>s(u),sx:{marginTop:"26px",flexGrow:0},children:l(te.Trash,{size:14,color:"red"})})]},u)),l(d.Button,{size:"xs",onClick:a,sx:{alignSelf:"center",width:"300px"},children:"Add one mapping rule"})]})});async function B4(e,t){const r=(await t.operationData.getItem("config")).dictionary;window.dispatchEvent(new CustomEvent("set-filter-values",{detail:{dictionary:r,payload:e}}))}const G4={displayName:"Set Filter Values",id:"builtin:op:set_filter_values",configRender:F4,run:B4},j4={filter_keys:[]},K4=se.observer(e=>{const t=Ze(),{value:n=j4,set:r}=et(e.operation.operationData,"config"),{filter_keys:i=[]}=n,o=s=>{r({filter_keys:[...s]})},a=x.useMemo(()=>t.filters.current.map(s=>({label:s.label,value:s.key})),[t.filters.values]);return l(d.Stack,{spacing:10,children:l(d.MultiSelect,{label:"Select Filters to Clear",data:a,value:i,onChange:o})})});async function H4(e,t){const r=(await t.operationData.getItem("config")).filter_keys;window.dispatchEvent(new CustomEvent("clear-filter-values",{detail:{filter_keys:r,payload:e}}))}const ms=[I4,k4,V4,G4,{displayName:"Clear Filter Values",id:"builtin:op:clear_filter_values",configRender:K4,run:H4}];class q4{constructor(t,n=ms){ke(this,"attachments");this.operations=n;const r=async i=>{const{id:o,schemaRef:a}=await i.getItem(null);return{id:o,schemaRef:a,operationData:new Mi(i,"data")}};this.attachments=new ic(t,"__OPERATIONS",r)}async runOperation(t,n){const r=await this.attachments.getInstance(t);if(!r){console.warn(`Operation '${t}' is not defined`);return}const i=this.tryGetSchema(r.schemaRef);if(!i){console.warn(`Operation schema '${r.schemaRef}' is not defined`);return}await i.run(n,r)}tryGetSchema(t){return this.operations.find(n=>n.id===t)}async needMigration(){const n=(await this.attachments.list()).map(async r=>{const i={configData:r.operationData},o=this.tryGetSchema(r.schemaRef),a=o==null?void 0:o.migrator;return a&&await a.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),a=o==null?void 0:o.migrator;a&&await a.needMigration(i)&&await a.migrate(i)});await Promise.all(n)}async createOrGetOperation(t,n){var a,s;if(!this.getOperationSchemaList().some(u=>u.id===n.id))throw new Error(`Operation schema '${n.id}' is not defined`);const i=await this.attachments.getInstance(t);return!i||i.schemaRef!==n.id?await this.attachments.create(t,{id:t,schemaRef:n.id,data:(s=(a=n.createDefaultConfig)==null?void 0:a.call(n))!=null?s:{}}):i}getOperationList(){return this.attachments.list()}getOperationSchemaList(){return this.operations}removeOperation(t){return this.attachments.remove(t)}async retrieveTrigger(t){return await this.attachments.getInstance(t)}}class zc{constructor(t,n,r){ke(this,"operationManager");ke(this,"triggerManager");ke(this,"attachments");this.operationManager=new q4(t,r),this.triggerManager=new oV(t,n);const i=async o=>{const{id:a,triggerRef:s,operationRef:u}=await o.getItem(null);return{id:a,triggerRef:s,operationRef:u}};this.attachments=new ic(t,"__INTERACTIONS",i)}async addInteraction(t,n){const r=t.id,i=n.id,o=`[${r}]:[${i}]`;await this.attachments.create(o,{id:o,triggerRef:r,operationRef:i})}getInteractionList(){return this.attachments.list()}async removeInteraction(t){const n=await this.attachments.getInstance(t);if(!n)return;const{triggerRef:r,operationRef:i}=n;await this.getTriggerRefCount(r)<=1&&await this.triggerManager.removeTrigger(r),await this.getOperationRefCount(i)<=1&&await this.operationManager.removeOperation(i),await this.attachments.remove(t)}async getOperationRefCount(t){return(await this.getInteractionList()).filter(r=>r.operationRef===t).length}async getTriggerRefCount(t){return(await this.getInteractionList()).filter(r=>r.triggerRef===t).length}async runInteraction(t,n){const i=(await this.getInteractionList()).filter(o=>o.triggerRef===t);await Promise.all(i.map(async o=>{try{return await this.operationManager.runOperation(o.operationRef,n)}catch(a){console.warn(`Failed to run operation '${o.operationRef}'`,a)}}))}}function W4(e,t){const[n,r]=x.useState([]);return nt.useAsyncEffect(async()=>{const i=await e.getInteractionList();r(i)},[t]),n}const U4=se.observer(({item:e,manager:t,instance:n,sampleData:r,variables:i,onRemove:o})=>{const{triggerRef:a,operationRef:s}=e,u=AL(t.triggerManager,n);if(nt.useAsyncEffect(async()=>{await u.configTrigger(a,r)},[u,a,r]),u.isReady()){const c=[...u.triggerSchema.payload,...i];return b(d.Group,{children:[l($L,{model:u}),l(DL,{instance:n,operationId:s,variables:c,operationManager:t.operationManager}),l(d.ActionIcon,{"aria-label":"delete-interaction",variant:"filled",color:"red",onClick:()=>o(e),children:l(te.Trash,{size:16})})]})}return null}),Y4=e=>{const[t,n]=x.useState(0),{interactionManager:r,instance:i,sampleData:o,variables:a}=e,s=W4(r,t),u=async()=>{const p=await r.triggerManager.createOrGetTrigger(wt.randomId(),r.triggerManager.getTriggerSchemaList()[0]),g=await r.operationManager.createOrGetOperation(wt.randomId(),r.operationManager.getOperationSchemaList()[0]);await r.addInteraction(p,g),n(v=>v+1)};async function c(p){await r.removeInteraction(p.id),n(g=>g+1)}const{data:f=0,loading:h}=nt.useRequest(async()=>{try{return(await r.triggerManager.getTriggerSchemaList()).length}catch{return 0}});return b(d.Stack,{children:[l(d.LoadingOverlay,{visible:h}),f===0&&l(d.Alert,{icon:l(te.AlertCircle,{size:16}),title:"Unavailable",color:"gray",children:"This visualization does not have available interactions to choose from"}),s.map(p=>l(U4,{onRemove:c,instance:i,sampleData:o,variables:a,item:p,manager:e.interactionManager},p.id)),l(d.Button,{style:{width:"fit-content"},onClick:()=>u(),disabled:f===0,children:"Add interaction"})]})},X4=()=>{const{panel:e,data:t}=jt(),n=e.viz,{vizManager:r}=x.useContext(Gn),i=e.json,o=nt.useCreation(()=>r.getOrCreateInstance(i),[r,n.type]),a=nt.useCreation(()=>new zc(o,r.resolveComponent(n.type),ms),[o,n.type]);return x.useEffect(()=>o.instanceData.watchItem(null,H.throttle(s=>{e.viz.setConf(s)},100,{leading:!1,trailing:!0})),[o]),{instance:o,vizManager:r,interactionManager:a,sampleData:t,variables:[]}},Q4=()=>{const e=X4();return l(Y4,{...e})},Z4=se.observer(()=>{const{panel:e}=jt();return l(Jy,{label:"Description",value:e.description,onChange:e.setDescription,styles:{root:{flexGrow:1}}})}),J4=se.observer(()=>{const{panel:e}=jt(),{style:t}=e;return l(De,{children:l(d.Switch,{label:"Border",checked:t.border.enabled,onChange:n=>t.border.setEnabled(n.currentTarget.checked)})})}),eG=se.observer(()=>{const{panel:{title:e,style:{border:t}}}=jt();return l(Wr,{children:b(d.Stack,{mx:"auto",mt:"xl",p:"5px",spacing:5,sx:{width:"600px",height:"450px",background:"transparent",borderRadius:"5px",border:"1px solid #e9ecef",borderWidth:t.enabled?"1px":"0px"},children:[b(d.Group,{position:"apart",noWrap:!0,sx:{flexGrow:0,flexShrink:0},children:[l(d.Group,{children:l(ny,{})}),l(d.Group,{grow:!0,position:"center",children:l(d.Text,{lineClamp:1,weight:"bold",children:e})}),l(d.Group,{position:"right",spacing:0,sx:{height:"28px"}})]}),l(d.Group,{sx:{background:"#eee",flexGrow:1}})]})})}),tG=se.observer(()=>{const{panel:e}=jt(),{title:t,setTitle:n}=e,[r,i]=wt.useInputState(t),o=t!==r,a=W.default.useCallback(()=>{!o||n(r)},[o,r]);return l(d.TextInput,{value:r,onChange:i,label:b(d.Group,{children:[l(d.Text,{children:"Panel Title"}),l(d.ActionIcon,{variant:"subtle",color:"blue",disabled:!o,onClick:a,children:l(te.DeviceFloppy,{size:20})})]}),styles:{label:{display:"block",paddingBottom:"4px"}}})});function nG(){return b(d.Group,{grow:!0,noWrap:!0,align:"stretch",sx:{height:"100%"},children:[b(d.Stack,{sx:{width:"40%",flexShrink:0,flexGrow:0,height:"100%"},children:[l(d.Divider,{label:"Style",labelPosition:"center",variant:"dashed"}),l(J4,{}),l(d.Divider,{label:"Info",labelPosition:"center",variant:"dashed"}),l(tG,{}),l(Z4,{})]}),l(d.Box,{sx:{height:"100%",flexGrow:1,maxWidth:"60%"},children:l(eG,{})})]})}const rG=se.observer(function(){const t=Ze(),{panel:{queryID:n,setQueryID:r}}=jt(),i=W.default.useMemo(()=>t.queries.current.map(o=>({value:o.id,label:o.name})),[t.queries.current]);return b(d.Stack,{children:[b(d.Group,{position:"left",sx:{maxWidth:"600px",alignItems:"baseline"},children:[l(d.Text,{children:"Select a Query"}),l(d.Select,{data:i,value:n,onChange:r,allowDeselect:!1,clearable:!1,sx:{flexGrow:"1 !important"}})]}),l(Vm,{id:n})]})});var gb=(e=>(e.migrated="migrated",e.nothingToMigrate="nothingToMigrate",e.checkFailed="checkFailed",e.migrationFailed="migrationFailed",e))(gb||{}),ys=(e=>(e.notStarted="notStarted",e.inProgress="inProgress",e.done="done",e))(ys||{});class iG{constructor(t){ke(this,"vizInstance");ke(this,"operationManager");ke(this,"triggerManager");ke(this,"vizManager");ke(this,"runningMigration");ke(this,"panelModel");ke(this,"status","notStarted");this.panelModel=t.getRequired($t.instanceScope.panelModel),this.vizInstance=t.getRequired($t.instanceScope.vizInstance),this.operationManager=t.getRequired($t.instanceScope.operationManager),this.triggerManager=t.getRequired($t.instanceScope.triggerManager),this.vizManager=t.getRequired($t.vizManager)}async createMigrationTask(){const t=[];try{await this.instanceNeedMigration()&&t.push(()=>this.runInstanceMigration()),await this.interactionNeedMigration()&&t.push(()=>this.runInteractionMigration())}catch(n){return console.warn("check migration failed",n),"checkFailed"}if(t.length===0)return"nothingToMigrate";try{return await Promise.all(t.map(n=>n())),"migrated"}catch(n){return console.warn("migration failed",n),"migrationFailed"}}async runMigration(){return this.runningMigration||(this.status="inProgress",this.runningMigration=this.createMigrationTask().then(t=>(this.status="done",t))),this.runningMigration}async runInteractionMigration(){await this.operationManager.runMigration(),await this.triggerManager.runMigration()}async runInstanceMigration(){const t=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData,panelModel:this.panelModel};await t.migrator.migrate(n)}async instanceNeedMigration(){const t=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData};return t.migrator.needMigration(n)}async interactionNeedMigration(){return await this.operationManager.needMigration()||await this.triggerManager.needMigration()}}function vb(e){const{panel:t}=jt();return x.useCallback(n=>{const r=n.getRequired($t.vizManager),i=r.resolveComponent(e.viz.type);return n.createScoped().provideFactory($t.instanceScope.vizInstance,()=>r.getOrCreateInstance(e)).provideFactory($t.instanceScope.interactionManager,o=>{const a=o.getRequired($t.instanceScope.vizInstance);return new zc(a,i,ms)}).provideFactory($t.instanceScope.operationManager,o=>o.getRequired($t.instanceScope.interactionManager).operationManager).provideFactory($t.instanceScope.triggerManager,o=>o.getRequired($t.instanceScope.interactionManager).triggerManager).provideValue($t.instanceScope.panelModel,t).provideFactory($t.instanceScope.migrator,o=>new iG(o))},[e.viz.type,e.viz.conf])}function mb(e){const[t,n]=x.useState(!1),r=nd().getRequired($t.instanceScope.migrator);return nt.useAsyncEffect(async()=>{const i=r.status===ys.notStarted;n(r.status===ys.done),r.status===ys.notStarted&&r.runMigration().then(o=>{o===gb.migrated&&i&&(e==null||e())}).finally(()=>{n(!0)})},[r]),t}function yb(e,t){const n=nd().getRequired($t.instanceScope.vizInstance);return x.useEffect(()=>n.instanceData.watchItem(null,r=>{e(r)}),[e,t.viz.type]),n}function oG({setVizConf:e,...t}){const{panel:n}=t,r=yb(e,n),i=mb(()=>{Po.showNotification({title:`${n.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})});return nt.useAsyncEffect(async()=>{await r.instanceData.setItem(null,n.viz.conf)},[r,n.viz.type]),i?l(FL,{...t}):l(d.Text,{children:"Checking update..."})}function aG(e){const{panel:t,setVizConf:n}=e;return yb(n,t),mb(()=>{Po.showNotification({title:`${t.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?l(zL,{...e}):l(d.Text,{children:"Checking update"})}const Qj="";function sG(e,t){const{vizManager:n}=x.useContext(Gn),{panel:{viz:r,title:i,id:o,description:a,queryID:s,variables:u}}=jt(),c={title:i,id:o,description:a,queryID:s,viz:r,layout:t},f=vb(c);try{return n.resolveComponent(r.type),l(Lo,{configure:f,children:l(aG,{setVizConf:r.setConf,panel:c,data:e,variables:u,vizManager:n})})}catch(h){return console.info(H.get(h,"message")),null}}const lG=["richText","button"],bb=se.observer(function({height:t,viz:n,data:r,loading:i,error:o,query:a}){const{ref:s,width:u,height:c}=wt.useElementSize(),f=sG(r,{w:u,h:c});if(lG.includes(n.type))return l("div",{className:"viz-root",style:{height:t},ref:s,children:l(Wr,{children:f})});if(i)return l("div",{className:"viz-root",style:{height:t},ref:s,children:l(d.LoadingOverlay,{visible:i,exitTransitionDuration:0})});const p=!!o,g=!p&&!!(a!=null&&a.stateMessage),v=!p&&!g;return b("div",{className:"viz-root",style:{height:t},ref:s,children:[p&&l(d.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:o}),g&&l(d.Text,{color:"gray",align:"center",children:a.stateMessage}),v&&l(Wr,{children:f})]})}),uG=se.observer(()=>{const{data:e,loading:t,panel:{viz:n}}=jt();return l(bb,{viz:n,data:e,loading:t,height:"100%"})}),Fc=[];function cG(){const{vizManager:e}=x.useContext(Gn);return x.useMemo(()=>e.availableVizList.map(t=>({value:t.name,label:t.displayName})).concat(Fc),[e])}function dG(e,t){try{return e.resolveComponent(t).createConfig()}catch{return null}}function fG(){const{data:e,panel:{variables:t,viz:n,title:r,queryID:i,description:o,setDescription:a,setTitle:s,setQueryID:u,id:c}}=jt(),{vizManager:f}=x.useContext(Gn),h={title:r,description:o,viz:n,queryID:i,id:c},p={setDescription:a,setQueryID:u,setTitle:s},g=vb(h);try{return f.resolveComponent(h.viz.type),l(Lo,{configure:g,children:l(oG,{variables:t,setVizConf:n.setConf,panel:h,panelInfoEditor:p,vizManager:f,data:e})})}catch(v){return console.info(H.get(v,"message")),null}}const pG=se.observer(()=>{const{data:e,panel:{viz:t}}=jt(),[n,r]=wt.useInputState(t.type),i=t.type!==n,{vizManager:o}=x.useContext(Gn),a=W.default.useCallback(()=>{if(!i)return;const g=dG(o,n);t.setType(n),t.setConf(g||{})},[t,i,n]),s=g=>{try{t.setConf(JSON.parse(g))}catch(v){console.error(v)}},u=W.default.useMemo(()=>{var g;return(g=Fc.find(v=>v.value===n))==null?void 0:g.Panel},[n,Fc]),c=fG(),f=u?x.createElement(u,{data:e,conf:t.conf,setConf:t.setConf}):null,h=c||f,p=cG();return b(De,{children:[l(d.Select,{label:"Visualization",value:n,onChange:r,data:p,rightSection:l(d.ActionIcon,{disabled:!i,onClick:a,children:l(te.DeviceFloppy,{size:20})})}),h,!h&&l(d.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(t.conf,null,2),onChange:s})]})});function hG(){return b(d.Group,{grow:!0,noWrap:!0,align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[l(d.Stack,{sx:{width:"40%",flexShrink:0,flexGrow:0,overflow:"auto",height:"100%"},children:l(pG,{})}),l(d.Box,{sx:{height:"100%",flexGrow:1,maxWidth:"60%"},children:l(uG,{})})]})}const gG=D.types.model("VariableModel",{name:D.types.string,size:D.types.string,weight:D.types.string,color:D.types.union(D.types.model({type:D.types.literal("static"),staticColor:D.types.string}),D.types.model({type:D.types.literal("continuous"),valueRange:D.types.array(D.types.number),colorRange:D.types.array(D.types.string)}),D.types.model({type:D.types.literal("piecewise")})),formatter:D.types.model({output:D.types.enumeration("Output",["number","percent"]),mantissa:D.types.number,average:D.types.optional(D.types.boolean,!1),trimMantissa:D.types.optional(D.types.boolean,!1)}),data_field:D.types.string,aggregation:D.types.union(D.types.model({type:D.types.enumeration(["none","sum","mean","median","min","max"]),config:D.types.frozen()}),D.types.model({type:D.types.literal("quantile"),config:D.types.model({p:D.types.number})}))}).views(e=>({get json(){return D.getSnapshot(e)}}));class vG{constructor(t){ke(this,"origin");ke(this,"copy");this.origin=t,this.copy=D.clone(t),zt.makeAutoObservable(this,{},{autoBind:!0,deep:!1})}get changed(){return!H.isEqual(D.getSnapshot(this.origin),D.getSnapshot(this.copy))}commit(){D.applySnapshot(this.origin,D.getSnapshot(this.copy))}update(t){D.applySnapshot(this.copy,t)}}const mG=e=>new vG(e),Bc={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 yG{constructor(t){ke(this,"panel");ke(this,"selected");this.panel=t,zt.makeAutoObservable(this,{},{deep:!1,autoBind:!0})}get variables(){return this.panel.variables}addNew(){const t=this.panel.variables.filter(n=>n.name.startsWith(Bc.name)).length;this.panel.addVariable(H.cloneDeep({...Bc,name:`${Bc.name}${t||""}`})),this.selected=H.last(this.panel.variables)}select(t){this.selected=t}remove(t){this.selected===t&&(this.selected=void 0);const n=this.panel.variables.indexOf(t);if(this.panel.removeVariable(t),!this.selected&&!H.isEmpty(this.panel.variables)){const r=Math.min(this.panel.variables.length-1,n);this.selected=this.panel.variables[r]}}}function bG(){const{panel:e}=jt();return nt.useCreation(()=>new yG(e),[e])}const wG=W.default.forwardRef(function({value:t,onChange:n,data:r,withStyle:i=!0},o){const a=(s,u)=>{const c=ye.default.cloneDeep(t);ye.default.set(c,s,u),n(c)};return b(d.Box,{px:"sm",py:"md",ref:o,children:[b(d.Group,{grow:!0,noWrap:!0,children:[l(d.TextInput,{label:"Name",required:!0,value:t.name,onChange:s=>a("name",s.currentTarget.value)}),l(mt,{label:"Data Field",required:!0,data:r,value:t.data_field,onChange:s=>a("data_field",s)})]}),l(xy,{label:"Aggregation",value:t.aggregation,onChange:s=>a("aggregation",s)}),l(d.Divider,{my:"xs",label:"Format",labelPosition:"center"}),l(jr,{value:t.formatter,onChange:s=>a("formatter",s)}),i&&l(Cy,{value:t,onChange:n})]})}),wb=d.createStyles(e=>({root:{height:"100%",overflow:"hidden",".var-list-container":{"& > *":{height:"100%"},width:250,height:"100%"},".var-list-actions":{height:"fit-content",flexShrink:0,width:"100%"},".var-list":{flex:"1 1 auto",overflow:"auto",minHeight:0,"& > *":{flex:"0 0 auto"}}},config:{height:"100%",overflow:"auto",paddingRight:10}})),xG=e=>{const{uiModel:t}=e;return l(d.Stack,{className:"var-list",children:t.variables.map(n=>l(d.Button,{variant:t.selected===n?"filled":"subtle",color:"gray",onClick:()=>t.select(n),children:n.name},n.name))})},SG=se.observer(xG),CG=({variable:e,data:t})=>l(d.Group,{style:{minHeight:0,height:"calc(100% - 68px)"},children:l(d.Paper,{withBorder:!0,p:"md",children:Ky(e,t)})}),_G=se.observer(CG),EG=e=>{const t=nt.useCreation(()=>mG(e.variable),[e.variable]),{classes:n}=wb(),{data:r}=jt();return b(d.Group,{style:{height:"100%"},align:"start",children:[b(d.Stack,{"data-testid":"variable-editor",align:"stretch",className:n.config,children:[b(d.Group,{position:"right",children:[l(d.ActionIcon,{variant:"filled",disabled:!t.changed,color:"primary",onClick:t.commit,children:l(mm,{size:18})}),l(d.ActionIcon,{color:"red",onClick:()=>e.uiModel.remove(e.variable),children:l(ym,{size:18})})]}),l(wG,{value:D.getSnapshot(t.copy),onChange:t.update,data:r})]}),l(_G,{variable:D.getSnapshot(t.copy),data:r})]})},TG=se.observer(EG),MG=()=>{const e=bG(),{classes:t}=wb();return b(d.Group,{className:t.root,noWrap:!0,align:"start",children:[l(d.Paper,{withBorder:!0,p:"md",className:"var-list-container",children:b(d.Stack,{justify:"space-between",children:[l(d.Box,{className:"var-list-actions",children:l(d.Button,{variant:"light",size:"sm",onClick:e.addNew,fullWidth:!0,children:"Add Variable"})}),l(SG,{uiModel:e})]})}),e.selected?l(De,{children:l(TG,{uiModel:e,variable:e.selected})}):l("span",{children:"Select or create a new variable on right side"})]})},OG=se.observer(MG),DG=se.observer(function({opened:t,close:n}){const{freezeLayout:r}=W.default.useContext(_n),[i,o]=x.useState("Visualization"),{panel:a,loading:s}=jt(),{id:u,title:c}=a;return W.default.useEffect(()=>{r(t)},[t]),l(d.Modal,{size:"96vw",overflow:"inside",opened:t,onClose:n,title:`Editing Panel - ${c.trim()?c:u}`,trapFocus:!0,onDragStart:f=>{f.stopPropagation()},children:l(d.AppShell,{sx:{height:"90vh",maxHeight:"calc(100vh - 185px)",".mantine-AppShell-body":{height:"100%"},main:{height:"100%",minHeight:"unset",maxHeight:"100%",width:"100%",padding:"16px"}},padding:"md",children:b(d.Tabs,{value:i,onTabChange:o,className:"panel-settings-tabs",children:[b(d.Tabs.List,{children:[l(d.Tabs.Tab,{value:"Data",children:"Data"}),l(d.Tabs.Tab,{value:"Panel",children:"Panel"}),l(d.Tabs.Tab,{value:"Variables",children:"Variables"}),l(d.Tabs.Tab,{value:"Visualization",children:"Visualization"}),l(d.Tabs.Tab,{value:"Interactions",children:"Interactions"})]}),b(d.Tabs.Panel,{value:"Data",pt:"sm",children:[l(d.LoadingOverlay,{visible:s,exitTransitionDuration:0}),l(rG,{})]}),l(d.Tabs.Panel,{value:"Panel",pt:"sm",children:i==="Panel"&&l(nG,{})}),l(d.Tabs.Panel,{value:"Variables",pt:"sm",children:i==="Variables"&&l(OG,{})}),l(d.Tabs.Panel,{value:"Visualization",pt:"sm",children:i==="Visualization"&&l(hG,{})}),l(d.Tabs.Panel,{value:"Interactions",pt:"sm",children:l(Wr,{children:l(Q4,{})})})]})})})}),RG=se.observer(({view:e})=>{const t=Ze(),n=Ss.useModals(),[r,i]=W.default.useState(!1),o=()=>i(!0),a=()=>i(!1),{panel:s}=jt(),{id:u,query:c}=s,{inEditMode:f}=W.default.useContext(_n),h=()=>c==null?void 0:c.fetchData(),{viewPanelInFullScreen:p,inFullScreen:g}=W.default.useContext(Os),v=()=>{e.panels.duplicateByID(u)},m=()=>n.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>e.panels.removeByID(u)}),w=W.default.useCallback(()=>{p(u)},[u,p]),y=!g&&e.type!==Ye.Modal;return b(De,{children:[l(d.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:b(d.Menu,{withinPortal:!0,children:[l(d.Menu.Target,{children:l(d.Box,{className:"panel-dropdown-target",sx:{width:"100%",height:"25px"}})}),b(d.Menu.Dropdown,{children:[l(d.Menu.Item,{onClick:h,icon:l(te.Refresh,{size:14}),children:"Refresh"}),l(d.Menu.Item,{onClick:()=>{var _;return t.queries.downloadDataByQueryID((_=c==null?void 0:c.id)!=null?_:"")},icon:l(te.Download,{size:14}),children:"Download Data"}),y&&l(d.Menu.Item,{onClick:w,icon:l(te.ArrowsMaximize,{size:14}),children:"Full Screen"}),f&&b(De,{children:[l(d.Divider,{label:"Edit",labelPosition:"center"}),l(d.Menu.Item,{onClick:o,icon:l(te.Settings,{size:14}),children:"Settings"}),l(d.Menu.Item,{onClick:v,icon:l(te.Copy,{size:14}),children:"Duplicate"}),l(d.Menu.Item,{color:"red",onClick:m,icon:l(te.Trash,{size:14}),children:"Delete"})]})]})]})}),f&&l(DG,{opened:r,close:a})]})}),Zj="",kG=se.observer(function(){const{panel:t}=jt(),{title:n}=t;return n?l(d.Group,{grow:!0,position:"center",px:20,className:"panel-title-wrapper",sx:{flexGrow:1},children:l(d.Text,{align:"center",lineClamp:1,weight:"bold",children:n})}):null});function AG(e){return!["richText","button"].includes(e)}const PG={border:"1px solid #e9ecef"},xb={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function NG(e,t,n){return e.style.border.enabled?PG:n||t?xb:{border:"1px dashed transparent"}}const bs=se.observer(function({panel:t,view:n}){const r=Ze(),{inEditMode:i}=x.useContext(_n),{data:o,state:a,error:s}=r.getDataStuffByID(t.queryID),u=r.queries.findByID(t.queryID),c=AG(t.viz.type),f=c&&a==="loading",h=t.title?"calc(100% - 25px - 5px)":"100%",p=NG(t,c,i),g=c||i;return l(ad,{value:{panel:t,data:o,loading:f},children:b(d.Box,{className:"panel-root",p:5,pt:0,sx:{...p},children:[l(d.Box,{sx:{position:"absolute",left:0,top:0,height:28,zIndex:310},children:l(ny,{})}),g&&l(RG,{view:n}),l(kG,{}),l(bb,{viz:t.viz,data:o,loading:f,error:s,height:h,query:u})]})})}),Sb=se.observer(function({view:t,panel:n,exitFullScreen:r}){return b(d.Stack,{px:"10px",pb:"5px",sx:{height:"100%",flexGrow:1,justifyContent:"flex-start"},children:[l(d.Group,{sx:{flexGrow:0},children:l(d.Button,{variant:"default",size:"sm",onClick:r,leftIcon:l(te.ArrowLeft,{size:20}),children:"Exit fullscreen"})}),l(d.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:l(bs,{view:t,panel:n})})]})});function Cb(e,t,n){const r=e.id==="Main",[i,o]=W.default.useState(()=>r&&e.panels.findByID(t)?t:null),a=W.default.useCallback(f=>{o(f),r&&n(f)},[r,n]),s=W.default.useCallback(()=>{o(null),r&&n("")},[r,n]),u=i?e.panels.findByID(i):null;return{viewPanelInFullScreen:a,exitFullScreen:s,inFullScreen:!!u,fullScreenPanel:u}}const Jj="",IG=W.default.forwardRef(({handleAxis:e},t)=>l(d.ActionIcon,{ref:t,className:"react-grid-customDragHandle",sx:{userSelect:"none",cursor:"grab",position:"absolute",top:0,right:0,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",children:l(te.ArrowsMove,{size:16})})),$G=W.default.forwardRef(({handleAxis:e,...t},n)=>l(d.ActionIcon,{ref:n,className:"react-grid-customResizeHandle",sx:{userSelect:"none",cursor:"nwse-resize",position:"absolute",bottom:-5,right:-5,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",...t,children:l(te.ChevronDownRight,{size:16})})),LG=_s.WidthProvider(Zc.default),VG=se.observer(function({view:t,className:n="layout",rowHeight:r=10,isDraggable:i,isResizable:o}){const a=W.default.useCallback(s=>{s.forEach(({i:u,...c})=>{const f=t.panels.findByID(u);!f||f.layout.set(c)})},[t]);return l(LG,{onLayoutChange:a,className:`dashboard-layout ${n}`,rowHeight:r,layout:t.panels.layouts,isDraggable:i,isResizable:o,draggableHandle:".react-grid-customDragHandle",resizeHandle:l($G,{}),children:t.panels.list.map((s,u)=>b("div",{"data-grid":{...s.layout},style:{position:"relative"},children:[i&&l(IG,{}),l(bs,{view:t,panel:s})]},s.id))})}),zG=_s.WidthProvider(Zc.default),FG=se.observer(function({view:t,className:n="layout",rowHeight:r=10}){return l(zG,{className:`dashboard-layout ${n}`,rowHeight:r,isDraggable:!1,isResizable:!1,layout:t.panels.layouts,children:t.panels.list.map(i=>l("div",{"data-grid":i.layout,children:l(bs,{view:t,panel:i})},i.id))})}),BG=se.observer(({children:e})=>l(d.Box,{children:e})),GG=se.observer(({children:e,view:t})=>{const n=t.config;return l(d.Modal,{size:n.width,overflow:"inside",opened:!0,onClose:ye.default.noop,withCloseButton:!1,title:n.custom_modal_title.value,trapFocus:!0,onDragStart:r=>{r.stopPropagation()},styles:{root:{position:"relative",height:"calc(100% - 44px)"},overlay:{position:"absolute !important"},modal:{border:"1px solid #efefef"},body:{maxHeight:"calc(100vh - 325px)"}},withinPortal:!1,transitionDuration:0,children:e})}),jG=({variant:e,orientation:t})=>{const n={tab:{},panel:{padding:"16px"}};return e==="pills"&&t==="horizontal"&&(n.tab.paddingTop="6px",n.tab.paddingBottom="6px"),t==="vertical"&&(n.tab["&.add-a-tab"]={paddingTop:"1px",paddingBottom:"1px"},n.tab["&.add-a-tab .mantine-Tabs-tabLabel"]={marginLeft:"auto",marginRight:"auto"}),n},KG=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},HG=se.observer(({children:e,view:t})=>{const n=Ze(),r=x.useMemo(()=>n.views.options.filter(o=>o.type===Ye.Division),[t.id,n.views.options]),i=t.config;return b(d.Box,{className:"preview-view-tabs",children:[b(d.Tabs,{variant:i.variant,orientation:i.orientation,defaultValue:i.tabs.length>0?i.tabs[0].id:"0",styles:jG(i),children:[b(d.Tabs.List,{grow:i.grow,children:[i.tabs.map(o=>{var a;return l(d.Tabs.Tab,{value:o.id,sx:KG(o),children:(a=o.name)!=null?a:o.id},o.id)}),l(d.Tabs.Tab,{onClick:i.addTab,value:"add",className:"add-a-tab",children:l(d.ActionIcon,{children:l(te.Plus,{size:18,color:"#228be6"})})})]}),i.tabs.map(o=>{const a=n.views.findByID(o.view_id);return b(d.Tabs.Panel,{value:o.id,sx:{position:"relative"},children:[b(d.Box,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:1},children:[l(d.Overlay,{opacity:.8,color:"#FFF",blur:10,zIndex:-1}),b(d.Stack,{mx:"auto",mt:100,sx:{width:"300px"},children:[l(d.TextInput,{label:"Tab Name",value:o.name,onChange:s=>o.setName(s.currentTarget.value)}),l(d.Select,{label:"View",value:o.view_id,onChange:o.setViewID,data:r}),l(d.ColorInput,{label:"Color",value:o.color,onChange:o.setColor,disabled:i.variant!=="default"}),a&&b(d.Button,{mt:20,variant:"gradient",leftIcon:l(S$,{size:18}),gradient:{from:"cyan",to:"indigo"},onClick:()=>n.views.setIDOfVIE(a.id),children:["Swith to View: ",a.name]})]})]}),a&&l(ws,{view:a})]},o.id)})]}),e]})}),qG=se.observer(({view:e,children:t})=>{switch(e.type){case Ye.Modal:return l(GG,{view:e,children:t});case Ye.Tabs:return l(HG,{view:e,children:t});case Ye.Division:default:return l(BG,{children:t})}}),_b=se.observer(function({view:t,saveDashboardChanges:n}){const{fullScreenPanelID:r,setFullScreenPanelID:i}=Rs(),{viewPanelInFullScreen:o,exitFullScreen:a,inFullScreen:s,fullScreenPanel:u}=Cb(t,r,i);return l(Os.Provider,{value:{viewPanelInFullScreen:o,inFullScreen:s},children:b(d.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:[s&&l(Sb,{view:t,panel:u,exitFullScreen:a}),!s&&l(qm,{saveChanges:n,inUseMode:!1}),l(qG,{view:t,children:b(d.Box,{sx:{position:"relative"},children:[!s&&l(d.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:l(Uh,{view:t})}),!s&&l(VG,{view:t,isDraggable:!0,isResizable:!0})]})})]})})}),WG=se.observer(({children:e})=>l(d.Box,{children:e})),UG=se.observer(({children:e,view:t})=>{const n=Ze(),r=t.config,i=n.views.visibleViewIDs.includes(t.id),o=()=>n.views.rmVisibleViewID(t.id);return l(d.Modal,{size:r.width,centered:!0,overflow:"inside",opened:i,onClose:o,withCloseButton:!1,title:r.custom_modal_title.value,trapFocus:!0,onDragStart:a=>{a.stopPropagation()},styles:{modal:{border:"1px solid #efefef"},body:{maxHeight:r.height,overflow:"auto"}},transitionDuration:0,children:e})}),YG=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},XG=se.observer(({children:e,view:t})=>{const n=Ze(),r=t.config;return b(d.Box,{className:"render-view-tabs",children:[b(d.Tabs,{variant:r.variant,orientation:r.orientation,defaultValue:r.tabs.length>0?r.tabs[0].id:"0",styles:{panel:{padding:"16px 0px"}},keepMounted:!1,children:[l(d.Tabs.List,{grow:r.grow,children:r.tabs.map(i=>{var o;return l(d.Tabs.Tab,{value:i.id,sx:YG(i),disabled:!i.view_id,children:(o=i.name)!=null?o:i.id},i.id)})}),r.tabs.map(i=>{const o=n.views.findByID(i.view_id);return o?l(d.Tabs.Panel,{value:i.id,children:l(ws,{view:o})},i.id):null})]}),e]})}),QG=se.observer(({view:e,children:t})=>{switch(e.type){case Ye.Modal:return l(UG,{view:e,children:t});case Ye.Tabs:return l(XG,{view:e,children:t});case Ye.Division:default:return l(WG,{children:t})}}),ws=se.observer(function({view:t}){const{fullScreenPanelID:n,setFullScreenPanelID:r}=Rs(),{viewPanelInFullScreen:i,exitFullScreen:o,inFullScreen:a,fullScreenPanel:s}=Cb(t,n,r);return l(Os.Provider,{value:{viewPanelInFullScreen:i,inFullScreen:a},children:b(d.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:[a&&l(Sb,{view:t,panel:s,exitFullScreen:o}),!a&&l(qm,{saveChanges:ye.default.noop,inUseMode:!0}),l(QG,{view:t,children:b(d.Box,{sx:{position:"relative"},children:[!a&&l(d.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:l(Uh,{view:t})}),!a&&l(FG,{view:t})]})})]})})}),Eb=D.types.model("FilterConfigModel_Checkbox",{_name:D.types.literal("checkbox"),default_value:D.types.boolean}).actions(e=>({setDefaultValue(t){e.default_value=t}})),ZG=()=>Eb.create({_name:"checkbox",default_value:!1}),JG=D.types.model("FilterConfigModel_DateRange",{_name:D.types.literal("date-range"),required:D.types.boolean,inputFormat:D.types.enumeration("DateRangeInputFormat",["YYYY","YYYYMM","YYYYMMDD","YYYY-MM","YYYY-MM-DD"]),default_value:D.types.optional(D.types.array(D.types.union(D.types.string,D.types.null)),[null,null]),clearable:D.types.boolean,max_days:D.types.optional(D.types.number,0),allowSingleDateInRange:D.types.optional(D.types.boolean,!1)}).views(e=>({truthy(t){return Array.isArray(t)&&t.length===2&&t.every(n=>!!n)}})).views(e=>({getMaxDate(t){const{max_days:n}=e;if(!(!n||!t))return Cn.default(t).startOf("day").add(n,"days").toDate()},getMinDate(t){const{max_days:n}=e;if(!(!n||!t))return Cn.default(t).startOf("day").subtract(n,"days").toDate()}})).actions(e=>({setFilterValue(t){try{const n=D.getParent(e);D.getRoot(e).filters.setValueByKey(n.key,t)}catch(n){console.error(n)}}})).actions(e=>({setRequired(t){e.required=t},setClearable(t){e.clearable=t},setInputFormat(t){e.inputFormat=t},setDefaultValue(t){e.default_value.length=0,e.default_value.push(...t),e.setFilterValue(t)},setMaxDays(t){e.max_days=t,t>0&&(e.clearable=!0)},setAllowSingleDateInRange(t){e.allowSingleDateInRange=t}})),Tb=D.types.snapshotProcessor(JG,{preProcessor({default_value:e,...t}){return{...t,default_value:e.map(n=>n===null?null:Cn.default.tz(n,"UTC").toISOString())}},postProcessor({default_value:e,...t}){return{...t,default_value:e.map(n=>{try{return n?Cn.default.tz(n,"UTC").format(t.inputFormat):null}catch{return console.log(`[date-range] failed parsing ${n}`),null}})}}}),ej=()=>Tb.create({_name:"date-range",required:!1,inputFormat:"YYYY-MM-DD",clearable:!1,default_value:[null,null]}),tj=D.types.model({label:D.types.string,value:D.types.string}).actions(e=>({setLabel(t){e.label=t},setValue(t){e.value=t}})),Gc=D.types.model("FilterConfigModel_BaseSelect",{static_options:D.types.optional(D.types.array(tj),[]),options_query_id:D.types.optional(D.types.string,""),default_selection_count:D.types.optional(D.types.number,0)}).views(e=>({get usingQuery(){return!!e.options_query_id}})).views(e=>({get options(){if(!e.usingQuery)return e.static_options;const{data:t,state:n,error:r}=D.getRoot(e).getDataStuffByID(e.options_query_id);return n==="idle"?t:[]}})).actions(e=>({addStaticOption(t){e.static_options.push(t)},removeStaticOption(t){e.static_options.splice(t,1)},setDefaultSelectionCount(t){e.default_selection_count=t},setOptionsQueryID(t){e.options_query_id=t!=null?t:""}})),Mb=D.types.compose("FilterConfigModel_MultiSelect",D.types.model({_name:D.types.literal("multi-select"),default_value:D.types.optional(D.types.array(D.types.string),[]),min_width:D.types.optional(D.types.string,"")}),Gc).actions(e=>({setDefaultValue(t){e.default_value=D.cast(t)},setMinWidth(t){e.min_width=t}})),nj=()=>Mb.create({_name:"multi-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),Ob=D.types.compose("FilterConfigModel_TreeSelect",D.types.model({_name:D.types.literal("tree-select"),default_value:D.types.optional(D.types.array(D.types.string),[]),min_width:D.types.optional(D.types.string,"")}),Gc).actions(e=>({setDefaultValue(t){e.default_value=D.cast(t)},setMinWidth(t){e.min_width=t}})),rj=()=>Ob.create({_name:"tree-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),Db=D.types.compose("FilterConfigModel_Select",D.types.model({_name:D.types.literal("select"),default_value:D.types.string,required:D.types.boolean,width:D.types.optional(D.types.string,"")}),Gc).views(e=>({truthy(t){return!!t}})).actions(e=>({setRequired(t){e.required=t},setDefaultValue(t){e.default_value=t},setWidth(t){e.width=t}})),ij=()=>Db.create({_name:"select",required:!1,default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),jc=D.types.model("FilterModel",{id:D.types.identifier,key:D.types.string,label:D.types.string,order:D.types.number,visibleInViewsIDs:D.types.array(D.types.string),auto_submit:D.types.optional(D.types.boolean,!1),type:D.types.enumeration("DashboardFilterType",[Ht.Select,Ht.MultiSelect,Ht.TreeSelect,Ht.TextInput,Ht.Checkbox,Ht.DateRange]),config:D.types.union(Db,Mb,Ob,Bm,Eb,Tb)}).views(e=>({get plainDefaultValue(){const t=e.config.default_value;return Array.isArray(t)?[...t]:t},get usingDefaultValue(){return e.type!==Ht.TreeSelect},get auto_submit_supported(){return[Ht.Select,Ht.Checkbox,Ht.DateRange].includes(e.type)}})).views(e=>({get should_auto_submit(){return e.auto_submit_supported&&e.auto_submit},requiredAndPass(t){return ye.default.get(e.config,"required",!1)?ye.default.get(e.config,"truthy",()=>!0)(t):!1}})).actions(e=>({setKey(t){e.key=t},setLabel(t){e.label=t},setOrder(t){e.order=t},setType(t){switch(t){case Ht.Select:e.config=ij();break;case Ht.MultiSelect:e.config=nj();break;case Ht.TreeSelect:e.config=rj();break;case Ht.TextInput:e.config=Gm();break;case Ht.Checkbox:e.config=ZG();break;case Ht.DateRange:e.config=ej();break}e.type=t},setVisibleInViewsIDs(t){e.visibleInViewsIDs.length=0,e.visibleInViewsIDs.push(...t)},setAutoSubmit(t){e.auto_submit=e.auto_submit_supported&&t}}));function Rb(e,t){if(e===void 0)return e;if(t._name==="date-range")try{const[...n]=e;return n.map(r=>{if(r===null)return r;const i=Cn.default.tz(r,"UTC").format(t.inputFormat);return i!=null?i:r})}catch(n){return console.error(n),e}return e}function kb(e){return e.reduce((t,n)=>(t[n.key]=Rb(n.config.default_value,n.config),t),{})}function oj(e,t,n){D.addDisposer(e,D.addMiddleware(e,(r,i)=>{i(r,()=>{D.getType(r.context)===t&&r.type==="action"&&n(r.name,r.context)})}))}const Ab=D.types.model("FiltersModel",{current:D.types.optional(D.types.array(jc),[]),values:D.types.optional(D.types.frozen(),{}),previewValues:D.types.optional(D.types.frozen(),{})}).views(e=>({get firstID(){if(e.current.length!==0)return e.current[0].id},get inOrder(){return ye.default.sortBy(e.current,"order")},get empty(){return e.current.length===0},visibleInView(t){return ye.default.sortBy(e.current.filter(n=>n.visibleInViewsIDs.includes(t)),"order")},get firstFilterValueKey(){var t;return(t=Object.keys(e.values)[0])!=null?t:""},get keyLabelMap(){return e.current.reduce((t,n)=>(t[n.key]=n.label,t),{})}})).actions(e=>({replace(t){e.current=D.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},setValues(t){e.values=t},setValueByKey(t,n){e.values={...e.values,[t]:n}},getValueByKey(t){return e.values[t]},refreshValues(){console.log("refreshing values"),e.values=kb(e.current)},updatePreviewValues(t){e.previewValues=t}})).actions(e=>{function t(){oj(e.current,jc,(n,r)=>{if(n==="setType"){const i=Rb(r.config.default_value,r.config);e.setValueByKey(r.key,i),e.updatePreviewValues({...e.previewValues,[r.key]:i})}})}return{afterCreate(){t()}}});function Pb(e){return{current:e,values:kb(e)}}const aj=D.types.model("QueryModel",{id:D.types.string,name:D.types.string,type:D.types.enumeration("DataSourceType",[Sn.Postgresql,Sn.MySQL,Sn.HTTP]),key:D.types.string,sql:D.types.string,pre_process:D.types.optional(D.types.string,""),post_process:D.types.optional(D.types.string,""),run_by:D.types.optional(D.types.array(D.types.string),[])}).views(e=>({get valid(){return e.id&&e.type&&e.key&&e.name?e.type===Sn.HTTP?!!e.pre_process:!!e.sql:!1},get json(){const{id:t,name:n,type:r,key:i,sql:o,run_by:a,pre_process:s,post_process:u}=e;return{id:t,name:n,type:r,key:i,sql:o,run_by:a,pre_process:s,post_process:u}},get conditionOptions(){const{context:t,mock_context:n,filterValues:r}=D.getRoot(e).payloadForSQL,i=Object.keys({...n,...t}).map(s=>`context.${s}`),o=Object.keys(r).map(s=>`filters.${s}`);return[...i,...o].map(s=>({label:s.split(".")[1],value:s,group:ye.default.capitalize(s.split(".")[0])}))},get unmetRunByConditions(){const{run_by:t}=e;if(t.length===0)return[];const{context:n,mock_context:r,filterValues:i}=D.getRoot(e).payloadForSQL,o={context:{...r,...n},filters:i};return t.filter(a=>{const s=ye.default.get(o,a);return Array.isArray(s)?s.length===0:typeof s=="number"?Number.isNaN(s):!s})}})).views(e=>({get runByConditionsMet(){return e.unmetRunByConditions.length===0},get conditionNames(){if(e.unmetRunByConditions.length===0)return{context:[],filters:[]};const{keyLabelMap:t}=D.getRoot(e).filters,n=e.unmetRunByConditions.filter(i=>i.startsWith("context.")).map(i=>i.split("context.")[0]),r=e.unmetRunByConditions.filter(i=>i.startsWith("filters.")).map(i=>ye.default.get({filters:t},i)).filter(i=>!!i);return{context:n,filters:r}}})).actions(e=>({setName(t){e.name=t},setKey(t){e.key=t},setType(t){e.type=t},setSQL(t){e.sql=t},setRunBy(t){e.run_by.length=0,e.run_by.push(...t)},setPreProcess(t){e.pre_process=t},setPostProcess(t){e.post_process=t}})),Nb=D.types.compose("QueryModel",aj,D.types.model({state:D.types.optional(D.types.enumeration(["idle","loading","error"]),"idle"),data:D.types.optional(D.types.array(D.types.frozen()),[]),error:D.types.frozen()})).views(e=>({get formattedSQL(){const{context:t,mock_context:n,sqlSnippets:r,filterValues:i}=D.getRoot(e).payloadForSQL;return wm(e.sql,t,n,r,i)},get typedAsSQL(){return[Sn.Postgresql,Sn.MySQL].includes(e.type)},get typedAsHTTP(){return[Sn.HTTP].includes(e.type)},get datasource(){const{key:t,type:n}=e;return D.getRoot(e).datasources.find({type:n,key:t})}})).views(e=>({get stateMessage(){if(e.state!=="idle")return"";if(!e.runByConditionsMet){const{context:t,filters:n}=e.conditionNames;if(t.length===0&&n.length===0)return"Waiting";const r=[];return t.length>0&&r.push(`context: ${t.join(", ")}`),n.length>0&&r.push(`filter${n.length>1?"s":""}: ${n.join(", ")}`),r.length===2&&r.splice(1,0,"and"),r.unshift("Waiting for"),r.join(" ")}return e.data.length>0?"":"Empty Data"}})).volatile(()=>({controller:new AbortController})).actions(e=>({runSQL:D.flow(function*(){var t;if(!!e.valid&&((t=e.controller)==null||t.abort(),!!e.runByConditionsMet)){e.controller=new AbortController,e.state="loading";try{const{context:n,mock_context:r,sqlSnippets:i,filterValues:o}=D.getRoot(e).payloadForSQL;e.data=yield*D.toGenerator(X$({context:n,mock_context:r,sqlSnippets:i,title:e.name,query:e.json,filterValues:o},e.controller.signal)),e.state="idle",e.error=null}catch(n){if(!Io.default.isCancel(n)){e.data.length=0;const r=H.get(n,"message","unkown error");e.error=H.get(n,"response.data.detail.message",r),e.state="error"}}}}),runHTTP:D.flow(function*(){var t;if(console.log("runHTTP, ",e.datasource),!(!e.valid||!e.datasource)&&((t=e.controller)==null||t.abort(),!!e.runByConditionsMet)){e.controller=new AbortController,e.state="loading";try{const{context:n,mock_context:r,filterValues:i}=D.getRoot(e).payloadForSQL;e.data=yield*D.toGenerator(Q$({context:n,mock_context:r,query:e.json,filterValues:i,datasource:e.datasource},e.controller.signal)),e.state="idle",e.error=null}catch(n){if(console.error(n),!Io.default.isCancel(n)){e.data.length=0;const r=H.get(n,"message","unkown error");e.error=H.get(n,"response.data.detail.message",r),e.state="error"}}}})})).actions(e=>({fetchData:e.typedAsHTTP?e.runHTTP:e.runSQL,beforeDestroy(){var t;(t=e.controller)==null||t.abort()}})).actions(e=>({afterCreate(){D.addDisposer(e,zt.reaction(()=>{var t;return e.typedAsHTTP?`${e.id}--${e.key}--${e.pre_process}--${e.post_process}--${(t=e.datasource)==null?void 0:t.id}`:`${e.id}--${e.key}--${e.formattedSQL}`},e.fetchData,{fireImmediately:!0,delay:0}))}})),Ib=D.types.model("QueriesModel",{current:D.types.optional(D.types.array(Nb),[])}).views(e=>({get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(n=>n.id===t)},get options(){return e.current.map(t=>({value:t.id,label:t.name}))}})).views(e=>({get json(){return e.current.filter(t=>t.id).map(t=>t.json)}})).actions(e=>({replace(t){e.current=D.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},replaceByIndex(t,n){e.current.splice(t,1,n)},downloadAllData(){const t=e.current.map(({name:n,data:r})=>({id:n,data:r.toJSON()}));L$(t)},downloadDataByQueryID(t){const n=e.findByID(t);if(!n){console.log("[downloadDataByQueryID] query not found");return}const{name:r,data:i}=n,o=bm(i);I$(r,o)},refetchDataByQueryID(t){const n=e.findByID(t);if(!n){console.error(new Error(`[downloadDataByQueryID] query by ID[${t}] not found`));return}return n.fetchData()},removeQuery(t){const n=e.current.find(r=>r.id===t);n&&(D.detach(n),e.current.remove(n))}})),$b=D.types.model("SQLSnippetModel",{key:D.types.string,value:D.types.string}).views(e=>({get json(){const{key:t,value:n}=e;return{key:t,value:n}},isADuplicatedKey(t){return!t||t===e.key?!1:!!D.getParent(e,2).findByKey(t)}})).actions(e=>({setKey(t){e.key=t},setValue(t){e.value=t}})),Lb=D.types.model("SQLSnippetsModel",{current:D.types.optional(D.types.array($b),[])}).views(e=>({get json(){return e.current.map(t=>t.json)},get record(){return e.current.reduce((t,n)=>(t[n.key]=n.value,t),{})},get firstKey(){if(e.current.length!==0)return e.current[0].key},findByKey(t){return e.current.find(n=>n.key===t)}})).actions(e=>({replace(t){e.current=D.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},replaceByIndex(t,n){e.current.splice(t,1,n)}})),Vb=D.types.model("ContextModel",{current:D.types.optional(D.types.frozen(),{})}).views(e=>({get keys(){return Object.keys(e.current)},get entries(){return Object.entries(e.current)}})).actions(e=>({replace(t){e.current=t},get(t){return e.current[t]},set(t,n){e.current[t]=n}})),sj=D.types.model("DataSourcesModel",{list:D.types.optional(D.types.frozen(),[])}).views(e=>({find({type:t,key:n}){return e.list.find(r=>r.key===n&&r.type===t)},get options(){return e.list.map(t=>({value:t.key,label:t.key}))}})).actions(e=>({replace(t){e.list=t}})),lj=D.types.model("MockContextModel",{current:D.types.optional(D.types.frozen(),{})}).views(e=>({get keys(){return Object.keys(e.current)},get entries(){return Object.entries(e.current)}})).actions(e=>({replace(t){e.current=t},get(t){return e.current[t]},set(t,n){e.current[t]=n}})),zb=D.types.model("ViewModel_Division",{_name:D.types.literal(Ye.Division)}).views(e=>({get json(){const{_name:t}=e;return{_name:t}}})).actions(e=>({})),uj=()=>zb.create({_name:Ye.Division}),cj=D.types.model("CustomModalTitleModel",{enabled:D.types.optional(D.types.boolean,!1),func_content:D.types.optional(D.types.string,"")}).views(e=>({get json(){const{enabled:t,func_content:n}=e;return{enabled:t,func_content:n}},get value(){const{enabled:t,func_content:n}=e,r=D.getParent(e,2),i=D.getRoot(e);if(!t)return r.name;try{const o={filters:i.filters.values,context:i.context.current};return new Function(`return ${n}`)()(o)}catch(o){return console.error(o),r.name}}})).actions(e=>({setEnabled(t){e.enabled=t},setFuncContent(t){e.func_content=t},replace({enabled:t,func_content:n}){e.enabled=t,e.func_content=n}})),Fb=D.types.model("ViewModel_Modal",{_name:D.types.literal(Ye.Modal),width:D.types.string,height:D.types.string,custom_modal_title:D.types.optional(cj,nc)}).views(e=>({get json(){const{_name:t,width:n,height:r,custom_modal_title:i}=e;return{_name:t,width:n,height:r,custom_modal_title:i.json}}})).actions(e=>({setWidth(t){e.width=t},setHeight(t){e.height=t}})),dj=()=>Fb.create({_name:Ye.Modal,width:"90vw",height:"90vh"}),fj=D.types.model("PanelLayoutModel",{x:D.types.number,y:D.types.number,w:D.types.number,h:D.types.number,moved:D.types.optional(D.types.boolean,!1),static:D.types.optional(D.types.boolean,!1)}).views(e=>({get json(){const{x:t,y:n,w:r,h:i,moved:o}=e;return{x:t,y:n,w:r,h:i,moved:o,static:e.static}}})).actions(e=>({set(t){const{x:n,y:r,w:i,h:o,moved:a}=t;e.x=n,e.y=r,e.w=i,e.h=o,e.moved=!!a,e.static=!!t.static}})),pj=D.types.model("PanelStyleBorderModel",{enabled:D.types.boolean}).views(e=>({get json(){const{enabled:t}=e;return{enabled:t}}})).actions(e=>({setEnabled(t){e.enabled=t}})),hj=D.types.model("PanelStyleModel",{border:pj}).views(e=>({get json(){const{border:t}=e;return{border:t.json}}})).actions(e=>({})),gj=D.types.model("PanelVizModel",{type:D.types.string,conf:D.types.frozen()}).views(e=>({get json(){return{type:e.type,conf:e.conf}}})).actions(e=>({setType(t){e.type=t},setConf(t){e.conf=t}})),vj=D.types.model({id:D.types.string,title:D.types.string,description:D.types.string,layout:fj,queryID:D.types.string,viz:gj,style:hj,variables:D.types.optional(D.types.array(gG),[])}).views(e=>({get query(){return D.getParentOfType(e,xs).queries.findByID(e.queryID)},get json(){const{id:t,title:n,description:r,queryID:i}=e;return{id:t,title:n,description:r,layout:e.layout.json,queryID:i,viz:e.viz.json,style:e.style.json,variables:e.variables.map(o=>o.json)}}})).actions(e=>({setID(t){e.id=t},setTitle(t){e.title=t},setDescription(t){e.description=t},setQueryID(t){if(D.getParentOfType(e,xs).queries.findByID(t))e.queryID=t;else throw new Error(`Query with id ${t} does not exist`)},addVariable(t){e.variables.push(t)},removeVariable(t){e.variables.remove(t)}})),mj=D.types.model("PanelsModel",{list:D.types.optional(D.types.array(vj),[])}).views(e=>({get json(){return e.list.map(t=>t.json)},get layouts(){return e.list.map(t=>({...t.layout.json,i:t.id}))},findByID(t){return e.list.find(n=>n.id===t)}})).actions(e=>({replace(t){e.list=D.castToSnapshot(t)},addANewPanel(){const t=wt.randomId();e.list.push({id:t,layout:{x:0,y:1/0,w:3,h:15},title:`Panel - ${t}`,description:"<p><br></p>",queryID:"",viz:{type:Pc.name,conf:Pc.createConfig()},style:{border:{enabled:!0}}})},append(t){e.list.push(t)},remove(t){e.list.splice(t,1)},removeByID(t){const n=e.list.findIndex(r=>r.id===t);n!==-1&&e.list.splice(n,1)},duplicateByID(t){const n=e.list.find(r=>r.id===t);if(!n){console.error(new Error(`[duplicate panel] Can't find a panel by id[${t}]`));return}e.list.push({...n.json,id:wt.randomId(),layout:{...n.layout,x:0,y:1/0,moved:!1}})},replaceByIndex(t,n){e.list.splice(t,1,n)}})),yj=D.types.model("ViewModel_Tabs_Tab",{id:D.types.identifier,name:D.types.string,view_id:D.types.string,color:D.types.optional(D.types.string,"")}).views(e=>({get json(){const{id:t,name:n,view_id:r,color:i}=e;return{id:t,name:n,view_id:r,color:i}}})).actions(e=>({setName(t){e.name=t},setViewID(t){e.view_id=t},setColor(t){e.color=t}})),Bb=D.types.model("ViewModel_Tabs",{_name:D.types.literal(Ye.Modal),tabs:D.types.optional(D.types.array(yj),[]),variant:D.types.optional(D.types.enumeration("variant",["default","outline","pills"]),"default"),orientation:D.types.optional(D.types.enumeration("orientation",["horizontal","vertical"]),"horizontal"),grow:D.types.optional(D.types.boolean,!1)}).views(e=>({get json(){const{_name:t,variant:n,orientation:r,tabs:i,grow:o}=e;return{_name:t,variant:n,orientation:r,grow:o,tabs:i.map(a=>a.json)}}})).actions(e=>({setVariant(t){e.variant=t},setOrientation(t){e.orientation=t},setGrow(t){e.grow=t},setTabs(t){e.tabs.length=0,e.tabs=D.cast(t)},addTab(){const t=wt.randomId(),n={id:t,name:t,view_id:""};e.tabs.push(n)},removeTab(t){e.tabs.splice(t,1)}})),bj=()=>Bb.create({_name:Ye.Modal,tabs:[]}),Gb=D.types.model({id:D.types.identifier,name:D.types.string,type:D.types.enumeration("EViewComponentType",[Ye.Division,Ye.Modal,Ye.Tabs]),config:D.types.union(zb,Fb,Bb),panels:mj}).views(e=>({get json(){const{id:t,name:n,type:r,config:i}=e;return{id:t,name:n,type:r,config:i.json,panels:e.panels.json}}})).actions(e=>({setName(t){e.name=t},setType(t){if(e.type!==t){switch(t){case Ye.Division:e.config=uj();break;case Ye.Modal:e.config=dj();break;case Ye.Tabs:e.config=bj();break}e.type=t}}})).actions(e=>({})),jb=D.types.model("ViewsModel",{current:D.types.optional(D.types.array(Gb),[]),visibleViewIDs:D.types.array(D.types.string),idOfVIE:D.types.string}).views(e=>({get json(){return e.current.map(t=>t.json)},findByID(t){return e.current.find(n=>n.id===t)},get isVIETheFirstView(){return e.current.length===0||!e.idOfVIE?!1:e.current[0].id===e.idOfVIE},get firstVisibleView(){const[t]=e.visibleViewIDs;return e.current.find(({id:n})=>n===t)},get visibleViews(){const t=new Set(e.visibleViewIDs);return e.current.filter(({id:n})=>t.has(n))},get VIE(){return e.current.find(({id:t})=>t===e.idOfVIE)},get options(){return e.current.map(t=>({label:t.name,value:t.id,type:t.type}))}})).actions(e=>({replace(t){e.current.replace(t)},addANewView(t,n,r){e.current.push({id:t,name:t,type:n,config:r,panels:{list:[]}})},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByID(t){const n=e.current.findIndex(r=>r.id===t);n!==-1&&e.current.splice(n,1)},replaceByIndex(t,n){e.current.splice(t,1,n)},setIDOfVIE(t){e.idOfVIE=t,e.visibleViewIDs.length=0,e.visibleViewIDs.push(t)},addAPanelToVIE(){var t;(t=e.VIE)==null||t.panels.addANewPanel()},appendToVisibles(t){new Set(e.visibleViewIDs.map(r=>r)).has(t)||e.visibleViewIDs.push(t)}})).actions(e=>({addARandomNewView(){const t=wt.randomId();e.addANewView(t,Ye.Division,{_name:Ye.Division}),e.setIDOfVIE(t)},removeVIE(){e.current.length!==1&&(e.removeByID(e.idOfVIE),e.setIDOfVIE(e.current[0].id))},rmVisibleViewID(t){const n=e.visibleViewIDs.findIndex(r=>r===t);n!==-1&&e.visibleViewIDs.splice(n,1)}}));function Kb(e){const t=e.length>0?[e[0].id]:[],n=e.length>0?e[0].id:"";return{current:e.map(i=>{const{_name:o=i.type}=i.config;return{...i,config:{...i.config,_name:o},panels:{list:i.panels}}}),visibleViewIDs:t,idOfVIE:n}}const wj=D.types.model({id:D.types.identifier,name:D.types.string,version:D.types.string,datasources:sj,filters:Ab,queries:Ib,sqlSnippets:Lb,views:jb,context:Vb,mock_context:lj,origin:D.types.maybe(D.types.frozen())}).views(e=>({get filtersChanged(){const t="filters.current";return!H.isEqual(D.getSnapshot(H.get(e,t)),H.get(e.origin,t))},get queriesChanged(){const t="queries.current",n=D.getSnapshot(H.get(e,t)).map(r=>H.pick(r,["id","name","key","type","sql","run_by","pre_process","post_process"]));return!H.isEqual(n,H.get(e.origin,t))},get sqlSnippetsChanged(){const t="sqlSnippets.current";return!H.isEqual(D.getSnapshot(H.get(e,t)),H.get(e.origin,t))},get viewsChanged(){const t="views.current";return!H.isEqual(D.getSnapshot(H.get(e,t)),H.get(e.origin,t))},get mockContextChanged(){const t="mock_context.current";return!H.isEqual(H.get(e,t),H.get(e.origin,t))}})).views(e=>({get payloadForSQL(){return{context:e.context.current,mock_context:e.mock_context.current,sqlSnippets:e.sqlSnippets.current,filterValues:e.filters.values}},get changed(){return e.filtersChanged||e.queriesChanged||e.sqlSnippetsChanged||e.viewsChanged||e.mockContextChanged},get data(){return e.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(t){const n=e.queries.findByID(t);return n?{data:n.data.toJSON(),dataProxy:n.data,len:n.data.length,state:n.state,error:n.error}:{data:[],dataProxy:null,len:0,state:"idle",error:void 0}},getDataStateByID(t){var n,r;return(r=(n=e.queries.findByID(t))==null?void 0:n.state)!=null?r:[]},getDataErrorByID(t){var n,r;return(r=(n=e.queries.findByID(t))==null?void 0:n.error)!=null?r:[]}})).views(e=>({findDependingPanels(t){return e.views.current.flatMap(n=>n.panels.list.filter(r=>r.queryID===t).map(r=>r.title))}})).actions(e=>({reset(){D.applySnapshot(e.filters.current,e.origin.filters.current),D.applySnapshot(e.queries.current,e.origin.queries.current),D.applySnapshot(e.sqlSnippets.current,e.origin.sqlSnippets.current),D.applySnapshot(e.views.current,e.origin.views.current),e.mock_context.current=e.origin.mock_context.current},resetFilters(){D.applySnapshot(e.filters.current,e.origin.filters.current)}})),xs=D.types.snapshotProcessor(wj,{preProcessor(e){return{...e,origin:e}},postProcessor(e){delete e.origin;const t=D.castToSnapshot(e.queries.current.map(n=>H.pick(n,["id","key","type","sql"])));return H.defaults({},{queries:{current:t}},e)}});function Kc({id:e,name:t,version:n,filters:r,views:i,definition:{queries:o,sqlSnippets:a,mock_context:s={}}},u,c){return xs.create({id:e,name:t,version:n,datasources:{list:u},filters:Pb(r),queries:{current:o},sqlSnippets:{current:a},context:{current:c},mock_context:{current:s},views:Kb(i)})}function Hc(e){return W.default.useCallback(t=>t.provideValue($t.pluginManager,e.pluginManager).provideValue($t.vizManager,e.vizManager).provideValue($t.colorManager,e.colorManager),[])}const eK="",xj=se.observer(function({context:t,dashboard:n,update:r,className:i="dashboard",config:o,fullScreenPanelID:a,setFullScreenPanelID:s}){xm(o);const{data:u=[]}=nt.useRequest(Fu),[c,f]=W.default.useState(!1),h=W.default.useMemo(()=>Kc(n,u,t),[n]);Jc(h,!0),W.default.useEffect(()=>{h.context.replace(t)},[t]),W.default.useEffect(()=>{h.datasources.replace(u)},[u]);const p=async()=>{const m=[...h.queries.json],w=[...h.sqlSnippets.json],y=[...h.views.json],_={...h.mock_context.current},C={...n,filters:[...h.filters.current],views:y,definition:{sqlSnippets:w,queries:m,mock_context:_}};await r(C)},g=nt.useCreation(Vc,[]),v=Hc(g);return l(Ss.ModalsProvider,{children:l(Ds,{value:h,children:l(Vo.Provider,{value:{fullScreenPanelID:a,setFullScreenPanelID:s},children:l(_n.Provider,{value:{layoutFrozen:c,freezeLayout:f,inEditMode:!0,inUseMode:!1},children:l(d.Box,{className:`${i} dashboard-root`,sx:{position:"relative"},children:l(Gn.Provider,{value:g,children:l(Lo,{configure:v,children:h.views.visibleViews.map(m=>l(_b,{view:m,saveDashboardChanges:p},m.id))})})})})})})})}),Sj=se.observer(({context:e,dashboard:t,className:n="dashboard",config:r,fullScreenPanelID:i,setFullScreenPanelID:o})=>{xm(r);const{data:a=[]}=nt.useRequest(Fu),s=W.default.useMemo(()=>Kc(t,a,e),[t]);Jc(s,!1),W.default.useEffect(()=>{s.context.replace(e)},[e]),W.default.useEffect(()=>{s.datasources.replace(a)},[a]);const u=nt.useCreation(Vc,[]),c=Hc(u);return l(Ss.ModalsProvider,{children:l(Ds,{value:s,children:l(Vo.Provider,{value:{fullScreenPanelID:i,setFullScreenPanelID:o},children:l(_n.Provider,{value:{layoutFrozen:!0,freezeLayout:ye.default.noop,inEditMode:!1,inUseMode:!0},children:l(d.Box,{className:`${n} dashboard-root`,children:l(Gn.Provider,{value:u,children:l(Lo,{configure:c,children:s.views.visibleViews.map(f=>l(ws,{view:f},f.id))})})})})})})})});var Hb={exports:{}};(function(e,t){(function(n,r){e.exports=r()})(fn,function(){var n={year:0,month:1,day:2,hour:3,minute:4,second:5},r={};return function(i,o,a){var s,u=function(p,g,v){v===void 0&&(v={});var m=new Date(p),w=function(y,_){_===void 0&&(_={});var C=_.timeZoneName||"short",S=y+"|"+C,E=r[S];return E||(E=new Intl.DateTimeFormat("en-US",{hour12:!1,timeZone:y,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:C}),r[S]=E),E}(g,v);return w.formatToParts(m)},c=function(p,g){for(var v=u(p,g),m=[],w=0;w<v.length;w+=1){var y=v[w],_=y.type,C=y.value,S=n[_];S>=0&&(m[S]=parseInt(C,10))}var E=m[3],M=E===24?0:E,A=m[0]+"-"+m[1]+"-"+m[2]+" "+M+":"+m[4]+":"+m[5]+":000",L=+p;return(a.utc(A).valueOf()-(L-=L%1e3))/6e4},f=o.prototype;f.tz=function(p,g){p===void 0&&(p=s);var v=this.utcOffset(),m=this.toDate(),w=m.toLocaleString("en-US",{timeZone:p}),y=Math.round((m-new Date(w))/1e3/60),_=a(w).$set("millisecond",this.$ms).utcOffset(15*-Math.round(m.getTimezoneOffset()/15)-y,!0);if(g){var C=_.utcOffset();_=_.add(v-C,"minute")}return _.$x.$timezone=p,_},f.offsetName=function(p){var g=this.$x.$timezone||a.tz.guess(),v=u(this.valueOf(),g,{timeZoneName:p}).find(function(m){return m.type.toLowerCase()==="timezonename"});return v&&v.value};var h=f.startOf;f.startOf=function(p,g){if(!this.$x||!this.$x.$timezone)return h.call(this,p,g);var v=a(this.format("YYYY-MM-DD HH:mm:ss:SSS"));return h.call(v,p,g).tz(this.$x.$timezone,!0)},a.tz=function(p,g,v){var m=v&&g,w=v||g||s,y=c(+a(),w);if(typeof p!="string")return a(p).tz(w);var _=function(M,A,L){var F=M-60*A*1e3,P=c(F,L);if(A===P)return[F,A];var O=c(F-=60*(P-A)*1e3,L);return P===O?[F,P]:[M-60*Math.min(P,O)*1e3,Math.max(P,O)]}(a.utc(p,m).valueOf(),y,w),C=_[0],S=_[1],E=a(C).utcOffset(S);return E.$x.$timezone=w,E},a.tz.guess=function(){return Intl.DateTimeFormat().resolvedOptions().timeZone},a.tz.setDefault=function(p){s=p}}})})(Hb);const Cj=Hb.exports;var qb={exports:{}};(function(e,t){(function(n,r){e.exports=r()})(fn,function(){var n="minute",r=/[+-]\d\d(?::?\d\d)?/g,i=/([+-]|\d\d)/g;return function(o,a,s){var u=a.prototype;s.utc=function(m){var w={date:m,utc:!0,args:arguments};return new a(w)},u.utc=function(m){var w=s(this.toDate(),{locale:this.$L,utc:!0});return m?w.add(this.utcOffset(),n):w},u.local=function(){return s(this.toDate(),{locale:this.$L,utc:!1})};var c=u.parse;u.parse=function(m){m.utc&&(this.$u=!0),this.$utils().u(m.$offset)||(this.$offset=m.$offset),c.call(this,m)};var f=u.init;u.init=function(){if(this.$u){var m=this.$d;this.$y=m.getUTCFullYear(),this.$M=m.getUTCMonth(),this.$D=m.getUTCDate(),this.$W=m.getUTCDay(),this.$H=m.getUTCHours(),this.$m=m.getUTCMinutes(),this.$s=m.getUTCSeconds(),this.$ms=m.getUTCMilliseconds()}else f.call(this)};var h=u.utcOffset;u.utcOffset=function(m,w){var y=this.$utils().u;if(y(m))return this.$u?0:y(this.$offset)?h.call(this):this.$offset;if(typeof m=="string"&&(m=function(E){E===void 0&&(E="");var M=E.match(r);if(!M)return null;var A=(""+M[0]).match(i)||["-",0,0],L=A[0],F=60*+A[1]+ +A[2];return F===0?0:L==="+"?F:-F}(m),m===null))return this;var _=Math.abs(m)<=16?60*m:m,C=this;if(w)return C.$offset=_,C.$u=m===0,C;if(m!==0){var S=this.$u?this.toDate().getTimezoneOffset():-1*this.utcOffset();(C=this.local().add(_+S,n)).$offset=_,C.$x.$localOffset=S}else C=this.utc();return C};var p=u.format;u.format=function(m){var w=m||(this.$u?"YYYY-MM-DDTHH:mm:ss[Z]":"");return p.call(this,w)},u.valueOf=function(){var m=this.$utils().u(this.$offset)?0:this.$offset+(this.$x.$localOffset||this.$d.getTimezoneOffset());return this.$d.valueOf()-6e4*m},u.isUTC=function(){return!!this.$u},u.toISOString=function(){return this.toDate().toISOString()},u.toString=function(){return this.toDate().toUTCString()};var g=u.toDate;u.toDate=function(m){return m==="s"&&this.$offset?s(this.format("YYYY-MM-DD HH:mm:ss:SSS")).toDate():g.call(this)};var v=u.diff;u.diff=function(m,w,y){if(m&&this.$u===m.$u)return v.call(this,m,w,y);var _=this.local(),C=s(m).local();return v.call(_,C,w,y)}}})})(qb);const _j=qb.exports,Ej=()=>Promise.resolve().then(()=>WL).then(({version:e})=>(console.log(`[@devtable/dashboard] version: ${e}`),e));Cn.default.extend(_j),Cn.default.extend(Cj),Cn.default.tz.setDefault("UTC"),pe.ContextModel=Vb,pe.Dashboard=xj,pe.DashboardFilterType=dm,pe.DashboardMode=cm,pe.DashboardModel=xs,pe.EViewComponentType=Ye,pe.FilterModel=jc,pe.FiltersModel=Ab,pe.FullScreenPanelContext=Vo,pe.LayoutStateContext=_n,pe.MainDashboardView=_b,pe.ModelContextProvider=Ds,pe.Panel=bs,pe.PanelContextProvider=ad,pe.QueriesModel=Ib,pe.QueryModel=Nb,pe.ReadOnlyDashboard=Sj,pe.ReadOnlyDashboardView=ws,pe.SQLSnippetModel=$b,pe.SQLSnippetsModel=Lb,pe.ViewModel=Gb,pe.ViewsModel=jb,pe.createDashboardModel=Kc,pe.createDashboardViewsModel=Kb,pe.getInitialFiltersPayload=Pb,pe.getVersion=Ej,pe.useFullScreenPanelContext=Rs,pe.useModelContext=Ze,pe.usePanelContext=jt,pe.useTopLevelServices=Hc,Object.defineProperties(pe,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
311
+ `),Lc={func_content:pb,horizontal_align:"left",font_size:"14px",font_weight:"normal"},y4=se.observer(({context:e})=>{const t=Ze(),{value:n=Lc}=et(e.instanceData,"config"),{variables:r}=e,{func_content:i,horizontal_align:o,font_size:a,font_weight:s}=n,u=x.useMemo(()=>new Function(`return ${i}`)()({data:e.data,variables:r,filters:t.filters.values,context:t.context.current}),[i,e.data,r,t.filters.values,t.context.current]);return l(d.Text,{align:o,weight:s,sx:{fontSize:a},children:u})}),b4=({value:e,onChange:t})=>{const n=r=>{!r||t(r)};return l(d.Box,{sx:{position:"relative"},children:l(Pn.default,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},w4=x.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:i,setFalse:o}]=nt.useBoolean(),[a,s]=x.useState(e),u=()=>{o(),t(a)},c=()=>{o(),s(e)},f=()=>{s(pb)};return x.useEffect(()=>{s(e)},[e]),b(De,{children:[l(d.Button,{variant:"filled",mt:24,onClick:i,sx:{flexGrow:0},children:"Edit Content"}),l(d.Modal,{size:800,title:"Text content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,children:r&&b(d.Stack,{children:[l(b4,{value:a,onChange:s}),b(d.Group,{position:"apart",children:[l(d.Button,{onClick:f,color:"red",leftIcon:l(te.Recycle,{size:20}),children:"Rest"}),b(d.Group,{position:"right",children:[l(d.Button,{onClick:c,variant:"subtle",children:"Cancel"}),l(d.Button,{onClick:u,children:"OK"})]})]})]})})]})}),x4=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}];function S4({context:e}){const{value:t,set:n}=et(e.instanceData,"config"),r=x.useMemo(()=>H.defaultsDeep({},t,Lc),[t]),i=x.useMemo(()=>{const{func_content:p,horizontal_align:g,font_size:v,font_weight:m}=r;return{func_content:p,horizontal_align:g,font_size:v,font_weight:m}},[r]);x.useEffect(()=>{!H.isEqual(r,i)&&(console.log("config malformed, resetting to defaults",r,i),n(i))},[r,i]);const{control:o,handleSubmit:a,watch:s,getValues:u,reset:c}=G.useForm({defaultValues:i});W.default.useEffect(()=>{c(i)},[i]),s(["func_content","horizontal_align","font_size","font_weight"]);const f=u(),h=W.default.useMemo(()=>!ye.default.isEqual(f,r),[f,r]);return l(d.Stack,{mt:"md",spacing:"xs",children:b("form",{onSubmit:a(n),children:[b(d.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[l(d.Text,{weight:500,children:"Configurations"}),l(d.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:l(te.DeviceFloppy,{size:20})})]}),b(d.Stack,{spacing:10,children:[l(G.Controller,{name:"func_content",control:o,render:({field:p})=>l(w4,{...p})}),l(d.Divider,{mt:10,mb:-10,variant:"dashed",label:"Style",labelPosition:"center"}),l(G.Controller,{name:"horizontal_align",control:o,render:({field:p})=>l(d.Select,{label:"Horizontal Alignment",data:x4,...p})}),l(G.Controller,{name:"font_size",control:o,render:({field:p})=>l(d.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1},...p})}),l(d.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:l(G.Controller,{name:"font_weight",control:o,render:({field:p})=>l(Sy,{label:"Font Weight",...p})})})]})]})})}class C4 extends en{constructor(){super(...arguments);ke(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const _4={displayName:"Text",migrator:new C4,name:"text",viewRender:y4,configRender:S4,createConfig(){return{version:1,config:H.cloneDeep(Lc)}}},E4=[{value:"#25262B",name:"Dark"},{value:"#868E96",name:"Gray"},{value:"#FA5252",name:"Red"},{value:"#E64980",name:"Pink"},{value:"#BE4BDB",name:"Grape"},{value:"#7950F2",name:"Violet"},{value:"#4C6EF5",name:"Indigo"},{value:"#228BE6",name:"Blue"},{value:"#15AABF",name:"Cyan"},{value:"#12B886",name:"Teal"},{value:"#40C057",name:"Green"},{value:"#82C91E",name:"Lime"},{value:"#FAB005",name:"Yellow"},{value:"#FD7E14",name:"Orange"}].map(e=>({name:e.name,value:e.value,type:"single",category:"basic"})),T4=[BL,GL,HL,KL,jL,qL],hb=()=>({id:"dashboard",version:oc,manifest:{viz:[Pc,YB,_4,BB,m3,gB,tV,az,cB,PF,m4,TB,LB,p5,wz],color:[...E4,...T4]}}),ko=new YL,$t={pluginManager:qn("pluginManager"),vizManager:qn("vizManager"),colorManager:qn("colorManager"),instanceScope:{panelModel:qn("panelModel"),vizInstance:qn("vizInstance"),interactionManager:qn("interactionManager"),migrator:qn("migrator"),operationManager:qn("operationManager"),triggerManager:qn("triggerManager")}},Vc=()=>{try{ko.install(hb())}catch{}const e=new VL(ko),t=new UL(ko);return{pluginManager:ko,vizManager:e,colorManager:t}},Gn=x.createContext(Vc());try{ko.install(hb())}catch{}function M4(e,t){const{value:n,set:r}=et(e.operation.operationData,"config"),[i,o]=x.useState(H.defaults({},n,t)),a=async()=>{await r(i)};return x.useEffect(()=>{o(H.defaults({},n,t))},[n]),{config:i,setConfig:o,commit:a}}function O4(e){const{config:t,setConfig:n,commit:r}=M4(e,{urlTemplate:"",openInNewTab:!0});async function i(){await r()}async function o(s){n({...t,openInNewTab:s}),await r()}const a=s=>n({...t,urlTemplate:s.currentTarget.value});return b(d.Stack,{children:[l(d.TextInput,{label:"Url",value:t.urlTemplate,onChange:a,onBlur:i}),l(d.Switch,{label:"Open in new Tab",checked:t.openInNewTab,onChange:s=>o(s.currentTarget.checked)})]})}async function D4(e,t){const{urlTemplate:n,openInNewTab:r}=await t.operationData.getItem("config");window.dispatchEvent(new CustomEvent("open-link",{detail:{urlTemplate:n,openInNewTab:r,payload:e}}))}class R4 extends en{constructor(){super(...arguments);ke(this,"VERSION",1)}configVersions(){this.version(1,n=>n)}}const k4={displayName:"Open Link",id:"builtin:op:open-link",configRender:O4,run:D4,migrator:new R4,createDefaultConfig:()=>({version:1,config:{urlTemplate:"",openInNewTab:!0}})};function A4(e){const{value:t,set:n}=et(e.operationData,"config"),r=i=>void n({template:i});return[(t==null?void 0:t.template)||"",r]}function P4(e){const[t,n]=A4(e.operation);return l(d.TextInput,{defaultValue:t,onBlur:r=>n(r.currentTarget.value),label:"console.log"})}async function N4(e,t){const n=await t.operationData.getItem("config"),r=H.template(n.template||"");console.log("run with payload",e),console.log(r(e))}const I4={displayName:"console.log (debug)",id:"builtin:op:debug",configRender:P4,run:N4},$4=se.observer(e=>{const t=Ze(),{value:n,set:r}=et(e.operation.operationData,"config");console.log({value:n,viewID:n==null?void 0:n.viewID});const i=(n==null?void 0:n.viewID)||"",o=a=>void r({viewID:a});return l(d.Select,{defaultValue:i,value:i,onChange:o,label:"View",data:t.views.options})});async function L4(e,t){const r=(await t.operationData.getItem("config")).viewID;window.dispatchEvent(new CustomEvent("open-view",{detail:{viewID:r}}))}const V4={displayName:"Open View",id:"builtin:op:open_view",configRender:$4,run:L4},z4={dictionary:{}},F4=se.observer(e=>{const t=Ze(),{value:n=z4,set:r}=et(e.operation.operationData,"config"),{dictionary:i={}}=n,o=(u,c)=>{r({dictionary:{...i,[u]:c}})},a=()=>{o(t.filters.firstFilterValueKey,"")},s=u=>{const c={...i};delete c[u],r({dictionary:c})};return b(d.Stack,{spacing:10,children:[l(d.Text,{children:"Mapping Rules"}),Object.entries(i).map(([u,c])=>b(d.Flex,{justify:"space-between",gap:10,children:[l(d.TextInput,{label:"Payload key",value:c,onChange:f=>{o(u,f.currentTarget.value)},sx:{flexGrow:1}}),l(mt,{data:[t.filters.values],value:u,onChange:f=>{o(f,c)},label:"Filter key",sx:{flexGrow:1}}),l(d.ActionIcon,{onClick:()=>s(u),sx:{marginTop:"26px",flexGrow:0},children:l(te.Trash,{size:14,color:"red"})})]},u)),l(d.Button,{size:"xs",onClick:a,sx:{alignSelf:"center",width:"300px"},children:"Add one mapping rule"})]})});async function B4(e,t){const r=(await t.operationData.getItem("config")).dictionary;window.dispatchEvent(new CustomEvent("set-filter-values",{detail:{dictionary:r,payload:e}}))}const G4={displayName:"Set Filter Values",id:"builtin:op:set_filter_values",configRender:F4,run:B4},j4={filter_keys:[]},K4=se.observer(e=>{const t=Ze(),{value:n=j4,set:r}=et(e.operation.operationData,"config"),{filter_keys:i=[]}=n,o=s=>{r({filter_keys:[...s]})},a=x.useMemo(()=>t.filters.current.map(s=>({label:s.label,value:s.key})),[t.filters.values]);return l(d.Stack,{spacing:10,children:l(d.MultiSelect,{label:"Select Filters to Clear",data:a,value:i,onChange:o})})});async function H4(e,t){const r=(await t.operationData.getItem("config")).filter_keys;window.dispatchEvent(new CustomEvent("clear-filter-values",{detail:{filter_keys:r,payload:e}}))}const ms=[I4,k4,V4,G4,{displayName:"Clear Filter Values",id:"builtin:op:clear_filter_values",configRender:K4,run:H4}];class q4{constructor(t,n=ms){ke(this,"attachments");this.operations=n;const r=async i=>{const{id:o,schemaRef:a}=await i.getItem(null);return{id:o,schemaRef:a,operationData:new Mi(i,"data")}};this.attachments=new ic(t,"__OPERATIONS",r)}async runOperation(t,n){const r=await this.attachments.getInstance(t);if(!r){console.warn(`Operation '${t}' is not defined`);return}const i=this.tryGetSchema(r.schemaRef);if(!i){console.warn(`Operation schema '${r.schemaRef}' is not defined`);return}await i.run(n,r)}tryGetSchema(t){return this.operations.find(n=>n.id===t)}async needMigration(){const n=(await this.attachments.list()).map(async r=>{const i={configData:r.operationData},o=this.tryGetSchema(r.schemaRef),a=o==null?void 0:o.migrator;return a&&await a.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),a=o==null?void 0:o.migrator;a&&await a.needMigration(i)&&await a.migrate(i)});await Promise.all(n)}async createOrGetOperation(t,n){var a,s;if(!this.getOperationSchemaList().some(u=>u.id===n.id))throw new Error(`Operation schema '${n.id}' is not defined`);const i=await this.attachments.getInstance(t);return!i||i.schemaRef!==n.id?await this.attachments.create(t,{id:t,schemaRef:n.id,data:(s=(a=n.createDefaultConfig)==null?void 0:a.call(n))!=null?s:{}}):i}getOperationList(){return this.attachments.list()}getOperationSchemaList(){return this.operations}removeOperation(t){return this.attachments.remove(t)}async retrieveTrigger(t){return await this.attachments.getInstance(t)}}class zc{constructor(t,n,r){ke(this,"operationManager");ke(this,"triggerManager");ke(this,"attachments");this.operationManager=new q4(t,r),this.triggerManager=new oV(t,n);const i=async o=>{const{id:a,triggerRef:s,operationRef:u}=await o.getItem(null);return{id:a,triggerRef:s,operationRef:u}};this.attachments=new ic(t,"__INTERACTIONS",i)}async addInteraction(t,n){const r=t.id,i=n.id,o=`[${r}]:[${i}]`;await this.attachments.create(o,{id:o,triggerRef:r,operationRef:i})}getInteractionList(){return this.attachments.list()}async removeInteraction(t){const n=await this.attachments.getInstance(t);if(!n)return;const{triggerRef:r,operationRef:i}=n;await this.getTriggerRefCount(r)<=1&&await this.triggerManager.removeTrigger(r),await this.getOperationRefCount(i)<=1&&await this.operationManager.removeOperation(i),await this.attachments.remove(t)}async getOperationRefCount(t){return(await this.getInteractionList()).filter(r=>r.operationRef===t).length}async getTriggerRefCount(t){return(await this.getInteractionList()).filter(r=>r.triggerRef===t).length}async runInteraction(t,n){const i=(await this.getInteractionList()).filter(o=>o.triggerRef===t);await Promise.all(i.map(async o=>{try{return await this.operationManager.runOperation(o.operationRef,n)}catch(a){console.warn(`Failed to run operation '${o.operationRef}'`,a)}}))}}function W4(e,t){const[n,r]=x.useState([]);return nt.useAsyncEffect(async()=>{const i=await e.getInteractionList();r(i)},[t]),n}const U4=se.observer(({item:e,manager:t,instance:n,sampleData:r,variables:i,onRemove:o})=>{const{triggerRef:a,operationRef:s}=e,u=AL(t.triggerManager,n);if(nt.useAsyncEffect(async()=>{await u.configTrigger(a,r)},[u,a,r]),u.isReady()){const c=[...u.triggerSchema.payload,...i];return b(d.Group,{children:[l($L,{model:u}),l(DL,{instance:n,operationId:s,variables:c,operationManager:t.operationManager}),l(d.ActionIcon,{"aria-label":"delete-interaction",variant:"filled",color:"red",onClick:()=>o(e),children:l(te.Trash,{size:16})})]})}return null}),Y4=e=>{const[t,n]=x.useState(0),{interactionManager:r,instance:i,sampleData:o,variables:a}=e,s=W4(r,t),u=async()=>{const p=await r.triggerManager.createOrGetTrigger(wt.randomId(),r.triggerManager.getTriggerSchemaList()[0]),g=await r.operationManager.createOrGetOperation(wt.randomId(),r.operationManager.getOperationSchemaList()[0]);await r.addInteraction(p,g),n(v=>v+1)};async function c(p){await r.removeInteraction(p.id),n(g=>g+1)}const{data:f=0,loading:h}=nt.useRequest(async()=>{try{return(await r.triggerManager.getTriggerSchemaList()).length}catch{return 0}});return b(d.Stack,{children:[l(d.LoadingOverlay,{visible:h}),f===0&&l(d.Alert,{icon:l(te.AlertCircle,{size:16}),title:"Unavailable",color:"gray",children:"This visualization does not have available interactions to choose from"}),s.map(p=>l(U4,{onRemove:c,instance:i,sampleData:o,variables:a,item:p,manager:e.interactionManager},p.id)),l(d.Button,{style:{width:"fit-content"},onClick:()=>u(),disabled:f===0,children:"Add interaction"})]})},X4=()=>{const{panel:e,data:t}=jt(),n=e.viz,{vizManager:r}=x.useContext(Gn),i=e.json,o=nt.useCreation(()=>r.getOrCreateInstance(i),[r,n.type]),a=nt.useCreation(()=>new zc(o,r.resolveComponent(n.type),ms),[o,n.type]);return x.useEffect(()=>o.instanceData.watchItem(null,H.throttle(s=>{e.viz.setConf(s)},100,{leading:!1,trailing:!0})),[o]),{instance:o,vizManager:r,interactionManager:a,sampleData:t,variables:[]}},Q4=()=>{const e=X4();return l(Y4,{...e})},Z4=se.observer(()=>{const{panel:e}=jt();return l(Jy,{label:"Description",value:e.description,onChange:e.setDescription,styles:{root:{flexGrow:1}}})}),J4=se.observer(()=>{const{panel:e}=jt(),{style:t}=e;return l(De,{children:l(d.Switch,{label:"Border",checked:t.border.enabled,onChange:n=>t.border.setEnabled(n.currentTarget.checked)})})}),eG=se.observer(()=>{const{panel:{title:e,style:{border:t}}}=jt();return l(Wr,{children:b(d.Stack,{mx:"auto",mt:"xl",p:"5px",spacing:5,sx:{width:"600px",height:"450px",background:"transparent",borderRadius:"5px",border:"1px solid #e9ecef",borderWidth:t.enabled?"1px":"0px"},children:[b(d.Group,{position:"apart",noWrap:!0,sx:{flexGrow:0,flexShrink:0},children:[l(d.Group,{children:l(ny,{})}),l(d.Group,{grow:!0,position:"center",children:l(d.Text,{lineClamp:1,weight:"bold",children:e})}),l(d.Group,{position:"right",spacing:0,sx:{height:"28px"}})]}),l(d.Group,{sx:{background:"#eee",flexGrow:1}})]})})}),tG=se.observer(()=>{const{panel:e}=jt(),{title:t,setTitle:n}=e,[r,i]=wt.useInputState(t),o=t!==r,a=W.default.useCallback(()=>{!o||n(r)},[o,r]);return l(d.TextInput,{value:r,onChange:i,label:b(d.Group,{children:[l(d.Text,{children:"Panel Title"}),l(d.ActionIcon,{variant:"subtle",color:"blue",disabled:!o,onClick:a,children:l(te.DeviceFloppy,{size:20})})]}),styles:{label:{display:"block",paddingBottom:"4px"}}})});function nG(){return b(d.Group,{grow:!0,noWrap:!0,align:"stretch",sx:{height:"100%"},children:[b(d.Stack,{sx:{width:"40%",flexShrink:0,flexGrow:0,height:"100%"},children:[l(d.Divider,{label:"Style",labelPosition:"center",variant:"dashed"}),l(J4,{}),l(d.Divider,{label:"Info",labelPosition:"center",variant:"dashed"}),l(tG,{}),l(Z4,{})]}),l(d.Box,{sx:{height:"100%",flexGrow:1,maxWidth:"60%"},children:l(eG,{})})]})}const rG=se.observer(function(){const t=Ze(),{panel:{queryID:n,setQueryID:r}}=jt(),i=W.default.useMemo(()=>t.queries.current.map(o=>({value:o.id,label:o.name})),[t.queries.current]);return b(d.Stack,{children:[b(d.Group,{position:"left",sx:{maxWidth:"600px",alignItems:"baseline"},children:[l(d.Text,{children:"Select a Query"}),l(d.Select,{data:i,value:n,onChange:r,allowDeselect:!1,clearable:!1,sx:{flexGrow:"1 !important"}})]}),l(Vm,{id:n})]})});var gb=(e=>(e.migrated="migrated",e.nothingToMigrate="nothingToMigrate",e.checkFailed="checkFailed",e.migrationFailed="migrationFailed",e))(gb||{}),ys=(e=>(e.notStarted="notStarted",e.inProgress="inProgress",e.done="done",e))(ys||{});class iG{constructor(t){ke(this,"vizInstance");ke(this,"operationManager");ke(this,"triggerManager");ke(this,"vizManager");ke(this,"runningMigration");ke(this,"panelModel");ke(this,"status","notStarted");this.panelModel=t.getRequired($t.instanceScope.panelModel),this.vizInstance=t.getRequired($t.instanceScope.vizInstance),this.operationManager=t.getRequired($t.instanceScope.operationManager),this.triggerManager=t.getRequired($t.instanceScope.triggerManager),this.vizManager=t.getRequired($t.vizManager)}async createMigrationTask(){const t=[];try{await this.instanceNeedMigration()&&t.push(()=>this.runInstanceMigration()),await this.interactionNeedMigration()&&t.push(()=>this.runInteractionMigration())}catch(n){return console.warn("check migration failed",n),"checkFailed"}if(t.length===0)return"nothingToMigrate";try{return await Promise.all(t.map(n=>n())),"migrated"}catch(n){return console.warn("migration failed",n),"migrationFailed"}}async runMigration(){return this.runningMigration||(this.status="inProgress",this.runningMigration=this.createMigrationTask().then(t=>(this.status="done",t))),this.runningMigration}async runInteractionMigration(){await this.operationManager.runMigration(),await this.triggerManager.runMigration()}async runInstanceMigration(){const t=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData,panelModel:this.panelModel};await t.migrator.migrate(n)}async instanceNeedMigration(){const t=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData};return t.migrator.needMigration(n)}async interactionNeedMigration(){return await this.operationManager.needMigration()||await this.triggerManager.needMigration()}}function vb(e){const{panel:t}=jt();return x.useCallback(n=>{const r=n.getRequired($t.vizManager),i=r.resolveComponent(e.viz.type);return n.createScoped().provideFactory($t.instanceScope.vizInstance,()=>r.getOrCreateInstance(e)).provideFactory($t.instanceScope.interactionManager,o=>{const a=o.getRequired($t.instanceScope.vizInstance);return new zc(a,i,ms)}).provideFactory($t.instanceScope.operationManager,o=>o.getRequired($t.instanceScope.interactionManager).operationManager).provideFactory($t.instanceScope.triggerManager,o=>o.getRequired($t.instanceScope.interactionManager).triggerManager).provideValue($t.instanceScope.panelModel,t).provideFactory($t.instanceScope.migrator,o=>new iG(o))},[e.viz.type,e.viz.conf])}function mb(e){const[t,n]=x.useState(!1),r=nd().getRequired($t.instanceScope.migrator);return nt.useAsyncEffect(async()=>{const i=r.status===ys.notStarted;n(r.status===ys.done),r.status===ys.notStarted&&r.runMigration().then(o=>{o===gb.migrated&&i&&(e==null||e())}).finally(()=>{n(!0)})},[r]),t}function yb(e,t){const n=nd().getRequired($t.instanceScope.vizInstance);return x.useEffect(()=>(n.instanceData.setItem(null,t.viz.conf),n.instanceData.watchItem(null,r=>{e(r)})),[e,t.viz.type]),n}function oG({setVizConf:e,...t}){const{panel:n}=t,r=yb(e,n),i=mb(()=>{Po.showNotification({title:`${n.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})});return nt.useAsyncEffect(async()=>{await r.instanceData.setItem(null,n.viz.conf)},[r,n.viz.type]),i?l(FL,{...t}):l(d.Text,{children:"Checking update..."})}function aG(e){const{panel:t,setVizConf:n}=e;return yb(n,t),mb(()=>{Po.showNotification({title:`${t.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?l(zL,{...e}):l(d.Text,{children:"Checking update"})}const Qj="";function sG(e,t){const{vizManager:n}=x.useContext(Gn),{panel:{viz:r,title:i,id:o,description:a,queryID:s,variables:u}}=jt(),c={title:i,id:o,description:a,queryID:s,viz:r,layout:t},f=vb(c);try{return n.resolveComponent(r.type),l(Lo,{configure:f,children:l(aG,{setVizConf:r.setConf,panel:c,data:e,variables:u,vizManager:n})})}catch(h){return console.info(H.get(h,"message")),null}}const lG=["richText","button"],bb=se.observer(function({height:t,viz:n,data:r,loading:i,error:o,query:a}){const{ref:s,width:u,height:c}=wt.useElementSize(),f=sG(r,{w:u,h:c});if(lG.includes(n.type))return l("div",{className:"viz-root",style:{height:t},ref:s,children:l(Wr,{children:f})});if(i)return l("div",{className:"viz-root",style:{height:t},ref:s,children:l(d.LoadingOverlay,{visible:i,exitTransitionDuration:0})});const p=!!o,g=!p&&!!(a!=null&&a.stateMessage),v=!p&&!g;return b("div",{className:"viz-root",style:{height:t},ref:s,children:[p&&l(d.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:o}),g&&l(d.Text,{color:"gray",align:"center",children:a.stateMessage}),v&&l(Wr,{children:f})]})}),uG=se.observer(()=>{const{data:e,loading:t,panel:{viz:n}}=jt();return l(bb,{viz:n,data:e,loading:t,height:"100%"})}),Fc=[];function cG(){const{vizManager:e}=x.useContext(Gn);return x.useMemo(()=>e.availableVizList.map(t=>({value:t.name,label:t.displayName})).concat(Fc),[e])}function dG(e,t){try{return e.resolveComponent(t).createConfig()}catch{return null}}function fG(){const{data:e,panel:{variables:t,viz:n,title:r,queryID:i,description:o,setDescription:a,setTitle:s,setQueryID:u,id:c}}=jt(),{vizManager:f}=x.useContext(Gn),h={title:r,description:o,viz:n,queryID:i,id:c},p={setDescription:a,setQueryID:u,setTitle:s},g=vb(h);try{return f.resolveComponent(h.viz.type),l(Lo,{configure:g,children:l(oG,{variables:t,setVizConf:n.setConf,panel:h,panelInfoEditor:p,vizManager:f,data:e})})}catch(v){return console.info(H.get(v,"message")),null}}const pG=se.observer(()=>{const{data:e,panel:{viz:t}}=jt(),[n,r]=wt.useInputState(t.type),i=t.type!==n,{vizManager:o}=x.useContext(Gn),a=W.default.useCallback(()=>{if(!i)return;const g=dG(o,n);t.setType(n),t.setConf(g||{})},[t,i,n]),s=g=>{try{t.setConf(JSON.parse(g))}catch(v){console.error(v)}},u=W.default.useMemo(()=>{var g;return(g=Fc.find(v=>v.value===n))==null?void 0:g.Panel},[n,Fc]),c=fG(),f=u?x.createElement(u,{data:e,conf:t.conf,setConf:t.setConf}):null,h=c||f,p=cG();return b(De,{children:[l(d.Select,{label:"Visualization",value:n,onChange:r,data:p,rightSection:l(d.ActionIcon,{disabled:!i,onClick:a,children:l(te.DeviceFloppy,{size:20})})}),h,!h&&l(d.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(t.conf,null,2),onChange:s})]})});function hG(){return b(d.Group,{grow:!0,noWrap:!0,align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[l(d.Stack,{sx:{width:"40%",flexShrink:0,flexGrow:0,overflow:"auto",height:"100%"},children:l(pG,{})}),l(d.Box,{sx:{height:"100%",flexGrow:1,maxWidth:"60%"},children:l(uG,{})})]})}const gG=D.types.model("VariableModel",{name:D.types.string,size:D.types.string,weight:D.types.string,color:D.types.union(D.types.model({type:D.types.literal("static"),staticColor:D.types.string}),D.types.model({type:D.types.literal("continuous"),valueRange:D.types.array(D.types.number),colorRange:D.types.array(D.types.string)}),D.types.model({type:D.types.literal("piecewise")})),formatter:D.types.model({output:D.types.enumeration("Output",["number","percent"]),mantissa:D.types.number,average:D.types.optional(D.types.boolean,!1),trimMantissa:D.types.optional(D.types.boolean,!1)}),data_field:D.types.string,aggregation:D.types.union(D.types.model({type:D.types.enumeration(["none","sum","mean","median","min","max"]),config:D.types.frozen()}),D.types.model({type:D.types.literal("quantile"),config:D.types.model({p:D.types.number})}))}).views(e=>({get json(){return D.getSnapshot(e)}}));class vG{constructor(t){ke(this,"origin");ke(this,"copy");this.origin=t,this.copy=D.clone(t),zt.makeAutoObservable(this,{},{autoBind:!0,deep:!1})}get changed(){return!H.isEqual(D.getSnapshot(this.origin),D.getSnapshot(this.copy))}commit(){D.applySnapshot(this.origin,D.getSnapshot(this.copy))}update(t){D.applySnapshot(this.copy,t)}}const mG=e=>new vG(e),Bc={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 yG{constructor(t){ke(this,"panel");ke(this,"selected");this.panel=t,zt.makeAutoObservable(this,{},{deep:!1,autoBind:!0})}get variables(){return this.panel.variables}addNew(){const t=this.panel.variables.filter(n=>n.name.startsWith(Bc.name)).length;this.panel.addVariable(H.cloneDeep({...Bc,name:`${Bc.name}${t||""}`})),this.selected=H.last(this.panel.variables)}select(t){this.selected=t}remove(t){this.selected===t&&(this.selected=void 0);const n=this.panel.variables.indexOf(t);if(this.panel.removeVariable(t),!this.selected&&!H.isEmpty(this.panel.variables)){const r=Math.min(this.panel.variables.length-1,n);this.selected=this.panel.variables[r]}}}function bG(){const{panel:e}=jt();return nt.useCreation(()=>new yG(e),[e])}const wG=W.default.forwardRef(function({value:t,onChange:n,data:r,withStyle:i=!0},o){const a=(s,u)=>{const c=ye.default.cloneDeep(t);ye.default.set(c,s,u),n(c)};return b(d.Box,{px:"sm",py:"md",ref:o,children:[b(d.Group,{grow:!0,noWrap:!0,children:[l(d.TextInput,{label:"Name",required:!0,value:t.name,onChange:s=>a("name",s.currentTarget.value)}),l(mt,{label:"Data Field",required:!0,data:r,value:t.data_field,onChange:s=>a("data_field",s)})]}),l(xy,{label:"Aggregation",value:t.aggregation,onChange:s=>a("aggregation",s)}),l(d.Divider,{my:"xs",label:"Format",labelPosition:"center"}),l(jr,{value:t.formatter,onChange:s=>a("formatter",s)}),i&&l(Cy,{value:t,onChange:n})]})}),wb=d.createStyles(e=>({root:{height:"100%",overflow:"hidden",".var-list-container":{"& > *":{height:"100%"},width:250,height:"100%"},".var-list-actions":{height:"fit-content",flexShrink:0,width:"100%"},".var-list":{flex:"1 1 auto",overflow:"auto",minHeight:0,"& > *":{flex:"0 0 auto"}}},config:{height:"100%",overflow:"auto",paddingRight:10}})),xG=e=>{const{uiModel:t}=e;return l(d.Stack,{className:"var-list",children:t.variables.map(n=>l(d.Button,{variant:t.selected===n?"filled":"subtle",color:"gray",onClick:()=>t.select(n),children:n.name},n.name))})},SG=se.observer(xG),CG=({variable:e,data:t})=>l(d.Group,{style:{minHeight:0,height:"calc(100% - 68px)"},children:l(d.Paper,{withBorder:!0,p:"md",children:Ky(e,t)})}),_G=se.observer(CG),EG=e=>{const t=nt.useCreation(()=>mG(e.variable),[e.variable]),{classes:n}=wb(),{data:r}=jt();return b(d.Group,{style:{height:"100%"},align:"start",children:[b(d.Stack,{"data-testid":"variable-editor",align:"stretch",className:n.config,children:[b(d.Group,{position:"right",children:[l(d.ActionIcon,{variant:"filled",disabled:!t.changed,color:"primary",onClick:t.commit,children:l(mm,{size:18})}),l(d.ActionIcon,{color:"red",onClick:()=>e.uiModel.remove(e.variable),children:l(ym,{size:18})})]}),l(wG,{value:D.getSnapshot(t.copy),onChange:t.update,data:r})]}),l(_G,{variable:D.getSnapshot(t.copy),data:r})]})},TG=se.observer(EG),MG=()=>{const e=bG(),{classes:t}=wb();return b(d.Group,{className:t.root,noWrap:!0,align:"start",children:[l(d.Paper,{withBorder:!0,p:"md",className:"var-list-container",children:b(d.Stack,{justify:"space-between",children:[l(d.Box,{className:"var-list-actions",children:l(d.Button,{variant:"light",size:"sm",onClick:e.addNew,fullWidth:!0,children:"Add Variable"})}),l(SG,{uiModel:e})]})}),e.selected?l(De,{children:l(TG,{uiModel:e,variable:e.selected})}):l("span",{children:"Select or create a new variable on right side"})]})},OG=se.observer(MG),DG=se.observer(function({opened:t,close:n}){const{freezeLayout:r}=W.default.useContext(_n),[i,o]=x.useState("Visualization"),{panel:a,loading:s}=jt(),{id:u,title:c}=a;return W.default.useEffect(()=>{r(t)},[t]),l(d.Modal,{size:"96vw",overflow:"inside",opened:t,onClose:n,title:`Editing Panel - ${c.trim()?c:u}`,trapFocus:!0,onDragStart:f=>{f.stopPropagation()},children:l(d.AppShell,{sx:{height:"90vh",maxHeight:"calc(100vh - 185px)",".mantine-AppShell-body":{height:"100%"},main:{height:"100%",minHeight:"unset",maxHeight:"100%",width:"100%",padding:"16px"}},padding:"md",children:b(d.Tabs,{value:i,onTabChange:o,className:"panel-settings-tabs",children:[b(d.Tabs.List,{children:[l(d.Tabs.Tab,{value:"Data",children:"Data"}),l(d.Tabs.Tab,{value:"Panel",children:"Panel"}),l(d.Tabs.Tab,{value:"Variables",children:"Variables"}),l(d.Tabs.Tab,{value:"Visualization",children:"Visualization"}),l(d.Tabs.Tab,{value:"Interactions",children:"Interactions"})]}),b(d.Tabs.Panel,{value:"Data",pt:"sm",children:[l(d.LoadingOverlay,{visible:s,exitTransitionDuration:0}),l(rG,{})]}),l(d.Tabs.Panel,{value:"Panel",pt:"sm",children:i==="Panel"&&l(nG,{})}),l(d.Tabs.Panel,{value:"Variables",pt:"sm",children:i==="Variables"&&l(OG,{})}),l(d.Tabs.Panel,{value:"Visualization",pt:"sm",children:i==="Visualization"&&l(hG,{})}),l(d.Tabs.Panel,{value:"Interactions",pt:"sm",children:l(Wr,{children:l(Q4,{})})})]})})})}),RG=se.observer(({view:e})=>{const t=Ze(),n=Ss.useModals(),[r,i]=W.default.useState(!1),o=()=>i(!0),a=()=>i(!1),{panel:s}=jt(),{id:u,query:c}=s,{inEditMode:f}=W.default.useContext(_n),h=()=>c==null?void 0:c.fetchData(),{viewPanelInFullScreen:p,inFullScreen:g}=W.default.useContext(Os),v=()=>{e.panels.duplicateByID(u)},m=()=>n.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>e.panels.removeByID(u)}),w=W.default.useCallback(()=>{p(u)},[u,p]),y=!g&&e.type!==Ye.Modal;return b(De,{children:[l(d.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:b(d.Menu,{withinPortal:!0,children:[l(d.Menu.Target,{children:l(d.Box,{className:"panel-dropdown-target",sx:{width:"100%",height:"25px"}})}),b(d.Menu.Dropdown,{children:[l(d.Menu.Item,{onClick:h,icon:l(te.Refresh,{size:14}),children:"Refresh"}),l(d.Menu.Item,{onClick:()=>{var _;return t.queries.downloadDataByQueryID((_=c==null?void 0:c.id)!=null?_:"")},icon:l(te.Download,{size:14}),children:"Download Data"}),y&&l(d.Menu.Item,{onClick:w,icon:l(te.ArrowsMaximize,{size:14}),children:"Full Screen"}),f&&b(De,{children:[l(d.Divider,{label:"Edit",labelPosition:"center"}),l(d.Menu.Item,{onClick:o,icon:l(te.Settings,{size:14}),children:"Settings"}),l(d.Menu.Item,{onClick:v,icon:l(te.Copy,{size:14}),children:"Duplicate"}),l(d.Menu.Item,{color:"red",onClick:m,icon:l(te.Trash,{size:14}),children:"Delete"})]})]})]})}),f&&l(DG,{opened:r,close:a})]})}),Zj="",kG=se.observer(function(){const{panel:t}=jt(),{title:n}=t;return n?l(d.Group,{grow:!0,position:"center",px:20,className:"panel-title-wrapper",sx:{flexGrow:1},children:l(d.Text,{align:"center",lineClamp:1,weight:"bold",children:n})}):null});function AG(e){return!["richText","button"].includes(e)}const PG={border:"1px solid #e9ecef"},xb={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function NG(e,t,n){return e.style.border.enabled?PG:n||t?xb:{border:"1px dashed transparent"}}const bs=se.observer(function({panel:t,view:n}){const r=Ze(),{inEditMode:i}=x.useContext(_n),{data:o,state:a,error:s}=r.getDataStuffByID(t.queryID),u=r.queries.findByID(t.queryID),c=AG(t.viz.type),f=c&&a==="loading",h=t.title?"calc(100% - 25px - 5px)":"100%",p=NG(t,c,i),g=c||i;return l(ad,{value:{panel:t,data:o,loading:f},children:b(d.Box,{className:"panel-root",p:5,pt:0,sx:{...p},children:[l(d.Box,{sx:{position:"absolute",left:0,top:0,height:28,zIndex:310},children:l(ny,{})}),g&&l(RG,{view:n}),l(kG,{}),l(bb,{viz:t.viz,data:o,loading:f,error:s,height:h,query:u})]})})}),Sb=se.observer(function({view:t,panel:n,exitFullScreen:r}){return b(d.Stack,{px:"10px",pb:"5px",sx:{height:"100%",flexGrow:1,justifyContent:"flex-start"},children:[l(d.Group,{sx:{flexGrow:0},children:l(d.Button,{variant:"default",size:"sm",onClick:r,leftIcon:l(te.ArrowLeft,{size:20}),children:"Exit fullscreen"})}),l(d.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:l(bs,{view:t,panel:n})})]})});function Cb(e,t,n){const r=e.id==="Main",[i,o]=W.default.useState(()=>r&&e.panels.findByID(t)?t:null),a=W.default.useCallback(f=>{o(f),r&&n(f)},[r,n]),s=W.default.useCallback(()=>{o(null),r&&n("")},[r,n]),u=i?e.panels.findByID(i):null;return{viewPanelInFullScreen:a,exitFullScreen:s,inFullScreen:!!u,fullScreenPanel:u}}const Jj="",IG=W.default.forwardRef(({handleAxis:e},t)=>l(d.ActionIcon,{ref:t,className:"react-grid-customDragHandle",sx:{userSelect:"none",cursor:"grab",position:"absolute",top:0,right:0,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",children:l(te.ArrowsMove,{size:16})})),$G=W.default.forwardRef(({handleAxis:e,...t},n)=>l(d.ActionIcon,{ref:n,className:"react-grid-customResizeHandle",sx:{userSelect:"none",cursor:"nwse-resize",position:"absolute",bottom:-5,right:-5,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",...t,children:l(te.ChevronDownRight,{size:16})})),LG=_s.WidthProvider(Zc.default),VG=se.observer(function({view:t,className:n="layout",rowHeight:r=10,isDraggable:i,isResizable:o}){const a=W.default.useCallback(s=>{s.forEach(({i:u,...c})=>{const f=t.panels.findByID(u);!f||f.layout.set(c)})},[t]);return l(LG,{onLayoutChange:a,className:`dashboard-layout ${n}`,rowHeight:r,layout:t.panels.layouts,isDraggable:i,isResizable:o,draggableHandle:".react-grid-customDragHandle",resizeHandle:l($G,{}),children:t.panels.list.map((s,u)=>b("div",{"data-grid":{...s.layout},style:{position:"relative"},children:[i&&l(IG,{}),l(bs,{view:t,panel:s})]},s.id))})}),zG=_s.WidthProvider(Zc.default),FG=se.observer(function({view:t,className:n="layout",rowHeight:r=10}){return l(zG,{className:`dashboard-layout ${n}`,rowHeight:r,isDraggable:!1,isResizable:!1,layout:t.panels.layouts,children:t.panels.list.map(i=>l("div",{"data-grid":i.layout,children:l(bs,{view:t,panel:i})},i.id))})}),BG=se.observer(({children:e})=>l(d.Box,{children:e})),GG=se.observer(({children:e,view:t})=>{const n=t.config;return l(d.Modal,{size:n.width,overflow:"inside",opened:!0,onClose:ye.default.noop,withCloseButton:!1,title:n.custom_modal_title.value,trapFocus:!0,onDragStart:r=>{r.stopPropagation()},styles:{root:{position:"relative",height:"calc(100% - 44px)"},overlay:{position:"absolute !important"},modal:{border:"1px solid #efefef"},body:{maxHeight:"calc(100vh - 325px)"}},withinPortal:!1,transitionDuration:0,children:e})}),jG=({variant:e,orientation:t})=>{const n={tab:{},panel:{padding:"16px"}};return e==="pills"&&t==="horizontal"&&(n.tab.paddingTop="6px",n.tab.paddingBottom="6px"),t==="vertical"&&(n.tab["&.add-a-tab"]={paddingTop:"1px",paddingBottom:"1px"},n.tab["&.add-a-tab .mantine-Tabs-tabLabel"]={marginLeft:"auto",marginRight:"auto"}),n},KG=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},HG=se.observer(({children:e,view:t})=>{const n=Ze(),r=x.useMemo(()=>n.views.options.filter(o=>o.type===Ye.Division),[t.id,n.views.options]),i=t.config;return b(d.Box,{className:"preview-view-tabs",children:[b(d.Tabs,{variant:i.variant,orientation:i.orientation,defaultValue:i.tabs.length>0?i.tabs[0].id:"0",styles:jG(i),children:[b(d.Tabs.List,{grow:i.grow,children:[i.tabs.map(o=>{var a;return l(d.Tabs.Tab,{value:o.id,sx:KG(o),children:(a=o.name)!=null?a:o.id},o.id)}),l(d.Tabs.Tab,{onClick:i.addTab,value:"add",className:"add-a-tab",children:l(d.ActionIcon,{children:l(te.Plus,{size:18,color:"#228be6"})})})]}),i.tabs.map(o=>{const a=n.views.findByID(o.view_id);return b(d.Tabs.Panel,{value:o.id,sx:{position:"relative"},children:[b(d.Box,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:1},children:[l(d.Overlay,{opacity:.8,color:"#FFF",blur:10,zIndex:-1}),b(d.Stack,{mx:"auto",mt:100,sx:{width:"300px"},children:[l(d.TextInput,{label:"Tab Name",value:o.name,onChange:s=>o.setName(s.currentTarget.value)}),l(d.Select,{label:"View",value:o.view_id,onChange:o.setViewID,data:r}),l(d.ColorInput,{label:"Color",value:o.color,onChange:o.setColor,disabled:i.variant!=="default"}),a&&b(d.Button,{mt:20,variant:"gradient",leftIcon:l(S$,{size:18}),gradient:{from:"cyan",to:"indigo"},onClick:()=>n.views.setIDOfVIE(a.id),children:["Swith to View: ",a.name]})]})]}),a&&l(ws,{view:a})]},o.id)})]}),e]})}),qG=se.observer(({view:e,children:t})=>{switch(e.type){case Ye.Modal:return l(GG,{view:e,children:t});case Ye.Tabs:return l(HG,{view:e,children:t});case Ye.Division:default:return l(BG,{children:t})}}),_b=se.observer(function({view:t,saveDashboardChanges:n}){const{fullScreenPanelID:r,setFullScreenPanelID:i}=Rs(),{viewPanelInFullScreen:o,exitFullScreen:a,inFullScreen:s,fullScreenPanel:u}=Cb(t,r,i);return l(Os.Provider,{value:{viewPanelInFullScreen:o,inFullScreen:s},children:b(d.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:[s&&l(Sb,{view:t,panel:u,exitFullScreen:a}),!s&&l(qm,{saveChanges:n,inUseMode:!1}),l(qG,{view:t,children:b(d.Box,{sx:{position:"relative"},children:[!s&&l(d.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:l(Uh,{view:t})}),!s&&l(VG,{view:t,isDraggable:!0,isResizable:!0})]})})]})})}),WG=se.observer(({children:e})=>l(d.Box,{children:e})),UG=se.observer(({children:e,view:t})=>{const n=Ze(),r=t.config,i=n.views.visibleViewIDs.includes(t.id),o=()=>n.views.rmVisibleViewID(t.id);return l(d.Modal,{size:r.width,centered:!0,overflow:"inside",opened:i,onClose:o,withCloseButton:!1,title:r.custom_modal_title.value,trapFocus:!0,onDragStart:a=>{a.stopPropagation()},styles:{modal:{border:"1px solid #efefef"},body:{maxHeight:r.height,overflow:"auto"}},transitionDuration:0,children:e})}),YG=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},XG=se.observer(({children:e,view:t})=>{const n=Ze(),r=t.config;return b(d.Box,{className:"render-view-tabs",children:[b(d.Tabs,{variant:r.variant,orientation:r.orientation,defaultValue:r.tabs.length>0?r.tabs[0].id:"0",styles:{panel:{padding:"16px 0px"}},keepMounted:!1,children:[l(d.Tabs.List,{grow:r.grow,children:r.tabs.map(i=>{var o;return l(d.Tabs.Tab,{value:i.id,sx:YG(i),disabled:!i.view_id,children:(o=i.name)!=null?o:i.id},i.id)})}),r.tabs.map(i=>{const o=n.views.findByID(i.view_id);return o?l(d.Tabs.Panel,{value:i.id,children:l(ws,{view:o})},i.id):null})]}),e]})}),QG=se.observer(({view:e,children:t})=>{switch(e.type){case Ye.Modal:return l(UG,{view:e,children:t});case Ye.Tabs:return l(XG,{view:e,children:t});case Ye.Division:default:return l(WG,{children:t})}}),ws=se.observer(function({view:t}){const{fullScreenPanelID:n,setFullScreenPanelID:r}=Rs(),{viewPanelInFullScreen:i,exitFullScreen:o,inFullScreen:a,fullScreenPanel:s}=Cb(t,n,r);return l(Os.Provider,{value:{viewPanelInFullScreen:i,inFullScreen:a},children:b(d.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:[a&&l(Sb,{view:t,panel:s,exitFullScreen:o}),!a&&l(qm,{saveChanges:ye.default.noop,inUseMode:!0}),l(QG,{view:t,children:b(d.Box,{sx:{position:"relative"},children:[!a&&l(d.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:l(Uh,{view:t})}),!a&&l(FG,{view:t})]})})]})})}),Eb=D.types.model("FilterConfigModel_Checkbox",{_name:D.types.literal("checkbox"),default_value:D.types.boolean}).actions(e=>({setDefaultValue(t){e.default_value=t}})),ZG=()=>Eb.create({_name:"checkbox",default_value:!1}),JG=D.types.model("FilterConfigModel_DateRange",{_name:D.types.literal("date-range"),required:D.types.boolean,inputFormat:D.types.enumeration("DateRangeInputFormat",["YYYY","YYYYMM","YYYYMMDD","YYYY-MM","YYYY-MM-DD"]),default_value:D.types.optional(D.types.array(D.types.union(D.types.string,D.types.null)),[null,null]),clearable:D.types.boolean,max_days:D.types.optional(D.types.number,0),allowSingleDateInRange:D.types.optional(D.types.boolean,!1)}).views(e=>({truthy(t){return Array.isArray(t)&&t.length===2&&t.every(n=>!!n)}})).views(e=>({getMaxDate(t){const{max_days:n}=e;if(!(!n||!t))return Cn.default(t).startOf("day").add(n,"days").toDate()},getMinDate(t){const{max_days:n}=e;if(!(!n||!t))return Cn.default(t).startOf("day").subtract(n,"days").toDate()}})).actions(e=>({setFilterValue(t){try{const n=D.getParent(e);D.getRoot(e).filters.setValueByKey(n.key,t)}catch(n){console.error(n)}}})).actions(e=>({setRequired(t){e.required=t},setClearable(t){e.clearable=t},setInputFormat(t){e.inputFormat=t},setDefaultValue(t){e.default_value.length=0,e.default_value.push(...t),e.setFilterValue(t)},setMaxDays(t){e.max_days=t,t>0&&(e.clearable=!0)},setAllowSingleDateInRange(t){e.allowSingleDateInRange=t}})),Tb=D.types.snapshotProcessor(JG,{preProcessor({default_value:e,...t}){return{...t,default_value:e.map(n=>n===null?null:Cn.default.tz(n,"UTC").toISOString())}},postProcessor({default_value:e,...t}){return{...t,default_value:e.map(n=>{try{return n?Cn.default.tz(n,"UTC").format(t.inputFormat):null}catch{return console.log(`[date-range] failed parsing ${n}`),null}})}}}),ej=()=>Tb.create({_name:"date-range",required:!1,inputFormat:"YYYY-MM-DD",clearable:!1,default_value:[null,null]}),tj=D.types.model({label:D.types.string,value:D.types.string}).actions(e=>({setLabel(t){e.label=t},setValue(t){e.value=t}})),Gc=D.types.model("FilterConfigModel_BaseSelect",{static_options:D.types.optional(D.types.array(tj),[]),options_query_id:D.types.optional(D.types.string,""),default_selection_count:D.types.optional(D.types.number,0)}).views(e=>({get usingQuery(){return!!e.options_query_id}})).views(e=>({get options(){if(!e.usingQuery)return e.static_options;const{data:t,state:n,error:r}=D.getRoot(e).getDataStuffByID(e.options_query_id);return n==="idle"?t:[]}})).actions(e=>({addStaticOption(t){e.static_options.push(t)},removeStaticOption(t){e.static_options.splice(t,1)},setDefaultSelectionCount(t){e.default_selection_count=t},setOptionsQueryID(t){e.options_query_id=t!=null?t:""}})),Mb=D.types.compose("FilterConfigModel_MultiSelect",D.types.model({_name:D.types.literal("multi-select"),default_value:D.types.optional(D.types.array(D.types.string),[]),min_width:D.types.optional(D.types.string,"")}),Gc).actions(e=>({setDefaultValue(t){e.default_value=D.cast(t)},setMinWidth(t){e.min_width=t}})),nj=()=>Mb.create({_name:"multi-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),Ob=D.types.compose("FilterConfigModel_TreeSelect",D.types.model({_name:D.types.literal("tree-select"),default_value:D.types.optional(D.types.array(D.types.string),[]),min_width:D.types.optional(D.types.string,"")}),Gc).actions(e=>({setDefaultValue(t){e.default_value=D.cast(t)},setMinWidth(t){e.min_width=t}})),rj=()=>Ob.create({_name:"tree-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),Db=D.types.compose("FilterConfigModel_Select",D.types.model({_name:D.types.literal("select"),default_value:D.types.string,required:D.types.boolean,width:D.types.optional(D.types.string,"")}),Gc).views(e=>({truthy(t){return!!t}})).actions(e=>({setRequired(t){e.required=t},setDefaultValue(t){e.default_value=t},setWidth(t){e.width=t}})),ij=()=>Db.create({_name:"select",required:!1,default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),jc=D.types.model("FilterModel",{id:D.types.identifier,key:D.types.string,label:D.types.string,order:D.types.number,visibleInViewsIDs:D.types.array(D.types.string),auto_submit:D.types.optional(D.types.boolean,!1),type:D.types.enumeration("DashboardFilterType",[Ht.Select,Ht.MultiSelect,Ht.TreeSelect,Ht.TextInput,Ht.Checkbox,Ht.DateRange]),config:D.types.union(Db,Mb,Ob,Bm,Eb,Tb)}).views(e=>({get plainDefaultValue(){const t=e.config.default_value;return Array.isArray(t)?[...t]:t},get usingDefaultValue(){return e.type!==Ht.TreeSelect},get auto_submit_supported(){return[Ht.Select,Ht.Checkbox,Ht.DateRange].includes(e.type)}})).views(e=>({get should_auto_submit(){return e.auto_submit_supported&&e.auto_submit},requiredAndPass(t){return ye.default.get(e.config,"required",!1)?ye.default.get(e.config,"truthy",()=>!0)(t):!1}})).actions(e=>({setKey(t){e.key=t},setLabel(t){e.label=t},setOrder(t){e.order=t},setType(t){switch(t){case Ht.Select:e.config=ij();break;case Ht.MultiSelect:e.config=nj();break;case Ht.TreeSelect:e.config=rj();break;case Ht.TextInput:e.config=Gm();break;case Ht.Checkbox:e.config=ZG();break;case Ht.DateRange:e.config=ej();break}e.type=t},setVisibleInViewsIDs(t){e.visibleInViewsIDs.length=0,e.visibleInViewsIDs.push(...t)},setAutoSubmit(t){e.auto_submit=e.auto_submit_supported&&t}}));function Rb(e,t){if(e===void 0)return e;if(t._name==="date-range")try{const[...n]=e;return n.map(r=>{if(r===null)return r;const i=Cn.default.tz(r,"UTC").format(t.inputFormat);return i!=null?i:r})}catch(n){return console.error(n),e}return e}function kb(e){return e.reduce((t,n)=>(t[n.key]=Rb(n.config.default_value,n.config),t),{})}function oj(e,t,n){D.addDisposer(e,D.addMiddleware(e,(r,i)=>{i(r,()=>{D.getType(r.context)===t&&r.type==="action"&&n(r.name,r.context)})}))}const Ab=D.types.model("FiltersModel",{current:D.types.optional(D.types.array(jc),[]),values:D.types.optional(D.types.frozen(),{}),previewValues:D.types.optional(D.types.frozen(),{})}).views(e=>({get firstID(){if(e.current.length!==0)return e.current[0].id},get inOrder(){return ye.default.sortBy(e.current,"order")},get empty(){return e.current.length===0},visibleInView(t){return ye.default.sortBy(e.current.filter(n=>n.visibleInViewsIDs.includes(t)),"order")},get firstFilterValueKey(){var t;return(t=Object.keys(e.values)[0])!=null?t:""},get keyLabelMap(){return e.current.reduce((t,n)=>(t[n.key]=n.label,t),{})}})).actions(e=>({replace(t){e.current=D.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},setValues(t){e.values=t},setValueByKey(t,n){e.values={...e.values,[t]:n}},getValueByKey(t){return e.values[t]},refreshValues(){console.log("refreshing values"),e.values=kb(e.current)},updatePreviewValues(t){e.previewValues=t}})).actions(e=>{function t(){oj(e.current,jc,(n,r)=>{if(n==="setType"){const i=Rb(r.config.default_value,r.config);e.setValueByKey(r.key,i),e.updatePreviewValues({...e.previewValues,[r.key]:i})}})}return{afterCreate(){t()}}});function Pb(e){return{current:e,values:kb(e)}}const aj=D.types.model("QueryModel",{id:D.types.string,name:D.types.string,type:D.types.enumeration("DataSourceType",[Sn.Postgresql,Sn.MySQL,Sn.HTTP]),key:D.types.string,sql:D.types.string,pre_process:D.types.optional(D.types.string,""),post_process:D.types.optional(D.types.string,""),run_by:D.types.optional(D.types.array(D.types.string),[])}).views(e=>({get valid(){return e.id&&e.type&&e.key&&e.name?e.type===Sn.HTTP?!!e.pre_process:!!e.sql:!1},get json(){const{id:t,name:n,type:r,key:i,sql:o,run_by:a,pre_process:s,post_process:u}=e;return{id:t,name:n,type:r,key:i,sql:o,run_by:a,pre_process:s,post_process:u}},get conditionOptions(){const{context:t,mock_context:n,filterValues:r}=D.getRoot(e).payloadForSQL,i=Object.keys({...n,...t}).map(s=>`context.${s}`),o=Object.keys(r).map(s=>`filters.${s}`);return[...i,...o].map(s=>({label:s.split(".")[1],value:s,group:ye.default.capitalize(s.split(".")[0])}))},get unmetRunByConditions(){const{run_by:t}=e;if(t.length===0)return[];const{context:n,mock_context:r,filterValues:i}=D.getRoot(e).payloadForSQL,o={context:{...r,...n},filters:i};return t.filter(a=>{const s=ye.default.get(o,a);return Array.isArray(s)?s.length===0:typeof s=="number"?Number.isNaN(s):!s})}})).views(e=>({get runByConditionsMet(){return e.unmetRunByConditions.length===0},get conditionNames(){if(e.unmetRunByConditions.length===0)return{context:[],filters:[]};const{keyLabelMap:t}=D.getRoot(e).filters,n=e.unmetRunByConditions.filter(i=>i.startsWith("context.")).map(i=>i.split("context.")[0]),r=e.unmetRunByConditions.filter(i=>i.startsWith("filters.")).map(i=>ye.default.get({filters:t},i)).filter(i=>!!i);return{context:n,filters:r}}})).actions(e=>({setName(t){e.name=t},setKey(t){e.key=t},setType(t){e.type=t},setSQL(t){e.sql=t},setRunBy(t){e.run_by.length=0,e.run_by.push(...t)},setPreProcess(t){e.pre_process=t},setPostProcess(t){e.post_process=t}})),Nb=D.types.compose("QueryModel",aj,D.types.model({state:D.types.optional(D.types.enumeration(["idle","loading","error"]),"idle"),data:D.types.optional(D.types.array(D.types.frozen()),[]),error:D.types.frozen()})).views(e=>({get formattedSQL(){const{context:t,mock_context:n,sqlSnippets:r,filterValues:i}=D.getRoot(e).payloadForSQL;return wm(e.sql,t,n,r,i)},get typedAsSQL(){return[Sn.Postgresql,Sn.MySQL].includes(e.type)},get typedAsHTTP(){return[Sn.HTTP].includes(e.type)},get datasource(){const{key:t,type:n}=e;return D.getRoot(e).datasources.find({type:n,key:t})}})).views(e=>({get stateMessage(){if(e.state!=="idle")return"";if(!e.runByConditionsMet){const{context:t,filters:n}=e.conditionNames;if(t.length===0&&n.length===0)return"Waiting";const r=[];return t.length>0&&r.push(`context: ${t.join(", ")}`),n.length>0&&r.push(`filter${n.length>1?"s":""}: ${n.join(", ")}`),r.length===2&&r.splice(1,0,"and"),r.unshift("Waiting for"),r.join(" ")}return e.data.length>0?"":"Empty Data"}})).volatile(()=>({controller:new AbortController})).actions(e=>({runSQL:D.flow(function*(){var t;if(!!e.valid&&((t=e.controller)==null||t.abort(),!!e.runByConditionsMet)){e.controller=new AbortController,e.state="loading";try{const{context:n,mock_context:r,sqlSnippets:i,filterValues:o}=D.getRoot(e).payloadForSQL;e.data=yield*D.toGenerator(X$({context:n,mock_context:r,sqlSnippets:i,title:e.name,query:e.json,filterValues:o},e.controller.signal)),e.state="idle",e.error=null}catch(n){if(!Io.default.isCancel(n)){e.data.length=0;const r=H.get(n,"message","unkown error");e.error=H.get(n,"response.data.detail.message",r),e.state="error"}}}}),runHTTP:D.flow(function*(){var t;if(console.log("runHTTP, ",e.datasource),!(!e.valid||!e.datasource)&&((t=e.controller)==null||t.abort(),!!e.runByConditionsMet)){e.controller=new AbortController,e.state="loading";try{const{context:n,mock_context:r,filterValues:i}=D.getRoot(e).payloadForSQL;e.data=yield*D.toGenerator(Q$({context:n,mock_context:r,query:e.json,filterValues:i,datasource:e.datasource},e.controller.signal)),e.state="idle",e.error=null}catch(n){if(console.error(n),!Io.default.isCancel(n)){e.data.length=0;const r=H.get(n,"message","unkown error");e.error=H.get(n,"response.data.detail.message",r),e.state="error"}}}})})).actions(e=>({fetchData:e.typedAsHTTP?e.runHTTP:e.runSQL,beforeDestroy(){var t;(t=e.controller)==null||t.abort()}})).actions(e=>({afterCreate(){D.addDisposer(e,zt.reaction(()=>{var t;return e.typedAsHTTP?`${e.id}--${e.key}--${e.pre_process}--${e.post_process}--${(t=e.datasource)==null?void 0:t.id}`:`${e.id}--${e.key}--${e.formattedSQL}`},e.fetchData,{fireImmediately:!0,delay:0}))}})),Ib=D.types.model("QueriesModel",{current:D.types.optional(D.types.array(Nb),[])}).views(e=>({get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(n=>n.id===t)},get options(){return e.current.map(t=>({value:t.id,label:t.name}))}})).views(e=>({get json(){return e.current.filter(t=>t.id).map(t=>t.json)}})).actions(e=>({replace(t){e.current=D.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},replaceByIndex(t,n){e.current.splice(t,1,n)},downloadAllData(){const t=e.current.map(({name:n,data:r})=>({id:n,data:r.toJSON()}));L$(t)},downloadDataByQueryID(t){const n=e.findByID(t);if(!n){console.log("[downloadDataByQueryID] query not found");return}const{name:r,data:i}=n,o=bm(i);I$(r,o)},refetchDataByQueryID(t){const n=e.findByID(t);if(!n){console.error(new Error(`[downloadDataByQueryID] query by ID[${t}] not found`));return}return n.fetchData()},removeQuery(t){const n=e.current.find(r=>r.id===t);n&&(D.detach(n),e.current.remove(n))}})),$b=D.types.model("SQLSnippetModel",{key:D.types.string,value:D.types.string}).views(e=>({get json(){const{key:t,value:n}=e;return{key:t,value:n}},isADuplicatedKey(t){return!t||t===e.key?!1:!!D.getParent(e,2).findByKey(t)}})).actions(e=>({setKey(t){e.key=t},setValue(t){e.value=t}})),Lb=D.types.model("SQLSnippetsModel",{current:D.types.optional(D.types.array($b),[])}).views(e=>({get json(){return e.current.map(t=>t.json)},get record(){return e.current.reduce((t,n)=>(t[n.key]=n.value,t),{})},get firstKey(){if(e.current.length!==0)return e.current[0].key},findByKey(t){return e.current.find(n=>n.key===t)}})).actions(e=>({replace(t){e.current=D.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},replaceByIndex(t,n){e.current.splice(t,1,n)}})),Vb=D.types.model("ContextModel",{current:D.types.optional(D.types.frozen(),{})}).views(e=>({get keys(){return Object.keys(e.current)},get entries(){return Object.entries(e.current)}})).actions(e=>({replace(t){e.current=t},get(t){return e.current[t]},set(t,n){e.current[t]=n}})),sj=D.types.model("DataSourcesModel",{list:D.types.optional(D.types.frozen(),[])}).views(e=>({find({type:t,key:n}){return e.list.find(r=>r.key===n&&r.type===t)},get options(){return e.list.map(t=>({value:t.key,label:t.key}))}})).actions(e=>({replace(t){e.list=t}})),lj=D.types.model("MockContextModel",{current:D.types.optional(D.types.frozen(),{})}).views(e=>({get keys(){return Object.keys(e.current)},get entries(){return Object.entries(e.current)}})).actions(e=>({replace(t){e.current=t},get(t){return e.current[t]},set(t,n){e.current[t]=n}})),zb=D.types.model("ViewModel_Division",{_name:D.types.literal(Ye.Division)}).views(e=>({get json(){const{_name:t}=e;return{_name:t}}})).actions(e=>({})),uj=()=>zb.create({_name:Ye.Division}),cj=D.types.model("CustomModalTitleModel",{enabled:D.types.optional(D.types.boolean,!1),func_content:D.types.optional(D.types.string,"")}).views(e=>({get json(){const{enabled:t,func_content:n}=e;return{enabled:t,func_content:n}},get value(){const{enabled:t,func_content:n}=e,r=D.getParent(e,2),i=D.getRoot(e);if(!t)return r.name;try{const o={filters:i.filters.values,context:i.context.current};return new Function(`return ${n}`)()(o)}catch(o){return console.error(o),r.name}}})).actions(e=>({setEnabled(t){e.enabled=t},setFuncContent(t){e.func_content=t},replace({enabled:t,func_content:n}){e.enabled=t,e.func_content=n}})),Fb=D.types.model("ViewModel_Modal",{_name:D.types.literal(Ye.Modal),width:D.types.string,height:D.types.string,custom_modal_title:D.types.optional(cj,nc)}).views(e=>({get json(){const{_name:t,width:n,height:r,custom_modal_title:i}=e;return{_name:t,width:n,height:r,custom_modal_title:i.json}}})).actions(e=>({setWidth(t){e.width=t},setHeight(t){e.height=t}})),dj=()=>Fb.create({_name:Ye.Modal,width:"90vw",height:"90vh"}),fj=D.types.model("PanelLayoutModel",{x:D.types.number,y:D.types.number,w:D.types.number,h:D.types.number,moved:D.types.optional(D.types.boolean,!1),static:D.types.optional(D.types.boolean,!1)}).views(e=>({get json(){const{x:t,y:n,w:r,h:i,moved:o}=e;return{x:t,y:n,w:r,h:i,moved:o,static:e.static}}})).actions(e=>({set(t){const{x:n,y:r,w:i,h:o,moved:a}=t;e.x=n,e.y=r,e.w=i,e.h=o,e.moved=!!a,e.static=!!t.static}})),pj=D.types.model("PanelStyleBorderModel",{enabled:D.types.boolean}).views(e=>({get json(){const{enabled:t}=e;return{enabled:t}}})).actions(e=>({setEnabled(t){e.enabled=t}})),hj=D.types.model("PanelStyleModel",{border:pj}).views(e=>({get json(){const{border:t}=e;return{border:t.json}}})).actions(e=>({})),gj=D.types.model("PanelVizModel",{type:D.types.string,conf:D.types.frozen()}).views(e=>({get json(){return{type:e.type,conf:e.conf}}})).actions(e=>({setType(t){e.type=t},setConf(t){e.conf=t}})),vj=D.types.model({id:D.types.string,title:D.types.string,description:D.types.string,layout:fj,queryID:D.types.string,viz:gj,style:hj,variables:D.types.optional(D.types.array(gG),[])}).views(e=>({get query(){return D.getParentOfType(e,xs).queries.findByID(e.queryID)},get json(){const{id:t,title:n,description:r,queryID:i}=e;return{id:t,title:n,description:r,layout:e.layout.json,queryID:i,viz:e.viz.json,style:e.style.json,variables:e.variables.map(o=>o.json)}}})).actions(e=>({setID(t){e.id=t},setTitle(t){e.title=t},setDescription(t){e.description=t},setQueryID(t){if(D.getParentOfType(e,xs).queries.findByID(t))e.queryID=t;else throw new Error(`Query with id ${t} does not exist`)},addVariable(t){e.variables.push(t)},removeVariable(t){e.variables.remove(t)}})),mj=D.types.model("PanelsModel",{list:D.types.optional(D.types.array(vj),[])}).views(e=>({get json(){return e.list.map(t=>t.json)},get layouts(){return e.list.map(t=>({...t.layout.json,i:t.id}))},findByID(t){return e.list.find(n=>n.id===t)}})).actions(e=>({replace(t){e.list=D.castToSnapshot(t)},addANewPanel(){const t=wt.randomId();e.list.push({id:t,layout:{x:0,y:1/0,w:3,h:15},title:`Panel - ${t}`,description:"<p><br></p>",queryID:"",viz:{type:Pc.name,conf:Pc.createConfig()},style:{border:{enabled:!0}}})},append(t){e.list.push(t)},remove(t){e.list.splice(t,1)},removeByID(t){const n=e.list.findIndex(r=>r.id===t);n!==-1&&e.list.splice(n,1)},duplicateByID(t){const n=e.list.find(r=>r.id===t);if(!n){console.error(new Error(`[duplicate panel] Can't find a panel by id[${t}]`));return}e.list.push({...n.json,id:wt.randomId(),layout:{...n.layout,x:0,y:1/0,moved:!1}})},replaceByIndex(t,n){e.list.splice(t,1,n)}})),yj=D.types.model("ViewModel_Tabs_Tab",{id:D.types.identifier,name:D.types.string,view_id:D.types.string,color:D.types.optional(D.types.string,"")}).views(e=>({get json(){const{id:t,name:n,view_id:r,color:i}=e;return{id:t,name:n,view_id:r,color:i}}})).actions(e=>({setName(t){e.name=t},setViewID(t){e.view_id=t},setColor(t){e.color=t}})),Bb=D.types.model("ViewModel_Tabs",{_name:D.types.literal(Ye.Modal),tabs:D.types.optional(D.types.array(yj),[]),variant:D.types.optional(D.types.enumeration("variant",["default","outline","pills"]),"default"),orientation:D.types.optional(D.types.enumeration("orientation",["horizontal","vertical"]),"horizontal"),grow:D.types.optional(D.types.boolean,!1)}).views(e=>({get json(){const{_name:t,variant:n,orientation:r,tabs:i,grow:o}=e;return{_name:t,variant:n,orientation:r,grow:o,tabs:i.map(a=>a.json)}}})).actions(e=>({setVariant(t){e.variant=t},setOrientation(t){e.orientation=t},setGrow(t){e.grow=t},setTabs(t){e.tabs.length=0,e.tabs=D.cast(t)},addTab(){const t=wt.randomId(),n={id:t,name:t,view_id:""};e.tabs.push(n)},removeTab(t){e.tabs.splice(t,1)}})),bj=()=>Bb.create({_name:Ye.Modal,tabs:[]}),Gb=D.types.model({id:D.types.identifier,name:D.types.string,type:D.types.enumeration("EViewComponentType",[Ye.Division,Ye.Modal,Ye.Tabs]),config:D.types.union(zb,Fb,Bb),panels:mj}).views(e=>({get json(){const{id:t,name:n,type:r,config:i}=e;return{id:t,name:n,type:r,config:i.json,panels:e.panels.json}}})).actions(e=>({setName(t){e.name=t},setType(t){if(e.type!==t){switch(t){case Ye.Division:e.config=uj();break;case Ye.Modal:e.config=dj();break;case Ye.Tabs:e.config=bj();break}e.type=t}}})).actions(e=>({})),jb=D.types.model("ViewsModel",{current:D.types.optional(D.types.array(Gb),[]),visibleViewIDs:D.types.array(D.types.string),idOfVIE:D.types.string}).views(e=>({get json(){return e.current.map(t=>t.json)},findByID(t){return e.current.find(n=>n.id===t)},get isVIETheFirstView(){return e.current.length===0||!e.idOfVIE?!1:e.current[0].id===e.idOfVIE},get firstVisibleView(){const[t]=e.visibleViewIDs;return e.current.find(({id:n})=>n===t)},get visibleViews(){const t=new Set(e.visibleViewIDs);return e.current.filter(({id:n})=>t.has(n))},get VIE(){return e.current.find(({id:t})=>t===e.idOfVIE)},get options(){return e.current.map(t=>({label:t.name,value:t.id,type:t.type}))}})).actions(e=>({replace(t){e.current.replace(t)},addANewView(t,n,r){e.current.push({id:t,name:t,type:n,config:r,panels:{list:[]}})},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByID(t){const n=e.current.findIndex(r=>r.id===t);n!==-1&&e.current.splice(n,1)},replaceByIndex(t,n){e.current.splice(t,1,n)},setIDOfVIE(t){e.idOfVIE=t,e.visibleViewIDs.length=0,e.visibleViewIDs.push(t)},addAPanelToVIE(){var t;(t=e.VIE)==null||t.panels.addANewPanel()},appendToVisibles(t){new Set(e.visibleViewIDs.map(r=>r)).has(t)||e.visibleViewIDs.push(t)}})).actions(e=>({addARandomNewView(){const t=wt.randomId();e.addANewView(t,Ye.Division,{_name:Ye.Division}),e.setIDOfVIE(t)},removeVIE(){e.current.length!==1&&(e.removeByID(e.idOfVIE),e.setIDOfVIE(e.current[0].id))},rmVisibleViewID(t){const n=e.visibleViewIDs.findIndex(r=>r===t);n!==-1&&e.visibleViewIDs.splice(n,1)}}));function Kb(e){const t=e.length>0?[e[0].id]:[],n=e.length>0?e[0].id:"";return{current:e.map(i=>{const{_name:o=i.type}=i.config;return{...i,config:{...i.config,_name:o},panels:{list:i.panels}}}),visibleViewIDs:t,idOfVIE:n}}const wj=D.types.model({id:D.types.identifier,name:D.types.string,version:D.types.string,datasources:sj,filters:Ab,queries:Ib,sqlSnippets:Lb,views:jb,context:Vb,mock_context:lj,origin:D.types.maybe(D.types.frozen())}).views(e=>({get filtersChanged(){const t="filters.current";return!H.isEqual(D.getSnapshot(H.get(e,t)),H.get(e.origin,t))},get queriesChanged(){const t="queries.current",n=D.getSnapshot(H.get(e,t)).map(r=>H.pick(r,["id","name","key","type","sql","run_by","pre_process","post_process"]));return!H.isEqual(n,H.get(e.origin,t))},get sqlSnippetsChanged(){const t="sqlSnippets.current";return!H.isEqual(D.getSnapshot(H.get(e,t)),H.get(e.origin,t))},get viewsChanged(){const t="views.current";return!H.isEqual(D.getSnapshot(H.get(e,t)),H.get(e.origin,t))},get mockContextChanged(){const t="mock_context.current";return!H.isEqual(H.get(e,t),H.get(e.origin,t))}})).views(e=>({get payloadForSQL(){return{context:e.context.current,mock_context:e.mock_context.current,sqlSnippets:e.sqlSnippets.current,filterValues:e.filters.values}},get changed(){return e.filtersChanged||e.queriesChanged||e.sqlSnippetsChanged||e.viewsChanged||e.mockContextChanged},get data(){return e.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(t){const n=e.queries.findByID(t);return n?{data:n.data.toJSON(),dataProxy:n.data,len:n.data.length,state:n.state,error:n.error}:{data:[],dataProxy:null,len:0,state:"idle",error:void 0}},getDataStateByID(t){var n,r;return(r=(n=e.queries.findByID(t))==null?void 0:n.state)!=null?r:[]},getDataErrorByID(t){var n,r;return(r=(n=e.queries.findByID(t))==null?void 0:n.error)!=null?r:[]}})).views(e=>({findDependingPanels(t){return e.views.current.flatMap(n=>n.panels.list.filter(r=>r.queryID===t).map(r=>r.title))}})).actions(e=>({reset(){D.applySnapshot(e.filters.current,e.origin.filters.current),D.applySnapshot(e.queries.current,e.origin.queries.current),D.applySnapshot(e.sqlSnippets.current,e.origin.sqlSnippets.current),D.applySnapshot(e.views.current,e.origin.views.current),e.mock_context.current=e.origin.mock_context.current},resetFilters(){D.applySnapshot(e.filters.current,e.origin.filters.current)}})),xs=D.types.snapshotProcessor(wj,{preProcessor(e){return{...e,origin:e}},postProcessor(e){delete e.origin;const t=D.castToSnapshot(e.queries.current.map(n=>H.pick(n,["id","key","type","sql"])));return H.defaults({},{queries:{current:t}},e)}});function Kc({id:e,name:t,version:n,filters:r,views:i,definition:{queries:o,sqlSnippets:a,mock_context:s={}}},u,c){return xs.create({id:e,name:t,version:n,datasources:{list:u},filters:Pb(r),queries:{current:o},sqlSnippets:{current:a},context:{current:c},mock_context:{current:s},views:Kb(i)})}function Hc(e){return W.default.useCallback(t=>t.provideValue($t.pluginManager,e.pluginManager).provideValue($t.vizManager,e.vizManager).provideValue($t.colorManager,e.colorManager),[])}const eK="",xj=se.observer(function({context:t,dashboard:n,update:r,className:i="dashboard",config:o,fullScreenPanelID:a,setFullScreenPanelID:s}){xm(o);const{data:u=[]}=nt.useRequest(Fu),[c,f]=W.default.useState(!1),h=W.default.useMemo(()=>Kc(n,u,t),[n]);Jc(h,!0),W.default.useEffect(()=>{h.context.replace(t)},[t]),W.default.useEffect(()=>{h.datasources.replace(u)},[u]);const p=async()=>{const m=[...h.queries.json],w=[...h.sqlSnippets.json],y=[...h.views.json],_={...h.mock_context.current},C={...n,filters:[...h.filters.current],views:y,definition:{sqlSnippets:w,queries:m,mock_context:_}};await r(C)},g=nt.useCreation(Vc,[]),v=Hc(g);return l(Ss.ModalsProvider,{children:l(Ds,{value:h,children:l(Vo.Provider,{value:{fullScreenPanelID:a,setFullScreenPanelID:s},children:l(_n.Provider,{value:{layoutFrozen:c,freezeLayout:f,inEditMode:!0,inUseMode:!1},children:l(d.Box,{className:`${i} dashboard-root`,sx:{position:"relative"},children:l(Gn.Provider,{value:g,children:l(Lo,{configure:v,children:h.views.visibleViews.map(m=>l(_b,{view:m,saveDashboardChanges:p},m.id))})})})})})})})}),Sj=se.observer(({context:e,dashboard:t,className:n="dashboard",config:r,fullScreenPanelID:i,setFullScreenPanelID:o})=>{xm(r);const{data:a=[]}=nt.useRequest(Fu),s=W.default.useMemo(()=>Kc(t,a,e),[t]);Jc(s,!1),W.default.useEffect(()=>{s.context.replace(e)},[e]),W.default.useEffect(()=>{s.datasources.replace(a)},[a]);const u=nt.useCreation(Vc,[]),c=Hc(u);return l(Ss.ModalsProvider,{children:l(Ds,{value:s,children:l(Vo.Provider,{value:{fullScreenPanelID:i,setFullScreenPanelID:o},children:l(_n.Provider,{value:{layoutFrozen:!0,freezeLayout:ye.default.noop,inEditMode:!1,inUseMode:!0},children:l(d.Box,{className:`${n} dashboard-root`,children:l(Gn.Provider,{value:u,children:l(Lo,{configure:c,children:s.views.visibleViews.map(f=>l(ws,{view:f},f.id))})})})})})})})});var Hb={exports:{}};(function(e,t){(function(n,r){e.exports=r()})(fn,function(){var n={year:0,month:1,day:2,hour:3,minute:4,second:5},r={};return function(i,o,a){var s,u=function(p,g,v){v===void 0&&(v={});var m=new Date(p),w=function(y,_){_===void 0&&(_={});var C=_.timeZoneName||"short",S=y+"|"+C,E=r[S];return E||(E=new Intl.DateTimeFormat("en-US",{hour12:!1,timeZone:y,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:C}),r[S]=E),E}(g,v);return w.formatToParts(m)},c=function(p,g){for(var v=u(p,g),m=[],w=0;w<v.length;w+=1){var y=v[w],_=y.type,C=y.value,S=n[_];S>=0&&(m[S]=parseInt(C,10))}var E=m[3],M=E===24?0:E,A=m[0]+"-"+m[1]+"-"+m[2]+" "+M+":"+m[4]+":"+m[5]+":000",L=+p;return(a.utc(A).valueOf()-(L-=L%1e3))/6e4},f=o.prototype;f.tz=function(p,g){p===void 0&&(p=s);var v=this.utcOffset(),m=this.toDate(),w=m.toLocaleString("en-US",{timeZone:p}),y=Math.round((m-new Date(w))/1e3/60),_=a(w).$set("millisecond",this.$ms).utcOffset(15*-Math.round(m.getTimezoneOffset()/15)-y,!0);if(g){var C=_.utcOffset();_=_.add(v-C,"minute")}return _.$x.$timezone=p,_},f.offsetName=function(p){var g=this.$x.$timezone||a.tz.guess(),v=u(this.valueOf(),g,{timeZoneName:p}).find(function(m){return m.type.toLowerCase()==="timezonename"});return v&&v.value};var h=f.startOf;f.startOf=function(p,g){if(!this.$x||!this.$x.$timezone)return h.call(this,p,g);var v=a(this.format("YYYY-MM-DD HH:mm:ss:SSS"));return h.call(v,p,g).tz(this.$x.$timezone,!0)},a.tz=function(p,g,v){var m=v&&g,w=v||g||s,y=c(+a(),w);if(typeof p!="string")return a(p).tz(w);var _=function(M,A,L){var F=M-60*A*1e3,P=c(F,L);if(A===P)return[F,A];var O=c(F-=60*(P-A)*1e3,L);return P===O?[F,P]:[M-60*Math.min(P,O)*1e3,Math.max(P,O)]}(a.utc(p,m).valueOf(),y,w),C=_[0],S=_[1],E=a(C).utcOffset(S);return E.$x.$timezone=w,E},a.tz.guess=function(){return Intl.DateTimeFormat().resolvedOptions().timeZone},a.tz.setDefault=function(p){s=p}}})})(Hb);const Cj=Hb.exports;var qb={exports:{}};(function(e,t){(function(n,r){e.exports=r()})(fn,function(){var n="minute",r=/[+-]\d\d(?::?\d\d)?/g,i=/([+-]|\d\d)/g;return function(o,a,s){var u=a.prototype;s.utc=function(m){var w={date:m,utc:!0,args:arguments};return new a(w)},u.utc=function(m){var w=s(this.toDate(),{locale:this.$L,utc:!0});return m?w.add(this.utcOffset(),n):w},u.local=function(){return s(this.toDate(),{locale:this.$L,utc:!1})};var c=u.parse;u.parse=function(m){m.utc&&(this.$u=!0),this.$utils().u(m.$offset)||(this.$offset=m.$offset),c.call(this,m)};var f=u.init;u.init=function(){if(this.$u){var m=this.$d;this.$y=m.getUTCFullYear(),this.$M=m.getUTCMonth(),this.$D=m.getUTCDate(),this.$W=m.getUTCDay(),this.$H=m.getUTCHours(),this.$m=m.getUTCMinutes(),this.$s=m.getUTCSeconds(),this.$ms=m.getUTCMilliseconds()}else f.call(this)};var h=u.utcOffset;u.utcOffset=function(m,w){var y=this.$utils().u;if(y(m))return this.$u?0:y(this.$offset)?h.call(this):this.$offset;if(typeof m=="string"&&(m=function(E){E===void 0&&(E="");var M=E.match(r);if(!M)return null;var A=(""+M[0]).match(i)||["-",0,0],L=A[0],F=60*+A[1]+ +A[2];return F===0?0:L==="+"?F:-F}(m),m===null))return this;var _=Math.abs(m)<=16?60*m:m,C=this;if(w)return C.$offset=_,C.$u=m===0,C;if(m!==0){var S=this.$u?this.toDate().getTimezoneOffset():-1*this.utcOffset();(C=this.local().add(_+S,n)).$offset=_,C.$x.$localOffset=S}else C=this.utc();return C};var p=u.format;u.format=function(m){var w=m||(this.$u?"YYYY-MM-DDTHH:mm:ss[Z]":"");return p.call(this,w)},u.valueOf=function(){var m=this.$utils().u(this.$offset)?0:this.$offset+(this.$x.$localOffset||this.$d.getTimezoneOffset());return this.$d.valueOf()-6e4*m},u.isUTC=function(){return!!this.$u},u.toISOString=function(){return this.toDate().toISOString()},u.toString=function(){return this.toDate().toUTCString()};var g=u.toDate;u.toDate=function(m){return m==="s"&&this.$offset?s(this.format("YYYY-MM-DD HH:mm:ss:SSS")).toDate():g.call(this)};var v=u.diff;u.diff=function(m,w,y){if(m&&this.$u===m.$u)return v.call(this,m,w,y);var _=this.local(),C=s(m).local();return v.call(_,C,w,y)}}})})(qb);const _j=qb.exports,Ej=()=>Promise.resolve().then(()=>WL).then(({version:e})=>(console.log(`[@devtable/dashboard] version: ${e}`),e));Cn.default.extend(_j),Cn.default.extend(Cj),Cn.default.tz.setDefault("UTC"),pe.ContextModel=Vb,pe.Dashboard=xj,pe.DashboardFilterType=dm,pe.DashboardMode=cm,pe.DashboardModel=xs,pe.EViewComponentType=Ye,pe.FilterModel=jc,pe.FiltersModel=Ab,pe.FullScreenPanelContext=Vo,pe.LayoutStateContext=_n,pe.MainDashboardView=_b,pe.ModelContextProvider=Ds,pe.Panel=bs,pe.PanelContextProvider=ad,pe.QueriesModel=Ib,pe.QueryModel=Nb,pe.ReadOnlyDashboard=Sj,pe.ReadOnlyDashboardView=ws,pe.SQLSnippetModel=$b,pe.SQLSnippetsModel=Lb,pe.ViewModel=Gb,pe.ViewsModel=jb,pe.createDashboardModel=Kc,pe.createDashboardViewsModel=Kb,pe.getInitialFiltersPayload=Pb,pe.getVersion=Ej,pe.useFullScreenPanelContext=Rs,pe.useModelContext=Ze,pe.usePanelContext=jt,pe.useTopLevelServices=Hc,Object.defineProperties(pe,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devtable/dashboard",
3
- "version": "7.20.3",
3
+ "version": "7.21.0",
4
4
  "license": "Apache-2.0",
5
5
  "publishConfig": {
6
6
  "access": "public",