moi-computer 0.12.1-next.2 → 0.12.1-next.3
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/app/app-router.tsx +2 -0
- package/client/app/routes/settings-route.tsx +10 -0
- package/client/app/shell/sidebar-layout.tsx +34 -53
- package/client/features/account/account-menu.tsx +96 -0
- package/client/features/account/account-provider.tsx +142 -0
- package/client/features/account/account-test-utils.tsx +293 -0
- package/client/features/account/api.ts +142 -0
- package/client/features/account/identity.ts +23 -0
- package/client/features/collab/applet-api.ts +15 -14
- package/client/features/collab/components/cursors.tsx +61 -24
- package/client/features/collab/components/presence-avatars.tsx +25 -12
- package/client/features/collab/components/presence-frame.tsx +20 -24
- package/client/features/collab/components/presence-group.tsx +15 -7
- package/client/features/collab/components/user-avatar-group.tsx +21 -8
- package/client/features/collab/components/user-avatar.tsx +38 -7
- package/client/features/collab/components/user.tsx +31 -12
- package/client/features/collab/users.ts +0 -5
- package/client/features/collab/workspace-users-menu.tsx +3 -3
- package/client/features/dev/collab/collab-playground.tsx +7 -7
- package/client/features/dev/collab/local-user-settings.tsx +7 -53
- package/client/features/settings/connectors-settings.tsx +3 -3
- package/client/features/settings/environment-settings.tsx +3 -3
- package/client/features/settings/general-settings.tsx +1 -1
- package/client/features/settings/profile-settings.tsx +95 -0
- package/client/features/settings/settings-page.tsx +44 -0
- package/client/features/settings/settings-section.tsx +26 -0
- package/client/features/settings/users-settings.tsx +195 -0
- package/client/features/update/update-control.tsx +1 -1
- package/client/features/workspace/add/create-workspace-dialog.tsx +5 -2
- package/client/lib/user-display-name.ts +6 -0
- package/client/main.tsx +4 -1
- package/dist/{chunk-vt6zybej.js → chunk-20ynagd4.js} +2 -2
- package/dist/chunk-42tde9a6.js +1 -0
- package/dist/{chunk-hmka9rt5.js → chunk-9w543s0r.js} +2 -2
- package/dist/{chunk-y8nbwp21.js → chunk-a5372n61.js} +2 -2
- package/dist/chunk-aja9y1vn.js +68 -0
- package/dist/chunk-fvcvrh3d.css +1 -0
- package/dist/{chunk-ysfdcew7.js → chunk-gtfjw3nx.js} +1 -1
- package/dist/{chunk-hvh9f5h0.js → chunk-j39y2aky.js} +1 -1
- package/dist/chunk-pja30km3.js +1 -0
- package/dist/{chunk-d7cbm65e.js → chunk-rm894bc2.js} +1 -1
- package/dist/chunk-tevvtfbk.js +10 -0
- package/dist/{chunk-am4agx6v.js → chunk-tgt9zd0r.js} +1 -1
- package/dist/chunk-tv5k5z00.js +1 -0
- package/dist/chunk-zq2ae5dx.js +2 -0
- package/dist/index.html +1 -1
- package/lib/types.ts +1 -1
- package/package.json +1 -1
- package/server/api/index.ts +2 -6
- package/server/app-config.ts +7 -0
- package/server/web.ts +1 -0
- package/server/workspaces/init.ts +0 -10
- package/server/workspaces/registry.ts +31 -9
- package/dist/chunk-00rh9df4.js +0 -2
- package/dist/chunk-4nh7y1hq.css +0 -1
- package/dist/chunk-hbpdv7vd.js +0 -1
- package/dist/chunk-mjjregkn.js +0 -10
- package/dist/chunk-rt30jbcm.js +0 -1
- package/dist/chunk-wbkwf6cc.js +0 -68
- package/dist/chunk-xjyfyz64.js +0 -1
|
@@ -0,0 +1,195 @@
|
|
|
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
|
+
}
|
|
@@ -100,6 +100,7 @@ export function CreateWorkspaceDialog({ trigger }: CreateWorkspaceDialogProps) {
|
|
|
100
100
|
{step === 'name' ? (
|
|
101
101
|
<WorkspaceNameStep
|
|
102
102
|
name={name}
|
|
103
|
+
showExistingFolder={appConfig.environment === 'local'}
|
|
103
104
|
validationError={nameError}
|
|
104
105
|
onNameChange={setName}
|
|
105
106
|
onSubmit={continueToAgent}
|
|
@@ -131,6 +132,7 @@ export function CreateWorkspaceDialog({ trigger }: CreateWorkspaceDialogProps) {
|
|
|
131
132
|
|
|
132
133
|
type WorkspaceNameStepProps = {
|
|
133
134
|
name: string
|
|
135
|
+
showExistingFolder: boolean
|
|
134
136
|
validationError: string | null
|
|
135
137
|
onNameChange: (name: string) => void
|
|
136
138
|
onSubmit: () => void
|
|
@@ -138,6 +140,7 @@ type WorkspaceNameStepProps = {
|
|
|
138
140
|
|
|
139
141
|
function WorkspaceNameStep({
|
|
140
142
|
name,
|
|
143
|
+
showExistingFolder,
|
|
141
144
|
validationError,
|
|
142
145
|
onNameChange,
|
|
143
146
|
onSubmit
|
|
@@ -180,9 +183,9 @@ function WorkspaceNameStep({
|
|
|
180
183
|
</div>
|
|
181
184
|
|
|
182
185
|
<div className="flex items-center justify-end gap-2">
|
|
183
|
-
<ExistingFolderButton />
|
|
186
|
+
{showExistingFolder && <ExistingFolderButton />}
|
|
184
187
|
<Button type="submit" disabled={!name.trim() || Boolean(validationError)}>
|
|
185
|
-
|
|
188
|
+
Continue
|
|
186
189
|
</Button>
|
|
187
190
|
</div>
|
|
188
191
|
</form>
|
package/client/main.tsx
CHANGED
|
@@ -6,6 +6,7 @@ import { Toaster } from '@/client/components/ui/toast'
|
|
|
6
6
|
import { TooltipProvider } from '@/client/components/ui/tooltip'
|
|
7
7
|
import { installAppletErrorHook } from '@/client/features/applets/applet-log'
|
|
8
8
|
import { initConnection } from '@/client/features/chat/connection/chat-connection'
|
|
9
|
+
import { AccountProvider } from '@/client/features/account/account-provider'
|
|
9
10
|
import { AppProvider } from './app/app-provider'
|
|
10
11
|
import { AppRouter } from './app/app-router'
|
|
11
12
|
|
|
@@ -27,7 +28,9 @@ export function mount(el: HTMLElement) {
|
|
|
27
28
|
<AppProvider>
|
|
28
29
|
<TooltipProvider>
|
|
29
30
|
<Router>
|
|
30
|
-
<
|
|
31
|
+
<AccountProvider>
|
|
32
|
+
<AppRouter />
|
|
33
|
+
</AccountProvider>
|
|
31
34
|
</Router>
|
|
32
35
|
<Toaster />
|
|
33
36
|
</TooltipProvider>
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
2
|
-
export{A as
|
|
1
|
+
import{Oc as r}from"/chunk-zq2ae5dx.js";import{cd as E}from"/chunk-tgt9zd0r.js";import{fd as x}from"/chunk-rm894bc2.js";var p=x(r(),1);var a={collab:!1},F=Object.keys(a);var f={environment:"local",demo:!1,experimental:{...a},demoInstallUrl:"https://moi.computer"},o=f,t=new Set;function y(e){return t.add(e),()=>{t.delete(e)}}async function m(){try{o=await E("/api/config");for(let e of t)e();return o}catch{}}async function A(){return m()}function L(){return p.useSyncExternalStore(y,()=>o)}
|
|
2
|
+
export{A as Mc,L as Nc};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a}from"/chunk-pcnahct1.js";import"/chunk-rm894bc2.js";export{a as sanitizeSvg};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var T=["pink","orange","amber","lime","emerald","cyan","blue","violet"];function _(A){return typeof A==="string"&&T.includes(A)}function V(A){let C=2166136261;for(let f=0;f<A.length;f++)C^=A.charCodeAt(f),C=Math.imul(C,16777619);return T[(C>>>0)%T.length]??T[0]}var o=1;var D=8192,H=320;function Q(A){return typeof A==="object"&&A!==null&&!Array.isArray(A)}function y(A,C=256){return typeof A==="string"&&A.length>0&&!A.includes("\x00")&&new TextEncoder().encode(A).length<=C}function j(A){return Q(A)&&y(A.id,240)&&A.id.trim().length>0&&(A.name===void 0||y(A.name)&&A.name.trim().length>0)&&_(A.color)&&(A.avatar===void 0||y(A.avatar,D))&&(A.email===void 0||y(A.email,H))}var W=["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 I(A,C){let f=A.filter((n)=>n!==C);return f[Math.floor(Math.random()*f.length)]??A[0]}function Z(A){return{name:I(W,A?.name),color:I(T,A?.color)}}function $(A,C){let f=C.name.trim();return{id:A,...f?{name:f}:{},color:C.color}}function G(){return $(`local-${crypto.randomUUID().slice(0,8)}`,Z())}var k="moi:local-profile",L=Object.freeze([]),B,g,Y,p=!1,w=new Set,X=new Set;function J(A,C){return JSON.stringify(A)===JSON.stringify(C)}function N(A){if(!A||typeof A.id!=="string"||!A.id.trim())throw Error("A user profile needs an id.");if(A.name!==void 0&&typeof A.name!=="string")throw Error("A user profile name must be a string when provided.");if(A.color!==void 0&&!_(A.color))throw Error("A user profile color must be one of the user palette names.");let C=A.id.trim(),f=A.name?.trim(),n={id:C,...f?{name:f}:{},color:A.color??V(C),...A.avatar!==void 0?{avatar:A.avatar}:{},...A.email!==void 0?{email:A.email}:{}};if(!j(n))throw Error("Invalid user profile.");return Object.freeze(n)}function b(A){if(!Array.isArray(A))throw Error("Users must be an array.");let C=new Set,f=A.map((n)=>{let M=N(n);if(C.has(M.id))throw Error("Users must have unique ids.");return C.add(M.id),M});return Object.freeze(f)}function F(A){if(!A||typeof A!=="object")throw Error("Users must be published as an object.");let C=b(A.users),f;if(A.me!==void 0&&A.me!==null){if(typeof A.me!=="string")throw Error("The current user id must be a string.");let M=A.me.trim();if(f=C.find((q)=>q.id===M),!f)throw Error("The current user must be listed in users.")}let n=g!=="external"||!J(B,f);if(g="external",n)B=f;if(Y=f?C:L,n)w.forEach((M)=>M());X.forEach((M)=>M())}function i(){return Y}function d(A){return X.add(A),()=>{X.delete(A)}}function c(){return B}function U(A){return w.add(A),()=>{w.delete(A)}}function a({provider:A,profile:C}){if(g==="external")return;if(A===void 0){if(g===void 0||g==="local")return;g=void 0,B=void 0}else{let f=C===void 0?void 0:N(C);if(g===A&&J(B,f))return;g=A,B=f}w.forEach((f)=>f())}function K(){try{localStorage.setItem(k,JSON.stringify(B))}catch{}}function E(A){if(g!==void 0&&g!=="local")return;let C=N(A);g="local",B=C,K(),w.forEach((f)=>f())}function
|
|
2
|
-
export{o as
|
|
1
|
+
var T=["pink","orange","amber","lime","emerald","cyan","blue","violet"];function _(A){return typeof A==="string"&&T.includes(A)}function V(A){let C=2166136261;for(let f=0;f<A.length;f++)C^=A.charCodeAt(f),C=Math.imul(C,16777619);return T[(C>>>0)%T.length]??T[0]}var o=1;var D=8192,H=320;function Q(A){return typeof A==="object"&&A!==null&&!Array.isArray(A)}function y(A,C=256){return typeof A==="string"&&A.length>0&&!A.includes("\x00")&&new TextEncoder().encode(A).length<=C}function j(A){return Q(A)&&y(A.id,240)&&A.id.trim().length>0&&(A.name===void 0||y(A.name)&&A.name.trim().length>0)&&_(A.color)&&(A.avatar===void 0||y(A.avatar,D))&&(A.email===void 0||y(A.email,H))}var W=["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 I(A,C){let f=A.filter((n)=>n!==C);return f[Math.floor(Math.random()*f.length)]??A[0]}function Z(A){return{name:I(W,A?.name),color:I(T,A?.color)}}function $(A,C){let f=C.name.trim();return{id:A,...f?{name:f}:{},color:C.color}}function G(){return $(`local-${crypto.randomUUID().slice(0,8)}`,Z())}var k="moi:local-profile",L=Object.freeze([]),B,g,Y,p=!1,w=new Set,X=new Set;function J(A,C){return JSON.stringify(A)===JSON.stringify(C)}function N(A){if(!A||typeof A.id!=="string"||!A.id.trim())throw Error("A user profile needs an id.");if(A.name!==void 0&&typeof A.name!=="string")throw Error("A user profile name must be a string when provided.");if(A.color!==void 0&&!_(A.color))throw Error("A user profile color must be one of the user palette names.");let C=A.id.trim(),f=A.name?.trim(),n={id:C,...f?{name:f}:{},color:A.color??V(C),...A.avatar!==void 0?{avatar:A.avatar}:{},...A.email!==void 0?{email:A.email}:{}};if(!j(n))throw Error("Invalid user profile.");return Object.freeze(n)}function b(A){if(!Array.isArray(A))throw Error("Users must be an array.");let C=new Set,f=A.map((n)=>{let M=N(n);if(C.has(M.id))throw Error("Users must have unique ids.");return C.add(M.id),M});return Object.freeze(f)}function F(A){if(!A||typeof A!=="object")throw Error("Users must be published as an object.");let C=b(A.users),f;if(A.me!==void 0&&A.me!==null){if(typeof A.me!=="string")throw Error("The current user id must be a string.");let M=A.me.trim();if(f=C.find((q)=>q.id===M),!f)throw Error("The current user must be listed in users.")}let n=g!=="external"||!J(B,f);if(g="external",n)B=f;if(Y=f?C:L,n)w.forEach((M)=>M());X.forEach((M)=>M())}function i(){return Y}function d(A){return X.add(A),()=>{X.delete(A)}}function c(){return B}function U(A){return w.add(A),()=>{w.delete(A)}}function a(){return g}function u({provider:A,profile:C}){if(g==="external")return;if(A===void 0){if(g===void 0||g==="local")return;g=void 0,B=void 0}else{let f=C===void 0?void 0:N(C);if(g===A&&J(B,f))return;g=A,B=f}w.forEach((f)=>f())}function K(){try{localStorage.setItem(k,JSON.stringify(B))}catch{}}function E(A){if(g!==void 0&&g!=="local")return;let C=N(A);g="local",B=C,K(),w.forEach((f)=>f())}function v(A,C){if(!A||!C||C.provider!==void 0||g!==void 0)return;try{let f=localStorage.getItem(k);if(f){E(JSON.parse(f));return}}catch{}E(G())}function s(){if(typeof window>"u"||p)return;p=!0;let A=window;A.moi??={};let C={publishUsers:F};A.moi.collab=C}function O(A){if(A.key!==k||!A.newValue||g!=="local")return;try{let C=N(JSON.parse(A.newValue));if(J(C,B))return;B=C,w.forEach((f)=>f())}catch{}}function l(){return window.addEventListener("storage",O),()=>window.removeEventListener("storage",O)}
|
|
2
|
+
export{o as Pc,Q as Qc,j as Rc,N as Sc,F as Tc,i as Uc,d as Vc,c as Wc,U as Xc,a as Yc,u as Zc,E as _c,v as $c,s as ad,l as bd};
|