@ckeditor/ckeditor5-enter 35.3.2 → 36.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 +1 -1
- package/package.json +10 -10
- package/src/enter.js +3 -3
- package/src/entercommand.js +66 -51
- package/src/enterobserver.js +2 -4
- package/src/index.js +1 -1
- package/src/shiftenter.js +2 -2
- package/src/shiftentercommand.js +2 -2
- package/src/utils.js +2 -2
package/LICENSE.md
CHANGED
|
@@ -2,7 +2,7 @@ Software License Agreement
|
|
|
2
2
|
==========================
|
|
3
3
|
|
|
4
4
|
**CKEditor 5 enter feature** – https://github.com/ckeditor/ckeditor5-enter <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
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckeditor/ckeditor5-enter",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "36.0.0",
|
|
4
4
|
"description": "Enter feature for CKEditor 5.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ckeditor",
|
|
@@ -12,17 +12,17 @@
|
|
|
12
12
|
],
|
|
13
13
|
"main": "src/index.js",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@ckeditor/ckeditor5-core": "^
|
|
16
|
-
"@ckeditor/ckeditor5-engine": "^
|
|
15
|
+
"@ckeditor/ckeditor5-core": "^36.0.0",
|
|
16
|
+
"@ckeditor/ckeditor5-engine": "^36.0.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@ckeditor/ckeditor5-basic-styles": "^
|
|
20
|
-
"@ckeditor/ckeditor5-editor-classic": "^
|
|
21
|
-
"@ckeditor/ckeditor5-heading": "^
|
|
22
|
-
"@ckeditor/ckeditor5-link": "^
|
|
23
|
-
"@ckeditor/ckeditor5-paragraph": "^
|
|
24
|
-
"@ckeditor/ckeditor5-typing": "^
|
|
25
|
-
"@ckeditor/ckeditor5-undo": "^
|
|
19
|
+
"@ckeditor/ckeditor5-basic-styles": "^36.0.0",
|
|
20
|
+
"@ckeditor/ckeditor5-editor-classic": "^36.0.0",
|
|
21
|
+
"@ckeditor/ckeditor5-heading": "^36.0.0",
|
|
22
|
+
"@ckeditor/ckeditor5-link": "^36.0.0",
|
|
23
|
+
"@ckeditor/ckeditor5-paragraph": "^36.0.0",
|
|
24
|
+
"@ckeditor/ckeditor5-typing": "^36.0.0",
|
|
25
|
+
"@ckeditor/ckeditor5-undo": "^36.0.0",
|
|
26
26
|
"typescript": "^4.8.4",
|
|
27
27
|
"webpack": "^5.58.1",
|
|
28
28
|
"webpack-cli": "^4.9.0"
|
package/src/enter.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
6
|
* @module enter/enter
|
|
7
7
|
*/
|
|
8
|
-
import Plugin from '@ckeditor/ckeditor5-core
|
|
8
|
+
import { Plugin } from '@ckeditor/ckeditor5-core';
|
|
9
9
|
import EnterCommand from './entercommand';
|
|
10
10
|
import EnterObserver from './enterobserver';
|
|
11
11
|
/**
|
|
12
|
-
* This plugin handles the <kbd>Enter</kbd>
|
|
12
|
+
* This plugin handles the <kbd>Enter</kbd> keystroke (hard line break) in the editor.
|
|
13
13
|
*
|
|
14
14
|
* See also the {@link module:enter/shiftenter~ShiftEnter} plugin.
|
|
15
15
|
*
|
package/src/entercommand.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
6
|
* @module enter/entercommand
|
|
7
7
|
*/
|
|
8
|
-
import Command from '@ckeditor/ckeditor5-core
|
|
8
|
+
import { Command } from '@ckeditor/ckeditor5-core';
|
|
9
9
|
import { getCopyOnEnterAttributes } from './utils';
|
|
10
10
|
/**
|
|
11
|
-
* Enter command. It is used by the {@link module:enter/enter~Enter Enter feature} to handle the <kbd>Enter</kbd>
|
|
11
|
+
* Enter command. It is used by the {@link module:enter/enter~Enter Enter feature} to handle the <kbd>Enter</kbd> keystroke.
|
|
12
12
|
*
|
|
13
13
|
* @extends module:core/command~Command
|
|
14
14
|
*/
|
|
@@ -17,60 +17,75 @@ export default class EnterCommand extends Command {
|
|
|
17
17
|
* @inheritDoc
|
|
18
18
|
*/
|
|
19
19
|
execute() {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
model.change(writer => {
|
|
23
|
-
enterBlock(this.editor.model, writer, doc.selection, model.schema);
|
|
20
|
+
this.editor.model.change(writer => {
|
|
21
|
+
this.enterBlock(writer);
|
|
24
22
|
this.fire('afterExecute', { writer });
|
|
25
23
|
});
|
|
26
24
|
}
|
|
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
|
-
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
// Partially selected elements.
|
|
62
|
-
//
|
|
63
|
-
// <h>x[xx]x</h> -> <h>x^x</h> -> <h>x</h><h>^x</h>
|
|
64
|
-
if (isContainedWithinOneElement) {
|
|
65
|
-
splitBlock(writer, selection.focus);
|
|
25
|
+
/**
|
|
26
|
+
* Splits a block where the document selection is placed, in the way how the <kbd>Enter</kbd> key is expected to work:
|
|
27
|
+
*
|
|
28
|
+
* <p>Foo[]bar</p> -> <p>Foo</p><p>[]bar</p>
|
|
29
|
+
* <p>Foobar[]</p> -> <p>Foobar</p><p>[]</p>
|
|
30
|
+
* <p>Fo[ob]ar</p> -> <p>Fo</p><p>[]ar</p>
|
|
31
|
+
*
|
|
32
|
+
* In some cases, the split will not happen:
|
|
33
|
+
*
|
|
34
|
+
* // The selection parent is a limit element:
|
|
35
|
+
* <figcaption>A[bc]d</figcaption> -> <figcaption>A[]d</figcaption>
|
|
36
|
+
*
|
|
37
|
+
* // The selection spans over multiple elements:
|
|
38
|
+
* <h>x[x</h><p>y]y<p> -> <h>x</h><p>[]y</p>
|
|
39
|
+
*
|
|
40
|
+
* @param writer Writer to use when performing the enter action.
|
|
41
|
+
* @returns `true` if a block was split, `false` otherwise.
|
|
42
|
+
*/
|
|
43
|
+
enterBlock(writer) {
|
|
44
|
+
const model = this.editor.model;
|
|
45
|
+
const selection = model.document.selection;
|
|
46
|
+
const schema = model.schema;
|
|
47
|
+
const isSelectionEmpty = selection.isCollapsed;
|
|
48
|
+
const range = selection.getFirstRange();
|
|
49
|
+
const startElement = range.start.parent;
|
|
50
|
+
const endElement = range.end.parent;
|
|
51
|
+
// Don't touch the roots and other limit elements.
|
|
52
|
+
if (schema.isLimit(startElement) || schema.isLimit(endElement)) {
|
|
53
|
+
// Delete the selected content but only if inside a single limit element.
|
|
54
|
+
// Abort, when crossing limit elements boundary (e.g. <limit1>x[x</limit1>donttouchme<limit2>y]y</limit2>).
|
|
55
|
+
// This is an edge case and it's hard to tell what should actually happen because such a selection
|
|
56
|
+
// is not entirely valid.
|
|
57
|
+
if (!isSelectionEmpty && startElement == endElement) {
|
|
58
|
+
model.deleteContent(selection);
|
|
66
59
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
if (isSelectionEmpty) {
|
|
63
|
+
const attributesToCopy = getCopyOnEnterAttributes(writer.model.schema, selection.getAttributes());
|
|
64
|
+
splitBlock(writer, range.start);
|
|
65
|
+
writer.setSelectionAttribute(attributesToCopy);
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
const leaveUnmerged = !(range.start.isAtStart && range.end.isAtEnd);
|
|
70
|
+
const isContainedWithinOneElement = (startElement == endElement);
|
|
71
|
+
model.deleteContent(selection, { leaveUnmerged });
|
|
72
|
+
if (leaveUnmerged) {
|
|
73
|
+
// Partially selected elements.
|
|
74
|
+
//
|
|
75
|
+
// <h>x[xx]x</h> -> <h>x^x</h> -> <h>x</h><h>^x</h>
|
|
76
|
+
if (isContainedWithinOneElement) {
|
|
77
|
+
splitBlock(writer, selection.focus);
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
// Selection over multiple elements.
|
|
81
|
+
//
|
|
82
|
+
// <h>x[x</h><p>y]y<p> -> <h>x^</h><p>y</p> -> <h>x</h><p>^y</p>
|
|
83
|
+
else {
|
|
84
|
+
writer.setSelection(endElement, 0);
|
|
85
|
+
}
|
|
72
86
|
}
|
|
73
87
|
}
|
|
88
|
+
return false;
|
|
74
89
|
}
|
|
75
90
|
}
|
|
76
91
|
function splitBlock(writer, splitPos) {
|
package/src/enterobserver.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
6
|
* @module enter/enterobserver
|
|
7
7
|
*/
|
|
8
|
-
import Observer from '@ckeditor/ckeditor5-engine
|
|
9
|
-
import DomEventData from '@ckeditor/ckeditor5-engine/src/view/observer/domeventdata';
|
|
10
|
-
import BubblingEventInfo from '@ckeditor/ckeditor5-engine/src/view/observer/bubblingeventinfo';
|
|
8
|
+
import { Observer, DomEventData, BubblingEventInfo } from '@ckeditor/ckeditor5-engine';
|
|
11
9
|
const ENTER_EVENT_TYPES = {
|
|
12
10
|
insertParagraph: { isSoft: false },
|
|
13
11
|
insertLineBreak: { isSoft: true }
|
package/src/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
/**
|
package/src/shiftenter.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import ShiftEnterCommand from './shiftentercommand';
|
|
9
9
|
import EnterObserver from './enterobserver';
|
|
10
|
-
import Plugin from '@ckeditor/ckeditor5-core
|
|
10
|
+
import { Plugin } from '@ckeditor/ckeditor5-core';
|
|
11
11
|
/**
|
|
12
12
|
* This plugin handles the <kbd>Shift</kbd>+<kbd>Enter</kbd> keystroke (soft line break) in the editor.
|
|
13
13
|
*
|
package/src/shiftentercommand.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
6
|
* @module enter/shiftentercommand
|
|
7
7
|
*/
|
|
8
|
-
import Command from '@ckeditor/ckeditor5-core
|
|
8
|
+
import { Command } from '@ckeditor/ckeditor5-core';
|
|
9
9
|
import { getCopyOnEnterAttributes } from './utils';
|
|
10
10
|
/**
|
|
11
11
|
* ShiftEnter command. It is used by the {@link module:enter/shiftenter~ShiftEnter ShiftEnter feature} to handle
|
package/src/utils.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
-
* Returns attributes that should be preserved on the enter
|
|
6
|
+
* Returns attributes that should be preserved on the enter keystroke.
|
|
7
7
|
*
|
|
8
8
|
* Filtering is realized based on `copyOnEnter` attribute property. Read more about attribute properties
|
|
9
9
|
* {@link module:engine/model/schema~Schema#setAttributeProperties here}.
|