@ckeditor/ckeditor5-paragraph 38.2.0-alpha.1 → 39.0.1
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/augmentation.d.ts +1 -1
- package/src/index.d.ts +5 -5
- package/src/index.js +3 -3
- package/src/insertparagraphcommand.d.ts +4 -0
- package/src/insertparagraphcommand.js +32 -30
- package/src/paragraph.js +2 -2
- package/src/paragraphbuttonui.d.ts +1 -1
- package/src/paragraphbuttonui.js +1 -1
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.1",
|
|
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.1",
|
|
16
|
+
"@ckeditor/ckeditor5-ui": "39.0.1",
|
|
17
|
+
"@ckeditor/ckeditor5-utils": "39.0.1"
|
|
19
18
|
},
|
|
20
19
|
"engines": {
|
|
21
20
|
"node": ">=16.0.0",
|
package/src/augmentation.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
import type { Paragraph, ParagraphCommand, InsertParagraphCommand } from './index
|
|
5
|
+
import type { Paragraph, ParagraphCommand, InsertParagraphCommand } from './index';
|
|
6
6
|
declare module '@ckeditor/ckeditor5-core' {
|
|
7
7
|
interface CommandsMap {
|
|
8
8
|
insertParagraph: InsertParagraphCommand;
|
package/src/index.d.ts
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module paragraph
|
|
7
7
|
*/
|
|
8
|
-
export { default as Paragraph } from './paragraph
|
|
9
|
-
export { default as ParagraphButtonUI } from './paragraphbuttonui
|
|
10
|
-
export type { default as ParagraphCommand } from './paragraphcommand
|
|
11
|
-
export type { default as InsertParagraphCommand } from './insertparagraphcommand
|
|
12
|
-
import './augmentation
|
|
8
|
+
export { default as Paragraph } from './paragraph';
|
|
9
|
+
export { default as ParagraphButtonUI } from './paragraphbuttonui';
|
|
10
|
+
export type { default as ParagraphCommand } from './paragraphcommand';
|
|
11
|
+
export type { default as InsertParagraphCommand } from './insertparagraphcommand';
|
|
12
|
+
import './augmentation';
|
package/src/index.js
CHANGED
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module paragraph
|
|
7
7
|
*/
|
|
8
|
-
export { default as Paragraph } from './paragraph
|
|
9
|
-
export { default as ParagraphButtonUI } from './paragraphbuttonui
|
|
10
|
-
import './augmentation
|
|
8
|
+
export { default as Paragraph } from './paragraph';
|
|
9
|
+
export { default as ParagraphButtonUI } from './paragraphbuttonui';
|
|
10
|
+
import './augmentation';
|
|
@@ -46,43 +46,45 @@ export default class InsertParagraphCommand extends Command {
|
|
|
46
46
|
return;
|
|
47
47
|
}
|
|
48
48
|
model.change(writer => {
|
|
49
|
-
|
|
50
|
-
|
|
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
|
}
|
package/src/paragraph.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module paragraph/paragraph
|
|
7
7
|
*/
|
|
8
|
-
import ParagraphCommand from './paragraphcommand
|
|
9
|
-
import InsertParagraphCommand from './insertparagraphcommand
|
|
8
|
+
import ParagraphCommand from './paragraphcommand';
|
|
9
|
+
import InsertParagraphCommand from './insertparagraphcommand';
|
|
10
10
|
import { Plugin } from '@ckeditor/ckeditor5-core';
|
|
11
11
|
/**
|
|
12
12
|
* The paragraph feature for the editor.
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @module paragraph/paragraphbuttonui
|
|
7
7
|
*/
|
|
8
8
|
import { Plugin } from '@ckeditor/ckeditor5-core';
|
|
9
|
-
import Paragraph from './paragraph
|
|
9
|
+
import Paragraph from './paragraph';
|
|
10
10
|
/**
|
|
11
11
|
* This plugin defines the `'paragraph'` button. It can be used together with
|
|
12
12
|
* {@link module:heading/headingbuttonsui~HeadingButtonsUI} to replace the standard heading dropdown.
|
package/src/paragraphbuttonui.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { Plugin, icons } from '@ckeditor/ckeditor5-core';
|
|
9
9
|
import { ButtonView } from '@ckeditor/ckeditor5-ui';
|
|
10
|
-
import Paragraph from './paragraph
|
|
10
|
+
import Paragraph from './paragraph';
|
|
11
11
|
const icon = icons.paragraph;
|
|
12
12
|
/**
|
|
13
13
|
* This plugin defines the `'paragraph'` button. It can be used together with
|