The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Fix document boundaries (#75311)
Romeo Van Snickdbf7e231fed7
diff --git a/frontend/lint/module-boundaries.mjs b/frontend/lint/module-boundaries.mjsindex 71a24f4adb6..4639edbb531 100644--- a/frontend/lint/module-boundaries.mjs+++ b/frontend/lint/module-boundaries.mjs@@ -65,7 +65,6 @@ const elements = [createElement({ type: "shared", name: "data-studio" }),createElement({ type: "shared", name: "databases" }),createElement({ type: "shared", name: "detail-view" }),- createElement({ type: "shared", name: "documents" }),createElement({type: "shared",name: "embed",@@ -155,6 +154,7 @@ const elements = [// featurecreateElement({ type: "feature", name: "admin" }),createElement({ type: "feature", name: "dashboard" }),+ createElement({ type: "feature", name: "documents" }),createElement({type: "feature",name: "enterprise",diff --git a/frontend/src/metabase/comments/components/Discussion/Discussion.tsx b/frontend/src/metabase/comments/components/Discussion/Discussion.tsxindex 5411a77d889..cf8ece893c6 100644--- a/frontend/src/metabase/comments/components/Discussion/Discussion.tsx+++ b/frontend/src/metabase/comments/components/Discussion/Discussion.tsx@@ -9,8 +9,7 @@ import {} from "metabase/api";import { getCommentsUrl } from "metabase/comments/utils";import { useToast } from "metabase/common/hooks";-import { setHoveredChildTargetId } from "metabase/documents/documents.slice";-import { useDispatch, useSelector } from "metabase/redux";+import { useSelector } from "metabase/redux";import { getUser } from "metabase/selectors/user";import { Avatar, Stack, Timeline, rem } from "metabase/ui";import type {@@ -30,7 +29,7 @@ export interface DiscussionProps {comments: Comment[];targetId: EntityId;targetType: CommentEntityType;- enableHoverHighlight?: boolean;+ onHoverChange?: (childTargetId: string | undefined) => void;}export const Discussion = ({@@ -38,10 +37,9 @@ export const Discussion = ({comments,targetId,targetType,- enableHoverHighlight = false,+ onHoverChange,}: DiscussionProps) => {const currentUser = useSelector(getUser);- const dispatch = useDispatch();const [, setNewComment] = useState<DocumentContent>();const parentCommentId = comments[0].id;const [sendToast] = useToast();@@ -179,15 +177,13 @@ export const Discussion = ({handleToggleReaction(comment, emoji, t`Failed to remove reaction`);const handleMouseEnter = () => {- if (enableHoverHighlight && effectiveChildTargetId) {- dispatch(setHoveredChildTargetId(String(effectiveChildTargetId)));+ if (effectiveChildTargetId) {+ onHoverChange?.(String(effectiveChildTargetId));}};const handleMouseLeave = () => {- if (enableHoverHighlight) {- dispatch(setHoveredChildTargetId(undefined));- }+ onHoverChange?.(undefined);};return (diff --git a/frontend/src/metabase/comments/components/Discussions/Discussions.tsx b/frontend/src/metabase/comments/components/Discussions/Discussions.tsxindex d2f17c524a5..23efc5b4037 100644--- a/frontend/src/metabase/comments/components/Discussions/Discussions.tsx+++ b/frontend/src/metabase/comments/components/Discussions/Discussions.tsx@@ -11,7 +11,7 @@ export interface DiscussionProps {comments: Comment[];targetId: Comment["target_id"];targetType: Comment["target_type"];- enableHoverHighlight?: boolean;+ onHoverChange?: (childTargetId: string | undefined) => void;}export const Discussions = ({@@ -19,7 +19,7 @@ export const Discussions = ({comments,targetId,targetType,- enableHoverHighlight = false,+ onHoverChange,}: DiscussionProps) => {const threads = useMemo(() => getCommentThreads(comments, childTargetId),@@ -36,7 +36,7 @@ export const Discussions = ({comments={thread.comments}targetId={targetId}targetType={targetType}- enableHoverHighlight={enableHoverHighlight}+ onHoverChange={onHoverChange}/></Box></Fragment>diff --git a/frontend/src/metabase/common/components/CopyModal/CopyModal.tsx b/frontend/src/metabase/common/components/CopyModal/CopyModal.tsxindex 9287cb43fdc..a887a2c5e18 100644--- a/frontend/src/metabase/common/components/CopyModal/CopyModal.tsx+++ b/frontend/src/metabase/common/components/CopyModal/CopyModal.tsx@@ -3,7 +3,7 @@ import { t } from "ttag";import { useGetDefaultCollectionId } from "metabase/common/collections/hooks";import { CopyDashboardFormConnected } from "metabase/common/components/CopyDashboardForm";-import { DocumentCopyForm } from "metabase/documents/components/DocumentCopyForm/DocumentCopyForm";+import { DocumentCopyForm } from "metabase/common/components/DocumentCopyForm/DocumentCopyForm";import { CopyCardForm } from "metabase/questions/components/CopyCardForm/CopyCardForm";import { Modal } from "metabase/ui";diff --git a/frontend/src/metabase/documents/components/DocumentCopyForm/DocumentCopyForm.tsx b/frontend/src/metabase/common/components/DocumentCopyForm/DocumentCopyForm.tsxsimilarity index 100%rename from frontend/src/metabase/documents/components/DocumentCopyForm/DocumentCopyForm.tsxrename to frontend/src/metabase/common/components/DocumentCopyForm/DocumentCopyForm.tsxdiff --git a/frontend/src/metabase/documents/components/CommentsSidesheet/CommentsSidesheet.tsx b/frontend/src/metabase/documents/components/CommentsSidesheet/CommentsSidesheet.tsxindex dc68b4691b6..e7da7d10a45 100644--- a/frontend/src/metabase/documents/components/CommentsSidesheet/CommentsSidesheet.tsx+++ b/frontend/src/metabase/documents/components/CommentsSidesheet/CommentsSidesheet.tsx@@ -14,6 +14,7 @@ import {} from "metabase/comments/utils";import { useToast } from "metabase/common/hooks";import Animation from "metabase/css/core/animation.module.css";+import { setHoveredChildTargetId } from "metabase/documents/documents.slice";import { useDocumentState } from "metabase/documents/hooks/use-document-state";import { getCurrentDocument } from "metabase/documents/selectors";import { getListCommentsQuery } from "metabase/documents/utils/api";@@ -80,6 +81,13 @@ export const CommentsSidesheet = ({ params, onClose }: Props) => {onClose();}, [closeCommentSidebar, onClose]);+ const handleHoverChange = useCallback(+ (hoveredChildTargetId: string | undefined) => {+ dispatch(setHoveredChildTargetId(hoveredChildTargetId));+ },+ [dispatch],+ );+useEffect(() => {if (childTargetId == null) {closeSidebar();@@ -227,7 +235,9 @@ export const CommentsSidesheet = ({ params, onClose }: Props) => {<DiscussionschildTargetId={childTargetId === "all" ? null : childTargetId}comments={activeComments}- enableHoverHighlight={childTargetId === "all"}+ onHoverChange={+ childTargetId === "all" ? handleHoverChange : undefined+ }targetId={document.id}targetType="document"/>diff --git a/frontend/src/metabase/documents/components/Editor/DocumentBlockShell.tsx b/frontend/src/metabase/documents/components/Editor/DocumentBlockShell.tsxnew file mode 100644index 00000000000..9aaad8da08e--- /dev/null+++ b/frontend/src/metabase/documents/components/Editor/DocumentBlockShell.tsx@@ -0,0 +1,80 @@+import { NodeViewWrapper } from "@tiptap/react";+import cx from "classnames";++import S from "metabase/rich_text_editing/tiptap/extensions/extensions.module.css";+import type { BlockShellProps } from "metabase/rich_text_editing/tiptap/extensions/shared/BlockShell";++import { useBlockMenus } from "../../hooks/use-block-menus";++import { AnchorLinkMenu } from "./AnchorLinkMenu";+import { CommentsMenu } from "./CommentsMenu";++/**+ * Document-specific block shell injected into the editor's block node views.+ * Wraps the block content and adds the comment menu (and, for headings, the+ * anchor-link menu) driven by the document's comment state.+ */+export const DocumentBlockShell = ({+ node,+ editor,+ getPos,+ hideMenus,+ children,+}: BlockShellProps) => {+ const {+ _id,+ isOpen,+ isHovered,+ hovered,+ setHovered,+ unresolvedCommentsCount,+ document,+ shouldShowMenus,+ anchorUrl,+ setReferenceElement,+ commentsRefs,+ commentsFloatingStyles,+ anchorRefs,+ anchorFloatingStyles,+ } = useBlockMenus({ node, editor, getPos, shouldHideMenus: hideMenus });++ const isHeading = node.type.name === "heading";++ return (+ <>+ <NodeViewWrapper+ aria-expanded={isOpen}+ className={cx(S.root, {+ [S.open]: isOpen || isHovered,+ })}+ data-node-id={_id}+ ref={setReferenceElement}+ onMouseOver={() => setHovered(true)}+ onMouseOut={() => setHovered(false)}+ >+ {children}+ </NodeViewWrapper>++ {shouldShowMenus && document && (+ <>+ {isHeading && (+ <AnchorLinkMenu+ ref={anchorRefs.setFloating}+ show={hovered}+ style={anchorFloatingStyles}+ url={anchorUrl}+ />+ )}+ <CommentsMenu+ active={isOpen}+ href={`/document/${document.id}/comments/${_id}`}+ ref={commentsRefs.setFloating}+ show={isOpen || hovered}+ style={commentsFloatingStyles}+ unresolvedCommentsCount={unresolvedCommentsCount}+ />+ </>+ )}+ </>+ );+};diff --git a/frontend/src/metabase/documents/components/Editor/DocumentEditorHost.tsx b/frontend/src/metabase/documents/components/Editor/DocumentEditorHost.tsxnew file mode 100644index 00000000000..e5b551a9e2f--- /dev/null+++ b/frontend/src/metabase/documents/components/Editor/DocumentEditorHost.tsx@@ -0,0 +1,81 @@+import type { ReactNode } from "react";++import {+ type EditorHost,+ EditorHostProvider,+} from "metabase/rich_text_editing/tiptap/EditorHost";++import { navigateToCardFromDocument } from "../../actions";+import {+ trackDocumentAddCard,+ trackDocumentAddSmartLink,+ trackDocumentAddSupportingText,+ trackDocumentAskMetabot,+ trackDocumentReplaceCard,+} from "../../analytics";+import {+ createDraftCard,+ generateDraftCardId,+ loadMetadataForDocumentCard,+ openVizSettingsSidebar,+ updateMentionsCache,+ updateVizSettings,+} from "../../documents.slice";+import { useCardData } from "../../hooks/use-card-data";+import { useDraftCardOperations } from "../../hooks/use-draft-card-operations";+import { useExternalCardDataLoader } from "../../hooks/use-external-card-data";+import {+ useNodeInViewport,+ useReportPrefetchLoading,+} from "../../hooks/use-node-in-viewport";+import { useUnresolvedCommentsCount } from "../../hooks/use-unresolved-comments-count";+import {+ getChildTargetId,+ getCurrentDocument,+ getHasUnsavedChanges,+ getHoveredChildTargetId,+} from "../../selectors";++/**+ * Concrete {@link EditorHost} that wires the document editor's state, actions,+ * analytics and data hooks into the document-agnostic `rich_text_editing`+ * extensions. Defined at module scope so its identity is stable.+ */+export const documentEditorHost: EditorHost = {+ selectors: {+ getCurrentDocument,+ getChildTargetId,+ getHoveredChildTargetId,+ getHasUnsavedChanges,+ },+ actions: {+ createDraftCard,+ generateDraftCardId,+ loadMetadataForDocumentCard,+ openVizSettingsSidebar,+ updateVizSettings,+ updateMentionsCache,+ },+ analytics: {+ trackAddCard: trackDocumentAddCard,+ trackAddSmartLink: trackDocumentAddSmartLink,+ trackAskMetabot: trackDocumentAskMetabot,+ trackReplaceCard: trackDocumentReplaceCard,+ trackAddSupportingText: trackDocumentAddSupportingText,+ },+ navigateToCard: navigateToCardFromDocument,+ useCardData,+ useExternalCardDataLoader,+ useUnresolvedCommentsCount,+ useNodeInViewport,+ useReportPrefetchLoading,+ useDraftCardOperations,+};++export const DocumentEditorHostProvider = ({+ children,+}: {+ children: ReactNode;+}) => (+ <EditorHostProvider value={documentEditorHost}>{children}</EditorHostProvider>+);diff --git a/frontend/src/metabase/documents/components/Editor/Editor.tsx b/frontend/src/metabase/documents/components/Editor/Editor.tsxindex 7c8961f56aa..fbb344abab1 100644--- a/frontend/src/metabase/documents/components/Editor/Editor.tsx+++ b/frontend/src/metabase/documents/components/Editor/Editor.tsx@@ -41,6 +41,8 @@ import { createSuggestionRenderer } from "metabase/rich_text_editing/tiptap/exteimport { getSetting } from "metabase/selectors/settings";import { Box, Center, Loader } from "metabase/ui";+import { DocumentBlockShell } from "./DocumentBlockShell";+import { DocumentEditorHostProvider } from "./DocumentEditorHost";import S from "./Editor.module.css";import { useCardEmbedsTracking, useQuestionSelection } from "./hooks";@@ -115,6 +117,7 @@ export const Editor: React.FC<EditorProps> = React.memo(width: 2,class: DropCursorS.dropCursor,},+ blockShell: DocumentBlockShell,}),Image.configure({inline: false,@@ -230,61 +233,63 @@ export const Editor: React.FC<EditorProps> = React.memo(}return (- <Box className={cx(S.editor, DND_IGNORE_CLASS_NAME)}>- <Box- className={S.editorContent}- ref={editorContainerRef}- onClick={(e) => {- // Focus editor when clicking on empty space- const target = e.target;- if (!(target instanceof HTMLElement)) {- return;- }+ <DocumentEditorHostProvider>+ <Box className={cx(S.editor, DND_IGNORE_CLASS_NAME)}>+ <Box+ className={S.editorContent}+ ref={editorContainerRef}+ onClick={(e) => {+ // Focus editor when clicking on empty space+ const target = e.target;+ if (!(target instanceof HTMLElement)) {+ return;+ }- if (- target.classList.contains(S.editorContent) ||- target.classList.contains("ProseMirror")- ) {- const clickY = e.clientY;- const proseMirrorElement = target.querySelector(".ProseMirror");+ if (+ target.classList.contains(S.editorContent) ||+ target.classList.contains("ProseMirror")+ ) {+ const clickY = e.clientY;+ const proseMirrorElement = target.querySelector(".ProseMirror");- if (proseMirrorElement) {- const proseMirrorRect =- proseMirrorElement.getBoundingClientRect();- const isClickBelowContent = clickY > proseMirrorRect.bottom;+ if (proseMirrorElement) {+ const proseMirrorRect =+ proseMirrorElement.getBoundingClientRect();+ const isClickBelowContent = clickY > proseMirrorRect.bottom;- if (isClickBelowContent) {- // Only move to end if clicking below the actual content- editor.commands.focus("end");+ if (isClickBelowContent) {+ // Only move to end if clicking below the actual content+ editor.commands.focus("end");+ } else {+ // Just focus without changing cursor position for clicks in padding areas+ editor.commands.focus();+ }} else {- // Just focus without changing cursor position for clicks in padding areas+ // Fallback: just focus without position changeeditor.commands.focus();}- } else {- // Fallback: just focus without position change- editor.commands.focus();}- }- }}- >- <EditorContent data-testid="document-content" editor={editor} />+ }}+ >+ <EditorContent data-testid="document-content" editor={editor} />- {editable && (- <EditorBubbleMenu- editor={editor}- disallowedNodes={BUBBLE_MENU_DISALLOWED_NODES}- disallowedFullySelectedNodes={- BUBBLE_MENU_DISALLOWED_FULLY_SELECTED_NODES- }- />- )}- <Box pos="absolute" top={0} left={0} w="100%">- <Box className={S.editorContentInner} pos="relative">- <LinkHoverMenu editor={editor} editable={editable} />+ {editable && (+ <EditorBubbleMenu+ editor={editor}+ disallowedNodes={BUBBLE_MENU_DISALLOWED_NODES}+ disallowedFullySelectedNodes={+ BUBBLE_MENU_DISALLOWED_FULLY_SELECTED_NODES+ }+ />+ )}+ <Box pos="absolute" top={0} left={0} w="100%">+ <Box className={S.editorContentInner} pos="relative">+ <LinkHoverMenu editor={editor} editable={editable} />+ </Box></Box></Box></Box>- </Box>+ </DocumentEditorHostProvider>);},);diff --git a/frontend/src/metabase/documents/components/Editor/constants.ts b/frontend/src/metabase/documents/components/Editor/constants.tsdeleted file mode 100644index 2ca6ab25420..00000000000--- a/frontend/src/metabase/documents/components/Editor/constants.ts+++ /dev/null@@ -1,2 +0,0 @@-// Class name used to prevent editor typography styles from affecting embedded content-export const EDITOR_STYLE_BOUNDARY_CLASS = "editor-style-boundary";diff --git a/frontend/src/metabase/documents/constants.ts b/frontend/src/metabase/documents/constants.tsindex 4e84398bdbf..6b2fb534c43 100644--- a/frontend/src/metabase/documents/constants.ts+++ b/frontend/src/metabase/documents/constants.ts@@ -1,3 +1 @@export const DOCUMENT_TITLE_MAX_LENGTH = 100;--export const MAX_GROUP_SIZE = 3;diff --git a/frontend/src/metabase/documents/hooks/use-card-data.ts b/frontend/src/metabase/documents/hooks/use-card-data.tsindex c8cb727fb54..3740b24705e 100644--- a/frontend/src/metabase/documents/hooks/use-card-data.ts+++ b/frontend/src/metabase/documents/hooks/use-card-data.ts@@ -6,6 +6,7 @@ import {useGetAdhocQueryQuery,} from "metabase/api/dataset";import { useSelector } from "metabase/redux";+import type { UseCardDataResult } from "metabase/rich_text_editing/tiptap/EditorHost";import { getMetadata } from "metabase/selectors/metadata";import Question from "metabase-lib/v1/Question";import { getPivotOptions } from "metabase-lib/v1/queries/utils/pivot";@@ -19,17 +20,6 @@ interface UseCardDataProps {skip?: boolean;}-export interface UseCardDataResult {- card?: Card;- dataset?: Dataset;- isLoading: boolean;- series: RawSeries | null;- question?: Question;- error?: "not found" | "unknown" | null;- draftCard?: Card;- regularDataset?: Dataset;-}-function buildAdhocQueryParams(card: Card) {return {...card.dataset_query,diff --git a/frontend/src/metabase/documents/hooks/use-external-card-data.ts b/frontend/src/metabase/documents/hooks/use-external-card-data.tsindex 4959f1307fe..780e56c7273 100644--- a/frontend/src/metabase/documents/hooks/use-external-card-data.ts+++ b/frontend/src/metabase/documents/hooks/use-external-card-data.ts@@ -1,14 +1,13 @@import { useMemo } from "react";import { skipToken, useGetPublicDocumentCardQueryQuery } from "metabase/api";-import { useExternalCardData } from "metabase/documents/contexts/ExternalCardDataContext";import { useSelector } from "metabase/redux";+import type { UseCardDataResult } from "metabase/rich_text_editing/tiptap/EditorHost";+import { useExternalCardData } from "metabase/rich_text_editing/tiptap/extensions/CardEmbed/ExternalCardDataContext";import { getMetadata } from "metabase/selectors/metadata";import Question from "metabase-lib/v1/Question";import type { Card, CardId, Dataset, RawSeries } from "metabase-types/api";-import type { UseCardDataResult } from "./use-card-data";-function buildSeries(card: Card, dataset: Dataset): RawSeries {return [{diff --git a/frontend/src/metabase/public/containers/PublicDocument/PublicDocument.tsx b/frontend/src/metabase/public/containers/PublicDocument/PublicDocument.tsxindex 8fb7dc3c448..4897daed686 100644--- a/frontend/src/metabase/public/containers/PublicDocument/PublicDocument.tsx+++ b/frontend/src/metabase/public/containers/PublicDocument/PublicDocument.tsx@@ -10,13 +10,14 @@ import { publicApi } from "metabase/api";import { runRtkEndpoint } from "metabase/api/utils/run-rtk-endpoint";import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";import CS from "metabase/css/core/index.css";-import { ExternalCardDataProvider } from "metabase/documents/contexts/ExternalCardDataContext";+import { DocumentEditorHostProvider } from "metabase/documents/components/Editor/DocumentEditorHost";import { EmbeddingEntityContextProvider } from "metabase/embedding/context";import { EmbedFrame } from "metabase/public/components/EmbedFrame";import { useEmbedFrameOptions } from "metabase/public/hooks";import { useDispatch, useSelector } from "metabase/redux";import { setErrorPage } from "metabase/redux/app";import { CardEmbed } from "metabase/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode";+import { ExternalCardDataProvider } from "metabase/rich_text_editing/tiptap/extensions/CardEmbed/ExternalCardDataContext";import { CustomStarterKit } from "metabase/rich_text_editing/tiptap/extensions/CustomStarterKit/CustomStarterKit";import { FlexContainer } from "metabase/rich_text_editing/tiptap/extensions/FlexContainer/FlexContainer";import { MetabotNode } from "metabase/rich_text_editing/tiptap/extensions/MetabotEmbed";@@ -154,17 +155,19 @@ export const PublicDocument = ({ location, params }: PublicDocumentProps) => {}}>{document && editor && (- <ExternalCardDataProvider value={externalCardDataValue}>- <Box maw={900} mx="auto" p="xl" w="100%">- <h1 style={{ marginBottom: "1rem" }}>{document.name}</h1>- <div className={S.editorContent}>- <EditorContent- data-testid="document-content"- editor={editor}- />- </div>- </Box>- </ExternalCardDataProvider>+ <DocumentEditorHostProvider>+ <ExternalCardDataProvider value={externalCardDataValue}>+ <Box maw={900} mx="auto" p="xl" w="100%">+ <h1 style={{ marginBottom: "1rem" }}>{document.name}</h1>+ <div className={S.editorContent}>+ <EditorContent+ data-testid="document-content"+ editor={editor}+ />+ </div>+ </Box>+ </ExternalCardDataProvider>+ </DocumentEditorHostProvider>)}</LoadingAndErrorWrapper></EmbedFrame>diff --git a/frontend/src/metabase/rich_text_editing/tiptap/EditorHost.tsx b/frontend/src/metabase/rich_text_editing/tiptap/EditorHost.tsxnew file mode 100644index 00000000000..66d4a731096--- /dev/null+++ b/frontend/src/metabase/rich_text_editing/tiptap/EditorHost.tsx@@ -0,0 +1,206 @@+import type { Editor } from "@tiptap/react";+import { createContext, useContext } from "react";++import type { State } from "metabase/redux/store";+import type Question from "metabase-lib/v1/Question";+import type {+ Card,+ Dataset,+ Document,+ RawSeries,+ VisualizationSettings,+} from "metabase-types/api";++/**+ * Result returned by the card-data hooks the host provides to the CardEmbed+ * extension. Declared by the editor primitive so extensions can depend on the+ * shape without importing the host (documents) implementation.+ */+export interface UseCardDataResult {+ card?: Card;+ dataset?: Dataset;+ isLoading: boolean;+ series: RawSeries | null;+ question?: Question;+ error?: "not found" | "unknown" | null;+ draftCard?: Card;+ regularDataset?: Dataset;+}++export interface DraftCardOperations {+ ensureDraftCard: (+ initialModifications?: Partial<Card>,+ isVizSettingsOnly?: boolean,+ ) => number;+}++/**+ * Viewport/prefetch state for a node view, produced by the host's+ * {@link EditorHost.useNodeInViewport}. Hosts without a scroll container+ * (comments, metabot) report everything as in-viewport so embedded content+ * loads eagerly.+ */+export interface NodeViewportState {+ ref: (instance: HTMLElement | null) => void;+ isInViewport: boolean;+ shouldLoadData: boolean;+}++type Selector<T> = (state: State) => T;++/**+ * A redux action or thunk produced by a host action creator. Broad by design+ * so injected creators dispatch cleanly through the app's overloaded dispatch.+ */+type DispatchableAction = any;++/** Document state read by most extensions, regardless of which are enabled. */+export interface EditorDocumentHost {+ selectors: {+ getCurrentDocument: Selector<Document | null>;+ getHasUnsavedChanges: Selector<boolean>;+ };+}++/** Embedding, rendering and authoring cards: the CardEmbed node, the+ * create/modify-question modals, and the Metabot embed. */+export interface EditorCardHost {+ navigateToCard: (+ url: string,+ document?: Document | null,+ ) => DispatchableAction;+ useCardData: (props: { id: number; skip?: boolean }) => UseCardDataResult;+ useExternalCardDataLoader: (+ cardId: number,+ opts?: { skip?: boolean },+ ) => UseCardDataResult;+ useDraftCardOperations: (+ draftCard: Card | null | undefined,+ card: Card | null | undefined,+ cardId: number,+ editorInstance: Editor | null | undefined,+ selectedEmbedIndex: number | null,+ regularDataset: Dataset | null | undefined,+ ) => DraftCardOperations;+ actions: {+ createDraftCard: (payload: {+ originalCard: Card | undefined;+ modifiedData: Partial<Card>;+ draftId: number;+ }) => DispatchableAction;+ generateDraftCardId: () => number;+ loadMetadataForDocumentCard: (card: Card) => DispatchableAction;+ openVizSettingsSidebar: (payload: {+ embedIndex: number;+ }) => DispatchableAction;+ updateVizSettings: (payload: {+ cardId: number;+ settings: VisualizationSettings;+ }) => DispatchableAction;+ };+}++/** Comment menus on blocks and card embeds. */+export interface EditorCommentsHost {+ selectors: {+ getChildTargetId: Selector<string | undefined>;+ getHoveredChildTargetId: Selector<string | undefined>;+ };+ useUnresolvedCommentsCount: (+ nodeId: string,+ opts?: { skip?: boolean },+ ) => number;+}++/** Viewport-aware lazy loading: hosts with a scroll container defer+ * data fetching until a node is near the viewport. The default host reports+ * everything as visible so other editors load eagerly. */+export interface EditorViewportHost {+ useNodeInViewport: (id?: string) => NodeViewportState;+ useReportPrefetchLoading: (id: string, isLoading: boolean) => void;+}++/** Mention / smart-link suggestions. */+export interface EditorMentionsHost {+ actions: {+ updateMentionsCache: (payload: {+ entityId: string;+ model: string;+ name: string;+ }) => DispatchableAction;+ };+}++/** Product analytics for editor affordances. */+export interface EditorAnalyticsHost {+ analytics: {+ trackAddCard: (document?: Document | null) => void;+ trackAddSmartLink: (document?: Document | null) => void;+ trackAskMetabot: (document?: Document | null) => void;+ trackReplaceCard: (document?: Document | null) => void;+ trackAddSupportingText: (document?: Document | null) => void;+ };+}++/**+ * The capabilities the editor extensions need, injected by the host so `rich_text_editing` stays an agnostic editor primitive.+ * Consumers that do not configure a host (e.g. the comments editor) get+ * {@link DEFAULT_EDITOR_HOST}.+ */+export type EditorHost = EditorDocumentHost &+ EditorCardHost &+ EditorCommentsHost &+ EditorViewportHost &+ EditorMentionsHost &+ EditorAnalyticsHost;++const noop = () => undefined;++/**+ * Inert host used when no provider is configured (e.g. the comments and metabot+ * editors). State selectors resolve to empty, operations are no-ops, and the+ * card-data hooks return idle results — the extensions that rely on a real host+ * (CardEmbed, SupportingText, Metabot embed) are only rendered by hosts that+ * provide one.+ */+export const DEFAULT_EDITOR_HOST: EditorHost = {+ selectors: {+ getCurrentDocument: () => null,+ getChildTargetId: () => undefined,+ getHoveredChildTargetId: () => undefined,+ getHasUnsavedChanges: () => false,+ },+ actions: {+ createDraftCard: () => ({ type: "@@editor-host/noop" }),+ generateDraftCardId: () => -1,+ loadMetadataForDocumentCard: () => ({ type: "@@editor-host/noop" }),+ openVizSettingsSidebar: () => ({ type: "@@editor-host/noop" }),+ updateVizSettings: () => ({ type: "@@editor-host/noop" }),+ updateMentionsCache: () => ({ type: "@@editor-host/noop" }),+ },+ analytics: {+ trackAddCard: noop,+ trackAddSmartLink: noop,+ trackAskMetabot: noop,+ trackReplaceCard: noop,+ trackAddSupportingText: noop,+ },+ navigateToCard: () => ({ type: "@@editor-host/noop" }),+ useCardData: () => ({ isLoading: false, series: null }),+ useExternalCardDataLoader: () => ({ isLoading: false, series: null }),+ useUnresolvedCommentsCount: () => 0,+ useNodeInViewport: () => ({+ ref: () => undefined,+ isInViewport: true,+ shouldLoadData: true,+ }),+ useReportPrefetchLoading: () => undefined,+ useDraftCardOperations: () => ({ ensureDraftCard: () => -1 }),+};++const EditorHostContext = createContext<EditorHost>(DEFAULT_EDITOR_HOST);++export const EditorHostProvider = EditorHostContext.Provider;++/** Access the host capabilities configured for the surrounding editor. */+export const useEditorHost = (): EditorHost => useContext(EditorHostContext);diff --git a/frontend/src/metabase/rich_text_editing/tiptap/components/EditorBubbleMenu/LinkEditor.tsx b/frontend/src/metabase/rich_text_editing/tiptap/components/EditorBubbleMenu/LinkEditor.tsxindex ddfbf4a4f18..5a059dec456 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/components/EditorBubbleMenu/LinkEditor.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/components/EditorBubbleMenu/LinkEditor.tsx@@ -1,7 +1,7 @@import { useEffect, useRef, useState } from "react";import { t } from "ttag";-import { processUrl } from "metabase/documents/utils/processUrl";+import { processUrl } from "metabase/rich_text_editing/tiptap/utils/processUrl";import {ActionIcon,Box,diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/Blockquote/Blockquote.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Blockquote/Blockquote.tsxindex a57039b2907..626684b2e85 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/Blockquote/Blockquote.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Blockquote/Blockquote.tsx@@ -1,19 +1,16 @@import type { NodeViewProps } from "@tiptap/core";-import { Blockquote } from "@tiptap/extension-blockquote";import {- NodeViewContent,- NodeViewWrapper,- ReactNodeViewRenderer,-} from "@tiptap/react";-import cx from "classnames";--import { CommentsMenu } from "metabase/documents/components/Editor/CommentsMenu";-import { useBlockMenus } from "metabase/documents/hooks/use-block-menus";+ Blockquote,+ type BlockquoteOptions,+} from "@tiptap/extension-blockquote";+import { NodeViewContent, ReactNodeViewRenderer } from "@tiptap/react";import { createIdAttribute, createProseMirrorPlugin } from "../NodeIds";-import S from "../extensions.module.css";+import { type BlockNodeOptions, DefaultBlockShell } from "../shared/BlockShell";-export const CustomBlockquote = Blockquote.extend({+export const CustomBlockquote = Blockquote.extend<+ BlockquoteOptions & BlockNodeOptions+>({addAttributes() {return {...createIdAttribute(),@@ -33,46 +30,22 @@ export const CustomBlockquote = Blockquote.extend({},});-export const BlockquoteNodeView = ({ node, editor, getPos }: NodeViewProps) => {- const {- _id,- isOpen,- isHovered,- hovered,- setHovered,- unresolvedCommentsCount,- document,- shouldShowMenus,- setReferenceElement,- commentsRefs,- commentsFloatingStyles,- } = useBlockMenus({ node, editor, getPos });+export const BlockquoteNodeView = ({+ node,+ editor,+ getPos,+ extension,+}: NodeViewProps) => {+ const BlockShell = extension.options.blockShell ?? DefaultBlockShell;return (- <>- <NodeViewWrapper- aria-expanded={isOpen}- className={cx(S.root, {- [S.open]: isOpen || isHovered,- })}- data-node-id={_id}- ref={setReferenceElement}- onMouseOver={() => setHovered(true)}- onMouseOut={() => setHovered(false)}- >- <NodeViewContent<"blockquote"> as="blockquote" />- </NodeViewWrapper>-- {shouldShowMenus && document && (- <CommentsMenu- active={isOpen}- href={`/document/${document.id}/comments/${_id}`}- ref={commentsRefs.setFloating}- show={isOpen || hovered}- style={commentsFloatingStyles}- unresolvedCommentsCount={unresolvedCommentsCount}- />- )}- </>+ <BlockShell+ node={node}+ editor={editor}+ getPos={getPos}+ hideMenus={extension.options.editorContext === "comments"}+ >+ <NodeViewContent<"blockquote"> as="blockquote" />+ </BlockShell>);};diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/BulletList/BulletList.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/BulletList/BulletList.tsxindex 7d3812e91db..a055c68a2c1 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/BulletList/BulletList.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/BulletList/BulletList.tsx@@ -1,19 +1,16 @@import type { NodeViewProps } from "@tiptap/core";-import { BulletList } from "@tiptap/extension-bullet-list";import {- NodeViewContent,- NodeViewWrapper,- ReactNodeViewRenderer,-} from "@tiptap/react";-import cx from "classnames";--import { CommentsMenu } from "metabase/documents/components/Editor/CommentsMenu";-import { useBlockMenus } from "metabase/documents/hooks/use-block-menus";+ BulletList,+ type BulletListOptions,+} from "@tiptap/extension-bullet-list";+import { NodeViewContent, ReactNodeViewRenderer } from "@tiptap/react";import { createIdAttribute, createProseMirrorPlugin } from "../NodeIds";-import S from "../extensions.module.css";+import { type BlockNodeOptions, DefaultBlockShell } from "../shared/BlockShell";-export const CustomBulletList = BulletList.extend({+export const CustomBulletList = BulletList.extend<+ BulletListOptions & BlockNodeOptions+>({addAttributes() {return {...createIdAttribute(),@@ -29,47 +26,22 @@ export const CustomBulletList = BulletList.extend({},});-export const BulletListNodeView = ({ node, editor, getPos }: NodeViewProps) => {- const {- _id,- isOpen,- isHovered,- hovered,- setHovered,- unresolvedCommentsCount,- document,- shouldShowMenus,- setReferenceElement,- commentsRefs,- commentsFloatingStyles,- } = useBlockMenus({ node, editor, getPos });+export const BulletListNodeView = ({+ node,+ editor,+ getPos,+ extension,+}: NodeViewProps) => {+ const BlockShell = extension.options.blockShell ?? DefaultBlockShell;return (- <>- <NodeViewWrapper- aria-expanded={isOpen}- className={cx(S.root, {- [S.open]: isOpen || isHovered,- })}- data-node-id={_id}- ref={setReferenceElement}- // onMouseEnter/onMouseLeave do not work on list elements living in contentEditable- onMouseOver={() => setHovered(true)}- onMouseOut={() => setHovered(false)}- >- <NodeViewContent<"ul"> as="ul" />- </NodeViewWrapper>-- {shouldShowMenus && document && (- <CommentsMenu- active={isOpen}- href={`/document/${document.id}/comments/${_id}`}- ref={commentsRefs.setFloating}- show={isOpen || hovered}- style={commentsFloatingStyles}- unresolvedCommentsCount={unresolvedCommentsCount}- />- )}- </>+ <BlockShell+ node={node}+ editor={editor}+ getPos={getPos}+ hideMenus={extension.options.editorContext === "comments"}+ >+ <NodeViewContent<"ul"> as="ul" />+ </BlockShell>);};diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode.tsxindex ff6201678b1..84681295c3e 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode.tsx@@ -18,32 +18,12 @@ import { ExplicitSizeRefreshModeContext } from "metabase/common/components/Expliimport { QuestionPickerModal } from "metabase/common/components/Pickers";import type { QuestionPickerValueItem } from "metabase/common/components/Pickers/QuestionPicker/types";import { useDownloadData } from "metabase/common/components/QuestionDownloadWidget/use-download-data";-import { navigateToCardFromDocument } from "metabase/documents/actions";-import {- trackDocumentAddSupportingText,- trackDocumentReplaceCard,-} from "metabase/documents/analytics";-import { EDITOR_STYLE_BOUNDARY_CLASS } from "metabase/documents/components/Editor/constants";-import { MAX_GROUP_SIZE } from "metabase/documents/constants";-import { useExternalCardData } from "metabase/documents/contexts/ExternalCardDataContext";-import {- loadMetadataForDocumentCard,- openVizSettingsSidebar,-} from "metabase/documents/documents.slice";-import { useCardData } from "metabase/documents/hooks/use-card-data";-import { useExternalCardDataLoader } from "metabase/documents/hooks/use-external-card-data";-import {- useNodeInViewport,- useReportPrefetchLoading,-} from "metabase/documents/hooks/use-node-in-viewport";-import { useUnresolvedCommentsCount } from "metabase/documents/hooks/use-unresolved-comments-count";-import {- getChildTargetId,- getCurrentDocument,- getHasUnsavedChanges,- getHoveredChildTargetId,-} from "metabase/documents/selectors";import { useDispatch, useSelector } from "metabase/redux";+import { useEditorHost } from "metabase/rich_text_editing/tiptap/EditorHost";+import {+ EDITOR_STYLE_BOUNDARY_CLASS,+ MAX_GROUP_SIZE,+} from "metabase/rich_text_editing/tiptap/extensions/shared/constants";import { DropZone } from "metabase/rich_text_editing/tiptap/extensions/shared/dnd/DropZone";import { getMetadata } from "metabase/selectors/metadata";import {@@ -77,6 +57,7 @@ import { useDndHelpers } from "../shared/dnd/use-dnd-helpers";import { CardEmbedLoadingState } from "./CardEmbedLoadingState";import { CardEmbedMenuDropdown } from "./CardEmbedMenuDropdown";import styles from "./CardEmbedNode.module.css";+import { useExternalCardData } from "./ExternalCardDataContext";import { ExternalDocumentCardMenu } from "./ExternalDocumentCardMenu";import { ModifyQuestionModal } from "./modals/ModifyQuestionModal";import { useUpdateCardOperations } from "./use-update-card-operations";@@ -171,21 +152,24 @@ export const CardEmbedComponent = memo(getPos,deleteNode,}: NodeViewProps) => {+ const host = useEditorHost();const { _id } = node.attrs;const {ref: viewportRef,isInViewport,shouldLoadData,- } = useNodeInViewport(_id);- const childTargetId = useSelector(getChildTargetId);- const hoveredChildTargetId = useSelector(getHoveredChildTargetId);- const document = useSelector(getCurrentDocument);+ } = host.useNodeInViewport(_id);+ const childTargetId = useSelector(host.selectors.getChildTargetId);+ const hoveredChildTargetId = useSelector(+ host.selectors.getHoveredChildTargetId,+ );+ const document = useSelector(host.selectors.getCurrentDocument);const externalCardData = useExternalCardData();- const unresolvedCommentsCount = useUnresolvedCommentsCount(_id, {+ const unresolvedCommentsCount = host.useUnresolvedCommentsCount(_id, {skip: !isInViewport,});- const hasUnsavedChanges = useSelector(getHasUnsavedChanges);+ const hasUnsavedChanges = useSelector(host.selectors.getHasUnsavedChanges);const isOpen = childTargetId === _id;const isHovered = hoveredChildTargetId === _id;const commentsPath = document@@ -207,8 +191,8 @@ export const CardEmbedComponent = memo(// Use external hook when viewing an externally-rendered document (e.g. public), otherwise use regular hookconst isExternalDocument = externalCardData != null;- const regularCardData = useCardData({ id, skip: !shouldLoadData });- const externalCardDataResult = useExternalCardDataLoader(id, {+ const regularCardData = host.useCardData({ id, skip: !shouldLoadData });+ const externalCardDataResult = host.useExternalCardDataLoader(id, {skip: !shouldLoadData,});@@ -216,7 +200,7 @@ export const CardEmbedComponent = memo(? externalCardDataResult: regularCardData;- useReportPrefetchLoading(_id, isLoading);+ host.useReportPrefetchLoading(_id, isLoading);const metadata = useSelector(getMetadata);const datasetError = dataset && getDatasetError(dataset);@@ -276,7 +260,7 @@ export const CardEmbedComponent = memo(tr.insert(match.start, supportingText);editor.view.dispatch(tr);editor.commands.focus(match.start + 1);- trackDocumentAddSupportingText(document);+ host.analytics.trackAddSupportingText(document);return;}const flexContainer =@@ -294,7 +278,7 @@ export const CardEmbedComponent = memo(editor.view.dispatch(tr);editor.commands.focus(match.start + 2);- trackDocumentAddSupportingText(document);+ host.analytics.trackAddSupportingText(document);};const displayName = name || card?.name;@@ -354,13 +338,13 @@ export const CardEmbedComponent = memo(// Load metadata for the carduseEffect(() => {if (card) {- dispatch(loadMetadataForDocumentCard(card));+ dispatch(host.actions.loadMetadataForDocumentCard(card));}- }, [card, dispatch]);+ }, [card, dispatch, host]);const handleEditVisualizationSettings = () => {if (embedIndex !== -1) {- dispatch(openVizSettingsSidebar({ embedIndex }));+ dispatch(host.actions.openVizSettingsSidebar({ embedIndex }));}};@@ -373,7 +357,7 @@ export const CardEmbedComponent = memo(metadata,);const url = Urls.question(question);- dispatch(navigateToCardFromDocument(url, document));+ dispatch(host.navigateToCard(url, document));} catch (error) {console.error("Failed to navigate to question:", error);}@@ -391,12 +375,12 @@ export const CardEmbedComponent = memo(name: null,});if (document) {- trackDocumentReplaceCard(document);+ host.analytics.trackReplaceCard(document);}setIsReplaceModalOpen(false);},- [updateAttributes, document],+ [updateAttributes, document, host],);const handleRemoveNode = useCallback(() => {diff --git a/frontend/src/metabase/documents/contexts/ExternalCardDataContext.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/ExternalCardDataContext.tsxsimilarity index 100%rename from frontend/src/metabase/documents/contexts/ExternalCardDataContext.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/ExternalCardDataContext.tsxdiff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/ExternalDocumentCardMenu.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/ExternalDocumentCardMenu.tsxindex c3ddcdd9ceb..8338ffe0193 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/ExternalDocumentCardMenu.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/ExternalDocumentCardMenu.tsx@@ -5,7 +5,6 @@ import { t } from "ttag";import { QuestionDownloadWidget } from "metabase/common/components/QuestionDownloadWidget";import { useDownloadData } from "metabase/common/components/QuestionDownloadWidget/use-download-data";-import { useExternalCardData } from "metabase/documents/contexts/ExternalCardDataContext";import { useSelector } from "metabase/redux";import { getMetadata } from "metabase/selectors/metadata";import { ActionIcon, Icon, Menu } from "metabase/ui";@@ -14,6 +13,8 @@ import { SAVING_DOM_IMAGE_HIDDEN_CLASS } from "metabase/visualizations/lib/save-import Question from "metabase-lib/v1/Question";import type { Card, Dataset } from "metabase-types/api";+import { useExternalCardData } from "./ExternalCardDataContext";+type ExternalDocumentCardMenuProps = {card: Card;dataset: Dataset;diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/modals/ModifyQuestionModal.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/modals/ModifyQuestionModal.tsxindex 52895d2bbde..3b617dcd493 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/modals/ModifyQuestionModal.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/modals/ModifyQuestionModal.tsx@@ -2,13 +2,9 @@ import { useEffect, useMemo, useState } from "react";import { t } from "ttag";import _ from "underscore";-import {- createDraftCard,- generateDraftCardId,- loadMetadataForDocumentCard,-} from "metabase/documents/documents.slice";import { Notebook } from "metabase/querying/notebook/components/Notebook";import { useDispatch, useSelector, useStore } from "metabase/redux";+import { useEditorHost } from "metabase/rich_text_editing/tiptap/EditorHost";import { getMetadata } from "metabase/selectors/metadata";import { getSetting } from "metabase/selectors/settings";import { Box, Button, Flex, Modal, Text } from "metabase/ui";@@ -33,6 +29,7 @@ export const ModifyQuestionModal = ({}: ModifyQuestionModalProps) => {const store = useStore();const dispatch = useDispatch();+ const host = useEditorHost();const metadata = useSelector(getMetadata);const reportTimezone = useSelector((state) =>getSetting(state, "report-timezone-long"),@@ -43,9 +40,9 @@ export const ModifyQuestionModal = ({useEffect(() => {if (isOpen && card) {- dispatch(loadMetadataForDocumentCard(card));+ dispatch(host.actions.loadMetadataForDocumentCard(card));}- }, [isOpen, card, dispatch]);+ }, [isOpen, card, dispatch, host.actions]);const question = useMemo(() => {if (!card || !metadata || !isOpen) {@@ -75,7 +72,9 @@ export const ModifyQuestionModal = ({);if (!_.isEqual(currentDependencies, nextDependencies)) {- await dispatch(loadMetadataForDocumentCard(newQuestion.card()));+ await dispatch(+ host.actions.loadMetadataForDocumentCard(newQuestion.card()),+ );const freshMetadata = getMetadata(store.getState());const questionWithFreshMetadata = new Question(newQuestion.card(),@@ -100,10 +99,10 @@ export const ModifyQuestionModal = ({modifiedQuestion.card().visualization_settings ?? {},};- const newCardId = generateDraftCardId();+ const newCardId = host.actions.generateDraftCardId();dispatch(- createDraftCard({+ host.actions.createDraftCard({originalCard: card,modifiedData,draftId: newCardId,diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/use-update-card-operations.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/use-update-card-operations.tsindex c0389cdbfde..c25d26ec85d 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/use-update-card-operations.ts+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/use-update-card-operations.ts@@ -1,11 +1,11 @@import type { NodeViewProps } from "@tiptap/core";import { useCallback } from "react";-import { navigateToCardFromDocument } from "metabase/documents/actions";-import { updateVizSettings } from "metabase/documents/documents.slice";-import type { UseCardDataResult } from "metabase/documents/hooks/use-card-data";-import { useDraftCardOperations } from "metabase/documents/hooks/use-draft-card-operations";import { useDispatch, useSelector } from "metabase/redux";+import {+ type UseCardDataResult,+ useEditorHost,+} from "metabase/rich_text_editing/tiptap/EditorHost";import { getMetadata } from "metabase/selectors/metadata";import * as Urls from "metabase/urls";import Question from "metabase-lib/v1/Question";@@ -26,12 +26,13 @@ export const useUpdateCardOperations = ({embedIndex: number;cardId: number;}) => {+ const host = useEditorHost();const dispatch = useDispatch();const metadata = useSelector(getMetadata);const { card, draftCard, regularDataset } = regularCardData;- const { ensureDraftCard } = useDraftCardOperations(+ const { ensureDraftCard } = host.useDraftCardOperations(draftCard,card,cardId,@@ -60,7 +61,7 @@ export const useUpdateCardOperations = ({const adhocCard = { ...nextCard, id: null };const question = new Question(adhocCard, metadata);const url = Urls.question(question);- dispatch(navigateToCardFromDocument(url, document));+ dispatch(host.navigateToCard(url, document));} catch (error) {console.error("Failed to create question URL:", error);// Fallback: navigate to a new question with the dataset_query@@ -68,15 +69,12 @@ export const useUpdateCardOperations = ({const params = new URLSearchParams();params.set("dataset_query", JSON.stringify(nextCard.dataset_query));dispatch(- navigateToCardFromDocument(- `/question?${params.toString()}`,- document,- ),+ host.navigateToCard(`/question?${params.toString()}`, document),);}}},- [dispatch, metadata, document],+ [dispatch, host, metadata, document],);const handleUpdateVisualizationSettings = useCallback(@@ -92,13 +90,15 @@ export const useUpdateCardOperations = ({{ visualization_settings: newSettings },true,);- dispatch(updateVizSettings({ cardId: actualCardId, settings }));+ dispatch(+ host.actions.updateVizSettings({ cardId: actualCardId, settings }),+ );} else {- dispatch(updateVizSettings({ cardId, settings }));+ dispatch(host.actions.updateVizSettings({ cardId, settings }));}}},- [card, cardId, dispatch, draftCard, embedIndex, ensureDraftCard],+ [card, cardId, dispatch, draftCard, embedIndex, ensureDraftCard, host],);const handleUpdateQuestion = useCallback(() => {diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/CodeBlock/CodeBlock.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CodeBlock/CodeBlock.tsxindex 1c82eb3ba44..618b73c21d9 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/CodeBlock/CodeBlock.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CodeBlock/CodeBlock.tsx@@ -1,22 +1,16 @@import type { NodeViewProps } from "@tiptap/core";-import { CodeBlock } from "@tiptap/extension-code-block";+import { CodeBlock, type CodeBlockOptions } from "@tiptap/extension-code-block";import { Plugin, PluginKey, TextSelection } from "@tiptap/pm/state";-import {- NodeViewContent,- NodeViewWrapper,- ReactNodeViewRenderer,-} from "@tiptap/react";-import cx from "classnames";--import { CommentsMenu } from "metabase/documents/components/Editor/CommentsMenu";-import { useBlockMenus } from "metabase/documents/hooks/use-block-menus";+import { NodeViewContent, ReactNodeViewRenderer } from "@tiptap/react";import { createIdAttribute, createProseMirrorPlugin } from "../NodeIds";-import S from "../extensions.module.css";+import { type BlockNodeOptions, DefaultBlockShell } from "../shared/BlockShell";const languageClassPrefix = "language-";-export const CustomCodeBlock = CodeBlock.extend({+export const CustomCodeBlock = CodeBlock.extend<+ CodeBlockOptions & BlockNodeOptions+>({addAttributes() {return {language: {@@ -110,55 +104,31 @@ export const CustomCodeBlock = CodeBlock.extend({},});-export const CodeBlockNodeView = ({ node, editor, getPos }: NodeViewProps) => {- const {- _id,- isOpen,- isHovered,- hovered,- setHovered,- unresolvedCommentsCount,- document,- shouldShowMenus,- setReferenceElement,- commentsRefs,- commentsFloatingStyles,- } = useBlockMenus({ node, editor, getPos });+export const CodeBlockNodeView = ({+ node,+ editor,+ getPos,+ extension,+}: NodeViewProps) => {+ const BlockShell = extension.options.blockShell ?? DefaultBlockShell;return (- <>- <NodeViewWrapper- aria-expanded={isOpen}- className={cx(S.root, {- [S.open]: isOpen || isHovered,- })}- data-node-id={_id}- ref={setReferenceElement}- onMouseOver={() => setHovered(true)}- onMouseOut={() => setHovered(false)}- >- <pre>- <NodeViewContent<"code">- as="code"- className={- node.attrs.language- ? languageClassPrefix + node.attrs.language- : undefined- }- />- </pre>- </NodeViewWrapper>-- {shouldShowMenus && document && (- <CommentsMenu- active={isOpen}- href={`/document/${document.id}/comments/${_id}`}- ref={commentsRefs.setFloating}- show={isOpen || hovered}- style={commentsFloatingStyles}- unresolvedCommentsCount={unresolvedCommentsCount}+ <BlockShell+ node={node}+ editor={editor}+ getPos={getPos}+ hideMenus={extension.options.editorContext === "comments"}+ >+ <pre>+ <NodeViewContent<"code">+ as="code"+ className={+ node.attrs.language+ ? languageClassPrefix + node.attrs.language+ : undefined+ }/>- )}- </>+ </pre>+ </BlockShell>);};diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/CommandExtension.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/CommandExtension.tsindex dc6cdb004b7..86bf15d0431 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/CommandExtension.ts+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/CommandExtension.ts@@ -2,11 +2,6 @@ import { type Editor, Extension, type Range } from "@tiptap/core";import { PluginKey } from "@tiptap/pm/state";import Suggestion, { type SuggestionOptions } from "@tiptap/suggestion";-import {- trackDocumentAddCard,- trackDocumentAddSmartLink,- trackDocumentAskMetabot,-} from "metabase/documents/analytics";import type { Document } from "metabase-types/api";import { wrapCardEmbed } from "../shared/layout";@@ -77,9 +72,6 @@ export const CommandExtension = Extension.create<CommandOptions>({).setTextSelection(range.from + 1).run();- if (props.document) {- trackDocumentAddCard(props.document);- }return;}@@ -96,9 +88,6 @@ export const CommandExtension = Extension.create<CommandOptions>({},}).run();- if (props.document) {- trackDocumentAddSmartLink(props.document);- }return;}@@ -116,9 +105,6 @@ export const CommandExtension = Extension.create<CommandOptions>({attrs: {},}).run();- if (props.document) {- trackDocumentAskMetabot(props.document);- }return;}diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/CommandSuggestion.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/CommandSuggestion.tsxindex b8ef450fb32..2c562cd6f91 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/CommandSuggestion.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/CommandSuggestion.tsx@@ -11,21 +11,21 @@ import {} from "react";import { t } from "ttag";+import {+ useMetabotName,+ useUserMetabotPermissions,+} from "metabase/metabot/hooks";+import { useSelector } from "metabase/redux";+import { useEditorHost } from "metabase/rich_text_editing/tiptap/EditorHost";import {CreateNewQuestionFooter,MenuItemComponent,SearchResultsFooter,-} from "metabase/documents/components/Editor/shared/MenuComponents";+} from "metabase/rich_text_editing/tiptap/extensions/shared/MenuComponents";import {LoadingSuggestionPaper,SuggestionPaper,-} from "metabase/documents/components/Editor/shared/SuggestionPaper";-import { getCurrentDocument } from "metabase/documents/selectors";-import {- useMetabotName,- useUserMetabotPermissions,-} from "metabase/metabot/hooks";-import { useSelector } from "metabase/redux";+} from "metabase/rich_text_editing/tiptap/extensions/shared/SuggestionPaper";import { getBrowseAllItemIndex } from "metabase/rich_text_editing/tiptap/extensions/shared/suggestionUtils";import type { SuggestionPickerViewMode } from "metabase/rich_text_editing/tiptap/extensions/shared/types";import {@@ -104,7 +104,8 @@ export const CommandSuggestion = forwardRef<SuggestionRef,CommandSuggestionProps>(function CommandSuggestionComponent({ command, editor, query }, ref) {- const document = useSelector(getCurrentDocument);+ const host = useEditorHost();+ const document = useSelector(host.selectors.getCurrentDocument);const { canUseMetabot: isMetabotEnabled } = useUserMetabotPermissions();const metabotName = useMetabotName();const [selectedIndex, setSelectedIndex] = useState(0);@@ -166,18 +167,22 @@ export const CommandSuggestion = forwardRef<selectItem: true,entityId: item.id,model: item.model,- document,});+ if (document) {+ host.analytics.trackAddSmartLink(document);+ }} else {command({embedItem: true,entityId: item.id,model: item.model,- document,});+ if (document) {+ host.analytics.trackAddCard(document);+ }}},- [viewMode, command, document],+ [viewMode, command, document, host],);const onTriggerCreateNewQuestion = useCallback(() => {@@ -230,8 +235,10 @@ export const CommandSuggestion = forwardRef<if (commandName === "metabot") {command({command: "metabot",- document,});+ if (document) {+ host.analytics.trackAskMetabot(document);+ }return;}diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/CommandSuggestion.unit.spec.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/CommandSuggestion.unit.spec.tsxindex 8700ed62dcd..44d30c97f9c 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/CommandSuggestion.unit.spec.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/CommandSuggestion.unit.spec.tsx@@ -196,7 +196,6 @@ describe("CommandSuggestion", () => {embedItem: true,entityId: 2,model: "card",- document: null,});});@@ -228,7 +227,6 @@ describe("CommandSuggestion", () => {selectItem: true,entityId: 4,model: "document",- document: null,});});@@ -268,7 +266,6 @@ describe("CommandSuggestion", () => {embedItem: true,entityId: 5,model: "card",- document: null,});});@@ -303,7 +300,6 @@ describe("CommandSuggestion", () => {embedItem: true,entityId: 6,model: "card",- document: null,});});@@ -338,7 +334,6 @@ describe("CommandSuggestion", () => {selectItem: true,entityId: 8,model: "table",- document: null,});});diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/CreateStructuredQuestionModal.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/CreateStructuredQuestionModal.tsxindex f2e0321642d..83ae56d6357 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/CreateStructuredQuestionModal.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/CreateStructuredQuestionModal.tsx@@ -2,13 +2,9 @@ import { useMemo, useState } from "react";import { t } from "ttag";import _ from "underscore";-import {- createDraftCard,- generateDraftCardId,- loadMetadataForDocumentCard,-} from "metabase/documents/documents.slice";import { Notebook } from "metabase/querying/notebook/components/Notebook";import { useDispatch, useSelector, useStore } from "metabase/redux";+import { useEditorHost } from "metabase/rich_text_editing/tiptap/EditorHost";import { getMetadata } from "metabase/selectors/metadata";import { getSetting } from "metabase/selectors/settings";import { Box, Button, Flex, Modal } from "metabase/ui";@@ -28,6 +24,7 @@ export const CreateStructuredQuestionModal = ({}: CreateQuestionModalProps) => {const store = useStore();const dispatch = useDispatch();+ const host = useEditorHost();const [modifiedQuestion, setModifiedQuestion] = useState<Question>(() =>Question.create(),@@ -58,7 +55,9 @@ export const CreateStructuredQuestionModal = ({);if (!_.isEqual(currentDependencies, nextDependencies)) {- await dispatch(loadMetadataForDocumentCard(newQuestion.card()));+ await dispatch(+ host.actions.loadMetadataForDocumentCard(newQuestion.card()),+ );const freshMetadata = getMetadata(store.getState());const questionWithFreshMetadata = new Question(newQuestion.card(),@@ -90,10 +89,10 @@ export const CreateStructuredQuestionModal = ({visualization_settings:questionWithDefaultDisplay.card().visualization_settings ?? {},};- const newCardId = generateDraftCardId();+ const newCardId = host.actions.generateDraftCardId();dispatch(- createDraftCard({+ host.actions.createDraftCard({originalCard: undefined,modifiedData,draftId: newCardId,diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/NewQuestionTypeMenuView.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/NewQuestionTypeMenuView.tsxindex 7498ad4749e..864d18e0c1e 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/NewQuestionTypeMenuView.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/NewQuestionTypeMenuView.tsx@@ -1,6 +1,6 @@import { useCallback, useLayoutEffect } from "react";-import { MenuItemComponent } from "metabase/documents/components/Editor/shared/MenuComponents";+import { MenuItemComponent } from "metabase/rich_text_editing/tiptap/extensions/shared/MenuComponents";import { CreateNativeQuestionModal } from "./CreateNativeQuestionModal";import { CreateStructuredQuestionModal } from "./CreateStructuredQuestionModal";diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/types.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/types.tsindex 488e9488f09..cd82c0b3a7d 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/types.ts+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/types.ts@@ -1,6 +1,6 @@import type { Editor } from "@tiptap/core";-import type { MenuItem } from "metabase/documents/components/Editor/shared/MenuComponents";+import type { MenuItem } from "metabase/rich_text_editing/tiptap/extensions/shared/MenuComponents";import type { IconName } from "metabase-types/api";export interface CommandOption {icon?: IconName;diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/CustomStarterKit/CustomStarterKit.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CustomStarterKit/CustomStarterKit.tsxindex ed1b405511a..b84d1b5f566 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/CustomStarterKit/CustomStarterKit.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CustomStarterKit/CustomStarterKit.tsx@@ -18,6 +18,7 @@ import { CustomCodeBlock } from "../CodeBlock";import { CustomHeading } from "../Heading";import { CustomOrderedList } from "../OrderedList";import { CustomParagraph } from "../Paragraph";+import type { BlockShellComponent } from "../shared/BlockShell";declare module "@tiptap/core" {// This adds a new configuration option to the NodeConfig@@ -54,8 +55,24 @@ interface CustomStarterKitOptions extends StarterKitOptions {paragraph: StarterKitOptions["paragraph"] & {editorContext?: "comments" | "document";};+ /**+ * Block "shell" component injected into the top-level block node views. Lets a+ * host (e.g. documents) attach block-level chrome such as comment and anchor+ * menus without the editor primitive depending on the host. When omitted the+ * blocks render with no extra chrome.+ */+ blockShell?: BlockShellComponent;}+/** Merge the shared `blockShell` option into a block's own configure options. */+const withBlockShell = (+ blockOptions: unknown,+ blockShell: BlockShellComponent | undefined,+) => ({+ ...(typeof blockOptions === "object" && blockOptions ? blockOptions : {}),+ blockShell,+});+/*** Modified StarterKit so it doesn't hijack browsers' cmd/ctrl+shift+b behavior*/@@ -63,12 +80,15 @@ export const CustomStarterKit = StarterKit.extend<CustomStarterKitOptions>({name: "customStarterKit",addExtensions() {let extensions = this.parent?.() || [];+ const { blockShell } = this.options;if (this.options.blockquote !== false) {extensions = replaceExtension(extensions,Blockquote,- CustomBlockquote.configure(this.options.blockquote),+ CustomBlockquote.configure(+ withBlockShell(this.options.blockquote, blockShell),+ ),);}@@ -76,7 +96,9 @@ export const CustomStarterKit = StarterKit.extend<CustomStarterKitOptions>({extensions = replaceExtension(extensions,BulletList,- CustomBulletList.configure(this.options.bulletList),+ CustomBulletList.configure(+ withBlockShell(this.options.bulletList, blockShell),+ ),);}@@ -84,7 +106,9 @@ export const CustomStarterKit = StarterKit.extend<CustomStarterKitOptions>({extensions = replaceExtension(extensions,OrderedList,- CustomOrderedList.configure(this.options.orderedList),+ CustomOrderedList.configure(+ withBlockShell(this.options.orderedList, blockShell),+ ),);}@@ -92,7 +116,9 @@ export const CustomStarterKit = StarterKit.extend<CustomStarterKitOptions>({extensions = replaceExtension(extensions,Heading,- CustomHeading.configure(this.options.heading),+ CustomHeading.configure(+ withBlockShell(this.options.heading, blockShell),+ ),);}@@ -100,7 +126,9 @@ export const CustomStarterKit = StarterKit.extend<CustomStarterKitOptions>({extensions = replaceExtension(extensions,Paragraph,- CustomParagraph.configure(this.options.paragraph),+ CustomParagraph.configure(+ withBlockShell(this.options.paragraph, blockShell),+ ),);}@@ -108,7 +136,9 @@ export const CustomStarterKit = StarterKit.extend<CustomStarterKitOptions>({extensions = replaceExtension(extensions,CodeBlock,- CustomCodeBlock.configure(this.options.codeBlock),+ CustomCodeBlock.configure(+ withBlockShell(this.options.codeBlock, blockShell),+ ),);}diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/Heading/Heading.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Heading/Heading.tsxindex 816f3285c1a..cc6636f999e 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/Heading/Heading.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Heading/Heading.tsx@@ -1,20 +1,11 @@import type { NodeViewProps } from "@tiptap/core";-import { Heading } from "@tiptap/extension-heading";-import {- NodeViewContent,- NodeViewWrapper,- ReactNodeViewRenderer,-} from "@tiptap/react";-import cx from "classnames";--import { AnchorLinkMenu } from "metabase/documents/components/Editor/AnchorLinkMenu";-import { CommentsMenu } from "metabase/documents/components/Editor/CommentsMenu";-import { useBlockMenus } from "metabase/documents/hooks/use-block-menus";+import { Heading, type HeadingOptions } from "@tiptap/extension-heading";+import { NodeViewContent, ReactNodeViewRenderer } from "@tiptap/react";import { createIdAttribute, createProseMirrorPlugin } from "../NodeIds";-import S from "../extensions.module.css";+import { type BlockNodeOptions, DefaultBlockShell } from "../shared/BlockShell";-export const CustomHeading = Heading.extend({+export const CustomHeading = Heading.extend<HeadingOptions & BlockNodeOptions>({addAttributes() {return {level: {@@ -47,61 +38,23 @@ const levelNodeMap: Record<Level, ElementType> = {6: "h6",};-export const HeadingNodeView = ({ node, editor, getPos }: NodeViewProps) => {+export const HeadingNodeView = ({+ node,+ editor,+ getPos,+ extension,+}: NodeViewProps) => {const { level } = node.attrs;-- const {- _id,- isOpen,- isHovered,- hovered,- setHovered,- unresolvedCommentsCount,- document,- shouldShowMenus,- anchorUrl,- setReferenceElement,- commentsRefs,- commentsFloatingStyles,- anchorRefs,- anchorFloatingStyles,- } = useBlockMenus({ node, editor, getPos });+ const BlockShell = extension.options.blockShell ?? DefaultBlockShell;return (- <>- <NodeViewWrapper- aria-expanded={isOpen}- className={cx(S.root, {- [S.open]: isOpen || isHovered,- })}- data-node-id={_id}- ref={setReferenceElement}- onMouseOver={() => setHovered(true)}- onMouseOut={() => setHovered(false)}- >- <NodeViewContent<ElementType>- as={levelNodeMap[level as Level] ?? "h1"}- />- </NodeViewWrapper>-- {shouldShowMenus && document && (- <>- <AnchorLinkMenu- ref={anchorRefs.setFloating}- show={hovered}- style={anchorFloatingStyles}- url={anchorUrl}- />- <CommentsMenu- active={isOpen}- href={`/document/${document.id}/comments/${_id}`}- ref={commentsRefs.setFloating}- show={isOpen || hovered}- style={commentsFloatingStyles}- unresolvedCommentsCount={unresolvedCommentsCount}- />- </>- )}- </>+ <BlockShell+ node={node}+ editor={editor}+ getPos={getPos}+ hideMenus={extension.options.editorContext === "comments"}+ >+ <NodeViewContent<ElementType> as={levelNodeMap[level as Level] ?? "h1"} />+ </BlockShell>);};diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/Mention/MentionExtension.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Mention/MentionExtension.tsindex 468713d2ec1..a02b7eb31c2 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/Mention/MentionExtension.ts+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Mention/MentionExtension.ts@@ -3,7 +3,6 @@ import type { Node as ProseMirrorNode } from "@tiptap/pm/model";import { PluginKey } from "@tiptap/pm/state";import Suggestion, { type SuggestionOptions } from "@tiptap/suggestion";-import { trackDocumentAddSmartLink } from "metabase/documents/analytics";import type { Document } from "metabase-types/api";export interface MentionOptions {@@ -65,9 +64,6 @@ export const MentionExtension = Extension.create<MentionOptions>({}).insertContent(" ").run();- if (props.document) {- trackDocumentAddSmartLink(props.document);- }}},},diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/Mention/MentionSuggestion.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Mention/MentionSuggestion.tsxindex e7d23cd101a..3a8a3a374b4 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/Mention/MentionSuggestion.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Mention/MentionSuggestion.tsx@@ -2,12 +2,12 @@ import type { Editor, Range } from "@tiptap/core";import { forwardRef, useCallback, useImperativeHandle } from "react";import { t } from "ttag";+import { useSelector } from "metabase/redux";+import { useEditorHost } from "metabase/rich_text_editing/tiptap/EditorHost";import {LoadingSuggestionPaper,SuggestionPaper,-} from "metabase/documents/components/Editor/shared/SuggestionPaper";-import { getCurrentDocument } from "metabase/documents/selectors";-import { useSelector } from "metabase/redux";+} from "metabase/rich_text_editing/tiptap/extensions/shared/SuggestionPaper";import type { SearchResult } from "metabase-types/api";import { EntitySearchSection } from "../shared/EntitySearchSection";@@ -50,7 +50,8 @@ const MentionSuggestionComponent = forwardRef<},ref,) {- const document = useSelector(getCurrentDocument);+ const host = useEditorHost();+ const document = useSelector(host.selectors.getCurrentDocument);const onSelectEntity = useCallback((item: {id: number | string;@@ -63,10 +64,12 @@ const MentionSuggestionComponent = forwardRef<model: item.model,label: item.label,href: item.href,- document, // currently only used for analytics tracking purposes});+ if (document) {+ host.analytics.trackAddSmartLink(document);+ }},- [command, document],+ [command, document, host],);const {diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotEmbed/MetabotEmbed.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotEmbed/MetabotEmbed.tsxindex 44b84360bb2..83b848da7f3 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotEmbed/MetabotEmbed.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotEmbed/MetabotEmbed.tsx@@ -13,13 +13,6 @@ import { t } from "ttag";import { useLazyMetabotGenerateContentQuery } from "metabase/api";import CS from "metabase/css/core/index.css";-import { trackDocumentAskMetabot } from "metabase/documents/analytics";-import {- createDraftCard,- generateDraftCardId,- loadMetadataForDocumentCard,-} from "metabase/documents/documents.slice";-import { getCurrentDocument } from "metabase/documents/selectors";import MetabotThinkingStyles from "metabase/metabot/components/MetabotChat/MetabotThinking.module.css";import { MetabotIcon } from "metabase/metabot/components/MetabotIcon";import {@@ -27,6 +20,7 @@ import {useUserMetabotPermissions,} from "metabase/metabot/hooks";import { useDispatch, useSelector } from "metabase/redux";+import { useEditorHost } from "metabase/rich_text_editing/tiptap/EditorHost";import { Box, Button, Flex, Icon, Text, Tooltip } from "metabase/ui";import type { Card, MetabotGenerateContentRequest } from "metabase-types/api";@@ -153,7 +147,8 @@ export const MetabotNode = Node.create<{export const MetabotComponent = memo(({ editor, getPos, deleteNode, node, extension }: NodeViewProps) => {const dispatch = useDispatch();- const document = useSelector(getCurrentDocument);+ const host = useEditorHost();+ const document = useSelector(host.selectors.getCurrentDocument);const controllerRef = useRef<AbortController | null>(null);const [isLoading, setIsLoading] = useState(false);const [errorText, setErrorText] = useState("");@@ -198,7 +193,7 @@ export const MetabotComponent = memo(return;}- const newCardId = generateDraftCardId();+ const newCardId = host.actions.generateDraftCardId();const card: Card = {...data.draft_card,id: newCardId,@@ -228,11 +223,11 @@ export const MetabotComponent = memo(archived: false,};- trackDocumentAskMetabot(document);- await dispatch(loadMetadataForDocumentCard(card));+ host.analytics.trackAskMetabot(document);+ await dispatch(host.actions.loadMetadataForDocumentCard(card));dispatch(- createDraftCard({+ host.actions.createDraftCard({originalCard: card,modifiedData: {},draftId: newCardId,diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotMention/MetabotSuggestion.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotMention/MetabotSuggestion.tsxindex b7c4ce7afde..dd1f233cf08 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotMention/MetabotSuggestion.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotMention/MetabotSuggestion.tsx@@ -15,10 +15,10 @@ import type {Section,} from "metabase/common/components/AccordionList/types";import { searchFilter } from "metabase/common/components/AccordionList/utils";-import type { MenuItem } from "metabase/documents/components/Editor/shared/MenuComponents";-import { MenuItemComponent } from "metabase/documents/components/Editor/shared/MenuComponents";-import { SuggestionPaper } from "metabase/documents/components/Editor/shared/SuggestionPaper";import { useMetabotName } from "metabase/metabot/hooks";+import type { MenuItem } from "metabase/rich_text_editing/tiptap/extensions/shared/MenuComponents";+import { MenuItemComponent } from "metabase/rich_text_editing/tiptap/extensions/shared/MenuComponents";+import { SuggestionPaper } from "metabase/rich_text_editing/tiptap/extensions/shared/SuggestionPaper";import { Box, Group, Loader, Text } from "metabase/ui";import type { Database, SearchResult } from "metabase-types/api";diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/OrderedList/OrderedList.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/OrderedList/OrderedList.tsxindex 01f614ed6a5..536f55f7a25 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/OrderedList/OrderedList.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/OrderedList/OrderedList.tsx@@ -1,19 +1,16 @@import type { NodeViewProps } from "@tiptap/core";-import { OrderedList } from "@tiptap/extension-ordered-list";import {- NodeViewContent,- NodeViewWrapper,- ReactNodeViewRenderer,-} from "@tiptap/react";-import cx from "classnames";--import { CommentsMenu } from "metabase/documents/components/Editor/CommentsMenu";-import { useBlockMenus } from "metabase/documents/hooks/use-block-menus";+ OrderedList,+ type OrderedListOptions,+} from "@tiptap/extension-ordered-list";+import { NodeViewContent, ReactNodeViewRenderer } from "@tiptap/react";import { createIdAttribute, createProseMirrorPlugin } from "../NodeIds";-import S from "../extensions.module.css";+import { type BlockNodeOptions, DefaultBlockShell } from "../shared/BlockShell";-export const CustomOrderedList = OrderedList.extend({+export const CustomOrderedList = OrderedList.extend<+ OrderedListOptions & BlockNodeOptions+>({addAttributes() {return {start: {@@ -45,47 +42,18 @@ export const OrderedListNodeView = ({node,editor,getPos,+ extension,}: NodeViewProps) => {- const {- _id,- isOpen,- isHovered,- hovered,- setHovered,- unresolvedCommentsCount,- document,- shouldShowMenus,- setReferenceElement,- commentsRefs,- commentsFloatingStyles,- } = useBlockMenus({ node, editor, getPos });+ const BlockShell = extension.options.blockShell ?? DefaultBlockShell;return (- <>- <NodeViewWrapper- aria-expanded={isOpen}- className={cx(S.root, {- [S.open]: isOpen || isHovered,- })}- data-node-id={_id}- ref={setReferenceElement}- // onMouseEnter/onMouseLeave do not work on list elements living in contentEditable- onMouseOver={() => setHovered(true)}- onMouseOut={() => setHovered(false)}- >- <NodeViewContent<"ol"> as="ol" />- </NodeViewWrapper>-- {shouldShowMenus && document && (- <CommentsMenu- active={isOpen}- href={`/document/${document.id}/comments/${_id}`}- ref={commentsRefs.setFloating}- show={isOpen || hovered}- style={commentsFloatingStyles}- unresolvedCommentsCount={unresolvedCommentsCount}- />- )}- </>+ <BlockShell+ node={node}+ editor={editor}+ getPos={getPos}+ hideMenus={extension.options.editorContext === "comments"}+ >+ <NodeViewContent<"ol"> as="ol" />+ </BlockShell>);};diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/Paragraph/Paragraph.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Paragraph/Paragraph.tsxindex 7b6df342b84..b288ed8c255 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/Paragraph/Paragraph.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Paragraph/Paragraph.tsx@@ -1,19 +1,13 @@import type { NodeViewProps } from "@tiptap/core";-import { Paragraph } from "@tiptap/extension-paragraph";-import {- NodeViewContent,- NodeViewWrapper,- ReactNodeViewRenderer,-} from "@tiptap/react";-import cx from "classnames";--import { CommentsMenu } from "metabase/documents/components/Editor/CommentsMenu";-import { useBlockMenus } from "metabase/documents/hooks/use-block-menus";+import { Paragraph, type ParagraphOptions } from "@tiptap/extension-paragraph";+import { NodeViewContent, ReactNodeViewRenderer } from "@tiptap/react";import { createIdAttribute, createProseMirrorPlugin } from "../NodeIds";-import S from "../extensions.module.css";+import { type BlockNodeOptions, DefaultBlockShell } from "../shared/BlockShell";-export const CustomParagraph = Paragraph.extend({+export const CustomParagraph = Paragraph.extend<+ ParagraphOptions & BlockNodeOptions+>({addAttributes() {return {...createIdAttribute(),@@ -35,53 +29,16 @@ export const ParagraphNodeView = ({getPos,extension,}: NodeViewProps) => {- const editorContext = extension?.options?.editorContext || "document";- const hideMenusInContext = editorContext === "comments";-- const {- _id,- isOpen,- isHovered,- hovered,- setHovered,- unresolvedCommentsCount,- document,- shouldShowMenus,- setReferenceElement,- commentsRefs,- commentsFloatingStyles,- } = useBlockMenus({- node,- editor,- getPos,- shouldHideMenus: hideMenusInContext,- });+ const BlockShell = extension.options.blockShell ?? DefaultBlockShell;return (- <>- <NodeViewWrapper- aria-expanded={isOpen}- className={cx(S.root, {- [S.open]: isOpen || isHovered,- })}- data-node-id={_id}- ref={setReferenceElement}- onMouseOver={() => setHovered(true)}- onMouseOut={() => setHovered(false)}- >- <NodeViewContent<"p"> as="p" />- </NodeViewWrapper>-- {shouldShowMenus && document && (- <CommentsMenu- active={isOpen}- href={`/document/${document.id}/comments/${_id}`}- ref={commentsRefs.setFloating}- show={isOpen || hovered}- style={commentsFloatingStyles}- unresolvedCommentsCount={unresolvedCommentsCount}- />- )}- </>+ <BlockShell+ node={node}+ editor={editor}+ getPos={getPos}+ hideMenus={extension.options.editorContext === "comments"}+ >+ <NodeViewContent<"p"> as="p" />+ </BlockShell>);};diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/PlainLink/PlainLink.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/PlainLink/PlainLink.tsindex 1997c5ed390..141ebbacac7 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/PlainLink/PlainLink.ts+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/PlainLink/PlainLink.ts@@ -8,7 +8,7 @@ import { Link } from "@tiptap/extension-link";import cx from "classnames";import CS from "metabase/css/core/index.css";-import { processUrl } from "metabase/documents/utils/processUrl";+import { processUrl } from "metabase/rich_text_editing/tiptap/utils/processUrl";import S from "./PlainLink.module.css";diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode.tsxindex b78602aee1a..e0c53841258 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode.tsx@@ -23,7 +23,6 @@ import {import { EntityIcon } from "metabase/common/components/EntityIcon";import { Link } from "metabase/common/components/Link";import type { IconModel, ObjectWithModel } from "metabase/common/utils/icon";-import { updateMentionsCache } from "metabase/documents/documents.slice";import { useGetIcon } from "metabase/hooks/use-icon";import {METABSE_PROTOCOL_MD_LINK,@@ -31,6 +30,7 @@ import {} from "metabase/metabot/utils/links";import { PLUGIN_TRANSFORMS } from "metabase/plugins";import { useDispatch } from "metabase/redux";+import { useEditorHost } from "metabase/rich_text_editing/tiptap/EditorHost";import { Icon } from "metabase/ui";import { modelToUrl } from "metabase/urls/modelToUrl";import { extractEntityId } from "metabase/urls/utils";@@ -451,14 +451,15 @@ export const SmartLinkComponent = memo(const entity = networkEntity || cachedEntity;const dispatch = useDispatch();+ const host = useEditorHost();useEffect(() => {if (entity) {const name ="display_name" in entity ? entity.display_name : entity?.name;updateAttributes({ label: name });- dispatch(updateMentionsCache({ entityId, model, name }));+ dispatch(host.actions.updateMentionsCache({ entityId, model, name }));}- }, [updateAttributes, dispatch, entity, entityId, model]);+ }, [updateAttributes, dispatch, host, entity, entityId, model]);const showLoading = isLoading && !entity;if (showLoading) {diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/SupportingText/SupportingText.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/SupportingText/SupportingText.tsxindex b0d7d4e4e82..647e9c98077 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/SupportingText/SupportingText.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/SupportingText/SupportingText.tsx@@ -14,13 +14,8 @@ import cx from "classnames";import { push } from "react-router-redux";import { t } from "ttag";-import { useNodeInViewport } from "metabase/documents/hooks/use-node-in-viewport";-import { useUnresolvedCommentsCount } from "metabase/documents/hooks/use-unresolved-comments-count";-import {- getChildTargetId,- getCurrentDocument,-} from "metabase/documents/selectors";import { useDispatch, useSelector } from "metabase/redux/hooks";+import { useEditorHost } from "metabase/rich_text_editing/tiptap/EditorHost";import { DropZone } from "metabase/rich_text_editing/tiptap/extensions/shared/dnd/DropZone";import { useDndHelpers } from "metabase/rich_text_editing/tiptap/extensions/shared/dnd/use-dnd-helpers";import { Box } from "metabase/ui";@@ -137,11 +132,12 @@ const SupportingTextComponent = ({node,selected,}: NodeViewProps) => {- const { ref: viewportRef, isInViewport } = useNodeInViewport();- const childTargetId = useSelector(getChildTargetId);- const document = useSelector(getCurrentDocument);+ const host = useEditorHost();+ const { ref: viewportRef, isInViewport } = host.useNodeInViewport();+ const childTargetId = useSelector(host.selectors.getChildTargetId);+ const document = useSelector(host.selectors.getCurrentDocument);const { _id } = node.attrs;- const unresolvedCommentsCount = useUnresolvedCommentsCount(_id, {+ const unresolvedCommentsCount = host.useUnresolvedCommentsCount(_id, {skip: !isInViewport,});const isOpen = childTargetId === _id;diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/BlockShell.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/BlockShell.tsxnew file mode 100644index 00000000000..e69a445d0b0--- /dev/null+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/BlockShell.tsx@@ -0,0 +1,49 @@+import type { NodeViewProps } from "@tiptap/core";+import { NodeViewWrapper } from "@tiptap/react";+import type { ReactNode } from "react";++import S from "../extensions.module.css";++/**+ * Props passed to a block "shell" — the element that wraps a top-level block's+ * content and is responsible for any block-level chrome (e.g. document comment+ * and anchor menus).+ */+export interface BlockShellProps {+ node: NodeViewProps["node"];+ editor: NodeViewProps["editor"];+ getPos: NodeViewProps["getPos"];+ /**+ * When true the host wants block-level menus suppressed (e.g. the block is+ * rendered inside the comments editor rather than a document).+ */+ hideMenus?: boolean;+ children: ReactNode;+}++/**+ * A block shell renders the block's outer wrapper and decides what chrome (if+ * any) to attach around it. The editor primitive ships {@link DefaultBlockShell}+ * (no chrome); hosts such as documents inject their own shell via the block+ * extension options to add comment/anchor menus.+ */+export type BlockShellComponent = (props: BlockShellProps) => ReactNode;++/**+ * Default block wrapper used when the host does not inject a shell. Renders the+ * plain node wrapper with no document-specific menus.+ */+export const DefaultBlockShell = ({ node, children }: BlockShellProps) => (+ <NodeViewWrapper className={S.root} data-node-id={node.attrs._id}>+ {children}+ </NodeViewWrapper>+);++/**+ * Options shared by the custom block node views, allowing a host to configure+ * the block shell and editing context.+ */+export interface BlockNodeOptions {+ blockShell?: BlockShellComponent;+ editorContext?: "comments" | "document";+}diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/EntitySearchSection.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/EntitySearchSection.tsxindex a6f86755cb6..b979180f8a4 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/EntitySearchSection.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/EntitySearchSection.tsx@@ -1,12 +1,12 @@import { t } from "ttag";import { QuestionPickerModal } from "metabase/common/components/Pickers";-import type { MenuItem } from "metabase/documents/components/Editor/shared/MenuComponents";+import type { MenuItem } from "metabase/rich_text_editing/tiptap/extensions/shared/MenuComponents";import {CreateNewQuestionFooter,MenuItemComponent,SearchResultsFooter,-} from "metabase/documents/components/Editor/shared/MenuComponents";+} from "metabase/rich_text_editing/tiptap/extensions/shared/MenuComponents";import type {SuggestionPickerModalType,SuggestionPickerViewMode,diff --git a/frontend/src/metabase/documents/components/Editor/shared/MenuComponents.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/MenuComponents.tsxsimilarity index 100%rename from frontend/src/metabase/documents/components/Editor/shared/MenuComponents.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/MenuComponents.tsxdiff --git a/frontend/src/metabase/documents/components/Editor/shared/MenuItems.module.css b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/MenuItems.module.csssimilarity index 100%rename from frontend/src/metabase/documents/components/Editor/shared/MenuItems.module.cssrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/MenuItems.module.cssdiff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/NativeQueryModal.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/NativeQueryModal.tsxindex f4b23b94228..ccf9cfce912 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/NativeQueryModal.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/NativeQueryModal.tsx@@ -5,15 +5,11 @@ import { c, t } from "ttag";import EmptyCodeResult from "assets/img/empty-states/code.svg";import { datasetApi } from "metabase/api/dataset";import { ErrorMessage } from "metabase/common/components/ErrorMessage";-import {- createDraftCard,- generateDraftCardId,- loadMetadataForDocumentCard,-} from "metabase/documents/documents.slice";import { DataReference } from "metabase/querying/components/DataReference/DataReference";import type { DataReferenceItem } from "metabase/querying/components/DataReference/types";import { NativeQueryEditor } from "metabase/querying/components/NativeQueryEditor";import { useDispatch, useSelector } from "metabase/redux";+import { useEditorHost } from "metabase/rich_text_editing/tiptap/EditorHost";import { getMetadata } from "metabase/selectors/metadata";import { Box, Button, Flex, Loader, Modal, Stack, Text } from "metabase/ui";import { isMac } from "metabase/utils/browser";@@ -110,6 +106,7 @@ export const NativeQueryModal = ({initialDataset,}: NativeQueryModalProps) => {const dispatch = useDispatch();+ const host = useEditorHost();const metadata = useSelector(getMetadata);const [modifiedQuestion, setModifiedQuestion] = useState<Question | null>(@@ -144,9 +141,9 @@ export const NativeQueryModal = ({useEffect(() => {if (isOpen && card) {- dispatch(loadMetadataForDocumentCard(card));+ dispatch(host.actions.loadMetadataForDocumentCard(card));}- }, [isOpen, card, dispatch]);+ }, [isOpen, card, dispatch, host.actions]);const question = useMemo(() => {if (!card || !metadata || !isOpen) {@@ -215,7 +212,7 @@ export const NativeQueryModal = ({return;}- const newCardId = generateDraftCardId();+ const newCardId = host.actions.generateDraftCardId();if (!isNewQuestion) {const modifiedData = {dataset_query: modifiedQuestion.datasetQuery(),@@ -225,7 +222,7 @@ export const NativeQueryModal = ({};dispatch(- createDraftCard({+ host.actions.createDraftCard({originalCard: card,modifiedData,draftId: newCardId,@@ -248,7 +245,7 @@ export const NativeQueryModal = ({};dispatch(- createDraftCard({+ host.actions.createDraftCard({originalCard: undefined,modifiedData,draftId: newCardId,@@ -258,7 +255,15 @@ export const NativeQueryModal = ({onSave({ card_id: newCardId });onClose();- }, [modifiedQuestion, isNewQuestion, onSave, onClose, dispatch, card]);+ }, [+ modifiedQuestion,+ isNewQuestion,+ onSave,+ onClose,+ dispatch,+ card,+ host.actions,+ ]);const rawSeries = useMemo<RawSeries | null>(() => {if (!modifiedQuestion || !datasetToUse || failedDataset) {diff --git a/frontend/src/metabase/documents/components/Editor/shared/SuggestionPaper.module.css b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/SuggestionPaper.module.csssimilarity index 100%rename from frontend/src/metabase/documents/components/Editor/shared/SuggestionPaper.module.cssrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/SuggestionPaper.module.cssdiff --git a/frontend/src/metabase/documents/components/Editor/shared/SuggestionPaper.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/SuggestionPaper.tsxsimilarity index 100%rename from frontend/src/metabase/documents/components/Editor/shared/SuggestionPaper.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/SuggestionPaper.tsxdiff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/constants.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/constants.tsindex 367c733319a..10bb10c6c67 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/constants.ts+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/constants.ts@@ -18,3 +18,9 @@ export const LINK_SEARCH_LIMIT = 5;export const USER_SEARCH_LIMIT = LINK_SEARCH_LIMIT;export const DROP_ZONE_COLOR = "var(--mb-color-core-brand)";++/** Maximum number of card embeds a FlexContainer group may hold side-by-side. */+export const MAX_GROUP_SIZE = 3;++/** Class name used to prevent editor typography styles from affecting embedded content. */+export const EDITOR_STYLE_BOUNDARY_CLASS = "editor-style-boundary";diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/suggestionHooks.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/suggestionHooks.tsindex 040e3260989..15c91a2ef4c 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/suggestionHooks.ts+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/suggestionHooks.ts@@ -1,8 +1,8 @@import { useCallback } from "react";import { getTranslatedEntityName } from "metabase/common/utils/model-names";-import type { MenuItem } from "metabase/documents/components/Editor/shared/MenuComponents";import { useGetIcon } from "metabase/hooks/use-icon";+import type { MenuItem } from "metabase/rich_text_editing/tiptap/extensions/shared/MenuComponents";import { modelToUrl } from "metabase/urls/modelToUrl";import { getName } from "metabase/utils/name";import type { Database, RecentItem, SearchResult } from "metabase-types/api";diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/suggestionUtils.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/suggestionUtils.tsindex 58f7cf70a1d..b6cb9147ca1 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/suggestionUtils.ts+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/suggestionUtils.ts@@ -1,7 +1,7 @@import { match } from "ts-pattern";-import type { MenuItem } from "metabase/documents/components/Editor/shared/MenuComponents";import type { MetabaseProtocolEntityModel } from "metabase/metabot/utils/links";+import type { MenuItem } from "metabase/rich_text_editing/tiptap/extensions/shared/MenuComponents";import type { UrlableModel } from "metabase/urls/modelToUrl";import type { MentionableUser, RecentItem } from "metabase-types/api";import { isObject } from "metabase-types/guards";diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/useEntitySearch.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/useEntitySearch.tsindex d42b886422e..8daab6124eb 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/useEntitySearch.ts+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/useEntitySearch.ts@@ -5,7 +5,7 @@ import {useListRecentsQuery,useSearchQuery,} from "metabase/api";-import type { MenuItem } from "metabase/documents/components/Editor/shared/MenuComponents";+import type { MenuItem } from "metabase/rich_text_editing/tiptap/extensions/shared/MenuComponents";import type {MentionableUser,RecentItem,diff --git a/frontend/src/metabase/documents/utils/processUrl.ts b/frontend/src/metabase/rich_text_editing/tiptap/utils/processUrl.tssimilarity index 100%rename from frontend/src/metabase/documents/utils/processUrl.tsrename to frontend/src/metabase/rich_text_editing/tiptap/utils/processUrl.tsdiff --git a/frontend/src/metabase/documents/utils/processUrl.unit.spec.ts b/frontend/src/metabase/rich_text_editing/tiptap/utils/processUrl.unit.spec.tssimilarity index 100%rename from frontend/src/metabase/documents/utils/processUrl.unit.spec.tsrename to frontend/src/metabase/rich_text_editing/tiptap/utils/processUrl.unit.spec.ts