"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[2462],{13860:(e,n,t)=>{function r(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function o(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,r)}return t}function i(e){for(var n=1;ne.length)&&(n=e.length);for(var t=0,r=new Array(n);t=e.length?e.apply(this,o):function(){for(var e=arguments.length,r=new Array(e),i=0;ive});var p=d((function(e,n){throw new Error(e[n]||e.default)}))({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"}),h={changes:function(e,n){return f(n)||p("changeType"),Object.keys(n).some((function(n){return t=e,r=n,!Object.prototype.hasOwnProperty.call(t,r);var t,r}))&&p("changeField"),n},selector:function(e){g(e)||p("selectorType")},handler:function(e){g(e)||f(e)||p("handlerType"),f(e)&&Object.values(e).some((function(e){return!g(e)}))&&p("handlersType")},initial:function(e){var n;e||p("initialIsRequired"),f(e)||p("initialType"),n=e,Object.keys(n).length||p("initialContent")}};function v(e,n){return g(n)?n(e.current):n}function m(e,n){return e.current=l(l({},e.current),n),n}function y(e,n,t){return g(n)?n(e.current):Object.keys(t).forEach((function(t){var r;return null===(r=n[t])||void 0===r?void 0:r.call(n,e.current[t])})),t}var b={create:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};h.initial(e),h.handler(n);var t={current:e},r=d(y)(t,n),o=d(m)(t),i=d(h.changes)(e),a=d(v)(t);function c(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:function(e){return e};return h.selector(e),e(t.current)}function u(e){s(r,o,i,a)(e)}return[c,u]}};const w=b;const O={paths:{vs:"https://cdn.jsdelivr.net/npm/monaco-editor@0.28.1/min/vs"}};const j=function(e){return{}.toString.call(e).includes("Object")};var M={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!\n You are using deprecated way of configuration.\n\n Instead of using\n monaco.config({ urls: { monacoBase: '...' } })\n use\n monaco.config({ paths: { vs: '...' } })\n\n For more please check the link https://github.com/suren-atoyan/monaco-loader#config\n "},k=function(e){return function n(){for(var t=this,r=arguments.length,o=new Array(r),i=0;i=e.length?e.apply(this,o):function(){for(var e=arguments.length,r=new Array(e),i=0;i{r.current=!1}:e,n)};function te(){}function re(e,n,t,r){return function(e,n){return e.editor.getModel(oe(e,n))}(e,r)||function(e,n,t,r){return e.editor.createModel(n,t,r&&oe(e,r))}(e,n,t,r)}function oe(e,n){return e.Uri.parse(n)}function ie({original:e,modified:n,language:t,originalLanguage:r,modifiedLanguage:o,originalModelPath:i,modifiedModelPath:a,keepCurrentOriginalModel:c,keepCurrentModifiedModel:u,theme:l,loading:s,options:d,height:f,width:g,className:p,wrapperProps:h,beforeMount:v,onMount:m}){const[y,b]=(0,W.useState)(!1),[w,O]=(0,W.useState)(!0),j=(0,W.useRef)(null),M=(0,W.useRef)(null),k=(0,W.useRef)(null),P=(0,W.useRef)(m),E=(0,W.useRef)(v);ee((()=>{const e=U.init();return e.then((e=>(M.current=e)&&O(!1))).catch((e=>"cancelation"!==(null==e?void 0:e.type)&&console.error("Monaco initialization: error:",e))),()=>j.current?function(){const e=j.current.getModel();var n,t;c||null===(n=e.original)||void 0===n||n.dispose();u||null===(t=e.modified)||void 0===t||t.dispose();j.current.dispose()}():e.cancel()})),ne((()=>{const e=j.current.getModifiedEditor();e.getOption(M.current.editor.EditorOption.readOnly)?e.setValue(n):n!==e.getValue()&&(e.executeEdits("",[{range:e.getModel().getFullModelRange(),text:n,forceMoveMarkers:!0}]),e.pushUndoStop())}),[n],y),ne((()=>{j.current.getModel().original.setValue(e)}),[e],y),ne((()=>{const{original:e,modified:n}=j.current.getModel();M.current.editor.setModelLanguage(e,r||t),M.current.editor.setModelLanguage(n,o||t)}),[t,r,o],y),ne((()=>{M.current.editor.setTheme(l)}),[l],y),ne((()=>{j.current.updateOptions(d)}),[d],y);const R=(0,W.useCallback)((()=>{E.current(M.current);const c=re(M.current,e,r||t,i),u=re(M.current,n,o||t,a);j.current.setModel({original:c,modified:u})}),[t,n,o,e,r,i,a]),T=(0,W.useCallback)((()=>{j.current=M.current.editor.createDiffEditor(k.current,{automaticLayout:!0,...d}),R(),M.current.editor.setTheme(l),b(!0)}),[d,l,R]);return(0,W.useEffect)((()=>{y&&P.current(j.current,M.current)}),[y]),(0,W.useEffect)((()=>{!w&&!y&&T()}),[w,y,T]),W.createElement(Z,{width:g,height:f,isEditorReady:y,loading:s,_ref:k,className:p,wrapperProps:h})}ie.propTypes={original:$().string,modified:$().string,language:$().string,originalLanguage:$().string,modifiedLanguage:$().string,originalModelPath:$().string,modifiedModelPath:$().string,keepCurrentOriginalModel:$().bool,keepCurrentModifiedModel:$().bool,theme:$().string,loading:$().oneOfType([$().element,$().string]),options:$().object,width:$().oneOfType([$().number,$().string]),height:$().oneOfType([$().number,$().string]),className:$().string,wrapperProps:$().object,beforeMount:$().func,onMount:$().func},ie.defaultProps={theme:"light",loading:"Loading...",options:{},keepCurrentOriginalModel:!1,keepCurrentModifiedModel:!1,width:"100%",height:"100%",wrapperProps:{},beforeMount:te,onMount:te};const ae=function(){const[e,n]=(0,W.useState)(U.__getMonacoInstance());return ee((()=>{let t;return e||(t=U.init(),t.then((e=>{n(e)}))),()=>{var e;return null===(e=t)||void 0===e?void 0:e.cancel()}})),e};const ce=function(e){const n=(0,W.useRef)();return(0,W.useEffect)((()=>{n.current=e}),[e]),n.current},ue=new Map;function le({defaultValue:e,defaultLanguage:n,defaultPath:t,value:r,language:o,path:i,theme:a,line:c,loading:u,options:l,overrideServices:s,saveViewState:d,keepCurrentModel:f,width:g,height:p,className:h,wrapperProps:v,beforeMount:m,onMount:y,onChange:b,onValidate:w}){const[O,j]=(0,W.useState)(!1),[M,k]=(0,W.useState)(!0),P=(0,W.useRef)(null),E=(0,W.useRef)(null),R=(0,W.useRef)(null),T=(0,W.useRef)(y),C=(0,W.useRef)(m),S=(0,W.useRef)(null),V=(0,W.useRef)(r),I=ce(i);ee((()=>{const e=U.init();return e.then((e=>(P.current=e)&&k(!1))).catch((e=>"cancelation"!==(null==e?void 0:e.type)&&console.error("Monaco initialization: error:",e))),()=>E.current?function(){var e,n;null===(e=S.current)||void 0===e||e.dispose(),f?d&&ue.set(i,E.current.saveViewState()):null===(n=E.current.getModel())||void 0===n||n.dispose();E.current.dispose()}():e.cancel()})),ne((()=>{const t=re(P.current,e||r,n||o,i);t!==E.current.getModel()&&(d&&ue.set(I,E.current.saveViewState()),E.current.setModel(t),d&&E.current.restoreViewState(ue.get(i)))}),[i],O),ne((()=>{E.current.updateOptions(l)}),[l],O),ne((()=>{E.current.getOption(P.current.editor.EditorOption.readOnly)?E.current.setValue(r):r!==E.current.getValue()&&(E.current.executeEdits("",[{range:E.current.getModel().getFullModelRange(),text:r,forceMoveMarkers:!0}]),E.current.pushUndoStop())}),[r],O),ne((()=>{P.current.editor.setModelLanguage(E.current.getModel(),o)}),[o],O),ne((()=>{void 0!==c&&E.current.revealLine(c)}),[c],O),ne((()=>{P.current.editor.setTheme(a)}),[a],O);const N=(0,W.useCallback)((()=>{C.current(P.current);const c=i||t,u=re(P.current,r||e,n||o,c);E.current=P.current.editor.create(R.current,{model:u,automaticLayout:!0,...l},s),d&&E.current.restoreViewState(ue.get(c)),P.current.editor.setTheme(a),j(!0)}),[e,n,t,r,o,i,l,s,d,a]);return(0,W.useEffect)((()=>{O&&T.current(E.current,P.current)}),[O]),(0,W.useEffect)((()=>{!M&&!O&&N()}),[M,O,N]),V.current=r,(0,W.useEffect)((()=>{var e,n;O&&b&&(null===(e=S.current)||void 0===e||e.dispose(),S.current=null===(n=E.current)||void 0===n?void 0:n.onDidChangeModelContent((e=>{const n=E.current.getValue();V.current!==n&&b(n,e)})))}),[O,b]),(0,W.useEffect)((()=>{if(O){const e=P.current.editor.onDidChangeMarkers((e=>{var n;const t=null===(n=E.current.getModel())||void 0===n?void 0:n.uri;if(t){if(e.find((e=>e.path===t.path))){const e=P.current.editor.getModelMarkers({resource:t});null==w||w(e)}}}));return()=>{null==e||e.dispose()}}}),[O,w]),W.createElement(Z,{width:g,height:p,isEditorReady:O,loading:u,_ref:R,className:h,wrapperProps:v})}le.propTypes={defaultValue:$().string,defaultPath:$().string,defaultLanguage:$().string,value:$().string,language:$().string,path:$().string,theme:$().string,line:$().number,loading:$().oneOfType([$().element,$().string]),options:$().object,overrideServices:$().object,saveViewState:$().bool,keepCurrentModel:$().bool,width:$().oneOfType([$().number,$().string]),height:$().oneOfType([$().number,$().string]),className:$().string,wrapperProps:$().object,beforeMount:$().func,onMount:$().func,onChange:$().func,onValidate:$().func},le.defaultProps={theme:"light",loading:"Loading...",options:{},overrideServices:{},saveViewState:!0,keepCurrentModel:!1,width:"100%",height:"100%",wrapperProps:{},beforeMount:te,onMount:te,onValidate:te};const se=le;const de=(0,W.memo)(se);var fe=t(49268);function ge(e,n){const t=function(e){return void 0===e?{}:{"editor.background":e.components.input.background,"minimap.background":e.colors.background.secondary}}(n);e.editor.defineTheme("grafana-dark",{base:"vs-dark",inherit:!0,colors:t,rules:[{token:"predefined",foreground:null==n?void 0:n.visualization.getColorByName("purple")},{token:"operator",foreground:null==n?void 0:n.visualization.getColorByName("orange")},{token:"tag",foreground:null==n?void 0:n.visualization.getColorByName("green")}]}),e.editor.defineTheme("grafana-light",{base:"vs",inherit:!0,colors:t,rules:[{token:"predefined",foreground:null==n?void 0:n.visualization.getColorByName("purple")},{token:"operator",foreground:null==n?void 0:n.visualization.getColorByName("orange")},{token:"tag",foreground:null==n?void 0:n.visualization.getColorByName("green")}]})}var pe=t(45916);let he=!1;const ve=e=>{const n=(0,fe.l4)(),t=ae();var r;(0,W.useEffect)((()=>{null!==t&&ge(t,n)}),[t,n]),he||(U.config({paths:{vs:(null!==(r=window.__grafana_public_path__)&&void 0!==r?r:"public/")+"lib/monaco/min/vs"}}),he=!0,U.init().then((e=>{ge(e)})));const o=n.isDark?"grafana-dark":"grafana-light";return(0,pe.jsx)(de,Object.assign({theme:o},e))}}}]); //# sourceMappingURL=react-monaco-editor.54510753028e9861ffa6.js.map