Skip to content

Multiple triggers on mention component #6300

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

Merged
merged 9 commits into from
Apr 29, 2025

Conversation

arnaugomez
Copy link
Contributor

Changes Overview

Support multiple triggers in mention component.

Example: @ is used to mention people and # is used to mention a place.

Implementation Approach

  • Expose a new "suggestions" option where multiple suggestion triggers can be attached to the Mention extension.

Testing Done

Manually, with the demos. No automated tests. Let me know if you need automated tests.

Verification Steps

  1. Open the Mention demo.
  2. Verify the behaviour of the Mention extension is the same as before. Try creating and deleting a mention.
  3. Open the MultiMention demo.
  4. Verify you can use both @ and # to trigger the mention extension. Verify that the list of options is different depending on the trigger character.

Additional Notes

The motivation of this PR is to enable a common workflow of AI assistant applications, where different resources (files, urls, users) are mentioned in the same prompt. It is also a requested feature in discussion #1768.

Checklist

  • I have created a changeset for this PR if necessary.
  • My changes do not break the library.
  • I have added tests where applicable.
  • I have followed the project guidelines.
  • I have fixed any lint issues.

Related Issues

#1768

@arnaugomez arnaugomez self-assigned this Apr 25, 2025
Copy link

changeset-bot bot commented Apr 25, 2025

🦋 Changeset detected

Latest commit: 40d2f3b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 57 packages
Name Type
@tiptap/extension-mention Major
@tiptap/core Major
@tiptap/extension-blockquote Major
@tiptap/extension-bold Major
@tiptap/extension-bubble-menu Major
@tiptap/extension-bullet-list Major
@tiptap/extension-code-block-lowlight Major
@tiptap/extension-code-block Major
@tiptap/extension-code Major
@tiptap/extension-collaboration-caret Major
@tiptap/extension-collaboration Major
@tiptap/extension-color Major
@tiptap/extension-document Major
@tiptap/extension-floating-menu Major
@tiptap/extension-font-family Major
@tiptap/extension-hard-break Major
@tiptap/extension-heading Major
@tiptap/extension-highlight Major
@tiptap/extension-horizontal-rule Major
@tiptap/extension-image Major
@tiptap/extension-italic Major
@tiptap/extension-link Major
@tiptap/extension-list Major
@tiptap/extension-ordered-list Major
@tiptap/extension-paragraph Major
@tiptap/extension-strike Major
@tiptap/extension-subscript Major
@tiptap/extension-superscript Major
@tiptap/extension-table Major
@tiptap/extension-text-align Major
@tiptap/extension-text-style Major
@tiptap/extension-text Major
@tiptap/extension-typography Major
@tiptap/extension-underline Major
@tiptap/extension-youtube Major
@tiptap/extensions Major
@tiptap/html Major
@tiptap/pm Major
@tiptap/react Major
@tiptap/starter-kit Major
@tiptap/static-renderer Major
@tiptap/suggestion Major
@tiptap/vue-2 Major
@tiptap/vue-3 Major
@tiptap/extension-character-count Major
@tiptap/extension-dropcursor Major
@tiptap/extension-focus Major
@tiptap/extension-gapcursor Major
@tiptap/extension-history Major
@tiptap/extension-list-item Major
@tiptap/extension-list-keymap Major
@tiptap/extension-placeholder Major
@tiptap/extension-table-cell Major
@tiptap/extension-table-header Major
@tiptap/extension-table-row Major
@tiptap/extension-task-item Major
@tiptap/extension-task-list Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

netlify bot commented Apr 25, 2025

Deploy Preview for tiptap-embed ready!

Name Link
🔨 Latest commit 40d2f3b
🔍 Latest deploy log https://app.netlify.com/sites/tiptap-embed/deploys/680fa1196b5e020008eaf7eb
😎 Deploy Preview https://deploy-preview-6300--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.

@arnaugomez arnaugomez requested a review from bdbch April 25, 2025 10:47
Copy link

pkg-pr-new bot commented Apr 25, 2025

Open in StackBlitz

@tiptap/core

npm i https://pkg.pr.new/@tiptap/core@6300

@tiptap/extension-blockquote

npm i https://pkg.pr.new/@tiptap/extension-blockquote@6300

@tiptap/extension-bold

npm i https://pkg.pr.new/@tiptap/extension-bold@6300

@tiptap/extension-bubble-menu

npm i https://pkg.pr.new/@tiptap/extension-bubble-menu@6300

@tiptap/extension-bullet-list

npm i https://pkg.pr.new/@tiptap/extension-bullet-list@6300

@tiptap/extension-code

npm i https://pkg.pr.new/@tiptap/extension-code@6300

@tiptap/extension-code-block-lowlight

npm i https://pkg.pr.new/@tiptap/extension-code-block-lowlight@6300

@tiptap/extension-code-block

npm i https://pkg.pr.new/@tiptap/extension-code-block@6300

@tiptap/extension-collaboration

npm i https://pkg.pr.new/@tiptap/extension-collaboration@6300

@tiptap/extension-collaboration-caret

npm i https://pkg.pr.new/@tiptap/extension-collaboration-caret@6300

@tiptap/extension-color

npm i https://pkg.pr.new/@tiptap/extension-color@6300

@tiptap/extension-document

npm i https://pkg.pr.new/@tiptap/extension-document@6300

@tiptap/extension-floating-menu

npm i https://pkg.pr.new/@tiptap/extension-floating-menu@6300

@tiptap/extension-font-family

npm i https://pkg.pr.new/@tiptap/extension-font-family@6300

@tiptap/extension-hard-break

npm i https://pkg.pr.new/@tiptap/extension-hard-break@6300

@tiptap/extension-heading

npm i https://pkg.pr.new/@tiptap/extension-heading@6300

@tiptap/extension-highlight

npm i https://pkg.pr.new/@tiptap/extension-highlight@6300

@tiptap/extension-horizontal-rule

npm i https://pkg.pr.new/@tiptap/extension-horizontal-rule@6300

@tiptap/extension-image

npm i https://pkg.pr.new/@tiptap/extension-image@6300

@tiptap/extension-italic

npm i https://pkg.pr.new/@tiptap/extension-italic@6300

@tiptap/extension-link

npm i https://pkg.pr.new/@tiptap/extension-link@6300

@tiptap/extension-list

npm i https://pkg.pr.new/@tiptap/extension-list@6300

@tiptap/extension-mention

npm i https://pkg.pr.new/@tiptap/extension-mention@6300

@tiptap/extension-ordered-list

npm i https://pkg.pr.new/@tiptap/extension-ordered-list@6300

@tiptap/extension-paragraph

npm i https://pkg.pr.new/@tiptap/extension-paragraph@6300

@tiptap/extension-strike

npm i https://pkg.pr.new/@tiptap/extension-strike@6300

@tiptap/extension-subscript

npm i https://pkg.pr.new/@tiptap/extension-subscript@6300

@tiptap/extension-superscript

npm i https://pkg.pr.new/@tiptap/extension-superscript@6300

@tiptap/extension-table

npm i https://pkg.pr.new/@tiptap/extension-table@6300

@tiptap/extension-text

npm i https://pkg.pr.new/@tiptap/extension-text@6300

@tiptap/extension-text-align

npm i https://pkg.pr.new/@tiptap/extension-text-align@6300

@tiptap/extension-text-style

npm i https://pkg.pr.new/@tiptap/extension-text-style@6300

@tiptap/extension-typography

npm i https://pkg.pr.new/@tiptap/extension-typography@6300

@tiptap/extension-underline

npm i https://pkg.pr.new/@tiptap/extension-underline@6300

@tiptap/extension-youtube

npm i https://pkg.pr.new/@tiptap/extension-youtube@6300

@tiptap/extensions

npm i https://pkg.pr.new/@tiptap/extensions@6300

@tiptap/html

npm i https://pkg.pr.new/@tiptap/html@6300

@tiptap/pm

npm i https://pkg.pr.new/@tiptap/pm@6300

@tiptap/react

npm i https://pkg.pr.new/@tiptap/react@6300

@tiptap/starter-kit

npm i https://pkg.pr.new/@tiptap/starter-kit@6300

@tiptap/static-renderer

npm i https://pkg.pr.new/@tiptap/static-renderer@6300

@tiptap/suggestion

npm i https://pkg.pr.new/@tiptap/suggestion@6300

@tiptap/vue-2

npm i https://pkg.pr.new/@tiptap/vue-2@6300

@tiptap/vue-3

npm i https://pkg.pr.new/@tiptap/vue-3@6300

commit: 40d2f3b

})
})

this.storage.getSuggestionFromChar = char => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem to do something like this but it brings me back to an idea I had before. It feels weird to store internal functions in storage as I'd expect storage to contain data useful for the users.

In the future in another breaking change we could maybe change the API of the Extension.create call to accept a callback function like this:

// we could maybe even have editor/other context related things as arguments
const MyNode = Node.create((editor) => {
  function internalHelperFunction() {

  }

  const internalVar = "my-internal-var"

  return {
    // ... your extension config as usual
  }
})

what are your thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But no need to do anything right now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this. Sometimes a helper function can help you reuse duplicated code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general having an enclosed scope for an extension can be really helpful. We could make this change retroactive by allowing both a callback function & the old way of creating extensions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created a PR for this:
#6301

Maybe we can merge this and use this instead of using storage?

Copy link
Member

@bdbch bdbch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bdbch
Copy link
Member

bdbch commented Apr 25, 2025

It would be nice if we could have another test case that handles multiple suggestion triggers?

@bdbch bdbch requested a review from Copilot April 25, 2025 13:56
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the Mention extension to support multiple suggestion triggers, allowing different suggestion configurations (e.g., '@' for people and '#' for places) and improves demos for both Vue and React. Key changes include:

  • Introduction of a new utility function to generate suggestion options.
  • Modifications to the Mention extension API and rendering functions to handle multiple triggers.
  • Updates to demo examples and test spec placeholders for multi-trigger mentions.

Reviewed Changes

Copilot reviewed 14 out of 16 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/extension-mention/src/utils/get-default-suggestion-attributes.ts New utility to generate suggestion options based on provided overrides.
packages/extension-mention/src/mention.ts Updated Mention extension to support multiple triggers and deprecate renderLabel in favor of renderText/renderHTML.
demos/src/Examples/MultiMention/Vue/suggestions.js Added support for multiple trigger characters in the Vue demo.
demos/src/Examples/MultiMention/Vue/index.vue Updated Vue demo example to utilize multi-trigger mention functionality.
demos/src/Examples/MultiMention/Vue/index.spec.js Added test spec file placeholder.
demos/src/Examples/MultiMention/Vue/MentionList.vue Updated Vue mention list component.
demos/src/Examples/MultiMention/React/suggestions.js Updated React suggestions file to support multiple triggers.
demos/src/Examples/MultiMention/React/index.spec.js Added test spec file placeholder for React.
demos/src/Examples/MultiMention/React/index.jsx Updated React demo for multi-trigger mention.
demos/src/Examples/MultiMention/React/MentionList.jsx Updated React mention list component.
demos/src/Commands/SetContent/React/index.spec.js Adjusted test case to account for the new mentionSuggestionChar attribute.
.changeset/wise-books-kiss.md Changeset documentation for supporting multiple triggers in the Mention extension.
Files not reviewed (2)
  • demos/src/Examples/MultiMention/React/MentionList.scss: Language not supported
  • demos/src/Examples/MultiMention/React/styles.scss: Language not supported
Comments suppressed due to low confidence (2)

demos/src/Examples/MultiMention/Vue/index.spec.js:6

  • Add automated tests to validate the multi-trigger mention functionality in the Vue demo to ensure consistent behavior.
// TODO: Write tests

demos/src/Examples/MultiMention/React/index.spec.js:6

  • Consider adding automated tests for the React multi-trigger mention demo to verify the proper functionality of the new configuration.
// TODO: Write tests

@arnaugomez
Copy link
Contributor Author

Ok, I'll add some tests on Monday

@arnaugomez
Copy link
Contributor Author

@bdbch I just added some tests

Copy link
Member

@bdbch bdbch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! We'd just need to make sure the docs are up to date. But feel free to merge.

@arnaugomez
Copy link
Contributor Author

arnaugomez commented Apr 29, 2025

I'll update the next docs then: ueberdosis/tiptap-docs#179

@arnaugomez arnaugomez merged commit 5729cf4 into next Apr 29, 2025
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants