"use client"; import { useEntitySetContext } from "components/EntitySetProvider"; import { useEntity } from "src/replicache"; import { useEditorStates } from "src/state/useEditorState"; import { useUIState } from "src/useUIState"; import { CommentTiny } from "components/Icons/CommentTiny"; import { SelectionActionPopover } from "components/SelectionActionPopover"; import { startEditorCommentDraft } from "./editorCommentDraftActions"; import { useEditorCommentSheetStore } from "./editorCommentStores"; // Selecting text in a document text block floats a popover over the selection // with a Comment action. It reuses the published-post selection toolbar // (SelectionActionPopover) and mirrors the toolbar's EditorCommentButton so the two // entry points start the same comment draft. Mounted once for the whole // editor; the `pre[data-entityid]` container scopes it to the document text // editors (doc and canvas), not the comment/footnote composers. export function EditorCommentSelectionPopover() { let { permissions } = useEntitySetContext(); // Commenting is a write interaction; hide the affordance without write access if (!permissions.write) return null; return ( { let blockID = (container as HTMLElement).dataset.entityid; return blockID ? { blockID } : null; }} > {() => } ); } function EditorCommentSelectionButton() { let focusedBlock = useUIState((s) => s.focusedEntity); let pageID = focusedBlock?.entityType === "block" ? focusedBlock.parent : null; let pageType = useEntity(pageID, "page/type")?.data.value || "doc"; return ( ); }