@univerjs/find-replace 0.16.1 → 0.17.0-insiders.20260318-d69dc16

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 (82) hide show
  1. package/lib/cjs/index.js +4 -1
  2. package/lib/cjs/locale/ca-ES.js +1 -1
  3. package/lib/cjs/locale/en-US.js +1 -1
  4. package/lib/cjs/locale/es-ES.js +1 -1
  5. package/lib/cjs/locale/fa-IR.js +1 -1
  6. package/lib/cjs/locale/fr-FR.js +1 -1
  7. package/lib/cjs/locale/ja-JP.js +1 -1
  8. package/lib/cjs/locale/ko-KR.js +1 -1
  9. package/lib/cjs/locale/ru-RU.js +1 -1
  10. package/lib/cjs/locale/sk-SK.js +1 -1
  11. package/lib/cjs/locale/vi-VN.js +1 -1
  12. package/lib/cjs/locale/zh-CN.js +1 -1
  13. package/lib/cjs/locale/zh-TW.js +1 -1
  14. package/lib/es/index.js +4 -959
  15. package/lib/es/locale/ca-ES.js +1 -52
  16. package/lib/es/locale/en-US.js +1 -52
  17. package/lib/es/locale/es-ES.js +1 -52
  18. package/lib/es/locale/fa-IR.js +1 -52
  19. package/lib/es/locale/fr-FR.js +1 -52
  20. package/lib/es/locale/ja-JP.js +1 -52
  21. package/lib/es/locale/ko-KR.js +1 -52
  22. package/lib/es/locale/ru-RU.js +1 -52
  23. package/lib/es/locale/sk-SK.js +1 -52
  24. package/lib/es/locale/vi-VN.js +1 -52
  25. package/lib/es/locale/zh-CN.js +1 -52
  26. package/lib/es/locale/zh-TW.js +1 -52
  27. package/lib/index.css +54 -1
  28. package/lib/index.js +4 -959
  29. package/lib/locale/ca-ES.js +1 -52
  30. package/lib/locale/en-US.js +1 -52
  31. package/lib/locale/es-ES.js +1 -52
  32. package/lib/locale/fa-IR.js +1 -52
  33. package/lib/locale/fr-FR.js +1 -52
  34. package/lib/locale/ja-JP.js +1 -52
  35. package/lib/locale/ko-KR.js +1 -52
  36. package/lib/locale/ru-RU.js +1 -52
  37. package/lib/locale/sk-SK.js +1 -52
  38. package/lib/locale/vi-VN.js +1 -52
  39. package/lib/locale/zh-CN.js +1 -52
  40. package/lib/locale/zh-TW.js +1 -52
  41. package/lib/types/commands/commands/replace.command.d.ts +16 -1
  42. package/lib/types/commands/operations/find-replace.operation.d.ts +16 -1
  43. package/lib/types/config/config.d.ts +22 -0
  44. package/lib/types/controllers/find-replace.controller.d.ts +15 -0
  45. package/lib/types/controllers/find-replace.shortcut.d.ts +16 -1
  46. package/lib/types/index.d.ts +1 -1
  47. package/lib/types/locale/ca-ES.d.ts +16 -1
  48. package/lib/types/locale/es-ES.d.ts +16 -1
  49. package/lib/types/locale/fa-IR.d.ts +16 -1
  50. package/lib/types/locale/fr-FR.d.ts +16 -1
  51. package/lib/types/locale/ja-JP.d.ts +16 -1
  52. package/lib/types/locale/ko-KR.d.ts +16 -1
  53. package/lib/types/locale/ru-RU.d.ts +16 -1
  54. package/lib/types/locale/sk-SK.d.ts +16 -1
  55. package/lib/types/locale/vi-VN.d.ts +16 -1
  56. package/lib/types/locale/zh-CN.d.ts +16 -1
  57. package/lib/types/locale/zh-TW.d.ts +16 -1
  58. package/lib/types/menu/find-replace.menu.d.ts +18 -0
  59. package/lib/types/menu/schema.d.ts +17 -0
  60. package/lib/types/plugin.d.ts +18 -1
  61. package/lib/types/services/find-replace.service.d.ts +20 -3
  62. package/lib/types/views/dialog/FindReplaceDialog.d.ts +2 -2
  63. package/lib/types/views/dialog/FindReplaceDialog.stories.d.ts +16 -1
  64. package/lib/types/views/dialog/SearchInput.d.ts +18 -3
  65. package/lib/umd/index.js +4 -1
  66. package/lib/umd/locale/ca-ES.js +1 -1
  67. package/lib/umd/locale/en-US.js +1 -1
  68. package/lib/umd/locale/es-ES.js +1 -1
  69. package/lib/umd/locale/fa-IR.js +1 -1
  70. package/lib/umd/locale/fr-FR.js +1 -1
  71. package/lib/umd/locale/ja-JP.js +1 -1
  72. package/lib/umd/locale/ko-KR.js +1 -1
  73. package/lib/umd/locale/ru-RU.js +1 -1
  74. package/lib/umd/locale/sk-SK.js +1 -1
  75. package/lib/umd/locale/vi-VN.js +1 -1
  76. package/lib/umd/locale/zh-CN.js +1 -1
  77. package/lib/umd/locale/zh-TW.js +1 -1
  78. package/package.json +11 -10
  79. package/LICENSE +0 -176
  80. package/lib/types/controllers/config.schema.d.ts +0 -7
  81. package/lib/types/controllers/find-replace.menu.d.ts +0 -3
  82. package/lib/types/controllers/menu.schema.d.ts +0 -2
package/lib/es/index.js CHANGED
@@ -1,959 +1,4 @@
1
- var st = Object.defineProperty;
2
- var rt = (t, e, n) => e in t ? st(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
- var o = (t, e, n) => rt(t, typeof e != "symbol" ? e + "" : e, n);
4
- import { createIdentifier as at, Inject as $, Injector as ue, IContextService as J, Disposable as Q, DisposableCollection as ot, toDisposable as O, IUniverInstanceService as fe, ICommandService as U, CommandType as b, IConfirmService as ct, LocaleService as B, FOCUSING_SHEET as pe, EDITOR_ACTIVATED as _e, UniverInstanceType as lt, RxDisposable as dt, IConfigService as ht, Plugin as ut, merge as ft } from "@univerjs/core";
5
- import { MessageType as N, Input as ge, Pager as pt, FormLayout as R, Select as k, FormDualColumnLayout as re, Checkbox as ae, Button as j } from "@univerjs/design";
6
- import { IMessageService as me, useDependency as m, useObservable as P, useDebounceFn as _t, ILayoutService as Se, KeyCode as C, MetaKeys as D, getMenuHiddenObservable as gt, MenuItemType as mt, RibbonDataGroup as St, IMenuManagerService as vt, IShortcutService as Ct, IDialogService as Mt, ComponentManager as Rt } from "@univerjs/ui";
7
- import { RENDER_RAW_FORMULA_KEY as bt } from "@univerjs/engine-render";
8
- import { throttleTime as It, BehaviorSubject as T, combineLatest as ve, debounceTime as Ft, Subject as Ce, fromEvent as Dt, map as yt, takeUntil as oe } from "rxjs";
9
- import { useRef as G, createElement as Me, forwardRef as X, useState as Pt, useCallback as u, useEffect as A, useMemo as ee, useImperativeHandle as Tt } from "react";
10
- import { jsx as c, jsxs as F, Fragment as H } from "react/jsx-runtime";
11
- const Re = "FIND_REPLACE_INPUT_FOCUS", be = "FIND_REPLACE_DIALOG_FOCUS", Ie = "FIND_REPLACE_REPLACE_REVEALED";
12
- var xt = Object.getOwnPropertyDescriptor, Fe = (t, e, n, i) => {
13
- for (var s = i > 1 ? void 0 : i ? xt(e, n) : e, r = t.length - 1, a; r >= 0; r--)
14
- (a = t[r]) && (s = a(s) || s);
15
- return s;
16
- }, L = (t, e) => (n, i) => e(n, i, t);
17
- class gi extends Q {
18
- }
19
- const f = at("find-replace.service");
20
- function Et(t) {
21
- return typeof t.findString < "u" || typeof t.inputtingFindString < "u" || typeof t.findDirection < "u" || typeof t.matchesTheWholeCell < "u" || typeof t.caseSensitive < "u" || typeof t.findScope < "u" || typeof t.findBy < "u";
22
- }
23
- let K = class extends Q {
24
- constructor(e, n, i, s) {
25
- super();
26
- o(this, "currentMatch$", new T(null));
27
- o(this, "replaceables$", new T([]));
28
- /** All find models returned by providers. */
29
- o(this, "_findModels", []);
30
- /** The find model that the current match is from. */
31
- o(this, "_matchingModel", null);
32
- o(this, "_matches", []);
33
- o(this, "_currentSearchingDisposables", null);
34
- this._state = e, this._providers = n, this._univerInstanceService = i, this._commandService = s, this.disposeWithMe(
35
- this._state.stateUpdates$.pipe(It(200, void 0, { leading: !0, trailing: !0 })).subscribe(async (r) => {
36
- const a = this._state.state;
37
- Et(r) && (a.findString !== "" && !a.replaceRevealed ? (await this._startSearching(), this._state.changeState({ findCompleted: !0 })) : r.replaceRevealed !== !0 && this._stopSearching());
38
- })
39
- );
40
- }
41
- get searched() {
42
- return this._findModels.length > 0;
43
- }
44
- dispose() {
45
- super.dispose(), this._stopSearching(), this.currentMatch$.complete(), this.replaceables$.complete(), this._state.changeState({ ...te(), revealed: !1 });
46
- }
47
- async start() {
48
- if (!this._state.findString)
49
- return { results: [] };
50
- const e = await this._startSearching();
51
- return this._state.changeState({ findCompleted: !0 }), e;
52
- }
53
- focusSelection() {
54
- var e;
55
- (e = this._matchingModel) == null || e.focusSelection();
56
- }
57
- /** Call this method to start a `searching`. */
58
- async _startSearching() {
59
- if (!this._state.findString)
60
- return { results: [] };
61
- const e = Array.from(this._providers), n = this._findModels = (await Promise.all(e.map((s) => s.find({
62
- findString: this._state.findString,
63
- findDirection: this._state.findDirection,
64
- findScope: this._state.findScope,
65
- findBy: this._state.findBy,
66
- replaceRevealed: this._state.replaceRevealed,
67
- caseSensitive: this._state.caseSensitive,
68
- matchesTheWholeCell: this._state.matchesTheWholeCell
69
- })))).flat();
70
- this._subscribeToModelsChanges(n);
71
- const i = this._matches = n.map((s) => s.getMatches()).flat();
72
- return this.replaceables$.next(i.filter((s) => s.replaceable)), i.length ? (this._moveToInitialMatch(n), this._state.changeState({ matchesCount: i.length }), { results: i }) : (this._state.changeState({ matchesCount: 0, matchesPosition: 0 }), { results: [] });
73
- }
74
- /** Terminate the current searching session, when searching string is empty. */
75
- _stopSearching() {
76
- var e;
77
- this._providers.forEach((n) => n.terminate()), this._findModels = [], this._matches = [], this._matchingModel = null, (e = this._currentSearchingDisposables) == null || e.dispose(), this._currentSearchingDisposables = null, this.currentMatch$.next(null), this.replaceables$.next([]), this._state.changeState({
78
- findCompleted: !1,
79
- matchesCount: 0,
80
- matchesPosition: 0
81
- });
82
- }
83
- // When a document's content changes, we should reset all matches and try to move to the next match.
84
- _subscribeToModelsChanges(e) {
85
- const n = this._currentSearchingDisposables = new ot(), i = ve(e.map((s) => s.matchesUpdate$)).pipe(Ft(220)).subscribe(([...s]) => {
86
- const r = this._matches = s.flat();
87
- r.length ? (this._moveToInitialMatch(this._findModels, !0), this._state.changeState({ matchesCount: r.length }), this.replaceables$.next(r.filter((a) => a.replaceable))) : (this._state.changeState({ matchesCount: 0, matchesPosition: 0 }), this.replaceables$.next([]));
88
- });
89
- e.forEach((s) => n.add(O(s.activelyChangingMatch$.subscribe((r) => {
90
- const a = this._matches.findIndex((l) => l === r);
91
- this._state.changeState({ matchesPosition: a + 1 });
92
- })))), n.add(O(i));
93
- }
94
- async replace() {
95
- return this._matchingModel ? this._matchingModel.replace(this._state.replaceString) : !1;
96
- }
97
- async replaceAll() {
98
- const e = await Promise.all(this._findModels.map((n) => n.replaceAll(this._state.replaceString))).then((n) => n.reduce((i, s) => (i.success += s.success, i.failure += s.failure, i), { success: 0, failure: 0 }));
99
- return e.failure === 0 && this._stopSearching(), e;
100
- }
101
- getCurrentMatch() {
102
- return this._state.matchesPosition > 0 ? this._matches[this._state.matchesPosition - 1] : null;
103
- }
104
- _markMatch(e) {
105
- const n = this._matches.findIndex((i) => i === e);
106
- this.currentMatch$.next(e), this._state.changeState({ matchesPosition: n + 1 });
107
- }
108
- moveToNextMatch() {
109
- if (!this._matchingModel)
110
- return;
111
- const e = this._findModels.length === 1, n = this._matchingModel.moveToNextMatch({ loop: e });
112
- if (n)
113
- return this._markMatch(n), n;
114
- {
115
- const i = this._findModels.findIndex((s) => s === this._matchingModel);
116
- return this._moveToNextUnitMatch(i);
117
- }
118
- }
119
- _moveToNextUnitMatch(e) {
120
- const n = this._findModels.length;
121
- for (let i = (e + 1) % n; i !== e; ) {
122
- const s = this._findModels[i], r = s.moveToNextMatch({ ignoreSelection: !0 });
123
- if (r)
124
- return this._matchingModel = s, this._markMatch(r), r;
125
- i = (i + 1) % n;
126
- }
127
- if (this._matchingModel) {
128
- const i = this._matchingModel.moveToNextMatch({ ignoreSelection: !0 });
129
- return i && this._markMatch(i), i;
130
- }
131
- }
132
- moveToPreviousMatch() {
133
- if (!this._matchingModel)
134
- return;
135
- const e = this._findModels.length === 1, n = this._matchingModel.moveToPreviousMatch({ loop: e });
136
- if (n) {
137
- const i = this._matches.findIndex((s) => s === n);
138
- return this.currentMatch$.next(n), this._state.changeState({ matchesPosition: i + 1 }), n;
139
- } else {
140
- const i = this._findModels.length, s = this._findModels.findIndex((a) => a === this._matchingModel);
141
- for (let a = (s - 1 + i) % i; a !== s; ) {
142
- const l = this._findModels[a], d = l.moveToPreviousMatch({ ignoreSelection: !0 });
143
- if (d)
144
- return this._matchingModel = l, this._markMatch(d), d;
145
- a = (a - 1) % i;
146
- }
147
- const r = this._matchingModel.moveToPreviousMatch({ ignoreSelection: !0 });
148
- return r && this._markMatch(r), r;
149
- }
150
- }
151
- _moveToInitialMatch(e, n = !1) {
152
- var r;
153
- const i = (r = this._univerInstanceService.getFocusedUnit()) == null ? void 0 : r.getUnitId();
154
- if (!i)
155
- return -1;
156
- const s = e.findIndex((a) => a.unitId === i);
157
- if (s !== -1) {
158
- this._matchingModel = e[s];
159
- const a = this._matchingModel.moveToNextMatch({ stayIfOnMatch: !0, noFocus: n });
160
- if (a)
161
- return this._markMatch(a), s;
162
- }
163
- return this._moveToNextUnitMatch(s), 0;
164
- }
165
- };
166
- K = Fe([
167
- L(2, fe),
168
- L(3, U)
169
- ], K);
170
- var q = /* @__PURE__ */ ((t) => (t.ROW = "row", t.COLUMN = "column", t))(q || {}), Z = /* @__PURE__ */ ((t) => (t.VALUE = "value", t.FORMULA = "formula", t))(Z || {}), z = /* @__PURE__ */ ((t) => (t.SUBUNIT = "subunit", t.UNIT = "unit", t))(z || {});
171
- function te() {
172
- return {
173
- caseSensitive: !1,
174
- findBy: "value",
175
- findCompleted: !1,
176
- findDirection: "row",
177
- findScope: "subunit",
178
- findString: "",
179
- inputtingFindString: "",
180
- matchesCount: 0,
181
- matchesPosition: 0,
182
- matchesTheWholeCell: !1,
183
- replaceRevealed: !1,
184
- replaceString: "",
185
- revealed: !0
186
- };
187
- }
188
- class Nt {
189
- constructor() {
190
- o(this, "_stateUpdates$", new Ce());
191
- o(this, "stateUpdates$", this._stateUpdates$.asObservable());
192
- o(this, "_state$", new T(te()));
193
- o(this, "state$", this._state$.asObservable());
194
- o(this, "_findString", "");
195
- o(this, "_inputtingFindString", "");
196
- o(this, "_replaceString", "");
197
- o(this, "_revealed", !1);
198
- o(this, "_replaceRevealed", !1);
199
- o(this, "_matchesPosition", 0);
200
- o(this, "_matchesCount", 0);
201
- o(this, "_caseSensitive", !0);
202
- o(this, "_matchesTheWholeCell", !1);
203
- o(this, "_findDirection", "row");
204
- o(this, "_findScope", "subunit");
205
- o(this, "_findBy", "value");
206
- o(this, "_findCompleted", !1);
207
- }
208
- get state() {
209
- return this._state$.getValue();
210
- }
211
- get inputtingFindString() {
212
- return this._inputtingFindString;
213
- }
214
- get findString() {
215
- return this._findString;
216
- }
217
- get revealed() {
218
- return this._revealed;
219
- }
220
- get replaceRevealed() {
221
- return this._replaceRevealed;
222
- }
223
- get matchesPosition() {
224
- return this._matchesPosition;
225
- }
226
- get matchesCount() {
227
- return this._matchesCount;
228
- }
229
- get replaceString() {
230
- return this._replaceString;
231
- }
232
- get caseSensitive() {
233
- return this._caseSensitive;
234
- }
235
- get matchesTheWholeCell() {
236
- return this._matchesTheWholeCell;
237
- }
238
- get findDirection() {
239
- return this._findDirection;
240
- }
241
- get findScope() {
242
- return this._findScope;
243
- }
244
- get findBy() {
245
- return this._findBy;
246
- }
247
- get findCompleted() {
248
- return this._findCompleted;
249
- }
250
- // eslint-disable-next-line max-lines-per-function, complexity
251
- changeState(e) {
252
- let n = !1;
253
- const i = {};
254
- typeof e.findString < "u" && e.findString !== this._findString && (this._findString = e.findString, i.findString = this._findString, n = !0), typeof e.revealed < "u" && e.revealed !== this._revealed && (this._revealed = e.revealed, i.revealed = e.revealed, n = !0), typeof e.replaceRevealed < "u" && e.replaceRevealed !== this._replaceRevealed && (this._replaceRevealed = e.replaceRevealed, i.replaceRevealed = e.replaceRevealed, n = !0), typeof e.replaceString < "u" && e.replaceString !== this._replaceString && (this._replaceString = e.replaceString, i.replaceString = e.replaceString, n = !0), typeof e.matchesCount < "u" && e.matchesCount !== this._matchesCount && (this._matchesCount = e.matchesCount, i.matchesCount = e.matchesCount, n = !0), typeof e.matchesPosition < "u" && e.matchesPosition !== this._matchesPosition && (this._matchesPosition = e.matchesPosition, i.matchesPosition = e.matchesPosition, n = !0), typeof e.findBy < "u" && e.findBy !== this._findBy && (this._findBy = e.findBy, i.findBy = e.findBy, n = !0), typeof e.findScope < "u" && e.findScope !== this._findScope && (this._findScope = e.findScope, i.findScope = e.findScope, n = !0), typeof e.findDirection < "u" && e.findDirection !== this._findDirection && (this._findDirection = e.findDirection, i.findDirection = e.findDirection, n = !0), typeof e.caseSensitive < "u" && e.caseSensitive !== this._caseSensitive && (this._caseSensitive = e.caseSensitive, i.caseSensitive = e.caseSensitive, n = !0), typeof e.matchesTheWholeCell < "u" && e.matchesTheWholeCell !== this._matchesTheWholeCell && (this._matchesTheWholeCell = e.matchesTheWholeCell, i.matchesTheWholeCell = e.matchesTheWholeCell, n = !0), typeof e.inputtingFindString < "u" && e.inputtingFindString !== this._inputtingFindString && (this._inputtingFindString = e.inputtingFindString, i.inputtingFindString = e.inputtingFindString, n = !0), typeof e.findCompleted < "u" && e.findCompleted !== this._findCompleted && (this._findCompleted = e.findCompleted, i.findCompleted = e.findCompleted, n = !0), n && (this._state$.next({
255
- caseSensitive: this._caseSensitive,
256
- findBy: this._findBy,
257
- findCompleted: this._findCompleted,
258
- findDirection: this._findDirection,
259
- findScope: this._findScope,
260
- findString: this._findString,
261
- inputtingFindString: this._inputtingFindString,
262
- matchesCount: this._matchesCount,
263
- matchesPosition: this._matchesPosition,
264
- matchesTheWholeCell: this._matchesTheWholeCell,
265
- replaceRevealed: this._replaceRevealed,
266
- revealed: this._revealed
267
- }), this._stateUpdates$.next(i));
268
- }
269
- }
270
- let Y = class extends Q {
271
- constructor(e, n) {
272
- super();
273
- o(this, "_providers", /* @__PURE__ */ new Set());
274
- o(this, "_state", new Nt());
275
- o(this, "_model");
276
- o(this, "_currentMatch$", new T(null));
277
- o(this, "currentMatch$", this._currentMatch$.asObservable());
278
- o(this, "_replaceables$", new T([]));
279
- o(this, "replaceables$", this._replaceables$.asObservable());
280
- o(this, "_focusSignal$", new Ce());
281
- o(this, "focusSignal$", this._focusSignal$.asObservable());
282
- this._injector = e, this._contextService = n;
283
- }
284
- get stateUpdates$() {
285
- return this._state.stateUpdates$;
286
- }
287
- get state$() {
288
- return this._state.state$;
289
- }
290
- get revealed() {
291
- return this._state.revealed;
292
- }
293
- get replaceRevealed() {
294
- return this._state.replaceRevealed;
295
- }
296
- dispose() {
297
- super.dispose(), this._currentMatch$.next(null), this._currentMatch$.complete(), this._replaceables$.next([]), this._replaceables$.complete(), this._focusSignal$.complete();
298
- }
299
- getProviders() {
300
- return this._providers;
301
- }
302
- getCurrentMatch() {
303
- var e;
304
- return (e = this._model) == null ? void 0 : e.getCurrentMatch();
305
- }
306
- getFindString() {
307
- return this._state.findString;
308
- }
309
- changeFindString(e) {
310
- this._state.changeState({ findString: e });
311
- }
312
- focusFindInput() {
313
- this._focusSignal$.next();
314
- }
315
- changeInputtingFindString(e) {
316
- e ? this._state.changeState({ inputtingFindString: e }) : this._state.changeState({ inputtingFindString: "", findString: "" });
317
- }
318
- changeReplaceString(e) {
319
- this._state.changeState({ replaceString: e });
320
- }
321
- changeMatchesTheWholeCell(e) {
322
- this._state.changeState({ matchesTheWholeCell: e });
323
- }
324
- changeCaseSensitive(e) {
325
- this._state.changeState({ caseSensitive: e });
326
- }
327
- changeFindBy(e) {
328
- this._state.changeState({ findBy: e }), this._toggleDisplayRawFormula(
329
- e === "formula"
330
- /* FORMULA */
331
- );
332
- }
333
- changeFindScope(e) {
334
- this._state.changeState({ findScope: e });
335
- }
336
- changeFindDirection(e) {
337
- this._state.changeState({ findDirection: e });
338
- }
339
- moveToNextMatch() {
340
- this._model && (this._state.replaceRevealed && !this._model.searched ? (this._state.changeState({ findString: this._state.inputtingFindString }), this._model.start()) : this._model.moveToNextMatch(), this._focusSignal$.next());
341
- }
342
- moveToPreviousMatch() {
343
- this._model && (this._state.replaceRevealed && !this._model.searched ? (this._state.changeState({ findString: this._state.inputtingFindString }), this._model.start()) : this._model.moveToPreviousMatch(), this._focusSignal$.next());
344
- }
345
- async replace() {
346
- return this._model ? this._model.replace() : !1;
347
- }
348
- async replaceAll() {
349
- if (!this._model)
350
- throw new Error("[FindReplaceService] replaceAll: model is not initialized!");
351
- return this._model.replaceAll();
352
- }
353
- revealReplace() {
354
- this._state.changeState({ replaceRevealed: !0, inputtingFindString: this._state.findString }), this._toggleRevealReplace(!0);
355
- }
356
- focusSelection() {
357
- var e;
358
- (e = this._model) == null || e.focusSelection();
359
- }
360
- start(e = !1) {
361
- if (this._providers.size === 0)
362
- return !1;
363
- this._model = this._injector.createInstance(K, this._state, this._providers), this._model.currentMatch$.subscribe((i) => this._currentMatch$.next(i)), this._model.replaceables$.subscribe((i) => this._replaceables$.next(i));
364
- const n = te();
365
- return e && (n.replaceRevealed = !0), this._state.changeState(n), this._toggleRevealReplace(e), !0;
366
- }
367
- find() {
368
- var e;
369
- (e = this._model) == null || e.start();
370
- }
371
- terminate() {
372
- var e;
373
- (e = this._model) == null || e.dispose(), this._model = null, this._toggleDisplayRawFormula(!1), this._toggleRevealReplace(!1);
374
- }
375
- registerFindReplaceProvider(e) {
376
- return this._providers.add(e), O(() => this._providers.delete(e));
377
- }
378
- _toggleRevealReplace(e) {
379
- this._contextService.setContextValue(Ie, e);
380
- }
381
- _toggleDisplayRawFormula(e) {
382
- this._contextService.setContextValue(bt, e);
383
- }
384
- };
385
- Y = Fe([
386
- L(0, $(ue)),
387
- L(1, J)
388
- ], Y);
389
- const De = {
390
- id: "ui.command.replace-current-match",
391
- type: b.COMMAND,
392
- handler: (t) => t.get(f).replace()
393
- }, $t = "CONFIRM_REPLACE_ALL", ye = {
394
- id: "ui.command.replace-all-matches",
395
- type: b.COMMAND,
396
- handler: async (t) => {
397
- const e = t.get(ct), n = t.get(B), i = t.get(me);
398
- if (!await e.confirm({
399
- id: $t,
400
- title: { title: n.t("find-replace.replace.confirm.title") },
401
- cancelText: n.t("button.cancel"),
402
- confirmText: n.t("button.confirm")
403
- }))
404
- return !1;
405
- const r = await t.get(f).replaceAll(), { success: a, failure: l } = r;
406
- return l > 0 ? (a === 0 ? i.show({
407
- type: N.Error,
408
- content: n.t("find-replace.replace.all-failure")
409
- }) : i.show({
410
- type: N.Warning,
411
- content: n.t("find-replace.replace.partial-success", `${a}`, `${l}`)
412
- }), !1) : (i.show({
413
- type: N.Success,
414
- content: n.t("find-replace.replace.all-success", `${a}`)
415
- }), !0);
416
- }
417
- }, x = {
418
- id: "ui.operation.open-find-dialog",
419
- type: b.OPERATION,
420
- handler: (t) => {
421
- const e = t.get(f);
422
- return e.revealed ? e.focusFindInput() : e.start(), !0;
423
- }
424
- }, ie = {
425
- id: "ui.operation.open-replace-dialog",
426
- type: b.OPERATION,
427
- handler: (t) => {
428
- const e = t.get(f);
429
- return e.revealed ? e.replaceRevealed ? e.focusFindInput() : e.revealReplace() : e.start(!0), !0;
430
- }
431
- }, Pe = {
432
- type: b.OPERATION,
433
- id: "ui.operation.go-to-next-match",
434
- handler: (t) => (t.get(f).moveToNextMatch(), !0)
435
- }, Te = {
436
- type: b.OPERATION,
437
- id: "ui.operation.go-to-previous-match",
438
- handler: (t) => (t.get(f).moveToPreviousMatch(), !0)
439
- }, xe = {
440
- type: b.OPERATION,
441
- id: "ui.operation.focus-selection",
442
- handler: (t) => (t.get(f).focusSelection(), !0)
443
- };
444
- function Ee({ ref: t, ...e }) {
445
- const { icon: n, id: i, className: s, extend: r, ...a } = e, l = `univerjs-icon univerjs-icon-${i} ${s || ""}`.trim(), d = G(`_${Lt()}`);
446
- return Ne(n, `${i}`, {
447
- defIds: n.defIds,
448
- idSuffix: d.current
449
- }, {
450
- ref: t,
451
- className: l,
452
- ...a
453
- }, r);
454
- }
455
- function Ne(t, e, n, i, s) {
456
- return Me(t.tag, {
457
- key: e,
458
- ...Ot(t, n, s),
459
- ...i
460
- }, (At(t, n).children || []).map((r, a) => Ne(r, `${e}-${t.tag}-${a}`, n, void 0, s)));
461
- }
462
- function Ot(t, e, n) {
463
- const i = { ...t.attrs };
464
- n != null && n.colorChannel1 && i.fill === "colorChannel1" && (i.fill = n.colorChannel1), t.tag === "mask" && i.id && (i.id = i.id + e.idSuffix), Object.entries(i).forEach(([r, a]) => {
465
- r === "mask" && typeof a == "string" && (i[r] = a.replace(/url\(#(.*)\)/, `url(#$1${e.idSuffix})`));
466
- });
467
- const { defIds: s } = e;
468
- return !s || s.length === 0 || (t.tag === "use" && i["xlink:href"] && (i["xlink:href"] = i["xlink:href"] + e.idSuffix), Object.entries(i).forEach(([r, a]) => {
469
- typeof a == "string" && (i[r] = a.replace(/url\(#(.*)\)/, `url(#$1${e.idSuffix})`));
470
- })), i;
471
- }
472
- function At(t, e) {
473
- var i;
474
- const { defIds: n } = e;
475
- return !n || n.length === 0 ? t : t.tag === "defs" && ((i = t.children) != null && i.length) ? {
476
- ...t,
477
- children: t.children.map((s) => typeof s.attrs.id == "string" && n && n.includes(s.attrs.id) ? {
478
- ...s,
479
- attrs: {
480
- ...s.attrs,
481
- id: s.attrs.id + e.idSuffix
482
- }
483
- } : s)
484
- } : t;
485
- }
486
- function Lt() {
487
- return Math.random().toString(36).substring(2, 8);
488
- }
489
- Ee.displayName = "UniverIcon";
490
- const wt = {
491
- tag: "svg",
492
- attrs: {
493
- xmlns: "http://www.w3.org/2000/svg",
494
- fill: "none",
495
- viewBox: "0 0 16 16",
496
- width: "1em",
497
- height: "1em"
498
- },
499
- children: [{
500
- tag: "path",
501
- attrs: {
502
- fill: "currentColor",
503
- d: "M7.71899 1.36938C4.37604 1.36938 1.66602 4.07941 1.66602 7.42236C1.66602 10.7653 4.37604 13.4753 7.71899 13.4753C9.16744 13.4753 10.4971 12.9666 11.5389 12.118L13.6598 14.4109C13.8848 14.6542 14.2644 14.669 14.5077 14.444C14.7509 14.219 14.7657 13.8393 14.5407 13.5961L12.3906 11.2716C13.2536 10.2254 13.772 8.88442 13.772 7.42236C13.772 4.07941 11.0619 1.36938 7.71899 1.36938ZM2.86602 7.42236C2.86602 4.74215 5.03878 2.56938 7.71899 2.56938C10.3992 2.56938 12.572 4.74215 12.572 7.42236C12.572 10.1026 10.3992 12.2753 7.71899 12.2753C5.03878 12.2753 2.86602 10.1026 2.86602 7.42236Z",
504
- fillRule: "evenodd",
505
- clipRule: "evenodd"
506
- }
507
- }]
508
- }, $e = X(function(e, n) {
509
- return Me(Ee, Object.assign({}, e, {
510
- id: "search-icon",
511
- ref: n,
512
- icon: wt
513
- }));
514
- });
515
- $e.displayName = "SearchIcon";
516
- function Oe(t) {
517
- const {
518
- findCompleted: e,
519
- localeService: n,
520
- matchesCount: i,
521
- matchesPosition: s,
522
- initialFindString: r,
523
- findReplaceService: a,
524
- onChange: l,
525
- ...d
526
- } = t, [_, p] = Pt(r), I = e && i === 0 ? n.t("find-replace.dialog.no-result") : i === 0 ? " " : void 0;
527
- function S(g) {
528
- s === i && g === 1 ? a.moveToNextMatch() : s === 1 && g === i || g < s ? a.moveToPreviousMatch() : a.moveToNextMatch();
529
- }
530
- return /* @__PURE__ */ c("div", { className: "univer-relative univer-flex univer-items-center univer-gap-2", onDrag: (g) => g.stopPropagation(), children: /* @__PURE__ */ c(
531
- ge,
532
- {
533
- "data-u-comp": "search-input",
534
- autoFocus: !0,
535
- placeholder: n.t("find-replace.dialog.find-placeholder"),
536
- value: _,
537
- onChange: (g) => {
538
- p(g), l == null || l(g);
539
- },
540
- slot: /* @__PURE__ */ c(
541
- pt,
542
- {
543
- loop: !0,
544
- text: I,
545
- value: s,
546
- total: i,
547
- onChange: S
548
- }
549
- ),
550
- ...d
551
- }
552
- ) });
553
- }
554
- function Ae(t, e) {
555
- const n = u(() => {
556
- var s;
557
- (s = document.querySelector(".univer-find-input input")) == null || s.focus();
558
- }, []), i = u(() => {
559
- const s = document.querySelectorAll("[data-u-comp=find-replace-dialog] [data-u-comp=search-input]");
560
- return Array.from(s).some((r) => r === document.activeElement);
561
- }, []);
562
- return Tt(e, () => ({ focus: n, selectHasFocus: i })), A(() => {
563
- const s = t.focusSignal$.subscribe(() => n());
564
- return () => s.unsubscribe();
565
- }, [t, n]), { focus: n, selectHasFocus: i };
566
- }
567
- const Ut = X(function(e, n) {
568
- const i = m(B), s = m(f), r = m(U), a = P(s.state$, void 0, !0), { findCompleted: l, findString: d, matchesCount: _, matchesPosition: p } = a, M = u(() => {
569
- r.executeCommand(ie.id);
570
- }, [r]), I = _t((S) => s.changeFindString(S), 500);
571
- return Ae(s, n), /* @__PURE__ */ F(H, { children: [
572
- /* @__PURE__ */ c(
573
- Oe,
574
- {
575
- findCompleted: l,
576
- matchesCount: _,
577
- matchesPosition: p,
578
- findReplaceService: s,
579
- localeService: i,
580
- initialFindString: d,
581
- onChange: I
582
- }
583
- ),
584
- /* @__PURE__ */ c("div", { className: "univer-mt-4 univer-text-center", children: /* @__PURE__ */ c(
585
- "a",
586
- {
587
- className: "hover:univer-text-primary-500/80 univer-cursor-pointer univer-text-sm univer-text-primary-500 univer-transition-colors",
588
- onClick: M,
589
- children: i.t("find-replace.dialog.advanced-finding")
590
- }
591
- ) })
592
- ] });
593
- }), Bt = X(function(e, n) {
594
- const i = m(f), s = m(B), r = m(U), a = m(me), l = P(i.currentMatch$, void 0, !0), d = P(i.replaceables$, void 0, !0), _ = P(i.state$, void 0, !0), {
595
- matchesCount: p,
596
- matchesPosition: M,
597
- findString: I,
598
- inputtingFindString: S,
599
- replaceString: g,
600
- caseSensitive: Ue,
601
- matchesTheWholeCell: Be,
602
- findDirection: We,
603
- findScope: ke,
604
- findBy: je,
605
- findCompleted: W
606
- } = _, Ve = S.length === 0, Ge = p === 0 || !(l != null && l.replaceable), He = d.length === 0, Ke = u(
607
- (h) => i.changeInputtingFindString(h),
608
- [i]
609
- ), qe = u(
610
- (h) => i.changeReplaceString(h),
611
- [i]
612
- ), { focus: Ze } = Ae(i, n), ze = u(() => {
613
- I === S ? i.moveToNextMatch() : (i.changeFindString(S), i.find());
614
- }, [I, S, i]), Ye = u(() => r.executeCommand(De.id), [r]), Je = u(async () => {
615
- await r.executeCommand(ye.id), Ze();
616
- }, [r]), Qe = u((h) => {
617
- i.changeFindDirection(h);
618
- }, [i]), Xe = u((h) => {
619
- i.changeFindScope(h);
620
- }, [i]), et = u((h) => {
621
- i.changeFindBy(h);
622
- }, [i]), tt = kt(s), it = jt(s), nt = Vt(s);
623
- return A(() => {
624
- W && p === 0 && a.show({
625
- content: s.t("find-replace.dialog.no-match"),
626
- type: N.Warning,
627
- duration: 5e3
628
- });
629
- }, [W, p, a, s]), /* @__PURE__ */ F("div", { children: [
630
- /* @__PURE__ */ c(R, { label: s.t("find-replace.dialog.find"), children: /* @__PURE__ */ c(
631
- Oe,
632
- {
633
- findCompleted: W,
634
- className: "univer-find-input",
635
- matchesCount: p,
636
- matchesPosition: M,
637
- findReplaceService: i,
638
- localeService: s,
639
- initialFindString: S,
640
- onChange: Ke
641
- }
642
- ) }),
643
- /* @__PURE__ */ c(R, { label: s.t("find-replace.dialog.replace"), children: /* @__PURE__ */ c(
644
- ge,
645
- {
646
- placeholder: s.t("find-replace.dialog.replace-placeholder"),
647
- value: g,
648
- onChange: (h) => qe(h)
649
- }
650
- ) }),
651
- /* @__PURE__ */ c(R, { label: s.t("find-replace.dialog.find-direction.title"), children: /* @__PURE__ */ c(k, { value: We, options: it, onChange: Qe }) }),
652
- /* @__PURE__ */ c(re, { children: /* @__PURE__ */ F(H, { children: [
653
- /* @__PURE__ */ c(R, { label: s.t("find-replace.dialog.find-scope.title"), children: /* @__PURE__ */ c(k, { value: ke, options: tt, onChange: Xe }) }),
654
- /* @__PURE__ */ c(R, { label: s.t("find-replace.dialog.find-by.title"), children: /* @__PURE__ */ c(k, { value: je, options: nt, onChange: et }) })
655
- ] }) }),
656
- /* @__PURE__ */ c(re, { children: /* @__PURE__ */ F(H, { children: [
657
- /* @__PURE__ */ c(R, { children: /* @__PURE__ */ c(
658
- ae,
659
- {
660
- checked: Ue,
661
- onChange: (h) => {
662
- i.changeCaseSensitive(h);
663
- },
664
- children: s.t("find-replace.dialog.case-sensitive")
665
- }
666
- ) }),
667
- /* @__PURE__ */ c(R, { children: /* @__PURE__ */ c(
668
- ae,
669
- {
670
- checked: Be,
671
- onChange: (h) => {
672
- i.changeMatchesTheWholeCell(h);
673
- },
674
- children: s.t("find-replace.dialog.match-the-whole-cell")
675
- }
676
- ) })
677
- ] }) }),
678
- /* @__PURE__ */ F("div", { className: "univer-mt-6 univer-flex univer-justify-between", children: [
679
- /* @__PURE__ */ c(j, { variant: "primary", onClick: ze, disabled: Ve, children: s.t("find-replace.dialog.find") }),
680
- /* @__PURE__ */ F("span", { className: "univer-inline-flex univer-gap-2", children: [
681
- /* @__PURE__ */ c(j, { disabled: Ge, onClick: Ye, children: s.t("find-replace.dialog.replace") }),
682
- /* @__PURE__ */ c(j, { disabled: He, onClick: Je, children: s.t("find-replace.dialog.replace-all") })
683
- ] })
684
- ] })
685
- ] });
686
- });
687
- function Wt() {
688
- const t = m(f), e = m(Se), n = m(J), i = P(t.state$, void 0, !0), s = G(null);
689
- A(() => {
690
- let d;
691
- return s.current && (d = e.registerContainerElement(s.current)), () => d == null ? void 0 : d.dispose();
692
- }, [e]);
693
- const r = G(null), a = u(
694
- (d) => n.setContextValue(be, d),
695
- [n]
696
- ), l = u(
697
- (d) => n.setContextValue(Re, d),
698
- [n]
699
- );
700
- return A(() => {
701
- var _;
702
- const d = Dt(document, "focusin").subscribe((p) => {
703
- var M;
704
- p.target && ((M = s.current) != null && M.contains(p.target)) ? a(!0) : a(!1), !r.current || !r.current.selectHasFocus() ? l(!1) : l(!0);
705
- });
706
- return (_ = r.current) == null || _.focus(), a(!0), l(!0), () => {
707
- d.unsubscribe(), a(!1);
708
- };
709
- }, [a, l]), /* @__PURE__ */ c("div", { ref: s, "data-u-comp": "find-replace-dialog", children: i.replaceRevealed ? /* @__PURE__ */ c(Bt, { ref: r }) : /* @__PURE__ */ c(Ut, { ref: r }) });
710
- }
711
- function kt(t) {
712
- const e = t.getCurrentLocale();
713
- return ee(() => [
714
- { label: t.t("find-replace.dialog.find-scope.current-sheet"), value: z.SUBUNIT },
715
- { label: t.t("find-replace.dialog.find-scope.workbook"), value: z.UNIT }
716
- ], [e]);
717
- }
718
- function jt(t) {
719
- const e = t.getCurrentLocale();
720
- return ee(() => [
721
- { label: t.t("find-replace.dialog.find-direction.row"), value: q.ROW },
722
- { label: t.t("find-replace.dialog.find-direction.column"), value: q.COLUMN }
723
- ], [e]);
724
- }
725
- function Vt(t) {
726
- const e = t.getCurrentLocale();
727
- return ee(() => [
728
- { label: t.t("find-replace.dialog.find-by.value"), value: Z.VALUE },
729
- { label: t.t("find-replace.dialog.find-by.formula"), value: Z.FORMULA }
730
- ], [e]);
731
- }
732
- function y(t) {
733
- return t.getContextValue(be);
734
- }
735
- function Gt(t) {
736
- return t.getContextValue(Ie);
737
- }
738
- function Le(t) {
739
- return t.getContextValue(Re);
740
- }
741
- const E = "7_find-replace-shortcuts";
742
- function ne(t) {
743
- return t.getContextValue(pe);
744
- }
745
- function se(t) {
746
- return !t.getContextValue(_e);
747
- }
748
- const Ht = {
749
- id: x.id,
750
- description: "find-replace.shortcut.open-find-dialog",
751
- binding: C.F | D.CTRL_COMMAND,
752
- group: E,
753
- preconditions(t) {
754
- return !y(t) && ne(t) && se(t);
755
- }
756
- }, Kt = {
757
- id: x.id,
758
- description: "find-replace.shortcut.open-find-dialog",
759
- binding: C.F | D.CTRL_COMMAND,
760
- mac: C.F | D.MAC_CTRL,
761
- preconditions(t) {
762
- return !y(t) && ne(t) && se(t);
763
- }
764
- }, qt = {
765
- id: ie.id,
766
- description: "find-replace.shortcut.open-replace-dialog",
767
- binding: C.H | D.CTRL_COMMAND,
768
- mac: C.H | D.MAC_CTRL,
769
- group: E,
770
- preconditions(t) {
771
- return ne(t) && se(t) && (!y(t) || !Gt(t));
772
- }
773
- }, Zt = {
774
- id: Pe.id,
775
- description: "find-replace.shortcut.go-to-next-match",
776
- binding: C.ENTER,
777
- group: E,
778
- priority: 1e3,
779
- preconditions(t) {
780
- return Le(t) && y(t);
781
- }
782
- }, zt = {
783
- id: Te.id,
784
- description: "find-replace.shortcut.go-to-previous-match",
785
- binding: C.ENTER | D.SHIFT,
786
- group: E,
787
- priority: 1e3,
788
- preconditions(t) {
789
- return Le(t) && y(t);
790
- }
791
- }, Yt = {
792
- id: xe.id,
793
- description: "find-replace.shortcut.focus-selection",
794
- binding: C.ESC,
795
- group: E,
796
- priority: 1e3,
797
- preconditions(t) {
798
- return y(t);
799
- }
800
- };
801
- function Jt(t) {
802
- const e = t.get(J);
803
- return {
804
- id: x.id,
805
- icon: "SearchIcon",
806
- tooltip: "find-replace.toolbar",
807
- type: mt.BUTTON,
808
- hidden$: gt(t, lt.UNIVER_SHEET),
809
- disabled$: ve([
810
- e.subscribeContextValue$(_e),
811
- e.subscribeContextValue$(pe)
812
- ]).pipe(yt(([n, i]) => n || !i))
813
- };
814
- }
815
- const Qt = {
816
- [St.ORGANIZATION]: {
817
- [x.id]: {
818
- order: 2,
819
- menuItemFactory: Jt
820
- }
821
- }
822
- };
823
- var Xt = Object.getOwnPropertyDescriptor, ei = (t, e, n, i) => {
824
- for (var s = i > 1 ? void 0 : i ? Xt(e, n) : e, r = t.length - 1, a; r >= 0; r--)
825
- (a = t[r]) && (s = a(s) || s);
826
- return s;
827
- }, v = (t, e) => (n, i) => e(n, i, t);
828
- const ce = "DESKTOP_FIND_REPLACE_DIALOG", we = 350, ti = 20, ii = 64;
829
- let w = class extends dt {
830
- constructor(e, n, i, s, r, a, l, d, _) {
831
- super();
832
- o(this, "_closingListenerDisposable");
833
- this._univerInstanceService = e, this._menuManagerService = n, this._shortcutService = i, this._commandService = s, this._findReplaceService = r, this._dialogService = a, this._layoutService = l, this._localeService = d, this._componentManager = _, this._initCommands(), this._initUI(), this._initShortcuts();
834
- }
835
- dispose() {
836
- var e;
837
- super.dispose(), (e = this._closingListenerDisposable) == null || e.dispose(), this._closingListenerDisposable = null;
838
- }
839
- _initCommands() {
840
- [
841
- x,
842
- ie,
843
- Pe,
844
- Te,
845
- ye,
846
- De,
847
- xe
848
- ].forEach((e) => {
849
- this.disposeWithMe(this._commandService.registerCommand(e));
850
- });
851
- }
852
- _initShortcuts() {
853
- [
854
- qt,
855
- Ht,
856
- Kt,
857
- zt,
858
- Zt,
859
- Yt
860
- ].forEach((e) => this.disposeWithMe(this._shortcutService.registerShortcut(e)));
861
- }
862
- _initUI() {
863
- [
864
- ["FindReplaceDialog", Wt],
865
- ["SearchIcon", $e]
866
- ].forEach(([e, n]) => {
867
- this.disposeWithMe(
868
- this._componentManager.register(e, n)
869
- );
870
- }), this._menuManagerService.mergeMenu(Qt), this._findReplaceService.stateUpdates$.pipe(oe(this.dispose$)).subscribe((e) => {
871
- e.revealed === !0 && this._openPanel();
872
- });
873
- }
874
- _openPanel() {
875
- this._dialogService.open({
876
- id: ce,
877
- draggable: !0,
878
- width: we,
879
- title: { title: this._localeService.t("find-replace.dialog.title") },
880
- children: { label: "FindReplaceDialog" },
881
- destroyOnClose: !0,
882
- mask: !1,
883
- maskClosable: !1,
884
- defaultPosition: ni(),
885
- preservePositionOnDestroy: !0,
886
- onClose: () => this.closePanel()
887
- }), this._closingListenerDisposable = O(this._univerInstanceService.focused$.pipe(oe(this.dispose$)).subscribe((e) => {
888
- (!e || !this._univerInstanceService.getUniverSheetInstance(e)) && this.closePanel();
889
- }));
890
- }
891
- closePanel() {
892
- this._closingListenerDisposable && (this._closingListenerDisposable.dispose(), this._closingListenerDisposable = null, this._dialogService.close(ce), this._findReplaceService.terminate(), queueMicrotask(() => this._layoutService.focus()));
893
- }
894
- };
895
- w = ei([
896
- v(0, fe),
897
- v(1, vt),
898
- v(2, Ct),
899
- v(3, U),
900
- v(4, f),
901
- v(5, Mt),
902
- v(6, Se),
903
- v(7, $(B)),
904
- v(8, $(Rt))
905
- ], w);
906
- function ni() {
907
- const { innerWidth: t } = window;
908
- return { x: t - we - ti, y: ii };
909
- }
910
- const si = "find-replace.config", le = {};
911
- var ri = Object.getOwnPropertyDescriptor, ai = (t, e, n, i) => {
912
- for (var s = i > 1 ? void 0 : i ? ri(e, n) : e, r = t.length - 1, a; r >= 0; r--)
913
- (a = t[r]) && (s = a(s) || s);
914
- return s;
915
- }, de = (t, e) => (n, i) => e(n, i, t);
916
- const oi = "UNIVER_FIND_REPLACE_PLUGIN";
917
- var V;
918
- let he = (V = class extends ut {
919
- constructor(t = le, e, n) {
920
- super(), this._config = t, this._injector = e, this._configService = n;
921
- const { ...i } = ft(
922
- {},
923
- le,
924
- this._config
925
- );
926
- this._configService.setConfig(si, i);
927
- }
928
- onStarting() {
929
- [
930
- [w],
931
- [f, { useClass: Y }]
932
- ].forEach((t) => this._injector.add(t));
933
- }
934
- onRendered() {
935
- this._injector.get(w);
936
- }
937
- }, o(V, "pluginName", oi), V);
938
- he = ai([
939
- de(1, $(ue)),
940
- de(2, ht)
941
- ], he);
942
- export {
943
- Z as FindBy,
944
- q as FindDirection,
945
- gi as FindModel,
946
- w as FindReplaceController,
947
- K as FindReplaceModel,
948
- Nt as FindReplaceState,
949
- z as FindScope,
950
- Pe as GoToNextMatchOperation,
951
- Te as GoToPreviousMatchOperation,
952
- f as IFindReplaceService,
953
- x as OpenFindDialogOperation,
954
- ie as OpenReplaceDialogOperation,
955
- ye as ReplaceAllMatchesCommand,
956
- De as ReplaceCurrentMatchCommand,
957
- he as UniverFindReplacePlugin,
958
- te as createInitFindReplaceState
959
- };
1
+ import{CommandType as e,Disposable as t,DisposableCollection as n,EDITOR_ACTIVATED as r,FOCUSING_SHEET as i,ICommandService as a,IConfigService as o,IConfirmService as s,IContextService as c,IUniverInstanceService as l,Inject as u,Injector as d,LocaleService as f,Plugin as p,RxDisposable as ee,UniverInstanceType as te,createIdentifier as ne,merge as re,toDisposable as m}from"@univerjs/core";import{Button as ie,Checkbox as ae,FormDualColumnLayout as oe,FormLayout as h,Input as se,MessageType as g,Pager as ce,Select as _}from"@univerjs/design";import{ComponentManager as v,IDialogService as le,ILayoutService as y,IMenuManagerService as ue,IMessageService as de,IShortcutService as fe,KeyCode as b,MenuItemType as pe,MetaKeys as x,RibbonDataGroup as me,getMenuHiddenObservable as he,useDebounceFn as ge,useDependency as S,useObservable as C}from"@univerjs/ui";import{RENDER_RAW_FORMULA_KEY as _e}from"@univerjs/engine-render";import{BehaviorSubject as w,Subject as T,combineLatest as ve,debounceTime as ye,fromEvent as be,map as xe,takeUntil as Se,throttleTime as Ce}from"rxjs";import{SearchIcon as we}from"@univerjs/icons";import{forwardRef as Te,useCallback as E,useEffect as D,useImperativeHandle as Ee,useMemo as O,useRef as De,useState as Oe}from"react";import{Fragment as k,jsx as A,jsxs as j}from"react/jsx-runtime";const ke=`FIND_REPLACE_INPUT_FOCUS`,Ae=`FIND_REPLACE_DIALOG_FOCUS`,je=`FIND_REPLACE_REPLACE_REVEALED`;function M(e){"@babel/helpers - typeof";return M=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},M(e)}function Me(e,t){if(M(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(M(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Ne(e){var t=Me(e,`string`);return M(t)==`symbol`?t:t+``}function N(e,t,n){return(t=Ne(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function P(e,t){return function(n,r){t(n,r,e)}}function F(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}var Pe=class extends t{};const I=ne(`find-replace.service`);function Fe(e){return e.findString!==void 0||e.inputtingFindString!==void 0||e.findDirection!==void 0||e.matchesTheWholeCell!==void 0||e.caseSensitive!==void 0||e.findScope!==void 0||e.findBy!==void 0}let L=class extends t{get searched(){return this._findModels.length>0}constructor(e,t,n,r){super(),this._state=e,this._providers=t,this._univerInstanceService=n,this._commandService=r,N(this,`currentMatch$`,new w(null)),N(this,`replaceables$`,new w([])),N(this,`_findModels`,[]),N(this,`_matchingModel`,null),N(this,`_matches`,[]),N(this,`_currentSearchingDisposables`,null),this.disposeWithMe(this._state.stateUpdates$.pipe(Ce(200,void 0,{leading:!0,trailing:!0})).subscribe(async e=>{let t=this._state.state;Fe(e)&&(t.findString!==``&&!t.replaceRevealed?(await this._startSearching(),this._state.changeState({findCompleted:!0})):e.replaceRevealed!==!0&&this._stopSearching())}))}dispose(){super.dispose(),this._stopSearching(),this.currentMatch$.complete(),this.replaceables$.complete(),this._state.changeState({...V(),revealed:!1})}async start(){if(!this._state.findString)return{results:[]};let e=await this._startSearching();return this._state.changeState({findCompleted:!0}),e}focusSelection(){var e;(e=this._matchingModel)==null||e.focusSelection()}async _startSearching(){if(!this._state.findString)return{results:[]};let e=Array.from(this._providers),t=this._findModels=(await Promise.all(e.map(e=>e.find({findString:this._state.findString,findDirection:this._state.findDirection,findScope:this._state.findScope,findBy:this._state.findBy,replaceRevealed:this._state.replaceRevealed,caseSensitive:this._state.caseSensitive,matchesTheWholeCell:this._state.matchesTheWholeCell})))).flat();this._subscribeToModelsChanges(t);let n=this._matches=t.map(e=>e.getMatches()).flat();return this.replaceables$.next(n.filter(e=>e.replaceable)),n.length?(this._moveToInitialMatch(t),this._state.changeState({matchesCount:n.length}),{results:n}):(this._state.changeState({matchesCount:0,matchesPosition:0}),{results:[]})}_stopSearching(){var e;this._providers.forEach(e=>e.terminate()),this._findModels=[],this._matches=[],this._matchingModel=null,(e=this._currentSearchingDisposables)==null||e.dispose(),this._currentSearchingDisposables=null,this.currentMatch$.next(null),this.replaceables$.next([]),this._state.changeState({findCompleted:!1,matchesCount:0,matchesPosition:0})}_subscribeToModelsChanges(e){let t=this._currentSearchingDisposables=new n,r=ve(e.map(e=>e.matchesUpdate$)).pipe(ye(220)).subscribe(([...e])=>{let t=this._matches=e.flat();t.length?(this._moveToInitialMatch(this._findModels,!0),this._state.changeState({matchesCount:t.length}),this.replaceables$.next(t.filter(e=>e.replaceable))):(this._state.changeState({matchesCount:0,matchesPosition:0}),this.replaceables$.next([]))});e.forEach(e=>t.add(m(e.activelyChangingMatch$.subscribe(e=>{let t=this._matches.findIndex(t=>t===e);this._state.changeState({matchesPosition:t+1})})))),t.add(m(r))}async replace(){return this._matchingModel?this._matchingModel.replace(this._state.replaceString):!1}async replaceAll(){let e=await Promise.all(this._findModels.map(e=>e.replaceAll(this._state.replaceString))).then(e=>e.reduce((e,t)=>(e.success+=t.success,e.failure+=t.failure,e),{success:0,failure:0}));return e.failure===0&&this._stopSearching(),e}getCurrentMatch(){return this._state.matchesPosition>0?this._matches[this._state.matchesPosition-1]:null}_markMatch(e){let t=this._matches.findIndex(t=>t===e);this.currentMatch$.next(e),this._state.changeState({matchesPosition:t+1})}moveToNextMatch(){if(!this._matchingModel)return;let e=this._findModels.length===1,t=this._matchingModel.moveToNextMatch({loop:e});if(t)return this._markMatch(t),t;{let e=this._findModels.findIndex(e=>e===this._matchingModel);return this._moveToNextUnitMatch(e)}}_moveToNextUnitMatch(e){let t=this._findModels.length;for(let n=(e+1)%t;n!==e;){let e=this._findModels[n],r=e.moveToNextMatch({ignoreSelection:!0});if(r)return this._matchingModel=e,this._markMatch(r),r;n=(n+1)%t}if(this._matchingModel){let e=this._matchingModel.moveToNextMatch({ignoreSelection:!0});return e&&this._markMatch(e),e}}moveToPreviousMatch(){if(!this._matchingModel)return;let e=this._findModels.length===1,t=this._matchingModel.moveToPreviousMatch({loop:e});if(t){let e=this._matches.findIndex(e=>e===t);return this.currentMatch$.next(t),this._state.changeState({matchesPosition:e+1}),t}else{let e=this._findModels.length,t=this._findModels.findIndex(e=>e===this._matchingModel);for(let n=(t-1+e)%e;n!==t;){let t=this._findModels[n],r=t.moveToPreviousMatch({ignoreSelection:!0});if(r)return this._matchingModel=t,this._markMatch(r),r;n=(n-1)%e}let n=this._matchingModel.moveToPreviousMatch({ignoreSelection:!0});return n&&this._markMatch(n),n}}_moveToInitialMatch(e,t=!1){var n;let r=(n=this._univerInstanceService.getFocusedUnit())==null?void 0:n.getUnitId();if(!r)return-1;let i=e.findIndex(e=>e.unitId===r);if(i!==-1){this._matchingModel=e[i];let n=this._matchingModel.moveToNextMatch({stayIfOnMatch:!0,noFocus:t});if(n)return this._markMatch(n),i}return this._moveToNextUnitMatch(i),0}};L=F([P(2,l),P(3,a)],L);let R=function(e){return e.ROW=`row`,e.COLUMN=`column`,e}({}),z=function(e){return e.VALUE=`value`,e.FORMULA=`formula`,e}({}),B=function(e){return e.SUBUNIT=`subunit`,e.UNIT=`unit`,e}({});function V(){return{caseSensitive:!1,findBy:z.VALUE,findCompleted:!1,findDirection:R.ROW,findScope:B.SUBUNIT,findString:``,inputtingFindString:``,matchesCount:0,matchesPosition:0,matchesTheWholeCell:!1,replaceRevealed:!1,replaceString:``,revealed:!0}}var Ie=class{constructor(){N(this,`_stateUpdates$`,new T),N(this,`stateUpdates$`,this._stateUpdates$.asObservable()),N(this,`_state$`,new w(V())),N(this,`state$`,this._state$.asObservable()),N(this,`_findString`,``),N(this,`_inputtingFindString`,``),N(this,`_replaceString`,``),N(this,`_revealed`,!1),N(this,`_replaceRevealed`,!1),N(this,`_matchesPosition`,0),N(this,`_matchesCount`,0),N(this,`_caseSensitive`,!0),N(this,`_matchesTheWholeCell`,!1),N(this,`_findDirection`,R.ROW),N(this,`_findScope`,B.SUBUNIT),N(this,`_findBy`,z.VALUE),N(this,`_findCompleted`,!1)}get state(){return this._state$.getValue()}get inputtingFindString(){return this._inputtingFindString}get findString(){return this._findString}get revealed(){return this._revealed}get replaceRevealed(){return this._replaceRevealed}get matchesPosition(){return this._matchesPosition}get matchesCount(){return this._matchesCount}get replaceString(){return this._replaceString}get caseSensitive(){return this._caseSensitive}get matchesTheWholeCell(){return this._matchesTheWholeCell}get findDirection(){return this._findDirection}get findScope(){return this._findScope}get findBy(){return this._findBy}get findCompleted(){return this._findCompleted}changeState(e){let t=!1,n={};e.findString!==void 0&&e.findString!==this._findString&&(this._findString=e.findString,n.findString=this._findString,t=!0),e.revealed!==void 0&&e.revealed!==this._revealed&&(this._revealed=e.revealed,n.revealed=e.revealed,t=!0),e.replaceRevealed!==void 0&&e.replaceRevealed!==this._replaceRevealed&&(this._replaceRevealed=e.replaceRevealed,n.replaceRevealed=e.replaceRevealed,t=!0),e.replaceString!==void 0&&e.replaceString!==this._replaceString&&(this._replaceString=e.replaceString,n.replaceString=e.replaceString,t=!0),e.matchesCount!==void 0&&e.matchesCount!==this._matchesCount&&(this._matchesCount=e.matchesCount,n.matchesCount=e.matchesCount,t=!0),e.matchesPosition!==void 0&&e.matchesPosition!==this._matchesPosition&&(this._matchesPosition=e.matchesPosition,n.matchesPosition=e.matchesPosition,t=!0),e.findBy!==void 0&&e.findBy!==this._findBy&&(this._findBy=e.findBy,n.findBy=e.findBy,t=!0),e.findScope!==void 0&&e.findScope!==this._findScope&&(this._findScope=e.findScope,n.findScope=e.findScope,t=!0),e.findDirection!==void 0&&e.findDirection!==this._findDirection&&(this._findDirection=e.findDirection,n.findDirection=e.findDirection,t=!0),e.caseSensitive!==void 0&&e.caseSensitive!==this._caseSensitive&&(this._caseSensitive=e.caseSensitive,n.caseSensitive=e.caseSensitive,t=!0),e.matchesTheWholeCell!==void 0&&e.matchesTheWholeCell!==this._matchesTheWholeCell&&(this._matchesTheWholeCell=e.matchesTheWholeCell,n.matchesTheWholeCell=e.matchesTheWholeCell,t=!0),e.inputtingFindString!==void 0&&e.inputtingFindString!==this._inputtingFindString&&(this._inputtingFindString=e.inputtingFindString,n.inputtingFindString=e.inputtingFindString,t=!0),e.findCompleted!==void 0&&e.findCompleted!==this._findCompleted&&(this._findCompleted=e.findCompleted,n.findCompleted=e.findCompleted,t=!0),t&&(this._state$.next({caseSensitive:this._caseSensitive,findBy:this._findBy,findCompleted:this._findCompleted,findDirection:this._findDirection,findScope:this._findScope,findString:this._findString,inputtingFindString:this._inputtingFindString,matchesCount:this._matchesCount,matchesPosition:this._matchesPosition,matchesTheWholeCell:this._matchesTheWholeCell,replaceRevealed:this._replaceRevealed,revealed:this._revealed}),this._stateUpdates$.next(n))}};let H=class extends t{get stateUpdates$(){return this._state.stateUpdates$}get state$(){return this._state.state$}get revealed(){return this._state.revealed}get replaceRevealed(){return this._state.replaceRevealed}constructor(e,t){super(),this._injector=e,this._contextService=t,N(this,`_providers`,new Set),N(this,`_state`,new Ie),N(this,`_model`,void 0),N(this,`_currentMatch$`,new w(null)),N(this,`currentMatch$`,this._currentMatch$.asObservable()),N(this,`_replaceables$`,new w([])),N(this,`replaceables$`,this._replaceables$.asObservable()),N(this,`_focusSignal$`,new T),N(this,`focusSignal$`,this._focusSignal$.asObservable())}dispose(){super.dispose(),this._currentMatch$.next(null),this._currentMatch$.complete(),this._replaceables$.next([]),this._replaceables$.complete(),this._focusSignal$.complete()}getProviders(){return this._providers}getCurrentMatch(){var e;return(e=this._model)==null?void 0:e.getCurrentMatch()}getFindString(){return this._state.findString}changeFindString(e){this._state.changeState({findString:e})}focusFindInput(){this._focusSignal$.next()}changeInputtingFindString(e){e?this._state.changeState({inputtingFindString:e}):this._state.changeState({inputtingFindString:``,findString:``})}changeReplaceString(e){this._state.changeState({replaceString:e})}changeMatchesTheWholeCell(e){this._state.changeState({matchesTheWholeCell:e})}changeCaseSensitive(e){this._state.changeState({caseSensitive:e})}changeFindBy(e){this._state.changeState({findBy:e}),this._toggleDisplayRawFormula(e===z.FORMULA)}changeFindScope(e){this._state.changeState({findScope:e})}changeFindDirection(e){this._state.changeState({findDirection:e})}moveToNextMatch(){this._model&&(this._state.replaceRevealed&&!this._model.searched?(this._state.changeState({findString:this._state.inputtingFindString}),this._model.start()):this._model.moveToNextMatch(),this._focusSignal$.next())}moveToPreviousMatch(){this._model&&(this._state.replaceRevealed&&!this._model.searched?(this._state.changeState({findString:this._state.inputtingFindString}),this._model.start()):this._model.moveToPreviousMatch(),this._focusSignal$.next())}async replace(){return this._model?this._model.replace():!1}async replaceAll(){if(!this._model)throw Error(`[FindReplaceService] replaceAll: model is not initialized!`);return this._model.replaceAll()}revealReplace(){this._state.changeState({replaceRevealed:!0,inputtingFindString:this._state.findString}),this._toggleRevealReplace(!0)}focusSelection(){var e;(e=this._model)==null||e.focusSelection()}start(e=!1){if(this._providers.size===0)return!1;this._model=this._injector.createInstance(L,this._state,this._providers),this._model.currentMatch$.subscribe(e=>this._currentMatch$.next(e)),this._model.replaceables$.subscribe(e=>this._replaceables$.next(e));let t=V();return e&&(t.replaceRevealed=!0),this._state.changeState(t),this._toggleRevealReplace(e),!0}find(){var e;(e=this._model)==null||e.start()}terminate(){var e;(e=this._model)==null||e.dispose(),this._model=null,this._toggleDisplayRawFormula(!1),this._toggleRevealReplace(!1)}registerFindReplaceProvider(e){return this._providers.add(e),m(()=>this._providers.delete(e))}_toggleRevealReplace(e){this._contextService.setContextValue(je,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue(_e,e)}};H=F([P(0,u(d)),P(1,c)],H);const U={id:`ui.command.replace-current-match`,type:e.COMMAND,handler:e=>e.get(I).replace()},W={id:`ui.command.replace-all-matches`,type:e.COMMAND,handler:async e=>{let t=e.get(s),n=e.get(f),r=e.get(de);if(!await t.confirm({id:`CONFIRM_REPLACE_ALL`,title:{title:n.t(`find-replace.replace.confirm.title`)},cancelText:n.t(`button.cancel`),confirmText:n.t(`button.confirm`)}))return!1;let{success:i,failure:a}=await e.get(I).replaceAll();return a>0?(i===0?r.show({type:g.Error,content:n.t(`find-replace.replace.all-failure`)}):r.show({type:g.Warning,content:n.t(`find-replace.replace.partial-success`,`${i}`,`${a}`)}),!1):(r.show({type:g.Success,content:n.t(`find-replace.replace.all-success`,`${i}`)}),!0)}},G={id:`ui.operation.open-find-dialog`,type:e.OPERATION,handler:e=>{let t=e.get(I);return t.revealed?t.focusFindInput():t.start(),!0}},K={id:`ui.operation.open-replace-dialog`,type:e.OPERATION,handler:e=>{let t=e.get(I);return t.revealed?t.replaceRevealed?t.focusFindInput():t.revealReplace():t.start(!0),!0}},q={type:e.OPERATION,id:`ui.operation.go-to-next-match`,handler:e=>(e.get(I).moveToNextMatch(),!0)},J={type:e.OPERATION,id:`ui.operation.go-to-previous-match`,handler:e=>(e.get(I).moveToPreviousMatch(),!0)},Le={type:e.OPERATION,id:`ui.operation.focus-selection`,handler:e=>(e.get(I).focusSelection(),!0)};function Re(e){let t=e.get(c);return{id:G.id,icon:`SearchIcon`,tooltip:`find-replace.toolbar`,type:pe.BUTTON,hidden$:he(e,te.UNIVER_SHEET),disabled$:ve([t.subscribeContextValue$(r),t.subscribeContextValue$(i)]).pipe(xe(([e,t])=>e||!t))}}const ze={[me.ORGANIZATION]:{[G.id]:{order:2,menuItemFactory:Re}}};function Be(e){let{findCompleted:t,localeService:n,matchesCount:r,matchesPosition:i,initialFindString:a,findReplaceService:o,onChange:s,...c}=e,[l,u]=Oe(a),d=t&&r===0?n.t(`find-replace.dialog.no-result`):r===0?` `:void 0;function f(e){i===r&&e===1?o.moveToNextMatch():i===1&&e===r||e<i?o.moveToPreviousMatch():o.moveToNextMatch()}return A(`div`,{className:`univer-relative univer-flex univer-items-center univer-gap-2`,onDrag:e=>e.stopPropagation(),children:A(se,{"data-u-comp":`search-input`,autoFocus:!0,placeholder:n.t(`find-replace.dialog.find-placeholder`),value:l,onChange:e=>{u(e),s==null||s(e)},slot:A(ce,{loop:!0,text:d,value:i,total:r,onChange:f}),...c})})}function Ve(e,t){let n=E(()=>{var e;(e=document.querySelector(`.univer-find-input input`))==null||e.focus()},[]),r=E(()=>{let e=document.querySelectorAll(`[data-u-comp=find-replace-dialog] [data-u-comp=search-input]`);return Array.from(e).some(e=>e===document.activeElement)},[]);return Ee(t,()=>({focus:n,selectHasFocus:r})),D(()=>{let t=e.focusSignal$.subscribe(()=>n());return()=>t.unsubscribe()},[e,n]),{focus:n,selectHasFocus:r}}const He=Te(function(e,t){let n=S(f),r=S(I),i=S(a),{findCompleted:o,findString:s,matchesCount:c,matchesPosition:l}=C(r.state$,void 0,!0),u=E(()=>{i.executeCommand(K.id)},[i]),d=ge(e=>r.changeFindString(e),500);return Ve(r,t),j(k,{children:[A(Be,{findCompleted:o,matchesCount:c,matchesPosition:l,findReplaceService:r,localeService:n,initialFindString:s,onChange:d}),A(`div`,{className:`univer-mt-4 univer-text-center`,children:A(`a`,{className:`
2
+ hover:univer-text-primary-500/80
3
+ univer-cursor-pointer univer-text-sm univer-text-primary-500 univer-transition-colors
4
+ `,onClick:u,children:n.t(`find-replace.dialog.advanced-finding`)})})]})}),Ue=Te(function(e,t){let n=S(I),r=S(f),i=S(a),o=S(de),s=C(n.currentMatch$,void 0,!0),c=C(n.replaceables$,void 0,!0),{matchesCount:l,matchesPosition:u,findString:d,inputtingFindString:p,replaceString:ee,caseSensitive:te,matchesTheWholeCell:ne,findDirection:re,findScope:m,findBy:ce,findCompleted:v}=C(n.state$,void 0,!0),le=p.length===0,y=l===0||!(s!=null&&s.replaceable),ue=c.length===0,fe=E(e=>n.changeInputtingFindString(e),[n]),b=E(e=>n.changeReplaceString(e),[n]),{focus:pe}=Ve(n,t),x=E(()=>{d===p?n.moveToNextMatch():(n.changeFindString(p),n.find())},[d,p,n]),me=E(()=>i.executeCommand(U.id),[i]),he=E(async()=>{await i.executeCommand(W.id),pe()},[i]),ge=E(e=>{n.changeFindDirection(e)},[n]),_e=E(e=>{n.changeFindScope(e)},[n]),w=E(e=>{n.changeFindBy(e)},[n]),T=Ge(r),ve=Ke(r),ye=qe(r);return D(()=>{v&&l===0&&o.show({content:r.t(`find-replace.dialog.no-match`),type:g.Warning,duration:5e3})},[v,l,o,r]),j(`div`,{children:[A(h,{label:r.t(`find-replace.dialog.find`),children:A(Be,{findCompleted:v,className:`univer-find-input`,matchesCount:l,matchesPosition:u,findReplaceService:n,localeService:r,initialFindString:p,onChange:fe})}),A(h,{label:r.t(`find-replace.dialog.replace`),children:A(se,{placeholder:r.t(`find-replace.dialog.replace-placeholder`),value:ee,onChange:e=>b(e)})}),A(h,{label:r.t(`find-replace.dialog.find-direction.title`),children:A(_,{value:re,options:ve,onChange:ge})}),A(oe,{children:j(k,{children:[A(h,{label:r.t(`find-replace.dialog.find-scope.title`),children:A(_,{value:m,options:T,onChange:_e})}),A(h,{label:r.t(`find-replace.dialog.find-by.title`),children:A(_,{value:ce,options:ye,onChange:w})})]})}),A(oe,{children:j(k,{children:[A(h,{children:A(ae,{checked:te,onChange:e=>{n.changeCaseSensitive(e)},children:r.t(`find-replace.dialog.case-sensitive`)})}),A(h,{children:A(ae,{checked:ne,onChange:e=>{n.changeMatchesTheWholeCell(e)},children:r.t(`find-replace.dialog.match-the-whole-cell`)})})]})}),j(`div`,{className:`univer-mt-6 univer-flex univer-justify-between`,children:[A(ie,{variant:`primary`,onClick:x,disabled:le,children:r.t(`find-replace.dialog.find`)}),j(`span`,{className:`univer-inline-flex univer-gap-2`,children:[A(ie,{disabled:y,onClick:me,children:r.t(`find-replace.dialog.replace`)}),A(ie,{disabled:ue,onClick:he,children:r.t(`find-replace.dialog.replace-all`)})]})]})]})});function We(){let e=S(I),t=S(y),n=S(c),r=C(e.state$,void 0,!0),i=De(null);D(()=>{let e;return i.current&&(e=t.registerContainerElement(i.current)),()=>e==null?void 0:e.dispose()},[t]);let a=De(null),o=E(e=>n.setContextValue(Ae,e),[n]),s=E(e=>n.setContextValue(ke,e),[n]);return D(()=>{var e;let t=be(document,`focusin`).subscribe(e=>{var t;e.target&&(t=i.current)!=null&&t.contains(e.target)?o(!0):o(!1),!a.current||!a.current.selectHasFocus()?s(!1):s(!0)});return(e=a.current)==null||e.focus(),o(!0),s(!0),()=>{t.unsubscribe(),o(!1)}},[o,s]),A(`div`,{ref:i,"data-u-comp":`find-replace-dialog`,children:r.replaceRevealed?A(Ue,{ref:a}):A(He,{ref:a})})}function Ge(e){return O(()=>[{label:e.t(`find-replace.dialog.find-scope.current-sheet`),value:B.SUBUNIT},{label:e.t(`find-replace.dialog.find-scope.workbook`),value:B.UNIT}],[e.getCurrentLocale()])}function Ke(e){return O(()=>[{label:e.t(`find-replace.dialog.find-direction.row`),value:R.ROW},{label:e.t(`find-replace.dialog.find-direction.column`),value:R.COLUMN}],[e.getCurrentLocale()])}function qe(e){return O(()=>[{label:e.t(`find-replace.dialog.find-by.value`),value:z.VALUE},{label:e.t(`find-replace.dialog.find-by.formula`),value:z.FORMULA}],[e.getCurrentLocale()])}function Y(e){return e.getContextValue(Ae)}function Je(e){return e.getContextValue(je)}function Ye(e){return e.getContextValue(ke)}const X=`7_find-replace-shortcuts`;function Z(e){return e.getContextValue(i)}function Xe(e){return!e.getContextValue(r)}const Ze={id:G.id,description:`find-replace.shortcut.open-find-dialog`,binding:b.F|x.CTRL_COMMAND,group:X,preconditions(e){return!Y(e)&&Z(e)&&Xe(e)}},Qe={id:G.id,description:`find-replace.shortcut.open-find-dialog`,binding:b.F|x.CTRL_COMMAND,mac:b.F|x.MAC_CTRL,preconditions(e){return!Y(e)&&Z(e)&&Xe(e)}},$e={id:K.id,description:`find-replace.shortcut.open-replace-dialog`,binding:b.H|x.CTRL_COMMAND,mac:b.H|x.MAC_CTRL,group:X,preconditions(e){return Z(e)&&Xe(e)&&(!Y(e)||!Je(e))}},et={id:q.id,description:`find-replace.shortcut.go-to-next-match`,binding:b.ENTER,group:X,priority:1e3,preconditions(e){return Ye(e)&&Y(e)}},tt={id:J.id,description:`find-replace.shortcut.go-to-previous-match`,binding:b.ENTER|x.SHIFT,group:X,priority:1e3,preconditions(e){return Ye(e)&&Y(e)}},nt={id:Le.id,description:`find-replace.shortcut.focus-selection`,binding:b.ESC,group:X,priority:1e3,preconditions(e){return Y(e)}},rt=`DESKTOP_FIND_REPLACE_DIALOG`;let Q=class extends ee{constructor(e,t,n,r,i,a,o,s,c){super(),this._univerInstanceService=e,this._menuManagerService=t,this._shortcutService=n,this._commandService=r,this._findReplaceService=i,this._dialogService=a,this._layoutService=o,this._localeService=s,this._componentManager=c,N(this,`_closingListenerDisposable`,void 0),this._initCommands(),this._initUI(),this._initShortcuts()}dispose(){var e;super.dispose(),(e=this._closingListenerDisposable)==null||e.dispose(),this._closingListenerDisposable=null}_initCommands(){[G,K,q,J,W,U,Le].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initShortcuts(){[$e,Ze,Qe,tt,et,nt].forEach(e=>this.disposeWithMe(this._shortcutService.registerShortcut(e)))}_initUI(){[[`FindReplaceDialog`,We],[`SearchIcon`,we]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))}),this._menuManagerService.mergeMenu(ze),this._findReplaceService.stateUpdates$.pipe(Se(this.dispose$)).subscribe(e=>{e.revealed===!0&&this._openPanel()})}_openPanel(){this._dialogService.open({id:rt,draggable:!0,width:350,title:{title:this._localeService.t(`find-replace.dialog.title`)},children:{label:`FindReplaceDialog`},destroyOnClose:!0,mask:!1,maskClosable:!1,defaultPosition:it(),preservePositionOnDestroy:!0,onClose:()=>this.closePanel()}),this._closingListenerDisposable=m(this._univerInstanceService.focused$.pipe(Se(this.dispose$)).subscribe(e=>{(!e||!this._univerInstanceService.getUniverSheetInstance(e))&&this.closePanel()}))}closePanel(){this._closingListenerDisposable&&(this._closingListenerDisposable.dispose(),this._closingListenerDisposable=null,this._dialogService.close(rt),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus()))}};Q=F([P(0,l),P(1,ue),P(2,fe),P(3,a),P(4,I),P(5,le),P(6,y),P(7,u(f)),P(8,u(v))],Q);function it(){let{innerWidth:e}=window;return{x:e-350-20,y:64}}var at=`@univerjs/find-replace`,ot=`0.17.0-insiders.20260318-d69dc16`;const st=`find-replace.config`;Symbol(st);const ct={};let $=class extends p{constructor(e=ct,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{...r}=re({},ct,this._config);this._configService.setConfig(st,r)}onStarting(){[[Q],[I,{useClass:H}]].forEach(e=>this._injector.add(e))}onRendered(){this._injector.get(Q)}};N($,`pluginName`,`UNIVER_FIND_REPLACE_PLUGIN`),N($,`packageName`,at),N($,`version`,ot),$=F([P(1,u(d)),P(2,o)],$);export{z as FindBy,R as FindDirection,Pe as FindModel,Q as FindReplaceController,L as FindReplaceModel,Ie as FindReplaceState,B as FindScope,q as GoToNextMatchOperation,J as GoToPreviousMatchOperation,I as IFindReplaceService,G as OpenFindDialogOperation,K as OpenReplaceDialogOperation,W as ReplaceAllMatchesCommand,U as ReplaceCurrentMatchCommand,$ as UniverFindReplacePlugin,V as createInitFindReplaceState};