import { useCallback, useRef, useState, type ReactNode } from "react"; import type YProvider from "y-partyserver/provider"; import { PageErrorState } from "@/client/components/ui/page-error-state"; import { PageTitleSection } from "@/client/components/ui/page-title-section"; import { Skeleton } from "@/client/components/ui/skeleton"; import { DocumentFrame, type DocumentOutlineMode, OUTLINE_RAIL_MEDIA_QUERY, PAGE_CONTENT_COLUMN_CLASS, PAGE_SHELL_CLASS, } from "@/shared/editor/presentation/document-layout"; import { useMediaQuery } from "@/client/hooks/use-media-query"; import type { EditorAffordance } from "@/client/lib/affordance/editor"; import { reportClientError } from "@/client/lib/report-client-error"; import { toast } from "@/client/components/toast-store"; import { EditorBody } from "./editor-body"; import { useEditorSession } from "./use-editor-session"; const INVALID_SCHEMA_MESSAGE = "This build can't parse this page. Reload to catch up."; const SNAPSHOT_ERROR_MESSAGE = "This page didn't load. Your connection might be flaky."; interface DocumentPageProps { pageId: string; initialTitle: string; onTitleChange?: (title: string) => void; onProvider?: (provider: YProvider | null) => void; shareToken?: string; workspaceId?: string; affordance: EditorAffordance; outlineMode: DocumentOutlineMode; chrome: ReactNode; docFooterLeading?: ReactNode; } export function DocumentPage({ pageId, initialTitle, onTitleChange, onProvider, shareToken, workspaceId, affordance, outlineMode, chrome, docFooterLeading, }: DocumentPageProps) { const [outlineTarget, setOutlineTargetState] = useState(null); const setOutlineTarget = useCallback((node: HTMLDivElement | null) => { setOutlineTargetState(node); }, []); // The rail layout is only realized in CSS at min-[1440px]; below that, an //