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

return invokation of command #4882

Merged
merged 1 commit into from
Apr 6, 2024

Conversation

hontas
Copy link
Contributor

@hontas hontas commented Feb 13, 2024

Please describe your changes

Return the invocation of command in order to get access to the return value in rendering component.

This allows one to act on it when for example doing an async action before updating the editor, like getting a suggestion from ChatGPT or fetching a response from an api to be inserted.

How did you accomplish your changes

return the invocation of command

How have you tested your changes

In my own SlashMenu extension based on https://tiptap.dev/docs/editor/experiments/commands where I wanted to render a spinner if the item command function returned a promise.

How can we verify your changes

Return something from the items command function and check the value in the rendering component

// suggestion.js
return [
  {
    title: 'H1',
    command: ({ editor, range }) => {
      return new Promise((resolve) => {
        setTimeout(() => {
          editor
            .chain()
            .focus()
            .deleteRange(range)
            .setNode('heading', { level: 1 })
            .run()
          resolve()
        }, 1000)
      })
    },
  }
]


// CommandsList.vue
if (item) {
  console.log(this.command(item))
}

Remarks

I didn't update the types of supported return value from the commands function, happy to get input on how to do that for increased type safety for supported return values

Checklist

  • The changes are not breaking the editor
  • Added tests where possible
  • Followed the guidelines
  • Fixed linting issues

Related issues

Copy link

netlify bot commented Feb 13, 2024

Deploy Preview for tiptap-embed ready!

Name Link
🔨 Latest commit 58be8ce
🔍 Latest deploy log https://app.netlify.com/sites/tiptap-embed/deploys/65e581d596140000082a667f
😎 Deploy Preview https://deploy-preview-4882--tiptap-embed.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@hontas hontas force-pushed the suggestion-return-command branch from ab8dcb0 to 58be8ce Compare March 4, 2024 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants