@ckeditor/ckeditor5-code-block 36.0.1 → 37.0.0-alpha.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-code-block",
3
- "version": "36.0.1",
3
+ "version": "37.0.0-alpha.1",
4
4
  "description": "Code block feature for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -12,27 +12,27 @@
12
12
  ],
13
13
  "main": "src/index.js",
14
14
  "dependencies": {
15
- "ckeditor5": "^36.0.1"
15
+ "ckeditor5": "^37.0.0-alpha.1"
16
16
  },
17
17
  "devDependencies": {
18
- "@ckeditor/ckeditor5-alignment": "^36.0.1",
19
- "@ckeditor/ckeditor5-autoformat": "^36.0.1",
20
- "@ckeditor/ckeditor5-basic-styles": "^36.0.1",
21
- "@ckeditor/ckeditor5-block-quote": "^36.0.1",
22
- "@ckeditor/ckeditor5-clipboard": "^36.0.1",
23
- "@ckeditor/ckeditor5-core": "^36.0.1",
24
- "@ckeditor/ckeditor5-dev-utils": "^32.0.0",
25
- "@ckeditor/ckeditor5-engine": "^36.0.1",
26
- "@ckeditor/ckeditor5-enter": "^36.0.1",
27
- "@ckeditor/ckeditor5-editor-classic": "^36.0.1",
28
- "@ckeditor/ckeditor5-image": "^36.0.1",
29
- "@ckeditor/ckeditor5-indent": "^36.0.1",
30
- "@ckeditor/ckeditor5-list": "^36.0.1",
31
- "@ckeditor/ckeditor5-markdown-gfm": "^36.0.1",
32
- "@ckeditor/ckeditor5-paragraph": "^36.0.1",
33
- "@ckeditor/ckeditor5-theme-lark": "^36.0.1",
34
- "@ckeditor/ckeditor5-undo": "^36.0.1",
35
- "@ckeditor/ckeditor5-utils": "^36.0.1",
18
+ "@ckeditor/ckeditor5-alignment": "^37.0.0-alpha.1",
19
+ "@ckeditor/ckeditor5-autoformat": "^37.0.0-alpha.1",
20
+ "@ckeditor/ckeditor5-basic-styles": "^37.0.0-alpha.1",
21
+ "@ckeditor/ckeditor5-block-quote": "^37.0.0-alpha.1",
22
+ "@ckeditor/ckeditor5-clipboard": "^37.0.0-alpha.1",
23
+ "@ckeditor/ckeditor5-core": "^37.0.0-alpha.1",
24
+ "@ckeditor/ckeditor5-dev-utils": "^35.0.0",
25
+ "@ckeditor/ckeditor5-engine": "^37.0.0-alpha.1",
26
+ "@ckeditor/ckeditor5-enter": "^37.0.0-alpha.1",
27
+ "@ckeditor/ckeditor5-editor-classic": "^37.0.0-alpha.1",
28
+ "@ckeditor/ckeditor5-image": "^37.0.0-alpha.1",
29
+ "@ckeditor/ckeditor5-indent": "^37.0.0-alpha.1",
30
+ "@ckeditor/ckeditor5-list": "^37.0.0-alpha.1",
31
+ "@ckeditor/ckeditor5-markdown-gfm": "^37.0.0-alpha.1",
32
+ "@ckeditor/ckeditor5-paragraph": "^37.0.0-alpha.1",
33
+ "@ckeditor/ckeditor5-theme-lark": "^37.0.0-alpha.1",
34
+ "@ckeditor/ckeditor5-undo": "^37.0.0-alpha.1",
35
+ "@ckeditor/ckeditor5-utils": "^37.0.0-alpha.1",
36
36
  "typescript": "^4.8.4",
37
37
  "webpack": "^5.58.1",
38
38
  "webpack-cli": "^4.9.0"
@@ -61,7 +61,8 @@
61
61
  ],
62
62
  "scripts": {
63
63
  "dll:build": "webpack",
64
- "build": "tsc -p ./tsconfig.release.json",
64
+ "build": "tsc -p ./tsconfig.json",
65
65
  "postversion": "npm run build"
66
- }
66
+ },
67
+ "types": "src/index.d.ts"
67
68
  }
@@ -0,0 +1,25 @@
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
+ import type { CodeBlock, CodeBlockCommand, CodeBlockConfig, CodeBlockEditing, CodeBlockUI, IndentCodeBlockCommand, OutdentCodeBlockCommand } from './index';
6
+ declare module '@ckeditor/ckeditor5-core' {
7
+ interface EditorConfig {
8
+ /**
9
+ * The configuration of the {@link module:code-block/codeblock~CodeBlock} feature.
10
+ *
11
+ * Read more in {@link module:code-block/codeblockconfig~CodeBlockConfig}.
12
+ */
13
+ codeBlock?: CodeBlockConfig;
14
+ }
15
+ interface PluginsMap {
16
+ [CodeBlock.pluginName]: CodeBlock;
17
+ [CodeBlockEditing.pluginName]: CodeBlockEditing;
18
+ [CodeBlockUI.pluginName]: CodeBlockUI;
19
+ }
20
+ interface CommandsMap {
21
+ codeBlock: CodeBlockCommand;
22
+ indentCodeBlock: IndentCodeBlockCommand;
23
+ outdentCodeBlock: OutdentCodeBlockCommand;
24
+ }
25
+ }
@@ -0,0 +1,5 @@
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
+ export {};
@@ -0,0 +1,27 @@
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/codeblock
7
+ */
8
+ import { Plugin, type PluginDependencies } from 'ckeditor5/src/core';
9
+ /**
10
+ * The code block plugin.
11
+ *
12
+ * For more information about this feature check the {@glink api/code-block package page} and the
13
+ * {@glink features/code-blocks code block} feature guide.
14
+ *
15
+ * This is a "glue" plugin that loads the {@link module:code-block/codeblockediting~CodeBlockEditing code block editing feature}
16
+ * and the {@link module:code-block/codeblockui~CodeBlockUI code block UI feature}.
17
+ */
18
+ export default class CodeBlock extends Plugin {
19
+ /**
20
+ * @inheritDoc
21
+ */
22
+ static get requires(): PluginDependencies;
23
+ /**
24
+ * @inheritDoc
25
+ */
26
+ static get pluginName(): 'CodeBlock';
27
+ }
package/src/codeblock.js CHANGED
@@ -12,7 +12,7 @@ import CodeBlockUI from './codeblockui';
12
12
  * The code block plugin.
13
13
  *
14
14
  * For more information about this feature check the {@glink api/code-block package page} and the
15
- * {@glink features/code-blocks code block feature guide}.
15
+ * {@glink features/code-blocks code block} feature guide.
16
16
  *
17
17
  * This is a "glue" plugin that loads the {@link module:code-block/codeblockediting~CodeBlockEditing code block editing feature}
18
18
  * and the {@link module:code-block/codeblockui~CodeBlockUI code block UI feature}.
@@ -0,0 +1,60 @@
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
+ import { Command, type Editor } from 'ckeditor5/src/core';
6
+ /**
7
+ * The code block command plugin.
8
+ */
9
+ export default class CodeBlockCommand extends Command {
10
+ /**
11
+ * Contains the last used language.
12
+ */
13
+ private _lastLanguage;
14
+ /**
15
+ * Contains language if any is selected, false otherwise.
16
+ * @observable
17
+ * @readonly
18
+ */
19
+ value: string | false;
20
+ /**
21
+ * @inheritDoc
22
+ */
23
+ constructor(editor: Editor);
24
+ /**
25
+ * @inheritDoc
26
+ */
27
+ refresh(): void;
28
+ /**
29
+ * Executes the command. When the command {@link #value is on}, all topmost code blocks within
30
+ * the selection will be removed. If it is off, all selected blocks will be flattened and
31
+ * wrapped by a code block.
32
+ *
33
+ * @fires execute
34
+ * @param options Command options.
35
+ * @param options.language The code block language.
36
+ * @param options.forceValue If set, it will force the command behavior. If `true`, the command will apply a code block,
37
+ * otherwise the command will remove the code block. If not set, the command will act basing on its current value.
38
+ * @param options.usePreviousLanguageChoice If set on `true` and the `options.language` is not specified, the command
39
+ * will apply the previous language (if the command was already executed) when inserting the `codeBlock` element.
40
+ */
41
+ execute(options?: {
42
+ language?: string;
43
+ forceValue?: boolean;
44
+ usePreviousLanguageChoice?: boolean;
45
+ }): void;
46
+ /**
47
+ * Checks the command's {@link #value}.
48
+ *
49
+ * @returns The current value.
50
+ */
51
+ private _getValue;
52
+ /**
53
+ * Checks whether the command can be enabled in the current context.
54
+ *
55
+ * @returns Whether the command should be enabled.
56
+ */
57
+ private _checkEnabled;
58
+ private _applyCodeBlock;
59
+ private _removeCodeBlock;
60
+ }
@@ -0,0 +1,146 @@
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/codeblockconfig
7
+ */
8
+ /**
9
+ * The configuration of the {@link module:code-block/codeblock~CodeBlock code block feature}.
10
+ *
11
+ * ```ts
12
+ * ClassicEditor
13
+ * .create( editorElement, {
14
+ * codeBlock: ... // The code block feature configuration.
15
+ * } )
16
+ * .then( ... )
17
+ * .catch( ... );
18
+ * ```
19
+ *
20
+ * See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
21
+ */
22
+ export interface CodeBlockConfig {
23
+ /**
24
+ * The list of code languages available in the user interface to choose for a particular code block.
25
+ *
26
+ * The language of the code block is represented as a CSS class (by default prefixed by "language-") set on the
27
+ * `<code>` element, both when editing and in the editor data. The CSS class associated with the language
28
+ * can be used by third–party code syntax highlighters to detect and apply the correct highlighting.
29
+ *
30
+ * For instance, this language configuration:
31
+ *
32
+ * ```ts
33
+ * ClassicEditor
34
+ * .create( document.querySelector( '#editor' ), {
35
+ * codeBlock: {
36
+ * languages: [
37
+ * // ...
38
+ * { language: 'javascript', label: 'JavaScript' },
39
+ * // ...
40
+ * ]
41
+ * }
42
+ * } )
43
+ * .then( ... )
44
+ * .catch( ... );
45
+ * ```
46
+ *
47
+ * will result in the following structure of JavaScript code blocks in the editor editing and data:
48
+ *
49
+ * ```html
50
+ * <pre><code class="language-javascript">window.alert( 'Hello world!' )</code></pre>
51
+ * ```
52
+ *
53
+ * You can customize the CSS class by specifying an optional `class` property in the language definition.
54
+ * You can set **multiple classes** but **only the first one** will be used as defining language class:
55
+ *
56
+ * ```ts
57
+ * ClassicEditor
58
+ * .create( document.querySelector( '#editor' ), {
59
+ * codeBlock: {
60
+ * languages: [
61
+ * // Do not render the CSS class for the plain text code blocks.
62
+ * { language: 'plaintext', label: 'Plain text', class: '' },
63
+ *
64
+ * // Use the "php-code" class for PHP code blocks.
65
+ * { language: 'php', label: 'PHP', class: 'php-code' },
66
+ *
67
+ * // Use the "js" class for JavaScript code blocks.
68
+ * // Note that only the first ("js") class will determine the language of the block when loading data.
69
+ * { language: 'javascript', label: 'JavaScript', class: 'js javascript js-code' },
70
+ *
71
+ * // Python code blocks will have the default "language-python" CSS class.
72
+ * { language: 'python', label: 'Python' }
73
+ * ]
74
+ * }
75
+ * } )
76
+ * .then( ... )
77
+ * .catch( ... );
78
+ * ```
79
+ *
80
+ * The default value of the language configuration is as follows:
81
+ *
82
+ * ```ts
83
+ * languages: [
84
+ * { language: 'plaintext', label: 'Plain text' }, // The default language.
85
+ * { language: 'c', label: 'C' },
86
+ * { language: 'cs', label: 'C#' },
87
+ * { language: 'cpp', label: 'C++' },
88
+ * { language: 'css', label: 'CSS' },
89
+ * { language: 'diff', label: 'Diff' },
90
+ * { language: 'html', label: 'HTML' },
91
+ * { language: 'java', label: 'Java' },
92
+ * { language: 'javascript', label: 'JavaScript' },
93
+ * { language: 'php', label: 'PHP' },
94
+ * { language: 'python', label: 'Python' },
95
+ * { language: 'ruby', label: 'Ruby' },
96
+ * { language: 'typescript', label: 'TypeScript' },
97
+ * { language: 'xml', label: 'XML' }
98
+ * ]
99
+ * ```
100
+ *
101
+ * **Note**: The first language defined in the configuration is considered the default one. This means it will be
102
+ * applied to code blocks loaded from the data that have no CSS `class` specified (or no matching `class` in the configuration).
103
+ * It will also be used when creating new code blocks using the main UI button. By default it is "Plain text".
104
+ */
105
+ languages?: Array<CodeBlockLanguageDefinition>;
106
+ /**
107
+ * A sequence of characters inserted or removed from the code block lines when its indentation
108
+ * is changed by the user, for instance, using <kbd>Tab</kbd> and <kbd>Shift</kbd>+<kbd>Tab</kbd> keys.
109
+ *
110
+ * The default value is a single tab character (" ", `\u0009` in Unicode).
111
+ *
112
+ * This configuration is used by `indentCodeBlock` and `outdentCodeBlock` commands (instances of
113
+ * {@link module:code-block/indentcodeblockcommand~IndentCodeBlockCommand}).
114
+ *
115
+ * **Note**: Setting this configuration to `false` will disable the code block indentation commands
116
+ * and associated keystrokes.
117
+ *
118
+ */
119
+ indentSequence?: string;
120
+ }
121
+ /**
122
+ * The code block language descriptor. See {@link module:code-block/codeblockconfig~CodeBlockConfig#languages} to learn more.
123
+ *
124
+ * ```ts
125
+ * {
126
+ * language: 'javascript',
127
+ * label: 'JavaScript'
128
+ * }
129
+ * ```
130
+ */
131
+ export interface CodeBlockLanguageDefinition {
132
+ /**
133
+ * The name of the language that will be stored in the model attribute. Also, when `class`
134
+ * is not specified, it will be used to create the CSS class associated with the language (prefixed by "language-").
135
+ */
136
+ language: string;
137
+ /**
138
+ * The human–readable label associated with the language and displayed in the UI.
139
+ */
140
+ label: string;
141
+ /**
142
+ * The CSS class associated with the language. When not specified the `language`
143
+ * property is used to create a class prefixed by "language-".
144
+ */
145
+ class?: string;
146
+ }
@@ -0,0 +1,5 @@
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
+ export {};
@@ -0,0 +1,35 @@
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/codeblockediting
7
+ */
8
+ import { Plugin, type PluginDependencies, type Editor } from 'ckeditor5/src/core';
9
+ /**
10
+ * The editing part of the code block feature.
11
+ *
12
+ * Introduces the `'codeBlock'` command and the `'codeBlock'` model element.
13
+ */
14
+ export default class CodeBlockEditing extends Plugin {
15
+ /**
16
+ * @inheritDoc
17
+ */
18
+ static get pluginName(): 'CodeBlockEditing';
19
+ /**
20
+ * @inheritDoc
21
+ */
22
+ static get requires(): PluginDependencies;
23
+ /**
24
+ * @inheritDoc
25
+ */
26
+ constructor(editor: Editor);
27
+ /**
28
+ * @inheritDoc
29
+ */
30
+ init(): void;
31
+ /**
32
+ * @inheritDoc
33
+ */
34
+ afterInit(): void;
35
+ }
@@ -0,0 +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
+ }
@@ -0,0 +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>;
@@ -0,0 +1,33 @@
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/indentcodeblockcommand
7
+ */
8
+ import { Command, type Editor } from 'ckeditor5/src/core';
9
+ /**
10
+ * The code block indentation increase command plugin.
11
+ */
12
+ export default class IndentCodeBlockCommand extends Command {
13
+ /**
14
+ * A sequence of characters added to the line when the command is executed.
15
+ */
16
+ private _indentSequence;
17
+ constructor(editor: Editor);
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ refresh(): void;
22
+ /**
23
+ * Executes the command. When the command {@link #isEnabled is enabled}, the indentation of the
24
+ * code lines in the selection will be increased.
25
+ *
26
+ * @fires execute
27
+ */
28
+ execute(): void;
29
+ /**
30
+ * Checks whether the command can be enabled in the current context.
31
+ */
32
+ private _checkEnabled;
33
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,15 @@
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
7
+ */
8
+ export { default as CodeBlock } from './codeblock';
9
+ export { default as CodeBlockEditing } from './codeblockediting';
10
+ export { default as CodeBlockUI } from './codeblockui';
11
+ export type { default as CodeBlockCommand } from './codeblockcommand';
12
+ export type { default as IndentCodeBlockCommand } from './indentcodeblockcommand';
13
+ export type { default as OutdentCodeBlockCommand } from './outdentcodeblockcommand';
14
+ export type { CodeBlockConfig } from './codeblockconfig';
15
+ import './augmentation';
package/src/index.js CHANGED
@@ -8,3 +8,4 @@
8
8
  export { default as CodeBlock } from './codeblock';
9
9
  export { default as CodeBlockEditing } from './codeblockediting';
10
10
  export { default as CodeBlockUI } from './codeblockui';
11
+ import './augmentation';
@@ -0,0 +1,33 @@
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
+ import { Command, type Editor } from 'ckeditor5/src/core';
6
+ /**
7
+ * The code block indentation decrease command plugin.
8
+ */
9
+ export default class OutdentCodeBlockCommand extends Command {
10
+ /**
11
+ * A sequence of characters removed from the line when the command is executed.
12
+ */
13
+ private readonly _indentSequence;
14
+ constructor(editor: Editor);
15
+ /**
16
+ * @inheritDoc
17
+ */
18
+ refresh(): void;
19
+ /**
20
+ * Executes the command. When the command {@link #isEnabled is enabled}, the indentation of the
21
+ * code lines in the selection will be decreased.
22
+ *
23
+ * @fires execute
24
+ */
25
+ execute(): void;
26
+ /**
27
+ * Checks whether the command can be enabled in the current context.
28
+ *
29
+ * @private
30
+ * @returns {Boolean} Whether the command should be enabled.
31
+ */
32
+ private _checkEnabled;
33
+ }
package/src/utils.d.ts ADDED
@@ -0,0 +1,138 @@
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/utils
7
+ */
8
+ import type { Editor } from 'ckeditor5/src/core';
9
+ import type { CodeBlockLanguageDefinition } from './codeblockconfig';
10
+ import type { DocumentSelection, Element, Model, Position, Schema, Text, UpcastWriter, ViewDocumentFragment } from 'ckeditor5/src/engine';
11
+ /**
12
+ * Returns code block languages as defined in `config.codeBlock.languages` but processed:
13
+ *
14
+ * * To consider the editor localization, i.e. to display {@link module:code-block/codeblockconfig~CodeBlockLanguageDefinition}
15
+ * in the correct language. There is no way to use {@link module:utils/locale~Locale#t} when the user
16
+ * configuration is defined because the editor does not exist yet.
17
+ * * To make sure each definition has a CSS class associated with it even if not specified
18
+ * in the original configuration.
19
+ */
20
+ export declare function getNormalizedAndLocalizedLanguageDefinitions(editor: Editor): Array<CodeBlockLanguageDefinition>;
21
+ /**
22
+ * Returns an object associating certain language definition properties with others. For instance:
23
+ *
24
+ * For:
25
+ *
26
+ * ```ts
27
+ * const definitions = {
28
+ * { language: 'php', class: 'language-php', label: 'PHP' },
29
+ * { language: 'javascript', class: 'js', label: 'JavaScript' },
30
+ * };
31
+ *
32
+ * getPropertyAssociation( definitions, 'class', 'language' );
33
+ * ```
34
+ *
35
+ * returns:
36
+ *
37
+ * ```ts
38
+ * {
39
+ * 'language-php': 'php',
40
+ * 'js': 'javascript'
41
+ * }
42
+ * ```
43
+ *
44
+ * and
45
+ *
46
+ * ```ts
47
+ * getPropertyAssociation( definitions, 'language', 'label' );
48
+ * ```
49
+ *
50
+ * returns:
51
+ *
52
+ * ```ts
53
+ * {
54
+ * 'php': 'PHP',
55
+ * 'javascript': 'JavaScript'
56
+ * }
57
+ * ```
58
+ */
59
+ export declare function getPropertyAssociation(languageDefs: Array<CodeBlockLanguageDefinition>, key: keyof CodeBlockLanguageDefinition, value: keyof CodeBlockLanguageDefinition): Record<string, string>;
60
+ /**
61
+ * For a given model text node, it returns white spaces that precede other characters in that node.
62
+ * This corresponds to the indentation part of the code block line.
63
+ */
64
+ export declare function getLeadingWhiteSpaces(textNode: Text): string;
65
+ /**
66
+ * For plain text containing the code (a snippet), it returns a document fragment containing
67
+ * view text nodes separated by `<br>` elements (in place of new line characters "\n"), for instance:
68
+ *
69
+ * Input:
70
+ *
71
+ * ```ts
72
+ * "foo()\n
73
+ * bar()"
74
+ * ```
75
+ *
76
+ * Output:
77
+ *
78
+ * ```html
79
+ * <DocumentFragment>
80
+ * "foo()"
81
+ * <br/>
82
+ * "bar()"
83
+ * </DocumentFragment>
84
+ * ```
85
+ *
86
+ * @param text The raw code text to be converted.
87
+ */
88
+ export declare function rawSnippetTextToViewDocumentFragment(writer: UpcastWriter, text: string): ViewDocumentFragment;
89
+ /**
90
+ * Returns an array of all model positions within the selection that represent code block lines.
91
+ *
92
+ * If the selection is collapsed, it returns the exact selection anchor position:
93
+ *
94
+ * ```html
95
+ * <codeBlock>[]foo</codeBlock> -> <codeBlock>^foo</codeBlock>
96
+ * <codeBlock>foo[]bar</codeBlock> -> <codeBlock>foo^bar</codeBlock>
97
+ * ```
98
+ *
99
+ * Otherwise, it returns positions **before** each text node belonging to all code blocks contained by the selection:
100
+ *
101
+ * ```html
102
+ * <codeBlock> <codeBlock>
103
+ * foo[bar ^foobar
104
+ * <softBreak></softBreak> -> <softBreak></softBreak>
105
+ * baz]qux ^bazqux
106
+ * </codeBlock> </codeBlock>
107
+ * ```
108
+ *
109
+ * It also works across other non–code blocks:
110
+ *
111
+ * ```html
112
+ * <codeBlock> <codeBlock>
113
+ * foo[bar ^foobar
114
+ * </codeBlock> </codeBlock>
115
+ * <paragraph>text</paragraph> -> <paragraph>text</paragraph>
116
+ * <codeBlock> <codeBlock>
117
+ * baz]qux ^bazqux
118
+ * </codeBlock> </codeBlock>
119
+ * ```
120
+ *
121
+ * **Note:** The positions are in reverse order so they do not get outdated when iterating over them and
122
+ * the writer inserts or removes elements at the same time.
123
+ *
124
+ * **Note:** The position is located after the leading white spaces in the text node.
125
+ */
126
+ export declare function getIndentOutdentPositions(model: Model): Array<Position>;
127
+ /**
128
+ * Checks if any of the blocks within the model selection is a code block.
129
+ */
130
+ export declare function isModelSelectionInCodeBlock(selection: DocumentSelection): boolean;
131
+ /**
132
+ * Checks if an {@link module:engine/model/element~Element Element} can become a code block.
133
+ *
134
+ * @param schema Model's schema.
135
+ * @param element The element to be checked.
136
+ * @returns Check result.
137
+ */
138
+ export declare function canBeCodeBlock(schema: Schema, element: Element): boolean;
package/src/utils.js CHANGED
@@ -6,7 +6,7 @@ import { first } from 'ckeditor5/src/utils';
6
6
  /**
7
7
  * Returns code block languages as defined in `config.codeBlock.languages` but processed:
8
8
  *
9
- * * To consider the editor localization, i.e. to display {@link module:code-block/codeblock~CodeBlockLanguageDefinition}
9
+ * * To consider the editor localization, i.e. to display {@link module:code-block/codeblockconfig~CodeBlockLanguageDefinition}
10
10
  * in the correct language. There is no way to use {@link module:utils/locale~Locale#t} when the user
11
11
  * configuration is defined because the editor does not exist yet.
12
12
  * * To make sure each definition has a CSS class associated with it even if not specified
@@ -30,12 +30,14 @@ export function getNormalizedAndLocalizedLanguageDefinitions(editor) {
30
30
  *
31
31
  * For:
32
32
  *
33
+ * ```ts
33
34
  * const definitions = {
34
35
  * { language: 'php', class: 'language-php', label: 'PHP' },
35
36
  * { language: 'javascript', class: 'js', label: 'JavaScript' },
36
37
  * };
37
38
  *
38
39
  * getPropertyAssociation( definitions, 'class', 'language' );
40
+ * ```
39
41
  *
40
42
  * returns:
41
43
  *