@ckeditor/ckeditor5-paragraph 39.0.0 → 39.0.2

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/CHANGELOG.md CHANGED
@@ -100,7 +100,7 @@ Internal changes only (updated dependencies, documentation, etc.).
100
100
 
101
101
  ### BREAKING CHANGES
102
102
 
103
- * The license under which CKEditor 5 is released has been changed from a triple GPL, LGPL and MPL license to a GPL2+ only. See [ckeditor/ckeditor5#991](https://github.com/ckeditor/ckeditor5/issues/991) for more information.
103
+ * The license under which CKEditor 5 is released has been changed from a triple GPL, LGPL and MPL license to a GPL2+ only. See [ckeditor/ckeditor5#991](https://github.com/ckeditor/ckeditor5/issues/991) for more information.
104
104
 
105
105
 
106
106
  ## [1.0.0-beta.4](https://github.com/ckeditor/ckeditor5-paragraph/compare/v1.0.0-beta.2...v1.0.0-beta.4) (2018-04-19)
package/LICENSE.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Software License Agreement
2
2
  ==========================
3
3
 
4
- **CKEditor 5 paragraph feature** – https://github.com/ckeditor/ckeditor5-paragraph <br>
4
+ **CKEditor&nbsp;5 paragraph feature** – https://github.com/ckeditor/ckeditor5-paragraph <br>
5
5
  Copyright (c) 2003-2023, [CKSource Holding sp. z o.o.](https://cksource.com) All rights reserved.
6
6
 
7
7
  Licensed under the terms of [GNU General Public License Version 2 or later](http://www.gnu.org/licenses/gpl.html).
package/README.md CHANGED
@@ -1,15 +1,15 @@
1
- CKEditor 5 paragraph feature
1
+ CKEditor&nbsp;5 paragraph feature
2
2
  ========================================
3
3
 
4
4
  [![npm version](https://badge.fury.io/js/%40ckeditor%2Fckeditor5-paragraph.svg)](https://www.npmjs.com/package/@ckeditor/ckeditor5-paragraph)
5
5
  [![Coverage Status](https://coveralls.io/repos/github/ckeditor/ckeditor5/badge.svg?branch=master)](https://coveralls.io/github/ckeditor/ckeditor5?branch=master)
6
6
  [![Build Status](https://travis-ci.com/ckeditor/ckeditor5.svg?branch=master)](https://app.travis-ci.com/github/ckeditor/ckeditor5)
7
7
 
8
- This package implements paragraph support for CKEditor 5.
8
+ This package implements paragraph support for CKEditor&nbsp;5.
9
9
 
10
10
  ## Documentation
11
11
 
12
- See the [`@ckeditor/ckeditor5-paragraph` package](https://ckeditor.com/docs/ckeditor5/latest/api/paragraph.html) page in [CKEditor 5 documentation](https://ckeditor.com/docs/ckeditor5/latest/).
12
+ See the [`@ckeditor/ckeditor5-paragraph` package](https://ckeditor.com/docs/ckeditor5/latest/api/paragraph.html) page in [CKEditor&nbsp;5 documentation](https://ckeditor.com/docs/ckeditor5/latest/).
13
13
 
14
14
  ## License
15
15
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-paragraph",
3
- "version": "39.0.0",
3
+ "version": "39.0.2",
4
4
  "description": "Paragraph feature for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -12,13 +12,9 @@
12
12
  ],
13
13
  "main": "src/index.js",
14
14
  "dependencies": {
15
- "@ckeditor/ckeditor5-core": "39.0.0",
16
- "@ckeditor/ckeditor5-ui": "39.0.0",
17
- "@ckeditor/ckeditor5-utils": "39.0.0"
18
- },
19
- "engines": {
20
- "node": ">=16.0.0",
21
- "npm": ">=5.7.1"
15
+ "@ckeditor/ckeditor5-core": "39.0.2",
16
+ "@ckeditor/ckeditor5-ui": "39.0.2",
17
+ "@ckeditor/ckeditor5-utils": "39.0.2"
22
18
  },
23
19
  "author": "CKSource (http://cksource.com/)",
24
20
  "license": "GPL-2.0-or-later",
@@ -38,4 +38,8 @@ export default class InsertParagraphCommand extends Command {
38
38
  position: Position;
39
39
  attributes: Record<string, unknown>;
40
40
  }): void;
41
+ /**
42
+ * Returns the best position to insert a new paragraph.
43
+ */
44
+ private _findPositionToInsertParagraph;
41
45
  }
@@ -46,43 +46,45 @@ export default class InsertParagraphCommand extends Command {
46
46
  return;
47
47
  }
48
48
  model.change(writer => {
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) {
49
+ position = this._findPositionToInsertParagraph(position, writer);
50
+ if (!position) {
54
51
  return;
55
52
  }
53
+ const paragraph = writer.createElement('paragraph');
56
54
  if (attributes) {
57
55
  model.schema.setAllowedAttributes(paragraph, attributes, writer);
58
56
  }
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) {
82
- position = writer.split(position, allowedParent).position;
83
- }
84
57
  model.insertContent(paragraph, position);
85
58
  writer.setSelection(paragraph, 'in');
86
59
  });
87
60
  }
61
+ /**
62
+ * Returns the best position to insert a new paragraph.
63
+ */
64
+ _findPositionToInsertParagraph(position, writer) {
65
+ const model = this.editor.model;
66
+ if (model.schema.checkChild(position, 'paragraph')) {
67
+ return position;
68
+ }
69
+ const allowedParent = model.schema.findAllowedParent(position, 'paragraph');
70
+ // It could be there's no ancestor limit that would allow paragraph.
71
+ // In theory, "paragraph" could be disallowed even in the "$root".
72
+ if (!allowedParent) {
73
+ return null;
74
+ }
75
+ const positionParent = position.parent;
76
+ const isTextAllowed = model.schema.checkChild(positionParent, '$text');
77
+ // At empty $block or at the end of $block.
78
+ // <paragraph>[]</paragraph> ---> <paragraph></paragraph><paragraph>[]</paragraph>
79
+ // <paragraph>foo[]</paragraph> ---> <paragraph>foo</paragraph><paragraph>[]</paragraph>
80
+ if (positionParent.isEmpty || isTextAllowed && position.isAtEnd) {
81
+ return model.createPositionAfter(positionParent);
82
+ }
83
+ // At the start of $block with text.
84
+ // <paragraph>[]foo</paragraph> ---> <paragraph>[]</paragraph><paragraph>foo</paragraph>
85
+ if (!positionParent.isEmpty && isTextAllowed && position.isAtStart) {
86
+ return model.createPositionBefore(positionParent);
87
+ }
88
+ return writer.split(position, allowedParent).position;
89
+ }
88
90
  }