-
Notifications
You must be signed in to change notification settings - Fork 33
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
TypeScript support #9
Comments
Not yet. |
Workarounds...
/// <reference types="node" />
declare module 'prosemirror-mentions' {
import { getMentionsPlugin, addMentionNodes, addTagNodes, tagNode, mentionNode } from 'prosemirror-mentions'
export const getMentionsPlugin
export const addMentionNodes
export const addTagNodes
export const tagNode
export const mentionNode
}
{
"compilerOptions": {
"allowJs": true,
"noImplicitAny": true,
"strictNullChecks": true
},
"include": ["src/**/*"],
}
import React from 'react'
import ReactDOMServer from 'react-dom/server'
import * as prosemirrorMentions from 'prosemirror-mentions'
export type UserRecord = {
name: string
id: string
}
export type SuggestionsComplete = (arg0: UserRecord[]) => void
const SuggestionList: React.FC<{ items: UserRecord[] }> = ({ items }) => {
return (
<div className="suggestion-item-list">
{items && items.map(i =>
<div className="suggestion-item">{i.name}</div>
)}
</div>
)
}
export const mentionPlugin = prosemirrorMentions.getMentionsPlugin({
getSuggestions: (type: string, text: any, done: SuggestionsComplete) => {
setTimeout(() => {
if (type === 'mention') {
done([
{ name: 'John Doe', id: '101' },
{ name: 'Joe Lewis', id: '102' }
])
}
}, 0)
},
getSuggestionsHTML: (items: UserRecord[], type: string) => {
if (type === 'mention') {
return ReactDOMServer.renderToString(<SuggestionList items={items} />)
}
}
})
|
Instead of the above workaround, I recommend looking at this TypeScript fork for now... |
Who would be interested to rewrite with me this plugin completely in Typescript? The plugin would be more maintainable and it would allow to make it evolve. |
Anyone already setup a declaration file?
The text was updated successfully, but these errors were encountered: