|
@@ -25,9 +25,9 @@ export function createViewListItemElement( writer ) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * Helper function that creates a `<ul><li></li></ul>` or (`<ol>`) structure out of given `modelItem` model `listItem` element.
|
|
|
|
|
- * Then, it binds created view list item (<li>) with model `listItem` element.
|
|
|
|
|
- * The function then returns created view list item (<li>).
|
|
|
|
|
|
|
+ * Helper function that creates a `<ul><li></li></ul>` or (`<ol>`) structure out of the given `modelItem` model `listItem` element.
|
|
|
|
|
+ * Then, it binds the created view list item (<li>) with the model `listItem` element.
|
|
|
|
|
+ * The function then returns the created view list item (<li>).
|
|
|
*
|
|
*
|
|
|
* @param {module:engine/model/item~Item} modelItem Model list item.
|
|
* @param {module:engine/model/item~Item} modelItem Model list item.
|
|
|
* @param {module:engine/conversion/upcastdispatcher~UpcastConversionApi} conversionApi Conversion interface.
|
|
* @param {module:engine/conversion/upcastdispatcher~UpcastConversionApi} conversionApi Conversion interface.
|
|
@@ -49,9 +49,9 @@ export function generateLiInUl( modelItem, conversionApi ) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * Helper function that takes model list item element `modelItem`, corresponding view list item element `injectedItem`
|
|
|
|
|
- * that is not added to the view and is inside a view list element (`ul` or `ol`) and is that's list only child.
|
|
|
|
|
- * The list is inserted at correct position (element breaking may be needed) and then merged with it's siblings.
|
|
|
|
|
|
|
+ * Helper function that inserts a view list at a correct place and merges it with its siblings.
|
|
|
|
|
+ * It takes a model list item element (`modelItem`) and a corresponding view list item element (`injectedItem`). The view list item
|
|
|
|
|
+ * should be in a view list element (`<ul>` or `<ol>`) and should be its only child.
|
|
|
* See comments below to better understand the algorithm.
|
|
* See comments below to better understand the algorithm.
|
|
|
*
|
|
*
|
|
|
* @param {module:engine/view/item~Item} modelItem Model list item.
|
|
* @param {module:engine/view/item~Item} modelItem Model list item.
|
|
@@ -64,12 +64,12 @@ export function injectViewList( modelItem, injectedItem, conversionApi, model )
|
|
|
const mapper = conversionApi.mapper;
|
|
const mapper = conversionApi.mapper;
|
|
|
const viewWriter = conversionApi.writer;
|
|
const viewWriter = conversionApi.writer;
|
|
|
|
|
|
|
|
- // Position where view list will be inserted.
|
|
|
|
|
|
|
+ // The position where the view list will be inserted.
|
|
|
let insertPosition = mapper.toViewPosition( model.createPositionBefore( modelItem ) );
|
|
let insertPosition = mapper.toViewPosition( model.createPositionBefore( modelItem ) );
|
|
|
|
|
|
|
|
- // 1. Find previous list item that has same or smaller indent. Basically we are looking for a first model item
|
|
|
|
|
- // that is "parent" or "sibling" of injected model item.
|
|
|
|
|
- // If there is no such list item, it means that injected list item is the first item in "its list".
|
|
|
|
|
|
|
+ // 1. Find the previous list item that has the same or smaller indent. Basically we are looking for the first model item
|
|
|
|
|
+ // that is a "parent" or "sibling" of the injected model item.
|
|
|
|
|
+ // If there is no such list item, it means that the injected list item is the first item in "its list".
|
|
|
const refItem = getSiblingListItem( modelItem.previousSibling, {
|
|
const refItem = getSiblingListItem( modelItem.previousSibling, {
|
|
|
sameIndent: true,
|
|
sameIndent: true,
|
|
|
smallerIndent: true,
|
|
smallerIndent: true,
|
|
@@ -78,19 +78,19 @@ export function injectViewList( modelItem, injectedItem, conversionApi, model )
|
|
|
const prevItem = modelItem.previousSibling;
|
|
const prevItem = modelItem.previousSibling;
|
|
|
|
|
|
|
|
if ( refItem && refItem.getAttribute( 'listIndent' ) == modelItem.getAttribute( 'listIndent' ) ) {
|
|
if ( refItem && refItem.getAttribute( 'listIndent' ) == modelItem.getAttribute( 'listIndent' ) ) {
|
|
|
- // There is a list item with same indent - we found same-level sibling.
|
|
|
|
|
- // Break the list after it. Inserted view item will be inserted in the broken space.
|
|
|
|
|
|
|
+ // There is a list item with the same indent - we found the same-level sibling.
|
|
|
|
|
+ // Break the list after it. The inserted view item will be added in the broken space.
|
|
|
const viewItem = mapper.toViewElement( refItem );
|
|
const viewItem = mapper.toViewElement( refItem );
|
|
|
insertPosition = viewWriter.breakContainer( viewWriter.createPositionAfter( viewItem ) );
|
|
insertPosition = viewWriter.breakContainer( viewWriter.createPositionAfter( viewItem ) );
|
|
|
} else {
|
|
} else {
|
|
|
- // There is no list item with same indent. Check previous model item.
|
|
|
|
|
|
|
+ // There is no list item with the same indent. Check the previous model item.
|
|
|
if ( prevItem && prevItem.name == 'listItem' ) {
|
|
if ( prevItem && prevItem.name == 'listItem' ) {
|
|
|
- // If it is a list item, it has to have lower indent.
|
|
|
|
|
- // It means that inserted item should be added to it as its nested item.
|
|
|
|
|
|
|
+ // If it is a list item, it has to have a lower indent.
|
|
|
|
|
+ // It means that the inserted item should be added to it as its nested item.
|
|
|
insertPosition = mapper.toViewPosition( model.createPositionAt( prevItem, 'end' ) );
|
|
insertPosition = mapper.toViewPosition( model.createPositionAt( prevItem, 'end' ) );
|
|
|
} else {
|
|
} else {
|
|
|
- // Previous item is not a list item (or does not exist at all).
|
|
|
|
|
- // Just map the position and insert the view item at mapped position.
|
|
|
|
|
|
|
+ // The previous item is not a list item (or does not exist at all).
|
|
|
|
|
+ // Just map the position and insert the view item at the mapped position.
|
|
|
insertPosition = mapper.toViewPosition( model.createPositionBefore( modelItem ) );
|
|
insertPosition = mapper.toViewPosition( model.createPositionBefore( modelItem ) );
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -100,7 +100,7 @@ export function injectViewList( modelItem, injectedItem, conversionApi, model )
|
|
|
// Insert the view item.
|
|
// Insert the view item.
|
|
|
viewWriter.insert( insertPosition, injectedList );
|
|
viewWriter.insert( insertPosition, injectedList );
|
|
|
|
|
|
|
|
- // 2. Handle possible children of injected model item.
|
|
|
|
|
|
|
+ // 2. Handle possible children of the injected model item.
|
|
|
if ( prevItem && prevItem.name == 'listItem' ) {
|
|
if ( prevItem && prevItem.name == 'listItem' ) {
|
|
|
const prevView = mapper.toViewElement( prevItem );
|
|
const prevView = mapper.toViewElement( prevItem );
|
|
|
|
|
|
|
@@ -142,19 +142,19 @@ export function injectViewList( modelItem, injectedItem, conversionApi, model )
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Merge inserted view list with its possible neighbour lists.
|
|
|
|
|
|
|
+ // Merge the inserted view list with its possible neighbor lists.
|
|
|
mergeViewLists( viewWriter, injectedList, injectedList.nextSibling );
|
|
mergeViewLists( viewWriter, injectedList, injectedList.nextSibling );
|
|
|
mergeViewLists( viewWriter, injectedList.previousSibling, injectedList );
|
|
mergeViewLists( viewWriter, injectedList.previousSibling, injectedList );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * Helper function that takes two parameters, that are expected to be view list elements, and merges them.
|
|
|
|
|
- * The merge happen only if both parameters are list elements of the same types (the same element name and the same class attributes).
|
|
|
|
|
|
|
+ * Helper function that takes two parameters that are expected to be view list elements, and merges them.
|
|
|
|
|
+ * The merge happens only if both parameters are list elements of the same type (the same element name and the same class attributes).
|
|
|
*
|
|
*
|
|
|
* @param {module:engine/view/downcastwriter~DowncastWriter} viewWriter The writer instance.
|
|
* @param {module:engine/view/downcastwriter~DowncastWriter} viewWriter The writer instance.
|
|
|
- * @param {module:engine/view/item~Item} firstList First element o compare.
|
|
|
|
|
- * @param {module:engine/view/item~Item} secondList Second parameter to compare.
|
|
|
|
|
- * @returns {module:engine/view/position~Position|null} Position after merge or `null` when there was no merge.
|
|
|
|
|
|
|
+ * @param {module:engine/view/item~Item} firstList The first element to compare.
|
|
|
|
|
+ * @param {module:engine/view/item~Item} secondList The second element to compare.
|
|
|
|
|
+ * @returns {module:engine/view/position~Position|null} The position after merge or `null` when there was no merge.
|
|
|
*/
|
|
*/
|
|
|
export function mergeViewLists( viewWriter, firstList, secondList ) {
|
|
export function mergeViewLists( viewWriter, firstList, secondList ) {
|
|
|
// Check if two lists are going to be merged.
|
|
// Check if two lists are going to be merged.
|
|
@@ -171,12 +171,12 @@ export function mergeViewLists( viewWriter, firstList, secondList ) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * Helper function that for given `view.Position`, returns a `view.Position` that is after all `view.UIElement`s that
|
|
|
|
|
- * are after given position.
|
|
|
|
|
|
|
+ * Helper function that for a given `view.Position`, returns a `view.Position` that is after all `view.UIElement`s that
|
|
|
|
|
+ * are after the given position.
|
|
|
*
|
|
*
|
|
|
* For example:
|
|
* For example:
|
|
|
* `<container:p>foo^<ui:span></ui:span><ui:span></ui:span>bar</container:p>`
|
|
* `<container:p>foo^<ui:span></ui:span><ui:span></ui:span>bar</container:p>`
|
|
|
- * For position ^, a position before "bar" will be returned.
|
|
|
|
|
|
|
+ * For position ^, the position before "bar" will be returned.
|
|
|
*
|
|
*
|
|
|
* @param {module:engine/view/position~Position} viewPosition
|
|
* @param {module:engine/view/position~Position} viewPosition
|
|
|
* @returns {module:engine/view/position~Position}
|
|
* @returns {module:engine/view/position~Position}
|
|
@@ -186,14 +186,14 @@ export function positionAfterUiElements( viewPosition ) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * Helper function that seeks for a previous list item sibling of given model item which meets given criteria
|
|
|
|
|
- * passed by an options object.
|
|
|
|
|
|
|
+ * Helper function that searches for a previous list item sibling of a given model item that meets the given criteria
|
|
|
|
|
+ * passed by the options object.
|
|
|
*
|
|
*
|
|
|
* @param {module:engine/model/item~Item} modelItem
|
|
* @param {module:engine/model/item~Item} modelItem
|
|
|
* @param {Object} options Search criteria.
|
|
* @param {Object} options Search criteria.
|
|
|
- * @param {Boolean} [options.sameIndent=false] Whether sought sibling should have same indent.
|
|
|
|
|
- * @param {Boolean} [options.smallerIndent=false] Whether sought sibling should have smaller indent.
|
|
|
|
|
- * @param {Number} [options.listIndent] The reference indent.
|
|
|
|
|
|
|
+ * @param {Boolean} [options.sameIndent=false] Whether the sought sibling should have the same indentation.
|
|
|
|
|
+ * @param {Boolean} [options.smallerIndent=false] Whether the sought sibling should have a smaller indentation.
|
|
|
|
|
+ * @param {Number} [options.listIndent] The reference indentation.
|
|
|
* @returns {module:engine/model/item~Item|null}
|
|
* @returns {module:engine/model/item~Item|null}
|
|
|
*/
|
|
*/
|
|
|
export function getSiblingListItem( modelItem, options ) {
|
|
export function getSiblingListItem( modelItem, options ) {
|
|
@@ -227,10 +227,10 @@ export function findInRange( range, comparator ) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * Helper method for creating an UI button and linking it with an appropriate command.
|
|
|
|
|
|
|
+ * Helper method for creating a UI button and linking it with an appropriate command.
|
|
|
*
|
|
*
|
|
|
* @private
|
|
* @private
|
|
|
- * @param {module:core/editor/editor~Editor} editor The editor instance to which UI component will be added.
|
|
|
|
|
|
|
+ * @param {module:core/editor/editor~Editor} editor The editor instance to which the UI component will be added.
|
|
|
* @param {String} commandName The name of the command.
|
|
* @param {String} commandName The name of the command.
|
|
|
* @param {Object} label The button label.
|
|
* @param {Object} label The button label.
|
|
|
* @param {String} icon The source of the icon.
|
|
* @param {String} icon The source of the icon.
|