Skip to content

Commit 3268659

Browse files
committed
Add annotate() documentation
1 parent 10036ff commit 3268659

2 files changed

Lines changed: 54 additions & 2 deletions

File tree

docs/.vitepress/config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ function sidebar() {
8888
{ text: 'Comments', link: '/modules/#comments' },
8989
{ text: 'Search', link: '/modules/#search' },
9090
{ text: 'Fields', link: '/modules/#fields' },
91+
{ text: 'Annotate', link: '/modules/#annotate' },
9192
]
9293
},
9394
{

docs/src/modules/index.md

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const config {
1818
}
1919
```
2020

21+
22+
2123
# Search
2224

2325
SuperDoc 0.11 adds a new .docx search feature.
@@ -63,6 +65,8 @@ You can customize the color of the highlights from these styles:
6365
.ProseMirror-active-search-match
6466
```
6567

68+
69+
6670
# Comments
6771

6872
The comments module can be added by adding the comments config to the modules.
@@ -171,6 +175,8 @@ const config = {
171175
### Default toolbar buttons
172176
See all buttons in defaultItems.js
173177

178+
179+
174180
# Fields
175181

176182
SuperDoc by default has the **fields** extension enabled. You can learn more about the [**Field Annotation** node here](https://github.com/Harbour-Enterprises/SuperDoc/blob/main/packages/super-editor/src/extensions/field-annotation/field-annotation.js)
@@ -221,9 +227,54 @@ Example:
221227
## Fields docx export
222228
SuperDoc supports full export and re-import of fields. By default, SuperDoc will not re-import document fields and will convert them to mustache style templates only.
223229

224-
To enable fields import simply add:
230+
To enable fields import simply add the below to your config when instantiating `new SuperDoc`
225231
```
226232
annotations: true
227233
```
228234

229-
To your SuperDoc config when instantiating with `new SuperDoc`
235+
236+
237+
238+
# Annotate
239+
240+
SuperDoc's editor instance (`superdoc.activeEditor`) exposes the `annotate()` function, allowing you to insert values into the Field nodes, either for preview or final document export.
241+
242+
### Usage
243+
244+
```ts
245+
type FieldValue = {
246+
input_id: string // The ID of the input field being annotated
247+
input_value: string // The value to insert into that field
248+
}
249+
250+
editor.annotate(
251+
fieldValues: FieldValue[], // Array of field annotations to insert or update
252+
hiddenFieldIds?: string[], // Optional array of field IDs to hide from the annotated view
253+
): void
254+
```
255+
256+
## Example use
257+
```
258+
editor.annotate(
259+
[
260+
{
261+
input_id: "name-123",
262+
input_value: "Alice Smith"
263+
},
264+
{
265+
input_id: "image-field-456",
266+
input_value: "http://some-image-url.jpg" // Images should be Object URLs (URL.createObjectURL) or base64
267+
}
268+
],
269+
["obsolete-field-id"]
270+
)
271+
```
272+
273+
## Exporting after annotate()
274+
If using annotate() to do field value replacement, and then exporting the `.docx` document via `superdoc.export()` the `.docx` file will be exported with the fields still in the document (rather than replacing the fields with their expected values, ie: for final document export).
275+
276+
You can pass in the `isFinalDoc` flag to export() in order to actually replace fields with their values, creating a seamless final document that contains no field objects.
277+
```
278+
Example:
279+
superdoc.export({ isFinalDoc: true })
280+
```

0 commit comments

Comments
 (0)