Skip to content

Commit 966692d

Browse files
committed
docs: describe references
1 parent ac54f67 commit 966692d

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

adr/2025_06_13-document-transforms.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,48 @@ Right now all transformation functions are defined directly on the `Editor` inst
1818

1919
Instead, we should have a separate `Transform` class which defines methods that operate on the editor's document to make changes to it. This will also be very useful for doing server-side transformations.
2020

21+
```ts
22+
editor.transform.insertBlocks(ctx:{
23+
at: Location,
24+
blocks: Block | Block[]
25+
});
26+
27+
editor.transform.replaceBlocks(ctx: {
28+
at: Location,
29+
with: Block | Block[]
30+
})
31+
32+
editor.transform.replaceContent(ctx: {
33+
at: Location,
34+
with: InlineContent | InlineContent[]
35+
})
36+
37+
editor.transform.deleteContent(ctx: {
38+
at: Location,
39+
})
40+
```
41+
42+
## References
43+
44+
Currently, we do not have a good way to reference things about content within a document, except by block id. With Locations, we can be much more granular & more powerful.
45+
46+
I think one application of this would be to introduce the concept of "references" to content within a document. For example, we currently do not store comments into the blocknote json, taking the position that it really is not part of the document, but rather metadata about the document.
47+
48+
With references, we could store comments with references to the blocks that they are about. And map those references through changes if they are ever modified. For example, if someone commented on the text within block id `123`, and then the block was moved to a new location, we could update the comment to reference the new block id.
49+
50+
So, this would allow a comment to still be a separate entity, but be able to "hydrate" within the editor and keep track of the content that it was about.
51+
52+
```ts
53+
type Reference<Metadata extends Record<string, any>> = {
54+
to: Location,
55+
metadata: Metadata
56+
}
57+
58+
type Comment = Reference<{
59+
threadId: string
60+
}>
61+
62+
editor.references.add(reference: Reference, onUpdate: (reference: Reference) => void);
63+
```
64+
65+
This is inspired by [bluesky's concept of facets for rich text content](https://docs.bsky.app/docs/advanced-guides/post-richtext) which is a great example of how to make block note content more inter-operable between different applications.

0 commit comments

Comments
 (0)