@ckeditor/ckeditor5-code-block 0.0.0-nightly-next-20260110.0 → 0.0.0-nightly-20260111.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.
Files changed (98) hide show
  1. package/build/code-block.js +5 -0
  2. package/build/translations/af.js +1 -0
  3. package/build/translations/ar.js +1 -0
  4. package/build/translations/ast.js +1 -0
  5. package/build/translations/az.js +1 -0
  6. package/build/translations/be.js +1 -0
  7. package/build/translations/bg.js +1 -0
  8. package/build/translations/bn.js +1 -0
  9. package/build/translations/bs.js +1 -0
  10. package/build/translations/ca.js +1 -0
  11. package/build/translations/cs.js +1 -0
  12. package/build/translations/da.js +1 -0
  13. package/build/translations/de-ch.js +1 -0
  14. package/build/translations/de.js +1 -0
  15. package/build/translations/el.js +1 -0
  16. package/build/translations/en-au.js +1 -0
  17. package/build/translations/en-gb.js +1 -0
  18. package/build/translations/eo.js +1 -0
  19. package/build/translations/es-co.js +1 -0
  20. package/build/translations/es.js +1 -0
  21. package/build/translations/et.js +1 -0
  22. package/build/translations/eu.js +1 -0
  23. package/build/translations/fa.js +1 -0
  24. package/build/translations/fi.js +1 -0
  25. package/build/translations/fr.js +1 -0
  26. package/build/translations/gl.js +1 -0
  27. package/build/translations/gu.js +1 -0
  28. package/build/translations/he.js +1 -0
  29. package/build/translations/hi.js +1 -0
  30. package/build/translations/hr.js +1 -0
  31. package/build/translations/hu.js +1 -0
  32. package/build/translations/hy.js +1 -0
  33. package/build/translations/id.js +1 -0
  34. package/build/translations/it.js +1 -0
  35. package/build/translations/ja.js +1 -0
  36. package/build/translations/jv.js +1 -0
  37. package/build/translations/kk.js +1 -0
  38. package/build/translations/km.js +1 -0
  39. package/build/translations/kn.js +1 -0
  40. package/build/translations/ko.js +1 -0
  41. package/build/translations/ku.js +1 -0
  42. package/build/translations/lt.js +1 -0
  43. package/build/translations/lv.js +1 -0
  44. package/build/translations/ms.js +1 -0
  45. package/build/translations/nb.js +1 -0
  46. package/build/translations/ne.js +1 -0
  47. package/build/translations/nl.js +1 -0
  48. package/build/translations/no.js +1 -0
  49. package/build/translations/oc.js +1 -0
  50. package/build/translations/pl.js +1 -0
  51. package/build/translations/pt-br.js +1 -0
  52. package/build/translations/pt.js +1 -0
  53. package/build/translations/ro.js +1 -0
  54. package/build/translations/ru.js +1 -0
  55. package/build/translations/si.js +1 -0
  56. package/build/translations/sk.js +1 -0
  57. package/build/translations/sl.js +1 -0
  58. package/build/translations/sq.js +1 -0
  59. package/build/translations/sr-latn.js +1 -0
  60. package/build/translations/sr.js +1 -0
  61. package/build/translations/sv.js +1 -0
  62. package/build/translations/th.js +1 -0
  63. package/build/translations/ti.js +1 -0
  64. package/build/translations/tk.js +1 -0
  65. package/build/translations/tr.js +1 -0
  66. package/build/translations/tt.js +1 -0
  67. package/build/translations/ug.js +1 -0
  68. package/build/translations/uk.js +1 -0
  69. package/build/translations/ur.js +1 -0
  70. package/build/translations/uz.js +1 -0
  71. package/build/translations/vi.js +1 -0
  72. package/build/translations/zh-cn.js +1 -0
  73. package/build/translations/zh.js +1 -0
  74. package/ckeditor5-metadata.json +1 -1
  75. package/dist/index.js.map +1 -1
  76. package/package.json +35 -24
  77. package/{dist → src}/augmentation.d.ts +0 -4
  78. package/src/augmentation.js +5 -0
  79. package/{dist → src}/codeblock.d.ts +1 -5
  80. package/src/codeblock.js +39 -0
  81. package/{dist → src}/codeblockcommand.d.ts +1 -5
  82. package/src/codeblockcommand.js +142 -0
  83. package/{dist → src}/codeblockconfig.d.ts +0 -4
  84. package/src/codeblockconfig.js +5 -0
  85. package/{dist → src}/codeblockediting.d.ts +2 -6
  86. package/src/codeblockediting.js +430 -0
  87. package/{dist → src}/codeblockui.d.ts +1 -5
  88. package/src/codeblockui.js +134 -0
  89. package/{dist → src}/converters.d.ts +2 -6
  90. package/src/converters.js +285 -0
  91. package/{dist → src}/indentcodeblockcommand.d.ts +1 -5
  92. package/src/indentcodeblockcommand.js +82 -0
  93. package/{dist → src}/index.d.ts +0 -4
  94. package/src/index.js +16 -0
  95. package/{dist → src}/outdentcodeblockcommand.d.ts +1 -5
  96. package/src/outdentcodeblockcommand.js +137 -0
  97. package/{dist → src}/utils.d.ts +3 -7
  98. package/src/utils.js +296 -0
package/package.json CHANGED
@@ -1,53 +1,64 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-code-block",
3
- "version": "0.0.0-nightly-next-20260110.0",
3
+ "version": "0.0.0-nightly-20260111.0",
4
4
  "description": "Code block feature for CKEditor 5.",
5
- "license": "SEE LICENSE IN LICENSE.md",
6
- "author": "CKSource (http://cksource.com/)",
7
- "homepage": "https://ckeditor.com/ckeditor-5",
8
- "bugs": "https://github.com/ckeditor/ckeditor5/issues",
9
- "repository": {
10
- "type": "git",
11
- "url": "https://github.com/ckeditor/ckeditor5.git",
12
- "directory": "packages/ckeditor5-code-block"
13
- },
14
5
  "keywords": [
15
6
  "ckeditor",
16
7
  "ckeditor5",
17
8
  "ckeditor 5",
18
9
  "ckeditor5-feature",
19
- "ckeditor5-plugin"
10
+ "ckeditor5-plugin",
11
+ "ckeditor5-dll"
20
12
  ],
21
13
  "type": "module",
22
- "main": "dist/index.js",
14
+ "main": "src/index.js",
23
15
  "dependencies": {
24
- "@ckeditor/ckeditor5-core": "0.0.0-nightly-next-20260110.0",
25
- "@ckeditor/ckeditor5-clipboard": "0.0.0-nightly-next-20260110.0",
26
- "@ckeditor/ckeditor5-engine": "0.0.0-nightly-next-20260110.0",
27
- "@ckeditor/ckeditor5-enter": "0.0.0-nightly-next-20260110.0",
28
- "@ckeditor/ckeditor5-icons": "0.0.0-nightly-next-20260110.0",
29
- "@ckeditor/ckeditor5-ui": "0.0.0-nightly-next-20260110.0",
30
- "@ckeditor/ckeditor5-utils": "0.0.0-nightly-next-20260110.0"
16
+ "@ckeditor/ckeditor5-core": "0.0.0-nightly-20260111.0",
17
+ "@ckeditor/ckeditor5-clipboard": "0.0.0-nightly-20260111.0",
18
+ "@ckeditor/ckeditor5-engine": "0.0.0-nightly-20260111.0",
19
+ "@ckeditor/ckeditor5-enter": "0.0.0-nightly-20260111.0",
20
+ "@ckeditor/ckeditor5-icons": "0.0.0-nightly-20260111.0",
21
+ "@ckeditor/ckeditor5-ui": "0.0.0-nightly-20260111.0",
22
+ "@ckeditor/ckeditor5-utils": "0.0.0-nightly-20260111.0",
23
+ "ckeditor5": "0.0.0-nightly-20260111.0"
24
+ },
25
+ "author": "CKSource (http://cksource.com/)",
26
+ "license": "SEE LICENSE IN LICENSE.md",
27
+ "homepage": "https://ckeditor.com/ckeditor-5",
28
+ "bugs": "https://github.com/ckeditor/ckeditor5/issues",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "https://github.com/ckeditor/ckeditor5.git",
32
+ "directory": "packages/ckeditor5-code-block"
31
33
  },
32
34
  "files": [
33
35
  "dist",
34
36
  "lang",
37
+ "src/**/*.js",
38
+ "src/**/*.d.ts",
35
39
  "theme",
40
+ "build",
36
41
  "ckeditor5-metadata.json",
37
42
  "CHANGELOG.md"
38
43
  ],
39
- "types": "dist/index.d.ts",
44
+ "types": "src/index.d.ts",
40
45
  "exports": {
41
46
  ".": {
42
- "types": "./dist/index.d.ts",
43
- "import": "./dist/index.js",
44
- "default": "./dist/index.js"
47
+ "types": "./src/index.d.ts",
48
+ "import": "./src/index.js",
49
+ "default": "./src/index.js"
45
50
  },
46
51
  "./dist/*": {
47
- "types": "./dist/index.d.ts",
52
+ "types": "./src/index.d.ts",
48
53
  "import": "./dist/*",
49
54
  "default": "./dist/*"
50
55
  },
56
+ "./src/*": {
57
+ "types": "./src/*.d.ts",
58
+ "import": "./src/*",
59
+ "default": "./src/*"
60
+ },
61
+ "./build/*": "./build/*",
51
62
  "./lang/*": "./lang/*",
52
63
  "./theme/*": "./theme/*",
53
64
  "./ckeditor5-metadata.json": "./ckeditor5-metadata.json",
@@ -1,7 +1,3 @@
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
1
  /**
6
2
  * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
7
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
@@ -0,0 +1,5 @@
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
+ export {};
@@ -1,7 +1,3 @@
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
1
  /**
6
2
  * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
7
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
@@ -9,7 +5,7 @@
9
5
  /**
10
6
  * @module code-block/codeblock
11
7
  */
12
- import { Plugin } from '@ckeditor/ckeditor5-core';
8
+ import { Plugin } from 'ckeditor5/src/core.js';
13
9
  import { CodeBlockEditing } from './codeblockediting.js';
14
10
  import { CodeBlockUI } from './codeblockui.js';
15
11
  /**
@@ -0,0 +1,39 @@
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 code-block/codeblock
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core.js';
9
+ import { CodeBlockEditing } from './codeblockediting.js';
10
+ import { CodeBlockUI } from './codeblockui.js';
11
+ /**
12
+ * The code block plugin.
13
+ *
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.
16
+ *
17
+ * This is a "glue" plugin that loads the {@link module:code-block/codeblockediting~CodeBlockEditing code block editing feature}
18
+ * and the {@link module:code-block/codeblockui~CodeBlockUI code block UI feature}.
19
+ */
20
+ export class CodeBlock extends Plugin {
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ static get requires() {
25
+ return [CodeBlockEditing, CodeBlockUI];
26
+ }
27
+ /**
28
+ * @inheritDoc
29
+ */
30
+ static get pluginName() {
31
+ return 'CodeBlock';
32
+ }
33
+ /**
34
+ * @inheritDoc
35
+ */
36
+ static get isOfficialPlugin() {
37
+ return true;
38
+ }
39
+ }
@@ -2,11 +2,7 @@
2
2
  * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
4
  */
5
- /**
6
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
7
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
8
- */
9
- import { Command, type Editor } from '@ckeditor/ckeditor5-core';
5
+ import { Command, type Editor } from 'ckeditor5/src/core.js';
10
6
  /**
11
7
  * The code block command plugin.
12
8
  */
@@ -0,0 +1,142 @@
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
+ import { Command } from 'ckeditor5/src/core.js';
6
+ import { first } from 'ckeditor5/src/utils.js';
7
+ import { getNormalizedAndLocalizedLanguageDefinitions, canBeCodeBlock } from './utils.js';
8
+ /**
9
+ * The code block command plugin.
10
+ */
11
+ export class CodeBlockCommand extends Command {
12
+ /**
13
+ * Contains the last used language.
14
+ */
15
+ _lastLanguage;
16
+ /**
17
+ * @inheritDoc
18
+ */
19
+ constructor(editor) {
20
+ super(editor);
21
+ this._lastLanguage = null;
22
+ }
23
+ /**
24
+ * @inheritDoc
25
+ */
26
+ refresh() {
27
+ this.value = this._getValue();
28
+ this.isEnabled = this._checkEnabled();
29
+ }
30
+ /**
31
+ * Executes the command. When the command {@link #value is on}, all topmost code blocks within
32
+ * the selection will be removed. If it is off, all selected blocks will be flattened and
33
+ * wrapped by a code block.
34
+ *
35
+ * @fires execute
36
+ * @param options Command options.
37
+ * @param options.language The code block language.
38
+ * @param options.forceValue If set, it will force the command behavior. If `true`, the command will apply a code block,
39
+ * otherwise the command will remove the code block. If not set, the command will act basing on its current value.
40
+ * @param options.usePreviousLanguageChoice If set on `true` and the `options.language` is not specified, the command
41
+ * will apply the previous language (if the command was already executed) when inserting the `codeBlock` element.
42
+ */
43
+ execute(options = {}) {
44
+ const editor = this.editor;
45
+ const model = editor.model;
46
+ const selection = model.document.selection;
47
+ const normalizedLanguagesDefs = getNormalizedAndLocalizedLanguageDefinitions(editor);
48
+ const firstLanguageInConfig = normalizedLanguagesDefs[0];
49
+ const blocks = Array.from(selection.getSelectedBlocks());
50
+ const value = options.forceValue == undefined ? !this.value : options.forceValue;
51
+ const language = getLanguage(options, this._lastLanguage, firstLanguageInConfig.language);
52
+ model.change(writer => {
53
+ if (value) {
54
+ this._applyCodeBlock(writer, blocks, language);
55
+ }
56
+ else {
57
+ this._removeCodeBlock(writer, blocks);
58
+ }
59
+ });
60
+ }
61
+ /**
62
+ * Checks the command's {@link #value}.
63
+ *
64
+ * @returns The current value.
65
+ */
66
+ _getValue() {
67
+ const selection = this.editor.model.document.selection;
68
+ const firstBlock = first(selection.getSelectedBlocks());
69
+ const isCodeBlock = !!firstBlock?.is('element', 'codeBlock');
70
+ return isCodeBlock ? firstBlock.getAttribute('language') : false;
71
+ }
72
+ /**
73
+ * Checks whether the command can be enabled in the current context.
74
+ *
75
+ * @returns Whether the command should be enabled.
76
+ */
77
+ _checkEnabled() {
78
+ if (this.value) {
79
+ return true;
80
+ }
81
+ const selection = this.editor.model.document.selection;
82
+ const schema = this.editor.model.schema;
83
+ const firstBlock = first(selection.getSelectedBlocks());
84
+ if (!firstBlock) {
85
+ return false;
86
+ }
87
+ return canBeCodeBlock(schema, firstBlock);
88
+ }
89
+ _applyCodeBlock(writer, blocks, language) {
90
+ this._lastLanguage = language;
91
+ const schema = this.editor.model.schema;
92
+ const allowedBlocks = blocks.filter(block => canBeCodeBlock(schema, block));
93
+ for (const block of allowedBlocks) {
94
+ writer.rename(block, 'codeBlock');
95
+ writer.setAttribute('language', language, block);
96
+ schema.removeDisallowedAttributes([block], writer);
97
+ // Remove children of the `codeBlock` element that are not allowed. See #9567.
98
+ Array.from(block.getChildren())
99
+ .filter(child => !schema.checkChild(block, child))
100
+ .forEach(child => writer.remove(child));
101
+ }
102
+ allowedBlocks.reverse().forEach((currentBlock, i) => {
103
+ const nextBlock = allowedBlocks[i + 1];
104
+ if (currentBlock.previousSibling === nextBlock) {
105
+ writer.appendElement('softBreak', nextBlock);
106
+ writer.merge(writer.createPositionBefore(currentBlock));
107
+ }
108
+ });
109
+ }
110
+ _removeCodeBlock(writer, blocks) {
111
+ const codeBlocks = blocks.filter(block => block.is('element', 'codeBlock'));
112
+ for (const block of codeBlocks) {
113
+ const range = writer.createRangeOn(block);
114
+ for (const item of Array.from(range.getItems()).reverse()) {
115
+ if (item.is('element', 'softBreak') && item.parent.is('element', 'codeBlock')) {
116
+ const { position } = writer.split(writer.createPositionBefore(item));
117
+ const elementAfter = position.nodeAfter;
118
+ writer.rename(elementAfter, 'paragraph');
119
+ writer.removeAttribute('language', elementAfter);
120
+ writer.remove(item);
121
+ }
122
+ }
123
+ writer.rename(block, 'paragraph');
124
+ writer.removeAttribute('language', block);
125
+ }
126
+ }
127
+ }
128
+ /**
129
+ * Picks the language for the new code block. If any language is passed as an option,
130
+ * it will be returned. Else, if option usePreviousLanguageChoice is true and some
131
+ * code block was already created (lastLanguage is not null) then previously used
132
+ * language will be returned. If not, it will return default language.
133
+ */
134
+ function getLanguage(options, lastLanguage, defaultLanguage) {
135
+ if (options.language) {
136
+ return options.language;
137
+ }
138
+ if (options.usePreviousLanguageChoice && lastLanguage) {
139
+ return lastLanguage;
140
+ }
141
+ return defaultLanguage;
142
+ }
@@ -1,7 +1,3 @@
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
1
  /**
6
2
  * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
7
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
@@ -0,0 +1,5 @@
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
+ export {};
@@ -1,7 +1,3 @@
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
1
  /**
6
2
  * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
7
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
@@ -9,8 +5,8 @@
9
5
  /**
10
6
  * @module code-block/codeblockediting
11
7
  */
12
- import { Plugin, type Editor } from '@ckeditor/ckeditor5-core';
13
- import { ShiftEnter } from '@ckeditor/ckeditor5-enter';
8
+ import { Plugin, type Editor } from 'ckeditor5/src/core.js';
9
+ import { ShiftEnter } from 'ckeditor5/src/enter.js';
14
10
  /**
15
11
  * The editing part of the code block feature.
16
12
  *