@ckeditor/ckeditor5-list
Advanced tools
Comparing version 0.5.0 to 0.5.1
{ | ||
"name": "@ckeditor/ckeditor5-list", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"description": "Introduces ordered and unordered lists feature to CKEditor 5.", | ||
"keywords": [], | ||
"dependencies": { | ||
"@ckeditor/ckeditor5-engine": "*", | ||
"@ckeditor/ckeditor5-core": "*", | ||
"@ckeditor/ckeditor5-ui": "*", | ||
"@ckeditor/ckeditor5-utils": "*" | ||
"@ckeditor/ckeditor5-engine": "^0.8.0", | ||
"@ckeditor/ckeditor5-core": "^0.7.0", | ||
"@ckeditor/ckeditor5-ui": "^0.7.1", | ||
"@ckeditor/ckeditor5-utils": "^0.8.0" | ||
}, | ||
"devDependencies": { | ||
"@ckeditor/ckeditor5-dev-lint": "^2.0.0", | ||
"@ckeditor/ckeditor5-editor-classic": "*", | ||
"@ckeditor/ckeditor5-enter": "*", | ||
"@ckeditor/ckeditor5-heading": "*", | ||
"@ckeditor/ckeditor5-paragraph": "*", | ||
"@ckeditor/ckeditor5-typing": "*", | ||
"@ckeditor/ckeditor5-undo": "*", | ||
"@ckeditor/ckeditor5-dev-lint": "^2.0.2", | ||
"@ckeditor/ckeditor5-editor-classic": "^0.7.1", | ||
"@ckeditor/ckeditor5-enter": "^0.8.0", | ||
"@ckeditor/ckeditor5-heading": "^0.8.0", | ||
"@ckeditor/ckeditor5-paragraph": "^0.6.1", | ||
"@ckeditor/ckeditor5-typing": "^0.8.0", | ||
"@ckeditor/ckeditor5-undo": "^0.7.1", | ||
"gulp": "^3.9.0", | ||
@@ -21,0 +21,0 @@ "guppy-pre-commit": "^0.4.0" |
@@ -112,42 +112,2 @@ /** | ||
/** | ||
* Model to view converter for `listItem` model element move. | ||
* | ||
* @see module:engine/conversion/modelconversiondispatcher~ModelConversionDispatcher#event:move | ||
* @param {module:utils/eventinfo~EventInfo} evt Object containing information about the fired event. | ||
* @param {Object} data Additional information about the change. | ||
* @param {module:engine/conversion/modelconsumable~ModelConsumable} consumable Values to consume. | ||
* @param {Object} conversionApi Conversion interface. | ||
*/ | ||
export function modelViewMove( evt, data, consumable, conversionApi ) { | ||
if ( !consumable.consume( data.item, 'move' ) ) { | ||
return; | ||
} | ||
const viewItem = conversionApi.mapper.toViewElement( data.item ); | ||
// 1. Break the container after and before the list item. | ||
// This will create a view list with one view list item -- the one that changed type. | ||
viewWriter.breakContainer( ViewPosition.createBefore( viewItem ) ); | ||
viewWriter.breakContainer( ViewPosition.createAfter( viewItem ) ); | ||
// 2. Extract view list with changed view list item and merge "hole" possibly created by breaking and removing elements. | ||
const viewList = viewItem.parent; | ||
const viewListPrev = viewList.previousSibling; | ||
const viewListNext = viewList.nextSibling; | ||
let insertionPosition = conversionApi.mapper.toViewPosition( data.targetPosition ); | ||
if ( insertionPosition.parent.name == 'ol' || insertionPosition.parent.name == 'ul' ) { | ||
insertionPosition = viewWriter.breakContainer( insertionPosition ); | ||
} | ||
viewWriter.move( ViewRange.createOn( viewList ), insertionPosition ); | ||
// No worries, merging will happen only if both elements exist and they are same type of lists. | ||
mergeViewLists( viewListPrev, viewListNext ); | ||
mergeViewLists( viewList, viewList.nextSibling ); | ||
mergeViewLists( viewList.previousSibling, viewList ); | ||
} | ||
/** | ||
* Model to view converter for `indent` attribute change on `listItem` model element. | ||
@@ -154,0 +114,0 @@ * |
@@ -11,3 +11,4 @@ /** | ||
import Command from '@ckeditor/ckeditor5-core/src/command/command'; | ||
import { getClosestListItem, getSelectedBlocks, getPositionBeforeBlock } from './utils'; | ||
import Position from '@ckeditor/ckeditor5-engine/src/model/position'; | ||
import { getClosestListItem } from './utils'; | ||
@@ -76,3 +77,3 @@ /** | ||
const document = this.editor.document; | ||
const blocks = getSelectedBlocks( document.selection, document.schema ); | ||
const blocks = Array.from( document.selection.getSelectedBlocks() ); | ||
@@ -204,7 +205,16 @@ // Whether we are turning off some items. | ||
const schema = this.editor.document.schema; | ||
const position = getPositionBeforeBlock( selection.getFirstPosition(), schema ); | ||
const firstBlock = selection.getSelectedBlocks().next().value; | ||
if ( !firstBlock ) { | ||
return false; | ||
} | ||
// Otherwise, check if list item can be inserted at the position start. | ||
return schema.check( { name: 'listItem', inside: position, attributes: [ 'type', 'indent' ] } ); | ||
return schema.check( { | ||
name: 'listItem', | ||
attributes: [ 'type', 'indent' ], | ||
inside: Position.createBefore( firstBlock ) | ||
} ); | ||
} | ||
} |
@@ -20,3 +20,2 @@ /** | ||
modelViewRemove, | ||
modelViewMove, | ||
modelViewSplitOnInsert, | ||
@@ -75,7 +74,2 @@ modelViewChangeIndent, | ||
editing.modelToView.on( 'move:listItem', modelViewMove ); | ||
editing.modelToView.on( 'move', modelViewMergeAfter, { priority: 'low' } ); | ||
data.modelToView.on( 'move:listItem', modelViewMove ); | ||
data.modelToView.on( 'move', modelViewMergeAfter, { priority: 'low' } ); | ||
editing.modelToView.on( 'changeAttribute:indent:listItem', modelViewChangeIndent ); | ||
@@ -82,0 +76,0 @@ data.modelToView.on( 'changeAttribute:indent:listItem', modelViewChangeIndent ); |
@@ -12,4 +12,2 @@ /** | ||
import Position from '@ckeditor/ckeditor5-engine/src/model/position'; | ||
/** | ||
@@ -26,54 +24,1 @@ * For given {@link module:engine/model/position~Position position}, returns the closest ancestor of that position which is a | ||
} | ||
/** | ||
* For given {@link module:engine/model/selection~Selection selection} and {@link module:engine/model/schema~Schema schema}, | ||
* returns an array with all elements that are in the selection and are extending `$block` schema item. | ||
* | ||
* @param {module:engine/model/selection~Selection} selection Selection from which blocks will be taken. | ||
* @param {module:engine/model/schema~Schema} schema Schema which will be used to check if a model element extends `$block`. | ||
* @returns {Array.<module:engine/model/element~Element>} All blocks from the selection. | ||
*/ | ||
export function getSelectedBlocks( selection, schema ) { | ||
let position = getPositionBeforeBlock( selection.getFirstPosition(), schema ); | ||
const endPosition = selection.getLastPosition(); | ||
const blocks = []; | ||
// Traverse model from the first position before a block to the end position of selection. | ||
// Store all elements that were after the correct positions. | ||
while ( position !== null && position.isBefore( endPosition ) ) { | ||
blocks.push( position.nodeAfter ); | ||
position.offset++; | ||
position = getPositionBeforeBlock( position, schema ); | ||
} | ||
return blocks; | ||
} | ||
/** | ||
* For given {@link module:engine/model/position~Position position}, finds a model element extending `$block` schema item which is | ||
* closest element to that position. First node after the position is checked and then the position's ancestors. `null` | ||
* is returned if such element has not been found or found element is a root element. | ||
* | ||
* @param position | ||
* @param schema | ||
* @returns {*} | ||
*/ | ||
export function getPositionBeforeBlock( position, schema ) { | ||
// Start from the element right after the position. Maybe it is already a `$block` element. | ||
let element = position.nodeAfter; | ||
// If the position is not before an element, check the parent. | ||
if ( !element ) { | ||
element = position.parent; | ||
} | ||
// If proper element is still not found, check the ancestors. | ||
while ( element !== null && !schema.itemExtends( element.name || '$text', '$block' ) ) { | ||
element = element.parent; | ||
} | ||
// If proper element has been found, return position before it, otherwise return null; | ||
return element !== null && element.parent !== null ? Position.createBefore( element ) : null; | ||
} |
@@ -94,17 +94,27 @@ /** | ||
it( 'should be true if selection first position is in a place where listItem can be inserted', () => { | ||
doc.selection.collapse( doc.getRoot(), 2 ); | ||
it( 'should be true if entire selection is in a list', () => { | ||
setData( doc, '<listItem type="bulleted" indent="0">[a]</listItem>' ); | ||
expect( command.isEnabled ).to.be.true; | ||
} ); | ||
doc.selection.collapse( doc.getRoot().getChild( 0 ) ); | ||
it( 'should be true if entire selection is in a block which can be turned into a list', () => { | ||
setData( doc, '<paragraph>[a]</paragraph>' ); | ||
expect( command.isEnabled ).to.be.true; | ||
} ); | ||
doc.selection.collapse( doc.getRoot().getChild( 2 ) ); | ||
it( 'should be true if selection first position is in a block which can be turned into a list', () => { | ||
setData( doc, '<paragraph>[a</paragraph><widget>b]</widget>' ); | ||
expect( command.isEnabled ).to.be.true; | ||
} ); | ||
it( 'should be false if selection first position is in a place where listItem cannot be inserted', () => { | ||
doc.selection.collapse( doc.getRoot().getChild( 4 ) ); | ||
it( 'should be false if selection first position is in an element which cannot be converted to a list item', () => { | ||
setData( doc, '<widget><paragraph>[a</paragraph></widget><paragraph>b]</paragraph>' ); | ||
expect( command.isEnabled ).to.be.false; | ||
} ); | ||
it( 'should be false in a root which does not allow blocks at all', () => { | ||
doc.createRoot( 'paragraph', 'inlineOnlyRoot' ); | ||
setData( doc, 'a[]b', { rootName: 'inlineOnlyRoot' } ); | ||
expect( command.isEnabled ).to.be.false; | ||
} ); | ||
} ); | ||
@@ -111,0 +121,0 @@ |
@@ -465,14 +465,2 @@ /** | ||
it( 'model move converter should not fire if change was already consumed', () => { | ||
editor.editing.modelToView.on( 'move', ( evt, data, consumable ) => { | ||
consumable.consume( data.item, 'move' ); | ||
}, { priority: 'highest' } ); | ||
setModelData( doc, '<listItem indent="0" type="bulleted"></listItem><paragraph>foo</paragraph>' ); | ||
doc.batch().move( root.getChild( 0 ), ModelPosition.createAt( root, 2 ) ); | ||
expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( '<ul><li></li></ul><p>foo</p>' ); | ||
} ); | ||
it( 'model change type converter should not fire if change was already consumed', () => { | ||
@@ -479,0 +467,0 @@ editor.editing.modelToView.on( 'changeAttribute:type', ( evt, data, consumable ) => { |
@@ -6,9 +6,6 @@ /** | ||
import { getClosestListItem, getSelectedBlocks, getPositionBeforeBlock } from '../src/utils'; | ||
import { getClosestListItem } from '../src/utils'; | ||
import Element from '@ckeditor/ckeditor5-engine/src/model/element'; | ||
import Text from '@ckeditor/ckeditor5-engine/src/model/text'; | ||
import Position from '@ckeditor/ckeditor5-engine/src/model/position'; | ||
import Schema from '@ckeditor/ckeditor5-engine/src/model/schema'; | ||
import Selection from '@ckeditor/ckeditor5-engine/src/model/selection'; | ||
@@ -27,76 +24,1 @@ describe( 'getClosestListItem', () => { | ||
} ); | ||
describe( 'getSelectedBlocks', () => { | ||
const paragraph1 = new Element( 'paragraph', null, '---' ); | ||
const item1 = new Element( 'listItem', null, '---' ); | ||
const item2 = new Element( 'listItem', null, '---' ); | ||
const item3 = new Element( 'listItem', null, '---' ); | ||
const paragraph2 = new Element( 'paragraph', null, '---' ); | ||
const root = new Element( '$root', null, [ | ||
paragraph1, item1, item2, item3, paragraph2 | ||
] ); | ||
const schema = new Schema(); | ||
schema.registerItem( 'paragraph', '$block' ); | ||
schema.registerItem( 'listItem', '$block' ); | ||
const selection = new Selection(); | ||
it( 'should return just one block if selection is over one block', () => { | ||
selection.collapse( root, 2 ); | ||
selection.setFocus( root, 3 ); | ||
expect( getSelectedBlocks( selection, schema ) ).to.deep.equal( [ item2 ] ); | ||
} ); | ||
it( 'should return ancestor block if selection is collapsed and not before a block', () => { | ||
selection.collapse( paragraph1, 2 ); | ||
expect( getSelectedBlocks( selection, schema ) ).to.deep.equal( [ paragraph1 ] ); | ||
} ); | ||
it( 'should return empty array for collapsed selection before a block, in a root', () => { | ||
selection.collapse( root, 1 ); | ||
expect( getSelectedBlocks( selection, schema ) ).to.deep.equal( [] ); | ||
} ); | ||
it( 'should return all blocks "touched" by the selection if it spans over multiple blocks', () => { | ||
selection.collapse( item1, 3 ); | ||
selection.setFocus( root, 4 ); | ||
expect( getSelectedBlocks( selection, schema ) ).to.deep.equal( [ item1, item2, item3 ] ); | ||
} ); | ||
} ); | ||
describe( 'getPositionBeforeBlock', () => { | ||
const paragraph = new Element( 'paragraph', null, 'foo' ); | ||
const item = new Element( 'listItem', null, 'bar' ); | ||
const text = new Text( 'xyz' ); | ||
const root = new Element( '$root' ); | ||
root.appendChildren( [ paragraph, item, text ] ); | ||
const schema = new Schema(); | ||
schema.registerItem( 'paragraph', '$block' ); | ||
schema.registerItem( 'listItem', '$block' ); | ||
it( 'should return same position if position is already before a block', () => { | ||
const position = Position.createBefore( paragraph ); | ||
expect( getPositionBeforeBlock( position, schema ).isEqual( position ) ).to.be.true; | ||
} ); | ||
it( 'should return position before position parent if position is inside a block', () => { | ||
const position = Position.createAt( item ); | ||
expect( getPositionBeforeBlock( position, schema ).isEqual( Position.createBefore( item ) ) ).to.be.true; | ||
} ); | ||
it( 'should return null if position is not next to block and is not in a block other than root', () => { | ||
const position = Position.createBefore( text ); | ||
expect( getPositionBeforeBlock( position, schema ) ).to.be.null; | ||
} ); | ||
} ); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 4 instances in 1 package
45
0
117256
2081
+ Added@ckeditor/ckeditor5-core@0.7.0(transitive)
+ Added@ckeditor/ckeditor5-engine@0.8.0(transitive)
+ Added@ckeditor/ckeditor5-theme-lark@0.6.1(transitive)
+ Added@ckeditor/ckeditor5-ui@0.7.1(transitive)
+ Added@ckeditor/ckeditor5-utils@0.8.0(transitive)
- Removed@ckeditor/ckeditor5-core@43.1.0(transitive)
- Removed@ckeditor/ckeditor5-engine@43.1.0(transitive)
- Removed@ckeditor/ckeditor5-ui@43.1.0(transitive)
- Removed@ckeditor/ckeditor5-utils@43.1.0(transitive)
- Removed@ckeditor/ckeditor5-watchdog@43.1.0(transitive)
- Removedcolor-convert@2.0.1(transitive)
- Removedcolor-name@1.1.4(transitive)
- Removedcolor-parse@1.4.2(transitive)
- Removedlodash-es@4.17.21(transitive)
- Removedvanilla-colorful@0.7.2(transitive)