UNPKG

adaptorex

Version:

Connect all your live interactive storytelling devices and software

2 lines (1 loc) 9.44 kB
import{C as X,u as Y,r as D,c as w,a as Z,o as u,b as d,d as a,t as c,F as C,e as $,g as U,h as m,w as _,j as S,D as ee,E as j,i as I,f as g,G as te,v as se,A as ae,z as O,k as J,_ as le,m as oe,B as ne,H as ie,I as ue,J as ce}from"./index-BijsIkza.js";import{_ as re}from"./FoldOut-riUX07ZO.js";const B=x=>(ie("data-v-0127c883"),x=x(),ue(),x),de={class:"is-scroll-container is-flex is-flex-direction-column has-background-purple-5 px-2"},ve={class:"title is-5"},me={class:"p-1"},fe={class:"level is-interactive"},pe={class:"level-left ml-1"},_e={class:"level-item"},he={class:"subtitle"},be={class:"level-right"},Ce={class:"level-item is-danger"},ge=["onClick"],xe={class:"level-item"},ye=["onClick"],ke={class:"collection-table-container"},De={key:0,class:"table is-striped is-bordered"},we={colspan:"100%",class:"has-background-light p-2"},$e={class:"is-flex is-justify-content-flex-start"},Se={class:"checkbox"},Oe=B(()=>a("span",{class:"ml-1 mr-2"},"Show Metadata",-1)),Be=B(()=>a("th",{class:"actions-cell has-background-light"},[a("div",{class:"is-flex is-align-items-center"},"actions")],-1)),Ne=["onClick"],Te={class:"is-flex is-align-items-center is-unselectable"},Ve={class:"actions-cell has-background-white"},Me={class:"buttons"},Ue=["onClick"],je=["onClick"],Ie=["onClick"],Je={class:"has-text-lines-5"},Ke={key:1,class:"button is-loading is-fullwidth"},Ee={key:2,class:"m-3 content"},Le={class:"has-text-pre-wrap",for:"value"},Ae=B(()=>a("div",{class:"is-flex-grow-1"},null,-1)),Fe={key:0,class:"field m-1"},Ge={class:"control"},Re={class:"mode-switcher"},ze={__name:"GameCollections",setup(x){const i=Y();i.dispatch("collections/getAll");const y=D(!1),h=D(!0),f=D("");function K(l){f.value===l?h.value=!h.value:(f.value=l,h.value=!0)}function E(l){return!p.value[l]||!f.value?p.value[l]:[...p.value[l]].sort((t,n)=>{const e=(t[f.value]??"").toString().toUpperCase(),o=(n[f.value]??"").toString().toUpperCase();return h.value?e.localeCompare(o):o.localeCompare(e)})}const L=w(()=>i.state.game.selected),A=w(()=>i.state.collections.names),p=w(()=>i.state.collections.documents),b=w(()=>i.state.collections.schema),N={visible:!1,onConfirm:void 0,onDismiss:()=>s.value.visible=!1,title:"...",text:"...",confirmButtonText:"Confirm",dismissButtonText:"Cancel",style:"is-info",mode:"",value:void 0,originValue:void 0,editable:!1},s=D({...N});function r(l){s.value=Object.assign(s.value,N,{visible:!0,originValue:(l==null?void 0:l.value)||""},l)}function F(l){const t=oe.cloneDeep(b.value[l]),n=Object.assign(t,{required:Object.keys(b.value[l].properties)}),e=ne(n);return T(e)}function T(l){const t=["_id","created_at","modified_at","created_by","modified_by","created_with","modified_with","sessions"];return Object.keys(l).filter(n=>t.indexOf(n)===-1).reduce((n,e)=>Object.assign(n,{[e]:l[e]}),{})}function V(l){return["_id","created_at","modified_at","created_by","modified_by","created_with","modified_with","sessions"].includes(l)}function G(l,t){const n=["_id","created_at","modified_at","created_by","modified_by","created_with","modified_with","sessions"];if(typeof t=="string")try{t=JSON.parse(t)}catch(e){const o=ce("ERROR.JSONCONVERT",{error:e.toString()});i.dispatch("adaptor/addLog",{type:"error",message:o});return}return n.forEach(e=>{e in l&&(t[e]=l[e])}),t}function R(l){i.dispatch("collections/getDocuments",{collection:l})}function z(l,t){console.log("createDocument",l,t),i.dispatch("collections/createDocument",{collection:l,document:t}).then(()=>r({visible:!1}))}function q(l,t){const n=t._id,e=G(t,s.value.value);e&&i.dispatch("collections/updateDocument",{collection:l,id:n,data:e}).then(()=>r({visible:!1}))}function H(l,t){i.dispatch("collections/deleteDocument",{collection:l,document:t}).then(()=>r({visible:!1}))}function P(l,t){const n=JSON.stringify(t,null,2);navigator.clipboard.writeText(n).then(()=>{i.dispatch("adaptor/addLog",{type:"success",message:`Document from ${l} copied to clipboard`})}).catch(e=>{i.dispatch("adaptor/addLog",{type:"error",message:`Failed to copy document: ${e}`})}),r({visible:!1})}function Q(){i.dispatch("collections/createCollection",{name:s.value.value}).then(()=>r({visible:!1}))}function W(l){i.dispatch("collections/deleteCollection",{collection:l}).then(()=>r({visible:!1}))}function M(l){if(l!==s.value.mode)if(l==="form")try{let t=JSON.parse(s.value.value);s.value.mode="form",s.value.value=t}catch(t){i.dispatch("adaptor/addLog",{type:"error",message:`${t}`})}else s.value.mode="multiline",s.value.originValue=s.value.value,s.value.value=JSON.stringify(s.value.value,null,2)}return(l,t)=>{const n=Z("Icon");return u(),d(C,null,[a("div",de,[a("h1",ve,"Collections "+c(L.value),1),(u(!0),d(C,null,$(A.value,e=>(u(),U(re,{key:e,class:"has-background-white has-border m-2",onOnOpen:o=>R(e)},{header:m(()=>[a("div",me,[a("nav",fe,[a("div",pe,[a("div",_e,[a("p",he,c(e),1)])]),a("div",be,[a("p",Ce,[a("a",{class:"has-text-danger",onClick:_(o=>r({title:"Delete Collection",text:`Do you really want do delete the Collection ${e}?`,confirmButtonText:`Delete ${e}`,style:"is-danger",onConfirm:()=>W(e)}),["stop"])}," Delete Collection ",8,ge)]),a("p",xe,[a("a",{class:"button is-success",onClick:_(o=>r({title:`Create Document in ${e.toUpperCase()}`,text:`Create new Document in Collection ${e}`,collection:e,value:F(e),confirmButtonText:"Create",mode:"form",editable:!0,onConfirm:()=>z(s.value.collection,s.value.value)}),["stop"])}," Add Document ",8,ye)])])])])]),default:m(()=>[a("div",ke,[p.value[e]&&p.value[e].length>0?(u(),d("table",De,[a("thead",null,[a("tr",null,[a("th",we,[a("div",$e,[a("label",Se,[Oe,S(a("input",{"onUpdate:modelValue":t[0]||(t[0]=o=>y.value=o),type:"checkbox"},null,512),[[ee,y.value]])])])])]),a("tr",null,[Be,(u(!0),d(C,null,$(b.value[e].properties,(o,v)=>S((u(),d("th",{key:`${e}_key_${v}`,class:"is-clickable",onClick:k=>K(v)},[a("p",Te,[I(c(v)+" ",1),g(n,{icon:f.value===v?h.value?"arrow-down":"arrow-up":"minus",class:"ml-2"},null,8,["icon"])])],8,Ne)),[[j,!V(v)||y.value]])),128))])]),a("tbody",null,[(u(!0),d(C,null,$(E(e),o=>(u(),d("tr",{key:o._id},[a("td",Ve,[a("div",Me,[a("a",{class:"button is-small is-rounded is-light",onClick:_(v=>r({title:"View Document",text:`View Document ${o._id} ${o.name?` (${o.name})`:""} in Collection ${e}`,value:JSON.stringify(o,null,2),confirmButtonText:"Copy to Clipboard",onConfirm:()=>P(e,o),mode:"multiline",editable:!1}),["stop"])},[g(n,{class:"has-text-dark",icon:"file",tooltip:"View Document"})],8,Ue),a("a",{class:"button is-small is-rounded is-light",onClick:_(v=>r({title:"Update Document",text:`Update Document ${o._id}${o.name?` (${o.name})`:""} in Collection ${e}`,value:T(o),collection:e,confirmButtonText:"Update",mode:"form",editable:!0,onConfirm:()=>q(e,o)}),["stop"])},[g(n,{class:"has-text-dark",icon:"edit",tooltip:"Edit Document"})],8,je),a("a",{class:"button is-small is-rounded is-light",onClick:_(v=>r({title:"Delete Document",text:`Do you really want do delete the Document ${o._id}?`,confirmButtonText:"Delete",style:"is-danger",onConfirm:()=>H(e,o._id)}),["stop"])},[g(n,{class:"has-text-danger",icon:"trash-2",tooltip:"Delete Document"})],8,Ie)])]),(u(!0),d(C,null,$(b.value[e].properties,(v,k)=>S((u(),d("td",{key:`${o._id}_${k}`},[a("span",Je,c((o==null?void 0:o[k])??""),1)])),[[j,!V(k)||y.value]])),128))]))),128))])])):p.value[e]?(u(),d("span",Ee,"No data in Collection "+c(e)+".",1)):(u(),d("a",Ke,"Loading"))])]),_:2},1032,["onOnOpen"]))),128)),a("section",null,[a("button",{class:"button is-dark m-2",onClick:t[1]||(t[1]=_(e=>r({title:"New Collection",text:"Give your new Collection a name.",confirmButtonText:"Create",onConfirm:()=>Q(),mode:"input"}),["stop"]))}," New Collection ")])]),s.value.visible?(u(),U(le,{key:0,modal:s.value,"css-classes":[s.value.style],onCloseModal:t[9]||(t[9]=e=>s.value.visible=!1)},te({header:m(()=>[I(c(s.value.title),1)]),footer:m(()=>[a("button",{class:O(["button m-1",s.value.style]),onClick:t[5]||(t[5]=(...e)=>s.value.onConfirm&&s.value.onConfirm(...e))},c(s.value.confirmButtonText),3),a("button",{class:"button m-1",onClick:t[6]||(t[6]=(...e)=>s.value.onDismiss&&s.value.onDismiss(...e))},c(s.value.dismissButtonText),1),Ae,s.value.editable?(u(),d("div",Fe,[a("div",Ge,[a("div",Re,[a("button",{class:O(["mode-button",{"is-active":s.value.mode==="form"}]),onClick:t[7]||(t[7]=e=>M("form"))}," Form ",2),a("button",{class:O(["mode-button",{"is-active":s.value.mode==="multiline"}]),onClick:t[8]||(t[8]=e=>M("multiline"))}," JSON ",2)])])])):J("",!0)]),_:2},[s.value.mode=="input"?{name:"default",fn:m(()=>[a("label",Le,c(s.value.text),1),S(a("input",{"onUpdate:modelValue":t[2]||(t[2]=e=>s.value.value=e),class:"input",type:"text",name:"value"},null,512),[[se,s.value.value]])]),key:"0"}:s.value.mode=="multiline"?{name:"default",fn:m(()=>[a("label",{for:"value"},c(s.value.text),1),a("pre",{class:"has-text-black",contenteditable:s.value.editable,onInput:t[3]||(t[3]=e=>s.value.value=e.target.textContent)},c(s.value.originValue),41,["contenteditable"])]),key:"1"}:s.value.mode=="form"?{name:"default",fn:m(()=>[a("label",{for:"value"},c(s.value.text),1),g(ae,{data:s.value.value,schema:b.value[s.value.collection],"show-controls":!1,onDataChanged:t[4]||(t[4]=e=>s.value.value=e)},null,8,["data","schema"])]),key:"2"}:{name:"default",fn:m(()=>[a("label",{for:"value"},c(s.value.text),1)]),key:"3"}]),1032,["modal","css-classes"])):J("",!0)],64)}}},Pe=X(ze,[["__scopeId","data-v-0127c883"]]);export{Pe as default};