Skip to content
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

[PRO]: Drag Handle vue #5896

Closed
1 task done
SunHengX opened this issue Nov 30, 2024 · 10 comments
Closed
1 task done

[PRO]: Drag Handle vue #5896

SunHengX opened this issue Nov 30, 2024 · 10 comments
Labels
Category: Pro The issue or pull request is related to the pro packages of Tiptap. Type: Bug The issue or pullrequest is related to a bug

Comments

@SunHengX
Copy link

Affected Packages

extension-drag-handle-vue-3

Version(s)

2.16.3

Description of the Bug

I copied the examples from the official website of tiptap and then ran them locally, but they didn't work properly. I'm currently using Vue 3. Could any expert please help me solve this problem?
image

Browser Used

Chrome

Code Example (Preferred)

No response

Expected Behavior

An error will occur when I use ` I hope it can be solved.

Additional Context (Optional)

image

Dependency Updates

  • Yes, I've updated all my dependencies.
@SunHengX SunHengX added Category: Pro The issue or pull request is related to the pro packages of Tiptap. Type: Bug The issue or pullrequest is related to a bug labels Nov 30, 2024
@nperez0111
Copy link
Contributor

More information on your integration would be needed to help you with this

@SunHengX
Copy link
Author

SunHengX commented Dec 5, 2024

需要更多有关您的集成的信息来帮助您实现这一点
I am using the official Tiptap demo from the Tiptap website.
image
image

@KevinvOosterhout
Copy link

KevinvOosterhout commented Dec 5, 2024

I'm experiencing the same with a Nuxt project. I've tried it with pure Vue too. See repo for reproduction: https://github.com/KevinvOosterhout/tiptap-draghandle-vue-bug

The copy of the demo is in src/views/HomeView.vue

@KevinvOosterhout
Copy link

Screenshot 2024-12-05 at 9 10 26 PM

@SunHengX
Copy link
Author

SunHengX commented Dec 6, 2024

@nperez0111 Please help us resolve this issue, experts.

@nperez0111
Copy link
Contributor

I don't have the time to look into this, but here is what the source is doing, perhaps you can figure it out yourselves from there:

import { Editor } from '@tiptap/vue-3'
import {
  DragHandlePlugin,
  dragHandlePluginDefaultKey,
  DragHandlePluginProps,
} from '@tiptap-pro/extension-drag-handle'
import {
  defineComponent, h, onBeforeUnmount, onMounted, PropType, ref,
} from 'vue'

type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;

export type DragHandleProps = Omit<Optional<DragHandlePluginProps, 'pluginKey'>, 'element'> & {
  class?: string;
  onNodeChange?: (data: { node: Node | null; editor: Editor; pos: number }) => void;
};

export const DragHandle = defineComponent({
  name: 'DragHandleVue',

  props: {
    pluginKey: {
      type: [String, Object] as PropType<DragHandleProps['pluginKey']>,
      default: dragHandlePluginDefaultKey,
    },

    editor: {
      type: Object as PropType<DragHandleProps['editor']>,
      required: true,
    },

    tippyOptions: {
      type: Object as PropType<DragHandleProps['tippyOptions']>,
      default: () => ({}),
    },

    onNodeChange: {
      type: Function as PropType<DragHandleProps['onNodeChange']>,
      default: null,
    },

    class: {
      type: String as PropType<DragHandleProps['class']>,
      default: 'drag-handle',
    },
  },

  setup(props, { slots }) {
    const root = ref<HTMLElement | null>(null)

    onMounted(() => {
      const {
        editor, pluginKey, onNodeChange, tippyOptions,
      } = props

      editor.registerPlugin(
        DragHandlePlugin({
          editor,
          element: root.value as HTMLElement,
          pluginKey,
          tippyOptions,
          onNodeChange,
        }),
      )
    })

    onBeforeUnmount(() => {
      const { pluginKey, editor } = props

      editor.unregisterPlugin(pluginKey as string)
    })

    return () => h('div', { ref: root, class: props.class }, slots.default?.())
  },
})

@KevinvOosterhout
Copy link

For some strange reason i've got it to function when using the pasted code above inside of a component with just a script tag around it, and changing the import to import { DragHandle } from '~/components/DragHandle.vue' .

@nperez0111
Copy link
Contributor

Perhaps it was built incorrectly? This project does have both vue 2 & vue 3 maybe it chose the wrong one?

@nperez0111
Copy link
Contributor

I'm releasing a new version, it looks like it was being bundled with the entire vue package because I did not declare it as a peer dep. Try this version: 2.16.5-beta.0

@KevinvOosterhout
Copy link

I've just tested the beta and it works like a charm. Thanks for the quick response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Pro The issue or pull request is related to the pro packages of Tiptap. Type: Bug The issue or pullrequest is related to a bug
Projects
None yet
Development

No branches or pull requests

3 participants