Class: SchemaView
A filtered, schema-specific projection of the document.
The SchemaView provides a "view" of the underlying Model that only contains nodes relevant to a specific schema (e.g., XHTML). It hides "invisible" nodes (like comments, processing instructions, or tags not in the allowed list) but preserves them in the Model during updates.
This enables applications (like WYSIWYG editors) to work with a simplified DOM structure without destroying the full fidelity of the original source code.
Constructors
Constructor
new SchemaView(
model,engine,config):SchemaView
Parameters
model
engine
config
SchemaViewConfig = {}
Returns
SchemaView
Methods
getDocument()
getDocument():
Document
Returns
getModelNode()
getModelNode(
viewNode):ModelNode
Parameters
viewNode
Returns
getNodeByModelId()
getNodeByModelId(
id):Node|null
Parameters
id
string
Returns
Node | null
getRoot()
getRoot():
Element
Returns
on()
on(
handler): () =>void
Subscribes to changes in the view.
Events emitted here are "projected" events:
- They only fire for nodes visible in this view.
targetnodes are View nodes (wrappers), not raw Model nodes.- Structure events (
addedNodes/removedNodes) are filtered to exclude invisible nodes.
Parameters
handler
(event) => void
Function to handle the events.
Returns
Unsubscribe function.
():
void
Returns
void
reconcile()
reconcile(
externalDomNode,meta?,target?):void
Reconciles an external DOM tree (e.g., from a browser's contentEditable) with this view.
This method calculates the differences between the external tree and the current view, then applies minimal updates to the underlying Model. Crucially, it respects the "Invisible Node Preservation" rule: if the external tree is missing a node that is hidden in this view (like a comment), that node is preserved in the Model.
Parameters
externalDomNode
The root of the external DOM tree to sync from.
meta?
Record<string, any>
Optional metadata to attach to the generated transaction.
target?
Optional specific element to reconcile (defaults to view root).
Returns
void