iobroker.javascript 9.2.3 → 9.2.4
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 +6 -14
- package/admin/assets/{AiChatPanel-C4zUsNmN.js → AiChatPanel-B4vPXgLz.js} +1 -1
- package/admin/assets/{ScriptEditor-C6W68ya0.js → ScriptEditor-CmEeMfC2.js} +1 -1
- package/admin/assets/{ScriptEditorVanillaMonaco-DYTcDqp_.js → ScriptEditorVanillaMonaco-C22Gpet7.js} +2 -2
- package/admin/assets/{index-crBQrXKG.js → index-7mrTpzQy.js} +1 -1
- package/admin/assets/{index-CUau9-il.js → index-BTQOdA7v.js} +28 -28
- package/admin/assets/{index-BXfqctma.js → index-Dggem6AX.js} +1 -1
- package/admin/assets/{stateHoverProvider-BYBqzJuX.js → stateHoverProvider-DxTNxyYN.js} +1 -1
- package/admin/custom/assets/{Components-jfkoGyES.js → Components-CGiJE5Zh.js} +1 -1
- package/admin/custom/assets/{index-CS_GBN2m.js → index-B6NrrORQ.js} +1 -1
- package/admin/custom/assets/index-CT5PwRfY.js +964 -0
- package/admin/custom/assets/{index-ChQotUCl.js → index-DTbSiEk2.js} +1 -1
- package/admin/custom/assets/{localSharedImportMap-BeObsVNc.js → localSharedImportMap-ChjFDKsq.js} +1 -1
- package/admin/custom/assets/{virtualExposes-wYe_Np-4.js → virtualExposes-D402kVGY.js} +1 -1
- package/admin/custom/assets/{virtual_mf-REMOTE_ENTRY_ID_ConfigCustomJavascriptSet__customComponents_js-BcRVut8U.js → virtual_mf-REMOTE_ENTRY_ID_ConfigCustomJavascriptSet__customComponents_js-ClQrb2n1.js} +2 -2
- package/admin/custom/customComponents.js +1 -1
- package/admin/i18n/es.json +77 -77
- package/admin/tab.html +1 -1
- package/build/lib/debugger.js +1 -1
- package/build/lib/debugger.js.map +1 -1
- package/build/lib/eventObj.js +10 -2
- package/build/lib/eventObj.js.map +1 -1
- package/build/lib/inspect.js +3 -3
- package/build/lib/inspect.js.map +1 -1
- package/build/lib/sandbox.js +169 -62
- package/build/lib/sandbox.js.map +1 -1
- package/build/main.js +63 -19
- package/build/main.js.map +1 -1
- package/build/types.d.ts +4 -0
- package/io-package.json +14 -14
- package/package.json +11 -11
- package/admin/custom/assets/index-qs6J40Tp.js +0 -964
package/README.md
CHANGED
|
@@ -27,6 +27,12 @@ Executes Javascript, Typescript Scripts.
|
|
|
27
27
|
-->
|
|
28
28
|
|
|
29
29
|
## Changelog
|
|
30
|
+
### 9.2.4 (2026-06-08)
|
|
31
|
+
* (arteck) Performance optimizations part 2
|
|
32
|
+
* (arteck) fix filter in tab scripts
|
|
33
|
+
* (@GermanBluefox) Fixed a subscription leak on script stop for RegExp-notation string ids (dispatch index)
|
|
34
|
+
* (@GermanBluefox) `extendObject` no longer throws into the script when the object contains non-clonable values (e.g. functions)
|
|
35
|
+
|
|
30
36
|
### 9.2.3 (2026-05-27)
|
|
31
37
|
* (arteck) Performance optimizations done
|
|
32
38
|
* (@GermanBluefox) Added on mouse over the value of the state
|
|
@@ -51,20 +57,6 @@ Executes Javascript, Typescript Scripts.
|
|
|
51
57
|
* (Eistee82) `search_datapoints` covers every object type (channels, devices, folders, enums, …) and matches on role; `get_object_info` lists children for containers — fixes finding aliases/motion-sensors modeled as channels
|
|
52
58
|
* (Eistee82) Non-chat model filter expanded (embeddings, image/audio/video/TTS, transcription, moderation, web-search, Ollama single-task models, …)
|
|
53
59
|
|
|
54
|
-
### 9.2.0 (2026-04-11)
|
|
55
|
-
* (Eistee82) AI Chat panel with multi-provider support, tool calling, inline completions, and smart-apply
|
|
56
|
-
* (Eistee82) Fix: prevent duplicate 'Stopping script' log when script is not running
|
|
57
|
-
* (Eistee82) Fix: only restart scripts on the instance that owns them
|
|
58
|
-
* (Eistee82) Added OID display mode toggle for Blockly editor: 4 display modes (Name, Name path, State ID, Full ID) with toolbar dropdown, context menu, optional object icons, and translations in 11 languages
|
|
59
|
-
* (Eistee82) Node 25 compatibility: replaced deprecated rmdirSync with rmSync in build tasks
|
|
60
|
-
* (@GermanBluefox) Added support for plain import/export
|
|
61
|
-
* (@GermanBluefox) Correcting error in configuration
|
|
62
|
-
* (@GermanBluefox) disallow writing into node_modules folder by scripts
|
|
63
|
-
* (@GermanBluefox) Correcting start of the script more than one time if restart is triggered
|
|
64
|
-
* (@GermanBluefox) All delayed writings are stopped by the script stop
|
|
65
|
-
* (@GermanBluefox) Added check if a script has been modified by another user/window
|
|
66
|
-
* (@GermanBluefox) Make the instance number more prominent
|
|
67
|
-
|
|
68
60
|
## License
|
|
69
61
|
The MIT License (MIT)
|
|
70
62
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as Se,j as i}from"./createSvgIcon-DYs_tNrE.js";import{k as A,j as te,b as ne,c as xe,l as Ue}from"./iobroker_javascript__loadShare__react__loadShare__.mjs-CTZOFJS2.js";import{z as $,P as ve,o as we,a0 as ct,a1 as lt,i as We,J as dt,r as ut,s as mt,u as pt,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 i}from"./createSvgIcon-DYs_tNrE.js";import{k as A,j as te,b as ne,c as xe,l as Ue}from"./iobroker_javascript__loadShare__react__loadShare__.mjs-CTZOFJS2.js";import{z as $,P as ve,o as we,a0 as ct,a1 as lt,i as We,J as dt,r as ut,s as mt,u as pt,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-BTQOdA7v.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-CeYV4czE.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(i.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(i.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"),Ct=Se(i.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"),It=Se(i.jsx("path",{d:"M9.01 14H2v2h7.01v3L13 15l-3.99-4zm5.98-1v-3H22V8h-7.01V5L11 9z"}),"CompareArrows"),Tt=Se(i.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(i.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(i.jsx("path",{d:"M2.01 21 23 12 2.01 3 2 10l15 2-15 2z"}),"Send"),Rt=Se(i.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"),Nt=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,Ae=null,Le=null,Me=null;function Dt(){$e=null,Ae=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",{}),o=((t==null?void 0:t.providers)||[]).map(d=>d.provider),s=((t==null?void 0:t.providers)||[]).find(d=>d.provider==="custom");return o.length?($e={providers:o,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 o=[],s={},d=[],m=(a,y)=>{for(const l of a)zt(l)&&(s[l]||(o.push(l),s[l]=y))},c=[],p=(a,y)=>{c.push(r.sendTo(t,"testApiConnection",{provider:a==="custom"?"openai":a}).then(l=>{l.models?m(l.models,a):l.error&&d.push(`${y||a}: ${l.error}`)}).catch(l=>{d.push(`${y||a}: ${String(l)}`)}))},g={openai:"OpenAI",anthropic:"Anthropic",gemini:"Gemini",deepseek:"DeepSeek",custom:"Custom"};for(const a of n.providers)p(a,g[a]);return await Promise.all(c),o.sort(),{models:o,providerMap:s,errors:d}}async function Re(r,e,n){var o;return await r.sendTo(e,"chatCompletion",{timeout:n.timeout||6e5,model:n.model,provider:n.provider,messages:n.messages,...n.baseUrl?{baseUrl:n.baseUrl}:{},...(o=n.tools)!=null&&o.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","","香"),o=await r.getObjectViewSystem("folder","","香"),s=await r.getObjectViewSystem("enum","","香");return Me=Object.assign(e,n,t,o,s),Me}async function nt(r){return tt(r)}function Ie(r,e){return r&&typeof r=="object"?r[e]||r.en:r||""}async function Ye(r){var S,b,v,H;if(Ae)return Ae;const e=u.I18n.getLanguage(),n=await tt(r),t=Object.keys(n).sort(),o=new gt,s=[],d=["UNREACH_STICKY"],m=[yt.Types.info],c=[],p=[],g=[],a=[];t.forEach(E=>{var I,x,w;((I=n[E])==null?void 0:I.type)==="enum"?c.push(E):(w=(x=n[E])==null?void 0:x.common)!=null&&w.smartName&&a.push(E)}),c.forEach(E=>{E.startsWith("enum.rooms.")?p.push(E):E.startsWith("enum.functions.")&&g.push(E);const I=n[E].common.members;I!=null&&I.length&&I.forEach(x=>{n[x]&&!a.includes(x)&&a.push(x)})});const y={id:"",objects:n,_keysOptional:t,_usedIdsOptional:s,ignoreIndicators:d,excludedTypes:m},l=[];a.forEach(E=>{y.id=E;const I=o.detect(y);I&&I.forEach(x=>{var de;const w=(de=x.states.find(T=>T.id))==null?void 0:de.id;if(!w||l.find(T=>T.id===w))return;const M=n[w],re={id:w,name:Ie(M.common.name,e),type:M.type,deviceType:x.type,states:x.states.filter(T=>T.id).map(T=>({id:T.id,name:T.name,role:T.defaultRole,type:n[T.id].common.type,unit:n[T.id].common.unit,read:n[T.id].common.read??!0,write:n[T.id].common.write??!0}))},Y=w.split(".");let _,G;(M.type==="channel"||M.type==="state")&&(Y.pop(),_=Y.join("."),n[_]&&(n[_].type==="channel"||n[_].type==="folder")?(Y.pop(),G=Y.join("."),(!n[G]||n[G].type!=="device"&&n[_].type!=="folder")&&(G=void 0)):_=void 0);const le=p.find(T=>{var U,X,Q;return(U=n[T].common.members)!=null&&U.includes(w)||_&&((X=n[T].common.members)!=null&&X.includes(_))?!0:G&&((Q=n[T].common.members)==null?void 0:Q.includes(G))});le&&(re.room=Ie(n[le].common.name,e));const K=g.find(T=>{var U,X,Q;return(U=n[T].common.members)!=null&&U.includes(w)||_&&((X=n[T].common.members)!=null&&X.includes(_))?!0:G&&((Q=n[T].common.members)==null?void 0:Q.includes(G))});K&&(re.function=Ie(n[K].common.name,e)),l.push(re)})});for(let E=0;E<l.length;E++){const I=l[E];if(I.type==="state"||I.type==="channel"){const x=I.id.split(".");x.pop();const w=n[x.join(".")];if(w&&(w.type==="channel"||w.type==="device"||w.type==="folder")){I.name=Ie(((S=w.common)==null?void 0:S.name)||I.name,e),x.pop();const M=n[x.join(".")];(M==null?void 0:M.type)==="device"&&((b=M.common)!=null&&b.icon)&&(I.name=Ie(((v=M.common)==null?void 0:v.name)||I.name,e))}else I.name=Ie(((H=w==null?void 0:w.common)==null?void 0:H.name)||I.name,e)}}return Ae=l,l}async function At(){return Le||(Le=(await Nt).default,Le)}function Ge(){return Mt[u.I18n.getLanguage()]||"English"}function Ut(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-C22Gpet7.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-BTQOdA7v.js";import"./virtual_mf-REMOTE_ENTRY_ID_iobroker_javascript__remoteEntry_js-CeYV4czE.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-DYTcDqp_.js → ScriptEditorVanillaMonaco-C22Gpet7.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-CUau9-il.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-CeYV4czE.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-BYBqzJuX.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-CUau9-il.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-BYBqzJuX.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-DxTNxyYN.js","./iobroker_javascript__loadShare___mf_0_iobroker_mf_1_adapter_mf_2_react_mf_2_v5__loadShare__.mjs-DkBjPSMw.js","./index-BTQOdA7v.js","./virtual_mf-REMOTE_ENTRY_ID_iobroker_javascript__remoteEntry_js-CeYV4czE.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-BTQOdA7v.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-CeYV4czE.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-DxTNxyYN.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-BTQOdA7v.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-DxTNxyYN.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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as n}from"./createSvgIcon-DYs_tNrE.js";import{c as E,h as yt,j as M,m as nt,k as lt,l as Dt,b as ut,o as xt}from"./iobroker_javascript__loadShare__react__loadShare__.mjs-CTZOFJS2.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{u as kt,a as St,M as Y,C as et,G as Nt,b as $t,c as bt,I as qt,S as J,d as Bt,e as ft,j as Mt,D as Ht,f as Wt}from"./index-CUau9-il.js";import{_ as wt,b as Ct,h as vt,i as jt,p as Tt,f as Et,g as mt,o as Pt,Y as Ut,Z as Ft,C as Jt,D as st}from"./iobroker_javascript__loadShare___mf_0_mui_mf_1_material__loadShare__.mjs-CV1_X-Lf.js";import{I as Lt}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-CeYV4czE.js";import"./preload-helper-BDBacUwf.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 zt(e){const s=kt().getMonitor(),[i,a]=St(s,e);return E(()=>s.subscribeToOffsetChange(a)),E(()=>s.subscribeToStateChange(a)),i}let V;function Gt(){return V||(V=new Image,V.src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="),V}const Kt="_wrapperRules_nnott_1",Qt="_rootWrapper_nnott_9",Yt="_addClass_nnott_14",ot={wrapperRules:Kt,rootWrapper:Qt,addClass:Yt},Zt="_switchesItem_10ls3_1",Xt="_switchesItemActive_10ls3_28",Vt="_iconTheme_10ls3_36",it={switchesItem:Zt,switchesItemActive:Xt,iconTheme:Vt},It=({name:e,id:t,active:s,icon:i,adapter:a,socket:o,onDoubleClick:c,title:l,onTouchMove:d,style:j})=>n.jsxs("div",{onDoubleClick:c,onTouchMove:d,title:l?u.I18n.t(l):void 0,className:u.Utils.clsx(it.switchesItem,s&&it.switchesItemActive,`block-${t}`),children:[n.jsx(Y,{iconName:i,className:it.iconTheme,adapter:a,socket:o,style:j}),n.jsx("span",{children:e?u.I18n.t(e):""})]},t),Rt="_cardStyle_8rq8v_1",tn="_cardStyleActive_8rq8v_17",nn="_controlMenu_8rq8v_22",en="_closeBtn_8rq8v_31",sn="_isDelete_8rq8v_73",on="_drag_mobile_8rq8v_90",G={cardStyle:Rt,cardStyleActive:tn,controlMenu:nn,closeBtn:en,isDelete:sn,drag_mobile:on};function K(e,t,s){let i;switch(e){case"actions":if(s==="else")return i={...t,actions:{...t[e],else:[...t[e].else]}},i;if(s==="then")return i={...t,actions:{...t[e],then:[...t[e].then]}},i;throw console.error(`Unknown additionalParameter: ${s}`),new Error(`Unknown additionalParameter: ${s}`);case"triggers":return i={...t,triggers:[...t.triggers]},i;case"conditions":return i={...t,conditions:[...t.conditions]},i;default:throw new Error(`Unknown name: ${e}`)}}function z(e,t,s,i){var a;switch(e){case"actions":return t.actions[s]=t.actions[s].filter(o=>o._id!==i),t;case"conditions":return t.conditions[s]=(a=t.conditions[s])==null?void 0:a.filter(o=>o._id!==i),t;default:return t.triggers=t.triggers.filter(o=>o._id!==i),t}}function cn(e,t,s){const{_id:i,acceptedBy:a}=e;let o;if(!a||!t[a])return console.warn(`Cannot find ${a}`),t;switch(a){case"actions":if(o=t.actions[s].find(c=>c._id===i),!o)console.warn(`Cannot find ${i}`);else{const c=t.actions[s].indexOf(o);t.actions[s][c]=e}return t;case"conditions":if(o=t.conditions[s].find(c=>c._id===i),!o)console.warn(`Cannot find ${i}`);else{const c=t.conditions[s].indexOf(o);t.conditions[s][c]=e}return t;default:if(o=t.triggers.find(c=>c._id===i),!o)console.warn(`Cannot find ${i}`);else{const c=t.triggers.indexOf(o);t.triggers[c]=e}return t}}const Ot=yt(e=>{var N;const{setUserRules:t,userRules:s,_id:i,id:a,blockValue:o,active:c,acceptedBy:l,isTourOpen:d,setTourStep:j,tourStep:O}=e,[I,_]=M(null),{blocks:r,socket:k,onUpdate:H,setOnUpdate:w,onDebugMessage:f,enableSimulation:x}=nt(et),p=lt(h=>r==null?void 0:r.find(b=>b.getStaticData().id===h),[r]),g=lt(h=>{const b=cn(h,s,o);b&&t(b)},[s]),C=h=>{h.currentTarget!==I&&_(h.currentTarget)},q=()=>_(null),T=Dt(()=>{const h=p(a)||Nt;return n.jsx(h,{...e,notFound:!p(a),isTourOpen:d,setTourStep:j,tourStep:O,onUpdate:H,setOnUpdate:w,enableSimulation:x,onDebugMessage:f,onChange:g,className:void 0,socket:k})},[s,H,f,x]),[S,B]=M(!1);return n.jsxs("div",{onMouseMove:C,onMouseEnter:C,onMouseLeave:q,onMouseDown:h=>{if(h.ctrlKey){let b;const v=K(l,s,o);l==="conditions"?(b=v.conditions[o].find(m=>m._id===i),b&&v.conditions[o].splice(v.conditions[o].indexOf(b),0,{...b,_id:Date.now()})):l==="actions"?(b=v.actions[o].find(m=>m._id===i),b&&v.actions[o].splice(v.actions[o].indexOf(b),0,{...b,_id:Date.now()})):(b=v.triggers.find(m=>m._id===i),b&&v.triggers.splice(v[l].indexOf(b),0,{...b,_id:Date.now()})),t(v)}},id:"height",style:c?{width:(((N=document.getElementById("width"))==null?void 0:N.clientWidth)||0)-70}:void 0,className:`${G.cardStyle} ${c?G.cardStyleActive:null} ${S?G.isDelete:null}`,children:[n.jsx("div",{className:G.drag_mobile}),T,t&&n.jsx("div",{className:G.controlMenu,style:I?{opacity:1}:{opacity:0},children:n.jsx("div",{onClick:()=>{let h=K(l,s,o);h=z(l,h,o,i),B(!0),setTimeout(()=>{l==="triggers"&&w(!0),t(h)},300)},className:G.closeBtn})})]})}),rn={position:"fixed",pointerEvents:"none",zIndex:100,left:0,top:0,width:"100%",height:"100%"},an=(e,t,s)=>{if(!e||!t)return{display:"none"};let{x:i,y:a}=t;const o=`translate(${i}px, ${a}px)`;return{transform:o,WebkitTransform:o}},ln=e=>{const{itemType:t,isDragging:s,item:i,initialOffset:a,currentOffset:o,targetIds:c}=zt(d=>({item:d.getItem(),itemType:d.getItemType(),initialOffset:d.getInitialSourceClientOffset(),currentOffset:d.getSourceClientOffset(),isDragging:d.isDragging(),targetIds:d.getTargetIds()})),l=()=>t==="box"?c.length?n.jsx(Ot,{active:!0,...i,allBlocks:e.allBlocks}):n.jsx(It,{active:!0,...i,socket:e.socket}):null;return s?n.jsx("div",{style:rn,children:n.jsx("div",{style:an(a,o),children:l()})}):null},dn="_border_wrpm3_1",fn="_emptyBlockStyle_wrpm3_6",mn="_emptyBlock_wrpm3_6",gn="_selectOnChange_wrpm3_22",hn="_selectOnChangeHelp_wrpm3_28",_n="_selectOnChangeHelpIcon_wrpm3_34",pn="_emptyBlockNone_wrpm3_49",un="_mainBlockItemRules_wrpm3_55",xn="_nameBlockItems_wrpm3_63",bn="_contentBlockItem_wrpm3_73",wn="_wrapperMargin_wrpm3_81",Cn="_contentHeightOn_wrpm3_87",vn="_contentHeightOff_wrpm3_99",jn="_cardAdd_wrpm3_105",In="_blockCardAdd_wrpm3_125",On="_addClassOverflow_wrpm3_136",An="_addClassHeight_wrpm3_140",D={border:dn,emptyBlockStyle:fn,emptyBlock:mn,selectOnChange:gn,selectOnChangeHelp:hn,selectOnChangeHelpIcon:_n,emptyBlockNone:pn,mainBlockItemRules:un,nameBlockItems:xn,contentBlockItem:bn,wrapperMargin:wn,contentHeightOn:Cn,contentHeightOff:vn,cardAdd:jn,blockCardAdd:In,addClassOverflow:On,addClassHeight:An};function dt(e,t){const[s,i]=M(window.localStorage.getItem(t)?JSON.parse(window.localStorage.getItem(t)||""):e);return[s,o=>{window.localStorage.setItem(t,JSON.stringify(o)),i(o)},!!window.localStorage.getItem(t)]}function yn(e,t){let s=0,i=null,a;return function(...o){const c=Date.now();a=o,c-s>=t?(s=c,e.apply(this,o)):i||(i=setTimeout(()=>{s=Date.now(),i=null,e.apply(this,a)},t-(c-s)))}}function tt(e){if(Array.isArray(e))return e.map(t=>tt(t));if(typeof e=="function")return e.bind(null);if(e&&typeof e=="object"){const t={};return Object.keys(e).forEach(s=>{t[s]=tt(e[s])}),t}return e}const ct=yn((e,t)=>e(t),0);function R(e,t){const s=t.find(i=>i._id===e);return{card:s,index:s?t.indexOf(s):-1}}function rt(e,t,s,i,a,o,c,l,d){const{card:j,index:O}=R(e,s);if(!(O<t&&l<d)&&!(O>t&&l>d)&&j&&O!==t){const I=tt(s);I.splice(O,1),I.splice(t,0,j);const _=tt(a);switch(o){case"actions":_.actions[c]=I,ct(i,_);return;case"conditions":_.conditions[c]=I,ct(i,_);return;default:_.triggers=I,ct(i,_);return}}}const Dn="_drag_7xfhc_1",kn="_root_7xfhc_11",gt={drag:Dn,root:kn},At=({typeBlock:e,allProperties:t,id:s,isActive:i,setUserRules:a,userRules:o,children:c,_id:l,blockValue:d})=>{const{setOnUpdate:j}=nt(et),[{opacity:O},I,_]=$t({type:"box",item:()=>({...t,id:s,isActive:i,_id:l}),end:(w,f)=>{const{acceptedBy:x}=w,p=f.getDropResult();let g;if(!p)return typeof l=="number"&&!f.getTargetIds().length&&(g=K(x,o,d),g=z(x,g,d,l),a(g)),null;if(p.blockValue!==d){const C=typeof l=="number"?l:Date.now();g=K(x,o,p.blockValue);const q={id:w.id,acceptedBy:w.acceptedBy};switch(x){case"actions":return d&&(g=z("actions",g,d,C)),g=z("actions",g,p.blockValue,C),g.actions[p.blockValue].push({...q,_id:C}),a(g);case"conditions":return typeof d=="number"&&(g=z("conditions",g,d,C)),g=z("conditions",g,p.blockValue,C),g.conditions[p.blockValue].push({...q,_id:C}),a(g);default:return j(!0),g=z("triggers",g,p.blockValue,C),g.triggers.push({...q,_id:C}),a(g)}}},collect:w=>({opacity:w.isDragging()?.4:1,isDragging:w.isDragging()})}),r=ut(null),[,k]=bt({accept:"box",canDrop:()=>!1,hover({_id:w,acceptedBy:f},x){var T;if(!r.current||e!==f)return;const p=(T=r.current)==null?void 0:T.getBoundingClientRect(),g=(p.bottom-p.top)/2,C=x.getClientOffset(),q=((C==null?void 0:C.y)||0)-p.top;if(l&&w!==l)switch(f){case"actions":if(d==="then"||d==="else"){const{index:S}=R(l,o.actions[d]);S!==w&&rt(w,S,o[f][d],a,o,f,d,q,g)}return;case"conditions":if(typeof d=="number"){const{index:S}=R(l,o[f][d]);S!==w&&rt(w,S,o[f][d],a,o,f,d,q,g)}return;default:{const{index:S}=R(l,o[f]);S!==w&&rt(w,S,o[f],a,o,f,void 0,q,g);return}}}});E(()=>{_(Gt(),{captureDraggingState:!0})},[]),I(k(r));const H=window.innerWidth<600;return n.jsxs("div",{ref:H&&l?null:r,className:gt.root,style:{opacity:O},children:[n.jsx("div",{className:l?gt.drag:null,ref:l&&H?r:null}),c]})},Sn=({onClose:e,open:t})=>n.jsxs(wt,{open:t,onClose:e,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[n.jsx(Ct,{children:n.jsxs("div",{style:{fontSize:"1rem",fontFamily:'"Roboto", "Helvetica", "Arial", sans-serif',fontWeight:400,lineHeight:1.5,letterSpacing:"0.00938em"},children:[n.jsx("h3",{children:u.I18n.t("On condition change")}),n.jsx("div",{children:u.I18n.t("help_on_change")}),n.jsx("h3",{children:u.I18n.t("Just check")}),n.jsx("div",{children:u.I18n.t("help_just_check")})]})}),n.jsx(vt,{children:n.jsx(jt,{onClick:e,color:"primary",autoFocus:!0,startIcon:n.jsx(Lt,{}),children:u.I18n.t("OK")})})]}),Nn=({onClose:e,open:t})=>n.jsxs(wt,{open:t,onClose:e,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[n.jsx(Ct,{children:n.jsxs(Tt,{id:"alert-dialog-description",children:[n.jsx("h3",{children:u.I18n.t("On condition change")}),n.jsx("div",{children:u.I18n.t("help_on_change")}),n.jsx("h3",{children:u.I18n.t("Just check")}),n.jsx("div",{children:u.I18n.t("help_just_check")})]})}),n.jsx(vt,{children:n.jsx(jt,{onClick:e,color:"primary",autoFocus:!0,children:u.I18n.t("OK")})})]}),ht=({size:e,blockValue:t,boolean:s,typeBlock:i,userRules:a,setUserRules:o,animation:c,setTourStep:l,tourStep:d,isTourOpen:j,theme:O,themeType:I,themeName:_})=>{var W;const[r,k]=M(!1),[H,w]=M(!1),[f,x]=M(!1),[p,g]=M("");s===void 0&&(s=!0);const C=bt({accept:"box",drop:()=>({blockValue:t}),hover:({acceptedBy:A,_id:L},Z)=>{k(A===i),x(!!L),g(Z.getHandlerId()||"")},canDrop:({acceptedBy:A})=>(w(A===i),A===i),collect:A=>{var L;return{isOver:A.isOver(),canDrop:((L=A.getItem())==null?void 0:L.acceptedBy)===i,offset:A.getClientOffset(),targetId:A.getHandlerId()}}}),q=C[0],{canDrop:T,isOver:S,offset:B,targetId:N}=q,h=C[1];E(()=>{g("")},[B]);const b=T&&S;let v="";b?v=r?"#00fb003d":"#fb00002e":T?v=H?"#00fb003d":"#fb00002e":B&&(v=N===p?"#fb00002e":"");let m;return i==="actions"?m=a.actions[t]:i==="conditions"?m=a.conditions[t]:m=a.triggers,n.jsx("div",{ref:h,style:{backgroundColor:v},className:`${u.Utils.clsx(D.contentBlockItem,e&&D.addClassHeight)} ${s?c?D.contentHeightOn:null:D.contentHeightOff}`,children:n.jsxs("div",{className:D.wrapperMargin,children:[m.map(A=>n.jsx(At,{typeBlock:i,...A,blockValue:t,allProperties:A,userRules:a,setUserRules:o,children:n.jsx(Ot,{...A,isTourOpen:j,setTourStep:l,tourStep:d,settings:A,blockValue:t,userRules:a,setUserRules:o,theme:O,themeType:I,themeName:_})},A._id)),n.jsx("div",{style:b&&r&&!f?{height:((W=document.getElementById("height"))==null?void 0:W.clientHeight)||200}:void 0,className:`${D.emptyBlockStyle} ${b&&r&&!f?D.emptyBlock:D.emptyBlockNone}`})]})})},at=({size:e,typeBlock:t,name:s,nameAdditionally:i,additionally:a,border:o,userRules:c,setUserRules:l,iconName:d,adapter:j,socket:O,setTourStep:I,tourStep:_,isTourOpen:r,theme:k,themeType:H,themeName:w})=>{const[f,x,p]=dt(t==="actions"?!1:[],`additionallyClickItems_${t}`),[g,C]=M(!1),[q,T]=M(!1);E(()=>{if(t==="conditions"&&(f==null?void 0:f.length)!==c.conditions.length-1){const N=[];c.conditions.forEach((h,b)=>{b>0&&N.push({_id:Date.now(),open:!0})}),x([...f,...N])}t==="actions"&&!p&&c.actions.else.length&&x(!0)},[]);const[S,B]=M(!1);return n.jsxs("div",{className:`${u.Utils.clsx(D.mainBlockItemRules,e&&D.addClassOverflow)} ${o&&!e?D.border:null}`,children:[n.jsxs("span",{id:"width",className:D.nameBlockItems,children:[n.jsx(Y,{iconName:d,className:D.iconThemCard,adapter:j,socket:O}),s]}),t==="conditions"?n.jsxs("div",{style:{width:"100%"},children:[n.jsxs(Et,{variant:"standard",className:D.selectOnChange,value:c.justCheck||!1,onChange:N=>{const h=K("conditions",c);h.justCheck=N.target.value==="true",l(h)},children:[n.jsx(mt,{value:"false",children:u.I18n.t("on condition change")}),n.jsx(mt,{value:"true",children:u.I18n.t("just check")})]}),n.jsx(Pt,{size:"small",title:u.I18n.t("Explanation"),className:D.selectOnChangeHelp,onClick:()=>C(!0),children:n.jsx(qt,{className:D.selectOnChangeHelpIcon})})]}):null,n.jsx(ht,{setTourStep:I,tourStep:_,isTourOpen:r,blockValue:t==="actions"?"then":t==="conditions"?0:t,typeBlock:t,setUserRules:l,userRules:c,theme:k,themeName:w,themeType:H,size:e}),a&&[...Array(t==="actions"?1:c.conditions.length-1)].map((N,h)=>{const b=(v=h)=>t==="actions"?!!f:!!f.find((m,W)=>W===v&&m.open);return n.jsxs(xt,{children:[n.jsxs("div",{onClick:()=>{if(t==="actions")return x(!f),null;let v=JSON.parse(JSON.stringify(f));if(c.conditions[h+1].length)return v[h].open=!v[h].open,x(v),null;v=v.filter((m,W)=>W!==h),x(v),B(h),setTimeout(()=>{B(!1),l({...c,conditions:[...c.conditions.filter((m,W)=>W!==h+1)]})},250)},className:D.blockCardAdd,children:[b()?"-":"+",n.jsx("div",{className:D.cardAdd,children:i})]},h),n.jsx(ht,{blockValue:t==="actions"?"else":t==="conditions"?h+1:t,typeBlock:t,setUserRules:l,userRules:c,boolean:b(),animation:S===h,size:e,theme:k,themeName:w,themeType:H})]},`${h}_block_${t}`)}),a&&t==="conditions"&&n.jsxs("div",{onClick:()=>{x([...f,{_id:Date.now(),open:!0}]),l({...c,conditions:[...c.conditions,[]]}),B(c.conditions.length-1),setTimeout(()=>B(!1),1e3)},className:D.blockCardAdd,children:["+",n.jsx("div",{className:D.cardAdd,children:i})]}),n.jsx(Sn,{open:g,onClose:()=>C(!1)}),n.jsx(Nn,{open:q,onClose:()=>T(!1)})]})},$n="_menuRules_1qqcb_1",qn="_switchesRenderWrapper_1qqcb_13",Bn="_menuOff_1qqcb_22",Mn="_menuTitle_1qqcb_28",Hn="_marginAuto_1qqcb_42",Wn="_inputWidth_1qqcb_47",Tn="_menuWrapper_1qqcb_52",En="_hamburgerWrapper_1qqcb_57",Pn="_hamburgerOff_1qqcb_74",Un="_nothingFound_1qqcb_82",Fn="_resetSearch_1qqcb_89",Jn="_controlPanel_1qqcb_101",Ln="_controlPanelAppBar_1qqcb_112",zn="_addClassMenu_1qqcb_126",Gn="_addClassBackground_1qqcb_132",Kn="_addClassPosition_1qqcb_136",$={menuRules:$n,switchesRenderWrapper:qn,menuOff:Bn,menuTitle:Mn,marginAuto:Hn,inputWidth:Wn,menuWrapper:Tn,hamburgerWrapper:En,hamburgerOff:Pn,nothingFound:Un,resetSearch:Fn,controlPanel:Jn,controlPanelAppBar:Ln,addClassMenu:zn,addClassBackground:Gn,addClassPosition:Kn},Qn=e=>{const{allProperties:t,allProperties:{acceptedBy:s,id:i},setUserRules:a,userRules:o,setTourStep:c,tourStep:l,isTourOpen:d,onTouchMove:j,isActive:O}=e;return n.jsx(At,{allProperties:t,id:t.id,isActive:O,setUserRules:a,userRules:o,children:n.jsx(It,{onDoubleClick:()=>{d&&l===J.addScheduleByDoubleClick&&i==="TriggerScheduleBlock"&&c(J.openTagsMenu),d&&l===J.addActionPrintText&&i==="ActionPrintText"&&c(J.showJavascript);const I=Date.now();let _;switch(s){case"actions":_="then";break;case"conditions":_=o[s].length-1;break}const r=K(s,o,_),k={id:i,_id:I,acceptedBy:s};_!==void 0?s==="actions"?r.actions[_].push({...k}):s==="conditions"&&r.conditions[_].push({...k}):r.triggers.push({...k}),a(r)},...e,...t,onTouchMove:j})})},Yn="_hamburgerMenu_hqnsm_8",Zn="_animate_hqnsm_21",_t={hamburgerMenu:Yn,animate:Zn};function Xn({bool:e}){return n.jsx("div",{className:`${_t.hamburgerMenu} ${e?_t.animate:""}`})}const Vn=({addClass:e,setAllBlocks:t,allBlocks:s,userRules:i,onChangeBlocks:a,setTourStep:o,tourStep:c,isTourOpen:l})=>{const{blocks:d,socket:j}=nt(et),[O,I]=dt(!1,"hamburgerOnOff"),[_,r]=dt({text:"",type:"triggers",index:0},"filterControlPanel"),k=(f=_.text,x=_.type)=>{if(!d)return;let p=[...d];p=p.filter(g=>{if(!f)return!0;const{name:C}=g.getStaticData();return C&&u.I18n.t(C).toLowerCase().includes(f.toLowerCase())}),p=p.filter(g=>x===g.getStaticData().acceptedBy),t(p)},H=(f,x)=>{l&&x===0&&c===J.selectTriggers&&o(J.addScheduleByDoubleClick),l&&x===2&&c===J.selectActions&&o(J.addActionPrintText),r({..._,index:x,type:["triggers","conditions","actions"][x]}),k(_.text,["triggers","conditions","actions"][x])},w=f=>({id:`scrollable-force-tab-${f}`,"aria-controls":`scrollable-force-tabpanel-${f}`});return E(()=>{k()},[d]),n.jsx(Ut,{mouseEvent:!1,touchEvent:"onTouchStart",onClickAway:()=>I(!0),children:n.jsxs("div",{className:u.Utils.clsx($.menuWrapper,e[1035]&&$.addClassMenu),children:[n.jsx("div",{className:`${$.hamburgerWrapper} ${O?$.hamburgerOff:null}`,onClick:()=>I(!O),children:n.jsx(Xn,{bool:!O})}),n.jsxs("div",{className:`${u.Utils.clsx($.menuRules,e[1035]&&$.addClassBackground,e[835]&&$.addClassPosition)} ${O?$.menuOff:null}`,children:[n.jsx("div",{className:$.controlPanel,children:n.jsx(Ft,{className:$.controlPanelAppBar,position:"static",children:n.jsxs(Jt,{value:_.index,onChange:H,children:[n.jsx(st,{className:"blocks-triggers",title:u.I18n.t("Triggers"),icon:n.jsx(Y,{iconName:"FlashOn"}),...w(0)}),n.jsx(st,{title:u.I18n.t("Conditions"),className:"blocks-conditions",icon:n.jsx(Y,{iconName:"Help"}),...w(1)}),n.jsx(st,{title:u.I18n.t("Actions"),className:"blocks-actions",icon:n.jsx(Y,{iconName:"PlayForWork"}),...w(2)})]})})}),n.jsx("div",{className:$.switchesRenderWrapper,children:n.jsxs("span",{children:[s.map(f=>{const{name:x,id:p,icon:g,adapter:C}=f.getStaticData();return n.jsx(xt,{children:n.jsx(Qn,{adapter:C,allProperties:f.getStaticData(),icon:g,id:p,isActive:!1,isTourOpen:l,name:x,onTouchMove:()=>I(!0),setTourStep:o,setUserRules:a,socket:j,tourStep:c,userRules:i})},p)}),!s.length&&n.jsxs("div",{className:$.nothingFound,children:[u.I18n.t("Nothing found"),"...",n.jsx("div",{className:$.resetSearch,onClick:()=>{r({..._,text:""}),k("")},children:u.I18n.t("reset search")})]})]})}),n.jsx("div",{className:u.Utils.clsx($.menuTitle,$.marginAuto)}),n.jsx(Bt,{className:$.inputWidth,fullWidth:!0,customValue:!0,value:_.text,size:"small",autoComplete:"off",label:u.I18n.t("search"),variant:"outlined",onChange:f=>{r({..._,text:f}),k(f)}})]})]})})};let pt=[];const me=({code:e,onChange:t,themeName:s,themeType:i,theme:a,setTourStep:o,tourStep:c,isTourOpen:l,command:d,scriptId:j,changed:O,running:I})=>{var v;const{blocks:_,socket:r,setOnUpdate:k,setOnDebugMessage:H,setEnableSimulation:w}=nt(et),[f,x]=M([]),[p,g]=M(ft(e)),[C,q]=M(""),[T,S]=M(!1);E(()=>{let m,W;const A=(P,y)=>{P===`${m}.alive`&&W!==(y==null?void 0:y.val)&&(W=!!(y!=null&&y.val),W&&m&&(r==null||r.sendTo(m.replace(/^system\.adapter\./,""),"rulesOn",j)))},L=(P,y)=>{var U,Q;r&&m!==((U=y==null?void 0:y.common)==null?void 0:U.engine)&&(m&&(r.unsubscribeState(`${m}.alive`,A),W&&r.sendTo(m.replace(/^system\.adapter\./,""),"rulesOn",j)),m=(Q=y==null?void 0:y.common)==null?void 0:Q.engine,m&&m&&r.subscribeState(`${m}.alive`,A))},Z=(P,y)=>{if(y)try{const U=JSON.parse(y.val),Q=Date.now();if(U.ruleId===j&&Q-U.ts<1e3){const F=[...pt,{blockId:U.blockId,data:U.data,ts:U.ts}];F.length>200&&F.splice(0,F.length-200);for(let X=F.length-1;X>=0;X--)if(F[X].ts<Q-5e3){F.splice(0,X);break}pt=F,H(F)}}catch{console.error(`Cannot parse: ${y.val}`)}};return r==null||r.getObject(j).then(P=>{var y;m=(y=P==null?void 0:P.common)==null?void 0:y.engine,r.subscribeObject(j,L),m&&(r.subscribeState(`${m}.alive`,A),r.subscribeState(`${m.replace(/^system\.adapter\./,"")}.debug.rules`,Z))}),function(){r==null||r.unsubscribeObject(j,L),m&&(r==null||r.unsubscribeState(`${m}.alive`,A),W&&(r==null||r.sendTo(m.replace(/^system\.adapter\./,""),"rulesOff",j)),r==null||r.unsubscribeState(`${m.replace(/^system\.adapter\./,"")}.debug.rules`,Z))}},[]),E(()=>{w(!O&&I)},[O,I,w]),E(()=>{d&&(q(d),T||S(!0))},[d]),E(()=>{const m=ft(e);JSON.stringify(m)!==JSON.stringify(p)&&(g(m),k(!0))},[e]),E(()=>{document.getElementsByTagName("HTML")[0].className=s||"blue"},[s]);const B=lt(m=>{g(m),_&&t(Mt(m,_))},[_,t]),N=ut(null),[h,b]=M({835:!1,1035:!1});return E(()=>{N.current&&(N.current.clientWidth<=1035&&b({835:!1,1035:!0}),N.current.clientWidth<=835&&b({1035:!0,835:!0}),N.current.clientWidth>1035&&b({835:!1,1035:!1}))},[((v=N.current)==null?void 0:v.clientWidth)||0]),!_||!r?null:n.jsxs("div",{className:ot.wrapperRules,ref:N,children:[n.jsx(ln,{allBlocks:f,socket:r}),T?C==="export"?n.jsx(Ht,{scriptId:j,themeType:i,onClose:()=>S(!1),text:JSON.stringify(p,null,2)}):n.jsx(Wt,{themeType:i,onClose:m=>{S(!1),m&&B(JSON.parse(m))}}):null,n.jsxs("div",{className:u.Utils.clsx(ot.rootWrapper,h[835]&&ot.addClass),children:[n.jsx(Vn,{setAllBlocks:x,allBlocks:f,userRules:p,onChangeBlocks:B,setTourStep:o,tourStep:c,addClass:h,isTourOpen:l}),n.jsx(at,{socket:r,setUserRules:B,userRules:p,isTourOpen:l,setTourStep:o,tourStep:c,name:`${u.I18n.t("when")}...`,typeBlock:"triggers",iconName:"FlashOn",size:h[835],themeType:i,themeName:s,theme:a}),n.jsx(at,{socket:r,setUserRules:B,isTourOpen:l,setTourStep:o,tourStep:c,userRules:p,name:`...${u.I18n.t("and")}...`,typeBlock:"conditions",iconName:"Help",nameAdditionally:u.I18n.t("or"),additionally:!0,border:!0,size:h[835],themeType:i,themeName:s,theme:a}),n.jsx(at,{socket:r,setUserRules:B,isTourOpen:l,setTourStep:o,tourStep:c,userRules:p,name:`...${u.I18n.t("then")}`,typeBlock:"actions",iconName:"PlayForWork",nameAdditionally:u.I18n.t("else"),additionally:!0,size:h[835],themeType:i,themeName:s,theme:a})]})]},"rulesEditor")};export{me as default};
|
|
1
|
+
import{j as n}from"./createSvgIcon-DYs_tNrE.js";import{c as E,h as yt,j as M,m as nt,k as lt,l as Dt,b as ut,o as xt}from"./iobroker_javascript__loadShare__react__loadShare__.mjs-CTZOFJS2.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{u as kt,a as St,M as Y,C as et,G as Nt,b as $t,c as bt,I as qt,S as J,d as Bt,e as ft,j as Mt,D as Ht,f as Wt}from"./index-BTQOdA7v.js";import{_ as wt,b as Ct,h as vt,i as jt,p as Tt,f as Et,g as mt,o as Pt,Y as Ut,Z as Ft,C as Jt,D as st}from"./iobroker_javascript__loadShare___mf_0_mui_mf_1_material__loadShare__.mjs-CV1_X-Lf.js";import{I as Lt}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-CeYV4czE.js";import"./preload-helper-BDBacUwf.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 zt(e){const s=kt().getMonitor(),[i,a]=St(s,e);return E(()=>s.subscribeToOffsetChange(a)),E(()=>s.subscribeToStateChange(a)),i}let V;function Gt(){return V||(V=new Image,V.src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="),V}const Kt="_wrapperRules_nnott_1",Qt="_rootWrapper_nnott_9",Yt="_addClass_nnott_14",ot={wrapperRules:Kt,rootWrapper:Qt,addClass:Yt},Zt="_switchesItem_10ls3_1",Xt="_switchesItemActive_10ls3_28",Vt="_iconTheme_10ls3_36",it={switchesItem:Zt,switchesItemActive:Xt,iconTheme:Vt},It=({name:e,id:t,active:s,icon:i,adapter:a,socket:o,onDoubleClick:c,title:l,onTouchMove:d,style:j})=>n.jsxs("div",{onDoubleClick:c,onTouchMove:d,title:l?u.I18n.t(l):void 0,className:u.Utils.clsx(it.switchesItem,s&&it.switchesItemActive,`block-${t}`),children:[n.jsx(Y,{iconName:i,className:it.iconTheme,adapter:a,socket:o,style:j}),n.jsx("span",{children:e?u.I18n.t(e):""})]},t),Rt="_cardStyle_8rq8v_1",tn="_cardStyleActive_8rq8v_17",nn="_controlMenu_8rq8v_22",en="_closeBtn_8rq8v_31",sn="_isDelete_8rq8v_73",on="_drag_mobile_8rq8v_90",G={cardStyle:Rt,cardStyleActive:tn,controlMenu:nn,closeBtn:en,isDelete:sn,drag_mobile:on};function K(e,t,s){let i;switch(e){case"actions":if(s==="else")return i={...t,actions:{...t[e],else:[...t[e].else]}},i;if(s==="then")return i={...t,actions:{...t[e],then:[...t[e].then]}},i;throw console.error(`Unknown additionalParameter: ${s}`),new Error(`Unknown additionalParameter: ${s}`);case"triggers":return i={...t,triggers:[...t.triggers]},i;case"conditions":return i={...t,conditions:[...t.conditions]},i;default:throw new Error(`Unknown name: ${e}`)}}function z(e,t,s,i){var a;switch(e){case"actions":return t.actions[s]=t.actions[s].filter(o=>o._id!==i),t;case"conditions":return t.conditions[s]=(a=t.conditions[s])==null?void 0:a.filter(o=>o._id!==i),t;default:return t.triggers=t.triggers.filter(o=>o._id!==i),t}}function cn(e,t,s){const{_id:i,acceptedBy:a}=e;let o;if(!a||!t[a])return console.warn(`Cannot find ${a}`),t;switch(a){case"actions":if(o=t.actions[s].find(c=>c._id===i),!o)console.warn(`Cannot find ${i}`);else{const c=t.actions[s].indexOf(o);t.actions[s][c]=e}return t;case"conditions":if(o=t.conditions[s].find(c=>c._id===i),!o)console.warn(`Cannot find ${i}`);else{const c=t.conditions[s].indexOf(o);t.conditions[s][c]=e}return t;default:if(o=t.triggers.find(c=>c._id===i),!o)console.warn(`Cannot find ${i}`);else{const c=t.triggers.indexOf(o);t.triggers[c]=e}return t}}const Ot=yt(e=>{var N;const{setUserRules:t,userRules:s,_id:i,id:a,blockValue:o,active:c,acceptedBy:l,isTourOpen:d,setTourStep:j,tourStep:O}=e,[I,_]=M(null),{blocks:r,socket:k,onUpdate:H,setOnUpdate:w,onDebugMessage:f,enableSimulation:x}=nt(et),p=lt(h=>r==null?void 0:r.find(b=>b.getStaticData().id===h),[r]),g=lt(h=>{const b=cn(h,s,o);b&&t(b)},[s]),C=h=>{h.currentTarget!==I&&_(h.currentTarget)},q=()=>_(null),T=Dt(()=>{const h=p(a)||Nt;return n.jsx(h,{...e,notFound:!p(a),isTourOpen:d,setTourStep:j,tourStep:O,onUpdate:H,setOnUpdate:w,enableSimulation:x,onDebugMessage:f,onChange:g,className:void 0,socket:k})},[s,H,f,x]),[S,B]=M(!1);return n.jsxs("div",{onMouseMove:C,onMouseEnter:C,onMouseLeave:q,onMouseDown:h=>{if(h.ctrlKey){let b;const v=K(l,s,o);l==="conditions"?(b=v.conditions[o].find(m=>m._id===i),b&&v.conditions[o].splice(v.conditions[o].indexOf(b),0,{...b,_id:Date.now()})):l==="actions"?(b=v.actions[o].find(m=>m._id===i),b&&v.actions[o].splice(v.actions[o].indexOf(b),0,{...b,_id:Date.now()})):(b=v.triggers.find(m=>m._id===i),b&&v.triggers.splice(v[l].indexOf(b),0,{...b,_id:Date.now()})),t(v)}},id:"height",style:c?{width:(((N=document.getElementById("width"))==null?void 0:N.clientWidth)||0)-70}:void 0,className:`${G.cardStyle} ${c?G.cardStyleActive:null} ${S?G.isDelete:null}`,children:[n.jsx("div",{className:G.drag_mobile}),T,t&&n.jsx("div",{className:G.controlMenu,style:I?{opacity:1}:{opacity:0},children:n.jsx("div",{onClick:()=>{let h=K(l,s,o);h=z(l,h,o,i),B(!0),setTimeout(()=>{l==="triggers"&&w(!0),t(h)},300)},className:G.closeBtn})})]})}),rn={position:"fixed",pointerEvents:"none",zIndex:100,left:0,top:0,width:"100%",height:"100%"},an=(e,t,s)=>{if(!e||!t)return{display:"none"};let{x:i,y:a}=t;const o=`translate(${i}px, ${a}px)`;return{transform:o,WebkitTransform:o}},ln=e=>{const{itemType:t,isDragging:s,item:i,initialOffset:a,currentOffset:o,targetIds:c}=zt(d=>({item:d.getItem(),itemType:d.getItemType(),initialOffset:d.getInitialSourceClientOffset(),currentOffset:d.getSourceClientOffset(),isDragging:d.isDragging(),targetIds:d.getTargetIds()})),l=()=>t==="box"?c.length?n.jsx(Ot,{active:!0,...i,allBlocks:e.allBlocks}):n.jsx(It,{active:!0,...i,socket:e.socket}):null;return s?n.jsx("div",{style:rn,children:n.jsx("div",{style:an(a,o),children:l()})}):null},dn="_border_wrpm3_1",fn="_emptyBlockStyle_wrpm3_6",mn="_emptyBlock_wrpm3_6",gn="_selectOnChange_wrpm3_22",hn="_selectOnChangeHelp_wrpm3_28",_n="_selectOnChangeHelpIcon_wrpm3_34",pn="_emptyBlockNone_wrpm3_49",un="_mainBlockItemRules_wrpm3_55",xn="_nameBlockItems_wrpm3_63",bn="_contentBlockItem_wrpm3_73",wn="_wrapperMargin_wrpm3_81",Cn="_contentHeightOn_wrpm3_87",vn="_contentHeightOff_wrpm3_99",jn="_cardAdd_wrpm3_105",In="_blockCardAdd_wrpm3_125",On="_addClassOverflow_wrpm3_136",An="_addClassHeight_wrpm3_140",D={border:dn,emptyBlockStyle:fn,emptyBlock:mn,selectOnChange:gn,selectOnChangeHelp:hn,selectOnChangeHelpIcon:_n,emptyBlockNone:pn,mainBlockItemRules:un,nameBlockItems:xn,contentBlockItem:bn,wrapperMargin:wn,contentHeightOn:Cn,contentHeightOff:vn,cardAdd:jn,blockCardAdd:In,addClassOverflow:On,addClassHeight:An};function dt(e,t){const[s,i]=M(window.localStorage.getItem(t)?JSON.parse(window.localStorage.getItem(t)||""):e);return[s,o=>{window.localStorage.setItem(t,JSON.stringify(o)),i(o)},!!window.localStorage.getItem(t)]}function yn(e,t){let s=0,i=null,a;return function(...o){const c=Date.now();a=o,c-s>=t?(s=c,e.apply(this,o)):i||(i=setTimeout(()=>{s=Date.now(),i=null,e.apply(this,a)},t-(c-s)))}}function tt(e){if(Array.isArray(e))return e.map(t=>tt(t));if(typeof e=="function")return e.bind(null);if(e&&typeof e=="object"){const t={};return Object.keys(e).forEach(s=>{t[s]=tt(e[s])}),t}return e}const ct=yn((e,t)=>e(t),0);function R(e,t){const s=t.find(i=>i._id===e);return{card:s,index:s?t.indexOf(s):-1}}function rt(e,t,s,i,a,o,c,l,d){const{card:j,index:O}=R(e,s);if(!(O<t&&l<d)&&!(O>t&&l>d)&&j&&O!==t){const I=tt(s);I.splice(O,1),I.splice(t,0,j);const _=tt(a);switch(o){case"actions":_.actions[c]=I,ct(i,_);return;case"conditions":_.conditions[c]=I,ct(i,_);return;default:_.triggers=I,ct(i,_);return}}}const Dn="_drag_7xfhc_1",kn="_root_7xfhc_11",gt={drag:Dn,root:kn},At=({typeBlock:e,allProperties:t,id:s,isActive:i,setUserRules:a,userRules:o,children:c,_id:l,blockValue:d})=>{const{setOnUpdate:j}=nt(et),[{opacity:O},I,_]=$t({type:"box",item:()=>({...t,id:s,isActive:i,_id:l}),end:(w,f)=>{const{acceptedBy:x}=w,p=f.getDropResult();let g;if(!p)return typeof l=="number"&&!f.getTargetIds().length&&(g=K(x,o,d),g=z(x,g,d,l),a(g)),null;if(p.blockValue!==d){const C=typeof l=="number"?l:Date.now();g=K(x,o,p.blockValue);const q={id:w.id,acceptedBy:w.acceptedBy};switch(x){case"actions":return d&&(g=z("actions",g,d,C)),g=z("actions",g,p.blockValue,C),g.actions[p.blockValue].push({...q,_id:C}),a(g);case"conditions":return typeof d=="number"&&(g=z("conditions",g,d,C)),g=z("conditions",g,p.blockValue,C),g.conditions[p.blockValue].push({...q,_id:C}),a(g);default:return j(!0),g=z("triggers",g,p.blockValue,C),g.triggers.push({...q,_id:C}),a(g)}}},collect:w=>({opacity:w.isDragging()?.4:1,isDragging:w.isDragging()})}),r=ut(null),[,k]=bt({accept:"box",canDrop:()=>!1,hover({_id:w,acceptedBy:f},x){var T;if(!r.current||e!==f)return;const p=(T=r.current)==null?void 0:T.getBoundingClientRect(),g=(p.bottom-p.top)/2,C=x.getClientOffset(),q=((C==null?void 0:C.y)||0)-p.top;if(l&&w!==l)switch(f){case"actions":if(d==="then"||d==="else"){const{index:S}=R(l,o.actions[d]);S!==w&&rt(w,S,o[f][d],a,o,f,d,q,g)}return;case"conditions":if(typeof d=="number"){const{index:S}=R(l,o[f][d]);S!==w&&rt(w,S,o[f][d],a,o,f,d,q,g)}return;default:{const{index:S}=R(l,o[f]);S!==w&&rt(w,S,o[f],a,o,f,void 0,q,g);return}}}});E(()=>{_(Gt(),{captureDraggingState:!0})},[]),I(k(r));const H=window.innerWidth<600;return n.jsxs("div",{ref:H&&l?null:r,className:gt.root,style:{opacity:O},children:[n.jsx("div",{className:l?gt.drag:null,ref:l&&H?r:null}),c]})},Sn=({onClose:e,open:t})=>n.jsxs(wt,{open:t,onClose:e,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[n.jsx(Ct,{children:n.jsxs("div",{style:{fontSize:"1rem",fontFamily:'"Roboto", "Helvetica", "Arial", sans-serif',fontWeight:400,lineHeight:1.5,letterSpacing:"0.00938em"},children:[n.jsx("h3",{children:u.I18n.t("On condition change")}),n.jsx("div",{children:u.I18n.t("help_on_change")}),n.jsx("h3",{children:u.I18n.t("Just check")}),n.jsx("div",{children:u.I18n.t("help_just_check")})]})}),n.jsx(vt,{children:n.jsx(jt,{onClick:e,color:"primary",autoFocus:!0,startIcon:n.jsx(Lt,{}),children:u.I18n.t("OK")})})]}),Nn=({onClose:e,open:t})=>n.jsxs(wt,{open:t,onClose:e,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[n.jsx(Ct,{children:n.jsxs(Tt,{id:"alert-dialog-description",children:[n.jsx("h3",{children:u.I18n.t("On condition change")}),n.jsx("div",{children:u.I18n.t("help_on_change")}),n.jsx("h3",{children:u.I18n.t("Just check")}),n.jsx("div",{children:u.I18n.t("help_just_check")})]})}),n.jsx(vt,{children:n.jsx(jt,{onClick:e,color:"primary",autoFocus:!0,children:u.I18n.t("OK")})})]}),ht=({size:e,blockValue:t,boolean:s,typeBlock:i,userRules:a,setUserRules:o,animation:c,setTourStep:l,tourStep:d,isTourOpen:j,theme:O,themeType:I,themeName:_})=>{var W;const[r,k]=M(!1),[H,w]=M(!1),[f,x]=M(!1),[p,g]=M("");s===void 0&&(s=!0);const C=bt({accept:"box",drop:()=>({blockValue:t}),hover:({acceptedBy:A,_id:L},Z)=>{k(A===i),x(!!L),g(Z.getHandlerId()||"")},canDrop:({acceptedBy:A})=>(w(A===i),A===i),collect:A=>{var L;return{isOver:A.isOver(),canDrop:((L=A.getItem())==null?void 0:L.acceptedBy)===i,offset:A.getClientOffset(),targetId:A.getHandlerId()}}}),q=C[0],{canDrop:T,isOver:S,offset:B,targetId:N}=q,h=C[1];E(()=>{g("")},[B]);const b=T&&S;let v="";b?v=r?"#00fb003d":"#fb00002e":T?v=H?"#00fb003d":"#fb00002e":B&&(v=N===p?"#fb00002e":"");let m;return i==="actions"?m=a.actions[t]:i==="conditions"?m=a.conditions[t]:m=a.triggers,n.jsx("div",{ref:h,style:{backgroundColor:v},className:`${u.Utils.clsx(D.contentBlockItem,e&&D.addClassHeight)} ${s?c?D.contentHeightOn:null:D.contentHeightOff}`,children:n.jsxs("div",{className:D.wrapperMargin,children:[m.map(A=>n.jsx(At,{typeBlock:i,...A,blockValue:t,allProperties:A,userRules:a,setUserRules:o,children:n.jsx(Ot,{...A,isTourOpen:j,setTourStep:l,tourStep:d,settings:A,blockValue:t,userRules:a,setUserRules:o,theme:O,themeType:I,themeName:_})},A._id)),n.jsx("div",{style:b&&r&&!f?{height:((W=document.getElementById("height"))==null?void 0:W.clientHeight)||200}:void 0,className:`${D.emptyBlockStyle} ${b&&r&&!f?D.emptyBlock:D.emptyBlockNone}`})]})})},at=({size:e,typeBlock:t,name:s,nameAdditionally:i,additionally:a,border:o,userRules:c,setUserRules:l,iconName:d,adapter:j,socket:O,setTourStep:I,tourStep:_,isTourOpen:r,theme:k,themeType:H,themeName:w})=>{const[f,x,p]=dt(t==="actions"?!1:[],`additionallyClickItems_${t}`),[g,C]=M(!1),[q,T]=M(!1);E(()=>{if(t==="conditions"&&(f==null?void 0:f.length)!==c.conditions.length-1){const N=[];c.conditions.forEach((h,b)=>{b>0&&N.push({_id:Date.now(),open:!0})}),x([...f,...N])}t==="actions"&&!p&&c.actions.else.length&&x(!0)},[]);const[S,B]=M(!1);return n.jsxs("div",{className:`${u.Utils.clsx(D.mainBlockItemRules,e&&D.addClassOverflow)} ${o&&!e?D.border:null}`,children:[n.jsxs("span",{id:"width",className:D.nameBlockItems,children:[n.jsx(Y,{iconName:d,className:D.iconThemCard,adapter:j,socket:O}),s]}),t==="conditions"?n.jsxs("div",{style:{width:"100%"},children:[n.jsxs(Et,{variant:"standard",className:D.selectOnChange,value:c.justCheck||!1,onChange:N=>{const h=K("conditions",c);h.justCheck=N.target.value==="true",l(h)},children:[n.jsx(mt,{value:"false",children:u.I18n.t("on condition change")}),n.jsx(mt,{value:"true",children:u.I18n.t("just check")})]}),n.jsx(Pt,{size:"small",title:u.I18n.t("Explanation"),className:D.selectOnChangeHelp,onClick:()=>C(!0),children:n.jsx(qt,{className:D.selectOnChangeHelpIcon})})]}):null,n.jsx(ht,{setTourStep:I,tourStep:_,isTourOpen:r,blockValue:t==="actions"?"then":t==="conditions"?0:t,typeBlock:t,setUserRules:l,userRules:c,theme:k,themeName:w,themeType:H,size:e}),a&&[...Array(t==="actions"?1:c.conditions.length-1)].map((N,h)=>{const b=(v=h)=>t==="actions"?!!f:!!f.find((m,W)=>W===v&&m.open);return n.jsxs(xt,{children:[n.jsxs("div",{onClick:()=>{if(t==="actions")return x(!f),null;let v=JSON.parse(JSON.stringify(f));if(c.conditions[h+1].length)return v[h].open=!v[h].open,x(v),null;v=v.filter((m,W)=>W!==h),x(v),B(h),setTimeout(()=>{B(!1),l({...c,conditions:[...c.conditions.filter((m,W)=>W!==h+1)]})},250)},className:D.blockCardAdd,children:[b()?"-":"+",n.jsx("div",{className:D.cardAdd,children:i})]},h),n.jsx(ht,{blockValue:t==="actions"?"else":t==="conditions"?h+1:t,typeBlock:t,setUserRules:l,userRules:c,boolean:b(),animation:S===h,size:e,theme:k,themeName:w,themeType:H})]},`${h}_block_${t}`)}),a&&t==="conditions"&&n.jsxs("div",{onClick:()=>{x([...f,{_id:Date.now(),open:!0}]),l({...c,conditions:[...c.conditions,[]]}),B(c.conditions.length-1),setTimeout(()=>B(!1),1e3)},className:D.blockCardAdd,children:["+",n.jsx("div",{className:D.cardAdd,children:i})]}),n.jsx(Sn,{open:g,onClose:()=>C(!1)}),n.jsx(Nn,{open:q,onClose:()=>T(!1)})]})},$n="_menuRules_1qqcb_1",qn="_switchesRenderWrapper_1qqcb_13",Bn="_menuOff_1qqcb_22",Mn="_menuTitle_1qqcb_28",Hn="_marginAuto_1qqcb_42",Wn="_inputWidth_1qqcb_47",Tn="_menuWrapper_1qqcb_52",En="_hamburgerWrapper_1qqcb_57",Pn="_hamburgerOff_1qqcb_74",Un="_nothingFound_1qqcb_82",Fn="_resetSearch_1qqcb_89",Jn="_controlPanel_1qqcb_101",Ln="_controlPanelAppBar_1qqcb_112",zn="_addClassMenu_1qqcb_126",Gn="_addClassBackground_1qqcb_132",Kn="_addClassPosition_1qqcb_136",$={menuRules:$n,switchesRenderWrapper:qn,menuOff:Bn,menuTitle:Mn,marginAuto:Hn,inputWidth:Wn,menuWrapper:Tn,hamburgerWrapper:En,hamburgerOff:Pn,nothingFound:Un,resetSearch:Fn,controlPanel:Jn,controlPanelAppBar:Ln,addClassMenu:zn,addClassBackground:Gn,addClassPosition:Kn},Qn=e=>{const{allProperties:t,allProperties:{acceptedBy:s,id:i},setUserRules:a,userRules:o,setTourStep:c,tourStep:l,isTourOpen:d,onTouchMove:j,isActive:O}=e;return n.jsx(At,{allProperties:t,id:t.id,isActive:O,setUserRules:a,userRules:o,children:n.jsx(It,{onDoubleClick:()=>{d&&l===J.addScheduleByDoubleClick&&i==="TriggerScheduleBlock"&&c(J.openTagsMenu),d&&l===J.addActionPrintText&&i==="ActionPrintText"&&c(J.showJavascript);const I=Date.now();let _;switch(s){case"actions":_="then";break;case"conditions":_=o[s].length-1;break}const r=K(s,o,_),k={id:i,_id:I,acceptedBy:s};_!==void 0?s==="actions"?r.actions[_].push({...k}):s==="conditions"&&r.conditions[_].push({...k}):r.triggers.push({...k}),a(r)},...e,...t,onTouchMove:j})})},Yn="_hamburgerMenu_hqnsm_8",Zn="_animate_hqnsm_21",_t={hamburgerMenu:Yn,animate:Zn};function Xn({bool:e}){return n.jsx("div",{className:`${_t.hamburgerMenu} ${e?_t.animate:""}`})}const Vn=({addClass:e,setAllBlocks:t,allBlocks:s,userRules:i,onChangeBlocks:a,setTourStep:o,tourStep:c,isTourOpen:l})=>{const{blocks:d,socket:j}=nt(et),[O,I]=dt(!1,"hamburgerOnOff"),[_,r]=dt({text:"",type:"triggers",index:0},"filterControlPanel"),k=(f=_.text,x=_.type)=>{if(!d)return;let p=[...d];p=p.filter(g=>{if(!f)return!0;const{name:C}=g.getStaticData();return C&&u.I18n.t(C).toLowerCase().includes(f.toLowerCase())}),p=p.filter(g=>x===g.getStaticData().acceptedBy),t(p)},H=(f,x)=>{l&&x===0&&c===J.selectTriggers&&o(J.addScheduleByDoubleClick),l&&x===2&&c===J.selectActions&&o(J.addActionPrintText),r({..._,index:x,type:["triggers","conditions","actions"][x]}),k(_.text,["triggers","conditions","actions"][x])},w=f=>({id:`scrollable-force-tab-${f}`,"aria-controls":`scrollable-force-tabpanel-${f}`});return E(()=>{k()},[d]),n.jsx(Ut,{mouseEvent:!1,touchEvent:"onTouchStart",onClickAway:()=>I(!0),children:n.jsxs("div",{className:u.Utils.clsx($.menuWrapper,e[1035]&&$.addClassMenu),children:[n.jsx("div",{className:`${$.hamburgerWrapper} ${O?$.hamburgerOff:null}`,onClick:()=>I(!O),children:n.jsx(Xn,{bool:!O})}),n.jsxs("div",{className:`${u.Utils.clsx($.menuRules,e[1035]&&$.addClassBackground,e[835]&&$.addClassPosition)} ${O?$.menuOff:null}`,children:[n.jsx("div",{className:$.controlPanel,children:n.jsx(Ft,{className:$.controlPanelAppBar,position:"static",children:n.jsxs(Jt,{value:_.index,onChange:H,children:[n.jsx(st,{className:"blocks-triggers",title:u.I18n.t("Triggers"),icon:n.jsx(Y,{iconName:"FlashOn"}),...w(0)}),n.jsx(st,{title:u.I18n.t("Conditions"),className:"blocks-conditions",icon:n.jsx(Y,{iconName:"Help"}),...w(1)}),n.jsx(st,{title:u.I18n.t("Actions"),className:"blocks-actions",icon:n.jsx(Y,{iconName:"PlayForWork"}),...w(2)})]})})}),n.jsx("div",{className:$.switchesRenderWrapper,children:n.jsxs("span",{children:[s.map(f=>{const{name:x,id:p,icon:g,adapter:C}=f.getStaticData();return n.jsx(xt,{children:n.jsx(Qn,{adapter:C,allProperties:f.getStaticData(),icon:g,id:p,isActive:!1,isTourOpen:l,name:x,onTouchMove:()=>I(!0),setTourStep:o,setUserRules:a,socket:j,tourStep:c,userRules:i})},p)}),!s.length&&n.jsxs("div",{className:$.nothingFound,children:[u.I18n.t("Nothing found"),"...",n.jsx("div",{className:$.resetSearch,onClick:()=>{r({..._,text:""}),k("")},children:u.I18n.t("reset search")})]})]})}),n.jsx("div",{className:u.Utils.clsx($.menuTitle,$.marginAuto)}),n.jsx(Bt,{className:$.inputWidth,fullWidth:!0,customValue:!0,value:_.text,size:"small",autoComplete:"off",label:u.I18n.t("search"),variant:"outlined",onChange:f=>{r({..._,text:f}),k(f)}})]})]})})};let pt=[];const me=({code:e,onChange:t,themeName:s,themeType:i,theme:a,setTourStep:o,tourStep:c,isTourOpen:l,command:d,scriptId:j,changed:O,running:I})=>{var v;const{blocks:_,socket:r,setOnUpdate:k,setOnDebugMessage:H,setEnableSimulation:w}=nt(et),[f,x]=M([]),[p,g]=M(ft(e)),[C,q]=M(""),[T,S]=M(!1);E(()=>{let m,W;const A=(P,y)=>{P===`${m}.alive`&&W!==(y==null?void 0:y.val)&&(W=!!(y!=null&&y.val),W&&m&&(r==null||r.sendTo(m.replace(/^system\.adapter\./,""),"rulesOn",j)))},L=(P,y)=>{var U,Q;r&&m!==((U=y==null?void 0:y.common)==null?void 0:U.engine)&&(m&&(r.unsubscribeState(`${m}.alive`,A),W&&r.sendTo(m.replace(/^system\.adapter\./,""),"rulesOn",j)),m=(Q=y==null?void 0:y.common)==null?void 0:Q.engine,m&&m&&r.subscribeState(`${m}.alive`,A))},Z=(P,y)=>{if(y)try{const U=JSON.parse(y.val),Q=Date.now();if(U.ruleId===j&&Q-U.ts<1e3){const F=[...pt,{blockId:U.blockId,data:U.data,ts:U.ts}];F.length>200&&F.splice(0,F.length-200);for(let X=F.length-1;X>=0;X--)if(F[X].ts<Q-5e3){F.splice(0,X);break}pt=F,H(F)}}catch{console.error(`Cannot parse: ${y.val}`)}};return r==null||r.getObject(j).then(P=>{var y;m=(y=P==null?void 0:P.common)==null?void 0:y.engine,r.subscribeObject(j,L),m&&(r.subscribeState(`${m}.alive`,A),r.subscribeState(`${m.replace(/^system\.adapter\./,"")}.debug.rules`,Z))}),function(){r==null||r.unsubscribeObject(j,L),m&&(r==null||r.unsubscribeState(`${m}.alive`,A),W&&(r==null||r.sendTo(m.replace(/^system\.adapter\./,""),"rulesOff",j)),r==null||r.unsubscribeState(`${m.replace(/^system\.adapter\./,"")}.debug.rules`,Z))}},[]),E(()=>{w(!O&&I)},[O,I,w]),E(()=>{d&&(q(d),T||S(!0))},[d]),E(()=>{const m=ft(e);JSON.stringify(m)!==JSON.stringify(p)&&(g(m),k(!0))},[e]),E(()=>{document.getElementsByTagName("HTML")[0].className=s||"blue"},[s]);const B=lt(m=>{g(m),_&&t(Mt(m,_))},[_,t]),N=ut(null),[h,b]=M({835:!1,1035:!1});return E(()=>{N.current&&(N.current.clientWidth<=1035&&b({835:!1,1035:!0}),N.current.clientWidth<=835&&b({1035:!0,835:!0}),N.current.clientWidth>1035&&b({835:!1,1035:!1}))},[((v=N.current)==null?void 0:v.clientWidth)||0]),!_||!r?null:n.jsxs("div",{className:ot.wrapperRules,ref:N,children:[n.jsx(ln,{allBlocks:f,socket:r}),T?C==="export"?n.jsx(Ht,{scriptId:j,themeType:i,onClose:()=>S(!1),text:JSON.stringify(p,null,2)}):n.jsx(Wt,{themeType:i,onClose:m=>{S(!1),m&&B(JSON.parse(m))}}):null,n.jsxs("div",{className:u.Utils.clsx(ot.rootWrapper,h[835]&&ot.addClass),children:[n.jsx(Vn,{setAllBlocks:x,allBlocks:f,userRules:p,onChangeBlocks:B,setTourStep:o,tourStep:c,addClass:h,isTourOpen:l}),n.jsx(at,{socket:r,setUserRules:B,userRules:p,isTourOpen:l,setTourStep:o,tourStep:c,name:`${u.I18n.t("when")}...`,typeBlock:"triggers",iconName:"FlashOn",size:h[835],themeType:i,themeName:s,theme:a}),n.jsx(at,{socket:r,setUserRules:B,isTourOpen:l,setTourStep:o,tourStep:c,userRules:p,name:`...${u.I18n.t("and")}...`,typeBlock:"conditions",iconName:"Help",nameAdditionally:u.I18n.t("or"),additionally:!0,border:!0,size:h[835],themeType:i,themeName:s,theme:a}),n.jsx(at,{socket:r,setUserRules:B,isTourOpen:l,setTourStep:o,tourStep:c,userRules:p,name:`...${u.I18n.t("then")}`,typeBlock:"actions",iconName:"PlayForWork",nameAdditionally:u.I18n.t("else"),additionally:!0,size:h[835],themeType:i,themeName:s,theme:a})]})]},"rulesEditor")};export{me as default};
|