From 84131c96bf15e6fb6dc0765c9141e1aa7ccfcf86 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Mon, 21 Aug 2023 19:54:49 -0700 Subject: [PATCH] Remove exclusions code from Tiptap utils --- utils/mentionSuggestions.tsx | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/utils/mentionSuggestions.tsx b/utils/mentionSuggestions.tsx index e495bfbd..8bc075c1 100644 --- a/utils/mentionSuggestions.tsx +++ b/utils/mentionSuggestions.tsx @@ -1,6 +1,5 @@ +import type { JSONContent } from '@tiptap/core' 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 { getCookie } from 'cookies-next' @@ -44,13 +43,23 @@ function transform(object: RawSearchResponse) { } 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 = { - items: async ({ query }): Promise => { + items: async ({ query, editor }): Promise => { const locale = getCookie('NEXT_LOCALE') ? (getCookie('NEXT_LOCALE') as string) : 'en' - const response = await api.searchAll(query, locale) + const response = await api.searchAll(query, [], locale) const results = response.data.results return results @@ -72,7 +81,6 @@ export const mentionSuggestionOptions: Omit = { render: () => { let component: ReactRenderer | undefined let popup: TippyInstance | undefined - return { onStart: (props) => { component = new ReactRenderer(MentionList, { @@ -80,6 +88,10 @@ export const mentionSuggestionOptions: Omit = { editor: props.editor, }) + console.log('in onStart') + const rect = props.clientRect?.() + console.log(rect) + popup = tippy('body', { getReferenceClientRect: props.clientRect, appendTo: () => document.body,