@ckeditor/ckeditor5-code-block 35.4.0 → 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/build/code-block.js +2 -2
- package/build/translations/ug.js +1 -1
- package/lang/translations/ug.po +1 -1
- package/package.json +26 -22
- package/src/codeblock.js +13 -151
- package/src/codeblockcommand.js +126 -191
- package/src/codeblockediting.js +358 -445
- package/src/codeblockui.js +69 -96
- package/src/converters.js +206 -240
- package/src/indentcodeblockcommand.js +66 -93
- package/src/index.js +1 -3
- package/src/outdentcodeblockcommand.js +121 -165
- package/src/utils.js +132 -161
- package/theme/codeblock.css +1 -1
package/src/codeblockui.js
CHANGED
|
@@ -1,115 +1,88 @@
|
|
|
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
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module code-block/codeblockui
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import { Plugin } from 'ckeditor5/src/core';
|
|
11
9
|
import { Collection } from 'ckeditor5/src/utils';
|
|
12
10
|
import { Model, SplitButtonView, createDropdown, addListToDropdown } from 'ckeditor5/src/ui';
|
|
13
|
-
|
|
14
11
|
import { getNormalizedAndLocalizedLanguageDefinitions } from './utils';
|
|
15
|
-
|
|
16
12
|
import codeBlockIcon from '../theme/icons/codeblock.svg';
|
|
17
13
|
import '../theme/codeblock.css';
|
|
18
|
-
|
|
19
14
|
/**
|
|
20
15
|
* The code block UI plugin.
|
|
21
16
|
*
|
|
22
17
|
* Introduces the `'codeBlock'` dropdown.
|
|
23
|
-
*
|
|
24
|
-
* @extends module:core/plugin~Plugin
|
|
25
18
|
*/
|
|
26
19
|
export default class CodeBlockUI extends Plugin {
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
for ( const languageDef of normalizedLanguageDefs ) {
|
|
97
|
-
const definition = {
|
|
98
|
-
type: 'button',
|
|
99
|
-
model: new Model( {
|
|
100
|
-
_codeBlockLanguage: languageDef.language,
|
|
101
|
-
label: languageDef.label,
|
|
102
|
-
withText: true
|
|
103
|
-
} )
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
definition.model.bind( 'isOn' ).to( command, 'value', value => {
|
|
107
|
-
return value === definition.model._codeBlockLanguage;
|
|
108
|
-
} );
|
|
109
|
-
|
|
110
|
-
itemDefinitions.add( definition );
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return itemDefinitions;
|
|
114
|
-
}
|
|
20
|
+
/**
|
|
21
|
+
* @inheritDoc
|
|
22
|
+
*/
|
|
23
|
+
static get pluginName() {
|
|
24
|
+
return 'CodeBlockUI';
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* @inheritDoc
|
|
28
|
+
*/
|
|
29
|
+
init() {
|
|
30
|
+
const editor = this.editor;
|
|
31
|
+
const t = editor.t;
|
|
32
|
+
const componentFactory = editor.ui.componentFactory;
|
|
33
|
+
const normalizedLanguageDefs = getNormalizedAndLocalizedLanguageDefinitions(editor);
|
|
34
|
+
componentFactory.add('codeBlock', locale => {
|
|
35
|
+
const command = editor.commands.get('codeBlock');
|
|
36
|
+
const dropdownView = createDropdown(locale, SplitButtonView);
|
|
37
|
+
const splitButtonView = dropdownView.buttonView;
|
|
38
|
+
splitButtonView.set({
|
|
39
|
+
label: t('Insert code block'),
|
|
40
|
+
tooltip: true,
|
|
41
|
+
icon: codeBlockIcon,
|
|
42
|
+
isToggleable: true
|
|
43
|
+
});
|
|
44
|
+
splitButtonView.bind('isOn').to(command, 'value', value => !!value);
|
|
45
|
+
splitButtonView.on('execute', () => {
|
|
46
|
+
editor.execute('codeBlock', {
|
|
47
|
+
usePreviousLanguageChoice: true
|
|
48
|
+
});
|
|
49
|
+
editor.editing.view.focus();
|
|
50
|
+
});
|
|
51
|
+
dropdownView.on('execute', evt => {
|
|
52
|
+
editor.execute('codeBlock', {
|
|
53
|
+
language: evt.source._codeBlockLanguage,
|
|
54
|
+
forceValue: true
|
|
55
|
+
});
|
|
56
|
+
editor.editing.view.focus();
|
|
57
|
+
});
|
|
58
|
+
dropdownView.class = 'ck-code-block-dropdown';
|
|
59
|
+
dropdownView.bind('isEnabled').to(command);
|
|
60
|
+
addListToDropdown(dropdownView, () => this._getLanguageListItemDefinitions(normalizedLanguageDefs));
|
|
61
|
+
return dropdownView;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* A helper returning a collection of the `codeBlock` dropdown items representing languages
|
|
66
|
+
* available for the user to choose from.
|
|
67
|
+
*/
|
|
68
|
+
_getLanguageListItemDefinitions(normalizedLanguageDefs) {
|
|
69
|
+
const editor = this.editor;
|
|
70
|
+
const command = editor.commands.get('codeBlock');
|
|
71
|
+
const itemDefinitions = new Collection();
|
|
72
|
+
for (const languageDef of normalizedLanguageDefs) {
|
|
73
|
+
const definition = {
|
|
74
|
+
type: 'button',
|
|
75
|
+
model: new Model({
|
|
76
|
+
_codeBlockLanguage: languageDef.language,
|
|
77
|
+
label: languageDef.label,
|
|
78
|
+
withText: true
|
|
79
|
+
})
|
|
80
|
+
};
|
|
81
|
+
definition.model.bind('isOn').to(command, 'value', value => {
|
|
82
|
+
return value === definition.model._codeBlockLanguage;
|
|
83
|
+
});
|
|
84
|
+
itemDefinitions.add(definition);
|
|
85
|
+
}
|
|
86
|
+
return itemDefinitions;
|
|
87
|
+
}
|
|
115
88
|
}
|