UNPKG

@getontime/cli

Version:
3 lines (2 loc) 8.24 kB
import{l as x,j as t,h as d,ay as k,aT as V,D as N,q as E,s as D,t as F,G as I,v as O}from"./vendor-q6fv0YT2.js";import{bi as $,e as g,B as j,ah as y,a as A,bj as H,D as z,ak as L}from"./index-B81u4hxi.js";import{C as R,I as B}from"./useWindowTitle-Bpmo_HzW.js";import{i as q}from"./viewUtils-B8Dr4GHH.js";import{S as U}from"./Select-BGGVCKqU.js";import{b as W,S as M}from"./SwatchPicker-Cm5Eicvv.js";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},s=new e.Error().stack;s&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[s]="244a2dff-e9fb-4d0a-97b3-fe7f981db9a1",e._sentryDebugIdIdentifier="sentry-dbid-244a2dff-e9fb-4d0a-97b3-fe7f981db9a1")}catch{}})();function Ae(e,s=[],n=!0){const a=[...s];for(const[r,i]of Object.entries(e))n&&i.type==="image"||a.push({value:`custom-${r}`,label:`Custom: ${i.label}`});return a}function He(e,s=!0){const n=[];for(const[a,r]of Object.entries(e))s&&r.type==="image"||n.push({value:a,label:r.label,colour:r.colour});return n}function ze(e,s=[]){const n=e.custom.map((a,r)=>({value:`${r}-${a.title}`,label:a.title}));return[...s,...n]}function G(e){return e.startsWith("#")?e.substring(1):e}function J(e){const s={defaultValues:{},colorFields:new Set,booleanFields:new Set,isPersistedField:new Set,persistedValues:{}};return e.forEach(n=>{n.options.forEach(a=>{a.type==="persist"?(s.isPersistedField.add(a.id),a.values&&(s.persistedValues[a.id]=a.values)):s.defaultValues[a.id]=String(a.defaultValue),a.type==="colour"?s.colorFields.add(a.id):a.type==="boolean"&&s.booleanFields.add(a.id)})}),s}function K(e,s){const n=new URLSearchParams,a=new Set,r=J(s),i=(o,l)=>{const c=`${o}:${l}`;a.has(c)||(a.add(c),n.append(o,l))};return Object.entries(r.persistedValues).forEach(([o,l])=>{l.forEach(c=>{c&&i(o,c)})}),Object.entries(e).forEach(([o,l])=>{typeof l=="string"&&l.length&&(r.isPersistedField.has(o)&&(Array.from(a).forEach(c=>{c.startsWith(`${o}:`)&&a.delete(c)}),n.delete(o)),l.split(",").forEach(c=>{const m=r.colorFields.has(o)?G(c):r.booleanFields.has(o)?c==="on"?"true":"false":c;(r.isPersistedField.has(o)||r.defaultValues[o]!==m)&&i(o,m)}))}),n}const Q="_presetSection_gc8wt_17",T="_preset_gc8wt_17",X="_active_gc8wt_34",Y="_presetActions_gc8wt_38",p={presetSection:Q,preset:T,active:X,presetActions:Y};function Z({target:e}){const{viewPresets:s}=$(e),[n,a]=x(),r=i=>{const o=new URLSearchParams(i.search);o.set("alias",i.alias),a(o)};return s.length===0?null:t.jsx("div",{className:p.presetSection,children:s.map(i=>{const o=n.get("alias")===i.alias;return t.jsxs("div",{className:g([p.preset,o&&p.active]),children:[t.jsx("div",{children:i.alias}),t.jsx(j,{variant:o?"ghosted":"subtle-white",onClick:()=>r(i),disabled:o,className:p.presetActions,children:o?"Applied":"Apply"})]},i.alias)})})}var v=(e=>(e.ClockOptions="Clock Options",e.TimerOptions="Timer Options",e.DataSources="Data sources",e.ElementVisibility="Element visibility",e.BehaviourOptions="View behaviour",e.StyleOverride="View style override",e.Animation="View animation",e.Schedule="Schedule options",e.Hidden="Hidden options",e))(v||{});const ee="_inline_4jmjk_17",se={inline:ee},S=e=>e.startsWith("#")?e:`#${e}`;function te({name:e,value:s}){const[n,a]=d.useState(()=>S(s));return d.useEffect(()=>{a(S(s))},[s]),t.jsxs("div",{className:se.inline,children:[t.jsx(W,{color:n,onChange:a,alwaysDisplayColor:!0}),t.jsx("span",{children:n}),t.jsx("input",{type:"hidden",name:e,value:n})]})}const ae="_inline_7qz4u_17",ne="_toggleSelect_7qz4u_24",re="_empty_7qz4u_52",_={inline:ae,toggleSelect:ne,empty:re};function w({paramField:e}){const[s]=x(),{id:n,type:a,defaultValue:r}=e;if(a==="persist")return!e.values||!e.values.length?null:t.jsx("input",{hidden:!0,name:n,readOnly:!0,value:e.values.join(",")});if(a==="option"){const c=s.get(n)||r;return e.values.length===0?t.jsx("span",{className:_.empty,children:"No options available"}):t.jsx(le,{id:n,initialValue:c,options:e.values})}if(a==="multi-option"){const l=s.getAll(n);return t.jsx(oe,{paramField:e,options:l.length?l:e.defaultValue??[""]})}if(a==="boolean")return t.jsx(ie,{id:n,initialValue:q(s.get(n))??r});if(a==="number"){const{placeholder:l}=e,c=s.get(n)??r;return t.jsx(y,{height:"large",type:"number",step:"any",name:n,defaultValue:c,placeholder:l})}if(a==="colour")return t.jsx(te,{name:n,value:s.get(n)??r});const i=s.get(n)??r??"",{placeholder:o}=e;return t.jsx(ce,{id:n,initialValue:i,placeholder:o})}function oe({paramField:e,options:s}){const{id:n,values:a}=e,[r,i]=d.useState(s);d.useEffect(()=>{i(s)},[s]);const o=(l,c)=>{i(c?m=>[...m,l]:m=>m.filter(b=>b!==l))};return a.length===0?t.jsx("span",{className:_.empty,children:"No options available"}):t.jsxs(t.Fragment,{children:[t.jsx("input",{name:n,hidden:!0,readOnly:!0,value:r.join(",")}),t.jsx("div",{className:_.inline,children:a.map(l=>t.jsxs("label",{className:_.toggleSelect,style:{"--user-bg":l.colour},children:[t.jsx(R,{checked:r.includes(l.value),onCheckedChange:c=>o(l.value,c)}),l.label]},l.value))})]})}function ie({id:e,initialValue:s}){const[n,a]=d.useState(s);return d.useEffect(()=>{a(s)},[s]),t.jsx(M,{size:"large",name:e,checked:n,onCheckedChange:a})}function le({id:e,initialValue:s,options:n}){const[a,r]=d.useState(s);return d.useEffect(()=>{r(s)},[s]),t.jsx(U,{size:"large",name:e,options:n,value:a,onValueChange:i=>{i!==null&&r(i)}})}function ce({id:e,initialValue:s,...n}){const[a,r]=d.useState(s);return d.useEffect(()=>{r(s)},[s]),t.jsx(y,{height:"large",name:e,value:a,onChange:i=>r(i.target.value),...n})}const de="_section_1ssto_17",ue="_sectionHeader_1ssto_22",fe="_collapsible_1ssto_28",me="_label_1ssto_32",he="_title_1ssto_41",pe="_description_1ssto_47",_e="_closed_1ssto_53",ge="_open_1ssto_58",be="_hidden_1ssto_63",f={section:de,sectionHeader:ue,collapsible:fe,label:me,title:he,description:pe,closed:_e,open:ge,hidden:be};function je({title:e,collapsible:s,options:n}){const[a,r]=k({key:`params-${e}`,defaultValue:!1}),i=()=>{s&&r(o=>!o)};return t.jsx("section",{className:f.section,children:e===v.Hidden?t.jsx(Se,{options:n}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:g([f.sectionHeader,s&&f.collapsible]),onClick:i,children:[e,s&&t.jsx(V,{className:g([a?f.closed:f.open])})]}),t.jsx(xe,{options:n,collapsed:a})]})})}function xe({options:e,collapsed:s}){return t.jsx(t.Fragment,{children:e.map(n=>t.jsxs("label",{className:g([f.label,s&&f.hidden]),children:[t.jsx("span",{className:f.title,children:n.title}),t.jsx("span",{className:f.description,children:n.description}),t.jsx(w,{paramField:n})]},n.title))})}function Se({options:e}){return t.jsx(t.Fragment,{children:e.map((s,n)=>t.jsx(w,{paramField:s},s.title+n))})}const ye="_backdrop_1pnpt_26",ve="_drawer_1pnpt_17",we="_header_1pnpt_67",Pe="_body_1pnpt_77",Ce="_footer_1pnpt_84",ke="_sectionList_1pnpt_92",Ve="_info_1pnpt_99",h={backdrop:ye,drawer:ve,header:we,body:Pe,footer:Ce,sectionList:ke,info:Ve},Le=d.memo(Ne);function Ne({target:e,viewOptions:s}){const[n,a]=x(),{data:r}=A(),{isOpen:i,close:o}=H(),l=z(),c=()=>{o()},m=()=>{a()},b=u=>{u.preventDefault();const P=Object.fromEntries(new FormData(u.currentTarget)),C=K(P,s);a(C),l&&o()};return t.jsx(N,{open:i,onOpenChange:u=>{u||c()},children:t.jsxs(E,{children:[t.jsx(D,{className:h.backdrop}),t.jsxs(F,{className:h.drawer,children:[t.jsxs("div",{className:h.header,children:[t.jsx(I,{children:"Customise"}),t.jsx(L,{variant:"subtle-white",size:"large","data-testid":"close-view-params",onClick:c,children:t.jsx(O,{})})]}),t.jsxs("div",{className:h.body,children:[r.overrideStyles&&t.jsx(B,{className:h.info,children:"This view style is being modified by a custom CSS file."}),t.jsx(Z,{target:e}),t.jsx("form",{id:"edit-params-form",onSubmit:b,className:h.sectionList,children:s.map(u=>t.jsx(je,{title:u.title,collapsible:u.collapsible,options:u.options},u.title))})]}),t.jsxs("div",{className:h.footer,children:[t.jsx(j,{variant:"subtle",size:"large",onClick:m,type:"reset",children:"Reset to default"}),t.jsx(j,{variant:"primary",size:"large",form:"edit-params-form",type:"submit","data-testid":"apply-view-params",children:"Apply"})]})]})]})})}export{v as O,Le as V,ze as a,He as b,Ae as m}; //# sourceMappingURL=ViewParamsEditor-C2-TRP6e.js.map