@ckeditor/ckeditor5-find-and-replace 40.0.0 → 40.2.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.
@@ -1,288 +1,288 @@
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 find-and-replace/ui/findandreplaceformview
7
- */
8
- import { View, LabeledFieldView, type InputView } from 'ckeditor5/src/ui';
9
- import { type Locale } from 'ckeditor5/src/utils';
10
- import '@ckeditor/ckeditor5-ui/theme/components/responsive-form/responsiveform.css';
11
- import '../../theme/findandreplaceform.css';
12
- /**
13
- * The find and replace form view class.
14
- *
15
- * See {@link module:find-and-replace/ui/findandreplaceformview~FindAndReplaceFormView}.
16
- */
17
- export default class FindAndReplaceFormView extends View {
18
- /**
19
- * Stores the number of matched search results.
20
- *
21
- * @readonly
22
- * @observable
23
- */
24
- matchCount: number;
25
- /**
26
- * The offset of currently highlighted search result in {@link #matchCount matched results}.
27
- *
28
- * @observable
29
- */
30
- readonly highlightOffset: number;
31
- /**
32
- * `true` when the search params (find text, options) has been changed by the user since
33
- * the last time find was executed. `false` otherwise.
34
- *
35
- * @readonly
36
- * @observable
37
- */
38
- isDirty: boolean;
39
- /**
40
- * A live object with the aggregated `isEnabled` states of editor commands related to find and
41
- * replace. For instance, it may look as follows:
42
- *
43
- * ```json
44
- * {
45
- * findNext: true,
46
- * findPrevious: true,
47
- * replace: false,
48
- * replaceAll: false
49
- * }
50
- * ```
51
- *
52
- * @internal
53
- * @observable
54
- */
55
- readonly _areCommandsEnabled: Record<string, boolean>;
56
- /**
57
- * The content of the counter label displaying the index of the current highlighted match
58
- * on top of the find input, for instance "3 of 50".
59
- *
60
- * @internal
61
- * @readonly
62
- * @observable
63
- */
64
- _resultsCounterText: string;
65
- /**
66
- * The flag reflecting the state of the "Match case" switch button in the search options
67
- * dropdown.
68
- *
69
- * @internal
70
- * @readonly
71
- * @observable
72
- */
73
- _matchCase: boolean;
74
- /**
75
- * The flag reflecting the state of the "Whole words only" switch button in the search options
76
- * dropdown.
77
- *
78
- * @internal
79
- * @readonly
80
- * @observable
81
- */
82
- _wholeWordsOnly: boolean;
83
- /**
84
- * This flag is set `true` when some matches were found and the user didn't change the search
85
- * params (text to find, options) yet. This is only possible immediately after hitting the "Find" button.
86
- * `false` when there were no matches (see {@link #matchCount}) or the user changed the params (see {@link #isDirty}).
87
- *
88
- * It is used to control the enabled state of the replace UI (input and buttons); replacing text is only possible
89
- * if this flag is `true`.
90
- *
91
- * @internal
92
- * @observable
93
- */
94
- readonly _searchResultsFound: boolean;
95
- /**
96
- * The find in text input view that stores the searched string.
97
- *
98
- * @internal
99
- */
100
- readonly _findInputView: LabeledFieldView<InputView>;
101
- /**
102
- * The replace input view.
103
- */
104
- private readonly _replaceInputView;
105
- /**
106
- * The find button view that initializes the search process.
107
- */
108
- private readonly _findButtonView;
109
- /**
110
- * The find previous button view.
111
- */
112
- private readonly _findPrevButtonView;
113
- /**
114
- * The find next button view.
115
- */
116
- private readonly _findNextButtonView;
117
- /**
118
- * The find options dropdown.
119
- */
120
- private readonly _optionsDropdown;
121
- /**
122
- * The replace button view.
123
- */
124
- private readonly _replaceButtonView;
125
- /**
126
- * The replace all button view.
127
- */
128
- private readonly _replaceAllButtonView;
129
- /**
130
- * The fieldset aggregating the find UI.
131
- */
132
- private readonly _findFieldsetView;
133
- /**
134
- * The fieldset aggregating the replace UI.
135
- */
136
- private readonly _replaceFieldsetView;
137
- /**
138
- * Tracks information about the DOM focus in the form.
139
- */
140
- private readonly _focusTracker;
141
- /**
142
- * An instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
143
- */
144
- private readonly _keystrokes;
145
- /**
146
- * A collection of views that can be focused in the form.
147
- */
148
- private readonly _focusables;
149
- /**
150
- * Helps cycling over {@link #_focusables} in the form.
151
- */
152
- private readonly _focusCycler;
153
- locale: Locale;
154
- /**
155
- * Creates a view of find and replace form.
156
- *
157
- * @param locale The localization services instance.
158
- */
159
- constructor(locale: Locale);
160
- /**
161
- * @inheritDoc
162
- */
163
- render(): void;
164
- /**
165
- * @inheritDoc
166
- */
167
- destroy(): void;
168
- /**
169
- * Focuses the fist {@link #_focusables} in the form.
170
- */
171
- focus(): void;
172
- /**
173
- * Resets the form before re-appearing.
174
- *
175
- * It clears error messages, hides the match counter and disables the replace feature
176
- * until the next hit of the "Find" button.
177
- *
178
- * **Note**: It does not reset inputs and options, though. This way the form works better in editors with
179
- * disappearing toolbar (e.g. BalloonEditor): hiding the toolbar by accident (together with the find and replace UI)
180
- * does not require filling the entire form again.
181
- */
182
- reset(): void;
183
- /**
184
- * Returns the value of the find input.
185
- */
186
- private get _textToFind();
187
- /**
188
- * Returns the value of the replace input.
189
- */
190
- private get _textToReplace();
191
- /**
192
- * Configures and returns the `<fieldset>` aggregating all find controls.
193
- */
194
- private _createFindFieldset;
195
- /**
196
- * The action performed when the {@link #_findButtonView} is pressed.
197
- */
198
- private _onFindButtonExecute;
199
- /**
200
- * Configures an injects the find results counter displaying a "N of M" label of the {@link #_findInputView}.
201
- */
202
- private _injectFindResultsCounter;
203
- /**
204
- * Configures and returns the `<fieldset>` aggregating all replace controls.
205
- */
206
- private _createReplaceFieldset;
207
- /**
208
- * Creates, configures and returns and instance of a dropdown allowing users to narrow
209
- * the search criteria down. The dropdown has a list with switch buttons for each option.
210
- */
211
- private _createOptionsDropdown;
212
- /**
213
- * Initializes the {@link #_focusables} and {@link #_focusTracker} to allow navigation
214
- * using <kbd>Tab</kbd> and <kbd>Shift</kbd>+<kbd>Tab</kbd> keystrokes in the right order.
215
- */
216
- private _initFocusCycling;
217
- /**
218
- * Initializes the keystroke handling in the form.
219
- */
220
- private _initKeystrokeHandling;
221
- /**
222
- * Creates a button view.
223
- *
224
- * @param options The properties of the `ButtonView`.
225
- * @returns The button view instance.
226
- */
227
- private _createButton;
228
- /**
229
- * Creates a labeled input view.
230
- *
231
- * @param label The input label.
232
- * @returns The labeled input view instance.
233
- */
234
- private _createInputField;
235
- }
236
- /**
237
- * Fired when the find next button is triggered.
238
- *
239
- * @eventName ~FindAndReplaceFormView#findNext
240
- * @param data The event data.
241
- */
242
- export type FindNextEvent = {
243
- name: 'findNext';
244
- args: [data?: FindNextEventData];
245
- };
246
- export type FindNextEventData = FindEventBaseData & {
247
- matchCase: boolean;
248
- wholeWords: boolean;
249
- };
250
- /**
251
- * Fired when the find previous button is triggered.
252
- *
253
- * @eventName ~FindAndReplaceFormView#findPrevious
254
- * @param data The event data.
255
- */
256
- export type FindPreviousEvent = {
257
- name: 'findPrevious';
258
- args: [data?: FindEventBaseData];
259
- };
260
- /**
261
- * Base type for all find/replace events.
262
- */
263
- export type FindEventBaseData = {
264
- searchText: string;
265
- };
266
- /**
267
- * Fired when the replace button is triggered.
268
- *
269
- * @eventName ~FindAndReplaceFormView#replace
270
- * @param data The event data.
271
- */
272
- export type ReplaceEvent = {
273
- name: 'replace';
274
- args: [data: ReplaceEventData];
275
- };
276
- export type ReplaceEventData = FindEventBaseData & {
277
- replaceText: string;
278
- };
279
- /**
280
- * Fired when the replaceAll button is triggered.
281
- *
282
- * @eventName ~FindAndReplaceFormView#replaceAll
283
- * @param data The event data.
284
- */
285
- export type ReplaceAllEvent = {
286
- name: 'replaceAll';
287
- args: [data: ReplaceEventData];
288
- };
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 find-and-replace/ui/findandreplaceformview
7
+ */
8
+ import { View, LabeledFieldView, type InputView } from 'ckeditor5/src/ui';
9
+ import { type Locale } from 'ckeditor5/src/utils';
10
+ import '@ckeditor/ckeditor5-ui/theme/components/responsive-form/responsiveform.css';
11
+ import '../../theme/findandreplaceform.css';
12
+ /**
13
+ * The find and replace form view class.
14
+ *
15
+ * See {@link module:find-and-replace/ui/findandreplaceformview~FindAndReplaceFormView}.
16
+ */
17
+ export default class FindAndReplaceFormView extends View {
18
+ /**
19
+ * Stores the number of matched search results.
20
+ *
21
+ * @readonly
22
+ * @observable
23
+ */
24
+ matchCount: number;
25
+ /**
26
+ * The offset of currently highlighted search result in {@link #matchCount matched results}.
27
+ *
28
+ * @observable
29
+ */
30
+ readonly highlightOffset: number;
31
+ /**
32
+ * `true` when the search params (find text, options) has been changed by the user since
33
+ * the last time find was executed. `false` otherwise.
34
+ *
35
+ * @readonly
36
+ * @observable
37
+ */
38
+ isDirty: boolean;
39
+ /**
40
+ * A live object with the aggregated `isEnabled` states of editor commands related to find and
41
+ * replace. For instance, it may look as follows:
42
+ *
43
+ * ```json
44
+ * {
45
+ * findNext: true,
46
+ * findPrevious: true,
47
+ * replace: false,
48
+ * replaceAll: false
49
+ * }
50
+ * ```
51
+ *
52
+ * @internal
53
+ * @observable
54
+ */
55
+ readonly _areCommandsEnabled: Record<string, boolean>;
56
+ /**
57
+ * The content of the counter label displaying the index of the current highlighted match
58
+ * on top of the find input, for instance "3 of 50".
59
+ *
60
+ * @internal
61
+ * @readonly
62
+ * @observable
63
+ */
64
+ _resultsCounterText: string;
65
+ /**
66
+ * The flag reflecting the state of the "Match case" switch button in the search options
67
+ * dropdown.
68
+ *
69
+ * @internal
70
+ * @readonly
71
+ * @observable
72
+ */
73
+ _matchCase: boolean;
74
+ /**
75
+ * The flag reflecting the state of the "Whole words only" switch button in the search options
76
+ * dropdown.
77
+ *
78
+ * @internal
79
+ * @readonly
80
+ * @observable
81
+ */
82
+ _wholeWordsOnly: boolean;
83
+ /**
84
+ * This flag is set `true` when some matches were found and the user didn't change the search
85
+ * params (text to find, options) yet. This is only possible immediately after hitting the "Find" button.
86
+ * `false` when there were no matches (see {@link #matchCount}) or the user changed the params (see {@link #isDirty}).
87
+ *
88
+ * It is used to control the enabled state of the replace UI (input and buttons); replacing text is only possible
89
+ * if this flag is `true`.
90
+ *
91
+ * @internal
92
+ * @observable
93
+ */
94
+ readonly _searchResultsFound: boolean;
95
+ /**
96
+ * The find in text input view that stores the searched string.
97
+ *
98
+ * @internal
99
+ */
100
+ readonly _findInputView: LabeledFieldView<InputView>;
101
+ /**
102
+ * The replace input view.
103
+ */
104
+ private readonly _replaceInputView;
105
+ /**
106
+ * The find button view that initializes the search process.
107
+ */
108
+ private readonly _findButtonView;
109
+ /**
110
+ * The find previous button view.
111
+ */
112
+ private readonly _findPrevButtonView;
113
+ /**
114
+ * The find next button view.
115
+ */
116
+ private readonly _findNextButtonView;
117
+ /**
118
+ * The find options dropdown.
119
+ */
120
+ private readonly _optionsDropdown;
121
+ /**
122
+ * The replace button view.
123
+ */
124
+ private readonly _replaceButtonView;
125
+ /**
126
+ * The replace all button view.
127
+ */
128
+ private readonly _replaceAllButtonView;
129
+ /**
130
+ * The fieldset aggregating the find UI.
131
+ */
132
+ private readonly _findFieldsetView;
133
+ /**
134
+ * The fieldset aggregating the replace UI.
135
+ */
136
+ private readonly _replaceFieldsetView;
137
+ /**
138
+ * Tracks information about the DOM focus in the form.
139
+ */
140
+ private readonly _focusTracker;
141
+ /**
142
+ * An instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
143
+ */
144
+ private readonly _keystrokes;
145
+ /**
146
+ * A collection of views that can be focused in the form.
147
+ */
148
+ private readonly _focusables;
149
+ /**
150
+ * Helps cycling over {@link #_focusables} in the form.
151
+ */
152
+ private readonly _focusCycler;
153
+ locale: Locale;
154
+ /**
155
+ * Creates a view of find and replace form.
156
+ *
157
+ * @param locale The localization services instance.
158
+ */
159
+ constructor(locale: Locale);
160
+ /**
161
+ * @inheritDoc
162
+ */
163
+ render(): void;
164
+ /**
165
+ * @inheritDoc
166
+ */
167
+ destroy(): void;
168
+ /**
169
+ * Focuses the fist {@link #_focusables} in the form.
170
+ */
171
+ focus(): void;
172
+ /**
173
+ * Resets the form before re-appearing.
174
+ *
175
+ * It clears error messages, hides the match counter and disables the replace feature
176
+ * until the next hit of the "Find" button.
177
+ *
178
+ * **Note**: It does not reset inputs and options, though. This way the form works better in editors with
179
+ * disappearing toolbar (e.g. BalloonEditor): hiding the toolbar by accident (together with the find and replace UI)
180
+ * does not require filling the entire form again.
181
+ */
182
+ reset(): void;
183
+ /**
184
+ * Returns the value of the find input.
185
+ */
186
+ private get _textToFind();
187
+ /**
188
+ * Returns the value of the replace input.
189
+ */
190
+ private get _textToReplace();
191
+ /**
192
+ * Configures and returns the `<fieldset>` aggregating all find controls.
193
+ */
194
+ private _createFindFieldset;
195
+ /**
196
+ * The action performed when the {@link #_findButtonView} is pressed.
197
+ */
198
+ private _onFindButtonExecute;
199
+ /**
200
+ * Configures an injects the find results counter displaying a "N of M" label of the {@link #_findInputView}.
201
+ */
202
+ private _injectFindResultsCounter;
203
+ /**
204
+ * Configures and returns the `<fieldset>` aggregating all replace controls.
205
+ */
206
+ private _createReplaceFieldset;
207
+ /**
208
+ * Creates, configures and returns and instance of a dropdown allowing users to narrow
209
+ * the search criteria down. The dropdown has a list with switch buttons for each option.
210
+ */
211
+ private _createOptionsDropdown;
212
+ /**
213
+ * Initializes the {@link #_focusables} and {@link #_focusTracker} to allow navigation
214
+ * using <kbd>Tab</kbd> and <kbd>Shift</kbd>+<kbd>Tab</kbd> keystrokes in the right order.
215
+ */
216
+ private _initFocusCycling;
217
+ /**
218
+ * Initializes the keystroke handling in the form.
219
+ */
220
+ private _initKeystrokeHandling;
221
+ /**
222
+ * Creates a button view.
223
+ *
224
+ * @param options The properties of the `ButtonView`.
225
+ * @returns The button view instance.
226
+ */
227
+ private _createButton;
228
+ /**
229
+ * Creates a labeled input view.
230
+ *
231
+ * @param label The input label.
232
+ * @returns The labeled input view instance.
233
+ */
234
+ private _createInputField;
235
+ }
236
+ /**
237
+ * Fired when the find next button is triggered.
238
+ *
239
+ * @eventName ~FindAndReplaceFormView#findNext
240
+ * @param data The event data.
241
+ */
242
+ export type FindNextEvent = {
243
+ name: 'findNext';
244
+ args: [data?: FindNextEventData];
245
+ };
246
+ export type FindNextEventData = FindEventBaseData & {
247
+ matchCase: boolean;
248
+ wholeWords: boolean;
249
+ };
250
+ /**
251
+ * Fired when the find previous button is triggered.
252
+ *
253
+ * @eventName ~FindAndReplaceFormView#findPrevious
254
+ * @param data The event data.
255
+ */
256
+ export type FindPreviousEvent = {
257
+ name: 'findPrevious';
258
+ args: [data?: FindEventBaseData];
259
+ };
260
+ /**
261
+ * Base type for all find/replace events.
262
+ */
263
+ export type FindEventBaseData = {
264
+ searchText: string;
265
+ };
266
+ /**
267
+ * Fired when the replace button is triggered.
268
+ *
269
+ * @eventName ~FindAndReplaceFormView#replace
270
+ * @param data The event data.
271
+ */
272
+ export type ReplaceEvent = {
273
+ name: 'replace';
274
+ args: [data: ReplaceEventData];
275
+ };
276
+ export type ReplaceEventData = FindEventBaseData & {
277
+ replaceText: string;
278
+ };
279
+ /**
280
+ * Fired when the replaceAll button is triggered.
281
+ *
282
+ * @eventName ~FindAndReplaceFormView#replaceAll
283
+ * @param data The event data.
284
+ */
285
+ export type ReplaceAllEvent = {
286
+ name: 'replaceAll';
287
+ args: [data: ReplaceEventData];
288
+ };