@ckeditor/ckeditor5-paragraph
Advanced tools
Comparing version 0.0.0-nightly-20230803.0 to 0.0.0-nightly-20230804.0
{ | ||
"name": "@ckeditor/ckeditor5-paragraph", | ||
"version": "0.0.0-nightly-20230803.0", | ||
"version": "0.0.0-nightly-20230804.0", | ||
"description": "Paragraph feature for CKEditor 5.", | ||
@@ -15,5 +15,5 @@ "keywords": [ | ||
"dependencies": { | ||
"@ckeditor/ckeditor5-core": "0.0.0-nightly-20230803.0", | ||
"@ckeditor/ckeditor5-ui": "0.0.0-nightly-20230803.0", | ||
"@ckeditor/ckeditor5-utils": "0.0.0-nightly-20230803.0" | ||
"@ckeditor/ckeditor5-core": "0.0.0-nightly-20230804.0", | ||
"@ckeditor/ckeditor5-ui": "0.0.0-nightly-20230804.0", | ||
"@ckeditor/ckeditor5-utils": "0.0.0-nightly-20230804.0" | ||
}, | ||
@@ -20,0 +20,0 @@ "engines": { |
@@ -41,2 +41,6 @@ /** | ||
}): void; | ||
/** | ||
* Returns the best position to insert a new paragraph. | ||
*/ | ||
private _findPositionToInsertParagraph; | ||
} |
@@ -49,37 +49,10 @@ /** | ||
model.change(writer => { | ||
const paragraph = writer.createElement('paragraph'); | ||
const allowedParent = model.schema.findAllowedParent(position, paragraph); | ||
// It could be there's no ancestor limit that would allow paragraph. | ||
// In theory, "paragraph" could be disallowed even in the "$root". | ||
if (!allowedParent) { | ||
position = this._findPositionToInsertParagraph(position, writer); | ||
if (!position) { | ||
return; | ||
} | ||
const paragraph = writer.createElement('paragraph'); | ||
if (attributes) { | ||
model.schema.setAllowedAttributes(paragraph, attributes, writer); | ||
} | ||
if (position.path.length < 2) { | ||
model.insertContent(paragraph, position); | ||
writer.setSelection(paragraph, 'in'); | ||
return; | ||
} | ||
const positionParent = position.parent; | ||
// E.g. | ||
// <paragraph>[]</paragraph> ---> <paragraph></paragraph><paragraph>[]</paragraph> | ||
const isInEmptyBlock = positionParent.isEmpty; | ||
// E.g. | ||
// <paragraph>foo[]</paragraph> ---> <paragraph>foo</paragraph><paragraph>[]</paragraph> | ||
const isAtEndOfTextBlock = position.isAtEnd && !positionParent.isEmpty; | ||
// E.g. | ||
// <paragraph>[]foo</paragraph> ---> <paragraph>[]</paragraph><paragraph>foo</paragraph> | ||
const isAtStartOfTextBlock = position.isAtStart && !positionParent.isEmpty; | ||
const canBeChild = model.schema.checkChild(positionParent, paragraph); | ||
if (isInEmptyBlock || isAtEndOfTextBlock) { | ||
position = writer.createPositionAfter(positionParent); | ||
} | ||
else if (isAtStartOfTextBlock) { | ||
position = writer.createPositionBefore(positionParent); | ||
} | ||
else if (!canBeChild) { | ||
position = writer.split(position, allowedParent).position; | ||
} | ||
model.insertContent(paragraph, position); | ||
@@ -89,2 +62,31 @@ writer.setSelection(paragraph, 'in'); | ||
} | ||
/** | ||
* Returns the best position to insert a new paragraph. | ||
*/ | ||
_findPositionToInsertParagraph(position, writer) { | ||
const model = this.editor.model; | ||
if (model.schema.checkChild(position, 'paragraph')) { | ||
return position; | ||
} | ||
const allowedParent = model.schema.findAllowedParent(position, 'paragraph'); | ||
// It could be there's no ancestor limit that would allow paragraph. | ||
// In theory, "paragraph" could be disallowed even in the "$root". | ||
if (!allowedParent) { | ||
return null; | ||
} | ||
const positionParent = position.parent; | ||
const isTextAllowed = model.schema.checkChild(positionParent, '$text'); | ||
// At empty $block or at the end of $block. | ||
// <paragraph>[]</paragraph> ---> <paragraph></paragraph><paragraph>[]</paragraph> | ||
// <paragraph>foo[]</paragraph> ---> <paragraph>foo</paragraph><paragraph>[]</paragraph> | ||
if (positionParent.isEmpty || isTextAllowed && position.isAtEnd) { | ||
return model.createPositionAfter(positionParent); | ||
} | ||
// At the start of $block with text. | ||
// <paragraph>[]foo</paragraph> ---> <paragraph>[]</paragraph><paragraph>foo</paragraph> | ||
if (!positionParent.isEmpty && isTextAllowed && position.isAtStart) { | ||
return model.createPositionBefore(positionParent); | ||
} | ||
return writer.split(position, allowedParent).position; | ||
} | ||
} |
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
30026
555
+ Added@ckeditor/ckeditor5-core@0.0.0-nightly-20230804.0(transitive)
+ Added@ckeditor/ckeditor5-engine@0.0.0-nightly-20230804.0(transitive)
+ Added@ckeditor/ckeditor5-ui@0.0.0-nightly-20230804.0(transitive)
+ Added@ckeditor/ckeditor5-utils@0.0.0-nightly-20230804.0(transitive)
- Removed@ckeditor/ckeditor5-core@0.0.0-nightly-20230803.0(transitive)
- Removed@ckeditor/ckeditor5-engine@0.0.0-nightly-20230803.0(transitive)
- Removed@ckeditor/ckeditor5-ui@0.0.0-nightly-20230803.0(transitive)
- Removed@ckeditor/ckeditor5-utils@0.0.0-nightly-20230803.0(transitive)