moi-computer 0.12.1-next.1 → 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/AGENTS.md +3 -2
- package/client/api/app-config.ts +3 -9
- package/client/api/workspace-keys.ts +2 -1
- package/client/app/app-provider.tsx +25 -0
- package/client/app/app-router.tsx +2 -0
- package/client/app/routes/settings-route.tsx +10 -0
- package/client/app/routes/workspace-route.tsx +4 -0
- package/client/app/shell/sidebar-layout.tsx +38 -51
- package/client/dev/index.html +5 -5
- 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/applets/api.ts +1 -1
- package/client/features/chat/connection/chat-frames.ts +2 -2
- package/client/features/chat/sessions/api.ts +1 -1
- package/client/features/chat/use-chat.ts +1 -1
- 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/host-state.ts +24 -7
- package/client/features/collab/local-user.ts +1 -1
- package/client/features/collab/proxy-user.ts +4 -9
- package/client/features/collab/users.ts +0 -5
- package/client/features/collab/workspace-users-menu.tsx +3 -3
- package/client/features/demo/demo-dialog.tsx +25 -79
- package/client/features/dev/collab/collab-playground.tsx +7 -7
- package/client/features/dev/collab/local-user-settings.tsx +7 -53
- package/client/features/dev/workspace-setup-preview.tsx +43 -16
- package/client/features/harness/device-login-steps.tsx +2 -2
- package/client/features/home/api.ts +29 -9
- package/client/features/home/home-page.tsx +7 -4
- package/client/features/scratchpad/scratchpad.tsx +3 -6
- package/client/features/settings/api.ts +14 -8
- 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/features/workspace/api.ts +12 -16
- package/client/features/workspace/setup/workspace-login-state.tsx +4 -4
- package/client/features/workspace/setup/workspace-setup.tsx +2 -1
- package/client/features/workspace/workspace-content.tsx +12 -52
- package/client/features/workspace/workspace-frame.tsx +76 -0
- package/client/features/workspace/workspace-layout-context.tsx +2 -0
- package/client/features/workspace/workspace-pending-screen.tsx +26 -0
- package/client/features/workspace/workspace-screen.tsx +3 -3
- package/client/index.html +28 -9
- package/client/index.tsx +7 -2
- package/client/lib/browser-tab-id.ts +4 -0
- package/client/lib/user-display-name.ts +6 -0
- package/client/main.tsx +12 -6
- package/client/runtime/app-context.ts +20 -0
- package/client/runtime/use-workspace-events.ts +29 -153
- package/client/runtime/workspace-events.ts +151 -0
- package/dist/chunk-20ynagd4.js +2 -0
- package/dist/chunk-42tde9a6.js +1 -0
- package/dist/chunk-9w543s0r.js +2 -0
- package/dist/{chunk-q0gbdts4.js → chunk-a5372n61.js} +71 -71
- package/dist/chunk-aja9y1vn.js +68 -0
- package/dist/chunk-fvcvrh3d.css +1 -0
- package/dist/chunk-gtfjw3nx.js +1 -0
- 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-jvyvwwv3.js → chunk-tgt9zd0r.js} +1 -1
- package/dist/chunk-tv5k5z00.js +1 -0
- package/dist/chunk-zq2ae5dx.js +2 -0
- package/dist/index.html +29 -10
- package/lib/ids.ts +2 -2
- package/lib/types.ts +1 -1
- package/package.json +1 -1
- package/server/api/index.ts +43 -28
- package/server/app-config.ts +7 -0
- package/server/applets/thumbnails.ts +8 -5
- package/server/harness/codex/thread-list.ts +4 -0
- package/server/static.ts +4 -2
- package/server/vendor.ts +23 -30
- package/server/web.ts +4 -2
- package/server/workspaces/init.ts +0 -10
- package/server/workspaces/layout.ts +11 -6
- package/server/workspaces/registry.ts +31 -9
- package/dist/chunk-08ndj2rg.js +0 -2
- package/dist/chunk-2x040tmg.js +0 -68
- package/dist/chunk-3smxq0ts.js +0 -1
- package/dist/chunk-68ch5hs8.js +0 -2
- package/dist/chunk-9vg3xa81.js +0 -2
- package/dist/chunk-c2p00p9j.css +0 -1
- package/dist/chunk-cs833y9j.js +0 -1
- package/dist/chunk-nwevqe86.js +0 -10
- package/dist/chunk-rt30jbcm.js +0 -1
- package/dist/chunk-y5y3kj67.js +0 -1
- /package/client/vendor/react/{development → 19.2.4/development}/_impl/react-dom-client.js +0 -0
- /package/client/vendor/react/{development → 19.2.4/development}/_impl/react-dom.js +0 -0
- /package/client/vendor/react/{development → 19.2.4/development}/_impl/react-jsx-dev-runtime.js +0 -0
- /package/client/vendor/react/{development → 19.2.4/development}/_impl/react-jsx-runtime.js +0 -0
- /package/client/vendor/react/{development → 19.2.4/development}/_impl/react.js +0 -0
- /package/client/vendor/react/{development → 19.2.4/development}/react-dom-client.js +0 -0
- /package/client/vendor/react/{development → 19.2.4/development}/react-dom.js +0 -0
- /package/client/vendor/react/{development → 19.2.4/development}/react-jsx-dev-runtime.js +0 -0
- /package/client/vendor/react/{development → 19.2.4/development}/react-jsx-runtime.js +0 -0
- /package/client/vendor/react/{development → 19.2.4/development}/react.js +0 -0
- /package/client/vendor/react/{production → 19.2.4/production}/_impl/react-dom-client.js +0 -0
- /package/client/vendor/react/{production → 19.2.4/production}/_impl/react-dom.js +0 -0
- /package/client/vendor/react/{production → 19.2.4/production}/_impl/react-jsx-dev-runtime.js +0 -0
- /package/client/vendor/react/{production → 19.2.4/production}/_impl/react-jsx-runtime.js +0 -0
- /package/client/vendor/react/{production → 19.2.4/production}/_impl/react.js +0 -0
- /package/client/vendor/react/{production → 19.2.4/production}/react-dom-client.js +0 -0
- /package/client/vendor/react/{production → 19.2.4/production}/react-dom.js +0 -0
- /package/client/vendor/react/{production → 19.2.4/production}/react-jsx-dev-runtime.js +0 -0
- /package/client/vendor/react/{production → 19.2.4/production}/react-jsx-runtime.js +0 -0
- /package/client/vendor/react/{production → 19.2.4/production}/react.js +0 -0
|
@@ -1,17 +1,24 @@
|
|
|
1
|
-
import type { CursorsProps } from 'moi/collab'
|
|
1
|
+
import type { CursorsProps as CursorsContainerProps } from 'moi/collab'
|
|
2
|
+
import type { UserProfile } from '@/lib/collab/types'
|
|
2
3
|
import type { JsonValue } from 'moi'
|
|
3
4
|
import { useLayoutEffect, useRef } from 'react'
|
|
4
|
-
import type { PointerEvent, Ref, RefObject } from 'react'
|
|
5
|
+
import type { PointerEvent, ReactNode, Ref, RefObject } from 'react'
|
|
5
6
|
import { IconPointer2 } from '@tabler/icons-react'
|
|
6
7
|
|
|
7
8
|
import { cn } from '@/client/lib/cn'
|
|
8
9
|
import { Badge } from '@/ui-components/badge'
|
|
9
10
|
|
|
10
|
-
import { presenceChannels, usePresenceChannel, usePresencePublisher,
|
|
11
|
-
import { userDisplayName } from '
|
|
11
|
+
import { presenceChannels, usePresenceChannel, usePresencePublisher, useUsers } from '../hooks'
|
|
12
|
+
import { userDisplayName } from '@/client/lib/user-display-name'
|
|
12
13
|
import { hasPresence } from './presence-helpers'
|
|
13
14
|
|
|
14
|
-
type PointerPosition = {
|
|
15
|
+
export type PointerPosition = {
|
|
16
|
+
x: number
|
|
17
|
+
y: number
|
|
18
|
+
target?: string
|
|
19
|
+
targetX?: number
|
|
20
|
+
targetY?: number
|
|
21
|
+
}
|
|
15
22
|
function pointerPosition(value: JsonValue): PointerPosition | null {
|
|
16
23
|
if (!value || typeof value !== 'object' || Array.isArray(value)) return null
|
|
17
24
|
if (typeof value.x !== 'number' || typeof value.y !== 'number') return null
|
|
@@ -29,7 +36,46 @@ function pointerPosition(value: JsonValue): PointerPosition | null {
|
|
|
29
36
|
}
|
|
30
37
|
}
|
|
31
38
|
|
|
32
|
-
export function
|
|
39
|
+
export function CursorsContainer({ id = 'default', ...props }: CursorsContainerProps) {
|
|
40
|
+
const channel = presenceChannels.cursor(id)
|
|
41
|
+
const cursors = usePresenceChannel<JsonValue>(channel)
|
|
42
|
+
const publish = usePresencePublisher<JsonValue>(channel, null, hasPresence)
|
|
43
|
+
const byConnection = new Map<string, { id: string; point: PointerPosition }>()
|
|
44
|
+
for (const { connectionId, userId, value } of cursors) {
|
|
45
|
+
const point = pointerPosition(value)
|
|
46
|
+
if (point) byConnection.set(connectionId, { id: userId, point })
|
|
47
|
+
}
|
|
48
|
+
const entries = [...byConnection]
|
|
49
|
+
const profiles = useUsers(entries.map(([, cursor]) => cursor.id))
|
|
50
|
+
return (
|
|
51
|
+
<Cursors
|
|
52
|
+
{...props}
|
|
53
|
+
id={id}
|
|
54
|
+
onPositionChange={publish}
|
|
55
|
+
cursors={entries.map(([connectionId, { point }], index) => ({
|
|
56
|
+
connectionId,
|
|
57
|
+
point,
|
|
58
|
+
profile: profiles[index]
|
|
59
|
+
}))}
|
|
60
|
+
/>
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export type CursorsProps = {
|
|
65
|
+
id?: string
|
|
66
|
+
children: ReactNode
|
|
67
|
+
className?: string
|
|
68
|
+
cursors: readonly { connectionId: string; point: PointerPosition; profile?: UserProfile }[]
|
|
69
|
+
onPositionChange?: (point: PointerPosition | null) => void
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function Cursors({
|
|
73
|
+
id = 'default',
|
|
74
|
+
children,
|
|
75
|
+
className,
|
|
76
|
+
cursors,
|
|
77
|
+
onPositionChange
|
|
78
|
+
}: CursorsProps) {
|
|
33
79
|
const root = useRef<HTMLDivElement>(null)
|
|
34
80
|
const layer = useRef<HTMLDivElement>(null)
|
|
35
81
|
// Keep the overlay in the visible viewport when the cursor area itself scrolls.
|
|
@@ -44,14 +90,6 @@ export function Cursors({ id = 'default', children, className }: CursorsProps) {
|
|
|
44
90
|
element.addEventListener('scroll', position)
|
|
45
91
|
return () => element.removeEventListener('scroll', position)
|
|
46
92
|
}, [])
|
|
47
|
-
const channel = presenceChannels.cursor(id)
|
|
48
|
-
const cursors = usePresenceChannel<JsonValue>(channel)
|
|
49
|
-
const publish = usePresencePublisher<JsonValue>(channel, null, hasPresence)
|
|
50
|
-
const byConnection = new Map<string, { id: string; point: PointerPosition }>()
|
|
51
|
-
for (const { connectionId, userId, value } of cursors) {
|
|
52
|
-
const point = pointerPosition(value)
|
|
53
|
-
if (point) byConnection.set(connectionId, { id: userId, point })
|
|
54
|
-
}
|
|
55
93
|
const move = (event: PointerEvent<HTMLDivElement>) => {
|
|
56
94
|
if (event.pointerType === 'touch') return
|
|
57
95
|
const element = root.current
|
|
@@ -68,7 +106,7 @@ export function Cursors({ id = 'default', children, className }: CursorsProps) {
|
|
|
68
106
|
: null
|
|
69
107
|
const anchor = target && element.contains(target) ? target : null
|
|
70
108
|
const rect = anchor?.getBoundingClientRect()
|
|
71
|
-
|
|
109
|
+
onPositionChange?.({
|
|
72
110
|
x: event.clientX - bounds.left - element.clientLeft + element.scrollLeft,
|
|
73
111
|
y: event.clientY - bounds.top - element.clientTop + element.scrollTop,
|
|
74
112
|
...(anchor && rect
|
|
@@ -92,7 +130,7 @@ export function Cursors({ id = 'default', children, className }: CursorsProps) {
|
|
|
92
130
|
event.target instanceof Element &&
|
|
93
131
|
event.target.closest('[data-collab-cursors]') === event.currentTarget
|
|
94
132
|
)
|
|
95
|
-
|
|
133
|
+
onPositionChange?.(null)
|
|
96
134
|
}}
|
|
97
135
|
>
|
|
98
136
|
{children}
|
|
@@ -101,8 +139,8 @@ export function Cursors({ id = 'default', children, className }: CursorsProps) {
|
|
|
101
139
|
className="pointer-events-none absolute inset-0 overflow-hidden"
|
|
102
140
|
aria-hidden="true"
|
|
103
141
|
>
|
|
104
|
-
{
|
|
105
|
-
<RemoteCursor key={connectionId} root={root} point={point}
|
|
142
|
+
{cursors.map(({ connectionId, point, profile }) => (
|
|
143
|
+
<RemoteCursor key={connectionId} root={root} point={point} profile={profile} />
|
|
106
144
|
))}
|
|
107
145
|
</div>
|
|
108
146
|
</div>
|
|
@@ -112,11 +150,11 @@ export function Cursors({ id = 'default', children, className }: CursorsProps) {
|
|
|
112
150
|
type RemoteCursorProps = {
|
|
113
151
|
root: RefObject<HTMLDivElement | null>
|
|
114
152
|
point: PointerPosition
|
|
115
|
-
|
|
153
|
+
profile?: UserProfile
|
|
116
154
|
}
|
|
117
155
|
// Semantic anchors follow their own data through scrolling and reordering.
|
|
118
156
|
// A cursor on a different record's modal has no matching anchor and stays hidden.
|
|
119
|
-
function RemoteCursor({ root, point,
|
|
157
|
+
function RemoteCursor({ root, point, profile }: RemoteCursorProps) {
|
|
120
158
|
const marker = useRef<HTMLSpanElement>(null)
|
|
121
159
|
useLayoutEffect(() => {
|
|
122
160
|
const element = root.current
|
|
@@ -166,15 +204,14 @@ function RemoteCursor({ root, point, id }: RemoteCursorProps) {
|
|
|
166
204
|
window.removeEventListener('resize', reposition)
|
|
167
205
|
}
|
|
168
206
|
}, [root, point])
|
|
169
|
-
return <Cursor ref={marker}
|
|
207
|
+
return <Cursor ref={marker} profile={profile} />
|
|
170
208
|
}
|
|
171
209
|
|
|
172
210
|
type CursorProps = {
|
|
173
|
-
|
|
211
|
+
profile?: UserProfile
|
|
174
212
|
ref?: Ref<HTMLSpanElement>
|
|
175
213
|
}
|
|
176
|
-
function Cursor({
|
|
177
|
-
const user = useUser(id)
|
|
214
|
+
function Cursor({ profile: user, ref }: CursorProps) {
|
|
178
215
|
return (
|
|
179
216
|
<span
|
|
180
217
|
ref={ref}
|
|
@@ -1,47 +1,56 @@
|
|
|
1
|
-
import type { PresenceAvatarsProps } from 'moi/collab'
|
|
1
|
+
import type { PresenceAvatarsProps as PresenceAvatarsContainerProps } from 'moi/collab'
|
|
2
|
+
import type { UserProfile } from '@/lib/collab/types'
|
|
2
3
|
import { useContext } from 'react'
|
|
3
4
|
import type { HTMLAttributes, ReactNode, Ref } from 'react'
|
|
4
5
|
import { motion } from 'motion/react'
|
|
5
6
|
import { cn } from '@/client/lib/cn'
|
|
6
7
|
import { PresenceGroupContext, usePresenceTarget, useTargetPresence } from './presence-helpers'
|
|
8
|
+
import { useUsers } from '../hooks'
|
|
7
9
|
import { UserAvatar } from './user-avatar'
|
|
8
10
|
|
|
9
|
-
export function
|
|
11
|
+
export function PresenceAvatarsContainer({
|
|
12
|
+
id,
|
|
13
|
+
present,
|
|
14
|
+
align,
|
|
15
|
+
children,
|
|
16
|
+
className
|
|
17
|
+
}: PresenceAvatarsContainerProps) {
|
|
10
18
|
const target = usePresenceTarget(id)
|
|
11
19
|
const presence = useTargetPresence(target, present)
|
|
20
|
+
const profiles = useUsers(presence.users.map(user => user.id))
|
|
12
21
|
const grouped = useContext(PresenceGroupContext).length > 0
|
|
13
22
|
return (
|
|
14
|
-
<
|
|
23
|
+
<PresenceAvatars
|
|
15
24
|
{...presence.props}
|
|
16
|
-
users={presence.users}
|
|
25
|
+
users={presence.users.map((user, index) => ({ ...user, profile: profiles[index] }))}
|
|
17
26
|
// Controlled presence can occupy several targets at once; only focus moves between them.
|
|
18
27
|
animate={grouped && present === undefined}
|
|
19
28
|
align={align}
|
|
20
29
|
className={className}
|
|
21
30
|
>
|
|
22
31
|
{children}
|
|
23
|
-
</
|
|
32
|
+
</PresenceAvatars>
|
|
24
33
|
)
|
|
25
34
|
}
|
|
26
35
|
|
|
27
|
-
type
|
|
36
|
+
export type PresenceAvatarsProps = HTMLAttributes<HTMLDivElement> & {
|
|
28
37
|
ref?: Ref<HTMLDivElement>
|
|
29
|
-
users: readonly { id: string; connectionId: string }[]
|
|
38
|
+
users: readonly { id: string; connectionId: string; profile?: UserProfile }[]
|
|
30
39
|
children: ReactNode
|
|
31
40
|
animate?: boolean
|
|
32
|
-
align?:
|
|
41
|
+
align?: PresenceAvatarsContainerProps['align']
|
|
33
42
|
}
|
|
34
43
|
|
|
35
44
|
// A target owns its own gutter. Optional group-scoped layout IDs let the same
|
|
36
45
|
// user's face glide between targets without searching or guessing DOM order.
|
|
37
|
-
function
|
|
46
|
+
export function PresenceAvatars({
|
|
38
47
|
users,
|
|
39
48
|
children,
|
|
40
49
|
animate = false,
|
|
41
50
|
align = 'center',
|
|
42
51
|
className,
|
|
43
52
|
...rest
|
|
44
|
-
}:
|
|
53
|
+
}: PresenceAvatarsProps) {
|
|
45
54
|
return (
|
|
46
55
|
<div className={cn('relative pl-8', className)} {...rest}>
|
|
47
56
|
{children}
|
|
@@ -50,9 +59,13 @@ function PresenceAvatarsPrimitive({
|
|
|
50
59
|
className="pointer-events-none absolute inset-y-0 left-0 flex items-center -space-x-3 data-[align=end]:items-end data-[align=start]:items-start"
|
|
51
60
|
aria-hidden="true"
|
|
52
61
|
>
|
|
53
|
-
{users.map(({ id, connectionId }) => (
|
|
62
|
+
{users.map(({ id, connectionId, profile }) => (
|
|
54
63
|
<motion.span key={id} layoutId={animate ? `presence:${connectionId}` : undefined}>
|
|
55
|
-
<UserAvatar
|
|
64
|
+
<UserAvatar
|
|
65
|
+
profile={profile}
|
|
66
|
+
size="sm"
|
|
67
|
+
className="animate-in duration-200 zoom-in-75 fade-in"
|
|
68
|
+
/>
|
|
56
69
|
</motion.span>
|
|
57
70
|
))}
|
|
58
71
|
</div>
|
|
@@ -1,51 +1,47 @@
|
|
|
1
|
-
import type { PresenceFrameProps } from 'moi/collab'
|
|
1
|
+
import type { PresenceFrameProps as PresenceFrameContainerProps } from 'moi/collab'
|
|
2
|
+
import type { UserProfile } from '@/lib/collab/types'
|
|
2
3
|
import { useLayoutEffect, useRef } from 'react'
|
|
3
4
|
import type { HTMLAttributes, ReactNode, Ref } from 'react'
|
|
4
5
|
import { cn } from '@/client/lib/cn'
|
|
5
6
|
import type { UserColor } from '@/lib/collab/colors'
|
|
6
7
|
import { Badge } from '@/ui-components/badge'
|
|
7
8
|
import { useUsers } from '../hooks'
|
|
8
|
-
import { userDisplayName } from '
|
|
9
|
+
import { userDisplayName } from '@/client/lib/user-display-name'
|
|
9
10
|
import { usePresenceTarget, useTargetPresence } from './presence-helpers'
|
|
10
11
|
|
|
11
|
-
export function
|
|
12
|
+
export function PresenceFrameContainer({
|
|
13
|
+
id,
|
|
14
|
+
present,
|
|
15
|
+
align,
|
|
16
|
+
children,
|
|
17
|
+
className
|
|
18
|
+
}: PresenceFrameContainerProps) {
|
|
12
19
|
const target = usePresenceTarget(id)
|
|
13
20
|
const presence = useTargetPresence(target, present)
|
|
21
|
+
const users = useUsers(presence.users.map(user => user.id)).filter(user => user !== undefined)
|
|
14
22
|
return (
|
|
15
|
-
<
|
|
16
|
-
{...presence.props}
|
|
17
|
-
ids={presence.users.map(user => user.id)}
|
|
18
|
-
align={align}
|
|
19
|
-
className={className}
|
|
20
|
-
>
|
|
23
|
+
<PresenceFrame {...presence.props} users={users} align={align} className={className}>
|
|
21
24
|
{children}
|
|
22
|
-
</
|
|
25
|
+
</PresenceFrame>
|
|
23
26
|
)
|
|
24
27
|
}
|
|
25
28
|
|
|
26
|
-
type
|
|
29
|
+
export type PresenceFrameProps = HTMLAttributes<HTMLDivElement> & {
|
|
27
30
|
ref?: Ref<HTMLDivElement>
|
|
28
31
|
// Everyone at this element; the first user's color draws the frame.
|
|
29
|
-
|
|
32
|
+
users: readonly UserProfile[]
|
|
30
33
|
children: ReactNode
|
|
31
|
-
align?:
|
|
34
|
+
align?: PresenceFrameContainerProps['align']
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
// One visible element gets a frame matching its shape; other content gets one shared frame.
|
|
35
|
-
export function
|
|
36
|
-
ids,
|
|
37
|
-
align,
|
|
38
|
-
children,
|
|
39
|
-
className,
|
|
40
|
-
...rest
|
|
41
|
-
}: PresenceOutlineProps) {
|
|
42
|
-
const resolved = useUsers(ids).filter(user => user !== undefined)
|
|
38
|
+
export function PresenceFrame({ users, align, children, className, ...rest }: PresenceFrameProps) {
|
|
43
39
|
return (
|
|
44
40
|
<div className={cn('relative', className)} {...rest}>
|
|
45
41
|
{/* Keep the overlay first so showing it never changes the content's spacing. */}
|
|
46
42
|
<FrameOutline
|
|
47
|
-
names={
|
|
48
|
-
color={
|
|
43
|
+
names={users.map(userDisplayName).join(', ')}
|
|
44
|
+
color={users[0]?.color}
|
|
49
45
|
align={align}
|
|
50
46
|
/>
|
|
51
47
|
{children}
|
|
@@ -66,7 +62,7 @@ const CORNERS = [
|
|
|
66
62
|
type FrameOutlineProps = {
|
|
67
63
|
names: string
|
|
68
64
|
color: UserColor | undefined
|
|
69
|
-
align?:
|
|
65
|
+
align?: PresenceFrameContainerProps['align']
|
|
70
66
|
}
|
|
71
67
|
|
|
72
68
|
function FrameOutline({ names, color, align = 'end' }: FrameOutlineProps) {
|
|
@@ -1,23 +1,31 @@
|
|
|
1
|
-
import type { PresenceGroupProps } from 'moi/collab'
|
|
1
|
+
import type { PresenceGroupProps as PresenceGroupContainerProps } from 'moi/collab'
|
|
2
|
+
import type { ReactNode } from 'react'
|
|
2
3
|
import { useContext, useId, useMemo } from 'react'
|
|
3
4
|
import { LayoutGroup, MotionConfig } from 'motion/react'
|
|
4
5
|
import { presenceTarget } from '../presence-target'
|
|
5
6
|
import { PresenceGroupContext } from './presence-helpers'
|
|
6
7
|
|
|
7
|
-
export function
|
|
8
|
+
export function PresenceGroupContainer({ id, children }: PresenceGroupContainerProps) {
|
|
8
9
|
const parent = useContext(PresenceGroupContext)
|
|
9
10
|
const scope = useMemo(() => {
|
|
10
11
|
presenceTarget(id)
|
|
11
12
|
return [...parent, id]
|
|
12
13
|
}, [parent, id])
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
return (
|
|
15
|
+
<PresenceGroup>
|
|
16
|
+
<PresenceGroupContext value={scope}>{children}</PresenceGroupContext>
|
|
17
|
+
</PresenceGroup>
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type PresenceGroupProps = { children: ReactNode }
|
|
22
|
+
|
|
23
|
+
export function PresenceGroup({ children }: PresenceGroupProps) {
|
|
24
|
+
// Keep avatar animations inside this particular rendered group.
|
|
15
25
|
const animationId = useId()
|
|
16
26
|
return (
|
|
17
27
|
<MotionConfig reducedMotion="user">
|
|
18
|
-
<LayoutGroup id={animationId}>
|
|
19
|
-
<PresenceGroupContext value={scope}>{children}</PresenceGroupContext>
|
|
20
|
-
</LayoutGroup>
|
|
28
|
+
<LayoutGroup id={animationId}>{children}</LayoutGroup>
|
|
21
29
|
</MotionConfig>
|
|
22
30
|
)
|
|
23
31
|
}
|
|
@@ -1,16 +1,29 @@
|
|
|
1
|
-
import type { UserAvatarGroupProps } from 'moi/collab'
|
|
1
|
+
import type { UserAvatarGroupProps as UserAvatarGroupContainerProps } from 'moi/collab'
|
|
2
|
+
import type { UserProfile } from '@/lib/collab/types'
|
|
2
3
|
import { AvatarGroup as AvatarGroupPrimitive, AvatarGroupCount } from '@/ui-components/avatar'
|
|
3
4
|
import { UserAvatar } from './user-avatar'
|
|
5
|
+
import type { UserAvatarProps } from './user-avatar'
|
|
6
|
+
import { useUsers } from '../hooks'
|
|
4
7
|
|
|
5
|
-
export function
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
export function UserAvatarGroupContainer({ ids, ...props }: UserAvatarGroupContainerProps) {
|
|
9
|
+
const users = useUsers([...new Set(ids)])
|
|
10
|
+
return <UserAvatarGroup users={users} {...props} />
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type UserAvatarGroupProps = {
|
|
14
|
+
users: readonly (UserProfile | undefined)[]
|
|
15
|
+
max?: number
|
|
16
|
+
size?: UserAvatarProps['size']
|
|
17
|
+
className?: string
|
|
18
|
+
}
|
|
9
19
|
|
|
20
|
+
export function UserAvatarGroup({ users, max = 3, size = 'sm', className }: UserAvatarGroupProps) {
|
|
21
|
+
const shown = users.slice(0, max)
|
|
22
|
+
const hidden = users.length - shown.length
|
|
10
23
|
return (
|
|
11
|
-
<AvatarGroupPrimitive className={className} aria-label={`${
|
|
12
|
-
{shown.map(
|
|
13
|
-
<UserAvatar key={id}
|
|
24
|
+
<AvatarGroupPrimitive className={className} aria-label={`${users.length} users`}>
|
|
25
|
+
{shown.map((profile, index) => (
|
|
26
|
+
<UserAvatar key={profile?.id ?? index} profile={profile} size={size} />
|
|
14
27
|
))}
|
|
15
28
|
{hidden > 0 && (
|
|
16
29
|
<AvatarGroupCount size={size} aria-label={`${hidden} more`}>
|
|
@@ -1,12 +1,42 @@
|
|
|
1
|
-
import type { UserAvatarProps } from 'moi/collab'
|
|
1
|
+
import type { UserAvatarProps as UserAvatarContainerProps } from 'moi/collab'
|
|
2
|
+
import type { UserProfile } from '@/lib/collab/types'
|
|
2
3
|
import { IconUser } from '@tabler/icons-react'
|
|
3
4
|
import { Blobatar } from '@blobatar/react'
|
|
4
5
|
import { Avatar, AvatarBadge, AvatarFallback, AvatarImage } from '@/ui-components/avatar'
|
|
6
|
+
import { cn } from '@/client/lib/cn'
|
|
7
|
+
import { userDisplayName } from '@/client/lib/user-display-name'
|
|
5
8
|
import { useUser } from '../hooks'
|
|
6
|
-
import { userDisplayName } from '../users'
|
|
7
9
|
|
|
8
|
-
export function
|
|
10
|
+
export function UserAvatarContainer({
|
|
11
|
+
id,
|
|
12
|
+
size,
|
|
13
|
+
showStatusBadge,
|
|
14
|
+
className
|
|
15
|
+
}: UserAvatarContainerProps) {
|
|
9
16
|
const user = useUser(id)
|
|
17
|
+
return (
|
|
18
|
+
<UserAvatar
|
|
19
|
+
profile={user}
|
|
20
|
+
size={size}
|
|
21
|
+
active={showStatusBadge && user?.status === 'active'}
|
|
22
|
+
className={className}
|
|
23
|
+
/>
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type UserAvatarProps = {
|
|
28
|
+
profile?: UserProfile
|
|
29
|
+
size?: 'xs' | 'sm' | 'default' | 'lg'
|
|
30
|
+
className?: string
|
|
31
|
+
active?: boolean
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function UserAvatar({
|
|
35
|
+
profile: user,
|
|
36
|
+
size = 'default',
|
|
37
|
+
className,
|
|
38
|
+
active
|
|
39
|
+
}: UserAvatarProps) {
|
|
10
40
|
const name = user ? userDisplayName(user) : 'Unknown user'
|
|
11
41
|
|
|
12
42
|
return (
|
|
@@ -14,16 +44,17 @@ export function UserAvatar({ id, size = 'default', showStatusBadge, className }:
|
|
|
14
44
|
size={size}
|
|
15
45
|
aria-label={name}
|
|
16
46
|
data-collab-color={user?.color ?? 'unknown'}
|
|
17
|
-
className={className}
|
|
47
|
+
className={cn('after:border-0', className)}
|
|
18
48
|
>
|
|
19
49
|
{user?.avatar && <AvatarImage src={user.avatar} alt="" />}
|
|
20
50
|
<AvatarFallback>
|
|
21
51
|
{user ? (
|
|
22
52
|
<Blobatar
|
|
23
|
-
|
|
53
|
+
className="scale-150"
|
|
54
|
+
name={user.id}
|
|
24
55
|
animate="hover"
|
|
25
56
|
background="circle"
|
|
26
|
-
traits={{
|
|
57
|
+
traits={{ 'eye.rx': 1 }}
|
|
27
58
|
palette={{
|
|
28
59
|
bg: 'var(--collab)',
|
|
29
60
|
head: 'var(--collab)',
|
|
@@ -34,7 +65,7 @@ export function UserAvatar({ id, size = 'default', showStatusBadge, className }:
|
|
|
34
65
|
<IconUser size={size === 'xs' || size === 'sm' ? 12 : 16} stroke={1.75} />
|
|
35
66
|
)}
|
|
36
67
|
</AvatarFallback>
|
|
37
|
-
{
|
|
68
|
+
{active && <AvatarBadge className="bg-success" />}
|
|
38
69
|
</Avatar>
|
|
39
70
|
)
|
|
40
71
|
}
|
|
@@ -1,33 +1,52 @@
|
|
|
1
|
-
import type { UserProps } from 'moi/collab'
|
|
1
|
+
import type { UserProps as UserContainerProps } from 'moi/collab'
|
|
2
|
+
import type { ReactNode } from 'react'
|
|
3
|
+
import type { UserProfile } from '@/lib/collab/types'
|
|
2
4
|
import { cn } from '@/client/lib/cn'
|
|
3
5
|
import { UserAvatar } from './user-avatar'
|
|
6
|
+
import { userDisplayName } from '@/client/lib/user-display-name'
|
|
4
7
|
import { useMe, useUser } from '../hooks'
|
|
5
|
-
import { userDisplayName } from '../users'
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
export function UserContainer({ id, showStatusBadge, showYouLabel, ...props }: UserContainerProps) {
|
|
10
|
+
const user = useUser(id)
|
|
11
|
+
const me = useMe()
|
|
12
|
+
return (
|
|
13
|
+
<User
|
|
14
|
+
{...props}
|
|
15
|
+
profile={user}
|
|
16
|
+
active={showStatusBadge && user?.status === 'active'}
|
|
17
|
+
showYouLabel={showYouLabel && user !== undefined && user.id === me?.id}
|
|
18
|
+
/>
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type UserProps = {
|
|
23
|
+
profile?: UserProfile
|
|
24
|
+
size?: 'xs' | 'sm' | 'default'
|
|
25
|
+
active?: boolean
|
|
26
|
+
showYouLabel?: boolean
|
|
27
|
+
description?: ReactNode
|
|
28
|
+
className?: string
|
|
29
|
+
}
|
|
8
30
|
|
|
9
31
|
export function User({
|
|
10
|
-
|
|
32
|
+
profile: user,
|
|
11
33
|
size = 'default',
|
|
12
|
-
|
|
34
|
+
active,
|
|
13
35
|
showYouLabel,
|
|
14
36
|
description,
|
|
15
37
|
className
|
|
16
38
|
}: UserProps) {
|
|
17
|
-
const
|
|
18
|
-
const me = useMe()
|
|
19
|
-
const name = user ? userDisplayName(user) : UNKNOWN_NAME
|
|
20
|
-
const isSelf = user !== undefined && user.id === me?.id
|
|
39
|
+
const name = user ? userDisplayName(user) : 'Unknown user'
|
|
21
40
|
|
|
22
41
|
return (
|
|
23
|
-
<span className={cn('
|
|
24
|
-
<UserAvatar
|
|
42
|
+
<span className={cn('flex min-w-0 items-center gap-2', className)}>
|
|
43
|
+
<UserAvatar profile={user} size={size} active={active} />
|
|
25
44
|
<span
|
|
26
45
|
className={cn('flex min-w-0 flex-1 text-sm', size === 'xs' ? 'items-baseline' : 'flex-col')}
|
|
27
46
|
>
|
|
28
47
|
<span className="flex min-w-0 items-baseline gap-1">
|
|
29
48
|
<span className={cn('truncate', !user && 'text-muted-foreground')}>{name}</span>
|
|
30
|
-
{showYouLabel &&
|
|
49
|
+
{showYouLabel && <span className="shrink-0 text-muted-foreground">(You)</span>}
|
|
31
50
|
</span>
|
|
32
51
|
{description && (
|
|
33
52
|
<span
|
|
@@ -19,8 +19,7 @@ export type HostApi = { publishUsers: (next: HostUsers) => void }
|
|
|
19
19
|
// Who supplies the current user: local setup, an outer host, or an auth proxy.
|
|
20
20
|
export type CurrentUserSource = 'local' | 'external' | AuthProvider
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
const PROFILE_KEY = 'moi:collab:dev-profile'
|
|
22
|
+
const PROFILE_KEY = 'moi:local-profile'
|
|
24
23
|
const NO_USERS: readonly UserProfile[] = Object.freeze([])
|
|
25
24
|
let currentUser: UserProfile | undefined
|
|
26
25
|
let currentUserSource: CurrentUserSource | undefined
|
|
@@ -138,7 +137,7 @@ export function setProxyUserState({ provider, profile }: ProxyUserState): void {
|
|
|
138
137
|
|
|
139
138
|
function persistLocalUser(): void {
|
|
140
139
|
try {
|
|
141
|
-
|
|
140
|
+
localStorage.setItem(PROFILE_KEY, JSON.stringify(currentUser))
|
|
142
141
|
} catch {
|
|
143
142
|
/* Private browsing. */
|
|
144
143
|
}
|
|
@@ -156,17 +155,17 @@ export function setLocalUser(next: UserProfile): void {
|
|
|
156
155
|
|
|
157
156
|
// Called after startup config and proxy identity settle, before React mounts.
|
|
158
157
|
// A host that has already published keeps the viewer it chose, signed in or not.
|
|
159
|
-
export function initializeLocalUser(
|
|
160
|
-
if (!
|
|
158
|
+
export function initializeLocalUser(local: boolean, proxyUser: ProxyUserState | undefined): void {
|
|
159
|
+
if (!local || !proxyUser || proxyUser.provider !== undefined || currentUserSource !== undefined)
|
|
161
160
|
return
|
|
162
161
|
try {
|
|
163
|
-
const saved =
|
|
162
|
+
const saved = localStorage.getItem(PROFILE_KEY)
|
|
164
163
|
if (saved) {
|
|
165
164
|
setLocalUser(JSON.parse(saved) as UserProfile)
|
|
166
165
|
return
|
|
167
166
|
}
|
|
168
167
|
} catch {
|
|
169
|
-
|
|
168
|
+
// Invalid or unavailable storage starts a fresh local profile.
|
|
170
169
|
}
|
|
171
170
|
setLocalUser(createLocalUser())
|
|
172
171
|
}
|
|
@@ -181,3 +180,21 @@ export function installHostApi(): void {
|
|
|
181
180
|
const api: HostApi = { publishUsers }
|
|
182
181
|
host.moi.collab = api
|
|
183
182
|
}
|
|
183
|
+
|
|
184
|
+
// Storage events update this tab without writing back and triggering another event.
|
|
185
|
+
export function receiveLocalProfile(event: Pick<StorageEvent, 'key' | 'newValue'>): void {
|
|
186
|
+
if (event.key !== PROFILE_KEY || !event.newValue || currentUserSource !== 'local') return
|
|
187
|
+
try {
|
|
188
|
+
const profile = normalizeUserProfile(JSON.parse(event.newValue) as UserProfile)
|
|
189
|
+
if (sameProfile(profile, currentUser)) return
|
|
190
|
+
currentUser = profile
|
|
191
|
+
listeners.forEach(listener => listener())
|
|
192
|
+
} catch {
|
|
193
|
+
// Ignore corrupt values from other tabs.
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export function subscribeLocalProfileStorage(): () => void {
|
|
198
|
+
window.addEventListener('storage', receiveLocalProfile)
|
|
199
|
+
return () => window.removeEventListener('storage', receiveLocalProfile)
|
|
200
|
+
}
|
|
@@ -40,7 +40,7 @@ export function localUserProfile(id: string, draft: LocalUserDraft): UserProfile
|
|
|
40
40
|
return { id, ...(name ? { name } : {}), color: draft.color }
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
// The id stays with the
|
|
43
|
+
// The id stays with the browser through renames, so peers keep seeing one user.
|
|
44
44
|
export function createLocalUser(): UserProfile {
|
|
45
45
|
return localUserProfile(`local-${crypto.randomUUID().slice(0, 8)}`, randomLocalUser())
|
|
46
46
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { ProxyUserState } from '@/lib/collab/types'
|
|
2
2
|
|
|
3
3
|
import { requestJson } from '@/client/api/http'
|
|
4
|
-
import { onWorkspaceEventsReconnect } from '@/client/runtime/use-workspace-events'
|
|
5
4
|
|
|
6
5
|
import { setProxyUserState } from './host-state'
|
|
7
6
|
|
|
@@ -23,13 +22,9 @@ async function fetchProxyUser(): Promise<ProxyUserState | undefined> {
|
|
|
23
22
|
} catch {}
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
// Loaded before the app mounts, like startup config, so workspaces
|
|
27
|
-
// between shared and browser-tab navigation with the inherited user
|
|
28
|
-
// in place.
|
|
25
|
+
// Loaded once before the app mounts, like startup config, so workspaces
|
|
26
|
+
// choose between shared and browser-tab navigation with the inherited user
|
|
27
|
+
// already in place.
|
|
29
28
|
export async function loadProxyUser(): Promise<ProxyUserState | undefined> {
|
|
30
|
-
|
|
31
|
-
onWorkspaceEventsReconnect(() => {
|
|
32
|
-
void fetchProxyUser()
|
|
33
|
-
})
|
|
34
|
-
return state
|
|
29
|
+
return fetchProxyUser()
|
|
35
30
|
}
|
|
@@ -13,11 +13,6 @@ export type UsersSource = {
|
|
|
13
13
|
users: readonly UserProfile[]
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
// Presentation only: keep the supplied profile unchanged in applet APIs.
|
|
17
|
-
export function userDisplayName(user: UserProfile): string {
|
|
18
|
-
return user.name?.trim() || user.email?.trim() || user.id
|
|
19
|
-
}
|
|
20
|
-
|
|
21
16
|
export function userStatus(connections: readonly Connection[], id: string): UserStatus {
|
|
22
17
|
const userConnections = connections.filter(connection => connection.userId === id)
|
|
23
18
|
return userConnections.some(connection => connection.location?.status === 'active')
|