Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

Rmoved tippy - looks less impressive but it's much lighter.

Matt Roberts10832c3d27d4
diff --git a/package.json b/package.json
index 62b12d062..9b66d8984 100644
--- a/package.json
+++ b/package.json
@@ -19,7 +19,6 @@
"react-dom": "^18.3.1",
"react-textarea-autosize": "^8.5.4",
"react-toastify": "^9.0.1",
- "tippy.js": "^6.3.7",
"tiptap-markdown": "^0.8.10"
},
"devDependencies": {
diff --git a/public/components/common/form/suggestion.ts b/public/components/common/form/suggestion.ts
index 264c7a143..e3a0191c1 100644
--- a/public/components/common/form/suggestion.ts
+++ b/public/components/common/form/suggestion.ts
@@ -1,5 +1,4 @@
import { ReactRenderer } from "@tiptap/react"
-import tippy from "tippy.js"
import { actions } from "@fider/services"
import MentionList, { MentionListHandle } from "./MentionList"
@@ -8,10 +7,6 @@ interface MentionListProps {
items: any[]
command?: (item: MentionNodeAttrs) => void
}
-// interface ReactRendererOptions {
-// props: { editor: any; clientRect?: (() => DOMRect | null) | null }
-// editor: any
-// }
// Cache for storing users
let cachedUsers: MentionNodeAttrs[] = []
@@ -31,7 +26,10 @@ export default {
},
render: () => {
let reactRenderer: ReactRenderer<MentionListHandle, MentionListProps>
- let popup: any
+ let containerElement: HTMLElement | null = null
+ let scrollListener: EventListener | null = null
+ let clickOutsideListener: EventListener | null = null
+ let initialPosition: { top: number; left: number } | null = null
return {
onStart: (props: { editor: any; clientRect?: (() => DOMRect | null) | null }) => {
@@ -43,19 +41,62 @@ export default {
if (!props.clientRect) {
return
}
+ // Add click outside listener
+ clickOutsideListener = (event: Event) => {
+ if (event instanceof MouseEvent && containerElement && event.target instanceof Node && !containerElement.contains(event.target)) {
+ // Click was outside the container, clean up
+ if (scrollListener) {
+ window.removeEventListener("scroll", scrollListener)
+ }
+ if (clickOutsideListener) {
+ document.removeEventListener("click", clickOutsideListener)
+ }
+ if (containerElement && containerElement.parentNode) {
+ document.body.removeChild(containerElement)
+ containerElement = null
+ }
- popup = tippy(document.body, {
- getReferenceClientRect: props.clientRect as () => DOMRect,
- appendTo: () => document.body,
- content: reactRenderer.element,
- showOnCreate: true,
- interactive: true,
- trigger: "manual",
- placement: "bottom-start",
- })
+ // Important: Return focus to editor
+ props.editor.view.focus()
+ }
+ }
+ // Use setTimeout to avoid immediate trigger when creating the popup
+ setTimeout(() => {
+ document.addEventListener("click", clickOutsideListener as EventListener)
+ }, 100)
+
+ // Create container for the suggestion list
+ containerElement = document.createElement("div")
+ containerElement.style.position = "absolute"
+ containerElement.style.zIndex = "1000"
+ document.body.appendChild(containerElement)
+ containerElement.appendChild(reactRenderer.element)
+
+ // Get initial position
+ const rect = props.clientRect()
+ if (rect) {
+ // Store initial position relative to the document
+ initialPosition = {
+ top: rect.bottom + window.scrollY,
+ left: rect.left + window.scrollX,
+ }
+
+ // Set initial position
+ containerElement.style.left = `${initialPosition.left}px`
+ containerElement.style.top = `${initialPosition.top}px`
+ }
+
+ // Add scroll listener to maintain position during scrolling
+ scrollListener = () => {
+ if (containerElement && initialPosition) {
+ containerElement.style.top = `${initialPosition.top}px`
+ }
+ }
+
+ window.addEventListener("scroll", scrollListener, { passive: true })
},
onUpdate(props: { clientRect?: (() => DOMRect | null) | null | undefined }) {
- if (!props.clientRect) {
+ if (!props.clientRect || !containerElement) {
return
}
@@ -66,15 +107,26 @@ export default {
reactRenderer.updateProps(props)
- popup.setProps({
- getReferenceClientRect: props.clientRect,
- })
+ // Update position
+ initialPosition = {
+ top: rect.bottom + window.scrollY,
+ left: rect.left + window.scrollX,
+ }
+
+ containerElement.style.left = `${initialPosition.left}px`
+ containerElement.style.top = `${initialPosition.top}px`
},
onKeyDown(props: { event: KeyboardEvent }) {
- if (props.event.key === "Escape") {
- popup.hide()
+ console.log(props.event.key)
+ if (props.event.key === "Escape" && containerElement) {
+ // Clean up
+ if (scrollListener) {
+ window.removeEventListener("scroll", scrollListener)
+ }
+ document.body.removeChild(containerElement)
+ containerElement = null
return true
}
@@ -82,7 +134,18 @@ export default {
},
onExit() {
- popup.destroy()
+ if (containerElement) {
+ if (scrollListener) {
+ window.removeEventListener("scroll", scrollListener)
+ }
+ if (clickOutsideListener) {
+ document.removeEventListener("click", clickOutsideListener)
+ }
+
+ document.body.removeChild(containerElement)
+ containerElement = null
+ }
+
reactRenderer.destroy()
},
}