@windoc/react 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +214 -0
- package/dist/index.js +395 -427
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +339 -371
- package/dist/index.mjs.map +1 -1
- package/package.json +27 -2
package/README.md
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/aliansyahFirdaus/windoc/main/docs/static/img/logo-text-white.png#gh-light-mode-only" alt="Windoc" height="120">
|
|
3
|
+
<img src="https://raw.githubusercontent.com/aliansyahFirdaus/windoc/main/docs/static/img/logo-text-black.png#gh-dark-mode-only" alt="Windoc" height="120">
|
|
4
|
+
</div>
|
|
5
|
+
|
|
6
|
+
# @windoc/react
|
|
7
|
+
|
|
8
|
+
React bindings for the [Windoc](https://www.npmjs.com/package/@windoc/core) canvas-based document editor. Provides a ready-to-use `<Editor />` component with a built-in toolbar, footer, and fully composable architecture.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
yarn add @windoc/react @windoc/core
|
|
14
|
+
# or
|
|
15
|
+
npm install @windoc/react @windoc/core
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
### Peer Dependencies
|
|
19
|
+
|
|
20
|
+
```json
|
|
21
|
+
{
|
|
22
|
+
"react": ">=18",
|
|
23
|
+
"react-dom": ">=18",
|
|
24
|
+
"lucide-react": ">=0.300.0"
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Quick Start
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
import { Editor } from '@windoc/react'
|
|
32
|
+
import '@windoc/core/style.css'
|
|
33
|
+
import '@windoc/react/style.css'
|
|
34
|
+
|
|
35
|
+
export default function App() {
|
|
36
|
+
return (
|
|
37
|
+
<Editor
|
|
38
|
+
defaultValue={{ main: [{ value: 'Hello, Windoc!' }] }}
|
|
39
|
+
options={{
|
|
40
|
+
margins: [40, 40, 40, 40],
|
|
41
|
+
placeholder: { data: 'Start typing...' },
|
|
42
|
+
}}
|
|
43
|
+
onReady={(editor) => console.log('Editor ready:', editor)}
|
|
44
|
+
onChange={(data) => console.log('Content changed:', data)}
|
|
45
|
+
className="editor"
|
|
46
|
+
style={{ flex: 1, minHeight: 0, overflow: 'auto' }}
|
|
47
|
+
/>
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Props
|
|
53
|
+
|
|
54
|
+
| Prop | Type | Default | Description |
|
|
55
|
+
|------|------|---------|-------------|
|
|
56
|
+
| `defaultValue` | `EditorData` | `{ main: [] }` | Initial document data |
|
|
57
|
+
| `options` | `EditorOptions` | `{}` | Editor configuration |
|
|
58
|
+
| `onChange` | `(data: object) => void` | — | Content change callback |
|
|
59
|
+
| `onReady` | `(editor: EditorInstance) => void` | — | Editor ready callback |
|
|
60
|
+
| `toolbar` | `boolean` | `true` | Show built-in toolbar |
|
|
61
|
+
| `footer` | `boolean` | `true` | Show built-in footer/statusbar |
|
|
62
|
+
| `renderToolbar` | `ReactNode` | — | Custom toolbar replacement |
|
|
63
|
+
| `renderFooter` | `ReactNode` | — | Custom footer replacement |
|
|
64
|
+
| `children` | `ReactNode` | — | Extra content inside EditorProvider |
|
|
65
|
+
| `className` | `string` | `'editor'` | CSS class for editor container |
|
|
66
|
+
| `style` | `CSSProperties` | — | Inline style for editor container |
|
|
67
|
+
| `onDrop` | `(e, editor) => void` | — | Drag-and-drop handler |
|
|
68
|
+
|
|
69
|
+
## Composable Architecture
|
|
70
|
+
|
|
71
|
+
Build your own toolbar or footer by composing individual tool components:
|
|
72
|
+
|
|
73
|
+
### Custom Toolbar
|
|
74
|
+
|
|
75
|
+
```tsx
|
|
76
|
+
import {
|
|
77
|
+
Editor,
|
|
78
|
+
EditorProvider,
|
|
79
|
+
UndoTool, RedoTool,
|
|
80
|
+
BoldTool, ItalicTool, UnderlineTool,
|
|
81
|
+
FontTool, FontSizeTool,
|
|
82
|
+
LeftAlignTool, CenterAlignTool, RightAlignTool,
|
|
83
|
+
TableTool, ImageTool,
|
|
84
|
+
} from '@windoc/react'
|
|
85
|
+
|
|
86
|
+
function MyToolbar() {
|
|
87
|
+
return (
|
|
88
|
+
<div className="my-toolbar">
|
|
89
|
+
<UndoTool />
|
|
90
|
+
<RedoTool />
|
|
91
|
+
<BoldTool />
|
|
92
|
+
<ItalicTool />
|
|
93
|
+
<UnderlineTool />
|
|
94
|
+
<FontTool />
|
|
95
|
+
<FontSizeTool />
|
|
96
|
+
<LeftAlignTool />
|
|
97
|
+
<CenterAlignTool />
|
|
98
|
+
<RightAlignTool />
|
|
99
|
+
<TableTool />
|
|
100
|
+
<ImageTool />
|
|
101
|
+
</div>
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export default function App() {
|
|
106
|
+
return (
|
|
107
|
+
<Editor
|
|
108
|
+
toolbar={false}
|
|
109
|
+
renderToolbar={<MyToolbar />}
|
|
110
|
+
/>
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Available Toolbar Tools
|
|
116
|
+
|
|
117
|
+
| Component | Description |
|
|
118
|
+
|-----------|-------------|
|
|
119
|
+
| `UndoTool` | Undo last action |
|
|
120
|
+
| `RedoTool` | Redo last action |
|
|
121
|
+
| `BoldTool` | Toggle bold |
|
|
122
|
+
| `ItalicTool` | Toggle italic |
|
|
123
|
+
| `UnderlineTool` | Toggle underline |
|
|
124
|
+
| `StrikeoutTool` | Toggle strikethrough |
|
|
125
|
+
| `ColorTool` | Text color picker |
|
|
126
|
+
| `HighlightTool` | Background highlight picker |
|
|
127
|
+
| `FontTool` | Font family selector |
|
|
128
|
+
| `FontSizeTool` | Font size selector |
|
|
129
|
+
| `TitleTool` | Heading level selector |
|
|
130
|
+
| `LineHeightTool` | Line height selector |
|
|
131
|
+
| `LeftAlignTool` | Align left |
|
|
132
|
+
| `CenterAlignTool` | Align center |
|
|
133
|
+
| `RightAlignTool` | Align right |
|
|
134
|
+
| `JustifyTool` | Justify text |
|
|
135
|
+
| `ListTool` | Ordered/unordered lists |
|
|
136
|
+
| `TableTool` | Insert table |
|
|
137
|
+
| `ImageTool` | Insert image |
|
|
138
|
+
| `ColumnTool` | Column layout |
|
|
139
|
+
| `SeparatorTool` | Horizontal separator |
|
|
140
|
+
| `PageBreakTool` | Page break |
|
|
141
|
+
| `WatermarkTool` | Watermark settings |
|
|
142
|
+
|
|
143
|
+
### Available Footer Tools
|
|
144
|
+
|
|
145
|
+
| Component | Description |
|
|
146
|
+
|-----------|-------------|
|
|
147
|
+
| `CatalogToggleTool` | Toggle document catalog/outline |
|
|
148
|
+
| `PageModeTool` | Switch page mode |
|
|
149
|
+
| `FooterStatus` | Page/word count status |
|
|
150
|
+
| `EditorModeTool` | Switch editor mode |
|
|
151
|
+
| `PageScaleMinusTool` | Zoom out |
|
|
152
|
+
| `PageScalePercentageTool` | Zoom percentage display |
|
|
153
|
+
| `PageScaleAddTool` | Zoom in |
|
|
154
|
+
| `PaperSizeTool` | Paper size selector |
|
|
155
|
+
| `PaperDirectionTool` | Paper orientation |
|
|
156
|
+
| `PaperMarginTool` | Paper margin settings |
|
|
157
|
+
| `FullscreenTool` | Toggle fullscreen |
|
|
158
|
+
| `EditorOptionTool` | Editor options |
|
|
159
|
+
| `WatermarkFooterTool` | Watermark toggle |
|
|
160
|
+
|
|
161
|
+
## Hooks
|
|
162
|
+
|
|
163
|
+
### `useEditor()`
|
|
164
|
+
|
|
165
|
+
Access the editor instance and selection state from any child component:
|
|
166
|
+
|
|
167
|
+
```tsx
|
|
168
|
+
import { useEditor } from '@windoc/react'
|
|
169
|
+
|
|
170
|
+
function MyComponent() {
|
|
171
|
+
const { editorRef, rangeStyle } = useEditor()
|
|
172
|
+
|
|
173
|
+
const handleClick = () => {
|
|
174
|
+
editorRef.current?.command.executeBold()
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return (
|
|
178
|
+
<button
|
|
179
|
+
onClick={handleClick}
|
|
180
|
+
className={rangeStyle?.bold ? 'active' : ''}
|
|
181
|
+
>
|
|
182
|
+
Bold
|
|
183
|
+
</button>
|
|
184
|
+
)
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### `useFooter()`
|
|
189
|
+
|
|
190
|
+
Access page/document metadata:
|
|
191
|
+
|
|
192
|
+
```tsx
|
|
193
|
+
import { useFooter } from '@windoc/react'
|
|
194
|
+
|
|
195
|
+
function StatusBar() {
|
|
196
|
+
const { pageNo, pageSize, wordCount, pageScale } = useFooter()
|
|
197
|
+
|
|
198
|
+
return (
|
|
199
|
+
<div>
|
|
200
|
+
Page {pageNo} of {pageSize} | {wordCount} words | {pageScale}%
|
|
201
|
+
</div>
|
|
202
|
+
)
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Types
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
import type { EditorInstance, RangeStylePayload, ICatalogItem, IComment } from '@windoc/react'
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## License
|
|
213
|
+
|
|
214
|
+
MIT
|