Skip to content

@miy2/xml-api


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

ModelElement

engine

SyncEngine

config

SchemaViewConfig = {}

Returns

SchemaView

Methods

getDocument()

getDocument(): Document

Returns

Document


getModelNode()

getModelNode(viewNode): ModelNode

Parameters

viewNode

Node

Returns

ModelNode


getNodeByModelId()

getNodeByModelId(id): Node | null

Parameters

id

string

Returns

Node | null


getRoot()

getRoot(): Element

Returns

Element


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.
  • target nodes 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

ExternalNode

The root of the external DOM tree to sync from.

meta?

Record<string, any>

Optional metadata to attach to the generated transaction.

target?

Element

Optional specific element to reconcile (defaults to view root).

Returns

void