Files
outline/app/hooks/useDocumentMenuAction.tsx
T
Tom Moor d57db81c6b feat: Split view (#13044)
Adds the ability to open a second route alongside the current one:

- The secondary route is stored in a `split` query string parameter so
  that reloading the page hydrates both panes.
- The secondary pane runs in its own in-memory router kept in sync with
  the query parameter, so links followed inside the pane navigate the
  pane rather than the primary route.
- Navigation while a split is open preserves the split, is directed to
  the focused pane, and routes that cannot render in a pane (such as
  settings) close the split.
- The focused pane is shown with an accent outline, updated as panes are
  clicked or focused, and keyboard shortcuts only apply to the focused
  pane.
- "Open in split view" added to document and collection menus and the
  command bar.
2026-07-19 11:57:33 -04:00

127 lines
3.5 KiB
TypeScript

import { useCallback } from "react";
import { useTranslation } from "react-i18next";
import { InputIcon, SearchIcon } from "outline-icons";
import { ActionSeparator, createAction, createRootMenuAction } from "~/actions";
import {
restoreDocument,
unsubscribeDocument,
subscribeDocument,
restoreDocumentToCollection,
starDocument,
unstarDocument,
editDocument,
shareDocument,
createNewDocument,
createNewDocumentInAlphabeticalCollection,
importDocument,
createTemplateFromDocument,
duplicateDocument,
publishDocument,
unpublishDocument,
archiveDocument,
moveDocument,
applyTemplateFactory,
pinDocument,
openDocumentComments,
openDocumentHistory,
openDocumentInsights,
openDocumentInDesktop,
openDocumentInSplit,
downloadDocument,
copyDocument,
presentDocument,
printDocument,
searchInDocument,
deleteDocument,
leaveDocument,
permanentlyDeleteDocument,
} from "~/actions/definitions/documents";
import { ActiveDocumentSection } from "~/actions/sections";
import useMobile from "./useMobile";
import type Template from "~/models/Template";
import usePolicy from "./usePolicy";
import { useTemplateMenuActions } from "./useTemplateMenuActions";
type Props = {
/** Document ID for which the actions are generated */
documentId: string;
/** Invoked when the "Find and replace" menu item is clicked */
onFindAndReplace?: () => void;
/** Invoked when the "Rename" menu item is clicked */
onRename?: () => void;
/** Callback when a template is selected to apply its content to the document */
onSelectTemplate?: (template: Template) => void;
};
export function useDocumentMenuAction({
documentId,
onFindAndReplace,
onRename,
onSelectTemplate,
}: Props) {
const { t } = useTranslation();
const isMobile = useMobile();
const can = usePolicy(documentId);
const templateMenuActions = useTemplateMenuActions({
documentId,
onSelectTemplate,
});
return useCallback(
() =>
createRootMenuAction([
restoreDocument,
restoreDocumentToCollection,
starDocument,
unstarDocument,
subscribeDocument,
unsubscribeDocument,
createAction({
name: `${t("Find and replace")}…`,
section: ActiveDocumentSection,
icon: <SearchIcon />,
visible: !!onFindAndReplace && isMobile,
perform: () => onFindAndReplace?.(),
}),
ActionSeparator,
editDocument,
createAction({
name: `${t("Rename")}…`,
section: ActiveDocumentSection,
icon: <InputIcon />,
visible: !!can.update && !!onRename,
perform: () => requestAnimationFrame(() => onRename?.()),
}),
shareDocument,
createTemplateFromDocument,
duplicateDocument,
publishDocument,
unpublishDocument,
archiveDocument,
moveDocument,
applyTemplateFactory({ actions: templateMenuActions }),
importDocument,
createNewDocument,
createNewDocumentInAlphabeticalCollection,
pinDocument,
ActionSeparator,
openDocumentComments,
openDocumentHistory,
openDocumentInsights,
openDocumentInSplit,
openDocumentInDesktop,
presentDocument,
downloadDocument,
copyDocument,
printDocument,
searchInDocument,
ActionSeparator,
deleteDocument,
permanentlyDeleteDocument,
leaveDocument,
]),
[t, isMobile, templateMenuActions, can.update, onFindAndReplace, onRename]
);
}