@ckeditor/ckeditor5-list
Advanced tools
Comparing version 0.6.0 to 0.6.1
Changelog | ||
========= | ||
## [0.6.1](https://github.com/ckeditor/ckeditor5-list/compare/v0.6.0...v0.6.1) (2017-05-07) | ||
### Bug fixes | ||
* List's view-to-model converter now returns `model.DocumentFragment` containing `listItem` model elements, instead of an array. Closes [#60](https://github.com/ckeditor/ckeditor5/issues/60). ([331242d](https://github.com/ckeditor/ckeditor5-list/commit/331242d)) | ||
* Pasted list items' indentation will now be correctly adjusted if they are pasted into a nested list. Closes [#56](https://github.com/ckeditor/ckeditor5-list/issues/56). ([e91c3d1](https://github.com/ckeditor/ckeditor5-list/commit/e91c3d1)) | ||
### Other changes | ||
* Updated translations. ([bd83eed](https://github.com/ckeditor/ckeditor5-list/commit/bd83eed)) | ||
## [0.6.0](https://github.com/ckeditor/ckeditor5-list/compare/v0.5.1...v0.6.0) (2017-04-05) | ||
@@ -5,0 +17,0 @@ |
{ | ||
"name": "@ckeditor/ckeditor5-list", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"description": "Introduces ordered and unordered lists feature to CKEditor 5.", | ||
"keywords": [], | ||
"dependencies": { | ||
"@ckeditor/ckeditor5-engine": "^0.9.0", | ||
"@ckeditor/ckeditor5-paragraph": "^0.7.0", | ||
"@ckeditor/ckeditor5-core": "^0.8.0", | ||
"@ckeditor/ckeditor5-ui": "^0.8.0", | ||
"@ckeditor/ckeditor5-utils": "^0.9.0" | ||
"@ckeditor/ckeditor5-engine": "^0.10.0", | ||
"@ckeditor/ckeditor5-paragraph": "^0.8.0", | ||
"@ckeditor/ckeditor5-core": "^0.8.1", | ||
"@ckeditor/ckeditor5-ui": "^0.9.0", | ||
"@ckeditor/ckeditor5-utils": "^0.9.1" | ||
}, | ||
"devDependencies": { | ||
"@ckeditor/ckeditor5-basic-styles": "^0.7.1", | ||
"@ckeditor/ckeditor5-basic-styles": "^0.8.1", | ||
"@ckeditor/ckeditor5-clipboard": "^0.6.0", | ||
"@ckeditor/ckeditor5-dev-lint": "^2.0.2", | ||
"@ckeditor/ckeditor5-editor-classic": "^0.7.2", | ||
"@ckeditor/ckeditor5-enter": "^0.9.0", | ||
"@ckeditor/ckeditor5-heading": "^0.9.0", | ||
"@ckeditor/ckeditor5-typing": "^0.9.0", | ||
"@ckeditor/ckeditor5-undo": "^0.8.0", | ||
"@ckeditor/ckeditor5-editor-classic": "^0.7.3", | ||
"@ckeditor/ckeditor5-enter": "^0.9.1", | ||
"@ckeditor/ckeditor5-heading": "^0.9.1", | ||
"@ckeditor/ckeditor5-typing": "^0.9.1", | ||
"@ckeditor/ckeditor5-undo": "^0.8.1", | ||
"gulp": "^3.9.0", | ||
@@ -22,0 +23,0 @@ "guppy-pre-commit": "^0.4.0" |
@@ -12,2 +12,3 @@ /** | ||
import ModelDocumentFragment from '@ckeditor/ckeditor5-engine/src/model/documentfragment'; | ||
import ModelElement from '@ckeditor/ckeditor5-engine/src/model/element'; | ||
@@ -50,3 +51,6 @@ import ModelPosition from '@ckeditor/ckeditor5-engine/src/model/position'; | ||
injectViewList( modelItem, viewItem, conversionApi.mapper ); | ||
// Providing kind of "default" insert position in case of converting incorrect model. | ||
const insertPosition = conversionApi.mapper.toViewPosition( ModelPosition.createBefore( modelItem ) ); | ||
injectViewList( modelItem, viewItem, conversionApi.mapper, insertPosition ); | ||
} | ||
@@ -368,3 +372,4 @@ | ||
// `listItem`s will be kept in flat structure. | ||
let items = [ listItem ]; | ||
let items = new ModelDocumentFragment(); | ||
items.appendChildren( listItem ); | ||
@@ -381,3 +386,3 @@ // Check all children of the converted `<li>`. | ||
if ( child.name == 'ul' || child.name == 'ol' ) { | ||
items = items.concat( Array.from( converted.getChildren() ) ); | ||
items.appendChildren( Array.from( converted.getChildren() ) ); | ||
} | ||
@@ -629,27 +634,27 @@ // If it was not a list it was a "regular" list item content. Just append it to `listItem`. | ||
function _fixItemsIndent( changePosition, document, batch ) { | ||
const prevItem = changePosition.nodeBefore; | ||
let nextItem = changePosition.nodeAfter; | ||
if ( nextItem && nextItem.name == 'listItem' ) { | ||
// This is the maximum indent that following model list item may have. | ||
const maxIndent = prevItem && prevItem.is( 'listItem' ) ? prevItem.getAttribute( 'indent' ) + 1 : 0; | ||
document.enqueueChanges( () => { | ||
const prevItem = nextItem.previousSibling; | ||
// This is the maximum indent that following model list item may have. | ||
const maxIndent = prevItem && prevItem.is( 'listItem' ) ? prevItem.getAttribute( 'indent' ) + 1 : 0; | ||
// Check how much the next item needs to be outdented. | ||
let outdentBy = nextItem.getAttribute( 'indent' ) - maxIndent; | ||
const items = []; | ||
// Check how much the next item needs to be outdented. | ||
let outdentBy = nextItem.getAttribute( 'indent' ) - maxIndent; | ||
const items = []; | ||
while ( nextItem && nextItem.name == 'listItem' && nextItem.getAttribute( 'indent' ) > maxIndent ) { | ||
if ( outdentBy > nextItem.getAttribute( 'indent' ) ) { | ||
outdentBy = nextItem.getAttribute( 'indent' ); | ||
} | ||
while ( nextItem && nextItem.name == 'listItem' && nextItem.getAttribute( 'indent' ) > maxIndent ) { | ||
if ( outdentBy > nextItem.getAttribute( 'indent' ) ) { | ||
outdentBy = nextItem.getAttribute( 'indent' ); | ||
} | ||
const newIndent = nextItem.getAttribute( 'indent' ) - outdentBy; | ||
const newIndent = nextItem.getAttribute( 'indent' ) - outdentBy; | ||
items.push( { item: nextItem, indent: newIndent } ); | ||
items.push( { item: nextItem, indent: newIndent } ); | ||
nextItem = nextItem.nextSibling; | ||
} | ||
nextItem = nextItem.nextSibling; | ||
} | ||
if ( items.length > 0 ) { | ||
document.enqueueChanges( () => { | ||
if ( items.length > 0 ) { | ||
// Since we are outdenting list items, it is safer to start from the last one (it will maintain correct model state). | ||
@@ -659,4 +664,4 @@ for ( let item of items.reverse() ) { | ||
} | ||
} ); | ||
} | ||
} | ||
} ); | ||
} | ||
@@ -678,14 +683,14 @@ } | ||
const refItem = _getBoundaryItemOfSameList( item, !fixPrevious ); | ||
document.enqueueChanges( () => { | ||
const refItem = _getBoundaryItemOfSameList( item, !fixPrevious ); | ||
if ( !refItem || refItem == item ) { | ||
// !refItem - happens if first list item is inserted. | ||
// refItem == item - happens if last item is inserted. | ||
return; | ||
} | ||
if ( !refItem || refItem == item ) { | ||
// !refItem - happens if first list item is inserted. | ||
// refItem == item - happens if last item is inserted. | ||
return; | ||
} | ||
const refIndent = refItem.getAttribute( 'indent' ); | ||
const refType = refItem.getAttribute( 'type' ); | ||
const refIndent = refItem.getAttribute( 'indent' ); | ||
const refType = refItem.getAttribute( 'type' ); | ||
document.enqueueChanges( () => { | ||
while ( item && item.is( 'listItem' ) && item.getAttribute( 'indent' ) >= refIndent ) { | ||
@@ -701,2 +706,62 @@ if ( item.getAttribute( 'type' ) != refType && item.getAttribute( 'indent' ) == refIndent ) { | ||
/** | ||
* Fixer for pasted content that includes list items. | ||
* | ||
* Fixes indent of pasted list items so the pasted items match correctly to the context they are pasted into. | ||
* | ||
* Example: | ||
* | ||
* <listItem type="bulleted" indent=0>A</listItem> | ||
* <listItem type="bulleted" indent=1>B^</listItem> | ||
* // At ^ paste: <listItem type="bulleted" indent=4>X</listItem> | ||
* // <listItem type="bulleted" indent=5>Y</listItem> | ||
* <listItem type="bulleted" indent=2>C</listItem> | ||
* | ||
* Should become: | ||
* | ||
* <listItem type="bulleted" indent=0>A</listItem> | ||
* <listItem type="bulleted" indent=1>BX</listItem> | ||
* <listItem type="bulleted" indent=2>Y/listItem> | ||
* <listItem type="bulleted" indent=2>C</listItem> | ||
* | ||
* @param {module:engine/model/document~Document} document Document to observe. | ||
* @returns {Function} Callback to be attached to {@link module:engine/model/document~Document#event:change document change event}. | ||
*/ | ||
export function modelIndentPasteFixer( evt, data ) { | ||
// Check whether inserted content starts from a `listItem`. If it does not, it means that there are some other | ||
// elements before it and there is no need to fix indents, because even if we insert that content into a list, | ||
// that list will be broken. | ||
let item = data.content.getChild( 0 ); | ||
if ( item.is( 'listItem' ) ) { | ||
// Get a reference list item. Inserted list items will be fixed according to that item. | ||
const pos = data.selection.getFirstPosition(); | ||
let refItem = null; | ||
if ( pos.parent.is( 'listItem' ) ) { | ||
refItem = pos.parent; | ||
} else if ( pos.nodeBefore && pos.nodeBefore.is( 'listItem' ) ) { | ||
refItem = pos.nodeBefore; | ||
} | ||
// If there is `refItem` it means that we do insert list items into an existing list. | ||
if ( refItem ) { | ||
// First list item in `data` has indent equal to 0 (it is a first list item). It should have indent equal | ||
// to the indent of reference item. We have to fix the first item and all of it's children and following siblings. | ||
// Indent of all those items has to be adjusted to reference item. | ||
const indentChange = refItem.getAttribute( 'indent' ); | ||
// Fix only if there is anything to fix. | ||
if ( indentChange > 0 ) { | ||
// Adjust indent of all "first" list items in inserted data. | ||
while ( item && item.is( 'listItem' ) ) { | ||
item.setAttribute( 'indent', item.getAttribute( 'indent' ) + indentChange ); | ||
item = item.nextSibling; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
// Helper function that creates a `<ul><li></li></ul>` or (`<ol>`) structure out of given `modelItem` model `listItem` element. | ||
@@ -703,0 +768,0 @@ // Then, it binds created view list item (<li>) with model `listItem` element. |
@@ -26,2 +26,3 @@ /** | ||
modelChangePostFixer, | ||
modelIndentPasteFixer, | ||
viewModelConverter, | ||
@@ -113,2 +114,5 @@ modelToViewPosition, | ||
// Fix indentation of pasted items. | ||
data.on( 'insertContent', modelIndentPasteFixer, { priority: 'high' } ); | ||
// Register commands for numbered and bulleted list. | ||
@@ -115,0 +119,0 @@ editor.commands.set( 'numberedList', new ListCommand( editor, 'numbered' ) ); |
Sorry, the diff of this file is too big to display
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
241471
56
5346
0
10
+ Added@ckeditor/ckeditor5-paragraph@0.8.0(transitive)
+ Added@ckeditor/ckeditor5-theme-lark@0.8.0(transitive)
+ Added@ckeditor/ckeditor5-ui@0.9.0(transitive)
- Removed@ckeditor/ckeditor5-engine@0.9.0(transitive)
- Removed@ckeditor/ckeditor5-paragraph@0.7.0(transitive)
- Removed@ckeditor/ckeditor5-theme-lark@0.7.0(transitive)
- Removed@ckeditor/ckeditor5-ui@0.8.0(transitive)