Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

UXW-2449 fix pasting mixed content containing cardEmbed (#66733)

Denis Berezinf601dea72d38
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.tsx
index 85f07f9ba37..6fbad7981c0 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
@@ -423,6 +423,9 @@ export const CardEmbedComponent = memo(
className={cx(styles.embedWrapper, CS.root, {
[CS.open]: isOpen || isHovered,
})}
+ data-type="cardEmbed"
+ data-id={id}
+ data-testid="document-card-embed"
style={{ position: "relative" }}
>
<Box
@@ -456,6 +459,8 @@ export const CardEmbedComponent = memo(
className={cx(styles.embedWrapper, CS.root, {
[CS.open]: isOpen || isHovered,
})}
+ data-type="cardEmbed"
+ data-id={id}
data-testid="document-card-embed"
style={{ position: "relative" }}
>
@@ -485,6 +490,8 @@ export const CardEmbedComponent = memo(
className={cx(styles.embedWrapper, CS.root, {
[CS.open]: isOpen || isHovered,
})}
+ data-type="cardEmbed"
+ data-id={id}
data-testid="document-card-embed"
data-drag-handle
onDragOver={handleDragOver}
diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/FlexContainer/FlexContainer.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/FlexContainer/FlexContainer.tsx
index 302435d74c7..3a2bbe1b296 100644
--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/FlexContainer/FlexContainer.tsx
+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/FlexContainer/FlexContainer.tsx
@@ -25,7 +25,7 @@ export const FlexContainer: Node<{
}> = Node.create({
name: "flexContainer",
group: "block",
- content: "(supportingText | cardEmbed){1,3}", // Contains 1-3 CardEmbed or SupportingText nodes only
+ content: "(supportingText|cardEmbed){1,3}", // Contains 1-3 CardEmbed or SupportingText nodes only
defining: true,
draggable: false,
selectable: false,
diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/HandleEditorDrop/HandleEditorDrop.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/HandleEditorDrop/HandleEditorDrop.tsx
index 1dc771f5001..1ce7d3666f8 100644
--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/HandleEditorDrop/HandleEditorDrop.tsx
+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/HandleEditorDrop/HandleEditorDrop.tsx
@@ -196,14 +196,6 @@ export const HandleEditorDrop = Extension.create({
}
const { state } = view;
- const resolvedPos = state.doc.resolve(state.selection.from);
- const isTopLevelParagraph =
- resolvedPos.parent.type.name === "paragraph" &&
- resolvedPos.depth === 1;
-
- if (!isTopLevelParagraph) {
- return slice;
- }
const transformedContent = slice.content.content.map((node) => {
return state.schema.nodes.resizeNode.create({}, [node]);
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.ts
index 74a84d0acb0..1997c5ed390 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
@@ -92,6 +92,24 @@ export const PlainLink = Link.extend({
};
},
+ parseHTML() {
+ return [
+ {
+ tag: "a[href]:not([data-type='smart-link'])",
+ getAttrs: (element) => {
+ if (typeof element === "string") {
+ return false;
+ }
+ // Don't parse smart-link elements as plain links
+ if (element.getAttribute("data-type") === "smart-link") {
+ return false;
+ }
+ return null;
+ },
+ },
+ ];
+ },
+
addInputRules() {
return [
linkInputRule({
diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/ResizeNode/ResizeNode.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/ResizeNode/ResizeNode.tsx
index 6fce97bf908..8632bb35573 100644
--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/ResizeNode/ResizeNode.tsx
+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/ResizeNode/ResizeNode.tsx
@@ -22,7 +22,7 @@ export const ResizeNode: Node<{
}> = Node.create({
name: "resizeNode",
group: "block",
- content: "(flexContainer | cardEmbed)",
+ content: "(flexContainer|cardEmbed)",
draggable: false,
selectable: false,
disableDropCursor: true,
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.tsx
index 8346f6bc95f..2599c45bb4a 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
@@ -175,7 +175,17 @@ export const SmartLink = Node.create<{
},
href: {
default: "/",
- parseHTML: (element) => element.getAttribute("data-href"),
+ parseHTML: (element) => {
+ const href = element.getAttribute("href");
+ const siteUrl = element.getAttribute("data-site-url");
+
+ // Remove siteUrl prefix if present to store relative path
+ if (href && siteUrl && href.startsWith(siteUrl)) {
+ return href.substring(siteUrl.length);
+ }
+
+ return href || element.getAttribute("data-href") || "/";
+ },
},
};
},
@@ -187,7 +197,23 @@ export const SmartLink = Node.create<{
parseHTML() {
return [
{
- tag: 'span[data-type="smart-link"]',
+ tag: 'a[data-type="smart-link"]',
+ priority: 100, // Higher priority than default to override Link mark
+ getAttrs: (element) => {
+ if (typeof element === "string") {
+ return false;
+ }
+
+ const entityId = element.getAttribute("data-entity-id");
+ const model = element.getAttribute("data-model");
+
+ // Only parse as smartLink if it has the required attributes
+ if (!entityId || !model) {
+ return false;
+ }
+
+ return null; // Return null to let the attribute parsers handle extraction
+ },
},
];
},
@@ -434,7 +460,7 @@ export const SmartLinkComponent = memo(
const showLoading = isLoading && !entity;
if (showLoading) {
return (
- <NodeViewWrapper as="span">
+ <NodeViewWrapper as="span" data-type="smart-link">
<span className={styles.smartLink}>
<span className={styles.smartLinkInner}>
<Icon name="hourglass" className={styles.icon} />
@@ -447,7 +473,7 @@ export const SmartLinkComponent = memo(
if (error || !entity) {
return (
- <NodeViewWrapper as="span">
+ <NodeViewWrapper as="span" data-type="smart-link">
<span className={styles.smartLink}>
<span className={styles.smartLinkInner}>
{isObject(error) && error.status === 403 ? (
@@ -469,7 +495,7 @@ export const SmartLinkComponent = memo(
if (model === "user" && isMentionableUser(entity)) {
return (
- <NodeViewWrapper as="span">
+ <NodeViewWrapper as="span" data-type="smart-link">
<span className={styles.userMention}>@{entity.common_name}</span>
</NodeViewWrapper>
);
@@ -489,7 +515,7 @@ export const SmartLinkComponent = memo(
);
return (
- <NodeViewWrapper as="span">
+ <NodeViewWrapper as="span" data-type="smart-link">
<a
href={entityUrl || "#"}
target="_blank"
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.tsx
index 4ead0db96eb..24273dd88d4 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
@@ -35,10 +35,12 @@ import { createIdAttribute, createProseMirrorPlugin } from "../NodeIds";
import S from "./SupportingText.module.css";
+const SUPPORTING_TEXT_NODE_NAME = "supportingText";
+
export const SupportingText = Node.create<{
HTMLAttributes: Record<string, any>;
}>({
- name: "supportingText",
+ name: SUPPORTING_TEXT_NODE_NAME,
group: "block",
content: "(paragraph|heading|bulletList|orderedList|blockquote|codeBlock)+",
draggable: true,
@@ -60,7 +62,7 @@ export const SupportingText = Node.create<{
parseHTML() {
return [
{
- tag: 'div[data-type="supportingText"]',
+ tag: `div[data-type="${SUPPORTING_TEXT_NODE_NAME}"]`,
},
];
},
@@ -69,7 +71,7 @@ export const SupportingText = Node.create<{
return [
"div",
mergeAttributes(HTMLAttributes, {
- "data-type": this.name,
+ "data-type": SUPPORTING_TEXT_NODE_NAME,
}),
0,
];
@@ -175,6 +177,7 @@ const SupportingTextComponent = ({
<NodeViewWrapper
className={cx(S.wrapper, { [S.selected]: selected })}
data-testid="document-card-supporting-text"
+ data-type={SUPPORTING_TEXT_NODE_NAME}
onDragOver={handleDragOver}
onDrop={() => setDragState({ isDraggedOver: false, side: null })}
onCut={onCutOrCopy}
diff --git a/src/metabase/server/middleware/security.clj b/src/metabase/server/middleware/security.clj
index d2e54fba7db..984baf7500d 100644
--- a/src/metabase/server/middleware/security.clj
+++ b/src/metabase/server/middleware/security.clj
@@ -160,6 +160,7 @@
(when config/is-dev?
"http://localhost:9630")
"https://accounts.google.com"]
+ :style-src-attr ["'self'"]
:frame-src (parse-allowed-iframe-hosts (server.settings/allowed-iframe-hosts))
:font-src ["*"]
:img-src ["*"
diff --git a/yarn.lock b/yarn.lock
index 3baf96a234b..0c8189d21be 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -17894,9 +17894,9 @@ prosemirror-menu@^1.2.4:
prosemirror-state "^1.0.0"
prosemirror-model@^1.0.0, prosemirror-model@^1.20.0, prosemirror-model@^1.21.0, prosemirror-model@^1.24.1, prosemirror-model@^1.25.0:
- version "1.25.2"
- resolved "https://registry.yarnpkg.com/prosemirror-model/-/prosemirror-model-1.25.2.tgz#39ca862f76f354237efb94441dbc9f79e81cb247"
- integrity sha512-BVypCAJ4SL6jOiTsDffP3Wp6wD69lRhI4zg/iT8JXjp3ccZFiq5WyguxvMKmdKFC3prhaig7wSr8dneDToHE1Q==
+ version "1.25.4"
+ resolved "https://registry.yarnpkg.com/prosemirror-model/-/prosemirror-model-1.25.4.tgz#8ebfbe29ecbee9e5e2e4048c4fe8e363fcd56e7c"
+ integrity sha512-PIM7E43PBxKce8OQeezAs9j4TP+5yDpZVbuurd1h5phUxEKIu+G2a+EUZzIC5nS1mJktDJWzbqS23n1tsAf5QA==
dependencies:
orderedmap "^2.0.0"