Skip to content
Anjunar/ DOCS

Custom node types

Applications extend Ember with typed nodes and separate adapters for storage, rendering and import.

Concept

Define and register

A node type describes identity, projection and validation. An Extension contributes it to the schema; a JSON codec, HTML semantics and view support are registered independently.

Inspect built-in nodes

The tree inspector reveals node IDs and types; your own type appears here after registration.

A paragraph with marks and an inline link.

9 words · 8 nodes
ember.core.root/1 [document] ember.rich-text.paragraph/1 [custom-node-types7] ember.core.text/1 [custom-node-types1] "A paragraph with " ember.core.text/1 [custom-node-types2] "marks" ember.core.text/1 [custom-node-types3] " and an inline " ember.link.link/1 [custom-node-types5] ember.core.text/1 [custom-node-types4] "link" ember.core.text/1 [custom-node-types6] "."
Source

Extension skeleton

Use a stable type ID for persisted data. The resolver checks duplicate types and missing dependencies before a session starts.

scala
final case class MentionNode(id: NodeId, userId: String) extends AtomNode object MentionNode extends NodeType[MentionNode]: val typeId = NodeTypeId("app.mention/1") def project(node: EditorNode): Option[MentionNode] = node match case mention: MentionNode => Some(mention) case _ => None def rekey(node: MentionNode, id: NodeId): MentionNode = node.copy(id = id) object MentionExtension extends Extension: val id = ExtensionId("app.mention") override def contribute = ExtensionContributions(nodeTypes = Vector(MentionNode)) // Add a NodeJsonCodec, HtmlSemantics and ViewSupport for this type.