You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(document-api): return NodeAddress from find and getNode instead of SDAddress (SD-2168) (#2342)
* fix(document-api): return NodeAddress from find and getNode instead of SDAddress
SD-2168: find and getNode now return NodeAddress directly, making their
results compatible with mutation targets like create.paragraph. Removes
the toSDAddress conversion layer that stripped nodeType and changed
kind from 'block' to 'content', which made find results unusable for
positional inserts. Also adds docs for the query.match → create.paragraph
workflow.
* feat(document-api): adopt SDM/1 addressing model for find, insert, and replace
* fix(document-api): return canonical nodeId in getNodeById address
* chore: update docs
* fix: stale block address resolution and structural fragment schemas
Copy file name to clipboardExpand all lines: apps/docs/document-api/common-workflows.mdx
+36Lines changed: 36 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -101,6 +101,42 @@ if (target) {
101
101
}
102
102
```
103
103
104
+
## Find text and insert at position
105
+
106
+
Search for a heading (or any text) and insert a new paragraph relative to it:
107
+
108
+
```ts
109
+
// 1. Find the heading by text content
110
+
const match =editor.doc.query.match({
111
+
select: { type: 'text', pattern: 'Materials and methods' },
112
+
require: 'first',
113
+
});
114
+
115
+
const address =match.items?.[0]?.address;
116
+
if (!address) return;
117
+
118
+
// 2. Insert a paragraph after the heading
119
+
editor.doc.create.paragraph({
120
+
at: { kind: 'after', target: address },
121
+
text: 'New section content goes here.',
122
+
});
123
+
```
124
+
125
+
The `address` from `query.match` is a `BlockNodeAddress` that works directly with `create.paragraph`, `create.heading`, and `create.table`. Use `kind: 'before'` to insert before the matched node instead.
126
+
127
+
To insert as a tracked change, pass `changeMode: 'tracked'`:
Use `query.match` (not `find`) for this workflow. `query.match` returns `BlockNodeAddress` objects that are directly compatible with mutation targets.
138
+
</Info>
139
+
104
140
For direct single-operation calls, prefer `item.target`. For plans or multi-step edits, prefer `item.handle.ref` so every step reuses the same resolved match.
105
141
106
142
## Build a selection explicitly with ranges.resolve
Copy file name to clipboardExpand all lines: apps/docs/document-api/overview.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,7 +31,7 @@ For mutation targeting and `getNode(...)`, use `NodeAddress`:
31
31
}
32
32
```
33
33
34
-
`find(...)` returns SDM/1 `SDAddress` values (for example `kind: "content"`). For text selectors, `query.match(...)` returns deterministic mutation-ready data: `item.target` as a canonical `SelectionTarget`, `item.handle.ref` as a reusable resolved handle, and `item.address` as the matching `NodeAddress`.
34
+
`find(...)` returns `NodeAddress` values (for example `kind: "block"`). For text selectors, `query.match(...)` returns deterministic mutation-ready data: `item.target` as a canonical `SelectionTarget`, `item.handle.ref` as a reusable resolved handle, and `item.address` as the matching `NodeAddress`.
0 commit comments