-
Notifications
You must be signed in to change notification settings - Fork 1k
feat(EditorDragHandle): pass tiptap props, custom middleware, fix onNodeChange emit #5960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v4
Are you sure you want to change the base?
Conversation
β¦d 'nestedOptions', omit the same from button props
π WalkthroughWalkthroughThe pull request modifies the EditorDragHandle component to emit a new Estimated code review effortπ― 3 (Moderate) | β±οΈ ~20 minutes π₯ Pre-merge checks | β 3β Passed checks (3 passed)
βοΈ Tip: You can configure your own custom pre-merge checks in the settings. β¨ Finishing touchesπ§ͺ Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
commit: |
|
@benjamincanac - noticed a few bugs/things that didn't quite align with documentation. Here's a small concise PR for the fixes:
π first contribution, long time user of nuxt ui β€οΈ - custom middleware seemed simple enough, and opens doors for flexibility. If its not robust enough, I can revert it. |
benjamincanac
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When building the Editor I did try to store the current node and send it inside the nodeChange even like you did but for a reason I never understood this breaks the drag handle completely, I even tried to pass it inside default slot props but didn't work either. My guess is the node.toJSON() object is just too big.
You can try in the playground and see it no longer displays when hovering elements.
|
For performance impact - it does look optimized under the hood - only called when actually changing - not retriggering on mouse movement. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
π€ Fix all issues with AI agents
In `@src/runtime/components/EditorDragHandle.vue`:
- Around line 42-44: The emit was renamed from nodeChange to nodeChanged,
breaking consumers who used `@node-change`; update the API docs and changelog to
document this breaking change and provide a migration note (replace `@node-change`
with `@node-changed`), and ensure the type/interface EditorDragHandleEmits and any
usages of nodeChange in EditorDragHandle.vue and elsewhere are updated to
nodeChanged so templates and listeners reflect the new event name.
| export interface EditorDragHandleEmits { | ||
| nodeChange: [{ node: JSONContent, pos: number }] | ||
| nodeChanged: [{ node: JSONContent, pos: number }] | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Breaking change: emit renamed from nodeChange to nodeChanged.
This rename changes the event from @node-change to @node-changed in Vue templates. While this aligns with Vue's naming convention for past-tense events (indicating something has happened), it's a breaking change for existing consumers.
Ensure the changelog documents this breaking change for users migrating from the previous API.
π€ Prompt for AI Agents
In `@src/runtime/components/EditorDragHandle.vue` around lines 42 - 44, The emit
was renamed from nodeChange to nodeChanged, breaking consumers who used
`@node-change`; update the API docs and changelog to document this breaking change
and provide a migration note (replace `@node-change` with `@node-changed`), and
ensure the type/interface EditorDragHandleEmits and any usages of nodeChange in
EditorDragHandle.vue and elsewhere are updated to nodeChanged so templates and
listeners reflect the new event name.
|
@solidprinciples We can't introduce a breaking change like this unfortunately, what are you trying to solve here? The |
|
Looking to be able to track currently selected node by the handle upon hover. |
|
What about adding a new diff --git a/src/runtime/components/EditorDragHandle.vue b/src/runtime/components/EditorDragHandle.vue
index 2c1824881..862cc47b9 100644
--- a/src/runtime/components/EditorDragHandle.vue
+++ b/src/runtime/components/EditorDragHandle.vue
@@ -40,6 +40,10 @@ export interface EditorDragHandleSlots {
export interface EditorDragHandleEmits {
nodeChange: [{ node: JSONContent, pos: number }]
+ /**
+ * Emitted when the hovered node changes.
+ */
+ hover: [{ node: JSONContent, pos: number }]
}
</script>
@@ -114,6 +118,13 @@ const currentNodePos = ref<number | null>()
function onNodeChange({ pos }: { pos: number }) {
currentNodePos.value = pos
+
+ if (!props.editor || pos < 0) return
+
+ const node = props.editor.state.doc.nodeAt(pos)
+ if (node) {
+ emit('hover', { node: node.toJSON(), pos })
+ }
}
function onClick() { |
|
@benjamincanac - reverted earlier changes around |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and canβt be posted inline due to platform limitations.
β οΈ Outside diff range comments (1)
src/runtime/components/EditorDragHandle.vue (1)
154-164: Default handle no longer triggersonClick.After removing the root
@click, the fallback<UButton>isnβt wired toonClick, sonodeChangewill never fire for the default slot. Please bind the handler in the fallback content to avoid a regression.π οΈ Suggested fix
<UButton v-bind="{ ...buttonProps, icon: props.icon || appConfig.ui.icons.drag, ...$attrs }" data-slot="handle" :class="ui.handle({ class: [props.ui?.handle, props.class] })" :ui="transformUI(ui, props.ui)" + `@click`="onClick" />
|
@benjamincanac hmm. same issue - I've at least diagnosed it down to this:
Haven't seen anything on tiptap's repo :( |
|
@benjamincanac - https://github.com/solidprinciples/tiptap-draghandle-state-update-bug/tree/bug/drag-handle Tiptap bug - same thing happens in their extension demo. Investigating to see feasibility of fixing upstream. |
|
@benjamincanac fixed in tip-tap - small one-liner in ueberdosis/tiptap#7472 π - seems like the DragHandle is re-rendering and re-applying visibility: hidden in these cases. |



β Type of change
π Description
While working with the editor, I noticed that nested drag handle options are documented but werenβt being explicitly passed through. This PR updates the implementation to correctly pick up the nested drag handle options exposed by TipTapβs DragHandleProps type.
It also includes a small nit fix to omit the same keys from the button props, since they arenβt used there.
This change fixes and enables nested drag handles.
I ran into this while trying to get nesting working locally and realized it was a straightforward fix worth contributing.
π Checklist