File
Blob: src/client/lib/affordance/share-page.ts
| 1 | import type { PageAccessLevel } from "@/shared/entitlements"; |
| 2 | import { deriveEditorAffordance, type EditorAffordance } from "@/client/lib/affordance/editor"; |
| 3 | import { deriveCanvasAffordance, type CanvasAffordance } from "@/client/lib/affordance/canvas"; |
| 4 | import type { PageKind } from "@/shared/types"; |
| 5 | |
| 6 | interface SharePageAffordanceBase { |
| 7 | showViewOnlyBadge: boolean; |
| 8 | } |
| 9 | |
| 10 | export type SharePageAffordance = |
| 11 | | (SharePageAffordanceBase & { |
| 12 | kind: "doc"; |
| 13 | editor: EditorAffordance; |
| 14 | }) |
| 15 | | (SharePageAffordanceBase & { |
| 16 | kind: "canvas"; |
| 17 | canvas: CanvasAffordance; |
| 18 | }); |
| 19 | |
| 20 | export function deriveSharePageAffordance(input: { |
| 21 | pageKind: PageKind; |
| 22 | pageAccess: PageAccessLevel; |
| 23 | workspaceId: string | undefined; |
| 24 | online: boolean; |
| 25 | }): SharePageAffordance { |
| 26 | const { pageKind, pageAccess, workspaceId, online } = input; |
| 27 | if (pageKind === "canvas") { |
| 28 | const canvas = deriveCanvasAffordance({ |
| 29 | surface: "shared", |
| 30 | pageAccess, |
| 31 | workspaceId, |
| 32 | online, |
| 33 | }); |
| 34 | return { |
| 35 | kind: "canvas", |
| 36 | showViewOnlyBadge: !canvas.canEdit, |
| 37 | canvas, |
| 38 | }; |
| 39 | } |
| 40 | |
| 41 | const editor = deriveEditorAffordance({ |
| 42 | surface: "shared", |
| 43 | pageAccess, |
| 44 | workspaceId, |
| 45 | online, |
| 46 | // Shared surface entitlements deny every AI action regardless of role, so |
| 47 | // role is informational here. Emit "none" to make the link-scoped contract |
| 48 | // explicit at the callsite. |
| 49 | workspaceRole: "none", |
| 50 | }); |
| 51 | return { |
| 52 | kind: "doc", |
| 53 | showViewOnlyBadge: !editor.documentEditable, |
| 54 | editor, |
| 55 | }; |
| 56 | } |