-
Notifications
You must be signed in to change notification settings - Fork 1.1k
adding mentionTrigger #320
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
Changes from all commits
7c8de90
f37a763
f7b752a
de58ad0
51fe22a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import { Entity } from 'draft-js'; | ||
|
||
const findMention = (character) => { | ||
const findMention = (trigger) => (character) => { | ||
const entityKey = character.getEntity(); | ||
return (entityKey !== null && Entity.get(entityKey).getType() === 'mention'); | ||
return (entityKey !== null && Entity.get(entityKey).getType() === `mention-${trigger}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would be a breaking change to all existing implementations. I think by default the type should still be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't think of any use case in which a custom Even if the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we would change the default type everyone who used the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will merge it and fix it, that in case of |
||
}; | ||
|
||
const findMentionEntities = (contentBlock, callback) => { | ||
contentBlock.findEntityRanges(findMention, callback); | ||
const findMentionEntities = (trigger) => (contentBlock, callback) => { | ||
contentBlock.findEntityRanges(findMention(trigger), callback); | ||
}; | ||
|
||
export default findMentionEntities; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
/* @flow */ | ||
|
||
import findWithRegex from 'find-with-regex'; | ||
import _ from 'lodash'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not ideal, as it would include the whole lodash library. By using |
||
|
||
const MENTION_REGEX = /(\s|^)@[\w]*/g; | ||
|
||
export default (contentBlock: Object, callback: Function) => { | ||
findWithRegex(MENTION_REGEX, contentBlock, callback); | ||
export default (trigger: String) => (contentBlock: Object, callback: Function) => { | ||
findWithRegex(new RegExp(`(\\s|^)${_.escapeRegExp(trigger)}[\\w]*`, 'g'), contentBlock, callback); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spaces where here by intention to make it easy to distinct which component is affected. Maybe a comment would have been better. Can you add comments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't realize I made these changes. I'll add some comments.