@ckeditor/ckeditor5-code-block 38.1.1 → 38.2.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 +3 -2
- package/src/augmentation.d.ts +25 -25
- package/src/augmentation.js +5 -5
- package/src/codeblock.d.ts +29 -29
- package/src/codeblock.js +33 -33
- package/src/codeblockcommand.d.ts +60 -60
- package/src/codeblockcommand.js +138 -138
- package/src/codeblockconfig.d.ts +146 -146
- package/src/codeblockconfig.js +5 -5
- package/src/codeblockediting.d.ts +36 -36
- package/src/codeblockediting.js +383 -383
- package/src/codeblockui.d.ts +29 -29
- package/src/codeblockui.js +93 -93
- package/src/converters.d.ts +126 -126
- package/src/converters.js +277 -277
- package/src/indentcodeblockcommand.d.ts +33 -33
- package/src/indentcodeblockcommand.js +78 -78
- package/src/index.d.ts +15 -15
- package/src/index.js +11 -11
- package/src/outdentcodeblockcommand.d.ts +33 -33
- package/src/outdentcodeblockcommand.js +148 -148
- package/src/utils.d.ts +138 -138
- package/src/utils.js +209 -209
- package/build/code-block.js.map +0 -1
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.js';
|
|
9
|
+
import type { CodeBlockLanguageDefinition } from './codeblockconfig.js';
|
|
10
|
+
import type { DocumentSelection, Element, Model, Position, Schema, Text, UpcastWriter, ViewDocumentFragment } from 'ckeditor5/src/engine.js';
|
|
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;
|