iobroker.javascript 9.0.12 → 9.0.13

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.
Files changed (52) hide show
  1. package/README.md +1 -1
  2. package/admin/assets/{OpenAiDialog-Db5nBWtV.js → OpenAiDialog-BmcYPsVa.js} +1 -1
  3. package/admin/assets/{ScriptEditor-CuzI8bbK.js → ScriptEditor-BoSBgnK-.js} +1 -1
  4. package/admin/assets/{ScriptEditorVanillaMonaco-LjlfPO8c.js → ScriptEditorVanillaMonaco-Xge2wqgO.js} +1 -1
  5. package/admin/assets/{index-DzAZ7TKU.js → index-BMwfsknM.js} +1 -1
  6. package/admin/assets/index-Br_QjNUk.js +942 -0
  7. package/admin/assets/{index-ee1BGSYh.js → index-CePzv5-W.js} +5 -5
  8. package/admin/assets/{index-DoG44L1P.js → index-DZ3lKVw8.js} +1 -1
  9. package/admin/assets/{index-CpvUlHhu.js → index-DwcZPzOL.js} +4 -4
  10. package/admin/assets/{index-CtB5rga_.js → index-OIiv3PJA.js} +1 -1
  11. package/admin/custom/assets/{Components-DJLwk8Py.js → Components-DjQ_LxKw.js} +1 -1
  12. package/admin/custom/assets/{DefaultPropsProvider-BbFDEnmq.js → DefaultPropsProvider-B8ZCC-c2.js} +1 -1
  13. package/admin/custom/assets/{DefaultPropsProvider-B6-0SEtV.js → DefaultPropsProvider-DfdXSIBu.js} +1 -7
  14. package/admin/custom/assets/{FilledInput-CX9v1cwN.js → FilledInput-CSjr0QT8.js} +1 -1
  15. package/admin/custom/assets/{Tabs-bjxmjZcg.js → Tabs-CiTQkBjL.js} +1 -1
  16. package/admin/custom/assets/{ThemeProvider-CeD4z8mE.js → ThemeProvider-C50pIiW4.js} +1 -1
  17. package/admin/custom/assets/{createSvgIcon-DAmSzHRD.js → createSvgIcon-C7qUEvjp.js} +1 -1
  18. package/admin/custom/assets/createTheme-Bm92JF8u.js +8 -0
  19. package/admin/custom/assets/defaultTheme-BlO0eCf6.js +1 -0
  20. package/admin/custom/assets/hostInit-BJ6gSofk.js +1 -1
  21. package/admin/custom/assets/index-4wMOc304.js +1 -0
  22. package/admin/custom/assets/{index-CrVgzaLe.js → index-5CTGLw4h.js} +1 -1
  23. package/admin/custom/assets/index-BHN4DzE4.js +908 -0
  24. package/admin/custom/assets/{index-BM9YMTul.js → index-BkjEWGjf.js} +1 -1
  25. package/admin/custom/assets/{index-D-RbixT9.js → index-COcxCdeX.js} +4 -20
  26. package/admin/custom/assets/{index-DMiiPxNM.js → index-CnpybLRW.js} +1 -1
  27. package/admin/custom/assets/{index-CznMGPgM.js → index-Db8nkuMR.js} +1 -1
  28. package/admin/custom/assets/{index-1hRrucfm.js → index-Df6OaCxx.js} +1 -1
  29. package/admin/custom/assets/{index-EogeheIH.js → index-t-NMdeH5.js} +6 -6
  30. package/admin/custom/assets/index-u8R8UVCf.js +1393 -0
  31. package/admin/custom/assets/jsx-runtime-C1csJtRx.js +1 -0
  32. package/admin/custom/assets/leaflet-src-DpWQqQWv.js +1 -0
  33. package/admin/custom/assets/useEnhancedEffect-aUb-5tTL.js +1 -0
  34. package/admin/custom/assets/{useTheme-Y8PztM11.js → useTheme-Cgjfsi-1.js} +1 -1
  35. package/admin/custom/assets/useTheme-DFGylj2o.js +1 -0
  36. package/admin/custom/assets/{virtualExposes-BMbgFEvP.js → virtualExposes-C_DtjFte.js} +2 -2
  37. package/admin/custom/customComponents.js +2 -2
  38. package/admin/mf-manifest.json +1 -1
  39. package/admin/remoteEntry.js +2 -2
  40. package/admin/tab.html +1 -1
  41. package/io-package.json +2 -2
  42. package/package.json +1 -1
  43. package/admin/assets/index-XLsd8FZV.js +0 -942
  44. package/admin/custom/assets/createTheme-LEFpI6rM.js +0 -16
  45. package/admin/custom/assets/defaultTheme-2suHr_rQ.js +0 -1
  46. package/admin/custom/assets/index-BgpTxVrG.js +0 -9
  47. package/admin/custom/assets/index-CJimub3l.js +0 -1399
  48. package/admin/custom/assets/index-CPZpQ2Mb.js +0 -916
  49. package/admin/custom/assets/jsx-runtime-CJ3ByJW3.js +0 -9
  50. package/admin/custom/assets/leaflet-src-Dnh7srds.js +0 -4
  51. package/admin/custom/assets/useEnhancedEffect-COBJo-Ex.js +0 -8
  52. package/admin/custom/assets/useTheme-52mADBCy.js +0 -1
package/README.md CHANGED
@@ -26,7 +26,7 @@ Executes Javascript, Typescript Scripts.
26
26
  <!--
27
27
  ### **WORK IN PROGRESS**
28
28
  -->
29
- ### 9.0.12 (2025-12-01)
29
+ ### 9.0.13 (2025-12-05)
30
30
  * (@GermanBluefox) Added possibility to encrypt scripts with password (only for vendors)
31
31
 
32
32
  ### 9.0.11 (2025-07-29)
@@ -1,4 +1,4 @@
1
- import{c as pr,j as P}from"./createSvgIcon-DlIk-fDn.js";import{i as Z}from"./iobroker_javascript__loadShare__react__loadShare__-i8pXne9X.js";import{i as j,c as pn,C as gr}from"./index-Cjl4b70e.js";import{i as U,h as _r}from"./index-ee1BGSYh.js";import{_ as yr}from"./preload-helper-BDBacUwf.js";import{C as wr,t as br}from"./index-DoG44L1P.js";import xr from"./ScriptEditorVanillaMonaco-LjlfPO8c.js";import"./_commonjsHelpers-Cpj98o6Y.js";import"./iobroker_javascript__mf_v__runtimeInit__mf_v__-DZdFIfoQ.js";import"./inheritsLoose-DNrhibGS.js";const Sr=pr(P.jsx("path",{d:"M11.07 12.85c.77-1.39 2.25-2.21 3.11-3.44.91-1.29.4-3.7-2.18-3.7-1.69 0-2.52 1.28-2.87 2.34L6.54 6.96C7.25 4.83 9.18 3 11.99 3c2.35 0 3.96 1.07 4.78 2.41.7 1.15 1.11 3.3.03 4.9-1.2 1.77-2.35 2.31-2.97 3.45-.25.46-.35.76-.35 2.24h-2.89c-.01-.78-.13-2.05.48-3.15M14 20c0 1.1-.9 2-2 2s-2-.9-2-2 .9-2 2-2 2 .9 2 2"}),"QuestionMark");function R(s,e,t,n,r){if(typeof e=="function"?s!==e||!0:!e.has(s))throw new TypeError("Cannot write private member to an object whose class did not declare it");return e.set(s,t),t}function c(s,e,t,n){if(t==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?s!==e||!n:!e.has(s))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?n:t==="a"?n.call(s):n?n.value:e.get(s)}let qn=function(){const{crypto:s}=globalThis;if(s!=null&&s.randomUUID)return qn=s.randomUUID.bind(s),s.randomUUID();const e=new Uint8Array(1),t=s?()=>s.getRandomValues(e)[0]:()=>Math.random()*255&255;return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,n=>(+n^t()&15>>+n/4).toString(16))};function Et(s){return typeof s=="object"&&s!==null&&("name"in s&&s.name==="AbortError"||"message"in s&&String(s.message).includes("FetchRequestCanceledException"))}const Pt=s=>{if(s instanceof Error)return s;if(typeof s=="object"&&s!==null){try{if(Object.prototype.toString.call(s)==="[object Error]"){const e=new Error(s.message,s.cause?{cause:s.cause}:{});return s.stack&&(e.stack=s.stack),s.cause&&!e.cause&&(e.cause=s.cause),s.name&&(e.name=s.name),e}}catch{}try{return new Error(JSON.stringify(s))}catch{}}return new Error(s)};class x extends Error{}class H extends x{constructor(e,t,n,r){super(`${H.makeMessage(e,t,n)}`),this.status=e,this.headers=r,this.requestID=r==null?void 0:r.get("x-request-id"),this.error=t;const a=t;this.code=a==null?void 0:a.code,this.param=a==null?void 0:a.param,this.type=a==null?void 0:a.type}static makeMessage(e,t,n){const r=t!=null&&t.message?typeof t.message=="string"?t.message:JSON.stringify(t.message):t?JSON.stringify(t):n;return e&&r?`${e} ${r}`:e?`${e} status code (no body)`:r||"(no status code or body)"}static generate(e,t,n,r){if(!e||!r)return new pt({message:n,cause:Pt(t)});const a=t==null?void 0:t.error;return e===400?new Jn(e,a,n,r):e===401?new Hn(e,a,n,r):e===403?new Xn(e,a,n,r):e===404?new Kn(e,a,n,r):e===409?new Vn(e,a,n,r):e===422?new Gn(e,a,n,r):e===429?new Qn(e,a,n,r):e>=500?new zn(e,a,n,r):new H(e,a,n,r)}}class z extends H{constructor({message:e}={}){super(void 0,void 0,e||"Request was aborted.",void 0)}}class pt extends H{constructor({message:e,cause:t}){super(void 0,void 0,e||"Connection error.",void 0),t&&(this.cause=t)}}class Jt extends pt{constructor({message:e}={}){super({message:e??"Request timed out."})}}class Jn extends H{}class Hn extends H{}class Xn extends H{}class Kn extends H{}class Vn extends H{}class Gn extends H{}class Qn extends H{}class zn extends H{}class Yn extends x{constructor(){super("Could not parse response content as the length limit was reached")}}class Zn extends x{constructor(){super("Could not parse response content as the request was rejected by the content filter")}}class Re extends Error{constructor(e){super(e)}}const Ar=/^[a-z][a-z0-9+.-]*:/i,vr=s=>Ar.test(s);let K=s=>(K=Array.isArray,K(s)),gn=K;function es(s){return typeof s!="object"?{}:s??{}}function Cr(s){if(!s)return!0;for(const e in s)return!1;return!0}function Ir(s,e){return Object.prototype.hasOwnProperty.call(s,e)}function St(s){return s!=null&&typeof s=="object"&&!Array.isArray(s)}const Rr=(s,e)=>{if(typeof e!="number"||!Number.isInteger(e))throw new x(`${s} must be an integer`);if(e<0)throw new x(`${s} must be a positive integer`);return e},$r=s=>{try{return JSON.parse(s)}catch{return}},Be=s=>new Promise(e=>setTimeout(e,s)),we="5.23.2",kr=()=>typeof window<"u"&&typeof window.document<"u"&&typeof navigator<"u";function Or(){return typeof Deno<"u"&&Deno.build!=null?"deno":typeof EdgeRuntime<"u"?"edge":Object.prototype.toString.call(typeof globalThis.process<"u"?globalThis.process:0)==="[object process]"?"node":"unknown"}const Er=()=>{var t;const s=Or();if(s==="deno")return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":we,"X-Stainless-OS":yn(Deno.build.os),"X-Stainless-Arch":_n(Deno.build.arch),"X-Stainless-Runtime":"deno","X-Stainless-Runtime-Version":typeof Deno.version=="string"?Deno.version:((t=Deno.version)==null?void 0:t.deno)??"unknown"};if(typeof EdgeRuntime<"u")return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":we,"X-Stainless-OS":"Unknown","X-Stainless-Arch":`other:${EdgeRuntime}`,"X-Stainless-Runtime":"edge","X-Stainless-Runtime-Version":globalThis.process.version};if(s==="node")return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":we,"X-Stainless-OS":yn(globalThis.process.platform??"unknown"),"X-Stainless-Arch":_n(globalThis.process.arch??"unknown"),"X-Stainless-Runtime":"node","X-Stainless-Runtime-Version":globalThis.process.version??"unknown"};const e=Pr();return e?{"X-Stainless-Lang":"js","X-Stainless-Package-Version":we,"X-Stainless-OS":"Unknown","X-Stainless-Arch":"unknown","X-Stainless-Runtime":`browser:${e.browser}`,"X-Stainless-Runtime-Version":e.version}:{"X-Stainless-Lang":"js","X-Stainless-Package-Version":we,"X-Stainless-OS":"Unknown","X-Stainless-Arch":"unknown","X-Stainless-Runtime":"unknown","X-Stainless-Runtime-Version":"unknown"}};function Pr(){if(typeof navigator>"u"||!navigator)return null;const s=[{key:"edge",pattern:/Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"ie",pattern:/MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"ie",pattern:/Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"chrome",pattern:/Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"firefox",pattern:/Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"safari",pattern:/(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/}];for(const{key:e,pattern:t}of s){const n=t.exec(navigator.userAgent);if(n){const r=n[1]||0,a=n[2]||0,i=n[3]||0;return{browser:e,version:`${r}.${a}.${i}`}}}return null}const _n=s=>s==="x32"?"x32":s==="x86_64"||s==="x64"?"x64":s==="arm"?"arm":s==="aarch64"||s==="arm64"?"arm64":s?`other:${s}`:"unknown",yn=s=>(s=s.toLowerCase(),s.includes("ios")?"iOS":s==="android"?"Android":s==="darwin"?"MacOS":s==="win32"?"Windows":s==="freebsd"?"FreeBSD":s==="openbsd"?"OpenBSD":s==="linux"?"Linux":s?`Other:${s}`:"Unknown");let wn;const Tr=()=>wn??(wn=Er());function Mr(){if(typeof fetch<"u")return fetch;throw new Error("`fetch` is not defined as a global; Either pass `fetch` to the client, `new OpenAI({ fetch })` or polyfill the global, `globalThis.fetch = fetch`")}function ts(...s){const e=globalThis.ReadableStream;if(typeof e>"u")throw new Error("`ReadableStream` is not defined as a global; You will need to polyfill it, `globalThis.ReadableStream = ReadableStream`");return new e(...s)}function ns(s){let e=Symbol.asyncIterator in s?s[Symbol.asyncIterator]():s[Symbol.iterator]();return ts({start(){},async pull(t){const{done:n,value:r}=await e.next();n?t.close():t.enqueue(r)},async cancel(){var t;await((t=e.return)==null?void 0:t.call(e))}})}function ss(s){if(s[Symbol.asyncIterator])return s;const e=s.getReader();return{async next(){try{const t=await e.read();return t!=null&&t.done&&e.releaseLock(),t}catch(t){throw e.releaseLock(),t}},async return(){const t=e.cancel();return e.releaseLock(),await t,{done:!0,value:void 0}},[Symbol.asyncIterator](){return this}}}async function Nr(s){var n,r;if(s===null||typeof s!="object")return;if(s[Symbol.asyncIterator]){await((r=(n=s[Symbol.asyncIterator]()).return)==null?void 0:r.call(n));return}const e=s.getReader(),t=e.cancel();e.releaseLock(),await t}const jr=({headers:s,body:e})=>({bodyHeaders:{"content-type":"application/json"},body:JSON.stringify(e)}),rs="RFC3986",as=s=>String(s),bn={RFC1738:s=>String(s).replace(/%20/g,"+"),RFC3986:as},Fr="RFC1738";let Tt=(s,e)=>(Tt=Object.hasOwn??Function.prototype.call.bind(Object.prototype.hasOwnProperty),Tt(s,e));const ee=(()=>{const s=[];for(let e=0;e<256;++e)s.push("%"+((e<16?"0":"")+e.toString(16)).toUpperCase());return s})(),At=1024,Lr=(s,e,t,n,r)=>{if(s.length===0)return s;let a=s;if(typeof s=="symbol"?a=Symbol.prototype.toString.call(s):typeof s!="string"&&(a=String(s)),t==="iso-8859-1")return escape(a).replace(/%u[0-9a-f]{4}/gi,function(o){return"%26%23"+parseInt(o.slice(2),16)+"%3B"});let i="";for(let o=0;o<a.length;o+=At){const l=a.length>=At?a.slice(o,o+At):a,u=[];for(let m=0;m<l.length;++m){let h=l.charCodeAt(m);if(h===45||h===46||h===95||h===126||h>=48&&h<=57||h>=65&&h<=90||h>=97&&h<=122||r===Fr&&(h===40||h===41)){u[u.length]=l.charAt(m);continue}if(h<128){u[u.length]=ee[h];continue}if(h<2048){u[u.length]=ee[192|h>>6]+ee[128|h&63];continue}if(h<55296||h>=57344){u[u.length]=ee[224|h>>12]+ee[128|h>>6&63]+ee[128|h&63];continue}m+=1,h=65536+((h&1023)<<10|l.charCodeAt(m)&1023),u[u.length]=ee[240|h>>18]+ee[128|h>>12&63]+ee[128|h>>6&63]+ee[128|h&63]}i+=u.join("")}return i};function Dr(s){return!s||typeof s!="object"?!1:!!(s.constructor&&s.constructor.isBuffer&&s.constructor.isBuffer(s))}function xn(s,e){if(K(s)){const t=[];for(let n=0;n<s.length;n+=1)t.push(e(s[n]));return t}return e(s)}const is={brackets(s){return String(s)+"[]"},comma:"comma",indices(s,e){return String(s)+"["+e+"]"},repeat(s){return String(s)}},os=function(s,e){Array.prototype.push.apply(s,K(e)?e:[e])};let Sn;const B={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:"indices",charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encodeDotInKeys:!1,encoder:Lr,encodeValuesOnly:!1,format:rs,formatter:as,indices:!1,serializeDate(s){return(Sn??(Sn=Function.prototype.call.bind(Date.prototype.toISOString)))(s)},skipNulls:!1,strictNullHandling:!1};function Br(s){return typeof s=="string"||typeof s=="number"||typeof s=="boolean"||typeof s=="symbol"||typeof s=="bigint"}const vt={};function cs(s,e,t,n,r,a,i,o,l,u,m,h,g,d,b,w,v,E){let p=s,y=E,_=0,C=!1;for(;(y=y.get(vt))!==void 0&&!C;){const T=y.get(s);if(_+=1,typeof T<"u"){if(T===_)throw new RangeError("Cyclic object value");C=!0}typeof y.get(vt)>"u"&&(_=0)}if(typeof u=="function"?p=u(e,p):p instanceof Date?p=g==null?void 0:g(p):t==="comma"&&K(p)&&(p=xn(p,function(T){return T instanceof Date?g==null?void 0:g(T):T})),p===null){if(a)return l&&!w?l(e,B.encoder,v,"key",d):e;p=""}if(Br(p)||Dr(p)){if(l){const T=w?e:l(e,B.encoder,v,"key",d);return[(b==null?void 0:b(T))+"="+(b==null?void 0:b(l(p,B.encoder,v,"value",d)))]}return[(b==null?void 0:b(e))+"="+(b==null?void 0:b(String(p)))]}const k=[];if(typeof p>"u")return k;let $;if(t==="comma"&&K(p))w&&l&&(p=xn(p,l)),$=[{value:p.length>0?p.join(",")||null:void 0}];else if(K(u))$=u;else{const T=Object.keys(p);$=m?T.sort(m):T}const F=o?String(e).replace(/\./g,"%2E"):String(e),A=n&&K(p)&&p.length===1?F+"[]":F;if(r&&K(p)&&p.length===0)return A+"[]";for(let T=0;T<$.length;++T){const M=$[T],se=typeof M=="object"&&typeof M.value<"u"?M.value:p[M];if(i&&se===null)continue;const me=h&&o?M.replace(/\./g,"%2E"):M,N=K(p)?typeof t=="function"?t(A,me):A:A+(h?"."+me:"["+me+"]");E.set(s,_);const ie=new WeakMap;ie.set(vt,E),os(k,cs(se,N,t,n,r,a,i,o,t==="comma"&&w&&K(p)?null:l,u,m,h,g,d,b,w,v,ie))}return k}function Wr(s=B){if(typeof s.allowEmptyArrays<"u"&&typeof s.allowEmptyArrays!="boolean")throw new TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(typeof s.encodeDotInKeys<"u"&&typeof s.encodeDotInKeys!="boolean")throw new TypeError("`encodeDotInKeys` option can only be `true` or `false`, when provided");if(s.encoder!==null&&typeof s.encoder<"u"&&typeof s.encoder!="function")throw new TypeError("Encoder has to be a function.");const e=s.charset||B.charset;if(typeof s.charset<"u"&&s.charset!=="utf-8"&&s.charset!=="iso-8859-1")throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");let t=rs;if(typeof s.format<"u"){if(!Tt(bn,s.format))throw new TypeError("Unknown format option provided.");t=s.format}const n=bn[t];let r=B.filter;(typeof s.filter=="function"||K(s.filter))&&(r=s.filter);let a;if(s.arrayFormat&&s.arrayFormat in is?a=s.arrayFormat:"indices"in s?a=s.indices?"indices":"repeat":a=B.arrayFormat,"commaRoundTrip"in s&&typeof s.commaRoundTrip!="boolean")throw new TypeError("`commaRoundTrip` must be a boolean, or absent");const i=typeof s.allowDots>"u"?s.encodeDotInKeys?!0:B.allowDots:!!s.allowDots;return{addQueryPrefix:typeof s.addQueryPrefix=="boolean"?s.addQueryPrefix:B.addQueryPrefix,allowDots:i,allowEmptyArrays:typeof s.allowEmptyArrays=="boolean"?!!s.allowEmptyArrays:B.allowEmptyArrays,arrayFormat:a,charset:e,charsetSentinel:typeof s.charsetSentinel=="boolean"?s.charsetSentinel:B.charsetSentinel,commaRoundTrip:!!s.commaRoundTrip,delimiter:typeof s.delimiter>"u"?B.delimiter:s.delimiter,encode:typeof s.encode=="boolean"?s.encode:B.encode,encodeDotInKeys:typeof s.encodeDotInKeys=="boolean"?s.encodeDotInKeys:B.encodeDotInKeys,encoder:typeof s.encoder=="function"?s.encoder:B.encoder,encodeValuesOnly:typeof s.encodeValuesOnly=="boolean"?s.encodeValuesOnly:B.encodeValuesOnly,filter:r,format:t,formatter:n,serializeDate:typeof s.serializeDate=="function"?s.serializeDate:B.serializeDate,skipNulls:typeof s.skipNulls=="boolean"?s.skipNulls:B.skipNulls,sort:typeof s.sort=="function"?s.sort:null,strictNullHandling:typeof s.strictNullHandling=="boolean"?s.strictNullHandling:B.strictNullHandling}}function Ur(s,e={}){let t=s;const n=Wr(e);let r,a;typeof n.filter=="function"?(a=n.filter,t=a("",t)):K(n.filter)&&(a=n.filter,r=a);const i=[];if(typeof t!="object"||t===null)return"";const o=is[n.arrayFormat],l=o==="comma"&&n.commaRoundTrip;r||(r=Object.keys(t)),n.sort&&r.sort(n.sort);const u=new WeakMap;for(let g=0;g<r.length;++g){const d=r[g];n.skipNulls&&t[d]===null||os(i,cs(t[d],d,o,l,n.allowEmptyArrays,n.strictNullHandling,n.skipNulls,n.encodeDotInKeys,n.encode?n.encoder:null,n.filter,n.sort,n.allowDots,n.serializeDate,n.format,n.formatter,n.encodeValuesOnly,n.charset,u))}const m=i.join(n.delimiter);let h=n.addQueryPrefix===!0?"?":"";return n.charsetSentinel&&(n.charset==="iso-8859-1"?h+="utf8=%26%2310003%3B&":h+="utf8=%E2%9C%93&"),m.length>0?h+m:""}function qr(s){let e=0;for(const r of s)e+=r.length;const t=new Uint8Array(e);let n=0;for(const r of s)t.set(r,n),n+=r.length;return t}let An;function Ht(s){let e;return(An??(e=new globalThis.TextEncoder,An=e.encode.bind(e)))(s)}let vn;function Cn(s){let e;return(vn??(e=new globalThis.TextDecoder,vn=e.decode.bind(e)))(s)}var V,G;class gt{constructor(){V.set(this,void 0),G.set(this,void 0),R(this,V,new Uint8Array),R(this,G,null)}decode(e){if(e==null)return[];const t=e instanceof ArrayBuffer?new Uint8Array(e):typeof e=="string"?Ht(e):e;R(this,V,qr([c(this,V,"f"),t]));const n=[];let r;for(;(r=Jr(c(this,V,"f"),c(this,G,"f")))!=null;){if(r.carriage&&c(this,G,"f")==null){R(this,G,r.index);continue}if(c(this,G,"f")!=null&&(r.index!==c(this,G,"f")+1||r.carriage)){n.push(Cn(c(this,V,"f").subarray(0,c(this,G,"f")-1))),R(this,V,c(this,V,"f").subarray(c(this,G,"f"))),R(this,G,null);continue}const a=c(this,G,"f")!==null?r.preceding-1:r.preceding,i=Cn(c(this,V,"f").subarray(0,a));n.push(i),R(this,V,c(this,V,"f").subarray(r.index)),R(this,G,null)}return n}flush(){return c(this,V,"f").length?this.decode(`
1
+ import{c as pr,j as P}from"./createSvgIcon-DlIk-fDn.js";import{i as Z}from"./iobroker_javascript__loadShare__react__loadShare__-i8pXne9X.js";import{i as j,c as pn,C as gr}from"./index-Cjl4b70e.js";import{i as U,h as _r}from"./index-CePzv5-W.js";import{_ as yr}from"./preload-helper-BDBacUwf.js";import{C as wr,t as br}from"./index-DZ3lKVw8.js";import xr from"./ScriptEditorVanillaMonaco-Xge2wqgO.js";import"./_commonjsHelpers-Cpj98o6Y.js";import"./iobroker_javascript__mf_v__runtimeInit__mf_v__-DZdFIfoQ.js";import"./inheritsLoose-DNrhibGS.js";const Sr=pr(P.jsx("path",{d:"M11.07 12.85c.77-1.39 2.25-2.21 3.11-3.44.91-1.29.4-3.7-2.18-3.7-1.69 0-2.52 1.28-2.87 2.34L6.54 6.96C7.25 4.83 9.18 3 11.99 3c2.35 0 3.96 1.07 4.78 2.41.7 1.15 1.11 3.3.03 4.9-1.2 1.77-2.35 2.31-2.97 3.45-.25.46-.35.76-.35 2.24h-2.89c-.01-.78-.13-2.05.48-3.15M14 20c0 1.1-.9 2-2 2s-2-.9-2-2 .9-2 2-2 2 .9 2 2"}),"QuestionMark");function R(s,e,t,n,r){if(typeof e=="function"?s!==e||!0:!e.has(s))throw new TypeError("Cannot write private member to an object whose class did not declare it");return e.set(s,t),t}function c(s,e,t,n){if(t==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?s!==e||!n:!e.has(s))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?n:t==="a"?n.call(s):n?n.value:e.get(s)}let qn=function(){const{crypto:s}=globalThis;if(s!=null&&s.randomUUID)return qn=s.randomUUID.bind(s),s.randomUUID();const e=new Uint8Array(1),t=s?()=>s.getRandomValues(e)[0]:()=>Math.random()*255&255;return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,n=>(+n^t()&15>>+n/4).toString(16))};function Et(s){return typeof s=="object"&&s!==null&&("name"in s&&s.name==="AbortError"||"message"in s&&String(s.message).includes("FetchRequestCanceledException"))}const Pt=s=>{if(s instanceof Error)return s;if(typeof s=="object"&&s!==null){try{if(Object.prototype.toString.call(s)==="[object Error]"){const e=new Error(s.message,s.cause?{cause:s.cause}:{});return s.stack&&(e.stack=s.stack),s.cause&&!e.cause&&(e.cause=s.cause),s.name&&(e.name=s.name),e}}catch{}try{return new Error(JSON.stringify(s))}catch{}}return new Error(s)};class x extends Error{}class H extends x{constructor(e,t,n,r){super(`${H.makeMessage(e,t,n)}`),this.status=e,this.headers=r,this.requestID=r==null?void 0:r.get("x-request-id"),this.error=t;const a=t;this.code=a==null?void 0:a.code,this.param=a==null?void 0:a.param,this.type=a==null?void 0:a.type}static makeMessage(e,t,n){const r=t!=null&&t.message?typeof t.message=="string"?t.message:JSON.stringify(t.message):t?JSON.stringify(t):n;return e&&r?`${e} ${r}`:e?`${e} status code (no body)`:r||"(no status code or body)"}static generate(e,t,n,r){if(!e||!r)return new pt({message:n,cause:Pt(t)});const a=t==null?void 0:t.error;return e===400?new Jn(e,a,n,r):e===401?new Hn(e,a,n,r):e===403?new Xn(e,a,n,r):e===404?new Kn(e,a,n,r):e===409?new Vn(e,a,n,r):e===422?new Gn(e,a,n,r):e===429?new Qn(e,a,n,r):e>=500?new zn(e,a,n,r):new H(e,a,n,r)}}class z extends H{constructor({message:e}={}){super(void 0,void 0,e||"Request was aborted.",void 0)}}class pt extends H{constructor({message:e,cause:t}){super(void 0,void 0,e||"Connection error.",void 0),t&&(this.cause=t)}}class Jt extends pt{constructor({message:e}={}){super({message:e??"Request timed out."})}}class Jn extends H{}class Hn extends H{}class Xn extends H{}class Kn extends H{}class Vn extends H{}class Gn extends H{}class Qn extends H{}class zn extends H{}class Yn extends x{constructor(){super("Could not parse response content as the length limit was reached")}}class Zn extends x{constructor(){super("Could not parse response content as the request was rejected by the content filter")}}class Re extends Error{constructor(e){super(e)}}const Ar=/^[a-z][a-z0-9+.-]*:/i,vr=s=>Ar.test(s);let K=s=>(K=Array.isArray,K(s)),gn=K;function es(s){return typeof s!="object"?{}:s??{}}function Cr(s){if(!s)return!0;for(const e in s)return!1;return!0}function Ir(s,e){return Object.prototype.hasOwnProperty.call(s,e)}function St(s){return s!=null&&typeof s=="object"&&!Array.isArray(s)}const Rr=(s,e)=>{if(typeof e!="number"||!Number.isInteger(e))throw new x(`${s} must be an integer`);if(e<0)throw new x(`${s} must be a positive integer`);return e},$r=s=>{try{return JSON.parse(s)}catch{return}},Be=s=>new Promise(e=>setTimeout(e,s)),we="5.23.2",kr=()=>typeof window<"u"&&typeof window.document<"u"&&typeof navigator<"u";function Or(){return typeof Deno<"u"&&Deno.build!=null?"deno":typeof EdgeRuntime<"u"?"edge":Object.prototype.toString.call(typeof globalThis.process<"u"?globalThis.process:0)==="[object process]"?"node":"unknown"}const Er=()=>{var t;const s=Or();if(s==="deno")return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":we,"X-Stainless-OS":yn(Deno.build.os),"X-Stainless-Arch":_n(Deno.build.arch),"X-Stainless-Runtime":"deno","X-Stainless-Runtime-Version":typeof Deno.version=="string"?Deno.version:((t=Deno.version)==null?void 0:t.deno)??"unknown"};if(typeof EdgeRuntime<"u")return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":we,"X-Stainless-OS":"Unknown","X-Stainless-Arch":`other:${EdgeRuntime}`,"X-Stainless-Runtime":"edge","X-Stainless-Runtime-Version":globalThis.process.version};if(s==="node")return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":we,"X-Stainless-OS":yn(globalThis.process.platform??"unknown"),"X-Stainless-Arch":_n(globalThis.process.arch??"unknown"),"X-Stainless-Runtime":"node","X-Stainless-Runtime-Version":globalThis.process.version??"unknown"};const e=Pr();return e?{"X-Stainless-Lang":"js","X-Stainless-Package-Version":we,"X-Stainless-OS":"Unknown","X-Stainless-Arch":"unknown","X-Stainless-Runtime":`browser:${e.browser}`,"X-Stainless-Runtime-Version":e.version}:{"X-Stainless-Lang":"js","X-Stainless-Package-Version":we,"X-Stainless-OS":"Unknown","X-Stainless-Arch":"unknown","X-Stainless-Runtime":"unknown","X-Stainless-Runtime-Version":"unknown"}};function Pr(){if(typeof navigator>"u"||!navigator)return null;const s=[{key:"edge",pattern:/Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"ie",pattern:/MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"ie",pattern:/Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"chrome",pattern:/Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"firefox",pattern:/Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"safari",pattern:/(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/}];for(const{key:e,pattern:t}of s){const n=t.exec(navigator.userAgent);if(n){const r=n[1]||0,a=n[2]||0,i=n[3]||0;return{browser:e,version:`${r}.${a}.${i}`}}}return null}const _n=s=>s==="x32"?"x32":s==="x86_64"||s==="x64"?"x64":s==="arm"?"arm":s==="aarch64"||s==="arm64"?"arm64":s?`other:${s}`:"unknown",yn=s=>(s=s.toLowerCase(),s.includes("ios")?"iOS":s==="android"?"Android":s==="darwin"?"MacOS":s==="win32"?"Windows":s==="freebsd"?"FreeBSD":s==="openbsd"?"OpenBSD":s==="linux"?"Linux":s?`Other:${s}`:"Unknown");let wn;const Tr=()=>wn??(wn=Er());function Mr(){if(typeof fetch<"u")return fetch;throw new Error("`fetch` is not defined as a global; Either pass `fetch` to the client, `new OpenAI({ fetch })` or polyfill the global, `globalThis.fetch = fetch`")}function ts(...s){const e=globalThis.ReadableStream;if(typeof e>"u")throw new Error("`ReadableStream` is not defined as a global; You will need to polyfill it, `globalThis.ReadableStream = ReadableStream`");return new e(...s)}function ns(s){let e=Symbol.asyncIterator in s?s[Symbol.asyncIterator]():s[Symbol.iterator]();return ts({start(){},async pull(t){const{done:n,value:r}=await e.next();n?t.close():t.enqueue(r)},async cancel(){var t;await((t=e.return)==null?void 0:t.call(e))}})}function ss(s){if(s[Symbol.asyncIterator])return s;const e=s.getReader();return{async next(){try{const t=await e.read();return t!=null&&t.done&&e.releaseLock(),t}catch(t){throw e.releaseLock(),t}},async return(){const t=e.cancel();return e.releaseLock(),await t,{done:!0,value:void 0}},[Symbol.asyncIterator](){return this}}}async function Nr(s){var n,r;if(s===null||typeof s!="object")return;if(s[Symbol.asyncIterator]){await((r=(n=s[Symbol.asyncIterator]()).return)==null?void 0:r.call(n));return}const e=s.getReader(),t=e.cancel();e.releaseLock(),await t}const jr=({headers:s,body:e})=>({bodyHeaders:{"content-type":"application/json"},body:JSON.stringify(e)}),rs="RFC3986",as=s=>String(s),bn={RFC1738:s=>String(s).replace(/%20/g,"+"),RFC3986:as},Fr="RFC1738";let Tt=(s,e)=>(Tt=Object.hasOwn??Function.prototype.call.bind(Object.prototype.hasOwnProperty),Tt(s,e));const ee=(()=>{const s=[];for(let e=0;e<256;++e)s.push("%"+((e<16?"0":"")+e.toString(16)).toUpperCase());return s})(),At=1024,Lr=(s,e,t,n,r)=>{if(s.length===0)return s;let a=s;if(typeof s=="symbol"?a=Symbol.prototype.toString.call(s):typeof s!="string"&&(a=String(s)),t==="iso-8859-1")return escape(a).replace(/%u[0-9a-f]{4}/gi,function(o){return"%26%23"+parseInt(o.slice(2),16)+"%3B"});let i="";for(let o=0;o<a.length;o+=At){const l=a.length>=At?a.slice(o,o+At):a,u=[];for(let m=0;m<l.length;++m){let h=l.charCodeAt(m);if(h===45||h===46||h===95||h===126||h>=48&&h<=57||h>=65&&h<=90||h>=97&&h<=122||r===Fr&&(h===40||h===41)){u[u.length]=l.charAt(m);continue}if(h<128){u[u.length]=ee[h];continue}if(h<2048){u[u.length]=ee[192|h>>6]+ee[128|h&63];continue}if(h<55296||h>=57344){u[u.length]=ee[224|h>>12]+ee[128|h>>6&63]+ee[128|h&63];continue}m+=1,h=65536+((h&1023)<<10|l.charCodeAt(m)&1023),u[u.length]=ee[240|h>>18]+ee[128|h>>12&63]+ee[128|h>>6&63]+ee[128|h&63]}i+=u.join("")}return i};function Dr(s){return!s||typeof s!="object"?!1:!!(s.constructor&&s.constructor.isBuffer&&s.constructor.isBuffer(s))}function xn(s,e){if(K(s)){const t=[];for(let n=0;n<s.length;n+=1)t.push(e(s[n]));return t}return e(s)}const is={brackets(s){return String(s)+"[]"},comma:"comma",indices(s,e){return String(s)+"["+e+"]"},repeat(s){return String(s)}},os=function(s,e){Array.prototype.push.apply(s,K(e)?e:[e])};let Sn;const B={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:"indices",charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encodeDotInKeys:!1,encoder:Lr,encodeValuesOnly:!1,format:rs,formatter:as,indices:!1,serializeDate(s){return(Sn??(Sn=Function.prototype.call.bind(Date.prototype.toISOString)))(s)},skipNulls:!1,strictNullHandling:!1};function Br(s){return typeof s=="string"||typeof s=="number"||typeof s=="boolean"||typeof s=="symbol"||typeof s=="bigint"}const vt={};function cs(s,e,t,n,r,a,i,o,l,u,m,h,g,d,b,w,v,E){let p=s,y=E,_=0,C=!1;for(;(y=y.get(vt))!==void 0&&!C;){const T=y.get(s);if(_+=1,typeof T<"u"){if(T===_)throw new RangeError("Cyclic object value");C=!0}typeof y.get(vt)>"u"&&(_=0)}if(typeof u=="function"?p=u(e,p):p instanceof Date?p=g==null?void 0:g(p):t==="comma"&&K(p)&&(p=xn(p,function(T){return T instanceof Date?g==null?void 0:g(T):T})),p===null){if(a)return l&&!w?l(e,B.encoder,v,"key",d):e;p=""}if(Br(p)||Dr(p)){if(l){const T=w?e:l(e,B.encoder,v,"key",d);return[(b==null?void 0:b(T))+"="+(b==null?void 0:b(l(p,B.encoder,v,"value",d)))]}return[(b==null?void 0:b(e))+"="+(b==null?void 0:b(String(p)))]}const k=[];if(typeof p>"u")return k;let $;if(t==="comma"&&K(p))w&&l&&(p=xn(p,l)),$=[{value:p.length>0?p.join(",")||null:void 0}];else if(K(u))$=u;else{const T=Object.keys(p);$=m?T.sort(m):T}const F=o?String(e).replace(/\./g,"%2E"):String(e),A=n&&K(p)&&p.length===1?F+"[]":F;if(r&&K(p)&&p.length===0)return A+"[]";for(let T=0;T<$.length;++T){const M=$[T],se=typeof M=="object"&&typeof M.value<"u"?M.value:p[M];if(i&&se===null)continue;const me=h&&o?M.replace(/\./g,"%2E"):M,N=K(p)?typeof t=="function"?t(A,me):A:A+(h?"."+me:"["+me+"]");E.set(s,_);const ie=new WeakMap;ie.set(vt,E),os(k,cs(se,N,t,n,r,a,i,o,t==="comma"&&w&&K(p)?null:l,u,m,h,g,d,b,w,v,ie))}return k}function Wr(s=B){if(typeof s.allowEmptyArrays<"u"&&typeof s.allowEmptyArrays!="boolean")throw new TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(typeof s.encodeDotInKeys<"u"&&typeof s.encodeDotInKeys!="boolean")throw new TypeError("`encodeDotInKeys` option can only be `true` or `false`, when provided");if(s.encoder!==null&&typeof s.encoder<"u"&&typeof s.encoder!="function")throw new TypeError("Encoder has to be a function.");const e=s.charset||B.charset;if(typeof s.charset<"u"&&s.charset!=="utf-8"&&s.charset!=="iso-8859-1")throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");let t=rs;if(typeof s.format<"u"){if(!Tt(bn,s.format))throw new TypeError("Unknown format option provided.");t=s.format}const n=bn[t];let r=B.filter;(typeof s.filter=="function"||K(s.filter))&&(r=s.filter);let a;if(s.arrayFormat&&s.arrayFormat in is?a=s.arrayFormat:"indices"in s?a=s.indices?"indices":"repeat":a=B.arrayFormat,"commaRoundTrip"in s&&typeof s.commaRoundTrip!="boolean")throw new TypeError("`commaRoundTrip` must be a boolean, or absent");const i=typeof s.allowDots>"u"?s.encodeDotInKeys?!0:B.allowDots:!!s.allowDots;return{addQueryPrefix:typeof s.addQueryPrefix=="boolean"?s.addQueryPrefix:B.addQueryPrefix,allowDots:i,allowEmptyArrays:typeof s.allowEmptyArrays=="boolean"?!!s.allowEmptyArrays:B.allowEmptyArrays,arrayFormat:a,charset:e,charsetSentinel:typeof s.charsetSentinel=="boolean"?s.charsetSentinel:B.charsetSentinel,commaRoundTrip:!!s.commaRoundTrip,delimiter:typeof s.delimiter>"u"?B.delimiter:s.delimiter,encode:typeof s.encode=="boolean"?s.encode:B.encode,encodeDotInKeys:typeof s.encodeDotInKeys=="boolean"?s.encodeDotInKeys:B.encodeDotInKeys,encoder:typeof s.encoder=="function"?s.encoder:B.encoder,encodeValuesOnly:typeof s.encodeValuesOnly=="boolean"?s.encodeValuesOnly:B.encodeValuesOnly,filter:r,format:t,formatter:n,serializeDate:typeof s.serializeDate=="function"?s.serializeDate:B.serializeDate,skipNulls:typeof s.skipNulls=="boolean"?s.skipNulls:B.skipNulls,sort:typeof s.sort=="function"?s.sort:null,strictNullHandling:typeof s.strictNullHandling=="boolean"?s.strictNullHandling:B.strictNullHandling}}function Ur(s,e={}){let t=s;const n=Wr(e);let r,a;typeof n.filter=="function"?(a=n.filter,t=a("",t)):K(n.filter)&&(a=n.filter,r=a);const i=[];if(typeof t!="object"||t===null)return"";const o=is[n.arrayFormat],l=o==="comma"&&n.commaRoundTrip;r||(r=Object.keys(t)),n.sort&&r.sort(n.sort);const u=new WeakMap;for(let g=0;g<r.length;++g){const d=r[g];n.skipNulls&&t[d]===null||os(i,cs(t[d],d,o,l,n.allowEmptyArrays,n.strictNullHandling,n.skipNulls,n.encodeDotInKeys,n.encode?n.encoder:null,n.filter,n.sort,n.allowDots,n.serializeDate,n.format,n.formatter,n.encodeValuesOnly,n.charset,u))}const m=i.join(n.delimiter);let h=n.addQueryPrefix===!0?"?":"";return n.charsetSentinel&&(n.charset==="iso-8859-1"?h+="utf8=%26%2310003%3B&":h+="utf8=%E2%9C%93&"),m.length>0?h+m:""}function qr(s){let e=0;for(const r of s)e+=r.length;const t=new Uint8Array(e);let n=0;for(const r of s)t.set(r,n),n+=r.length;return t}let An;function Ht(s){let e;return(An??(e=new globalThis.TextEncoder,An=e.encode.bind(e)))(s)}let vn;function Cn(s){let e;return(vn??(e=new globalThis.TextDecoder,vn=e.decode.bind(e)))(s)}var V,G;class gt{constructor(){V.set(this,void 0),G.set(this,void 0),R(this,V,new Uint8Array),R(this,G,null)}decode(e){if(e==null)return[];const t=e instanceof ArrayBuffer?new Uint8Array(e):typeof e=="string"?Ht(e):e;R(this,V,qr([c(this,V,"f"),t]));const n=[];let r;for(;(r=Jr(c(this,V,"f"),c(this,G,"f")))!=null;){if(r.carriage&&c(this,G,"f")==null){R(this,G,r.index);continue}if(c(this,G,"f")!=null&&(r.index!==c(this,G,"f")+1||r.carriage)){n.push(Cn(c(this,V,"f").subarray(0,c(this,G,"f")-1))),R(this,V,c(this,V,"f").subarray(c(this,G,"f"))),R(this,G,null);continue}const a=c(this,G,"f")!==null?r.preceding-1:r.preceding,i=Cn(c(this,V,"f").subarray(0,a));n.push(i),R(this,V,c(this,V,"f").subarray(r.index)),R(this,G,null)}return n}flush(){return c(this,V,"f").length?this.decode(`
2
2
  `):[]}}V=new WeakMap,G=new WeakMap;gt.NEWLINE_CHARS=new Set([`
3
3
  `,"\r"]);gt.NEWLINE_REGEXP=/\r\n|[\n\r]/g;function Jr(s,e){for(let r=e??0;r<s.length;r++){if(s[r]===10)return{preceding:r,index:r+1,carriage:!1};if(s[r]===13)return{preceding:r,index:r+1,carriage:!0}}return null}function Hr(s){for(let n=0;n<s.length-1;n++){if(s[n]===10&&s[n+1]===10||s[n]===13&&s[n+1]===13)return n+2;if(s[n]===13&&s[n+1]===10&&n+3<s.length&&s[n+2]===13&&s[n+3]===10)return n+4}return-1}const ot={off:0,error:200,warn:300,info:400,debug:500},In=(s,e,t)=>{if(s){if(Ir(ot,s))return s;q(t).warn(`${e} was set to ${JSON.stringify(s)}, expected one of ${JSON.stringify(Object.keys(ot))}`)}};function $e(){}function Je(s,e,t){return!e||ot[s]>ot[t]?$e:e[s].bind(e)}const Xr={error:$e,warn:$e,info:$e,debug:$e};let Rn=new WeakMap;function q(s){const e=s.logger,t=s.logLevel??"off";if(!e)return Xr;const n=Rn.get(e);if(n&&n[0]===t)return n[1];const r={error:Je("error",e,t),warn:Je("warn",e,t),info:Je("info",e,t),debug:Je("debug",e,t)};return Rn.set(e,[t,r]),r}const le=s=>(s.options&&(s.options={...s.options},delete s.options.headers),s.headers&&(s.headers=Object.fromEntries((s.headers instanceof Headers?[...s.headers]:Object.entries(s.headers)).map(([e,t])=>[e,e.toLowerCase()==="authorization"||e.toLowerCase()==="cookie"||e.toLowerCase()==="set-cookie"?"***":t]))),"retryOfRequestLogID"in s&&(s.retryOfRequestLogID&&(s.retryOf=s.retryOfRequestLogID),delete s.retryOfRequestLogID),s);var Ie;class ne{constructor(e,t,n){this.iterator=e,Ie.set(this,void 0),this.controller=t,R(this,Ie,n)}static fromSSEResponse(e,t,n){let r=!1;const a=n?q(n):console;async function*i(){if(r)throw new x("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");r=!0;let o=!1;try{for await(const l of Kr(e,t))if(!o){if(l.data.startsWith("[DONE]")){o=!0;continue}if(l.event===null||!l.event.startsWith("thread.")){let u;try{u=JSON.parse(l.data)}catch(m){throw a.error("Could not parse message into JSON:",l.data),a.error("From chunk:",l.raw),m}if(u&&u.error)throw new H(void 0,u.error,void 0,e.headers);yield u}else{let u;try{u=JSON.parse(l.data)}catch(m){throw console.error("Could not parse message into JSON:",l.data),console.error("From chunk:",l.raw),m}if(l.event=="error")throw new H(void 0,u.error,u.message,void 0);yield{event:l.event,data:u}}}o=!0}catch(l){if(Et(l))return;throw l}finally{o||t.abort()}}return new ne(i,t,n)}static fromReadableStream(e,t,n){let r=!1;async function*a(){const o=new gt,l=ss(e);for await(const u of l)for(const m of o.decode(u))yield m;for(const u of o.flush())yield u}async function*i(){if(r)throw new x("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");r=!0;let o=!1;try{for await(const l of a())o||l&&(yield JSON.parse(l));o=!0}catch(l){if(Et(l))return;throw l}finally{o||t.abort()}}return new ne(i,t,n)}[(Ie=new WeakMap,Symbol.asyncIterator)](){return this.iterator()}tee(){const e=[],t=[],n=this.iterator(),r=a=>({next:()=>{if(a.length===0){const i=n.next();e.push(i),t.push(i)}return a.shift()}});return[new ne(()=>r(e),this.controller,c(this,Ie,"f")),new ne(()=>r(t),this.controller,c(this,Ie,"f"))]}toReadableStream(){const e=this;let t;return ts({async start(){t=e[Symbol.asyncIterator]()},async pull(n){try{const{value:r,done:a}=await t.next();if(a)return n.close();const i=Ht(JSON.stringify(r)+`
4
4
  `);n.enqueue(i)}catch(r){n.error(r)}},async cancel(){var n;await((n=t.return)==null?void 0:n.call(t))}})}}async function*Kr(s,e){if(!s.body)throw e.abort(),typeof globalThis.navigator<"u"&&globalThis.navigator.product==="ReactNative"?new x("The default react-native fetch implementation does not support streaming. Please use expo/fetch: https://docs.expo.dev/versions/latest/sdk/expo/#expofetch-api"):new x("Attempted to iterate over a response with no body");const t=new Gr,n=new gt,r=ss(s.body);for await(const a of Vr(r))for(const i of n.decode(a)){const o=t.decode(i);o&&(yield o)}for(const a of n.flush()){const i=t.decode(a);i&&(yield i)}}async function*Vr(s){let e=new Uint8Array;for await(const t of s){if(t==null)continue;const n=t instanceof ArrayBuffer?new Uint8Array(t):typeof t=="string"?Ht(t):t;let r=new Uint8Array(e.length+n.length);r.set(e),r.set(n,e.length),e=r;let a;for(;(a=Hr(e))!==-1;)yield e.slice(0,a),e=e.slice(a)}e.length>0&&(yield e)}class Gr{constructor(){this.event=null,this.data=[],this.chunks=[]}decode(e){if(e.endsWith("\r")&&(e=e.substring(0,e.length-1)),!e){if(!this.event&&!this.data.length)return null;const a={event:this.event,data:this.data.join(`
@@ -1,2 +1,2 @@
1
- import{j as e}from"./createSvgIcon-DlIk-fDn.js";import{R as i}from"./iobroker_javascript__loadShare__react__loadShare__-i8pXne9X.js";import{i as r,I as n}from"./index-Cjl4b70e.js";import{i as a}from"./index-ee1BGSYh.js";import l from"./ScriptEditorVanillaMonaco-LjlfPO8c.js";import{I as c}from"./Save-DXaUpIPM.js";import"./_commonjsHelpers-Cpj98o6Y.js";import"./iobroker_javascript__mf_v__runtimeInit__mf_v__-DZdFIfoQ.js";import"./inheritsLoose-DNrhibGS.js";import"./preload-helper-BDBacUwf.js";const o={textArea:{width:"calc(100% - 10px)",resize:"none"},dialog:{height:"95%"},fullHeight:{height:"100%",overflow:"hidden"},args:s=>({color:s.palette.mode==="dark"?"white":"black",height:30,width:"100%",fontSize:16}),argsTitle:s=>({color:s.palette.mode==="dark"?"white":"black",fontWeight:"bold"})};class k extends i.Component{constructor(t){super(t),this.state={changed:!1,source:!t.source&&t.isReturn?`
1
+ import{j as e}from"./createSvgIcon-DlIk-fDn.js";import{R as i}from"./iobroker_javascript__loadShare__react__loadShare__-i8pXne9X.js";import{i as r,I as n}from"./index-Cjl4b70e.js";import{i as a}from"./index-CePzv5-W.js";import l from"./ScriptEditorVanillaMonaco-Xge2wqgO.js";import{I as c}from"./Save-DXaUpIPM.js";import"./_commonjsHelpers-Cpj98o6Y.js";import"./iobroker_javascript__mf_v__runtimeInit__mf_v__-DZdFIfoQ.js";import"./inheritsLoose-DNrhibGS.js";import"./preload-helper-BDBacUwf.js";const o={textArea:{width:"calc(100% - 10px)",resize:"none"},dialog:{height:"95%"},fullHeight:{height:"100%",overflow:"hidden"},args:s=>({color:s.palette.mode==="dark"?"white":"black",height:30,width:"100%",fontSize:16}),argsTitle:s=>({color:s.palette.mode==="dark"?"white":"black",fontWeight:"bold"})};class k extends i.Component{constructor(t){super(t),this.state={changed:!1,source:!t.source&&t.isReturn?`
2
2
  return false`:t.source}}componentDidMount(){setTimeout(()=>{var t;try{(t=window.document.getElementById("source-text-area"))==null||t.focus()}catch{}},100)}handleCancel(){this.props.onClose(!1)}handleOk(){(!this.props.isReturn||this.state.source.includes("return "))&&this.props.onClose(this.state.source)}onChange(t){this.setState({changed:!0,source:t})}render(){return e.jsxs(r.Dialog,{onClose:()=>!1,maxWidth:"lg",sx:{"& .MuiDialog-paper":o.dialog},fullWidth:!0,open:!0,"aria-labelledby":"source-dialog-title",children:[e.jsx(r.DialogTitle,{id:"source-dialog-title",children:a.I18n.t("Function editor")}),e.jsxs(r.DialogContent,{style:o.fullHeight,children:[this.props.args&&e.jsxs(r.Box,{sx:o.args,children:[e.jsx(r.Box,{component:"span",sx:o.argsTitle,children:a.I18n.t("function (")}),this.props.args,e.jsx(r.Box,{component:"span",sx:o.argsTitle,children:")"})]},"arguments"),e.jsx(l,{triggerPrettier:1,adapterName:this.props.adapterName,runningInstances:this.props.runningInstances,style:{...o.textArea,height:this.props.args?"calc(100% - 30px)":"100%"},name:"blockly",socket:this.props.socket,readOnly:!1,checkJs:!1,changed:this.state.changed,code:this.state.source,isDark:this.props.themeType==="dark",onChange:t=>this.onChange(t),language:"javascript"},"scriptEditor")]}),e.jsxs(r.DialogActions,{children:[e.jsx(r.Button,{variant:"contained",onClick:()=>this.handleOk(),color:"primary",startIcon:e.jsx(c,{}),children:a.I18n.t("Save")}),e.jsx(r.Button,{color:"grey",variant:"contained",onClick:()=>this.handleCancel(),startIcon:e.jsx(n,{}),children:a.I18n.t("Cancel")})]})]})}}export{k as default};
@@ -1 +1 @@
1
- import{j as n}from"./createSvgIcon-DlIk-fDn.js";import{R as S}from"./iobroker_javascript__loadShare__react__loadShare__-i8pXne9X.js";import{i as p,o as b,av as C}from"./index-Cjl4b70e.js";import{i as f}from"./index-ee1BGSYh.js";import"./_commonjsHelpers-Cpj98o6Y.js";import"./iobroker_javascript__mf_v__runtimeInit__mf_v__-DZdFIfoQ.js";import"./inheritsLoose-DNrhibGS.js";import"./preload-helper-BDBacUwf.js";function v(w){return/^script\.js\.global\./.test(w)}let O=0;function E(w){const t=/\x1b\[[0-9;]*m/g;return w.replace(t,"")}class R extends S.Component{monacoDiv=null;editor=null;monaco=window.monaco;insert="";originalCode;runningInstancesStr;monacoCounter=0;location;breakpoints;lastSearch="";typings={};decorations=[];triggerPrettier;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=S.createRef()}waitForMonaco(t){var e,s,o,r,l,a,h,g;let i=!!((r=(o=(s=(e=this.monaco)==null?void 0:e.languages)==null?void 0:s.typescript)==null?void 0:o.typescriptDefaults)!=null&&r.getCompilerOptions);if(!i||!this.props.runningInstances){if(this.monaco=window.monaco,i=!!((g=(h=(a=(l=this.monaco)==null?void 0:l.languages)==null?void 0:a.typescript)==null?void 0:h.typescriptDefaults)!=null&&g.getCompilerOptions),this.monacoCounter++,!i&&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 i=t&&Object.keys(t).find(e=>t==null?void 0:t[e]);i&&this.props.socket.sendTo(i.replace("system.adapter.",""),"loadTypings",null).then(e=>{this.setState({alive:!0,check:!0,typingsLoaded:!0}),this.setTypeCheck(!0),e.typings?(this.typings=e.typings,this.setEditorTypings(this.state.name)):console.error(`failed to load typings: ${e.error}`)})}componentDidMount(){var e,s,o,r,l,a,h,g,y,k,d,u;let t=!!((r=(o=(s=(e=this.monaco)==null?void 0:e.languages)==null?void 0:s.typescript)==null?void 0:o.typescriptDefaults)!=null&&r.getCompilerOptions);if((!t||!this.props.runningInstances)&&(this.monaco=window.monaco,t=!!((g=(h=(a=(l=this.monaco)==null?void 0:l.languages)==null?void 0:a.typescript)==null?void 0:h.typescriptDefaults)!=null&&g.getCompilerOptions),!t)){console.log("wait for monaco loaded..."),this.waitForMonaco(()=>this.componentDidMount());return}if(!this.editor&&t&&this.monaco){console.log("Init editor"),(k=(y=this.props).onRegisterSelect)==null||k.call(y,()=>{var m;if(this.editor){const D=this.editor.getSelection();if(D)return(m=this.editor.getModel())==null?void 0:m.getValueInRange(D)}});const c=this.monaco.languages.typescript.typescriptDefaults.getCompilerOptions();c.allowJs=!0,c.checkJs=this.props.checkJs!==!1,c.noLib=!0,c.lib=[],c.useUnknownInCatchVariables=!1,c.moduleResolution=this.monaco.languages.typescript.ModuleResolutionKind.NodeJs,c.target=this.monaco.languages.typescript.ScriptTarget.ESNext,c.module=this.monaco.languages.typescript.ModuleKind.ESNext,c.allowNonTsExtensions=!0,this.monaco.languages.typescript.typescriptDefaults.setCompilerOptions(c),this.setTypeCheck(!1),(d=this.monacoDiv)!=null&&d.current&&(this.editor=this.monaco.editor.create((u=this.monacoDiv)==null?void 0:u.current,{lineNumbers:"on",scrollBeyondLastLine:!1,automaticLayout:!0,glyphMargin:!!this.props.breakpoints,colorDecorators:!0}),this.editor.onDidChangeModelContent(()=>this.onChange()),this.loadTypings(),this.props.onForceSave&&this.editor.addCommand(this.monaco.KeyMod.CtrlCmd|this.monaco.KeyCode.KeyS,()=>this.props.onForceSave&&this.props.onForceSave()),setTimeout(()=>{this.highlightText(this.state.searchText),this.location=this.props.location||void 0,this.breakpoints=this.props.breakpoints,this.showDecorators()}))}const i={selectOnLineNumbers:!0,scrollBeyondLastLine:!1,automaticLayout:!0,readOnly:this.state.readOnly,language:this.state.language,isDark:this.state.isDark};this.setEditorOptions(i),this.editor&&(this.editor.focus(),this.editor.setValue(this.originalCode),this.props.onToggleBreakpoint?this.editor.onMouseDown(c=>{var D;const m=c.target;this.props.onToggleBreakpoint&&((D=m.detail)==null?void 0:D.glyphMarginLeft)!==void 0&&m.position&&this.props.onToggleBreakpoint(m.position.lineNumber-1)}):this.editor.onMouseDown(()=>{}))}setEditorOptions(t){var i;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&&((i=this.monaco)==null||i.editor.setTheme(t.isDark?"vs-dark":"vs")))}componentWillUnmount(){var t,i;this.editor&&((i=(t=this.props).onRegisterSelect)==null||i.call(t,null),this.editor.dispose(),this.editor=null)}async doPrettier(){var e,s,o,r;const t=this.props.runningInstances&&Object.keys(this.props.runningInstances).find(l=>{var a;return(a=this.props.runningInstances)==null?void 0:a[l]});if(!t){window.alert(f.I18n.t("No script adapter instance found to format the code"));return}const i=await this.props.socket.sendTo(t.replace("system.adapter.",""),"prettier",{code:(e=this.editor)==null?void 0:e.getValue(),type:this.state.language});i.error?this.setState({showError:{title:f.I18n.t("Error formatting code"),message:E(i.error)}}):i.code&&((s=this.editor)==null||s.setValue(i.code),(r=(o=this.props).onChange)==null||r.call(o,i.code),this.showDecorators())}setEditorLanguage(t){var e;if(!this.editor)return;const i=this.editor.getModel();if(i){const s=i.getValue(),o=i.uri.path,r=typeof o=="string"&&o.includes(".")?o.substring(0,o.lastIndexOf(".")):"index",l=t==="javascript"?"js":t==="typescript"?"ts":t;i.dispose();const a=t==="javascript"||t==="typescript"?"typescript":t,h=(e=this.monaco)==null?void 0:e.editor.createModel(s,a,this.monaco.Uri.from({scheme:window.location.protocol.replace(":",""),path:`${r}${O++}.${l}`}));h&&this.editor.setModel(h)}}setTypeCheck(t){var e,s;const i={noSemanticValidation:!this.state.alive||!t,noSyntaxValidation:!this.state.alive};(e=this.monaco)==null||e.languages.typescript.typescriptDefaults.setDiagnosticsOptions(i),(s=this.monaco)==null||s.languages.typescript.javascriptDefaults.setDiagnosticsOptions({noSemanticValidation:!this.state.alive||!t,noSyntaxValidation:!this.state.alive})}setEditorTypings(t=""){var o,r,l,a,h,g,y,k;const i=v(t),e=`${t}.d.ts`,s=[];for(const d of Object.keys(this.typings))i&&(d==="global.d.ts"||d.startsWith("script.js.global")&&d!==e)||s.push({filePath:d,content:this.typings[d]});if((a=(l=(r=(o=this.monaco)==null?void 0:o.languages)==null?void 0:r.typescript)==null?void 0:l.typescriptDefaults)!=null&&a.setExtraLibs)this.monaco.languages.typescript.typescriptDefaults.setExtraLibs(s);else if((k=(y=(g=(h=this.monaco)==null?void 0:h.languages)==null?void 0:g.typescript)==null?void 0:y.typescriptDefaults)!=null&&k.addExtraLib){const d=this.monaco.languages.typescript.typescriptDefaults.getExtraLibs();s.forEach(u=>{!d[u.filePath]&&this.monaco&&this.monaco.languages.typescript.typescriptDefaults.addExtraLib(u.content,u.filePath)})}}insertTextIntoEditor(t){if(!this.editor||!this.monaco)return;const i=this.editor.getSelection();if(i){const e=new this.monaco.Range(i.startLineNumber,i.startColumn,i.endLineNumber,i.endColumn);this.editor.executeEdits("",[{range:e,text:t,forceMoveMarkers:!0}])}this.editor.focus()}highlightText(t){var e;if(!this.editor||!this.monaco)return;const i=t?(e=this.editor.getModel())==null?void 0:e.findMatches(t,!0,!1,!1,null,!0):void 0;if(i!=null&&i.length)i.forEach(s=>{var o;return(o=this.editor)==null?void 0:o.setSelection(s.range)}),this.editor.revealLine(i[0].range.startLineNumber);else{const s=this.editor.getPosition();if(s){const o=s.lineNumber,r=s.column;this.editor.setSelection(new this.monaco.Range(o,r,o,r))}}}showDecorators(){var i;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"}})),(i=this.breakpoints)==null||i.forEach(e=>{this.monaco&&t.push({range:new this.monaco.Range(e.location.lineNumber+1,0,e.location.lineNumber+1,100),options:{isWholeLine:!0,glyphMarginClassName:this.props.isDark?"monacoBreakPointDark":"monacoBreakPoint"}})}),this.editor){const e=this.editor.getModel();e&&(this.decorations=e.deltaDecorations(this.decorations,t))}}initNewScript(t,i){var e;this.setState({name:t}),this.originalCode=i||"",(e=this.editor)==null||e.setValue(i||""),this.highlightText(this.lastSearch),this.showDecorators(),this.setEditorTypings(t)}scrollToLineIfNeeded(t){if(this.editor){const i=this.editor.getVisibleRanges();(!i||!i[0]||i[0].startLineNumber>t||t>i[0].endLineNumber)&&this.editor.revealLineInCenter(t)}}UNSAFE_componentWillReceiveProps(t){const i={};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"}),i.language=t.language||"javascript"):this.state.readOnly!==(t.readOnly||!1)?(this.setState({readOnly:t.readOnly||!1}),i.readOnly=t.readOnly):this.state.isDark!==(t.isDark||!1)&&(this.setState({isDark:t.isDark||!1}),i.isDark=t.isDark),this.setEditorOptions(i),this.insert!==t.insert&&(this.insert=t.insert||"",this.insert&&(console.log(`Insert text: ${this.insert}`),setTimeout(e=>{this.insertTextIntoEditor(e),setTimeout(()=>this.props.onInserted&&this.props.onInserted(),100)},100,this.insert)))}onChange(){var t,i;!this.props.readOnly&&this.editor&&((i=(t=this.props).onChange)==null||i.call(t,this.editor.getValue()))}renderErrorDialog(){return this.state.showError?this.state.showError.full?n.jsxs(p.Dialog,{open:!0,maxWidth:"md",onClose:()=>this.setState({showError:null}),children:[n.jsx(p.DialogTitle,{children:this.state.showError.title||f.I18n.t("Error")}),n.jsx(p.DialogContent,{children:n.jsx("pre",{children:n.jsx("code",{children:this.state.showError.message})})}),n.jsx(p.DialogActions,{children:n.jsxs(p.Button,{variant:"contained",startIcon:n.jsx(b,{}),onClick:()=>this.setState({showError:null}),children:[f.I18n.t("Close")," "]})})]}):n.jsx(p.Snackbar,{open:!0,autoHideDuration:5e3,onClose:()=>this.setState({showError:null}),message:this.state.showError.title,action:n.jsxs(S.Fragment,{children:[n.jsx(p.Button,{color:"secondary",size:"small",onClick:()=>this.setState({showError:{...this.state.showError,full:!0}}),children:f.I18n.t("More")}),n.jsx(p.IconButton,{size:"small","aria-label":"close",color:"inherit",onClick:()=>this.setState({showError:null}),children:n.jsx(b,{fontSize:"small"})})]})}):null}render(){var t,i,e;return!((e=(i=(t=this.monaco)==null?void 0:t.languages)==null?void 0:i.typescript)!=null&&e.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(s=>console.error("Error formatting code:",s)),50)),n.jsxs("div",{ref:this.monacoDiv,style:{...this.props.style,width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:[this.renderErrorDialog(),!this.state.check&&n.jsx(p.Fab,{size:"small",title:f.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:n.jsx(C,{})})]}))}}export{R as default};
1
+ import{j as n}from"./createSvgIcon-DlIk-fDn.js";import{R as S}from"./iobroker_javascript__loadShare__react__loadShare__-i8pXne9X.js";import{i as p,o as b,av as C}from"./index-Cjl4b70e.js";import{i as f}from"./index-CePzv5-W.js";import"./_commonjsHelpers-Cpj98o6Y.js";import"./iobroker_javascript__mf_v__runtimeInit__mf_v__-DZdFIfoQ.js";import"./inheritsLoose-DNrhibGS.js";import"./preload-helper-BDBacUwf.js";function v(w){return/^script\.js\.global\./.test(w)}let O=0;function E(w){const t=/\x1b\[[0-9;]*m/g;return w.replace(t,"")}class R extends S.Component{monacoDiv=null;editor=null;monaco=window.monaco;insert="";originalCode;runningInstancesStr;monacoCounter=0;location;breakpoints;lastSearch="";typings={};decorations=[];triggerPrettier;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=S.createRef()}waitForMonaco(t){var e,s,o,r,l,a,h,g;let i=!!((r=(o=(s=(e=this.monaco)==null?void 0:e.languages)==null?void 0:s.typescript)==null?void 0:o.typescriptDefaults)!=null&&r.getCompilerOptions);if(!i||!this.props.runningInstances){if(this.monaco=window.monaco,i=!!((g=(h=(a=(l=this.monaco)==null?void 0:l.languages)==null?void 0:a.typescript)==null?void 0:h.typescriptDefaults)!=null&&g.getCompilerOptions),this.monacoCounter++,!i&&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 i=t&&Object.keys(t).find(e=>t==null?void 0:t[e]);i&&this.props.socket.sendTo(i.replace("system.adapter.",""),"loadTypings",null).then(e=>{this.setState({alive:!0,check:!0,typingsLoaded:!0}),this.setTypeCheck(!0),e.typings?(this.typings=e.typings,this.setEditorTypings(this.state.name)):console.error(`failed to load typings: ${e.error}`)})}componentDidMount(){var e,s,o,r,l,a,h,g,y,k,d,u;let t=!!((r=(o=(s=(e=this.monaco)==null?void 0:e.languages)==null?void 0:s.typescript)==null?void 0:o.typescriptDefaults)!=null&&r.getCompilerOptions);if((!t||!this.props.runningInstances)&&(this.monaco=window.monaco,t=!!((g=(h=(a=(l=this.monaco)==null?void 0:l.languages)==null?void 0:a.typescript)==null?void 0:h.typescriptDefaults)!=null&&g.getCompilerOptions),!t)){console.log("wait for monaco loaded..."),this.waitForMonaco(()=>this.componentDidMount());return}if(!this.editor&&t&&this.monaco){console.log("Init editor"),(k=(y=this.props).onRegisterSelect)==null||k.call(y,()=>{var m;if(this.editor){const D=this.editor.getSelection();if(D)return(m=this.editor.getModel())==null?void 0:m.getValueInRange(D)}});const c=this.monaco.languages.typescript.typescriptDefaults.getCompilerOptions();c.allowJs=!0,c.checkJs=this.props.checkJs!==!1,c.noLib=!0,c.lib=[],c.useUnknownInCatchVariables=!1,c.moduleResolution=this.monaco.languages.typescript.ModuleResolutionKind.NodeJs,c.target=this.monaco.languages.typescript.ScriptTarget.ESNext,c.module=this.monaco.languages.typescript.ModuleKind.ESNext,c.allowNonTsExtensions=!0,this.monaco.languages.typescript.typescriptDefaults.setCompilerOptions(c),this.setTypeCheck(!1),(d=this.monacoDiv)!=null&&d.current&&(this.editor=this.monaco.editor.create((u=this.monacoDiv)==null?void 0:u.current,{lineNumbers:"on",scrollBeyondLastLine:!1,automaticLayout:!0,glyphMargin:!!this.props.breakpoints,colorDecorators:!0}),this.editor.onDidChangeModelContent(()=>this.onChange()),this.loadTypings(),this.props.onForceSave&&this.editor.addCommand(this.monaco.KeyMod.CtrlCmd|this.monaco.KeyCode.KeyS,()=>this.props.onForceSave&&this.props.onForceSave()),setTimeout(()=>{this.highlightText(this.state.searchText),this.location=this.props.location||void 0,this.breakpoints=this.props.breakpoints,this.showDecorators()}))}const i={selectOnLineNumbers:!0,scrollBeyondLastLine:!1,automaticLayout:!0,readOnly:this.state.readOnly,language:this.state.language,isDark:this.state.isDark};this.setEditorOptions(i),this.editor&&(this.editor.focus(),this.editor.setValue(this.originalCode),this.props.onToggleBreakpoint?this.editor.onMouseDown(c=>{var D;const m=c.target;this.props.onToggleBreakpoint&&((D=m.detail)==null?void 0:D.glyphMarginLeft)!==void 0&&m.position&&this.props.onToggleBreakpoint(m.position.lineNumber-1)}):this.editor.onMouseDown(()=>{}))}setEditorOptions(t){var i;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&&((i=this.monaco)==null||i.editor.setTheme(t.isDark?"vs-dark":"vs")))}componentWillUnmount(){var t,i;this.editor&&((i=(t=this.props).onRegisterSelect)==null||i.call(t,null),this.editor.dispose(),this.editor=null)}async doPrettier(){var e,s,o,r;const t=this.props.runningInstances&&Object.keys(this.props.runningInstances).find(l=>{var a;return(a=this.props.runningInstances)==null?void 0:a[l]});if(!t){window.alert(f.I18n.t("No script adapter instance found to format the code"));return}const i=await this.props.socket.sendTo(t.replace("system.adapter.",""),"prettier",{code:(e=this.editor)==null?void 0:e.getValue(),type:this.state.language});i.error?this.setState({showError:{title:f.I18n.t("Error formatting code"),message:E(i.error)}}):i.code&&((s=this.editor)==null||s.setValue(i.code),(r=(o=this.props).onChange)==null||r.call(o,i.code),this.showDecorators())}setEditorLanguage(t){var e;if(!this.editor)return;const i=this.editor.getModel();if(i){const s=i.getValue(),o=i.uri.path,r=typeof o=="string"&&o.includes(".")?o.substring(0,o.lastIndexOf(".")):"index",l=t==="javascript"?"js":t==="typescript"?"ts":t;i.dispose();const a=t==="javascript"||t==="typescript"?"typescript":t,h=(e=this.monaco)==null?void 0:e.editor.createModel(s,a,this.monaco.Uri.from({scheme:window.location.protocol.replace(":",""),path:`${r}${O++}.${l}`}));h&&this.editor.setModel(h)}}setTypeCheck(t){var e,s;const i={noSemanticValidation:!this.state.alive||!t,noSyntaxValidation:!this.state.alive};(e=this.monaco)==null||e.languages.typescript.typescriptDefaults.setDiagnosticsOptions(i),(s=this.monaco)==null||s.languages.typescript.javascriptDefaults.setDiagnosticsOptions({noSemanticValidation:!this.state.alive||!t,noSyntaxValidation:!this.state.alive})}setEditorTypings(t=""){var o,r,l,a,h,g,y,k;const i=v(t),e=`${t}.d.ts`,s=[];for(const d of Object.keys(this.typings))i&&(d==="global.d.ts"||d.startsWith("script.js.global")&&d!==e)||s.push({filePath:d,content:this.typings[d]});if((a=(l=(r=(o=this.monaco)==null?void 0:o.languages)==null?void 0:r.typescript)==null?void 0:l.typescriptDefaults)!=null&&a.setExtraLibs)this.monaco.languages.typescript.typescriptDefaults.setExtraLibs(s);else if((k=(y=(g=(h=this.monaco)==null?void 0:h.languages)==null?void 0:g.typescript)==null?void 0:y.typescriptDefaults)!=null&&k.addExtraLib){const d=this.monaco.languages.typescript.typescriptDefaults.getExtraLibs();s.forEach(u=>{!d[u.filePath]&&this.monaco&&this.monaco.languages.typescript.typescriptDefaults.addExtraLib(u.content,u.filePath)})}}insertTextIntoEditor(t){if(!this.editor||!this.monaco)return;const i=this.editor.getSelection();if(i){const e=new this.monaco.Range(i.startLineNumber,i.startColumn,i.endLineNumber,i.endColumn);this.editor.executeEdits("",[{range:e,text:t,forceMoveMarkers:!0}])}this.editor.focus()}highlightText(t){var e;if(!this.editor||!this.monaco)return;const i=t?(e=this.editor.getModel())==null?void 0:e.findMatches(t,!0,!1,!1,null,!0):void 0;if(i!=null&&i.length)i.forEach(s=>{var o;return(o=this.editor)==null?void 0:o.setSelection(s.range)}),this.editor.revealLine(i[0].range.startLineNumber);else{const s=this.editor.getPosition();if(s){const o=s.lineNumber,r=s.column;this.editor.setSelection(new this.monaco.Range(o,r,o,r))}}}showDecorators(){var i;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"}})),(i=this.breakpoints)==null||i.forEach(e=>{this.monaco&&t.push({range:new this.monaco.Range(e.location.lineNumber+1,0,e.location.lineNumber+1,100),options:{isWholeLine:!0,glyphMarginClassName:this.props.isDark?"monacoBreakPointDark":"monacoBreakPoint"}})}),this.editor){const e=this.editor.getModel();e&&(this.decorations=e.deltaDecorations(this.decorations,t))}}initNewScript(t,i){var e;this.setState({name:t}),this.originalCode=i||"",(e=this.editor)==null||e.setValue(i||""),this.highlightText(this.lastSearch),this.showDecorators(),this.setEditorTypings(t)}scrollToLineIfNeeded(t){if(this.editor){const i=this.editor.getVisibleRanges();(!i||!i[0]||i[0].startLineNumber>t||t>i[0].endLineNumber)&&this.editor.revealLineInCenter(t)}}UNSAFE_componentWillReceiveProps(t){const i={};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"}),i.language=t.language||"javascript"):this.state.readOnly!==(t.readOnly||!1)?(this.setState({readOnly:t.readOnly||!1}),i.readOnly=t.readOnly):this.state.isDark!==(t.isDark||!1)&&(this.setState({isDark:t.isDark||!1}),i.isDark=t.isDark),this.setEditorOptions(i),this.insert!==t.insert&&(this.insert=t.insert||"",this.insert&&(console.log(`Insert text: ${this.insert}`),setTimeout(e=>{this.insertTextIntoEditor(e),setTimeout(()=>this.props.onInserted&&this.props.onInserted(),100)},100,this.insert)))}onChange(){var t,i;!this.props.readOnly&&this.editor&&((i=(t=this.props).onChange)==null||i.call(t,this.editor.getValue()))}renderErrorDialog(){return this.state.showError?this.state.showError.full?n.jsxs(p.Dialog,{open:!0,maxWidth:"md",onClose:()=>this.setState({showError:null}),children:[n.jsx(p.DialogTitle,{children:this.state.showError.title||f.I18n.t("Error")}),n.jsx(p.DialogContent,{children:n.jsx("pre",{children:n.jsx("code",{children:this.state.showError.message})})}),n.jsx(p.DialogActions,{children:n.jsxs(p.Button,{variant:"contained",startIcon:n.jsx(b,{}),onClick:()=>this.setState({showError:null}),children:[f.I18n.t("Close")," "]})})]}):n.jsx(p.Snackbar,{open:!0,autoHideDuration:5e3,onClose:()=>this.setState({showError:null}),message:this.state.showError.title,action:n.jsxs(S.Fragment,{children:[n.jsx(p.Button,{color:"secondary",size:"small",onClick:()=>this.setState({showError:{...this.state.showError,full:!0}}),children:f.I18n.t("More")}),n.jsx(p.IconButton,{size:"small","aria-label":"close",color:"inherit",onClick:()=>this.setState({showError:null}),children:n.jsx(b,{fontSize:"small"})})]})}):null}render(){var t,i,e;return!((e=(i=(t=this.monaco)==null?void 0:t.languages)==null?void 0:i.typescript)!=null&&e.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(s=>console.error("Error formatting code:",s)),50)),n.jsxs("div",{ref:this.monacoDiv,style:{...this.props.style,width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:[this.renderErrorDialog(),!this.state.check&&n.jsx(p.Fab,{size:"small",title:f.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:n.jsx(C,{})})]}))}}export{R as default};
@@ -1 +1 @@
1
- import{j as t}from"./createSvgIcon-DlIk-fDn.js";import{i as u}from"./iobroker_javascript__loadShare__react__loadShare__-i8pXne9X.js";import{u as pe,a as xe,i as x,M as X,C as te,G as be,b as Ce,c as he,I as we,S as J,d as ve,e as le,j as je,D as Ie,f as Oe}from"./index-ee1BGSYh.js";import{i as N,C as Se}from"./index-Cjl4b70e.js";import"./_commonjsHelpers-Cpj98o6Y.js";import"./iobroker_javascript__mf_v__runtimeInit__mf_v__-DZdFIfoQ.js";import"./inheritsLoose-DNrhibGS.js";import"./preload-helper-BDBacUwf.js";function Ae(n){const s=pe().getMonitor(),[i,r]=xe(s,n);return u.useEffect(()=>s.subscribeToOffsetChange(r)),u.useEffect(()=>s.subscribeToStateChange(r)),i}let V;function ye(){return V||(V=new Image,V.src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="),V}const De="_wrapperRules_nnott_1",ke="_rootWrapper_nnott_9",Ne="_addClass_nnott_14",ne={wrapperRules:De,rootWrapper:ke,addClass:Ne},$e="_switchesItem_10ls3_1",Be="_switchesItemActive_10ls3_28",Ee="_iconTheme_10ls3_36",se={switchesItem:$e,switchesItemActive:Be,iconTheme:Ee},ue=({name:n,id:e,active:s,icon:i,adapter:r,socket:o,onDoubleClick:c,title:l,onTouchMove:d,style:I})=>t.jsxs("div",{onDoubleClick:c,onTouchMove:d,title:l?x.I18n.t(l):void 0,className:x.Utils.clsx(se.switchesItem,s&&se.switchesItemActive,`block-${e}`),children:[t.jsx(X,{iconName:i,className:se.iconTheme,adapter:r,socket:o,style:I}),t.jsx("span",{children:n?x.I18n.t(n):""})]},e),Me="_cardStyle_8rq8v_1",qe="_cardStyleActive_8rq8v_17",He="_controlMenu_8rq8v_22",Te="_closeBtn_8rq8v_31",We="_isDelete_8rq8v_73",Pe="_drag_mobile_8rq8v_90",G={cardStyle:Me,cardStyleActive:qe,controlMenu:He,closeBtn:Te,isDelete:We,drag_mobile:Pe};function K(n,e,s){let i;switch(n){case"actions":if(s==="else")return i={...e,actions:{...e[n],else:[...e[n].else]}},i;if(s==="then")return i={...e,actions:{...e[n],then:[...e[n].then]}},i;throw console.error(`Unknown additionalParameter: ${s}`),new Error(`Unknown additionalParameter: ${s}`);case"triggers":return i={...e,triggers:[...e.triggers]},i;case"conditions":return i={...e,conditions:[...e.conditions]},i;default:throw new Error(`Unknown name: ${n}`)}}function z(n,e,s,i){var r;switch(n){case"actions":return e.actions[s]=e.actions[s].filter(o=>o._id!==i),e;case"conditions":return e.conditions[s]=(r=e.conditions[s])==null?void 0:r.filter(o=>o._id!==i),e;case"triggers":default:return e.triggers=e.triggers.filter(o=>o._id!==i),e}}function Fe(n,e,s){const{_id:i,acceptedBy:r}=n;let o;if(!r||!e[r])return console.warn(`Cannot find ${r}`),e;switch(r){case"actions":if(o=e.actions[s].find(c=>c._id===i),!o)console.warn(`Cannot find ${i}`);else{const c=e.actions[s].indexOf(o);e.actions[s][c]=n}return e;case"conditions":if(o=e.conditions[s].find(c=>c._id===i),!o)console.warn(`Cannot find ${i}`);else{const c=e.conditions[s].indexOf(o);e.conditions[s][c]=n}return e;default:if(o=e.triggers.find(c=>c._id===i),!o)console.warn(`Cannot find ${i}`);else{const c=e.triggers.indexOf(o);e.triggers[c]=n}return e}}const me=u.memo(n=>{var B;const{setUserRules:e,userRules:s,_id:i,id:r,blockValue:o,active:c,acceptedBy:l,isTourOpen:d,setTourStep:I,tourStep:S}=n,[O,_]=u.useState(null),{blocks:a,socket:k,onUpdate:H,setOnUpdate:w,onDebugMessage:f,enableSimulation:b}=u.useContext(te),p=u.useCallback(m=>a==null?void 0:a.find(C=>C.getStaticData().id===m),[a]),h=u.useCallback(m=>{const C=Fe(m,s,o);C&&e(C)},[s]),v=m=>{m.currentTarget!==O&&_(m.currentTarget)},M=()=>_(null),W=u.useMemo(()=>{const m=p(r)||be;return t.jsx(m,{...n,notFound:!p(r),isTourOpen:d,setTourStep:I,tourStep:S,onUpdate:H,setOnUpdate:w,enableSimulation:b,onDebugMessage:f,onChange:h,className:void 0,socket:k})},[s,H,f,b]),[$,q]=u.useState(!1);return t.jsxs("div",{onMouseMove:v,onMouseEnter:v,onMouseLeave:M,onMouseDown:m=>{if(m.ctrlKey){let C;const j=K(l,s,o);l==="conditions"?(C=j.conditions[o].find(g=>g._id===i),C&&j.conditions[o].splice(j.conditions[o].indexOf(C),0,{...C,_id:Date.now()})):l==="actions"?(C=j.actions[o].find(g=>g._id===i),C&&j.actions[o].splice(j.actions[o].indexOf(C),0,{...C,_id:Date.now()})):(C=j.triggers.find(g=>g._id===i),C&&j.triggers.splice(j[l].indexOf(C),0,{...C,_id:Date.now()})),e(j)}},id:"height",style:c?{width:(((B=document.getElementById("width"))==null?void 0:B.clientWidth)||0)-70}:void 0,className:`${G.cardStyle} ${c?G.cardStyleActive:null} ${$?G.isDelete:null}`,children:[t.jsx("div",{className:G.drag_mobile}),W,e&&t.jsx("div",{className:G.controlMenu,style:O?{opacity:1}:{opacity:0},children:t.jsx("div",{onClick:()=>{let m=K(l,s,o);m=z(l,m,o,i),q(!0),setTimeout(()=>{l==="triggers"&&w(!0),e(m)},300)},className:G.closeBtn})})]})}),Ue={position:"fixed",pointerEvents:"none",zIndex:100,left:0,top:0,width:"100%",height:"100%"},Je=(n,e,s)=>{if(!n||!e)return{display:"none"};let{x:i,y:r}=e;const o=`translate(${i}px, ${r}px)`;return{transform:o,WebkitTransform:o}},Le=n=>{const{itemType:e,isDragging:s,item:i,initialOffset:r,currentOffset:o,targetIds:c}=Ae(d=>({item:d.getItem(),itemType:d.getItemType(),initialOffset:d.getInitialSourceClientOffset(),currentOffset:d.getSourceClientOffset(),isDragging:d.isDragging(),targetIds:d.getTargetIds()})),l=()=>{switch(e){case"box":return c.length?t.jsx(me,{active:!0,...i,allBlocks:n.allBlocks}):t.jsx(ue,{active:!0,...i,socket:n.socket});default:return null}};return s?t.jsx("div",{style:Ue,children:t.jsx("div",{style:Je(r,o),children:l()})}):null},ze="_border_wrpm3_1",Ge="_emptyBlockStyle_wrpm3_6",Ke="_emptyBlock_wrpm3_6",Qe="_selectOnChange_wrpm3_22",Xe="_selectOnChangeHelp_wrpm3_28",Ye="_selectOnChangeHelpIcon_wrpm3_34",Ze="_emptyBlockNone_wrpm3_49",Ve="_mainBlockItemRules_wrpm3_55",Re="_nameBlockItems_wrpm3_63",et="_contentBlockItem_wrpm3_73",tt="_wrapperMargin_wrpm3_81",nt="_contentHeightOn_wrpm3_87",st="_contentHeightOff_wrpm3_99",ot="_cardAdd_wrpm3_105",it="_blockCardAdd_wrpm3_125",ct="_addClassOverflow_wrpm3_136",at="_addClassHeight_wrpm3_140",D={border:ze,emptyBlockStyle:Ge,emptyBlock:Ke,selectOnChange:Qe,selectOnChangeHelp:Xe,selectOnChangeHelpIcon:Ye,emptyBlockNone:Ze,mainBlockItemRules:Ve,nameBlockItems:Re,contentBlockItem:et,wrapperMargin:tt,contentHeightOn:nt,contentHeightOff:st,cardAdd:ot,blockCardAdd:it,addClassOverflow:ct,addClassHeight:at};function re(n,e){const[s,i]=u.useState(window.localStorage.getItem(e)?JSON.parse(window.localStorage.getItem(e)||""):n);return[s,o=>{window.localStorage.setItem(e,JSON.stringify(o)),i(o)},!!window.localStorage.getItem(e)]}function rt(n,e){let s=0,i=null,r;return function(...o){const c=Date.now();r=o,c-s>=e?(s=c,n.apply(this,o)):i||(i=setTimeout(()=>{s=Date.now(),i=null,n.apply(this,r)},e-(c-s)))}}function ee(n){if(Array.isArray(n))return n.map(e=>ee(e));if(typeof n=="function")return n.bind(null);if(n&&typeof n=="object"){const e={};return Object.keys(n).forEach(s=>{e[s]=ee(n[s])}),e}return n}const oe=rt((n,e)=>n(e),0);function R(n,e){const s=e.find(i=>i._id===n);return{card:s,index:s?e.indexOf(s):-1}}function ie(n,e,s,i,r,o,c,l,d){const{card:I,index:S}=R(n,s);if(!(S<e&&l<d)&&!(S>e&&l>d)&&I&&S!==e){const O=ee(s);O.splice(S,1),O.splice(e,0,I);const _=ee(r);switch(o){case"actions":_.actions[c]=O,oe(i,_);return;case"conditions":_.conditions[c]=O,oe(i,_);return;default:_.triggers=O,oe(i,_);return}}}const lt="_drag_7xfhc_1",dt="_root_7xfhc_11",de={drag:lt,root:dt},_e=({typeBlock:n,allProperties:e,id:s,isActive:i,setUserRules:r,userRules:o,children:c,_id:l,blockValue:d})=>{const{setOnUpdate:I}=u.useContext(te),[{opacity:S},O,_]=Ce({type:"box",item:()=>({...e,id:s,isActive:i,_id:l}),end:(w,f)=>{const{acceptedBy:b}=w,p=f.getDropResult();let h;if(!p)return typeof l=="number"&&!f.getTargetIds().length&&(h=K(b,o,d),h=z(b,h,d,l),r(h)),null;if(p.blockValue!==d){const v=typeof l=="number"?l:Date.now();h=K(b,o,p.blockValue);const M={id:w.id,acceptedBy:w.acceptedBy};switch(b){case"actions":return d&&(h=z("actions",h,d,v)),h=z("actions",h,p.blockValue,v),h.actions[p.blockValue].push({...M,_id:v}),r(h);case"conditions":return typeof d=="number"&&(h=z("conditions",h,d,v)),h=z("conditions",h,p.blockValue,v),h.conditions[p.blockValue].push({...M,_id:v}),r(h);default:return I(!0),h=z("triggers",h,p.blockValue,v),h.triggers.push({...M,_id:v}),r(h)}}},collect:w=>({opacity:w.isDragging()?.4:1,isDragging:w.isDragging()})}),a=u.useRef(null),[,k]=he({accept:"box",canDrop:()=>!1,hover({_id:w,acceptedBy:f},b){var W;if(!a.current||n!==f)return;const p=(W=a.current)==null?void 0:W.getBoundingClientRect(),h=(p.bottom-p.top)/2,v=b.getClientOffset(),M=((v==null?void 0:v.y)||0)-p.top;if(l&&w!==l)switch(f){case"actions":if(d==="then"||d==="else"){const{index:$}=R(l,o.actions[d]);$!==w&&ie(w,$,o[f][d],r,o,f,d,M,h)}return;case"conditions":if(typeof d=="number"){const{index:$}=R(l,o[f][d]);$!==w&&ie(w,$,o[f][d],r,o,f,d,M,h)}return;default:{const{index:$}=R(l,o[f]);$!==w&&ie(w,$,o[f],r,o,f,void 0,M,h);return}}}});u.useEffect(()=>{_(ye(),{captureDraggingState:!0})},[]),O(k(a));const H=window.innerWidth<600;return t.jsxs("div",{ref:H&&l?null:a,className:de.root,style:{opacity:S},children:[t.jsx("div",{className:l?de.drag:null,ref:l&&H?a:null}),c]})},ft=({onClose:n,open:e})=>t.jsxs(N.Dialog,{open:e,onClose:n,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[t.jsx(N.DialogContent,{children:t.jsxs("div",{style:{fontSize:"1rem",fontFamily:'"Roboto", "Helvetica", "Arial", sans-serif',fontWeight:400,lineHeight:1.5,letterSpacing:"0.00938em"},children:[t.jsx("h3",{children:x.I18n.t("On condition change")}),t.jsx("div",{children:x.I18n.t("help_on_change")}),t.jsx("h3",{children:x.I18n.t("Just check")}),t.jsx("div",{children:x.I18n.t("help_just_check")})]})}),t.jsx(N.DialogActions,{children:t.jsx(N.Button,{onClick:n,color:"primary",autoFocus:!0,startIcon:t.jsx(Se,{}),children:x.I18n.t("OK")})})]}),gt=({onClose:n,open:e})=>t.jsxs(N.Dialog,{open:e,onClose:n,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[t.jsx(N.DialogContent,{children:t.jsxs(N.DialogContentText,{id:"alert-dialog-description",children:[t.jsx("h3",{children:x.I18n.t("On condition change")}),t.jsx("div",{children:x.I18n.t("help_on_change")}),t.jsx("h3",{children:x.I18n.t("Just check")}),t.jsx("div",{children:x.I18n.t("help_just_check")})]})}),t.jsx(N.DialogActions,{children:t.jsx(N.Button,{onClick:n,color:"primary",autoFocus:!0,children:x.I18n.t("OK")})})]}),fe=({size:n,blockValue:e,boolean:s,typeBlock:i,userRules:r,setUserRules:o,animation:c,setTourStep:l,tourStep:d,isTourOpen:I,theme:S,themeType:O,themeName:_})=>{var T;const[a,k]=u.useState(!1),[H,w]=u.useState(!1),[f,b]=u.useState(!1),[p,h]=u.useState("");s===void 0&&(s=!0);const v=he({accept:"box",drop:()=>({blockValue:e}),hover:({acceptedBy:A,_id:L},Y)=>{k(A===i),b(!!L),h(Y.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()}}}),M=v[0],{canDrop:W,isOver:$,offset:q,targetId:B}=M,m=v[1];u.useEffect(()=>{h("")},[q]);const C=W&&$;let j="";C?j=a?"#00fb003d":"#fb00002e":W?j=H?"#00fb003d":"#fb00002e":q&&(j=B===p?"#fb00002e":"");let g;return i==="actions"?g=r.actions[e]:i==="conditions"?g=r.conditions[e]:g=r.triggers,t.jsx("div",{ref:m,style:{backgroundColor:j},className:`${x.Utils.clsx(D.contentBlockItem,n&&D.addClassHeight)} ${s?c?D.contentHeightOn:null:D.contentHeightOff}`,children:t.jsxs("div",{className:D.wrapperMargin,children:[g.map(A=>t.jsx(_e,{typeBlock:i,...A,blockValue:e,allProperties:A,userRules:r,setUserRules:o,children:t.jsx(me,{...A,isTourOpen:I,setTourStep:l,tourStep:d,settings:A,blockValue:e,userRules:r,setUserRules:o,theme:S,themeType:O,themeName:_})},A._id)),t.jsx("div",{style:C&&a&&!f?{height:((T=document.getElementById("height"))==null?void 0:T.clientHeight)||200}:void 0,className:`${D.emptyBlockStyle} ${C&&a&&!f?D.emptyBlock:D.emptyBlockNone}`})]})})},ce=({size:n,typeBlock:e,name:s,nameAdditionally:i,additionally:r,border:o,userRules:c,setUserRules:l,iconName:d,adapter:I,socket:S,setTourStep:O,tourStep:_,isTourOpen:a,theme:k,themeType:H,themeName:w})=>{const[f,b,p]=re(e==="actions"?!1:[],`additionallyClickItems_${e}`),[h,v]=u.useState(!1),[M,W]=u.useState(!1);u.useEffect(()=>{if(e==="conditions"&&(f==null?void 0:f.length)!==c.conditions.length-1){const B=[];c.conditions.forEach((m,C)=>{C>0&&B.push({_id:Date.now(),open:!0})}),b([...f,...B])}e==="actions"&&!p&&c.actions.else.length&&b(!0)},[]);const[$,q]=u.useState(!1);return t.jsxs("div",{className:`${x.Utils.clsx(D.mainBlockItemRules,n&&D.addClassOverflow)} ${o&&!n?D.border:null}`,children:[t.jsxs("span",{id:"width",className:D.nameBlockItems,children:[t.jsx(X,{iconName:d,className:D.iconThemCard,adapter:I,socket:S}),s]}),e==="conditions"?t.jsxs("div",{style:{width:"100%"},children:[t.jsxs(N.Select,{variant:"standard",className:D.selectOnChange,value:c.justCheck||!1,onChange:B=>{const m=K("conditions",c);m.justCheck=B.target.value==="true",l(m)},children:[t.jsx(N.MenuItem,{value:"false",children:x.I18n.t("on condition change")}),t.jsx(N.MenuItem,{value:"true",children:x.I18n.t("just check")})]}),t.jsx(N.IconButton,{size:"small",title:x.I18n.t("Explanation"),className:D.selectOnChangeHelp,onClick:()=>v(!0),children:t.jsx(we,{className:D.selectOnChangeHelpIcon})})]}):null,t.jsx(fe,{setTourStep:O,tourStep:_,isTourOpen:a,blockValue:e==="actions"?"then":e==="conditions"?0:e,typeBlock:e,setUserRules:l,userRules:c,theme:k,themeName:w,themeType:H,size:n}),r&&[...Array(e==="actions"?1:c.conditions.length-1)].map((B,m)=>{const C=(j=m)=>e==="actions"?!!f:!!f.find((g,T)=>T===j&&g.open);return t.jsxs(u.Fragment,{children:[t.jsxs("div",{onClick:()=>{if(e==="actions")return b(!f),null;let j=JSON.parse(JSON.stringify(f));if(c.conditions[m+1].length)return j[m].open=!j[m].open,b(j),null;j=j.filter((g,T)=>T!==m),b(j),q(m),setTimeout(()=>{q(!1),l({...c,conditions:[...c.conditions.filter((g,T)=>T!==m+1)]})},250)},className:D.blockCardAdd,children:[C()?"-":"+",t.jsx("div",{className:D.cardAdd,children:i})]},m),t.jsx(fe,{blockValue:e==="actions"?"else":e==="conditions"?m+1:e,typeBlock:e,setUserRules:l,userRules:c,boolean:C(),animation:$===m,size:n,theme:k,themeName:w,themeType:H})]},`${m}_block_${e}`)}),r&&e==="conditions"&&t.jsxs("div",{onClick:()=>{b([...f,{_id:Date.now(),open:!0}]),l({...c,conditions:[...c.conditions,[]]}),q(c.conditions.length-1),setTimeout(()=>q(!1),1e3)},className:D.blockCardAdd,children:["+",t.jsx("div",{className:D.cardAdd,children:i})]}),t.jsx(ft,{open:h,onClose:()=>v(!1)}),t.jsx(gt,{open:M,onClose:()=>W(!1)})]})},ht="_menuRules_1qqcb_1",ut="_switchesRenderWrapper_1qqcb_13",mt="_menuOff_1qqcb_22",_t="_menuTitle_1qqcb_28",pt="_marginAuto_1qqcb_42",xt="_inputWidth_1qqcb_47",bt="_menuWrapper_1qqcb_52",Ct="_hamburgerWrapper_1qqcb_57",wt="_hamburgerOff_1qqcb_74",vt="_nothingFound_1qqcb_82",jt="_resetSearch_1qqcb_89",It="_controlPanel_1qqcb_101",Ot="_controlPanelAppBar_1qqcb_112",St="_addClassMenu_1qqcb_126",At="_addClassBackground_1qqcb_132",yt="_addClassPosition_1qqcb_136",E={menuRules:ht,switchesRenderWrapper:ut,menuOff:mt,menuTitle:_t,marginAuto:pt,inputWidth:xt,menuWrapper:bt,hamburgerWrapper:Ct,hamburgerOff:wt,nothingFound:vt,resetSearch:jt,controlPanel:It,controlPanelAppBar:Ot,addClassMenu:St,addClassBackground:At,addClassPosition:yt},Dt=n=>{const{allProperties:e,allProperties:{acceptedBy:s,id:i},setUserRules:r,userRules:o,setTourStep:c,tourStep:l,isTourOpen:d,onTouchMove:I,isActive:S}=n;return t.jsx(_e,{allProperties:e,id:e.id,isActive:S,setUserRules:r,userRules:o,children:t.jsx(ue,{onDoubleClick:()=>{d&&l===J.addScheduleByDoubleClick&&i==="TriggerScheduleBlock"&&c(J.openTagsMenu),d&&l===J.addActionPrintText&&i==="ActionPrintText"&&c(J.showJavascript);const O=Date.now();let _;switch(s){case"actions":_="then";break;case"conditions":_=o[s].length-1;break}const a=K(s,o,_),k={id:i,_id:O,acceptedBy:s};_!==void 0?s==="actions"?a.actions[_].push({...k}):s==="conditions"&&a.conditions[_].push({...k}):a.triggers.push({...k}),r(a)},...n,...e,onTouchMove:I})})},kt="_hamburgerMenu_hqnsm_8",Nt="_animate_hqnsm_21",ge={hamburgerMenu:kt,animate:Nt};function $t({bool:n}){return t.jsx("div",{className:`${ge.hamburgerMenu} ${n?ge.animate:""}`})}const Bt=({addClass:n,setAllBlocks:e,allBlocks:s,userRules:i,onChangeBlocks:r,setTourStep:o,tourStep:c,isTourOpen:l})=>{const{blocks:d,socket:I}=u.useContext(te),[S,O]=re(!1,"hamburgerOnOff"),[_,a]=re({text:"",type:"triggers",index:0},"filterControlPanel"),k=(f=_.text,b=_.type)=>{if(!d)return;let p=[...d];p=p.filter(h=>{if(!f)return!0;const{name:v}=h.getStaticData();return v&&x.I18n.t(v).toLowerCase().includes(f.toLowerCase())}),p=p.filter(h=>b===h.getStaticData().acceptedBy),e(p)},H=(f,b)=>{l&&b===0&&c===J.selectTriggers&&o(J.addScheduleByDoubleClick),l&&b===2&&c===J.selectActions&&o(J.addActionPrintText),a({..._,index:b,type:["triggers","conditions","actions"][b]}),k(_.text,["triggers","conditions","actions"][b])},w=f=>({id:`scrollable-force-tab-${f}`,"aria-controls":`scrollable-force-tabpanel-${f}`});return u.useEffect(()=>{k()},[d]),t.jsx(N.ClickAwayListener,{mouseEvent:!1,touchEvent:"onTouchStart",onClickAway:()=>O(!0),children:t.jsxs("div",{className:x.Utils.clsx(E.menuWrapper,n[1035]&&E.addClassMenu),children:[t.jsx("div",{className:`${E.hamburgerWrapper} ${S?E.hamburgerOff:null}`,onClick:()=>O(!S),children:t.jsx($t,{bool:!S})}),t.jsxs("div",{className:`${x.Utils.clsx(E.menuRules,n[1035]&&E.addClassBackground,n[835]&&E.addClassPosition)} ${S?E.menuOff:null}`,children:[t.jsx("div",{className:E.controlPanel,children:t.jsx(N.AppBar,{className:E.controlPanelAppBar,position:"static",children:t.jsxs(N.Tabs,{value:_.index,onChange:H,children:[t.jsx(N.Tab,{className:"blocks-triggers",title:x.I18n.t("Triggers"),icon:t.jsx(X,{iconName:"FlashOn"}),...w(0)}),t.jsx(N.Tab,{title:x.I18n.t("Conditions"),className:"blocks-conditions",icon:t.jsx(X,{iconName:"Help"}),...w(1)}),t.jsx(N.Tab,{title:x.I18n.t("Actions"),className:"blocks-actions",icon:t.jsx(X,{iconName:"PlayForWork"}),...w(2)})]})})}),t.jsx("div",{className:E.switchesRenderWrapper,children:t.jsxs("span",{children:[s.map(f=>{const{name:b,id:p,icon:h,adapter:v}=f.getStaticData();return t.jsx(u.Fragment,{children:t.jsx(Dt,{adapter:v,allProperties:f.getStaticData(),icon:h,id:p,isActive:!1,isTourOpen:l,name:b,onTouchMove:()=>O(!0),setTourStep:o,setUserRules:r,socket:I,tourStep:c,userRules:i})},p)}),!s.length&&t.jsxs("div",{className:E.nothingFound,children:[x.I18n.t("Nothing found"),"...",t.jsx("div",{className:E.resetSearch,onClick:()=>{a({..._,text:""}),k("")},children:x.I18n.t("reset search")})]})]})}),t.jsx("div",{className:x.Utils.clsx(E.menuTitle,E.marginAuto)}),t.jsx(ve,{className:E.inputWidth,fullWidth:!0,customValue:!0,value:_.text,size:"small",autoComplete:"off",label:x.I18n.t("search"),variant:"outlined",onChange:f=>{a({..._,text:f}),k(f)}})]})]})})};let ae=[];const Ut=({code:n,onChange:e,themeName:s,themeType:i,theme:r,setTourStep:o,tourStep:c,isTourOpen:l,command:d,scriptId:I,changed:S,running:O})=>{var j;const{blocks:_,socket:a,setOnUpdate:k,setOnDebugMessage:H,setEnableSimulation:w}=u.useContext(te),[f,b]=u.useState([]),[p,h]=u.useState(le(n)),[v,M]=u.useState(""),[W,$]=u.useState(!1);u.useEffect(()=>{let g,T;const A=(F,y)=>{F===`${g}.alive`&&T!==(y==null?void 0:y.val)&&(T=!!(y!=null&&y.val),T&&g&&(a==null||a.sendTo(g.replace(/^system\.adapter\./,""),"rulesOn",I)))},L=(F,y)=>{var U,Q;a&&g!==((U=y==null?void 0:y.common)==null?void 0:U.engine)&&(g&&(a.unsubscribeState(`${g}.alive`,A),T&&a.sendTo(g.replace(/^system\.adapter\./,""),"rulesOn",I)),g=(Q=y==null?void 0:y.common)==null?void 0:Q.engine,g&&g&&a.subscribeState(`${g}.alive`,A))},Y=(F,y)=>{if(y)try{const U=JSON.parse(y.val),Q=Date.now();if(U.ruleId===I&&Q-U.ts<1e3){const P=[...ae,{blockId:U.blockId,data:U.data,ts:U.ts}];P.length>200&&P.splice(0,200-P.length);for(let Z=P.length-1;Z>=0;Z--)if(P[Z].ts<Q-5e3){P.splice(0,Z);break}console.log(`Debug1: ${JSON.stringify(ae)}`),console.log(`Debug2: ${JSON.stringify(P)}`),ae=P,H(P)}}catch{console.error(`Cannot parse: ${y.val}`)}};return a==null||a.getObject(I).then(F=>{var y;g=(y=F==null?void 0:F.common)==null?void 0:y.engine,a.subscribeObject(I,L),g&&(a.subscribeState(`${g}.alive`,A),a.subscribeState(`${g.replace(/^system\.adapter\./,"")}.debug.rules`,Y))}),function(){a==null||a.unsubscribeState(I,A),g&&(a==null||a.unsubscribeObject(`${g}.alive`,L),T&&(a==null||a.sendTo(g.replace(/^system\.adapter\./,""),"rulesOff",I)),a==null||a.unsubscribeState(`${g.replace(/^system\.adapter\./,"")}.debug.rules`,Y))}},[]),u.useEffect(()=>{w(!S&&O)},[S,O,w]),u.useEffect(()=>{d&&(M(d),W||$(!0))},[d]),u.useEffect(()=>{const g=le(n);JSON.stringify(g)!==JSON.stringify(p)&&(h(g),k(!0))},[n]),u.useEffect(()=>{document.getElementsByTagName("HTML")[0].className=s||"blue"},[s]);const q=u.useCallback(g=>{h(g),_&&e(je(g,_))},[_,e]),B=u.useRef(null),[m,C]=u.useState({835:!1,1035:!1});return u.useEffect(()=>{B.current&&(B.current.clientWidth<=1035&&C({835:!1,1035:!0}),B.current.clientWidth<=835&&C({1035:!0,835:!0}),B.current.clientWidth>1035&&C({835:!1,1035:!1}))},[((j=B.current)==null?void 0:j.clientWidth)||0]),!_||!a?null:t.jsxs("div",{className:ne.wrapperRules,ref:B,children:[t.jsx(Le,{allBlocks:f,socket:a}),W?v==="export"?t.jsx(Ie,{scriptId:I,themeType:i,onClose:()=>$(!1),text:JSON.stringify(p,null,2)}):t.jsx(Oe,{themeType:i,onClose:g=>{$(!1),g&&q(JSON.parse(g))}}):null,t.jsxs("div",{className:x.Utils.clsx(ne.rootWrapper,m[835]&&ne.addClass),children:[t.jsx(Bt,{setAllBlocks:b,allBlocks:f,userRules:p,onChangeBlocks:q,setTourStep:o,tourStep:c,addClass:m,isTourOpen:l}),t.jsx(ce,{socket:a,setUserRules:q,userRules:p,isTourOpen:l,setTourStep:o,tourStep:c,name:`${x.I18n.t("when")}...`,typeBlock:"triggers",iconName:"FlashOn",size:m[835],themeType:i,themeName:s,theme:r}),t.jsx(ce,{socket:a,setUserRules:q,isTourOpen:l,setTourStep:o,tourStep:c,userRules:p,name:`...${x.I18n.t("and")}...`,typeBlock:"conditions",iconName:"Help",nameAdditionally:x.I18n.t("or"),additionally:!0,border:!0,size:m[835],themeType:i,themeName:s,theme:r}),t.jsx(ce,{socket:a,setUserRules:q,isTourOpen:l,setTourStep:o,tourStep:c,userRules:p,name:`...${x.I18n.t("then")}`,typeBlock:"actions",iconName:"PlayForWork",nameAdditionally:x.I18n.t("else"),additionally:!0,size:m[835],themeType:i,themeName:s,theme:r})]})]},"rulesEditor")};export{Ut as default};
1
+ import{j as t}from"./createSvgIcon-DlIk-fDn.js";import{i as u}from"./iobroker_javascript__loadShare__react__loadShare__-i8pXne9X.js";import{u as pe,a as xe,i as x,M as X,C as te,G as be,b as Ce,c as he,I as we,S as J,d as ve,e as le,j as je,D as Ie,f as Oe}from"./index-CePzv5-W.js";import{i as N,C as Se}from"./index-Cjl4b70e.js";import"./_commonjsHelpers-Cpj98o6Y.js";import"./iobroker_javascript__mf_v__runtimeInit__mf_v__-DZdFIfoQ.js";import"./inheritsLoose-DNrhibGS.js";import"./preload-helper-BDBacUwf.js";function Ae(n){const s=pe().getMonitor(),[i,r]=xe(s,n);return u.useEffect(()=>s.subscribeToOffsetChange(r)),u.useEffect(()=>s.subscribeToStateChange(r)),i}let V;function ye(){return V||(V=new Image,V.src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="),V}const De="_wrapperRules_nnott_1",ke="_rootWrapper_nnott_9",Ne="_addClass_nnott_14",ne={wrapperRules:De,rootWrapper:ke,addClass:Ne},$e="_switchesItem_10ls3_1",Be="_switchesItemActive_10ls3_28",Ee="_iconTheme_10ls3_36",se={switchesItem:$e,switchesItemActive:Be,iconTheme:Ee},ue=({name:n,id:e,active:s,icon:i,adapter:r,socket:o,onDoubleClick:c,title:l,onTouchMove:d,style:I})=>t.jsxs("div",{onDoubleClick:c,onTouchMove:d,title:l?x.I18n.t(l):void 0,className:x.Utils.clsx(se.switchesItem,s&&se.switchesItemActive,`block-${e}`),children:[t.jsx(X,{iconName:i,className:se.iconTheme,adapter:r,socket:o,style:I}),t.jsx("span",{children:n?x.I18n.t(n):""})]},e),Me="_cardStyle_8rq8v_1",qe="_cardStyleActive_8rq8v_17",He="_controlMenu_8rq8v_22",Te="_closeBtn_8rq8v_31",We="_isDelete_8rq8v_73",Pe="_drag_mobile_8rq8v_90",G={cardStyle:Me,cardStyleActive:qe,controlMenu:He,closeBtn:Te,isDelete:We,drag_mobile:Pe};function K(n,e,s){let i;switch(n){case"actions":if(s==="else")return i={...e,actions:{...e[n],else:[...e[n].else]}},i;if(s==="then")return i={...e,actions:{...e[n],then:[...e[n].then]}},i;throw console.error(`Unknown additionalParameter: ${s}`),new Error(`Unknown additionalParameter: ${s}`);case"triggers":return i={...e,triggers:[...e.triggers]},i;case"conditions":return i={...e,conditions:[...e.conditions]},i;default:throw new Error(`Unknown name: ${n}`)}}function z(n,e,s,i){var r;switch(n){case"actions":return e.actions[s]=e.actions[s].filter(o=>o._id!==i),e;case"conditions":return e.conditions[s]=(r=e.conditions[s])==null?void 0:r.filter(o=>o._id!==i),e;case"triggers":default:return e.triggers=e.triggers.filter(o=>o._id!==i),e}}function Fe(n,e,s){const{_id:i,acceptedBy:r}=n;let o;if(!r||!e[r])return console.warn(`Cannot find ${r}`),e;switch(r){case"actions":if(o=e.actions[s].find(c=>c._id===i),!o)console.warn(`Cannot find ${i}`);else{const c=e.actions[s].indexOf(o);e.actions[s][c]=n}return e;case"conditions":if(o=e.conditions[s].find(c=>c._id===i),!o)console.warn(`Cannot find ${i}`);else{const c=e.conditions[s].indexOf(o);e.conditions[s][c]=n}return e;default:if(o=e.triggers.find(c=>c._id===i),!o)console.warn(`Cannot find ${i}`);else{const c=e.triggers.indexOf(o);e.triggers[c]=n}return e}}const me=u.memo(n=>{var B;const{setUserRules:e,userRules:s,_id:i,id:r,blockValue:o,active:c,acceptedBy:l,isTourOpen:d,setTourStep:I,tourStep:S}=n,[O,_]=u.useState(null),{blocks:a,socket:k,onUpdate:H,setOnUpdate:w,onDebugMessage:f,enableSimulation:b}=u.useContext(te),p=u.useCallback(m=>a==null?void 0:a.find(C=>C.getStaticData().id===m),[a]),h=u.useCallback(m=>{const C=Fe(m,s,o);C&&e(C)},[s]),v=m=>{m.currentTarget!==O&&_(m.currentTarget)},M=()=>_(null),W=u.useMemo(()=>{const m=p(r)||be;return t.jsx(m,{...n,notFound:!p(r),isTourOpen:d,setTourStep:I,tourStep:S,onUpdate:H,setOnUpdate:w,enableSimulation:b,onDebugMessage:f,onChange:h,className:void 0,socket:k})},[s,H,f,b]),[$,q]=u.useState(!1);return t.jsxs("div",{onMouseMove:v,onMouseEnter:v,onMouseLeave:M,onMouseDown:m=>{if(m.ctrlKey){let C;const j=K(l,s,o);l==="conditions"?(C=j.conditions[o].find(g=>g._id===i),C&&j.conditions[o].splice(j.conditions[o].indexOf(C),0,{...C,_id:Date.now()})):l==="actions"?(C=j.actions[o].find(g=>g._id===i),C&&j.actions[o].splice(j.actions[o].indexOf(C),0,{...C,_id:Date.now()})):(C=j.triggers.find(g=>g._id===i),C&&j.triggers.splice(j[l].indexOf(C),0,{...C,_id:Date.now()})),e(j)}},id:"height",style:c?{width:(((B=document.getElementById("width"))==null?void 0:B.clientWidth)||0)-70}:void 0,className:`${G.cardStyle} ${c?G.cardStyleActive:null} ${$?G.isDelete:null}`,children:[t.jsx("div",{className:G.drag_mobile}),W,e&&t.jsx("div",{className:G.controlMenu,style:O?{opacity:1}:{opacity:0},children:t.jsx("div",{onClick:()=>{let m=K(l,s,o);m=z(l,m,o,i),q(!0),setTimeout(()=>{l==="triggers"&&w(!0),e(m)},300)},className:G.closeBtn})})]})}),Ue={position:"fixed",pointerEvents:"none",zIndex:100,left:0,top:0,width:"100%",height:"100%"},Je=(n,e,s)=>{if(!n||!e)return{display:"none"};let{x:i,y:r}=e;const o=`translate(${i}px, ${r}px)`;return{transform:o,WebkitTransform:o}},Le=n=>{const{itemType:e,isDragging:s,item:i,initialOffset:r,currentOffset:o,targetIds:c}=Ae(d=>({item:d.getItem(),itemType:d.getItemType(),initialOffset:d.getInitialSourceClientOffset(),currentOffset:d.getSourceClientOffset(),isDragging:d.isDragging(),targetIds:d.getTargetIds()})),l=()=>{switch(e){case"box":return c.length?t.jsx(me,{active:!0,...i,allBlocks:n.allBlocks}):t.jsx(ue,{active:!0,...i,socket:n.socket});default:return null}};return s?t.jsx("div",{style:Ue,children:t.jsx("div",{style:Je(r,o),children:l()})}):null},ze="_border_wrpm3_1",Ge="_emptyBlockStyle_wrpm3_6",Ke="_emptyBlock_wrpm3_6",Qe="_selectOnChange_wrpm3_22",Xe="_selectOnChangeHelp_wrpm3_28",Ye="_selectOnChangeHelpIcon_wrpm3_34",Ze="_emptyBlockNone_wrpm3_49",Ve="_mainBlockItemRules_wrpm3_55",Re="_nameBlockItems_wrpm3_63",et="_contentBlockItem_wrpm3_73",tt="_wrapperMargin_wrpm3_81",nt="_contentHeightOn_wrpm3_87",st="_contentHeightOff_wrpm3_99",ot="_cardAdd_wrpm3_105",it="_blockCardAdd_wrpm3_125",ct="_addClassOverflow_wrpm3_136",at="_addClassHeight_wrpm3_140",D={border:ze,emptyBlockStyle:Ge,emptyBlock:Ke,selectOnChange:Qe,selectOnChangeHelp:Xe,selectOnChangeHelpIcon:Ye,emptyBlockNone:Ze,mainBlockItemRules:Ve,nameBlockItems:Re,contentBlockItem:et,wrapperMargin:tt,contentHeightOn:nt,contentHeightOff:st,cardAdd:ot,blockCardAdd:it,addClassOverflow:ct,addClassHeight:at};function re(n,e){const[s,i]=u.useState(window.localStorage.getItem(e)?JSON.parse(window.localStorage.getItem(e)||""):n);return[s,o=>{window.localStorage.setItem(e,JSON.stringify(o)),i(o)},!!window.localStorage.getItem(e)]}function rt(n,e){let s=0,i=null,r;return function(...o){const c=Date.now();r=o,c-s>=e?(s=c,n.apply(this,o)):i||(i=setTimeout(()=>{s=Date.now(),i=null,n.apply(this,r)},e-(c-s)))}}function ee(n){if(Array.isArray(n))return n.map(e=>ee(e));if(typeof n=="function")return n.bind(null);if(n&&typeof n=="object"){const e={};return Object.keys(n).forEach(s=>{e[s]=ee(n[s])}),e}return n}const oe=rt((n,e)=>n(e),0);function R(n,e){const s=e.find(i=>i._id===n);return{card:s,index:s?e.indexOf(s):-1}}function ie(n,e,s,i,r,o,c,l,d){const{card:I,index:S}=R(n,s);if(!(S<e&&l<d)&&!(S>e&&l>d)&&I&&S!==e){const O=ee(s);O.splice(S,1),O.splice(e,0,I);const _=ee(r);switch(o){case"actions":_.actions[c]=O,oe(i,_);return;case"conditions":_.conditions[c]=O,oe(i,_);return;default:_.triggers=O,oe(i,_);return}}}const lt="_drag_7xfhc_1",dt="_root_7xfhc_11",de={drag:lt,root:dt},_e=({typeBlock:n,allProperties:e,id:s,isActive:i,setUserRules:r,userRules:o,children:c,_id:l,blockValue:d})=>{const{setOnUpdate:I}=u.useContext(te),[{opacity:S},O,_]=Ce({type:"box",item:()=>({...e,id:s,isActive:i,_id:l}),end:(w,f)=>{const{acceptedBy:b}=w,p=f.getDropResult();let h;if(!p)return typeof l=="number"&&!f.getTargetIds().length&&(h=K(b,o,d),h=z(b,h,d,l),r(h)),null;if(p.blockValue!==d){const v=typeof l=="number"?l:Date.now();h=K(b,o,p.blockValue);const M={id:w.id,acceptedBy:w.acceptedBy};switch(b){case"actions":return d&&(h=z("actions",h,d,v)),h=z("actions",h,p.blockValue,v),h.actions[p.blockValue].push({...M,_id:v}),r(h);case"conditions":return typeof d=="number"&&(h=z("conditions",h,d,v)),h=z("conditions",h,p.blockValue,v),h.conditions[p.blockValue].push({...M,_id:v}),r(h);default:return I(!0),h=z("triggers",h,p.blockValue,v),h.triggers.push({...M,_id:v}),r(h)}}},collect:w=>({opacity:w.isDragging()?.4:1,isDragging:w.isDragging()})}),a=u.useRef(null),[,k]=he({accept:"box",canDrop:()=>!1,hover({_id:w,acceptedBy:f},b){var W;if(!a.current||n!==f)return;const p=(W=a.current)==null?void 0:W.getBoundingClientRect(),h=(p.bottom-p.top)/2,v=b.getClientOffset(),M=((v==null?void 0:v.y)||0)-p.top;if(l&&w!==l)switch(f){case"actions":if(d==="then"||d==="else"){const{index:$}=R(l,o.actions[d]);$!==w&&ie(w,$,o[f][d],r,o,f,d,M,h)}return;case"conditions":if(typeof d=="number"){const{index:$}=R(l,o[f][d]);$!==w&&ie(w,$,o[f][d],r,o,f,d,M,h)}return;default:{const{index:$}=R(l,o[f]);$!==w&&ie(w,$,o[f],r,o,f,void 0,M,h);return}}}});u.useEffect(()=>{_(ye(),{captureDraggingState:!0})},[]),O(k(a));const H=window.innerWidth<600;return t.jsxs("div",{ref:H&&l?null:a,className:de.root,style:{opacity:S},children:[t.jsx("div",{className:l?de.drag:null,ref:l&&H?a:null}),c]})},ft=({onClose:n,open:e})=>t.jsxs(N.Dialog,{open:e,onClose:n,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[t.jsx(N.DialogContent,{children:t.jsxs("div",{style:{fontSize:"1rem",fontFamily:'"Roboto", "Helvetica", "Arial", sans-serif',fontWeight:400,lineHeight:1.5,letterSpacing:"0.00938em"},children:[t.jsx("h3",{children:x.I18n.t("On condition change")}),t.jsx("div",{children:x.I18n.t("help_on_change")}),t.jsx("h3",{children:x.I18n.t("Just check")}),t.jsx("div",{children:x.I18n.t("help_just_check")})]})}),t.jsx(N.DialogActions,{children:t.jsx(N.Button,{onClick:n,color:"primary",autoFocus:!0,startIcon:t.jsx(Se,{}),children:x.I18n.t("OK")})})]}),gt=({onClose:n,open:e})=>t.jsxs(N.Dialog,{open:e,onClose:n,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[t.jsx(N.DialogContent,{children:t.jsxs(N.DialogContentText,{id:"alert-dialog-description",children:[t.jsx("h3",{children:x.I18n.t("On condition change")}),t.jsx("div",{children:x.I18n.t("help_on_change")}),t.jsx("h3",{children:x.I18n.t("Just check")}),t.jsx("div",{children:x.I18n.t("help_just_check")})]})}),t.jsx(N.DialogActions,{children:t.jsx(N.Button,{onClick:n,color:"primary",autoFocus:!0,children:x.I18n.t("OK")})})]}),fe=({size:n,blockValue:e,boolean:s,typeBlock:i,userRules:r,setUserRules:o,animation:c,setTourStep:l,tourStep:d,isTourOpen:I,theme:S,themeType:O,themeName:_})=>{var T;const[a,k]=u.useState(!1),[H,w]=u.useState(!1),[f,b]=u.useState(!1),[p,h]=u.useState("");s===void 0&&(s=!0);const v=he({accept:"box",drop:()=>({blockValue:e}),hover:({acceptedBy:A,_id:L},Y)=>{k(A===i),b(!!L),h(Y.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()}}}),M=v[0],{canDrop:W,isOver:$,offset:q,targetId:B}=M,m=v[1];u.useEffect(()=>{h("")},[q]);const C=W&&$;let j="";C?j=a?"#00fb003d":"#fb00002e":W?j=H?"#00fb003d":"#fb00002e":q&&(j=B===p?"#fb00002e":"");let g;return i==="actions"?g=r.actions[e]:i==="conditions"?g=r.conditions[e]:g=r.triggers,t.jsx("div",{ref:m,style:{backgroundColor:j},className:`${x.Utils.clsx(D.contentBlockItem,n&&D.addClassHeight)} ${s?c?D.contentHeightOn:null:D.contentHeightOff}`,children:t.jsxs("div",{className:D.wrapperMargin,children:[g.map(A=>t.jsx(_e,{typeBlock:i,...A,blockValue:e,allProperties:A,userRules:r,setUserRules:o,children:t.jsx(me,{...A,isTourOpen:I,setTourStep:l,tourStep:d,settings:A,blockValue:e,userRules:r,setUserRules:o,theme:S,themeType:O,themeName:_})},A._id)),t.jsx("div",{style:C&&a&&!f?{height:((T=document.getElementById("height"))==null?void 0:T.clientHeight)||200}:void 0,className:`${D.emptyBlockStyle} ${C&&a&&!f?D.emptyBlock:D.emptyBlockNone}`})]})})},ce=({size:n,typeBlock:e,name:s,nameAdditionally:i,additionally:r,border:o,userRules:c,setUserRules:l,iconName:d,adapter:I,socket:S,setTourStep:O,tourStep:_,isTourOpen:a,theme:k,themeType:H,themeName:w})=>{const[f,b,p]=re(e==="actions"?!1:[],`additionallyClickItems_${e}`),[h,v]=u.useState(!1),[M,W]=u.useState(!1);u.useEffect(()=>{if(e==="conditions"&&(f==null?void 0:f.length)!==c.conditions.length-1){const B=[];c.conditions.forEach((m,C)=>{C>0&&B.push({_id:Date.now(),open:!0})}),b([...f,...B])}e==="actions"&&!p&&c.actions.else.length&&b(!0)},[]);const[$,q]=u.useState(!1);return t.jsxs("div",{className:`${x.Utils.clsx(D.mainBlockItemRules,n&&D.addClassOverflow)} ${o&&!n?D.border:null}`,children:[t.jsxs("span",{id:"width",className:D.nameBlockItems,children:[t.jsx(X,{iconName:d,className:D.iconThemCard,adapter:I,socket:S}),s]}),e==="conditions"?t.jsxs("div",{style:{width:"100%"},children:[t.jsxs(N.Select,{variant:"standard",className:D.selectOnChange,value:c.justCheck||!1,onChange:B=>{const m=K("conditions",c);m.justCheck=B.target.value==="true",l(m)},children:[t.jsx(N.MenuItem,{value:"false",children:x.I18n.t("on condition change")}),t.jsx(N.MenuItem,{value:"true",children:x.I18n.t("just check")})]}),t.jsx(N.IconButton,{size:"small",title:x.I18n.t("Explanation"),className:D.selectOnChangeHelp,onClick:()=>v(!0),children:t.jsx(we,{className:D.selectOnChangeHelpIcon})})]}):null,t.jsx(fe,{setTourStep:O,tourStep:_,isTourOpen:a,blockValue:e==="actions"?"then":e==="conditions"?0:e,typeBlock:e,setUserRules:l,userRules:c,theme:k,themeName:w,themeType:H,size:n}),r&&[...Array(e==="actions"?1:c.conditions.length-1)].map((B,m)=>{const C=(j=m)=>e==="actions"?!!f:!!f.find((g,T)=>T===j&&g.open);return t.jsxs(u.Fragment,{children:[t.jsxs("div",{onClick:()=>{if(e==="actions")return b(!f),null;let j=JSON.parse(JSON.stringify(f));if(c.conditions[m+1].length)return j[m].open=!j[m].open,b(j),null;j=j.filter((g,T)=>T!==m),b(j),q(m),setTimeout(()=>{q(!1),l({...c,conditions:[...c.conditions.filter((g,T)=>T!==m+1)]})},250)},className:D.blockCardAdd,children:[C()?"-":"+",t.jsx("div",{className:D.cardAdd,children:i})]},m),t.jsx(fe,{blockValue:e==="actions"?"else":e==="conditions"?m+1:e,typeBlock:e,setUserRules:l,userRules:c,boolean:C(),animation:$===m,size:n,theme:k,themeName:w,themeType:H})]},`${m}_block_${e}`)}),r&&e==="conditions"&&t.jsxs("div",{onClick:()=>{b([...f,{_id:Date.now(),open:!0}]),l({...c,conditions:[...c.conditions,[]]}),q(c.conditions.length-1),setTimeout(()=>q(!1),1e3)},className:D.blockCardAdd,children:["+",t.jsx("div",{className:D.cardAdd,children:i})]}),t.jsx(ft,{open:h,onClose:()=>v(!1)}),t.jsx(gt,{open:M,onClose:()=>W(!1)})]})},ht="_menuRules_1qqcb_1",ut="_switchesRenderWrapper_1qqcb_13",mt="_menuOff_1qqcb_22",_t="_menuTitle_1qqcb_28",pt="_marginAuto_1qqcb_42",xt="_inputWidth_1qqcb_47",bt="_menuWrapper_1qqcb_52",Ct="_hamburgerWrapper_1qqcb_57",wt="_hamburgerOff_1qqcb_74",vt="_nothingFound_1qqcb_82",jt="_resetSearch_1qqcb_89",It="_controlPanel_1qqcb_101",Ot="_controlPanelAppBar_1qqcb_112",St="_addClassMenu_1qqcb_126",At="_addClassBackground_1qqcb_132",yt="_addClassPosition_1qqcb_136",E={menuRules:ht,switchesRenderWrapper:ut,menuOff:mt,menuTitle:_t,marginAuto:pt,inputWidth:xt,menuWrapper:bt,hamburgerWrapper:Ct,hamburgerOff:wt,nothingFound:vt,resetSearch:jt,controlPanel:It,controlPanelAppBar:Ot,addClassMenu:St,addClassBackground:At,addClassPosition:yt},Dt=n=>{const{allProperties:e,allProperties:{acceptedBy:s,id:i},setUserRules:r,userRules:o,setTourStep:c,tourStep:l,isTourOpen:d,onTouchMove:I,isActive:S}=n;return t.jsx(_e,{allProperties:e,id:e.id,isActive:S,setUserRules:r,userRules:o,children:t.jsx(ue,{onDoubleClick:()=>{d&&l===J.addScheduleByDoubleClick&&i==="TriggerScheduleBlock"&&c(J.openTagsMenu),d&&l===J.addActionPrintText&&i==="ActionPrintText"&&c(J.showJavascript);const O=Date.now();let _;switch(s){case"actions":_="then";break;case"conditions":_=o[s].length-1;break}const a=K(s,o,_),k={id:i,_id:O,acceptedBy:s};_!==void 0?s==="actions"?a.actions[_].push({...k}):s==="conditions"&&a.conditions[_].push({...k}):a.triggers.push({...k}),r(a)},...n,...e,onTouchMove:I})})},kt="_hamburgerMenu_hqnsm_8",Nt="_animate_hqnsm_21",ge={hamburgerMenu:kt,animate:Nt};function $t({bool:n}){return t.jsx("div",{className:`${ge.hamburgerMenu} ${n?ge.animate:""}`})}const Bt=({addClass:n,setAllBlocks:e,allBlocks:s,userRules:i,onChangeBlocks:r,setTourStep:o,tourStep:c,isTourOpen:l})=>{const{blocks:d,socket:I}=u.useContext(te),[S,O]=re(!1,"hamburgerOnOff"),[_,a]=re({text:"",type:"triggers",index:0},"filterControlPanel"),k=(f=_.text,b=_.type)=>{if(!d)return;let p=[...d];p=p.filter(h=>{if(!f)return!0;const{name:v}=h.getStaticData();return v&&x.I18n.t(v).toLowerCase().includes(f.toLowerCase())}),p=p.filter(h=>b===h.getStaticData().acceptedBy),e(p)},H=(f,b)=>{l&&b===0&&c===J.selectTriggers&&o(J.addScheduleByDoubleClick),l&&b===2&&c===J.selectActions&&o(J.addActionPrintText),a({..._,index:b,type:["triggers","conditions","actions"][b]}),k(_.text,["triggers","conditions","actions"][b])},w=f=>({id:`scrollable-force-tab-${f}`,"aria-controls":`scrollable-force-tabpanel-${f}`});return u.useEffect(()=>{k()},[d]),t.jsx(N.ClickAwayListener,{mouseEvent:!1,touchEvent:"onTouchStart",onClickAway:()=>O(!0),children:t.jsxs("div",{className:x.Utils.clsx(E.menuWrapper,n[1035]&&E.addClassMenu),children:[t.jsx("div",{className:`${E.hamburgerWrapper} ${S?E.hamburgerOff:null}`,onClick:()=>O(!S),children:t.jsx($t,{bool:!S})}),t.jsxs("div",{className:`${x.Utils.clsx(E.menuRules,n[1035]&&E.addClassBackground,n[835]&&E.addClassPosition)} ${S?E.menuOff:null}`,children:[t.jsx("div",{className:E.controlPanel,children:t.jsx(N.AppBar,{className:E.controlPanelAppBar,position:"static",children:t.jsxs(N.Tabs,{value:_.index,onChange:H,children:[t.jsx(N.Tab,{className:"blocks-triggers",title:x.I18n.t("Triggers"),icon:t.jsx(X,{iconName:"FlashOn"}),...w(0)}),t.jsx(N.Tab,{title:x.I18n.t("Conditions"),className:"blocks-conditions",icon:t.jsx(X,{iconName:"Help"}),...w(1)}),t.jsx(N.Tab,{title:x.I18n.t("Actions"),className:"blocks-actions",icon:t.jsx(X,{iconName:"PlayForWork"}),...w(2)})]})})}),t.jsx("div",{className:E.switchesRenderWrapper,children:t.jsxs("span",{children:[s.map(f=>{const{name:b,id:p,icon:h,adapter:v}=f.getStaticData();return t.jsx(u.Fragment,{children:t.jsx(Dt,{adapter:v,allProperties:f.getStaticData(),icon:h,id:p,isActive:!1,isTourOpen:l,name:b,onTouchMove:()=>O(!0),setTourStep:o,setUserRules:r,socket:I,tourStep:c,userRules:i})},p)}),!s.length&&t.jsxs("div",{className:E.nothingFound,children:[x.I18n.t("Nothing found"),"...",t.jsx("div",{className:E.resetSearch,onClick:()=>{a({..._,text:""}),k("")},children:x.I18n.t("reset search")})]})]})}),t.jsx("div",{className:x.Utils.clsx(E.menuTitle,E.marginAuto)}),t.jsx(ve,{className:E.inputWidth,fullWidth:!0,customValue:!0,value:_.text,size:"small",autoComplete:"off",label:x.I18n.t("search"),variant:"outlined",onChange:f=>{a({..._,text:f}),k(f)}})]})]})})};let ae=[];const Ut=({code:n,onChange:e,themeName:s,themeType:i,theme:r,setTourStep:o,tourStep:c,isTourOpen:l,command:d,scriptId:I,changed:S,running:O})=>{var j;const{blocks:_,socket:a,setOnUpdate:k,setOnDebugMessage:H,setEnableSimulation:w}=u.useContext(te),[f,b]=u.useState([]),[p,h]=u.useState(le(n)),[v,M]=u.useState(""),[W,$]=u.useState(!1);u.useEffect(()=>{let g,T;const A=(F,y)=>{F===`${g}.alive`&&T!==(y==null?void 0:y.val)&&(T=!!(y!=null&&y.val),T&&g&&(a==null||a.sendTo(g.replace(/^system\.adapter\./,""),"rulesOn",I)))},L=(F,y)=>{var U,Q;a&&g!==((U=y==null?void 0:y.common)==null?void 0:U.engine)&&(g&&(a.unsubscribeState(`${g}.alive`,A),T&&a.sendTo(g.replace(/^system\.adapter\./,""),"rulesOn",I)),g=(Q=y==null?void 0:y.common)==null?void 0:Q.engine,g&&g&&a.subscribeState(`${g}.alive`,A))},Y=(F,y)=>{if(y)try{const U=JSON.parse(y.val),Q=Date.now();if(U.ruleId===I&&Q-U.ts<1e3){const P=[...ae,{blockId:U.blockId,data:U.data,ts:U.ts}];P.length>200&&P.splice(0,200-P.length);for(let Z=P.length-1;Z>=0;Z--)if(P[Z].ts<Q-5e3){P.splice(0,Z);break}console.log(`Debug1: ${JSON.stringify(ae)}`),console.log(`Debug2: ${JSON.stringify(P)}`),ae=P,H(P)}}catch{console.error(`Cannot parse: ${y.val}`)}};return a==null||a.getObject(I).then(F=>{var y;g=(y=F==null?void 0:F.common)==null?void 0:y.engine,a.subscribeObject(I,L),g&&(a.subscribeState(`${g}.alive`,A),a.subscribeState(`${g.replace(/^system\.adapter\./,"")}.debug.rules`,Y))}),function(){a==null||a.unsubscribeState(I,A),g&&(a==null||a.unsubscribeObject(`${g}.alive`,L),T&&(a==null||a.sendTo(g.replace(/^system\.adapter\./,""),"rulesOff",I)),a==null||a.unsubscribeState(`${g.replace(/^system\.adapter\./,"")}.debug.rules`,Y))}},[]),u.useEffect(()=>{w(!S&&O)},[S,O,w]),u.useEffect(()=>{d&&(M(d),W||$(!0))},[d]),u.useEffect(()=>{const g=le(n);JSON.stringify(g)!==JSON.stringify(p)&&(h(g),k(!0))},[n]),u.useEffect(()=>{document.getElementsByTagName("HTML")[0].className=s||"blue"},[s]);const q=u.useCallback(g=>{h(g),_&&e(je(g,_))},[_,e]),B=u.useRef(null),[m,C]=u.useState({835:!1,1035:!1});return u.useEffect(()=>{B.current&&(B.current.clientWidth<=1035&&C({835:!1,1035:!0}),B.current.clientWidth<=835&&C({1035:!0,835:!0}),B.current.clientWidth>1035&&C({835:!1,1035:!1}))},[((j=B.current)==null?void 0:j.clientWidth)||0]),!_||!a?null:t.jsxs("div",{className:ne.wrapperRules,ref:B,children:[t.jsx(Le,{allBlocks:f,socket:a}),W?v==="export"?t.jsx(Ie,{scriptId:I,themeType:i,onClose:()=>$(!1),text:JSON.stringify(p,null,2)}):t.jsx(Oe,{themeType:i,onClose:g=>{$(!1),g&&q(JSON.parse(g))}}):null,t.jsxs("div",{className:x.Utils.clsx(ne.rootWrapper,m[835]&&ne.addClass),children:[t.jsx(Bt,{setAllBlocks:b,allBlocks:f,userRules:p,onChangeBlocks:q,setTourStep:o,tourStep:c,addClass:m,isTourOpen:l}),t.jsx(ce,{socket:a,setUserRules:q,userRules:p,isTourOpen:l,setTourStep:o,tourStep:c,name:`${x.I18n.t("when")}...`,typeBlock:"triggers",iconName:"FlashOn",size:m[835],themeType:i,themeName:s,theme:r}),t.jsx(ce,{socket:a,setUserRules:q,isTourOpen:l,setTourStep:o,tourStep:c,userRules:p,name:`...${x.I18n.t("and")}...`,typeBlock:"conditions",iconName:"Help",nameAdditionally:x.I18n.t("or"),additionally:!0,border:!0,size:m[835],themeType:i,themeName:s,theme:r}),t.jsx(ce,{socket:a,setUserRules:q,isTourOpen:l,setTourStep:o,tourStep:c,userRules:p,name:`...${x.I18n.t("then")}`,typeBlock:"actions",iconName:"PlayForWork",nameAdditionally:x.I18n.t("else"),additionally:!0,size:m[835],themeType:i,themeName:s,theme:r})]})]},"rulesEditor")};export{Ut as default};