Trilium Frontend API
    Preparing search index...

    Class ModelSchema

    The model's schema. It defines the allowed and disallowed structures of nodes as well as nodes' attributes. The schema is usually defined by the features and based on them, the editing framework and features make decisions on how to change and process the model.

    The instance of schema is available in module:engine/model/model~Model#schema editor.model.schema.

    Read more about the schema in:

    • The {@glink framework/architecture/editing-engine#schema schema section} of the {@glink framework/architecture/editing-engine Introduction to the Editing engine architecture} guide.
    • The {@glink framework/deep-dive/schema Schema deep-dive} guide.

    Hierarchy (View Summary)

    Index

    Constructors

    • Creates a schema instance.

      Returns ModelSchema

    Methods

    • Allows registering a callback to the #checkAttribute method calls.

      Callbacks allow you to implement rules which are not otherwise possible to achieve by using the declarative API of module:engine/model/schema~ModelSchemaItemDefinition.

      Note that callback checks have bigger priority than declarative rules checks and may overwrite them.

      For example, by using this method you can disallow setting attributes on nodes in specific contexts:

      // Disallow setting `bold` on text inside `heading1` element:
      schema.addAttributeCheck( context => {
      if ( context.endsWith( 'heading1 $text' ) ) {
      return false;
      }
      }, 'bold' );

      You can skip the optional attributeName parameter to evaluate the callback for every checkAttribute() call.

      // Disallow formatting attributes on text inside custom `myTitle` element:
      schema.addAttributeCheck( ( context, attributeName ) => {
      if ( context.endsWith( 'myTitle $text' ) && schema.getAttributeProperties( attributeName ).isFormatting ) {
      return false;
      }
      } );

      Please note that the generic callbacks may affect the editor performance and should be avoided if possible.

      When one of the callbacks makes a decision (returns true or false) the processing is finished and other callbacks are not fired. Callbacks are fired in the order they were added, however generic callbacks are fired before callbacks added for a specified item.

      You can also use #event:checkAttribute event, if you need even better control. The result from the example above could also be achieved with following event callback:

      schema.on( 'checkAttribute', ( evt, args ) => {
      const context = args[ 0 ];
      const attributeName = args[ 1 ];

      if ( context.endsWith( 'myTitle $text' ) && schema.getAttributeProperties( attributeName ).isFormatting ) {
      // Prevent next listeners from being called.
      evt.stop();
      // Set the `checkAttribute()` return value.
      evt.return = false;
      }
      }, { priority: 'high' } );

      Note that the callback checks and declarative rules checks are processed on normal priority.

      Adding callbacks this way can also negatively impact editor performance.

      Parameters

      • callback: ModelSchemaAttributeCheckCallback

        The callback to be called. It is called with two parameters: module:engine/model/schema~ModelSchemaContext context and attribute name. The callback may return true or false, to override checkAttribute()'s return value. If it does not return a boolean value, the default algorithm (or other callbacks) will define checkAttribute()'s return value.

      • OptionalattributeName: string

        Name of the attribute for which the callback is registered. If specified, the callback will be run only for checkAttribute() calls with matching attributeName. Otherwise, the callback will run for every checkAttribute() call.

      Returns void

    • Allows registering a callback to the #checkChild method calls.

      Callbacks allow you to implement rules which are not otherwise possible to achieve by using the declarative API of module:engine/model/schema~ModelSchemaItemDefinition.

      Note that callback checks have bigger priority than declarative rules checks and may overwrite them.

      For example, by using this method you can disallow elements in specific contexts:

      // Disallow `heading1` inside a `blockQuote` that is inside a table.
      schema.addChildCheck( ( context, childDefinition ) => {
      if ( context.endsWith( 'tableCell blockQuote' ) ) {
      return false;
      }
      }, 'heading1' );

      You can skip the optional itemName parameter to evaluate the callback for every checkChild() call.

      // Inside specific custom element, allow only children, which allows for a specific attribute.
      schema.addChildCheck( ( context, childDefinition ) => {
      if ( context.endsWith( 'myElement' ) ) {
      return childDefinition.allowAttributes.includes( 'myAttribute' );
      }
      } );

      Please note that the generic callbacks may affect the editor performance and should be avoided if possible.

      When one of the callbacks makes a decision (returns true or false) the processing is finished and other callbacks are not fired. Callbacks are fired in the order they were added, however generic callbacks are fired before callbacks added for a specified item.

      You can also use checkChild event, if you need even better control. The result from the example above could also be achieved with following event callback:

      schema.on( 'checkChild', ( evt, args ) => {
      const context = args[ 0 ];
      const childDefinition = args[ 1 ];

      if ( context.endsWith( 'myElement' ) ) {
      // Prevent next listeners from being called.
      evt.stop();
      // Set the `checkChild()` return value.
      evt.return = childDefinition.allowAttributes.includes( 'myAttribute' );
      }
      }, { priority: 'high' } );

      Note that the callback checks and declarative rules checks are processed on normal priority.

      Adding callbacks this way can also negatively impact editor performance.

      Parameters

      • callback: ModelSchemaChildCheckCallback

        The callback to be called. It is called with two parameters: module:engine/model/schema~ModelSchemaContext (context) instance and module:engine/model/schema~ModelSchemaCompiledItemDefinition (definition). The callback may return true/false to override checkChild()'s return value. If it does not return a boolean value, the default algorithm (or other callbacks) will define checkChild()'s return value.

      • OptionalitemName: string

        Name of the schema item for which the callback is registered. If specified, the callback will be run only for checkChild() calls which def parameter matches the itemName. Otherwise, the callback will run for every checkChild call.

      Returns void

    • Binds #set observable properties to other objects implementing the module:utils/observablemixin~Observable interface.

      Read more in the {@glink framework/deep-dive/observables#property-bindings dedicated} guide covering the topic of property bindings with some additional examples.

      Consider two objects: a button and an associated command (both Observable).

      A simple property binding could be as follows:

      button.bind( 'isEnabled' ).to( command, 'isEnabled' );
      

      or even shorter:

      button.bind( 'isEnabled' ).to( command );
      

      which works in the following way:

      • button.isEnabled instantly equals command.isEnabled,
      • whenever command.isEnabled changes, button.isEnabled will immediately reflect its value.

      Note: To release the binding, use module:utils/observablemixin~Observable#unbind.

      You can also "rename" the property in the binding by specifying the new name in the to() chain:

      button.bind( 'isEnabled' ).to( command, 'isWorking' );
      

      It is possible to bind more than one property at a time to shorten the code:

      button.bind( 'isEnabled', 'value' ).to( command );
      

      which corresponds to:

      button.bind( 'isEnabled' ).to( command );
      button.bind( 'value' ).to( command );

      The binding can include more than one observable, combining multiple data sources in a custom callback:

      button.bind( 'isEnabled' ).to( command, 'isEnabled', ui, 'isVisible',
      ( isCommandEnabled, isUIVisible ) => isCommandEnabled && isUIVisible );

      Using a custom callback allows processing the value before passing it to the target property:

      button.bind( 'isEnabled' ).to( command, 'value', value => value === 'heading1' );
      

      It is also possible to bind to the same property in an array of observables. To bind a button to multiple commands (also Observables) so that each and every one of them must be enabled for the button to become enabled, use the following code:

      button.bind( 'isEnabled' ).toMany( [ commandA, commandB, commandC ], 'isEnabled',
      ( isAEnabled, isBEnabled, isCEnabled ) => isAEnabled && isBEnabled && isCEnabled );

      Type Parameters

      • K extends
            | "getDefinition"
            | "set"
            | "bind"
            | "unbind"
            | "decorate"
            | "on"
            | "once"
            | "off"
            | "listenTo"
            | "stopListening"
            | "fire"
            | "delegate"
            | "stopDelegating"
            | "register"
            | "extend"
            | "getDefinitions"
            | "isRegistered"
            | "isBlock"
            | "isLimit"
            | "isObject"
            | "isInline"
            | "isSelectable"
            | "isContent"
            | "checkChild"
            | "checkAttribute"
            | "checkMerge"
            | "addChildCheck"
            | "addAttributeCheck"
            | "setAttributeProperties"
            | "getAttributeProperties"
            | "getLimitElement"
            | "checkAttributeInSelection"
            | "getValidRanges"
            | "getNearestSelectionRange"
            | "findAllowedParent"
            | "setAllowedAttributes"
            | "removeDisallowedAttributes"
            | "getAttributesWithProperty"
            | "createContext"
            | "findOptimalInsertionRange"

      Parameters

      • bindProperty: K

        Observable property that will be bound to other observable(s).

      Returns ObservableSingleBindChain<K, ModelSchema[K]>

      The bind chain with the to() and toMany() methods.

      SINGLE_BIND

    • Binds #set observable properties to other objects implementing the module:utils/observablemixin~Observable interface.

      Read more in the {@glink framework/deep-dive/observables#property-bindings dedicated} guide covering the topic of property bindings with some additional examples.

      Consider two objects: a button and an associated command (both Observable).

      A simple property binding could be as follows:

      button.bind( 'isEnabled' ).to( command, 'isEnabled' );
      

      or even shorter:

      button.bind( 'isEnabled' ).to( command );
      

      which works in the following way:

      • button.isEnabled instantly equals command.isEnabled,
      • whenever command.isEnabled changes, button.isEnabled will immediately reflect its value.

      Note: To release the binding, use module:utils/observablemixin~Observable#unbind.

      You can also "rename" the property in the binding by specifying the new name in the to() chain:

      button.bind( 'isEnabled' ).to( command, 'isWorking' );
      

      It is possible to bind more than one property at a time to shorten the code:

      button.bind( 'isEnabled', 'value' ).to( command );
      

      which corresponds to:

      button.bind( 'isEnabled' ).to( command );
      button.bind( 'value' ).to( command );

      The binding can include more than one observable, combining multiple data sources in a custom callback:

      button.bind( 'isEnabled' ).to( command, 'isEnabled', ui, 'isVisible',
      ( isCommandEnabled, isUIVisible ) => isCommandEnabled && isUIVisible );

      Using a custom callback allows processing the value before passing it to the target property:

      button.bind( 'isEnabled' ).to( command, 'value', value => value === 'heading1' );
      

      It is also possible to bind to the same property in an array of observables. To bind a button to multiple commands (also Observables) so that each and every one of them must be enabled for the button to become enabled, use the following code:

      button.bind( 'isEnabled' ).toMany( [ commandA, commandB, commandC ], 'isEnabled',
      ( isAEnabled, isBEnabled, isCEnabled ) => isAEnabled && isBEnabled && isCEnabled );

      Type Parameters

      • K1 extends
            | "getDefinition"
            | "set"
            | "bind"
            | "unbind"
            | "decorate"
            | "on"
            | "once"
            | "off"
            | "listenTo"
            | "stopListening"
            | "fire"
            | "delegate"
            | "stopDelegating"
            | "register"
            | "extend"
            | "getDefinitions"
            | "isRegistered"
            | "isBlock"
            | "isLimit"
            | "isObject"
            | "isInline"
            | "isSelectable"
            | "isContent"
            | "checkChild"
            | "checkAttribute"
            | "checkMerge"
            | "addChildCheck"
            | "addAttributeCheck"
            | "setAttributeProperties"
            | "getAttributeProperties"
            | "getLimitElement"
            | "checkAttributeInSelection"
            | "getValidRanges"
            | "getNearestSelectionRange"
            | "findAllowedParent"
            | "setAllowedAttributes"
            | "removeDisallowedAttributes"
            | "getAttributesWithProperty"
            | "createContext"
            | "findOptimalInsertionRange"
      • K2 extends
            | "getDefinition"
            | "set"
            | "bind"
            | "unbind"
            | "decorate"
            | "on"
            | "once"
            | "off"
            | "listenTo"
            | "stopListening"
            | "fire"
            | "delegate"
            | "stopDelegating"
            | "register"
            | "extend"
            | "getDefinitions"
            | "isRegistered"
            | "isBlock"
            | "isLimit"
            | "isObject"
            | "isInline"
            | "isSelectable"
            | "isContent"
            | "checkChild"
            | "checkAttribute"
            | "checkMerge"
            | "addChildCheck"
            | "addAttributeCheck"
            | "setAttributeProperties"
            | "getAttributeProperties"
            | "getLimitElement"
            | "checkAttributeInSelection"
            | "getValidRanges"
            | "getNearestSelectionRange"
            | "findAllowedParent"
            | "setAllowedAttributes"
            | "removeDisallowedAttributes"
            | "getAttributesWithProperty"
            | "createContext"
            | "findOptimalInsertionRange"

      Parameters

      • bindProperty1: K1

        Observable property that will be bound to other observable(s).

      • bindProperty2: K2

        Observable property that will be bound to other observable(s).

      Returns ObservableDualBindChain<K1, ModelSchema[K1], K2, ModelSchema[K2]>

      The bind chain with the to() and toMany() methods.

      DUAL_BIND

    • Binds #set observable properties to other objects implementing the module:utils/observablemixin~Observable interface.

      Read more in the {@glink framework/deep-dive/observables#property-bindings dedicated} guide covering the topic of property bindings with some additional examples.

      Consider two objects: a button and an associated command (both Observable).

      A simple property binding could be as follows:

      button.bind( 'isEnabled' ).to( command, 'isEnabled' );
      

      or even shorter:

      button.bind( 'isEnabled' ).to( command );
      

      which works in the following way:

      • button.isEnabled instantly equals command.isEnabled,
      • whenever command.isEnabled changes, button.isEnabled will immediately reflect its value.

      Note: To release the binding, use module:utils/observablemixin~Observable#unbind.

      You can also "rename" the property in the binding by specifying the new name in the to() chain:

      button.bind( 'isEnabled' ).to( command, 'isWorking' );
      

      It is possible to bind more than one property at a time to shorten the code:

      button.bind( 'isEnabled', 'value' ).to( command );
      

      which corresponds to:

      button.bind( 'isEnabled' ).to( command );
      button.bind( 'value' ).to( command );

      The binding can include more than one observable, combining multiple data sources in a custom callback:

      button.bind( 'isEnabled' ).to( command, 'isEnabled', ui, 'isVisible',
      ( isCommandEnabled, isUIVisible ) => isCommandEnabled && isUIVisible );

      Using a custom callback allows processing the value before passing it to the target property:

      button.bind( 'isEnabled' ).to( command, 'value', value => value === 'heading1' );
      

      It is also possible to bind to the same property in an array of observables. To bind a button to multiple commands (also Observables) so that each and every one of them must be enabled for the button to become enabled, use the following code:

      button.bind( 'isEnabled' ).toMany( [ commandA, commandB, commandC ], 'isEnabled',
      ( isAEnabled, isBEnabled, isCEnabled ) => isAEnabled && isBEnabled && isCEnabled );

      Parameters

      • ...bindProperties: (
            | "getDefinition"
            | "set"
            | "bind"
            | "unbind"
            | "decorate"
            | "on"
            | "once"
            | "off"
            | "listenTo"
            | "stopListening"
            | "fire"
            | "delegate"
            | "stopDelegating"
            | "register"
            | "extend"
            | "getDefinitions"
            | "isRegistered"
            | "isBlock"
            | "isLimit"
            | "isObject"
            | "isInline"
            | "isSelectable"
            | "isContent"
            | "checkChild"
            | "checkAttribute"
            | "checkMerge"
            | "addChildCheck"
            | "addAttributeCheck"
            | "setAttributeProperties"
            | "getAttributeProperties"
            | "getLimitElement"
            | "checkAttributeInSelection"
            | "getValidRanges"
            | "getNearestSelectionRange"
            | "findAllowedParent"
            | "setAllowedAttributes"
            | "removeDisallowedAttributes"
            | "getAttributesWithProperty"
            | "createContext"
            | "findOptimalInsertionRange"
        )[]

        Observable properties that will be bound to other observable(s).

      Returns ObservableMultiBindChain

      The bind chain with the to() and toMany() methods.

      MANY_BIND

    • Checks whether the given attribute can be applied in the given context (on the last item of the context).

      schema.checkAttribute( textNode, 'bold' ); // -> false

      schema.extend( '$text', {
      allowAttributes: 'bold'
      } );

      schema.checkAttribute( textNode, 'bold' ); // -> true

      Both module:engine/model/schema~ModelSchema#addAttributeCheck callback checks and declarative rules (added when module:engine/model/schema~ModelSchema#register registering and module:engine/model/schema~ModelSchema#extend extending items) are evaluated when this method is called.

      Note that callback checks have bigger priority than declarative rules checks and may overwrite them.

      Parameters

      • context: ModelSchemaContextDefinition

        The context in which the attribute will be checked.

      • attributeName: string

        Name of attribute to check in the given context.

      Returns boolean

      checkAttribute

    • Checks whether the attribute is allowed in selection:

      • if the selection is not collapsed, then checks if the attribute is allowed on any of nodes in that range,
      • if the selection is collapsed, then checks if on the selection position there's a text with the specified attribute allowed.

      Parameters

      Returns boolean

    • Checks whether the given node can be a child of the given context.

      schema.checkChild( model.document.getRoot(), paragraph ); // -> false

      schema.register( 'paragraph', {
      allowIn: '$root'
      } );

      schema.checkChild( model.document.getRoot(), paragraph ); // -> true

      Both module:engine/model/schema~ModelSchema#addChildCheck callback checks and declarative rules (added when module:engine/model/schema~ModelSchema#register registering and module:engine/model/schema~ModelSchema#extend extending items) are evaluated when this method is called.

      Note that callback checks have bigger priority than declarative rules checks and may overwrite them.

      Note that when verifying whether the given node can be a child of the given context, the schema also verifies the entire context – from its root to its last element. Therefore, it is possible for checkChild() to return false even though the context last element can contain the checked child. It happens if one of the context elements does not allow its child. When context is verified, module:engine/model/schema~ModelSchema#addChildCheck custom checks are considered as well.

      Parameters

      Returns boolean

      checkChild

    • Parameters

      Returns boolean

    • Parameters

      Returns boolean

    • Turns the given methods of this object into event-based ones. This means that the new method will fire an event (named after the method) and the original action will be plugged as a listener to that event.

      Read more in the {@glink framework/deep-dive/observables#decorating-object-methods dedicated} guide covering the topic of decorating methods with some additional examples.

      Decorating the method does not change its behavior (it only adds an event), but it allows to modify it later on by listening to the method's event.

      For example, to cancel the method execution the event can be module:utils/eventinfo~EventInfo#stop stopped:

      class Foo extends ObservableMixin() {
      constructor() {
      super();
      this.decorate( 'method' );
      }

      method() {
      console.log( 'called!' );
      }
      }

      const foo = new Foo();
      foo.on( 'method', ( evt ) => {
      evt.stop();
      }, { priority: 'high' } );

      foo.method(); // Nothing is logged.

      Note: The high module:utils/priorities~PriorityString priority listener has been used to execute this particular callback before the one which calls the original method (which uses the "normal" priority).

      It is also possible to change the returned value:

      foo.on( 'method', ( evt ) => {
      evt.return = 'Foo!';
      } );

      foo.method(); // -> 'Foo'

      Finally, it is possible to access and modify the arguments the method is called with:

      method( a, b ) {
      console.log( `${ a }, ${ b }` );
      }

      // ...

      foo.on( 'method', ( evt, args ) => {
      args[ 0 ] = 3;

      console.log( args[ 1 ] ); // -> 2
      }, { priority: 'high' } );

      foo.method( 1, 2 ); // -> '3, 2'

      Parameters

      • methodName:
            | "getDefinition"
            | "set"
            | "bind"
            | "unbind"
            | "decorate"
            | "on"
            | "once"
            | "off"
            | "listenTo"
            | "stopListening"
            | "fire"
            | "delegate"
            | "stopDelegating"
            | "register"
            | "extend"
            | "getDefinitions"
            | "isRegistered"
            | "isBlock"
            | "isLimit"
            | "isObject"
            | "isInline"
            | "isSelectable"
            | "isContent"
            | "checkChild"
            | "checkAttribute"
            | "checkMerge"
            | "addChildCheck"
            | "addAttributeCheck"
            | "setAttributeProperties"
            | "getAttributeProperties"
            | "getLimitElement"
            | "checkAttributeInSelection"
            | "getValidRanges"
            | "getNearestSelectionRange"
            | "findAllowedParent"
            | "setAllowedAttributes"
            | "removeDisallowedAttributes"
            | "getAttributesWithProperty"
            | "createContext"
            | "findOptimalInsertionRange"

        Name of the method to decorate.

      Returns void

    • Delegates selected events to another module:utils/emittermixin~Emitter. For instance:

      emitterA.delegate( 'eventX' ).to( emitterB );
      emitterA.delegate( 'eventX', 'eventY' ).to( emitterC );

      then eventX is delegated (fired by) emitterB and emitterC along with data:

      emitterA.fire( 'eventX', data );
      

      and eventY is delegated (fired by) emitterC along with data:

      emitterA.fire( 'eventY', data );
      

      Parameters

      • ...events: string[]

        Event names that will be delegated to another emitter.

      Returns EmitterMixinDelegateChain

    • Extends a #register registered item's definition.

      Extending properties such as allowIn will add more items to the existing properties, while redefining properties such as isBlock will override the previously defined ones.

      schema.register( 'foo', {
      allowIn: '$root',
      isBlock: true;
      } );
      schema.extend( 'foo', {
      allowIn: 'blockQuote',
      isBlock: false
      } );

      schema.getDefinition( 'foo' );
      // {
      // allowIn: [ '$root', 'blockQuote' ],
      // isBlock: false
      // }

      Parameters

      Returns void

    • Tries to find position ancestors that allow to insert a given node. It starts searching from the given position and goes node by node to the top of the model tree as long as a module:engine/model/schema~ModelSchema#isLimit limit element, an module:engine/model/schema~ModelSchema#isObject object element or a topmost ancestor is not reached.

      Parameters

      • position: ModelPosition

        The position that the search will start from.

      • node: string | ModelNode

        The node for which an allowed parent should be found or its name.

      Returns ModelElement

      Allowed parent or null if nothing was found.

    • Internal

      Returns a model range which is optimal (in terms of UX) for inserting a widget block.

      For instance, if a selection is in the middle of a paragraph, the collapsed range before this paragraph will be returned so that it is not split. If the selection is at the end of a paragraph, the collapsed range after this paragraph will be returned.

      Note: If the selection is placed in an empty block, the range in that block will be returned. If that range is then passed to module:engine/model/model~Model#insertContent, the block will be fully replaced by the inserted widget block.

      Parameters

      • selection: ModelSelection | ModelDocumentSelection

        The selection based on which the insertion position should be calculated.

      • Optionalplace: "before" | "after" | "auto"

        The place where to look for optimal insertion range. The auto value will determine itself the best position for insertion. The before value will try to find a position before selection. The after value will try to find a position after selection.

      Returns ModelRange

      The optimal range.

    • Fires an event, executing all callbacks registered for it.

      The first parameter passed to callbacks is an module:utils/eventinfo~EventInfo object, followed by the optional args provided in the fire() method call.

      Type Parameters

      • TEvent extends BaseEvent

        The type describing the event. See module:utils/emittermixin~BaseEvent.

      Parameters

      • eventOrInfo: GetNameOrEventInfo<TEvent>

        The name of the event or EventInfo object if event is delegated.

      • ...args: TEvent["args"]

        Additional arguments to be passed to the callbacks.

      Returns GetEventInfo<TEvent>["return"]

      By default the method returns undefined. However, the return value can be changed by listeners through modification of the module:utils/eventinfo~EventInfo#return evt.return's property (the event info is the first param of every callback).

    • Returns properties associated with a given model attribute. See #setAttributeProperties setAttributeProperties().

      Parameters

      • attributeName: string

        A name of the attribute.

      Returns ModelAttributeProperties

    • Gets attributes of a node that have a given property.

      Parameters

      • node: ModelNode

        Node to get attributes from.

      • propertyName: string

        Name of the property that attribute must have to return it.

      • propertyValue: unknown

        Desired value of the property that we want to check. When undefined attributes will be returned if they have set a given property no matter what the value is. If specified it will return attributes which given property's value is equal to this parameter.

      Returns Record<string, unknown>

      Object with attributes' names as key and attributes' values as value.

    • Returns data of all registered items.

      This method should normally be used for reflection purposes (e.g. defining a clone of a certain element, checking a list of all block elements, etc). Use specific methods (such as #checkChild checkChild() or #isLimit isLimit()) in other cases.

      Returns Record<string, ModelSchemaCompiledItemDefinition>

    • Basing on given position, finds and returns a module:engine/model/range~ModelRange range which is nearest to that position and is a correct range for selection.

      The correct selection range might be collapsed when it is located in a position where the text node can be placed. Non-collapsed range is returned when selection can be placed around element marked as an "object" in the module:engine/model/schema~ModelSchema schema.

      Direction of searching for the nearest correct selection range can be specified as:

      • both - searching will be performed in both ways,
      • forward - searching will be performed only forward,
      • backward - searching will be performed only backward.

      When valid selection range cannot be found, null is returned.

      Parameters

      • position: ModelPosition

        Reference position where new selection range should be looked for.

      • Optionaldirection: "both" | "forward" | "backward"

        Search direction.

      Returns ModelRange

      Nearest selection range or null if one cannot be found.

    • Transforms the given set of ranges into a set of ranges where the given attribute is allowed (and can be applied).

      Parameters

      • ranges: Iterable<ModelRange>

        Ranges to be validated.

      • attribute: string

        The name of the attribute to check.

      Returns IterableIterator<ModelRange>

      Ranges in which the attribute is allowed.

    • Returns true if the given item is defined to be a block by the module:engine/model/schema~ModelSchemaItemDefinition's isBlock property.

      schema.isBlock( 'paragraph' ); // -> true
      schema.isBlock( '$root' ); // -> false

      const paragraphElement = writer.createElement( 'paragraph' );
      schema.isBlock( paragraphElement ); // -> true

      See the {@glink framework/deep-dive/schema#block-elements Block elements} section of the {@glink framework/deep-dive/schema Schema deep-dive} guide for more details.

      Returns boolean

    • Returns true if the given item is defined to be a content by the module:engine/model/schema~ModelSchemaItemDefinition's isContent property.

      schema.isContent( 'paragraph' ); // -> false
      schema.isContent( 'heading1' ); // -> false
      schema.isContent( 'imageBlock' ); // -> true
      schema.isContent( 'horizontalLine' ); // -> true

      const text = writer.createText( 'foo' );
      schema.isContent( text ); // -> true

      See the {@glink framework/deep-dive/schema#content-elements Content elements section} of the {@glink framework/deep-dive/schema Schema deep-dive} guide for more details.

      Returns boolean

    • Returns true if the given item is defined to be an inline element by the module:engine/model/schema~ModelSchemaItemDefinition's isInline property.

      schema.isInline( 'paragraph' ); // -> false
      schema.isInline( 'softBreak' ); // -> true

      const text = writer.createText( 'foo' );
      schema.isInline( text ); // -> true

      See the {@glink framework/deep-dive/schema#inline-elements Inline elements} section of the {@glink framework/deep-dive/schema Schema deep-dive} guide for more details.

      Returns boolean

    • Returns true if the given item should be treated as a limit element.

      It considers an item to be a limit element if its module:engine/model/schema~ModelSchemaItemDefinition's module:engine/model/schema~ModelSchemaItemDefinition#isLimit isLimit or module:engine/model/schema~ModelSchemaItemDefinition#isObject isObject property was set to true.

      schema.isLimit( 'paragraph' ); // -> false
      schema.isLimit( '$root' ); // -> true
      schema.isLimit( editor.model.document.getRoot() ); // -> true
      schema.isLimit( 'imageBlock' ); // -> true

      See the {@glink framework/deep-dive/schema#limit-elements Limit elements} section of the {@glink framework/deep-dive/schema Schema deep-dive} guide for more details.

      Returns boolean

    • Returns true if the given item should be treated as an object element.

      It considers an item to be an object element if its module:engine/model/schema~ModelSchemaItemDefinition's module:engine/model/schema~ModelSchemaItemDefinition#isObject isObject property was set to true.

      schema.isObject( 'paragraph' ); // -> false
      schema.isObject( 'imageBlock' ); // -> true

      const imageElement = writer.createElement( 'imageBlock' );
      schema.isObject( imageElement ); // -> true

      See the {@glink framework/deep-dive/schema#object-elements Object elements} section of the {@glink framework/deep-dive/schema Schema deep-dive} guide for more details.

      Returns boolean

    • Returns true if the given item is registered in the schema.

      schema.isRegistered( 'paragraph' ); // -> true
      schema.isRegistered( editor.model.document.getRoot() ); // -> true
      schema.isRegistered( 'foo' ); // -> false

      Returns boolean

    • Returns true if the given item is defined to be a selectable element by the module:engine/model/schema~ModelSchemaItemDefinition's isSelectable property.

      schema.isSelectable( 'paragraph' ); // -> false
      schema.isSelectable( 'heading1' ); // -> false
      schema.isSelectable( 'imageBlock' ); // -> true
      schema.isSelectable( 'tableCell' ); // -> true

      const text = writer.createText( 'foo' );
      schema.isSelectable( text ); // -> false

      See the {@glink framework/deep-dive/schema#selectable-elements Selectable elements section} of the {@glink framework/deep-dive/schema Schema deep-dive} guide for more details.

      Returns boolean

    • Registers a callback function to be executed when an event is fired in a specific (emitter) object.

      Events can be grouped in namespaces using :. When namespaced event is fired, it additionally fires all callbacks for that namespace.

      // myEmitter.on( ... ) is a shorthand for myEmitter.listenTo( myEmitter, ... ).
      myEmitter.on( 'myGroup', genericCallback );
      myEmitter.on( 'myGroup:myEvent', specificCallback );

      // genericCallback is fired.
      myEmitter.fire( 'myGroup' );
      // both genericCallback and specificCallback are fired.
      myEmitter.fire( 'myGroup:myEvent' );
      // genericCallback is fired even though there are no callbacks for "foo".
      myEmitter.fire( 'myGroup:foo' );

      An event callback can module:utils/eventinfo~EventInfo#stop stop the event and set the module:utils/eventinfo~EventInfo#return return value of the #fire method.

      Type Parameters

      • TEvent extends BaseEvent

        The type describing the event. See module:utils/emittermixin~BaseEvent.

      Parameters

      Returns void

      BASE_EMITTER

    • Stops executing the callback on the given event. Shorthand for #stopListening this.stopListening( this, event, callback ).

      Parameters

      • event: string

        The name of the event.

      • callback: Function

        The function to stop being called.

      Returns void

    • Registers a callback function to be executed when an event is fired.

      Shorthand for #listenTo this.listenTo( this, event, callback, options ) (it makes the emitter listen on itself).

      Type Parameters

      • TEvent extends BaseEvent

        The type descibing the event. See module:utils/emittermixin~BaseEvent.

      Parameters

      Returns void

    • Registers a callback function to be executed on the next time the event is fired only. This is similar to calling #on followed by #off in the callback.

      Type Parameters

      • TEvent extends BaseEvent

        The type descibing the event. See module:utils/emittermixin~BaseEvent.

      Parameters

      Returns void

    • Registers a schema item. Can only be called once for every item name.

      schema.register( 'paragraph', {
      inheritAllFrom: '$block'
      } );

      Parameters

      Returns void

    • Removes attributes disallowed by the schema.

      Parameters

      Returns void

    • Creates and sets the value of an observable property of this object. Such a property becomes a part of the state and is observable.

      This method throws the observable-set-cannot-override error if the observable instance already has a property with the given property name. This prevents from mistakenly overriding existing properties and methods, but means that foo.set( 'bar', 1 ) may be slightly slower than foo.bar = 1.

      In TypeScript, those properties should be declared in class using declare keyword. In example:

      public declare myProp: number;

      constructor() {
      this.set( 'myProp', 2 );
      }

      Type Parameters

      • K extends
            | "getDefinition"
            | "set"
            | "bind"
            | "unbind"
            | "decorate"
            | "on"
            | "once"
            | "off"
            | "listenTo"
            | "stopListening"
            | "fire"
            | "delegate"
            | "stopDelegating"
            | "register"
            | "extend"
            | "getDefinitions"
            | "isRegistered"
            | "isBlock"
            | "isLimit"
            | "isObject"
            | "isInline"
            | "isSelectable"
            | "isContent"
            | "checkChild"
            | "checkAttribute"
            | "checkMerge"
            | "addChildCheck"
            | "addAttributeCheck"
            | "setAttributeProperties"
            | "getAttributeProperties"
            | "getLimitElement"
            | "checkAttributeInSelection"
            | "getValidRanges"
            | "getNearestSelectionRange"
            | "findAllowedParent"
            | "setAllowedAttributes"
            | "removeDisallowedAttributes"
            | "getAttributesWithProperty"
            | "createContext"
            | "findOptimalInsertionRange"

      Parameters

      • name: K

        The property's name.

      • value: ModelSchema[K]

        The property's value.

      Returns void

      KEY_VALUE

    • Creates and sets the value of an observable properties of this object. Such a property becomes a part of the state and is observable.

      It accepts a single object literal containing key/value pairs with properties to be set.

      This method throws the observable-set-cannot-override error if the observable instance already has a property with the given property name. This prevents from mistakenly overriding existing properties and methods, but means that foo.set( 'bar', 1 ) may be slightly slower than foo.bar = 1.

      In TypeScript, those properties should be declared in class using declare keyword. In example:

      public declare myProp1: number;
      public declare myProp2: string;

      constructor() {
      this.set( {
      'myProp1: 2,
      'myProp2: 'foo'
      } );
      }

      Parameters

      • values: object & {
            addAttributeCheck?: unknown;
            addChildCheck?: unknown;
            bind?: unknown;
            checkAttribute?: unknown;
            checkAttributeInSelection?: unknown;
            checkChild?: unknown;
            checkMerge?: unknown;
            createContext?: unknown;
            decorate?: unknown;
            delegate?: unknown;
            extend?: unknown;
            findAllowedParent?: unknown;
            findOptimalInsertionRange?: unknown;
            fire?: unknown;
            getAttributeProperties?: unknown;
            getAttributesWithProperty?: unknown;
            getDefinition?: unknown;
            getDefinitions?: unknown;
            getLimitElement?: unknown;
            getNearestSelectionRange?: unknown;
            getValidRanges?: unknown;
            isBlock?: unknown;
            isContent?: unknown;
            isInline?: unknown;
            isLimit?: unknown;
            isObject?: unknown;
            isRegistered?: unknown;
            isSelectable?: unknown;
            listenTo?: unknown;
            off?: unknown;
            on?: unknown;
            once?: unknown;
            register?: unknown;
            removeDisallowedAttributes?: unknown;
            set?: unknown;
            setAllowedAttributes?: unknown;
            setAttributeProperties?: unknown;
            stopDelegating?: unknown;
            stopListening?: unknown;
            unbind?: unknown;
        }

        An object with name=>value pairs.

      Returns void

      OBJECT

    • Sets attributes allowed by the schema on a given node.

      Parameters

      • node: ModelNode

        A node to set attributes on.

      • attributes: Record<string, unknown>

        Attributes keys and values.

      • writer: ModelWriter

        An instance of the model writer.

      Returns void

    • This method allows assigning additional metadata to the model attributes. For example, module:engine/model/schema~ModelAttributeProperties AttributeProperties#isFormatting property is used to mark formatting attributes (like bold or italic).

      // Mark bold as a formatting attribute.
      schema.setAttributeProperties( 'bold', {
      isFormatting: true
      } );

      // Override code not to be considered a formatting markup.
      schema.setAttributeProperties( 'code', {
      isFormatting: false
      } );

      Properties are not limited to members defined in the module:engine/model/schema~ModelAttributeProperties AttributeProperties type and you can also use custom properties:

      schema.setAttributeProperties( 'blockQuote', {
      customProperty: 'value'
      } );

      Subsequent calls with the same attribute will extend its custom properties:

      schema.setAttributeProperties( 'blockQuote', {
      one: 1
      } );

      schema.setAttributeProperties( 'blockQuote', {
      two: 2
      } );

      console.log( schema.getAttributeProperties( 'blockQuote' ) );
      // Logs: { one: 1, two: 2 }

      Parameters

      • attributeName: string

        A name of the attribute to receive the properties.

      • properties: ModelAttributeProperties

        A dictionary of properties.

      Returns void

    • Stops delegating events. It can be used at different levels:

      • To stop delegating all events.
      • To stop delegating a specific event to all emitters.
      • To stop delegating a specific event to a specific emitter.

      Parameters

      • Optionalevent: string

        The name of the event to stop delegating. If omitted, stops it all delegations.

      • Optionalemitter: Emitter

        (requires event) The object to stop delegating a particular event to. If omitted, stops delegation of event to all emitters.

      Returns void

    • Stops listening for events. It can be used at different levels:

      • To stop listening to a specific callback.
      • To stop listening to a specific event.
      • To stop listening to all events fired by a specific object.
      • To stop listening to all events fired by all objects.

      Parameters

      • Optionalemitter: Emitter

        The object to stop listening to. If omitted, stops it for all objects.

      • Optionalevent: string

        (Requires the emitter) The name of the event to stop listening to. If omitted, stops it for all events from emitter.

      • Optionalcallback: Function

        (Requires the event) The function to be removed from the call list for the given event.

      Returns void

      BASE_STOP

    • Removes the binding created with #bind.

      // Removes the binding for the 'a' property.
      A.unbind( 'a' );

      // Removes bindings for all properties.
      A.unbind();

      Parameters

      • ...unbindProperties: (
            | "getDefinition"
            | "set"
            | "bind"
            | "unbind"
            | "decorate"
            | "on"
            | "once"
            | "off"
            | "listenTo"
            | "stopListening"
            | "fire"
            | "delegate"
            | "stopDelegating"
            | "register"
            | "extend"
            | "getDefinitions"
            | "isRegistered"
            | "isBlock"
            | "isLimit"
            | "isObject"
            | "isInline"
            | "isSelectable"
            | "isContent"
            | "checkChild"
            | "checkAttribute"
            | "checkMerge"
            | "addChildCheck"
            | "addAttributeCheck"
            | "setAttributeProperties"
            | "getAttributeProperties"
            | "getLimitElement"
            | "checkAttributeInSelection"
            | "getValidRanges"
            | "getNearestSelectionRange"
            | "findAllowedParent"
            | "setAllowedAttributes"
            | "removeDisallowedAttributes"
            | "getAttributesWithProperty"
            | "createContext"
            | "findOptimalInsertionRange"
        )[]

        Observable properties to be unbound. All the bindings will be released if no properties are provided.

      Returns void