ModelSchemaContext
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 ModelSchemaContextDefinitions.
Properties
last : ModelSchemaContextItemreadonlymodule:engine/model/schema~ModelSchemaContext#lastThe last item (the lowest node).
length : numberreadonlymodule:engine/model/schema~ModelSchemaContext#lengthThe number of items.
_items : Array<ModelSchemaContextItem>privatemodule:engine/model/schema~ModelSchemaContext#_items
Methods
constructor( context )module:engine/model/schema~ModelSchemaContext#constructorSymbol.iterator() → IterableIterator<ModelSchemaContextItem>module:engine/model/schema~ModelSchemaContext#Symbol.iteratorendsWith( query ) → booleanmodule:engine/model/schema~ModelSchemaContext#endsWithChecks whether the context ends with the given nodes.
const ctx = new ModelSchemaContext( [ rootElement, paragraphElement, textNode ] ); ctx.endsWith( '$text' ); // -> true ctx.endsWith( 'paragraph $text' ); // -> true ctx.endsWith( '$root' ); // -> false ctx.endsWith( 'paragraph' ); // -> falseCopy codeParameters
query : string
Returns
boolean
getItem( index ) → ModelSchemaContextItemmodule:engine/model/schema~ModelSchemaContext#getItemGets an item on the given index.
Parameters
index : number
Returns
getNames() → IterableIterator<string>module:engine/model/schema~ModelSchemaContext#getNamespush( item ) → ModelSchemaContextmodule:engine/model/schema~ModelSchemaContext#pushReturns a new schema context instance with an additional item.
Item can be added as:
const context = new ModelSchemaContext( [ '$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' ]Copy codeNote
ModelNodethat is already in the model tree will be added as the only item (without ancestors).Parameters
item : string | ModelNodeAn item that will be added to the current context.
Returns
ModelSchemaContextA new schema context instance with an additional item.
startsWith( query ) → booleanmodule:engine/model/schema~ModelSchemaContext#startsWithChecks whether the context starts with the given nodes.
const ctx = new ModelSchemaContext( [ rootElement, paragraphElement, textNode ] ); ctx.endsWith( '$root' ); // -> true ctx.endsWith( '$root paragraph' ); // -> true ctx.endsWith( '$text' ); // -> false ctx.endsWith( 'paragraph' ); // -> falseCopy codeParameters
query : string
Returns
boolean
module:engine/model/schema~ModelSchemaContext#trimLastReturns a new schema context that is based on this context but has the last item removed.
const ctxParagraph = new ModelSchemaContext( [ '$root', 'blockQuote', 'paragraph' ] ); const ctxBlockQuote = ctxParagraph.trimLast(); // Items in `ctxBlockQuote` are: `$root` an `blockQuote`. const ctxRoot = ctxBlockQuote.trimLast(); // Items in `ctxRoot` are: `$root`.Copy codeReturns
ModelSchemaContextA new reduced schema context instance.