UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

1 lines 6.15 kB
"use strict";(self.webpackChunkmctools_app=self.webpackChunkmctools_app||[]).push([[749],{4749:(t,e,i)=>{i.d(e,{default:()=>u});var o=i(74848),s=i(96540),n=i(58807),r=i(94134),d=i(11641),a=i(20982),l=i(66188),h=i(96997),m=i(22275),c=i(74239);class p extends s.Component{editor;_monaco=null;_decorationIds=[];constructor(t){super(t),this._handleContentUpdated=this._handleContentUpdated.bind(this),this._handleEditorWillMount=this._handleEditorWillMount.bind(this),this._handleEditorDidMount=this._handleEditorDidMount.bind(this),this._zoomIn=this._zoomIn.bind(this),this._zoomOut=this._zoomOut.bind(this),this._clearRun=this._clearRun.bind(this),this.state={fileToEdit:t.file,content:t.initialContent}}static getDerivedStateFromProps(t,e){return null==e?e={fileToEdit:t.file}:t.file!==e.fileToEdit?(e.fileToEdit=t.file,e):null}_handleEditorWillMount(t){this._monaco=t,t.languages.register({id:"mcCommands"}),t.languages.setMonarchTokensProvider("mcCommands",{tokenizer:{root:[[/\[error.*/,"custom-error"],[/\[notice.*/,"custom-notice"],[/\[info.*/,"custom-info"],[/\[[a-zA-Z 0-9:]+\]/,"custom-date"]]}});let e="vs-dark";h.Ay.theme===h.g3.light&&(e="vs");const i=(0,m.kt)();t.editor.defineTheme("mcCommandsTheme"+this.props.roleId,{base:e,inherit:!0,colors:{"editor.foreground":i.foreground4,"editor.background":i.background1,"editorCursor.foreground":"#8B0000","editor.lineHighlightBackground":"#0000FF20","editorLineNumber.foreground":"#008800","editor.selectionBackground":"#88000030","editor.inactiveSelectionBackground":"#88000015"},rules:[{token:"",background:"EDF9FA"},{token:"custom-info",foreground:"FFFFFF"},{token:"custom-error",foreground:"ff11FF",fontStyle:"bold"},{token:"custom-notice",foreground:"FFA500"},{token:"custom-date",foreground:"FF88FF"}]}),t.languages.registerCompletionItemProvider("mcCommands",{provideCompletionItems:(t,e,i,o)=>this._provideCompletionItems(t,e,i,o)})}_provideCompletionItems(t,e,i,o){return this._monaco?{suggestions:[{label:"simpleText",kind:this._monaco.languages.CompletionItemKind.Text,insertText:"simpleText"},{label:"testing",kind:this._monaco.languages.CompletionItemKind.Keyword,insertText:"testing(${1:condition})",insertTextRules:this._monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet},{label:"ifelse",kind:this._monaco.languages.CompletionItemKind.Snippet,insertText:["if (${1:condition}) {","\t$0","} else {","\t","}"].join("\n"),insertTextRules:this._monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,documentation:this.props.intl.formatMessage({id:"project_editor.molang_ed.ifelse_doc"})}]}:{suggestions:[]}}_handleEditorDidMount(t,e){this.editor=t,this._monaco=e,this.editor}_handleContentUpdated(t,e){t&&(t=t.trim(),this.props.onMolangTextChanged&&(t.startsWith("/")||this.props.onMolangTextChanged(t)))}async persist(){let t=!1;if(void 0!==this.editor){const e=this.editor.getValue();void 0!==this.state.fileToEdit&&(t=this.state.fileToEdit.setContent(e)),void 0!==this.state.content&&this.setState({content:e,fileToEdit:this.state.fileToEdit}),void 0!==this.props.onUpdateContent&&this.props.onUpdateContent(e)}return t}_zoomIn(){if(this.editor){let t=this.editor.getAction("editor.action.fontZoomIn");t&&(t.run(),this._updateZoom())}}_zoomOut(){if(this.editor){let t=this.editor.getAction("editor.action.fontZoomOut");t&&(t.run(),this._updateZoom())}}_updateZoom(){if(void 0===this.editor||!this._monaco)return;const t=this.editor.getOption(this._monaco.editor.EditorOption.fontSize);void 0!==t&&(this.props.onUpdatePreferredTextSize?this.props.onUpdatePreferredTextSize(Math.round(t)):this.props.creatorTools.preferredTextSize=Math.round(t))}async _clearRun(){void 0!==this.editor&&(this._decorationIds=this.editor.deltaDecorations(this._decorationIds,[]),this.editor.updateOptions({glyphMargin:!1}))}async _clearContent(){void 0!==this.editor&&(this.editor.updateOptions({glyphMargin:!1}),void 0!==this.state.fileToEdit&&this.state.fileToEdit.setContent(""),void 0!==this.state.content&&this.setState({content:"",fileToEdit:this.state.fileToEdit}),this.editor.setValue(""),void 0!==this.props.onUpdateContent&&this.props.onUpdateContent(""))}render(){let t=(0,o.jsx)(o.Fragment,{}),e="96px",i="33px";if(this.props.fixedHeight&&(e=this.props.fixedHeight+"px",i=this.props.fixedHeight-90+"px"),null!==this.state&&null!==this.state.fileToEdit){let e=this.state.content;void 0===e&&(e=this.props.initialContent),void 0===e&&void 0!==this.state.fileToEdit&&"string"==typeof this.state.fileToEdit.content&&(e=this.state.fileToEdit.content),void 0!==e&&(void 0!==this.props.setActivePersistable&&this.props.setActivePersistable(this),t=(0,o.jsx)(n.Ay,{height:i,theme:"mcCommandsTheme"+this.props.roleId,language:"mcCommands",options:{lineNumbers:"off",minimap:{enabled:!1},glyphMargin:!0,fontSize:this.props.preferredTextSize,readOnly:this.props.readOnly},defaultValue:e,value:e,beforeMount:this._handleEditorWillMount,onMount:this._handleEditorDidMount,onChange:this._handleContentUpdated}))}let s=(0,o.jsx)(o.Fragment,{});return s=(0,o.jsxs)("div",{className:"mcme-toolBarArea",children:[(0,o.jsx)("div",{className:"mcme-title",children:(0,o.jsx)("span",{children:this.props.intl.formatMessage({id:"project_editor.molang_ed.title"})})}),(0,o.jsx)("div",{className:"mcme-toolbar",children:(0,o.jsxs)(r.A,{direction:"row",spacing:.5,"aria-label":this.props.intl.formatMessage({id:"project_editor.molang_ed.toolbar_aria"}),children:[(0,o.jsx)(d.A,{onClick:this._zoomIn,title:this.props.intl.formatMessage({id:"project_editor.molang_ed.zoom_in_title"}),"aria-label":"Zoom in",children:(0,o.jsx)(a.g,{icon:l.KmH,className:"fa-lg"})}),(0,o.jsx)(d.A,{onClick:this._zoomOut,title:this.props.intl.formatMessage({id:"project_editor.molang_ed.zoom_in_title"}),"aria-label":"Zoom out",children:(0,o.jsx)(a.g,{icon:l.YBE,className:"fa-lg"})})]})})]}),(0,o.jsxs)("div",{className:"mcme-area",style:{minHeight:e,maxHeight:e},children:[s,(0,o.jsx)("div",{className:"mcme-content",children:(0,o.jsx)("div",{className:"mcme-interior",style:{minHeight:i,maxHeight:i,backgroundColor:h.Ay.theme===h.g3.dark?"#000000":(0,m.kt)().background1},children:t})})]})}}const u=(0,c.g)(p)}}]);