Gathering detailed insights and metrics for quill-mention
Gathering detailed insights and metrics for quill-mention
Gathering detailed insights and metrics for quill-mention
Gathering detailed insights and metrics for quill-mention
npm install quill-mention
97.9
Supply Chain
100
Quality
84.3
Maintenance
100
Vulnerability
98.2
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
755 Stars
269 Commits
274 Forks
14 Watching
3 Branches
40 Contributors
Updated on 22 Nov 2024
TypeScript (67.26%)
JavaScript (25.82%)
HTML (3.72%)
CSS (3.2%)
Cumulative downloads
Total Downloads
Last day
-6.2%
19,188
Compared to previous day
Last week
2.8%
104,782
Compared to previous week
Last month
5.8%
450,273
Compared to previous month
Last year
-8.1%
4,443,818
Compared to previous year
Quill Mention is a module to provide @mentions or #hashtag functionality for the Quill rich text editor.
Install with npm:
1npm install quill-mention --save
Install with Yarn:
1yarn add quill-mention
1import "quill-mention/autoregister";
Importing quill-mention automatically adds it to Quill modules.
Now you only need to pass quill-mention config to quill.
Or you can manually import module and register it
1import Quill from "quill"; 2import {Mention, MentionBlot} from "quill-mention"; 3 4Quill.register({ "blots/mention": MentionBlot, "modules/mention": Mention });
1import "quill-mention/autoregister"; 2 3const atValues = [ 4 { id: 1, value: "Fredrik Sundqvist" }, 5 { id: 2, value: "Patrik Sjölin" } 6]; 7const hashValues = [ 8 { id: 3, value: "Fredrik Sundqvist 2" }, 9 { id: 4, value: "Patrik Sjölin 2" } 10]; 11const quill = new Quill("#editor", { 12 modules: { 13 mention: { 14 allowedChars: /^[A-Za-z\sÅÄÖåäö]*$/, 15 mentionDenotationChars: ["@", "#"], 16 source: function(searchTerm, renderList, mentionChar) { 17 let values; 18 19 if (mentionChar === "@") { 20 values = atValues; 21 } else { 22 values = hashValues; 23 } 24 25 if (searchTerm.length === 0) { 26 renderList(values, searchTerm); 27 } else { 28 const matches = []; 29 for (let i = 0; i < values.length; i++) 30 if ( 31 ~values[i].value.toLowerCase().indexOf(searchTerm.toLowerCase()) 32 ) 33 matches.push(values[i]); 34 renderList(matches, searchTerm); 35 } 36 } 37 } 38 } 39});
1 window.addEventListener('mention-hovered', (event) => {console.log('hovered: ', event)}, false); 2 window.addEventListener('mention-clicked', (event) => {console.log('hovered: ', event)}, false);
1async function suggestPeople(searchTerm) { 2 const allPeople = [ 3 { 4 id: 1, 5 value: "Fredrik Sundqvist" 6 }, 7 { 8 id: 2, 9 value: "Patrik Sjölin" 10 } 11 ]; 12 return allPeople.filter(person => person.value.includes(searchTerm)); 13} 14 15const quill = new Quill("#editor", { 16 modules: { 17 mention: { 18 allowedChars: /^[A-Za-z\sÅÄÖåäö]*$/, 19 mentionDenotationChars: ["@", "#"], 20 source: async function(searchTerm, renderList) { 21 const matchedPeople = await suggestPeople(searchTerm); 22 renderList(matchedPeople); 23 } 24 } 25 } 26});
Note: if you whitelist quill formats via "formats" option, you need to add the mention format (default: "mention") there. Another way quill-mention won't work. Here's an example with whitelisted formats:
1const quill = new Quill("#editor", { 2 formats: ["bold", "italic", "mention"], 3 // note "mention" format above 4 modules: { 5 mention: { 6 allowedChars: /^[A-Za-z\sÅÄÖåäö]*$/, 7 mentionDenotationChars: ["@", "#"], 8 source: function(searchTerm, renderList, mentionChar) { 9 // some source implementation 10 } 11 } 12 } 13});
Property | Default | Description |
---|---|---|
source(searchTerm, renderList, mentionChar) | null | Required callback function to handle the search term and connect it to a data source for matches. The data source can be a local source or an AJAX request. The callback should call renderList(matches, searchTerm); with matches of JSON Objects in an array to show the result for the user. The JSON Objects should have id and value but can also have other values to be used in renderItem for custom display. |
renderItem(item, searchTerm) | function | A function that gives you control over how matches from source are displayed. You can use this function to highlight the search term or change the design with custom HTML. This function will need to return either a string possibly containing unsanitized user content, or a class implementing the Node interface which will be treated as a sanitized DOM node. |
allowedChars | [a-zA-Z0-9_] (or function ) | Allowed characters in search term triggering a search request using regular expressions. Can be a function that takes the denotationChar and returns a regex. |
minChars | 0 | Minimum number of characters after the @ symbol triggering a search request |
maxChars | 31 | Maximum number of characters after the @ symbol triggering a search request |
offsetTop | 2 | Additional top offset of the mention container position |
offsetLeft | 0 | Additional left offset of the mention container position |
mentionDenotationChars | ["@"] | Specifies which characters will cause the mention autocomplete to open |
isolateCharacter | false | Whether or not the denotation character(s) should be isolated. For example, to avoid mentioning in an email. |
allowInlineMentionChar | false | Only works if isolateCharacter is set to true . Whether or not the denotation character(s) can appear inline of the mention text. For example, to allow mentioning an email with the @ symbol as the denotation character. |
fixMentionsToQuill | false | When set to true, the mentions menu will be rendered above or below the quill container. Otherwise, the mentions menu will track the denotation character(s); |
showDenotationChar | true | Whether to show the used denotation character in the mention item or not |
defaultMenuOrientation | 'bottom' | Options are 'bottom' and 'top' . Determines what the default orientation of the menu will be. Quill-mention will attempt to render the menu either above or below the editor. If 'top' is provided as a value, and there is not enough space above the editor, the menu will be rendered below. Vice versa, if there is not enough space below the editor, and 'bottom' is provided as a value (or no value is provided at all), the menu will be rendered above the editor. |
blotName | 'mention' | The name of the Quill Blot to be used for inserted mentions. A default implementation is provided named 'mention', which may be overridden with a custom blot. |
dataAttributes | ['id', 'value', 'denotationChar', 'link', 'target','disabled'] | A list of data values you wish to be passed from your list data to the html node. (id, value, denotationChar, link, target are included by default). |
onOpen | function | Callback when mention dropdown is open. |
onBeforeClose | function | Callback before the DOM of mention dropdown is removed. |
onClose | function | Callback when mention dropdown is closed. |
onSelect(item, insertItem) | function | Callback for a selected item. When overriding this method, insertItem should be used to insert item to the editor. This makes async requests possible. |
linkTarget | '_blank' | Link target for mentions with a link |
listItemClass | 'ql-mention-list-item' | Style class to be used for list items (may be null) |
mentionContainerClass | 'ql-mention-list-container' | Style class to be used for the mention list container (may be null) |
mentionListClass | 'ql-mention-list' | Style class to be used for the mention list (may be null) |
spaceAfterInsert | true | Whether or not insert 1 space after mention block in text |
positioningStrategy | 'normal' | Options are 'normal' and 'fixed' . When 'fixed' , the menu will be appended to the body and use fixed positioning. Use this if the menu is clipped by a parent element that's using `overflow:hidden |
renderLoading | function | A function that returns the HTML for a loading message during async calls from source . The function will need to return either a string possibly containing unsanitized user content, or a class implementing the Node interface which will be treated as a sanitized DOM node. The default functions returns null to prevent a loading message. |
selectKeys | [13] | An array of keyboard key codes that will trigger the select action for the mention dropdown. Default is ENTER key. See this reference for a list of numbers for each keyboard key. |
You may retrieve the module from Quill like quill.getModule('mention')
then call one of the imperative methods below.
Method | Example | Description |
---|---|---|
insertItem(data, programmaticInsert, overriddenOptions = {}) | insertItem({id:'123',value:'My Mention'},true, {blotName: "new_blot"}) | Inserts the given mention into the editor. Also you can override blotName , showDenotationChar and spaceAfterInsert options using overriddenOptions param |
openMenu(denotationChar) | openMenu('@') | Opens the mentions menu for the given denotation character. |
To allow styling based on the menu orientation, a class is added depending on the orientation and the mentionContainerClass
option. By default this will be ql-mention-list-container-bottom
or ql-mention-list-container-top
.
Mention blots can also be dynamically styled from data attributes, but requires implement a custom Quill blot. For example:
1const MentionBlot = Quill.import("blots/mention"); 2 3class StyledMentionBlot extends MentionBlot { 4 static render(data) { 5 const element = document.createElement('span'); 6 element.innerText = data.value; 7 element.style.color = data.color; 8 return element; 9 } 10} 11StyledMentionBlot.blotName = "styled-mention"; 12 13Quill.register(StyledMentionBlot);
Then, when creating your Quill instance, use the following settings:
1const quill = new Quill('#editor', { 2 modules: { 3 mention: { 4 // ... 5 dataAttributes: ['id', 'value', 'denotationChar', 'link', 'target', 'disabled', 'color'], 6 blotName: 'styled-mention', 7 } 8 } 9});
Sometimes you may want to display a menu item that should not be selectable. These items may be group headers, hint text, or even a message saying there were no matching results. To show items like these, add disabled:true
to items passed to renderList
from your source
method. Disabled items are shown but not selectable with the mouse or keyboard. If you need to style the disabled items differently, you will need to override the renderItem
method.
As of 4.0.0, HTML embedded in value
will no longer be rendered, due to potential XSS issues. Instead, to adjust rendering of list items, you can return a class implementing the Node interface which will be treated as a sanitized DOM node, and in order to customize blot rendering, you will need to create a custom mention blot
Fredrik Sundqvist (MadSpindel)
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE file for details
The latest stable version of the package.
Stable Version
1
6.1/10
Summary
quill-mention Cross-site Scripting vulnerability
Affected Versions
< 4.0.0
Patched Versions
4.0.0
No security vulnerabilities found.