Skip to main content

@windoc/react

React bindings for Windoc. Provides the <Editor /> component and composable toolbar/footer tools.

Installation​

npm install @windoc/react @windoc/core

Peer Dependencies​

  • react >= 18
  • react-dom >= 18
  • lucide-react >= 0.300.0

<Editor />​

The main component that renders the full editor.

import { Editor } from '@windoc/react'
import '@windoc/core/style.css'
import '@windoc/react/style.css'

Props​

PropTypeDefaultDescription
defaultValueEditorData{ main: [] }Initial document data
optionsEditorOptions{}Editor configuration
onChange(data: object) => void—Content change callback
onReady(editor: EditorInstance) => void—Editor ready callback
toolbarbooleantrueShow built-in toolbar
footerbooleantrueShow built-in footer
renderToolbarReactNode—Custom toolbar replacement
renderFooterReactNode—Custom footer replacement
childrenReactNode—Extra content inside EditorProvider
classNamestring'editor'CSS class for editor container
styleCSSProperties—Inline style for editor container
onDrop(e, editor) => void—Drag-and-drop handler

Hooks​

useEditor()​

Access the editor instance and current selection style from any child component.

import { useEditor } from '@windoc/react'

function MyTool() {
const { editorRef, rangeStyle } = useEditor()

return (
<button onClick={() => editorRef.current?.command.executeBold()}>
Bold: {rangeStyle?.bold ? 'ON' : 'OFF'}
</button>
)
}

Returns:

PropertyTypeDescription
editorRefMutableRefObject<EditorInstance | null>Ref to the editor instance
rangeStyleRangeStylePayload | nullCurrent selection's style state

useFooter()​

Access page and document metadata.

import { useFooter } from '@windoc/react'

function Status() {
const { pageNo, pageSize, wordCount, pageScale } = useFooter()
return <span>Page {pageNo}/{pageSize}</span>
}

Returns:

PropertyTypeDescription
pageNonumberCurrent page number
pageSizenumberTotal page count
wordCountnumberDocument word count
pageScalenumberCurrent zoom percentage
pageNoListstringVisible page numbers
rowNonumberCurrent row number
colNonumberCurrent column number

Providers​

<EditorProvider>​

Wraps components that need access to useEditor(). The <Editor /> component includes this automatically.

<FooterProvider>​

Wraps components that need access to useFooter(). The <Editor /> component includes this automatically.

Types​

import type {
EditorInstance,
RangeStylePayload,
ICatalogItem,
IComment,
} from '@windoc/react'