@ckeditor/ckeditor5-code-block 40.0.0 → 40.2.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.
@@ -1,29 +1,29 @@
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 code-block/codeblockui
7
- */
8
- import { Plugin } from 'ckeditor5/src/core';
9
- import '../theme/codeblock.css';
10
- /**
11
- * The code block UI plugin.
12
- *
13
- * Introduces the `'codeBlock'` dropdown.
14
- */
15
- export default class CodeBlockUI extends Plugin {
16
- /**
17
- * @inheritDoc
18
- */
19
- static get pluginName(): "CodeBlockUI";
20
- /**
21
- * @inheritDoc
22
- */
23
- init(): void;
24
- /**
25
- * A helper returning a collection of the `codeBlock` dropdown items representing languages
26
- * available for the user to choose from.
27
- */
28
- private _getLanguageListItemDefinitions;
29
- }
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 code-block/codeblockui
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core';
9
+ import '../theme/codeblock.css';
10
+ /**
11
+ * The code block UI plugin.
12
+ *
13
+ * Introduces the `'codeBlock'` dropdown.
14
+ */
15
+ export default class CodeBlockUI extends Plugin {
16
+ /**
17
+ * @inheritDoc
18
+ */
19
+ static get pluginName(): "CodeBlockUI";
20
+ /**
21
+ * @inheritDoc
22
+ */
23
+ init(): void;
24
+ /**
25
+ * A helper returning a collection of the `codeBlock` dropdown items representing languages
26
+ * available for the user to choose from.
27
+ */
28
+ private _getLanguageListItemDefinitions;
29
+ }
@@ -1,93 +1,93 @@
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 code-block/codeblockui
7
- */
8
- import { Plugin } from 'ckeditor5/src/core';
9
- import { Collection } from 'ckeditor5/src/utils';
10
- import { Model, SplitButtonView, createDropdown, addListToDropdown } from 'ckeditor5/src/ui';
11
- import { getNormalizedAndLocalizedLanguageDefinitions } from './utils';
12
- import codeBlockIcon from '../theme/icons/codeblock.svg';
13
- import '../theme/codeblock.css';
14
- /**
15
- * The code block UI plugin.
16
- *
17
- * Introduces the `'codeBlock'` dropdown.
18
- */
19
- export default class CodeBlockUI extends Plugin {
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
- const accessibleLabel = t('Insert code block');
39
- splitButtonView.set({
40
- label: accessibleLabel,
41
- tooltip: true,
42
- icon: codeBlockIcon,
43
- isToggleable: true
44
- });
45
- splitButtonView.bind('isOn').to(command, 'value', value => !!value);
46
- splitButtonView.on('execute', () => {
47
- editor.execute('codeBlock', {
48
- usePreviousLanguageChoice: true
49
- });
50
- editor.editing.view.focus();
51
- });
52
- dropdownView.on('execute', evt => {
53
- editor.execute('codeBlock', {
54
- language: evt.source._codeBlockLanguage,
55
- forceValue: true
56
- });
57
- editor.editing.view.focus();
58
- });
59
- dropdownView.class = 'ck-code-block-dropdown';
60
- dropdownView.bind('isEnabled').to(command);
61
- addListToDropdown(dropdownView, () => this._getLanguageListItemDefinitions(normalizedLanguageDefs), {
62
- role: 'menu',
63
- ariaLabel: accessibleLabel
64
- });
65
- return dropdownView;
66
- });
67
- }
68
- /**
69
- * A helper returning a collection of the `codeBlock` dropdown items representing languages
70
- * available for the user to choose from.
71
- */
72
- _getLanguageListItemDefinitions(normalizedLanguageDefs) {
73
- const editor = this.editor;
74
- const command = editor.commands.get('codeBlock');
75
- const itemDefinitions = new Collection();
76
- for (const languageDef of normalizedLanguageDefs) {
77
- const definition = {
78
- type: 'button',
79
- model: new Model({
80
- _codeBlockLanguage: languageDef.language,
81
- label: languageDef.label,
82
- role: 'menuitemradio',
83
- withText: true
84
- })
85
- };
86
- definition.model.bind('isOn').to(command, 'value', value => {
87
- return value === definition.model._codeBlockLanguage;
88
- });
89
- itemDefinitions.add(definition);
90
- }
91
- return itemDefinitions;
92
- }
93
- }
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 code-block/codeblockui
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core';
9
+ import { Collection } from 'ckeditor5/src/utils';
10
+ import { Model, SplitButtonView, createDropdown, addListToDropdown } from 'ckeditor5/src/ui';
11
+ import { getNormalizedAndLocalizedLanguageDefinitions } from './utils';
12
+ import codeBlockIcon from '../theme/icons/codeblock.svg';
13
+ import '../theme/codeblock.css';
14
+ /**
15
+ * The code block UI plugin.
16
+ *
17
+ * Introduces the `'codeBlock'` dropdown.
18
+ */
19
+ export default class CodeBlockUI extends Plugin {
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
+ const accessibleLabel = t('Insert code block');
39
+ splitButtonView.set({
40
+ label: accessibleLabel,
41
+ tooltip: true,
42
+ icon: codeBlockIcon,
43
+ isToggleable: true
44
+ });
45
+ splitButtonView.bind('isOn').to(command, 'value', value => !!value);
46
+ splitButtonView.on('execute', () => {
47
+ editor.execute('codeBlock', {
48
+ usePreviousLanguageChoice: true
49
+ });
50
+ editor.editing.view.focus();
51
+ });
52
+ dropdownView.on('execute', evt => {
53
+ editor.execute('codeBlock', {
54
+ language: evt.source._codeBlockLanguage,
55
+ forceValue: true
56
+ });
57
+ editor.editing.view.focus();
58
+ });
59
+ dropdownView.class = 'ck-code-block-dropdown';
60
+ dropdownView.bind('isEnabled').to(command);
61
+ addListToDropdown(dropdownView, () => this._getLanguageListItemDefinitions(normalizedLanguageDefs), {
62
+ role: 'menu',
63
+ ariaLabel: accessibleLabel
64
+ });
65
+ return dropdownView;
66
+ });
67
+ }
68
+ /**
69
+ * A helper returning a collection of the `codeBlock` dropdown items representing languages
70
+ * available for the user to choose from.
71
+ */
72
+ _getLanguageListItemDefinitions(normalizedLanguageDefs) {
73
+ const editor = this.editor;
74
+ const command = editor.commands.get('codeBlock');
75
+ const itemDefinitions = new Collection();
76
+ for (const languageDef of normalizedLanguageDefs) {
77
+ const definition = {
78
+ type: 'button',
79
+ model: new Model({
80
+ _codeBlockLanguage: languageDef.language,
81
+ label: languageDef.label,
82
+ role: 'menuitemradio',
83
+ withText: true
84
+ })
85
+ };
86
+ definition.model.bind('isOn').to(command, 'value', value => {
87
+ return value === definition.model._codeBlockLanguage;
88
+ });
89
+ itemDefinitions.add(definition);
90
+ }
91
+ return itemDefinitions;
92
+ }
93
+ }
@@ -1,126 +1,126 @@
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 code-block/converters
7
- */
8
- import type { GetCallback } from 'ckeditor5/src/utils';
9
- import type { DowncastInsertEvent, Model, UpcastElementEvent, UpcastTextEvent, View } from 'ckeditor5/src/engine';
10
- import type { CodeBlockLanguageDefinition } from './codeblockconfig';
11
- /**
12
- * A model-to-view (both editing and data) converter for the `codeBlock` element.
13
- *
14
- * Sample input:
15
- *
16
- * ```html
17
- * <codeBlock language="javascript">foo();<softBreak></softBreak>bar();</codeBlock>
18
- * ```
19
- *
20
- * Sample output (editing):
21
- *
22
- * ```html
23
- * <pre data-language="JavaScript"><code class="language-javascript">foo();<br />bar();</code></pre>
24
- * ```
25
- *
26
- * Sample output (data, see {@link module:code-block/converters~modelToDataViewSoftBreakInsertion}):
27
- *
28
- * ```html
29
- * <pre><code class="language-javascript">foo();\nbar();</code></pre>
30
- * ```
31
- *
32
- * @param languageDefs The normalized language configuration passed to the feature.
33
- * @param useLabels When `true`, the `<pre>` element will get a `data-language` attribute with a
34
- * human–readable label of the language. Used only in the editing.
35
- * @returns Returns a conversion callback.
36
- */
37
- export declare function modelToViewCodeBlockInsertion(model: Model, languageDefs: Array<CodeBlockLanguageDefinition>, useLabels?: boolean): GetCallback<DowncastInsertEvent>;
38
- /**
39
- * A model-to-data view converter for the new line (`softBreak`) separator.
40
- *
41
- * Sample input:
42
- *
43
- * ```html
44
- * <codeBlock ...>foo();<softBreak></softBreak>bar();</codeBlock>
45
- * ```
46
- *
47
- * Sample output:
48
- *
49
- * ```html
50
- * <pre><code ...>foo();\nbar();</code></pre>
51
- * ```
52
- *
53
- * @returns Returns a conversion callback.
54
- */
55
- export declare function modelToDataViewSoftBreakInsertion(model: Model): GetCallback<DowncastInsertEvent>;
56
- /**
57
- * A view-to-model converter for `<pre>` with the `<code>` HTML.
58
- *
59
- * Sample input:
60
- *
61
- * ```html
62
- * <pre><code class="language-javascript">foo();bar();</code></pre>
63
- * ```
64
- *
65
- * Sample output:
66
- *
67
- * ```html
68
- * <codeBlock language="javascript">foo();bar();</codeBlock>
69
- * ```
70
- *
71
- * @param languageDefs The normalized language configuration passed to the feature.
72
- * @returns Returns a conversion callback.
73
- */
74
- export declare function dataViewToModelCodeBlockInsertion(editingView: View, languageDefs: Array<CodeBlockLanguageDefinition>): GetCallback<UpcastElementEvent>;
75
- /**
76
- * A view-to-model converter for new line characters in `<pre>`.
77
- *
78
- * Sample input:
79
- *
80
- * ```html
81
- * <pre><code class="language-javascript">foo();\nbar();</code></pre>
82
- * ```
83
- *
84
- * Sample output:
85
- *
86
- * ```html
87
- * <codeBlock language="javascript">foo();<softBreak></softBreak>bar();</codeBlock>
88
- * ```
89
- *
90
- * @returns {Function} Returns a conversion callback.
91
- */
92
- export declare function dataViewToModelTextNewlinesInsertion(): GetCallback<UpcastTextEvent>;
93
- /**
94
- * A view-to-model converter that handles orphan text nodes (white spaces, new lines, etc.)
95
- * that surround `<code>` inside `<pre>`.
96
- *
97
- * Sample input:
98
- *
99
- * ```html
100
- * // White spaces
101
- * <pre> <code>foo()</code> </pre>
102
- *
103
- * // White spaces
104
- * <pre> <code>foo()</code> </pre>
105
- *
106
- * // White spaces
107
- * <pre> <code>foo()</code> </pre>
108
- *
109
- * // New lines
110
- * <pre>
111
- * <code>foo()</code>
112
- * </pre>
113
- *
114
- * // Redundant text
115
- * <pre>ABC<code>foo()</code>DEF</pre>
116
- * ```
117
- *
118
- * Unified output for each case:
119
- *
120
- * ```html
121
- * <codeBlock language="plaintext">foo()</codeBlock>
122
- * ```
123
- *
124
- * @returns Returns a conversion callback.
125
- */
126
- export declare function dataViewToModelOrphanNodeConsumer(): GetCallback<UpcastElementEvent>;
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 code-block/converters
7
+ */
8
+ import type { GetCallback } from 'ckeditor5/src/utils';
9
+ import type { DowncastInsertEvent, Model, UpcastElementEvent, UpcastTextEvent, View } from 'ckeditor5/src/engine';
10
+ import type { CodeBlockLanguageDefinition } from './codeblockconfig';
11
+ /**
12
+ * A model-to-view (both editing and data) converter for the `codeBlock` element.
13
+ *
14
+ * Sample input:
15
+ *
16
+ * ```html
17
+ * <codeBlock language="javascript">foo();<softBreak></softBreak>bar();</codeBlock>
18
+ * ```
19
+ *
20
+ * Sample output (editing):
21
+ *
22
+ * ```html
23
+ * <pre data-language="JavaScript"><code class="language-javascript">foo();<br />bar();</code></pre>
24
+ * ```
25
+ *
26
+ * Sample output (data, see {@link module:code-block/converters~modelToDataViewSoftBreakInsertion}):
27
+ *
28
+ * ```html
29
+ * <pre><code class="language-javascript">foo();\nbar();</code></pre>
30
+ * ```
31
+ *
32
+ * @param languageDefs The normalized language configuration passed to the feature.
33
+ * @param useLabels When `true`, the `<pre>` element will get a `data-language` attribute with a
34
+ * human–readable label of the language. Used only in the editing.
35
+ * @returns Returns a conversion callback.
36
+ */
37
+ export declare function modelToViewCodeBlockInsertion(model: Model, languageDefs: Array<CodeBlockLanguageDefinition>, useLabels?: boolean): GetCallback<DowncastInsertEvent>;
38
+ /**
39
+ * A model-to-data view converter for the new line (`softBreak`) separator.
40
+ *
41
+ * Sample input:
42
+ *
43
+ * ```html
44
+ * <codeBlock ...>foo();<softBreak></softBreak>bar();</codeBlock>
45
+ * ```
46
+ *
47
+ * Sample output:
48
+ *
49
+ * ```html
50
+ * <pre><code ...>foo();\nbar();</code></pre>
51
+ * ```
52
+ *
53
+ * @returns Returns a conversion callback.
54
+ */
55
+ export declare function modelToDataViewSoftBreakInsertion(model: Model): GetCallback<DowncastInsertEvent>;
56
+ /**
57
+ * A view-to-model converter for `<pre>` with the `<code>` HTML.
58
+ *
59
+ * Sample input:
60
+ *
61
+ * ```html
62
+ * <pre><code class="language-javascript">foo();bar();</code></pre>
63
+ * ```
64
+ *
65
+ * Sample output:
66
+ *
67
+ * ```html
68
+ * <codeBlock language="javascript">foo();bar();</codeBlock>
69
+ * ```
70
+ *
71
+ * @param languageDefs The normalized language configuration passed to the feature.
72
+ * @returns Returns a conversion callback.
73
+ */
74
+ export declare function dataViewToModelCodeBlockInsertion(editingView: View, languageDefs: Array<CodeBlockLanguageDefinition>): GetCallback<UpcastElementEvent>;
75
+ /**
76
+ * A view-to-model converter for new line characters in `<pre>`.
77
+ *
78
+ * Sample input:
79
+ *
80
+ * ```html
81
+ * <pre><code class="language-javascript">foo();\nbar();</code></pre>
82
+ * ```
83
+ *
84
+ * Sample output:
85
+ *
86
+ * ```html
87
+ * <codeBlock language="javascript">foo();<softBreak></softBreak>bar();</codeBlock>
88
+ * ```
89
+ *
90
+ * @returns {Function} Returns a conversion callback.
91
+ */
92
+ export declare function dataViewToModelTextNewlinesInsertion(): GetCallback<UpcastTextEvent>;
93
+ /**
94
+ * A view-to-model converter that handles orphan text nodes (white spaces, new lines, etc.)
95
+ * that surround `<code>` inside `<pre>`.
96
+ *
97
+ * Sample input:
98
+ *
99
+ * ```html
100
+ * // White spaces
101
+ * <pre> <code>foo()</code> </pre>
102
+ *
103
+ * // White spaces
104
+ * <pre> <code>foo()</code> </pre>
105
+ *
106
+ * // White spaces
107
+ * <pre> <code>foo()</code> </pre>
108
+ *
109
+ * // New lines
110
+ * <pre>
111
+ * <code>foo()</code>
112
+ * </pre>
113
+ *
114
+ * // Redundant text
115
+ * <pre>ABC<code>foo()</code>DEF</pre>
116
+ * ```
117
+ *
118
+ * Unified output for each case:
119
+ *
120
+ * ```html
121
+ * <codeBlock language="plaintext">foo()</codeBlock>
122
+ * ```
123
+ *
124
+ * @returns Returns a conversion callback.
125
+ */
126
+ export declare function dataViewToModelOrphanNodeConsumer(): GetCallback<UpcastElementEvent>;