@devtable/dashboard 8.63.0 → 8.64.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.
@@ -17,14 +17,14 @@
17
17
  */var Di;function bo(){return Di||(Di=1,process.env.NODE_ENV!=="production"&&function(){var e=b,t=Symbol.for("react.element"),r=Symbol.for("react.portal"),i=Symbol.for("react.fragment"),s=Symbol.for("react.strict_mode"),o=Symbol.for("react.profiler"),u=Symbol.for("react.provider"),l=Symbol.for("react.context"),d=Symbol.for("react.forward_ref"),c=Symbol.for("react.suspense"),f=Symbol.for("react.suspense_list"),g=Symbol.for("react.memo"),h=Symbol.for("react.lazy"),m=Symbol.for("react.offscreen"),w=Symbol.iterator,C="@@iterator";function S(_){if(_===null||typeof _!="object")return null;var M=w&&_[w]||_[C];return typeof M=="function"?M:null}var I=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function $(_){{for(var M=arguments.length,E=new Array(M>1?M-1:0),R=1;R<M;R++)E[R-1]=arguments[R];G("error",_,E)}}function G(_,M,E){{var R=I.ReactDebugCurrentFrame,ie=R.getStackAddendum();ie!==""&&(M+="%s",E=E.concat([ie]));var ue=E.map(function(ee){return String(ee)});ue.unshift("Warning: "+M),Function.prototype.apply.call(console[_],console,ue)}}var q=!1,L=!1,z=!1,A=!1,N=!1,U;U=Symbol.for("react.module.reference");function Q(_){return!!(typeof _=="string"||typeof _=="function"||_===i||_===o||N||_===s||_===c||_===f||A||_===m||q||L||z||typeof _=="object"&&_!==null&&(_.$$typeof===h||_.$$typeof===g||_.$$typeof===u||_.$$typeof===l||_.$$typeof===d||_.$$typeof===U||_.getModuleId!==void 0))}function te(_,M,E){var R=_.displayName;if(R)return R;var ie=M.displayName||M.name||"";return ie!==""?E+"("+ie+")":E}function re(_){return _.displayName||"Context"}function oe(_){if(_==null)return null;if(typeof _.tag=="number"&&$("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof _=="function")return _.displayName||_.name||null;if(typeof _=="string")return _;switch(_){case i:return"Fragment";case r:return"Portal";case o:return"Profiler";case s:return"StrictMode";case c:return"Suspense";case f:return"SuspenseList"}if(typeof _=="object")switch(_.$$typeof){case l:var M=_;return re(M)+".Consumer";case u:var E=_;return re(E._context)+".Provider";case d:return te(_,_.render,"ForwardRef");case g:var R=_.displayName||null;return R!==null?R:oe(_.type)||"Memo";case h:{var ie=_,ue=ie._payload,ee=ie._init;try{return oe(ee(ue))}catch{return null}}}return null}var ne=Object.assign,pe=0,fe,Se,Fe,Ae,Re,it,dn;function cn(){}cn.__reactDisabledLog=!0;function ni(){{if(pe===0){fe=console.log,Se=console.info,Fe=console.warn,Ae=console.error,Re=console.group,it=console.groupCollapsed,dn=console.groupEnd;var _={configurable:!0,enumerable:!0,value:cn,writable:!0};Object.defineProperties(console,{info:_,log:_,warn:_,error:_,group:_,groupCollapsed:_,groupEnd:_})}pe++}}function ri(){{if(pe--,pe===0){var _={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:ne({},_,{value:fe}),info:ne({},_,{value:Se}),warn:ne({},_,{value:Fe}),error:ne({},_,{value:Ae}),group:ne({},_,{value:Re}),groupCollapsed:ne({},_,{value:it}),groupEnd:ne({},_,{value:dn})})}pe<0&&$("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var $t=I.ReactCurrentDispatcher,ft;function et(_,M,E){{if(ft===void 0)try{throw Error()}catch(ie){var R=ie.stack.trim().match(/\n( *(at )?)/);ft=R&&R[1]||""}return`
18
18
  `+ft+_}}var at=!1,tt;{var gt=typeof WeakMap=="function"?WeakMap:Map;tt=new gt}function mt(_,M){if(!_||at)return"";{var E=tt.get(_);if(E!==void 0)return E}var R;at=!0;var ie=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var ue;ue=$t.current,$t.current=null,ni();try{if(M){var ee=function(){throw Error()};if(Object.defineProperty(ee.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(ee,[])}catch(Qe){R=Qe}Reflect.construct(_,[],ee)}else{try{ee.call()}catch(Qe){R=Qe}_.call(ee.prototype)}}else{try{throw Error()}catch(Qe){R=Qe}_()}}catch(Qe){if(Qe&&R&&typeof Qe.stack=="string"){for(var J=Qe.stack.split(`
19
19
  `),ke=R.stack.split(`
20
- `),ge=J.length-1,be=ke.length-1;ge>=1&&be>=0&&J[ge]!==ke[be];)be--;for(;ge>=1&&be>=0;ge--,be--)if(J[ge]!==ke[be]){if(ge!==1||be!==1)do if(ge--,be--,be<0||J[ge]!==ke[be]){var Ee=`
21
- `+J[ge].replace(" at new "," at ");return _.displayName&&Ee.includes("<anonymous>")&&(Ee=Ee.replace("<anonymous>",_.displayName)),typeof _=="function"&&tt.set(_,Ee),Ee}while(ge>=1&&be>=0);break}}}finally{at=!1,$t.current=ue,ri(),Error.prepareStackTrace=ie}var yt=_?_.displayName||_.name:"",ro=yt?et(yt):"";return typeof _=="function"&&tt.set(_,ro),ro}function zt(_,M,E){return mt(_,!1)}function Et(_){var M=_.prototype;return!!(M&&M.isReactComponent)}function nt(_,M,E){if(_==null)return"";if(typeof _=="function")return mt(_,Et(_));if(typeof _=="string")return et(_);switch(_){case c:return et("Suspense");case f:return et("SuspenseList")}if(typeof _=="object")switch(_.$$typeof){case d:return zt(_.render);case g:return nt(_.type,M,E);case h:{var R=_,ie=R._payload,ue=R._init;try{return nt(ue(ie),M,E)}catch{}}}return""}var Lt=Object.prototype.hasOwnProperty,Ys={},Rs=I.ReactDebugCurrentFrame;function pn(_){if(_){var M=_._owner,E=nt(_.type,_._source,M?M.type:null);Rs.setExtraStackFrame(E)}else Rs.setExtraStackFrame(null)}function Nw(_,M,E,R,ie){{var ue=Function.call.bind(Lt);for(var ee in _)if(ue(_,ee)){var J=void 0;try{if(typeof _[ee]!="function"){var ke=Error((R||"React class")+": "+E+" type `"+ee+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof _[ee]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw ke.name="Invariant Violation",ke}J=_[ee](M,ee,R,E,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(ge){J=ge}J&&!(J instanceof Error)&&(pn(ie),$("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",R||"React class",E,ee,typeof J),pn(null)),J instanceof Error&&!(J.message in Ys)&&(Ys[J.message]=!0,pn(ie),$("Failed %s type: %s",E,J.message),pn(null))}}}var Gw=Array.isArray;function ii(_){return Gw(_)}function qw(_){{var M=typeof Symbol=="function"&&Symbol.toStringTag,E=M&&_[Symbol.toStringTag]||_.constructor.name||"Object";return E}}function Fw(_){try{return Qs(_),!1}catch{return!0}}function Qs(_){return""+_}function Us(_){if(Fw(_))return $("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",qw(_)),Qs(_)}var Pt=I.ReactCurrentOwner,Ww={key:!0,ref:!0,__self:!0,__source:!0},Xs,Zs,ai;ai={};function jw(_){if(Lt.call(_,"ref")){var M=Object.getOwnPropertyDescriptor(_,"ref").get;if(M&&M.isReactWarning)return!1}return _.ref!==void 0}function Yw(_){if(Lt.call(_,"key")){var M=Object.getOwnPropertyDescriptor(_,"key").get;if(M&&M.isReactWarning)return!1}return _.key!==void 0}function Rw(_,M){if(typeof _.ref=="string"&&Pt.current&&M&&Pt.current.stateNode!==M){var E=oe(Pt.current.type);ai[E]||($('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',oe(Pt.current.type),_.ref),ai[E]=!0)}}function Qw(_,M){{var E=function(){Xs||(Xs=!0,$("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",M))};E.isReactWarning=!0,Object.defineProperty(_,"key",{get:E,configurable:!0})}}function Uw(_,M){{var E=function(){Zs||(Zs=!0,$("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",M))};E.isReactWarning=!0,Object.defineProperty(_,"ref",{get:E,configurable:!0})}}var Xw=function(_,M,E,R,ie,ue,ee){var J={$$typeof:t,type:_,key:M,ref:E,props:ee,_owner:ue};return J._store={},Object.defineProperty(J._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(J,"_self",{configurable:!1,enumerable:!1,writable:!1,value:R}),Object.defineProperty(J,"_source",{configurable:!1,enumerable:!1,writable:!1,value:ie}),Object.freeze&&(Object.freeze(J.props),Object.freeze(J)),J};function Zw(_,M,E,R,ie){{var ue,ee={},J=null,ke=null;E!==void 0&&(Us(E),J=""+E),Yw(M)&&(Us(M.key),J=""+M.key),jw(M)&&(ke=M.ref,Rw(M,ie));for(ue in M)Lt.call(M,ue)&&!Ww.hasOwnProperty(ue)&&(ee[ue]=M[ue]);if(_&&_.defaultProps){var ge=_.defaultProps;for(ue in ge)ee[ue]===void 0&&(ee[ue]=ge[ue])}if(J||ke){var be=typeof _=="function"?_.displayName||_.name||"Unknown":_;J&&Qw(ee,be),ke&&Uw(ee,be)}return Xw(_,J,ke,ie,R,Pt.current,ee)}}var si=I.ReactCurrentOwner,Ks=I.ReactDebugCurrentFrame;function bt(_){if(_){var M=_._owner,E=nt(_.type,_._source,M?M.type:null);Ks.setExtraStackFrame(E)}else Ks.setExtraStackFrame(null)}var oi;oi=!1;function li(_){return typeof _=="object"&&_!==null&&_.$$typeof===t}function Js(){{if(si.current){var _=oe(si.current.type);if(_)return`
20
+ `),ge=J.length-1,ye=ke.length-1;ge>=1&&ye>=0&&J[ge]!==ke[ye];)ye--;for(;ge>=1&&ye>=0;ge--,ye--)if(J[ge]!==ke[ye]){if(ge!==1||ye!==1)do if(ge--,ye--,ye<0||J[ge]!==ke[ye]){var Ee=`
21
+ `+J[ge].replace(" at new "," at ");return _.displayName&&Ee.includes("<anonymous>")&&(Ee=Ee.replace("<anonymous>",_.displayName)),typeof _=="function"&&tt.set(_,Ee),Ee}while(ge>=1&&ye>=0);break}}}finally{at=!1,$t.current=ue,ri(),Error.prepareStackTrace=ie}var yt=_?_.displayName||_.name:"",ro=yt?et(yt):"";return typeof _=="function"&&tt.set(_,ro),ro}function zt(_,M,E){return mt(_,!1)}function Et(_){var M=_.prototype;return!!(M&&M.isReactComponent)}function nt(_,M,E){if(_==null)return"";if(typeof _=="function")return mt(_,Et(_));if(typeof _=="string")return et(_);switch(_){case c:return et("Suspense");case f:return et("SuspenseList")}if(typeof _=="object")switch(_.$$typeof){case d:return zt(_.render);case g:return nt(_.type,M,E);case h:{var R=_,ie=R._payload,ue=R._init;try{return nt(ue(ie),M,E)}catch{}}}return""}var Lt=Object.prototype.hasOwnProperty,Ys={},Rs=I.ReactDebugCurrentFrame;function pn(_){if(_){var M=_._owner,E=nt(_.type,_._source,M?M.type:null);Rs.setExtraStackFrame(E)}else Rs.setExtraStackFrame(null)}function Nw(_,M,E,R,ie){{var ue=Function.call.bind(Lt);for(var ee in _)if(ue(_,ee)){var J=void 0;try{if(typeof _[ee]!="function"){var ke=Error((R||"React class")+": "+E+" type `"+ee+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof _[ee]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw ke.name="Invariant Violation",ke}J=_[ee](M,ee,R,E,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(ge){J=ge}J&&!(J instanceof Error)&&(pn(ie),$("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",R||"React class",E,ee,typeof J),pn(null)),J instanceof Error&&!(J.message in Ys)&&(Ys[J.message]=!0,pn(ie),$("Failed %s type: %s",E,J.message),pn(null))}}}var Gw=Array.isArray;function ii(_){return Gw(_)}function qw(_){{var M=typeof Symbol=="function"&&Symbol.toStringTag,E=M&&_[Symbol.toStringTag]||_.constructor.name||"Object";return E}}function Fw(_){try{return Qs(_),!1}catch{return!0}}function Qs(_){return""+_}function Us(_){if(Fw(_))return $("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",qw(_)),Qs(_)}var Pt=I.ReactCurrentOwner,Ww={key:!0,ref:!0,__self:!0,__source:!0},Xs,Zs,ai;ai={};function jw(_){if(Lt.call(_,"ref")){var M=Object.getOwnPropertyDescriptor(_,"ref").get;if(M&&M.isReactWarning)return!1}return _.ref!==void 0}function Yw(_){if(Lt.call(_,"key")){var M=Object.getOwnPropertyDescriptor(_,"key").get;if(M&&M.isReactWarning)return!1}return _.key!==void 0}function Rw(_,M){if(typeof _.ref=="string"&&Pt.current&&M&&Pt.current.stateNode!==M){var E=oe(Pt.current.type);ai[E]||($('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',oe(Pt.current.type),_.ref),ai[E]=!0)}}function Qw(_,M){{var E=function(){Xs||(Xs=!0,$("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",M))};E.isReactWarning=!0,Object.defineProperty(_,"key",{get:E,configurable:!0})}}function Uw(_,M){{var E=function(){Zs||(Zs=!0,$("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",M))};E.isReactWarning=!0,Object.defineProperty(_,"ref",{get:E,configurable:!0})}}var Xw=function(_,M,E,R,ie,ue,ee){var J={$$typeof:t,type:_,key:M,ref:E,props:ee,_owner:ue};return J._store={},Object.defineProperty(J._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(J,"_self",{configurable:!1,enumerable:!1,writable:!1,value:R}),Object.defineProperty(J,"_source",{configurable:!1,enumerable:!1,writable:!1,value:ie}),Object.freeze&&(Object.freeze(J.props),Object.freeze(J)),J};function Zw(_,M,E,R,ie){{var ue,ee={},J=null,ke=null;E!==void 0&&(Us(E),J=""+E),Yw(M)&&(Us(M.key),J=""+M.key),jw(M)&&(ke=M.ref,Rw(M,ie));for(ue in M)Lt.call(M,ue)&&!Ww.hasOwnProperty(ue)&&(ee[ue]=M[ue]);if(_&&_.defaultProps){var ge=_.defaultProps;for(ue in ge)ee[ue]===void 0&&(ee[ue]=ge[ue])}if(J||ke){var ye=typeof _=="function"?_.displayName||_.name||"Unknown":_;J&&Qw(ee,ye),ke&&Uw(ee,ye)}return Xw(_,J,ke,ie,R,Pt.current,ee)}}var si=I.ReactCurrentOwner,Ks=I.ReactDebugCurrentFrame;function bt(_){if(_){var M=_._owner,E=nt(_.type,_._source,M?M.type:null);Ks.setExtraStackFrame(E)}else Ks.setExtraStackFrame(null)}var oi;oi=!1;function li(_){return typeof _=="object"&&_!==null&&_.$$typeof===t}function Js(){{if(si.current){var _=oe(si.current.type);if(_)return`
22
22
 
23
23
  Check the render method of \``+_+"`."}return""}}function Kw(_){{if(_!==void 0){var M=_.fileName.replace(/^.*[\\\/]/,""),E=_.lineNumber;return`
24
24
 
25
25
  Check your code at `+M+":"+E+"."}return""}}var Hs={};function Jw(_){{var M=Js();if(!M){var E=typeof _=="string"?_:_.displayName||_.name;E&&(M=`
26
26
 
27
- Check the top-level render call using <`+E+">.")}return M}}function eo(_,M){{if(!_._store||_._store.validated||_.key!=null)return;_._store.validated=!0;var E=Jw(M);if(Hs[E])return;Hs[E]=!0;var R="";_&&_._owner&&_._owner!==si.current&&(R=" It was passed a child from "+oe(_._owner.type)+"."),bt(_),$('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',E,R),bt(null)}}function to(_,M){{if(typeof _!="object")return;if(ii(_))for(var E=0;E<_.length;E++){var R=_[E];li(R)&&eo(R,M)}else if(li(_))_._store&&(_._store.validated=!0);else if(_){var ie=S(_);if(typeof ie=="function"&&ie!==_.entries)for(var ue=ie.call(_),ee;!(ee=ue.next()).done;)li(ee.value)&&eo(ee.value,M)}}}function Hw(_){{var M=_.type;if(M==null||typeof M=="string")return;var E;if(typeof M=="function")E=M.propTypes;else if(typeof M=="object"&&(M.$$typeof===d||M.$$typeof===g))E=M.propTypes;else return;if(E){var R=oe(M);Nw(E,_.props,"prop",R,_)}else if(M.PropTypes!==void 0&&!oi){oi=!0;var ie=oe(M);$("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",ie||"Unknown")}typeof M.getDefaultProps=="function"&&!M.getDefaultProps.isReactClassApproved&&$("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function e1(_){{for(var M=Object.keys(_.props),E=0;E<M.length;E++){var R=M[E];if(R!=="children"&&R!=="key"){bt(_),$("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",R),bt(null);break}}_.ref!==null&&(bt(_),$("Invalid attribute `ref` supplied to `React.Fragment`."),bt(null))}}function no(_,M,E,R,ie,ue){{var ee=Q(_);if(!ee){var J="";(_===void 0||typeof _=="object"&&_!==null&&Object.keys(_).length===0)&&(J+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var ke=Kw(ie);ke?J+=ke:J+=Js();var ge;_===null?ge="null":ii(_)?ge="array":_!==void 0&&_.$$typeof===t?(ge="<"+(oe(_.type)||"Unknown")+" />",J=" Did you accidentally export a JSX literal instead of a component?"):ge=typeof _,$("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",ge,J)}var be=Zw(_,M,E,ie,ue);if(be==null)return be;if(ee){var Ee=M.children;if(Ee!==void 0)if(R)if(ii(Ee)){for(var yt=0;yt<Ee.length;yt++)to(Ee[yt],_);Object.freeze&&Object.freeze(Ee)}else $("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else to(Ee,_)}return _===i?e1(be):Hw(be),be}}function t1(_,M,E){return no(_,M,E,!0)}function n1(_,M,E){return no(_,M,E,!1)}var r1=n1,i1=t1;wt.Fragment=i,wt.jsx=r1,wt.jsxs=i1}()),wt}(function(e){process.env.NODE_ENV==="production"?e.exports=mo():e.exports=bo()})(go);const O=xt.Fragment,n=xt.jsx,p=xt.jsxs;function Mi(e,t){b.useEffect(()=>{const r=i=>{console.log(i);const{viewID:s}=i.detail;if(!s){console.error(new Error("[Open View] Needs to pick a view first"));return}e.views.appendToVisibles(s),t&&e.views.setIDOfVIE(s)};return window.addEventListener("open-view",r),()=>{window.removeEventListener("open-view",r)}},[e,t]),b.useEffect(()=>{const r=i=>{console.log(i);const{dictionary:s,payload:o}=i.detail;if(!o||Object.keys(o).length===0){console.error(new Error("[Set Filter Values] payload is empty"));return}Object.entries(s).forEach(([u,l])=>{e.filters.setValueByKey(u,v.get(o,l))})};return window.addEventListener("set-filter-values",r),()=>{window.removeEventListener("set-filter-values",r)}},[e]),b.useEffect(()=>{function r(s){return Array.isArray(s)?[]:typeof s=="object"?{}:typeof s=="boolean"?!1:typeof s=="string"?"":typeof s=="number"?0:s}const i=s=>{console.log(s);const{filter_keys:o}=s.detail;o.forEach(u=>{const l=v.get(e.filters.values,u),d=r(l);console.log(`${u}: ${d}`),e.filters.setValueByKey(u,d)})};return window.addEventListener("clear-filter-values",i),()=>{window.removeEventListener("clear-filter-values",i)}},[e]),b.useEffect(()=>{const r=i=>{console.log(i);const{urlTemplate:s,openInNewTab:o,enableEncoding:u=!1,payload:l}=i.detail;if(!s){console.error(new Error("[Open Link] URL is empty"));return}function d(g){return v.cloneDeepWith(g,m=>{if(u&&typeof m=="string")return encodeURIComponent(m)})}const f=v.template(s||"")(d({...l,filters:e.payloadForSQL.filterValues,context:e.payloadForSQL.context}));window.open(f,o?"_blank":"_self","noopener")};return window.addEventListener("open-link",r),()=>{window.removeEventListener("open-link",r)}},[e])}class yo{constructor(t){P(this,"symbol");this.symbol=Symbol(t)}}function je(e){return new yo(e)}class fn{constructor(){P(this,"parent");P(this,"factoryRegistry",new Map);P(this,"instanceRegistry",new Map)}createScoped(){const t=new fn;return t.parent=this,t}getRequired(t){return this.get(t)}get(t){if(this.instanceRegistry.has(t.symbol))return this.instanceRegistry.get(t.symbol);const r=this.factoryRegistry.get(t.symbol);if(r){const i=r(this);return this.instanceRegistry.set(t.symbol,i),i}if(this.parent)return this.parent.get(t)}provideFactory(t,r){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,r),this}provideValue(t,r){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,()=>r),this}dispose(){this.instanceRegistry.forEach(t=>{const r=v.get(t,"dispose");v.isFunction(r)&&r.bind(t)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}const gn=b.createContext(null);function Gt(e){const t=b.useContext(gn),r=Z.useCreation(()=>e.configure(t||new fn),[e.configure]),i=Z.usePrevious(r);return i&&i!==r&&i.dispose(),n(gn.Provider,{value:r,children:e.children})}function Ii(){return b.useContext(gn)}const vo={viewPanelInFullScreen:v.noop,inFullScreen:!1},mn=b.createContext(vo),Ai=b.createContext(null),bn=Ai.Provider;function ye(){const e=b.useContext(Ai);if(!e)throw new Error("Please use ModelContextProvider");return e}const $i=b.createContext(null),yn=$i.Provider;function F(){const e=b.useContext($i);if(!e)throw new Error("Please use ContentModelContextProvider");return e}const xo={layoutFrozen:!1,freezeLayout:v.noop,inEditMode:!1},Ze=b.createContext(xo),zi=b.createContext({panel:null,data:[],loading:!1}),vn=zi.Provider;function Ce(){const e=b.useContext(zi);if(!e.panel)throw new Error("Please use PanelContextProvider");return e}const Co={fullScreenPanelID:"",setFullScreenPanelID:v.noop},xn=b.createContext(Co);function Ei(){const e=b.useContext(xn);if(!e)throw new Error("Please use FullScreenPanelContext.Provider");return e}class $e extends b.Component{constructor(t){super(t),this.state={error:null}}componentDidCatch(t){this.setState({error:t})}render(){var t;if(this.state.error){const r=()=>{this.setState({error:null})};return p(a.Box,{children:[n(a.Text,{size:"xs",children:(t=this.state.error)==null?void 0:t.message}),n(a.Button,{variant:"subtle",size:"xs",mx:"auto",compact:!0,sx:{display:"block"},onClick:r,children:"Retry"})]})}return this.props.children}}const Cn={fontSize:"14px",lineHeight:"32px",color:"#3D3E45",ul:{paddingLeft:"2em",margin:"6px 0 0"},p:{margin:0},a:{WebkitTapHighlightColor:"transparent",color:"rgb(34, 139, 230)",textDecoration:"none","&:hover":{textDecoration:"underline"},"&:active, &:hover":{outlineWidth:0}},table:{tr:{"th, td":{padding:"0 .5em"}}},"table.rich-text-table-render, div.tableWrapper table":{"th, td":{border:"1px solid #eaeaea"},"tr:last-of-type td":{borderBottom:"1px solid #eaeaea"}},".resize-cursor":{cursor:"col-resize"},details:{summary:{listStyle:"none",cursor:"pointer",transition:"color 300ms ease",userSelect:"none"},"summary::-webkit-details-marker":{display:"none"},"summary:hover":{color:"black","&::before":{opacity:1}},"summary::before":{content:'"►"',fontSize:"10px",margin:"0px 5px",opacity:.5,display:"inline-block",transition:"opacity 300ms ease, transform 300ms ease"}},"details[open] summary::before":{transform:"rotate(90deg)"},"details + details":{marginTop:"10px"}},qt=({value:e,styles:t={}})=>{const r=Ci.useEditor({extensions:[wi,xi,X.Link,hi,pi,di,mi.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),vi,yi,bi,fi.configure({types:["heading","paragraph"]}),ci.configure({placeholder:"This is placeholder"}),gi,ui.Color],content:e,editable:!1});b.useEffect(()=>{r==null||r.commands.setContent(e)},[e,r]);const i=b.useMemo(()=>v.defaultsDeep({},{content:Cn},t),[t]);return n(X.RichTextEditor,{editor:r,styles:i,children:n(X.RichTextEditor.Content,{})})},wo=({description:e,isDescriptionEmpty:t})=>t?null:n(a.Tooltip,{color:"white",label:n(qt,{value:e,styles:{root:{border:"none"},content:{padding:0}}}),styles:{tooltip:{border:"0.0625rem solid rgb(233, 236, 239)",boxShadow:"rgb(0 0 0 / 5%) 0px 0.0625rem 0.1875rem, rgb(0 0 0 / 5%) 0px 1.25rem 1.5625rem -0.3125rem, rgb(0 0 0 / 4%) 0px 0.625rem 0.625rem -0.3125rem"}},withArrow:!0,children:n(a.Box,{sx:{height:"16px",alignSelf:"center"},children:n(V.IconInfoCircle,{size:16,color:"gray"})})}),_o=T.observer(({label:e,config:{default_value:t,description:r,isDescriptionEmpty:i,...s},value:o,onChange:u})=>p(a.Box,{children:[n(a.Text,{children:" "}),n(a.Checkbox,{label:p(a.Group,{noWrap:!0,position:"apart",align:"middle",spacing:6,children:[n(a.Box,{sx:{flexGrow:1},children:e}),n(wo,{description:r,isDescriptionEmpty:i})]}),checked:o||!1,onChange:l=>u(l.currentTarget.checked),...s,pt:".4em",styles:{input:{borderColor:"#e9ecef"}}})]})),Li=T.observer(({label:e,config:t,value:r=[null,null],onChange:i})=>{const s=Array.isArray(r)?r.map(d=>d?j(d).toDate():null):[null,null],o=d=>{i(d.map(c=>c&&j(c).format(t.inputFormat)))},u=t.getMinDate(s[0]),l=t.getMaxDate(s[0]);return n(io.DateRangePicker,{label:e,value:s,onChange:o,icon:n(k.Calendar,{size:16}),sx:{minWidth:"16em"},minDate:u,maxDate:l,styles:{input:{borderColor:"#e9ecef"}},...t})}),Pi=b.forwardRef(({label:e,description:t,...r},i)=>n("div",{ref:i,...r,children:n(a.Group,{noWrap:!0,children:p("div",{children:[n(a.Text,{size:"sm","data-role":"label",children:e}),n(a.Text,{size:"xs",color:"dimmed","data-role":"description",children:t})]})})})),So=T.observer(({label:e,config:t,value:r,onChange:i})=>{const s=F(),o=!!t.options_query_id,{state:u}=s.getDataStuffByID(t.options_query_id),l=u==="loading",d=t.min_width?t.min_width:"200px",c=o?l:!1;return n(a.MultiSelect,{label:e,data:t.options,disabled:c,value:r,onChange:i,styles:{root:{minWidth:d,maxWidth:c?d:"unset"},input:{borderColor:"#e9ecef"}},itemComponent:Pi})}),To=T.observer(({label:e,config:t,value:r,onChange:i})=>{const s=F(),o=!!t.options_query_id,{state:u}=s.getDataStuffByID(t.options_query_id),l=u==="loading";return b.useEffect(()=>{var f;const{default_selection_count:d}=t;if(!d)return;const c=((f=t.options[0])==null?void 0:f.value)??"";console.log("Selecting the first option by default. New value: ",c),i(c,!0)},[t.default_selection_count,t.options]),n(a.Select,{label:e,data:t.options,disabled:o?l:!1,value:r,onChange:i,styles:{root:{width:t.width?t.width:"200px"},input:{borderColor:"#e9ecef"}},sx:{".mantine-Select-item[data-selected] .mantine-Text-root[data-role=description]":{color:"rgba(255,255,255,.7)"}},itemComponent:Pi})});function ko({label:e,config:t,value:r,onChange:i}){return n(a.TextInput,{label:e,value:r||"",onChange:s=>i(s.currentTarget.value),...t,styles:{input:{borderColor:"#e9ecef"}}})}function Do(e){return ao.arrayToTree(e,{id:"value",parentId:"parent_value",childrenField:"children",dataField:null})}const Mo=({rotate:e,onClick:t})=>n("svg",{onClick:t,className:"caret-icon",viewBox:"0 0 1024 1024",focusable:"false","data-icon":"caret-down",width:"14px",height:"14px",fill:"currentColor","aria-hidden":"true",transform:`rotate(${e})`,children:n("path",{d:"M840.4 300H183.6c-19.7 0-30.7 20.8-18.5 35l328.4 380.8c9.4 10.9 27.5 10.9 37 0L858.9 335c12.2-14.2 1.2-35-18.5-35z"})}),Io=({expanded:e,isLeaf:t,value:r,onClick:i,...s})=>(r==="0-0-value"&&console.log(s),t?n("span",{style:{width:"14px",display:"inline-block"}}):n(Mo,{rotate:e?"0":"-90",onClick:i,...s})),Ao=({onClick:e})=>p("svg",{onClick:e,className:"checkbox-icon",width:"16",height:"16",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[n("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),n("rect",{className:"border",x:"4",y:"4",width:"16",height:"16",rx:"2"}),n("rect",{className:"checkmark-indeterminate",x:"8",y:"8",width:"8",height:"8",rx:"2",stroke:"none"}),n("path",{className:"checkmark-checked",d:"M9 12l2 2l4 -4"})]}),$o=({onClick:e,...t})=>n(Ao,{onClick:e,...t}),zo=a.createStyles((e,{radius:t=4})=>({root:{borderRadius:e.fn.radius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-tree-select.rc-tree-select-open":{borderColor:"#228be6 !important",".rc-tree-select-selection-overflow-item-rest":{display:"none"},".rc-tree-select-selection-overflow-item-suffix":{display:"block"}},".rc-tree-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-tree-select-selection-search-mirror":{display:"none"},".rc-tree-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-tree-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-tree-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-tree-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-tree-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-tree-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-tree-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-tree-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},dropdown:{fontSize:e.fontSizes.xs,zIndex:300,paddingTop:"6px","&.rc-tree-select-dropdown-slide-up-leave-active":{display:"none"},".rc-tree-select-tree-list .rc-tree-select-tree-list-holder":{},".rc-tree-select-tree-list, .rc-tree-select-empty":{backgroundColor:"#fff",border:"1px solid #e9ecef",padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px"},".rc-tree-select-empty":{padding:"8px 12px"},".rc-tree-select-tree-treenode":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"8px 12px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},"&.rc-tree-select-tree-treenode-checkbox-checked":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-checked":{stroke:"rgb(64, 192, 87)",animation:"check 200ms linear forwards"}},"&.rc-tree-select-tree-treenode-checkbox-indeterminate":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-indeterminate":{fill:"rgb(64, 192, 87)"}},".rc-tree-select-tree-switcher":{height:"16px",alignSelf:"center",paddingRight:"2px",transition:"color 200ms ease","&:hover":{color:"#228be6","svg.caret-icon":{color:"#228be6"}},"svg.caret-icon":{color:"#ced4da",transition:"all 200ms ease"}},".rc-tree-select-tree-node-content-wrapper":{display:"flex",flexWrap:"nowrap",overflow:"hidden",alignItems:"center",gap:"8px",transition:"color 200ms ease","&:hover":{color:"#228be6"}},".rc-tree-select-tree-iconEle":{height:"16px","svg .border":{stroke:"#ced4da"},".checkbox-icon .checkmark-indeterminate":{fill:"transparent",transition:"fill 200ms ease"},".checkbox-icon .checkmark-checked":{transform:"scale(1.2)",transformOrigin:"center center",strokeDasharray:10,strokeDashoffset:-10},"@keyframes check":{"0%":{strokeDashoffset:10},"100%":{strokeDashoffset:0}}},".rc-tree-select-tree-title":{textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden",".rc-tree-select-tree-title-desc":{fontSize:"12px",maxWidth:"100%",textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden"}},".rc-tree-select-tree-indent":{flexGrow:0,height:0,verticalAlign:"bottom"},".rc-tree-select-tree-indent-unit":{display:"inline-block",width:"1em"}}}})),Eo=({disabled:e,classNames:t,styles:r,unstyled:i,radius:s,style:o,label:u,value:l,onChange:d,treeData:c})=>{const{classes:f,cx:g}=zo({radius:s},{name:"FilterTreeSelectWidget",classNames:t,styles:r,unstyled:i}),[h,m]=b.useState((l==null?void 0:l.length)>0),w=S=>{m(S)},C=h&&(l==null?void 0:l.length)>0;return p(a.Stack,{spacing:3,children:[p(a.Group,{position:"apart",children:[n(a.Text,{className:f.label,children:u}),C&&n(a.Tooltip,{label:`${l.length} selected`,children:n(a.Badge,{children:l.length})})]}),n(_i,{disabled:e,allowClear:!0,className:g(f.root,"check-select"),dropdownClassName:g(f.dropdown,""),onDropdownVisibleChange:w,transitionName:"rc-tree-select-dropdown-slide-up",choiceTransitionName:"rc-tree-select-selection__choice-zoom",style:o,treeLine:!0,clearIcon:()=>n(a.CloseButton,{}),switcherIcon:Io,treeIcon:$o,maxTagTextLength:10,value:l,treeData:c,treeNodeFilterProp:"filterBasis",treeCheckable:!0,showCheckedStrategy:_i.SHOW_PARENT,onChange:d,onSelect:console.log,maxTagCount:0,maxTagPlaceholder:S=>`${S.length} selected`})]})};function Lo(e){return e.map(t=>{const{label:r,description:i,...s}=t,o={...s,filterBasis:`${r}___${i??""}`,description:i,label:r};return i&&(o.label=p("div",{children:[n(a.Text,{title:t.label,children:t.label}),n(a.Text,{className:"rc-tree-select-tree-title-desc",color:"dimmed",title:t.description,children:t.description})]})),o})}const Po=T.observer(({label:e,config:t,value:r,onChange:i})=>{const s=F(),{state:o,dataProxy:u,len:l}=s.getDataStuffByID(t.options_query_id),d=o==="loading",c=b.useMemo(()=>{if(!u)return[];const m=[...u],w=Lo(m);return Do(w)},[u,l]);b.useEffect(()=>{const{default_selection_count:m}=t;if(!m)return;if(c.length===0){console.log("[filter.tree-select] Resetting to empty"),i([],!0);return}const w=c.slice(0,m).map(C=>C.value);console.log(`[filter.tree-select] Selecting first ${m} option(s)`),i(w,!0)},[t.default_selection_count,c]);const f=t.min_width?t.min_width:"200px",h=!!t.options_query_id?d:!1;return n(Eo,{disabled:h,style:{minWidth:f,maxWidth:h?f:"unset",borderColor:"#e9ecef"},value:r,onChange:m=>i(m,!1),treeData:c,label:e})}),Oo=T.observer(({filter:{type:e,config:t,key:r,...i},formFieldProps:s})=>{switch(e){case"select":return n(To,{...i,...s,config:t});case"multi-select":return n(So,{...i,...s,config:t});case"tree-select":return n(Po,{...i,...s,config:t});case"text-input":return n(ko,{...i,...s,config:t});case"date-range":return n(Li,{...i,...s,config:t});case"checkbox":return n(_o,{...i,...s,config:t});default:return null}}),Oi=T.observer(b.forwardRef(({filter:e,...t},r)=>n("div",{className:"filter-root",ref:r,children:n($e,{children:n(Oo,{filter:e,formFieldProps:t})})}))),Vi=T.observer(function({view:t}){const r=F(),{control:i,handleSubmit:s,reset:o}=x.useForm({defaultValues:r.filters.values,reValidateMode:"onBlur"}),u=x.useWatch({control:i});b.useEffect(()=>{o(r.filters.values)},[r.filters.values,o]),b.useEffect(()=>{r.filters.updatePreviewValues(u)},[u]);const l=r.filters.visibleInView(t.id),d=b.useMemo(()=>l.every(h=>h.should_auto_submit),[l]),c=b.useMemo(()=>l.filter(h=>v.get(h,"config.required",!1)),[l]),f=b.useMemo(()=>c.length===0?!1:c.some(h=>!h.requiredAndPass(u[h.key])),[u,c]);if(l.length===0)return null;const g=(h,m)=>(w,C)=>{m(w),(h.should_auto_submit||C)&&r.filters.setValueByKey(h.key,w)};return n("form",{onSubmit:s(r.filters.setValues),children:p(a.Group,{className:"dashboard-filters",position:"apart",noWrap:!0,sx:d?{}:{border:"1px solid #e9ecef",borderRadius:"4px",padding:"16px"},children:[n(a.Group,{align:"flex-start",children:l.map(h=>n(x.Controller,{name:h.key,control:i,render:({field:m})=>n(Oi,{filter:h,value:m.value,onChange:g(h,m.onChange)})},h.id))}),!d&&n(a.Group,{sx:{alignSelf:"flex-end"},children:n(a.Button,{color:"blue",size:"sm",type:"submit",disabled:f,children:"Search"})})]})})}),l1="";function Vo(e){return e?["<p><br></p>","<p></p>"].includes(e):!0}const Bi=T.observer(()=>{const{freezeLayout:e}=b.useContext(Ze),[t,r]=b.useState(!1),{panel:i}=Ce();return b.useEffect(()=>{e(t)},[t]),Vo(i.description)?null:p(O,{children:[n(a.Modal,{opened:t,onClose:()=>r(!1),title:i.title,withCloseButton:!1,withinPortal:!0,zIndex:310,children:n(qt,{value:i.description,styles:{root:{border:"none"},content:{padding:0}}})}),n(a.Tooltip,{label:"Click to see description",position:"top-start",withinPortal:!0,children:n(a.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>r(s=>!s),sx:{verticalAlign:"baseline",cursor:"pointer"},children:n(k.InfoCircle,{size:20})})})]})}),Bo=T.observer(({view:e})=>{const t=ye(),r=F(),i=Le.useModals(),{panel:s}=Ce(),{id:o,query:u}=s,{inEditMode:l}=b.useContext(Ze),d=()=>u==null?void 0:u.fetchData(),{viewPanelInFullScreen:c,inFullScreen:f}=b.useContext(mn),g=()=>{r.duplicatePanelByID(o,e.id)},h=()=>{t.editor.open(["_VIEWS_",e.id,"_PANELS_",o])},m=()=>i.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>r.removePanelByID(o,e.id),confirmProps:{color:"red"},zIndex:320}),w=b.useCallback(()=>{c(o)},[o,c]),C=!f&&e.type!==K.Modal;return n(O,{children:n(a.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:p(a.Menu,{withinPortal:!0,children:[n(a.Menu.Target,{children:n(a.Box,{className:"panel-dropdown-target",sx:{width:"100%",height:"25px"}})}),p(a.Menu.Dropdown,{children:[n(a.Menu.Item,{onClick:d,icon:n(k.Refresh,{size:14}),children:"Refresh"}),n(a.Menu.Item,{onClick:()=>r.queries.downloadDataByQueryID((u==null?void 0:u.id)??""),icon:n(k.Download,{size:14}),children:"Download Data"}),C&&n(a.Menu.Item,{onClick:w,icon:n(k.ArrowsMaximize,{size:14}),disabled:l,children:"Full Screen"}),l&&p(O,{children:[n(a.Divider,{label:"Edit",labelPosition:"center"}),n(a.Menu.Item,{onClick:h,icon:n(k.Settings,{size:14}),children:"Settings"}),n(a.Menu.Item,{onClick:g,icon:n(k.Copy,{size:14}),children:"Duplicate"}),n(a.Menu.Item,{color:"red",onClick:m,icon:n(k.Trash,{size:14}),children:"Delete"})]})]})]})})})}),u1="",No=T.observer(function(){const{panel:t}=Ce(),{title:r}=t;return r?n(a.Group,{grow:!0,position:"center",px:20,className:"panel-title-wrapper",sx:{flexGrow:1},children:n(a.Text,{align:"center",lineClamp:1,weight:"bold",children:r})}):null}),Ve=(e,t)=>{const[r,i]=b.useState([]);return b.useEffect(()=>e.watchTriggerSnapshotList(s=>i(s.filter(o=>o.schemaRef===t))),[]),r};class lt{constructor(t,r){this.root=t,this.path=r}async deleteItem(t){t===null&&await this.root.deleteItem(this.path);const r=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,v.omit(r,t))}async getItem(t){const r=await this.root.getItem(this.path);return t===null?r:v.get(r,t)}async setItem(t,r){if(t===null)await this.root.setItem(this.path,r);else{const i=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,{...i,[t]:r})}return await this.getItem(t)}watchItem(t,r,i){return t===null?this.root.watchItem(this.path,(s,o)=>{r(s,o)},i):this.root.watchItem(this.path,(s,o)=>{const u=v.get(s,t),l=v.get(o,t);u!==l&&r(u,l)},i)}}class wn{constructor(t,r,i){P(this,"attachmentStorage");this.instance=t,this.attachmentKey=r,this.constructInstance=i,this.attachmentStorage=new lt(t.instanceData,r)}async getInstance(t){if(await this.attachmentStorage.getItem(t))return this.constructInstance(new lt(this.attachmentStorage,t))}async create(t,r){return await this.attachmentStorage.setItem(t,r),this.constructInstance(new lt(this.attachmentStorage,t))}async remove(t){await this.attachmentStorage.deleteItem(t)}async list(){const t=await this.attachmentStorage.getItem(null);return Promise.all(v.values(t).map(r=>this.constructInstance(new lt(this.attachmentStorage,r.id))))}}class Ni{constructor(t){P(this,"rootRef");this.rootRef=ae.observable({current:t})}async deleteItem(t){ae.runInAction(()=>{v.unset(this.rootRef.current,[t])})}getItem(t){const r=this.getValueFromRoot(t);return Promise.resolve(r)}getValueFromRoot(t){return t===null?ae.toJS(this.rootRef.current):v.get(this.rootRef.current,[t])}setItem(t,r){if(t===null)if(v.isObject(r))ae.runInAction(()=>{this.rootRef.current=r});else throw new Error("Cannot set root value to non-object");else ae.runInAction(()=>{v.set(this.rootRef.current,[t],r)});return Promise.resolve(this.getItem(t))}watchItem(t,r,i){return ae.reaction(()=>this.getValueFromRoot(t),(s,o)=>{r(s,o)},{requiresObservable:!0,fireImmediately:v.get(i,"fireImmediately",!1)})}}class Go{constructor(){P(this,"channels",new Map);P(this,"globalChannel",new Si)}getChannel(t){const r=this.channels.get(t);if(r)return r;const i=new Si;return this.channels.set(t,i),i}}class qo{constructor(t){P(this,"instances",new Map);this.pluginManager=t}get availableVizList(){return this.pluginManager.installedPlugins.flatMap(t=>t.manifest.viz)}resolveComponent(t){return this.pluginManager.factory.viz(t)}getOrCreateInstance(t){const r=this.instances.get(t.id);if(r)return r;const i={id:t.id,name:t.viz.type,type:t.viz.type,messageChannels:new Go,instanceData:new Ni(t.viz.conf)};return this.instances.set(t.id,i),i}}function Gi(e,t,r,i){return{vizManager:r,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new Ni({}),colorPalette:{getColor(){return()=>""}},data:t,variables:i}}const Fo=e=>{const{panel:t,vizManager:r,data:i,variables:s}=e,o=r.resolveComponent(t.viz.type),u=r.getOrCreateInstance(t),l={...Gi(u,i,r,s),viewport:{width:t.layout.w,height:t.layout.h}},d=o.viewRender;return n(d,{context:l,instance:u,...v.omit(e,["panel","vizManager","data"])})},Wo=e=>{const{vizManager:t,panel:r,panelInfoEditor:i,data:s,variables:o}=e,u=t.resolveComponent(r.viz.type),l=t.getOrCreateInstance(r),d={...Gi(l,s,t,o),panelInfoEditor:i},c=u.configRender;return n(c,{context:d,instance:l,...v.omit(e,["panel","vizManager","data","panelInfoEditor"])})},qi=(e,t)=>{const r=We.bezier(e),i=We.bezier(t);return function(s){return s<50?r(s*2/100).hex():i((s-50)*2/100).hex()}},Ft=e=>{const t=We.bezier(e);return function(r){return t(r/100).hex()}},jo={type:"interpolation",displayName:"Red / Green",getColor:qi(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},Yo={type:"interpolation",displayName:"Yellow / Blue",getColor:qi(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},Ro={type:"interpolation",displayName:"Red",getColor:Ft(["#fff7f1","darkred"]),name:"red",category:"sequential"},Qo={type:"interpolation",displayName:"Green",getColor:Ft(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},Uo={type:"interpolation",displayName:"Blue",getColor:Ft(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},Xo={type:"interpolation",displayName:"Orange",getColor:Ft(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"},Fi="@devtable/dashboard",_n="8.63.0",Wi="Apache-2.0",ji={access:"public",registry:"https://registry.npmjs.org/"},Yi=["dist"],Ri="./dist/dashboard.umd.js",Qi="./dist/dashboard.es.js",Ui="./dist/index.d.ts",Xi={".":{import:"./dist/dashboard.es.js",require:"./dist/dashboard.umd.js"},"./dist/style.css":{import:"./dist/style.css",require:"./dist/style.css"}},Zi={"dev-build":"tsc && vite build --watch",build:"tsc && vite build",preview:"vite preview",test:"vitest","test:ui":"vitest --ui",coverage:"vitest --coverage"},Ki={"@monaco-editor/react":"4.4.6","@types/chroma-js":"^2.1.4","file-saver":"2.0.5",mathjs:"11.8.0","monaco-editor":"0.36.0","performant-array-to-tree":"1.11.0",popmotion:"^11.0.3","rc-tree-select":"5.5.5",reactflow:"^11.5.3"},Ji={"@emotion/babel-plugin":"11.10.6","@faker-js/faker":"7.6.0","@mantine/core":"5.9.5","@mantine/dates":"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":"^9.0.0","@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.3","@tiptap/extension-color":"2.0.3","@tiptap/extension-highlight":"2.0.3","@tiptap/extension-link":"2.0.3","@tiptap/extension-placeholder":"2.0.3","@tiptap/extension-subscript":"2.0.3","@tiptap/extension-superscript":"2.0.3","@tiptap/extension-table":"2.0.3","@tiptap/extension-table-cell":"2.0.3","@tiptap/extension-table-header":"2.0.3","@tiptap/extension-table-row":"2.0.3","@tiptap/extension-text-align":"2.0.3","@tiptap/extension-text-style":"2.0.3","@tiptap/extension-underline":"2.0.3","@tiptap/pm":"2.0.3","@tiptap/react":"2.0.3","@tiptap/starter-kit":"2.0.3","@types/crypto-js":"v4.1.1","@types/d3-array":"3.0.4","@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.12.0",axios:"^0.27.2","crypto-js":"^4.1.1",cypress:"^12.9.0","cypress-wait-until":"^1.7.2",echarts:"^5.3.2","echarts-for-react":"^3.0.2","echarts-gl":"^2.0.9",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","vite-plugin-static-copy":"0.13.1"},Hi={"@emotion/react":"11.10.6","@faker-js/faker":"7.6.0","@mantine/core":"5.9.5","@mantine/dates":"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.3","@tiptap/extension-color":"2.0.3","@tiptap/extension-highlight":"2.0.3","@tiptap/extension-link":"2.0.3","@tiptap/extension-placeholder":"2.0.3","@tiptap/extension-subscript":"2.0.3","@tiptap/extension-superscript":"2.0.3","@tiptap/extension-table":"2.0.3","@tiptap/extension-table-cell":"2.0.3","@tiptap/extension-table-header":"2.0.3","@tiptap/extension-table-row":"2.0.3","@tiptap/extension-text-align":"2.0.3","@tiptap/extension-text-style":"2.0.3","@tiptap/extension-underline":"2.0.3","@tiptap/pm":"2.0.3","@tiptap/react":"2.0.3","@tiptap/starter-kit":"2.0.3",ahooks:"^3.3.11",axios:"^0.27.2","chroma-js":"^2.4.2","crypto-js":"^4.1.1","d3-array":"3.2.3","d3-regression":"1.3.10",dayjs:"1.11.7",echarts:"^5.3.2","echarts-for-react":"^3.0.2","echarts-gl":"^2.0.9",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-router-dom":"^6.3.0","react-virtual":"^2.10.4","tabler-icons-react":"^1.48.0"},Zo=Object.freeze(Object.defineProperty({__proto__:null,default:{name:Fi,version:_n,license:Wi,publishConfig:ji,files:Yi,main:Ri,module:Qi,types:Ui,exports:Xi,scripts:Zi,dependencies:Ki,devDependencies:Ji,peerDependencies:Hi},dependencies:Ki,devDependencies:Ji,exports:Xi,files:Yi,license:Wi,main:Ri,module:Qi,name:Fi,peerDependencies:Hi,publishConfig:ji,scripts:Zi,types:Ui,version:_n},Symbol.toStringTag,{value:"Module"}));class Ko{constructor(t){P(this,"staticColors",new Map);P(this,"interpolations",new Map);t.installedPlugins.forEach(r=>{r.manifest.color.forEach(i=>{this.register(i)})})}getStaticColors(){return Array.from(this.staticColors.values())}register(t){const r=this.encodeColor(t);t.type==="single"?(this.staticColors.has(r)&&console.warn(`the color '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.staticColors.set(r,t)):t.type==="interpolation"&&(this.interpolations.has(r)&&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(r,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 Jo{constructor(){P(this,"plugins",new Map);P(this,"vizComponents",new Map);P(this,"factory",{viz:t=>{const r=this.vizComponents.get(t);if(r)return r;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 r of t.manifest.viz){if(this.vizComponents.has(r.name))throw new Error(`Viz Component (${r.name}) has been installed before`);this.vizComponents.set(r.name,r)}}get installedPlugins(){return Array.from(this.plugins.values())}}class Ho{constructor(){P(this,"migrations",[])}version(t,r){return this.migrations.push({version:t,handler:r}),this}run(t,r,i){var u;if(t.from===t.to)return r;if(t.from>t.to)throw new Error(`Can not downgrade from version '${t.from}' to (${t.to})`);const s=this.migrations.filter(l=>l.version>t.from&&l.version<=t.to),o=v.orderBy(s,"version","asc");if(((u=v.last(o))==null?void 0:u.version)!==t.to)throw new Error(`Migration to version ${t.to} not found`);return o.reduce((l,d)=>d.handler(l,i),r)}}class he extends Ho{constructor(){super(),this.configVersions()}version(t,r){return super.version(t,(i,s)=>({version:t,...r(i,s)}))}async migrate({configData:t,panelModel:r}){const i=await t.getItem(null),s=v.get(i,"version",0),o=this.run({from:s,to:this.VERSION},i,{panelModel:r});await t.setItem(null,o)}async needMigration({configData:t}){const r=await t.getItem(null);return v.get(r,"version",0)<this.VERSION}}const W=(e,t)=>{const[r,{setFalse:i}]=Z.useBoolean(!0),[s,o]=b.useState();b.useEffect(()=>(e.getItem(t).then(l=>{o(l),i()}),e.watchItem(t,l=>{o(l)})));const u=b.useCallback(async l=>{await e.setItem(t,l),o(l)},[e,t]);return{loading:r,value:s,set:u}},Sn={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"}};le.use([B.GridComponent,B.VisualMapComponent,B.LegendComponent,B.TooltipComponent,De.CanvasRenderer]);function el({context:e}){const{value:t}=W(e.instanceData,"config"),r=e.data,{width:i,height:s}=e.viewport,{x_axis_data_key:o,y_axis_data_key:u,z_axis_data_key:l,xAxis3D:d,yAxis3D:c,zAxis3D:f}=v.defaults({},t,Sn),g=b.useMemo(()=>{const w=v.minBy(r,C=>C[l]);return v.get(w,l)},[r,l]),h=b.useMemo(()=>{const w=v.maxBy(r,C=>C[l]);return v.get(w,l)},[r,l]),m={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:g,max:h,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:d,yAxis3D:c,zAxis3D:f,grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}},series:[{type:"bar3D",wireframe:{},data:r.map(w=>[w[o],w[u],w[l]])}]};return t?n(Me,{echarts:le,option:m,style:{width:i,height:s},notMerge:!0,theme:"merico-light"}):null}function tl({label:e,required:t,value:r,onChange:i,data:s,clearable:o=!1,sx:u,...l},d){const c=b.useMemo(()=>{if(!Array.isArray(s)||s.length===0)return[];const g=Object.keys(s[0]).map(h=>({label:h,value:h}));return o?g.concat([{label:"unset",value:""}]):g},[s]);return n(a.Select,{ref:d,label:e,data:c,value:r,onChange:i,required:t,sx:u,...l})}const Y=b.forwardRef(tl);function nl({context:e}){const{value:t,set:r}=W(e.instanceData,"config"),i=e.data,s=v.defaults({},t,Sn),{control:o,handleSubmit:u,reset:l}=x.useForm({defaultValues:s});return b.useEffect(()=>{l(s)},[t]),t?n(a.Stack,{spacing:"xs",children:p("form",{onSubmit:u(r),children:[n(a.Text,{children:"X Axis"}),p(a.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[n(x.Controller,{name:"x_axis_data_key",control:o,render:({field:d})=>n(Y,{label:"Data Field",required:!0,data:i,...d})}),n(x.Controller,{name:"xAxis3D.name",control:o,render:({field:d})=>n(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...d})})]}),n(a.Text,{mt:"lg",children:"Y Axis"}),p(a.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[n(x.Controller,{name:"y_axis_data_key",control:o,render:({field:d})=>n(Y,{label:"Data Field",required:!0,data:i,...d})}),n(x.Controller,{name:"yAxis3D.name",control:o,render:({field:d})=>n(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...d})})]}),n(a.Text,{mt:"lg",children:"Z Axis"}),p(a.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[n(x.Controller,{name:"z_axis_data_key",control:o,render:({field:d})=>n(Y,{label:"Data Field",required:!0,data:i,...d})}),n(x.Controller,{name:"zAxis3D.name",control:o,render:({field:d})=>n(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...d})})]}),n(a.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:p(a.Button,{color:"blue",type:"submit",children:[n(k.DeviceFloppy,{size:20}),n(a.Text,{ml:"md",children:"Save"})]})})]})}):null}class rl extends he{constructor(){super(...arguments);P(this,"VERSION",1)}configVersions(){this.version(1,r=>({version:1,config:r}))}}const il={displayName:"Bar Chart (3D)",displayGroup:"ECharts-based charts",migrator:new rl,name:"bar-3d",viewRender:el,configRender:nl,createConfig(){return{version:1,config:v.cloneDeep(Sn)}}},Ie={mantissa:0,output:"number",trimMantissa:!1,average:!1};function al({value:e,onChange:t},r){const i=l=>{t({...e,output:l})},s=l=>{const d=l===0?!1:e.trimMantissa;t({...e,mantissa:l,trimMantissa:d})},o=l=>{t({...e,trimMantissa:l.currentTarget.checked})},u=l=>{t({...e,average:l.currentTarget.checked})};return p(a.Stack,{ref:r,children:[p(a.Group,{grow:!0,children:[n(a.Select,{label:"Format",data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:e.output,onChange:i,sx:{flexGrow:1}}),n(a.Switch,{label:p(a.Stack,{spacing:0,children:[n(a.Text,{children:"Average"}),n(a.Text,{size:12,color:"gray",children:"like 1.234k, 1.234m"})]}),checked:e.average,onChange:u,disabled:e.output!=="number",sx:{flexGrow:1},styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}}})]}),p(a.Group,{grow:!0,children:[n(a.NumberInput,{label:"Mantissa",defaultValue:0,min:0,step:1,max:4,value:e.mantissa,onChange:s}),n(a.Switch,{label:"Trim mantissa",checked:e.trimMantissa,onChange:o,disabled:e.mantissa===0,styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"}}})]}),p(a.Stack,{spacing:0,children:[n(a.Text,{weight:"bold",children:"Preview"}),n($e,{children:p(a.Group,{position:"apart",children:[p(a.Text,{size:12,color:"gray",children:["123456789 ",n(k.ArrowRight,{size:9})," ",se(123456789).format(e)]}),p(a.Text,{size:12,color:"gray",children:["1234 ",n(k.ArrowRight,{size:9})," ",se(1234).format(e)]}),p(a.Text,{size:12,color:"gray",children:["0.1234 ",n(k.ArrowRight,{size:9})," ",se(.1234).format(e)]})]})})]})]})}const Be=b.forwardRef(al),Ne={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
27
+ Check the top-level render call using <`+E+">.")}return M}}function eo(_,M){{if(!_._store||_._store.validated||_.key!=null)return;_._store.validated=!0;var E=Jw(M);if(Hs[E])return;Hs[E]=!0;var R="";_&&_._owner&&_._owner!==si.current&&(R=" It was passed a child from "+oe(_._owner.type)+"."),bt(_),$('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',E,R),bt(null)}}function to(_,M){{if(typeof _!="object")return;if(ii(_))for(var E=0;E<_.length;E++){var R=_[E];li(R)&&eo(R,M)}else if(li(_))_._store&&(_._store.validated=!0);else if(_){var ie=S(_);if(typeof ie=="function"&&ie!==_.entries)for(var ue=ie.call(_),ee;!(ee=ue.next()).done;)li(ee.value)&&eo(ee.value,M)}}}function Hw(_){{var M=_.type;if(M==null||typeof M=="string")return;var E;if(typeof M=="function")E=M.propTypes;else if(typeof M=="object"&&(M.$$typeof===d||M.$$typeof===g))E=M.propTypes;else return;if(E){var R=oe(M);Nw(E,_.props,"prop",R,_)}else if(M.PropTypes!==void 0&&!oi){oi=!0;var ie=oe(M);$("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",ie||"Unknown")}typeof M.getDefaultProps=="function"&&!M.getDefaultProps.isReactClassApproved&&$("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function e1(_){{for(var M=Object.keys(_.props),E=0;E<M.length;E++){var R=M[E];if(R!=="children"&&R!=="key"){bt(_),$("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",R),bt(null);break}}_.ref!==null&&(bt(_),$("Invalid attribute `ref` supplied to `React.Fragment`."),bt(null))}}function no(_,M,E,R,ie,ue){{var ee=Q(_);if(!ee){var J="";(_===void 0||typeof _=="object"&&_!==null&&Object.keys(_).length===0)&&(J+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var ke=Kw(ie);ke?J+=ke:J+=Js();var ge;_===null?ge="null":ii(_)?ge="array":_!==void 0&&_.$$typeof===t?(ge="<"+(oe(_.type)||"Unknown")+" />",J=" Did you accidentally export a JSX literal instead of a component?"):ge=typeof _,$("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",ge,J)}var ye=Zw(_,M,E,ie,ue);if(ye==null)return ye;if(ee){var Ee=M.children;if(Ee!==void 0)if(R)if(ii(Ee)){for(var yt=0;yt<Ee.length;yt++)to(Ee[yt],_);Object.freeze&&Object.freeze(Ee)}else $("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else to(Ee,_)}return _===i?e1(ye):Hw(ye),ye}}function t1(_,M,E){return no(_,M,E,!0)}function n1(_,M,E){return no(_,M,E,!1)}var r1=n1,i1=t1;wt.Fragment=i,wt.jsx=r1,wt.jsxs=i1}()),wt}(function(e){process.env.NODE_ENV==="production"?e.exports=mo():e.exports=bo()})(go);const O=xt.Fragment,n=xt.jsx,p=xt.jsxs;function Mi(e,t){b.useEffect(()=>{const r=i=>{console.log(i);const{viewID:s}=i.detail;if(!s){console.error(new Error("[Open View] Needs to pick a view first"));return}e.views.appendToVisibles(s),t&&e.views.setIDOfVIE(s)};return window.addEventListener("open-view",r),()=>{window.removeEventListener("open-view",r)}},[e,t]),b.useEffect(()=>{const r=i=>{console.log(i);const{dictionary:s,payload:o}=i.detail;if(!o||Object.keys(o).length===0){console.error(new Error("[Set Filter Values] payload is empty"));return}Object.entries(s).forEach(([u,l])=>{e.filters.setValueByKey(u,v.get(o,l))})};return window.addEventListener("set-filter-values",r),()=>{window.removeEventListener("set-filter-values",r)}},[e]),b.useEffect(()=>{function r(s){return Array.isArray(s)?[]:typeof s=="object"?{}:typeof s=="boolean"?!1:typeof s=="string"?"":typeof s=="number"?0:s}const i=s=>{console.log(s);const{filter_keys:o}=s.detail;o.forEach(u=>{const l=v.get(e.filters.values,u),d=r(l);console.log(`${u}: ${d}`),e.filters.setValueByKey(u,d)})};return window.addEventListener("clear-filter-values",i),()=>{window.removeEventListener("clear-filter-values",i)}},[e]),b.useEffect(()=>{const r=i=>{console.log(i);const{urlTemplate:s,openInNewTab:o,enableEncoding:u=!1,payload:l}=i.detail;if(!s){console.error(new Error("[Open Link] URL is empty"));return}function d(g){return v.cloneDeepWith(g,m=>{if(u&&typeof m=="string")return encodeURIComponent(m)})}const f=v.template(s||"")(d({...l,filters:e.payloadForSQL.filterValues,context:e.payloadForSQL.context}));window.open(f,o?"_blank":"_self","noopener")};return window.addEventListener("open-link",r),()=>{window.removeEventListener("open-link",r)}},[e])}class yo{constructor(t){P(this,"symbol");this.symbol=Symbol(t)}}function je(e){return new yo(e)}class fn{constructor(){P(this,"parent");P(this,"factoryRegistry",new Map);P(this,"instanceRegistry",new Map)}createScoped(){const t=new fn;return t.parent=this,t}getRequired(t){return this.get(t)}get(t){if(this.instanceRegistry.has(t.symbol))return this.instanceRegistry.get(t.symbol);const r=this.factoryRegistry.get(t.symbol);if(r){const i=r(this);return this.instanceRegistry.set(t.symbol,i),i}if(this.parent)return this.parent.get(t)}provideFactory(t,r){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,r),this}provideValue(t,r){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,()=>r),this}dispose(){this.instanceRegistry.forEach(t=>{const r=v.get(t,"dispose");v.isFunction(r)&&r.bind(t)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}const gn=b.createContext(null);function Gt(e){const t=b.useContext(gn),r=Z.useCreation(()=>e.configure(t||new fn),[e.configure]),i=Z.usePrevious(r);return i&&i!==r&&i.dispose(),n(gn.Provider,{value:r,children:e.children})}function Ii(){return b.useContext(gn)}const vo={viewPanelInFullScreen:v.noop,inFullScreen:!1},mn=b.createContext(vo),Ai=b.createContext(null),bn=Ai.Provider;function me(){const e=b.useContext(Ai);if(!e)throw new Error("Please use ModelContextProvider");return e}const $i=b.createContext(null),yn=$i.Provider;function F(){const e=b.useContext($i);if(!e)throw new Error("Please use ContentModelContextProvider");return e}const xo={layoutFrozen:!1,freezeLayout:v.noop,inEditMode:!1},Ze=b.createContext(xo),zi=b.createContext({panel:null,data:[],loading:!1}),vn=zi.Provider;function Ce(){const e=b.useContext(zi);if(!e.panel)throw new Error("Please use PanelContextProvider");return e}const Co={fullScreenPanelID:"",setFullScreenPanelID:v.noop},xn=b.createContext(Co);function Ei(){const e=b.useContext(xn);if(!e)throw new Error("Please use FullScreenPanelContext.Provider");return e}class $e extends b.Component{constructor(t){super(t),this.state={error:null}}componentDidCatch(t){this.setState({error:t})}render(){var t;if(this.state.error){const r=()=>{this.setState({error:null})};return p(a.Box,{children:[n(a.Text,{size:"xs",children:(t=this.state.error)==null?void 0:t.message}),n(a.Button,{variant:"subtle",size:"xs",mx:"auto",compact:!0,sx:{display:"block"},onClick:r,children:"Retry"})]})}return this.props.children}}const Cn={fontSize:"14px",lineHeight:"32px",color:"#3D3E45",ul:{paddingLeft:"2em",margin:"6px 0 0"},p:{margin:0},a:{WebkitTapHighlightColor:"transparent",color:"rgb(34, 139, 230)",textDecoration:"none","&:hover":{textDecoration:"underline"},"&:active, &:hover":{outlineWidth:0}},table:{tr:{"th, td":{padding:"0 .5em"}}},"table.rich-text-table-render, div.tableWrapper table":{"th, td":{border:"1px solid #eaeaea"},"tr:last-of-type td":{borderBottom:"1px solid #eaeaea"}},".resize-cursor":{cursor:"col-resize"},details:{summary:{listStyle:"none",cursor:"pointer",transition:"color 300ms ease",userSelect:"none"},"summary::-webkit-details-marker":{display:"none"},"summary:hover":{color:"black","&::before":{opacity:1}},"summary::before":{content:'"►"',fontSize:"10px",margin:"0px 5px",opacity:.5,display:"inline-block",transition:"opacity 300ms ease, transform 300ms ease"}},"details[open] summary::before":{transform:"rotate(90deg)"},"details + details":{marginTop:"10px"}},qt=({value:e,styles:t={}})=>{const r=Ci.useEditor({extensions:[wi,xi,X.Link,hi,pi,di,mi.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),vi,yi,bi,fi.configure({types:["heading","paragraph"]}),ci.configure({placeholder:"This is placeholder"}),gi,ui.Color],content:e,editable:!1});b.useEffect(()=>{r==null||r.commands.setContent(e)},[e,r]);const i=b.useMemo(()=>v.defaultsDeep({},{content:Cn},t),[t]);return n(X.RichTextEditor,{editor:r,styles:i,children:n(X.RichTextEditor.Content,{})})},wo=({description:e,isDescriptionEmpty:t})=>t?null:n(a.Tooltip,{color:"white",label:n(qt,{value:e,styles:{root:{border:"none"},content:{padding:0}}}),styles:{tooltip:{border:"0.0625rem solid rgb(233, 236, 239)",boxShadow:"rgb(0 0 0 / 5%) 0px 0.0625rem 0.1875rem, rgb(0 0 0 / 5%) 0px 1.25rem 1.5625rem -0.3125rem, rgb(0 0 0 / 4%) 0px 0.625rem 0.625rem -0.3125rem"}},withArrow:!0,children:n(a.Box,{sx:{height:"16px",alignSelf:"center"},children:n(V.IconInfoCircle,{size:16,color:"gray"})})}),_o=T.observer(({label:e,config:{default_value:t,description:r,isDescriptionEmpty:i,...s},value:o,onChange:u})=>p(a.Box,{children:[n(a.Text,{children:" "}),n(a.Checkbox,{label:p(a.Group,{noWrap:!0,position:"apart",align:"middle",spacing:6,children:[n(a.Box,{sx:{flexGrow:1},children:e}),n(wo,{description:r,isDescriptionEmpty:i})]}),checked:o||!1,onChange:l=>u(l.currentTarget.checked),...s,pt:".4em",styles:{input:{borderColor:"#e9ecef"}}})]})),Li=T.observer(({label:e,config:t,value:r=[null,null],onChange:i})=>{const s=Array.isArray(r)?r.map(d=>d?j(d).toDate():null):[null,null],o=d=>{i(d.map(c=>c&&j(c).format(t.inputFormat)))},u=t.getMinDate(s[0]),l=t.getMaxDate(s[0]);return n(io.DateRangePicker,{label:e,value:s,onChange:o,icon:n(k.Calendar,{size:16}),sx:{minWidth:"16em"},minDate:u,maxDate:l,styles:{input:{borderColor:"#e9ecef"}},...t})}),Pi=b.forwardRef(({label:e,description:t,...r},i)=>n("div",{ref:i,...r,children:n(a.Group,{noWrap:!0,children:p("div",{children:[n(a.Text,{size:"sm","data-role":"label",children:e}),n(a.Text,{size:"xs",color:"dimmed","data-role":"description",children:t})]})})})),So=T.observer(({label:e,config:t,value:r,onChange:i})=>{const s=F(),o=!!t.options_query_id,{state:u}=s.getDataStuffByID(t.options_query_id),l=u==="loading",d=t.min_width?t.min_width:"200px",c=o?l:!1;return n(a.MultiSelect,{label:e,data:t.options,disabled:c,value:r,onChange:i,styles:{root:{minWidth:d,maxWidth:c?d:"unset"},input:{borderColor:"#e9ecef"}},itemComponent:Pi})}),To=T.observer(({label:e,config:t,value:r,onChange:i})=>{const s=F(),o=!!t.options_query_id,{state:u}=s.getDataStuffByID(t.options_query_id),l=u==="loading";return b.useEffect(()=>{var f;const{default_selection_count:d}=t;if(!d)return;const c=((f=t.options[0])==null?void 0:f.value)??"";console.log("Selecting the first option by default. New value: ",c),i(c,!0)},[t.default_selection_count,t.options]),n(a.Select,{label:e,data:t.options,disabled:o?l:!1,value:r,onChange:i,styles:{root:{width:t.width?t.width:"200px"},input:{borderColor:"#e9ecef"}},sx:{".mantine-Select-item[data-selected] .mantine-Text-root[data-role=description]":{color:"rgba(255,255,255,.7)"}},itemComponent:Pi})});function ko({label:e,config:t,value:r,onChange:i}){return n(a.TextInput,{label:e,value:r||"",onChange:s=>i(s.currentTarget.value),...t,styles:{input:{borderColor:"#e9ecef"}}})}function Do(e){return ao.arrayToTree(e,{id:"value",parentId:"parent_value",childrenField:"children",dataField:null})}const Mo=({rotate:e,onClick:t})=>n("svg",{onClick:t,className:"caret-icon",viewBox:"0 0 1024 1024",focusable:"false","data-icon":"caret-down",width:"14px",height:"14px",fill:"currentColor","aria-hidden":"true",transform:`rotate(${e})`,children:n("path",{d:"M840.4 300H183.6c-19.7 0-30.7 20.8-18.5 35l328.4 380.8c9.4 10.9 27.5 10.9 37 0L858.9 335c12.2-14.2 1.2-35-18.5-35z"})}),Io=({expanded:e,isLeaf:t,value:r,onClick:i,...s})=>(r==="0-0-value"&&console.log(s),t?n("span",{style:{width:"14px",display:"inline-block"}}):n(Mo,{rotate:e?"0":"-90",onClick:i,...s})),Ao=({onClick:e})=>p("svg",{onClick:e,className:"checkbox-icon",width:"16",height:"16",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[n("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),n("rect",{className:"border",x:"4",y:"4",width:"16",height:"16",rx:"2"}),n("rect",{className:"checkmark-indeterminate",x:"8",y:"8",width:"8",height:"8",rx:"2",stroke:"none"}),n("path",{className:"checkmark-checked",d:"M9 12l2 2l4 -4"})]}),$o=({onClick:e,...t})=>n(Ao,{onClick:e,...t}),zo=a.createStyles((e,{radius:t=4})=>({root:{borderRadius:e.fn.radius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-tree-select.rc-tree-select-open":{borderColor:"#228be6 !important",".rc-tree-select-selection-overflow-item-rest":{display:"none"},".rc-tree-select-selection-overflow-item-suffix":{display:"block"}},".rc-tree-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-tree-select-selection-search-mirror":{display:"none"},".rc-tree-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-tree-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-tree-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-tree-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-tree-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-tree-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-tree-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-tree-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},dropdown:{fontSize:e.fontSizes.xs,zIndex:300,paddingTop:"6px","&.rc-tree-select-dropdown-slide-up-leave-active":{display:"none"},".rc-tree-select-tree-list .rc-tree-select-tree-list-holder":{},".rc-tree-select-tree-list, .rc-tree-select-empty":{backgroundColor:"#fff",border:"1px solid #e9ecef",padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px"},".rc-tree-select-empty":{padding:"8px 12px"},".rc-tree-select-tree-treenode":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"8px 12px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},"&.rc-tree-select-tree-treenode-checkbox-checked":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-checked":{stroke:"rgb(64, 192, 87)",animation:"check 200ms linear forwards"}},"&.rc-tree-select-tree-treenode-checkbox-indeterminate":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-indeterminate":{fill:"rgb(64, 192, 87)"}},".rc-tree-select-tree-switcher":{height:"16px",alignSelf:"center",paddingRight:"2px",transition:"color 200ms ease","&:hover":{color:"#228be6","svg.caret-icon":{color:"#228be6"}},"svg.caret-icon":{color:"#ced4da",transition:"all 200ms ease"}},".rc-tree-select-tree-node-content-wrapper":{display:"flex",flexWrap:"nowrap",overflow:"hidden",alignItems:"center",gap:"8px",transition:"color 200ms ease","&:hover":{color:"#228be6"}},".rc-tree-select-tree-iconEle":{height:"16px","svg .border":{stroke:"#ced4da"},".checkbox-icon .checkmark-indeterminate":{fill:"transparent",transition:"fill 200ms ease"},".checkbox-icon .checkmark-checked":{transform:"scale(1.2)",transformOrigin:"center center",strokeDasharray:10,strokeDashoffset:-10},"@keyframes check":{"0%":{strokeDashoffset:10},"100%":{strokeDashoffset:0}}},".rc-tree-select-tree-title":{textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden",".rc-tree-select-tree-title-desc":{fontSize:"12px",maxWidth:"100%",textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden"}},".rc-tree-select-tree-indent":{flexGrow:0,height:0,verticalAlign:"bottom"},".rc-tree-select-tree-indent-unit":{display:"inline-block",width:"1em"}}}})),Eo=({disabled:e,classNames:t,styles:r,unstyled:i,radius:s,style:o,label:u,value:l,onChange:d,treeData:c})=>{const{classes:f,cx:g}=zo({radius:s},{name:"FilterTreeSelectWidget",classNames:t,styles:r,unstyled:i}),[h,m]=b.useState((l==null?void 0:l.length)>0),w=S=>{m(S)},C=h&&(l==null?void 0:l.length)>0;return p(a.Stack,{spacing:3,children:[p(a.Group,{position:"apart",children:[n(a.Text,{className:f.label,children:u}),C&&n(a.Tooltip,{label:`${l.length} selected`,children:n(a.Badge,{children:l.length})})]}),n(_i,{disabled:e,allowClear:!0,className:g(f.root,"check-select"),dropdownClassName:g(f.dropdown,""),onDropdownVisibleChange:w,transitionName:"rc-tree-select-dropdown-slide-up",choiceTransitionName:"rc-tree-select-selection__choice-zoom",style:o,treeLine:!0,clearIcon:()=>n(a.CloseButton,{}),switcherIcon:Io,treeIcon:$o,maxTagTextLength:10,value:l,treeData:c,treeNodeFilterProp:"filterBasis",treeCheckable:!0,showCheckedStrategy:_i.SHOW_PARENT,onChange:d,onSelect:console.log,maxTagCount:0,maxTagPlaceholder:S=>`${S.length} selected`})]})};function Lo(e){return e.map(t=>{const{label:r,description:i,...s}=t,o={...s,filterBasis:`${r}___${i??""}`,description:i,label:r};return i&&(o.label=p("div",{children:[n(a.Text,{title:t.label,children:t.label}),n(a.Text,{className:"rc-tree-select-tree-title-desc",color:"dimmed",title:t.description,children:t.description})]})),o})}const Po=T.observer(({label:e,config:t,value:r,onChange:i})=>{const s=F(),{state:o,dataProxy:u,len:l}=s.getDataStuffByID(t.options_query_id),d=o==="loading",c=b.useMemo(()=>{if(!u)return[];const m=[...u],w=Lo(m);return Do(w)},[u,l]);b.useEffect(()=>{const{default_selection_count:m}=t;if(!m)return;if(c.length===0){console.log("[filter.tree-select] Resetting to empty"),i([],!0);return}const w=c.slice(0,m).map(C=>C.value);console.log(`[filter.tree-select] Selecting first ${m} option(s)`),i(w,!0)},[t.default_selection_count,c]);const f=t.min_width?t.min_width:"200px",h=!!t.options_query_id?d:!1;return n(Eo,{disabled:h,style:{minWidth:f,maxWidth:h?f:"unset",borderColor:"#e9ecef"},value:r,onChange:m=>i(m,!1),treeData:c,label:e})}),Oo=T.observer(({filter:{type:e,config:t,key:r,...i},formFieldProps:s})=>{switch(e){case"select":return n(To,{...i,...s,config:t});case"multi-select":return n(So,{...i,...s,config:t});case"tree-select":return n(Po,{...i,...s,config:t});case"text-input":return n(ko,{...i,...s,config:t});case"date-range":return n(Li,{...i,...s,config:t});case"checkbox":return n(_o,{...i,...s,config:t});default:return null}}),Oi=T.observer(b.forwardRef(({filter:e,...t},r)=>n("div",{className:"filter-root",ref:r,children:n($e,{children:n(Oo,{filter:e,formFieldProps:t})})}))),Vi=T.observer(function({view:t}){const r=F(),{control:i,handleSubmit:s,reset:o}=x.useForm({defaultValues:r.filters.values,reValidateMode:"onBlur"}),u=x.useWatch({control:i});b.useEffect(()=>{o(r.filters.values)},[r.filters.values,o]),b.useEffect(()=>{r.filters.updatePreviewValues(u)},[u]);const l=r.filters.visibleInView(t.id),d=b.useMemo(()=>l.every(h=>h.should_auto_submit),[l]),c=b.useMemo(()=>l.filter(h=>v.get(h,"config.required",!1)),[l]),f=b.useMemo(()=>c.length===0?!1:c.some(h=>!h.requiredAndPass(u[h.key])),[u,c]);if(l.length===0)return null;const g=(h,m)=>(w,C)=>{m(w),(h.should_auto_submit||C)&&r.filters.setValueByKey(h.key,w)};return n("form",{onSubmit:s(r.filters.setValues),children:p(a.Group,{className:"dashboard-filters",position:"apart",noWrap:!0,sx:d?{}:{border:"1px solid #e9ecef",borderRadius:"4px",padding:"16px"},children:[n(a.Group,{align:"flex-start",children:l.map(h=>n(x.Controller,{name:h.key,control:i,render:({field:m})=>n(Oi,{filter:h,value:m.value,onChange:g(h,m.onChange)})},h.id))}),!d&&n(a.Group,{sx:{alignSelf:"flex-end"},children:n(a.Button,{color:"blue",size:"sm",type:"submit",disabled:f,children:"Search"})})]})})}),l1="";function Vo(e){return e?["<p><br></p>","<p></p>"].includes(e):!0}const Bi=T.observer(()=>{const{freezeLayout:e}=b.useContext(Ze),[t,r]=b.useState(!1),{panel:i}=Ce();return b.useEffect(()=>{e(t)},[t]),Vo(i.description)?null:p(O,{children:[n(a.Modal,{opened:t,onClose:()=>r(!1),title:i.title,withCloseButton:!1,withinPortal:!0,zIndex:310,children:n(qt,{value:i.description,styles:{root:{border:"none"},content:{padding:0}}})}),n(a.Tooltip,{label:"Click to see description",position:"top-start",withinPortal:!0,children:n(a.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>r(s=>!s),sx:{verticalAlign:"baseline",cursor:"pointer"},children:n(k.InfoCircle,{size:20})})})]})}),Bo=T.observer(({view:e})=>{const t=me(),r=F(),i=Le.useModals(),{panel:s}=Ce(),{id:o,query:u}=s,{inEditMode:l}=b.useContext(Ze),d=()=>u==null?void 0:u.fetchData(),{viewPanelInFullScreen:c,inFullScreen:f}=b.useContext(mn),g=()=>{r.duplicatePanelByID(o,e.id)},h=()=>{t.editor.open(["_VIEWS_",e.id,"_PANELS_",o])},m=()=>i.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>r.removePanelByID(o,e.id),confirmProps:{color:"red"},zIndex:320}),w=b.useCallback(()=>{c(o)},[o,c]),C=!f&&e.type!==K.Modal;return n(O,{children:n(a.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:p(a.Menu,{withinPortal:!0,children:[n(a.Menu.Target,{children:n(a.Box,{className:"panel-dropdown-target",sx:{width:"100%",height:"25px"}})}),p(a.Menu.Dropdown,{children:[n(a.Menu.Item,{onClick:d,icon:n(k.Refresh,{size:14}),children:"Refresh"}),n(a.Menu.Item,{onClick:()=>r.queries.downloadDataByQueryID((u==null?void 0:u.id)??""),icon:n(k.Download,{size:14}),children:"Download Data"}),C&&n(a.Menu.Item,{onClick:w,icon:n(k.ArrowsMaximize,{size:14}),disabled:l,children:"Full Screen"}),l&&p(O,{children:[n(a.Divider,{label:"Edit",labelPosition:"center"}),n(a.Menu.Item,{onClick:h,icon:n(k.Settings,{size:14}),children:"Settings"}),n(a.Menu.Item,{onClick:g,icon:n(k.Copy,{size:14}),children:"Duplicate"}),n(a.Menu.Item,{color:"red",onClick:m,icon:n(k.Trash,{size:14}),children:"Delete"})]})]})]})})})}),u1="",No=T.observer(function(){const{panel:t}=Ce(),{title:r}=t;return r?n(a.Group,{grow:!0,position:"center",px:20,className:"panel-title-wrapper",sx:{flexGrow:1},children:n(a.Text,{align:"center",lineClamp:1,weight:"bold",children:r})}):null}),Ve=(e,t)=>{const[r,i]=b.useState([]);return b.useEffect(()=>e.watchTriggerSnapshotList(s=>i(s.filter(o=>o.schemaRef===t))),[]),r};class lt{constructor(t,r){this.root=t,this.path=r}async deleteItem(t){t===null&&await this.root.deleteItem(this.path);const r=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,v.omit(r,t))}async getItem(t){const r=await this.root.getItem(this.path);return t===null?r:v.get(r,t)}async setItem(t,r){if(t===null)await this.root.setItem(this.path,r);else{const i=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,{...i,[t]:r})}return await this.getItem(t)}watchItem(t,r,i){return t===null?this.root.watchItem(this.path,(s,o)=>{r(s,o)},i):this.root.watchItem(this.path,(s,o)=>{const u=v.get(s,t),l=v.get(o,t);u!==l&&r(u,l)},i)}}class wn{constructor(t,r,i){P(this,"attachmentStorage");this.instance=t,this.attachmentKey=r,this.constructInstance=i,this.attachmentStorage=new lt(t.instanceData,r)}async getInstance(t){if(await this.attachmentStorage.getItem(t))return this.constructInstance(new lt(this.attachmentStorage,t))}async create(t,r){return await this.attachmentStorage.setItem(t,r),this.constructInstance(new lt(this.attachmentStorage,t))}async remove(t){await this.attachmentStorage.deleteItem(t)}async list(){const t=await this.attachmentStorage.getItem(null);return Promise.all(v.values(t).map(r=>this.constructInstance(new lt(this.attachmentStorage,r.id))))}}class Ni{constructor(t){P(this,"rootRef");this.rootRef=ae.observable({current:t})}async deleteItem(t){ae.runInAction(()=>{v.unset(this.rootRef.current,[t])})}getItem(t){const r=this.getValueFromRoot(t);return Promise.resolve(r)}getValueFromRoot(t){return t===null?ae.toJS(this.rootRef.current):v.get(this.rootRef.current,[t])}setItem(t,r){if(t===null)if(v.isObject(r))ae.runInAction(()=>{this.rootRef.current=r});else throw new Error("Cannot set root value to non-object");else ae.runInAction(()=>{v.set(this.rootRef.current,[t],r)});return Promise.resolve(this.getItem(t))}watchItem(t,r,i){return ae.reaction(()=>this.getValueFromRoot(t),(s,o)=>{r(s,o)},{requiresObservable:!0,fireImmediately:v.get(i,"fireImmediately",!1)})}}class Go{constructor(){P(this,"channels",new Map);P(this,"globalChannel",new Si)}getChannel(t){const r=this.channels.get(t);if(r)return r;const i=new Si;return this.channels.set(t,i),i}}class qo{constructor(t){P(this,"instances",new Map);this.pluginManager=t}get availableVizList(){return this.pluginManager.installedPlugins.flatMap(t=>t.manifest.viz)}resolveComponent(t){return this.pluginManager.factory.viz(t)}getOrCreateInstance(t){const r=this.instances.get(t.id);if(r)return r;const i={id:t.id,name:t.viz.type,type:t.viz.type,messageChannels:new Go,instanceData:new Ni(t.viz.conf)};return this.instances.set(t.id,i),i}}function Gi(e,t,r,i){return{vizManager:r,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new Ni({}),colorPalette:{getColor(){return()=>""}},data:t,variables:i}}const Fo=e=>{const{panel:t,vizManager:r,data:i,variables:s}=e,o=r.resolveComponent(t.viz.type),u=r.getOrCreateInstance(t),l={...Gi(u,i,r,s),viewport:{width:t.layout.w,height:t.layout.h}},d=o.viewRender;return n(d,{context:l,instance:u,...v.omit(e,["panel","vizManager","data"])})},Wo=e=>{const{vizManager:t,panel:r,panelInfoEditor:i,data:s,variables:o}=e,u=t.resolveComponent(r.viz.type),l=t.getOrCreateInstance(r),d={...Gi(l,s,t,o),panelInfoEditor:i},c=u.configRender;return n(c,{context:d,instance:l,...v.omit(e,["panel","vizManager","data","panelInfoEditor"])})},qi=(e,t)=>{const r=We.bezier(e),i=We.bezier(t);return function(s){return s<50?r(s*2/100).hex():i((s-50)*2/100).hex()}},Ft=e=>{const t=We.bezier(e);return function(r){return t(r/100).hex()}},jo={type:"interpolation",displayName:"Red / Green",getColor:qi(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},Yo={type:"interpolation",displayName:"Yellow / Blue",getColor:qi(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},Ro={type:"interpolation",displayName:"Red",getColor:Ft(["#fff7f1","darkred"]),name:"red",category:"sequential"},Qo={type:"interpolation",displayName:"Green",getColor:Ft(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},Uo={type:"interpolation",displayName:"Blue",getColor:Ft(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},Xo={type:"interpolation",displayName:"Orange",getColor:Ft(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"},Fi="@devtable/dashboard",_n="8.64.0",Wi="Apache-2.0",ji={access:"public",registry:"https://registry.npmjs.org/"},Yi=["dist"],Ri="./dist/dashboard.umd.js",Qi="./dist/dashboard.es.js",Ui="./dist/index.d.ts",Xi={".":{import:"./dist/dashboard.es.js",require:"./dist/dashboard.umd.js"},"./dist/style.css":{import:"./dist/style.css",require:"./dist/style.css"}},Zi={"dev-build":"tsc && vite build --watch",build:"tsc && vite build",preview:"vite preview",test:"vitest","test:ui":"vitest --ui",coverage:"vitest --coverage"},Ki={"@monaco-editor/react":"4.4.6","@types/chroma-js":"^2.1.4","file-saver":"2.0.5",mathjs:"11.8.0","monaco-editor":"0.36.0","performant-array-to-tree":"1.11.0",popmotion:"^11.0.3","rc-tree-select":"5.5.5",reactflow:"^11.5.3"},Ji={"@emotion/babel-plugin":"11.10.6","@faker-js/faker":"7.6.0","@mantine/core":"5.9.5","@mantine/dates":"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":"^9.0.0","@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.3","@tiptap/extension-color":"2.0.3","@tiptap/extension-highlight":"2.0.3","@tiptap/extension-link":"2.0.3","@tiptap/extension-placeholder":"2.0.3","@tiptap/extension-subscript":"2.0.3","@tiptap/extension-superscript":"2.0.3","@tiptap/extension-table":"2.0.3","@tiptap/extension-table-cell":"2.0.3","@tiptap/extension-table-header":"2.0.3","@tiptap/extension-table-row":"2.0.3","@tiptap/extension-text-align":"2.0.3","@tiptap/extension-text-style":"2.0.3","@tiptap/extension-underline":"2.0.3","@tiptap/pm":"2.0.3","@tiptap/react":"2.0.3","@tiptap/starter-kit":"2.0.3","@types/crypto-js":"v4.1.1","@types/d3-array":"3.0.4","@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.12.0",axios:"^0.27.2","crypto-js":"^4.1.1",cypress:"^12.9.0","cypress-wait-until":"^1.7.2",echarts:"^5.3.2","echarts-for-react":"^3.0.2","echarts-gl":"^2.0.9",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","vite-plugin-static-copy":"0.13.1"},Hi={"@emotion/react":"11.10.6","@faker-js/faker":"7.6.0","@mantine/core":"5.9.5","@mantine/dates":"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.3","@tiptap/extension-color":"2.0.3","@tiptap/extension-highlight":"2.0.3","@tiptap/extension-link":"2.0.3","@tiptap/extension-placeholder":"2.0.3","@tiptap/extension-subscript":"2.0.3","@tiptap/extension-superscript":"2.0.3","@tiptap/extension-table":"2.0.3","@tiptap/extension-table-cell":"2.0.3","@tiptap/extension-table-header":"2.0.3","@tiptap/extension-table-row":"2.0.3","@tiptap/extension-text-align":"2.0.3","@tiptap/extension-text-style":"2.0.3","@tiptap/extension-underline":"2.0.3","@tiptap/pm":"2.0.3","@tiptap/react":"2.0.3","@tiptap/starter-kit":"2.0.3",ahooks:"^3.3.11",axios:"^0.27.2","chroma-js":"^2.4.2","crypto-js":"^4.1.1","d3-array":"3.2.3","d3-regression":"1.3.10",dayjs:"1.11.7",echarts:"^5.3.2","echarts-for-react":"^3.0.2","echarts-gl":"^2.0.9",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-router-dom":"^6.3.0","react-virtual":"^2.10.4","tabler-icons-react":"^1.48.0"},Zo=Object.freeze(Object.defineProperty({__proto__:null,default:{name:Fi,version:_n,license:Wi,publishConfig:ji,files:Yi,main:Ri,module:Qi,types:Ui,exports:Xi,scripts:Zi,dependencies:Ki,devDependencies:Ji,peerDependencies:Hi},dependencies:Ki,devDependencies:Ji,exports:Xi,files:Yi,license:Wi,main:Ri,module:Qi,name:Fi,peerDependencies:Hi,publishConfig:ji,scripts:Zi,types:Ui,version:_n},Symbol.toStringTag,{value:"Module"}));class Ko{constructor(t){P(this,"staticColors",new Map);P(this,"interpolations",new Map);t.installedPlugins.forEach(r=>{r.manifest.color.forEach(i=>{this.register(i)})})}getStaticColors(){return Array.from(this.staticColors.values())}register(t){const r=this.encodeColor(t);t.type==="single"?(this.staticColors.has(r)&&console.warn(`the color '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.staticColors.set(r,t)):t.type==="interpolation"&&(this.interpolations.has(r)&&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(r,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 Jo{constructor(){P(this,"plugins",new Map);P(this,"vizComponents",new Map);P(this,"factory",{viz:t=>{const r=this.vizComponents.get(t);if(r)return r;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 r of t.manifest.viz){if(this.vizComponents.has(r.name))throw new Error(`Viz Component (${r.name}) has been installed before`);this.vizComponents.set(r.name,r)}}get installedPlugins(){return Array.from(this.plugins.values())}}class Ho{constructor(){P(this,"migrations",[])}version(t,r){return this.migrations.push({version:t,handler:r}),this}run(t,r,i){var u;if(t.from===t.to)return r;if(t.from>t.to)throw new Error(`Can not downgrade from version '${t.from}' to (${t.to})`);const s=this.migrations.filter(l=>l.version>t.from&&l.version<=t.to),o=v.orderBy(s,"version","asc");if(((u=v.last(o))==null?void 0:u.version)!==t.to)throw new Error(`Migration to version ${t.to} not found`);return o.reduce((l,d)=>d.handler(l,i),r)}}class he extends Ho{constructor(){super(),this.configVersions()}version(t,r){return super.version(t,(i,s)=>({version:t,...r(i,s)}))}async migrate({configData:t,panelModel:r}){const i=await t.getItem(null),s=v.get(i,"version",0),o=this.run({from:s,to:this.VERSION},i,{panelModel:r});await t.setItem(null,o)}async needMigration({configData:t}){const r=await t.getItem(null);return v.get(r,"version",0)<this.VERSION}}const W=(e,t)=>{const[r,{setFalse:i}]=Z.useBoolean(!0),[s,o]=b.useState();b.useEffect(()=>(e.getItem(t).then(l=>{o(l),i()}),e.watchItem(t,l=>{o(l)})));const u=b.useCallback(async l=>{await e.setItem(t,l),o(l)},[e,t]);return{loading:r,value:s,set:u}},Sn={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"}};le.use([B.GridComponent,B.VisualMapComponent,B.LegendComponent,B.TooltipComponent,De.CanvasRenderer]);function el({context:e}){const{value:t}=W(e.instanceData,"config"),r=e.data,{width:i,height:s}=e.viewport,{x_axis_data_key:o,y_axis_data_key:u,z_axis_data_key:l,xAxis3D:d,yAxis3D:c,zAxis3D:f}=v.defaults({},t,Sn),g=b.useMemo(()=>{const w=v.minBy(r,C=>C[l]);return v.get(w,l)},[r,l]),h=b.useMemo(()=>{const w=v.maxBy(r,C=>C[l]);return v.get(w,l)},[r,l]),m={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:g,max:h,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:d,yAxis3D:c,zAxis3D:f,grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}},series:[{type:"bar3D",wireframe:{},data:r.map(w=>[w[o],w[u],w[l]])}]};return t?n(Me,{echarts:le,option:m,style:{width:i,height:s},notMerge:!0,theme:"merico-light"}):null}function tl({label:e,required:t,value:r,onChange:i,data:s,clearable:o=!1,sx:u,...l},d){const c=b.useMemo(()=>{if(!Array.isArray(s)||s.length===0)return[];const g=Object.keys(s[0]).map(h=>({label:h,value:h}));return o?g.concat([{label:"unset",value:""}]):g},[s]);return n(a.Select,{ref:d,label:e,data:c,value:r,onChange:i,required:t,sx:u,...l})}const Y=b.forwardRef(tl);function nl({context:e}){const{value:t,set:r}=W(e.instanceData,"config"),i=e.data,s=v.defaults({},t,Sn),{control:o,handleSubmit:u,reset:l}=x.useForm({defaultValues:s});return b.useEffect(()=>{l(s)},[t]),t?n(a.Stack,{spacing:"xs",children:p("form",{onSubmit:u(r),children:[n(a.Text,{children:"X Axis"}),p(a.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[n(x.Controller,{name:"x_axis_data_key",control:o,render:({field:d})=>n(Y,{label:"Data Field",required:!0,data:i,...d})}),n(x.Controller,{name:"xAxis3D.name",control:o,render:({field:d})=>n(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...d})})]}),n(a.Text,{mt:"lg",children:"Y Axis"}),p(a.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[n(x.Controller,{name:"y_axis_data_key",control:o,render:({field:d})=>n(Y,{label:"Data Field",required:!0,data:i,...d})}),n(x.Controller,{name:"yAxis3D.name",control:o,render:({field:d})=>n(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...d})})]}),n(a.Text,{mt:"lg",children:"Z Axis"}),p(a.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[n(x.Controller,{name:"z_axis_data_key",control:o,render:({field:d})=>n(Y,{label:"Data Field",required:!0,data:i,...d})}),n(x.Controller,{name:"zAxis3D.name",control:o,render:({field:d})=>n(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...d})})]}),n(a.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:p(a.Button,{color:"blue",type:"submit",children:[n(k.DeviceFloppy,{size:20}),n(a.Text,{ml:"md",children:"Save"})]})})]})}):null}class rl extends he{constructor(){super(...arguments);P(this,"VERSION",1)}configVersions(){this.version(1,r=>({version:1,config:r}))}}const il={displayName:"Bar Chart (3D)",displayGroup:"ECharts-based charts",migrator:new rl,name:"bar-3d",viewRender:el,configRender:nl,createConfig(){return{version:1,config:v.cloneDeep(Sn)}}},Ie={mantissa:0,output:"number",trimMantissa:!1,average:!1};function al({value:e,onChange:t},r){const i=l=>{t({...e,output:l})},s=l=>{const d=l===0?!1:e.trimMantissa;t({...e,mantissa:l,trimMantissa:d})},o=l=>{t({...e,trimMantissa:l.currentTarget.checked})},u=l=>{t({...e,average:l.currentTarget.checked})};return p(a.Stack,{ref:r,children:[p(a.Group,{grow:!0,children:[n(a.Select,{label:"Format",data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:e.output,onChange:i,sx:{flexGrow:1}}),n(a.Switch,{label:p(a.Stack,{spacing:0,children:[n(a.Text,{children:"Average"}),n(a.Text,{size:12,color:"gray",children:"like 1.234k, 1.234m"})]}),checked:e.average,onChange:u,disabled:e.output!=="number",sx:{flexGrow:1},styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}}})]}),p(a.Group,{grow:!0,children:[n(a.NumberInput,{label:"Mantissa",defaultValue:0,min:0,step:1,max:4,value:e.mantissa,onChange:s}),n(a.Switch,{label:"Trim mantissa",checked:e.trimMantissa,onChange:o,disabled:e.mantissa===0,styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"}}})]}),p(a.Stack,{spacing:0,children:[n(a.Text,{weight:"bold",children:"Preview"}),n($e,{children:p(a.Group,{position:"apart",children:[p(a.Text,{size:12,color:"gray",children:["123456789 ",n(k.ArrowRight,{size:9})," ",se(123456789).format(e)]}),p(a.Text,{size:12,color:"gray",children:["1234 ",n(k.ArrowRight,{size:9})," ",se(1234).format(e)]}),p(a.Text,{size:12,color:"gray",children:["0.1234 ",n(k.ArrowRight,{size:9})," ",se(.1234).format(e)]})]})})]})]})}const Be=b.forwardRef(al),Ne={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
28
28
  `)},ea={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:ol,configRender:sl,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 sl(e){return n(O,{})}function ol(e){return n(a.Text,{children:"Click chart's series"})}const ll=[{label:"Truncate",value:"truncate"},{label:"Break Line",value:"break"},{label:"Break Word",value:"breakAll"}],Wt=b.forwardRef(({sectionTitle:e,value:t,onChange:r},i)=>{const s=o=>u=>{const l=v.cloneDeep(t);v.set(l,o,u),r(l)};return p(a.Stack,{spacing:0,children:[e&&n(a.Divider,{mb:-5,mt:5,variant:"dotted",label:e,labelPosition:"right",labelProps:{color:"dimmed"}}),p(a.Group,{grow:!0,noWrap:!0,children:[n(a.NumberInput,{label:"Max Width",hideControls:!0,value:t.width,onChange:s("width")}),n(a.Select,{label:"Overflow",data:ll,value:t.overflow,onChange:s("overflow")}),n(a.TextInput,{label:"Ellipsis",value:t.ellipsis,disabled:!0})]})]})}),rt=b.forwardRef(({value:e,onChange:t},r)=>{const i=o=>{t({...e,on_axis:o})},s=o=>{t({...e,in_tooltip:o})};return p(a.Stack,{ref:r,spacing:0,children:[n(Wt,{sectionTitle:"Overflow on Axis",value:e.on_axis,onChange:i}),n(Wt,{sectionTitle:"Overflow in Tooltip",value:e.in_tooltip,onChange:s})]})}),Ye={on_axis:{width:80,overflow:"truncate",ellipsis:"..."},in_tooltip:{width:200,overflow:"break",ellipsis:"..."}};function Ke({overflow:e,width:t}){const r={truncate:"initial",break:"break-all",breakAll:"break-word"}[e],i=e==="truncate"?"nowrap":"initial",s={truncate:"ellipsis",break:"clip",breakAll:"clip"}[e];return`
29
29
  max-width: ${t}px;
30
30
  word-break: ${r};
@@ -344,7 +344,7 @@ Check the top-level render call using <`+E+">.")}return M}}function eo(_,M){{if(
344
344
  </tbody>
345
345
  </table>
346
346
  `}},show_in_legend:!0}))}function Rm(e,t,r,i){const s=t.data_key,o=t.name,u=r.map(l=>{const d=v.sumBy(i[l],s);return[l,d]});return{type:"line",name:o,xAxisIndex:3,yAxisIndex:3,color:"#b41529",data:u,show_in_legend:!1}}function Qm(e,t,r,i){const u={barMinWidth:5,barMaxWidth:20};return[qm(e,r,i),Wm(e,r,i,u),...Ym(e,r,i,u),Rm(e,t,r,i)]}function Um({enabled:e,func_content:t}){return(r,i)=>{if(!e)return r;try{return new Function(`return ${t}`)()(r,i)}catch(s){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${s.message}`),r}}}function Xm(e,t){const{axisLabel:r}=e.x_axis;return[{data:t,id:"准确估算比例",gridIndex:0,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:t,id:"平均偏差",gridIndex:1,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!0,lineStyle:{color:"#FFFFFF",width:2}},type:"category"},{data:t,id:"数量占比",gridIndex:2,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:t,id:"代码当量",gridIndex:3,axisTick:{show:!1},type:"category",axisLabel:{...r,formatter:Um(r.formatter)},axisLine:{show:!1}}]}function Zm(e){return[{type:"category",name:"准确估算比例",nameRotate:0,nameGap:5,nameLocation:"end",nameTextStyle:{align:"left"},gridIndex:0,axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:"平均偏差",nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:1,boundaryGap:[1,1],axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:"数量占比",nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:2,axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1},min:0,max:1},{type:"value",gridIndex:3,position:"right",splitNumber:3,axisLabel:{show:!0,verticalAlign:"top",showMinLabel:!1,lineHeight:14},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:e.name,nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:3,position:"left",axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}}]}function tr(e){return e==1||e==2?1:tr(e-2)+tr(e-1)}const Km=Array.from(new Array(20),(e,t)=>tr(t+1));function La(e){return e<=1?e:Km.findIndex(t=>e<=t)-1}function Jm(e,t){const{estimated_value:r,actual_value:i}=e.deviation.data_keys;return t.map(s=>{const o=La(s[r]),u=La(s[i]),l=o-u;return{...s,level:{estimated:o,actual:u,diff:l}}})}function Hm(e){return e==="rgba(255, 255, 255, 1)"?{borderColor:"rgba(0,0,0,.1)",borderWidth:1}:{}}function eb(e){return{show:!0,orient:"vertical",top:"middle",right:0,data:e.filter(r=>r.show_in_legend).reverse().map(r=>({name:`${r.name}`,color:r.color,itemStyle:Hm(r.color)})),tooltip:{show:!0,formatter:"档位偏差:{a}"}}}const tb={tooltip:{trigger:"axis"}};function nb(e,t){const{deviation:r,metrics:i}=e,s=i.find(u=>u.data_key===t);if(s)return s;const o=r.data_keys.actual_value;return{id:o,name:r.name,data_key:o}}function rb(e,t,r){const i=Jm(e,r),s=v.uniqBy(r,e.x_axis.data_key).map(c=>c[e.x_axis.data_key]),o=v.groupBy(i,e.x_axis.data_key),u=nb(e,t),l=Qm(e,u,s,o),d={xAxis:Xm(e,s),yAxis:Zm(u),series:l,grid:Gm(),visualMap:[{min:0,max:1,calculable:!0,show:!1,seriesIndex:0,color:["#F0F0F0","#418AAF"]}],legend:eb(l)};return v.defaultsDeep({},d,tb)}const Pa={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
347
- `)},nr={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...Pa}}},deviation:{name:"",data_keys:{estimated_value:"",actual_value:""}},metrics:[]},ib={input:{border:"none !important",paddingLeft:0,lineHeight:"1.55 !important"}},ab=({conf:e,metricKey:t,setMetricKey:r})=>{const{deviation:i,metrics:s}=e,o=b.useMemo(()=>{const u=s.map(l=>({label:l.name,value:l.data_key}));return u.push({label:i.name?i.name:i.data_keys.actual_value,value:i.data_keys.actual_value}),u},[i,s]);return p(a.Group,{spacing:1,children:[n(a.Text,{size:12,color:"dimmed",sx:{cursor:"default",userSelect:"none"},children:"基线指标"}),n(a.NativeSelect,{size:"xs",data:o,value:t,onChange:u=>r(u.currentTarget.value),styles:ib})]})},sb={"tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function ob(){return p(a.HoverCard,{width:400,shadow:"md",children:[n(a.HoverCard.Target,{children:n(a.Button,{size:"xs",variant:"subtle",compact:!0,leftIcon:n(V.IconInfoCircle,{size:14}),children:"指标说明"})}),n(a.HoverCard.Dropdown,{children:n(a.Table,{fontSize:14,sx:sb,children:p("tbody",{children:[p("tr",{children:[n("th",{children:"估算偏差"}),n("td",{children:"使用斐波那契数列(1,2,3,5,8,13)估算故事点,每个数位为一个档位,计算issue实际故事点与估算故事点的档位偏差,即为估算偏差。如估算故事点为5,实际故事点为8,则估算偏差为-1。"})]}),p("tr",{children:[n("th",{children:"准确估算比例"}),n("td",{children:"偏差在 ± 1 档位内的 issue 均为准确估算,以此计算准确估算的比例。"})]})]})})})]})}function lb(e){return p(a.Group,{position:"apart",children:[n(ob,{}),n(ab,{...e})]})}le.use([de.BarChart,de.LineChart,de.HeatmapChart,B.GridComponent,B.LegendComponent,B.TooltipComponent,De.CanvasRenderer,B.VisualMapComponent]);function ub({conf:e,data:t,width:r,height:i,metricKey:s}){const o=b.useMemo(()=>rb(e,s,t),[e,t,s]);return!r||!i?null:n(Me,{echarts:le,option:o,style:{width:r,height:i},notMerge:!0,theme:"merico-light"})}function db({context:e}){const{value:t}=W(e.instanceData,"config"),r=b.useMemo(()=>v.defaults({},t,nr),[t]),i=e.data,{width:s,height:o}=e.viewport,{x_axis:u,deviation:l}=r,{estimated_value:d,actual_value:c}=l.data_keys,[f,g]=b.useState(c);if(b.useEffect(()=>{g(w=>w||c)},[c]),!u.data_key||!d||!c)return null;const h=Math.max(s,300),m=Math.max(o,370);return p(a.Box,{sx:{overflow:"hidden",height:m,width:h},children:[n(lb,{conf:r,metricKey:f,setMetricKey:g}),n(ub,{width:h,height:m-30,data:i,conf:r,metricKey:f})]})}const cb=({disabled:e,value:t,onChange:r})=>{const i=s=>{s&&r(s)};return p(a.Box,{sx:{position:"relative"},children:[e&&n(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),n(_e,{height:"500px",defaultLanguage:"javascript",value:t,onChange:i,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},pb=b.forwardRef(({value:e,onChange:t},r)=>{const[i,{setTrue:s,setFalse:o}]=Z.useBoolean(),[u,l]=b.useState(e);b.useEffect(()=>{l(e)},[e]);const d=m=>{l({...u,enabled:m})},c=()=>{o();const{enabled:m,func_content:w}=u,C={enabled:m,func_content:w};l(C),t(C)},f=()=>{o(),l(e)},g=m=>{l(w=>({...w,func_content:m}))},h=()=>{g(Pa.func_content)};return p(O,{children:[n(a.Button,{variant:"filled",mt:24,onClick:s,sx:{flexGrow:0},children:"Customize Label"}),n(a.Modal,{size:800,title:"Customize label content",opened:i,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:i&&p(a.Stack,{children:[n(a.Checkbox,{mt:10,label:"Enabled",checked:u.enabled,onChange:m=>d(m.currentTarget.checked)}),n(cb,{value:u.func_content,onChange:g,disabled:!u.enabled}),p(a.Group,{position:"apart",children:[n(a.Button,{onClick:h,color:"red",leftIcon:n(k.Recycle,{size:20}),children:"Rest"}),p(a.Group,{position:"right",children:[n(a.Button,{onClick:f,variant:"subtle",children:"Cancel"}),n(a.Button,{onClick:c,children:"OK"})]})]})]})})]})});function hb({data:e,control:t,watch:r}){return r(["x_axis"]),p(a.Stack,{children:[p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:"x_axis.data_key",control:t,render:({field:i})=>n(Y,{label:"数据字段",required:!0,data:e,sx:{flex:1},...i})}),n(x.Controller,{name:"x_axis.name",control:t,render:({field:i})=>n(a.TextInput,{label:"X轴名称",sx:{flex:1},...i})})]}),n(a.Divider,{mb:-15,label:"点位文案",labelPosition:"center"}),p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:i})=>n(a.NumberInput,{label:"旋转",hideControls:!0,min:-90,max:90,rightSection:n(a.Text,{color:"dimmed",children:"度"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...i})}),n(x.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:i})=>n(pb,{data:e,...i})})]})]})}function fb({data:e,control:t,watch:r}){return r(["deviation"]),p(a.Stack,{children:[n(a.Group,{grow:!0,noWrap:!0,children:n(x.Controller,{name:"deviation.name",control:t,render:({field:i})=>n(a.TextInput,{label:"指标名称",sx:{flex:1},...i})})}),p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:"deviation.data_keys.estimated_value",control:t,render:({field:i})=>n(Y,{label:"估算值字段",required:!0,data:e,sx:{flex:1},...i})}),n(x.Controller,{name:"deviation.data_keys.actual_value",control:t,render:({field:i})=>n(Y,{label:"实际值字段",required:!0,data:e,sx:{flex:1},...i})})]})]})}const gb=({control:e,data:t,index:r,remove:i})=>p(a.Stack,{children:[p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:`metrics.${r}.name`,control:e,render:({field:s})=>n(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...s})}),n(x.Controller,{name:`metrics.${r}.data_key`,control:e,render:({field:s})=>n(Y,{label:"Value Field",required:!0,data:t,sx:{flex:1},...s})})]}),n(a.Divider,{mb:-10,mt:10,variant:"dashed"}),n(a.Button,{leftIcon:n(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>i(r),sx:{top:15,right:5},children:"Delete this Metric"})]}),mb=({control:e,watch:t,data:r})=>{const{fields:i,append:s,remove:o}=x.useFieldArray({control:e,name:"metrics"}),u=t("metrics"),l=i.map((h,m)=>({...h,...u[m]})),d=()=>s({id:Date.now().toString(),data_key:"",name:""}),c=t("metrics.0.id"),[f,g]=b.useState(()=>c??null);return b.useEffect(()=>{c&&g(h=>h!==null?h:c)},[c]),p(O,{children:[p(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[n(k.InfoCircle,{size:14,color:"#888"}),n(a.Text,{size:14,color:"#888",children:"设置可以展示在基线图的指标,例如代码当量"})]}),n(a.Divider,{variant:"dashed",my:10}),p(a.Tabs,{value:f,onTabChange:h=>g(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(a.Tabs.List,{children:[l.map((h,m)=>n(a.Tabs.Tab,{value:h.id,children:h.name?h.name:m},h.id)),n(a.Tabs.Tab,{onClick:d,value:"add",children:n(k.Plus,{size:18,color:"#228be6"})})]}),l.map((h,m)=>n(a.Tabs.Panel,{value:h.id,children:n(gb,{control:e,index:m,remove:o,data:r},h.id)},h.id))]})]})};function bb({context:e}){const{value:t,set:r}=W(e.instanceData,"config"),i=e.data,s=b.useMemo(()=>v.defaultsDeep({},t,nr),[t]),{control:o,handleSubmit:u,watch:l,getValues:d,reset:c}=x.useForm({defaultValues:s});b.useEffect(()=>{c(s)},[s]),l([]);const f=d(),g=b.useMemo(()=>!v.isEqual(f,s),[f,s]);return n(a.Stack,{spacing:"xs",children:p("form",{onSubmit:u(r),children:[p(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[n(a.Text,{children:"Merico Estimation Chart Config"}),n(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!g,children:n(k.DeviceFloppy,{size:20})})]}),p(a.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"12px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(a.Tabs.List,{children:[n(a.Tabs.Tab,{value:"X Axis",children:"X 轴"}),n(a.Tabs.Tab,{value:"Deviation",children:"偏差"}),n(a.Tabs.Tab,{value:"Additional Metrics",children:"指标"})]}),n(a.Tabs.Panel,{value:"X Axis",children:n(hb,{control:o,watch:l,data:i})}),n(a.Tabs.Panel,{value:"Deviation",children:n(fb,{control:o,watch:l,data:i})}),n(a.Tabs.Panel,{value:"Additional Metrics",children:n(mb,{control:o,watch:l,data:i})})]})]})})}class yb extends he{constructor(){super(...arguments);P(this,"VERSION",1)}configVersions(){this.version(1,r=>({version:1,config:r}))}}const vb={displayName:"Merico Estimation Chart",displayGroup:"Merico suite",migrator:new yb,name:"mericoEstimationChart",viewRender:db,configRender:bb,createConfig:()=>({version:1,config:nr})},xb=[{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"})),Cb=[jo,Yo,Uo,Qo,Ro,Xo],Oa=()=>({id:"dashboard",version:_n,manifest:{viz:[Un,Hh,vg,Bp,Cf,op,Nm,il,Rl,Zd,Sc,em,np,Md,Yh,_p,Ep,Dg,vb,su],color:[...xb,...Cb]}}),Mt=new Jo,me={pluginManager:je("pluginManager"),vizManager:je("vizManager"),colorManager:je("colorManager"),instanceScope:{panelModel:je("panelModel"),vizInstance:je("vizInstance"),interactionManager:je("interactionManager"),migrator:je("migrator"),operationManager:je("operationManager"),triggerManager:je("triggerManager")}},rr=()=>{try{Mt.install(Oa())}catch{}const e=new qo(Mt),t=new Ko(Mt);return{pluginManager:Mt,vizManager:e,colorManager:t}},Ge=b.createContext(rr());try{Mt.install(Oa())}catch{}function wb(e,t){const{value:r,set:i}=W(e.operation.operationData,"config"),[s,o]=b.useState(v.defaults({},r,t)),u=async()=>{await i(s)};return b.useEffect(()=>{o(v.defaults({},r,t))},[r]),{config:s,setConfig:o,commit:u}}function _b(e){const{config:t,setConfig:r,commit:i}=wb(e,{urlTemplate:"",openInNewTab:!0});async function s(){await i()}async function o(l){r({...t,openInNewTab:l}),await i()}const u=l=>r({...t,urlTemplate:l.currentTarget.value});return p(a.Stack,{children:[n(a.TextInput,{label:"Url",value:t.urlTemplate,onChange:u,onBlur:s}),n(a.Switch,{label:"Open in new Tab",checked:t.openInNewTab,onChange:l=>o(l.currentTarget.checked)})]})}async function Sb(e,t){const{urlTemplate:r,openInNewTab:i}=await t.operationData.getItem("config");window.dispatchEvent(new CustomEvent("open-link",{detail:{urlTemplate:r,openInNewTab:i,payload:e}}))}class Tb extends he{constructor(){super(...arguments);P(this,"VERSION",1)}configVersions(){this.version(1,r=>r)}}const kb={displayName:"Open Link",id:"builtin:op:open-link",configRender:_b,run:Sb,migrator:new Tb,createDefaultConfig:()=>({version:1,config:{urlTemplate:"",openInNewTab:!0}})};function Db(e){const{value:t,set:r}=W(e.operationData,"config"),i=s=>void r({template:s});return[(t==null?void 0:t.template)||"",i]}function Mb(e){const[t,r]=Db(e.operation);return n(a.TextInput,{defaultValue:t,onBlur:i=>r(i.currentTarget.value),label:"console.log"})}async function Ib(e,t){const r=await t.operationData.getItem("config"),i=v.template(r.template||"");console.log("run with payload",e),console.log(i(e))}const Ab={displayName:"console.log (debug)",id:"builtin:op:debug",configRender:Mb,run:Ib},$b=T.observer(e=>{const t=F(),{value:r,set:i}=W(e.operation.operationData,"config");console.log({value:r,viewID:r==null?void 0:r.viewID});const s=(r==null?void 0:r.viewID)||"",o=u=>void i({viewID:u});return n(a.Select,{defaultValue:s,value:s,onChange:o,label:"View",data:t.views.options})});async function zb(e,t){const i=(await t.operationData.getItem("config")).viewID;window.dispatchEvent(new CustomEvent("open-view",{detail:{viewID:i}}))}const Eb={displayName:"Open View",id:"builtin:op:open_view",configRender:$b,run:zb},Lb={dictionary:{}},Pb=T.observer(e=>{const t=F(),{value:r=Lb,set:i}=W(e.operation.operationData,"config"),{dictionary:s={}}=r,o=(d,c)=>{i({dictionary:{...s,[d]:c}})},u=()=>{o(t.filters.firstFilterValueKey,"")},l=d=>{const c={...s};delete c[d],i({dictionary:c})};return p(a.Stack,{spacing:10,children:[n(a.Text,{children:"Mapping Rules"}),Object.entries(s).map(([d,c])=>p(a.Flex,{justify:"space-between",gap:10,children:[n(a.TextInput,{label:"Payload key",value:c,onChange:f=>{o(d,f.currentTarget.value)},sx:{flexGrow:1}}),n(Y,{data:[t.filters.values],value:d,onChange:f=>{o(f,c)},label:"Filter key",sx:{flexGrow:1}}),n(a.ActionIcon,{onClick:()=>l(d),sx:{marginTop:"26px",flexGrow:0},children:n(k.Trash,{size:14,color:"red"})})]},d)),n(a.Button,{size:"xs",onClick:u,sx:{alignSelf:"center",width:"300px"},children:"Add one mapping rule"})]})});async function Ob(e,t){const i=(await t.operationData.getItem("config")).dictionary;window.dispatchEvent(new CustomEvent("set-filter-values",{detail:{dictionary:i,payload:e}}))}const Vb={displayName:"Set Filter Values",id:"builtin:op:set_filter_values",configRender:Pb,run:Ob},Bb={filter_keys:[]},Nb=T.observer(e=>{const t=F(),{value:r=Bb,set:i}=W(e.operation.operationData,"config"),{filter_keys:s=[]}=r,o=l=>{i({filter_keys:[...l]})},u=b.useMemo(()=>t.filters.current.map(l=>({label:l.label,value:l.key})),[t.filters.values]);return n(a.Stack,{spacing:10,children:n(a.MultiSelect,{label:"Select Filters to Clear",data:u,value:s,onChange:o})})});async function Gb(e,t){const i=(await t.operationData.getItem("config")).filter_keys;window.dispatchEvent(new CustomEvent("clear-filter-values",{detail:{filter_keys:i,payload:e}}))}const Ht=[Ab,kb,Eb,Vb,{displayName:"Clear Filter Values",id:"builtin:op:clear_filter_values",configRender:Nb,run:Gb}];class qb{constructor(t,r=Ht){P(this,"attachments");this.operations=r;const i=async s=>{const{id:o,schemaRef:u}=await s.getItem(null);return{id:o,schemaRef:u,operationData:new lt(s,"data")}};this.attachments=new wn(t,"__OPERATIONS",i)}async runOperation(t,r){const i=await this.attachments.getInstance(t);if(!i){console.warn(`Operation '${t}' is not defined`);return}const s=this.tryGetSchema(i.schemaRef);if(!s){console.warn(`Operation schema '${i.schemaRef}' is not defined`);return}await s.run(r,i)}tryGetSchema(t){return this.operations.find(r=>r.id===t)}async needMigration(){const r=(await this.attachments.list()).map(async i=>{const s={configData:i.operationData},o=this.tryGetSchema(i.schemaRef),u=o==null?void 0:o.migrator;return u&&await u.needMigration(s)});return(await Promise.all(r)).some(i=>i)}async runMigration(){const r=(await this.attachments.list()).map(async i=>{const s={configData:i.operationData},o=this.tryGetSchema(i.schemaRef),u=o==null?void 0:o.migrator;u&&await u.needMigration(s)&&await u.migrate(s)});await Promise.all(r)}async createOrGetOperation(t,r){var u;if(!this.getOperationSchemaList().some(l=>l.id===r.id))throw new Error(`Operation schema '${r.id}' is not defined`);const s=await this.attachments.getInstance(t);return!s||s.schemaRef!==r.id?await this.attachments.create(t,{id:t,schemaRef:r.id,data:((u=r.createDefaultConfig)==null?void 0:u.call(r))??{}}):s}getOperationList(){return this.attachments.list()}getOperationSchemaList(){return this.operations}removeOperation(t){return this.attachments.remove(t)}async retrieveTrigger(t){return await this.attachments.getInstance(t)}}const Va="__TRIGGERS";class Fb{constructor(t,r){P(this,"attachments");this.instance=t,this.component=r;const i=async s=>{const{id:o,schemaRef:u}=await s.getItem(null);return{id:o,schemaRef:u,triggerData:new lt(s,"data")}};this.attachments=new wn(t,Va,i)}watchTriggerSnapshotList(t){return this.instance.instanceData.watchItem(Va,r=>{const i=v.values(r).map(s=>({id:v.get(s,"id"),schemaRef:v.get(s,"schemaRef"),config:ae.toJS(v.get(s,"data.config"))}));t(i)},{fireImmediately:!0})}async createOrGetTrigger(t,r,i={recreate:!1}){var l;if(!this.getTriggerSchemaList().some(d=>d.id===r.id))throw new Error(`Trigger schema '${r.id}' is not defined in component '${this.component.name}'`);const o=await this.attachments.getInstance(t);return!o||i.recreate||o.schemaRef!==r.id?await this.attachments.create(t,{id:t,schemaRef:r.id,data:((l=r==null?void 0:r.createDefaultConfig)==null?void 0:l.call(r))||{}}):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 r=(await this.getTriggerList()).map(async i=>{const s=this.getTriggerSchemaList().find(l=>l.id===i.schemaRef),o=s==null?void 0:s.migrator,u={configData:i.triggerData};return o&&await o.needMigration(u)?()=>o.migrate(u):null});return Promise.all(r).then(i=>i.filter(s=>s))}async needMigration(){return(await this.getMigrationTasks()).length>0}async runMigration(){const t=await this.getMigrationTasks();await Promise.all(t.map(r=>r()))}}class ir{constructor(t,r,i){P(this,"operationManager");P(this,"triggerManager");P(this,"attachments");this.operationManager=new qb(t,i),this.triggerManager=new Fb(t,r);const s=async o=>{const{id:u,triggerRef:l,operationRef:d}=await o.getItem(null);return{id:u,triggerRef:l,operationRef:d}};this.attachments=new wn(t,"__INTERACTIONS",s)}async addInteraction(t,r){const i=t.id,s=r.id,o=`[${i}]:[${s}]`;await this.attachments.create(o,{id:o,triggerRef:i,operationRef:s})}getInteractionList(){return this.attachments.list()}async removeInteraction(t){const r=await this.attachments.getInstance(t);if(!r)return;const{triggerRef:i,operationRef:s}=r;await this.getTriggerRefCount(i)<=1&&await this.triggerManager.removeTrigger(i),await this.getOperationRefCount(s)<=1&&await this.operationManager.removeOperation(s),await this.attachments.remove(t)}async getOperationRefCount(t){return(await this.getInteractionList()).filter(i=>i.operationRef===t).length}async getTriggerRefCount(t){return(await this.getInteractionList()).filter(i=>i.triggerRef===t).length}async runInteraction(t,r){const s=(await this.getInteractionList()).filter(o=>o.triggerRef===t);await Promise.all(s.map(async o=>{try{return await this.operationManager.runOperation(o.operationRef,r)}catch(u){console.warn(`Failed to run operation '${o.operationRef}'`,u)}}))}}const qe=({vizManager:e,instance:t})=>Z.useCreation(()=>new ir(t,e.resolveComponent(t.type),Ht),[t,e]),Ba=e=>{const{title:t="Variables",variables:r}=e,i=ve.useClipboard(),s=o=>{i.copy(o),Vt.showNotification({color:"green",message:"Copied to clipboard"})};return p(a.Paper,{withBorder:!0,p:"sm",children:[n(a.Text,{size:"xs",color:"dimmed",mb:"sm",children:t}),n(a.Stack,{style:{maxHeight:"500px"},children:r.map(o=>p(a.Text,{size:"sm",children:[p(a.Code,{color:"teal",children:["// ",o.description]}),n("br",{}),p(a.Code,{onClick:()=>s(o.name),style:{cursor:"pointer"},children:[o.name," : ",o.valueType]})]},o.name))})]})};class Wb{constructor(t,r){P(this,"operationId");P(this,"operation");P(this,"operationSchema");P(this,"variables",[]);this.operationManager=t,this.instance=r,ae.makeAutoObservable(this)}get schemaList(){return this.operationManager.getOperationSchemaList()}async configOperation(t,r){const i=await this.operationManager.retrieveTrigger(t),s=this.operationManager.getOperationSchemaList().find(o=>o.id===(i==null?void 0:i.schemaRef));ae.runInAction(()=>{this.operationId=t,this.operation=i,this.operationSchema=s,this.variables=r})}async changeSchema(t){this.operationId&&(await this.operationManager.createOrGetOperation(this.operationId,t),await this.configOperation(this.operationId,this.variables))}}function jb(e){return!!e.operationId}const Yb=T.observer(({model:e,onClick:t})=>{var i;const r=(i=e.operationSchema)==null?void 0:i.displayName;return n(a.Button,{variant:"outline",onClick:t,children:r})}),Rb=T.observer(({model:e})=>{const t={operation:e.operation,instance:e.instance,variables:[]};return b.createElement(e.operationSchema.configRender,t)});function Qb({model:e}){const t=e.schemaList,r=t.map(s=>({label:s.displayName,value:s.id}));async function i(s){await e.changeSchema(t.find(o=>o.id===s))}return n(a.Select,{label:"Operation",data:r,onChange:i,value:e.operationSchema.id})}const Ub=T.observer(e=>{const[t,{setTrue:r,setFalse:i}]=Z.useBoolean(!1),{operationManager:s,operationId:o,instance:u,variables:l}=e,d=Z.useCreation(()=>new Wb(s,u),[s,u]);return Z.useAsyncEffect(async()=>{await d.configOperation(o,l)},[o,d]),jb(d)?p(O,{children:[n(Yb,{model:d,onClick:r}),n(a.Modal,{size:600,opened:t,onClose:i,title:"Operation Settings",closeButtonLabel:"close",zIndex:320,children:p(a.Stack,{children:[n(Qb,{model:d}),n(Rb,{model:d}),n(Ba,{title:"Variables",variables:d.variables})]})})]}):null});class Xb{constructor(t,r){P(this,"triggerId");P(this,"trigger");P(this,"triggerSchema");P(this,"sampleData");this.triggerManager=t,this.instance=r,ae.makeAutoObservable(this)}get schemaList(){return this.triggerManager.getTriggerSchemaList()}async configTrigger(t,r){const i=await this.triggerManager.retrieveTrigger(t),s=this.triggerManager.getTriggerSchemaList().find(o=>o.id===(i==null?void 0:i.schemaRef));ae.runInAction(()=>{this.triggerId=t,this.trigger=i,this.triggerSchema=s,this.sampleData=r})}async changeSchema(t){this.triggerId&&(await this.triggerManager.createOrGetTrigger(this.triggerId,t),await this.configTrigger(this.triggerId,this.sampleData))}isReady(){return Zb(this)}}function Zb(e){return!!e.triggerId&&!!e.triggerSchema}function Kb(e,t){return Z.useCreation(()=>new Xb(e,t),[e,t])}const Jb=T.observer(({model:e,onClick:t})=>{const r=e.triggerSchema.nameRender,i={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return n(a.Button,{variant:"outline",onClick:t,children:b.createElement(r,i)})}),Hb=T.observer(({model:e})=>{const t=e.schemaList,r=t.map(s=>({label:s.displayName,value:s.id}));async function i(s){await e.changeSchema(t.find(o=>o.id===s))}return n(a.Select,{label:"Trigger",data:r,value:e.triggerSchema.id,onChange:i})}),ey=T.observer(({model:e})=>{const t={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return b.createElement(e.triggerSchema.configRender,t)}),ty=T.observer(e=>{const[t,{setTrue:r,setFalse:i}]=Z.useBoolean(!1),s=e.model;return p(O,{children:[n(a.Modal,{opened:t,onClose:i,title:"Setup Trigger",closeButtonLabel:"close setup",zIndex:320,children:p(a.Stack,{children:[n(Hb,{model:s}),n(ey,{model:s}),n(Ba,{title:"Payload",variables:s.triggerSchema.payload})]})}),n(Jb,{onClick:r,model:s})]})});function ny(e,t){const[r,i]=b.useState([]);return Z.useAsyncEffect(async()=>{const s=await e.getInteractionList();i(s)},[t,e]),r}const ry=T.observer(({item:e,manager:t,instance:r,sampleData:i,variables:s,onRemove:o})=>{const{triggerRef:u,operationRef:l}=e,d=Kb(t.triggerManager,r);if(Z.useAsyncEffect(async()=>{await d.configTrigger(u,i)},[d,u,i]),d.isReady()){const c=[...d.triggerSchema.payload,...s];return p(a.Group,{children:[n(ty,{model:d}),n(Ub,{instance:r,operationId:l,variables:c,operationManager:t.operationManager}),n(a.ActionIcon,{"aria-label":"delete-interaction",variant:"filled",color:"red",onClick:()=>o(e),children:n(k.Trash,{size:16})})]})}return null}),iy=e=>{const[t,r]=b.useState(0),{interactionManager:i,instance:s,sampleData:o,variables:u}=e,l=ny(i,t),d=async()=>{const h=await i.triggerManager.createOrGetTrigger(ve.randomId(),i.triggerManager.getTriggerSchemaList()[0]),m=await i.operationManager.createOrGetOperation(ve.randomId(),i.operationManager.getOperationSchemaList()[0]);await i.addInteraction(h,m),r(w=>w+1)};async function c(h){await i.removeInteraction(h.id),r(m=>m+1)}const{data:f=0,loading:g}=Z.useRequest(async()=>{try{return(await i.triggerManager.getTriggerSchemaList()).length}catch{return 0}});return p(a.Stack,{children:[n(a.LoadingOverlay,{visible:g}),f===0&&n(a.Alert,{icon:n(k.AlertCircle,{size:16}),title:"Unavailable",color:"gray",children:"This visualization does not have available interactions to choose from"}),l.map(h=>n(ry,{onRemove:c,instance:s,sampleData:o,variables:u,item:h,manager:e.interactionManager},h.id)),n(a.Button,{style:{width:"fit-content"},onClick:()=>d(),disabled:f===0,children:"Add interaction"})]})},ay=()=>{const{panel:e,data:t}=Ce(),r=e.viz,{vizManager:i}=b.useContext(Ge),s=e.json,o=Z.useCreation(()=>i.getOrCreateInstance(s),[i,s]),u=Z.useCreation(()=>new ir(o,i.resolveComponent(r.type),Ht),[o,r.type]);return b.useEffect(()=>o.instanceData.watchItem(null,v.throttle(l=>{e.viz.setConf(l)},100,{leading:!1,trailing:!0})),[o]),{instance:o,vizManager:i,interactionManager:u,sampleData:t,variables:[]}},sy=()=>{const e=ay();return n(iy,{...e})};var Na=(e=>(e.migrated="migrated",e.nothingToMigrate="nothingToMigrate",e.checkFailed="checkFailed",e.migrationFailed="migrationFailed",e))(Na||{}),en=(e=>(e.notStarted="notStarted",e.inProgress="inProgress",e.done="done",e))(en||{});class oy{constructor(t){P(this,"vizInstance");P(this,"operationManager");P(this,"triggerManager");P(this,"vizManager");P(this,"runningMigration");P(this,"panelModel");P(this,"status","notStarted");this.panelModel=t.getRequired(me.instanceScope.panelModel),this.vizInstance=t.getRequired(me.instanceScope.vizInstance),this.operationManager=t.getRequired(me.instanceScope.operationManager),this.triggerManager=t.getRequired(me.instanceScope.triggerManager),this.vizManager=t.getRequired(me.vizManager)}async createMigrationTask(){const t=[];try{await this.instanceNeedMigration()&&t.push(()=>this.runInstanceMigration()),await this.interactionNeedMigration()&&t.push(()=>this.runInteractionMigration())}catch(r){return console.warn("check migration failed",r),"checkFailed"}if(t.length===0)return"nothingToMigrate";try{return await Promise.all(t.map(r=>r())),"migrated"}catch(r){return console.warn("migration failed",r),"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),r={configData:this.vizInstance.instanceData,panelModel:this.panelModel};await t.migrator.migrate(r)}async instanceNeedMigration(){const t=this.vizManager.resolveComponent(this.vizInstance.type),r={configData:this.vizInstance.instanceData};return t.migrator.needMigration(r)}async interactionNeedMigration(){return await this.operationManager.needMigration()||await this.triggerManager.needMigration()}}function Ga(e){const{panel:t}=Ce();return b.useCallback(r=>{const i=r.getRequired(me.vizManager),s=i.resolveComponent(e.viz.type);return r.createScoped().provideFactory(me.instanceScope.vizInstance,()=>i.getOrCreateInstance(e)).provideFactory(me.instanceScope.interactionManager,o=>{const u=o.getRequired(me.instanceScope.vizInstance);return new ir(u,s,Ht)}).provideFactory(me.instanceScope.operationManager,o=>o.getRequired(me.instanceScope.interactionManager).operationManager).provideFactory(me.instanceScope.triggerManager,o=>o.getRequired(me.instanceScope.interactionManager).triggerManager).provideValue(me.instanceScope.panelModel,t).provideFactory(me.instanceScope.migrator,o=>new oy(o))},[e.viz.type,e.viz.conf])}function qa(e){const[t,r]=b.useState(!1),i=Ii().getRequired(me.instanceScope.migrator);return Z.useAsyncEffect(async()=>{const s=i.status===en.notStarted;r(i.status===en.done),i.status===en.notStarted&&i.runMigration().then(o=>{o===Na.migrated&&s&&(e==null||e())}).finally(()=>{r(!0)})},[i]),t}function Fa(e,t){const r=Ii().getRequired(me.instanceScope.vizInstance);return b.useEffect(()=>(r.instanceData.setItem(null,t.viz.conf),r.instanceData.watchItem(null,i=>{e(i)})),[e,t.viz.type]),r}function ly({setVizConf:e,...t}){const{panel:r}=t,i=Fa(e,r),s=qa(()=>{Vt.showNotification({title:`${r.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})});return Z.useAsyncEffect(async()=>{await i.instanceData.setItem(null,r.viz.conf)},[i,r.viz.type]),s?n(Wo,{...t}):n(a.Text,{children:"Checking update..."})}function uy(e){const{panel:t,setVizConf:r}=e;Fa(r,t);const{inEditMode:i}=b.useContext(Ze);return qa(()=>{i&&Vt.showNotification({title:`${t.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?n(Fo,{...e}):n(a.Text,{children:"Checking update"})}const p1="";function dy(e,t){const{vizManager:r}=b.useContext(Ge),{panel:{viz:i,title:s,id:o,description:u,queryID:l,variables:d}}=Ce(),c={title:s,id:o,description:u,queryID:l,viz:i,layout:t},f=Ga(c);try{return r.resolveComponent(i.type),n(Gt,{configure:f,children:n(uy,{setVizConf:i.setConf,panel:c,data:e,variables:d,vizManager:r})})}catch(g){return console.info(v.get(g,"message")),null}}const cy=["richText","button"],Wa=T.observer(function({height:t,viz:r,data:i,loading:s,error:o,query:u}){const{ref:l,width:d,height:c}=ve.useElementSize(),f=dy(i,{w:d,h:c});if(cy.includes(r.type))return n("div",{className:"viz-root",style:{height:t},ref:l,children:n($e,{children:f})});if(s)return n("div",{className:"viz-root",style:{height:t,position:"relative"},ref:l,children:n(a.LoadingOverlay,{visible:s,exitTransitionDuration:0})});const h=!!o,m=!h&&!!(u!=null&&u.stateMessage),w=!h&&!m;return p("div",{className:"viz-root",style:{height:t},ref:l,children:[h&&n(a.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:o}),m&&n(a.Text,{color:"gray",align:"center",children:u.stateMessage}),w&&n($e,{children:f})]})});function py(e){return!["richText","button"].includes(e)}const hy={border:"1px solid #e9ecef"},ja={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function fy(e,t,r){return e.style.border.enabled?hy:r||t?ja:{border:"1px dashed transparent"}}const tn=T.observer(function({panel:t,view:r}){const i=F(),{inEditMode:s}=b.useContext(Ze),{data:o,state:u,error:l}=i.getDataStuffByID(t.queryID),d=i.queries.findByID(t.queryID),c=py(t.viz.type),f=c&&u==="loading",g=t.title?"calc(100% - 25px - 5px)":"100%",h=fy(t,c,s),m=c||s;return n(vn,{value:{panel:t,data:o,loading:f},children:p(a.Box,{className:"panel-root",p:5,pt:0,sx:{...h},children:[n(a.Box,{sx:{position:"absolute",left:0,top:0,height:28,zIndex:310},children:n(Bi,{})}),m&&n(Bo,{view:r}),n(No,{}),n(Wa,{viz:t.viz,data:o,loading:f,error:l,height:g,query:d})]})})}),h1="",gy=b.forwardRef(({h:e},t)=>n(a.ActionIcon,{ref:t,className:"react-grid-customDragHandle",sx:{userSelect:"none",cursor:"grab",position:"absolute",top:5,right:e>38?5:20,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",children:n(k.ArrowsMove,{size:16})})),my=b.forwardRef(({handleAxis:e,...t},r)=>n(a.ActionIcon,{ref:r,className:"react-grid-customResizeHandle",sx:{userSelect:"none",cursor:"nwse-resize",position:"absolute",bottom:0,right:0,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",...t,children:n(k.ChevronDownRight,{size:16})})),by=Ot.WidthProvider(Ot),yy=T.observer(({view:e,className:t="layout"})=>{const r=F(),{panels:i,layouts:s}=r.panels.panelsByIDs(e.panelIDs),o=b.useCallback(l=>{l.forEach(({i:d,...c})=>{const f=r.panels.findByID(d);f&&f.layout.set(c)})},[r]),u=(l,d,c,f)=>{c.h<30&&(c.h=30,f.h=30),c.w<4&&(c.w=4,f.w=4)};return n(by,{onLayoutChange:o,className:`dashboard-layout ${t}`,rowHeight:1,cols:36,margin:[0,0],isBounded:!0,isDraggable:!0,isResizable:!0,layout:s,draggableHandle:".react-grid-customDragHandle",resizeHandle:n(my,{}),onResize:u,children:i.map((l,d)=>p("div",{"data-grid":{...l.layout},className:"panel-grid-item",children:[n(gy,{h:l.layout.h}),n(tn,{view:e,panel:l})]},l.id))})}),vy=Ot.WidthProvider(Ot),xy=T.observer(function({view:t,className:r="layout"}){const{panels:i,layouts:s}=F().panels.panelsByIDs(t.panelIDs);return n(vy,{className:`dashboard-layout ${r}`,cols:36,rowHeight:1,margin:[0,0],isDraggable:!1,isResizable:!1,layout:s,children:i.map(o=>n("div",{"data-grid":{...o.layout},className:"panel-grid-item",children:n(tn,{view:t,panel:o})},o.id))})});var Ya=(e=>(e.Use="use",e.Edit="edit",e))(Ya||{}),K=(e=>(e.Division="div",e.Modal="modal",e.Tabs="tabs",e))(K||{});const Cy={div:"Division",tabs:"Tabs",modal:"Modal"},Ra={div:"rgba(255, 0, 0, 0.2)",modal:"rgba(0, 0, 0, 0.2)",tabs:"rgba(255, 200, 100, 0.4)"},wy={div:"#ff4000",modal:"#000",tabs:"#ffad18"},_y={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:"div",config:{},panelIDs:[]}],panels:[],filters:[],version:"8.57.0"};var ar=(e=>(e.Select="select",e.TreeSelect="tree-select",e.MultiSelect="multi-select",e.TextInput="text-input",e.Checkbox="checkbox",e.DateRange="date-range",e))(ar||{});const Sy=T.observer(({children:e})=>n(a.Box,{pt:10,pb:100,children:e})),Ty=T.observer(({children:e,view:t})=>{const r=t.config;return n(a.Modal,{size:r.width,overflow:"inside",opened:!0,onClose:v.noop,withCloseButton:!1,title:r.custom_modal_title.value,trapFocus:!0,onDragStart:i=>{i.stopPropagation()},styles:{root:{position:"relative",height:"100%"},overlay:{position:"absolute !important"},modal:{border:"1px solid #efefef"},body:{maxHeight:"calc(100vh - 325px)"}},withinPortal:!1,transitionDuration:0,children:e})}),ky=({variant:e,orientation:t})=>{const r={tab:{},panel:{padding:"16px"}};return e==="pills"&&t==="horizontal"&&(r.tab.paddingTop="6px",r.tab.paddingBottom="6px"),t==="vertical"&&(r.tab["&.add-a-tab"]={paddingTop:"1px",paddingBottom:"1px"},r.tab["&.add-a-tab .mantine-Tabs-tabLabel"]={marginLeft:"auto",marginRight:"auto"}),r},Dy=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},My=T.observer(({children:e,view:t})=>{const r=Le.useModals(),i=F(),s=b.useMemo(()=>i.views.options.filter(d=>d.type===K.Division),[t.id,i.views.options]),o=t.config,u=d=>r.openConfirmModal({title:"Delete this tab?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{o.removeTab(d)},confirmProps:{color:"red"},zIndex:320}),l=o.tabs.length===0;return p(a.Box,{className:"preview-view-tabs",children:[p(a.Tabs,{variant:o.variant,orientation:o.orientation,defaultValue:o.tabs.length>0?o.tabs[0].id:"0",styles:ky(o),children:[p(a.Tabs.List,{grow:o.grow,children:[o.tabs.map(d=>n(a.Tabs.Tab,{value:d.id,sx:Dy(d),children:d.name??d.id},d.id)),n(a.Tabs.Tab,{onClick:o.addTab,value:"add",className:"add-a-tab",children:n(k.Plus,{size:18,color:"#228be6"})})]}),o.tabs.map((d,c)=>{const f=i.views.findByID(d.view_id);return p(a.Tabs.Panel,{value:d.id,sx:{position:"relative"},children:[p(a.Box,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:200},children:[n(a.Overlay,{opacity:.8,color:"#FFF",blur:10,zIndex:100}),p(a.Stack,{mx:"auto",mt:100,sx:{width:"300px",position:"relative",zIndex:200},children:[n(a.TextInput,{label:"Tab Name",value:d.name,onChange:g=>d.setName(g.currentTarget.value)}),n(a.Select,{label:"View",value:d.view_id,onChange:d.setViewID,data:s}),n(a.ColorInput,{label:"Color",value:d.color,onChange:d.setColor,disabled:o.variant!=="default"}),f&&p(a.Button,{mt:20,variant:"gradient",leftIcon:n(V.IconArrowsLeftRight,{size:18}),gradient:{from:"cyan",to:"indigo"},onClick:()=>i.views.setIDOfVIE(f.id),children:["Swith to View: ",f.name]}),n(a.Button,{mt:20,variant:"subtle",color:"red",onClick:()=>u(c),disabled:l,leftIcon:n(V.IconTrash,{size:14}),children:"Delete This Tab"})]})]}),f&&n(nn,{view:f})]},d.id)})]}),e]})}),Iy=T.observer(({view:e,children:t})=>{switch(e.type){case K.Modal:return n(Ty,{view:e,children:t});case K.Tabs:return n(My,{view:e,children:t});case K.Division:default:return n(Sy,{children:t})}}),Qa=T.observer(function({view:t}){return n(mn.Provider,{value:{viewPanelInFullScreen:v.noop,inFullScreen:!1},children:n(a.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:n(Iy,{view:t,children:p(a.Box,{sx:{position:"relative"},children:[n(a.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:n(Vi,{view:t})}),n(yy,{view:t})]})})})})}),Ay={modal:{display:"flex",flexDirection:"column",flexWrap:"nowrap"},body:{display:"flex",height:"calc(100vh - 88px)"}},$y=T.observer(function({view:t,panel:r,exitFullScreen:i}){return n(a.Modal,{opened:!0,fullScreen:!0,onClose:i,title:n(a.Button,{color:"blue",size:"xs",onClick:i,leftIcon:n(k.ArrowLeft,{size:20}),children:"Exit fullscreen"}),styles:Ay,children:n(a.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:n(tn,{view:t,panel:r})})})});function zy(e,t,r){const{panels:i}=F(),s=e.id==="Main",[o,u]=b.useState(()=>s&&i.findByID(t)?t:null),l=b.useCallback(g=>{u(g),s&&r(g)},[s,r]),d=b.useCallback(()=>{u(null),s&&r("")},[s,r]),c=o?i.findByID(o):null;return{viewPanelInFullScreen:l,exitFullScreen:d,inFullScreen:!!c,fullScreenPanel:c}}const Ey=T.observer(({children:e})=>n(a.Box,{children:e})),Ly=T.observer(({children:e,view:t})=>{const r=F(),i=t.config,s=r.views.visibleViewIDs.includes(t.id),o=()=>r.views.rmVisibleViewID(t.id);return n(a.Modal,{size:i.width,centered:!0,overflow:"inside",opened:s,onClose:o,withCloseButton:!1,title:i.custom_modal_title.value,trapFocus:!0,onDragStart:u=>{u.stopPropagation()},styles:{modal:{border:"1px solid #efefef"},body:{maxHeight:i.height,overflow:"auto"}},transitionDuration:0,children:e})}),Py=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},Oy=T.observer(({children:e,view:t})=>{const r=F(),i=t.config;return p(a.Box,{className:"render-view-tabs",children:[p(a.Tabs,{variant:i.variant,orientation:i.orientation,defaultValue:i.tabs.length>0?i.tabs[0].id:"0",styles:{panel:{padding:i.orientation==="horizontal"?"16px 0px":"0"}},keepMounted:!1,children:[n(a.Tabs.List,{grow:i.grow,children:i.tabs.map(s=>n(a.Tabs.Tab,{value:s.id,sx:Py(s),disabled:!s.view_id,children:s.name??s.id},s.id))}),i.tabs.map(s=>{const o=r.views.findByID(s.view_id);return o?n(a.Tabs.Panel,{value:s.id,children:n(nn,{view:o})},s.id):null})]}),e]})}),Vy=T.observer(({view:e,children:t})=>{switch(e.type){case K.Modal:return n(Ly,{view:e,children:t});case K.Tabs:return n(Oy,{view:e,children:t});case K.Division:default:return n(Ey,{children:t})}}),nn=T.observer(function({view:t}){const{fullScreenPanelID:r,setFullScreenPanelID:i}=Ei(),{viewPanelInFullScreen:s,exitFullScreen:o,inFullScreen:u,fullScreenPanel:l}=zy(t,r,i);return n(mn.Provider,{value:{viewPanelInFullScreen:s,inFullScreen:u},children:p(a.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:[u&&n($y,{view:t,panel:l,exitFullScreen:o}),n(Vy,{view:t,children:p(a.Box,{sx:{position:"relative"},children:[!u&&n(a.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:n(Vi,{view:t})}),!u&&n(xy,{view:t})]})})]})})});function By(e){e=e||{};const t=Object.keys(e).sort(),r=[];for(let i=0;i<t.length;i++){const s=t[i];if(s!="authentication"&&e[s])r.push(t[i]+"="+(typeof e[s]=="object"?JSON.stringify(e[s]):e[s]));else{const o=Object.keys(e[s]).sort();for(let u=0;u<o.length;u++){const l=o[u];l!="sign"&&e[s][l]&&r.push(o[u]+"="+(typeof e[s][l]=="object"?JSON.stringify(e[s][l]):e[s][l]))}}}return r.sort().join("&")}function Ny(e,t){let r=By(e);return r+="&key="+t,Ti.MD5(r).toString().toUpperCase()}const ze={baseURL:"http://localhost:31200",app_id:"",app_secret:"",getAuthentication(e){if(!this.app_id||!this.app_secret)return;const t=new Date().getTime().toString();return{app_id:this.app_id,nonce_str:t,sign:Ny({app_id:this.app_id,nonce_str:t,...e},this.app_secret)}},getRequest(e,t){return(r,i,s={})=>{const o=window.localStorage.getItem("token"),u={"X-Requested-With":"XMLHttpRequest","Content-Type":s.string?"application/x-www-form-urlencoded":"application/json",authorization:o?`bearer ${o}`:"",...s.headers},l={baseURL:this.baseURL,method:e,url:r,params:e==="GET"?i:s.params,headers:u,signal:t};return["POST","PUT"].includes(e)&&(l.data=s.string?JSON.stringify(i):i,l.data.authentication=this.getAuthentication(l.data)),Ue(l).then(d=>d.data).catch(d=>Promise.reject(d))}}};function Ua(e){ze.baseURL!==e.apiBaseURL&&(ze.baseURL=e.apiBaseURL),e.app_id&&(ze.app_id=e.app_id),e.app_secret&&(ze.app_secret=e.app_secret)}const Xa=y.types.model("FilterConfigModel_Checkbox",{_name:y.types.literal("checkbox"),description:y.types.optional(y.types.string,""),default_value:y.types.boolean}).views(e=>({get json(){const{_name:t,description:r,default_value:i}=e;return{_name:t,description:r,default_value:i}},get isDescriptionEmpty(){const{description:t}=e;return t===""||t==="<p></p>"}})).actions(e=>({setDefaultValue(t){e.default_value=t},setDescription(t){e.description=t}})),Gy=()=>Xa.create({_name:"checkbox",description:"",default_value:!1});var ce=(e=>(e.Postgresql="postgresql",e.MySQL="mysql",e.HTTP="http",e))(ce||{}),we=(e=>(e.Select="select",e.MultiSelect="multi-select",e.TreeSelect="tree-select",e.TextInput="text-input",e.Checkbox="checkbox",e.DateRange="date-range",e))(we||{});y.types.model({type:y.types.enumeration("DataSourceType",[ce.Postgresql,ce.MySQL,ce.HTTP]),key:y.types.string,sql:y.types.string});function Za(e,t){return e.map(r=>{try{return r?j.tz(r,"UTC").format(t):null}catch{return console.log(`[date-range] failed parsing ${r}`),null}})}const qy=y.types.model("FilterConfigModel_DateRange",{_name:y.types.literal("date-range"),required:y.types.boolean,inputFormat:y.types.enumeration("DateRangeInputFormat",["YYYY","YYYYMM","YYYYMMDD","YYYY-MM","YYYY-MM-DD"]),default_value:y.types.optional(y.types.array(y.types.union(y.types.string,y.types.null)),[null,null]),clearable:y.types.boolean,max_days:y.types.optional(y.types.number,0),allowSingleDateInRange:y.types.optional(y.types.boolean,!1)}).views(e=>({get json(){const{_name:t,max_days:r,required:i,clearable:s,inputFormat:o,default_value:u,allowSingleDateInRange:l}=e;return{_name:t,max_days:r,required:i,clearable:s,inputFormat:o,default_value:Za(u,o),allowSingleDateInRange:l}},truthy(t){return Array.isArray(t)&&t.length===2&&t.every(r=>!!r)}})).views(e=>({getMaxDate(t){const{max_days:r}=e;if(!(!r||!t))return j(t).startOf("day").add(r,"days").toDate()},getMinDate(t){const{max_days:r}=e;if(!(!r||!t))return j(t).startOf("day").subtract(r,"days").toDate()}})).actions(e=>({setFilterValue(t){try{const r=y.getParent(e);y.getRoot(e).filters.setValueByKey(r.key,t)}catch(r){console.error(r)}}})).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}})),Ka=y.types.snapshotProcessor(qy,{preProcessor({default_value:e,...t}){return{...t,default_value:e.map(r=>r===null?null:j.tz(r,"UTC").toISOString())}},postProcessor(e){const{default_value:t,...r}=e;return{...r,default_value:Za(t,r.inputFormat)}}}),Fy=()=>Ka.create({_name:"date-range",required:!1,inputFormat:"YYYY-MM-DD",clearable:!1,default_value:[null,null]}),Wy=y.types.model({label:y.types.string,value:y.types.string}).actions(e=>({setLabel(t){e.label=t},setValue(t){e.value=t}})),sr=y.types.model("FilterConfigModel_BaseSelect",{static_options:y.types.optional(y.types.array(Wy),[]),options_query_id:y.types.optional(y.types.string,""),default_selection_count:y.types.optional(y.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:r,error:i}=y.getRoot(e).content.getDataStuffByID(e.options_query_id);return r==="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??""}})),rn=e=>v.cloneDeepWith(e,(t,r)=>{if(r!==void 0&&t)return ae.toJS(t)}),Ja=y.types.compose("FilterConfigModel_MultiSelect",y.types.model({_name:y.types.literal("multi-select"),min_width:y.types.optional(y.types.string,""),default_value:y.types.optional(y.types.array(y.types.string),[])}),sr).views(e=>({get json(){const{_name:t,default_value:r,min_width:i,static_options:s,options_query_id:o,default_selection_count:u}=e;return rn({_name:t,min_width:i,default_value:r,static_options:s,options_query_id:o,default_selection_count:u})},get default_selection(){return e.usingQuery?e.options.slice(0,e.default_selection_count).map(t=>t.value):e.default_value}})).actions(e=>({setDefaultValue(t){e.default_value=y.cast(t)},setMinWidth(t){e.min_width=t},setDefaultSelection(){const t=y.getRoot(e).content.filters,r=y.getParent(e).key;t.setValueByKey(r,e.default_selection)}})).actions(e=>({afterCreate(){y.addDisposer(e,ae.reaction(()=>ae.toJS(e.default_selection),e.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),jy=()=>Ja.create({_name:"multi-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),Ha=y.types.compose("FilterConfigModel_TreeSelect",y.types.model({_name:y.types.literal("tree-select"),min_width:y.types.optional(y.types.string,""),default_value:y.types.optional(y.types.array(y.types.string),[])}),sr).views(e=>({get json(){const{_name:t,default_value:r,min_width:i,static_options:s,options_query_id:o,default_selection_count:u}=e;return{_name:t,min_width:i,default_value:r,static_options:s,options_query_id:o,default_selection_count:u}}})).actions(e=>({setDefaultValue(t){e.default_value=y.cast(t)},setMinWidth(t){e.min_width=t}})),Yy=()=>Ha.create({_name:"tree-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),es=y.types.compose("FilterConfigModel_Select",y.types.model({_name:y.types.literal("select"),default_value:y.types.string,required:y.types.boolean,width:y.types.optional(y.types.string,"")}),sr).views(e=>({get json(){const{_name:t,default_value:r,required:i,width:s,static_options:o,options_query_id:u,default_selection_count:l}=e;return rn({_name:t,width:s,required:i,default_value:r,static_options:o,options_query_id:u,default_selection_count:l})},truthy(t){return!!t}})).actions(e=>({setRequired(t){e.required=t},setDefaultValue(t){e.default_value=t},setWidth(t){e.width=t}})),Ry=()=>es.create({_name:"select",required:!1,default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),ts=y.types.model("FilterConfigModel_TextInput",{_name:y.types.literal("text-input"),required:y.types.boolean,default_value:y.types.string}).views(e=>({get json(){const{_name:t,required:r,default_value:i}=e;return{_name:t,required:r,default_value:i}},truthy(t){return typeof t!="string"?!1:!!t.trim()}})).actions(e=>({setRequired(t){e.required=t},setDefaultValue(t){e.default_value=t}})),ns=()=>ts.create({_name:"text-input",required:!1,default_value:""}),or=y.types.model("FilterModel",{id:y.types.identifier,key:y.types.string,label:y.types.string,order:y.types.number,visibleInViewsIDs:y.types.array(y.types.string),auto_submit:y.types.optional(y.types.boolean,!1),type:y.types.enumeration("DashboardFilterType",[we.Select,we.MultiSelect,we.TreeSelect,we.TextInput,we.Checkbox,we.DateRange]),config:y.types.union(es,Ja,Ha,ts,Xa,Ka)}).views(e=>({get plainDefaultValue(){const t=e.config.default_value;return Array.isArray(t)?[...t]:t},get usingDefaultValue(){return e.type!==we.TreeSelect},get auto_submit_supported(){return[we.Select,we.Checkbox,we.DateRange].includes(e.type)}})).views(e=>({get json(){const{id:t,key:r,label:i,order:s,visibleInViewsIDs:o,auto_submit:u,type:l,config:d}=e;return{id:t,key:r,type:l,label:i,order:s,config:d.json,auto_submit:u,visibleInViewsIDs:ae.toJS(o)}},get should_auto_submit(){return e.auto_submit_supported&&e.auto_submit},requiredAndPass(t){return v.get(e.config,"required",!1)?v.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 we.Select:e.config=Ry();break;case we.MultiSelect:e.config=jy();break;case we.TreeSelect:e.config=Yy();break;case we.TextInput:e.config=ns();break;case we.Checkbox:e.config=Gy();break;case we.DateRange:e.config=Fy();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 rs(e,t){if(e===void 0)return e;if(t._name==="date-range")try{const[...r]=e;return r.map(i=>i===null?i:j.tz(i,"UTC").format(t.inputFormat)??i)}catch(r){return console.error(r),e}return e}function is(e){return e.reduce((t,r)=>(t[r.key]=rs(r.config.default_value,r.config),t),{})}function Qy(e,t,r){y.addDisposer(e,y.addMiddleware(e,(i,s)=>{s(i,()=>{y.getType(i.context)===t&&i.type==="action"&&r(i.name,i.context)})}))}const as=y.types.model("FiltersModel",{current:y.types.optional(y.types.array(or),[]),values:y.types.optional(y.types.frozen(),{}),previewValues:y.types.optional(y.types.frozen(),{})}).views(e=>({get json(){return e.current.map(t=>t.json)},get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(r=>r.id===t)},get inOrder(){return v.sortBy(e.current,"order")},get options(){return e.current.map(t=>({label:t.label??t.id,value:t.id,_type:"filter"}))},get empty(){return e.current.length===0},visibleInView(t){return v.sortBy(e.current.filter(r=>r.visibleInViewsIDs.includes(t)),"order")},get firstFilterValueKey(){return Object.keys(e.values)[0]??""},get keyLabelMap(){return e.current.reduce((t,r)=>(t[r.key]=r.label,t),{})}})).actions(e=>({replace(t){e.current=y.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByID(t){const r=e.current.findIndex(i=>i.id===t);r>=0&&e.current.splice(r,1)},setValues(t){e.values=t},setValueByKey(t,r){e.values={...e.values,[t]:r}},getValueByKey(t){return e.values[t]},refreshValues(){console.log("refreshing values"),e.values=is(e.current)},updatePreviewValues(t){e.previewValues=t}})).actions(e=>{function t(){Qy(e.current,or,(r,i)=>{if(r==="setType"){const s=rs(i.config.default_value,i.config);e.setValueByKey(i.key,s),e.updatePreviewValues({...e.previewValues,[i.key]:s})}})}return{afterCreate(){t()}}});function ss(e){return{current:e,values:is(e)}}const os="\uFEFF";function Uy(e,t){const r=new Blob([os+t],{type:"text/csv"});hn.saveAs(r,`${e}.csv`)}function Xy(e,t){const r=new Blob([t],{type:"application/json"});hn.saveAs(r,`${e}.json`)}function Zy(e){const t=new co;e.forEach(({id:r,data:i})=>{t.file(`${r}.csv`,us(i))}),t.generateAsync({type:"blob"}).then(r=>{hn.saveAs(r,"dashboard_data.zip")})}function ls(e){return e.includes(",")?`"${e}"`:e}function us(e){if(!Array.isArray(e)||e.length===0)return"";const t=[],r=Object.keys(e[0]).map(ls);return t.push(r.join(",")),e.forEach(i=>{const s=Object.values(i).map(ls).join(",");t.push(s)}),os+t.join(`
347
+ `)},nr={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...Pa}}},deviation:{name:"",data_keys:{estimated_value:"",actual_value:""}},metrics:[]},ib={input:{border:"none !important",paddingLeft:0,lineHeight:"1.55 !important"}},ab=({conf:e,metricKey:t,setMetricKey:r})=>{const{deviation:i,metrics:s}=e,o=b.useMemo(()=>{const u=s.map(l=>({label:l.name,value:l.data_key}));return u.push({label:i.name?i.name:i.data_keys.actual_value,value:i.data_keys.actual_value}),u},[i,s]);return p(a.Group,{spacing:1,children:[n(a.Text,{size:12,color:"dimmed",sx:{cursor:"default",userSelect:"none"},children:"基线指标"}),n(a.NativeSelect,{size:"xs",data:o,value:t,onChange:u=>r(u.currentTarget.value),styles:ib})]})},sb={"tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function ob(){return p(a.HoverCard,{width:400,shadow:"md",children:[n(a.HoverCard.Target,{children:n(a.Button,{size:"xs",variant:"subtle",compact:!0,leftIcon:n(V.IconInfoCircle,{size:14}),children:"指标说明"})}),n(a.HoverCard.Dropdown,{children:n(a.Table,{fontSize:14,sx:sb,children:p("tbody",{children:[p("tr",{children:[n("th",{children:"估算偏差"}),n("td",{children:"使用斐波那契数列(1,2,3,5,8,13)估算故事点,每个数位为一个档位,计算issue实际故事点与估算故事点的档位偏差,即为估算偏差。如估算故事点为5,实际故事点为8,则估算偏差为-1。"})]}),p("tr",{children:[n("th",{children:"准确估算比例"}),n("td",{children:"偏差在 ± 1 档位内的 issue 均为准确估算,以此计算准确估算的比例。"})]})]})})})]})}function lb(e){return p(a.Group,{position:"apart",children:[n(ob,{}),n(ab,{...e})]})}le.use([de.BarChart,de.LineChart,de.HeatmapChart,B.GridComponent,B.LegendComponent,B.TooltipComponent,De.CanvasRenderer,B.VisualMapComponent]);function ub({conf:e,data:t,width:r,height:i,metricKey:s}){const o=b.useMemo(()=>rb(e,s,t),[e,t,s]);return!r||!i?null:n(Me,{echarts:le,option:o,style:{width:r,height:i},notMerge:!0,theme:"merico-light"})}function db({context:e}){const{value:t}=W(e.instanceData,"config"),r=b.useMemo(()=>v.defaults({},t,nr),[t]),i=e.data,{width:s,height:o}=e.viewport,{x_axis:u,deviation:l}=r,{estimated_value:d,actual_value:c}=l.data_keys,[f,g]=b.useState(c);if(b.useEffect(()=>{g(w=>w||c)},[c]),!u.data_key||!d||!c)return null;const h=Math.max(s,300),m=Math.max(o,370);return p(a.Box,{sx:{overflow:"hidden",height:m,width:h},children:[n(lb,{conf:r,metricKey:f,setMetricKey:g}),n(ub,{width:h,height:m-30,data:i,conf:r,metricKey:f})]})}const cb=({disabled:e,value:t,onChange:r})=>{const i=s=>{s&&r(s)};return p(a.Box,{sx:{position:"relative"},children:[e&&n(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),n(_e,{height:"500px",defaultLanguage:"javascript",value:t,onChange:i,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},pb=b.forwardRef(({value:e,onChange:t},r)=>{const[i,{setTrue:s,setFalse:o}]=Z.useBoolean(),[u,l]=b.useState(e);b.useEffect(()=>{l(e)},[e]);const d=m=>{l({...u,enabled:m})},c=()=>{o();const{enabled:m,func_content:w}=u,C={enabled:m,func_content:w};l(C),t(C)},f=()=>{o(),l(e)},g=m=>{l(w=>({...w,func_content:m}))},h=()=>{g(Pa.func_content)};return p(O,{children:[n(a.Button,{variant:"filled",mt:24,onClick:s,sx:{flexGrow:0},children:"Customize Label"}),n(a.Modal,{size:800,title:"Customize label content",opened:i,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:i&&p(a.Stack,{children:[n(a.Checkbox,{mt:10,label:"Enabled",checked:u.enabled,onChange:m=>d(m.currentTarget.checked)}),n(cb,{value:u.func_content,onChange:g,disabled:!u.enabled}),p(a.Group,{position:"apart",children:[n(a.Button,{onClick:h,color:"red",leftIcon:n(k.Recycle,{size:20}),children:"Rest"}),p(a.Group,{position:"right",children:[n(a.Button,{onClick:f,variant:"subtle",children:"Cancel"}),n(a.Button,{onClick:c,children:"OK"})]})]})]})})]})});function hb({data:e,control:t,watch:r}){return r(["x_axis"]),p(a.Stack,{children:[p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:"x_axis.data_key",control:t,render:({field:i})=>n(Y,{label:"数据字段",required:!0,data:e,sx:{flex:1},...i})}),n(x.Controller,{name:"x_axis.name",control:t,render:({field:i})=>n(a.TextInput,{label:"X轴名称",sx:{flex:1},...i})})]}),n(a.Divider,{mb:-15,label:"点位文案",labelPosition:"center"}),p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:i})=>n(a.NumberInput,{label:"旋转",hideControls:!0,min:-90,max:90,rightSection:n(a.Text,{color:"dimmed",children:"度"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...i})}),n(x.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:i})=>n(pb,{data:e,...i})})]})]})}function fb({data:e,control:t,watch:r}){return r(["deviation"]),p(a.Stack,{children:[n(a.Group,{grow:!0,noWrap:!0,children:n(x.Controller,{name:"deviation.name",control:t,render:({field:i})=>n(a.TextInput,{label:"指标名称",sx:{flex:1},...i})})}),p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:"deviation.data_keys.estimated_value",control:t,render:({field:i})=>n(Y,{label:"估算值字段",required:!0,data:e,sx:{flex:1},...i})}),n(x.Controller,{name:"deviation.data_keys.actual_value",control:t,render:({field:i})=>n(Y,{label:"实际值字段",required:!0,data:e,sx:{flex:1},...i})})]})]})}const gb=({control:e,data:t,index:r,remove:i})=>p(a.Stack,{children:[p(a.Group,{grow:!0,noWrap:!0,children:[n(x.Controller,{name:`metrics.${r}.name`,control:e,render:({field:s})=>n(a.TextInput,{label:"Name",required:!0,sx:{flex:1},...s})}),n(x.Controller,{name:`metrics.${r}.data_key`,control:e,render:({field:s})=>n(Y,{label:"Value Field",required:!0,data:t,sx:{flex:1},...s})})]}),n(a.Divider,{mb:-10,mt:10,variant:"dashed"}),n(a.Button,{leftIcon:n(k.Trash,{size:16}),color:"red",variant:"light",onClick:()=>i(r),sx:{top:15,right:5},children:"Delete this Metric"})]}),mb=({control:e,watch:t,data:r})=>{const{fields:i,append:s,remove:o}=x.useFieldArray({control:e,name:"metrics"}),u=t("metrics"),l=i.map((h,m)=>({...h,...u[m]})),d=()=>s({id:Date.now().toString(),data_key:"",name:""}),c=t("metrics.0.id"),[f,g]=b.useState(()=>c??null);return b.useEffect(()=>{c&&g(h=>h!==null?h:c)},[c]),p(O,{children:[p(a.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[n(k.InfoCircle,{size:14,color:"#888"}),n(a.Text,{size:14,color:"#888",children:"设置可以展示在基线图的指标,例如代码当量"})]}),n(a.Divider,{variant:"dashed",my:10}),p(a.Tabs,{value:f,onTabChange:h=>g(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(a.Tabs.List,{children:[l.map((h,m)=>n(a.Tabs.Tab,{value:h.id,children:h.name?h.name:m},h.id)),n(a.Tabs.Tab,{onClick:d,value:"add",children:n(k.Plus,{size:18,color:"#228be6"})})]}),l.map((h,m)=>n(a.Tabs.Panel,{value:h.id,children:n(gb,{control:e,index:m,remove:o,data:r},h.id)},h.id))]})]})};function bb({context:e}){const{value:t,set:r}=W(e.instanceData,"config"),i=e.data,s=b.useMemo(()=>v.defaultsDeep({},t,nr),[t]),{control:o,handleSubmit:u,watch:l,getValues:d,reset:c}=x.useForm({defaultValues:s});b.useEffect(()=>{c(s)},[s]),l([]);const f=d(),g=b.useMemo(()=>!v.isEqual(f,s),[f,s]);return n(a.Stack,{spacing:"xs",children:p("form",{onSubmit:u(r),children:[p(a.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[n(a.Text,{children:"Merico Estimation Chart Config"}),n(a.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!g,children:n(k.DeviceFloppy,{size:20})})]}),p(a.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"12px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(a.Tabs.List,{children:[n(a.Tabs.Tab,{value:"X Axis",children:"X 轴"}),n(a.Tabs.Tab,{value:"Deviation",children:"偏差"}),n(a.Tabs.Tab,{value:"Additional Metrics",children:"指标"})]}),n(a.Tabs.Panel,{value:"X Axis",children:n(hb,{control:o,watch:l,data:i})}),n(a.Tabs.Panel,{value:"Deviation",children:n(fb,{control:o,watch:l,data:i})}),n(a.Tabs.Panel,{value:"Additional Metrics",children:n(mb,{control:o,watch:l,data:i})})]})]})})}class yb extends he{constructor(){super(...arguments);P(this,"VERSION",1)}configVersions(){this.version(1,r=>({version:1,config:r}))}}const vb={displayName:"Merico Estimation Chart",displayGroup:"Merico suite",migrator:new yb,name:"mericoEstimationChart",viewRender:db,configRender:bb,createConfig:()=>({version:1,config:nr})},xb=[{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"})),Cb=[jo,Yo,Uo,Qo,Ro,Xo],Oa=()=>({id:"dashboard",version:_n,manifest:{viz:[Un,Hh,vg,Bp,Cf,op,Nm,il,Rl,Zd,Sc,em,np,Md,Yh,_p,Ep,Dg,vb,su],color:[...xb,...Cb]}}),Mt=new Jo,be={pluginManager:je("pluginManager"),vizManager:je("vizManager"),colorManager:je("colorManager"),instanceScope:{panelModel:je("panelModel"),vizInstance:je("vizInstance"),interactionManager:je("interactionManager"),migrator:je("migrator"),operationManager:je("operationManager"),triggerManager:je("triggerManager")}},rr=()=>{try{Mt.install(Oa())}catch{}const e=new qo(Mt),t=new Ko(Mt);return{pluginManager:Mt,vizManager:e,colorManager:t}},Ge=b.createContext(rr());try{Mt.install(Oa())}catch{}function wb(e,t){const{value:r,set:i}=W(e.operation.operationData,"config"),[s,o]=b.useState(v.defaults({},r,t)),u=async()=>{await i(s)};return b.useEffect(()=>{o(v.defaults({},r,t))},[r]),{config:s,setConfig:o,commit:u}}function _b(e){const{config:t,setConfig:r,commit:i}=wb(e,{urlTemplate:"",openInNewTab:!0});async function s(){await i()}async function o(l){r({...t,openInNewTab:l}),await i()}const u=l=>r({...t,urlTemplate:l.currentTarget.value});return p(a.Stack,{children:[n(a.TextInput,{label:"Url",value:t.urlTemplate,onChange:u,onBlur:s}),n(a.Switch,{label:"Open in new Tab",checked:t.openInNewTab,onChange:l=>o(l.currentTarget.checked)})]})}async function Sb(e,t){const{urlTemplate:r,openInNewTab:i}=await t.operationData.getItem("config");window.dispatchEvent(new CustomEvent("open-link",{detail:{urlTemplate:r,openInNewTab:i,payload:e}}))}class Tb extends he{constructor(){super(...arguments);P(this,"VERSION",1)}configVersions(){this.version(1,r=>r)}}const kb={displayName:"Open Link",id:"builtin:op:open-link",configRender:_b,run:Sb,migrator:new Tb,createDefaultConfig:()=>({version:1,config:{urlTemplate:"",openInNewTab:!0}})};function Db(e){const{value:t,set:r}=W(e.operationData,"config"),i=s=>void r({template:s});return[(t==null?void 0:t.template)||"",i]}function Mb(e){const[t,r]=Db(e.operation);return n(a.TextInput,{defaultValue:t,onBlur:i=>r(i.currentTarget.value),label:"console.log"})}async function Ib(e,t){const r=await t.operationData.getItem("config"),i=v.template(r.template||"");console.log("run with payload",e),console.log(i(e))}const Ab={displayName:"console.log (debug)",id:"builtin:op:debug",configRender:Mb,run:Ib},$b=T.observer(e=>{const t=F(),{value:r,set:i}=W(e.operation.operationData,"config");console.log({value:r,viewID:r==null?void 0:r.viewID});const s=(r==null?void 0:r.viewID)||"",o=u=>void i({viewID:u});return n(a.Select,{defaultValue:s,value:s,onChange:o,label:"View",data:t.views.options})});async function zb(e,t){const i=(await t.operationData.getItem("config")).viewID;window.dispatchEvent(new CustomEvent("open-view",{detail:{viewID:i}}))}const Eb={displayName:"Open View",id:"builtin:op:open_view",configRender:$b,run:zb},Lb={dictionary:{}},Pb=T.observer(e=>{const t=F(),{value:r=Lb,set:i}=W(e.operation.operationData,"config"),{dictionary:s={}}=r,o=(d,c)=>{i({dictionary:{...s,[d]:c}})},u=()=>{o(t.filters.firstFilterValueKey,"")},l=d=>{const c={...s};delete c[d],i({dictionary:c})};return p(a.Stack,{spacing:10,children:[n(a.Text,{children:"Mapping Rules"}),Object.entries(s).map(([d,c])=>p(a.Flex,{justify:"space-between",gap:10,children:[n(a.TextInput,{label:"Payload key",value:c,onChange:f=>{o(d,f.currentTarget.value)},sx:{flexGrow:1}}),n(Y,{data:[t.filters.values],value:d,onChange:f=>{o(f,c)},label:"Filter key",sx:{flexGrow:1}}),n(a.ActionIcon,{onClick:()=>l(d),sx:{marginTop:"26px",flexGrow:0},children:n(k.Trash,{size:14,color:"red"})})]},d)),n(a.Button,{size:"xs",onClick:u,sx:{alignSelf:"center",width:"300px"},children:"Add one mapping rule"})]})});async function Ob(e,t){const i=(await t.operationData.getItem("config")).dictionary;window.dispatchEvent(new CustomEvent("set-filter-values",{detail:{dictionary:i,payload:e}}))}const Vb={displayName:"Set Filter Values",id:"builtin:op:set_filter_values",configRender:Pb,run:Ob},Bb={filter_keys:[]},Nb=T.observer(e=>{const t=F(),{value:r=Bb,set:i}=W(e.operation.operationData,"config"),{filter_keys:s=[]}=r,o=l=>{i({filter_keys:[...l]})},u=b.useMemo(()=>t.filters.current.map(l=>({label:l.label,value:l.key})),[t.filters.values]);return n(a.Stack,{spacing:10,children:n(a.MultiSelect,{label:"Select Filters to Clear",data:u,value:s,onChange:o})})});async function Gb(e,t){const i=(await t.operationData.getItem("config")).filter_keys;window.dispatchEvent(new CustomEvent("clear-filter-values",{detail:{filter_keys:i,payload:e}}))}const Ht=[Ab,kb,Eb,Vb,{displayName:"Clear Filter Values",id:"builtin:op:clear_filter_values",configRender:Nb,run:Gb}];class qb{constructor(t,r=Ht){P(this,"attachments");this.operations=r;const i=async s=>{const{id:o,schemaRef:u}=await s.getItem(null);return{id:o,schemaRef:u,operationData:new lt(s,"data")}};this.attachments=new wn(t,"__OPERATIONS",i)}async runOperation(t,r){const i=await this.attachments.getInstance(t);if(!i){console.warn(`Operation '${t}' is not defined`);return}const s=this.tryGetSchema(i.schemaRef);if(!s){console.warn(`Operation schema '${i.schemaRef}' is not defined`);return}await s.run(r,i)}tryGetSchema(t){return this.operations.find(r=>r.id===t)}async needMigration(){const r=(await this.attachments.list()).map(async i=>{const s={configData:i.operationData},o=this.tryGetSchema(i.schemaRef),u=o==null?void 0:o.migrator;return u&&await u.needMigration(s)});return(await Promise.all(r)).some(i=>i)}async runMigration(){const r=(await this.attachments.list()).map(async i=>{const s={configData:i.operationData},o=this.tryGetSchema(i.schemaRef),u=o==null?void 0:o.migrator;u&&await u.needMigration(s)&&await u.migrate(s)});await Promise.all(r)}async createOrGetOperation(t,r){var u;if(!this.getOperationSchemaList().some(l=>l.id===r.id))throw new Error(`Operation schema '${r.id}' is not defined`);const s=await this.attachments.getInstance(t);return!s||s.schemaRef!==r.id?await this.attachments.create(t,{id:t,schemaRef:r.id,data:((u=r.createDefaultConfig)==null?void 0:u.call(r))??{}}):s}getOperationList(){return this.attachments.list()}getOperationSchemaList(){return this.operations}removeOperation(t){return this.attachments.remove(t)}async retrieveTrigger(t){return await this.attachments.getInstance(t)}}const Va="__TRIGGERS";class Fb{constructor(t,r){P(this,"attachments");this.instance=t,this.component=r;const i=async s=>{const{id:o,schemaRef:u}=await s.getItem(null);return{id:o,schemaRef:u,triggerData:new lt(s,"data")}};this.attachments=new wn(t,Va,i)}watchTriggerSnapshotList(t){return this.instance.instanceData.watchItem(Va,r=>{const i=v.values(r).map(s=>({id:v.get(s,"id"),schemaRef:v.get(s,"schemaRef"),config:ae.toJS(v.get(s,"data.config"))}));t(i)},{fireImmediately:!0})}async createOrGetTrigger(t,r,i={recreate:!1}){var l;if(!this.getTriggerSchemaList().some(d=>d.id===r.id))throw new Error(`Trigger schema '${r.id}' is not defined in component '${this.component.name}'`);const o=await this.attachments.getInstance(t);return!o||i.recreate||o.schemaRef!==r.id?await this.attachments.create(t,{id:t,schemaRef:r.id,data:((l=r==null?void 0:r.createDefaultConfig)==null?void 0:l.call(r))||{}}):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 r=(await this.getTriggerList()).map(async i=>{const s=this.getTriggerSchemaList().find(l=>l.id===i.schemaRef),o=s==null?void 0:s.migrator,u={configData:i.triggerData};return o&&await o.needMigration(u)?()=>o.migrate(u):null});return Promise.all(r).then(i=>i.filter(s=>s))}async needMigration(){return(await this.getMigrationTasks()).length>0}async runMigration(){const t=await this.getMigrationTasks();await Promise.all(t.map(r=>r()))}}class ir{constructor(t,r,i){P(this,"operationManager");P(this,"triggerManager");P(this,"attachments");this.operationManager=new qb(t,i),this.triggerManager=new Fb(t,r);const s=async o=>{const{id:u,triggerRef:l,operationRef:d}=await o.getItem(null);return{id:u,triggerRef:l,operationRef:d}};this.attachments=new wn(t,"__INTERACTIONS",s)}async addInteraction(t,r){const i=t.id,s=r.id,o=`[${i}]:[${s}]`;await this.attachments.create(o,{id:o,triggerRef:i,operationRef:s})}getInteractionList(){return this.attachments.list()}async removeInteraction(t){const r=await this.attachments.getInstance(t);if(!r)return;const{triggerRef:i,operationRef:s}=r;await this.getTriggerRefCount(i)<=1&&await this.triggerManager.removeTrigger(i),await this.getOperationRefCount(s)<=1&&await this.operationManager.removeOperation(s),await this.attachments.remove(t)}async getOperationRefCount(t){return(await this.getInteractionList()).filter(i=>i.operationRef===t).length}async getTriggerRefCount(t){return(await this.getInteractionList()).filter(i=>i.triggerRef===t).length}async runInteraction(t,r){const s=(await this.getInteractionList()).filter(o=>o.triggerRef===t);await Promise.all(s.map(async o=>{try{return await this.operationManager.runOperation(o.operationRef,r)}catch(u){console.warn(`Failed to run operation '${o.operationRef}'`,u)}}))}}const qe=({vizManager:e,instance:t})=>Z.useCreation(()=>new ir(t,e.resolveComponent(t.type),Ht),[t,e]),Ba=e=>{const{title:t="Variables",variables:r}=e,i=ve.useClipboard(),s=o=>{i.copy(o),Vt.showNotification({color:"green",message:"Copied to clipboard"})};return p(a.Paper,{withBorder:!0,p:"sm",children:[n(a.Text,{size:"xs",color:"dimmed",mb:"sm",children:t}),n(a.Stack,{style:{maxHeight:"500px"},children:r.map(o=>p(a.Text,{size:"sm",children:[p(a.Code,{color:"teal",children:["// ",o.description]}),n("br",{}),p(a.Code,{onClick:()=>s(o.name),style:{cursor:"pointer"},children:[o.name," : ",o.valueType]})]},o.name))})]})};class Wb{constructor(t,r){P(this,"operationId");P(this,"operation");P(this,"operationSchema");P(this,"variables",[]);this.operationManager=t,this.instance=r,ae.makeAutoObservable(this)}get schemaList(){return this.operationManager.getOperationSchemaList()}async configOperation(t,r){const i=await this.operationManager.retrieveTrigger(t),s=this.operationManager.getOperationSchemaList().find(o=>o.id===(i==null?void 0:i.schemaRef));ae.runInAction(()=>{this.operationId=t,this.operation=i,this.operationSchema=s,this.variables=r})}async changeSchema(t){this.operationId&&(await this.operationManager.createOrGetOperation(this.operationId,t),await this.configOperation(this.operationId,this.variables))}}function jb(e){return!!e.operationId}const Yb=T.observer(({model:e,onClick:t})=>{var i;const r=(i=e.operationSchema)==null?void 0:i.displayName;return n(a.Button,{variant:"outline",onClick:t,children:r})}),Rb=T.observer(({model:e})=>{const t={operation:e.operation,instance:e.instance,variables:[]};return b.createElement(e.operationSchema.configRender,t)});function Qb({model:e}){const t=e.schemaList,r=t.map(s=>({label:s.displayName,value:s.id}));async function i(s){await e.changeSchema(t.find(o=>o.id===s))}return n(a.Select,{label:"Operation",data:r,onChange:i,value:e.operationSchema.id})}const Ub=T.observer(e=>{const[t,{setTrue:r,setFalse:i}]=Z.useBoolean(!1),{operationManager:s,operationId:o,instance:u,variables:l}=e,d=Z.useCreation(()=>new Wb(s,u),[s,u]);return Z.useAsyncEffect(async()=>{await d.configOperation(o,l)},[o,d]),jb(d)?p(O,{children:[n(Yb,{model:d,onClick:r}),n(a.Modal,{size:600,opened:t,onClose:i,title:"Operation Settings",closeButtonLabel:"close",zIndex:320,children:p(a.Stack,{children:[n(Qb,{model:d}),n(Rb,{model:d}),n(Ba,{title:"Variables",variables:d.variables})]})})]}):null});class Xb{constructor(t,r){P(this,"triggerId");P(this,"trigger");P(this,"triggerSchema");P(this,"sampleData");this.triggerManager=t,this.instance=r,ae.makeAutoObservable(this)}get schemaList(){return this.triggerManager.getTriggerSchemaList()}async configTrigger(t,r){const i=await this.triggerManager.retrieveTrigger(t),s=this.triggerManager.getTriggerSchemaList().find(o=>o.id===(i==null?void 0:i.schemaRef));ae.runInAction(()=>{this.triggerId=t,this.trigger=i,this.triggerSchema=s,this.sampleData=r})}async changeSchema(t){this.triggerId&&(await this.triggerManager.createOrGetTrigger(this.triggerId,t),await this.configTrigger(this.triggerId,this.sampleData))}isReady(){return Zb(this)}}function Zb(e){return!!e.triggerId&&!!e.triggerSchema}function Kb(e,t){return Z.useCreation(()=>new Xb(e,t),[e,t])}const Jb=T.observer(({model:e,onClick:t})=>{const r=e.triggerSchema.nameRender,i={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return n(a.Button,{variant:"outline",onClick:t,children:b.createElement(r,i)})}),Hb=T.observer(({model:e})=>{const t=e.schemaList,r=t.map(s=>({label:s.displayName,value:s.id}));async function i(s){await e.changeSchema(t.find(o=>o.id===s))}return n(a.Select,{label:"Trigger",data:r,value:e.triggerSchema.id,onChange:i})}),ey=T.observer(({model:e})=>{const t={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return b.createElement(e.triggerSchema.configRender,t)}),ty=T.observer(e=>{const[t,{setTrue:r,setFalse:i}]=Z.useBoolean(!1),s=e.model;return p(O,{children:[n(a.Modal,{opened:t,onClose:i,title:"Setup Trigger",closeButtonLabel:"close setup",zIndex:320,children:p(a.Stack,{children:[n(Hb,{model:s}),n(ey,{model:s}),n(Ba,{title:"Payload",variables:s.triggerSchema.payload})]})}),n(Jb,{onClick:r,model:s})]})});function ny(e,t){const[r,i]=b.useState([]);return Z.useAsyncEffect(async()=>{const s=await e.getInteractionList();i(s)},[t,e]),r}const ry=T.observer(({item:e,manager:t,instance:r,sampleData:i,variables:s,onRemove:o})=>{const{triggerRef:u,operationRef:l}=e,d=Kb(t.triggerManager,r);if(Z.useAsyncEffect(async()=>{await d.configTrigger(u,i)},[d,u,i]),d.isReady()){const c=[...d.triggerSchema.payload,...s];return p(a.Group,{children:[n(ty,{model:d}),n(Ub,{instance:r,operationId:l,variables:c,operationManager:t.operationManager}),n(a.ActionIcon,{"aria-label":"delete-interaction",variant:"filled",color:"red",onClick:()=>o(e),children:n(k.Trash,{size:16})})]})}return null}),iy=e=>{const[t,r]=b.useState(0),{interactionManager:i,instance:s,sampleData:o,variables:u}=e,l=ny(i,t),d=async()=>{const h=await i.triggerManager.createOrGetTrigger(ve.randomId(),i.triggerManager.getTriggerSchemaList()[0]),m=await i.operationManager.createOrGetOperation(ve.randomId(),i.operationManager.getOperationSchemaList()[0]);await i.addInteraction(h,m),r(w=>w+1)};async function c(h){await i.removeInteraction(h.id),r(m=>m+1)}const{data:f=0,loading:g}=Z.useRequest(async()=>{try{return(await i.triggerManager.getTriggerSchemaList()).length}catch{return 0}});return p(a.Stack,{children:[n(a.LoadingOverlay,{visible:g}),f===0&&n(a.Alert,{icon:n(k.AlertCircle,{size:16}),title:"Unavailable",color:"gray",children:"This visualization does not have available interactions to choose from"}),l.map(h=>n(ry,{onRemove:c,instance:s,sampleData:o,variables:u,item:h,manager:e.interactionManager},h.id)),n(a.Button,{style:{width:"fit-content"},onClick:()=>d(),disabled:f===0,children:"Add interaction"})]})},ay=()=>{const{panel:e,data:t}=Ce(),r=e.viz,{vizManager:i}=b.useContext(Ge),s=e.json,o=Z.useCreation(()=>i.getOrCreateInstance(s),[i,s]),u=Z.useCreation(()=>new ir(o,i.resolveComponent(r.type),Ht),[o,r.type]);return b.useEffect(()=>o.instanceData.watchItem(null,v.throttle(l=>{e.viz.setConf(l)},100,{leading:!1,trailing:!0})),[o]),{instance:o,vizManager:i,interactionManager:u,sampleData:t,variables:[]}},sy=()=>{const e=ay();return n(iy,{...e})};var Na=(e=>(e.migrated="migrated",e.nothingToMigrate="nothingToMigrate",e.checkFailed="checkFailed",e.migrationFailed="migrationFailed",e))(Na||{}),en=(e=>(e.notStarted="notStarted",e.inProgress="inProgress",e.done="done",e))(en||{});class oy{constructor(t){P(this,"vizInstance");P(this,"operationManager");P(this,"triggerManager");P(this,"vizManager");P(this,"runningMigration");P(this,"panelModel");P(this,"status","notStarted");this.panelModel=t.getRequired(be.instanceScope.panelModel),this.vizInstance=t.getRequired(be.instanceScope.vizInstance),this.operationManager=t.getRequired(be.instanceScope.operationManager),this.triggerManager=t.getRequired(be.instanceScope.triggerManager),this.vizManager=t.getRequired(be.vizManager)}async createMigrationTask(){const t=[];try{await this.instanceNeedMigration()&&t.push(()=>this.runInstanceMigration()),await this.interactionNeedMigration()&&t.push(()=>this.runInteractionMigration())}catch(r){return console.warn("check migration failed",r),"checkFailed"}if(t.length===0)return"nothingToMigrate";try{return await Promise.all(t.map(r=>r())),"migrated"}catch(r){return console.warn("migration failed",r),"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),r={configData:this.vizInstance.instanceData,panelModel:this.panelModel};await t.migrator.migrate(r)}async instanceNeedMigration(){const t=this.vizManager.resolveComponent(this.vizInstance.type),r={configData:this.vizInstance.instanceData};return t.migrator.needMigration(r)}async interactionNeedMigration(){return await this.operationManager.needMigration()||await this.triggerManager.needMigration()}}function Ga(e){const{panel:t}=Ce();return b.useCallback(r=>{const i=r.getRequired(be.vizManager),s=i.resolveComponent(e.viz.type);return r.createScoped().provideFactory(be.instanceScope.vizInstance,()=>i.getOrCreateInstance(e)).provideFactory(be.instanceScope.interactionManager,o=>{const u=o.getRequired(be.instanceScope.vizInstance);return new ir(u,s,Ht)}).provideFactory(be.instanceScope.operationManager,o=>o.getRequired(be.instanceScope.interactionManager).operationManager).provideFactory(be.instanceScope.triggerManager,o=>o.getRequired(be.instanceScope.interactionManager).triggerManager).provideValue(be.instanceScope.panelModel,t).provideFactory(be.instanceScope.migrator,o=>new oy(o))},[e.viz.type,e.viz.conf])}function qa(e){const[t,r]=b.useState(!1),i=Ii().getRequired(be.instanceScope.migrator);return Z.useAsyncEffect(async()=>{const s=i.status===en.notStarted;r(i.status===en.done),i.status===en.notStarted&&i.runMigration().then(o=>{o===Na.migrated&&s&&(e==null||e())}).finally(()=>{r(!0)})},[i]),t}function Fa(e,t){const r=Ii().getRequired(be.instanceScope.vizInstance);return b.useEffect(()=>(r.instanceData.setItem(null,t.viz.conf),r.instanceData.watchItem(null,i=>{e(i)})),[e,t.viz.type]),r}function ly({setVizConf:e,...t}){const{panel:r}=t,i=Fa(e,r),s=qa(()=>{Vt.showNotification({title:`${r.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})});return Z.useAsyncEffect(async()=>{await i.instanceData.setItem(null,r.viz.conf)},[i,r.viz.type]),s?n(Wo,{...t}):n(a.Text,{children:"Checking update..."})}function uy(e){const{panel:t,setVizConf:r}=e;Fa(r,t);const{inEditMode:i}=b.useContext(Ze);return qa(()=>{i&&Vt.showNotification({title:`${t.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?n(Fo,{...e}):n(a.Text,{children:"Checking update"})}const p1="";function dy(e,t){const{vizManager:r}=b.useContext(Ge),{panel:{viz:i,title:s,id:o,description:u,queryID:l,variables:d}}=Ce(),c={title:s,id:o,description:u,queryID:l,viz:i,layout:t},f=Ga(c);try{return r.resolveComponent(i.type),n(Gt,{configure:f,children:n(uy,{setVizConf:i.setConf,panel:c,data:e,variables:d,vizManager:r})})}catch(g){return console.info(v.get(g,"message")),null}}const cy=["richText","button"],Wa=T.observer(function({height:t,viz:r,data:i,loading:s,error:o,query:u}){const{ref:l,width:d,height:c}=ve.useElementSize(),f=dy(i,{w:d,h:c});if(cy.includes(r.type))return n("div",{className:"viz-root",style:{height:t},ref:l,children:n($e,{children:f})});if(s)return n("div",{className:"viz-root",style:{height:t,position:"relative"},ref:l,children:n(a.LoadingOverlay,{visible:s,exitTransitionDuration:0})});const h=!!o,m=!h&&!!(u!=null&&u.stateMessage),w=!h&&!m;return p("div",{className:"viz-root",style:{height:t},ref:l,children:[h&&n(a.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:o}),m&&n(a.Text,{color:"gray",align:"center",children:u.stateMessage}),w&&n($e,{children:f})]})});function py(e){return!["richText","button"].includes(e)}const hy={border:"1px solid #e9ecef"},ja={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function fy(e,t,r){return e.style.border.enabled?hy:r||t?ja:{border:"1px dashed transparent"}}const tn=T.observer(function({panel:t,view:r}){const i=F(),{inEditMode:s}=b.useContext(Ze),{data:o,state:u,error:l}=i.getDataStuffByID(t.queryID),d=i.queries.findByID(t.queryID),c=py(t.viz.type),f=c&&u==="loading",g=t.title?"calc(100% - 25px - 5px)":"100%",h=fy(t,c,s),m=c||s;return n(vn,{value:{panel:t,data:o,loading:f},children:p(a.Box,{className:"panel-root",p:5,pt:0,sx:{...h},children:[n(a.Box,{sx:{position:"absolute",left:0,top:0,height:28,zIndex:310},children:n(Bi,{})}),m&&n(Bo,{view:r}),n(No,{}),n(Wa,{viz:t.viz,data:o,loading:f,error:l,height:g,query:d})]})})}),h1="",gy=b.forwardRef(({h:e},t)=>n(a.ActionIcon,{ref:t,className:"react-grid-customDragHandle",sx:{userSelect:"none",cursor:"grab",position:"absolute",top:5,right:e>38?5:20,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",children:n(k.ArrowsMove,{size:16})})),my=b.forwardRef(({handleAxis:e,...t},r)=>n(a.ActionIcon,{ref:r,className:"react-grid-customResizeHandle",sx:{userSelect:"none",cursor:"nwse-resize",position:"absolute",bottom:0,right:0,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",...t,children:n(k.ChevronDownRight,{size:16})})),by=Ot.WidthProvider(Ot),yy=T.observer(({view:e,className:t="layout"})=>{const r=F(),{panels:i,layouts:s}=r.panels.panelsByIDs(e.panelIDs),o=b.useCallback(l=>{l.forEach(({i:d,...c})=>{const f=r.panels.findByID(d);f&&f.layout.set(c)})},[r]),u=(l,d,c,f)=>{c.h<30&&(c.h=30,f.h=30),c.w<4&&(c.w=4,f.w=4)};return n(by,{onLayoutChange:o,className:`dashboard-layout ${t}`,rowHeight:1,cols:36,margin:[0,0],isBounded:!0,isDraggable:!0,isResizable:!0,layout:s,draggableHandle:".react-grid-customDragHandle",resizeHandle:n(my,{}),onResize:u,children:i.map((l,d)=>p("div",{"data-grid":{...l.layout},className:"panel-grid-item",children:[n(gy,{h:l.layout.h}),n(tn,{view:e,panel:l})]},l.id))})}),vy=Ot.WidthProvider(Ot),xy=T.observer(function({view:t,className:r="layout"}){const{panels:i,layouts:s}=F().panels.panelsByIDs(t.panelIDs);return n(vy,{className:`dashboard-layout ${r}`,cols:36,rowHeight:1,margin:[0,0],isDraggable:!1,isResizable:!1,layout:s,children:i.map(o=>n("div",{"data-grid":{...o.layout},className:"panel-grid-item",children:n(tn,{view:t,panel:o})},o.id))})});var Ya=(e=>(e.Use="use",e.Edit="edit",e))(Ya||{}),K=(e=>(e.Division="div",e.Modal="modal",e.Tabs="tabs",e))(K||{});const Cy={div:"Division",tabs:"Tabs",modal:"Modal"},Ra={div:"rgba(255, 0, 0, 0.2)",modal:"rgba(0, 0, 0, 0.2)",tabs:"rgba(255, 200, 100, 0.4)"},wy={div:"#ff4000",modal:"#000",tabs:"#ffad18"},_y={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:"div",config:{},panelIDs:[]}],panels:[],filters:[],version:"8.57.0"};var ar=(e=>(e.Select="select",e.TreeSelect="tree-select",e.MultiSelect="multi-select",e.TextInput="text-input",e.Checkbox="checkbox",e.DateRange="date-range",e))(ar||{});const Sy=T.observer(({children:e})=>n(a.Box,{pt:10,pb:100,children:e})),Ty=T.observer(({children:e,view:t})=>{const r=t.config;return n(a.Modal,{size:r.width,overflow:"inside",opened:!0,onClose:v.noop,withCloseButton:!1,title:r.custom_modal_title.value,trapFocus:!0,onDragStart:i=>{i.stopPropagation()},styles:{root:{position:"relative",height:"100%"},overlay:{position:"absolute !important"},modal:{border:"1px solid #efefef"},body:{maxHeight:"calc(100vh - 325px)"}},withinPortal:!1,transitionDuration:0,children:e})}),ky=({variant:e,orientation:t})=>{const r={tab:{},panel:{padding:"16px"}};return e==="pills"&&t==="horizontal"&&(r.tab.paddingTop="6px",r.tab.paddingBottom="6px"),t==="vertical"&&(r.tab["&.add-a-tab"]={paddingTop:"1px",paddingBottom:"1px"},r.tab["&.add-a-tab .mantine-Tabs-tabLabel"]={marginLeft:"auto",marginRight:"auto"}),r},Dy=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},My=T.observer(({children:e,view:t})=>{const r=Le.useModals(),i=F(),s=b.useMemo(()=>i.views.options.filter(d=>d.type===K.Division),[t.id,i.views.options]),o=t.config,u=d=>r.openConfirmModal({title:"Delete this tab?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{o.removeTab(d)},confirmProps:{color:"red"},zIndex:320}),l=o.tabs.length===0;return p(a.Box,{className:"preview-view-tabs",children:[p(a.Tabs,{variant:o.variant,orientation:o.orientation,defaultValue:o.tabs.length>0?o.tabs[0].id:"0",styles:ky(o),children:[p(a.Tabs.List,{grow:o.grow,children:[o.tabs.map(d=>n(a.Tabs.Tab,{value:d.id,sx:Dy(d),children:d.name??d.id},d.id)),n(a.Tabs.Tab,{onClick:o.addTab,value:"add",className:"add-a-tab",children:n(k.Plus,{size:18,color:"#228be6"})})]}),o.tabs.map((d,c)=>{const f=i.views.findByID(d.view_id);return p(a.Tabs.Panel,{value:d.id,sx:{position:"relative"},children:[p(a.Box,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:200},children:[n(a.Overlay,{opacity:.8,color:"#FFF",blur:10,zIndex:100}),p(a.Stack,{mx:"auto",mt:100,sx:{width:"300px",position:"relative",zIndex:200},children:[n(a.TextInput,{label:"Tab Name",value:d.name,onChange:g=>d.setName(g.currentTarget.value)}),n(a.Select,{label:"View",value:d.view_id,onChange:d.setViewID,data:s}),n(a.ColorInput,{label:"Color",value:d.color,onChange:d.setColor,disabled:o.variant!=="default"}),f&&p(a.Button,{mt:20,variant:"gradient",leftIcon:n(V.IconArrowsLeftRight,{size:18}),gradient:{from:"cyan",to:"indigo"},onClick:()=>i.views.setIDOfVIE(f.id),children:["Swith to View: ",f.name]}),n(a.Button,{mt:20,variant:"subtle",color:"red",onClick:()=>u(c),disabled:l,leftIcon:n(V.IconTrash,{size:14}),children:"Delete This Tab"})]})]}),f&&n(nn,{view:f})]},d.id)})]}),e]})}),Iy=T.observer(({view:e,children:t})=>{switch(e.type){case K.Modal:return n(Ty,{view:e,children:t});case K.Tabs:return n(My,{view:e,children:t});case K.Division:default:return n(Sy,{children:t})}}),Qa=T.observer(function({view:t}){return n(mn.Provider,{value:{viewPanelInFullScreen:v.noop,inFullScreen:!1},children:n(a.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:n(Iy,{view:t,children:p(a.Box,{sx:{position:"relative"},children:[n(a.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:n(Vi,{view:t})}),n(yy,{view:t})]})})})})}),Ay={modal:{display:"flex",flexDirection:"column",flexWrap:"nowrap"},body:{display:"flex",height:"calc(100vh - 88px)"}},$y=T.observer(function({view:t,panel:r,exitFullScreen:i}){return n(a.Modal,{opened:!0,fullScreen:!0,onClose:i,title:n(a.Button,{color:"blue",size:"xs",onClick:i,leftIcon:n(k.ArrowLeft,{size:20}),children:"Exit fullscreen"}),styles:Ay,children:n(a.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:n(tn,{view:t,panel:r})})})});function zy(e,t,r){const{panels:i}=F(),s=e.id==="Main",[o,u]=b.useState(()=>s&&i.findByID(t)?t:null),l=b.useCallback(g=>{u(g),s&&r(g)},[s,r]),d=b.useCallback(()=>{u(null),s&&r("")},[s,r]),c=o?i.findByID(o):null;return{viewPanelInFullScreen:l,exitFullScreen:d,inFullScreen:!!c,fullScreenPanel:c}}const Ey=T.observer(({children:e})=>n(a.Box,{children:e})),Ly=T.observer(({children:e,view:t})=>{const r=F(),i=t.config,s=r.views.visibleViewIDs.includes(t.id),o=()=>r.views.rmVisibleViewID(t.id);return n(a.Modal,{size:i.width,centered:!0,overflow:"inside",opened:s,onClose:o,withCloseButton:!1,title:i.custom_modal_title.value,trapFocus:!0,onDragStart:u=>{u.stopPropagation()},styles:{modal:{border:"1px solid #efefef"},body:{maxHeight:i.height,overflow:"auto"}},transitionDuration:0,children:e})}),Py=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},Oy=T.observer(({children:e,view:t})=>{const r=F(),i=t.config;return p(a.Box,{className:"render-view-tabs",children:[p(a.Tabs,{variant:i.variant,orientation:i.orientation,defaultValue:i.tabs.length>0?i.tabs[0].id:"0",styles:{panel:{padding:i.orientation==="horizontal"?"16px 0px":"0"}},keepMounted:!1,children:[n(a.Tabs.List,{grow:i.grow,children:i.tabs.map(s=>n(a.Tabs.Tab,{value:s.id,sx:Py(s),disabled:!s.view_id,children:s.name??s.id},s.id))}),i.tabs.map(s=>{const o=r.views.findByID(s.view_id);return o?n(a.Tabs.Panel,{value:s.id,children:n(nn,{view:o})},s.id):null})]}),e]})}),Vy=T.observer(({view:e,children:t})=>{switch(e.type){case K.Modal:return n(Ly,{view:e,children:t});case K.Tabs:return n(Oy,{view:e,children:t});case K.Division:default:return n(Ey,{children:t})}}),nn=T.observer(function({view:t}){const{fullScreenPanelID:r,setFullScreenPanelID:i}=Ei(),{viewPanelInFullScreen:s,exitFullScreen:o,inFullScreen:u,fullScreenPanel:l}=zy(t,r,i);return n(mn.Provider,{value:{viewPanelInFullScreen:s,inFullScreen:u},children:p(a.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:[u&&n($y,{view:t,panel:l,exitFullScreen:o}),n(Vy,{view:t,children:p(a.Box,{sx:{position:"relative"},children:[!u&&n(a.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:n(Vi,{view:t})}),!u&&n(xy,{view:t})]})})]})})});function By(e){e=e||{};const t=Object.keys(e).sort(),r=[];for(let i=0;i<t.length;i++){const s=t[i];if(s!="authentication"&&e[s])r.push(t[i]+"="+(typeof e[s]=="object"?JSON.stringify(e[s]):e[s]));else{const o=Object.keys(e[s]).sort();for(let u=0;u<o.length;u++){const l=o[u];l!="sign"&&e[s][l]&&r.push(o[u]+"="+(typeof e[s][l]=="object"?JSON.stringify(e[s][l]):e[s][l]))}}}return r.sort().join("&")}function Ny(e,t){let r=By(e);return r+="&key="+t,Ti.MD5(r).toString().toUpperCase()}const ze={baseURL:"http://localhost:31200",app_id:"",app_secret:"",getAuthentication(e){if(!this.app_id||!this.app_secret)return;const t=new Date().getTime().toString();return{app_id:this.app_id,nonce_str:t,sign:Ny({app_id:this.app_id,nonce_str:t,...e},this.app_secret)}},getRequest(e,t){return(r,i,s={})=>{const o=window.localStorage.getItem("token"),u={"X-Requested-With":"XMLHttpRequest","Content-Type":s.string?"application/x-www-form-urlencoded":"application/json",authorization:o?`bearer ${o}`:"",...s.headers},l={baseURL:this.baseURL,method:e,url:r,params:e==="GET"?i:s.params,headers:u,signal:t};return["POST","PUT"].includes(e)&&(l.data=s.string?JSON.stringify(i):i,l.data.authentication=this.getAuthentication(l.data)),Ue(l).then(d=>d.data).catch(d=>Promise.reject(d))}}};function Ua(e){ze.baseURL!==e.apiBaseURL&&(ze.baseURL=e.apiBaseURL),e.app_id&&(ze.app_id=e.app_id),e.app_secret&&(ze.app_secret=e.app_secret)}const Xa=y.types.model("FilterConfigModel_Checkbox",{_name:y.types.literal("checkbox"),description:y.types.optional(y.types.string,""),default_value:y.types.boolean}).views(e=>({get json(){const{_name:t,description:r,default_value:i}=e;return{_name:t,description:r,default_value:i}},get isDescriptionEmpty(){const{description:t}=e;return t===""||t==="<p></p>"}})).actions(e=>({setDefaultValue(t){e.default_value=t},setDescription(t){e.description=t}})),Gy=()=>Xa.create({_name:"checkbox",description:"",default_value:!1});var ce=(e=>(e.Postgresql="postgresql",e.MySQL="mysql",e.HTTP="http",e))(ce||{}),we=(e=>(e.Select="select",e.MultiSelect="multi-select",e.TreeSelect="tree-select",e.TextInput="text-input",e.Checkbox="checkbox",e.DateRange="date-range",e))(we||{});y.types.model({type:y.types.enumeration("DataSourceType",[ce.Postgresql,ce.MySQL,ce.HTTP]),key:y.types.string,sql:y.types.string});function Za(e,t){return e.map(r=>{try{return r?j.tz(r,"UTC").format(t):null}catch{return console.log(`[date-range] failed parsing ${r}`),null}})}const qy=y.types.model("FilterConfigModel_DateRange",{_name:y.types.literal("date-range"),required:y.types.boolean,inputFormat:y.types.enumeration("DateRangeInputFormat",["YYYY","YYYYMM","YYYYMMDD","YYYY-MM","YYYY-MM-DD"]),default_value:y.types.optional(y.types.array(y.types.union(y.types.string,y.types.null)),[null,null]),clearable:y.types.boolean,max_days:y.types.optional(y.types.number,0),allowSingleDateInRange:y.types.optional(y.types.boolean,!1)}).views(e=>({get json(){const{_name:t,max_days:r,required:i,clearable:s,inputFormat:o,default_value:u,allowSingleDateInRange:l}=e;return{_name:t,max_days:r,required:i,clearable:s,inputFormat:o,default_value:Za(u,o),allowSingleDateInRange:l}},truthy(t){return Array.isArray(t)&&t.length===2&&t.every(r=>!!r)}})).views(e=>({getMaxDate(t){const{max_days:r}=e;if(!(!r||!t))return j(t).startOf("day").add(r,"days").toDate()},getMinDate(t){const{max_days:r}=e;if(!(!r||!t))return j(t).startOf("day").subtract(r,"days").toDate()}})).actions(e=>({setFilterValue(t){try{const r=y.getParent(e);y.getRoot(e).filters.setValueByKey(r.key,t)}catch(r){console.error(r)}}})).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}})),Ka=y.types.snapshotProcessor(qy,{preProcessor({default_value:e,...t}){return{...t,default_value:e.map(r=>r===null?null:j.tz(r,"UTC").toISOString())}},postProcessor(e){const{default_value:t,...r}=e;return{...r,default_value:Za(t,r.inputFormat)}}}),Fy=()=>Ka.create({_name:"date-range",required:!1,inputFormat:"YYYY-MM-DD",clearable:!1,default_value:[null,null]}),Wy=y.types.model({label:y.types.string,value:y.types.string}).actions(e=>({setLabel(t){e.label=t},setValue(t){e.value=t}})),sr=y.types.model("FilterConfigModel_BaseSelect",{static_options:y.types.optional(y.types.array(Wy),[]),options_query_id:y.types.optional(y.types.string,""),default_selection_count:y.types.optional(y.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:r,error:i}=y.getRoot(e).content.getDataStuffByID(e.options_query_id);return r==="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??""}})),rn=e=>v.cloneDeepWith(e,(t,r)=>{if(r!==void 0&&t)return ae.toJS(t)}),Ja=y.types.compose("FilterConfigModel_MultiSelect",y.types.model({_name:y.types.literal("multi-select"),min_width:y.types.optional(y.types.string,""),default_value:y.types.optional(y.types.array(y.types.string),[])}),sr).views(e=>({get json(){const{_name:t,default_value:r,min_width:i,static_options:s,options_query_id:o,default_selection_count:u}=e;return rn({_name:t,min_width:i,default_value:r,static_options:s,options_query_id:o,default_selection_count:u})},get default_selection(){return e.usingQuery?e.options.slice(0,e.default_selection_count).map(t=>t.value):e.default_value}})).actions(e=>({setDefaultValue(t){e.default_value=y.cast(t)},setMinWidth(t){e.min_width=t},setDefaultSelection(){const t=y.getRoot(e).content.filters,r=y.getParent(e).key;t.setValueByKey(r,e.default_selection)}})).actions(e=>({afterCreate(){y.addDisposer(e,ae.reaction(()=>ae.toJS(e.default_selection),e.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),jy=()=>Ja.create({_name:"multi-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),Ha=y.types.compose("FilterConfigModel_TreeSelect",y.types.model({_name:y.types.literal("tree-select"),min_width:y.types.optional(y.types.string,""),default_value:y.types.optional(y.types.array(y.types.string),[])}),sr).views(e=>({get json(){const{_name:t,default_value:r,min_width:i,static_options:s,options_query_id:o,default_selection_count:u}=e;return{_name:t,min_width:i,default_value:r,static_options:s,options_query_id:o,default_selection_count:u}}})).actions(e=>({setDefaultValue(t){e.default_value=y.cast(t)},setMinWidth(t){e.min_width=t}})),Yy=()=>Ha.create({_name:"tree-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),es=y.types.compose("FilterConfigModel_Select",y.types.model({_name:y.types.literal("select"),default_value:y.types.string,required:y.types.boolean,width:y.types.optional(y.types.string,"")}),sr).views(e=>({get json(){const{_name:t,default_value:r,required:i,width:s,static_options:o,options_query_id:u,default_selection_count:l}=e;return rn({_name:t,width:s,required:i,default_value:r,static_options:o,options_query_id:u,default_selection_count:l})},truthy(t){return!!t}})).actions(e=>({setRequired(t){e.required=t},setDefaultValue(t){e.default_value=t},setWidth(t){e.width=t}})),Ry=()=>es.create({_name:"select",required:!1,default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),ts=y.types.model("FilterConfigModel_TextInput",{_name:y.types.literal("text-input"),required:y.types.boolean,default_value:y.types.string}).views(e=>({get json(){const{_name:t,required:r,default_value:i}=e;return{_name:t,required:r,default_value:i}},truthy(t){return typeof t!="string"?!1:!!t.trim()}})).actions(e=>({setRequired(t){e.required=t},setDefaultValue(t){e.default_value=t}})),ns=()=>ts.create({_name:"text-input",required:!1,default_value:""}),or=y.types.model("FilterModel",{id:y.types.identifier,key:y.types.string,label:y.types.string,order:y.types.number,visibleInViewsIDs:y.types.array(y.types.string),auto_submit:y.types.optional(y.types.boolean,!1),type:y.types.enumeration("DashboardFilterType",[we.Select,we.MultiSelect,we.TreeSelect,we.TextInput,we.Checkbox,we.DateRange]),config:y.types.union(es,Ja,Ha,ts,Xa,Ka)}).views(e=>({get plainDefaultValue(){const t=e.config.default_value;return Array.isArray(t)?[...t]:t},get usingDefaultValue(){return e.type!==we.TreeSelect},get auto_submit_supported(){return[we.Select,we.Checkbox,we.DateRange].includes(e.type)}})).views(e=>({get json(){const{id:t,key:r,label:i,order:s,visibleInViewsIDs:o,auto_submit:u,type:l,config:d}=e;return{id:t,key:r,type:l,label:i,order:s,config:d.json,auto_submit:u,visibleInViewsIDs:ae.toJS(o)}},get should_auto_submit(){return e.auto_submit_supported&&e.auto_submit},requiredAndPass(t){return v.get(e.config,"required",!1)?v.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 we.Select:e.config=Ry();break;case we.MultiSelect:e.config=jy();break;case we.TreeSelect:e.config=Yy();break;case we.TextInput:e.config=ns();break;case we.Checkbox:e.config=Gy();break;case we.DateRange:e.config=Fy();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 rs(e,t){if(e===void 0)return e;if(t._name==="date-range")try{const[...r]=e;return r.map(i=>i===null?i:j.tz(i,"UTC").format(t.inputFormat)??i)}catch(r){return console.error(r),e}return e}function is(e){return e.reduce((t,r)=>(t[r.key]=rs(r.config.default_value,r.config),t),{})}function Qy(e,t,r){y.addDisposer(e,y.addMiddleware(e,(i,s)=>{s(i,()=>{y.getType(i.context)===t&&i.type==="action"&&r(i.name,i.context)})}))}const as=y.types.model("FiltersModel",{current:y.types.optional(y.types.array(or),[]),values:y.types.optional(y.types.frozen(),{}),previewValues:y.types.optional(y.types.frozen(),{})}).views(e=>({get json(){return e.current.map(t=>t.json)},get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(r=>r.id===t)},get inOrder(){return v.sortBy(e.current,"order")},get options(){return e.current.map(t=>({label:t.label??t.id,value:t.id,_type:"filter"}))},get empty(){return e.current.length===0},visibleInView(t){return v.sortBy(e.current.filter(r=>r.visibleInViewsIDs.includes(t)),"order")},get firstFilterValueKey(){return Object.keys(e.values)[0]??""},get keyLabelMap(){return e.current.reduce((t,r)=>(t[r.key]=r.label,t),{})}})).actions(e=>({replace(t){e.current=y.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByID(t){const r=e.current.findIndex(i=>i.id===t);r>=0&&e.current.splice(r,1)},setValues(t){e.values=t},setValueByKey(t,r){e.values={...e.values,[t]:r}},getValueByKey(t){return e.values[t]},refreshValues(){console.log("refreshing values"),e.values=is(e.current)},updatePreviewValues(t){e.previewValues=t}})).actions(e=>{function t(){Qy(e.current,or,(r,i)=>{if(r==="setType"){const s=rs(i.config.default_value,i.config);e.setValueByKey(i.key,s),e.updatePreviewValues({...e.previewValues,[i.key]:s})}})}return{afterCreate(){t()}}});function ss(e){return{current:e,values:is(e)}}const os="\uFEFF";function Uy(e,t){const r=new Blob([os+t],{type:"text/csv"});hn.saveAs(r,`${e}.csv`)}function Xy(e,t){const r=new Blob([t],{type:"application/json"});hn.saveAs(r,`${e}.json`)}function Zy(e){const t=new co;e.forEach(({id:r,data:i})=>{t.file(`${r}.csv`,us(i))}),t.generateAsync({type:"blob"}).then(r=>{hn.saveAs(r,"dashboard_data.zip")})}function ls(e){return e.includes(",")?`"${e}"`:e}function us(e){if(!Array.isArray(e)||e.length===0)return"";const t=[],r=Object.keys(e[0]).map(ls);return t.push(r.join(",")),e.forEach(i=>{const s=Object.values(i).map(ls).join(",");t.push(s)}),os+t.join(`
348
348
  `)}const ht={CryptoJS:Ti,d3Array:fo,dayjs:j,lodash:v,numbro:se,mathjs:Nt,faker:po.faker},Ky=[{name:"CryptoJS",url:"https://github.com/brix/crypto-js",version:"4.1.1"},{name:"d3Array",url:"https://github.com/d3/d3-array",version:"3.2.0"},{name:"dayjs",url:"https://day.js.org/",version:"1.11.6"},{name:"lodash",url:"https://lodash.com/docs/4.17.15",version:"4.17.21"},{name:"mathjs",url:"https://mathjs.org/",version:"11.7.0"},{name:"numbro",url:"https://numbrojs.com/",version:"2.3.6"},{name:"faker",url:"https://fakerjs.dev/",version:"7.6.0"}],Jy=e=>`
349
349
  <tr>
350
350
  <td><code>${e.name}</code></td>
@@ -436,7 +436,7 @@ Check the top-level render call using <`+E+">.")}return M}}function eo(_,M){{if(
436
436
  SELECT count(*) AS total
437
437
  FROM ${r}.${t}
438
438
  `}})).actions(e=>({setPage(t){e.page=t},resetPage(){e.page=1},setLimit(t){e.limit=t}})).actions(e=>({afterCreate(){y.addDisposer(e,ae.reaction(()=>e.keywordString,e.resetPage,{fireImmediately:!1,delay:0})),y.addDisposer(e,ae.reaction(()=>e.limit,e.resetPage,{fireImmediately:!1,delay:0}))}})),mv=y.types.model("DataSourceModel",{id:y.types.string,type:y.types.enumeration("DataSourceType",[ce.HTTP,ce.MySQL,ce.Postgresql]),key:y.types.string,config:y.types.frozen(),tables:y.types.optional(fv,{}),columns:y.types.optional(pv,{}),tableData:y.types.optional(gv,{}),indexes:y.types.optional(hv,{}),table_schema:y.types.optional(y.types.string,""),table_name:y.types.optional(y.types.string,"")}).volatile(()=>({controllers:{tables:new AbortController,columns:new AbortController,indexes:new AbortController,tableData:new AbortController}})).actions(e=>({setKeywords(t,r){e.table_schema=t,e.table_name=r}})).actions(e=>({initKeywords(){if(e.tables.empty)return;const t=Object.keys(e.tables.data)[0],r=e.tables.data[t][0].table_name;e.setKeywords(t,r)}})).actions(e=>{const t=y.flow(function*(){var r;(r=e.controllers.tables)==null||r.abort(),e.controllers.tables=new AbortController,e.tables.state="loading";try{const i=yield*y.toGenerator(ze.getRequest("POST",e.controllers.tables.signal)("/query",{type:e.type,key:e.key,query:e.tables.sql},{}));e.tables.data=v.groupBy(i,"table_schema"),e.tables.state="idle",e.tables.error=null,e.initKeywords()}catch(i){if(!Ue.isCancel(i)){e.tables.data={};const s=v.get(i,"message","unkown error");e.tables.error=v.get(i,"response.data.detail.message",s),e.tables.state="error"}}});return{loadTables:t,loadTablesIfEmpty(){e.tables.empty&&t()},loadColumns:y.flow(function*(){var r;(r=e.controllers.columns)==null||r.abort(),e.controllers.columns=new AbortController,e.columns.state="loading";try{e.columns.data=yield*y.toGenerator(ze.getRequest("POST",e.controllers.columns.signal)("/query",{type:e.type,key:e.key,query:e.columns.sql},{})),e.columns.state="idle",e.columns.error=null}catch(i){if(Ue.isCancel(i))e.columns.state="idle",e.columns.error=null;else{e.columns.data=[];const s=v.get(i,"message","unkown error");e.columns.error=v.get(i,"response.data.detail.message",s),e.columns.state="error"}}}),loadIndexes:y.flow(function*(){var r;(r=e.controllers.indexes)==null||r.abort(),e.controllers.indexes=new AbortController,e.indexes.state="loading";try{e.indexes.data=yield*y.toGenerator(ze.getRequest("POST",e.controllers.indexes.signal)("/query",{type:e.type,key:e.key,query:e.indexes.sql},{})),e.indexes.state="idle",e.indexes.error=null}catch(i){if(Ue.isCancel(i))e.indexes.state="idle",e.indexes.error=null;else{e.indexes.data=[];const s=v.get(i,"message","unkown error");e.indexes.error=v.get(i,"response.data.detail.message",s),e.indexes.state="error"}}}),loadTableData:y.flow(function*(){var i;(i=e.controllers.tableData)==null||i.abort(),e.controllers.tableData=new AbortController;const r=e.tableData;r.state="loading";try{r.data=yield*y.toGenerator(ze.getRequest("POST",e.controllers.tableData.signal)("/query",{type:e.type,key:e.key,query:r.sql},{}));const[{total:s}]=yield*y.toGenerator(ze.getRequest("POST",e.controllers.tableData.signal)("/query",{type:e.type,key:e.key,query:r.countSql},{}));r.total=Number(s),r.state="idle",r.error=null}catch(s){if(Ue.isCancel(s))r.state="idle",r.error=null;else{r.data=[];const o=v.get(s,"message","unkown error");r.error=v.get(s,"response.data.detail.message",o),r.state="error"}}})}}).actions(e=>({afterCreate(){y.addDisposer(e,ae.reaction(()=>e.columns.sql,e.loadColumns,{fireImmediately:!1,delay:500}))}})).actions(e=>({afterCreate(){y.addDisposer(e,ae.reaction(()=>e.indexes.sql,e.loadIndexes,{fireImmediately:!1,delay:500})),y.addDisposer(e,ae.reaction(()=>e.tableData.sql,e.loadTableData,{fireImmediately:!1,delay:0}))}})),bv=y.types.model("DataSourcesModel",{list:y.types.optional(y.types.array(mv),[])}).views(e=>({find({type:t,key:r}){return e.list.find(i=>i.key===r&&i.type===t)},get options(){return e.list.map(t=>({value:t.key,label:t.key}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}}));function an(e){return{label:e,value:e,_type:"ACTION",_action_type:e,Icon:null,children:null}}function yv(e){switch(e._type){case"GROUP":case"ACTION":return null;case"global_variables":return["_GLOBAL_VARS_"];case"mock_context":return["_MOCK_CONTEXT_"];case"filter":return["_FILTERS_",e.value];case"sql_snippet":return["_SQL_SNIPPETS_",e.value];case"query":return["_QUERIES_",e.value];case"view":return["_VIEWS_",e.value];case"panel":return e.parentID?["_VIEWS_",e.parentID,"_PANELS_",e.value]:(console.error("[getPathFromOption] parentID is required"),null)}}const vv=y.types.model("EditorModel",{path:y.types.optional(y.types.frozen(),[]),settings_open:y.types.optional(y.types.boolean,!1)}).views(e=>({get navOptions(){const{content:t}=y.getRoot(e),{filters:r,views:i,sqlSnippets:s,queries:o}=t;return[{label:"Global Variables",value:"_GLOBAL_VARS_",_type:"global_variables",Icon:V.IconVariable},{label:"Mock Context",value:"_MOCK_CONTEXT_",Icon:V.IconCodeDots,_type:"mock_context"},{label:"Filters",value:"_FILTERS_",Icon:V.IconFilter,children:[...r.options,an("_Add_A_Filter_")],_type:"GROUP"},{label:"SQL Snipepts",value:"_SQL_SNIPPETS_",Icon:V.IconCopy,children:[...s.options,an("_Add_A_SQL_SNIPPET_")],_type:"GROUP"},{label:"Queries",value:"_QUERIES_",Icon:V.IconDatabase,children:[...o.options,an("_Add_A_QUERY_")],_type:"GROUP"},{label:"Views",value:"_VIEWS_",Icon:V.IconBoxMultiple,children:[...i.editorOptions,an("_Add_A_VIEW_")],_type:"GROUP"}]},isOptionActive(t,r){return t.length===0?!1:t[t.length-1]===r.value},isOptionOpened(t){const{path:r}=e;return r.length===0||!t.children||t.children.length===0?!1:r.includes(t.value)}})).actions(e=>({setPath(t){e.path=t},setSettingsOpen(t){e.settings_open=t}})).actions(e=>({open(t){e.setPath(t),e.setSettingsOpen(!0)},close(){e.setSettingsOpen(!1)},navigate(t){const r=yv(t);r&&e.setPath(r)}})),xv=y.types.model("MockContextModel",{current:y.types.optional(y.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,r){e.current[t]=r}})),Cv=y.types.model("VariableModel",{name:y.types.string,size:y.types.string,weight:y.types.string,color:y.types.union(y.types.model({type:y.types.literal("static"),staticColor:y.types.string}),y.types.model({type:y.types.literal("continuous"),valueRange:y.types.array(y.types.number),colorRange:y.types.array(y.types.string)}),y.types.model({type:y.types.literal("piecewise")})),formatter:y.types.model({output:y.types.enumeration("Output",["number","percent"]),average:y.types.optional(y.types.boolean,!1),mantissa:y.types.number,trimMantissa:y.types.optional(y.types.boolean,!1)}),data_field:y.types.string,aggregation:y.types.union(y.types.model({type:y.types.enumeration(["none","sum","mean","median","min","max","CV","std"]),config:y.types.frozen()}),y.types.model({type:y.types.literal("quantile"),config:y.types.model({p:y.types.number})}))}).views(e=>({get json(){const{name:t,size:r,weight:i,color:s,formatter:o,data_field:u,aggregation:l}=e;return v.cloneDeep({name:t,size:r,color:s,weight:i,formatter:o,data_field:u,aggregation:l})}}));class wv{constructor(t){P(this,"origin");P(this,"copy");this.origin=t,this.copy=y.clone(t),ae.makeAutoObservable(this,{},{autoBind:!0,deep:!1})}get changed(){return!v.isEqual(y.getSnapshot(this.origin),y.getSnapshot(this.copy))}commit(){y.applySnapshot(this.origin,y.getSnapshot(this.copy))}update(t){y.applySnapshot(this.copy,t)}}const _v=e=>new wv(e),Sv=y.types.model("PanelLayoutModel",{x:y.types.number,y:y.types.maybeNull(y.types.number),w:y.types.number,h:y.types.number,moved:y.types.optional(y.types.boolean,!1),static:y.types.optional(y.types.boolean,!1)}).views(e=>({get json(){const{x:t,y:r,w:i,h:s,moved:o}=e;return{h:s,w:i,x:t,y:r===null?0:r,moved:o,static:e.static}}})).actions(e=>({set(t){const{x:r,y:i,w:s,h:o,moved:u}=t;e.x=r,e.y=i,e.w=s,e.h=o,e.moved=!!u,e.static=!!t.static}})),Tv=y.types.model("PanelStyleBorderModel",{enabled:y.types.boolean}).views(e=>({get json(){const{enabled:t}=e;return{enabled:t}}})).actions(e=>({setEnabled(t){e.enabled=t}})),kv=y.types.model("PanelStyleModel",{border:Tv}).views(e=>({get json(){const{border:t}=e;return{border:t.json}}})).actions(e=>({})),Dv=y.types.model("PanelVizModel",{type:y.types.string,conf:y.types.frozen()}).views(e=>({get json(){return{conf:e.conf,type:e.type}}})).actions(e=>({setType(t){e.type=t},setConf(t){e.conf=t}})),ms=y.types.model({id:y.types.string,title:y.types.string,description:y.types.string,layout:Sv,queryID:y.types.string,viz:Dv,style:kv,variables:y.types.optional(y.types.array(Cv),[])}).views(e=>({get query(){return y.getParentOfType(e,It).queries.findByID(e.queryID)},get json(){const{id:t,title:r,description:i,queryID:s}=e;return{id:t,viz:e.viz.json,style:e.style.json,title:r,layout:e.layout.json,queryID:s,variables:e.variables.map(o=>o.json),description:i}}})).actions(e=>({setID(t){e.id=t},setTitle(t){e.title=t},setDescription(t){e.description=t},setQueryID(t){if(y.getParentOfType(e,It).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)},removeSelf(){y.getParent(e,2).removeByID(e.id)}})).actions(e=>({moveToView(t,r){y.getRoot(e).content.views.findByID(t).removePanelID(e.id),y.getRoot(e).content.views.findByID(r).appendPanelID(e.id),y.getRoot(e).editor.setPath(["_VIEWS_",r,"_PANELS_",e.id])}}));function bs(e){return{id:e,layout:{x:0,y:1/0,w:18,h:300},title:e,description:"<p></p>",queryID:"",viz:{type:Un.name,conf:Un.createConfig()},style:{border:{enabled:!0}}}}const ys=y.types.model("PanelsModel",{list:y.types.optional(y.types.array(ms),[])}).views(e=>({get json(){return e.list.map(t=>t.json)},findByID(t){return e.list.find(r=>r.id===t)},get idMap(){const t=new Map;return e.list.forEach(r=>{t.set(r.id,r)}),t}})).views(e=>({panelsByIDs(t){const r=[];t.forEach(s=>{const o=e.idMap.get(s);o?r.push(o):console.warn(`Panel is not found, id:${s}`)});const i=r.map(s=>({...s.layout.json,i:s.id}));return{panels:r,layouts:i}}})).views(e=>({editorOptions(t,r){const{panels:i}=e.panelsByIDs(r);i.length!==r.length&&console.warn(`Unfulfilled panels for View[${t}]`);const s=i.map(u=>({label:u.title?u.title:v.capitalize(u.viz.type),value:u.id,_type:"panel",parentID:t})),o="_Add_A_PANEL_";return s.push({label:o,value:o,_type:"ACTION",_action_type:o,parentID:t,Icon:null,children:null}),s}})).actions(e=>({replace(t){e.list=y.castToSnapshot(t)},append(t){e.list.push(t)},remove(t){e.list.splice(t,1)},removeByID(t){const r=e.list.findIndex(i=>i.id===t);r!==-1&&e.list.splice(r,1)},duplicateByID(t){const r=e.list.find(s=>s.id===t);if(!r){console.error(new Error(`[duplicate panel] Can't find a panel by id[${t}]`));return}const i=new Date().getTime().toString();return e.list.push({...r.json,id:i,layout:{...r.layout,y:1/0,moved:!1}}),i},replaceByIndex(t,r){e.list.splice(t,1,r)}})),vs=y.types.model("ViewModel_Division",{_name:y.types.literal(K.Division)}).views(e=>({get json(){const{_name:t}=e;return{_name:t}}})).actions(e=>({})),Mv=()=>vs.create({_name:K.Division}),cr={enabled:!1,func_content:["function text({ filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
439
- `)},Iv=y.types.model("CustomModalTitleModel",{enabled:y.types.optional(y.types.boolean,!1),func_content:y.types.optional(y.types.string,"")}).views(e=>({get json(){const{enabled:t,func_content:r}=e;return{enabled:t,func_content:r}},get value(){const{enabled:t,func_content:r}=e,i=y.getParent(e,2),s=y.getRoot(e);if(!t)return i.name;try{const o={filters:s.filters.values,context:s.context.current};return new Function(`return ${r}`)()(o)}catch(o){return console.error(o),i.name}}})).actions(e=>({setEnabled(t){e.enabled=t},setFuncContent(t){e.func_content=t},replace({enabled:t,func_content:r}){e.enabled=t,e.func_content=r}})),xs=y.types.model("ViewModel_Modal",{_name:y.types.literal(K.Modal),width:y.types.string,height:y.types.string,custom_modal_title:y.types.optional(Iv,cr)}).views(e=>({get json(){const{_name:t,width:r,height:i,custom_modal_title:s}=e;return{_name:t,width:r,height:i,custom_modal_title:s.json}}})).actions(e=>({setWidth(t){e.width=t},setHeight(t){e.height=t}})),Av=()=>xs.create({_name:K.Modal,width:"90vw",height:"90vh"}),$v=y.types.model("ViewModel_Tabs_Tab",{id:y.types.identifier,name:y.types.string,view_id:y.types.string,color:y.types.optional(y.types.string,"")}).views(e=>({get json(){const{id:t,name:r,view_id:i,color:s}=e;return{id:t,name:r,color:s,view_id:i}}})).actions(e=>({setName(t){e.name=t},setViewID(t){e.view_id=t},setColor(t){e.color=t}})),Cs=y.types.model("ViewModel_Tabs",{_name:y.types.literal(K.Modal),tabs:y.types.optional(y.types.array($v),[]),variant:y.types.optional(y.types.enumeration("variant",["default","outline","pills"]),"default"),orientation:y.types.optional(y.types.enumeration("orientation",["horizontal","vertical"]),"horizontal"),grow:y.types.optional(y.types.boolean,!1)}).views(e=>({get json(){const{_name:t,variant:r,orientation:i,tabs:s,grow:o}=e;return{grow:o,tabs:s.map(u=>u.json),_name:t,variant:r,orientation:i}}})).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=y.cast(t)},addTab(){const t=ve.randomId(),r={id:t,name:t,view_id:""};e.tabs.push(r)},removeTab(t){e.tabs.splice(t,1)}})),zv=()=>Cs.create({_name:K.Modal,tabs:[]}),ws=y.types.model({id:y.types.identifier,name:y.types.string,type:y.types.enumeration("EViewComponentType",[K.Division,K.Modal,K.Tabs]),config:y.types.union(vs,xs,Cs),panelIDs:y.types.optional(y.types.array(y.types.string),[])}).views(e=>({get json(){const{id:t,name:r,type:i,config:s}=e;return{id:t,name:r,type:i,config:s.json,panelIDs:e.panelIDs}}})).actions(e=>({setName(t){e.name=t},setType(t){if(e.type!==t){switch(t){case K.Division:e.config=Mv();break;case K.Modal:e.config=Av();break;case K.Tabs:e.config=zv();break}e.type=t}},appendPanelID(t){e.panelIDs.push(t)},removePanelID(t){const r=e.panelIDs.filter(i=>i!==t);e.panelIDs.length=0,e.panelIDs.push(...r)}})).actions(e=>({})),_s=y.types.model("ViewsModel",{current:y.types.optional(y.types.array(ws),[]),visibleViewIDs:y.types.array(y.types.string),idOfVIE:y.types.string}).views(e=>({get json(){return e.current.map(t=>rn(t.json))},get idMap(){const t=new Map;return e.current.forEach(r=>{t.set(r.id,r)}),t},findByID(t){return e.current.find(r=>r.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:r})=>r===t)},get visibleViews(){const t=new Set(e.visibleViewIDs);return e.current.filter(({id:r})=>t.has(r))},get VIE(){return e.current.find(({id:t})=>t===e.idOfVIE)},get options(){return e.current.map(t=>({label:t.name,value:t.id,type:t.type}))},get editorOptions(){const t=y.getRoot(e).content.panels;return e.current.map(r=>({label:r.name,value:r.id,_type:"view",children:t.editorOptions(r.id,r.panelIDs)}))}})).actions(e=>({replace(t){e.current.replace(t)},addANewView(t,r,i,s){e.current.push({id:t,name:r,type:i,config:s,panelIDs:[]})},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByID(t){const r=e.current.findIndex(i=>i.id===t);r!==-1&&e.current.splice(r,1)},replaceByIndex(t,r){e.current.splice(t,1,r)},setIDOfVIE(t){e.idOfVIE=t,e.visibleViewIDs.length=0,e.visibleViewIDs.push(t)},appendToVisibles(t){new Set(e.visibleViewIDs.map(i=>i)).has(t)||e.visibleViewIDs.push(t)}})).actions(e=>({addARandomNewView(){const t=new Date().getTime().toString();e.addANewView(t,K.Division,K.Division,{_name:K.Division}),e.setIDOfVIE(t)},removeVIE(){e.current.length!==1&&(e.removeByID(e.idOfVIE),e.setIDOfVIE(e.current[0].id))},rmVisibleViewID(t){const r=e.visibleViewIDs.findIndex(i=>i===t);r!==-1&&e.visibleViewIDs.splice(r,1)}}));function pr(e){const t=e.length>0?[e[0].id]:[],r=e.length>0?e[0].id:"";return{current:e.map(s=>{const{_name:o=s.type}=s.config;return{...s,config:{...s.config,_name:o},panelIDs:s.panelIDs}}),visibleViewIDs:t,idOfVIE:r}}const Ev=y.types.model({id:y.types.string,name:y.types.string,dashboard_id:y.types.string,create_time:y.types.string,update_time:y.types.string,version:y.types.string,filters:as,queries:ps,sqlSnippets:fs,views:_s,panels:ys,mock_context:xv,origin:y.types.maybe(y.types.frozen())}).views(e=>({get json(){return{id:e.id,name:e.name,create_time:e.create_time,update_time:e.update_time,dashboard_id:e.dashboard_id,content:{views:e.views.json,panels:e.panels.json,filters:e.filters.json,version:e.version,definition:{queries:e.queries.json,sqlSnippets:e.sqlSnippets.json,mock_context:e.mock_context.current}}}},get filtersChanged(){const t="filters.current";return!v.isEqual(y.getSnapshot(v.get(e,t)),v.get(e.origin,t))},get queriesChanged(){const t="queries.current",r=y.getSnapshot(v.get(e,t)).map(i=>v.pick(i,["id","name","key","type","sql","run_by","pre_process","post_process"]));return!v.isEqual(r,v.get(e.origin,t))},get sqlSnippetsChanged(){const t="sqlSnippets.current";return!v.isEqual(y.getSnapshot(v.get(e,t)),v.get(e.origin,t))},get viewsChanged(){const t="views.current";return!v.isEqual(y.getSnapshot(v.get(e,t)),v.get(e.origin,t))},get panelsChanged(){const t="panels.list";return!v.isEqual(y.getSnapshot(v.get(e,t)),v.get(e.origin,t))},get mockContextChanged(){const t="mock_context.current";return!v.isEqual(v.get(e,t),v.get(e.origin,t))},get payloadForSQL(){return{context:y.getParent(e).context.current,mock_context:e.mock_context.current,sqlSnippets:e.sqlSnippets.current,filterValues:e.filters.values}},get changed(){return this.filtersChanged||this.queriesChanged||this.sqlSnippetsChanged||this.viewsChanged||this.panelsChanged||this.mockContextChanged},get data(){return e.queries.current.map(({id:r,data:i})=>({id:r,data:i})).reduce((r,i)=>(r[i.id]=i.data,r),{})},getDataStuffByID(t){const r=e.queries.findByID(t);return r?{data:r.data.toJSON(),dataProxy:r.data,len:r.data.length,state:r.state,error:r.error}:{data:[],dataProxy:null,len:0,state:"idle",error:void 0}},getDataStateByID(t){var r;return((r=e.queries.findByID(t))==null?void 0:r.state)??[]},getDataErrorByID(t){var r;return((r=e.queries.findByID(t))==null?void 0:r.error)??[]}})).views(e=>({findQueryUsage(t){const r=e.panels.idMap,i=e.views.current.flatMap(u=>u.panelIDs.map(l=>r.get(l)).filter(l=>(l==null?void 0:l.queryID)===t).map(l=>({type:"panel",id:l.id,label:l.title?l.title:l.viz.type,views:[{id:u.id,label:u.name}]}))),s=e.views.idMap,o=e.filters.current.filter(u=>v.get(u,"config.options_query_id")===t).map(u=>({type:"filter",id:u.id,label:u.label,views:u.visibleInViewsIDs.map(l=>{var d;return{id:l,label:((d=s.get(l))==null?void 0:d.name)??l}})}));return i.concat(o)}})).actions(e=>({duplicatePanelByID(t,r){var s;const i=e.panels.duplicateByID(t);i&&((s=e.views.findByID(r))==null||s.appendPanelID(i))},removePanelByID(t,r){var i;e.panels.removeByID(t),(i=e.views.findByID(r))==null||i.removePanelID(t)},addANewPanel(t){var i;const r=new Date().getTime().toString();e.panels.append(bs(r)),(i=e.views.findByID(t))==null||i.appendPanelID(r)}})).actions(e=>({reset(){y.applySnapshot(e.filters.current,e.origin.filters.current),y.applySnapshot(e.queries.current,e.origin.queries.current),y.applySnapshot(e.sqlSnippets.current,e.origin.sqlSnippets.current),y.applySnapshot(e.views.current,e.origin.views.current),y.applySnapshot(e.panels.list,e.origin.panels.list),e.mock_context.current=e.origin.mock_context.current},resetFilters(){y.applySnapshot(e.filters.current,e.origin.filters.current)},updateCurrent(t){const{id:r,name:i,content:s}=t;if(!s)throw new Error("unexpected null content when updating a content model");const{version:o,filters:u,views:l,panels:d,definition:{queries:c,sqlSnippets:f,mock_context:g={}}}=s;e.id=r,e.name=i,e.version=o,y.applySnapshot(e.filters.current,u),y.applySnapshot(e.views.current,pr(l).current),y.applySnapshot(e.panels.list,d),y.applySnapshot(e.queries.current,c),y.applySnapshot(e.sqlSnippets.current,f),e.mock_context.current=g}})),It=y.types.snapshotProcessor(Ev,{preProcessor(e){return{...e,origin:e}},postProcessor(e){delete e.origin;const t=y.castToSnapshot(e.queries.current.map(r=>v.pick(r,["id","key","type","sql"])));return v.defaults({},{queries:{current:t}},e)}});function Lv(e,t){t.filters&&y.applySnapshot(e.filters.current,t.filters)}function Ss({id:e,name:t,dashboard_id:r,create_time:i,update_time:s,content:o}){if(!o)throw new Error("unexpected null content when creating a content model");const{version:u,filters:l,views:d,panels:c,definition:{queries:f,sqlSnippets:g,mock_context:h={}}}=o;return It.create({id:e,name:t,dashboard_id:r,create_time:i,update_time:s,version:u,filters:ss(l),queries:{current:f},sqlSnippets:{current:g},mock_context:{current:h},views:pr(d),panels:{list:c}})}const Ts=y.types.model({id:y.types.identifier,name:y.types.string,group:y.types.string,content:It,content_id:y.types.string,datasources:bv,context:gs,editor:vv}).views(e=>({get json(){return{id:e.id,name:e.name,group:e.group,content_id:e.content_id}}})).actions(e=>({updateCurrentContent(t){e.content.updateCurrent(t)},updateCurrent(t,r){const{id:i,name:s,group:o,content_id:u}=t;e.id=i,e.name=s,e.group=o,e.content_id=u,this.updateCurrentContent(r)}}));function hr({id:e,name:t,group:r,content_id:i},s,o,u){return Ts.create({id:e,name:t,group:r,content_id:i,content:Ss(s),datasources:{list:o},context:{current:u},editor:{}})}function fr(e){return b.useCallback(t=>t.provideValue(me.pluginManager,e.pluginManager).provideValue(me.vizManager,e.vizManager).provideValue(me.colorManager,e.colorManager),[])}const f1="",Pv=T.observer(({headerMenuItems:e=null})=>{const t=F(),r=()=>{const i=JSON.stringify(t.json,null,2);Xy(t.name,i)};return p(a.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:310,children:[n(a.Menu.Target,{children:n(a.ActionIcon,{variant:"light",color:"blue",children:n(V.IconMenu2,{size:14})})}),p(a.Menu.Dropdown,{children:[n(a.Menu.Item,{icon:n(V.IconDownload,{size:14}),onClick:t.queries.downloadAllData,children:"Download Data"}),n(a.Menu.Item,{icon:n(V.IconCode,{size:14}),onClick:r,children:"Download Schema"}),e]})]})}),Ov=T.observer(({saveDashboardChanges:e})=>{const t=Le.useModals(),r=F(),i=()=>{t.openConfirmModal({title:p(a.Group,{position:"left",children:[n(V.IconAlertTriangle,{size:18,color:"red"}),n(a.Text,{children:"You are reverting changes"})]}),labels:{confirm:"Confirm",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:()=>r.reset(),zIndex:320,withCloseButton:!1})},s=r.changed;return p(a.Group,{spacing:0,children:[n(a.Button,{color:"green",variant:"filled",size:"xs",leftIcon:n(V.IconDeviceFloppy,{size:18}),onClick:e,disabled:!s,sx:{borderTopRightRadius:0,borderBottomRightRadius:0},children:"Save Changes"}),p(a.Menu,{width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:320,disabled:!s,children:[n(a.Menu.Target,{children:n(a.ActionIcon,{variant:"default",disabled:!s,sx:{height:"30px",borderTopLeftRadius:0,borderBottomLeftRadius:0,svg:{fill:"rgb(173, 181, 189)",stroke:"none"}},children:n(V.IconCaretDown,{size:18})})}),n(a.Menu.Dropdown,{children:n(a.Menu.Item,{icon:n(V.IconRecycle,{size:14,color:"red"}),disabled:!s,onClick:i,children:"Revert Changes"})})]})]})}),Vv=T.observer(({saveDashboardChanges:e,headerSlot:t=null,headerMenuItems:r})=>{const i=ho.useNavigate(),s=ye(),o=()=>{i(`/dashboard/${s.id}`)},u=Le.useModals(),l=()=>{u.openConfirmModal({title:p(a.Group,{position:"left",children:[n(V.IconAlertTriangle,{size:18,color:"red"}),n(a.Text,{children:"There are unsaved changes"})]}),labels:{confirm:"Discard",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:o,zIndex:320,withCloseButton:!1})},d=s.content.changed;return n(a.Header,{height:60,px:"md",py:0,sx:{zIndex:299},children:p(a.Group,{position:"apart",sx:{height:60,minWidth:"1000px",position:"relative"},children:[p(a.Group,{children:[n(a.Button,{size:"xs",color:d?"red":"green",leftIcon:n(V.IconArrowLeft,{size:20}),onClick:d?l:o,children:p(a.Group,{spacing:4,children:["End Editing",n(a.Text,{td:"underline",children:s.name})]})}),n(Ov,{saveDashboardChanges:e})]}),p(a.Group,{position:"right",sx:{flexGrow:1},children:[t,n(Pv,{headerMenuItems:r})]})]})})}),Bv={position:"fixed",top:60,left:0,right:0,height:30,zIndex:299,borderBottom:"1px solid #e9ecef",background:"rgba(233,236,239, 0.15)"},Nv=T.observer(()=>{const e=F();return n(a.Box,{sx:Bv,pl:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},children:p(a.Group,{position:"apart",align:"center",sx:{height:"30px"},pr:16,children:[n(a.Button,{variant:"outline",color:"blue",radius:0,size:"xs",disabled:!e.views.VIE,onClick:()=>e.addANewPanel(e.views.idOfVIE),leftIcon:n(V.IconPlaylistAdd,{size:20}),sx:{height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef",background:"rgb(231, 245, 255)"},children:"Add a Panel"}),n(a.Box,{}),n(a.Box,{})]})})}),Gv=T.observer(e=>p(O,{children:[n(Vv,{...e}),n(Nv,{})]})),g1="";function qv(e,t,r){const i=[];return e.filter(s=>"__INTERACTIONS"in s.viz.conf).forEach((s,o)=>{const u=t[s.id];u.data.interactions=v.get(u,"data.interactions",[]);const{__INTERACTIONS:l,__OPERATIONS:d,__TRIGGERS:c}=s.viz.conf;Object.entries(d).forEach(([f,g])=>{const{schemaRef:h,data:m}=g,{config:w}=m;switch(h){case"builtin:op:open-link":let C=w.urlTemplate.substring(0,100);w.urlTemplate.length>=20&&(C+="..."),u.type="interaction",u.data.interactions.push({schemaRef:h,urlTemplate:w.urlTemplate,shortURLTemplate:C});return;case"builtin:op:open_view":i.push({id:`OPERATION--${f}`,source:s.id,target:w.viewID,label:"Open View",style:{stroke:"rgba(0,0,0,0.8)"},type:"default"});return;case"builtin:op:set_filter_values":u.type="interaction",u.data.interactions.push({schemaRef:h,filters:Object.keys(w.dictionary).map(S=>({key:S,label:r[S]}))});return;case"builtin:op:clear_filter_values":u.type="interaction",u.data.interactions.push({schemaRef:h,filters:w.filter_keys.map(S=>({key:S,label:r[S]}))});return;default:return}})}),i}function Fv(e,t){const r=e.filters.keyLabelMap;return{edges:qv(e.panels.list,t,r),edgeNodes:[]}}function ks(e,t,r){return e*t+e*r}function Wv(e,t,r){return e*t+(e-1)*r}const sn=25,gr=40,Ds=25,mr=350,jv=150,Yv=150,Ms=150,Is=300,on=40,As=25,Rv=300;function Qv(e,t){const r=v.keyBy(t,s=>s.id),i=[];return e.current.forEach((s,o)=>{s.panelIDs.forEach((u,l)=>{const d=ks(l,on,As)+gr,c=r[u];if(!c){i.push({id:u,_node_type:"panel",parentNode:s.id,data:{label:`!: ${u}`},position:{x:sn,y:d},sourcePosition:xe.Position.Right,targetPosition:xe.Position.Left,style:{width:Is,height:on}});return}const f=c.title.trim()?`${c.title}`:c.viz.type;i.push({id:c.id,_node_type:"panel",parentNode:s.id,data:{label:f},position:{x:sn,y:d},sourcePosition:xe.Position.Right,targetPosition:xe.Position.Left,style:{width:Is,height:on}})})}),i}const Uv={[K.Division]:"Div",[K.Modal]:"Modal",[K.Tabs]:"Tabs"},Xv=Ra;function Zv(e){return e.current.map((r,i)=>{const s=Wv(r.panelIDs.length,on,As)+gr+Ds;let o=[];return r.type===K.Tabs&&(o=r.config.tabs.map(l=>l.view_id)),{id:r.id,_node_type:"view-root",_view_type:r.type,_view_level:0,_sub_view_ids:[],_tab_view_ids:o,data:{label:`${Uv[r.type]}:${r.name}`},position:{x:0,y:0},sourcePosition:xe.Position.Right,targetPosition:xe.Position.Left,className:"light",style:{backgroundColor:Xv[r.type],width:mr,height:s}}})}function Kv(e){const t=v.keyBy(e,r=>r.id);e.forEach(r=>{r._node_type!=="view-root"||r._view_type!==K.Tabs||r._tab_view_ids.forEach(i=>{t[i].parentNode=r.id})})}function Jv(e){const t=Zv(e.views);Kv(t);const r=Qv(e.views,e.panels.list);return[...t,...r]}function Hv({nodeMap:e,nodes:t,edges:r}){t.forEach(i=>{i._node_type!=="view-root"||i._view_type!==K.Tabs||(i.sourcePosition=xe.Position.Bottom,i.style.width=mr+sn*2,i.style.height=Ds+i._tab_view_ids.reduce((s,o)=>{const u=e[o];u.position.y=s,u.position.x=sn;const l=u.style.height;return s+l+20},gr))})}function ex({nodeMap:e,nodes:t,edges:r}){r.filter(i=>i.label==="Open View").forEach(i=>{const s=e[i.source],o=e[i.target];if(!s||!o||!s.parentNode)return;const u=e[s.parentNode];u._node_type!=="view-root"||o._node_type!=="view-root"||(o._view_level+=1+u._view_level,u._sub_view_ids.push(o.id))}),t.sort((i,s)=>i._node_type==="view-root"&&s._node_type==="view-root"?i._view_level-s._view_level:i._node_type!=="view-root"&&s._node_type!=="view-root"?0:i._node_type==="view-root"?-1:1)}function tx({nodeMap:e,nodes:t,edges:r}){const i={};r.forEach(s=>{if(s.label!=="Open View")return;const o=e[s.source],u=e[s.target];if(o&&u&&o.parentNode){const l=e[o.parentNode],d=l.position.x,c=Number(v.get(u,"style.height",0)),f=Number(l.style.width);u.position.x=d+f+Rv,l._view_level===0&&u._sub_view_ids.length===0&&(o.sourcePosition=xe.Position.Left,u.targetPosition=xe.Position.Right,u.position.x*=-1);const h=u.position.x,m=v.get(i,h,0);u.position.y=m,i[h]=m+c+Ms}})}function nx({nodeMap:e,nodes:t,edges:r}){const i=new Set,s=new Set;r.forEach(u=>{i.add(u.source),s.add(u.target)}),t.filter(u=>u._node_type!=="view-root"||u.id==="Main"||u.parentNode?!1:!i.has(u.id)&&!s.has(u.id)).forEach((u,l)=>{u.position.x=ks(l,mr,Yv),u.position.y=0-jv-Ms})}function rx({nodeMap:e,nodes:t,edges:r}){const i={nodeMap:e,nodes:t,edges:r};return nx(i),ex(i),Hv(i),tx(i),{nodes:t,edges:r}}function ix(e){const t=Jv(e),r=v.keyBy(t,d=>d.id),{edges:i,edgeNodes:s}=Fv(e,r),o=[...t,...s],u=v.keyBy(o,d=>d.id),l={edges:v.uniqBy(i,d=>d.id),nodes:o,nodeMap:u};return rx(l)}const m1="",br={"builtin:op:open-link":n(a.ThemeIcon,{color:"blue",size:20,radius:"xl",children:n(V.IconCircleDashed,{size:14})}),"builtin:op:set_filter_values":n(a.ThemeIcon,{color:"orange",size:20,radius:"xl",children:n(V.IconCircleDot,{size:14})}),"builtin:op:clear_filter_values":n(a.ThemeIcon,{color:"orange",size:20,radius:"xl",children:n(V.IconCircleOff,{size:14})})};function ax(e){const t=[];return e.forEach(r=>{switch(r.schemaRef){case"builtin:op:open-link":t.push({key:r.urlTemplate,icon:br[r.schemaRef],text:p(a.Group,{spacing:4,children:[n(a.Text,{children:"Open: "}),n(a.Text,{color:"dimmed",children:r.shortURLTemplate})]})});return;case"builtin:op:set_filter_values":r.filters.forEach(({key:i,label:s})=>{t.push({key:r.schemaRef+i,icon:br[r.schemaRef],text:n(a.Group,{spacing:4,children:p(a.Text,{children:["Set Filter: ",s]})})})});return;case"builtin:op:clear_filter_values":r.filters.forEach(({key:i,label:s})=>{t.push({key:r.schemaRef+i,icon:br[r.schemaRef],text:n(a.Group,{spacing:4,children:p(a.Text,{children:["Clear Filter: ",s]})})})});return}}),t}const sx=b.memo(({data:e,isConnectable:t,sourcePosition:r=xe.Position.Right,targetPosition:i=xe.Position.Left,...s})=>{const o=b.useMemo(()=>ax(e.interactions),[e.interactions]);return p(O,{children:[n(xe.Handle,{type:"target",position:i,isConnectable:t}),n(a.Box,{sx:{position:"absolute",top:0,right:0},children:n(k.ChevronsUpRight,{size:12})}),p(a.HoverCard,{shadow:"xl",withinPortal:!0,children:[n(a.HoverCard.Target,{children:n(a.Text,{children:e.label})}),n(a.HoverCard.Dropdown,{children:n(a.List,{spacing:"xs",size:"sm",center:!0,children:o.map(u=>n(a.List.Item,{icon:u.icon,children:u.text},u.key))})})]}),n(xe.Handle,{type:"source",position:r,isConnectable:t})]})}),b1="",ox={interaction:sx},lx=T.observer(()=>{const e=F(),{edges:t,nodes:r}=ix(e);return p(xe,{nodes:r,edges:t,onNodesChange:v.noop,onEdgesChange:v.noop,onConnect:v.noop,className:"interactions-viewer",fitView:!0,nodeTypes:ox,children:[n(xe.MiniMap,{}),n(xe.Controls,{}),n(xe.Background,{})]})}),ux=T.observer(({opened:e,close:t})=>{const{freezeLayout:r}=b.useContext(Ze);return b.useEffect(()=>{r(e)},[e]),n(a.Modal,{size:"96vw",overflow:"inside",opened:e,onClose:t,title:"Interactions",trapFocus:!0,onDragStart:i=>{i.stopPropagation()},styles:{body:{height:"90vh"},modal:{transform:"none !important"}},zIndex:300,children:n(lx,{})})}),dx={"> button":{"&:first-of-type":{borderTopRightRadius:0,borderBottomRightRadius:0,borderRightWidth:.5},":not(:first-of-type):not(:last-of-type)":{borderTopRightRadius:0,borderBottomRightRadius:0,borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeftWidth:.5,borderRightWidth:.5},"&:last-of-type":{borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeftWidth:.5}}};function cx({onClick:e,name:t,active:r,openSettings:i}){return p(a.Box,{sx:{position:"relative"},children:[n(a.UnstyledButton,{sx:s=>({display:"block",width:"100%",padding:s.spacing.xs,borderRadius:0,position:"relative",color:s.black,"&:hover":{backgroundColor:s.colors.gray[0]},backgroundColor:r?s.colors.gray[2]:"transparent"}),children:n(a.Group,{sx:{width:"calc(100% - 28px)"},onClick:e,children:n(a.Text,{size:"sm",children:t})})}),r&&n(a.Tooltip,{label:"Edit",position:"right",withinPortal:!0,children:n(a.ActionIcon,{onClick:i,variant:"light",color:"blue",sx:{position:"absolute",top:0,bottom:0,height:"100%",right:0,zIndex:0,borderRadius:0},children:n(V.IconAdjustments,{size:16})})})]})}const px=T.observer(()=>{const e=ye(),t=F(),r=b.useCallback(s=>()=>t.views.setIDOfVIE(s),[t]),i=s=>{e.editor.open(["_VIEWS_",s])};return p(a.Box,{sx:{position:"relative"},children:[t.views.options.map(s=>n(cx,{active:t.views.idOfVIE===s.value,name:s.label,onClick:r(s.value),openSettings:()=>i(s.value)},s.value)),n(a.Divider,{variant:"dashed"}),n(a.Button,{variant:"subtle",rightIcon:n(V.IconPlus,{size:14}),size:"sm",px:"xs",color:"blue",onClick:t.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"space-between"}},children:"Add a View"})]})}),hx=T.observer(()=>{const e=ye(),t=F(),r=()=>{if(!t.queries.firstID){e.editor.open(["_QUERIES_",""]);return}e.editor.open(["_QUERIES_",t.queries.firstID])},i=()=>{if(!t.filters.firstID){e.editor.open(["_FILTERS_",""]);return}e.editor.open(["_FILTERS_",t.filters.firstID])},[s,o]=b.useState(!1),u=()=>o(!0),l=()=>o(!1);return p(a.Navbar,{p:0,width:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},zIndex:299,children:[p(a.Navbar.Section,{children:[p(a.Group,{grow:!0,spacing:0,sx:{...dx,button:{borderWidth:0,borderBottomWidth:1,borderColor:"#e9ecef"}},children:[n(a.Tooltip,{label:"Filters",withinPortal:!0,children:n(a.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:i,children:n(V.IconFilter,{size:20})})}),n(a.Tooltip,{label:"Queries",withinPortal:!0,children:n(a.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:r,children:n(V.IconDatabase,{size:20})})}),n(a.Tooltip,{label:"Interactions Viewer",withinPortal:!0,children:n(a.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:u,children:n(V.IconLink,{size:20})})})]}),n(ux,{opened:s,close:l})]}),n(a.Navbar.Section,{py:5,sx:{borderBottom:"1px solid #eee"},children:n(a.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Views"})}),n(a.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:n(px,{})}),n(a.Navbar.Section,{children:n(a.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:n(a.Button,{size:"xs",leftIcon:n(V.IconSettings,{size:20}),onClick:()=>e.editor.open([]),children:"Settings"})})})]})}),fx=T.observer(function({config:t}){return p(O,{children:[n(a.Checkbox,{checked:t.default_value,onChange:r=>t.setDefaultValue(r.currentTarget.checked),label:"Default Checked"}),n(qn,{label:"Description",value:t.description,onChange:t.setDescription,styles:{root:{flexGrow:1,minHeight:"400px"}}})]})}),gx=[{label:"2022",value:"YYYY"},{label:"202201",value:"YYYYMM"},{label:"20220101",value:"YYYYMMDD"},{label:"2022-01",value:"YYYY-MM"},{label:"2022-01-01",value:"YYYY-MM-DD"}],mx=T.observer(function({config:t}){return p(O,{children:[p(a.Group,{children:[n(a.Checkbox,{checked:t.required,onChange:r=>t.setRequired(r.currentTarget.checked),label:"Required"}),n(a.Checkbox,{checked:t.clearable,onChange:r=>t.setClearable(r.currentTarget.checked),disabled:t.max_days>0,label:"Clearable"}),n(a.Checkbox,{checked:t.allowSingleDateInRange,onChange:r=>t.setAllowSingleDateInRange(r.currentTarget.checked),label:"Allow choosing 1 day"})]}),n(a.Select,{data:gx,label:"Display Format",value:t.inputFormat,onChange:t.setInputFormat}),n(Li,{label:"Default Value",config:t,value:t.default_value,onChange:t.setDefaultValue}),n(a.NumberInput,{label:"Max Days",description:p(a.Group,{position:"apart",children:[n(a.Text,{children:"Set 0 to disable."}),p(a.Group,{spacing:4,children:[n(a.Text,{children:"This feature requires"}),n(a.Text,{color:"blue",children:"Clearable"}),n(a.Text,{children:"to be checked"})]})]}),min:0,value:t.max_days,onChange:t.setMaxDays,hideControls:!0})]})}),yr=T.observer(({value:e,onChange:t})=>{const r=F(),i=b.useMemo(()=>r.queries.options,[r.queries.current]),s=i.length===0;return n(a.Select,{label:"Pick a query",data:i,value:e,onChange:t,allowDeselect:!1,clearable:!0,sx:{flexGrow:1},disabled:s,error:s?"You need to add a query in Data Settings":void 0})}),bx=`
439
+ `)},Iv=y.types.model("CustomModalTitleModel",{enabled:y.types.optional(y.types.boolean,!1),func_content:y.types.optional(y.types.string,"")}).views(e=>({get json(){const{enabled:t,func_content:r}=e;return{enabled:t,func_content:r}},get value(){const{enabled:t,func_content:r}=e,i=y.getParent(e,2),s=y.getRoot(e);if(!t)return i.name;try{const o={filters:s.filters.values,context:s.context.current};return new Function(`return ${r}`)()(o)}catch(o){return console.error(o),i.name}}})).actions(e=>({setEnabled(t){e.enabled=t},setFuncContent(t){e.func_content=t},replace({enabled:t,func_content:r}){e.enabled=t,e.func_content=r}})),xs=y.types.model("ViewModel_Modal",{_name:y.types.literal(K.Modal),width:y.types.string,height:y.types.string,custom_modal_title:y.types.optional(Iv,cr)}).views(e=>({get json(){const{_name:t,width:r,height:i,custom_modal_title:s}=e;return{_name:t,width:r,height:i,custom_modal_title:s.json}}})).actions(e=>({setWidth(t){e.width=t},setHeight(t){e.height=t}})),Av=()=>xs.create({_name:K.Modal,width:"90vw",height:"90vh"}),$v=y.types.model("ViewModel_Tabs_Tab",{id:y.types.identifier,name:y.types.string,view_id:y.types.string,color:y.types.optional(y.types.string,"")}).views(e=>({get json(){const{id:t,name:r,view_id:i,color:s}=e;return{id:t,name:r,color:s,view_id:i}}})).actions(e=>({setName(t){e.name=t},setViewID(t){e.view_id=t},setColor(t){e.color=t}})),Cs=y.types.model("ViewModel_Tabs",{_name:y.types.literal(K.Modal),tabs:y.types.optional(y.types.array($v),[]),variant:y.types.optional(y.types.enumeration("variant",["default","outline","pills"]),"default"),orientation:y.types.optional(y.types.enumeration("orientation",["horizontal","vertical"]),"horizontal"),grow:y.types.optional(y.types.boolean,!1)}).views(e=>({get json(){const{_name:t,variant:r,orientation:i,tabs:s,grow:o}=e;return{grow:o,tabs:s.map(u=>u.json),_name:t,variant:r,orientation:i}}})).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=y.cast(t)},addTab(){const t=ve.randomId(),r={id:t,name:t,view_id:""};e.tabs.push(r)},removeTab(t){e.tabs.splice(t,1)}})),zv=()=>Cs.create({_name:K.Modal,tabs:[]}),ws=y.types.model({id:y.types.identifier,name:y.types.string,type:y.types.enumeration("EViewComponentType",[K.Division,K.Modal,K.Tabs]),config:y.types.union(vs,xs,Cs),panelIDs:y.types.optional(y.types.array(y.types.string),[])}).views(e=>({get json(){const{id:t,name:r,type:i,config:s}=e;return{id:t,name:r,type:i,config:s.json,panelIDs:e.panelIDs}}})).actions(e=>({setName(t){e.name=t},setType(t){if(e.type!==t){switch(t){case K.Division:e.config=Mv();break;case K.Modal:e.config=Av();break;case K.Tabs:e.config=zv();break}e.type=t}},appendPanelID(t){e.panelIDs.push(t)},removePanelID(t){const r=e.panelIDs.filter(i=>i!==t);e.panelIDs.length=0,e.panelIDs.push(...r)}})).actions(e=>({})),_s=y.types.model("ViewsModel",{current:y.types.optional(y.types.array(ws),[]),visibleViewIDs:y.types.array(y.types.string),idOfVIE:y.types.string}).views(e=>({get json(){return e.current.map(t=>rn(t.json))},get idMap(){const t=new Map;return e.current.forEach(r=>{t.set(r.id,r)}),t},findByID(t){return e.current.find(r=>r.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:r})=>r===t)},get visibleViews(){const t=new Set(e.visibleViewIDs);return e.current.filter(({id:r})=>t.has(r))},get VIE(){return e.current.find(({id:t})=>t===e.idOfVIE)},get options(){return e.current.map(t=>({label:t.name,value:t.id,type:t.type}))},get editorOptions(){const t=y.getRoot(e).content.panels;return e.current.map(r=>({label:r.name,value:r.id,_type:"view",children:t.editorOptions(r.id,r.panelIDs)}))}})).actions(e=>({replace(t){e.current.replace(t)},addANewView(t,r,i,s){e.current.push({id:t,name:r,type:i,config:s,panelIDs:[]})},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByID(t){const r=e.current.findIndex(i=>i.id===t);r!==-1&&e.current.splice(r,1)},replaceByIndex(t,r){e.current.splice(t,1,r)},setIDOfVIE(t){e.idOfVIE=t,e.visibleViewIDs.length=0,e.visibleViewIDs.push(t)},appendToVisibles(t){new Set(e.visibleViewIDs.map(i=>i)).has(t)||e.visibleViewIDs.push(t)}})).actions(e=>({addARandomNewView(){const t=new Date().getTime().toString();e.addANewView(t,K.Division,K.Division,{_name:K.Division}),e.setIDOfVIE(t)},removeVIE(){e.current.length!==1&&(e.removeByID(e.idOfVIE),e.setIDOfVIE(e.current[0].id))},rmVisibleViewID(t){const r=e.visibleViewIDs.findIndex(i=>i===t);r!==-1&&e.visibleViewIDs.splice(r,1)}}));function pr(e){const t=e.length>0?[e[0].id]:[],r=e.length>0?e[0].id:"";return{current:e.map(s=>{const{_name:o=s.type}=s.config;return{...s,config:{...s.config,_name:o},panelIDs:s.panelIDs}}),visibleViewIDs:t,idOfVIE:r}}const Ev=y.types.model({id:y.types.string,name:y.types.string,dashboard_id:y.types.string,create_time:y.types.string,update_time:y.types.string,version:y.types.string,filters:as,queries:ps,sqlSnippets:fs,views:_s,panels:ys,mock_context:xv,origin:y.types.maybe(y.types.frozen())}).views(e=>({get json(){return{id:e.id,name:e.name,create_time:e.create_time,update_time:e.update_time,dashboard_id:e.dashboard_id,content:{views:e.views.json,panels:e.panels.json,filters:e.filters.json,version:e.version,definition:{queries:e.queries.json,sqlSnippets:e.sqlSnippets.json,mock_context:e.mock_context.current}}}},get filtersChanged(){const t="filters.current";return!v.isEqual(y.getSnapshot(v.get(e,t)),v.get(e.origin,t))},get queriesChanged(){const t="queries.current",r=y.getSnapshot(v.get(e,t)).map(i=>v.pick(i,["id","name","key","type","sql","run_by","pre_process","post_process"]));return!v.isEqual(r,v.get(e.origin,t))},get sqlSnippetsChanged(){const t="sqlSnippets.current";return!v.isEqual(y.getSnapshot(v.get(e,t)),v.get(e.origin,t))},get viewsChanged(){const t="views.current";return!v.isEqual(y.getSnapshot(v.get(e,t)),v.get(e.origin,t))},get panelsChanged(){const t="panels.list";return!v.isEqual(y.getSnapshot(v.get(e,t)),v.get(e.origin,t))},get mockContextChanged(){const t="mock_context.current";return!v.isEqual(v.get(e,t),v.get(e.origin,t))},get payloadForSQL(){return{context:y.getParent(e).context.current,mock_context:e.mock_context.current,sqlSnippets:e.sqlSnippets.current,filterValues:e.filters.values}},get changed(){return this.filtersChanged||this.queriesChanged||this.sqlSnippetsChanged||this.viewsChanged||this.panelsChanged||this.mockContextChanged},get data(){return e.queries.current.map(({id:r,data:i})=>({id:r,data:i})).reduce((r,i)=>(r[i.id]=i.data,r),{})},getDataStuffByID(t){const r=e.queries.findByID(t);return r?{data:r.data.toJSON(),dataProxy:r.data,len:r.data.length,state:r.state,error:r.error}:{data:[],dataProxy:null,len:0,state:"idle",error:void 0}},getDataStateByID(t){var r;return((r=e.queries.findByID(t))==null?void 0:r.state)??[]},getDataErrorByID(t){var r;return((r=e.queries.findByID(t))==null?void 0:r.error)??[]}})).views(e=>({findQueryUsage(t){const r=e.panels.idMap,i=e.views.current.flatMap(u=>u.panelIDs.map(l=>r.get(l)).filter(l=>(l==null?void 0:l.queryID)===t).map(l=>({type:"panel",id:l.id,label:l.title?l.title:l.viz.type,views:[{id:u.id,label:u.name}]}))),s=e.views.idMap,o=e.filters.current.filter(u=>v.get(u,"config.options_query_id")===t).map(u=>({type:"filter",id:u.id,label:u.label,views:u.visibleInViewsIDs.map(l=>{var d;return{id:l,label:((d=s.get(l))==null?void 0:d.name)??l}})}));return i.concat(o)}})).actions(e=>({duplicatePanelByID(t,r){var s;const i=e.panels.duplicateByID(t);i&&((s=e.views.findByID(r))==null||s.appendPanelID(i))},removePanelByID(t,r){var i;e.panels.removeByID(t),(i=e.views.findByID(r))==null||i.removePanelID(t)},addANewPanel(t){var i;const r=new Date().getTime().toString();e.panels.append(bs(r)),(i=e.views.findByID(t))==null||i.appendPanelID(r)}})).actions(e=>({reset(){y.applySnapshot(e.filters.current,e.origin.filters.current),y.applySnapshot(e.queries.current,e.origin.queries.current),y.applySnapshot(e.sqlSnippets.current,e.origin.sqlSnippets.current),y.applySnapshot(e.views.current,e.origin.views.current),y.applySnapshot(e.panels.list,e.origin.panels.list),e.mock_context.current=e.origin.mock_context.current},resetFilters(){y.applySnapshot(e.filters.current,e.origin.filters.current)},updateCurrent(t){const{id:r,name:i,content:s}=t;if(!s)throw new Error("unexpected null content when updating a content model");const{version:o,filters:u,views:l,panels:d,definition:{queries:c,sqlSnippets:f,mock_context:g={}}}=s;e.id=r,e.name=i,e.version=o,y.applySnapshot(e.filters.current,u),y.applySnapshot(e.views.current,pr(l).current),y.applySnapshot(e.panels.list,d),y.applySnapshot(e.queries.current,c),y.applySnapshot(e.sqlSnippets.current,f),e.mock_context.current=g}})),It=y.types.snapshotProcessor(Ev,{preProcessor(e){return{...e,origin:e}},postProcessor(e){delete e.origin;const t=y.castToSnapshot(e.queries.current.map(r=>v.pick(r,["id","key","type","sql"])));return v.defaults({},{queries:{current:t}},e)}});function Lv(e,t){t.filters&&y.applySnapshot(e.filters.current,t.filters)}function Ss({id:e,name:t,dashboard_id:r,create_time:i,update_time:s,content:o}){if(!o)throw new Error("unexpected null content when creating a content model");const{version:u,filters:l,views:d,panels:c,definition:{queries:f,sqlSnippets:g,mock_context:h={}}}=o;return It.create({id:e,name:t,dashboard_id:r,create_time:i,update_time:s,version:u,filters:ss(l),queries:{current:f},sqlSnippets:{current:g},mock_context:{current:h},views:pr(d),panels:{list:c}})}const Ts=y.types.model({id:y.types.identifier,name:y.types.string,group:y.types.string,content:It,content_id:y.types.string,datasources:bv,context:gs,editor:vv}).views(e=>({get json(){return{id:e.id,name:e.name,group:e.group,content_id:e.content_id}}})).actions(e=>({updateCurrentContent(t){e.content.updateCurrent(t)},updateCurrent(t,r){const{id:i,name:s,group:o,content_id:u}=t;e.id=i,e.name=s,e.group=o,e.content_id=u,this.updateCurrentContent(r)}}));function hr({id:e,name:t,group:r,content_id:i},s,o,u){return Ts.create({id:e,name:t,group:r,content_id:i,content:Ss(s),datasources:{list:o},context:{current:u},editor:{}})}function fr(e){return b.useCallback(t=>t.provideValue(be.pluginManager,e.pluginManager).provideValue(be.vizManager,e.vizManager).provideValue(be.colorManager,e.colorManager),[])}const f1="",Pv=T.observer(({headerMenuItems:e=null})=>{const t=me(),r=F(),i=()=>{const s=JSON.stringify(r.json,null,2),o=`${t.name}__${r.name}`;Xy(o,s)};return p(a.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:310,children:[n(a.Menu.Target,{children:n(a.ActionIcon,{variant:"light",color:"blue",children:n(V.IconMenu2,{size:14})})}),p(a.Menu.Dropdown,{children:[n(a.Menu.Item,{icon:n(V.IconDownload,{size:14}),onClick:r.queries.downloadAllData,children:"Download Data"}),n(a.Menu.Item,{icon:n(V.IconCode,{size:14}),onClick:i,children:"Download Schema"}),e]})]})}),Ov=T.observer(({saveDashboardChanges:e})=>{const t=Le.useModals(),r=F(),i=()=>{t.openConfirmModal({title:p(a.Group,{position:"left",children:[n(V.IconAlertTriangle,{size:18,color:"red"}),n(a.Text,{children:"You are reverting changes"})]}),labels:{confirm:"Confirm",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:()=>r.reset(),zIndex:320,withCloseButton:!1})},s=r.changed;return p(a.Group,{spacing:0,children:[n(a.Button,{color:"green",variant:"filled",size:"xs",leftIcon:n(V.IconDeviceFloppy,{size:18}),onClick:e,disabled:!s,sx:{borderTopRightRadius:0,borderBottomRightRadius:0},children:"Save Changes"}),p(a.Menu,{width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:320,disabled:!s,children:[n(a.Menu.Target,{children:n(a.ActionIcon,{variant:"default",disabled:!s,sx:{height:"30px",borderTopLeftRadius:0,borderBottomLeftRadius:0,svg:{fill:"rgb(173, 181, 189)",stroke:"none"}},children:n(V.IconCaretDown,{size:18})})}),n(a.Menu.Dropdown,{children:n(a.Menu.Item,{icon:n(V.IconRecycle,{size:14,color:"red"}),disabled:!s,onClick:i,children:"Revert Changes"})})]})]})}),Vv=T.observer(({saveDashboardChanges:e,headerSlot:t=null,headerMenuItems:r})=>{const i=ho.useNavigate(),s=me(),o=()=>{i(`/dashboard/${s.id}`)},u=Le.useModals(),l=()=>{u.openConfirmModal({title:p(a.Group,{position:"left",children:[n(V.IconAlertTriangle,{size:18,color:"red"}),n(a.Text,{children:"There are unsaved changes"})]}),labels:{confirm:"Discard",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:o,zIndex:320,withCloseButton:!1})},d=s.content.changed;return n(a.Header,{height:60,px:"md",py:0,sx:{zIndex:299},children:p(a.Group,{position:"apart",sx:{height:60,minWidth:"1000px",position:"relative"},children:[p(a.Group,{children:[n(a.Button,{size:"xs",color:d?"red":"green",leftIcon:n(V.IconArrowLeft,{size:20}),onClick:d?l:o,children:p(a.Group,{spacing:4,children:["End Editing",n(a.Text,{td:"underline",children:s.name})]})}),n(Ov,{saveDashboardChanges:e})]}),p(a.Group,{position:"right",sx:{flexGrow:1},children:[t,n(Pv,{headerMenuItems:r})]})]})})}),Bv={position:"fixed",top:60,left:0,right:0,height:30,zIndex:299,borderBottom:"1px solid #e9ecef",background:"rgba(233,236,239, 0.15)"},Nv=T.observer(()=>{const e=F();return n(a.Box,{sx:Bv,pl:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},children:p(a.Group,{position:"apart",align:"center",sx:{height:"30px"},pr:16,children:[n(a.Button,{variant:"outline",color:"blue",radius:0,size:"xs",disabled:!e.views.VIE,onClick:()=>e.addANewPanel(e.views.idOfVIE),leftIcon:n(V.IconPlaylistAdd,{size:20}),sx:{height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef",background:"rgb(231, 245, 255)"},children:"Add a Panel"}),n(a.Box,{}),n(a.Box,{})]})})}),Gv=T.observer(e=>p(O,{children:[n(Vv,{...e}),n(Nv,{})]})),g1="";function qv(e,t,r){const i=[];return e.filter(s=>"__INTERACTIONS"in s.viz.conf).forEach((s,o)=>{const u=t[s.id];u.data.interactions=v.get(u,"data.interactions",[]);const{__INTERACTIONS:l,__OPERATIONS:d,__TRIGGERS:c}=s.viz.conf;Object.entries(d).forEach(([f,g])=>{const{schemaRef:h,data:m}=g,{config:w}=m;switch(h){case"builtin:op:open-link":let C=w.urlTemplate.substring(0,100);w.urlTemplate.length>=20&&(C+="..."),u.type="interaction",u.data.interactions.push({schemaRef:h,urlTemplate:w.urlTemplate,shortURLTemplate:C});return;case"builtin:op:open_view":i.push({id:`OPERATION--${f}`,source:s.id,target:w.viewID,label:"Open View",style:{stroke:"rgba(0,0,0,0.8)"},type:"default"});return;case"builtin:op:set_filter_values":u.type="interaction",u.data.interactions.push({schemaRef:h,filters:Object.keys(w.dictionary).map(S=>({key:S,label:r[S]}))});return;case"builtin:op:clear_filter_values":u.type="interaction",u.data.interactions.push({schemaRef:h,filters:w.filter_keys.map(S=>({key:S,label:r[S]}))});return;default:return}})}),i}function Fv(e,t){const r=e.filters.keyLabelMap;return{edges:qv(e.panels.list,t,r),edgeNodes:[]}}function ks(e,t,r){return e*t+e*r}function Wv(e,t,r){return e*t+(e-1)*r}const sn=25,gr=40,Ds=25,mr=350,jv=150,Yv=150,Ms=150,Is=300,on=40,As=25,Rv=300;function Qv(e,t){const r=v.keyBy(t,s=>s.id),i=[];return e.current.forEach((s,o)=>{s.panelIDs.forEach((u,l)=>{const d=ks(l,on,As)+gr,c=r[u];if(!c){i.push({id:u,_node_type:"panel",parentNode:s.id,data:{label:`!: ${u}`},position:{x:sn,y:d},sourcePosition:xe.Position.Right,targetPosition:xe.Position.Left,style:{width:Is,height:on}});return}const f=c.title.trim()?`${c.title}`:c.viz.type;i.push({id:c.id,_node_type:"panel",parentNode:s.id,data:{label:f},position:{x:sn,y:d},sourcePosition:xe.Position.Right,targetPosition:xe.Position.Left,style:{width:Is,height:on}})})}),i}const Uv={[K.Division]:"Div",[K.Modal]:"Modal",[K.Tabs]:"Tabs"},Xv=Ra;function Zv(e){return e.current.map((r,i)=>{const s=Wv(r.panelIDs.length,on,As)+gr+Ds;let o=[];return r.type===K.Tabs&&(o=r.config.tabs.map(l=>l.view_id)),{id:r.id,_node_type:"view-root",_view_type:r.type,_view_level:0,_sub_view_ids:[],_tab_view_ids:o,data:{label:`${Uv[r.type]}:${r.name}`},position:{x:0,y:0},sourcePosition:xe.Position.Right,targetPosition:xe.Position.Left,className:"light",style:{backgroundColor:Xv[r.type],width:mr,height:s}}})}function Kv(e){const t=v.keyBy(e,r=>r.id);e.forEach(r=>{r._node_type!=="view-root"||r._view_type!==K.Tabs||r._tab_view_ids.forEach(i=>{t[i].parentNode=r.id})})}function Jv(e){const t=Zv(e.views);Kv(t);const r=Qv(e.views,e.panels.list);return[...t,...r]}function Hv({nodeMap:e,nodes:t,edges:r}){t.forEach(i=>{i._node_type!=="view-root"||i._view_type!==K.Tabs||(i.sourcePosition=xe.Position.Bottom,i.style.width=mr+sn*2,i.style.height=Ds+i._tab_view_ids.reduce((s,o)=>{const u=e[o];u.position.y=s,u.position.x=sn;const l=u.style.height;return s+l+20},gr))})}function ex({nodeMap:e,nodes:t,edges:r}){r.filter(i=>i.label==="Open View").forEach(i=>{const s=e[i.source],o=e[i.target];if(!s||!o||!s.parentNode)return;const u=e[s.parentNode];u._node_type!=="view-root"||o._node_type!=="view-root"||(o._view_level+=1+u._view_level,u._sub_view_ids.push(o.id))}),t.sort((i,s)=>i._node_type==="view-root"&&s._node_type==="view-root"?i._view_level-s._view_level:i._node_type!=="view-root"&&s._node_type!=="view-root"?0:i._node_type==="view-root"?-1:1)}function tx({nodeMap:e,nodes:t,edges:r}){const i={};r.forEach(s=>{if(s.label!=="Open View")return;const o=e[s.source],u=e[s.target];if(o&&u&&o.parentNode){const l=e[o.parentNode],d=l.position.x,c=Number(v.get(u,"style.height",0)),f=Number(l.style.width);u.position.x=d+f+Rv,l._view_level===0&&u._sub_view_ids.length===0&&(o.sourcePosition=xe.Position.Left,u.targetPosition=xe.Position.Right,u.position.x*=-1);const h=u.position.x,m=v.get(i,h,0);u.position.y=m,i[h]=m+c+Ms}})}function nx({nodeMap:e,nodes:t,edges:r}){const i=new Set,s=new Set;r.forEach(u=>{i.add(u.source),s.add(u.target)}),t.filter(u=>u._node_type!=="view-root"||u.id==="Main"||u.parentNode?!1:!i.has(u.id)&&!s.has(u.id)).forEach((u,l)=>{u.position.x=ks(l,mr,Yv),u.position.y=0-jv-Ms})}function rx({nodeMap:e,nodes:t,edges:r}){const i={nodeMap:e,nodes:t,edges:r};return nx(i),ex(i),Hv(i),tx(i),{nodes:t,edges:r}}function ix(e){const t=Jv(e),r=v.keyBy(t,d=>d.id),{edges:i,edgeNodes:s}=Fv(e,r),o=[...t,...s],u=v.keyBy(o,d=>d.id),l={edges:v.uniqBy(i,d=>d.id),nodes:o,nodeMap:u};return rx(l)}const m1="",br={"builtin:op:open-link":n(a.ThemeIcon,{color:"blue",size:20,radius:"xl",children:n(V.IconCircleDashed,{size:14})}),"builtin:op:set_filter_values":n(a.ThemeIcon,{color:"orange",size:20,radius:"xl",children:n(V.IconCircleDot,{size:14})}),"builtin:op:clear_filter_values":n(a.ThemeIcon,{color:"orange",size:20,radius:"xl",children:n(V.IconCircleOff,{size:14})})};function ax(e){const t=[];return e.forEach(r=>{switch(r.schemaRef){case"builtin:op:open-link":t.push({key:r.urlTemplate,icon:br[r.schemaRef],text:p(a.Group,{spacing:4,children:[n(a.Text,{children:"Open: "}),n(a.Text,{color:"dimmed",children:r.shortURLTemplate})]})});return;case"builtin:op:set_filter_values":r.filters.forEach(({key:i,label:s})=>{t.push({key:r.schemaRef+i,icon:br[r.schemaRef],text:n(a.Group,{spacing:4,children:p(a.Text,{children:["Set Filter: ",s]})})})});return;case"builtin:op:clear_filter_values":r.filters.forEach(({key:i,label:s})=>{t.push({key:r.schemaRef+i,icon:br[r.schemaRef],text:n(a.Group,{spacing:4,children:p(a.Text,{children:["Clear Filter: ",s]})})})});return}}),t}const sx=b.memo(({data:e,isConnectable:t,sourcePosition:r=xe.Position.Right,targetPosition:i=xe.Position.Left,...s})=>{const o=b.useMemo(()=>ax(e.interactions),[e.interactions]);return p(O,{children:[n(xe.Handle,{type:"target",position:i,isConnectable:t}),n(a.Box,{sx:{position:"absolute",top:0,right:0},children:n(k.ChevronsUpRight,{size:12})}),p(a.HoverCard,{shadow:"xl",withinPortal:!0,children:[n(a.HoverCard.Target,{children:n(a.Text,{children:e.label})}),n(a.HoverCard.Dropdown,{children:n(a.List,{spacing:"xs",size:"sm",center:!0,children:o.map(u=>n(a.List.Item,{icon:u.icon,children:u.text},u.key))})})]}),n(xe.Handle,{type:"source",position:r,isConnectable:t})]})}),b1="",ox={interaction:sx},lx=T.observer(()=>{const e=F(),{edges:t,nodes:r}=ix(e);return p(xe,{nodes:r,edges:t,onNodesChange:v.noop,onEdgesChange:v.noop,onConnect:v.noop,className:"interactions-viewer",fitView:!0,nodeTypes:ox,children:[n(xe.MiniMap,{}),n(xe.Controls,{}),n(xe.Background,{})]})}),ux=T.observer(({opened:e,close:t})=>{const{freezeLayout:r}=b.useContext(Ze);return b.useEffect(()=>{r(e)},[e]),n(a.Modal,{size:"96vw",overflow:"inside",opened:e,onClose:t,title:"Interactions",trapFocus:!0,onDragStart:i=>{i.stopPropagation()},styles:{body:{height:"90vh"},modal:{transform:"none !important"}},zIndex:300,children:n(lx,{})})}),dx={"> button":{"&:first-of-type":{borderTopRightRadius:0,borderBottomRightRadius:0,borderRightWidth:.5},":not(:first-of-type):not(:last-of-type)":{borderTopRightRadius:0,borderBottomRightRadius:0,borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeftWidth:.5,borderRightWidth:.5},"&:last-of-type":{borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeftWidth:.5}}};function cx({onClick:e,name:t,active:r,openSettings:i}){return p(a.Box,{sx:{position:"relative"},children:[n(a.UnstyledButton,{sx:s=>({display:"block",width:"100%",padding:s.spacing.xs,borderRadius:0,position:"relative",color:s.black,"&:hover":{backgroundColor:s.colors.gray[0]},backgroundColor:r?s.colors.gray[2]:"transparent"}),children:n(a.Group,{sx:{width:"calc(100% - 28px)"},onClick:e,children:n(a.Text,{size:"sm",children:t})})}),r&&n(a.Tooltip,{label:"Edit",position:"right",withinPortal:!0,children:n(a.ActionIcon,{onClick:i,variant:"light",color:"blue",sx:{position:"absolute",top:0,bottom:0,height:"100%",right:0,zIndex:0,borderRadius:0},children:n(V.IconAdjustments,{size:16})})})]})}const px=T.observer(()=>{const e=me(),t=F(),r=b.useCallback(s=>()=>t.views.setIDOfVIE(s),[t]),i=s=>{e.editor.open(["_VIEWS_",s])};return p(a.Box,{sx:{position:"relative"},children:[t.views.options.map(s=>n(cx,{active:t.views.idOfVIE===s.value,name:s.label,onClick:r(s.value),openSettings:()=>i(s.value)},s.value)),n(a.Divider,{variant:"dashed"}),n(a.Button,{variant:"subtle",rightIcon:n(V.IconPlus,{size:14}),size:"sm",px:"xs",color:"blue",onClick:t.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"space-between"}},children:"Add a View"})]})}),hx=T.observer(()=>{const e=me(),t=F(),r=()=>{if(!t.queries.firstID){e.editor.open(["_QUERIES_",""]);return}e.editor.open(["_QUERIES_",t.queries.firstID])},i=()=>{if(!t.filters.firstID){e.editor.open(["_FILTERS_",""]);return}e.editor.open(["_FILTERS_",t.filters.firstID])},[s,o]=b.useState(!1),u=()=>o(!0),l=()=>o(!1);return p(a.Navbar,{p:0,width:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},zIndex:299,children:[p(a.Navbar.Section,{children:[p(a.Group,{grow:!0,spacing:0,sx:{...dx,button:{borderWidth:0,borderBottomWidth:1,borderColor:"#e9ecef"}},children:[n(a.Tooltip,{label:"Filters",withinPortal:!0,children:n(a.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:i,children:n(V.IconFilter,{size:20})})}),n(a.Tooltip,{label:"Queries",withinPortal:!0,children:n(a.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:r,children:n(V.IconDatabase,{size:20})})}),n(a.Tooltip,{label:"Interactions Viewer",withinPortal:!0,children:n(a.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:u,children:n(V.IconLink,{size:20})})})]}),n(ux,{opened:s,close:l})]}),n(a.Navbar.Section,{py:5,sx:{borderBottom:"1px solid #eee"},children:n(a.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Views"})}),n(a.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:n(px,{})}),n(a.Navbar.Section,{children:n(a.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:n(a.Button,{size:"xs",leftIcon:n(V.IconSettings,{size:20}),onClick:()=>e.editor.open([]),children:"Settings"})})})]})}),fx=T.observer(function({config:t}){return p(O,{children:[n(a.Checkbox,{checked:t.default_value,onChange:r=>t.setDefaultValue(r.currentTarget.checked),label:"Default Checked"}),n(qn,{label:"Description",value:t.description,onChange:t.setDescription,styles:{root:{flexGrow:1,minHeight:"400px"}}})]})}),gx=[{label:"2022",value:"YYYY"},{label:"202201",value:"YYYYMM"},{label:"20220101",value:"YYYYMMDD"},{label:"2022-01",value:"YYYY-MM"},{label:"2022-01-01",value:"YYYY-MM-DD"}],mx=T.observer(function({config:t}){return p(O,{children:[p(a.Group,{children:[n(a.Checkbox,{checked:t.required,onChange:r=>t.setRequired(r.currentTarget.checked),label:"Required"}),n(a.Checkbox,{checked:t.clearable,onChange:r=>t.setClearable(r.currentTarget.checked),disabled:t.max_days>0,label:"Clearable"}),n(a.Checkbox,{checked:t.allowSingleDateInRange,onChange:r=>t.setAllowSingleDateInRange(r.currentTarget.checked),label:"Allow choosing 1 day"})]}),n(a.Select,{data:gx,label:"Display Format",value:t.inputFormat,onChange:t.setInputFormat}),n(Li,{label:"Default Value",config:t,value:t.default_value,onChange:t.setDefaultValue}),n(a.NumberInput,{label:"Max Days",description:p(a.Group,{position:"apart",children:[n(a.Text,{children:"Set 0 to disable."}),p(a.Group,{spacing:4,children:[n(a.Text,{children:"This feature requires"}),n(a.Text,{color:"blue",children:"Clearable"}),n(a.Text,{children:"to be checked"})]})]}),min:0,value:t.max_days,onChange:t.setMaxDays,hideControls:!0})]})}),yr=T.observer(({value:e,onChange:t})=>{const r=F(),i=b.useMemo(()=>r.queries.options,[r.queries.current]),s=i.length===0;return n(a.Select,{label:"Pick a query",data:i,value:e,onChange:t,allowDeselect:!1,clearable:!0,sx:{flexGrow:1},disabled:s,error:s?"You need to add a query in Data Settings":void 0})}),bx=`
440
440
  // row
441
441
  {
442
442
  label: string;
@@ -451,7 +451,7 @@ Check the top-level render call using <`+E+">.")}return M}}function eo(_,M){{if(
451
451
  parent_value: string;
452
452
  description?: string;
453
453
  }
454
- `,wx=()=>{const[e,t]=b.useState(!1);return p(O,{children:[n(a.Button,{variant:"subtle",compact:!0,onClick:()=>t(r=>!r),children:e?"Close":"Click to see expected data structure"}),n(a.Collapse,{in:e,children:n(ot.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:Cx})})]})},_x=T.observer(function({config:t}){return p(O,{children:[n(a.TextInput,{label:"Min-width",value:t.min_width,onChange:r=>t.setMinWidth(r.currentTarget.value),placeholder:"200px"}),n(a.Divider,{label:"Fetch options from database",labelPosition:"center"}),n(a.NumberInput,{value:t.default_selection_count,onChange:t.setDefaultSelectionCount,label:"Select first N options by default"}),n(yr,{value:t.options_query_id,onChange:t.setOptionsQueryID}),n(wx,{})]})}),Sx=T.observer(function({filter:t}){const[r,i]=b.useState(t.plainDefaultValue);return b.useEffect(()=>{i(t.plainDefaultValue)},[t]),p(a.Box,{sx:{maxWidth:"480px"},children:[n(a.Text,{pb:"md",color:"gray",children:"Preview"}),n(Oi,{filter:t,value:r,onChange:i}),n(a.Text,{pt:"lg",pb:"md",color:"gray",children:"Config"}),n(ot.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(t,null,4)})]})}),Tx={select:vx,"multi-select":yx,"tree-select":_x,"text-input":xx,checkbox:fx,"date-range":mx},kx=[{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"}],Dx=T.observer(function({filter:t}){const r=F(),i=b.useMemo(()=>Tx[t.type],[t.type]);return p(a.Group,{grow:!0,spacing:20,align:"top",children:[p(a.Box,{sx:{maxWidth:"600px"},children:[n(a.Text,{pb:"md",color:"gray",children:"Edit"}),p(a.Stack,{children:[p(a.Group,{noWrap:!0,children:[n(a.NumberInput,{label:"Placement Order",required:!0,value:t.order,onChange:t.setOrder,hideControls:!0,sx:{flexGrow:"1 !important"}}),t.auto_submit_supported&&n(a.Checkbox,{label:"Submit automatically",checked:t.auto_submit,onChange:s=>t.setAutoSubmit(s.currentTarget.checked),mt:22})]}),n(a.MultiSelect,{label:"Visible in...",data:r.views.options,value:[...t.visibleInViewsIDs],onChange:t.setVisibleInViewsIDs}),n(a.TextInput,{label:"Key",placeholder:"A unique key to refer",required:!0,value:t.key,onChange:s=>{t.setKey(s.currentTarget.value)}}),n(a.TextInput,{label:"Label",placeholder:"Label for this field",required:!0,value:t.label,onChange:s=>{t.setLabel(s.currentTarget.value)}}),n(a.Select,{label:"Widget",data:kx,required:!0,value:t.type,onChange:t.setType}),n(i,{config:t.config})]})]}),n(Sx,{filter:t})]})}),Mx=T.observer(({id:e})=>{const t=Le.useModals(),r=ye(),i=F();if(e==="")return null;const s=i.filters.findByID(e);if(!s)return p(a.Text,{size:14,children:["Filter by ID[",e,"] is not found"]});const o=()=>{r.editor.setPath(["_FILTERS_",""])},u=()=>{t.openConfirmModal({title:"Delete this filter?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.filters.removeByID(e),o()},zIndex:320})};return p(a.Stack,{sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",pb:30,children:[n(a.Group,{position:"right",pt:10,children:n(a.Button,{size:"xs",color:"red",leftIcon:n(k.Trash,{size:16}),onClick:u,children:"Delete this filter"})}),n(a.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:n(Dx,{filter:s})})]})}),Ix=T.observer(()=>{const e=F(),[t,r]=b.useState(()=>JSON.stringify(e.mock_context.current,null,4)),i=()=>{try{e.mock_context.replace(JSON.parse(t))}catch(o){Vt.showNotification({title:"Failed",message:o.message,color:"red"})}},s=b.useMemo(()=>{try{return JSON.stringify(JSON.parse(t))!==JSON.stringify(e.mock_context.current)}catch{return!1}},[t,e.mock_context.current]);return p(a.Stack,{sx:{border:"1px solid #eee",borderLeft:"none",borderRight:"none",flexGrow:1,maxWidth:"unset"},children:[n(a.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:n(a.Text,{weight:500,children:"Mock Context"})}),p(a.Group,{grow:!0,px:"md",pb:"md",pt:0,sx:{flexGrow:1,position:"relative",alignItems:"flex-start"},children:[p(a.Stack,{spacing:10,sx:{maxWidth:"unset !important"},children:[n(a.Text,{children:"A valid json string is required"}),n(a.JsonInput,{validationError:"Invalid json",formatOnBlur:!0,autosize:!0,minRows:30,value:t,onChange:r,sx:{flexGrow:1}})]}),n(a.ActionIcon,{mr:5,variant:"filled",color:"blue",sx:{position:"absolute",right:12,top:0},disabled:!s,onClick:i,children:n(k.DeviceFloppy,{size:20})})]})]})}),Ax=T.observer(()=>{const{panel:e}=Ce();return n(qn,{label:"Description",value:e.description,onChange:e.setDescription,styles:{root:{flexGrow:1}}})}),$x=T.observer(()=>{const{panel:e}=Ce(),{style:t}=e;return n(O,{children:n(a.Switch,{label:"Border",checked:t.border.enabled,onChange:r=>t.border.setEnabled(r.currentTarget.checked)})})}),zx=T.observer(()=>{const{panel:e}=Ce(),{title:t,setTitle:r}=e,[i,s]=ve.useInputState(t),o=t!==i,u=b.useCallback(()=>{o&&r(i)},[o,i]);return b.useEffect(()=>{s(t)},[t]),n(a.TextInput,{value:i,onChange:s,label:p(a.Group,{children:[n(a.Text,{children:"Panel Title"}),n(a.ActionIcon,{variant:"subtle",color:"blue",disabled:!o,onClick:u,children:n(k.DeviceFloppy,{size:20})})]}),styles:{label:{display:"block",paddingBottom:"4px"}}})});function Ex(){return p(a.Stack,{sx:{height:"100%"},children:[n(a.Divider,{label:"Style",labelPosition:"center",variant:"dashed"}),n($x,{}),n(a.Divider,{label:"Info",labelPosition:"center",variant:"dashed"}),n(zx,{}),n(Ax,{})]})}const Lx=({queryID:e})=>{const t=F(),{state:r,error:i}=t.getDataStuffByID(e),s=b.useMemo(()=>t.queries.findByID(e),[t,e]);return r==="loading"?null:i?n(a.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:i}):s!=null&&s.stateMessage?n(a.Text,{color:"gray",align:"center",children:s.stateMessage}):null},Px={width:"fit-content",minWidth:"100%",tableLayout:"fixed",tr:{width:"fit-content"},th:{position:"relative"},".resizer":{position:"absolute",right:0,top:"50%",transform:"translateY(-50%)",cursor:"col-resize",userSelect:"none",touchAction:"none"},".resizer.isResizing":{color:"#228be6",opacity:"1"},"@media (hover: hover)":{".resizer":{opacity:"0"},"*:hover > .resizer":{color:"#228be6",opacity:"1"}}};function zs({data:e}){const t=b.useMemo(()=>{if(!Array.isArray(e)||e.length===0)return[];const i=Pe.createColumnHelper();return Object.keys(e[0]).map(s=>i.accessor(s,{cell:o=>o.getValue()}))},[e]),r=Pe.useReactTable({data:e,columns:t,columnResizeMode:"onChange",getCoreRowModel:Pe.getCoreRowModel()});return e.length===0?n(a.Box,{sx:{height:"5em"}}):n($e,{children:p(a.Table,{sx:Px,children:[n("thead",{children:r.getHeaderGroups().map(i=>n("tr",{children:i.headers.map(s=>p("th",{style:{width:s.getSize()},children:[s.isPlaceholder?null:Pe.flexRender(s.column.columnDef.header,s.getContext()),n(a.ActionIcon,{onMouseDown:s.getResizeHandler(),onTouchStart:s.getResizeHandler(),className:`resizer ${s.column.getIsResizing()?"isResizing":""}`,children:n(k.ArrowBarToRight,{})})]},s.id))},i.id))}),n("tbody",{children:r.getRowModel().rows.map(i=>n("tr",{children:i.getVisibleCells().map(s=>n("td",{children:n($e,{children:Pe.flexRender(s.column.columnDef.cell,s.getContext())})},s.id))},i.id))})]})})}const Es=T.observer(function({id:t}){const r=F(),{data:i,state:s}=r.getDataStuffByID(t),o=s==="loading",u=()=>{r.queries.refetchDataByQueryID(t)},l=()=>{r.queries.downloadDataByQueryID(t)},d=b.useMemo(()=>Array.isArray(i)?i.slice(0,10):[],[i]),c=!Array.isArray(i)||i.length===0;return p(a.Stack,{sx:{border:"1px solid #eee"},children:[p(a.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[p(a.Group,{position:"left",children:[n(a.Text,{weight:500,children:"Preview Data"}),i.length>10&&p(a.Text,{size:"sm",color:"gray",children:["Showing 10 rows of ",i.length]})]}),p(a.Group,{pr:15,children:[n(a.ActionIcon,{variant:"subtle",color:"blue",disabled:o,onClick:u,children:n(k.Refresh,{size:15})}),n(a.ActionIcon,{variant:"subtle",color:"blue",disabled:o||c,onClick:l,children:n(k.Download,{size:15})})]})]}),p(a.Box,{sx:{position:"relative",overflow:"auto"},children:[n(a.LoadingOverlay,{visible:o}),n(Lx,{queryID:t}),n(zs,{data:d})]})]})}),Ox=T.observer(function(){const t=ye(),r=F(),{panel:{queryID:i,setQueryID:s}}=Ce(),o=()=>{t.editor.setPath(["_QUERIES_",i])};return p(a.Stack,{children:[p(a.Group,{position:"left",sx:{maxWidth:"600px",alignItems:"baseline"},children:[n(a.Text,{children:"Use query"}),n(a.Select,{data:r.queries.options,value:i,onChange:s,allowDeselect:!1,clearable:!1,sx:{flexGrow:"1 !important"},maxDropdownHeight:300,rightSection:i&&n(a.Tooltip,{label:"Open this query",children:n(a.ActionIcon,{variant:"subtle",color:"blue",onClick:o,children:n(V.IconArrowCurveRight,{size:16})})})})]}),n(Es,{id:i})]})}),Vx=T.observer(({height:e})=>{const t=F(),{data:r,loading:i,error:s,panel:{viz:o,queryID:u}}=Ce(),l=t.queries.findByID(u);return n(Wa,{viz:o,data:r,loading:i,error:s,query:l,height:e})}),Bx=T.observer(()=>{const{panel:{title:e,style:{border:t}}}=Ce();return n($e,{children:n(a.Box,{sx:{height:"100%",flexGrow:0,flexShrink:0,width:"600px"},children:p(a.Stack,{mt:24,spacing:5,sx:{width:"600px",height:"450px",background:"transparent",borderRadius:"5px",border:"1px solid #e9ecef",borderWidth:t.enabled?"1px":"0px"},children:[p(a.Group,{position:"apart",noWrap:!0,sx:{flexGrow:0,flexShrink:0},children:[n(a.Group,{children:n(Bi,{})}),n(a.Group,{grow:!0,position:"center",children:n(a.Text,{lineClamp:1,weight:"bold",children:e})}),n(a.Group,{position:"right",spacing:0,sx:{height:"28px"}})]}),n(a.Group,{px:5,pb:5,sx:{flexGrow:1},children:n(Vx,{height:"410px"})})]})})})}),vr={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 Nx{constructor(t){P(this,"panel");P(this,"selected");this.panel=t,ae.makeAutoObservable(this,{},{deep:!1,autoBind:!0})}get variables(){return this.panel.variables}addNew(){const t=this.panel.variables.filter(r=>r.name.startsWith(vr.name)).length;this.panel.addVariable(v.cloneDeep({...vr,name:`${vr.name}${t||""}`})),this.selected=v.last(this.panel.variables)}select(t){this.selected=t}remove(t){this.selected===t&&(this.selected=void 0);const r=this.panel.variables.indexOf(t);if(this.panel.removeVariable(t),!this.selected&&!v.isEmpty(this.panel.variables)){const i=Math.min(this.panel.variables.length-1,r);this.selected=this.panel.variables[i]}}}function Gx(){const{panel:e}=Ce();return Z.useCreation(()=>new Nx(e),[e])}const qx=b.forwardRef(function({value:t,onChange:r,data:i,withStyle:s=!0},o){const u=(l,d)=>{const c=v.cloneDeep(t);v.set(c,l,d),r(c)};return p(a.Box,{px:"sm",py:"md",ref:o,children:[p(a.Group,{grow:!0,noWrap:!0,children:[n(a.TextInput,{label:"Name",required:!0,value:t.name,onChange:l=>u("name",l.currentTarget.value)}),n(Y,{label:"Data Field",required:!0,data:i,value:t.data_field,onChange:l=>u("data_field",l)})]}),n(jt,{label:"Aggregation",value:t.aggregation,onChange:l=>u("aggregation",l)}),n(a.Divider,{my:"xs",label:"Format",labelPosition:"center"}),n(Be,{value:t.formatter,onChange:l=>u("formatter",l)}),s&&n(na,{value:t,onChange:r})]})}),Ls=a.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}})),Fx=e=>{const{uiModel:t}=e;return n(a.Stack,{className:"var-list",children:t.variables.map(r=>n(a.Button,{variant:t.selected===r?"filled":"subtle",color:"gray",onClick:()=>t.select(r),children:r.name},r.name))})},Wx=T.observer(Fx),jx=({variable:e,data:t})=>n(a.Group,{style:{minHeight:0,height:"calc(100% - 68px)"},children:n(a.Paper,{withBorder:!0,p:"md",children:ra(e,t)})}),Yx=T.observer(jx),Rx=e=>{const t=Z.useCreation(()=>_v(e.variable),[e.variable]),{classes:r}=Ls(),{data:i}=Ce();return p(a.Group,{style:{height:"100%"},align:"start",children:[p(a.Stack,{"data-testid":"variable-editor",align:"stretch",className:r.config,children:[p(a.Group,{position:"right",children:[n(a.ActionIcon,{variant:"filled",disabled:!t.changed,color:"primary",onClick:t.commit,children:n(V.IconDeviceFloppy,{size:18})}),n(a.ActionIcon,{color:"red",onClick:()=>e.uiModel.remove(e.variable),children:n(V.IconTrash,{size:18})})]}),n(qx,{value:y.getSnapshot(t.copy),onChange:t.update,data:i})]}),n(Yx,{variable:y.getSnapshot(t.copy),data:i})]})},Qx=T.observer(Rx),Ux=()=>{const e=Gx(),{classes:t}=Ls();return p(a.Group,{className:t.root,noWrap:!0,align:"start",children:[n(a.Paper,{withBorder:!0,p:"md",className:"var-list-container",children:p(a.Stack,{justify:"space-between",children:[n(a.Box,{className:"var-list-actions",children:n(a.Button,{variant:"light",size:"sm",onClick:e.addNew,fullWidth:!0,children:"Add Variable"})}),n(Wx,{uiModel:e})]})}),e.selected?n(O,{children:n(Qx,{uiModel:e,variable:e.selected})}):n("span",{children:"Select or create a new variable on right side"})]})},Xx=T.observer(Ux);function Zx(){const{vizManager:e}=b.useContext(Ge);return b.useMemo(()=>{const t=e.availableVizList.map(r=>({value:r.name,label:r.displayName??r.name,group:r.displayGroup??""}));return v.orderBy(t,[r=>r.group,r=>r.label],["asc","asc"])},[e])}const Kx=T.observer(({value:e,submit:t})=>{const[r,i]=ve.useInputState(e);b.useEffect(()=>{i(e)},[e]);const s=Zx(),o=e!==r;return n(a.Select,{label:"Visualization",value:r,searchable:!0,onChange:i,data:s,rightSection:n(a.ActionIcon,{disabled:!o,onClick:()=>t(r),children:n(k.DeviceFloppy,{size:20})}),maxDropdownHeight:600})}),Ps=[];function Jx(e,t){try{return e.resolveComponent(t).createConfig()}catch{return null}}function Hx(){const{data:e,panel:{variables:t,viz:r,title:i,queryID:s,description:o,setDescription:u,setTitle:l,setQueryID:d,id:c}}=Ce(),{vizManager:f}=b.useContext(Ge),g={title:i,description:o,viz:r,queryID:s,id:c},h={setDescription:u,setQueryID:d,setTitle:l},m=Ga(g);try{return f.resolveComponent(g.viz.type),n(Gt,{configure:m,children:n(ly,{variables:t,setVizConf:r.setConf,panel:g,panelInfoEditor:h,vizManager:f,data:e})})}catch(w){return console.info(v.get(w,"message")),null}}const e0=T.observer(()=>{const{data:e,panel:{viz:t}}=Ce(),{vizManager:r}=b.useContext(Ge),i=b.useCallback(c=>{if(c===t.type)return;const f=Jx(r,c);t.setType(c),t.setConf(f||{})},[t.type]),s=c=>{try{t.setConf(JSON.parse(c))}catch(f){console.error(f)}},o=b.useMemo(()=>{var c;return(c=Ps.find(f=>f.value===t.type))==null?void 0:c.Panel},[t.type,Ps]),u=Hx(),l=o?b.createElement(o,{data:e,conf:t.conf,setConf:t.setConf}):null,d=u||l;return p(a.Stack,{align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[n(Kx,{submit:i,value:t.type}),n(a.Stack,{pb:50,sx:{flexGrow:1,maxHeight:"calc(100% - 80px)",overflow:"auto"},children:d}),!d&&n(a.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(t.conf,null,2),onChange:s})]})}),t0=T.observer(({panel:e,sourceViewID:t})=>{const r=F(),[i,s]=b.useState(t);b.useEffect(()=>{s(t)},[t]);const[o,{open:u,close:l}]=ve.useDisclosure(!1),d=()=>{e.moveToView(t,i),l()};return p(O,{children:[n(a.Button,{size:"xs",variant:"subtle",color:"blue",onClick:u,leftIcon:n(V.IconBoxMultiple,{size:14}),children:"Move into Another View"}),n(a.Modal,{opened:o,onClose:l,title:"Move panel into another view",zIndex:320,overflow:"inside",children:p(a.Stack,{sx:{maxHeight:"calc(100vh - 185px)",overflow:"hidden"},children:[n(a.Radio.Group,{value:i,onChange:s,pb:10,sx:{flexGrow:1,maxHeight:"calc(100vh - 185px - 30px)",overflow:"auto"},children:n(a.Stack,{spacing:"xs",children:r.views.options.map(c=>n(a.Radio,{value:c.value,label:c.label},c.value))})}),p(a.Group,{noWrap:!0,position:"apart",sx:{flexGrow:0,flexShrink:0},children:[n(a.Button,{size:"xs",color:"red",leftIcon:n(V.IconX,{size:14}),onClick:l,children:"Cancel"}),n(a.Button,{size:"xs",color:"blue",leftIcon:n(V.IconDeviceFloppy,{size:14}),onClick:d,disabled:i===t,children:"Confirm"})]})]})})]})}),n0={root:{flexGrow:1,width:"100%",height:"100%"},panel:{width:"100%",height:"100%",padding:10}},Os=({children:e})=>p(a.Group,{noWrap:!0,grow:!0,position:"left",spacing:20,sx:{width:"100%",height:"calc(100% - 36px)"},children:[n(a.Box,{sx:{maxWidth:"calc(100% - 610px - 10px)",height:"100%",overflow:"auto"},children:e}),n(Bx,{})]});function r0(e){return!["richText","button"].includes(e)}const i0=T.observer(({panel:e})=>{const t=Le.useModals(),r=ye(),i=F(),[s,o]=b.useState("Data"),{data:u,state:l,error:d}=i.getDataStuffByID(e.queryID),c=i.queries.findByID(e.queryID),g=r0(e.viz.type)&&l==="loading",h=g||d||!c||!!c.stateMessage,m=r.editor.path[1];b.useEffect(()=>{o(S=>h&&S==="Visualization"?"Data":S)},[e.id,h]);const w=()=>{r.editor.setPath(["_VIEWS_",m])},C=()=>t.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.removePanelByID(e.id,m),w()},confirmProps:{color:"red"},zIndex:320});return p(vn,{value:{panel:e,data:u,loading:g,error:d},children:[p(a.Group,{px:16,position:"apart",sx:{borderBottom:"1px solid #eee"},children:[p(a.Text,{pt:9,pb:8,children:[e.title?e.title:e.viz.type," "]}),p(a.Group,{position:"right",noWrap:!0,children:[n(t0,{panel:e,sourceViewID:m}),n(a.Button,{size:"xs",variant:"subtle",color:"red",onClick:C,leftIcon:n(V.IconTrash,{size:14}),children:"Delete This Panel"})]})]}),p(a.Tabs,{value:s,onTabChange:o,keepMounted:!1,styles:n0,children:[p(a.Tabs.List,{children:[n(a.Tabs.Tab,{value:"Data",disabled:g,children:"Data"}),n(a.Tabs.Tab,{value:"Panel",children:"Panel"}),n(a.Tabs.Tab,{value:"Variables",disabled:h,children:n(a.Tooltip,{label:"Requires data",disabled:!h,withinPortal:!0,zIndex:310,children:n(a.Text,{children:"Variables"})})}),n(a.Tabs.Tab,{value:"Visualization",disabled:h,children:n(a.Tooltip,{label:"Requires data",disabled:!h,withinPortal:!0,zIndex:310,children:n(a.Text,{children:"Visualization"})})}),n(a.Tabs.Tab,{value:"Interactions",children:"Interactions"})]}),p(a.Tabs.Panel,{value:"Data",children:[n(a.LoadingOverlay,{visible:g,exitTransitionDuration:0}),n(Ox,{})]}),n(a.Tabs.Panel,{value:"Panel",children:n(Os,{children:n(Ex,{})})}),n(a.Tabs.Panel,{value:"Variables",children:n(Xx,{})}),n(a.Tabs.Panel,{value:"Visualization",children:n($e,{children:n(Os,{children:n(e0,{})})})}),n(a.Tabs.Panel,{value:"Interactions",children:n($e,{children:n(sy,{})})})]})]})}),a0=T.observer(({viewID:e,panelID:t})=>{const r=F();if(!r.views.findByID(e))return p(a.Text,{size:14,children:["View by ID[",e,"] is not found"]});const s=r.panels.findByID(t);return s?n(i0,{panel:s}):p(a.Text,{size:14,children:["Panel by ID[",t,"] is not found"]})}),Vs=({width:e="calc(100% - 32px)",lastWidth:t="50%",height:r,count:i,spacing:s=16,pl:o=0})=>p(a.Stack,{spacing:s,mt:6,pl:o,children:[Array.from(new Array(i-1),(u,l)=>n(a.Skeleton,{width:e,height:r,radius:"xs"},l)),n(a.Skeleton,{width:t,height:r,radius:"xs"})]}),At=({value:e})=>e===null||e===""?null:n(a.Tooltip,{label:e,disabled:!e,multiline:!0,children:n(a.ActionIcon,{children:n(V.IconInfoCircle,{size:14})})}),s0=({column:e})=>{const{column_key:t,column_key_text:r}=e;return t?n(a.Tooltip,{label:r,disabled:!r,children:n(a.Badge,{children:t})}):null},o0=T.observer(({dataSource:e})=>{const{columns:t}=e;return t.loading?n(Vs,{height:"24px",width:"100%",lastWidth:"100%",count:20,pl:6}):t.empty?null:p(a.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"1000px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[n("col",{style:{width:50}}),n("col",{style:{minWidth:300}}),n("col",{style:{width:30}}),n("col",{style:{width:70}}),n("col",{style:{minWidth:300}}),n("col",{style:{minWidth:80,width:80}}),n("col",{style:{minWidth:120,width:120}})]}),n("thead",{children:p("tr",{children:[n("th",{children:"#"}),n("th",{children:"Column Name"}),n("th",{}),n("th",{}),n("th",{children:"Type"}),n("th",{children:"Nullable"}),n("th",{children:"Default Value"})]})}),n("tbody",{children:t.data.map(r=>p("tr",{children:[n("td",{children:r.ordinal_position}),n("td",{children:r.column_name}),n("td",{children:n(At,{value:r.column_comment})}),n("td",{children:n(s0,{column:r})}),n("td",{children:r.column_type}),n("td",{children:r.is_nullable}),n("td",{children:n(At,{value:r.column_default})})]},r.column_name))})]})}),l0=T.observer(({dataSource:e})=>{const{indexes:t}=e,r=t.data;return p(a.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"950px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[n("col",{style:{width:100}}),n("col",{style:{minWidth:300}}),n("col",{style:{width:150}}),n("col",{style:{width:150}}),n("col",{style:{width:250}})]}),n("thead",{children:p("tr",{children:[n("th",{children:"Index Length"}),n("th",{children:"Index Name"}),n("th",{children:"Index Algorithm"}),n("th",{children:"Unique"}),n("th",{children:"Column Name"})]})}),n("tbody",{children:r.map(i=>p("tr",{children:[n("td",{children:i.index_length}),n("td",{children:i.index_name}),n("td",{children:i.index_algorithm}),n("td",{children:i.is_unique?"YES":"NO"}),n("td",{children:i.column_name})]},i.index_name))})]})}),u0=T.observer(({dataSource:e})=>{const{indexes:t}=e,r=t.data;return p(a.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"850px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[n("col",{style:{minWidth:300}}),n("col",{style:{width:150}}),n("col",{style:{width:100}}),n("col",{style:{width:100}}),n("col",{style:{width:100}}),n("col",{style:{width:100}})]}),n("thead",{children:p("tr",{children:[n("th",{children:"Index Name"}),n("th",{children:"Index Algorithm"}),n("th",{children:"Unique"}),n("th",{children:"Definition"}),n("th",{children:"Condition"}),n("th",{children:"Comment"})]})}),n("tbody",{children:r.map(i=>p("tr",{children:[n("td",{children:i.index_name}),n("td",{children:i.index_algorithm}),n("td",{children:i.is_unique?"YES":"NO"}),n("td",{children:n(At,{value:i.index_definition})}),n("td",{children:n(At,{value:i.condition})}),n("td",{children:n(At,{value:i.comment})})]},i.index_name))})]})}),d0=T.observer(({dataSource:e})=>{const{indexes:t}=e;return t.loading||t.empty?null:e.type===ce.MySQL?n(l0,{dataSource:e}):e.type===ce.Postgresql?n(u0,{dataSource:e}):null}),c0=T.observer(({dataSource:e})=>p(a.Stack,{spacing:40,pt:10,sx:{flexGrow:1,overflow:"auto",position:"relative"},children:[n($e,{children:n(o0,{dataSource:e})}),n($e,{children:n(d0,{dataSource:e})})]}));function p0({table_type:e}){return e==="VIEW"?n(V.IconEye,{size:14}):e==="BASE TABLE"?n(V.IconTable,{size:14}):null}const h0=T.observer(({dataSource:e})=>{const{tables:t}=e;return t.loading?n(Vs,{height:"24px",lastWidth:"50%",count:15}):n(a.Box,{h:"100%",sx:{overflow:"auto",".mantine-NavLink-label":{fontFamily:"monospace"}},children:Object.entries(t.data).map(([r,i])=>n(a.NavLink,{label:r,icon:n(V.IconDatabase,{size:14}),defaultOpened:e.table_schema===r,pl:0,childrenOffset:14,children:i.map(s=>n(a.NavLink,{label:s.table_name,icon:n(p0,{table_type:s.table_type}),onClick:()=>{e.setKeywords(r,s.table_name)},active:e.table_name===s.table_name},s.table_name))},r))})}),f0=({visible:e})=>n(a.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:n(a.LoadingOverlay,{visible:e})}),g0=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],m0={icon:{width:"50px",textAlign:"center"},input:{"&.mantine-Input-withIcon":{paddingLeft:"50px"}}},b0=T.observer(({dataSource:e})=>{const{tableData:t}=e;return p(a.Group,{pt:10,px:10,position:"apart",children:[p(a.Group,{position:"left",children:[t.maxPage>1&&n(a.Pagination,{size:"sm",page:t.page,onChange:t.setPage,total:t.maxPage,withEdges:t.maxPage>7,styles:{item:{height:"30px"}}}),n(a.Select,{icon:n(a.Text,{ta:"center",color:"dimmed",size:14,children:"Limit"}),size:"xs",styles:m0,data:g0,value:String(t.limit),onChange:r=>t.setLimit(Number(r))})]}),n(a.Group,{position:"right",children:p(a.Text,{color:"dimmed",my:0,size:14,children:["Total ",t.total," rows"]})})]})}),y0=T.observer(({dataSource:e})=>{const t=e.tableData;return t.maxPage===0?n(a.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:"This table is empty"}):t.error?n(a.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:t.error}):t.page===1&&t.loading?n(f0,{visible:!0}):p($e,{children:[n(b0,{dataSource:e}),p(a.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[n(a.LoadingOverlay,{visible:t.loading,overlayBlur:2}),n(zs,{data:t.data})]})]})}),v0={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},x0=T.observer(({dataSource:e})=>(b.useEffect(()=>{e.loadTablesIfEmpty()},[e]),e.tables.error?n(a.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:e.tables.error}):p(a.Flex,{sx:{height:"100%"},children:[n(a.Box,{w:300,sx:{flexGrow:0,flexShrink:0,position:"relative"},children:n($e,{children:n(h0,{dataSource:e})})}),p(a.Tabs,{defaultValue:"structure",styles:v0,children:[p(a.Tabs.List,{children:[n(a.Tabs.Tab,{value:"structure",icon:n(V.IconColumns,{size:14}),children:"Structure"}),n(a.Tabs.Tab,{value:"data",icon:n(V.IconDatabase,{size:14}),children:"Data"})]}),n(a.Tabs.Panel,{value:"structure",children:n(c0,{dataSource:e})}),n(a.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:n(y0,{dataSource:e})})]})]}))),C0={modal:{paddingLeft:"0px !important",paddingRight:"0px !important"},header:{marginBottom:0,padding:"0 20px 10px",borderBottom:"1px solid #efefef"},title:{flexGrow:1},body:{padding:"0 0 0 20px"}},Bs=T.observer(({dataSource:e,triggerButtonProps:t={}})=>{const[r,i]=b.useState(!1);return p(O,{children:[n(a.Modal,{opened:r,onClose:()=>i(!1),title:p(a.Group,{position:"apart",sx:{flexGrow:1},children:[n(a.Text,{fw:500,children:"Explorer Data Source"}),p(a.Group,{spacing:7,children:[n(a.Badge,{variant:"gradient",gradient:{from:"indigo",to:"cyan"},children:e.key}),n(a.Badge,{variant:"gradient",gradient:{from:"orange",to:"red"},children:e.type})]})]}),zIndex:320,size:"96vw",overflow:"inside",styles:C0,children:n(a.Box,{sx:{height:"calc(100vh - 220px)"},children:n(x0,{dataSource:e})})}),n(a.Button,{variant:"subtle",onClick:()=>i(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},...t,children:"See Table Structure"})]})}),w0=b.forwardRef(({label:e,type:t,...r},i)=>p(a.Group,{position:"apart",ref:i,...r,children:[n(a.Text,{children:e}),n(a.Text,{children:t})]})),_0=T.observer(({value:e,onChange:t})=>{const r=ye(),{data:i=[],loading:s}=Z.useRequest(dr,{refreshDeps:[]},[]),o=b.useMemo(()=>i.map(c=>({label:c.key,value:c.key,type:c.type})),[i]),u=b.useMemo(()=>o.reduce((c,f)=>(c[f.value]=f.type,c),{}),[o]),l=c=>{c!==null&&t({key:c,type:u[c]})},d=b.useMemo(()=>r.datasources.find(e),[r,e]);return n(a.Select,{data:o,label:p(a.Group,{position:"apart",children:[n(a.Box,{children:"Data Source"}),d&&n(Bs,{dataSource:d,triggerButtonProps:{compact:!0,size:"xs",px:10}})]}),itemComponent:w0,rightSection:d?n(a.Text,{size:"xs",color:"dimmed",children:d.type}):void 0,rightSectionWidth:85,maxDropdownHeight:280,styles:{root:{flex:1},label:{display:"block"},rightSection:{pointerEvents:"none",".mantine-Text-root":{userSelect:"none"}}},disabled:s,value:e.key,onChange:l})}),S0=e=>{const{queryModel:t}=e,r=ye(),i=F(),o=i.findQueryUsage(t.id).length>0,u=Le.useModals(),l=()=>{u.openConfirmModal({title:"Delete this query?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.queries.removeQuery(t.id),r.editor.setPath(["_QUERIES_",""])},zIndex:320})};return o?n(a.Tooltip,{label:"Can't delete this query for it's being used, check out Usage tab for details",withArrow:!0,events:{hover:!0,focus:!1,touch:!1},withinPortal:!0,children:n(a.Button,{color:"gray",size:"xs",leftIcon:n(V.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})}):n(a.Button,{color:"red",size:"xs",onClick:l,leftIcon:n(V.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})},T0=T.observer(S0),k0=T.observer(({queryModel:e})=>n(a.Center,{ml:20,mt:20,sx:{maxWidth:"600px"},children:p(a.Stack,{spacing:10,sx:{width:"100%"},children:[n(a.Divider,{mb:-10,variant:"dashed",label:"Basics",labelPosition:"center"}),n(a.TextInput,{placeholder:"A unique name",label:"Name",required:!0,sx:{flex:1},value:e.name,onChange:t=>{e.setName(t.currentTarget.value)}}),n(_0,{value:{type:e.type,key:e.key},onChange:({type:t,key:r})=>{e.setKey(r),e.setType(t)}}),n(a.Divider,{mt:10,mb:-10,variant:"dashed",label:"Conditions",labelPosition:"center"}),n(a.MultiSelect,{label:"Run query when these are truthy",data:e.conditionOptions,value:[...e.run_by],onChange:e.setRunBy}),n(a.Divider,{mt:20,mb:10,variant:"dashed"}),n(T0,{queryModel:e})]})}));function D0(){const[e,{open:t,close:r}]=ve.useDisclosure(!1);return p(O,{children:[n(a.Modal,{opened:e,onClose:r,title:"About FunctionUtils",zIndex:320,children:n(qt,{value:Hy,styles:{root:{border:"none"},content:{padding:0}}})}),n(a.Button,{variant:"light",color:"violet",size:"xs",onClick:t,leftIcon:n(V.IconInfoCircle,{size:16}),children:"About parameter 'utils'"})]})}const M0=({value:e,onChange:t})=>{const r=i=>{i&&t(i)};return n(a.Box,{sx:{position:"relative",flexGrow:1},children:n(_e,{className:"function-editor",height:"100%",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1}}})})},ln=b.forwardRef(({value:e,onChange:t,label:r,defaultValue:i},s)=>{const[o,u]=b.useState(e),l=()=>{t(o)},d=()=>{u(e)},c=()=>{u(i)};b.useEffect(()=>{u(e)},[e]);const f=o!==e;return p(a.Stack,{spacing:4,sx:{height:"100%"},children:[p(a.Group,{mb:6,position:"apart",sx:{flexShrink:0,flexGrow:0},children:[n(a.Group,{position:"left",children:n(D0,{})}),p(a.Group,{position:"right",children:[n(a.Button,{onClick:c,size:"xs",variant:"default",leftIcon:n(V.IconPlayerSkipBack,{size:16}),children:"Reset to default"}),n(a.Button,{onClick:d,color:"red",size:"xs",disabled:!f,leftIcon:n(V.IconRecycle,{size:16}),children:"Revert Changes"}),n(a.Button,{size:"xs",onClick:l,disabled:!f,leftIcon:n(V.IconDeviceFloppy,{size:16}),children:"Confirm Changes"})]})]}),n(a.Text,{size:14,children:r}),n(M0,{value:o,onChange:u})]})}),I0=`
454
+ `,wx=()=>{const[e,t]=b.useState(!1);return p(O,{children:[n(a.Button,{variant:"subtle",compact:!0,onClick:()=>t(r=>!r),children:e?"Close":"Click to see expected data structure"}),n(a.Collapse,{in:e,children:n(ot.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:Cx})})]})},_x=T.observer(function({config:t}){return p(O,{children:[n(a.TextInput,{label:"Min-width",value:t.min_width,onChange:r=>t.setMinWidth(r.currentTarget.value),placeholder:"200px"}),n(a.Divider,{label:"Fetch options from database",labelPosition:"center"}),n(a.NumberInput,{value:t.default_selection_count,onChange:t.setDefaultSelectionCount,label:"Select first N options by default"}),n(yr,{value:t.options_query_id,onChange:t.setOptionsQueryID}),n(wx,{})]})}),Sx=T.observer(function({filter:t}){const[r,i]=b.useState(t.plainDefaultValue);return b.useEffect(()=>{i(t.plainDefaultValue)},[t]),p(a.Box,{sx:{maxWidth:"480px"},children:[n(a.Text,{pb:"md",color:"gray",children:"Preview"}),n(Oi,{filter:t,value:r,onChange:i}),n(a.Text,{pt:"lg",pb:"md",color:"gray",children:"Config"}),n(ot.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(t,null,4)})]})}),Tx={select:vx,"multi-select":yx,"tree-select":_x,"text-input":xx,checkbox:fx,"date-range":mx},kx=[{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"}],Dx=T.observer(function({filter:t}){const r=F(),i=b.useMemo(()=>Tx[t.type],[t.type]);return p(a.Group,{grow:!0,spacing:20,align:"top",children:[p(a.Box,{sx:{maxWidth:"600px"},children:[n(a.Text,{pb:"md",color:"gray",children:"Edit"}),p(a.Stack,{children:[p(a.Group,{noWrap:!0,children:[n(a.NumberInput,{label:"Placement Order",required:!0,value:t.order,onChange:t.setOrder,hideControls:!0,sx:{flexGrow:"1 !important"}}),t.auto_submit_supported&&n(a.Checkbox,{label:"Submit automatically",checked:t.auto_submit,onChange:s=>t.setAutoSubmit(s.currentTarget.checked),mt:22})]}),n(a.MultiSelect,{label:"Visible in...",data:r.views.options,value:[...t.visibleInViewsIDs],onChange:t.setVisibleInViewsIDs}),n(a.TextInput,{label:"Key",placeholder:"A unique key to refer",required:!0,value:t.key,onChange:s=>{t.setKey(s.currentTarget.value)}}),n(a.TextInput,{label:"Label",placeholder:"Label for this field",required:!0,value:t.label,onChange:s=>{t.setLabel(s.currentTarget.value)}}),n(a.Select,{label:"Widget",data:kx,required:!0,value:t.type,onChange:t.setType}),n(i,{config:t.config})]})]}),n(Sx,{filter:t})]})}),Mx=T.observer(({id:e})=>{const t=Le.useModals(),r=me(),i=F();if(e==="")return null;const s=i.filters.findByID(e);if(!s)return p(a.Text,{size:14,children:["Filter by ID[",e,"] is not found"]});const o=()=>{r.editor.setPath(["_FILTERS_",""])},u=()=>{t.openConfirmModal({title:"Delete this filter?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.filters.removeByID(e),o()},zIndex:320})};return p(a.Stack,{sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",pb:30,children:[n(a.Group,{position:"right",pt:10,children:n(a.Button,{size:"xs",color:"red",leftIcon:n(k.Trash,{size:16}),onClick:u,children:"Delete this filter"})}),n(a.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:n(Dx,{filter:s})})]})}),Ix=T.observer(()=>{const e=F(),[t,r]=b.useState(()=>JSON.stringify(e.mock_context.current,null,4)),i=()=>{try{e.mock_context.replace(JSON.parse(t))}catch(o){Vt.showNotification({title:"Failed",message:o.message,color:"red"})}},s=b.useMemo(()=>{try{return JSON.stringify(JSON.parse(t))!==JSON.stringify(e.mock_context.current)}catch{return!1}},[t,e.mock_context.current]);return p(a.Stack,{sx:{border:"1px solid #eee",borderLeft:"none",borderRight:"none",flexGrow:1,maxWidth:"unset"},children:[n(a.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:n(a.Text,{weight:500,children:"Mock Context"})}),p(a.Group,{grow:!0,px:"md",pb:"md",pt:0,sx:{flexGrow:1,position:"relative",alignItems:"flex-start"},children:[p(a.Stack,{spacing:10,sx:{maxWidth:"unset !important"},children:[n(a.Text,{children:"A valid json string is required"}),n(a.JsonInput,{validationError:"Invalid json",formatOnBlur:!0,autosize:!0,minRows:30,value:t,onChange:r,sx:{flexGrow:1}})]}),n(a.ActionIcon,{mr:5,variant:"filled",color:"blue",sx:{position:"absolute",right:12,top:0},disabled:!s,onClick:i,children:n(k.DeviceFloppy,{size:20})})]})]})}),Ax=T.observer(()=>{const{panel:e}=Ce();return n(qn,{label:"Description",value:e.description,onChange:e.setDescription,styles:{root:{flexGrow:1}}})}),$x=T.observer(()=>{const{panel:e}=Ce(),{style:t}=e;return n(O,{children:n(a.Switch,{label:"Border",checked:t.border.enabled,onChange:r=>t.border.setEnabled(r.currentTarget.checked)})})}),zx=T.observer(()=>{const{panel:e}=Ce(),{title:t,setTitle:r}=e,[i,s]=ve.useInputState(t),o=t!==i,u=b.useCallback(()=>{o&&r(i)},[o,i]);return b.useEffect(()=>{s(t)},[t]),n(a.TextInput,{value:i,onChange:s,label:p(a.Group,{children:[n(a.Text,{children:"Panel Title"}),n(a.ActionIcon,{variant:"subtle",color:"blue",disabled:!o,onClick:u,children:n(k.DeviceFloppy,{size:20})})]}),styles:{label:{display:"block",paddingBottom:"4px"}}})});function Ex(){return p(a.Stack,{sx:{height:"100%"},children:[n(a.Divider,{label:"Style",labelPosition:"center",variant:"dashed"}),n($x,{}),n(a.Divider,{label:"Info",labelPosition:"center",variant:"dashed"}),n(zx,{}),n(Ax,{})]})}const Lx=({queryID:e})=>{const t=F(),{state:r,error:i}=t.getDataStuffByID(e),s=b.useMemo(()=>t.queries.findByID(e),[t,e]);return r==="loading"?null:i?n(a.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:i}):s!=null&&s.stateMessage?n(a.Text,{color:"gray",align:"center",children:s.stateMessage}):null},Px={width:"fit-content",minWidth:"100%",tableLayout:"fixed",tr:{width:"fit-content"},th:{position:"relative"},".resizer":{position:"absolute",right:0,top:"50%",transform:"translateY(-50%)",cursor:"col-resize",userSelect:"none",touchAction:"none"},".resizer.isResizing":{color:"#228be6",opacity:"1"},"@media (hover: hover)":{".resizer":{opacity:"0"},"*:hover > .resizer":{color:"#228be6",opacity:"1"}}};function zs({data:e}){const t=b.useMemo(()=>{if(!Array.isArray(e)||e.length===0)return[];const i=Pe.createColumnHelper();return Object.keys(e[0]).map(s=>i.accessor(s,{cell:o=>o.getValue()}))},[e]),r=Pe.useReactTable({data:e,columns:t,columnResizeMode:"onChange",getCoreRowModel:Pe.getCoreRowModel()});return e.length===0?n(a.Box,{sx:{height:"5em"}}):n($e,{children:p(a.Table,{sx:Px,children:[n("thead",{children:r.getHeaderGroups().map(i=>n("tr",{children:i.headers.map(s=>p("th",{style:{width:s.getSize()},children:[s.isPlaceholder?null:Pe.flexRender(s.column.columnDef.header,s.getContext()),n(a.ActionIcon,{onMouseDown:s.getResizeHandler(),onTouchStart:s.getResizeHandler(),className:`resizer ${s.column.getIsResizing()?"isResizing":""}`,children:n(k.ArrowBarToRight,{})})]},s.id))},i.id))}),n("tbody",{children:r.getRowModel().rows.map(i=>n("tr",{children:i.getVisibleCells().map(s=>n("td",{children:n($e,{children:Pe.flexRender(s.column.columnDef.cell,s.getContext())})},s.id))},i.id))})]})})}const Es=T.observer(function({id:t}){const r=F(),{data:i,state:s}=r.getDataStuffByID(t),o=s==="loading",u=()=>{r.queries.refetchDataByQueryID(t)},l=()=>{r.queries.downloadDataByQueryID(t)},d=b.useMemo(()=>Array.isArray(i)?i.slice(0,10):[],[i]),c=!Array.isArray(i)||i.length===0;return p(a.Stack,{sx:{border:"1px solid #eee"},children:[p(a.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[p(a.Group,{position:"left",children:[n(a.Text,{weight:500,children:"Preview Data"}),i.length>10&&p(a.Text,{size:"sm",color:"gray",children:["Showing 10 rows of ",i.length]})]}),p(a.Group,{pr:15,children:[n(a.ActionIcon,{variant:"subtle",color:"blue",disabled:o,onClick:u,children:n(k.Refresh,{size:15})}),n(a.ActionIcon,{variant:"subtle",color:"blue",disabled:o||c,onClick:l,children:n(k.Download,{size:15})})]})]}),p(a.Box,{sx:{position:"relative",overflow:"auto"},children:[n(a.LoadingOverlay,{visible:o}),n(Lx,{queryID:t}),n(zs,{data:d})]})]})}),Ox=T.observer(function(){const t=me(),r=F(),{panel:{queryID:i,setQueryID:s}}=Ce(),o=()=>{t.editor.setPath(["_QUERIES_",i])};return p(a.Stack,{children:[p(a.Group,{position:"left",sx:{maxWidth:"600px",alignItems:"baseline"},children:[n(a.Text,{children:"Use query"}),n(a.Select,{data:r.queries.options,value:i,onChange:s,allowDeselect:!1,clearable:!1,sx:{flexGrow:"1 !important"},maxDropdownHeight:300,rightSection:i&&n(a.Tooltip,{label:"Open this query",children:n(a.ActionIcon,{variant:"subtle",color:"blue",onClick:o,children:n(V.IconArrowCurveRight,{size:16})})})})]}),n(Es,{id:i})]})}),Vx=T.observer(({height:e})=>{const t=F(),{data:r,loading:i,error:s,panel:{viz:o,queryID:u}}=Ce(),l=t.queries.findByID(u);return n(Wa,{viz:o,data:r,loading:i,error:s,query:l,height:e})}),Bx=T.observer(()=>{const{panel:{title:e,style:{border:t}}}=Ce();return n($e,{children:n(a.Box,{sx:{height:"100%",flexGrow:0,flexShrink:0,width:"600px"},children:p(a.Stack,{mt:24,spacing:5,sx:{width:"600px",height:"450px",background:"transparent",borderRadius:"5px",border:"1px solid #e9ecef",borderWidth:t.enabled?"1px":"0px"},children:[p(a.Group,{position:"apart",noWrap:!0,sx:{flexGrow:0,flexShrink:0},children:[n(a.Group,{children:n(Bi,{})}),n(a.Group,{grow:!0,position:"center",children:n(a.Text,{lineClamp:1,weight:"bold",children:e})}),n(a.Group,{position:"right",spacing:0,sx:{height:"28px"}})]}),n(a.Group,{px:5,pb:5,sx:{flexGrow:1},children:n(Vx,{height:"410px"})})]})})})}),vr={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 Nx{constructor(t){P(this,"panel");P(this,"selected");this.panel=t,ae.makeAutoObservable(this,{},{deep:!1,autoBind:!0})}get variables(){return this.panel.variables}addNew(){const t=this.panel.variables.filter(r=>r.name.startsWith(vr.name)).length;this.panel.addVariable(v.cloneDeep({...vr,name:`${vr.name}${t||""}`})),this.selected=v.last(this.panel.variables)}select(t){this.selected=t}remove(t){this.selected===t&&(this.selected=void 0);const r=this.panel.variables.indexOf(t);if(this.panel.removeVariable(t),!this.selected&&!v.isEmpty(this.panel.variables)){const i=Math.min(this.panel.variables.length-1,r);this.selected=this.panel.variables[i]}}}function Gx(){const{panel:e}=Ce();return Z.useCreation(()=>new Nx(e),[e])}const qx=b.forwardRef(function({value:t,onChange:r,data:i,withStyle:s=!0},o){const u=(l,d)=>{const c=v.cloneDeep(t);v.set(c,l,d),r(c)};return p(a.Box,{px:"sm",py:"md",ref:o,children:[p(a.Group,{grow:!0,noWrap:!0,children:[n(a.TextInput,{label:"Name",required:!0,value:t.name,onChange:l=>u("name",l.currentTarget.value)}),n(Y,{label:"Data Field",required:!0,data:i,value:t.data_field,onChange:l=>u("data_field",l)})]}),n(jt,{label:"Aggregation",value:t.aggregation,onChange:l=>u("aggregation",l)}),n(a.Divider,{my:"xs",label:"Format",labelPosition:"center"}),n(Be,{value:t.formatter,onChange:l=>u("formatter",l)}),s&&n(na,{value:t,onChange:r})]})}),Ls=a.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}})),Fx=e=>{const{uiModel:t}=e;return n(a.Stack,{className:"var-list",children:t.variables.map(r=>n(a.Button,{variant:t.selected===r?"filled":"subtle",color:"gray",onClick:()=>t.select(r),children:r.name},r.name))})},Wx=T.observer(Fx),jx=({variable:e,data:t})=>n(a.Group,{style:{minHeight:0,height:"calc(100% - 68px)"},children:n(a.Paper,{withBorder:!0,p:"md",children:ra(e,t)})}),Yx=T.observer(jx),Rx=e=>{const t=Z.useCreation(()=>_v(e.variable),[e.variable]),{classes:r}=Ls(),{data:i}=Ce();return p(a.Group,{style:{height:"100%"},align:"start",children:[p(a.Stack,{"data-testid":"variable-editor",align:"stretch",className:r.config,children:[p(a.Group,{position:"right",children:[n(a.ActionIcon,{variant:"filled",disabled:!t.changed,color:"primary",onClick:t.commit,children:n(V.IconDeviceFloppy,{size:18})}),n(a.ActionIcon,{color:"red",onClick:()=>e.uiModel.remove(e.variable),children:n(V.IconTrash,{size:18})})]}),n(qx,{value:y.getSnapshot(t.copy),onChange:t.update,data:i})]}),n(Yx,{variable:y.getSnapshot(t.copy),data:i})]})},Qx=T.observer(Rx),Ux=()=>{const e=Gx(),{classes:t}=Ls();return p(a.Group,{className:t.root,noWrap:!0,align:"start",children:[n(a.Paper,{withBorder:!0,p:"md",className:"var-list-container",children:p(a.Stack,{justify:"space-between",children:[n(a.Box,{className:"var-list-actions",children:n(a.Button,{variant:"light",size:"sm",onClick:e.addNew,fullWidth:!0,children:"Add Variable"})}),n(Wx,{uiModel:e})]})}),e.selected?n(O,{children:n(Qx,{uiModel:e,variable:e.selected})}):n("span",{children:"Select or create a new variable on right side"})]})},Xx=T.observer(Ux);function Zx(){const{vizManager:e}=b.useContext(Ge);return b.useMemo(()=>{const t=e.availableVizList.map(r=>({value:r.name,label:r.displayName??r.name,group:r.displayGroup??""}));return v.orderBy(t,[r=>r.group,r=>r.label],["asc","asc"])},[e])}const Kx=T.observer(({value:e,submit:t})=>{const[r,i]=ve.useInputState(e);b.useEffect(()=>{i(e)},[e]);const s=Zx(),o=e!==r;return n(a.Select,{label:"Visualization",value:r,searchable:!0,onChange:i,data:s,rightSection:n(a.ActionIcon,{disabled:!o,onClick:()=>t(r),children:n(k.DeviceFloppy,{size:20})}),maxDropdownHeight:600})}),Ps=[];function Jx(e,t){try{return e.resolveComponent(t).createConfig()}catch{return null}}function Hx(){const{data:e,panel:{variables:t,viz:r,title:i,queryID:s,description:o,setDescription:u,setTitle:l,setQueryID:d,id:c}}=Ce(),{vizManager:f}=b.useContext(Ge),g={title:i,description:o,viz:r,queryID:s,id:c},h={setDescription:u,setQueryID:d,setTitle:l},m=Ga(g);try{return f.resolveComponent(g.viz.type),n(Gt,{configure:m,children:n(ly,{variables:t,setVizConf:r.setConf,panel:g,panelInfoEditor:h,vizManager:f,data:e})})}catch(w){return console.info(v.get(w,"message")),null}}const e0=T.observer(()=>{const{data:e,panel:{viz:t}}=Ce(),{vizManager:r}=b.useContext(Ge),i=b.useCallback(c=>{if(c===t.type)return;const f=Jx(r,c);t.setType(c),t.setConf(f||{})},[t.type]),s=c=>{try{t.setConf(JSON.parse(c))}catch(f){console.error(f)}},o=b.useMemo(()=>{var c;return(c=Ps.find(f=>f.value===t.type))==null?void 0:c.Panel},[t.type,Ps]),u=Hx(),l=o?b.createElement(o,{data:e,conf:t.conf,setConf:t.setConf}):null,d=u||l;return p(a.Stack,{align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[n(Kx,{submit:i,value:t.type}),n(a.Stack,{pb:50,sx:{flexGrow:1,maxHeight:"calc(100% - 80px)",overflow:"auto"},children:d}),!d&&n(a.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(t.conf,null,2),onChange:s})]})}),t0=T.observer(({panel:e,sourceViewID:t})=>{const r=F(),[i,s]=b.useState(t);b.useEffect(()=>{s(t)},[t]);const[o,{open:u,close:l}]=ve.useDisclosure(!1),d=()=>{e.moveToView(t,i),l()};return p(O,{children:[n(a.Button,{size:"xs",variant:"subtle",color:"blue",onClick:u,leftIcon:n(V.IconBoxMultiple,{size:14}),children:"Move into Another View"}),n(a.Modal,{opened:o,onClose:l,title:"Move panel into another view",zIndex:320,overflow:"inside",children:p(a.Stack,{sx:{maxHeight:"calc(100vh - 185px)",overflow:"hidden"},children:[n(a.Radio.Group,{value:i,onChange:s,pb:10,sx:{flexGrow:1,maxHeight:"calc(100vh - 185px - 30px)",overflow:"auto"},children:n(a.Stack,{spacing:"xs",children:r.views.options.map(c=>n(a.Radio,{value:c.value,label:c.label},c.value))})}),p(a.Group,{noWrap:!0,position:"apart",sx:{flexGrow:0,flexShrink:0},children:[n(a.Button,{size:"xs",color:"red",leftIcon:n(V.IconX,{size:14}),onClick:l,children:"Cancel"}),n(a.Button,{size:"xs",color:"blue",leftIcon:n(V.IconDeviceFloppy,{size:14}),onClick:d,disabled:i===t,children:"Confirm"})]})]})})]})}),n0={root:{flexGrow:1,width:"100%",height:"100%"},panel:{width:"100%",height:"100%",padding:10}},Os=({children:e})=>p(a.Group,{noWrap:!0,grow:!0,position:"left",spacing:20,sx:{width:"100%",height:"calc(100% - 36px)"},children:[n(a.Box,{sx:{maxWidth:"calc(100% - 610px - 10px)",height:"100%",overflow:"auto"},children:e}),n(Bx,{})]});function r0(e){return!["richText","button"].includes(e)}const i0=T.observer(({panel:e})=>{const t=Le.useModals(),r=me(),i=F(),[s,o]=b.useState("Data"),{data:u,state:l,error:d}=i.getDataStuffByID(e.queryID),c=i.queries.findByID(e.queryID),g=r0(e.viz.type)&&l==="loading",h=g||d||!c||!!c.stateMessage,m=r.editor.path[1];b.useEffect(()=>{o(S=>h&&S==="Visualization"?"Data":S)},[e.id,h]);const w=()=>{r.editor.setPath(["_VIEWS_",m])},C=()=>t.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.removePanelByID(e.id,m),w()},confirmProps:{color:"red"},zIndex:320});return p(vn,{value:{panel:e,data:u,loading:g,error:d},children:[p(a.Group,{px:16,position:"apart",sx:{borderBottom:"1px solid #eee"},children:[p(a.Text,{pt:9,pb:8,children:[e.title?e.title:e.viz.type," "]}),p(a.Group,{position:"right",noWrap:!0,children:[n(t0,{panel:e,sourceViewID:m}),n(a.Button,{size:"xs",variant:"subtle",color:"red",onClick:C,leftIcon:n(V.IconTrash,{size:14}),children:"Delete This Panel"})]})]}),p(a.Tabs,{value:s,onTabChange:o,keepMounted:!1,styles:n0,children:[p(a.Tabs.List,{children:[n(a.Tabs.Tab,{value:"Data",disabled:g,children:"Data"}),n(a.Tabs.Tab,{value:"Panel",children:"Panel"}),n(a.Tabs.Tab,{value:"Variables",disabled:h,children:n(a.Tooltip,{label:"Requires data",disabled:!h,withinPortal:!0,zIndex:310,children:n(a.Text,{children:"Variables"})})}),n(a.Tabs.Tab,{value:"Visualization",disabled:h,children:n(a.Tooltip,{label:"Requires data",disabled:!h,withinPortal:!0,zIndex:310,children:n(a.Text,{children:"Visualization"})})}),n(a.Tabs.Tab,{value:"Interactions",children:"Interactions"})]}),p(a.Tabs.Panel,{value:"Data",children:[n(a.LoadingOverlay,{visible:g,exitTransitionDuration:0}),n(Ox,{})]}),n(a.Tabs.Panel,{value:"Panel",children:n(Os,{children:n(Ex,{})})}),n(a.Tabs.Panel,{value:"Variables",children:n(Xx,{})}),n(a.Tabs.Panel,{value:"Visualization",children:n($e,{children:n(Os,{children:n(e0,{})})})}),n(a.Tabs.Panel,{value:"Interactions",children:n($e,{children:n(sy,{})})})]})]})}),a0=T.observer(({viewID:e,panelID:t})=>{const r=F();if(!r.views.findByID(e))return p(a.Text,{size:14,children:["View by ID[",e,"] is not found"]});const s=r.panels.findByID(t);return s?n(i0,{panel:s}):p(a.Text,{size:14,children:["Panel by ID[",t,"] is not found"]})}),Vs=({width:e="calc(100% - 32px)",lastWidth:t="50%",height:r,count:i,spacing:s=16,pl:o=0})=>p(a.Stack,{spacing:s,mt:6,pl:o,children:[Array.from(new Array(i-1),(u,l)=>n(a.Skeleton,{width:e,height:r,radius:"xs"},l)),n(a.Skeleton,{width:t,height:r,radius:"xs"})]}),At=({value:e})=>e===null||e===""?null:n(a.Tooltip,{label:e,disabled:!e,multiline:!0,children:n(a.ActionIcon,{children:n(V.IconInfoCircle,{size:14})})}),s0=({column:e})=>{const{column_key:t,column_key_text:r}=e;return t?n(a.Tooltip,{label:r,disabled:!r,children:n(a.Badge,{children:t})}):null},o0=T.observer(({dataSource:e})=>{const{columns:t}=e;return t.loading?n(Vs,{height:"24px",width:"100%",lastWidth:"100%",count:20,pl:6}):t.empty?null:p(a.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"1000px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[n("col",{style:{width:50}}),n("col",{style:{minWidth:300}}),n("col",{style:{width:30}}),n("col",{style:{width:70}}),n("col",{style:{minWidth:300}}),n("col",{style:{minWidth:80,width:80}}),n("col",{style:{minWidth:120,width:120}})]}),n("thead",{children:p("tr",{children:[n("th",{children:"#"}),n("th",{children:"Column Name"}),n("th",{}),n("th",{}),n("th",{children:"Type"}),n("th",{children:"Nullable"}),n("th",{children:"Default Value"})]})}),n("tbody",{children:t.data.map(r=>p("tr",{children:[n("td",{children:r.ordinal_position}),n("td",{children:r.column_name}),n("td",{children:n(At,{value:r.column_comment})}),n("td",{children:n(s0,{column:r})}),n("td",{children:r.column_type}),n("td",{children:r.is_nullable}),n("td",{children:n(At,{value:r.column_default})})]},r.column_name))})]})}),l0=T.observer(({dataSource:e})=>{const{indexes:t}=e,r=t.data;return p(a.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"950px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[n("col",{style:{width:100}}),n("col",{style:{minWidth:300}}),n("col",{style:{width:150}}),n("col",{style:{width:150}}),n("col",{style:{width:250}})]}),n("thead",{children:p("tr",{children:[n("th",{children:"Index Length"}),n("th",{children:"Index Name"}),n("th",{children:"Index Algorithm"}),n("th",{children:"Unique"}),n("th",{children:"Column Name"})]})}),n("tbody",{children:r.map(i=>p("tr",{children:[n("td",{children:i.index_length}),n("td",{children:i.index_name}),n("td",{children:i.index_algorithm}),n("td",{children:i.is_unique?"YES":"NO"}),n("td",{children:i.column_name})]},i.index_name))})]})}),u0=T.observer(({dataSource:e})=>{const{indexes:t}=e,r=t.data;return p(a.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"850px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[n("col",{style:{minWidth:300}}),n("col",{style:{width:150}}),n("col",{style:{width:100}}),n("col",{style:{width:100}}),n("col",{style:{width:100}}),n("col",{style:{width:100}})]}),n("thead",{children:p("tr",{children:[n("th",{children:"Index Name"}),n("th",{children:"Index Algorithm"}),n("th",{children:"Unique"}),n("th",{children:"Definition"}),n("th",{children:"Condition"}),n("th",{children:"Comment"})]})}),n("tbody",{children:r.map(i=>p("tr",{children:[n("td",{children:i.index_name}),n("td",{children:i.index_algorithm}),n("td",{children:i.is_unique?"YES":"NO"}),n("td",{children:n(At,{value:i.index_definition})}),n("td",{children:n(At,{value:i.condition})}),n("td",{children:n(At,{value:i.comment})})]},i.index_name))})]})}),d0=T.observer(({dataSource:e})=>{const{indexes:t}=e;return t.loading||t.empty?null:e.type===ce.MySQL?n(l0,{dataSource:e}):e.type===ce.Postgresql?n(u0,{dataSource:e}):null}),c0=T.observer(({dataSource:e})=>p(a.Stack,{spacing:40,pt:10,sx:{flexGrow:1,overflow:"auto",position:"relative"},children:[n($e,{children:n(o0,{dataSource:e})}),n($e,{children:n(d0,{dataSource:e})})]}));function p0({table_type:e}){return e==="VIEW"?n(V.IconEye,{size:14}):e==="BASE TABLE"?n(V.IconTable,{size:14}):null}const h0=T.observer(({dataSource:e})=>{const{tables:t}=e;return t.loading?n(Vs,{height:"24px",lastWidth:"50%",count:15}):n(a.Box,{h:"100%",sx:{overflow:"auto",".mantine-NavLink-label":{fontFamily:"monospace"}},children:Object.entries(t.data).map(([r,i])=>n(a.NavLink,{label:r,icon:n(V.IconDatabase,{size:14}),defaultOpened:e.table_schema===r,pl:0,childrenOffset:14,children:i.map(s=>n(a.NavLink,{label:s.table_name,icon:n(p0,{table_type:s.table_type}),onClick:()=>{e.setKeywords(r,s.table_name)},active:e.table_name===s.table_name},s.table_name))},r))})}),f0=({visible:e})=>n(a.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:n(a.LoadingOverlay,{visible:e})}),g0=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],m0={icon:{width:"50px",textAlign:"center"},input:{"&.mantine-Input-withIcon":{paddingLeft:"50px"}}},b0=T.observer(({dataSource:e})=>{const{tableData:t}=e;return p(a.Group,{pt:10,px:10,position:"apart",children:[p(a.Group,{position:"left",children:[t.maxPage>1&&n(a.Pagination,{size:"sm",page:t.page,onChange:t.setPage,total:t.maxPage,withEdges:t.maxPage>7,styles:{item:{height:"30px"}}}),n(a.Select,{icon:n(a.Text,{ta:"center",color:"dimmed",size:14,children:"Limit"}),size:"xs",styles:m0,data:g0,value:String(t.limit),onChange:r=>t.setLimit(Number(r))})]}),n(a.Group,{position:"right",children:p(a.Text,{color:"dimmed",my:0,size:14,children:["Total ",t.total," rows"]})})]})}),y0=T.observer(({dataSource:e})=>{const t=e.tableData;return t.maxPage===0?n(a.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:"This table is empty"}):t.error?n(a.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:t.error}):t.page===1&&t.loading?n(f0,{visible:!0}):p($e,{children:[n(b0,{dataSource:e}),p(a.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[n(a.LoadingOverlay,{visible:t.loading,overlayBlur:2}),n(zs,{data:t.data})]})]})}),v0={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},x0=T.observer(({dataSource:e})=>(b.useEffect(()=>{e.loadTablesIfEmpty()},[e]),e.tables.error?n(a.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:e.tables.error}):p(a.Flex,{sx:{height:"100%"},children:[n(a.Box,{w:300,sx:{flexGrow:0,flexShrink:0,position:"relative"},children:n($e,{children:n(h0,{dataSource:e})})}),p(a.Tabs,{defaultValue:"structure",styles:v0,children:[p(a.Tabs.List,{children:[n(a.Tabs.Tab,{value:"structure",icon:n(V.IconColumns,{size:14}),children:"Structure"}),n(a.Tabs.Tab,{value:"data",icon:n(V.IconDatabase,{size:14}),children:"Data"})]}),n(a.Tabs.Panel,{value:"structure",children:n(c0,{dataSource:e})}),n(a.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:n(y0,{dataSource:e})})]})]}))),C0={modal:{paddingLeft:"0px !important",paddingRight:"0px !important"},header:{marginBottom:0,padding:"0 20px 10px",borderBottom:"1px solid #efefef"},title:{flexGrow:1},body:{padding:"0 0 0 20px"}},Bs=T.observer(({dataSource:e,triggerButtonProps:t={}})=>{const[r,i]=b.useState(!1);return p(O,{children:[n(a.Modal,{opened:r,onClose:()=>i(!1),title:p(a.Group,{position:"apart",sx:{flexGrow:1},children:[n(a.Text,{fw:500,children:"Explorer Data Source"}),p(a.Group,{spacing:7,children:[n(a.Badge,{variant:"gradient",gradient:{from:"indigo",to:"cyan"},children:e.key}),n(a.Badge,{variant:"gradient",gradient:{from:"orange",to:"red"},children:e.type})]})]}),zIndex:320,size:"96vw",overflow:"inside",styles:C0,children:n(a.Box,{sx:{height:"calc(100vh - 220px)"},children:n(x0,{dataSource:e})})}),n(a.Button,{variant:"subtle",onClick:()=>i(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},...t,children:"See Table Structure"})]})}),w0=b.forwardRef(({label:e,type:t,...r},i)=>p(a.Group,{position:"apart",ref:i,...r,children:[n(a.Text,{children:e}),n(a.Text,{children:t})]})),_0=T.observer(({value:e,onChange:t})=>{const r=me(),{data:i=[],loading:s}=Z.useRequest(dr,{refreshDeps:[]},[]),o=b.useMemo(()=>i.map(c=>({label:c.key,value:c.key,type:c.type})),[i]),u=b.useMemo(()=>o.reduce((c,f)=>(c[f.value]=f.type,c),{}),[o]),l=c=>{c!==null&&t({key:c,type:u[c]})},d=b.useMemo(()=>r.datasources.find(e),[r,e]);return n(a.Select,{data:o,label:p(a.Group,{position:"apart",children:[n(a.Box,{children:"Data Source"}),d&&n(Bs,{dataSource:d,triggerButtonProps:{compact:!0,size:"xs",px:10}})]}),itemComponent:w0,rightSection:d?n(a.Text,{size:"xs",color:"dimmed",children:d.type}):void 0,rightSectionWidth:85,maxDropdownHeight:280,styles:{root:{flex:1},label:{display:"block"},rightSection:{pointerEvents:"none",".mantine-Text-root":{userSelect:"none"}}},disabled:s,value:e.key,onChange:l})}),S0=e=>{const{queryModel:t}=e,r=me(),i=F(),o=i.findQueryUsage(t.id).length>0,u=Le.useModals(),l=()=>{u.openConfirmModal({title:"Delete this query?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.queries.removeQuery(t.id),r.editor.setPath(["_QUERIES_",""])},zIndex:320})};return o?n(a.Tooltip,{label:"Can't delete this query for it's being used, check out Usage tab for details",withArrow:!0,events:{hover:!0,focus:!1,touch:!1},withinPortal:!0,children:n(a.Button,{color:"gray",size:"xs",leftIcon:n(V.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})}):n(a.Button,{color:"red",size:"xs",onClick:l,leftIcon:n(V.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})},T0=T.observer(S0),k0=T.observer(({queryModel:e})=>n(a.Center,{ml:20,mt:20,sx:{maxWidth:"600px"},children:p(a.Stack,{spacing:10,sx:{width:"100%"},children:[n(a.Divider,{mb:-10,variant:"dashed",label:"Basics",labelPosition:"center"}),n(a.TextInput,{placeholder:"A unique name",label:"Name",required:!0,sx:{flex:1},value:e.name,onChange:t=>{e.setName(t.currentTarget.value)}}),n(_0,{value:{type:e.type,key:e.key},onChange:({type:t,key:r})=>{e.setKey(r),e.setType(t)}}),n(a.Divider,{mt:10,mb:-10,variant:"dashed",label:"Conditions",labelPosition:"center"}),n(a.MultiSelect,{label:"Run query when these are truthy",data:e.conditionOptions,value:[...e.run_by],onChange:e.setRunBy}),n(a.Divider,{mt:20,mb:10,variant:"dashed"}),n(T0,{queryModel:e})]})}));function D0(){const[e,{open:t,close:r}]=ve.useDisclosure(!1);return p(O,{children:[n(a.Modal,{opened:e,onClose:r,title:"About FunctionUtils",zIndex:320,children:n(qt,{value:Hy,styles:{root:{border:"none"},content:{padding:0}}})}),n(a.Button,{variant:"light",color:"violet",size:"xs",onClick:t,leftIcon:n(V.IconInfoCircle,{size:16}),children:"About parameter 'utils'"})]})}const M0=({value:e,onChange:t})=>{const r=i=>{i&&t(i)};return n(a.Box,{sx:{position:"relative",flexGrow:1},children:n(_e,{className:"function-editor",height:"100%",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1}}})})},ln=b.forwardRef(({value:e,onChange:t,label:r,defaultValue:i},s)=>{const[o,u]=b.useState(e),l=()=>{t(o)},d=()=>{u(e)},c=()=>{u(i)};b.useEffect(()=>{u(e)},[e]);const f=o!==e;return p(a.Stack,{spacing:4,sx:{height:"100%"},children:[p(a.Group,{mb:6,position:"apart",sx:{flexShrink:0,flexGrow:0},children:[n(a.Group,{position:"left",children:n(D0,{})}),p(a.Group,{position:"right",children:[n(a.Button,{onClick:c,size:"xs",variant:"default",leftIcon:n(V.IconPlayerSkipBack,{size:16}),children:"Reset to default"}),n(a.Button,{onClick:d,color:"red",size:"xs",disabled:!f,leftIcon:n(V.IconRecycle,{size:16}),children:"Revert Changes"}),n(a.Button,{size:"xs",onClick:l,disabled:!f,leftIcon:n(V.IconDeviceFloppy,{size:16}),children:"Confirm Changes"})]})]}),n(a.Text,{size:14,children:r}),n(M0,{value:o,onChange:u})]})}),I0=`
455
455
  -- You may reference global variables in SQL or VizConfig.
456
456
  SELECT *
457
457
  FROM commit
@@ -463,8 +463,8 @@ WHERE
463
463
  -- SQL snippets
464
464
  AND \${sql_snippets.author_email_condition}
465
465
  \${sql_snippets.order_by_clause}
466
- `,Ns=T.observer(function({showSQLSnippets:t=!0,sx:r={}}){const i=ye(),s=F(),o=i.context.current,u=(()=>{const l={context:{...s.mock_context.current,...o},filters:s.filters.previewValues};return t&&(l.sql_snippets=s.sqlSnippets.record),JSON.stringify(l,null,2)})();return n(a.Stack,{sx:{overflow:"hidden",...r},children:p(a.Stack,{sx:{width:"100%"},children:[n(a.Text,{weight:500,sx:{flexGrow:0},children:"Guide"}),n(ot.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:I0}),n(a.Text,{weight:500,sx:{flexGrow:0},children:"Current Values"}),n(ot.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:u})]})})}),xr=T.observer(()=>{const[e,t]=b.useState(!1);return p(O,{children:[n(a.Modal,{opened:e,onClose:()=>t(!1),title:"Global Variables",zIndex:320,size:"800px",children:n(Ns,{})}),n(a.Button,{variant:"subtle",onClick:()=>t(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},children:"See Global Variables"})]})}),Gs={pre:["function build_request({ context, filters }, utils) {"," // build the quest"," return { method, url, params, headers, data }","}"].join(`
466
+ `,Ns=T.observer(function({showSQLSnippets:t=!0,sx:r={}}){const i=me(),s=F(),o=i.context.current,u=(()=>{const l={context:{...s.mock_context.current,...o},filters:s.filters.previewValues};return t&&(l.sql_snippets=s.sqlSnippets.record),JSON.stringify(l,null,2)})();return n(a.Stack,{sx:{overflow:"hidden",...r},children:p(a.Stack,{sx:{width:"100%"},children:[n(a.Text,{weight:500,sx:{flexGrow:0},children:"Guide"}),n(ot.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:I0}),n(a.Text,{weight:500,sx:{flexGrow:0},children:"Current Values"}),n(ot.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:u})]})})}),xr=T.observer(()=>{const[e,t]=b.useState(!1);return p(O,{children:[n(a.Modal,{opened:e,onClose:()=>t(!1),title:"Global Variables",zIndex:320,size:"800px",children:n(Ns,{})}),n(a.Button,{variant:"subtle",onClick:()=>t(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},children:"See Global Variables"})]})}),Gs={pre:["function build_request({ context, filters }, utils) {"," // build the quest"," return { method, url, params, headers, data }","}"].join(`
467
467
  `),post:["function process_result(res, utils) {"," // your code goes here"," return data","}"].join(`
468
- `)},A0=T.observer(({queryModel:e})=>e.typedAsHTTP?p(a.Tabs,{defaultValue:"pre_process",orientation:"vertical",sx:{flexGrow:1},children:[p(a.Tabs.List,{children:[n(a.Tabs.Tab,{value:"pre_process",children:"Build Request"}),n(a.Tabs.Tab,{value:"post_process",children:"Process Result"}),n(xr,{})]}),n(a.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:n(ln,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:Gs.pre})}),n(a.Tabs.Panel,{value:"post_process",p:"sm",children:n(ln,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:Gs.post})})]}):null),$0=T.observer(({queryID:e,usage:t})=>{const r=ye().editor,i=o=>{if(o.type==="filter"){r.setPath(["_FILTERS_",o.id]);return}if(o.type==="panel"){const u=o.views[0].id;r.setPath(["_VIEWS_",u,"_PANELS_",o.id]);return}},s=o=>{r.setPath(["_VIEWS_",o])};return n(a.Stack,{py:"sm",px:"md",children:p(a.Table,{highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[n("thead",{children:p("tr",{children:[n("th",{style:{width:100},children:"Type"}),n("th",{style:{width:"calc(50% - 50px)"},children:"Name"}),n("th",{children:"In View(s)"})]})}),n("tbody",{children:t.map(o=>p("tr",{children:[n("td",{children:v.capitalize(o.type)}),n("td",{children:n(a.Anchor,{component:"button",type:"button",onClick:()=>i(o),children:o.label})}),n("td",{children:p(a.Stack,{align:"flex-start",justify:"flex-start",spacing:2,children:[o.views.map(u=>n(a.Anchor,{component:"button",type:"button",onClick:()=>s(u.id),children:n(a.Box,{children:u.label})})),o.views.length===0&&n(a.Box,{children:"--"})]})})]},o.id))})]})})}),Cr=({value:e,onChange:t,height:r="200px",defaultLanguage:i="sql"})=>{const s=u=>{console.log("changing"),t==null||t(u??"")},o=!t;return n(_e,{className:"minimal-monaco-editor",height:r,defaultLanguage:i,value:e,onChange:o?void 0:s,theme:"vs-dark",options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1},readOnly:o||!t}})},z0=({value:e,height:t="200px",defaultLanguage:r="sql"})=>n(_e,{className:"preview-sql-in-monaco-editor",height:t,defaultLanguage:r,value:e,onChange:void 0,theme:"vs-light",options:{lineNumbers:"on",folding:!0,lineDecorationsWidth:20,wordWrap:"on",minimap:{enabled:!1},readOnly:!0}}),E0=T.observer(({value:e})=>{const r=F().payloadForSQL,i=b.useMemo(()=>{const{context:s,mock_context:o,sqlSnippets:u,filterValues:l}=r;return ds(e,s,o,u,l)},[e,r]);return n(z0,{height:"100%",value:i})}),qs={pre:["function process_request({ context, filters, sql }, utils) {"," // modify and return sql"," return sql","}"].join(`
468
+ `)},A0=T.observer(({queryModel:e})=>e.typedAsHTTP?p(a.Tabs,{defaultValue:"pre_process",orientation:"vertical",sx:{flexGrow:1},children:[p(a.Tabs.List,{children:[n(a.Tabs.Tab,{value:"pre_process",children:"Build Request"}),n(a.Tabs.Tab,{value:"post_process",children:"Process Result"}),n(xr,{})]}),n(a.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:n(ln,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:Gs.pre})}),n(a.Tabs.Panel,{value:"post_process",p:"sm",children:n(ln,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:Gs.post})})]}):null),$0=T.observer(({queryID:e,usage:t})=>{const r=me().editor,i=o=>{if(o.type==="filter"){r.setPath(["_FILTERS_",o.id]);return}if(o.type==="panel"){const u=o.views[0].id;r.setPath(["_VIEWS_",u,"_PANELS_",o.id]);return}},s=o=>{r.setPath(["_VIEWS_",o])};return n(a.Stack,{py:"sm",px:"md",children:p(a.Table,{highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[n("thead",{children:p("tr",{children:[n("th",{style:{width:100},children:"Type"}),n("th",{style:{width:"calc(50% - 50px)"},children:"Name"}),n("th",{children:"In View(s)"})]})}),n("tbody",{children:t.map(o=>p("tr",{children:[n("td",{children:v.capitalize(o.type)}),n("td",{children:n(a.Anchor,{component:"button",type:"button",onClick:()=>i(o),children:o.label})}),n("td",{children:p(a.Stack,{align:"flex-start",justify:"flex-start",spacing:2,children:[o.views.map(u=>n(a.Anchor,{component:"button",type:"button",onClick:()=>s(u.id),children:n(a.Box,{children:u.label})})),o.views.length===0&&n(a.Box,{children:"--"})]})})]},o.id))})]})})}),Cr=({value:e,onChange:t,height:r="200px",defaultLanguage:i="sql"})=>{const s=u=>{console.log("changing"),t==null||t(u??"")},o=!t;return n(_e,{className:"minimal-monaco-editor",height:r,defaultLanguage:i,value:e,onChange:o?void 0:s,theme:"vs-dark",options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1},readOnly:o||!t}})},z0=({value:e,height:t="200px",defaultLanguage:r="sql"})=>n(_e,{className:"preview-sql-in-monaco-editor",height:t,defaultLanguage:r,value:e,onChange:void 0,theme:"vs-light",options:{lineNumbers:"on",folding:!0,lineDecorationsWidth:20,wordWrap:"on",minimap:{enabled:!1},readOnly:!0}}),E0=T.observer(({value:e})=>{const r=F().payloadForSQL,i=b.useMemo(()=>{const{context:s,mock_context:o,sqlSnippets:u,filterValues:l}=r;return ds(e,s,o,u,l)},[e,r]);return n(z0,{height:"100%",value:i})}),qs={pre:["function process_request({ context, filters, sql }, utils) {"," // modify and return sql"," return sql","}"].join(`
469
469
  `),post:["function process_result(data, utils) {"," // process data and return the result"," return data","}"].join(`
470
- `)},L0=T.observer(({queryModel:e})=>{const[t,r]=b.useState(e.sql);b.useEffect(()=>{r(o=>o!==e.sql?e.sql:o)},[e.sql]);const i=t!==e.sql,s=()=>{e.setSQL(t)};return e.typedAsSQL?p(a.Tabs,{defaultValue:"Edit",orientation:"vertical",sx:{flexGrow:1},styles:{tabLabel:{width:"100%",height:"28px",lineHeight:"28px"}},keepMounted:!1,children:[p(a.Tabs.List,{children:[n(a.Tabs.Tab,{value:"Edit",children:p(a.Group,{spacing:14,position:"apart",children:["Edit SQL",n(a.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!i,onClick:s,children:n(k.DeviceFloppy,{size:20})})]})}),n(a.Tabs.Tab,{value:"Preview",children:"Preview SQL"}),n(a.Tabs.Tab,{value:"pre_process",children:"Process Request"}),n(a.Tabs.Tab,{value:"post_process",children:"Process Result"}),n(xr,{}),e.datasource&&n(Bs,{dataSource:e.datasource})]}),n(a.Tabs.Panel,{value:"Edit",sx:{position:"relative"},p:"sm",children:n(Cr,{height:"100%",value:t,onChange:r})}),n(a.Tabs.Panel,{value:"Preview",p:0,pl:4,children:n(E0,{value:e.sql})}),n(a.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:n(ln,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:qs.pre})}),n(a.Tabs.Panel,{value:"post_process",p:"sm",children:n(ln,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:qs.post})})]}):null}),un={height:"calc(100% - 44px)",padding:0},P0=T.observer(({queryModel:e})=>{const t=F(),r=b.useMemo(()=>e.datasource?e.typedAsHTTP?"HTTP":"SQL":"Configurations",[e.datasource,e.typedAsHTTP]),i=t.findQueryUsage(e.id),s=i.length===0;return n(a.Stack,{sx:{flexGrow:1},my:0,p:0,children:p(a.Tabs,{defaultValue:r,orientation:"horizontal",keepMounted:!1,sx:{flexGrow:1},children:[p(a.Tabs.List,{grow:!0,children:[n(a.Tabs.Tab,{value:"Configurations",children:"Configurations"}),e.typedAsSQL&&n(a.Tabs.Tab,{value:"SQL",children:"Request"}),e.typedAsHTTP&&n(a.Tabs.Tab,{value:"HTTP",children:"Request"}),n(a.Tabs.Tab,{value:"Data",disabled:!e.datasource,children:n(a.Tooltip,{label:"Need to pick a Data Source first",disabled:e.datasource,withinPortal:!0,children:n(a.Text,{children:"Data"})})}),n(a.Tabs.Tab,{value:"Usage",disabled:s,children:n(a.Tooltip,{label:"This query is not used for any filter or panel",disabled:!s,withinPortal:!0,children:n(a.Text,{children:"Usage"})})})]}),n(a.Tabs.Panel,{value:"Configurations",pt:0,p:0,children:n(k0,{queryModel:e})}),e.typedAsSQL&&n(a.Tabs.Panel,{value:"SQL",sx:un,children:n(a.Stack,{sx:{height:"100%"},children:n(L0,{queryModel:e})})}),e.typedAsHTTP&&n(a.Tabs.Panel,{value:"HTTP",sx:un,children:n(a.Stack,{sx:{height:"100%"},children:n(A0,{queryModel:e})})}),n(a.Tabs.Panel,{value:"Data",sx:{...un,overflow:"hidden"},children:n(Es,{id:e.id})}),n(a.Tabs.Panel,{value:"Usage",sx:{...un,overflow:"hidden"},children:n($0,{queryID:e.id,usage:i})})]})})}),O0=T.observer(({id:e})=>{const r=F().queries.findByID(e);return e===""?null:r?n(a.Stack,{sx:{height:"100%"},spacing:"sm",children:n(P0,{queryModel:r})}):n(a.Text,{size:14,color:"red",children:"Invalid Query ID"})}),V0=T.observer(({value:e})=>{const t=F(),{context:r,mock_context:i,filterValues:s}=t.payloadForSQL,o=sv(e,r,i,s);return n(Cr,{height:"100%",value:o})}),B0=T.observer(({item:e,remove:t,onKeyChanged:r})=>{const[i,s]=b.useState("SQL"),[o,u]=b.useState(e.key),l=()=>{e.setKey(o),r(o)},d=o!==e.key,c=e.isADuplicatedKey(o),[f,g]=b.useState(e.value),h=()=>{e.setValue(f)};b.useEffect(()=>{u(e.key),g(e.value)},[e]);const m=f!==e.value,w=Le.useModals(),C=()=>{w.openConfirmModal({title:"Delete this SQL snippet?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:t,zIndex:320})};return p(a.Stack,{p:20,sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",children:[p(a.Group,{sx:{alignItems:"end"},spacing:40,children:[n(a.TextInput,{label:c?"This key is occupied by another snippet":"Key",value:o,onChange:S=>{u(S.currentTarget.value)},sx:{flexGrow:"1 !important"},rightSection:n(a.ActionIcon,{color:"blue",variant:"subtle",onClick:l,disabled:!d||c,children:n(k.DeviceFloppy,{size:16})}),error:c}),n(a.Button,{leftIcon:n(k.Trash,{size:16}),color:"red",variant:"light",onClick:C,children:"Delete this SQL Snippet"})]}),p(a.Tabs,{value:i,onTabChange:s,sx:{flexGrow:1},styles:{panel:{height:"calc(100% - 50px)"}},children:[p(a.Tabs.List,{sx:{position:"relative"},children:[n(a.Tabs.Tab,{value:"SQL",children:"SQL"}),n(a.Tabs.Tab,{value:"Preview",children:"Preview"}),n(xr,{}),n(a.ActionIcon,{color:"blue",variant:"filled",onClick:h,disabled:!m,sx:{position:"absolute",top:0,right:10},children:n(k.DeviceFloppy,{size:18})})]}),n(a.Tabs.Panel,{value:"SQL",pt:"sm",children:n(Cr,{height:"100%",value:f,onChange:g})}),n(a.Tabs.Panel,{value:"Preview",pt:"sm",children:n(V0,{value:f})})]})]})}),N0=T.observer(({id:e})=>{const t=ye(),r=F(),i=b.useMemo(()=>r.sqlSnippets.findByKey(e),[e]);if(!e)return null;if(!i)return p(a.Text,{size:14,children:["SQL Snippet by key[",e,"] is not found"]});const s=()=>{t.editor.setPath(["_SQL_SNIPPETS_",""])};return n(B0,{item:i,remove:()=>{r.sqlSnippets.removeByKey(e),s()},onKeyChanged:l=>{t.editor.setPath(["_SQL_SNIPPETS_",l])}})}),G0=T.observer(({view:e})=>!e||e.type!==K.Division?null:p(a.Stack,{children:[n(a.Divider,{mt:8,mb:0,label:"Division settings",labelPosition:"center"}),n(a.Text,{align:"center",size:"xs",color:"dimmed",children:"Under construction"})]})),q0=[{value:"default",label:"Default"},{value:"outline",label:"Outline"},{value:"pills",label:"Pills"}],F0=[{value:"horizontal",label:"Horizontal"},{value:"vertical",label:"Vertical"}],W0=T.observer(({view:e})=>{if(!e||e.type!==K.Tabs)return null;const t=e.config;return p(a.Stack,{children:[n(a.Divider,{mt:8,mb:0,label:"Tabs settings",labelPosition:"center"}),n(a.Select,{label:"Variant",value:t.variant,onChange:t.setVariant,data:q0}),n(a.Select,{label:"Orientation",value:t.orientation,onChange:t.setOrientation,data:F0}),n(a.Switch,{label:"Grow Tabs",checked:t.grow,onChange:r=>t.setGrow(r.currentTarget.checked)})]})}),j0=({disabled:e,value:t,onChange:r})=>{const i=s=>{s&&r(s)};return p(a.Box,{sx:{position:"relative"},children:[e&&n(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),n(_e,{height:"500px",defaultLanguage:"javascript",value:t,onChange:i,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},Y0=({value:e,onChange:t})=>{const[r,{setTrue:i,setFalse:s}]=Z.useBoolean(),[o,u]=b.useState(e??cr),l=h=>{u({...o,enabled:h})},d=()=>{s();const{enabled:h,func_content:m}=o,w={enabled:h,func_content:m};u(w),t(w)},c=()=>{s(),u(e)},f=h=>{u(m=>({...m,func_content:h}))},g=()=>{f(cr.func_content)};return p(O,{children:[n(a.ActionIcon,{size:"lg",color:"blue",variant:"filled",mt:26,onClick:i,sx:{flexGrow:0},children:n(k.Settings,{size:14})}),n(a.Modal,{size:800,title:"Customize modal title",opened:r,onClose:s,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(a.Stack,{children:[n(a.Checkbox,{mt:10,label:"Enabled",checked:o.enabled,onChange:h=>l(h.currentTarget.checked)}),n(j0,{value:o.func_content,onChange:f,disabled:!o.enabled}),p(a.Group,{position:"apart",children:[n(a.Button,{onClick:g,color:"red",leftIcon:n(k.Recycle,{size:20}),children:"Rest"}),p(a.Group,{position:"right",children:[n(a.Button,{onClick:c,variant:"subtle",children:"Cancel"}),n(a.Button,{onClick:d,children:"OK"})]})]})]})})]})},R0=T.observer(({view:e})=>{if(!e||e.type!==K.Modal)return null;const t=e.config,r=t.custom_modal_title.value;return p(a.Stack,{children:[n(a.Divider,{mt:8,label:"Modal settings",labelPosition:"center"}),p(a.Flex,{gap:10,children:[n(a.TextInput,{label:"Modal Title",value:r,onChange:v.noop,disabled:!0,sx:{flexGrow:1}}),n(Y0,{value:t.custom_modal_title,onChange:t.custom_modal_title.replace})]}),p(a.Group,{grow:!0,children:[n(a.TextInput,{label:"Width",value:t.width,onChange:i=>t.setWidth(i.currentTarget.value),placeholder:"600px / 50vw"}),n(a.TextInput,{label:"Height",value:t.height,onChange:i=>t.setHeight(i.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),Q0=T.observer(({view:e})=>p(O,{children:[n(G0,{view:e}),n(R0,{view:e}),n(W0,{view:e})]})),U0=[{label:"Division",value:K.Division},{label:"Modal",value:K.Modal},{label:"Tabs",value:K.Tabs}],X0=T.observer(({view:e})=>e?p(a.Stack,{sx:{position:"relative"},children:[n(a.TextInput,{label:"Name",value:e.name,onChange:t=>{e.setName(t.currentTarget.value)}}),n(a.Select,{label:"Type",withinPortal:!0,value:e.type,onChange:e.setType,data:U0}),n(Q0,{view:e})]}):null),Z0=T.observer(({id:e})=>{const t=Le.useModals(),r=ye(),i=F();if(e==="")return null;const s=i.views.findByID(e);if(!s)return p(a.Text,{size:14,children:["View by ID[",e,"] is not found"]});const o=()=>{r.editor.setPath(["_VIEWS_",""])},u=()=>{t.openConfirmModal({title:"Delete this view?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.views.removeByID(e),o()},zIndex:320})};return p(a.Stack,{sx:{maxWidth:"600px",height:"100%"},spacing:"sm",children:[n(a.Group,{position:"right",pt:10,children:n(a.Button,{size:"xs",color:"red",leftIcon:n(k.Trash,{size:16}),onClick:u,children:"Delete this view"})}),n(a.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:n(X0,{view:s})})]})});function K0(e){return e.length===1&&e[0]==="_GLOBAL_VARS_"}function J0(e){return e.length===1&&e[0]==="_MOCK_CONTEXT_"}function H0(e){return e.length===2&&e[0]==="_FILTERS_"}function eC(e){return e.length===2&&e[0]==="_SQL_SNIPPETS_"}function tC(e){return e.length===2&&e[0]==="_QUERIES_"}function nC(e){return e.length===2&&e[0]==="_VIEWS_"}function rC(e){return e.length===4&&e[0]==="_VIEWS_"&&e[2]==="_PANELS_"}const iC=T.observer(()=>n(a.Stack,{sx:{height:"100%"},p:"sm",children:n(Ns,{})})),aC=T.observer(()=>{const e=ye().editor,t=e.path;return K0(t)?n(iC,{}):J0(t)?n(Ix,{}):H0(t)?n(a.Box,{p:"xs",pl:20,children:n(Mx,{id:t[1]})}):eC(t)?n(N0,{id:t[1]}):tC(t)?n(O0,{id:t[1]}):nC(t)?n(a.Box,{p:"xs",pl:20,children:n(Z0,{id:t[1]})}):rC(t)?n(a0,{viewID:t[1],panelID:t[3]}):n(a.Box,{children:e.path})}),sC=T.observer(()=>n(aC,{})),oC=T.observer(()=>{const e=F(),t=()=>{const r=new Date().getTime().toString(),i={id:r,key:r,label:r,order:e.filters.current.length+1,type:ar.TextInput,config:ns(),visibleInViewsIDs:["Main"],auto_submit:!1};e.filters.append(i)};return n(a.Button,{variant:"subtle",leftIcon:n(V.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Filter"})}),lC=T.observer(({parentID:e})=>{const t=F();if(!e)return null;const r=t.views.findByID(e);return r?n(a.Button,{variant:"subtle",leftIcon:n(V.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:()=>t.addANewPanel(r.id),sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Panel"}):null}),uC=T.observer(()=>{const e=F(),t=()=>{const r=new Date().getTime().toString(),i={id:r,name:r,type:ce.Postgresql,key:"",sql:""};e.queries.append(i)};return n(a.Button,{variant:"subtle",leftIcon:n(V.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Query"})}),dC=T.observer(()=>{const e=F(),t=()=>{const i={key:new Date().getTime().toString(),value:""};e.sqlSnippets.append(i)};return n(a.Button,{variant:"subtle",leftIcon:n(V.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a SQL Snippet"})}),cC=T.observer(()=>{const e=F();return n(a.Button,{variant:"subtle",leftIcon:n(V.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:e.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a View"})}),pC=T.observer(({action_type:e,parentID:t})=>(F(),e==="_Add_A_Filter_"?n(oC,{}):e==="_Add_A_SQL_SNIPPET_"?n(dC,{}):e==="_Add_A_QUERY_"?n(uC,{}):e==="_Add_A_VIEW_"?n(cC,{}):e==="_Add_A_PANEL_"?n(lC,{parentID:t}):null)),Fs=T.observer(({option:e})=>{var c;const t=ye().editor,r=t.isOptionActive,i=r(t.path,e),s=t.isOptionOpened,o=t.navigate,u=s(e),[l,d]=b.useState(u);return b.useEffect(()=>{d(u)},[u]),n(a.NavLink,{active:i,defaultOpened:u,opened:l,onChange:d,label:e.label,onClick:()=>o(e),icon:e.Icon?n(e.Icon,{size:18}):null,children:(c=e.children)==null?void 0:c.map(f=>f._type==="ACTION"?n(pC,{action_type:f._action_type,parentID:f.parentID},`_ADD_${f.value}_`):n(Fs,{option:f},f.value))},e.label)}),hC=T.observer(()=>{const e=ye();return n(a.Box,{sx:{position:"relative"},children:e.editor.navOptions.map(t=>n(Fs,{option:t},t.value))})}),fC=T.observer(()=>{const e=ye();return p(a.Navbar,{p:0,width:{base:200,xs:200,sm:220,md:240,lg:280,xl:300},sx:{height:"100vh - 60px - 60px"},children:[n(a.Navbar.Section,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:n(a.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Settings"})}),n(a.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:n(hC,{})}),n(a.Navbar.Section,{children:n(a.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:n(a.Button,{size:"xs",color:"red",leftIcon:n(V.IconX,{size:18}),onClick:()=>e.editor.close(),children:"Close"})})})]})}),gC={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1,nav:{top:0,height:"100vh"}},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:0,height:"100vh"}},mC=T.observer(()=>{const e=ye().editor;return n(a.Modal,{onClose:()=>e.setSettingsOpen(!1),closeOnEscape:!1,closeOnClickOutside:!1,opened:e.settings_open,fullScreen:!0,title:null,transitionDuration:0,withCloseButton:!1,withinPortal:!0,zIndex:300,styles:{modal:{padding:"0 !important"}},children:n(a.AppShell,{padding:0,navbar:n(fC,{}),styles:gC,children:n(sC,{})})})}),bC=e=>e.replace(/([^:])(\/\/+)/g,"$1/");function yC(e){b.useEffect(()=>{if(_e.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const r=bC(e);_e.loader.config({paths:{vs:r}}),_e.loader.init().then(i=>console.log("monaco instance:",i))},[])}const Ws={grid:{axis:"#97999D",scope:"rgba(47,140,192,0.1)",boundary:"#789AB4",reference:"#CFCFD8"},graphics:{compared:{blueDark:"#3E7CAB",blue:"#6398C7",blueLight:"#7CB0DF",blue10:"#6398C71a",redDark:"#AF5F6B",red:"#CD7C88",redLight:"#E794A0",red10:"#CD7C881a"},gradient:{distributed:"linear-gradient(90deg, #1babe6 0%, #2fc8c8 28.63%, #98d44b 48.86%, #ffd057 67.53%, #f5ae53 80.6%, #e76441 91.18%, #b90000 100%)",protrude:"linear-gradient(180deg, #ec73734d 0%, #ec737300 100%)"},level:{lv0:"#6398C7",lv1:"#61B5BF",lv2:"#54D4BB",lv3:"#F5D277",lv4:"#E8BB7F",lv5:"#DB9E84",lv6:"#CB8089"},depth:{dp0:"#FFF7F8",dp1:"#FFE1E1",dp2:"#FDBCBC",dp3:"#F39494",dp4:"#FA4242",dp5:"#E21212"},multiple:{c1:"#66B4DB",c2:"#E46464",c3:"#EEBA00",c4:"#33A678",c5:"#9D88CB",c6:"#939943",c7:"#E49792",c8:"#09A2B8",c9:"#AF5F6B",c10:"#6CA157",c11:"#3E7CAB",c12:"#6398C7",c13:"#E692BA",c14:"#97B566",c15:"#8CACE2",c16:"#CA79AC",c17:"#6DBC80",c18:"#B08F4B",c19:"#39BFA2",c20:"#826BAF"}}};function vC(){le.registerTheme("merico-light",{color:Object.values(Ws.graphics.multiple),visualMap:{color:Object.values(Ws.graphics.depth).reverse()}})}function js(){vC()}js();const xC={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:60+30,height:"100vh"}},CC=({context:e,dashboard:t,content:r,update:i,className:s="dashboard",config:o,onChange:u,headerSlot:l,headerMenuItems:d},c)=>{yC(o.monacoPath),Ua(o);const{data:f=[]}=Z.useRequest(dr),[g,h]=b.useState(!1),m=b.useMemo(()=>hr(t,r,f,e),[t,r]);b.useImperativeHandle(c,()=>m,[m]),Mi(m.content,!0),b.useEffect(()=>{m.context.replace(e)},[e]),b.useEffect(()=>{m.datasources.replace(f)},[f]),b.useEffect(()=>ae.reaction(()=>ae.toJS(m.json),I=>{u==null||u(I)}),[m]);const w=async()=>{await i(m.json,m.content.json)},C=Z.useCreation(rr,[]),S=fr(C);return n(Le.ModalsProvider,{children:n(bn,{value:m,children:n(yn,{value:m.content,children:n(Ze.Provider,{value:{layoutFrozen:g,freezeLayout:h,inEditMode:!0},children:n(Ge.Provider,{value:C,children:p(Gt,{configure:S,children:[n(a.AppShell,{padding:0,header:n(Gv,{saveDashboardChanges:w,headerSlot:l,headerMenuItems:d}),navbar:n(hx,{}),styles:xC,children:n(a.Box,{className:`${s} dashboard-root`,sx:{position:"relative"},children:m.content.views.visibleViews.map(I=>n(Qa,{view:I},I.id))})}),n(mC,{})]})})})})})})},wC=T.observer(b.forwardRef(CC)),y1="";js();const _C=T.observer(({context:e,dashboard:t,content:r,className:i="dashboard",config:s,fullScreenPanelID:o,setFullScreenPanelID:u})=>{Ua(s);const{data:l=[]}=Z.useRequest(dr),d=b.useMemo(()=>hr(t,r,l,e),[t,r]);Mi(d.content,!1),b.useEffect(()=>{d.context.replace(e)},[e]),b.useEffect(()=>{d.datasources.replace(l)},[l]);const c=Z.useCreation(rr,[]),f=fr(c);return n(Le.ModalsProvider,{children:n(bn,{value:d,children:n(yn,{value:d.content,children:n(xn.Provider,{value:{fullScreenPanelID:o,setFullScreenPanelID:u},children:n(Ze.Provider,{value:{layoutFrozen:!0,freezeLayout:v.noop,inEditMode:!1},children:n(a.Box,{className:`${i} dashboard-root`,children:n(Ge.Provider,{value:c,children:n(Gt,{configure:f,children:d.content.views.visibleViews.map(g=>n(nn,{view:g},g.id))})})})})})})})})});var wr={},SC={get exports(){return wr},set exports(e){wr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){var o=i.prototype,u=o.format;s.en.ordinal=function(l){var d=["th","st","nd","rd"],c=l%100;return"["+l+(d[(c-20)%10]||d[c]||d[0])+"]"},o.format=function(l){var d=this,c=this.$locale();if(!this.isValid())return u.bind(this)(l);var f=this.$utils(),g=(l||"YYYY-MM-DDTHH:mm:ssZ").replace(/\[([^\]]+)]|Q|wo|ww|w|WW|W|zzz|z|gggg|GGGG|Do|X|x|k{1,2}|S/g,function(h){switch(h){case"Q":return Math.ceil((d.$M+1)/3);case"Do":return c.ordinal(d.$D);case"gggg":return d.weekYear();case"GGGG":return d.isoWeekYear();case"wo":return c.ordinal(d.week(),"W");case"w":case"ww":return f.s(d.week(),h==="w"?1:2,"0");case"W":case"WW":return f.s(d.isoWeek(),h==="W"?1:2,"0");case"k":case"kk":return f.s(String(d.$H===0?24:d.$H),h==="k"?1:2,"0");case"X":return Math.floor(d.$d.getTime()/1e3);case"x":return d.$d.getTime();case"z":return"["+d.offsetName()+"]";case"zzz":return"["+d.offsetName("long")+"]";default:return h}});return u.bind(this)(g)}}})})(SC);const TC=wr;var _r={},kC={get exports(){return _r},set exports(e){_r=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){var o=i.prototype,u=function(d){var c=d.date,f=d.utc;return Array.isArray(c)?f?c.length?new Date(Date.UTC.apply(null,c)):new Date:c.length===1?s(String(c[0])).toDate():new(Function.prototype.bind.apply(Date,[null].concat(c))):c},l=o.parse;o.parse=function(d){d.date=u.bind(this)(d),l.bind(this)(d)}}})})(kC);const DC=_r;var Sr={},MC={get exports(){return Sr},set exports(e){Sr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){var s=i.prototype;s.$g=function(h,m,w){return this.$utils().u(h)?this[m]:this.$set(w,h)},s.set=function(h,m){return this.$set(h,m)};var o=s.startOf;s.startOf=function(h,m){return this.$d=o.bind(this)(h,m).toDate(),this.init(),this};var u=s.add;s.add=function(h,m){return this.$d=u.bind(this)(h,m).toDate(),this.init(),this};var l=s.locale;s.locale=function(h,m){return h?(this.$L=l.bind(this)(h,m).$L,this):this.$L};var d=s.daysInMonth;s.daysInMonth=function(){return d.bind(this.clone())()};var c=s.isSame;s.isSame=function(h,m){return c.bind(this.clone())(h,m)};var f=s.isBefore;s.isBefore=function(h,m){return f.bind(this.clone())(h,m)};var g=s.isAfter;s.isAfter=function(h,m){return g.bind(this.clone())(h,m)}}})})(MC);const IC=Sr;var Tr={},AC={get exports(){return Tr},set exports(e){Tr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){var s=i.prototype,o=s.format;s.format=function(u){var l=this,d=(u||"YYYY-MM-DDTHH:mm:ssZ").replace(/(\[[^\]]+])|BBBB|BB/g,function(c,f){var g,h=String(l.$y+543),m=c==="BB"?[h.slice(-2),2]:[h,4];return f||(g=l.$utils()).s.apply(g,m.concat(["0"]))});return o.bind(this)(d)}}})})(AC);const $C=Tr;var kr={},zC={get exports(){return kr},set exports(e){kr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){var o="h:mm A",u={lastDay:"[Yesterday at] "+o,sameDay:"[Today at] "+o,nextDay:"[Tomorrow at] "+o,nextWeek:"dddd [at] "+o,lastWeek:"[Last] dddd [at] "+o,sameElse:"MM/DD/YYYY"};i.prototype.calendar=function(l,d){var c=d||this.$locale().calendar||u,f=s(l||void 0).startOf("d"),g=this.diff(f,"d",!0),h="sameElse",m=g<-6?h:g<-1?"lastWeek":g<0?"lastDay":g<1?"sameDay":g<2?"nextDay":g<7?"nextWeek":h,w=c[m]||u[m];return typeof w=="function"?w.call(this,s()):this.format(w)}}})})(zC);const EC=kr;var Dr={},LC={get exports(){return Dr},set exports(e){Dr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){var r={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"},i=/(\[[^[]*\])|([-_:/.,()\s]+)|(A|a|YYYY|YY?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g,s=/\d\d/,o=/\d\d?/,u=/\d*[^-_:/,()\s\d]+/,l={},d=function(C){return(C=+C)+(C>68?1900:2e3)},c=function(C){return function(S){this[C]=+S}},f=[/[+-]\d\d:?(\d\d)?|Z/,function(C){(this.zone||(this.zone={})).offset=function(S){if(!S||S==="Z")return 0;var I=S.match(/([+-]|\d\d)/g),$=60*I[1]+(+I[2]||0);return $===0?0:I[0]==="+"?-$:$}(C)}],g=function(C){var S=l[C];return S&&(S.indexOf?S:S.s.concat(S.f))},h=function(C,S){var I,$=l.meridiem;if($){for(var G=1;G<=24;G+=1)if(C.indexOf($(G,0,S))>-1){I=G>12;break}}else I=C===(S?"pm":"PM");return I},m={A:[u,function(C){this.afternoon=h(C,!1)}],a:[u,function(C){this.afternoon=h(C,!0)}],S:[/\d/,function(C){this.milliseconds=100*+C}],SS:[s,function(C){this.milliseconds=10*+C}],SSS:[/\d{3}/,function(C){this.milliseconds=+C}],s:[o,c("seconds")],ss:[o,c("seconds")],m:[o,c("minutes")],mm:[o,c("minutes")],H:[o,c("hours")],h:[o,c("hours")],HH:[o,c("hours")],hh:[o,c("hours")],D:[o,c("day")],DD:[s,c("day")],Do:[u,function(C){var S=l.ordinal,I=C.match(/\d+/);if(this.day=I[0],S)for(var $=1;$<=31;$+=1)S($).replace(/\[|\]/g,"")===C&&(this.day=$)}],M:[o,c("month")],MM:[s,c("month")],MMM:[u,function(C){var S=g("months"),I=(g("monthsShort")||S.map(function($){return $.slice(0,3)})).indexOf(C)+1;if(I<1)throw new Error;this.month=I%12||I}],MMMM:[u,function(C){var S=g("months").indexOf(C)+1;if(S<1)throw new Error;this.month=S%12||S}],Y:[/[+-]?\d+/,c("year")],YY:[s,function(C){this.year=d(C)}],YYYY:[/\d{4}/,c("year")],Z:f,ZZ:f};function w(C){var S,I;S=C,I=l&&l.formats;for(var $=(C=S.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(U,Q,te){var re=te&&te.toUpperCase();return Q||I[te]||r[te]||I[re].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(oe,ne,pe){return ne||pe.slice(1)})})).match(i),G=$.length,q=0;q<G;q+=1){var L=$[q],z=m[L],A=z&&z[0],N=z&&z[1];$[q]=N?{regex:A,parser:N}:L.replace(/^\[|\]$/g,"")}return function(U){for(var Q={},te=0,re=0;te<G;te+=1){var oe=$[te];if(typeof oe=="string")re+=oe.length;else{var ne=oe.regex,pe=oe.parser,fe=U.slice(re),Se=ne.exec(fe)[0];pe.call(Q,Se),U=U.replace(Se,"")}}return function(Fe){var Ae=Fe.afternoon;if(Ae!==void 0){var Re=Fe.hours;Ae?Re<12&&(Fe.hours+=12):Re===12&&(Fe.hours=0),delete Fe.afternoon}}(Q),Q}}return function(C,S,I){I.p.customParseFormat=!0,C&&C.parseTwoDigitYear&&(d=C.parseTwoDigitYear);var $=S.prototype,G=$.parse;$.parse=function(q){var L=q.date,z=q.utc,A=q.args;this.$u=z;var N=A[1];if(typeof N=="string"){var U=A[2]===!0,Q=A[3]===!0,te=U||Q,re=A[2];Q&&(re=A[2]),l=this.$locale(),!U&&re&&(l=I.Ls[re]),this.$d=function(fe,Se,Fe){try{if(["x","X"].indexOf(Se)>-1)return new Date((Se==="X"?1e3:1)*fe);var Ae=w(Se)(fe),Re=Ae.year,it=Ae.month,dn=Ae.day,cn=Ae.hours,ni=Ae.minutes,ri=Ae.seconds,$t=Ae.milliseconds,ft=Ae.zone,et=new Date,at=dn||(Re||it?1:et.getDate()),tt=Re||et.getFullYear(),gt=0;Re&&!it||(gt=it>0?it-1:et.getMonth());var mt=cn||0,zt=ni||0,Et=ri||0,nt=$t||0;return ft?new Date(Date.UTC(tt,gt,at,mt,zt,Et,nt+60*ft.offset*1e3)):Fe?new Date(Date.UTC(tt,gt,at,mt,zt,Et,nt)):new Date(tt,gt,at,mt,zt,Et,nt)}catch{return new Date("")}}(L,N,z),this.init(),re&&re!==!0&&(this.$L=this.locale(re).$L),te&&L!=this.format(N)&&(this.$d=new Date("")),l={}}else if(N instanceof Array)for(var oe=N.length,ne=1;ne<=oe;ne+=1){A[1]=N[ne-1];var pe=I.apply(this,A);if(pe.isValid()){this.$d=pe.$d,this.$L=pe.$L,this.init();break}ne===oe&&(this.$d=new Date(""))}else G.call(this,q)}}})})(LC);const PC=Dr;var Mr={},OC={get exports(){return Mr},set exports(e){Mr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){i.prototype.dayOfYear=function(o){var u=Math.round((s(this).startOf("day")-s(this).startOf("year"))/864e5)+1;return o==null?u:this.add(o-u,"day")}}})})(OC);const VC=Mr;var Ir={},BC={get exports(){return Ir},set exports(e){Ir=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){var r,i,s=1e3,o=6e4,u=36e5,l=864e5,d=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,c=31536e6,f=2592e6,g=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/,h={years:c,months:f,days:l,hours:u,minutes:o,seconds:s,milliseconds:1,weeks:6048e5},m=function(L){return L instanceof q},w=function(L,z,A){return new q(L,A,z.$l)},C=function(L){return i.p(L)+"s"},S=function(L){return L<0},I=function(L){return S(L)?Math.ceil(L):Math.floor(L)},$=function(L){return Math.abs(L)},G=function(L,z){return L?S(L)?{negative:!0,format:""+$(L)+z}:{negative:!1,format:""+L+z}:{negative:!1,format:""}},q=function(){function L(A,N,U){var Q=this;if(this.$d={},this.$l=U,A===void 0&&(this.$ms=0,this.parseFromMilliseconds()),N)return w(A*h[C(N)],this);if(typeof A=="number")return this.$ms=A,this.parseFromMilliseconds(),this;if(typeof A=="object")return Object.keys(A).forEach(function(oe){Q.$d[C(oe)]=A[oe]}),this.calMilliseconds(),this;if(typeof A=="string"){var te=A.match(g);if(te){var re=te.slice(2).map(function(oe){return oe!=null?Number(oe):0});return this.$d.years=re[0],this.$d.months=re[1],this.$d.weeks=re[2],this.$d.days=re[3],this.$d.hours=re[4],this.$d.minutes=re[5],this.$d.seconds=re[6],this.calMilliseconds(),this}}return this}var z=L.prototype;return z.calMilliseconds=function(){var A=this;this.$ms=Object.keys(this.$d).reduce(function(N,U){return N+(A.$d[U]||0)*h[U]},0)},z.parseFromMilliseconds=function(){var A=this.$ms;this.$d.years=I(A/c),A%=c,this.$d.months=I(A/f),A%=f,this.$d.days=I(A/l),A%=l,this.$d.hours=I(A/u),A%=u,this.$d.minutes=I(A/o),A%=o,this.$d.seconds=I(A/s),A%=s,this.$d.milliseconds=A},z.toISOString=function(){var A=G(this.$d.years,"Y"),N=G(this.$d.months,"M"),U=+this.$d.days||0;this.$d.weeks&&(U+=7*this.$d.weeks);var Q=G(U,"D"),te=G(this.$d.hours,"H"),re=G(this.$d.minutes,"M"),oe=this.$d.seconds||0;this.$d.milliseconds&&(oe+=this.$d.milliseconds/1e3);var ne=G(oe,"S"),pe=A.negative||N.negative||Q.negative||te.negative||re.negative||ne.negative,fe=te.format||re.format||ne.format?"T":"",Se=(pe?"-":"")+"P"+A.format+N.format+Q.format+fe+te.format+re.format+ne.format;return Se==="P"||Se==="-P"?"P0D":Se},z.toJSON=function(){return this.toISOString()},z.format=function(A){var N=A||"YYYY-MM-DDTHH:mm:ss",U={Y:this.$d.years,YY:i.s(this.$d.years,2,"0"),YYYY:i.s(this.$d.years,4,"0"),M:this.$d.months,MM:i.s(this.$d.months,2,"0"),D:this.$d.days,DD:i.s(this.$d.days,2,"0"),H:this.$d.hours,HH:i.s(this.$d.hours,2,"0"),m:this.$d.minutes,mm:i.s(this.$d.minutes,2,"0"),s:this.$d.seconds,ss:i.s(this.$d.seconds,2,"0"),SSS:i.s(this.$d.milliseconds,3,"0")};return N.replace(d,function(Q,te){return te||String(U[Q])})},z.as=function(A){return this.$ms/h[C(A)]},z.get=function(A){var N=this.$ms,U=C(A);return U==="milliseconds"?N%=1e3:N=U==="weeks"?I(N/h[U]):this.$d[U],N===0?0:N},z.add=function(A,N,U){var Q;return Q=N?A*h[C(N)]:m(A)?A.$ms:w(A,this).$ms,w(this.$ms+Q*(U?-1:1),this)},z.subtract=function(A,N){return this.add(A,N,!0)},z.locale=function(A){var N=this.clone();return N.$l=A,N},z.clone=function(){return w(this.$ms,this)},z.humanize=function(A){return r().add(this.$ms,"ms").locale(this.$l).fromNow(!A)},z.milliseconds=function(){return this.get("milliseconds")},z.asMilliseconds=function(){return this.as("milliseconds")},z.seconds=function(){return this.get("seconds")},z.asSeconds=function(){return this.as("seconds")},z.minutes=function(){return this.get("minutes")},z.asMinutes=function(){return this.as("minutes")},z.hours=function(){return this.get("hours")},z.asHours=function(){return this.as("hours")},z.days=function(){return this.get("days")},z.asDays=function(){return this.as("days")},z.weeks=function(){return this.get("weeks")},z.asWeeks=function(){return this.as("weeks")},z.months=function(){return this.get("months")},z.asMonths=function(){return this.as("months")},z.years=function(){return this.get("years")},z.asYears=function(){return this.as("years")},L}();return function(L,z,A){r=A,i=A().$utils(),A.duration=function(Q,te){var re=A.locale();return w(Q,{$l:re},te)},A.isDuration=m;var N=z.prototype.add,U=z.prototype.subtract;z.prototype.add=function(Q,te){return m(Q)&&(Q=Q.asMilliseconds()),N.bind(this)(Q,te)},z.prototype.subtract=function(Q,te){return m(Q)&&(Q=Q.asMilliseconds()),U.bind(this)(Q,te)}}})})(BC);const NC=Ir;var Ar={},GC={get exports(){return Ar},set exports(e){Ar=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){i.prototype.isBetween=function(o,u,l,d){var c=s(o),f=s(u),g=(d=d||"()")[0]==="(",h=d[1]===")";return(g?this.isAfter(c,l):!this.isBefore(c,l))&&(h?this.isBefore(f,l):!this.isAfter(f,l))||(g?this.isBefore(c,l):!this.isAfter(c,l))&&(h?this.isAfter(f,l):!this.isBefore(f,l))}}})})(GC);const qC=Ar;var $r={},FC={get exports(){return $r},set exports(e){$r=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){i.prototype.isLeapYear=function(){return this.$y%4==0&&this.$y%100!=0||this.$y%400==0}}})})(FC);const WC=$r;var zr={},jC={get exports(){return zr},set exports(e){zr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){s.isMoment=function(o){return s.isDayjs(o)}}})})(jC);const YC=zr;var Er={},RC={get exports(){return Er},set exports(e){Er=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){var r="day";return function(i,s,o){var u=function(c){return c.add(4-c.isoWeekday(),r)},l=s.prototype;l.isoWeekYear=function(){return u(this).year()},l.isoWeek=function(c){if(!this.$utils().u(c))return this.add(7*(c-this.isoWeek()),r);var f,g,h,m,w=u(this),C=(f=this.isoWeekYear(),g=this.$u,h=(g?o.utc:o)().year(f).startOf("year"),m=4-h.isoWeekday(),h.isoWeekday()>4&&(m+=7),h.add(m,r));return w.diff(C,"week")+1},l.isoWeekday=function(c){return this.$utils().u(c)?this.day()||7:this.day(this.day()%7?c:c-7)};var d=l.startOf;l.startOf=function(c,f){var g=this.$utils(),h=!!g.u(f)||f;return g.p(c)==="isoweek"?h?this.date(this.date()-(this.isoWeekday()-1)).startOf("day"):this.date(this.date()-1-(this.isoWeekday()-1)+7).endOf("day"):d.bind(this)(c,f)}}})})(RC);const QC=Er;var Lr={},UC={get exports(){return Lr},set exports(e){Lr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){i.prototype.isoWeeksInYear=function(){var s=this.isLeapYear(),o=this.endOf("y").day();return o===4||s&&o===5?53:52}}})})(UC);const XC=Lr;var Pr={},ZC={get exports(){return Pr},set exports(e){Pr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){i.prototype.isSameOrAfter=function(s,o){return this.isSame(s,o)||this.isAfter(s,o)}}})})(ZC);const KC=Pr;var Or={},JC={get exports(){return Or},set exports(e){Or=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){i.prototype.isSameOrBefore=function(s,o){return this.isSame(s,o)||this.isBefore(s,o)}}})})(JC);const HC=Or;var Vr={},ew={get exports(){return Vr},set exports(e){Vr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){i.prototype.isToday=function(){var o="YYYY-MM-DD",u=s();return this.format(o)===u.format(o)}}})})(ew);const tw=Vr;var Br={},nw={get exports(){return Br},set exports(e){Br=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){i.prototype.isTomorrow=function(){var o="YYYY-MM-DD",u=s().add(1,"day");return this.format(o)===u.format(o)}}})})(nw);const rw=Br;var Nr={},iw={get exports(){return Nr},set exports(e){Nr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){i.prototype.isYesterday=function(){var o="YYYY-MM-DD",u=s().subtract(1,"day");return this.format(o)===u.format(o)}}})})(iw);const aw=Nr;var Gr={},sw={get exports(){return Gr},set exports(e){Gr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){var o=i.prototype,u=function(g){return g&&(g.indexOf?g:g.s)},l=function(g,h,m,w,C){var S=g.name?g:g.$locale(),I=u(S[h]),$=u(S[m]),G=I||$.map(function(L){return L.slice(0,w)});if(!C)return G;var q=S.weekStart;return G.map(function(L,z){return G[(z+(q||0))%7]})},d=function(){return s.Ls[s.locale()]},c=function(g,h){return g.formats[h]||function(m){return m.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(w,C,S){return C||S.slice(1)})}(g.formats[h.toUpperCase()])},f=function(){var g=this;return{months:function(h){return h?h.format("MMMM"):l(g,"months")},monthsShort:function(h){return h?h.format("MMM"):l(g,"monthsShort","months",3)},firstDayOfWeek:function(){return g.$locale().weekStart||0},weekdays:function(h){return h?h.format("dddd"):l(g,"weekdays")},weekdaysMin:function(h){return h?h.format("dd"):l(g,"weekdaysMin","weekdays",2)},weekdaysShort:function(h){return h?h.format("ddd"):l(g,"weekdaysShort","weekdays",3)},longDateFormat:function(h){return c(g.$locale(),h)},meridiem:this.$locale().meridiem,ordinal:this.$locale().ordinal}};o.localeData=function(){return f.bind(this)()},s.localeData=function(){var g=d();return{firstDayOfWeek:function(){return g.weekStart||0},weekdays:function(){return s.weekdays()},weekdaysShort:function(){return s.weekdaysShort()},weekdaysMin:function(){return s.weekdaysMin()},months:function(){return s.months()},monthsShort:function(){return s.monthsShort()},longDateFormat:function(h){return c(g,h)},meridiem:g.meridiem,ordinal:g.ordinal}},s.months=function(){return l(d(),"months")},s.monthsShort=function(){return l(d(),"monthsShort","months",3)},s.weekdays=function(g){return l(d(),"weekdays",null,null,g)},s.weekdaysShort=function(g){return l(d(),"weekdaysShort","weekdays",3,g)},s.weekdaysMin=function(g){return l(d(),"weekdaysMin","weekdays",2,g)}}})})(sw);const ow=Gr;var qr={},lw={get exports(){return qr},set exports(e){qr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){var r={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"};return function(i,s,o){var u=s.prototype,l=u.format;o.en.formats=r,u.format=function(d){d===void 0&&(d="YYYY-MM-DDTHH:mm:ssZ");var c=this.$locale().formats,f=function(g,h){return g.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(m,w,C){var S=C&&C.toUpperCase();return w||h[C]||r[C]||h[S].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(I,$,G){return $||G.slice(1)})})}(d,c===void 0?{}:c);return l.call(this,f)}}})})(lw);const uw=qr;var Fr={},dw={get exports(){return Fr},set exports(e){Fr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){var o=function(u,l){if(!l||!l.length||!l[0]||l.length===1&&!l[0].length)return null;var d;l.length===1&&l[0].length>0&&(l=l[0]),d=l[0];for(var c=1;c<l.length;c+=1)l[c].isValid()&&!l[c][u](d)||(d=l[c]);return d};s.max=function(){var u=[].slice.call(arguments,0);return o("isAfter",u)},s.min=function(){var u=[].slice.call(arguments,0);return o("isBefore",u)}}})})(dw);const cw=Fr;var Wr={},pw={get exports(){return Wr},set exports(e){Wr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){var o=i.prototype,u=function(g){var h,m=g.date,w=g.utc,C={};if(!((h=m)instanceof Date)&&!(h instanceof Array)&&h instanceof Object){if(!Object.keys(m).length)return new Date;var S=w?s.utc():s();Object.keys(m).forEach(function(N){var U,Q;C[U=N,Q=o.$utils().p(U),Q==="date"?"day":Q]=m[N]});var I=C.day||(C.year||C.month>=0?1:S.date()),$=C.year||S.year(),G=C.month>=0?C.month:C.year||C.day?0:S.month(),q=C.hour||0,L=C.minute||0,z=C.second||0,A=C.millisecond||0;return w?new Date(Date.UTC($,G,I,q,L,z,A)):new Date($,G,I,q,L,z,A)}return m},l=o.parse;o.parse=function(g){g.date=u.bind(this)(g),l.bind(this)(g)};var d=o.set,c=o.add,f=function(g,h,m,w){if(w===void 0&&(w=1),h instanceof Object){var C=Object.keys(h),S=this;return C.forEach(function(I){S=g.bind(S)(h[I]*w,I)}),S}return g.bind(this)(h*w,m)};o.set=function(g,h){return h=h===void 0?g:h,f.bind(this)(function(m,w){return d.bind(this)(w,m)},h,g)},o.add=function(g,h){return f.bind(this)(c,g,h)},o.subtract=function(g,h){return f.bind(this)(c,g,h,-1)}}})})(pw);const hw=Wr;var jr={},fw={get exports(){return jr},set exports(e){jr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){var s=i.prototype;["milliseconds","seconds","minutes","hours","days","weeks","isoWeeks","months","quarters","years","dates"].forEach(function(o){s[o]=s[o.replace(/s$/,"")]})}})})(fw);const gw=jr;var Yr={},mw={get exports(){return Yr},set exports(e){Yr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){var s=i.prototype.parse;i.prototype.parse=function(l){if(typeof l.date=="string"){var d=this.$locale();l.date=d&&d.preparse?d.preparse(l.date):l.date}return s.bind(this)(l)};var o=i.prototype.format;i.prototype.format=function(){for(var l=arguments.length,d=new Array(l),c=0;c<l;c++)d[c]=arguments[c];var f=o.call.apply(o,[this].concat(d)),g=this.$locale();return g&&g.postformat?g.postformat(f):f};var u=i.prototype.fromToBase;u&&(i.prototype.fromToBase=function(l,d,c,f){var g=this.$locale()||c.$locale();return u.call(this,l,d,c,f,g&&g.postformat)})}})})(mw);const bw=Yr;var Rr={},yw={get exports(){return Rr},set exports(e){Rr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){var r="month",i="quarter";return function(s,o){var u=o.prototype;u.quarter=function(c){return this.$utils().u(c)?Math.ceil((this.month()+1)/3):this.month(this.month()%3+3*(c-1))};var l=u.add;u.add=function(c,f){return c=Number(c),this.$utils().p(f)===i?this.add(3*c,r):l.bind(this)(c,f)};var d=u.startOf;u.startOf=function(c,f){var g=this.$utils(),h=!!g.u(f)||f;if(g.p(c)===i){var m=this.quarter()-1;return h?this.month(3*m).startOf(r).startOf("day"):this.month(3*m+2).endOf(r).endOf("day")}return d.bind(this)(c,f)}}})})(yw);const vw=Rr;var Qr={},xw={get exports(){return Qr},set exports(e){Qr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){r=r||{};var o=i.prototype,u={future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"};function l(c,f,g,h){return o.fromToBase(c,f,g,h)}s.en.relativeTime=u,o.fromToBase=function(c,f,g,h,m){for(var w,C,S,I=g.$locale().relativeTime||u,$=r.thresholds||[{l:"s",r:44,d:"second"},{l:"m",r:89},{l:"mm",r:44,d:"minute"},{l:"h",r:89},{l:"hh",r:21,d:"hour"},{l:"d",r:35},{l:"dd",r:25,d:"day"},{l:"M",r:45},{l:"MM",r:10,d:"month"},{l:"y",r:17},{l:"yy",d:"year"}],G=$.length,q=0;q<G;q+=1){var L=$[q];L.d&&(w=h?s(c).diff(g,L.d,!0):g.diff(c,L.d,!0));var z=(r.rounding||Math.round)(Math.abs(w));if(S=w>0,z<=L.r||!L.r){z<=1&&q>0&&(L=$[q-1]);var A=I[L.l];m&&(z=m(""+z)),C=typeof A=="string"?A.replace("%d",z):A(z,f,L.l,S);break}}if(f)return C;var N=S?I.future:I.past;return typeof N=="function"?N(C):N.replace("%s",C)},o.to=function(c,f){return l(c,f,this,!0)},o.from=function(c,f){return l(c,f,this)};var d=function(c){return c.$u?s.utc():s()};o.toNow=function(c){return this.to(d(this),c)},o.fromNow=function(c){return this.from(d(this),c)}}})})(xw);const Cw=Qr;var Ur={},ww={get exports(){return Ur},set exports(e){Ur=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){var r={year:0,month:1,day:2,hour:3,minute:4,second:5},i={};return function(s,o,u){var l,d=function(h,m,w){w===void 0&&(w={});var C=new Date(h),S=function(I,$){$===void 0&&($={});var G=$.timeZoneName||"short",q=I+"|"+G,L=i[q];return L||(L=new Intl.DateTimeFormat("en-US",{hour12:!1,timeZone:I,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:G}),i[q]=L),L}(m,w);return S.formatToParts(C)},c=function(h,m){for(var w=d(h,m),C=[],S=0;S<w.length;S+=1){var I=w[S],$=I.type,G=I.value,q=r[$];q>=0&&(C[q]=parseInt(G,10))}var L=C[3],z=L===24?0:L,A=C[0]+"-"+C[1]+"-"+C[2]+" "+z+":"+C[4]+":"+C[5]+":000",N=+h;return(u.utc(A).valueOf()-(N-=N%1e3))/6e4},f=o.prototype;f.tz=function(h,m){h===void 0&&(h=l);var w=this.utcOffset(),C=this.toDate(),S=C.toLocaleString("en-US",{timeZone:h}),I=Math.round((C-new Date(S))/1e3/60),$=u(S).$set("millisecond",this.$ms).utcOffset(15*-Math.round(C.getTimezoneOffset()/15)-I,!0);if(m){var G=$.utcOffset();$=$.add(w-G,"minute")}return $.$x.$timezone=h,$},f.offsetName=function(h){var m=this.$x.$timezone||u.tz.guess(),w=d(this.valueOf(),m,{timeZoneName:h}).find(function(C){return C.type.toLowerCase()==="timezonename"});return w&&w.value};var g=f.startOf;f.startOf=function(h,m){if(!this.$x||!this.$x.$timezone)return g.call(this,h,m);var w=u(this.format("YYYY-MM-DD HH:mm:ss:SSS"));return g.call(w,h,m).tz(this.$x.$timezone,!0)},u.tz=function(h,m,w){var C=w&&m,S=w||m||l,I=c(+u(),S);if(typeof h!="string")return u(h).tz(S);var $=function(z,A,N){var U=z-60*A*1e3,Q=c(U,N);if(A===Q)return[U,A];var te=c(U-=60*(Q-A)*1e3,N);return Q===te?[U,Q]:[z-60*Math.min(Q,te)*1e3,Math.max(Q,te)]}(u.utc(h,C).valueOf(),I,S),G=$[0],q=$[1],L=u(G).utcOffset(q);return L.$x.$timezone=S,L},u.tz.guess=function(){return Intl.DateTimeFormat().resolvedOptions().timeZone},u.tz.setDefault=function(h){l=h}}})})(ww);const _w=Ur;var Xr={},Sw={get exports(){return Xr},set exports(e){Xr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){i.prototype.toArray=function(){return[this.$y,this.$M,this.$D,this.$H,this.$m,this.$s,this.$ms]}}})})(Sw);const Tw=Xr;var Zr={},kw={get exports(){return Zr},set exports(e){Zr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){i.prototype.toObject=function(){return{years:this.$y,months:this.$M,date:this.$D,hours:this.$H,minutes:this.$m,seconds:this.$s,milliseconds:this.$ms}}}})})(kw);const Dw=Zr;var Kr={},Mw={get exports(){return Kr},set exports(e){Kr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){s.updateLocale=function(o,u){var l=s.Ls[o];if(l)return(u?Object.keys(u):[]).forEach(function(d){l[d]=u[d]}),l}}})})(Mw);const Iw=Kr;var Jr={},Aw={get exports(){return Jr},set exports(e){Jr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){var r="minute",i=/[+-]\d\d(?::?\d\d)?/g,s=/([+-]|\d\d)/g;return function(o,u,l){var d=u.prototype;l.utc=function(C){var S={date:C,utc:!0,args:arguments};return new u(S)},d.utc=function(C){var S=l(this.toDate(),{locale:this.$L,utc:!0});return C?S.add(this.utcOffset(),r):S},d.local=function(){return l(this.toDate(),{locale:this.$L,utc:!1})};var c=d.parse;d.parse=function(C){C.utc&&(this.$u=!0),this.$utils().u(C.$offset)||(this.$offset=C.$offset),c.call(this,C)};var f=d.init;d.init=function(){if(this.$u){var C=this.$d;this.$y=C.getUTCFullYear(),this.$M=C.getUTCMonth(),this.$D=C.getUTCDate(),this.$W=C.getUTCDay(),this.$H=C.getUTCHours(),this.$m=C.getUTCMinutes(),this.$s=C.getUTCSeconds(),this.$ms=C.getUTCMilliseconds()}else f.call(this)};var g=d.utcOffset;d.utcOffset=function(C,S){var I=this.$utils().u;if(I(C))return this.$u?0:I(this.$offset)?g.call(this):this.$offset;if(typeof C=="string"&&(C=function(L){L===void 0&&(L="");var z=L.match(i);if(!z)return null;var A=(""+z[0]).match(s)||["-",0,0],N=A[0],U=60*+A[1]+ +A[2];return U===0?0:N==="+"?U:-U}(C),C===null))return this;var $=Math.abs(C)<=16?60*C:C,G=this;if(S)return G.$offset=$,G.$u=C===0,G;if(C!==0){var q=this.$u?this.toDate().getTimezoneOffset():-1*this.utcOffset();(G=this.local().add($+q,r)).$offset=$,G.$x.$localOffset=q}else G=this.utc();return G};var h=d.format;d.format=function(C){var S=C||(this.$u?"YYYY-MM-DDTHH:mm:ss[Z]":"");return h.call(this,S)},d.valueOf=function(){var C=this.$utils().u(this.$offset)?0:this.$offset+(this.$x.$localOffset||this.$d.getTimezoneOffset());return this.$d.valueOf()-6e4*C},d.isUTC=function(){return!!this.$u},d.toISOString=function(){return this.toDate().toISOString()},d.toString=function(){return this.toDate().toUTCString()};var m=d.toDate;d.toDate=function(C){return C==="s"&&this.$offset?l(this.format("YYYY-MM-DD HH:mm:ss:SSS")).toDate():m.call(this)};var w=d.diff;d.diff=function(C,S,I){if(C&&this.$u===C.$u)return w.call(this,C,S,I);var $=this.local(),G=l(C).local();return w.call($,G,S,I)}}})})(Aw);const $w=Jr;var Hr={},zw={get exports(){return Hr},set exports(e){Hr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){i.prototype.weekday=function(s){var o=this.$locale().weekStart||0,u=this.$W,l=(u<o?u+7:u)-o;return this.$utils().u(s)?l:this.subtract(l,"day").add(s,"day")}}})})(zw);const Ew=Hr;var ei={},Lw={get exports(){return ei},set exports(e){ei=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){var r="week",i="year";return function(s,o,u){var l=o.prototype;l.week=function(d){if(d===void 0&&(d=null),d!==null)return this.add(7*(d-this.week()),"day");var c=this.$locale().yearStart||1;if(this.month()===11&&this.date()>25){var f=u(this).startOf(i).add(1,i).date(c),g=u(this).endOf(r);if(f.isBefore(g))return 1}var h=u(this).startOf(i).date(c).startOf(r).subtract(1,"millisecond"),m=this.diff(h,r,!0);return m<0?u(this).startOf("week").week():Math.ceil(m)},l.weeks=function(d){return d===void 0&&(d=null),this.week(d)}}})})(Lw);const Pw=ei;var ti={},Ow={get exports(){return ti},set exports(e){ti=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){i.prototype.weekYear=function(){var s=this.month(),o=this.week(),u=this.year();return o===1&&s===11?u+1:s===0&&o>=52?u-1:u}}})})(Ow);const Vw=ti;j.extend(TC),j.extend(DC),j.extend(IC),j.extend($C),j.extend(EC),j.extend(PC),j.extend(VC),j.extend(NC),j.extend(qC),j.extend(WC),j.extend(YC),j.extend(KC),j.extend(HC),j.extend(tw),j.extend(rw),j.extend(aw),j.extend(QC),j.extend(XC),j.extend(ow),j.extend(uw),j.extend(cw),j.extend(hw),j.extend(gw),j.extend(bw),j.extend(vw),j.extend(Cw),j.extend(_w),j.extend(Tw),j.extend(Dw),j.extend(Iw),j.extend($w),j.extend(Pw),j.extend(Vw),j.extend(Ew),j.tz.setDefault("UTC");const Bw=()=>Promise.resolve().then(()=>Zo).then(({version:e})=>(console.log(`[@devtable/dashboard] version: ${e}`),e));D.ContentModel=It,D.ContentModelContextProvider=yn,D.ContextModel=gs,D.DashboardEditor=wC,D.DashboardFilterType=ar,D.DashboardMode=Ya,D.DashboardModel=Ts,D.DashboardViewEditor=Qa,D.DashboardViewRender=nn,D.EViewComponentType=K,D.FilterModel=or,D.FiltersModel=as,D.FullScreenPanelContext=xn,D.LayoutStateContext=Ze,D.ModelContextProvider=bn,D.Panel=tn,D.PanelContextProvider=vn,D.PanelModel=ms,D.PanelsModel=ys,D.QueriesModel=ps,D.QueryModel=cs,D.ReadOnlyDashboard=_C,D.SQLSnippetModel=hs,D.SQLSnippetsModel=fs,D.ViewComponentTypeBackground=Ra,D.ViewComponentTypeColor=wy,D.ViewComponentTypeName=Cy,D.ViewModel=ws,D.ViewsModel=_s,D.applyPartialDashboard=Lv,D.createContentModel=Ss,D.createDashboardModel=hr,D.createDashboardViewsModel=pr,D.getInitialFiltersPayload=ss,D.getNewPanel=bs,D.getVersion=Bw,D.initialDashboardContent=_y,D.useContentModelContext=F,D.useFullScreenPanelContext=Ei,D.useModelContext=ye,D.usePanelContext=Ce,D.useTopLevelServices=fr,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
470
+ `)},L0=T.observer(({queryModel:e})=>{const[t,r]=b.useState(e.sql);b.useEffect(()=>{r(o=>o!==e.sql?e.sql:o)},[e.sql]);const i=t!==e.sql,s=()=>{e.setSQL(t)};return e.typedAsSQL?p(a.Tabs,{defaultValue:"Edit",orientation:"vertical",sx:{flexGrow:1},styles:{tabLabel:{width:"100%",height:"28px",lineHeight:"28px"}},keepMounted:!1,children:[p(a.Tabs.List,{children:[n(a.Tabs.Tab,{value:"Edit",children:p(a.Group,{spacing:14,position:"apart",children:["Edit SQL",n(a.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!i,onClick:s,children:n(k.DeviceFloppy,{size:20})})]})}),n(a.Tabs.Tab,{value:"Preview",children:"Preview SQL"}),n(a.Tabs.Tab,{value:"pre_process",children:"Process Request"}),n(a.Tabs.Tab,{value:"post_process",children:"Process Result"}),n(xr,{}),e.datasource&&n(Bs,{dataSource:e.datasource})]}),n(a.Tabs.Panel,{value:"Edit",sx:{position:"relative"},p:"sm",children:n(Cr,{height:"100%",value:t,onChange:r})}),n(a.Tabs.Panel,{value:"Preview",p:0,pl:4,children:n(E0,{value:e.sql})}),n(a.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:n(ln,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:qs.pre})}),n(a.Tabs.Panel,{value:"post_process",p:"sm",children:n(ln,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:qs.post})})]}):null}),un={height:"calc(100% - 44px)",padding:0},P0=T.observer(({queryModel:e})=>{const t=F(),r=b.useMemo(()=>e.datasource?e.typedAsHTTP?"HTTP":"SQL":"Configurations",[e.datasource,e.typedAsHTTP]),i=t.findQueryUsage(e.id),s=i.length===0;return n(a.Stack,{sx:{flexGrow:1},my:0,p:0,children:p(a.Tabs,{defaultValue:r,orientation:"horizontal",keepMounted:!1,sx:{flexGrow:1},children:[p(a.Tabs.List,{grow:!0,children:[n(a.Tabs.Tab,{value:"Configurations",children:"Configurations"}),e.typedAsSQL&&n(a.Tabs.Tab,{value:"SQL",children:"Request"}),e.typedAsHTTP&&n(a.Tabs.Tab,{value:"HTTP",children:"Request"}),n(a.Tabs.Tab,{value:"Data",disabled:!e.datasource,children:n(a.Tooltip,{label:"Need to pick a Data Source first",disabled:e.datasource,withinPortal:!0,children:n(a.Text,{children:"Data"})})}),n(a.Tabs.Tab,{value:"Usage",disabled:s,children:n(a.Tooltip,{label:"This query is not used for any filter or panel",disabled:!s,withinPortal:!0,children:n(a.Text,{children:"Usage"})})})]}),n(a.Tabs.Panel,{value:"Configurations",pt:0,p:0,children:n(k0,{queryModel:e})}),e.typedAsSQL&&n(a.Tabs.Panel,{value:"SQL",sx:un,children:n(a.Stack,{sx:{height:"100%"},children:n(L0,{queryModel:e})})}),e.typedAsHTTP&&n(a.Tabs.Panel,{value:"HTTP",sx:un,children:n(a.Stack,{sx:{height:"100%"},children:n(A0,{queryModel:e})})}),n(a.Tabs.Panel,{value:"Data",sx:{...un,overflow:"hidden"},children:n(Es,{id:e.id})}),n(a.Tabs.Panel,{value:"Usage",sx:{...un,overflow:"hidden"},children:n($0,{queryID:e.id,usage:i})})]})})}),O0=T.observer(({id:e})=>{const r=F().queries.findByID(e);return e===""?null:r?n(a.Stack,{sx:{height:"100%"},spacing:"sm",children:n(P0,{queryModel:r})}):n(a.Text,{size:14,color:"red",children:"Invalid Query ID"})}),V0=T.observer(({value:e})=>{const t=F(),{context:r,mock_context:i,filterValues:s}=t.payloadForSQL,o=sv(e,r,i,s);return n(Cr,{height:"100%",value:o})}),B0=T.observer(({item:e,remove:t,onKeyChanged:r})=>{const[i,s]=b.useState("SQL"),[o,u]=b.useState(e.key),l=()=>{e.setKey(o),r(o)},d=o!==e.key,c=e.isADuplicatedKey(o),[f,g]=b.useState(e.value),h=()=>{e.setValue(f)};b.useEffect(()=>{u(e.key),g(e.value)},[e]);const m=f!==e.value,w=Le.useModals(),C=()=>{w.openConfirmModal({title:"Delete this SQL snippet?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:t,zIndex:320})};return p(a.Stack,{p:20,sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",children:[p(a.Group,{sx:{alignItems:"end"},spacing:40,children:[n(a.TextInput,{label:c?"This key is occupied by another snippet":"Key",value:o,onChange:S=>{u(S.currentTarget.value)},sx:{flexGrow:"1 !important"},rightSection:n(a.ActionIcon,{color:"blue",variant:"subtle",onClick:l,disabled:!d||c,children:n(k.DeviceFloppy,{size:16})}),error:c}),n(a.Button,{leftIcon:n(k.Trash,{size:16}),color:"red",variant:"light",onClick:C,children:"Delete this SQL Snippet"})]}),p(a.Tabs,{value:i,onTabChange:s,sx:{flexGrow:1},styles:{panel:{height:"calc(100% - 50px)"}},children:[p(a.Tabs.List,{sx:{position:"relative"},children:[n(a.Tabs.Tab,{value:"SQL",children:"SQL"}),n(a.Tabs.Tab,{value:"Preview",children:"Preview"}),n(xr,{}),n(a.ActionIcon,{color:"blue",variant:"filled",onClick:h,disabled:!m,sx:{position:"absolute",top:0,right:10},children:n(k.DeviceFloppy,{size:18})})]}),n(a.Tabs.Panel,{value:"SQL",pt:"sm",children:n(Cr,{height:"100%",value:f,onChange:g})}),n(a.Tabs.Panel,{value:"Preview",pt:"sm",children:n(V0,{value:f})})]})]})}),N0=T.observer(({id:e})=>{const t=me(),r=F(),i=b.useMemo(()=>r.sqlSnippets.findByKey(e),[e]);if(!e)return null;if(!i)return p(a.Text,{size:14,children:["SQL Snippet by key[",e,"] is not found"]});const s=()=>{t.editor.setPath(["_SQL_SNIPPETS_",""])};return n(B0,{item:i,remove:()=>{r.sqlSnippets.removeByKey(e),s()},onKeyChanged:l=>{t.editor.setPath(["_SQL_SNIPPETS_",l])}})}),G0=T.observer(({view:e})=>!e||e.type!==K.Division?null:p(a.Stack,{children:[n(a.Divider,{mt:8,mb:0,label:"Division settings",labelPosition:"center"}),n(a.Text,{align:"center",size:"xs",color:"dimmed",children:"Under construction"})]})),q0=[{value:"default",label:"Default"},{value:"outline",label:"Outline"},{value:"pills",label:"Pills"}],F0=[{value:"horizontal",label:"Horizontal"},{value:"vertical",label:"Vertical"}],W0=T.observer(({view:e})=>{if(!e||e.type!==K.Tabs)return null;const t=e.config;return p(a.Stack,{children:[n(a.Divider,{mt:8,mb:0,label:"Tabs settings",labelPosition:"center"}),n(a.Select,{label:"Variant",value:t.variant,onChange:t.setVariant,data:q0}),n(a.Select,{label:"Orientation",value:t.orientation,onChange:t.setOrientation,data:F0}),n(a.Switch,{label:"Grow Tabs",checked:t.grow,onChange:r=>t.setGrow(r.currentTarget.checked)})]})}),j0=({disabled:e,value:t,onChange:r})=>{const i=s=>{s&&r(s)};return p(a.Box,{sx:{position:"relative"},children:[e&&n(a.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),n(_e,{height:"500px",defaultLanguage:"javascript",value:t,onChange:i,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},Y0=({value:e,onChange:t})=>{const[r,{setTrue:i,setFalse:s}]=Z.useBoolean(),[o,u]=b.useState(e??cr),l=h=>{u({...o,enabled:h})},d=()=>{s();const{enabled:h,func_content:m}=o,w={enabled:h,func_content:m};u(w),t(w)},c=()=>{s(),u(e)},f=h=>{u(m=>({...m,func_content:h}))},g=()=>{f(cr.func_content)};return p(O,{children:[n(a.ActionIcon,{size:"lg",color:"blue",variant:"filled",mt:26,onClick:i,sx:{flexGrow:0},children:n(k.Settings,{size:14})}),n(a.Modal,{size:800,title:"Customize modal title",opened:r,onClose:s,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(a.Stack,{children:[n(a.Checkbox,{mt:10,label:"Enabled",checked:o.enabled,onChange:h=>l(h.currentTarget.checked)}),n(j0,{value:o.func_content,onChange:f,disabled:!o.enabled}),p(a.Group,{position:"apart",children:[n(a.Button,{onClick:g,color:"red",leftIcon:n(k.Recycle,{size:20}),children:"Rest"}),p(a.Group,{position:"right",children:[n(a.Button,{onClick:c,variant:"subtle",children:"Cancel"}),n(a.Button,{onClick:d,children:"OK"})]})]})]})})]})},R0=T.observer(({view:e})=>{if(!e||e.type!==K.Modal)return null;const t=e.config,r=t.custom_modal_title.value;return p(a.Stack,{children:[n(a.Divider,{mt:8,label:"Modal settings",labelPosition:"center"}),p(a.Flex,{gap:10,children:[n(a.TextInput,{label:"Modal Title",value:r,onChange:v.noop,disabled:!0,sx:{flexGrow:1}}),n(Y0,{value:t.custom_modal_title,onChange:t.custom_modal_title.replace})]}),p(a.Group,{grow:!0,children:[n(a.TextInput,{label:"Width",value:t.width,onChange:i=>t.setWidth(i.currentTarget.value),placeholder:"600px / 50vw"}),n(a.TextInput,{label:"Height",value:t.height,onChange:i=>t.setHeight(i.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),Q0=T.observer(({view:e})=>p(O,{children:[n(G0,{view:e}),n(R0,{view:e}),n(W0,{view:e})]})),U0=[{label:"Division",value:K.Division},{label:"Modal",value:K.Modal},{label:"Tabs",value:K.Tabs}],X0=T.observer(({view:e})=>e?p(a.Stack,{sx:{position:"relative"},children:[n(a.TextInput,{label:"Name",value:e.name,onChange:t=>{e.setName(t.currentTarget.value)}}),n(a.Select,{label:"Type",withinPortal:!0,value:e.type,onChange:e.setType,data:U0}),n(Q0,{view:e})]}):null),Z0=T.observer(({id:e})=>{const t=Le.useModals(),r=me(),i=F();if(e==="")return null;const s=i.views.findByID(e);if(!s)return p(a.Text,{size:14,children:["View by ID[",e,"] is not found"]});const o=()=>{r.editor.setPath(["_VIEWS_",""])},u=()=>{t.openConfirmModal({title:"Delete this view?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.views.removeByID(e),o()},zIndex:320})};return p(a.Stack,{sx:{maxWidth:"600px",height:"100%"},spacing:"sm",children:[n(a.Group,{position:"right",pt:10,children:n(a.Button,{size:"xs",color:"red",leftIcon:n(k.Trash,{size:16}),onClick:u,children:"Delete this view"})}),n(a.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:n(X0,{view:s})})]})});function K0(e){return e.length===1&&e[0]==="_GLOBAL_VARS_"}function J0(e){return e.length===1&&e[0]==="_MOCK_CONTEXT_"}function H0(e){return e.length===2&&e[0]==="_FILTERS_"}function eC(e){return e.length===2&&e[0]==="_SQL_SNIPPETS_"}function tC(e){return e.length===2&&e[0]==="_QUERIES_"}function nC(e){return e.length===2&&e[0]==="_VIEWS_"}function rC(e){return e.length===4&&e[0]==="_VIEWS_"&&e[2]==="_PANELS_"}const iC=T.observer(()=>n(a.Stack,{sx:{height:"100%"},p:"sm",children:n(Ns,{})})),aC=T.observer(()=>{const e=me().editor,t=e.path;return K0(t)?n(iC,{}):J0(t)?n(Ix,{}):H0(t)?n(a.Box,{p:"xs",pl:20,children:n(Mx,{id:t[1]})}):eC(t)?n(N0,{id:t[1]}):tC(t)?n(O0,{id:t[1]}):nC(t)?n(a.Box,{p:"xs",pl:20,children:n(Z0,{id:t[1]})}):rC(t)?n(a0,{viewID:t[1],panelID:t[3]}):n(a.Box,{children:e.path})}),sC=T.observer(()=>n(aC,{})),oC=T.observer(()=>{const e=F(),t=()=>{const r=new Date().getTime().toString(),i={id:r,key:r,label:r,order:e.filters.current.length+1,type:ar.TextInput,config:ns(),visibleInViewsIDs:["Main"],auto_submit:!1};e.filters.append(i)};return n(a.Button,{variant:"subtle",leftIcon:n(V.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Filter"})}),lC=T.observer(({parentID:e})=>{const t=F();if(!e)return null;const r=t.views.findByID(e);return r?n(a.Button,{variant:"subtle",leftIcon:n(V.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:()=>t.addANewPanel(r.id),sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Panel"}):null}),uC=T.observer(()=>{const e=F(),t=()=>{const r=new Date().getTime().toString(),i={id:r,name:r,type:ce.Postgresql,key:"",sql:""};e.queries.append(i)};return n(a.Button,{variant:"subtle",leftIcon:n(V.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Query"})}),dC=T.observer(()=>{const e=F(),t=()=>{const i={key:new Date().getTime().toString(),value:""};e.sqlSnippets.append(i)};return n(a.Button,{variant:"subtle",leftIcon:n(V.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a SQL Snippet"})}),cC=T.observer(()=>{const e=F();return n(a.Button,{variant:"subtle",leftIcon:n(V.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:e.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a View"})}),pC=T.observer(({action_type:e,parentID:t})=>(F(),e==="_Add_A_Filter_"?n(oC,{}):e==="_Add_A_SQL_SNIPPET_"?n(dC,{}):e==="_Add_A_QUERY_"?n(uC,{}):e==="_Add_A_VIEW_"?n(cC,{}):e==="_Add_A_PANEL_"?n(lC,{parentID:t}):null)),Fs=T.observer(({option:e})=>{var c;const t=me().editor,r=t.isOptionActive,i=r(t.path,e),s=t.isOptionOpened,o=t.navigate,u=s(e),[l,d]=b.useState(u);return b.useEffect(()=>{d(u)},[u]),n(a.NavLink,{active:i,defaultOpened:u,opened:l,onChange:d,label:e.label,onClick:()=>o(e),icon:e.Icon?n(e.Icon,{size:18}):null,children:(c=e.children)==null?void 0:c.map(f=>f._type==="ACTION"?n(pC,{action_type:f._action_type,parentID:f.parentID},`_ADD_${f.value}_`):n(Fs,{option:f},f.value))},e.label)}),hC=T.observer(()=>{const e=me();return n(a.Box,{sx:{position:"relative"},children:e.editor.navOptions.map(t=>n(Fs,{option:t},t.value))})}),fC=T.observer(()=>{const e=me();return p(a.Navbar,{p:0,width:{base:200,xs:200,sm:220,md:240,lg:280,xl:300},sx:{height:"100vh - 60px - 60px"},children:[n(a.Navbar.Section,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:n(a.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Settings"})}),n(a.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:n(hC,{})}),n(a.Navbar.Section,{children:n(a.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:n(a.Button,{size:"xs",color:"red",leftIcon:n(V.IconX,{size:18}),onClick:()=>e.editor.close(),children:"Close"})})})]})}),gC={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1,nav:{top:0,height:"100vh"}},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:0,height:"100vh"}},mC=T.observer(()=>{const e=me().editor;return n(a.Modal,{onClose:()=>e.setSettingsOpen(!1),closeOnEscape:!1,closeOnClickOutside:!1,opened:e.settings_open,fullScreen:!0,title:null,transitionDuration:0,withCloseButton:!1,withinPortal:!0,zIndex:300,styles:{modal:{padding:"0 !important"}},children:n(a.AppShell,{padding:0,navbar:n(fC,{}),styles:gC,children:n(sC,{})})})}),bC=e=>e.replace(/([^:])(\/\/+)/g,"$1/");function yC(e){b.useEffect(()=>{if(_e.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const r=bC(e);_e.loader.config({paths:{vs:r}}),_e.loader.init().then(i=>console.log("monaco instance:",i))},[])}const Ws={grid:{axis:"#97999D",scope:"rgba(47,140,192,0.1)",boundary:"#789AB4",reference:"#CFCFD8"},graphics:{compared:{blueDark:"#3E7CAB",blue:"#6398C7",blueLight:"#7CB0DF",blue10:"#6398C71a",redDark:"#AF5F6B",red:"#CD7C88",redLight:"#E794A0",red10:"#CD7C881a"},gradient:{distributed:"linear-gradient(90deg, #1babe6 0%, #2fc8c8 28.63%, #98d44b 48.86%, #ffd057 67.53%, #f5ae53 80.6%, #e76441 91.18%, #b90000 100%)",protrude:"linear-gradient(180deg, #ec73734d 0%, #ec737300 100%)"},level:{lv0:"#6398C7",lv1:"#61B5BF",lv2:"#54D4BB",lv3:"#F5D277",lv4:"#E8BB7F",lv5:"#DB9E84",lv6:"#CB8089"},depth:{dp0:"#FFF7F8",dp1:"#FFE1E1",dp2:"#FDBCBC",dp3:"#F39494",dp4:"#FA4242",dp5:"#E21212"},multiple:{c1:"#66B4DB",c2:"#E46464",c3:"#EEBA00",c4:"#33A678",c5:"#9D88CB",c6:"#939943",c7:"#E49792",c8:"#09A2B8",c9:"#AF5F6B",c10:"#6CA157",c11:"#3E7CAB",c12:"#6398C7",c13:"#E692BA",c14:"#97B566",c15:"#8CACE2",c16:"#CA79AC",c17:"#6DBC80",c18:"#B08F4B",c19:"#39BFA2",c20:"#826BAF"}}};function vC(){le.registerTheme("merico-light",{color:Object.values(Ws.graphics.multiple),visualMap:{color:Object.values(Ws.graphics.depth).reverse()}})}function js(){vC()}js();const xC={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:60+30,height:"100vh"}},CC=({context:e,dashboard:t,content:r,update:i,className:s="dashboard",config:o,onChange:u,headerSlot:l,headerMenuItems:d},c)=>{yC(o.monacoPath),Ua(o);const{data:f=[]}=Z.useRequest(dr),[g,h]=b.useState(!1),m=b.useMemo(()=>hr(t,r,f,e),[t,r]);b.useImperativeHandle(c,()=>m,[m]),Mi(m.content,!0),b.useEffect(()=>{m.context.replace(e)},[e]),b.useEffect(()=>{m.datasources.replace(f)},[f]),b.useEffect(()=>ae.reaction(()=>ae.toJS(m.json),I=>{u==null||u(I)}),[m]);const w=async()=>{await i(m.json,m.content.json)},C=Z.useCreation(rr,[]),S=fr(C);return n(Le.ModalsProvider,{children:n(bn,{value:m,children:n(yn,{value:m.content,children:n(Ze.Provider,{value:{layoutFrozen:g,freezeLayout:h,inEditMode:!0},children:n(Ge.Provider,{value:C,children:p(Gt,{configure:S,children:[n(a.AppShell,{padding:0,header:n(Gv,{saveDashboardChanges:w,headerSlot:l,headerMenuItems:d}),navbar:n(hx,{}),styles:xC,children:n(a.Box,{className:`${s} dashboard-root`,sx:{position:"relative"},children:m.content.views.visibleViews.map(I=>n(Qa,{view:I},I.id))})}),n(mC,{})]})})})})})})},wC=T.observer(b.forwardRef(CC)),y1="";js();const _C=T.observer(({context:e,dashboard:t,content:r,className:i="dashboard",config:s,fullScreenPanelID:o,setFullScreenPanelID:u})=>{Ua(s);const{data:l=[]}=Z.useRequest(dr),d=b.useMemo(()=>hr(t,r,l,e),[t,r]);Mi(d.content,!1),b.useEffect(()=>{d.context.replace(e)},[e]),b.useEffect(()=>{d.datasources.replace(l)},[l]);const c=Z.useCreation(rr,[]),f=fr(c);return n(Le.ModalsProvider,{children:n(bn,{value:d,children:n(yn,{value:d.content,children:n(xn.Provider,{value:{fullScreenPanelID:o,setFullScreenPanelID:u},children:n(Ze.Provider,{value:{layoutFrozen:!0,freezeLayout:v.noop,inEditMode:!1},children:n(a.Box,{className:`${i} dashboard-root`,children:n(Ge.Provider,{value:c,children:n(Gt,{configure:f,children:d.content.views.visibleViews.map(g=>n(nn,{view:g},g.id))})})})})})})})})});var wr={},SC={get exports(){return wr},set exports(e){wr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){var o=i.prototype,u=o.format;s.en.ordinal=function(l){var d=["th","st","nd","rd"],c=l%100;return"["+l+(d[(c-20)%10]||d[c]||d[0])+"]"},o.format=function(l){var d=this,c=this.$locale();if(!this.isValid())return u.bind(this)(l);var f=this.$utils(),g=(l||"YYYY-MM-DDTHH:mm:ssZ").replace(/\[([^\]]+)]|Q|wo|ww|w|WW|W|zzz|z|gggg|GGGG|Do|X|x|k{1,2}|S/g,function(h){switch(h){case"Q":return Math.ceil((d.$M+1)/3);case"Do":return c.ordinal(d.$D);case"gggg":return d.weekYear();case"GGGG":return d.isoWeekYear();case"wo":return c.ordinal(d.week(),"W");case"w":case"ww":return f.s(d.week(),h==="w"?1:2,"0");case"W":case"WW":return f.s(d.isoWeek(),h==="W"?1:2,"0");case"k":case"kk":return f.s(String(d.$H===0?24:d.$H),h==="k"?1:2,"0");case"X":return Math.floor(d.$d.getTime()/1e3);case"x":return d.$d.getTime();case"z":return"["+d.offsetName()+"]";case"zzz":return"["+d.offsetName("long")+"]";default:return h}});return u.bind(this)(g)}}})})(SC);const TC=wr;var _r={},kC={get exports(){return _r},set exports(e){_r=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){var o=i.prototype,u=function(d){var c=d.date,f=d.utc;return Array.isArray(c)?f?c.length?new Date(Date.UTC.apply(null,c)):new Date:c.length===1?s(String(c[0])).toDate():new(Function.prototype.bind.apply(Date,[null].concat(c))):c},l=o.parse;o.parse=function(d){d.date=u.bind(this)(d),l.bind(this)(d)}}})})(kC);const DC=_r;var Sr={},MC={get exports(){return Sr},set exports(e){Sr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){var s=i.prototype;s.$g=function(h,m,w){return this.$utils().u(h)?this[m]:this.$set(w,h)},s.set=function(h,m){return this.$set(h,m)};var o=s.startOf;s.startOf=function(h,m){return this.$d=o.bind(this)(h,m).toDate(),this.init(),this};var u=s.add;s.add=function(h,m){return this.$d=u.bind(this)(h,m).toDate(),this.init(),this};var l=s.locale;s.locale=function(h,m){return h?(this.$L=l.bind(this)(h,m).$L,this):this.$L};var d=s.daysInMonth;s.daysInMonth=function(){return d.bind(this.clone())()};var c=s.isSame;s.isSame=function(h,m){return c.bind(this.clone())(h,m)};var f=s.isBefore;s.isBefore=function(h,m){return f.bind(this.clone())(h,m)};var g=s.isAfter;s.isAfter=function(h,m){return g.bind(this.clone())(h,m)}}})})(MC);const IC=Sr;var Tr={},AC={get exports(){return Tr},set exports(e){Tr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){var s=i.prototype,o=s.format;s.format=function(u){var l=this,d=(u||"YYYY-MM-DDTHH:mm:ssZ").replace(/(\[[^\]]+])|BBBB|BB/g,function(c,f){var g,h=String(l.$y+543),m=c==="BB"?[h.slice(-2),2]:[h,4];return f||(g=l.$utils()).s.apply(g,m.concat(["0"]))});return o.bind(this)(d)}}})})(AC);const $C=Tr;var kr={},zC={get exports(){return kr},set exports(e){kr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){var o="h:mm A",u={lastDay:"[Yesterday at] "+o,sameDay:"[Today at] "+o,nextDay:"[Tomorrow at] "+o,nextWeek:"dddd [at] "+o,lastWeek:"[Last] dddd [at] "+o,sameElse:"MM/DD/YYYY"};i.prototype.calendar=function(l,d){var c=d||this.$locale().calendar||u,f=s(l||void 0).startOf("d"),g=this.diff(f,"d",!0),h="sameElse",m=g<-6?h:g<-1?"lastWeek":g<0?"lastDay":g<1?"sameDay":g<2?"nextDay":g<7?"nextWeek":h,w=c[m]||u[m];return typeof w=="function"?w.call(this,s()):this.format(w)}}})})(zC);const EC=kr;var Dr={},LC={get exports(){return Dr},set exports(e){Dr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){var r={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"},i=/(\[[^[]*\])|([-_:/.,()\s]+)|(A|a|YYYY|YY?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g,s=/\d\d/,o=/\d\d?/,u=/\d*[^-_:/,()\s\d]+/,l={},d=function(C){return(C=+C)+(C>68?1900:2e3)},c=function(C){return function(S){this[C]=+S}},f=[/[+-]\d\d:?(\d\d)?|Z/,function(C){(this.zone||(this.zone={})).offset=function(S){if(!S||S==="Z")return 0;var I=S.match(/([+-]|\d\d)/g),$=60*I[1]+(+I[2]||0);return $===0?0:I[0]==="+"?-$:$}(C)}],g=function(C){var S=l[C];return S&&(S.indexOf?S:S.s.concat(S.f))},h=function(C,S){var I,$=l.meridiem;if($){for(var G=1;G<=24;G+=1)if(C.indexOf($(G,0,S))>-1){I=G>12;break}}else I=C===(S?"pm":"PM");return I},m={A:[u,function(C){this.afternoon=h(C,!1)}],a:[u,function(C){this.afternoon=h(C,!0)}],S:[/\d/,function(C){this.milliseconds=100*+C}],SS:[s,function(C){this.milliseconds=10*+C}],SSS:[/\d{3}/,function(C){this.milliseconds=+C}],s:[o,c("seconds")],ss:[o,c("seconds")],m:[o,c("minutes")],mm:[o,c("minutes")],H:[o,c("hours")],h:[o,c("hours")],HH:[o,c("hours")],hh:[o,c("hours")],D:[o,c("day")],DD:[s,c("day")],Do:[u,function(C){var S=l.ordinal,I=C.match(/\d+/);if(this.day=I[0],S)for(var $=1;$<=31;$+=1)S($).replace(/\[|\]/g,"")===C&&(this.day=$)}],M:[o,c("month")],MM:[s,c("month")],MMM:[u,function(C){var S=g("months"),I=(g("monthsShort")||S.map(function($){return $.slice(0,3)})).indexOf(C)+1;if(I<1)throw new Error;this.month=I%12||I}],MMMM:[u,function(C){var S=g("months").indexOf(C)+1;if(S<1)throw new Error;this.month=S%12||S}],Y:[/[+-]?\d+/,c("year")],YY:[s,function(C){this.year=d(C)}],YYYY:[/\d{4}/,c("year")],Z:f,ZZ:f};function w(C){var S,I;S=C,I=l&&l.formats;for(var $=(C=S.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(U,Q,te){var re=te&&te.toUpperCase();return Q||I[te]||r[te]||I[re].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(oe,ne,pe){return ne||pe.slice(1)})})).match(i),G=$.length,q=0;q<G;q+=1){var L=$[q],z=m[L],A=z&&z[0],N=z&&z[1];$[q]=N?{regex:A,parser:N}:L.replace(/^\[|\]$/g,"")}return function(U){for(var Q={},te=0,re=0;te<G;te+=1){var oe=$[te];if(typeof oe=="string")re+=oe.length;else{var ne=oe.regex,pe=oe.parser,fe=U.slice(re),Se=ne.exec(fe)[0];pe.call(Q,Se),U=U.replace(Se,"")}}return function(Fe){var Ae=Fe.afternoon;if(Ae!==void 0){var Re=Fe.hours;Ae?Re<12&&(Fe.hours+=12):Re===12&&(Fe.hours=0),delete Fe.afternoon}}(Q),Q}}return function(C,S,I){I.p.customParseFormat=!0,C&&C.parseTwoDigitYear&&(d=C.parseTwoDigitYear);var $=S.prototype,G=$.parse;$.parse=function(q){var L=q.date,z=q.utc,A=q.args;this.$u=z;var N=A[1];if(typeof N=="string"){var U=A[2]===!0,Q=A[3]===!0,te=U||Q,re=A[2];Q&&(re=A[2]),l=this.$locale(),!U&&re&&(l=I.Ls[re]),this.$d=function(fe,Se,Fe){try{if(["x","X"].indexOf(Se)>-1)return new Date((Se==="X"?1e3:1)*fe);var Ae=w(Se)(fe),Re=Ae.year,it=Ae.month,dn=Ae.day,cn=Ae.hours,ni=Ae.minutes,ri=Ae.seconds,$t=Ae.milliseconds,ft=Ae.zone,et=new Date,at=dn||(Re||it?1:et.getDate()),tt=Re||et.getFullYear(),gt=0;Re&&!it||(gt=it>0?it-1:et.getMonth());var mt=cn||0,zt=ni||0,Et=ri||0,nt=$t||0;return ft?new Date(Date.UTC(tt,gt,at,mt,zt,Et,nt+60*ft.offset*1e3)):Fe?new Date(Date.UTC(tt,gt,at,mt,zt,Et,nt)):new Date(tt,gt,at,mt,zt,Et,nt)}catch{return new Date("")}}(L,N,z),this.init(),re&&re!==!0&&(this.$L=this.locale(re).$L),te&&L!=this.format(N)&&(this.$d=new Date("")),l={}}else if(N instanceof Array)for(var oe=N.length,ne=1;ne<=oe;ne+=1){A[1]=N[ne-1];var pe=I.apply(this,A);if(pe.isValid()){this.$d=pe.$d,this.$L=pe.$L,this.init();break}ne===oe&&(this.$d=new Date(""))}else G.call(this,q)}}})})(LC);const PC=Dr;var Mr={},OC={get exports(){return Mr},set exports(e){Mr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){i.prototype.dayOfYear=function(o){var u=Math.round((s(this).startOf("day")-s(this).startOf("year"))/864e5)+1;return o==null?u:this.add(o-u,"day")}}})})(OC);const VC=Mr;var Ir={},BC={get exports(){return Ir},set exports(e){Ir=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){var r,i,s=1e3,o=6e4,u=36e5,l=864e5,d=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,c=31536e6,f=2592e6,g=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/,h={years:c,months:f,days:l,hours:u,minutes:o,seconds:s,milliseconds:1,weeks:6048e5},m=function(L){return L instanceof q},w=function(L,z,A){return new q(L,A,z.$l)},C=function(L){return i.p(L)+"s"},S=function(L){return L<0},I=function(L){return S(L)?Math.ceil(L):Math.floor(L)},$=function(L){return Math.abs(L)},G=function(L,z){return L?S(L)?{negative:!0,format:""+$(L)+z}:{negative:!1,format:""+L+z}:{negative:!1,format:""}},q=function(){function L(A,N,U){var Q=this;if(this.$d={},this.$l=U,A===void 0&&(this.$ms=0,this.parseFromMilliseconds()),N)return w(A*h[C(N)],this);if(typeof A=="number")return this.$ms=A,this.parseFromMilliseconds(),this;if(typeof A=="object")return Object.keys(A).forEach(function(oe){Q.$d[C(oe)]=A[oe]}),this.calMilliseconds(),this;if(typeof A=="string"){var te=A.match(g);if(te){var re=te.slice(2).map(function(oe){return oe!=null?Number(oe):0});return this.$d.years=re[0],this.$d.months=re[1],this.$d.weeks=re[2],this.$d.days=re[3],this.$d.hours=re[4],this.$d.minutes=re[5],this.$d.seconds=re[6],this.calMilliseconds(),this}}return this}var z=L.prototype;return z.calMilliseconds=function(){var A=this;this.$ms=Object.keys(this.$d).reduce(function(N,U){return N+(A.$d[U]||0)*h[U]},0)},z.parseFromMilliseconds=function(){var A=this.$ms;this.$d.years=I(A/c),A%=c,this.$d.months=I(A/f),A%=f,this.$d.days=I(A/l),A%=l,this.$d.hours=I(A/u),A%=u,this.$d.minutes=I(A/o),A%=o,this.$d.seconds=I(A/s),A%=s,this.$d.milliseconds=A},z.toISOString=function(){var A=G(this.$d.years,"Y"),N=G(this.$d.months,"M"),U=+this.$d.days||0;this.$d.weeks&&(U+=7*this.$d.weeks);var Q=G(U,"D"),te=G(this.$d.hours,"H"),re=G(this.$d.minutes,"M"),oe=this.$d.seconds||0;this.$d.milliseconds&&(oe+=this.$d.milliseconds/1e3);var ne=G(oe,"S"),pe=A.negative||N.negative||Q.negative||te.negative||re.negative||ne.negative,fe=te.format||re.format||ne.format?"T":"",Se=(pe?"-":"")+"P"+A.format+N.format+Q.format+fe+te.format+re.format+ne.format;return Se==="P"||Se==="-P"?"P0D":Se},z.toJSON=function(){return this.toISOString()},z.format=function(A){var N=A||"YYYY-MM-DDTHH:mm:ss",U={Y:this.$d.years,YY:i.s(this.$d.years,2,"0"),YYYY:i.s(this.$d.years,4,"0"),M:this.$d.months,MM:i.s(this.$d.months,2,"0"),D:this.$d.days,DD:i.s(this.$d.days,2,"0"),H:this.$d.hours,HH:i.s(this.$d.hours,2,"0"),m:this.$d.minutes,mm:i.s(this.$d.minutes,2,"0"),s:this.$d.seconds,ss:i.s(this.$d.seconds,2,"0"),SSS:i.s(this.$d.milliseconds,3,"0")};return N.replace(d,function(Q,te){return te||String(U[Q])})},z.as=function(A){return this.$ms/h[C(A)]},z.get=function(A){var N=this.$ms,U=C(A);return U==="milliseconds"?N%=1e3:N=U==="weeks"?I(N/h[U]):this.$d[U],N===0?0:N},z.add=function(A,N,U){var Q;return Q=N?A*h[C(N)]:m(A)?A.$ms:w(A,this).$ms,w(this.$ms+Q*(U?-1:1),this)},z.subtract=function(A,N){return this.add(A,N,!0)},z.locale=function(A){var N=this.clone();return N.$l=A,N},z.clone=function(){return w(this.$ms,this)},z.humanize=function(A){return r().add(this.$ms,"ms").locale(this.$l).fromNow(!A)},z.milliseconds=function(){return this.get("milliseconds")},z.asMilliseconds=function(){return this.as("milliseconds")},z.seconds=function(){return this.get("seconds")},z.asSeconds=function(){return this.as("seconds")},z.minutes=function(){return this.get("minutes")},z.asMinutes=function(){return this.as("minutes")},z.hours=function(){return this.get("hours")},z.asHours=function(){return this.as("hours")},z.days=function(){return this.get("days")},z.asDays=function(){return this.as("days")},z.weeks=function(){return this.get("weeks")},z.asWeeks=function(){return this.as("weeks")},z.months=function(){return this.get("months")},z.asMonths=function(){return this.as("months")},z.years=function(){return this.get("years")},z.asYears=function(){return this.as("years")},L}();return function(L,z,A){r=A,i=A().$utils(),A.duration=function(Q,te){var re=A.locale();return w(Q,{$l:re},te)},A.isDuration=m;var N=z.prototype.add,U=z.prototype.subtract;z.prototype.add=function(Q,te){return m(Q)&&(Q=Q.asMilliseconds()),N.bind(this)(Q,te)},z.prototype.subtract=function(Q,te){return m(Q)&&(Q=Q.asMilliseconds()),U.bind(this)(Q,te)}}})})(BC);const NC=Ir;var Ar={},GC={get exports(){return Ar},set exports(e){Ar=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){i.prototype.isBetween=function(o,u,l,d){var c=s(o),f=s(u),g=(d=d||"()")[0]==="(",h=d[1]===")";return(g?this.isAfter(c,l):!this.isBefore(c,l))&&(h?this.isBefore(f,l):!this.isAfter(f,l))||(g?this.isBefore(c,l):!this.isAfter(c,l))&&(h?this.isAfter(f,l):!this.isBefore(f,l))}}})})(GC);const qC=Ar;var $r={},FC={get exports(){return $r},set exports(e){$r=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){i.prototype.isLeapYear=function(){return this.$y%4==0&&this.$y%100!=0||this.$y%400==0}}})})(FC);const WC=$r;var zr={},jC={get exports(){return zr},set exports(e){zr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){s.isMoment=function(o){return s.isDayjs(o)}}})})(jC);const YC=zr;var Er={},RC={get exports(){return Er},set exports(e){Er=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){var r="day";return function(i,s,o){var u=function(c){return c.add(4-c.isoWeekday(),r)},l=s.prototype;l.isoWeekYear=function(){return u(this).year()},l.isoWeek=function(c){if(!this.$utils().u(c))return this.add(7*(c-this.isoWeek()),r);var f,g,h,m,w=u(this),C=(f=this.isoWeekYear(),g=this.$u,h=(g?o.utc:o)().year(f).startOf("year"),m=4-h.isoWeekday(),h.isoWeekday()>4&&(m+=7),h.add(m,r));return w.diff(C,"week")+1},l.isoWeekday=function(c){return this.$utils().u(c)?this.day()||7:this.day(this.day()%7?c:c-7)};var d=l.startOf;l.startOf=function(c,f){var g=this.$utils(),h=!!g.u(f)||f;return g.p(c)==="isoweek"?h?this.date(this.date()-(this.isoWeekday()-1)).startOf("day"):this.date(this.date()-1-(this.isoWeekday()-1)+7).endOf("day"):d.bind(this)(c,f)}}})})(RC);const QC=Er;var Lr={},UC={get exports(){return Lr},set exports(e){Lr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){i.prototype.isoWeeksInYear=function(){var s=this.isLeapYear(),o=this.endOf("y").day();return o===4||s&&o===5?53:52}}})})(UC);const XC=Lr;var Pr={},ZC={get exports(){return Pr},set exports(e){Pr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){i.prototype.isSameOrAfter=function(s,o){return this.isSame(s,o)||this.isAfter(s,o)}}})})(ZC);const KC=Pr;var Or={},JC={get exports(){return Or},set exports(e){Or=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){i.prototype.isSameOrBefore=function(s,o){return this.isSame(s,o)||this.isBefore(s,o)}}})})(JC);const HC=Or;var Vr={},ew={get exports(){return Vr},set exports(e){Vr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){i.prototype.isToday=function(){var o="YYYY-MM-DD",u=s();return this.format(o)===u.format(o)}}})})(ew);const tw=Vr;var Br={},nw={get exports(){return Br},set exports(e){Br=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){i.prototype.isTomorrow=function(){var o="YYYY-MM-DD",u=s().add(1,"day");return this.format(o)===u.format(o)}}})})(nw);const rw=Br;var Nr={},iw={get exports(){return Nr},set exports(e){Nr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){i.prototype.isYesterday=function(){var o="YYYY-MM-DD",u=s().subtract(1,"day");return this.format(o)===u.format(o)}}})})(iw);const aw=Nr;var Gr={},sw={get exports(){return Gr},set exports(e){Gr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){var o=i.prototype,u=function(g){return g&&(g.indexOf?g:g.s)},l=function(g,h,m,w,C){var S=g.name?g:g.$locale(),I=u(S[h]),$=u(S[m]),G=I||$.map(function(L){return L.slice(0,w)});if(!C)return G;var q=S.weekStart;return G.map(function(L,z){return G[(z+(q||0))%7]})},d=function(){return s.Ls[s.locale()]},c=function(g,h){return g.formats[h]||function(m){return m.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(w,C,S){return C||S.slice(1)})}(g.formats[h.toUpperCase()])},f=function(){var g=this;return{months:function(h){return h?h.format("MMMM"):l(g,"months")},monthsShort:function(h){return h?h.format("MMM"):l(g,"monthsShort","months",3)},firstDayOfWeek:function(){return g.$locale().weekStart||0},weekdays:function(h){return h?h.format("dddd"):l(g,"weekdays")},weekdaysMin:function(h){return h?h.format("dd"):l(g,"weekdaysMin","weekdays",2)},weekdaysShort:function(h){return h?h.format("ddd"):l(g,"weekdaysShort","weekdays",3)},longDateFormat:function(h){return c(g.$locale(),h)},meridiem:this.$locale().meridiem,ordinal:this.$locale().ordinal}};o.localeData=function(){return f.bind(this)()},s.localeData=function(){var g=d();return{firstDayOfWeek:function(){return g.weekStart||0},weekdays:function(){return s.weekdays()},weekdaysShort:function(){return s.weekdaysShort()},weekdaysMin:function(){return s.weekdaysMin()},months:function(){return s.months()},monthsShort:function(){return s.monthsShort()},longDateFormat:function(h){return c(g,h)},meridiem:g.meridiem,ordinal:g.ordinal}},s.months=function(){return l(d(),"months")},s.monthsShort=function(){return l(d(),"monthsShort","months",3)},s.weekdays=function(g){return l(d(),"weekdays",null,null,g)},s.weekdaysShort=function(g){return l(d(),"weekdaysShort","weekdays",3,g)},s.weekdaysMin=function(g){return l(d(),"weekdaysMin","weekdays",2,g)}}})})(sw);const ow=Gr;var qr={},lw={get exports(){return qr},set exports(e){qr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){var r={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"};return function(i,s,o){var u=s.prototype,l=u.format;o.en.formats=r,u.format=function(d){d===void 0&&(d="YYYY-MM-DDTHH:mm:ssZ");var c=this.$locale().formats,f=function(g,h){return g.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(m,w,C){var S=C&&C.toUpperCase();return w||h[C]||r[C]||h[S].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(I,$,G){return $||G.slice(1)})})}(d,c===void 0?{}:c);return l.call(this,f)}}})})(lw);const uw=qr;var Fr={},dw={get exports(){return Fr},set exports(e){Fr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){var o=function(u,l){if(!l||!l.length||!l[0]||l.length===1&&!l[0].length)return null;var d;l.length===1&&l[0].length>0&&(l=l[0]),d=l[0];for(var c=1;c<l.length;c+=1)l[c].isValid()&&!l[c][u](d)||(d=l[c]);return d};s.max=function(){var u=[].slice.call(arguments,0);return o("isAfter",u)},s.min=function(){var u=[].slice.call(arguments,0);return o("isBefore",u)}}})})(dw);const cw=Fr;var Wr={},pw={get exports(){return Wr},set exports(e){Wr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){var o=i.prototype,u=function(g){var h,m=g.date,w=g.utc,C={};if(!((h=m)instanceof Date)&&!(h instanceof Array)&&h instanceof Object){if(!Object.keys(m).length)return new Date;var S=w?s.utc():s();Object.keys(m).forEach(function(N){var U,Q;C[U=N,Q=o.$utils().p(U),Q==="date"?"day":Q]=m[N]});var I=C.day||(C.year||C.month>=0?1:S.date()),$=C.year||S.year(),G=C.month>=0?C.month:C.year||C.day?0:S.month(),q=C.hour||0,L=C.minute||0,z=C.second||0,A=C.millisecond||0;return w?new Date(Date.UTC($,G,I,q,L,z,A)):new Date($,G,I,q,L,z,A)}return m},l=o.parse;o.parse=function(g){g.date=u.bind(this)(g),l.bind(this)(g)};var d=o.set,c=o.add,f=function(g,h,m,w){if(w===void 0&&(w=1),h instanceof Object){var C=Object.keys(h),S=this;return C.forEach(function(I){S=g.bind(S)(h[I]*w,I)}),S}return g.bind(this)(h*w,m)};o.set=function(g,h){return h=h===void 0?g:h,f.bind(this)(function(m,w){return d.bind(this)(w,m)},h,g)},o.add=function(g,h){return f.bind(this)(c,g,h)},o.subtract=function(g,h){return f.bind(this)(c,g,h,-1)}}})})(pw);const hw=Wr;var jr={},fw={get exports(){return jr},set exports(e){jr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){var s=i.prototype;["milliseconds","seconds","minutes","hours","days","weeks","isoWeeks","months","quarters","years","dates"].forEach(function(o){s[o]=s[o.replace(/s$/,"")]})}})})(fw);const gw=jr;var Yr={},mw={get exports(){return Yr},set exports(e){Yr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){var s=i.prototype.parse;i.prototype.parse=function(l){if(typeof l.date=="string"){var d=this.$locale();l.date=d&&d.preparse?d.preparse(l.date):l.date}return s.bind(this)(l)};var o=i.prototype.format;i.prototype.format=function(){for(var l=arguments.length,d=new Array(l),c=0;c<l;c++)d[c]=arguments[c];var f=o.call.apply(o,[this].concat(d)),g=this.$locale();return g&&g.postformat?g.postformat(f):f};var u=i.prototype.fromToBase;u&&(i.prototype.fromToBase=function(l,d,c,f){var g=this.$locale()||c.$locale();return u.call(this,l,d,c,f,g&&g.postformat)})}})})(mw);const bw=Yr;var Rr={},yw={get exports(){return Rr},set exports(e){Rr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){var r="month",i="quarter";return function(s,o){var u=o.prototype;u.quarter=function(c){return this.$utils().u(c)?Math.ceil((this.month()+1)/3):this.month(this.month()%3+3*(c-1))};var l=u.add;u.add=function(c,f){return c=Number(c),this.$utils().p(f)===i?this.add(3*c,r):l.bind(this)(c,f)};var d=u.startOf;u.startOf=function(c,f){var g=this.$utils(),h=!!g.u(f)||f;if(g.p(c)===i){var m=this.quarter()-1;return h?this.month(3*m).startOf(r).startOf("day"):this.month(3*m+2).endOf(r).endOf("day")}return d.bind(this)(c,f)}}})})(yw);const vw=Rr;var Qr={},xw={get exports(){return Qr},set exports(e){Qr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){r=r||{};var o=i.prototype,u={future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"};function l(c,f,g,h){return o.fromToBase(c,f,g,h)}s.en.relativeTime=u,o.fromToBase=function(c,f,g,h,m){for(var w,C,S,I=g.$locale().relativeTime||u,$=r.thresholds||[{l:"s",r:44,d:"second"},{l:"m",r:89},{l:"mm",r:44,d:"minute"},{l:"h",r:89},{l:"hh",r:21,d:"hour"},{l:"d",r:35},{l:"dd",r:25,d:"day"},{l:"M",r:45},{l:"MM",r:10,d:"month"},{l:"y",r:17},{l:"yy",d:"year"}],G=$.length,q=0;q<G;q+=1){var L=$[q];L.d&&(w=h?s(c).diff(g,L.d,!0):g.diff(c,L.d,!0));var z=(r.rounding||Math.round)(Math.abs(w));if(S=w>0,z<=L.r||!L.r){z<=1&&q>0&&(L=$[q-1]);var A=I[L.l];m&&(z=m(""+z)),C=typeof A=="string"?A.replace("%d",z):A(z,f,L.l,S);break}}if(f)return C;var N=S?I.future:I.past;return typeof N=="function"?N(C):N.replace("%s",C)},o.to=function(c,f){return l(c,f,this,!0)},o.from=function(c,f){return l(c,f,this)};var d=function(c){return c.$u?s.utc():s()};o.toNow=function(c){return this.to(d(this),c)},o.fromNow=function(c){return this.from(d(this),c)}}})})(xw);const Cw=Qr;var Ur={},ww={get exports(){return Ur},set exports(e){Ur=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){var r={year:0,month:1,day:2,hour:3,minute:4,second:5},i={};return function(s,o,u){var l,d=function(h,m,w){w===void 0&&(w={});var C=new Date(h),S=function(I,$){$===void 0&&($={});var G=$.timeZoneName||"short",q=I+"|"+G,L=i[q];return L||(L=new Intl.DateTimeFormat("en-US",{hour12:!1,timeZone:I,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:G}),i[q]=L),L}(m,w);return S.formatToParts(C)},c=function(h,m){for(var w=d(h,m),C=[],S=0;S<w.length;S+=1){var I=w[S],$=I.type,G=I.value,q=r[$];q>=0&&(C[q]=parseInt(G,10))}var L=C[3],z=L===24?0:L,A=C[0]+"-"+C[1]+"-"+C[2]+" "+z+":"+C[4]+":"+C[5]+":000",N=+h;return(u.utc(A).valueOf()-(N-=N%1e3))/6e4},f=o.prototype;f.tz=function(h,m){h===void 0&&(h=l);var w=this.utcOffset(),C=this.toDate(),S=C.toLocaleString("en-US",{timeZone:h}),I=Math.round((C-new Date(S))/1e3/60),$=u(S).$set("millisecond",this.$ms).utcOffset(15*-Math.round(C.getTimezoneOffset()/15)-I,!0);if(m){var G=$.utcOffset();$=$.add(w-G,"minute")}return $.$x.$timezone=h,$},f.offsetName=function(h){var m=this.$x.$timezone||u.tz.guess(),w=d(this.valueOf(),m,{timeZoneName:h}).find(function(C){return C.type.toLowerCase()==="timezonename"});return w&&w.value};var g=f.startOf;f.startOf=function(h,m){if(!this.$x||!this.$x.$timezone)return g.call(this,h,m);var w=u(this.format("YYYY-MM-DD HH:mm:ss:SSS"));return g.call(w,h,m).tz(this.$x.$timezone,!0)},u.tz=function(h,m,w){var C=w&&m,S=w||m||l,I=c(+u(),S);if(typeof h!="string")return u(h).tz(S);var $=function(z,A,N){var U=z-60*A*1e3,Q=c(U,N);if(A===Q)return[U,A];var te=c(U-=60*(Q-A)*1e3,N);return Q===te?[U,Q]:[z-60*Math.min(Q,te)*1e3,Math.max(Q,te)]}(u.utc(h,C).valueOf(),I,S),G=$[0],q=$[1],L=u(G).utcOffset(q);return L.$x.$timezone=S,L},u.tz.guess=function(){return Intl.DateTimeFormat().resolvedOptions().timeZone},u.tz.setDefault=function(h){l=h}}})})(ww);const _w=Ur;var Xr={},Sw={get exports(){return Xr},set exports(e){Xr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){i.prototype.toArray=function(){return[this.$y,this.$M,this.$D,this.$H,this.$m,this.$s,this.$ms]}}})})(Sw);const Tw=Xr;var Zr={},kw={get exports(){return Zr},set exports(e){Zr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){i.prototype.toObject=function(){return{years:this.$y,months:this.$M,date:this.$D,hours:this.$H,minutes:this.$m,seconds:this.$s,milliseconds:this.$ms}}}})})(kw);const Dw=Zr;var Kr={},Mw={get exports(){return Kr},set exports(e){Kr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i,s){s.updateLocale=function(o,u){var l=s.Ls[o];if(l)return(u?Object.keys(u):[]).forEach(function(d){l[d]=u[d]}),l}}})})(Mw);const Iw=Kr;var Jr={},Aw={get exports(){return Jr},set exports(e){Jr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){var r="minute",i=/[+-]\d\d(?::?\d\d)?/g,s=/([+-]|\d\d)/g;return function(o,u,l){var d=u.prototype;l.utc=function(C){var S={date:C,utc:!0,args:arguments};return new u(S)},d.utc=function(C){var S=l(this.toDate(),{locale:this.$L,utc:!0});return C?S.add(this.utcOffset(),r):S},d.local=function(){return l(this.toDate(),{locale:this.$L,utc:!1})};var c=d.parse;d.parse=function(C){C.utc&&(this.$u=!0),this.$utils().u(C.$offset)||(this.$offset=C.$offset),c.call(this,C)};var f=d.init;d.init=function(){if(this.$u){var C=this.$d;this.$y=C.getUTCFullYear(),this.$M=C.getUTCMonth(),this.$D=C.getUTCDate(),this.$W=C.getUTCDay(),this.$H=C.getUTCHours(),this.$m=C.getUTCMinutes(),this.$s=C.getUTCSeconds(),this.$ms=C.getUTCMilliseconds()}else f.call(this)};var g=d.utcOffset;d.utcOffset=function(C,S){var I=this.$utils().u;if(I(C))return this.$u?0:I(this.$offset)?g.call(this):this.$offset;if(typeof C=="string"&&(C=function(L){L===void 0&&(L="");var z=L.match(i);if(!z)return null;var A=(""+z[0]).match(s)||["-",0,0],N=A[0],U=60*+A[1]+ +A[2];return U===0?0:N==="+"?U:-U}(C),C===null))return this;var $=Math.abs(C)<=16?60*C:C,G=this;if(S)return G.$offset=$,G.$u=C===0,G;if(C!==0){var q=this.$u?this.toDate().getTimezoneOffset():-1*this.utcOffset();(G=this.local().add($+q,r)).$offset=$,G.$x.$localOffset=q}else G=this.utc();return G};var h=d.format;d.format=function(C){var S=C||(this.$u?"YYYY-MM-DDTHH:mm:ss[Z]":"");return h.call(this,S)},d.valueOf=function(){var C=this.$utils().u(this.$offset)?0:this.$offset+(this.$x.$localOffset||this.$d.getTimezoneOffset());return this.$d.valueOf()-6e4*C},d.isUTC=function(){return!!this.$u},d.toISOString=function(){return this.toDate().toISOString()},d.toString=function(){return this.toDate().toUTCString()};var m=d.toDate;d.toDate=function(C){return C==="s"&&this.$offset?l(this.format("YYYY-MM-DD HH:mm:ss:SSS")).toDate():m.call(this)};var w=d.diff;d.diff=function(C,S,I){if(C&&this.$u===C.$u)return w.call(this,C,S,I);var $=this.local(),G=l(C).local();return w.call($,G,S,I)}}})})(Aw);const $w=Jr;var Hr={},zw={get exports(){return Hr},set exports(e){Hr=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){i.prototype.weekday=function(s){var o=this.$locale().weekStart||0,u=this.$W,l=(u<o?u+7:u)-o;return this.$utils().u(s)?l:this.subtract(l,"day").add(s,"day")}}})})(zw);const Ew=Hr;var ei={},Lw={get exports(){return ei},set exports(e){ei=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){var r="week",i="year";return function(s,o,u){var l=o.prototype;l.week=function(d){if(d===void 0&&(d=null),d!==null)return this.add(7*(d-this.week()),"day");var c=this.$locale().yearStart||1;if(this.month()===11&&this.date()>25){var f=u(this).startOf(i).add(1,i).date(c),g=u(this).endOf(r);if(f.isBefore(g))return 1}var h=u(this).startOf(i).date(c).startOf(r).subtract(1,"millisecond"),m=this.diff(h,r,!0);return m<0?u(this).startOf("week").week():Math.ceil(m)},l.weeks=function(d){return d===void 0&&(d=null),this.week(d)}}})})(Lw);const Pw=ei;var ti={},Ow={get exports(){return ti},set exports(e){ti=e}};(function(e,t){(function(r,i){e.exports=i()})(H,function(){return function(r,i){i.prototype.weekYear=function(){var s=this.month(),o=this.week(),u=this.year();return o===1&&s===11?u+1:s===0&&o>=52?u-1:u}}})})(Ow);const Vw=ti;j.extend(TC),j.extend(DC),j.extend(IC),j.extend($C),j.extend(EC),j.extend(PC),j.extend(VC),j.extend(NC),j.extend(qC),j.extend(WC),j.extend(YC),j.extend(KC),j.extend(HC),j.extend(tw),j.extend(rw),j.extend(aw),j.extend(QC),j.extend(XC),j.extend(ow),j.extend(uw),j.extend(cw),j.extend(hw),j.extend(gw),j.extend(bw),j.extend(vw),j.extend(Cw),j.extend(_w),j.extend(Tw),j.extend(Dw),j.extend(Iw),j.extend($w),j.extend(Pw),j.extend(Vw),j.extend(Ew),j.tz.setDefault("UTC");const Bw=()=>Promise.resolve().then(()=>Zo).then(({version:e})=>(console.log(`[@devtable/dashboard] version: ${e}`),e));D.ContentModel=It,D.ContentModelContextProvider=yn,D.ContextModel=gs,D.DashboardEditor=wC,D.DashboardFilterType=ar,D.DashboardMode=Ya,D.DashboardModel=Ts,D.DashboardViewEditor=Qa,D.DashboardViewRender=nn,D.EViewComponentType=K,D.FilterModel=or,D.FiltersModel=as,D.FullScreenPanelContext=xn,D.LayoutStateContext=Ze,D.ModelContextProvider=bn,D.Panel=tn,D.PanelContextProvider=vn,D.PanelModel=ms,D.PanelsModel=ys,D.QueriesModel=ps,D.QueryModel=cs,D.ReadOnlyDashboard=_C,D.SQLSnippetModel=hs,D.SQLSnippetsModel=fs,D.ViewComponentTypeBackground=Ra,D.ViewComponentTypeColor=wy,D.ViewComponentTypeName=Cy,D.ViewModel=ws,D.ViewsModel=_s,D.applyPartialDashboard=Lv,D.createContentModel=Ss,D.createDashboardModel=hr,D.createDashboardViewsModel=pr,D.getInitialFiltersPayload=ss,D.getNewPanel=bs,D.getVersion=Bw,D.initialDashboardContent=_y,D.useContentModelContext=F,D.useFullScreenPanelContext=Ei,D.useModelContext=me,D.usePanelContext=Ce,D.useTopLevelServices=fr,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});