@univerjs/find-replace 0.1.1 → 0.1.3

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/es/index.js CHANGED
@@ -1,245 +1,331 @@
1
- var de = Object.defineProperty;
2
- var he = (t, e, n) => e in t ? de(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
- var l = (t, e, n) => (he(t, typeof e != "symbol" ? e + "" : e, n), n);
4
- import { Disposable as E, ILogService as B, IUniverInstanceService as G, toDisposable as ue, CommandType as m, LocaleService as j, UniverInstanceType as pe, OnLifecycle as fe, LifecycleStages as _e, RxDisposable as ve, ICommandService as ge, IContextService as me, Plugin as Se } from "@univerjs/core";
5
- import { createIdentifier as xe, Inject as S, Injector as H } from "@wendellhu/redi";
6
- import { ILayoutService as W, MenuGroup as Re, MenuItemType as Me, MenuPosition as Ie, getMenuHiddenObservable as Ce, KeyCode as R, MetaKeys as F, ComponentManager as Oe, IMenuService as Pe, IShortcutService as ye, IDialogService as Te } from "@univerjs/ui";
7
- import { Subject as be, BehaviorSubject as Ee, takeUntil as je } from "rxjs";
8
- import Fe, { forwardRef as k, useRef as z, createElement as K, useState as $, useCallback as M, useEffect as De, Fragment as A } from "react";
9
- import { useObservable as Ne, InputWithSlot as $e, Pager as Ae, Button as I, FormLayout as P, Input as U, Select as Ue } from "@univerjs/design";
10
- import { useDependency as y } from "@wendellhu/redi/react-bindings";
11
- var u = function() {
12
- return u = Object.assign || function(t) {
1
+ var rt = Object.defineProperty;
2
+ var at = (t, e, n) => e in t ? rt(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
+ var c = (t, e, n) => (at(t, typeof e != "symbol" ? e + "" : e, n), n);
4
+ import { Disposable as X, IUniverInstanceService as fe, ILogService as pe, IContextService as U, DisposableCollection as ot, toDisposable as q, CommandType as b, LocaleService as P, ICommandService as ee, FOCUSING_SHEET as _e, EDITOR_ACTIVATED as ge, UniverInstanceType as ct, OnLifecycle as lt, LifecycleStages as dt, RxDisposable as ht, Plugin as ut } from "@univerjs/core";
5
+ import { createIdentifier as ft, Inject as y, Injector as me } from "@wendellhu/redi";
6
+ import { IConfirmService as pt, IMessageService as ve, useObservable as I, ILayoutService as Se, KeyCode as x, MetaKeys as M, MenuGroup as _t, MenuItemType as gt, MenuPosition as mt, getMenuHiddenObservable as vt, ComponentManager as St, IMenuService as Ct, IShortcutService as Rt, IDialogService as xt } from "@univerjs/ui";
7
+ import { throttleTime as Mt, BehaviorSubject as F, combineLatest as Ce, debounceTime as bt, Subject as Re, fromEvent as yt, map as It, takeUntil as ce } from "rxjs";
8
+ import { RENDER_RAW_FORMULA_KEY as Ft } from "@univerjs/engine-render";
9
+ import Pt, { forwardRef as B, useRef as z, createElement as xe, useCallback as _, Fragment as E, useEffect as j, useMemo as te, useImperativeHandle as Dt } from "react";
10
+ import { MessageType as $, InputWithSlot as Ot, Pager as Tt, Button as N, FormLayout as R, Input as Et, Select as H, FormDualColumnLayout as le, Checkbox as de } from "@univerjs/design";
11
+ import { useDependency as S } from "@wendellhu/redi/react-bindings";
12
+ var m = function() {
13
+ return m = Object.assign || function(t) {
13
14
  for (var e, n = 1, i = arguments.length; n < i; n++) {
14
15
  e = arguments[n];
15
- for (var r in e)
16
- Object.prototype.hasOwnProperty.call(e, r) && (t[r] = e[r]);
16
+ for (var s in e)
17
+ Object.prototype.hasOwnProperty.call(e, s) && (t[s] = e[s]);
17
18
  }
18
19
  return t;
19
- }, u.apply(this, arguments);
20
- }, Le = function(t, e) {
20
+ }, m.apply(this, arguments);
21
+ }, $t = function(t, e) {
21
22
  var n = {};
22
23
  for (var i in t)
23
24
  Object.prototype.hasOwnProperty.call(t, i) && e.indexOf(i) < 0 && (n[i] = t[i]);
24
25
  if (t != null && typeof Object.getOwnPropertySymbols == "function")
25
- for (var r = 0, i = Object.getOwnPropertySymbols(t); r < i.length; r++)
26
- e.indexOf(i[r]) < 0 && Object.prototype.propertyIsEnumerable.call(t, i[r]) && (n[i[r]] = t[i[r]]);
26
+ for (var s = 0, i = Object.getOwnPropertySymbols(t); s < i.length; s++)
27
+ e.indexOf(i[s]) < 0 && Object.prototype.propertyIsEnumerable.call(t, i[s]) && (n[i[s]] = t[i[s]]);
27
28
  return n;
28
- }, q = k(function(t, e) {
29
- var n = t.icon, i = t.id, r = t.className, o = t.extend, a = Le(t, ["icon", "id", "className", "extend"]), s = "univerjs-icon univerjs-icon-".concat(i, " ").concat(r || "").trim(), h = z("_".concat(Be()));
30
- return Z(n, "".concat(i), { defIds: n.defIds, idSuffix: h.current }, u({ ref: e, className: s }, a), o);
29
+ }, Me = B(function(t, e) {
30
+ var n = t.icon, i = t.id, s = t.className, r = t.extend, a = $t(t, ["icon", "id", "className", "extend"]), o = "univerjs-icon univerjs-icon-".concat(i, " ").concat(s || "").trim(), d = z("_".concat(jt()));
31
+ return be(n, "".concat(i), { defIds: n.defIds, idSuffix: d.current }, m({ ref: e, className: o }, a), r);
31
32
  });
32
- function Z(t, e, n, i, r) {
33
- return K(t.tag, u(u({ key: e }, we(t, n, r)), i), (Ve(t, n).children || []).map(function(o, a) {
34
- return Z(o, "".concat(e, "-").concat(t.tag, "-").concat(a), n, void 0, r);
33
+ function be(t, e, n, i, s) {
34
+ return xe(t.tag, m(m({ key: e }, Nt(t, n, s)), i), (At(t, n).children || []).map(function(r, a) {
35
+ return be(r, "".concat(e, "-").concat(t.tag, "-").concat(a), n, void 0, s);
35
36
  }));
36
37
  }
37
- function we(t, e, n) {
38
- var i = u({}, t.attrs);
38
+ function Nt(t, e, n) {
39
+ var i = m({}, t.attrs);
39
40
  n != null && n.colorChannel1 && i.fill === "colorChannel1" && (i.fill = n.colorChannel1);
40
- var r = e.defIds;
41
- return !r || r.length === 0 || (t.tag === "use" && i["xlink:href"] && (i["xlink:href"] = i["xlink:href"] + e.idSuffix), Object.entries(i).forEach(function(o) {
42
- var a = o[0], s = o[1];
43
- typeof s == "string" && (i[a] = s.replace(/url\(#(.*)\)/, "url(#$1".concat(e.idSuffix, ")")));
41
+ var s = e.defIds;
42
+ return !s || s.length === 0 || (t.tag === "use" && i["xlink:href"] && (i["xlink:href"] = i["xlink:href"] + e.idSuffix), Object.entries(i).forEach(function(r) {
43
+ var a = r[0], o = r[1];
44
+ typeof o == "string" && (i[a] = o.replace(/url\(#(.*)\)/, "url(#$1".concat(e.idSuffix, ")")));
44
45
  })), i;
45
46
  }
46
- function Ve(t, e) {
47
+ function At(t, e) {
47
48
  var n, i = e.defIds;
48
- return !i || i.length === 0 ? t : t.tag === "defs" && (!((n = t.children) === null || n === void 0) && n.length) ? u(u({}, t), { children: t.children.map(function(r) {
49
- return typeof r.attrs.id == "string" && i && i.indexOf(r.attrs.id) > -1 ? u(u({}, r), { attrs: u(u({}, r.attrs), { id: r.attrs.id + e.idSuffix }) }) : r;
49
+ return !i || i.length === 0 ? t : t.tag === "defs" && (!((n = t.children) === null || n === void 0) && n.length) ? m(m({}, t), { children: t.children.map(function(s) {
50
+ return typeof s.attrs.id == "string" && i && i.indexOf(s.attrs.id) > -1 ? m(m({}, s), { attrs: m(m({}, s.attrs), { id: s.attrs.id + e.idSuffix }) }) : s;
50
51
  }) }) : t;
51
52
  }
52
- function Be() {
53
+ function jt() {
53
54
  return Math.random().toString(36).substring(2, 8);
54
55
  }
55
- q.displayName = "UniverIcon";
56
- var Ge = {
57
- tag: "svg",
58
- attrs: { fill: "none", viewBox: "0 0 17 17", width: "1em", height: "1em" },
59
- children: [
60
- {
61
- tag: "mask",
62
- attrs: {
63
- id: "mask0_217_40",
64
- style: { maskType: "alpha" },
65
- width: 17,
66
- height: 17,
67
- x: 0,
68
- y: 0,
69
- maskUnits: "userSpaceOnUse"
70
- },
71
- children: [
72
- {
73
- tag: "path",
74
- attrs: { fill: "#D9D9D9", d: "M0.9 0.09H16.9V16.09H0.9z" }
75
- }
76
- ]
77
- },
78
- {
79
- tag: "g",
80
- attrs: { mask: "url(#mask0_217_40)" },
81
- children: [
82
- {
83
- tag: "path",
84
- attrs: {
85
- fill: "currentColor",
86
- d: "M2.39551 7.37266C2.39551 4.18105 4.98281 1.59375 8.17441 1.59375C11.366 1.59375 13.9533 4.18105 13.9533 7.37266C13.9533 8.72342 13.4898 9.96603 12.7133 10.95L15.1964 13.4331C15.4619 13.6986 15.4619 14.1291 15.1964 14.3946C14.9309 14.6601 14.5004 14.6601 14.2349 14.3946L11.7518 11.9115C10.7678 12.6881 9.52525 13.1516 8.17441 13.1516C4.98281 13.1516 2.39551 10.5642 2.39551 7.37266ZM8.17441 2.95349C5.73378 2.95349 3.75525 4.93202 3.75525 7.37266C3.75525 9.81333 5.73378 11.7918 8.17441 11.7918C10.6151 11.7918 12.5936 9.81333 12.5936 7.37266C12.5936 4.93202 10.6151 2.95349 8.17441 2.95349Z",
87
- fillRule: "evenodd",
88
- clipRule: "evenodd"
89
- }
90
- }
91
- ]
92
- }
93
- ]
94
- }, J = k(function(t, e) {
95
- return K(q, Object.assign({}, t, {
56
+ Me.displayName = "UniverIcon";
57
+ var wt = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 17 17", width: "1em", height: "1em" }, children: [{ tag: "mask", attrs: { id: "mask0_217_40", style: { maskType: "alpha" }, width: 17, height: 17, x: 0, y: 0, maskUnits: "userSpaceOnUse" }, children: [{ tag: "path", attrs: { fill: "#D9D9D9", d: "M0.9 0.09H16.9V16.09H0.9z" } }] }, { tag: "g", attrs: { mask: "url(#mask0_217_40)" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M2.39551 7.37266C2.39551 4.18105 4.98281 1.59375 8.17441 1.59375C11.366 1.59375 13.9533 4.18105 13.9533 7.37266C13.9533 8.72342 13.4898 9.96603 12.7133 10.95L15.1964 13.4331C15.4619 13.6986 15.4619 14.1291 15.1964 14.3946C14.9309 14.6601 14.5004 14.6601 14.2349 14.3946L11.7518 11.9115C10.7678 12.6881 9.52525 13.1516 8.17441 13.1516C4.98281 13.1516 2.39551 10.5642 2.39551 7.37266ZM8.17441 2.95349C5.73378 2.95349 3.75525 4.93202 3.75525 7.37266C3.75525 9.81333 5.73378 11.7918 8.17441 11.7918C10.6151 11.7918 12.5936 9.81333 12.5936 7.37266C12.5936 4.93202 10.6151 2.95349 8.17441 2.95349Z", fillRule: "evenodd", clipRule: "evenodd" } }] }] }, ye = B(function(t, e) {
58
+ return xe(Me, Object.assign({}, t, {
96
59
  id: "search-single-16",
97
60
  ref: e,
98
- icon: Ge
61
+ icon: wt
99
62
  }));
100
63
  });
101
- J.displayName = "SearchSingle16";
102
- var He = Object.defineProperty, We = Object.getOwnPropertyDescriptor, Y = (t, e, n, i) => {
103
- for (var r = i > 1 ? void 0 : i ? We(e, n) : e, o = t.length - 1, a; o >= 0; o--)
104
- (a = t[o]) && (r = (i ? a(e, n, r) : a(r)) || r);
105
- return i && r && He(e, n, r), r;
106
- }, x = (t, e) => (n, i) => e(n, i, t);
107
- class Ct extends E {
64
+ ye.displayName = "SearchSingle16";
65
+ const Ie = "FIND_REPLACE_INPUT_FOCUS", Fe = "FIND_REPLACE_DIALOG_FOCUS", Pe = "FIND_REPLACE_REPLACE_REVEALED";
66
+ var Lt = Object.defineProperty, Ut = Object.getOwnPropertyDescriptor, De = (t, e, n, i) => {
67
+ for (var s = i > 1 ? void 0 : i ? Ut(e, n) : e, r = t.length - 1, a; r >= 0; r--)
68
+ (a = t[r]) && (s = (i ? a(e, n, s) : a(s)) || s);
69
+ return i && s && Lt(e, n, s), s;
70
+ }, w = (t, e) => (n, i) => e(n, i, t);
71
+ class Ni extends X {
108
72
  }
109
- const f = xe("univer.find-replace.service");
110
- let T = class extends E {
111
- constructor(e, n, i, r) {
73
+ const v = ft("find-replace.service");
74
+ function Bt(t) {
75
+ 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";
76
+ }
77
+ let K = class extends X {
78
+ constructor(e, n, i, s) {
112
79
  super();
113
- l(this, "_matchPositionFindModel", null);
114
- l(this, "_findModels", []);
115
- l(this, "_matches", []);
116
- l(this, "_positionModel", null);
117
- this._state = e, this._providers = n, this._logService = i, this._univerInstanceService = r, this._state.stateUpdates$.subscribe((o) => {
118
- typeof o.findString < "u" && (o.findString ? this.find() : this._cancelFinding());
119
- });
80
+ c(this, "currentMatch$", new F(null));
81
+ c(this, "replaceables$", new F([]));
82
+ /** All find models returned by providers. */
83
+ c(this, "_findModels", []);
84
+ /** The find model that the current match is from. */
85
+ c(this, "_matchingModel", null);
86
+ c(this, "_matches", []);
87
+ c(this, "_currentSearchingDisposables", null);
88
+ this._state = e, this._providers = n, this._univerInstanceService = i, this._logService = s, this.disposeWithMe(
89
+ this._state.stateUpdates$.pipe(Mt(200, void 0, { leading: !0, trailing: !0 })).subscribe(async (r) => {
90
+ const a = this._state.state;
91
+ Bt(r) && (a.findString !== "" && !a.replaceRevealed ? (await this._startSearching(), this._state.changeState({ findCompleted: !0 })) : r.replaceRevealed !== !0 && this._stopSearching());
92
+ })
93
+ );
120
94
  }
121
- async find() {
122
- this._cancelFinding();
123
- const e = Array.from(this._providers), n = this._findModels = (await Promise.all(e.map((o) => o.find({ text: this._state.findString })))).flat(), i = n.map((o) => o.getMatches()).flat();
124
- if (this._matches = i, !i.length)
125
- return {
126
- results: []
127
- };
128
- const r = this._moveToInitialMatch(n, i);
95
+ get searched() {
96
+ return this._findModels.length > 0;
97
+ }
98
+ dispose() {
99
+ super.dispose(), this._stopSearching(), this.currentMatch$.complete(), this.replaceables$.complete(), this._state.changeState({ ...ie(), revealed: !1 });
100
+ }
101
+ async start() {
102
+ if (!this._state.findString)
103
+ return { results: [] };
104
+ const e = await this._startSearching();
105
+ return this._state.changeState({ findCompleted: !0 }), e;
106
+ }
107
+ /** Call this method to start a `searching`. */
108
+ async _startSearching() {
109
+ if (!this._state.findString)
110
+ return { results: [] };
111
+ const e = Array.from(this._providers), n = this._findModels = (await Promise.all(e.map((r) => r.find({
112
+ findString: this._state.findString,
113
+ findDirection: this._state.findDirection,
114
+ findScope: this._state.findScope,
115
+ findBy: this._state.findBy,
116
+ replaceRevealed: this._state.replaceRevealed,
117
+ caseSensitive: this._state.caseSensitive,
118
+ matchesTheWholeCell: this._state.matchesTheWholeCell
119
+ })))).flat();
120
+ this._subscribeToModelsChanges(n);
121
+ const i = this._matches = n.map((r) => r.getMatches()).flat();
122
+ if (this.replaceables$.next(i.filter((r) => r.replaceable)), !i.length)
123
+ return this._state.changeState({ matchesCount: 0, matchesPosition: 0 }), { results: [] };
124
+ const s = this._moveToInitialMatch(n, i);
129
125
  return this._state.changeState({
130
126
  matchesCount: i.length,
131
- matchesPosition: r + 1
127
+ matchesPosition: s + 1
132
128
  // the matches position start from 1
133
- }), {
134
- results: i
135
- };
129
+ }), { results: i };
130
+ }
131
+ /** Terminate the current searching session, when searching string is empty. */
132
+ _stopSearching() {
133
+ var e;
134
+ 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({
135
+ findCompleted: !1,
136
+ matchesCount: 0,
137
+ matchesPosition: 0
138
+ });
139
+ }
140
+ // When a document's content changes, we should reset all matches and try to move to the next match.
141
+ _subscribeToModelsChanges(e) {
142
+ const n = this._currentSearchingDisposables = new ot(), i = Ce(e.map((s) => s.matchesUpdate$)).pipe(bt(220)).subscribe(([...s]) => {
143
+ const r = this._matches = s.flat();
144
+ if (r.length) {
145
+ const a = this._moveToInitialMatch(this._findModels, r, !0);
146
+ this._state.changeState({ matchesCount: r.length, matchesPosition: a + 1 }), this.replaceables$.next(r.filter((o) => o.replaceable));
147
+ } else
148
+ this._state.changeState({ matchesCount: 0, matchesPosition: 0 }), this.replaceables$.next([]);
149
+ });
150
+ e.forEach((s) => n.add(q(s.activelyChangingMatch$.subscribe((r) => {
151
+ const a = this._matches.findIndex((o) => o === r);
152
+ this._state.changeState({ matchesPosition: a + 1 });
153
+ })))), n.add(q(i));
154
+ }
155
+ async replace() {
156
+ return this._matchingModel ? this._matchingModel.replace(this._state.replaceString) : !1;
157
+ }
158
+ async replaceAll() {
159
+ 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 }));
160
+ return e.failure === 0 && this._stopSearching(), e;
161
+ }
162
+ getCurrentMatch() {
163
+ return this._state.matchesPosition > 0 ? this._matches[this._state.matchesPosition - 1] : null;
136
164
  }
137
165
  moveToNextMatch() {
138
- if (!this._positionModel)
166
+ if (!this._matchingModel)
139
167
  return;
140
- const e = this._findModels.length === 1, n = this._positionModel.moveToNextMatch(e);
168
+ const e = this._findModels.length === 1, n = this._matchingModel.moveToNextMatch({ loop: e });
141
169
  if (n) {
142
- const i = this._matches.findIndex((r) => r === n);
143
- this._state.changeState({
170
+ const i = this._matches.findIndex((s) => s === n);
171
+ this.currentMatch$.next(n), this._state.changeState({
144
172
  matchesPosition: i + 1
145
173
  });
146
174
  } else {
147
- const i = this._findModels.findIndex((s) => s === this._positionModel), r = this._findModels[(i + 1) % this._findModels.length], o = r.moveToNextMatch(), a = this._matches.findIndex((s) => s === o);
148
- this._positionModel = r, this._state.changeState({
175
+ const i = this._findModels.findIndex((o) => o === this._matchingModel), s = this._findModels[(i + 1) % this._findModels.length], r = s.moveToNextMatch(), a = this._matches.findIndex((o) => o === r);
176
+ this.currentMatch$.next(r), this._matchingModel = s, this._state.changeState({
149
177
  matchesPosition: a + 1
150
178
  });
151
179
  }
152
180
  }
153
181
  moveToPreviousMatch() {
154
- if (!this._positionModel)
182
+ if (!this._matchingModel)
155
183
  return;
156
- const e = this._findModels.length === 1, n = this._positionModel.moveToPreviousMatch(e);
184
+ const e = this._findModels.length === 1, n = this._matchingModel.moveToPreviousMatch({ loop: e });
157
185
  if (n) {
158
- const i = this._matches.findIndex((r) => r === n);
159
- this._state.changeState({
186
+ const i = this._matches.findIndex((s) => s === n);
187
+ this.currentMatch$.next(n), this._state.changeState({
160
188
  matchesPosition: i + 1
161
189
  });
162
190
  } else {
163
- const i = this._findModels.findIndex((s) => s === this._positionModel), r = this._findModels[(i - 1 + this._findModels.length) % this._findModels.length], o = r.moveToPreviousMatch(), a = this._matches.findIndex((s) => s === o);
164
- this._positionModel = r, this._state.changeState({
191
+ const i = this._findModels.findIndex((o) => o === this._matchingModel), s = this._findModels[(i - 1 + this._findModels.length) % this._findModels.length], r = s.moveToPreviousMatch(), a = this._matches.findIndex((o) => o === r);
192
+ this.currentMatch$.next(r), this._matchingModel = s, this._state.changeState({
165
193
  matchesPosition: a + 1
166
194
  });
167
195
  }
168
196
  }
169
- // TODO@wzhudev: some cold could definitely be reused. Reuse them.
170
- _moveToInitialMatch(e, n) {
171
- var s;
172
- const i = (s = this._univerInstanceService.getFocusedUniverInstance()) == null ? void 0 : s.getUnitId();
173
- if (!i)
197
+ _moveToInitialMatch(e, n, i = !1) {
198
+ var d;
199
+ const s = (d = this._univerInstanceService.getFocusedUniverInstance()) == null ? void 0 : d.getUnitId();
200
+ if (!s)
174
201
  return -1;
175
- const r = e.find((h) => h.unitId === i);
202
+ const r = e.find((u) => u.unitId === s);
176
203
  if (r) {
177
- this._positionModel = r;
178
- const h = r.moveToNextMatch();
179
- return n.findIndex((g) => g === h);
204
+ this._matchingModel = r;
205
+ const u = r.moveToNextMatch({ stayIfOnMatch: !0, noFocus: i }), p = n.findIndex((f) => f === u);
206
+ return this.currentMatch$.next(u), p;
180
207
  }
181
- this._positionModel = e[0];
182
- const o = this._positionModel.moveToNextMatch();
183
- return this._matches.findIndex((h) => h === o);
184
- }
185
- _cancelFinding() {
186
- this._providers.forEach((e) => e.cancel()), this._state.changeState({
187
- matchesCount: 0,
188
- matchesPosition: 0
189
- });
208
+ this._matchingModel = e[0];
209
+ const a = this._matchingModel.moveToNextMatch({ noFocus: i }), o = this._matches.findIndex((u) => u === a);
210
+ return this.currentMatch$.next(a), o;
190
211
  }
191
212
  };
192
- T = Y([
193
- x(2, B),
194
- x(3, G)
195
- ], T);
196
- function Q() {
213
+ K = De([
214
+ w(2, fe),
215
+ w(3, pe)
216
+ ], K);
217
+ var Y = /* @__PURE__ */ ((t) => (t.ROW = "row", t.COLUMN = "column", t))(Y || {}), Z = /* @__PURE__ */ ((t) => (t.VALUE = "value", t.FORMULA = "formula", t))(Z || {}), J = /* @__PURE__ */ ((t) => (t.SUBUNIT = "subunit", t.UNIT = "unit", t))(J || {});
218
+ function ie() {
197
219
  return {
198
- revealed: !0,
220
+ caseSensitive: !1,
221
+ findBy: "value",
222
+ findCompleted: !1,
223
+ findDirection: "row",
224
+ findScope: "subunit",
199
225
  findString: "",
200
- replaceRevealed: !1,
226
+ inputtingFindString: "",
227
+ matchesCount: 0,
201
228
  matchesPosition: 0,
202
- matchesCount: 0
229
+ matchesTheWholeCell: !1,
230
+ replaceRevealed: !1,
231
+ replaceString: "",
232
+ revealed: !0
203
233
  };
204
234
  }
205
- class ke {
235
+ class Wt {
206
236
  constructor() {
207
- l(this, "_stateUpdates$", new be());
208
- l(this, "stateUpdates$", this._stateUpdates$.asObservable());
209
- l(this, "_state$", new Ee(Q()));
210
- l(this, "state$", this._state$.asObservable());
211
- // TODO@wzhudev: put all state properties here
212
- l(this, "_findString", "");
213
- l(this, "_revealed", !1);
214
- l(this, "_replaceRevealed", !1);
215
- l(this, "_matchesPosition", 0);
216
- l(this, "_matchesCount", 0);
237
+ c(this, "_stateUpdates$", new Re());
238
+ c(this, "stateUpdates$", this._stateUpdates$.asObservable());
239
+ c(this, "_state$", new F(ie()));
240
+ c(this, "state$", this._state$.asObservable());
241
+ c(this, "_findString", "");
242
+ c(this, "_inputtingFindString", "");
243
+ c(this, "_replaceString", "");
244
+ c(this, "_revealed", !1);
245
+ c(this, "_replaceRevealed", !1);
246
+ c(this, "_matchesPosition", 0);
247
+ c(this, "_matchesCount", 0);
248
+ c(this, "_caseSensitive", !0);
249
+ c(this, "_matchesTheWholeCell", !1);
250
+ c(this, "_findDirection", "row");
251
+ c(this, "_findScope", "subunit");
252
+ c(this, "_findBy", "value");
253
+ c(this, "_findCompleted", !1);
217
254
  }
218
255
  get state() {
219
256
  return this._state$.getValue();
220
257
  }
258
+ get inputtingFindString() {
259
+ return this._inputtingFindString;
260
+ }
221
261
  get findString() {
222
262
  return this._findString;
223
263
  }
264
+ get revealed() {
265
+ return this._revealed;
266
+ }
267
+ get replaceRevealed() {
268
+ return this._replaceRevealed;
269
+ }
270
+ get matchesPosition() {
271
+ return this._matchesPosition;
272
+ }
273
+ get matchesCount() {
274
+ return this._matchesCount;
275
+ }
276
+ get replaceString() {
277
+ return this._replaceString;
278
+ }
279
+ get caseSensitive() {
280
+ return this._caseSensitive;
281
+ }
282
+ get matchesTheWholeCell() {
283
+ return this._matchesTheWholeCell;
284
+ }
285
+ get findDirection() {
286
+ return this._findDirection;
287
+ }
288
+ get findScope() {
289
+ return this._findScope;
290
+ }
291
+ get findBy() {
292
+ return this._findBy;
293
+ }
294
+ get findCompleted() {
295
+ return this._findCompleted;
296
+ }
224
297
  changeState(e) {
225
298
  let n = !1;
226
299
  const i = {};
227
- 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.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), n && (this._stateUpdates$.next(i), this._state$.next({
300
+ 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({
301
+ caseSensitive: this._caseSensitive,
302
+ findBy: this._findBy,
303
+ findCompleted: this._findCompleted,
304
+ findDirection: this._findDirection,
305
+ findScope: this._findScope,
228
306
  findString: this._findString,
229
- revealed: this._revealed,
230
- replaceRevealed: this._replaceRevealed,
307
+ inputtingFindString: this._inputtingFindString,
231
308
  matchesCount: this._matchesCount,
232
- matchesPosition: this._matchesPosition
233
- }));
309
+ matchesPosition: this._matchesPosition,
310
+ matchesTheWholeCell: this._matchesTheWholeCell,
311
+ replaceRevealed: this._replaceRevealed,
312
+ revealed: this._revealed
313
+ }), this._stateUpdates$.next(i));
234
314
  }
235
315
  }
236
- let b = class extends E {
237
- constructor(e, n, i) {
316
+ let Q = class extends X {
317
+ constructor(e, n) {
238
318
  super();
239
- l(this, "_providers", /* @__PURE__ */ new Set());
240
- l(this, "_state", new ke());
241
- l(this, "_model");
242
- this._injector = e, this._univerInstanceService = n, this._logService = i;
319
+ c(this, "_providers", /* @__PURE__ */ new Set());
320
+ c(this, "_state", new Wt());
321
+ c(this, "_model");
322
+ c(this, "_currentMatch$", new F(null));
323
+ c(this, "currentMatch$", this._currentMatch$.asObservable());
324
+ c(this, "_replaceables$", new F([]));
325
+ c(this, "replaceables$", this._replaceables$.asObservable());
326
+ c(this, "_focusSignal$", new Re());
327
+ c(this, "focusSignal$", this._focusSignal$.asObservable());
328
+ this._injector = e, this._contextService = n;
243
329
  }
244
330
  get stateUpdates$() {
245
331
  return this._state.stateUpdates$;
@@ -247,77 +333,122 @@ let b = class extends E {
247
333
  get state$() {
248
334
  return this._state.state$;
249
335
  }
336
+ get revealed() {
337
+ return this._state.revealed;
338
+ }
339
+ get replaceRevealed() {
340
+ return this._state.replaceRevealed;
341
+ }
342
+ dispose() {
343
+ super.dispose(), this._currentMatch$.next(null), this._currentMatch$.complete(), this._replaceables$.next([]), this._replaceables$.complete(), this._focusSignal$.complete();
344
+ }
345
+ getCurrentMatch() {
346
+ var e;
347
+ return (e = this._model) == null ? void 0 : e.getCurrentMatch();
348
+ }
349
+ getFindString() {
350
+ return this._state.findString;
351
+ }
250
352
  changeFindString(e) {
251
- this._state.changeState({
252
- findString: e
253
- });
353
+ this._state.changeState({ findString: e });
354
+ }
355
+ focusFindInput() {
356
+ this._focusSignal$.next();
357
+ }
358
+ changeInputtingFindString(e) {
359
+ e ? this._state.changeState({ inputtingFindString: e }) : this._state.changeState({ inputtingFindString: "", findString: "" });
360
+ }
361
+ changeReplaceString(e) {
362
+ this._state.changeState({ replaceString: e });
363
+ }
364
+ changeMatchesTheWholeCell(e) {
365
+ this._state.changeState({ matchesTheWholeCell: e });
366
+ }
367
+ changeCaseSensitive(e) {
368
+ this._state.changeState({ caseSensitive: e });
369
+ }
370
+ changeFindBy(e) {
371
+ this._state.changeState({ findBy: e }), this._toggleDisplayRawFormula(
372
+ e === "formula"
373
+ /* FORMULA */
374
+ );
375
+ }
376
+ changeFindScope(e) {
377
+ this._state.changeState({ findScope: e });
378
+ }
379
+ changeFindDirection(e) {
380
+ this._state.changeState({ findDirection: e });
254
381
  }
255
382
  moveToNextMatch() {
256
- var e;
257
- this._model && ((e = this._model) == null || e.moveToNextMatch());
383
+ this._model && (this._state.replaceRevealed && !this._model.searched ? (this._state.changeState({ findString: this._state.inputtingFindString }), this._model.start()) : this._model.moveToNextMatch(), this._focusSignal$.next());
258
384
  }
259
385
  moveToPreviousMatch() {
260
- var e;
261
- this._model && ((e = this._model) == null || e.moveToPreviousMatch());
386
+ this._model && (this._state.replaceRevealed && !this._model.searched ? (this._state.changeState({ findString: this._state.inputtingFindString }), this._model.start()) : this._model.moveToPreviousMatch(), this._focusSignal$.next());
262
387
  }
263
- replace() {
264
- return !0;
388
+ async replace() {
389
+ return this._model ? this._model.replace() : !1;
265
390
  }
266
- replaceAll() {
267
- return !0;
391
+ async replaceAll() {
392
+ if (!this._model)
393
+ throw new Error("[FindReplaceService] replaceAll: model is not initialized!");
394
+ return this._model.replaceAll();
268
395
  }
269
396
  revealReplace() {
270
- this._state.changeState({ replaceRevealed: !0 });
397
+ this._state.changeState({ replaceRevealed: !0, inputtingFindString: this._state.findString }), this._toggleRevealReplace(!0);
271
398
  }
272
- disposeModel() {
273
- var e;
274
- (e = this._model) == null || e.dispose(), this._model = null;
275
- }
276
- start() {
399
+ start(e = !1) {
277
400
  if (this._providers.size === 0)
278
401
  return !1;
279
- this._model = this._injector.createInstance(T, this._state, this._providers);
280
- const e = Q();
281
- return e.revealed = !0, this._state.changeState(e), !0;
402
+ 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));
403
+ const n = ie();
404
+ return e && (n.replaceRevealed = !0), this._state.changeState(n), this._toggleRevealReplace(e), !0;
405
+ }
406
+ find() {
407
+ var e;
408
+ (e = this._model) == null || e.start();
282
409
  }
283
- end() {
284
- return this._state.changeState({ revealed: !1, replaceRevealed: !1 }), !0;
410
+ terminate() {
411
+ var e;
412
+ (e = this._model) == null || e.dispose(), this._model = null, this._toggleDisplayRawFormula(!1), this._toggleRevealReplace(!1);
285
413
  }
286
414
  registerFindReplaceProvider(e) {
287
- return this._providers.add(e), ue(() => this._providers.delete(e));
415
+ return this._providers.add(e), q(() => this._providers.delete(e));
416
+ }
417
+ _toggleRevealReplace(e) {
418
+ this._contextService.setContextValue(Pe, e);
419
+ }
420
+ _toggleDisplayRawFormula(e) {
421
+ this._contextService.setContextValue(Ft, e);
288
422
  }
289
423
  };
290
- b = Y([
291
- x(0, S(H)),
292
- x(1, G),
293
- x(2, B)
294
- ], b);
295
- const D = {
424
+ Q = De([
425
+ w(0, y(me)),
426
+ w(1, U)
427
+ ], Q);
428
+ const W = {
296
429
  id: "ui.operation.open-find-dialog",
297
- type: m.OPERATION,
298
- handler: (t) => (t.get(f).start(), !0)
299
- }, X = {
430
+ type: b.OPERATION,
431
+ handler: (t) => {
432
+ const e = t.get(v);
433
+ return e.revealed ? e.focusFindInput() : e.start(), !0;
434
+ }
435
+ }, ne = {
300
436
  id: "ui.operation.open-replace-dialog",
301
- type: m.OPERATION,
302
- handler: (t) => (t.get(f).start(), !0)
303
- }, ze = {
304
- id: "ui.operation.toggle-replace-dialog",
305
- type: m.OPERATION,
306
- handler: (t) => (t.get(f), !0)
307
- }, ee = {
308
- id: "ui.operation.close-find-replace-dialog",
309
- type: m.OPERATION,
310
- handler: (t) => !0
311
- }, te = {
312
- type: m.OPERATION,
437
+ type: b.OPERATION,
438
+ handler: (t) => {
439
+ const e = t.get(v);
440
+ return e.revealed ? e.replaceRevealed ? e.focusFindInput() : e.revealReplace() : e.start(!0), !0;
441
+ }
442
+ }, Oe = {
443
+ type: b.OPERATION,
313
444
  id: "ui.operation.go-to-next-match",
314
- handler: (t) => (t.get(f).moveToNextMatch(), !0)
315
- }, ie = {
316
- type: m.OPERATION,
445
+ handler: (t) => (t.get(v).moveToNextMatch(), !0)
446
+ }, Te = {
447
+ type: b.OPERATION,
317
448
  id: "ui.operation.go-to-previous-match",
318
- handler: (t) => (t.get(f).moveToPreviousMatch(), !0)
319
- }, _ = "FIND_REPLACE_ACTIVATED";
320
- var ne = { exports: {} }, O = {};
449
+ handler: (t) => (t.get(v).moveToPreviousMatch(), !0)
450
+ };
451
+ var Ee = { exports: {} }, G = {};
321
452
  /**
322
453
  * @license React
323
454
  * react-jsx-runtime.production.min.js
@@ -327,262 +458,487 @@ var ne = { exports: {} }, O = {};
327
458
  * This source code is licensed under the MIT license found in the
328
459
  * LICENSE file in the root directory of this source tree.
329
460
  */
330
- var Ke = Fe, qe = Symbol.for("react.element"), Ze = Symbol.for("react.fragment"), Je = Object.prototype.hasOwnProperty, Ye = Ke.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, Qe = { key: !0, ref: !0, __self: !0, __source: !0 };
331
- function re(t, e, n) {
332
- var i, r = {}, o = null, a = null;
333
- n !== void 0 && (o = "" + n), e.key !== void 0 && (o = "" + e.key), e.ref !== void 0 && (a = e.ref);
461
+ var Gt = Pt, kt = Symbol.for("react.element"), Vt = Symbol.for("react.fragment"), Ht = Object.prototype.hasOwnProperty, qt = Gt.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, zt = { key: !0, ref: !0, __self: !0, __source: !0 };
462
+ function $e(t, e, n) {
463
+ var i, s = {}, r = null, a = null;
464
+ n !== void 0 && (r = "" + n), e.key !== void 0 && (r = "" + e.key), e.ref !== void 0 && (a = e.ref);
334
465
  for (i in e)
335
- Je.call(e, i) && !Qe.hasOwnProperty(i) && (r[i] = e[i]);
466
+ Ht.call(e, i) && !zt.hasOwnProperty(i) && (s[i] = e[i]);
336
467
  if (t && t.defaultProps)
337
468
  for (i in e = t.defaultProps, e)
338
- r[i] === void 0 && (r[i] = e[i]);
339
- return { $$typeof: qe, type: t, key: o, ref: a, props: r, _owner: Ye.current };
469
+ s[i] === void 0 && (s[i] = e[i]);
470
+ return { $$typeof: kt, type: t, key: r, ref: a, props: s, _owner: qt.current };
340
471
  }
341
- O.Fragment = Ze;
342
- O.jsx = re;
343
- O.jsxs = re;
344
- ne.exports = O;
345
- var d = ne.exports;
346
- const Xe = "univer-find-replace-expand-container", L = {
347
- findReplaceExpandContainer: Xe
472
+ G.Fragment = Vt;
473
+ G.jsx = $e;
474
+ G.jsxs = $e;
475
+ Ee.exports = G;
476
+ var l = Ee.exports;
477
+ const Ne = {
478
+ id: "ui.command.replace-current-match",
479
+ type: b.COMMAND,
480
+ handler: (t) => t.get(v).replace()
481
+ }, Kt = "CONFIRM_REPLACE_ALL", Ae = {
482
+ id: "ui.command.replace-all-matches",
483
+ type: b.COMMAND,
484
+ handler: async (t) => {
485
+ const e = t.get(pt), n = t.get(P), i = t.get(ve);
486
+ if (!await e.confirm({
487
+ id: Kt,
488
+ title: { title: n.t("find-replace.replace.confirm.title") },
489
+ cancelText: n.t("button.cancel"),
490
+ confirmText: n.t("button.confirm")
491
+ }))
492
+ return !1;
493
+ const r = await t.get(v).replaceAll(), { success: a, failure: o } = r;
494
+ return o > 0 ? (a === 0 ? i.show({
495
+ type: $.Error,
496
+ content: n.t("find-replace.replace.all-failure")
497
+ }) : i.show({
498
+ type: $.Warning,
499
+ content: n.t("find-replace.replace.partial-success", `${a}`, `${o}`)
500
+ }), !1) : (i.show({
501
+ type: $.Success,
502
+ content: n.t("find-replace.replace.all-success", `${a}`)
503
+ }), !0);
504
+ }
348
505
  };
349
- function et() {
350
- const t = y(f), e = y(j), n = y(W), [i, r] = $(""), [o, a] = $(""), s = z(null), h = Ne(t.state$, !0), { matchesCount: v, matchesPosition: g } = h, oe = M(() => t.revealReplace(), [t]), ae = M(
351
- (c) => t.changeFindString(c),
352
- // FIXME@wzhudev: this throttle function has no leading and taling config hence has some problems
353
- // throttle((findString: string) => findReplaceService.changeFindString(findString), FIND_THROTTLE_TIME),
354
- [t]
355
- ), se = M(
356
- (c) => {
357
- r(c), ae(c);
358
- },
359
- [t]
360
- ), N = M(
361
- (c) => {
362
- a(c);
363
- },
364
- [t]
365
- );
366
- De(() => {
367
- let c;
368
- return s.current && (c = n.registerContainerElement(s.current)), () => c == null ? void 0 : c.dispose();
369
- }, [s.current]);
370
- function ce() {
371
- return /* @__PURE__ */ d.jsxs(A, { children: [
372
- /* @__PURE__ */ d.jsx(
373
- $e,
506
+ function je(t) {
507
+ const { findCompleted: e, localeService: n, matchesCount: i, matchesPosition: s, findString: r, findReplaceService: a, onChange: o, ...d } = t, p = e && i === 0 ? n.t("find-replace.dialog.no-result") : i === 0 ? " " : void 0;
508
+ return /* @__PURE__ */ l.jsx(
509
+ Ot,
510
+ {
511
+ autoFocus: !0,
512
+ placeholder: n.t("find-replace.dialog.find-placeholder"),
513
+ slot: /* @__PURE__ */ l.jsx(
514
+ Tt,
374
515
  {
375
- autoFocus: !0,
376
- placeholder: e.t("univer.find-replace.dialog.find-placeholder"),
377
- slot: /* @__PURE__ */ d.jsx(
378
- Ae,
379
- {
380
- loop: !0,
381
- value: g,
382
- total: v,
383
- onChange: (c) => {
384
- g === v && c === 1 ? t.moveToNextMatch() : g === 1 && c === v || c < g ? t.moveToPreviousMatch() : t.moveToNextMatch();
385
- }
386
- }
387
- ),
388
- value: i,
389
- onChange: (c) => se(c)
516
+ loop: !0,
517
+ text: p,
518
+ value: s,
519
+ total: i,
520
+ onChange: (f) => {
521
+ s === i && f === 1 ? a.moveToNextMatch() : s === 1 && f === i || f < s ? a.moveToPreviousMatch() : a.moveToNextMatch();
522
+ }
390
523
  }
391
524
  ),
392
- /* @__PURE__ */ d.jsx("div", { className: L.findReplaceExpandContainer, children: /* @__PURE__ */ d.jsx(I, { type: "text", size: "small", onClick: oe, children: e.t("univer.find-replace.dialog.advanced-finding") }) })
393
- ] });
394
- }
395
- function le() {
396
- return /* @__PURE__ */ d.jsxs(A, { children: [
397
- /* @__PURE__ */ d.jsx(P, { label: e.t("univer.find-replace.dialog.find"), children: /* @__PURE__ */ d.jsx(
398
- U,
525
+ value: r,
526
+ onChange: (f) => o == null ? void 0 : o(f),
527
+ ...d
528
+ }
529
+ );
530
+ }
531
+ const Yt = "univer-find-replace-dialog-container", Zt = "univer-find-replace-expand-container", Jt = "univer-button-text", Qt = "univer-find-replace-buttons-group", Xt = "univer-find-replace-buttons-group-right", L = {
532
+ findReplaceDialogContainer: Yt,
533
+ findReplaceExpandContainer: Zt,
534
+ buttonText: Jt,
535
+ findReplaceButtonsGroup: Qt,
536
+ findReplaceButtonsGroupRight: Xt
537
+ };
538
+ function we(t, e) {
539
+ const n = _(() => {
540
+ var s;
541
+ (s = document.querySelector(".univer-find-input input")) == null || s.focus();
542
+ }, []), i = _(() => {
543
+ const s = document.querySelectorAll(".univer-find-replace-dialog-container .univer-select-selection-search-input");
544
+ return Array.from(s).some((r) => r === document.activeElement);
545
+ }, []);
546
+ return Dt(e, () => ({ focus: n, selectHasFocus: i })), j(() => {
547
+ const s = t.focusSignal$.subscribe(() => n());
548
+ return () => s.unsubscribe();
549
+ }, [t, n]), { focus: n, selectHasFocus: i };
550
+ }
551
+ const ei = B(function(e, n) {
552
+ const i = S(P), s = S(v), r = S(ee), a = I(s.state$, void 0, !0), { findCompleted: o, findString: d, matchesCount: u, matchesPosition: p } = a, f = _(() => {
553
+ r.executeCommand(ne.id);
554
+ }, [r]), O = _((C) => s.changeFindString(C), [s]);
555
+ return we(s, n), /* @__PURE__ */ l.jsxs(E, { children: [
556
+ /* @__PURE__ */ l.jsx(
557
+ je,
558
+ {
559
+ findCompleted: o,
560
+ className: "univer-find-input",
561
+ matchesCount: u,
562
+ matchesPosition: p,
563
+ findReplaceService: s,
564
+ localeService: i,
565
+ findString: d,
566
+ onChange: O
567
+ }
568
+ ),
569
+ /* @__PURE__ */ l.jsx("div", { className: L.findReplaceExpandContainer, children: /* @__PURE__ */ l.jsx(N, { type: "text", size: "small", onClick: f, children: i.t("find-replace.dialog.advanced-finding") }) })
570
+ ] });
571
+ }), ti = B(function(e, n) {
572
+ const i = S(v), s = S(P), r = S(ee), a = S(ve), o = I(i.currentMatch$, void 0, !0), d = I(i.replaceables$, void 0, !0), u = I(i.state$, void 0, !0), {
573
+ matchesCount: p,
574
+ matchesPosition: f,
575
+ findString: O,
576
+ inputtingFindString: C,
577
+ replaceString: Be,
578
+ caseSensitive: ae,
579
+ matchesTheWholeCell: oe,
580
+ findDirection: We,
581
+ findScope: Ge,
582
+ findBy: ke,
583
+ findCompleted: V
584
+ } = u, Ve = C.length === 0, He = p === 0 || !(o != null && o.replaceable), qe = d.length === 0, ze = _(
585
+ (h) => i.changeInputtingFindString(h),
586
+ [i]
587
+ ), Ke = _(
588
+ (h) => i.changeReplaceString(h),
589
+ [i]
590
+ ), { focus: Ye } = we(i, n), Ze = _(() => {
591
+ O === C ? i.moveToNextMatch() : (i.changeFindString(C), i.find());
592
+ }, [O, C, i]), Je = _(() => r.executeCommand(Ne.id), [r]), Qe = _(async () => {
593
+ await r.executeCommand(Ae.id), Ye();
594
+ }, [r]), Xe = _((h) => {
595
+ i.changeFindDirection(h);
596
+ }, [i]), et = _((h) => {
597
+ i.changeFindScope(h);
598
+ }, [i]), tt = _((h) => {
599
+ i.changeFindBy(h);
600
+ }, [i]), it = ni(s), nt = si(s), st = ri(s);
601
+ return j(() => {
602
+ const h = V && p === 0;
603
+ let T = null;
604
+ return h && (T = a.show({
605
+ content: s.t("find-replace.dialog.no-match"),
606
+ type: $.Warning,
607
+ delay: 5e3
608
+ })), () => T == null ? void 0 : T.dispose();
609
+ }, [V, p, a, s]), /* @__PURE__ */ l.jsxs(E, { children: [
610
+ /* @__PURE__ */ l.jsx(R, { label: s.t("find-replace.dialog.find"), children: /* @__PURE__ */ l.jsx(
611
+ je,
612
+ {
613
+ findCompleted: V,
614
+ className: "univer-find-input",
615
+ matchesCount: p,
616
+ matchesPosition: f,
617
+ findReplaceService: i,
618
+ localeService: s,
619
+ findString: C,
620
+ onChange: ze
621
+ }
622
+ ) }),
623
+ /* @__PURE__ */ l.jsx(R, { label: s.t("find-replace.dialog.replace"), children: /* @__PURE__ */ l.jsx(
624
+ Et,
625
+ {
626
+ placeholder: s.t("find-replace.dialog.replace-placeholder"),
627
+ value: Be,
628
+ onChange: (h) => Ke(h)
629
+ }
630
+ ) }),
631
+ /* @__PURE__ */ l.jsx(R, { label: s.t("find-replace.dialog.find-direction.title"), children: /* @__PURE__ */ l.jsx(H, { value: We, options: nt, onChange: Xe }) }),
632
+ /* @__PURE__ */ l.jsx(le, { children: /* @__PURE__ */ l.jsxs(E, { children: [
633
+ /* @__PURE__ */ l.jsx(R, { label: s.t("find-replace.dialog.find-scope.title"), children: /* @__PURE__ */ l.jsx(H, { value: Ge, options: it, onChange: et }) }),
634
+ /* @__PURE__ */ l.jsx(R, { label: s.t("find-replace.dialog.find-by.title"), children: /* @__PURE__ */ l.jsx(H, { value: ke, options: st, onChange: tt }) })
635
+ ] }) }),
636
+ /* @__PURE__ */ l.jsx(le, { children: /* @__PURE__ */ l.jsxs(E, { children: [
637
+ /* @__PURE__ */ l.jsx(R, { children: /* @__PURE__ */ l.jsx(
638
+ de,
399
639
  {
400
- placeholder: e.t("univer.find-replace.dialog.find-placeholder"),
401
- autoFocus: !0,
402
- value: i,
403
- onChange: (c) => N(c)
640
+ checked: ae,
641
+ value: ae,
642
+ onChange: (h) => {
643
+ i.changeCaseSensitive(h);
644
+ },
645
+ children: s.t("find-replace.dialog.case-sensitive")
404
646
  }
405
647
  ) }),
406
- /* @__PURE__ */ d.jsx(P, { label: e.t("univer.find-replace.dialog.replace"), children: /* @__PURE__ */ d.jsx(
407
- U,
648
+ /* @__PURE__ */ l.jsx(R, { children: /* @__PURE__ */ l.jsx(
649
+ de,
408
650
  {
409
- placeholder: e.t("univer.find-replace.dialog.replace-placeholder"),
410
- value: o,
411
- onChange: (c) => N(c)
651
+ checked: oe,
652
+ value: oe,
653
+ onChange: (h) => {
654
+ i.changeMatchesTheWholeCell(h);
655
+ },
656
+ children: s.t("find-replace.dialog.match-the-whole-cell")
412
657
  }
413
- ) }),
414
- /* @__PURE__ */ d.jsx(P, { label: e.t("univer.find-replace.dialog.find-range"), children: /* @__PURE__ */ d.jsx(Ue, { value: "123", onChange: () => {
415
- } }) }),
416
- /* @__PURE__ */ d.jsx(I, { type: "primary", children: e.t("univer.find-replace.dialog.find") }),
417
- /* @__PURE__ */ d.jsx(I, { children: e.t("univer.find-replace.dialog.replace") }),
418
- /* @__PURE__ */ d.jsx(I, { children: e.t("univer.find-replace.dialog.replace-all") })
419
- ] });
420
- }
421
- return /* @__PURE__ */ d.jsx("div", { className: L.findReplaceDialogContainer, ref: s, children: h.replaceRevealed ? le() : ce() });
658
+ ) })
659
+ ] }) }),
660
+ /* @__PURE__ */ l.jsxs("div", { className: L.findReplaceButtonsGroup, children: [
661
+ /* @__PURE__ */ l.jsx(N, { type: "primary", onClick: Ze, disabled: Ve, children: s.t("find-replace.dialog.find") }),
662
+ /* @__PURE__ */ l.jsxs("span", { className: L.findReplaceButtonsGroupRight, children: [
663
+ /* @__PURE__ */ l.jsx(N, { disabled: He, onClick: Je, children: s.t("find-replace.dialog.replace") }),
664
+ /* @__PURE__ */ l.jsx(N, { disabled: qe, onClick: Qe, children: s.t("find-replace.dialog.replace-all") })
665
+ ] })
666
+ ] })
667
+ ] });
668
+ });
669
+ function ii() {
670
+ const t = S(v), e = S(Se), n = S(U), i = I(t.state$, void 0, !0), s = z(null);
671
+ j(() => {
672
+ let d;
673
+ return s.current && (d = e.registerContainerElement(s.current)), () => d == null ? void 0 : d.dispose();
674
+ }, [e]);
675
+ const r = z(null), a = _(
676
+ (d) => n.setContextValue(Fe, d),
677
+ [n]
678
+ ), o = _(
679
+ (d) => n.setContextValue(Ie, d),
680
+ [n]
681
+ );
682
+ return j(() => {
683
+ var u;
684
+ const d = yt(document, "focusin").subscribe((p) => {
685
+ var f;
686
+ p.target && ((f = s.current) != null && f.contains(p.target)) ? a(!0) : a(!1), !r.current || !r.current.selectHasFocus() ? o(!0) : o(!1);
687
+ });
688
+ return (u = r.current) == null || u.focus(), a(!0), o(!0), () => {
689
+ d.unsubscribe(), a(!1);
690
+ };
691
+ }, [a, o]), /* @__PURE__ */ l.jsx("div", { className: L.findReplaceDialogContainer, ref: s, children: i.replaceRevealed ? /* @__PURE__ */ l.jsx(ti, { ref: r }) : /* @__PURE__ */ l.jsx(ei, { ref: r }) });
422
692
  }
423
- function tt(t) {
424
- return {
425
- id: D.id,
426
- icon: "SearchIcon",
427
- tooltip: "toolbar.find-replace",
428
- group: Re.TOOLBAR_OTHERS,
429
- type: Me.BUTTON,
430
- positions: [Ie.TOOLBAR_START],
431
- hidden$: Ce(t, pe.SHEET)
432
- };
693
+ function ni(t) {
694
+ const e = t.getCurrentLocale();
695
+ return te(() => [
696
+ { label: t.t("find-replace.dialog.find-scope.current-sheet"), value: J.SUBUNIT },
697
+ { label: t.t("find-replace.dialog.find-scope.workbook"), value: J.UNIT }
698
+ ], [e]);
699
+ }
700
+ function si(t) {
701
+ const e = t.getCurrentLocale();
702
+ return te(() => [
703
+ { label: t.t("find-replace.dialog.find-direction.row"), value: Y.ROW },
704
+ { label: t.t("find-replace.dialog.find-direction.column"), value: Y.COLUMN }
705
+ ], [e]);
706
+ }
707
+ function ri(t) {
708
+ const e = t.getCurrentLocale();
709
+ return te(() => [
710
+ { label: t.t("find-replace.dialog.find-by.value"), value: Z.VALUE },
711
+ { label: t.t("find-replace.dialog.find-by.formula"), value: Z.FORMULA }
712
+ ], [e]);
713
+ }
714
+ function D(t) {
715
+ return t.getContextValue(Fe);
716
+ }
717
+ function ai(t) {
718
+ return t.getContextValue(Pe);
719
+ }
720
+ function Le(t) {
721
+ return t.getContextValue(Ie);
722
+ }
723
+ const k = "7_find-replace-shortcuts";
724
+ function se(t) {
725
+ return t.getContextValue(_e);
433
726
  }
434
- const it = {
435
- id: D.id,
436
- description: "shortcut.find-replace.open-find-dialog",
437
- binding: R.F | F.CTRL_COMMAND,
438
- group: "4_find-replace",
727
+ function re(t) {
728
+ return !t.getContextValue(ge);
729
+ }
730
+ const oi = {
731
+ id: W.id,
732
+ description: "find-replace.shortcut.open-find-dialog",
733
+ binding: x.F | M.CTRL_COMMAND,
734
+ group: k,
439
735
  preconditions(t) {
440
- return !t.getContextValue(_);
736
+ return !D(t) && se(t) && re(t);
441
737
  }
442
- }, nt = {
443
- id: X.id,
444
- description: "shortcut.find-replace.open-replace-dialog",
445
- binding: R.H | F.CTRL_COMMAND,
446
- group: "4_find-replace",
738
+ }, ci = {
739
+ id: W.id,
740
+ description: "find-replace.shortcut.open-find-dialog",
741
+ binding: x.F | M.CTRL_COMMAND,
742
+ mac: x.F | M.MAC_CTRL,
447
743
  preconditions(t) {
448
- return !t.getContextValue(_);
449
- }
450
- }, rt = {
451
- id: ee.id,
452
- description: "shortcut.find-replace.close-dialog",
453
- binding: R.ESC,
454
- group: "4_find-replace",
455
- priority: 1e3,
744
+ return !D(t) && se(t) && re(t);
745
+ }
746
+ }, li = {
747
+ id: ne.id,
748
+ description: "find-replace.shortcut.open-replace-dialog",
749
+ binding: x.H | M.CTRL_COMMAND,
750
+ mac: x.H | M.MAC_CTRL,
751
+ group: k,
456
752
  preconditions(t) {
457
- return !!t.getContextValue(_);
753
+ return se(t) && re(t) && (!D(t) || !ai(t));
458
754
  }
459
- }, ot = {
460
- id: te.id,
461
- description: "shortcut.find-replace.go-to-next-find-match",
462
- binding: R.ENTER,
463
- group: "4_find-replace",
755
+ }, di = {
756
+ id: Oe.id,
757
+ description: "find-replace.shortcut.go-to-next-match",
758
+ binding: x.ENTER,
759
+ group: k,
464
760
  priority: 1e3,
465
761
  preconditions(t) {
466
- return !!t.getContextValue(_);
762
+ return Le(t) && D(t);
467
763
  }
468
- }, at = {
469
- id: ie.id,
470
- description: "shortcut.find-replace.go-to-previous-find-match",
471
- binding: R.ENTER | F.SHIFT,
472
- group: "4_find-replace",
764
+ }, hi = {
765
+ id: Te.id,
766
+ description: "find-replace.shortcut.go-to-previous-match",
767
+ binding: x.ENTER | M.SHIFT,
768
+ group: k,
473
769
  priority: 1e3,
474
770
  preconditions(t) {
475
- return !!t.getContextValue(_);
771
+ return Le(t) && D(t);
476
772
  }
477
773
  };
478
- var st = Object.defineProperty, ct = Object.getOwnPropertyDescriptor, lt = (t, e, n, i) => {
479
- for (var r = i > 1 ? void 0 : i ? ct(e, n) : e, o = t.length - 1, a; o >= 0; o--)
480
- (a = t[o]) && (r = (i ? a(e, n, r) : a(r)) || r);
481
- return i && r && st(e, n, r), r;
482
- }, p = (t, e) => (n, i) => e(n, i, t);
483
- const w = "DESKTOP_FIND_REPLACE_DIALOG";
484
- let C = class extends ve {
485
- constructor(t, e, n, i, r, o, a, s, h, v) {
486
- super(), this._menuService = t, this._shortcutService = e, this._commandService = n, this._findReplaceService = i, this._dialogService = r, this._contextService = o, this._layoutService = a, this._localeService = s, this._componentManager = h, this._injector = v, this._initOperations(), this._initUI(), this._initShortcuts();
487
- }
488
- _initOperations() {
774
+ function ui(t) {
775
+ const e = t.get(U);
776
+ return {
777
+ id: W.id,
778
+ icon: "SearchIcon",
779
+ tooltip: "find-replace.toolbar",
780
+ group: _t.TOOLBAR_OTHERS,
781
+ type: gt.BUTTON,
782
+ positions: [mt.TOOLBAR_START],
783
+ hidden$: vt(t, ct.SHEET),
784
+ disabled$: Ce([
785
+ e.subscribeContextValue$(ge),
786
+ e.subscribeContextValue$(_e)
787
+ ]).pipe(It(([n, i]) => n || !i))
788
+ };
789
+ }
790
+ var fi = Object.defineProperty, pi = Object.getOwnPropertyDescriptor, _i = (t, e, n, i) => {
791
+ for (var s = i > 1 ? void 0 : i ? pi(e, n) : e, r = t.length - 1, a; r >= 0; r--)
792
+ (a = t[r]) && (s = (i ? a(e, n, s) : a(s)) || s);
793
+ return i && s && fi(e, n, s), s;
794
+ }, g = (t, e) => (n, i) => e(n, i, t);
795
+ const he = "DESKTOP_FIND_REPLACE_DIALOG", Ue = 350, gi = 20, mi = 0;
796
+ let A = class extends ht {
797
+ constructor(t, e, n, i, s, r, a, o, d, u, p, f) {
798
+ super(), this._univerInstanceService = t, this._menuService = e, this._shortcutService = n, this._commandService = i, this._findReplaceService = s, this._logService = r, this._dialogService = a, this._contextService = o, this._layoutService = d, this._localeService = u, this._componentManager = p, this._injector = f, this._initCommands(), this._initUI(), this._initShortcuts();
799
+ }
800
+ _initCommands() {
489
801
  [
490
- ee,
491
- D,
492
- X,
493
- ze,
494
- te,
495
- ie
802
+ W,
803
+ ne,
804
+ Oe,
805
+ Te,
806
+ Ae,
807
+ Ne
496
808
  ].forEach((t) => {
497
809
  this.disposeWithMe(this._commandService.registerCommand(t));
498
810
  });
499
811
  }
500
- _initUI() {
501
- [tt].forEach((t) => {
502
- this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(t)));
503
- }), this.disposeWithMe(this._componentManager.register("FindReplaceDialog", et)), this.disposeWithMe(this._componentManager.register("SearchIcon", J)), this._findReplaceService.stateUpdates$.pipe(je(this.dispose$)).subscribe((t) => {
504
- t.revealed === !0 ? this._openPanel() : t.revealed === !1 && this._closePanel();
505
- });
506
- }
507
812
  _initShortcuts() {
508
813
  [
509
- nt,
510
- it,
511
- rt,
512
- at,
513
- ot
514
- ].forEach((t) => {
515
- this.disposeWithMe(this._shortcutService.registerShortcut(t));
516
- });
814
+ li,
815
+ oi,
816
+ ci,
817
+ hi,
818
+ di
819
+ ].forEach((t) => this.disposeWithMe(this._shortcutService.registerShortcut(t)));
820
+ }
821
+ _initUI() {
822
+ this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(ui))), this.disposeWithMe(this._componentManager.register("FindReplaceDialog", ii)), this.disposeWithMe(this._componentManager.register("SearchIcon", ye)), this._findReplaceService.stateUpdates$.pipe(ce(this.dispose$)).subscribe((t) => {
823
+ t.revealed === !0 && this._openPanel();
824
+ }), this.disposeWithMe(
825
+ this._univerInstanceService.focused$.pipe(ce(this.dispose$)).subscribe((t) => {
826
+ (!t || !this._univerInstanceService.getUniverSheetInstance(t)) && this.closePanel();
827
+ })
828
+ );
517
829
  }
518
830
  _openPanel() {
519
831
  this._dialogService.open({
520
- id: w,
832
+ id: he,
521
833
  draggable: !0,
522
- width: 350,
523
- title: { title: this._localeService.t("univer.find-replace.dialog.title") },
834
+ width: Ue,
835
+ title: { title: this._localeService.t("find-replace.dialog.title") },
524
836
  children: { label: "FindReplaceDialog" },
525
- onClose: () => this._closePanel()
526
- }), this._contextService.setContextValue(_, !0);
837
+ destroyOnClose: !0,
838
+ defaultPosition: vi(),
839
+ onClose: () => this.closePanel()
840
+ });
527
841
  }
528
- _closePanel() {
529
- this._dialogService.close(w), this._contextService.setContextValue(_, !1), this._layoutService.focus(), this._findReplaceService.end();
842
+ closePanel() {
843
+ this._dialogService.close(he), this._findReplaceService.terminate(), queueMicrotask(() => this._layoutService.focus());
530
844
  }
531
845
  };
532
- C = lt([
533
- fe(_e.Rendered, C),
534
- p(0, Pe),
535
- p(1, ye),
536
- p(2, ge),
537
- p(3, f),
538
- p(4, Te),
539
- p(5, me),
540
- p(6, W),
541
- p(7, S(j)),
542
- p(8, S(Oe)),
543
- p(9, S(H))
544
- ], C);
545
- const dt = {
546
- univer: {
547
- "find-replace": {
548
- dialog: {
549
- title: "查找",
550
- find: "查找",
551
- replace: "替换",
552
- "replace-all": "替换全部",
553
- "find-range": "查找范围",
554
- "find-placeholder": "输入查找内容",
555
- "advanced-finding": "替换 / 高级查找",
556
- "replace-placeholder": "输入替换内容"
846
+ A = _i([
847
+ lt(dt.Rendered, A),
848
+ g(0, fe),
849
+ g(1, Ct),
850
+ g(2, Rt),
851
+ g(3, ee),
852
+ g(4, v),
853
+ g(5, pe),
854
+ g(6, xt),
855
+ g(7, U),
856
+ g(8, Se),
857
+ g(9, y(P)),
858
+ g(10, y(St)),
859
+ g(11, y(me))
860
+ ], A);
861
+ function vi() {
862
+ const { innerWidth: t } = window;
863
+ return { x: t - Ue - gi, y: mi };
864
+ }
865
+ const Si = {
866
+ "find-replace": {
867
+ toolbar: "查找替换",
868
+ shortcut: {
869
+ "open-find-dialog": "打开查找对话框",
870
+ "open-replace-dialog": "打开替换对话框",
871
+ "close-dialog": "关闭查找替换对话框",
872
+ "go-to-next-match": "下一个匹配项",
873
+ "go-to-previous-match": "下一个匹配项"
874
+ },
875
+ dialog: {
876
+ title: "查找",
877
+ find: "查找",
878
+ replace: "替换",
879
+ "replace-all": "替换全部",
880
+ "find-placeholder": "输入查找内容",
881
+ "advanced-finding": "替换 / 高级查找",
882
+ "replace-placeholder": "输入替换内容",
883
+ "case-sensitive": "匹配大小写",
884
+ "match-the-whole-cell": "匹配整个单元格",
885
+ "find-scope": {
886
+ title: "查找范围",
887
+ "current-sheet": "当前子表",
888
+ workbook: "整个工作簿"
889
+ },
890
+ "find-direction": {
891
+ title: "查找顺序",
892
+ column: "按列查找",
893
+ row: "按行查找"
894
+ },
895
+ "find-by": {
896
+ title: "查找方式",
897
+ formula: "查找公式",
898
+ value: "查找值"
899
+ },
900
+ "no-match": "已完成搜索,但是未找到任何匹配项",
901
+ "no-result": "无结果"
902
+ },
903
+ replace: {
904
+ "all-success": "已全部替换 {0} 个匹配项",
905
+ "all-failure": "替换失败",
906
+ confirm: {
907
+ title: "确定要替换所有的匹配项吗?"
557
908
  }
558
909
  }
559
- }
910
+ },
911
+ "find-replace-shortcuts": "查找替换"
560
912
  };
561
- var ht = Object.defineProperty, ut = Object.getOwnPropertyDescriptor, pt = (t, e, n, i) => {
562
- for (var r = i > 1 ? void 0 : i ? ut(e, n) : e, o = t.length - 1, a; o >= 0; o--)
563
- (a = t[o]) && (r = (i ? a(e, n, r) : a(r)) || r);
564
- return i && r && ht(e, n, r), r;
565
- }, ft = (t, e) => (n, i) => e(n, i, t);
566
- const _t = "FIND_REPLACE";
567
- let V = class extends Se {
913
+ var Ci = Object.defineProperty, Ri = Object.getOwnPropertyDescriptor, xi = (t, e, n, i) => {
914
+ for (var s = i > 1 ? void 0 : i ? Ri(e, n) : e, r = t.length - 1, a; r >= 0; r--)
915
+ (a = t[r]) && (s = (i ? a(e, n, s) : a(s)) || s);
916
+ return i && s && Ci(e, n, s), s;
917
+ }, Mi = (t, e) => (n, i) => e(n, i, t);
918
+ const bi = "FIND_REPLACE";
919
+ let ue = class extends ut {
568
920
  constructor(t, e) {
569
- super(_t), this._injector = t, this._localeService = e, this._localeService.load({
570
- zhCN: dt
921
+ super(bi), this._injector = t, this._localeService = e, this._localeService.load({
922
+ zhCN: Si
571
923
  });
572
924
  }
573
925
  onStarting(t) {
574
- [[C], [f, { useClass: b }]].forEach(
926
+ [[A], [v, { useClass: Q }]].forEach(
575
927
  (e) => {
576
928
  t.add(e);
577
929
  }
578
930
  );
579
931
  }
580
932
  };
581
- V = pt([
582
- ft(1, S(j))
583
- ], V);
933
+ ue = xi([
934
+ Mi(1, y(P))
935
+ ], ue);
584
936
  export {
585
- Ct as FindModel,
586
- f as IFindReplaceService,
587
- V as UniverFindReplacePlugin
937
+ Z as FindBy,
938
+ Y as FindDirection,
939
+ Ni as FindModel,
940
+ A as FindReplaceController,
941
+ J as FindScope,
942
+ v as IFindReplaceService,
943
+ ue as UniverFindReplacePlugin
588
944
  };