iobroker.javascript
Version:
Rules Engine for ioBroker
3 lines (2 loc) • 2.51 kB
JavaScript
import{j as e}from"./createSvgIcon-C_ElRFrf.js";import{R as i}from"./iobroker_javascript__loadShare__react__loadShare__-B-pIv4x_.js";import{i as r,I as n}from"./index-DeFm7TiX.js";import{i as a}from"./index-BUU5hWiL.js";import l from"./ScriptEditorVanillaMonaco-BWe9MiKn.js";import{I as c}from"./Save--0ldNXLf.js";import"./_commonjsHelpers-Cpj98o6Y.js";import"./iobroker_javascript__mf_v__runtimeInit__mf_v__-CmuPLb0X.js";import"./inheritsLoose-CLw44UEv.js";import"./preload-helper-Dp1pzeXC.js";const o={textArea:{width:"calc(100% - 10px)",resize:"none"},dialog:{height:"95%"},fullHeight:{height:"100%",overflow:"hidden"},args:s=>({color:s.palette.mode==="dark"?"white":"black",height:30,width:"100%",fontSize:16}),argsTitle:s=>({color:s.palette.mode==="dark"?"white":"black",fontWeight:"bold"})};class k extends i.Component{constructor(t){super(t),this.state={changed:!1,source:!t.source&&t.isReturn?`
return false`:t.source}}componentDidMount(){setTimeout(()=>{var t;try{(t=window.document.getElementById("source-text-area"))==null||t.focus()}catch{}},100)}handleCancel(){this.props.onClose(!1)}handleOk(){(!this.props.isReturn||this.state.source.includes("return "))&&this.props.onClose(this.state.source)}onChange(t){this.setState({changed:!0,source:t})}render(){return e.jsxs(r.Dialog,{onClose:()=>!1,maxWidth:"lg",sx:{"& .MuiDialog-paper":o.dialog},fullWidth:!0,open:!0,"aria-labelledby":"source-dialog-title",children:[e.jsx(r.DialogTitle,{id:"source-dialog-title",children:a.I18n.t("Function editor")}),e.jsxs(r.DialogContent,{style:o.fullHeight,children:[this.props.args&&e.jsxs(r.Box,{sx:o.args,children:[e.jsx(r.Box,{component:"span",sx:o.argsTitle,children:a.I18n.t("function (")}),this.props.args,e.jsx(r.Box,{component:"span",sx:o.argsTitle,children:")"})]},"arguments"),e.jsx(l,{triggerPrettier:1,adapterName:this.props.adapterName,runningInstances:this.props.runningInstances,style:{...o.textArea,height:this.props.args?"calc(100% - 30px)":"100%"},name:"blockly",socket:this.props.socket,readOnly:!1,checkJs:!1,changed:this.state.changed,code:this.state.source,isDark:this.props.themeType==="dark",onChange:t=>this.onChange(t),language:"javascript"},"scriptEditor")]}),e.jsxs(r.DialogActions,{children:[e.jsx(r.Button,{variant:"contained",onClick:()=>this.handleOk(),color:"primary",startIcon:e.jsx(c,{}),children:a.I18n.t("Save")}),e.jsx(r.Button,{color:"grey",variant:"contained",onClick:()=>this.handleCancel(),startIcon:e.jsx(n,{}),children:a.I18n.t("Cancel")})]})]})}}export{k as default};