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

Need more explanation regarding custom plugin #10

Closed
neelay92 opened this issue Mar 18, 2020 · 6 comments
Closed

Need more explanation regarding custom plugin #10

neelay92 opened this issue Mar 18, 2020 · 6 comments

Comments

@neelay92
Copy link

How do I create custom extension, say for Heading?
In the doc it is mentioned to extend the Base Class, but what if I want to add a custom class to it?
Is it similar to tiptap, wherein the we need to define it in the schema/doc?

Also can you explain what menuBtnView (editorContext) {} expects and needs to return.

Thanks.
Great work on the plugin!

@Leecason
Copy link
Owner

Leecason commented Mar 19, 2020

I created this simple demo for you. you can check it

Create The Custom Bold Menu Button

In your custom extension class, add a menuBtnView function to return a object (in there i called Vue Component Spec) that contains three attribute:

{
  component:  // your vue component
  componentProps: {
    // props will pass to your vue component
  },
  componentEvents: {
    // handle events that your component emit
  },
}

menuBtnView function has just one param editorContext, its properties are same as https://github.com/scrumpy/tiptap#editormenubar, i just plus the tiptap editor instance to it.

Also you can overwrite such as schema, plugins and commands in your custom extension class like in tiptap. create-custom-extensions

If you want to render multiple buttons in one extension, just like you say the Heading extension.

your can return a Vue Component Spec array in the menuBtnView:

class Bold extends OriginalBold {
  menuBtnView () {
    return [
       {
          component: componentH1,
       },
       {
          component: componentH2,
       }
      ...
    ];
  }
}

i will make the docs more detailed.

I'm glad to reply if you have any other questions.

thanks for supporting this project.

@Leecason
Copy link
Owner

Do you still have any questions?

@neelay92
Copy link
Author

Hey
Thanks for the reply. I managed to get it working by your help.

@shadrachtuck
Copy link

@Leecason Trying to render multiple buttons in the extension as per your last example works for rendering buttons but the logic within component events is not firing. Perhaps I have the syntax incorrect??

export default class Bold extends OriginalBold {
  // here you can extend the extension like tiptap, such as schema, plugins ...
  menuBtnView({ isActive, word, code }) {
    
    return [
        {
          component: RhymeButton,
        },
        {
          component: ThesaurusButton,
        },
        {
          component: DictionaryButton
        },
      {
      componentProps: {
        isActive: isActive.bold(),
        word: String,
        code: String
      },
      props: ["code"],
      componentEvents: {
        click: () => {
          let word = this.word;
          word = (document.all)
          ? document.selection.createRange().text.toString()
          : document.getSelection().toString().trim().toLowerCase();
          // document.getElementById('hidden').value = word;
          // document.onmouseup = getSelectionText;
          // if (!document.all) document.captureEvents(Event.MOUSEUP);
          this.word = word;
          store.commit("addWord", this.word)
        },
      },
    }
    
    ];

  }

}

@Leecason
Copy link
Owner

@shadrachtuck
Each component object contains its props and events

menuBtnView (editorContext) {
  return [
    {
      component: compA,
      componentProps: compAprops,
      componentEvents: compAevents, 
    },
    {
      component: compB,
      componentProps: compBprops,
      componentEvents: compBevents,
    },
    ...
  ],
}

@shadrachtuck
Copy link

@Leecason oh of course! brilliant, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants