flotilla/src/app/editor/MentionNodeView.ts

29 lines
676 B
TypeScript
Raw Normal View History

import type {NodeViewProps} from "@tiptap/core"
2025-04-15 18:03:27 +00:00
import {deriveAliasDisplay} from "@app/state"
2025-04-15 18:03:27 +00:00
export const makeMentionNodeView =
(url?: string) =>
({node}: NodeViewProps) => {
const dom = document.createElement("span")
const display = deriveAliasDisplay(node.attrs.pubkey, url)
2025-04-15 18:03:27 +00:00
dom.classList.add("tiptap-object")
2025-04-15 18:03:27 +00:00
const unsubDisplay = display.subscribe($display => {
dom.textContent = "@" + $display
})
2025-04-15 18:03:27 +00:00
return {
dom,
destroy: () => {
unsubDisplay()
},
selectNode() {
dom.classList.add("tiptap-active")
},
deselectNode() {
dom.classList.remove("tiptap-active")
},
}
}