engine/conversion/downcasthelpers
Classes
-
module:engine/conversion/downcasthelpers~DowncastHelpers
Interfaces
-
module:engine/conversion/downcasthelpers~DowncastHighlightDescriptor
Type Definitions
-
module:engine/conversion/downcasthelpers~ConsumerFunction -
module:engine/conversion/downcasthelpers~DowncastAddHighlightCallback -
module:engine/conversion/downcasthelpers~DowncastAttributeCreatorFunction -
module:engine/conversion/downcasthelpers~DowncastAttributeDescriptor -
module:engine/conversion/downcasthelpers~DowncastAttributeElementCreatorFunction -
module:engine/conversion/downcasthelpers~DowncastElementCreatorFunction -
module:engine/conversion/downcasthelpers~DowncastHighlightDescriptorCreatorFunction -
module:engine/conversion/downcasthelpers~DowncastMarkerDataCreatorFunction -
module:engine/conversion/downcasthelpers~DowncastMarkerElementCreatorFunction -
module:engine/conversion/downcasthelpers~DowncastRemoveHighlightCallback -
module:engine/conversion/downcasthelpers~DowncastSlotFilter -
module:engine/conversion/downcasthelpers~DowncastStructureCreatorFunction
Functions
-
cleanSelection() → ( evt: EventInfo, data: unknown, conversionApi: DowncastConversionApi ) => voidinternalmodule:engine/conversion/downcasthelpers~cleanSelectionFunction factory that creates a converter which cleans artifacts after the previous model selection conversion. It removes all empty view attribute elements and merges sibling attributes at all start and end positions of all ranges.
<p><strong>^</strong></p> -> <p>^</p> <p><strong>foo</strong>^<strong>bar</strong>bar</p> -> <p><strong>foo^bar<strong>bar</p> <p><strong>foo</strong><em>^</em><strong>bar</strong>bar</p> -> <p><strong>foo^bar<strong>bar</p>Copy codeThis listener should be assigned before any converter for the new selection:
modelDispatcher.on( 'cleanSelection', cleanSelection() );Copy codeSee
convertCollapsedSelectionwhich does the opposite by breaking attributes in the selection position.Returns
( evt: EventInfo, data: unknown, conversionApi: DowncastConversionApi ) => voidSelection converter.
-
convertCollapsedSelection() → ( evt: EventInfo, data: object, conversionApi: DowncastConversionApi ) => voidinternalmodule:engine/conversion/downcasthelpers~convertCollapsedSelectionFunction factory that creates a converter which converts a collapsed model selection to a view selection. The converter consumes appropriate value from the
consumableobject, maps the model selection position to the view position and breaks attribute elements at the selection position.modelDispatcher.on( 'selection', convertCollapsedSelection() );Copy codeAn example of the view state before and after converting the collapsed selection:
<p><strong>f^oo<strong>bar</p> -> <p><strong>f</strong>^<strong>oo</strong>bar</p>Copy codeBy breaking attribute elements like
<strong>, the selection is in a correct element. Then, when the selection attribute is converted, broken attributes might be merged again, or the position where the selection is may be wrapped with different, appropriate attribute elements.See also
cleanSelectionwhich does a clean-up by merging attributes.Returns
( evt: EventInfo, data: object, conversionApi: DowncastConversionApi ) => voidSelection converter.
-
convertRangeSelection() → ( evt: EventInfo, data: object, conversionApi: DowncastConversionApi ) => voidinternalmodule:engine/conversion/downcasthelpers~convertRangeSelectionFunction factory that creates a converter which converts a non-collapsed model selection to a view selection. The converter consumes appropriate value from the
consumableobject and maps model positions from the selection to view positions.modelDispatcher.on( 'selection', convertRangeSelection() );Copy codeReturns
( evt: EventInfo, data: object, conversionApi: DowncastConversionApi ) => voidSelection converter.
-
createViewElementFromDowncastHighlightDescriptor( writer, descriptor ) → ViewAttributeElementinternalmodule:engine/conversion/downcasthelpers~createViewElementFromDowncastHighlightDescriptorCreates a
<span>view attribute element from the information provided by the highlight descriptor object. If the priority is not provided in the descriptor, the default priority will be used.Parameters
writer : ViewDowncastWriterdescriptor : DowncastHighlightDescriptor
Returns
-
insertAttributesAndChildren() → ( evt: unknown, data: object, conversionApi: DowncastConversionApi ) => voidinternalmodule:engine/conversion/downcasthelpers~insertAttributesAndChildrenFunction factory that creates a default downcast converter for triggering attributes and children conversion.
Returns
( evt: unknown, data: object, conversionApi: DowncastConversionApi ) => voidThe converter.
-
insertElement( elementCreator, consumer ) → ( evt: unknown, data: object, conversionApi: DowncastConversionApi ) => voidinternalmodule:engine/conversion/downcasthelpers~insertElementFunction factory that creates a converter which converts node insertion changes from the model to the view. The function passed will be provided with all the parameters of the dispatcher's
insertevent. It is expected that the function returns anViewElement. The result of the function will be inserted into the view.The converter automatically consumes the corresponding value from the consumables list and binds the model and view elements.
downcastDispatcher.on( 'insert:myElem', insertElement( ( modelItem, { writer } ) => { const text = writer.createText( 'myText' ); const myElem = writer.createElement( 'myElem', { myAttr: 'my-' + modelItem.getAttribute( 'myAttr' ) }, text ); // Do something fancy with `myElem` using `modelItem` or other parameters. return myElem; } ) );Copy codeParameters
elementCreator : DowncastElementCreatorFunctionFunction returning a view element, which will be inserted.
consumer : ConsumerFunctionFunction defining element consumption process. By default this function just consume passed item insertion.
Defaults to
defaultConsumer
Returns
( evt: unknown, data: object, conversionApi: DowncastConversionApi ) => voidInsert element event converter.
-
insertStructure( elementCreator, consumer ) → ( evt: unknown, data: object, conversionApi: DowncastConversionApi ) => voidinternalmodule:engine/conversion/downcasthelpers~insertStructureFunction factory that creates a converter which converts a single model node insertion to a view structure.
It is expected that the passed element creator function returns an
ViewElementwith attached slots created withwriter.createSlot()to indicate where child nodes should be converted.Parameters
elementCreator : DowncastElementCreatorFunctionFunction returning a view structure, which will be inserted.
consumer : ConsumerFunctionA callback that is expected to consume all the consumables that were used by the element creator.
Returns
( evt: unknown, data: object, conversionApi: DowncastConversionApi ) => voidInsert element event converter.
Related:
-
insertText() → ( evt: EventInfo, data: object, conversionApi: DowncastConversionApi ) => voidinternalmodule:engine/conversion/downcasthelpers~insertTextFunction factory that creates a default downcast converter for text insertion changes.
The converter automatically consumes the corresponding value from the consumables list and stops the event (see
DowncastDispatcher).modelDispatcher.on( 'insert:$text', insertText() );Copy codeReturns
( evt: EventInfo, data: object, conversionApi: DowncastConversionApi ) => voidInsert text event converter.
-
insertUIElement( elementCreator ) → ( evt: EventInfo, data: object, conversionApi: DowncastConversionApi ) => voidinternalmodule:engine/conversion/downcasthelpers~insertUIElementFunction factory that creates a converter which converts marker adding change to the view UI element.
The view UI element that will be added to the view depends on the passed parameter. See
insertElement. In case of a non-collapsed range, the UI element will not wrap nodes but separate elements will be placed at the beginning and at the end of the range.This converter binds created UI elements with the marker name using
bindElementToMarker.Parameters
elementCreator : DowncastMarkerElementCreatorFunctionA view UI element or a function returning the view element that will be inserted.
Returns
( evt: EventInfo, data: object, conversionApi: DowncastConversionApi ) => voidInsert element event converter.
-
remove() → ( evt: unknown, data: object, conversionApi: DowncastConversionApi ) => voidinternalmodule:engine/conversion/downcasthelpers~removeFunction factory that creates a default downcast converter for node remove changes.
modelDispatcher.on( 'remove', remove() );Copy codeReturns
( evt: unknown, data: object, conversionApi: DowncastConversionApi ) => voidRemove event converter.
-
wrap( elementCreator ) → ( evt: EventInfo, data: object, conversionApi: DowncastConversionApi ) => voidinternalmodule:engine/conversion/downcasthelpers~wrapFunction factory that creates a converter which converts the set/change/remove attribute changes from the model to the view. It can also be used to convert selection attributes. In that case, an empty attribute element will be created and the selection will be put inside it.
Attributes from the model are converted to a view element that will be wrapping these view nodes that are bound to model elements having the given attribute. This is useful for attributes like
boldthat may be set on text nodes in the model but are represented as an element in the view:[paragraph] MODEL ====> VIEW <p> |- a {bold: true} |- <b> |- b {bold: true} | |- ab |- c |- c ``` Passed `Function` will be provided with the attribute value and then all the parameters of the `attribute` event. It is expected that the function returns anViewElement. The result of the function will be the wrapping element. When the provided `Function` does not return any element, no conversion will take place. The converter automatically consumes the corresponding value from the consumables list and stops the event (seeDowncastDispatcher). ```ts modelDispatcher.on( 'attribute:bold', wrap( ( modelAttributeValue, { writer } ) => { return writer.createAttributeElement( 'strong' ); } );Copy codeParameters
elementCreator : DowncastAttributeElementCreatorFunctionFunction returning a view element that will be used for wrapping.
Returns
( evt: EventInfo, data: object, conversionApi: DowncastConversionApi ) => voidSet/change attribute converter.