"use strict";var rr=Object.defineProperty,nr=Object.defineProperties;var or=Object.getOwnPropertyDescriptors;var Te=Object.getOwnPropertySymbols;var ir=Object.prototype.hasOwnProperty,ar=Object.prototype.propertyIsEnumerable;var Ie=(R,y,d)=>y in R?rr(R,y,{enumerable:!0,configurable:!0,writable:!0,value:d}):R[y]=d,A=(R,y)=>{for(var d in y||(y={}))ir.call(y,d)&&Ie(R,d,y[d]);if(Te)for(var d of Te(y))ar.call(y,d)&&Ie(R,d,y[d]);return R},Ae=(R,y)=>nr(R,or(y));(self.webpackChunk_grafana_ui=self.webpackChunk_grafana_ui||[]).push([[462],{"./src/components/Monaco/ReactMonacoEditor.tsx":function(R,y,d){d.r(y),d.d(y,{ReactMonacoEditor:function(){return K}});function ke(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function fe(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),r.push.apply(r,n)}return r}function de(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?fe(Object(r),!0).forEach(function(n){ke(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):fe(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}function xe(e,t){if(e==null)return{};var r={},n=Object.keys(e),i,a;for(a=0;a<n.length;a++)i=n[a],!(t.indexOf(i)>=0)&&(r[i]=e[i]);return r}function De(e,t){if(e==null)return{};var r=xe(e,t),n,i;if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(i=0;i<a.length;i++)n=a[i],!(t.indexOf(n)>=0)&&(!Object.prototype.propertyIsEnumerable.call(e,n)||(r[n]=e[n]))}return r}function ze(e,t){return Ne(e)||Le(e,t)||Ue(e,t)||Be()}function Ne(e){if(Array.isArray(e))return e}function Le(e,t){if(!(typeof Symbol=="undefined"||!(Symbol.iterator in Object(e)))){var r=[],n=!0,i=!1,a=void 0;try{for(var s=e[Symbol.iterator](),m;!(n=(m=s.next()).done)&&(r.push(m.value),!(t&&r.length===t));n=!0);}catch(g){i=!0,a=g}finally{try{!n&&s.return!=null&&s.return()}finally{if(i)throw a}}return r}}function Ue(e,t){if(!!e){if(typeof e=="string")return pe(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if(r==="Object"&&e.constructor&&(r=e.constructor.name),r==="Map"||r==="Set")return Array.from(e);if(r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return pe(e,t)}}function pe(e,t){(t==null||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function Be(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Fe(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function ge(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),r.push.apply(r,n)}return r}function ve(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?ge(Object(r),!0).forEach(function(n){Fe(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ge(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}function He(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return function(n){return t.reduceRight(function(i,a){return a(i)},n)}}function k(e){return function t(){for(var r=this,n=arguments.length,i=new Array(n),a=0;a<n;a++)i[a]=arguments[a];return i.length>=e.length?e.apply(this,i):function(){for(var s=arguments.length,m=new Array(s),g=0;g<s;g++)m[g]=arguments[g];return t.apply(r,[].concat(i,m))}}}function F(e){return{}.toString.call(e).includes("Object")}function Ve(e){return!Object.keys(e).length}function x(e){return typeof e=="function"}function qe(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function We(e,t){return F(t)||P("changeType"),Object.keys(t).some(function(r){return!qe(e,r)})&&P("changeField"),t}function Ke(e){x(e)||P("selectorType")}function Ye(e){x(e)||F(e)||P("handlerType"),F(e)&&Object.values(e).some(function(t){return!x(t)})&&P("handlersType")}function Ge(e){e||P("initialIsRequired"),F(e)||P("initialType"),Ve(e)&&P("initialContent")}function Ze(e,t){throw new Error(e[t]||e.default)}var Je={initialIsRequired:"initial state is required",initialType:"initial state should be an object",initialContent:"initial state shouldn't be an empty object",handlerType:"handler should be an object or a function",handlersType:"all handlers should be a functions",selectorType:"selector should be a function",changeType:"provided value of changes should be an object",changeField:'it seams you want to change a field in the state which is not specified in the "initial" state',default:"an unknown error accured in `state-local` package"},P=k(Ze)(Je),H={changes:We,selector:Ke,handler:Ye,initial:Ge};function Qe(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};H.initial(e),H.handler(t);var r={current:e},n=k(et)(r,t),i=k($e)(r),a=k(H.changes)(e),s=k(Xe)(r);function m(){var b=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(I){return I};return H.selector(b),b(r.current)}function g(b){He(n,i,a,s)(b)}return[m,g]}function Xe(e,t){return x(t)?t(e.current):t}function $e(e,t){return e.current=ve(ve({},e.current),t),t}function et(e,t,r){return x(t)?t(e.current):Object.keys(r).forEach(function(n){var i;return(i=t[n])===null||i===void 0?void 0:i.call(t,e.current[n])}),r}var tt={create:Qe},rt=tt,nt={paths:{vs:"https://cdn.jsdelivr.net/npm/monaco-editor@0.33.0/min/vs"}},ot=nt;function it(e){return function t(){for(var r=this,n=arguments.length,i=new Array(n),a=0;a<n;a++)i[a]=arguments[a];return i.length>=e.length?e.apply(this,i):function(){for(var s=arguments.length,m=new Array(s),g=0;g<s;g++)m[g]=arguments[g];return t.apply(r,[].concat(i,m))}}}var at=it;function ct(e){return{}.toString.call(e).includes("Object")}var ut=ct;function st(e){return e||he("configIsRequired"),ut(e)||he("configType"),e.urls?(lt(),{paths:{vs:e.urls.monacoBase}}):e}function lt(){console.warn(me.deprecation)}function ft(e,t){throw new Error(e[t]||e.default)}var me={configIsRequired:"the configuration object is required",configType:"the configuration object should be an object",default:"an unknown error accured in `@monaco-editor/loader` package",deprecation:`Deprecation warning!
    You are using deprecated way of configuration.

    Instead of using
      monaco.config({ urls: { monacoBase: '...' } })
    use
      monaco.config({ paths: { vs: '...' } })

    For more please check the link https://github.com/suren-atoyan/monaco-loader#config
  `},he=at(ft)(me),dt={config:st},pt=dt,gt=function(){for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];return function(i){return r.reduceRight(function(a,s){return s(a)},i)}},vt=gt;function ye(e,t){return Object.keys(t).forEach(function(r){t[r]instanceof Object&&e[r]&&Object.assign(t[r],ye(e[r],t[r]))}),de(de({},e),t)}var mt=ye,ht={type:"cancelation",msg:"operation is manually canceled"};function yt(e){var t=!1,r=new Promise(function(n,i){e.then(function(a){return t?i(ht):n(a)}),e.catch(i)});return r.cancel=function(){return t=!0},r}var Z=yt,bt=rt.create({config:ot,isInitialized:!1,resolve:null,reject:null,monaco:null}),be=ze(bt,2),D=be[0],V=be[1];function Mt(e){var t=pt.config(e),r=t.monaco,n=De(t,["monaco"]);V(function(i){return{config:mt(i.config,n),monaco:r}})}function Ot(){var e=D(function(t){var r=t.monaco,n=t.isInitialized,i=t.resolve;return{monaco:r,isInitialized:n,resolve:i}});if(!e.isInitialized){if(V({isInitialized:!0}),e.monaco)return e.resolve(e.monaco),Z(J);if(window.monaco&&window.monaco.editor)return Me(window.monaco),e.resolve(window.monaco),Z(J);vt(wt,jt)(Rt)}return Z(J)}function wt(e){return document.body.appendChild(e)}function Et(e){var t=document.createElement("script");return e&&(t.src=e),t}function jt(e){var t=D(function(n){var i=n.config,a=n.reject;return{config:i,reject:a}}),r=Et("".concat(t.config.paths.vs,"/loader.js"));return r.onload=function(){return e()},r.onerror=t.reject,r}function Rt(){var e=D(function(r){var n=r.config,i=r.resolve,a=r.reject;return{config:n,resolve:i,reject:a}}),t=window.require;t.config(e.config),t(["vs/editor/editor.main"],function(r){Me(r),e.resolve(r)},function(r){e.reject(r)})}function Me(e){D().monaco||V({monaco:e})}function Ct(){return D(function(e){var t=e.monaco;return t})}var J=new Promise(function(e,t){return V({resolve:e,reject:t})}),Pt={config:Mt,init:Ot,__getMonacoInstance:Ct},T=Pt,c=d("../../../yarn/cache/react-npm-17.0.2-99ba37d931-b254cc17ce.zip/node_modules/react/index.js"),St=d("../../../yarn/cache/prop-types-npm-15.7.2-d7a04f2274-5eef82fdda.zip/node_modules/prop-types/index.js"),o=d.n(St);function Q(){return Q=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},Q.apply(this,arguments)}const _t={display:"flex",height:"100%",width:"100%",justifyContent:"center",alignItems:"center"};function Tt({content:e}){return c.createElement("div",{style:_t},e)}var It=Tt,X={wrapper:{display:"flex",position:"relative",textAlign:"initial"},fullWidth:{width:"100%"},hide:{display:"none"}};function Oe({width:e,height:t,isEditorReady:r,loading:n,_ref:i,className:a,wrapperProps:s}){return c.createElement("section",Q({style:Ae(A({},X.wrapper),{width:e,height:t})},s),!r&&c.createElement(It,{content:n}),c.createElement("div",{ref:i,style:A(A({},X.fullWidth),!r&&X.hide),className:a}))}Oe.propTypes={width:o().oneOfType([o().number,o().string]).isRequired,height:o().oneOfType([o().number,o().string]).isRequired,loading:o().oneOfType([o().element,o().string]).isRequired,isEditorReady:o().bool.isRequired,className:o().string,wrapperProps:o().object};var At=Oe,kt=(0,c.memo)(At),we=kt;function xt(e){(0,c.useEffect)(e,[])}var $=xt;function Dt(e,t,r=!0){const n=(0,c.useRef)(!0);(0,c.useEffect)(n.current||!r?()=>{n.current=!1}:e,t)}var j=Dt;function z(){}function q(e,t,r,n){return zt(e,n)||Nt(e,t,r,n)}function zt(e,t){return e.editor.getModel(Ee(e,t))}function Nt(e,t,r,n){return e.editor.createModel(t,r,n&&Ee(e,n))}function Ee(e,t){return e.Uri.parse(t)}function Lt(e){return e===void 0}function ee({original:e,modified:t,language:r,originalLanguage:n,modifiedLanguage:i,originalModelPath:a,modifiedModelPath:s,keepCurrentOriginalModel:m,keepCurrentModifiedModel:g,theme:b,loading:I,options:C,height:re,width:ne,className:oe,wrapperProps:ie,beforeMount:ae,onMount:ce}){const[w,N]=(0,c.useState)(!1),[_,v]=(0,c.useState)(!0),E=(0,c.useRef)(null),M=(0,c.useRef)(null),Y=(0,c.useRef)(null),O=(0,c.useRef)(ce),u=(0,c.useRef)(ae);$(()=>{const l=T.init();return l.then(h=>(M.current=h)&&v(!1)).catch(h=>(h==null?void 0:h.type)!=="cancelation"&&console.error("Monaco initialization: error:",h)),()=>E.current?ue():l.cancel()}),j(()=>{const l=E.current.getModifiedEditor();l.getOption(M.current.editor.EditorOption.readOnly)?l.setValue(t):t!==l.getValue()&&(l.executeEdits("",[{range:l.getModel().getFullModelRange(),text:t,forceMoveMarkers:!0}]),l.pushUndoStop())},[t],w),j(()=>{E.current.getModel().original.setValue(e)},[e],w),j(()=>{const{original:l,modified:h}=E.current.getModel();M.current.editor.setModelLanguage(l,n||r),M.current.editor.setModelLanguage(h,i||r)},[r,n,i],w),j(()=>{M.current.editor.setTheme(b)},[b],w),j(()=>{E.current.updateOptions(C)},[C],w);const L=(0,c.useCallback)(()=>{u.current(M.current);const l=q(M.current,e,n||r,a),h=q(M.current,t,i||r,s);E.current.setModel({original:l,modified:h})},[r,t,i,e,n,a,s]),G=(0,c.useCallback)(()=>{E.current=M.current.editor.createDiffEditor(Y.current,A({automaticLayout:!0},C)),L(),M.current.editor.setTheme(b),N(!0)},[C,b,L]);(0,c.useEffect)(()=>{w&&O.current(E.current,M.current)},[w]),(0,c.useEffect)(()=>{!_&&!w&&G()},[_,w,G]);function ue(){const l=E.current.getModel();if(!m){var h;(h=l.original)===null||h===void 0||h.dispose()}if(!g){var U;(U=l.modified)===null||U===void 0||U.dispose()}E.current.dispose()}return c.createElement(we,{width:ne,height:re,isEditorReady:w,loading:I,_ref:Y,className:oe,wrapperProps:ie})}ee.propTypes={original:o().string,modified:o().string,language:o().string,originalLanguage:o().string,modifiedLanguage:o().string,originalModelPath:o().string,modifiedModelPath:o().string,keepCurrentOriginalModel:o().bool,keepCurrentModifiedModel:o().bool,theme:o().string,loading:o().oneOfType([o().element,o().string]),options:o().object,width:o().oneOfType([o().number,o().string]),height:o().oneOfType([o().number,o().string]),className:o().string,wrapperProps:o().object,beforeMount:o().func,onMount:o().func},ee.defaultProps={theme:"light",loading:"Loading...",options:{},keepCurrentOriginalModel:!1,keepCurrentModifiedModel:!1,width:"100%",height:"100%",wrapperProps:{},beforeMount:z,onMount:z};var Ut=ee,ur=(0,c.memo)(Ut),sr=null;function Bt(){const[e,t]=(0,c.useState)(T.__getMonacoInstance());return $(()=>{let r;return e||(r=T.init(),r.then(n=>{t(n)})),()=>{var n;return(n=r)===null||n===void 0?void 0:n.cancel()}}),e}var Ft=Bt;function Ht(e){const t=(0,c.useRef)();return(0,c.useEffect)(()=>{t.current=e},[e]),t.current}var Vt=Ht;const W=new Map;function te({defaultValue:e,defaultLanguage:t,defaultPath:r,value:n,language:i,path:a,theme:s,line:m,loading:g,options:b,overrideServices:I,saveViewState:C,keepCurrentModel:re,width:ne,height:oe,className:ie,wrapperProps:ae,beforeMount:ce,onMount:w,onChange:N,onValidate:_}){const[v,E]=(0,c.useState)(!1),[M,Y]=(0,c.useState)(!0),O=(0,c.useRef)(null),u=(0,c.useRef)(null),L=(0,c.useRef)(null),G=(0,c.useRef)(w),ue=(0,c.useRef)(ce),l=(0,c.useRef)(null),h=(0,c.useRef)(n),U=Vt(a),Se=(0,c.useRef)(!1);$(()=>{const f=T.init();return f.then(p=>(O.current=p)&&Y(!1)).catch(p=>(p==null?void 0:p.type)!=="cancelation"&&console.error("Monaco initialization: error:",p)),()=>u.current?tr():f.cancel()}),j(()=>{const f=q(O.current,e||n,t||i,a);f!==u.current.getModel()&&(C&&W.set(U,u.current.saveViewState()),u.current.setModel(f),C&&u.current.restoreViewState(W.get(a)))},[a],v),j(()=>{u.current.updateOptions(b)},[b],v),j(()=>{u.current.getOption(O.current.editor.EditorOption.readOnly)?u.current.setValue(n):n!==u.current.getValue()&&(u.current.executeEdits("",[{range:u.current.getModel().getFullModelRange(),text:n,forceMoveMarkers:!0}]),u.current.pushUndoStop())},[n],v),j(()=>{O.current.editor.setModelLanguage(u.current.getModel(),i)},[i],v),j(()=>{Lt(m)||u.current.revealLine(m)},[m],v),j(()=>{O.current.editor.setTheme(s)},[s],v);const _e=(0,c.useCallback)(()=>{if(!Se.current){ue.current(O.current);const f=a||r,p=q(O.current,n||e,t||i,f);u.current=O.current.editor.create(L.current,A({model:p,automaticLayout:!0},b),I),C&&u.current.restoreViewState(W.get(f)),O.current.editor.setTheme(s),E(!0),Se.current=!0}},[e,t,r,n,i,a,b,I,C,s]);(0,c.useEffect)(()=>{v&&G.current(u.current,O.current)},[v]),(0,c.useEffect)(()=>{!M&&!v&&_e()},[M,v,_e]),h.current=n,(0,c.useEffect)(()=>{if(v&&N){var f,p;(f=l.current)===null||f===void 0||f.dispose(),l.current=(p=u.current)===null||p===void 0?void 0:p.onDidChangeModelContent(B=>{N(u.current.getValue(),B)})}},[v,N]),(0,c.useEffect)(()=>{if(v){const f=O.current.editor.onDidChangeMarkers(p=>{var B;const se=(B=u.current.getModel())===null||B===void 0?void 0:B.uri;if(se&&p.find(le=>le.path===se.path)){const le=O.current.editor.getModelMarkers({resource:se});_==null||_(le)}});return()=>{f==null||f.dispose()}}},[v,_]);function tr(){var f;if((f=l.current)===null||f===void 0||f.dispose(),re)C&&W.set(a,u.current.saveViewState());else{var p;(p=u.current.getModel())===null||p===void 0||p.dispose()}u.current.dispose()}return c.createElement(we,{width:ne,height:oe,isEditorReady:v,loading:g,_ref:L,className:ie,wrapperProps:ae})}te.propTypes={defaultValue:o().string,defaultPath:o().string,defaultLanguage:o().string,value:o().string,language:o().string,path:o().string,theme:o().string,line:o().number,loading:o().oneOfType([o().element,o().string]),options:o().object,overrideServices:o().object,saveViewState:o().bool,keepCurrentModel:o().bool,width:o().oneOfType([o().number,o().string]),height:o().oneOfType([o().number,o().string]),className:o().string,wrapperProps:o().object,beforeMount:o().func,onMount:o().func,onChange:o().func,onValidate:o().func},te.defaultProps={theme:"light",loading:"Loading...",options:{},overrideServices:{},saveViewState:!0,keepCurrentModel:!1,width:"100%",height:"100%",wrapperProps:{},beforeMount:z,onMount:z,onValidate:z};var qt=te,Wt=(0,c.memo)(qt),Kt=Wt,Yt=d("./src/themes/ThemeContext.tsx"),Gt=d("../../../yarn/cache/tinycolor2-npm-1.6.0-8df41252c6-6df4d07fce.zip/node_modules/tinycolor2/esm/tinycolor.js");function Zt(e){if(e===void 0)return{};{const t={"editor.background":e.components.input.background,"minimap.background":e.colors.background.secondary};return Object.keys(t).forEach(r=>{t[r]=S(t[r])}),t}}function S(e){return(0,Gt.Z)(e).toHexString()}function je(e,t){const r=Zt(t);e.editor.defineTheme("grafana-dark",{base:"vs-dark",inherit:!0,colors:r,rules:[{token:"predefined",foreground:S(t==null?void 0:t.visualization.getColorByName("purple"))},{token:"operator",foreground:S(t==null?void 0:t.visualization.getColorByName("orange"))},{token:"tag",foreground:S(t==null?void 0:t.visualization.getColorByName("green"))}]}),e.editor.defineTheme("grafana-light",{base:"vs",inherit:!0,colors:r,rules:[{token:"predefined",foreground:S(t==null?void 0:t.visualization.getColorByName("purple"))},{token:"operator",foreground:S(t==null?void 0:t.visualization.getColorByName("orange"))},{token:"tag",foreground:S(t==null?void 0:t.visualization.getColorByName("green"))}]})}var Jt=Object.defineProperty,Re=Object.getOwnPropertySymbols,Qt=Object.prototype.hasOwnProperty,Xt=Object.prototype.propertyIsEnumerable,Ce=(e,t,r)=>t in e?Jt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,$t=(e,t)=>{for(var r in t||(t={}))Qt.call(t,r)&&Ce(e,r,t[r]);if(Re)for(var r of Re(t))Xt.call(t,r)&&Ce(e,r,t[r]);return e};let Pe=!1;function er(){var e;Pe||(T.config({paths:{vs:((e=window.__grafana_public_path__)!=null?e:"public/")+"lib/monaco/min/vs"}}),Pe=!0,T.init().then(t=>{je(t)}))}const K=e=>{const t=(0,Yt.l4)(),r=Ft();(0,c.useEffect)(()=>{r!=null&&je(r,t)},[r,t]),er();const n=t.isDark?"grafana-dark":"grafana-light";return c.createElement(Kt,$t({theme:n},e))};try{K.displayName="ReactMonacoEditor",K.__docgenInfo={description:"",displayName:"ReactMonacoEditor",props:{}},typeof STORYBOOK_REACT_CLASSES!="undefined"&&(STORYBOOK_REACT_CLASSES["src/components/Monaco/ReactMonacoEditor.tsx#ReactMonacoEditor"]={docgenInfo:K.__docgenInfo,name:"ReactMonacoEditor",path:"src/components/Monaco/ReactMonacoEditor.tsx#ReactMonacoEditor"})}catch(e){}}}]);
