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