All Projects → joelewis → Prosemirror Mentions

joelewis / Prosemirror Mentions

Licence: mit
ProseMirror plugin to enable @mentions and #hashtags

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Prosemirror Mentions

Js Proxy Deep
A proxy API for deeply nested JavaScript objects
Stars: ✭ 29 (-47.27%)
Mutual labels:  javascript-library
React Native Heic Converter
Convert your HEIC files with React Native
Stars: ✭ 43 (-21.82%)
Mutual labels:  javascript-library
Adder
Executing untrusted code with ease.
Stars: ✭ 45 (-18.18%)
Mutual labels:  javascript-library
React Equalizer
Pure React Match Height Component
Stars: ✭ 32 (-41.82%)
Mutual labels:  javascript-library
Minisauras
An open-source CI/CD automation tool based on GitHub Actions that pulls all the JavaScript and CSS files from your base branch, minify them and creates a pull-request with a new branch.
Stars: ✭ 40 (-27.27%)
Mutual labels:  javascript-library
Ansi Escape Sequences
A simple, isomorphic library containing all known terminal ansi escape codes and sequences.
Stars: ✭ 44 (-20%)
Mutual labels:  javascript-library
Oojs
Power for object oriented javascript libraries. This is a mirror from https://gerrit.wikimedia.org. See https://www.mediawiki.org/wiki/Developer_access for contributing.
Stars: ✭ 14 (-74.55%)
Mutual labels:  javascript-library
Drafter.js
API Blueprint parser in JS
Stars: ✭ 50 (-9.09%)
Mutual labels:  javascript-library
Redash
Tiny functional programming suite for JavaScript.
Stars: ✭ 40 (-27.27%)
Mutual labels:  javascript-library
Angular Tree Component
A simple yet powerful tree component for Angular (>=2)
Stars: ✭ 1,031 (+1774.55%)
Mutual labels:  javascript-library
Byte Size
Isomorphic function to convert a bytes value (e.g. 3456) to a human-readable string ('3.5 kB')
Stars: ✭ 33 (-40%)
Mutual labels:  javascript-library
Svg World Map
🗺 A JavaScript library to easily integrate one or more SVG world maps with all nations (countries) and second-level political subdivisions (countries, provinces, states).
Stars: ✭ 38 (-30.91%)
Mutual labels:  javascript-library
Filepond Boilerplate Php
🔥 A FilePond PHP project starter kit
Stars: ✭ 45 (-18.18%)
Mutual labels:  javascript-library
Pki.js
PKI.js is a pure JavaScript library implementing the formats that are used in PKI applications (signing, encryption, certificate requests, OCSP and TSP requests/responses). It is built on WebCrypto (Web Cryptography API) and requires no plug-ins.
Stars: ✭ 960 (+1645.45%)
Mutual labels:  javascript-library
Chroma.js
JavaScript library for all kinds of color manipulations
Stars: ✭ 8,364 (+15107.27%)
Mutual labels:  javascript-library
Zumly
Zumly is a JS library for building zooming user interfaces
Stars: ✭ 22 (-60%)
Mutual labels:  javascript-library
Vue Prism
Simple Vue.js Syntax highlighting with Prism.js
Stars: ✭ 43 (-21.82%)
Mutual labels:  javascript-library
Autoobjectdocumentation
Auto Object Documentation - JavaScript
Stars: ✭ 54 (-1.82%)
Mutual labels:  javascript-library
Flowy
The minimal javascript library to create flowcharts ✨
Stars: ✭ 8,636 (+15601.82%)
Mutual labels:  javascript-library
Simpletones.js
The goal of simpleTones.js is to provide every JavaScript developer with a lightweight solution for creating custom sounds in their web applications. This documentation has been written in hopes that the least experienced developer can read, understand and go on to do great things. You can check out several examples at this link:
Stars: ✭ 45 (-18.18%)
Mutual labels:  javascript-library

ProseMirror Mentions

A ProseMirror plugin that enables @mentions and #hashtags in a prosemirror view.

Demo: https://star-drug.glitch.me/

Alternative: https://github.com/quartzy/prosemirror-suggestions

What's different then?

prosemirror-suggestions is a lighter alternative that comes with the bare minimum. It is upto you to implement the dropdown & related logic.

prosemirror-mentions is a fully packed plugin. It comes with all batteries included: default dropdown UI, behavior handling, support for async fetching of suggestions, etc. Configure options to suit your needs.

Installation

npm install prosemirror-mentions

Usage

import {addMentionNodes, addTagNodes, getMentionsPlugin} from 'prosemirror-mentions'

...
...

var schema = new Schema({
    nodes: addTagNodes(addMentionNodes(schema.spec.nodes)),
    marks: schema.spec.marks
});

...
...


/**
 * IMPORTANT: outer div's "suggestion-item-list" class is mandatory. The plugin uses this class for querying.
 * IMPORTANT: inner div's "suggestion-item" class is mandatory too for the same reasons
 */
var getMentionSuggestionsHTML = items => '<div class="suggestion-item-list">'+
  items.map(i => '<div class="suggestion-item">'+i.name+'</div>').join('')+
'</div>';

/**
 * IMPORTANT: outer div's "suggestion-item-list" class is mandatory. The plugin uses this class for querying.
 * IMPORTANT: inner div's "suggestion-item" class is mandatory too for the same reasons
 */
var getTagSuggestionsHTML = items => '<div class="suggestion-item-list">'+
  items.map(i => '<div class="suggestion-item">'+i.tag+'</div>').join('')+
'</div>';

var plugins = [/* A list of other plugins */]

var mentionPlugin = getMentionsPlugin({
    getSuggestions: (type, text, done) => {
      setTimeout(() => {
        if (type === 'mention') {
            // pass dummy mention suggestions
            done([{name: 'John Doe', id: '101', email: '[email protected]'}, {name: 'Joe Lewis', id: '102', email: '[email protected]'}])
        } else {
            // pass dummy tag suggestions
            done([{tag: 'WikiLeaks'}, {tag: 'NetNeutrality'}])
        }
      }, 0);
    },
    getSuggestionsHTML: (items, type) =>  {
      if (type === 'mention') {
        return getMentionSuggestionsHTML(items)
      } else if (type === 'tag') {
        return getTagSuggestionsHTML(items)
      }
    }
});

plugins.unshift(mentionPlugin); // push it before keymap plugin to override keydown handlers
...
...
window.view = new EditorView(document.querySelector("#my-editor-div"), {
  state: EditorState.create({
    schema: schema,
    plugins: plugins
  })
});

Refer example application for clarifications.

Complete List of Options

// default options
var defaultOpts = {
  // char for triggering @mention
  mentionTrigger: "@",

  // char for triggering #tag
  hashtagTrigger: "#",

  // if true: allows you to type @FirstName LastName with a space in between.
  allowSpace: true,

  /**
   * callback to fetch suggestions and return a list of suggestions
   * @param {String} type - 'mention' or 'tag'
   * @param {String} text - query text. For e.g @Joh -> text = 'Joh'
   * @param {Function} done - callback to execute after fetching suggestions (ideally from ajax requests)
   */
  getSuggestions: (type, text, done) => {
    done([]);
  },

  /**
   * callback to construct and return a HTML string for a set of suggestions
   * @param {Array} items - a list of suggestions returned from getSuggestions()
   * @param {String} type - 'mention' or 'tag'
   */
  getSuggestionsHTML: (items, type) =>
    '<div class="suggestion-item-list">' +
    items
      .map(i =>
        '<div class="suggestion-item">' + type === "mention"
          ? i.name
          : i.tag + "</div>"
      )
      .join("") +
    "</div>",

  // css class to add when a .suggestion-item element is active / selected.
  activeClass: "suggestion-item-active",

  // css class to add to "@Mentioned Text" in editor. Can be used to style, the current active @mention content.
  suggestionTextClass: "prosemirror-suggestion",

  // Max number of suggestions to show in dropdown UI.
  // The response from getSuggestions() will be truncated based on this value.
  maxNoOfSuggestions: 10,

  // debounce timeout for getSuggestions() call when user types continuously
  delay: 500
};

Development

npm run build
npm run watch

Authors

Pending Tasks

grep the repository for "TODO:"

ISSUES & FEEDBACK

Use Github Issues to file requests and bugs.

License

MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].