Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ckeditor/ckeditor5-paragraph

Package Overview
Dependencies
Maintainers
1
Versions
711
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ckeditor/ckeditor5-paragraph - npm Package Compare versions

Comparing version 0.0.0-nightly-20230803.0 to 0.0.0-nightly-20230804.0

8

package.json
{
"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;
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc