@ckeditor/ckeditor5-paragraph 38.2.0-alpha.0 → 39.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -1
- package/package.json +4 -5
- package/src/insertparagraphcommand.js +29 -7
package/README.md
CHANGED
|
@@ -4,7 +4,6 @@ CKEditor 5 paragraph feature
|
|
|
4
4
|
[](https://www.npmjs.com/package/@ckeditor/ckeditor5-paragraph)
|
|
5
5
|
[](https://coveralls.io/github/ckeditor/ckeditor5?branch=master)
|
|
6
6
|
[](https://app.travis-ci.com/github/ckeditor/ckeditor5)
|
|
7
|
-

|
|
8
7
|
|
|
9
8
|
This package implements paragraph support for CKEditor 5.
|
|
10
9
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckeditor/ckeditor5-paragraph",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "39.0.0",
|
|
4
4
|
"description": "Paragraph feature for CKEditor 5.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ckeditor",
|
|
@@ -11,11 +11,10 @@
|
|
|
11
11
|
"ckeditor5-dll"
|
|
12
12
|
],
|
|
13
13
|
"main": "src/index.js",
|
|
14
|
-
"type": "module",
|
|
15
14
|
"dependencies": {
|
|
16
|
-
"@ckeditor/ckeditor5-core": "
|
|
17
|
-
"@ckeditor/ckeditor5-ui": "
|
|
18
|
-
"@ckeditor/ckeditor5-utils": "
|
|
15
|
+
"@ckeditor/ckeditor5-core": "39.0.0",
|
|
16
|
+
"@ckeditor/ckeditor5-ui": "39.0.0",
|
|
17
|
+
"@ckeditor/ckeditor5-utils": "39.0.0"
|
|
19
18
|
},
|
|
20
19
|
"engines": {
|
|
21
20
|
"node": ">=16.0.0",
|
|
@@ -47,16 +47,38 @@ export default class InsertParagraphCommand extends Command {
|
|
|
47
47
|
}
|
|
48
48
|
model.change(writer => {
|
|
49
49
|
const paragraph = writer.createElement('paragraph');
|
|
50
|
+
const allowedParent = model.schema.findAllowedParent(position, paragraph);
|
|
51
|
+
// It could be there's no ancestor limit that would allow paragraph.
|
|
52
|
+
// In theory, "paragraph" could be disallowed even in the "$root".
|
|
53
|
+
if (!allowedParent) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
50
56
|
if (attributes) {
|
|
51
57
|
model.schema.setAllowedAttributes(paragraph, attributes, writer);
|
|
52
58
|
}
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
if (position.path.length < 2) {
|
|
60
|
+
model.insertContent(paragraph, position);
|
|
61
|
+
writer.setSelection(paragraph, 'in');
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const positionParent = position.parent;
|
|
65
|
+
// E.g.
|
|
66
|
+
// <paragraph>[]</paragraph> ---> <paragraph></paragraph><paragraph>[]</paragraph>
|
|
67
|
+
const isInEmptyBlock = positionParent.isEmpty;
|
|
68
|
+
// E.g.
|
|
69
|
+
// <paragraph>foo[]</paragraph> ---> <paragraph>foo</paragraph><paragraph>[]</paragraph>
|
|
70
|
+
const isAtEndOfTextBlock = position.isAtEnd && !positionParent.isEmpty;
|
|
71
|
+
// E.g.
|
|
72
|
+
// <paragraph>[]foo</paragraph> ---> <paragraph>[]</paragraph><paragraph>foo</paragraph>
|
|
73
|
+
const isAtStartOfTextBlock = position.isAtStart && !positionParent.isEmpty;
|
|
74
|
+
const canBeChild = model.schema.checkChild(positionParent, paragraph);
|
|
75
|
+
if (isInEmptyBlock || isAtEndOfTextBlock) {
|
|
76
|
+
position = writer.createPositionAfter(positionParent);
|
|
77
|
+
}
|
|
78
|
+
else if (isAtStartOfTextBlock) {
|
|
79
|
+
position = writer.createPositionBefore(positionParent);
|
|
80
|
+
}
|
|
81
|
+
else if (!canBeChild) {
|
|
60
82
|
position = writer.split(position, allowedParent).position;
|
|
61
83
|
}
|
|
62
84
|
model.insertContent(paragraph, position);
|