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) => voidContent change callback
onReady(editor: EditorInstance) => voidEditor ready callback
toolbarbooleantrueShow built-in toolbar
footerbooleantrueShow built-in footer
renderToolbarReactNodeCustom toolbar replacement
renderFooterReactNodeCustom footer replacement
childrenReactNodeExtra content inside EditorProvider
classNamestring'editor'CSS class for editor container
styleCSSPropertiesInline style for editor container
onDrop(e, editor) => voidDrag-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'