iobroker.javascript 10.2.2 → 10.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +2 -1
  2. package/admin/assets/{AiChatPanel-C5vTuhiL.js → AiChatPanel-AZko1BsN.js} +2 -2
  3. package/admin/assets/Debugger-CVDh3kgz.js +15 -0
  4. package/admin/assets/RulesEditor-D3kTbD_T.css +1 -0
  5. package/admin/assets/RulesEditor-DsO4cKIk.js +1 -0
  6. package/admin/assets/{ScriptEditor-COwzdxKl.js → ScriptEditor-BCGahS47.js} +1 -1
  7. package/admin/assets/{ScriptEditorVanillaMonaco-C0biTTli.js → ScriptEditorVanillaMonaco-BDAw2Bw6.js} +2 -2
  8. package/admin/assets/aiPromptBuilder-aJfHa-eU.js +1 -0
  9. package/admin/assets/{blocks_action-CycTOoDY.js → blocks_action-DS28sNfo.js} +1 -1
  10. package/admin/assets/{blocks_convert-BUmTT450.js → blocks_convert-CLb0DLyc.js} +1 -1
  11. package/admin/assets/{blocks_logic-BP_rkFPu.js → blocks_logic-Dpp2fwlu.js} +1 -1
  12. package/admin/assets/{blocks_number-DZPdNWcv.js → blocks_number-N4IfHvYD.js} +1 -1
  13. package/admin/assets/{blocks_object-CUKKvXdl.js → blocks_object-uK7FHVhS.js} +1 -1
  14. package/admin/assets/{blocks_procedures-D3LiaeLD.js → blocks_procedures-C_KD0Bm6.js} +1 -1
  15. package/admin/assets/{blocks_sendto-BWmeOFOr.js → blocks_sendto-BxCMg9X4.js} +1 -1
  16. package/admin/assets/{blocks_switch-B17LJ99U.js → blocks_switch-C8Rls5pK.js} +1 -1
  17. package/admin/assets/{blocks_system-DdvuotD5.js → blocks_system-CEQnj5fY.js} +1 -1
  18. package/admin/assets/{blocks_text-D35PPiiy.js → blocks_text-BDEWxu0P.js} +1 -1
  19. package/admin/assets/{blocks_time-CuI_GrE0.js → blocks_time-aHQQK1Uz.js} +1 -1
  20. package/admin/assets/{blocks_timeout-tbB0KBqO.js → blocks_timeout-C2L93TLJ.js} +1 -1
  21. package/admin/assets/{blocks_trigger-Bw3qbQRd.js → blocks_trigger-XivsIDE5.js} +1 -1
  22. package/admin/assets/{helpers-D5PdK4BS.js → helpers-DiwtLpXM.js} +1 -1
  23. package/admin/assets/{index-PLY-IJik.js → index-B0FfAYMN.js} +7 -7
  24. package/admin/assets/{mf-entry-bootstrap-0-f35ca6a1.js → mf-entry-bootstrap-0-019228a5.js} +1 -1
  25. package/admin/mf-stats.json +1 -1
  26. package/admin/tab.html +2 -2
  27. package/build/lib/inspect.js +547 -632
  28. package/build/lib/inspect.js.map +1 -1
  29. package/build/main.js +8 -13
  30. package/build/main.js.map +1 -1
  31. package/io-package.json +27 -27
  32. package/package.json +1 -1
  33. package/admin/assets/Debugger-DnrhfguX.js +0 -15
  34. package/admin/assets/RulesEditor-BwQ6Bo1V.css +0 -1
  35. package/admin/assets/RulesEditor-u3ppR2Xl.js +0 -1
  36. package/admin/assets/aiPromptBuilder-4yeoONDF.js +0 -1
  37. package/build/lib/debugger.js +0 -1135
  38. package/build/lib/debugger.js.map +0 -1
@@ -0,0 +1 @@
1
+ import{$n as e,Bn as t,En as n,Et as r,Fn as i,Ft as a,Ot as o,Qn as s,Qt as c,St as l,Tt as u,Ut as d,Zn as f,_ as p,_r as m,br as h,bt as g,dr as _,dt as v,en as y,fr as b,hr as x,in as S,kn as C,mn as w,mr as T,nn as E,p as D,pr as O,rn as k,tn as A,wn as j,wr as M,wt as N,yr as P}from"./_virtual_mf___mfe_internal__iobroker_javascript__mf_owner__113183188387379__loadShare___mf_0_iobroker_mf_1_gui_mf_2_components__loadShare__.js-D-gi6Mty.js";import{n as F,t as I}from"./Import-XKVP-nRT.js";import{C as L,_ as R,a as z,b as B,i as V,n as ee,o as H,r as te,t as U,v as W,x as G,y as ne}from"./index-B0FfAYMN.js";var re=t(s(`path`,{d:`M7.5 5.6 10 7 8.6 4.5 10 2 7.5 3.4 5 2l1.4 2.5L5 7zm12 9.8L17 14l1.4 2.5L17 19l2.5-1.4L22 19l-1.4-2.5L22 14zM22 2l-2.5 1.4L17 2l1.4 2.5L17 7l2.5-1.4L22 7l-1.4-2.5zm-7.63 5.29a.996.996 0 0 0-1.41 0L1.29 18.96c-.39.39-.39 1.02 0 1.41l2.34 2.34c.39.39 1.02.39 1.41 0L16.7 11.05c.39-.39.39-1.02 0-1.41zm-1.03 5.49-2.12-2.12 2.44-2.44 2.12 2.12z`}),`AutoFixHigh`),ie=t(s(`path`,{d:`M15.41 7.41 14 6l-6 6 6 6 1.41-1.41L10.83 12z`}),`ChevronLeft`),ae=t(s(`path`,{d:`M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z`}),`ChevronRight`),oe=t(s(`path`,{d:`M16 9v10H8V9zm-1.5-6h-5l-1 1H5v2h14V4h-3.5zM18 7H6v12c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2z`}),`DeleteOutlined`),se=t(s(`path`,{d:`M16.59 8.59 12 13.17 7.41 8.59 6 10l6 6 6-6z`}),`ExpandMore`),ce=t(s(`path`,{d:`M15.41 7.41 14 6l-6 6 6 6 1.41-1.41L10.83 12z`}),`NavigateBefore`);M();function le(e){let t=B().getMonitor(),[n,r]=G(t,e);return x(()=>t.subscribeToOffsetChange(r)),x(()=>t.subscribeToStateChange(r)),n}var ue;function de(){return ue||(ue=new Image,ue.src=`data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==`),ue}var K={wrapperRules:`_wrapperRules_147jt_8`,rootWrapper:`_rootWrapper_147jt_14`,bands:`_bands_147jt_26`,emptyRule:`_emptyRule_147jt_39`,emptyRuleText:`_emptyRuleText_147jt_51`},fe={switchesItem:`_switchesItem_b8h5i_6`,switchesItemActive:`_switchesItemActive_b8h5i_35`,iconTheme:`_iconTheme_b8h5i_43`};M();var pe=({name:t,id:n,active:r,icon:i,adapter:a,socket:o,onDoubleClick:c,title:l,onTouchMove:u,style:d})=>e(`div`,{onDoubleClick:c,onTouchMove:u,title:D.t(l||t),className:p.clsx(fe.switchesItem,r&&fe.switchesItemActive,`block-${n}`),children:[s(z,{iconName:i,className:fe.iconTheme,adapter:a,socket:o,style:d}),s(`span`,{children:t?D.t(t):``})]},n),q={cardStyle:`_cardStyle_15e7l_1`,railTriggers:`_railTriggers_15e7l_25`,railConditions:`_railConditions_15e7l_29`,railActions:`_railActions_15e7l_33`,cardStyleActive:`_cardStyleActive_15e7l_37`,controlMenu:`_controlMenu_15e7l_46`,closeBtn:`_closeBtn_15e7l_64`,isDelete:`_isDelete_15e7l_106`,drag_mobile:`_drag_mobile_15e7l_125`};function J(e,t,n){let r;switch(e){case`actions`:if(n===`else`)return r={...t,actions:{...t[e],else:[...t[e].else]}},r;if(n===`then`)return r={...t,actions:{...t[e],then:[...t[e].then]}},r;throw console.error(`Unknown additionalParameter: ${n}`),Error(`Unknown additionalParameter: ${n}`);case`triggers`:return r={...t,triggers:[...t.triggers]},r;case`conditions`:return r={...t,conditions:[...t.conditions]},r;default:throw Error(`Unknown name: ${e}`)}}function Y(e,t,n,r){switch(e){case`actions`:return t.actions[n]=t.actions[n].filter(e=>e._id!==r),t;case`conditions`:var i;return t.conditions[n]=(i=t.conditions[n])==null?void 0:i.filter(e=>e._id!==r),t;default:return t.triggers=t.triggers.filter(e=>e._id!==r),t}}function me(e,t,n){let{_id:r,acceptedBy:i}=e,a;if(!i||!t[i])return console.warn(`Cannot find ${i}`),t;switch(i){case`actions`:if(a=t.actions[n].find(e=>e._id===r),!a)console.warn(`Cannot find ${r}`);else{let r=t.actions[n].indexOf(a);t.actions[n][r]=e}return t;case`conditions`:if(a=t.conditions[n].find(e=>e._id===r),!a)console.warn(`Cannot find ${r}`);else{let r=t.conditions[n].indexOf(a);t.conditions[n][r]=e}return t;default:if(a=t.triggers.find(e=>e._id===r),!a)console.warn(`Cannot find ${r}`);else{let n=t.triggers.indexOf(a);t.triggers[n]=e}return t}}M();var he={triggers:q.railTriggers,conditions:q.railConditions,actions:q.railActions},ge=_(t=>{var n;let{setUserRules:r,userRules:i,_id:a,id:o,blockValue:c,active:l,acceptedBy:u,isTourOpen:d,setTourStep:f,tourStep:p}=t,{blocks:g,socket:_,onUpdate:v,setOnUpdate:y,onDebugMessage:x,enableSimulation:S}=O(U),C=b(e=>g==null?void 0:g.find(t=>t.getStaticData().id===e),[g]),w=b(e=>{let t=me(e,i,c);t&&r(t)},[i]),T=m(()=>{let e=C(o)||V;return s(e,{...t,notFound:!C(o),isTourOpen:d,setTourStep:f,tourStep:p,onUpdate:v,setOnUpdate:y,enableSimulation:S,onDebugMessage:x,onChange:w,className:void 0,socket:_})},[i,v,x,S]),[E,D]=h(!1);return e(`div`,{onMouseDown:e=>{if(e.ctrlKey){let e,t=J(u,i,c);u===`conditions`?(e=t.conditions[c].find(e=>e._id===a),e&&t.conditions[c].splice(t.conditions[c].indexOf(e),0,{...e,_id:Date.now()})):u===`actions`?(e=t.actions[c].find(e=>e._id===a),e&&t.actions[c].splice(t.actions[c].indexOf(e),0,{...e,_id:Date.now()})):(e=t.triggers.find(e=>e._id===a),e&&t.triggers.splice(t[u].indexOf(e),0,{...e,_id:Date.now()})),r(t)}},id:`height`,style:l?{width:(((n=document.getElementById(`width`))==null?void 0:n.clientWidth)||0)-70}:void 0,className:[q.cardStyle,he[u],l&&q.cardStyleActive,E&&q.isDelete].filter(Boolean).join(` `),children:[s(`div`,{className:q.drag_mobile}),T,r&&s(`div`,{className:q.controlMenu,children:s(`div`,{onClick:()=>{let e=J(u,i,c);e=Y(u,e,c,a),D(!0),setTimeout(()=>{u===`triggers`&&y(!0),r(e)},300)},className:q.closeBtn})})]})});M();var _e={position:`fixed`,pointerEvents:`none`,zIndex:100,left:0,top:0,width:`100%`,height:`100%`},ve=(e,t)=>[Math.round(e/32)*32,Math.round(t/32)*32],ye=(e,t,n)=>{if(!e||!t)return{display:`none`};let{x:r,y:i}=t;n&&(r-=e.x,i-=e.y,[r,i]=ve(r,i),r+=e.x,i+=e.y);let a=`translate(${r}px, ${i}px)`;return{transform:a,WebkitTransform:a}},be=e=>{let{itemType:t,isDragging:n,item:r,initialOffset:i,currentOffset:a,targetIds:o}=le(e=>({item:e.getItem(),itemType:e.getItemType(),initialOffset:e.getInitialSourceClientOffset(),currentOffset:e.getSourceClientOffset(),isDragging:e.isDragging(),targetIds:e.getTargetIds()}));return n?s(`div`,{style:_e,children:s(`div`,{style:ye(i,a),children:(()=>{switch(t){case`box`:return o.length?s(ge,{active:!0,...r,allBlocks:e.allBlocks}):s(pe,{active:!0,...r,socket:e.socket});default:return null}})()})}):null},X={emptyBlockStyle:`_emptyBlockStyle_1p9c1_1`,emptyBlock:`_emptyBlock_1p9c1_1`,marginTop:`_marginTop_1p9c1_1`,selectOnChange:`_selectOnChange_1p9c1_17`,selectOnChangeHelp:`_selectOnChangeHelp_1p9c1_23`,selectOnChangeHelpIcon:`_selectOnChangeHelpIcon_1p9c1_29`,emptyBlockNone:`_emptyBlockNone_1p9c1_44`,bandTriggers:`_bandTriggers_1p9c1_57`,bandConditions:`_bandConditions_1p9c1_61`,bandActions:`_bandActions_1p9c1_65`,mainBlockItemRules:`_mainBlockItemRules_1p9c1_69`,nameBlockItems:`_nameBlockItems_1p9c1_93`,nameBlockItemsFoldable:`_nameBlockItemsFoldable_1p9c1_120`,foldIcon:`_foldIcon_1p9c1_124`,foldHint:`_foldHint_1p9c1_124`,contentBlockItem:`_contentBlockItem_1p9c1_145`,wrapperMargin:`_wrapperMargin_1p9c1_153`,contentHeightOn:`_contentHeightOn_1p9c1_160`,heightBlock:`_heightBlock_1p9c1_1`,contentHeightOff:`_contentHeightOff_1p9c1_179`,cardAdd:`_cardAdd_1p9c1_186`,blockCardAdd:`_blockCardAdd_1p9c1_206`};M();function xe(e,t){let[n,r]=h(window.localStorage.getItem(t)?JSON.parse(window.localStorage.getItem(t)||``):e);return[n,e=>{window.localStorage.setItem(t,JSON.stringify(e)),r(e)},!!window.localStorage.getItem(t)]}function Se(e,t){let n=0,r=null,i;return function(...a){let o=Date.now();i=a,o-n>=t?(n=o,e.apply(this,a)):r||=setTimeout(()=>{n=Date.now(),r=null,e.apply(this,i)},t-(o-n))}}function Ce(e){if(Array.isArray(e))return e.map(e=>Ce(e));if(typeof e==`function`)return e.bind(null);if(e&&typeof e==`object`){let t={};return Object.keys(e).forEach(n=>{t[n]=Ce(e[n])}),t}return e}var we=Se((e,t)=>e(t),0);function Te(e,t){let n=t.find(t=>t._id===e);return{card:n,index:n?t.indexOf(n):-1}}function Ee(e,t,n,r,i,a,o,s,c){let{card:l,index:u}=Te(e,n);if(!(u<t&&s<c)&&!(u>t&&s>c)&&l&&u!==t){let e=Ce(n);e.splice(u,1),e.splice(t,0,l);let s=Ce(i);switch(a){case`actions`:s.actions[o]=e,we(r,s);return;case`conditions`:s.conditions[o]=e,we(r,s);return;default:s.triggers=e,we(r,s);return}}}var De={drag:`_drag_7xfhc_1`,root:`_root_7xfhc_11`};M();var Oe=({typeBlock:t,allProperties:n,id:r,isActive:i,setUserRules:a,userRules:o,children:c,_id:l,blockValue:u})=>{let{setOnUpdate:d}=O(U),[{opacity:f},p,m]=ne({type:`box`,item:()=>({...n,id:r,isActive:i,_id:l}),end:(e,t)=>{let{acceptedBy:n}=e,r=t.getDropResult(),i;if(!r)return typeof l==`number`&&!t.getTargetIds().length&&(i=J(n,o,u),i=Y(n,i,u,l),a(i)),null;if(r.blockValue!==u){let t=typeof l==`number`?l:Date.now();i=J(n,o,r.blockValue);let s={id:e.id,acceptedBy:e.acceptedBy};switch(n){case`actions`:return u&&(i=Y(`actions`,i,u,t)),i=Y(`actions`,i,r.blockValue,t),i.actions[r.blockValue].push({...s,_id:t}),a(i);case`conditions`:return typeof u==`number`&&(i=Y(`conditions`,i,u,t)),i=Y(`conditions`,i,r.blockValue,t),i.conditions[r.blockValue].push({...s,_id:t}),a(i);default:return d(!0),i=Y(`triggers`,i,r.blockValue,t),i.triggers.push({...s,_id:t}),a(i)}}},collect:e=>({opacity:e.isDragging()?.4:1,isDragging:e.isDragging()})}),h=P(null),[,g]=W({accept:`box`,canDrop:()=>!1,hover({_id:e,acceptedBy:n},r){var i;if(!h.current||t!==n)return;let s=(i=h.current)==null?void 0:i.getBoundingClientRect(),c=(s.bottom-s.top)/2,d=r.getClientOffset(),f=((d==null?void 0:d.y)||0)-s.top;if(l&&e!==l)switch(n){case`actions`:if(u===`then`||u===`else`){let{index:t}=Te(l,o.actions[u]);t!==e&&Ee(e,t,o[n][u],a,o,n,u,f,c)}return;case`conditions`:if(typeof u==`number`){let{index:t}=Te(l,o[n][u]);t!==e&&Ee(e,t,o[n][u],a,o,n,u,f,c)}return;default:{let{index:t}=Te(l,o[n]);t!==e&&Ee(e,t,o[n],a,o,n,void 0,f,c);return}}}});x(()=>{m(de(),{captureDraggingState:!0})},[]),p(g(h));let _=window.innerWidth<600;return e(`div`,{ref:_&&l?null:h,className:De.root,style:{opacity:f},children:[s(`div`,{className:l?De.drag:null,ref:l&&_?h:null}),c]})};M();var ke=({onClose:t,open:n})=>e(y,{open:n,onClose:t,"aria-labelledby":`alert-dialog-title`,"aria-describedby":`alert-dialog-description`,children:[s(E,{children:e(`div`,{style:{fontSize:`1rem`,fontFamily:`"Roboto", "Helvetica", "Arial", sans-serif`,fontWeight:400,lineHeight:1.5,letterSpacing:`0.00938em`},children:[s(`h3`,{children:D.t(`On condition change`)}),s(`div`,{children:D.t(`help_on_change`)}),s(`h3`,{children:D.t(`Just check`)}),s(`div`,{children:D.t(`help_just_check`)})]})}),s(A,{children:s(d,{onClick:t,color:`primary`,autoFocus:!0,startIcon:s(l,{}),children:D.t(`OK`)})})]});M();var Ae=({onClose:t,open:n})=>e(y,{open:n,onClose:t,"aria-labelledby":`alert-dialog-title`,"aria-describedby":`alert-dialog-description`,children:[s(E,{children:e(k,{id:`alert-dialog-description`,children:[s(`h3`,{children:D.t(`On condition change`)}),s(`div`,{children:D.t(`help_on_change`)}),s(`h3`,{children:D.t(`Just check`)}),s(`div`,{children:D.t(`help_just_check`)})]})}),s(A,{children:s(d,{onClick:t,color:`primary`,autoFocus:!0,children:D.t(`OK`)})})]});M();var je={triggers:X.bandTriggers,conditions:X.bandConditions,actions:X.bandActions},Me=({blockValue:t,boolean:n,typeBlock:r,userRules:i,setUserRules:a,animation:o,setTourStep:c,tourStep:l,isTourOpen:u,theme:d,themeType:f,themeName:m})=>{var g;let[_,v]=h(!1),[y,b]=h(!1),[S,C]=h(!1),[w,T]=h(``);n===void 0&&(n=!0);let E=W({accept:`box`,drop:()=>({blockValue:t}),hover:({acceptedBy:e,_id:t},n)=>{v(e===r),C(!!t),T(n.getHandlerId()||``)},canDrop:({acceptedBy:e})=>(b(e===r),e===r),collect:e=>{var t;return{isOver:e.isOver(),canDrop:((t=e.getItem())==null?void 0:t.acceptedBy)===r,offset:e.getClientOffset(),targetId:e.getHandlerId()}}}),{canDrop:D,isOver:O,offset:k,targetId:A}=E[0],j=E[1];x(()=>{T(``)},[k]);let M=D&&O,N=``;M?N=_?`#00fb003d`:`#fb00002e`:D?N=y?`#00fb003d`:`#fb00002e`:k&&(N=A===w?`#fb00002e`:``);let P;return P=r===`actions`?i.actions[t]:r===`conditions`?i.conditions[t]:i.triggers,s(`div`,{ref:e=>{j(e)},style:{backgroundColor:N},className:p.clsx(X.contentBlockItem,n?o&&X.contentHeightOn:X.contentHeightOff),children:e(`div`,{className:X.wrapperMargin,children:[P.map(e=>s(Oe,{typeBlock:r,...e,blockValue:t,allProperties:e,userRules:i,setUserRules:a,children:s(ge,{...e,isTourOpen:u,setTourStep:c,tourStep:l,settings:e,blockValue:t,userRules:i,setUserRules:a,theme:d,themeType:f,themeName:m})},e._id)),s(`div`,{style:M&&_&&!S?{height:((g=document.getElementById(`height`))==null?void 0:g.clientHeight)||200}:void 0,className:`${X.emptyBlockStyle} ${M&&_&&!S?X.emptyBlock:X.emptyBlockNone}`})]})})},Ne=({typeBlock:t,name:r,nameAdditionally:i,additionally:a,userRules:o,setUserRules:c,iconName:l,adapter:u,socket:d,setTourStep:m,tourStep:g,isTourOpen:_,theme:v,themeType:y,themeName:b})=>{let[S,E,O]=xe(t!==`actions`&&[],`additionallyClickItems_${t}`),[k,A]=h(!1),[j,M]=h(!1),N=t===`conditions`&&!o.conditions.some(e=>e.length),[P,F]=xe(!0,`foldEmptyConditions`),I=N&&P,[,R]=W({accept:`box`,hover:({acceptedBy:e})=>{e===`conditions`&&I&&F(!1)}});x(()=>{if(t===`conditions`&&(S==null?void 0:S.length)!==o.conditions.length-1){let e=[];o.conditions.forEach((t,n)=>{n>0&&e.push({_id:Date.now(),open:!0})}),E([...S,...e])}t===`actions`&&!O&&o.actions.else.length&&E(!0)},[]);let[B,V]=h(!1),ee=o.conditions.some(e=>e.length)||!!o.actions.else.length;return e(`div`,{className:`${X.mainBlockItemRules} ${je[t]}`,children:[e(`span`,{id:`width`,ref:e=>{R(N?e:null)},className:p.clsx(X.nameBlockItems,N&&X.nameBlockItemsFoldable),onClick:N?()=>F(!P):void 0,title:N?D.t(I?`Show conditions`:`Hide empty conditions`):void 0,children:[s(z,{iconName:l,className:X.iconThemCard,adapter:u,socket:d}),r,N?e(f,{children:[s(I?ae:se,{className:X.foldIcon}),I?s(`span`,{className:X.foldHint,children:D.t(`without condition`)}):null]}):null]}),t===`conditions`&&!I?e(`div`,{style:{width:`100%`},children:[e(C,{variant:`standard`,className:X.selectOnChange,value:o.justCheck||!1,onChange:e=>{let t=J(`conditions`,o);t.justCheck=e.target.value===`true`,c(t)},children:[s(n,{value:`false`,children:D.t(`on condition change`)}),s(n,{value:`true`,children:D.t(`just check`)})]}),s(w,{size:`small`,title:D.t(`Explanation`),className:X.selectOnChangeHelp,onClick:()=>A(!0),children:s(L,{className:X.selectOnChangeHelpIcon})})]}):null,I?null:s(Me,{setTourStep:m,tourStep:g,isTourOpen:_,blockValue:t===`actions`?`then`:t===`conditions`?0:t,typeBlock:t,setUserRules:c,userRules:o,theme:v,themeName:b,themeType:y}),!I&&a&&[...Array(t===`actions`?+!!ee:o.conditions.length-1)].map((n,r)=>{let a=(e=r)=>t===`actions`?!!S:!!S.find((t,n)=>n===e&&t.open);return e(T,{children:[e(`div`,{onClick:()=>{if(t===`actions`)return E(!S),null;let e=JSON.parse(JSON.stringify(S));if(o.conditions[r+1].length)return e[r].open=!e[r].open,E(e),null;e=e.filter((e,t)=>t!==r),E(e),V(r),setTimeout(()=>{V(!1),c({...o,conditions:[...o.conditions.filter((e,t)=>t!==r+1)]})},250)},className:X.blockCardAdd,children:[a()?`-`:`+`,s(`div`,{className:X.cardAdd,children:i})]},r),s(Me,{blockValue:t===`actions`?`else`:t===`conditions`?r+1:t,typeBlock:t,setUserRules:c,userRules:o,boolean:a(),animation:B===r,theme:v,themeName:b,themeType:y})]},`${r}_block_${t}`)}),!I&&a&&t===`conditions`&&e(`div`,{onClick:()=>{E([...S,{_id:Date.now(),open:!0}]),c({...o,conditions:[...o.conditions,[]]}),V(o.conditions.length-1),setTimeout(()=>V(!1),1e3)},className:X.blockCardAdd,children:[`+`,s(`div`,{className:X.cardAdd,children:i})]}),s(ke,{open:k,onClose:()=>A(!1)}),s(Ae,{open:j,onClose:()=>M(!1)})]})},Z={menuRules:`_menuRules_1ijaq_1`,wizardButton:`_wizardButton_1ijaq_13`,switchesRenderWrapper:`_switchesRenderWrapper_1ijaq_26`,menuOff:`_menuOff_1ijaq_35`,menuTitle:`_menuTitle_1ijaq_41`,marginAuto:`_marginAuto_1ijaq_55`,inputWidth:`_inputWidth_1ijaq_60`,menuWrapper:`_menuWrapper_1ijaq_72`,hamburgerWrapper:`_hamburgerWrapper_1ijaq_80`,hamburgerOff:`_hamburgerOff_1ijaq_113`,nothingFound:`_nothingFound_1ijaq_121`,resetSearch:`_resetSearch_1ijaq_128`,controlPanel:`_controlPanel_1ijaq_140`,controlPanelAppBar:`_controlPanelAppBar_1ijaq_164`,tabTriggers:`_tabTriggers_1ijaq_180`,tabConditions:`_tabConditions_1ijaq_184`,tabActions:`_tabActions_1ijaq_188`,addClassMenu:`_addClassMenu_1ijaq_192`,addClassBackground:`_addClassBackground_1ijaq_198`,addClassPosition:`_addClassPosition_1ijaq_202`};M();var Pe=e=>{let{allProperties:t,allProperties:{acceptedBy:n,id:r},setUserRules:i,userRules:a,setTourStep:o,tourStep:c,isTourOpen:l,onTouchMove:u,isActive:d}=e;return s(Oe,{allProperties:t,id:t.id,isActive:d,setUserRules:i,userRules:a,children:s(pe,{onDoubleClick:()=>{l&&c===R.addScheduleByDoubleClick&&r===`TriggerScheduleBlock`&&o(R.openTagsMenu),l&&c===R.addActionPrintText&&r===`ActionPrintText`&&o(R.showJavascript);let e=Date.now(),t;switch(n){case`actions`:t=`then`;break;case`conditions`:t=a[n].length-1}let s=J(n,a,t),u={id:r,_id:e,acceptedBy:n};t===void 0?s.triggers.push({...u}):n===`actions`?s.actions[t].push({...u}):n===`conditions`&&s.conditions[t].push({...u}),i(s)},...e,...t,onTouchMove:u})})};M();var Fe={triggers:Z.tabTriggers,conditions:Z.tabConditions,actions:Z.tabActions},Ie=({addClass:t,setAllBlocks:n,allBlocks:r,userRules:i,onChangeBlocks:l,setTourStep:u,tourStep:f,isTourOpen:m,onStartWizard:h})=>{let{blocks:g,socket:_}=O(U),[v,y]=xe(!1,`hamburgerOnOff`),[b,S]=xe({text:``,type:`triggers`,index:0},`filterControlPanel`),C=(e=b.text,t=b.type)=>{if(!g)return;let r=[...g];r=r.filter(t=>{if(!e)return!0;let{name:n}=t.getStaticData();return n&&D.t(n).toLowerCase().includes(e.toLowerCase())}),r=r.filter(e=>t===e.getStaticData().acceptedBy),n(r)},w=(e,t)=>{m&&t===0&&f===R.selectTriggers&&u(R.addScheduleByDoubleClick),m&&t===2&&f===R.selectActions&&u(R.addActionPrintText),S({...b,index:t,type:[`triggers`,`conditions`,`actions`][t]}),C(b.text,[`triggers`,`conditions`,`actions`][t])},E=e=>({id:`scrollable-force-tab-${e}`,"aria-controls":`scrollable-force-tabpanel-${e}`});return x(()=>{C()},[g]),s(c,{mouseEvent:!1,touchEvent:`onTouchStart`,onClickAway:()=>y(!0),children:e(`div`,{className:p.clsx(Z.menuWrapper,t[1035]&&Z.addClassMenu),children:[s(`div`,{className:`${Z.hamburgerWrapper} ${v?Z.hamburgerOff:null}`,onClick:()=>y(!v),children:s(v?ae:ie,{})}),e(`div`,{className:`${p.clsx(Z.menuRules,Fe[b.type],t[1035]&&Z.addClassBackground,t[835]&&Z.addClassPosition)} ${v?Z.menuOff:null}`,children:[s(d,{className:Z.wizardButton,fullWidth:!0,size:`small`,variant:`outlined`,startIcon:s(re,{}),onClick:h,children:D.t(`Wizard`)}),s(`div`,{className:Z.controlPanel,children:s(j,{className:Z.controlPanelAppBar,position:`static`,children:e(a,{value:b.index,onChange:w,children:[s(o,{className:p.clsx(`blocks-triggers`,Z.tabTriggers),title:D.t(`Triggers`),icon:s(z,{iconName:`FlashOn`}),...E(0)}),s(o,{title:D.t(`Conditions`),className:p.clsx(`blocks-conditions`,Z.tabConditions),icon:s(z,{iconName:`Help`}),...E(1)}),s(o,{title:D.t(`Actions`),className:p.clsx(`blocks-actions`,Z.tabActions),icon:s(z,{iconName:`PlayForWork`}),...E(2)})]})})}),s(`div`,{className:Z.switchesRenderWrapper,children:e(`span`,{children:[r.map(e=>{let{name:t,id:n,icon:r,adapter:a}=e.getStaticData();return s(T,{children:s(Pe,{adapter:a,allProperties:e.getStaticData(),icon:r,id:n,isActive:!1,isTourOpen:m,name:t,onTouchMove:()=>y(!0),setTourStep:u,setUserRules:l,socket:_,tourStep:f,userRules:i})},n)}),!r.length&&e(`div`,{className:Z.nothingFound,children:[D.t(`Nothing found`),`...`,s(`div`,{className:Z.resetSearch,onClick:()=>{S({...b,text:``}),C(``)},children:D.t(`reset search`)})]})]})}),s(`div`,{className:p.clsx(Z.menuTitle,Z.marginAuto)}),s(H,{className:Z.inputWidth,fullWidth:!0,customValue:!0,value:b.text,size:`small`,autoComplete:`off`,label:D.t(`search`),variant:`outlined`,onChange:e=>{S({...b,text:e}),C(e)}})]})]})})},Q={bandTriggers:`_bandTriggers_91vrz_5`,bandConditions:`_bandConditions_91vrz_9`,bandActions:`_bandActions_91vrz_13`,paper:`_paper_91vrz_17`,title:`_title_91vrz_22`,close:`_close_91vrz_29`,content:`_content_91vrz_35`,stepper:`_stepper_91vrz_40`,step:`_step_91vrz_40`,hint:`_hint_91vrz_56`,warning:`_warning_91vrz_61`,blockCard:`_blockCard_91vrz_68`,blockBody:`_blockBody_91vrz_79`,remove:`_remove_91vrz_86`,notFound:`_notFound_91vrz_93`,chooser:`_chooser_91vrz_99`,choice:`_choice_91vrz_105`,choiceIcon:`_choiceIcon_91vrz_128`,choiceName:`_choiceName_91vrz_136`,addMore:`_addMore_91vrz_144`,summaryBand:`_summaryBand_91vrz_150`,summaryLabel:`_summaryLabel_91vrz_156`,preview:`_preview_91vrz_164`,actions:`_actions_91vrz_169`,spacer:`_spacer_91vrz_173`};M();var $=[`triggers`,`conditions`,`actions`],Le={triggers:`Triggers`,conditions:`Conditions`,actions:`Actions`},Re={triggers:`What should start the rule?`,conditions:`When should the rule run? This step is optional.`,actions:`What should happen?`},ze={triggers:`when`,conditions:`and`,actions:`then`},Be={triggers:Q.bandTriggers,conditions:Q.bandConditions,actions:Q.bandActions},Ve=()=>({triggers:[],conditions:[],actions:[]}),He=({onCreate:t,onClose:n,hasRule:a,socket:o,theme:c,themeType:l,themeName:f})=>{let{blocks:_}=O(U),[b,x]=h(0),[C,T]=h(Ve),[k,j]=h(null),M=P(0),F=m(()=>{let e={triggers:[],conditions:[],actions:[]};return _==null||_.forEach(t=>{var n;let{acceptedBy:r}=t.getStaticData();(n=e[r])==null||n.push(t)}),e},[_]),I=m(()=>({triggers:C.triggers,conditions:C.conditions.length?[C.conditions]:[[]],justCheck:!1,actions:{then:C.actions,else:[]}}),[C]),L=(e,t)=>{M.current+=1,T(n=>({...n,[e]:[...n[e],{id:t,_id:M.current,acceptedBy:e}]})),j(null)},R=(e,t)=>T(n=>({...n,[e]:n[e].filter(e=>e._id!==t)})),B=(e,t,n)=>T(r=>({...r,[e]:r[e].map(r=>r._id===t?{...n,_id:t,id:r.id,acceptedBy:e}:r)})),V=(e,t,n)=>{let r=_==null?void 0:_.find(t=>t.getStaticData().id===e.id);return r?s(r,{_id:e._id,settings:e,acceptedBy:t,onChange:n?()=>{}:n=>B(t,e._id,n),socket:o,theme:c,themeType:l,themeName:f,enableSimulation:!1,userRules:I,onUpdate:!1,setOnUpdate:()=>{}}):s(`div`,{className:Q.notFound,children:D.t(`Block not found`)})},ee=t=>s(`div`,{className:Q.chooser,children:F[t].map(n=>{let{id:r,name:i,icon:a,adapter:c,title:l}=n.getStaticData();return e(`button`,{type:`button`,className:Q.choice,title:l?D.t(l):void 0,onClick:()=>L(t,r),children:[s(z,{iconName:a,adapter:c,socket:o,className:Q.choiceIcon}),s(`span`,{className:Q.choiceName,children:D.t(i)})]},r)})}),H=(t,n)=>e(`div`,{className:Q.step,hidden:b!==n,children:[s(`div`,{className:Q.hint,children:D.t(Re[t])}),C[t].map(n=>e(`div`,{className:p.clsx(Q.blockCard,Be[t]),children:[s(`div`,{className:Q.blockBody,children:V(n,t)}),s(w,{className:Q.remove,size:`small`,title:D.t(`Delete`),onClick:()=>R(t,n._id),children:s(oe,{fontSize:`small`})})]},n._id)),k===t||!C[t].length?ee(t):s(d,{className:Q.addMore,startIcon:s(N,{}),onClick:()=>j(t),children:D.t(`Add another`)})]},t),te=()=>e(`div`,{className:Q.step,children:[$.map(t=>C[t].length?e(`div`,{className:Q.summaryBand,children:[s(`div`,{className:p.clsx(Q.summaryLabel,Be[t]),children:D.t(ze[t])}),C[t].map(e=>s(`div`,{className:p.clsx(Q.blockCard,Q.preview,Be[t]),children:s(`div`,{className:Q.blockBody,children:V(e,t,!0)})},e._id))]},t):null),C.conditions.length?null:s(`div`,{className:Q.hint,children:D.t(`Without a condition the rule always runs`)}),a?s(`div`,{className:Q.warning,children:D.t(`The current rule will be replaced`)}):null]}),W=b===$.length,G=W||b===1||!!C[$[b]].length;return e(y,{open:!0,fullWidth:!0,maxWidth:`md`,onClose:n,classes:{paper:Q.paper},children:[e(S,{className:Q.title,children:[D.t(`Create a rule step by step`),s(w,{className:Q.close,size:`small`,title:D.t(`Close`),onClick:n,children:s(g,{})})]}),e(E,{className:Q.content,children:[e(r,{className:Q.stepper,activeStep:b,children:[$.map(e=>s(i,{children:s(u,{children:D.t(Le[e])})},e)),s(i,{children:s(u,{children:D.t(`Summary`)})})]}),$.map(H),W?te():null]}),e(A,{className:Q.actions,children:[s(d,{disabled:!b,startIcon:s(ce,{}),onClick:()=>x(b-1),children:D.t(`Back`)}),s(`div`,{className:Q.spacer}),s(d,{onClick:n,children:D.t(`Cancel`)}),W?s(d,{variant:`contained`,color:`primary`,onClick:()=>{t(I),n()},children:D.t(a?`Replace rule`:`Create rule`)}):s(d,{variant:`contained`,color:`primary`,disabled:!G,endIcon:s(v,{}),onClick:()=>x(b+1),children:D.t(b===1&&!C.conditions.length?`Skip`:`Next`)})]})]})};M();var Ue=[],We=({code:t,onChange:n,themeName:r,themeType:i,theme:a,setTourStep:o,tourStep:c,isTourOpen:l,command:u,scriptId:f,changed:p,running:m,newRuleId:g,onNewRuleHandled:_})=>{var v;let{blocks:y,socket:S,setOnUpdate:C,setOnDebugMessage:w,setEnableSimulation:T}=O(U),[E,k]=h([]),[A,j]=h(ee(t)),[M,N]=h(``),[L,R]=h(!1),[z,B]=h(!1);x(()=>{let e,t,n=(n,r)=>{n===`${e}.alive`&&t!==(r==null?void 0:r.val)&&(t=!!(r!=null&&r.val),t&&e&&(S==null||S.sendTo(e.replace(/^system\.adapter\./,``),`rulesOn`,f)))},r=(r,i)=>{var a;if(S&&e!==(i==null||(a=i.common)==null?void 0:a.engine)){var o;e&&(S.unsubscribeState(`${e}.alive`,n),t&&S.sendTo(e.replace(/^system\.adapter\./,``),`rulesOn`,f)),e=i==null||(o=i.common)==null?void 0:o.engine,e&&e&&S.subscribeState(`${e}.alive`,n)}},i=(e,t)=>{if(t)try{let e=JSON.parse(t.val),n=Date.now();if(e.ruleId===f&&n-e.ts<1e3){let t=[...Ue,{blockId:e.blockId,data:e.data,ts:e.ts}];t.length>200&&t.splice(0,t.length-200);for(let e=t.length-1;e>=0;e--)if(t[e].ts<n-5e3){t.splice(0,e);break}Ue=t,w(t)}}catch{console.error(`Cannot parse: ${t.val}`)}};return S==null||S.getObject(f).then(t=>{var a;e=t==null||(a=t.common)==null?void 0:a.engine,S.subscribeObject(f,r),e&&(S.subscribeState(`${e}.alive`,n),S.subscribeState(`${e.replace(/^system\.adapter\./,``)}.debug.rules`,i))}),function(){S==null||S.unsubscribeObject(f,r),e&&(S==null||S.unsubscribeState(`${e}.alive`,n),t&&(S==null||S.sendTo(e.replace(/^system\.adapter\./,``),`rulesOff`,f)),S==null||S.unsubscribeState(`${e.replace(/^system\.adapter\./,``)}.debug.rules`,i))}},[]),x(()=>{T(!p&&m)},[p,m,T]),x(()=>{u&&(N(u),L||R(!0))},[u]),x(()=>{let e=ee(t);JSON.stringify(e)!==JSON.stringify(A)&&(j(e),C(!0))},[t]),x(()=>{document.getElementsByTagName(`HTML`)[0].className=r||`blue`},[r]),x(()=>{g&&g===f&&(_(),B(!0))},[g,f,_]);let V=b(e=>{j(e),y&&n(te(e,y))},[y,n]),H=P(null),[W,G]=h({835:!1,1035:!1});if(x(()=>{H.current&&(H.current.clientWidth<=1035&&G({835:!1,1035:!0}),H.current.clientWidth<=835&&G({1035:!0,835:!0}),H.current.clientWidth>1035&&G({835:!1,1035:!1}))},[((v=H.current)==null?void 0:v.clientWidth)||0]),!y||!S)return null;let ne=!A.triggers.length&&!A.actions.then.length&&!A.actions.else.length&&!A.conditions.some(e=>e.length);return e(`div`,{className:K.wrapperRules,ref:H,children:[s(be,{allBlocks:E,socket:S}),L?M===`export`?s(F,{scriptId:f,themeType:i,onClose:()=>R(!1),text:JSON.stringify(A,null,2)}):s(I,{themeType:i,onClose:e=>{R(!1),e&&V(JSON.parse(e))}}):null,z?s(He,{hasRule:!ne,socket:S,theme:a,themeType:i,themeName:r,onCreate:V,onClose:()=>B(!1)}):null,e(`div`,{className:K.rootWrapper,children:[s(Ie,{setAllBlocks:k,allBlocks:E,userRules:A,onChangeBlocks:V,setTourStep:o,tourStep:c,addClass:W,isTourOpen:l,onStartWizard:()=>B(!0)}),e(`div`,{className:K.bands,children:[ne?e(`div`,{className:K.emptyRule,children:[s(`div`,{className:K.emptyRuleText,children:D.t(`Create a rule step by step`)}),s(d,{variant:`contained`,color:`primary`,startIcon:s(re,{}),onClick:()=>B(!0),children:D.t(`Wizard`)})]}):null,s(Ne,{socket:S,setUserRules:V,userRules:A,isTourOpen:l,setTourStep:o,tourStep:c,name:`${D.t(`when`)}...`,typeBlock:`triggers`,iconName:`FlashOn`,themeType:i,themeName:r,theme:a}),s(Ne,{socket:S,setUserRules:V,isTourOpen:l,setTourStep:o,tourStep:c,userRules:A,name:`...${D.t(`and`)}...`,typeBlock:`conditions`,iconName:`Help`,nameAdditionally:D.t(`or`),additionally:!0,themeType:i,themeName:r,theme:a}),s(Ne,{socket:S,setUserRules:V,isTourOpen:l,setTourStep:o,tourStep:c,userRules:A,name:`...${D.t(`then`)}`,typeBlock:`actions`,iconName:`PlayForWork`,nameAdditionally:D.t(`else`),additionally:!0,themeType:i,themeName:r,theme:a})]})]})]},`rulesEditor`)};export{We as default};
@@ -1,2 +1,2 @@
1
- import{$n as e,Ct as t,Qn as n,Ut as r,Vt as i,en as a,in as o,lt as s,nn as c,nr as l,p as u,tn as d,wr as f}from"./_virtual_mf___mfe_internal__iobroker_javascript__mf_owner__113183188387379__loadShare___mf_0_iobroker_mf_1_gui_mf_2_components__loadShare__.js-D-gi6Mty.js";import{t as p}from"./ScriptEditorVanillaMonaco-C0biTTli.js";f();var m={textArea:{width:`calc(100% - 10px)`,resize:`none`},dialog:{height:`95%`},fullHeight:{height:`100%`,overflow:`hidden`},args:e=>({color:e.palette.mode===`dark`?`white`:`black`,height:30,width:`100%`,fontSize:16}),argsTitle:e=>({color:e.palette.mode===`dark`?`white`:`black`,fontWeight:`bold`})},h=class extends l.Component{constructor(e){super(e),this.state={changed:!1,source:!e.source&&e.isReturn?`
1
+ import{$n as e,Ct as t,Qn as n,Ut as r,Vt as i,en as a,in as o,lt as s,nn as c,nr as l,p as u,tn as d,wr as f}from"./_virtual_mf___mfe_internal__iobroker_javascript__mf_owner__113183188387379__loadShare___mf_0_iobroker_mf_1_gui_mf_2_components__loadShare__.js-D-gi6Mty.js";import{t as p}from"./ScriptEditorVanillaMonaco-BDAw2Bw6.js";f();var m={textArea:{width:`calc(100% - 10px)`,resize:`none`},dialog:{height:`95%`},fullHeight:{height:`100%`,overflow:`hidden`},args:e=>({color:e.palette.mode===`dark`?`white`:`black`,height:30,width:`100%`,fontSize:16}),argsTitle:e=>({color:e.palette.mode===`dark`?`white`:`black`,fontWeight:`bold`})},h=class extends l.Component{constructor(e){super(e),this.state={changed:!1,source:!e.source&&e.isReturn?`
2
2
  return false`:e.source}}componentDidMount(){setTimeout(()=>{try{var e;(e=window.document.getElementById(`source-text-area`))==null||e.focus()}catch{}},100)}handleCancel(){this.props.onClose(!1)}handleOk(){(!this.props.isReturn||this.state.source.includes(`return `))&&this.props.onClose(this.state.source)}onChange(e){this.setState({changed:!0,source:e})}render(){return e(a,{onClose:()=>!1,maxWidth:`lg`,sx:{"& .MuiDialog-paper":m.dialog},fullWidth:!0,open:!0,"aria-labelledby":`source-dialog-title`,children:[n(o,{id:`source-dialog-title`,children:u.t(`Function editor`)}),e(c,{style:m.fullHeight,children:[this.props.args&&e(i,{sx:m.args,children:[n(i,{component:`span`,sx:m.argsTitle,children:u.t(`function (`)}),this.props.args,n(i,{component:`span`,sx:m.argsTitle,children:`)`})]},`arguments`),n(p,{triggerPrettier:1,adapterName:this.props.adapterName,runningInstances:this.props.runningInstances,style:{...m.textArea,height:this.props.args?`calc(100% - 30px)`:`100%`},name:`blockly`,socket:this.props.socket,readOnly:!1,checkJs:!1,changed:this.state.changed,code:this.state.source,isDark:this.props.themeType===`dark`,onChange:e=>this.onChange(e),language:`javascript`},`scriptEditor`)]}),e(d,{children:[n(r,{variant:`contained`,onClick:()=>this.handleOk(),color:`primary`,startIcon:n(s,{}),children:u.t(`Save`)}),n(r,{color:`grey`,variant:`contained`,onClick:()=>this.handleCancel(),startIcon:n(t,{}),children:u.t(`Cancel`)})]})]})}};export{h as default};
@@ -1,3 +1,3 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./stateHoverProvider-BkW15VMN.js","./cronHoverProvider-BZMOFHO_.js","./AiInlineProvider-BxOW88xU.js","./AiChatService-Bsp_rhVx.js","./index-PLY-IJik.js","./Import-XKVP-nRT.js","./Error-Ch2nx5uC.js","./blockly-fcfyKYzp.js","./index-CXaeqPRy.css","./inlineDiffController-Qh402KhK.js","./applyCodeEdit-D3nb7erO.js","./inlineChatWidget-NIvdRGmU.js"])))=>i.map(i=>d[i]);
2
- import{r as e}from"./rolldown-runtime-C0FnF6B9.js";import{t}from"./vite-preload-helper-CaC3yEL3.js";import{$n as n,N as r,Nn as i,Qn as a,Ut as o,en as s,in as c,mn as l,nn as u,nr as d,p as f,sn as p,tn as m,wr as h,z as g,zn as _}from"./_virtual_mf___mfe_internal__iobroker_javascript__mf_owner__113183188387379__loadShare___mf_0_iobroker_mf_1_gui_mf_2_components__loadShare__.js-D-gi6Mty.js";import{d as v,p as y,u as b}from"./index-PLY-IJik.js";var x=e({default:()=>T});h();function S(e){return/^script\.js\.global\./.test(e)}var C=0;function w(e){return e.replace(/\x1b\[[0-9;]*m/g,``)}var T=class extends d.Component{get monacoTS(){var e;return(e=this.monaco)==null||(e=e.languages)==null?void 0:e.typescript}constructor(e){super(e),_(this,`monacoDiv`,null),_(this,`editor`,null),_(this,`monaco`,window.monaco),_(this,`insert`,``),_(this,`originalCode`,void 0),_(this,`runningInstancesStr`,void 0),_(this,`monacoCounter`,0),_(this,`location`,void 0),_(this,`breakpoints`,void 0),_(this,`lastSearch`,``),_(this,`typings`,{}),_(this,`decorations`,[]),_(this,`datapointProviderDisposable`,null),_(this,`inlineProviderDisposable`,null),_(this,`stateHoverDisposable`,null),_(this,`showStateValueDisposable`,null),_(this,`cronHoverDisposable`,null),_(this,`codeLensDisposable`,null),_(this,`aiHelpersUnsubscribe`,null),_(this,`inlineChatWidgetInstance`,null),_(this,`inlineDiffInstance`,null),_(this,`inlineDiffCssInjected`,!1),_(this,`triggerPrettier`,void 0),_(this,`contentChangeDisposable`,null),_(this,`mouseDownDisposable`,null),this.state={name:`current`,isDark:e.isDark||!1,language:e.language||`javascript`,readOnly:e.readOnly||!1,alive:!0,check:!1,searchText:this.props.searchText||``,typingsLoaded:!1,showError:null},this.triggerPrettier=e.triggerPrettier,this.runningInstancesStr=JSON.stringify(this.props.runningInstances),this.originalCode=e.code||``,this.monacoDiv=d.createRef()}waitForMonaco(e){var t;let n=!!((t=this.monacoTS)!=null&&(t=t.typescriptDefaults)!=null&&t.getCompilerOptions);if(!n||!this.props.runningInstances){var r;if(this.monaco=window.monaco,n=!!((r=this.monacoTS)!=null&&(r=r.typescriptDefaults)!=null&&r.getCompilerOptions),this.monacoCounter++,!n&&this.monacoCounter<20){console.log(`wait for monaco loaded`),setTimeout(()=>this.waitForMonaco(e),200);return}this.monacoCounter>=20&&console.error(`Cannot load monaco!`)}else e&&e()}loadTypings(e){if(!this.editor)return;e||=this.props.runningInstances;let t=e&&Object.keys(e).find(t=>e==null?void 0:e[t]);t&&this.props.socket.sendTo(t.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;this.undo,this.redo,this.showInlineDiff,this.getEditorSelection,this.getEditorContent,this.getCursorPosition,this.highlightLineRange,this.goToLine,this.replaceSelection,this.getDiagnostics,this.getDocumentSymbols;let n=!!((e=this.monacoTS)!=null&&(e=e.typescriptDefaults)!=null&&e.getCompilerOptions);if(!n||!this.props.runningInstances){var r;if(this.monaco=window.monaco,n=!!((r=this.monacoTS)!=null&&(r=r.typescriptDefaults)!=null&&r.getCompilerOptions),!n){console.log(`wait for monaco loaded...`),this.waitForMonaco(()=>this.componentDidMount());return}}if(!this.editor&&n&&this.monaco){var i,a,o;console.log(`Init editor`),(i=(a=this.props).onRegisterSelect)==null||i.call(a,()=>{if(this.editor){let t=this.editor.getSelection();if(t){var e;return(e=this.editor.getModel())==null?void 0:e.getValueInRange(t)}}});let e=this.monacoTS.typescriptDefaults.getCompilerOptions();if(e.allowJs=!0,e.checkJs=this.props.checkJs!==!1,e.noLib=!0,e.lib=[],e.useUnknownInCatchVariables=!1,e.moduleResolution=this.monacoTS.ModuleResolutionKind.NodeJs,e.target=this.monacoTS.ScriptTarget.ESNext,e.module=this.monacoTS.ModuleKind.ESNext,e.allowNonTsExtensions=!0,this.monacoTS.typescriptDefaults.setCompilerOptions(e),this.setTypeCheck(!1),(o=this.monacoDiv)!=null&&o.current){var s;this.editor=this.monaco.editor.create((s=this.monacoDiv)==null?void 0:s.current,{lineNumbers:`on`,scrollBeyondLastLine:!1,automaticLayout:!0,glyphMargin:!!this.props.breakpoints,colorDecorators:!0,hover:{enabled:`on`,delay:200,sticky:!0},fixedOverflowWidgets:!0}),this.contentChangeDisposable=this.editor.onDidChangeModelContent(()=>this.onChange()),this.monaco&&!this.datapointProviderDisposable&&t(async()=>{let{registerDatapointProvider:e}=await import(`./AiDatapointProvider-DzFpUKkT.js`);return{registerDatapointProvider:e}},[],import.meta.url).then(({registerDatapointProvider:e})=>{this.monaco&&(this.datapointProviderDisposable=e(this.monaco,this.props.socket))}).catch(()=>{}),this.monaco&&!this.showStateValueDisposable&&t(async()=>{let{registerShowStateValueAction:e}=await import(`./stateHoverProvider-BkW15VMN.js`);return{registerShowStateValueAction:e}},__vite__mapDeps([0]),import.meta.url).then(({registerShowStateValueAction:e})=>{this.monaco&&this.editor&&!this.showStateValueDisposable&&(this.showStateValueDisposable=e(this.editor,this.monaco,f.t(`Show ioBroker state value`)))}).catch(()=>{}),this.registerAiHelpers(),this.aiHelpersUnsubscribe=v(e=>{e?this.registerAiHelpers():this.disposeAiHelpers()}),this.loadTypings(),this.props.onForceSave&&this.editor.addCommand(this.monaco.KeyMod.CtrlCmd|this.monaco.KeyCode.KeyS,()=>this.props.onForceSave&&this.props.onForceSave()),this.registerAiActions(),setTimeout(()=>{this.highlightText(this.state.searchText),this.location=this.props.location||void 0,this.breakpoints=this.props.breakpoints,this.showDecorators()})}}let c={selectOnLineNumbers:!0,scrollBeyondLastLine:!1,automaticLayout:!0,readOnly:this.state.readOnly,language:this.state.language,isDark:this.state.isDark};this.setEditorOptions(c),this.editor&&(this.editor.focus(),this.editor.setValue(this.originalCode),this.props.onToggleBreakpoint&&(this.mouseDownDisposable=this.editor.onMouseDown(e=>{var t;let n=e.target;this.props.onToggleBreakpoint&&((t=n.detail)==null?void 0:t.glyphMarginLeft)!==void 0&&n.position&&this.props.onToggleBreakpoint(n.position.lineNumber-1)})))}setEditorOptions(e){if(e&&(e.language&&this.setEditorLanguage(e.language),this.editor&&(e.readOnly!==void 0&&this.editor.updateOptions({readOnly:e.readOnly}),e.lineWrap!==void 0&&this.editor.updateOptions({wordWrap:e.lineWrap?`on`:`off`})),e.typeCheck!==void 0&&this.setTypeCheck(e.typeCheck),e.isDark!==void 0)){var t;(t=this.monaco)==null||t.editor.setTheme(e.isDark?`vs-dark`:`vs`)}}registerAiHelpers(){b()&&this.monaco&&this.editor&&(this.stateHoverDisposable||t(async()=>{let{registerStateHoverProvider:e}=await import(`./stateHoverProvider-BkW15VMN.js`);return{registerStateHoverProvider:e}},__vite__mapDeps([0]),import.meta.url).then(({registerStateHoverProvider:e})=>{this.monaco&&b()&&!this.stateHoverDisposable&&(this.stateHoverDisposable=e(this.monaco,this.props.socket))}).catch(()=>{}),this.cronHoverDisposable||t(async()=>{let{registerCronHoverProvider:e}=await import(`./cronHoverProvider-BZMOFHO_.js`);return{registerCronHoverProvider:e}},__vite__mapDeps([1]),import.meta.url).then(({registerCronHoverProvider:e})=>{this.monaco&&b()&&!this.cronHoverDisposable&&(this.cronHoverDisposable=e(this.monaco))}).catch(()=>{}),this.props.aiCompletionsEnabled&&!this.inlineProviderDisposable&&t(async()=>{let{registerAiInlineProvider:e}=await import(`./AiInlineProvider-BxOW88xU.js`);return{registerAiInlineProvider:e}},__vite__mapDeps([2,3]),import.meta.url).then(({registerAiInlineProvider:e})=>{this.monaco&&b()&&!this.inlineProviderDisposable&&(this.inlineProviderDisposable=e(this.monaco,this.props.socket,this.props.runningInstances))}).catch(()=>{}),this.props.onAiAction&&!this.codeLensDisposable&&t(async()=>{let{registerAiCodeLensProvider:e}=await import(`./index-PLY-IJik.js`).then(e=>e.f);return{registerAiCodeLensProvider:e}},__vite__mapDeps([4,5,6,7,8]),import.meta.url).then(({registerAiCodeLensProvider:e})=>{this.monaco&&this.editor&&this.props.onAiAction&&b()&&!this.codeLensDisposable&&(this.codeLensDisposable=e(this.monaco,this.editor,(e,t,n,r,i)=>{var a,o,s;let c=(a=this.editor)==null?void 0:a.getModel(),l=c?c.getLineMaxColumn(Math.min(i,c.getLineCount())):1;(o=(s=this.props).onAiAction)==null||o.call(s,{action:e,code:t,rangeLabel:n,range:{startLine:r,startColumn:1,endLine:i,endColumn:l},kind:`codelens`})}))}).catch(()=>{}))}disposeAiHelpers(){var e,t,n,r;(e=this.stateHoverDisposable)==null||e.dispose(),this.stateHoverDisposable=null,(t=this.cronHoverDisposable)==null||t.dispose(),this.cronHoverDisposable=null,(n=this.inlineProviderDisposable)==null||n.dispose(),this.inlineProviderDisposable=null,(r=this.codeLensDisposable)==null||r.dispose(),this.codeLensDisposable=null}componentWillUnmount(){var e,n,r,i,a,o,s,c,l,u;if((e=this.contentChangeDisposable)==null||e.dispose(),this.contentChangeDisposable=null,(n=this.mouseDownDisposable)==null||n.dispose(),this.mouseDownDisposable=null,(r=this.datapointProviderDisposable)==null||r.dispose(),this.datapointProviderDisposable=null,t(async()=>{let{clearDatapointCache:e}=await import(`./AiDatapointProvider-DzFpUKkT.js`);return{clearDatapointCache:e}},[],import.meta.url).then(({clearDatapointCache:e})=>e()).catch(()=>{}),(i=this.inlineProviderDisposable)==null||i.dispose(),this.inlineProviderDisposable=null,(a=this.stateHoverDisposable)==null||a.dispose(),this.stateHoverDisposable=null,(o=this.showStateValueDisposable)==null||o.dispose(),this.showStateValueDisposable=null,t(async()=>{let{clearStateHoverCache:e}=await import(`./stateHoverProvider-BkW15VMN.js`);return{clearStateHoverCache:e}},__vite__mapDeps([0]),import.meta.url).then(({clearStateHoverCache:e})=>e()).catch(()=>{}),(s=this.cronHoverDisposable)==null||s.dispose(),this.cronHoverDisposable=null,(c=this.codeLensDisposable)==null||c.dispose(),this.codeLensDisposable=null,(l=this.aiHelpersUnsubscribe)==null||l.call(this),this.aiHelpersUnsubscribe=null,(u=this.inlineChatWidgetInstance)==null||u.dispose(),this.inlineChatWidgetInstance=null,this.hideInlineDiff(),this.editor){var d,f;(d=(f=this.props).onRegisterSelect)==null||d.call(f,null),this.editor.dispose(),this.editor=null}}async doPrettier(){var e;let t=this.props.runningInstances&&Object.keys(this.props.runningInstances).find(e=>{var t;return(t=this.props.runningInstances)==null?void 0:t[e]});if(!t){window.alert(f.t(`No script adapter instance found to format the code`));return}let n=await this.props.socket.sendTo(t.replace(`system.adapter.`,``),`prettier`,{code:(e=this.editor)==null?void 0:e.getValue(),type:this.state.language});if(n.error)this.setState({showError:{title:f.t(`Error formatting code`),message:w(n.error)}});else if(n.code){var r,i,a;(r=this.editor)==null||r.setValue(n.code),(i=(a=this.props).onChange)==null||i.call(a,n.code),this.showDecorators()}}setEditorLanguage(e){if(!this.editor)return;let t=this.editor.getModel();if(t){var n;let i=t.getValue(),a=t.uri.path,o=typeof a==`string`&&a.includes(`.`)?a.substring(0,a.lastIndexOf(`.`)):`index`,s=e===`javascript`?`js`:e===`typescript`?`ts`:e;t.dispose();let c=e===`javascript`||e===`typescript`?`typescript`:e,l=(n=this.monaco)==null?void 0:n.editor.createModel(i,c,this.monaco.Uri.from({scheme:window.location.protocol.replace(`:`,``),path:`${o}${C++}.${s}`}));if(l){var r;this.editor.setModel(l),(r=this.contentChangeDisposable)==null||r.dispose(),this.contentChangeDisposable=this.editor.onDidChangeModelContent(()=>this.onChange())}}}setTypeCheck(e){var t,n;let r={noSemanticValidation:!this.state.alive||!e,noSyntaxValidation:!this.state.alive};(t=this.monacoTS)==null||t.typescriptDefaults.setDiagnosticsOptions(r),(n=this.monacoTS)==null||n.javascriptDefaults.setDiagnosticsOptions({noSemanticValidation:!this.state.alive||!e,noSyntaxValidation:!this.state.alive})}setEditorTypings(e=``){var t,n;let r=S(e),i=`${e}.d.ts`,a=[];for(let e of Object.keys(this.typings))r&&(e===`global.d.ts`||e.startsWith(`script.js.global`)&&e!==i)||a.push({filePath:e,content:this.typings[e]});if((t=this.monacoTS)!=null&&(t=t.typescriptDefaults)!=null&&t.setExtraLibs)this.monacoTS.typescriptDefaults.setExtraLibs(a);else if((n=this.monacoTS)!=null&&(n=n.typescriptDefaults)!=null&&n.addExtraLib){let e=this.monacoTS.typescriptDefaults.getExtraLibs();a.forEach(t=>{!e[t.filePath]&&this.monaco&&this.monacoTS.typescriptDefaults.addExtraLib(t.content,t.filePath)})}}undo(){var e;(e=this.editor)==null||e.trigger(`toolbar`,`undo`,null)}redo(){var e;(e=this.editor)==null||e.trigger(`toolbar`,`redo`,null)}insertTextIntoEditor(e){if(!this.editor||!this.monaco)return;let t=this.editor.getSelection();if(t){let n=new this.monaco.Range(t.startLineNumber,t.startColumn,t.endLineNumber,t.endColumn);this.editor.executeEdits(``,[{range:n,text:e,forceMoveMarkers:!0}])}this.editor.focus()}highlightText(e){var t;if(!this.editor||!this.monaco)return 0;let n=e?(t=this.editor.getModel())==null?void 0:t.findMatches(e,!0,!1,!1,null,!0):void 0;if(n!=null&&n.length)return n.forEach(e=>{var t;return(t=this.editor)==null?void 0:t.setSelection(e.range)}),this.editor.revealLine(n[0].range.startLineNumber),n.length;let r=this.editor.getPosition();if(r){let e=r.lineNumber,t=r.column;this.editor.setSelection(new this.monaco.Range(e,t,e,t))}return 0}showInlineDiff(e){if(!this.editor||!this.monaco)return;let n=this.editor,r=this.monaco;this.hideInlineDiff(),t(async()=>{let{InlineDiffController:e,INLINE_DIFF_CSS:t}=await import(`./inlineDiffController-Qh402KhK.js`);return{InlineDiffController:e,INLINE_DIFF_CSS:t}},__vite__mapDeps([9,10]),import.meta.url).then(({InlineDiffController:t,INLINE_DIFF_CSS:i})=>{if(!this.inlineDiffCssInjected){let e=document.createElement(`style`);e.textContent=i,e.setAttribute(`data-iob-aichat`,`inline-diff`),document.head.appendChild(e),this.inlineDiffCssInjected=!0}let a=new t(n,r,{range:e.range,originalText:e.originalText,modifiedText:e.modifiedText,onAccepted:()=>{var t;this.inlineDiffInstance=null,(t=e.onAccepted)==null||t.call(e)},onRejected:()=>{var t;this.inlineDiffInstance=null,(t=e.onRejected)==null||t.call(e)}});this.inlineDiffInstance=a,a.show()}).catch(()=>{})}hideInlineDiff(){if(this.inlineDiffInstance){try{this.inlineDiffInstance.dispose()}catch{}this.inlineDiffInstance=null}}showInlineChatWidget(){if(!this.editor||!this.monaco||!this.props.onInlineAsk)return;if(this.inlineChatWidgetInstance){this.inlineChatWidgetInstance.show();return}let e=this.editor,n=this.monaco,r=this.props.onInlineAsk,i=this.props.onAiAction;t(async()=>{let{InlineChatWidget:e}=await import(`./inlineChatWidget-NIvdRGmU.js`);return{InlineChatWidget:e}},__vite__mapDeps([11,10]),import.meta.url).then(({InlineChatWidget:t})=>{let a=new t(e,n,{onSubmit:async e=>r({question:e.question,selectedCode:e.selectedCode}),onEscalateToChat:e=>{i&&i({action:`ask`,code:e.selectedCode,question:e.question,rangeLabel:e.range?`lines ${e.range.startLineNumber}-${e.range.endLineNumber}`:`whole file`})}});this.inlineChatWidgetInstance=a,a.show()}).catch(()=>{})}registerAiActions(){if(!this.editor||!this.monaco||!this.props.onAiAction)return;let e=this.monaco,t=(t,n={})=>{if(!this.editor||!this.props.onAiAction)return;let r=this.editor.getModel();if(!r)return;let i=this.editor.getSelection(),a=i&&!i.isEmpty(),o,s,c,l=`selection`;if(a)o=r.getValueInRange(i),s=i.startLineNumber===i.endLineNumber?`line ${i.startLineNumber}`:`lines ${i.startLineNumber}-${i.endLineNumber}`,c={startLine:i.startLineNumber,startColumn:i.startColumn,endLine:i.endLineNumber,endColumn:i.endColumn},l=`selection`;else{let t=this.editor.getPosition(),n=null;if(t)try{n=y(r.getValue(),t.lineNumber)}catch{}if(n){let t=n.startLine,i=n.endLine,a=r.getLineMaxColumn(i),u=new e.Range(t,1,i,a);o=r.getValueInRange(u),s=t===i?`line ${t}`:`lines ${t}-${i}`,c={startLine:t,startColumn:1,endLine:i,endColumn:a},l=`codelens`}else o=r.getValue(),s=`whole file`,l=`none`}this.props.onAiAction({action:t,code:o,rangeLabel:s,range:c,kind:l,...n})},n=[{id:`iobroker.ai.inline`,label:`🤖 ${f.t(`AI: Inline chat…`)}`,keybindings:[e.KeyMod.CtrlCmd|e.KeyMod.Alt|e.KeyCode.KeyI],order:1,run:()=>{if(this.props.onInlineAsk)this.showInlineChatWidget();else{let e=window.prompt(f.t(`Ask the AI about the selected code:`));e&&e.trim()&&t(`ask`,{question:e.trim()})}}},{id:`iobroker.ai.explain`,label:`💡 ${f.t(`AI: Explain`)}`,keybindings:[e.KeyMod.CtrlCmd|e.KeyMod.Alt|e.KeyCode.KeyE],order:2,run:()=>t(`explain`)},{id:`iobroker.ai.refactor`,label:`🔧 ${f.t(`AI: Refactor`)}`,keybindings:[e.KeyMod.CtrlCmd|e.KeyMod.Alt|e.KeyCode.KeyR],order:3,run:()=>t(`refactor`)},{id:`iobroker.ai.comment`,label:`💬 ${f.t(`AI: Add comments`)}`,keybindings:[e.KeyMod.CtrlCmd|e.KeyMod.Alt|e.KeyCode.KeyC],order:4,run:()=>t(`comment`)},{id:`iobroker.ai.fix`,label:`🛠️ ${f.t(`AI: Fix problem`)}`,keybindings:[e.KeyMod.CtrlCmd|e.KeyMod.Alt|e.KeyCode.KeyF],order:5,run:()=>{let n;try{var r,i;let t=(r=this.editor)==null?void 0:r.getModel(),a=(i=this.editor)==null?void 0:i.getPosition();if(t&&a){let r=e.editor.getModelMarkers({resource:t.uri}).find(e=>a.lineNumber>=e.startLineNumber&&a.lineNumber<=e.endLineNumber);r&&(n=r.message)}}catch{}t(`fix`,{diagnostic:n})}},{id:`iobroker.ai.tests`,label:`✅ ${f.t(`AI: Suggest tests`)}`,order:6,run:()=>t(`tests`)}];for(let e of n)try{this.editor.addAction({id:e.id,label:e.label,contextMenuGroupId:`aichat`,contextMenuOrder:e.order,keybindings:e.keybindings,run:()=>e.run()})}catch{}}getEditorSelection(){if(!this.editor)return null;let e=this.editor.getSelection();if(!e||e.isEmpty())return null;let t=this.editor.getModel();return t?{text:t.getValueInRange(e),range:{startLine:e.startLineNumber,startColumn:e.startColumn,endLine:e.endLineNumber,endColumn:e.endColumn}}:null}getEditorContent(){var e;return((e=this.editor)==null||(e=e.getModel())==null?void 0:e.getValue())??``}getCursorPosition(){var e;let t=(e=this.editor)==null?void 0:e.getPosition();return t?{line:t.lineNumber,column:t.column}:null}highlightLineRange(e,t){if(!this.editor||!this.monaco)return!1;let n=this.editor.getModel();if(!n)return!1;let r=n.getLineCount(),i=Math.max(1,Math.min(e,r)),a=Math.max(i,Math.min(t,r)),o=n.getLineMaxColumn(a);return this.editor.setSelection(new this.monaco.Range(i,1,a,o)),this.editor.revealLineInCenter(i),!0}goToLine(e,t=1){if(!this.editor||!this.monaco)return!1;let n=this.editor.getModel();if(!n)return!1;let r=n.getLineCount(),i=Math.max(1,Math.min(e,r));return this.editor.setPosition({lineNumber:i,column:t}),this.editor.revealLineInCenter(i),this.editor.focus(),!0}replaceSelection(e){if(!this.editor||!this.monaco)return!1;let t=this.editor.getSelection();if(!t)return!1;let n=new this.monaco.Range(t.startLineNumber,t.startColumn,t.endLineNumber,t.endColumn);return this.editor.executeEdits(``,[{range:n,text:e,forceMoveMarkers:!0}]),this.editor.focus(),!0}getDiagnostics(){if(!this.editor||!this.monaco)return[];let e=this.editor.getModel();if(!e)return[];let t=this.monaco.editor.getModelMarkers({resource:e.uri}),n={8:`error`,4:`warning`,2:`info`,1:`hint`};return t.map(e=>({line:e.startLineNumber,column:e.startColumn,endLine:e.endLineNumber,endColumn:e.endColumn,severity:n[e.severity]||`info`,message:e.message,...e.source?{source:e.source}:{}}))}async getDocumentSymbols(){if(!this.editor||!this.monaco)return[];let e=this.editor.getModel();if(!e)return[];let t=[];try{var n;let r=this.monaco.languages,i=(n=r.getDocumentSymbolProviders)==null?void 0:n.call(r,e);if(i!=null&&i.length){let n={0:`file`,1:`module`,2:`namespace`,3:`package`,4:`class`,5:`method`,6:`property`,7:`field`,8:`constructor`,9:`enum`,10:`interface`,11:`function`,12:`variable`,13:`constant`,14:`string`,15:`number`,16:`boolean`,17:`array`,18:`object`,19:`key`,20:`null`,21:`enum-member`,22:`struct`,23:`event`,24:`operator`,25:`type-parameter`};for(let r of i){let i=await r.provideDocumentSymbols(e,{isCancellationRequested:!1});if(!i)continue;let a=e=>{for(let i of e){var r;t.push({name:i.name,kind:n[i.kind]||String(i.kind),line:i.range.startLineNumber,endLine:i.range.endLineNumber,...i.detail?{detail:i.detail}:{}}),(r=i.children)!=null&&r.length&&a(i.children)}};if(a(i),t.length)break}}}catch{}if(t.length===0){let n=e.getValue().split(`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./stateHoverProvider-BkW15VMN.js","./cronHoverProvider-BZMOFHO_.js","./AiInlineProvider-BxOW88xU.js","./AiChatService-Bsp_rhVx.js","./index-B0FfAYMN.js","./Import-XKVP-nRT.js","./Error-Ch2nx5uC.js","./blockly-fcfyKYzp.js","./index-CXaeqPRy.css","./inlineDiffController-Qh402KhK.js","./applyCodeEdit-D3nb7erO.js","./inlineChatWidget-NIvdRGmU.js"])))=>i.map(i=>d[i]);
2
+ import{r as e}from"./rolldown-runtime-C0FnF6B9.js";import{t}from"./vite-preload-helper-CaC3yEL3.js";import{$n as n,N as r,Nn as i,Qn as a,Ut as o,en as s,in as c,mn as l,nn as u,nr as d,p as f,sn as p,tn as m,wr as h,z as g,zn as _}from"./_virtual_mf___mfe_internal__iobroker_javascript__mf_owner__113183188387379__loadShare___mf_0_iobroker_mf_1_gui_mf_2_components__loadShare__.js-D-gi6Mty.js";import{d as v,p as y,u as b}from"./index-B0FfAYMN.js";var x=e({default:()=>T});h();function S(e){return/^script\.js\.global\./.test(e)}var C=0;function w(e){return e.replace(/\x1b\[[0-9;]*m/g,``)}var T=class extends d.Component{get monacoTS(){var e;return(e=this.monaco)==null||(e=e.languages)==null?void 0:e.typescript}constructor(e){super(e),_(this,`monacoDiv`,null),_(this,`editor`,null),_(this,`monaco`,window.monaco),_(this,`insert`,``),_(this,`originalCode`,void 0),_(this,`runningInstancesStr`,void 0),_(this,`monacoCounter`,0),_(this,`location`,void 0),_(this,`breakpoints`,void 0),_(this,`lastSearch`,``),_(this,`typings`,{}),_(this,`decorations`,[]),_(this,`datapointProviderDisposable`,null),_(this,`inlineProviderDisposable`,null),_(this,`stateHoverDisposable`,null),_(this,`showStateValueDisposable`,null),_(this,`cronHoverDisposable`,null),_(this,`codeLensDisposable`,null),_(this,`aiHelpersUnsubscribe`,null),_(this,`inlineChatWidgetInstance`,null),_(this,`inlineDiffInstance`,null),_(this,`inlineDiffCssInjected`,!1),_(this,`triggerPrettier`,void 0),_(this,`contentChangeDisposable`,null),_(this,`mouseDownDisposable`,null),this.state={name:`current`,isDark:e.isDark||!1,language:e.language||`javascript`,readOnly:e.readOnly||!1,alive:!0,check:!1,searchText:this.props.searchText||``,typingsLoaded:!1,showError:null},this.triggerPrettier=e.triggerPrettier,this.runningInstancesStr=JSON.stringify(this.props.runningInstances),this.originalCode=e.code||``,this.monacoDiv=d.createRef()}waitForMonaco(e){var t;let n=!!((t=this.monacoTS)!=null&&(t=t.typescriptDefaults)!=null&&t.getCompilerOptions);if(!n||!this.props.runningInstances){var r;if(this.monaco=window.monaco,n=!!((r=this.monacoTS)!=null&&(r=r.typescriptDefaults)!=null&&r.getCompilerOptions),this.monacoCounter++,!n&&this.monacoCounter<20){console.log(`wait for monaco loaded`),setTimeout(()=>this.waitForMonaco(e),200);return}this.monacoCounter>=20&&console.error(`Cannot load monaco!`)}else e&&e()}loadTypings(e){if(!this.editor)return;e||=this.props.runningInstances;let t=e&&Object.keys(e).find(t=>e==null?void 0:e[t]);t&&this.props.socket.sendTo(t.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;this.undo,this.redo,this.showInlineDiff,this.getEditorSelection,this.getEditorContent,this.getCursorPosition,this.highlightLineRange,this.goToLine,this.replaceSelection,this.getDiagnostics,this.getDocumentSymbols;let n=!!((e=this.monacoTS)!=null&&(e=e.typescriptDefaults)!=null&&e.getCompilerOptions);if(!n||!this.props.runningInstances){var r;if(this.monaco=window.monaco,n=!!((r=this.monacoTS)!=null&&(r=r.typescriptDefaults)!=null&&r.getCompilerOptions),!n){console.log(`wait for monaco loaded...`),this.waitForMonaco(()=>this.componentDidMount());return}}if(!this.editor&&n&&this.monaco){var i,a,o;console.log(`Init editor`),(i=(a=this.props).onRegisterSelect)==null||i.call(a,()=>{if(this.editor){let t=this.editor.getSelection();if(t){var e;return(e=this.editor.getModel())==null?void 0:e.getValueInRange(t)}}});let e=this.monacoTS.typescriptDefaults.getCompilerOptions();if(e.allowJs=!0,e.checkJs=this.props.checkJs!==!1,e.noLib=!0,e.lib=[],e.useUnknownInCatchVariables=!1,e.moduleResolution=this.monacoTS.ModuleResolutionKind.NodeJs,e.target=this.monacoTS.ScriptTarget.ESNext,e.module=this.monacoTS.ModuleKind.ESNext,e.allowNonTsExtensions=!0,this.monacoTS.typescriptDefaults.setCompilerOptions(e),this.setTypeCheck(!1),(o=this.monacoDiv)!=null&&o.current){var s;this.editor=this.monaco.editor.create((s=this.monacoDiv)==null?void 0:s.current,{lineNumbers:`on`,scrollBeyondLastLine:!1,automaticLayout:!0,glyphMargin:!!this.props.breakpoints,colorDecorators:!0,hover:{enabled:`on`,delay:200,sticky:!0},fixedOverflowWidgets:!0}),this.contentChangeDisposable=this.editor.onDidChangeModelContent(()=>this.onChange()),this.monaco&&!this.datapointProviderDisposable&&t(async()=>{let{registerDatapointProvider:e}=await import(`./AiDatapointProvider-DzFpUKkT.js`);return{registerDatapointProvider:e}},[],import.meta.url).then(({registerDatapointProvider:e})=>{this.monaco&&(this.datapointProviderDisposable=e(this.monaco,this.props.socket))}).catch(()=>{}),this.monaco&&!this.showStateValueDisposable&&t(async()=>{let{registerShowStateValueAction:e}=await import(`./stateHoverProvider-BkW15VMN.js`);return{registerShowStateValueAction:e}},__vite__mapDeps([0]),import.meta.url).then(({registerShowStateValueAction:e})=>{this.monaco&&this.editor&&!this.showStateValueDisposable&&(this.showStateValueDisposable=e(this.editor,this.monaco,f.t(`Show ioBroker state value`)))}).catch(()=>{}),this.registerAiHelpers(),this.aiHelpersUnsubscribe=v(e=>{e?this.registerAiHelpers():this.disposeAiHelpers()}),this.loadTypings(),this.props.onForceSave&&this.editor.addCommand(this.monaco.KeyMod.CtrlCmd|this.monaco.KeyCode.KeyS,()=>this.props.onForceSave&&this.props.onForceSave()),this.registerAiActions(),setTimeout(()=>{this.highlightText(this.state.searchText),this.location=this.props.location||void 0,this.breakpoints=this.props.breakpoints,this.showDecorators()})}}let c={selectOnLineNumbers:!0,scrollBeyondLastLine:!1,automaticLayout:!0,readOnly:this.state.readOnly,language:this.state.language,isDark:this.state.isDark};this.setEditorOptions(c),this.editor&&(this.editor.focus(),this.editor.setValue(this.originalCode),this.props.onToggleBreakpoint&&(this.mouseDownDisposable=this.editor.onMouseDown(e=>{var t;let n=e.target;this.props.onToggleBreakpoint&&((t=n.detail)==null?void 0:t.glyphMarginLeft)!==void 0&&n.position&&this.props.onToggleBreakpoint(n.position.lineNumber-1)})))}setEditorOptions(e){if(e&&(e.language&&this.setEditorLanguage(e.language),this.editor&&(e.readOnly!==void 0&&this.editor.updateOptions({readOnly:e.readOnly}),e.lineWrap!==void 0&&this.editor.updateOptions({wordWrap:e.lineWrap?`on`:`off`})),e.typeCheck!==void 0&&this.setTypeCheck(e.typeCheck),e.isDark!==void 0)){var t;(t=this.monaco)==null||t.editor.setTheme(e.isDark?`vs-dark`:`vs`)}}registerAiHelpers(){b()&&this.monaco&&this.editor&&(this.stateHoverDisposable||t(async()=>{let{registerStateHoverProvider:e}=await import(`./stateHoverProvider-BkW15VMN.js`);return{registerStateHoverProvider:e}},__vite__mapDeps([0]),import.meta.url).then(({registerStateHoverProvider:e})=>{this.monaco&&b()&&!this.stateHoverDisposable&&(this.stateHoverDisposable=e(this.monaco,this.props.socket))}).catch(()=>{}),this.cronHoverDisposable||t(async()=>{let{registerCronHoverProvider:e}=await import(`./cronHoverProvider-BZMOFHO_.js`);return{registerCronHoverProvider:e}},__vite__mapDeps([1]),import.meta.url).then(({registerCronHoverProvider:e})=>{this.monaco&&b()&&!this.cronHoverDisposable&&(this.cronHoverDisposable=e(this.monaco))}).catch(()=>{}),this.props.aiCompletionsEnabled&&!this.inlineProviderDisposable&&t(async()=>{let{registerAiInlineProvider:e}=await import(`./AiInlineProvider-BxOW88xU.js`);return{registerAiInlineProvider:e}},__vite__mapDeps([2,3]),import.meta.url).then(({registerAiInlineProvider:e})=>{this.monaco&&b()&&!this.inlineProviderDisposable&&(this.inlineProviderDisposable=e(this.monaco,this.props.socket,this.props.runningInstances))}).catch(()=>{}),this.props.onAiAction&&!this.codeLensDisposable&&t(async()=>{let{registerAiCodeLensProvider:e}=await import(`./index-B0FfAYMN.js`).then(e=>e.f);return{registerAiCodeLensProvider:e}},__vite__mapDeps([4,5,6,7,8]),import.meta.url).then(({registerAiCodeLensProvider:e})=>{this.monaco&&this.editor&&this.props.onAiAction&&b()&&!this.codeLensDisposable&&(this.codeLensDisposable=e(this.monaco,this.editor,(e,t,n,r,i)=>{var a,o,s;let c=(a=this.editor)==null?void 0:a.getModel(),l=c?c.getLineMaxColumn(Math.min(i,c.getLineCount())):1;(o=(s=this.props).onAiAction)==null||o.call(s,{action:e,code:t,rangeLabel:n,range:{startLine:r,startColumn:1,endLine:i,endColumn:l},kind:`codelens`})}))}).catch(()=>{}))}disposeAiHelpers(){var e,t,n,r;(e=this.stateHoverDisposable)==null||e.dispose(),this.stateHoverDisposable=null,(t=this.cronHoverDisposable)==null||t.dispose(),this.cronHoverDisposable=null,(n=this.inlineProviderDisposable)==null||n.dispose(),this.inlineProviderDisposable=null,(r=this.codeLensDisposable)==null||r.dispose(),this.codeLensDisposable=null}componentWillUnmount(){var e,n,r,i,a,o,s,c,l,u;if((e=this.contentChangeDisposable)==null||e.dispose(),this.contentChangeDisposable=null,(n=this.mouseDownDisposable)==null||n.dispose(),this.mouseDownDisposable=null,(r=this.datapointProviderDisposable)==null||r.dispose(),this.datapointProviderDisposable=null,t(async()=>{let{clearDatapointCache:e}=await import(`./AiDatapointProvider-DzFpUKkT.js`);return{clearDatapointCache:e}},[],import.meta.url).then(({clearDatapointCache:e})=>e()).catch(()=>{}),(i=this.inlineProviderDisposable)==null||i.dispose(),this.inlineProviderDisposable=null,(a=this.stateHoverDisposable)==null||a.dispose(),this.stateHoverDisposable=null,(o=this.showStateValueDisposable)==null||o.dispose(),this.showStateValueDisposable=null,t(async()=>{let{clearStateHoverCache:e}=await import(`./stateHoverProvider-BkW15VMN.js`);return{clearStateHoverCache:e}},__vite__mapDeps([0]),import.meta.url).then(({clearStateHoverCache:e})=>e()).catch(()=>{}),(s=this.cronHoverDisposable)==null||s.dispose(),this.cronHoverDisposable=null,(c=this.codeLensDisposable)==null||c.dispose(),this.codeLensDisposable=null,(l=this.aiHelpersUnsubscribe)==null||l.call(this),this.aiHelpersUnsubscribe=null,(u=this.inlineChatWidgetInstance)==null||u.dispose(),this.inlineChatWidgetInstance=null,this.hideInlineDiff(),this.editor){var d,f;(d=(f=this.props).onRegisterSelect)==null||d.call(f,null),this.editor.dispose(),this.editor=null}}async doPrettier(){var e;let t=this.props.runningInstances&&Object.keys(this.props.runningInstances).find(e=>{var t;return(t=this.props.runningInstances)==null?void 0:t[e]});if(!t){window.alert(f.t(`No script adapter instance found to format the code`));return}let n=await this.props.socket.sendTo(t.replace(`system.adapter.`,``),`prettier`,{code:(e=this.editor)==null?void 0:e.getValue(),type:this.state.language});if(n.error)this.setState({showError:{title:f.t(`Error formatting code`),message:w(n.error)}});else if(n.code){var r,i,a;(r=this.editor)==null||r.setValue(n.code),(i=(a=this.props).onChange)==null||i.call(a,n.code),this.showDecorators()}}setEditorLanguage(e){if(!this.editor)return;let t=this.editor.getModel();if(t){var n;let i=t.getValue(),a=t.uri.path,o=typeof a==`string`&&a.includes(`.`)?a.substring(0,a.lastIndexOf(`.`)):`index`,s=e===`javascript`?`js`:e===`typescript`?`ts`:e;t.dispose();let c=e===`javascript`||e===`typescript`?`typescript`:e,l=(n=this.monaco)==null?void 0:n.editor.createModel(i,c,this.monaco.Uri.from({scheme:window.location.protocol.replace(`:`,``),path:`${o}${C++}.${s}`}));if(l){var r;this.editor.setModel(l),(r=this.contentChangeDisposable)==null||r.dispose(),this.contentChangeDisposable=this.editor.onDidChangeModelContent(()=>this.onChange())}}}setTypeCheck(e){var t,n;let r={noSemanticValidation:!this.state.alive||!e,noSyntaxValidation:!this.state.alive};(t=this.monacoTS)==null||t.typescriptDefaults.setDiagnosticsOptions(r),(n=this.monacoTS)==null||n.javascriptDefaults.setDiagnosticsOptions({noSemanticValidation:!this.state.alive||!e,noSyntaxValidation:!this.state.alive})}setEditorTypings(e=``){var t,n;let r=S(e),i=`${e}.d.ts`,a=[];for(let e of Object.keys(this.typings))r&&(e===`global.d.ts`||e.startsWith(`script.js.global`)&&e!==i)||a.push({filePath:e,content:this.typings[e]});if((t=this.monacoTS)!=null&&(t=t.typescriptDefaults)!=null&&t.setExtraLibs)this.monacoTS.typescriptDefaults.setExtraLibs(a);else if((n=this.monacoTS)!=null&&(n=n.typescriptDefaults)!=null&&n.addExtraLib){let e=this.monacoTS.typescriptDefaults.getExtraLibs();a.forEach(t=>{!e[t.filePath]&&this.monaco&&this.monacoTS.typescriptDefaults.addExtraLib(t.content,t.filePath)})}}undo(){var e;(e=this.editor)==null||e.trigger(`toolbar`,`undo`,null)}redo(){var e;(e=this.editor)==null||e.trigger(`toolbar`,`redo`,null)}insertTextIntoEditor(e){if(!this.editor||!this.monaco)return;let t=this.editor.getSelection();if(t){let n=new this.monaco.Range(t.startLineNumber,t.startColumn,t.endLineNumber,t.endColumn);this.editor.executeEdits(``,[{range:n,text:e,forceMoveMarkers:!0}])}this.editor.focus()}highlightText(e){var t;if(!this.editor||!this.monaco)return 0;let n=e?(t=this.editor.getModel())==null?void 0:t.findMatches(e,!0,!1,!1,null,!0):void 0;if(n!=null&&n.length)return n.forEach(e=>{var t;return(t=this.editor)==null?void 0:t.setSelection(e.range)}),this.editor.revealLine(n[0].range.startLineNumber),n.length;let r=this.editor.getPosition();if(r){let e=r.lineNumber,t=r.column;this.editor.setSelection(new this.monaco.Range(e,t,e,t))}return 0}showInlineDiff(e){if(!this.editor||!this.monaco)return;let n=this.editor,r=this.monaco;this.hideInlineDiff(),t(async()=>{let{InlineDiffController:e,INLINE_DIFF_CSS:t}=await import(`./inlineDiffController-Qh402KhK.js`);return{InlineDiffController:e,INLINE_DIFF_CSS:t}},__vite__mapDeps([9,10]),import.meta.url).then(({InlineDiffController:t,INLINE_DIFF_CSS:i})=>{if(!this.inlineDiffCssInjected){let e=document.createElement(`style`);e.textContent=i,e.setAttribute(`data-iob-aichat`,`inline-diff`),document.head.appendChild(e),this.inlineDiffCssInjected=!0}let a=new t(n,r,{range:e.range,originalText:e.originalText,modifiedText:e.modifiedText,onAccepted:()=>{var t;this.inlineDiffInstance=null,(t=e.onAccepted)==null||t.call(e)},onRejected:()=>{var t;this.inlineDiffInstance=null,(t=e.onRejected)==null||t.call(e)}});this.inlineDiffInstance=a,a.show()}).catch(()=>{})}hideInlineDiff(){if(this.inlineDiffInstance){try{this.inlineDiffInstance.dispose()}catch{}this.inlineDiffInstance=null}}showInlineChatWidget(){if(!this.editor||!this.monaco||!this.props.onInlineAsk)return;if(this.inlineChatWidgetInstance){this.inlineChatWidgetInstance.show();return}let e=this.editor,n=this.monaco,r=this.props.onInlineAsk,i=this.props.onAiAction;t(async()=>{let{InlineChatWidget:e}=await import(`./inlineChatWidget-NIvdRGmU.js`);return{InlineChatWidget:e}},__vite__mapDeps([11,10]),import.meta.url).then(({InlineChatWidget:t})=>{let a=new t(e,n,{onSubmit:async e=>r({question:e.question,selectedCode:e.selectedCode}),onEscalateToChat:e=>{i&&i({action:`ask`,code:e.selectedCode,question:e.question,rangeLabel:e.range?`lines ${e.range.startLineNumber}-${e.range.endLineNumber}`:`whole file`})}});this.inlineChatWidgetInstance=a,a.show()}).catch(()=>{})}registerAiActions(){if(!this.editor||!this.monaco||!this.props.onAiAction)return;let e=this.monaco,t=(t,n={})=>{if(!this.editor||!this.props.onAiAction)return;let r=this.editor.getModel();if(!r)return;let i=this.editor.getSelection(),a=i&&!i.isEmpty(),o,s,c,l=`selection`;if(a)o=r.getValueInRange(i),s=i.startLineNumber===i.endLineNumber?`line ${i.startLineNumber}`:`lines ${i.startLineNumber}-${i.endLineNumber}`,c={startLine:i.startLineNumber,startColumn:i.startColumn,endLine:i.endLineNumber,endColumn:i.endColumn},l=`selection`;else{let t=this.editor.getPosition(),n=null;if(t)try{n=y(r.getValue(),t.lineNumber)}catch{}if(n){let t=n.startLine,i=n.endLine,a=r.getLineMaxColumn(i),u=new e.Range(t,1,i,a);o=r.getValueInRange(u),s=t===i?`line ${t}`:`lines ${t}-${i}`,c={startLine:t,startColumn:1,endLine:i,endColumn:a},l=`codelens`}else o=r.getValue(),s=`whole file`,l=`none`}this.props.onAiAction({action:t,code:o,rangeLabel:s,range:c,kind:l,...n})},n=[{id:`iobroker.ai.inline`,label:`🤖 ${f.t(`AI: Inline chat…`)}`,keybindings:[e.KeyMod.CtrlCmd|e.KeyMod.Alt|e.KeyCode.KeyI],order:1,run:()=>{if(this.props.onInlineAsk)this.showInlineChatWidget();else{let e=window.prompt(f.t(`Ask the AI about the selected code:`));e&&e.trim()&&t(`ask`,{question:e.trim()})}}},{id:`iobroker.ai.explain`,label:`💡 ${f.t(`AI: Explain`)}`,keybindings:[e.KeyMod.CtrlCmd|e.KeyMod.Alt|e.KeyCode.KeyE],order:2,run:()=>t(`explain`)},{id:`iobroker.ai.refactor`,label:`🔧 ${f.t(`AI: Refactor`)}`,keybindings:[e.KeyMod.CtrlCmd|e.KeyMod.Alt|e.KeyCode.KeyR],order:3,run:()=>t(`refactor`)},{id:`iobroker.ai.comment`,label:`💬 ${f.t(`AI: Add comments`)}`,keybindings:[e.KeyMod.CtrlCmd|e.KeyMod.Alt|e.KeyCode.KeyC],order:4,run:()=>t(`comment`)},{id:`iobroker.ai.fix`,label:`🛠️ ${f.t(`AI: Fix problem`)}`,keybindings:[e.KeyMod.CtrlCmd|e.KeyMod.Alt|e.KeyCode.KeyF],order:5,run:()=>{let n;try{var r,i;let t=(r=this.editor)==null?void 0:r.getModel(),a=(i=this.editor)==null?void 0:i.getPosition();if(t&&a){let r=e.editor.getModelMarkers({resource:t.uri}).find(e=>a.lineNumber>=e.startLineNumber&&a.lineNumber<=e.endLineNumber);r&&(n=r.message)}}catch{}t(`fix`,{diagnostic:n})}},{id:`iobroker.ai.tests`,label:`✅ ${f.t(`AI: Suggest tests`)}`,order:6,run:()=>t(`tests`)}];for(let e of n)try{this.editor.addAction({id:e.id,label:e.label,contextMenuGroupId:`aichat`,contextMenuOrder:e.order,keybindings:e.keybindings,run:()=>e.run()})}catch{}}getEditorSelection(){if(!this.editor)return null;let e=this.editor.getSelection();if(!e||e.isEmpty())return null;let t=this.editor.getModel();return t?{text:t.getValueInRange(e),range:{startLine:e.startLineNumber,startColumn:e.startColumn,endLine:e.endLineNumber,endColumn:e.endColumn}}:null}getEditorContent(){var e;return((e=this.editor)==null||(e=e.getModel())==null?void 0:e.getValue())??``}getCursorPosition(){var e;let t=(e=this.editor)==null?void 0:e.getPosition();return t?{line:t.lineNumber,column:t.column}:null}highlightLineRange(e,t){if(!this.editor||!this.monaco)return!1;let n=this.editor.getModel();if(!n)return!1;let r=n.getLineCount(),i=Math.max(1,Math.min(e,r)),a=Math.max(i,Math.min(t,r)),o=n.getLineMaxColumn(a);return this.editor.setSelection(new this.monaco.Range(i,1,a,o)),this.editor.revealLineInCenter(i),!0}goToLine(e,t=1){if(!this.editor||!this.monaco)return!1;let n=this.editor.getModel();if(!n)return!1;let r=n.getLineCount(),i=Math.max(1,Math.min(e,r));return this.editor.setPosition({lineNumber:i,column:t}),this.editor.revealLineInCenter(i),this.editor.focus(),!0}replaceSelection(e){if(!this.editor||!this.monaco)return!1;let t=this.editor.getSelection();if(!t)return!1;let n=new this.monaco.Range(t.startLineNumber,t.startColumn,t.endLineNumber,t.endColumn);return this.editor.executeEdits(``,[{range:n,text:e,forceMoveMarkers:!0}]),this.editor.focus(),!0}getDiagnostics(){if(!this.editor||!this.monaco)return[];let e=this.editor.getModel();if(!e)return[];let t=this.monaco.editor.getModelMarkers({resource:e.uri}),n={8:`error`,4:`warning`,2:`info`,1:`hint`};return t.map(e=>({line:e.startLineNumber,column:e.startColumn,endLine:e.endLineNumber,endColumn:e.endColumn,severity:n[e.severity]||`info`,message:e.message,...e.source?{source:e.source}:{}}))}async getDocumentSymbols(){if(!this.editor||!this.monaco)return[];let e=this.editor.getModel();if(!e)return[];let t=[];try{var n;let r=this.monaco.languages,i=(n=r.getDocumentSymbolProviders)==null?void 0:n.call(r,e);if(i!=null&&i.length){let n={0:`file`,1:`module`,2:`namespace`,3:`package`,4:`class`,5:`method`,6:`property`,7:`field`,8:`constructor`,9:`enum`,10:`interface`,11:`function`,12:`variable`,13:`constant`,14:`string`,15:`number`,16:`boolean`,17:`array`,18:`object`,19:`key`,20:`null`,21:`enum-member`,22:`struct`,23:`event`,24:`operator`,25:`type-parameter`};for(let r of i){let i=await r.provideDocumentSymbols(e,{isCancellationRequested:!1});if(!i)continue;let a=e=>{for(let i of e){var r;t.push({name:i.name,kind:n[i.kind]||String(i.kind),line:i.range.startLineNumber,endLine:i.range.endLineNumber,...i.detail?{detail:i.detail}:{}}),(r=i.children)!=null&&r.length&&a(i.children)}};if(a(i),t.length)break}}}catch{}if(t.length===0){let n=e.getValue().split(`
3
3
  `),r=[{re:/^(?:export\s+)?(?:async\s+)?function\s+(\w+)/,kind:`function`},{re:/^(?:export\s+)?class\s+(\w+)/,kind:`class`},{re:/^(?:export\s+)?(?:const|let|var)\s+(\w+)/,kind:`variable`}];for(let e=0;e<n.length;e++){let i=n[e].trim();for(let{re:n,kind:a}of r){let r=n.exec(i);if(r!=null&&r[1]){t.push({name:r[1],kind:a,line:e+1,endLine:e+1});break}}}}return t}showDecorators(){var e;let t=[];if(this.location&&this.monaco&&(t.push({range:new this.monaco.Range(this.location.lineNumber+1,(this.location.columnNumber||0)+1,this.location.lineNumber+1,1e3),options:{isWholeLine:!1,className:this.props.isDark?`monacoCurrentLineDark`:`monacoCurrentLine`}}),t.push({range:new this.monaco.Range(this.location.lineNumber+1,0,this.location.lineNumber+1,0),options:{isWholeLine:!0,className:this.props.isDark?`monacoCurrentFullLineDark`:`monacoCurrentFullLine`}})),(e=this.breakpoints)==null||e.forEach(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){let e=this.editor.getModel();e&&(this.decorations=e.deltaDecorations(this.decorations,t))}}initNewScript(e,t){var n;this.setState({name:e}),this.originalCode=t||``,(n=this.editor)==null||n.setValue(t||``),this.highlightText(this.lastSearch),this.showDecorators(),this.setEditorTypings(e)}scrollToLineIfNeeded(e){if(this.editor){let t=this.editor.getVisibleRanges();(!t||!t[0]||t[0].startLineNumber>e||e>t[0].endLineNumber)&&this.editor.revealLineInCenter(e)}}UNSAFE_componentWillReceiveProps(e){let n={};this.state.name!==e.name&&this.initNewScript(e.name,e.code),JSON.stringify(e.runningInstances)!==this.runningInstancesStr&&(this.runningInstancesStr=JSON.stringify(e.runningInstances),this.state.typingsLoaded||this.loadTypings(e.runningInstances)),this.editor&&!e.changed&&(e.code!==this.originalCode||e.code!==this.editor.getValue())&&(this.originalCode=e.code||``,this.editor.setValue(this.originalCode),this.showDecorators(),this.location&&this.scrollToLineIfNeeded(this.location.lineNumber+1)),e.searchText!==this.lastSearch&&(this.lastSearch=e.searchText||``,this.highlightText(this.lastSearch)),JSON.stringify(e.location)!==JSON.stringify(this.location)&&JSON.stringify(e.breakpoints)!==JSON.stringify(this.breakpoints)?(this.location=e.location||void 0,this.breakpoints=e.breakpoints,this.showDecorators(),this.editor&&this.location&&this.scrollToLineIfNeeded(this.location.lineNumber+1)):JSON.stringify(e.breakpoints)===JSON.stringify(this.breakpoints)?JSON.stringify(e.location)!==JSON.stringify(this.location)&&(this.location=e.location||void 0,this.showDecorators(),this.editor&&this.location&&this.scrollToLineIfNeeded(this.location.lineNumber+1)):(this.breakpoints=e.breakpoints,this.showDecorators()),this.state.language===(e.language||`javascript`)?this.state.readOnly===(e.readOnly||!1)?this.state.isDark!==(e.isDark||!1)&&(this.setState({isDark:e.isDark||!1}),n.isDark=e.isDark):(this.setState({readOnly:e.readOnly||!1}),n.readOnly=e.readOnly):(this.setState({language:e.language||`javascript`}),n.language=e.language||`javascript`),this.setEditorOptions(n),e.aiCompletionsEnabled!==this.props.aiCompletionsEnabled&&(e.aiCompletionsEnabled&&this.monaco&&b()?this.inlineProviderDisposable||t(async()=>{let{registerAiInlineProvider:e}=await import(`./AiInlineProvider-BxOW88xU.js`);return{registerAiInlineProvider:e}},__vite__mapDeps([2,3]),import.meta.url).then(({registerAiInlineProvider:e})=>{this.monaco&&b()&&!this.inlineProviderDisposable&&(this.inlineProviderDisposable=e(this.monaco,this.props.socket,this.props.runningInstances))}).catch(()=>{}):!e.aiCompletionsEnabled&&this.inlineProviderDisposable&&(this.inlineProviderDisposable.dispose(),this.inlineProviderDisposable=null)),this.insert!==e.insert&&(this.insert=e.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(){if(!this.props.readOnly&&this.editor){var e,t;(e=(t=this.props).onChange)==null||e.call(t,this.editor.getValue())}}renderErrorDialog(){return this.state.showError?this.state.showError.full?n(s,{open:!0,maxWidth:`md`,onClose:()=>this.setState({showError:null}),children:[a(c,{children:this.state.showError.title||f.t(`Error`)}),a(u,{children:a(`pre`,{children:a(`code`,{children:this.state.showError.message})})}),a(m,{children:n(o,{variant:`contained`,startIcon:a(r,{}),onClick:()=>this.setState({showError:null}),children:[f.t(`Close`),` `]})})]}):a(i,{open:!0,autoHideDuration:5e3,onClose:()=>this.setState({showError:null}),message:this.state.showError.title,action:n(d.Fragment,{children:[a(o,{color:`secondary`,size:`small`,onClick:()=>this.setState({showError:{...this.state.showError,full:!0}}),children:f.t(`More`)}),a(l,{size:`small`,"aria-label":`close`,color:`inherit`,onClick:()=>this.setState({showError:null}),children:a(r,{fontSize:`small`})})]})}):null}render(){var e;return!((e=this.monacoTS)!=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(e=>console.error(`Error formatting code:`,e)),50)),n(`div`,{ref:this.monacoDiv,style:{...this.props.style,width:`100%`,height:`100%`,overflow:`hidden`,position:`relative`},children:[this.renderErrorDialog(),!this.state.check&&a(p,{size:`small`,title:f.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:a(g,{})})]}))}};export{x as n,T as t};
@@ -0,0 +1 @@
1
+ import{t as e}from"./AiChatPanel-AZko1BsN.js";export{e as buildActionPrompt};
@@ -1 +1 @@
1
- import{i as e,o as t,r as n,t as r}from"./blockly-fcfyKYzp.js";import{c as i,l as a}from"./index-PLY-IJik.js";import{c as o,d as s,i as c,p as l,r as u,s as d}from"./helpers-D5PdK4BS.js";function f(){let f=window.Blockly,p=f.Translate,m=window.getHelp;f.CustomBlocks=f.CustomBlocks||[],f.CustomBlocks.push(`Action`),f.Action={HUE:330,blocks:{}};let h=()=>new n(`FALSE`,function(e){this.getSourceBlock().updateShape_(u(e))}),g=()=>[[p(`http_timeout_ms`),`ms`],[p(`http_timeout_sec`),`sec`]],_=()=>[[p(`http_type_text`),`text`],[p(`http_type_arraybuffer`),`arraybuffer`]],v=()=>[[p(`http_content_type_default`),`default`],[`application/json`,`application/json`],[`application/x-www-form-urlencoded`,`application/x-www-form-urlencoded`],[`text/plain`,`text/plain`],[`text/xml`,`text/xml`],[`application/xml`,`application/xml`],[p(`http_content_type_custom`),`custom`]],y={mutationToDom:function(){let e=document.createElement(`mutation`);return e.setAttribute(`with_statement`,String(u(this.getFieldValue(`WITH_STATEMENT`)))),e},domToMutation:function(e){this.updateShape_(u(e.getAttribute(`with_statement`)))},updateShape_:function(e){s(this,e)}},b=(t,n,o,s,c,u)=>{r[t]={init:function(){this.appendDummyInput().appendField(n),this.appendDummyInput(`ATTR`).appendField(new e(o),`ATTR`),this.setInputsInline(!0),this.setOutput(!0),this.setColour(f.Action.HUE),this.setTooltip(p(`${t}_tooltip`)),u&&this.setHelpUrl(m(u))},onchange:function(){l(this,s,c)},FUNCTION_TYPES:s},a.forBlock[t]=function(e){return[e.getFieldValue(`ATTR`),i.ATOMIC]}};f.Action.blocks.exec=`<block type="exec"> <mutation with_statement="false"></mutation> <field name="WITH_STATEMENT">FALSE</field> <field name="LOG"></field> <value name="COMMAND"> <shadow type="text"> <field name="TEXT">pwd</field> </shadow> </value></block>`,r.exec={init:function(){this.appendDummyInput(`TEXT`).appendField(`» ${p(`exec`)}`),this.appendValueInput(`COMMAND`).appendField(p(`exec_command`)),this.appendDummyInput(`WITH_STATEMENT`).appendField(p(`with_results`)).appendField(h(),`WITH_STATEMENT`),this.appendDummyInput(`LOG`).appendField(p(`loglevel`)).appendField(new e(c()),`LOG`),this.setInputsInline(!1),this.setPreviousStatement(!0,null),this.setNextStatement(!0,null),this.setColour(f.Action.HUE),this.setTooltip(p(`exec_tooltip`)),this.setHelpUrl(m(`exec_help`))},...y},a.forBlock.exec=function(e){let t=a.valueToCode(e,`COMMAND`,i.ATOMIC),n=e.getFieldValue(`LOG`),r=``;if(n&&(r=`console.${n}('exec: ' + ${t});\n`),u(e.getFieldValue(`WITH_STATEMENT`))){let n=a.statementToCode(e,`STATEMENT`);if(n)return`exec(${t}, async (error, result, stderr) => {\n${n}});\n${r}`}return`exec(${t});\n${r}`},f.Action.blocks.exec_result=`<sep gap="5"></sep><block type="exec_result"> <field name="ATTR">result</field></block>`,b(`exec_result`,`»`,[[p(`exec_result_result`),`result`],[p(`exec_result_stderr`),`stderr`],[p(`exec_result_error`),`error`]],[`exec`],`exec_result_warning`,`exec_help`),f.Action.blocks.http_get=`<block type="http_get"> <field name="TIMEOUT">2000</field> <field name="UNIT">ms</field> <field name="TYPE">text</field> <value name="URL"> <shadow type="text"> <field name="TEXT">http://</field> </shadow> </value></block>`,r.http_get={init:function(){this.appendValueInput(`URL`).appendField(`🌐 ${p(`http_get`)}`),this.appendDummyInput().appendField(p(`http_timeout`)).appendField(new t(`2000`),`TIMEOUT`).appendField(new e(g()),`UNIT`),this.appendDummyInput(`TYPE`).appendField(p(`http_type`)).appendField(new e(_()),`TYPE`),this.appendStatementInput(`STATEMENT`).setCheck(null),this.setInputsInline(!1),this.setPreviousStatement(!0,null),this.setNextStatement(!0,null),this.setColour(f.Action.HUE),this.setTooltip(p(`http_get_tooltip`)),this.setHelpUrl(m(`http_get_help`))}},a.forBlock.http_get=function(e){let t=a.valueToCode(e,`URL`,i.ATOMIC),n=e.getFieldValue(`UNIT`),r=e.getFieldValue(`TIMEOUT`);Number.isNaN(r)&&(r=2e3),n===`sec`&&(r*=1e3);let o=e.getFieldValue(`TYPE`)||`text`,s=a.statementToCode(e,`STATEMENT`);return`httpGet(${t}, { timeout: ${r}, responseType: '${o}' }, async (err, response) => {\n${s}});\n`},f.Action.blocks.http_post=`<sep gap="5"></sep><block type="http_post"> <field name="TIMEOUT">2000</field> <field name="UNIT">ms</field> <field name="TYPE">text</field> <field name="CONTENT_TYPE">default</field> <value name="URL"> <shadow type="text"> <field name="TEXT">http://</field> </shadow> </value> <value name="DATA"> <shadow type="logic_null"></shadow> </value></block>`,r.http_post={init:function(){this.appendValueInput(`URL`).appendField(`🌐 ${p(`http_post`)}`),this.appendDummyInput().appendField(p(`http_timeout`)).appendField(new t(`2000`),`TIMEOUT`).appendField(new e(g()),`UNIT`),this.appendDummyInput(`TYPE`).appendField(p(`http_type`)).appendField(new e(_()),`TYPE`),this.appendDummyInput(`CONTENT_TYPE`).appendField(p(`http_content_type`)).appendField(new e(v(),function(e){this.getSourceBlock().updateContentTypeShape_(e===`custom`)}),`CONTENT_TYPE`),this.appendValueInput(`DATA`).appendField(p(`http_post_data`)),this.appendStatementInput(`STATEMENT`).setCheck(null),this.setInputsInline(!1),this.setPreviousStatement(!0,null),this.setNextStatement(!0,null),this.setColour(f.Action.HUE),this.setTooltip(p(`http_post_tooltip`)),this.setHelpUrl(m(`http_post_help`))},mutationToDom:function(){let e=document.createElement(`mutation`);return e.setAttribute(`custom_content_type`,String(this.getFieldValue(`CONTENT_TYPE`)===`custom`)),e},domToMutation:function(e){this.updateContentTypeShape_(u(e.getAttribute(`custom_content_type`)))},updateContentTypeShape_:function(e){e?this.getInput(`CONTENT_TYPE_CUSTOM`)||(this.appendDummyInput(`CONTENT_TYPE_CUSTOM`).appendField(` `).appendField(new t(`application/json`),`CONTENT_TYPE_CUSTOM`),this.moveInputBefore(`CONTENT_TYPE_CUSTOM`,`DATA`)):this.getInput(`CONTENT_TYPE_CUSTOM`)&&this.removeInput(`CONTENT_TYPE_CUSTOM`)}},a.forBlock.http_post=function(e){let t=a.valueToCode(e,`URL`,i.ATOMIC),n=e.getFieldValue(`UNIT`),r=e.getFieldValue(`TIMEOUT`);isNaN(r)&&(r=2e3),n===`sec`&&(r*=1e3);let s=e.getFieldValue(`TYPE`)||`text`,c=a.valueToCode(e,`DATA`,i.ATOMIC)||`null`,l=a.statementToCode(e,`STATEMENT`),u=e.getFieldValue(`CONTENT_TYPE`)||`default`,d=u===`custom`?(e.getFieldValue(`CONTENT_TYPE_CUSTOM`)||``).trim():u,f=d&&d!=="default"?`, headers: { 'Content-Type': ${o(d)} }`:``;return`httpPost(${t}, ${c}, { timeout: ${r}, responseType: '${s}'${f} }, async (err, response) => {\n${l}});\n`},f.Action.blocks.http_response=`<sep gap="5"></sep><block type="http_response"> <field name="ATTR">response.data</field></block>`,b(`http_response`,`🌐`,[[p(`http_response_data`),`response.data`],[p(`http_response_statuscode`),`response.statusCode`],[p(`http_response_responsetime`),`response.responseTime`],[p(`http_response_headers`),`response.headers`],[p(`http_response_error`),`err`]],[`http_get`,`http_post`],`http_response_warning`,`http_response_help`),f.Action.blocks.http_response_tofile=`<sep gap="5"></sep><block type="http_response_tofile"> <value name="FILENAME"> <shadow type="text"> <field name="TEXT">temp.jpg</field> </shadow> </value></block>`,r.http_response_tofile={init:function(){this.appendDummyInput().appendField(`🌐 ${p(`http_response_tofile`)}`),this.appendValueInput(`FILENAME`).appendField(p(`http_response_tofile_filename`)).setCheck(null),this.setInputsInline(!1),this.setOutput(!0,`String`),this.setColour(f.Action.HUE),this.setTooltip(p(`http_response_tofile_tooltip`)),this.setHelpUrl(m(`http_response_tofile_help`))},onchange:function(){l(this,[`http_get`,`http_post`],`http_response_warning`)},FUNCTION_TYPES:[`http_get`,`http_post`]},a.forBlock.http_response_tofile=function(e){return[`createTempFile(${a.valueToCode(e,`FILENAME`,i.ATOMIC)}, response.data)`,i.ATOMIC]};let x=()=>`${a.prefixLines(`if (err) {`,a.INDENT)}\n${a.prefixLines(`console.error(err);`,a.INDENT+a.INDENT)}\n${a.prefixLines(`}`,a.INDENT)}\n`;f.Action.blocks.file_write=`<block type="file_write"> <value name="OID"> <shadow type="field_oid_meta"> <field name="oid">0_userdata.0</field> </shadow> </value> <value name="FILE"> <shadow type="text"> <field name="TEXT">demo.json</field> </shadow> </value></block>`,r.file_write={init:function(){this.appendValueInput(`OID`).appendField(`📁 ${p(`file_write`)}`),this.appendValueInput(`FILE`).appendField(p(`file_write_filename`)).setCheck(null),this.appendValueInput(`DATA`).appendField(p(`file_write_data`)),this.setInputsInline(!1),this.setPreviousStatement(!0,null),this.setNextStatement(!0,null),this.setColour(f.Action.HUE),this.setTooltip(p(`file_write_tooltip`)),this.setHelpUrl(m(`file_write_help`))}},a.forBlock.file_write=function(e){let t=a.valueToCode(e,`OID`,i.ATOMIC),n=a.valueToCode(e,`FILE`,i.ATOMIC),r=a.valueToCode(e,`DATA`,i.ATOMIC),o=d(t);return`writeFile(${t}${o?` /* ${o} */`:``}, String(${n}), ${r||`null`}, (err) => {\n${x()}});\n`},f.Action.blocks.file_read=`<sep gap="5"></sep><block type="file_read"> <value name="OID"> <shadow type="field_oid_meta"> <field name="oid">0_userdata.0</field> </shadow> </value> <value name="FILE"> <shadow type="text"> <field name="TEXT">demo.json</field> </shadow> </value></block>`,r.file_read={init:function(){this.appendValueInput(`OID`).appendField(`📁 ${p(`file_read`)}`),this.appendValueInput(`FILE`).appendField(p(`file_read_filename`)).setCheck(null),this.appendStatementInput(`STATEMENT`).setCheck(null),this.setInputsInline(!1),this.setPreviousStatement(!0,null),this.setNextStatement(!0,null),this.setColour(f.Action.HUE),this.setTooltip(p(`file_read_tooltip`)),this.setHelpUrl(m(`file_read_help`))}},a.forBlock.file_read=function(e){let t=a.valueToCode(e,`OID`,i.ATOMIC),n=a.valueToCode(e,`FILE`,i.ATOMIC),r=a.statementToCode(e,`STATEMENT`),o=d(t);return`readFile(${t}${o?` /* ${o} */`:``}, String(${n}), (err, data, mimeType) => {\n${x()}${r}});\n`},f.Action.blocks.file_data=`<sep gap="5"></sep><block type="file_data"> <field name="ATTR">data</field></block>`,b(`file_data`,`📁`,[[p(`file_data_data`),`data`],[p(`file_data_mimeType`),`mimeType`]],[`file_read`],`file_data_warning`),f.Action.blocks.request=`<block type="request"> <mutation with_statement="false"></mutation> <field name="WITH_STATEMENT">FALSE</field> <field name="LOG"></field> <value name="URL"> <shadow type="text"> <field name="TEXT">http://</field> </shadow> </value></block>`,r.request={init:function(){this.appendDummyInput(`TEXT`).appendField(p(`request`)),this.appendValueInput(`URL`).appendField(p(`request_url`)),this.appendDummyInput(`WITH_STATEMENT`).appendField(p(`with_results`)).appendField(h(),`WITH_STATEMENT`),this.appendDummyInput(`LOG`).appendField(p(`loglevel`)).appendField(new e(c()),`LOG`),this.setInputsInline(!1),this.setPreviousStatement(!0,null),this.setNextStatement(!0,null),this.setColour(f.Action.HUE),this.setTooltip(p(`request_tooltip`)),this.setHelpUrl(p(`request_help`))},...y},a.forBlock.request=function(e){let t=a.valueToCode(e,`URL`,i.ATOMIC),n=e.getFieldValue(`LOG`),r=``;if(n&&(r=`console.${n}('request: ' + ${t});\n`),u(e.getFieldValue(`WITH_STATEMENT`))){let n=a.statementToCode(e,`STATEMENT`);if(n)return`try {\n require("request")(${t}, async (error, response, result) => {\n ${n} }).on("error", (e) => { console.error(e); });\n} catch (e) { console.error(e); }\n${r}`}return`try {\n require("request")(${t}).on("error", (e) => { console.error(e); });\n} catch (e) { console.error(e); }\n${r}`}}export{f as install};
1
+ import{i as e,o as t,r as n,t as r}from"./blockly-fcfyKYzp.js";import{c as i,l as a}from"./index-B0FfAYMN.js";import{c as o,d as s,i as c,p as l,r as u,s as d}from"./helpers-DiwtLpXM.js";function f(){let f=window.Blockly,p=f.Translate,m=window.getHelp;f.CustomBlocks=f.CustomBlocks||[],f.CustomBlocks.push(`Action`),f.Action={HUE:330,blocks:{}};let h=()=>new n(`FALSE`,function(e){this.getSourceBlock().updateShape_(u(e))}),g=()=>[[p(`http_timeout_ms`),`ms`],[p(`http_timeout_sec`),`sec`]],_=()=>[[p(`http_type_text`),`text`],[p(`http_type_arraybuffer`),`arraybuffer`]],v=()=>[[p(`http_content_type_default`),`default`],[`application/json`,`application/json`],[`application/x-www-form-urlencoded`,`application/x-www-form-urlencoded`],[`text/plain`,`text/plain`],[`text/xml`,`text/xml`],[`application/xml`,`application/xml`],[p(`http_content_type_custom`),`custom`]],y={mutationToDom:function(){let e=document.createElement(`mutation`);return e.setAttribute(`with_statement`,String(u(this.getFieldValue(`WITH_STATEMENT`)))),e},domToMutation:function(e){this.updateShape_(u(e.getAttribute(`with_statement`)))},updateShape_:function(e){s(this,e)}},b=(t,n,o,s,c,u)=>{r[t]={init:function(){this.appendDummyInput().appendField(n),this.appendDummyInput(`ATTR`).appendField(new e(o),`ATTR`),this.setInputsInline(!0),this.setOutput(!0),this.setColour(f.Action.HUE),this.setTooltip(p(`${t}_tooltip`)),u&&this.setHelpUrl(m(u))},onchange:function(){l(this,s,c)},FUNCTION_TYPES:s},a.forBlock[t]=function(e){return[e.getFieldValue(`ATTR`),i.ATOMIC]}};f.Action.blocks.exec=`<block type="exec"> <mutation with_statement="false"></mutation> <field name="WITH_STATEMENT">FALSE</field> <field name="LOG"></field> <value name="COMMAND"> <shadow type="text"> <field name="TEXT">pwd</field> </shadow> </value></block>`,r.exec={init:function(){this.appendDummyInput(`TEXT`).appendField(`» ${p(`exec`)}`),this.appendValueInput(`COMMAND`).appendField(p(`exec_command`)),this.appendDummyInput(`WITH_STATEMENT`).appendField(p(`with_results`)).appendField(h(),`WITH_STATEMENT`),this.appendDummyInput(`LOG`).appendField(p(`loglevel`)).appendField(new e(c()),`LOG`),this.setInputsInline(!1),this.setPreviousStatement(!0,null),this.setNextStatement(!0,null),this.setColour(f.Action.HUE),this.setTooltip(p(`exec_tooltip`)),this.setHelpUrl(m(`exec_help`))},...y},a.forBlock.exec=function(e){let t=a.valueToCode(e,`COMMAND`,i.ATOMIC),n=e.getFieldValue(`LOG`),r=``;if(n&&(r=`console.${n}('exec: ' + ${t});\n`),u(e.getFieldValue(`WITH_STATEMENT`))){let n=a.statementToCode(e,`STATEMENT`);if(n)return`exec(${t}, async (error, result, stderr) => {\n${n}});\n${r}`}return`exec(${t});\n${r}`},f.Action.blocks.exec_result=`<sep gap="5"></sep><block type="exec_result"> <field name="ATTR">result</field></block>`,b(`exec_result`,`»`,[[p(`exec_result_result`),`result`],[p(`exec_result_stderr`),`stderr`],[p(`exec_result_error`),`error`]],[`exec`],`exec_result_warning`,`exec_help`),f.Action.blocks.http_get=`<block type="http_get"> <field name="TIMEOUT">2000</field> <field name="UNIT">ms</field> <field name="TYPE">text</field> <value name="URL"> <shadow type="text"> <field name="TEXT">http://</field> </shadow> </value></block>`,r.http_get={init:function(){this.appendValueInput(`URL`).appendField(`🌐 ${p(`http_get`)}`),this.appendDummyInput().appendField(p(`http_timeout`)).appendField(new t(`2000`),`TIMEOUT`).appendField(new e(g()),`UNIT`),this.appendDummyInput(`TYPE`).appendField(p(`http_type`)).appendField(new e(_()),`TYPE`),this.appendStatementInput(`STATEMENT`).setCheck(null),this.setInputsInline(!1),this.setPreviousStatement(!0,null),this.setNextStatement(!0,null),this.setColour(f.Action.HUE),this.setTooltip(p(`http_get_tooltip`)),this.setHelpUrl(m(`http_get_help`))}},a.forBlock.http_get=function(e){let t=a.valueToCode(e,`URL`,i.ATOMIC),n=e.getFieldValue(`UNIT`),r=e.getFieldValue(`TIMEOUT`);Number.isNaN(r)&&(r=2e3),n===`sec`&&(r*=1e3);let o=e.getFieldValue(`TYPE`)||`text`,s=a.statementToCode(e,`STATEMENT`);return`httpGet(${t}, { timeout: ${r}, responseType: '${o}' }, async (err, response) => {\n${s}});\n`},f.Action.blocks.http_post=`<sep gap="5"></sep><block type="http_post"> <field name="TIMEOUT">2000</field> <field name="UNIT">ms</field> <field name="TYPE">text</field> <field name="CONTENT_TYPE">default</field> <value name="URL"> <shadow type="text"> <field name="TEXT">http://</field> </shadow> </value> <value name="DATA"> <shadow type="logic_null"></shadow> </value></block>`,r.http_post={init:function(){this.appendValueInput(`URL`).appendField(`🌐 ${p(`http_post`)}`),this.appendDummyInput().appendField(p(`http_timeout`)).appendField(new t(`2000`),`TIMEOUT`).appendField(new e(g()),`UNIT`),this.appendDummyInput(`TYPE`).appendField(p(`http_type`)).appendField(new e(_()),`TYPE`),this.appendDummyInput(`CONTENT_TYPE`).appendField(p(`http_content_type`)).appendField(new e(v(),function(e){this.getSourceBlock().updateContentTypeShape_(e===`custom`)}),`CONTENT_TYPE`),this.appendValueInput(`DATA`).appendField(p(`http_post_data`)),this.appendStatementInput(`STATEMENT`).setCheck(null),this.setInputsInline(!1),this.setPreviousStatement(!0,null),this.setNextStatement(!0,null),this.setColour(f.Action.HUE),this.setTooltip(p(`http_post_tooltip`)),this.setHelpUrl(m(`http_post_help`))},mutationToDom:function(){let e=document.createElement(`mutation`);return e.setAttribute(`custom_content_type`,String(this.getFieldValue(`CONTENT_TYPE`)===`custom`)),e},domToMutation:function(e){this.updateContentTypeShape_(u(e.getAttribute(`custom_content_type`)))},updateContentTypeShape_:function(e){e?this.getInput(`CONTENT_TYPE_CUSTOM`)||(this.appendDummyInput(`CONTENT_TYPE_CUSTOM`).appendField(` `).appendField(new t(`application/json`),`CONTENT_TYPE_CUSTOM`),this.moveInputBefore(`CONTENT_TYPE_CUSTOM`,`DATA`)):this.getInput(`CONTENT_TYPE_CUSTOM`)&&this.removeInput(`CONTENT_TYPE_CUSTOM`)}},a.forBlock.http_post=function(e){let t=a.valueToCode(e,`URL`,i.ATOMIC),n=e.getFieldValue(`UNIT`),r=e.getFieldValue(`TIMEOUT`);isNaN(r)&&(r=2e3),n===`sec`&&(r*=1e3);let s=e.getFieldValue(`TYPE`)||`text`,c=a.valueToCode(e,`DATA`,i.ATOMIC)||`null`,l=a.statementToCode(e,`STATEMENT`),u=e.getFieldValue(`CONTENT_TYPE`)||`default`,d=u===`custom`?(e.getFieldValue(`CONTENT_TYPE_CUSTOM`)||``).trim():u,f=d&&d!=="default"?`, headers: { 'Content-Type': ${o(d)} }`:``;return`httpPost(${t}, ${c}, { timeout: ${r}, responseType: '${s}'${f} }, async (err, response) => {\n${l}});\n`},f.Action.blocks.http_response=`<sep gap="5"></sep><block type="http_response"> <field name="ATTR">response.data</field></block>`,b(`http_response`,`🌐`,[[p(`http_response_data`),`response.data`],[p(`http_response_statuscode`),`response.statusCode`],[p(`http_response_responsetime`),`response.responseTime`],[p(`http_response_headers`),`response.headers`],[p(`http_response_error`),`err`]],[`http_get`,`http_post`],`http_response_warning`,`http_response_help`),f.Action.blocks.http_response_tofile=`<sep gap="5"></sep><block type="http_response_tofile"> <value name="FILENAME"> <shadow type="text"> <field name="TEXT">temp.jpg</field> </shadow> </value></block>`,r.http_response_tofile={init:function(){this.appendDummyInput().appendField(`🌐 ${p(`http_response_tofile`)}`),this.appendValueInput(`FILENAME`).appendField(p(`http_response_tofile_filename`)).setCheck(null),this.setInputsInline(!1),this.setOutput(!0,`String`),this.setColour(f.Action.HUE),this.setTooltip(p(`http_response_tofile_tooltip`)),this.setHelpUrl(m(`http_response_tofile_help`))},onchange:function(){l(this,[`http_get`,`http_post`],`http_response_warning`)},FUNCTION_TYPES:[`http_get`,`http_post`]},a.forBlock.http_response_tofile=function(e){return[`createTempFile(${a.valueToCode(e,`FILENAME`,i.ATOMIC)}, response.data)`,i.ATOMIC]};let x=()=>`${a.prefixLines(`if (err) {`,a.INDENT)}\n${a.prefixLines(`console.error(err);`,a.INDENT+a.INDENT)}\n${a.prefixLines(`}`,a.INDENT)}\n`;f.Action.blocks.file_write=`<block type="file_write"> <value name="OID"> <shadow type="field_oid_meta"> <field name="oid">0_userdata.0</field> </shadow> </value> <value name="FILE"> <shadow type="text"> <field name="TEXT">demo.json</field> </shadow> </value></block>`,r.file_write={init:function(){this.appendValueInput(`OID`).appendField(`📁 ${p(`file_write`)}`),this.appendValueInput(`FILE`).appendField(p(`file_write_filename`)).setCheck(null),this.appendValueInput(`DATA`).appendField(p(`file_write_data`)),this.setInputsInline(!1),this.setPreviousStatement(!0,null),this.setNextStatement(!0,null),this.setColour(f.Action.HUE),this.setTooltip(p(`file_write_tooltip`)),this.setHelpUrl(m(`file_write_help`))}},a.forBlock.file_write=function(e){let t=a.valueToCode(e,`OID`,i.ATOMIC),n=a.valueToCode(e,`FILE`,i.ATOMIC),r=a.valueToCode(e,`DATA`,i.ATOMIC),o=d(t);return`writeFile(${t}${o?` /* ${o} */`:``}, String(${n}), ${r||`null`}, (err) => {\n${x()}});\n`},f.Action.blocks.file_read=`<sep gap="5"></sep><block type="file_read"> <value name="OID"> <shadow type="field_oid_meta"> <field name="oid">0_userdata.0</field> </shadow> </value> <value name="FILE"> <shadow type="text"> <field name="TEXT">demo.json</field> </shadow> </value></block>`,r.file_read={init:function(){this.appendValueInput(`OID`).appendField(`📁 ${p(`file_read`)}`),this.appendValueInput(`FILE`).appendField(p(`file_read_filename`)).setCheck(null),this.appendStatementInput(`STATEMENT`).setCheck(null),this.setInputsInline(!1),this.setPreviousStatement(!0,null),this.setNextStatement(!0,null),this.setColour(f.Action.HUE),this.setTooltip(p(`file_read_tooltip`)),this.setHelpUrl(m(`file_read_help`))}},a.forBlock.file_read=function(e){let t=a.valueToCode(e,`OID`,i.ATOMIC),n=a.valueToCode(e,`FILE`,i.ATOMIC),r=a.statementToCode(e,`STATEMENT`),o=d(t);return`readFile(${t}${o?` /* ${o} */`:``}, String(${n}), (err, data, mimeType) => {\n${x()}${r}});\n`},f.Action.blocks.file_data=`<sep gap="5"></sep><block type="file_data"> <field name="ATTR">data</field></block>`,b(`file_data`,`📁`,[[p(`file_data_data`),`data`],[p(`file_data_mimeType`),`mimeType`]],[`file_read`],`file_data_warning`),f.Action.blocks.request=`<block type="request"> <mutation with_statement="false"></mutation> <field name="WITH_STATEMENT">FALSE</field> <field name="LOG"></field> <value name="URL"> <shadow type="text"> <field name="TEXT">http://</field> </shadow> </value></block>`,r.request={init:function(){this.appendDummyInput(`TEXT`).appendField(p(`request`)),this.appendValueInput(`URL`).appendField(p(`request_url`)),this.appendDummyInput(`WITH_STATEMENT`).appendField(p(`with_results`)).appendField(h(),`WITH_STATEMENT`),this.appendDummyInput(`LOG`).appendField(p(`loglevel`)).appendField(new e(c()),`LOG`),this.setInputsInline(!1),this.setPreviousStatement(!0,null),this.setNextStatement(!0,null),this.setColour(f.Action.HUE),this.setTooltip(p(`request_tooltip`)),this.setHelpUrl(p(`request_help`))},...y},a.forBlock.request=function(e){let t=a.valueToCode(e,`URL`,i.ATOMIC),n=e.getFieldValue(`LOG`),r=``;if(n&&(r=`console.${n}('request: ' + ${t});\n`),u(e.getFieldValue(`WITH_STATEMENT`))){let n=a.statementToCode(e,`STATEMENT`);if(n)return`try {\n require("request")(${t}, async (error, response, result) => {\n ${n} }).on("error", (e) => { console.error(e); });\n} catch (e) { console.error(e); }\n${r}`}return`try {\n require("request")(${t}).on("error", (e) => { console.error(e); });\n} catch (e) { console.error(e); }\n${r}`}}export{f as install};
@@ -1,3 +1,3 @@
1
- import{i as e,o as t,r as n,t as r}from"./blockly-fcfyKYzp.js";import{c as i,l as a}from"./index-PLY-IJik.js";import{c as o,n as s,t as c}from"./helpers-D5PdK4BS.js";function l(){let l=window.Blockly,u=l.Translate;l.CustomBlocks=l.CustomBlocks||[],l.CustomBlocks.push(`Convert`),l.Convert={HUE:280,blocks:{}},l.Convert.blocks.convert_tonumber=`<block type="convert_tonumber"></block>`,r.convert_tonumber={init:function(){this.appendValueInput(`VALUE`).appendField(u(`convert_tonumber`)),this.setOutput(!0,`Number`),this.setColour(l.Convert.HUE),this.setTooltip(u(`convert_tonumber_tooltip`))}},a.forBlock.convert_tonumber=function(e){return[`parseFloat(${a.valueToCode(e,`VALUE`,i.ATOMIC)})`,i.ATOMIC]},l.Convert.blocks.convert_toboolean=`<block type="convert_toboolean"></block>`,r.convert_toboolean={init:function(){this.appendValueInput(`VALUE`).appendField(u(`convert_toboolean`)),this.setOutput(!0,`Boolean`),this.setColour(l.Convert.HUE),this.setTooltip(u(`convert_toboolean_tooltip`))}},a.forBlock.convert_toboolean=function(e){return[`(() => {
1
+ import{i as e,o as t,r as n,t as r}from"./blockly-fcfyKYzp.js";import{c as i,l as a}from"./index-B0FfAYMN.js";import{c as o,n as s,t as c}from"./helpers-DiwtLpXM.js";function l(){let l=window.Blockly,u=l.Translate;l.CustomBlocks=l.CustomBlocks||[],l.CustomBlocks.push(`Convert`),l.Convert={HUE:280,blocks:{}},l.Convert.blocks.convert_tonumber=`<block type="convert_tonumber"></block>`,r.convert_tonumber={init:function(){this.appendValueInput(`VALUE`).appendField(u(`convert_tonumber`)),this.setOutput(!0,`Number`),this.setColour(l.Convert.HUE),this.setTooltip(u(`convert_tonumber_tooltip`))}},a.forBlock.convert_tonumber=function(e){return[`parseFloat(${a.valueToCode(e,`VALUE`,i.ATOMIC)})`,i.ATOMIC]},l.Convert.blocks.convert_toboolean=`<block type="convert_toboolean"></block>`,r.convert_toboolean={init:function(){this.appendValueInput(`VALUE`).appendField(u(`convert_toboolean`)),this.setOutput(!0,`Boolean`),this.setColour(l.Convert.HUE),this.setTooltip(u(`convert_toboolean_tooltip`))}},a.forBlock.convert_toboolean=function(e){return[`(() => {
2
2
  const val = ${a.valueToCode(e,`VALUE`,i.ATOMIC)};\n if (val === 'true' || val === 'TRUE') return true;\n if (val === 'false' || val === 'FALSE') return false;\n return !!val;
3
3
  })()`,i.ATOMIC]},l.Convert.blocks.convert_tostring=`<block type="convert_tostring"></block>`,r.convert_tostring={init:function(){this.appendValueInput(`VALUE`).appendField(u(`convert_tostring`)),this.setOutput(!0,`String`),this.setColour(l.Convert.HUE),this.setTooltip(u(`convert_tostring_tooltip`))}},a.forBlock.convert_tostring=function(e){return[`('' + ${a.valueToCode(e,`VALUE`,i.ATOMIC)})`,i.ATOMIC]},l.Convert.blocks.convert_type=`<block type="convert_type"></block>`,r.convert_type={init:function(){this.appendValueInput(`ITEM`).appendField(u(`convert_type`)),this.setOutput(!0,`String`),this.setColour(l.Convert.HUE),this.setTooltip(u(`convert_type_tooltip`))}},a.forBlock.convert_type=function(e){return[`typeof ${a.valueToCode(e,`ITEM`,i.ATOMIC)}`,i.ATOMIC]},l.Convert.blocks.convert_to_date=`<block type="convert_to_date"></block>`,r.convert_to_date={init:function(){this.appendValueInput(`VALUE`).appendField(u(`convert_to_date`)),this.setOutput(!0,`Date`),this.setColour(l.Convert.HUE),this.setTooltip(u(`convert_to_date_tooltip`))}},a.forBlock.convert_to_date=function(e){return[`getDateObject(${a.valueToCode(e,`VALUE`,i.ATOMIC)}).getTime()`,i.ATOMIC]},l.Convert.blocks.convert_from_date=`<block type="convert_from_date"> <mutation format="false" language="false"></mutation> <field name="OPTION">object</field></block>`,r.convert_from_date={init:function(){this.appendValueInput(`VALUE`).appendField(u(`convert_from_date`)),this.appendDummyInput(`OPTION`).appendField(u(`convert_to`)).appendField(new e(c(),function(e){this.getSourceBlock().updateShape_(e===`custom`,e===`wdts`||e===`wdt`||e===`Mt`||e===`Mts`)}),`OPTION`),this.setInputsInline(!0),this.setOutput(!0),this.setColour(l.Convert.HUE),this.setTooltip(u(`convert_from_date_tooltip`))},mutationToDom:function(){let e=document.createElement(`mutation`),t=this.getFieldValue(`OPTION`);return e.setAttribute(`format`,t===`custom`?`true`:`false`),e.setAttribute(`language`,t===`wdt`||t===`wdts`||t===`Mt`||t===`Mts`?`true`:`false`),e},domToMutation:function(e){let t=e.getAttribute(`format`),n=e.getAttribute(`language`);this.updateShape_(t===`true`||t===`TRUE`,n===`true`||n===`TRUE`)},updateShape_:function(n,r){if(n?this.getInput(`FORMAT`)||this.appendDummyInput(`FORMAT`).appendField(` `).appendField(new t(u(`time_get_default_format`)),`FORMAT`):this.getInput(`FORMAT`)&&this.removeInput(`FORMAT`),r){if(!this.getInput(`LANGUAGE`)){let t=s();this.appendDummyInput(`LANGUAGE`).appendField(new e(t),`LANGUAGE`)}}else this.getInput(`LANGUAGE`)&&this.removeInput(`LANGUAGE`)}},a.forBlock.convert_from_date=function(e){let t=e.getFieldValue(`OPTION`),n=e.getFieldValue(`FORMAT`),r=e.getFieldValue(`LANGUAGE`),s=a.valueToCode(e,`VALUE`,i.ATOMIC),c;return c=t===`object`?`getDateObject(${s}).getTime()`:t===`ms`?`getDateObject(${s}).getMilliseconds()`:t===`s`?`getDateObject(${s}).getSeconds()`:t===`sid`?`(() => { const v = getDateObject(${s}); return v.getHours() * 3600 + v.getMinutes() * 60 + v.getSeconds(); })()`:t===`m`?`getDateObject(${s}).getMinutes()`:t===`mid`?`(() => { const v = getDateObject(${s}); return v.getHours() * 60 + v.getMinutes(); })()`:t===`h`?`getDateObject(${s}).getHours()`:t===`d`?`getDateObject(${s}).getDate()`:t===`M`?`(getDateObject(${s}).getMonth() + 1)`:t===`Mt`?`formatDate(getDateObject(${s}), 'OO', '${r}')`:t===`Mts`?`formatDate(getDateObject(${s}), 'O', '${r}')`:t===`y`?`getDateObject(${s}).getYear()`:t===`fy`?`getDateObject(${s}).getFullYear()`:t===`wdt`?`formatDate(getDateObject(${s}), 'WW', '${r}')`:t===`wdts`?`formatDate(getDateObject(${s}), 'W', '${r}')`:t===`wd`?`(() => { const d = getDateObject(${s}).getDay(); return d === 0 ? 7 : d; })()`:t===`cw`?`((date) => { const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate())); const dayNum = d.getUTCDay() || 7; d.setUTCDate(d.getUTCDate() + 4 - dayNum); const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1)); return Math.ceil(((d.getTime() - yearStart.getTime()) / 86400000 + 1) / 7); })(getDateObject(${s}))`:t===`custom`?`formatDate(getDateObject(${s}), ${o(n)})`:`formatDate(getDateObject(${s}), ${o(t)})`,[c,i.ATOMIC]},l.Convert.blocks.convert_time_difference=`<block type="convert_time_difference"> <mutation format="false"></mutation> <field name="OPTION">hh:mm:ss</field> </block>`,r.convert_time_difference={init:function(){this.appendValueInput(`VALUE`).appendField(u(`convert_time_difference`)),this.appendDummyInput(`OPTION`).appendField(u(`convert_to`)).appendField(new e([[u(`time_difference_hh:mm:ss`),`hh:mm:ss`],[u(`time_difference_h:m:s`),`h:m:s`],[u(`time_difference_hh:mm`),`hh:mm`],[u(`time_difference_h:m`),`h:m`],[u(`time_difference_mm:ss`),`mm:ss`],[u(`time_difference_m:s`),`m:s`],[u(`time_difference_custom`),`custom`]],function(e){this.getSourceBlock().updateShape_(e===`custom`)}),`OPTION`),this.setInputsInline(!0),this.setOutput(!0,`String`),this.setColour(l.Convert.HUE),this.setTooltip(u(`convert_time_difference_tooltip`))},mutationToDom:function(){let e=document.createElement(`mutation`),t=this.getFieldValue(`OPTION`);return e.setAttribute(`format`,t===`custom`?`true`:`false`),e},domToMutation:function(e){let t=e.getAttribute(`format`);this.updateShape_(t===`true`||t===`TRUE`)},updateShape_:function(e){e?this.getInput(`FORMAT`)||this.appendDummyInput(`FORMAT`).appendField(` `).appendField(new t(u(`time_difference_default_format`)),`FORMAT`):this.getInput(`FORMAT`)&&this.removeInput(`FORMAT`)}},a.forBlock.convert_time_difference=function(e){let t=e.getFieldValue(`OPTION`),n=e.getFieldValue(`FORMAT`);return[`formatTimeDiff(${a.valueToCode(e,`VALUE`,i.ATOMIC)||`0`}, ${o(t===`custom`?n:t)})`,i.ATOMIC]},l.Convert.blocks.convert_json2object=`<block type="convert_json2object"></block>`,r.convert_json2object={init:function(){this.appendValueInput(`VALUE`).appendField(u(`convert_json2object`)),this.setOutput(!0),this.setColour(l.Convert.HUE),this.setTooltip(u(`convert_json2object_tooltip`))}},a.forBlock.convert_json2object=function(e){return[`(() => { try { return JSON.parse(${a.valueToCode(e,`VALUE`,i.ATOMIC)}); } catch (e) { return {}; }})()`,i.ATOMIC]},l.Convert.blocks.convert_object2json=`<block type="convert_object2json"> <field name="PRETTIFY">FALSE</field></block>`,r.convert_object2json={init:function(){this.appendValueInput(`VALUE`).appendField(u(`convert_object2json`)),this.appendDummyInput(`PRETTIFY`).appendField(u(`convert_object2json_prettify`)).appendField(new n(`FALSE`),`PRETTIFY`),this.setOutput(!0,`String`),this.setColour(l.Convert.HUE),this.setTooltip(u(`convert_object2json_tooltip`))}},a.forBlock.convert_object2json=function(e){let t=a.valueToCode(e,`VALUE`,i.ATOMIC),n=e.getFieldValue(`PRETTIFY`);return[`JSON.stringify(${t}${n===`TRUE`||n===`true`||n===!0?`, null, 2`:``})`,i.ATOMIC]},l.Convert.blocks.convert_jsonata=`<block type="convert_jsonata"> <value name="EXPRESSION"> <shadow type="text"> <field name="TEXT">*</field> </shadow> </value></block>`,r.convert_jsonata={init:function(){this.appendValueInput(`EXPRESSION`).appendField(u(`convert_jsonata`)),this.appendValueInput(`TARGET`).appendField(u(`convert_jsonata_target`)),this.setInputsInline(!0),this.setOutput(!0,`String`),this.setColour(l.Convert.HUE),this.setTooltip(u(`convert_jsonata_tooltip`))}},a.forBlock.convert_jsonata=function(e){let t=a.valueToCode(e,`EXPRESSION`,i.ATOMIC),n=a.valueToCode(e,`TARGET`,i.ATOMIC);return n||=`{}`,[`(await jsonataExpression(${n}, ${t}))`,i.ATOMIC]}}export{l as install};
@@ -1 +1 @@
1
- import{f as e,i as t,p as n,t as r}from"./blockly-fcfyKYzp.js";import{c as i,l as a}from"./index-PLY-IJik.js";import{l as o}from"./helpers-D5PdK4BS.js";function s(t,s,c,l,u){let d=window.Blockly.Translate,f=`${t}_container`,p=`${t}_mutator`;r[f]={init:function(){this.appendDummyInput().appendField(d(t)),this.appendStatementInput(`STACK`),this.setColour(`%{BKY_LOGIC_HUE}`),this.setTooltip(d(`${t}_tooltip`)),this.contextMenu=!1}},r[p]={init:function(){this.appendDummyInput(s).appendField(d(c)),this.setPreviousStatement(!0),this.setNextStatement(!0),this.setColour(`%{BKY_LOGIC_HUE}`),this.setTooltip(d(`${t}_tooltip`)),this.contextMenu=!1}},r[t]={init:function(){this.itemCount_=2,this.setMutator(new e.MutatorIcon([p],this)),this.setInputsInline(!1),this.setOutput(!0,`Boolean`),this.setColour(`%{BKY_LOGIC_HUE}`),this.setTooltip(d(`${t}_tooltip`))},mutationToDom:function(){let e=document.createElement(`mutation`);return e.setAttribute(`items`,String(this.itemCount_)),e},domToMutation:function(e){this.itemCount_=parseInt(e.getAttribute(`items`),10),this.updateShape_()},decompose:function(e){var t;let n=e.newBlock(f);n.initSvg();let r=(t=n.getInput(`STACK`))==null?void 0:t.connection;for(let t=0;t<this.itemCount_;t++){let t=e.newBlock(p);t.initSvg(),r.connect(t.previousConnection),r=t.nextConnection}return n},compose:function(e){let t=e.getInputTargetBlock(`STACK`),n=[];for(;t;)n.push(t.valueConnection_),t=t.nextConnection&&t.nextConnection.targetBlock();for(let e=0;e<this.itemCount_;e++){var r;let t=(r=this.getInput(`${s}${e}`))==null||(r=r.connection)==null?void 0:r.targetConnection;t&&!n.includes(t)&&t.disconnect()}this.itemCount_=n.length,this.itemCount_<2&&(this.itemCount_=2),this.updateShape_();for(let e=0;e<this.itemCount_;e++)o(n[e],this,`${s}${e}`)},saveConnections:function(e){let t=e.getInputTargetBlock(`STACK`),n=0;for(;t;){var r,i;let e=this.getInput(`${s}${n}`);t.valueConnection_=e==null||(r=e.connection)==null?void 0:r.targetConnection,n++,t=(i=t.nextConnection)==null?void 0:i.targetBlock()}},updateShape_:function(){for(let e=0;e<this.itemCount_;e++)if(!this.getInput(`${s}${e}`)){let t=this.appendValueInput(`${s}${e}`).setAlign(n.Align.RIGHT);e>0&&t.appendField(d(c))}for(let e=this.itemCount_;this.getInput(`${s}${e}`);e++)this.removeInput(`${s}${e}`)}},a.forBlock[t]=function(e){let t=e,n=[];for(let r=0;r<t.itemCount_;r++){let t=a.valueToCode(e,`${s}${r}`,i.ATOMIC);t&&n.push(t)}return[`${n.length>0?n.join(l):`false`}`,u]}}function c(){let e=window.Blockly.Translate;s(`logic_multi_and`,`AND`,`logic_multi_and_and`,` && `,i.LOGICAL_AND),s(`logic_multi_or`,`OR`,`logic_multi_or_or`,` || `,i.LOGICAL_OR),r.logic_between={init:function(){this.appendValueInput(`MIN`).setCheck(`Number`),this.appendValueInput(`VALUE`).setCheck(`Number`).appendField(new t([[`<`,`LT`],[`≤`,`LE`]]),`MIN_OPERATOR`),this.appendValueInput(`MAX`).setCheck(`Number`).appendField(new t([[`<`,`LT`],[`≤`,`LE`]]),`MAX_OPERATOR`),this.setInputsInline(!0),this.setOutput(!0,`Boolean`),this.setColour(`%{BKY_LOGIC_HUE}`),this.setTooltip(e(`logic_between_tooltip`))}},a.forBlock.logic_between=function(e){let t=a.valueToCode(e,`MIN`,i.RELATIONAL)||0,n=a.valueToCode(e,`VALUE`,i.RELATIONAL)||0,r=a.valueToCode(e,`MAX`,i.RELATIONAL)||0;return[`${t} ${e.getFieldValue(`MIN_OPERATOR`)===`LT`?`<`:`<=`} ${n} && ${n} ${e.getFieldValue(`MAX_OPERATOR`)===`LT`?`<`:`<=`} ${r}`,i.LOGICAL_AND]},r.logic_ifempty={init:function(){this.appendValueInput(`VALUE`).setCheck(null).setAlign(n.Align.RIGHT).appendField(e(`logic_ifempty`)),this.appendValueInput(`DEFLT`).setCheck(null).setAlign(n.Align.RIGHT).appendField(e(`logic_ifempty_then`)),this.setInputsInline(!0),this.setOutput(!0,null),this.setColour(`%{BKY_LOGIC_HUE}`),this.setTooltip(e(`logic_ifempty_tooltip`))}},a.forBlock.logic_ifempty=function(e){return[`${a.valueToCode(e,`VALUE`,i.LOGICAL_OR)||null} || ${a.valueToCode(e,`DEFLT`,i.LOGICAL_OR)||null}`,i.LOGICAL_OR]}}export{c as install};
1
+ import{f as e,i as t,p as n,t as r}from"./blockly-fcfyKYzp.js";import{c as i,l as a}from"./index-B0FfAYMN.js";import{l as o}from"./helpers-DiwtLpXM.js";function s(t,s,c,l,u){let d=window.Blockly.Translate,f=`${t}_container`,p=`${t}_mutator`;r[f]={init:function(){this.appendDummyInput().appendField(d(t)),this.appendStatementInput(`STACK`),this.setColour(`%{BKY_LOGIC_HUE}`),this.setTooltip(d(`${t}_tooltip`)),this.contextMenu=!1}},r[p]={init:function(){this.appendDummyInput(s).appendField(d(c)),this.setPreviousStatement(!0),this.setNextStatement(!0),this.setColour(`%{BKY_LOGIC_HUE}`),this.setTooltip(d(`${t}_tooltip`)),this.contextMenu=!1}},r[t]={init:function(){this.itemCount_=2,this.setMutator(new e.MutatorIcon([p],this)),this.setInputsInline(!1),this.setOutput(!0,`Boolean`),this.setColour(`%{BKY_LOGIC_HUE}`),this.setTooltip(d(`${t}_tooltip`))},mutationToDom:function(){let e=document.createElement(`mutation`);return e.setAttribute(`items`,String(this.itemCount_)),e},domToMutation:function(e){this.itemCount_=parseInt(e.getAttribute(`items`),10),this.updateShape_()},decompose:function(e){var t;let n=e.newBlock(f);n.initSvg();let r=(t=n.getInput(`STACK`))==null?void 0:t.connection;for(let t=0;t<this.itemCount_;t++){let t=e.newBlock(p);t.initSvg(),r.connect(t.previousConnection),r=t.nextConnection}return n},compose:function(e){let t=e.getInputTargetBlock(`STACK`),n=[];for(;t;)n.push(t.valueConnection_),t=t.nextConnection&&t.nextConnection.targetBlock();for(let e=0;e<this.itemCount_;e++){var r;let t=(r=this.getInput(`${s}${e}`))==null||(r=r.connection)==null?void 0:r.targetConnection;t&&!n.includes(t)&&t.disconnect()}this.itemCount_=n.length,this.itemCount_<2&&(this.itemCount_=2),this.updateShape_();for(let e=0;e<this.itemCount_;e++)o(n[e],this,`${s}${e}`)},saveConnections:function(e){let t=e.getInputTargetBlock(`STACK`),n=0;for(;t;){var r,i;let e=this.getInput(`${s}${n}`);t.valueConnection_=e==null||(r=e.connection)==null?void 0:r.targetConnection,n++,t=(i=t.nextConnection)==null?void 0:i.targetBlock()}},updateShape_:function(){for(let e=0;e<this.itemCount_;e++)if(!this.getInput(`${s}${e}`)){let t=this.appendValueInput(`${s}${e}`).setAlign(n.Align.RIGHT);e>0&&t.appendField(d(c))}for(let e=this.itemCount_;this.getInput(`${s}${e}`);e++)this.removeInput(`${s}${e}`)}},a.forBlock[t]=function(e){let t=e,n=[];for(let r=0;r<t.itemCount_;r++){let t=a.valueToCode(e,`${s}${r}`,i.ATOMIC);t&&n.push(t)}return[`${n.length>0?n.join(l):`false`}`,u]}}function c(){let e=window.Blockly.Translate;s(`logic_multi_and`,`AND`,`logic_multi_and_and`,` && `,i.LOGICAL_AND),s(`logic_multi_or`,`OR`,`logic_multi_or_or`,` || `,i.LOGICAL_OR),r.logic_between={init:function(){this.appendValueInput(`MIN`).setCheck(`Number`),this.appendValueInput(`VALUE`).setCheck(`Number`).appendField(new t([[`<`,`LT`],[`≤`,`LE`]]),`MIN_OPERATOR`),this.appendValueInput(`MAX`).setCheck(`Number`).appendField(new t([[`<`,`LT`],[`≤`,`LE`]]),`MAX_OPERATOR`),this.setInputsInline(!0),this.setOutput(!0,`Boolean`),this.setColour(`%{BKY_LOGIC_HUE}`),this.setTooltip(e(`logic_between_tooltip`))}},a.forBlock.logic_between=function(e){let t=a.valueToCode(e,`MIN`,i.RELATIONAL)||0,n=a.valueToCode(e,`VALUE`,i.RELATIONAL)||0,r=a.valueToCode(e,`MAX`,i.RELATIONAL)||0;return[`${t} ${e.getFieldValue(`MIN_OPERATOR`)===`LT`?`<`:`<=`} ${n} && ${n} ${e.getFieldValue(`MAX_OPERATOR`)===`LT`?`<`:`<=`} ${r}`,i.LOGICAL_AND]},r.logic_ifempty={init:function(){this.appendValueInput(`VALUE`).setCheck(null).setAlign(n.Align.RIGHT).appendField(e(`logic_ifempty`)),this.appendValueInput(`DEFLT`).setCheck(null).setAlign(n.Align.RIGHT).appendField(e(`logic_ifempty_then`)),this.setInputsInline(!0),this.setOutput(!0,null),this.setColour(`%{BKY_LOGIC_HUE}`),this.setTooltip(e(`logic_ifempty_tooltip`))}},a.forBlock.logic_ifempty=function(e){return[`${a.valueToCode(e,`VALUE`,i.LOGICAL_OR)||null} || ${a.valueToCode(e,`DEFLT`,i.LOGICAL_OR)||null}`,i.LOGICAL_OR]}}export{c as install};
@@ -1 +1 @@
1
- import{a as e,s as t,t as n}from"./blockly-fcfyKYzp.js";import{c as r,l as i}from"./index-PLY-IJik.js";function a(){let a=window.Blockly.Translate;n.math_rndfixed={init:function(){this.appendValueInput(`x`).setCheck(`Number`).appendField(a(`math_rndfixed_round`)),this.appendDummyInput().appendField(a(`math_rndfixed_to`)).appendField(new e(0,1,25),`n`).appendField(a(`math_rndfixed_decplcs`)),this.setInputsInline(!0),this.setOutput(!0,`Number`),this.setColour(t.MATH_HUE),this.setTooltip(a(`math_rndfixed_tooltip`))}},i.forBlock.math_rndfixed=function(e){let t=i.valueToCode(e,`x`,r.ATOMIC),n=10**Number(e.getFieldValue(`n`));return[`Math.round(${t} * ${n}) / ${n}`,r.ATOMIC]}}export{a as install};
1
+ import{a as e,s as t,t as n}from"./blockly-fcfyKYzp.js";import{c as r,l as i}from"./index-B0FfAYMN.js";function a(){let a=window.Blockly.Translate;n.math_rndfixed={init:function(){this.appendValueInput(`x`).setCheck(`Number`).appendField(a(`math_rndfixed_round`)),this.appendDummyInput().appendField(a(`math_rndfixed_to`)).appendField(new e(0,1,25),`n`).appendField(a(`math_rndfixed_decplcs`)),this.setInputsInline(!0),this.setOutput(!0,`Number`),this.setColour(t.MATH_HUE),this.setTooltip(a(`math_rndfixed_tooltip`))}},i.forBlock.math_rndfixed=function(e){let t=i.valueToCode(e,`x`,r.ATOMIC),n=10**Number(e.getFieldValue(`n`));return[`Math.round(${t} * ${n}) / ${n}`,r.ATOMIC]}}export{a as install};
@@ -1 +1 @@
1
- import{f as e,o as t,p as n,t as r}from"./blockly-fcfyKYzp.js";import{c as i,l as a}from"./index-PLY-IJik.js";import{c as o,l as s}from"./helpers-D5PdK4BS.js";function c(){let c=window.Blockly,l=c.Translate;c.CustomBlocks=c.CustomBlocks||[],c.CustomBlocks.push(`Object`),c.Object={HUE:40,blocks:{}},c.Object.blocks.object_new=`<block type="object_new"></block>`,r.object_new_container={init:function(){this.setColour(c.Object.HUE),this.appendDummyInput().appendField(l(`object_new_attributes`)),this.appendStatementInput(`STACK`),this.setTooltip(l(`object_new_tooltip`)),this.contextMenu=!1}},r.object_new_mutator={init:function(){this.setColour(c.Object.HUE),this.appendDummyInput(`ATTR`).appendField(l(`object_new_attribute`)).appendField(new t(`attribute1`),`ATTR`),this.setPreviousStatement(!0),this.setNextStatement(!0),this.setTooltip(l(`object_new_tooltip`)),this.contextMenu=!1}},r.object_new={init:function(){this.appendDummyInput(`NAME`).appendField(l(`object_new`)),this.attributes_=[],this.itemCount_=0,this.setMutator(new e.MutatorIcon([`object_new_mutator`],this)),this.setInputsInline(!1),this.setOutput(!0),this.setColour(c.Object.HUE),this.setTooltip(l(`object_new_tooltip`))},mutationToDom:function(){let e=document.createElement(`mutation`);for(let t=0;t<this.attributes_.length;t++){let n=document.createElement(`attribute`);n.setAttribute(`id`,`ATTR_${t}`),n.setAttribute(`name`,this.attributes_[t]),e.appendChild(n)}return e},domToMutation:function(e){this.attributes_=[];for(let t=0,n;n=e.childNodes[t];t++)n.nodeName.toLowerCase()===`attribute`&&this.attributes_.push(n.getAttribute(`name`));this.itemCount_=this.attributes_.length,this.updateShape_()},decompose:function(e){var t;let n=e.newBlock(`object_new_container`);n.initSvg();let r=(t=n.getInput(`STACK`))==null?void 0:t.connection;for(let t=0;t<this.itemCount_;t++){let n=e.newBlock(`object_new_mutator`);n.setFieldValue(this.attributes_[t],`ATTR`),n.initSvg(),r.connect(n.previousConnection),r=n.nextConnection}return n},compose:function(e){this.attributes_=[];let t=e.getInputTargetBlock(`STACK`),n=[];for(;t;){let e=t.getFieldValue(`ATTR`);this.attributes_.push(e),n.push(t.valueConnection_),t=t.nextConnection&&t.nextConnection.targetBlock()}for(let e=0;e<this.itemCount_;e++){var r;let t=(r=this.getInput(`ATTR_${e}`))==null||(r=r.connection)==null?void 0:r.targetConnection;t&&!n.includes(t)&&t.disconnect()}this.itemCount_=n.length,this.itemCount_<0&&(this.itemCount_=0),this.updateShape_();for(let e=0;e<this.itemCount_;e++)s(n[e],this,`ATTR_${e}`)},saveConnections:function(e){let t=e.getInputTargetBlock(`STACK`),n=0;for(;t;){var r,i;let e=this.getInput(`ATTR_${n}`);t.valueConnection_=e==null||(r=e.connection)==null?void 0:r.targetConnection,n++,t=(i=t.nextConnection)==null?void 0:i.targetBlock()}},updateShape_:function(){let e=this.workspace;for(let t=0;t<this.itemCount_;t++){let r=this.getInput(`ATTR_${t}`);r?r.fieldRow[0].setValue(this.attributes_[t]):(r=this.appendValueInput(`ATTR_${t}`).setAlign(n.Align.RIGHT),r.appendField(this.attributes_[t])),setTimeout(t=>{var n;if(!((n=t.connection)!=null&&n.isConnected())){let n=e.newBlock(`text`);n.setShadow(!0),n.initSvg(),n.render(),n.outputConnection.connect(t.connection)}},100,r)}for(let e=this.itemCount_;this.getInput(`ATTR_${e}`);e++)this.removeInput(`ATTR_${e}`)}},a.forBlock.object_new=function(e){let t=e,n=[];for(let r=0;r<t.itemCount_;r++){let s=a.valueToCode(e,`ATTR_${r}`,i.COMMA);s&&n.push(`${o(t.attributes_[r])}: ${s}`)}return[`{ ${n.length?n.join(`, `):``} }`,i.ATOMIC]},c.Object.blocks.object_set_attr=`<block type="object_set_attr"> <field name="ATTR">attribute1</field> <value name="VALUE"> <shadow type="text"> <field name="TEXT">value</field> </shadow> </value></block>`,r.object_set_attr={init:function(){this.appendDummyInput(`ATTR`).appendField(l(`object_set_attr`)).appendField(new t(`attribute1`),`ATTR`),this.appendValueInput(`OBJECT`).appendField(l(`object_set_attr_object`)),this.appendValueInput(`VALUE`).setCheck(null).appendField(l(`object_set_attr_value`)),this.setInputsInline(!1),this.setPreviousStatement(!0,null),this.setNextStatement(!0,null),this.setColour(c.Object.HUE),this.setTooltip(l(`object_set_attr_tooltip`))}},a.forBlock.object_set_attr=function(e){let t=e.getFieldValue(`ATTR`),n=a.valueToCode(e,`VALUE`,i.ATOMIC),r=a.valueToCode(e,`OBJECT`,i.ATOMIC);return r||=`{}`,`((obj) => { if (typeof obj === 'object') { obj[${o(t)}] = ${n}; } })(${r});\n`},c.Object.blocks.object_del_attr=`<block type="object_del_attr"> <field name="ATTR">attribute1</field></block>`,r.object_del_attr={init:function(){this.appendDummyInput(`ATTR`).appendField(l(`object_del_attr`)).appendField(new t(`attribute1`),`ATTR`),this.appendValueInput(`OBJECT`).appendField(l(`object_del_attr_object`)),this.setInputsInline(!1),this.setPreviousStatement(!0,null),this.setNextStatement(!0,null),this.setColour(c.Object.HUE),this.setTooltip(l(`object_del_attr_tooltip`))}},a.forBlock.object_del_attr=function(e){let t=e.getFieldValue(`ATTR`),n=a.valueToCode(e,`OBJECT`,i.ATOMIC);return n||=`{}`,`((obj) => { if (typeof obj === 'object') { delete obj[${o(t)}]; } })(${n});\n`},c.Object.blocks.object_has_attr=`<block type="object_has_attr"> <field name="ATTR">attribute1</field> <value name="OBJECT"> <shadow type="get_object"> <field name="OID">Object ID</field> </shadow> </value></block>`,r.object_has_attr={init:function(){this.appendValueInput(`OBJECT`).appendField(l(`object_has_attr`)),this.appendDummyInput(`ATTR`).appendField(l(`object_has_attr_attr`)).appendField(new t(`attribute1`),`ATTR`),this.setInputsInline(!0),this.setOutput(!0,`Boolean`),this.setColour(c.Object.HUE),this.setTooltip(l(`object_has_attr_tooltip`))}},a.forBlock.object_has_attr=function(e){let t=a.valueToCode(e,`OBJECT`,i.ATOMIC),n=e.getFieldValue(`ATTR`);return[`Object.prototype.hasOwnProperty.call(${t}, ${o(n)})`,i.ATOMIC]},c.Object.blocks.object_keys=`<block type="object_keys"> <value name="OBJECT"> <shadow type="get_object"> <field name="OID">Object ID</field> </shadow> </value></block>`,r.object_keys={init:function(){this.appendValueInput(`OBJECT`).appendField(l(`object_keys`)),this.setInputsInline(!0),this.setOutput(!0,`Array`),this.setColour(c.Object.HUE),this.setTooltip(l(`object_keys_tooltip`))}},a.forBlock.object_keys=function(e){let t=a.valueToCode(e,`OBJECT`,i.ATOMIC);return t||=`{}`,[`Object.keys(${t})`,i.ATOMIC]}}export{c as install};
1
+ import{f as e,o as t,p as n,t as r}from"./blockly-fcfyKYzp.js";import{c as i,l as a}from"./index-B0FfAYMN.js";import{c as o,l as s}from"./helpers-DiwtLpXM.js";function c(){let c=window.Blockly,l=c.Translate;c.CustomBlocks=c.CustomBlocks||[],c.CustomBlocks.push(`Object`),c.Object={HUE:40,blocks:{}},c.Object.blocks.object_new=`<block type="object_new"></block>`,r.object_new_container={init:function(){this.setColour(c.Object.HUE),this.appendDummyInput().appendField(l(`object_new_attributes`)),this.appendStatementInput(`STACK`),this.setTooltip(l(`object_new_tooltip`)),this.contextMenu=!1}},r.object_new_mutator={init:function(){this.setColour(c.Object.HUE),this.appendDummyInput(`ATTR`).appendField(l(`object_new_attribute`)).appendField(new t(`attribute1`),`ATTR`),this.setPreviousStatement(!0),this.setNextStatement(!0),this.setTooltip(l(`object_new_tooltip`)),this.contextMenu=!1}},r.object_new={init:function(){this.appendDummyInput(`NAME`).appendField(l(`object_new`)),this.attributes_=[],this.itemCount_=0,this.setMutator(new e.MutatorIcon([`object_new_mutator`],this)),this.setInputsInline(!1),this.setOutput(!0),this.setColour(c.Object.HUE),this.setTooltip(l(`object_new_tooltip`))},mutationToDom:function(){let e=document.createElement(`mutation`);for(let t=0;t<this.attributes_.length;t++){let n=document.createElement(`attribute`);n.setAttribute(`id`,`ATTR_${t}`),n.setAttribute(`name`,this.attributes_[t]),e.appendChild(n)}return e},domToMutation:function(e){this.attributes_=[];for(let t=0,n;n=e.childNodes[t];t++)n.nodeName.toLowerCase()===`attribute`&&this.attributes_.push(n.getAttribute(`name`));this.itemCount_=this.attributes_.length,this.updateShape_()},decompose:function(e){var t;let n=e.newBlock(`object_new_container`);n.initSvg();let r=(t=n.getInput(`STACK`))==null?void 0:t.connection;for(let t=0;t<this.itemCount_;t++){let n=e.newBlock(`object_new_mutator`);n.setFieldValue(this.attributes_[t],`ATTR`),n.initSvg(),r.connect(n.previousConnection),r=n.nextConnection}return n},compose:function(e){this.attributes_=[];let t=e.getInputTargetBlock(`STACK`),n=[];for(;t;){let e=t.getFieldValue(`ATTR`);this.attributes_.push(e),n.push(t.valueConnection_),t=t.nextConnection&&t.nextConnection.targetBlock()}for(let e=0;e<this.itemCount_;e++){var r;let t=(r=this.getInput(`ATTR_${e}`))==null||(r=r.connection)==null?void 0:r.targetConnection;t&&!n.includes(t)&&t.disconnect()}this.itemCount_=n.length,this.itemCount_<0&&(this.itemCount_=0),this.updateShape_();for(let e=0;e<this.itemCount_;e++)s(n[e],this,`ATTR_${e}`)},saveConnections:function(e){let t=e.getInputTargetBlock(`STACK`),n=0;for(;t;){var r,i;let e=this.getInput(`ATTR_${n}`);t.valueConnection_=e==null||(r=e.connection)==null?void 0:r.targetConnection,n++,t=(i=t.nextConnection)==null?void 0:i.targetBlock()}},updateShape_:function(){let e=this.workspace;for(let t=0;t<this.itemCount_;t++){let r=this.getInput(`ATTR_${t}`);r?r.fieldRow[0].setValue(this.attributes_[t]):(r=this.appendValueInput(`ATTR_${t}`).setAlign(n.Align.RIGHT),r.appendField(this.attributes_[t])),setTimeout(t=>{var n;if(!((n=t.connection)!=null&&n.isConnected())){let n=e.newBlock(`text`);n.setShadow(!0),n.initSvg(),n.render(),n.outputConnection.connect(t.connection)}},100,r)}for(let e=this.itemCount_;this.getInput(`ATTR_${e}`);e++)this.removeInput(`ATTR_${e}`)}},a.forBlock.object_new=function(e){let t=e,n=[];for(let r=0;r<t.itemCount_;r++){let s=a.valueToCode(e,`ATTR_${r}`,i.COMMA);s&&n.push(`${o(t.attributes_[r])}: ${s}`)}return[`{ ${n.length?n.join(`, `):``} }`,i.ATOMIC]},c.Object.blocks.object_set_attr=`<block type="object_set_attr"> <field name="ATTR">attribute1</field> <value name="VALUE"> <shadow type="text"> <field name="TEXT">value</field> </shadow> </value></block>`,r.object_set_attr={init:function(){this.appendDummyInput(`ATTR`).appendField(l(`object_set_attr`)).appendField(new t(`attribute1`),`ATTR`),this.appendValueInput(`OBJECT`).appendField(l(`object_set_attr_object`)),this.appendValueInput(`VALUE`).setCheck(null).appendField(l(`object_set_attr_value`)),this.setInputsInline(!1),this.setPreviousStatement(!0,null),this.setNextStatement(!0,null),this.setColour(c.Object.HUE),this.setTooltip(l(`object_set_attr_tooltip`))}},a.forBlock.object_set_attr=function(e){let t=e.getFieldValue(`ATTR`),n=a.valueToCode(e,`VALUE`,i.ATOMIC),r=a.valueToCode(e,`OBJECT`,i.ATOMIC);return r||=`{}`,`((obj) => { if (typeof obj === 'object') { obj[${o(t)}] = ${n}; } })(${r});\n`},c.Object.blocks.object_del_attr=`<block type="object_del_attr"> <field name="ATTR">attribute1</field></block>`,r.object_del_attr={init:function(){this.appendDummyInput(`ATTR`).appendField(l(`object_del_attr`)).appendField(new t(`attribute1`),`ATTR`),this.appendValueInput(`OBJECT`).appendField(l(`object_del_attr_object`)),this.setInputsInline(!1),this.setPreviousStatement(!0,null),this.setNextStatement(!0,null),this.setColour(c.Object.HUE),this.setTooltip(l(`object_del_attr_tooltip`))}},a.forBlock.object_del_attr=function(e){let t=e.getFieldValue(`ATTR`),n=a.valueToCode(e,`OBJECT`,i.ATOMIC);return n||=`{}`,`((obj) => { if (typeof obj === 'object') { delete obj[${o(t)}]; } })(${n});\n`},c.Object.blocks.object_has_attr=`<block type="object_has_attr"> <field name="ATTR">attribute1</field> <value name="OBJECT"> <shadow type="get_object"> <field name="OID">Object ID</field> </shadow> </value></block>`,r.object_has_attr={init:function(){this.appendValueInput(`OBJECT`).appendField(l(`object_has_attr`)),this.appendDummyInput(`ATTR`).appendField(l(`object_has_attr_attr`)).appendField(new t(`attribute1`),`ATTR`),this.setInputsInline(!0),this.setOutput(!0,`Boolean`),this.setColour(c.Object.HUE),this.setTooltip(l(`object_has_attr_tooltip`))}},a.forBlock.object_has_attr=function(e){let t=a.valueToCode(e,`OBJECT`,i.ATOMIC),n=e.getFieldValue(`ATTR`);return[`Object.prototype.hasOwnProperty.call(${t}, ${o(n)})`,i.ATOMIC]},c.Object.blocks.object_keys=`<block type="object_keys"> <value name="OBJECT"> <shadow type="get_object"> <field name="OID">Object ID</field> </shadow> </value></block>`,r.object_keys={init:function(){this.appendValueInput(`OBJECT`).appendField(l(`object_keys`)),this.setInputsInline(!0),this.setOutput(!0,`Array`),this.setColour(c.Object.HUE),this.setTooltip(l(`object_keys_tooltip`))}},a.forBlock.object_keys=function(e){let t=a.valueToCode(e,`OBJECT`,i.ATOMIC);return t||=`{}`,[`Object.keys(${t})`,i.ATOMIC]}}export{c as install};
@@ -1,3 +1,3 @@
1
- import{f as e,h as t,l as n,o as r,s as i,t as a}from"./blockly-fcfyKYzp.js";import{c as o,l as s}from"./index-PLY-IJik.js";import{FieldScript as c,b64DecodeUnicode as l}from"./field_script-CehplM7L.js";function u(e){return a[e]}function d(){let d=window.Blockly,f=d.Translate,p=t.xml,m=u(`procedures_ifreturn`);m.FUNCTION_TYPES.includes(`procedures_defcustomreturn`)||m.FUNCTION_TYPES.push(`procedures_defcustomreturn`),m.FUNCTION_TYPES.includes(`procedures_defcustomnoreturn`)||m.FUNCTION_TYPES.push(`procedures_defcustomnoreturn`),d.Procedures.allProceduresNew=function(e){let t=n.allProcedures(e),r=()=>e.getProcedureMap().getProcedures().filter(e=>!!e.getReturnTypes()).map(e=>[e.getName(),e.getParameters().map(e=>e.getName()),!0]),i=t=>{let i=r();return e.getBlocksByType(t,!1).forEach(e=>{n.isProcedureBlock(e)||i.push(e.getProcedureDef())}),i};return t.concat([i(`procedures_defcustomnoreturn`),i(`procedures_defcustomreturn`)])},d.Procedures.flyoutCategoryNew=function(e){let t=[],n=(e,n)=>{if(!a[e])return;let r=p.createElement(`block`);r.setAttribute(`type`,e),r.setAttribute(`gap`,`16`);let o=p.createElement(`field`);o.setAttribute(`name`,`NAME`),o.appendChild(p.createTextNode(i[n])),r.appendChild(o),t.push(r)},r=e=>{if(!a[e])return;let n=p.createElement(`block`);n.setAttribute(`type`,e),n.setAttribute(`gap`,`16`),t.push(n)};n(`procedures_defnoreturn`,`PROCEDURES_DEFNORETURN_PROCEDURE`),n(`procedures_defreturn`,`PROCEDURES_DEFRETURN_PROCEDURE`),r(`procedures_ifreturn`),r(`procedures_return`),n(`procedures_defcustomnoreturn`,`PROCEDURES_DEFNORETURN_PROCEDURE`),n(`procedures_defcustomreturn`,`PROCEDURES_DEFRETURN_PROCEDURE`),t.length&&t[t.length-1].setAttribute(`gap`,`24`);let o=(e,n)=>{for(let[r,i]of e){let e=p.createElement(`block`);e.setAttribute(`type`,n),e.setAttribute(`gap`,`16`);let a=p.createElement(`mutation`);a.setAttribute(`name`,r),e.appendChild(a);for(let e of i){let t=p.createElement(`arg`);t.setAttribute(`name`,e),a.appendChild(t)}t.push(e)}},s=d.Procedures.allProceduresNew(e);return o(s[0],`procedures_callnoreturn`),o(s[1],`procedures_callreturn`),o(s[2],`procedures_callcustomnoreturn`),o(s[3],`procedures_callcustomreturn`),t},s.forBlock.procedures_defreturn=function(e){let t=s,r=t.nameDB_.getName(e.getFieldValue(`NAME`),n.CATEGORY_NAME),i=``;t.STATEMENT_PREFIX&&(i+=t.injectId(t.STATEMENT_PREFIX,e)),t.STATEMENT_SUFFIX&&(i+=t.injectId(t.STATEMENT_SUFFIX,e)),i&&=t.prefixLines(i,t.INDENT);let a=``;t.INFINITE_LOOP_TRAP&&(a=t.prefixLines(t.injectId(t.INFINITE_LOOP_TRAP,e),t.INDENT));let c=``,l=``,u=e.getInput(`STACK`)?t.statementToCode(e,`STACK`):``;e.getInput(`RETURN`)&&(c=t.valueToCode(e,`RETURN`,o.NONE)||``,u&&c&&(l=i),c&&=`${t.INDENT}return ${c};\n`);let d=`async function ${r}(${e.getVarModels().map(e=>t.nameDB_.getName(e.name,`VARIABLE`)).join(`, `)}) {\n${i}${a}${u}${l}${c}}`;return d=t.scrub_(e,d),t.definitions_[`%${r}`]=d,null},s.forBlock.procedures_defnoreturn=s.forBlock.procedures_defreturn,s.forBlock.procedures_callreturn=function(e){let t=s;return[`await ${t.nameDB_.getName(e.getFieldValue(`NAME`),n.CATEGORY_NAME)}(${e.getVarModels().map((n,r)=>t.valueToCode(e,`ARG${r}`,o.NONE)||`null`).join(`, `)})`,o.FUNCTION_CALL]};let h=t=>{let o=t?`procedures_defcustomreturn`:`procedures_defcustomnoreturn`,s=u(t?`procedures_defreturn`:`procedures_defnoreturn`),l=t?`procedures_defcustomreturn_name`:`procedures_defcustomnoreturn_name`,d=t?`PROCEDURES_DEFRETURN`:`PROCEDURES_DEFNORETURN`;a[o]={getProcedureModel(){return this.model},isProcedureDef(){return!0},init:function(){var a;let o=new r(``,n.rename);o.setSpellcheck(!1),this.appendDummyInput().appendField(f(l)).appendField(o,`NAME`).appendField(``,`PARAMS`),this.setMutator(new e.MutatorIcon([`procedures_mutatorarg`],this));let s=this.workspace.options;(s.comments||(a=s.parentWorkspace)!=null&&a.options.comments)&&i[`${d}_COMMENT`]&&this.setCommentText(i[`${d}_COMMENT`]),this.setStyle(`procedure_blocks`),t||this.setColour(i.PROCEDURES_HUE),this.setTooltip(i[`${d}_TOOLTIP`]),this.setHelpUrl(i[`${d}_HELPURL`]),this.arguments_=[],this.argumentVarModels_=[],this.setStatements_(!0),this.statementConnection_=null,this.appendDummyInput(`SCRIPT`).appendField(new c(t?btoa(`return 0;`):``),`SCRIPT`),this.setInputsInline(!0),this.setStatements_(!1)},setStatements_:s.setStatements_,updateParams_:s.updateParams_,mutationToDom:s.mutationToDom,domToMutation:s.domToMutation,decompose:function(e){var t,r;let i=e.newBlock(`procedures_mutatorcontainer`);i.initSvg(),(t=i.getInput(`STATEMENT_INPUT`))==null||t.setVisible(!1);let a=(r=i.getInput(`STACK`))==null?void 0:r.connection;for(let t=0;t<this.arguments_.length;t++){let n=e.newBlock(`procedures_mutatorarg`);n.initSvg(),n.setFieldValue(this.arguments_[t],`NAME`),n.oldLocation=t,a.connect(n.previousConnection),a=n.nextConnection}return n.mutateCallers(this),i},compose:function(e){this.arguments_=[],this.paramIds_=[],this.argumentVarModels_=[];let t=e.getInputTargetBlock(`STACK`);for(;t&&!t.isInsertionMarker();){let e=t.getFieldValue(`NAME`);this.arguments_.push(e),this.argumentVarModels_.push(this.workspace.getVariableMap().getVariable(e,``)),this.paramIds_.push(t.id),t=t.nextConnection&&t.nextConnection.targetBlock()}this.updateParams_(),n.mutateCallers(this)},getProcedureDef:function(){return[this.getFieldValue(`NAME`),this.arguments_,t,!0]},getVarModels:s.getVarModels,renameVarById:s.renameVarById,updateVarName:s.updateVarName,displayRenamedVar_:s.displayRenamedVar_,customContextMenu:s.customContextMenu,callType_:t?`procedures_callcustomreturn`:`procedures_callcustomnoreturn`}},g=e=>{let t=e?`procedures_callcustomreturn`:`procedures_callcustomnoreturn`,n=u(e?`procedures_callreturn`:`procedures_callnoreturn`);a[t]={init:n.init,getProcedureCall:n.getProcedureCall,renameProcedure:n.renameProcedure,setProcedureParameters_:n.setProcedureParameters_,updateShape_:n.updateShape_,mutationToDom:n.mutationToDom,domToMutation:n.domToMutation,getVarModels:n.getVarModels,onchange:n.onchange,customContextMenu:n.customContextMenu,defType_:e?`procedures_defcustomreturn`:`procedures_defcustomnoreturn`}};h(!0),s.forBlock.procedures_defcustomreturn=function(e){let t=s,r=t.nameDB_.getName(e.getFieldValue(`NAME`),n.CATEGORY_NAME),i=e.arguments_.map(e=>t.nameDB_.getName(e,`VARIABLE`)),a=l(e.getFieldValue(`SCRIPT`)||``).split(`
1
+ import{f as e,h as t,l as n,o as r,s as i,t as a}from"./blockly-fcfyKYzp.js";import{c as o,l as s}from"./index-B0FfAYMN.js";import{FieldScript as c,b64DecodeUnicode as l}from"./field_script-CehplM7L.js";function u(e){return a[e]}function d(){let d=window.Blockly,f=d.Translate,p=t.xml,m=u(`procedures_ifreturn`);m.FUNCTION_TYPES.includes(`procedures_defcustomreturn`)||m.FUNCTION_TYPES.push(`procedures_defcustomreturn`),m.FUNCTION_TYPES.includes(`procedures_defcustomnoreturn`)||m.FUNCTION_TYPES.push(`procedures_defcustomnoreturn`),d.Procedures.allProceduresNew=function(e){let t=n.allProcedures(e),r=()=>e.getProcedureMap().getProcedures().filter(e=>!!e.getReturnTypes()).map(e=>[e.getName(),e.getParameters().map(e=>e.getName()),!0]),i=t=>{let i=r();return e.getBlocksByType(t,!1).forEach(e=>{n.isProcedureBlock(e)||i.push(e.getProcedureDef())}),i};return t.concat([i(`procedures_defcustomnoreturn`),i(`procedures_defcustomreturn`)])},d.Procedures.flyoutCategoryNew=function(e){let t=[],n=(e,n)=>{if(!a[e])return;let r=p.createElement(`block`);r.setAttribute(`type`,e),r.setAttribute(`gap`,`16`);let o=p.createElement(`field`);o.setAttribute(`name`,`NAME`),o.appendChild(p.createTextNode(i[n])),r.appendChild(o),t.push(r)},r=e=>{if(!a[e])return;let n=p.createElement(`block`);n.setAttribute(`type`,e),n.setAttribute(`gap`,`16`),t.push(n)};n(`procedures_defnoreturn`,`PROCEDURES_DEFNORETURN_PROCEDURE`),n(`procedures_defreturn`,`PROCEDURES_DEFRETURN_PROCEDURE`),r(`procedures_ifreturn`),r(`procedures_return`),n(`procedures_defcustomnoreturn`,`PROCEDURES_DEFNORETURN_PROCEDURE`),n(`procedures_defcustomreturn`,`PROCEDURES_DEFRETURN_PROCEDURE`),t.length&&t[t.length-1].setAttribute(`gap`,`24`);let o=(e,n)=>{for(let[r,i]of e){let e=p.createElement(`block`);e.setAttribute(`type`,n),e.setAttribute(`gap`,`16`);let a=p.createElement(`mutation`);a.setAttribute(`name`,r),e.appendChild(a);for(let e of i){let t=p.createElement(`arg`);t.setAttribute(`name`,e),a.appendChild(t)}t.push(e)}},s=d.Procedures.allProceduresNew(e);return o(s[0],`procedures_callnoreturn`),o(s[1],`procedures_callreturn`),o(s[2],`procedures_callcustomnoreturn`),o(s[3],`procedures_callcustomreturn`),t},s.forBlock.procedures_defreturn=function(e){let t=s,r=t.nameDB_.getName(e.getFieldValue(`NAME`),n.CATEGORY_NAME),i=``;t.STATEMENT_PREFIX&&(i+=t.injectId(t.STATEMENT_PREFIX,e)),t.STATEMENT_SUFFIX&&(i+=t.injectId(t.STATEMENT_SUFFIX,e)),i&&=t.prefixLines(i,t.INDENT);let a=``;t.INFINITE_LOOP_TRAP&&(a=t.prefixLines(t.injectId(t.INFINITE_LOOP_TRAP,e),t.INDENT));let c=``,l=``,u=e.getInput(`STACK`)?t.statementToCode(e,`STACK`):``;e.getInput(`RETURN`)&&(c=t.valueToCode(e,`RETURN`,o.NONE)||``,u&&c&&(l=i),c&&=`${t.INDENT}return ${c};\n`);let d=`async function ${r}(${e.getVarModels().map(e=>t.nameDB_.getName(e.name,`VARIABLE`)).join(`, `)}) {\n${i}${a}${u}${l}${c}}`;return d=t.scrub_(e,d),t.definitions_[`%${r}`]=d,null},s.forBlock.procedures_defnoreturn=s.forBlock.procedures_defreturn,s.forBlock.procedures_callreturn=function(e){let t=s;return[`await ${t.nameDB_.getName(e.getFieldValue(`NAME`),n.CATEGORY_NAME)}(${e.getVarModels().map((n,r)=>t.valueToCode(e,`ARG${r}`,o.NONE)||`null`).join(`, `)})`,o.FUNCTION_CALL]};let h=t=>{let o=t?`procedures_defcustomreturn`:`procedures_defcustomnoreturn`,s=u(t?`procedures_defreturn`:`procedures_defnoreturn`),l=t?`procedures_defcustomreturn_name`:`procedures_defcustomnoreturn_name`,d=t?`PROCEDURES_DEFRETURN`:`PROCEDURES_DEFNORETURN`;a[o]={getProcedureModel(){return this.model},isProcedureDef(){return!0},init:function(){var a;let o=new r(``,n.rename);o.setSpellcheck(!1),this.appendDummyInput().appendField(f(l)).appendField(o,`NAME`).appendField(``,`PARAMS`),this.setMutator(new e.MutatorIcon([`procedures_mutatorarg`],this));let s=this.workspace.options;(s.comments||(a=s.parentWorkspace)!=null&&a.options.comments)&&i[`${d}_COMMENT`]&&this.setCommentText(i[`${d}_COMMENT`]),this.setStyle(`procedure_blocks`),t||this.setColour(i.PROCEDURES_HUE),this.setTooltip(i[`${d}_TOOLTIP`]),this.setHelpUrl(i[`${d}_HELPURL`]),this.arguments_=[],this.argumentVarModels_=[],this.setStatements_(!0),this.statementConnection_=null,this.appendDummyInput(`SCRIPT`).appendField(new c(t?btoa(`return 0;`):``),`SCRIPT`),this.setInputsInline(!0),this.setStatements_(!1)},setStatements_:s.setStatements_,updateParams_:s.updateParams_,mutationToDom:s.mutationToDom,domToMutation:s.domToMutation,decompose:function(e){var t,r;let i=e.newBlock(`procedures_mutatorcontainer`);i.initSvg(),(t=i.getInput(`STATEMENT_INPUT`))==null||t.setVisible(!1);let a=(r=i.getInput(`STACK`))==null?void 0:r.connection;for(let t=0;t<this.arguments_.length;t++){let n=e.newBlock(`procedures_mutatorarg`);n.initSvg(),n.setFieldValue(this.arguments_[t],`NAME`),n.oldLocation=t,a.connect(n.previousConnection),a=n.nextConnection}return n.mutateCallers(this),i},compose:function(e){this.arguments_=[],this.paramIds_=[],this.argumentVarModels_=[];let t=e.getInputTargetBlock(`STACK`);for(;t&&!t.isInsertionMarker();){let e=t.getFieldValue(`NAME`);this.arguments_.push(e),this.argumentVarModels_.push(this.workspace.getVariableMap().getVariable(e,``)),this.paramIds_.push(t.id),t=t.nextConnection&&t.nextConnection.targetBlock()}this.updateParams_(),n.mutateCallers(this)},getProcedureDef:function(){return[this.getFieldValue(`NAME`),this.arguments_,t,!0]},getVarModels:s.getVarModels,renameVarById:s.renameVarById,updateVarName:s.updateVarName,displayRenamedVar_:s.displayRenamedVar_,customContextMenu:s.customContextMenu,callType_:t?`procedures_callcustomreturn`:`procedures_callcustomnoreturn`}},g=e=>{let t=e?`procedures_callcustomreturn`:`procedures_callcustomnoreturn`,n=u(e?`procedures_callreturn`:`procedures_callnoreturn`);a[t]={init:n.init,getProcedureCall:n.getProcedureCall,renameProcedure:n.renameProcedure,setProcedureParameters_:n.setProcedureParameters_,updateShape_:n.updateShape_,mutationToDom:n.mutationToDom,domToMutation:n.domToMutation,getVarModels:n.getVarModels,onchange:n.onchange,customContextMenu:n.customContextMenu,defType_:e?`procedures_defcustomreturn`:`procedures_defcustomnoreturn`}};h(!0),s.forBlock.procedures_defcustomreturn=function(e){let t=s,r=t.nameDB_.getName(e.getFieldValue(`NAME`),n.CATEGORY_NAME),i=e.arguments_.map(e=>t.nameDB_.getName(e,`VARIABLE`)),a=l(e.getFieldValue(`SCRIPT`)||``).split(`
2
2
  `).map(e=>` ${e}`),o=`async function ${r}(${i.join(`, `)}) {\n${a.join(`
3
3
  `)}\n}`;return o=t.scrub_(e,o),t.definitions_[`%${r}`]=o,null},g(!0),s.forBlock.procedures_callcustomreturn=s.forBlock.procedures_callreturn,u(`procedures_ifreturn`).init=function(){let e=this.appendValueInput(`CONDITION`).setCheck(`Boolean`).appendField(i.CONTROLS_IF_MSG_IF),t=this.workspace.newBlock(`logic_boolean`);t.setShadow(!0),t.setFieldValue(`TRUE`,`BOOL`),t.outputConnection.connect(e.connection),this.appendValueInput(`VALUE`).appendField(i.PROCEDURES_DEFRETURN_RETURN),this.setInputsInline(!0),this.setPreviousStatement(!0),this.setNextStatement(!0),this.setStyle(`procedure_blocks`),this.setTooltip(i.PROCEDURES_IFRETURN_TOOLTIP),this.setHelpUrl(i.PROCEDURES_IFRETURN_HELPURL),this.hasReturnValue_=!0},h(!1),a.procedures_defcustomnoreturn.decompose=a.procedures_defcustomreturn.decompose,a.procedures_defcustomnoreturn.compose=a.procedures_defcustomreturn.compose,s.forBlock.procedures_defcustomnoreturn=s.forBlock.procedures_defcustomreturn,g(!1),s.forBlock.procedures_callcustomnoreturn=function(e){return`${s.forBlock.procedures_callcustomreturn(e,s)[0]};\n`},a.procedures_return={init:function(){this.appendValueInput(`VALUE`).appendField(i.PROCEDURES_DEFRETURN_RETURN),this.setInputsInline(!0),this.setPreviousStatement(!0),this.setNextStatement(!0),this.setStyle(`procedure_blocks`),this.setTooltip(i.PROCEDURES_IFRETURN_TOOLTIP),this.setHelpUrl(i.PROCEDURES_IFRETURN_HELPURL),this.hasReturnValue_=!0},mutationToDom:function(){let e=p.createElement(`mutation`);return e.setAttribute(`value`,String(Number(this.hasReturnValue_))),e},domToMutation:function(e){this.hasReturnValue_=e.getAttribute(`value`)===`1`,this.hasReturnValue_||(this.removeInput(`VALUE`),this.appendDummyInput(`VALUE`).appendField(i.PROCEDURES_DEFRETURN_RETURN))},onchange:function(e){var t,n;if((t=(n=this.workspace).isDragging)!=null&&t.call(n)||e.type!==`move`&&e.type!==`create`)return;let r=!1,a=this;do{if(this.FUNCTION_TYPES.includes(a.type)){r=!0;break}a=a.getSurroundParent()}while(a);r?(a.type===`procedures_defnoreturn`&&this.hasReturnValue_?(this.removeInput(`VALUE`),this.appendDummyInput(`VALUE`).appendField(i.PROCEDURES_DEFRETURN_RETURN),this.hasReturnValue_=!1):a.type===`procedures_defreturn`&&!this.hasReturnValue_&&(this.removeInput(`VALUE`),this.appendValueInput(`VALUE`).appendField(i.PROCEDURES_DEFRETURN_RETURN),this.hasReturnValue_=!0),this.setWarningText(null)):this.setWarningText(i.PROCEDURES_IFRETURN_WARNING),this.isInFlyout||this.setDisabledReason(!r,`UNPARENTED_IFRETURN`)},FUNCTION_TYPES:[`procedures_defnoreturn`,`procedures_defreturn`,`procedures_defcustomreturn`,`procedures_defcustomnoreturn`]},s.forBlock.procedures_return=function(e,t){let n=``;if(t.STATEMENT_SUFFIX&&(n+=t.prefixLines(t.injectId(t.STATEMENT_SUFFIX,e),t.INDENT)),e.hasReturnValue_){let r=t.valueToCode(e,`VALUE`,o.NONE)||`null`;n+=`${t.INDENT}return ${r};\n`}else n+=`${t.INDENT}return;\n`;return n}}export{d as install};
@@ -1,4 +1,4 @@
1
- import{f as e,i as t,o as n,p as r,r as i,t as a}from"./blockly-fcfyKYzp.js";import{c as o,l as s}from"./index-PLY-IJik.js";import{c,d as l,i as u,l as d,r as f,s as p}from"./helpers-D5PdK4BS.js";function m(e,t){let n=parseFloat(e);return t===`min`?n*6e4:t===`sec`?n*1e3:n}function h(){let h=window.Blockly,g=h.Translate,_=window.getHelp;h.CustomBlocks=h.CustomBlocks||[],h.CustomBlocks.push(`Sendto`),h.Sendto={HUE:310,blocks:{}};let v=()=>new i(`FALSE`,function(e){this.getSourceBlock().updateShape_(f(e))});h.Sendto.blocks.sendto_custom=`<block type="sendto_custom"> <mutation xmlns="http://www.w3.org/1999/xhtml" items="parameter"></mutation> <field name="INSTANCE">admin.0</field> <field name="COMMAND">send</field> <field name="LOG"></field> <field name="WITH_STATEMENT">FALSE</field> <value name="ARG0"> <shadow type="text"> <field name="TEXT"></field> </shadow> </value></block>`,a.sendto_custom_container={init:function(){this.appendDummyInput().appendField(g(`sendto_custom_arguments`)),this.appendStatementInput(`STACK`),this.setColour(h.Sendto.HUE),this.setTooltip(g(`sendto_custom_arg_tooltip`)),this.contextMenu=!1}},a.sendto_custom_mutator={init:function(){this.appendDummyInput(`ATTR`).appendField(g(`sendto_custom_argument`)).appendField(new n(`parameter`),`ATTR`),this.setPreviousStatement(!0),this.setNextStatement(!0),this.setColour(h.Sendto.HUE),this.setTooltip(g(`sendto_custom_arg_tooltip`)),this.contextMenu=!1}},a.sendto_custom={init:function(){var r;let i=[];if((r=window.main)!=null&&r.instances){for(let e of window.main.instances){var a;if((a=window.main.objects[e])!=null&&(a=a.common)!=null&&a.messagebox){let t=e.substring(15);i.push([t,t])}}i.length||i.push([g(`sendto_no_instances`),``]),this.appendDummyInput(`INSTANCE`).appendField(g(`sendto_custom`)).appendField(new t(i),`INSTANCE`)}else this.appendDummyInput(`INSTANCE`).appendField(g(`sendto_custom`)).appendField(new n(`adapter.0`),`INSTANCE`);this.appendDummyInput(`COMMAND`).appendField(g(`sendto_custom_command`)).appendField(new n(`send`),`COMMAND`),this.appendDummyInput(`LOG`).appendField(g(`loglevel`)).appendField(new t(u()),`LOG`),this.appendDummyInput(`WITH_STATEMENT`).appendField(g(`with_results`)).appendField(v(),`WITH_STATEMENT`),this.attributes_=[],this.itemCount_=0,this.setMutator(new e.MutatorIcon([`sendto_custom_mutator`],this)),this.updateShape_(),this.setInputsInline(!1),this.setPreviousStatement(!0,null),this.setNextStatement(!0,null),this.setColour(h.Sendto.HUE),this.setTooltip(g(`sendto_custom_tooltip`)),this.setHelpUrl(_(`sendto_custom_help`))},mutationToDom:function(){let e=document.createElement(`mutation`);return e.setAttribute(`items`,this.attributes_.map(e=>encodeURIComponent(e)).join(`,`)),e},domToMutation:function(e){this.attributes_=e.getAttribute(`items`).split(`,`).map(e=>decodeURIComponent(e)),this.itemCount_=this.attributes_.length,this.updateShape_()},decompose:function(e){var t;let n=e.newBlock(`sendto_custom_container`);n.initSvg();let r=(t=n.getInput(`STACK`))==null?void 0:t.connection;for(let t=0;t<this.itemCount_;t++){let n=e.newBlock(`sendto_custom_mutator`);n.setFieldValue(this.attributes_[t],`ATTR`),n.initSvg(),r.connect(n.previousConnection),r=n.nextConnection}return n},compose:function(e){this.attributes_=[];let t=e.getInputTargetBlock(`STACK`),n=[];for(;t;)this.attributes_.push(t.getFieldValue(`ATTR`)),n.push(t.valueConnection_),t=t.nextConnection&&t.nextConnection.targetBlock();for(let e=0;e<this.itemCount_;e++){var r;let t=(r=this.getInput(`ARG${e}`))==null||(r=r.connection)==null?void 0:r.targetConnection;t&&!n.includes(t)&&t.disconnect()}this.itemCount_=n.length,this.itemCount_<0&&(this.itemCount_=0),this.updateShape_();for(let e=0;e<this.itemCount_;e++)d(n[e],this,`ARG${e}`)},saveConnections:function(e){let t=e.getInputTargetBlock(`STACK`),n=0;for(;t;){var r,i;t.valueConnection_=(r=this.getInput(`ARG${n}`))==null||(r=r.connection)==null?void 0:r.targetConnection,t=(i=t.nextConnection)==null?void 0:i.targetBlock(),n++}},updateShape_:function(e){let t=this.workspace;for(let e=0;e<this.itemCount_;e++){let n=this.getInput(`ARG${e}`);n?n.fieldRow.length>=1&&n.fieldRow[0].setValue(this.attributes_[e]):(n=this.appendValueInput(`ARG${e}`).setAlign(r.Align.RIGHT),n.appendField(this.attributes_[e])),setTimeout(e=>{var n;if(!((n=e.connection)!=null&&n.isConnected())){let n=t.newBlock(`text`);n.setShadow(!0),n.initSvg(),n.render(),n.outputConnection.connect(e.connection)}},100,n)}for(let e=this.itemCount_;this.getInput(`ARG${e}`);e++)this.removeInput(`ARG${e}`);l(this,e)}},s.forBlock.sendto_custom=function(e){let t=e,n=e.getFieldValue(`INSTANCE`),r=e.getFieldValue(`LOG`),i=e.getFieldValue(`COMMAND`),a=``,l;f(e.getFieldValue(`WITH_STATEMENT`))&&(l=s.statementToCode(e,`STATEMENT`));let u=[];for(let d=0;d<t.itemCount_;d++){let f=String(t.attributes_[d]),p=s.valueToCode(e,`ARG${d}`,o.COMMA);if(p&&p.startsWith(`'{`)&&p.endsWith(`}'`)&&(p=p.substring(1,p.length-1)),t.itemCount_===1&&!f)return r&&(a=`console.${r}('sendTo[custom] ${n}: ' + ${p});\n`),l?`sendTo('${n}', ${c(i)}, ${p}, async (result) => {\n${l}});\n${a}`:`sendTo('${n}', ${c(i)}, ${p});\n${a}`;u.push({attr:f.replace(/'/g,`\\'`),val:p})}let d=u.length?u.map(e=>s.prefixLines(`'${e.attr}': ${e.val},`,s.INDENT)).join(`
1
+ import{f as e,i as t,o as n,p as r,r as i,t as a}from"./blockly-fcfyKYzp.js";import{c as o,l as s}from"./index-B0FfAYMN.js";import{c,d as l,i as u,l as d,r as f,s as p}from"./helpers-DiwtLpXM.js";function m(e,t){let n=parseFloat(e);return t===`min`?n*6e4:t===`sec`?n*1e3:n}function h(){let h=window.Blockly,g=h.Translate,_=window.getHelp;h.CustomBlocks=h.CustomBlocks||[],h.CustomBlocks.push(`Sendto`),h.Sendto={HUE:310,blocks:{}};let v=()=>new i(`FALSE`,function(e){this.getSourceBlock().updateShape_(f(e))});h.Sendto.blocks.sendto_custom=`<block type="sendto_custom"> <mutation xmlns="http://www.w3.org/1999/xhtml" items="parameter"></mutation> <field name="INSTANCE">admin.0</field> <field name="COMMAND">send</field> <field name="LOG"></field> <field name="WITH_STATEMENT">FALSE</field> <value name="ARG0"> <shadow type="text"> <field name="TEXT"></field> </shadow> </value></block>`,a.sendto_custom_container={init:function(){this.appendDummyInput().appendField(g(`sendto_custom_arguments`)),this.appendStatementInput(`STACK`),this.setColour(h.Sendto.HUE),this.setTooltip(g(`sendto_custom_arg_tooltip`)),this.contextMenu=!1}},a.sendto_custom_mutator={init:function(){this.appendDummyInput(`ATTR`).appendField(g(`sendto_custom_argument`)).appendField(new n(`parameter`),`ATTR`),this.setPreviousStatement(!0),this.setNextStatement(!0),this.setColour(h.Sendto.HUE),this.setTooltip(g(`sendto_custom_arg_tooltip`)),this.contextMenu=!1}},a.sendto_custom={init:function(){var r;let i=[];if((r=window.main)!=null&&r.instances){for(let e of window.main.instances){var a;if((a=window.main.objects[e])!=null&&(a=a.common)!=null&&a.messagebox){let t=e.substring(15);i.push([t,t])}}i.length||i.push([g(`sendto_no_instances`),``]),this.appendDummyInput(`INSTANCE`).appendField(g(`sendto_custom`)).appendField(new t(i),`INSTANCE`)}else this.appendDummyInput(`INSTANCE`).appendField(g(`sendto_custom`)).appendField(new n(`adapter.0`),`INSTANCE`);this.appendDummyInput(`COMMAND`).appendField(g(`sendto_custom_command`)).appendField(new n(`send`),`COMMAND`),this.appendDummyInput(`LOG`).appendField(g(`loglevel`)).appendField(new t(u()),`LOG`),this.appendDummyInput(`WITH_STATEMENT`).appendField(g(`with_results`)).appendField(v(),`WITH_STATEMENT`),this.attributes_=[],this.itemCount_=0,this.setMutator(new e.MutatorIcon([`sendto_custom_mutator`],this)),this.updateShape_(),this.setInputsInline(!1),this.setPreviousStatement(!0,null),this.setNextStatement(!0,null),this.setColour(h.Sendto.HUE),this.setTooltip(g(`sendto_custom_tooltip`)),this.setHelpUrl(_(`sendto_custom_help`))},mutationToDom:function(){let e=document.createElement(`mutation`);return e.setAttribute(`items`,this.attributes_.map(e=>encodeURIComponent(e)).join(`,`)),e},domToMutation:function(e){this.attributes_=e.getAttribute(`items`).split(`,`).map(e=>decodeURIComponent(e)),this.itemCount_=this.attributes_.length,this.updateShape_()},decompose:function(e){var t;let n=e.newBlock(`sendto_custom_container`);n.initSvg();let r=(t=n.getInput(`STACK`))==null?void 0:t.connection;for(let t=0;t<this.itemCount_;t++){let n=e.newBlock(`sendto_custom_mutator`);n.setFieldValue(this.attributes_[t],`ATTR`),n.initSvg(),r.connect(n.previousConnection),r=n.nextConnection}return n},compose:function(e){this.attributes_=[];let t=e.getInputTargetBlock(`STACK`),n=[];for(;t;)this.attributes_.push(t.getFieldValue(`ATTR`)),n.push(t.valueConnection_),t=t.nextConnection&&t.nextConnection.targetBlock();for(let e=0;e<this.itemCount_;e++){var r;let t=(r=this.getInput(`ARG${e}`))==null||(r=r.connection)==null?void 0:r.targetConnection;t&&!n.includes(t)&&t.disconnect()}this.itemCount_=n.length,this.itemCount_<0&&(this.itemCount_=0),this.updateShape_();for(let e=0;e<this.itemCount_;e++)d(n[e],this,`ARG${e}`)},saveConnections:function(e){let t=e.getInputTargetBlock(`STACK`),n=0;for(;t;){var r,i;t.valueConnection_=(r=this.getInput(`ARG${n}`))==null||(r=r.connection)==null?void 0:r.targetConnection,t=(i=t.nextConnection)==null?void 0:i.targetBlock(),n++}},updateShape_:function(e){let t=this.workspace;for(let e=0;e<this.itemCount_;e++){let n=this.getInput(`ARG${e}`);n?n.fieldRow.length>=1&&n.fieldRow[0].setValue(this.attributes_[e]):(n=this.appendValueInput(`ARG${e}`).setAlign(r.Align.RIGHT),n.appendField(this.attributes_[e])),setTimeout(e=>{var n;if(!((n=e.connection)!=null&&n.isConnected())){let n=t.newBlock(`text`);n.setShadow(!0),n.initSvg(),n.render(),n.outputConnection.connect(e.connection)}},100,n)}for(let e=this.itemCount_;this.getInput(`ARG${e}`);e++)this.removeInput(`ARG${e}`);l(this,e)}},s.forBlock.sendto_custom=function(e){let t=e,n=e.getFieldValue(`INSTANCE`),r=e.getFieldValue(`LOG`),i=e.getFieldValue(`COMMAND`),a=``,l;f(e.getFieldValue(`WITH_STATEMENT`))&&(l=s.statementToCode(e,`STATEMENT`));let u=[];for(let d=0;d<t.itemCount_;d++){let f=String(t.attributes_[d]),p=s.valueToCode(e,`ARG${d}`,o.COMMA);if(p&&p.startsWith(`'{`)&&p.endsWith(`}'`)&&(p=p.substring(1,p.length-1)),t.itemCount_===1&&!f)return r&&(a=`console.${r}('sendTo[custom] ${n}: ' + ${p});\n`),l?`sendTo('${n}', ${c(i)}, ${p}, async (result) => {\n${l}});\n${a}`:`sendTo('${n}', ${c(i)}, ${p});\n${a}`;u.push({attr:f.replace(/'/g,`\\'`),val:p})}let d=u.length?u.map(e=>s.prefixLines(`'${e.attr}': ${e.val},`,s.INDENT)).join(`
2
2
  `):``;return r&&(a=`console.${r}('sendTo[custom] ${n}: ${u.length?u.map(e=>`${e.attr}: ' + ${e.val} + '`).join(`, `):`[no args]`}');\n`),l?`sendTo('${n}', ${c(i)}, {\n${d}\n}, async (result) => {\n${l}});\n${a}`:`sendTo('${n}', ${c(i)}, {\n${d}\n});\n${a}`},h.Sendto.blocks.sendto_otherscript=`<block type="sendto_otherscript"> <field name="INSTANCE">0</field> <field name="TIMEOUT">1000</field> <field name="UNIT">ms</field> <field name="MESSAGE">customMessage</field> <field name="WITH_STATEMENT">FALSE</field> <value name="OID"> <shadow type="field_oid_script"> <field name="oid">Script Object ID</field> </shadow> </value></block>`,a.sendto_otherscript={init:function(){var e;let r=[];if((e=window.main)!=null&&e.instances)for(let e of window.main.instances){let t=e.match(/^system\.adapter\.javascript\.(\d+)$/);if(t){let e=parseInt(t[1],10);r.push([`javascript.${e}`,String(e)])}}if(!r.length)for(let e=0;e<=4;e++)r.push([`javascript.${e}`,String(e)]);this.appendDummyInput(`NAME`).appendField(`✉️ ${g(`sendto_otherscript_name`)}`),this.appendDummyInput(`INSTANCE`).appendField(g(`sendto_otherscript_instance`)).appendField(new t(r),`INSTANCE`),this.appendValueInput(`OID`).appendField(g(`sendto_otherscript_script`)).setCheck(null),this.appendDummyInput().appendField(g(`sendto_otherscript_timeout`)).appendField(new n(`1000`),`TIMEOUT`).appendField(new t([[g(`timeouts_settimeout_ms`),`ms`],[g(`timeouts_settimeout_sec`),`sec`],[g(`timeouts_settimeout_min`),`min`]]),`UNIT`),this.appendDummyInput(`MESSAGE`).appendField(g(`sendto_otherscript_message`)).appendField(new n(`customMessage`),`MESSAGE`),this.appendValueInput(`DATA`).appendField(g(`sendto_otherscript_data`)),this.appendDummyInput(`WITH_STATEMENT`).appendField(g(`with_results`)).appendField(v(),`WITH_STATEMENT`),this.updateShape_(),this.setInputsInline(!1),this.setPreviousStatement(!0,null),this.setNextStatement(!0,null),this.setColour(h.Sendto.HUE),this.setTooltip(g(`sendto_otherscript_tooltip`)),this.setHelpUrl(_(`sendto_otherscript_help`))},updateShape_:function(e){l(this,e)}},s.forBlock.sendto_otherscript=function(e){let t=e.getFieldValue(`INSTANCE`),n=s.valueToCode(e,`OID`,o.ATOMIC),r=e.getFieldValue(`MESSAGE`),i=m(e.getFieldValue(`TIMEOUT`),e.getFieldValue(`UNIT`)),a;f(e.getFieldValue(`WITH_STATEMENT`))&&(a=s.statementToCode(e,`STATEMENT`));let l=p(n),u=s.valueToCode(e,`DATA`,o.ATOMIC)||`true`,d=`{ instance: ${t}, script: ${n}${l?` /* ${l} */`:``}, message: ${c(r)} }`;return a?`messageTo(${d}, ${u}, { timeout: ${i} }, (result) => {\n${a}})\n`:`messageTo(${d}, ${u}, { timeout: ${i} });\n`},h.Sendto.blocks.sendto_gethistory=`<block type="sendto_gethistory"> <field name="INSTANCE">default</field> <field name="AGGREGATE">none</field> <field name="STEP">0</field> <field name="COUNT">500</field> <field name="UNIT">min</field> <value name="OID"> <shadow type="field_oid"> </shadow> </value> <value name="START"> <shadow type="time_get_special"> <field name="TYPE">dayStart</field> </shadow> </value> <value name="END"> <shadow type="time_get_special"> <field name="TYPE">dayEnd</field> </shadow> </value></block>`,a.sendto_gethistory={init:function(){var e;let r=[[`default`,`default`]];if((e=window.main)!=null&&e.instances)for(let e of window.main.instances){let t=e.match(/^system\.adapter\.(history|influxdb|sql)\.(\d+)$/);if(t){let e=`${t[1]}.${t[2]}`;r.push([e,e])}}this.appendDummyInput(`NAME`).appendField(g(`sendto_gethistory_name`)),this.appendDummyInput(`INSTANCE`).appendField(g(`sendto_gethistory_instance`)).appendField(new t(r),`INSTANCE`),this.appendValueInput(`OID`).appendField(g(`sendto_gethistory_oid`)).setCheck(null),this.appendValueInput(`START`).appendField(g(`sendto_gethistory_start`)).setCheck(null),this.appendValueInput(`END`).appendField(g(`sendto_gethistory_end`)).setCheck(null),this.appendDummyInput(`AGGREGATE`).appendField(g(`sendto_gethistory_aggregate`)).appendField(new t([[g(`sendto_gethistory_none`),`none`],[g(`sendto_gethistory_minimum`),`min`],[g(`sendto_gethistory_maximum`),`max`],[g(`sendto_gethistory_avg`),`average`],[g(`sendto_gethistory_cnt`),`count`]]),`AGGREGATE`),this.appendDummyInput(`UNIT`).appendField(g(`sendto_gethistory_step`)).appendField(new n(`0`),`STEP`).appendField(new t([[g(`sendto_gethistory_ms`),`ms`],[g(`sendto_gethistory_sec`),`sec`],[g(`sendto_gethistory_min`),`min`],[g(`sendto_gethistory_hour`),`hour`],[g(`sendto_gethistory_day`),`day`]]),`UNIT`),this.appendDummyInput(`COUNT`).appendField(g(`sendto_gethistory_count`)).appendField(new n(`0`),`COUNT`),this.appendStatementInput(`STATEMENT`).setCheck(null),this.setInputsInline(!1),this.setPreviousStatement(!0,null),this.setNextStatement(!0,null),this.setColour(h.Sendto.HUE),this.setTooltip(g(`sendto_gethistory_tooltip`)),this.setHelpUrl(_(`sendto_gethistory_help`))}},s.forBlock.sendto_gethistory=function(e){let t=e.getFieldValue(`INSTANCE`),n=s.valueToCode(e,`OID`,o.ATOMIC),r=s.valueToCode(e,`START`,o.ATOMIC),i=s.valueToCode(e,`END`,o.ATOMIC),a=e.getFieldValue(`AGGREGATE`),l=e.getFieldValue(`UNIT`),u=parseInt(e.getFieldValue(`COUNT`),10),d=parseFloat(e.getFieldValue(`STEP`));l===`day`?d*=864e5:l===`hour`?d*=36e5:l===`min`?d*=6e4:l===`sec`&&(d*=1e3);let f=s.statementToCode(e,`STATEMENT`),m=p(n);return`getHistory(${t==="default"?``:`${c(t)}, `}{\n id: ${n}${m?` /* ${m} */`:``},\n start: ${r},\n end: ${i},\n`+(d>0&&a!==`none`?` step: ${d},\n`:``)+(d===0||a===`none`?` count: ${u},\n`:``)+` aggregate: '${a}',\n removeBorderValues: true,\n}, async (err, result) => {\n if (err) {\n console.error(err);\n`+(f?` } else {
3
3
  `:``)+(f?s.prefixLines(f,s.INDENT):``)+` }
4
4
  });
@@ -1,2 +1,2 @@
1
- import{f as e,t}from"./blockly-fcfyKYzp.js";import{c as n,l as r}from"./index-PLY-IJik.js";function i(){let i=window.Blockly.Translate;t.logic_switch_case={init:function(){this.appendValueInput(`CONDITION`).appendField(i(`logic_switch_case_is`)),this.appendValueInput(`CASECONDITION0`).appendField(i(`logic_switch_case_of`)),this.appendStatementInput(`CASE0`).appendField(i(`logic_switch_do`)),this.setMutator(new e.MutatorIcon([`case_incaseof`,`case_default`],this)),this.setPreviousStatement(!0),this.setNextStatement(!0),this.setColour(`%{BKY_LOGIC_HUE}`),this.setTooltip(i(`logic_switch_tooltip`)),this.caseCount_=0,this.defaultCount_=0},mutationToDom:function(){if(!this.caseCount_&&!this.defaultCount_)return null;let e=document.createElement(`mutation`);return this.caseCount_&&e.setAttribute(`case`,String(this.caseCount_)),this.defaultCount_&&e.setAttribute(`default`,`1`),e},domToMutation:function(e){this.caseCount_=parseInt(e.getAttribute(`case`),10),this.defaultCount_=parseInt(e.getAttribute(`default`),10);for(let e=1;e<=this.caseCount_;e++)this.appendValueInput(`CASECONDITION${e}`).appendField(i(`logic_switch_case_of`)),this.appendStatementInput(`CASE${e}`).appendField(i(`logic_switch_do`));this.defaultCount_&&this.appendStatementInput(`ONDEFAULT`).appendField(`default`)},decompose:function(e){var t;let n=e.newBlock(`control_case`);n.initSvg();let r=(t=n.getInput(`STACK`))==null?void 0:t.connection;for(let t=1;t<=this.caseCount_;t++){let t=e.newBlock(`case_incaseof`);t.initSvg(),r.connect(t.previousConnection),r=t.nextConnection}if(this.defaultCount_){let t=e.newBlock(`case_default`);t.initSvg(),r.connect(t.previousConnection)}return n},compose:function(e){this.defaultCount_&&this.removeInput(`ONDEFAULT`),this.defaultCount_=0;for(let e=this.caseCount_;e>0;e--)this.removeInput(`CASECONDITION${e}`),this.removeInput(`CASE${e}`);this.caseCount_=0;let t=e.getInputTargetBlock(`STACK`);for(;t;){switch(t.type){case`case_incaseof`:{this.caseCount_++;let e=this.appendValueInput(`CASECONDITION${this.caseCount_}`).appendField(i(`logic_switch_case_of`)),a=this.appendStatementInput(`CASE${this.caseCount_}`).appendField(i(`logic_switch_do`));if(t.valueConnection_){var n;(n=e.connection)==null||n.connect(t.valueConnection_)}if(t.statementConnection_){var r;(r=a.connection)==null||r.connect(t.statementConnection_)}break}case`case_default`:{this.defaultCount_++;let e=this.appendStatementInput(`ONDEFAULT`).appendField(`default`);if(t.statementConnection_){var a;(a=e.connection)==null||a.connect(t.statementConnection_)}break}default:throw`Unknown block type.`}t=t.nextConnection&&t.nextConnection.targetBlock()}},saveConnections:function(e){let t=e.getInputTargetBlock(`STACK`),n=1;for(;t;){var r;switch(t.type){case`case_incaseof`:{var i,a;let e=this.getInput(`CASECONDITION${n}`),r=this.getInput(`CASE${n}`);t.valueConnection_=e==null||(i=e.connection)==null?void 0:i.targetConnection,t.statementConnection_=r==null||(a=r.connection)==null?void 0:a.targetConnection,n++;break}case`case_default`:{var o;let e=this.getInput(`ONDEFAULT`);t.statementConnection_=e==null||(o=e.connection)==null?void 0:o.targetConnection;break}default:throw`Unknown block type`}t=(r=t.nextConnection)==null?void 0:r.targetBlock()}}},t.control_case={init:function(){this.appendDummyInput().appendField(i(`logic_switch_case_is`)),this.appendStatementInput(`STACK`),this.setColour(`%{BKY_LOGIC_HUE}`),this.setTooltip(i(`logic_switch_control_case_tooltip`)),this.contextMenu=!1}},t.case_incaseof={init:function(){this.appendDummyInput().appendField(i(`logic_switch_case_of`)),this.setPreviousStatement(!0),this.setNextStatement(!0),this.setColour(`%{BKY_LOGIC_HUE}`),this.setTooltip(i(`logic_switch_case_incaseof_tooltip`)),this.contextMenu=!1}},t.case_default={init:function(){this.appendDummyInput().appendField(`default`),this.setPreviousStatement(!0),this.setNextStatement(!1),this.setColour(`%{BKY_LOGIC_HUE}`),this.setTooltip(i(`logic_switch_default_tooltip`)),this.contextMenu=!1}},r.forBlock.logic_switch_case=function(e){let t=e,i=``,a,o,s=r.valueToCode(e,`CONDITION`,n.NONE)||null;if(s){if(/^\(?([._$\d\w"'?: ()])*\)?$/g.test(s)){i=`\nswitch (${s}) {\n`;let c=r.valueToCode(e,`CASECONDITION0`,n.NONE)||null,l=r.statementToCode(e,`CASE0`);i+=`\tcase ${c}:\n${l}\n\t\tbreak;\n`;for(let s=1;s<=t.caseCount_;s++)o=r.valueToCode(e,`CASECONDITION${s}`,n.NONE)||null,o&&(a=r.statementToCode(e,`CASE${s}`),i+=`\tcase ${o}:\n${a}\n\t\tbreak;\n`);t.defaultCount_&&(a=r.statementToCode(e,`ONDEFAULT`),i+=`\tdefault:\n${a}\n\t\tbreak;\n`),i+=`}
1
+ import{f as e,t}from"./blockly-fcfyKYzp.js";import{c as n,l as r}from"./index-B0FfAYMN.js";function i(){let i=window.Blockly.Translate;t.logic_switch_case={init:function(){this.appendValueInput(`CONDITION`).appendField(i(`logic_switch_case_is`)),this.appendValueInput(`CASECONDITION0`).appendField(i(`logic_switch_case_of`)),this.appendStatementInput(`CASE0`).appendField(i(`logic_switch_do`)),this.setMutator(new e.MutatorIcon([`case_incaseof`,`case_default`],this)),this.setPreviousStatement(!0),this.setNextStatement(!0),this.setColour(`%{BKY_LOGIC_HUE}`),this.setTooltip(i(`logic_switch_tooltip`)),this.caseCount_=0,this.defaultCount_=0},mutationToDom:function(){if(!this.caseCount_&&!this.defaultCount_)return null;let e=document.createElement(`mutation`);return this.caseCount_&&e.setAttribute(`case`,String(this.caseCount_)),this.defaultCount_&&e.setAttribute(`default`,`1`),e},domToMutation:function(e){this.caseCount_=parseInt(e.getAttribute(`case`),10),this.defaultCount_=parseInt(e.getAttribute(`default`),10);for(let e=1;e<=this.caseCount_;e++)this.appendValueInput(`CASECONDITION${e}`).appendField(i(`logic_switch_case_of`)),this.appendStatementInput(`CASE${e}`).appendField(i(`logic_switch_do`));this.defaultCount_&&this.appendStatementInput(`ONDEFAULT`).appendField(`default`)},decompose:function(e){var t;let n=e.newBlock(`control_case`);n.initSvg();let r=(t=n.getInput(`STACK`))==null?void 0:t.connection;for(let t=1;t<=this.caseCount_;t++){let t=e.newBlock(`case_incaseof`);t.initSvg(),r.connect(t.previousConnection),r=t.nextConnection}if(this.defaultCount_){let t=e.newBlock(`case_default`);t.initSvg(),r.connect(t.previousConnection)}return n},compose:function(e){this.defaultCount_&&this.removeInput(`ONDEFAULT`),this.defaultCount_=0;for(let e=this.caseCount_;e>0;e--)this.removeInput(`CASECONDITION${e}`),this.removeInput(`CASE${e}`);this.caseCount_=0;let t=e.getInputTargetBlock(`STACK`);for(;t;){switch(t.type){case`case_incaseof`:{this.caseCount_++;let e=this.appendValueInput(`CASECONDITION${this.caseCount_}`).appendField(i(`logic_switch_case_of`)),a=this.appendStatementInput(`CASE${this.caseCount_}`).appendField(i(`logic_switch_do`));if(t.valueConnection_){var n;(n=e.connection)==null||n.connect(t.valueConnection_)}if(t.statementConnection_){var r;(r=a.connection)==null||r.connect(t.statementConnection_)}break}case`case_default`:{this.defaultCount_++;let e=this.appendStatementInput(`ONDEFAULT`).appendField(`default`);if(t.statementConnection_){var a;(a=e.connection)==null||a.connect(t.statementConnection_)}break}default:throw`Unknown block type.`}t=t.nextConnection&&t.nextConnection.targetBlock()}},saveConnections:function(e){let t=e.getInputTargetBlock(`STACK`),n=1;for(;t;){var r;switch(t.type){case`case_incaseof`:{var i,a;let e=this.getInput(`CASECONDITION${n}`),r=this.getInput(`CASE${n}`);t.valueConnection_=e==null||(i=e.connection)==null?void 0:i.targetConnection,t.statementConnection_=r==null||(a=r.connection)==null?void 0:a.targetConnection,n++;break}case`case_default`:{var o;let e=this.getInput(`ONDEFAULT`);t.statementConnection_=e==null||(o=e.connection)==null?void 0:o.targetConnection;break}default:throw`Unknown block type`}t=(r=t.nextConnection)==null?void 0:r.targetBlock()}}},t.control_case={init:function(){this.appendDummyInput().appendField(i(`logic_switch_case_is`)),this.appendStatementInput(`STACK`),this.setColour(`%{BKY_LOGIC_HUE}`),this.setTooltip(i(`logic_switch_control_case_tooltip`)),this.contextMenu=!1}},t.case_incaseof={init:function(){this.appendDummyInput().appendField(i(`logic_switch_case_of`)),this.setPreviousStatement(!0),this.setNextStatement(!0),this.setColour(`%{BKY_LOGIC_HUE}`),this.setTooltip(i(`logic_switch_case_incaseof_tooltip`)),this.contextMenu=!1}},t.case_default={init:function(){this.appendDummyInput().appendField(`default`),this.setPreviousStatement(!0),this.setNextStatement(!1),this.setColour(`%{BKY_LOGIC_HUE}`),this.setTooltip(i(`logic_switch_default_tooltip`)),this.contextMenu=!1}},r.forBlock.logic_switch_case=function(e){let t=e,i=``,a,o,s=r.valueToCode(e,`CONDITION`,n.NONE)||null;if(s){if(/^\(?([._$\d\w"'?: ()])*\)?$/g.test(s)){i=`\nswitch (${s}) {\n`;let c=r.valueToCode(e,`CASECONDITION0`,n.NONE)||null,l=r.statementToCode(e,`CASE0`);i+=`\tcase ${c}:\n${l}\n\t\tbreak;\n`;for(let s=1;s<=t.caseCount_;s++)o=r.valueToCode(e,`CASECONDITION${s}`,n.NONE)||null,o&&(a=r.statementToCode(e,`CASE${s}`),i+=`\tcase ${o}:\n${a}\n\t\tbreak;\n`);t.defaultCount_&&(a=r.statementToCode(e,`ONDEFAULT`),i+=`\tdefault:\n${a}\n\t\tbreak;\n`),i+=`}
2
2
  `}else alert(`logic_switch_case: ${s} is not a variable name`)}return i}}export{i as install};