@ckeditor/ckeditor5-paragraph 30.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/LICENSE.md ADDED
@@ -0,0 +1,17 @@
1
+ Software License Agreement
2
+ ==========================
3
+
4
+ **CKEditor 5 paragraph feature** – https://github.com/ckeditor/ckeditor5-paragraph <br>
5
+ Copyright (c) 2003-2021, [CKSource](http://cksource.com) Frederico Knabben. All rights reserved.
6
+
7
+ Licensed under the terms of [GNU General Public License Version 2 or later](http://www.gnu.org/licenses/gpl.html).
8
+
9
+ Sources of Intellectual Property Included in CKEditor
10
+ -----------------------------------------------------
11
+
12
+ Where not otherwise indicated, all CKEditor content is authored by CKSource engineers and consists of CKSource-owned intellectual property. In some specific instances, CKEditor will incorporate work done by developers outside of CKSource with their express permission.
13
+
14
+ Trademarks
15
+ ----------
16
+
17
+ **CKEditor** is a trademark of [CKSource](http://cksource.com) Frederico Knabben. All other brand and product names are trademarks, registered trademarks or service marks of their respective holders.
package/README.md ADDED
@@ -0,0 +1,16 @@
1
+ CKEditor 5 paragraph feature
2
+ ========================================
3
+
4
+ [![npm version](https://badge.fury.io/js/%40ckeditor%2Fckeditor5-paragraph.svg)](https://www.npmjs.com/package/@ckeditor/ckeditor5-paragraph)
5
+ [![Coverage Status](https://coveralls.io/repos/github/ckeditor/ckeditor5/badge.svg?branch=master)](https://coveralls.io/github/ckeditor/ckeditor5?branch=master)
6
+ [![Build Status](https://travis-ci.com/ckeditor/ckeditor5.svg?branch=master)](https://travis-ci.com/ckeditor/ckeditor5)
7
+
8
+ This package implements paragraph support for CKEditor 5.
9
+
10
+ ## Documentation
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/).
13
+
14
+ ## License
15
+
16
+ Licensed under the terms of [GNU General Public License Version 2 or later](http://www.gnu.org/licenses/gpl.html). For full details about the license, please check the `LICENSE.md` file or [https://ckeditor.com/legal/ckeditor-oss-license](https://ckeditor.com/legal/ckeditor-oss-license).
@@ -0,0 +1,17 @@
1
+ {
2
+ "plugins": [
3
+ {
4
+ "name": "Paragraph",
5
+ "className": "Paragraph",
6
+ "description": "Enables support for adding paragraphs to your content.",
7
+ "path": "src/paragraph.js",
8
+ "htmlOutput": [
9
+ {
10
+ "elements": "p",
11
+ "implements": "$block",
12
+ "_comment": "The HTML element may contain classes, styles or attributes that are created by other plugins, which alter the <code>`$block`</code> element."
13
+ }
14
+ ]
15
+ }
16
+ ]
17
+ }
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@ckeditor/ckeditor5-paragraph",
3
+ "version": "30.0.0",
4
+ "description": "Paragraph feature for CKEditor 5.",
5
+ "keywords": [
6
+ "ckeditor",
7
+ "ckeditor5",
8
+ "ckeditor 5",
9
+ "ckeditor5-feature",
10
+ "ckeditor5-plugin",
11
+ "ckeditor5-dll"
12
+ ],
13
+ "main": "src/index.js",
14
+ "dependencies": {
15
+ "@ckeditor/ckeditor5-core": "^30.0.0",
16
+ "@ckeditor/ckeditor5-ui": "^30.0.0",
17
+ "@ckeditor/ckeditor5-utils": "^30.0.0"
18
+ },
19
+ "devDependencies": {
20
+ "@ckeditor/ckeditor5-basic-styles": "^30.0.0",
21
+ "@ckeditor/ckeditor5-clipboard": "^30.0.0",
22
+ "@ckeditor/ckeditor5-editor-classic": "^30.0.0",
23
+ "@ckeditor/ckeditor5-engine": "^30.0.0",
24
+ "@ckeditor/ckeditor5-enter": "^30.0.0",
25
+ "@ckeditor/ckeditor5-heading": "^30.0.0",
26
+ "@ckeditor/ckeditor5-link": "^30.0.0",
27
+ "@ckeditor/ckeditor5-typing": "^30.0.0",
28
+ "@ckeditor/ckeditor5-undo": "^30.0.0"
29
+ },
30
+ "engines": {
31
+ "node": ">=12.0.0",
32
+ "npm": ">=5.7.1"
33
+ },
34
+ "author": "CKSource (http://cksource.com/)",
35
+ "license": "GPL-2.0-or-later",
36
+ "homepage": "https://ckeditor.com/ckeditor-5",
37
+ "bugs": "https://github.com/ckeditor/ckeditor5/issues",
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "https://github.com/ckeditor/ckeditor5.git",
41
+ "directory": "packages/ckeditor5-paragraph"
42
+ },
43
+ "files": [
44
+ "lang",
45
+ "src",
46
+ "theme",
47
+ "ckeditor5-metadata.json"
48
+ ]
49
+ }
package/src/index.js ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+
6
+ /**
7
+ * @module paragraph
8
+ */
9
+
10
+ export { default as Paragraph } from './paragraph';
11
+ export { default as ParagraphButtonUI } from './paragraphbuttonui';
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+
6
+ /**
7
+ * @module paragraph/insertparagraphcommand
8
+ */
9
+
10
+ import Command from '@ckeditor/ckeditor5-core/src/command';
11
+
12
+ /**
13
+ * The insert paragraph command. It inserts a new paragraph at a specific
14
+ * {@link module:engine/model/position~Position document position}.
15
+ *
16
+ * // Insert a new paragraph before an element in the document.
17
+ * editor.execute( 'insertParagraph', {
18
+ * position: editor.model.createPositionBefore( element )
19
+ * } );
20
+ *
21
+ * If a paragraph is disallowed in the context of the specific position, the command
22
+ * will attempt to split position ancestors to find a place where it is possible
23
+ * to insert a paragraph.
24
+ *
25
+ * **Note**: This command moves the selection to the inserted paragraph.
26
+ *
27
+ * @extends module:core/command~Command
28
+ */
29
+ export default class InsertParagraphCommand extends Command {
30
+ /**
31
+ * Executes the command.
32
+ *
33
+ * @param {Object} options Options for the executed command.
34
+ * @param {module:engine/model/position~Position} options.position The model position at which
35
+ * the new paragraph will be inserted.
36
+ * @fires execute
37
+ */
38
+ execute( options ) {
39
+ const model = this.editor.model;
40
+ let position = options.position;
41
+
42
+ model.change( writer => {
43
+ const paragraph = writer.createElement( 'paragraph' );
44
+
45
+ if ( !model.schema.checkChild( position.parent, paragraph ) ) {
46
+ const allowedParent = model.schema.findAllowedParent( position, paragraph );
47
+
48
+ // It could be there's no ancestor limit that would allow paragraph.
49
+ // In theory, "paragraph" could be disallowed even in the "$root".
50
+ if ( !allowedParent ) {
51
+ return;
52
+ }
53
+
54
+ position = writer.split( position, allowedParent ).position;
55
+ }
56
+
57
+ model.insertContent( paragraph, position );
58
+
59
+ writer.setSelection( paragraph, 'in' );
60
+ } );
61
+ }
62
+ }
@@ -0,0 +1,118 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+
6
+ /**
7
+ * @module paragraph/paragraph
8
+ */
9
+
10
+ import ParagraphCommand from './paragraphcommand';
11
+ import InsertParagraphCommand from './insertparagraphcommand';
12
+
13
+ import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
14
+
15
+ /**
16
+ * The paragraph feature for the editor.
17
+ *
18
+ * It introduces the `<paragraph>` element in the model which renders as a `<p>` element in the DOM and data.
19
+ *
20
+ * It also brings two editors commands:
21
+ *
22
+ * * The {@link module:paragraph/paragraphcommand~ParagraphCommand `'paragraph'`} command that converts all
23
+ * blocks in the model selection into paragraphs.
24
+ * * The {@link module:paragraph/insertparagraphcommand~InsertParagraphCommand `'insertParagraph'`} command
25
+ * that inserts a new paragraph at a specified location in the model.
26
+ *
27
+ * @extends module:core/plugin~Plugin
28
+ */
29
+ export default class Paragraph extends Plugin {
30
+ /**
31
+ * @inheritDoc
32
+ */
33
+ static get pluginName() {
34
+ return 'Paragraph';
35
+ }
36
+
37
+ /**
38
+ * @inheritDoc
39
+ */
40
+ init() {
41
+ const editor = this.editor;
42
+ const model = editor.model;
43
+
44
+ editor.commands.add( 'paragraph', new ParagraphCommand( editor ) );
45
+ editor.commands.add( 'insertParagraph', new InsertParagraphCommand( editor ) );
46
+
47
+ // Schema.
48
+ model.schema.register( 'paragraph', { inheritAllFrom: '$block' } );
49
+
50
+ editor.conversion.elementToElement( { model: 'paragraph', view: 'p' } );
51
+
52
+ // Conversion for paragraph-like elements which has not been converted by any plugin.
53
+ editor.conversion.for( 'upcast' ).elementToElement( {
54
+ model: ( viewElement, { writer } ) => {
55
+ if ( !Paragraph.paragraphLikeElements.has( viewElement.name ) ) {
56
+ return null;
57
+ }
58
+
59
+ // Do not auto-paragraph empty elements.
60
+ if ( viewElement.isEmpty ) {
61
+ return null;
62
+ }
63
+
64
+ return writer.createElement( 'paragraph' );
65
+ },
66
+ view: /.+/,
67
+ converterPriority: 'low'
68
+ } );
69
+ }
70
+ }
71
+
72
+ /**
73
+ * A list of element names which should be treated by the autoparagraphing algorithms as
74
+ * paragraph-like. This means that e.g. the following content:
75
+ *
76
+ * <h1>Foo</h1>
77
+ * <table>
78
+ * <tr>
79
+ * <td>X</td>
80
+ * <td>
81
+ * <ul>
82
+ * <li>Y</li>
83
+ * <li>Z</li>
84
+ * </ul>
85
+ * </td>
86
+ * </tr>
87
+ * </table>
88
+ *
89
+ * contains five paragraph-like elements: `<h1>`, two `<td>`s and two `<li>`s.
90
+ * Hence, if none of the features is going to convert those elements the above content will be automatically handled
91
+ * by the paragraph feature and converted to:
92
+ *
93
+ * <p>Foo</p>
94
+ * <p>X</p>
95
+ * <p>Y</p>
96
+ * <p>Z</p>
97
+ *
98
+ * Note: The `<td>` containing two `<li>` elements was ignored as the innermost paragraph-like elements
99
+ * have a priority upon conversion.
100
+ *
101
+ * @member {Set.<String>} module:paragraph/paragraph~Paragraph.paragraphLikeElements
102
+ */
103
+ Paragraph.paragraphLikeElements = new Set( [
104
+ 'blockquote',
105
+ 'dd',
106
+ 'div',
107
+ 'dt',
108
+ 'h1',
109
+ 'h2',
110
+ 'h3',
111
+ 'h4',
112
+ 'h5',
113
+ 'h6',
114
+ 'li',
115
+ 'p',
116
+ 'td',
117
+ 'th'
118
+ ] );
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+
6
+ /**
7
+ * @module paragraph/paragraphbuttonui
8
+ */
9
+
10
+ import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
11
+ import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
12
+ import icon from '../theme/icons/paragraph.svg';
13
+
14
+ /**
15
+ * This plugin defines the `'paragraph'` button. It can be used together with
16
+ * {@link module:heading/headingbuttonsui~HeadingButtonsUI} to replace the standard heading dropdown.
17
+ *
18
+ * This plugin is not loaded automatically by the {@link module:paragraph/paragraph~Paragraph} plugin. It must
19
+ * be added manually.
20
+ *
21
+ * ClassicEditor
22
+ * .create( {
23
+ * plugins: [ ..., Heading, Paragraph, HeadingButtonsUI, ParagraphButtonUI ]
24
+ * toolbar: [ 'paragraph', 'heading1', 'heading2', 'heading3' ]
25
+ * } )
26
+ * .then( ... )
27
+ * .catch( ... );
28
+ *
29
+ * @extends module:core/plugin~Plugin
30
+ */
31
+ export default class ParagraphButtonUI extends Plugin {
32
+ init() {
33
+ const editor = this.editor;
34
+ const t = editor.t;
35
+
36
+ editor.ui.componentFactory.add( 'paragraph', locale => {
37
+ const view = new ButtonView( locale );
38
+ const command = editor.commands.get( 'paragraph' );
39
+
40
+ view.label = t( 'Paragraph' );
41
+ view.icon = icon;
42
+ view.tooltip = true;
43
+ view.isToggleable = true;
44
+ view.bind( 'isEnabled' ).to( command );
45
+ view.bind( 'isOn' ).to( command, 'value' );
46
+
47
+ view.on( 'execute', () => {
48
+ editor.execute( 'paragraph' );
49
+ } );
50
+
51
+ return view;
52
+ } );
53
+ }
54
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+
6
+ /**
7
+ * @module paragraph/paragraphcommand
8
+ */
9
+
10
+ import Command from '@ckeditor/ckeditor5-core/src/command';
11
+ import first from '@ckeditor/ckeditor5-utils/src/first';
12
+
13
+ /**
14
+ * The paragraph command.
15
+ *
16
+ * @extends module:core/command~Command
17
+ */
18
+ export default class ParagraphCommand extends Command {
19
+ /**
20
+ * The value of the command. Indicates whether the selection start is placed in a paragraph.
21
+ *
22
+ * @readonly
23
+ * @observable
24
+ * @member {Boolean} #value
25
+ */
26
+
27
+ /**
28
+ * @inheritDoc
29
+ */
30
+ refresh() {
31
+ const model = this.editor.model;
32
+ const document = model.document;
33
+ const block = first( document.selection.getSelectedBlocks() );
34
+
35
+ this.value = !!block && block.is( 'element', 'paragraph' );
36
+ this.isEnabled = !!block && checkCanBecomeParagraph( block, model.schema );
37
+ }
38
+
39
+ /**
40
+ * Executes the command. All the blocks (see {@link module:engine/model/schema~Schema}) in the selection
41
+ * will be turned to paragraphs.
42
+ *
43
+ * @fires execute
44
+ * @param {Object} [options] Options for the executed command.
45
+ * @param {module:engine/model/selection~Selection|module:engine/model/documentselection~DocumentSelection} [options.selection]
46
+ * The selection that the command should be applied to.
47
+ * By default, if not provided, the command is applied to the {@link module:engine/model/document~Document#selection}.
48
+ */
49
+ execute( options = {} ) {
50
+ const model = this.editor.model;
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
+ }
63
+ }
64
+
65
+ // Checks whether the given block can be replaced by a paragraph.
66
+ //
67
+ // @private
68
+ // @param {module:engine/model/element~Element} block A block to be tested.
69
+ // @param {module:engine/model/schema~Schema} schema The schema of the document.
70
+ // @returns {Boolean}
71
+ function checkCanBecomeParagraph( block, schema ) {
72
+ return schema.checkChild( block.parent, 'paragraph' ) && !schema.isObject( block );
73
+ }
@@ -0,0 +1 @@
1
+ <svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M10.5 5.5H7v5h3.5a2.5 2.5 0 1 0 0-5zM5 3h6.5v.025a5 5 0 0 1 0 9.95V13H7v4a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1z"/></svg>