@camstack/addon-admin-ui 1.2.351 → 1.2.353
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/Addons-CSSlxmKX.js +4 -0
- package/dist/assets/AdminPage-BSFohA3i.js +1 -0
- package/dist/assets/{AdminTabs-CLXyClcg.js → AdminTabs-D2EUE5A0.js} +1 -1
- package/dist/assets/{AiProfiles-ChIr3l8J.js → AiProfiles-ZTs3hQfG.js} +1 -1
- package/dist/assets/BrokerForm-jvEIkwfE.js +1 -0
- package/dist/assets/{Build-ByqfAJAw.js → Build-D-cQZg2g.js} +3 -3
- package/dist/assets/{Calendars-B4BPsOl1.js → Calendars-BCpPE1jT.js} +1 -1
- package/dist/assets/{Capabilities-70q-pu5f.js → Capabilities-WsxtQm6G.js} +1 -1
- package/dist/assets/{Cluster-2DoknXyA.js → Cluster-BZpFTXoQ.js} +1 -1
- package/dist/assets/{ClusterStepModel-B-xVF7M9.js → ClusterStepModel-Hz5Uy3Lc.js} +1 -1
- package/dist/assets/{CompositionEditor-DewhGunb.js → CompositionEditor-DlXjZmuS.js} +1 -1
- package/dist/assets/{CompositionEditorPage-DTanATOp.js → CompositionEditorPage-DN1jwFte.js} +1 -1
- package/dist/assets/{Data-ovpjy5aC.js → Data-BiwkrKto.js} +1 -1
- package/dist/assets/{DetectionIntelligence-CJMGXsWL.js → DetectionIntelligence-C_6PVnNp.js} +1 -1
- package/dist/assets/{DeviceDetail-BuLCyjcK.js → DeviceDetail-Dd16eq5_.js} +2 -2
- package/dist/assets/{DeviceDoActionFields-DBwevgKK.js → DeviceDoActionFields-C9efvuLy.js} +1 -1
- package/dist/assets/{Devices-DvSDZeG9.js → Devices-uRSR1KF9.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-enhtADF7.js → EmbedPlayerPage-B0M5LCl6.js} +1 -1
- package/dist/assets/{Events-Dv_1XIVc.js → Events-BqYGW97U.js} +1 -1
- package/dist/assets/Identity-CwF15mWM.js +1 -0
- package/dist/assets/{IntegrationDetail-DSqCZO4S.js → IntegrationDetail-KiizjQky.js} +1 -1
- package/dist/assets/IntegrationHub-CtZ9pFUl.js +1 -0
- package/dist/assets/Integrations-5D0W0NO_.js +1 -0
- package/dist/assets/Integrations-8JethkBu.js +1 -0
- package/dist/assets/{Locations-BNBOCArW.js → Locations-C0VGgBDh.js} +1 -1
- package/dist/assets/Logs-BdD9ktZ1.js +1 -0
- package/dist/assets/{MotionZonesSettings-aDMRPb0C.js → MotionZonesSettings-BMZDT9aS.js} +1 -1
- package/dist/assets/{MyAccess-bpwJEqEY.js → MyAccess-VT-IYS_0.js} +1 -1
- package/dist/assets/Network-DAS4ofeO.js +1 -0
- package/dist/assets/NodeAddonsSettingsPanel-2ImNi4l_.js +1 -0
- package/dist/assets/{Notifications-ML8zmn39.js → Notifications-CtpsBCVg.js} +1 -1
- package/dist/assets/{Plates-DIoGtVsY.js → Plates-DRYDfqhl.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-DFTAA5dg.js → PrivacyMaskSettings-e1shTFq0.js} +1 -1
- package/dist/assets/{Recordings-CoOwir1H.js → Recordings-Cp1t8Lsr.js} +1 -1
- package/dist/assets/ScanNetworkModal-CtcUY86A.js +1 -0
- package/dist/assets/{SceneMonitorEditor-rhbNHUiH.js → SceneMonitorEditor-B8SaYaRg.js} +1 -1
- package/dist/assets/{Scenes-B6vGKWeX.js → Scenes-UX3CQiSD.js} +1 -1
- package/dist/assets/{Settings-PKIvMwLh.js → Settings-hvJAx444.js} +1 -1
- package/dist/assets/{Showroom-CiPParUW.js → Showroom-DGF0GI0t.js} +1 -1
- package/dist/assets/{Terminal-yp9gTtPT.js → Terminal-CnAgipZG.js} +1 -1
- package/dist/assets/{Viewer-CrwFaVq7.js → Viewer-u429VTlj.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-Cc2A3Ptb.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-Dmoq9iz_.js} +1 -1
- package/dist/assets/addon-display-names-BkwMrExv.js +1 -0
- package/dist/assets/{archive-D5jN_xRr.js → archive-DEGN5b-2.js} +1 -1
- package/dist/assets/{authed-media-DIbw4JLn.js → authed-media-zoQQL-DU.js} +1 -1
- package/dist/assets/{boxes-Cz0W-SHm.js → boxes-D53xb3mF.js} +1 -1
- package/dist/assets/circle-slash-g5R19IPN.js +1 -0
- package/dist/assets/{client-DWiaUxRQ.js → client-CxHFB-xR.js} +2 -2
- package/dist/assets/crop-DTBzwOc0.js +1 -0
- package/dist/assets/{debounced-invalidate-BhgMMKYH.js → debounced-invalidate-Di49k3Ur.js} +1 -1
- package/dist/assets/{device-integration-icon-BnWP0LSQ.js → device-integration-icon-C44r3pOz.js} +1 -1
- package/dist/assets/device-picker-model-Y21yLCDr.js +1 -0
- package/dist/assets/{dist-brqlsTXV.js → dist-B_y7Xf3Y.js} +2 -2
- package/dist/assets/{dist-BvHPU1Ls.js → dist-CupCPVu2.js} +1 -1
- package/dist/assets/{face-bbox--pttun6Q.js → face-bbox-BekWkYM8.js} +1 -1
- package/dist/assets/{hard-drive-download-DvX0zc41.js → hard-drive-download-CaBI4JJt.js} +1 -1
- package/dist/assets/{hostInit-BxEpkmct.js → hostInit-LeZtjcV4.js} +1 -1
- package/dist/assets/{index-Buq71VHG.js → index-BdYsVZMw.js} +3 -3
- package/dist/assets/index-CFkS00_M.css +2 -0
- package/dist/assets/{layers-CTxykl5p.js → layers-Bl4GXnaV.js} +1 -1
- package/dist/assets/{location-owned-usage-CV2yEH4j.js → location-owned-usage-B2EH12kQ.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-9f9ea6de.js → mf-entry-bootstrap-0-f71236c8.js} +2 -2
- package/dist/assets/mount-Y21yLCDr.js +1 -0
- package/dist/assets/{notification-schedule-field-CQPEDiDO.js → notification-schedule-field-CX_ISfhK.js} +1 -1
- package/dist/assets/{player-overlays-CrKWnjLj.js → player-overlays-CHWCYkGf.js} +1 -1
- package/dist/assets/remoteEntry-D2L5CI92.js +1 -0
- package/dist/assets/{send-SN1L0Kiz.js → send-BxCvGnMf.js} +1 -1
- package/dist/assets/{settings-2-BY8TSBhz.js → settings-2-CWTgzyTw.js} +1 -1
- package/dist/assets/{src-Bkpo8B0D.js → src-Crb8RLzq.js} +3 -3
- package/dist/assets/{use-scenes-feed-Dwp-15g8.js → use-scenes-feed-CsZwOmyp.js} +1 -1
- package/dist/assets/{use-stationary-objects-CCknD3DG.js → use-stationary-objects-DTKCTzni.js} +1 -1
- package/dist/assets/useEventInvalidation-Y21yLCDr.js +1 -0
- package/dist/assets/{useNodeUrlSelection-NjZtQ6mH.js → useNodeUrlSelection-BSYJnQKG.js} +1 -1
- package/dist/assets/user-round-BR8uDCSh.js +1 -0
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-Cok7af3G.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-mzuJ2veF.js} +2 -2
- package/dist/index.html +8 -8
- package/dist/server/addon.js +17 -2
- package/package.json +1 -1
- package/dist/assets/AddonCollectionPage-BwMkNEOp.js +0 -1
- package/dist/assets/Addons-80LT7Kq1.js +0 -4
- package/dist/assets/AdminPage-CiKtOLQm.js +0 -1
- package/dist/assets/BrokerForm-DGnvvf1S.js +0 -1
- package/dist/assets/Identity-Cc3G2Fa0.js +0 -1
- package/dist/assets/Integrations-Beb2EhOS.js +0 -1
- package/dist/assets/Integrations-DYhW5V60.js +0 -1
- package/dist/assets/Logs-CScz1BkD.js +0 -1
- package/dist/assets/Network-Bx7uEVdz.js +0 -1
- package/dist/assets/NodeAddonsSettingsPanel-BgxOJU3d.js +0 -1
- package/dist/assets/ScanNetworkModal-BPZGLiZQ.js +0 -1
- package/dist/assets/addon-display-names-DvSEQty-.js +0 -1
- package/dist/assets/circle-slash-tZFznooZ.js +0 -1
- package/dist/assets/crop-B8tpwR6u.js +0 -1
- package/dist/assets/device-picker-model-D1aOGj40.js +0 -1
- package/dist/assets/index-CFu9bpWo.css +0 -2
- package/dist/assets/mount-D1aOGj40.js +0 -1
- package/dist/assets/remoteEntry-BFpE5_8_.js +0 -1
- package/dist/assets/useBodyScrollLock-BDocajQE.js +0 -1
- package/dist/assets/useEventInvalidation-D1aOGj40.js +0 -1
- package/dist/assets/user-round-DCIxbUZ9.js +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import{I as e,K as t,M as n,Q as r,S as i,T as a,W as o,a as s,b as c,q as l,t as u,x as d,z as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as p,gt as m,ht as h,st as g,vt as _}from"./player-overlays-
|
|
1
|
+
import{I as e,K as t,M as n,Q as r,S as i,T as a,W as o,a as s,b as c,q as l,t as u,x as d,z as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as p,gt as m,ht as h,st as g,vt as _}from"./player-overlays-CHWCYkGf.js";import{Ai as v,Bn as y,F as b,Gt as x,Gu as S,Iu as C,Jt as w,Kt as T,Ld as E,Ln as D,Mi as O,Nt as k,Pn as A,Rt as j,St as M,Ti as N,Uu as P,Wu as F,Zn as I,ar as L,da as ee,dn as R,en as te,fn as z,ht as ne,if as re,ji as ie,ju as ae,ki as oe,md as se,nn as ce,qt as le,rd as B,sf as ue,su as de,tn as fe,wi as pe,wt as me,zn as V,zt as he}from"./src-Crb8RLzq.js";import{Dr as ge,Er as _e,Kt as ve,Or as H,Tr as U,ar as ye,oi as be,or as xe,pr as Se,rr as W,vr as G,wr as Ce,yr as we}from"./client-CxHFB-xR.js";import{F as Te,J as Ee,V as K,W as De,_ as Oe,h as ke,k as Ae,m as je}from"./index-BdYsVZMw.js";import{t as Me}from"./AdminPage-BSFohA3i.js";import{t as Ne}from"./DeviceDoActionFields-C9efvuLy.js";var Pe=_(`braces`,[[`path`,{d:`M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1`,key:`ezmyqa`}],[`path`,{d:`M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1`,key:`e1hn23`}]]),Fe=_(`ungroup`,[[`rect`,{width:`8`,height:`6`,x:`5`,y:`4`,rx:`1`,key:`nzclkv`}],[`rect`,{width:`8`,height:`6`,x:`11`,y:`14`,rx:`1`,key:`4tytwb`}]]),Ie=`const AUTOMATION_RECIPE =`,Le=`// EJECTED from the visual automation editor — this file is now hand-owned.
|
|
2
2
|
// The recipe that produced it was removed with it, on purpose: while it was
|
|
3
3
|
// here the editor could re-open this block and overwrite everything below.`;function Re(e){return e.includes(Ie)}function ze(e){let t=e.indexOf(Ie);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 Be(e){let t=ze(e);if(t===null)return{ok:!1,reason:`this block carries no AUTOMATION_RECIPE literal`};let n;try{n=JSON.parse(t.json)}catch(e){return{ok:!1,reason:`the embedded recipe is not readable JSON: ${e instanceof Error?e.message:String(e)}`}}let r=U.safeParse(n);if(!r.success){let e=r.error.issues[0];return{ok:!1,reason:`the embedded recipe does not match the recipe schema${e===void 0?``:` at ${e.path.join(`.`)}: ${e.message}`}`}}return{ok:!0,recipe:r.data}}function Ve(e){let t=ze(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)}${Le}${e.slice(i)}`}r();var He=6e4;function Ue(){let e=ee({projection:`slim`});return o(()=>(e.data??[]).filter(e=>ve(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 We(e){let t=p();return s({queryKey:[`automation`,`wireable-fields`,e],enabled:e>0,staleTime:He,queryFn:async()=>(await t.trpcClient.deviceManager.getWireableFields.query({deviceId:e})).caps})}function Ge(e,t){return e.find(e=>e.cap===t)?.fields??[]}function q({children:e}){return d(`span`,{className:`mb-1 block text-xs text-foreground-subtle`,children:e})}function Ke(e){let t=We(e.deviceId);if(t.data!==void 0)return Ge(t.data,e.cap).find(t=>t.path===e.fieldPath)}function qe({value:e,devices:t,onChange:n}){let r=We(e.deviceId),a=r.data??[],o=Ge(a,e.cap);return i(c,{children:[i(`label`,{className:`min-w-[10rem] flex-1`,children:[d(q,{children:`Device`}),d(V,{value:String(e.deviceId),onChange:e=>n({deviceId:Number(e.target.value),cap:``,fieldPath:``}),options:[{value:`0`,label:`Select a device…`},...t.map(e=>({value:String(e.id),label:e.name}))]})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(q,{children:`Capability`}),d(V,{value:e.cap,disabled:e.deviceId===0,onChange:t=>n({...e,cap:t.target.value,fieldPath:``}),options:[{value:``,label:Je(e.deviceId,a.length,r.isLoading)},...a.map(e=>({value:e.cap,label:e.cap}))]})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(q,{children:`Field`}),d(V,{value:e.fieldPath,disabled:e.cap===``,onChange:t=>n({...e,fieldPath:t.target.value}),options:[{value:``,label:o.length===0?`No readable fields`:`Select a field…`},...o.map(e=>({value:e.path,label:`${e.path} (${e.kind})`}))]})]})]})}function Je(e,t,n){return e===0?`Pick a device first`:n?`Reading this device…`:t===0?`This device reports no readable capabilities`:`Select a capability…`}var Ye=[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`,`contains`,`in`];function Xe(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 Ye}}function Ze(e){switch(e){case`eq`:return`is`;case`ne`:return`is not`;case`gt`:return`is above`;case`gte`:return`is at least`;case`lt`:return`is below`;case`lte`:return`is at most`;case`contains`:return`contains`;default:return`is one of`}}function Qe(e){return Xe(e).map(e=>({value:e,label:Ze(e)}))}function $e(e){switch(e){case`device-state`:return`A device field changes`;case`device-event`:return`An event happens`;case`schedule`:return`On a schedule`;default:return`Only when run by hand`}}var et={triggers:[],actions:[]};function tt(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 nt(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 rt(){return{kind:`condition`,deviceId:0,cap:``,fieldPath:``,operator:`eq`,value:``}}function it(){return{kind:`expression`,expr:``,bindings:{}}}function at(e,t,n){return e.map((e,r)=>r===t?n:e)}function ot(e,t){return e.filter((e,n)=>n!==t)}function st(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=ot(e,t);return[...a.slice(0,i),r,...a.slice(i)]}function ct(e,t){return{...e,triggers:[...t]}}function lt(e,t){return{...e,actions:[...t]}}var ut=[{value:`cap`,label:`Do something`},{value:`wait`,label:`Wait`},{value:`code`,label:`Run code`}];function dt({actions:e,devices:t,devicesState:n=`answered`,onChange:r}){return i(`div`,{className:`space-y-2`,children:[e.length===0&&d(`p`,{className:`text-xs text-warning`,children:`No actions yet. An automation that does nothing is not an automation.`}),e.map((a,o)=>i(`div`,{className:`rounded border border-border p-3 space-y-2`,children:[i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(L,{variant:`default`,children:o+1}),i(`label`,{className:`w-40`,children:[d(q,{children:`Step`}),d(V,{value:a.kind,onChange:t=>r(at(e,o,nt(ft(t.target.value)))),options:ut.map(e=>({value:e.value,label:e.label}))})]}),i(`div`,{className:`ml-auto flex items-center gap-1`,children:[d(y,{variant:`ghost`,disabled:o===0,onClick:()=>r(st(e,o,o-1)),title:`Run this step earlier`,children:d(re,{className:`h-3.5 w-3.5`})}),d(y,{variant:`ghost`,disabled:o===e.length-1,onClick:()=>r(st(e,o,o+1)),title:`Run this step later`,children:d(ue,{className:`h-3.5 w-3.5`})}),d(y,{variant:`ghost`,onClick:()=>r(ot(e,o)),title:`Remove this step`,children:d(g,{className:`h-3.5 w-3.5`})})]})]}),a.kind===`wait`&&i(`label`,{className:`block w-32`,children:[d(q,{children:`Seconds`}),d(z,{type:`number`,min:0,max:300,value:String(a.seconds),onChange:t=>r(at(e,o,{kind:`wait`,seconds:Number(t.target.value)}))})]}),a.kind===`code`&&i(`label`,{className:`block`,children:[d(q,{children:`Code`}),d(`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(at(e,o,{kind:`code`,code:t.target.value}))}),i(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:[`Compiled into this automation's own block by the same compiler as a script — not evaluated at run time. `,d(`code`,{children:`ctx`}),` and `,d(`code`,{children:`vars`}),` are in scope.`]})]}),a.kind===`cap`&&d(mt,{action:a,devices:t,devicesState:n,onChange:t=>r(at(e,o,t))})]},`${a.kind}-${String(o)}`)),i(`div`,{className:`flex items-center gap-2`,children:[i(y,{variant:`outline`,onClick:()=>r([...e,nt(`cap`)]),children:[d(P,{className:`h-4 w-4`}),` Step`]}),e.length>1&&d(`span`,{className:`text-xs text-foreground-subtle`,children:`Steps run in order and stop at the first failure.`})]})]})}function ft(e){return ut.find(t=>t.value===e)?.value??`cap`}function pt(e){return typeof e==`number`?e:typeof e==`object`&&e&&`$var`in e?{$var:e.$var}:[...e]}function mt({action:e,devices:t,devicesState:n,onChange:r}){return d(Ne,{value:e,allowTriggerDevice:!0,allowMultiSameFamily:!0,devices:t,listState:n,onChange:e=>r({kind:`cap`,deviceId:pt(e.deviceId),cap:e.cap,method:e.method,...e.args===void 0?{}:{args:{...e.args}}})})}function ht({value:e,field:t,onChange:n}){return t?.kind===`boolean`?d(V,{value:e===!0?`true`:`false`,onChange:e=>n(e.target.value===`true`),options:[{value:`true`,label:`true`},{value:`false`,label:`false`}]}):t?.kind===`enum`&&t.enumValues!==void 0&&t.enumValues.length>0?d(V,{value:String(e),onChange:e=>n(e.target.value),options:t.enumValues.map(e=>({value:e,label:e}))}):t?.kind===`number`?d(z,{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)}}):d(z,{value:String(e),placeholder:`value`,onChange:e=>n(e.target.value)})}function gt({value:e,field:t,onChange:n}){return d(z,{value:e.join(`, `),placeholder:`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 _t(e){return typeof e==`object`}function vt(e){return _t(e)?e[0]??``:e}function yt(e){return _t(e)?e:typeof e==`boolean`?[]:[e]}function bt({leaf:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Ke(r),o=Qe(a?.kind),s=e.operator===`in`,c=t=>{n({...e,deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath})},l=t=>{let r=xt(t,o);n({...e,operator:r,value:r===`in`?yt(e.value):vt(e.value)})};return i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(qe,{value:r,devices:t,onChange:c}),i(`label`,{className:`min-w-[8rem]`,children:[d(q,{children:`Comparison`}),d(V,{value:e.operator,onChange:e=>l(e.target.value),options:o.map(e=>({value:e.value,label:e.label}))})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(q,{children:`Value`}),s?d(gt,{value:yt(e.value),field:a,onChange:t=>n({...e,value:t})}):d(ht,{value:vt(e.value),field:a,onChange:t=>n({...e,value:t})})]})]})}function xt(e,t){return t.find(t=>t.value===e)?.value??`eq`}var St={kind:`global`,sourceStableId:``,cap:``,fieldPath:``};function Ct({leaf:e,devices:t,onChange:n}){let r=Object.entries(e.bindings),a=t=>{n({kind:`expression`,expr:e.expr,bindings:t})};return i(`div`,{className:`space-y-2`,children:[i(`label`,{className:`block`,children:[d(q,{children:`Expression`}),d(z,{value:e.expr,placeholder:`indoor - outdoor > 5`,onChange:t=>n({kind:`expression`,expr:t.target.value,bindings:e.bindings})}),d(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:`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.`})]}),i(`div`,{className:`space-y-1.5`,children:[r.length===0&&d(`p`,{className:`text-xs text-foreground-subtle`,children:`No names bound yet. An expression reads devices only through these.`}),r.map(([n,r])=>d(wt,{alias:n,source:r,devices:t,onRename:t=>a(At(e.bindings,n,t)),onChange:t=>a({...e.bindings,[n]:t}),onRemove:()=>a(jt(e.bindings,n))},n)),i(y,{variant:`ghost`,onClick:()=>a({...e.bindings,[kt(e.bindings)]:St}),children:[d(P,{className:`h-3.5 w-3.5`}),` Name`]})]})]})}function wt({alias:e,source:t,devices:n,onRename:r,onChange:a,onRemove:o}){let s=t.kind===`literal`,c=s?{deviceId:0,cap:``,fieldPath:``}:{deviceId:Dt(n,Et(t)),cap:t.cap,fieldPath:t.fieldPath};return i(`div`,{className:`flex flex-wrap items-end gap-2 rounded border border-border p-2`,children:[i(`label`,{className:`w-32`,children:[d(q,{children:`Name`}),d(z,{value:e,placeholder:`indoor`,onChange:e=>r(e.target.value)})]}),i(`label`,{className:`w-36`,children:[d(q,{children:`Reads`}),d(V,{value:s?`literal`:`global`,onChange:e=>a(e.target.value===`literal`?{kind:`literal`,value:``}:St),options:[{value:`global`,label:`A device field`},{value:`literal`,label:`A constant`}]})]}),s?i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(q,{children:`Constant`}),d(z,{value:t.value===null?``:String(t.value),placeholder:`5`,onChange:e=>a({kind:`literal`,value:Tt(e.target.value)})})]}):d(qe,{value:c,devices:n,onChange:e=>a({kind:`global`,sourceStableId:Ot(n,e.deviceId),cap:e.cap,fieldPath:e.fieldPath})}),d(y,{variant:`ghost`,onClick:o,title:`Remove this name`,children:d(g,{className:`h-3.5 w-3.5`})})]})}function Tt(e){let t=e.trim();return t===`true`?!0:t===`false`?!1:t!==``&&!Number.isNaN(Number(t))?Number(t):e}function Et(e){return e.kind===`global`?e.sourceStableId:``}function Dt(e,t){return e.find(e=>e.stableId===t)?.id??0}function Ot(e,t){return e.find(e=>e.id===t)?.stableId??``}function kt(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 At(e,t,n){let r={};for(let[i,a]of Object.entries(e))i===t?r[n]=a:r[i]=a;return r}function jt(e,t){let n={};for(let[r,i]of Object.entries(e))r!==t&&(n[r]=i);return n}function J(e){return e.kind===`all`||e.kind===`any`}function Y(e){let t=e.conditions;return t===void 0?{kind:`all`,children:[]}:J(t)?t:{kind:`all`,children:[t]}}function Mt(e,t){return t===null||J(t)&&t.children.length===0?{triggers:e.triggers,actions:e.actions}:{triggers:e.triggers,actions:e.actions,conditions:t}}function Nt(e){return Mt(e,Y(e))}function Pt(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?Pt(e.child,r):null;if(!J(e))return null;let i=e.children[n];return i===void 0?null:Pt(i,r)}function X(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=X(e.child,i,n);return t===null?null:{kind:`not`,child:t}}if(!J(e))return e;let a=e.children[r];if(a===void 0)return e;let o=X(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 Ft(e){return e===null?null:H({triggers:[{kind:`manual`}],actions:[{kind:`wait`,seconds:0}],conditions:e})}function It(e){let t=Y(e);return{depth:t.children.length===0?0:_e(t),leaves:t.children.length===0?0:ge(t),depthLimit:3,leafLimit:32}}function Lt(e,t){let n=Ft(t);return n===null?{ok:!0,recipe:Mt(e,t)}:{ok:!1,reason:n}}function Rt(e,t){let n=Y(e);return Lt(e,{kind:n.kind,children:[...n.children,t]})}function zt(e,t,n){return Mt(e,X(Y(e),t,()=>n))}function Bt(e,t){return Mt(e,X(Y(e),t,()=>null))}function Vt(e,t,n){return Mt(e,X(Y(e),t,e=>J(e)?{kind:n,children:e.children}:e))}function Ht(e,t){return Pt(Y(e),t)===null?{ok:!1,reason:`that row is no longer there`}:Lt(e,X(Y(e),t,e=>e.kind===`not`?e.child:{kind:`not`,child:e}))}function Ut(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 Wt(e,t,n){if(t.length<2)return{ok:!1,reason:`select at least two rows — a group of one is just the row`};if(new Set(t.map(e=>e.slice(0,-1).join(`/`))).size!==1)return{ok:!1,reason:`those rows are in different groups — a group can only be made from rows side by side`};let r=Ut(t[0]??[]);if(r===null)return{ok:!1,reason:`the root list cannot be grouped into itself`};let i=Y(e),a=Pt(i,r.path);if(a===null||!J(a))return{ok:!1,reason:`those rows are inside a NOT — remove it before grouping them`};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:`one of the selected rows is no longer there`};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 Lt(e,X(i,r.path,()=>d))}function Gt(e,t){if(t.length===0)return{ok:!1,reason:`the outer list is not a group — there is nothing to dissolve`};let n=Y(e),r=Pt(n,t);if(r===null)return{ok:!1,reason:`that group is no longer there`};if(r.kind===`not`)return Lt(e,X(n,t,()=>r.child));if(!J(r))return{ok:!1,reason:`that row is a condition, not a group`};let i=Ut(t);if(i===null)return{ok:!1,reason:`that group has no parent to dissolve into`};let a=Pt(n,i.path);if(a===null||!J(a))return{ok:!1,reason:`a group inside a NOT cannot be dissolved in place`};let o={kind:a.kind,children:[...a.children.slice(0,i.index),...r.children,...a.children.slice(i.index+1)]};return Lt(e,X(n,i.path,()=>o))}r();var Kt=[{value:`all`,label:`ALL of`},{value:`any`,label:`ANY of`}];function qt(e){return e.join(`/`)}function Jt(e){return e===``?[]:e.split(`/`).map(e=>Number(e))}function Yt({recipe:e,devices:t,onChange:n}){let[r,a]=l([]),[s,c]=l(null),u=Y(e),f=It(e),p=o(()=>r.map(Jt),[r]),m=e=>{if(!e.ok){c(e.reason);return}c(null),a([]),n(e.recipe)},h=Wt(e,p,`all`),g=Wt(e,p,`any`),_=p.length===1?Ht(e,p[0]??[]):{ok:!1,reason:`select exactly one row to negate`},v={devices:t,selected:new Set(r),onToggleSelect:e=>a(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),onUpdate:(t,r)=>n(zt(e,t,r)),onRemove:t=>{a([]),n(Bt(e,t))},onSetKind:(t,r)=>n(Vt(e,t,r)),onUngroup:t=>m(Gt(e,t))};return i(`div`,{className:`space-y-2`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(L,{variant:`default`,children:`And only if`}),d(`div`,{className:`w-32`,children:d(V,{value:u.kind,onChange:t=>n(Vt(e,[],Xt(t.target.value))),options:Kt})}),i(`span`,{className:`text-xs text-foreground-subtle`,children:[`depth `,f.depth,`/`,f.depthLimit,` · `,f.leaves,`/`,f.leafLimit,` conditions`]})]}),u.children.length===0?d(`p`,{className:`text-xs text-foreground-subtle`,children:`No conditions. The actions run every time a trigger fires.`}):d(Zt,{container:u,path:[],handlers:v}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(y,{variant:`outline`,onClick:()=>m(Rt(e,rt())),title:`Compare one device field to a value`,children:[d(P,{className:`h-4 w-4`}),` Condition`]}),i(y,{variant:`outline`,onClick:()=>m(Rt(e,it())),title:`Arithmetic across device fields — the bounded expression engine`,children:[d(Pe,{className:`h-4 w-4`}),` Expression`]}),d(`span`,{className:`mx-1 h-5 w-px bg-border`}),d(y,{variant:`ghost`,disabled:!h.ok,onClick:()=>m(h),title:h.ok?`All selected rows must be true`:h.reason,children:`Group as ALL`}),d(y,{variant:`ghost`,disabled:!g.ok,onClick:()=>m(g),title:g.ok?`Any one of the selected rows is enough`:g.reason,children:`Group as ANY`}),d(y,{variant:`ghost`,disabled:!_.ok,onClick:()=>m(_),title:_.ok?`Invert the selected row`:_.reason,children:`NOT`}),r.length>0&&i(`span`,{className:`text-xs text-foreground-subtle`,children:[r.length,` selected`]})]}),s!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-2 text-xs text-warning`,children:s})]})}function Xt(e){return e===`any`?`any`:`all`}function Zt({container:e,path:t,handlers:n}){return d(`div`,{className:`space-y-1.5`,children:e.children.map((e,r)=>d(Qt,{node:e,path:[...t,r],handlers:n},qt([...t,r])))})}function Qt({node:e,path:t,handlers:n}){let r=qt(t),a=d(R,{checked:n.selected.has(r),onChange:()=>n.onToggleSelect(r),"aria-label":`Select this row for grouping`});return J(e)?i(`div`,{className:`rounded border border-border bg-surface-subtle/40 p-2`,children:[i(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[a,d(`div`,{className:`w-32`,children:d(V,{value:e.kind,onChange:e=>n.onSetKind(t,Xt(e.target.value)),options:Kt})}),i(y,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Dissolve this group, keeping its rows`,children:[d(Fe,{className:`h-3.5 w-3.5`}),` Ungroup`]}),d(y,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Delete this group and everything in it`,children:d(g,{className:`h-3.5 w-3.5`})})]}),d(`div`,{className:`pl-4`,children:d(Zt,{container:e,path:t,handlers:n})})]}):e.kind===`not`?i(`div`,{className:`rounded border border-border p-2`,children:[i(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[a,d(L,{variant:`warning`,children:`NOT`}),i(y,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Remove the NOT, keeping the row`,children:[d(Fe,{className:`h-3.5 w-3.5`}),` Remove NOT`]})]}),d(`div`,{className:`pl-4`,children:d(Qt,{node:e.child,path:[...t,0],handlers:n})})]}):i(`div`,{className:`flex items-start gap-2 rounded border border-border p-2`,children:[d(`div`,{className:`pt-6`,children:a}),d(`div`,{className:`min-w-0 flex-1`,children:e.kind===`condition`?d(bt,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)}):d(Ct,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)})}),d(y,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Remove this condition`,children:d(g,{className:`h-3.5 w-3.5`})})]})}r();function $t({code:e,error:t,canEject:n,ejecting:r,onEject:a}){let[o,s]=l(!1),c=I(),u=async()=>{await c({title:`Eject to code — this cannot be undone`,message:`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:`Eject to code`,cancelLabel:`Keep it visual`,variant:`warning`})&&a()};return i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2 px-3 py-2`,children:[i(y,{variant:`ghost`,onClick:()=>s(!o),children:[d(o?m:h,{className:`h-4 w-4`}),`Generated code`]}),d(`span`,{className:`text-xs text-foreground-subtle`,children:`Derived from the recipe above — regenerated on every save, never edited here.`}),i(y,{className:`ml-auto`,variant:`ghost`,disabled:!n||e===null||r,onClick:()=>void u(),title:n?`Take permanent ownership of this code as a script`:`Save the automation first — there is no stored block to eject yet`,children:[d(je,{className:`h-4 w-4`}),` Eject to code`]})]}),o&&d(`div`,{className:`border-t border-border p-3`,children:e===null?d(`p`,{className:`text-xs text-warning`,children:t??`The recipe is not complete enough to generate a block yet.`}):d(k,{maxHeight:420,children:e})})]})}var en=[`device-state`,`device-event`,`schedule`,`manual`],tn=Object.values(be).sort((e,t)=>e.localeCompare(t));function nn({triggers:e,devices:t,onChange:n}){return i(`div`,{className:`space-y-2`,children:[e.length===0&&d(`p`,{className:`text-xs text-warning`,children:`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)=>d(rn,{trigger:r,devices:t,position:i,onChange:t=>n(at(e,i,t)),onRemove:()=>n(ot(e,i))},`${r.kind}-${String(i)}`)),i(y,{variant:`outline`,onClick:()=>n([...e,tt(`device-state`)]),title:`Add another way this automation can start`,children:[d(P,{className:`h-4 w-4`}),` Trigger`]})]})}function rn({trigger:e,devices:t,position:n,onChange:r,onRemove:a}){return i(`div`,{className:`rounded border border-border p-3`,children:[i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(L,{variant:`default`,children:n===0?`When`:`or when`}),i(`label`,{className:`min-w-[13rem] flex-1`,children:[d(q,{children:`Trigger`}),d(V,{value:e.kind,onChange:e=>r(tt(an(e.target.value))),options:en.map(e=>({value:e,label:$e(e)}))})]}),d(y,{variant:`ghost`,onClick:a,title:`Remove this trigger`,children:d(g,{className:`h-4 w-4`})})]}),i(`div`,{className:`mt-2 flex flex-wrap items-end gap-2`,children:[e.kind===`device-state`&&d(sn,{trigger:e,devices:t,onChange:r}),e.kind===`device-event`&&d(ln,{trigger:e,devices:t,onChange:r}),e.kind===`schedule`&&i(`label`,{className:`min-w-[14rem] flex-1`,children:[d(q,{children:`Cron expression`}),d(z,{value:e.cron,placeholder:`0 30 23 * * *`,onChange:e=>r({kind:`schedule`,cron:e.target.value})}),i(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:[`Six fields, seconds first. `,d(`code`,{children:`0 30 23 * * *`}),` is every night at 23:30.`]})]}),e.kind===`manual`&&i(`p`,{className:`text-xs text-foreground-subtle`,children:[`Runs only when someone presses `,d(`strong`,{children:`Run actions`}),`. The conditions are still evaluated — a manual run is a run, not an override.`]})]})]})}function an(e){return en.find(t=>t===e)??`manual`}function on(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 sn({trigger:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Ke(r),o={...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 i(c,{children:[d(qe,{value:r,devices:t,onChange:e=>n(on(e,o))}),i(`div`,{className:`min-w-[11rem] flex-1`,children:[d(q,{children:`Becomes`}),i(`div`,{className:`flex items-center gap-2`,children:[i(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[d(R,{checked:e.becomes===void 0,onChange:e=>n(on(r,{...o,...e.target.checked?{becomes:void 0}:{becomes:``}}))}),`any change`]}),e.becomes!==void 0&&d(ht,{value:e.becomes,field:a,onChange:e=>n(on(r,{...o,becomes:e}))})]})]}),i(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[d(R,{checked:e.edge===!0,onChange:e=>n(on(r,{...o,...e.target.checked?{edge:!0}:{edge:void 0}}))}),`only on a change`]}),i(`label`,{className:`w-28`,children:[d(q,{children:`Held for (s)`}),d(z,{type:`number`,min:0,value:e.forMs===void 0?``:String(e.forMs/1e3),placeholder:`0`,onChange:e=>n(on(r,{...o,forMs:cn(e.target.value)}))})]}),i(`label`,{className:`w-28`,children:[d(q,{children:`Debounce (s)`}),d(z,{type:`number`,min:0,value:e.debounceMs===void 0?``:String(e.debounceMs/1e3),placeholder:`0`,onChange:e=>n(on(r,{...o,debounceMs:cn(e.target.value)}))})]})]})}function cn(e){if(e.trim()===``)return;let t=Number(e);if(!(Number.isNaN(t)||t<0))return Math.round(t*1e3)}function ln({trigger:e,devices:t,onChange:n}){return i(c,{children:[i(`label`,{className:`min-w-[15rem] flex-1`,children:[d(q,{children:`Event category`}),d(V,{value:e.category,onChange:t=>n({kind:`device-event`,category:t.target.value,...e.deviceId===void 0?{}:{deviceId:e.deviceId}}),options:[{value:``,label:`Select an event…`},...tn.map(e=>({value:e,label:e}))]})]}),i(`label`,{className:`min-w-[11rem] flex-1`,children:[d(q,{children:`From device`}),d(V,{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:`Any device`},...t.map(e=>({value:String(e.id),label:e.name}))]})]})]})}r();var un=`hub`;function dn({existing:e,initialRecipe:t,saving:n,saveError:r,ejecting:a,onSave:s,onEject:c,onCancel:u}){let[f,p]=l(e?.name??``),[m,h]=l(()=>Nt(t)),[g,_]=l(!1),v=Ue(),b=H(m),x=o(()=>pn(m),[m]),S=o(()=>mn(f.trim()===``?`Untitled automation`:f.trim(),m),[f,m]),C=f.trim()===``,w=C||b!==null||x!==null||S.code===null;return d(A,{children:i(`div`,{className:`space-y-4 p-4`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`h3`,{className:`font-medium`,children:e===null?`New automation`:`Edit ${e.name}`}),d(L,{variant:`info`,children:`runs on the hub`})]}),i(`label`,{className:`block max-w-md text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Name`}),d(z,{className:`mt-1`,value:f,onChange:e=>p(e.target.value),placeholder:`What this automation does`})]}),d(fn,{step:`1`,title:`When`,subtitle:`Any one of these starts a run.`,children:d(nn,{triggers:m.triggers,devices:v,onChange:e=>h(ct(m,e))})}),d(fn,{step:`2`,title:`And only if`,subtitle:`Checked after a trigger fires. Nothing runs unless this is true.`,children:d(Yt,{recipe:m,devices:v,onChange:h})}),d(fn,{step:`3`,title:`Then`,subtitle:`In this order, stopping at the first failure.`,children:d(dt,{actions:m.actions,devices:v,onChange:e=>h(lt(m,e))})}),d($t,{code:S.code,error:S.error,canEject:e!==null,ejecting:a,onEject:c}),b!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:b}),b===null&&x!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:x}),r!==null&&d(`p`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:r}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(y,{onClick:()=>{S.code!==null&&s({name:f.trim(),code:S.code,enabled:e?.enabled??!0,placement:un})},disabled:n||w,children:[n&&d(B,{className:`h-4 w-4 animate-spin`}),` Save`]}),i(y,{variant:`ghost`,onClick:()=>_(!g),disabled:e===null,title:e===null?`Logs appear once the automation has been saved and started`:`Show this automation's process logs`,"data-testid":`automation-logs-toggle`,children:[d(ae,{className:`h-4 w-4`}),` Logs `,g?`▾`:`▸`]}),d(y,{variant:`ghost`,onClick:u,disabled:n,children:`Close`}),C&&d(L,{variant:`warning`,children:`Name required`})]}),g&&e!==null&&i(`div`,{className:`rounded border border-border`,"data-testid":`automation-logs-panel`,children:[i(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,d(`code`,{children:W(e.id)})]}),d(M,{addonId:W(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})})}function fn({step:e,title:t,subtitle:n,children:r}){return i(`section`,{className:`border-l-2 border-border pl-4`,children:[i(`div`,{className:`mb-2 flex flex-wrap items-baseline gap-2`,children:[d(`span`,{className:`text-xs font-mono text-foreground-subtle`,children:e}),d(`h4`,{className:`text-sm font-medium uppercase tracking-wide`,children:t}),d(`span`,{className:`text-xs text-foreground-subtle`,children:n})]}),r]})}function pn(e){let t=U.safeParse(e);if(t.success)return null;let n=t.error.issues[0];return n===void 0?`this automation is not complete yet`:`${n.path.length===0?``:`${n.path.join(`.`)}: `}${n.message}`}function mn(e,t){try{return{code:Ce({name:e,recipe:t}),error:null}}catch(e){return{code:null,error:e instanceof Error?e.message:String(e)}}}function hn(e){if(!e.enabled)return{tone:`idle`,label:`Disabled`,detail:`Not started — the block is turned off.`};switch(e.status){case`running`:return{tone:`ok`,label:`Running`,detail:`One process, supervised.`};case`starting`:return{tone:`pending`,label:`Starting`,detail:e.lastError??`Waiting for the process to report ready.`};case`failed`:return{tone:`error`,label:`Failed`,detail:e.lastError??`Failed with no reason recorded — check the node logs.`};default:return{tone:`error`,label:`Not running`,detail:e.lastError??`Enabled but no process is running. The supervisor reconciles every 15s; if this persists, the node may not be running a block supervisor.`}}}function gn(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function _n(e,t){let n=e.find(e=>e.id===t.id);return n===void 0?t:n.updatedAt>=t.updatedAt?n:t}function vn(e){let t=e=>{let t=hn(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 yn(e){if(e.length===0)return`No blocks yet.`;let t=e.filter(e=>hn(e).tone===`error`).length,n=e.filter(e=>hn(e).tone===`ok`).length,r=[`${String(e.length)} block${e.length===1?``:`s`}`];return n>0&&r.push(`${String(n)} running`),t>0&&r.push(`${String(t)} NOT running`),r.join(` · `)}function bn({block:e,busy:t,confirming:n,logsOpen:r,unreadable:a,onEdit:o,onToggle:s,onToggleLogs:c,onAskDelete:l,onCancelDelete:u,onConfirmDelete:f}){let p=hn(e),m=ne(e.updatedAt);return i(`li`,{className:`flex flex-col gap-2 p-3`,children:[i(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[i(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`span`,{className:`truncate font-medium`,children:e.name}),d(L,{variant:gn(p.tone),children:p.label}),m!==null&&i(`span`,{className:`text-xs text-foreground-subtle`,children:[`edited `,m]})]}),d(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:p.detail}),a!==null&&i(`p`,{className:`mt-0.5 text-xs text-warning`,children:[`Its recipe cannot be read (`,a,`), so it cannot be opened visually. The code is intact and still running — edit it as a script.`]})]}),n?i(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-xs text-foreground-subtle`,children:`Delete this automation?`}),d(y,{variant:`danger`,onClick:f,disabled:t,children:`Delete`}),d(y,{variant:`ghost`,onClick:u,children:`Cancel`})]}):i(`div`,{className:`flex items-center gap-2`,children:[d(y,{variant:`ghost`,onClick:o,disabled:a!==null,title:a===null?`Edit`:`This block cannot be opened visually`,children:d(S,{className:`h-4 w-4`})}),i(te,{children:[d(ce,{children:d(y,{variant:`ghost`,disabled:!0,title:`Run actions`,children:d(F,{className:`h-4 w-4`})})}),d(fe,{children:`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.`})]}),d(y,{variant:`ghost`,onClick:c,title:`Logs`,children:d(ae,{className:`h-4 w-4`})}),d(y,{variant:`ghost`,onClick:()=>s(!e.enabled),disabled:t,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),d(y,{variant:`ghost`,onClick:l,title:`Delete`,children:d(g,{className:`h-4 w-4`})})]})]}),r&&i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,d(`code`,{children:W(e.id)})]}),d(M,{addonId:W(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function xn({onCreate:e}){return d(A,{children:i(`div`,{className:`space-y-2 p-4`,children:[d(`p`,{className:`text-sm text-foreground`,children:`No automations yet.`}),d(`p`,{className:`max-w-2xl text-xs text-foreground-subtle`,children:`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.`}),d(y,{onClick:e,children:`New automation`})]})})}r();var Sn=[`coreBlocks`,`list`],Cn=5e3;function wn(e){return e instanceof Error?e.message:String(e)}function Tn({onOpenScripts:e,initialBlockId:n,onBlockIdChange:r,createRequested:a=!1,onCreateConsumed:o}){let c=p(),[m,h]=l({mode:`closed`}),[g,_]=l(null),[v,y]=l(null),b=t(null);f(()=>{a&&(h({mode:`edit`,block:null}),r?.(null),o?.())},[a,o,r]);let x=s({queryKey:Sn,refetchInterval:Cn,queryFn:async()=>(await c.trpcClient.coreBlocks.list.query({})).blocks}),S=()=>{x.refetch()},C=x.data;f(()=>{if(n===void 0||b.current===n)return;let e=C?.find(e=>e.id===n&&Re(e.code));e!==void 0&&(b.current=n,h({mode:`edit`,block:e}))},[n,C]);let w=u({mutationFn:e=>c.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{h({mode:`edit`,block:e.block}),r?.(e.block.id),S()}}),T=u({mutationFn:e=>c.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{h({mode:`edit`,block:e.block}),r?.(e.block.id),S()}}),E=u({mutationFn:e=>c.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{_(null),S()}}),O=u({mutationFn:e=>c.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:S}),k=u({mutationFn:e=>c.trpcClient.coreBlocks.update.mutate({blockId:e.id,block:{name:e.name,code:Ve(e.code),enabled:e.enabled,placement:e.placement,...e.integrationId===void 0?{}:{integrationId:e.integrationId}}}),onSuccess:t=>{h({mode:`closed`}),S(),e(t.block.id)}}),j=x.data,M=vn((j??[]).filter(e=>Re(e.code))),N=j!==void 0&&M.length===0,P=m.mode===`edit`&&m.block!==null?_n(M,m.block):null,F=P===null?null:Be(P.code),I=w.error===null?T.error===null?k.error===null?null:wn(k.error):wn(T.error):wn(w.error),L=m.mode===`edit`;return i(`div`,{className:`space-y-3`,children:[!L&&d(`p`,{className:`text-xs text-foreground-subtle`,children:j===void 0?``:yn(M)}),x.error!=null&&d(D,{title:`Could not read the automations`,message:wn(x.error),onRetry:S}),L&&d(`div`,{className:`min-h-[70vh]`,"data-testid":`automation-editor-panel`,children:d(dn,{existing:P,initialRecipe:F!==null&&F.ok?F.recipe:et,saving:w.isPending||T.isPending,saveError:I,ejecting:k.isPending,onSave:e=>{P===null?w.mutate(e):T.mutate({blockId:P.id,block:e})},onEject:()=>{P!==null&&k.mutate(P)},onCancel:()=>{w.reset(),T.reset(),k.reset(),h({mode:`closed`}),r?.(null)}},P?.id??`new`)}),!L&&N&&d(xn,{onCreate:()=>{h({mode:`edit`,block:null}),r?.(null)}}),!L&&M.length>0&&d(A,{children:d(`ul`,{className:`divide-y divide-border`,children:M.map(e=>{let t=Be(e.code);return d(bn,{block:e,busy:O.isPending||E.isPending,confirming:g===e.id,logsOpen:v===e.id,unreadable:t.ok?null:t.reason,onEdit:()=>{h({mode:`edit`,block:e}),r?.(e.id)},onToggle:t=>O.mutate({blockId:e.id,enabled:t}),onToggleLogs:()=>y(v===e.id?null:e.id),onAskDelete:()=>_(e.id),onCancelDelete:()=>_(null),onConfirmDelete:()=>E.mutate(e.id)},e.id)})})}),E.error!=null&&d(D,{message:wn(E.error)}),O.error!=null&&d(D,{message:wn(O.error)})]})}function En(e){return{state:`answered`,byRef:new Map(e.map(e=>[G(e),e]))}}function Dn(e,t){if(e.state!==`unanswered`)return e.byRef.get(G(t))??null}function On(e){return e===void 0?`unknown`:e===null?`missing`:`present`}function kn(e){return we(e).map(e=>e.source)}function An(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(...kn(t));for(let t of Object.values(e.items??{}))for(let e of Object.values(t.fields))n.push(...kn(e))}let r=new Set;return n.filter(e=>{let t=G(e);return r.has(t)?!1:(r.add(t),!0)})}function jn(e,t){return`${String(e)} ${t}${e===1?``:`s`}`}function Mn(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:`Running`,reason:null};let r=[...t.length>0?[`${jn(t.length,`field`)} unavailable`]:[],...n.length>0?[`${jn(n.length,`field`)} stale`]:[]].join(`, `),i=t[0]??n[0];return{tone:`pending`,label:`Running`,reason:`${r}${i===void 0?``:` — ${i.cap}.${i.path}: ${i.reason??`no reason recorded`}`}`}}function Nn(e,t){let n=e.reason??t??null;switch(e.status){case`running`:return Mn(e);case`degraded`:return{tone:`pending`,label:`Degraded`,reason:n??`Running with a field handed back to the device; no reason recorded.`};case`starting`:return{tone:`pending`,label:`Starting`,reason:n};case`failed`:return{tone:`error`,label:`Failed`,reason:n??`Failed with no reason recorded — check the composer logs.`};default:return{tone:`error`,label:`Not running`,reason:n??`Enabled but the composer is not running it.`}}}function Pn(e){let{block:t,state:n}=e;return t.enabled?n.kind===`unreachable`?{tone:`pending`,label:`Unknown`,reason:`The composer could not be asked: ${n.error}`}:n.state===null?{tone:`pending`,label:`Not reported yet`,reason:`The composer holds no record of this block yet (stored status: ${t.lastError===void 0?t.status:`${t.status}: ${t.lastError}`}).`}:Nn(n.state,t.lastError):{tone:`idle`,label:`Off`,reason:null}}function Fn(e){return G(e)}function In(e,t){let n=Dn(t,e);return{key:G(e),label:n?n.name:Fn(e),presence:On(n),deviceId:n?n.id:null}}function Ln(e){return e.state.kind===`answered`&&e.state.state!==null?e.state.state.deviceId:null}function Rn(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:Se(e.block.id),a=G(i),o=An(e).filter(e=>G(e)!==a).map(e=>In(e,t)),s=n.features.map(e=>e.enabled===!1?`${e.cap} (off)`:e.cap),c=Dn(t,i),l=Ln(e),u=Pn(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=On(c);return{blockId:e.block.id,kind:`customization`,name:c?c.name:Fn(r.device),namePresence:d,type:c?c.type:null,features:s,state:u,sources:o,reportedDeviceId:l}}function zn(e){return e.state.tone===`error`?0:e.state.tone===`pending`?1:e.state.tone===`ok`?2:3}function Bn(e,t){return zn(e)-zn(t)||e.name.localeCompare(t.name)}function Vn(e,t){let n=e.flatMap(e=>{let n=Rn(e,t);return n===null?[]:[n]});return{composed:n.filter(e=>e.kind===`composed`).toSorted(Bn),customizations:n.filter(e=>e.kind===`customization`).toSorted(Bn)}}var Hn=1e4;function Un(e){return e instanceof Error?e.message:typeof e==`object`&&e&&`message`in e?String(e.message):String(e)}function Wn(){let e=Te();return e.data===void 0?{state:`unanswered`,reason:e.error==null?`the device list has not answered yet`:`the device list could not be read (${Un(e.error)})`}:En(e.data)}function Gn(){let e=oe({},{refetchInterval:Hn}),t=Wn(),n=e.data;if(e.error!=null&&n===void 0)return d(D,{title:`Could not read the compositions`,message:Un(e.error),onRetry:()=>void e.refetch()});if(n===void 0)return d(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:`Loading compositions…`});if(n.state===`not-loaded`)return d(A,{children:i(`div`,{className:`space-y-1 p-4`,children:[d(`p`,{className:`text-sm text-warning`,children:`The composition store has not been read yet.`}),i(`p`,{className:`text-xs text-foreground-subtle`,children:[`This is not the same as having none — the list appears once the hub has read it (`,n.reason,`).`]})]})});let r=e.error==null?null:Un(e.error);return d(Kn,{lists:Vn(n.views,t),fleet:t,refreshError:r})}function Kn({lists:e,fleet:t,refreshError:n}){return i(`div`,{className:`space-y-4`,children:[n!==null&&i(`p`,{className:`text-xs text-warning`,children:[`Showing the last answer — the latest refresh failed: `,n]}),t.state===`unanswered`&&i(`p`,{className:`text-xs text-warning`,children:[`Device names are shown as references: `,t.reason,`. No source is marked missing until it has.`]}),d(qn,{title:`Composed devices`,hint:`A new device whose state is derived from other devices.`,rows:e.composed,nameHeader:`Name`,emptyMessage:`No composed devices.`,action:d(K,{to:De,className:`text-xs text-primary hover:underline`,children:`+ New composed device`})}),d(qn,{title:`Customizations`,hint:`Fields added to or replaced on an existing device — one per device, edited from the device.`,rows:e.customizations,nameHeader:`Device`,emptyMessage:`No customizations.`})]})}function qn({title:e,hint:t,rows:n,nameHeader:r,emptyMessage:a,action:o}){return i(`section`,{className:`space-y-2`,"aria-label":e,children:[i(`div`,{className:`flex items-start justify-between gap-2`,children:[i(`div`,{children:[d(`h3`,{className:`font-medium`,children:e}),d(`p`,{className:`text-xs text-foreground-subtle`,children:t})]}),o!==void 0&&o]}),d(A,{variant:`flat`,className:`p-0`,children:d(j,{columns:Jn(r),rows:n,rowKey:e=>e.blockId,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:he,emptyMessage:a})})]})}function Jn(e){return[{key:`name`,header:e,sortValue:e=>e.name.toLowerCase(),render:e=>d(Yn,{row:e})},{key:`type`,header:`Type`,sortValue:e=>e.type,render:e=>d(`span`,{className:`text-xs text-foreground-subtle`,children:e.type??`unknown`})},{key:`state`,header:`State`,nowrap:!1,notSortableReason:`A state and its reason are read together, not ordered.`,render:e=>i(`div`,{className:`space-y-0.5`,children:[d(L,{variant:gn(e.state.tone),children:e.state.label}),e.state.reason!==null&&d(`p`,{className:`max-w-md whitespace-normal text-xs text-foreground-subtle`,children:e.state.reason})]})},{key:`sources`,header:`Sources`,nowrap:!1,notSortableReason:`A list of devices has no single order.`,render:e=>d(Zn,{sources:e.sources})}]}function Yn({row:e}){return i(`div`,{className:`space-y-0.5`,children:[d(Xn,{row:e}),e.namePresence===`missing`&&d(`span`,{className:`ml-1.5 text-[10px] text-danger`,children:`device missing`}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:e.features.join(`, `)})]})}function Xn({row:e}){return e.kind===`composed`?d(K,{to:Ae(e.blockId),className:`text-xs text-foreground hover:underline`,children:e.name}):e.reportedDeviceId===null?i(`span`,{className:`text-xs text-foreground-subtle`,children:[e.name,` — device not reported yet`]}):d(K,{to:ke(e.reportedDeviceId),className:`text-xs text-foreground hover:underline`,children:e.name})}function Zn({sources:e}){return e.length===0?d(`span`,{className:`text-xs text-foreground-subtle`,children:`—`}):d(`ul`,{className:`space-y-0.5`,children:e.map(e=>i(`li`,{className:`text-xs`,children:[e.deviceId===null?d(`span`,{className:e.presence===`missing`?`text-danger`:`text-foreground`,children:e.label}):d(K,{to:`/devices/${String(e.deviceId)}`,className:`hover:underline`,children:e.label}),e.presence===`missing`&&d(`span`,{className:`ml-1.5 text-[10px] text-danger`,children:`missing`})]},e.key))})}function Qn(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 $n(e){if(Array.isArray(e))return e}function er(e,t,n){return(t=lr(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function tr(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 nr(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
4
|
+
`};default:return{kind:`cap`,deviceId:0,cap:``,method:``}}}function rt(){return{kind:`condition`,deviceId:0,cap:``,fieldPath:``,operator:`eq`,value:``}}function it(){return{kind:`expression`,expr:``,bindings:{}}}function at(e,t,n){return e.map((e,r)=>r===t?n:e)}function ot(e,t){return e.filter((e,n)=>n!==t)}function st(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=ot(e,t);return[...a.slice(0,i),r,...a.slice(i)]}function ct(e,t){return{...e,triggers:[...t]}}function lt(e,t){return{...e,actions:[...t]}}var ut=[{value:`cap`,label:`Do something`},{value:`wait`,label:`Wait`},{value:`code`,label:`Run code`}];function dt({actions:e,devices:t,devicesState:n=`answered`,onChange:r}){return i(`div`,{className:`space-y-2`,children:[e.length===0&&d(`p`,{className:`text-xs text-warning`,children:`No actions yet. An automation that does nothing is not an automation.`}),e.map((a,o)=>i(`div`,{className:`rounded border border-border p-3 space-y-2`,children:[i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(L,{variant:`default`,children:o+1}),i(`label`,{className:`w-40`,children:[d(q,{children:`Step`}),d(V,{value:a.kind,onChange:t=>r(at(e,o,nt(ft(t.target.value)))),options:ut.map(e=>({value:e.value,label:e.label}))})]}),i(`div`,{className:`ml-auto flex items-center gap-1`,children:[d(y,{variant:`ghost`,disabled:o===0,onClick:()=>r(st(e,o,o-1)),title:`Run this step earlier`,children:d(re,{className:`h-3.5 w-3.5`})}),d(y,{variant:`ghost`,disabled:o===e.length-1,onClick:()=>r(st(e,o,o+1)),title:`Run this step later`,children:d(ue,{className:`h-3.5 w-3.5`})}),d(y,{variant:`ghost`,onClick:()=>r(ot(e,o)),title:`Remove this step`,children:d(g,{className:`h-3.5 w-3.5`})})]})]}),a.kind===`wait`&&i(`label`,{className:`block w-32`,children:[d(q,{children:`Seconds`}),d(z,{type:`number`,min:0,max:300,value:String(a.seconds),onChange:t=>r(at(e,o,{kind:`wait`,seconds:Number(t.target.value)}))})]}),a.kind===`code`&&i(`label`,{className:`block`,children:[d(q,{children:`Code`}),d(`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(at(e,o,{kind:`code`,code:t.target.value}))}),i(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:[`Compiled into this automation's own block by the same compiler as a script — not evaluated at run time. `,d(`code`,{children:`ctx`}),` and `,d(`code`,{children:`vars`}),` are in scope.`]})]}),a.kind===`cap`&&d(mt,{action:a,devices:t,devicesState:n,onChange:t=>r(at(e,o,t))})]},`${a.kind}-${String(o)}`)),i(`div`,{className:`flex items-center gap-2`,children:[i(y,{variant:`outline`,onClick:()=>r([...e,nt(`cap`)]),children:[d(P,{className:`h-4 w-4`}),` Step`]}),e.length>1&&d(`span`,{className:`text-xs text-foreground-subtle`,children:`Steps run in order and stop at the first failure.`})]})]})}function ft(e){return ut.find(t=>t.value===e)?.value??`cap`}function pt(e){return typeof e==`number`?e:typeof e==`object`&&e&&`$var`in e?{$var:e.$var}:[...e]}function mt({action:e,devices:t,devicesState:n,onChange:r}){return d(Ne,{value:e,allowTriggerDevice:!0,allowMultiSameFamily:!0,devices:t,listState:n,onChange:e=>r({kind:`cap`,deviceId:pt(e.deviceId),cap:e.cap,method:e.method,...e.args===void 0?{}:{args:{...e.args}}})})}function ht({value:e,field:t,onChange:n}){return t?.kind===`boolean`?d(V,{value:e===!0?`true`:`false`,onChange:e=>n(e.target.value===`true`),options:[{value:`true`,label:`true`},{value:`false`,label:`false`}]}):t?.kind===`enum`&&t.enumValues!==void 0&&t.enumValues.length>0?d(V,{value:String(e),onChange:e=>n(e.target.value),options:t.enumValues.map(e=>({value:e,label:e}))}):t?.kind===`number`?d(z,{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)}}):d(z,{value:String(e),placeholder:`value`,onChange:e=>n(e.target.value)})}function gt({value:e,field:t,onChange:n}){return d(z,{value:e.join(`, `),placeholder:`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 _t(e){return typeof e==`object`}function vt(e){return _t(e)?e[0]??``:e}function yt(e){return _t(e)?e:typeof e==`boolean`?[]:[e]}function bt({leaf:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Ke(r),o=Qe(a?.kind),s=e.operator===`in`,c=t=>{n({...e,deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath})},l=t=>{let r=xt(t,o);n({...e,operator:r,value:r===`in`?yt(e.value):vt(e.value)})};return i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(qe,{value:r,devices:t,onChange:c}),i(`label`,{className:`min-w-[8rem]`,children:[d(q,{children:`Comparison`}),d(V,{value:e.operator,onChange:e=>l(e.target.value),options:o.map(e=>({value:e.value,label:e.label}))})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(q,{children:`Value`}),s?d(gt,{value:yt(e.value),field:a,onChange:t=>n({...e,value:t})}):d(ht,{value:vt(e.value),field:a,onChange:t=>n({...e,value:t})})]})]})}function xt(e,t){return t.find(t=>t.value===e)?.value??`eq`}var St={kind:`global`,sourceStableId:``,cap:``,fieldPath:``};function Ct({leaf:e,devices:t,onChange:n}){let r=Object.entries(e.bindings),a=t=>{n({kind:`expression`,expr:e.expr,bindings:t})};return i(`div`,{className:`space-y-2`,children:[i(`label`,{className:`block`,children:[d(q,{children:`Expression`}),d(z,{value:e.expr,placeholder:`indoor - outdoor > 5`,onChange:t=>n({kind:`expression`,expr:t.target.value,bindings:e.bindings})}),d(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:`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.`})]}),i(`div`,{className:`space-y-1.5`,children:[r.length===0&&d(`p`,{className:`text-xs text-foreground-subtle`,children:`No names bound yet. An expression reads devices only through these.`}),r.map(([n,r])=>d(wt,{alias:n,source:r,devices:t,onRename:t=>a(At(e.bindings,n,t)),onChange:t=>a({...e.bindings,[n]:t}),onRemove:()=>a(jt(e.bindings,n))},n)),i(y,{variant:`ghost`,onClick:()=>a({...e.bindings,[kt(e.bindings)]:St}),children:[d(P,{className:`h-3.5 w-3.5`}),` Name`]})]})]})}function wt({alias:e,source:t,devices:n,onRename:r,onChange:a,onRemove:o}){let s=t.kind===`literal`,c=s?{deviceId:0,cap:``,fieldPath:``}:{deviceId:Dt(n,Et(t)),cap:t.cap,fieldPath:t.fieldPath};return i(`div`,{className:`flex flex-wrap items-end gap-2 rounded border border-border p-2`,children:[i(`label`,{className:`w-32`,children:[d(q,{children:`Name`}),d(z,{value:e,placeholder:`indoor`,onChange:e=>r(e.target.value)})]}),i(`label`,{className:`w-36`,children:[d(q,{children:`Reads`}),d(V,{value:s?`literal`:`global`,onChange:e=>a(e.target.value===`literal`?{kind:`literal`,value:``}:St),options:[{value:`global`,label:`A device field`},{value:`literal`,label:`A constant`}]})]}),s?i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(q,{children:`Constant`}),d(z,{value:t.value===null?``:String(t.value),placeholder:`5`,onChange:e=>a({kind:`literal`,value:Tt(e.target.value)})})]}):d(qe,{value:c,devices:n,onChange:e=>a({kind:`global`,sourceStableId:Ot(n,e.deviceId),cap:e.cap,fieldPath:e.fieldPath})}),d(y,{variant:`ghost`,onClick:o,title:`Remove this name`,children:d(g,{className:`h-3.5 w-3.5`})})]})}function Tt(e){let t=e.trim();return t===`true`?!0:t===`false`?!1:t!==``&&!Number.isNaN(Number(t))?Number(t):e}function Et(e){return e.kind===`global`?e.sourceStableId:``}function Dt(e,t){return e.find(e=>e.stableId===t)?.id??0}function Ot(e,t){return e.find(e=>e.id===t)?.stableId??``}function kt(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 At(e,t,n){let r={};for(let[i,a]of Object.entries(e))i===t?r[n]=a:r[i]=a;return r}function jt(e,t){let n={};for(let[r,i]of Object.entries(e))r!==t&&(n[r]=i);return n}function J(e){return e.kind===`all`||e.kind===`any`}function Y(e){let t=e.conditions;return t===void 0?{kind:`all`,children:[]}:J(t)?t:{kind:`all`,children:[t]}}function Mt(e,t){return t===null||J(t)&&t.children.length===0?{triggers:e.triggers,actions:e.actions}:{triggers:e.triggers,actions:e.actions,conditions:t}}function Nt(e){return Mt(e,Y(e))}function Pt(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?Pt(e.child,r):null;if(!J(e))return null;let i=e.children[n];return i===void 0?null:Pt(i,r)}function X(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=X(e.child,i,n);return t===null?null:{kind:`not`,child:t}}if(!J(e))return e;let a=e.children[r];if(a===void 0)return e;let o=X(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 Ft(e){return e===null?null:H({triggers:[{kind:`manual`}],actions:[{kind:`wait`,seconds:0}],conditions:e})}function It(e){let t=Y(e);return{depth:t.children.length===0?0:_e(t),leaves:t.children.length===0?0:ge(t),depthLimit:3,leafLimit:32}}function Lt(e,t){let n=Ft(t);return n===null?{ok:!0,recipe:Mt(e,t)}:{ok:!1,reason:n}}function Rt(e,t){let n=Y(e);return Lt(e,{kind:n.kind,children:[...n.children,t]})}function zt(e,t,n){return Mt(e,X(Y(e),t,()=>n))}function Bt(e,t){return Mt(e,X(Y(e),t,()=>null))}function Vt(e,t,n){return Mt(e,X(Y(e),t,e=>J(e)?{kind:n,children:e.children}:e))}function Ht(e,t){return Pt(Y(e),t)===null?{ok:!1,reason:`that row is no longer there`}:Lt(e,X(Y(e),t,e=>e.kind===`not`?e.child:{kind:`not`,child:e}))}function Ut(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 Wt(e,t,n){if(t.length<2)return{ok:!1,reason:`select at least two rows — a group of one is just the row`};if(new Set(t.map(e=>e.slice(0,-1).join(`/`))).size!==1)return{ok:!1,reason:`those rows are in different groups — a group can only be made from rows side by side`};let r=Ut(t[0]??[]);if(r===null)return{ok:!1,reason:`the root list cannot be grouped into itself`};let i=Y(e),a=Pt(i,r.path);if(a===null||!J(a))return{ok:!1,reason:`those rows are inside a NOT — remove it before grouping them`};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:`one of the selected rows is no longer there`};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 Lt(e,X(i,r.path,()=>d))}function Gt(e,t){if(t.length===0)return{ok:!1,reason:`the outer list is not a group — there is nothing to dissolve`};let n=Y(e),r=Pt(n,t);if(r===null)return{ok:!1,reason:`that group is no longer there`};if(r.kind===`not`)return Lt(e,X(n,t,()=>r.child));if(!J(r))return{ok:!1,reason:`that row is a condition, not a group`};let i=Ut(t);if(i===null)return{ok:!1,reason:`that group has no parent to dissolve into`};let a=Pt(n,i.path);if(a===null||!J(a))return{ok:!1,reason:`a group inside a NOT cannot be dissolved in place`};let o={kind:a.kind,children:[...a.children.slice(0,i.index),...r.children,...a.children.slice(i.index+1)]};return Lt(e,X(n,i.path,()=>o))}r();var Kt=[{value:`all`,label:`ALL of`},{value:`any`,label:`ANY of`}];function qt(e){return e.join(`/`)}function Jt(e){return e===``?[]:e.split(`/`).map(e=>Number(e))}function Yt({recipe:e,devices:t,onChange:n}){let[r,a]=l([]),[s,c]=l(null),u=Y(e),f=It(e),p=o(()=>r.map(Jt),[r]),m=e=>{if(!e.ok){c(e.reason);return}c(null),a([]),n(e.recipe)},h=Wt(e,p,`all`),g=Wt(e,p,`any`),_=p.length===1?Ht(e,p[0]??[]):{ok:!1,reason:`select exactly one row to negate`},v={devices:t,selected:new Set(r),onToggleSelect:e=>a(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),onUpdate:(t,r)=>n(zt(e,t,r)),onRemove:t=>{a([]),n(Bt(e,t))},onSetKind:(t,r)=>n(Vt(e,t,r)),onUngroup:t=>m(Gt(e,t))};return i(`div`,{className:`space-y-2`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(L,{variant:`default`,children:`And only if`}),d(`div`,{className:`w-32`,children:d(V,{value:u.kind,onChange:t=>n(Vt(e,[],Xt(t.target.value))),options:Kt})}),i(`span`,{className:`text-xs text-foreground-subtle`,children:[`depth `,f.depth,`/`,f.depthLimit,` · `,f.leaves,`/`,f.leafLimit,` conditions`]})]}),u.children.length===0?d(`p`,{className:`text-xs text-foreground-subtle`,children:`No conditions. The actions run every time a trigger fires.`}):d(Zt,{container:u,path:[],handlers:v}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(y,{variant:`outline`,onClick:()=>m(Rt(e,rt())),title:`Compare one device field to a value`,children:[d(P,{className:`h-4 w-4`}),` Condition`]}),i(y,{variant:`outline`,onClick:()=>m(Rt(e,it())),title:`Arithmetic across device fields — the bounded expression engine`,children:[d(Pe,{className:`h-4 w-4`}),` Expression`]}),d(`span`,{className:`mx-1 h-5 w-px bg-border`}),d(y,{variant:`ghost`,disabled:!h.ok,onClick:()=>m(h),title:h.ok?`All selected rows must be true`:h.reason,children:`Group as ALL`}),d(y,{variant:`ghost`,disabled:!g.ok,onClick:()=>m(g),title:g.ok?`Any one of the selected rows is enough`:g.reason,children:`Group as ANY`}),d(y,{variant:`ghost`,disabled:!_.ok,onClick:()=>m(_),title:_.ok?`Invert the selected row`:_.reason,children:`NOT`}),r.length>0&&i(`span`,{className:`text-xs text-foreground-subtle`,children:[r.length,` selected`]})]}),s!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-2 text-xs text-warning`,children:s})]})}function Xt(e){return e===`any`?`any`:`all`}function Zt({container:e,path:t,handlers:n}){return d(`div`,{className:`space-y-1.5`,children:e.children.map((e,r)=>d(Qt,{node:e,path:[...t,r],handlers:n},qt([...t,r])))})}function Qt({node:e,path:t,handlers:n}){let r=qt(t),a=d(R,{checked:n.selected.has(r),onChange:()=>n.onToggleSelect(r),"aria-label":`Select this row for grouping`});return J(e)?i(`div`,{className:`rounded border border-border bg-surface-subtle/40 p-2`,children:[i(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[a,d(`div`,{className:`w-32`,children:d(V,{value:e.kind,onChange:e=>n.onSetKind(t,Xt(e.target.value)),options:Kt})}),i(y,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Dissolve this group, keeping its rows`,children:[d(Fe,{className:`h-3.5 w-3.5`}),` Ungroup`]}),d(y,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Delete this group and everything in it`,children:d(g,{className:`h-3.5 w-3.5`})})]}),d(`div`,{className:`pl-4`,children:d(Zt,{container:e,path:t,handlers:n})})]}):e.kind===`not`?i(`div`,{className:`rounded border border-border p-2`,children:[i(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[a,d(L,{variant:`warning`,children:`NOT`}),i(y,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Remove the NOT, keeping the row`,children:[d(Fe,{className:`h-3.5 w-3.5`}),` Remove NOT`]})]}),d(`div`,{className:`pl-4`,children:d(Qt,{node:e.child,path:[...t,0],handlers:n})})]}):i(`div`,{className:`flex items-start gap-2 rounded border border-border p-2`,children:[d(`div`,{className:`pt-6`,children:a}),d(`div`,{className:`min-w-0 flex-1`,children:e.kind===`condition`?d(bt,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)}):d(Ct,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)})}),d(y,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Remove this condition`,children:d(g,{className:`h-3.5 w-3.5`})})]})}r();function $t({code:e,error:t,canEject:n,ejecting:r,onEject:a}){let[o,s]=l(!1),c=I(),u=async()=>{await c({title:`Eject to code — this cannot be undone`,message:`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:`Eject to code`,cancelLabel:`Keep it visual`,variant:`warning`})&&a()};return i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2 px-3 py-2`,children:[i(y,{variant:`ghost`,onClick:()=>s(!o),children:[d(o?m:h,{className:`h-4 w-4`}),`Generated code`]}),d(`span`,{className:`text-xs text-foreground-subtle`,children:`Derived from the recipe above — regenerated on every save, never edited here.`}),i(y,{className:`ml-auto`,variant:`ghost`,disabled:!n||e===null||r,onClick:()=>void u(),title:n?`Take permanent ownership of this code as a script`:`Save the automation first — there is no stored block to eject yet`,children:[d(Ee,{className:`h-4 w-4`}),` Eject to code`]})]}),o&&d(`div`,{className:`border-t border-border p-3`,children:e===null?d(`p`,{className:`text-xs text-warning`,children:t??`The recipe is not complete enough to generate a block yet.`}):d(k,{maxHeight:420,children:e})})]})}var en=[`device-state`,`device-event`,`schedule`,`manual`],tn=Object.values(be).sort((e,t)=>e.localeCompare(t));function nn({triggers:e,devices:t,onChange:n}){return i(`div`,{className:`space-y-2`,children:[e.length===0&&d(`p`,{className:`text-xs text-warning`,children:`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)=>d(rn,{trigger:r,devices:t,position:i,onChange:t=>n(at(e,i,t)),onRemove:()=>n(ot(e,i))},`${r.kind}-${String(i)}`)),i(y,{variant:`outline`,onClick:()=>n([...e,tt(`device-state`)]),title:`Add another way this automation can start`,children:[d(P,{className:`h-4 w-4`}),` Trigger`]})]})}function rn({trigger:e,devices:t,position:n,onChange:r,onRemove:a}){return i(`div`,{className:`rounded border border-border p-3`,children:[i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(L,{variant:`default`,children:n===0?`When`:`or when`}),i(`label`,{className:`min-w-[13rem] flex-1`,children:[d(q,{children:`Trigger`}),d(V,{value:e.kind,onChange:e=>r(tt(an(e.target.value))),options:en.map(e=>({value:e,label:$e(e)}))})]}),d(y,{variant:`ghost`,onClick:a,title:`Remove this trigger`,children:d(g,{className:`h-4 w-4`})})]}),i(`div`,{className:`mt-2 flex flex-wrap items-end gap-2`,children:[e.kind===`device-state`&&d(sn,{trigger:e,devices:t,onChange:r}),e.kind===`device-event`&&d(ln,{trigger:e,devices:t,onChange:r}),e.kind===`schedule`&&i(`label`,{className:`min-w-[14rem] flex-1`,children:[d(q,{children:`Cron expression`}),d(z,{value:e.cron,placeholder:`0 30 23 * * *`,onChange:e=>r({kind:`schedule`,cron:e.target.value})}),i(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:[`Six fields, seconds first. `,d(`code`,{children:`0 30 23 * * *`}),` is every night at 23:30.`]})]}),e.kind===`manual`&&i(`p`,{className:`text-xs text-foreground-subtle`,children:[`Runs only when someone presses `,d(`strong`,{children:`Run actions`}),`. The conditions are still evaluated — a manual run is a run, not an override.`]})]})]})}function an(e){return en.find(t=>t===e)??`manual`}function on(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 sn({trigger:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Ke(r),o={...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 i(c,{children:[d(qe,{value:r,devices:t,onChange:e=>n(on(e,o))}),i(`div`,{className:`min-w-[11rem] flex-1`,children:[d(q,{children:`Becomes`}),i(`div`,{className:`flex items-center gap-2`,children:[i(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[d(R,{checked:e.becomes===void 0,onChange:e=>n(on(r,{...o,...e.target.checked?{becomes:void 0}:{becomes:``}}))}),`any change`]}),e.becomes!==void 0&&d(ht,{value:e.becomes,field:a,onChange:e=>n(on(r,{...o,becomes:e}))})]})]}),i(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[d(R,{checked:e.edge===!0,onChange:e=>n(on(r,{...o,...e.target.checked?{edge:!0}:{edge:void 0}}))}),`only on a change`]}),i(`label`,{className:`w-28`,children:[d(q,{children:`Held for (s)`}),d(z,{type:`number`,min:0,value:e.forMs===void 0?``:String(e.forMs/1e3),placeholder:`0`,onChange:e=>n(on(r,{...o,forMs:cn(e.target.value)}))})]}),i(`label`,{className:`w-28`,children:[d(q,{children:`Debounce (s)`}),d(z,{type:`number`,min:0,value:e.debounceMs===void 0?``:String(e.debounceMs/1e3),placeholder:`0`,onChange:e=>n(on(r,{...o,debounceMs:cn(e.target.value)}))})]})]})}function cn(e){if(e.trim()===``)return;let t=Number(e);if(!(Number.isNaN(t)||t<0))return Math.round(t*1e3)}function ln({trigger:e,devices:t,onChange:n}){return i(c,{children:[i(`label`,{className:`min-w-[15rem] flex-1`,children:[d(q,{children:`Event category`}),d(V,{value:e.category,onChange:t=>n({kind:`device-event`,category:t.target.value,...e.deviceId===void 0?{}:{deviceId:e.deviceId}}),options:[{value:``,label:`Select an event…`},...tn.map(e=>({value:e,label:e}))]})]}),i(`label`,{className:`min-w-[11rem] flex-1`,children:[d(q,{children:`From device`}),d(V,{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:`Any device`},...t.map(e=>({value:String(e.id),label:e.name}))]})]})]})}r();var un=`hub`;function dn({existing:e,initialRecipe:t,saving:n,saveError:r,ejecting:a,onSave:s,onEject:c,onCancel:u}){let[f,p]=l(e?.name??``),[m,h]=l(()=>Nt(t)),[g,_]=l(!1),v=Ue(),b=H(m),x=o(()=>pn(m),[m]),S=o(()=>mn(f.trim()===``?`Untitled automation`:f.trim(),m),[f,m]),C=f.trim()===``,w=C||b!==null||x!==null||S.code===null;return d(A,{children:i(`div`,{className:`space-y-4 p-4`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`h3`,{className:`font-medium`,children:e===null?`New automation`:`Edit ${e.name}`}),d(L,{variant:`info`,children:`runs on the hub`})]}),i(`label`,{className:`block max-w-md text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Name`}),d(z,{className:`mt-1`,value:f,onChange:e=>p(e.target.value),placeholder:`What this automation does`})]}),d(fn,{step:`1`,title:`When`,subtitle:`Any one of these starts a run.`,children:d(nn,{triggers:m.triggers,devices:v,onChange:e=>h(ct(m,e))})}),d(fn,{step:`2`,title:`And only if`,subtitle:`Checked after a trigger fires. Nothing runs unless this is true.`,children:d(Yt,{recipe:m,devices:v,onChange:h})}),d(fn,{step:`3`,title:`Then`,subtitle:`In this order, stopping at the first failure.`,children:d(dt,{actions:m.actions,devices:v,onChange:e=>h(lt(m,e))})}),d($t,{code:S.code,error:S.error,canEject:e!==null,ejecting:a,onEject:c}),b!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:b}),b===null&&x!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:x}),r!==null&&d(`p`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:r}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(y,{onClick:()=>{S.code!==null&&s({name:f.trim(),code:S.code,enabled:e?.enabled??!0,placement:un})},disabled:n||w,children:[n&&d(B,{className:`h-4 w-4 animate-spin`}),` Save`]}),i(y,{variant:`ghost`,onClick:()=>_(!g),disabled:e===null,title:e===null?`Logs appear once the automation has been saved and started`:`Show this automation's process logs`,"data-testid":`automation-logs-toggle`,children:[d(ae,{className:`h-4 w-4`}),` Logs `,g?`▾`:`▸`]}),d(y,{variant:`ghost`,onClick:u,disabled:n,children:`Close`}),C&&d(L,{variant:`warning`,children:`Name required`})]}),g&&e!==null&&i(`div`,{className:`rounded border border-border`,"data-testid":`automation-logs-panel`,children:[i(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,d(`code`,{children:W(e.id)})]}),d(M,{addonId:W(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})})}function fn({step:e,title:t,subtitle:n,children:r}){return i(`section`,{className:`border-l-2 border-border pl-4`,children:[i(`div`,{className:`mb-2 flex flex-wrap items-baseline gap-2`,children:[d(`span`,{className:`text-xs font-mono text-foreground-subtle`,children:e}),d(`h4`,{className:`text-sm font-medium uppercase tracking-wide`,children:t}),d(`span`,{className:`text-xs text-foreground-subtle`,children:n})]}),r]})}function pn(e){let t=U.safeParse(e);if(t.success)return null;let n=t.error.issues[0];return n===void 0?`this automation is not complete yet`:`${n.path.length===0?``:`${n.path.join(`.`)}: `}${n.message}`}function mn(e,t){try{return{code:Ce({name:e,recipe:t}),error:null}}catch(e){return{code:null,error:e instanceof Error?e.message:String(e)}}}function hn(e){if(!e.enabled)return{tone:`idle`,label:`Disabled`,detail:`Not started — the block is turned off.`};switch(e.status){case`running`:return{tone:`ok`,label:`Running`,detail:`One process, supervised.`};case`starting`:return{tone:`pending`,label:`Starting`,detail:e.lastError??`Waiting for the process to report ready.`};case`failed`:return{tone:`error`,label:`Failed`,detail:e.lastError??`Failed with no reason recorded — check the node logs.`};default:return{tone:`error`,label:`Not running`,detail:e.lastError??`Enabled but no process is running. The supervisor reconciles every 15s; if this persists, the node may not be running a block supervisor.`}}}function gn(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function _n(e,t){let n=e.find(e=>e.id===t.id);return n===void 0?t:n.updatedAt>=t.updatedAt?n:t}function vn(e){let t=e=>{let t=hn(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 yn(e){if(e.length===0)return`No blocks yet.`;let t=e.filter(e=>hn(e).tone===`error`).length,n=e.filter(e=>hn(e).tone===`ok`).length,r=[`${String(e.length)} block${e.length===1?``:`s`}`];return n>0&&r.push(`${String(n)} running`),t>0&&r.push(`${String(t)} NOT running`),r.join(` · `)}function bn({block:e,busy:t,confirming:n,logsOpen:r,unreadable:a,onEdit:o,onToggle:s,onToggleLogs:c,onAskDelete:l,onCancelDelete:u,onConfirmDelete:f}){let p=hn(e),m=ne(e.updatedAt);return i(`li`,{className:`flex flex-col gap-2 p-3`,children:[i(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[i(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`span`,{className:`truncate font-medium`,children:e.name}),d(L,{variant:gn(p.tone),children:p.label}),m!==null&&i(`span`,{className:`text-xs text-foreground-subtle`,children:[`edited `,m]})]}),d(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:p.detail}),a!==null&&i(`p`,{className:`mt-0.5 text-xs text-warning`,children:[`Its recipe cannot be read (`,a,`), so it cannot be opened visually. The code is intact and still running — edit it as a script.`]})]}),n?i(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-xs text-foreground-subtle`,children:`Delete this automation?`}),d(y,{variant:`danger`,onClick:f,disabled:t,children:`Delete`}),d(y,{variant:`ghost`,onClick:u,children:`Cancel`})]}):i(`div`,{className:`flex items-center gap-2`,children:[d(y,{variant:`ghost`,onClick:o,disabled:a!==null,title:a===null?`Edit`:`This block cannot be opened visually`,children:d(S,{className:`h-4 w-4`})}),i(te,{children:[d(ce,{children:d(y,{variant:`ghost`,disabled:!0,title:`Run actions`,children:d(F,{className:`h-4 w-4`})})}),d(fe,{children:`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.`})]}),d(y,{variant:`ghost`,onClick:c,title:`Logs`,children:d(ae,{className:`h-4 w-4`})}),d(y,{variant:`ghost`,onClick:()=>s(!e.enabled),disabled:t,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),d(y,{variant:`ghost`,onClick:l,title:`Delete`,children:d(g,{className:`h-4 w-4`})})]})]}),r&&i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,d(`code`,{children:W(e.id)})]}),d(M,{addonId:W(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function xn({onCreate:e}){return d(A,{children:i(`div`,{className:`space-y-2 p-4`,children:[d(`p`,{className:`text-sm text-foreground`,children:`No automations yet.`}),d(`p`,{className:`max-w-2xl text-xs text-foreground-subtle`,children:`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.`}),d(y,{onClick:e,children:`New automation`})]})})}r();var Sn=[`coreBlocks`,`list`],Cn=5e3;function wn(e){return e instanceof Error?e.message:String(e)}function Tn({onOpenScripts:e,initialBlockId:n,onBlockIdChange:r,createRequested:a=!1,onCreateConsumed:o}){let c=p(),[m,h]=l({mode:`closed`}),[g,_]=l(null),[v,y]=l(null),b=t(null);f(()=>{a&&(h({mode:`edit`,block:null}),r?.(null),o?.())},[a,o,r]);let x=s({queryKey:Sn,refetchInterval:Cn,queryFn:async()=>(await c.trpcClient.coreBlocks.list.query({})).blocks}),S=()=>{x.refetch()},C=x.data;f(()=>{if(n===void 0||b.current===n)return;let e=C?.find(e=>e.id===n&&Re(e.code));e!==void 0&&(b.current=n,h({mode:`edit`,block:e}))},[n,C]);let w=u({mutationFn:e=>c.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{h({mode:`edit`,block:e.block}),r?.(e.block.id),S()}}),T=u({mutationFn:e=>c.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{h({mode:`edit`,block:e.block}),r?.(e.block.id),S()}}),E=u({mutationFn:e=>c.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{_(null),S()}}),O=u({mutationFn:e=>c.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:S}),k=u({mutationFn:e=>c.trpcClient.coreBlocks.update.mutate({blockId:e.id,block:{name:e.name,code:Ve(e.code),enabled:e.enabled,placement:e.placement,...e.integrationId===void 0?{}:{integrationId:e.integrationId}}}),onSuccess:t=>{h({mode:`closed`}),S(),e(t.block.id)}}),j=x.data,M=vn((j??[]).filter(e=>Re(e.code))),N=j!==void 0&&M.length===0,P=m.mode===`edit`&&m.block!==null?_n(M,m.block):null,F=P===null?null:Be(P.code),I=w.error===null?T.error===null?k.error===null?null:wn(k.error):wn(T.error):wn(w.error),L=m.mode===`edit`;return i(`div`,{className:`space-y-3`,children:[!L&&d(`p`,{className:`text-xs text-foreground-subtle`,children:j===void 0?``:yn(M)}),x.error!=null&&d(D,{title:`Could not read the automations`,message:wn(x.error),onRetry:S}),L&&d(`div`,{className:`min-h-[70vh]`,"data-testid":`automation-editor-panel`,children:d(dn,{existing:P,initialRecipe:F!==null&&F.ok?F.recipe:et,saving:w.isPending||T.isPending,saveError:I,ejecting:k.isPending,onSave:e=>{P===null?w.mutate(e):T.mutate({blockId:P.id,block:e})},onEject:()=>{P!==null&&k.mutate(P)},onCancel:()=>{w.reset(),T.reset(),k.reset(),h({mode:`closed`}),r?.(null)}},P?.id??`new`)}),!L&&N&&d(xn,{onCreate:()=>{h({mode:`edit`,block:null}),r?.(null)}}),!L&&M.length>0&&d(A,{children:d(`ul`,{className:`divide-y divide-border`,children:M.map(e=>{let t=Be(e.code);return d(bn,{block:e,busy:O.isPending||E.isPending,confirming:g===e.id,logsOpen:v===e.id,unreadable:t.ok?null:t.reason,onEdit:()=>{h({mode:`edit`,block:e}),r?.(e.id)},onToggle:t=>O.mutate({blockId:e.id,enabled:t}),onToggleLogs:()=>y(v===e.id?null:e.id),onAskDelete:()=>_(e.id),onCancelDelete:()=>_(null),onConfirmDelete:()=>E.mutate(e.id)},e.id)})})}),E.error!=null&&d(D,{message:wn(E.error)}),O.error!=null&&d(D,{message:wn(O.error)})]})}function En(e){return{state:`answered`,byRef:new Map(e.map(e=>[G(e),e]))}}function Dn(e,t){if(e.state!==`unanswered`)return e.byRef.get(G(t))??null}function On(e){return e===void 0?`unknown`:e===null?`missing`:`present`}function kn(e){return we(e).map(e=>e.source)}function An(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(...kn(t));for(let t of Object.values(e.items??{}))for(let e of Object.values(t.fields))n.push(...kn(e))}let r=new Set;return n.filter(e=>{let t=G(e);return r.has(t)?!1:(r.add(t),!0)})}function jn(e,t){return`${String(e)} ${t}${e===1?``:`s`}`}function Mn(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:`Running`,reason:null};let r=[...t.length>0?[`${jn(t.length,`field`)} unavailable`]:[],...n.length>0?[`${jn(n.length,`field`)} stale`]:[]].join(`, `),i=t[0]??n[0];return{tone:`pending`,label:`Running`,reason:`${r}${i===void 0?``:` — ${i.cap}.${i.path}: ${i.reason??`no reason recorded`}`}`}}function Nn(e,t){let n=e.reason??t??null;switch(e.status){case`running`:return Mn(e);case`degraded`:return{tone:`pending`,label:`Degraded`,reason:n??`Running with a field handed back to the device; no reason recorded.`};case`starting`:return{tone:`pending`,label:`Starting`,reason:n};case`failed`:return{tone:`error`,label:`Failed`,reason:n??`Failed with no reason recorded — check the composer logs.`};default:return{tone:`error`,label:`Not running`,reason:n??`Enabled but the composer is not running it.`}}}function Pn(e){let{block:t,state:n}=e;return t.enabled?n.kind===`unreachable`?{tone:`pending`,label:`Unknown`,reason:`The composer could not be asked: ${n.error}`}:n.state===null?{tone:`pending`,label:`Not reported yet`,reason:`The composer holds no record of this block yet (stored status: ${t.lastError===void 0?t.status:`${t.status}: ${t.lastError}`}).`}:Nn(n.state,t.lastError):{tone:`idle`,label:`Off`,reason:null}}function Fn(e){return G(e)}function In(e,t){let n=Dn(t,e);return{key:G(e),label:n?n.name:Fn(e),presence:On(n),deviceId:n?n.id:null}}function Ln(e){return e.state.kind===`answered`&&e.state.state!==null?e.state.state.deviceId:null}function Rn(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:Se(e.block.id),a=G(i),o=An(e).filter(e=>G(e)!==a).map(e=>In(e,t)),s=n.features.map(e=>e.enabled===!1?`${e.cap} (off)`:e.cap),c=Dn(t,i),l=Ln(e),u=Pn(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=On(c);return{blockId:e.block.id,kind:`customization`,name:c?c.name:Fn(r.device),namePresence:d,type:c?c.type:null,features:s,state:u,sources:o,reportedDeviceId:l}}function zn(e){return e.state.tone===`error`?0:e.state.tone===`pending`?1:e.state.tone===`ok`?2:3}function Bn(e,t){return zn(e)-zn(t)||e.name.localeCompare(t.name)}function Vn(e,t){let n=e.flatMap(e=>{let n=Rn(e,t);return n===null?[]:[n]});return{composed:n.filter(e=>e.kind===`composed`).toSorted(Bn),customizations:n.filter(e=>e.kind===`customization`).toSorted(Bn)}}var Hn=1e4;function Un(e){return e instanceof Error?e.message:typeof e==`object`&&e&&`message`in e?String(e.message):String(e)}function Wn(){let e=Te();return e.data===void 0?{state:`unanswered`,reason:e.error==null?`the device list has not answered yet`:`the device list could not be read (${Un(e.error)})`}:En(e.data)}function Gn(){let e=oe({},{refetchInterval:Hn}),t=Wn(),n=e.data;if(e.error!=null&&n===void 0)return d(D,{title:`Could not read the compositions`,message:Un(e.error),onRetry:()=>void e.refetch()});if(n===void 0)return d(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:`Loading compositions…`});if(n.state===`not-loaded`)return d(A,{children:i(`div`,{className:`space-y-1 p-4`,children:[d(`p`,{className:`text-sm text-warning`,children:`The composition store has not been read yet.`}),i(`p`,{className:`text-xs text-foreground-subtle`,children:[`This is not the same as having none — the list appears once the hub has read it (`,n.reason,`).`]})]})});let r=e.error==null?null:Un(e.error);return d(Kn,{lists:Vn(n.views,t),fleet:t,refreshError:r})}function Kn({lists:e,fleet:t,refreshError:n}){return i(`div`,{className:`space-y-4`,children:[n!==null&&i(`p`,{className:`text-xs text-warning`,children:[`Showing the last answer — the latest refresh failed: `,n]}),t.state===`unanswered`&&i(`p`,{className:`text-xs text-warning`,children:[`Device names are shown as references: `,t.reason,`. No source is marked missing until it has.`]}),d(qn,{title:`Composed devices`,hint:`A new device whose state is derived from other devices.`,rows:e.composed,nameHeader:`Name`,emptyMessage:`No composed devices.`,action:d(K,{to:je,className:`text-xs text-primary hover:underline`,children:`+ New composed device`})}),d(qn,{title:`Customizations`,hint:`Fields added to or replaced on an existing device — one per device, edited from the device.`,rows:e.customizations,nameHeader:`Device`,emptyMessage:`No customizations.`})]})}function qn({title:e,hint:t,rows:n,nameHeader:r,emptyMessage:a,action:o}){return i(`section`,{className:`space-y-2`,"aria-label":e,children:[i(`div`,{className:`flex items-start justify-between gap-2`,children:[i(`div`,{children:[d(`h3`,{className:`font-medium`,children:e}),d(`p`,{className:`text-xs text-foreground-subtle`,children:t})]}),o!==void 0&&o]}),d(A,{variant:`flat`,className:`p-0`,children:d(j,{columns:Jn(r),rows:n,rowKey:e=>e.blockId,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:he,emptyMessage:a})})]})}function Jn(e){return[{key:`name`,header:e,sortValue:e=>e.name.toLowerCase(),render:e=>d(Yn,{row:e})},{key:`type`,header:`Type`,sortValue:e=>e.type,render:e=>d(`span`,{className:`text-xs text-foreground-subtle`,children:e.type??`unknown`})},{key:`state`,header:`State`,nowrap:!1,notSortableReason:`A state and its reason are read together, not ordered.`,render:e=>i(`div`,{className:`space-y-0.5`,children:[d(L,{variant:gn(e.state.tone),children:e.state.label}),e.state.reason!==null&&d(`p`,{className:`max-w-md whitespace-normal text-xs text-foreground-subtle`,children:e.state.reason})]})},{key:`sources`,header:`Sources`,nowrap:!1,notSortableReason:`A list of devices has no single order.`,render:e=>d(Zn,{sources:e.sources})}]}function Yn({row:e}){return i(`div`,{className:`space-y-0.5`,children:[d(Xn,{row:e}),e.namePresence===`missing`&&d(`span`,{className:`ml-1.5 text-[10px] text-danger`,children:`device missing`}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:e.features.join(`, `)})]})}function Xn({row:e}){return e.kind===`composed`?d(K,{to:ke(e.blockId),className:`text-xs text-foreground hover:underline`,children:e.name}):e.reportedDeviceId===null?i(`span`,{className:`text-xs text-foreground-subtle`,children:[e.name,` — device not reported yet`]}):d(K,{to:Oe(e.reportedDeviceId),className:`text-xs text-foreground hover:underline`,children:e.name})}function Zn({sources:e}){return e.length===0?d(`span`,{className:`text-xs text-foreground-subtle`,children:`—`}):d(`ul`,{className:`space-y-0.5`,children:e.map(e=>i(`li`,{className:`text-xs`,children:[e.deviceId===null?d(`span`,{className:e.presence===`missing`?`text-danger`:`text-foreground`,children:e.label}):d(K,{to:`/devices/${String(e.deviceId)}`,className:`hover:underline`,children:e.label}),e.presence===`missing`&&d(`span`,{className:`ml-1.5 text-[10px] text-danger`,children:`missing`})]},e.key))})}function Qn(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 $n(e){if(Array.isArray(e))return e}function er(e,t,n){return(t=lr(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function tr(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 nr(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
5
5
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function rr(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 ir(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?rr(Object(n),!0).forEach(function(t){er(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):rr(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function ar(e,t){if(e==null)return{};var n,r,i=or(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 or(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 sr(e,t){return $n(e)||tr(e,t)||ur(e,t)||nr()}function cr(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 lr(e){var t=cr(e,`string`);return typeof t==`symbol`?t:t+``}function ur(e,t){if(e){if(typeof e==`string`)return Qn(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)?Qn(e,t):void 0}}function dr(e,t,n){return 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=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 pr(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?fr(Object(n),!0).forEach(function(t){dr(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):fr(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function mr(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}}function hr(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 _r(e){return!Object.keys(e).length}function vr(e){return typeof e==`function`}function yr(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function br(e,t){return gr(t)||Z(`changeType`),Object.keys(t).some(function(t){return!yr(e,t)})&&Z(`changeField`),t}function xr(e){vr(e)||Z(`selectorType`)}function Sr(e){vr(e)||gr(e)||Z(`handlerType`),gr(e)&&Object.values(e).some(function(e){return!vr(e)})&&Z(`handlersType`)}function Cr(e){e||Z(`initialIsRequired`),gr(e)||Z(`initialType`),_r(e)&&Z(`initialContent`)}function wr(e,t){throw Error(e[t]||e.default)}var Z=hr(wr)({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"}),Tr={changes:br,selector:xr,handler:Sr,initial:Cr};function Er(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};Tr.initial(e),Tr.handler(t);var n={current:e},r=hr(kr)(n,t),i=hr(Or)(n),a=hr(Tr.changes)(e),o=hr(Dr)(n);function s(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(e){return e};return Tr.selector(e),e(n.current)}function c(e){mr(r,i,a,o)(e)}return[s,c]}function Dr(e,t){return vr(t)?t(e.current):t}function Or(e,t){return e.current=pr(pr({},e.current),t),t}function kr(e,t,n){return vr(t)?t(e.current):Object.keys(n).forEach(function(n){return t[n]?.call(t,e.current[n])}),n}var Ar={create:Er},jr={paths:{vs:`https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs`}};function Mr(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 Nr(e){return{}.toString.call(e).includes(`Object`)}function Pr(e){return e||Rr(`configIsRequired`),Nr(e)||Rr(`configType`),e.urls?(Fr(),{paths:{vs:e.urls.monacoBase}}):e}function Fr(){console.warn(Lr.deprecation)}function Ir(e,t){throw Error(e[t]||e.default)}var Lr={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
6
|
You are using deprecated way of configuration.
|
|
7
7
|
|
|
@@ -37,4 +37,4 @@ export default function block(ctx: AddonContext) {
|
|
|
37
37
|
ctx.logger.info('hello from a core block')
|
|
38
38
|
return () => undefined
|
|
39
39
|
}
|
|
40
|
-
`;function Mi({existing:e,dirty:t,saving:n,restarting:r}){return e===null?`Save the script first — there is no process to restart yet.`:n?`Saving…`:r?`Restarting…`:t?`Save first — a restart now would run the last SAVED code, not what is on screen.`:e.enabled?null:`This script is disabled. Enable it instead of restarting it.`}r();var Ni=5e3;function Pi(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 Fi({blockId:e}){let t=W(e),n=ee({addonId:t,projection:`slim`},{refetchInterval:Ni}),r=o(()=>Pi(n.data),[n.data]);return n.isLoading?i(`p`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(B,{className:`h-3.5 w-3.5 animate-spin`}),` Loading devices owned by this script…`]}):n.isError?i(`p`,{className:`text-xs text-danger`,children:[`Could not list devices:`,` `,n.error instanceof Error?n.error.message:String(n.error)]}):i(`section`,{className:`space-y-3 rounded border border-border p-3`,"data-testid":`script-devices-panel`,children:[i(`div`,{className:`flex items-center justify-between gap-2`,children:[i(`div`,{children:[d(`h4`,{className:`text-sm font-medium`,children:`Devices`}),i(`p`,{className:`text-xs text-foreground-subtle`,children:[`Declared by this script under the shared Blocks integration (`,d(`code`,{className:`text-[11px]`,children:t}),`). Open a device for its export section.`]})]}),d(L,{variant:`default`,children:r.length})]}),r.length===0?i(`p`,{className:`text-xs text-foreground-subtle`,children:[`No devices yet. Call `,d(`code`,{children:`reconcileBlockDevices(ctx, …)`}),` from the script (and Restart) to declare them.`]}):d(`ul`,{className:`space-y-3`,children:r.map(e=>d(`li`,{className:`rounded border border-border/80 px-3 py-2`,"data-testid":`script-device-${e.id}`,children:i(`div`,{className:`flex flex-wrap items-baseline gap-2`,children:[d(K,{to:`/devices/${String(e.id)}`,className:`text-sm font-medium hover:underline`,title:`Open device detail`,children:e.name}),d(L,{variant:`info`,style:`outline`,children:e.type}),e.stableId!==void 0&&i(`span`,{className:`text-[11px] text-foreground-subtle`,children:[`stableId `,d(`code`,{children:e.stableId})]}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:[`#`,e.id]})]})},e.id))})]})}r();function Ii(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 Li(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 Ri(e){switch(e){case`refresh-channel-catalog`:return`Script enabled so the channel catalog can scrape.`;case`send-tv-schedule-now`:return`Script enabled so the TV schedule can send.`;case`refresh-nordvpn-catalog`:return`Script enabled so the NordVPN catalog can refresh.`;case`probe-nordvpn-italy`:return`Script enabled so Italy stations can be probed.`;case`test-nordvpn-endpoint`:return`Script enabled so the VPN endpoint can be tested.`;case`refresh-unifi-catalog`:return`Script enabled so UniFi IDs can be fetched.`}}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 Bi(e){if(!(typeof e!=`object`||!e||!(`value`in e)))return Reflect.get(e,`value`)}function Vi(e){let t={};for(let n of e.sections)for(let e of n.fields){let n=zi(e);n!==null&&(t[n]=Bi(e))}return t}function Hi(e){return typeof e!=`object`||!e?!1:Array.isArray(Reflect.get(e,`sections`))}function Ui({blockId:t}){let n=p(),r=pe({blockId:t},{retry:!1}),a=N({blockId:t},{refetchInterval:1e4,retry:!1}),s=O({onSuccess:()=>{a.refetch()}}),c=v(),u=ie(),[f,m]=l(null),[h,g]=l(null),[_,b]=l(null),[x,S]=l(!1),C=Hi(a.data)?a.data:null,w=o(()=>C===null?{}:Vi(C),[C]),T=f??w,E=e(e=>{m(e)},[]),D=f!==null,k=e(()=>{f!==null&&(g(null),s.mutate({blockId:t,patch:f},{onSuccess:()=>m(null),onError:e=>g(e instanceof Error?e.message:String(e))}))},[t,f,s]),A=e(async(e,i)=>{if(Ii(e)){S(!0),g(null),b(null);try{f!==null&&(await n.trpcClient.coreBlocks.updateBlockSettings.mutate({blockId:t,patch:f}),m(null)),await n.trpcClient.coreBlocks.updateBlockSettings.mutate({blockId:t,patch:Li(e)}),r.data?.block?.enabled!==!0&&(await u.mutateAsync({blockId:t,enabled:!0}),b(Ri(e))),await c.mutateAsync({blockId:t}),await a.refetch(),e===`send-tv-schedule-now`?b(`Sending tonight’s schedule now…`):e===`probe-nordvpn-italy`?b(`Probing NordVPN Italy stations (no UniFi change)…`):e===`test-nordvpn-endpoint`?b(`Testing VPN endpoint on UniFi…`):e===`refresh-nordvpn-catalog`?b(`Refreshing NordVPN Italy catalog…`):e===`refresh-unifi-catalog`&&b(`Refreshing UniFi ID catalogs…`)}catch(e){g(e instanceof Error?e.message:String(e))}finally{S(!1)}}},[t,r.data?.block?.enabled,f,c,u,a,n.trpcClient.coreBlocks]);return a.isLoading?i(`p`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(B,{className:`h-3.5 w-3.5 animate-spin`}),` Loading script settings…`]}):a.isError?i(`p`,{className:`text-xs text-danger`,"data-testid":`script-settings-error`,children:[`Could not load settings:`,` `,a.error instanceof Error?a.error.message:String(a.error)]}):C===null?null:i(`section`,{className:`space-y-3 rounded border border-border p-3`,"data-testid":`script-settings-panel`,children:[i(`div`,{className:`flex items-center justify-between gap-2`,children:[i(`div`,{children:[d(`h4`,{className:`text-sm font-medium`,children:`Settings`}),i(`p`,{className:`text-xs text-foreground-subtle`,children:[`Declared by this script's `,d(`code`,{children:`settingsSchema`}),` export.`]})]}),i(y,{size:`sm`,variant:`primary`,onClick:k,disabled:!D||s.isPending||x,children:[s.isPending&&d(B,{className:`h-3.5 w-3.5 animate-spin`}),`Save settings`]})]}),d(Oe,{schema:C,values:T,onChange:E,onAction:A}),h===null?null:d(`p`,{className:`text-xs text-danger`,"data-testid":`script-settings-save-error`,children:h}),_===null?null:d(`p`,{className:`text-xs text-foreground-subtle`,"data-testid":`script-settings-info`,children:_})]})}r();var Wi=`hub`;function Gi({existing:e,typeDefs:t,typeDefsLoading:n,saving:r,saveError:a,restarting:s,restartError:f,onRestart:m,onSave:h,onCancel:g}){let _=p(),v=I(),{resolvedMode:x}=me(),S=xe({code:e?.code??ji,files:e?.files,entry:e?.entry}),[w,T]=l(e?.name??``),[D,O]=l(S.files),[k,j]=l(S.entry),[N,P]=l(S.entry),[F,ee]=l(e?.placement??Wi),[R,te]=l(e?.integrationId??``),[ne,re]=l([]),[ie,oe]=l(!1),[se,ce]=l(`blank`),[le,ue]=l(null),[fe,pe]=l(``),V=D[N]??``,he=e=>{O(t=>({...t,[N]:e}))},ge=Object.keys(D).toSorted(),_e=ki.length>1,ve=o(()=>[...t?.libs??[],...wi(D,N)],[t?.libs,D,N]),H=u({mutationFn:()=>_.trpcClient.coreBlocks.compile.mutate({files:D,entry:k})}),U=o(()=>ne.filter(e=>e.severity>=8),[ne]),ye=Oi(ne),be=w.trim()===``,Se=e===null?null:xe(e),G=e===null||Se===null||JSON.stringify(D)!==JSON.stringify(Se.files)||k!==Se.entry||w.trim()!==e.name||F!==e.placement||(R.trim()===``?void 0:R.trim())!==e.integrationId,Ce=()=>{H.reset(),h({name:w.trim(),files:D,entry:k,enabled:e?.enabled??!0,placement:F,...R.trim()===``?{}:{integrationId:R.trim()}})},we=()=>{let e=Ai(Object.keys(D));O(t=>({...t,[e]:``})),P(e),ue(e),pe(e)},Te=e=>{ue(e),pe(e)},Ee=()=>{if(le===null)return;let e=le,t=fe.trim();if(ue(null),!(t===``||t===e)){if(D[t]!==void 0){P(t);return}O(n=>{let r={};for(let[i,a]of Object.entries(n))r[i===e?t:i]=a;return r}),k===e&&j(t),P(t)}},K=async e=>{let t=ki.find(t=>t.id===e);if(t===void 0)return;let n=ki.find(e=>e.id===`blank`);!(n!==void 0&&JSON.stringify(D)===JSON.stringify(n.files)&&k===n.entry)&&!await v({title:`Load example`,message:`Replace the current editor contents with this example?`,confirmLabel:`Replace`,variant:`warning`})||(ce(e),O({...t.files}),j(t.entry),P(t.entry),(w.trim()===``||se===`blank`)&&T(t.id===`blank`?``:t.name))},De=e===null?null:hn(e),Oe=Mi({existing:e,dirty:G,saving:r,restarting:s});return d(A,{children:i(`div`,{className:`space-y-4 p-4`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`h3`,{className:`font-medium`,children:e===null?`New script`:`Edit ${e.name}`}),De!==null&&d(L,{variant:gn(De.tone),children:De.label})]}),i(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[i(`label`,{className:`block text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Name`}),d(z,{className:`mt-1`,value:w,onChange:e=>T(e.target.value),placeholder:`What this script does`})]}),i(`label`,{className:`block text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Integration (optional)`}),d(z,{className:`mt-1`,value:R,onChange:e=>te(e.target.value),placeholder:`Leave empty for the shared system integration`})]})]}),e===null&&_e&&i(`label`,{className:`block text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Start from`}),d(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1.5 text-sm`,value:se,onChange:e=>void K(e.target.value),"data-testid":`script-example-select`,children:ki.map(e=>i(`option`,{value:e.id,children:[e.name,` — `,e.description]},e.id))})]}),i(`div`,{children:[d(b,{selectedNodeId:F,onSelect:ee,label:`Runs on`,alwaysShow:!0}),F!==Wi&&i(`p`,{className:`mt-2 flex items-start gap-2 text-xs text-warning`,children:[d(de,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),i(`span`,{children:[`Block execution is hub-only today. Saved with this placement the block will be stored and compiled, but it will report `,d(`strong`,{children:`Failed`}),` instead of running.`]})]})]}),i(`div`,{className:`flex min-h-[56vh] flex-col rounded border border-border`,children:[i(`div`,{className:`flex flex-wrap items-center gap-1 border-b border-border px-2 py-1.5`,children:[ge.map(e=>le===e?d(z,{value:fe,onChange:e=>pe(e.target.value),onBlur:()=>Ee(),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),Ee()),e.key===`Escape`&&(e.preventDefault(),ue(null))},className:`h-7 w-36 px-2 py-0 text-xs`,autoFocus:!0,"data-testid":`script-file-rename`,"aria-label":`Rename file`},e):i(`button`,{type:`button`,className:`rounded px-2 py-1 text-xs ${e===N?`bg-muted font-medium text-foreground`:`text-foreground-subtle hover:text-foreground`}`,onClick:()=>P(e),onDoubleClick:()=>Te(e),title:`Double-click to rename`,"data-testid":`script-file-tab-${e}`,children:[e,e===k?` · entry`:``]},e)),d(`button`,{type:`button`,className:`ml-1 rounded px-2 py-1 text-xs text-foreground-subtle hover:text-foreground`,onClick:we,"data-testid":`script-file-add`,children:`+ file`}),N!==k&&d(`button`,{type:`button`,className:`rounded px-2 py-1 text-xs text-foreground-subtle hover:text-foreground`,onClick:()=>j(N),title:`Use this file as the compile entry`,children:`Set as entry`})]}),n?d(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:`Loading the node's type definitions…`}):d(Di,{value:V,onChange:he,path:`file:///${N}`,extraLibs:ve,onDiagnostics:re,dark:x===`dark`,heightPx:560})]}),t!==void 0&&t.libs.length===0&&d(`p`,{className:`text-xs text-warning`,children:`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.`}),U.length>0&&i(`div`,{className:`space-y-1 rounded border border-danger/40 bg-danger/10 p-3 text-xs`,children:[i(`p`,{className:`font-medium text-danger`,children:[U.length,` error`,U.length===1?``:`s`,` — the block cannot be saved.`]}),U.slice(0,5).map(e=>i(`p`,{className:`text-danger`,children:[`line `,e.line,`: `,e.message]},`${String(e.line)}:${String(e.column)}:${e.message}`)),U.length>5&&i(`p`,{className:`text-foreground-subtle`,children:[`…and `,U.length-5,` more.`]})]}),H.data!==void 0&&(H.data.ok?i(`p`,{className:`flex items-center gap-2 text-xs text-success`,children:[d(E,{className:`h-3.5 w-3.5`}),` The node compiled this code. Nothing was saved.`]}):i(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:[H.data.line===void 0?``:`line ${String(H.data.line)}: `,H.data.error??`the code does not compile`]})),H.error!==null&&i(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:[`Could not reach the compiler: `,Ki(H.error)]}),a!==null&&d(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:a}),f!==null&&d(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:f}),e!==null&&i(`div`,{className:`space-y-3`,children:[d(Ui,{blockId:e.id}),d(Fi,{blockId:e.id})]}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(y,{variant:`outline`,onClick:()=>H.mutate(),disabled:H.isPending||r,title:`Type-check on the node without saving`,children:[H.isPending&&d(B,{className:`h-4 w-4 animate-spin`}),` Compile`]}),i(y,{onClick:Ce,disabled:r||ye||be,children:[r&&d(B,{className:`h-4 w-4 animate-spin`}),` Save`]}),i(y,{variant:`outline`,onClick:()=>m?.(),disabled:Oe!==null||m===void 0,title:Oe??`Stop the process and let the supervisor bring it back`,children:[s?d(C,{className:`h-4 w-4 animate-spin`}):d(C,{className:`h-4 w-4`}),` `,`Restart`]}),i(y,{variant:`ghost`,onClick:()=>oe(!ie),title:`Show this script's process logs`,"data-testid":`script-logs-toggle`,children:[d(ae,{className:`h-4 w-4`}),` Logs `,ie?`▾`:`▸`]}),d(y,{variant:`ghost`,onClick:g,disabled:r,children:`Close`}),i(`span`,{className:`ml-auto text-xs text-foreground-subtle`,children:[`errors: `,U.length,G&&e!==null?` · unsaved changes`:``]}),be&&d(L,{variant:`warning`,children:`Name required`})]}),ie&&i(`div`,{className:`rounded border border-border`,"data-testid":`script-logs-panel`,children:[d(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:e===null?`Logs appear once the script has been saved and started.`:i(c,{children:[`Logs — `,d(`code`,{children:W(e.id)})]})}),e!==null&&d(M,{addonId:W(e.id),maxHeight:`max-h-[560px]`,showFilters:!1})]})]})})}function Ki(e){return e instanceof Error?e.message:String(e)}r();var qi=[`coreBlocks`,`list`],Ji=[`coreBlocks`,`getTypeDefs`],Yi=5e3;function $(e){return e instanceof Error?e.message:String(e)}function Xi({initialBlockId:e,onBlockIdChange:n,createRequested:r=!1,onCreateConsumed:a}={}){let o=p(),[c,m]=l({mode:`closed`}),[h,g]=l(null),[_,v]=l(null),y=s({queryKey:qi,refetchInterval:Yi,queryFn:async()=>(await o.trpcClient.coreBlocks.list.query({})).blocks}),b=s({queryKey:Ji,enabled:c.mode===`edit`,staleTime:1/0,gcTime:1/0,queryFn:()=>o.trpcClient.coreBlocks.getTypeDefs.query({})}),x=()=>{y.refetch()},S=t(null),C=y.data;f(()=>{if(e===void 0||S.current===e)return;let t=C?.find(t=>t.id===e&&ye(t)===`code`);t!==void 0&&(S.current=e,m({mode:`edit`,block:t}))},[e,C]),f(()=>{r&&(m({mode:`edit`,block:null}),n?.(null),a?.())},[r,a,n]);let w=u({mutationFn:e=>o.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{m({mode:`edit`,block:e.block}),n?.(e.block.id),x()}}),T=u({mutationFn:e=>o.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{m({mode:`edit`,block:e.block}),n?.(e.block.id),x()}}),E=u({mutationFn:e=>o.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{g(null),x()}}),O=u({mutationFn:e=>o.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:x}),k=u({mutationFn:e=>o.trpcClient.coreBlocks.restart.mutate({blockId:e}),onSuccess:x}),j=vn((y.data??[]).filter(e=>ye(e)===`code`)),M=y.data!==void 0&&j.length===0,N=w.isPending||T.isPending,P=w.error===null?T.error===null?null:$(T.error):$(w.error),F=c.mode===`edit`&&c.block!==null?_n(j,c.block):null,I=c.mode===`edit`;return i(`div`,{className:`space-y-3`,children:[!I&&d(`p`,{className:`text-xs text-foreground-subtle`,children:y.data===void 0?``:yn(j)}),y.error!=null&&d(D,{title:`Could not read the scripts`,message:$(y.error),onRetry:x}),I&&d(`div`,{className:`min-h-[70vh]`,"data-testid":`script-editor-panel`,children:d(Gi,{existing:F,typeDefs:b.data,typeDefsLoading:b.isLoading,saving:N,saveError:P,restarting:k.isPending,restartError:k.error===null?null:$(k.error),onRestart:F===null?void 0:()=>k.mutate(F.id),onSave:e=>{let t=F;t===null?w.mutate(e):T.mutate({blockId:t.id,block:e})},onCancel:()=>{w.reset(),T.reset(),k.reset(),m({mode:`closed`}),n?.(null)}})}),!I&&M&&d(A,{children:i(`div`,{className:`space-y-1 p-4`,children:[d(`p`,{className:`text-sm text-foreground`,children:`No scripts yet.`}),d(`p`,{className:`text-xs text-foreground-subtle`,children:`A script is TypeScript the hub runs in its own process, with the same context an addon gets — devices, storage, the event bus. It is supervised: one that throws or hangs is marked failed and shown here, not left silently absent.`})]})}),!I&&j.length>0&&d(A,{children:d(`ul`,{className:`divide-y divide-border`,"data-testid":`scripts-list`,children:j.map(e=>d(Zi,{block:e,busy:O.isPending||E.isPending,restarting:k.isPending&&k.variables===e.id,confirming:h===e.id,logsOpen:_===e.id,onToggle:t=>O.mutate({blockId:e.id,enabled:t}),onRestart:()=>k.mutate(e.id),onToggleLogs:()=>v(_===e.id?null:e.id),onEdit:()=>{m({mode:`edit`,block:e}),n?.(e.id)},onAskDelete:()=>g(e.id),onCancelDelete:()=>g(null),onConfirmDelete:()=>E.mutate(e.id)},e.id))})}),E.error!=null&&d(D,{message:$(E.error)}),O.error!=null&&d(D,{message:$(O.error)}),k.error!=null&&d(D,{message:$(k.error)})]})}function Zi({block:e,busy:t,restarting:n,confirming:r,logsOpen:a,onToggle:o,onRestart:s,onToggleLogs:c,onEdit:l,onAskDelete:u,onCancelDelete:f,onConfirmDelete:p}){let m=hn(e),h=ne(e.updatedAt);return i(`li`,{className:`flex flex-col gap-2 p-3`,children:[i(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[i(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`span`,{className:`truncate font-medium`,children:e.name}),d(L,{variant:gn(m.tone),children:m.label}),d(L,{variant:`info`,children:e.placement}),h!==null&&i(`span`,{className:`text-xs text-foreground-subtle`,children:[`edited `,h]})]}),d(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:m.detail})]}),r?i(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-xs text-foreground-subtle`,children:`Delete this script?`}),d(y,{variant:`danger`,onClick:p,disabled:t,children:`Delete`}),d(y,{variant:`ghost`,onClick:f,children:`Cancel`})]}):i(`div`,{className:`flex items-center gap-2`,children:[d(y,{variant:`ghost`,onClick:l,title:`Edit`,children:d(S,{className:`h-4 w-4`})}),d(y,{variant:`ghost`,onClick:s,disabled:t||n||!e.enabled,title:e.enabled?`Restart`:`Enable it instead — a disabled script has no process`,children:d(C,{className:`h-4 w-4${n?` animate-spin`:``}`})}),d(y,{variant:`ghost`,onClick:c,title:`Logs`,children:d(ae,{className:`h-4 w-4`})}),d(y,{variant:`ghost`,onClick:()=>o(!e.enabled),disabled:t,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),d(y,{variant:`ghost`,onClick:u,title:`Delete`,children:d(g,{className:`h-4 w-4`})})]})]}),a&&i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,d(`code`,{children:W(e.id)})]}),d(M,{addonId:W(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}var Qi=[`automations`,`scripts`,`custom-device`];function $i(e){return e!==null&&Qi.some(t=>t===e)}var ea=[`coreBlocks`,`list`,`build-counts`];function ta(e){return e.filter(e=>ye(e)===`code`).length}function na(e){return e.filter(e=>Re(e.code)).length}function ra(){let e=p(),[t,n]=Ee(),r=t.get(`tab`),a=$i(r)?r:`automations`,o=t.get(`create`)===`1`,c=s({queryKey:ea,refetchInterval:5e3,queryFn:async()=>(await e.trpcClient.coreBlocks.list.query({})).blocks}).data,l=c===void 0?null:ta(c),u=c===void 0?null:na(c),f=s({queryKey:[`coreBlocks`,`listCompositions`,`build-counts`],refetchInterval:1e4,queryFn:async()=>e.trpcClient.coreBlocks.listCompositions.query({})}),m=f.data?.state===`loaded`?f.data.views.length:null,h=e=>{n(t=>{let n=new URLSearchParams(t);return n.set(`tab`,e),n.delete(`block`),n.delete(`create`),n},{replace:!0})},g=e=>{n(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})},_=e=>{n(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})},v=e=>{n(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})},b=()=>{n(e=>{let t=new URLSearchParams(e);return t.set(`create`,`1`),t.delete(`block`),t},{replace:!0})},S=()=>{n(e=>{let t=new URLSearchParams(e);return t.delete(`create`),t},{replace:!0})};return d(Me,{icon:se,title:`Build-your-self`,subtitle:`Automations, scripts and composed devices — what this installation does on its own.`,actions:a===`custom-device`?void 0:i(y,{type:`button`,onClick:b,"data-testid":`build-new`,children:[d(P,{className:`h-4 w-4`}),` `,a===`automations`?`New automation`:a===`scripts`?`New script`:`New composition`]}),children:i(x,{value:a,onValueChange:h,children:[i(le,{children:[i(w,{value:`automations`,children:[`Automations`,u===null?``:` (${String(u)})`]}),i(w,{value:`scripts`,children:[`Scripts`,l===null?``:` (${String(l)})`]}),i(w,{value:`custom-device`,children:[`Custom Device`,m===null?``:` (${String(m)})`]})]}),d(T,{value:`automations`,children:d(Tn,{onOpenScripts:g,initialBlockId:a===`automations`?t.get(`block`)??void 0:void 0,onBlockIdChange:_,createRequested:a===`automations`&&o,onCreateConsumed:S})}),d(T,{value:`scripts`,children:d(Xi,{initialBlockId:a===`scripts`?t.get(`block`)??void 0:void 0,onBlockIdChange:v,createRequested:a===`scripts`&&o,onCreateConsumed:S})}),d(T,{value:`custom-device`,children:d(Gn,{})})]})})}export{ra as BuildPage};
|
|
40
|
+
`;function Mi({existing:e,dirty:t,saving:n,restarting:r}){return e===null?`Save the script first — there is no process to restart yet.`:n?`Saving…`:r?`Restarting…`:t?`Save first — a restart now would run the last SAVED code, not what is on screen.`:e.enabled?null:`This script is disabled. Enable it instead of restarting it.`}r();var Ni=5e3;function Pi(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 Fi({blockId:e}){let t=W(e),n=ee({addonId:t,projection:`slim`},{refetchInterval:Ni}),r=o(()=>Pi(n.data),[n.data]);return n.isLoading?i(`p`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(B,{className:`h-3.5 w-3.5 animate-spin`}),` Loading devices owned by this script…`]}):n.isError?i(`p`,{className:`text-xs text-danger`,children:[`Could not list devices:`,` `,n.error instanceof Error?n.error.message:String(n.error)]}):i(`section`,{className:`space-y-3 rounded border border-border p-3`,"data-testid":`script-devices-panel`,children:[i(`div`,{className:`flex items-center justify-between gap-2`,children:[i(`div`,{children:[d(`h4`,{className:`text-sm font-medium`,children:`Devices`}),i(`p`,{className:`text-xs text-foreground-subtle`,children:[`Declared by this script under the shared Blocks integration (`,d(`code`,{className:`text-[11px]`,children:t}),`). Open a device for its export section.`]})]}),d(L,{variant:`default`,children:r.length})]}),r.length===0?i(`p`,{className:`text-xs text-foreground-subtle`,children:[`No devices yet. Call `,d(`code`,{children:`reconcileBlockDevices(ctx, …)`}),` from the script (and Restart) to declare them.`]}):d(`ul`,{className:`space-y-3`,children:r.map(e=>d(`li`,{className:`rounded border border-border/80 px-3 py-2`,"data-testid":`script-device-${e.id}`,children:i(`div`,{className:`flex flex-wrap items-baseline gap-2`,children:[d(K,{to:`/devices/${String(e.id)}`,className:`text-sm font-medium hover:underline`,title:`Open device detail`,children:e.name}),d(L,{variant:`info`,style:`outline`,children:e.type}),e.stableId!==void 0&&i(`span`,{className:`text-[11px] text-foreground-subtle`,children:[`stableId `,d(`code`,{children:e.stableId})]}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:[`#`,e.id]})]})},e.id))})]})}r();function Ii(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 Li(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 Ri(e){switch(e){case`refresh-channel-catalog`:return`Script enabled so the channel catalog can scrape.`;case`send-tv-schedule-now`:return`Script enabled so the TV schedule can send.`;case`refresh-nordvpn-catalog`:return`Script enabled so the NordVPN catalog can refresh.`;case`probe-nordvpn-italy`:return`Script enabled so Italy stations can be probed.`;case`test-nordvpn-endpoint`:return`Script enabled so the VPN endpoint can be tested.`;case`refresh-unifi-catalog`:return`Script enabled so UniFi IDs can be fetched.`}}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 Bi(e){if(!(typeof e!=`object`||!e||!(`value`in e)))return Reflect.get(e,`value`)}function Vi(e){let t={};for(let n of e.sections)for(let e of n.fields){let n=zi(e);n!==null&&(t[n]=Bi(e))}return t}function Hi(e){return typeof e!=`object`||!e?!1:Array.isArray(Reflect.get(e,`sections`))}function Ui({blockId:t}){let n=p(),r=pe({blockId:t},{retry:!1}),a=N({blockId:t},{refetchInterval:1e4,retry:!1}),s=O({onSuccess:()=>{a.refetch()}}),c=v(),u=ie(),[f,m]=l(null),[h,g]=l(null),[_,b]=l(null),[x,S]=l(!1),C=Hi(a.data)?a.data:null,w=o(()=>C===null?{}:Vi(C),[C]),T=f??w,E=e(e=>{m(e)},[]),D=f!==null,k=e(()=>{f!==null&&(g(null),s.mutate({blockId:t,patch:f},{onSuccess:()=>m(null),onError:e=>g(e instanceof Error?e.message:String(e))}))},[t,f,s]),A=e(async(e,i)=>{if(Ii(e)){S(!0),g(null),b(null);try{f!==null&&(await n.trpcClient.coreBlocks.updateBlockSettings.mutate({blockId:t,patch:f}),m(null)),await n.trpcClient.coreBlocks.updateBlockSettings.mutate({blockId:t,patch:Li(e)}),r.data?.block?.enabled!==!0&&(await u.mutateAsync({blockId:t,enabled:!0}),b(Ri(e))),await c.mutateAsync({blockId:t}),await a.refetch(),e===`send-tv-schedule-now`?b(`Sending tonight’s schedule now…`):e===`probe-nordvpn-italy`?b(`Probing NordVPN Italy stations (no UniFi change)…`):e===`test-nordvpn-endpoint`?b(`Testing VPN endpoint on UniFi…`):e===`refresh-nordvpn-catalog`?b(`Refreshing NordVPN Italy catalog…`):e===`refresh-unifi-catalog`&&b(`Refreshing UniFi ID catalogs…`)}catch(e){g(e instanceof Error?e.message:String(e))}finally{S(!1)}}},[t,r.data?.block?.enabled,f,c,u,a,n.trpcClient.coreBlocks]);return a.isLoading?i(`p`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(B,{className:`h-3.5 w-3.5 animate-spin`}),` Loading script settings…`]}):a.isError?i(`p`,{className:`text-xs text-danger`,"data-testid":`script-settings-error`,children:[`Could not load settings:`,` `,a.error instanceof Error?a.error.message:String(a.error)]}):C===null?null:i(`section`,{className:`space-y-3 rounded border border-border p-3`,"data-testid":`script-settings-panel`,children:[i(`div`,{className:`flex items-center justify-between gap-2`,children:[i(`div`,{children:[d(`h4`,{className:`text-sm font-medium`,children:`Settings`}),i(`p`,{className:`text-xs text-foreground-subtle`,children:[`Declared by this script's `,d(`code`,{children:`settingsSchema`}),` export.`]})]}),i(y,{size:`sm`,variant:`primary`,onClick:k,disabled:!D||s.isPending||x,children:[s.isPending&&d(B,{className:`h-3.5 w-3.5 animate-spin`}),`Save settings`]})]}),d(Ae,{schema:C,values:T,onChange:E,onAction:A}),h===null?null:d(`p`,{className:`text-xs text-danger`,"data-testid":`script-settings-save-error`,children:h}),_===null?null:d(`p`,{className:`text-xs text-foreground-subtle`,"data-testid":`script-settings-info`,children:_})]})}r();var Wi=`hub`;function Gi({existing:e,typeDefs:t,typeDefsLoading:n,saving:r,saveError:a,restarting:s,restartError:f,onRestart:m,onSave:h,onCancel:g}){let _=p(),v=I(),{resolvedMode:x}=me(),S=xe({code:e?.code??ji,files:e?.files,entry:e?.entry}),[w,T]=l(e?.name??``),[D,O]=l(S.files),[k,j]=l(S.entry),[N,P]=l(S.entry),[F,ee]=l(e?.placement??Wi),[R,te]=l(e?.integrationId??``),[ne,re]=l([]),[ie,oe]=l(!1),[se,ce]=l(`blank`),[le,ue]=l(null),[fe,pe]=l(``),V=D[N]??``,he=e=>{O(t=>({...t,[N]:e}))},ge=Object.keys(D).toSorted(),_e=ki.length>1,ve=o(()=>[...t?.libs??[],...wi(D,N)],[t?.libs,D,N]),H=u({mutationFn:()=>_.trpcClient.coreBlocks.compile.mutate({files:D,entry:k})}),U=o(()=>ne.filter(e=>e.severity>=8),[ne]),ye=Oi(ne),be=w.trim()===``,Se=e===null?null:xe(e),G=e===null||Se===null||JSON.stringify(D)!==JSON.stringify(Se.files)||k!==Se.entry||w.trim()!==e.name||F!==e.placement||(R.trim()===``?void 0:R.trim())!==e.integrationId,Ce=()=>{H.reset(),h({name:w.trim(),files:D,entry:k,enabled:e?.enabled??!0,placement:F,...R.trim()===``?{}:{integrationId:R.trim()}})},we=()=>{let e=Ai(Object.keys(D));O(t=>({...t,[e]:``})),P(e),ue(e),pe(e)},Te=e=>{ue(e),pe(e)},Ee=()=>{if(le===null)return;let e=le,t=fe.trim();if(ue(null),!(t===``||t===e)){if(D[t]!==void 0){P(t);return}O(n=>{let r={};for(let[i,a]of Object.entries(n))r[i===e?t:i]=a;return r}),k===e&&j(t),P(t)}},K=async e=>{let t=ki.find(t=>t.id===e);if(t===void 0)return;let n=ki.find(e=>e.id===`blank`);!(n!==void 0&&JSON.stringify(D)===JSON.stringify(n.files)&&k===n.entry)&&!await v({title:`Load example`,message:`Replace the current editor contents with this example?`,confirmLabel:`Replace`,variant:`warning`})||(ce(e),O({...t.files}),j(t.entry),P(t.entry),(w.trim()===``||se===`blank`)&&T(t.id===`blank`?``:t.name))},De=e===null?null:hn(e),Oe=Mi({existing:e,dirty:G,saving:r,restarting:s});return d(A,{children:i(`div`,{className:`space-y-4 p-4`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`h3`,{className:`font-medium`,children:e===null?`New script`:`Edit ${e.name}`}),De!==null&&d(L,{variant:gn(De.tone),children:De.label})]}),i(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[i(`label`,{className:`block text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Name`}),d(z,{className:`mt-1`,value:w,onChange:e=>T(e.target.value),placeholder:`What this script does`})]}),i(`label`,{className:`block text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Integration (optional)`}),d(z,{className:`mt-1`,value:R,onChange:e=>te(e.target.value),placeholder:`Leave empty for the shared system integration`})]})]}),e===null&&_e&&i(`label`,{className:`block text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Start from`}),d(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1.5 text-sm`,value:se,onChange:e=>void K(e.target.value),"data-testid":`script-example-select`,children:ki.map(e=>i(`option`,{value:e.id,children:[e.name,` — `,e.description]},e.id))})]}),i(`div`,{children:[d(b,{selectedNodeId:F,onSelect:ee,label:`Runs on`,alwaysShow:!0}),F!==Wi&&i(`p`,{className:`mt-2 flex items-start gap-2 text-xs text-warning`,children:[d(de,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),i(`span`,{children:[`Block execution is hub-only today. Saved with this placement the block will be stored and compiled, but it will report `,d(`strong`,{children:`Failed`}),` instead of running.`]})]})]}),i(`div`,{className:`flex min-h-[56vh] flex-col rounded border border-border`,children:[i(`div`,{className:`flex flex-wrap items-center gap-1 border-b border-border px-2 py-1.5`,children:[ge.map(e=>le===e?d(z,{value:fe,onChange:e=>pe(e.target.value),onBlur:()=>Ee(),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),Ee()),e.key===`Escape`&&(e.preventDefault(),ue(null))},className:`h-7 w-36 px-2 py-0 text-xs`,autoFocus:!0,"data-testid":`script-file-rename`,"aria-label":`Rename file`},e):i(`button`,{type:`button`,className:`rounded px-2 py-1 text-xs ${e===N?`bg-muted font-medium text-foreground`:`text-foreground-subtle hover:text-foreground`}`,onClick:()=>P(e),onDoubleClick:()=>Te(e),title:`Double-click to rename`,"data-testid":`script-file-tab-${e}`,children:[e,e===k?` · entry`:``]},e)),d(`button`,{type:`button`,className:`ml-1 rounded px-2 py-1 text-xs text-foreground-subtle hover:text-foreground`,onClick:we,"data-testid":`script-file-add`,children:`+ file`}),N!==k&&d(`button`,{type:`button`,className:`rounded px-2 py-1 text-xs text-foreground-subtle hover:text-foreground`,onClick:()=>j(N),title:`Use this file as the compile entry`,children:`Set as entry`})]}),n?d(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:`Loading the node's type definitions…`}):d(Di,{value:V,onChange:he,path:`file:///${N}`,extraLibs:ve,onDiagnostics:re,dark:x===`dark`,heightPx:560})]}),t!==void 0&&t.libs.length===0&&d(`p`,{className:`text-xs text-warning`,children:`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.`}),U.length>0&&i(`div`,{className:`space-y-1 rounded border border-danger/40 bg-danger/10 p-3 text-xs`,children:[i(`p`,{className:`font-medium text-danger`,children:[U.length,` error`,U.length===1?``:`s`,` — the block cannot be saved.`]}),U.slice(0,5).map(e=>i(`p`,{className:`text-danger`,children:[`line `,e.line,`: `,e.message]},`${String(e.line)}:${String(e.column)}:${e.message}`)),U.length>5&&i(`p`,{className:`text-foreground-subtle`,children:[`…and `,U.length-5,` more.`]})]}),H.data!==void 0&&(H.data.ok?i(`p`,{className:`flex items-center gap-2 text-xs text-success`,children:[d(E,{className:`h-3.5 w-3.5`}),` The node compiled this code. Nothing was saved.`]}):i(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:[H.data.line===void 0?``:`line ${String(H.data.line)}: `,H.data.error??`the code does not compile`]})),H.error!==null&&i(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:[`Could not reach the compiler: `,Ki(H.error)]}),a!==null&&d(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:a}),f!==null&&d(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:f}),e!==null&&i(`div`,{className:`space-y-3`,children:[d(Ui,{blockId:e.id}),d(Fi,{blockId:e.id})]}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(y,{variant:`outline`,onClick:()=>H.mutate(),disabled:H.isPending||r,title:`Type-check on the node without saving`,children:[H.isPending&&d(B,{className:`h-4 w-4 animate-spin`}),` Compile`]}),i(y,{onClick:Ce,disabled:r||ye||be,children:[r&&d(B,{className:`h-4 w-4 animate-spin`}),` Save`]}),i(y,{variant:`outline`,onClick:()=>m?.(),disabled:Oe!==null||m===void 0,title:Oe??`Stop the process and let the supervisor bring it back`,children:[s?d(C,{className:`h-4 w-4 animate-spin`}):d(C,{className:`h-4 w-4`}),` `,`Restart`]}),i(y,{variant:`ghost`,onClick:()=>oe(!ie),title:`Show this script's process logs`,"data-testid":`script-logs-toggle`,children:[d(ae,{className:`h-4 w-4`}),` Logs `,ie?`▾`:`▸`]}),d(y,{variant:`ghost`,onClick:g,disabled:r,children:`Close`}),i(`span`,{className:`ml-auto text-xs text-foreground-subtle`,children:[`errors: `,U.length,G&&e!==null?` · unsaved changes`:``]}),be&&d(L,{variant:`warning`,children:`Name required`})]}),ie&&i(`div`,{className:`rounded border border-border`,"data-testid":`script-logs-panel`,children:[d(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:e===null?`Logs appear once the script has been saved and started.`:i(c,{children:[`Logs — `,d(`code`,{children:W(e.id)})]})}),e!==null&&d(M,{addonId:W(e.id),maxHeight:`max-h-[560px]`,showFilters:!1})]})]})})}function Ki(e){return e instanceof Error?e.message:String(e)}r();var qi=[`coreBlocks`,`list`],Ji=[`coreBlocks`,`getTypeDefs`],Yi=5e3;function $(e){return e instanceof Error?e.message:String(e)}function Xi({initialBlockId:e,onBlockIdChange:n,createRequested:r=!1,onCreateConsumed:a}={}){let o=p(),[c,m]=l({mode:`closed`}),[h,g]=l(null),[_,v]=l(null),y=s({queryKey:qi,refetchInterval:Yi,queryFn:async()=>(await o.trpcClient.coreBlocks.list.query({})).blocks}),b=s({queryKey:Ji,enabled:c.mode===`edit`,staleTime:1/0,gcTime:1/0,queryFn:()=>o.trpcClient.coreBlocks.getTypeDefs.query({})}),x=()=>{y.refetch()},S=t(null),C=y.data;f(()=>{if(e===void 0||S.current===e)return;let t=C?.find(t=>t.id===e&&ye(t)===`code`);t!==void 0&&(S.current=e,m({mode:`edit`,block:t}))},[e,C]),f(()=>{r&&(m({mode:`edit`,block:null}),n?.(null),a?.())},[r,a,n]);let w=u({mutationFn:e=>o.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{m({mode:`edit`,block:e.block}),n?.(e.block.id),x()}}),T=u({mutationFn:e=>o.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{m({mode:`edit`,block:e.block}),n?.(e.block.id),x()}}),E=u({mutationFn:e=>o.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{g(null),x()}}),O=u({mutationFn:e=>o.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:x}),k=u({mutationFn:e=>o.trpcClient.coreBlocks.restart.mutate({blockId:e}),onSuccess:x}),j=vn((y.data??[]).filter(e=>ye(e)===`code`)),M=y.data!==void 0&&j.length===0,N=w.isPending||T.isPending,P=w.error===null?T.error===null?null:$(T.error):$(w.error),F=c.mode===`edit`&&c.block!==null?_n(j,c.block):null,I=c.mode===`edit`;return i(`div`,{className:`space-y-3`,children:[!I&&d(`p`,{className:`text-xs text-foreground-subtle`,children:y.data===void 0?``:yn(j)}),y.error!=null&&d(D,{title:`Could not read the scripts`,message:$(y.error),onRetry:x}),I&&d(`div`,{className:`min-h-[70vh]`,"data-testid":`script-editor-panel`,children:d(Gi,{existing:F,typeDefs:b.data,typeDefsLoading:b.isLoading,saving:N,saveError:P,restarting:k.isPending,restartError:k.error===null?null:$(k.error),onRestart:F===null?void 0:()=>k.mutate(F.id),onSave:e=>{let t=F;t===null?w.mutate(e):T.mutate({blockId:t.id,block:e})},onCancel:()=>{w.reset(),T.reset(),k.reset(),m({mode:`closed`}),n?.(null)}})}),!I&&M&&d(A,{children:i(`div`,{className:`space-y-1 p-4`,children:[d(`p`,{className:`text-sm text-foreground`,children:`No scripts yet.`}),d(`p`,{className:`text-xs text-foreground-subtle`,children:`A script is TypeScript the hub runs in its own process, with the same context an addon gets — devices, storage, the event bus. It is supervised: one that throws or hangs is marked failed and shown here, not left silently absent.`})]})}),!I&&j.length>0&&d(A,{children:d(`ul`,{className:`divide-y divide-border`,"data-testid":`scripts-list`,children:j.map(e=>d(Zi,{block:e,busy:O.isPending||E.isPending,restarting:k.isPending&&k.variables===e.id,confirming:h===e.id,logsOpen:_===e.id,onToggle:t=>O.mutate({blockId:e.id,enabled:t}),onRestart:()=>k.mutate(e.id),onToggleLogs:()=>v(_===e.id?null:e.id),onEdit:()=>{m({mode:`edit`,block:e}),n?.(e.id)},onAskDelete:()=>g(e.id),onCancelDelete:()=>g(null),onConfirmDelete:()=>E.mutate(e.id)},e.id))})}),E.error!=null&&d(D,{message:$(E.error)}),O.error!=null&&d(D,{message:$(O.error)}),k.error!=null&&d(D,{message:$(k.error)})]})}function Zi({block:e,busy:t,restarting:n,confirming:r,logsOpen:a,onToggle:o,onRestart:s,onToggleLogs:c,onEdit:l,onAskDelete:u,onCancelDelete:f,onConfirmDelete:p}){let m=hn(e),h=ne(e.updatedAt);return i(`li`,{className:`flex flex-col gap-2 p-3`,children:[i(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[i(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`span`,{className:`truncate font-medium`,children:e.name}),d(L,{variant:gn(m.tone),children:m.label}),d(L,{variant:`info`,children:e.placement}),h!==null&&i(`span`,{className:`text-xs text-foreground-subtle`,children:[`edited `,h]})]}),d(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:m.detail})]}),r?i(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-xs text-foreground-subtle`,children:`Delete this script?`}),d(y,{variant:`danger`,onClick:p,disabled:t,children:`Delete`}),d(y,{variant:`ghost`,onClick:f,children:`Cancel`})]}):i(`div`,{className:`flex items-center gap-2`,children:[d(y,{variant:`ghost`,onClick:l,title:`Edit`,children:d(S,{className:`h-4 w-4`})}),d(y,{variant:`ghost`,onClick:s,disabled:t||n||!e.enabled,title:e.enabled?`Restart`:`Enable it instead — a disabled script has no process`,children:d(C,{className:`h-4 w-4${n?` animate-spin`:``}`})}),d(y,{variant:`ghost`,onClick:c,title:`Logs`,children:d(ae,{className:`h-4 w-4`})}),d(y,{variant:`ghost`,onClick:()=>o(!e.enabled),disabled:t,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),d(y,{variant:`ghost`,onClick:u,title:`Delete`,children:d(g,{className:`h-4 w-4`})})]})]}),a&&i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,d(`code`,{children:W(e.id)})]}),d(M,{addonId:W(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}var Qi=[`automations`,`scripts`,`custom-device`];function $i(e){return e!==null&&Qi.some(t=>t===e)}var ea=[`coreBlocks`,`list`,`build-counts`];function ta(e){return e.filter(e=>ye(e)===`code`).length}function na(e){return e.filter(e=>Re(e.code)).length}function ra(){let e=p(),[t,n]=De(),r=t.get(`tab`),a=$i(r)?r:`automations`,o=t.get(`create`)===`1`,c=s({queryKey:ea,refetchInterval:5e3,queryFn:async()=>(await e.trpcClient.coreBlocks.list.query({})).blocks}).data,l=c===void 0?null:ta(c),u=c===void 0?null:na(c),f=s({queryKey:[`coreBlocks`,`listCompositions`,`build-counts`],refetchInterval:1e4,queryFn:async()=>e.trpcClient.coreBlocks.listCompositions.query({})}),m=f.data?.state===`loaded`?f.data.views.length:null,h=e=>{n(t=>{let n=new URLSearchParams(t);return n.set(`tab`,e),n.delete(`block`),n.delete(`create`),n},{replace:!0})},g=e=>{n(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})},_=e=>{n(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})},v=e=>{n(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})},b=()=>{n(e=>{let t=new URLSearchParams(e);return t.set(`create`,`1`),t.delete(`block`),t},{replace:!0})},S=()=>{n(e=>{let t=new URLSearchParams(e);return t.delete(`create`),t},{replace:!0})};return d(Me,{icon:se,title:`Build-your-self`,subtitle:`Automations, scripts and composed devices — what this installation does on its own.`,actions:a===`custom-device`?void 0:i(y,{type:`button`,onClick:b,"data-testid":`build-new`,children:[d(P,{className:`h-4 w-4`}),` `,a===`automations`?`New automation`:a===`scripts`?`New script`:`New composition`]}),children:i(x,{value:a,onValueChange:h,children:[i(le,{children:[i(w,{value:`automations`,children:[`Automations`,u===null?``:` (${String(u)})`]}),i(w,{value:`scripts`,children:[`Scripts`,l===null?``:` (${String(l)})`]}),i(w,{value:`custom-device`,children:[`Custom Device`,m===null?``:` (${String(m)})`]})]}),d(T,{value:`automations`,children:d(Tn,{onOpenScripts:g,initialBlockId:a===`automations`?t.get(`block`)??void 0:void 0,onBlockIdChange:_,createRequested:a===`automations`&&o,onCreateConsumed:S})}),d(T,{value:`scripts`,children:d(Xi,{initialBlockId:a===`scripts`?t.get(`block`)??void 0:void 0,onBlockIdChange:v,createRequested:a===`scripts`&&o,onCreateConsumed:S})}),d(T,{value:`custom-device`,children:d(Gn,{})})]})})}export{ra as BuildPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{I as e,Q as t,S as n,W as r,b as i,q as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{ht as s}from"./player-overlays-CrKWnjLj.js";import{Bn as c,Vd as l,Wd as u,an as d,bi as f,cn as p,in as m,ln as h,rn as g,sn as _,vi as v,xi as y,yi as b}from"./src-Bkpo8B0D.js";import{t as x}from"./AdminPage-CiKtOLQm.js";t();var S=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`];function C(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function w(e,t){let n=new Date(e);return n.setDate(n.getDate()+t),n}function T(e){let t=e.getDay();return C(w(e,t===0?-6:1-t))}function E(e,t){if(t===`day`){let t=C(e);return{startMs:t.getTime(),endMs:w(t,1).getTime()}}if(t===`week`){let t=T(e);return{startMs:t.getTime(),endMs:w(t,7).getTime()}}let n=new Date(e.getFullYear(),e.getMonth(),1),r=new Date(e.getFullYear(),e.getMonth()+1,0),i=T(n),a=w(T(r),7);return{startMs:i.getTime(),endMs:a.getTime()}}function D(e,t){if(t===`day`)return e.toLocaleDateString(void 0,{weekday:`long`,year:`numeric`,month:`long`,day:`numeric`});if(t===`week`){let t=T(e),n=w(t,6),r={month:`short`,day:`numeric`};return`${t.toLocaleDateString(void 0,r)} – ${n.toLocaleDateString(void 0,{...r,year:`numeric`})}`}return e.toLocaleDateString(void 0,{month:`long`,year:`numeric`})}function O(e,t,n){return t===`day`?w(e,n):t===`week`?w(e,n*7):new Date(e.getFullYear(),e.getMonth()+n,1)}function k(e,t){if(t===void 0)return e;let n=t.calendars[e.id];return n===void 0?e:{...e,visible:n.visible??e.visible,color:n.color??e.defaultColor}}function A(e){return e.providerAddonId!==void 0&&e.providerAddonId.length>0?e.providerAddonId:e.source===`ha`?`Home Assistant`:e.source}function j(e){if(e.allDay===!0)return`All day`;let t=new Date(e.startMs),n=new Date(e.endMs),r={hour:`2-digit`,minute:`2-digit`};return`${t.toLocaleTimeString([],r)} – ${n.toLocaleTimeString([],r)}`}function M(e){let t=new Date(e.startMs),n=new Date(e.endMs),r={weekday:`short`,year:`numeric`,month:`short`,day:`numeric`};if(e.allDay===!0){let i=C(t),a=w(C(n),-1);return L(i,a)||N(e)?`${t.toLocaleDateString(void 0,r)} · All day`:`${t.toLocaleDateString(void 0,r)} – ${a.toLocaleDateString(void 0,r)} · All day`}let i={hour:`2-digit`,minute:`2-digit`};return L(t,n)?`${t.toLocaleDateString(void 0,r)} · ${t.toLocaleTimeString([],i)} – ${n.toLocaleTimeString([],i)}`:`${t.toLocaleString(void 0,{...r,...i})} – ${n.toLocaleString(void 0,{...r,...i})}`}function N(e){return C(new Date(e.endMs)).getTime()===C(new Date(e.startMs)).getTime()}function P({label:e,children:t}){return n(`div`,{className:`grid grid-cols-[7rem_minmax(0,1fr)] gap-x-3 gap-y-1 text-sm`,children:[o(`dt`,{className:`text-foreground-subtle`,children:e}),o(`dd`,{className:`min-w-0 break-words text-foreground`,children:t})]})}function F({ev:e,calendarName:t,color:r,onClose:i}){return o(g,{open:!0,onOpenChange:e=>!e&&i(),children:n(d,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`calendars-event-detail`,children:[o(p,{children:n(`div`,{className:`flex min-w-0 items-start gap-2.5`,children:[o(`span`,{className:`mt-1.5 h-3 w-3 shrink-0 rounded-full`,style:{backgroundColor:r},"aria-hidden":!0}),o(h,{className:`min-w-0 break-words`,children:e.title})]})}),o(m,{children:n(`dl`,{className:`space-y-3`,children:[o(P,{label:`When`,children:M(e)}),o(P,{label:`Calendar`,children:t}),e.location!==void 0&&e.location.length>0?o(P,{label:`Location`,children:e.location}):null,e.description!==void 0&&e.description.length>0?o(P,{label:`Description`,children:o(`span`,{className:`whitespace-pre-wrap`,children:e.description})}):null]})}),o(_,{children:o(c,{type:`button`,size:`sm`,variant:`secondary`,onClick:i,children:`Close`})})]})})}function I(e,t){let n=t+1440*60*1e3;return e.filter(e=>e.startMs<n&&e.endMs>t)}function L(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function R({mode:e,onChange:t}){return o(`div`,{className:`inline-flex rounded-lg border border-border bg-surface p-0.5`,role:`group`,"aria-label":`Calendar view`,children:[{id:`month`,label:`Month`},{id:`week`,label:`Week`},{id:`day`,label:`Day`}].map(n=>o(`button`,{type:`button`,className:e===n.id?`rounded-md bg-primary px-2.5 py-1 text-xs font-medium text-primary-foreground`:`rounded-md px-2.5 py-1 text-xs font-medium text-foreground-subtle hover:text-foreground`,"aria-pressed":e===n.id,onClick:()=>t(n.id),"data-testid":`calendars-view-${n.id}`,children:n.label},n.id))})}function z({calendars:e,onToggleVisible:t,onColorChange:r,busy:i}){return n(`aside`,{className:`w-full shrink-0 space-y-2 lg:w-56 xl:w-64`,"data-testid":`calendars-legend`,children:[o(`h2`,{className:`text-xs font-medium text-foreground-subtle`,children:`Calendars`}),o(`ul`,{className:`space-y-1`,children:e.map(e=>n(`li`,{className:`flex items-start gap-2 rounded-md px-1.5 py-1.5 hover:bg-surface`,children:[o(`input`,{type:`checkbox`,className:`mt-1 h-3.5 w-3.5 shrink-0 accent-primary`,checked:e.visible,disabled:i,onChange:n=>t(e.id,n.target.checked),"aria-label":`Show ${e.name}`,"data-testid":`calendars-visible-${e.id}`}),o(`input`,{type:`color`,className:`mt-0.5 h-6 w-6 shrink-0 cursor-pointer rounded border border-border bg-transparent p-0`,value:e.color,disabled:i,onChange:t=>r(e.id,t.target.value.toUpperCase()),"aria-label":`Colour for ${e.name}`,"data-testid":`calendars-color-${e.id}`}),n(`div`,{className:`min-w-0 flex-1`,children:[o(`div`,{className:`truncate text-sm font-medium ${e.visible?`text-foreground`:`text-foreground-subtle`}`,children:e.name}),n(`div`,{className:`truncate text-[11px] text-foreground-subtle`,children:[A(e),e.enabled?``:` · unavailable at source`]})]})]},e.id))})]})}function B({ev:e,color:t,compact:r,onSelect:a}){return o(`button`,{type:`button`,className:r?`block w-full truncate rounded px-1 py-0.5 text-left text-[10px] leading-tight text-white hover:brightness-110`:`block w-full rounded-md px-2 py-1.5 text-left text-xs text-white hover:brightness-110`,style:{backgroundColor:t},title:e.title,onClick:()=>a(e),"data-testid":`calendars-event-${e.id}`,children:r?e.title:n(i,{children:[o(`div`,{className:`font-medium`,children:e.title}),o(`div`,{className:`opacity-90`,children:j(e)})]})})}function V({anchor:e,events:t,colorById:r,today:i,onSelectEvent:a}){let{startMs:s,endMs:c}=E(e,`month`),l=[];for(let e=s;e<c;e+=1440*60*1e3)l.push(new Date(e));let u=e.getMonth();return n(`div`,{"data-testid":`calendars-month`,children:[o(`div`,{className:`mb-1 grid grid-cols-7 gap-px`,children:S.map(e=>o(`div`,{className:`px-1 py-1 text-center text-[11px] font-medium text-foreground-subtle`,children:e},e))}),o(`div`,{className:`grid grid-cols-7 gap-px overflow-hidden rounded-lg border border-border bg-border`,children:l.map(e=>{let s=C(e).getTime(),c=I(t,s),l=e.getMonth()!==u,d=L(e,i);return n(`div`,{className:`min-h-[5.5rem] bg-background p-1 ${l?`opacity-45`:``}`,children:[o(`div`,{className:d?`mb-1 inline-flex h-5 w-5 items-center justify-center rounded-full bg-primary text-[11px] font-semibold text-primary-foreground`:`mb-1 text-[11px] font-medium text-foreground-subtle`,children:e.getDate()}),n(`div`,{className:`space-y-0.5`,children:[c.slice(0,3).map(e=>o(B,{ev:e,color:r.get(e.calendarId)??`#64748B`,compact:!0,onSelect:a},e.id)),c.length>3?n(`div`,{className:`text-[10px] text-foreground-subtle`,children:[`+`,c.length-3,` more`]}):null]})]},s)})})]})}function H({anchor:e,events:t,colorById:r,today:i,onSelectEvent:a}){let s=T(e);return o(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-7 sm:gap-px sm:overflow-hidden sm:rounded-lg sm:border sm:border-border sm:bg-border`,"data-testid":`calendars-week`,children:Array.from({length:7},(e,t)=>w(s,t)).map(e=>{let s=C(e).getTime(),c=I(t,s);return n(`div`,{className:`min-h-[8rem] bg-background p-2 sm:min-h-[12rem]`,children:[o(`div`,{className:L(e,i)?`mb-2 text-xs font-semibold text-primary`:`mb-2 text-xs font-medium text-foreground-subtle`,children:e.toLocaleDateString(void 0,{weekday:`short`,day:`numeric`})}),o(`div`,{className:`space-y-1`,children:c.length===0?o(`p`,{className:`text-[11px] text-foreground-subtle`,children:`—`}):c.map(e=>o(B,{ev:e,color:r.get(e.calendarId)??`#64748B`,onSelect:a},e.id))})]},s)})})}function U({anchor:e,events:t,colorById:r,calName:i,onSelectEvent:a}){let s=I(t,C(e).getTime());return s.length===0?o(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-day-empty`,children:`No events on this day.`}):o(`ul`,{className:`divide-y divide-border rounded-lg border border-border`,"data-testid":`calendars-day`,children:s.map(e=>o(`li`,{children:n(`button`,{type:`button`,className:`flex w-full items-start gap-3 px-3 py-3 text-left hover:bg-surface`,onClick:()=>a(e),"data-testid":`calendars-event-${e.id}`,children:[o(`span`,{className:`mt-1 h-2.5 w-2.5 shrink-0 rounded-full`,style:{backgroundColor:r.get(e.calendarId)??`#64748B`}}),n(`div`,{className:`min-w-0`,children:[o(`div`,{className:`font-medium text-sm text-foreground`,children:e.title}),n(`div`,{className:`text-xs text-foreground-subtle`,children:[j(e),` · `,i.get(e.calendarId)??e.calendarId]}),e.location!==void 0&&e.location.length>0?o(`div`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:e.location}):null]})]})},e.id))})}function W(){let t=b(),i=v({}),c=y(),[d,p]=a(`month`),[m,h]=a(()=>C(new Date)),[g,_]=a(null),S=r(()=>C(new Date),[]),w=t.isSuccess,T=i.isSuccess&&i.data!==void 0?i.data:void 0,A=r(()=>!w||t.data===void 0?[]:t.data.map(e=>k(e,T)),[w,t.data,T]),j=r(()=>A.filter(e=>e.visible),[A]),M=r(()=>j.map(e=>e.id),[j]),N=r(()=>E(m,d),[m,d]),P=f({startMs:N.startMs,endMs:N.endMs,calendarIds:[...M]},{enabled:w&&M.length>0}),I=P.data??[],L=r(()=>{let e=new Map;for(let t of A)e.set(t.id,t.color);return e},[A]),B=r(()=>{let e=new Map;for(let t of A)e.set(t.id,t.name);return e},[A]),W=e((e,t)=>{c.mutateAsync({calendarId:e,visible:t}).then(()=>i.refetch())},[i,c]),G=e((e,t)=>{/^#[0-9A-Fa-f]{6}$/.test(t)&&c.mutateAsync({calendarId:e,color:t}).then(()=>i.refetch())},[i,c]),K=e(()=>h(C(new Date)),[]),q=e(()=>h(e=>O(e,d,-1)),[d]),J=e(()=>h(e=>O(e,d,1)),[d]),Y=`inline-flex h-8 w-8 items-center justify-center rounded-lg border border-border bg-surface text-foreground hover:bg-primary/5 disabled:opacity-50`,X;return X=t.isPending?o(`p`,{className:`text-sm text-foreground-subtle`,children:`Loading calendars…`}):t.isError?n(`p`,{className:`text-sm text-destructive`,children:[`Could not list calendars: `,t.error.message]}):A.length===0?o(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-empty-sources`,children:`No calendar sources yet. Connect a calendar-source addon (for example Home Assistant) and wait for it to register calendars.`}):M.length===0?n(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start`,children:[o(z,{calendars:A,onToggleVisible:W,onColorChange:G,busy:c.isPending}),o(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-empty-hidden`,children:`All calendars are hidden. Turn one on in the legend to see events.`})]}):n(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start`,children:[o(z,{calendars:A,onToggleVisible:W,onColorChange:G,busy:c.isPending}),n(`div`,{className:`min-w-0 flex-1 space-y-3`,children:[n(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(R,{mode:d,onChange:p}),n(`div`,{className:`flex items-center gap-1`,children:[o(`button`,{type:`button`,className:Y,onClick:q,"aria-label":`Previous`,"data-testid":`calendars-prev`,children:o(l,{className:`h-4 w-4`})}),o(`button`,{type:`button`,className:`inline-flex items-center rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5`,onClick:K,"data-testid":`calendars-today`,children:`Today`}),o(`button`,{type:`button`,className:Y,onClick:J,"aria-label":`Next`,"data-testid":`calendars-next`,children:o(s,{className:`h-4 w-4`})})]}),o(`span`,{className:`text-sm font-medium text-foreground`,"data-testid":`calendars-period`,children:D(m,d)})]}),P.isPending?o(`p`,{className:`text-sm text-foreground-subtle`,children:`Loading events…`}):P.isError?n(`p`,{className:`text-sm text-destructive`,children:[`Could not list events: `,P.error.message]}):d===`month`?o(V,{anchor:m,events:I,colorById:L,today:S,onSelectEvent:_}):d===`week`?o(H,{anchor:m,events:I,colorById:L,today:S,onSelectEvent:_}):o(U,{anchor:m,events:I,colorById:L,calName:B,onSelectEvent:_})]})]}),n(x,{icon:u,title:`Calendars`,subtitle:`Calendars from connected sources. Used by Calendar events notification rules.`,children:[X,g===null?null:o(F,{ev:g,calendarName:B.get(g.calendarId)??g.calendarId,color:L.get(g.calendarId)??`#64748B`,onClose:()=>_(null)})]})}export{W as CalendarsPage,W as default};
|
|
1
|
+
import{I as e,Q as t,S as n,W as r,b as i,q as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{ht as s}from"./player-overlays-CHWCYkGf.js";import{Bn as c,Vd as l,Wd as u,an as d,bi as f,cn as p,in as m,ln as h,rn as g,sn as _,vi as v,xi as y,yi as b}from"./src-Crb8RLzq.js";import{t as x}from"./AdminPage-BSFohA3i.js";t();var S=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`];function C(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function w(e,t){let n=new Date(e);return n.setDate(n.getDate()+t),n}function T(e){let t=e.getDay();return C(w(e,t===0?-6:1-t))}function E(e,t){if(t===`day`){let t=C(e);return{startMs:t.getTime(),endMs:w(t,1).getTime()}}if(t===`week`){let t=T(e);return{startMs:t.getTime(),endMs:w(t,7).getTime()}}let n=new Date(e.getFullYear(),e.getMonth(),1),r=new Date(e.getFullYear(),e.getMonth()+1,0),i=T(n),a=w(T(r),7);return{startMs:i.getTime(),endMs:a.getTime()}}function D(e,t){if(t===`day`)return e.toLocaleDateString(void 0,{weekday:`long`,year:`numeric`,month:`long`,day:`numeric`});if(t===`week`){let t=T(e),n=w(t,6),r={month:`short`,day:`numeric`};return`${t.toLocaleDateString(void 0,r)} – ${n.toLocaleDateString(void 0,{...r,year:`numeric`})}`}return e.toLocaleDateString(void 0,{month:`long`,year:`numeric`})}function O(e,t,n){return t===`day`?w(e,n):t===`week`?w(e,n*7):new Date(e.getFullYear(),e.getMonth()+n,1)}function k(e,t){if(t===void 0)return e;let n=t.calendars[e.id];return n===void 0?e:{...e,visible:n.visible??e.visible,color:n.color??e.defaultColor}}function A(e){return e.providerAddonId!==void 0&&e.providerAddonId.length>0?e.providerAddonId:e.source===`ha`?`Home Assistant`:e.source}function j(e){if(e.allDay===!0)return`All day`;let t=new Date(e.startMs),n=new Date(e.endMs),r={hour:`2-digit`,minute:`2-digit`};return`${t.toLocaleTimeString([],r)} – ${n.toLocaleTimeString([],r)}`}function M(e){let t=new Date(e.startMs),n=new Date(e.endMs),r={weekday:`short`,year:`numeric`,month:`short`,day:`numeric`};if(e.allDay===!0){let i=C(t),a=w(C(n),-1);return L(i,a)||N(e)?`${t.toLocaleDateString(void 0,r)} · All day`:`${t.toLocaleDateString(void 0,r)} – ${a.toLocaleDateString(void 0,r)} · All day`}let i={hour:`2-digit`,minute:`2-digit`};return L(t,n)?`${t.toLocaleDateString(void 0,r)} · ${t.toLocaleTimeString([],i)} – ${n.toLocaleTimeString([],i)}`:`${t.toLocaleString(void 0,{...r,...i})} – ${n.toLocaleString(void 0,{...r,...i})}`}function N(e){return C(new Date(e.endMs)).getTime()===C(new Date(e.startMs)).getTime()}function P({label:e,children:t}){return n(`div`,{className:`grid grid-cols-[7rem_minmax(0,1fr)] gap-x-3 gap-y-1 text-sm`,children:[o(`dt`,{className:`text-foreground-subtle`,children:e}),o(`dd`,{className:`min-w-0 break-words text-foreground`,children:t})]})}function F({ev:e,calendarName:t,color:r,onClose:i}){return o(g,{open:!0,onOpenChange:e=>!e&&i(),children:n(d,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`calendars-event-detail`,children:[o(p,{children:n(`div`,{className:`flex min-w-0 items-start gap-2.5`,children:[o(`span`,{className:`mt-1.5 h-3 w-3 shrink-0 rounded-full`,style:{backgroundColor:r},"aria-hidden":!0}),o(h,{className:`min-w-0 break-words`,children:e.title})]})}),o(m,{children:n(`dl`,{className:`space-y-3`,children:[o(P,{label:`When`,children:M(e)}),o(P,{label:`Calendar`,children:t}),e.location!==void 0&&e.location.length>0?o(P,{label:`Location`,children:e.location}):null,e.description!==void 0&&e.description.length>0?o(P,{label:`Description`,children:o(`span`,{className:`whitespace-pre-wrap`,children:e.description})}):null]})}),o(_,{children:o(c,{type:`button`,size:`sm`,variant:`secondary`,onClick:i,children:`Close`})})]})})}function I(e,t){let n=t+1440*60*1e3;return e.filter(e=>e.startMs<n&&e.endMs>t)}function L(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function R({mode:e,onChange:t}){return o(`div`,{className:`inline-flex rounded-lg border border-border bg-surface p-0.5`,role:`group`,"aria-label":`Calendar view`,children:[{id:`month`,label:`Month`},{id:`week`,label:`Week`},{id:`day`,label:`Day`}].map(n=>o(`button`,{type:`button`,className:e===n.id?`rounded-md bg-primary px-2.5 py-1 text-xs font-medium text-primary-foreground`:`rounded-md px-2.5 py-1 text-xs font-medium text-foreground-subtle hover:text-foreground`,"aria-pressed":e===n.id,onClick:()=>t(n.id),"data-testid":`calendars-view-${n.id}`,children:n.label},n.id))})}function z({calendars:e,onToggleVisible:t,onColorChange:r,busy:i}){return n(`aside`,{className:`w-full shrink-0 space-y-2 lg:w-56 xl:w-64`,"data-testid":`calendars-legend`,children:[o(`h2`,{className:`text-xs font-medium text-foreground-subtle`,children:`Calendars`}),o(`ul`,{className:`space-y-1`,children:e.map(e=>n(`li`,{className:`flex items-start gap-2 rounded-md px-1.5 py-1.5 hover:bg-surface`,children:[o(`input`,{type:`checkbox`,className:`mt-1 h-3.5 w-3.5 shrink-0 accent-primary`,checked:e.visible,disabled:i,onChange:n=>t(e.id,n.target.checked),"aria-label":`Show ${e.name}`,"data-testid":`calendars-visible-${e.id}`}),o(`input`,{type:`color`,className:`mt-0.5 h-6 w-6 shrink-0 cursor-pointer rounded border border-border bg-transparent p-0`,value:e.color,disabled:i,onChange:t=>r(e.id,t.target.value.toUpperCase()),"aria-label":`Colour for ${e.name}`,"data-testid":`calendars-color-${e.id}`}),n(`div`,{className:`min-w-0 flex-1`,children:[o(`div`,{className:`truncate text-sm font-medium ${e.visible?`text-foreground`:`text-foreground-subtle`}`,children:e.name}),n(`div`,{className:`truncate text-[11px] text-foreground-subtle`,children:[A(e),e.enabled?``:` · unavailable at source`]})]})]},e.id))})]})}function B({ev:e,color:t,compact:r,onSelect:a}){return o(`button`,{type:`button`,className:r?`block w-full truncate rounded px-1 py-0.5 text-left text-[10px] leading-tight text-white hover:brightness-110`:`block w-full rounded-md px-2 py-1.5 text-left text-xs text-white hover:brightness-110`,style:{backgroundColor:t},title:e.title,onClick:()=>a(e),"data-testid":`calendars-event-${e.id}`,children:r?e.title:n(i,{children:[o(`div`,{className:`font-medium`,children:e.title}),o(`div`,{className:`opacity-90`,children:j(e)})]})})}function V({anchor:e,events:t,colorById:r,today:i,onSelectEvent:a}){let{startMs:s,endMs:c}=E(e,`month`),l=[];for(let e=s;e<c;e+=1440*60*1e3)l.push(new Date(e));let u=e.getMonth();return n(`div`,{"data-testid":`calendars-month`,children:[o(`div`,{className:`mb-1 grid grid-cols-7 gap-px`,children:S.map(e=>o(`div`,{className:`px-1 py-1 text-center text-[11px] font-medium text-foreground-subtle`,children:e},e))}),o(`div`,{className:`grid grid-cols-7 gap-px overflow-hidden rounded-lg border border-border bg-border`,children:l.map(e=>{let s=C(e).getTime(),c=I(t,s),l=e.getMonth()!==u,d=L(e,i);return n(`div`,{className:`min-h-[5.5rem] bg-background p-1 ${l?`opacity-45`:``}`,children:[o(`div`,{className:d?`mb-1 inline-flex h-5 w-5 items-center justify-center rounded-full bg-primary text-[11px] font-semibold text-primary-foreground`:`mb-1 text-[11px] font-medium text-foreground-subtle`,children:e.getDate()}),n(`div`,{className:`space-y-0.5`,children:[c.slice(0,3).map(e=>o(B,{ev:e,color:r.get(e.calendarId)??`#64748B`,compact:!0,onSelect:a},e.id)),c.length>3?n(`div`,{className:`text-[10px] text-foreground-subtle`,children:[`+`,c.length-3,` more`]}):null]})]},s)})})]})}function H({anchor:e,events:t,colorById:r,today:i,onSelectEvent:a}){let s=T(e);return o(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-7 sm:gap-px sm:overflow-hidden sm:rounded-lg sm:border sm:border-border sm:bg-border`,"data-testid":`calendars-week`,children:Array.from({length:7},(e,t)=>w(s,t)).map(e=>{let s=C(e).getTime(),c=I(t,s);return n(`div`,{className:`min-h-[8rem] bg-background p-2 sm:min-h-[12rem]`,children:[o(`div`,{className:L(e,i)?`mb-2 text-xs font-semibold text-primary`:`mb-2 text-xs font-medium text-foreground-subtle`,children:e.toLocaleDateString(void 0,{weekday:`short`,day:`numeric`})}),o(`div`,{className:`space-y-1`,children:c.length===0?o(`p`,{className:`text-[11px] text-foreground-subtle`,children:`—`}):c.map(e=>o(B,{ev:e,color:r.get(e.calendarId)??`#64748B`,onSelect:a},e.id))})]},s)})})}function U({anchor:e,events:t,colorById:r,calName:i,onSelectEvent:a}){let s=I(t,C(e).getTime());return s.length===0?o(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-day-empty`,children:`No events on this day.`}):o(`ul`,{className:`divide-y divide-border rounded-lg border border-border`,"data-testid":`calendars-day`,children:s.map(e=>o(`li`,{children:n(`button`,{type:`button`,className:`flex w-full items-start gap-3 px-3 py-3 text-left hover:bg-surface`,onClick:()=>a(e),"data-testid":`calendars-event-${e.id}`,children:[o(`span`,{className:`mt-1 h-2.5 w-2.5 shrink-0 rounded-full`,style:{backgroundColor:r.get(e.calendarId)??`#64748B`}}),n(`div`,{className:`min-w-0`,children:[o(`div`,{className:`font-medium text-sm text-foreground`,children:e.title}),n(`div`,{className:`text-xs text-foreground-subtle`,children:[j(e),` · `,i.get(e.calendarId)??e.calendarId]}),e.location!==void 0&&e.location.length>0?o(`div`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:e.location}):null]})]})},e.id))})}function W(){let t=b(),i=v({}),c=y(),[d,p]=a(`month`),[m,h]=a(()=>C(new Date)),[g,_]=a(null),S=r(()=>C(new Date),[]),w=t.isSuccess,T=i.isSuccess&&i.data!==void 0?i.data:void 0,A=r(()=>!w||t.data===void 0?[]:t.data.map(e=>k(e,T)),[w,t.data,T]),j=r(()=>A.filter(e=>e.visible),[A]),M=r(()=>j.map(e=>e.id),[j]),N=r(()=>E(m,d),[m,d]),P=f({startMs:N.startMs,endMs:N.endMs,calendarIds:[...M]},{enabled:w&&M.length>0}),I=P.data??[],L=r(()=>{let e=new Map;for(let t of A)e.set(t.id,t.color);return e},[A]),B=r(()=>{let e=new Map;for(let t of A)e.set(t.id,t.name);return e},[A]),W=e((e,t)=>{c.mutateAsync({calendarId:e,visible:t}).then(()=>i.refetch())},[i,c]),G=e((e,t)=>{/^#[0-9A-Fa-f]{6}$/.test(t)&&c.mutateAsync({calendarId:e,color:t}).then(()=>i.refetch())},[i,c]),K=e(()=>h(C(new Date)),[]),q=e(()=>h(e=>O(e,d,-1)),[d]),J=e(()=>h(e=>O(e,d,1)),[d]),Y=`inline-flex h-8 w-8 items-center justify-center rounded-lg border border-border bg-surface text-foreground hover:bg-primary/5 disabled:opacity-50`,X;return X=t.isPending?o(`p`,{className:`text-sm text-foreground-subtle`,children:`Loading calendars…`}):t.isError?n(`p`,{className:`text-sm text-destructive`,children:[`Could not list calendars: `,t.error.message]}):A.length===0?o(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-empty-sources`,children:`No calendar sources yet. Connect a calendar-source addon (for example Home Assistant) and wait for it to register calendars.`}):M.length===0?n(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start`,children:[o(z,{calendars:A,onToggleVisible:W,onColorChange:G,busy:c.isPending}),o(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-empty-hidden`,children:`All calendars are hidden. Turn one on in the legend to see events.`})]}):n(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start`,children:[o(z,{calendars:A,onToggleVisible:W,onColorChange:G,busy:c.isPending}),n(`div`,{className:`min-w-0 flex-1 space-y-3`,children:[n(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(R,{mode:d,onChange:p}),n(`div`,{className:`flex items-center gap-1`,children:[o(`button`,{type:`button`,className:Y,onClick:q,"aria-label":`Previous`,"data-testid":`calendars-prev`,children:o(l,{className:`h-4 w-4`})}),o(`button`,{type:`button`,className:`inline-flex items-center rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5`,onClick:K,"data-testid":`calendars-today`,children:`Today`}),o(`button`,{type:`button`,className:Y,onClick:J,"aria-label":`Next`,"data-testid":`calendars-next`,children:o(s,{className:`h-4 w-4`})})]}),o(`span`,{className:`text-sm font-medium text-foreground`,"data-testid":`calendars-period`,children:D(m,d)})]}),P.isPending?o(`p`,{className:`text-sm text-foreground-subtle`,children:`Loading events…`}):P.isError?n(`p`,{className:`text-sm text-destructive`,children:[`Could not list events: `,P.error.message]}):d===`month`?o(V,{anchor:m,events:I,colorById:L,today:S,onSelectEvent:_}):d===`week`?o(H,{anchor:m,events:I,colorById:L,today:S,onSelectEvent:_}):o(U,{anchor:m,events:I,colorById:L,calName:B,onSelectEvent:_})]})]}),n(x,{icon:u,title:`Calendars`,subtitle:`Calendars from connected sources. Used by Calendar events notification rules.`,children:[X,g===null?null:o(F,{ev:g,calendarName:B.get(g.calendarId)??g.calendarId,color:L.get(g.calendarId)??`#64748B`,onClose:()=>_(null)})]})}export{W as CalendarsPage,W as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Q as e,S as t,W as n,a as r,q as i,t as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as s}from"./player-overlays-CrKWnjLj.js";import{Ln as c,Rd as l,bu as u,rd as d,zd as f}from"./src-Bkpo8B0D.js";import{t as p}from"./AdminPage-CiKtOLQm.js";e();var m={detection:`border-green-500`,detector:`border-green-500`,streaming:`border-blue-500`,decode:`border-blue-500`,decoder:`border-blue-500`,recording:`border-orange-500`,recorder:`border-orange-500`,transcoding:`border-purple-500`,transcoder:`border-purple-500`,restream:`border-cyan-500`,restreamer:`border-cyan-500`,storage:`border-yellow-500`,notification:`border-pink-500`,notifier:`border-pink-500`,faces:`border-indigo-500`},h={detection:`bg-green-500/5`,detector:`bg-green-500/5`,streaming:`bg-blue-500/5`,decode:`bg-blue-500/5`,decoder:`bg-blue-500/5`,recording:`bg-orange-500/5`,recorder:`bg-orange-500/5`,transcoding:`bg-purple-500/5`,transcoder:`bg-purple-500/5`,restream:`bg-cyan-500/5`,restreamer:`bg-cyan-500/5`,storage:`bg-yellow-500/5`,notification:`bg-pink-500/5`,notifier:`bg-pink-500/5`,faces:`bg-indigo-500/5`};function g({entry:e,actions:n}){let r=e.name.toLowerCase(),i=m[r]??`border-primary`,a=h[r]??`bg-primary/5`,s=e.providers.find(e=>e.active),c=n?.pendingCapability===e.name;return t(`div`,{className:`rounded-lg border-t-2 border border-border ${i} ${a} p-3 space-y-2`,children:[t(`div`,{className:`flex items-center justify-between gap-2`,children:[t(`span`,{className:`text-xs font-semibold text-foreground capitalize flex items-center gap-1.5`,children:[e.name,c&&o(d,{className:`h-3 w-3 animate-spin text-primary`})]}),o(`span`,{className:`rounded-full px-2 py-0.5 text-[10px] font-medium ${e.mode===`singleton`?`bg-primary/10 text-primary`:`bg-info/10 text-info`}`,children:e.mode})]}),e.mode===`singleton`?o(_,{entry:e,actions:n,activeProvider:s,isPending:c}):o(v,{entry:e,actions:n,isPending:c})]})}function _({entry:e,actions:n,activeProvider:r,isPending:i}){if(!n)return o(`div`,{children:r?t(`div`,{className:`flex items-center gap-1.5 text-[10px] text-foreground`,children:[o(l,{className:`h-3 w-3 text-green-400 shrink-0`}),o(`span`,{className:`font-medium`,children:r.addonName}),o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto`,children:`ACTIVE`})]}):o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No active provider`})});if(e.providers.length===0)return o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});let a=`__inherit__`;return t(`div`,{className:`space-y-2`,children:[o(`div`,{className:`space-y-1`,children:e.providers.map(r=>{let a=r.active;return t(`button`,{type:`button`,disabled:i||a,onClick:()=>n.onSelectSingleton(e.name,r.addonId),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${a?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[o(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${a?`border-green-400 bg-green-400`:`border-border`}`}),o(`span`,{className:`font-medium truncate`,children:r.addonName}),a&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},r.addonId)})}),e.perNode&&e.perNode.length>0&&o(`div`,{className:`space-y-2 pt-1 border-t border-border/40`,children:e.perNode.map(r=>{let s=r.hasOverride&&r.resolvedActive?r.resolvedActive:a,c=[{value:a,label:`Inherit global${r.resolvedActive?` (${r.resolvedActive})`:``}`},...r.providers.map(e=>({value:e,label:e}))],l=t=>{t===a?n.onClearNodeSingleton(e.name,r.nodeId):n.onSelectNodeSingleton(e.name,r.nodeId,t)},u=i;return t(`div`,{className:`space-y-0.5`,children:[t(`div`,{className:`text-[9px] font-semibold uppercase tracking-widest text-foreground-subtle/60 px-1.5`,children:[r.nodeId,r.hasOverride&&o(`span`,{className:`ml-1.5 rounded-full bg-primary/10 text-primary px-1 py-0.5 normal-case tracking-normal font-medium`,children:`override`})]}),c.map(e=>{let n=s===e.value;return t(`button`,{type:`button`,disabled:u||n,onClick:()=>l(e.value),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${n?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[o(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${n?`border-green-400 bg-green-400`:`border-border`}`}),o(`span`,{className:`font-medium truncate`,children:e.label}),n&&e.value!==a&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},e.value)})]},r.nodeId)})})]})}function v({entry:e,actions:n,isPending:r}){if(e.providers.length===0)return o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});if(!n)return o(`div`,{className:`space-y-1`,children:e.providers.map(e=>t(`div`,{className:`flex items-center justify-between gap-2 text-[10px]`,children:[o(`span`,{className:`text-foreground-subtle`,children:e.addonName}),e.active&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium`,children:`ACTIVE`})]},e.addonId))});let i=e.providers.filter(e=>e.active).map(e=>e.addonId),a=(t,r)=>{let a=r?[...new Set([...i,t])]:i.filter(e=>e!==t);n.onToggleCollection(e.name,a)};return o(`div`,{className:`space-y-1`,children:e.providers.map(e=>t(`label`,{className:`flex items-center justify-between gap-2 text-[10px] rounded px-1.5 py-1 transition-colors ${r?`opacity-50`:`hover:bg-surface-hover cursor-pointer`}`,children:[t(`span`,{className:`flex items-center gap-1.5 min-w-0`,children:[o(`input`,{type:`checkbox`,checked:e.active,disabled:r,onChange:t=>a(e.addonId,t.target.checked),className:`h-3 w-3 accent-green-500 shrink-0`}),o(`span`,{className:`text-foreground truncate`,children:e.addonName})]}),e.active&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium shrink-0`,children:`ACTIVE`})]},e.addonId))})}function y({capabilities:e,actions:t}){return e.length===0?o(`div`,{className:`text-xs text-foreground-subtle text-center py-8`,children:`No capabilities registered`}):o(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3`,children:e.map(e=>o(g,{entry:e,actions:t},e.name))})}var b=[`capabilities`,`listCapabilities`];function x(e){return e===`singleton`||e===`collection`}function S(e){let t=e.indexOf(`@`);return t===-1?`${e} (hub)`:`${e.slice(0,t)} (${e.slice(t+1)})`}function C(e,t){return{name:e.name,mode:t,providers:e.providers.map(n=>({addonId:n,addonName:S(n),active:t===`singleton`?e.activeProvider===n:!e.disabledProviders.includes(n)})),...t===`singleton`&&e.perNode?{perNode:e.perNode}:{}}}function w(){let e=s(),[d,m]=i(null),[h,g]=i(null),_=r({queryKey:b,queryFn:()=>e.trpcClient.capabilities.listCapabilities.query()}),v=n(()=>{let e=(_.data??[]).flatMap(e=>x(e.mode)?[C(e,e.mode)]:[]),t=e.filter(e=>e.mode===`singleton`).toSorted((e,t)=>e.name.localeCompare(t.name)),n=e.filter(e=>e.mode===`collection`).toSorted((e,t)=>e.name.localeCompare(t.name));return[...t,...n]},[_.data]),S=n(()=>v.filter(e=>e.mode===`singleton`),[v]),w=n(()=>v.filter(e=>e.mode===`collection`),[v]),T=a({mutationFn:t=>e.trpcClient.capabilities.setActiveSingleton.mutate({capability:t.capName,addonId:t.addonId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} → ${t.addonId} is now active.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),E=a({mutationFn:t=>e.trpcClient.capabilities.setActiveSingleton.mutate({capability:t.capName,addonId:t.addonId,nodeId:t.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} → ${t.addonId}.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),D=a({mutationFn:t=>e.trpcClient.capabilities.clearSingletonNodeOverride.mutate({capability:t.capName,nodeId:t.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} now inherits the global default.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to clear ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),O=a({mutationFn:t=>e.trpcClient.capabilities.setCollectionEnabledProviders.mutate({capability:t.capName,enabledAddonIds:[...t.enabledAddonIds]}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName}: ${t.enabledAddonIds.length} provider(s) enabled.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to update ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),k={onSelectSingleton:(e,t)=>T.mutate({capName:e,addonId:t}),onSelectNodeSingleton:(e,t,n)=>E.mutate({capName:e,nodeId:t,addonId:n}),onClearNodeSingleton:(e,t)=>D.mutate({capName:e,nodeId:t}),onToggleCollection:(e,t)=>O.mutate({capName:e,enabledAddonIds:t}),pendingCapability:d};return t(p,{icon:u,title:`Capabilities`,subtitle:`Choose which provider is active for each system capability. Singleton caps pick exactly one provider; collection caps enable a set.`,children:[h&&t(`div`,{className:`flex items-center gap-2 rounded-md border px-3 py-2 text-xs ${h.kind===`success`?`border-green-500/30 bg-green-500/10 text-green-700 dark:text-green-300`:`border-danger/40 bg-danger/10 text-danger`}`,children:[h.kind===`success`?o(l,{className:`h-3.5 w-3.5 shrink-0`}):o(f,{className:`h-3.5 w-3.5 shrink-0`}),o(`span`,{children:h.message})]}),_.isLoading&&o(`div`,{className:`flex items-center justify-center py-16`,children:o(`div`,{className:`animate-spin h-6 w-6 border-2 border-primary border-t-transparent rounded-full`})}),_.isError&&!_.isLoading&&o(c,{title:`Failed to load capabilities`,message:_.error instanceof Error?_.error.message:`Unknown error`,onRetry:()=>void _.refetch()}),!_.isLoading&&!_.isError&&v.length===0&&o(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No capabilities registered.`}),!_.isLoading&&!_.isError&&v.length>0&&t(`div`,{className:`space-y-6`,children:[S.length>0&&t(`section`,{className:`space-y-2`,children:[o(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Singleton — pick one provider`}),o(y,{capabilities:S,actions:k})]}),w.length>0&&t(`section`,{className:`space-y-2`,children:[o(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Collection — enable a set`}),o(y,{capabilities:w,actions:k})]})]})]})}export{w as CapabilitiesPage,w as default};
|
|
1
|
+
import{Q as e,S as t,W as n,a as r,q as i,t as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as s}from"./player-overlays-CHWCYkGf.js";import{Ln as c,Rd as l,bu as u,rd as d,zd as f}from"./src-Crb8RLzq.js";import{t as p}from"./AdminPage-BSFohA3i.js";e();var m={detection:`border-green-500`,detector:`border-green-500`,streaming:`border-blue-500`,decode:`border-blue-500`,decoder:`border-blue-500`,recording:`border-orange-500`,recorder:`border-orange-500`,transcoding:`border-purple-500`,transcoder:`border-purple-500`,restream:`border-cyan-500`,restreamer:`border-cyan-500`,storage:`border-yellow-500`,notification:`border-pink-500`,notifier:`border-pink-500`,faces:`border-indigo-500`},h={detection:`bg-green-500/5`,detector:`bg-green-500/5`,streaming:`bg-blue-500/5`,decode:`bg-blue-500/5`,decoder:`bg-blue-500/5`,recording:`bg-orange-500/5`,recorder:`bg-orange-500/5`,transcoding:`bg-purple-500/5`,transcoder:`bg-purple-500/5`,restream:`bg-cyan-500/5`,restreamer:`bg-cyan-500/5`,storage:`bg-yellow-500/5`,notification:`bg-pink-500/5`,notifier:`bg-pink-500/5`,faces:`bg-indigo-500/5`};function g({entry:e,actions:n}){let r=e.name.toLowerCase(),i=m[r]??`border-primary`,a=h[r]??`bg-primary/5`,s=e.providers.find(e=>e.active),c=n?.pendingCapability===e.name;return t(`div`,{className:`rounded-lg border-t-2 border border-border ${i} ${a} p-3 space-y-2`,children:[t(`div`,{className:`flex items-center justify-between gap-2`,children:[t(`span`,{className:`text-xs font-semibold text-foreground capitalize flex items-center gap-1.5`,children:[e.name,c&&o(d,{className:`h-3 w-3 animate-spin text-primary`})]}),o(`span`,{className:`rounded-full px-2 py-0.5 text-[10px] font-medium ${e.mode===`singleton`?`bg-primary/10 text-primary`:`bg-info/10 text-info`}`,children:e.mode})]}),e.mode===`singleton`?o(_,{entry:e,actions:n,activeProvider:s,isPending:c}):o(v,{entry:e,actions:n,isPending:c})]})}function _({entry:e,actions:n,activeProvider:r,isPending:i}){if(!n)return o(`div`,{children:r?t(`div`,{className:`flex items-center gap-1.5 text-[10px] text-foreground`,children:[o(l,{className:`h-3 w-3 text-green-400 shrink-0`}),o(`span`,{className:`font-medium`,children:r.addonName}),o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto`,children:`ACTIVE`})]}):o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No active provider`})});if(e.providers.length===0)return o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});let a=`__inherit__`;return t(`div`,{className:`space-y-2`,children:[o(`div`,{className:`space-y-1`,children:e.providers.map(r=>{let a=r.active;return t(`button`,{type:`button`,disabled:i||a,onClick:()=>n.onSelectSingleton(e.name,r.addonId),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${a?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[o(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${a?`border-green-400 bg-green-400`:`border-border`}`}),o(`span`,{className:`font-medium truncate`,children:r.addonName}),a&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},r.addonId)})}),e.perNode&&e.perNode.length>0&&o(`div`,{className:`space-y-2 pt-1 border-t border-border/40`,children:e.perNode.map(r=>{let s=r.hasOverride&&r.resolvedActive?r.resolvedActive:a,c=[{value:a,label:`Inherit global${r.resolvedActive?` (${r.resolvedActive})`:``}`},...r.providers.map(e=>({value:e,label:e}))],l=t=>{t===a?n.onClearNodeSingleton(e.name,r.nodeId):n.onSelectNodeSingleton(e.name,r.nodeId,t)},u=i;return t(`div`,{className:`space-y-0.5`,children:[t(`div`,{className:`text-[9px] font-semibold uppercase tracking-widest text-foreground-subtle/60 px-1.5`,children:[r.nodeId,r.hasOverride&&o(`span`,{className:`ml-1.5 rounded-full bg-primary/10 text-primary px-1 py-0.5 normal-case tracking-normal font-medium`,children:`override`})]}),c.map(e=>{let n=s===e.value;return t(`button`,{type:`button`,disabled:u||n,onClick:()=>l(e.value),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${n?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[o(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${n?`border-green-400 bg-green-400`:`border-border`}`}),o(`span`,{className:`font-medium truncate`,children:e.label}),n&&e.value!==a&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},e.value)})]},r.nodeId)})})]})}function v({entry:e,actions:n,isPending:r}){if(e.providers.length===0)return o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});if(!n)return o(`div`,{className:`space-y-1`,children:e.providers.map(e=>t(`div`,{className:`flex items-center justify-between gap-2 text-[10px]`,children:[o(`span`,{className:`text-foreground-subtle`,children:e.addonName}),e.active&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium`,children:`ACTIVE`})]},e.addonId))});let i=e.providers.filter(e=>e.active).map(e=>e.addonId),a=(t,r)=>{let a=r?[...new Set([...i,t])]:i.filter(e=>e!==t);n.onToggleCollection(e.name,a)};return o(`div`,{className:`space-y-1`,children:e.providers.map(e=>t(`label`,{className:`flex items-center justify-between gap-2 text-[10px] rounded px-1.5 py-1 transition-colors ${r?`opacity-50`:`hover:bg-surface-hover cursor-pointer`}`,children:[t(`span`,{className:`flex items-center gap-1.5 min-w-0`,children:[o(`input`,{type:`checkbox`,checked:e.active,disabled:r,onChange:t=>a(e.addonId,t.target.checked),className:`h-3 w-3 accent-green-500 shrink-0`}),o(`span`,{className:`text-foreground truncate`,children:e.addonName})]}),e.active&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium shrink-0`,children:`ACTIVE`})]},e.addonId))})}function y({capabilities:e,actions:t}){return e.length===0?o(`div`,{className:`text-xs text-foreground-subtle text-center py-8`,children:`No capabilities registered`}):o(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3`,children:e.map(e=>o(g,{entry:e,actions:t},e.name))})}var b=[`capabilities`,`listCapabilities`];function x(e){return e===`singleton`||e===`collection`}function S(e){let t=e.indexOf(`@`);return t===-1?`${e} (hub)`:`${e.slice(0,t)} (${e.slice(t+1)})`}function C(e,t){return{name:e.name,mode:t,providers:e.providers.map(n=>({addonId:n,addonName:S(n),active:t===`singleton`?e.activeProvider===n:!e.disabledProviders.includes(n)})),...t===`singleton`&&e.perNode?{perNode:e.perNode}:{}}}function w(){let e=s(),[d,m]=i(null),[h,g]=i(null),_=r({queryKey:b,queryFn:()=>e.trpcClient.capabilities.listCapabilities.query()}),v=n(()=>{let e=(_.data??[]).flatMap(e=>x(e.mode)?[C(e,e.mode)]:[]),t=e.filter(e=>e.mode===`singleton`).toSorted((e,t)=>e.name.localeCompare(t.name)),n=e.filter(e=>e.mode===`collection`).toSorted((e,t)=>e.name.localeCompare(t.name));return[...t,...n]},[_.data]),S=n(()=>v.filter(e=>e.mode===`singleton`),[v]),w=n(()=>v.filter(e=>e.mode===`collection`),[v]),T=a({mutationFn:t=>e.trpcClient.capabilities.setActiveSingleton.mutate({capability:t.capName,addonId:t.addonId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} → ${t.addonId} is now active.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),E=a({mutationFn:t=>e.trpcClient.capabilities.setActiveSingleton.mutate({capability:t.capName,addonId:t.addonId,nodeId:t.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} → ${t.addonId}.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),D=a({mutationFn:t=>e.trpcClient.capabilities.clearSingletonNodeOverride.mutate({capability:t.capName,nodeId:t.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} now inherits the global default.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to clear ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),O=a({mutationFn:t=>e.trpcClient.capabilities.setCollectionEnabledProviders.mutate({capability:t.capName,enabledAddonIds:[...t.enabledAddonIds]}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName}: ${t.enabledAddonIds.length} provider(s) enabled.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to update ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),k={onSelectSingleton:(e,t)=>T.mutate({capName:e,addonId:t}),onSelectNodeSingleton:(e,t,n)=>E.mutate({capName:e,nodeId:t,addonId:n}),onClearNodeSingleton:(e,t)=>D.mutate({capName:e,nodeId:t}),onToggleCollection:(e,t)=>O.mutate({capName:e,enabledAddonIds:t}),pendingCapability:d};return t(p,{icon:u,title:`Capabilities`,subtitle:`Choose which provider is active for each system capability. Singleton caps pick exactly one provider; collection caps enable a set.`,children:[h&&t(`div`,{className:`flex items-center gap-2 rounded-md border px-3 py-2 text-xs ${h.kind===`success`?`border-green-500/30 bg-green-500/10 text-green-700 dark:text-green-300`:`border-danger/40 bg-danger/10 text-danger`}`,children:[h.kind===`success`?o(l,{className:`h-3.5 w-3.5 shrink-0`}):o(f,{className:`h-3.5 w-3.5 shrink-0`}),o(`span`,{children:h.message})]}),_.isLoading&&o(`div`,{className:`flex items-center justify-center py-16`,children:o(`div`,{className:`animate-spin h-6 w-6 border-2 border-primary border-t-transparent rounded-full`})}),_.isError&&!_.isLoading&&o(c,{title:`Failed to load capabilities`,message:_.error instanceof Error?_.error.message:`Unknown error`,onRetry:()=>void _.refetch()}),!_.isLoading&&!_.isError&&v.length===0&&o(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No capabilities registered.`}),!_.isLoading&&!_.isError&&v.length>0&&t(`div`,{className:`space-y-6`,children:[S.length>0&&t(`section`,{className:`space-y-2`,children:[o(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Singleton — pick one provider`}),o(y,{capabilities:S,actions:k})]}),w.length>0&&t(`section`,{className:`space-y-2`,children:[o(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Collection — enable a set`}),o(y,{capabilities:w,actions:k})]})]})]})}export{w as CapabilitiesPage,w as default};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,V as i,W as a,b as o,o as s,q as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as d,gt as f,ht as p,st as m,vt as h}from"./player-overlays-CrKWnjLj.js";import{Ao as g,As as _,Au as v,Bl as y,Bo as b,Gu as x,Hd as S,Iu as C,Kl as w,Lo as T,Lu as E,Mc as ee,Nc as te,Od as D,Pc as ne,Ro as re,Rt as O,Ru as ie,St as ae,Vl as k,Zn as oe,cf as A,cr as se,da as ce,dr as le,ec as ue,jc as de,jo as fe,ju as pe,ku as me,lr as he,qd as ge,rd as j,su as _e,tl as ve,ur as ye,xt as be,zo as xe,zt as Se}from"./src-Bkpo8B0D.js";import{t as Ce}from"./hard-drive-download-DvX0zc41.js";import{Wr as we}from"./client-DWiaUxRQ.js";import{t as M}from"./useTranslation-Bc5yH9V9.js";import{t as Te}from"./NodeAddonsSettingsPanel-BgxOJU3d.js";import{t as N}from"./format-size-DIxKXxtj.js";import{n as Ee,r as De,t as Oe}from"./useNodeUrlSelection-NjZtQ6mH.js";var ke=h(`memory-stick`,[[`path`,{d:`M12 12v-2`,key:`fwoke6`}],[`path`,{d:`M12 18v-2`,key:`qj6yno`}],[`path`,{d:`M16 12v-2`,key:`heuere`}],[`path`,{d:`M16 18v-2`,key:`s1ct0w`}],[`path`,{d:`M2 11h1.5`,key:`15p63e`}],[`path`,{d:`M20 18v-2`,key:`12ehxp`}],[`path`,{d:`M20.5 11H22`,key:`khsy7a`}],[`path`,{d:`M4 18v-2`,key:`1c3oqr`}],[`path`,{d:`M8 12v-2`,key:`1mwtfd`}],[`path`,{d:`M8 18v-2`,key:`qcmpov`}],[`rect`,{x:`2`,y:`6`,width:`20`,height:`10`,rx:`2`,key:`1qcswk`}]]);n();function Ae(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m`;let n=Math.floor(t/60);return n<24?`${n}h ${t%60}m`:`${Math.floor(n/24)}d ${n%24}h`}function je({state:e}){return l(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e===`running`?`bg-success/10 text-success`:e===`crashed`||e===`failed`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e})}var Me=[`trace`,`debug`,`info`,`warn`,`error`];function Ne({proc:e,nodeId:t,defaultExpanded:n,activePanel:i,onTogglePanel:a}){let o=e.services??[],s=o.length===1,[u,d]=c(s||n),[m,h]=c(null),[g,_]=c(`info`),v=e.name.includes(`(core)`),y=re(),x=xe(),S=b(),w=async e=>{h(e);try{await y.mutateAsync({nodeId:t,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{h(null)}},T=async()=>{h(e.name);try{await x.mutateAsync({nodeId:t,processName:e.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{h(null)}},E=async n=>{let r=`${t}/${e.name}`;try{await S.mutateAsync({nodeId:r,level:n}),_(n)}catch(e){console.error(`Failed to set log level:`,e)}};return r(`div`,{className:`border border-border/50 rounded-lg overflow-hidden`,children:[r(`div`,{role:s?void 0:`button`,tabIndex:s?void 0:0,onClick:s?void 0:()=>d(!u),onKeyDown:s?void 0:e=>{(e.key===`Enter`||e.key===` `)&&d(!u)},className:`flex items-center gap-2 w-full px-3 py-2 bg-muted/20 transition-colors text-left select-none ${s?``:`hover:bg-muted/40 cursor-pointer`}`,children:[s?l(`span`,{className:`h-3 w-3 shrink-0`}):l(u?f:p,{className:`h-3 w-3 text-muted-foreground shrink-0`}),v?l(me,{className:`h-3.5 w-3.5 text-primary shrink-0`}):l(ge,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),l(`span`,{className:`text-xs font-semibold flex-1`,children:e.name}),r(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[`PID `,e.pid]}),l(je,{state:e.state}),r(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[e.cpuPercent,`% CPU`]}),l(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:N(e.memoryRss)}),l(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:Ae(e.uptimeSeconds)}),!v&&r(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[r(se,{children:[l(le,{className:`text-[9px] px-1.5 py-0.5 rounded border border-border text-muted-foreground hover:text-foreground hover:bg-muted transition-colors font-mono`,title:`Set log level`,children:g}),l(he,{align:`end`,className:`min-w-[70px] py-0.5`,children:Me.map(e=>l(ye,{onClick:()=>E(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===g?`text-primary font-semibold`:``}`,children:e},e))})]}),l(`button`,{onClick:T,disabled:m===e.name,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart process`,children:l(C,{className:`h-3 w-3 ${m===e.name?`animate-spin`:``}`})})]})]}),u&&o.length>0&&l(`div`,{className:`divide-y divide-border/30`,children:o.map(e=>r(`div`,{children:[r(`div`,{className:`flex items-center gap-2 px-3 py-1.5 pl-9 hover:bg-muted/10 transition-colors`,children:[l(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`running`?`bg-success`:`bg-muted-foreground/30`}`}),l(`span`,{className:`text-xs font-medium flex-1 min-w-0 truncate`,children:e.addonId}),e.capabilities.length>0&&r(`div`,{className:`flex gap-1 flex-shrink-0`,children:[e.capabilities.slice(0,3).map(e=>l(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400 truncate max-w-[80px]`,children:e},e)),e.capabilities.length>3&&r(`span`,{className:`text-[9px] text-muted-foreground`,children:[`+`,e.capabilities.length-3]})]}),r(`div`,{className:`flex items-center gap-1 shrink-0`,children:[l(`button`,{onClick:()=>a(e.addonId,`logs`),className:`p-0.5 rounded transition-colors ${i?.addonId===e.addonId&&i.type===`logs`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show logs for ${e.addonId}`,children:l(pe,{className:`h-3 w-3`})}),l(`button`,{onClick:()=>a(e.addonId,`events`),className:`p-0.5 rounded transition-colors ${i?.addonId===e.addonId&&i.type===`events`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show events for ${e.addonId}`,children:l(ie,{className:`h-3 w-3`})}),l(`button`,{onClick:()=>w(e.addonId),disabled:m===e.addonId,className:`p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.addonId}`,children:l(C,{className:`h-3 w-3 ${m===e.addonId?`animate-spin`:``}`})})]})]}),i?.addonId===e.addonId&&i.type===`logs`&&l(`div`,{className:`border-t border-border/40 bg-muted/5`,children:l(ae,{addonId:e.addonId,agentId:t,maxHeight:`max-h-48`,showFilters:!1,onClose:()=>a(e.addonId,`logs`)})}),i?.addonId===e.addonId&&i.type===`events`&&l(`div`,{className:`border-t border-border/40 bg-muted/5`,children:l(be,{addonId:e.addonId,category:`addon.*`,maxHeight:`max-h-48`,onClose:()=>a(e.addonId,`events`)})})]},e.addonId))}),u&&o.length===0&&l(`div`,{className:`px-3 py-2 pl-9 text-[10px] text-muted-foreground`,children:`No services`})]})}function Pe({nodeId:e,processes:t}){let[n,r]=c(null),i=(e,t)=>{r(n=>n?.addonId===e&&n.type===t?null:{addonId:e,type:t})};return t.length===0?l(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No processes on this node`}):l(`div`,{className:`space-y-2 py-1`,children:t.map((t,r)=>l(Ne,{proc:t,nodeId:e,defaultExpanded:r===0,activePanel:n,onTogglePanel:i},t.name))})}var Fe={system:0,managed:1,root:2};n();function Ie(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m ${e%60}s`:e<86400?`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`:`${Math.floor(e/86400)}d ${Math.floor(e%86400/3600)}h`}function Le(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function Re({nodeId:e}){let t=s(),n=k(`metrics.node-processes-snapshot`,t=>t.nodeId===e),{data:i}=fe({nodeId:e}),o=n?.processes??i,c=a(()=>o?[...o]:[],[o]),u=a(()=>[{key:`classification`,header:`Class`,sortValue:e=>Fe[e.classification],render:e=>l(`span`,{className:`inline-block rounded-full px-1.5 py-0.5 text-[10px] font-medium ${e.classification===`root`?`bg-sky-500/20 text-sky-400`:e.classification===`system`?`bg-foreground-subtle/20 text-foreground-subtle`:`bg-success/20 text-success`}`,children:e.classification})},{key:`pid`,header:`PID`,align:`right`,sortValue:e=>e.pid,render:e=>l(`span`,{className:`font-mono`,children:e.pid})},{key:`ppid`,header:`PPID`,align:`right`,sortValue:e=>e.ppid,render:e=>l(`span`,{className:`font-mono text-foreground-subtle`,children:e.ppid})},{key:`addonId`,header:`Addon`,sortValue:e=>e.addonId,render:e=>l(`span`,{className:`text-foreground-subtle text-[11px]`,children:e.addonId??`—`})},{key:`command`,header:`Command`,nowrap:!1,render:e=>l(`span`,{className:`font-mono text-[10px] text-foreground-subtle break-all`,children:Le(e.command)})},{key:`cpuPercent`,header:`CPU%`,align:`right`,sortValue:e=>e.cpuPercent,render:e=>e.cpuPercent.toFixed(1)},{key:`memoryRssBytes`,header:`RSS`,align:`right`,sortValue:e=>e.memoryRssBytes,render:e=>N(e.memoryRssBytes)},{key:`uptimeSec`,header:`Uptime`,align:`right`,sortValue:e=>e.uptimeSec,render:e=>l(`span`,{className:`text-foreground-subtle`,children:Ie(e.uptimeSec)})}],[]);return r(`div`,{className:`space-y-4`,children:[l(`div`,{className:`flex items-start justify-end gap-4`,children:r(`button`,{type:`button`,onClick:()=>t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}),className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[l(E,{className:`h-3 w-3`}),` Refresh`]})}),l(O,{columns:u,rows:c,rowKey:e=>e.pid,minWidthPx:880,mobileMode:`scroll`,maxBodyHeight:Se,emptyMessage:`Scanning…`})]})}var P={width:320,height:64},ze=.8,F=Math.ceil(8*ze-3)+1,I=P.width+34,L=P.height+F+1+11,Be=F+P.height+1+3+Math.ceil(8*ze),Ve=[1,2,5,10],He=[1,2,4,8,16,32,64,128,256,512,1024],Ue=[1,1.5,2,2.5,3,4,5],R=[4,3,5,2],We=1e-9;function Ge(e,t){if(!Number.isFinite(e)||e<=0)return!1;if(t===`bytes`){if(!Number.isInteger(e))return!1;let t=e/1024**Math.floor(Math.log(e)/Math.log(1024));return Ue.some(e=>Math.abs(t-e)<We)}let n=e/10**Math.floor(Math.log10(e));return Ue.some(e=>Math.abs(n-e)<We)}function Ke(e,t,n){let r=0;for(let t of e)t!==null&&t>r&&(r=t);if(r<=t)return t;if(n===`bytes`){let e=1024**Math.floor(Math.log(r)/Math.log(1024));for(let t of He){let n=t*e;if(n>=r)return n}return 1024*e}let i=10**Math.floor(Math.log10(r));for(let e of Ve){let t=e*i;if(t>=r)return t}return 10*i}function z(e,t){if(!Number.isFinite(e)||e<=0)return[];let n=R.find(n=>Ge(e/n,t))??R[R.length-1],r=e/n,i=[];for(let e=1;e<=n;e++)i.push(r*e);return i}var qe=2.5;function B(e){return e*qe}function V(e,t,n,r){if(e.length===0)return[];let i=e[0].atMs,a=e.at(-1).atMs-i,o=n<=0?1:n,s=r!==void 0&&r>0?r:null;return e.map((r,c)=>{let l=a>0?(r.atMs-i)/a*t.width:c/Math.max(1,e.length-1)*t.width,u=c>0?e[c-1]:void 0;return{x:l,y:r.value===null?null:t.height-Math.min(r.value,n)/o*t.height,gapBefore:s!==null&&u!==void 0&&r.atMs-u.atMs>s}})}function H(e){let t=[],n=!1;for(let r of e){if(r.y===null){n=!1;continue}r.gapBefore&&(n=!1),t.push(`${n?`L`:`M`}${r.x.toFixed(1)},${r.y.toFixed(1)}`),n=!0}return t.join(` `)}function U(e,t){let n=[],r=[],i=()=>{if(r.length<2){r=[];return}let e=r.map((e,t)=>`${t===0?`M`:`L`}${e.x.toFixed(1)},${e.top.toFixed(1)}`),t=[...r].reverse().map(e=>`L${e.x.toFixed(1)},${e.bottom.toFixed(1)}`);n.push(`${e.join(` `)} ${t.join(` `)} Z`),r=[]};for(let n=0;n<e.length;n++){let a=e[n],o=t[n];if(!a||!o||a.y===null||o.y===null){i();continue}(a.gapBefore||o.gapBefore)&&i(),r.push({x:a.x,top:a.y,bottom:o.y})}return i(),n.join(` `)}function W(e,t,n=3){if(e.length<2||n<2)return[];let r=e[0].atMs,i=e.at(-1).atMs-r;if(i<=0)return[];let a=[];for(let e=0;e<n;e++){let o=e/(n-1);a.push({atMs:r+i*o,x:o*t.width,anchor:e===0?`start`:e===n-1?`end`:`middle`})}return a}function G(e){return e.length<2?0:Math.max(0,e.at(-1).atMs-e[0].atMs)}function Je(e){let t=[];for(let n=1;n<e.length;n++){let r=e[n];r.gapBefore&&t.push({fromX:e[n-1].x,toX:r.x})}return t}function Ye(e,t){if(e.length===0)return null;let n=0,r=1/0;for(let i=0;i<e.length;i++){let a=Math.abs(e[i].x-t);a<r&&(r=a,n=i)}return n}n();var K={main:`var(--load-series-main)`,gc:`var(--load-series-gc)`},Xe=`
|
|
1
|
+
import{I as e,K as t,Q as n,S as r,V as i,W as a,b as o,o as s,q as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as d,gt as f,ht as p,st as m,vt as h}from"./player-overlays-CHWCYkGf.js";import{Ao as g,As as _,Au as v,Bl as y,Bo as b,Gu as x,Hd as S,Iu as C,Kl as w,Lo as T,Lu as E,Mc as ee,Nc as te,Od as D,Pc as ne,Ro as re,Rt as O,Ru as ie,St as ae,Vl as k,Zn as oe,cf as A,cr as se,da as ce,dr as le,ec as ue,jc as de,jo as fe,ju as pe,ku as me,lr as he,qd as ge,rd as j,su as _e,tl as ve,ur as ye,xt as be,zo as xe,zt as Se}from"./src-Crb8RLzq.js";import{t as Ce}from"./hard-drive-download-CaBI4JJt.js";import{Wr as we}from"./client-CxHFB-xR.js";import{t as M}from"./useTranslation-Bc5yH9V9.js";import{t as Te}from"./NodeAddonsSettingsPanel-2ImNi4l_.js";import{t as N}from"./format-size-DIxKXxtj.js";import{n as Ee,r as De,t as Oe}from"./useNodeUrlSelection-BSYJnQKG.js";var ke=h(`memory-stick`,[[`path`,{d:`M12 12v-2`,key:`fwoke6`}],[`path`,{d:`M12 18v-2`,key:`qj6yno`}],[`path`,{d:`M16 12v-2`,key:`heuere`}],[`path`,{d:`M16 18v-2`,key:`s1ct0w`}],[`path`,{d:`M2 11h1.5`,key:`15p63e`}],[`path`,{d:`M20 18v-2`,key:`12ehxp`}],[`path`,{d:`M20.5 11H22`,key:`khsy7a`}],[`path`,{d:`M4 18v-2`,key:`1c3oqr`}],[`path`,{d:`M8 12v-2`,key:`1mwtfd`}],[`path`,{d:`M8 18v-2`,key:`qcmpov`}],[`rect`,{x:`2`,y:`6`,width:`20`,height:`10`,rx:`2`,key:`1qcswk`}]]);n();function Ae(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m`;let n=Math.floor(t/60);return n<24?`${n}h ${t%60}m`:`${Math.floor(n/24)}d ${n%24}h`}function je({state:e}){return l(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e===`running`?`bg-success/10 text-success`:e===`crashed`||e===`failed`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e})}var Me=[`trace`,`debug`,`info`,`warn`,`error`];function Ne({proc:e,nodeId:t,defaultExpanded:n,activePanel:i,onTogglePanel:a}){let o=e.services??[],s=o.length===1,[u,d]=c(s||n),[m,h]=c(null),[g,_]=c(`info`),v=e.name.includes(`(core)`),y=re(),x=xe(),S=b(),w=async e=>{h(e);try{await y.mutateAsync({nodeId:t,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{h(null)}},T=async()=>{h(e.name);try{await x.mutateAsync({nodeId:t,processName:e.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{h(null)}},E=async n=>{let r=`${t}/${e.name}`;try{await S.mutateAsync({nodeId:r,level:n}),_(n)}catch(e){console.error(`Failed to set log level:`,e)}};return r(`div`,{className:`border border-border/50 rounded-lg overflow-hidden`,children:[r(`div`,{role:s?void 0:`button`,tabIndex:s?void 0:0,onClick:s?void 0:()=>d(!u),onKeyDown:s?void 0:e=>{(e.key===`Enter`||e.key===` `)&&d(!u)},className:`flex items-center gap-2 w-full px-3 py-2 bg-muted/20 transition-colors text-left select-none ${s?``:`hover:bg-muted/40 cursor-pointer`}`,children:[s?l(`span`,{className:`h-3 w-3 shrink-0`}):l(u?f:p,{className:`h-3 w-3 text-muted-foreground shrink-0`}),v?l(me,{className:`h-3.5 w-3.5 text-primary shrink-0`}):l(ge,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),l(`span`,{className:`text-xs font-semibold flex-1`,children:e.name}),r(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[`PID `,e.pid]}),l(je,{state:e.state}),r(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[e.cpuPercent,`% CPU`]}),l(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:N(e.memoryRss)}),l(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:Ae(e.uptimeSeconds)}),!v&&r(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[r(se,{children:[l(le,{className:`text-[9px] px-1.5 py-0.5 rounded border border-border text-muted-foreground hover:text-foreground hover:bg-muted transition-colors font-mono`,title:`Set log level`,children:g}),l(he,{align:`end`,className:`min-w-[70px] py-0.5`,children:Me.map(e=>l(ye,{onClick:()=>E(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===g?`text-primary font-semibold`:``}`,children:e},e))})]}),l(`button`,{onClick:T,disabled:m===e.name,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart process`,children:l(C,{className:`h-3 w-3 ${m===e.name?`animate-spin`:``}`})})]})]}),u&&o.length>0&&l(`div`,{className:`divide-y divide-border/30`,children:o.map(e=>r(`div`,{children:[r(`div`,{className:`flex items-center gap-2 px-3 py-1.5 pl-9 hover:bg-muted/10 transition-colors`,children:[l(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`running`?`bg-success`:`bg-muted-foreground/30`}`}),l(`span`,{className:`text-xs font-medium flex-1 min-w-0 truncate`,children:e.addonId}),e.capabilities.length>0&&r(`div`,{className:`flex gap-1 flex-shrink-0`,children:[e.capabilities.slice(0,3).map(e=>l(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400 truncate max-w-[80px]`,children:e},e)),e.capabilities.length>3&&r(`span`,{className:`text-[9px] text-muted-foreground`,children:[`+`,e.capabilities.length-3]})]}),r(`div`,{className:`flex items-center gap-1 shrink-0`,children:[l(`button`,{onClick:()=>a(e.addonId,`logs`),className:`p-0.5 rounded transition-colors ${i?.addonId===e.addonId&&i.type===`logs`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show logs for ${e.addonId}`,children:l(pe,{className:`h-3 w-3`})}),l(`button`,{onClick:()=>a(e.addonId,`events`),className:`p-0.5 rounded transition-colors ${i?.addonId===e.addonId&&i.type===`events`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show events for ${e.addonId}`,children:l(ie,{className:`h-3 w-3`})}),l(`button`,{onClick:()=>w(e.addonId),disabled:m===e.addonId,className:`p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.addonId}`,children:l(C,{className:`h-3 w-3 ${m===e.addonId?`animate-spin`:``}`})})]})]}),i?.addonId===e.addonId&&i.type===`logs`&&l(`div`,{className:`border-t border-border/40 bg-muted/5`,children:l(ae,{addonId:e.addonId,agentId:t,maxHeight:`max-h-48`,showFilters:!1,onClose:()=>a(e.addonId,`logs`)})}),i?.addonId===e.addonId&&i.type===`events`&&l(`div`,{className:`border-t border-border/40 bg-muted/5`,children:l(be,{addonId:e.addonId,category:`addon.*`,maxHeight:`max-h-48`,onClose:()=>a(e.addonId,`events`)})})]},e.addonId))}),u&&o.length===0&&l(`div`,{className:`px-3 py-2 pl-9 text-[10px] text-muted-foreground`,children:`No services`})]})}function Pe({nodeId:e,processes:t}){let[n,r]=c(null),i=(e,t)=>{r(n=>n?.addonId===e&&n.type===t?null:{addonId:e,type:t})};return t.length===0?l(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No processes on this node`}):l(`div`,{className:`space-y-2 py-1`,children:t.map((t,r)=>l(Ne,{proc:t,nodeId:e,defaultExpanded:r===0,activePanel:n,onTogglePanel:i},t.name))})}var Fe={system:0,managed:1,root:2};n();function Ie(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m ${e%60}s`:e<86400?`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`:`${Math.floor(e/86400)}d ${Math.floor(e%86400/3600)}h`}function Le(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function Re({nodeId:e}){let t=s(),n=k(`metrics.node-processes-snapshot`,t=>t.nodeId===e),{data:i}=fe({nodeId:e}),o=n?.processes??i,c=a(()=>o?[...o]:[],[o]),u=a(()=>[{key:`classification`,header:`Class`,sortValue:e=>Fe[e.classification],render:e=>l(`span`,{className:`inline-block rounded-full px-1.5 py-0.5 text-[10px] font-medium ${e.classification===`root`?`bg-sky-500/20 text-sky-400`:e.classification===`system`?`bg-foreground-subtle/20 text-foreground-subtle`:`bg-success/20 text-success`}`,children:e.classification})},{key:`pid`,header:`PID`,align:`right`,sortValue:e=>e.pid,render:e=>l(`span`,{className:`font-mono`,children:e.pid})},{key:`ppid`,header:`PPID`,align:`right`,sortValue:e=>e.ppid,render:e=>l(`span`,{className:`font-mono text-foreground-subtle`,children:e.ppid})},{key:`addonId`,header:`Addon`,sortValue:e=>e.addonId,render:e=>l(`span`,{className:`text-foreground-subtle text-[11px]`,children:e.addonId??`—`})},{key:`command`,header:`Command`,nowrap:!1,render:e=>l(`span`,{className:`font-mono text-[10px] text-foreground-subtle break-all`,children:Le(e.command)})},{key:`cpuPercent`,header:`CPU%`,align:`right`,sortValue:e=>e.cpuPercent,render:e=>e.cpuPercent.toFixed(1)},{key:`memoryRssBytes`,header:`RSS`,align:`right`,sortValue:e=>e.memoryRssBytes,render:e=>N(e.memoryRssBytes)},{key:`uptimeSec`,header:`Uptime`,align:`right`,sortValue:e=>e.uptimeSec,render:e=>l(`span`,{className:`text-foreground-subtle`,children:Ie(e.uptimeSec)})}],[]);return r(`div`,{className:`space-y-4`,children:[l(`div`,{className:`flex items-start justify-end gap-4`,children:r(`button`,{type:`button`,onClick:()=>t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}),className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[l(E,{className:`h-3 w-3`}),` Refresh`]})}),l(O,{columns:u,rows:c,rowKey:e=>e.pid,minWidthPx:880,mobileMode:`scroll`,maxBodyHeight:Se,emptyMessage:`Scanning…`})]})}var P={width:320,height:64},ze=.8,F=Math.ceil(8*ze-3)+1,I=P.width+34,L=P.height+F+1+11,Be=F+P.height+1+3+Math.ceil(8*ze),Ve=[1,2,5,10],He=[1,2,4,8,16,32,64,128,256,512,1024],Ue=[1,1.5,2,2.5,3,4,5],R=[4,3,5,2],We=1e-9;function Ge(e,t){if(!Number.isFinite(e)||e<=0)return!1;if(t===`bytes`){if(!Number.isInteger(e))return!1;let t=e/1024**Math.floor(Math.log(e)/Math.log(1024));return Ue.some(e=>Math.abs(t-e)<We)}let n=e/10**Math.floor(Math.log10(e));return Ue.some(e=>Math.abs(n-e)<We)}function Ke(e,t,n){let r=0;for(let t of e)t!==null&&t>r&&(r=t);if(r<=t)return t;if(n===`bytes`){let e=1024**Math.floor(Math.log(r)/Math.log(1024));for(let t of He){let n=t*e;if(n>=r)return n}return 1024*e}let i=10**Math.floor(Math.log10(r));for(let e of Ve){let t=e*i;if(t>=r)return t}return 10*i}function z(e,t){if(!Number.isFinite(e)||e<=0)return[];let n=R.find(n=>Ge(e/n,t))??R[R.length-1],r=e/n,i=[];for(let e=1;e<=n;e++)i.push(r*e);return i}var qe=2.5;function B(e){return e*qe}function V(e,t,n,r){if(e.length===0)return[];let i=e[0].atMs,a=e.at(-1).atMs-i,o=n<=0?1:n,s=r!==void 0&&r>0?r:null;return e.map((r,c)=>{let l=a>0?(r.atMs-i)/a*t.width:c/Math.max(1,e.length-1)*t.width,u=c>0?e[c-1]:void 0;return{x:l,y:r.value===null?null:t.height-Math.min(r.value,n)/o*t.height,gapBefore:s!==null&&u!==void 0&&r.atMs-u.atMs>s}})}function H(e){let t=[],n=!1;for(let r of e){if(r.y===null){n=!1;continue}r.gapBefore&&(n=!1),t.push(`${n?`L`:`M`}${r.x.toFixed(1)},${r.y.toFixed(1)}`),n=!0}return t.join(` `)}function U(e,t){let n=[],r=[],i=()=>{if(r.length<2){r=[];return}let e=r.map((e,t)=>`${t===0?`M`:`L`}${e.x.toFixed(1)},${e.top.toFixed(1)}`),t=[...r].reverse().map(e=>`L${e.x.toFixed(1)},${e.bottom.toFixed(1)}`);n.push(`${e.join(` `)} ${t.join(` `)} Z`),r=[]};for(let n=0;n<e.length;n++){let a=e[n],o=t[n];if(!a||!o||a.y===null||o.y===null){i();continue}(a.gapBefore||o.gapBefore)&&i(),r.push({x:a.x,top:a.y,bottom:o.y})}return i(),n.join(` `)}function W(e,t,n=3){if(e.length<2||n<2)return[];let r=e[0].atMs,i=e.at(-1).atMs-r;if(i<=0)return[];let a=[];for(let e=0;e<n;e++){let o=e/(n-1);a.push({atMs:r+i*o,x:o*t.width,anchor:e===0?`start`:e===n-1?`end`:`middle`})}return a}function G(e){return e.length<2?0:Math.max(0,e.at(-1).atMs-e[0].atMs)}function Je(e){let t=[];for(let n=1;n<e.length;n++){let r=e[n];r.gapBefore&&t.push({fromX:e[n-1].x,toX:r.x})}return t}function Ye(e,t){if(e.length===0)return null;let n=0,r=1/0;for(let i=0;i<e.length;i++){let a=Math.abs(e[i].x-t);a<r&&(r=a,n=i)}return n}n();var K={main:`var(--load-series-main)`,gc:`var(--load-series-gc)`},Xe=`
|
|
2
2
|
.load-chart-scope { --load-series-main: #2a78d6; --load-series-gc: #e87ba4; }
|
|
3
3
|
@media (prefers-color-scheme: dark) {
|
|
4
4
|
:root:not([data-theme="light"]) .load-chart-scope {
|