Remove exclusions code from Tiptap utils

This commit is contained in:
Justin Edmund 2023-08-21 19:54:49 -07:00
parent d88945ad95
commit 84131c96bf

View file

@ -1,6 +1,5 @@
import type { JSONContent } from '@tiptap/core'
import { ReactRenderer } from '@tiptap/react' import { ReactRenderer } from '@tiptap/react'
import { MentionOptions } from '@tiptap/extension-mention'
import { SuggestionKeyDownProps, SuggestionProps } from '@tiptap/suggestion'
import tippy, { Instance as TippyInstance } from 'tippy.js' import tippy, { Instance as TippyInstance } from 'tippy.js'
import { getCookie } from 'cookies-next' import { getCookie } from 'cookies-next'
@ -44,13 +43,23 @@ function transform(object: RawSearchResponse) {
} }
return result return result
} }
//
function parseMentions(data: JSONContent) {
const mentions: string[] = (data.content || []).flatMap(parseMentions)
if (data.type === 'mention') {
const granblueId = data.attrs?.id.granblue_id
mentions.push(granblueId)
}
return [...new Set(mentions)]
}
export const mentionSuggestionOptions: Omit<SuggestionOptions, 'editor'> = { export const mentionSuggestionOptions: Omit<SuggestionOptions, 'editor'> = {
items: async ({ query }): Promise<MentionSuggestion[]> => { items: async ({ query, editor }): Promise<MentionSuggestion[]> => {
const locale = getCookie('NEXT_LOCALE') const locale = getCookie('NEXT_LOCALE')
? (getCookie('NEXT_LOCALE') as string) ? (getCookie('NEXT_LOCALE') as string)
: 'en' : 'en'
const response = await api.searchAll(query, locale) const response = await api.searchAll(query, [], locale)
const results = response.data.results const results = response.data.results
return results return results
@ -72,7 +81,6 @@ export const mentionSuggestionOptions: Omit<SuggestionOptions, 'editor'> = {
render: () => { render: () => {
let component: ReactRenderer<MentionRef> | undefined let component: ReactRenderer<MentionRef> | undefined
let popup: TippyInstance | undefined let popup: TippyInstance | undefined
return { return {
onStart: (props) => { onStart: (props) => {
component = new ReactRenderer(MentionList, { component = new ReactRenderer(MentionList, {
@ -80,6 +88,10 @@ export const mentionSuggestionOptions: Omit<SuggestionOptions, 'editor'> = {
editor: props.editor, editor: props.editor,
}) })
console.log('in onStart')
const rect = props.clientRect?.()
console.log(rect)
popup = tippy('body', { popup = tippy('body', {
getReferenceClientRect: props.clientRect, getReferenceClientRect: props.clientRect,
appendTo: () => document.body, appendTo: () => document.body,