Skip to content

Commit

Permalink
feat: Add onBeforeStart and onBeforeUpdate handlers to the render…
Browse files Browse the repository at this point in the history
… function
  • Loading branch information
rfgamaral committed Mar 11, 2022
1 parent ab4a0e2 commit 7d6401a
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions packages/suggestion/src/suggestion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export interface SuggestionOptions {
editor: Editor,
}) => any[] | Promise<any[]>,
render?: () => {
onBeforeStart?: (props: SuggestionProps) => void
onStart?: (props: SuggestionProps) => void,
onBeforeUpdate?: (props: SuggestionProps) => void
onUpdate?: (props: SuggestionProps) => void,
onExit?: (props: SuggestionProps) => void,
onKeyDown?: (props: SuggestionKeyDownProps) => boolean,
Expand Down Expand Up @@ -104,12 +106,7 @@ export function Suggestion({
range: state.range,
query: state.query,
text: state.text,
items: (handleChange || handleStart)
? await items({
editor,
query: state.query,
})
: [],
items: [],
command: commandProps => {
command({
editor,
Expand All @@ -132,6 +129,21 @@ export function Suggestion({
: null,
}

if (handleStart) {
renderer?.onBeforeStart?.(props)
}

if (handleChange) {
renderer?.onBeforeUpdate?.(props)
}

if (handleChange || handleStart) {
props.items = await items({
editor,
query: state.query,
})
}

if (handleExit) {
renderer?.onExit?.(props)
}
Expand Down

0 comments on commit 7d6401a

Please sign in to comment.