chirkle 0.1.0 → 0.3.0
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/README.md +23 -4
- package/package.json +2 -1
- package/pb_hooks/federation/messages.js +48 -2
- package/pb_hooks/lib/anonymous.js +10 -6
- package/pb_hooks/lib/bulk.js +2 -0
- package/pb_hooks/lib/files.js +39 -47
- package/pb_hooks/lib/handles.js +337 -0
- package/pb_hooks/lib/http.js +35 -23
- package/pb_hooks/lib/inbox.js +383 -0
- package/pb_hooks/lib/lists.js +8 -2
- package/pb_hooks/lib/live.js +137 -0
- package/pb_hooks/lib/messages.js +4 -0
- package/pb_hooks/lib/reactions.js +2 -0
- package/pb_hooks/lib/reads.js +3 -1
- package/pb_hooks/lib/site.js +1 -1
- package/pb_hooks/lib/stats.js +252 -0
- package/pb_hooks/lib/users.js +6 -1
- package/pb_hooks/main.pb.js +104 -27
- package/pb_hooks/telegram/api.js +3 -2
- package/pb_hooks/telegram/inbound.js +6 -1
- package/pb_hooks/telegram/outbound.js +35 -6
- package/pb_hooks/telegram/people.js +4 -0
- package/pb_hooks/telegram/reactions.js +193 -0
- package/pb_hooks/telegram/worker.js +1 -0
- package/pb_migrations/1760000043_telegram_reactions.js +21 -0
- package/pb_migrations/1760000044_stats.js +70 -0
- package/pb_migrations/1760000045_mentions.js +187 -0
- package/pb_migrations/1760000046_reserved_handles.js +29 -0
- package/pb_public/assets/access-GUDTDXIP.js +2 -0
- package/pb_public/assets/access-GUDTDXIP.js.map +7 -0
- package/pb_public/assets/app-3WX5JYL2.js +3 -0
- package/pb_public/assets/app-3WX5JYL2.js.map +7 -0
- package/pb_public/assets/app-WAFKVN2H.css +2 -0
- package/pb_public/assets/app-WAFKVN2H.css.map +7 -0
- package/pb_public/assets/collections-DHJEOLHW.css +2 -0
- package/pb_public/assets/collections-DHJEOLHW.css.map +7 -0
- package/pb_public/assets/{emoji-WSTVXAW5.css → emoji-VA2WCEAC.css} +2 -2
- package/pb_public/assets/{emoji-WSTVXAW5.css.map → emoji-VA2WCEAC.css.map} +2 -2
- package/pb_public/assets/{emoji-picker-QYRX6NYL.js → emoji-picker-65VVVGYW.js} +2 -2
- package/pb_public/assets/forward-66PELNWT.js +2 -0
- package/pb_public/assets/forward-66PELNWT.js.map +7 -0
- package/pb_public/assets/inbox-3FSOPY2T.css +2 -0
- package/pb_public/assets/inbox-3FSOPY2T.css.map +7 -0
- package/pb_public/assets/inbox-TZJWPRTG.js +2 -0
- package/pb_public/assets/inbox-TZJWPRTG.js.map +7 -0
- package/pb_public/assets/{lazy-SCCVSUZO.js → lazy-4CXRBHHM.js} +2 -2
- package/pb_public/assets/lazy-4CXRBHHM.js.map +7 -0
- package/pb_public/assets/login-G7Y44CJ7.js +2 -0
- package/pb_public/assets/login-G7Y44CJ7.js.map +7 -0
- package/pb_public/assets/{media-L3EYTHKT.css → media-7TCBG7WM.css} +2 -2
- package/pb_public/assets/{media-L3EYTHKT.css.map → media-7TCBG7WM.css.map} +2 -2
- package/pb_public/assets/media-FPRU2QH5.js +2 -0
- package/pb_public/assets/media-FPRU2QH5.js.map +7 -0
- package/pb_public/assets/mention-suggest-R7MXUH6R.js +2 -0
- package/pb_public/assets/mention-suggest-R7MXUH6R.js.map +7 -0
- package/pb_public/assets/notify-RQ6ZLR46.js +2 -0
- package/pb_public/assets/notify-RQ6ZLR46.js.map +7 -0
- package/pb_public/assets/profile-2CNVT2KX.js +2 -0
- package/pb_public/assets/profile-2CNVT2KX.js.map +7 -0
- package/pb_public/assets/stats-A2TBRUI6.css +2 -0
- package/pb_public/assets/stats-A2TBRUI6.css.map +7 -0
- package/pb_public/assets/stats-JX52AQCO.js +2 -0
- package/pb_public/assets/stats-JX52AQCO.js.map +7 -0
- package/pb_public/assets/user-search-7GNEIXMN.js +2 -0
- package/pb_public/assets/user-search-7GNEIXMN.js.map +7 -0
- package/pb_public/index.html +3 -3
- package/pb_public/stats.html +25 -0
- package/pb_public/sw.js +1 -1
- package/pb_public/assets/access-ALBW2MT2.js +0 -2
- package/pb_public/assets/access-ALBW2MT2.js.map +0 -7
- package/pb_public/assets/app-ECR34OBK.css +0 -2
- package/pb_public/assets/app-ECR34OBK.css.map +0 -7
- package/pb_public/assets/app-SILEBEXB.js +0 -3
- package/pb_public/assets/app-SILEBEXB.js.map +0 -7
- package/pb_public/assets/collections-VEOIOCAW.css +0 -2
- package/pb_public/assets/collections-VEOIOCAW.css.map +0 -7
- package/pb_public/assets/lazy-SCCVSUZO.js.map +0 -7
- package/pb_public/assets/media-DH7ECZSF.js +0 -2
- package/pb_public/assets/media-DH7ECZSF.js.map +0 -7
- package/pb_public/assets/notify-L6GERFNO.js +0 -2
- package/pb_public/assets/notify-L6GERFNO.js.map +0 -7
- /package/pb_public/assets/{emoji-picker-QYRX6NYL.js.map → emoji-picker-65VVVGYW.js.map} +0 -0
|
@@ -605,5 +605,5 @@ var E=s=>s.split(" "),T=[{name:"Smileys",icon:"\u{1F600}",emoji:E("\u{1F600} \u{
|
|
|
605
605
|
\u{1F3F4} black_flag flag
|
|
606
606
|
\u{1F3F3}\uFE0F\u200D\u{1F308} rainbow_flag pride lgbt flag
|
|
607
607
|
\u{1F3F4}\u200D\u2620\uFE0F pirate_flag pirate flag`,W=null,F=null;function q(){return W??=X.split(`
|
|
608
|
-
`).map(s=>{let[a,n,...o]=s.split(" ");return{emoji:a,name:n,words:[...new Set([n,...[n,...o].flatMap(l=>l.split("_"))])]}}),W}function G(s){return F??=new Map(q().map(a=>[a.name,a.emoji])),F.get(s.toLowerCase())}function H(s,a=Number.POSITIVE_INFINITY){let o=s.trim().toLowerCase().split(/[\s_]+/).filter(Boolean);if(!o.length)return[];let l=o.join("_"),m=i=>i.name===l?0:i.name.startsWith(l)?1:2;return q().filter(i=>o.every(u=>i.words.some(b=>b.startsWith(u)))).map((i,u)=>({n:i,i:u,r:m(i)})).sort((i,u)=>i.r-u.r||(i.r===1?i.n.name.length-u.n.name.length:0)||i.i-u.i).slice(0,a).map(i=>i.n)}var Q=8,Z=/(?<=^|[\s(]):([\w+-]{2,})$/,ee=/(?<=^|[\s(]):([\w+-]+):$/;function te(s,a){let n=Z.exec(s.slice(0,a));return n?{start:n.index,query:n[1].toLowerCase()}:null}function ne(s){let{h:a,textarea:n,signal:o}=s,l=`${n.id}-emoji`,m=a("ul",{class:"emoji-suggest",id:l,role:"listbox","aria-label":"Emoji",hidden:!0});document.body.append(m),o.addEventListener("abort",()=>m.remove(),{once:!0});let i=[],u=0,b=-1,c=-1;function g(r=!1){let h=n.selectionStart;if(h!==n.selectionEnd)return w();let f=r?ee.exec(n.value.slice(0,h)):null,S=f&&G(f[1]);if(f&&S)return L(f.index,h,S,"");let j=te(n.value,h);if(j||(c=-1),!j||j.start===c||(i=H(j.query,Q),!i.length))return w();j.start!==b&&(u=0),b=j.start,u=Math.min(u,i.length-1),_()}function _(){m.replaceChildren(...i.map((r,h)=>a("li",{id:`${l}-${h}`,role:"option","aria-label":`${r.emoji} ${r.name}`,"aria-selected":String(h===u),on:{pointerdown:f=>f.preventDefault(),click:()=>M(h)},signal:o},[a("span",{class:"emoji","aria-hidden":"true"},r.emoji),`:${r.name}:`]))),n.setAttribute("aria-autocomplete","list"),n.setAttribute("aria-controls",l),n.setAttribute("aria-activedescendant",`${l}-${u}`),m.hidden=!1,k()}function k(){let r=(n.parentElement??n).getBoundingClientRect(),h=n.getBoundingClientRect();m.style.setProperty("--x",`${Math.round(Math.max(8,h.left))}px`),m.style.setProperty("--b",`${Math.round(innerHeight-r.top+6)}px`)}function x(r){u=(r+i.length)%i.length;for(let[h,f]of[...m.children].entries())f.setAttribute("aria-selected",String(h===u));n.setAttribute("aria-activedescendant",`${l}-${u}`),m.children[u]?.scrollIntoView?.({block:"nearest"})}function M(r){let h=i[r];if(!h)return;let f=n.selectionStart;L(b,f,h.emoji,f===n.value.length?" ":"")}function L(r,h,f,S){w(),n.focus(),n.setRangeText(f+S,r,h,"end"),z(f),n.dispatchEvent(new Event("input",{bubbles:!0}))}function w(){if(b=-1,!m.hidden){m.hidden=!0,m.replaceChildren();for(let r of["aria-autocomplete","aria-controls","aria-activedescendant"])n.removeAttribute(r)}}return n.addEventListener("input",r=>g(r instanceof InputEvent&&r.inputType.startsWith("insert")),{signal:o}),n.addEventListener("click",()=>g(),{signal:o}),n.addEventListener("keyup",r=>{!m.hidden&&/^(ArrowLeft|ArrowRight|Home|End)$/.test(r.key)&&g()},{signal:o}),n.addEventListener("blur",w,{signal:o}),addEventListener("resize",()=>m.hidden||k(),{signal:o}),(n.form??n.parentElement)?.addEventListener("keydown",r=>{if(r.target!==n||m.hidden||r.isComposing||r.keyCode===229)return;let h=!(r.shiftKey||r.ctrlKey||r.altKey||r.metaKey);if(r.key==="ArrowDown"||r.key==="ArrowUp"){if(!h)return;x(u+(r.key==="ArrowDown"?1:-1))}else if((r.key==="Enter"||r.key==="Tab")&&h)M(u);else if(r.key==="Escape")c=b,w();else return;r.preventDefault(),r.stopPropagation()},{capture:!0,signal:o}),{el:m,update:g,close:w,get isOpen(){return!m.hidden}}}var P=null;function me(s){return P??=new Promise(a=>{let o=s("link",{rel:"stylesheet",href:"/assets/emoji-
|
|
609
|
-
//# sourceMappingURL=emoji-picker-
|
|
608
|
+
`).map(s=>{let[a,n,...o]=s.split(" ");return{emoji:a,name:n,words:[...new Set([n,...[n,...o].flatMap(l=>l.split("_"))])]}}),W}function G(s){return F??=new Map(q().map(a=>[a.name,a.emoji])),F.get(s.toLowerCase())}function H(s,a=Number.POSITIVE_INFINITY){let o=s.trim().toLowerCase().split(/[\s_]+/).filter(Boolean);if(!o.length)return[];let l=o.join("_"),m=i=>i.name===l?0:i.name.startsWith(l)?1:2;return q().filter(i=>o.every(u=>i.words.some(b=>b.startsWith(u)))).map((i,u)=>({n:i,i:u,r:m(i)})).sort((i,u)=>i.r-u.r||(i.r===1?i.n.name.length-u.n.name.length:0)||i.i-u.i).slice(0,a).map(i=>i.n)}var Q=8,Z=/(?<=^|[\s(]):([\w+-]{2,})$/,ee=/(?<=^|[\s(]):([\w+-]+):$/;function te(s,a){let n=Z.exec(s.slice(0,a));return n?{start:n.index,query:n[1].toLowerCase()}:null}function ne(s){let{h:a,textarea:n,signal:o}=s,l=`${n.id}-emoji`,m=a("ul",{class:"emoji-suggest",id:l,role:"listbox","aria-label":"Emoji",hidden:!0});document.body.append(m),o.addEventListener("abort",()=>m.remove(),{once:!0});let i=[],u=0,b=-1,c=-1;function g(r=!1){let h=n.selectionStart;if(h!==n.selectionEnd)return w();let f=r?ee.exec(n.value.slice(0,h)):null,S=f&&G(f[1]);if(f&&S)return L(f.index,h,S,"");let j=te(n.value,h);if(j||(c=-1),!j||j.start===c||(i=H(j.query,Q),!i.length))return w();j.start!==b&&(u=0),b=j.start,u=Math.min(u,i.length-1),_()}function _(){m.replaceChildren(...i.map((r,h)=>a("li",{id:`${l}-${h}`,role:"option","aria-label":`${r.emoji} ${r.name}`,"aria-selected":String(h===u),on:{pointerdown:f=>f.preventDefault(),click:()=>M(h)},signal:o},[a("span",{class:"emoji","aria-hidden":"true"},r.emoji),`:${r.name}:`]))),n.setAttribute("aria-autocomplete","list"),n.setAttribute("aria-controls",l),n.setAttribute("aria-activedescendant",`${l}-${u}`),m.hidden=!1,k()}function k(){let r=(n.parentElement??n).getBoundingClientRect(),h=n.getBoundingClientRect();m.style.setProperty("--x",`${Math.round(Math.max(8,h.left))}px`),m.style.setProperty("--b",`${Math.round(innerHeight-r.top+6)}px`)}function x(r){u=(r+i.length)%i.length;for(let[h,f]of[...m.children].entries())f.setAttribute("aria-selected",String(h===u));n.setAttribute("aria-activedescendant",`${l}-${u}`),m.children[u]?.scrollIntoView?.({block:"nearest"})}function M(r){let h=i[r];if(!h)return;let f=n.selectionStart;L(b,f,h.emoji,f===n.value.length?" ":"")}function L(r,h,f,S){w(),n.focus(),n.setRangeText(f+S,r,h,"end"),z(f),n.dispatchEvent(new Event("input",{bubbles:!0}))}function w(){if(b=-1,!m.hidden){m.hidden=!0,m.replaceChildren();for(let r of["aria-autocomplete","aria-controls","aria-activedescendant"])n.removeAttribute(r)}}return n.addEventListener("input",r=>g(r instanceof InputEvent&&r.inputType.startsWith("insert")),{signal:o}),n.addEventListener("click",()=>g(),{signal:o}),n.addEventListener("keyup",r=>{!m.hidden&&/^(ArrowLeft|ArrowRight|Home|End)$/.test(r.key)&&g()},{signal:o}),n.addEventListener("blur",w,{signal:o}),addEventListener("resize",()=>m.hidden||k(),{signal:o}),(n.form??n.parentElement)?.addEventListener("keydown",r=>{if(r.target!==n||m.hidden||r.isComposing||r.keyCode===229)return;let h=!(r.shiftKey||r.ctrlKey||r.altKey||r.metaKey);if(r.key==="ArrowDown"||r.key==="ArrowUp"){if(!h)return;x(u+(r.key==="ArrowDown"?1:-1))}else if((r.key==="Enter"||r.key==="Tab")&&h)M(u);else if(r.key==="Escape")c=b,w();else return;r.preventDefault(),r.stopPropagation()},{capture:!0,signal:o}),{el:m,update:g,close:w,get isOpen(){return!m.hidden}}}var P=null;function me(s){return P??=new Promise(a=>{let o=s("link",{rel:"stylesheet",href:"/assets/emoji-VA2WCEAC.css",on:{load:()=>a(),error:()=>{o.remove(),P=null,a()}}});document.head.append(o)}),P}var v=8;function oe(s,a,n){let{cat:o,i:l}=a,m=s[o],i=l%v,u=c=>{for(let g=c-1;g>=0;g--)if(s[g])return g;return-1},b=c=>{for(let g=c+1;g<s.length;g++)if(s[g])return g;return-1};switch(n){case"left":{if(l>0)return{cat:o,i:l-1};let c=u(o);return c<0?a:{cat:c,i:s[c]-1}}case"right":{if(l<m-1)return{cat:o,i:l+1};let c=b(o);return c<0?a:{cat:c,i:0}}case"up":{if(l>=v)return{cat:o,i:l-v};let c=u(o);if(c<0)return a;let g=Math.floor((s[c]-1)/v)*v;return{cat:c,i:Math.min(g+i,s[c]-1)}}case"down":{if(l+v<m)return{cat:o,i:l+v};if(Math.floor(l/v)<Math.floor((m-1)/v))return{cat:o,i:m-1};let c=b(o);return c<0?a:{cat:c,i:Math.min(i,s[c]-1)}}}}var re={ArrowLeft:"left",ArrowRight:"right",ArrowUp:"up",ArrowDown:"down"};function he(s){let{h:a,signal:n}=s,o=a("div",{class:"emoji-picker",role:"dialog",hidden:!0}),l=a("input",{type:"search",class:"emoji-search",placeholder:"Search emoji","aria-label":"Search emoji",autocomplete:"off",enterkeyhint:"done"}),m=a("div",{class:"emoji-tabs"}),i=a("div",{class:"emoji-scroll"}),u=a("section",{class:"emoji-section found",id:"emoji-found",hidden:!0});o.append(l,m,i);let b=!1,c=null,g=null,_=[],k=null,x=null,M=e=>`emoji-cat-${e}`;function L(e){k&&(k.tabIndex=-1),k=e,e&&(e.tabIndex=0)}let w=new Map(q().map(e=>[e.emoji,e.name]));function r(e){let t=w.get(e);return a("button",{type:"button",class:"emoji",tabindex:-1,title:t&&`:${t}:`,dataset:{emoji:e}},e)}function h(){let e=l.value.trim().replace(/^:|:$/g,""),t=e!=="";for(let d of i.querySelectorAll(".emoji-section:not(.found)"))d.hidden=t;if(u.hidden=!t,t){let d=H(e);u.replaceChildren(a("h2",{class:"emoji-heading",id:"emoji-found-h"},d.length?"Found":"No emoji found"),a("div",{class:"emoji-grid",role:"group","aria-labelledby":"emoji-found-h"},d.map(p=>r(p.emoji)))),_=[[...u.querySelectorAll("button.emoji")]],S(u)}else u.replaceChildren(),_=f();i.scrollTop=0,L(_[0]?.[0]??null)}let f=()=>[...i.querySelectorAll(".emoji-section:not(.found) .emoji-grid")].map(e=>[...e.querySelectorAll("button.emoji")]);function S(e){let t=g?.chosen;for(let d of e.querySelectorAll("button.emoji")){let p=!!t?.has(d.dataset.emoji);d.classList.toggle("on",p),t?d.setAttribute("aria-pressed",String(p)):d.removeAttribute("aria-pressed"),d.tabIndex=-1}}function j(){let e=[],t=$();t.length&&e.push({name:"Recent",icon:"\u{1F558}",emoji:t}),e.push(...T),(!b||m.childElementCount!==e.length)&&m.replaceChildren(...e.map((p,y)=>a("button",{type:"button",class:"emoji-tab",title:p.name,"aria-label":p.name,on:{click:()=>{l.value&&(l.value="",h()),J(y)}},signal:n},p.icon))),b||(b=!0,i.replaceChildren(...T.map((p,y)=>I(p,y+1)),u));let d=i.querySelector(".emoji-section.recent");if(t.length){let p=I(e[0],0);p.classList.add("recent"),d?d.replaceWith(p):i.prepend(p)}else d?.remove();S(i),k=null,l.value="",h()}function I(e,t){return a("section",{class:"emoji-section",id:M(t)},[a("h2",{class:"emoji-heading",id:`${M(t)}-h`},e.name),a("div",{class:"emoji-grid",role:"group","aria-labelledby":`${M(t)}-h`},e.emoji.map(r))])}function J(e){let t=_[e]?.[0];t&&(i.querySelectorAll(".emoji-section:not(.found)")[e]?.scrollIntoView?.({block:"start"}),L(t),t.focus({preventScroll:!0}))}function U(e){for(let t=0;t<_.length;t++){let d=_[t].indexOf(e);if(d>=0)return{cat:t,i:d}}return null}function R(e){let t=g;A(!1),z(e),t?.onPick(e)}i.addEventListener("click",e=>{let t=e.target.closest?.("button.emoji");t instanceof HTMLButtonElement&&R(t.dataset.emoji)},{signal:n}),i.addEventListener("keydown",e=>{let t=e.target;if(!(t instanceof HTMLButtonElement)||!t.matches("button.emoji"))return;let d=U(t);if(!d)return;let p=null,y=re[e.key];y?p=oe(_.map(N=>N.length),d,y):e.key==="Home"?p={cat:0,i:0}:e.key==="End"&&(p={cat:_.length-1,i:_.at(-1).length-1});let C=p&&_[p.cat]?.[p.i];if(y==="up"&&C===t){e.preventDefault(),l.focus();return}C&&(e.preventDefault(),L(C),C.focus())},{signal:n}),l.addEventListener("input",h,{signal:n}),l.addEventListener("keydown",e=>{if(!e.isComposing){if(e.key==="Escape"&&l.value)e.preventDefault(),e.stopPropagation(),l.value="",h();else if(e.key==="ArrowDown"&&k)e.preventDefault(),k.focus();else if(e.key==="Enter"){e.preventDefault();let t=u.hidden?void 0:_[0]?.[0];t&&R(t.dataset.emoji)}}},{signal:n}),o.addEventListener("keydown",e=>{e.key==="Escape"&&(e.preventDefault(),e.stopPropagation(),A(!0))},{signal:n});function O(e){let t=e.getBoundingClientRect(),d=o.offsetWidth,p=o.offsetHeight,y=6,C=Math.max(8,Math.min(t.right-d,innerWidth-d-8)),N=t.top-y-p>=8?t.top-y-p:Math.min(t.bottom+y,innerHeight-p-8);o.style.setProperty("--x",`${Math.round(C)}px`),o.style.setProperty("--y",`${Math.round(Math.max(8,N))}px`)}function V(){x=new AbortController;let e={capture:!0,signal:x.signal},t=d=>{d.target instanceof Node&&!o.contains(d.target)&&!c?.contains(d.target)&&A(!1)};document.addEventListener("pointerdown",t,e),document.addEventListener("focusin",t,e),addEventListener("resize",()=>c?.isConnected&&O(c),e)}function Y(e,t){if(!n.aborted){if(!o.hidden&&c===e)return A(!0);o.hidden||A(!1),c=e,g=t,o.setAttribute("aria-label",t.label),j(),o.hidden=!1,e.setAttribute("aria-expanded","true"),O(e),i.scrollTop=0,V(),matchMedia?.("(pointer: fine)").matches?l.focus({preventScroll:!0}):k?.focus({preventScroll:!0})}}function A(e){if(o.hidden)return;o.hidden=!0,x?.abort(),x=null,c?.setAttribute("aria-expanded","false");let t=g,d=c;c=null,g=null,e&&(t?.restoreFocus?t.restoreFocus():d?.isConnected&&d.focus())}return n.addEventListener("abort",()=>x?.abort(),{once:!0}),{el:o,open:Y,close:()=>A(!1),get isOpen(){return!o.hidden}}}export{v as COLS,he as createEmojiPicker,ne as createEmojiSuggest,me as loadStylesheet,oe as step};
|
|
609
|
+
//# sourceMappingURL=emoji-picker-65VVVGYW.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function R(a){let{signal:s}=a,{h:r,uniqueId:x,avatar:C,otherMember:T,roomTitle:U,SEARCH_DEBOUNCE_MS:A}=a.kit,b=x("forward"),g=r("h2",{id:`${b}-title`}),l=r("input",{type:"search",autocomplete:"off",placeholder:"Search rooms and people","aria-label":"Search rooms and people","aria-controls":`${b}-list`}),i=r("p",{class:"search-status",role:"status"}),F=r("ul",{id:`${b}-list`,class:"search-results forward-list","aria-label":"Forward to"}),E=r("button",{type:"button",class:"cancel",on:{click:()=>h()},signal:s},"Cancel"),n=r("dialog",{class:"forward","aria-labelledby":g.id},[g,l,i,F,E]),d=[],c=!1,f=!1,w,u=null;function M(e,o,m){return r("li",{},r("button",{type:"button",class:"person",on:{click:()=>{k(m)}},signal:s},[o,r("span",{},e)]))}function p(){let e=l.value.trim().toLowerCase(),o=a.me(),m=a.rooms().filter(t=>U(t,o).toLowerCase().includes(e)),y=new Set(a.rooms().map(t=>T(t,o)?.id)),S=[...m.map(t=>{let v=T(t,o);return M(v?U(t,o):t.name,v?C(v,24,a.avatarUrl):r("span",{class:"hash"},"#"),{room:t})}),...(e?d.filter(t=>!y.has(t.id)&&t.name.toLowerCase().includes(e)):[]).map(t=>M(t.name,C(t,24,a.avatarUrl),{user:t}))];F.replaceChildren(...S),f||(i.textContent=S.length?"":c?"Searching\u2026":"Nothing found.")}async function D(e){if(u?.abort(),d=[],!e)return c=!1,p();let o=new AbortController;u=o;try{let m=await a.searchUsers(e,o.signal);u===o&&!s.aborted&&(d=m.filter(y=>!y.no_dms))}catch{}u!==o||s.aborted||(c=!1,p())}function L(e){f=e,n.classList.toggle("busy",e),E.disabled=e}async function k(e){if(f)return;L(!0),i.textContent="Forwarding\u2026";let o=await a.onPick(e);if(L(!1),!s.aborted){if(o===null)return h();i.textContent=o,n.open||n.showModal()}}function h(){clearTimeout(w),u?.abort(),n.open&&n.close()}return n.addEventListener("cancel",e=>f&&e.preventDefault(),{signal:s}),l.addEventListener("input",()=>{c=l.value.trim()!=="",p(),clearTimeout(w),w=setTimeout(()=>{D(l.value.trim())},A)},{signal:s}),s.addEventListener("abort",h,{once:!0}),{el:n,open(e){g.textContent=e===1?"Forward message":`Forward ${e} messages`,l.value="",d=[],c=!1,i.textContent="",p(),n.open||n.showModal(),l.focus()},close:h}}export{R as createForwardDialog};
|
|
2
|
+
//# sourceMappingURL=forward-66PELNWT.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../web/src/views/room/forward.ts"],
|
|
4
|
+
"sourcesContent": ["// Forward dialog (\u00A721.3): choose where messages go \u2014 a room, a DM, or someone you have no DM with yet (found by name).\n// A modal <dialog>: it keeps focus inside, Escape closes it, and focus goes back to where it was.\n//\n// A lazy chunk: the room view loads it when Forward is first chosen. It imports types only, and gets what it uses of\n// app.js in `kit` (lazy.ts FORWARD_KIT).\n\nimport type { h, uniqueId } from \"../../dom.ts\";\nimport type { otherMember, roomTitle } from \"../../lib/rooms.ts\";\nimport type { Room, User } from \"../../lib/types.ts\";\nimport type { AvatarUrl, avatar } from \"../../ui/avatar.ts\";\n\nexport interface ForwardKit {\n h: typeof h;\n uniqueId: typeof uniqueId;\n avatar: typeof avatar;\n otherMember: typeof otherMember;\n roomTitle: typeof roomTitle;\n /** How long typing pauses before people are searched (the people search's). */\n SEARCH_DEBOUNCE_MS: number;\n}\n\nexport type ForwardTo = { room: Room } | { user: User };\n\nexport interface ForwardDialog {\n readonly el: HTMLDialogElement;\n /** Open it for `count` messages. */\n open(count: number): void;\n close(): void;\n}\n\nexport function createForwardDialog(opts: {\n kit: ForwardKit;\n /** Where messages can go, in the order to offer them. */\n rooms: () => Room[];\n me: () => User | null;\n searchUsers: (query: string, signal: AbortSignal) => Promise<User[]>;\n avatarUrl: AvatarUrl;\n /** Forward there. Resolves to what went wrong, or null once it is done (the dialog then closes). */\n onPick: (to: ForwardTo) => Promise<string | null>;\n signal: AbortSignal;\n}): ForwardDialog {\n const { signal } = opts;\n const { h, uniqueId, avatar, otherMember, roomTitle, SEARCH_DEBOUNCE_MS } = opts.kit;\n const id = uniqueId(\"forward\");\n const title = h(\"h2\", { id: `${id}-title` });\n const input = h(\"input\", {\n type: \"search\",\n autocomplete: \"off\",\n placeholder: \"Search rooms and people\",\n \"aria-label\": \"Search rooms and people\",\n \"aria-controls\": `${id}-list`,\n });\n const status = h(\"p\", { class: \"search-status\", role: \"status\" });\n const list = h(\"ul\", { id: `${id}-list`, class: \"search-results forward-list\", \"aria-label\": \"Forward to\" });\n const cancel = h(\"button\", { type: \"button\", class: \"cancel\", on: { click: () => close() }, signal }, \"Cancel\");\n const el = h(\"dialog\", { class: \"forward\", \"aria-labelledby\": title.id }, [title, input, status, list, cancel]);\n\n let people: User[] = [];\n /** A people search is waiting for its debounce or its answer. */\n let searching = false;\n let busy = false;\n let timer: ReturnType<typeof setTimeout> | undefined;\n let inflight: AbortController | null = null;\n\n function target(label: string, icon: HTMLElement, to: ForwardTo): HTMLElement {\n return h(\n \"li\",\n {},\n h(\"button\", { type: \"button\", class: \"person\", on: { click: () => void pick(to) }, signal }, [icon, h(\"span\", {}, label)]),\n );\n }\n\n function show() {\n const q = input.value.trim().toLowerCase();\n const me = opts.me();\n const rooms = opts.rooms().filter((r) => roomTitle(r, me).toLowerCase().includes(q));\n // Someone you already have a DM with is offered as that DM. Only DMs: sharing a private room with someone is no\n // way to reach them alone.\n const inDms = new Set(opts.rooms().map((r) => otherMember(r, me)?.id));\n const items = [\n ...rooms.map((r) => {\n const other = otherMember(r, me);\n // A room's name after its \"#\" icon: its title, \"#name\", would say \"#\" twice.\n return target(other ? roomTitle(r, me) : r.name, other ? avatar(other, 24, opts.avatarUrl) : h(\"span\", { class: \"hash\" }, \"#\"), {\n room: r,\n });\n }),\n // (Found for an earlier query, until this one's answer comes: only those that still match.)\n ...(q ? people.filter((u) => !inDms.has(u.id) && u.name.toLowerCase().includes(q)) : []).map((u) =>\n target(u.name, avatar(u, 24, opts.avatarUrl), { user: u }),\n ),\n ];\n list.replaceChildren(...items);\n if (!busy) status.textContent = items.length ? \"\" : searching ? \"Searching\u2026\" : \"Nothing found.\";\n }\n\n async function search(q: string) {\n inflight?.abort();\n people = [];\n if (!q) {\n searching = false;\n return show();\n }\n const ac = new AbortController();\n inflight = ac;\n try {\n const found = await opts.searchUsers(q, ac.signal);\n if (inflight === ac && !signal.aborted) people = found.filter((u) => !u.no_dms); // no DM with them (\u00A716.7)\n } catch {\n /* rooms still show; people are a bonus */\n }\n if (inflight !== ac || signal.aborted) return;\n searching = false;\n show();\n }\n\n function setBusy(on: boolean) {\n busy = on;\n el.classList.toggle(\"busy\", on);\n cancel.disabled = on; // what happens to the forward must be seen: it can't be called off once sent\n }\n\n async function pick(to: ForwardTo) {\n if (busy) return;\n setBusy(true);\n status.textContent = \"Forwarding\u2026\";\n const problem = await opts.onPick(to);\n setBusy(false);\n if (signal.aborted) return;\n if (problem === null) return close();\n status.textContent = problem;\n if (!el.open) el.showModal(); // closed anyway meanwhile (a second Escape can't be refused): say what went wrong\n }\n\n function close() {\n clearTimeout(timer);\n inflight?.abort();\n if (el.open) el.close();\n }\n\n // Escape while forwarding: stay open until it is done.\n el.addEventListener(\"cancel\", (e) => busy && e.preventDefault(), { signal });\n input.addEventListener(\n \"input\",\n () => {\n searching = input.value.trim() !== \"\";\n show();\n clearTimeout(timer);\n timer = setTimeout(() => void search(input.value.trim()), SEARCH_DEBOUNCE_MS);\n },\n { signal },\n );\n signal.addEventListener(\"abort\", close, { once: true });\n\n return {\n el,\n open(count) {\n title.textContent = count === 1 ? \"Forward message\" : `Forward ${count} messages`;\n input.value = \"\";\n people = [];\n searching = false;\n status.textContent = \"\";\n show();\n if (!el.open) el.showModal();\n input.focus();\n },\n close,\n };\n}\n"],
|
|
5
|
+
"mappings": "AA8BO,SAASA,EAAoBC,EAUlB,CAChB,GAAM,CAAE,OAAAC,CAAO,EAAID,EACb,CAAE,EAAAE,EAAG,SAAAC,EAAU,OAAAC,EAAQ,YAAAC,EAAa,UAAAC,EAAW,mBAAAC,CAAmB,EAAIP,EAAK,IAC3EQ,EAAKL,EAAS,SAAS,EACvBM,EAAQP,EAAE,KAAM,CAAE,GAAI,GAAGM,CAAE,QAAS,CAAC,EACrCE,EAAQR,EAAE,QAAS,CACvB,KAAM,SACN,aAAc,MACd,YAAa,0BACb,aAAc,0BACd,gBAAiB,GAAGM,CAAE,OACxB,CAAC,EACKG,EAAST,EAAE,IAAK,CAAE,MAAO,gBAAiB,KAAM,QAAS,CAAC,EAC1DU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K,CAAK,EAClBC,GAAU,MAAM,EACZL,EAAG,MAAMA,EAAG,MAAM,CACxB,CAGA,OAAAA,EAAG,iBAAiB,SAAW,GAAMG,GAAQ,EAAE,eAAe,EAAG,CAAE,OAAAjB,CAAO,CAAC,EAC3ES,EAAM,iBACJ,QACA,IAAM,CACJO,EAAYP,EAAM,MAAM,KAAK,IAAM,GACnCgB,EAAK,EACL,aAAaP,CAAK,EAClBA,EAAQ,WAAW,IAAG,CAAQgB,EAAOzB,EAAM,MAAM,KAAK,CAAC,GAAGH,CAAkB,CAC9E,EACA,CAAE,OAAAN,CAAO,CACX,EACAA,EAAO,iBAAiB,QAASa,EAAO,CAAE,KAAM,EAAK,CAAC,EAE/C,CACL,GAAAC,EACA,KAAK0B,EAAO,CACVhC,EAAM,YAAcgC,IAAU,EAAI,kBAAoB,WAAWA,CAAK,YACtE/B,EAAM,MAAQ,GACdM,EAAS,CAAC,EACVC,EAAY,GACZN,EAAO,YAAc,GACrBe,EAAK,EACAX,EAAG,MAAMA,EAAG,UAAU,EAC3BL,EAAM,MAAM,CACd,EACA,MAAAI,CACF,CACF",
|
|
6
|
+
"names": ["createForwardDialog", "opts", "signal", "h", "uniqueId", "avatar", "otherMember", "roomTitle", "SEARCH_DEBOUNCE_MS", "id", "title", "input", "status", "list", "cancel", "close", "el", "people", "searching", "busy", "timer", "inflight", "target", "label", "icon", "to", "pick", "show", "q", "me", "rooms", "r", "inDms", "items", "other", "u", "search", "ac", "found", "setBusy", "on", "problem", "count"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
.inbox-list{max-width:760px;margin:0;padding:12px 20px 8px;list-style:none}.inbox-list a{display:flex;gap:12px;padding:10px 12px;border-radius:12px;color:inherit;text-decoration:none}@media(hover:hover){.inbox-list a:hover{background:var(--hover)}}.inbox-list .new a{background:var(--tint)}.inbox-list .avatar{flex:none;margin-top:2px}.inbox-body{flex:1;min-width:0}.inbox-body p{margin:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.inbox-body .inbox-what{color:var(--muted);white-space:normal;overflow-wrap:anywhere}.inbox-what strong{color:var(--fg)}.inbox-what time{margin-left:8px;white-space:nowrap;color:var(--dim);font-size:.75rem}.inbox-quote{color:var(--dim);font-size:.8125rem}.inbox-quote:before{content:"\21b3 "}.inbox-text{margin-top:2px}.inbox-status{padding:24px 32px;color:var(--dim)}.inbox-status:empty{display:none}.inbox-more{margin:4px 32px 32px}
|
|
2
|
+
/*# sourceMappingURL=inbox-3FSOPY2T.css.map */
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../web/styles/inbox.css"],
|
|
4
|
+
"sourcesContent": ["/* \"Mentions & replies\" (DESIGN.md \u00A741). Not part of app.css: the chunk links this file when the page first shows. Uses\n app.css's custom properties and its .room-header. */\n\n.inbox-list {\n max-width: calc(720px + 2 * 20px);\n margin: 0;\n padding: 12px 20px 8px;\n list-style: none;\n}\n\n.inbox-list a {\n display: flex;\n gap: 12px;\n padding: 10px 12px;\n border-radius: 12px;\n color: inherit;\n text-decoration: none;\n}\n\n@media (hover: hover) {\n .inbox-list a:hover {\n background: var(--hover);\n }\n}\n\n/* Not seen before this visit. */\n.inbox-list .new a {\n background: var(--tint);\n}\n\n.inbox-list .avatar {\n flex: none;\n margin-top: 2px;\n}\n\n.inbox-body {\n flex: 1;\n min-width: 0;\n}\n\n.inbox-body p {\n margin: 0;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n\n/* Who did what, where and when wraps: on a phone one line cut the room's name and the time off (QA BUG-251). */\n.inbox-body .inbox-what {\n color: var(--muted);\n white-space: normal;\n overflow-wrap: anywhere;\n}\n\n.inbox-what strong {\n color: var(--fg);\n}\n\n.inbox-what time {\n margin-left: 8px;\n white-space: nowrap;\n color: var(--dim);\n font-size: 0.75rem;\n}\n\n.inbox-quote {\n color: var(--dim);\n font-size: 0.8125rem;\n}\n\n.inbox-quote::before {\n content: \"\u21B3 \";\n}\n\n.inbox-text {\n margin-top: 2px;\n}\n\n.inbox-status {\n padding: 24px 32px;\n color: var(--dim);\n}\n\n.inbox-status:empty {\n display: none;\n}\n\n.inbox-more {\n margin: 4px 32px 32px;\n}\n"],
|
|
5
|
+
"mappings": "AAGA,CAAC,WACC,UAAW,MAJb,OAKU,EALV,QAMW,KAAK,KAAK,IACnB,WAAY,IACd,CAEA,CAPC,WAOW,EACV,QAAS,KACT,IAAK,KAZP,QAaW,KAAK,KAbhB,cAciB,KACf,MAAO,QACP,gBAAiB,IACnB,CAEA,OAAO,MAAQ,OACb,CAjBD,WAiBa,CAAC,OACX,WAAY,IAAI,QAClB,CACF,CAGA,CAvBC,WAuBW,CAAC,IAAI,EACf,WAAY,IAAI,OAClB,CAEA,CA3BC,WA2BW,CAAC,OACX,KAAM,KACN,WAAY,GACd,CAEA,CAAC,WACC,KAAM,EACN,UAAW,CACb,CAEA,CALC,WAKW,EAxCZ,OAyCU,EACR,SAAU,OACV,cAAe,SACf,YAAa,MACf,CAGA,CAbC,WAaW,CAAC,WACX,MAAO,IAAI,SACX,YAAa,OACb,cAAe,QACjB,CAEA,CANa,WAMD,OACV,MAAO,IAAI,KACb,CAEA,CAVa,WAUD,KACV,YAAa,IACb,YAAa,OACb,MAAO,IAAI,OACX,UAAW,MACb,CAEA,CAAC,YACC,MAAO,IAAI,OACX,UAAW,QACb,CAEA,CALC,WAKW,QACV,QAAS,SACX,CAEA,CAAC,WACC,WAAY,GACd,CAEA,CAAC,aA9ED,QA+EW,KAAK,KACd,MAAO,IAAI,MACb,CAEA,CALC,YAKY,OACX,QAAS,IACX,CAEA,CAAC,WAvFD,OAwFU,IAAI,KAAK,IACnB",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var f=null;function k(n){return f??=new Promise(s=>{let t=n("link",{rel:"stylesheet",href:"/assets/inbox-3FSOPY2T.css",on:{load:()=>s(),error:()=>{t.remove(),f=null,s()}}});document.head.append(t)}),f}function C(n,s){let i=s?` in ${s}`:"";return n.kind==="reaction"?` reacted ${n.emoji} to your message${i}`:n.kind==="reply"?` replied to you${i}`:` mentioned you${i}`}var y=n=>n.text||(n.files?n.files===1?"Attachment":`${n.files} attachments`:"Message deleted");async function L(n,s){let{api:i,h:t,store:d,signal:a}=s;if(await k(t),a.aborted)return;let p=t("ul",{class:"inbox-list"}),u=t("p",{class:"inbox-status",role:"status"},"Loading\u2026"),b=t("button",{type:"button",class:"inbox-more",hidden:!0},"Show older");n.replaceChildren(t("section",{class:"inbox","aria-labelledby":"inbox-title"},[t("header",{class:"room-header"},[t("a",{href:"/",class:"back ic i-back","aria-label":"Back to rooms"}),t("h1",{id:"inbox-title"},"Mentions & replies")]),p,u,b]));let x=()=>document.querySelectorAll('a[href="/inbox"]');for(let e of x())e.setAttribute("aria-current","page");a.addEventListener("abort",()=>{for(let e of x())e.removeAttribute("aria-current")});let l=null,r=[],c="",m=!1,w=(e="")=>i.request("/api/chat/inbox",{query:e?{before:e}:{},signal:a});function I(e){let o=s.roomName(e.room);return t("li",{class:l!==null&&e.created>l?"new":""},t("a",{href:`/r/${e.room}/m/${e.message.id}`},[s.avatar(e.actor),t("div",{class:"inbox-body"},[t("p",{class:"inbox-what"},[t("strong",{},e.actor.name),C(e,o),t("time",{dateTime:e.created},s.when(e.created))]),e.quote?t("p",{class:"inbox-quote"},y(e.quote)):null,t("p",{class:"inbox-text"},y(e.message))])]))}function g(){p.replaceChildren(...r.map(I)),u.textContent=r.length?"":"Nothing here yet. When someone mentions you, replies to you or reacts to your message, it shows here.",b.hidden=!c}function v(){let e=r[0]?.created;e&&(l===null||e>l||d.get().inbox)&&(d.set({inbox:0}),i.request("/api/chat/inbox/seen",{method:"POST",body:{at:e}}).catch(()=>{}))}async function h(e){if(!m){m=!0;try{let o=await w(e?"":c);if(a.aborted)return;l??=o.seen_at,e?r=o.items:r=[...r,...o.items.filter(S=>!r.some(A=>A.id===S.id))],(!e||!c||!r.length)&&(c=o.more?o.items.at(-1)?.cursor??"":""),g(),v()}catch{a.aborted||(u.textContent="Couldn't load your mentions and replies. Check your connection.")}finally{m=!1}}}b.addEventListener("click",()=>{h(!1)},{signal:a}),i.subscribeInbox(e=>{a.aborted||e.action!=="delete"||!r.some(o=>o.id===e.id)||(r=r.filter(o=>o.id!==e.id),g())}).then(e=>{a.aborted?e().catch(()=>{}):a.addEventListener("abort",()=>{e().catch(()=>{})},{once:!0})},()=>{}),a.addEventListener("abort",d.subscribe((e,o)=>e.inbox>o.inbox&&void h(!0)),{once:!0}),await h(!0)}export{L as mountInbox};
|
|
2
|
+
//# sourceMappingURL=inbox-TZJWPRTG.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../web/src/views/inbox.ts"],
|
|
4
|
+
"sourcesContent": ["// \"Mentions & replies\" (\u00A741), /inbox, next to the room list: the messages that mention you, the replies to your\n// messages and the reactions to them, newest first, each a link to it in its room. What you hadn't seen is marked, and\n// opening the page sees it. New ones come in at the top while it is open.\n//\n// A lazy chunk with its own stylesheet (styles/inbox.css), like the media grid (\u00A730.2): app.ts import()s it for the\n// route. It imports types only; what it needs from app.js comes in its options.\n\nimport type { Api } from \"../api.ts\";\nimport type { h as H } from \"../dom.ts\";\nimport type { InboxItem, User } from \"../lib/types.ts\";\nimport type { AppState, Store } from \"../store.ts\";\n\n/** The stylesheet's URL, set by the build (scripts/lib/build-utils.mjs). */\ndeclare const INBOX_CSS: string;\n\nexport interface InboxOptions {\n api: Api;\n h: typeof H;\n store: Store<AppState>;\n /** A user's avatar at 32 px. */\n avatar: (u: User) => HTMLElement;\n /** How a room is named: \"#name\", or a DM's other member. \"\" when it isn't one you have. */\n roomName: (id: string) => string;\n /** When, for people: \"Today 10:42\", \"Oct 10\". */\n when: (created: string) => string;\n signal: AbortSignal;\n}\n\ninterface Page {\n items: InboxItem[];\n more: boolean;\n seen_at: string;\n}\n\nlet sheet: Promise<void> | null = null;\nfunction loadStylesheet(h: typeof H): Promise<void> {\n sheet ??= new Promise((resolve) => {\n const failed = () => {\n link.remove();\n sheet = null;\n resolve();\n };\n const link = h(\"link\", { rel: \"stylesheet\", href: INBOX_CSS, on: { load: () => resolve(), error: failed } });\n document.head.append(link);\n });\n return sheet;\n}\n\n/** What a row says happened, after who did it. */\nfunction what(item: InboxItem, room: string): string {\n const where = room ? ` in ${room}` : \"\";\n if (item.kind === \"reaction\") return ` reacted ${item.emoji} to your message${where}`;\n return item.kind === \"reply\" ? ` replied to you${where}` : ` mentioned you${where}`;\n}\n\n/** A message's words on one line, or what it has instead. */\nconst words = (m: { text: string; files: number }) =>\n m.text || (m.files ? (m.files === 1 ? \"Attachment\" : `${m.files} attachments`) : \"Message deleted\");\n\nexport async function mountInbox(root: HTMLElement, o: InboxOptions): Promise<void> {\n const { api, h, store, signal } = o;\n await loadStylesheet(h);\n if (signal.aborted) return;\n\n const list = h(\"ul\", { class: \"inbox-list\" });\n const status = h(\"p\", { class: \"inbox-status\", role: \"status\" }, \"Loading\u2026\");\n const more = h(\"button\", { type: \"button\", class: \"inbox-more\", hidden: true }, \"Show older\");\n root.replaceChildren(\n h(\"section\", { class: \"inbox\", \"aria-labelledby\": \"inbox-title\" }, [\n h(\"header\", { class: \"room-header\" }, [\n h(\"a\", { href: \"/\", class: \"back ic i-back\", \"aria-label\": \"Back to rooms\" }),\n h(\"h1\", { id: \"inbox-title\" }, \"Mentions & replies\"),\n ]),\n list,\n status,\n more,\n ]),\n );\n // The sidebar's row says you are here (it isn't drawn again for a page that isn't a room's).\n const rows = () => document.querySelectorAll('a[href=\"/inbox\"]');\n for (const a of rows()) a.setAttribute(\"aria-current\", \"page\");\n signal.addEventListener(\"abort\", () => {\n for (const a of rows()) a.removeAttribute(\"aria-current\");\n });\n\n /** Seen before this visit: newer ones are marked new. */\n let seenAt: string | null = null;\n let shown: InboxItem[] = [];\n let cursor = \"\";\n let loading = false;\n\n const fetchPage = (before = \"\") => api.request<Page>(\"/api/chat/inbox\", { query: before ? { before } : {}, signal });\n\n function row(item: InboxItem): HTMLElement {\n const room = o.roomName(item.room);\n return h(\n \"li\",\n { class: seenAt !== null && item.created > seenAt ? \"new\" : \"\" },\n h(\"a\", { href: `/r/${item.room}/m/${item.message.id}` }, [\n o.avatar(item.actor),\n h(\"div\", { class: \"inbox-body\" }, [\n h(\"p\", { class: \"inbox-what\" }, [\n h(\"strong\", {}, item.actor.name),\n what(item, room),\n h(\"time\", { dateTime: item.created }, o.when(item.created)),\n ]),\n item.quote ? h(\"p\", { class: \"inbox-quote\" }, words(item.quote)) : null,\n h(\"p\", { class: \"inbox-text\" }, words(item.message)),\n ]),\n ]),\n );\n }\n\n function render() {\n list.replaceChildren(...shown.map(row));\n status.textContent = shown.length\n ? \"\"\n : \"Nothing here yet. When someone mentions you, replies to you or reacts to your message, it shows here.\";\n more.hidden = !cursor;\n }\n\n /** You have seen everything listed: the server and the sidebar's count hear of it. */\n function seeAll() {\n const newest = shown[0]?.created;\n if (newest && (seenAt === null || newest > seenAt || store.get().inbox)) {\n store.set({ inbox: 0 });\n void api.request(\"/api/chat/inbox/seen\", { method: \"POST\", body: { at: newest } }).catch(() => {});\n }\n }\n\n async function load(first: boolean) {\n if (loading) return;\n loading = true;\n try {\n const page = await fetchPage(first ? \"\" : cursor);\n if (signal.aborted) return;\n seenAt ??= page.seen_at;\n if (first) shown = page.items;\n else shown = [...shown, ...page.items.filter((i) => !shown.some((s) => s.id === i.id))];\n // Paging from the top again keeps how far \"Show older\" had got.\n if (!first || !cursor || !shown.length) cursor = page.more ? (page.items.at(-1)?.cursor ?? \"\") : \"\";\n render();\n seeAll();\n } catch {\n if (!signal.aborted) status.textContent = \"Couldn't load your mentions and replies. Check your connection.\";\n } finally {\n loading = false;\n }\n }\n\n more.addEventListener(\"click\", () => void load(false), { signal });\n // A row taken away while you look (its message deleted, the mention edited out, the reaction taken back) goes, rather\n // than leading to a message that isn't there (QA BUG-254).\n api\n .subscribeInbox((ev) => {\n if (signal.aborted || ev.action !== \"delete\" || !shown.some((i) => i.id === ev.id)) return;\n shown = shown.filter((i) => i.id !== ev.id);\n render();\n })\n .then(\n (stop) => {\n if (signal.aborted) void stop().catch(() => {});\n else signal.addEventListener(\"abort\", () => void stop().catch(() => {}), { once: true });\n },\n () => {}, // offline: the list is fetched again when something new comes\n );\n // Something new (or taken back) while you look: the top again.\n signal.addEventListener(\n \"abort\",\n store.subscribe((s, prev) => s.inbox > prev.inbox && void load(true)),\n { once: true },\n );\n await load(true);\n}\n"],
|
|
5
|
+
"mappings": "AAkCA,IAAIA,EAA8B,KAClC,SAASC,EAAeC,EAA4B,CAClD,OAAAF,IAAU,IAAI,QAASG,GAAY,CAMjC,IAAMC,EAAOF,EAAE,OAAQ,CAAE,IAAK,aAAc,KAAM,6BAAW,GAAI,CAAE,KAAM,IAAMC,EAAQ,EAAG,MAL3E,IAAM,CACnBC,EAAK,OAAO,EACZJ,EAAQ,KACRG,EAAQ,CACV,CACwG,CAAE,CAAC,EAC3G,SAAS,KAAK,OAAOC,CAAI,CAC3B,CAAC,EACMJ,CACT,CAGA,SAASK,EAAKC,EAAiBC,EAAsB,CACnD,IAAMC,EAAQD,EAAO,OAAOA,CAAI,GAAK,GACrC,OAAID,EAAK,OAAS,WAAmB,YAAYA,EAAK,KAAK,mBAAmBE,CAAK,GAC5EF,EAAK,OAAS,QAAU,kBAAkBE,CAAK,GAAK,iBAAiBA,CAAK,EACnF,CAGA,IAAMC,EAASC,GACbA,EAAE,OAASA,EAAE,MAASA,EAAE,QAAU,EAAI,aAAe,GAAGA,EAAE,KAAK,eAAkB,mBAEnF,eAAsBC,EAAWC,EAAmBC,EAAgC,CAClF,GAAM,CAAE,IAAAC,EAAK,EAAAZ,EAAG,MAAAa,EAAO,OAAAC,CAAO,EAAIH,EAElC,GADA,MAAMZ,EAAeC,CAAC,EAClBc,EAAO,QAAS,OAEpB,IAAMC,EAAOf,EAAE,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EAAE,GAAG,QAAU,GAAM,IACjGL,EAAO,EACPC,EAAO,CACT,MAAQ,CACDd,EAAO,UAASE,EAAO,YAAc,kEAC5C,QAAE,CACAO,EAAU,EACZ,EACF,CAEAN,EAAK,iBAAiB,QAAS,IAAG,CAAQa,EAAK,EAAK,GAAG,CAAE,OAAAhB,CAAO,CAAC,EAGjEF,EACG,eAAgBuB,GAAO,CAClBrB,EAAO,SAAWqB,EAAG,SAAW,UAAY,CAACd,EAAM,KAAMY,GAAMA,EAAE,KAAOE,EAAG,EAAE,IACjFd,EAAQA,EAAM,OAAQY,GAAMA,EAAE,KAAOE,EAAG,EAAE,EAC1CR,EAAO,EACT,CAAC,EACA,KACES,GAAS,CACJtB,EAAO,QAAcsB,EAAK,EAAE,MAAM,IAAM,CAAC,CAAC,EACzCtB,EAAO,iBAAiB,QAAS,IAAG,CAAQsB,EAAK,EAAE,MAAM,IAAM,CAAC,CAAC,GAAG,CAAE,KAAM,EAAK,CAAC,CACzF,EACA,IAAM,CAAC,CACT,EAEFtB,EAAO,iBACL,QACAD,EAAM,UAAU,CAACqB,EAAGG,IAASH,EAAE,MAAQG,EAAK,OAAS,KAAKP,EAAK,EAAI,CAAC,EACpE,CAAE,KAAM,EAAK,CACf,EACA,MAAMA,EAAK,EAAI,CACjB",
|
|
6
|
+
"names": ["sheet", "loadStylesheet", "h", "resolve", "link", "what", "item", "room", "where", "words", "m", "mountInbox", "root", "o", "api", "store", "signal", "list", "status", "more", "rows", "a", "seenAt", "shown", "cursor", "loading", "fetchPage", "before", "row", "render", "seeAll", "newest", "load", "first", "page", "i", "s", "ev", "stop", "prev"]
|
|
7
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var oe="/api/collections/collections/records",D=o=>JSON.stringify(o),Ae="id,collection,file,name,video,poster,created";function _(o){return{get:(e,n)=>o.request(`${oe}/${e}`,{query:{expand:"owner",fields:"id,name,public,owner,items,expand.owner.name"},signal:n}),create:(e,n,a)=>o.request(oe,{method:"POST",body:{owner:e,name:n,public:a},query:{fields:"id"}}),update:(e,n)=>o.request(`${oe}/${e}`,{method:"PATCH",body:n,query:{fields:"name,public"}}),remove:e=>o.request(`${oe}/${e}`,{method:"DELETE"}),async items(e,n,a,i=!1){let d=i?">":"<",m=n?` && (created ${d} ${D(n.created)} || (created = ${D(n.created)} && id ${d} ${D(n.id)}))`:"",g={filter:`collection = ${D(e)}${m}`,sort:"-created,-id",perPage:61,skipTotal:!0,fields:Ae},{items:b}=await o.request("/api/collections/collection_items/records",{query:g,signal:a});return{items:b.slice(0,60),more:b.length>60}},async idsSince(e,n,a){let i=new Set,d=`collection = ${D(e)} && (created > ${D(n.created)} || (created = ${D(n.created)} && id >= ${D(n.id)}))`;for(let m=1;;m++){let g={filter:d,sort:"-created,-id",page:m,perPage:1e3,skipTotal:!0,fields:"id"},{items:b}=await o.request("/api/collections/collection_items/records",{query:g,signal:a});for(let p of b)i.add(p.id);if(b.length<1e3)return i}},save:(e,n)=>o.request("/api/chat/items",{method:"POST",body:{collection:e,...n}}),upload:(e,n,a)=>o.request("/api/chat/items",{method:"POST",body:{collection:e,file:n},onUpload:a}),unsave:e=>o.request(`/api/chat/items/${e}`,{method:"DELETE"}),savedIn:(e,n)=>o.request("/api/chat/saved",{query:e,signal:n}),follow:(e,n)=>o.request("/api/chat/subs",{method:"POST",body:{collection:e,on:n}})}}var le=null;function N(o){return le??=new Promise(e=>{let a=o("link",{rel:"stylesheet",href:"/assets/collections-VEOIOCAW.css",on:{load:()=>e(),error:()=>{a.remove(),le=null,e()}}});document.head.append(a)}),le}var ye=/\.(jpe?g|png|gif|webp|avif|mp4|m4v|webm|mov|ogv)$/i,Ce=".jpg,.jpeg,.png,.gif,.webp,.avif,.mp4,.m4v,.webm,.mov,.ogv",we=20*1024*1024,O=o=>o.list()??{mine:[],subs:[]};function ce(o,e){return new Promise(n=>{let a=()=>{i(),clearTimeout(d),n()},i=o.watch(a),d=setTimeout(a,e)})}function B(o){let e=o;return e?.status===0?"Can't reach the server. Check your connection.":Object.values(e?.fields??{})[0]||e?.message||"Something went wrong."}var q=o=>o("span",{class:"ci","aria-hidden":"true"}),xe=new Intl.DateTimeFormat(void 0,{month:"long",year:"numeric"}),Se=o=>new Date(o.replace(" ","T"));function de(o){let{id:e,created:n,file:a,name:i}=o;return{id:e,room:"",author:"",text:"",created:n,updated:n,edited_at:"",deleted:!1,files:[a],file_names:{[a]:i}}}function ie(o,e,n){if(e.video&&!e.poster)return null;let a=o.h("img",{src:e.video?o.api.itemPosterUrl(e):o.api.itemUrl(e,"240x240"),alt:"",loading:"lazy",decoding:"async"});return e.video&&a.addEventListener("error",()=>a.remove(),{signal:n}),a}function Y(o,e,n){let a=[],i=!1,d=null;return{items:a,get done(){return i},next(){return i?Promise.resolve([]):(d??=_(o.api).items(e,a.at(-1),n).then(m=>(d=null,i=!m.more,a.push(...m.items),m.items),m=>{throw d=null,m}),d)}}}async function Oe(o){let{h:e}=o,n=new AbortController,{signal:a}=n;o.signal.addEventListener("abort",()=>y(),{signal:a});let i=e("h2",{id:"coll-create-title"},[q(e)," New collection"]),d=e("input",{required:!0,autocomplete:"off","aria-label":"Name",placeholder:"Name"}),m=e("input",{type:"checkbox",role:"switch",class:"switch"}),g=e("p",{class:"coll-status",role:"alert"}),b=e("button",{type:"submit",class:"primary"},"Create"),p=e("form",{class:"coll-body",on:{submit:async w=>{if(w.preventDefault(),!b.disabled){b.disabled=!0,g.textContent="";try{let{id:M}=await _(o.api).create(o.me()?.id??"",d.value,m.checked);o.service.refresh(),y(!1),o.onCreated(M)}catch(M){g.textContent=B(M)}finally{b.disabled=!1}}}},signal:a},[e("p",{class:"coll-new-form"},[d,b]),e("label",{class:"coll-public"},[m,"Public: anyone can see it and subscribe"]),g]),x=e("dialog",{class:"coll-dialog coll-create","aria-labelledby":i.id},[e("header",{class:"media-bar"},[i,e("button",{type:"button",class:"icon-button ic i-x","aria-label":"Close",on:{click:()=>y()},signal:a})]),p]);function y(w=!0){a.aborted||(n.abort(),x.open&&x.close(),x.remove(),w&&o.opener.focus())}x.addEventListener("close",()=>y(),{signal:a}),await N(e),!a.aborted&&(document.body.append(x),x.showModal(),d.focus())}var ue=null;async function se(o){ue?.();let{h:e}=o,n=_(o.api),a=new AbortController,{signal:i}=a;o.signal.addEventListener("abort",()=>A(),{signal:i});let d=e("h2",{id:"coll-save-title"},[q(e)," Save to collection"]),m=e("ul",{class:"coll-choices"}),g=e("p",{class:"coll-status",role:"status"},"Loading\u2026"),b=e("input",{placeholder:"New collection","aria-label":"New collection name",autocomplete:"off"}),p=e("form",{class:"coll-new-form",on:{submit:async v=>{if(v.preventDefault(),!!b.value.trim())try{let r=(await n.create(o.me()?.id??"",b.value,!1)).id;b.value="",await M(r,!0)}catch(r){g.textContent=B(r)}}},signal:i},[b,e("button",{type:"submit"},"Create")]),x=e("dialog",{class:"coll-dialog coll-save","aria-labelledby":d.id},[e("header",{class:"media-bar"},[d,e("button",{type:"button",class:"icon-button ic i-x","aria-label":"Close",on:{click:()=>A()},signal:i})]),e("div",{class:"coll-body"},[m,g,p])]),y={},w=new Map;async function M(v,r){w.set(v,r),g.textContent=r?"Saving\u2026":"Removing\u2026",h();try{r?y[v]=(await n.save(v,o.from)).id:y[v]&&(await n.unsave(y[v]),delete y[v]),g.textContent=r?"Saved.":"Removed.",o.service.refresh()}catch(S){S.status===409?y=await n.savedIn(o.from,i).catch(()=>y):g.textContent=B(S)}w.delete(v),h()}function h(){let v=O(o).mine;m.replaceChildren(...v.map(r=>{let S=e("input",{type:"checkbox",checked:w.get(r.id)??!!y[r.id],disabled:w.has(r.id)});return S.addEventListener("change",()=>{M(r.id,S.checked)},{signal:i}),e("li",{"aria-busy":w.has(r.id)?"true":"false"},e("label",{},[S," ",r.name,e("span",{class:"coll-meta"},r.public?" \xB7 Public: anyone can see it":" \xB7 Private"),w.has(r.id)?e("span",{class:"coll-spin","aria-hidden":"true"}):null]))})),!v.length&&g.textContent===""&&(g.textContent="You have no collections yet. Make one:")}function A(){i.aborted||(a.abort(),ue=null,x.open&&x.close(),x.remove(),o.opener.setAttribute("aria-expanded","false"),o.opener.focus())}if(ue=A,x.addEventListener("close",()=>A(),{signal:i}),i.addEventListener("abort",o.watch(h),{once:!0}),await N(e),!i.aborted){document.body.append(x),x.showModal(),o.opener.setAttribute("aria-expanded","true");try{y=await n.savedIn(o.from,i),g.textContent=""}catch(v){if(i.aborted)return;g.textContent=B(v)}h(),(m.querySelector("input")??b).focus()}}async function qe(o,e){let{h:n,api:a,signal:i,id:d}=e,m=_(a),[,g]=await Promise.all([N(n),m.get(d,i).catch(()=>null),(async()=>{e.me()&&!e.list()&&await ce(e,2e3)})()]);if(i.aborted)return;function b(){o.replaceChildren(n("section",{class:"collection not-found"},[n("h1",{},[q(n)," This collection doesn't exist."]),n("p",{},["It may be private, or deleted. ",n("a",{href:"/"},"Back to rooms")])]))}if(!g)return b();let p=g,x=e.me(),y=!!x&&p.owner===x.id,w=g.expand?.owner?.name??"",M=O(e).subs.find(t=>t.id===d)?.seen_at??"",h=Y(e,d,i),A=n("h1",{id:"coll-title"}),v=n("p",{class:"coll-meta"}),r=n("div",{class:"coll-actions"}),S=n("p",{class:"coll-notice",role:"status"}),z=n("p",{class:"coll-new",hidden:!0}),P=n("div",{class:"media-grid coll-grid"}),$=n("p",{class:"media-status",role:"status"});o.replaceChildren(n("section",{class:"collection","aria-labelledby":"coll-title"},[n("header",{class:`coll-head t${d.charCodeAt(0)%4}`},[n("a",{href:"/",class:"back ic i-back","aria-label":"Back to rooms"}),A,v,r,S]),z,P,$]));let R=(t,s)=>{S.textContent=`Couldn't ${t}. ${B(s)}`},I=(t,s,l="")=>n("button",{type:"button",class:l,on:{click:()=>{s()}},signal:i},t),F=t=>`${t} ${t===1?"item":"items"}`,J=()=>y?"Nothing here yet. Upload images and videos, or save them from the chat.":"Nothing here yet.",L=[],c=0,E=!1,H=[],W=n("input",{type:"file",multiple:!0,accept:Ce,hidden:!0,on:{change:()=>{ae([...W.files??[]]),W.value=""}},signal:i});function ae(t){for(let s of t)ye.test(s.name)?s.size>we?H.push(`${s.name}: larger than 20 MB`):L.push(s):H.push(`${s.name}: not an image or video`);if(!E){if(!L.length)return me();E=!0,(async()=>{for(;L.length&&!i.aborted;){let s=L[0],l=`Uploading ${c+1} of ${c+L.length}\u2026`;S.textContent=l;try{await m.upload(d,s,f=>S.textContent=`${l} ${Math.round(f*100)}%`)}catch(f){if(f.status===429){S.textContent="Waiting for the server\u2026",await new Promise(u=>setTimeout(u,1e4));continue}H.push(`${s.name}: ${B(f)}`)}L.shift(),c++,e.service.refresh()}c=0,E=!1,me()})()}}function me(){S.textContent=H.length?`Couldn't upload ${H.join("; ")}`:"",H=[]}let K=!1,G="",Q="";function Z(){K=!1,Q="",j()}async function pe(t){try{return p={...p,...await m.update(d,t)},S.textContent="",e.service.refresh(),Z(),!0}catch(s){return R("save",s),!1}}function Ee(){K=!0,G="Rename";let t=n("input",{value:p.name,"aria-label":"Collection name",autocomplete:"off"}),s=n("form",{class:"coll-rename",on:{submit:l=>{l.preventDefault(),pe({name:t.value})},keydown:l=>l.key==="Escape"&&Z()},signal:i},[t,n("button",{type:"submit"},"Save"),I("Cancel",Z,"link")]);r.replaceChildren(s),t.focus(),t.select()}function ke(){K=!0,G="Delete",r.replaceChildren(n("span",{},`Delete \u201C${p.name}\u201D${p.items?` and its ${F(p.items)}`:""}? This can't be undone.`),I("Delete collection",async()=>{try{await m.remove(d),e.service.refresh(),e.navigate("/")}catch(t){R("delete it",t)}},"danger"),I("Cancel",Z,"link")),r.querySelector("button")?.focus()}function j(){if(i.aborted)return;A.replaceChildren(q(n)," ",p.name),v.textContent=[y?"Yours":w&&`By ${w}`,p.public?"Public":"Private",F(p.items)].filter(Boolean).join(" \xB7 ");let t=O(e).subs.some(u=>u.id===d),s=[p.public,t].join();if(K||s===Q)return;Q=s;let l=[...r.children].findIndex(u=>u.contains(document.activeElement));if(y)r.replaceChildren(I("Upload",()=>W.click()),I("Rename",Ee),I(p.public?"Make private":"Make public",()=>pe({public:!p.public})),I("Delete",ke,"danger"));else if(x&&(p.public||t)){let u=I(t?"Unsubscribe":"Subscribe",async()=>{u.disabled=!0;try{await m.follow(d,!t),e.service.refresh(),await ce(e,1e3)}catch(k){R(t?"unsubscribe":"subscribe",k)}Q="",j()});u.setAttribute("aria-pressed",String(t)),r.replaceChildren(u)}else r.replaceChildren();let f=[...r.children];l>=0&&(f.find(u=>G&&u.textContent===G)??f[l])?.focus(),G=""}if(j(),y){o.firstElementChild.append(W);let t=s=>s.dataTransfer?.types.includes("Files");o.addEventListener("dragover",s=>t(s)&&s.preventDefault(),{signal:i}),o.addEventListener("drop",s=>{t(s)&&(s.preventDefault(),ae([...s.dataTransfer?.files??[]]))},{signal:i}),document.addEventListener("paste",s=>{let l=[...s.clipboardData?.files??[]];!l.length||document.querySelector("dialog[open]")||(s.preventDefault(),ae(l))},{signal:i})}let V="";function re(){if(!V||document.visibilityState!=="visible"||!O(e).subs.some(s=>s.id===d))return;let t=V;V="",queueMicrotask(()=>i.aborted||e.service.seen(d,t))}document.addEventListener("visibilitychange",re,{signal:i});let fe=()=>[...O(e).mine,...O(e).subs].find(t=>t.id===d),U=fe();function $e(){let t=fe();t?(p={...p,name:t.name,public:t.public,items:t.items},U&&t.last_added!==U.last_added&&Ie(),U&&t.items<U.items+(t.last_added!==U.last_added?1:0)&&Pe(),t.new&&(V=t.last_added,re())):U&&m.get(d,i).then(s=>{p={...p,...s},j()},s=>s.status===404&&b()),U=t,j()}i.addEventListener("abort",e.watch($e),{once:!0});let X="",ee=0;function be(t,s=!1){let l=xe.format(Se(t.created)),f=s||!!M&&t.created>M;f&&!s&&ee++;let u=`${t.name}${t.video?", video":""}${f?", new":""}`,k=n("button",{type:"button",class:"media-tile","aria-label":u,title:t.name,on:{click:()=>{Le(t,k)}},signal:i},[ie(e,t,i),t.video&&n("span",{"aria-hidden":"true"},"\u25B6")]),C=n("div",{class:`coll-cell${f?" new":""}`,dataset:{item:t.id}},[k]);if(x){let T=n("button",{type:"button",class:"att-save","aria-label":`Save ${t.name} to collection`,title:"Save to collection",on:{click:()=>se({...e,from:{item:t.id},opener:T})},signal:i},q(n));C.append(T)}y&&C.append(n("button",{type:"button",class:"coll-remove","aria-label":`Remove ${t.name} from the collection`,title:"Remove from collection",on:{click:()=>{Me(t,C)}},signal:i},"\xD7")),s?P.firstElementChild?.textContent===l?P.firstElementChild.after(C):(P.prepend(n("h2",{},l),C),X||=l):(l!==X&&P.append(n("h2",{},l)),X=l,P.append(C))}async function Me(t,s){try{await m.unsave(t.id)}catch(k){return R("remove it",k)}let l=[...P.querySelectorAll(".coll-cell")],f=l.indexOf(s),u=l[f+1]??l[f-1];ge(t),p={...p,items:Math.max(0,p.items-1)},j(),(u?.querySelector(".coll-remove")??r.querySelector("button"))?.focus(),e.service.refresh()}function ge(t){let s=h.items.indexOf(t);if(s<0)return;h.items.splice(s,1);let l=[...P.querySelectorAll(".coll-cell")].find(f=>f.dataset.item===t.id);if(l){let[f,u]=[l.previousElementSibling,l.nextElementSibling];l.contains(document.activeElement)&&(u?.querySelector("button")??r.querySelector("button"))?.focus(),l.remove(),f?.tagName==="H2"&&(!u||u.tagName==="H2")&&(f.remove(),u||(X=""))}h.done&&!h.items.length&&($.textContent=J())}let he=0;async function Pe(){let t=++he,s=[...h.items],l=s.at(-1),f=l&&await m.idsSince(d,l,i).catch(()=>null);if(!(!f||t!==he||i.aborted))for(let u of s.filter(k=>!f.has(k.id)))ge(u)}async function te(){let t=h;if(!t.done){$.textContent="Loading\u2026";try{let s=await t.next();if(i.aborted||t!==h)return;for(let l of s)be(l);$.textContent=t.done&&!t.items.length?J():""}catch{if(i.aborted||t!==h)return;ne.unobserve($),$.replaceChildren("Couldn't load the collection. ",I("Retry",()=>{te()},"link"));return}ne.unobserve($),t.done||ne.observe($)}}function ve(){return h=Y(e,d,i),P.replaceChildren(),X="",te()}async function Ie(){let t=h.items[0];if(!t)return ve();let s=await m.items(d,t,i,!0).catch(()=>null);if(!s||i.aborted)return;if(s.more)return ve();let l=new Set(h.items.map(u=>u.id)),f=s.items.filter(u=>!l.has(u.id));h.items.unshift(...f);for(let u of f.reverse())be(u,!0);f.length&&($.textContent="")}async function Le(t,s){let f=[...h.items].reverse().map(k=>({message:de(k),file:k.file,video:k.video})),u=h;try{let{openViewer:k}=await import("./viewer-DXT7SKOU.js");if(i.aborted)return;await k({images:f,start:f.findIndex(C=>C.message.id===t.id),more:[!u.done,!1],page:async C=>({messages:(C?await u.next():[]).map(de).reverse(),done:!C||u.done}),media:C=>[{message:C,file:C.files[0],video:u.items.find(T=>T.id===C.id)?.video??!1}],h:n,name:(C,T)=>C.file_names?.[T]??T,when:C=>`Added ${e.when(C.created)}`,fileUrl:(C,T)=>a.itemUrl({id:C.id,file:T}),...x?{onSave:(C,T,Te)=>se({...e,from:{item:C.id},opener:Te})}:{},opener:s,follow:()=>{},signal:i})}catch{window.open(a.itemUrl(t),"_blank","noopener")}}let ne=new IntersectionObserver(t=>t.some(s=>s.isIntersecting)&&void te(),{rootMargin:"400px"});i.addEventListener("abort",()=>ne.disconnect(),{once:!0}),await te(),!i.aborted&&(ee&&(z.hidden=!1,z.textContent=`${ee>=60?"60+":ee} new since your last visit`),V=h.items[0]?.created??"",re())}async function He(o){let{h:e}=o,n=new AbortController,{signal:a}=n;o.signal.addEventListener("abort",()=>L(),{signal:a});let{mine:i,subs:d}=O(o),m=[...i,...d],g=e("h2",{id:"coll-pick-title"},[q(e)," Attach from collections"]),b=m[0]?.id??"",p=m.map(c=>e("button",{type:"button",class:"coll-chip","aria-pressed":String(c.id===b),on:{click:E=>I(c.id,E.currentTarget)},signal:a},c.owner?`${c.name} \xB7 ${c.owner.name}`:c.name)),x=e("div",{class:"coll-chips",role:"group","aria-label":"Collection"},p),y=e("div",{class:"media-grid coll-grid"}),w=e("p",{class:"media-status",role:"status"}),M=e("span",{class:"coll-count","aria-live":"polite"}),h=e("button",{type:"button",disabled:!0,on:{click:()=>J()},signal:a},"Attach"),A=e("div",{class:"coll-body"},[y,w]),v=e("dialog",{class:"coll-dialog coll-pick","aria-labelledby":g.id},[e("header",{class:"media-bar"},[g,e("button",{type:"button",class:"icon-button ic i-x","aria-label":"Close",on:{click:()=>L()},signal:a})]),m.length?x:null,A,e("footer",{class:"coll-foot"},[M,h])]),r=new Map,S=Y(o,"",a);function z(){M.textContent=r.size?`${r.size} picked${r.size>=o.max?" (the most a message takes)":""}`:o.max?"":"The message has all the files it can take.",h.disabled=!r.size,h.textContent=r.size?`Attach ${r.size}`:"Attach"}function P(c){let E=e("button",{type:"button",class:"media-tile","aria-label":`${c.name}${c.video?", video":""}`,title:c.name,"aria-pressed":String(r.has(c.id)),on:{click:()=>{r.has(c.id)?r.delete(c.id):r.size<o.max&&r.set(c.id,c),E.setAttribute("aria-pressed",String(r.has(c.id))),z()}},signal:a},[ie(o,c,a),c.video&&e("span",{"aria-hidden":"true"},"\u25B6")]);return E}async function $(){if(S.done||!b)return;let c=S;w.textContent="Loading\u2026";try{let E=await c.next();if(a.aborted||c!==S)return;y.append(...E.map(P)),w.textContent=c.done&&!c.items.length?"Nothing in this collection yet.":""}catch{if(a.aborted||c!==S)return;F.unobserve(w),w.replaceChildren("Couldn't load the collection. ",e("button",{type:"button",class:"link",on:{click:()=>{$()}},signal:a},"Retry"));return}F.unobserve(w),c.done||F.observe(w)}function R(){S=Y(o,b,a),y.replaceChildren(),$()}function I(c,E){if(c!==b){b=c;for(let H of p)H.setAttribute("aria-pressed",String(H===E));E.scrollIntoView({block:"nearest",inline:"nearest"}),R()}}let F=new IntersectionObserver(c=>c.some(E=>E.isIntersecting)&&void $(),{root:A,rootMargin:"400px"});function J(){let c=[...r.values()];L(),c.length&&o.onPick(c)}function L(){a.aborted||(n.abort(),F.disconnect(),v.open&&v.close(),v.remove(),o.opener.focus())}if(v.addEventListener("close",()=>L(),{signal:a}),await N(e),!a.aborted){if(document.body.append(v),v.showModal(),z(),!m.length){w.textContent="You have no collections yet. Save images and videos from the chat to one first.";return}R(),p[0]?.focus()}}export{qe as mountCollection,Oe as openCreate,He as openPicker,se as openSave};
|
|
2
|
-
//# sourceMappingURL=lazy-
|
|
1
|
+
var oe="/api/collections/collections/records",D=o=>JSON.stringify(o),Ae="id,collection,file,name,video,poster,created";function _(o){return{get:(e,n)=>o.request(`${oe}/${e}`,{query:{expand:"owner",fields:"id,name,public,owner,items,expand.owner.name"},signal:n}),create:(e,n,a)=>o.request(oe,{method:"POST",body:{owner:e,name:n,public:a},query:{fields:"id"}}),update:(e,n)=>o.request(`${oe}/${e}`,{method:"PATCH",body:n,query:{fields:"name,public"}}),remove:e=>o.request(`${oe}/${e}`,{method:"DELETE"}),async items(e,n,a,i=!1){let d=i?">":"<",m=n?` && (created ${d} ${D(n.created)} || (created = ${D(n.created)} && id ${d} ${D(n.id)}))`:"",g={filter:`collection = ${D(e)}${m}`,sort:"-created,-id",perPage:61,skipTotal:!0,fields:Ae},{items:b}=await o.request("/api/collections/collection_items/records",{query:g,signal:a});return{items:b.slice(0,60),more:b.length>60}},async idsSince(e,n,a){let i=new Set,d=`collection = ${D(e)} && (created > ${D(n.created)} || (created = ${D(n.created)} && id >= ${D(n.id)}))`;for(let m=1;;m++){let g={filter:d,sort:"-created,-id",page:m,perPage:1e3,skipTotal:!0,fields:"id"},{items:b}=await o.request("/api/collections/collection_items/records",{query:g,signal:a});for(let p of b)i.add(p.id);if(b.length<1e3)return i}},save:(e,n)=>o.request("/api/chat/items",{method:"POST",body:{collection:e,...n}}),upload:(e,n,a)=>o.request("/api/chat/items",{method:"POST",body:{collection:e,file:n},onUpload:a}),unsave:e=>o.request(`/api/chat/items/${e}`,{method:"DELETE"}),savedIn:(e,n)=>o.request("/api/chat/saved",{query:e,signal:n}),follow:(e,n)=>o.request("/api/chat/subs",{method:"POST",body:{collection:e,on:n}})}}var le=null;function N(o){return le??=new Promise(e=>{let a=o("link",{rel:"stylesheet",href:"/assets/collections-DHJEOLHW.css",on:{load:()=>e(),error:()=>{a.remove(),le=null,e()}}});document.head.append(a)}),le}var ye=/\.(jpe?g|png|gif|webp|avif|mp4|m4v|webm|mov|ogv)$/i,Ce=".jpg,.jpeg,.png,.gif,.webp,.avif,.mp4,.m4v,.webm,.mov,.ogv",we=20*1024*1024,O=o=>o.list()??{mine:[],subs:[]};function ce(o,e){return new Promise(n=>{let a=()=>{i(),clearTimeout(d),n()},i=o.watch(a),d=setTimeout(a,e)})}function B(o){let e=o;return e?.status===0?"Can't reach the server. Check your connection.":Object.values(e?.fields??{})[0]||e?.message||"Something went wrong."}var q=o=>o("span",{class:"ci","aria-hidden":"true"}),xe=new Intl.DateTimeFormat(void 0,{month:"long",year:"numeric"}),Se=o=>new Date(o.replace(" ","T"));function de(o){let{id:e,created:n,file:a,name:i}=o;return{id:e,room:"",author:"",text:"",created:n,updated:n,edited_at:"",deleted:!1,files:[a],file_names:{[a]:i}}}function ie(o,e,n){if(e.video&&!e.poster)return null;let a=o.h("img",{src:e.video?o.api.itemPosterUrl(e):o.api.itemUrl(e,"240x240"),alt:"",loading:"lazy",decoding:"async"});return e.video&&a.addEventListener("error",()=>a.remove(),{signal:n}),a}function Y(o,e,n){let a=[],i=!1,d=null;return{items:a,get done(){return i},next(){return i?Promise.resolve([]):(d??=_(o.api).items(e,a.at(-1),n).then(m=>(d=null,i=!m.more,a.push(...m.items),m.items),m=>{throw d=null,m}),d)}}}async function Oe(o){let{h:e}=o,n=new AbortController,{signal:a}=n;o.signal.addEventListener("abort",()=>y(),{signal:a});let i=e("h2",{id:"coll-create-title"},[q(e)," New collection"]),d=e("input",{required:!0,autocomplete:"off","aria-label":"Name",placeholder:"Name"}),m=e("input",{type:"checkbox",role:"switch",class:"switch"}),g=e("p",{class:"coll-status",role:"alert"}),b=e("button",{type:"submit",class:"primary"},"Create"),p=e("form",{class:"coll-body",on:{submit:async w=>{if(w.preventDefault(),!b.disabled){b.disabled=!0,g.textContent="";try{let{id:M}=await _(o.api).create(o.me()?.id??"",d.value,m.checked);o.service.refresh(),y(!1),o.onCreated(M)}catch(M){g.textContent=B(M)}finally{b.disabled=!1}}}},signal:a},[e("p",{class:"coll-new-form"},[d,b]),e("label",{class:"coll-public"},[m,"Public: anyone can see it and subscribe"]),g]),x=e("dialog",{class:"coll-dialog coll-create","aria-labelledby":i.id},[e("header",{class:"media-bar"},[i,e("button",{type:"button",class:"icon-button ic i-x","aria-label":"Close",on:{click:()=>y()},signal:a})]),p]);function y(w=!0){a.aborted||(n.abort(),x.open&&x.close(),x.remove(),w&&o.opener.focus())}x.addEventListener("close",()=>y(),{signal:a}),await N(e),!a.aborted&&(document.body.append(x),x.showModal(),d.focus())}var ue=null;async function se(o){ue?.();let{h:e}=o,n=_(o.api),a=new AbortController,{signal:i}=a;o.signal.addEventListener("abort",()=>A(),{signal:i});let d=e("h2",{id:"coll-save-title"},[q(e)," Save to collection"]),m=e("ul",{class:"coll-choices"}),g=e("p",{class:"coll-status",role:"status"},"Loading\u2026"),b=e("input",{placeholder:"New collection","aria-label":"New collection name",autocomplete:"off"}),p=e("form",{class:"coll-new-form",on:{submit:async v=>{if(v.preventDefault(),!!b.value.trim())try{let r=(await n.create(o.me()?.id??"",b.value,!1)).id;b.value="",await M(r,!0)}catch(r){g.textContent=B(r)}}},signal:i},[b,e("button",{type:"submit"},"Create")]),x=e("dialog",{class:"coll-dialog coll-save","aria-labelledby":d.id},[e("header",{class:"media-bar"},[d,e("button",{type:"button",class:"icon-button ic i-x","aria-label":"Close",on:{click:()=>A()},signal:i})]),e("div",{class:"coll-body"},[m,g,p])]),y={},w=new Map;async function M(v,r){w.set(v,r),g.textContent=r?"Saving\u2026":"Removing\u2026",h();try{r?y[v]=(await n.save(v,o.from)).id:y[v]&&(await n.unsave(y[v]),delete y[v]),g.textContent=r?"Saved.":"Removed.",o.service.refresh()}catch(S){S.status===409?y=await n.savedIn(o.from,i).catch(()=>y):g.textContent=B(S)}w.delete(v),h()}function h(){let v=O(o).mine;m.replaceChildren(...v.map(r=>{let S=e("input",{type:"checkbox",checked:w.get(r.id)??!!y[r.id],disabled:w.has(r.id)});return S.addEventListener("change",()=>{M(r.id,S.checked)},{signal:i}),e("li",{"aria-busy":w.has(r.id)?"true":"false"},e("label",{},[S," ",r.name,e("span",{class:"coll-meta"},r.public?" \xB7 Public: anyone can see it":" \xB7 Private"),w.has(r.id)?e("span",{class:"coll-spin","aria-hidden":"true"}):null]))})),!v.length&&g.textContent===""&&(g.textContent="You have no collections yet. Make one:")}function A(){i.aborted||(a.abort(),ue=null,x.open&&x.close(),x.remove(),o.opener.setAttribute("aria-expanded","false"),o.opener.focus())}if(ue=A,x.addEventListener("close",()=>A(),{signal:i}),i.addEventListener("abort",o.watch(h),{once:!0}),await N(e),!i.aborted){document.body.append(x),x.showModal(),o.opener.setAttribute("aria-expanded","true");try{y=await n.savedIn(o.from,i),g.textContent=""}catch(v){if(i.aborted)return;g.textContent=B(v)}h(),(m.querySelector("input")??b).focus()}}async function qe(o,e){let{h:n,api:a,signal:i,id:d}=e,m=_(a),[,g]=await Promise.all([N(n),m.get(d,i).catch(()=>null),(async()=>{e.me()&&!e.list()&&await ce(e,2e3)})()]);if(i.aborted)return;function b(){o.replaceChildren(n("section",{class:"collection not-found"},[n("h1",{},[q(n)," This collection doesn't exist."]),n("p",{},["It may be private, or deleted. ",n("a",{href:"/"},"Back to rooms")])]))}if(!g)return b();let p=g,x=e.me(),y=!!x&&p.owner===x.id,w=g.expand?.owner?.name??"",M=O(e).subs.find(t=>t.id===d)?.seen_at??"",h=Y(e,d,i),A=n("h1",{id:"coll-title"}),v=n("p",{class:"coll-meta"}),r=n("div",{class:"coll-actions"}),S=n("p",{class:"coll-notice",role:"status"}),z=n("p",{class:"coll-new",hidden:!0}),P=n("div",{class:"media-grid coll-grid"}),$=n("p",{class:"media-status",role:"status"});o.replaceChildren(n("section",{class:"collection","aria-labelledby":"coll-title"},[n("header",{class:`coll-head t${d.charCodeAt(0)%4}`},[n("a",{href:"/",class:"back ic i-back","aria-label":"Back to rooms"}),A,v,r,S]),z,P,$]));let R=(t,s)=>{S.textContent=`Couldn't ${t}. ${B(s)}`},I=(t,s,l="")=>n("button",{type:"button",class:l,on:{click:()=>{s()}},signal:i},t),F=t=>`${t} ${t===1?"item":"items"}`,J=()=>y?"Nothing here yet. Upload images and videos, or save them from the chat.":"Nothing here yet.",L=[],c=0,E=!1,H=[],W=n("input",{type:"file",multiple:!0,accept:Ce,hidden:!0,on:{change:()=>{ae([...W.files??[]]),W.value=""}},signal:i});function ae(t){for(let s of t)ye.test(s.name)?s.size>we?H.push(`${s.name}: larger than 20 MB`):L.push(s):H.push(`${s.name}: not an image or video`);if(!E){if(!L.length)return me();E=!0,(async()=>{for(;L.length&&!i.aborted;){let s=L[0],l=`Uploading ${c+1} of ${c+L.length}\u2026`;S.textContent=l;try{await m.upload(d,s,f=>S.textContent=`${l} ${Math.round(f*100)}%`)}catch(f){if(f.status===429){S.textContent="Waiting for the server\u2026",await new Promise(u=>setTimeout(u,1e4));continue}H.push(`${s.name}: ${B(f)}`)}L.shift(),c++,e.service.refresh()}c=0,E=!1,me()})()}}function me(){S.textContent=H.length?`Couldn't upload ${H.join("; ")}`:"",H=[]}let K=!1,G="",Q="";function Z(){K=!1,Q="",j()}async function pe(t){try{return p={...p,...await m.update(d,t)},S.textContent="",e.service.refresh(),Z(),!0}catch(s){return R("save",s),!1}}function Ee(){K=!0,G="Rename";let t=n("input",{value:p.name,"aria-label":"Collection name",autocomplete:"off"}),s=n("form",{class:"coll-rename",on:{submit:l=>{l.preventDefault(),pe({name:t.value})},keydown:l=>l.key==="Escape"&&Z()},signal:i},[t,n("button",{type:"submit"},"Save"),I("Cancel",Z,"link")]);r.replaceChildren(s),t.focus(),t.select()}function ke(){K=!0,G="Delete",r.replaceChildren(n("span",{},`Delete \u201C${p.name}\u201D${p.items?` and its ${F(p.items)}`:""}? This can't be undone.`),I("Delete collection",async()=>{try{await m.remove(d),e.service.refresh(),e.navigate("/")}catch(t){R("delete it",t)}},"danger"),I("Cancel",Z,"link")),r.querySelector("button")?.focus()}function j(){if(i.aborted)return;A.replaceChildren(q(n)," ",p.name),v.textContent=[y?"Yours":w&&`By ${w}`,p.public?"Public":"Private",F(p.items)].filter(Boolean).join(" \xB7 ");let t=O(e).subs.some(u=>u.id===d),s=[p.public,t].join();if(K||s===Q)return;Q=s;let l=[...r.children].findIndex(u=>u.contains(document.activeElement));if(y)r.replaceChildren(I("Upload",()=>W.click()),I("Rename",Ee),I(p.public?"Make private":"Make public",()=>pe({public:!p.public})),I("Delete",ke,"danger"));else if(x&&(p.public||t)){let u=I(t?"Unsubscribe":"Subscribe",async()=>{u.disabled=!0;try{await m.follow(d,!t),e.service.refresh(),await ce(e,1e3)}catch(k){R(t?"unsubscribe":"subscribe",k)}Q="",j()});u.setAttribute("aria-pressed",String(t)),r.replaceChildren(u)}else r.replaceChildren();let f=[...r.children];l>=0&&(f.find(u=>G&&u.textContent===G)??f[l])?.focus(),G=""}if(j(),y){o.firstElementChild.append(W);let t=s=>s.dataTransfer?.types.includes("Files");o.addEventListener("dragover",s=>t(s)&&s.preventDefault(),{signal:i}),o.addEventListener("drop",s=>{t(s)&&(s.preventDefault(),ae([...s.dataTransfer?.files??[]]))},{signal:i}),document.addEventListener("paste",s=>{let l=[...s.clipboardData?.files??[]];!l.length||document.querySelector("dialog[open]")||(s.preventDefault(),ae(l))},{signal:i})}let V="";function re(){if(!V||document.visibilityState!=="visible"||!O(e).subs.some(s=>s.id===d))return;let t=V;V="",queueMicrotask(()=>i.aborted||e.service.seen(d,t))}document.addEventListener("visibilitychange",re,{signal:i});let fe=()=>[...O(e).mine,...O(e).subs].find(t=>t.id===d),U=fe();function $e(){let t=fe();t?(p={...p,name:t.name,public:t.public,items:t.items},U&&t.last_added!==U.last_added&&Ie(),U&&t.items<U.items+(t.last_added!==U.last_added?1:0)&&Pe(),t.new&&(V=t.last_added,re())):U&&m.get(d,i).then(s=>{p={...p,...s},j()},s=>s.status===404&&b()),U=t,j()}i.addEventListener("abort",e.watch($e),{once:!0});let X="",ee=0;function be(t,s=!1){let l=xe.format(Se(t.created)),f=s||!!M&&t.created>M;f&&!s&&ee++;let u=`${t.name}${t.video?", video":""}${f?", new":""}`,k=n("button",{type:"button",class:"media-tile","aria-label":u,title:t.name,on:{click:()=>{Le(t,k)}},signal:i},[ie(e,t,i),t.video&&n("span",{class:"att-play","aria-hidden":"true"})]),C=n("div",{class:`coll-cell${f?" new":""}`,dataset:{item:t.id}},[k]);if(x){let T=n("button",{type:"button",class:"att-save","aria-label":`Save ${t.name} to collection`,title:"Save to collection",on:{click:()=>se({...e,from:{item:t.id},opener:T})},signal:i},q(n));C.append(T)}y&&C.append(n("button",{type:"button",class:"coll-remove","aria-label":`Remove ${t.name} from the collection`,title:"Remove from collection",on:{click:()=>{Me(t,C)}},signal:i},"\xD7")),s?P.firstElementChild?.textContent===l?P.firstElementChild.after(C):(P.prepend(n("h2",{},l),C),X||=l):(l!==X&&P.append(n("h2",{},l)),X=l,P.append(C))}async function Me(t,s){try{await m.unsave(t.id)}catch(k){return R("remove it",k)}let l=[...P.querySelectorAll(".coll-cell")],f=l.indexOf(s),u=l[f+1]??l[f-1];ge(t),p={...p,items:Math.max(0,p.items-1)},j(),(u?.querySelector(".coll-remove")??r.querySelector("button"))?.focus(),e.service.refresh()}function ge(t){let s=h.items.indexOf(t);if(s<0)return;h.items.splice(s,1);let l=[...P.querySelectorAll(".coll-cell")].find(f=>f.dataset.item===t.id);if(l){let[f,u]=[l.previousElementSibling,l.nextElementSibling];l.contains(document.activeElement)&&(u?.querySelector("button")??r.querySelector("button"))?.focus(),l.remove(),f?.tagName==="H2"&&(!u||u.tagName==="H2")&&(f.remove(),u||(X=""))}h.done&&!h.items.length&&($.textContent=J())}let he=0;async function Pe(){let t=++he,s=[...h.items],l=s.at(-1),f=l&&await m.idsSince(d,l,i).catch(()=>null);if(!(!f||t!==he||i.aborted))for(let u of s.filter(k=>!f.has(k.id)))ge(u)}async function te(){let t=h;if(!t.done){$.textContent="Loading\u2026";try{let s=await t.next();if(i.aborted||t!==h)return;for(let l of s)be(l);$.textContent=t.done&&!t.items.length?J():""}catch{if(i.aborted||t!==h)return;ne.unobserve($),$.replaceChildren("Couldn't load the collection. ",I("Retry",()=>{te()},"link"));return}ne.unobserve($),t.done||ne.observe($)}}function ve(){return h=Y(e,d,i),P.replaceChildren(),X="",te()}async function Ie(){let t=h.items[0];if(!t)return ve();let s=await m.items(d,t,i,!0).catch(()=>null);if(!s||i.aborted)return;if(s.more)return ve();let l=new Set(h.items.map(u=>u.id)),f=s.items.filter(u=>!l.has(u.id));h.items.unshift(...f);for(let u of f.reverse())be(u,!0);f.length&&($.textContent="")}async function Le(t,s){let f=[...h.items].reverse().map(k=>({message:de(k),file:k.file,video:k.video})),u=h;try{let{openViewer:k}=await import("./viewer-DXT7SKOU.js");if(i.aborted)return;await k({images:f,start:f.findIndex(C=>C.message.id===t.id),more:[!u.done,!1],page:async C=>({messages:(C?await u.next():[]).map(de).reverse(),done:!C||u.done}),media:C=>[{message:C,file:C.files[0],video:u.items.find(T=>T.id===C.id)?.video??!1}],h:n,name:(C,T)=>C.file_names?.[T]??T,when:C=>`Added ${e.when(C.created)}`,fileUrl:(C,T)=>a.itemUrl({id:C.id,file:T}),...x?{onSave:(C,T,Te)=>se({...e,from:{item:C.id},opener:Te})}:{},opener:s,follow:()=>{},signal:i})}catch{window.open(a.itemUrl(t),"_blank","noopener")}}let ne=new IntersectionObserver(t=>t.some(s=>s.isIntersecting)&&void te(),{rootMargin:"400px"});i.addEventListener("abort",()=>ne.disconnect(),{once:!0}),await te(),!i.aborted&&(ee&&(z.hidden=!1,z.textContent=`${ee>=60?"60+":ee} new since your last visit`),V=h.items[0]?.created??"",re())}async function He(o){let{h:e}=o,n=new AbortController,{signal:a}=n;o.signal.addEventListener("abort",()=>L(),{signal:a});let{mine:i,subs:d}=O(o),m=[...i,...d],g=e("h2",{id:"coll-pick-title"},[q(e)," Attach from collections"]),b=m[0]?.id??"",p=m.map(c=>e("button",{type:"button",class:"coll-chip","aria-pressed":String(c.id===b),on:{click:E=>I(c.id,E.currentTarget)},signal:a},c.owner?`${c.name} \xB7 ${c.owner.name}`:c.name)),x=e("div",{class:"coll-chips",role:"group","aria-label":"Collection"},p),y=e("div",{class:"media-grid coll-grid"}),w=e("p",{class:"media-status",role:"status"}),M=e("span",{class:"coll-count","aria-live":"polite"}),h=e("button",{type:"button",disabled:!0,on:{click:()=>J()},signal:a},"Attach"),A=e("div",{class:"coll-body"},[y,w]),v=e("dialog",{class:"coll-dialog coll-pick","aria-labelledby":g.id},[e("header",{class:"media-bar"},[g,e("button",{type:"button",class:"icon-button ic i-x","aria-label":"Close",on:{click:()=>L()},signal:a})]),m.length?x:null,A,e("footer",{class:"coll-foot"},[M,h])]),r=new Map,S=Y(o,"",a);function z(){M.textContent=r.size?`${r.size} picked${r.size>=o.max?" (the most a message takes)":""}`:o.max?"":"The message has all the files it can take.",h.disabled=!r.size,h.textContent=r.size?`Attach ${r.size}`:"Attach"}function P(c){let E=e("button",{type:"button",class:"media-tile","aria-label":`${c.name}${c.video?", video":""}`,title:c.name,"aria-pressed":String(r.has(c.id)),on:{click:()=>{r.has(c.id)?r.delete(c.id):r.size<o.max&&r.set(c.id,c),E.setAttribute("aria-pressed",String(r.has(c.id))),z()}},signal:a},[ie(o,c,a),c.video&&e("span",{class:"att-play","aria-hidden":"true"})]);return E}async function $(){if(S.done||!b)return;let c=S;w.textContent="Loading\u2026";try{let E=await c.next();if(a.aborted||c!==S)return;y.append(...E.map(P)),w.textContent=c.done&&!c.items.length?"Nothing in this collection yet.":""}catch{if(a.aborted||c!==S)return;F.unobserve(w),w.replaceChildren("Couldn't load the collection. ",e("button",{type:"button",class:"link",on:{click:()=>{$()}},signal:a},"Retry"));return}F.unobserve(w),c.done||F.observe(w)}function R(){S=Y(o,b,a),y.replaceChildren(),$()}function I(c,E){if(c!==b){b=c;for(let H of p)H.setAttribute("aria-pressed",String(H===E));E.scrollIntoView({block:"nearest",inline:"nearest"}),R()}}let F=new IntersectionObserver(c=>c.some(E=>E.isIntersecting)&&void $(),{root:A,rootMargin:"400px"});function J(){let c=[...r.values()];L(),c.length&&o.onPick(c)}function L(){a.aborted||(n.abort(),F.disconnect(),v.open&&v.close(),v.remove(),o.opener.focus())}if(v.addEventListener("close",()=>L(),{signal:a}),await N(e),!a.aborted){if(document.body.append(v),v.showModal(),z(),!m.length){w.textContent="You have no collections yet. Save images and videos from the chat to one first.";return}R(),p[0]?.focus()}}export{qe as mountCollection,Oe as openCreate,He as openPicker,se as openSave};
|
|
2
|
+
//# sourceMappingURL=lazy-4CXRBHHM.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../web/src/views/collection/calls.ts", "../../web/src/views/collection/shared.ts", "../../web/src/views/collection/create.ts", "../../web/src/views/collection/save.ts", "../../web/src/views/collection/page.ts", "../../web/src/views/collection/picker.ts"],
|
|
4
|
+
"sourcesContent": ["// The collections' requests (\u00A731), through Api.request: app.js doesn't carry them. ITEM_FIELDS is shared/contract.json's\n// (tests/unit/contract.test.ts).\n\nimport type { Api } from \"../../api.ts\";\nimport type { CollectionItem } from \"../../lib/types.ts\";\n\n/** What a collection's page shows of it. */\nexport interface Meta {\n id: string;\n name: string;\n public: boolean;\n owner: string;\n items: number;\n}\n\n/** A message's file (the one that has it: a forward's original, \u00A721.3), or an item. */\nexport type From = { message: string; file: string } | { item: string };\n\n/** A collection's page of items, as the media grid's (\u00A730.2). */\nexport const PAGE = 60;\n\nexport const RECORDS = \"/api/collections/collections/records\";\n\n/** A value in a records filter (ids and dates here), quoted and escaped. */\nexport const lit = (v: string) => JSON.stringify(v);\n\n/** What a page of items asks for (shared/contract.json). */\nexport const ITEM_FIELDS = \"id,collection,file,name,video,poster,created\";\n\n/** The requests of the page, the menu and the picker. */\nexport function calls(api: Api) {\n return {\n /** The collection, with its owner's name (guests can't look users up). */\n get: (id: string, signal: AbortSignal) =>\n api.request<Meta & { expand?: { owner?: { name: string } } }>(`${RECORDS}/${id}`, {\n query: { expand: \"owner\", fields: \"id,name,public,owner,items,expand.owner.name\" },\n signal,\n }),\n create: (owner: string, name: string, isPublic: boolean) =>\n api.request<{ id: string }>(RECORDS, { method: \"POST\", body: { owner, name, public: isPublic }, query: { fields: \"id\" } }),\n update: (id: string, body: { name?: string; public?: boolean }) =>\n api.request<Pick<Meta, \"name\" | \"public\">>(`${RECORDS}/${id}`, { method: \"PATCH\", body, query: { fields: \"name,public\" } }),\n remove: (id: string) => api.request(`${RECORDS}/${id}`, { method: \"DELETE\" }),\n /**\n * A page of a collection's items, newest first: older than `after` (the oldest shown), or the newest; with\n * `newer`, those added after `after` (the newest shown).\n */\n async items(collection: string, after: CollectionItem | undefined, signal: AbortSignal, newer = false) {\n const op = newer ? \">\" : \"<\";\n const cursor = after\n ? ` && (created ${op} ${lit(after.created)} || (created = ${lit(after.created)} && id ${op} ${lit(after.id)}))`\n : \"\";\n const query = {\n filter: `collection = ${lit(collection)}${cursor}`,\n sort: \"-created,-id\",\n perPage: PAGE + 1,\n skipTotal: true,\n fields: ITEM_FIELDS,\n };\n const { items } = await api.request<{ items: CollectionItem[] }>(\"/api/collections/collection_items/records\", { query, signal });\n return { items: items.slice(0, PAGE), more: items.length > PAGE };\n },\n /** The ids of a collection's items from `oldest` on (it included): which of those shown are still there. */\n async idsSince(collection: string, oldest: CollectionItem, signal: AbortSignal) {\n const ids = new Set<string>();\n const filter = `collection = ${lit(collection)} && (created > ${lit(oldest.created)} || (created = ${lit(oldest.created)} && id >= ${lit(oldest.id)}))`;\n for (let page = 1; ; page++) {\n const query = { filter, sort: \"-created,-id\", page, perPage: 1000, skipTotal: true, fields: \"id\" };\n const { items } = await api.request<{ items: { id: string }[] }>(\"/api/collections/collection_items/records\", { query, signal });\n for (const x of items) ids.add(x.id);\n if (items.length < 1000) return ids;\n }\n },\n /** A copy of a message's file or of an item in a collection of yours. 409: it is in there already. */\n save: (collection: string, from: From) =>\n api.request<CollectionItem>(\"/api/chat/items\", { method: \"POST\", body: { collection, ...from } }),\n /** An image or video of your own, uploaded straight into a collection of yours. */\n upload: (collection: string, file: File, onUpload: (fraction: number) => void) =>\n api.request<CollectionItem>(\"/api/chat/items\", { method: \"POST\", body: { collection, file }, onUpload }),\n unsave: (item: string) => api.request(`/api/chat/items/${item}`, { method: \"DELETE\" }),\n /** Your collections that have the file already: collection id \u2192 item id. */\n savedIn: (from: From, signal: AbortSignal) => api.request<Record<string, string>>(\"/api/chat/saved\", { query: from, signal }),\n follow: (collection: string, on: boolean) => api.request(\"/api/chat/subs\", { method: \"POST\", body: { collection, on } }),\n };\n}\n", "// What the collections' chunk (lazy.ts) shares between its parts: the options every part gets, the stylesheet, and the\n// helpers for tiles, pages of items and errors.\n\nimport type { Api } from \"../../api.ts\";\nimport type { CollectionsService } from \"../../collections.ts\";\nimport type { h as H } from \"../../dom.ts\";\nimport type { CollectionItem, Collections, Message, User } from \"../../lib/types.ts\";\nimport { calls } from \"./calls.ts\";\n\n/** The stylesheet's URL, set by the build (scripts/lib/build-utils.mjs). */\ndeclare const COLLECTIONS_CSS: string;\n\nexport interface Base {\n api: Api;\n h: typeof H;\n service: CollectionsService;\n me: () => User | null;\n /** Yours and those you follow, as the store has them: null until they are loaded. */\n list: () => Collections | null;\n /** Call `fn` when they change; returns the unsubscribe. */\n watch: (fn: () => void) => () => void;\n /** When an item was added, for the viewer. */\n when: (created: string) => string;\n signal: AbortSignal;\n}\n\nlet stylesheet: Promise<void> | null = null;\nexport function loadStylesheet(h: typeof H): Promise<void> {\n stylesheet ??= new Promise((resolve) => {\n const failed = () => {\n link.remove();\n stylesheet = null;\n resolve();\n };\n const link = h(\"link\", { rel: \"stylesheet\", href: COLLECTIONS_CSS, on: { load: () => resolve(), error: failed } });\n document.head.append(link);\n });\n return stylesheet;\n}\n\n/** What can be uploaded into a collection: the images and videos of lib/files.ts (not imported: app.js has it), at most 20 MB. */\nexport const MEDIA = /\\.(jpe?g|png|gif|webp|avif|mp4|m4v|webm|mov|ogv)$/i;\nexport const ACCEPT = \".jpg,.jpeg,.png,.gif,.webp,.avif,.mp4,.m4v,.webm,.mov,.ogv\";\nexport const MAX_BYTES = 20 * 1024 * 1024;\n\n/** Yours and those you follow (none until they are loaded). */\nexport const lists = (o: Base): Collections => o.list() ?? { mine: [], subs: [] };\n\n/** The next change of the collections in the store, or `ms` without one. */\nexport function changed(o: Base, ms: number): Promise<void> {\n return new Promise((resolve) => {\n const done = () => {\n off();\n clearTimeout(timer);\n resolve();\n };\n const off = o.watch(done);\n const timer = setTimeout(done, ms);\n });\n}\n\n/** Why a request failed, in words: the server's reason for a field when it gave one. */\nexport function reason(e: unknown): string {\n const err = e as { fields?: Record<string, string>; message?: string; status?: number };\n if (err?.status === 0) return \"Can't reach the server. Check your connection.\";\n return Object.values(err?.fields ?? {})[0] || err?.message || \"Something went wrong.\";\n}\n\nexport const icon = (h: typeof H) => h(\"span\", { class: \"ci\", \"aria-hidden\": \"true\" });\nexport const monthOf = new Intl.DateTimeFormat(undefined, { month: \"long\", year: \"numeric\" });\nexport const dateOf = (created: string) => new Date(created.replace(\" \", \"T\"));\n\n/** An item as the viewer takes it: a message of its own with one file. */\nexport function asMessage(it: CollectionItem): Message {\n const { id, created, file, name } = it;\n return {\n id,\n room: \"\",\n author: \"\",\n text: \"\",\n created,\n updated: created,\n edited_at: \"\",\n deleted: false,\n files: [file],\n file_names: { [file]: name },\n };\n}\n\n/** A square tile's picture: the grid thumbnail, a video's poster, or nothing (a plain tile with the play badge). */\nexport function picture(b: Base, it: CollectionItem, signal: AbortSignal): HTMLImageElement | null {\n if (it.video && !it.poster) return null;\n const img = b.h(\"img\", {\n src: it.video ? b.api.itemPosterUrl(it) : b.api.itemUrl(it, \"240x240\"),\n alt: \"\",\n loading: \"lazy\",\n decoding: \"async\",\n });\n // A poster that fails leaves the plain tile.\n if (it.video) img.addEventListener(\"error\", () => img.remove(), { signal });\n return img;\n}\n\n/** A collection's items a page at a time, newest first. */\nexport function pager(b: Base, collection: string, signal: AbortSignal) {\n const items: CollectionItem[] = [];\n let done = false;\n let loading: Promise<CollectionItem[]> | null = null;\n return {\n items,\n get done() {\n return done;\n },\n /** The next page (the same one while it loads); rejects when it fails. */\n next(): Promise<CollectionItem[]> {\n if (done) return Promise.resolve([]);\n loading ??= calls(b.api)\n .items(collection, items.at(-1), signal)\n .then(\n (page: { items: CollectionItem[]; more: boolean }) => {\n loading = null;\n done = !page.more;\n items.push(...page.items);\n return page.items;\n },\n (e: unknown) => {\n loading = null;\n throw e;\n },\n );\n return loading!;\n },\n };\n}\n", "// A new collection (\u00A731): the sidebar's \"+\".\n\nimport { calls } from \"./calls.ts\";\nimport { type Base, icon, loadStylesheet, reason } from \"./shared.ts\";\n\nexport interface CreateOptions extends Base {\n opener: HTMLElement;\n /** Made: e.g. go to its page. */\n onCreated: (id: string) => void;\n}\n\n/** The sidebar's \"+\" (\u00A731): a name, and whether anyone may see it. */\nexport async function openCreate(o: CreateOptions): Promise<void> {\n const { h } = o;\n const scope = new AbortController();\n const { signal } = scope;\n o.signal.addEventListener(\"abort\", () => close(), { signal });\n const title = h(\"h2\", { id: \"coll-create-title\" }, [icon(h), \" New collection\"]);\n const input = h(\"input\", { required: true, autocomplete: \"off\", \"aria-label\": \"Name\", placeholder: \"Name\" });\n // A switch, as Settings' choices are.\n const pub = h(\"input\", { type: \"checkbox\", role: \"switch\", class: \"switch\" });\n const err = h(\"p\", { class: \"coll-status\", role: \"alert\" });\n const submit = h(\"button\", { type: \"submit\", class: \"primary\" }, \"Create\");\n const form = h(\n \"form\",\n {\n class: \"coll-body\",\n on: {\n submit: async (e) => {\n e.preventDefault();\n if (submit.disabled) return;\n submit.disabled = true;\n err.textContent = \"\";\n try {\n const { id } = await calls(o.api).create(o.me()?.id ?? \"\", input.value, pub.checked);\n o.service.refresh();\n close(false);\n o.onCreated(id);\n } catch (e) {\n err.textContent = reason(e);\n } finally {\n submit.disabled = false;\n }\n },\n },\n signal,\n },\n [\n h(\"p\", { class: \"coll-new-form\" }, [input, submit]),\n h(\"label\", { class: \"coll-public\" }, [pub, \"Public: anyone can see it and subscribe\"]),\n err,\n ],\n );\n const dialog = h(\"dialog\", { class: \"coll-dialog coll-create\", \"aria-labelledby\": title.id }, [\n h(\"header\", { class: \"media-bar\" }, [\n title,\n h(\"button\", { type: \"button\", class: \"icon-button ic i-x\", \"aria-label\": \"Close\", on: { click: () => close() }, signal }),\n ]),\n form,\n ]);\n function close(refocus = true) {\n if (signal.aborted) return;\n scope.abort();\n if (dialog.open) dialog.close();\n dialog.remove();\n if (refocus) o.opener.focus();\n }\n dialog.addEventListener(\"close\", () => close(), { signal });\n await loadStylesheet(h);\n if (signal.aborted) return;\n document.body.append(dialog);\n dialog.showModal();\n input.focus();\n}\n", "// The save menu (\u00A731): which of your collections have a file; tick to add, untick to take out, or make a new one.\n\nimport type { Collection } from \"../../lib/types.ts\";\nimport type { From } from \"./calls.ts\";\nimport { calls } from \"./calls.ts\";\nimport { type Base, icon, lists, loadStylesheet, reason } from \"./shared.ts\";\n\nexport interface SaveOptions extends Base {\n from: From;\n /** Gets focus back on close. */\n opener: HTMLElement;\n}\n\n/** One save menu at a time. */\nlet saving: (() => void) | null = null;\n\nexport async function openSave(o: SaveOptions): Promise<void> {\n saving?.();\n const { h } = o;\n const call = calls(o.api);\n const scope = new AbortController();\n const { signal } = scope;\n o.signal.addEventListener(\"abort\", () => close(), { signal });\n const title = h(\"h2\", { id: \"coll-save-title\" }, [icon(h), \" Save to collection\"]);\n const list = h(\"ul\", { class: \"coll-choices\" });\n const status = h(\"p\", { class: \"coll-status\", role: \"status\" }, \"Loading\u2026\");\n const input = h(\"input\", { placeholder: \"New collection\", \"aria-label\": \"New collection name\", autocomplete: \"off\" });\n const form = h(\n \"form\",\n {\n class: \"coll-new-form\",\n on: {\n submit: async (e) => {\n e.preventDefault();\n if (!input.value.trim()) return;\n try {\n const id = (await call.create(o.me()?.id ?? \"\", input.value, false)).id;\n input.value = \"\";\n await toggle(id, true);\n } catch (err) {\n status.textContent = reason(err);\n }\n },\n },\n signal,\n },\n [input, h(\"button\", { type: \"submit\" }, \"Create\")],\n );\n const dialog = h(\"dialog\", { class: \"coll-dialog coll-save\", \"aria-labelledby\": title.id }, [\n h(\"header\", { class: \"media-bar\" }, [\n title,\n h(\"button\", { type: \"button\", class: \"icon-button ic i-x\", \"aria-label\": \"Close\", on: { click: () => close() }, signal }),\n ]),\n h(\"div\", { class: \"coll-body\" }, [list, status, form]),\n ]);\n /** Collection id \u2192 the item there (ticked). */\n let saved: Record<string, string> = {};\n /** Collection id \u2192 ticked or unticked, while that is saving. */\n const busy = new Map<string, boolean>();\n\n async function toggle(id: string, on: boolean) {\n busy.set(id, on);\n status.textContent = on ? \"Saving\u2026\" : \"Removing\u2026\";\n render();\n try {\n if (on) saved[id] = (await call.save(id, o.from)).id;\n else if (saved[id]) {\n await call.unsave(saved[id]);\n delete saved[id];\n }\n status.textContent = on ? \"Saved.\" : \"Removed.\";\n o.service.refresh();\n } catch (e) {\n // In there already (another tab): it is ticked.\n if ((e as { status?: number }).status === 409) saved = await call.savedIn(o.from, signal).catch(() => saved);\n else status.textContent = reason(e);\n }\n busy.delete(id);\n render();\n }\n\n function render() {\n const mine = lists(o).mine;\n list.replaceChildren(\n ...mine.map((c: Collection) => {\n const box = h(\"input\", { type: \"checkbox\", checked: busy.get(c.id) ?? !!saved[c.id], disabled: busy.has(c.id) });\n box.addEventListener(\"change\", () => void toggle(c.id, box.checked), { signal });\n // Saving copies the file on the server, which can take a while: a spinner on the row until it is done.\n return h(\n \"li\",\n { \"aria-busy\": busy.has(c.id) ? \"true\" : \"false\" },\n h(\"label\", {}, [\n box,\n \" \",\n c.name,\n h(\"span\", { class: \"coll-meta\" }, c.public ? \" \u00B7 Public: anyone can see it\" : \" \u00B7 Private\"),\n busy.has(c.id) ? h(\"span\", { class: \"coll-spin\", \"aria-hidden\": \"true\" }) : null,\n ]),\n );\n }),\n );\n if (!mine.length && status.textContent === \"\") status.textContent = \"You have no collections yet. Make one:\";\n }\n\n function close() {\n if (signal.aborted) return;\n scope.abort();\n saving = null;\n if (dialog.open) dialog.close();\n dialog.remove();\n o.opener.setAttribute(\"aria-expanded\", \"false\");\n o.opener.focus();\n }\n saving = close;\n dialog.addEventListener(\"close\", () => close(), { signal });\n signal.addEventListener(\"abort\", o.watch(render), { once: true });\n\n await loadStylesheet(h);\n if (signal.aborted) return;\n document.body.append(dialog);\n dialog.showModal();\n o.opener.setAttribute(\"aria-expanded\", \"true\");\n try {\n saved = await call.savedIn(o.from, signal);\n status.textContent = \"\";\n } catch (e) {\n if (signal.aborted) return;\n status.textContent = reason(e);\n }\n render();\n (list.querySelector(\"input\") ?? input).focus();\n}\n", "// A collection's page (/c/:id, \u00A731): its items as a grid like the media grid's, newest first under month headings, what\n// is new since you last looked highlighted.\n\nimport type { CollectionItem, Message } from \"../../lib/types.ts\";\nimport type { ViewerImage } from \"../room/viewer.ts\";\nimport { calls, type Meta } from \"./calls.ts\";\nimport { openSave } from \"./save.ts\";\nimport {\n ACCEPT,\n asMessage,\n type Base,\n changed,\n dateOf,\n icon,\n lists,\n loadStylesheet,\n MAX_BYTES,\n MEDIA,\n monthOf,\n pager,\n picture,\n reason,\n} from \"./shared.ts\";\n\nexport interface PageOptions extends Base {\n id: string;\n navigate: (path: string) => void;\n}\n\nexport async function mountCollection(root: HTMLElement, o: PageOptions): Promise<void> {\n const { h, api, signal, id } = o;\n const call = calls(api);\n const [, meta] = await Promise.all([\n loadStylesheet(h),\n call.get(id, signal).catch(() => null),\n (async () => {\n // Your subscription's `seen_at` decides what is new: wait for the store to have it (just after a reload).\n if (o.me() && !o.list()) {\n await changed(o, 2000);\n }\n })(),\n ]);\n if (signal.aborted) return;\n /** Not there (any more), or not yours to see. */\n function gone() {\n root.replaceChildren(\n h(\"section\", { class: \"collection not-found\" }, [\n h(\"h1\", {}, [icon(h), \" This collection doesn't exist.\"]),\n h(\"p\", {}, [\"It may be private, or deleted. \", h(\"a\", { href: \"/\" }, \"Back to rooms\")]),\n ]),\n );\n }\n if (!meta) return gone();\n let info: Meta = meta;\n const me = o.me();\n const mine = !!me && info.owner === me.id;\n const ownerName = meta.expand?.owner?.name ?? \"\";\n const seenAt = lists(o).subs.find((c) => c.id === id)?.seen_at ?? \"\";\n let pages = pager(o, id, signal);\n\n const heading = h(\"h1\", { id: \"coll-title\" });\n const metaLine = h(\"p\", { class: \"coll-meta\" });\n const actions = h(\"div\", { class: \"coll-actions\" });\n const notice = h(\"p\", { class: \"coll-notice\", role: \"status\" });\n const newLine = h(\"p\", { class: \"coll-new\", hidden: true });\n const grid = h(\"div\", { class: \"media-grid coll-grid\" });\n const status = h(\"p\", { class: \"media-status\", role: \"status\" });\n root.replaceChildren(\n h(\"section\", { class: \"collection\", \"aria-labelledby\": \"coll-title\" }, [\n // The tile's tint is the sidebar row's (t0..t3, views/rooms.ts).\n h(\"header\", { class: `coll-head t${id.charCodeAt(0) % 4}` }, [\n h(\"a\", { href: \"/\", class: \"back ic i-back\", \"aria-label\": \"Back to rooms\" }),\n heading,\n metaLine,\n actions,\n notice,\n ]),\n newLine,\n grid,\n status,\n ]),\n );\n\n const fail = (what: string, e: unknown) => {\n notice.textContent = `Couldn't ${what}. ${reason(e)}`;\n };\n const btn = (label: string, run: () => unknown, cls = \"\") =>\n h(\"button\", { type: \"button\", class: cls, on: { click: () => void run() }, signal }, label);\n const count = (n: number) => `${n} ${n === 1 ? \"item\" : \"items\"}`;\n const empty = () => (mine ? \"Nothing here yet. Upload images and videos, or save them from the chat.\" : \"Nothing here yet.\");\n\n /** Files waiting to be uploaded (the owner's), one at a time; each comes in at the top once the store hears of it. */\n const queue: File[] = [];\n let sent = 0;\n let busy = false;\n let failed: string[] = [];\n const picker = h(\"input\", {\n type: \"file\",\n multiple: true,\n accept: ACCEPT,\n hidden: true,\n on: {\n change: () => {\n upload([...(picker.files ?? [])]);\n picker.value = \"\";\n },\n },\n signal,\n });\n function upload(files: File[]) {\n for (const f of files) {\n if (!MEDIA.test(f.name)) failed.push(`${f.name}: not an image or video`);\n else if (f.size > MAX_BYTES) failed.push(`${f.name}: larger than 20 MB`);\n else queue.push(f);\n }\n if (busy) return;\n if (!queue.length) return report();\n busy = true;\n void (async () => {\n while (queue.length && !signal.aborted) {\n const f = queue[0]!;\n const at = `Uploading ${sent + 1} of ${sent + queue.length}\u2026`;\n notice.textContent = at;\n try {\n await call.upload(id, f, (x) => (notice.textContent = `${at} ${Math.round(x * 100)}%`));\n } catch (e) {\n // Too many at once (the server's rate limit): wait, then the same one again.\n if ((e as { status?: number }).status === 429) {\n notice.textContent = \"Waiting for the server\u2026\";\n await new Promise((r) => setTimeout(r, 10_000));\n continue;\n }\n failed.push(`${f.name}: ${reason(e)}`);\n }\n queue.shift();\n sent++;\n o.service.refresh();\n }\n sent = 0;\n busy = false;\n report();\n })();\n }\n /** After an upload: what didn't go, or nothing. */\n function report() {\n notice.textContent = failed.length ? `Couldn't upload ${failed.join(\"; \")}` : \"\";\n failed = [];\n }\n\n /** Renaming or confirming a delete: the actions stay as they are while the store changes. */\n let editing = false;\n /** The button that was pressed to edit (Rename or Delete): it gets focus back. */\n let back = \"\";\n /** What the actions were drawn for: they are drawn again only when that changes, so focus stays. */\n let drawn = \"\";\n function doneEditing() {\n editing = false;\n drawn = \"\";\n renderHead();\n }\n\n /** Saved: true. Refused: the reason is shown, and whatever was being edited stays. */\n async function change(patch: { name?: string; public?: boolean }): Promise<boolean> {\n try {\n info = { ...info, ...(await call.update(id, patch)) };\n notice.textContent = \"\";\n o.service.refresh();\n doneEditing();\n return true;\n } catch (e) {\n fail(\"save\", e);\n return false;\n }\n }\n\n function renameForm() {\n editing = true;\n back = \"Rename\";\n const input = h(\"input\", { value: info.name, \"aria-label\": \"Collection name\", autocomplete: \"off\" });\n const form = h(\n \"form\",\n {\n class: \"coll-rename\",\n on: {\n submit: (e) => {\n e.preventDefault();\n void change({ name: input.value });\n },\n keydown: (e) => e.key === \"Escape\" && doneEditing(),\n },\n signal,\n },\n [input, h(\"button\", { type: \"submit\" }, \"Save\"), btn(\"Cancel\", doneEditing, \"link\")],\n );\n actions.replaceChildren(form);\n input.focus();\n input.select();\n }\n\n function confirmDelete() {\n editing = true;\n back = \"Delete\";\n actions.replaceChildren(\n h(\"span\", {}, `Delete \u201C${info.name}\u201D${info.items ? ` and its ${count(info.items)}` : \"\"}? This can't be undone.`),\n btn(\n \"Delete collection\",\n async () => {\n try {\n await call.remove(id);\n o.service.refresh();\n o.navigate(\"/\");\n } catch (e) {\n fail(\"delete it\", e);\n }\n },\n \"danger\",\n ),\n btn(\"Cancel\", doneEditing, \"link\"),\n );\n actions.querySelector(\"button\")?.focus();\n }\n\n function renderHead() {\n if (signal.aborted) return;\n heading.replaceChildren(icon(h), \" \", info.name);\n metaLine.textContent = [mine ? \"Yours\" : ownerName && `By ${ownerName}`, info.public ? \"Public\" : \"Private\", count(info.items)]\n .filter(Boolean)\n .join(\" \u00B7 \");\n const following = lists(o).subs.some((c) => c.id === id);\n const key = [info.public, following].join();\n if (editing || key === drawn) return;\n drawn = key;\n const focused = [...actions.children].findIndex((c) => c.contains(document.activeElement));\n if (mine) {\n actions.replaceChildren(\n btn(\"Upload\", () => picker.click()),\n btn(\"Rename\", renameForm),\n btn(info.public ? \"Make private\" : \"Make public\", () => change({ public: !info.public })),\n btn(\"Delete\", confirmDelete, \"danger\"),\n );\n } else if (me && (info.public || following)) {\n const b = btn(following ? \"Unsubscribe\" : \"Subscribe\", async () => {\n b.disabled = true;\n try {\n await call.follow(id, !following);\n o.service.refresh();\n await changed(o, 1000);\n } catch (e) {\n fail(following ? \"unsubscribe\" : \"subscribe\", e);\n }\n drawn = \"\";\n renderHead();\n });\n b.setAttribute(\"aria-pressed\", String(following));\n actions.replaceChildren(b);\n } else actions.replaceChildren();\n const kids = [...actions.children] as HTMLElement[];\n if (focused >= 0) (kids.find((c) => back && c.textContent === back) ?? kids[focused])?.focus();\n back = \"\";\n }\n renderHead();\n if (mine) {\n root.firstElementChild!.append(picker);\n const files = (e: DragEvent) => e.dataTransfer?.types.includes(\"Files\");\n root.addEventListener(\"dragover\", (e) => files(e) && e.preventDefault(), { signal });\n root.addEventListener(\n \"drop\",\n (e) => {\n if (!files(e)) return;\n e.preventDefault();\n upload([...(e.dataTransfer?.files ?? [])]);\n },\n { signal },\n );\n // Pasted (Ctrl+V) anywhere on the page, unless a dialog (the viewer, a menu's) is open over it.\n document.addEventListener(\n \"paste\",\n (e) => {\n const pasted = [...(e.clipboardData?.files ?? [])];\n if (!pasted.length || document.querySelector(\"dialog[open]\")) return;\n e.preventDefault();\n upload(pasted);\n },\n { signal },\n );\n }\n\n /** The newest item's `created` (or the collection's last_added), to send as seen once the tab is visible. */\n let unseen = \"\";\n function markSeen() {\n if (!unseen || document.visibilityState !== \"visible\" || !lists(o).subs.some((c) => c.id === id)) return;\n const at = unseen;\n unseen = \"\";\n // Not while the store is telling its listeners of a change: the badge goes with the next one.\n queueMicrotask(() => signal.aborted || o.service.seen(id, at));\n }\n document.addEventListener(\"visibilitychange\", markSeen, { signal });\n\n /** The collection as the store has it (yours, or followed), last time: what changed since. */\n const listed = () => [...lists(o).mine, ...lists(o).subs].find((c) => c.id === id);\n let last = listed();\n function follow() {\n const c = listed();\n if (c) {\n info = { ...info, name: c.name, public: c.public, items: c.items };\n if (last && c.last_added !== last.last_added) void newer();\n // Some may have been taken out (the save menu, another tab): the gone ones leave the grid.\n if (last && c.items < last.items + (c.last_added !== last.last_added ? 1 : 0)) void prune();\n if (c.new) {\n unseen = c.last_added;\n markSeen();\n }\n } else if (last) {\n // Gone from the list: made private, deleted, or no longer followed.\n void call.get(id, signal).then(\n (m) => {\n info = { ...info, ...m };\n renderHead();\n },\n (e: { status?: number }) => e.status === 404 && gone(),\n );\n }\n last = c;\n renderHead();\n }\n signal.addEventListener(\"abort\", o.watch(follow), { once: true });\n\n let month = \"\";\n let fresh = 0;\n /** An item's cell, at the end (a page of older ones) or at the top (`added`: new while the page is open). */\n function add(it: CollectionItem, added = false) {\n const mo = monthOf.format(dateOf(it.created));\n const isNew = added || (!!seenAt && it.created > seenAt);\n if (isNew && !added) fresh++;\n const label = `${it.name}${it.video ? \", video\" : \"\"}${isNew ? \", new\" : \"\"}`;\n const tile = h(\n \"button\",\n {\n type: \"button\",\n class: \"media-tile\",\n \"aria-label\": label,\n title: it.name,\n on: { click: () => void open(it, tile) },\n signal,\n },\n [picture(o, it, signal), it.video && h(\"span\", { class: \"att-play\", \"aria-hidden\": \"true\" })],\n );\n const cell = h(\"div\", { class: `coll-cell${isNew ? \" new\" : \"\"}`, dataset: { item: it.id } }, [tile]);\n if (me) {\n const save: HTMLButtonElement = h(\n \"button\",\n {\n type: \"button\",\n class: \"att-save\",\n \"aria-label\": `Save ${it.name} to collection`,\n title: \"Save to collection\",\n on: { click: () => openSave({ ...o, from: { item: it.id }, opener: save }) },\n signal,\n },\n icon(h),\n );\n cell.append(save);\n }\n if (mine) {\n cell.append(\n h(\n \"button\",\n {\n type: \"button\",\n class: \"coll-remove\",\n \"aria-label\": `Remove ${it.name} from the collection`,\n title: \"Remove from collection\",\n on: { click: () => void remove(it, cell) },\n signal,\n },\n \"\u00D7\",\n ),\n );\n }\n if (!added) {\n if (mo !== month) grid.append(h(\"h2\", {}, mo));\n month = mo;\n grid.append(cell);\n } else if (grid.firstElementChild?.textContent === mo) grid.firstElementChild.after(cell);\n else {\n grid.prepend(h(\"h2\", {}, mo), cell);\n month ||= mo;\n }\n }\n\n async function remove(it: CollectionItem, cell: HTMLElement) {\n try {\n await call.unsave(it.id);\n } catch (e) {\n return fail(\"remove it\", e);\n }\n const cells = [...grid.querySelectorAll(\".coll-cell\")];\n const at = cells.indexOf(cell);\n const to = cells[at + 1] ?? cells[at - 1];\n drop(it);\n info = { ...info, items: Math.max(0, info.items - 1) };\n renderHead();\n // Focus stays in the grid (the next one's Remove), or goes to the actions once it is empty.\n (to?.querySelector<HTMLElement>(\".coll-remove\") ?? actions.querySelector(\"button\"))?.focus();\n o.service.refresh();\n }\n\n /** An item no longer in the collection: its cell goes, and its month's heading when it was the last of it. */\n function drop(it: CollectionItem) {\n const at = pages.items.indexOf(it);\n if (at < 0) return;\n pages.items.splice(at, 1);\n const cell = [...grid.querySelectorAll<HTMLElement>(\".coll-cell\")].find((c) => c.dataset.item === it.id);\n if (cell) {\n const [before, after] = [cell.previousElementSibling, cell.nextElementSibling];\n if (cell.contains(document.activeElement)) (after?.querySelector<HTMLElement>(\"button\") ?? actions.querySelector(\"button\"))?.focus();\n cell.remove();\n if (before?.tagName === \"H2\" && (!after || after.tagName === \"H2\")) {\n before.remove();\n if (!after) month = \"\";\n }\n }\n if (pages.done && !pages.items.length) status.textContent = empty();\n }\n\n /** Taken out elsewhere (the save menu, another tab): those shown that are gone go from the grid. */\n let pruned = 0;\n async function prune() {\n const seq = ++pruned;\n const shown = [...pages.items];\n const oldest = shown.at(-1);\n const ids = oldest && (await call.idsSince(id, oldest, signal).catch(() => null));\n if (!ids || seq !== pruned || signal.aborted) return;\n for (const it of shown.filter((x) => !ids.has(x.id))) drop(it);\n }\n\n async function more() {\n const p = pages;\n if (p.done) return;\n status.textContent = \"Loading\u2026\";\n try {\n const page = await p.next();\n if (signal.aborted || p !== pages) return;\n for (const it of page) add(it);\n status.textContent = p.done && !p.items.length ? empty() : \"\";\n } catch {\n if (signal.aborted || p !== pages) return;\n seen.unobserve(status);\n status.replaceChildren(\n \"Couldn't load the collection. \",\n btn(\"Retry\", () => void more(), \"link\"),\n );\n return;\n }\n seen.unobserve(status);\n if (!p.done) seen.observe(status);\n }\n\n /** From the start again (the page was empty, or more was added than a page holds). */\n function reset() {\n pages = pager(o, id, signal);\n grid.replaceChildren();\n month = \"\";\n return more();\n }\n\n /** Items added while the page is open: at the top, marked new. */\n async function newer() {\n const top = pages.items[0];\n if (!top) return reset();\n const got = await call.items(id, top, signal, true).catch(() => null);\n if (!got || signal.aborted) return;\n if (got.more) return reset();\n const shown = new Set(pages.items.map((x) => x.id));\n const added = got.items.filter((x) => !shown.has(x.id));\n pages.items.unshift(...added);\n for (const it of added.reverse()) add(it, true);\n if (added.length) status.textContent = \"\";\n }\n\n async function open(it: CollectionItem, opener: HTMLElement) {\n const images = (): ViewerImage[] => [...pages.items].reverse().map((x) => ({ message: asMessage(x), file: x.file, video: x.video }));\n const all = images();\n const p = pages;\n try {\n const { openViewer } = await import(\"../room/viewer.ts\");\n if (signal.aborted) return;\n await openViewer({\n images: all,\n start: all.findIndex((x) => x.message.id === it.id),\n more: [!p.done, false],\n page: async (older) => {\n const got = older ? await p.next() : [];\n return { messages: got.map(asMessage).reverse(), done: !older || p.done };\n },\n media: (m) => [{ message: m, file: m.files![0]!, video: p.items.find((x) => x.id === m.id)?.video ?? false }],\n h,\n name: (m, f) => m.file_names?.[f] ?? f,\n when: (m) => `Added ${o.when(m.created)}`,\n fileUrl: (m, f) => api.itemUrl({ id: m.id, file: f }),\n ...(me ? { onSave: (m: Message, _f: string, b: HTMLElement) => openSave({ ...o, from: { item: m.id }, opener: b }) } : {}),\n opener,\n follow: () => {},\n signal,\n });\n } catch {\n window.open(api.itemUrl(it), \"_blank\", \"noopener\");\n }\n }\n\n const seen = new IntersectionObserver((es) => es.some((e) => e.isIntersecting) && void more(), { rootMargin: \"400px\" });\n signal.addEventListener(\"abort\", () => seen.disconnect(), { once: true });\n await more();\n if (signal.aborted) return;\n if (fresh) {\n newLine.hidden = false;\n newLine.textContent = `${fresh >= 60 ? \"60+\" : fresh} new since your last visit`;\n }\n // Seen once it is on screen in a visible tab: the sidebar's count goes.\n unseen = pages.items[0]?.created ?? \"\";\n markSeen();\n}\n", "// The picker the composer opens (\u00A731): items of your collections and those you follow, to attach.\n\nimport type { CollectionItem } from \"../../lib/types.ts\";\nimport { type Base, icon, lists, loadStylesheet, pager, picture } from \"./shared.ts\";\n\nexport interface PickOptions extends Base {\n /** At most this many may be picked (what the message still has room for). */\n max: number;\n /** Attach these (Attach was pressed). */\n onPick: (items: CollectionItem[]) => void;\n opener: HTMLElement;\n}\n\nexport async function openPicker(o: PickOptions): Promise<void> {\n const { h } = o;\n const scope = new AbortController();\n const { signal } = scope;\n o.signal.addEventListener(\"abort\", () => close(), { signal });\n const { mine, subs } = lists(o);\n const all = [...mine, ...subs];\n const title = h(\"h2\", { id: \"coll-pick-title\" }, [icon(h), \" Attach from collections\"]);\n /** The collection shown: a row of chips, as the app's. */\n let chosen = all[0]?.id ?? \"\";\n const chips = all.map((c) =>\n h(\n \"button\",\n {\n type: \"button\",\n class: \"coll-chip\",\n \"aria-pressed\": String(c.id === chosen),\n on: { click: (e: Event) => choose(c.id, e.currentTarget as HTMLElement) },\n signal,\n },\n c.owner ? `${c.name} \u00B7 ${c.owner.name}` : c.name,\n ),\n );\n const row = h(\"div\", { class: \"coll-chips\", role: \"group\", \"aria-label\": \"Collection\" }, chips);\n const grid = h(\"div\", { class: \"media-grid coll-grid\" });\n const status = h(\"p\", { class: \"media-status\", role: \"status\" });\n const count = h(\"span\", { class: \"coll-count\", \"aria-live\": \"polite\" });\n const attach = h(\"button\", { type: \"button\", disabled: true, on: { click: () => done() }, signal }, \"Attach\");\n const body = h(\"div\", { class: \"coll-body\" }, [grid, status]);\n const dialog = h(\"dialog\", { class: \"coll-dialog coll-pick\", \"aria-labelledby\": title.id }, [\n h(\"header\", { class: \"media-bar\" }, [\n title,\n h(\"button\", { type: \"button\", class: \"icon-button ic i-x\", \"aria-label\": \"Close\", on: { click: () => close() }, signal }),\n ]),\n all.length ? row : null,\n body,\n h(\"footer\", { class: \"coll-foot\" }, [count, attach]),\n ]);\n /** Picked, in the order they were. */\n const picked = new Map<string, CollectionItem>();\n let pages = pager(o, \"\", signal);\n\n function update() {\n count.textContent = picked.size\n ? `${picked.size} picked${picked.size >= o.max ? \" (the most a message takes)\" : \"\"}`\n : o.max\n ? \"\"\n : \"The message has all the files it can take.\";\n attach.disabled = !picked.size;\n attach.textContent = picked.size ? `Attach ${picked.size}` : \"Attach\";\n }\n\n function tile(it: CollectionItem) {\n const b: HTMLButtonElement = h(\n \"button\",\n {\n type: \"button\",\n class: \"media-tile\",\n \"aria-label\": `${it.name}${it.video ? \", video\" : \"\"}`,\n title: it.name,\n \"aria-pressed\": String(picked.has(it.id)),\n on: {\n click: () => {\n if (picked.has(it.id)) picked.delete(it.id);\n else if (picked.size < o.max) picked.set(it.id, it);\n b.setAttribute(\"aria-pressed\", String(picked.has(it.id)));\n update();\n },\n },\n signal,\n },\n [picture(o, it, signal), it.video && h(\"span\", { class: \"att-play\", \"aria-hidden\": \"true\" })],\n );\n return b;\n }\n\n async function more() {\n if (pages.done || !chosen) return;\n const p = pages;\n status.textContent = \"Loading\u2026\";\n try {\n const got = await p.next();\n if (signal.aborted || p !== pages) return;\n grid.append(...got.map(tile));\n status.textContent = p.done && !p.items.length ? \"Nothing in this collection yet.\" : \"\";\n } catch {\n if (signal.aborted || p !== pages) return;\n seen.unobserve(status);\n status.replaceChildren(\n \"Couldn't load the collection. \",\n h(\"button\", { type: \"button\", class: \"link\", on: { click: () => void more() }, signal }, \"Retry\"),\n );\n return;\n }\n seen.unobserve(status);\n if (!p.done) seen.observe(status);\n }\n\n function show() {\n pages = pager(o, chosen, signal);\n grid.replaceChildren();\n void more();\n }\n\n function choose(id: string, chip: HTMLElement) {\n if (id === chosen) return;\n chosen = id;\n for (const c of chips) c.setAttribute(\"aria-pressed\", String(c === chip));\n chip.scrollIntoView({ block: \"nearest\", inline: \"nearest\" });\n show();\n }\n const seen = new IntersectionObserver((es) => es.some((e) => e.isIntersecting) && void more(), { root: body, rootMargin: \"400px\" });\n\n function done() {\n const items = [...picked.values()];\n close();\n if (items.length) o.onPick(items);\n }\n\n function close() {\n if (signal.aborted) return;\n scope.abort();\n seen.disconnect();\n if (dialog.open) dialog.close();\n dialog.remove();\n o.opener.focus();\n }\n dialog.addEventListener(\"close\", () => close(), { signal });\n\n await loadStylesheet(h);\n if (signal.aborted) return;\n document.body.append(dialog);\n dialog.showModal();\n update();\n if (!all.length) {\n status.textContent = \"You have no collections yet. Save images and videos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EAAK,UAAUjB,CAAM,EAChBe,EAAE,MAAME,EAAK,QAAQjB,CAAM,CAClC,CAEA,SAASkB,GAAO,CACdX,EAAQC,EAAM,EAAGd,EAAQR,CAAM,EAC/Ba,EAAK,gBAAgB,EAChBe,EAAK,CACZ,CAEA,SAASjB,EAAOsB,EAAYC,EAAmB,CAC7C,GAAID,IAAOzB,EACX,CAAAA,EAASyB,EACT,QAAWE,KAAK1B,EAAO0B,EAAE,aAAa,eAAgB,OAAOA,IAAMD,CAAI,CAAC,EACxEA,EAAK,eAAe,CAAE,MAAO,UAAW,OAAQ,SAAU,CAAC,EAC3DF,EAAK,EACP,CACA,IAAMD,EAAO,IAAI,qBAAsBK,GAAOA,EAAG,KAAM1B,GAAMA,EAAE,cAAc,GAAK,KAAKkB,EAAK,EAAG,CAAE,KAAMV,EAAM,WAAY,OAAQ,CAAC,EAElI,SAASD,GAAO,CACd,IAAMoB,EAAQ,CAAC,GAAGjB,EAAO,OAAO,CAAC,EACjCnB,EAAM,EACFoC,EAAM,QAAQ,EAAE,OAAOA,CAAK,CAClC,CAEA,SAASpC,GAAQ,CACXD,EAAO,UACXD,EAAM,MAAM,EACZgC,EAAK,WAAW,EACZZ,EAAO,MAAMA,EAAO,MAAM,EAC9BA,EAAO,OAAO,EACd,EAAE,OAAO,MAAM,EACjB,CAIA,GAHAA,EAAO,iBAAiB,QAAS,IAAMlB,EAAM,EAAG,CAAE,OAAAD,CAAO,CAAC,EAE1D,MAAMsC,EAAexC,CAAC,EAClB,CAAAE,EAAO,QAIX,IAHA,SAAS,KAAK,OAAOmB,CAAM,EAC3BA,EAAO,UAAU,EACjBI,EAAO,EACH,CAAClB,EAAI,OAAQ,CACfS,EAAO,YAAc,kFACrB,MACF,CACAkB,EAAK,EACLvB,EAAM,CAAC,GAAG,MAAM,EAClB",
|
|
6
|
+
"names": ["RECORDS", "lit", "v", "ITEM_FIELDS", "calls", "api", "id", "signal", "owner", "name", "isPublic", "body", "collection", "after", "newer", "op", "cursor", "query", "items", "oldest", "ids", "filter", "page", "x", "from", "file", "onUpload", "item", "on", "stylesheet", "loadStylesheet", "h", "resolve", "link", "MEDIA", "ACCEPT", "MAX_BYTES", "lists", "changed", "ms", "done", "off", "timer", "reason", "e", "err", "icon", "monthOf", "dateOf", "created", "asMessage", "it", "id", "file", "name", "picture", "b", "signal", "img", "pager", "collection", "items", "loading", "calls", "page", "openCreate", "h", "scope", "signal", "close", "title", "icon", "input", "pub", "err", "submit", "form", "e", "id", "calls", "reason", "dialog", "refocus", "loadStylesheet", "saving", "openSave", "h", "call", "calls", "scope", "signal", "close", "title", "icon", "list", "status", "input", "form", "e", "id", "toggle", "err", "reason", "dialog", "saved", "busy", "on", "render", "mine", "lists", "c", "box", "loadStylesheet", "mountCollection", "root", "o", "h", "api", "signal", "id", "call", "calls", "meta", "loadStylesheet", "changed", "gone", "icon", "info", "me", "mine", "ownerName", "seenAt", "lists", "c", "pages", "pager", "heading", "metaLine", "actions", "notice", "newLine", "grid", "status", "fail", "what", "e", "reason", "btn", "label", "run", "cls", "count", "n", "empty", "queue", "sent", "busy", "failed", "picker", "ACCEPT", "upload", "files", "f", "MEDIA", "MAX_BYTES", "report", "at", "x", "r", "editing", "back", "drawn", "doneEditing", "renderHead", "change", "patch", "renameForm", "input", "form", "confirmDelete", "following", "key", "focused", "b", "kids", "pasted", "unseen", "markSeen", "listed", "last", "follow", "newer", "prune", "m", "month", "fresh", "add", "it", "added", "mo", "monthOf", "dateOf", "isNew", "tile", "open", "picture", "cell", "save", "openSave", "remove", "cells", "to", "drop", "before", "after", "pruned", "seq", "shown", "oldest", "ids", "more", "p", "page", "seen", "reset", "top", "got", "opener", "all", "asMessage", "openViewer", "older", "_f", "es", "openPicker", "h", "scope", "signal", "close", "mine", "subs", "lists", "all", "title", "icon", "chosen", "chips", "e", "choose", "row", "grid", "status", "count", "attach", "done", "body", "dialog", "picked", "pages", "pager", "update", "tile", "it", "b", "picture", "more", "p", "got", "seen", "show", "id", "chip", "c", "es", "items", "loadStylesheet"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var q=r=>({login:[{name:"email",label:"Email",type:"email",autocomplete:"email"},{name:"password",label:"Password",type:"password",autocomplete:"current-password"}],signup:[{name:"name",label:"Display name",type:"text",autocomplete:"nickname"},{name:"email",label:"Email",type:"email",autocomplete:"email"},{name:"password",label:"Password",type:"password",autocomplete:"new-password",extra:{minlength:r.passwordMin}}]}),P={name:"invite_code",label:"Invite code",type:"text",autocomplete:"off"},L={login:"Log in",signup:"Sign up"};function R(r){let{h:o,clear:v,uniqueId:F,byLine:x,ApiError:u,errorMessage:E,SIGNUP_LOGIN_FAILED:O,LIMITS:I,textLength:N,DEFAULT_SITE:D}=r.kit,M=q(I),s=null,i=r.mode??"login",c=!1,n={name:"",email:"",password:"",invite_code:""},g=()=>r.store?.get().site??D,S=a=>a==="signup"&&g().inviteOnly?[...M.signup,P]:M[a],_=()=>{},U=F("login"),b;function m(a={}){s?.abort(),s=new AbortController;let{signal:e}=s,p=Object.keys(L).map(t=>o("button",{type:"button",role:"tab","aria-selected":String(t===i),on:{click:()=>{t!==i&&(i=t,m())}},signal:e},L[t])),l=o("button",{type:"submit",class:"primary",disabled:c},L[i]),h=S(i).map(t=>{let d=`${U}-${t.name}`,A=`${d}-error`,T=a.fields?.[t.name];return o("div",{class:"field"},[o("label",{for:d},t.label),o("input",{id:d,name:t.name,type:t.type,autocomplete:t.autocomplete,required:!0,value:n[t.name],"aria-invalid":T?"true":null,"aria-describedby":A,...t.extra,on:{input:G=>n[t.name]=G.target.value},signal:e}),o("p",{id:A,class:"field-error"},T??"")])}),y=o("form",{class:"auth-form","aria-label":L[i],on:{submit:t=>{t.preventDefault();for(let d of S(i))n[d.name]=y.elements.namedItem(d.name).value;k(l)}},signal:e},[...h,o("p",{role:"alert",class:"form-error"},a.form??""),l]),{title:w,logo:f}=g();v(b),b.append(o("section",{class:"auth"},[o("h1",{class:f?"has-logo":""},[f?o("img",{src:f,alt:"",class:"brand-logo"}):null,w]),x(g(),"p"),o("div",{class:"auth-card"},[o("div",{role:"tablist",class:"tabs"},p),y]),o("p",{class:"auth-skip"},o("a",{href:"/"},"Just looking? Read the Open Air rooms"))]))}async function k(a){if(!c){if(i==="signup"&&N(n.name.trim())>I.userName){m({fields:{name:`Must be no more than ${I.userName} characters.`}});return}c=!0,a.disabled=!0;try{let e=i==="login"?await r.api.logIn(n.email,n.password):await r.api.signUp({name:n.name,email:n.email,password:n.password,...g().inviteOnly?{inviteCode:n.invite_code}:{}});c=!1,a.disabled=!1,r.onLogin(e)}catch(e){if(c=!1,!s||s.signal.aborted)return;if(e instanceof u&&e.codes.auth===O){i="login",m({form:`Your account was created, but logging in failed: ${E(e)} Log in to continue.`});return}let p=e instanceof u?e.fields:{},l=Object.fromEntries(Object.entries(p).filter(([f])=>S(i).some(t=>t.name===f)));i==="signup"&&e instanceof u&&e.codes.email==="validation_not_unique"&&(l.email="There is already an account with this email. Log in instead.");let h=i==="login"&&e instanceof u&&e.status===400,y=e instanceof u&&!l.invite_code?p.invite_code:void 0,w=Object.keys(l).length?"":y??(h?"Wrong email or password.":E(e));m({form:w,fields:l})}}}return{mount(a){b=a,m(),_=r.store?.subscribe((e,p)=>{e.site!==p.site&&!c&&m()})??(()=>{})},unmount(){_(),s?.abort(),s=null,v(b)}}}export{R as createLoginView};
|
|
2
|
+
//# sourceMappingURL=login-G7Y44CJ7.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../web/src/views/login.ts"],
|
|
4
|
+
"sourcesContent": ["// Login / signup screen (\u00A77.1): /login and /signup, reached from the header (\u00A723.3). Shows the site's title and logo,\n// and asks for an invite code to sign up while the site is invite-only (\u00A724).\n//\n// A lazy chunk: app.ts loads it for /login and /signup (at once for someone not signed in). It imports types only, and\n// gets what it uses of app.js in `kit` (lazy.ts LOGIN_KIT).\n\nimport type { Api, ApiError, errorMessage, SIGNUP_LOGIN_FAILED } from \"../api.ts\";\nimport type { clear, h, uniqueId } from \"../dom.ts\";\nimport type { byLine } from \"../header.ts\";\nimport type { LIMITS, textLength } from \"../lib/limits.ts\";\nimport type { Site, User } from \"../lib/types.ts\";\nimport type { View } from \"../router.ts\";\nimport type { AppState, Store } from \"../store.ts\";\n\nexport interface LoginKit {\n h: typeof h;\n clear: typeof clear;\n uniqueId: typeof uniqueId;\n byLine: typeof byLine;\n ApiError: typeof ApiError;\n errorMessage: typeof errorMessage;\n SIGNUP_LOGIN_FAILED: typeof SIGNUP_LOGIN_FAILED;\n LIMITS: typeof LIMITS;\n textLength: typeof textLength;\n /** The site without a site record. */\n DEFAULT_SITE: Site;\n}\n\ntype Mode = \"login\" | \"signup\";\ntype Field = \"name\" | \"email\" | \"password\" | \"invite_code\";\n\ninterface FieldSpec {\n name: Field;\n label: string;\n type: string;\n autocomplete: string;\n extra?: Record<string, string | number>;\n}\n\nconst fieldSpecs = (LIMITS: LoginKit[\"LIMITS\"]): Record<Mode, FieldSpec[]> => ({\n login: [\n { name: \"email\", label: \"Email\", type: \"email\", autocomplete: \"email\" },\n { name: \"password\", label: \"Password\", type: \"password\", autocomplete: \"current-password\" },\n ],\n signup: [\n // No `maxlength`: it counts UTF-16 units (an emoji is 2), the server counts characters. Checked on submit.\n { name: \"name\", label: \"Display name\", type: \"text\", autocomplete: \"nickname\" },\n { name: \"email\", label: \"Email\", type: \"email\", autocomplete: \"email\" },\n { name: \"password\", label: \"Password\", type: \"password\", autocomplete: \"new-password\", extra: { minlength: LIMITS.passwordMin } },\n ],\n});\n\n/** Asked for last on signup, while the site is invite-only (\u00A724). */\nconst INVITE: FieldSpec = { name: \"invite_code\", label: \"Invite code\", type: \"text\", autocomplete: \"off\" };\n\nconst TITLES: Record<Mode, string> = { login: \"Log in\", signup: \"Sign up\" };\n\n/** `store`: where the site's branding and signup policy are (\u00A724); the defaults without one. */\nexport function createLoginView(deps: {\n kit: LoginKit;\n api: Api;\n onLogin: (user: User) => void;\n mode?: Mode;\n store?: Store<AppState>;\n}): View {\n const { h, clear, uniqueId, byLine, ApiError, errorMessage, SIGNUP_LOGIN_FAILED, LIMITS, textLength, DEFAULT_SITE } = deps.kit;\n const FIELDS = fieldSpecs(LIMITS);\n let ac: AbortController | null = null;\n let mode: Mode = deps.mode ?? \"login\";\n let busy = false;\n const values: Record<Field, string> = { name: \"\", email: \"\", password: \"\", invite_code: \"\" };\n const site = () => deps.store?.get().site ?? DEFAULT_SITE;\n const fieldsOf = (m: Mode) => (m === \"signup\" && site().inviteOnly ? [...FIELDS.signup, INVITE] : FIELDS[m]);\n let offStore = () => {};\n const prefix = uniqueId(\"login\");\n let root: HTMLElement;\n\n function render(errors: { form?: string; fields?: Record<string, string> } = {}) {\n ac?.abort();\n ac = new AbortController();\n const { signal } = ac;\n\n const tabs = (Object.keys(TITLES) as Mode[]).map((m) =>\n h(\n \"button\",\n {\n type: \"button\",\n role: \"tab\",\n \"aria-selected\": String(m === mode),\n on: {\n click: () => {\n if (m === mode) return;\n mode = m;\n render();\n },\n },\n signal,\n },\n TITLES[m],\n ),\n );\n\n const submit = h(\"button\", { type: \"submit\", class: \"primary\", disabled: busy }, TITLES[mode]);\n\n const fields = fieldsOf(mode).map((f) => {\n const id = `${prefix}-${f.name}`;\n const errId = `${id}-error`;\n const error = errors.fields?.[f.name];\n return h(\"div\", { class: \"field\" }, [\n h(\"label\", { for: id }, f.label),\n h(\"input\", {\n id,\n name: f.name,\n type: f.type,\n autocomplete: f.autocomplete,\n required: true,\n value: values[f.name],\n \"aria-invalid\": error ? \"true\" : null,\n \"aria-describedby\": errId,\n ...f.extra,\n on: { input: (e) => (values[f.name] = (e.target as HTMLInputElement).value) },\n signal,\n }),\n h(\"p\", { id: errId, class: \"field-error\" }, error ?? \"\"),\n ]);\n });\n\n const form = h(\n \"form\",\n {\n class: \"auth-form\",\n \"aria-label\": TITLES[mode],\n on: {\n submit: (e) => {\n e.preventDefault();\n // Read the inputs now: autofill/password managers may not fire input events.\n for (const f of fieldsOf(mode)) values[f.name] = (form.elements.namedItem(f.name) as HTMLInputElement).value;\n void onSubmit(submit);\n },\n },\n signal,\n },\n [...fields, h(\"p\", { role: \"alert\", class: \"form-error\" }, errors.form ?? \"\"), submit],\n );\n\n const { title, logo } = site();\n clear(root);\n root.append(\n h(\"section\", { class: \"auth\" }, [\n h(\"h1\", { class: logo ? \"has-logo\" : \"\" }, [logo ? h(\"img\", { src: logo, alt: \"\", class: \"brand-logo\" }) : null, title]),\n byLine(site(), \"p\"),\n h(\"div\", { class: \"auth-card\" }, [h(\"div\", { role: \"tablist\", class: \"tabs\" }, tabs), form]),\n h(\"p\", { class: \"auth-skip\" }, h(\"a\", { href: \"/\" }, \"Just looking? Read the Open Air rooms\")),\n ]),\n );\n }\n\n async function onSubmit(button: HTMLButtonElement) {\n if (busy) return;\n if (mode === \"signup\" && textLength(values.name.trim()) > LIMITS.userName) {\n render({ fields: { name: `Must be no more than ${LIMITS.userName} characters.` } });\n return;\n }\n busy = true;\n button.disabled = true;\n try {\n const user =\n mode === \"login\"\n ? await deps.api.logIn(values.email, values.password)\n : await deps.api.signUp({\n name: values.name,\n email: values.email,\n password: values.password,\n ...(site().inviteOnly ? { inviteCode: values.invite_code } : {}),\n });\n busy = false;\n button.disabled = false;\n deps.onLogin(user);\n } catch (e) {\n busy = false;\n if (!ac || ac.signal.aborted) return; // unmounted meanwhile\n if (e instanceof ApiError && e.codes.auth === SIGNUP_LOGIN_FAILED) {\n // The account exists now: signing up again would only say the email is taken.\n mode = \"login\";\n render({ form: `Your account was created, but logging in failed: ${errorMessage(e)} Log in to continue.` });\n return;\n }\n // Errors for fields on screen go next to them; anything else (network, rate limit, \u2026) above the button.\n const all = e instanceof ApiError ? e.fields : {};\n const fields = Object.fromEntries(Object.entries(all).filter(([k]) => fieldsOf(mode).some((f) => f.name === k)));\n // PocketBase says \"Value must be unique.\" (QA BUG-49).\n if (mode === \"signup\" && e instanceof ApiError && e.codes.email === \"validation_not_unique\") {\n fields.email = \"There is already an account with this email. Log in instead.\";\n }\n // A refused login is a 400 without field errors; PocketBase's \"Failed to authenticate.\" doesn't say why (QA BUG-40).\n const badLogin = mode === \"login\" && e instanceof ApiError && e.status === 400;\n // The site became invite-only after this page loaded (\u00A724): no code field on screen to put the error next to.\n const invite = e instanceof ApiError && !fields.invite_code ? all.invite_code : undefined;\n const form = Object.keys(fields).length ? \"\" : (invite ?? (badLogin ? \"Wrong email or password.\" : errorMessage(e)));\n render({ form, fields });\n }\n }\n\n return {\n mount(el) {\n root = el;\n render();\n // The site loaded (or changed) while on this page: its title, and maybe the invite code field.\n offStore =\n deps.store?.subscribe((s, prev) => {\n if (s.site !== prev.site && !busy) render();\n }) ?? (() => {});\n },\n unmount() {\n offStore();\n ac?.abort();\n ac = null;\n clear(root);\n },\n };\n}\n"],
|
|
5
|
+
"mappings": "AAuCA,IAAMA,EAAcC,IAA2D,CAC7E,MAAO,CACL,CAAE,KAAM,QAAS,MAAO,QAAS,KAAM,QAAS,aAAc,OAAQ,EACtE,CAAE,KAAM,WAAY,MAAO,WAAY,KAAM,WAAY,aAAc,kBAAmB,CAC5F,EACA,OAAQ,CAEN,CAAE,KAAM,OAAQ,MAAO,eAAgB,KAAM,OAAQ,aAAc,UAAW,EAC9E,CAAE,KAAM,QAAS,MAAO,QAAS,KAAM,QAAS,aAAc,OAAQ,EACtE,CAAE,KAAM,WAAY,MAAO,WAAY,KAAM,WAAY,aAAc,eAAgB,MAAO,CAAE,UAAWA,EAAO,WAAY,CAAE,CAClI,CACF,GAGMC,EAAoB,CAAE,KAAM,cAAe,MAAO,cAAe,KAAM,OAAQ,aAAc,KAAM,EAEnGC,EAA+B,CAAE,MAAO,SAAU,OAAQ,SAAU,EAGnE,SAASC,EAAgBC,EAMvB,CACP,GAAM,CAAE,EAAAC,EAAG,MAAAC,EAAO,SAAAC,EAAU,OAAAC,EAAQ,SAAAC,EAAU,aAAAC,EAAc,oBAAAC,EAAqB,OAAAX,EAAQ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EAAO,OAAO,KAAKN,CAAM,EAAE,OAAS,GAAMe,IAAWD,EAAW,2BAA6BlC,EAAa,CAAC,GACjHe,EAAO,CAAE,KAAAW,EAAM,OAAAN,CAAO,CAAC,CACzB,EACF,CAEA,MAAO,CACL,MAAMgB,EAAI,CACRtB,EAAOsB,EACPrB,EAAO,EAEPH,EACElB,EAAK,OAAO,UAAU,CAAC2C,EAAGC,IAAS,CAC7BD,EAAE,OAASC,EAAK,MAAQ,CAAC/B,GAAMQ,EAAO,CAC5C,CAAC,IAAM,IAAM,CAAC,EAClB,EACA,SAAU,CACRH,EAAS,EACTP,GAAI,MAAM,EACVA,EAAK,KACLT,EAAMkB,CAAI,CACZ,CACF,CACF",
|
|
6
|
+
"names": ["fieldSpecs", "LIMITS", "INVITE", "TITLES", "createLoginView", "deps", "h", "clear", "uniqueId", "byLine", "ApiError", "errorMessage", "SIGNUP_LOGIN_FAILED", "textLength", "DEFAULT_SITE", "FIELDS", "ac", "mode", "busy", "values", "site", "fieldsOf", "m", "offStore", "prefix", "root", "render", "errors", "signal", "tabs", "submit", "fields", "f", "id", "errId", "error", "e", "form", "onSubmit", "title", "logo", "button", "user", "all", "k", "badLogin", "invite", "el", "s", "prev"]
|
|
7
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
dialog.media{width:min(55rem,100%);height:min(49.25rem,100%);max-width:none;max-height:none;padding:0;border:1px solid var(--border);border-radius:16px;background:color-mix(in srgb,var(--raised),var(--bg));color:var(--fg);box-shadow:var(--shadow)}dialog.media[open]{display:flex;flex-direction:column}dialog.media::backdrop{background:#08060eb3}.media-bar{display:flex;align-items:center;gap:10px;padding:14px 16px 12px 24px;border-bottom:1px solid var(--border)}.media-bar h2{flex:1;min-width:0;margin:0;font-size:1.0625rem;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.media-bar .hash{width:auto;margin-right:1px}.media-bar .icon-button{width:36px;height:36px;color:var(--muted)}.media-body{flex:1;overflow-y:auto;padding:0 24px 20px}.media-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(8rem,1fr));gap:6px}.media-grid h3{grid-column:1 / -1;margin:16px 0 4px;font-size:.8125rem;font-weight:600;color:var(--muted)}.media-tile{position:relative;display:block;width:100%;aspect-ratio:1;padding:0;border:0;border-radius:6px;overflow:hidden;background:var(--surface);cursor:pointer}.media-tile img{display:block;width:100%;height:100%;object-fit:cover}.media-tile:hover{opacity:.85}.media-
|
|
2
|
-
/*# sourceMappingURL=media-
|
|
1
|
+
dialog.media{width:min(55rem,100%);height:min(49.25rem,100%);max-width:none;max-height:none;padding:0;border:1px solid var(--border);border-radius:16px;background:color-mix(in srgb,var(--raised),var(--bg));color:var(--fg);box-shadow:var(--shadow)}dialog.media[open]{display:flex;flex-direction:column}dialog.media::backdrop{background:#08060eb3}.media-bar{display:flex;align-items:center;gap:10px;padding:14px 16px 12px 24px;border-bottom:1px solid var(--border)}.media-bar h2{flex:1;min-width:0;margin:0;font-size:1.0625rem;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.media-bar .hash{width:auto;margin-right:1px}.media-bar .icon-button{width:36px;height:36px;color:var(--muted)}.media-body{flex:1;overflow-y:auto;padding:0 24px 20px}.media-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(8rem,1fr));gap:6px}.media-grid h3{grid-column:1 / -1;margin:16px 0 4px;font-size:.8125rem;font-weight:600;color:var(--muted)}.media-tile{position:relative;display:block;width:100%;aspect-ratio:1;padding:0;border:0;border-radius:6px;overflow:hidden;background:var(--surface);cursor:pointer}.media-tile img{display:block;width:100%;height:100%;object-fit:cover}.media-tile:hover{opacity:.85}.media-status{margin:1rem 0 0;text-align:center;color:var(--muted);font-size:.9rem}@media(max-width:40rem){dialog.media{width:100%;height:100%;border:0;border-radius:0}.media-bar{padding-top:max(.5rem,env(safe-area-inset-top))}}
|
|
2
|
+
/*# sourceMappingURL=media-7TCBG7WM.css.map */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../web/styles/media.css"],
|
|
4
|
-
"sourcesContent": ["/* Media grid (DESIGN.md \u00A730). Not part of app.css: the grid links this file when it first opens.\n Uses app.css's custom properties, so it follows the theme. */\n\ndialog.media {\n width: min(55rem, 100%);\n height: min(49.25rem, 100%);\n max-width: none;\n max-height: none;\n padding: 0;\n border: 1px solid var(--border);\n border-radius: 16px;\n background: color-mix(in srgb, var(--raised), var(--bg));\n color: var(--fg);\n box-shadow: var(--shadow);\n}\n\ndialog.media[open] {\n display: flex;\n flex-direction: column;\n}\n\ndialog.media::backdrop {\n background: rgb(8 6 14 / 70%);\n}\n\n.media-bar {\n display: flex;\n align-items: center;\n gap: 10px;\n padding: 14px 16px 12px 24px;\n border-bottom: 1px solid var(--border);\n}\n\n.media-bar h2 {\n flex: 1;\n min-width: 0;\n margin: 0;\n font-size: 1.0625rem;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n\n.media-bar .hash {\n width: auto;\n margin-right: 1px;\n}\n\n.media-bar .icon-button {\n width: 36px;\n height: 36px;\n color: var(--muted);\n}\n\n.media-body {\n flex: 1;\n overflow-y: auto;\n padding: 0 24px 20px;\n}\n\n.media-grid {\n display: grid;\n grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr));\n gap: 6px;\n}\n\n.media-grid h3 {\n grid-column: 1 / -1;\n margin: 16px 0 4px;\n font-size: 0.8125rem;\n font-weight: 600;\n color: var(--muted);\n}\n\n.media-tile {\n position: relative;\n display: block;\n width: 100%;\n aspect-ratio: 1;\n padding: 0;\n border: 0;\n border-radius: 6px;\n overflow: hidden;\n background: var(--surface);\n cursor: pointer;\n}\n\n.media-tile img {\n display: block;\n width: 100%;\n height: 100%;\n object-fit: cover;\n}\n\n.media-tile:hover {\n opacity: 0.85;\n}\n\n.media-
|
|
5
|
-
"mappings": "AAGA,MAAM,CAAC,MACL,MAAO,IAAI,KAAK,CAAE,MAClB,OAAQ,IAAI,QAAQ,CAAE,MACtB,UAAW,KACX,WAAY,KAPd,QAQW,EACT,OAAQ,IAAI,MAAM,IAAI,UATxB,cAUiB,KACf,WAAY,UAAU,GAAG,IAAI,CAAE,IAAI,SAAS,CAAE,IAAI,OAClD,MAAO,IAAI,MACX,WAAY,IAAI,SAClB,CAEA,MAAM,CAbC,KAaK,CAAC,MACX,QAAS,KACT,eAAgB,MAClB,CAEA,MAAM,CAlBC,KAkBK,WACV,WAAY,SACd,CAEA,CAAC,UACC,QAAS,KACT,YAAa,OACb,IAAK,KA5BP,QA6BW,KAAK,KAAK,KAAK,KACxB,cAAe,IAAI,MAAM,IAAI,SAC/B,CAEA,CARC,UAQU,GACT,KAAM,EACN,UAAW,EAnCb,OAoCU,EACR,UAAW,UACX,SAAU,OACV,cAAe,SACf,YAAa,MACf,CAEA,CAlBC,UAkBU,CAAC,KACV,MAAO,KACP,aAAc,GAChB,CAEA,CAvBC,UAuBU,CAAC,YACV,MAAO,KACP,OAAQ,KACR,MAAO,IAAI,QACb,CAEA,CAAC,WACC,KAAM,EACN,WAAY,KAxDd,QAyDW,EAAE,KAAK,IAClB,CAEA,CAAC,WACC,QAAS,KACT,sBAAuB,OAAO,SAAS,CAAE,OAAO,IAAI,CAAE,MACtD,IAAK,GACP,CAEA,CANC,WAMW,GACV,YAAa,EAAE,EAAE,GAnEnB,OAoEU,KAAK,EAAE,IACf,UAAW,SACX,YAAa,IACb,MAAO,IAAI,QACb,CAEA,CAAC,WACC,SAAU,SACV,QAAS,MACT,MAAO,KACP,aAAc,EA9EhB,QA+EW,EACT,OAAQ,EAhFV,cAiFiB,IACf,SAAU,OACV,WAAY,IAAI,WAChB,OAAQ,OACV,CAEA,CAbC,WAaW,IACV,QAAS,MACT,MAAO,KACP,OAAQ,KACR,WAAY,KACd,CAEA,CApBC,UAoBU,OACT,QAAS,GACX,CAEA,
|
|
4
|
+
"sourcesContent": ["/* Media grid (DESIGN.md \u00A730). Not part of app.css: the grid links this file when it first opens.\n Uses app.css's custom properties, so it follows the theme. */\n\ndialog.media {\n width: min(55rem, 100%);\n height: min(49.25rem, 100%);\n max-width: none;\n max-height: none;\n padding: 0;\n border: 1px solid var(--border);\n border-radius: 16px;\n background: color-mix(in srgb, var(--raised), var(--bg));\n color: var(--fg);\n box-shadow: var(--shadow);\n}\n\ndialog.media[open] {\n display: flex;\n flex-direction: column;\n}\n\ndialog.media::backdrop {\n background: rgb(8 6 14 / 70%);\n}\n\n.media-bar {\n display: flex;\n align-items: center;\n gap: 10px;\n padding: 14px 16px 12px 24px;\n border-bottom: 1px solid var(--border);\n}\n\n.media-bar h2 {\n flex: 1;\n min-width: 0;\n margin: 0;\n font-size: 1.0625rem;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n\n.media-bar .hash {\n width: auto;\n margin-right: 1px;\n}\n\n.media-bar .icon-button {\n width: 36px;\n height: 36px;\n color: var(--muted);\n}\n\n.media-body {\n flex: 1;\n overflow-y: auto;\n padding: 0 24px 20px;\n}\n\n.media-grid {\n display: grid;\n grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr));\n gap: 6px;\n}\n\n.media-grid h3 {\n grid-column: 1 / -1;\n margin: 16px 0 4px;\n font-size: 0.8125rem;\n font-weight: 600;\n color: var(--muted);\n}\n\n.media-tile {\n position: relative;\n display: block;\n width: 100%;\n aspect-ratio: 1;\n padding: 0;\n border: 0;\n border-radius: 6px;\n overflow: hidden;\n background: var(--surface);\n cursor: pointer;\n}\n\n.media-tile img {\n display: block;\n width: 100%;\n height: 100%;\n object-fit: cover;\n}\n\n.media-tile:hover {\n opacity: 0.85;\n}\n\n.media-status {\n margin: 1rem 0 0;\n text-align: center;\n color: var(--muted);\n font-size: 0.9rem;\n}\n\n@media (max-width: 40rem) {\n dialog.media {\n width: 100%;\n height: 100%;\n border: 0;\n border-radius: 0;\n }\n .media-bar {\n padding-top: max(0.5rem, env(safe-area-inset-top));\n }\n}\n"],
|
|
5
|
+
"mappings": "AAGA,MAAM,CAAC,MACL,MAAO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,OACZ,MAAO,IAAI,SACX,UAAW,KACb,CAEA,OAAO,UAAY,OACjB,MAAM,CAvGD,MAwGH,MAAO,KACP,OAAQ,KACR,OAAQ,EA7GZ,cA8GmB,CACjB,CACA,CAvFD,UAwFG,YAAa,IAAI,KAAM,CAAE,IAAI,qBAC/B,CACF",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var x=null;function q(a){return x??=new Promise(n=>{let b=a("link",{rel:"stylesheet",href:"/assets/media-7TCBG7WM.css",on:{load:()=>n(),error:()=>{b.remove(),x=null,n()}}});document.head.append(b)}),x}var $=`media-${Date.now()}-${Math.random()}`,w=()=>history.state?.media===$,H=null,k=!1;function B(a){if(k)return;k=!0;let{h:n,api:v}=a,b=document.activeElement,I=new AbortController,{signal:r}=I;a.signal.addEventListener("abort",()=>g(!1),{signal:r});let S=n("h2",{id:"media-title"},a.label?["Media in ",n("span",{class:"hash"},"#"),a.label]:"Media"),M=n("div",{class:"media-grid"}),l=n("p",{class:"media-status",role:"status"}),L=n("div",{class:"media-body"},[M,l]),d=n("dialog",{class:"media","aria-labelledby":S.id},[n("header",{class:"media-bar"},[S,n("button",{type:"button",class:"icon-button ic i-x","aria-label":"Close",autofocus:!0,on:{click:()=>g(!0)},signal:r})]),L]),c=[],f,C=new Map,u=!1,E=!1,O="",m=!1,N=new Intl.DateTimeFormat(void 0,{month:"long",year:"numeric"});async function P(){if(!(E||u||m)){E=!0,l.textContent="Loading\u2026";try{let e=await v.media(a.room,f&&{sent:f.sent,message:f.message,pos:f.pos},r);if(m)return;u=!e.more,f=e.items.at(-1)??f;for(let t of e.items)R(t);l.textContent=u?c.length?"":"No photos or videos here yet.":""}catch{if(m)return;p.unobserve(l),l.replaceChildren("Couldn't load media. ",n("button",{type:"button",class:"link",on:{click:()=>{P()}},signal:r},"Retry"));return}finally{E=!1}p.unobserve(l),!u&&!m&&p.observe(l)}}function V(e){let t=C.get(e.message);if(!t){let{message:i,sent:o,author:s}=e;t={id:i,room:a.room,author:s?.id??"",text:"",created:o,updated:o,edited_at:"",deleted:!1},t.files=[],t.file_names={},e.source!==i&&(t.forward_of=e.source),s&&(t.expand={author:s}),C.set(i,t)}return t.files.unshift(e.file),e.name&&(t.file_names[e.file]=e.name),t}function R(e){let{file:t,video:i}=e,o=V(e),s=new Date(o.created.replace(" ","T")),h=N.format(s);h!==O&&(O=h,M.append(n("h3",{},h)));let Y=a.name(o,t),j=()=>i?v.posterUrl(o,t):v.fileUrl(o,t,"240x240"),y=(!i||e.poster)&&n("img",{src:j(),alt:"",loading:"lazy",decoding:"async"});y&&i&&y.addEventListener("error",()=>y.remove(),{signal:r});let _=`${Y}${i?", video":""}, ${o.expand?.author?.name??"Unknown"}, ${s.toLocaleDateString()}`,A=n("button",{type:"button",class:"media-tile","aria-label":_,title:_,on:{click:()=>z(D)},signal:r},[y,i&&n("span",{class:"att-play","aria-hidden":"true"})]),D={message:o,file:t,video:i,tile:A};c.push(D),M.append(A)}function z({message:e,file:t,tile:i}){let o=c.map(({tile:s,...h})=>h).reverse();a.open(e,t,i,o,[!u,!1],()=>g(!0,!1))}a.follow((e,t)=>{let i=new Set(t||e.deleted?[]:e.files??[]);for(let o of c.filter(s=>s.message.id===e.id&&!i.has(s.file))){c.splice(c.indexOf(o),1);let s=o.tile.previousElementSibling;o.tile.remove(),s?.tagName==="H3"&&(!s.nextElementSibling||s.nextElementSibling.tagName==="H3")&&s.remove()}u&&!c.length&&(l.textContent="No photos or videos here yet.")});let p=new IntersectionObserver(e=>e.some(t=>t.isIntersecting)&&void P(),{root:L,rootMargin:"400px"});function g(e,t=!0){m||(m=!0,k=!1,I.abort(),p.disconnect(),a.follow(void 0),d.open&&d.close(),e?H=F().finally(()=>d.remove()):d.remove(),t&&b?.focus())}let T=()=>new Promise(e=>window.addEventListener("popstate",e,{once:!0})),U=()=>!!history.state?.viewer;async function F(){if(!w()&&U()&&await T(),!w())return;let e=T();history.back(),await e}d.addEventListener("close",()=>g(!0),{signal:r}),(async()=>(await Promise.all([q(n),H]),!m&&(w()||history.pushState({media:$},""),window.addEventListener("popstate",()=>!w()&&!U()&&g(!1),{signal:r}),document.body.append(d),d.showModal(),p.observe(l))))()}export{B as openMedia};
|
|
2
|
+
//# sourceMappingURL=media-FPRU2QH5.js.map
|