@camstack/addon-admin-ui 1.2.457 → 1.2.458
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AddonAssetIcon-BOcwQMt3.js → AddonAssetIcon-arpH1jD8.js} +1 -1
- package/dist/assets/{Addons-BrsHM2rE.js → Addons-HbtgQft-.js} +1 -1
- package/dist/assets/{AdminPage-0E8EpSO9.js → AdminPage-BjrFg6FM.js} +1 -1
- package/dist/assets/{AdminSectionedPage-CxodN1sn.js → AdminSectionedPage-DxQ2pH4Y.js} +1 -1
- package/dist/assets/{AiProfiles-EJziTK6H.js → AiProfiles-BdzPXclT.js} +1 -1
- package/dist/assets/{BrokerForm-Dbs6DDhN.js → BrokerForm-DEL7JPI4.js} +1 -1
- package/dist/assets/Build-DNm-26dy.js +40 -0
- package/dist/assets/{Calendars-DwIn1aCE.js → Calendars-Cw-Q6N0f.js} +1 -1
- package/dist/assets/{Cluster-FzZaIb80.js → Cluster-CUox6xE3.js} +1 -1
- package/dist/assets/ClusterStepModel-BSI39thg.js +1 -0
- package/dist/assets/CompositionEditor-B3e76JM9.js +1 -0
- package/dist/assets/{CompositionEditorPage-I6-ghm-F.js → CompositionEditorPage-DnCUuqEl.js} +1 -1
- package/dist/assets/{Data-CWXYjuUH.js → Data-IEAE-8BN.js} +1 -1
- package/dist/assets/DeviceDetail-MmjrNM7o.js +2 -0
- package/dist/assets/{DeviceDoActionFields-XK5u9sG-.js → DeviceDoActionFields-BRZweXYw.js} +1 -1
- package/dist/assets/{Devices-CPoElWdX.js → Devices-BtjFXXD8.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-CwqeH_Vp.js → EmbedPlayerPage-DmA2dyRs.js} +1 -1
- package/dist/assets/{History-146ywVRO.js → History-Csgt6RnT.js} +1 -1
- package/dist/assets/Identity-DmdFLJiQ.js +1 -0
- package/dist/assets/{IntegrationDetail-CUffTwqo.js → IntegrationDetail-DsIRBJ-F.js} +1 -1
- package/dist/assets/{IntegrationHub-DAndpOVJ.js → IntegrationHub-DTFQyFFN.js} +1 -1
- package/dist/assets/{Integrations-DaNoA1oi.js → Integrations-3Dm1BWSC.js} +1 -1
- package/dist/assets/{Integrations-DrSNiPXr.js → Integrations-CPsVHs77.js} +1 -1
- package/dist/assets/{Library-BMJeDfUP.js → Library-CsCzamEb.js} +1 -1
- package/dist/assets/{Locations-DpWQPPRR.js → Locations-BmYKJdte.js} +2 -2
- package/dist/assets/{Logs-ClfIrCg_.js → Logs-BfeyENDk.js} +1 -1
- package/dist/assets/{MaskShapeCanvas-BACSOVPv.js → MaskShapeCanvas-tNwtlAOM.js} +1 -1
- package/dist/assets/{MotionZonesSettings-C-BWiqKl.js → MotionZonesSettings-C8j_gawX.js} +1 -1
- package/dist/assets/{MyAccess-B2mddc8z.js → MyAccess-CQtGUeMl.js} +1 -1
- package/dist/assets/{Network-CCpscaUS.js → Network-C_cYS-fR.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-J8GvbAOS.js → NodeAddonsSettingsPanel-BgUAqnzo.js} +1 -1
- package/dist/assets/Notifications-Bp7cRi1y.js +1 -0
- package/dist/assets/{PrivacyMaskSettings-_hgbaRHe.js → PrivacyMaskSettings-Dpr5kjzL.js} +1 -1
- package/dist/assets/{Recordings-CmuOayrH.js → Recordings-DEsoK17t.js} +1 -1
- package/dist/assets/{ScanNetworkModal-CHpDtEMN.js → ScanNetworkModal-CHmBk64D.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-DNX5LjxD.js → SceneMonitorEditor-_NtH_gGA.js} +1 -1
- package/dist/assets/{SessionsList-CO2JCtUA.js → SessionsList-CRE59_h3.js} +1 -1
- package/dist/assets/{Showroom-C1Cx5rmM.js → Showroom-CpcQ_noP.js} +1 -1
- package/dist/assets/{System-8QdXWXlv.js → System-Cmlqjd1R.js} +1 -1
- package/dist/assets/{Terminal-D-QqW5OC.js → Terminal-B2_h39vc.js} +1 -1
- package/dist/assets/{Viewer-DEkhIs_o.js → Viewer-BY7zR9zQ.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DXRH_g5-.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BByWRJ1W.js} +1 -1
- package/dist/assets/{addon-icons-context-r4-8qNuL.js → addon-icons-context-C4CUqZFb.js} +1 -1
- package/dist/assets/{archive-CHNksUXE.js → archive-D-IttKbd.js} +1 -1
- package/dist/assets/{authed-media-CLfNNAcR.js → authed-media-BH09w7mx.js} +1 -1
- package/dist/assets/{bell-off-BQUuLgGa.js → bell-off-esSw14-4.js} +1 -1
- package/dist/assets/{board-model-CCKjMnih.js → board-model-CzpY9jow.js} +1 -1
- package/dist/assets/{boxes-OM3WXXCF.js → boxes-DLm9pV7A.js} +1 -1
- package/dist/assets/circle-slash-DUiMT2dc.js +1 -0
- package/dist/assets/client-BI85kkig.js +358 -0
- package/dist/assets/{cloud-upload-DnQzN7Zu.js → cloud-upload-CmlXZ47L.js} +1 -1
- package/dist/assets/crop-DFOEm7GN.js +1 -0
- package/dist/assets/{device-integration-icon-T6DuiFIe.js → device-integration-icon-BBk1BbPA.js} +1 -1
- package/dist/assets/device-picker-model-B-2vVHUA.js +1 -0
- package/dist/assets/dist-DmOQydcE.js +358 -0
- package/dist/assets/{dist-DWpE4F9Y.js → dist-DyazYmMR.js} +1 -1
- package/dist/assets/{eraser-2zvTICay.js → eraser-plwpovOj.js} +1 -1
- package/dist/assets/{hard-drive-download-BuPae4i9.js → hard-drive-download-B8wIgrJR.js} +1 -1
- package/dist/assets/{hostInit-B0H8YgMs.js → hostInit-u9GmPoX9.js} +1 -1
- package/dist/assets/i18n-DCSomJiP.js +1 -0
- package/dist/assets/{icons-Bf1g4TTU.js → icons-Dkn5asvl.js} +1 -1
- package/dist/assets/index-DPvkuJxO.js +4 -0
- package/dist/assets/{key-y1dQIrgn.js → key-CA18pL-8.js} +1 -1
- package/dist/assets/{key-round-PVl1EIeU.js → key-round-C7R-scbw.js} +1 -1
- package/dist/assets/{layers-BvTBL45e.js → layers-BxsydRGi.js} +1 -1
- package/dist/assets/{linked-devices-model-NEAloVak.js → linked-devices-model-BLcQ9yAI.js} +1 -1
- package/dist/assets/{list-ordered-Cy6LNkX7.js → list-ordered-DnwKxGIw.js} +1 -1
- package/dist/assets/{location-owned-usage-COJFqP2Z.js → location-owned-usage-CuK_nCoP.js} +1 -1
- package/dist/assets/{log-in-C8bG6uHT.js → log-in-Bf5RUTf4.js} +1 -1
- package/dist/assets/{memory-stick-DgCbrom_.js → memory-stick-B59QUWgK.js} +1 -1
- package/dist/assets/{message-square-plus-T2Q-JaNP.js → message-square-plus-Ckmg1y08.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-fa03047b.js → mf-entry-bootstrap-0-547cfa14.js} +2 -2
- package/dist/assets/{mic-off-CQXTB132.js → mic-off-CsCgSoDy.js} +1 -1
- package/dist/assets/{monitor-off-CvP-Xwqs.js → monitor-off-BwsLAWve.js} +1 -1
- package/dist/assets/{monitor-smartphone-DgPyh0bq.js → monitor-smartphone-G--2aBuy.js} +1 -1
- package/dist/assets/mount-B-2vVHUA.js +1 -0
- package/dist/assets/notification-schedule-field-C6qs47JN.js +1 -0
- package/dist/assets/{player-overlays-DTcu3p6k.js → player-overlays-BTnXgs6l.js} +1 -1
- package/dist/assets/{recycle-BgfATMDb.js → recycle-f9jOE7g7.js} +1 -1
- package/dist/assets/remoteEntry-BA9oATqv.js +1 -0
- package/dist/assets/{scan-eye-Cw7uLDDg.js → scan-eye-CC4mTfUp.js} +1 -1
- package/dist/assets/{scissors-GZwoMkJz.js → scissors-BNEM1Ztl.js} +1 -1
- package/dist/assets/{search-x-mGDaYxQw.js → search-x-3m2MRtEu.js} +1 -1
- package/dist/assets/{send-B4zTG8IX.js → send-D6irwubo.js} +1 -1
- package/dist/assets/{settings-2-7MkaO5_9.js → settings-2-B_7_TLiY.js} +1 -1
- package/dist/assets/{speaker-iZgcW4qe.js → speaker-CBOD08Ii.js} +1 -1
- package/dist/assets/src-B_ik3sNc.js +67 -0
- package/dist/assets/{timer-reset-CZOKA6Qu.js → timer-reset-BmRk3MOl.js} +1 -1
- package/dist/assets/{ungroup-CmTgkman.js → ungroup-CtlTayH1.js} +1 -1
- package/dist/assets/{unlink-DgTv7GBL.js → unlink-8-ZUzI25.js} +1 -1
- package/dist/assets/{usb-CDpFB3qV.js → usb-DRY8JHaQ.js} +1 -1
- package/dist/assets/{use-scenes-feed-Xf26vjq3.js → use-scenes-feed-Bnlc0umC.js} +1 -1
- package/dist/assets/{use-stationary-objects-piZ9a4go.js → use-stationary-objects-CSaIphB2.js} +1 -1
- package/dist/assets/useEventInvalidation-B-2vVHUA.js +1 -0
- package/dist/assets/{useNodeUrlSelection-Bmr7pzZ8.js → useNodeUrlSelection-UerjxtpH.js} +1 -1
- package/dist/assets/user-round-D65mcWwX.js +1 -0
- package/dist/assets/{user-x-DG-dacDQ.js → user-x-DWSR4aIw.js} +1 -1
- package/dist/assets/{video-DSWn6X4v.js → video-BRH0aO3l.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-9bgJ3bqj.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-VnpYmyAv.js} +2 -2
- package/dist/index.html +10 -10
- package/dist/server/addon.js +78 -199
- package/package.json +1 -1
- package/dist/assets/Build-G3WNIoIu.js +0 -40
- package/dist/assets/ClusterStepModel-BKwbYUSr.js +0 -1
- package/dist/assets/CompositionEditor-Du0918m6.js +0 -1
- package/dist/assets/DeviceDetail-DEN9C3es.js +0 -2
- package/dist/assets/Identity-NsWnwCVn.js +0 -1
- package/dist/assets/Notifications-CJvDmENV.js +0 -1
- package/dist/assets/circle-slash-B-qX3Tzf.js +0 -1
- package/dist/assets/client-Tf7DwHzR.js +0 -358
- package/dist/assets/crop-BXCCBrRT.js +0 -1
- package/dist/assets/device-picker-model-CJDjbyFR.js +0 -1
- package/dist/assets/dist-COc-M7x5.js +0 -358
- package/dist/assets/i18n-dPXh_JKN.js +0 -1
- package/dist/assets/index-k7RW-84l.js +0 -4
- package/dist/assets/mount-CJDjbyFR.js +0 -1
- package/dist/assets/notification-schedule-field-DXLce27m.js +0 -1
- package/dist/assets/remoteEntry-T1NwEQgU.js +0 -1
- package/dist/assets/src-CxF5mieK.js +0 -67
- package/dist/assets/useEventInvalidation-CJDjbyFR.js +0 -1
- package/dist/assets/user-round-XpdQk1Uf.js +0 -1
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import{$ as e,B as t,G as n,J as r,L as i,N as a,S as o,T as s,a as c,b as l,q as u,t as d,x as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{An as p,Fn as m,It as h,Nt as g,Zi as _,kn as v,or as y,ot as b,pi as x,pn as S,pt as C,qi as w,sa as T,vn as E,wr as D,xi as O,yi as k}from"./player-overlays-DTcu3p6k.js";import{$i as A,Ir as j,Kr as M,Lr as N,Qr as P,Rr as F,Zr as I,ei as ee,fi as L,ii as R,ni as z,ri as B,sn as V,ti as te,zr as ne}from"./client-Tf7DwHzR.js";import{t as re}from"./boxes-OM3WXXCF.js";import{n as ie,r as ae,t as oe}from"./ungroup-CmTgkman.js";import{s as se}from"./video-DSWn6X4v.js";import{Ar as ce,Au as le,Mn as ue,Mu as de,Nu as H,Ou as U,Rr as W,Wt as fe,Za as pe,Zt as me,_n as G,aa as he,ca as ge,dt as _e,en as ve,fa as ye,fr as K,ga as be,gn as xe,ha as Se,hr as q,ht as Ce,ju as we,la as Te,lt as Ee,ma as De,pa as Oe,sa as ke,sr as Ae,un as je}from"./src-CxF5mieK.js";import{t as J}from"./i18n-dPXh_JKN.js";import{t as Y}from"./useTranslation-D3Is_4B6.js";import{G as Me,Q as Ne,T as Pe,Z as X,nt as Fe,v as Ie,z as Le}from"./index-k7RW-84l.js";import{t as Re}from"./AdminSectionedPage-CxodN1sn.js";import{t as ze}from"./DeviceDoActionFields-XK5u9sG-.js";import{E as Be,O as Ve,t as He}from"./CompositionEditor-Du0918m6.js";var Ue=`const AUTOMATION_RECIPE =`,We=`// EJECTED from the visual automation editor — this file is now hand-owned.
|
|
2
|
-
// The recipe that produced it was removed with it, on purpose: while it was
|
|
3
|
-
// here the editor could re-open this block and overwrite everything below.`;function Ge(e){return e.includes(Ue)}function Ke(e){let t=e.indexOf(Ue);if(t<0)return null;let n=e.indexOf(`{`,t+25);if(n<0)return null;let r=0,i=!1,a=!1;for(let o=n;o<e.length;o+=1){let s=e.charAt(o);if(i){a?a=!1:s===`\\`?a=!0:s===`"`&&(i=!1);continue}if(s===`"`){i=!0;continue}if(s===`{`)r+=1;else if(s===`}`&&(--r,r===0))return{declStart:t,literalEnd:o+1,json:e.slice(n,o+1)}}return null}function qe(e){let t=Ke(e);if(t===null)return{ok:!1,reason:J.t(`helpers.recipeFromCode.noLiteral`)};let n;try{n=JSON.parse(t.json)}catch(e){let t=e instanceof Error?e.message:String(e);return{ok:!1,reason:J.t(`helpers.recipeFromCode.badJson`,{detail:t})}}let r=te.safeParse(n);if(!r.success){let e=r.error.issues[0];return{ok:!1,reason:e===void 0?J.t(`helpers.recipeFromCode.schemaMismatch`):J.t(`helpers.recipeFromCode.schemaMismatchAt`,{path:e.path.join(`.`),message:e.message})}}return{ok:!0,recipe:r.data}}function Je(e){let t=Ke(e);if(t===null)return e;let n=e.slice(t.literalEnd),r=/^\s*as\s+const/.exec(n),i=t.literalEnd+(r===null?0:r[0].length);return`${e.slice(0,t.declStart)}${We}${e.slice(i)}`}e();var Ye=6e4;function Xe(){let e=pe({projection:`slim`});return n(()=>(e.data??[]).filter(e=>V(String(e.type))).map(e=>({id:e.id,name:e.name,stableId:e.stableId,type:String(e.type),location:e.location??null})).toSorted((e,t)=>e.name.localeCompare(t.name)),[e.data])}function Ze(e){let t=b();return c({queryKey:[`automation`,`wireable-fields`,e],enabled:e>0,staleTime:Ye,queryFn:async()=>(await t.trpcClient.deviceManager.getWireableFields.query({deviceId:e})).caps})}function Qe(e,t){return e.find(e=>e.cap===t)?.fields??[]}function Z({children:e}){return f(`span`,{className:`mb-1 block text-xs text-foreground-subtle`,children:e})}function $e(e){let t=Ze(e.deviceId);if(t.data!==void 0)return Qe(t.data,e.cap).find(t=>t.path===e.fieldPath)}function et({value:e,devices:t,onChange:n}){let{t:r}=Y(),i=Ze(e.deviceId),a=i.data??[],s=Qe(a,e.cap);return o(l,{children:[o(`label`,{className:`min-w-[10rem] flex-1`,children:[f(Z,{children:r(`automation.fieldPicker.device`,`Device`)}),f(U,{value:String(e.deviceId),onChange:e=>n({deviceId:Number(e.target.value),cap:``,fieldPath:``}),options:[{value:`0`,label:r(`automation.fieldPicker.selectADevice`,`Select a device…`)},...t.map(e=>({value:String(e.id),label:e.name}))]})]}),o(`label`,{className:`min-w-[9rem] flex-1`,children:[f(Z,{children:r(`automation.fieldPicker.capability`,`Capability`)}),f(U,{value:e.cap,disabled:e.deviceId===0,onChange:t=>n({...e,cap:t.target.value,fieldPath:``}),options:[{value:``,label:tt(e.deviceId,a.length,i.isLoading)},...a.map(e=>({value:e.cap,label:e.cap}))]})]}),o(`label`,{className:`min-w-[9rem] flex-1`,children:[f(Z,{children:r(`automation.fieldPicker.field`,`Field`)}),f(U,{value:e.fieldPath,disabled:e.cap===``,onChange:t=>n({...e,fieldPath:t.target.value}),options:[{value:``,label:s.length===0?r(`automation.fieldPicker.noReadableFields`,`No readable fields`):r(`automation.fieldPicker.selectAField`,`Select a field…`)},...s.map(e=>({value:e.path,label:`${e.path} (${e.kind})`}))]})]})]})}function tt(e,t,n){return e===0?J.t(`automation.fieldPicker.pickDeviceFirst`):n?J.t(`automation.fieldPicker.readingDevice`):t===0?J.t(`automation.fieldPicker.noReadableCaps`):J.t(`automation.fieldPicker.selectCap`)}var nt=[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`,`contains`,`in`];function rt(e){switch(e){case`boolean`:return[`eq`,`ne`];case`number`:return[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`];case`string`:case`enum`:return[`eq`,`ne`,`contains`,`in`];default:return nt}}function it(e){switch(e){case`eq`:return J.t(`helpers.recipeParts.op_eq`);case`ne`:return J.t(`helpers.recipeParts.op_ne`);case`gt`:return J.t(`helpers.recipeParts.op_gt`);case`gte`:return J.t(`helpers.recipeParts.op_gte`);case`lt`:return J.t(`helpers.recipeParts.op_lt`);case`lte`:return J.t(`helpers.recipeParts.op_lte`);case`contains`:return J.t(`helpers.recipeParts.op_contains`);default:return J.t(`helpers.recipeParts.op_in`)}}function at(e){return rt(e).map(e=>({value:e,label:it(e)}))}function ot(e){switch(e){case`device-state`:return J.t(`helpers.recipeParts.trigger_device_state`);case`device-event`:return J.t(`helpers.recipeParts.trigger_device_event`);case`schedule`:return J.t(`helpers.recipeParts.trigger_schedule`);default:return J.t(`helpers.recipeParts.trigger_manual`)}}var st={triggers:[],actions:[]};function ct(e){switch(e){case`device-state`:return{kind:e,deviceId:0,cap:``,fieldPath:``};case`device-event`:return{kind:e,category:``};case`schedule`:return{kind:e,cron:`0 30 23 * * *`};default:return{kind:`manual`}}}function lt(e){switch(e){case`wait`:return{kind:e,seconds:5};case`code`:return{kind:e,code:`// runs inside this automation, with ctx in scope
|
|
4
|
-
`};default:return{kind:`cap`,deviceId:0,cap:``,method:``}}}function ut(){return{kind:`condition`,deviceId:0,cap:``,fieldPath:``,operator:`eq`,value:``}}function dt(){return{kind:`expression`,expr:``,bindings:{}}}function ft(e,t,n){return e.map((e,r)=>r===t?n:e)}function pt(e,t){return e.filter((e,n)=>n!==t)}function mt(e,t,n){let r=e[t];if(r===void 0)return e;let i=Math.min(Math.max(n,0),e.length-1);if(i===t)return e;let a=pt(e,t);return[...a.slice(0,i),r,...a.slice(i)]}function ht(e,t){return{...e,triggers:[...t]}}function gt(e,t){return{...e,actions:[...t]}}var _t=[{value:`cap`,labelKey:`automation.actionList.kindCap`},{value:`wait`,labelKey:`automation.actionList.kindWait`},{value:`code`,labelKey:`automation.actionList.kindCode`}];function vt({actions:e,devices:t,devicesState:n=`answered`,onChange:r}){let{t:i}=Y();return o(`div`,{className:`space-y-2`,children:[e.length===0&&f(`p`,{className:`text-xs text-warning`,children:i(`automation.actionList.noActionsYetAnAutomation`,`No actions yet. An automation that does nothing is not an automation.`)}),e.map((a,s)=>o(`div`,{className:`rounded border border-border p-3 space-y-2`,children:[o(`div`,{className:`flex flex-wrap items-end gap-2`,children:[f(W,{variant:`default`,children:s+1}),o(`label`,{className:`w-40`,children:[f(Z,{children:i(`automation.actionList.step`,`Step`)}),f(U,{value:a.kind,onChange:t=>r(ft(e,s,lt(yt(t.target.value)))),options:_t.map(e=>({value:e.value,label:i(e.labelKey)}))})]}),o(`div`,{className:`ml-auto flex items-center gap-1`,children:[f(q,{variant:`ghost`,disabled:s===0,onClick:()=>r(mt(e,s,s-1)),title:i(`automation.actionList.runThisStepEarlier`,`Run this step earlier`),children:f(w,{className:`h-3.5 w-3.5`})}),f(q,{variant:`ghost`,disabled:s===e.length-1,onClick:()=>r(mt(e,s,s+1)),title:i(`automation.actionList.runThisStepLater`,`Run this step later`),children:f(_,{className:`h-3.5 w-3.5`})}),f(q,{variant:`ghost`,onClick:()=>r(pt(e,s)),title:i(`automation.actionList.removeThisStep`,`Remove this step`),children:f(h,{className:`h-3.5 w-3.5`})})]})]}),a.kind===`wait`&&o(`label`,{className:`block w-32`,children:[f(Z,{children:i(`automation.actionList.seconds`,`Seconds`)}),f(H,{type:`number`,min:0,max:300,value:String(a.seconds),onChange:t=>r(ft(e,s,{kind:`wait`,seconds:Number(t.target.value)}))})]}),a.kind===`code`&&o(`label`,{className:`block`,children:[f(Z,{children:i(`automation.actionList.code`,`Code`)}),f(`textarea`,{className:`h-32 w-full rounded-md border border-border bg-surface p-2 font-mono text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,value:a.code,spellCheck:!1,onChange:t=>r(ft(e,s,{kind:`code`,code:t.target.value}))}),f(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:f(X,{i18nKey:`automation.actionList.codeHint`,components:{code:f(`code`,{})}})})]}),a.kind===`cap`&&f(xt,{action:a,devices:t,devicesState:n,onChange:t=>r(ft(e,s,t))})]},`${a.kind}-${String(s)}`)),o(`div`,{className:`flex items-center gap-2`,children:[o(q,{variant:`outline`,onClick:()=>r([...e,lt(`cap`)]),children:[f(v,{className:`h-4 w-4`}),` `,i(`automation.actionList.addStep`)]}),e.length>1&&f(`span`,{className:`text-xs text-foreground-subtle`,children:i(`automation.actionList.stepsRunInOrderAnd`,`Steps run in order and stop at the first failure.`)})]})]})}function yt(e){return _t.find(t=>t.value===e)?.value??`cap`}function bt(e){return typeof e==`number`?e:typeof e==`object`&&e&&`$var`in e?{$var:e.$var}:[...e]}function xt({action:e,devices:t,devicesState:n,onChange:r}){return f(ze,{value:e,allowTriggerDevice:!0,allowMultiSameFamily:!0,devices:t,listState:n,onChange:e=>r({kind:`cap`,deviceId:bt(e.deviceId),cap:e.cap,method:e.method,...e.args===void 0?{}:{args:{...e.args}}})})}function St({value:e,field:t,onChange:n}){let{t:r}=Y();return t?.kind===`boolean`?f(U,{value:e===!0?`true`:`false`,onChange:e=>n(e.target.value===`true`),options:[{value:`true`,label:r(`common.true`)},{value:`false`,label:r(`common.false`)}]}):t?.kind===`enum`&&t.enumValues!==void 0&&t.enumValues.length>0?f(U,{value:String(e),onChange:e=>n(e.target.value),options:t.enumValues.map(e=>({value:e,label:e}))}):t?.kind===`number`?f(H,{type:`number`,value:typeof e==`number`?String(e):``,placeholder:`0`,onChange:e=>{let t=Number(e.target.value);e.target.value!==``&&!Number.isNaN(t)&&n(t)}}):f(H,{value:String(e),placeholder:r(`common.valueWord`),onChange:e=>n(e.target.value)})}function Ct({value:e,field:t,onChange:n}){let{t:r}=Y();return f(H,{value:e.join(`, `),placeholder:r(`automation.valueInput.oneTwoThree`,`one, two, three`),onChange:e=>{let r=e.target.value.split(`,`).map(e=>e.trim()).filter(e=>e!==``);n(t?.kind===`number`?r.map(e=>Number(e)).filter(e=>!Number.isNaN(e)):r)}})}function wt(e){return typeof e==`object`}function Tt(e){return wt(e)?e[0]??``:e}function Et(e){return wt(e)?e:typeof e==`boolean`?[]:[e]}function Dt({leaf:e,devices:t,onChange:n}){let{t:r}=Y(),i={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=$e(i),s=at(a?.kind),c=e.operator===`in`,l=t=>{n({...e,deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath})},u=t=>{let r=Ot(t,s);n({...e,operator:r,value:r===`in`?Et(e.value):Tt(e.value)})};return o(`div`,{className:`flex flex-wrap items-end gap-2`,children:[f(et,{value:i,devices:t,onChange:l}),o(`label`,{className:`min-w-[8rem]`,children:[f(Z,{children:r(`automation.conditionRow.comparison`,`Comparison`)}),f(U,{value:e.operator,onChange:e=>u(e.target.value),options:s.map(e=>({value:e.value,label:e.label}))})]}),o(`label`,{className:`min-w-[9rem] flex-1`,children:[f(Z,{children:r(`automation.conditionRow.value`,`Value`)}),c?f(Ct,{value:Et(e.value),field:a,onChange:t=>n({...e,value:t})}):f(St,{value:Tt(e.value),field:a,onChange:t=>n({...e,value:t})})]})]})}function Ot(e,t){return t.find(t=>t.value===e)?.value??`eq`}var kt={kind:`global`,sourceStableId:``,cap:``,fieldPath:``};function At({leaf:e,devices:t,onChange:n}){let{t:r}=Y(),i=Object.entries(e.bindings),a=t=>{n({kind:`expression`,expr:e.expr,bindings:t})};return o(`div`,{className:`space-y-2`,children:[o(`label`,{className:`block`,children:[f(Z,{children:r(`automation.expressionLeafRow.expression`,`Expression`)}),f(H,{value:e.expr,placeholder:r(`automation.expressionLeafRow.indoorOutdoor5`,`indoor - outdoor > 5`),onChange:t=>n({kind:`expression`,expr:t.target.value,bindings:e.bindings})}),f(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:r(`automation.expressionLeafRow.mustEvaluateToTrueOr`,`Must evaluate to true or false. Every name in it has to be bound below — an unbound name is refused when the automation is saved, not when it runs.`)})]}),o(`div`,{className:`space-y-1.5`,children:[i.length===0&&f(`p`,{className:`text-xs text-foreground-subtle`,children:r(`automation.expressionLeafRow.noNamesBoundYetAn`,`No names bound yet. An expression reads devices only through these.`)}),i.map(([n,r])=>f(jt,{alias:n,source:r,devices:t,onRename:t=>a(Lt(e.bindings,n,t)),onChange:t=>a({...e.bindings,[n]:t}),onRemove:()=>a(Rt(e.bindings,n))},n)),o(q,{variant:`ghost`,onClick:()=>a({...e.bindings,[It(e.bindings)]:kt}),children:[f(v,{className:`h-3.5 w-3.5`}),` `,r(`common.name`)]})]})]})}function jt({alias:e,source:t,devices:n,onRename:r,onChange:i,onRemove:a}){let{t:s}=Y(),c=t.kind===`literal`,l=c?{deviceId:0,cap:``,fieldPath:``}:{deviceId:Pt(n,Nt(t)),cap:t.cap,fieldPath:t.fieldPath};return o(`div`,{className:`flex flex-wrap items-end gap-2 rounded border border-border p-2`,children:[o(`label`,{className:`w-32`,children:[f(Z,{children:s(`automation.expressionLeafRow.name`,`Name`)}),f(H,{value:e,placeholder:s(`automation.expressionLeafRow.aliasExample`),onChange:e=>r(e.target.value)})]}),o(`label`,{className:`w-36`,children:[f(Z,{children:s(`automation.expressionLeafRow.reads`,`Reads`)}),f(U,{value:c?`literal`:`global`,onChange:e=>i(e.target.value===`literal`?{kind:`literal`,value:``}:kt),options:[{value:`global`,label:s(`automation.expressionLeafRow.aDeviceField`,`A device field`)},{value:`literal`,label:s(`automation.expressionLeafRow.aConstant`,`A constant`)}]})]}),c?o(`label`,{className:`min-w-[9rem] flex-1`,children:[f(Z,{children:s(`automation.expressionLeafRow.constant`,`Constant`)}),f(H,{value:t.value===null?``:String(t.value),placeholder:`5`,onChange:e=>i({kind:`literal`,value:Mt(e.target.value)})})]}):f(et,{value:l,devices:n,onChange:e=>i({kind:`global`,sourceStableId:Ft(n,e.deviceId),cap:e.cap,fieldPath:e.fieldPath})}),f(q,{variant:`ghost`,onClick:a,title:s(`automation.expressionLeafRow.removeThisName`,`Remove this name`),children:f(h,{className:`h-3.5 w-3.5`})})]})}function Mt(e){let t=e.trim();return t===`true`?!0:t===`false`?!1:t!==``&&!Number.isNaN(Number(t))?Number(t):e}function Nt(e){return e.kind===`global`?e.sourceStableId:``}function Pt(e,t){return e.find(e=>e.stableId===t)?.id??0}function Ft(e,t){return e.find(e=>e.id===t)?.stableId??``}function It(e){for(let t=0;t<26;t+=1){let n=String.fromCharCode(97+t);if(!(n in e))return n}return`n${String(Object.keys(e).length)}`}function Lt(e,t,n){let r={};for(let[i,a]of Object.entries(e))i===t?r[n]=a:r[i]=a;return r}function Rt(e,t){let n={};for(let[r,i]of Object.entries(e))r!==t&&(n[r]=i);return n}function zt(e){return e.kind===`all`||e.kind===`any`}function Q(e){let t=e.conditions;return t===void 0?{kind:`all`,children:[]}:zt(t)?t:{kind:`all`,children:[t]}}function Bt(e,t){return t===null||zt(t)&&t.children.length===0?{triggers:e.triggers,actions:e.actions}:{triggers:e.triggers,actions:e.actions,conditions:t}}function Vt(e){return Bt(e,Q(e))}function Ht(e,t){if(t.length===0)return e;let[n,...r]=t;if(n===void 0)return e;if(e.kind===`not`)return n===0?Ht(e.child,r):null;if(!zt(e))return null;let i=e.children[n];return i===void 0?null:Ht(i,r)}function Ut(e,t,n){if(t.length===0)return n(e);let[r,...i]=t;if(r===void 0)return n(e);if(e.kind===`not`){if(r!==0)return e;let t=Ut(e.child,i,n);return t===null?null:{kind:`not`,child:t}}if(!zt(e))return e;let a=e.children[r];if(a===void 0)return e;let o=Ut(a,i,n),s=o===null?[...e.children.slice(0,r),...e.children.slice(r+1)]:[...e.children.slice(0,r),o,...e.children.slice(r+1)];return s.length===0?null:{kind:e.kind,children:s}}function Wt(e){return e===null?null:R({triggers:[{kind:`manual`}],actions:[{kind:`wait`,seconds:0}],conditions:e})}function Gt(e){let t=Q(e);return{depth:t.children.length===0?0:z(t),leaves:t.children.length===0?0:B(t),depthLimit:3,leafLimit:32}}function Kt(e,t){let n=Wt(t);return n===null?{ok:!0,recipe:Bt(e,t)}:{ok:!1,reason:n}}function qt(e,t){let n=Q(e);return Kt(e,{kind:n.kind,children:[...n.children,t]})}function Jt(e,t,n){return Bt(e,Ut(Q(e),t,()=>n))}function Yt(e,t){return Bt(e,Ut(Q(e),t,()=>null))}function Xt(e,t,n){return Bt(e,Ut(Q(e),t,e=>zt(e)?{kind:n,children:e.children}:e))}function Zt(e,t){return Ht(Q(e),t)===null?{ok:!1,reason:J.t(`helpers.recipeOps.rowGone`)}:Kt(e,Ut(Q(e),t,e=>e.kind===`not`?e.child:{kind:`not`,child:e}))}function Qt(e){if(e.length===0)return null;let t=e[e.length-1];return t===void 0?null:{path:e.slice(0,-1),index:t}}function $t(e,t,n){if(t.length<2)return{ok:!1,reason:J.t(`helpers.recipeOps.selectTwo`)};if(new Set(t.map(e=>e.slice(0,-1).join(`/`))).size!==1)return{ok:!1,reason:J.t(`helpers.recipeOps.differentGroups`)};let r=Qt(t[0]??[]);if(r===null)return{ok:!1,reason:J.t(`helpers.recipeOps.rootGroup`)};let i=Q(e),a=Ht(i,r.path);if(a===null||!zt(a))return{ok:!1,reason:J.t(`helpers.recipeOps.insideNot`)};let o=[...t.map(e=>e[e.length-1]??-1)].sort((e,t)=>e-t),s=o.map(e=>a.children[e]).filter(e=>e!==void 0);if(s.length!==o.length)return{ok:!1,reason:J.t(`helpers.recipeOps.selectedGone`)};let c=a.children.filter((e,t)=>!o.includes(t)),l=o[0]??0,u={kind:n,children:s},d={kind:a.kind,children:[...c.slice(0,l),u,...c.slice(l)]};return Kt(e,Ut(i,r.path,()=>d))}function en(e,t){if(t.length===0)return{ok:!1,reason:J.t(`helpers.recipeOps.outerNotGroup`)};let n=Q(e),r=Ht(n,t);if(r===null)return{ok:!1,reason:J.t(`helpers.recipeOps.groupGone`)};if(r.kind===`not`)return Kt(e,Ut(n,t,()=>r.child));if(!zt(r))return{ok:!1,reason:J.t(`helpers.recipeOps.rowIsCondition`)};let i=Qt(t);if(i===null)return{ok:!1,reason:J.t(`helpers.recipeOps.noParent`)};let a=Ht(n,i.path);if(a===null||!zt(a))return{ok:!1,reason:J.t(`helpers.recipeOps.groupInNot`)};let o={kind:a.kind,children:[...a.children.slice(0,i.index),...r.children,...a.children.slice(i.index+1)]};return Kt(e,Ut(n,i.path,()=>o))}e();var tn=[{value:`all`,labelKey:`automation.conditionTree.allOf`},{value:`any`,labelKey:`automation.conditionTree.anyOf`}];function nn(e){return e.join(`/`)}function rn(e){return e===``?[]:e.split(`/`).map(e=>Number(e))}function an({recipe:e,devices:t,onChange:i}){let{t:a}=Y(),[s,c]=r([]),[l,u]=r(null),d=Q(e),p=Gt(e),m=n(()=>s.map(rn),[s]),h=e=>{if(!e.ok){u(e.reason);return}u(null),c([]),i(e.recipe)},g=$t(e,m,`all`),_=$t(e,m,`any`),y=m.length===1?Zt(e,m[0]??[]):{ok:!1,reason:a(`automation.conditionTree.selectOneNegate`)},b={devices:t,selected:new Set(s),onToggleSelect:e=>c(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),onUpdate:(t,n)=>i(Jt(e,t,n)),onRemove:t=>{c([]),i(Yt(e,t))},onSetKind:(t,n)=>i(Xt(e,t,n)),onUngroup:t=>h(en(e,t))};return o(`div`,{className:`space-y-2`,children:[o(`div`,{className:`flex flex-wrap items-center gap-2`,children:[f(W,{variant:`default`,children:a(`automation.conditionTree.andOnlyIf`,`And only if`)}),f(`div`,{className:`w-32`,children:f(U,{value:d.kind,onChange:t=>i(Xt(e,[],on(t.target.value))),options:tn.map(e=>({value:e.value,label:a(e.labelKey)}))})}),f(`span`,{className:`text-xs text-foreground-subtle`,children:a(`automation.conditionTree.budget`,{depth:p.depth,depthLimit:p.depthLimit,leaves:p.leaves,leafLimit:p.leafLimit})})]}),d.children.length===0?f(`p`,{className:`text-xs text-foreground-subtle`,children:a(`automation.conditionTree.noConditionsTheActionsRun`,`No conditions. The actions run every time a trigger fires.`)}):f(sn,{container:d,path:[],handlers:b}),o(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(q,{variant:`outline`,onClick:()=>h(qt(e,ut())),title:a(`automation.conditionTree.compareOneDeviceFieldTo`,`Compare one device field to a value`),children:[f(v,{className:`h-4 w-4`}),` `,a(`automation.conditionTree.addCondition`)]}),o(q,{variant:`outline`,onClick:()=>h(qt(e,dt())),title:a(`automation.conditionTree.arithmeticAcrossDeviceFieldsThe`,`Arithmetic across device fields — the bounded expression engine`),children:[f(ae,{className:`h-4 w-4`}),` `,a(`automation.conditionTree.addExpression`)]}),f(`span`,{className:`mx-1 h-5 w-px bg-border`}),f(q,{variant:`ghost`,disabled:!g.ok,onClick:()=>h(g),title:g.ok?a(`automation.conditionTree.allSelectedRowsMustBe`,`All selected rows must be true`):g.reason,children:a(`automation.conditionTree.groupAsAll`,`Group as ALL`)}),f(q,{variant:`ghost`,disabled:!_.ok,onClick:()=>h(_),title:_.ok?a(`automation.conditionTree.anyOneOfTheSelected`,`Any one of the selected rows is enough`):_.reason,children:a(`automation.conditionTree.groupAsAny`,`Group as ANY`)}),f(q,{variant:`ghost`,disabled:!y.ok,onClick:()=>h(y),title:y.ok?a(`automation.conditionTree.invertTheSelectedRow`,`Invert the selected row`):y.reason,children:`NOT`}),s.length>0&&f(`span`,{className:`text-xs text-foreground-subtle`,children:a(`common.selectedCount`,{count:s.length})})]}),l!==null&&f(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-2 text-xs text-warning`,children:l})]})}function on(e){return e===`any`?`any`:`all`}function sn({container:e,path:t,handlers:n}){return f(`div`,{className:`space-y-1.5`,children:e.children.map((e,r)=>f(cn,{node:e,path:[...t,r],handlers:n},nn([...t,r])))})}function cn({node:e,path:t,handlers:n}){let{t:r}=Y(),i=nn(t),a=f(ue,{checked:n.selected.has(i),onChange:()=>n.onToggleSelect(i),"aria-label":r(`automation.conditionTree.selectThisRowForGrouping`,`Select this row for grouping`)});return zt(e)?o(`div`,{className:`rounded border border-border bg-surface-subtle/40 p-2`,children:[o(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[a,f(`div`,{className:`w-32`,children:f(U,{value:e.kind,onChange:e=>n.onSetKind(t,on(e.target.value)),options:tn.map(e=>({value:e.value,label:r(e.labelKey)}))})}),o(q,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:r(`automation.conditionTree.dissolveThisGroupKeepingIts`,`Dissolve this group, keeping its rows`),children:[f(oe,{className:`h-3.5 w-3.5`}),` `,r(`automation.conditionTree.ungroup`)]}),f(q,{variant:`ghost`,onClick:()=>n.onRemove(t),title:r(`automation.conditionTree.deleteThisGroupAndEverything`,`Delete this group and everything in it`),children:f(h,{className:`h-3.5 w-3.5`})})]}),f(`div`,{className:`pl-4`,children:f(sn,{container:e,path:t,handlers:n})})]}):e.kind===`not`?o(`div`,{className:`rounded border border-border p-2`,children:[o(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[a,f(W,{variant:`warning`,children:`NOT`}),o(q,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:r(`automation.conditionTree.removeTheNotKeepingThe`,`Remove the NOT, keeping the row`),children:[f(oe,{className:`h-3.5 w-3.5`}),` `,r(`automation.conditionTree.removeNot`)]})]}),f(`div`,{className:`pl-4`,children:f(cn,{node:e.child,path:[...t,0],handlers:n})})]}):o(`div`,{className:`flex items-start gap-2 rounded border border-border p-2`,children:[f(`div`,{className:`pt-6`,children:a}),f(`div`,{className:`min-w-0 flex-1`,children:e.kind===`condition`?f(Dt,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)}):f(At,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)})}),f(q,{variant:`ghost`,onClick:()=>n.onRemove(t),title:r(`automation.conditionTree.removeThisCondition`,`Remove this condition`),children:f(h,{className:`h-3.5 w-3.5`})})]})}e();function ln({code:e,error:t,canEject:n,ejecting:i,onEject:a}){let{t:s}=Y(),[c,l]=r(!1),u=ce(),d=async()=>{await u({title:s(`automation.generatedCodePanel.ejectToCodeThisCannot`,`Eject to code — this cannot be undone`),message:s(`automation.generatedCodePanel.theRecipeIsRemovedFrom`,`The recipe is removed from the block and it becomes an ordinary script. The visual editor will no longer open it, and there is no way back to it except authoring a new automation from scratch. The code itself is kept exactly as it is now.`),confirmLabel:s(`automation.generatedCodePanel.ejectToCode`,`Eject to code`),cancelLabel:s(`automation.generatedCodePanel.keepItVisual`,`Keep it visual`),variant:`warning`})&&a()};return o(`div`,{className:`rounded border border-border`,children:[o(`div`,{className:`flex flex-wrap items-center gap-2 px-3 py-2`,children:[o(q,{variant:`ghost`,onClick:()=>l(!c),children:[f(c?O:k,{className:`h-4 w-4`}),s(`automation.generatedCodePanel.generatedCode`,`Generated code`)]}),f(`span`,{className:`text-xs text-foreground-subtle`,children:s(`automation.generatedCodePanel.derivedFromTheRecipeAbove`,`Derived from the recipe above — regenerated on every save, never edited here.`)}),o(q,{className:`ml-auto`,variant:`ghost`,disabled:!n||e===null||i,onClick:()=>void d(),title:n?s(`automation.generatedCodePanel.takePermanentOwnershipOfThis`,`Take permanent ownership of this code as a script`):s(`automation.generatedCodePanel.saveTheAutomationFirstThere`,`Save the automation first — there is no stored block to eject yet`),children:[f(se,{className:`h-4 w-4`}),` `,s(`automation.generatedCodePanel.eject`)]})]}),c&&f(`div`,{className:`border-t border-border p-3`,children:e===null?f(`p`,{className:`text-xs text-warning`,children:t??s(`automation.generatedCodePanel.theRecipeIsNotComplete`,`The recipe is not complete enough to generate a block yet.`)}):f(je,{maxHeight:420,children:e})})]})}var un=[`device-state`,`device-event`,`schedule`,`manual`],dn=Object.values(A).sort((e,t)=>e.localeCompare(t));function fn({triggers:e,devices:t,onChange:n}){let{t:r}=Y();return o(`div`,{className:`space-y-2`,children:[e.length===0&&f(`p`,{className:`text-xs text-warning`,children:r(`automation.triggerEditor.noTriggersYetWithoutOne`,`No triggers yet. Without one nothing can ever start this automation — not even "Run actions", which needs a manual trigger to have somewhere to arrive.`)}),e.map((r,i)=>f(pn,{trigger:r,devices:t,position:i,onChange:t=>n(ft(e,i,t)),onRemove:()=>n(pt(e,i))},`${r.kind}-${String(i)}`)),o(q,{variant:`outline`,onClick:()=>n([...e,ct(`device-state`)]),title:r(`automation.triggerEditor.addAnotherWayThisAutomation`,`Add another way this automation can start`),children:[f(v,{className:`h-4 w-4`}),` `,r(`automation.triggerEditor.trigger`)]})]})}function pn({trigger:e,devices:t,position:n,onChange:r,onRemove:i}){let{t:a}=Y();return o(`div`,{className:`rounded border border-border p-3`,children:[o(`div`,{className:`flex flex-wrap items-end gap-2`,children:[f(W,{variant:`default`,children:n===0?a(`automation.triggerEditor.when`,`When`):a(`automation.triggerEditor.orWhen`,`or when`)}),o(`label`,{className:`min-w-[13rem] flex-1`,children:[f(Z,{children:a(`automation.triggerEditor.trigger`,`Trigger`)}),f(U,{value:e.kind,onChange:e=>r(ct(mn(e.target.value))),options:un.map(e=>({value:e,label:ot(e)}))})]}),f(q,{variant:`ghost`,onClick:i,title:a(`automation.triggerEditor.removeThisTrigger`,`Remove this trigger`),children:f(h,{className:`h-4 w-4`})})]}),o(`div`,{className:`mt-2 flex flex-wrap items-end gap-2`,children:[e.kind===`device-state`&&f(gn,{trigger:e,devices:t,onChange:r}),e.kind===`device-event`&&f(vn,{trigger:e,devices:t,onChange:r}),e.kind===`schedule`&&o(`label`,{className:`min-w-[14rem] flex-1`,children:[f(Z,{children:a(`automation.triggerEditor.cronExpression`,`Cron expression`)}),f(H,{value:e.cron,placeholder:`0 30 23 * * *`,onChange:e=>r({kind:`schedule`,cron:e.target.value})}),f(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:f(X,{i18nKey:`automation.triggerEditor.cronHint`,components:{code:f(`code`,{})}})})]}),e.kind===`manual`&&f(`p`,{className:`text-xs text-foreground-subtle`,children:f(X,{i18nKey:`automation.triggerEditor.manualHint`,components:{b:f(`strong`,{})}})})]})]})}function mn(e){return un.find(t=>t===e)??`manual`}function hn(e,t){return{kind:`device-state`,deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath,...t.becomes===void 0?{}:{becomes:t.becomes},...t.edge===void 0?{}:{edge:t.edge},...t.forMs===void 0?{}:{forMs:t.forMs},...t.debounceMs===void 0?{}:{debounceMs:t.debounceMs}}}function gn({trigger:e,devices:t,onChange:n}){let{t:r}=Y(),i={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=$e(i),s={...e.becomes===void 0?{}:{becomes:e.becomes},...e.edge===void 0?{}:{edge:e.edge},...e.forMs===void 0?{}:{forMs:e.forMs},...e.debounceMs===void 0?{}:{debounceMs:e.debounceMs}};return o(l,{children:[f(et,{value:i,devices:t,onChange:e=>n(hn(e,s))}),o(`div`,{className:`min-w-[11rem] flex-1`,children:[f(Z,{children:r(`automation.triggerEditor.becomes`,`Becomes`)}),o(`div`,{className:`flex items-center gap-2`,children:[o(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[f(ue,{checked:e.becomes===void 0,onChange:e=>n(hn(i,{...s,...e.target.checked?{becomes:void 0}:{becomes:``}}))}),r(`automation.triggerEditor.anyChange`,`any change`)]}),e.becomes!==void 0&&f(St,{value:e.becomes,field:a,onChange:e=>n(hn(i,{...s,becomes:e}))})]})]}),o(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[f(ue,{checked:e.edge===!0,onChange:e=>n(hn(i,{...s,...e.target.checked?{edge:!0}:{edge:void 0}}))}),r(`automation.triggerEditor.onlyOnAChange`,`only on a change`)]}),o(`label`,{className:`w-28`,children:[f(Z,{children:r(`automation.triggerEditor.heldForS`,`Held for (s)`)}),f(H,{type:`number`,min:0,value:e.forMs===void 0?``:String(e.forMs/1e3),placeholder:`0`,onChange:e=>n(hn(i,{...s,forMs:_n(e.target.value)}))})]}),o(`label`,{className:`w-28`,children:[f(Z,{children:r(`automation.triggerEditor.debounceS`,`Debounce (s)`)}),f(H,{type:`number`,min:0,value:e.debounceMs===void 0?``:String(e.debounceMs/1e3),placeholder:`0`,onChange:e=>n(hn(i,{...s,debounceMs:_n(e.target.value)}))})]})]})}function _n(e){if(e.trim()===``)return;let t=Number(e);if(!(Number.isNaN(t)||t<0))return Math.round(t*1e3)}function vn({trigger:e,devices:t,onChange:n}){let{t:r}=Y();return o(l,{children:[o(`label`,{className:`min-w-[15rem] flex-1`,children:[f(Z,{children:r(`automation.triggerEditor.eventCategory`,`Event category`)}),f(U,{value:e.category,onChange:t=>n({kind:`device-event`,category:t.target.value,...e.deviceId===void 0?{}:{deviceId:e.deviceId}}),options:[{value:``,label:r(`automation.triggerEditor.selectAnEvent`,`Select an event…`)},...dn.map(e=>({value:e,label:e}))]})]}),o(`label`,{className:`min-w-[11rem] flex-1`,children:[f(Z,{children:r(`automation.triggerEditor.fromDevice`,`From device`)}),f(U,{value:e.deviceId===void 0?``:String(e.deviceId),onChange:t=>n({kind:`device-event`,category:e.category,...t.target.value===``?{}:{deviceId:Number(t.target.value)}}),options:[{value:``,label:r(`automation.triggerEditor.anyDevice`,`Any device`)},...t.map(e=>({value:String(e.id),label:e.name}))]})]})]})}e();var yn=`hub`;function bn({existing:e,initialRecipe:t,saving:i,saveError:a,ejecting:s,onSave:c,onEject:l,onCancel:u}){let{t:d}=Y(),[p,m]=r(e?.name??``),[h,g]=r(()=>Vt(t)),[_,v]=r(!1),b=Xe(),x=R(h),C=n(()=>Sn(h),[h]),w=n(()=>Cn(p.trim()===``?`Untitled automation`:p.trim(),h),[p,h]),T=p.trim()===``,E=T||x!==null||C!==null||w.code===null;return o(`div`,{className:`space-y-4`,children:[f(`div`,{className:`flex flex-wrap items-center gap-2`,children:f(W,{variant:`info`,children:d(`automation.automationEditor.runsOnTheHub`,`runs on the hub`)})}),o(`label`,{className:`block max-w-md text-sm`,children:[f(`span`,{className:`text-foreground-subtle`,children:d(`automation.automationEditor.name`,`Name`)}),f(H,{className:`mt-1`,value:p,onChange:e=>m(e.target.value),placeholder:d(`automation.automationEditor.whatThisAutomationDoes`,`What this automation does`)})]}),f(xn,{step:`1`,title:d(`automation.automationEditor.when`,`When`),subtitle:d(`automation.automationEditor.anyOneOfTheseStarts`,`Any one of these starts a run.`),children:f(fn,{triggers:h.triggers,devices:b,onChange:e=>g(ht(h,e))})}),f(xn,{step:`2`,title:d(`automation.automationEditor.andOnlyIf`,`And only if`),subtitle:d(`automation.automationEditor.checkedAfterATriggerFires`,`Checked after a trigger fires. Nothing runs unless this is true.`),children:f(an,{recipe:h,devices:b,onChange:g})}),f(xn,{step:`3`,title:d(`automation.automationEditor.then`,`Then`),subtitle:d(`automation.automationEditor.inThisOrderStoppingAt`,`In this order, stopping at the first failure.`),children:f(vt,{actions:h.actions,devices:b,onChange:e=>g(gt(h,e))})}),f(ln,{code:w.code,error:w.error,canEject:e!==null,ejecting:s,onEject:l}),x!==null&&f(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:x}),x===null&&C!==null&&f(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:C}),a!==null&&f(`p`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:a}),o(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(q,{onClick:()=>{w.code!==null&&c({name:p.trim(),code:w.code,enabled:e?.enabled??!0,placement:yn})},disabled:i||E,children:[i&&f(y,{className:`h-4 w-4 animate-spin`}),` `,d(`common.save`)]}),o(q,{variant:`ghost`,onClick:()=>v(!_),disabled:e===null,title:e===null?d(`automation.automationEditor.logsAppearOnceTheAutomation`,`Logs appear once the automation has been saved and started`):d(`automation.automationEditor.showThisAutomationSProcess`,`Show this automation's process logs`),"data-testid":`automation-logs-toggle`,children:[f(S,{className:`h-4 w-4`}),` `,d(`common.logs`),` `,_?`▾`:`▸`]}),f(q,{variant:`ghost`,onClick:u,disabled:i,children:d(`common.close`,`Close`)}),T&&f(W,{variant:`warning`,children:d(`automation.automationEditor.nameRequired`,`Name required`)})]}),_&&e!==null&&o(`div`,{className:`rounded border border-border`,"data-testid":`automation-logs-panel`,children:[f(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:f(X,{i18nKey:`common.logsOf`,values:{id:j(e.id)},components:{code:f(`code`,{})}})}),f(me,{addonId:j(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function xn({step:e,title:t,subtitle:n,children:r}){return o(`section`,{className:`border-l-2 border-border pl-4`,children:[o(`div`,{className:`mb-2 flex flex-wrap items-baseline gap-2`,children:[f(`span`,{className:`text-xs font-mono text-foreground-subtle`,children:e}),f(`h4`,{className:`text-sm font-medium uppercase tracking-wide`,children:t}),f(`span`,{className:`text-xs text-foreground-subtle`,children:n})]}),r]})}function Sn(e){let t=te.safeParse(e);if(t.success)return null;let n=t.error.issues[0];return n===void 0?J.t(`helpers.automationEditor.incomplete`):`${n.path.length===0?``:`${n.path.join(`.`)}: `}${n.message}`}function Cn(e,t){try{return{code:ee({name:e,recipe:t}),error:null}}catch(e){return{code:null,error:e instanceof Error?e.message:String(e)}}}function wn(e){if(!e.enabled)return{tone:`idle`,label:J.t(`helpers.coreBlockStatus.disabled`),detail:J.t(`helpers.coreBlockStatus.disabledDetail`)};switch(e.status){case`running`:return{tone:`ok`,label:J.t(`helpers.coreBlockStatus.running`),detail:J.t(`helpers.coreBlockStatus.runningDetail`)};case`starting`:return{tone:`pending`,label:J.t(`helpers.coreBlockStatus.starting`),detail:e.lastError??J.t(`helpers.coreBlockStatus.startingDetail`)};case`failed`:return{tone:`error`,label:J.t(`helpers.coreBlockStatus.failed`),detail:e.lastError??J.t(`helpers.coreBlockStatus.failedDetail`)};default:return{tone:`error`,label:J.t(`helpers.coreBlockStatus.notRunning`),detail:e.lastError??J.t(`helpers.coreBlockStatus.notRunningDetail`)}}}function Tn(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function En(e,t){let n=e.find(e=>e.id===t.id);return n===void 0?t:n.updatedAt>=t.updatedAt?n:t}function Dn(e){let t=e=>{let t=wn(e).tone;return t===`error`?0:t===`pending`?1:t===`ok`?2:3};return[...e].sort((e,n)=>t(e)-t(n)||e.name.localeCompare(n.name))}function On(e){if(e.length===0)return J.t(`helpers.coreBlockStatus.noBlocks`);let t=e.filter(e=>wn(e).tone===`error`).length,n=e.filter(e=>wn(e).tone===`ok`).length,r=[J.t(`helpers.coreBlockStatus.blocks`,{count:e.length})];return n>0&&r.push(J.t(`helpers.coreBlockStatus.runningCount`,{count:n})),t>0&&r.push(J.t(`helpers.coreBlockStatus.notRunningCount`,{count:t})),r.join(` · `)}function kn({block:e,busy:t,confirming:n,logsOpen:r,unreadable:i,onEdit:a,onToggle:s,onToggleLogs:c,onAskDelete:l,onCancelDelete:u,onConfirmDelete:d}){let g=T(),{t:_}=Y(),v=wn(e),y=fe(e.updatedAt,g);return o(`li`,{className:`flex flex-col gap-2 p-3`,children:[o(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[o(`div`,{className:`min-w-0 flex-1`,children:[o(`div`,{className:`flex flex-wrap items-center gap-2`,children:[f(`span`,{className:`truncate font-medium`,children:e.name}),f(W,{variant:Tn(v.tone),children:v.label}),y!==null&&f(`span`,{className:`text-xs text-foreground-subtle`,children:_(`common.edited`,{when:y})})]}),f(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:v.detail}),i!==null&&f(`p`,{className:`mt-0.5 text-xs text-warning`,children:_(`automation.editor.listUnreadable`,{reason:i})})]}),n?o(`div`,{className:`flex justify-end gap-1`,children:[f(`span`,{className:`text-xs text-foreground-subtle`,children:_(`automation.automationList.deleteThisAutomation`,`Delete this automation?`)}),f(q,{variant:`danger`,onClick:e=>{e.stopPropagation(),d()},disabled:t,children:_(`common.delete`,`Delete`)}),f(q,{variant:`ghost`,onClick:e=>{e.stopPropagation(),u()},children:_(`common.cancel`,`Cancel`)})]}):o(`div`,{className:`flex justify-end gap-1`,children:[f(q,{variant:`ghost`,onClick:e=>{e.stopPropagation(),a()},disabled:i!==null,title:i===null?_(`common.edit`,`Edit`):_(`automation.automationList.thisBlockCannotBeOpened`,`This block cannot be opened visually`),children:f(m,{className:`h-4 w-4`})}),o(le,{children:[f(de,{children:f(q,{variant:`ghost`,disabled:!0,title:_(`automation.automationList.runActions`,`Run actions`),children:f(p,{className:`h-4 w-4`})})}),f(we,{children:_(`automation.automationList.runningAnAutomationByHand`,`Running an automation by hand needs the automation-control authority, which is not wired up yet. There is deliberately no second way to execute one.`)})]}),f(q,{variant:`ghost`,onClick:e=>{e.stopPropagation(),c()},title:_(`automation.automationList.logs`,`Logs`),children:f(S,{className:`h-4 w-4`})}),f(q,{variant:`ghost`,onClick:t=>{t.stopPropagation(),s(!e.enabled)},disabled:t,title:e.enabled?_(`common.disable`,`Disable`):_(`common.enable`,`Enable`),children:e.enabled?_(`common.disable`,`Disable`):_(`common.enable`,`Enable`)}),f(q,{variant:`ghost`,onClick:e=>{e.stopPropagation(),l()},title:_(`common.delete`,`Delete`),children:f(h,{className:`h-4 w-4`})})]})]}),r&&o(`div`,{className:`rounded border border-border`,children:[f(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:f(X,{i18nKey:`common.logsOf`,values:{id:j(e.id)},components:{code:f(`code`,{})}})}),f(me,{addonId:j(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function An({onCreate:e}){let{t}=Y();return f(Ae,{children:o(`div`,{className:`space-y-2 p-4`,children:[f(`p`,{className:`text-sm text-foreground`,children:t(`automation.automationList.noAutomationsYet`,`No automations yet.`)}),f(`p`,{className:`max-w-2xl text-xs text-foreground-subtle`,children:t(`automation.automationList.anAutomationIsATrigger`,`An automation is a trigger, a set of conditions and a list of actions. It compiles to an ordinary block and runs in its own supervised process — there is no separate engine, so anything that goes wrong shows up here with a reason.`)}),f(q,{onClick:e,children:t(`automation.automationList.newAutomation`,`New automation`)})]})})}e();var jn=[`coreBlocks`,`list`],Mn=5e3;function Nn(e){return e instanceof Error?e.message:String(e)}function Pn({onOpenScripts:e,initialBlockId:i,onBlockIdChange:a,createRequested:s=!1,onCreateConsumed:l}){let{t:p}=Y(),m=b(),{state:h,openNew:g,openEdit:_,close:v}=Ee({editKey:`block`,newKey:`new`}),[y,x]=r(null),[S,w]=r(null),[T,E]=r(null),D=u(null),O=h.mode!==`closed`;t(()=>{s&&(x(null),g(),a?.(null),l?.())},[s,l,a,g]);let k=c({queryKey:jn,refetchInterval:Mn,queryFn:async()=>(await m.trpcClient.coreBlocks.list.query({})).blocks}),A=()=>{k.refetch()},j=k.data;t(()=>{i===void 0||D.current===i||j?.find(e=>e.id===i&&Ge(e.code))!==void 0&&(D.current=i,_(i),a?.(i))},[i,j,_,a]);let M=d({mutationFn:e=>m.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{x(e.block),_(e.block.id),a?.(e.block.id),A()}}),N=d({mutationFn:e=>m.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{x(e.block),_(e.block.id),a?.(e.block.id),A()}}),P=d({mutationFn:e=>m.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{w(null),A()}}),F=d({mutationFn:e=>m.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:A}),I=d({mutationFn:e=>m.trpcClient.coreBlocks.update.mutate({blockId:e.id,block:{name:e.name,code:Je(e.code),enabled:e.enabled,placement:e.placement,...e.integrationId===void 0?{}:{integrationId:e.integrationId}}}),onSuccess:t=>{v(),x(null),A(),e(t.block.id)}}),ee=k.data,L=Dn((ee??[]).filter(e=>Ge(e.code))),R=ee!==void 0&&L.length===0,z=h.mode===`edit`?L.find(e=>e.id===h.id)??(y!==null&&y.id===h.id?y:null):null,B=h.mode===`new`||z===null?null:En(L,z),V=B===null?null:qe(B.code),te=M.error===null?N.error===null?I.error===null?null:Nn(I.error):Nn(N.error):Nn(M.error),ne=n(()=>[{key:`row`,header:p(`build.automationsTab.automation`,`Automation`),nowrap:!1,notSortableReason:`Composite status row`,render:e=>{let t=qe(e.code);return f(`ul`,{className:`list-none`,children:f(kn,{block:e,busy:F.isPending||P.isPending,confirming:S===e.id,logsOpen:T===e.id,unreadable:t.ok?null:t.reason,onEdit:()=>{x(e),_(e.id),a?.(e.id)},onToggle:t=>F.mutate({blockId:e.id,enabled:t}),onToggleLogs:()=>E(T===e.id?null:e.id),onAskDelete:()=>w(e.id),onCancelDelete:()=>w(null),onConfirmDelete:()=>P.mutate(e.id)})})},sortValue:e=>e.name}],[S,T,a,_,P,F,p]);return o(`div`,{className:`space-y-3`,children:[f(`p`,{className:`text-xs text-foreground-subtle`,children:ee===void 0?``:On(L)}),k.error!=null&&f(K,{title:p(`build.automationsTab.couldNotReadTheAutomations`,`Could not read the automations`),message:Nn(k.error),onRetry:A}),R?f(An,{onCreate:()=>{x(null),g(),a?.(null)}}):f(xe,{columns:ne,rows:L,rowKey:e=>e.id,pageSize:25,maxBodyHeight:G,emptyMessage:ee===void 0?p(`build.automationsTab.loadingAutomations`,`Loading automations…`):p(`build.automationsTab.noAutomationsYet`,`No automations yet.`),onRowClick:e=>{x(e),_(e.id),a?.(e.id)}}),f(_e,{open:O,onClose:()=>{M.reset(),N.reset(),I.reset(),x(null),v(),a?.(null)},title:B===null?p(`build.automationsTab.newAutomation`,`New automation`):p(`build.automationsTab.edit`,`Edit {{name}}`,{name:B.name}),icon:C,width:`xl`,testId:`automation-editor-panel`,children:f(bn,{existing:B,initialRecipe:V!==null&&V.ok?V.recipe:st,saving:M.isPending||N.isPending,saveError:te,ejecting:I.isPending,onSave:e=>{B===null?M.mutate(e):N.mutate({blockId:B.id,block:e})},onEject:()=>{B!==null&&I.mutate(B)},onCancel:()=>{M.reset(),N.reset(),I.reset(),x(null),v(),a?.(null)}},B?.id??`new`)}),P.error!=null&&f(K,{message:Nn(P.error)}),F.error!=null&&f(K,{message:Nn(F.error)})]})}function Fn(e){return{state:`answered`,byRef:new Map(e.map(e=>[I(e),e]))}}function In(e,t){if(e.state!==`unanswered`)return e.byRef.get(I(t))??null}function Ln(e){return e===void 0?`unknown`:e===null?`missing`:`present`}function Rn(e){return P(e).map(e=>e.source)}function zn(e){let t=e.block.source?.kind===`composition`?e.block.source.composition:null;if(t===null)return[];let n=[];for(let e of t.features){if(e.kind===`passthrough`){n.push(e.source);continue}for(let t of Object.values(e.fields))n.push(...Rn(t));for(let t of Object.values(e.items??{}))for(let e of Object.values(t.fields))n.push(...Rn(e))}let r=new Set;return n.filter(e=>{let t=I(e);return r.has(t)?!1:(r.add(t),!0)})}function Bn(e){let t=e.fields.filter(e=>e.state===`unavailable`),n=e.fields.filter(e=>e.state===`stale`);if(t.length===0&&n.length===0)return{tone:`ok`,label:J.t(`helpers.compositionRows.running`),reason:null};let r=[...t.length>0?[J.t(`helpers.compositionRows.fieldsUnavailable`,{count:t.length})]:[],...n.length>0?[J.t(`helpers.compositionRows.fieldsStale`,{count:n.length})]:[]].join(`, `),i=t[0]??n[0],a=i===void 0?``:` — ${i.cap}.${i.path}: ${i.reason??J.t(`helpers.compositionRows.noReason`)}`;return{tone:`pending`,label:J.t(`helpers.compositionRows.running`),reason:`${r}${a}`}}function Vn(e,t){let n=e.reason??t??null;switch(e.status){case`running`:return Bn(e);case`degraded`:return{tone:`pending`,label:J.t(`helpers.compositionRows.degraded`),reason:n??J.t(`helpers.compositionRows.degradedReason`)};case`starting`:return{tone:`pending`,label:J.t(`helpers.compositionRows.starting`),reason:n};case`failed`:return{tone:`error`,label:J.t(`helpers.compositionRows.failed`),reason:n??J.t(`helpers.compositionRows.failedReason`)};default:return{tone:`error`,label:J.t(`helpers.compositionRows.notRunning`),reason:n??J.t(`helpers.compositionRows.notRunningReason`)}}}function Hn(e){let{block:t,state:n}=e;if(!t.enabled)return{tone:`idle`,label:J.t(`helpers.compositionRows.off`),reason:null};if(n.kind===`unreachable`)return{tone:`pending`,label:J.t(`helpers.compositionRows.unknown`),reason:J.t(`helpers.compositionRows.unreachable`,{error:n.error})};if(n.state!==null)return Vn(n.state,t.lastError);let r=t.lastError===void 0?t.status:`${t.status}: ${t.lastError}`;return{tone:`pending`,label:J.t(`helpers.compositionRows.notReported`),reason:J.t(`helpers.compositionRows.noRecord`,{stored:r})}}function Un(e){return I(e)}function Wn(e,t){let n=In(t,e);return{key:I(e),label:n?n.name:Un(e),presence:Ln(n),deviceId:n?n.id:null}}function Gn(e){return e.state.kind===`answered`&&e.state.state!==null?e.state.state.deviceId:null}function Kn(e,t){let n=e.block.source?.kind===`composition`?e.block.source.composition:null;if(n===null)return null;let r=n.target,i=r.kind===`existing`?r.device:M(e.block.id),a=I(i),o=zn(e).filter(e=>I(e)!==a).map(e=>Wn(e,t)),s=n.features.map(e=>e.enabled===!1?J.t(`helpers.compositionRows.featureOff`,{cap:e.cap}):e.cap),c=In(t,i),l=Gn(e),u=Hn(e);if(r.kind===`new`)return{blockId:e.block.id,kind:`composed`,name:e.block.name,namePresence:`present`,type:r.role===void 0?r.type:`${r.type} · ${r.role}`,features:s,state:u,sources:o,reportedDeviceId:l};let d=Ln(c);return{blockId:e.block.id,kind:`customization`,name:c?c.name:Un(r.device),namePresence:d,type:c?c.type:null,features:s,state:u,sources:o,reportedDeviceId:l}}function qn(e){return e.state.tone===`error`?0:e.state.tone===`pending`?1:e.state.tone===`ok`?2:3}function Jn(e,t){return qn(e)-qn(t)||e.name.localeCompare(t.name)}function Yn(e,t){let n=e.flatMap(e=>{let n=Kn(e,t);return n===null?[]:[n]});return{composed:n.filter(e=>e.kind===`composed`).toSorted(Jn),customizations:n.filter(e=>e.kind===`customization`).toSorted(Jn)}}e();var Xn=1e4;function Zn(e){return e instanceof Error?e.message:typeof e==`object`&&e&&`message`in e?String(e.message):String(e)}function Qn(e){let t=e.trim();return t===``?{}:{name:t}}function $n(){let e=Me();return e.data===void 0?{state:`unanswered`,reason:e.error==null?J.t(`build.customDeviceTab.deviceListPending`):J.t(`build.customDeviceTab.deviceListUnreadable`,{error:Zn(e.error)})}:Fn(e.data)}function er({createRequested:e=!1,onCreateConsumed:n}={}){let{t:r}=Y(),i=ye({},{refetchInterval:Xn}),a=$n(),s=Ee({editKey:`block`,newKey:`new`});t(()=>{e&&(s.openNew(),n?.())},[e]);let c=i.data;if(i.error!=null&&c===void 0)return f(K,{title:r(`build.customDeviceTab.couldNotReadTheCompositions`,`Could not read the compositions`),message:Zn(i.error),onRetry:()=>void i.refetch()});if(c===void 0)return f(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:r(`build.customDeviceTab.loadingCompositions`,`Loading compositions…`)});if(c.state===`not-loaded`)return f(Ae,{children:o(`div`,{className:`space-y-1 p-4`,children:[f(`p`,{className:`text-sm text-warning`,children:r(`build.customDeviceTab.theCompositionStoreHasNot`,`The composition store has not been read yet.`)}),o(`p`,{className:`text-xs text-foreground-subtle`,children:[r(`build.customDeviceTab.thisIsNotTheSame`,`This is not the same as having none — the list appears once the hub has read it (`),c.reason,`).`]})]})});let u=i.error==null?null:Zn(i.error),d=Yn(c.views,a),p=s.state.mode===`edit`?s.state.id:null,m=s.state.mode===`new`;return o(l,{children:[f(rr,{lists:d,fleet:a,refreshError:u,onEditComposed:e=>s.openEdit(e)}),f(_e,{open:m||p!==null,onClose:()=>s.close(),title:m?r(`build.customDeviceTab.newComposedDevice`,`New composed device`):r(`build.customDeviceTab.editComposedDevice`,`Edit composed device`),icon:re,width:`xl`,testId:`composed-device-editor`,children:m?f(tr,{onClose:()=>s.close(),onCreated:e=>{i.refetch(),s.openEdit(e)}}):p===null?null:f(nr,{blockId:p,onClose:()=>s.close(),onSaved:()=>void i.refetch()})})]})}function tr({onClose:e,onCreated:t}){let n=he();return f(He,{initial:Ve(L.Sensor),blockId:null,deviceType:L.Sensor,nativeCaps:null,targetFields:null,showTemplates:!0,onCancel:e,save:async(e,r)=>{try{let{block:i}=await n.mutateAsync({block:{...Qn(r),enabled:!0,composition:e}});return t(i.id),{kind:`saved`}}catch(e){return{kind:`refused`,reason:Zn(e)}}}})}function nr({blockId:e,onClose:t,onSaved:n}){let{t:r}=Y(),i=be(),a=Te({blockId:e});if(a.status===`pending`)return f(`p`,{role:`status`,children:r(`compositionEditor.loading`)});if(a.status===`error`)return f(K,{title:r(`compositionEditor.loadFailed`),message:a.error.message});if(a.data.state===`not-loaded`)return f(`p`,{role:`status`,children:r(`customize.status.notLoaded`,{reason:a.data.reason})});let o=a.data.view;if(o===null)return f(`p`,{children:r(`compositionEditor.notFound`,{blockId:e})});let s=N(o.block);if(s===null)return f(`p`,{children:r(`compositionEditor.notComposition`)});if(s.target.kind===`existing`){let e=o.state.kind===`answered`?o.state.state?.deviceId??null:null;return e===null?f(`p`,{children:r(`compositionEditor.customizationUnknownDevice`)}):f(Ne,{className:`text-primary`,to:Ie(e),children:r(`compositionEditor.openOnDevice`)})}return f(He,{initial:Be(s,o.block.name),blockId:o.block.id,deviceType:s.target.type,nativeCaps:null,targetFields:null,onCancel:t,save:async(e,t)=>{try{return await i.mutateAsync({blockId:o.block.id,expectedUpdatedAt:o.block.updatedAt,block:{...Qn(t),composition:e}}),await a.refetch(),n(),{kind:`saved`}}catch(e){return{kind:`refused`,reason:Zn(e)}}}},`${o.block.id}@${o.block.updatedAt}`)}function rr({lists:e,fleet:t,refreshError:n,onEditComposed:r}){let{t:i}=Y();return o(`div`,{className:`space-y-4`,children:[n!==null&&o(`p`,{className:`text-xs text-warning`,children:[i(`build.customDeviceTab.showingTheLastAnswerThe`,`Showing the last answer — the latest refresh failed:`),` `,n]}),t.state===`unanswered`&&o(`p`,{className:`text-xs text-warning`,children:[i(`build.customDeviceTab.deviceNamesAreShownAs`,`Device names are shown as references:`),` `,t.reason,`. No source is marked missing until it has.`]}),f(ir,{title:i(`build.customDeviceTab.composedDevices`,`Composed devices`),hint:i(`build.customDeviceTab.aNewDeviceWhoseState`,`A new device whose state is derived from other devices.`),rows:e.composed,nameHeader:`Name`,emptyMessage:i(`build.customDeviceTab.noComposedDevices`,`No composed devices.`),kind:`composed`,onEditComposed:r}),f(ir,{title:i(`build.customDeviceTab.customizations`,`Customizations`),hint:i(`build.customDeviceTab.fieldsAddedToOrReplaced`,`Fields added to or replaced on an existing device — one per device, edited from the device.`),rows:e.customizations,nameHeader:`Device`,emptyMessage:i(`build.customDeviceTab.noCustomizations`,`No customizations.`),kind:`customization`,onEditComposed:r})]})}function ir({title:e,hint:t,rows:n,nameHeader:r,emptyMessage:i,kind:a,onEditComposed:s}){return o(`section`,{className:`space-y-2`,"aria-label":e,children:[o(`div`,{children:[f(`h3`,{className:`font-medium`,children:e}),f(`p`,{className:`text-xs text-foreground-subtle`,children:t})]}),f(Ae,{variant:`flat`,className:`p-0`,children:f(xe,{columns:ar(r,a,s),rows:n,rowKey:e=>e.blockId,minWidthPx:760,bordered:!1,maxBodyHeight:G,emptyMessage:i,onRowClick:a===`composed`?e=>s(e.blockId):void 0})})]})}function ar(e,t,n){let r=[{key:`name`,header:e,sortValue:e=>e.name.toLowerCase(),render:e=>f(or,{row:e})},{key:`type`,header:J.t(`build.customDeviceTab.type`,`Type`),sortValue:e=>e.type,render:e=>f(`span`,{className:`text-xs text-foreground-subtle`,children:e.type??J.t(`common.unknownWord`)})},{key:`state`,header:J.t(`build.customDeviceTab.state`,`State`),nowrap:!1,notSortableReason:`A state and its reason are read together, not ordered.`,render:e=>o(`div`,{className:`space-y-0.5`,children:[f(W,{variant:Tn(e.state.tone),children:e.state.label}),e.state.reason!==null&&f(`p`,{className:`max-w-md whitespace-normal text-xs text-foreground-subtle`,children:e.state.reason})]})},{key:`sources`,header:J.t(`build.customDeviceTab.sources`,`Sources`),nowrap:!1,notSortableReason:`A list of devices has no single order.`,render:e=>f(cr,{sources:e.sources})}];return t===`composed`&&r.push({key:`actions`,header:``,align:`right`,notSortableReason:`Row actions`,nowrap:!0,render:e=>f(`div`,{className:`flex justify-end gap-1`,children:f(q,{type:`button`,size:`sm`,variant:`secondary`,onClick:t=>{t.stopPropagation(),n(e.blockId)},children:J.t(`common.edit`,`Edit`)})})}),r}function or({row:e}){let{t}=Y();return o(`div`,{className:`space-y-0.5`,children:[f(sr,{row:e}),e.namePresence===`missing`&&f(`span`,{className:`ml-1.5 text-[10px] text-danger`,children:t(`build.customDeviceTab.deviceMissing`,`device missing`)}),f(`p`,{className:`text-[11px] text-foreground-subtle`,children:e.features.join(`, `)})]})}function sr({row:e}){let{t}=Y();return e.kind===`composed`?f(`span`,{className:`text-xs font-medium text-foreground`,children:e.name}):e.reportedDeviceId===null?f(`span`,{className:`text-xs text-foreground-subtle`,children:t(`build.customDeviceTab.notReported`,{name:e.name})}):f(Ne,{to:Ie(e.reportedDeviceId),className:`text-xs text-foreground hover:underline`,onClick:e=>e.stopPropagation(),children:e.name})}function cr({sources:e}){let{t}=Y();return e.length===0?f(`span`,{className:`text-xs text-foreground-subtle`,children:`—`}):f(`ul`,{className:`space-y-0.5`,children:e.map(e=>o(`li`,{className:`text-xs`,children:[e.deviceId===null?f(`span`,{className:e.presence===`missing`?`text-danger`:`text-foreground`,children:e.label}):f(Ne,{to:`/devices/${String(e.deviceId)}`,className:`hover:underline`,children:e.label}),e.presence===`missing`&&f(`span`,{className:`ml-1.5 text-[10px] text-danger`,children:t(`common.missing`)})]},e.key))})}function lr(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function ur(e){if(Array.isArray(e))return e}function dr(e,t,n){return(t=br(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function fr(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t!==0)for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function pr(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
5
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function mr(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function hr(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?mr(Object(n),!0).forEach(function(t){dr(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):mr(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function gr(e,t){if(e==null)return{};var n,r,i=_r(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function _r(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function vr(e,t){return ur(e)||fr(e,t)||xr(e,t)||pr()}function yr(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function br(e){var t=yr(e,`string`);return typeof t==`symbol`?t:t+``}function xr(e,t){if(e){if(typeof e==`string`)return lr(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?lr(e,t):void 0}}function Sr(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Cr(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function wr(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Cr(Object(n),!0).forEach(function(t){Sr(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Cr(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Tr(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}}function Er(e){return function t(){var n=this,r=[...arguments];return r.length>=e.length?e.apply(this,r):function(){var e=[...arguments];return t.apply(n,[].concat(r,e))}}}function Dr(e){return{}.toString.call(e).includes(`Object`)}function Or(e){return!Object.keys(e).length}function kr(e){return typeof e==`function`}function Ar(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function jr(e,t){return Dr(t)||Ir(`changeType`),Object.keys(t).some(function(t){return!Ar(e,t)})&&Ir(`changeField`),t}function Mr(e){kr(e)||Ir(`selectorType`)}function Nr(e){kr(e)||Dr(e)||Ir(`handlerType`),Dr(e)&&Object.values(e).some(function(e){return!kr(e)})&&Ir(`handlersType`)}function Pr(e){e||Ir(`initialIsRequired`),Dr(e)||Ir(`initialType`),Or(e)&&Ir(`initialContent`)}function Fr(e,t){throw Error(e[t]||e.default)}var Ir=Er(Fr)({initialIsRequired:`initial state is required`,initialType:`initial state should be an object`,initialContent:`initial state shouldn't be an empty object`,handlerType:`handler should be an object or a function`,handlersType:`all handlers should be a functions`,selectorType:`selector should be a function`,changeType:`provided value of changes should be an object`,changeField:`it seams you want to change a field in the state which is not specified in the "initial" state`,default:"an unknown error accured in `state-local` package"}),Lr={changes:jr,selector:Mr,handler:Nr,initial:Pr};function Rr(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};Lr.initial(e),Lr.handler(t);var n={current:e},r=Er(Vr)(n,t),i=Er(Br)(n),a=Er(Lr.changes)(e),o=Er(zr)(n);function s(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(e){return e};return Lr.selector(e),e(n.current)}function c(e){Tr(r,i,a,o)(e)}return[s,c]}function zr(e,t){return kr(t)?t(e.current):t}function Br(e,t){return e.current=wr(wr({},e.current),t),t}function Vr(e,t,n){return kr(t)?t(e.current):Object.keys(n).forEach(function(n){return t[n]?.call(t,e.current[n])}),n}var Hr={create:Rr},Ur={paths:{vs:`https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs`}};function Wr(e){return function t(){var n=this,r=[...arguments];return r.length>=e.length?e.apply(this,r):function(){var e=[...arguments];return t.apply(n,[].concat(r,e))}}}function Gr(e){return{}.toString.call(e).includes(`Object`)}function Kr(e){return e||Xr(`configIsRequired`),Gr(e)||Xr(`configType`),e.urls?(qr(),{paths:{vs:e.urls.monacoBase}}):e}function qr(){console.warn(Yr.deprecation)}function Jr(e,t){throw Error(e[t]||e.default)}var Yr={configIsRequired:`the configuration object is required`,configType:`the configuration object should be an object`,default:"an unknown error accured in `@monaco-editor/loader` package",deprecation:`Deprecation warning!
|
|
6
|
-
You are using deprecated way of configuration.
|
|
7
|
-
|
|
8
|
-
Instead of using
|
|
9
|
-
monaco.config({ urls: { monacoBase: '...' } })
|
|
10
|
-
use
|
|
11
|
-
monaco.config({ paths: { vs: '...' } })
|
|
12
|
-
|
|
13
|
-
For more please check the link https://github.com/suren-atoyan/monaco-loader#config
|
|
14
|
-
`},Xr=Wr(Jr)(Yr),Zr={config:Kr},Qr=function(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}};function $r(e,t){return Object.keys(t).forEach(function(n){t[n]instanceof Object&&e[n]&&Object.assign(t[n],$r(e[n],t[n]))}),hr(hr({},e),t)}var ei={type:`cancelation`,msg:`operation is manually canceled`};function ti(e){var t=!1,n=new Promise(function(n,r){e.then(function(e){return t?r(ei):n(e)}),e.catch(r)});return n.cancel=function(){return t=!0},n}var ni=[`monaco`],ri=vr(Hr.create({config:Ur,isInitialized:!1,resolve:null,reject:null,monaco:null}),2),ii=ri[0],ai=ri[1];function oi(e){var t=Zr.config(e),n=t.monaco,r=gr(t,ni);ai(function(e){return{config:$r(e.config,r),monaco:n}})}function si(){var e=ii(function(e){return{monaco:e.monaco,isInitialized:e.isInitialized,resolve:e.resolve}});if(!e.isInitialized){if(ai({isInitialized:!0}),e.monaco)return e.resolve(e.monaco),ti(mi);if(window.monaco&&window.monaco.editor)return fi(window.monaco),e.resolve(window.monaco),ti(mi);Qr(ci,ui)(di)}return ti(mi)}function ci(e){return document.body.appendChild(e)}function li(e){var t=document.createElement(`script`);return e&&(t.src=e),t}function ui(e){var t=ii(function(e){return{config:e.config,reject:e.reject}}),n=li(`${t.config.paths.vs}/loader.js`);return n.onload=function(){return e()},n.onerror=t.reject,n}function di(){var e=ii(function(e){return{config:e.config,resolve:e.resolve,reject:e.reject}}),t=window.require;t.config(e.config),t([`vs/editor/editor.main`],function(t){var n=t.m||t;fi(n),e.resolve(n)},function(t){e.reject(t)})}function fi(e){ii().monaco||ai({monaco:e})}function pi(){return ii(function(e){return e.monaco})}var mi=new Promise(function(e,t){return ai({resolve:e,reject:t})}),hi={config:oi,init:si,__getMonacoInstance:pi};e();var gi={wrapper:{display:`flex`,position:`relative`,textAlign:`initial`},fullWidth:{width:`100%`},hide:{display:`none`}},_i={container:{display:`flex`,height:`100%`,width:`100%`,justifyContent:`center`,alignItems:`center`}};function vi({children:e}){return s.createElement(`div`,{style:_i.container},e)}var yi=vi;function bi({width:e,height:t,isEditorReady:n,loading:r,_ref:i,className:a,wrapperProps:o}){return s.createElement(`section`,{style:{...gi.wrapper,width:e,height:t},...o},!n&&s.createElement(yi,null,r),s.createElement(`div`,{ref:i,style:{...gi.fullWidth,...!n&&gi.hide},className:a}))}var xi=a(bi);function Si(e){t(e,[])}var Ci=Si;function wi(e,n,r=!0){let i=u(!0);t(i.current||!r?()=>{i.current=!1}:e,n)}var $=wi;function Ti(){}function Ei(e,t,n,r){return Di(e,r)||Oi(e,t,n,r)}function Di(e,t){return e.editor.getModel(ki(e,t))}function Oi(e,t,n,r){return e.editor.createModel(t,n,r?ki(e,r):void 0)}function ki(e,t){return e.Uri.parse(t)}function Ai({original:e,modified:n,language:a,originalLanguage:o,modifiedLanguage:c,originalModelPath:l,modifiedModelPath:d,keepCurrentOriginalModel:f=!1,keepCurrentModifiedModel:p=!1,theme:m=`light`,loading:h=`Loading...`,options:g={},height:_=`100%`,width:v=`100%`,className:y,wrapperProps:b={},beforeMount:x=Ti,onMount:S=Ti}){let[C,w]=r(!1),[T,E]=r(!0),D=u(null),O=u(null),k=u(null),A=u(S),j=u(x),M=u(!1);Ci(()=>{let e=hi.init();return e.then(e=>(O.current=e)&&E(!1)).catch(e=>e?.type!==`cancelation`&&console.error(`Monaco initialization: error:`,e)),()=>D.current?F():e.cancel()}),$(()=>{if(D.current&&O.current){let t=D.current.getOriginalEditor(),n=Ei(O.current,e||``,o||a||`text`,l||``);n!==t.getModel()&&t.setModel(n)}},[l],C),$(()=>{if(D.current&&O.current){let e=D.current.getModifiedEditor(),t=Ei(O.current,n||``,c||a||`text`,d||``);t!==e.getModel()&&e.setModel(t)}},[d],C),$(()=>{let e=D.current.getModifiedEditor();e.getOption(O.current.editor.EditorOption.readOnly)?e.setValue(n||``):n!==e.getValue()&&(e.executeEdits(``,[{range:e.getModel().getFullModelRange(),text:n||``,forceMoveMarkers:!0}]),e.pushUndoStop())},[n],C),$(()=>{D.current?.getModel()?.original.setValue(e||``)},[e],C),$(()=>{let{original:e,modified:t}=D.current.getModel();O.current.editor.setModelLanguage(e,o||a||`text`),O.current.editor.setModelLanguage(t,c||a||`text`)},[a,o,c],C),$(()=>{O.current?.editor.setTheme(m)},[m],C),$(()=>{D.current?.updateOptions(g)},[g],C);let N=i(()=>{if(!O.current)return;j.current(O.current);let t=Ei(O.current,e||``,o||a||`text`,l||``),r=Ei(O.current,n||``,c||a||`text`,d||``);D.current?.setModel({original:t,modified:r})},[a,n,c,e,o,l,d]),P=i(()=>{!M.current&&k.current&&(D.current=O.current.editor.createDiffEditor(k.current,{automaticLayout:!0,...g}),N(),O.current?.editor.setTheme(m),w(!0),M.current=!0)},[g,m,N]);t(()=>{C&&A.current(D.current,O.current)},[C]),t(()=>{!T&&!C&&P()},[T,C,P]);function F(){let e=D.current?.getModel();f||e?.original?.dispose(),p||e?.modified?.dispose(),D.current?.dispose()}return s.createElement(xi,{width:v,height:_,isEditorReady:C,loading:h,_ref:k,className:y,wrapperProps:b})}a(Ai);function ji(e){let n=u();return t(()=>{n.current=e},[e]),n.current}var Mi=ji,Ni=new Map;function Pi({defaultValue:e,defaultLanguage:n,defaultPath:a,value:o,language:c,path:l,theme:d=`light`,line:f,loading:p=`Loading...`,options:m={},overrideServices:h={},saveViewState:g=!0,keepCurrentModel:_=!1,width:v=`100%`,height:y=`100%`,className:b,wrapperProps:x={},beforeMount:S=Ti,onMount:C=Ti,onChange:w,onValidate:T=Ti}){let[E,D]=r(!1),[O,k]=r(!0),A=u(null),j=u(null),M=u(null),N=u(C),P=u(S),F=u(),I=u(o),ee=Mi(l),L=u(!1),R=u(!1);Ci(()=>{let e=hi.init();return e.then(e=>(A.current=e)&&k(!1)).catch(e=>e?.type!==`cancelation`&&console.error(`Monaco initialization: error:`,e)),()=>j.current?B():e.cancel()}),$(()=>{let t=Ei(A.current,e||o||``,n||c||``,l||a||``);t!==j.current?.getModel()&&(g&&Ni.set(ee,j.current?.saveViewState()),j.current?.setModel(t),g&&j.current?.restoreViewState(Ni.get(l)))},[l],E),$(()=>{j.current?.updateOptions(m)},[m],E),$(()=>{!j.current||o===void 0||(j.current.getOption(A.current.editor.EditorOption.readOnly)?j.current.setValue(o):o!==j.current.getValue()&&(R.current=!0,j.current.executeEdits(``,[{range:j.current.getModel().getFullModelRange(),text:o,forceMoveMarkers:!0}]),j.current.pushUndoStop(),R.current=!1))},[o],E),$(()=>{let e=j.current?.getModel();e&&c&&A.current?.editor.setModelLanguage(e,c)},[c],E),$(()=>{f!==void 0&&j.current?.revealLine(f)},[f],E),$(()=>{A.current?.editor.setTheme(d)},[d],E);let z=i(()=>{if(!(!M.current||!A.current)&&!L.current){P.current(A.current);let t=l||a,r=Ei(A.current,o||e||``,n||c||``,t||``);j.current=A.current?.editor.create(M.current,{model:r,automaticLayout:!0,...m},h),g&&j.current.restoreViewState(Ni.get(t)),A.current.editor.setTheme(d),f!==void 0&&j.current.revealLine(f),D(!0),L.current=!0}},[e,n,a,o,c,l,m,h,g,d,f]);t(()=>{E&&N.current(j.current,A.current)},[E]),t(()=>{!O&&!E&&z()},[O,E,z]),I.current=o,t(()=>{E&&w&&(F.current?.dispose(),F.current=j.current?.onDidChangeModelContent(e=>{R.current||w(j.current.getValue(),e)}))},[E,w]),t(()=>{if(E){let e=A.current.editor.onDidChangeMarkers(e=>{let t=j.current.getModel()?.uri;if(t&&e.find(e=>e.path===t.path)){let e=A.current.editor.getModelMarkers({resource:t});T?.(e)}});return()=>{e?.dispose()}}return()=>{}},[E,T]);function B(){F.current?.dispose(),_?g&&Ni.set(l,j.current.saveViewState()):j.current.getModel()?.dispose(),j.current.dispose()}return s.createElement(xi,{width:v,height:y,isEditorReady:E,loading:p,_ref:M,className:b,wrapperProps:x})}var Fi=a(Pi);e();function Ii(e,t){let n=[];for(let[r,i]of Object.entries(e))r!==t&&(n.push({filePath:`file:///${r}`,content:i}),r.endsWith(`.ts`)&&n.push({filePath:`file:///${r.slice(0,-3)}.js`,content:i}));return n}var Li={target:99,module:99,moduleResolution:2,strict:!0,noImplicitAny:!0,strictNullChecks:!0,allowNonTsExtensions:!0,isolatedModules:!0};function Ri(e,t){let n=e.languages.typescript.typescriptDefaults;n.setCompilerOptions({...n.getCompilerOptions(),...Li}),n.setExtraLibs(t.map(e=>({filePath:e.filePath,content:e.content})))}function zi({value:e,onChange:n,extraLibs:r=[],path:a=`file:///block.ts`,onDiagnostics:o,readOnly:s=!1,heightPx:c=420,dark:l=!0}){let d=u(null),p=i((e,t)=>{if(d.current=t,Ri(t,r),o===void 0)return;let n=e.getModel();if(n===null)return;let i=()=>{o(t.editor.getModelMarkers({resource:n.uri}).map(e=>({line:e.startLineNumber,column:e.startColumn,message:e.message,severity:e.severity})))};t.editor.onDidChangeMarkers(i),i()},[r,o]);return t(()=>{let e=d.current;e!==null&&Ri(e,r)},[r]),f(Fi,{height:c,defaultLanguage:`typescript`,path:a,theme:l?`vs-dark`:`vs`,value:e,onChange:e=>n(e??``),onMount:p,options:{readOnly:s,minimap:{enabled:!1},fontSize:12,lineNumbers:`on`,scrollBeyondLastLine:!1,automaticLayout:!0,tabSize:2,renderWhitespace:`selection`}})}function Bi(e){return e.some(e=>e.severity>=8)}var Vi=[{id:`blank`,name:`Blank script`,get description(){return J.t(`helpers.buildExamples.blankDescription`)},entry:`main.ts`,files:{"main.ts":`import type { AddonContext } from '@camstack/types'
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* A core block. Runs in its own process, with the same \`ctx\` an addon gets.
|
|
18
|
-
* Return a function to release whatever you took (timers, sockets, listeners).
|
|
19
|
-
*
|
|
20
|
-
* Declaring devices: import { reconcileBlockDevices, exposeBlockDevices } from
|
|
21
|
-
* '@camstack/types' and hang them off the shared Blocks integration.
|
|
22
|
-
*/
|
|
23
|
-
export default function block(ctx: AddonContext) {
|
|
24
|
-
ctx.logger.info('hello from a core block')
|
|
25
|
-
|
|
26
|
-
const timer = setInterval(() => {
|
|
27
|
-
ctx.logger.info('tick')
|
|
28
|
-
}, 60_000)
|
|
29
|
-
|
|
30
|
-
return () => {
|
|
31
|
-
clearInterval(timer)
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
`}}];function Hi(e){let t=e instanceof Set?e:new Set(e);if(!t.has(`file.ts`))return`file.ts`;let n=2;for(;t.has(`file-${String(n)}.ts`);)n+=1;return`file-${String(n)}.ts`}var Ui=Vi.find(e=>e.id===`blank`)?.files[`main.ts`]??`import type { AddonContext } from '@camstack/types'
|
|
35
|
-
|
|
36
|
-
export default function block(ctx: AddonContext) {
|
|
37
|
-
ctx.logger.info('hello from a core block')
|
|
38
|
-
return () => undefined
|
|
39
|
-
}
|
|
40
|
-
`;function Wi({existing:e,dirty:t,saving:n,restarting:r}){return e===null?J.t(`helpers.restartGate.saveFirstNoProcess`):n?J.t(`helpers.restartGate.saving`):r?J.t(`helpers.restartGate.restarting`):t?J.t(`helpers.restartGate.saveFirstDirty`):e.enabled?null:J.t(`helpers.restartGate.disabled`)}e();var Gi=5e3;function Ki(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(typeof n!=`object`||!n)continue;let e=Reflect.get(n,`id`),r=Reflect.get(n,`name`),i=Reflect.get(n,`type`),a=Reflect.get(n,`stableId`);typeof e!=`number`||typeof r!=`string`||typeof i!=`string`||t.push({id:e,name:r,type:i,...typeof a==`string`?{stableId:a}:{}})}return t}function qi({blockId:e}){let{t}=Y(),r=j(e),i=pe({addonId:r,projection:`slim`},{refetchInterval:Gi}),a=n(()=>Ki(i.data),[i.data]);return i.isLoading?o(`p`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[f(y,{className:`h-3.5 w-3.5 animate-spin`}),` `,t(`build.scriptDevicesPanel.loading`)]}):i.isError?o(`p`,{className:`text-xs text-danger`,children:[t(`build.scriptDevicesPanel.couldNotListDevices`,`Could not list devices:`),` `,i.error instanceof Error?i.error.message:String(i.error)]}):o(`section`,{className:`space-y-3 rounded border border-border p-3`,"data-testid":`script-devices-panel`,children:[o(`div`,{className:`flex items-center justify-between gap-2`,children:[o(`div`,{children:[f(`h4`,{className:`text-sm font-medium`,children:t(`build.scriptDevicesPanel.devices`,`Devices`)}),f(`p`,{className:`text-xs text-foreground-subtle`,children:f(X,{i18nKey:`build.scriptDevicesPanel.declaredBy`,values:{addonId:r},components:{code:f(`code`,{className:`text-[11px]`})}})})]}),f(W,{variant:`default`,children:a.length})]}),a.length===0?f(`p`,{className:`text-xs text-foreground-subtle`,children:f(X,{i18nKey:`build.scriptDevicesPanel.noDevices`,components:{code:f(`code`,{})}})}):f(`ul`,{className:`space-y-3`,children:a.map(e=>f(`li`,{className:`rounded border border-border/80 px-3 py-2`,"data-testid":`script-device-${e.id}`,children:o(`div`,{className:`flex flex-wrap items-baseline gap-2`,children:[f(Ne,{to:`/devices/${String(e.id)}`,className:`text-sm font-medium hover:underline`,title:t(`build.scriptDevicesPanel.openDeviceDetail`,`Open device detail`),children:e.name}),f(W,{variant:`info`,style:`outline`,children:e.type}),e.stableId!==void 0&&o(`span`,{className:`text-[11px] text-foreground-subtle`,children:[`stableId `,f(`code`,{children:e.stableId})]}),o(`span`,{className:`text-[11px] text-foreground-subtle`,children:[`#`,e.id]})]})},e.id))})]})}e();function Ji(e){return e===`refresh-channel-catalog`||e===`send-tv-schedule-now`||e===`refresh-nordvpn-catalog`||e===`probe-nordvpn-italy`||e===`test-nordvpn-endpoint`||e===`refresh-unifi-catalog`}function Yi(e){let t=Date.now();switch(e){case`refresh-channel-catalog`:return{channelCatalogRefreshAt:t};case`send-tv-schedule-now`:return{sendNowAt:t};case`refresh-nordvpn-catalog`:return{nordVpnCatalogRefreshAt:t};case`probe-nordvpn-italy`:return{nordVpnProbeAt:t};case`test-nordvpn-endpoint`:return{nordVpnTestAt:t};case`refresh-unifi-catalog`:return{unifiCatalogRefreshAt:t}}}function Xi(e){switch(e){case`refresh-channel-catalog`:return J.t(`build.scriptSettingsPanel.enableChannel`);case`send-tv-schedule-now`:return J.t(`build.scriptSettingsPanel.enableTv`);case`refresh-nordvpn-catalog`:return J.t(`build.scriptSettingsPanel.enableNord`);case`probe-nordvpn-italy`:return J.t(`build.scriptSettingsPanel.enableItaly`);case`test-nordvpn-endpoint`:return J.t(`build.scriptSettingsPanel.enableVpn`);case`refresh-unifi-catalog`:return J.t(`build.scriptSettingsPanel.enableUnifi`)}}function Zi(e){if(typeof e!=`object`||!e||!(`key`in e))return null;let t=Reflect.get(e,`key`);return typeof t==`string`?t:null}function Qi(e){if(!(typeof e!=`object`||!e||!(`value`in e)))return Reflect.get(e,`value`)}function $i(e){let t={};for(let n of e.sections)for(let e of n.fields){let n=Zi(e);n!==null&&(t[n]=Qi(e))}return t}function ea(e){return typeof e!=`object`||!e?!1:Array.isArray(Reflect.get(e,`sections`))}function ta({blockId:e}){let{t}=Y(),a=b(),s=ke({blockId:e},{retry:!1}),c=ge({blockId:e},{refetchInterval:1e4,retry:!1}),l=Se({onSuccess:()=>{c.refetch()}}),u=Oe(),d=De(),[p,m]=r(null),[h,g]=r(null),[_,v]=r(null),[x,S]=r(!1),C=ea(c.data)?c.data:null,w=n(()=>C===null?{}:$i(C),[C]),T=p??w,E=i(e=>{m(e)},[]),D=p!==null,O=i(()=>{p!==null&&(g(null),l.mutate({blockId:e,patch:p},{onSuccess:()=>m(null),onError:e=>g(e instanceof Error?e.message:String(e))}))},[e,p,l]),k=i(async(t,n)=>{if(Ji(t)){S(!0),g(null),v(null);try{p!==null&&(await a.trpcClient.coreBlocks.updateBlockSettings.mutate({blockId:e,patch:p}),m(null)),await a.trpcClient.coreBlocks.updateBlockSettings.mutate({blockId:e,patch:Yi(t)}),s.data?.block?.enabled!==!0&&(await d.mutateAsync({blockId:e,enabled:!0}),v(Xi(t))),await u.mutateAsync({blockId:e}),await c.refetch(),t===`send-tv-schedule-now`?v(`Sending tonight’s schedule now…`):t===`probe-nordvpn-italy`?v(`Probing NordVPN Italy stations (no UniFi change)…`):t===`test-nordvpn-endpoint`?v(`Testing VPN endpoint on UniFi…`):t===`refresh-nordvpn-catalog`?v(`Refreshing NordVPN Italy catalog…`):t===`refresh-unifi-catalog`&&v(`Refreshing UniFi ID catalogs…`)}catch(e){g(e instanceof Error?e.message:String(e))}finally{S(!1)}}},[e,s.data?.block?.enabled,p,u,d,c,a.trpcClient.coreBlocks]);return c.isLoading?o(`p`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[f(y,{className:`h-3.5 w-3.5 animate-spin`}),` `,t(`build.scriptSettingsPanel.loading`)]}):c.isError?o(`p`,{className:`text-xs text-danger`,"data-testid":`script-settings-error`,children:[t(`build.scriptSettingsPanel.couldNotLoadSettings`,`Could not load settings:`),` `,c.error instanceof Error?c.error.message:String(c.error)]}):C===null?null:o(`section`,{className:`space-y-3 rounded border border-border p-3`,"data-testid":`script-settings-panel`,children:[o(`div`,{className:`flex items-center justify-between gap-2`,children:[o(`div`,{children:[f(`h4`,{className:`text-sm font-medium`,children:t(`build.scriptSettingsPanel.settings`,`Settings`)}),f(`p`,{className:`text-xs text-foreground-subtle`,children:f(X,{i18nKey:`build.scriptSettingsPanel.declaredBy`,components:{code:f(`code`,{})}})})]}),o(q,{size:`sm`,variant:`primary`,onClick:O,disabled:!D||l.isPending||x,children:[l.isPending&&f(y,{className:`h-3.5 w-3.5 animate-spin`}),t(`build.scriptSettingsPanel.saveSettings`,`Save settings`)]})]}),f(Le,{schema:C,values:T,onChange:E,onAction:k}),h===null?null:f(`p`,{className:`text-xs text-danger`,"data-testid":`script-settings-save-error`,children:h}),_===null?null:f(`p`,{className:`text-xs text-foreground-subtle`,"data-testid":`script-settings-info`,children:_})]})}e();var na=`hub`;function ra({existing:e,typeDefs:t,typeDefsLoading:i,saving:a,saveError:s,restarting:c,restartError:u,onRestart:p,onSave:m,onCancel:h}){let{t:_}=Y(),v=b(),C=ce(),{resolvedMode:w}=ve(),T=ne({code:e?.code??Ui,files:e?.files,entry:e?.entry}),[D,O]=r(e?.name??``),[k,A]=r(T.files),[M,N]=r(T.entry),[P,F]=r(T.entry),[I,ee]=r(e?.placement??na),[L,R]=r(e?.integrationId??``),[z,B]=r([]),[V,te]=r(!1),[re,ie]=r(`blank`),[ae,oe]=r(null),[se,le]=r(``),ue=k[P]??``,de=e=>{A(t=>({...t,[P]:e}))},U=Object.keys(k).toSorted(),fe=Vi.length>1,pe=n(()=>[...t?.libs??[],...Ii(k,P)],[t?.libs,k,P]),G=d({mutationFn:()=>v.trpcClient.coreBlocks.compile.mutate({files:k,entry:M})}),he=n(()=>z.filter(e=>e.severity>=8),[z]),ge=Bi(z),_e=D.trim()===``,ye=e===null?null:ne(e),K=e===null||ye===null||JSON.stringify(k)!==JSON.stringify(ye.files)||M!==ye.entry||D.trim()!==e.name||I!==e.placement||(L.trim()===``?void 0:L.trim())!==e.integrationId,be=()=>{G.reset(),m({name:D.trim(),files:k,entry:M,enabled:e?.enabled??!0,placement:I,...L.trim()===``?{}:{integrationId:L.trim()}})},xe=()=>{let e=Hi(Object.keys(k));A(t=>({...t,[e]:``})),F(e),oe(e),le(e)},Se=e=>{oe(e),le(e)},we=()=>{if(ae===null)return;let e=ae,t=se.trim();if(oe(null),!(t===``||t===e)){if(k[t]!==void 0){F(t);return}A(n=>{let r={};for(let[i,a]of Object.entries(n))r[i===e?t:i]=a;return r}),M===e&&N(t),F(t)}},Te=async e=>{let t=Vi.find(t=>t.id===e);if(t===void 0)return;let n=Vi.find(e=>e.id===`blank`);!(n!==void 0&&JSON.stringify(k)===JSON.stringify(n.files)&&M===n.entry)&&!await C({title:_(`build.blockEditor.loadExample`,`Load example`),message:_(`build.blockEditor.replaceTheCurrentEditorContents`,`Replace the current editor contents with this example?`),confirmLabel:_(`build.blockEditor.replace`,`Replace`),variant:`warning`})||(ie(e),A({...t.files}),N(t.entry),F(t.entry),(D.trim()===``||re===`blank`)&&O(t.id===`blank`?``:t.name))},Ee=e===null?null:wn(e),De=Wi({existing:e,dirty:K,saving:a,restarting:c});return o(`div`,{className:`space-y-4`,children:[Ee!==null&&f(`div`,{className:`flex flex-wrap items-center gap-2`,children:f(W,{variant:Tn(Ee.tone),children:Ee.label})}),o(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[o(`label`,{className:`block text-sm`,children:[f(`span`,{className:`text-foreground-subtle`,children:_(`build.blockEditor.name`,`Name`)}),f(H,{className:`mt-1`,value:D,onChange:e=>O(e.target.value),placeholder:_(`build.blockEditor.whatThisScriptDoes`,`What this script does`)})]}),o(`label`,{className:`block text-sm`,children:[f(`span`,{className:`text-foreground-subtle`,children:_(`build.blockEditor.integrationOptional`,`Integration (optional)`)}),f(H,{className:`mt-1`,value:L,onChange:e=>R(e.target.value),placeholder:_(`build.blockEditor.leaveEmptyForTheShared`,`Leave empty for the shared system integration`)})]})]}),e===null&&fe&&o(`label`,{className:`block text-sm`,children:[f(`span`,{className:`text-foreground-subtle`,children:_(`build.blockEditor.startFrom`,`Start from`)}),f(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1.5 text-sm`,value:re,onChange:e=>void Te(e.target.value),"data-testid":`script-example-select`,children:Vi.map(e=>o(`option`,{value:e.id,children:[e.name,` — `,e.description]},e.id))})]}),o(`div`,{children:[f(Ce,{selectedNodeId:I,onSelect:ee,label:_(`build.blockEditor.runsOn`,`Runs on`),alwaysShow:!0}),I!==na&&o(`p`,{className:`mt-2 flex items-start gap-2 text-xs text-warning`,children:[f(g,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),f(`span`,{children:f(X,{i18nKey:`build.blockEditor.hubOnlyWarning`,components:{strong:f(`strong`,{})}})})]})]}),o(`div`,{className:`flex min-h-[56vh] flex-col rounded border border-border`,children:[o(`div`,{className:`flex flex-wrap items-center gap-1 border-b border-border px-2 py-1.5`,children:[U.map(e=>ae===e?f(H,{value:se,onChange:e=>le(e.target.value),onBlur:()=>we(),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),we()),e.key===`Escape`&&(e.preventDefault(),oe(null))},className:`h-7 w-36 px-2 py-0 text-xs`,autoFocus:!0,"data-testid":`script-file-rename`,"aria-label":_(`build.blockEditor.renameFile`,`Rename file`)},e):o(`button`,{type:`button`,className:`rounded px-2 py-1 text-xs ${e===P?`bg-muted font-medium text-foreground`:`text-foreground-subtle hover:text-foreground`}`,onClick:()=>F(e),onDoubleClick:()=>Se(e),title:_(`build.blockEditor.doubleClickToRename`,`Double-click to rename`),"data-testid":`script-file-tab-${e}`,children:[e,e===M?` · ${_(`build.blockEditor.entry`)}`:``]},e)),f(`button`,{type:`button`,className:`ml-1 rounded px-2 py-1 text-xs text-foreground-subtle hover:text-foreground`,onClick:xe,"data-testid":`script-file-add`,children:_(`build.blockEditor.file`,`+ file`)}),P!==M&&f(`button`,{type:`button`,className:`rounded px-2 py-1 text-xs text-foreground-subtle hover:text-foreground`,onClick:()=>N(P),title:_(`build.blockEditor.useThisFileAsThe`,`Use this file as the compile entry`),children:_(`build.blockEditor.setAsEntry`,`Set as entry`)})]}),i?f(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:_(`build.blockEditor.loadingTheNodeSType`,`Loading the node's type definitions…`)}):f(zi,{value:ue,onChange:de,path:`file:///${P}`,extraLibs:pe,onDiagnostics:B,dark:w===`dark`,heightPx:560})]}),t!==void 0&&t.libs.length===0&&f(`p`,{className:`text-xs text-warning`,children:_(`build.blockEditor.theNodeReturnedNoType`,`The node returned no type definitions, so this code is NOT being checked against the system's types. The server-side compile still applies on save.`)}),he.length>0&&o(`div`,{className:`space-y-1 rounded border border-danger/40 bg-danger/10 p-3 text-xs`,children:[f(`p`,{className:`font-medium text-danger`,children:_(`build.blockEditor.errorsCannotSave`,{count:he.length})}),he.slice(0,5).map(e=>f(`p`,{className:`text-danger`,children:_(`build.blockEditor.diagnosticLine`,{line:e.line,message:e.message})},`${String(e.line)}:${String(e.column)}:${e.message}`)),he.length>5&&f(`p`,{className:`text-foreground-subtle`,children:_(`build.blockEditor.moreErrors`,{count:he.length-5})})]}),G.data!==void 0&&(G.data.ok?o(`p`,{className:`flex items-center gap-2 text-xs text-success`,children:[f(x,{className:`h-3.5 w-3.5`}),` `,_(`build.blockEditor.compiledOk`)]}):o(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:[G.data.line!==void 0&&f(`span`,{className:`mr-1`,children:_(`build.blockEditor.errorLine`,{line:String(G.data.line)})}),G.data.error??_(`build.blockEditor.theCodeDoesNotCompile`,`the code does not compile`)]})),G.error!==null&&o(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:[_(`build.blockEditor.couldNotReachTheCompiler`,`Could not reach the compiler:`),` `,ia(G.error)]}),s!==null&&f(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:s}),u!==null&&f(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:u}),e!==null&&o(`div`,{className:`space-y-3`,children:[f(ta,{blockId:e.id}),f(qi,{blockId:e.id})]}),o(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(q,{variant:`outline`,onClick:()=>G.mutate(),disabled:G.isPending||a,title:_(`build.blockEditor.typeCheckOnTheNode`,`Type-check on the node without saving`),children:[G.isPending&&f(y,{className:`h-4 w-4 animate-spin`}),` `,_(`common.compile`)]}),o(q,{onClick:be,disabled:a||ge||_e,children:[a&&f(y,{className:`h-4 w-4 animate-spin`}),` `,_(`common.save`)]}),o(q,{variant:`outline`,onClick:()=>p?.(),disabled:De!==null||p===void 0,title:De??_(`build.blockEditor.stopTheProcessAndLet`,`Stop the process and let the supervisor bring it back`),children:[c?f(E,{className:`h-4 w-4 animate-spin`}):f(E,{className:`h-4 w-4`}),` `,_(`build.blockEditor.restart`,`Restart`)]}),o(q,{variant:`ghost`,onClick:()=>te(!V),title:_(`build.blockEditor.showThisScriptSProcess`,`Show this script's process logs`),"data-testid":`script-logs-toggle`,children:[f(S,{className:`h-4 w-4`}),` `,_(`common.logs`),` `,V?`▾`:`▸`]}),f(q,{variant:`ghost`,onClick:h,disabled:a,children:_(`common.close`,`Close`)}),o(`span`,{className:`ml-auto text-xs text-foreground-subtle`,children:[_(`build.blockEditor.errorsCount`,{count:he.length}),K&&e!==null?` · ${_(`build.blockEditor.unsavedChanges`)}`:``]}),_e&&f(W,{variant:`warning`,children:_(`build.blockEditor.nameRequired`,`Name required`)})]}),V&&o(`div`,{className:`rounded border border-border`,"data-testid":`script-logs-panel`,children:[f(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:e===null?_(`build.blockEditor.logsAppearOnceTheScript`,`Logs appear once the script has been saved and started.`):f(l,{children:f(X,{i18nKey:`build.blockEditor.logsOf`,values:{id:j(e.id)},components:{code:f(`code`,{})}})})}),e!==null&&f(me,{addonId:j(e.id),maxHeight:`max-h-[560px]`,showFilters:!1})]})]})}function ia(e){return e instanceof Error?e.message:String(e)}e();var aa=[`coreBlocks`,`list`],oa=[`coreBlocks`,`getTypeDefs`],sa=5e3;function ca(e){return e instanceof Error?e.message:String(e)}function la({initialBlockId:e,onBlockIdChange:i,createRequested:a=!1,onCreateConsumed:s}={}){let l=T(),{t:p}=Y(),m=b(),{state:g,openNew:_,openEdit:v,close:y}=Ee({editKey:`block`,newKey:`new`}),[x,C]=r(null),[w,D]=r(null),[O,k]=r(null),A=c({queryKey:aa,refetchInterval:sa,queryFn:async()=>(await m.trpcClient.coreBlocks.list.query({})).blocks}),M=g.mode!==`closed`,N=c({queryKey:oa,enabled:M,staleTime:1/0,gcTime:1/0,queryFn:()=>m.trpcClient.coreBlocks.getTypeDefs.query({})}),P=()=>{A.refetch()},I=u(null),ee=A.data;t(()=>{e===void 0||I.current===e||ee?.find(t=>t.id===e&&F(t)===`code`)!==void 0&&(I.current=e,v(e),i?.(e))},[e,ee,v,i]),t(()=>{a&&(C(null),_(),i?.(null),s?.())},[a,s,i,_]);let L=d({mutationFn:e=>m.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{C(e.block),v(e.block.id),i?.(e.block.id),P()}}),R=d({mutationFn:e=>m.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{C(e.block),v(e.block.id),i?.(e.block.id),P()}}),z=d({mutationFn:e=>m.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{D(null),P()}}),B=d({mutationFn:e=>m.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:P}),V=d({mutationFn:e=>m.trpcClient.coreBlocks.restart.mutate({blockId:e}),onSuccess:P}),te=Dn((A.data??[]).filter(e=>F(e)===`code`)),ne=A.data!==void 0&&te.length===0,re=L.isPending||R.isPending,ae=L.error===null?R.error===null?null:ca(R.error):ca(L.error),oe=g.mode===`edit`?te.find(e=>e.id===g.id)??(x!==null&&x.id===g.id?x:null):null,se=g.mode===`new`||oe===null?null:En(te,oe),ce=n(()=>[{key:`name`,header:p(`build.scriptsTab.name`,`Name`),render:e=>{let t=wn(e),n=fe(e.updatedAt,l);return o(`div`,{className:`min-w-0`,children:[o(`div`,{className:`flex flex-wrap items-center gap-2`,children:[f(`span`,{className:`truncate font-medium`,children:e.name}),f(W,{variant:Tn(t.tone),children:t.label}),f(W,{variant:`info`,children:e.placement}),n!==null&&f(`span`,{className:`text-xs text-foreground-subtle`,children:p(`common.edited`,{when:n})})]}),f(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:t.detail}),O===e.id&&o(`div`,{className:`mt-2 rounded border border-border`,children:[f(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:f(X,{i18nKey:`common.logsOf`,values:{id:j(e.id)},components:{code:f(`code`,{})}})}),f(me,{addonId:j(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})},sortValue:e=>e.name,nowrap:!1},{key:`actions`,header:``,align:`right`,notSortableReason:`Row actions`,render:e=>{let t=B.isPending||z.isPending,n=V.isPending&&V.variables===e.id;return w===e.id?o(`div`,{className:`flex justify-end gap-1`,children:[f(`span`,{className:`text-xs text-foreground-subtle`,children:p(`build.scriptsTab.deleteThisScript`,`Delete this script?`)}),f(q,{variant:`danger`,onClick:()=>z.mutate(e.id),disabled:t,children:p(`common.delete`,`Delete`)}),f(q,{variant:`ghost`,onClick:()=>D(null),children:p(`common.cancel`,`Cancel`)})]}):o(`div`,{className:`flex justify-end gap-1`,children:[f(q,{variant:`ghost`,onClick:t=>{t.stopPropagation(),C(e),v(e.id),i?.(e.id)},title:p(`common.edit`,`Edit`),children:p(`common.edit`,`Edit`)}),f(q,{variant:`ghost`,onClick:t=>{t.stopPropagation(),V.mutate(e.id)},disabled:t||n||!e.enabled,title:e.enabled?p(`build.scriptsTab.restart`,`Restart`):p(`build.scriptsTab.enableItInsteadADisabled`,`Enable it instead — a disabled script has no process`),children:f(E,{className:`h-4 w-4${n?` animate-spin`:``}`})}),f(q,{variant:`ghost`,onClick:t=>{t.stopPropagation(),k(O===e.id?null:e.id)},title:p(`build.scriptsTab.logs`,`Logs`),children:f(S,{className:`h-4 w-4`})}),f(q,{variant:`ghost`,onClick:t=>{t.stopPropagation(),B.mutate({blockId:e.id,enabled:!e.enabled})},disabled:t,title:e.enabled?p(`common.disable`,`Disable`):p(`common.enable`,`Enable`),children:e.enabled?p(`common.disable`,`Disable`):p(`common.enable`,`Enable`)}),f(q,{variant:`ghost`,onClick:t=>{t.stopPropagation(),D(e.id)},title:p(`common.delete`,`Delete`),children:f(h,{className:`h-4 w-4`})})]})}}],[w,O,i,v,z,V.isPending,V.variables,B,p]);return o(`div`,{className:`space-y-3`,children:[f(`p`,{className:`text-xs text-foreground-subtle`,children:A.data===void 0?``:On(te)}),A.error!=null&&f(K,{title:p(`build.scriptsTab.couldNotReadTheScripts`,`Could not read the scripts`),message:ca(A.error),onRetry:P}),f(xe,{columns:ce,rows:te,rowKey:e=>e.id,pageSize:25,maxBodyHeight:G,emptyMessage:ne?p(`build.scriptsTab.noScriptsYetAScript`,`No scripts yet. A script is TypeScript the hub runs in its own process.`):A.data===void 0?p(`build.scriptsTab.loadingScripts`,`Loading scripts…`):p(`build.scriptsTab.noScriptsYet`,`No scripts yet.`),onRowClick:e=>{C(e),v(e.id),i?.(e.id)}}),f(_e,{open:M,onClose:()=>{L.reset(),R.reset(),V.reset(),C(null),y(),i?.(null)},title:se===null?p(`build.scriptsTab.newScript`,`New script`):p(`build.scriptsTab.edit`,`Edit {{name}}`,{name:se.name}),icon:ie,width:`xl`,testId:`script-editor-panel`,children:f(ra,{existing:se,typeDefs:N.data,typeDefsLoading:N.isLoading,saving:re,saveError:ae,restarting:V.isPending,restartError:V.error===null?null:ca(V.error),onRestart:se===null?void 0:()=>V.mutate(se.id),onSave:e=>{let t=se;t===null?L.mutate(e):R.mutate({blockId:t.id,block:e})},onCancel:()=>{L.reset(),R.reset(),V.reset(),C(null),y(),i?.(null)}})}),z.error!=null&&f(K,{message:ca(z.error)}),B.error!=null&&f(K,{message:ca(B.error)}),V.error!=null&&f(K,{message:ca(V.error)})]})}var ua=[`automations`,`scripts`,`custom-device`];function da(e){return e!==null&&ua.some(t=>t===e)}var fa=[`coreBlocks`,`list`,`build-counts`],pa=[`block`,`create`];function ma(e){return e.filter(e=>F(e)===`code`).length}function ha(e){return e.filter(e=>Ge(e.code)).length}function ga(e,t){return t===null?e:`${e} (${String(t)})`}function _a(){let{t:e}=Y(),t=b(),[n,r]=Fe(),i=n.get(`tab`),a=da(i)?i:`automations`,s=n.get(`create`)===`1`,l=c({queryKey:fa,refetchInterval:5e3,queryFn:async()=>(await t.trpcClient.coreBlocks.list.query({})).blocks}).data,u=l===void 0?null:ma(l),d=l===void 0?null:ha(l),p=c({queryKey:[`coreBlocks`,`listCompositions`,`build-counts`],refetchInterval:1e4,queryFn:async()=>t.trpcClient.coreBlocks.listCompositions.query({})}),m=p.data?.state===`loaded`?p.data.views.length:null,h=e=>{r(t=>{let n=new URLSearchParams(t);return n.set(`tab`,`scripts`),n.delete(`create`),e===void 0?n.delete(`block`):n.set(`block`,e),n},{replace:!0})},g=e=>{r(t=>{let n=new URLSearchParams(t);return n.set(`tab`,`automations`),n.delete(`create`),e===null?n.delete(`block`):n.set(`block`,e),n},{replace:!0})},_=e=>{r(t=>{let n=new URLSearchParams(t);return n.set(`tab`,`scripts`),n.delete(`create`),e===null?n.delete(`block`):n.set(`block`,e),n},{replace:!0})},y=()=>{r(e=>{let t=new URLSearchParams(e);return t.set(`create`,`1`),t.delete(`block`),t},{replace:!0})},x=()=>{r(e=>{let t=new URLSearchParams(e);return t.delete(`create`),t},{replace:!0})},S=a===`automations`?`New automation`:a===`scripts`?`New script`:`New composition`,C=Pe(`/build`,{t:e,isAdmin:!0})??{icon:D,title:e(`nav.build`,`Build-your-self`)};return f(Re,{icon:C.icon,title:C.title,subtitle:e(`build.automationsScriptsAndComposedDevices`,`Automations, scripts and composed devices — what this installation does on its own.`),defaultSection:`automations`,sectionsLabel:`${C.title} sections`,fill:!0,actions:o(q,{type:`button`,onClick:y,"data-testid":`build-new`,children:[f(v,{className:`h-4 w-4`}),` `,S]}),sections:[{id:`automations`,label:ga(`Automations`,d),ownedParams:pa,content:f(Pn,{onOpenScripts:h,initialBlockId:a===`automations`?n.get(`block`)??void 0:void 0,onBlockIdChange:g,createRequested:a===`automations`&&s,onCreateConsumed:x})},{id:`scripts`,label:ga(`Scripts`,u),ownedParams:pa,content:f(la,{initialBlockId:a===`scripts`?n.get(`block`)??void 0:void 0,onBlockIdChange:_,createRequested:a===`scripts`&&s,onCreateConsumed:x})},{id:`custom-device`,label:ga(`Custom Device`,m),ownedParams:pa,content:f(er,{createRequested:a===`custom-device`&&s,onCreateConsumed:x})}]})}export{_a as BuildPage};
|