@ckeditor/ckeditor5-paragraph 35.2.0 → 35.3.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/package.json +23 -15
- package/src/index.js +0 -2
- package/src/insertparagraphcommand.js +31 -42
- package/src/paragraph.js +75 -87
- package/src/paragraphbuttonui.js +18 -25
- package/src/paragraphcommand.js +34 -50
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckeditor/ckeditor5-paragraph",
|
|
3
|
-
"version": "35.
|
|
3
|
+
"version": "35.3.0",
|
|
4
4
|
"description": "Paragraph feature for CKEditor 5.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ckeditor",
|
|
@@ -12,20 +12,23 @@
|
|
|
12
12
|
],
|
|
13
13
|
"main": "src/index.js",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@ckeditor/ckeditor5-core": "^35.
|
|
16
|
-
"@ckeditor/ckeditor5-ui": "^35.
|
|
17
|
-
"@ckeditor/ckeditor5-utils": "^35.
|
|
15
|
+
"@ckeditor/ckeditor5-core": "^35.3.0",
|
|
16
|
+
"@ckeditor/ckeditor5-ui": "^35.3.0",
|
|
17
|
+
"@ckeditor/ckeditor5-utils": "^35.3.0"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@ckeditor/ckeditor5-basic-styles": "^35.
|
|
21
|
-
"@ckeditor/ckeditor5-clipboard": "^35.
|
|
22
|
-
"@ckeditor/ckeditor5-editor-classic": "^35.
|
|
23
|
-
"@ckeditor/ckeditor5-engine": "^35.
|
|
24
|
-
"@ckeditor/ckeditor5-enter": "^35.
|
|
25
|
-
"@ckeditor/ckeditor5-heading": "^35.
|
|
26
|
-
"@ckeditor/ckeditor5-link": "^35.
|
|
27
|
-
"@ckeditor/ckeditor5-typing": "^35.
|
|
28
|
-
"@ckeditor/ckeditor5-undo": "^35.
|
|
20
|
+
"@ckeditor/ckeditor5-basic-styles": "^35.3.0",
|
|
21
|
+
"@ckeditor/ckeditor5-clipboard": "^35.3.0",
|
|
22
|
+
"@ckeditor/ckeditor5-editor-classic": "^35.3.0",
|
|
23
|
+
"@ckeditor/ckeditor5-engine": "^35.3.0",
|
|
24
|
+
"@ckeditor/ckeditor5-enter": "^35.3.0",
|
|
25
|
+
"@ckeditor/ckeditor5-heading": "^35.3.0",
|
|
26
|
+
"@ckeditor/ckeditor5-link": "^35.3.0",
|
|
27
|
+
"@ckeditor/ckeditor5-typing": "^35.3.0",
|
|
28
|
+
"@ckeditor/ckeditor5-undo": "^35.3.0",
|
|
29
|
+
"typescript": "^4.8.4",
|
|
30
|
+
"webpack": "^5.58.1",
|
|
31
|
+
"webpack-cli": "^4.9.0"
|
|
29
32
|
},
|
|
30
33
|
"engines": {
|
|
31
34
|
"node": ">=14.0.0",
|
|
@@ -42,9 +45,14 @@
|
|
|
42
45
|
},
|
|
43
46
|
"files": [
|
|
44
47
|
"lang",
|
|
45
|
-
"src",
|
|
48
|
+
"src/**/*.js",
|
|
49
|
+
"src/**/*.d.ts",
|
|
46
50
|
"theme",
|
|
47
51
|
"ckeditor5-metadata.json",
|
|
48
52
|
"CHANGELOG.md"
|
|
49
|
-
]
|
|
53
|
+
],
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "tsc -p ./tsconfig.release.json",
|
|
56
|
+
"postversion": "npm run build"
|
|
57
|
+
}
|
|
50
58
|
}
|
package/src/index.js
CHANGED
|
@@ -2,10 +2,8 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2022, 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
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module paragraph
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
export { default as Paragraph } from './paragraph';
|
|
11
9
|
export { default as ParagraphButtonUI } from './paragraphbuttonui';
|
|
@@ -2,13 +2,10 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2022, 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
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module paragraph/insertparagraphcommand
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import Command from '@ckeditor/ckeditor5-core/src/command';
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* The insert paragraph command. It inserts a new paragraph at a specific
|
|
14
11
|
* {@link module:engine/model/position~Position document position}.
|
|
@@ -27,43 +24,35 @@ import Command from '@ckeditor/ckeditor5-core/src/command';
|
|
|
27
24
|
* @extends module:core/command~Command
|
|
28
25
|
*/
|
|
29
26
|
export default class InsertParagraphCommand extends Command {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
position = writer.split( position, allowedParent ).position;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
model.insertContent( paragraph, position );
|
|
65
|
-
|
|
66
|
-
writer.setSelection( paragraph, 'in' );
|
|
67
|
-
} );
|
|
68
|
-
}
|
|
27
|
+
/**
|
|
28
|
+
* Executes the command.
|
|
29
|
+
*
|
|
30
|
+
* @param {Object} options Options for the executed command.
|
|
31
|
+
* @param {module:engine/model/position~Position} options.position The model position at which
|
|
32
|
+
* the new paragraph will be inserted.
|
|
33
|
+
* @param {Object} attributes Attributes keys and values to set on a inserted paragraph
|
|
34
|
+
* @fires execute
|
|
35
|
+
*/
|
|
36
|
+
execute(options) {
|
|
37
|
+
const model = this.editor.model;
|
|
38
|
+
const attributes = options.attributes;
|
|
39
|
+
let position = options.position;
|
|
40
|
+
model.change(writer => {
|
|
41
|
+
const paragraph = writer.createElement('paragraph');
|
|
42
|
+
if (attributes) {
|
|
43
|
+
model.schema.setAllowedAttributes(paragraph, attributes, writer);
|
|
44
|
+
}
|
|
45
|
+
if (!model.schema.checkChild(position.parent, paragraph)) {
|
|
46
|
+
const allowedParent = model.schema.findAllowedParent(position, paragraph);
|
|
47
|
+
// It could be there's no ancestor limit that would allow paragraph.
|
|
48
|
+
// In theory, "paragraph" could be disallowed even in the "$root".
|
|
49
|
+
if (!allowedParent) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
position = writer.split(position, allowedParent).position;
|
|
53
|
+
}
|
|
54
|
+
model.insertContent(paragraph, position);
|
|
55
|
+
writer.setSelection(paragraph, 'in');
|
|
56
|
+
});
|
|
57
|
+
}
|
|
69
58
|
}
|
package/src/paragraph.js
CHANGED
|
@@ -2,16 +2,12 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2022, 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
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module paragraph/paragraph
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import ParagraphCommand from './paragraphcommand';
|
|
11
9
|
import InsertParagraphCommand from './insertparagraphcommand';
|
|
12
|
-
|
|
13
10
|
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
|
|
14
|
-
|
|
15
11
|
/**
|
|
16
12
|
* The paragraph feature for the editor.
|
|
17
13
|
*
|
|
@@ -27,92 +23,84 @@ import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
|
|
|
27
23
|
* @extends module:core/plugin~Plugin
|
|
28
24
|
*/
|
|
29
25
|
export default class Paragraph extends Plugin {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return writer.createElement( 'paragraph' );
|
|
65
|
-
},
|
|
66
|
-
view: /.+/,
|
|
67
|
-
converterPriority: 'low'
|
|
68
|
-
} );
|
|
69
|
-
}
|
|
26
|
+
/**
|
|
27
|
+
* @inheritDoc
|
|
28
|
+
*/
|
|
29
|
+
static get pluginName() {
|
|
30
|
+
return 'Paragraph';
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* @inheritDoc
|
|
34
|
+
*/
|
|
35
|
+
init() {
|
|
36
|
+
const editor = this.editor;
|
|
37
|
+
const model = editor.model;
|
|
38
|
+
editor.commands.add('paragraph', new ParagraphCommand(editor));
|
|
39
|
+
editor.commands.add('insertParagraph', new InsertParagraphCommand(editor));
|
|
40
|
+
// Schema.
|
|
41
|
+
model.schema.register('paragraph', { inheritAllFrom: '$block' });
|
|
42
|
+
editor.conversion.elementToElement({ model: 'paragraph', view: 'p' });
|
|
43
|
+
// Conversion for paragraph-like elements which has not been converted by any plugin.
|
|
44
|
+
editor.conversion.for('upcast').elementToElement({
|
|
45
|
+
model: (viewElement, { writer }) => {
|
|
46
|
+
if (!Paragraph.paragraphLikeElements.has(viewElement.name)) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
// Do not auto-paragraph empty elements.
|
|
50
|
+
if (viewElement.isEmpty) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
return writer.createElement('paragraph');
|
|
54
|
+
},
|
|
55
|
+
view: /.+/,
|
|
56
|
+
converterPriority: 'low'
|
|
57
|
+
});
|
|
58
|
+
}
|
|
70
59
|
}
|
|
71
|
-
|
|
72
60
|
/**
|
|
73
61
|
* A list of element names which should be treated by the autoparagraphing algorithms as
|
|
74
62
|
* paragraph-like. This means that e.g. the following content:
|
|
75
63
|
*
|
|
76
64
|
* <h1>Foo</h1>
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
Paragraph.paragraphLikeElements = new Set(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
]
|
|
65
|
+
* <table>
|
|
66
|
+
* <tr>
|
|
67
|
+
* <td>X</td>
|
|
68
|
+
* <td>
|
|
69
|
+
* <ul>
|
|
70
|
+
* <li>Y</li>
|
|
71
|
+
* <li>Z</li>
|
|
72
|
+
* </ul>
|
|
73
|
+
* </td>
|
|
74
|
+
* </tr>
|
|
75
|
+
* </table>
|
|
76
|
+
*
|
|
77
|
+
* contains five paragraph-like elements: `<h1>`, two `<td>`s and two `<li>`s.
|
|
78
|
+
* Hence, if none of the features is going to convert those elements the above content will be automatically handled
|
|
79
|
+
* by the paragraph feature and converted to:
|
|
80
|
+
*
|
|
81
|
+
* <p>Foo</p>
|
|
82
|
+
* <p>X</p>
|
|
83
|
+
* <p>Y</p>
|
|
84
|
+
* <p>Z</p>
|
|
85
|
+
*
|
|
86
|
+
* Note: The `<td>` containing two `<li>` elements was ignored as the innermost paragraph-like elements
|
|
87
|
+
* have a priority upon conversion.
|
|
88
|
+
*
|
|
89
|
+
* @member {Set.<String>} module:paragraph/paragraph~Paragraph.paragraphLikeElements
|
|
90
|
+
*/
|
|
91
|
+
Paragraph.paragraphLikeElements = new Set([
|
|
92
|
+
'blockquote',
|
|
93
|
+
'dd',
|
|
94
|
+
'div',
|
|
95
|
+
'dt',
|
|
96
|
+
'h1',
|
|
97
|
+
'h2',
|
|
98
|
+
'h3',
|
|
99
|
+
'h4',
|
|
100
|
+
'h5',
|
|
101
|
+
'h6',
|
|
102
|
+
'li',
|
|
103
|
+
'p',
|
|
104
|
+
'td',
|
|
105
|
+
'th'
|
|
106
|
+
]);
|
package/src/paragraphbuttonui.js
CHANGED
|
@@ -2,15 +2,12 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2022, 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
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module paragraph/paragraphbuttonui
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
|
|
11
9
|
import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
|
|
12
10
|
import icon from '@ckeditor/ckeditor5-core/theme/icons/paragraph.svg';
|
|
13
|
-
|
|
14
11
|
/**
|
|
15
12
|
* This plugin defines the `'paragraph'` button. It can be used together with
|
|
16
13
|
* {@link module:heading/headingbuttonsui~HeadingButtonsUI} to replace the standard heading dropdown.
|
|
@@ -29,26 +26,22 @@ import icon from '@ckeditor/ckeditor5-core/theme/icons/paragraph.svg';
|
|
|
29
26
|
* @extends module:core/plugin~Plugin
|
|
30
27
|
*/
|
|
31
28
|
export default class ParagraphButtonUI extends Plugin {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return view;
|
|
52
|
-
} );
|
|
53
|
-
}
|
|
29
|
+
init() {
|
|
30
|
+
const editor = this.editor;
|
|
31
|
+
const t = editor.t;
|
|
32
|
+
editor.ui.componentFactory.add('paragraph', locale => {
|
|
33
|
+
const view = new ButtonView(locale);
|
|
34
|
+
const command = editor.commands.get('paragraph');
|
|
35
|
+
view.label = t('Paragraph');
|
|
36
|
+
view.icon = icon;
|
|
37
|
+
view.tooltip = true;
|
|
38
|
+
view.isToggleable = true;
|
|
39
|
+
view.bind('isEnabled').to(command);
|
|
40
|
+
view.bind('isOn').to(command, 'value');
|
|
41
|
+
view.on('execute', () => {
|
|
42
|
+
editor.execute('paragraph');
|
|
43
|
+
});
|
|
44
|
+
return view;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
54
47
|
}
|
package/src/paragraphcommand.js
CHANGED
|
@@ -2,72 +2,56 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2022, 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
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module paragraph/paragraphcommand
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import Command from '@ckeditor/ckeditor5-core/src/command';
|
|
11
9
|
import first from '@ckeditor/ckeditor5-utils/src/first';
|
|
12
|
-
|
|
13
10
|
/**
|
|
14
11
|
* The paragraph command.
|
|
15
12
|
*
|
|
16
13
|
* @extends module:core/command~Command
|
|
17
14
|
*/
|
|
18
15
|
export default class ParagraphCommand extends Command {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const document = model.document;
|
|
52
|
-
|
|
53
|
-
model.change( writer => {
|
|
54
|
-
const blocks = ( options.selection || document.selection ).getSelectedBlocks();
|
|
55
|
-
|
|
56
|
-
for ( const block of blocks ) {
|
|
57
|
-
if ( !block.is( 'element', 'paragraph' ) && checkCanBecomeParagraph( block, model.schema ) ) {
|
|
58
|
-
writer.rename( block, 'paragraph' );
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
} );
|
|
62
|
-
}
|
|
16
|
+
/**
|
|
17
|
+
* @inheritDoc
|
|
18
|
+
*/
|
|
19
|
+
refresh() {
|
|
20
|
+
const model = this.editor.model;
|
|
21
|
+
const document = model.document;
|
|
22
|
+
const block = first(document.selection.getSelectedBlocks());
|
|
23
|
+
this.value = !!block && block.is('element', 'paragraph');
|
|
24
|
+
this.isEnabled = !!block && checkCanBecomeParagraph(block, model.schema);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Executes the command. All the blocks (see {@link module:engine/model/schema~Schema}) in the selection
|
|
28
|
+
* will be turned to paragraphs.
|
|
29
|
+
*
|
|
30
|
+
* @fires execute
|
|
31
|
+
* @param {Object} [options] Options for the executed command.
|
|
32
|
+
* @param {module:engine/model/selection~Selection|module:engine/model/documentselection~DocumentSelection} [options.selection]
|
|
33
|
+
* The selection that the command should be applied to.
|
|
34
|
+
* By default, if not provided, the command is applied to the {@link module:engine/model/document~Document#selection}.
|
|
35
|
+
*/
|
|
36
|
+
execute(options = {}) {
|
|
37
|
+
const model = this.editor.model;
|
|
38
|
+
const document = model.document;
|
|
39
|
+
model.change(writer => {
|
|
40
|
+
const blocks = (options.selection || document.selection).getSelectedBlocks();
|
|
41
|
+
for (const block of blocks) {
|
|
42
|
+
if (!block.is('element', 'paragraph') && checkCanBecomeParagraph(block, model.schema)) {
|
|
43
|
+
writer.rename(block, 'paragraph');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
63
48
|
}
|
|
64
|
-
|
|
65
49
|
// Checks whether the given block can be replaced by a paragraph.
|
|
66
50
|
//
|
|
67
51
|
// @private
|
|
68
52
|
// @param {module:engine/model/element~Element} block A block to be tested.
|
|
69
53
|
// @param {module:engine/model/schema~Schema} schema The schema of the document.
|
|
70
54
|
// @returns {Boolean}
|
|
71
|
-
function checkCanBecomeParagraph(
|
|
72
|
-
|
|
55
|
+
function checkCanBecomeParagraph(block, schema) {
|
|
56
|
+
return schema.checkChild(block.parent, 'paragraph') && !schema.isObject(block);
|
|
73
57
|
}
|