diff --git a/packages/editor/src/core/extensions/custom-image/components/image-block.tsx b/packages/editor/src/core/extensions/custom-image/components/image-block.tsx index 89ace94a57f..f6843210a83 100644 --- a/packages/editor/src/core/extensions/custom-image/components/image-block.tsx +++ b/packages/editor/src/core/extensions/custom-image/components/image-block.tsx @@ -145,7 +145,7 @@ export const CustomImageBlock: React.FC = (props) => { src={src} width={size.width} height={size.height} - className={cn("block rounded-md", { + className={cn("image-component block rounded-md", { hidden: isShimmerVisible, "read-only-image": !editor.isEditable, })} diff --git a/packages/editor/src/core/extensions/side-menu.tsx b/packages/editor/src/core/extensions/side-menu.tsx index 038d679b185..616e315e206 100644 --- a/packages/editor/src/core/extensions/side-menu.tsx +++ b/packages/editor/src/core/extensions/side-menu.tsx @@ -78,10 +78,11 @@ const SideMenu = (options: SideMenuPluginProps) => { hideSideMenu(); view?.dom.parentElement?.appendChild(editorSideMenu); // side menu elements' initialization - if (handlesConfig.ai) { + if (handlesConfig.ai && !editorSideMenu.querySelector("#ai-handle")) { aiHandleView(view, editorSideMenu); } - if (handlesConfig.dragDrop) { + + if (handlesConfig.dragDrop && !editorSideMenu.querySelector("#drag-handle")) { dragHandleView(view, editorSideMenu); } @@ -113,6 +114,10 @@ const SideMenu = (options: SideMenuPluginProps) => { rect.top += (lineHeight - 20) / 2; rect.top += paddingTop; + if (handlesConfig.ai) { + rect.left -= 20; + } + if (node.parentElement?.parentElement?.matches("td") || node.parentElement?.parentElement?.matches("th")) { if (node.matches("ul:not([data-type=taskList]) li, ol li")) { rect.left -= 5; diff --git a/packages/editor/src/core/plugins/ai-handle.ts b/packages/editor/src/core/plugins/ai-handle.ts index 8af93ed1dd1..5f87df3ffed 100644 --- a/packages/editor/src/core/plugins/ai-handle.ts +++ b/packages/editor/src/core/plugins/ai-handle.ts @@ -2,45 +2,12 @@ import { NodeSelection } from "@tiptap/pm/state"; import { EditorView } from "@tiptap/pm/view"; // extensions import { SideMenuHandleOptions, SideMenuPluginProps } from "@/extensions"; +// plugins +import { nodeDOMAtCoords } from "@/plugins/drag-handle"; const sparklesIcon = ''; -const nodeDOMAtCoords = (coords: { x: number; y: number }) => { - const elements = document.elementsFromPoint(coords.x, coords.y); - const generalSelectors = [ - "li", - "p:not(:first-child)", - ".code-block", - "blockquote", - "img", - "h1, h2, h3, h4, h5, h6", - "[data-type=horizontalRule]", - ".table-wrapper", - ".issue-embed", - ].join(", "); - - for (const elem of elements) { - if (elem.matches("p:first-child") && elem.parentElement?.matches(".ProseMirror")) { - return elem; - } - - // if the element is a

tag that is the first child of a td or th - if ( - (elem.matches("td > p:first-child") || elem.matches("th > p:first-child")) && - elem?.textContent?.trim() !== "" - ) { - return elem; // Return only if p tag is not empty in td or th - } - - // apply general selector - if (elem.matches(generalSelectors)) { - return elem; - } - } - return null; -}; - const nodePosAtDOM = (node: Element, view: EditorView, options: SideMenuPluginProps) => { const boundingRect = node.getBoundingClientRect(); diff --git a/packages/editor/src/core/plugins/drag-handle.ts b/packages/editor/src/core/plugins/drag-handle.ts index d260b284968..ba390180bbe 100644 --- a/packages/editor/src/core/plugins/drag-handle.ts +++ b/packages/editor/src/core/plugins/drag-handle.ts @@ -37,39 +37,19 @@ export const nodeDOMAtCoords = (coords: { x: number; y: number }) => { "p:not(:first-child)", ".code-block", "blockquote", - "img", "h1, h2, h3, h4, h5, h6", "[data-type=horizontalRule]", ".table-wrapper", ".issue-embed", + ".image-component", ".image-upload-component", ].join(", "); - const hasNestedImg = (el: Element): boolean => { - if (el.tagName.toLowerCase() === "img") return true; - // @ts-expect-error todo - for (const child of el.children) { - if (hasNestedImg(child)) return true; - } - return false; - }; - for (const elem of elements) { - const elemHasNestedImg = hasNestedImg(elem); if (elem.matches("p:first-child") && elem.parentElement?.matches(".ProseMirror")) { return elem; } - // if the element is a

tag and has a nested img i.e. the new image - // component - if (elem.matches("p") && elemHasNestedImg) { - return null; - } - - if (elem.matches("div") && elemHasNestedImg) { - return elem; - } - // if the element is a

tag that is the first child of a td or th if ( (elem.matches("td > p:first-child") || elem.matches("th > p:first-child")) && diff --git a/packages/editor/src/styles/drag-drop.css b/packages/editor/src/styles/drag-drop.css index 96b40d450b8..7db6ed87554 100644 --- a/packages/editor/src/styles/drag-drop.css +++ b/packages/editor/src/styles/drag-drop.css @@ -5,7 +5,6 @@ align-items: center; opacity: 1; transition: opacity 0.2s ease 0.2s; - transform: translateX(-50%); &.side-menu-hidden { opacity: 0;