From 9c08da8fad85e8c1d6345c3b896ec756d6453269 Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Mon, 28 Jul 2025 23:23:25 -0600 Subject: [PATCH] fix a few more node --- .../components/ui/report/EditorContainer.tsx | 2 +- .../ui/report/elements/BlockDraggable.tsx | 83 ++++++++++++++++--- .../ui/report/elements/CalloutNode.tsx | 4 +- .../ui/report/elements/CodeBlockNode.tsx | 4 +- 4 files changed, 75 insertions(+), 18 deletions(-) diff --git a/apps/web/src/components/ui/report/EditorContainer.tsx b/apps/web/src/components/ui/report/EditorContainer.tsx index 0908b887e..193de6eff 100644 --- a/apps/web/src/components/ui/report/EditorContainer.tsx +++ b/apps/web/src/components/ui/report/EditorContainer.tsx @@ -16,7 +16,7 @@ const editorContainerVariants = cva('relative cursor-text h-full p-4', { comment: 'bg-background/50' }, readonly: { - true: 'cursor-not-allowed' + true: 'cursor-text' } }, defaultVariants: { diff --git a/apps/web/src/components/ui/report/elements/BlockDraggable.tsx b/apps/web/src/components/ui/report/elements/BlockDraggable.tsx index cd709773a..fac16c895 100644 --- a/apps/web/src/components/ui/report/elements/BlockDraggable.tsx +++ b/apps/web/src/components/ui/report/elements/BlockDraggable.tsx @@ -4,8 +4,8 @@ import * as React from 'react'; import { DndPlugin, useDraggable, useDropLine } from '@platejs/dnd'; import { BlockSelectionPlugin } from '@platejs/selection/react'; -import { GripDotsVertical } from '@/components/ui/icons'; -import { getPluginByType, isType, KEYS, type TElement } from 'platejs'; +import { GripDotsVertical, Plus } from '@/components/ui/icons'; +import { getPluginByType, isType, KEYS, type SlateRenderNodeProps, type TElement } from 'platejs'; import { type PlateEditor, type PlateElementProps, @@ -109,23 +109,27 @@ function Draggable(props: PlateElementProps) {
+ + data-plate-prevent-deselect + prefix={ + + }>
@@ -148,6 +152,59 @@ function Draggable(props: PlateElementProps) { ); } + +function AddNewBlockButton({ + style, + className +}: { + style: React.CSSProperties; + className: string; +}) { + const editor = useEditorRef(); + const path = usePath(); + + const handleClick = (event: React.MouseEvent) => { + // build the insertion point based on modifier key + const parentPath = path.slice(0, -1); + const currentIndex = path[path.length - 1]; + + // Option/Alt key adds before, regular click adds after + const insertIndex = event.altKey ? currentIndex : currentIndex + 1; + + editor.tf.insertNodes( + { type: 'p', children: [{ text: '' }] }, + { at: [...parentPath, insertIndex] } + ); + + setTimeout(() => { + // Calculate the path to the start of the new paragraph's text + const newNodePath = [...parentPath, insertIndex]; + const textPath = [...newNodePath, 0]; // Path to the first text node + + // Set the selection to the start of the new paragraph + editor.tf.select({ + anchor: { path: textPath, offset: 0 }, + focus: { path: textPath, offset: 0 } + }); + + // Ensure the editor is focused + editor.tf.focus(); + }, 25); + }; + + return ( + +