Selection in BlockSuite is a data model that represents the user's current selection state in the editor. It follows a unidirectional data flow pattern:
User interacts with the editor
Selection model is updated
View is rendered based on the selection state
Selection is a pure data model that describes what is currently selected
It's independent of how the selection is rendered
Changes to selection are managed through the selection extension
The model is synchronized across clients in collaborative scenarios
User Interaction → Selection Model Update → View Update
Keep the model focused on selection state
Use Zod for runtime validation
Ensure proper serialization
Update selection state through the extension
Handle selection lifecycle properly
Consider collaborative scenarios
Let the view layer handle rendering
Keep selection model independent of view
Use selection state to drive UI updates