UNPKG

@getontime/cli

Version:
3 lines (2 loc) 9.46 kB
import{a7 as R,r as p,j as e,v as z,a8 as B,t as M,a9 as U,aa as V,S as E}from"./vendor-DFNUfA2K.js";import{P as W,b as D,T as g,j as Z,F as $,k as q,g as P,i as C,B as y,l as G,m as K,n as Q,t as J,o as I,f as O,p as X,q as Y,u as ee,d as te,L as se,h as oe,O as re,r as ne}from"./index-BNit4nUw.js";import{u as ae,i as ie,a as ce}from"./useRundown-DgZv-crd.js";import{E as N}from"./Empty-BLJKwoJq.js";import{E as le}from"./EmptyPage-dVRQ987V.js";import{V as de}from"./ViewLogo-BhUYUzFU.js";import{m as ue,O as F,i as me,b as w,g as fe,V as pe}from"./ViewParamsEditor-C6i_vUmm.js";import{u as he}from"./useWindowTitle-Bgl000Se.js";import{S as L,a as xe}from"./viewLoader.utils-CeLIIcNn.js";import{g as ge}from"./common.options-CwGs4uxL.js";import{u as we}from"./useFollowComponent-2C-gde3X.js";import{g as ye}from"./offset-DC4blUxG.js";import{F as je}from"./FollowButton-DHe0O-J2.js";import{u as Se}from"./useCustomFields-C60U2vqf.js";import{u as be}from"./useProjectData-BfKJevmX.js";import"./Select-Bp_h4xvR.js";(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},s=new t.Error().stack;s&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[s]="3e26453f-5c5a-429f-a6e5-2693f2732409",t._sentryDebugIdIdentifier="sentry-dbid-3e26453f-5c5a-429f-a6e5-2693f2732409")}catch{}})();const Ce=(t,s,o)=>{const r=ue(s,[{value:"note",label:"Note"}]);return[{title:F.ClockOptions,collapsible:!0,options:[ge(t)]},{title:F.DataSources,collapsible:!0,options:[{id:"secondary-src",title:"Event secondary text",description:"Select the data source for auxiliary text shown in the card",type:"option",values:r,defaultValue:""}]},{title:F.BehaviourOptions,collapsible:!0,options:[{id:"showExpected",title:"Show expected time",description:"Whether the times shown should account for the runtime offset.",type:"boolean",defaultValue:!1}]},{title:F.Hidden,options:[{id:"sub",title:"Event subscription",description:"The events to follow",values:o,type:"persist"}]}]};function Fe(t,s){const o=n=>(s==null?void 0:s.get(n))??t.get(n);return{subscriptions:(n=>s!=null&&s.has(n)?s.getAll(n):t.getAll(n))("sub"),secondarySource:o("secondary-src"),showExpected:me(o("showExpected"))}}function k(){const[t]=R(),s=p.use(W);return p.useMemo(()=>{const r=s?new URLSearchParams(s.search):void 0;return Fe(t,r)},[s,t])}function ve(t){return t??"{no title}"}function Oe(t,s,o){return t===s&&o!==D.Armed}const _={removeSeconds:!0,removeLeadingZero:!0},v={removeSeconds:!0,removeLeadingZero:!1},_e={future:"countdown.to_start",due:"timeline.due",live:"timeline.live",done:"countdown.ended"};function Ne(t,s,o,r,n,i,d,u,f=!1){const a=f?i+r.delay:0;if(n===r.id)return s===D.Armed?{status:"due",timer:w(r.timeStart+a,g.CountDown,u,v)}:{status:"live",timer:w(t,g.CountDown,u,_)};if(r.dayOffset>d){const c=(r.dayOffset-d)*Z;return{status:"future",timer:w(r.timeStart+c-o-a,g.CountDown,u,_)}}return r.dayOffset<d?{status:"done",timer:w(r.timeEnd,g.CountDown,u,v)}:o<r.timeStart?{status:"future",timer:w(r.timeStart-o-a,g.CountDown,u,_)}:o>r.timeEnd?{status:"done",timer:w(r.timeEnd,g.CountDown,u,v)}:{status:"due",timer:w(r.timeStart+a,g.CountDown,u,v)}}function ke(t,s){const o=new URL(t),r=new URLSearchParams;for(const[n,i]of o.searchParams.entries())n!=="sub"&&r.append(n,i);return s.forEach(n=>{r.append("sub",n)}),o.search=r.toString(),o}function Te(t,s){return s.filter(o=>t.includes(o.id))}function j(t){const{value:s,preferredFormat12:o=$,preferredFormat24:r=q,className:n}=t,i=P(s,{format12:o,format24:r});return e.jsx(L,{className:n,time:i})}function Ee({events:t,subscriptions:s,disableEdit:o}){const[r,n]=p.useState(s),i=z(),d=a=>{n(c=>c.includes(a)?c.filter(m=>m!==a):[...c,a])},u=()=>{const a=r.filter(m=>t.some(h=>h.id===m)),c=ke(window.location.href,a);o(),n([]),i(c.search.toString())},f=new Set(r);return e.jsxs("div",{className:"list-container",children:[t.map((a,c)=>{const m=a.title||"{no title}",h=f.has(a.id);return e.jsxs("div",{role:"button",tabIndex:0,onClick:()=>d(a.id),onKeyDown:x=>{(x.key==="Enter"||x.key===" ")&&(d(a.id),x.stopPropagation())},className:C(["sub",h&&"sub--selected"]),children:[e.jsx("div",{className:"sub__binder",style:{"--user-color":(a==null?void 0:a.colour)??""}}),e.jsxs("div",{className:"sub__schedule",children:[e.jsx(j,{value:a.timeStart,preferredFormat12:"h:mm",preferredFormat24:"HH:mm"}),"→",e.jsx(j,{value:a.timeEnd,preferredFormat12:"h:mm",preferredFormat24:"HH:mm"})]}),e.jsx("div",{className:"sub__label",children:h?"Click to remove":"Click to add"}),e.jsx("div",{className:"sub__title",children:m})]},c)}),e.jsxs("div",{className:"fab-container",children:[e.jsxs(y,{variant:"subtle",size:"xlarge",onClick:o,children:[e.jsx(B,{})," Go back"]}),e.jsxs(y,{variant:"subtle",size:"xlarge",onClick:()=>n([]),disabled:r.length===0,children:[e.jsx(M,{})," Clear"]}),e.jsxs(y,{variant:"primary",size:"xlarge",disabled:t.length<1,onClick:u,children:[e.jsx(U,{})," Save"]})]})]})}function De({subscribedEvents:t,goToEditMode:s}){const{secondarySource:o,showExpected:r}=k(),{playback:n}=G(),{selectedEventId:i}=K(),d=Q(!0),u=p.useRef(null),[f,a]=p.useState(!1),c=p.useRef(null),m=p.useRef(null),h=we({followRef:c,scrollRef:m,doFollow:!f,topOffset:0});p.useEffect(()=>{var l;i||f||(l=m.current)==null||l.scrollTo(0,0)},[i,f,m]);const x=()=>{i&&h(),a(!1)},A=J(()=>{if(c!=null&&c.current&&(m!=null&&m.current)){const l=c.current.getBoundingClientRect(),S=m.current.getBoundingClientRect();if(l&&S){const b=l.top-S.top,H=b<-8||b>50;a(H)}}},1e3),T=()=>{u.current&&clearTimeout(u.current),A()};return e.jsxs("div",{className:"list-container",onWheel:T,onTouchMove:T,ref:m,children:[t.map(l=>{const S=fe(l,o),b=Oe(l.id,i,n);return e.jsxs("div",{ref:b?c:void 0,className:C(["sub",b&&"sub--live"]),children:[e.jsx("div",{className:"sub__binder",style:{"--user-color":l.colour}}),e.jsx("div",{className:C(["sub__schedule",l.delay>0&&"sub__schedule--delayed"]),children:r?e.jsx(Pe,{timeStart:l.timeStart,timeEnd:l.timeEnd,delay:l.delay}):e.jsxs(e.Fragment,{children:[e.jsx(j,{value:l.timeStart+l.delay,preferredFormat12:"h:mm",preferredFormat24:"HH:mm"}),"→",e.jsx(j,{value:l.timeEnd+l.delay,preferredFormat12:"h:mm",preferredFormat24:"HH:mm"})]})}),e.jsx(Ie,{event:l,selectedEventId:i},l.id),e.jsx("div",{className:C(["sub__title",!l.title&&"subdued"]),children:ve(l.title)}),S&&e.jsx("div",{className:"sub__secondary",children:S})]},l.id)}),e.jsx("div",{className:C(["fab-container",!d&&"fab-container--hidden"]),children:e.jsxs(y,{variant:"primary",size:"xlarge",onClick:s,children:[e.jsx(V,{})," Edit"]})}),e.jsx(je,{isVisible:f,onClickHandler:x})]})}function Pe(t){const{timeStart:s,timeEnd:o,delay:r}=t,{offset:n}=I(),i=n-r,d=ye(i);return e.jsxs(e.Fragment,{children:[e.jsx(j,{value:s-i,className:`sub__schedule--${d}`,preferredFormat12:"h:mm",preferredFormat24:"HH:mm"}),"→",e.jsx(j,{value:o-i,preferredFormat12:"h:mm",preferredFormat24:"HH:mm"})]})}function Ie({event:t,selectedEventId:s}){const{getLocalizedString:o}=O(),{currentDay:r}=X(),{offset:n}=I(),{showExpected:i}=k(),{playback:d,current:u,clock:f}=Y(),{status:a,timer:c}=Ne(u,d,f,t,s,n,r,o("common.minutes"),i);return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"sub__status",children:o(_e[a])}),e.jsx("div",{className:"sub__timer",children:c})]})}function Le(){const t=ee(a=>a.mirror),{data:s,status:o}=ae(),{data:r,status:n}=be(),{data:i,status:d}=te(),{data:u,status:f}=Se();return{data:{customFields:u,events:s,projectData:r,isMirrored:t,settings:i},status:xe([o,n,d,f])}}function st(){const{data:t,status:s}=Le();return he("Countdown"),s==="pending"?e.jsx(se,{}):s==="error"?e.jsx(le,{text:"There was an error fetching data, please refresh the page."}):e.jsx(Ae,{...t})}function Ae({customFields:t,events:s,projectData:o,isMirrored:r,settings:n}){const{getLocalizedString:i}=O(),{subscriptions:d}=k(),[u,f]=p.useState(!1),a=s.filter(x=>ie(x)&&ce(x)),c=a.length>0,m=oe(n==null?void 0:n.timeFormat),h=p.useMemo(()=>Ce(m,t,d),[m,t,d]);return e.jsxs("div",{className:`countdown ${r?"mirror":""}`,"data-testid":"countdown-view",children:[e.jsx(pe,{target:re.Countdown,viewOptions:h}),e.jsxs("div",{className:"project-header",children:[(o==null?void 0:o.logo)&&e.jsx(de,{name:o.logo,className:"logo"}),e.jsx("div",{className:"title",children:o.title}),e.jsx(Re,{})]}),!c&&e.jsx(N,{text:i("common.no_data"),className:"empty-container"}),c&&u&&e.jsx(Ee,{events:a,subscriptions:d,disableEdit:()=>f(!1)}),c&&!u&&e.jsx(He,{playableEvents:a,subscriptions:d,goToEditMode:()=>f(!0)})]})}function He({playableEvents:t,subscriptions:s,goToEditMode:o}){const{getLocalizedString:r}=O();if(s.length===0)return e.jsxs("div",{className:"empty-container",children:[e.jsx(N,{text:r("countdown.select_event"),className:"empty-container"}),e.jsxs(y,{variant:"primary",size:"xlarge",onClick:o,children:[e.jsx(E,{})," Add"]})]});const n=Te(s,t);return n.length===0?e.jsxs("div",{className:"empty-container",children:[e.jsx(N,{text:r("countdown.select_event"),className:"empty-container"}),e.jsxs(y,{variant:"primary",size:"xlarge",onClick:o,children:[e.jsx(E,{})," Add"]})]}):e.jsx(De,{subscribedEvents:n,goToEditMode:o})}function Re(){const{getLocalizedString:t}=O(),{clock:s}=ne(),o=P(s);return e.jsxs("div",{className:"clock-container",children:[e.jsx("div",{className:"label",children:t("common.time_now")}),e.jsx(L,{time:o,className:"time"})]})}export{st as default}; //# sourceMappingURL=Countdown-DP7Joj2L.js.map