iobroker.javascript 9.3.0 → 9.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -4
- package/admin/assets/{AiChatPanel-BvND3KNP.js → AiChatPanel-C3bIw_D5.js} +1 -1
- package/admin/assets/{ScriptEditor-1BwI9a_X.js → ScriptEditor-8UU88tT5.js} +1 -1
- package/admin/assets/{ScriptEditorVanillaMonaco-BPK75VNu.js → ScriptEditorVanillaMonaco-Bn8xJ3LV.js} +2 -2
- package/admin/assets/index-C0ZnUCQf.js +990 -0
- package/admin/assets/{index-CxRhXAwi.js → index-CO9RA-Wq.js} +4 -4
- package/admin/assets/{index-fS-54-pB.js → index-CRGWWpGb.js} +1 -1
- package/admin/assets/{index-DUMiVB6k.js → index-CsyuIWlD.js} +1 -1
- package/admin/assets/localSharedImportMap-Db5DxDmY.js +1 -0
- package/admin/assets/{stateHoverProvider-dvzAyUDH.js → stateHoverProvider-C82xsI7Q.js} +1 -1
- package/admin/assets/{virtual_mf-REMOTE_ENTRY_ID_iobroker_javascript__remoteEntry_js-Dus28I2g.js → virtual_mf-REMOTE_ENTRY_ID_iobroker_javascript__remoteEntry_js-Bw22wl4W.js} +2 -2
- package/admin/custom/assets/index-CMsuyEZj.js +964 -0
- package/admin/custom/assets/{index-C8_qJ4Y6.js → index-CuAhFQ4L.js} +1 -1
- package/admin/custom/assets/{index-BVOepGI5.js → index-mkhHeJ3Q.js} +1 -1
- package/admin/custom/assets/localSharedImportMap-BsMINYMr.js +1 -0
- package/admin/custom/assets/{virtual_mf-REMOTE_ENTRY_ID_ConfigCustomJavascriptSet__customComponents_js-CO2hfDx_.js → virtual_mf-REMOTE_ENTRY_ID_ConfigCustomJavascriptSet__customComponents_js-BzLNCazi.js} +2 -2
- package/admin/custom/customComponents.js +1 -1
- package/admin/mf-manifest.json +1 -1
- package/admin/remoteEntry.js +1 -1
- package/admin/tab.html +2 -2
- package/build/lib/sandbox.js +20 -12
- package/build/lib/sandbox.js.map +1 -1
- package/build/main.js +34 -25
- package/build/main.js.map +1 -1
- package/build/types.d.ts +4 -4
- package/io-package.json +14 -14
- package/package.json +3 -3
- package/admin/assets/index-Be9Zg6aF.js +0 -990
- package/admin/assets/localSharedImportMap-Cs4ibnCv.js +0 -1
- package/admin/custom/assets/index-DSGXVHGh.js +0 -964
- package/admin/custom/assets/localSharedImportMap-C-8wOKN2.js +0 -1
package/README.md
CHANGED
|
@@ -27,9 +27,11 @@ Executes Javascript, Typescript Scripts.
|
|
|
27
27
|
-->
|
|
28
28
|
|
|
29
29
|
## Changelog
|
|
30
|
+
### 9.3.1 (2026-06-18)
|
|
31
|
+
* (@GermanBluefox) Added the possibility to execute one-way scripts without saving it
|
|
32
|
+
|
|
30
33
|
### 9.3.0 (2026-06-17)
|
|
31
34
|
* (@GermanBluefox) Implemented the support for credentials manager in the configuration
|
|
32
|
-
* (@GermanBluefox) Added the possiblilty to execute scripts from AI agent
|
|
33
35
|
|
|
34
36
|
### 9.2.4 (2026-06-08)
|
|
35
37
|
* (arteck) Performance optimizations part 2
|
|
@@ -46,9 +48,6 @@ Executes Javascript, Typescript Scripts.
|
|
|
46
48
|
* (Eistee82) Clarified the AI chat mode descriptions in the tooltip: Agent is for larger models with tool support and handles both analysis and script creation, Code is for smaller models without tool support (uses two-step plan-then-code) — translations updated in all 11 languages
|
|
47
49
|
* (@GermanBluefox) Added the "is state exists" block to blockly
|
|
48
50
|
|
|
49
|
-
### 9.2.1 (2026-04-30)
|
|
50
|
-
* (@GermanBluefox) See previous changelog entries
|
|
51
|
-
|
|
52
51
|
## License
|
|
53
52
|
The MIT License (MIT)
|
|
54
53
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as Se,j as o}from"./createSvgIcon-DYs_tNrE.js";import{k as J,j as te,b as ne,c as xe,l as Ae}from"./iobroker_javascript__loadShare__react__loadShare__.mjs-CTZOFJS2.js";import{z as L,P as ve,o as we,a0 as ct,a1 as lt,i as We,J as dt,r as ut,s as pt,u as mt,a2 as Fe,c as ft,f as He,g as ze,a3 as Oe,a4 as Ve,a5 as ht}from"./iobroker_javascript__loadShare___mf_0_mui_mf_1_material__loadShare__.mjs-CV1_X-Lf.js";import{_ as u}from"./iobroker_javascript__loadShare___mf_0_iobroker_mf_1_adapter_mf_2_react_mf_2_v5__loadShare__.mjs-DkBjPSMw.js";import{_ as Ze}from"./preload-helper-BDBacUwf.js";import{C as gt,b as yt,I as bt,R as xt}from"./index-45IwpC7_.js";import{i as vt,k as qe,l as wt,n as St}from"./index-
|
|
1
|
+
import{c as Se,j as o}from"./createSvgIcon-DYs_tNrE.js";import{k as J,j as te,b as ne,c as xe,l as Ae}from"./iobroker_javascript__loadShare__react__loadShare__.mjs-CTZOFJS2.js";import{z as L,P as ve,o as we,a0 as ct,a1 as lt,i as We,J as dt,r as ut,s as pt,u as mt,a2 as Fe,c as ft,f as He,g as ze,a3 as Oe,a4 as Ve,a5 as ht}from"./iobroker_javascript__loadShare___mf_0_mui_mf_1_material__loadShare__.mjs-CV1_X-Lf.js";import{_ as u}from"./iobroker_javascript__loadShare___mf_0_iobroker_mf_1_adapter_mf_2_react_mf_2_v5__loadShare__.mjs-DkBjPSMw.js";import{_ as Ze}from"./preload-helper-BDBacUwf.js";import{C as gt,b as yt,I as bt,R as xt}from"./index-45IwpC7_.js";import{i as vt,k as qe,l as wt,n as St}from"./index-CO9RA-Wq.js";import{g as kt,c as jt}from"./index-wHNMOf-c.js";import"./iobroker_javascript__loadShare__react__loadShare__.mjs_commonjs-proxy-CE9lvhW8.js";import"./iobroker_javascript__loadShare__prop_mf_2_types__loadShare__.mjs-BCtSFofY.js";import"./virtual_mf-REMOTE_ENTRY_ID_iobroker_javascript__remoteEntry_js-Bw22wl4W.js";import"./iobroker_javascript__loadShare__react_mf_2_dom__loadShare__.mjs_commonjs-proxy-RQRRZMX5.js";import"./iobroker_javascript__loadShare__react_mf_2_dom__loadShare__.mjs-DeVAS-oa.js";import"./inheritsLoose-CIXm_zPk.js";const et=Se(o.jsx("path",{d:"M13 7h-2v4H7v2h4v4h2v-4h4v-2h-4zm-1-5C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2m0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8"}),"AddCircleOutline"),_t=Se(o.jsx("path",{d:"M21.99 4c0-1.1-.89-2-1.99-2H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h14l4 4zM17 11h-4v4h-2v-4H7V9h4V5h2v4h4z"}),"AddComment"),Tt=Se(o.jsx("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10h5v-2h-5c-4.34 0-8-3.66-8-8s3.66-8 8-8 8 3.66 8 8v1.43c0 .79-.71 1.57-1.5 1.57s-1.5-.78-1.5-1.57V12c0-2.76-2.24-5-5-5s-5 2.24-5 5 2.24 5 5 5c1.38 0 2.64-.56 3.54-1.47.65.89 1.77 1.47 2.96 1.47 1.97 0 3.5-1.6 3.5-3.57V12c0-5.52-4.48-10-10-10m0 13c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3"}),"AlternateEmail"),Ct=Se(o.jsx("path",{d:"M9.01 14H2v2h7.01v3L13 15l-3.99-4zm5.98-1v-3H22V8h-7.01V5L11 9z"}),"CompareArrows"),It=Se(o.jsx("path",{d:"M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4m0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4"}),"Person"),Ot=Se(o.jsx("path",{d:"M3 10h11v2H3zm0-4h11v2H3zm0 8h7v2H3zm17.59-2.07-4.25 4.24-2.12-2.12-1.41 1.41L16.34 19 22 13.34z"}),"PlaylistAddCheck"),Et=Se(o.jsx("path",{d:"M2.01 21 23 12 2.01 3 2 10l15 2-15 2z"}),"Send"),Nt=Se(o.jsx("path",{d:"M20 9V7c0-1.1-.9-2-2-2h-3c0-1.66-1.34-3-3-3S9 3.34 9 5H6c-1.1 0-2 .9-2 2v2c-1.66 0-3 1.34-3 3s1.34 3 3 3v4c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2v-4c1.66 0 3-1.34 3-3s-1.34-3-3-3M7.5 11.5c0-.83.67-1.5 1.5-1.5s1.5.67 1.5 1.5S9.83 13 9 13s-1.5-.67-1.5-1.5M16 17H8v-2h8zm-1-4c-.83 0-1.5-.67-1.5-1.5S14.17 10 15 10s1.5.67 1.5 1.5S15.83 13 15 13"}),"SmartToy"),Rt=Ze(()=>import("./docs-compact-CKNGiYh2.js"),[],import.meta.url),$t={openai:"img/openai.svg",anthropic:"img/anthropic.svg",gemini:"img/gemini.svg",deepseek:"img/deepseek.svg",custom:"img/custom.svg"},Lt={width:16,height:16,flexShrink:0,opacity:.7},Mt={ru:"Russian",en:"English",de:"German",es:"Spanish",fr:"French",it:"Italian",pl:"Polish",nl:"Dutch",pt:"Portuguese",uk:"Ukrainian","zh-cn":"Chinese"};let $e=null,Je=null,Le=null,Me=null;function Dt(){$e=null,Je=null,Le=null,Me=null}async function De(r,e){if($e)return $e;const n=Object.keys(e)[0];if(!n)return null;const t=await r.sendTo(n,"getAvailableAiProviders",{}),i=((t==null?void 0:t.providers)||[]).map(a=>a.provider),s=((t==null?void 0:t.providers)||[]).find(a=>a.provider==="custom");return i.length?($e={providers:i,gptBaseUrl:s==null?void 0:s.baseUrl},$e):null}const Bt=["embedding","text-embedding","textembedding","embeddinggemma","embed-","-embed","bge-","mxbai-embed","nomic-embed","arctic-embed","snowflake-arctic-embed","all-minilm","multilingual-e5","jina-embed","voyage-","gecko","paraphrase-multilingual","dall-e","gpt-image","image-edit","-image-preview","-image-latest","flash-image","nano-banana","stable-diffusion","sdxl","midjourney","flux-","imagen","sora","veo-","cogvideo","runway-","lumiere","lyria","whisper","tts-","-tts","speech-","audio-preview","mini-tts","mini-transcribe","-transcribe","native-audio","flash-live","gpt-audio","realtime","bark-","xtts","voicebox","moderation","omni-moderation","llama-guard","shieldgemma","prompt-guard","-guardian","safeguard","rerank","reranker","babbage-","davinci-","curie-","text-ada-","text-davinci","text-curie","text-babbage","instructgpt","code-davinci","code-cushman","-turbo-instruct","-search-preview","-search-api","code-search","text-search","similarity-","computer-use-preview","deep-research","robotics","aqa","reader-lm","-nsql","minicheck"];function zt(r){const e=r.toLowerCase();return!(Bt.some(n=>e.includes(n))||e.startsWith("claude-1")||e.startsWith("claude-instant"))}async function Pt(r,e){const n=await De(r,e);if(!n)return{models:[],providerMap:{},errors:["No API keys configured"]};const t=Object.keys(e)[0];if(!t)return{models:[],providerMap:{},errors:[u.I18n.t("No running javascript instance found")]};const i=[],s={},a=[],p=(c,y)=>{for(const d of c)zt(d)&&(s[d]||(i.push(d),s[d]=y))},l=[],m=(c,y)=>{l.push(r.sendTo(t,"testApiConnection",{provider:c==="custom"?"openai":c}).then(d=>{d.models?p(d.models,c):d.error&&a.push(`${y||c}: ${d.error}`)}).catch(d=>{a.push(`${y||c}: ${String(d)}`)}))},g={openai:"OpenAI",anthropic:"Anthropic",gemini:"Gemini",deepseek:"DeepSeek",custom:"Custom"};for(const c of n.providers)m(c,g[c]);return await Promise.all(l),i.sort(),{models:i,providerMap:s,errors:a}}async function Ne(r,e,n){var i;return await r.sendTo(e,"chatCompletion",{timeout:n.timeout||6e5,model:n.model,provider:n.provider,messages:n.messages,...n.baseUrl?{baseUrl:n.baseUrl}:{},...(i=n.tools)!=null&&i.length?{tools:n.tools}:{}})}async function tt(r){if(Me)return Me;const e=await r.getObjectViewSystem("state","","香"),n=await r.getObjectViewSystem("channel","","香"),t=await r.getObjectViewSystem("device","","香"),i=await r.getObjectViewSystem("folder","","香"),s=await r.getObjectViewSystem("enum","","香");return Me=Object.assign(e,n,t,i,s),Me}async function nt(r){return tt(r)}function Ce(r,e){return r&&typeof r=="object"?r[e]||r.en:r||""}async function Ge(r){var S,b,v,H;if(Je)return Je;const e=u.I18n.getLanguage(),n=await tt(r),t=Object.keys(n).sort(),i=new gt,s=[],a=["UNREACH_STICKY"],p=[yt.Types.info],l=[],m=[],g=[],c=[];t.forEach(E=>{var C,x,w;((C=n[E])==null?void 0:C.type)==="enum"?l.push(E):(w=(x=n[E])==null?void 0:x.common)!=null&&w.smartName&&c.push(E)}),l.forEach(E=>{E.startsWith("enum.rooms.")?m.push(E):E.startsWith("enum.functions.")&&g.push(E);const C=n[E].common.members;C!=null&&C.length&&C.forEach(x=>{n[x]&&!c.includes(x)&&c.push(x)})});const y={id:"",objects:n,_keysOptional:t,_usedIdsOptional:s,ignoreIndicators:a,excludedTypes:p},d=[];c.forEach(E=>{y.id=E;const C=i.detect(y);C&&C.forEach(x=>{var de;const w=(de=x.states.find(I=>I.id))==null?void 0:de.id;if(!w||d.find(I=>I.id===w))return;const M=n[w],re={id:w,name:Ce(M.common.name,e),type:M.type,deviceType:x.type,states:x.states.filter(I=>I.id).map(I=>({id:I.id,name:I.name,role:I.defaultRole,type:n[I.id].common.type,unit:n[I.id].common.unit,read:n[I.id].common.read??!0,write:n[I.id].common.write??!0}))},G=w.split(".");let _,Y;(M.type==="channel"||M.type==="state")&&(G.pop(),_=G.join("."),n[_]&&(n[_].type==="channel"||n[_].type==="folder")?(G.pop(),Y=G.join("."),(!n[Y]||n[Y].type!=="device"&&n[_].type!=="folder")&&(Y=void 0)):_=void 0);const le=m.find(I=>{var A,X,Q;return(A=n[I].common.members)!=null&&A.includes(w)||_&&((X=n[I].common.members)!=null&&X.includes(_))?!0:Y&&((Q=n[I].common.members)==null?void 0:Q.includes(Y))});le&&(re.room=Ce(n[le].common.name,e));const K=g.find(I=>{var A,X,Q;return(A=n[I].common.members)!=null&&A.includes(w)||_&&((X=n[I].common.members)!=null&&X.includes(_))?!0:Y&&((Q=n[I].common.members)==null?void 0:Q.includes(Y))});K&&(re.function=Ce(n[K].common.name,e)),d.push(re)})});for(let E=0;E<d.length;E++){const C=d[E];if(C.type==="state"||C.type==="channel"){const x=C.id.split(".");x.pop();const w=n[x.join(".")];if(w&&(w.type==="channel"||w.type==="device"||w.type==="folder")){C.name=Ce(((S=w.common)==null?void 0:S.name)||C.name,e),x.pop();const M=n[x.join(".")];(M==null?void 0:M.type)==="device"&&((b=M.common)!=null&&b.icon)&&(C.name=Ce(((v=M.common)==null?void 0:v.name)||C.name,e))}else C.name=Ce(((H=w==null?void 0:w.common)==null?void 0:H.name)||C.name,e)}}return Je=d,d}async function Jt(){return Le||(Le=(await Rt).default,Le)}function Ye(){return Mt[u.I18n.getLanguage()]||"English"}function At(r){return`You write ioBroker JavaScript adapter scripts.
|
|
2
2
|
Copy EXACTLY this syntax. Do NOT change the callback signature.
|
|
3
3
|
IMPORTANT: Write all code at top level. NEVER use console.log (use log instead). NEVER define functions with the function keyword.
|
|
4
4
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{j as t}from"./createSvgIcon-DYs_tNrE.js";import{a as n}from"./iobroker_javascript__loadShare__react__loadShare__.mjs-CTZOFJS2.js";import{_ as l,a as c,b as h,z as a,h as d,i}from"./iobroker_javascript__loadShare___mf_0_mui_mf_1_material__loadShare__.mjs-CV1_X-Lf.js";import{_ as o}from"./iobroker_javascript__loadShare___mf_0_iobroker_mf_1_adapter_mf_2_react_mf_2_v5__loadShare__.mjs-DkBjPSMw.js";import p from"./ScriptEditorVanillaMonaco-
|
|
1
|
+
import{j as t}from"./createSvgIcon-DYs_tNrE.js";import{a as n}from"./iobroker_javascript__loadShare__react__loadShare__.mjs-CTZOFJS2.js";import{_ as l,a as c,b as h,z as a,h as d,i}from"./iobroker_javascript__loadShare___mf_0_mui_mf_1_material__loadShare__.mjs-CV1_X-Lf.js";import{_ as o}from"./iobroker_javascript__loadShare___mf_0_iobroker_mf_1_adapter_mf_2_react_mf_2_v5__loadShare__.mjs-DkBjPSMw.js";import p from"./ScriptEditorVanillaMonaco-Bn8xJ3LV.js";import{S as m}from"./Save-CkuNSiWL.js";import{a as g}from"./index-wHNMOf-c.js";import"./iobroker_javascript__loadShare__react__loadShare__.mjs_commonjs-proxy-CE9lvhW8.js";import"./iobroker_javascript__loadShare__prop_mf_2_types__loadShare__.mjs-BCtSFofY.js";import"./preload-helper-BDBacUwf.js";import"./index-CO9RA-Wq.js";import"./virtual_mf-REMOTE_ENTRY_ID_iobroker_javascript__remoteEntry_js-Bw22wl4W.js";import"./iobroker_javascript__loadShare__react_mf_2_dom__loadShare__.mjs_commonjs-proxy-RQRRZMX5.js";import"./iobroker_javascript__loadShare__react_mf_2_dom__loadShare__.mjs-DeVAS-oa.js";import"./inheritsLoose-CIXm_zPk.js";const s={textArea:{width:"calc(100% - 10px)",resize:"none"},dialog:{height:"95%"},fullHeight:{height:"100%",overflow:"hidden"},args:r=>({color:r.palette.mode==="dark"?"white":"black",height:30,width:"100%",fontSize:16}),argsTitle:r=>({color:r.palette.mode==="dark"?"white":"black",fontWeight:"bold"})};class D extends n.Component{constructor(e){super(e),this.state={changed:!1,source:!e.source&&e.isReturn?`
|
|
2
2
|
return false`:e.source}}componentDidMount(){setTimeout(()=>{var e;try{(e=window.document.getElementById("source-text-area"))==null||e.focus()}catch{}},100)}handleCancel(){this.props.onClose(!1)}handleOk(){(!this.props.isReturn||this.state.source.includes("return "))&&this.props.onClose(this.state.source)}onChange(e){this.setState({changed:!0,source:e})}render(){return t.jsxs(l,{onClose:()=>!1,maxWidth:"lg",sx:{"& .MuiDialog-paper":s.dialog},fullWidth:!0,open:!0,"aria-labelledby":"source-dialog-title",children:[t.jsx(c,{id:"source-dialog-title",children:o.I18n.t("Function editor")}),t.jsxs(h,{style:s.fullHeight,children:[this.props.args&&t.jsxs(a,{sx:s.args,children:[t.jsx(a,{component:"span",sx:s.argsTitle,children:o.I18n.t("function (")}),this.props.args,t.jsx(a,{component:"span",sx:s.argsTitle,children:")"})]},"arguments"),t.jsx(p,{triggerPrettier:1,adapterName:this.props.adapterName,runningInstances:this.props.runningInstances,style:{...s.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:e=>this.onChange(e),language:"javascript"},"scriptEditor")]}),t.jsxs(d,{children:[t.jsx(i,{variant:"contained",onClick:()=>this.handleOk(),color:"primary",startIcon:t.jsx(m,{}),children:o.I18n.t("Save")}),t.jsx(i,{color:"grey",variant:"contained",onClick:()=>this.handleCancel(),startIcon:t.jsx(g,{}),children:o.I18n.t("Cancel")})]})]})}}export{D as default};
|
package/admin/assets/{ScriptEditorVanillaMonaco-BPK75VNu.js → ScriptEditorVanillaMonaco-Bn8xJ3LV.js}
RENAMED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./stateHoverProvider-
|
|
2
|
-
import{_ as g}from"./preload-helper-BDBacUwf.js";import{j as m}from"./createSvgIcon-DYs_tNrE.js";import{a as k}from"./iobroker_javascript__loadShare__react__loadShare__.mjs-CTZOFJS2.js";import{_ as T,a as N,b as M,h as A,i as S,Q as O,o as x,$ as j}from"./iobroker_javascript__loadShare___mf_0_mui_mf_1_material__loadShare__.mjs-CV1_X-Lf.js";import{n as _,Z as R}from"./index-wHNMOf-c.js";import{_ as p}from"./iobroker_javascript__loadShare___mf_0_iobroker_mf_1_adapter_mf_2_react_mf_2_v5__loadShare__.mjs-DkBjPSMw.js";import{h as V}from"./index-CxRhXAwi.js";import"./iobroker_javascript__loadShare__react__loadShare__.mjs_commonjs-proxy-CE9lvhW8.js";import"./iobroker_javascript__loadShare__prop_mf_2_types__loadShare__.mjs-BCtSFofY.js";import"./virtual_mf-REMOTE_ENTRY_ID_iobroker_javascript__remoteEntry_js-Dus28I2g.js";import"./iobroker_javascript__loadShare__react_mf_2_dom__loadShare__.mjs_commonjs-proxy-RQRRZMX5.js";import"./iobroker_javascript__loadShare__react_mf_2_dom__loadShare__.mjs-DeVAS-oa.js";import"./inheritsLoose-CIXm_zPk.js";function K(v){return/^script\.js\.global\./.test(v)}let P=0;function W(v){const t=/\x1b\[[0-9;]*m/g;return v.replace(t,"")}class tt extends k.Component{monacoDiv=null;editor=null;monaco=window.monaco;get monacoTS(){var t,e;return(e=(t=this.monaco)==null?void 0:t.languages)==null?void 0:e.typescript}insert="";originalCode;runningInstancesStr;monacoCounter=0;location;breakpoints;lastSearch="";typings={};decorations=[];datapointProviderDisposable=null;inlineProviderDisposable=null;stateHoverDisposable=null;showStateValueDisposable=null;cronHoverDisposable=null;codeLensDisposable=null;inlineChatWidgetInstance=null;inlineDiffInstance=null;inlineDiffCssInjected=!1;triggerPrettier;contentChangeDisposable=null;mouseDownDisposable=null;constructor(t){super(t),this.state={name:"current",isDark:t.isDark||!1,language:t.language||"javascript",readOnly:t.readOnly||!1,alive:!0,check:!1,searchText:this.props.searchText||"",typingsLoaded:!1,showError:null},this.triggerPrettier=t.triggerPrettier,this.runningInstancesStr=JSON.stringify(this.props.runningInstances),this.originalCode=t.code||"",this.monacoDiv=k.createRef()}waitForMonaco(t){var i,o,n,r;let e=!!((o=(i=this.monacoTS)==null?void 0:i.typescriptDefaults)!=null&&o.getCompilerOptions);if(!e||!this.props.runningInstances){if(this.monaco=window.monaco,e=!!((r=(n=this.monacoTS)==null?void 0:n.typescriptDefaults)!=null&&r.getCompilerOptions),this.monacoCounter++,!e&&this.monacoCounter<20){console.log("wait for monaco loaded"),setTimeout(()=>this.waitForMonaco(t),200);return}this.monacoCounter>=20&&console.error("Cannot load monaco!")}else t&&t()}loadTypings(t){if(!this.editor)return;t||=this.props.runningInstances;const e=t&&Object.keys(t).find(i=>t==null?void 0:t[i]);e&&this.props.socket.sendTo(e.replace("system.adapter.",""),"loadTypings",null).then(i=>{this.setState({alive:!0,check:!0,typingsLoaded:!0}),this.setTypeCheck(!0),i.typings?(this.typings=i.typings,this.setEditorTypings(this.state.name)):console.error(`failed to load typings: ${i.error}`)})}componentDidMount(){var i,o,n,r,s,u,c,d;this.undo,this.redo,this.showInlineDiff,this.getEditorSelection,this.getEditorContent,this.getCursorPosition,this.highlightLineRange,this.goToLine,this.replaceSelection,this.getDiagnostics,this.getDocumentSymbols;let t=!!((o=(i=this.monacoTS)==null?void 0:i.typescriptDefaults)!=null&&o.getCompilerOptions);if((!t||!this.props.runningInstances)&&(this.monaco=window.monaco,t=!!((r=(n=this.monacoTS)==null?void 0:n.typescriptDefaults)!=null&&r.getCompilerOptions),!t)){console.log("wait for monaco loaded..."),this.waitForMonaco(()=>this.componentDidMount());return}if(!this.editor&&t&&this.monaco){console.log("Init editor"),(u=(s=this.props).onRegisterSelect)==null||u.call(s,()=>{var a;if(this.editor){const h=this.editor.getSelection();if(h)return(a=this.editor.getModel())==null?void 0:a.getValueInRange(h)}});const l=this.monacoTS.typescriptDefaults.getCompilerOptions();l.allowJs=!0,l.checkJs=this.props.checkJs!==!1,l.noLib=!0,l.lib=[],l.useUnknownInCatchVariables=!1,l.moduleResolution=this.monacoTS.ModuleResolutionKind.NodeJs,l.target=this.monacoTS.ScriptTarget.ESNext,l.module=this.monacoTS.ModuleKind.ESNext,l.allowNonTsExtensions=!0,this.monacoTS.typescriptDefaults.setCompilerOptions(l),this.setTypeCheck(!1),(c=this.monacoDiv)!=null&&c.current&&(this.editor=this.monaco.editor.create((d=this.monacoDiv)==null?void 0:d.current,{lineNumbers:"on",scrollBeyondLastLine:!1,automaticLayout:!0,glyphMargin:!!this.props.breakpoints,colorDecorators:!0,hover:{enabled:!0,delay:200,sticky:!0},fixedOverflowWidgets:!0}),this.contentChangeDisposable=this.editor.onDidChangeModelContent(()=>this.onChange()),this.monaco&&!this.datapointProviderDisposable&&g(async()=>{const{registerDatapointProvider:a}=await import("./AiDatapointProvider-B0i3I5Fm.js");return{registerDatapointProvider:a}},[],import.meta.url).then(({registerDatapointProvider:a})=>{this.monaco&&(this.datapointProviderDisposable=a(this.monaco,this.props.socket))}).catch(()=>{}),this.monaco&&!this.stateHoverDisposable&&g(async()=>{const{registerStateHoverProvider:a,registerShowStateValueAction:h}=await import("./stateHoverProvider-dvzAyUDH.js");return{registerStateHoverProvider:a,registerShowStateValueAction:h}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14]),import.meta.url).then(({registerStateHoverProvider:a,registerShowStateValueAction:h})=>{this.monaco&&(this.stateHoverDisposable=a(this.monaco,this.props.socket)),this.monaco&&this.editor&&!this.showStateValueDisposable&&(this.showStateValueDisposable=h(this.editor,this.monaco,p.I18n.t("Show ioBroker state value")))}).catch(()=>{}),this.monaco&&!this.cronHoverDisposable&&g(async()=>{const{registerCronHoverProvider:a}=await import("./cronHoverProvider-Bg0Vz-1E.js");return{registerCronHoverProvider:a}},__vite__mapDeps([15,1]),import.meta.url).then(({registerCronHoverProvider:a})=>{this.monaco&&(this.cronHoverDisposable=a(this.monaco))}).catch(()=>{}),this.props.aiCompletionsEnabled&&this.monaco&&!this.inlineProviderDisposable&&g(async()=>{const{registerAiInlineProvider:a}=await import("./AiInlineProvider-DkgjVSFQ.js");return{registerAiInlineProvider:a}},[],import.meta.url).then(({registerAiInlineProvider:a})=>{this.monaco&&(this.inlineProviderDisposable=a(this.monaco,this.props.socket,this.props.runningInstances))}).catch(()=>{}),this.loadTypings(),this.props.onForceSave&&this.editor.addCommand(this.monaco.KeyMod.CtrlCmd|this.monaco.KeyCode.KeyS,()=>this.props.onForceSave&&this.props.onForceSave()),this.registerAiActions(),this.monaco&&this.editor&&this.props.onAiAction&&!this.codeLensDisposable&&g(async()=>{const{registerAiCodeLensProvider:a}=await import("./index-CxRhXAwi.js").then(h=>h.p);return{registerAiCodeLensProvider:a}},__vite__mapDeps([2,3,4,5,6,7,8,9,10,11,1,12,13,14]),import.meta.url).then(({registerAiCodeLensProvider:a})=>{this.monaco&&this.editor&&this.props.onAiAction&&(this.codeLensDisposable=a(this.monaco,this.editor,(h,y,f,b,D)=>{var L,w,I;const C=(L=this.editor)==null?void 0:L.getModel(),E=C?C.getLineMaxColumn(Math.min(D,C.getLineCount())):1;(I=(w=this.props).onAiAction)==null||I.call(w,{action:h,code:y,rangeLabel:f,range:{startLine:b,startColumn:1,endLine:D,endColumn:E},kind:"codelens"})}))}).catch(()=>{}),setTimeout(()=>{this.highlightText(this.state.searchText),this.location=this.props.location||void 0,this.breakpoints=this.props.breakpoints,this.showDecorators()}))}const e={selectOnLineNumbers:!0,scrollBeyondLastLine:!1,automaticLayout:!0,readOnly:this.state.readOnly,language:this.state.language,isDark:this.state.isDark};this.setEditorOptions(e),this.editor&&(this.editor.focus(),this.editor.setValue(this.originalCode),this.props.onToggleBreakpoint&&(this.mouseDownDisposable=this.editor.onMouseDown(l=>{var h;const a=l.target;this.props.onToggleBreakpoint&&((h=a.detail)==null?void 0:h.glyphMarginLeft)!==void 0&&a.position&&this.props.onToggleBreakpoint(a.position.lineNumber-1)})))}setEditorOptions(t){var e;t&&(t.language&&this.setEditorLanguage(t.language),this.editor&&(t.readOnly!==void 0&&this.editor.updateOptions({readOnly:t.readOnly}),t.lineWrap!==void 0&&this.editor.updateOptions({wordWrap:t.lineWrap?"on":"off"})),t.typeCheck!==void 0&&this.setTypeCheck(t.typeCheck),t.isDark!==void 0&&((e=this.monaco)==null||e.editor.setTheme(t.isDark?"vs-dark":"vs")))}componentWillUnmount(){var t,e,i,o,n,r,s,u,c,d,l;(t=this.contentChangeDisposable)==null||t.dispose(),this.contentChangeDisposable=null,(e=this.mouseDownDisposable)==null||e.dispose(),this.mouseDownDisposable=null,(i=this.datapointProviderDisposable)==null||i.dispose(),this.datapointProviderDisposable=null,g(async()=>{const{clearDatapointCache:a}=await import("./AiDatapointProvider-B0i3I5Fm.js");return{clearDatapointCache:a}},[],import.meta.url).then(({clearDatapointCache:a})=>a()).catch(()=>{}),(o=this.inlineProviderDisposable)==null||o.dispose(),this.inlineProviderDisposable=null,(n=this.stateHoverDisposable)==null||n.dispose(),this.stateHoverDisposable=null,(r=this.showStateValueDisposable)==null||r.dispose(),this.showStateValueDisposable=null,g(async()=>{const{clearStateHoverCache:a}=await import("./stateHoverProvider-dvzAyUDH.js");return{clearStateHoverCache:a}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14]),import.meta.url).then(({clearStateHoverCache:a})=>a()).catch(()=>{}),(s=this.cronHoverDisposable)==null||s.dispose(),this.cronHoverDisposable=null,(u=this.codeLensDisposable)==null||u.dispose(),this.codeLensDisposable=null,(c=this.inlineChatWidgetInstance)==null||c.dispose(),this.inlineChatWidgetInstance=null,this.hideInlineDiff(),this.editor&&((l=(d=this.props).onRegisterSelect)==null||l.call(d,null),this.editor.dispose(),this.editor=null)}async doPrettier(){var i,o,n,r;const t=this.props.runningInstances&&Object.keys(this.props.runningInstances).find(s=>{var u;return(u=this.props.runningInstances)==null?void 0:u[s]});if(!t){window.alert(p.I18n.t("No script adapter instance found to format the code"));return}const e=await this.props.socket.sendTo(t.replace("system.adapter.",""),"prettier",{code:(i=this.editor)==null?void 0:i.getValue(),type:this.state.language});e.error?this.setState({showError:{title:p.I18n.t("Error formatting code"),message:W(e.error)}}):e.code&&((o=this.editor)==null||o.setValue(e.code),(r=(n=this.props).onChange)==null||r.call(n,e.code),this.showDecorators())}setEditorLanguage(t){var i,o;if(!this.editor)return;const e=this.editor.getModel();if(e){const n=e.getValue(),r=e.uri.path,s=typeof r=="string"&&r.includes(".")?r.substring(0,r.lastIndexOf(".")):"index",u=t==="javascript"?"js":t==="typescript"?"ts":t;e.dispose();const c=t==="javascript"||t==="typescript"?"typescript":t,d=(i=this.monaco)==null?void 0:i.editor.createModel(n,c,this.monaco.Uri.from({scheme:window.location.protocol.replace(":",""),path:`${s}${P++}.${u}`}));d&&(this.editor.setModel(d),(o=this.contentChangeDisposable)==null||o.dispose(),this.contentChangeDisposable=this.editor.onDidChangeModelContent(()=>this.onChange()))}}setTypeCheck(t){var i,o;const e={noSemanticValidation:!this.state.alive||!t,noSyntaxValidation:!this.state.alive};(i=this.monacoTS)==null||i.typescriptDefaults.setDiagnosticsOptions(e),(o=this.monacoTS)==null||o.javascriptDefaults.setDiagnosticsOptions({noSemanticValidation:!this.state.alive||!t,noSyntaxValidation:!this.state.alive})}setEditorTypings(t=""){var n,r,s,u;const e=K(t),i=`${t}.d.ts`,o=[];for(const c of Object.keys(this.typings))e&&(c==="global.d.ts"||c.startsWith("script.js.global")&&c!==i)||o.push({filePath:c,content:this.typings[c]});if((r=(n=this.monacoTS)==null?void 0:n.typescriptDefaults)!=null&&r.setExtraLibs)this.monacoTS.typescriptDefaults.setExtraLibs(o);else if((u=(s=this.monacoTS)==null?void 0:s.typescriptDefaults)!=null&&u.addExtraLib){const c=this.monacoTS.typescriptDefaults.getExtraLibs();o.forEach(d=>{!c[d.filePath]&&this.monaco&&this.monacoTS.typescriptDefaults.addExtraLib(d.content,d.filePath)})}}undo(){var t;(t=this.editor)==null||t.trigger("toolbar","undo",null)}redo(){var t;(t=this.editor)==null||t.trigger("toolbar","redo",null)}insertTextIntoEditor(t){if(!this.editor||!this.monaco)return;const e=this.editor.getSelection();if(e){const i=new this.monaco.Range(e.startLineNumber,e.startColumn,e.endLineNumber,e.endColumn);this.editor.executeEdits("",[{range:i,text:t,forceMoveMarkers:!0}])}this.editor.focus()}highlightText(t){var o;if(!this.editor||!this.monaco)return 0;const e=t?(o=this.editor.getModel())==null?void 0:o.findMatches(t,!0,!1,!1,null,!0):void 0;if(e!=null&&e.length)return e.forEach(n=>{var r;return(r=this.editor)==null?void 0:r.setSelection(n.range)}),this.editor.revealLine(e[0].range.startLineNumber),e.length;const i=this.editor.getPosition();if(i){const n=i.lineNumber,r=i.column;this.editor.setSelection(new this.monaco.Range(n,r,n,r))}return 0}showInlineDiff(t){if(!this.editor||!this.monaco)return;const e=this.editor,i=this.monaco;this.hideInlineDiff(),g(async()=>{const{InlineDiffController:o,INLINE_DIFF_CSS:n}=await import("./inlineDiffController-DBLpPOe2.js");return{InlineDiffController:o,INLINE_DIFF_CSS:n}},__vite__mapDeps([16,1,17]),import.meta.url).then(({InlineDiffController:o,INLINE_DIFF_CSS:n})=>{if(!this.inlineDiffCssInjected){const s=document.createElement("style");s.textContent=n,s.setAttribute("data-iob-aichat","inline-diff"),document.head.appendChild(s),this.inlineDiffCssInjected=!0}const r=new o(e,i,{range:t.range,originalText:t.originalText,modifiedText:t.modifiedText,onAccepted:()=>{var s;this.inlineDiffInstance=null,(s=t.onAccepted)==null||s.call(t)},onRejected:()=>{var s;this.inlineDiffInstance=null,(s=t.onRejected)==null||s.call(t)}});this.inlineDiffInstance=r,r.show()}).catch(()=>{})}hideInlineDiff(){if(this.inlineDiffInstance){try{this.inlineDiffInstance.dispose()}catch{}this.inlineDiffInstance=null}}showInlineChatWidget(){if(!this.editor||!this.monaco||!this.props.onInlineAsk)return;if(this.inlineChatWidgetInstance){this.inlineChatWidgetInstance.show();return}const t=this.editor,e=this.monaco,i=this.props.onInlineAsk,o=this.props.onAiAction;g(async()=>{const{InlineChatWidget:n}=await import("./inlineChatWidget-Cu6rb4Ar.js");return{InlineChatWidget:n}},__vite__mapDeps([18,1,17]),import.meta.url).then(({InlineChatWidget:n})=>{const r=new n(t,e,{onSubmit:async s=>i({question:s.question,selectedCode:s.selectedCode}),onEscalateToChat:s=>{o&&o({action:"ask",code:s.selectedCode,question:s.question,rangeLabel:s.range?`lines ${s.range.startLineNumber}-${s.range.endLineNumber}`:"whole file"})}});this.inlineChatWidgetInstance=r,r.show()}).catch(()=>{})}registerAiActions(){if(!this.editor||!this.monaco||!this.props.onAiAction)return;const t=this.monaco,e=(o,n={})=>{if(!this.editor||!this.props.onAiAction)return;const r=this.editor.getModel();if(!r)return;const s=this.editor.getSelection(),u=s&&!s.isEmpty();let c,d,l,a="selection";if(u)c=r.getValueInRange(s),d=s.startLineNumber===s.endLineNumber?`line ${s.startLineNumber}`:`lines ${s.startLineNumber}-${s.endLineNumber}`,l={startLine:s.startLineNumber,startColumn:s.startColumn,endLine:s.endLineNumber,endColumn:s.endColumn},a="selection";else{const h=this.editor.getPosition();let y=null;if(h)try{y=V(r.getValue(),h.lineNumber)}catch{}if(y){const f=y.startLine,b=y.endLine,D=r.getLineMaxColumn(b),C=new t.Range(f,1,b,D);c=r.getValueInRange(C),d=f===b?`line ${f}`:`lines ${f}-${b}`,l={startLine:f,startColumn:1,endLine:b,endColumn:D},a="codelens"}else c=r.getValue(),d="whole file",a="none"}this.props.onAiAction({action:o,code:c,rangeLabel:d,range:l,kind:a,...n})},i=[{id:"iobroker.ai.inline",label:`🤖 ${p.I18n.t("AI: Inline chat…")}`,keybindings:[t.KeyMod.CtrlCmd|t.KeyMod.Alt|t.KeyCode.KeyI],order:1,run:()=>{if(this.props.onInlineAsk)this.showInlineChatWidget();else{const o=window.prompt(p.I18n.t("Ask the AI about the selected code:"));o&&o.trim()&&e("ask",{question:o.trim()})}}},{id:"iobroker.ai.explain",label:`💡 ${p.I18n.t("AI: Explain")}`,keybindings:[t.KeyMod.CtrlCmd|t.KeyMod.Alt|t.KeyCode.KeyE],order:2,run:()=>e("explain")},{id:"iobroker.ai.refactor",label:`🔧 ${p.I18n.t("AI: Refactor")}`,keybindings:[t.KeyMod.CtrlCmd|t.KeyMod.Alt|t.KeyCode.KeyR],order:3,run:()=>e("refactor")},{id:"iobroker.ai.comment",label:`💬 ${p.I18n.t("AI: Add comments")}`,keybindings:[t.KeyMod.CtrlCmd|t.KeyMod.Alt|t.KeyCode.KeyC],order:4,run:()=>e("comment")},{id:"iobroker.ai.fix",label:`🛠️ ${p.I18n.t("AI: Fix problem")}`,keybindings:[t.KeyMod.CtrlCmd|t.KeyMod.Alt|t.KeyCode.KeyF],order:5,run:()=>{var n,r;let o;try{const s=(n=this.editor)==null?void 0:n.getModel(),u=(r=this.editor)==null?void 0:r.getPosition();if(s&&u){const d=t.editor.getModelMarkers({resource:s.uri}).find(l=>u.lineNumber>=l.startLineNumber&&u.lineNumber<=l.endLineNumber);d&&(o=d.message)}}catch{}e("fix",{diagnostic:o})}},{id:"iobroker.ai.tests",label:`✅ ${p.I18n.t("AI: Suggest tests")}`,order:6,run:()=>e("tests")}];for(const o of i)try{this.editor.addAction({id:o.id,label:o.label,contextMenuGroupId:"aichat",contextMenuOrder:o.order,keybindings:o.keybindings,run:()=>o.run()})}catch{}}getEditorSelection(){if(!this.editor)return null;const t=this.editor.getSelection();if(!t||t.isEmpty())return null;const e=this.editor.getModel();return e?{text:e.getValueInRange(t),range:{startLine:t.startLineNumber,startColumn:t.startColumn,endLine:t.endLineNumber,endColumn:t.endColumn}}:null}getEditorContent(){var t,e;return((e=(t=this.editor)==null?void 0:t.getModel())==null?void 0:e.getValue())??""}getCursorPosition(){var e;const t=(e=this.editor)==null?void 0:e.getPosition();return t?{line:t.lineNumber,column:t.column}:null}highlightLineRange(t,e){if(!this.editor||!this.monaco)return!1;const i=this.editor.getModel();if(!i)return!1;const o=i.getLineCount(),n=Math.max(1,Math.min(t,o)),r=Math.max(n,Math.min(e,o)),s=i.getLineMaxColumn(r);return this.editor.setSelection(new this.monaco.Range(n,1,r,s)),this.editor.revealLineInCenter(n),!0}goToLine(t,e=1){if(!this.editor||!this.monaco)return!1;const i=this.editor.getModel();if(!i)return!1;const o=i.getLineCount(),n=Math.max(1,Math.min(t,o));return this.editor.setPosition({lineNumber:n,column:e}),this.editor.revealLineInCenter(n),this.editor.focus(),!0}replaceSelection(t){if(!this.editor||!this.monaco)return!1;const e=this.editor.getSelection();if(!e)return!1;const i=new this.monaco.Range(e.startLineNumber,e.startColumn,e.endLineNumber,e.endColumn);return this.editor.executeEdits("",[{range:i,text:t,forceMoveMarkers:!0}]),this.editor.focus(),!0}getDiagnostics(){if(!this.editor||!this.monaco)return[];const t=this.editor.getModel();if(!t)return[];const e=this.monaco.editor.getModelMarkers({resource:t.uri}),i={8:"error",4:"warning",2:"info",1:"hint"};return e.map(o=>({line:o.startLineNumber,column:o.startColumn,endLine:o.endLineNumber,endColumn:o.endColumn,severity:i[o.severity]||"info",message:o.message,...o.source?{source:o.source}:{}}))}async getDocumentSymbols(){var i;if(!this.editor||!this.monaco)return[];const t=this.editor.getModel();if(!t)return[];const e=[];try{const o=this.monaco.languages,n=(i=o.getDocumentSymbolProviders)==null?void 0:i.call(o,t);if(n!=null&&n.length){const r={0:"file",1:"module",2:"namespace",3:"package",4:"class",5:"method",6:"property",7:"field",8:"constructor",9:"enum",10:"interface",11:"function",12:"variable",13:"constant",14:"string",15:"number",16:"boolean",17:"array",18:"object",19:"key",20:"null",21:"enum-member",22:"struct",23:"event",24:"operator",25:"type-parameter"};for(const s of n){const u={isCancellationRequested:!1},c=await s.provideDocumentSymbols(t,u);if(!c)continue;const d=l=>{var a;for(const h of l)e.push({name:h.name,kind:r[h.kind]||String(h.kind),line:h.range.startLineNumber,endLine:h.range.endLineNumber,...h.detail?{detail:h.detail}:{}}),(a=h.children)!=null&&a.length&&d(h.children)};if(d(c),e.length)break}}}catch{}if(e.length===0){const n=t.getValue().split(`
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./stateHoverProvider-C82xsI7Q.js","./iobroker_javascript__loadShare___mf_0_iobroker_mf_1_adapter_mf_2_react_mf_2_v5__loadShare__.mjs-DkBjPSMw.js","./index-CO9RA-Wq.js","./virtual_mf-REMOTE_ENTRY_ID_iobroker_javascript__remoteEntry_js-Bw22wl4W.js","./preload-helper-BDBacUwf.js","./createSvgIcon-DYs_tNrE.js","./iobroker_javascript__loadShare__react__loadShare__.mjs-CTZOFJS2.js","./iobroker_javascript__loadShare__react__loadShare__.mjs_commonjs-proxy-CE9lvhW8.js","./iobroker_javascript__loadShare__prop_mf_2_types__loadShare__.mjs-BCtSFofY.js","./iobroker_javascript__loadShare__react_mf_2_dom__loadShare__.mjs_commonjs-proxy-RQRRZMX5.js","./iobroker_javascript__loadShare__react_mf_2_dom__loadShare__.mjs-DeVAS-oa.js","./iobroker_javascript__loadShare___mf_0_mui_mf_1_material__loadShare__.mjs-CV1_X-Lf.js","./index-wHNMOf-c.js","./inheritsLoose-CIXm_zPk.js","./index-BTsjunTt.css","./cronHoverProvider-Bg0Vz-1E.js","./inlineDiffController-DBLpPOe2.js","./applyCodeEdit-BdRnbz2g.js","./inlineChatWidget-Cu6rb4Ar.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{_ as g}from"./preload-helper-BDBacUwf.js";import{j as m}from"./createSvgIcon-DYs_tNrE.js";import{a as k}from"./iobroker_javascript__loadShare__react__loadShare__.mjs-CTZOFJS2.js";import{_ as T,a as N,b as M,h as A,i as S,Q as O,o as x,$ as j}from"./iobroker_javascript__loadShare___mf_0_mui_mf_1_material__loadShare__.mjs-CV1_X-Lf.js";import{n as _,Z as R}from"./index-wHNMOf-c.js";import{_ as p}from"./iobroker_javascript__loadShare___mf_0_iobroker_mf_1_adapter_mf_2_react_mf_2_v5__loadShare__.mjs-DkBjPSMw.js";import{h as V}from"./index-CO9RA-Wq.js";import"./iobroker_javascript__loadShare__react__loadShare__.mjs_commonjs-proxy-CE9lvhW8.js";import"./iobroker_javascript__loadShare__prop_mf_2_types__loadShare__.mjs-BCtSFofY.js";import"./virtual_mf-REMOTE_ENTRY_ID_iobroker_javascript__remoteEntry_js-Bw22wl4W.js";import"./iobroker_javascript__loadShare__react_mf_2_dom__loadShare__.mjs_commonjs-proxy-RQRRZMX5.js";import"./iobroker_javascript__loadShare__react_mf_2_dom__loadShare__.mjs-DeVAS-oa.js";import"./inheritsLoose-CIXm_zPk.js";function K(v){return/^script\.js\.global\./.test(v)}let P=0;function W(v){const t=/\x1b\[[0-9;]*m/g;return v.replace(t,"")}class tt extends k.Component{monacoDiv=null;editor=null;monaco=window.monaco;get monacoTS(){var t,e;return(e=(t=this.monaco)==null?void 0:t.languages)==null?void 0:e.typescript}insert="";originalCode;runningInstancesStr;monacoCounter=0;location;breakpoints;lastSearch="";typings={};decorations=[];datapointProviderDisposable=null;inlineProviderDisposable=null;stateHoverDisposable=null;showStateValueDisposable=null;cronHoverDisposable=null;codeLensDisposable=null;inlineChatWidgetInstance=null;inlineDiffInstance=null;inlineDiffCssInjected=!1;triggerPrettier;contentChangeDisposable=null;mouseDownDisposable=null;constructor(t){super(t),this.state={name:"current",isDark:t.isDark||!1,language:t.language||"javascript",readOnly:t.readOnly||!1,alive:!0,check:!1,searchText:this.props.searchText||"",typingsLoaded:!1,showError:null},this.triggerPrettier=t.triggerPrettier,this.runningInstancesStr=JSON.stringify(this.props.runningInstances),this.originalCode=t.code||"",this.monacoDiv=k.createRef()}waitForMonaco(t){var i,o,n,r;let e=!!((o=(i=this.monacoTS)==null?void 0:i.typescriptDefaults)!=null&&o.getCompilerOptions);if(!e||!this.props.runningInstances){if(this.monaco=window.monaco,e=!!((r=(n=this.monacoTS)==null?void 0:n.typescriptDefaults)!=null&&r.getCompilerOptions),this.monacoCounter++,!e&&this.monacoCounter<20){console.log("wait for monaco loaded"),setTimeout(()=>this.waitForMonaco(t),200);return}this.monacoCounter>=20&&console.error("Cannot load monaco!")}else t&&t()}loadTypings(t){if(!this.editor)return;t||=this.props.runningInstances;const e=t&&Object.keys(t).find(i=>t==null?void 0:t[i]);e&&this.props.socket.sendTo(e.replace("system.adapter.",""),"loadTypings",null).then(i=>{this.setState({alive:!0,check:!0,typingsLoaded:!0}),this.setTypeCheck(!0),i.typings?(this.typings=i.typings,this.setEditorTypings(this.state.name)):console.error(`failed to load typings: ${i.error}`)})}componentDidMount(){var i,o,n,r,s,u,c,d;this.undo,this.redo,this.showInlineDiff,this.getEditorSelection,this.getEditorContent,this.getCursorPosition,this.highlightLineRange,this.goToLine,this.replaceSelection,this.getDiagnostics,this.getDocumentSymbols;let t=!!((o=(i=this.monacoTS)==null?void 0:i.typescriptDefaults)!=null&&o.getCompilerOptions);if((!t||!this.props.runningInstances)&&(this.monaco=window.monaco,t=!!((r=(n=this.monacoTS)==null?void 0:n.typescriptDefaults)!=null&&r.getCompilerOptions),!t)){console.log("wait for monaco loaded..."),this.waitForMonaco(()=>this.componentDidMount());return}if(!this.editor&&t&&this.monaco){console.log("Init editor"),(u=(s=this.props).onRegisterSelect)==null||u.call(s,()=>{var a;if(this.editor){const h=this.editor.getSelection();if(h)return(a=this.editor.getModel())==null?void 0:a.getValueInRange(h)}});const l=this.monacoTS.typescriptDefaults.getCompilerOptions();l.allowJs=!0,l.checkJs=this.props.checkJs!==!1,l.noLib=!0,l.lib=[],l.useUnknownInCatchVariables=!1,l.moduleResolution=this.monacoTS.ModuleResolutionKind.NodeJs,l.target=this.monacoTS.ScriptTarget.ESNext,l.module=this.monacoTS.ModuleKind.ESNext,l.allowNonTsExtensions=!0,this.monacoTS.typescriptDefaults.setCompilerOptions(l),this.setTypeCheck(!1),(c=this.monacoDiv)!=null&&c.current&&(this.editor=this.monaco.editor.create((d=this.monacoDiv)==null?void 0:d.current,{lineNumbers:"on",scrollBeyondLastLine:!1,automaticLayout:!0,glyphMargin:!!this.props.breakpoints,colorDecorators:!0,hover:{enabled:!0,delay:200,sticky:!0},fixedOverflowWidgets:!0}),this.contentChangeDisposable=this.editor.onDidChangeModelContent(()=>this.onChange()),this.monaco&&!this.datapointProviderDisposable&&g(async()=>{const{registerDatapointProvider:a}=await import("./AiDatapointProvider-B0i3I5Fm.js");return{registerDatapointProvider:a}},[],import.meta.url).then(({registerDatapointProvider:a})=>{this.monaco&&(this.datapointProviderDisposable=a(this.monaco,this.props.socket))}).catch(()=>{}),this.monaco&&!this.stateHoverDisposable&&g(async()=>{const{registerStateHoverProvider:a,registerShowStateValueAction:h}=await import("./stateHoverProvider-C82xsI7Q.js");return{registerStateHoverProvider:a,registerShowStateValueAction:h}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14]),import.meta.url).then(({registerStateHoverProvider:a,registerShowStateValueAction:h})=>{this.monaco&&(this.stateHoverDisposable=a(this.monaco,this.props.socket)),this.monaco&&this.editor&&!this.showStateValueDisposable&&(this.showStateValueDisposable=h(this.editor,this.monaco,p.I18n.t("Show ioBroker state value")))}).catch(()=>{}),this.monaco&&!this.cronHoverDisposable&&g(async()=>{const{registerCronHoverProvider:a}=await import("./cronHoverProvider-Bg0Vz-1E.js");return{registerCronHoverProvider:a}},__vite__mapDeps([15,1]),import.meta.url).then(({registerCronHoverProvider:a})=>{this.monaco&&(this.cronHoverDisposable=a(this.monaco))}).catch(()=>{}),this.props.aiCompletionsEnabled&&this.monaco&&!this.inlineProviderDisposable&&g(async()=>{const{registerAiInlineProvider:a}=await import("./AiInlineProvider-DkgjVSFQ.js");return{registerAiInlineProvider:a}},[],import.meta.url).then(({registerAiInlineProvider:a})=>{this.monaco&&(this.inlineProviderDisposable=a(this.monaco,this.props.socket,this.props.runningInstances))}).catch(()=>{}),this.loadTypings(),this.props.onForceSave&&this.editor.addCommand(this.monaco.KeyMod.CtrlCmd|this.monaco.KeyCode.KeyS,()=>this.props.onForceSave&&this.props.onForceSave()),this.registerAiActions(),this.monaco&&this.editor&&this.props.onAiAction&&!this.codeLensDisposable&&g(async()=>{const{registerAiCodeLensProvider:a}=await import("./index-CO9RA-Wq.js").then(h=>h.p);return{registerAiCodeLensProvider:a}},__vite__mapDeps([2,3,4,5,6,7,8,9,10,11,1,12,13,14]),import.meta.url).then(({registerAiCodeLensProvider:a})=>{this.monaco&&this.editor&&this.props.onAiAction&&(this.codeLensDisposable=a(this.monaco,this.editor,(h,y,f,b,D)=>{var L,w,I;const C=(L=this.editor)==null?void 0:L.getModel(),E=C?C.getLineMaxColumn(Math.min(D,C.getLineCount())):1;(I=(w=this.props).onAiAction)==null||I.call(w,{action:h,code:y,rangeLabel:f,range:{startLine:b,startColumn:1,endLine:D,endColumn:E},kind:"codelens"})}))}).catch(()=>{}),setTimeout(()=>{this.highlightText(this.state.searchText),this.location=this.props.location||void 0,this.breakpoints=this.props.breakpoints,this.showDecorators()}))}const e={selectOnLineNumbers:!0,scrollBeyondLastLine:!1,automaticLayout:!0,readOnly:this.state.readOnly,language:this.state.language,isDark:this.state.isDark};this.setEditorOptions(e),this.editor&&(this.editor.focus(),this.editor.setValue(this.originalCode),this.props.onToggleBreakpoint&&(this.mouseDownDisposable=this.editor.onMouseDown(l=>{var h;const a=l.target;this.props.onToggleBreakpoint&&((h=a.detail)==null?void 0:h.glyphMarginLeft)!==void 0&&a.position&&this.props.onToggleBreakpoint(a.position.lineNumber-1)})))}setEditorOptions(t){var e;t&&(t.language&&this.setEditorLanguage(t.language),this.editor&&(t.readOnly!==void 0&&this.editor.updateOptions({readOnly:t.readOnly}),t.lineWrap!==void 0&&this.editor.updateOptions({wordWrap:t.lineWrap?"on":"off"})),t.typeCheck!==void 0&&this.setTypeCheck(t.typeCheck),t.isDark!==void 0&&((e=this.monaco)==null||e.editor.setTheme(t.isDark?"vs-dark":"vs")))}componentWillUnmount(){var t,e,i,o,n,r,s,u,c,d,l;(t=this.contentChangeDisposable)==null||t.dispose(),this.contentChangeDisposable=null,(e=this.mouseDownDisposable)==null||e.dispose(),this.mouseDownDisposable=null,(i=this.datapointProviderDisposable)==null||i.dispose(),this.datapointProviderDisposable=null,g(async()=>{const{clearDatapointCache:a}=await import("./AiDatapointProvider-B0i3I5Fm.js");return{clearDatapointCache:a}},[],import.meta.url).then(({clearDatapointCache:a})=>a()).catch(()=>{}),(o=this.inlineProviderDisposable)==null||o.dispose(),this.inlineProviderDisposable=null,(n=this.stateHoverDisposable)==null||n.dispose(),this.stateHoverDisposable=null,(r=this.showStateValueDisposable)==null||r.dispose(),this.showStateValueDisposable=null,g(async()=>{const{clearStateHoverCache:a}=await import("./stateHoverProvider-C82xsI7Q.js");return{clearStateHoverCache:a}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14]),import.meta.url).then(({clearStateHoverCache:a})=>a()).catch(()=>{}),(s=this.cronHoverDisposable)==null||s.dispose(),this.cronHoverDisposable=null,(u=this.codeLensDisposable)==null||u.dispose(),this.codeLensDisposable=null,(c=this.inlineChatWidgetInstance)==null||c.dispose(),this.inlineChatWidgetInstance=null,this.hideInlineDiff(),this.editor&&((l=(d=this.props).onRegisterSelect)==null||l.call(d,null),this.editor.dispose(),this.editor=null)}async doPrettier(){var i,o,n,r;const t=this.props.runningInstances&&Object.keys(this.props.runningInstances).find(s=>{var u;return(u=this.props.runningInstances)==null?void 0:u[s]});if(!t){window.alert(p.I18n.t("No script adapter instance found to format the code"));return}const e=await this.props.socket.sendTo(t.replace("system.adapter.",""),"prettier",{code:(i=this.editor)==null?void 0:i.getValue(),type:this.state.language});e.error?this.setState({showError:{title:p.I18n.t("Error formatting code"),message:W(e.error)}}):e.code&&((o=this.editor)==null||o.setValue(e.code),(r=(n=this.props).onChange)==null||r.call(n,e.code),this.showDecorators())}setEditorLanguage(t){var i,o;if(!this.editor)return;const e=this.editor.getModel();if(e){const n=e.getValue(),r=e.uri.path,s=typeof r=="string"&&r.includes(".")?r.substring(0,r.lastIndexOf(".")):"index",u=t==="javascript"?"js":t==="typescript"?"ts":t;e.dispose();const c=t==="javascript"||t==="typescript"?"typescript":t,d=(i=this.monaco)==null?void 0:i.editor.createModel(n,c,this.monaco.Uri.from({scheme:window.location.protocol.replace(":",""),path:`${s}${P++}.${u}`}));d&&(this.editor.setModel(d),(o=this.contentChangeDisposable)==null||o.dispose(),this.contentChangeDisposable=this.editor.onDidChangeModelContent(()=>this.onChange()))}}setTypeCheck(t){var i,o;const e={noSemanticValidation:!this.state.alive||!t,noSyntaxValidation:!this.state.alive};(i=this.monacoTS)==null||i.typescriptDefaults.setDiagnosticsOptions(e),(o=this.monacoTS)==null||o.javascriptDefaults.setDiagnosticsOptions({noSemanticValidation:!this.state.alive||!t,noSyntaxValidation:!this.state.alive})}setEditorTypings(t=""){var n,r,s,u;const e=K(t),i=`${t}.d.ts`,o=[];for(const c of Object.keys(this.typings))e&&(c==="global.d.ts"||c.startsWith("script.js.global")&&c!==i)||o.push({filePath:c,content:this.typings[c]});if((r=(n=this.monacoTS)==null?void 0:n.typescriptDefaults)!=null&&r.setExtraLibs)this.monacoTS.typescriptDefaults.setExtraLibs(o);else if((u=(s=this.monacoTS)==null?void 0:s.typescriptDefaults)!=null&&u.addExtraLib){const c=this.monacoTS.typescriptDefaults.getExtraLibs();o.forEach(d=>{!c[d.filePath]&&this.monaco&&this.monacoTS.typescriptDefaults.addExtraLib(d.content,d.filePath)})}}undo(){var t;(t=this.editor)==null||t.trigger("toolbar","undo",null)}redo(){var t;(t=this.editor)==null||t.trigger("toolbar","redo",null)}insertTextIntoEditor(t){if(!this.editor||!this.monaco)return;const e=this.editor.getSelection();if(e){const i=new this.monaco.Range(e.startLineNumber,e.startColumn,e.endLineNumber,e.endColumn);this.editor.executeEdits("",[{range:i,text:t,forceMoveMarkers:!0}])}this.editor.focus()}highlightText(t){var o;if(!this.editor||!this.monaco)return 0;const e=t?(o=this.editor.getModel())==null?void 0:o.findMatches(t,!0,!1,!1,null,!0):void 0;if(e!=null&&e.length)return e.forEach(n=>{var r;return(r=this.editor)==null?void 0:r.setSelection(n.range)}),this.editor.revealLine(e[0].range.startLineNumber),e.length;const i=this.editor.getPosition();if(i){const n=i.lineNumber,r=i.column;this.editor.setSelection(new this.monaco.Range(n,r,n,r))}return 0}showInlineDiff(t){if(!this.editor||!this.monaco)return;const e=this.editor,i=this.monaco;this.hideInlineDiff(),g(async()=>{const{InlineDiffController:o,INLINE_DIFF_CSS:n}=await import("./inlineDiffController-DBLpPOe2.js");return{InlineDiffController:o,INLINE_DIFF_CSS:n}},__vite__mapDeps([16,1,17]),import.meta.url).then(({InlineDiffController:o,INLINE_DIFF_CSS:n})=>{if(!this.inlineDiffCssInjected){const s=document.createElement("style");s.textContent=n,s.setAttribute("data-iob-aichat","inline-diff"),document.head.appendChild(s),this.inlineDiffCssInjected=!0}const r=new o(e,i,{range:t.range,originalText:t.originalText,modifiedText:t.modifiedText,onAccepted:()=>{var s;this.inlineDiffInstance=null,(s=t.onAccepted)==null||s.call(t)},onRejected:()=>{var s;this.inlineDiffInstance=null,(s=t.onRejected)==null||s.call(t)}});this.inlineDiffInstance=r,r.show()}).catch(()=>{})}hideInlineDiff(){if(this.inlineDiffInstance){try{this.inlineDiffInstance.dispose()}catch{}this.inlineDiffInstance=null}}showInlineChatWidget(){if(!this.editor||!this.monaco||!this.props.onInlineAsk)return;if(this.inlineChatWidgetInstance){this.inlineChatWidgetInstance.show();return}const t=this.editor,e=this.monaco,i=this.props.onInlineAsk,o=this.props.onAiAction;g(async()=>{const{InlineChatWidget:n}=await import("./inlineChatWidget-Cu6rb4Ar.js");return{InlineChatWidget:n}},__vite__mapDeps([18,1,17]),import.meta.url).then(({InlineChatWidget:n})=>{const r=new n(t,e,{onSubmit:async s=>i({question:s.question,selectedCode:s.selectedCode}),onEscalateToChat:s=>{o&&o({action:"ask",code:s.selectedCode,question:s.question,rangeLabel:s.range?`lines ${s.range.startLineNumber}-${s.range.endLineNumber}`:"whole file"})}});this.inlineChatWidgetInstance=r,r.show()}).catch(()=>{})}registerAiActions(){if(!this.editor||!this.monaco||!this.props.onAiAction)return;const t=this.monaco,e=(o,n={})=>{if(!this.editor||!this.props.onAiAction)return;const r=this.editor.getModel();if(!r)return;const s=this.editor.getSelection(),u=s&&!s.isEmpty();let c,d,l,a="selection";if(u)c=r.getValueInRange(s),d=s.startLineNumber===s.endLineNumber?`line ${s.startLineNumber}`:`lines ${s.startLineNumber}-${s.endLineNumber}`,l={startLine:s.startLineNumber,startColumn:s.startColumn,endLine:s.endLineNumber,endColumn:s.endColumn},a="selection";else{const h=this.editor.getPosition();let y=null;if(h)try{y=V(r.getValue(),h.lineNumber)}catch{}if(y){const f=y.startLine,b=y.endLine,D=r.getLineMaxColumn(b),C=new t.Range(f,1,b,D);c=r.getValueInRange(C),d=f===b?`line ${f}`:`lines ${f}-${b}`,l={startLine:f,startColumn:1,endLine:b,endColumn:D},a="codelens"}else c=r.getValue(),d="whole file",a="none"}this.props.onAiAction({action:o,code:c,rangeLabel:d,range:l,kind:a,...n})},i=[{id:"iobroker.ai.inline",label:`🤖 ${p.I18n.t("AI: Inline chat…")}`,keybindings:[t.KeyMod.CtrlCmd|t.KeyMod.Alt|t.KeyCode.KeyI],order:1,run:()=>{if(this.props.onInlineAsk)this.showInlineChatWidget();else{const o=window.prompt(p.I18n.t("Ask the AI about the selected code:"));o&&o.trim()&&e("ask",{question:o.trim()})}}},{id:"iobroker.ai.explain",label:`💡 ${p.I18n.t("AI: Explain")}`,keybindings:[t.KeyMod.CtrlCmd|t.KeyMod.Alt|t.KeyCode.KeyE],order:2,run:()=>e("explain")},{id:"iobroker.ai.refactor",label:`🔧 ${p.I18n.t("AI: Refactor")}`,keybindings:[t.KeyMod.CtrlCmd|t.KeyMod.Alt|t.KeyCode.KeyR],order:3,run:()=>e("refactor")},{id:"iobroker.ai.comment",label:`💬 ${p.I18n.t("AI: Add comments")}`,keybindings:[t.KeyMod.CtrlCmd|t.KeyMod.Alt|t.KeyCode.KeyC],order:4,run:()=>e("comment")},{id:"iobroker.ai.fix",label:`🛠️ ${p.I18n.t("AI: Fix problem")}`,keybindings:[t.KeyMod.CtrlCmd|t.KeyMod.Alt|t.KeyCode.KeyF],order:5,run:()=>{var n,r;let o;try{const s=(n=this.editor)==null?void 0:n.getModel(),u=(r=this.editor)==null?void 0:r.getPosition();if(s&&u){const d=t.editor.getModelMarkers({resource:s.uri}).find(l=>u.lineNumber>=l.startLineNumber&&u.lineNumber<=l.endLineNumber);d&&(o=d.message)}}catch{}e("fix",{diagnostic:o})}},{id:"iobroker.ai.tests",label:`✅ ${p.I18n.t("AI: Suggest tests")}`,order:6,run:()=>e("tests")}];for(const o of i)try{this.editor.addAction({id:o.id,label:o.label,contextMenuGroupId:"aichat",contextMenuOrder:o.order,keybindings:o.keybindings,run:()=>o.run()})}catch{}}getEditorSelection(){if(!this.editor)return null;const t=this.editor.getSelection();if(!t||t.isEmpty())return null;const e=this.editor.getModel();return e?{text:e.getValueInRange(t),range:{startLine:t.startLineNumber,startColumn:t.startColumn,endLine:t.endLineNumber,endColumn:t.endColumn}}:null}getEditorContent(){var t,e;return((e=(t=this.editor)==null?void 0:t.getModel())==null?void 0:e.getValue())??""}getCursorPosition(){var e;const t=(e=this.editor)==null?void 0:e.getPosition();return t?{line:t.lineNumber,column:t.column}:null}highlightLineRange(t,e){if(!this.editor||!this.monaco)return!1;const i=this.editor.getModel();if(!i)return!1;const o=i.getLineCount(),n=Math.max(1,Math.min(t,o)),r=Math.max(n,Math.min(e,o)),s=i.getLineMaxColumn(r);return this.editor.setSelection(new this.monaco.Range(n,1,r,s)),this.editor.revealLineInCenter(n),!0}goToLine(t,e=1){if(!this.editor||!this.monaco)return!1;const i=this.editor.getModel();if(!i)return!1;const o=i.getLineCount(),n=Math.max(1,Math.min(t,o));return this.editor.setPosition({lineNumber:n,column:e}),this.editor.revealLineInCenter(n),this.editor.focus(),!0}replaceSelection(t){if(!this.editor||!this.monaco)return!1;const e=this.editor.getSelection();if(!e)return!1;const i=new this.monaco.Range(e.startLineNumber,e.startColumn,e.endLineNumber,e.endColumn);return this.editor.executeEdits("",[{range:i,text:t,forceMoveMarkers:!0}]),this.editor.focus(),!0}getDiagnostics(){if(!this.editor||!this.monaco)return[];const t=this.editor.getModel();if(!t)return[];const e=this.monaco.editor.getModelMarkers({resource:t.uri}),i={8:"error",4:"warning",2:"info",1:"hint"};return e.map(o=>({line:o.startLineNumber,column:o.startColumn,endLine:o.endLineNumber,endColumn:o.endColumn,severity:i[o.severity]||"info",message:o.message,...o.source?{source:o.source}:{}}))}async getDocumentSymbols(){var i;if(!this.editor||!this.monaco)return[];const t=this.editor.getModel();if(!t)return[];const e=[];try{const o=this.monaco.languages,n=(i=o.getDocumentSymbolProviders)==null?void 0:i.call(o,t);if(n!=null&&n.length){const r={0:"file",1:"module",2:"namespace",3:"package",4:"class",5:"method",6:"property",7:"field",8:"constructor",9:"enum",10:"interface",11:"function",12:"variable",13:"constant",14:"string",15:"number",16:"boolean",17:"array",18:"object",19:"key",20:"null",21:"enum-member",22:"struct",23:"event",24:"operator",25:"type-parameter"};for(const s of n){const u={isCancellationRequested:!1},c=await s.provideDocumentSymbols(t,u);if(!c)continue;const d=l=>{var a;for(const h of l)e.push({name:h.name,kind:r[h.kind]||String(h.kind),line:h.range.startLineNumber,endLine:h.range.endLineNumber,...h.detail?{detail:h.detail}:{}}),(a=h.children)!=null&&a.length&&d(h.children)};if(d(c),e.length)break}}}catch{}if(e.length===0){const n=t.getValue().split(`
|
|
3
3
|
`),r=[{re:/^(?:export\s+)?(?:async\s+)?function\s+(\w+)/,kind:"function"},{re:/^(?:export\s+)?class\s+(\w+)/,kind:"class"},{re:/^(?:export\s+)?(?:const|let|var)\s+(\w+)/,kind:"variable"}];for(let s=0;s<n.length;s++){const u=n[s].trim();for(const{re:c,kind:d}of r){const l=c.exec(u);if(l!=null&&l[1]){e.push({name:l[1],kind:d,line:s+1,endLine:s+1});break}}}}return e}showDecorators(){var e;const t=[];if(this.location&&this.monaco&&(t.push({range:new this.monaco.Range(this.location.lineNumber+1,(this.location.columnNumber||0)+1,this.location.lineNumber+1,1e3),options:{isWholeLine:!1,className:this.props.isDark?"monacoCurrentLineDark":"monacoCurrentLine"}}),t.push({range:new this.monaco.Range(this.location.lineNumber+1,0,this.location.lineNumber+1,0),options:{isWholeLine:!0,className:this.props.isDark?"monacoCurrentFullLineDark":"monacoCurrentFullLine"}})),(e=this.breakpoints)==null||e.forEach(i=>{this.monaco&&t.push({range:new this.monaco.Range(i.location.lineNumber+1,0,i.location.lineNumber+1,100),options:{isWholeLine:!0,glyphMarginClassName:this.props.isDark?"monacoBreakPointDark":"monacoBreakPoint"}})}),this.editor){const i=this.editor.getModel();i&&(this.decorations=i.deltaDecorations(this.decorations,t))}}initNewScript(t,e){var i;this.setState({name:t}),this.originalCode=e||"",(i=this.editor)==null||i.setValue(e||""),this.highlightText(this.lastSearch),this.showDecorators(),this.setEditorTypings(t)}scrollToLineIfNeeded(t){if(this.editor){const e=this.editor.getVisibleRanges();(!e||!e[0]||e[0].startLineNumber>t||t>e[0].endLineNumber)&&this.editor.revealLineInCenter(t)}}UNSAFE_componentWillReceiveProps(t){const e={};this.state.name!==t.name&&this.initNewScript(t.name,t.code),JSON.stringify(t.runningInstances)!==this.runningInstancesStr&&(this.runningInstancesStr=JSON.stringify(t.runningInstances),this.state.typingsLoaded||this.loadTypings(t.runningInstances)),this.editor&&!t.changed&&(t.code!==this.originalCode||t.code!==this.editor.getValue())&&(this.originalCode=t.code||"",this.editor.setValue(this.originalCode),this.showDecorators(),this.location&&this.scrollToLineIfNeeded(this.location.lineNumber+1)),t.searchText!==this.lastSearch&&(this.lastSearch=t.searchText||"",this.highlightText(this.lastSearch)),JSON.stringify(t.location)!==JSON.stringify(this.location)&&JSON.stringify(t.breakpoints)!==JSON.stringify(this.breakpoints)?(this.location=t.location||void 0,this.breakpoints=t.breakpoints,this.showDecorators(),this.editor&&this.location&&this.scrollToLineIfNeeded(this.location.lineNumber+1)):JSON.stringify(t.breakpoints)!==JSON.stringify(this.breakpoints)?(this.breakpoints=t.breakpoints,this.showDecorators()):JSON.stringify(t.location)!==JSON.stringify(this.location)&&(this.location=t.location||void 0,this.showDecorators(),this.editor&&this.location&&this.scrollToLineIfNeeded(this.location.lineNumber+1)),this.state.language!==(t.language||"javascript")?(this.setState({language:t.language||"javascript"}),e.language=t.language||"javascript"):this.state.readOnly!==(t.readOnly||!1)?(this.setState({readOnly:t.readOnly||!1}),e.readOnly=t.readOnly):this.state.isDark!==(t.isDark||!1)&&(this.setState({isDark:t.isDark||!1}),e.isDark=t.isDark),this.setEditorOptions(e),t.aiCompletionsEnabled!==this.props.aiCompletionsEnabled&&(t.aiCompletionsEnabled&&this.monaco&&!this.inlineProviderDisposable?g(async()=>{const{registerAiInlineProvider:i}=await import("./AiInlineProvider-DkgjVSFQ.js");return{registerAiInlineProvider:i}},[],import.meta.url).then(({registerAiInlineProvider:i})=>{this.monaco&&(this.inlineProviderDisposable=i(this.monaco,this.props.socket,this.props.runningInstances))}).catch(()=>{}):!t.aiCompletionsEnabled&&this.inlineProviderDisposable&&(this.inlineProviderDisposable.dispose(),this.inlineProviderDisposable=null)),this.insert!==t.insert&&(this.insert=t.insert||"",this.insert&&(console.log(`Insert text: ${this.insert}`),setTimeout(i=>{this.insertTextIntoEditor(i),setTimeout(()=>this.props.onInserted&&this.props.onInserted(),100)},100,this.insert)))}onChange(){var t,e;!this.props.readOnly&&this.editor&&((e=(t=this.props).onChange)==null||e.call(t,this.editor.getValue()))}renderErrorDialog(){return this.state.showError?this.state.showError.full?m.jsxs(T,{open:!0,maxWidth:"md",onClose:()=>this.setState({showError:null}),children:[m.jsx(N,{children:this.state.showError.title||p.I18n.t("Error")}),m.jsx(M,{children:m.jsx("pre",{children:m.jsx("code",{children:this.state.showError.message})})}),m.jsx(A,{children:m.jsxs(S,{variant:"contained",startIcon:m.jsx(_,{}),onClick:()=>this.setState({showError:null}),children:[p.I18n.t("Close")," "]})})]}):m.jsx(O,{open:!0,autoHideDuration:5e3,onClose:()=>this.setState({showError:null}),message:this.state.showError.title,action:m.jsxs(k.Fragment,{children:[m.jsx(S,{color:"secondary",size:"small",onClick:()=>this.setState({showError:{...this.state.showError,full:!0}}),children:p.I18n.t("More")}),m.jsx(x,{size:"small","aria-label":"close",color:"inherit",onClick:()=>this.setState({showError:null}),children:m.jsx(_,{fontSize:"small"})})]})}):null}render(){var t;return!((t=this.monacoTS)!=null&&t.typescriptDefaults)||!this.props.runningInstances?(setTimeout(()=>{this.monaco=window.monaco,this.forceUpdate()},200),null):(this.props.triggerPrettier!==this.triggerPrettier&&(this.triggerPrettier=this.props.triggerPrettier,setTimeout(()=>this.doPrettier().catch(e=>console.error("Error formatting code:",e)),50)),m.jsxs("div",{ref:this.monacoDiv,style:{...this.props.style,width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:[this.renderErrorDialog(),!this.state.check&&m.jsx(j,{size:"small",title:p.I18n.t("Check is not active, because javascript adapter is disabled"),style:{bottom:10,right:10,opacity:.5,position:"absolute",zIndex:1,background:"red",color:"white"},color:"secondary",children:m.jsx(R,{})})]}))}}export{tt as default};
|