feat: Add onBeforeStart and onBeforeUpdate handlers to the render function
This commit is contained in:
@@ -22,7 +22,9 @@ export interface SuggestionOptions {
|
|||||||
editor: Editor,
|
editor: Editor,
|
||||||
}) => any[] | Promise<any[]>,
|
}) => any[] | Promise<any[]>,
|
||||||
render?: () => {
|
render?: () => {
|
||||||
|
onBeforeStart?: (props: SuggestionProps) => void
|
||||||
onStart?: (props: SuggestionProps) => void,
|
onStart?: (props: SuggestionProps) => void,
|
||||||
|
onBeforeUpdate?: (props: SuggestionProps) => void
|
||||||
onUpdate?: (props: SuggestionProps) => void,
|
onUpdate?: (props: SuggestionProps) => void,
|
||||||
onExit?: (props: SuggestionProps) => void,
|
onExit?: (props: SuggestionProps) => void,
|
||||||
onKeyDown?: (props: SuggestionKeyDownProps) => boolean,
|
onKeyDown?: (props: SuggestionKeyDownProps) => boolean,
|
||||||
@@ -104,12 +106,7 @@ export function Suggestion({
|
|||||||
range: state.range,
|
range: state.range,
|
||||||
query: state.query,
|
query: state.query,
|
||||||
text: state.text,
|
text: state.text,
|
||||||
items: (handleChange || handleStart)
|
items: [],
|
||||||
? await items({
|
|
||||||
editor,
|
|
||||||
query: state.query,
|
|
||||||
})
|
|
||||||
: [],
|
|
||||||
command: commandProps => {
|
command: commandProps => {
|
||||||
command({
|
command({
|
||||||
editor,
|
editor,
|
||||||
@@ -132,6 +129,21 @@ export function Suggestion({
|
|||||||
: null,
|
: null,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (handleStart) {
|
||||||
|
renderer?.onBeforeStart?.(props)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (handleChange) {
|
||||||
|
renderer?.onBeforeUpdate?.(props)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (handleChange || handleStart) {
|
||||||
|
props.items = await items({
|
||||||
|
editor,
|
||||||
|
query: state.query,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if (handleExit) {
|
if (handleExit) {
|
||||||
renderer?.onExit?.(props)
|
renderer?.onExit?.(props)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user