Skip to content
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

Add editor to items prop in suggestion plugin #2082

Merged
merged 2 commits into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demos/src/Examples/Community/React/suggestion.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import tippy from 'tippy.js'
import { MentionList } from './MentionList'

export default {
items: query => {
items: ({ query }) => {
return [
'Lea Thompson', 'Cyndi Lauper', 'Tom Cruise', 'Madonna', 'Jerry Hall', 'Joan Collins', 'Winona Ryder', 'Christina Applegate', 'Alyssa Milano', 'Molly Ringwald', 'Ally Sheedy', 'Debbie Harry', 'Olivia Newton-John', 'Elton John', 'Michael J. Fox', 'Axl Rose', 'Emilio Estevez', 'Ralph Macchio', 'Rob Lowe', 'Jennifer Grey', 'Mickey Rourke', 'John Cusack', 'Matthew Broderick', 'Justine Bateman', 'Lisa Bonet',
].filter(item => item.toLowerCase().startsWith(query.toLowerCase())).slice(0, 5)
Expand Down
2 changes: 1 addition & 1 deletion demos/src/Examples/Community/Vue/suggestion.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import tippy from 'tippy.js'
import MentionList from './MentionList.vue'

export default {
items: query => {
items: ({ query }) => {
return [
'Lea Thompson', 'Cyndi Lauper', 'Tom Cruise', 'Madonna', 'Jerry Hall', 'Joan Collins', 'Winona Ryder', 'Christina Applegate', 'Alyssa Milano', 'Molly Ringwald', 'Ally Sheedy', 'Debbie Harry', 'Olivia Newton-John', 'Elton John', 'Michael J. Fox', 'Axl Rose', 'Emilio Estevez', 'Ralph Macchio', 'Rob Lowe', 'Jennifer Grey', 'Mickey Rourke', 'John Cusack', 'Matthew Broderick', 'Justine Bateman', 'Lisa Bonet',
].filter(item => item.toLowerCase().startsWith(query.toLowerCase())).slice(0, 5)
Expand Down
2 changes: 1 addition & 1 deletion demos/src/Experiments/Commands/Vue/suggestion.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { VueRenderer } from '@tiptap/vue-3'
import CommandsList from './CommandsList.vue'

export default {
items: query => {
items: ({ query }) => {
return [
{
title: 'H1',
Expand Down
2 changes: 1 addition & 1 deletion demos/src/Nodes/Mention/Vue/suggestion.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import tippy from 'tippy.js'
import MentionList from './MentionList.vue'

export default {
items: query => {
items: ({ query }) => {
return [
'Lea Thompson', 'Cyndi Lauper', 'Tom Cruise', 'Madonna', 'Jerry Hall', 'Joan Collins', 'Winona Ryder', 'Christina Applegate', 'Alyssa Milano', 'Molly Ringwald', 'Ally Sheedy', 'Debbie Harry', 'Olivia Newton-John', 'Elton John', 'Michael J. Fox', 'Axl Rose', 'Emilio Estevez', 'Ralph Macchio', 'Rob Lowe', 'Jennifer Grey', 'Mickey Rourke', 'John Cusack', 'Matthew Broderick', 'Justine Bateman', 'Lisa Bonet',
].filter(item => item.toLowerCase().startsWith(query.toLowerCase())).slice(0, 5)
Expand Down
2 changes: 1 addition & 1 deletion docs/api/utilities/suggestion.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Default: `() => {}'`
### items
Pass an array of filtered suggestions, can be async.

Default: `() => {}`
Default: `({ editor, query }) => []`

### render
A render function for the autocomplete popup.
Expand Down
10 changes: 8 additions & 2 deletions packages/suggestion/src/suggestion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export interface SuggestionOptions {
range: Range,
props: any,
}) => void,
items?: (query: string) => any[] | Promise<any[]>,
items?: (props: {
query: string,
editor: Editor,
}) => any[] | Promise<any[]>,
render?: () => {
onStart?: (props: SuggestionProps) => void,
onUpdate?: (props: SuggestionProps) => void,
Expand Down Expand Up @@ -99,7 +102,10 @@ export function Suggestion({
query: state.query,
text: state.text,
items: (handleChange || handleStart)
? await items(state.query)
? await items({
editor,
query: state.query,
})
: [],
command: commandProps => {
command({
Expand Down