@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-paragraph",
3
- "version": "35.2.0",
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.2.0",
16
- "@ckeditor/ckeditor5-ui": "^35.2.0",
17
- "@ckeditor/ckeditor5-utils": "^35.2.0"
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.2.0",
21
- "@ckeditor/ckeditor5-clipboard": "^35.2.0",
22
- "@ckeditor/ckeditor5-editor-classic": "^35.2.0",
23
- "@ckeditor/ckeditor5-engine": "^35.2.0",
24
- "@ckeditor/ckeditor5-enter": "^35.2.0",
25
- "@ckeditor/ckeditor5-heading": "^35.2.0",
26
- "@ckeditor/ckeditor5-link": "^35.2.0",
27
- "@ckeditor/ckeditor5-typing": "^35.2.0",
28
- "@ckeditor/ckeditor5-undo": "^35.2.0"
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
- * 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
- * @param {Object} attributes Attributes keys and values to set on a inserted paragraph
37
- * @fires execute
38
- */
39
- execute( options ) {
40
- const model = this.editor.model;
41
- const attributes = options.attributes;
42
-
43
- let position = options.position;
44
-
45
- model.change( writer => {
46
- const paragraph = writer.createElement( 'paragraph' );
47
-
48
- if ( attributes ) {
49
- model.schema.setAllowedAttributes( paragraph, attributes, writer );
50
- }
51
-
52
- if ( !model.schema.checkChild( position.parent, paragraph ) ) {
53
- const allowedParent = model.schema.findAllowedParent( position, paragraph );
54
-
55
- // It could be there's no ancestor limit that would allow paragraph.
56
- // In theory, "paragraph" could be disallowed even in the "$root".
57
- if ( !allowedParent ) {
58
- return;
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
- * @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
- }
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
- * <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
- ] );
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
+ ]);
@@ -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
- 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
- }
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
  }
@@ -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
- * 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
- }
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( block, schema ) {
72
- return schema.checkChild( block.parent, 'paragraph' ) && !schema.isObject( block );
55
+ function checkCanBecomeParagraph(block, schema) {
56
+ return schema.checkChild(block.parent, 'paragraph') && !schema.isObject(block);
73
57
  }