moi-computer 0.11.0 → 0.11.1-dev.1c52199
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/client/AGENTS.md +2 -2
- package/client/api/app-config.ts +2 -1
- package/client/app/AppRouter.tsx +2 -2
- package/client/app/routes/WorkspaceRoute.tsx +33 -27
- package/client/app/shell/SidebarLayout.tsx +18 -15
- package/client/components/shared/BottomPanel.tsx +26 -14
- package/client/components/shared/PanelHeader.tsx +1 -1
- package/client/components/shared/ReorderableList.tsx +7 -2
- package/client/components/shared/WorkspaceIcon.tsx +92 -0
- package/client/components/ui/alert-dialog.tsx +1 -0
- package/client/components/ui/button.tsx +1 -53
- package/client/components/ui/checkbox.tsx +1 -0
- package/client/components/ui/collapsible.tsx +1 -15
- package/client/components/ui/dialog.tsx +1 -58
- package/client/components/ui/dropdown-menu.tsx +1 -254
- package/client/components/ui/hover-card.tsx +1 -44
- package/client/components/ui/inline-input.tsx +84 -0
- package/client/components/ui/input.tsx +1 -21
- package/client/components/ui/popover.tsx +1 -88
- package/client/components/ui/resizable.tsx +1 -40
- package/client/components/ui/skeleton.tsx +1 -13
- package/client/components/ui/slider.tsx +1 -70
- package/client/components/ui/spinner.tsx +1 -18
- package/client/components/ui/switch.tsx +1 -23
- package/client/components/ui/tabs.tsx +1 -0
- package/client/components/ui/textarea.tsx +1 -18
- package/client/components/ui/toast.tsx +2 -2
- package/client/components/ui/tooltip.tsx +1 -51
- package/client/features/applets/AppletMount.tsx +5 -2
- package/client/features/applets/applet-cache.ts +3 -3
- package/client/features/applets/applet-runtime.ts +158 -108
- package/client/features/applets/applet-styles.ts +2 -2
- package/client/features/applets/applet-thumbnail.ts +6 -8
- package/client/features/applets/useApplet.ts +10 -9
- package/client/features/chat/ChatPanel.tsx +24 -15
- package/client/features/chat/ChatPopup.tsx +9 -5
- package/client/features/chat/applet-chat-intents.ts +179 -0
- package/client/features/chat/chat-send.ts +116 -64
- package/client/features/chat/chat-store.ts +51 -62
- package/client/features/chat/composer/ChatComposer.tsx +43 -128
- package/client/features/chat/composer/ModelPicker.tsx +47 -60
- package/client/features/chat/composer/attachments/AttachmentChip.tsx +99 -0
- package/client/features/chat/composer/attachments/DrawingAttachmentChip.tsx +37 -0
- package/client/features/chat/composer/attachments/FileAttachmentChip.tsx +22 -0
- package/client/features/chat/composer/attachments/TextAttachmentChip.tsx +11 -0
- package/client/features/chat/composer/attachments/draft-attachments.ts +168 -0
- package/client/features/chat/composer/attachments/types.ts +25 -0
- package/client/features/chat/composer/attachments/uploads.ts +26 -0
- package/client/features/chat/composer/banners/ErrorBanner.tsx +20 -12
- package/client/features/chat/composer/model-order.ts +15 -0
- package/client/features/chat/composer/useWorkspaceComposerState.tsx +15 -7
- package/client/features/chat/{chat-connection.ts → connection/chat-connection.ts} +1 -1
- package/client/features/chat/{chat-frames.ts → connection/chat-frames.ts} +10 -8
- package/client/features/chat/{ChatEmptyState.tsx → messages/ChatEmptyState.tsx} +16 -11
- package/client/features/chat/{MarkdownContent.tsx → messages/MarkdownContent.tsx} +16 -1
- package/client/features/chat/{TurnView.tsx → messages/TurnView.tsx} +27 -19
- package/client/features/chat/{group-turns.ts → messages/group-turns.ts} +12 -0
- package/client/features/chat/{interleave-notices.ts → messages/interleave-notices.ts} +7 -11
- package/client/features/chat/{tool-group → messages/tool-group}/SubagentCard.tsx +1 -1
- package/client/features/chat/{tool-group → messages/tool-group}/TimelineRow.tsx +2 -2
- package/client/features/chat/{tool-group → messages/tool-group}/ToolCallGroup.tsx +2 -5
- package/client/features/chat/{tool-group → messages/tool-group}/format/codex.ts +4 -1
- package/client/features/chat/{ChatSelector.tsx → sessions/ChatSelector.tsx} +3 -3
- package/client/features/chat/{api.ts → sessions/api.ts} +5 -14
- package/client/features/chat/sessions/session-view.ts +53 -0
- package/client/features/chat/{useSelectedSession.ts → sessions/useSelectedSession.ts} +64 -20
- package/client/features/chat/useChat.ts +46 -24
- package/client/features/collab/DevCollabIdentity.tsx +170 -0
- package/client/features/collab/DevCollabKit.tsx +501 -0
- package/client/features/collab/DevCollabPage.tsx +25 -0
- package/client/features/collab/WorkspaceCollabControls.tsx +313 -0
- package/client/features/collab/client.ts +146 -0
- package/client/features/collab/components.tsx +307 -0
- package/client/features/collab/dev-persona.ts +66 -0
- package/client/features/collab/engine.ts +96 -0
- package/client/features/collab/entry.tsx +35 -0
- package/client/features/collab/facehash-avatar.ts +132 -0
- package/client/features/collab/fake-engine.ts +130 -0
- package/client/features/collab/hooks.tsx +253 -0
- package/client/features/collab/identity.ts +305 -0
- package/client/features/collab/index.ts +45 -0
- package/client/features/collab/people.ts +102 -0
- package/client/features/collab/personal-state.ts +61 -0
- package/client/features/collab/presence-publisher.ts +29 -0
- package/client/features/collab/presence-target.ts +10 -0
- package/client/features/collab/primitives.tsx +398 -0
- package/client/features/collab/proxy-identity.ts +24 -0
- package/client/features/collab/store.ts +156 -0
- package/client/features/dev/ChatStatesPage.tsx +8 -7
- package/client/features/dev/DevIndexPage.tsx +10 -0
- package/client/features/dev/DevRoutes.tsx +16 -1
- package/client/features/dev/HarnessDebugPage.tsx +11 -8
- package/client/features/dev/ToolCallsPage.tsx +1 -1
- package/client/features/dev/UiComponentPreviews.tsx +855 -0
- package/client/features/dev/UiComponentsPage.tsx +60 -0
- package/client/features/dev/chat-states-fixtures.ts +13 -2
- package/client/features/drawings/useChatAnnotation.ts +17 -17
- package/client/features/drawings/useDrawingLayer.ts +7 -9
- package/client/features/drawings/useViewBuilderSketch.ts +18 -15
- package/client/features/home/HomePage.tsx +8 -7
- package/client/features/home/WorkspacePreview.tsx +2 -2
- package/client/features/home/workspace-presentation.tsx +1 -11
- package/client/features/home/workspace-setup/DemoDialog.tsx +3 -2
- package/client/features/home/workspace-setup/ImportWorkspaceDialog.tsx +5 -8
- package/client/features/home/workspace-setup/WorkspaceAgentStep.tsx +2 -4
- package/client/features/home/workspace-setup/WorkspaceDialogContent.tsx +7 -20
- package/client/features/overview/HiddenPanel.tsx +109 -0
- package/client/features/overview/Overview.tsx +302 -0
- package/client/features/overview/WidgetCanvas.tsx +164 -0
- package/client/features/{widgets → overview}/WidgetFrame.tsx +25 -17
- package/client/features/overview/WorkspaceName.tsx +60 -0
- package/client/features/overview/api.ts +30 -0
- package/client/features/overview/default/ViewsWidget.tsx +252 -0
- package/client/features/overview/default/registry.tsx +36 -0
- package/client/features/{widgets → overview}/grid.ts +36 -0
- package/client/features/overview/useGridReconcile.ts +94 -0
- package/client/features/scratchpad/Scratchpad.tsx +7 -8
- package/client/features/scratchpad/ScratchpadControls.tsx +0 -1
- package/client/features/scratchpad/useScratchpadSnapshot.tsx +23 -13
- package/client/features/settings/GeneralSettings.tsx +55 -58
- package/client/features/settings/SettingsLayout.tsx +2 -2
- package/client/features/settings/WorkspaceIconPicker.tsx +318 -0
- package/client/features/settings/WorkspaceSettingsDialog.tsx +65 -0
- package/client/features/settings/api.ts +48 -24
- package/client/features/views/ViewBuilder.tsx +5 -4
- package/client/features/views/ViewManager.tsx +28 -22
- package/client/features/views/api.ts +36 -2
- package/client/features/views/useViewBuilderActions.ts +11 -5
- package/client/features/views/useViewBuilderDrafts.ts +23 -21
- package/client/features/views/view-presentation.ts +13 -0
- package/client/features/workspace/{CustomizePanel.tsx → ThemePanel.tsx} +26 -31
- package/client/features/workspace/UnavailablePage.tsx +21 -0
- package/client/features/workspace/WorkspaceLayoutContext.tsx +22 -10
- package/client/features/workspace/WorkspaceScreen.tsx +228 -172
- package/client/features/workspace/WorkspaceSplitLayout.tsx +7 -2
- package/client/features/workspace/WorkspaceTabs.tsx +2 -0
- package/client/features/workspace/api.ts +5 -31
- package/client/features/workspace/layout-save.ts +13 -0
- package/client/features/workspace/moi-context.ts +15 -11
- package/client/features/workspace/tab-resolution.ts +10 -33
- package/client/features/workspace/useWorkspaceNavigation.ts +173 -101
- package/client/index.css +23 -30
- package/client/index.tsx +4 -3
- package/client/lib/app-icon-registry.ts +2 -0
- package/client/lib/use-latest-ref.ts +11 -0
- package/client/main.tsx +1 -1
- package/client/runtime/useWorkspaceEvents.ts +59 -14
- package/client/theme.css +5 -5
- package/dist/chunk-1ftessc8.js +2 -0
- package/dist/chunk-3802vh2p.js +2 -0
- package/dist/chunk-542a2m9m.js +1 -0
- package/dist/chunk-5745d83v.js +2 -0
- package/dist/chunk-5zxdsjym.js +1 -0
- package/dist/{chunk-tqd3pkg8.css → chunk-60q353jq.css} +1 -1
- package/dist/chunk-7r4z77ry.js +2 -0
- package/dist/chunk-9cm0wjah.js +79 -0
- package/dist/{chunk-11cab5dq.css → chunk-cq2r11fg.css} +1 -1
- package/dist/chunk-cvgdm1hq.js +2 -0
- package/dist/chunk-gptm4jpd.js +546 -0
- package/dist/chunk-nf2wkvf9.js +14 -0
- package/dist/chunk-wnmf38ta.js +5 -0
- package/dist/chunk-xaehhr1j.css +1 -0
- package/dist/chunk-xpt063fx.js +1 -0
- package/dist/index.html +1 -1
- package/lib/app-icons.ts +1 -0
- package/lib/applet-selector.ts +24 -0
- package/lib/chat-title.ts +6 -1
- package/lib/collab/colors.ts +24 -0
- package/lib/collab/protocol.ts +83 -0
- package/lib/collab/types.ts +63 -0
- package/lib/default-widgets.ts +32 -0
- package/lib/experimental.ts +14 -0
- package/lib/format.ts +67 -7
- package/lib/message-attachments.ts +40 -0
- package/lib/moi-attachments.ts +204 -0
- package/lib/moi-context.ts +27 -35
- package/lib/navigation.ts +84 -0
- package/lib/themes.ts +6 -6
- package/lib/types.ts +103 -40
- package/lib/workspace-icon.ts +20 -0
- package/lib/workspace-layout.ts +22 -2
- package/lib/workspace-tabs.ts +9 -33
- package/package.json +44 -32
- package/registry.json +656 -0
- package/server/AGENTS.md +2 -0
- package/server/agent.ts +1 -1
- package/server/api.ts +162 -68
- package/server/app-config.ts +127 -34
- package/server/applet-typecheck.ts +100 -0
- package/server/applets/applet-css.ts +55 -0
- package/server/{bundler → applets}/build-applet.ts +21 -240
- package/server/applets/build-worker.ts +178 -0
- package/server/applets/config.ts +226 -0
- package/server/applets/dependencies.ts +206 -0
- package/server/{applets.ts → applets/index.ts} +44 -189
- package/server/applets/runtime/base.ts +4 -0
- package/server/applets/runtime/moi.ts +42 -0
- package/server/applets/runtime/rpc.ts +17 -0
- package/server/applets/view-source.ts +67 -0
- package/server/attachment-message.ts +95 -0
- package/server/chat-selection.ts +23 -0
- package/server/cli-ui-components.ts +28 -33
- package/server/cli.ts +226 -120
- package/server/collab/applet-module.ts +50 -0
- package/server/collab/cloudflare-access.ts +77 -0
- package/server/collab/config.ts +18 -0
- package/server/collab/ipc.ts +10 -0
- package/server/collab/manager.ts +407 -0
- package/server/collab/service.ts +137 -0
- package/server/collab/skill/collab-env.d.ts +92 -0
- package/server/collab/skill/index.ts +59 -0
- package/server/collab/worker.ts +52 -0
- package/server/control.ts +63 -42
- package/server/data-dir.ts +1 -1
- package/server/harness/README.md +45 -50
- package/server/harness/acp/NOTES.md +426 -0
- package/server/harness/acp/adapter.ts +7 -21
- package/server/harness/acp/discovery.ts +27 -30
- package/server/harness/acp/model-state.ts +57 -0
- package/server/harness/acp/session.ts +49 -56
- package/server/harness/claude-code/NOTES.md +54 -13
- package/server/harness/claude-code/adapter.ts +8 -25
- package/server/harness/claude-code/cli.ts +40 -0
- package/server/harness/claude-code/index.ts +13 -5
- package/server/harness/claude-code/models.ts +72 -19
- package/server/harness/claude-code/session.ts +447 -343
- package/server/harness/claude-code/sessions.ts +9 -4
- package/server/harness/codex/NOTES.md +222 -350
- package/server/harness/codex/adapter.ts +102 -52
- package/server/harness/codex/auth.ts +1 -3
- package/server/harness/codex/client.ts +169 -249
- package/server/harness/codex/discovery.ts +9 -17
- package/server/harness/codex/index.ts +3 -1
- package/server/harness/codex/pagination.ts +24 -0
- package/server/harness/codex/permissions.ts +32 -8
- package/server/harness/codex/probe.ts +10 -13
- package/server/harness/codex/session.ts +567 -181
- package/server/harness/codex/transport.ts +184 -0
- package/server/harness/debug.ts +1 -1
- package/server/harness/hermes/NOTES.md +19 -1
- package/server/harness/hermes/discovery.ts +20 -0
- package/server/harness/hermes/index.ts +13 -0
- package/server/harness/hermes/models.ts +28 -8
- package/server/harness/openclaw/NOTES.md +1 -1
- package/server/harness/openclaw/adapter.ts +22 -4
- package/server/harness/openclaw/gateway.ts +5 -3
- package/server/harness/openclaw/session.ts +27 -27
- package/server/harness/types.ts +9 -5
- package/server/layout.ts +24 -16
- package/server/moi-scaffold.ts +22 -14
- package/server/navigation-relay.ts +110 -0
- package/server/preview.ts +3 -1
- package/server/registry.ts +71 -41
- package/server/scratchpad-executor.ts +79 -56
- package/server/scratchpad-shape-defaults.ts +82 -0
- package/server/selected-session.ts +24 -4
- package/server/skill-update.ts +5 -3
- package/server/skill-version.ts +4 -7
- package/server/skills-template.ts +60 -9
- package/server/tabs.ts +19 -33
- package/server/tldraw-package.d.ts +4 -0
- package/server/ui-components.ts +101 -434
- package/server/uploads.ts +0 -0
- package/server/view-builders.ts +20 -2
- package/server/views.ts +126 -6
- package/server/web.ts +108 -30
- package/server/widgets.ts +12 -5
- package/server/workspace-config.ts +13 -9
- package/server/workspace-env.ts +3 -2
- package/tsconfig.json +0 -1
- package/ui-components/accordion.tsx +71 -0
- package/ui-components/alert-dialog.tsx +165 -0
- package/ui-components/alert.tsx +68 -0
- package/ui-components/attachment.tsx +195 -0
- package/ui-components/avatar.tsx +91 -0
- package/ui-components/badge.tsx +49 -0
- package/ui-components/button-group.tsx +78 -0
- package/ui-components/button.tsx +55 -0
- package/ui-components/calendar.tsx +180 -0
- package/ui-components/card.tsx +84 -0
- package/ui-components/carousel.tsx +235 -0
- package/ui-components/chart.tsx +338 -0
- package/ui-components/checkbox.tsx +28 -0
- package/ui-components/collapsible.tsx +15 -0
- package/ui-components/combobox.tsx +267 -0
- package/ui-components/context-menu.tsx +244 -0
- package/ui-components/dialog.tsx +138 -0
- package/ui-components/docs/accordion.md +463 -0
- package/ui-components/docs/alert-dialog.md +481 -0
- package/ui-components/docs/alert.md +301 -0
- package/ui-components/docs/attachment.md +689 -0
- package/ui-components/docs/avatar.md +495 -0
- package/ui-components/docs/badge.md +258 -0
- package/ui-components/docs/button-group.md +879 -0
- package/ui-components/docs/button.md +26 -0
- package/ui-components/docs/calendar.md +862 -0
- package/ui-components/docs/card.md +265 -0
- package/ui-components/docs/carousel.md +627 -0
- package/ui-components/docs/chart.md +1256 -0
- package/ui-components/docs/checkbox.md +477 -0
- package/ui-components/docs/collapsible.md +446 -0
- package/ui-components/docs/combobox.md +1003 -0
- package/ui-components/docs/context-menu.md +860 -0
- package/ui-components/docs/data-table.md +1580 -0
- package/ui-components/docs/date-picker.md +614 -0
- package/ui-components/docs/dialog.md +414 -0
- package/ui-components/docs/drawer.md +51 -0
- package/ui-components/docs/dropdown-menu.md +1000 -0
- package/ui-components/docs/field.md +1192 -0
- package/ui-components/docs/hover-card.md +275 -0
- package/ui-components/docs/input-group.md +866 -0
- package/ui-components/docs/input.md +456 -0
- package/ui-components/docs/kbd.md +191 -0
- package/ui-components/docs/label.md +295 -0
- package/ui-components/docs/pagination.md +416 -0
- package/ui-components/docs/popover.md +348 -0
- package/ui-components/docs/progress.md +214 -0
- package/ui-components/docs/radio-group.md +389 -0
- package/ui-components/docs/resizable.md +265 -0
- package/ui-components/docs/select.md +616 -0
- package/ui-components/docs/separator.md +216 -0
- package/ui-components/docs/skeleton.md +205 -0
- package/ui-components/docs/slider.md +226 -0
- package/ui-components/docs/spinner.md +332 -0
- package/ui-components/docs/switch.md +236 -0
- package/ui-components/docs/table.md +551 -0
- package/ui-components/docs/tabs.md +379 -0
- package/ui-components/docs/textarea.md +187 -0
- package/ui-components/docs/toggle-group.md +370 -0
- package/ui-components/docs/toggle.md +91 -0
- package/ui-components/docs/tooltip.md +290 -0
- package/ui-components/drawer.tsx +213 -0
- package/ui-components/dropdown-menu.tsx +263 -0
- package/ui-components/field.tsx +224 -0
- package/ui-components/hover-card.tsx +46 -0
- package/ui-components/input-group.tsx +146 -0
- package/ui-components/input.tsx +20 -0
- package/ui-components/kbd.tsx +32 -0
- package/ui-components/label.tsx +17 -0
- package/ui-components/pagination.tsx +124 -0
- package/ui-components/popover.tsx +81 -0
- package/ui-components/progress.tsx +63 -0
- package/ui-components/radio-group.tsx +38 -0
- package/ui-components/resizable.tsx +40 -0
- package/ui-components/scoped-portal.tsx +31 -0
- package/ui-components/select.tsx +195 -0
- package/ui-components/separator.tsx +18 -0
- package/ui-components/skeleton.tsx +15 -0
- package/ui-components/slider.tsx +75 -0
- package/ui-components/spinner.tsx +20 -0
- package/ui-components/switch.tsx +27 -0
- package/ui-components/table.tsx +86 -0
- package/ui-components/tabs.tsx +75 -0
- package/ui-components/textarea.tsx +17 -0
- package/ui-components/toggle-group.tsx +85 -0
- package/ui-components/toggle.tsx +42 -0
- package/ui-components/tooltip.tsx +61 -0
- package/ui-components/utils.ts +8 -0
- package/workspace/.claude/skills/moi-workspace/SKILL.md +295 -248
- package/workspace/.claude/skills/moi-workspace/references/COLLABORATIVE.md +151 -0
- package/workspace/.claude/skills/moi-workspace/references/DESIGN.md +100 -152
- package/workspace/.claude/skills/moi-workspace/references/INTENTS.md +156 -0
- package/workspace/.claude/skills/moi-workspace/references/UI-COMPONENTS.md +67 -203
- package/client/features/chat/attachment-staging.ts +0 -153
- package/client/features/chat/uploads.ts +0 -18
- package/client/features/chat/useAppletChatMessage.ts +0 -68
- package/client/features/settings/IconPicker.tsx +0 -442
- package/client/features/settings/WorkspaceSettings.tsx +0 -92
- package/client/features/settings/render-icon.ts +0 -173
- package/client/features/widgets/HiddenPanel.tsx +0 -80
- package/client/features/widgets/WidgetGrid.tsx +0 -123
- package/client/features/widgets/Widgets.tsx +0 -264
- package/client/features/widgets/useGridReconcile.ts +0 -73
- package/dist/chunk-104m57qw.js +0 -2
- package/dist/chunk-59zf0m6n.js +0 -1
- package/dist/chunk-bj3akjs2.js +0 -1
- package/dist/chunk-c9pjqx9m.js +0 -14
- package/dist/chunk-j2w2vak4.js +0 -546
- package/dist/chunk-k2r9c95m.js +0 -10
- package/dist/chunk-kmbxhgwv.js +0 -1
- package/dist/chunk-p1yqa71k.js +0 -83
- package/dist/chunk-pcnahct1.js +0 -5
- package/dist/chunk-r5xrenjy.css +0 -1
- package/dist/chunk-tny85yt2.js +0 -2
- package/dist/chunk-v7wr1df4.js +0 -2
- package/server/bundler/applet-css.ts +0 -155
- /package/client/features/chat/{ChatPromptBubbles.tsx → messages/ChatPromptBubbles.tsx} +0 -0
- /package/client/features/chat/{ShimmerText.tsx → messages/ShimmerText.tsx} +0 -0
- /package/client/features/chat/{preview-turn.ts → messages/preview-turn.ts} +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/CodeBlock.tsx +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/Collapse.tsx +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/ReadImagePreview.tsx +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/ToolOutput.tsx +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/detect.ts +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/fixtures.ts +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/format/claude.ts +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/format/hermes.ts +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/format/index.ts +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/format/mcp.ts +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/format/openclaw.ts +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/format/shared.ts +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/format/shell.ts +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/index.ts +0 -0
- /package/client/features/chat/{useStickToBottom.ts → messages/useStickToBottom.ts} +0 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Activity,
|
|
3
|
+
Cursors,
|
|
4
|
+
Facepile,
|
|
5
|
+
User,
|
|
6
|
+
PresenceFrame,
|
|
7
|
+
PresenceGroup,
|
|
8
|
+
PresenceGutter,
|
|
9
|
+
Selection
|
|
10
|
+
} from './components'
|
|
11
|
+
import {
|
|
12
|
+
useMe,
|
|
13
|
+
usePeers,
|
|
14
|
+
usePresence,
|
|
15
|
+
usePublishPresence,
|
|
16
|
+
useUser,
|
|
17
|
+
useWorkspaceUsers,
|
|
18
|
+
useWorkspaceUsersStatus
|
|
19
|
+
} from './hooks'
|
|
20
|
+
|
|
21
|
+
export { CollabProvider, AppletScope, CollabContext } from './hooks'
|
|
22
|
+
export { WorkspaceCollabControls } from './WorkspaceCollabControls'
|
|
23
|
+
export { getIdentity, subscribeIdentityStore } from './identity'
|
|
24
|
+
|
|
25
|
+
const appletApi = {
|
|
26
|
+
Activity,
|
|
27
|
+
Cursors,
|
|
28
|
+
Facepile,
|
|
29
|
+
User,
|
|
30
|
+
PresenceFrame,
|
|
31
|
+
PresenceGroup,
|
|
32
|
+
PresenceGutter,
|
|
33
|
+
Selection,
|
|
34
|
+
useMe,
|
|
35
|
+
usePeers,
|
|
36
|
+
useUser,
|
|
37
|
+
useWorkspaceUsers,
|
|
38
|
+
useWorkspaceUsersStatus,
|
|
39
|
+
usePresence,
|
|
40
|
+
usePublishPresence
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function createAppletCollabApi() {
|
|
44
|
+
return appletApi
|
|
45
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { CollabIdentity, CollabLocation, CollabParticipant } from '@/lib/collab/types'
|
|
2
|
+
|
|
3
|
+
export type UserStatus = 'active' | 'away' | 'offline'
|
|
4
|
+
export type CollabUser = CollabIdentity & { status: UserStatus }
|
|
5
|
+
export type WorkspaceUsersOptions = { status?: UserStatus }
|
|
6
|
+
export type UsersSource = {
|
|
7
|
+
participants: readonly CollabParticipant[]
|
|
8
|
+
users: readonly CollabIdentity[]
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Presentation only: keep the supplied profile unchanged in applet APIs.
|
|
12
|
+
export function userDisplayName(user: CollabIdentity): string {
|
|
13
|
+
return user.name?.trim() || user.email?.trim() || user.id
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function userStatus(participants: readonly CollabParticipant[], id: string): UserStatus {
|
|
17
|
+
const connections = participants.filter(participant => participant.userId === id)
|
|
18
|
+
return connections.some(connection => connection.location !== null && !connection.location.away)
|
|
19
|
+
? 'active'
|
|
20
|
+
: connections.length
|
|
21
|
+
? 'away'
|
|
22
|
+
: 'offline'
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// A supplied host directory is authoritative, including an empty list/removals.
|
|
26
|
+
export function workspaceProfiles(
|
|
27
|
+
liveUsers: readonly CollabIdentity[],
|
|
28
|
+
self: CollabIdentity | null,
|
|
29
|
+
directory: readonly CollabIdentity[] | null
|
|
30
|
+
): readonly CollabIdentity[] {
|
|
31
|
+
if (directory !== null) return directory
|
|
32
|
+
const users = new Map(liveUsers.map(user => [user.id, user]))
|
|
33
|
+
if (self) users.set(self.id, self)
|
|
34
|
+
return [...users.values()]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function resolveUser(source: UsersSource, id: string): CollabUser | null {
|
|
38
|
+
const profile = source.users.find(user => user.id === id)
|
|
39
|
+
return profile ? { ...profile, status: userStatus(source.participants, id) } : null
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type PeersOptions = { scope?: 'page' | 'workspace'; status?: 'active' | 'away' }
|
|
43
|
+
export function resolvePeers(
|
|
44
|
+
source: UsersSource,
|
|
45
|
+
selfId: string | null,
|
|
46
|
+
location: CollabLocation | null,
|
|
47
|
+
{ scope = 'page', status }: PeersOptions = {}
|
|
48
|
+
): CollabUser[] {
|
|
49
|
+
const peers: CollabUser[] = []
|
|
50
|
+
const ids = new Set(
|
|
51
|
+
source.participants
|
|
52
|
+
.filter(
|
|
53
|
+
participant =>
|
|
54
|
+
participant.userId !== selfId &&
|
|
55
|
+
(scope === 'workspace' ||
|
|
56
|
+
(location !== null && participant.location?.page === location.page))
|
|
57
|
+
)
|
|
58
|
+
.map(participant => participant.userId)
|
|
59
|
+
)
|
|
60
|
+
for (const id of ids) {
|
|
61
|
+
const user = resolveUser(source, id)
|
|
62
|
+
if (user && (!status || user.status === status)) peers.push(user)
|
|
63
|
+
}
|
|
64
|
+
return peers
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export type PresentPerson = {
|
|
68
|
+
identity: CollabIdentity
|
|
69
|
+
self: boolean
|
|
70
|
+
pages: string[]
|
|
71
|
+
status: UserStatus
|
|
72
|
+
}
|
|
73
|
+
export type SelfConnection = {
|
|
74
|
+
identity: CollabIdentity | null
|
|
75
|
+
connectionId: string | null
|
|
76
|
+
page: string | null
|
|
77
|
+
users: readonly CollabIdentity[]
|
|
78
|
+
}
|
|
79
|
+
export function groupPeople(
|
|
80
|
+
participants: CollabParticipant[],
|
|
81
|
+
self: SelfConnection
|
|
82
|
+
): PresentPerson[] {
|
|
83
|
+
const users = [...self.users].sort(
|
|
84
|
+
(a, b) => Number(b.id === self.identity?.id) - Number(a.id === self.identity?.id)
|
|
85
|
+
)
|
|
86
|
+
return users.map(identity => {
|
|
87
|
+
const pages = new Set<string>()
|
|
88
|
+
for (const participant of participants) {
|
|
89
|
+
if (participant.userId !== identity.id || participant.connectionId === self.connectionId)
|
|
90
|
+
continue
|
|
91
|
+
if (participant.location) pages.add(participant.location.page)
|
|
92
|
+
}
|
|
93
|
+
const isSelf = identity.id === self.identity?.id
|
|
94
|
+
if (isSelf && self.page) pages.add(self.page)
|
|
95
|
+
return {
|
|
96
|
+
identity,
|
|
97
|
+
self: isSelf,
|
|
98
|
+
pages: [...pages],
|
|
99
|
+
status: userStatus(participants, identity.id)
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { useCallback, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
import type { WorkspaceTabsState } from '@/lib/types'
|
|
4
|
+
import { normalizeWorkspaceTabs } from '@/lib/workspace-layout'
|
|
5
|
+
|
|
6
|
+
const keyFor = (workspaceId: string, field: string) => `moi:collab:${workspaceId}:${field}`
|
|
7
|
+
|
|
8
|
+
export function readPersonalSession(workspaceId: string): string | null {
|
|
9
|
+
try {
|
|
10
|
+
return sessionStorage.getItem(keyFor(workspaceId, 'session'))
|
|
11
|
+
} catch {
|
|
12
|
+
return null
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function writePersonalSession(workspaceId: string, sessionId: string | null): void {
|
|
17
|
+
try {
|
|
18
|
+
if (sessionId === null) sessionStorage.removeItem(keyFor(workspaceId, 'session'))
|
|
19
|
+
else sessionStorage.setItem(keyFor(workspaceId, 'session'), sessionId)
|
|
20
|
+
} catch {
|
|
21
|
+
/* A private browser can still keep the active query in memory. */
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function readPersonalTabs(
|
|
26
|
+
workspaceId: string,
|
|
27
|
+
defaults: WorkspaceTabsState
|
|
28
|
+
): WorkspaceTabsState {
|
|
29
|
+
try {
|
|
30
|
+
const saved = sessionStorage.getItem(keyFor(workspaceId, 'tabs'))
|
|
31
|
+
return saved ? normalizeWorkspaceTabs(JSON.parse(saved)) : defaults
|
|
32
|
+
} catch {
|
|
33
|
+
return defaults
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function writePersonalTabs(workspaceId: string, tabs: WorkspaceTabsState): void {
|
|
38
|
+
try {
|
|
39
|
+
sessionStorage.setItem(keyFor(workspaceId, 'tabs'), JSON.stringify(tabs))
|
|
40
|
+
} catch {
|
|
41
|
+
// The hook retains its in-memory selection when browser storage is denied.
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function usePersonalTabs(
|
|
46
|
+
workspaceId: string,
|
|
47
|
+
enabled: boolean,
|
|
48
|
+
defaults: WorkspaceTabsState
|
|
49
|
+
) {
|
|
50
|
+
const [local, setLocal] = useState<WorkspaceTabsState>(() =>
|
|
51
|
+
enabled ? readPersonalTabs(workspaceId, defaults) : defaults
|
|
52
|
+
)
|
|
53
|
+
const setTabs = useCallback(
|
|
54
|
+
(tabs: WorkspaceTabsState) => {
|
|
55
|
+
setLocal(tabs)
|
|
56
|
+
writePersonalTabs(workspaceId, tabs)
|
|
57
|
+
},
|
|
58
|
+
[workspaceId]
|
|
59
|
+
)
|
|
60
|
+
return [enabled ? local : defaults, setTabs] as const
|
|
61
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { CollabJsonValue, CollabPresenceRegistration } from '@/lib/collab/types'
|
|
2
|
+
|
|
3
|
+
import type { CollabEngineApi } from './engine'
|
|
4
|
+
|
|
5
|
+
// A mounted control owns a registration only while it has something to show.
|
|
6
|
+
// Public custom publishers omit the predicate: false and null are valid values.
|
|
7
|
+
export function createPresencePublisher<T extends CollabJsonValue>(
|
|
8
|
+
engine: Pick<CollabEngineApi, 'setPresence' | 'deletePresence'>,
|
|
9
|
+
registration: Omit<CollabPresenceRegistration, 'value'>,
|
|
10
|
+
isPresent: (value: T) => boolean = () => true
|
|
11
|
+
) {
|
|
12
|
+
let registered = false
|
|
13
|
+
const clear = () => {
|
|
14
|
+
if (!registered) return
|
|
15
|
+
registered = false
|
|
16
|
+
engine.deletePresence(registration.registrationId)
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
publish(value: T, active: boolean) {
|
|
20
|
+
if (!active || !isPresent(value)) {
|
|
21
|
+
clear()
|
|
22
|
+
return
|
|
23
|
+
}
|
|
24
|
+
registered = true
|
|
25
|
+
engine.setPresence({ ...registration, value })
|
|
26
|
+
},
|
|
27
|
+
clear
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Encode whole IDs before joining them, so a slash inside an ID cannot become
|
|
2
|
+
// a group boundary. React-generated IDs never form part of shared targets.
|
|
3
|
+
export function presenceTarget(...ids: string[]): string {
|
|
4
|
+
if (!ids.length || ids.some(id => typeof id !== 'string' || !id.trim())) {
|
|
5
|
+
throw new Error(
|
|
6
|
+
'PresenceGroup, PresenceFrame, PresenceGutter, and Selection require a nonempty id.'
|
|
7
|
+
)
|
|
8
|
+
}
|
|
9
|
+
return ids.map(id => encodeURIComponent(id)).join('/')
|
|
10
|
+
}
|
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
import { useCallback, useLayoutEffect, useMemo, useRef } from 'react'
|
|
2
|
+
import type { HTMLAttributes, ReactNode, Ref } from 'react'
|
|
3
|
+
|
|
4
|
+
import { IconUser } from '@tabler/icons-react'
|
|
5
|
+
import { wcagLuminance } from 'culori'
|
|
6
|
+
|
|
7
|
+
import { cn } from '@/client/lib/cn'
|
|
8
|
+
import { Avatar, AvatarBadge, AvatarFallback, AvatarImage } from '@/ui-components/avatar'
|
|
9
|
+
import { Badge } from '@/ui-components/badge'
|
|
10
|
+
|
|
11
|
+
import { facehashDataUrl } from './facehash-avatar'
|
|
12
|
+
import { useUser, useUsers } from './hooks'
|
|
13
|
+
import { userDisplayName } from './people'
|
|
14
|
+
import { motion } from 'motion/react'
|
|
15
|
+
|
|
16
|
+
// User components resolve IDs through the current workspace directory,
|
|
17
|
+
// which resolves to the current name, face, and status through the workspace.
|
|
18
|
+
|
|
19
|
+
export type UserSize = 'xs' | 'sm' | 'md' | 'lg'
|
|
20
|
+
const AVATAR_SIZE = { xs: 'xs', sm: 'sm', md: 'default', lg: 'lg' } as const
|
|
21
|
+
// Shown for an id nobody in this workspace has ever used.
|
|
22
|
+
const UNKNOWN_NAME = 'Unknown user'
|
|
23
|
+
|
|
24
|
+
// Black or white, whichever reads on the person's color.
|
|
25
|
+
export function readableOn(color: string): string {
|
|
26
|
+
return (wcagLuminance(color) ?? 0) > 0.3 ? 'oklch(0 0 0)' : 'oklch(1 0 0)'
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Identity colors are data. They land on the node as custom properties
|
|
30
|
+
// instead of stylesheet rules; classes read `--collab-color` and
|
|
31
|
+
// `--collab-contrast` from there. An unknown person gets quiet theme tones.
|
|
32
|
+
export function useUserColor(color: string | undefined) {
|
|
33
|
+
return useCallback(
|
|
34
|
+
(node: HTMLElement | null) => {
|
|
35
|
+
if (!node) return
|
|
36
|
+
node.style.setProperty('--collab-color', color ?? 'var(--muted-foreground)')
|
|
37
|
+
node.style.setProperty('--collab-contrast', color ? readableOn(color) : 'var(--background)')
|
|
38
|
+
},
|
|
39
|
+
[color]
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type UserProps = {
|
|
44
|
+
id: string
|
|
45
|
+
size?: UserSize
|
|
46
|
+
// Only the face, for stacks, gutters, and tight rows.
|
|
47
|
+
avatarOnly?: boolean
|
|
48
|
+
you?: boolean
|
|
49
|
+
// A quiet second line: where they are, what they are doing. The compact
|
|
50
|
+
// `xs` size keeps it on the same line.
|
|
51
|
+
detail?: ReactNode
|
|
52
|
+
// The green dot: this person has the workspace open in a visible tab right
|
|
53
|
+
// now. Away (every tab hidden) and offline people never get one.
|
|
54
|
+
showStatus?: boolean
|
|
55
|
+
label?: string
|
|
56
|
+
className?: string
|
|
57
|
+
}
|
|
58
|
+
export function User({
|
|
59
|
+
id,
|
|
60
|
+
size = 'md',
|
|
61
|
+
avatarOnly = false,
|
|
62
|
+
you = false,
|
|
63
|
+
detail,
|
|
64
|
+
showStatus = true,
|
|
65
|
+
label,
|
|
66
|
+
className
|
|
67
|
+
}: UserProps) {
|
|
68
|
+
const identity = useUser(id)
|
|
69
|
+
const name = identity ? userDisplayName(identity) : UNKNOWN_NAME
|
|
70
|
+
// A profile without a picture gets the same generated face on every client,
|
|
71
|
+
// so nobody shows up as bare initials.
|
|
72
|
+
const picture = identity?.avatar
|
|
73
|
+
const faceName = identity ? name : undefined
|
|
74
|
+
const faceColor = identity?.color
|
|
75
|
+
const face = useMemo(
|
|
76
|
+
() => (faceName && faceColor ? (picture ?? facehashDataUrl(faceName, faceColor)) : undefined),
|
|
77
|
+
[picture, faceName, faceColor]
|
|
78
|
+
)
|
|
79
|
+
const compact = size === 'xs'
|
|
80
|
+
const avatar = (
|
|
81
|
+
<Avatar
|
|
82
|
+
size={AVATAR_SIZE[size]}
|
|
83
|
+
title={label ?? name}
|
|
84
|
+
aria-label={label ?? name}
|
|
85
|
+
className={avatarOnly ? className : undefined}
|
|
86
|
+
>
|
|
87
|
+
{face && <AvatarImage src={face} alt="" />}
|
|
88
|
+
<AvatarFallback>
|
|
89
|
+
{identity ? (
|
|
90
|
+
name.slice(0, 2).toUpperCase()
|
|
91
|
+
) : (
|
|
92
|
+
<IconUser size={size === 'xs' || size === 'sm' ? 12 : 16} stroke={1.75} />
|
|
93
|
+
)}
|
|
94
|
+
</AvatarFallback>
|
|
95
|
+
{showStatus && identity?.status === 'active' && <AvatarBadge className="bg-success" />}
|
|
96
|
+
</Avatar>
|
|
97
|
+
)
|
|
98
|
+
if (avatarOnly) return avatar
|
|
99
|
+
return (
|
|
100
|
+
<span
|
|
101
|
+
className={cn(
|
|
102
|
+
'inline-flex min-w-0 items-center',
|
|
103
|
+
size === 'lg' ? 'gap-3' : compact ? 'gap-1.5' : 'gap-2',
|
|
104
|
+
className
|
|
105
|
+
)}
|
|
106
|
+
>
|
|
107
|
+
{avatar}
|
|
108
|
+
<span className={cn('flex min-w-0', compact ? 'items-baseline gap-1' : 'flex-col')}>
|
|
109
|
+
<span
|
|
110
|
+
className={cn(
|
|
111
|
+
'truncate text-sm',
|
|
112
|
+
size === 'lg' && 'font-medium',
|
|
113
|
+
!identity && 'text-muted-foreground'
|
|
114
|
+
)}
|
|
115
|
+
>
|
|
116
|
+
{name}
|
|
117
|
+
{you && <span className="font-normal text-muted-foreground"> (you)</span>}
|
|
118
|
+
</span>
|
|
119
|
+
{detail && (
|
|
120
|
+
<span className="truncate text-xs text-muted-foreground">
|
|
121
|
+
{compact && <span aria-hidden="true">· </span>}
|
|
122
|
+
{detail}
|
|
123
|
+
</span>
|
|
124
|
+
)}
|
|
125
|
+
</span>
|
|
126
|
+
</span>
|
|
127
|
+
)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export type FacepileProps = {
|
|
131
|
+
ids: readonly string[]
|
|
132
|
+
max?: number
|
|
133
|
+
size?: 'xs' | 'sm' | 'md'
|
|
134
|
+
// Dots are off in a pile, where they crowd the overlapping faces.
|
|
135
|
+
showStatus?: boolean
|
|
136
|
+
className?: string
|
|
137
|
+
}
|
|
138
|
+
export function Facepile({
|
|
139
|
+
ids,
|
|
140
|
+
max = 3,
|
|
141
|
+
size = 'sm',
|
|
142
|
+
showStatus = false,
|
|
143
|
+
className
|
|
144
|
+
}: FacepileProps) {
|
|
145
|
+
const unique = [...new Set(ids)]
|
|
146
|
+
const shown = unique.slice(0, max)
|
|
147
|
+
const hidden = unique.length - shown.length
|
|
148
|
+
return (
|
|
149
|
+
<span
|
|
150
|
+
className={cn(
|
|
151
|
+
'inline-flex items-center',
|
|
152
|
+
size === 'xs' ? '-space-x-1.5' : '-space-x-2',
|
|
153
|
+
className
|
|
154
|
+
)}
|
|
155
|
+
aria-label={`${unique.length} people`}
|
|
156
|
+
>
|
|
157
|
+
{shown.map(id => (
|
|
158
|
+
<User
|
|
159
|
+
key={id}
|
|
160
|
+
id={id}
|
|
161
|
+
avatarOnly
|
|
162
|
+
size={size}
|
|
163
|
+
showStatus={showStatus}
|
|
164
|
+
className="ring-2 ring-background"
|
|
165
|
+
/>
|
|
166
|
+
))}
|
|
167
|
+
{hidden > 0 && (
|
|
168
|
+
<Avatar
|
|
169
|
+
size={AVATAR_SIZE[size]}
|
|
170
|
+
className="ring-2 ring-background"
|
|
171
|
+
title={`${hidden} more`}
|
|
172
|
+
>
|
|
173
|
+
<AvatarFallback>+{hidden}</AvatarFallback>
|
|
174
|
+
</Avatar>
|
|
175
|
+
)}
|
|
176
|
+
</span>
|
|
177
|
+
)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
type UserTagProps = {
|
|
181
|
+
name: string
|
|
182
|
+
color: string | undefined
|
|
183
|
+
icon?: ReactNode
|
|
184
|
+
className?: string
|
|
185
|
+
}
|
|
186
|
+
// The kit's badge in the person's color, wherever a name marks a place.
|
|
187
|
+
function UserTag({ name, color, icon, className }: UserTagProps) {
|
|
188
|
+
return (
|
|
189
|
+
<Badge
|
|
190
|
+
ref={useUserColor(color)}
|
|
191
|
+
className={cn('bg-(--collab-color) text-(--collab-contrast)', className)}
|
|
192
|
+
>
|
|
193
|
+
{icon}
|
|
194
|
+
<span className="truncate">{name}</span>
|
|
195
|
+
</Badge>
|
|
196
|
+
)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export type CursorProps = {
|
|
200
|
+
id: string
|
|
201
|
+
// Pointer tip in the parent's coordinate space. Leave both out to place the
|
|
202
|
+
// node yourself through `ref`.
|
|
203
|
+
x?: number
|
|
204
|
+
y?: number
|
|
205
|
+
label?: boolean
|
|
206
|
+
className?: string
|
|
207
|
+
ref?: Ref<HTMLSpanElement>
|
|
208
|
+
}
|
|
209
|
+
export function Cursor({ id, x, y, label = true, className, ref }: CursorProps) {
|
|
210
|
+
const identity = useUser(id)
|
|
211
|
+
const node = useRef<HTMLSpanElement | null>(null)
|
|
212
|
+
const setColor = useUserColor(identity?.color)
|
|
213
|
+
const attach = useCallback(
|
|
214
|
+
(element: HTMLSpanElement | null) => {
|
|
215
|
+
node.current = element
|
|
216
|
+
setColor(element)
|
|
217
|
+
if (typeof ref === 'function') ref(element)
|
|
218
|
+
else if (ref) ref.current = element
|
|
219
|
+
},
|
|
220
|
+
[ref, setColor]
|
|
221
|
+
)
|
|
222
|
+
useLayoutEffect(() => {
|
|
223
|
+
if (node.current && x !== undefined && y !== undefined)
|
|
224
|
+
node.current.style.transform = `translate(${x}px, ${y}px)`
|
|
225
|
+
}, [x, y])
|
|
226
|
+
return (
|
|
227
|
+
<span
|
|
228
|
+
ref={attach}
|
|
229
|
+
aria-hidden="true"
|
|
230
|
+
className={cn(
|
|
231
|
+
'pointer-events-none absolute top-0 left-0 transition-transform duration-100 ease-linear motion-reduce:transition-none',
|
|
232
|
+
className
|
|
233
|
+
)}
|
|
234
|
+
>
|
|
235
|
+
<span className="relative block animate-in duration-200 zoom-in-75 fade-in">
|
|
236
|
+
<svg viewBox="0 0 20 20" className="size-5 drop-shadow-sm" fill="var(--collab-color)">
|
|
237
|
+
<path d="M1 1 17.5 10.5 9.8 12.2 6 19.5Z" />
|
|
238
|
+
</svg>
|
|
239
|
+
{label && (
|
|
240
|
+
<UserTag
|
|
241
|
+
name={identity ? userDisplayName(identity) : 'Someone'}
|
|
242
|
+
color={identity?.color}
|
|
243
|
+
className="absolute top-4 left-3.5"
|
|
244
|
+
/>
|
|
245
|
+
)}
|
|
246
|
+
</span>
|
|
247
|
+
</span>
|
|
248
|
+
)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export type PresenceFramePrimitiveProps = HTMLAttributes<HTMLDivElement> & {
|
|
252
|
+
ref?: Ref<HTMLDivElement>
|
|
253
|
+
// Everyone at this element; the first person's color draws the frame.
|
|
254
|
+
ids: readonly string[]
|
|
255
|
+
icon?: ReactNode
|
|
256
|
+
children: ReactNode
|
|
257
|
+
}
|
|
258
|
+
// Wraps anything. With one element inside, the frame hugs that element and
|
|
259
|
+
// takes its corner radius, so a field, a card, a button, and a round avatar
|
|
260
|
+
// each get a frame of their own shape with no styling from the caller.
|
|
261
|
+
export function PresenceFramePrimitive({
|
|
262
|
+
ids,
|
|
263
|
+
icon,
|
|
264
|
+
children,
|
|
265
|
+
className,
|
|
266
|
+
...rest
|
|
267
|
+
}: PresenceFramePrimitiveProps) {
|
|
268
|
+
const resolved = useUsers(ids).filter(user => user !== null)
|
|
269
|
+
const lead = resolved[0]
|
|
270
|
+
return (
|
|
271
|
+
<div className={cn('relative', className)} {...rest}>
|
|
272
|
+
{children}
|
|
273
|
+
{lead && (
|
|
274
|
+
<FrameOutline
|
|
275
|
+
names={resolved.map(userDisplayName).join(', ')}
|
|
276
|
+
color={lead.color}
|
|
277
|
+
icon={icon}
|
|
278
|
+
/>
|
|
279
|
+
)}
|
|
280
|
+
</div>
|
|
281
|
+
)
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// A name does not fit within a frame narrower than this, so its tag starts at
|
|
285
|
+
// the frame's left edge and runs past it instead of ending at the right edge.
|
|
286
|
+
const NARROW_FRAME = 160
|
|
287
|
+
const CORNERS = [
|
|
288
|
+
'borderTopLeftRadius',
|
|
289
|
+
'borderTopRightRadius',
|
|
290
|
+
'borderBottomRightRadius',
|
|
291
|
+
'borderBottomLeftRadius'
|
|
292
|
+
] as const
|
|
293
|
+
|
|
294
|
+
type FrameOutlineProps = { names: string; color: string | undefined; icon?: ReactNode }
|
|
295
|
+
function FrameOutline({ names, color, icon }: FrameOutlineProps) {
|
|
296
|
+
const node = useRef<HTMLDivElement | null>(null)
|
|
297
|
+
const setColor = useUserColor(color)
|
|
298
|
+
const attach = useCallback(
|
|
299
|
+
(element: HTMLDivElement | null) => {
|
|
300
|
+
node.current = element
|
|
301
|
+
setColor(element)
|
|
302
|
+
},
|
|
303
|
+
[setColor]
|
|
304
|
+
)
|
|
305
|
+
// Runs after every render, because whatever is wrapped may have changed shape
|
|
306
|
+
// in the same render, and again whenever the wrapped element resizes.
|
|
307
|
+
useLayoutEffect(() => {
|
|
308
|
+
const outline = node.current
|
|
309
|
+
const frame = outline?.parentElement
|
|
310
|
+
if (!outline || !frame) return
|
|
311
|
+
const fit = () => {
|
|
312
|
+
// The one in-flow element inside is what the frame is about; hidden
|
|
313
|
+
// inputs and other out-of-flow helpers beside it do not count. With
|
|
314
|
+
// several elements, or bare text, the frame goes around all of it.
|
|
315
|
+
const inside = [...frame.children].filter(child => {
|
|
316
|
+
if (child === outline) return false
|
|
317
|
+
const { display, position } = getComputedStyle(child)
|
|
318
|
+
return display !== 'none' && position !== 'absolute' && position !== 'fixed'
|
|
319
|
+
})
|
|
320
|
+
const bareText = [...frame.childNodes].some(
|
|
321
|
+
child => child.nodeType === Node.TEXT_NODE && child.textContent?.trim()
|
|
322
|
+
)
|
|
323
|
+
const only = inside.length === 1 && !bareText ? inside[0] : null
|
|
324
|
+
const subject = only instanceof HTMLElement ? only : null
|
|
325
|
+
const box = outline.style
|
|
326
|
+
box.left = subject ? `${subject.offsetLeft}px` : ''
|
|
327
|
+
box.top = subject ? `${subject.offsetTop}px` : ''
|
|
328
|
+
box.right = subject ? 'auto' : ''
|
|
329
|
+
box.bottom = subject ? 'auto' : ''
|
|
330
|
+
box.width = subject ? `${subject.offsetWidth}px` : ''
|
|
331
|
+
box.height = subject ? `${subject.offsetHeight}px` : ''
|
|
332
|
+
// Square elements, usually bare text, keep the outline's own slight
|
|
333
|
+
// rounding and get more air so the content does not touch the line.
|
|
334
|
+
const shape = getComputedStyle(subject ?? frame)
|
|
335
|
+
const rounded = CORNERS.some(corner => parseFloat(shape[corner]) > 0)
|
|
336
|
+
for (const corner of CORNERS) box[corner] = rounded ? shape[corner] : ''
|
|
337
|
+
// Both states are spelled out, and every class that depends on them is a
|
|
338
|
+
// variant: inside an applet, the applet's own copy of a bare utility
|
|
339
|
+
// outranks a host variant that tries to override it.
|
|
340
|
+
outline.dataset.shape = rounded ? 'rounded' : 'square'
|
|
341
|
+
outline.dataset.tag = (subject ?? frame).offsetWidth < NARROW_FRAME ? 'start' : 'end'
|
|
342
|
+
}
|
|
343
|
+
fit()
|
|
344
|
+
const observer = new ResizeObserver(fit)
|
|
345
|
+
observer.observe(frame)
|
|
346
|
+
for (const child of frame.children) if (child !== outline) observer.observe(child)
|
|
347
|
+
return () => observer.disconnect()
|
|
348
|
+
})
|
|
349
|
+
return (
|
|
350
|
+
<div
|
|
351
|
+
ref={attach}
|
|
352
|
+
className="group/frame pointer-events-none absolute inset-0 animate-in rounded-sm outline-2 outline-(--collab-color) duration-150 fade-in data-[shape=rounded]:outline-offset-2 data-[shape=square]:outline-offset-4"
|
|
353
|
+
>
|
|
354
|
+
<UserTag
|
|
355
|
+
name={names}
|
|
356
|
+
color={color}
|
|
357
|
+
icon={icon}
|
|
358
|
+
className="absolute bottom-full group-data-[shape=rounded]/frame:mb-1.5 group-data-[shape=square]/frame:mb-2 group-data-[tag=end]/frame:right-0 group-data-[tag=end]/frame:max-w-full group-data-[tag=start]/frame:left-0 group-data-[tag=start]/frame:max-w-40"
|
|
359
|
+
/>
|
|
360
|
+
</div>
|
|
361
|
+
)
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
export type PresenceGutterPrimitiveProps = HTMLAttributes<HTMLDivElement> & {
|
|
365
|
+
ref?: Ref<HTMLDivElement>
|
|
366
|
+
users: readonly { id: string; connectionId: string }[]
|
|
367
|
+
children: ReactNode
|
|
368
|
+
animate?: boolean
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// A target owns its own gutter. Optional group-scoped layout IDs let the same
|
|
372
|
+
// user's face glide between targets without searching or guessing DOM order.
|
|
373
|
+
export function PresenceGutterPrimitive({
|
|
374
|
+
users,
|
|
375
|
+
children,
|
|
376
|
+
animate = false,
|
|
377
|
+
className,
|
|
378
|
+
...rest
|
|
379
|
+
}: PresenceGutterPrimitiveProps) {
|
|
380
|
+
return (
|
|
381
|
+
<div className={cn('relative pl-8', className)} {...rest}>
|
|
382
|
+
{children}
|
|
383
|
+
<div className="pointer-events-none absolute top-0 left-0 flex -space-x-3" aria-hidden="true">
|
|
384
|
+
{users.map(({ id, connectionId }) => (
|
|
385
|
+
<motion.span key={id} layoutId={animate ? `presence:${connectionId}` : undefined}>
|
|
386
|
+
<User
|
|
387
|
+
id={id}
|
|
388
|
+
avatarOnly
|
|
389
|
+
size="xs"
|
|
390
|
+
showStatus={false}
|
|
391
|
+
className="animate-in ring-2 ring-background duration-200 zoom-in-75 fade-in"
|
|
392
|
+
/>
|
|
393
|
+
</motion.span>
|
|
394
|
+
))}
|
|
395
|
+
</div>
|
|
396
|
+
</div>
|
|
397
|
+
)
|
|
398
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ProxyIdentity } from '@/lib/collab/types'
|
|
2
|
+
|
|
3
|
+
import { requestJson } from '@/client/api/http'
|
|
4
|
+
import { onWorkspaceEventsReconnect } from '@/client/runtime/useWorkspaceEvents'
|
|
5
|
+
|
|
6
|
+
import { setProxyIdentity } from './identity'
|
|
7
|
+
|
|
8
|
+
// GET /api/identity: the viewer as verified by a proxy in front of moi, such as
|
|
9
|
+
// Cloudflare Access. A failed request keeps the current identity.
|
|
10
|
+
async function fetchProxyIdentity(): Promise<void> {
|
|
11
|
+
try {
|
|
12
|
+
setProxyIdentity(await requestJson<ProxyIdentity>('/api/identity'))
|
|
13
|
+
} catch {}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Loaded before the app mounts, like startup config, so workspaces choose
|
|
17
|
+
// between shared and personal navigation with the inherited identity already
|
|
18
|
+
// in place. A server restart can change the proxy config, so reconnects refetch.
|
|
19
|
+
export async function loadProxyIdentity(): Promise<void> {
|
|
20
|
+
await fetchProxyIdentity()
|
|
21
|
+
onWorkspaceEventsReconnect(() => {
|
|
22
|
+
void fetchProxyIdentity()
|
|
23
|
+
})
|
|
24
|
+
}
|