@ckeditor/ckeditor5-enter 47.6.1 → 48.0.0-alpha.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/dist/index.css +3 -0
- package/dist/index.css.map +1 -0
- package/package.json +21 -40
- package/lang/contexts.json +0 -4
- package/lang/translations/af.po +0 -20
- package/lang/translations/ar.po +0 -20
- package/lang/translations/ast.po +0 -20
- package/lang/translations/az.po +0 -20
- package/lang/translations/be.po +0 -20
- package/lang/translations/bg.po +0 -20
- package/lang/translations/bn.po +0 -20
- package/lang/translations/bs.po +0 -20
- package/lang/translations/ca.po +0 -20
- package/lang/translations/cs.po +0 -20
- package/lang/translations/da.po +0 -20
- package/lang/translations/de-ch.po +0 -20
- package/lang/translations/de.po +0 -20
- package/lang/translations/el.po +0 -20
- package/lang/translations/en-au.po +0 -20
- package/lang/translations/en-gb.po +0 -20
- package/lang/translations/en.po +0 -20
- package/lang/translations/eo.po +0 -20
- package/lang/translations/es-co.po +0 -20
- package/lang/translations/es.po +0 -20
- package/lang/translations/et.po +0 -20
- package/lang/translations/eu.po +0 -20
- package/lang/translations/fa.po +0 -20
- package/lang/translations/fi.po +0 -20
- package/lang/translations/fr.po +0 -20
- package/lang/translations/gl.po +0 -20
- package/lang/translations/gu.po +0 -20
- package/lang/translations/he.po +0 -20
- package/lang/translations/hi.po +0 -20
- package/lang/translations/hr.po +0 -20
- package/lang/translations/hu.po +0 -20
- package/lang/translations/hy.po +0 -20
- package/lang/translations/id.po +0 -20
- package/lang/translations/it.po +0 -20
- package/lang/translations/ja.po +0 -20
- package/lang/translations/jv.po +0 -20
- package/lang/translations/kk.po +0 -20
- package/lang/translations/km.po +0 -20
- package/lang/translations/kn.po +0 -20
- package/lang/translations/ko.po +0 -20
- package/lang/translations/ku.po +0 -20
- package/lang/translations/lt.po +0 -20
- package/lang/translations/lv.po +0 -20
- package/lang/translations/ms.po +0 -20
- package/lang/translations/nb.po +0 -20
- package/lang/translations/ne.po +0 -20
- package/lang/translations/nl.po +0 -20
- package/lang/translations/no.po +0 -20
- package/lang/translations/oc.po +0 -20
- package/lang/translations/pl.po +0 -20
- package/lang/translations/pt-br.po +0 -20
- package/lang/translations/pt.po +0 -20
- package/lang/translations/ro.po +0 -20
- package/lang/translations/ru.po +0 -20
- package/lang/translations/si.po +0 -20
- package/lang/translations/sk.po +0 -20
- package/lang/translations/sl.po +0 -20
- package/lang/translations/sq.po +0 -20
- package/lang/translations/sr-latn.po +0 -20
- package/lang/translations/sr.po +0 -20
- package/lang/translations/sv.po +0 -20
- package/lang/translations/th.po +0 -20
- package/lang/translations/ti.po +0 -20
- package/lang/translations/tk.po +0 -20
- package/lang/translations/tr.po +0 -20
- package/lang/translations/tt.po +0 -20
- package/lang/translations/ug.po +0 -20
- package/lang/translations/uk.po +0 -20
- package/lang/translations/ur.po +0 -20
- package/lang/translations/uz.po +0 -20
- package/lang/translations/vi.po +0 -20
- package/lang/translations/zh-cn.po +0 -20
- package/lang/translations/zh.po +0 -20
- package/src/augmentation.js +0 -5
- package/src/enter.js +0 -61
- package/src/entercommand.js +0 -96
- package/src/enterobserver.js +0 -61
- package/src/index.js +0 -14
- package/src/shiftenter.js +0 -79
- package/src/shiftentercommand.js +0 -118
- package/src/utils.js +0 -21
- /package/{src → dist}/augmentation.d.ts +0 -0
- /package/{src → dist}/enter.d.ts +0 -0
- /package/{src → dist}/entercommand.d.ts +0 -0
- /package/{src → dist}/enterobserver.d.ts +0 -0
- /package/{src → dist}/index.d.ts +0 -0
- /package/{src → dist}/shiftenter.d.ts +0 -0
- /package/{src → dist}/shiftentercommand.d.ts +0 -0
- /package/{src → dist}/utils.d.ts +0 -0
package/src/shiftenter.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module enter/shiftenter
|
|
7
|
-
*/
|
|
8
|
-
import { ShiftEnterCommand } from './shiftentercommand.js';
|
|
9
|
-
import { EnterObserver } from './enterobserver.js';
|
|
10
|
-
import { Plugin } from '@ckeditor/ckeditor5-core';
|
|
11
|
-
/**
|
|
12
|
-
* This plugin handles the <kbd>Shift</kbd>+<kbd>Enter</kbd> keystroke (soft line break) in the editor.
|
|
13
|
-
*
|
|
14
|
-
* See also the {@link module:enter/enter~Enter} plugin.
|
|
15
|
-
*
|
|
16
|
-
* For more information about this feature see the {@glink api/enter package page}.
|
|
17
|
-
*/
|
|
18
|
-
export class ShiftEnter extends Plugin {
|
|
19
|
-
/**
|
|
20
|
-
* @inheritDoc
|
|
21
|
-
*/
|
|
22
|
-
static get pluginName() {
|
|
23
|
-
return 'ShiftEnter';
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* @inheritDoc
|
|
27
|
-
*/
|
|
28
|
-
static get isOfficialPlugin() {
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
init() {
|
|
32
|
-
const editor = this.editor;
|
|
33
|
-
const schema = editor.model.schema;
|
|
34
|
-
const conversion = editor.conversion;
|
|
35
|
-
const view = editor.editing.view;
|
|
36
|
-
const viewDocument = view.document;
|
|
37
|
-
const t = this.editor.t;
|
|
38
|
-
// Configure the schema.
|
|
39
|
-
schema.register('softBreak', {
|
|
40
|
-
allowWhere: '$text',
|
|
41
|
-
isInline: true
|
|
42
|
-
});
|
|
43
|
-
// Configure converters.
|
|
44
|
-
conversion.for('upcast')
|
|
45
|
-
.elementToElement({
|
|
46
|
-
model: 'softBreak',
|
|
47
|
-
view: 'br'
|
|
48
|
-
});
|
|
49
|
-
conversion.for('downcast')
|
|
50
|
-
.elementToElement({
|
|
51
|
-
model: 'softBreak',
|
|
52
|
-
view: (modelElement, { writer }) => writer.createEmptyElement('br')
|
|
53
|
-
});
|
|
54
|
-
view.addObserver(EnterObserver);
|
|
55
|
-
editor.commands.add('shiftEnter', new ShiftEnterCommand(editor));
|
|
56
|
-
this.listenTo(viewDocument, 'enter', (evt, data) => {
|
|
57
|
-
// When not in composition, we handle the action, so prevent the default one.
|
|
58
|
-
// When in composition, it's the browser who modify the DOM (renderer is disabled).
|
|
59
|
-
if (!viewDocument.isComposing) {
|
|
60
|
-
data.preventDefault();
|
|
61
|
-
}
|
|
62
|
-
// The hard enter key is handled by the Enter plugin.
|
|
63
|
-
if (!data.isSoft) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
editor.execute('shiftEnter');
|
|
67
|
-
view.scrollToTheSelection();
|
|
68
|
-
}, { priority: 'low' });
|
|
69
|
-
// Add the information about the keystroke to the accessibility database.
|
|
70
|
-
editor.accessibility.addKeystrokeInfos({
|
|
71
|
-
keystrokes: [
|
|
72
|
-
{
|
|
73
|
-
label: t('Insert a soft break (a <code><br></code> element)'),
|
|
74
|
-
keystroke: 'Shift+Enter'
|
|
75
|
-
}
|
|
76
|
-
]
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
}
|
package/src/shiftentercommand.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module enter/shiftentercommand
|
|
7
|
-
*/
|
|
8
|
-
import { Command } from '@ckeditor/ckeditor5-core';
|
|
9
|
-
import { getCopyOnEnterAttributes } from './utils.js';
|
|
10
|
-
/**
|
|
11
|
-
* ShiftEnter command. It is used by the {@link module:enter/shiftenter~ShiftEnter ShiftEnter feature} to handle
|
|
12
|
-
* the <kbd>Shift</kbd>+<kbd>Enter</kbd> keystroke.
|
|
13
|
-
*/
|
|
14
|
-
export class ShiftEnterCommand extends Command {
|
|
15
|
-
/**
|
|
16
|
-
* @inheritDoc
|
|
17
|
-
*/
|
|
18
|
-
execute() {
|
|
19
|
-
const model = this.editor.model;
|
|
20
|
-
const doc = model.document;
|
|
21
|
-
model.change(writer => {
|
|
22
|
-
softBreakAction(model, writer, doc.selection);
|
|
23
|
-
this.fire('afterExecute', { writer });
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* @inheritDoc
|
|
28
|
-
*/
|
|
29
|
-
refresh() {
|
|
30
|
-
const model = this.editor.model;
|
|
31
|
-
const doc = model.document;
|
|
32
|
-
this.isEnabled = isEnabled(model.schema, doc.selection);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Checks whether the ShiftEnter command should be enabled in the specified selection.
|
|
37
|
-
*/
|
|
38
|
-
function isEnabled(schema, selection) {
|
|
39
|
-
// At this moment it is okay to support single range selections only.
|
|
40
|
-
// But in the future we may need to change that.
|
|
41
|
-
if (selection.rangeCount > 1) {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
const anchorPos = selection.anchor;
|
|
45
|
-
// Check whether the break element can be inserted in the current selection anchor.
|
|
46
|
-
if (!anchorPos || !schema.checkChild(anchorPos, 'softBreak')) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
const range = selection.getFirstRange();
|
|
50
|
-
const startElement = range.start.parent;
|
|
51
|
-
const endElement = range.end.parent;
|
|
52
|
-
// Do not modify the content if selection is cross-limit elements.
|
|
53
|
-
if ((isInsideLimitElement(startElement, schema) || isInsideLimitElement(endElement, schema)) && startElement !== endElement) {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Creates a break in the way that the <kbd>Shift</kbd>+<kbd>Enter</kbd> keystroke is expected to work.
|
|
60
|
-
*/
|
|
61
|
-
function softBreakAction(model, writer, selection) {
|
|
62
|
-
const isSelectionEmpty = selection.isCollapsed;
|
|
63
|
-
const range = selection.getFirstRange();
|
|
64
|
-
const startElement = range.start.parent;
|
|
65
|
-
const endElement = range.end.parent;
|
|
66
|
-
const isContainedWithinOneElement = (startElement == endElement);
|
|
67
|
-
if (isSelectionEmpty) {
|
|
68
|
-
const attributesToCopy = getCopyOnEnterAttributes(model.schema, selection.getAttributes());
|
|
69
|
-
insertBreak(model, writer, range.end);
|
|
70
|
-
writer.removeSelectionAttribute(selection.getAttributeKeys());
|
|
71
|
-
writer.setSelectionAttribute(attributesToCopy);
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
const leaveUnmerged = !(range.start.isAtStart && range.end.isAtEnd);
|
|
75
|
-
model.deleteContent(selection, { leaveUnmerged });
|
|
76
|
-
// Selection within one element:
|
|
77
|
-
//
|
|
78
|
-
// <h>x[xx]x</h> -> <h>x^x</h> -> <h>x<br>^x</h>
|
|
79
|
-
if (isContainedWithinOneElement) {
|
|
80
|
-
insertBreak(model, writer, selection.focus);
|
|
81
|
-
}
|
|
82
|
-
// Selection over multiple elements.
|
|
83
|
-
//
|
|
84
|
-
// <h>x[x</h><p>y]y<p> -> <h>x^</h><p>y</p> -> <h>x</h><p>^y</p>
|
|
85
|
-
//
|
|
86
|
-
// We chose not to insert a line break in this case because:
|
|
87
|
-
//
|
|
88
|
-
// * it's not a very common scenario,
|
|
89
|
-
// * it actually surprised me when I saw the "expected behavior" in real life.
|
|
90
|
-
//
|
|
91
|
-
// It's ok if the user will need to be more specific where they want the <br> to be inserted.
|
|
92
|
-
else {
|
|
93
|
-
// Move the selection to the 2nd element (last step of the example above).
|
|
94
|
-
if (leaveUnmerged) {
|
|
95
|
-
writer.setSelection(endElement, 0);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
function insertBreak(model, writer, position) {
|
|
101
|
-
const breakLineElement = writer.createElement('softBreak');
|
|
102
|
-
model.insertContent(breakLineElement, position);
|
|
103
|
-
writer.setSelection(breakLineElement, 'after');
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Checks whether the specified `element` is a child of the limit element.
|
|
107
|
-
*
|
|
108
|
-
* Checking whether the `<p>` element is inside a limit element:
|
|
109
|
-
* - `<$root><p>Text.</p></$root> => false`
|
|
110
|
-
* - `<$root><limitElement><p>Text</p></limitElement></$root> => true`
|
|
111
|
-
*/
|
|
112
|
-
function isInsideLimitElement(element, schema) {
|
|
113
|
-
// `$root` is a limit element but in this case is an invalid element.
|
|
114
|
-
if (element.is('rootElement')) {
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
return schema.isLimit(element) || isInsideLimitElement(element.parent, schema);
|
|
118
|
-
}
|
package/src/utils.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Returns attributes that should be preserved on the enter keystroke.
|
|
7
|
-
*
|
|
8
|
-
* Filtering is realized based on `copyOnEnter` attribute property. Read more about attribute properties
|
|
9
|
-
* {@link module:engine/model/schema~ModelSchema#setAttributeProperties here}.
|
|
10
|
-
*
|
|
11
|
-
* @param schema Model's schema.
|
|
12
|
-
* @param allAttributes Attributes to filter.
|
|
13
|
-
* @internal
|
|
14
|
-
*/
|
|
15
|
-
export function* getCopyOnEnterAttributes(schema, allAttributes) {
|
|
16
|
-
for (const attribute of allAttributes) {
|
|
17
|
-
if (attribute && schema.getAttributeProperties(attribute[0]).copyOnEnter) {
|
|
18
|
-
yield attribute;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
File without changes
|
/package/{src → dist}/enter.d.ts
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/{src → dist}/index.d.ts
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/{src → dist}/utils.d.ts
RENAMED
|
File without changes
|