moi-computer 0.13.0 → 0.13.1-next.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/client/api/query-client.ts +5 -0
- package/client/app/app-router.tsx +1 -1
- package/client/app/routes/workspace-route.tsx +2 -0
- package/client/features/account/account-provider.tsx +28 -77
- package/client/features/account/account-test-utils.tsx +95 -93
- package/client/features/account/api.ts +32 -109
- package/client/features/account/profile-actions.ts +31 -0
- package/client/features/app-settings/settings-page.tsx +0 -4
- package/client/features/collab/client.ts +38 -13
- package/client/features/collab/hooks.tsx +9 -8
- package/client/features/collab/host-state.ts +45 -85
- package/client/features/collab/testing/fake-engine.ts +13 -1
- package/client/features/collab/users.ts +0 -12
- package/client/features/dev/cloud-avatar-upload.tsx +58 -0
- package/client/features/dev/cloud-page.tsx +363 -0
- package/client/features/dev/dev-index-page.tsx +6 -0
- package/client/features/dev/dev-routes.tsx +2 -0
- package/client/features/identity/host-api.ts +34 -0
- package/client/features/identity/store.ts +32 -0
- package/client/features/identity/types.ts +41 -0
- package/client/features/identity/use-identity.ts +6 -0
- package/client/features/workspace-members/api.ts +20 -0
- package/client/features/workspace-members/hooks.ts +127 -0
- package/client/features/workspace-members/keys.ts +6 -0
- package/client/features/workspace-members/store.ts +123 -0
- package/client/features/workspace-members/types.ts +53 -0
- package/client/index.html +1 -1
- package/client/index.tsx +5 -9
- package/client/main.tsx +2 -2
- package/dist/{chunk-cqt3s31j.js → chunk-00s35r33.js} +68 -68
- package/dist/{chunk-bncc7heg.js → chunk-7rz6g7g7.js} +1 -1
- package/dist/chunk-af2jyddf.js +2 -0
- package/dist/chunk-cekekc3f.css +1 -0
- package/dist/chunk-ep5vh16c.js +75 -0
- package/dist/{chunk-2y59vrxg.js → chunk-kdgk4dac.js} +1 -1
- package/dist/chunk-s5s1vzdw.js +2 -0
- package/dist/{chunk-58dyt9bk.js → chunk-svxhxfeq.js} +2 -2
- package/dist/chunk-t0r0bds1.js +1 -0
- package/dist/chunk-vp2qzc0d.js +1 -0
- package/dist/{chunk-q37knr3m.js → chunk-wz5qv1bn.js} +2 -2
- package/dist/index.html +2 -2
- package/package.json +5 -4
- package/server/app-config.ts +3 -1
- package/client/features/account/identity.ts +0 -23
- package/client/features/app-settings/users-settings.tsx +0 -195
- package/dist/chunk-dcmks9sm.js +0 -75
- package/dist/chunk-md45evr2.css +0 -1
- package/dist/chunk-n0nab26d.js +0 -1
- package/dist/chunk-nmzhgyp9.js +0 -2
- package/dist/chunk-s90m4qkz.js +0 -1
- package/dist/chunk-wjvd4byz.js +0 -2
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
* SVG/attribute allowlists and URI sanitization approach derived from DOMPurify.
|
|
3
3
|
* DOMPurify — MIT License, Copyright (c) 2015 Mario Heiderich
|
|
4
4
|
* https://github.com/cure53/DOMPurify/blob/main/LICENSE
|
|
5
|
-
*/var v=new Set(["svg","a","altglyph","altglyphdef","altglyphitem","animate","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","feblend","fecolormatrix","fecomponenttransfer","fecomposite","feconvolvematrix","fediffuselighting","fedisplacementmap","fedistantlight","fedropshadow","feflood","fefunca","fefuncb","fefuncg","fefuncr","fegaussianblur","feimage","femerge","femergenode","femorphology","feoffset","fepointlight","fespecularlighting","fespotlight","fetile","feturbulence","filter","font","foreignobject","g","glyph","glyphref","hkern","image","line","lineargradient","marker","mask","metadata","mpath","path","pattern","polygon","polyline","radialgradient","rect","set","stop","style","switch","symbol","text","textpath","title","tref","tspan","use","view","vkern"]),y=new Set(["a","b","blockquote","body","br","code","del","div","em","h1","h2","h3","h4","h5","h6","i","li","mark","ol","p","pre","span","strong","s","sub","sup","table","tbody","td","th","thead","tr","u","ul"]),A=new Set(["script","iframe","object","embed","form","input","textarea","select","button","link","meta","base","img","video","audio","source","picture","svg"]),x=new Set(["accent-height","accumulate","additive","alignment-baseline","amplitude","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clip-path","clip-rule","clippathunits","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","diffuseconstant","direction","display","divisor","dominant-baseline","dur","dx","dy","edgemode","elevation","end","exponent","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","from","fx","fy","g1","g2","glyph-name","glyphref","gradienttransform","gradientunits","height","href","id","image-rendering","in","in2","intercept","k","k1","k2","k3","k4","kerning","kernelmatrix","kernelunitlength","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","mask","mask-type","maskcontentunits","maskunits","max","media","method","min","mode","name","numoctaves","offset","opacity","operator","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","pointer-events","points","preservealpha","preserveaspectratio","primitiveunits","r","radius","refx","refy","repeatcount","repeatdur","requiredfeatures","restart","result","role","rotate","rx","ry","scale","seed","shape-rendering","slope","specularconstant","specularexponent","spreadmethod","startoffset","stddeviation","stitchtiles","stop-color","stop-opacity","stroke","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","style","surfacescale","systemlanguage","tabindex","tablevalues","targetx","targety","text-anchor","text-decoration","text-rendering","textlength","to","transform","transform-origin","type","u1","u2","unicode","values","version","vert-adv-y","vert-origin-x","vert-origin-y","viewbox","visibility","width","word-spacing","wrap","writing-mode","x","x1","x2","xchannelselector","xlink:href","xml:id","xml:space","xlink:title","xmlns","xmlns:xlink","y","y1","y2","z","zoomandpan"]),k=new Set(["class","dir","href","id","lang","role","style","tabindex","title"]),d=/^data-/,p=/^aria-/,o=/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g,g=/^(?:https?:|mailto:)/i,S=/^data:/i,T=/^data:image\/(?:png|jpeg|jpg|gif|webp|avif|bmp|tiff|x-icon|vnd\.microsoft\.icon)[;,]/i,_=/^data:image\/svg\+xml[;,]/i,u=/^#/;function w(t){return t.replace(/\\([0-9a-fA-F]{1,6})\s?|\\([^\n])/g,(i,r,n)=>{if(r){let e=parseInt(r,16);if(e>1114111||e===0)return"�";return String.fromCodePoint(e)}return n})}var E=/^data:(?:image\/(?:png|jpeg|jpg|gif|webp|avif)|font\/(?:woff2?|opentype|truetype|sfnt)|application\/(?:x-font-woff|font-woff2?|x-font-ttf|x-font-opentype|font-sfnt))[;,]/i;function f(t){let i=w(t);return i=i.replace(/@import\s+(?:url\s*\([^)]*\)|"[^"]*"|'[^']*')[^;]*;?|@import\b[^;]*;?/gi,""),i=i.replace(/expression\s*\([^)]*\)/gi,""),i=i.replace(/-moz-binding\s*:[^;]*/gi,""),i=i.replace(/behavior\s*:[^;]*/gi,""),i=i.replace(/url\s*\(\s*(['"]?)(.*?)\1\s*\)/gis,(r,n,e)=>{let a=e.replace(o,"");if(E.test(a)||u.test(a))return r;return""}),i}function L(t){return f(t)}var N=new Set(["animate","set","animatecolor","animatetransform"]),R=/^(?:href|xlink:href|on)/i;function z(t){let i=t.getAttribute("attributeName");if(!i)return!1;return R.test(i.replace(o,""))}var h=/^on/i,D=new Set(["clip-path","cursor","fill","filter","marker-end","marker-mid","marker-start","mask","stroke"]),m=10;function I(t){let i=t.search(/;base64,/i);if(i>=0){let n=t.slice(i+8),e=Uint8Array.from(atob(n),(a)=>a.charCodeAt(0));return new TextDecoder().decode(e)}let r=t.indexOf(",");if(r<0)return null;return decodeURIComponent(t.slice(r+1))}function C(t){let i=new TextEncoder().encode(t),r=Array.from(i,(n)=>String.fromCharCode(n)).join("");return"data:image/svg+xml;base64,"+btoa(r)}function G(t,i){if(i>=m)return console.warn(`Embedded SVG data URI recursion depth limit (${m}) reached`),null;let r;try{let e=I(t);if(e===null)return null;r=e}catch{return null}let n=b(r,i+1);if(!n)return null;return C(n)}function O(t,i,r,n){let e=r.replace(o,""),a=t.tagName.toLowerCase();if(a==="image"||a==="feimage"){if(T.test(e))return r;if(_.test(e))return G(e,n);return null}if(a==="use"){if(u.test(e))return r;return null}if(a==="a"){if(g.test(e))return r;return null}if(S.test(e)||u.test(e))return r;return null}function l(t,i){for(let r=t.attributes.length-1;r>=0;r--){let n=t.attributes[r],e=n.name.toLowerCase(),a=e.replace(o,"");if(h.test(a)){t.removeAttribute(n.name);continue}if(d.test(e)||p.test(e))continue;if(!x.has(e)){t.removeAttribute(n.name);continue}if(e==="href"||e==="xlink:href"){let s=O(t,e,n.value,i);if(s===null)t.removeAttribute(n.name);else if(s!==n.value)n.value=s;continue}if(e==="style"){n.value=f(n.value);continue}if(D.has(e)&&/url\s*\(/i.test(n.value))n.value=f(n.value)}}function M(t){let i=t.tagName.toLowerCase();for(let r=t.attributes.length-1;r>=0;r--){let n=t.attributes[r],e=n.name.toLowerCase(),a=e.replace(o,"");if(h.test(a)){t.removeAttribute(n.name);continue}if(d.test(e)||p.test(e))continue;if(!k.has(e)){t.removeAttribute(n.name);continue}if(e==="href"){if(i!=="a"){t.removeAttribute(n.name);continue}let s=n.value.replace(o,"");if(!g.test(s))t.removeAttribute(n.name);continue}if(e==="style")n.value=f(n.value)}}function c(t,i,r){for(let n=t.children.length-1;n>=0;n--){let e=t.children[n],a=e.tagName.toLowerCase();if(i==="svg")if(a==="foreignobject")l(e,r),c(e,"html",r);else if(a==="style"){if(l(e,r),e.textContent)e.textContent=L(e.textContent)}else if(N.has(a)&&z(e))e.remove();else if(v.has(a))l(e,r),c(e,"svg",r);else e.remove();else if(A.has(a))e.remove();else if(y.has(a))M(e),c(e,"html",r);else e.remove()}}function b(t,i){let r=new DOMParser().parseFromString(t,"image/svg+xml");if(r.querySelector("parsererror"))return"";let e=r.documentElement;if(e.tagName.toLowerCase()!=="svg")return"";if(l(e,i),c(e,"svg",i),e.children.length===0)return"";return new XMLSerializer().serializeToString(e)}function
|
|
5
|
+
*/var v=new Set(["svg","a","altglyph","altglyphdef","altglyphitem","animate","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","feblend","fecolormatrix","fecomponenttransfer","fecomposite","feconvolvematrix","fediffuselighting","fedisplacementmap","fedistantlight","fedropshadow","feflood","fefunca","fefuncb","fefuncg","fefuncr","fegaussianblur","feimage","femerge","femergenode","femorphology","feoffset","fepointlight","fespecularlighting","fespotlight","fetile","feturbulence","filter","font","foreignobject","g","glyph","glyphref","hkern","image","line","lineargradient","marker","mask","metadata","mpath","path","pattern","polygon","polyline","radialgradient","rect","set","stop","style","switch","symbol","text","textpath","title","tref","tspan","use","view","vkern"]),y=new Set(["a","b","blockquote","body","br","code","del","div","em","h1","h2","h3","h4","h5","h6","i","li","mark","ol","p","pre","span","strong","s","sub","sup","table","tbody","td","th","thead","tr","u","ul"]),A=new Set(["script","iframe","object","embed","form","input","textarea","select","button","link","meta","base","img","video","audio","source","picture","svg"]),x=new Set(["accent-height","accumulate","additive","alignment-baseline","amplitude","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clip-path","clip-rule","clippathunits","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","diffuseconstant","direction","display","divisor","dominant-baseline","dur","dx","dy","edgemode","elevation","end","exponent","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","from","fx","fy","g1","g2","glyph-name","glyphref","gradienttransform","gradientunits","height","href","id","image-rendering","in","in2","intercept","k","k1","k2","k3","k4","kerning","kernelmatrix","kernelunitlength","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","mask","mask-type","maskcontentunits","maskunits","max","media","method","min","mode","name","numoctaves","offset","opacity","operator","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","pointer-events","points","preservealpha","preserveaspectratio","primitiveunits","r","radius","refx","refy","repeatcount","repeatdur","requiredfeatures","restart","result","role","rotate","rx","ry","scale","seed","shape-rendering","slope","specularconstant","specularexponent","spreadmethod","startoffset","stddeviation","stitchtiles","stop-color","stop-opacity","stroke","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","style","surfacescale","systemlanguage","tabindex","tablevalues","targetx","targety","text-anchor","text-decoration","text-rendering","textlength","to","transform","transform-origin","type","u1","u2","unicode","values","version","vert-adv-y","vert-origin-x","vert-origin-y","viewbox","visibility","width","word-spacing","wrap","writing-mode","x","x1","x2","xchannelselector","xlink:href","xml:id","xml:space","xlink:title","xmlns","xmlns:xlink","y","y1","y2","z","zoomandpan"]),k=new Set(["class","dir","href","id","lang","role","style","tabindex","title"]),d=/^data-/,p=/^aria-/,o=/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g,g=/^(?:https?:|mailto:)/i,S=/^data:/i,T=/^data:image\/(?:png|jpeg|jpg|gif|webp|avif|bmp|tiff|x-icon|vnd\.microsoft\.icon)[;,]/i,_=/^data:image\/svg\+xml[;,]/i,u=/^#/;function w(t){return t.replace(/\\([0-9a-fA-F]{1,6})\s?|\\([^\n])/g,(i,r,n)=>{if(r){let e=parseInt(r,16);if(e>1114111||e===0)return"�";return String.fromCodePoint(e)}return n})}var E=/^data:(?:image\/(?:png|jpeg|jpg|gif|webp|avif)|font\/(?:woff2?|opentype|truetype|sfnt)|application\/(?:x-font-woff|font-woff2?|x-font-ttf|x-font-opentype|font-sfnt))[;,]/i;function f(t){let i=w(t);return i=i.replace(/@import\s+(?:url\s*\([^)]*\)|"[^"]*"|'[^']*')[^;]*;?|@import\b[^;]*;?/gi,""),i=i.replace(/expression\s*\([^)]*\)/gi,""),i=i.replace(/-moz-binding\s*:[^;]*/gi,""),i=i.replace(/behavior\s*:[^;]*/gi,""),i=i.replace(/url\s*\(\s*(['"]?)(.*?)\1\s*\)/gis,(r,n,e)=>{let a=e.replace(o,"");if(E.test(a)||u.test(a))return r;return""}),i}function L(t){return f(t)}var N=new Set(["animate","set","animatecolor","animatetransform"]),R=/^(?:href|xlink:href|on)/i;function z(t){let i=t.getAttribute("attributeName");if(!i)return!1;return R.test(i.replace(o,""))}var h=/^on/i,D=new Set(["clip-path","cursor","fill","filter","marker-end","marker-mid","marker-start","mask","stroke"]),m=10;function I(t){let i=t.search(/;base64,/i);if(i>=0){let n=t.slice(i+8),e=Uint8Array.from(atob(n),(a)=>a.charCodeAt(0));return new TextDecoder().decode(e)}let r=t.indexOf(",");if(r<0)return null;return decodeURIComponent(t.slice(r+1))}function C(t){let i=new TextEncoder().encode(t),r=Array.from(i,(n)=>String.fromCharCode(n)).join("");return"data:image/svg+xml;base64,"+btoa(r)}function G(t,i){if(i>=m)return console.warn(`Embedded SVG data URI recursion depth limit (${m}) reached`),null;let r;try{let e=I(t);if(e===null)return null;r=e}catch{return null}let n=b(r,i+1);if(!n)return null;return C(n)}function O(t,i,r,n){let e=r.replace(o,""),a=t.tagName.toLowerCase();if(a==="image"||a==="feimage"){if(T.test(e))return r;if(_.test(e))return G(e,n);return null}if(a==="use"){if(u.test(e))return r;return null}if(a==="a"){if(g.test(e))return r;return null}if(S.test(e)||u.test(e))return r;return null}function l(t,i){for(let r=t.attributes.length-1;r>=0;r--){let n=t.attributes[r],e=n.name.toLowerCase(),a=e.replace(o,"");if(h.test(a)){t.removeAttribute(n.name);continue}if(d.test(e)||p.test(e))continue;if(!x.has(e)){t.removeAttribute(n.name);continue}if(e==="href"||e==="xlink:href"){let s=O(t,e,n.value,i);if(s===null)t.removeAttribute(n.name);else if(s!==n.value)n.value=s;continue}if(e==="style"){n.value=f(n.value);continue}if(D.has(e)&&/url\s*\(/i.test(n.value))n.value=f(n.value)}}function M(t){let i=t.tagName.toLowerCase();for(let r=t.attributes.length-1;r>=0;r--){let n=t.attributes[r],e=n.name.toLowerCase(),a=e.replace(o,"");if(h.test(a)){t.removeAttribute(n.name);continue}if(d.test(e)||p.test(e))continue;if(!k.has(e)){t.removeAttribute(n.name);continue}if(e==="href"){if(i!=="a"){t.removeAttribute(n.name);continue}let s=n.value.replace(o,"");if(!g.test(s))t.removeAttribute(n.name);continue}if(e==="style")n.value=f(n.value)}}function c(t,i,r){for(let n=t.children.length-1;n>=0;n--){let e=t.children[n],a=e.tagName.toLowerCase();if(i==="svg")if(a==="foreignobject")l(e,r),c(e,"html",r);else if(a==="style"){if(l(e,r),e.textContent)e.textContent=L(e.textContent)}else if(N.has(a)&&z(e))e.remove();else if(v.has(a))l(e,r),c(e,"svg",r);else e.remove();else if(A.has(a))e.remove();else if(y.has(a))M(e),c(e,"html",r);else e.remove()}}function b(t,i){let r=new DOMParser().parseFromString(t,"image/svg+xml");if(r.querySelector("parsererror"))return"";let e=r.documentElement;if(e.tagName.toLowerCase()!=="svg")return"";if(l(e,i),c(e,"svg",i),e.children.length===0)return"";return new XMLSerializer().serializeToString(e)}function gt(t){return b(t,0)}export{gt};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var na=Object.create;var{getPrototypeOf:sa,defineProperty:sr,getOwnPropertyNames:ca}=Object;var xr=Object.prototype.hasOwnProperty;function la(r){return this[r]}var da,pa,e=(r,a,t)=>{var o=r!=null&&typeof r==="object";if(o){var i=a?da??=new WeakMap:pa??=new WeakMap,c=i.get(r);if(c)return c}t=r!=null?na(sa(r)):{};let n=a||!r||!r.__esModule||!xr.call(r,"default")?sr(t,"default",{value:r,enumerable:!0}):t;if(r&&typeof r==="object"||typeof r==="function"){for(let s of ca(r))if(!xr.call(n,s))sr(n,s,{get:la.bind(r,s),enumerable:!0})}if(o)i.set(r,n);return n};var x=(r,a)=>()=>(a||r((a={exports:{}}).exports,a),a.exports);var ha=(r)=>r;function ga(r,a){this[r]=ha.bind(null,a)}var be=(r,a)=>{for(var t in a)sr(r,t,{get:a[t],enumerable:!0,configurable:!0,set:ga.bind(a,t)})};var st=((r)=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(a,t)=>(typeof require<"u"?require:a)[t]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var yr,cr,L,Y=(r,a)=>{for(var[t,o,i]of yr||[])for(var c=[r],n=globalThis,s=n.document,l,d,h,p,g;d=c.pop();)if(!cr[d]&&(h=o[d])){cr[d]=1;for(p=1;p<h.length;p++)c.push(i[h[p]]);if(!a&&d!==r&&(l=s&&s.head)){if(L===void 0)L=(p=s.querySelector("meta[property=csp-nonce]"))&&(p.nonce||p.getAttribute("nonce"))||"";if(g=s.createElement("link"),g.rel="modulepreload",g.crossOrigin="",L)g.nonce=L;g.href=new n.URL(h[0],t),l.appendChild(g)}}},ua=(r,a,t,o)=>{for(var i={},c=0;c<a.length;c++)i[a[c]]=t[c];(yr||=[]).push([r,i,a]),cr||={},Y(a[o],1)};ua(import.meta.url,["s5s1vzdw","ep5vh16c","vp2qzc0d","7rz6g7g7","nf2wkvf9","00s35r33","af2jyddf","wz5qv1bn","svxhxfeq","t0r0bds1","kdgk4dac"],[["/chunk-s5s1vzdw.js"],["/chunk-ep5vh16c.js",6,0,7,8],["/chunk-vp2qzc0d.js",7],["/chunk-7rz6g7g7.js",0,8],["/chunk-nf2wkvf9.js"],["/chunk-00s35r33.js",10,6,0,7],["/chunk-af2jyddf.js",0,7],["/chunk-wz5qv1bn.js",0,8],["/chunk-svxhxfeq.js"],["/chunk-t0r0bds1.js",10],["/chunk-kdgk4dac.js"]],0);
|
|
2
|
+
if(typeof globalThis.structuredClone==="function")globalThis.structuredClone=globalThis.structuredClone.bind(globalThis);var va={setTimeout:(r,a)=>setTimeout(r,a),clearTimeout:(r)=>clearTimeout(r),setInterval:(r,a)=>setInterval(r,a),clearInterval:(r)=>clearInterval(r)},wa=class{#r=va;#a=!1;setTimeoutProvider(r){this.#r=r}setTimeout(r,a){return this.#r.setTimeout(r,a)}clearTimeout(r){this.#r.clearTimeout(r)}setInterval(r,a){return this.#r.setInterval(r,a)}clearInterval(r){this.#r.clearInterval(r)}},Z=new wa;function kr(r){setTimeout(r,0)}var dr=typeof window>"u"||"Deno"in globalThis;function A(){}function Cr(r,a){return typeof r==="function"?r(a):r}function Be(r){return typeof r==="number"&&r>=0&&r!==1/0}function ze(r,a){return Math.max(r+(a||0)-Date.now(),0)}function T(r,a){return typeof r==="function"?r(a):r}function ve(r,a){let{type:t="all",exact:o,fetchStatus:i,predicate:c,queryKey:n,stale:s}=r;if(n){if(o){if(a.queryHash!==D(n,a.options))return!1}else if(!z(a.queryKey,n))return!1}if(t!=="all"){let l=a.isActive();if(t==="active"&&!l)return!1;if(t==="inactive"&&l)return!1}if(typeof s==="boolean"&&a.isStale()!==s)return!1;if(i&&i!==a.state.fetchStatus)return!1;if(c&&!c(a))return!1;return!0}function K(r,a){let{exact:t,status:o,predicate:i,mutationKey:c}=r;if(c){if(!a.options.mutationKey)return!1;if(t){if(J(a.options.mutationKey)!==J(c))return!1}else if(!z(a.options.mutationKey,c))return!1}if(o&&a.state.status!==o)return!1;if(i&&!i(a))return!1;return!0}function D(r,a){return(a?.queryKeyHashFn||J)(r)}function J(r){return JSON.stringify(r,(a,t)=>lr(t)?Object.keys(t).sort().reduce((o,i)=>(o[i]=t[i],o),{}):t)}function z(r,a){if(r===a)return!0;if(typeof r!==typeof a)return!1;if(r&&a&&typeof r==="object"&&typeof a==="object"){if(Array.isArray(r)&&Array.isArray(a)){for(let o=0;o<a.length;o++)if(!z(r[o],a[o]))return!1;return!0}let t=Object.keys(a);for(let o of t)if(!z(r[o],a[o]))return!1;return!0}return!1}var ma=Object.prototype.hasOwnProperty;function Re(r,a,t=0){if(r===a)return r;if(t>500)return a;let o=zr(r)&&zr(a);if(!o&&!(lr(r)&&lr(a)))return a;let i=(o?r:Object.keys(r)).length,c=o?a:Object.keys(a),n=c.length,s=o?Array(n):{},l=0;for(let d=0;d<n;d++){let h=o?d:c[d],p=r[h],g=a[h];if(p===g){if(s[h]=p,o?d<i:ma.call(r,h))l++;continue}if(p===null||g===null||typeof p!=="object"||typeof g!=="object"){s[h]=g;continue}let b=Re(p,g,t+1);if(s[h]=b,b===p)l++}return i===n&&l===i?r:s}function we(r,a){if(!a||Object.keys(r).length!==Object.keys(a).length)return!1;for(let t in r)if(r[t]!==a[t])return!1;return!0}function zr(r){return Array.isArray(r)&&r.length===Object.keys(r).length}function lr(r){if(!_r(r))return!1;let a=r.constructor;if(a===void 0)return!0;let t=a.prototype;if(!_r(t))return!1;if(!t.hasOwnProperty("isPrototypeOf"))return!1;if(Object.getPrototypeOf(r)!==Object.prototype)return!1;return!0}function _r(r){return Object.prototype.toString.call(r)==="[object Object]"}function Er(r){return new Promise((a)=>{Z.setTimeout(a,r)})}function Ae(r,a,t){if(typeof t.structuralSharing==="function")return t.structuralSharing(r,a);else if(t.structuralSharing!==!1)return Re(r,a);return a}function Sr(r,a,t=0){let o=[...r,a];return t&&o.length>t?o.slice(1):o}function Ar(r,a,t=0){let o=[a,...r];return t&&o.length>t?o.slice(0,-1):o}var P=Symbol();function H(r,a){if(!r.queryFn&&a?.initialPromise)return()=>a.initialPromise;if(!r.queryFn||r.queryFn===P)return()=>Promise.reject(Error(`Missing queryFn: '${r.queryHash}'`));return r.queryFn}function Se(r,a){if(typeof r==="function")return r(...a);return!!r}function jr(r,a,t){let o=!1,i;return Object.defineProperty(r,"signal",{enumerable:!0,get:()=>{if(i??=a(),o)return i;if(o=!0,i.aborted)t();else i.addEventListener("abort",t,{once:!0});return i}}),r}var fa=()=>dr,Ie=()=>fa();var G=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(r){return this.listeners.add(r),this.onSubscribe(),()=>{this.listeners.delete(r),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}};var ba=class extends G{#r;#a;#t;constructor(){super();this.#t=(r)=>{if(typeof window<"u"&&window.addEventListener){let a=()=>r();return window.addEventListener("visibilitychange",a,!1),()=>{window.removeEventListener("visibilitychange",a)}}}}onSubscribe(){if(!this.#a)this.setEventListener(this.#t)}onUnsubscribe(){if(!this.hasListeners())this.#a?.(),this.#a=void 0}setEventListener(r){this.#t=r,this.#a?.(),this.#a=r((a)=>{if(typeof a==="boolean")this.setFocused(a);else this.onFocus()})}setFocused(r){if(this.#r!==r)this.#r=r,this.onFocus()}onFocus(){let r=this.isFocused();this.listeners.forEach((a)=>{a(r)})}isFocused(){if(typeof this.#r==="boolean")return this.#r;return globalThis.document?.visibilityState!=="hidden"}},Ce=new ba;var Pr=kr;function xa(){let r=[],a=0,t=(s)=>{s()},o=(s)=>{s()},i=Pr,c=(s)=>{if(a)r.push(s);else i(()=>{t(s)})},n=()=>{let s=r;if(r=[],s.length)i(()=>{o(()=>{s.forEach((l)=>{t(l)})})})};return{batch:(s)=>{let l;a++;try{l=s()}finally{if(a--,!a)n()}return l},batchCalls:(s)=>(...l)=>{c(()=>{s(...l)})},schedule:c,setNotifyFunction:(s)=>{t=s},setBatchNotifyFunction:(s)=>{o=s},setScheduler:(s)=>{i=s}}}var C=xa();var ya=class extends G{#r=!0;#a;#t;constructor(){super();this.#t=(r)=>{if(typeof window<"u"&&window.addEventListener){let a=()=>r(!0),t=()=>r(!1);return window.addEventListener("online",a,!1),window.addEventListener("offline",t,!1),()=>{window.removeEventListener("online",a),window.removeEventListener("offline",t)}}}}onSubscribe(){if(!this.#a)this.setEventListener(this.#t)}onUnsubscribe(){if(!this.hasListeners())this.#a?.(),this.#a=void 0}setEventListener(r){this.#t=r,this.#a?.(),this.#a=r(this.setOnline.bind(this))}setOnline(r){if(this.#r!==r)this.#r=r,this.listeners.forEach((a)=>{a(r)})}isOnline(){return this.#r}},O=new ya;function ka(r){return Math.min(1000*2**r,30000)}function pr(r){return(r??"online")==="online"?O.isOnline():!0}var V=class extends Error{constructor(r){super("CancelledError");this.revert=r?.revert,this.silent=r?.silent}};function X(r){let a=!1,t=0,o,i="pending",c,n,s=new Promise((u,m)=>{c=u,n=m});s.catch(A);let l=()=>i!=="pending",d=(u)=>{if(!l()){let m=new V(u);w(m),r.onCancel?.(m)}},h=()=>{a=!0},p=()=>{a=!1},g=()=>Ce.isFocused()&&(r.networkMode==="always"||O.isOnline())&&r.canRun(),b=()=>pr(r.networkMode)&&r.canRun(),v=(u)=>{if(!l())o?.(),i="resolved",c(u)},w=(u)=>{if(!l())o?.(),i="rejected",n(u)},y=()=>new Promise((u)=>{o=(m)=>{if(l()||g())u(m)},r.onPause?.()}).then(()=>{if(o=void 0,!l())r.onContinue?.()}),R=()=>{if(l())return;let u,m=t===0?r.initialPromise:void 0;try{u=m??r.fn()}catch(f){u=Promise.reject(f)}Promise.resolve(u).then(v).catch((f)=>{if(l())return;let k=r.retry??(Ie()?0:3),S=r.retryDelay??ka,oa=typeof S==="function"?S(t,f):S,ia=k===!0||typeof k==="number"&&t<k||typeof k==="function"&&k(t,f);if(a||!ia){w(f);return}t++,r.onFail?.(t,f),Er(oa).then(()=>g()?void 0:y()).then(()=>{if(a)w(f);else R()})})};return{promise:s,status:()=>i,cancel:d,continue:()=>(o?.(),s),cancelRetry:h,continueRetry:p,canStart:b,start:()=>{if(b())R();else y().then(R);return s}}}var rr=class{#r;destroy(){this.clearGcTimeout()}scheduleGc(){if(this.clearGcTimeout(),Be(this.gcTime))this.#r=Z.setTimeout(()=>{this.optionalRemove()},this.gcTime)}updateGcTime(r){this.gcTime=Math.max(this.gcTime||0,r??(Ie()?1/0:300000))}clearGcTimeout(){if(this.#r!==void 0)Z.clearTimeout(this.#r),this.#r=void 0}};function Mr(r){return{onFetch:(a,t)=>{let o=a.options,i=a.fetchOptions?.meta?.fetchMore?.direction,c=a.state.data?.pages||[],n=a.state.data?.pageParams||[],s={pages:[],pageParams:[]},l=0,d=async()=>{let h=!1,p=(v)=>{jr(v,()=>a.signal,()=>h=!0)},g=H(a.options,a.fetchOptions),b=async(v,w,y)=>{if(h)return Promise.reject(a.signal.reason);if(w==null&&v.pages.length)return Promise.resolve(v);let u=(()=>{let S={client:a.client,queryKey:a.queryKey,pageParam:w,direction:y?"backward":"forward",meta:a.options.meta};return p(S),S})(),m=await g(u),{maxPages:f}=a.options,k=y?Ar:Sr;return{pages:k(v.pages,m,f),pageParams:k(v.pageParams,w,f)}};if(i&&c.length){let v=i==="backward",w=v?za:Or,y={pages:c,pageParams:n};s=await b(y,w(o,y),v)}else{let v=r??c.length;do{let w=l===0?n[0]??o.initialPageParam:Or(o,s);if(l>0&&w==null)break;s=await b(s,w),l++}while(l<v)}return s};if(a.options.persister)a.fetchFn=()=>a.options.persister?.(d,{client:a.client,queryKey:a.queryKey,meta:a.options.meta,signal:a.signal},t);else a.fetchFn=d}}}function Or(r,{pages:a,pageParams:t}){let o=a.length-1;return a.length>0?r.getNextPageParam(a[o],a,t[o],t):void 0}function za(r,{pages:a,pageParams:t}){return a.length>0?r.getPreviousPageParam?.(a[0],a,t[0],t):void 0}var Dr=class extends rr{#r;#a;#t;#o;#i;#e;#c;#n;constructor(r){super();this.#n=!1,this.#c=r.defaultOptions,this.setOptions(r.options),this.observers=[],this.#i=r.client,this.#o=this.#i.getQueryCache(),this.queryKey=r.queryKey,this.queryHash=r.queryHash,this.#a=qr(this.options),this.state=r.state??this.#a,this.scheduleGc()}get meta(){return this.options.meta}get queryType(){return this.#r}get promise(){return this.#e?.promise}setOptions(r){if(this.options={...this.#c,...r},r?._type)this.#r=r._type;if(this.updateGcTime(this.options.gcTime),this.state&&this.state.data===void 0){let a=qr(this.options);if(a.data!==void 0)this.setState(Ir(a.data,a.dataUpdatedAt)),this.#a=a}}optionalRemove(){if(!this.observers.length&&this.state.fetchStatus==="idle")this.#o.remove(this)}setData(r,a){let t=Ae(this.state.data,r,this.options);return this.#s({data:t,type:"success",dataUpdatedAt:a?.updatedAt,manual:a?.manual}),t}setState(r){this.#s({type:"setState",state:r})}cancel(r){let a=this.#e?.promise;return this.#e?.cancel(r),a?a.then(A).catch(A):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}get resetState(){return this.#a}reset(){this.destroy(),this.setState(this.resetState)}isActive(){return this.observers.some((r)=>T(r.options.enabled,this)!==!1)}isDisabled(){if(this.getObserversCount()>0)return!this.isActive();return this.options.queryFn===P||!this.isFetched()}isFetched(){return this.state.dataUpdateCount+this.state.errorUpdateCount>0}isStatic(){if(this.getObserversCount()>0)return this.observers.some((r)=>T(r.options.staleTime,this)==="static");return!1}isStale(){if(this.getObserversCount()>0)return this.observers.some((r)=>r.getCurrentResult().isStale);return this.state.data===void 0||this.state.isInvalidated}isStaleByTime(r=0){if(this.state.data===void 0)return!0;if(r==="static")return!1;if(this.state.isInvalidated)return!0;return!ze(this.state.dataUpdatedAt,r)}onFocus(){this.observers.find((r)=>r.shouldFetchOnWindowFocus())?.refetch({cancelRefetch:!1}),this.#e?.continue()}onOnline(){this.observers.find((r)=>r.shouldFetchOnReconnect())?.refetch({cancelRefetch:!1}),this.#e?.continue()}addObserver(r){if(!this.observers.includes(r))this.observers.push(r),this.clearGcTimeout(),this.#o.notify({type:"observerAdded",query:this,observer:r})}removeObserver(r){let a=this.observers.indexOf(r);if(a!==-1){if(this.observers.splice(a,1),!this.observers.length){if(this.#e)if(this.#n||this.state.fetchStatus==="paused"&&this.state.status==="pending")this.#e.cancel({revert:!0});else this.#e.cancelRetry();this.scheduleGc()}this.#o.notify({type:"observerRemoved",query:this,observer:r})}}getObserversCount(){return this.observers.length}invalidate(){if(!this.state.isInvalidated)this.#s({type:"invalidate"})}async fetch(r,a){if(this.state.fetchStatus!=="idle"&&this.#e?.status()!=="rejected"){if(this.state.data!==void 0&&a?.cancelRefetch)this.cancel({silent:!0});else if(this.#e)return this.#e.continueRetry(),this.#e.promise}if(r)this.setOptions(r);if(!this.options.queryFn){let l=this.observers.find((d)=>d.options.queryFn);if(l)this.setOptions(l.options)}let t=new AbortController,o=(l)=>{Object.defineProperty(l,"signal",{enumerable:!0,get:()=>(this.#n=!0,t.signal)})},i=()=>{let l=H(this.options,a),h=(()=>{let p={client:this.#i,queryKey:this.queryKey,meta:this.meta};return o(p),p})();if(this.#n=!1,this.options.persister)return this.options.persister(l,h,this);return l(h)},n=(()=>{let l={fetchOptions:a,options:this.options,queryKey:this.queryKey,client:this.#i,state:this.state,fetchFn:i};return o(l),l})();if((this.#r==="infinite"?Mr(this.options.pages):this.options.behavior)?.onFetch(n,this),this.#t=this.state,this.state.fetchStatus==="idle"||this.state.fetchMeta!==n.fetchOptions?.meta)this.#s({type:"fetch",meta:n.fetchOptions?.meta});let s=this.#e=X({initialPromise:a?.initialPromise,fn:n.fetchFn,onCancel:(l)=>{if(l instanceof V&&l.revert)this.setState({...this.#t,fetchStatus:"idle"});t.abort()},onFail:(l,d)=>{this.#s({type:"failed",failureCount:l,error:d})},onPause:()=>{this.#s({type:"pause"})},onContinue:()=>{this.#s({type:"continue"})},retry:n.options.retry,retryDelay:n.options.retryDelay,networkMode:n.options.networkMode,canRun:()=>!0});try{let l=await s.start();if(l===void 0)throw Error(`${this.queryHash} data is undefined`);return this.setData(l),this.#o.config.onSuccess?.(l,this),this.#o.config.onSettled?.(l,this.state.error,this),l}catch(l){if(l instanceof V){if(l.silent)return this.#e.promise;else if(l.revert){if(this.state.data===void 0)throw l;return this.state.data}}throw this.#s({type:"error",error:l}),this.#o.config.onError?.(l,this),this.#o.config.onSettled?.(this.state.data,l,this),l}finally{if(this.#e===s)this.#e=void 0;this.scheduleGc()}}#s(r){let a=(t)=>{switch(r.type){case"failed":return{...t,fetchFailureCount:r.failureCount,fetchFailureReason:r.error};case"pause":return{...t,fetchStatus:"paused"};case"continue":return{...t,fetchStatus:"fetching"};case"fetch":return{...t,...Ze(t.data,this.options),fetchMeta:r.meta??null};case"success":let o={...t,...Ir(r.data,r.dataUpdatedAt),dataUpdateCount:t.dataUpdateCount+1,...!r.manual&&{fetchStatus:"idle",fetchFailureCount:0,fetchFailureReason:null}};return this.#t=r.manual?o:void 0,o;case"error":let i=r.error;return{...t,error:i,errorUpdateCount:t.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:t.fetchFailureCount+1,fetchFailureReason:i,fetchStatus:"idle",status:"error",isInvalidated:!0};case"invalidate":return{...t,isInvalidated:!0};case"setState":return{...t,...r.state}}};this.state=a(this.state),C.batch(()=>{this.observers.slice().forEach((t)=>{t.onQueryUpdate()}),this.#o.notify({query:this,type:"updated",action:r})})}};function Ze(r,a){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:pr(a.networkMode)?"fetching":"paused",...r===void 0&&{error:null,status:"pending"}}}function Ir(r,a){return{data:r,dataUpdatedAt:a??Date.now(),error:null,isInvalidated:!1,status:"success"}}function qr(r){let a=typeof r.initialData==="function"?r.initialData():r.initialData,t=a!==void 0,o=t?typeof r.initialDataUpdatedAt==="function"?r.initialDataUpdatedAt():r.initialDataUpdatedAt:0;return{data:a,dataUpdateCount:0,dataUpdatedAt:t?o??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:t?"success":"pending",fetchStatus:"idle"}}var Ur=class extends rr{#r;#a;#t;#o;constructor(r){super();this.#r=r.client,this.mutationId=r.mutationId,this.#t=r.mutationCache,this.#a=[],this.state=r.state||Je(),this.setOptions(r.options),this.scheduleGc()}setOptions(r){this.options=r,this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(r){if(!this.#a.includes(r))this.#a.push(r),this.clearGcTimeout(),this.#t.notify({type:"observerAdded",mutation:this,observer:r})}removeObserver(r){this.#a=this.#a.filter((a)=>a!==r),this.scheduleGc(),this.#t.notify({type:"observerRemoved",mutation:this,observer:r})}optionalRemove(){if(!this.#a.length)if(this.state.status==="pending")this.scheduleGc();else this.#t.remove(this)}continue(){return this.#o?.continue()??(this.state.status==="pending"?this.execute(this.state.variables):Promise.resolve())}async execute(r){let a=()=>{this.#i({type:"continue"})},t={client:this.#r,meta:this.options.meta,mutationKey:this.options.mutationKey},o=this.#o=X({fn:()=>{if(!this.options.mutationFn)return Promise.reject(Error("No mutationFn found"));return this.options.mutationFn(r,t)},onFail:(n,s)=>{this.#i({type:"failed",failureCount:n,error:s})},onPause:()=>{this.#i({type:"pause"})},onContinue:a,retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>this.#t.canRun(this)}),i=this.state.status==="pending",c=!o.canStart();try{if(i)a();else{if(this.#i({type:"pending",variables:r,isPaused:c}),this.#t.config.onMutate)await this.#t.config.onMutate(r,this,t);let s=await this.options.onMutate?.(r,t);if(s!==this.state.context)this.#i({type:"pending",context:s,variables:r,isPaused:c})}let n=await o.start();return await this.#t.config.onSuccess?.(n,r,this.state.context,this,t),await this.options.onSuccess?.(n,r,this.state.context,t),await this.#t.config.onSettled?.(n,null,this.state.variables,this.state.context,this,t),await this.options.onSettled?.(n,null,r,this.state.context,t),this.#i({type:"success",data:n}),n}catch(n){try{await this.#t.config.onError?.(n,r,this.state.context,this,t)}catch(s){Promise.reject(s)}try{await this.options.onError?.(n,r,this.state.context,t)}catch(s){Promise.reject(s)}try{await this.#t.config.onSettled?.(void 0,n,this.state.variables,this.state.context,this,t)}catch(s){Promise.reject(s)}try{await this.options.onSettled?.(void 0,n,r,this.state.context,t)}catch(s){Promise.reject(s)}throw this.#i({type:"error",error:n}),n}finally{if(this.#o===o)this.#o=void 0;this.#t.runNext(this)}}#i(r){let a=(t)=>{switch(r.type){case"failed":return{...t,failureCount:r.failureCount,failureReason:r.error};case"pause":return{...t,isPaused:!0};case"continue":return{...t,isPaused:!1};case"pending":return{...t,context:r.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:r.isPaused,status:"pending",variables:r.variables,submittedAt:Date.now()};case"success":return{...t,data:r.data,failureCount:0,failureReason:null,error:null,status:"success",isPaused:!1};case"error":return{...t,data:void 0,error:r.error,failureCount:t.failureCount+1,failureReason:r.error,isPaused:!1,status:"error"}}};this.state=a(this.state),C.batch(()=>{this.#a.forEach((t)=>{t.onMutationUpdate(r)}),this.#t.notify({mutation:this,type:"updated",action:r})})}};function Je(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0}}var Fr=class extends G{#r;#a;#t;constructor(r={}){super();this.config=r,this.#r=new Set,this.#a=new Map,this.#t=0}build(r,a,t){let o=new Ur({client:r,mutationCache:this,mutationId:++this.#t,options:r.defaultMutationOptions(a),state:t});return this.add(o),o}add(r){this.#r.add(r);let a=ar(r);if(typeof a==="string"){let t=this.#a.get(a);if(t)t.push(r);else this.#a.set(a,[r])}this.notify({type:"added",mutation:r})}remove(r){if(this.#r.delete(r)){let a=ar(r);if(typeof a==="string"){let t=this.#a.get(a);if(t){if(t.length>1){let o=t.indexOf(r);if(o!==-1)t.splice(o,1)}else if(t[0]===r)this.#a.delete(a)}}}this.notify({type:"removed",mutation:r})}canRun(r){let a=ar(r);if(typeof a==="string"){let t=this.#a.get(a)?.find((o)=>o.state.status==="pending");return!t||t===r}else return!0}runNext(r){let a=ar(r);if(typeof a==="string")return this.#a.get(a)?.find((t)=>t!==r&&t.state.isPaused)?.continue()??Promise.resolve();else return Promise.resolve()}clear(){C.batch(()=>{this.#r.forEach((r)=>{this.notify({type:"removed",mutation:r})}),this.#r.clear(),this.#a.clear()})}getAll(){return Array.from(this.#r)}find(r){let a={exact:!0,...r};return this.getAll().find((t)=>K(a,t))}findAll(r={}){return this.getAll().filter((a)=>K(r,a))}notify(r){C.batch(()=>{this.listeners.forEach((a)=>{a(r)})})}resumePausedMutations(){let r=this.getAll().filter((a)=>a.state.isPaused);return C.batch(()=>Promise.all(r.map((a)=>a.continue().catch(A))))}};function ar(r){return r.options.scope?.id}var Tr=class extends G{#r;constructor(r={}){super();this.config=r,this.#r=new Map}build(r,a,t){let o=a.queryKey,i=a.queryHash??D(o,a),c=this.get(i);if(!c)c=new Dr({client:r,queryKey:o,queryHash:i,options:r.defaultQueryOptions(a),state:t,defaultOptions:r.getQueryDefaults(o)}),this.add(c);return c}add(r){if(!this.#r.has(r.queryHash))this.#r.set(r.queryHash,r),this.notify({type:"added",query:r})}remove(r){let a=this.#r.get(r.queryHash);if(a){if(r.destroy(),a===r)this.#r.delete(r.queryHash);this.notify({type:"removed",query:r})}}clear(){C.batch(()=>{this.getAll().forEach((r)=>{this.remove(r)})})}get(r){return this.#r.get(r)}getAll(){return[...this.#r.values()]}find(r){let a={exact:!0,...r};return this.getAll().find((t)=>ve(a,t))}findAll(r={}){let a=this.getAll();return Object.keys(r).length>0?a.filter((t)=>ve(r,t)):a}notify(r){C.batch(()=>{this.listeners.forEach((a)=>{a(r)})})}onFocus(){C.batch(()=>{this.getAll().forEach((r)=>{r.onFocus()})})}onOnline(){C.batch(()=>{this.getAll().forEach((r)=>{r.onOnline()})})}};var hr=class{#r;#a;#t;#o;#i;#e;#c;#n;constructor(r={}){this.#r=r.queryCache||new Tr,this.#a=r.mutationCache||new Fr,this.#t=r.defaultOptions||{},this.#o=new Map,this.#i=new Map,this.#e=0}mount(){if(this.#e++,this.#e!==1)return;this.#c=Ce.subscribe(async(r)=>{if(r)await this.resumePausedMutations(),this.#r.onFocus()}),this.#n=O.subscribe(async(r)=>{if(r)await this.resumePausedMutations(),this.#r.onOnline()})}unmount(){if(this.#e--,this.#e!==0)return;this.#c?.(),this.#c=void 0,this.#n?.(),this.#n=void 0}isFetching(r){return this.#r.findAll({...r,fetchStatus:"fetching"}).length}isMutating(r){return this.#a.findAll({...r,status:"pending"}).length}getQueryData(r){let a=this.defaultQueryOptions({queryKey:r});return this.#r.get(a.queryHash)?.state.data}ensureQueryData(r){let a=this.defaultQueryOptions(r),t=this.#r.build(this,a),o=t.state.data;if(o===void 0)return this.fetchQuery(r);if(r.revalidateIfStale&&t.isStaleByTime(T(a.staleTime,t)))this.prefetchQuery(a);return Promise.resolve(o)}getQueriesData(r){return this.#r.findAll(r).map(({queryKey:a,state:t})=>[a,t.data])}setQueryData(r,a,t){let o=this.defaultQueryOptions({queryKey:r}),i=this.#r.get(o.queryHash)?.state.data,c=Cr(a,i);if(c===void 0)return;return this.#r.build(this,o).setData(c,{...t,manual:!0})}setQueriesData(r,a,t){return C.batch(()=>this.#r.findAll(r).map(({queryKey:o})=>[o,this.setQueryData(o,a,t)]))}getQueryState(r){let a=this.defaultQueryOptions({queryKey:r});return this.#r.get(a.queryHash)?.state}removeQueries(r){let a=this.#r;C.batch(()=>{a.findAll(r).forEach((t)=>{a.remove(t)})})}resetQueries(r,a){let t=this.#r;return C.batch(()=>{let o=t.findAll(r),i=new Set(o);return o.forEach((c)=>{c.reset()}),this.refetchQueries({type:"active",predicate:(c)=>i.has(c)},a)})}cancelQueries(r,a={}){let t={revert:!0,...a},o=C.batch(()=>this.#r.findAll(r).map((i)=>i.cancel(t)));return Promise.all(o).then(A).catch(A)}invalidateQueries(r,a={}){return C.batch(()=>{if(this.#r.findAll(r).forEach((t)=>{t.invalidate()}),r?.refetchType==="none")return Promise.resolve();return this.refetchQueries({...r,type:r?.refetchType??r?.type??"active"},a)})}refetchQueries(r,a={}){let t={...a,cancelRefetch:a.cancelRefetch??!0},o=C.batch(()=>this.#r.findAll(r).filter((i)=>!i.isDisabled()&&!i.isStatic()).map((i)=>{let c=i.fetch(void 0,t);if(!t.throwOnError)c=c.catch(A);return i.state.fetchStatus==="paused"?Promise.resolve():c}));return Promise.all(o).then(A)}async query(r){let a=this.defaultQueryOptions(r);if(a.retry===void 0)a.retry=!1;let t=this.#r.build(this,a),o=t.isStaleByTime(T(a.staleTime,t))?await t.fetch(a):t.state.data,i=a.select;if(i)return i(o);return o}fetchQuery(r){let a=this.defaultQueryOptions(r);if(a.retry===void 0)a.retry=!1;let t=this.#r.build(this,a);return t.isStaleByTime(T(a.staleTime,t))?t.fetch(a):Promise.resolve(t.state.data)}prefetchQuery(r){return this.fetchQuery(r).then(A).catch(A)}infiniteQuery(r){return r._type="infinite",this.query(r)}fetchInfiniteQuery(r){return r._type="infinite",this.fetchQuery(r)}prefetchInfiniteQuery(r){return this.fetchInfiniteQuery(r).then(A).catch(A)}ensureInfiniteQueryData(r){return r._type="infinite",this.ensureQueryData(r)}resumePausedMutations(){if(O.isOnline())return this.#a.resumePausedMutations();return Promise.resolve()}getQueryCache(){return this.#r}getMutationCache(){return this.#a}getDefaultOptions(){return this.#t}setDefaultOptions(r){this.#t=r}setQueryDefaults(r,a){this.#o.set(J(r),{queryKey:r,defaultOptions:a})}getQueryDefaults(r){let a=[...this.#o.values()],t={};return a.forEach((o)=>{if(z(r,o.queryKey))Object.assign(t,o.defaultOptions)}),t}setMutationDefaults(r,a){this.#i.set(J(r),{mutationKey:r,defaultOptions:a})}getMutationDefaults(r){let a=[...this.#i.values()],t={};return a.forEach((o)=>{if(z(r,o.mutationKey))Object.assign(t,o.defaultOptions)}),t}defaultQueryOptions(r){if(r._defaulted)return r;let a={...this.#t.queries,...this.getQueryDefaults(r.queryKey),...r,_defaulted:!0};if(!a.queryHash)a.queryHash=D(a.queryKey,a);if(a.refetchOnReconnect===void 0)a.refetchOnReconnect=a.networkMode!=="always";if(a.throwOnError===void 0)a.throwOnError=!!a.suspense;if(!a.networkMode&&a.persister)a.networkMode="offlineFirst";if(a.queryFn===P)a.enabled=!1;return a}defaultMutationOptions(r){if(r?._defaulted)return r;return{...this.#t.mutations,...r?.mutationKey&&this.getMutationDefaults(r.mutationKey),...r,_defaulted:!0}}clear(){this.#r.clear(),this.#a.clear()}};var M=new hr;var N={all:["workspace-members"],account:(r)=>[...N.all,r??"unknown"],workspace:(r,a)=>[...N.account(r),a]};var I=["pink","orange","amber","lime","emerald","cyan","blue","violet"];function tr(r){return typeof r==="string"&&I.includes(r)}function Qr(r){let a=2166136261;for(let t=0;t<r.length;t++)a^=r.charCodeAt(t),a=Math.imul(a,16777619);return I[(a>>>0)%I.length]??I[0]}var lt=1;var _a=8192,Ca=320;function ne(r){return typeof r==="object"&&r!==null&&!Array.isArray(r)}function er(r,a=256){return typeof r==="string"&&r.length>0&&!r.includes("\x00")&&new TextEncoder().encode(r).length<=a}function Rr(r){return ne(r)&&er(r.id,240)&&r.id.trim().length>0&&(r.name===void 0||er(r.name)&&r.name.trim().length>0)&&tr(r.color)&&(r.avatar===void 0||er(r.avatar,_a))&&(r.email===void 0||er(r.email,Ca))}function or(r,a){return typeof r==="string"&&r.length<=a&&!r.includes("\x00")}function Ea(r){if(!or(r,2048))return!1;try{return["http:","https:"].includes(new URL(r).protocol)}catch{return!1}}function ie(r){if(!ne(r)||!or(r.id,240)||!r.id.trim()||r.id!==r.id.trim()||!or(r.name,256)||r.avatar!==void 0&&!Ea(r.avatar))throw Error("Invalid identity");let a={id:r.id,name:r.name,...r.avatar!==void 0?{avatar:r.avatar}:{}};if(r.type==="agent")return{...a,type:"agent"};if(r.type==="user"&&or(r.email,320)&&typeof r.isAnonymous==="boolean")return{...a,type:"user",email:r.email,isAnonymous:r.isAnonymous};throw Error("Invalid identity")}var W=(r)=>`${r.type}:${r.id}`,ir=(r)=>r.type==="agent"?`agent:${r.id}`:r.id;var nr,Lr=0,Nr=0,gr=new Set,U=()=>nr,_e=()=>Nr,Q=()=>Lr;function Ue(r){return gr.add(r),()=>{gr.delete(r)}}function ce(r){let a=r===null?null:ie(r);if((nr&&W(nr))!==(a&&W(a)))Lr++,M.cancelQueries({queryKey:N.all}),M.removeQueries({queryKey:N.all});Nr++,nr=a,gr.forEach((o)=>o())}var Sa=["Curious Kiwi","Cheerful Cherry","Sleepy Peach","Excited Banana","Cosmic Mango","Velvet Lemon","Electric Plum","Wandering Pear","Dramatic Papaya","Suspicious Pineapple","Confused Coconut","Sneaky Tangerine","Gentle Fig","Quiet Apricot","Mellow Melon","Dreamy Guava"];function Kr(r,a){let t=r.filter((o)=>o!==a);return t[Math.floor(Math.random()*t.length)]??r[0]}function Aa(r){return{name:Kr(Sa,r?.name),color:Kr(I,r?.color)}}function ja(r,a){let t=a.name.trim();return{id:r,...t?{name:t}:{},color:a.color}}function Br(){return ja(`local-${crypto.randomUUID().slice(0,8)}`,Aa())}var vr="moi:local-profile",_,E,F=new Set;function wr(r,a){return JSON.stringify(r)===JSON.stringify(a)}function q(r){if(!r||typeof r.id!=="string"||!r.id.trim())throw Error("A user profile needs an id.");if(r.name!==void 0&&typeof r.name!=="string")throw Error("A user profile name must be a string when provided.");if(r.color!==void 0&&!tr(r.color))throw Error("A user profile color must be one of the user palette names.");let a=r.id.trim(),t=r.name?.trim(),o={id:a,...t?{name:t}:{},color:r.color??Qr(a),...r.avatar!==void 0?{avatar:r.avatar}:{},...r.email!==void 0?{email:r.email}:{}};if(!Rr(o))throw Error("Invalid user profile.");return Object.freeze(o)}var ur,Hr;function B(){let r=U();if(r===void 0)return _;if(r!==Hr){Hr=r;let a=!r||r.type==="user"&&r.isAnonymous?void 0:q({id:ir(r),name:r.name||void 0,avatar:r.avatar,email:r.type==="user"?r.email||void 0:void 0});if(!wr(ur,a))ur=a}return ur}function ue(r){let a=B(),t=j(),o=()=>{let c=B(),n=j();if(a===c&&t===n)return;a=c,t=n,r()};F.add(o);let i=Ue(o);return()=>{F.delete(o),i()}}function j(){return U()!==void 0?"external":E}function ct({provider:r,profile:a}){if(j()==="external")return;if(r===void 0){if(E===void 0||E==="local")return;E=void 0,_=void 0}else{let t=a===void 0?void 0:q(a);if(E===r&&wr(_,t))return;E=r,_=t}F.forEach((t)=>t())}function Pa(){try{localStorage.setItem(vr,JSON.stringify(_))}catch{}}function He(r){if(j()!==void 0&&j()!=="local")return;let a=q(r);E="local",_=a,Pa(),F.forEach((t)=>t())}function Vr(r,a){if(!r||!a||a.provider!==void 0||j()!==void 0)return;try{let t=localStorage.getItem(vr);if(t){He(JSON.parse(t));return}}catch{}He(Br())}function Wr(r){if(r.key!==vr||!r.newValue||j()!=="local")return;try{let a=q(JSON.parse(r.newValue));if(wr(a,_))return;_=a,F.forEach((t)=>t())}catch{}}function $r(){return window.addEventListener("storage",Wr),()=>window.removeEventListener("storage",Wr)}function Me(r){if(!ne(r)||!Array.isArray(r.members)||!Array.isArray(r.invitations))throw Error("Invalid workspace members");let a=r.members.map((o)=>{let i=ie(o);if(ne(o)&&o.membershipId!==void 0){if(typeof o.membershipId!=="string"||!o.membershipId||o.membershipId.length>240)throw Error("Invalid membership id");return{...i,membershipId:o.membershipId}}return i}),t=r.invitations.map((o)=>{if(!ne(o)||typeof o.id!=="string"||!o.id||typeof o.email!=="string"||!o.email||typeof o.expiresAt!=="string"||!Number.isFinite(Date.parse(o.expiresAt)))throw Error("Invalid invitation");return{id:o.id,email:o.email,expiresAt:o.expiresAt}});if(new Set(a.map(W)).size!==a.length||new Set(t.map((o)=>o.id)).size!==t.length)throw Error("Duplicate workspace member or invitation");return{members:a,invitations:t}}function ke(r){if(!/^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/.test(r))throw Error("Invalid workspace id");return r}M.setQueryDefaults(N.all,{gcTime:1/0});var fr=0,Jr,mr=new Set,Yr=new WeakMap;M.getQueryCache().subscribe((r)=>{if(r.query.queryKey[0]!==N.all[0])return;if(r.type==="removed"||r.type==="updated"&&r.action.type==="success")fr++});var Zr=()=>fr,Xr=new WeakMap;function We(){let r=U();if(Jr!==Q()||r?.type!=="user"||r.isAnonymous)return;let a=Yr.get(r);if(!a)a={members:[r],invitations:[]},Yr.set(r,a);return a}function Gr(r,a){let t=U(),o=N.workspace(t?W(t):void 0,r);ke(r);let i=Me(a);M.cancelQueries({queryKey:o,exact:!0}),M.setQueryData(o,i)}function ra(r){if(!Array.isArray(r))throw Error("Invalid workspace members");let a=r.map((n)=>({id:ke(n.id),data:Me(n)})),t=new Set(a.map((n)=>n.id));if(t.size!==a.length)throw Error("Duplicate workspace id");Jr=Q();let o=U(),i=o?W(o):void 0,c=N.account(i);M.cancelQueries({queryKey:c});for(let n of M.getQueryCache().findAll({queryKey:c}))if(!t.has(n.queryKey[2]))br(n.queryKey);for(let n of a)M.setQueryData(N.workspace(i,n.id),n.data);fr++,mr.forEach((n)=>n())}function aa(r){let a=U(),t=N.workspace(a?W(a):void 0,r);ke(r),M.cancelQueries({queryKey:t,exact:!0}),br(t)}function ta(){M.cancelQueries({queryKey:N.all});for(let r of M.getQueryCache().findAll({queryKey:N.all}))br(r.queryKey)}function br(r){M.setQueryData(r,We()??{members:[],invitations:[]})}function ut(r){let a=U(),t=N.workspace(a?W(a):void 0,r),o=M.getQueryData(t)??We();if(!o)return;let i=Xr.get(o);if(!i)i=o.members.map((c)=>q({id:ir(c),name:c.name||void 0,avatar:c.avatar,email:c.type==="user"?c.email||void 0:void 0})),Xr.set(o,i);return i}function Qe(r){mr.add(r);let a=M.getQueryCache().subscribe((t)=>{if(t.query.queryKey[0]===N.all[0])r()});return()=>{mr.delete(r),a()}}function ea(){if(typeof window>"u")return;let r=window;r.moi??={},r.moi.identity={set:ce,getRevision:_e},r.moi.workspaceMembers={set:Gr,setAll:ra,remove:aa,clear:ta,getRevision:Zr}}ea();$r();async function Oa(r){let[{mount:a},t,o]=await Promise.all([(Y("ep5vh16c"),import("/chunk-ep5vh16c.js")),(Y("vp2qzc0d"),import("/chunk-vp2qzc0d.js")).then((i)=>i.loadAppConfig()),(Y("7rz6g7g7"),import("/chunk-7rz6g7g7.js")).then((i)=>i.loadProxyUser())]);Vr(t?.environment==="local"&&!t.demo,o),a(r)}globalThis.__init=Oa;export{e,x,be,st,Y,Z,A,Be,ze,T,ve,J,Re,we,Ae,Se,Ie,G,Ce,C,Ze,Je,M,N,lt,ne,ie,W,U,_e,Q,Ue,ce,B,ue,j,ct,He,Me,ke,We,ut,Qe};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
async function s(t,e){let o=await t.text();return Error(o||e)}async function p(t,e,o="Request failed"){let n=await fetch(t,e);if(!n.ok)throw await s(n,o);return n.json()}async function
|
|
2
|
-
export{p,
|
|
1
|
+
async function s(t,e){let o=await t.text();return Error(o||e)}async function p(t,e,o="Request failed"){let n=await fetch(t,e);if(!n.ok)throw await s(n,o);return n.json()}async function H(t,e,o="Request failed"){let n=await fetch(t,e);if(!n.ok)throw await s(n,o)}function v(t,e){return{method:t,headers:{"Content-Type":"application/json"},body:e===void 0?void 0:JSON.stringify(e)}}
|
|
2
|
+
export{p,H,v};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{gt}from"/chunk-kdgk4dac.js";export{gt as sanitizeSvg};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{xt,R}from"/chunk-wz5qv1bn.js";export{xt as loadAppConfig,R as useAppConfig};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{e,x}from"/chunk-
|
|
2
|
-
export{t,
|
|
1
|
+
import{e,x}from"/chunk-s5s1vzdw.js";import{p}from"/chunk-svxhxfeq.js";var t=x(function(a,r){r.exports=globalThis.__esm.react});var f=e(t(),1);var l={environment:"local",collab:!1,demo:!1,demoInstallUrl:"https://moi.computer"},o=l,i=new Set;function s(n){return i.add(n),()=>{i.delete(n)}}async function c(){try{o=await p("/api/config");for(let n of i)n();return o}catch{}}async function xt(){return c()}function R(){return f.useSyncExternalStore(s,()=>o)}
|
|
2
|
+
export{t,xt,R};
|
package/dist/index.html
CHANGED
|
@@ -55,11 +55,11 @@
|
|
|
55
55
|
<link rel="modulepreload" href="/vendor/react/19.2.4/production/react-dom-client.js" />
|
|
56
56
|
<link rel="modulepreload" href="/vendor/react/19.2.4/production/_impl/react-dom-client.js" />
|
|
57
57
|
|
|
58
|
-
<link rel="stylesheet" crossorigin href="/chunk-
|
|
58
|
+
<link rel="stylesheet" crossorigin href="/chunk-cekekc3f.css"><script type="module" crossorigin src="/chunk-s5s1vzdw.js"></script></head>
|
|
59
59
|
<body>
|
|
60
60
|
<div id="root"></div>
|
|
61
61
|
|
|
62
|
-
<script type="module">
|
|
62
|
+
<script id="moi-start" type="module">
|
|
63
63
|
const [react, jsxRuntime, jsxDevRuntime, reactDom, reactDomClient] = await Promise.all([
|
|
64
64
|
import('react'),
|
|
65
65
|
import('react/jsx-runtime'),
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "moi-computer",
|
|
3
|
-
"version": "0.13.0",
|
|
3
|
+
"version": "0.13.1-next.0",
|
|
4
4
|
"description": "Local AI workspace powered by the Claude Agent SDK, Bun, React, and Tailwind. Requires Bun.",
|
|
5
5
|
"license": "Elastic-2.0",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"homepage": "https://github.com/
|
|
7
|
+
"homepage": "https://github.com/moi-computer/moi#readme",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "git+https://github.com/
|
|
10
|
+
"url": "git+https://github.com/moi-computer/moi.git"
|
|
11
11
|
},
|
|
12
12
|
"bugs": {
|
|
13
|
-
"url": "https://github.com/
|
|
13
|
+
"url": "https://github.com/moi-computer/moi/issues"
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
16
16
|
"ai",
|
|
@@ -68,6 +68,7 @@
|
|
|
68
68
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
69
69
|
"@tabler/icons-react": "^3.46.0",
|
|
70
70
|
"@tailwindcss/typography": "^0.5.20",
|
|
71
|
+
"@tanstack/query-core": "5.102.8",
|
|
71
72
|
"@tanstack/react-query": "^5.102.8",
|
|
72
73
|
"@tldraw/store": "5.2.3",
|
|
73
74
|
"@tldraw/tlschema": "5.2.3",
|
package/server/app-config.ts
CHANGED
|
@@ -48,7 +48,7 @@ export type CloudflareAccessConfig = {
|
|
|
48
48
|
|
|
49
49
|
const DEFAULTS: AppConfig = {
|
|
50
50
|
environment: 'local',
|
|
51
|
-
//
|
|
51
|
+
// Experimental; deployments opt in explicitly.
|
|
52
52
|
collab: false,
|
|
53
53
|
demo: false,
|
|
54
54
|
demoInstallUrl: 'https://moi.computer',
|
|
@@ -198,6 +198,7 @@ function fileValues(raw: Record<string, unknown>): Partial<AppConfig> {
|
|
|
198
198
|
const out: Partial<AppConfig> = {}
|
|
199
199
|
const environment = parseEnvironment(raw.environment)
|
|
200
200
|
if (environment !== undefined) out.environment = environment
|
|
201
|
+
if (typeof raw.collab === 'boolean') out.collab = raw.collab
|
|
201
202
|
if (raw.demo !== undefined) {
|
|
202
203
|
if (typeof raw.demo === 'boolean') out.demo = raw.demo
|
|
203
204
|
else warn('ignoring "demo" — expected a boolean')
|
|
@@ -225,6 +226,7 @@ export function loadAppConfig(
|
|
|
225
226
|
const fromEnv: Partial<AppConfig> = {
|
|
226
227
|
environment: parseEnvironment(env.MOI_ENVIRONMENT),
|
|
227
228
|
demo: parseBool(env.MOI_DEMO),
|
|
229
|
+
collab: parseBool(env.MOI_COLLAB),
|
|
228
230
|
demoInstallUrl: parseString(env.MOI_DEMO_INSTALL_URL)
|
|
229
231
|
}
|
|
230
232
|
const merged = { ...DEFAULTS, ...fromFile }
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { getCurrentUser, getDirectory, publishUsers } from '@/client/features/collab/host-state'
|
|
2
|
-
import type { CloudSession, CloudTeam } from './api'
|
|
3
|
-
|
|
4
|
-
// The session identifies the viewer. Keep the injected directory until the team
|
|
5
|
-
// request resolves, and preserve known avatar and color information by user id.
|
|
6
|
-
export function syncCloudIdentity(session: CloudSession, team?: CloudTeam): void {
|
|
7
|
-
if (!session || session.user.isAnonymous) {
|
|
8
|
-
publishUsers({ users: [] })
|
|
9
|
-
return
|
|
10
|
-
}
|
|
11
|
-
const { id, name, email } = session.user
|
|
12
|
-
const sameAccount = getCurrentUser()?.id === id
|
|
13
|
-
const known = new Map((getDirectory() ?? []).map(user => [user.id, user]))
|
|
14
|
-
const users =
|
|
15
|
-
team?.members.map(user => ({
|
|
16
|
-
...known.get(user.userId),
|
|
17
|
-
id: user.userId,
|
|
18
|
-
name: user.name,
|
|
19
|
-
email: user.email
|
|
20
|
-
})) ?? (sameAccount ? [...known.values()] : [])
|
|
21
|
-
const profile = { ...known.get(id), id, name, email }
|
|
22
|
-
publishUsers({ me: id, users: [...users.filter(user => user.id !== id), profile] })
|
|
23
|
-
}
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
import { useState, useSyncExternalStore } from 'react'
|
|
2
|
-
import { IconX } from '@tabler/icons-react'
|
|
3
|
-
import { useIsMutating, useMutation, useQueryClient } from '@tanstack/react-query'
|
|
4
|
-
import { Field, FieldLabel } from '@/ui-components/field'
|
|
5
|
-
import { Button } from '@/client/components/ui/button'
|
|
6
|
-
import { Input } from '@/client/components/ui/input'
|
|
7
|
-
import { Skeleton } from '@/client/components/ui/skeleton'
|
|
8
|
-
import { toast } from '@/client/components/ui/toast'
|
|
9
|
-
import { User } from '@/client/features/collab/components/user'
|
|
10
|
-
import {
|
|
11
|
-
getDirectory,
|
|
12
|
-
normalizeUserProfile,
|
|
13
|
-
subscribeDirectoryStore
|
|
14
|
-
} from '@/client/features/collab/host-state'
|
|
15
|
-
import { useAccount } from '../account/account-provider'
|
|
16
|
-
import { SettingsSection } from './settings-section'
|
|
17
|
-
import {
|
|
18
|
-
accountKeys,
|
|
19
|
-
CloudApiError,
|
|
20
|
-
cancelInvitation,
|
|
21
|
-
inviteMember,
|
|
22
|
-
removeMember
|
|
23
|
-
} from '../account/api'
|
|
24
|
-
import type { CloudSession, TeamMember } from '../account/api'
|
|
25
|
-
|
|
26
|
-
export function UsersSettings() {
|
|
27
|
-
const { team, removingMemberIds, setRemovingMemberIds } = useAccount()
|
|
28
|
-
const directory = useSyncExternalStore(subscribeDirectoryStore, getDirectory, getDirectory)
|
|
29
|
-
const qc = useQueryClient()
|
|
30
|
-
const [email, setEmail] = useState('')
|
|
31
|
-
const mutation = useMutation({
|
|
32
|
-
mutationKey: accountKeys.team,
|
|
33
|
-
mutationFn: (action: () => Promise<unknown>) => action(),
|
|
34
|
-
onSuccess: () => qc.invalidateQueries({ queryKey: accountKeys.team }),
|
|
35
|
-
onError: error => {
|
|
36
|
-
toast.add({ title: 'Couldn’t update users', description: error.message, type: 'error' })
|
|
37
|
-
if (error instanceof CloudApiError && error.status === 401)
|
|
38
|
-
void qc.invalidateQueries({ queryKey: accountKeys.session })
|
|
39
|
-
}
|
|
40
|
-
})
|
|
41
|
-
const pending = useIsMutating({ mutationKey: accountKeys.team }) > 0
|
|
42
|
-
|
|
43
|
-
function act(action: () => Promise<unknown>) {
|
|
44
|
-
if (!pending) mutation.mutate(action)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function remove(member: TeamMember) {
|
|
48
|
-
const userId = qc.getQueryData<CloudSession>(accountKeys.session)?.user.id
|
|
49
|
-
const restore = () => setRemovingMemberIds(ids => ids.filter(id => id !== member.id))
|
|
50
|
-
let undone = false
|
|
51
|
-
setRemovingMemberIds(ids => [...ids, member.id])
|
|
52
|
-
// Keep access intact until the toast closes, so Undo needs no restore API.
|
|
53
|
-
const id = toast.add({
|
|
54
|
-
title: `${member.name.trim() || member.email} removed`,
|
|
55
|
-
timeout: 5000,
|
|
56
|
-
onClose: () => {
|
|
57
|
-
if (undone || qc.getQueryData<CloudSession>(accountKeys.session)?.user.id !== userId) {
|
|
58
|
-
restore()
|
|
59
|
-
return
|
|
60
|
-
}
|
|
61
|
-
void mutation.mutateAsync(() => removeMember(member.id)).then(restore, restore)
|
|
62
|
-
},
|
|
63
|
-
actionProps: {
|
|
64
|
-
children: 'Undo',
|
|
65
|
-
onClick: () => {
|
|
66
|
-
undone = true
|
|
67
|
-
toast.close(id)
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
})
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (team.isPending)
|
|
74
|
-
return (
|
|
75
|
-
<SettingsSection title="Users">
|
|
76
|
-
<div className="flex flex-col gap-4" aria-label="Loading users">
|
|
77
|
-
<Skeleton className="h-6 w-32" />
|
|
78
|
-
<Skeleton className="h-24 w-full" />
|
|
79
|
-
</div>
|
|
80
|
-
</SettingsSection>
|
|
81
|
-
)
|
|
82
|
-
if (team.isError)
|
|
83
|
-
return (
|
|
84
|
-
<SettingsSection title="Users">
|
|
85
|
-
<div className="flex flex-col items-start gap-3">
|
|
86
|
-
<p role="alert">{team.error.message}</p>
|
|
87
|
-
<Button variant="outline" onClick={() => void team.refetch()}>
|
|
88
|
-
Try again
|
|
89
|
-
</Button>
|
|
90
|
-
</div>
|
|
91
|
-
</SettingsSection>
|
|
92
|
-
)
|
|
93
|
-
const { members, invitations, role } = team.data
|
|
94
|
-
const owner = role === 'owner'
|
|
95
|
-
|
|
96
|
-
return (
|
|
97
|
-
<SettingsSection title="Users">
|
|
98
|
-
<ul className="flex flex-col gap-4">
|
|
99
|
-
{members
|
|
100
|
-
.filter(member => !removingMemberIds.includes(member.id))
|
|
101
|
-
.map(member => (
|
|
102
|
-
<li key={member.id} className="flex items-center gap-3">
|
|
103
|
-
<User
|
|
104
|
-
profile={normalizeUserProfile({
|
|
105
|
-
...directory?.find(user => user.id === member.userId),
|
|
106
|
-
id: member.userId,
|
|
107
|
-
name: member.name,
|
|
108
|
-
email: member.email
|
|
109
|
-
})}
|
|
110
|
-
size="sm"
|
|
111
|
-
showYouLabel={member.me}
|
|
112
|
-
description={member.name?.trim() ? member.email : undefined}
|
|
113
|
-
className="flex-1"
|
|
114
|
-
/>
|
|
115
|
-
<span className="text-xs text-muted-foreground">
|
|
116
|
-
{member.role === 'owner' ? 'Owner' : 'Member'}
|
|
117
|
-
</span>
|
|
118
|
-
{owner && !member.me && (
|
|
119
|
-
<Button
|
|
120
|
-
variant="ghost"
|
|
121
|
-
size="sm"
|
|
122
|
-
disabled={pending}
|
|
123
|
-
aria-label={`Remove ${member.email}`}
|
|
124
|
-
onClick={() => remove(member)}
|
|
125
|
-
>
|
|
126
|
-
Remove
|
|
127
|
-
</Button>
|
|
128
|
-
)}
|
|
129
|
-
</li>
|
|
130
|
-
))}
|
|
131
|
-
{owner &&
|
|
132
|
-
invitations.map(invitation => (
|
|
133
|
-
<li
|
|
134
|
-
key={`invitation-${invitation.id}`}
|
|
135
|
-
className="group/invitation flex items-center gap-3"
|
|
136
|
-
tabIndex={0}
|
|
137
|
-
>
|
|
138
|
-
<User
|
|
139
|
-
profile={normalizeUserProfile({ id: invitation.id, email: invitation.email })}
|
|
140
|
-
size="sm"
|
|
141
|
-
description={`Invitation expires ${new Date(invitation.expiresAt).toLocaleDateString()}`}
|
|
142
|
-
className="flex-1 text-muted-foreground [&_[data-slot=avatar]]:opacity-50"
|
|
143
|
-
/>
|
|
144
|
-
<div className="flex shrink-0 items-center gap-2">
|
|
145
|
-
<span className="text-xs text-muted-foreground [@media(hover:hover)]:group-focus-within/invitation:hidden [@media(hover:hover)]:group-hover/invitation:hidden">
|
|
146
|
-
Pending invite
|
|
147
|
-
</span>
|
|
148
|
-
<Button
|
|
149
|
-
variant="ghost"
|
|
150
|
-
size="icon-sm"
|
|
151
|
-
className="text-muted-foreground transition-none group-focus-within/invitation:inline-flex group-hover/invitation:inline-flex [@media(hover:hover)]:hidden"
|
|
152
|
-
disabled={pending}
|
|
153
|
-
aria-label={`Cancel invitation for ${invitation.email}`}
|
|
154
|
-
onClick={() => act(() => cancelInvitation(invitation.id))}
|
|
155
|
-
>
|
|
156
|
-
<IconX stroke={1.75} />
|
|
157
|
-
</Button>
|
|
158
|
-
</div>
|
|
159
|
-
</li>
|
|
160
|
-
))}
|
|
161
|
-
</ul>
|
|
162
|
-
{owner && (
|
|
163
|
-
<form
|
|
164
|
-
className="flex items-end gap-2"
|
|
165
|
-
onSubmit={event => {
|
|
166
|
-
event.preventDefault()
|
|
167
|
-
const value = email.trim()
|
|
168
|
-
if (!value) return
|
|
169
|
-
act(async () => {
|
|
170
|
-
await inviteMember(value)
|
|
171
|
-
setEmail('')
|
|
172
|
-
})
|
|
173
|
-
}}
|
|
174
|
-
>
|
|
175
|
-
<Field className="min-w-0 flex-1">
|
|
176
|
-
<FieldLabel htmlFor="invite-email">Invite someone</FieldLabel>
|
|
177
|
-
<Input
|
|
178
|
-
id="invite-email"
|
|
179
|
-
type="email"
|
|
180
|
-
required
|
|
181
|
-
autoComplete="off"
|
|
182
|
-
placeholder="Email"
|
|
183
|
-
value={email}
|
|
184
|
-
disabled={pending}
|
|
185
|
-
onChange={event => setEmail(event.target.value)}
|
|
186
|
-
/>
|
|
187
|
-
</Field>
|
|
188
|
-
<Button type="submit" disabled={pending}>
|
|
189
|
-
Invite
|
|
190
|
-
</Button>
|
|
191
|
-
</form>
|
|
192
|
-
)}
|
|
193
|
-
</SettingsSection>
|
|
194
|
-
)
|
|
195
|
-
}
|