@ckeditor/ckeditor5-block-quote 30.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE.md +17 -0
- package/README.md +20 -0
- package/build/block-quote.js +5 -0
- package/build/translations/af.js +1 -0
- package/build/translations/ar.js +1 -0
- package/build/translations/az.js +1 -0
- package/build/translations/bg.js +1 -0
- package/build/translations/ca.js +1 -0
- package/build/translations/cs.js +1 -0
- package/build/translations/da.js +1 -0
- package/build/translations/de-ch.js +1 -0
- package/build/translations/de.js +1 -0
- package/build/translations/el.js +1 -0
- package/build/translations/en-au.js +1 -0
- package/build/translations/en-gb.js +1 -0
- package/build/translations/es.js +1 -0
- package/build/translations/et.js +1 -0
- package/build/translations/eu.js +1 -0
- package/build/translations/fa.js +1 -0
- package/build/translations/fi.js +1 -0
- package/build/translations/fr.js +1 -0
- package/build/translations/gl.js +1 -0
- package/build/translations/gu.js +1 -0
- package/build/translations/he.js +1 -0
- package/build/translations/hi.js +1 -0
- package/build/translations/hr.js +1 -0
- package/build/translations/hu.js +1 -0
- package/build/translations/id.js +1 -0
- package/build/translations/it.js +1 -0
- package/build/translations/ja.js +1 -0
- package/build/translations/km.js +1 -0
- package/build/translations/kn.js +1 -0
- package/build/translations/ko.js +1 -0
- package/build/translations/ku.js +1 -0
- package/build/translations/lt.js +1 -0
- package/build/translations/lv.js +1 -0
- package/build/translations/nb.js +1 -0
- package/build/translations/ne.js +1 -0
- package/build/translations/nl.js +1 -0
- package/build/translations/no.js +1 -0
- package/build/translations/pl.js +1 -0
- package/build/translations/pt-br.js +1 -0
- package/build/translations/ro.js +1 -0
- package/build/translations/ru.js +1 -0
- package/build/translations/sk.js +1 -0
- package/build/translations/sl.js +1 -0
- package/build/translations/sq.js +1 -0
- package/build/translations/sr-latn.js +1 -0
- package/build/translations/sr.js +1 -0
- package/build/translations/sv.js +1 -0
- package/build/translations/th.js +1 -0
- package/build/translations/tk.js +1 -0
- package/build/translations/tr.js +1 -0
- package/build/translations/ug.js +1 -0
- package/build/translations/uk.js +1 -0
- package/build/translations/vi.js +1 -0
- package/build/translations/zh-cn.js +1 -0
- package/build/translations/zh.js +1 -0
- package/ckeditor5-metadata.json +23 -0
- package/lang/contexts.json +3 -0
- package/lang/translations/af.po +21 -0
- package/lang/translations/ar.po +21 -0
- package/lang/translations/az.po +21 -0
- package/lang/translations/bg.po +21 -0
- package/lang/translations/ca.po +21 -0
- package/lang/translations/cs.po +21 -0
- package/lang/translations/da.po +21 -0
- package/lang/translations/de-ch.po +21 -0
- package/lang/translations/de.po +21 -0
- package/lang/translations/el.po +21 -0
- package/lang/translations/en-au.po +21 -0
- package/lang/translations/en-gb.po +21 -0
- package/lang/translations/en.po +21 -0
- package/lang/translations/es.po +21 -0
- package/lang/translations/et.po +21 -0
- package/lang/translations/eu.po +21 -0
- package/lang/translations/fa.po +21 -0
- package/lang/translations/fi.po +21 -0
- package/lang/translations/fr.po +21 -0
- package/lang/translations/gl.po +21 -0
- package/lang/translations/gu.po +21 -0
- package/lang/translations/he.po +21 -0
- package/lang/translations/hi.po +21 -0
- package/lang/translations/hr.po +21 -0
- package/lang/translations/hu.po +21 -0
- package/lang/translations/id.po +21 -0
- package/lang/translations/it.po +21 -0
- package/lang/translations/ja.po +21 -0
- package/lang/translations/km.po +21 -0
- package/lang/translations/kn.po +21 -0
- package/lang/translations/ko.po +21 -0
- package/lang/translations/ku.po +21 -0
- package/lang/translations/lt.po +21 -0
- package/lang/translations/lv.po +21 -0
- package/lang/translations/nb.po +21 -0
- package/lang/translations/ne.po +21 -0
- package/lang/translations/nl.po +21 -0
- package/lang/translations/no.po +21 -0
- package/lang/translations/pl.po +21 -0
- package/lang/translations/pt-br.po +21 -0
- package/lang/translations/ro.po +21 -0
- package/lang/translations/ru.po +21 -0
- package/lang/translations/sk.po +21 -0
- package/lang/translations/sl.po +21 -0
- package/lang/translations/sq.po +21 -0
- package/lang/translations/sr-latn.po +21 -0
- package/lang/translations/sr.po +21 -0
- package/lang/translations/sv.po +21 -0
- package/lang/translations/th.po +21 -0
- package/lang/translations/tk.po +21 -0
- package/lang/translations/tr.po +21 -0
- package/lang/translations/ug.po +21 -0
- package/lang/translations/uk.po +21 -0
- package/lang/translations/vi.po +21 -0
- package/lang/translations/zh-cn.po +21 -0
- package/lang/translations/zh.po +21 -0
- package/package.json +57 -0
- package/src/blockquote.js +39 -0
- package/src/blockquotecommand.js +232 -0
- package/src/blockquoteediting.js +147 -0
- package/src/blockquoteui.js +60 -0
- package/src/index.js +12 -0
- package/theme/blockquote.css +23 -0
@@ -0,0 +1,147 @@
|
|
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 block-quote/blockquoteediting
|
8
|
+
*/
|
9
|
+
|
10
|
+
import { Plugin } from 'ckeditor5/src/core';
|
11
|
+
import { Enter } from 'ckeditor5/src/enter';
|
12
|
+
import { Delete } from 'ckeditor5/src/typing';
|
13
|
+
|
14
|
+
import BlockQuoteCommand from './blockquotecommand';
|
15
|
+
|
16
|
+
/**
|
17
|
+
* The block quote editing.
|
18
|
+
*
|
19
|
+
* Introduces the `'blockQuote'` command and the `'blockQuote'` model element.
|
20
|
+
*
|
21
|
+
* @extends module:core/plugin~Plugin
|
22
|
+
*/
|
23
|
+
export default class BlockQuoteEditing extends Plugin {
|
24
|
+
/**
|
25
|
+
* @inheritDoc
|
26
|
+
*/
|
27
|
+
static get pluginName() {
|
28
|
+
return 'BlockQuoteEditing';
|
29
|
+
}
|
30
|
+
|
31
|
+
/**
|
32
|
+
* @inheritDoc
|
33
|
+
*/
|
34
|
+
static get requires() {
|
35
|
+
return [ Enter, Delete ];
|
36
|
+
}
|
37
|
+
|
38
|
+
/**
|
39
|
+
* @inheritDoc
|
40
|
+
*/
|
41
|
+
init() {
|
42
|
+
const editor = this.editor;
|
43
|
+
const schema = editor.model.schema;
|
44
|
+
|
45
|
+
editor.commands.add( 'blockQuote', new BlockQuoteCommand( editor ) );
|
46
|
+
|
47
|
+
schema.register( 'blockQuote', {
|
48
|
+
allowWhere: '$block',
|
49
|
+
allowContentOf: '$root'
|
50
|
+
} );
|
51
|
+
|
52
|
+
editor.conversion.elementToElement( { model: 'blockQuote', view: 'blockquote' } );
|
53
|
+
|
54
|
+
// Postfixer which cleans incorrect model states connected with block quotes.
|
55
|
+
editor.model.document.registerPostFixer( writer => {
|
56
|
+
const changes = editor.model.document.differ.getChanges();
|
57
|
+
|
58
|
+
for ( const entry of changes ) {
|
59
|
+
if ( entry.type == 'insert' ) {
|
60
|
+
const element = entry.position.nodeAfter;
|
61
|
+
|
62
|
+
if ( !element ) {
|
63
|
+
// We are inside a text node.
|
64
|
+
continue;
|
65
|
+
}
|
66
|
+
|
67
|
+
if ( element.is( 'element', 'blockQuote' ) && element.isEmpty ) {
|
68
|
+
// Added an empty blockQuote - remove it.
|
69
|
+
writer.remove( element );
|
70
|
+
|
71
|
+
return true;
|
72
|
+
} else if ( element.is( 'element', 'blockQuote' ) && !schema.checkChild( entry.position, element ) ) {
|
73
|
+
// Added a blockQuote in incorrect place. Unwrap it so the content inside is not lost.
|
74
|
+
writer.unwrap( element );
|
75
|
+
|
76
|
+
return true;
|
77
|
+
} else if ( element.is( 'element' ) ) {
|
78
|
+
// Just added an element. Check that all children meet the scheme rules.
|
79
|
+
const range = writer.createRangeIn( element );
|
80
|
+
|
81
|
+
for ( const child of range.getItems() ) {
|
82
|
+
if (
|
83
|
+
child.is( 'element', 'blockQuote' ) &&
|
84
|
+
!schema.checkChild( writer.createPositionBefore( child ), child )
|
85
|
+
) {
|
86
|
+
writer.unwrap( child );
|
87
|
+
|
88
|
+
return true;
|
89
|
+
}
|
90
|
+
}
|
91
|
+
}
|
92
|
+
} else if ( entry.type == 'remove' ) {
|
93
|
+
const parent = entry.position.parent;
|
94
|
+
|
95
|
+
if ( parent.is( 'element', 'blockQuote' ) && parent.isEmpty ) {
|
96
|
+
// Something got removed and now blockQuote is empty. Remove the blockQuote as well.
|
97
|
+
writer.remove( parent );
|
98
|
+
|
99
|
+
return true;
|
100
|
+
}
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
return false;
|
105
|
+
} );
|
106
|
+
|
107
|
+
const viewDocument = this.editor.editing.view.document;
|
108
|
+
const selection = editor.model.document.selection;
|
109
|
+
const blockQuoteCommand = editor.commands.get( 'blockQuote' );
|
110
|
+
|
111
|
+
// Overwrite default Enter key behavior.
|
112
|
+
// If Enter key is pressed with selection collapsed in empty block inside a quote, break the quote.
|
113
|
+
this.listenTo( viewDocument, 'enter', ( evt, data ) => {
|
114
|
+
if ( !selection.isCollapsed || !blockQuoteCommand.value ) {
|
115
|
+
return;
|
116
|
+
}
|
117
|
+
|
118
|
+
const positionParent = selection.getLastPosition().parent;
|
119
|
+
|
120
|
+
if ( positionParent.isEmpty ) {
|
121
|
+
editor.execute( 'blockQuote' );
|
122
|
+
editor.editing.view.scrollToTheSelection();
|
123
|
+
|
124
|
+
data.preventDefault();
|
125
|
+
evt.stop();
|
126
|
+
}
|
127
|
+
}, { context: 'blockquote' } );
|
128
|
+
|
129
|
+
// Overwrite default Backspace key behavior.
|
130
|
+
// If Backspace key is pressed with selection collapsed in first empty block inside a quote, break the quote.
|
131
|
+
this.listenTo( viewDocument, 'delete', ( evt, data ) => {
|
132
|
+
if ( data.direction != 'backward' || !selection.isCollapsed || !blockQuoteCommand.value ) {
|
133
|
+
return;
|
134
|
+
}
|
135
|
+
|
136
|
+
const positionParent = selection.getLastPosition().parent;
|
137
|
+
|
138
|
+
if ( positionParent.isEmpty && !positionParent.previousSibling ) {
|
139
|
+
editor.execute( 'blockQuote' );
|
140
|
+
editor.editing.view.scrollToTheSelection();
|
141
|
+
|
142
|
+
data.preventDefault();
|
143
|
+
evt.stop();
|
144
|
+
}
|
145
|
+
}, { context: 'blockquote' } );
|
146
|
+
}
|
147
|
+
}
|
@@ -0,0 +1,60 @@
|
|
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 block-quote/blockquoteui
|
8
|
+
*/
|
9
|
+
|
10
|
+
import { Plugin, icons } from 'ckeditor5/src/core';
|
11
|
+
import { ButtonView } from 'ckeditor5/src/ui';
|
12
|
+
|
13
|
+
import '../theme/blockquote.css';
|
14
|
+
|
15
|
+
/**
|
16
|
+
* The block quote UI plugin.
|
17
|
+
*
|
18
|
+
* It introduces the `'blockQuote'` button.
|
19
|
+
*
|
20
|
+
* @extends module:core/plugin~Plugin
|
21
|
+
*/
|
22
|
+
export default class BlockQuoteUI extends Plugin {
|
23
|
+
/**
|
24
|
+
* @inheritDoc
|
25
|
+
*/
|
26
|
+
static get pluginName() {
|
27
|
+
return 'BlockQuoteUI';
|
28
|
+
}
|
29
|
+
|
30
|
+
/**
|
31
|
+
* @inheritDoc
|
32
|
+
*/
|
33
|
+
init() {
|
34
|
+
const editor = this.editor;
|
35
|
+
const t = editor.t;
|
36
|
+
|
37
|
+
editor.ui.componentFactory.add( 'blockQuote', locale => {
|
38
|
+
const command = editor.commands.get( 'blockQuote' );
|
39
|
+
const buttonView = new ButtonView( locale );
|
40
|
+
|
41
|
+
buttonView.set( {
|
42
|
+
label: t( 'Block quote' ),
|
43
|
+
icon: icons.quote,
|
44
|
+
tooltip: true,
|
45
|
+
isToggleable: true
|
46
|
+
} );
|
47
|
+
|
48
|
+
// Bind button model to command.
|
49
|
+
buttonView.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' );
|
50
|
+
|
51
|
+
// Execute command.
|
52
|
+
this.listenTo( buttonView, 'execute', () => {
|
53
|
+
editor.execute( 'blockQuote' );
|
54
|
+
editor.editing.view.focus();
|
55
|
+
} );
|
56
|
+
|
57
|
+
return buttonView;
|
58
|
+
} );
|
59
|
+
}
|
60
|
+
}
|
package/src/index.js
ADDED
@@ -0,0 +1,12 @@
|
|
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 block-quote
|
8
|
+
*/
|
9
|
+
|
10
|
+
export { default as BlockQuote } from './blockquote';
|
11
|
+
export { default as BlockQuoteEditing } from './blockquoteediting';
|
12
|
+
export { default as BlockQuoteUI } from './blockquoteui';
|
@@ -0,0 +1,23 @@
|
|
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
|
+
.ck-content blockquote {
|
7
|
+
/* See #12 */
|
8
|
+
overflow: hidden;
|
9
|
+
|
10
|
+
/* https://github.com/ckeditor/ckeditor5-block-quote/issues/15 */
|
11
|
+
padding-right: 1.5em;
|
12
|
+
padding-left: 1.5em;
|
13
|
+
|
14
|
+
margin-left: 0;
|
15
|
+
margin-right: 0;
|
16
|
+
font-style: italic;
|
17
|
+
border-left: solid 5px hsl(0, 0%, 80%);
|
18
|
+
}
|
19
|
+
|
20
|
+
.ck-content[dir="rtl"] blockquote {
|
21
|
+
border-left: 0;
|
22
|
+
border-right: solid 5px hsl(0, 0%, 80%);
|
23
|
+
}
|