@ckeditor/ckeditor5-code-block 39.0.1 → 40.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +3 -3
  3. package/build/code-block.js +1 -1
  4. package/build/code-block.js.map +1 -0
  5. package/lang/translations/af.po +1 -0
  6. package/lang/translations/ar.po +1 -0
  7. package/lang/translations/az.po +1 -0
  8. package/lang/translations/bg.po +1 -0
  9. package/lang/translations/bn.po +1 -0
  10. package/lang/translations/bs.po +1 -0
  11. package/lang/translations/ca.po +1 -0
  12. package/lang/translations/cs.po +1 -0
  13. package/lang/translations/da.po +1 -0
  14. package/lang/translations/de-ch.po +1 -0
  15. package/lang/translations/de.po +1 -0
  16. package/lang/translations/el.po +1 -0
  17. package/lang/translations/en-au.po +1 -0
  18. package/lang/translations/en.po +1 -0
  19. package/lang/translations/es-co.po +1 -0
  20. package/lang/translations/es.po +1 -0
  21. package/lang/translations/et.po +1 -0
  22. package/lang/translations/fa.po +1 -0
  23. package/lang/translations/fi.po +1 -0
  24. package/lang/translations/fr.po +1 -0
  25. package/lang/translations/gl.po +1 -0
  26. package/lang/translations/he.po +1 -0
  27. package/lang/translations/hi.po +1 -0
  28. package/lang/translations/hr.po +1 -0
  29. package/lang/translations/hu.po +1 -0
  30. package/lang/translations/id.po +1 -0
  31. package/lang/translations/it.po +1 -0
  32. package/lang/translations/ja.po +1 -0
  33. package/lang/translations/jv.po +1 -0
  34. package/lang/translations/ko.po +1 -0
  35. package/lang/translations/ku.po +1 -0
  36. package/lang/translations/lt.po +1 -0
  37. package/lang/translations/lv.po +1 -0
  38. package/lang/translations/ms.po +1 -0
  39. package/lang/translations/nl.po +1 -0
  40. package/lang/translations/no.po +1 -0
  41. package/lang/translations/pl.po +1 -0
  42. package/lang/translations/pt-br.po +1 -0
  43. package/lang/translations/pt.po +1 -0
  44. package/lang/translations/ro.po +1 -0
  45. package/lang/translations/ru.po +1 -0
  46. package/lang/translations/sk.po +1 -0
  47. package/lang/translations/sq.po +1 -0
  48. package/lang/translations/sr-latn.po +1 -0
  49. package/lang/translations/sr.po +1 -0
  50. package/lang/translations/sv.po +1 -0
  51. package/lang/translations/th.po +1 -0
  52. package/lang/translations/tk.po +1 -0
  53. package/lang/translations/tr.po +1 -0
  54. package/lang/translations/ug.po +1 -0
  55. package/lang/translations/uk.po +1 -0
  56. package/lang/translations/ur.po +1 -0
  57. package/lang/translations/uz.po +1 -0
  58. package/lang/translations/vi.po +1 -0
  59. package/lang/translations/zh-cn.po +1 -0
  60. package/lang/translations/zh.po +1 -0
  61. package/package.json +2 -6
  62. package/src/augmentation.d.ts +25 -25
  63. package/src/augmentation.js +5 -5
  64. package/src/codeblock.d.ts +29 -29
  65. package/src/codeblock.js +33 -33
  66. package/src/codeblockcommand.d.ts +60 -60
  67. package/src/codeblockcommand.js +138 -138
  68. package/src/codeblockconfig.d.ts +146 -146
  69. package/src/codeblockconfig.js +5 -5
  70. package/src/codeblockediting.d.ts +36 -36
  71. package/src/codeblockediting.js +382 -383
  72. package/src/codeblockui.d.ts +29 -29
  73. package/src/codeblockui.js +93 -93
  74. package/src/converters.d.ts +126 -126
  75. package/src/converters.js +277 -277
  76. package/src/indentcodeblockcommand.d.ts +33 -33
  77. package/src/indentcodeblockcommand.js +78 -78
  78. package/src/index.d.ts +15 -15
  79. package/src/index.js +11 -11
  80. package/src/outdentcodeblockcommand.d.ts +33 -33
  81. package/src/outdentcodeblockcommand.js +148 -148
  82. package/src/utils.d.ts +138 -138
  83. package/src/utils.js +209 -209
package/src/utils.d.ts CHANGED
@@ -1,138 +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;
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;