@univerjs/find-replace 0.17.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +4 -1
- package/lib/cjs/locale/ca-ES.js +1 -1
- package/lib/cjs/locale/en-US.js +1 -1
- package/lib/cjs/locale/es-ES.js +1 -1
- package/lib/cjs/locale/fa-IR.js +1 -1
- package/lib/cjs/locale/fr-FR.js +1 -1
- package/lib/cjs/locale/ja-JP.js +1 -1
- package/lib/cjs/locale/ko-KR.js +1 -1
- package/lib/cjs/locale/ru-RU.js +1 -1
- package/lib/cjs/locale/sk-SK.js +1 -1
- package/lib/cjs/locale/vi-VN.js +1 -1
- package/lib/cjs/locale/zh-CN.js +1 -1
- package/lib/cjs/locale/zh-TW.js +1 -1
- package/lib/es/index.js +4 -960
- package/lib/es/locale/ca-ES.js +1 -52
- package/lib/es/locale/en-US.js +1 -52
- package/lib/es/locale/es-ES.js +1 -52
- package/lib/es/locale/fa-IR.js +1 -52
- package/lib/es/locale/fr-FR.js +1 -52
- package/lib/es/locale/ja-JP.js +1 -52
- package/lib/es/locale/ko-KR.js +1 -52
- package/lib/es/locale/ru-RU.js +1 -52
- package/lib/es/locale/sk-SK.js +1 -52
- package/lib/es/locale/vi-VN.js +1 -52
- package/lib/es/locale/zh-CN.js +1 -52
- package/lib/es/locale/zh-TW.js +1 -52
- package/lib/index.css +54 -1
- package/lib/index.js +4 -960
- package/lib/locale/ca-ES.js +1 -52
- package/lib/locale/en-US.js +1 -52
- package/lib/locale/es-ES.js +1 -52
- package/lib/locale/fa-IR.js +1 -52
- package/lib/locale/fr-FR.js +1 -52
- package/lib/locale/ja-JP.js +1 -52
- package/lib/locale/ko-KR.js +1 -52
- package/lib/locale/ru-RU.js +1 -52
- package/lib/locale/sk-SK.js +1 -52
- package/lib/locale/vi-VN.js +1 -52
- package/lib/locale/zh-CN.js +1 -52
- package/lib/locale/zh-TW.js +1 -52
- package/lib/types/commands/commands/replace.command.d.ts +16 -1
- package/lib/types/commands/operations/find-replace.operation.d.ts +16 -1
- package/lib/types/config/config.d.ts +16 -1
- package/lib/types/controllers/find-replace.controller.d.ts +15 -0
- package/lib/types/controllers/find-replace.shortcut.d.ts +16 -1
- package/lib/types/locale/ca-ES.d.ts +16 -1
- package/lib/types/locale/es-ES.d.ts +16 -1
- package/lib/types/locale/fa-IR.d.ts +16 -1
- package/lib/types/locale/fr-FR.d.ts +16 -1
- package/lib/types/locale/ja-JP.d.ts +16 -1
- package/lib/types/locale/ko-KR.d.ts +16 -1
- package/lib/types/locale/ru-RU.d.ts +16 -1
- package/lib/types/locale/sk-SK.d.ts +16 -1
- package/lib/types/locale/vi-VN.d.ts +16 -1
- package/lib/types/locale/zh-CN.d.ts +16 -1
- package/lib/types/locale/zh-TW.d.ts +16 -1
- package/lib/types/menu/find-replace.menu.d.ts +17 -2
- package/lib/types/menu/schema.d.ts +16 -1
- package/lib/types/plugin.d.ts +16 -1
- package/lib/types/services/find-replace.service.d.ts +20 -3
- package/lib/types/views/dialog/FindReplaceDialog.d.ts +2 -2
- package/lib/types/views/dialog/FindReplaceDialog.stories.d.ts +16 -1
- package/lib/types/views/dialog/SearchInput.d.ts +18 -3
- package/lib/umd/index.js +4 -1
- package/lib/umd/locale/ca-ES.js +1 -1
- package/lib/umd/locale/en-US.js +1 -1
- package/lib/umd/locale/es-ES.js +1 -1
- package/lib/umd/locale/fa-IR.js +1 -1
- package/lib/umd/locale/fr-FR.js +1 -1
- package/lib/umd/locale/ja-JP.js +1 -1
- package/lib/umd/locale/ko-KR.js +1 -1
- package/lib/umd/locale/ru-RU.js +1 -1
- package/lib/umd/locale/sk-SK.js +1 -1
- package/lib/umd/locale/vi-VN.js +1 -1
- package/lib/umd/locale/zh-CN.js +1 -1
- package/lib/umd/locale/zh-TW.js +1 -1
- package/package.json +10 -9
package/lib/index.js
CHANGED
|
@@ -1,960 +1,4 @@
|
|
|
1
|
-
var rt = Object.defineProperty;
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { MessageType as N, Input as me, Pager as _t, FormLayout as R, Select as j, FormDualColumnLayout as re, Checkbox as ae, Button as V } from "@univerjs/design";
|
|
6
|
-
import { IMessageService as Se, getMenuHiddenObservable as gt, MenuItemType as mt, RibbonDataGroup as St, useDependency as m, useObservable as T, useDebounceFn as vt, ILayoutService as ve, KeyCode as C, MetaKeys as D, IMenuManagerService as Ct, IShortcutService as Mt, IDialogService as Rt, ComponentManager as bt } from "@univerjs/ui";
|
|
7
|
-
import { RENDER_RAW_FORMULA_KEY as It } from "@univerjs/engine-render";
|
|
8
|
-
import { throttleTime as Ft, BehaviorSubject as x, combineLatest as Ce, debounceTime as Dt, Subject as Me, map as yt, fromEvent as Pt, takeUntil as oe } from "rxjs";
|
|
9
|
-
import { useRef as G, createElement as Re, forwardRef as X, useState as Tt, useCallback as u, useEffect as L, useMemo as ee, useImperativeHandle as xt } from "react";
|
|
10
|
-
import { jsx as c, jsxs as F, Fragment as H } from "react/jsx-runtime";
|
|
11
|
-
const be = "FIND_REPLACE_INPUT_FOCUS", Ie = "FIND_REPLACE_DIALOG_FOCUS", Fe = "FIND_REPLACE_REPLACE_REVEALED";
|
|
12
|
-
var Et = Object.getOwnPropertyDescriptor, De = (t, e, n, i) => {
|
|
13
|
-
for (var s = i > 1 ? void 0 : i ? Et(e, n) : e, r = t.length - 1, a; r >= 0; r--)
|
|
14
|
-
(a = t[r]) && (s = a(s) || s);
|
|
15
|
-
return s;
|
|
16
|
-
}, w = (t, e) => (n, i) => e(n, i, t);
|
|
17
|
-
class Si extends Q {
|
|
18
|
-
}
|
|
19
|
-
const f = ot("find-replace.service");
|
|
20
|
-
function $t(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 x(null));
|
|
27
|
-
o(this, "replaceables$", new x([]));
|
|
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(Ft(200, void 0, { leading: !0, trailing: !0 })).subscribe(async (r) => {
|
|
36
|
-
const a = this._state.state;
|
|
37
|
-
$t(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 ct(), i = Ce(e.map((s) => s.matchesUpdate$)).pipe(Dt(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(A(s.activelyChangingMatch$.subscribe((r) => {
|
|
90
|
-
const a = this._matches.findIndex((l) => l === r);
|
|
91
|
-
this._state.changeState({ matchesPosition: a + 1 });
|
|
92
|
-
})))), n.add(A(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 = De([
|
|
167
|
-
w(2, pe),
|
|
168
|
-
w(3, B)
|
|
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 Me());
|
|
191
|
-
o(this, "stateUpdates$", this._stateUpdates$.asObservable());
|
|
192
|
-
o(this, "_state$", new x(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 x(null));
|
|
277
|
-
o(this, "currentMatch$", this._currentMatch$.asObservable());
|
|
278
|
-
o(this, "_replaceables$", new x([]));
|
|
279
|
-
o(this, "replaceables$", this._replaceables$.asObservable());
|
|
280
|
-
o(this, "_focusSignal$", new Me());
|
|
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), A(() => this._providers.delete(e));
|
|
377
|
-
}
|
|
378
|
-
_toggleRevealReplace(e) {
|
|
379
|
-
this._contextService.setContextValue(Fe, e);
|
|
380
|
-
}
|
|
381
|
-
_toggleDisplayRawFormula(e) {
|
|
382
|
-
this._contextService.setContextValue(It, e);
|
|
383
|
-
}
|
|
384
|
-
};
|
|
385
|
-
Y = De([
|
|
386
|
-
w(0, O(fe)),
|
|
387
|
-
w(1, J)
|
|
388
|
-
], Y);
|
|
389
|
-
const ye = {
|
|
390
|
-
id: "ui.command.replace-current-match",
|
|
391
|
-
type: b.COMMAND,
|
|
392
|
-
handler: (t) => t.get(f).replace()
|
|
393
|
-
}, Ot = "CONFIRM_REPLACE_ALL", Pe = {
|
|
394
|
-
id: "ui.command.replace-all-matches",
|
|
395
|
-
type: b.COMMAND,
|
|
396
|
-
handler: async (t) => {
|
|
397
|
-
const e = t.get(lt), n = t.get(W), i = t.get(Se);
|
|
398
|
-
if (!await e.confirm({
|
|
399
|
-
id: Ot,
|
|
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
|
-
}, E = {
|
|
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
|
-
}, Te = {
|
|
432
|
-
type: b.OPERATION,
|
|
433
|
-
id: "ui.operation.go-to-next-match",
|
|
434
|
-
handler: (t) => (t.get(f).moveToNextMatch(), !0)
|
|
435
|
-
}, xe = {
|
|
436
|
-
type: b.OPERATION,
|
|
437
|
-
id: "ui.operation.go-to-previous-match",
|
|
438
|
-
handler: (t) => (t.get(f).moveToPreviousMatch(), !0)
|
|
439
|
-
}, Ee = {
|
|
440
|
-
type: b.OPERATION,
|
|
441
|
-
id: "ui.operation.focus-selection",
|
|
442
|
-
handler: (t) => (t.get(f).focusSelection(), !0)
|
|
443
|
-
};
|
|
444
|
-
function $e({ 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(`_${wt()}`);
|
|
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 Re(t.tag, {
|
|
457
|
-
key: e,
|
|
458
|
-
...At(t, n, s),
|
|
459
|
-
...i
|
|
460
|
-
}, (Lt(t, n).children || []).map((r, a) => Ne(r, `${e}-${t.tag}-${a}`, n, void 0, s)));
|
|
461
|
-
}
|
|
462
|
-
function At(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 Lt(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 wt() {
|
|
487
|
-
return Math.random().toString(36).substring(2, 8);
|
|
488
|
-
}
|
|
489
|
-
$e.displayName = "UniverIcon";
|
|
490
|
-
const Ut = {
|
|
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
|
-
}, Oe = X(function(e, n) {
|
|
509
|
-
return Re($e, Object.assign({}, e, {
|
|
510
|
-
id: "search-icon",
|
|
511
|
-
ref: n,
|
|
512
|
-
icon: Ut
|
|
513
|
-
}));
|
|
514
|
-
});
|
|
515
|
-
Oe.displayName = "SearchIcon";
|
|
516
|
-
function Bt(t) {
|
|
517
|
-
const e = t.get(J);
|
|
518
|
-
return {
|
|
519
|
-
id: E.id,
|
|
520
|
-
icon: "SearchIcon",
|
|
521
|
-
tooltip: "find-replace.toolbar",
|
|
522
|
-
type: mt.BUTTON,
|
|
523
|
-
hidden$: gt(t, dt.UNIVER_SHEET),
|
|
524
|
-
disabled$: Ce([
|
|
525
|
-
e.subscribeContextValue$(_e),
|
|
526
|
-
e.subscribeContextValue$(ge)
|
|
527
|
-
]).pipe(yt(([n, i]) => n || !i))
|
|
528
|
-
};
|
|
529
|
-
}
|
|
530
|
-
const Wt = {
|
|
531
|
-
[St.ORGANIZATION]: {
|
|
532
|
-
[E.id]: {
|
|
533
|
-
order: 2,
|
|
534
|
-
menuItemFactory: Bt
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
};
|
|
538
|
-
function Ae(t) {
|
|
539
|
-
const {
|
|
540
|
-
findCompleted: e,
|
|
541
|
-
localeService: n,
|
|
542
|
-
matchesCount: i,
|
|
543
|
-
matchesPosition: s,
|
|
544
|
-
initialFindString: r,
|
|
545
|
-
findReplaceService: a,
|
|
546
|
-
onChange: l,
|
|
547
|
-
...d
|
|
548
|
-
} = t, [_, p] = Tt(r), I = e && i === 0 ? n.t("find-replace.dialog.no-result") : i === 0 ? " " : void 0;
|
|
549
|
-
function S(g) {
|
|
550
|
-
s === i && g === 1 ? a.moveToNextMatch() : s === 1 && g === i || g < s ? a.moveToPreviousMatch() : a.moveToNextMatch();
|
|
551
|
-
}
|
|
552
|
-
return /* @__PURE__ */ c("div", { className: "univer-relative univer-flex univer-items-center univer-gap-2", onDrag: (g) => g.stopPropagation(), children: /* @__PURE__ */ c(
|
|
553
|
-
me,
|
|
554
|
-
{
|
|
555
|
-
"data-u-comp": "search-input",
|
|
556
|
-
autoFocus: !0,
|
|
557
|
-
placeholder: n.t("find-replace.dialog.find-placeholder"),
|
|
558
|
-
value: _,
|
|
559
|
-
onChange: (g) => {
|
|
560
|
-
p(g), l == null || l(g);
|
|
561
|
-
},
|
|
562
|
-
slot: /* @__PURE__ */ c(
|
|
563
|
-
_t,
|
|
564
|
-
{
|
|
565
|
-
loop: !0,
|
|
566
|
-
text: I,
|
|
567
|
-
value: s,
|
|
568
|
-
total: i,
|
|
569
|
-
onChange: S
|
|
570
|
-
}
|
|
571
|
-
),
|
|
572
|
-
...d
|
|
573
|
-
}
|
|
574
|
-
) });
|
|
575
|
-
}
|
|
576
|
-
function Le(t, e) {
|
|
577
|
-
const n = u(() => {
|
|
578
|
-
var s;
|
|
579
|
-
(s = document.querySelector(".univer-find-input input")) == null || s.focus();
|
|
580
|
-
}, []), i = u(() => {
|
|
581
|
-
const s = document.querySelectorAll("[data-u-comp=find-replace-dialog] [data-u-comp=search-input]");
|
|
582
|
-
return Array.from(s).some((r) => r === document.activeElement);
|
|
583
|
-
}, []);
|
|
584
|
-
return xt(e, () => ({ focus: n, selectHasFocus: i })), L(() => {
|
|
585
|
-
const s = t.focusSignal$.subscribe(() => n());
|
|
586
|
-
return () => s.unsubscribe();
|
|
587
|
-
}, [t, n]), { focus: n, selectHasFocus: i };
|
|
588
|
-
}
|
|
589
|
-
const kt = X(function(e, n) {
|
|
590
|
-
const i = m(W), s = m(f), r = m(B), a = T(s.state$, void 0, !0), { findCompleted: l, findString: d, matchesCount: _, matchesPosition: p } = a, M = u(() => {
|
|
591
|
-
r.executeCommand(ie.id);
|
|
592
|
-
}, [r]), I = vt((S) => s.changeFindString(S), 500);
|
|
593
|
-
return Le(s, n), /* @__PURE__ */ F(H, { children: [
|
|
594
|
-
/* @__PURE__ */ c(
|
|
595
|
-
Ae,
|
|
596
|
-
{
|
|
597
|
-
findCompleted: l,
|
|
598
|
-
matchesCount: _,
|
|
599
|
-
matchesPosition: p,
|
|
600
|
-
findReplaceService: s,
|
|
601
|
-
localeService: i,
|
|
602
|
-
initialFindString: d,
|
|
603
|
-
onChange: I
|
|
604
|
-
}
|
|
605
|
-
),
|
|
606
|
-
/* @__PURE__ */ c("div", { className: "univer-mt-4 univer-text-center", children: /* @__PURE__ */ c(
|
|
607
|
-
"a",
|
|
608
|
-
{
|
|
609
|
-
className: "hover:univer-text-primary-500/80 univer-cursor-pointer univer-text-sm univer-text-primary-500 univer-transition-colors",
|
|
610
|
-
onClick: M,
|
|
611
|
-
children: i.t("find-replace.dialog.advanced-finding")
|
|
612
|
-
}
|
|
613
|
-
) })
|
|
614
|
-
] });
|
|
615
|
-
}), jt = X(function(e, n) {
|
|
616
|
-
const i = m(f), s = m(W), r = m(B), a = m(Se), l = T(i.currentMatch$, void 0, !0), d = T(i.replaceables$, void 0, !0), _ = T(i.state$, void 0, !0), {
|
|
617
|
-
matchesCount: p,
|
|
618
|
-
matchesPosition: M,
|
|
619
|
-
findString: I,
|
|
620
|
-
inputtingFindString: S,
|
|
621
|
-
replaceString: g,
|
|
622
|
-
caseSensitive: Be,
|
|
623
|
-
matchesTheWholeCell: We,
|
|
624
|
-
findDirection: ke,
|
|
625
|
-
findScope: je,
|
|
626
|
-
findBy: Ve,
|
|
627
|
-
findCompleted: k
|
|
628
|
-
} = _, Ge = S.length === 0, He = p === 0 || !(l != null && l.replaceable), Ke = d.length === 0, qe = u(
|
|
629
|
-
(h) => i.changeInputtingFindString(h),
|
|
630
|
-
[i]
|
|
631
|
-
), Ze = u(
|
|
632
|
-
(h) => i.changeReplaceString(h),
|
|
633
|
-
[i]
|
|
634
|
-
), { focus: ze } = Le(i, n), Ye = u(() => {
|
|
635
|
-
I === S ? i.moveToNextMatch() : (i.changeFindString(S), i.find());
|
|
636
|
-
}, [I, S, i]), Je = u(() => r.executeCommand(ye.id), [r]), Qe = u(async () => {
|
|
637
|
-
await r.executeCommand(Pe.id), ze();
|
|
638
|
-
}, [r]), Xe = u((h) => {
|
|
639
|
-
i.changeFindDirection(h);
|
|
640
|
-
}, [i]), et = u((h) => {
|
|
641
|
-
i.changeFindScope(h);
|
|
642
|
-
}, [i]), tt = u((h) => {
|
|
643
|
-
i.changeFindBy(h);
|
|
644
|
-
}, [i]), it = Gt(s), nt = Ht(s), st = Kt(s);
|
|
645
|
-
return L(() => {
|
|
646
|
-
k && p === 0 && a.show({
|
|
647
|
-
content: s.t("find-replace.dialog.no-match"),
|
|
648
|
-
type: N.Warning,
|
|
649
|
-
duration: 5e3
|
|
650
|
-
});
|
|
651
|
-
}, [k, p, a, s]), /* @__PURE__ */ F("div", { children: [
|
|
652
|
-
/* @__PURE__ */ c(R, { label: s.t("find-replace.dialog.find"), children: /* @__PURE__ */ c(
|
|
653
|
-
Ae,
|
|
654
|
-
{
|
|
655
|
-
findCompleted: k,
|
|
656
|
-
className: "univer-find-input",
|
|
657
|
-
matchesCount: p,
|
|
658
|
-
matchesPosition: M,
|
|
659
|
-
findReplaceService: i,
|
|
660
|
-
localeService: s,
|
|
661
|
-
initialFindString: S,
|
|
662
|
-
onChange: qe
|
|
663
|
-
}
|
|
664
|
-
) }),
|
|
665
|
-
/* @__PURE__ */ c(R, { label: s.t("find-replace.dialog.replace"), children: /* @__PURE__ */ c(
|
|
666
|
-
me,
|
|
667
|
-
{
|
|
668
|
-
placeholder: s.t("find-replace.dialog.replace-placeholder"),
|
|
669
|
-
value: g,
|
|
670
|
-
onChange: (h) => Ze(h)
|
|
671
|
-
}
|
|
672
|
-
) }),
|
|
673
|
-
/* @__PURE__ */ c(R, { label: s.t("find-replace.dialog.find-direction.title"), children: /* @__PURE__ */ c(j, { value: ke, options: nt, onChange: Xe }) }),
|
|
674
|
-
/* @__PURE__ */ c(re, { children: /* @__PURE__ */ F(H, { children: [
|
|
675
|
-
/* @__PURE__ */ c(R, { label: s.t("find-replace.dialog.find-scope.title"), children: /* @__PURE__ */ c(j, { value: je, options: it, onChange: et }) }),
|
|
676
|
-
/* @__PURE__ */ c(R, { label: s.t("find-replace.dialog.find-by.title"), children: /* @__PURE__ */ c(j, { value: Ve, options: st, onChange: tt }) })
|
|
677
|
-
] }) }),
|
|
678
|
-
/* @__PURE__ */ c(re, { children: /* @__PURE__ */ F(H, { children: [
|
|
679
|
-
/* @__PURE__ */ c(R, { children: /* @__PURE__ */ c(
|
|
680
|
-
ae,
|
|
681
|
-
{
|
|
682
|
-
checked: Be,
|
|
683
|
-
onChange: (h) => {
|
|
684
|
-
i.changeCaseSensitive(h);
|
|
685
|
-
},
|
|
686
|
-
children: s.t("find-replace.dialog.case-sensitive")
|
|
687
|
-
}
|
|
688
|
-
) }),
|
|
689
|
-
/* @__PURE__ */ c(R, { children: /* @__PURE__ */ c(
|
|
690
|
-
ae,
|
|
691
|
-
{
|
|
692
|
-
checked: We,
|
|
693
|
-
onChange: (h) => {
|
|
694
|
-
i.changeMatchesTheWholeCell(h);
|
|
695
|
-
},
|
|
696
|
-
children: s.t("find-replace.dialog.match-the-whole-cell")
|
|
697
|
-
}
|
|
698
|
-
) })
|
|
699
|
-
] }) }),
|
|
700
|
-
/* @__PURE__ */ F("div", { className: "univer-mt-6 univer-flex univer-justify-between", children: [
|
|
701
|
-
/* @__PURE__ */ c(V, { variant: "primary", onClick: Ye, disabled: Ge, children: s.t("find-replace.dialog.find") }),
|
|
702
|
-
/* @__PURE__ */ F("span", { className: "univer-inline-flex univer-gap-2", children: [
|
|
703
|
-
/* @__PURE__ */ c(V, { disabled: He, onClick: Je, children: s.t("find-replace.dialog.replace") }),
|
|
704
|
-
/* @__PURE__ */ c(V, { disabled: Ke, onClick: Qe, children: s.t("find-replace.dialog.replace-all") })
|
|
705
|
-
] })
|
|
706
|
-
] })
|
|
707
|
-
] });
|
|
708
|
-
});
|
|
709
|
-
function Vt() {
|
|
710
|
-
const t = m(f), e = m(ve), n = m(J), i = T(t.state$, void 0, !0), s = G(null);
|
|
711
|
-
L(() => {
|
|
712
|
-
let d;
|
|
713
|
-
return s.current && (d = e.registerContainerElement(s.current)), () => d == null ? void 0 : d.dispose();
|
|
714
|
-
}, [e]);
|
|
715
|
-
const r = G(null), a = u(
|
|
716
|
-
(d) => n.setContextValue(Ie, d),
|
|
717
|
-
[n]
|
|
718
|
-
), l = u(
|
|
719
|
-
(d) => n.setContextValue(be, d),
|
|
720
|
-
[n]
|
|
721
|
-
);
|
|
722
|
-
return L(() => {
|
|
723
|
-
var _;
|
|
724
|
-
const d = Pt(document, "focusin").subscribe((p) => {
|
|
725
|
-
var M;
|
|
726
|
-
p.target && ((M = s.current) != null && M.contains(p.target)) ? a(!0) : a(!1), !r.current || !r.current.selectHasFocus() ? l(!1) : l(!0);
|
|
727
|
-
});
|
|
728
|
-
return (_ = r.current) == null || _.focus(), a(!0), l(!0), () => {
|
|
729
|
-
d.unsubscribe(), a(!1);
|
|
730
|
-
};
|
|
731
|
-
}, [a, l]), /* @__PURE__ */ c("div", { ref: s, "data-u-comp": "find-replace-dialog", children: i.replaceRevealed ? /* @__PURE__ */ c(jt, { ref: r }) : /* @__PURE__ */ c(kt, { ref: r }) });
|
|
732
|
-
}
|
|
733
|
-
function Gt(t) {
|
|
734
|
-
const e = t.getCurrentLocale();
|
|
735
|
-
return ee(() => [
|
|
736
|
-
{ label: t.t("find-replace.dialog.find-scope.current-sheet"), value: z.SUBUNIT },
|
|
737
|
-
{ label: t.t("find-replace.dialog.find-scope.workbook"), value: z.UNIT }
|
|
738
|
-
], [e]);
|
|
739
|
-
}
|
|
740
|
-
function Ht(t) {
|
|
741
|
-
const e = t.getCurrentLocale();
|
|
742
|
-
return ee(() => [
|
|
743
|
-
{ label: t.t("find-replace.dialog.find-direction.row"), value: q.ROW },
|
|
744
|
-
{ label: t.t("find-replace.dialog.find-direction.column"), value: q.COLUMN }
|
|
745
|
-
], [e]);
|
|
746
|
-
}
|
|
747
|
-
function Kt(t) {
|
|
748
|
-
const e = t.getCurrentLocale();
|
|
749
|
-
return ee(() => [
|
|
750
|
-
{ label: t.t("find-replace.dialog.find-by.value"), value: Z.VALUE },
|
|
751
|
-
{ label: t.t("find-replace.dialog.find-by.formula"), value: Z.FORMULA }
|
|
752
|
-
], [e]);
|
|
753
|
-
}
|
|
754
|
-
function y(t) {
|
|
755
|
-
return t.getContextValue(Ie);
|
|
756
|
-
}
|
|
757
|
-
function qt(t) {
|
|
758
|
-
return t.getContextValue(Fe);
|
|
759
|
-
}
|
|
760
|
-
function we(t) {
|
|
761
|
-
return t.getContextValue(be);
|
|
762
|
-
}
|
|
763
|
-
const $ = "7_find-replace-shortcuts";
|
|
764
|
-
function ne(t) {
|
|
765
|
-
return t.getContextValue(ge);
|
|
766
|
-
}
|
|
767
|
-
function se(t) {
|
|
768
|
-
return !t.getContextValue(_e);
|
|
769
|
-
}
|
|
770
|
-
const Zt = {
|
|
771
|
-
id: E.id,
|
|
772
|
-
description: "find-replace.shortcut.open-find-dialog",
|
|
773
|
-
binding: C.F | D.CTRL_COMMAND,
|
|
774
|
-
group: $,
|
|
775
|
-
preconditions(t) {
|
|
776
|
-
return !y(t) && ne(t) && se(t);
|
|
777
|
-
}
|
|
778
|
-
}, zt = {
|
|
779
|
-
id: E.id,
|
|
780
|
-
description: "find-replace.shortcut.open-find-dialog",
|
|
781
|
-
binding: C.F | D.CTRL_COMMAND,
|
|
782
|
-
mac: C.F | D.MAC_CTRL,
|
|
783
|
-
preconditions(t) {
|
|
784
|
-
return !y(t) && ne(t) && se(t);
|
|
785
|
-
}
|
|
786
|
-
}, Yt = {
|
|
787
|
-
id: ie.id,
|
|
788
|
-
description: "find-replace.shortcut.open-replace-dialog",
|
|
789
|
-
binding: C.H | D.CTRL_COMMAND,
|
|
790
|
-
mac: C.H | D.MAC_CTRL,
|
|
791
|
-
group: $,
|
|
792
|
-
preconditions(t) {
|
|
793
|
-
return ne(t) && se(t) && (!y(t) || !qt(t));
|
|
794
|
-
}
|
|
795
|
-
}, Jt = {
|
|
796
|
-
id: Te.id,
|
|
797
|
-
description: "find-replace.shortcut.go-to-next-match",
|
|
798
|
-
binding: C.ENTER,
|
|
799
|
-
group: $,
|
|
800
|
-
priority: 1e3,
|
|
801
|
-
preconditions(t) {
|
|
802
|
-
return we(t) && y(t);
|
|
803
|
-
}
|
|
804
|
-
}, Qt = {
|
|
805
|
-
id: xe.id,
|
|
806
|
-
description: "find-replace.shortcut.go-to-previous-match",
|
|
807
|
-
binding: C.ENTER | D.SHIFT,
|
|
808
|
-
group: $,
|
|
809
|
-
priority: 1e3,
|
|
810
|
-
preconditions(t) {
|
|
811
|
-
return we(t) && y(t);
|
|
812
|
-
}
|
|
813
|
-
}, Xt = {
|
|
814
|
-
id: Ee.id,
|
|
815
|
-
description: "find-replace.shortcut.focus-selection",
|
|
816
|
-
binding: C.ESC,
|
|
817
|
-
group: $,
|
|
818
|
-
priority: 1e3,
|
|
819
|
-
preconditions(t) {
|
|
820
|
-
return y(t);
|
|
821
|
-
}
|
|
822
|
-
};
|
|
823
|
-
var ei = Object.getOwnPropertyDescriptor, ti = (t, e, n, i) => {
|
|
824
|
-
for (var s = i > 1 ? void 0 : i ? ei(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", Ue = 350, ii = 20, ni = 64;
|
|
829
|
-
let U = class extends ht {
|
|
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
|
-
E,
|
|
842
|
-
ie,
|
|
843
|
-
Te,
|
|
844
|
-
xe,
|
|
845
|
-
Pe,
|
|
846
|
-
ye,
|
|
847
|
-
Ee
|
|
848
|
-
].forEach((e) => {
|
|
849
|
-
this.disposeWithMe(this._commandService.registerCommand(e));
|
|
850
|
-
});
|
|
851
|
-
}
|
|
852
|
-
_initShortcuts() {
|
|
853
|
-
[
|
|
854
|
-
Yt,
|
|
855
|
-
Zt,
|
|
856
|
-
zt,
|
|
857
|
-
Qt,
|
|
858
|
-
Jt,
|
|
859
|
-
Xt
|
|
860
|
-
].forEach((e) => this.disposeWithMe(this._shortcutService.registerShortcut(e)));
|
|
861
|
-
}
|
|
862
|
-
_initUI() {
|
|
863
|
-
[
|
|
864
|
-
["FindReplaceDialog", Vt],
|
|
865
|
-
["SearchIcon", Oe]
|
|
866
|
-
].forEach(([e, n]) => {
|
|
867
|
-
this.disposeWithMe(
|
|
868
|
-
this._componentManager.register(e, n)
|
|
869
|
-
);
|
|
870
|
-
}), this._menuManagerService.mergeMenu(Wt), 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: Ue,
|
|
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: si(),
|
|
885
|
-
preservePositionOnDestroy: !0,
|
|
886
|
-
onClose: () => this.closePanel()
|
|
887
|
-
}), this._closingListenerDisposable = A(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
|
-
U = ti([
|
|
896
|
-
v(0, pe),
|
|
897
|
-
v(1, Ct),
|
|
898
|
-
v(2, Mt),
|
|
899
|
-
v(3, B),
|
|
900
|
-
v(4, f),
|
|
901
|
-
v(5, Rt),
|
|
902
|
-
v(6, ve),
|
|
903
|
-
v(7, O(W)),
|
|
904
|
-
v(8, O(bt))
|
|
905
|
-
], U);
|
|
906
|
-
function si() {
|
|
907
|
-
const { innerWidth: t } = window;
|
|
908
|
-
return { x: t - Ue - ii, y: ni };
|
|
909
|
-
}
|
|
910
|
-
const ri = "@univerjs/find-replace", ai = "0.17.0", le = {
|
|
911
|
-
name: ri,
|
|
912
|
-
version: ai
|
|
913
|
-
}, oi = "find-replace.config", de = {};
|
|
914
|
-
var ci = Object.getOwnPropertyDescriptor, li = (t, e, n, i) => {
|
|
915
|
-
for (var s = i > 1 ? void 0 : i ? ci(e, n) : e, r = t.length - 1, a; r >= 0; r--)
|
|
916
|
-
(a = t[r]) && (s = a(s) || s);
|
|
917
|
-
return s;
|
|
918
|
-
}, he = (t, e) => (n, i) => e(n, i, t), P;
|
|
919
|
-
let ue = (P = class extends ft {
|
|
920
|
-
constructor(t = de, e, n) {
|
|
921
|
-
super(), this._config = t, this._injector = e, this._configService = n;
|
|
922
|
-
const { ...i } = pt(
|
|
923
|
-
{},
|
|
924
|
-
de,
|
|
925
|
-
this._config
|
|
926
|
-
);
|
|
927
|
-
this._configService.setConfig(oi, i);
|
|
928
|
-
}
|
|
929
|
-
onStarting() {
|
|
930
|
-
[
|
|
931
|
-
[U],
|
|
932
|
-
[f, { useClass: Y }]
|
|
933
|
-
].forEach((t) => this._injector.add(t));
|
|
934
|
-
}
|
|
935
|
-
onRendered() {
|
|
936
|
-
this._injector.get(U);
|
|
937
|
-
}
|
|
938
|
-
}, o(P, "pluginName", "UNIVER_FIND_REPLACE_PLUGIN"), o(P, "packageName", le.name), o(P, "version", le.version), P);
|
|
939
|
-
ue = li([
|
|
940
|
-
he(1, O(fe)),
|
|
941
|
-
he(2, ut)
|
|
942
|
-
], ue);
|
|
943
|
-
export {
|
|
944
|
-
Z as FindBy,
|
|
945
|
-
q as FindDirection,
|
|
946
|
-
Si as FindModel,
|
|
947
|
-
U as FindReplaceController,
|
|
948
|
-
K as FindReplaceModel,
|
|
949
|
-
Nt as FindReplaceState,
|
|
950
|
-
z as FindScope,
|
|
951
|
-
Te as GoToNextMatchOperation,
|
|
952
|
-
xe as GoToPreviousMatchOperation,
|
|
953
|
-
f as IFindReplaceService,
|
|
954
|
-
E as OpenFindDialogOperation,
|
|
955
|
-
ie as OpenReplaceDialogOperation,
|
|
956
|
-
Pe as ReplaceAllMatchesCommand,
|
|
957
|
-
ye as ReplaceCurrentMatchCommand,
|
|
958
|
-
ue as UniverFindReplacePlugin,
|
|
959
|
-
te as createInitFindReplaceState
|
|
960
|
-
};
|
|
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.18.0`;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};
|