@docx-editor.dev/react 2.30.0 → 2.32.0

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 CHANGED
@@ -127,6 +127,30 @@ Read `isEnabled` to set the disabled state. Show `disabledReason` when the comma
127
127
  - [`@docx-editor.dev/editor-api`](https://www.npmjs.com/package/@docx-editor.dev/editor-api) — A supported subset of the Office.js API for server and browser editing
128
128
  - [`@docx-editor.dev/core`](https://www.npmjs.com/package/@docx-editor.dev/core) — the engine this adapter renders
129
129
 
130
+ ## Which API for which job
131
+
132
+ | Job | Use |
133
+ | --- | --- |
134
+ | Build a review UI in the browser | The React or Vue adapter hooks, plus the review hooks and `DocxEditorReview` from `@docx-editor.dev/pro/react` or `@docx-editor.dev/pro/vue`. |
135
+ | Edit in a headless, server, or agent pipeline | The editing API in `@docx-editor.dev/editor-api`, which follows the Office.js object model. |
136
+
137
+ | Task | Browser host (React or Vue) | Headless, server, or agent |
138
+ | --- | --- | --- |
139
+ | [Comment on found text](https://www.docx-editor.dev/docs/2.x/recipes/comment-on-found-text) | `editor.findMatches`, `editor.selectMatch`, then `useReview().comment` | `body.search`, then `Range.insertComment` |
140
+ | Reply to a thread | `useReview().reply(item, text)` | `Comment.reply(text)` |
141
+ | [Record a tracked replacement](https://www.docx-editor.dev/docs/2.x/recipes/tracked-replacement) | Suggesting mode, then `editor.exec({ type: 'replaceMatch', match, text })` | `document.changeTrackingMode = 'TrackMineOnly'`, then `Range.insertText(text, 'Replace')` |
142
+ | [Propose an AI rewrite as tracked changes](https://www.docx-editor.dev/docs/2.x/recipes/propose-rewrite) | The same code through `DocxEditor.createBrowser` from `@docx-editor.dev/editor-api/browser` | `prepareRewrite` from `@docx-editor.dev/editor-api/agent` |
143
+ | [Accept or reject a change](https://www.docx-editor.dev/docs/2.x/recipes/accept-reject-without-scrolling) | `useReview().accept(item)` or `useReview().reject(item)` | `Revision.accept()` or `Revision.reject()` |
144
+ | [Open or reveal a change without scrolling](https://www.docx-editor.dev/docs/2.x/recipes/accept-reject-without-scrolling) | `useReview().setActive(key, { reveal: false })` | Not applicable: no viewport |
145
+ | [Highlight ranges](https://www.docx-editor.dev/docs/2.x/recipes/highlight-ranges) | `useHighlights(name, source, options)` | Not applicable |
146
+ | [Custom review rail cards](https://www.docx-editor.dev/docs/2.x/recipes/custom-review-cards) | `DocxEditorReview` with `preset` set to `false`, `useReview().items`, `useStackedReviewPositions`, and `useReviewRailMetrics` | Not applicable |
147
+ | Comment-on-selection button | `DocxEditorReview.AddComment` as a direct child of `DocxEditorReview`, or `useEditorCommand('review.addComment')` | Not applicable |
148
+ | Page setup and paragraph dialogs from a custom toolbar | `DocxEditor.PageSetupDialog` or `DocxEditor.ParagraphDialog` with `open` and a close handler (`onClose` in React, `@close` in Vue); enable the button from `usePageSetup().isEnabled` or `useParagraphFormat().isEnabled` | `Section.pageSetup`, and `Paragraph` properties such as `alignment` |
149
+
150
+ The review hooks need `reviewModule()` from `@docx-editor.dev/pro` in the editor's modules, and an editor `author` for comments and tracked changes. The editing API takes its author from the `author` option of `DocxEditor.createServer`, imported from `@docx-editor.dev/editor-api`, or of `DocxEditor.createBrowser`, imported from `@docx-editor.dev/editor-api/browser`.
151
+
152
+ This package ships the task recipes in [`docs/index.md`](./docs/index.md). They are also on the site: [Task recipes](https://www.docx-editor.dev/docs/2.x/recipes).
153
+
130
154
  ## Documentation
131
155
 
132
156
  - [Quickstart](https://www.docx-editor.dev/docs/2.x/quickstart)
@@ -139,3 +163,50 @@ Read `isEnabled` to set the disabled state. Show `disabledReason` when the comma
139
163
  ## License
140
164
 
141
165
  Apache-2.0
166
+
167
+ ### Custom unsupported content
168
+
169
+ Register components under `DocxEditor` or `DocxEditor.Root`. Each declaration
170
+ handles matching unsupported content, including opaque inline and block elements.
171
+
172
+ ```tsx
173
+ <DocxEditor document={bytes}>
174
+ <DocxEditor.UnsupportedElement
175
+ match={(element) => element.namespaceUri === 'urn:my-widgets'}
176
+ layout={{ width: 180, height: 48 }}
177
+ >
178
+ {({ element }) => <MyWidget element={element} />}
179
+ </DocxEditor.UnsupportedElement>
180
+ <DocxEditor.UnsupportedElement>
181
+ {({ element }) => <MyPlaceholder label={element.label} />}
182
+ </DocxEditor.UnsupportedElement>
183
+ </DocxEditor>
184
+ ```
185
+
186
+ The first mounted matching declaration wins. Prop updates retain its priority.
187
+ Removing and mounting a declaration again gives it a later priority. To disable a
188
+ specific renderer temporarily, keep it mounted and change `match`, or use
189
+ matchers that do not overlap.
190
+ Omit `match` for a catch-all. Use source metadata in predicates; geometry is not
191
+ available before pagination. Return `null` to keep the default placeholder.
192
+ An empty result does not select the next declaration.
193
+
194
+ `UnsupportedElement` exposes `nodeId`, `ownerPartName`, `namespaceUri`,
195
+ `localName`, `source`, `placement`, and `label`. `bounds` describes the reserved
196
+ box after layout. Optional `drawing` and `equation` records provide specialized
197
+ metadata. Treat source content as read-only and untrusted.
198
+
199
+ `layout` reserves width and height in document points for opaque elements.
200
+ Source placement determines inline or block flow. Without `layout`, opaque
201
+ inline elements reserve 120 × 24 points; blocks reserve 240 × 96 points.
202
+ Dimensions must be positive, finite, and at most 100,000 points.
203
+ Drawing and equation fallbacks retain their existing geometry.
204
+ Unmatched opaque content retains its existing invisible behavior.
205
+ Properties, metadata, and nested payloads inside unsupported elements are not
206
+ independent content occurrences.
207
+
208
+ Components retain framework context and local state across same-page repaints.
209
+ They can remount when pagination, virtualization, or document changes remove an
210
+ occurrence. Keep durable application data outside the component.
211
+ Prop updates and declaration removal preserve document edits and undo history.
212
+ Custom rendering does not change saved DOCX content.