'use client' import * as React from 'react' import type { ContentEditorTextStyle } from '@admin/utils/editor/content-editor-text-style' import type { Editor } from '@tiptap/react' import { applyContentEditorTextStyle } from '@admin/utils/editor/apply-content-editor-text-style' import { getContentEditorTextStyle } from '@admin/utils/editor/get-content-editor-text-style' import { useEditorState } from '@tiptap/react' export function useContentEditorTextStyle(editor: Editor | null) { const activeStyle = useEditorState({ editor, selector: ({ editor: currentEditor }) => currentEditor ? getContentEditorTextStyle(currentEditor) : 'paragraph' }) const applyStyle = React.useCallback( (style: ContentEditorTextStyle) => { if (editor) applyContentEditorTextStyle(editor, style) }, [editor] ) return { activeStyle: activeStyle ?? 'paragraph', applyStyle } }