@univerjs/find-replace 0.1.0-beta.2 → 0.1.0-beta.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,270 +1,589 @@
1
- var C = Object.defineProperty;
2
- var E = (t, e, i) => e in t ? C(t, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : t[e] = i;
3
- var o = (t, e, i) => (E(t, typeof e != "symbol" ? e + "" : e, i), i);
4
- import { toDisposable as h, remove as R, ICommandService as L, IContextService as I, Disposable as O, CommandType as B, OnLifecycle as D, LifecycleStages as y, Plugin as M } from "@univerjs/core";
5
- import { createIdentifier as T, Optional as b, Inject as N, Injector as P } from "@wendellhu/redi";
6
- import { Subject as $, BehaviorSubject as U } from "rxjs";
7
- var S = /* @__PURE__ */ ((t) => (t.VOID = "void", t.TOOLBAR_START = "uiToolbar.start", t.TOOLBAR_INSERT = "uiToolbar.insert", t.TOOLBAR_FORMULAS = "uiToolbar.formulas", t.TOOLBAR_DATA = "uiToolbar.data", t.TOOLBAR_VIEW = "uiToolbar.view", t.TOOLBAR_OTHERS = "uiToolbar.others", t.CONTEXT_MENU = "contextMenu", t))(S || {}), g = /* @__PURE__ */ ((t) => (t[t.TOOLBAR_HISTORY = 0] = "TOOLBAR_HISTORY", t[t.TOOLBAR_FORMAT = 1] = "TOOLBAR_FORMAT", t[t.TOOLBAR_LAYOUT = 2] = "TOOLBAR_LAYOUT", t[t.TOOLBAR_FORMULAS_INSERT = 3] = "TOOLBAR_FORMULAS_INSERT", t[t.TOOLBAR_FORMULAS_VIEW = 4] = "TOOLBAR_FORMULAS_VIEW", t[t.TOOLBAR_FILE = 5] = "TOOLBAR_FILE", t[t.TOOLBAR_OTHERS = 6] = "TOOLBAR_OTHERS", t[t.CONTEXT_MENU_FORMAT = 7] = "CONTEXT_MENU_FORMAT", t[t.CONTEXT_MENU_LAYOUT = 8] = "CONTEXT_MENU_LAYOUT", t[t.CONTEXT_MENU_DATA = 9] = "CONTEXT_MENU_DATA", t[t.CONTEXT_MENU_OTHERS = 10] = "CONTEXT_MENU_OTHERS", t))(g || {}), A = /* @__PURE__ */ ((t) => (t[t.BUTTON = 0] = "BUTTON", t[t.SELECTOR = 1] = "SELECTOR", t[t.BUTTON_SELECTOR = 2] = "BUTTON_SELECTOR", t[t.SUBITEMS = 3] = "SUBITEMS", t))(A || {});
8
- function w(t, e, i) {
9
- return document.addEventListener(t, e, i), h(() => document.removeEventListener(t, e, i));
1
+ var le = Object.defineProperty;
2
+ var de = (t, e, n) => e in t ? le(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
+ var l = (t, e, n) => (de(t, typeof e != "symbol" ? e + "" : e, n), n);
4
+ import { Disposable as E, ILogService as B, IUniverInstanceService as G, toDisposable as he, CommandType as m, LocaleService as F, UniverInstanceType as ue, OnLifecycle as pe, LifecycleStages as fe, RxDisposable as ve, ICommandService as _e, IContextService as ge, Plugin as me } from "@univerjs/core";
5
+ import { createIdentifier as Se, Inject as S, Injector as H } from "@wendellhu/redi";
6
+ import { LayoutService as xe, MenuGroup as Re, MenuItemType as Me, MenuPosition as Ie, getMenuHiddenObservable as Ce, KeyCode as R, MetaKeys as j, ComponentManager as Oe, IMenuService as Pe, IShortcutService as ye, IDialogService as Te, IFocusService as be } from "@univerjs/ui";
7
+ import { Subject as Ee, BehaviorSubject as Fe, takeUntil as je } from "rxjs";
8
+ import De, { forwardRef as W, useRef as k, createElement as z, useState as $, useCallback as M, useEffect as Ne, Fragment as A } from "react";
9
+ import { useObservable as $e, InputWithSlot as Ae, Pager as Ue, Button as I, FormLayout as P, Input as U, Select as Le } from "@univerjs/design";
10
+ import { useDependency as y } from "@wendellhu/redi/react-bindings";
11
+ var u = function() {
12
+ return u = Object.assign || function(t) {
13
+ for (var e, n = 1, i = arguments.length; n < i; n++) {
14
+ e = arguments[n];
15
+ for (var r in e)
16
+ Object.prototype.hasOwnProperty.call(e, r) && (t[r] = e[r]);
17
+ }
18
+ return t;
19
+ }, u.apply(this, arguments);
20
+ }, we = function(t, e) {
21
+ var n = {};
22
+ for (var i in t)
23
+ Object.prototype.hasOwnProperty.call(t, i) && e.indexOf(i) < 0 && (n[i] = t[i]);
24
+ 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]]);
27
+ return n;
28
+ }, K = W(function(t, e) {
29
+ var n = t.icon, i = t.id, r = t.className, o = t.extend, a = we(t, ["icon", "id", "className", "extend"]), s = "univerjs-icon univerjs-icon-".concat(i, " ").concat(r || "").trim(), h = k("_".concat(Ge()));
30
+ return q(n, "".concat(i), { defIds: n.defIds, idSuffix: h.current }, u({ ref: e, className: s }, a), o);
31
+ });
32
+ function q(t, e, n, i, r) {
33
+ return z(t.tag, u(u({ key: e }, Ve(t, n, r)), i), (Be(t, n).children || []).map(function(o, a) {
34
+ return q(o, "".concat(e, "-").concat(t.tag, "-").concat(a), n, void 0, r);
35
+ }));
10
36
  }
11
- class F {
12
- constructor() {
13
- o(this, "_containers", []);
14
- }
15
- registerContainer(e) {
16
- if (this._containers.indexOf(e) === -1)
17
- return this._containers.push(e), h(() => R(this._containers, e));
18
- throw new Error("[LayoutService]: container already registered!");
19
- }
20
- checkElementInCurrentApplicationScope(e) {
21
- return this._containers.some((i) => i.contains(e));
22
- }
37
+ function Ve(t, e, n) {
38
+ var i = u({}, t.attrs);
39
+ 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, ")")));
44
+ })), i;
23
45
  }
24
- const x = T("univer.platform-service"), j = {
25
- 8: "Backspace",
26
- 9: "Tab",
27
- 13: "Enter",
28
- 46: "Del",
29
- 27: "Esc",
30
- 32: "Space",
31
- 37: "←",
32
- 39: "→",
33
- 38: "",
34
- 40: "↓",
35
- 48: "0",
36
- 49: "1",
37
- 50: "2",
38
- 51: "3",
39
- 52: "4",
40
- 53: "5",
41
- 54: "6",
42
- 55: "7",
43
- 56: "8",
44
- 57: "9",
45
- 65: "A",
46
- 66: "B",
47
- 67: "C",
48
- 68: "D",
49
- 69: "E",
50
- 70: "F",
51
- 71: "G",
52
- 72: "H",
53
- 73: "I",
54
- 74: "J",
55
- 75: "K",
56
- 76: "L",
57
- 77: "M",
58
- 78: "N",
59
- 79: "O",
60
- 80: "P",
61
- 81: "Q",
62
- 82: "R",
63
- 83: "S",
64
- 84: "T",
65
- 85: "U",
66
- 86: "V",
67
- 87: "W",
68
- 88: "X",
69
- 89: "Y",
70
- 90: "Z",
71
- 189: "-",
72
- 187: "="
73
- };
74
- var c = /* @__PURE__ */ ((t) => (t[t.SHIFT = 1024] = "SHIFT", t[t.ALT = 2048] = "ALT", t[t.CTRL_COMMAND = 4096] = "CTRL_COMMAND", t[t.MAC_CTRL = 8192] = "MAC_CTRL", t))(c || {}), H = Object.defineProperty, X = Object.getOwnPropertyDescriptor, K = (t, e, i, s) => {
75
- for (var r = s > 1 ? void 0 : s ? X(e, i) : e, n = t.length - 1, a; n >= 0; n--)
76
- (a = t[n]) && (r = (s ? a(e, i, r) : a(r)) || r);
77
- return s && r && H(e, i, r), r;
78
- }, d = (t, e) => (i, s) => e(i, s, t);
79
- const W = T("univer.shortcut");
80
- let f = class extends O {
81
- constructor(e, i, s, r) {
46
+ function Be(t, e) {
47
+ 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;
50
+ }) }) : t;
51
+ }
52
+ function Ge() {
53
+ return Math.random().toString(36).substring(2, 8);
54
+ }
55
+ K.displayName = "UniverIcon";
56
+ var He = {
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: { "mask-type": "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
+ }, Z = W(function(t, e) {
95
+ return z(K, Object.assign({}, t, {
96
+ id: "search-single-16",
97
+ ref: e,
98
+ icon: He
99
+ }));
100
+ });
101
+ Z.displayName = "SearchSingle16";
102
+ const We = Z;
103
+ var ke = Object.defineProperty, ze = Object.getOwnPropertyDescriptor, J = (t, e, n, i) => {
104
+ for (var r = i > 1 ? void 0 : i ? ze(e, n) : e, o = t.length - 1, a; o >= 0; o--)
105
+ (a = t[o]) && (r = (i ? a(e, n, r) : a(r)) || r);
106
+ return i && r && ke(e, n, r), r;
107
+ }, x = (t, e) => (n, i) => e(n, i, t);
108
+ class Pt extends E {
109
+ }
110
+ const f = Se("univer.find-replace.service");
111
+ let T = class extends E {
112
+ constructor(e, n, i, r) {
82
113
  super();
83
- o(this, "_shortCutMapping", /* @__PURE__ */ new Map());
84
- o(this, "_commandIDMapping", /* @__PURE__ */ new Map());
85
- o(this, "_shortcutChanged$", new $());
86
- o(this, "shortcutChanged$", this._shortcutChanged$.asObservable());
87
- o(this, "_forceEscaped", !1);
88
- o(this, "_disable", !1);
89
- this._commandService = e, this._platformService = i, this._contextService = s, this._layoutService = r, this.disposeWithMe(
90
- w("keydown", (n) => {
91
- this._resolveKeyboardEvent(n);
92
- })
93
- );
114
+ l(this, "_matchPositionFindModel", null);
115
+ l(this, "_findModels", []);
116
+ l(this, "_matches", []);
117
+ l(this, "_positionModel", null);
118
+ this._state = e, this._providers = n, this._logService = i, this._univerInstanceService = r, this._state.stateUpdates$.subscribe((o) => {
119
+ typeof o.findString < "u" && (o.findString ? this.find() : this._cancelFinding());
120
+ });
121
+ }
122
+ async find() {
123
+ this._cancelFinding();
124
+ 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();
125
+ if (this._matches = i, !i.length)
126
+ return {
127
+ results: []
128
+ };
129
+ const r = this._moveToInitialMatch(n, i);
130
+ return this._state.changeState({
131
+ matchesCount: i.length,
132
+ matchesPosition: r + 1
133
+ // the matches position start from 1
134
+ }), {
135
+ results: i
136
+ };
94
137
  }
95
- setDisable(e) {
96
- this._disable = e;
138
+ moveToNextMatch() {
139
+ if (!this._positionModel)
140
+ return;
141
+ const e = this._findModels.length === 1, n = this._positionModel.moveToNextMatch(e);
142
+ if (n) {
143
+ const i = this._matches.findIndex((r) => r === n);
144
+ this._state.changeState({
145
+ matchesPosition: i + 1
146
+ });
147
+ } else {
148
+ 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);
149
+ this._positionModel = r, this._state.changeState({
150
+ matchesPosition: a + 1
151
+ });
152
+ }
153
+ }
154
+ moveToPreviousMatch() {
155
+ if (!this._positionModel)
156
+ return;
157
+ const e = this._findModels.length === 1, n = this._positionModel.moveToPreviousMatch(e);
158
+ if (n) {
159
+ const i = this._matches.findIndex((r) => r === n);
160
+ this._state.changeState({
161
+ matchesPosition: i + 1
162
+ });
163
+ } else {
164
+ 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);
165
+ this._positionModel = r, this._state.changeState({
166
+ matchesPosition: a + 1
167
+ });
168
+ }
97
169
  }
98
- getAllShortcuts() {
99
- return Array.from(this._shortCutMapping.values()).map((e) => Array.from(e.values())).flat();
170
+ // TODO@wzhudev: some cold could definitely be reused. Reuse them.
171
+ _moveToInitialMatch(e, n) {
172
+ var s;
173
+ const i = (s = this._univerInstanceService.getFocusedUniverInstance()) == null ? void 0 : s.getUnitId();
174
+ if (!i)
175
+ return -1;
176
+ const r = e.find((h) => h.unitId === i);
177
+ if (r) {
178
+ this._positionModel = r;
179
+ const h = r.moveToNextMatch();
180
+ return n.findIndex((g) => g === h);
181
+ }
182
+ this._positionModel = e[0];
183
+ const o = this._positionModel.moveToNextMatch();
184
+ return this._matches.findIndex((h) => h === o);
100
185
  }
101
- registerShortcut(e) {
102
- const i = this._getBindingFromItem(e), s = this._shortCutMapping.get(i);
103
- s ? s.add(e) : this._shortCutMapping.set(i, /* @__PURE__ */ new Set([e]));
104
- const r = e.id, n = this._commandIDMapping.get(r);
105
- return n ? n.add(e) : this._commandIDMapping.set(r, /* @__PURE__ */ new Set([e])), this._emitShortcutChanged(), h(() => {
106
- var a, _, u, p;
107
- (a = this._shortCutMapping.get(i)) == null || a.delete(e), ((_ = this._shortCutMapping.get(i)) == null ? void 0 : _.size) === 0 && this._shortCutMapping.delete(i), (u = this._commandIDMapping.get(r)) == null || u.delete(e), ((p = this._commandIDMapping.get(r)) == null ? void 0 : p.size) === 0 && this._commandIDMapping.delete(r), this._emitShortcutChanged();
186
+ _cancelFinding() {
187
+ this._providers.forEach((e) => e.cancel()), this._state.changeState({
188
+ matchesCount: 0,
189
+ matchesPosition: 0
108
190
  });
109
191
  }
110
- getShortcutDisplayOfCommand(e) {
111
- const i = this._commandIDMapping.get(e);
112
- return i ? this.getShortcutDisplay(i.values().next().value) : null;
192
+ };
193
+ T = J([
194
+ x(2, B),
195
+ x(3, G)
196
+ ], T);
197
+ function Y() {
198
+ return {
199
+ revealed: !0,
200
+ findString: "",
201
+ replaceRevealed: !1,
202
+ matchesPosition: 0,
203
+ matchesCount: 0
204
+ };
205
+ }
206
+ class Ke {
207
+ constructor() {
208
+ l(this, "_stateUpdates$", new Ee());
209
+ l(this, "stateUpdates$", this._stateUpdates$.asObservable());
210
+ l(this, "_state$", new Fe(Y()));
211
+ l(this, "state$", this._state$.asObservable());
212
+ // TODO@wzhudev: put all state properties here
213
+ l(this, "_findString", "");
214
+ l(this, "_revealed", !1);
215
+ l(this, "_replaceRevealed", !1);
216
+ l(this, "_matchesPosition", 0);
217
+ l(this, "_matchesCount", 0);
113
218
  }
114
- getShortcutDisplay(e) {
115
- const i = this._getBindingFromItem(e), s = i & c.CTRL_COMMAND, r = i & c.SHIFT, n = i & c.ALT, a = i & c.MAC_CTRL, _ = j[i & 255] ?? "<->";
116
- return this._platformService.isMac ? `${s ? "⌘" : ""}${r ? "⇧" : ""}${n ? "⌥" : ""}${a ? "⌃" : ""}${_}` : `${s ? "Ctrl+" : ""}${r ? "Shift+" : ""}${n ? "Alt+" : ""}${_}`;
219
+ get state() {
220
+ return this._state$.getValue();
117
221
  }
118
- _emitShortcutChanged() {
119
- this._shortcutChanged$.next();
222
+ get findString() {
223
+ return this._findString;
120
224
  }
121
- forceEscape() {
122
- return this._forceEscaped = !0, h(() => this._forceEscaped = !1);
225
+ changeState(e) {
226
+ let n = !1;
227
+ const i = {};
228
+ 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({
229
+ findString: this._findString,
230
+ revealed: this._revealed,
231
+ replaceRevealed: this._replaceRevealed,
232
+ matchesCount: this._matchesCount,
233
+ matchesPosition: this._matchesPosition
234
+ }));
123
235
  }
124
- _resolveKeyboardEvent(e) {
125
- if (this._forceEscaped || this._disable || this._layoutService && !this._layoutService.checkElementInCurrentApplicationScope(e.target))
126
- return;
127
- this._dispatch(e) && e.preventDefault();
236
+ }
237
+ let b = class extends E {
238
+ constructor(e, n, i) {
239
+ super();
240
+ l(this, "_providers", /* @__PURE__ */ new Set());
241
+ l(this, "_state", new Ke());
242
+ l(this, "_model");
243
+ this._injector = e, this._univerInstanceService = n, this._logService = i;
128
244
  }
129
- _dispatch(e) {
130
- const i = this._deriveBindingFromEvent(e);
131
- if (i === null)
132
- return !1;
133
- const s = this._shortCutMapping.get(i);
134
- if (s === void 0)
135
- return !1;
136
- const r = Array.from(s).sort((n, a) => (a.priority ?? 0) - (n.priority ?? 0)).find((n) => {
137
- var a;
138
- return ((a = n.preconditions) == null ? void 0 : a.call(n, this._contextService)) ?? !0;
245
+ get stateUpdates$() {
246
+ return this._state.stateUpdates$;
247
+ }
248
+ get state$() {
249
+ return this._state.state$;
250
+ }
251
+ changeFindString(e) {
252
+ this._state.changeState({
253
+ findString: e
139
254
  });
140
- return r ? (this._commandService.executeCommand(r.id, r.staticParameters), !0) : !1;
141
255
  }
142
- _getBindingFromItem(e) {
143
- return this._platformService.isMac && e.mac ? e.mac : this._platformService.isWindows && e.win ? e.win : this._platformService.isLinux && e.linux ? e.linux : e.binding;
256
+ moveToNextMatch() {
257
+ var e;
258
+ this._model && ((e = this._model) == null || e.moveToNextMatch());
144
259
  }
145
- _deriveBindingFromEvent(e) {
146
- const { shiftKey: i, metaKey: s, altKey: r, keyCode: n } = e;
147
- let a = n;
148
- return i && (a |= c.SHIFT), r && (a |= c.ALT), (this._platformService.isMac ? s : e.ctrlKey) && (a |= c.CTRL_COMMAND), this._platformService.isMac && e.ctrlKey && (a |= c.MAC_CTRL), a;
260
+ moveToPreviousMatch() {
261
+ var e;
262
+ this._model && ((e = this._model) == null || e.moveToPreviousMatch());
149
263
  }
150
- };
151
- f = K([
152
- d(0, L),
153
- d(1, x),
154
- d(2, I),
155
- d(3, b(F))
156
- ], f);
157
- var Y = Object.defineProperty, V = Object.getOwnPropertyDescriptor, z = (t, e, i, s) => {
158
- for (var r = s > 1 ? void 0 : s ? V(e, i) : e, n = t.length - 1, a; n >= 0; n--)
159
- (a = t[n]) && (r = (s ? a(e, i, r) : a(r)) || r);
160
- return s && r && Y(e, i, r), r;
161
- }, J = (t, e) => (i, s) => e(i, s, t);
162
- const Q = T("univer.menu-service");
163
- let m = class extends O {
164
- constructor(e) {
165
- super();
166
- o(this, "_menuItemMap", /* @__PURE__ */ new Map());
167
- o(this, "_menuByPositions", /* @__PURE__ */ new Map());
168
- o(this, "_menuChanged$", new U(void 0));
169
- o(this, "menuChanged$", this._menuChanged$.asObservable());
170
- this._shortcutService = e;
171
- }
172
- dispose() {
173
- this._menuItemMap.clear(), this._menuChanged$.complete();
174
- }
175
- addMenuItem(e) {
176
- if (this._menuItemMap.has(e.id))
177
- throw new Error(`Menu item with the same id ${e.id} has already been added!`);
178
- return this._menuItemMap.set(e.id, e), Array.isArray(e.positions) ? e.positions.forEach((i) => this._appendMenuToPosition(e, i)) : this._appendMenuToPosition(e, e.positions), this._menuChanged$.next(), h(() => {
179
- if (this._menuItemMap.delete(e.id), Array.isArray(e.positions))
180
- e.positions.forEach((i) => {
181
- const s = this._menuByPositions.get(i);
182
- if (!s)
183
- return;
184
- const r = s.findIndex((n) => n[0] === e.id);
185
- r > -1 && s.splice(r, 1);
186
- });
187
- else {
188
- const i = this._menuByPositions.get(e.positions);
189
- if (!i)
190
- return;
191
- const s = i.findIndex((r) => r[0] === e.id);
192
- s > -1 && i.splice(s, 1);
193
- }
194
- this._menuChanged$.next();
195
- });
264
+ replace() {
265
+ return !0;
196
266
  }
197
- getMenuItems(e) {
198
- if (this._menuByPositions.has(e)) {
199
- const i = this._menuByPositions.get(e);
200
- if (i)
201
- return [...i.values()].map((s) => this._getDisplayMenuItems(s[1]));
202
- }
203
- return [];
267
+ replaceAll() {
268
+ return !0;
269
+ }
270
+ revealReplace() {
271
+ this._state.changeState({ replaceRevealed: !0 });
204
272
  }
205
- getMenuItem(e) {
206
- return this._menuItemMap.has(e) ? this._menuItemMap.get(e) : null;
273
+ disposeModel() {
274
+ var e;
275
+ (e = this._model) == null || e.dispose(), this._model = null;
276
+ }
277
+ start() {
278
+ if (this._providers.size === 0)
279
+ return !1;
280
+ this._model = this._injector.createInstance(T, this._state, this._providers);
281
+ const e = Y();
282
+ return e.revealed = !0, this._state.changeState(e), !0;
207
283
  }
208
- _getDisplayMenuItems(e) {
209
- const i = this._shortcutService.getShortcutDisplayOfCommand(e.id);
210
- return i ? {
211
- ...e,
212
- shortcut: i
213
- } : e;
284
+ end() {
285
+ return this._state.changeState({ revealed: !1, replaceRevealed: !1 }), !0;
214
286
  }
215
- _appendMenuToPosition(e, i) {
216
- this._menuByPositions.has(i) || this._menuByPositions.set(i, []);
217
- const s = this._menuByPositions.get(i);
218
- if (s.findIndex((r) => r[0] === e.id) > -1)
219
- throw new Error(`Menu item with the same id ${e.id} has already been added!`);
220
- s.push([e.id, e]);
287
+ registerFindReplaceProvider(e) {
288
+ return this._providers.add(e), he(() => this._providers.delete(e));
221
289
  }
222
290
  };
223
- m = z([
224
- J(0, W)
225
- ], m);
226
- const Z = {
227
- type: B.OPERATION,
228
- id: "ui.operation.toggle-find-replace-dialog",
291
+ b = J([
292
+ x(0, S(H)),
293
+ x(1, G),
294
+ x(2, B)
295
+ ], b);
296
+ const D = {
297
+ id: "ui.operation.open-find-dialog",
298
+ type: m.OPERATION,
299
+ handler: (t) => (t.get(f).start(), !0)
300
+ }, Q = {
301
+ id: "ui.operation.open-replace-dialog",
302
+ type: m.OPERATION,
303
+ handler: (t) => (t.get(f).start(), !0)
304
+ }, qe = {
305
+ id: "ui.operation.toggle-replace-dialog",
306
+ type: m.OPERATION,
307
+ handler: (t) => (t.get(f), !0)
308
+ }, X = {
309
+ id: "ui.operation.close-find-replace-dialog",
310
+ type: m.OPERATION,
229
311
  handler: (t) => !0
312
+ }, ee = {
313
+ type: m.OPERATION,
314
+ id: "ui.operation.go-to-next-match",
315
+ handler: (t) => (t.get(f).moveToNextMatch(), !0)
316
+ }, te = {
317
+ type: m.OPERATION,
318
+ id: "ui.operation.go-to-previous-match",
319
+ handler: (t) => (t.get(f).moveToPreviousMatch(), !0)
320
+ }, v = "FIND_REPLACE_ACTIVATED";
321
+ var ie = { exports: {} }, O = {};
322
+ /**
323
+ * @license React
324
+ * react-jsx-runtime.production.min.js
325
+ *
326
+ * Copyright (c) Facebook, Inc. and its affiliates.
327
+ *
328
+ * This source code is licensed under the MIT license found in the
329
+ * LICENSE file in the root directory of this source tree.
330
+ */
331
+ var Ze = De, Je = Symbol.for("react.element"), Ye = Symbol.for("react.fragment"), Qe = Object.prototype.hasOwnProperty, Xe = Ze.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, et = { key: !0, ref: !0, __self: !0, __source: !0 };
332
+ function ne(t, e, n) {
333
+ var i, r = {}, o = null, a = null;
334
+ n !== void 0 && (o = "" + n), e.key !== void 0 && (o = "" + e.key), e.ref !== void 0 && (a = e.ref);
335
+ for (i in e)
336
+ Qe.call(e, i) && !et.hasOwnProperty(i) && (r[i] = e[i]);
337
+ if (t && t.defaultProps)
338
+ for (i in e = t.defaultProps, e)
339
+ r[i] === void 0 && (r[i] = e[i]);
340
+ return { $$typeof: Je, type: t, key: o, ref: a, props: r, _owner: Xe.current };
341
+ }
342
+ O.Fragment = Ye;
343
+ O.jsx = ne;
344
+ O.jsxs = ne;
345
+ ie.exports = O;
346
+ var d = ie.exports;
347
+ const tt = "univer-find-replace-expand-container", L = {
348
+ findReplaceExpandContainer: tt
230
349
  };
231
- function q(t) {
350
+ function it() {
351
+ const t = y(f), e = y(F), n = y(xe), [i, r] = $(""), [o, a] = $(""), s = k(null), h = $e(t.state$, !0), { matchesCount: _, matchesPosition: g } = h, re = M(() => t.revealReplace(), [t]), oe = M(
352
+ (c) => t.changeFindString(c),
353
+ // FIXME@wzhudev: this throttle function has no leading and taling config hence has some problems
354
+ // throttle((findString: string) => findReplaceService.changeFindString(findString), FIND_THROTTLE_TIME),
355
+ [t]
356
+ ), ae = M(
357
+ (c) => {
358
+ r(c), oe(c);
359
+ },
360
+ [t]
361
+ ), N = M(
362
+ (c) => {
363
+ a(c);
364
+ },
365
+ [t]
366
+ );
367
+ Ne(() => {
368
+ let c;
369
+ return s.current && (c = n.registerContainer(s.current)), () => c == null ? void 0 : c.dispose();
370
+ }, [s.current]);
371
+ function se() {
372
+ return /* @__PURE__ */ d.jsxs(A, { children: [
373
+ /* @__PURE__ */ d.jsx(
374
+ Ae,
375
+ {
376
+ autoFocus: !0,
377
+ placeholder: e.t("univer.find-replace.dialog.find-placeholder"),
378
+ slot: /* @__PURE__ */ d.jsx(
379
+ Ue,
380
+ {
381
+ loop: !0,
382
+ value: g,
383
+ total: _,
384
+ onChange: (c) => {
385
+ g === _ && c === 1 ? t.moveToNextMatch() : g === 1 && c === _ || c < g ? t.moveToPreviousMatch() : t.moveToNextMatch();
386
+ }
387
+ }
388
+ ),
389
+ value: i,
390
+ onChange: (c) => ae(c)
391
+ }
392
+ ),
393
+ /* @__PURE__ */ d.jsx("div", { className: L.findReplaceExpandContainer, children: /* @__PURE__ */ d.jsx(I, { type: "text", size: "small", onClick: re, children: e.t("univer.find-replace.dialog.advanced-finding") }) })
394
+ ] });
395
+ }
396
+ function ce() {
397
+ return /* @__PURE__ */ d.jsxs(A, { children: [
398
+ /* @__PURE__ */ d.jsx(P, { label: e.t("univer.find-replace.dialog.find"), children: /* @__PURE__ */ d.jsx(
399
+ U,
400
+ {
401
+ placeholder: e.t("univer.find-replace.dialog.find-placeholder"),
402
+ autoFocus: !0,
403
+ value: i,
404
+ onChange: (c) => N(c)
405
+ }
406
+ ) }),
407
+ /* @__PURE__ */ d.jsx(P, { label: e.t("univer.find-replace.dialog.replace"), children: /* @__PURE__ */ d.jsx(
408
+ U,
409
+ {
410
+ placeholder: e.t("univer.find-replace.dialog.replace-placeholder"),
411
+ value: o,
412
+ onChange: (c) => N(c)
413
+ }
414
+ ) }),
415
+ /* @__PURE__ */ d.jsx(P, { label: e.t("univer.find-replace.dialog.find-range"), children: /* @__PURE__ */ d.jsx(Le, { value: "123", onChange: () => {
416
+ } }) }),
417
+ /* @__PURE__ */ d.jsx(I, { type: "primary", children: e.t("univer.find-replace.dialog.find") }),
418
+ /* @__PURE__ */ d.jsx(I, { children: e.t("univer.find-replace.dialog.replace") }),
419
+ /* @__PURE__ */ d.jsx(I, { children: e.t("univer.find-replace.dialog.replace-all") })
420
+ ] });
421
+ }
422
+ return /* @__PURE__ */ d.jsx("div", { className: L.findReplaceDialogContainer, ref: s, children: h.replaceRevealed ? ce() : se() });
423
+ }
424
+ function nt(t) {
232
425
  return {
233
- id: Z.id,
426
+ id: D.id,
427
+ icon: "SearchIcon",
234
428
  tooltip: "toolbar.find-replace",
235
- group: g.TOOLBAR_OTHERS,
236
- type: A.BUTTON,
237
- positions: [S.TOOLBAR_START]
429
+ group: Re.TOOLBAR_OTHERS,
430
+ type: Me.BUTTON,
431
+ positions: [Ie.TOOLBAR_START],
432
+ hidden$: Ce(t, ue.SHEET)
238
433
  };
239
434
  }
240
- var k = Object.defineProperty, G = Object.getOwnPropertyDescriptor, ee = (t, e, i, s) => {
241
- for (var r = s > 1 ? void 0 : s ? G(e, i) : e, n = t.length - 1, a; n >= 0; n--)
242
- (a = t[n]) && (r = (s ? a(e, i, r) : a(r)) || r);
243
- return s && r && k(e, i, r), r;
244
- }, v = (t, e) => (i, s) => e(i, s, t);
245
- let l = class extends O {
246
- constructor(t, e) {
247
- super(), this._menuService = t, this._injector = e, [q].forEach((i) => {
248
- this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(i)));
435
+ const rt = {
436
+ id: D.id,
437
+ description: "shortcut.find-replace.open-find-dialog",
438
+ binding: R.F | j.CTRL_COMMAND,
439
+ group: "4_find-replace",
440
+ preconditions(t) {
441
+ return !t.getContextValue(v);
442
+ }
443
+ }, ot = {
444
+ id: Q.id,
445
+ description: "shortcut.find-replace.open-replace-dialog",
446
+ binding: R.H | j.CTRL_COMMAND,
447
+ group: "4_find-replace",
448
+ preconditions(t) {
449
+ return !t.getContextValue(v);
450
+ }
451
+ }, at = {
452
+ id: X.id,
453
+ description: "shortcut.find-replace.close-dialog",
454
+ binding: R.ESC,
455
+ group: "4_find-replace",
456
+ priority: 1e3,
457
+ preconditions(t) {
458
+ return !!t.getContextValue(v);
459
+ }
460
+ }, st = {
461
+ id: ee.id,
462
+ description: "shortcut.find-replace.go-to-next-find-match",
463
+ binding: R.ENTER,
464
+ group: "4_find-replace",
465
+ priority: 1e3,
466
+ preconditions(t) {
467
+ return !!t.getContextValue(v);
468
+ }
469
+ }, ct = {
470
+ id: te.id,
471
+ description: "shortcut.find-replace.go-to-previous-find-match",
472
+ binding: R.ENTER | j.SHIFT,
473
+ group: "4_find-replace",
474
+ priority: 1e3,
475
+ preconditions(t) {
476
+ return !!t.getContextValue(v);
477
+ }
478
+ };
479
+ var lt = Object.defineProperty, dt = Object.getOwnPropertyDescriptor, ht = (t, e, n, i) => {
480
+ for (var r = i > 1 ? void 0 : i ? dt(e, n) : e, o = t.length - 1, a; o >= 0; o--)
481
+ (a = t[o]) && (r = (i ? a(e, n, r) : a(r)) || r);
482
+ return i && r && lt(e, n, r), r;
483
+ }, p = (t, e) => (n, i) => e(n, i, t);
484
+ const w = "DESKTOP_FIND_REPLACE_DIALOG";
485
+ let C = class extends ve {
486
+ constructor(t, e, n, i, r, o, a, s, h, _) {
487
+ super(), this._menuService = t, this._shortcutService = e, this._commandService = n, this._findReplaceService = i, this._dialogService = r, this._contextService = o, this._focusService = a, this._localeService = s, this._componentManager = h, this._injector = _, this._initOperations(), this._initUI(), this._initShortcuts();
488
+ }
489
+ _initOperations() {
490
+ [
491
+ X,
492
+ D,
493
+ Q,
494
+ qe,
495
+ ee,
496
+ te
497
+ ].forEach((t) => {
498
+ this.disposeWithMe(this._commandService.registerCommand(t));
249
499
  });
250
500
  }
501
+ _initUI() {
502
+ [nt].forEach((t) => {
503
+ this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(t)));
504
+ }), this.disposeWithMe(this._componentManager.register("FindReplaceDialog", it)), this.disposeWithMe(this._componentManager.register("SearchIcon", We)), this._findReplaceService.stateUpdates$.pipe(je(this.dispose$)).subscribe((t) => {
505
+ t.revealed === !0 ? this._openPanel() : t.revealed === !1 && this._closePanel();
506
+ });
507
+ }
508
+ _initShortcuts() {
509
+ [
510
+ ot,
511
+ rt,
512
+ at,
513
+ ct,
514
+ st
515
+ ].forEach((t) => {
516
+ this.disposeWithMe(this._shortcutService.registerShortcut(t));
517
+ });
518
+ }
519
+ _openPanel() {
520
+ this._dialogService.open({
521
+ id: w,
522
+ draggable: !0,
523
+ width: 350,
524
+ title: { title: this._localeService.t("univer.find-replace.dialog.title") },
525
+ children: { label: "FindReplaceDialog" },
526
+ onClose: () => this._closePanel()
527
+ }), this._contextService.setContextValue(v, !0);
528
+ }
529
+ _closePanel() {
530
+ this._dialogService.close(w), this._contextService.setContextValue(v, !1), this._focusService.forceFocus(), this._findReplaceService.end();
531
+ }
532
+ };
533
+ C = ht([
534
+ pe(fe.Rendered, C),
535
+ p(0, Pe),
536
+ p(1, ye),
537
+ p(2, _e),
538
+ p(3, f),
539
+ p(4, Te),
540
+ p(5, ge),
541
+ p(6, be),
542
+ p(7, S(F)),
543
+ p(8, S(Oe)),
544
+ p(9, S(H))
545
+ ], C);
546
+ const ut = {
547
+ univer: {
548
+ "find-replace": {
549
+ dialog: {
550
+ title: "查找",
551
+ find: "查找",
552
+ replace: "替换",
553
+ "replace-all": "替换全部",
554
+ "find-range": "查找范围",
555
+ "find-placeholder": "输入查找内容",
556
+ "advanced-finding": "替换 / 高级查找",
557
+ "replace-placeholder": "输入替换内容"
558
+ }
559
+ }
560
+ }
251
561
  };
252
- l = ee([
253
- D(y.Steady, l),
254
- v(0, Q),
255
- v(1, N(P))
256
- ], l);
257
- const te = "FIND_REPLACE";
258
- class ae extends M {
259
- constructor(e) {
260
- super(te), this._injector = e;
261
- }
262
- onStarting(e) {
263
- [[l]].forEach((i) => {
264
- e.add(i);
562
+ var pt = Object.defineProperty, ft = Object.getOwnPropertyDescriptor, vt = (t, e, n, i) => {
563
+ for (var r = i > 1 ? void 0 : i ? ft(e, n) : e, o = t.length - 1, a; o >= 0; o--)
564
+ (a = t[o]) && (r = (i ? a(e, n, r) : a(r)) || r);
565
+ return i && r && pt(e, n, r), r;
566
+ }, _t = (t, e) => (n, i) => e(n, i, t);
567
+ const gt = "FIND_REPLACE";
568
+ let V = class extends me {
569
+ constructor(t, e) {
570
+ super(gt), this._injector = t, this._localeService = e, this._localeService.load({
571
+ zhCN: ut
265
572
  });
266
573
  }
267
- }
574
+ onStarting(t) {
575
+ [[C], [f, { useClass: b }]].forEach(
576
+ (e) => {
577
+ t.add(e);
578
+ }
579
+ );
580
+ }
581
+ };
582
+ V = vt([
583
+ _t(1, S(F))
584
+ ], V);
268
585
  export {
269
- ae as UniverFindReplacePlugin
586
+ Pt as FindModel,
587
+ f as IFindReplaceService,
588
+ V as UniverFindReplacePlugin
270
589
  };