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
Documents supporting text - Drag-and-drop (#65854)
Brad Anderson54c23276d747
diff --git a/e2e/support/document-initial-data.ts b/e2e/support/document-initial-data.tsindex bcc1c00ada1..515abea28f5 100644--- a/e2e/support/document-initial-data.ts+++ b/e2e/support/document-initial-data.ts@@ -163,3 +163,88 @@ export const DOCUMENT_WITH_THREE_CARDS_AND_COLUMNS = {],type: "doc",};++export const DOCUMENT_WITH_SUPPORTING_TEXT = {+ type: "doc",+ content: [+ {+ type: "resizeNode",+ attrs: {+ height: 350,+ minHeight: 280,+ _id: "1",+ },+ content: [+ {+ type: "flexContainer",+ attrs: {+ _id: "1a",+ columnWidths: [33.33333333333333, 66.66666666666666],+ },+ content: [+ {+ type: "supportingText",+ attrs: { _id: "1b" },+ content: [+ {+ type: "paragraph",+ attrs: { _id: "1c" },+ content: [+ {+ type: "text",+ text: "Lorem ipsum",+ },+ ],+ },+ ],+ },+ {+ type: "cardEmbed",+ attrs: {+ id: ORDERS_QUESTION_ID,+ name: null,+ _id: "2a2",+ },+ },+ ],+ },+ ],+ },+ {+ type: "paragraph",+ content: [+ {+ type: "text",+ text: "Standalone card below",+ },+ ],+ attrs: {+ _id: "3",+ },+ },+ {+ type: "resizeNode",+ attrs: {+ height: 350,+ minHeight: 280,+ _id: "4",+ },+ content: [+ {+ type: "cardEmbed",+ attrs: {+ id: ORDERS_COUNT_QUESTION_ID,+ name: null,+ _id: "4a",+ },+ },+ ],+ },+ {+ type: "paragraph",+ attrs: {+ _id: "5",+ },+ },+ ],+};diff --git a/e2e/support/helpers/e2e-document-helpers.ts b/e2e/support/helpers/e2e-document-helpers.tsindex 441561c202c..17d234fd52d 100644--- a/e2e/support/helpers/e2e-document-helpers.ts+++ b/e2e/support/helpers/e2e-document-helpers.ts@@ -109,33 +109,33 @@ const visitDocumentById = (id: DocumentId) => {cy.wait(`@${alias}`);};-export function dragAndDropCardOnAnotherCard(- sourceCardTitle: string,- targetCardTitle: string,- {- side = "left",- }: {- side?: "left" | "right";- } = {},-) {- // Perform drag and drop: drag sourceCard card onto targetCard- getDocumentCard(sourceCardTitle)+export function documentsDragAndDrop({+ getSource,+ getTarget,+ side = "left",+}: {+ getSource: () => Cypress.Chainable;+ getTarget: () => Cypress.Chainable;+ side?: "left" | "right";+}) {+ // Perform drag and drop: drag source onto target+ getSource().should("exist")- .then(($ordersCard) => {- getDocumentCard(targetCardTitle)+ .then(($source) => {+ getTarget().should("exist")- .then(($ordersCountCard) => {- const sourceRect = $ordersCard[0].getBoundingClientRect();+ .then(($target) => {+ const sourceRect = $source[0].getBoundingClientRect();- // Start drag from center of Orders card- getDocumentCard(sourceCardTitle).trigger("mousedown", {+ // Start drag from center of source+ getSource().trigger("mousedown", {x: 10,y: 10,scrollBehavior: false,force: true,});const dataTransfer = new DataTransfer();- getDocumentCard(sourceCardTitle).trigger("dragstart", {+ getSource().trigger("dragstart", {dataTransfer,clientX: sourceRect.left + 10,clientY: sourceRect.top + 10,@@ -143,8 +143,8 @@ export function dragAndDropCardOnAnotherCard(force: true,});- const targetRect = $ordersCountCard[0].getBoundingClientRect();- // Calculate position for target card side drop (20% from left or 20% from right based on 'side' param)+ const targetRect = $target[0].getBoundingClientRect();+ // Calculate position for target side drop (20% from left or 20% from right based on 'side' param)const sideX =targetRect.left + targetRect.width * (side === "left" ? 0.2 : 0.8);const centerY = targetRect.top + 10;@@ -153,24 +153,24 @@ export function dragAndDropCardOnAnotherCard(clientY: centerY,scrollBehavior: false,});- getDocumentCard(targetCardTitle).trigger("dragover", {+ getTarget().trigger("dragover", {clientX: sideX,clientY: centerY,scrollBehavior: false,force: true,});- getDocumentCard(sourceCardTitle).realMouseUp({+ getSource().realMouseUp({scrollBehavior: false,});- getDocumentCard(targetCardTitle).trigger("drop", {+ getTarget().trigger("drop", {dataTransfer,clientX: sideX,clientY: centerY,scrollBehavior: false,force: true,});- getDocumentCard(sourceCardTitle).trigger("dragend", {+ getSource().trigger("dragend", {scrollBehavior: false,force: true,});@@ -178,6 +178,20 @@ export function dragAndDropCardOnAnotherCard(});}+export function dragAndDropCardOnAnotherCard(+ sourceCardTitle: string,+ targetCardTitle: string,+ options: {+ side?: "left" | "right";+ } = {},+) {+ return documentsDragAndDrop({+ getSource: () => getDocumentCard(sourceCardTitle),+ getTarget: () => getDocumentCard(targetCardTitle),+ ...options,+ });+}+export function documentUndo() {const macOSX = Cypress.platform === "darwin";diff --git a/e2e/test/scenarios/documents/supporting-text.cy.spec.ts b/e2e/test/scenarios/documents/supporting-text.cy.spec.tsindex 840a465a0c5..be14b242615 100644--- a/e2e/test/scenarios/documents/supporting-text.cy.spec.ts+++ b/e2e/test/scenarios/documents/supporting-text.cy.spec.ts@@ -1,4 +1,5 @@import {+ DOCUMENT_WITH_SUPPORTING_TEXT,DOCUMENT_WITH_THREE_CARDS_AND_COLUMNS,DOCUMENT_WITH_TWO_CARDS,} from "e2e/support/document-initial-data";@@ -455,4 +456,112 @@ describe("documents supporting text", () => {H.dragAndDropCardOnAnotherCard("Orders, Count", targetCardTitle);H.documentContent().findByText("Lorem ipsum").should("not.exist");});++ describe("drag and drop", () => {+ beforeEach(() => {+ H.createDocument({+ name: "DnD Test Document",+ document: DOCUMENT_WITH_SUPPORTING_TEXT,+ collection_id: null,+ alias: "document",+ idAlias: "documentId",+ });+ H.visitDocument("@documentId");+ });++ const getSupportingText = (contents: string = "Lorem ipsum") => {+ const testId = "document-card-supporting-text";+ return cy+ .findAllByTestId(testId)+ .contains(contents)+ .closest(`[data-testid="${testId}"]`);+ };++ const assertHorizontalLayout = (+ c1: Cypress.Chainable<JQuery<HTMLElement>>,+ c2: Cypress.Chainable<JQuery<HTMLElement>>,+ ) => {+ c1.then(($c1) => {+ c2.then(($c2) => {+ const rect1 = $c1[0].getBoundingClientRect();+ const rect2 = $c2[0].getBoundingClientRect();+ expect(rect2.left).to.gte(rect1.right);+ expect(rect1.top).to.be.closeTo(rect2.top, 2);+ });+ });+ };++ const assertVerticalLayout = (+ c1: Cypress.Chainable<JQuery<HTMLElement>>,+ c2: Cypress.Chainable<JQuery<HTMLElement>>,+ ) => {+ c1.then(($c1) => {+ c2.then(($c2) => {+ const rect1 = $c1[0].getBoundingClientRect();+ const rect2 = $c2[0].getBoundingClientRect();+ expect(rect2.top).to.gte(rect1.bottom);+ expect(rect1.left).to.be.closeTo(rect2.left, 2);+ });+ });+ };++ it("should reorder when dropping a supporting text block onto a card", () => {+ H.getDocumentCard("Orders").should("exist");+ H.documentsDragAndDrop({+ getSource: () => getSupportingText().find("[data-drag-handle]"),+ getTarget: () => H.getDocumentCard("Orders"),+ side: "right",+ });++ assertHorizontalLayout(H.getDocumentCard("Orders"), getSupportingText());+ assertVerticalLayout(+ H.getDocumentCard("Orders"),+ H.getDocumentCard("Orders, Count"),+ );+ });++ it("should reorder when dropping a card onto a supporting text block", () => {+ H.getDocumentCard("Orders").should("exist");+ H.documentsDragAndDrop({+ getSource: () => H.getDocumentCard("Orders"),+ getTarget: () => getSupportingText(),+ side: "left",+ });++ assertHorizontalLayout(H.getDocumentCard("Orders"), getSupportingText());+ assertVerticalLayout(+ H.getDocumentCard("Orders"),+ H.getDocumentCard("Orders, Count"),+ );+ });++ it("should insert a card when dropped onto a supporting text block", () => {+ H.getDocumentCard("Orders").should("exist");+ H.documentsDragAndDrop({+ getSource: () => H.getDocumentCard("Orders, Count"),+ getTarget: () => getSupportingText(),+ side: "left",+ });++ assertHorizontalLayout(+ H.getDocumentCard("Orders, Count"),+ getSupportingText(),+ );+ assertHorizontalLayout(getSupportingText(), H.getDocumentCard("Orders"));+ });++ it("should do nothing if dragging a supporting text block outside of a group", () => {+ H.getDocumentCard("Orders").should("exist");+ H.documentsDragAndDrop({+ getSource: () => getSupportingText().find("[data-drag-handle]"),+ getTarget: () => H.getDocumentCard("Orders, Count"),+ });++ assertHorizontalLayout(getSupportingText(), H.getDocumentCard("Orders"));+ assertVerticalLayout(+ getSupportingText(),+ H.getDocumentCard("Orders, Count"),+ );+ });+ });});diff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/Editor.tsx b/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/Editor.tsxindex fbee97e5112..c96e82363a0 100644--- a/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/Editor.tsx+++ b/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/Editor.tsx@@ -17,14 +17,12 @@ import type { DocumentsStoreState } from "metabase-enterprise/documents/types";import { isMetabotBlock } from "metabase-enterprise/documents/utils/editorNodeUtils";import { getMentionsCacheKey } from "metabase-enterprise/documents/utils/mentionsUtils";import { EditorBubbleMenu } from "metabase-enterprise/rich_text_editing/tiptap/components/EditorBubbleMenu/EditorBubbleMenu";-import {- CardEmbed,- DROP_ZONE_COLOR,-} from "metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode";+import { CardEmbed } from "metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode";import { CommandExtension } from "metabase-enterprise/rich_text_editing/tiptap/extensions/Command/CommandExtension";import { CommandSuggestion } from "metabase-enterprise/rich_text_editing/tiptap/extensions/Command/CommandSuggestion";import { CustomStarterKit } from "metabase-enterprise/rich_text_editing/tiptap/extensions/CustomStarterKit/CustomStarterKit";import { DisableMetabotSidebar } from "metabase-enterprise/rich_text_editing/tiptap/extensions/DisableMetabotSidebar";+import DropCursorS from "metabase-enterprise/rich_text_editing/tiptap/extensions/DropCursor/DropCursor.module.css";import { FlexContainer } from "metabase-enterprise/rich_text_editing/tiptap/extensions/FlexContainer/FlexContainer";import { HandleEditorDrop } from "metabase-enterprise/rich_text_editing/tiptap/extensions/HandleEditorDrop/HandleEditorDrop";import { LinkHoverMenu } from "metabase-enterprise/rich_text_editing/tiptap/extensions/LinkHoverMenu/LinkHoverMenu";@@ -40,6 +38,7 @@ import { PlainLink } from "metabase-enterprise/rich_text_editing/tiptap/extensioimport { ResizeNode } from "metabase-enterprise/rich_text_editing/tiptap/extensions/ResizeNode/ResizeNode";import { SmartLink } from "metabase-enterprise/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode";import { SupportingText } from "metabase-enterprise/rich_text_editing/tiptap/extensions/SupportingText/SupportingText";+import { DROP_ZONE_COLOR } from "metabase-enterprise/rich_text_editing/tiptap/extensions/shared/constants";import { createSuggestionRenderer } from "metabase-enterprise/rich_text_editing/tiptap/extensions/suggestionRenderer";import S from "./Editor.module.css";@@ -111,6 +110,7 @@ export const Editor: React.FC<EditorProps> = ({dropcursor: {color: DROP_ZONE_COLOR,width: 2,+ class: DropCursorS.dropCursor,},}),Image.configure({diff --git a/enterprise/frontend/src/metabase-enterprise/public/containers/PublicDocument/PublicDocument.tsx b/enterprise/frontend/src/metabase-enterprise/public/containers/PublicDocument/PublicDocument.tsxindex cb6204639f8..181723b9f3c 100644--- a/enterprise/frontend/src/metabase-enterprise/public/containers/PublicDocument/PublicDocument.tsx+++ b/enterprise/frontend/src/metabase-enterprise/public/containers/PublicDocument/PublicDocument.tsx@@ -14,15 +14,13 @@ import { getSetting } from "metabase/selectors/settings";import { PublicApi } from "metabase/services";import { Box } from "metabase/ui";import { PublicDocumentProvider } from "metabase-enterprise/public/contexts/PublicDocumentContext";-import {- CardEmbed,- DROP_ZONE_COLOR,-} from "metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode";+import { CardEmbed } from "metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode";import { CustomStarterKit } from "metabase-enterprise/rich_text_editing/tiptap/extensions/CustomStarterKit/CustomStarterKit";import { FlexContainer } from "metabase-enterprise/rich_text_editing/tiptap/extensions/FlexContainer/FlexContainer";import { ResizeNode } from "metabase-enterprise/rich_text_editing/tiptap/extensions/ResizeNode/ResizeNode";import { SmartLink } from "metabase-enterprise/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode";import { SupportingText } from "metabase-enterprise/rich_text_editing/tiptap/extensions/SupportingText/SupportingText";+import { DROP_ZONE_COLOR } from "metabase-enterprise/rich_text_editing/tiptap/extensions/shared/constants";import type { Document } from "metabase-types/api";import S from "./PublicDocument.module.css";diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedMenuDropdown.tsx b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedMenuDropdown.tsxnew file mode 100644index 00000000000..37ad54be67a--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedMenuDropdown.tsx@@ -0,0 +1,150 @@+import { t } from "ttag";++import { ForwardRefLink } from "metabase/common/components/Link";+import { canDownloadResults } from "metabase/dashboard/components/DashCard/DashCardMenu/utils";+import { isWithinIframe } from "metabase/lib/dom";+import { QuestionDownloadWidget } from "metabase/query_builder/components/QuestionDownloadWidget";+import { Icon, Menu } from "metabase/ui";+import type Question from "metabase-lib/v1/Question";+import type { Dataset } from "metabase-types/api";++export interface CardEmbedMenuContext {+ canWrite: boolean;+ dataset: Dataset | undefined;+ question: Question | undefined;+ isNativeQuestion: boolean | undefined;+ commentsPath: string;+ hasUnsavedChanges: boolean;+ unresolvedCommentsCount: number;+}++export interface CardEmbedMenuActions {+ handleDownload: (opts: {+ type: string;+ enableFormatting: boolean;+ enablePivot: boolean;+ }) => void;+ handleEditVisualizationSettings: () => void;+ setIsModifyModalOpen: (open: boolean) => void;+ handleReplaceQuestion: () => void;+ handleRemoveNode: () => void;+ handleAddSupportingText?: () => void;+}++export interface CardEmbedMenuState {+ menuView: string | null;+ setMenuView: (view: string | null) => void;+ isDownloadingData: boolean;+}++export type CardEmbedMenuDropdownProps = CardEmbedMenuContext &+ CardEmbedMenuActions &+ CardEmbedMenuState;+export const CardEmbedMenuDropdown = ({+ // Context+ canWrite,+ dataset,+ question,+ isNativeQuestion,+ commentsPath,+ hasUnsavedChanges,+ unresolvedCommentsCount,+ // Actions+ handleDownload,+ handleEditVisualizationSettings,+ setIsModifyModalOpen,+ handleReplaceQuestion,+ handleRemoveNode,+ handleAddSupportingText,+ // State+ menuView,+ setMenuView,+ isDownloadingData,+}: CardEmbedMenuDropdownProps) => {+ if (menuView === "downloads" && question && dataset) {+ return (+ <QuestionDownloadWidget+ question={question}+ result={dataset}+ onDownload={(opts) => {+ setMenuView(null);+ handleDownload(opts);+ }}+ />+ );+ }++ return (+ <>+ {!isWithinIframe() && canWrite && (+ <Menu.Item+ leftSection={<Icon name="add_comment" size={14} />}+ component={ForwardRefLink}+ to={+ unresolvedCommentsCount > 0+ ? commentsPath+ : `${commentsPath}?new=true`+ }+ onClick={(e) => {+ if (!commentsPath || hasUnsavedChanges) {+ e.preventDefault();+ }+ }}+ disabled={!commentsPath || hasUnsavedChanges}+ >+ {t`Comment`}+ </Menu.Item>+ )}+ <Menu.Item+ onClick={handleAddSupportingText}+ disabled={!canWrite || !handleAddSupportingText}+ leftSection={<Icon name="add_list" size={14} />}+ >+ {t`Add supporting text`}+ </Menu.Item>+ <Menu.Item+ onClick={handleEditVisualizationSettings}+ leftSection={<Icon name="palette" size={14} />}+ disabled={!canWrite}+ >+ {t`Edit Visualization`}+ </Menu.Item>+ <Menu.Item+ onClick={() => setIsModifyModalOpen(true)}+ leftSection={+ <Icon name={isNativeQuestion ? "sql" : "notebook"} size={14} />+ }+ disabled={!canWrite}+ >+ {t`Edit Query`}+ </Menu.Item>+ <Menu.Item+ onClick={handleReplaceQuestion}+ leftSection={<Icon name="refresh" size={14} />}+ disabled={!canWrite}+ >+ {t`Replace`}+ </Menu.Item>+ {canDownloadResults(dataset) && (+ <Menu.Item+ leftSection={<Icon name="download" aria-hidden />}+ aria-label={isDownloadingData ? t`Downloading…` : t`Download results`}+ disabled={isDownloadingData}+ closeMenuOnClick={false}+ onClick={() => {+ setMenuView("downloads");+ }}+ >+ {isDownloadingData ? t`Downloading…` : t`Download results`}+ </Menu.Item>+ )}+ <Menu.Item+ onClick={handleRemoveNode}+ leftSection={<Icon name="trash" size={14} />}+ disabled={!canWrite}+ >+ {t`Remove Chart`}+ </Menu.Item>+ </>+ );+};diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode.tsx b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode.tsxindex b88b9492eb8..304fba88f02 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode.tsx+++ b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode.tsx@@ -14,13 +14,9 @@ import { push } from "react-router-redux";import { t } from "ttag";import { Ellipsified } from "metabase/common/components/Ellipsified";-import { ForwardRefLink } from "metabase/common/components/Link";import { QuestionPickerModal } from "metabase/common/components/Pickers/QuestionPicker/components/QuestionPickerModal";import type { QuestionPickerValueItem } from "metabase/common/components/Pickers/QuestionPicker/types";-import { canDownloadResults } from "metabase/dashboard/components/DashCard/DashCardMenu/utils";-import { isWithinIframe } from "metabase/lib/dom";import { useDispatch, useSelector } from "metabase/lib/redux";-import { QuestionDownloadWidget } from "metabase/query_builder/components/QuestionDownloadWidget";import { useDownloadData } from "metabase/query_builder/components/QuestionDownloadWidget/use-download-data";import { getMetadata } from "metabase/selectors/metadata";import { Box, Flex, Icon, Loader, Menu, Text, TextInput } from "metabase/ui";@@ -53,6 +49,7 @@ import {import { getListCommentsQuery } from "metabase-enterprise/documents/utils/api";import { usePublicDocumentContext } from "metabase-enterprise/public/contexts/PublicDocumentContext";import { usePublicDocumentCardData } from "metabase-enterprise/public/hooks/use-public-document-card-data";+import { DropZone } from "metabase-enterprise/rich_text_editing/tiptap/extensions/shared/dnd/DropZone";import Question from "metabase-lib/v1/Question";import { getUrl } from "metabase-lib/v1/urls";import type { CardDisplayType, Dataset } from "metabase-types/api";@@ -65,186 +62,15 @@ import {import { createIdAttribute, createProseMirrorPlugin } from "../NodeIds";import CS from "../extensions.module.css";import { NativeQueryModal } from "../shared/NativeQueryModal";+import { useDndHelpers } from "../shared/dnd/use-dnd-helpers";+import { CardEmbedMenuDropdown } from "./CardEmbedMenuDropdown";import styles from "./CardEmbedNode.module.css";import { PublicDocumentCardMenu } from "./PublicDocumentCardMenu";import { ModifyQuestionModal } from "./modals/ModifyQuestionModal";-import { useDndHelpers } from "./use-dnd-helpers";import { useUpdateCardOperations } from "./use-update-card-operations";import { getEmbedIndex } from "./utils";-interface CardEmbedMenuContext {- canWrite: boolean;- dataset: Dataset | undefined;- question: Question | undefined;- isNativeQuestion: boolean | undefined;- commentsPath: string;- hasUnsavedChanges: boolean;- unresolvedCommentsCount: number;-}--interface CardEmbedMenuActions {- handleDownload: (opts: {- type: string;- enableFormatting: boolean;- enablePivot: boolean;- }) => void;- handleEditVisualizationSettings: () => void;- setIsModifyModalOpen: (open: boolean) => void;- handleReplaceQuestion: () => void;- handleRemoveNode: () => void;- handleAddSupportingText?: () => void;-}--interface CardEmbedMenuState {- menuView: string | null;- setMenuView: (view: string | null) => void;- isDownloadingData: boolean;-}--type CardEmbedMenuDropdownProps = CardEmbedMenuContext &- CardEmbedMenuActions &- CardEmbedMenuState;--const CardEmbedMenuDropdown = ({- // Context- canWrite,- dataset,- question,- isNativeQuestion,- commentsPath,- hasUnsavedChanges,- unresolvedCommentsCount,- // Actions- handleDownload,- handleEditVisualizationSettings,- setIsModifyModalOpen,- handleReplaceQuestion,- handleRemoveNode,- handleAddSupportingText,- // State- menuView,- setMenuView,- isDownloadingData,-}: CardEmbedMenuDropdownProps) => {- if (menuView === "downloads" && question && dataset) {- return (- <QuestionDownloadWidget- question={question}- result={dataset}- onDownload={(opts) => {- setMenuView(null);- handleDownload(opts);- }}- />- );- }-- return (- <>- {!isWithinIframe() && canWrite && (- <Menu.Item- leftSection={<Icon name="add_comment" size={14} />}- component={ForwardRefLink}- to={- unresolvedCommentsCount > 0- ? commentsPath- : `${commentsPath}?new=true`- }- onClick={(e) => {- if (!commentsPath || hasUnsavedChanges) {- e.preventDefault();- }- }}- disabled={!commentsPath || hasUnsavedChanges}- >- {t`Comment`}- </Menu.Item>- )}- <Menu.Item- onClick={handleAddSupportingText}- disabled={!canWrite || !handleAddSupportingText}- leftSection={<Icon name="add_list" size={14} />}- >- {t`Add supporting text`}- </Menu.Item>- <Menu.Item- onClick={handleEditVisualizationSettings}- leftSection={<Icon name="palette" size={14} />}- disabled={!canWrite}- >- {t`Edit Visualization`}- </Menu.Item>- <Menu.Item- onClick={() => setIsModifyModalOpen(true)}- leftSection={- <Icon name={isNativeQuestion ? "sql" : "notebook"} size={14} />- }- disabled={!canWrite}- >- {t`Edit Query`}- </Menu.Item>- <Menu.Item- onClick={handleReplaceQuestion}- leftSection={<Icon name="refresh" size={14} />}- disabled={!canWrite}- >- {t`Replace`}- </Menu.Item>- {canDownloadResults(dataset) && (- <Menu.Item- leftSection={<Icon name="download" aria-hidden />}- aria-label={isDownloadingData ? t`Downloading…` : t`Download results`}- disabled={isDownloadingData}- closeMenuOnClick={false}- onClick={() => {- setMenuView("downloads");- }}- >- {isDownloadingData ? t`Downloading…` : t`Download results`}- </Menu.Item>- )}- <Menu.Item- onClick={handleRemoveNode}- leftSection={<Icon name="trash" size={14} />}- disabled={!canWrite}- >- {t`Remove Chart`}- </Menu.Item>- </>- );-};--export const DROP_ZONE_COLOR = "var(--mb-color-brand)";--interface DropZoneProps {- isOver: boolean;- side: "left" | "right";- disabled?: boolean;-}--const DropZone = ({ isOver, side, disabled }: DropZoneProps) => {- if (disabled) {- return null;- }-- return (- <Box- style={{- position: "absolute",- top: 0,- bottom: 0,- width: "0.25rem",- [side]: "-0.625rem",- borderRadius: "0.125rem",- backgroundColor: isOver ? DROP_ZONE_COLOR : "transparent",- zIndex: 10,- pointerEvents: "all",- }}- />- );-};-function formatCardEmbed(attrs: CardEmbedAttributes): string {if (attrs.name) {return `{% card id=${attrs.id} name="${attrs.name}" %}`;@@ -376,7 +202,7 @@ export const CardEmbedComponent = memo(dragState,setDragState,handleDragOver,- cardEmbedRef,+ dragElRef: cardEmbedRef,} = useDndHelpers({ editor, node, getPos });const embedIndex = getEmbedIndex(editor, getPos);diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/DropCursor/DropCursor.module.css b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/DropCursor/DropCursor.module.cssnew file mode 100644index 00000000000..14dbf33f979--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/DropCursor/DropCursor.module.css@@ -0,0 +1,5 @@+:global(.dragging-supportingText) {+ .dropCursor {+ display: none;+ }+}diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/FlexContainer/FlexContainer.module.css b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/FlexContainer/FlexContainer.module.cssindex bc1a57aa7f3..b5550e6185c 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/FlexContainer/FlexContainer.module.css+++ b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/FlexContainer/FlexContainer.module.css@@ -49,16 +49,16 @@}.flexContent :global(.node-supportingText) {- padding-left: 0.5rem;- padding-right: 0.5rem;+ margin-left: 0.5rem;+ margin-right: 0.5rem;}.flexContent :global(.node-supportingText):first-child {- padding-left: 0;+ margin-left: 0;}.flexContent :global(.node-supportingText):last-child {- padding-right: 0;+ margin-right: 0;}/* Resize handles */diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/HandleEditorDrop/DropHandlers/cardToCard.ts b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/HandleEditorDrop/DropHandlers/cardToCard.tsindex 2331385a277..5c27b4e23c4 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/HandleEditorDrop/DropHandlers/cardToCard.ts+++ b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/HandleEditorDrop/DropHandlers/cardToCard.ts@@ -15,7 +15,7 @@ export const handleCardDropOnCard = (targetCardEmbed: Node,) => {const {- cardEmbedNode,+ draggedNode,view,event: e,originalParent,@@ -25,16 +25,16 @@ export const handleCardDropOnCard = (cameFromFlexContainer,} = payload;- if (targetCardEmbed === cardEmbedNode) {+ if (targetCardEmbed === draggedNode) {return true; // Prevent dropping on itself}const dropSide = getCardEmbedDropSide(e);- // Create new FlexContainer when dropping on a standalone CardEmbed+ // Create new FlexContainer when dropping on a standalone itemconst children =dropSide === "left"- ? [cardEmbedNode.copy(), targetCardEmbed.copy()]- : [targetCardEmbed.copy(), cardEmbedNode.copy()];+ ? [draggedNode.copy(), targetCardEmbed.copy()]+ : [targetCardEmbed.copy(), draggedNode.copy()];const flexContainer = view.state.schema.nodes.flexContainer.create({},@@ -52,7 +52,7 @@ export const handleCardDropOnCard = (// Determine what to replace - if target is wrapped in resizeNode, replace the wrapperlet replacePos = originalPos;- let replaceSize = cardEmbedNode.nodeSize;+ let replaceSize = draggedNode.nodeSize;if (dropToParent.type.name === "resizeNode") {// Target is wrapped, replace the entire resizeNodereplacePos = dropToParentPos.before();@@ -64,7 +64,7 @@ export const handleCardDropOnCard = (// First, find and remove the dropped node from its original positionconst nodeToRemove =- originalParent.type.name === "resizeNode" ? originalParent : cardEmbedNode;+ originalParent.type.name === "resizeNode" ? originalParent : draggedNode;let removalHandled = false;let removePos: number | null = null;view.state.doc.descendants((node, nodePos) => {diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/HandleEditorDrop/DropHandlers/cardToDocument.ts b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/HandleEditorDrop/DropHandlers/cardToDocument.tsindex b6accf31541..7780d72d655 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/HandleEditorDrop/DropHandlers/cardToDocument.ts+++ b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/HandleEditorDrop/DropHandlers/cardToDocument.ts@@ -4,7 +4,10 @@ import {RESIZE_NODE_DEFAULT_HEIGHT,RESIZE_NODE_MIN_HEIGHT,} from "../../ResizeNode/ResizeNode";-import { type DroppedCardEmbedNodeData, extractCardEmbed } from "../utils";+import {+ type DroppedCardEmbedNodeData,+ extractContainerSingleCardNode,+} from "../utils";export const handleCardDropOnDocument = (payload: DroppedCardEmbedNodeData) => {const {@@ -12,7 +15,7 @@ export const handleCardDropOnDocument = (payload: DroppedCardEmbedNodeData) => {originalPos,view,cameFromFlexContainer,- cardEmbedNode,+ draggedNode,dropPos,} = payload;let diffSize = 0;@@ -54,9 +57,20 @@ export const handleCardDropOnDocument = (payload: DroppedCardEmbedNodeData) => {if (newChildren.length === 1) {// If only one card left, unwrap it from FlexContainer and wrap in resizeNodeconst remainingChild = newChildren[0];- const remainingCardEmbed = extractCardEmbed(remainingChild);+ const remainingCardEmbed =+ extractContainerSingleCardNode(remainingChild);- if (remainingCardEmbed) {+ if (remainingCardEmbed?.type.name === "supportingText") {+ // Only a SupportingText is left, remove the entire FlexContainer and its wrapper+ const containerResolvedPos = view.state.doc.resolve(flexContainerPos);+ const containerParent = containerResolvedPos.parent;+ const wrapperPos = containerResolvedPos.before();+ replaceWith(+ wrapperPos,+ wrapperPos + containerParent.nodeSize,+ Fragment.empty,+ );+ } else if (remainingCardEmbed) {const wrappedRemainingCard =view.state.schema.nodes.resizeNode.create({@@ -86,16 +100,6 @@ export const handleCardDropOnDocument = (payload: DroppedCardEmbedNodeData) => {wrappedRemainingCard,);}- } else {- // Only a SupportingText is left, remove the entire FlexContainer and its wrapper- const containerResolvedPos = view.state.doc.resolve(flexContainerPos);- const containerParent = containerResolvedPos.parent;- const wrapperPos = containerResolvedPos.before();- replaceWith(- wrapperPos,- wrapperPos + containerParent.nodeSize,- Fragment.empty,- );}} else if (newChildren.length > 1) {// Multiple cards left, keep as FlexContainer@@ -137,7 +141,7 @@ export const handleCardDropOnDocument = (payload: DroppedCardEmbedNodeData) => {height: RESIZE_NODE_DEFAULT_HEIGHT,minHeight: RESIZE_NODE_MIN_HEIGHT,},- [cardEmbedNode],+ [draggedNode],);// Calculate adjusted drop position if the FlexContainer operations affected positions@@ -162,10 +166,10 @@ export const handleCardDropOnDocument = (payload: DroppedCardEmbedNodeData) => {height: RESIZE_NODE_DEFAULT_HEIGHT,minHeight: RESIZE_NODE_MIN_HEIGHT,},- [cardEmbedNode],+ [draggedNode],);- const nodeToRemove = originalParent || cardEmbedNode;+ const nodeToRemove = originalParent || draggedNode;// Remove the original node from its position// Find the actual node to remove (could be the cardEmbed itself or its resizeNode wrapper)diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/HandleEditorDrop/DropHandlers/cardToFlexContainer.ts b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/HandleEditorDrop/DropHandlers/cardToFlexContainer.tsindex db1516d1c30..606d3e71f98 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/HandleEditorDrop/DropHandlers/cardToFlexContainer.ts+++ b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/HandleEditorDrop/DropHandlers/cardToFlexContainer.ts@@ -6,7 +6,7 @@ import {} from "../../ResizeNode/ResizeNode";import {type DroppedCardEmbedNodeData,- extractCardEmbed,+ extractContainerSingleCardNode,getCardEmbedDropSide,getTargetCardEmbedNode,} from "../utils";@@ -18,32 +18,31 @@ export const handleCardDropToFlexContainer = (cameFromFlexContainer,originalParent,dropToParent,- cardEmbedNode,+ draggedNode,view,originalPos,event: e,- dropToParentPos,} = payload;// Handle dropping within the same FlexContainer - columns reorderingif (cameFromFlexContainer && originalParent === dropToParent) {- const targetCardEmbedNode = getTargetCardEmbedNode(e, view);+ const targetNode = getTargetCardEmbedNode(e, view);- if (!targetCardEmbedNode) {+ if (!targetNode) {return;}- if (targetCardEmbedNode === cardEmbedNode) {+ if (targetNode === draggedNode) {return true; // Prevent dropping on itself}- // Moving within the same FlexContainer - reorder cards+ // Moving within the same FlexContainer - reorder itemsconst tr = view.state.tr;// Find the source indexconst sourceIndex = view.state.doc.resolve(originalPos).index();// Calculate the intended insertion index based on drop position- let targetIndex = dropToParent.content.content.indexOf(targetCardEmbedNode);+ let targetIndex = dropToParent.content.content.indexOf(targetNode);const dropSide = getCardEmbedDropSide(e);if (dropSide === "left" && targetIndex > 1) {@@ -57,8 +56,8 @@ export const handleCardDropToFlexContainer = (for (let i = 0; i < dropToParent.childCount; i++) {if (i !== sourceIndex) {const child = dropToParent.child(i);- const childCardEmbed = extractCardEmbed(child);- allChildren.push(childCardEmbed ? childCardEmbed : child);+ const extractedChild = extractContainerSingleCardNode(child);+ allChildren.push(extractedChild ? extractedChild : child);}}@@ -81,7 +80,7 @@ export const handleCardDropToFlexContainer = (}// Insert the dragged element at the correct position- allChildren.splice(adjustedTargetIndex, 0, cardEmbedNode);+ allChildren.splice(adjustedTargetIndex, 0, draggedNode);// Preserve column widths by reordering them to match the new card positionsconst currentColumnWidths = dropToParent.attrs.columnWidths;@@ -111,7 +110,18 @@ export const handleCardDropToFlexContainer = (allChildren,);- const containerPos = dropToParentPos.before();+ // Find the actual position of the FlexContainer in the document+ let containerPos: number | null = null;+ view.state.doc.descendants((node, nodePos) => {+ if (node === dropToParent) {+ containerPos = nodePos;+ return false;+ }+ });++ if (containerPos === null) {+ return true; // Safety check+ }tr.replaceWith(containerPos,@@ -126,20 +136,23 @@ export const handleCardDropToFlexContainer = (// Handle dropping from one FlexContainer to another FlexContainerif (cameFromFlexContainer && originalParent !== dropToParent) {+ if (draggedNode.type.name === "supportingText") {+ return true;+ }const targetFlexContainer = dropToParent;- // Check if target flexContainer already has 3 or more cards+ // Check if target flexContainer already has 3 or more itemsif (targetFlexContainer.content.childCount >= 3) {- return true; // Don't allow dropping if target already has 3 cards+ return true; // Don't allow dropping if target already has 3 items}- const targetCardEmbedNode = getTargetCardEmbedNode(e, view);- if (!targetCardEmbedNode) {+ const targetNode = getTargetCardEmbedNode(e, view);+ if (!targetNode) {return;}// Calculate the intended insertion index based on drop position- let targetIndex = dropToParent.content.content.indexOf(targetCardEmbedNode);+ let targetIndex = dropToParent.content.content.indexOf(targetNode);const dropSide = getCardEmbedDropSide(e);if (dropSide === "left" && targetIndex > 1) {@@ -180,9 +193,12 @@ export const handleCardDropToFlexContainer = (if (sourceNewChildren.length === 1) {// Only one card left in source - unwrap it from flexContainerconst remainingChild = sourceNewChildren[0];- const remainingCardEmbed = extractCardEmbed(remainingChild);+ const remainingCardEmbed = extractContainerSingleCardNode(remainingChild);- if (remainingCardEmbed) {+ if (+ remainingCardEmbed &&+ remainingCardEmbed.type.name !== "supportingText"+ ) {const wrappedRemainingCard = view.state.schema.nodes.resizeNode.create({height: RESIZE_NODE_DEFAULT_HEIGHT,@@ -254,14 +270,14 @@ export const handleCardDropToFlexContainer = (}}- // Now add the card to the target flexContainer+ // Now add the item to the target flexContainerconst targetChildren: Node[] = [];for (let i = 0; i < targetFlexContainer.content.childCount; i++) {const child = targetFlexContainer.content.child(i);targetChildren.push(child);}- targetChildren.splice(targetIndex, 0, cardEmbedNode.copy());+ targetChildren.splice(targetIndex, 0, draggedNode.copy());// Find target flexContainer positionlet targetFlexContainerPos: number | null = null;@@ -304,21 +320,21 @@ export const handleCardDropToFlexContainer = (return true;}- // Handle dropping on a cardEmbed that is already in a flexContainer+ // Handle dropping on an item that is already in a flexContainerif (!cameFromFlexContainer) {const flexContainer = dropToParent;if (flexContainer.content.childCount === 3) {- return true; // Don't allow more than 3 cards in flexContainer+ return true; // Don't allow more than 3 items in flexContainer}- const targetCardEmbedNode = getTargetCardEmbedNode(e, view);- if (!targetCardEmbedNode) {+ const targetNode = getTargetCardEmbedNode(e, view);+ if (!targetNode) {return;}// Calculate the intended insertion index based on drop position- let targetIndex = dropToParent.content.content.indexOf(targetCardEmbedNode);+ let targetIndex = dropToParent.content.content.indexOf(targetNode);const dropSide = getCardEmbedDropSide(e);if (dropSide === "left" && targetIndex > 1) {@@ -327,14 +343,14 @@ export const handleCardDropToFlexContainer = (targetIndex++;}- // Get all current children as cardEmbeds+ // Get all current childrenconst newChildren: Node[] = [];for (let i = 0; i < flexContainer.content.childCount; i++) {const child = flexContainer.content.child(i);newChildren.push(child);}- newChildren.splice(targetIndex, 0, cardEmbedNode.copy());+ newChildren.splice(targetIndex, 0, draggedNode.copy());// Find the position of the flexContainer (it should be wrapped in resizeNode)let flexContainerPos: number | null = null;@@ -368,9 +384,7 @@ export const handleCardDropToFlexContainer = (// Now remove the dropped node from its original position// We need to find it again in the updated documentconst nodeToRemove =- originalParent.type.name === "resizeNode"- ? originalParent- : cardEmbedNode;+ originalParent.type.name === "resizeNode" ? originalParent : draggedNode;const updatedDoc = tr.doc;let nodeFound = false;diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/HandleEditorDrop/HandleEditorDrop.tsx b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/HandleEditorDrop/HandleEditorDrop.tsxindex 44a500f91de..1dc771f5001 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/HandleEditorDrop/HandleEditorDrop.tsx+++ b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/HandleEditorDrop/HandleEditorDrop.tsx@@ -11,7 +11,7 @@ import { handleCardDropOnDocument } from "./DropHandlers/cardToDocument";import {type DroppedCardEmbedNodeData,cleanupFlexContainerNodes,- extractCardEmbed,+ extractContainerSingleCardNode,getDroppedCardEmbedNodeData,} from "./utils";@@ -29,16 +29,31 @@ export const HandleEditorDrop = Extension.create({slice,moved,);+ view.dom.offsetParent?.classList.remove(+ "dragging",+ `dragging-${cardEmbedInitialData?.draggedNode.type.name}`,+ );if (cardEmbedInitialData) {- const { dropToParent } = cardEmbedInitialData;+ const { dropToParent, draggedNode } = cardEmbedInitialData;++ // SupportingText can only be dropped within a flexContainer+ // Block drops on standalone nodes or outside flexContainer+ if (+ draggedNode.type.name === "supportingText" &&+ dropToParent.type.name !== "flexContainer" &&+ dropToParent.type.name !== "supportingText"+ ) {+ return true; // Block the drop+ }// Dropping inside a flexContainerif (dropToParent.type.name === "flexContainer") {return handleCardDropToFlexContainer(cardEmbedInitialData);}- const targetCardEmbed = extractCardEmbed(dropToParent);+ const targetCardEmbed =+ extractContainerSingleCardNode(dropToParent);// Dropping on another cardEmbedif (targetCardEmbed &&@@ -50,12 +65,60 @@ export const HandleEditorDrop = Extension.create({);}- if (dropToParent.type.name === "paragraph") {- return handleCardDropOnParagraph(cardEmbedInitialData);- }-- if (dropToParent.type.name === "supportingText") {- return true;+ // Check if dropping on a node inside supportingText (paragraph, heading, etc.)+ // or directly on supportingText+ if (+ dropToParent.type.name === "paragraph" ||+ dropToParent.type.name === "heading" ||+ dropToParent.type.name === "supportingText"+ ) {+ const dropPos = view.state.doc.resolve(+ cardEmbedInitialData.dropPos,+ );+ let currentDepth = dropPos.depth;+ let foundSupportingText = false;+ let foundFlexContainer = false;++ // Walk up the tree to check if we're inside a supportingText+ while (currentDepth > 0) {+ const parentAtDepth = dropPos.node(currentDepth);++ if (+ parentAtDepth.type.name === "supportingText" &&+ !foundSupportingText+ ) {+ foundSupportingText = true;+ }++ if (parentAtDepth.type.name === "flexContainer") {+ foundFlexContainer = true;+ // If we found a supportingText inside a flexContainer,+ // handle this as a flexContainer drop (reordering)+ if (foundSupportingText) {+ const flexContainerPos = dropPos.before(currentDepth);+ const flexContainerResolvedPos =+ view.state.doc.resolve(flexContainerPos);+ cardEmbedInitialData.dropToParent = parentAtDepth;+ cardEmbedInitialData.dropToParentPos =+ flexContainerResolvedPos;+ return handleCardDropToFlexContainer(+ cardEmbedInitialData,+ );+ }+ break;+ }+ currentDepth--;+ }++ // If we're inside supportingText but not in a flexContainer, block the drop+ if (foundSupportingText && !foundFlexContainer) {+ return true;+ }++ // Otherwise, if it's a paragraph not inside supportingText, handle normally+ if (dropToParent.type.name === "paragraph") {+ return handleCardDropOnParagraph(cardEmbedInitialData);+ }}// Check if dropping into document (not into another flexContainer or cardEmbed)@@ -80,8 +143,13 @@ export const HandleEditorDrop = Extension.create({});if (maybePos) {- const { pos } = maybePos;- const node = view.state.doc.nodeAt(pos);+ const { inside } = maybePos;+ const node = view.state.doc.nodeAt(inside);++ view.dom.offsetParent?.classList.add(+ "dragging",+ `dragging-${node?.type.name}`,+ );view.draggingNode = node;return false;diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/HandleEditorDrop/utils.ts b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/HandleEditorDrop/utils.tsindex 7365f3d83db..74a35952577 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/HandleEditorDrop/utils.ts+++ b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/HandleEditorDrop/utils.ts@@ -1,14 +1,17 @@import type { Node, ResolvedPos, Slice } from "@tiptap/pm/model";import type { EditorView } from "@tiptap/pm/view";-// Helper function to extract cardEmbed from resizeNode wrapper-export const extractCardEmbed = (node: Node): Node | null => {- if (node.type.name === "cardEmbed") {+// Helper function to extract cardEmbed or supportingText from resizeNode wrapper+export const extractContainerSingleCardNode = (node: Node): Node | null => {+ if (node.type.name === "cardEmbed" || node.type.name === "supportingText") {return node;}if (node.type.name === "resizeNode" && node.content.childCount === 1) {const child = node.content.child(0);- if (child.type.name === "cardEmbed") {+ if (+ child.type.name === "cardEmbed" ||+ child.type.name === "supportingText"+ ) {return child;}}@@ -18,8 +21,14 @@ export const extractCardEmbed = (node: Node): Node | null => {export const getCardEmbedDropSide = (e: DragEvent): "left" | "right" | null => {const targetCardEmbedDOM =e.target instanceof Element ? e.target.closest(".node-cardEmbed") : null;- if (targetCardEmbedDOM) {- const rect = targetCardEmbedDOM.getBoundingClientRect();+ const targetSupportingTextDOM =+ e.target instanceof Element+ ? e.target.closest(".node-supportingText")+ : null;+ const targetDOM = targetCardEmbedDOM || targetSupportingTextDOM;++ if (targetDOM) {+ const rect = targetDOM.getBoundingClientRect();const xPct = (e.clientX - rect.left) / rect.width;return xPct >= 0.5 ? "right" : "left";@@ -31,13 +40,36 @@ export const getCardEmbedDropSide = (e: DragEvent): "left" | "right" | null => {export const getTargetCardEmbedNode = (e: DragEvent, view: EditorView) => {const targetCardEmbedDOM =e.target instanceof Element ? e.target.closest(".node-cardEmbed") : null;-- if (targetCardEmbedDOM) {- const pos = view.posAtDOM(targetCardEmbedDOM, 0);- const targetCardEmbed = view.state.doc.nodeAt(pos);-- if (targetCardEmbed) {- return extractCardEmbed(targetCardEmbed);+ const targetSupportingTextDOM =+ e.target instanceof Element+ ? e.target.closest(".node-supportingText")+ : null;+ const targetDOM = targetCardEmbedDOM || targetSupportingTextDOM;++ if (targetDOM) {+ const pos = view.posAtDOM(targetDOM, 0);+ const resolvedPos = view.state.doc.resolve(pos);++ // For supportingText, posAtDOM returns a position inside the node (pointing to content)+ // so we need to check the parent. For cardEmbed (atom), it returns the position before the node.+ if (targetSupportingTextDOM) {+ // Check if the parent is supportingText+ if (resolvedPos.parent.type.name === "supportingText") {+ return resolvedPos.parent;+ }+ // Otherwise search up the tree+ for (let d = resolvedPos.depth; d > 0; d--) {+ const node = resolvedPos.node(d);+ if (node.type.name === "supportingText") {+ return node;+ }+ }+ } else if (targetCardEmbedDOM) {+ // For cardEmbed, nodeAt works as expected+ const targetNode = view.state.doc.nodeAt(pos);+ if (targetNode) {+ return extractContainerSingleCardNode(targetNode);+ }}}@@ -45,7 +77,7 @@ export const getTargetCardEmbedNode = (e: DragEvent, view: EditorView) => {};export interface DroppedCardEmbedNodeData {- cardEmbedNode: Node;+ draggedNode: Node;originalPos: number;originalParent: Node;cameFromFlexContainer: boolean;@@ -64,14 +96,14 @@ export const getDroppedCardEmbedNodeData = (slice: Slice,moved: boolean,): DroppedCardEmbedNodeData | undefined => {- // Check if we're moving a cardEmbed node+ // Check if we're moving a cardEmbed or supportingText nodeif (slice.content.childCount === 1) {const droppedNode = slice.content.child(0);- const cardEmbedNode = extractCardEmbed(droppedNode);+ const draggedNode = extractContainerSingleCardNode(droppedNode);- // Dropping a "cardEmbed" node- if (cardEmbedNode && moved) {- const nodeParentResult = findNodeParentAndPos(view, cardEmbedNode);+ // Dropping a "cardEmbed" or "supportingText" node+ if (draggedNode && moved) {+ const nodeParentResult = findNodeParentAndPos(view, draggedNode);if (!nodeParentResult) {return;@@ -84,7 +116,7 @@ export const getDroppedCardEmbedNodeData = (? (originalParent as Node).type.name === "flexContainer": false;- // Find the position where the card was dropped+ // Find the position where the node was droppedconst coords = view.posAtCoords({left: event.clientX,top: event.clientY,@@ -96,7 +128,7 @@ export const getDroppedCardEmbedNodeData = (const dropToParent = dropToParentPos.parent;return {- cardEmbedNode,+ draggedNode,originalPos,originalParent,cameFromFlexContainer,@@ -127,7 +159,10 @@ export const findNodeParentAndPos = (return false;}- if (extractCardEmbed(node) === nodeToFind && node !== nodeToFind) {+ if (+ extractContainerSingleCardNode(node) === nodeToFind &&+ node !== nodeToFind+ ) {parentPos = pos;parent = node;return false;diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/SupportingText/SupportingText.module.css b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/SupportingText/SupportingText.module.cssindex cf7f1cd1e0f..2a72bba5bdc 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/SupportingText/SupportingText.module.css+++ b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/SupportingText/SupportingText.module.css@@ -2,7 +2,6 @@height: 100%;position: relative;border-radius: var(--mantine-radius-md);- overflow: hidden;background-color: var(--mb-color-background-light);border: 1px solid transparent;transition:@@ -43,16 +42,26 @@caret-color: auto;}+/* Prevent dropCursor from displaying while dragging over SupportingText contents */+:global(.dragging) .scrollContainer {+ pointer-events: none;+}+.handle {- cursor: pointer;+ cursor: grab;height: 1rem;position: absolute;top: 0;width: 100%;+ user-select: none; /* Needed to make this handle draggable in FF */&:focus-visible {outline: none !important;}++ &:active {+ cursor: grabbing;+ }}.placeholder {diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/SupportingText/SupportingText.tsx b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/SupportingText/SupportingText.tsxindex 5537eedfedc..59d3b3027f0 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/SupportingText/SupportingText.tsx+++ b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/SupportingText/SupportingText.tsx@@ -26,6 +26,8 @@ import {getCurrentDocument,} from "metabase-enterprise/documents/selectors";import { getListCommentsQuery } from "metabase-enterprise/documents/utils/api";+import { DropZone } from "metabase-enterprise/rich_text_editing/tiptap/extensions/shared/dnd/DropZone";+import { useDndHelpers } from "metabase-enterprise/rich_text_editing/tiptap/extensions/shared/dnd/use-dnd-helpers";import { CommentsButton } from "../../components/CommentsButton";import { cleanupFlexContainerNodes } from "../HandleEditorDrop/utils";@@ -67,7 +69,7 @@ export const SupportingText = Node.create<{return ["div",mergeAttributes(HTMLAttributes, {- "data-type": "supportingText",+ "data-type": this.name,}),0,];@@ -157,11 +159,41 @@ const SupportingTextComponent = ({: "";const dispatch = useDispatch();+ const canWrite = editor.options.editable;++ const { isBeingDragged, dragState, setDragState, handleDragOver, dragElRef } =+ useDndHelpers({ editor, node, getPos });++ // Disallow cut/copy on the drag-handle/comments-button since that'd cut/copy the block itself (cutting/copying supportingText *content* should be allowed though)+ const onCutOrCopy = (e: ClipboardEvent) => {+ if (window.document.activeElement !== editor.view.dom) {+ e.preventDefault();+ }+ };+return (<NodeViewWrapperclassName={cx(S.wrapper, { [S.selected]: selected })}data-testid="document-card-supporting-text"+ onDragOver={handleDragOver}+ onDrop={() => setDragState({ isDraggedOver: false, side: null })}+ onCut={onCutOrCopy}+ onCopy={onCutOrCopy}>+ {canWrite && (+ <>+ <DropZone+ isOver={dragState.isDraggedOver && dragState.side === "left"}+ side="left"+ disabled={isBeingDragged}+ />+ <DropZone+ isOver={dragState.isDraggedOver && dragState.side === "right"}+ side="right"+ disabled={isBeingDragged}+ />+ </>+ )}<div className={S.scrollContainer}>{isNodeEmpty(node) && (<div contentEditable={false} className={S.placeholder}>@@ -170,7 +202,13 @@ const SupportingTextComponent = ({)}<NodeViewContent /></div>- <button++ {/* Would be nice to use a real `button` here, but that prevents ProseMirror plugin dragstart events from firing */}+ <div+ role="button"+ tabIndex={0}+ data-drag-handle+ ref={dragElRef}contentEditable={false}aria-label={t`Supporting text`}className={S.handle}diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/constants.ts b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/constants.tsindex 080b6613e73..b46bd22f2ff 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/constants.ts+++ b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/constants.ts@@ -16,3 +16,5 @@ export const EMBED_SEARCH_MODELS: SuggestionModel[] = ["card", "dataset"];export const LINK_SEARCH_LIMIT = 5;export const USER_SEARCH_LIMIT = LINK_SEARCH_LIMIT;++export const DROP_ZONE_COLOR = "var(--mb-color-brand)";diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/dnd/DropZone.tsx b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/dnd/DropZone.tsxnew file mode 100644index 00000000000..0814ec64c48--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/dnd/DropZone.tsx@@ -0,0 +1,31 @@+import { Box } from "metabase/ui";++import { DROP_ZONE_COLOR } from "../constants";++export interface DropZoneProps {+ isOver: boolean;+ side: "left" | "right";+ disabled?: boolean;+}++export const DropZone = ({ isOver, side, disabled }: DropZoneProps) => {+ if (disabled) {+ return null;+ }++ return (+ <Box+ style={{+ position: "absolute",+ top: 0,+ bottom: 0,+ width: "0.25rem",+ [side]: "-0.625rem",+ borderRadius: "0.125rem",+ backgroundColor: isOver ? DROP_ZONE_COLOR : "transparent",+ zIndex: 10,+ pointerEvents: "all",+ }}+ />+ );+};diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/use-dnd-helpers.ts b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/dnd/use-dnd-helpers.tssimilarity index 75%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/use-dnd-helpers.tsrename to enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/dnd/use-dnd-helpers.tsindex c5441b70961..83558c0379e 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/use-dnd-helpers.ts+++ b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/dnd/use-dnd-helpers.ts@@ -18,7 +18,7 @@ export const useDndHelpers = ({side: "left" | "right" | null;}>({ isDraggedOver: false, side: null });const draggedOverTimeoutRef = useRef<number | undefined>();- const cardEmbedRef = useRef<HTMLDivElement | null>(null);+ const dragElRef = useRef<HTMLDivElement | null>(null);const isMountedRef = useRef(false);const isBeingDragged = editor.view.draggingNode === node;@@ -30,15 +30,29 @@ export const useDndHelpers = ({const draggingNode = editor.view.draggingNode;if (draggingNode &&- draggingNode.type.name === "cardEmbed" &&- cardEmbedRef.current+ (draggingNode.type.name === "cardEmbed" ||+ draggingNode.type.name === "supportingText") &&+ dragElRef.current) {- // Check if this cardEmbed is in a flexContainer that already has 3 childrenconst pos = getPos();if (pos) {const resolvedPos = editor.state.doc.resolve(pos);const { parent } = resolvedPos;+ // For simplicity's sake, don't allow dragging supportingText from one group to another+ if (draggingNode.type.name === "supportingText") {+ if (+ parent.type.name === "flexContainer" ||+ parent.type.name === "resizeNode"+ ) {+ if (!parent.content.content.includes(draggingNode)) {+ setDragState({ isDraggedOver: false, side: null });+ return;+ }+ }+ }++ // Check if this cardEmbed is in a flexContainer that already has 3 childrenif (parent.type.name === "flexContainer" &&parent.content.childCount >= 3@@ -59,7 +73,7 @@ export const useDndHelpers = ({}}- const rect = cardEmbedRef.current?.getBoundingClientRect();+ const rect = dragElRef.current?.getBoundingClientRect();const relativeX = e.clientX - rect.left;const nodeWidth = rect.width;@@ -98,6 +112,6 @@ export const useDndHelpers = ({dragState,setDragState,handleDragOver,- cardEmbedRef,+ dragElRef,};};