@univerjs/find-replace 0.1.2 → 0.1.4

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 he, ILogService as ue, toDisposable as q, IContextService as U, DisposableCollection as ot, CommandType as b, LocaleService as P, ICommandService as ee, FOCUSING_SHEET as fe, EDITOR_ACTIVATED as pe, UniverInstanceType as ct, RxDisposable as lt, OnLifecycle as dt, LifecycleStages as ht, Plugin as ut } from "@univerjs/core";
5
+ import { createIdentifier as ft, Inject as y, Injector as _e } from "@wendellhu/redi";
6
+ import { IConfirmService as pt, IMessageService as ge, useObservable as I, ILayoutService as me, 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 { BehaviorSubject as F, Subject as ve, throttleTime as Mt, combineLatest as Se, debounceTime as bt, fromEvent as yt, map as It, takeUntil as ae } 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 Ce, 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 oe, Checkbox as ce } 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
+ }, Re = 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 xe(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 xe(t, e, n, i, s) {
34
+ return Ce(t.tag, m(m({ key: e }, Nt(t, n, s)), i), (At(t, n).children || []).map(function(r, a) {
35
+ return xe(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
+ Re.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" } }] }] }, Me = B(function(t, e) {
58
+ return Ce(Re, 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
+ Me.displayName = "SearchSingle16";
65
+ const be = "FIND_REPLACE_INPUT_FOCUS", ye = "FIND_REPLACE_DIALOG_FOCUS", Ie = "FIND_REPLACE_REPLACE_REVEALED";
66
+ var Lt = Object.defineProperty, Ut = Object.getOwnPropertyDescriptor, Fe = (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
- class ke {
111
- constructor() {
112
- l(this, "_stateUpdates$", new be());
113
- l(this, "stateUpdates$", this._stateUpdates$.asObservable());
114
- l(this, "_state$", new Ee(Q()));
115
- l(this, "state$", this._state$.asObservable());
116
- // TODO@wzhudev: put all state properties here
117
- l(this, "_findString", "");
118
- l(this, "_revealed", !1);
119
- l(this, "_replaceRevealed", !1);
120
- l(this, "_matchesPosition", 0);
121
- l(this, "_matchesCount", 0);
122
- }
123
- get state() {
124
- return this._state$.getValue();
125
- }
126
- get findString() {
127
- return this._findString;
128
- }
129
- changeState(e) {
130
- let n = !1;
131
- const i = {};
132
- 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({
133
- findString: this._findString,
134
- revealed: this._revealed,
135
- replaceRevealed: this._replaceRevealed,
136
- matchesCount: this._matchesCount,
137
- matchesPosition: this._matchesPosition
138
- }));
139
- }
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";
140
76
  }
141
- let T = class extends E {
142
- constructor(e, n, i, r) {
77
+ let K = class extends X {
78
+ constructor(e, n, i, s) {
143
79
  super();
144
- l(this, "_matchPositionFindModel", null);
145
- l(this, "_findModels", []);
146
- l(this, "_matches", []);
147
- l(this, "_positionModel", null);
148
- this._state = e, this._providers = n, this._logService = i, this._univerInstanceService = r, this._state.stateUpdates$.subscribe((o) => {
149
- typeof o.findString < "u" && (o.findString ? this.find() : this._cancelFinding());
150
- });
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
+ );
151
94
  }
152
- async find() {
153
- this._cancelFinding();
154
- 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();
155
- if (this._matches = i, !i.length)
156
- return {
157
- results: []
158
- };
159
- 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);
160
125
  return this._state.changeState({
161
126
  matchesCount: i.length,
162
- matchesPosition: r + 1
127
+ matchesPosition: s + 1
163
128
  // the matches position start from 1
164
- }), {
165
- results: i
166
- };
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 = Se(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;
167
164
  }
168
165
  moveToNextMatch() {
169
- if (!this._positionModel)
166
+ if (!this._matchingModel)
170
167
  return;
171
- const e = this._findModels.length === 1, n = this._positionModel.moveToNextMatch(e);
168
+ const e = this._findModels.length === 1, n = this._matchingModel.moveToNextMatch({ loop: e });
172
169
  if (n) {
173
- const i = this._matches.findIndex((r) => r === n);
174
- this._state.changeState({
170
+ const i = this._matches.findIndex((s) => s === n);
171
+ this.currentMatch$.next(n), this._state.changeState({
175
172
  matchesPosition: i + 1
176
173
  });
177
174
  } else {
178
- 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);
179
- 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({
180
177
  matchesPosition: a + 1
181
178
  });
182
179
  }
183
180
  }
184
181
  moveToPreviousMatch() {
185
- if (!this._positionModel)
182
+ if (!this._matchingModel)
186
183
  return;
187
- const e = this._findModels.length === 1, n = this._positionModel.moveToPreviousMatch(e);
184
+ const e = this._findModels.length === 1, n = this._matchingModel.moveToPreviousMatch({ loop: e });
188
185
  if (n) {
189
- const i = this._matches.findIndex((r) => r === n);
190
- this._state.changeState({
186
+ const i = this._matches.findIndex((s) => s === n);
187
+ this.currentMatch$.next(n), this._state.changeState({
191
188
  matchesPosition: i + 1
192
189
  });
193
190
  } else {
194
- 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);
195
- 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({
196
193
  matchesPosition: a + 1
197
194
  });
198
195
  }
199
196
  }
200
- // TODO@wzhudev: some cold could definitely be reused. Reuse them.
201
- _moveToInitialMatch(e, n) {
202
- var s;
203
- const i = (s = this._univerInstanceService.getFocusedUniverInstance()) == null ? void 0 : s.getUnitId();
204
- 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)
205
201
  return -1;
206
- const r = e.find((h) => h.unitId === i);
202
+ const r = e.find((u) => u.unitId === s);
207
203
  if (r) {
208
- this._positionModel = r;
209
- const h = r.moveToNextMatch();
210
- 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;
211
207
  }
212
- this._positionModel = e[0];
213
- const o = this._positionModel.moveToNextMatch();
214
- return this._matches.findIndex((h) => h === o);
215
- }
216
- _cancelFinding() {
217
- this._providers.forEach((e) => e.cancel()), this._state.changeState({
218
- matchesCount: 0,
219
- matchesPosition: 0
220
- });
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;
221
211
  }
222
212
  };
223
- T = Y([
224
- x(2, B),
225
- x(3, G)
226
- ], T);
227
- function Q() {
213
+ K = Fe([
214
+ w(2, he),
215
+ w(3, ue)
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() {
228
219
  return {
229
- revealed: !0,
220
+ caseSensitive: !1,
221
+ findBy: "value",
222
+ findCompleted: !1,
223
+ findDirection: "row",
224
+ findScope: "subunit",
230
225
  findString: "",
231
- replaceRevealed: !1,
226
+ inputtingFindString: "",
227
+ matchesCount: 0,
232
228
  matchesPosition: 0,
233
- matchesCount: 0
229
+ matchesTheWholeCell: !1,
230
+ replaceRevealed: !1,
231
+ replaceString: "",
232
+ revealed: !0
234
233
  };
235
234
  }
236
- let b = class extends E {
237
- constructor(e, n, i) {
235
+ class Wt {
236
+ constructor() {
237
+ c(this, "_stateUpdates$", new ve());
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);
254
+ }
255
+ get state() {
256
+ return this._state$.getValue();
257
+ }
258
+ get inputtingFindString() {
259
+ return this._inputtingFindString;
260
+ }
261
+ get findString() {
262
+ return this._findString;
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
+ }
297
+ changeState(e) {
298
+ let n = !1;
299
+ const i = {};
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,
306
+ findString: this._findString,
307
+ inputtingFindString: this._inputtingFindString,
308
+ matchesCount: this._matchesCount,
309
+ matchesPosition: this._matchesPosition,
310
+ matchesTheWholeCell: this._matchesTheWholeCell,
311
+ replaceRevealed: this._replaceRevealed,
312
+ revealed: this._revealed
313
+ }), this._stateUpdates$.next(i));
314
+ }
315
+ }
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 ve());
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 });
271
- }
272
- disposeModel() {
273
- var e;
274
- (e = this._model) == null || e.dispose(), this._model = null;
397
+ this._state.changeState({ replaceRevealed: !0, inputtingFindString: this._state.findString }), this._toggleRevealReplace(!0);
275
398
  }
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;
282
405
  }
283
- end() {
284
- return this._state.changeState({ revealed: !1, replaceRevealed: !1 }), !0;
406
+ find() {
407
+ var e;
408
+ (e = this._model) == null || e.start();
409
+ }
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(Ie, 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 = Fe([
425
+ w(0, y(_e)),
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
+ }, Pe = {
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
+ }, De = {
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 Oe = { exports: {} }, G = {};
321
452
  /**
322
453
  * @license React
323
454
  * react-jsx-runtime.production.min.js
@@ -327,262 +458,486 @@ 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 Te(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 = Te;
474
+ G.jsxs = Te;
475
+ Oe.exports = G;
476
+ var l = Oe.exports;
477
+ const Ee = {
478
+ id: "ui.command.replace-current-match",
479
+ type: b.COMMAND,
480
+ handler: (t) => t.get(v).replace()
481
+ }, Kt = "CONFIRM_REPLACE_ALL", $e = {
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(ge);
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 Ne(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 Ae(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 Ae(s, n), /* @__PURE__ */ l.jsxs(E, { children: [
556
+ /* @__PURE__ */ l.jsx(
557
+ Ne,
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(ge), 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: Le,
578
+ caseSensitive: Ue,
579
+ matchesTheWholeCell: Be,
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 } = Ae(i, n), Ze = _(() => {
591
+ O === C ? i.moveToNextMatch() : (i.changeFindString(C), i.find());
592
+ }, [O, C, i]), Je = _(() => r.executeCommand(Ee.id), [r]), Qe = _(async () => {
593
+ await r.executeCommand($e.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
+ Ne,
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: Le,
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(oe, { 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(oe, { children: /* @__PURE__ */ l.jsxs(E, { children: [
637
+ /* @__PURE__ */ l.jsx(R, { children: /* @__PURE__ */ l.jsx(
638
+ ce,
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: Ue,
641
+ onChange: (h) => {
642
+ i.changeCaseSensitive(h);
643
+ },
644
+ children: s.t("find-replace.dialog.case-sensitive")
404
645
  }
405
646
  ) }),
406
- /* @__PURE__ */ d.jsx(P, { label: e.t("univer.find-replace.dialog.replace"), children: /* @__PURE__ */ d.jsx(
407
- U,
647
+ /* @__PURE__ */ l.jsx(R, { children: /* @__PURE__ */ l.jsx(
648
+ ce,
408
649
  {
409
- placeholder: e.t("univer.find-replace.dialog.replace-placeholder"),
410
- value: o,
411
- onChange: (c) => N(c)
650
+ checked: Be,
651
+ onChange: (h) => {
652
+ i.changeMatchesTheWholeCell(h);
653
+ },
654
+ children: s.t("find-replace.dialog.match-the-whole-cell")
412
655
  }
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() });
656
+ ) })
657
+ ] }) }),
658
+ /* @__PURE__ */ l.jsxs("div", { className: L.findReplaceButtonsGroup, children: [
659
+ /* @__PURE__ */ l.jsx(N, { type: "primary", onClick: Ze, disabled: Ve, children: s.t("find-replace.dialog.find") }),
660
+ /* @__PURE__ */ l.jsxs("span", { className: L.findReplaceButtonsGroupRight, children: [
661
+ /* @__PURE__ */ l.jsx(N, { disabled: He, onClick: Je, children: s.t("find-replace.dialog.replace") }),
662
+ /* @__PURE__ */ l.jsx(N, { disabled: qe, onClick: Qe, children: s.t("find-replace.dialog.replace-all") })
663
+ ] })
664
+ ] })
665
+ ] });
666
+ });
667
+ function ii() {
668
+ const t = S(v), e = S(me), n = S(U), i = I(t.state$, void 0, !0), s = z(null);
669
+ j(() => {
670
+ let d;
671
+ return s.current && (d = e.registerContainerElement(s.current)), () => d == null ? void 0 : d.dispose();
672
+ }, [e]);
673
+ const r = z(null), a = _(
674
+ (d) => n.setContextValue(ye, d),
675
+ [n]
676
+ ), o = _(
677
+ (d) => n.setContextValue(be, d),
678
+ [n]
679
+ );
680
+ return j(() => {
681
+ var u;
682
+ const d = yt(document, "focusin").subscribe((p) => {
683
+ var f;
684
+ p.target && ((f = s.current) != null && f.contains(p.target)) ? a(!0) : a(!1), !r.current || !r.current.selectHasFocus() ? o(!0) : o(!1);
685
+ });
686
+ return (u = r.current) == null || u.focus(), a(!0), o(!0), () => {
687
+ d.unsubscribe(), a(!1);
688
+ };
689
+ }, [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
690
  }
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
- };
691
+ function ni(t) {
692
+ const e = t.getCurrentLocale();
693
+ return te(() => [
694
+ { label: t.t("find-replace.dialog.find-scope.current-sheet"), value: J.SUBUNIT },
695
+ { label: t.t("find-replace.dialog.find-scope.workbook"), value: J.UNIT }
696
+ ], [e]);
697
+ }
698
+ function si(t) {
699
+ const e = t.getCurrentLocale();
700
+ return te(() => [
701
+ { label: t.t("find-replace.dialog.find-direction.row"), value: Y.ROW },
702
+ { label: t.t("find-replace.dialog.find-direction.column"), value: Y.COLUMN }
703
+ ], [e]);
433
704
  }
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",
705
+ function ri(t) {
706
+ const e = t.getCurrentLocale();
707
+ return te(() => [
708
+ { label: t.t("find-replace.dialog.find-by.value"), value: Z.VALUE },
709
+ { label: t.t("find-replace.dialog.find-by.formula"), value: Z.FORMULA }
710
+ ], [e]);
711
+ }
712
+ function D(t) {
713
+ return t.getContextValue(ye);
714
+ }
715
+ function ai(t) {
716
+ return t.getContextValue(Ie);
717
+ }
718
+ function je(t) {
719
+ return t.getContextValue(be);
720
+ }
721
+ const k = "7_find-replace-shortcuts";
722
+ function se(t) {
723
+ return t.getContextValue(fe);
724
+ }
725
+ function re(t) {
726
+ return !t.getContextValue(pe);
727
+ }
728
+ const oi = {
729
+ id: W.id,
730
+ description: "find-replace.shortcut.open-find-dialog",
731
+ binding: x.F | M.CTRL_COMMAND,
732
+ group: k,
439
733
  preconditions(t) {
440
- return !t.getContextValue(_);
734
+ return !D(t) && se(t) && re(t);
441
735
  }
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",
736
+ }, ci = {
737
+ id: W.id,
738
+ description: "find-replace.shortcut.open-find-dialog",
739
+ binding: x.F | M.CTRL_COMMAND,
740
+ mac: x.F | M.MAC_CTRL,
447
741
  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,
742
+ return !D(t) && se(t) && re(t);
743
+ }
744
+ }, li = {
745
+ id: ne.id,
746
+ description: "find-replace.shortcut.open-replace-dialog",
747
+ binding: x.H | M.CTRL_COMMAND,
748
+ mac: x.H | M.MAC_CTRL,
749
+ group: k,
456
750
  preconditions(t) {
457
- return !!t.getContextValue(_);
751
+ return se(t) && re(t) && (!D(t) || !ai(t));
458
752
  }
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",
753
+ }, di = {
754
+ id: Pe.id,
755
+ description: "find-replace.shortcut.go-to-next-match",
756
+ binding: x.ENTER,
757
+ group: k,
464
758
  priority: 1e3,
465
759
  preconditions(t) {
466
- return !!t.getContextValue(_);
760
+ return je(t) && D(t);
467
761
  }
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",
762
+ }, hi = {
763
+ id: De.id,
764
+ description: "find-replace.shortcut.go-to-previous-match",
765
+ binding: x.ENTER | M.SHIFT,
766
+ group: k,
473
767
  priority: 1e3,
474
768
  preconditions(t) {
475
- return !!t.getContextValue(_);
769
+ return je(t) && D(t);
476
770
  }
477
771
  };
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() {
772
+ function ui(t) {
773
+ const e = t.get(U);
774
+ return {
775
+ id: W.id,
776
+ icon: "SearchIcon",
777
+ tooltip: "find-replace.toolbar",
778
+ group: _t.TOOLBAR_OTHERS,
779
+ type: gt.BUTTON,
780
+ positions: [mt.TOOLBAR_START],
781
+ hidden$: vt(t, ct.SHEET),
782
+ disabled$: Se([
783
+ e.subscribeContextValue$(pe),
784
+ e.subscribeContextValue$(fe)
785
+ ]).pipe(It(([n, i]) => n || !i))
786
+ };
787
+ }
788
+ var fi = Object.defineProperty, pi = Object.getOwnPropertyDescriptor, _i = (t, e, n, i) => {
789
+ for (var s = i > 1 ? void 0 : i ? pi(e, n) : e, r = t.length - 1, a; r >= 0; r--)
790
+ (a = t[r]) && (s = (i ? a(e, n, s) : a(s)) || s);
791
+ return i && s && fi(e, n, s), s;
792
+ }, g = (t, e) => (n, i) => e(n, i, t);
793
+ const le = "DESKTOP_FIND_REPLACE_DIALOG", we = 350, gi = 20, mi = -90;
794
+ let A = class extends lt {
795
+ constructor(t, e, n, i, s, r, a, o, d, u, p, f) {
796
+ 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();
797
+ }
798
+ _initCommands() {
489
799
  [
490
- ee,
491
- D,
492
- X,
493
- ze,
494
- te,
495
- ie
800
+ W,
801
+ ne,
802
+ Pe,
803
+ De,
804
+ $e,
805
+ Ee
496
806
  ].forEach((t) => {
497
807
  this.disposeWithMe(this._commandService.registerCommand(t));
498
808
  });
499
809
  }
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
810
  _initShortcuts() {
508
811
  [
509
- nt,
510
- it,
511
- rt,
512
- at,
513
- ot
514
- ].forEach((t) => {
515
- this.disposeWithMe(this._shortcutService.registerShortcut(t));
516
- });
812
+ li,
813
+ oi,
814
+ ci,
815
+ hi,
816
+ di
817
+ ].forEach((t) => this.disposeWithMe(this._shortcutService.registerShortcut(t)));
818
+ }
819
+ _initUI() {
820
+ this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(ui))), this.disposeWithMe(this._componentManager.register("FindReplaceDialog", ii)), this.disposeWithMe(this._componentManager.register("SearchIcon", Me)), this._findReplaceService.stateUpdates$.pipe(ae(this.dispose$)).subscribe((t) => {
821
+ t.revealed === !0 && this._openPanel();
822
+ }), this.disposeWithMe(
823
+ this._univerInstanceService.focused$.pipe(ae(this.dispose$)).subscribe((t) => {
824
+ (!t || !this._univerInstanceService.getUniverSheetInstance(t)) && this.closePanel();
825
+ })
826
+ );
517
827
  }
518
828
  _openPanel() {
519
829
  this._dialogService.open({
520
- id: w,
830
+ id: le,
521
831
  draggable: !0,
522
- width: 350,
523
- title: { title: this._localeService.t("univer.find-replace.dialog.title") },
832
+ width: we,
833
+ title: { title: this._localeService.t("find-replace.dialog.title") },
524
834
  children: { label: "FindReplaceDialog" },
525
- onClose: () => this._closePanel()
526
- }), this._contextService.setContextValue(_, !0);
835
+ destroyOnClose: !0,
836
+ defaultPosition: vi(),
837
+ preservePositionOnDestroy: !0,
838
+ onClose: () => this.closePanel()
839
+ });
527
840
  }
528
- _closePanel() {
529
- this._dialogService.close(w), this._contextService.setContextValue(_, !1), this._layoutService.focus(), this._findReplaceService.end();
841
+ closePanel() {
842
+ this._dialogService.close(le), this._findReplaceService.terminate(), queueMicrotask(() => this._layoutService.focus());
530
843
  }
531
844
  };
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": "输入替换内容"
845
+ A = _i([
846
+ dt(ht.Rendered, A),
847
+ g(0, he),
848
+ g(1, Ct),
849
+ g(2, Rt),
850
+ g(3, ee),
851
+ g(4, v),
852
+ g(5, ue),
853
+ g(6, xt),
854
+ g(7, U),
855
+ g(8, me),
856
+ g(9, y(P)),
857
+ g(10, y(St)),
858
+ g(11, y(_e))
859
+ ], A);
860
+ function vi() {
861
+ const { innerWidth: t } = window;
862
+ return { x: (t - we) / 2 - gi, y: mi };
863
+ }
864
+ const Si = {
865
+ "find-replace": {
866
+ toolbar: "查找替换",
867
+ shortcut: {
868
+ "open-find-dialog": "打开查找对话框",
869
+ "open-replace-dialog": "打开替换对话框",
870
+ "close-dialog": "关闭查找替换对话框",
871
+ "go-to-next-match": "下一个匹配项",
872
+ "go-to-previous-match": "下一个匹配项"
873
+ },
874
+ dialog: {
875
+ title: "查找",
876
+ find: "查找",
877
+ replace: "替换",
878
+ "replace-all": "替换全部",
879
+ "find-placeholder": "输入查找内容",
880
+ "advanced-finding": "替换 / 高级查找",
881
+ "replace-placeholder": "输入替换内容",
882
+ "case-sensitive": "匹配大小写",
883
+ "match-the-whole-cell": "匹配整个单元格",
884
+ "find-scope": {
885
+ title: "查找范围",
886
+ "current-sheet": "当前子表",
887
+ workbook: "整个工作簿"
888
+ },
889
+ "find-direction": {
890
+ title: "查找顺序",
891
+ column: "按列查找",
892
+ row: "按行查找"
893
+ },
894
+ "find-by": {
895
+ title: "查找方式",
896
+ formula: "查找公式",
897
+ value: "查找值"
898
+ },
899
+ "no-match": "已完成搜索,但是未找到任何匹配项",
900
+ "no-result": "无结果"
901
+ },
902
+ replace: {
903
+ "all-success": "已全部替换 {0} 个匹配项",
904
+ "all-failure": "替换失败",
905
+ confirm: {
906
+ title: "确定要替换所有的匹配项吗?"
557
907
  }
558
908
  }
559
- }
909
+ },
910
+ "find-replace-shortcuts": "查找替换"
560
911
  };
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 {
912
+ var Ci = Object.defineProperty, Ri = Object.getOwnPropertyDescriptor, xi = (t, e, n, i) => {
913
+ for (var s = i > 1 ? void 0 : i ? Ri(e, n) : e, r = t.length - 1, a; r >= 0; r--)
914
+ (a = t[r]) && (s = (i ? a(e, n, s) : a(s)) || s);
915
+ return i && s && Ci(e, n, s), s;
916
+ }, Mi = (t, e) => (n, i) => e(n, i, t);
917
+ const bi = "FIND_REPLACE";
918
+ let de = class extends ut {
568
919
  constructor(t, e) {
569
- super(_t), this._injector = t, this._localeService = e, this._localeService.load({
570
- zhCN: dt
920
+ super(bi), this._injector = t, this._localeService = e, this._localeService.load({
921
+ zhCN: Si
571
922
  });
572
923
  }
573
924
  onStarting(t) {
574
- [[C], [f, { useClass: b }]].forEach(
925
+ [[A], [v, { useClass: Q }]].forEach(
575
926
  (e) => {
576
927
  t.add(e);
577
928
  }
578
929
  );
579
930
  }
580
931
  };
581
- V = pt([
582
- ft(1, S(j))
583
- ], V);
932
+ de = xi([
933
+ Mi(1, y(P))
934
+ ], de);
584
935
  export {
585
- Ct as FindModel,
586
- f as IFindReplaceService,
587
- V as UniverFindReplacePlugin
936
+ Z as FindBy,
937
+ Y as FindDirection,
938
+ Ni as FindModel,
939
+ A as FindReplaceController,
940
+ J as FindScope,
941
+ v as IFindReplaceService,
942
+ de as UniverFindReplacePlugin
588
943
  };