mirror of
https://github.com/linsa-io/linsa.git
synced 2026-04-27 02:38:45 +02:00
chore: Enhancement + New Feature (#185)
* wip * wip page * chore: style * wip pages * wip pages * chore: toggle * chore: link * feat: topic search * chore: page section * refactor: apply tailwind class ordering * fix: handle loggedIn user for guest route * feat: folder & image schema * chore: move utils to shared * refactor: tailwind class ordering * feat: img ext for editor * refactor: remove qa * fix: tanstack start * fix: wrong import * chore: use toast * chore: schema
This commit is contained in:
34
web/shared/editor/hooks/use-text-menu-states.ts
Normal file
34
web/shared/editor/hooks/use-text-menu-states.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import * as React from "react"
|
||||
import { Editor } from "@tiptap/react"
|
||||
import { ShouldShowProps } from "../types"
|
||||
import { isCustomNodeSelected, isTextSelected } from "../lib/utils"
|
||||
|
||||
export const useTextmenuStates = (editor: Editor) => {
|
||||
const shouldShow = React.useCallback(
|
||||
({ view, from }: ShouldShowProps) => {
|
||||
if (!view) {
|
||||
return false
|
||||
}
|
||||
|
||||
const domAtPos = view.domAtPos(from || 0).node as HTMLElement
|
||||
const nodeDOM = view.nodeDOM(from || 0) as HTMLElement
|
||||
const node = nodeDOM || domAtPos
|
||||
|
||||
if (isCustomNodeSelected(editor, node)) {
|
||||
return false
|
||||
}
|
||||
|
||||
return isTextSelected({ editor })
|
||||
},
|
||||
[editor],
|
||||
)
|
||||
|
||||
return {
|
||||
isBold: editor.isActive("bold"),
|
||||
isItalic: editor.isActive("italic"),
|
||||
isStrike: editor.isActive("strike"),
|
||||
isUnderline: editor.isActive("underline"),
|
||||
isCode: editor.isActive("code"),
|
||||
shouldShow,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user