SchemaContext (engine/model)
@ckeditor/ckeditor5-engine/src/model/schema
A schema context – a list of ancestors of a given position in the document.
Considering such position:
<$root>
<blockQuote>
<paragraph>
^
</paragraph>
</blockQuote>
</$root>
The context of this position is its lists of ancestors:
[ rootElement, blockQuoteElement, paragraphElement ]
Contexts are used in the Schema#checkChild
and
Schema#checkAttribute
events as a definition
of a place in the document where the check occurs. The context instances are created based on the first arguments
of the Schema#checkChild()
and
Schema#checkAttribute()
methods so when
using these methods you need to use SchemaContextDefinition
s.
Filtering
Properties
-
The last item (the lowest node).
-
The number of items.
Methods
-
constructor( context )
module:engine/model/schema~SchemaContext#constructor
-
Symbol.iterator() → IterableIterator<SchemaContextItem>
module:engine/model/schema~SchemaContext#Symbol.iterator
-
endsWith( query ) → boolean
module:engine/model/schema~SchemaContext#endsWith
Checks whether the context ends with the given nodes.
const ctx = new SchemaContext( [ rootElement, paragraphElement, textNode ] ); ctx.endsWith( '$text' ); // -> true ctx.endsWith( 'paragraph $text' ); // -> true ctx.endsWith( '$root' ); // -> false ctx.endsWith( 'paragraph' ); // -> false
Parameters
query : string
Returns
boolean
-
getItem( index ) → SchemaContextItem
module:engine/model/schema~SchemaContext#getItem
-
getNames() → IterableIterator<string>
module:engine/model/schema~SchemaContext#getNames
-
push( item ) → SchemaContext
module:engine/model/schema~SchemaContext#push
Returns a new schema context instance with an additional item.
Item can be added as:
const context = new SchemaContext( [ '$root' ] ); // An element. const fooElement = writer.createElement( 'fooElement' ); const newContext = context.push( fooElement ); // [ '$root', 'fooElement' ] // A text node. const text = writer.createText( 'foobar' ); const newContext = context.push( text ); // [ '$root', '$text' ] // A string (element name). const newContext = context.push( 'barElement' ); // [ '$root', 'barElement' ]
Note
Node
that is already in the model tree will be added as the only item (without ancestors).Parameters
item : string | Node
An item that will be added to the current context.
Returns
SchemaContext
A new schema context instance with an additional item.
-
startsWith( query ) → boolean
module:engine/model/schema~SchemaContext#startsWith
Checks whether the context starts with the given nodes.
const ctx = new SchemaContext( [ rootElement, paragraphElement, textNode ] ); ctx.endsWith( '$root' ); // -> true ctx.endsWith( '$root paragraph' ); // -> true ctx.endsWith( '$text' ); // -> false ctx.endsWith( 'paragraph' ); // -> false
Parameters
query : string
Returns
boolean
-
trimLast() → SchemaContext
module:engine/model/schema~SchemaContext#trimLast
Returns a new schema context that is based on this context but has the last item removed.
const ctxParagraph = new SchemaContext( [ '$root', 'blockQuote', 'paragraph' ] ); const ctxBlockQuote = ctxParagraph.trimLast(); // Items in `ctxBlockQuote` are: `$root` an `blockQuote`. const ctxRoot = ctxBlockQuote.trimLast(); // Items in `ctxRoot` are: `$root`.
Returns
SchemaContext
A new reduced schema context instance.
Every day, we work hard to keep our documentation complete. Have you spotted outdated information? Is something missing? Please report it via our issue tracker.
With the release of version 42.0.0, we have rewritten much of our documentation to reflect the new import paths and features. We appreciate your feedback to help us ensure its accuracy and completeness.