@ckeditor/ckeditor5-code-block 41.3.0 → 41.4.0-alpha.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 (136) hide show
  1. package/build/code-block.js +1 -1
  2. package/dist/index-content.css +22 -0
  3. package/dist/index-editor.css +11 -0
  4. package/dist/index.css +46 -0
  5. package/dist/index.css.map +1 -0
  6. package/dist/index.js +1348 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/translations/af.d.ts +8 -0
  9. package/dist/translations/af.js +5 -0
  10. package/dist/translations/ar.d.ts +8 -0
  11. package/dist/translations/ar.js +5 -0
  12. package/dist/translations/az.d.ts +8 -0
  13. package/dist/translations/az.js +5 -0
  14. package/dist/translations/bg.d.ts +8 -0
  15. package/dist/translations/bg.js +5 -0
  16. package/dist/translations/bn.d.ts +8 -0
  17. package/dist/translations/bn.js +5 -0
  18. package/dist/translations/bs.d.ts +8 -0
  19. package/dist/translations/bs.js +5 -0
  20. package/dist/translations/ca.d.ts +8 -0
  21. package/dist/translations/ca.js +5 -0
  22. package/dist/translations/cs.d.ts +8 -0
  23. package/dist/translations/cs.js +5 -0
  24. package/dist/translations/da.d.ts +8 -0
  25. package/dist/translations/da.js +5 -0
  26. package/dist/translations/de-ch.d.ts +8 -0
  27. package/dist/translations/de-ch.js +5 -0
  28. package/dist/translations/de.d.ts +8 -0
  29. package/dist/translations/de.js +5 -0
  30. package/dist/translations/el.d.ts +8 -0
  31. package/dist/translations/el.js +5 -0
  32. package/dist/translations/en-au.d.ts +8 -0
  33. package/dist/translations/en-au.js +5 -0
  34. package/dist/translations/en.d.ts +8 -0
  35. package/dist/translations/en.js +5 -0
  36. package/dist/translations/es-co.d.ts +8 -0
  37. package/dist/translations/es-co.js +5 -0
  38. package/dist/translations/es.d.ts +8 -0
  39. package/dist/translations/es.js +5 -0
  40. package/dist/translations/et.d.ts +8 -0
  41. package/dist/translations/et.js +5 -0
  42. package/dist/translations/fa.d.ts +8 -0
  43. package/dist/translations/fa.js +5 -0
  44. package/dist/translations/fi.d.ts +8 -0
  45. package/dist/translations/fi.js +5 -0
  46. package/dist/translations/fr.d.ts +8 -0
  47. package/dist/translations/fr.js +5 -0
  48. package/dist/translations/gl.d.ts +8 -0
  49. package/dist/translations/gl.js +5 -0
  50. package/dist/translations/he.d.ts +8 -0
  51. package/dist/translations/he.js +5 -0
  52. package/dist/translations/hi.d.ts +8 -0
  53. package/dist/translations/hi.js +5 -0
  54. package/dist/translations/hr.d.ts +8 -0
  55. package/dist/translations/hr.js +5 -0
  56. package/dist/translations/hu.d.ts +8 -0
  57. package/dist/translations/hu.js +5 -0
  58. package/dist/translations/id.d.ts +8 -0
  59. package/dist/translations/id.js +5 -0
  60. package/dist/translations/it.d.ts +8 -0
  61. package/dist/translations/it.js +5 -0
  62. package/dist/translations/ja.d.ts +8 -0
  63. package/dist/translations/ja.js +5 -0
  64. package/dist/translations/jv.d.ts +8 -0
  65. package/dist/translations/jv.js +5 -0
  66. package/dist/translations/ko.d.ts +8 -0
  67. package/dist/translations/ko.js +5 -0
  68. package/dist/translations/ku.d.ts +8 -0
  69. package/dist/translations/ku.js +5 -0
  70. package/dist/translations/lt.d.ts +8 -0
  71. package/dist/translations/lt.js +5 -0
  72. package/dist/translations/lv.d.ts +8 -0
  73. package/dist/translations/lv.js +5 -0
  74. package/dist/translations/ms.d.ts +8 -0
  75. package/dist/translations/ms.js +5 -0
  76. package/dist/translations/nl.d.ts +8 -0
  77. package/dist/translations/nl.js +5 -0
  78. package/dist/translations/no.d.ts +8 -0
  79. package/dist/translations/no.js +5 -0
  80. package/dist/translations/pl.d.ts +8 -0
  81. package/dist/translations/pl.js +5 -0
  82. package/dist/translations/pt-br.d.ts +8 -0
  83. package/dist/translations/pt-br.js +5 -0
  84. package/dist/translations/pt.d.ts +8 -0
  85. package/dist/translations/pt.js +5 -0
  86. package/dist/translations/ro.d.ts +8 -0
  87. package/dist/translations/ro.js +5 -0
  88. package/dist/translations/ru.d.ts +8 -0
  89. package/dist/translations/ru.js +5 -0
  90. package/dist/translations/sk.d.ts +8 -0
  91. package/dist/translations/sk.js +5 -0
  92. package/dist/translations/sq.d.ts +8 -0
  93. package/dist/translations/sq.js +5 -0
  94. package/dist/translations/sr-latn.d.ts +8 -0
  95. package/dist/translations/sr-latn.js +5 -0
  96. package/dist/translations/sr.d.ts +8 -0
  97. package/dist/translations/sr.js +5 -0
  98. package/dist/translations/sv.d.ts +8 -0
  99. package/dist/translations/sv.js +5 -0
  100. package/dist/translations/th.d.ts +8 -0
  101. package/dist/translations/th.js +5 -0
  102. package/dist/translations/tk.d.ts +8 -0
  103. package/dist/translations/tk.js +5 -0
  104. package/dist/translations/tr.d.ts +8 -0
  105. package/dist/translations/tr.js +5 -0
  106. package/dist/translations/ug.d.ts +8 -0
  107. package/dist/translations/ug.js +5 -0
  108. package/dist/translations/uk.d.ts +8 -0
  109. package/dist/translations/uk.js +5 -0
  110. package/dist/translations/ur.d.ts +8 -0
  111. package/dist/translations/ur.js +5 -0
  112. package/dist/translations/uz.d.ts +8 -0
  113. package/dist/translations/uz.js +5 -0
  114. package/dist/translations/vi.d.ts +8 -0
  115. package/dist/translations/vi.js +5 -0
  116. package/dist/translations/zh-cn.d.ts +8 -0
  117. package/dist/translations/zh-cn.js +5 -0
  118. package/dist/translations/zh.d.ts +8 -0
  119. package/dist/translations/zh.js +5 -0
  120. package/dist/types/augmentation.d.ts +29 -0
  121. package/dist/types/codeblock.d.ts +33 -0
  122. package/dist/types/codeblockcommand.d.ts +64 -0
  123. package/dist/types/codeblockconfig.d.ts +150 -0
  124. package/dist/types/codeblockediting.d.ts +44 -0
  125. package/dist/types/codeblockui.d.ts +33 -0
  126. package/dist/types/converters.d.ts +130 -0
  127. package/dist/types/indentcodeblockcommand.d.ts +37 -0
  128. package/dist/types/index.d.ts +19 -0
  129. package/dist/types/outdentcodeblockcommand.d.ts +37 -0
  130. package/dist/types/utils.d.ts +147 -0
  131. package/lang/contexts.json +4 -0
  132. package/package.json +4 -2
  133. package/src/codeblockediting.d.ts +7 -3
  134. package/src/codeblockediting.js +26 -4
  135. package/src/utils.d.ts +5 -0
  136. package/src/utils.js +18 -0
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ import { Plugin, type Editor } from 'ckeditor5/src/core.js';
10
+ import { ShiftEnter } from 'ckeditor5/src/enter.js';
11
+ /**
12
+ * The editing part of the code block feature.
13
+ *
14
+ * Introduces the `'codeBlock'` command and the `'codeBlock'` model element.
15
+ */
16
+ export default class CodeBlockEditing extends Plugin {
17
+ /**
18
+ * @inheritDoc
19
+ */
20
+ static get pluginName(): "CodeBlockEditing";
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ static get requires(): readonly [typeof ShiftEnter];
25
+ /**
26
+ * @inheritDoc
27
+ */
28
+ constructor(editor: Editor);
29
+ /**
30
+ * @inheritDoc
31
+ */
32
+ init(): void;
33
+ /**
34
+ * @inheritDoc
35
+ */
36
+ afterInit(): void;
37
+ /**
38
+ * Observe when user enters or leaves code block and set proper aria value in global live announcer.
39
+ * This allows screen readers to indicate when the user has entered and left the specified code block.
40
+ *
41
+ * @internal
42
+ */
43
+ private _initAriaAnnouncements;
44
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module code-block/codeblockui
11
+ */
12
+ import { Plugin } from 'ckeditor5/src/core.js';
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(): "CodeBlockUI";
24
+ /**
25
+ * @inheritDoc
26
+ */
27
+ init(): void;
28
+ /**
29
+ * A helper returning a collection of the `codeBlock` dropdown items representing languages
30
+ * available for the user to choose from.
31
+ */
32
+ private _getLanguageListItemDefinitions;
33
+ }
@@ -0,0 +1,130 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module code-block/converters
11
+ */
12
+ import type { GetCallback } from 'ckeditor5/src/utils.js';
13
+ import type { DowncastInsertEvent, Model, UpcastElementEvent, UpcastTextEvent, EditingView } from 'ckeditor5/src/engine.js';
14
+ import type { CodeBlockLanguageDefinition } from './codeblockconfig.js';
15
+ /**
16
+ * A model-to-view (both editing and data) converter for the `codeBlock` element.
17
+ *
18
+ * Sample input:
19
+ *
20
+ * ```html
21
+ * <codeBlock language="javascript">foo();<softBreak></softBreak>bar();</codeBlock>
22
+ * ```
23
+ *
24
+ * Sample output (editing):
25
+ *
26
+ * ```html
27
+ * <pre data-language="JavaScript"><code class="language-javascript">foo();<br />bar();</code></pre>
28
+ * ```
29
+ *
30
+ * Sample output (data, see {@link module:code-block/converters~modelToDataViewSoftBreakInsertion}):
31
+ *
32
+ * ```html
33
+ * <pre><code class="language-javascript">foo();\nbar();</code></pre>
34
+ * ```
35
+ *
36
+ * @param languageDefs The normalized language configuration passed to the feature.
37
+ * @param useLabels When `true`, the `<pre>` element will get a `data-language` attribute with a
38
+ * human–readable label of the language. Used only in the editing.
39
+ * @returns Returns a conversion callback.
40
+ */
41
+ export declare function modelToViewCodeBlockInsertion(model: Model, languageDefs: Array<CodeBlockLanguageDefinition>, useLabels?: boolean): GetCallback<DowncastInsertEvent>;
42
+ /**
43
+ * A model-to-data view converter for the new line (`softBreak`) separator.
44
+ *
45
+ * Sample input:
46
+ *
47
+ * ```html
48
+ * <codeBlock ...>foo();<softBreak></softBreak>bar();</codeBlock>
49
+ * ```
50
+ *
51
+ * Sample output:
52
+ *
53
+ * ```html
54
+ * <pre><code ...>foo();\nbar();</code></pre>
55
+ * ```
56
+ *
57
+ * @returns Returns a conversion callback.
58
+ */
59
+ export declare function modelToDataViewSoftBreakInsertion(model: Model): GetCallback<DowncastInsertEvent>;
60
+ /**
61
+ * A view-to-model converter for `<pre>` with the `<code>` HTML.
62
+ *
63
+ * Sample input:
64
+ *
65
+ * ```html
66
+ * <pre><code class="language-javascript">foo();bar();</code></pre>
67
+ * ```
68
+ *
69
+ * Sample output:
70
+ *
71
+ * ```html
72
+ * <codeBlock language="javascript">foo();bar();</codeBlock>
73
+ * ```
74
+ *
75
+ * @param languageDefs The normalized language configuration passed to the feature.
76
+ * @returns Returns a conversion callback.
77
+ */
78
+ export declare function dataViewToModelCodeBlockInsertion(editingView: EditingView, languageDefs: Array<CodeBlockLanguageDefinition>): GetCallback<UpcastElementEvent>;
79
+ /**
80
+ * A view-to-model converter for new line characters in `<pre>`.
81
+ *
82
+ * Sample input:
83
+ *
84
+ * ```html
85
+ * <pre><code class="language-javascript">foo();\nbar();</code></pre>
86
+ * ```
87
+ *
88
+ * Sample output:
89
+ *
90
+ * ```html
91
+ * <codeBlock language="javascript">foo();<softBreak></softBreak>bar();</codeBlock>
92
+ * ```
93
+ *
94
+ * @returns {Function} Returns a conversion callback.
95
+ */
96
+ export declare function dataViewToModelTextNewlinesInsertion(): GetCallback<UpcastTextEvent>;
97
+ /**
98
+ * A view-to-model converter that handles orphan text nodes (white spaces, new lines, etc.)
99
+ * that surround `<code>` inside `<pre>`.
100
+ *
101
+ * Sample input:
102
+ *
103
+ * ```html
104
+ * // White spaces
105
+ * <pre> <code>foo()</code> </pre>
106
+ *
107
+ * // White spaces
108
+ * <pre> <code>foo()</code> </pre>
109
+ *
110
+ * // White spaces
111
+ * <pre> <code>foo()</code> </pre>
112
+ *
113
+ * // New lines
114
+ * <pre>
115
+ * <code>foo()</code>
116
+ * </pre>
117
+ *
118
+ * // Redundant text
119
+ * <pre>ABC<code>foo()</code>DEF</pre>
120
+ * ```
121
+ *
122
+ * Unified output for each case:
123
+ *
124
+ * ```html
125
+ * <codeBlock language="plaintext">foo()</codeBlock>
126
+ * ```
127
+ *
128
+ * @returns Returns a conversion callback.
129
+ */
130
+ export declare function dataViewToModelOrphanNodeConsumer(): GetCallback<UpcastElementEvent>;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module code-block/indentcodeblockcommand
11
+ */
12
+ import { Command, type Editor } from 'ckeditor5/src/core.js';
13
+ /**
14
+ * The code block indentation increase command plugin.
15
+ */
16
+ export default class IndentCodeBlockCommand extends Command {
17
+ /**
18
+ * A sequence of characters added to the line when the command is executed.
19
+ */
20
+ private _indentSequence;
21
+ constructor(editor: Editor);
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ refresh(): void;
26
+ /**
27
+ * Executes the command. When the command {@link #isEnabled is enabled}, the indentation of the
28
+ * code lines in the selection will be increased.
29
+ *
30
+ * @fires execute
31
+ */
32
+ execute(): void;
33
+ /**
34
+ * Checks whether the command can be enabled in the current context.
35
+ */
36
+ private _checkEnabled;
37
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module code-block
11
+ */
12
+ export { default as CodeBlock } from './codeblock.js';
13
+ export { default as CodeBlockEditing } from './codeblockediting.js';
14
+ export { default as CodeBlockUI } from './codeblockui.js';
15
+ export type { default as CodeBlockCommand } from './codeblockcommand.js';
16
+ export type { default as IndentCodeBlockCommand } from './indentcodeblockcommand.js';
17
+ export type { default as OutdentCodeBlockCommand } from './outdentcodeblockcommand.js';
18
+ export type { CodeBlockConfig } from './codeblockconfig.js';
19
+ import './augmentation.js';
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ import { Command, type Editor } from 'ckeditor5/src/core.js';
10
+ /**
11
+ * The code block indentation decrease command plugin.
12
+ */
13
+ export default class OutdentCodeBlockCommand extends Command {
14
+ /**
15
+ * A sequence of characters removed from the line when the command is executed.
16
+ */
17
+ private readonly _indentSequence;
18
+ constructor(editor: Editor);
19
+ /**
20
+ * @inheritDoc
21
+ */
22
+ refresh(): void;
23
+ /**
24
+ * Executes the command. When the command {@link #isEnabled is enabled}, the indentation of the
25
+ * code lines in the selection will be decreased.
26
+ *
27
+ * @fires execute
28
+ */
29
+ execute(): void;
30
+ /**
31
+ * Checks whether the command can be enabled in the current context.
32
+ *
33
+ * @private
34
+ * @returns {Boolean} Whether the command should be enabled.
35
+ */
36
+ private _checkEnabled;
37
+ }
@@ -0,0 +1,147 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module code-block/utils
11
+ */
12
+ import type { Editor } from 'ckeditor5/src/core.js';
13
+ import type { CodeBlockLanguageDefinition } from './codeblockconfig.js';
14
+ import type { DocumentSelection, Element, Model, Position, Schema, Text, UpcastWriter, ViewDocumentFragment } from 'ckeditor5/src/engine.js';
15
+ import { type LocaleTranslate } from 'ckeditor5/src/utils.js';
16
+ /**
17
+ * Returns code block languages as defined in `config.codeBlock.languages` but processed:
18
+ *
19
+ * * To consider the editor localization, i.e. to display {@link module:code-block/codeblockconfig~CodeBlockLanguageDefinition}
20
+ * in the correct language. There is no way to use {@link module:utils/locale~Locale#t} when the user
21
+ * configuration is defined because the editor does not exist yet.
22
+ * * To make sure each definition has a CSS class associated with it even if not specified
23
+ * in the original configuration.
24
+ */
25
+ export declare function getNormalizedAndLocalizedLanguageDefinitions(editor: Editor): Array<CodeBlockLanguageDefinition>;
26
+ /**
27
+ * Returns an object associating certain language definition properties with others. For instance:
28
+ *
29
+ * For:
30
+ *
31
+ * ```ts
32
+ * const definitions = {
33
+ * { language: 'php', class: 'language-php', label: 'PHP' },
34
+ * { language: 'javascript', class: 'js', label: 'JavaScript' },
35
+ * };
36
+ *
37
+ * getPropertyAssociation( definitions, 'class', 'language' );
38
+ * ```
39
+ *
40
+ * returns:
41
+ *
42
+ * ```ts
43
+ * {
44
+ * 'language-php': 'php',
45
+ * 'js': 'javascript'
46
+ * }
47
+ * ```
48
+ *
49
+ * and
50
+ *
51
+ * ```ts
52
+ * getPropertyAssociation( definitions, 'language', 'label' );
53
+ * ```
54
+ *
55
+ * returns:
56
+ *
57
+ * ```ts
58
+ * {
59
+ * 'php': 'PHP',
60
+ * 'javascript': 'JavaScript'
61
+ * }
62
+ * ```
63
+ */
64
+ export declare function getPropertyAssociation(languageDefs: Array<CodeBlockLanguageDefinition>, key: keyof CodeBlockLanguageDefinition, value: keyof CodeBlockLanguageDefinition): Record<string, string>;
65
+ /**
66
+ * For a given model text node, it returns white spaces that precede other characters in that node.
67
+ * This corresponds to the indentation part of the code block line.
68
+ */
69
+ export declare function getLeadingWhiteSpaces(textNode: Text): string;
70
+ /**
71
+ * For plain text containing the code (a snippet), it returns a document fragment containing
72
+ * view text nodes separated by `<br>` elements (in place of new line characters "\n"), for instance:
73
+ *
74
+ * Input:
75
+ *
76
+ * ```ts
77
+ * "foo()\n
78
+ * bar()"
79
+ * ```
80
+ *
81
+ * Output:
82
+ *
83
+ * ```html
84
+ * <DocumentFragment>
85
+ * "foo()"
86
+ * <br/>
87
+ * "bar()"
88
+ * </DocumentFragment>
89
+ * ```
90
+ *
91
+ * @param text The raw code text to be converted.
92
+ */
93
+ export declare function rawSnippetTextToViewDocumentFragment(writer: UpcastWriter, text: string): ViewDocumentFragment;
94
+ /**
95
+ * Returns an array of all model positions within the selection that represent code block lines.
96
+ *
97
+ * If the selection is collapsed, it returns the exact selection anchor position:
98
+ *
99
+ * ```html
100
+ * <codeBlock>[]foo</codeBlock> -> <codeBlock>^foo</codeBlock>
101
+ * <codeBlock>foo[]bar</codeBlock> -> <codeBlock>foo^bar</codeBlock>
102
+ * ```
103
+ *
104
+ * Otherwise, it returns positions **before** each text node belonging to all code blocks contained by the selection:
105
+ *
106
+ * ```html
107
+ * <codeBlock> <codeBlock>
108
+ * foo[bar ^foobar
109
+ * <softBreak></softBreak> -> <softBreak></softBreak>
110
+ * baz]qux ^bazqux
111
+ * </codeBlock> </codeBlock>
112
+ * ```
113
+ *
114
+ * It also works across other non–code blocks:
115
+ *
116
+ * ```html
117
+ * <codeBlock> <codeBlock>
118
+ * foo[bar ^foobar
119
+ * </codeBlock> </codeBlock>
120
+ * <paragraph>text</paragraph> -> <paragraph>text</paragraph>
121
+ * <codeBlock> <codeBlock>
122
+ * baz]qux ^bazqux
123
+ * </codeBlock> </codeBlock>
124
+ * ```
125
+ *
126
+ * **Note:** The positions are in reverse order so they do not get outdated when iterating over them and
127
+ * the writer inserts or removes elements at the same time.
128
+ *
129
+ * **Note:** The position is located after the leading white spaces in the text node.
130
+ */
131
+ export declare function getIndentOutdentPositions(model: Model): Array<Position>;
132
+ /**
133
+ * Checks if any of the blocks within the model selection is a code block.
134
+ */
135
+ export declare function isModelSelectionInCodeBlock(selection: DocumentSelection): boolean;
136
+ /**
137
+ * Checks if an {@link module:engine/model/element~Element Element} can become a code block.
138
+ *
139
+ * @param schema Model's schema.
140
+ * @param element The element to be checked.
141
+ * @returns Check result.
142
+ */
143
+ export declare function canBeCodeBlock(schema: Schema, element: Element): boolean;
144
+ /**
145
+ * Get the translated message read by the screen reader when you enter or exit an element with your cursor.
146
+ */
147
+ export declare function getCodeBlockAriaAnnouncement(t: LocaleTranslate, languageDefs: Array<CodeBlockLanguageDefinition>, element: Element, direction: 'enter' | 'leave'): string;
@@ -1,5 +1,9 @@
1
1
  {
2
2
  "Insert code block": "A label of the button that allows inserting a new code block into the editor content.",
3
3
  "Plain text": "A language of the code block in the editor content when no specific programming language is associated with it.",
4
+ "Leaving %0 code snippet": "Assistive technologies label for leaving the code block with a specified programming language. Example: 'Leaving JavaScript code snippet'",
5
+ "Entering %0 code snippet": "Assistive technologies label for entering the code block with a specified programming language. Example: 'Entering JavaScript code snippet'",
6
+ "Entering code snippet": "Assistive technologies label for entering the code block with unspecified programming language.",
7
+ "Leaving code snippet": "Assistive technologies label for leaving the code block with unspecified programming language.",
4
8
  "Code block": "The accessible label of the menu bar button that inserts a code block into editor content."
5
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-code-block",
3
- "version": "41.3.0",
3
+ "version": "41.4.0-alpha.0",
4
4
  "description": "Code block feature for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -13,7 +13,8 @@
13
13
  "type": "module",
14
14
  "main": "src/index.js",
15
15
  "dependencies": {
16
- "ckeditor5": "41.3.0"
16
+ "ckeditor5": "41.4.0-alpha.0",
17
+ "lodash-es": "4.17.21"
17
18
  },
18
19
  "author": "CKSource (http://cksource.com/)",
19
20
  "license": "GPL-2.0-or-later",
@@ -25,6 +26,7 @@
25
26
  "directory": "packages/ckeditor5-code-block"
26
27
  },
27
28
  "files": [
29
+ "dist",
28
30
  "lang",
29
31
  "src/**/*.js",
30
32
  "src/**/*.d.ts",
@@ -2,9 +2,6 @@
2
2
  * @license Copyright (c) 2003-2024, 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
- * @module code-block/codeblockediting
7
- */
8
5
  import { Plugin, type Editor } from 'ckeditor5/src/core.js';
9
6
  import { ShiftEnter } from 'ckeditor5/src/enter.js';
10
7
  /**
@@ -33,4 +30,11 @@ export default class CodeBlockEditing extends Plugin {
33
30
  * @inheritDoc
34
31
  */
35
32
  afterInit(): void;
33
+ /**
34
+ * Observe when user enters or leaves code block and set proper aria value in global live announcer.
35
+ * This allows screen readers to indicate when the user has entered and left the specified code block.
36
+ *
37
+ * @internal
38
+ */
39
+ private _initAriaAnnouncements;
36
40
  }
@@ -2,16 +2,13 @@
2
2
  * @license Copyright (c) 2003-2024, 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
- * @module code-block/codeblockediting
7
- */
8
5
  import { Plugin } from 'ckeditor5/src/core.js';
9
6
  import { ShiftEnter } from 'ckeditor5/src/enter.js';
10
7
  import { UpcastWriter } from 'ckeditor5/src/engine.js';
11
8
  import CodeBlockCommand from './codeblockcommand.js';
12
9
  import IndentCodeBlockCommand from './indentcodeblockcommand.js';
13
10
  import OutdentCodeBlockCommand from './outdentcodeblockcommand.js';
14
- import { getNormalizedAndLocalizedLanguageDefinitions, getLeadingWhiteSpaces, rawSnippetTextToViewDocumentFragment } from './utils.js';
11
+ import { getNormalizedAndLocalizedLanguageDefinitions, getLeadingWhiteSpaces, rawSnippetTextToViewDocumentFragment, getCodeBlockAriaAnnouncement } from './utils.js';
15
12
  import { modelToViewCodeBlockInsertion, modelToDataViewSoftBreakInsertion, dataViewToModelCodeBlockInsertion, dataViewToModelTextNewlinesInsertion, dataViewToModelOrphanNodeConsumer } from './converters.js';
16
13
  const DEFAULT_ELEMENT = 'paragraph';
17
14
  /**
@@ -195,6 +192,31 @@ export default class CodeBlockEditing extends Plugin {
195
192
  data.preventDefault();
196
193
  evt.stop();
197
194
  }, { context: 'pre' });
195
+ this._initAriaAnnouncements();
196
+ }
197
+ /**
198
+ * Observe when user enters or leaves code block and set proper aria value in global live announcer.
199
+ * This allows screen readers to indicate when the user has entered and left the specified code block.
200
+ *
201
+ * @internal
202
+ */
203
+ _initAriaAnnouncements() {
204
+ const { model, ui, t } = this.editor;
205
+ const languageDefs = getNormalizedAndLocalizedLanguageDefinitions(this.editor);
206
+ let lastFocusedCodeBlock = null;
207
+ model.document.selection.on('change:range', () => {
208
+ const focusParent = model.document.selection.focus.parent;
209
+ if (!ui || lastFocusedCodeBlock === focusParent || !focusParent.is('element')) {
210
+ return;
211
+ }
212
+ if (lastFocusedCodeBlock && lastFocusedCodeBlock.is('element', 'codeBlock')) {
213
+ ui.ariaLiveAnnouncer.announce(getCodeBlockAriaAnnouncement(t, languageDefs, lastFocusedCodeBlock, 'leave'));
214
+ }
215
+ if (focusParent.is('element', 'codeBlock')) {
216
+ ui.ariaLiveAnnouncer.announce(getCodeBlockAriaAnnouncement(t, languageDefs, focusParent, 'enter'));
217
+ }
218
+ lastFocusedCodeBlock = focusParent;
219
+ });
198
220
  }
199
221
  }
200
222
  /**
package/src/utils.d.ts CHANGED
@@ -8,6 +8,7 @@
8
8
  import type { Editor } from 'ckeditor5/src/core.js';
9
9
  import type { CodeBlockLanguageDefinition } from './codeblockconfig.js';
10
10
  import type { DocumentSelection, Element, Model, Position, Schema, Text, UpcastWriter, ViewDocumentFragment } from 'ckeditor5/src/engine.js';
11
+ import { type LocaleTranslate } from 'ckeditor5/src/utils.js';
11
12
  /**
12
13
  * Returns code block languages as defined in `config.codeBlock.languages` but processed:
13
14
  *
@@ -136,3 +137,7 @@ export declare function isModelSelectionInCodeBlock(selection: DocumentSelection
136
137
  * @returns Check result.
137
138
  */
138
139
  export declare function canBeCodeBlock(schema: Schema, element: Element): boolean;
140
+ /**
141
+ * Get the translated message read by the screen reader when you enter or exit an element with your cursor.
142
+ */
143
+ export declare function getCodeBlockAriaAnnouncement(t: LocaleTranslate, languageDefs: Array<CodeBlockLanguageDefinition>, element: Element, direction: 'enter' | 'leave'): string;
package/src/utils.js CHANGED
@@ -207,3 +207,21 @@ export function canBeCodeBlock(schema, element) {
207
207
  }
208
208
  return schema.checkChild(element.parent, 'codeBlock');
209
209
  }
210
+ /**
211
+ * Get the translated message read by the screen reader when you enter or exit an element with your cursor.
212
+ */
213
+ export function getCodeBlockAriaAnnouncement(t, languageDefs, element, direction) {
214
+ const languagesToLabels = getPropertyAssociation(languageDefs, 'language', 'label');
215
+ const codeBlockLanguage = element.getAttribute('language');
216
+ if (codeBlockLanguage in languagesToLabels) {
217
+ const language = languagesToLabels[codeBlockLanguage];
218
+ if (direction === 'enter') {
219
+ return t('Entering %0 code snippet', language);
220
+ }
221
+ return t('Leaving %0 code snippet', language);
222
+ }
223
+ if (direction === 'enter') {
224
+ return t('Entering code snippet');
225
+ }
226
+ return t('Leaving code snippet');
227
+ }