@ckeditor/ckeditor5-typing 41.3.0-alpha.4 → 41.3.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.
- package/package.json +4 -5
- package/dist/content-index.css +0 -4
- package/dist/editor-index.css +0 -4
- package/dist/index.css +0 -4
- package/dist/types/augmentation.d.ts +0 -31
- package/dist/types/delete.d.ts +0 -36
- package/dist/types/deletecommand.d.ts +0 -87
- package/dist/types/deleteobserver.d.ts +0 -59
- package/dist/types/index.d.ts +0 -28
- package/dist/types/input.d.ts +0 -25
- package/dist/types/inserttextcommand.d.ts +0 -80
- package/dist/types/inserttextobserver.d.ts +0 -63
- package/dist/types/texttransformation.d.ts +0 -37
- package/dist/types/textwatcher.d.ts +0 -142
- package/dist/types/twostepcaretmovement.d.ts +0 -236
- package/dist/types/typing.d.ts +0 -27
- package/dist/types/typingconfig.d.ts +0 -208
- package/dist/types/utils/changebuffer.d.ts +0 -107
- package/dist/types/utils/findattributerange.d.ts +0 -37
- package/dist/types/utils/getlasttextline.d.ts +0 -53
- package/dist/types/utils/inlinehighlight.d.ts +0 -37
|
@@ -1,236 +0,0 @@
|
|
|
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 typing/twostepcaretmovement
|
|
11
|
-
*/
|
|
12
|
-
import { Plugin, type Editor } from '@ckeditor/ckeditor5-core';
|
|
13
|
-
/**
|
|
14
|
-
* This plugin enables the two-step caret (phantom) movement behavior for
|
|
15
|
-
* {@link module:typing/twostepcaretmovement~TwoStepCaretMovement#registerAttribute registered attributes}
|
|
16
|
-
* on arrow right (<kbd>→</kbd>) and left (<kbd>←</kbd>) key press.
|
|
17
|
-
*
|
|
18
|
-
* Thanks to this (phantom) caret movement the user is able to type before/after as well as at the
|
|
19
|
-
* beginning/end of an attribute.
|
|
20
|
-
*
|
|
21
|
-
* **Note:** This plugin support right–to–left (Arabic, Hebrew, etc.) content by mirroring its behavior
|
|
22
|
-
* but for the sake of simplicity examples showcase only left–to–right use–cases.
|
|
23
|
-
*
|
|
24
|
-
* # Forward movement
|
|
25
|
-
*
|
|
26
|
-
* ## "Entering" an attribute:
|
|
27
|
-
*
|
|
28
|
-
* When this plugin is enabled and registered for the `a` attribute and the selection is right before it
|
|
29
|
-
* (at the attribute boundary), pressing the right arrow key will not move the selection but update its
|
|
30
|
-
* attributes accordingly:
|
|
31
|
-
*
|
|
32
|
-
* * When enabled:
|
|
33
|
-
*
|
|
34
|
-
* ```xml
|
|
35
|
-
* foo{}<$text a="true">bar</$text>
|
|
36
|
-
* ```
|
|
37
|
-
*
|
|
38
|
-
* <kbd>→</kbd>
|
|
39
|
-
*
|
|
40
|
-
* ```xml
|
|
41
|
-
* foo<$text a="true">{}bar</$text>
|
|
42
|
-
* ```
|
|
43
|
-
*
|
|
44
|
-
* * When disabled:
|
|
45
|
-
*
|
|
46
|
-
* ```xml
|
|
47
|
-
* foo{}<$text a="true">bar</$text>
|
|
48
|
-
* ```
|
|
49
|
-
*
|
|
50
|
-
* <kbd>→</kbd>
|
|
51
|
-
*
|
|
52
|
-
* ```xml
|
|
53
|
-
* foo<$text a="true">b{}ar</$text>
|
|
54
|
-
* ```
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* ## "Leaving" an attribute:
|
|
58
|
-
*
|
|
59
|
-
* * When enabled:
|
|
60
|
-
*
|
|
61
|
-
* ```xml
|
|
62
|
-
* <$text a="true">bar{}</$text>baz
|
|
63
|
-
* ```
|
|
64
|
-
*
|
|
65
|
-
* <kbd>→</kbd>
|
|
66
|
-
*
|
|
67
|
-
* ```xml
|
|
68
|
-
* <$text a="true">bar</$text>{}baz
|
|
69
|
-
* ```
|
|
70
|
-
*
|
|
71
|
-
* * When disabled:
|
|
72
|
-
*
|
|
73
|
-
* ```xml
|
|
74
|
-
* <$text a="true">bar{}</$text>baz
|
|
75
|
-
* ```
|
|
76
|
-
*
|
|
77
|
-
* <kbd>→</kbd>
|
|
78
|
-
*
|
|
79
|
-
* ```xml
|
|
80
|
-
* <$text a="true">bar</$text>b{}az
|
|
81
|
-
* ```
|
|
82
|
-
*
|
|
83
|
-
* # Backward movement
|
|
84
|
-
*
|
|
85
|
-
* * When enabled:
|
|
86
|
-
*
|
|
87
|
-
* ```xml
|
|
88
|
-
* <$text a="true">bar</$text>{}baz
|
|
89
|
-
* ```
|
|
90
|
-
*
|
|
91
|
-
* <kbd>←</kbd>
|
|
92
|
-
*
|
|
93
|
-
* ```xml
|
|
94
|
-
* <$text a="true">bar{}</$text>baz
|
|
95
|
-
* ```
|
|
96
|
-
*
|
|
97
|
-
* * When disabled:
|
|
98
|
-
*
|
|
99
|
-
* ```xml
|
|
100
|
-
* <$text a="true">bar</$text>{}baz
|
|
101
|
-
* ```
|
|
102
|
-
*
|
|
103
|
-
* <kbd>←</kbd>
|
|
104
|
-
*
|
|
105
|
-
* ```xml
|
|
106
|
-
* <$text a="true">ba{}r</$text>b{}az
|
|
107
|
-
* ```
|
|
108
|
-
*
|
|
109
|
-
* # Multiple attributes
|
|
110
|
-
*
|
|
111
|
-
* * When enabled and many attributes starts or ends at the same position:
|
|
112
|
-
*
|
|
113
|
-
* ```xml
|
|
114
|
-
* <$text a="true" b="true">bar</$text>{}baz
|
|
115
|
-
* ```
|
|
116
|
-
*
|
|
117
|
-
* <kbd>←</kbd>
|
|
118
|
-
*
|
|
119
|
-
* ```xml
|
|
120
|
-
* <$text a="true" b="true">bar{}</$text>baz
|
|
121
|
-
* ```
|
|
122
|
-
*
|
|
123
|
-
* * When enabled and one procedes another:
|
|
124
|
-
*
|
|
125
|
-
* ```xml
|
|
126
|
-
* <$text a="true">bar</$text><$text b="true">{}bar</$text>
|
|
127
|
-
* ```
|
|
128
|
-
*
|
|
129
|
-
* <kbd>←</kbd>
|
|
130
|
-
*
|
|
131
|
-
* ```xml
|
|
132
|
-
* <$text a="true">bar{}</$text><$text b="true">bar</$text>
|
|
133
|
-
* ```
|
|
134
|
-
*
|
|
135
|
-
*/
|
|
136
|
-
export default class TwoStepCaretMovement extends Plugin {
|
|
137
|
-
/**
|
|
138
|
-
* A set of attributes to handle.
|
|
139
|
-
*/
|
|
140
|
-
private attributes;
|
|
141
|
-
/**
|
|
142
|
-
* The current UID of the overridden gravity, as returned by
|
|
143
|
-
* {@link module:engine/model/writer~Writer#overrideSelectionGravity}.
|
|
144
|
-
*/
|
|
145
|
-
private _overrideUid;
|
|
146
|
-
/**
|
|
147
|
-
* A flag indicating that the automatic gravity restoration should not happen upon the next
|
|
148
|
-
* gravity restoration.
|
|
149
|
-
* {@link module:engine/model/selection~Selection#event:change:range} event.
|
|
150
|
-
*/
|
|
151
|
-
private _isNextGravityRestorationSkipped;
|
|
152
|
-
/**
|
|
153
|
-
* @inheritDoc
|
|
154
|
-
*/
|
|
155
|
-
static get pluginName(): "TwoStepCaretMovement";
|
|
156
|
-
/**
|
|
157
|
-
* @inheritDoc
|
|
158
|
-
*/
|
|
159
|
-
constructor(editor: Editor);
|
|
160
|
-
/**
|
|
161
|
-
* @inheritDoc
|
|
162
|
-
*/
|
|
163
|
-
init(): void;
|
|
164
|
-
/**
|
|
165
|
-
* Registers a given attribute for the two-step caret movement.
|
|
166
|
-
*
|
|
167
|
-
* @param attribute Name of the attribute to handle.
|
|
168
|
-
*/
|
|
169
|
-
registerAttribute(attribute: string): void;
|
|
170
|
-
/**
|
|
171
|
-
* Updates the document selection and the view according to the two–step caret movement state
|
|
172
|
-
* when moving **forwards**. Executed upon `keypress` in the {@link module:engine/view/view~View}.
|
|
173
|
-
*
|
|
174
|
-
* @param data Data of the key press.
|
|
175
|
-
* @returns `true` when the handler prevented caret movement.
|
|
176
|
-
*/
|
|
177
|
-
private _handleForwardMovement;
|
|
178
|
-
/**
|
|
179
|
-
* Updates the document selection and the view according to the two–step caret movement state
|
|
180
|
-
* when moving **backwards**. Executed upon `keypress` in the {@link module:engine/view/view~View}.
|
|
181
|
-
*
|
|
182
|
-
* @param data Data of the key press.
|
|
183
|
-
* @returns `true` when the handler prevented caret movement
|
|
184
|
-
*/
|
|
185
|
-
private _handleBackwardMovement;
|
|
186
|
-
/**
|
|
187
|
-
* Starts listening to {@link module:engine/view/document~Document#event:mousedown} and
|
|
188
|
-
* {@link module:engine/view/document~Document#event:selectionChange} and puts the selection before/after a 2-step node
|
|
189
|
-
* if clicked at the beginning/ending of the 2-step node.
|
|
190
|
-
*
|
|
191
|
-
* The purpose of this action is to allow typing around the 2-step node directly after a click.
|
|
192
|
-
*
|
|
193
|
-
* See https://github.com/ckeditor/ckeditor5/issues/1016.
|
|
194
|
-
*/
|
|
195
|
-
private _enableClickingAfterNode;
|
|
196
|
-
/**
|
|
197
|
-
* Starts listening to {@link module:engine/model/model~Model#event:insertContent} and corrects the model
|
|
198
|
-
* selection attributes if the selection is at the end of a two-step node after inserting the content.
|
|
199
|
-
*
|
|
200
|
-
* The purpose of this action is to improve the overall UX because the user is no longer "trapped" by the
|
|
201
|
-
* two-step attribute of the selection, and they can type a "clean" (`linkHref`–less) text right away.
|
|
202
|
-
*
|
|
203
|
-
* See https://github.com/ckeditor/ckeditor5/issues/6053.
|
|
204
|
-
*/
|
|
205
|
-
private _enableInsertContentSelectionAttributesFixer;
|
|
206
|
-
/**
|
|
207
|
-
* Starts listening to {@link module:engine/model/model~Model#deleteContent} and checks whether
|
|
208
|
-
* removing a content right after the tow-step attribute.
|
|
209
|
-
*
|
|
210
|
-
* If so, the selection should not preserve the two-step attribute. However, if
|
|
211
|
-
* the {@link module:typing/twostepcaretmovement~TwoStepCaretMovement} plugin is active and
|
|
212
|
-
* the selection has the two-step attribute due to overridden gravity (at the end), the two-step attribute should stay untouched.
|
|
213
|
-
*
|
|
214
|
-
* The purpose of this action is to allow removing the link text and keep the selection outside the link.
|
|
215
|
-
*
|
|
216
|
-
* See https://github.com/ckeditor/ckeditor5/issues/7521.
|
|
217
|
-
*/
|
|
218
|
-
private _handleDeleteContentAfterNode;
|
|
219
|
-
/**
|
|
220
|
-
* `true` when the gravity is overridden for the plugin.
|
|
221
|
-
*/
|
|
222
|
-
private get _isGravityOverridden();
|
|
223
|
-
/**
|
|
224
|
-
* Overrides the gravity using the {@link module:engine/model/writer~Writer model writer}
|
|
225
|
-
* and stores the information about this fact in the {@link #_overrideUid}.
|
|
226
|
-
*
|
|
227
|
-
* A shorthand for {@link module:engine/model/writer~Writer#overrideSelectionGravity}.
|
|
228
|
-
*/
|
|
229
|
-
private _overrideGravity;
|
|
230
|
-
/**
|
|
231
|
-
* Restores the gravity using the {@link module:engine/model/writer~Writer model writer}.
|
|
232
|
-
*
|
|
233
|
-
* A shorthand for {@link module:engine/model/writer~Writer#restoreSelectionGravity}.
|
|
234
|
-
*/
|
|
235
|
-
private _restoreGravity;
|
|
236
|
-
}
|
package/dist/types/typing.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
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 typing/typing
|
|
11
|
-
*/
|
|
12
|
-
import { Plugin } from '@ckeditor/ckeditor5-core';
|
|
13
|
-
import Input from './input.js';
|
|
14
|
-
import Delete from './delete.js';
|
|
15
|
-
/**
|
|
16
|
-
* The typing feature. It handles typing.
|
|
17
|
-
*
|
|
18
|
-
* This is a "glue" plugin which loads the {@link module:typing/input~Input} and {@link module:typing/delete~Delete}
|
|
19
|
-
* plugins.
|
|
20
|
-
*/
|
|
21
|
-
export default class Typing extends Plugin {
|
|
22
|
-
static get requires(): readonly [typeof Input, typeof Delete];
|
|
23
|
-
/**
|
|
24
|
-
* @inheritDoc
|
|
25
|
-
*/
|
|
26
|
-
static get pluginName(): "Typing";
|
|
27
|
-
}
|
|
@@ -1,208 +0,0 @@
|
|
|
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 typing/typingconfig
|
|
11
|
-
*/
|
|
12
|
-
/**
|
|
13
|
-
* The configuration of the typing features. Used by the typing features in `@ckeditor/ckeditor5-typing` package.
|
|
14
|
-
*
|
|
15
|
-
* ```ts
|
|
16
|
-
* ClassicEditor
|
|
17
|
-
* .create( editorElement, {
|
|
18
|
-
* typing: ... // Typing feature options.
|
|
19
|
-
* } )
|
|
20
|
-
* .then( ... )
|
|
21
|
-
* .catch( ... );
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
|
|
25
|
-
*/
|
|
26
|
-
export interface TypingConfig {
|
|
27
|
-
/**
|
|
28
|
-
* The granularity of undo/redo for typing and deleting. The value `20` means (more or less) that a new undo step
|
|
29
|
-
* is created every 20 characters are inserted or deleted.
|
|
30
|
-
*
|
|
31
|
-
* @default 20
|
|
32
|
-
*/
|
|
33
|
-
undoStep?: number;
|
|
34
|
-
/**
|
|
35
|
-
* The configuration of the {@link module:typing/texttransformation~TextTransformation} feature.
|
|
36
|
-
*
|
|
37
|
-
* Read more in {@link module:typing/typingconfig~TextTransformationConfig}.
|
|
38
|
-
*/
|
|
39
|
-
transformations: TextTransformationConfig;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* The configuration of the text transformation feature.
|
|
43
|
-
*
|
|
44
|
-
* ```ts
|
|
45
|
-
* ClassicEditor
|
|
46
|
-
* .create( editorElement, {
|
|
47
|
-
* typing: {
|
|
48
|
-
* transformations: ... // Text transformation feature options.
|
|
49
|
-
* }
|
|
50
|
-
* } )
|
|
51
|
-
* .then( ... )
|
|
52
|
-
* .catch( ... );
|
|
53
|
-
* ```
|
|
54
|
-
*
|
|
55
|
-
* By default, the feature comes pre-configured
|
|
56
|
-
* (via {@link module:typing/typingconfig~TextTransformationConfig#include `config.typing.transformations.include`}) with the
|
|
57
|
-
* following groups of transformations:
|
|
58
|
-
*
|
|
59
|
-
* * Typography (group name: `typography`)
|
|
60
|
-
* - `ellipsis`: transforms `...` to `…`
|
|
61
|
-
* - `enDash`: transforms ` -- ` to ` – `
|
|
62
|
-
* - `emDash`: transforms ` --- ` to ` — `
|
|
63
|
-
* * Quotations (group name: `quotes`)
|
|
64
|
-
* - `quotesPrimary`: transforms `"Foo bar"` to `“Foo bar”`
|
|
65
|
-
* - `quotesSecondary`: transforms `'Foo bar'` to `‘Foo bar’`
|
|
66
|
-
* * Symbols (group name: `symbols`)
|
|
67
|
-
* - `trademark`: transforms `(tm)` to `™`
|
|
68
|
-
* - `registeredTrademark`: transforms `(r)` to `®`
|
|
69
|
-
* - `copyright`: transforms `(c)` to `©`
|
|
70
|
-
* * Mathematical (group name: `mathematical`)
|
|
71
|
-
* - `oneHalf`: transforms `1/2` to: `½`
|
|
72
|
-
* - `oneThird`: transforms `1/3` to: `⅓`
|
|
73
|
-
* - `twoThirds`: transforms `2/3` to: `⅔`
|
|
74
|
-
* - `oneForth`: transforms `1/4` to: `¼`
|
|
75
|
-
* - `threeQuarters`: transforms `3/4` to: `¾`
|
|
76
|
-
* - `lessThanOrEqual`: transforms `<=` to: `≤`
|
|
77
|
-
* - `greaterThanOrEqual`: transforms `>=` to: `≥`
|
|
78
|
-
* - `notEqual`: transforms `!=` to: `≠`
|
|
79
|
-
* - `arrowLeft`: transforms `<-` to: `←`
|
|
80
|
-
* - `arrowRight`: transforms `->` to: `→`
|
|
81
|
-
* * Misc:
|
|
82
|
-
* - `quotesPrimaryEnGb`: transforms `'Foo bar'` to `‘Foo bar’`
|
|
83
|
-
* - `quotesSecondaryEnGb`: transforms `"Foo bar"` to `“Foo bar”`
|
|
84
|
-
* - `quotesPrimaryPl`: transforms `"Foo bar"` to `„Foo bar”`
|
|
85
|
-
* - `quotesSecondaryPl`: transforms `'Foo bar'` to `‚Foo bar’`
|
|
86
|
-
*
|
|
87
|
-
* In order to load additional transformations, use the
|
|
88
|
-
* {@link module:typing/typingconfig~TextTransformationConfig#extra `transformations.extra` option}.
|
|
89
|
-
*
|
|
90
|
-
* In order to narrow down the list of transformations, use the
|
|
91
|
-
* {@link module:typing/typingconfig~TextTransformationConfig#remove `transformations.remove` option}.
|
|
92
|
-
*
|
|
93
|
-
* In order to completely override the supported transformations, use the
|
|
94
|
-
* {@link module:typing/typingconfig~TextTransformationConfig#include `transformations.include` option}.
|
|
95
|
-
*
|
|
96
|
-
* Examples:
|
|
97
|
-
*
|
|
98
|
-
* ```ts
|
|
99
|
-
* const transformationsConfig = {
|
|
100
|
-
* include: [
|
|
101
|
-
* // Use only the 'quotes' and 'typography' groups.
|
|
102
|
-
* 'quotes',
|
|
103
|
-
* 'typography',
|
|
104
|
-
*
|
|
105
|
-
* // Plus, some custom transformation.
|
|
106
|
-
* { from: 'CKE', to: 'CKEditor' }
|
|
107
|
-
* ]
|
|
108
|
-
* };
|
|
109
|
-
*
|
|
110
|
-
* const transformationsConfig = {
|
|
111
|
-
* // Remove the 'ellipsis' transformation loaded by the 'typography' group.
|
|
112
|
-
* remove: [ 'ellipsis' ]
|
|
113
|
-
* }
|
|
114
|
-
* ```
|
|
115
|
-
*/
|
|
116
|
-
export interface TextTransformationConfig {
|
|
117
|
-
/**
|
|
118
|
-
* The standard list of text transformations supported by the editor. By default it comes pre-configured with a couple dozen of them
|
|
119
|
-
* (see {@link module:typing/typingconfig~TextTransformationConfig} for the full list). You can override this list completely
|
|
120
|
-
* by setting this option or use the other two options
|
|
121
|
-
* ({@link module:typing/typingconfig~TextTransformationConfig#extra `transformations.extra`},
|
|
122
|
-
* {@link module:typing/typingconfig~TextTransformationConfig#remove `transformations.remove`}) to fine-tune the default list.
|
|
123
|
-
*/
|
|
124
|
-
include: Array<TextTransformationDescription | string>;
|
|
125
|
-
/**
|
|
126
|
-
* Additional text transformations that are added to the transformations defined in
|
|
127
|
-
* {@link module:typing/typingconfig~TextTransformationConfig#include `transformations.include`}.
|
|
128
|
-
*
|
|
129
|
-
* ```ts
|
|
130
|
-
* const transformationsConfig = {
|
|
131
|
-
* extra: [
|
|
132
|
-
* { from: 'CKE', to: 'CKEditor' }
|
|
133
|
-
* ]
|
|
134
|
-
* };
|
|
135
|
-
* ```
|
|
136
|
-
*/
|
|
137
|
-
extra?: Array<TextTransformationDescription | string>;
|
|
138
|
-
/**
|
|
139
|
-
* The text transformation names that are removed from transformations defined in
|
|
140
|
-
* {@link module:typing/typingconfig~TextTransformationConfig#include `transformations.include`} or
|
|
141
|
-
* {@link module:typing/typingconfig~TextTransformationConfig#extra `transformations.extra`}.
|
|
142
|
-
*
|
|
143
|
-
* ```ts
|
|
144
|
-
* const transformationsConfig = {
|
|
145
|
-
* remove: [
|
|
146
|
-
* 'ellipsis', // Remove only 'ellipsis' from the 'typography' group.
|
|
147
|
-
* 'mathematical' // Remove all transformations from the 'mathematical' group.
|
|
148
|
-
* ]
|
|
149
|
-
* }
|
|
150
|
-
* ```
|
|
151
|
-
*/
|
|
152
|
-
remove?: Array<TextTransformationDescription | string>;
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* The text transformation definition object. It describes what should be replaced with what.
|
|
156
|
-
*
|
|
157
|
-
* The input value (`from`) can be passed either as a string or as a regular expression.
|
|
158
|
-
*
|
|
159
|
-
* * If a string is passed, it will be simply checked if the end of the input matches it.
|
|
160
|
-
* * If a regular expression is passed, its entire length must be covered with capturing groups (e.g. `/(foo)(bar)$/`).
|
|
161
|
-
* Also, since it is compared against the end of the input, it has to end with `$` to be correctly matched.
|
|
162
|
-
* See examples below.
|
|
163
|
-
*
|
|
164
|
-
* The output value (`to`) can be passed as a string, as an array or as a function.
|
|
165
|
-
*
|
|
166
|
-
* * If a string is passed, it will be used as a replacement value as-is. Note that a string output value can be used only if
|
|
167
|
-
* the input value is a string, too.
|
|
168
|
-
* * If an array is passed, it has to have the same number of elements as there are capturing groups in the input value regular expression.
|
|
169
|
-
* Each capture group will be replaced with a corresponding string from the passed array. If a given capturing group should not be replaced,
|
|
170
|
-
* use `null` instead of passing a string.
|
|
171
|
-
* * If a function is used, it should return an array as described above. The function is passed one parameter – an array with matches
|
|
172
|
-
* by the regular expression. See the examples below.
|
|
173
|
-
*
|
|
174
|
-
* A simple string-to-string replacement:
|
|
175
|
-
*
|
|
176
|
-
* ```ts
|
|
177
|
-
* { from: '(c)', to: '©' }
|
|
178
|
-
* ```
|
|
179
|
-
*
|
|
180
|
-
* Change quote styles using a regular expression. Note how all the parts are in separate capturing groups and the space at the beginning
|
|
181
|
-
* and the text inside quotes are not replaced (`null` passed as the first and the third value in the `to` parameter):
|
|
182
|
-
*
|
|
183
|
-
* ```ts
|
|
184
|
-
* {
|
|
185
|
-
* from: /(^|\s)(")([^"]*)(")$/,
|
|
186
|
-
* to: [ null, '“', null, '”' ]
|
|
187
|
-
* }
|
|
188
|
-
* ```
|
|
189
|
-
*
|
|
190
|
-
* Automatic uppercase after a dot using a callback:
|
|
191
|
-
*
|
|
192
|
-
* ```ts
|
|
193
|
-
* {
|
|
194
|
-
* from: /(\. )([a-z])$/,
|
|
195
|
-
* to: matches => [ null, matches[ 1 ].toUpperCase() ]
|
|
196
|
-
* }
|
|
197
|
-
* ```
|
|
198
|
-
*/
|
|
199
|
-
export interface TextTransformationDescription {
|
|
200
|
-
/**
|
|
201
|
-
* The string or regular expression to transform.
|
|
202
|
-
*/
|
|
203
|
-
from: string | RegExp;
|
|
204
|
-
/**
|
|
205
|
-
* The text to transform compatible with `String.replace()`.
|
|
206
|
-
*/
|
|
207
|
-
to: string | Array<string | null> | ((matches: Array<string>) => Array<string | null>);
|
|
208
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
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 typing/utils/changebuffer
|
|
11
|
-
*/
|
|
12
|
-
import type { Model, Batch } from '@ckeditor/ckeditor5-engine';
|
|
13
|
-
/**
|
|
14
|
-
* Change buffer allows to group atomic changes (like characters that have been typed) into
|
|
15
|
-
* {@link module:engine/model/batch~Batch batches}.
|
|
16
|
-
*
|
|
17
|
-
* Batches represent single undo steps, hence changes added to one single batch are undone together.
|
|
18
|
-
*
|
|
19
|
-
* The buffer has a configurable limit of atomic changes that it can accommodate. After the limit was
|
|
20
|
-
* exceeded (see {@link ~ChangeBuffer#input}), a new batch is created in {@link ~ChangeBuffer#batch}.
|
|
21
|
-
*
|
|
22
|
-
* To use the change buffer you need to let it know about the number of changes that were added to the batch:
|
|
23
|
-
*
|
|
24
|
-
* ```ts
|
|
25
|
-
* const buffer = new ChangeBuffer( model, LIMIT );
|
|
26
|
-
*
|
|
27
|
-
* // Later on in your feature:
|
|
28
|
-
* buffer.batch.insert( pos, insertedCharacters );
|
|
29
|
-
* buffer.input( insertedCharacters.length );
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
export default class ChangeBuffer {
|
|
33
|
-
/**
|
|
34
|
-
* The model instance.
|
|
35
|
-
*/
|
|
36
|
-
readonly model: Model;
|
|
37
|
-
/**
|
|
38
|
-
* The maximum number of atomic changes which can be contained in one batch.
|
|
39
|
-
*/
|
|
40
|
-
readonly limit: number;
|
|
41
|
-
/**
|
|
42
|
-
* Whether the buffer is locked. A locked buffer cannot be reset unless it gets unlocked.
|
|
43
|
-
*/
|
|
44
|
-
private _isLocked;
|
|
45
|
-
/**
|
|
46
|
-
* The number of atomic changes in the buffer. Once it exceeds the {@link #limit},
|
|
47
|
-
* the {@link #batch batch} is set to a new one.
|
|
48
|
-
*/
|
|
49
|
-
private _size;
|
|
50
|
-
/**
|
|
51
|
-
* The current batch instance.
|
|
52
|
-
*/
|
|
53
|
-
private _batch;
|
|
54
|
-
/**
|
|
55
|
-
* The callback to document the change event which later needs to be removed.
|
|
56
|
-
*/
|
|
57
|
-
private readonly _changeCallback;
|
|
58
|
-
/**
|
|
59
|
-
* The callback to document selection `change:attribute` and `change:range` events which resets the buffer.
|
|
60
|
-
*/
|
|
61
|
-
private readonly _selectionChangeCallback;
|
|
62
|
-
/**
|
|
63
|
-
* Creates a new instance of the change buffer.
|
|
64
|
-
*
|
|
65
|
-
* @param limit The maximum number of atomic changes which can be contained in one batch.
|
|
66
|
-
*/
|
|
67
|
-
constructor(model: Model, limit?: number);
|
|
68
|
-
/**
|
|
69
|
-
* The current batch to which a feature should add its operations. Once the {@link #size}
|
|
70
|
-
* is reached or exceeds the {@link #limit}, the batch is set to a new instance and the size is reset.
|
|
71
|
-
*/
|
|
72
|
-
get batch(): Batch;
|
|
73
|
-
/**
|
|
74
|
-
* The number of atomic changes in the buffer. Once it exceeds the {@link #limit},
|
|
75
|
-
* the {@link #batch batch} is set to a new one.
|
|
76
|
-
*/
|
|
77
|
-
get size(): number;
|
|
78
|
-
/**
|
|
79
|
-
* The input number of changes into the buffer. Once the {@link #size} is
|
|
80
|
-
* reached or exceeds the {@link #limit}, the batch is set to a new instance and the size is reset.
|
|
81
|
-
*
|
|
82
|
-
* @param changeCount The number of atomic changes to input.
|
|
83
|
-
*/
|
|
84
|
-
input(changeCount: number): void;
|
|
85
|
-
/**
|
|
86
|
-
* Whether the buffer is locked. A locked buffer cannot be reset unless it gets unlocked.
|
|
87
|
-
*/
|
|
88
|
-
get isLocked(): boolean;
|
|
89
|
-
/**
|
|
90
|
-
* Locks the buffer.
|
|
91
|
-
*/
|
|
92
|
-
lock(): void;
|
|
93
|
-
/**
|
|
94
|
-
* Unlocks the buffer.
|
|
95
|
-
*/
|
|
96
|
-
unlock(): void;
|
|
97
|
-
/**
|
|
98
|
-
* Destroys the buffer.
|
|
99
|
-
*/
|
|
100
|
-
destroy(): void;
|
|
101
|
-
/**
|
|
102
|
-
* Resets the change buffer.
|
|
103
|
-
*
|
|
104
|
-
* @param ignoreLock Whether internal lock {@link #isLocked} should be ignored.
|
|
105
|
-
*/
|
|
106
|
-
private _reset;
|
|
107
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
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 typing/utils/findattributerange
|
|
11
|
-
*/
|
|
12
|
-
import type { Position, Model, Range } from '@ckeditor/ckeditor5-engine';
|
|
13
|
-
/**
|
|
14
|
-
* Returns a model range that covers all consecutive nodes with the same `attributeName` and its `value`
|
|
15
|
-
* that intersect the given `position`.
|
|
16
|
-
*
|
|
17
|
-
* It can be used e.g. to get the entire range on which the `linkHref` attribute needs to be changed when having a
|
|
18
|
-
* selection inside a link.
|
|
19
|
-
*
|
|
20
|
-
* @param position The start position.
|
|
21
|
-
* @param attributeName The attribute name.
|
|
22
|
-
* @param value The attribute value.
|
|
23
|
-
* @param model The model instance.
|
|
24
|
-
* @returns The link range.
|
|
25
|
-
*/
|
|
26
|
-
export default function findAttributeRange(position: Position, attributeName: string, value: unknown, model: Model): Range;
|
|
27
|
-
/**
|
|
28
|
-
* Walks forward or backward (depends on the `lookBack` flag), node by node, as long as they have the same attribute value
|
|
29
|
-
* and returns a position just before or after (depends on the `lookBack` flag) the last matched node.
|
|
30
|
-
*
|
|
31
|
-
* @param position The start position.
|
|
32
|
-
* @param attributeName The attribute name.
|
|
33
|
-
* @param value The attribute value.
|
|
34
|
-
* @param lookBack Whether the walk direction is forward (`false`) or backward (`true`).
|
|
35
|
-
* @returns The position just before the last matched node.
|
|
36
|
-
*/
|
|
37
|
-
export declare function findAttributeRangeBound(position: Position, attributeName: string, value: unknown, lookBack: boolean, model: Model): Position;
|
|
@@ -1,53 +0,0 @@
|
|
|
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 typing/utils/getlasttextline
|
|
11
|
-
*/
|
|
12
|
-
import type { Model, Range } from '@ckeditor/ckeditor5-engine';
|
|
13
|
-
/**
|
|
14
|
-
* Returns the last text line from the given range.
|
|
15
|
-
*
|
|
16
|
-
* "The last text line" is understood as text (from one or more text nodes) which is limited either by a parent block
|
|
17
|
-
* or by inline elements (e.g. `<softBreak>`).
|
|
18
|
-
*
|
|
19
|
-
* ```ts
|
|
20
|
-
* const rangeToCheck = model.createRange(
|
|
21
|
-
* model.createPositionAt( paragraph, 0 ),
|
|
22
|
-
* model.createPositionAt( paragraph, 'end' )
|
|
23
|
-
* );
|
|
24
|
-
*
|
|
25
|
-
* const { text, range } = getLastTextLine( rangeToCheck, model );
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
28
|
-
* For model below, the returned `text` will be "Foo bar baz" and `range` will be set on whole `<paragraph>` content:
|
|
29
|
-
*
|
|
30
|
-
* ```xml
|
|
31
|
-
* <paragraph>Foo bar baz<paragraph>
|
|
32
|
-
* ```
|
|
33
|
-
*
|
|
34
|
-
* However, in below case, `text` will be set to "baz" and `range` will be set only on "baz".
|
|
35
|
-
*
|
|
36
|
-
* ```xml
|
|
37
|
-
* <paragraph>Foo<softBreak></softBreak>bar<softBreak></softBreak>baz<paragraph>
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
export default function getLastTextLine(range: Range, model: Model): LastTextLineData;
|
|
41
|
-
/**
|
|
42
|
-
* The value returned by {@link module:typing/utils/getlasttextline~getLastTextLine}.
|
|
43
|
-
*/
|
|
44
|
-
export type LastTextLineData = {
|
|
45
|
-
/**
|
|
46
|
-
* The text from the text nodes in the last text line.
|
|
47
|
-
*/
|
|
48
|
-
text: string;
|
|
49
|
-
/**
|
|
50
|
-
* The range set on the text nodes in the last text line.
|
|
51
|
-
*/
|
|
52
|
-
range: Range;
|
|
53
|
-
};
|