Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tiptap/suggestion

Package Overview
Dependencies
Maintainers
4
Versions
240
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tiptap/suggestion

suggestion plugin for tiptap

  • 2.1.0-rc.12
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
464K
decreased by-7.63%
Maintainers
4
Weekly downloads
 
Created

What is @tiptap/suggestion?

@tiptap/suggestion is a plugin for the Tiptap editor that provides a way to add suggestions to your editor. This can be used for implementing features like mentions, hashtags, or any other type of inline suggestions.

What are @tiptap/suggestion's main functionalities?

Basic Suggestion Setup

This code sets up a basic suggestion plugin that triggers on the '@' character. When a suggestion is selected, it inserts a mention node at the current position.

import { Suggestion } from '@tiptap/suggestion';

const suggestion = Suggestion({
  char: '@',
  startOfLine: false,
  command: ({ editor, range, props }) => {
    editor.chain().focus().insertContentAt(range, [
      {
        type: 'mention',
        attrs: props,
      },
      {
        type: 'text',
        text: ' ',
      },
    ]).run();
  },
});

Customizing Suggestion Menu

This code customizes the suggestion menu to trigger on the '#' character and filter items based on the query. It uses Vue and Tippy.js to render and manage the suggestion list.

import { Suggestion } from '@tiptap/suggestion';

const suggestion = Suggestion({
  char: '#',
  startOfLine: false,
  items: ({ query }) => {
    return [
      { title: 'JavaScript', id: 1 },
      { title: 'TypeScript', id: 2 },
      { title: 'React', id: 3 },
    ].filter(item => item.title.toLowerCase().includes(query.toLowerCase()));
  },
  render: () => {
    let component;
    let popup;

    return {
      onStart: props => {
        component = new Vue({
          render: h => h(SuggestionList, { props }),
        }).$mount();
        popup = tippy('body', {
          getReferenceClientRect: props.clientRect,
          appendTo: () => document.body,
          content: component.$el,
          showOnCreate: true,
        });
      },
      onUpdate: props => {
        component.$props = props;
        popup[0].setProps({
          getReferenceClientRect: props.clientRect,
        });
      },
      onExit: () => {
        popup[0].destroy();
        component.$destroy();
      },
    };
  },
});

Other packages similar to @tiptap/suggestion

Keywords

FAQs

Package last updated on 14 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc