Skip to content

Adding to custom nodes #16

Open
Open
@yuvalkarmi

Description

@yuvalkarmi

Hey @amirhhashemi thanks so much for making this.

For some reason, this isn't working on my custom components. For instance, I have this Alert node:

import { mergeAttributes, Node } from '@tiptap/core';
import { ReactNodeViewRenderer } from '@tiptap/react';

import AlertComponent from './AlertComponent';

const AlertNode = Node.create({
  name: 'alert',

  group: 'block',

  content: 'inline*',

  atom: false,

  draggable: true,

  selectable: true,

  addAttributes() {
    return {
      type: {
        default: 'info',
      },
    }
  },
  addKeyboardShortcuts() {
    return {}
  },


  parseHTML() {
    return [
      {
        tag: 'alert',
      },
    ]
  },

  renderHTML({ HTMLAttributes }) {
    return [
      'alert',
      mergeAttributes(HTMLAttributes),
      0 // This 0 is a placeholder for the node's content
    ];
  },

  addCommands() {
    return {};
  },

  addNodeView() {
    return ReactNodeViewRenderer(AlertComponent)
  },
})

export default AlertNode;

My actual alert component uses <NodeViewContent /> for the rendering.

I also made sure to include alert it when initializing the plugin:

TextDirection.configure({
    types: ["heading", "paragraph", "alert"],
  }),

Despite this, the text direction does not apply. I'm sure I'm missing something in the implementation.

Could you please shed a bit of light on how to implement the plugin in custom components?

Thanks!
Yuval

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions