Skip to content

Commit fadf806

Browse files
committed
Add fields docs
1 parent 411d855 commit fadf806

3 files changed

Lines changed: 130 additions & 84 deletions

File tree

docs/.vitepress/config.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,16 @@ function sidebar() {
7878
items: [
7979
{ text: 'SuperDoc', link: '/components/#superdoc' },
8080
{ text: 'SuperEditor', link: '/components/#supereditor' },
81-
{ text: 'Search', link: '/components/#search' },
82-
{ text: 'Toolbar', link: '/components/#superdoc-toolbar' },
8381
],
8482
},
8583
{
8684
text: 'Modules',
8785
link: '/modules',
8886
items: [
87+
{ text: 'Toolbar', link: '/modules/#superdoc-toolbar' },
8988
{ text: 'Comments', link: '/modules/#comments' },
89+
{ text: 'Search', link: '/modules/#search' },
90+
{ text: 'Fields', link: '/modules/#fields' },
9091
]
9192
},
9293
{

docs/src/components/index.md

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -204,89 +204,8 @@ SuperEditor has a variety of hooks
204204

205205
You can get a list of currently available commands from ```editor.commands```
206206

207-
# Search
208-
## SuperDoc extension
209-
210-
SuperDoc 0.11 adds a new .docx search feature.
211-
212-
### Usage
213-
Search works the same if you're using SuperDoc or the Editor instance directly.
214-
215-
```
216-
const superdoc = new SuperDoc({ ...myConfig });
217-
218-
// Text search
219-
const results = superdoc.search('My text search'); // An array of results
220-
// Or editor.commands.search('My text search');
221-
222-
// results = [
223-
// { from: 12, to: 24, text: 'My text search' },
224-
// …
225-
// ]
226-
227-
// Regex
228-
const regexResults = superdoc.search(/\b\w+ng\b/gi);
229-
// Or editor.commands.search('My text search');
230-
231-
// results = [
232-
// { from: 5, to: 13, text: 'painting' },
233-
// { from: 18, to: 28, text: 'preparing' },
234-
// …
235-
// ]
236-
```
237-
238-
### Commands
239-
superdoc.search(...)
240-
// Or editor.commands.search(...)
241-
242-
superdoc.goToSearchResult(match); // Pass in a match from the result of search()
243-
// Or editor.commands.goToSearchResult(match);
244-
245-
### Customization
246-
You can customize the color of the highlights from these styles:
247-
248-
```
249-
.ProseMirror-search-match
250-
.ProseMirror-active-search-match
251-
```
252-
253207
## Next Steps
254208

255209
- See [Integration](/integration/) for framework-specific integration guides
256210
- Check out [Resources](/resources/) for examples, FAQ, and community resources
257211
- Learn more about [Getting Started](/) for basic concepts and setup
258-
259-
## SuperDoc Toolbar {#superdoc-toolbar}
260-
261-
The **SuperDoc** will render into a DOM element of your choosing, allowing for full control of placement and styling over the toolbar.
262-
By default, we render a toolbar with all available buttons. You can customize this further by adding a `toolbar` object to the `modules` config in the **SuperDoc configuration** object.
263-
264-
## Customization
265-
266-
You can customize the toolbar configuration via the **SuperDoc config** object.
267-
268-
```
269-
const config = {
270-
// ... your SuperDoc config
271-
modules: {
272-
toolbar: {
273-
selector: 'superdoc-toolbar', // The ID of the DOM element you want to render the toolbar into
274-
275-
toolbarGroups: ['left', 'center', 'right'],
276-
277-
// Optional: Specify what toolbar buttons to render. Overrides toolbarGroups.
278-
groups: {
279-
center: ['bold', 'italic'],
280-
},
281-
282-
// Optional: Instead of specifying all the buttons you want, specify which ones to exclude
283-
excludeItems: ['bold', italic'], // Will exclude these from the standard toolbar
284-
285-
}
286-
}
287-
}
288-
```
289-
290-
### Default toolbar buttons
291-
See all buttons in defaultItems.js
292-

docs/src/modules/index.md

Lines changed: 127 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,52 @@ const config {
1818
}
1919
```
2020

21-
## Comments
21+
# Search
22+
23+
SuperDoc 0.11 adds a new .docx search feature.
24+
25+
### Usage
26+
Search works the same if you're using SuperDoc or the Editor instance directly.
27+
28+
```
29+
const superdoc = new SuperDoc({ ...myConfig });
30+
31+
// Text search
32+
const results = superdoc.search('My text search'); // An array of results
33+
// Or editor.commands.search('My text search');
34+
35+
// results = [
36+
// { from: 12, to: 24, text: 'My text search' },
37+
// …
38+
// ]
39+
40+
// Regex
41+
const regexResults = superdoc.search(/\b\w+ng\b/gi);
42+
// Or editor.commands.search('My text search');
43+
44+
// results = [
45+
// { from: 5, to: 13, text: 'painting' },
46+
// { from: 18, to: 28, text: 'preparing' },
47+
// …
48+
// ]
49+
```
50+
51+
### Commands
52+
superdoc.search(...)
53+
// Or editor.commands.search(...)
54+
55+
superdoc.goToSearchResult(match); // Pass in a match from the result of search()
56+
// Or editor.commands.goToSearchResult(match);
57+
58+
### Customization
59+
You can customize the color of the highlights from these styles:
60+
61+
```
62+
.ProseMirror-search-match
63+
.ProseMirror-active-search-match
64+
```
65+
66+
# Comments
2267

2368
The comments module can be added by adding the comments config to the modules.
2469

@@ -91,3 +136,84 @@ const myCommentsUpdateHandler = ({ type, comment meta }) => {
91136
};
92137
};
93138
```
139+
140+
## SuperDoc Toolbar {#superdoc-toolbar}
141+
142+
The **SuperDoc** will render into a DOM element of your choosing, allowing for full control of placement and styling over the toolbar.
143+
By default, we render a toolbar with all available buttons. You can customize this further by adding a `toolbar` object to the `modules` config in the **SuperDoc configuration** object.
144+
145+
## Customization
146+
147+
You can customize the toolbar configuration via the **SuperDoc config** object.
148+
149+
```
150+
const config = {
151+
// ... your SuperDoc config
152+
modules: {
153+
toolbar: {
154+
selector: 'superdoc-toolbar', // The ID of the DOM element you want to render the toolbar into
155+
156+
toolbarGroups: ['left', 'center', 'right'],
157+
158+
// Optional: Specify what toolbar buttons to render. Overrides toolbarGroups.
159+
groups: {
160+
center: ['bold', 'italic'],
161+
},
162+
163+
// Optional: Instead of specifying all the buttons you want, specify which ones to exclude
164+
excludeItems: ['bold', italic'], // Will exclude these from the standard toolbar
165+
166+
}
167+
}
168+
}
169+
```
170+
171+
### Default toolbar buttons
172+
See all buttons in defaultItems.js
173+
174+
# Fields
175+
176+
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)
177+
178+
Fields can be used when placeholder / variable content is needed inside the document. They can contain various types of data:
179+
- Plain text
180+
- HTML rich text
181+
- Images
182+
- Links
183+
- Checkboxes
184+
185+
## Commands
186+
```
187+
// Add a field annotation at the specified position
188+
// editorFocus = true will re-focus the editor after the command, in cases where it is not in focus (ie: drag and drop)
189+
addFieldAnnotation(pos, attrs = {}, editorFocus = false)
190+
191+
// Add a field annotation at the current selection
192+
// editorFocus = true will re-focus the editor after the command, in cases where it is not in focus (ie: drag and drop)
193+
addFieldAnnotationAtSelection(attrs = {}, editorFocus = false)
194+
```
195+
196+
## Field schema
197+
To create a field, we just pass in a JSON config to the addFieldAnnotationAtSelection command
198+
```
199+
const fieldTypes = ['text', 'image', 'signature', 'checkbox', 'html', 'link']
200+
const myField = {
201+
displayLabel: 'My placeholder field', // Placeholder text
202+
fieldId: MY_FIELD_ID, // The ID you'd like for this field
203+
type: 'html', // from fieldTypes
204+
fieldColor: '#000099', // Styling
205+
}
206+
207+
// Add the field to the editor
208+
addFieldAnnotationAtSelection(myField)
209+
```
210+
211+
## Drag-and-drop
212+
If you create a drag-and-drop system ([See this example](https://github.com/Harbour-Enterprises/SuperDoc/tree/main/examples/vue-fields-example)) for fields, you should listen for the Editor event 'fieldAnnotationDropped'.
213+
214+
Example:
215+
```
216+
superdoc.activeEditor.on('fieldAnnotationDropped', ({ sourceField }) => {
217+
superdoc.activeEditor.commands.addFieldAnnotationAtSelection(sourceField);
218+
});
219+
```

0 commit comments

Comments
 (0)