import {
useEffect as t,
useMemo as e,
useState as o,
createElement as r,
useContext as n,
} from "react"
import { useEditor as i, EditorContext as s, EditorContent as c } from "@tiptap/react"
export { useEditorState } from "@tiptap/react"
const d = {
bold: !1,
italic: !1,
strike: !1,
code: !1,
codeBlock: !1,
orderedList: !1,
bulletList: !1,
blockquote: !1,
},
a = Object.keys(d)
export { i as useEditor }
export const EditorProvider = ({ children: t, ...o }) => {
const n = i(o),
c = e(() => ({ value: { editor: n } }), [n])
return n ? r(s.Provider, c, t) : null
}
export const EditorContent = ({ className: t }) => {
const { editor: o } = useCurrentEditor(),
n = e(() => ({ editor: o, className: t }), [o, t])
return o ? r(c, n) : null
}
export const useCurrentEditor = () => n(s)
export const useEditorStyles = () => {
const { editor: e } = n(s),
[r, i] = o(d)
return (
t(() => {
if (!e) return void i(d)
const t = () => {
i((t) =>
a.reduce((o, r) => {
const n = e.isActive(r)
return n === t[r] ? o : { ...o, [r]: n }
}, t),
)
}
return (
e.on("selectionUpdate", t),
e.on("transaction", t),
() => {
;(e.off("selectionUpdate", t), e.off("transaction", t))
}
)
}, [e]),
{ styles: r }
)
}