Skip to content

Commit

Permalink
warn if user is using the deprecated renderLabel
Browse files Browse the repository at this point in the history
  • Loading branch information
moham96 committed Jul 28, 2023
1 parent 186d670 commit 6dbfb30
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions packages/extension-mention/src/mention.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Suggestion, { SuggestionOptions } from '@tiptap/suggestion'
export type MentionOptions = {
HTMLAttributes: Record<string, any>
/** @deprecated use renderText and renderHTML instead */
renderLabel: (props: { options: MentionOptions; node: ProseMirrorNode }) => string
renderLabel?: (props: { options: MentionOptions; node: ProseMirrorNode }) => string
renderText: (props: { options: MentionOptions; node: ProseMirrorNode }) => string
renderHTML: (props: { options: MentionOptions; node: ProseMirrorNode }) => DOMOutputSpec
suggestion: Omit<SuggestionOptions, 'editor'>
Expand All @@ -20,9 +20,6 @@ export const Mention = Node.create<MentionOptions>({
addOptions() {
return {
HTMLAttributes: {},
renderLabel({ options, node }) {
return `${options.suggestion.char}${node.attrs.label ?? node.attrs.id}`
},
renderText({ options, node }) {
return `${options.suggestion.char}${node.attrs.label ?? node.attrs.id}`
},
Expand Down Expand Up @@ -123,6 +120,17 @@ export const Mention = Node.create<MentionOptions>({
},

renderHTML({ node, HTMLAttributes }) {
if (this.options.renderLabel !== undefined) {
console.warn('renderLabel is deprecated use renderText and renderHTML instead')
return [
'span',
mergeAttributes({ 'data-type': this.name }, this.options.HTMLAttributes, HTMLAttributes),
this.options.renderLabel({
options: this.options,
node,
}),
]
}
return [
'span',
mergeAttributes({ 'data-type': this.name }, this.options.HTMLAttributes, HTMLAttributes),
Expand All @@ -134,6 +142,13 @@ export const Mention = Node.create<MentionOptions>({
},

renderText({ node }) {
if (this.options.renderLabel !== undefined) {
console.warn('renderLabel is deprecated use renderText and renderHTML instead')
return this.options.renderLabel({
options: this.options,
node,
})
}
return this.options.renderText({
options: this.options,
node,
Expand Down

0 comments on commit 6dbfb30

Please sign in to comment.