@ckeditor/ckeditor5-paragraph 40.0.0 → 40.1.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 +2 -2
- package/package.json +4 -4
- package/src/augmentation.d.ts +14 -14
- package/src/augmentation.js +5 -5
- package/src/index.d.ts +12 -12
- package/src/index.js +10 -10
- package/src/insertparagraphcommand.d.ts +45 -45
- package/src/insertparagraphcommand.js +90 -90
- package/src/paragraph.d.ts +61 -61
- package/src/paragraph.js +106 -106
- package/src/paragraphbuttonui.d.ts +36 -36
- package/src/paragraphbuttonui.js +57 -57
- package/src/paragraphcommand.d.ts +38 -38
- package/src/paragraphcommand.js +64 -64
package/LICENSE.md
CHANGED
|
@@ -2,7 +2,7 @@ Software License Agreement
|
|
|
2
2
|
==========================
|
|
3
3
|
|
|
4
4
|
**CKEditor 5 paragraph feature** – https://github.com/ckeditor/ckeditor5-paragraph <br>
|
|
5
|
-
Copyright (c) 2003
|
|
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).
|
|
8
8
|
|
|
@@ -14,4 +14,4 @@ Where not otherwise indicated, all CKEditor content is authored by CKSource engi
|
|
|
14
14
|
Trademarks
|
|
15
15
|
----------
|
|
16
16
|
|
|
17
|
-
**CKEditor** is a trademark of [CKSource Holding sp. z o.o.](https://cksource.com) All other brand and product names are trademarks, registered trademarks or service marks of their respective holders.
|
|
17
|
+
**CKEditor** is a trademark of [CKSource Holding sp. z o.o.](https://cksource.com) All other brand and product names are trademarks, registered trademarks, or service marks of their respective holders.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckeditor/ckeditor5-paragraph",
|
|
3
|
-
"version": "40.
|
|
3
|
+
"version": "40.1.0",
|
|
4
4
|
"description": "Paragraph feature for CKEditor 5.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ckeditor",
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
],
|
|
13
13
|
"main": "src/index.js",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@ckeditor/ckeditor5-core": "40.
|
|
16
|
-
"@ckeditor/ckeditor5-ui": "40.
|
|
17
|
-
"@ckeditor/ckeditor5-utils": "40.
|
|
15
|
+
"@ckeditor/ckeditor5-core": "40.1.0",
|
|
16
|
+
"@ckeditor/ckeditor5-ui": "40.1.0",
|
|
17
|
+
"@ckeditor/ckeditor5-utils": "40.1.0"
|
|
18
18
|
},
|
|
19
19
|
"author": "CKSource (http://cksource.com/)",
|
|
20
20
|
"license": "GPL-2.0-or-later",
|
package/src/augmentation.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
import type { Paragraph, ParagraphCommand, InsertParagraphCommand } from './index';
|
|
6
|
-
declare module '@ckeditor/ckeditor5-core' {
|
|
7
|
-
interface CommandsMap {
|
|
8
|
-
insertParagraph: InsertParagraphCommand;
|
|
9
|
-
paragraph: ParagraphCommand;
|
|
10
|
-
}
|
|
11
|
-
interface PluginsMap {
|
|
12
|
-
[Paragraph.pluginName]: Paragraph;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
import type { Paragraph, ParagraphCommand, InsertParagraphCommand } from './index';
|
|
6
|
+
declare module '@ckeditor/ckeditor5-core' {
|
|
7
|
+
interface CommandsMap {
|
|
8
|
+
insertParagraph: InsertParagraphCommand;
|
|
9
|
+
paragraph: ParagraphCommand;
|
|
10
|
+
}
|
|
11
|
+
interface PluginsMap {
|
|
12
|
+
[Paragraph.pluginName]: Paragraph;
|
|
13
|
+
}
|
|
14
|
+
}
|
package/src/augmentation.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
export {};
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
export {};
|
package/src/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module paragraph
|
|
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';
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module paragraph
|
|
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';
|
package/src/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module paragraph
|
|
7
|
-
*/
|
|
8
|
-
export { default as Paragraph } from './paragraph';
|
|
9
|
-
export { default as ParagraphButtonUI } from './paragraphbuttonui';
|
|
10
|
-
import './augmentation';
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module paragraph
|
|
7
|
+
*/
|
|
8
|
+
export { default as Paragraph } from './paragraph';
|
|
9
|
+
export { default as ParagraphButtonUI } from './paragraphbuttonui';
|
|
10
|
+
import './augmentation';
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module paragraph/insertparagraphcommand
|
|
7
|
-
*/
|
|
8
|
-
import { Command, type Editor } from '@ckeditor/ckeditor5-core';
|
|
9
|
-
import type { Position } from '@ckeditor/ckeditor5-engine';
|
|
10
|
-
/**
|
|
11
|
-
* The insert paragraph command. It inserts a new paragraph at a specific
|
|
12
|
-
* {@link module:engine/model/position~Position document position}.
|
|
13
|
-
*
|
|
14
|
-
* ```ts
|
|
15
|
-
* // Insert a new paragraph before an element in the document.
|
|
16
|
-
* editor.execute( 'insertParagraph', {
|
|
17
|
-
* position: editor.model.createPositionBefore( element )
|
|
18
|
-
* } );
|
|
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
|
-
export default class InsertParagraphCommand extends Command {
|
|
28
|
-
constructor(editor: Editor);
|
|
29
|
-
/**
|
|
30
|
-
* Executes the command.
|
|
31
|
-
*
|
|
32
|
-
* @param options Options for the executed command.
|
|
33
|
-
* @param options.position The model position at which the new paragraph will be inserted.
|
|
34
|
-
* @param options.attributes Attributes keys and values to set on a inserted paragraph.
|
|
35
|
-
* @fires execute
|
|
36
|
-
*/
|
|
37
|
-
execute(options: {
|
|
38
|
-
position: Position;
|
|
39
|
-
attributes
|
|
40
|
-
}): void;
|
|
41
|
-
/**
|
|
42
|
-
* Returns the best position to insert a new paragraph.
|
|
43
|
-
*/
|
|
44
|
-
private _findPositionToInsertParagraph;
|
|
45
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module paragraph/insertparagraphcommand
|
|
7
|
+
*/
|
|
8
|
+
import { Command, type Editor } from '@ckeditor/ckeditor5-core';
|
|
9
|
+
import type { Position } from '@ckeditor/ckeditor5-engine';
|
|
10
|
+
/**
|
|
11
|
+
* The insert paragraph command. It inserts a new paragraph at a specific
|
|
12
|
+
* {@link module:engine/model/position~Position document position}.
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* // Insert a new paragraph before an element in the document.
|
|
16
|
+
* editor.execute( 'insertParagraph', {
|
|
17
|
+
* position: editor.model.createPositionBefore( element )
|
|
18
|
+
* } );
|
|
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
|
+
export default class InsertParagraphCommand extends Command {
|
|
28
|
+
constructor(editor: Editor);
|
|
29
|
+
/**
|
|
30
|
+
* Executes the command.
|
|
31
|
+
*
|
|
32
|
+
* @param options Options for the executed command.
|
|
33
|
+
* @param options.position The model position at which the new paragraph will be inserted.
|
|
34
|
+
* @param options.attributes Attributes keys and values to set on a inserted paragraph.
|
|
35
|
+
* @fires execute
|
|
36
|
+
*/
|
|
37
|
+
execute(options: {
|
|
38
|
+
position: Position;
|
|
39
|
+
attributes?: Record<string, unknown>;
|
|
40
|
+
}): void;
|
|
41
|
+
/**
|
|
42
|
+
* Returns the best position to insert a new paragraph.
|
|
43
|
+
*/
|
|
44
|
+
private _findPositionToInsertParagraph;
|
|
45
|
+
}
|
|
@@ -1,90 +1,90 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module paragraph/insertparagraphcommand
|
|
7
|
-
*/
|
|
8
|
-
import { Command } from '@ckeditor/ckeditor5-core';
|
|
9
|
-
/**
|
|
10
|
-
* The insert paragraph command. It inserts a new paragraph at a specific
|
|
11
|
-
* {@link module:engine/model/position~Position document position}.
|
|
12
|
-
*
|
|
13
|
-
* ```ts
|
|
14
|
-
* // Insert a new paragraph before an element in the document.
|
|
15
|
-
* editor.execute( 'insertParagraph', {
|
|
16
|
-
* position: editor.model.createPositionBefore( element )
|
|
17
|
-
* } );
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
* If a paragraph is disallowed in the context of the specific position, the command
|
|
21
|
-
* will attempt to split position ancestors to find a place where it is possible
|
|
22
|
-
* to insert a paragraph.
|
|
23
|
-
*
|
|
24
|
-
* **Note**: This command moves the selection to the inserted paragraph.
|
|
25
|
-
*/
|
|
26
|
-
export default class InsertParagraphCommand extends Command {
|
|
27
|
-
constructor(editor) {
|
|
28
|
-
super(editor);
|
|
29
|
-
// Since this command passes position in execution block instead of selection, it should be checked directly.
|
|
30
|
-
this._isEnabledBasedOnSelection = false;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Executes the command.
|
|
34
|
-
*
|
|
35
|
-
* @param options Options for the executed command.
|
|
36
|
-
* @param options.position The model position at which the new paragraph will be inserted.
|
|
37
|
-
* @param options.attributes Attributes keys and values to set on a inserted paragraph.
|
|
38
|
-
* @fires execute
|
|
39
|
-
*/
|
|
40
|
-
execute(options) {
|
|
41
|
-
const model = this.editor.model;
|
|
42
|
-
const attributes = options.attributes;
|
|
43
|
-
let position = options.position;
|
|
44
|
-
// Don't execute command if position is in non-editable place.
|
|
45
|
-
if (!model.canEditAt(position)) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
model.change(writer => {
|
|
49
|
-
position = this._findPositionToInsertParagraph(position, writer);
|
|
50
|
-
if (!position) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
const paragraph = writer.createElement('paragraph');
|
|
54
|
-
if (attributes) {
|
|
55
|
-
model.schema.setAllowedAttributes(paragraph, attributes, writer);
|
|
56
|
-
}
|
|
57
|
-
model.insertContent(paragraph, position);
|
|
58
|
-
writer.setSelection(paragraph, 'in');
|
|
59
|
-
});
|
|
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
|
-
}
|
|
90
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module paragraph/insertparagraphcommand
|
|
7
|
+
*/
|
|
8
|
+
import { Command } from '@ckeditor/ckeditor5-core';
|
|
9
|
+
/**
|
|
10
|
+
* The insert paragraph command. It inserts a new paragraph at a specific
|
|
11
|
+
* {@link module:engine/model/position~Position document position}.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* // Insert a new paragraph before an element in the document.
|
|
15
|
+
* editor.execute( 'insertParagraph', {
|
|
16
|
+
* position: editor.model.createPositionBefore( element )
|
|
17
|
+
* } );
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* If a paragraph is disallowed in the context of the specific position, the command
|
|
21
|
+
* will attempt to split position ancestors to find a place where it is possible
|
|
22
|
+
* to insert a paragraph.
|
|
23
|
+
*
|
|
24
|
+
* **Note**: This command moves the selection to the inserted paragraph.
|
|
25
|
+
*/
|
|
26
|
+
export default class InsertParagraphCommand extends Command {
|
|
27
|
+
constructor(editor) {
|
|
28
|
+
super(editor);
|
|
29
|
+
// Since this command passes position in execution block instead of selection, it should be checked directly.
|
|
30
|
+
this._isEnabledBasedOnSelection = false;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Executes the command.
|
|
34
|
+
*
|
|
35
|
+
* @param options Options for the executed command.
|
|
36
|
+
* @param options.position The model position at which the new paragraph will be inserted.
|
|
37
|
+
* @param options.attributes Attributes keys and values to set on a inserted paragraph.
|
|
38
|
+
* @fires execute
|
|
39
|
+
*/
|
|
40
|
+
execute(options) {
|
|
41
|
+
const model = this.editor.model;
|
|
42
|
+
const attributes = options.attributes;
|
|
43
|
+
let position = options.position;
|
|
44
|
+
// Don't execute command if position is in non-editable place.
|
|
45
|
+
if (!model.canEditAt(position)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
model.change(writer => {
|
|
49
|
+
position = this._findPositionToInsertParagraph(position, writer);
|
|
50
|
+
if (!position) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const paragraph = writer.createElement('paragraph');
|
|
54
|
+
if (attributes) {
|
|
55
|
+
model.schema.setAllowedAttributes(paragraph, attributes, writer);
|
|
56
|
+
}
|
|
57
|
+
model.insertContent(paragraph, position);
|
|
58
|
+
writer.setSelection(paragraph, 'in');
|
|
59
|
+
});
|
|
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
|
+
}
|
|
90
|
+
}
|
package/src/paragraph.d.ts
CHANGED
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
import { Plugin } from '@ckeditor/ckeditor5-core';
|
|
6
|
-
/**
|
|
7
|
-
* The paragraph feature for the editor.
|
|
8
|
-
*
|
|
9
|
-
* It introduces the `<paragraph>` element in the model which renders as a `<p>` element in the DOM and data.
|
|
10
|
-
*
|
|
11
|
-
* It also brings two editors commands:
|
|
12
|
-
*
|
|
13
|
-
* * The {@link module:paragraph/paragraphcommand~ParagraphCommand `'paragraph'`} command that converts all
|
|
14
|
-
* blocks in the model selection into paragraphs.
|
|
15
|
-
* * The {@link module:paragraph/insertparagraphcommand~InsertParagraphCommand `'insertParagraph'`} command
|
|
16
|
-
* that inserts a new paragraph at a specified location in the model.
|
|
17
|
-
*/
|
|
18
|
-
export default class Paragraph extends Plugin {
|
|
19
|
-
/**
|
|
20
|
-
* @inheritDoc
|
|
21
|
-
*/
|
|
22
|
-
static get pluginName(): "Paragraph";
|
|
23
|
-
/**
|
|
24
|
-
* @inheritDoc
|
|
25
|
-
*/
|
|
26
|
-
init(): void;
|
|
27
|
-
/**
|
|
28
|
-
* A list of element names which should be treated by the autoparagraphing algorithms as
|
|
29
|
-
* paragraph-like. This means that e.g. the following content:
|
|
30
|
-
*
|
|
31
|
-
* ```html
|
|
32
|
-
* <h1>Foo</h1>
|
|
33
|
-
* <table>
|
|
34
|
-
* <tr>
|
|
35
|
-
* <td>X</td>
|
|
36
|
-
* <td>
|
|
37
|
-
* <ul>
|
|
38
|
-
* <li>Y</li>
|
|
39
|
-
* <li>Z</li>
|
|
40
|
-
* </ul>
|
|
41
|
-
* </td>
|
|
42
|
-
* </tr>
|
|
43
|
-
* </table>
|
|
44
|
-
* ```
|
|
45
|
-
*
|
|
46
|
-
* contains five paragraph-like elements: `<h1>`, two `<td>`s and two `<li>`s.
|
|
47
|
-
* Hence, if none of the features is going to convert those elements the above content will be automatically handled
|
|
48
|
-
* by the paragraph feature and converted to:
|
|
49
|
-
*
|
|
50
|
-
* ```html
|
|
51
|
-
* <p>Foo</p>
|
|
52
|
-
* <p>X</p>
|
|
53
|
-
* <p>Y</p>
|
|
54
|
-
* <p>Z</p>
|
|
55
|
-
* ```
|
|
56
|
-
*
|
|
57
|
-
* Note: The `<td>` containing two `<li>` elements was ignored as the innermost paragraph-like elements
|
|
58
|
-
* have a priority upon conversion.
|
|
59
|
-
*/
|
|
60
|
-
static paragraphLikeElements: Set<string>;
|
|
61
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
import { Plugin } from '@ckeditor/ckeditor5-core';
|
|
6
|
+
/**
|
|
7
|
+
* The paragraph feature for the editor.
|
|
8
|
+
*
|
|
9
|
+
* It introduces the `<paragraph>` element in the model which renders as a `<p>` element in the DOM and data.
|
|
10
|
+
*
|
|
11
|
+
* It also brings two editors commands:
|
|
12
|
+
*
|
|
13
|
+
* * The {@link module:paragraph/paragraphcommand~ParagraphCommand `'paragraph'`} command that converts all
|
|
14
|
+
* blocks in the model selection into paragraphs.
|
|
15
|
+
* * The {@link module:paragraph/insertparagraphcommand~InsertParagraphCommand `'insertParagraph'`} command
|
|
16
|
+
* that inserts a new paragraph at a specified location in the model.
|
|
17
|
+
*/
|
|
18
|
+
export default class Paragraph extends Plugin {
|
|
19
|
+
/**
|
|
20
|
+
* @inheritDoc
|
|
21
|
+
*/
|
|
22
|
+
static get pluginName(): "Paragraph";
|
|
23
|
+
/**
|
|
24
|
+
* @inheritDoc
|
|
25
|
+
*/
|
|
26
|
+
init(): void;
|
|
27
|
+
/**
|
|
28
|
+
* A list of element names which should be treated by the autoparagraphing algorithms as
|
|
29
|
+
* paragraph-like. This means that e.g. the following content:
|
|
30
|
+
*
|
|
31
|
+
* ```html
|
|
32
|
+
* <h1>Foo</h1>
|
|
33
|
+
* <table>
|
|
34
|
+
* <tr>
|
|
35
|
+
* <td>X</td>
|
|
36
|
+
* <td>
|
|
37
|
+
* <ul>
|
|
38
|
+
* <li>Y</li>
|
|
39
|
+
* <li>Z</li>
|
|
40
|
+
* </ul>
|
|
41
|
+
* </td>
|
|
42
|
+
* </tr>
|
|
43
|
+
* </table>
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* contains five paragraph-like elements: `<h1>`, two `<td>`s and two `<li>`s.
|
|
47
|
+
* Hence, if none of the features is going to convert those elements the above content will be automatically handled
|
|
48
|
+
* by the paragraph feature and converted to:
|
|
49
|
+
*
|
|
50
|
+
* ```html
|
|
51
|
+
* <p>Foo</p>
|
|
52
|
+
* <p>X</p>
|
|
53
|
+
* <p>Y</p>
|
|
54
|
+
* <p>Z</p>
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* Note: The `<td>` containing two `<li>` elements was ignored as the innermost paragraph-like elements
|
|
58
|
+
* have a priority upon conversion.
|
|
59
|
+
*/
|
|
60
|
+
static paragraphLikeElements: Set<string>;
|
|
61
|
+
}
|
package/src/paragraph.js
CHANGED
|
@@ -1,106 +1,106 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module paragraph/paragraph
|
|
7
|
-
*/
|
|
8
|
-
import ParagraphCommand from './paragraphcommand';
|
|
9
|
-
import InsertParagraphCommand from './insertparagraphcommand';
|
|
10
|
-
import { Plugin } from '@ckeditor/ckeditor5-core';
|
|
11
|
-
/**
|
|
12
|
-
* The paragraph feature for the editor.
|
|
13
|
-
*
|
|
14
|
-
* It introduces the `<paragraph>` element in the model which renders as a `<p>` element in the DOM and data.
|
|
15
|
-
*
|
|
16
|
-
* It also brings two editors commands:
|
|
17
|
-
*
|
|
18
|
-
* * The {@link module:paragraph/paragraphcommand~ParagraphCommand `'paragraph'`} command that converts all
|
|
19
|
-
* blocks in the model selection into paragraphs.
|
|
20
|
-
* * The {@link module:paragraph/insertparagraphcommand~InsertParagraphCommand `'insertParagraph'`} command
|
|
21
|
-
* that inserts a new paragraph at a specified location in the model.
|
|
22
|
-
*/
|
|
23
|
-
export default class Paragraph extends Plugin {
|
|
24
|
-
/**
|
|
25
|
-
* @inheritDoc
|
|
26
|
-
*/
|
|
27
|
-
static get pluginName() {
|
|
28
|
-
return 'Paragraph';
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* @inheritDoc
|
|
32
|
-
*/
|
|
33
|
-
init() {
|
|
34
|
-
const editor = this.editor;
|
|
35
|
-
const model = editor.model;
|
|
36
|
-
editor.commands.add('paragraph', new ParagraphCommand(editor));
|
|
37
|
-
editor.commands.add('insertParagraph', new InsertParagraphCommand(editor));
|
|
38
|
-
// Schema.
|
|
39
|
-
model.schema.register('paragraph', { inheritAllFrom: '$block' });
|
|
40
|
-
editor.conversion.elementToElement({ model: 'paragraph', view: 'p' });
|
|
41
|
-
// Conversion for paragraph-like elements which has not been converted by any plugin.
|
|
42
|
-
editor.conversion.for('upcast').elementToElement({
|
|
43
|
-
model: (viewElement, { writer }) => {
|
|
44
|
-
if (!Paragraph.paragraphLikeElements.has(viewElement.name)) {
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
// Do not auto-paragraph empty elements.
|
|
48
|
-
if (viewElement.isEmpty) {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
return writer.createElement('paragraph');
|
|
52
|
-
},
|
|
53
|
-
view: /.+/,
|
|
54
|
-
converterPriority: 'low'
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* A list of element names which should be treated by the autoparagraphing algorithms as
|
|
60
|
-
* paragraph-like. This means that e.g. the following content:
|
|
61
|
-
*
|
|
62
|
-
* ```html
|
|
63
|
-
* <h1>Foo</h1>
|
|
64
|
-
* <table>
|
|
65
|
-
* <tr>
|
|
66
|
-
* <td>X</td>
|
|
67
|
-
* <td>
|
|
68
|
-
* <ul>
|
|
69
|
-
* <li>Y</li>
|
|
70
|
-
* <li>Z</li>
|
|
71
|
-
* </ul>
|
|
72
|
-
* </td>
|
|
73
|
-
* </tr>
|
|
74
|
-
* </table>
|
|
75
|
-
* ```
|
|
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
|
-
* ```html
|
|
82
|
-
* <p>Foo</p>
|
|
83
|
-
* <p>X</p>
|
|
84
|
-
* <p>Y</p>
|
|
85
|
-
* <p>Z</p>
|
|
86
|
-
* ```
|
|
87
|
-
*
|
|
88
|
-
* Note: The `<td>` containing two `<li>` elements was ignored as the innermost paragraph-like elements
|
|
89
|
-
* have a priority upon conversion.
|
|
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
|
-
]);
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module paragraph/paragraph
|
|
7
|
+
*/
|
|
8
|
+
import ParagraphCommand from './paragraphcommand';
|
|
9
|
+
import InsertParagraphCommand from './insertparagraphcommand';
|
|
10
|
+
import { Plugin } from '@ckeditor/ckeditor5-core';
|
|
11
|
+
/**
|
|
12
|
+
* The paragraph feature for the editor.
|
|
13
|
+
*
|
|
14
|
+
* It introduces the `<paragraph>` element in the model which renders as a `<p>` element in the DOM and data.
|
|
15
|
+
*
|
|
16
|
+
* It also brings two editors commands:
|
|
17
|
+
*
|
|
18
|
+
* * The {@link module:paragraph/paragraphcommand~ParagraphCommand `'paragraph'`} command that converts all
|
|
19
|
+
* blocks in the model selection into paragraphs.
|
|
20
|
+
* * The {@link module:paragraph/insertparagraphcommand~InsertParagraphCommand `'insertParagraph'`} command
|
|
21
|
+
* that inserts a new paragraph at a specified location in the model.
|
|
22
|
+
*/
|
|
23
|
+
export default class Paragraph extends Plugin {
|
|
24
|
+
/**
|
|
25
|
+
* @inheritDoc
|
|
26
|
+
*/
|
|
27
|
+
static get pluginName() {
|
|
28
|
+
return 'Paragraph';
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @inheritDoc
|
|
32
|
+
*/
|
|
33
|
+
init() {
|
|
34
|
+
const editor = this.editor;
|
|
35
|
+
const model = editor.model;
|
|
36
|
+
editor.commands.add('paragraph', new ParagraphCommand(editor));
|
|
37
|
+
editor.commands.add('insertParagraph', new InsertParagraphCommand(editor));
|
|
38
|
+
// Schema.
|
|
39
|
+
model.schema.register('paragraph', { inheritAllFrom: '$block' });
|
|
40
|
+
editor.conversion.elementToElement({ model: 'paragraph', view: 'p' });
|
|
41
|
+
// Conversion for paragraph-like elements which has not been converted by any plugin.
|
|
42
|
+
editor.conversion.for('upcast').elementToElement({
|
|
43
|
+
model: (viewElement, { writer }) => {
|
|
44
|
+
if (!Paragraph.paragraphLikeElements.has(viewElement.name)) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
// Do not auto-paragraph empty elements.
|
|
48
|
+
if (viewElement.isEmpty) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
return writer.createElement('paragraph');
|
|
52
|
+
},
|
|
53
|
+
view: /.+/,
|
|
54
|
+
converterPriority: 'low'
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* A list of element names which should be treated by the autoparagraphing algorithms as
|
|
60
|
+
* paragraph-like. This means that e.g. the following content:
|
|
61
|
+
*
|
|
62
|
+
* ```html
|
|
63
|
+
* <h1>Foo</h1>
|
|
64
|
+
* <table>
|
|
65
|
+
* <tr>
|
|
66
|
+
* <td>X</td>
|
|
67
|
+
* <td>
|
|
68
|
+
* <ul>
|
|
69
|
+
* <li>Y</li>
|
|
70
|
+
* <li>Z</li>
|
|
71
|
+
* </ul>
|
|
72
|
+
* </td>
|
|
73
|
+
* </tr>
|
|
74
|
+
* </table>
|
|
75
|
+
* ```
|
|
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
|
+
* ```html
|
|
82
|
+
* <p>Foo</p>
|
|
83
|
+
* <p>X</p>
|
|
84
|
+
* <p>Y</p>
|
|
85
|
+
* <p>Z</p>
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* Note: The `<td>` containing two `<li>` elements was ignored as the innermost paragraph-like elements
|
|
89
|
+
* have a priority upon conversion.
|
|
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
|
+
]);
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module paragraph/paragraphbuttonui
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from '@ckeditor/ckeditor5-core';
|
|
9
|
-
import Paragraph from './paragraph';
|
|
10
|
-
/**
|
|
11
|
-
* This plugin defines the `'paragraph'` button. It can be used together with
|
|
12
|
-
* {@link module:heading/headingbuttonsui~HeadingButtonsUI} to replace the standard heading dropdown.
|
|
13
|
-
*
|
|
14
|
-
* This plugin is not loaded automatically by the {@link module:paragraph/paragraph~Paragraph} plugin. It must
|
|
15
|
-
* be added manually.
|
|
16
|
-
*
|
|
17
|
-
* ```ts
|
|
18
|
-
* ClassicEditor
|
|
19
|
-
* .create( {
|
|
20
|
-
* plugins: [ ..., Heading, Paragraph, HeadingButtonsUI, ParagraphButtonUI ]
|
|
21
|
-
* toolbar: [ 'paragraph', 'heading1', 'heading2', 'heading3' ]
|
|
22
|
-
* } )
|
|
23
|
-
* .then( ... )
|
|
24
|
-
* .catch( ... );
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
export default class ParagraphButtonUI extends Plugin {
|
|
28
|
-
/**
|
|
29
|
-
* @inheritDoc
|
|
30
|
-
*/
|
|
31
|
-
static get requires(): readonly [typeof Paragraph];
|
|
32
|
-
/**
|
|
33
|
-
* @inheritDoc
|
|
34
|
-
*/
|
|
35
|
-
init(): void;
|
|
36
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module paragraph/paragraphbuttonui
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from '@ckeditor/ckeditor5-core';
|
|
9
|
+
import Paragraph from './paragraph';
|
|
10
|
+
/**
|
|
11
|
+
* This plugin defines the `'paragraph'` button. It can be used together with
|
|
12
|
+
* {@link module:heading/headingbuttonsui~HeadingButtonsUI} to replace the standard heading dropdown.
|
|
13
|
+
*
|
|
14
|
+
* This plugin is not loaded automatically by the {@link module:paragraph/paragraph~Paragraph} plugin. It must
|
|
15
|
+
* be added manually.
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* ClassicEditor
|
|
19
|
+
* .create( {
|
|
20
|
+
* plugins: [ ..., Heading, Paragraph, HeadingButtonsUI, ParagraphButtonUI ]
|
|
21
|
+
* toolbar: [ 'paragraph', 'heading1', 'heading2', 'heading3' ]
|
|
22
|
+
* } )
|
|
23
|
+
* .then( ... )
|
|
24
|
+
* .catch( ... );
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export default class ParagraphButtonUI extends Plugin {
|
|
28
|
+
/**
|
|
29
|
+
* @inheritDoc
|
|
30
|
+
*/
|
|
31
|
+
static get requires(): readonly [typeof Paragraph];
|
|
32
|
+
/**
|
|
33
|
+
* @inheritDoc
|
|
34
|
+
*/
|
|
35
|
+
init(): void;
|
|
36
|
+
}
|
package/src/paragraphbuttonui.js
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module paragraph/paragraphbuttonui
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin, icons } from '@ckeditor/ckeditor5-core';
|
|
9
|
-
import { ButtonView } from '@ckeditor/ckeditor5-ui';
|
|
10
|
-
import Paragraph from './paragraph';
|
|
11
|
-
const icon = icons.paragraph;
|
|
12
|
-
/**
|
|
13
|
-
* This plugin defines the `'paragraph'` button. It can be used together with
|
|
14
|
-
* {@link module:heading/headingbuttonsui~HeadingButtonsUI} to replace the standard heading dropdown.
|
|
15
|
-
*
|
|
16
|
-
* This plugin is not loaded automatically by the {@link module:paragraph/paragraph~Paragraph} plugin. It must
|
|
17
|
-
* be added manually.
|
|
18
|
-
*
|
|
19
|
-
* ```ts
|
|
20
|
-
* ClassicEditor
|
|
21
|
-
* .create( {
|
|
22
|
-
* plugins: [ ..., Heading, Paragraph, HeadingButtonsUI, ParagraphButtonUI ]
|
|
23
|
-
* toolbar: [ 'paragraph', 'heading1', 'heading2', 'heading3' ]
|
|
24
|
-
* } )
|
|
25
|
-
* .then( ... )
|
|
26
|
-
* .catch( ... );
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
export default class ParagraphButtonUI extends Plugin {
|
|
30
|
-
/**
|
|
31
|
-
* @inheritDoc
|
|
32
|
-
*/
|
|
33
|
-
static get requires() {
|
|
34
|
-
return [Paragraph];
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* @inheritDoc
|
|
38
|
-
*/
|
|
39
|
-
init() {
|
|
40
|
-
const editor = this.editor;
|
|
41
|
-
const t = editor.t;
|
|
42
|
-
editor.ui.componentFactory.add('paragraph', locale => {
|
|
43
|
-
const view = new ButtonView(locale);
|
|
44
|
-
const command = editor.commands.get('paragraph');
|
|
45
|
-
view.label = t('Paragraph');
|
|
46
|
-
view.icon = icon;
|
|
47
|
-
view.tooltip = true;
|
|
48
|
-
view.isToggleable = true;
|
|
49
|
-
view.bind('isEnabled').to(command);
|
|
50
|
-
view.bind('isOn').to(command, 'value');
|
|
51
|
-
view.on('execute', () => {
|
|
52
|
-
editor.execute('paragraph');
|
|
53
|
-
});
|
|
54
|
-
return view;
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module paragraph/paragraphbuttonui
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin, icons } from '@ckeditor/ckeditor5-core';
|
|
9
|
+
import { ButtonView } from '@ckeditor/ckeditor5-ui';
|
|
10
|
+
import Paragraph from './paragraph';
|
|
11
|
+
const icon = icons.paragraph;
|
|
12
|
+
/**
|
|
13
|
+
* This plugin defines the `'paragraph'` button. It can be used together with
|
|
14
|
+
* {@link module:heading/headingbuttonsui~HeadingButtonsUI} to replace the standard heading dropdown.
|
|
15
|
+
*
|
|
16
|
+
* This plugin is not loaded automatically by the {@link module:paragraph/paragraph~Paragraph} plugin. It must
|
|
17
|
+
* be added manually.
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* ClassicEditor
|
|
21
|
+
* .create( {
|
|
22
|
+
* plugins: [ ..., Heading, Paragraph, HeadingButtonsUI, ParagraphButtonUI ]
|
|
23
|
+
* toolbar: [ 'paragraph', 'heading1', 'heading2', 'heading3' ]
|
|
24
|
+
* } )
|
|
25
|
+
* .then( ... )
|
|
26
|
+
* .catch( ... );
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export default class ParagraphButtonUI extends Plugin {
|
|
30
|
+
/**
|
|
31
|
+
* @inheritDoc
|
|
32
|
+
*/
|
|
33
|
+
static get requires() {
|
|
34
|
+
return [Paragraph];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @inheritDoc
|
|
38
|
+
*/
|
|
39
|
+
init() {
|
|
40
|
+
const editor = this.editor;
|
|
41
|
+
const t = editor.t;
|
|
42
|
+
editor.ui.componentFactory.add('paragraph', locale => {
|
|
43
|
+
const view = new ButtonView(locale);
|
|
44
|
+
const command = editor.commands.get('paragraph');
|
|
45
|
+
view.label = t('Paragraph');
|
|
46
|
+
view.icon = icon;
|
|
47
|
+
view.tooltip = true;
|
|
48
|
+
view.isToggleable = true;
|
|
49
|
+
view.bind('isEnabled').to(command);
|
|
50
|
+
view.bind('isOn').to(command, 'value');
|
|
51
|
+
view.on('execute', () => {
|
|
52
|
+
editor.execute('paragraph');
|
|
53
|
+
});
|
|
54
|
+
return view;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module paragraph/paragraphcommand
|
|
7
|
-
*/
|
|
8
|
-
import { Command, type Editor } from '@ckeditor/ckeditor5-core';
|
|
9
|
-
import type { Selection, DocumentSelection } from '@ckeditor/ckeditor5-engine';
|
|
10
|
-
/**
|
|
11
|
-
* The paragraph command.
|
|
12
|
-
*/
|
|
13
|
-
export default class ParagraphCommand extends Command {
|
|
14
|
-
constructor(editor: Editor);
|
|
15
|
-
/**
|
|
16
|
-
* The value of the command. Indicates whether the selection start is placed in a paragraph.
|
|
17
|
-
*
|
|
18
|
-
* @readonly
|
|
19
|
-
* @observable
|
|
20
|
-
*/
|
|
21
|
-
value: boolean;
|
|
22
|
-
/**
|
|
23
|
-
* @inheritDoc
|
|
24
|
-
*/
|
|
25
|
-
refresh(): void;
|
|
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 options Options for the executed command.
|
|
32
|
-
* @param options.selection The selection that the command should be applied to. By default,
|
|
33
|
-
* if not provided, the command is applied to the {@link module:engine/model/document~Document#selection}.
|
|
34
|
-
*/
|
|
35
|
-
execute(options?: {
|
|
36
|
-
selection?: Selection | DocumentSelection;
|
|
37
|
-
}): void;
|
|
38
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module paragraph/paragraphcommand
|
|
7
|
+
*/
|
|
8
|
+
import { Command, type Editor } from '@ckeditor/ckeditor5-core';
|
|
9
|
+
import type { Selection, DocumentSelection } from '@ckeditor/ckeditor5-engine';
|
|
10
|
+
/**
|
|
11
|
+
* The paragraph command.
|
|
12
|
+
*/
|
|
13
|
+
export default class ParagraphCommand extends Command {
|
|
14
|
+
constructor(editor: Editor);
|
|
15
|
+
/**
|
|
16
|
+
* The value of the command. Indicates whether the selection start is placed in a paragraph.
|
|
17
|
+
*
|
|
18
|
+
* @readonly
|
|
19
|
+
* @observable
|
|
20
|
+
*/
|
|
21
|
+
value: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* @inheritDoc
|
|
24
|
+
*/
|
|
25
|
+
refresh(): void;
|
|
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 options Options for the executed command.
|
|
32
|
+
* @param options.selection The selection that the command should be applied to. By default,
|
|
33
|
+
* if not provided, the command is applied to the {@link module:engine/model/document~Document#selection}.
|
|
34
|
+
*/
|
|
35
|
+
execute(options?: {
|
|
36
|
+
selection?: Selection | DocumentSelection;
|
|
37
|
+
}): void;
|
|
38
|
+
}
|
package/src/paragraphcommand.js
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module paragraph/paragraphcommand
|
|
7
|
-
*/
|
|
8
|
-
import { Command } from '@ckeditor/ckeditor5-core';
|
|
9
|
-
import { first } from '@ckeditor/ckeditor5-utils';
|
|
10
|
-
/**
|
|
11
|
-
* The paragraph command.
|
|
12
|
-
*/
|
|
13
|
-
export default class ParagraphCommand extends Command {
|
|
14
|
-
constructor(editor) {
|
|
15
|
-
super(editor);
|
|
16
|
-
// Since this command may pass selection in execution block, it should be checked directly.
|
|
17
|
-
this._isEnabledBasedOnSelection = false;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* @inheritDoc
|
|
21
|
-
*/
|
|
22
|
-
refresh() {
|
|
23
|
-
const model = this.editor.model;
|
|
24
|
-
const document = model.document;
|
|
25
|
-
const block = first(document.selection.getSelectedBlocks());
|
|
26
|
-
this.value = !!block && block.is('element', 'paragraph');
|
|
27
|
-
this.isEnabled = !!block && checkCanBecomeParagraph(block, model.schema);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Executes the command. All the blocks (see {@link module:engine/model/schema~Schema}) in the selection
|
|
31
|
-
* will be turned to paragraphs.
|
|
32
|
-
*
|
|
33
|
-
* @fires execute
|
|
34
|
-
* @param options Options for the executed command.
|
|
35
|
-
* @param options.selection The selection that the command should be applied to. By default,
|
|
36
|
-
* if not provided, the command is applied to the {@link module:engine/model/document~Document#selection}.
|
|
37
|
-
*/
|
|
38
|
-
execute(options = {}) {
|
|
39
|
-
const model = this.editor.model;
|
|
40
|
-
const document = model.document;
|
|
41
|
-
const selection = options.selection || document.selection;
|
|
42
|
-
// Don't execute command if selection is in non-editable place.
|
|
43
|
-
if (!model.canEditAt(selection)) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
model.change(writer => {
|
|
47
|
-
const blocks = selection.getSelectedBlocks();
|
|
48
|
-
for (const block of blocks) {
|
|
49
|
-
if (!block.is('element', 'paragraph') && checkCanBecomeParagraph(block, model.schema)) {
|
|
50
|
-
writer.rename(block, 'paragraph');
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Checks whether the given block can be replaced by a paragraph.
|
|
58
|
-
*
|
|
59
|
-
* @param block A block to be tested.
|
|
60
|
-
* @param schema The schema of the document.
|
|
61
|
-
*/
|
|
62
|
-
function checkCanBecomeParagraph(block, schema) {
|
|
63
|
-
return schema.checkChild(block.parent, 'paragraph') && !schema.isObject(block);
|
|
64
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module paragraph/paragraphcommand
|
|
7
|
+
*/
|
|
8
|
+
import { Command } from '@ckeditor/ckeditor5-core';
|
|
9
|
+
import { first } from '@ckeditor/ckeditor5-utils';
|
|
10
|
+
/**
|
|
11
|
+
* The paragraph command.
|
|
12
|
+
*/
|
|
13
|
+
export default class ParagraphCommand extends Command {
|
|
14
|
+
constructor(editor) {
|
|
15
|
+
super(editor);
|
|
16
|
+
// Since this command may pass selection in execution block, it should be checked directly.
|
|
17
|
+
this._isEnabledBasedOnSelection = false;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* @inheritDoc
|
|
21
|
+
*/
|
|
22
|
+
refresh() {
|
|
23
|
+
const model = this.editor.model;
|
|
24
|
+
const document = model.document;
|
|
25
|
+
const block = first(document.selection.getSelectedBlocks());
|
|
26
|
+
this.value = !!block && block.is('element', 'paragraph');
|
|
27
|
+
this.isEnabled = !!block && checkCanBecomeParagraph(block, model.schema);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Executes the command. All the blocks (see {@link module:engine/model/schema~Schema}) in the selection
|
|
31
|
+
* will be turned to paragraphs.
|
|
32
|
+
*
|
|
33
|
+
* @fires execute
|
|
34
|
+
* @param options Options for the executed command.
|
|
35
|
+
* @param options.selection The selection that the command should be applied to. By default,
|
|
36
|
+
* if not provided, the command is applied to the {@link module:engine/model/document~Document#selection}.
|
|
37
|
+
*/
|
|
38
|
+
execute(options = {}) {
|
|
39
|
+
const model = this.editor.model;
|
|
40
|
+
const document = model.document;
|
|
41
|
+
const selection = options.selection || document.selection;
|
|
42
|
+
// Don't execute command if selection is in non-editable place.
|
|
43
|
+
if (!model.canEditAt(selection)) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
model.change(writer => {
|
|
47
|
+
const blocks = selection.getSelectedBlocks();
|
|
48
|
+
for (const block of blocks) {
|
|
49
|
+
if (!block.is('element', 'paragraph') && checkCanBecomeParagraph(block, model.schema)) {
|
|
50
|
+
writer.rename(block, 'paragraph');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Checks whether the given block can be replaced by a paragraph.
|
|
58
|
+
*
|
|
59
|
+
* @param block A block to be tested.
|
|
60
|
+
* @param schema The schema of the document.
|
|
61
|
+
*/
|
|
62
|
+
function checkCanBecomeParagraph(block, schema) {
|
|
63
|
+
return schema.checkChild(block.parent, 'paragraph') && !schema.isObject(block);
|
|
64
|
+
}
|