Skip to content

Commit

Permalink
feat: Add a generic type for suggestion items
Browse files Browse the repository at this point in the history
  • Loading branch information
rfgamaral committed Mar 11, 2022
1 parent ab4a0e2 commit f6fc6b2
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions packages/suggestion/src/suggestion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { EditorState, Plugin, PluginKey } from 'prosemirror-state'
import { Decoration, DecorationSet, EditorView } from 'prosemirror-view'
import { findSuggestionMatch } from './findSuggestionMatch'

export interface SuggestionOptions {
export interface SuggestionOptions<I = any> {
pluginKey?: PluginKey,
editor: Editor,
char?: string,
Expand All @@ -15,16 +15,16 @@ export interface SuggestionOptions {
command?: (props: {
editor: Editor,
range: Range,
props: any,
props: I,
}) => void,
items?: (props: {
query: string,
editor: Editor,
}) => any[] | Promise<any[]>,
}) => I[] | Promise<I[]>,
render?: () => {
onStart?: (props: SuggestionProps) => void,
onUpdate?: (props: SuggestionProps) => void,
onExit?: (props: SuggestionProps) => void,
onStart?: (props: SuggestionProps<I>) => void,
onUpdate?: (props: SuggestionProps<I>) => void,
onExit?: (props: SuggestionProps<I>) => void,
onKeyDown?: (props: SuggestionKeyDownProps) => boolean,
},
allow?: (props: {
Expand All @@ -34,13 +34,13 @@ export interface SuggestionOptions {
}) => boolean,
}

export interface SuggestionProps {
export interface SuggestionProps<I = any> {
editor: Editor,
range: Range,
query: string,
text: string,
items: any[],
command: (props: any) => void,
items: I[],
command: (props: I) => void,
decorationNode: Element | null,
clientRect: (() => DOMRect) | null,
}
Expand All @@ -53,7 +53,7 @@ export interface SuggestionKeyDownProps {

export const SuggestionPluginKey = new PluginKey('suggestion')

export function Suggestion({
export function Suggestion<I = any>({
pluginKey = SuggestionPluginKey,
editor,
char = '@',
Expand All @@ -66,9 +66,9 @@ export function Suggestion({
items = () => [],
render = () => ({}),
allow = () => true,
}: SuggestionOptions) {
}: SuggestionOptions<I>) {

let props: SuggestionProps | undefined
let props: SuggestionProps<I> | undefined
const renderer = render?.()

return new Plugin({
Expand Down

0 comments on commit f6fc6b2

Please sign in to comment.