var e=require("./index.js"),t=require("react");require("@grafarg/data"),require("react-dom"),require("@grafarg/e2e-selectors"),require("tty"),require("util"),require("os"),require("moment"),require("crypto"),require("jquery"),require("@grafana/aws-sdk");var n=require("monaco-editor/esm/vs/editor/editor.api"),r=require("react-monaco-editor");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=i(t),s=i(r);function a(e,t,n){var r;const i=[];for(const o of t)e&&!o.label.startsWith(e)||i.push(Object.assign(Object.assign({},o),{kind:u(o.kind),range:n,insertText:null!==(r=o.insertText)&&void 0!==r?r:o.label}));return i}function u(t){switch(t){case e.CodeEditorSuggestionItemKind.Method:return n.languages.CompletionItemKind.Method;case e.CodeEditorSuggestionItemKind.Field:return n.languages.CompletionItemKind.Field;case e.CodeEditorSuggestionItemKind.Property:return n.languages.CompletionItemKind.Property;case e.CodeEditorSuggestionItemKind.Constant:return n.languages.CompletionItemKind.Constant;case e.CodeEditorSuggestionItemKind.Text:return n.languages.CompletionItemKind.Text}return n.languages.CompletionItemKind.Text}function l(e,t){if(e&&t)return n.languages.registerCompletionItemProvider(e,{triggerCharacters:["$"],provideCompletionItems:(e,n,r)=>{const i={startLineNumber:n.lineNumber,endLineNumber:n.lineNumber,startColumn:n.column,endColumn:n.column};if("$"===r.triggerCharacter)return i.startColumn=n.column-1,{suggestions:a("$",t(),i)};const o=e.getValueInRange({startLineNumber:n.lineNumber,startColumn:1,endLineNumber:n.lineNumber,endColumn:n.column}),{index:s,prefix:u}=function(e){for(let t=e.length-1;t>0;t--){const n=e.charAt(t);if("$"===n)return{index:t,prefix:e.substring(t)};if(" "===n||"\t"===n||'"'===n||"'"===n)return{index:t+1,prefix:e.substring(t+1)}}return{index:0,prefix:e}}(o);i.startColumn=s+1;const l=a(u,t(),i);return l.length?{suggestions:l}:void 0}})}class d extends o.default.PureComponent{constructor(){super(...arguments),this.getEditorValue=()=>"",this.onBlur=()=>{const{onBlur:e}=this.props;e&&e(this.getEditorValue())},this.editorWillMount=e=>{const{language:t,getSuggestions:n}=this.props;n&&(this.completionCancel=l(t,n))},this.editorDidMount=e=>{const{onSave:t,onEditorDidMount:r}=this.props;this.getEditorValue=()=>e.getValue(),t&&e.addCommand(n.KeyMod.CtrlCmd|n.KeyCode.KEY_S,(()=>{t(this.getEditorValue())})),r&&r(e)}}componentWillUnmount(){this.completionCancel&&this.completionCancel.dispose()}componentDidUpdate(e){const{getSuggestions:t,language:n}=this.props;t&&n!==e.language&&(this.completionCancel&&this.completionCancel.dispose(),this.completionCancel=l(n,t))}render(){var e;const{theme:t,language:n,width:r,height:i,showMiniMap:a,showLineNumbers:u,readOnly:l}=this.props,d=null!==(e=this.props.value)&&void 0!==e?e:"",g={wordWrap:"off",codeLens:!1,minimap:{enabled:d.length>100&&a,renderCharacters:!1},readOnly:l,lineNumbersMinChars:4,lineDecorationsWidth:0,overviewRulerBorder:!1,automaticLayout:!0};return u||(g.glyphMargin=!1,g.folding=!1,g.lineNumbers="off",g.lineDecorationsWidth=5,g.lineNumbersMinChars=0),o.default.createElement("div",{onBlur:this.onBlur},o.default.createElement(s.default,{width:r,height:i,language:n,theme:t.isDark?"vs-dark":"vs-light",value:d,options:g,editorWillMount:this.editorWillMount,editorDidMount:this.editorDidMount}))}}var g=e.withTheme(d);exports.default=g;
//# sourceMappingURL=CodeEditor.production.js.map
