@univerjs/find-replace 0.1.0-beta.2 → 0.1.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/es/index.js CHANGED
@@ -1,270 +1,586 @@
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 W } from "@wendellhu/redi";
6
+ import { LayoutService as xe, MenuGroup as Re, MenuItemType as Me, MenuPosition as Ie, getMenuHiddenObservable as Oe, KeyCode as R, MetaKeys as j, ComponentManager as Pe, IMenuService as Ce, 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 z, useRef as H, createElement as k, 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 C, Input as U, Select as we } 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
+ }, Le = 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 = z(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 = H("_".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 k(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 We = {
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
+ { tag: "path", attrs: { fill: "#D9D9D9", d: "M.9.09h16v16H.9z" } }
73
+ ]
74
+ },
75
+ {
76
+ tag: "g",
77
+ attrs: { mask: "url(#mask0_217_40)" },
78
+ children: [
79
+ {
80
+ tag: "path",
81
+ attrs: {
82
+ fill: "currentColor",
83
+ d: "M2.4 7.37a5.78 5.78 0 1110.31 3.58l2.49 2.48a.68.68 0 01-.97.96l-2.48-2.48A5.78 5.78 0 012.4 7.37zm5.77-4.42a4.42 4.42 0 100 8.84 4.42 4.42 0 000-8.84z",
84
+ fillRule: "evenodd",
85
+ clipRule: "evenodd"
86
+ }
87
+ }
88
+ ]
89
+ }
90
+ ]
91
+ }, J = z(function(t, e) {
92
+ return k(K, Object.assign({}, t, {
93
+ id: "search-single-16",
94
+ ref: e,
95
+ icon: We
96
+ }));
97
+ });
98
+ J.displayName = "SearchSingle16";
99
+ const ze = J;
100
+ var He = Object.defineProperty, ke = Object.getOwnPropertyDescriptor, Y = (t, e, n, i) => {
101
+ for (var r = i > 1 ? void 0 : i ? ke(e, n) : e, o = t.length - 1, a; o >= 0; o--)
102
+ (a = t[o]) && (r = (i ? a(e, n, r) : a(r)) || r);
103
+ return i && r && He(e, n, r), r;
104
+ }, x = (t, e) => (n, i) => e(n, i, t);
105
+ class Ct extends E {
106
+ }
107
+ const f = Se("univer.find-replace.service");
108
+ let T = class extends E {
109
+ constructor(e, n, i, r) {
82
110
  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
- );
111
+ l(this, "_matchPositionFindModel", null);
112
+ l(this, "_findModels", []);
113
+ l(this, "_matches", []);
114
+ l(this, "_positionModel", null);
115
+ this._state = e, this._providers = n, this._logService = i, this._univerInstanceService = r, this._state.stateUpdates$.subscribe((o) => {
116
+ typeof o.findString < "u" && (o.findString ? this.find() : this._cancelFinding());
117
+ });
118
+ }
119
+ async find() {
120
+ this._cancelFinding();
121
+ 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();
122
+ if (this._matches = i, !i.length)
123
+ return {
124
+ results: []
125
+ };
126
+ const r = this._moveToInitialMatch(n, i);
127
+ return this._state.changeState({
128
+ matchesCount: i.length,
129
+ matchesPosition: r + 1
130
+ // the matches position start from 1
131
+ }), {
132
+ results: i
133
+ };
94
134
  }
95
- setDisable(e) {
96
- this._disable = e;
135
+ moveToNextMatch() {
136
+ if (!this._positionModel)
137
+ return;
138
+ const e = this._findModels.length === 1, n = this._positionModel.moveToNextMatch(e);
139
+ if (n) {
140
+ const i = this._matches.findIndex((r) => r === n);
141
+ this._state.changeState({
142
+ matchesPosition: i + 1
143
+ });
144
+ } else {
145
+ 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);
146
+ this._positionModel = r, this._state.changeState({
147
+ matchesPosition: a + 1
148
+ });
149
+ }
150
+ }
151
+ moveToPreviousMatch() {
152
+ if (!this._positionModel)
153
+ return;
154
+ const e = this._findModels.length === 1, n = this._positionModel.moveToPreviousMatch(e);
155
+ if (n) {
156
+ const i = this._matches.findIndex((r) => r === n);
157
+ this._state.changeState({
158
+ matchesPosition: i + 1
159
+ });
160
+ } else {
161
+ 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);
162
+ this._positionModel = r, this._state.changeState({
163
+ matchesPosition: a + 1
164
+ });
165
+ }
97
166
  }
98
- getAllShortcuts() {
99
- return Array.from(this._shortCutMapping.values()).map((e) => Array.from(e.values())).flat();
167
+ // TODO@wzhudev: some cold could definitely be reused. Reuse them.
168
+ _moveToInitialMatch(e, n) {
169
+ var s;
170
+ const i = (s = this._univerInstanceService.getFocusedUniverInstance()) == null ? void 0 : s.getUnitId();
171
+ if (!i)
172
+ return -1;
173
+ const r = e.find((h) => h.unitId === i);
174
+ if (r) {
175
+ this._positionModel = r;
176
+ const h = r.moveToNextMatch();
177
+ return n.findIndex((g) => g === h);
178
+ }
179
+ this._positionModel = e[0];
180
+ const o = this._positionModel.moveToNextMatch();
181
+ return this._matches.findIndex((h) => h === o);
100
182
  }
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();
183
+ _cancelFinding() {
184
+ this._providers.forEach((e) => e.cancel()), this._state.changeState({
185
+ matchesCount: 0,
186
+ matchesPosition: 0
108
187
  });
109
188
  }
110
- getShortcutDisplayOfCommand(e) {
111
- const i = this._commandIDMapping.get(e);
112
- return i ? this.getShortcutDisplay(i.values().next().value) : null;
189
+ };
190
+ T = Y([
191
+ x(2, B),
192
+ x(3, G)
193
+ ], T);
194
+ function Q() {
195
+ return {
196
+ revealed: !0,
197
+ findString: "",
198
+ replaceRevealed: !1,
199
+ matchesPosition: 0,
200
+ matchesCount: 0
201
+ };
202
+ }
203
+ class Ke {
204
+ constructor() {
205
+ l(this, "_stateUpdates$", new Ee());
206
+ l(this, "stateUpdates$", this._stateUpdates$.asObservable());
207
+ l(this, "_state$", new Fe(Q()));
208
+ l(this, "state$", this._state$.asObservable());
209
+ // TODO@wzhudev: put all state properties here
210
+ l(this, "_findString", "");
211
+ l(this, "_revealed", !1);
212
+ l(this, "_replaceRevealed", !1);
213
+ l(this, "_matchesPosition", 0);
214
+ l(this, "_matchesCount", 0);
113
215
  }
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+" : ""}${_}`;
216
+ get state() {
217
+ return this._state$.getValue();
117
218
  }
118
- _emitShortcutChanged() {
119
- this._shortcutChanged$.next();
219
+ get findString() {
220
+ return this._findString;
120
221
  }
121
- forceEscape() {
122
- return this._forceEscaped = !0, h(() => this._forceEscaped = !1);
222
+ changeState(e) {
223
+ let n = !1;
224
+ const i = {};
225
+ 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({
226
+ findString: this._findString,
227
+ revealed: this._revealed,
228
+ replaceRevealed: this._replaceRevealed,
229
+ matchesCount: this._matchesCount,
230
+ matchesPosition: this._matchesPosition
231
+ }));
123
232
  }
124
- _resolveKeyboardEvent(e) {
125
- if (this._forceEscaped || this._disable || this._layoutService && !this._layoutService.checkElementInCurrentApplicationScope(e.target))
126
- return;
127
- this._dispatch(e) && e.preventDefault();
233
+ }
234
+ let b = class extends E {
235
+ constructor(e, n, i) {
236
+ super();
237
+ l(this, "_providers", /* @__PURE__ */ new Set());
238
+ l(this, "_state", new Ke());
239
+ l(this, "_model");
240
+ this._injector = e, this._univerInstanceService = n, this._logService = i;
128
241
  }
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;
242
+ get stateUpdates$() {
243
+ return this._state.stateUpdates$;
244
+ }
245
+ get state$() {
246
+ return this._state.state$;
247
+ }
248
+ changeFindString(e) {
249
+ this._state.changeState({
250
+ findString: e
139
251
  });
140
- return r ? (this._commandService.executeCommand(r.id, r.staticParameters), !0) : !1;
141
252
  }
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;
253
+ moveToNextMatch() {
254
+ var e;
255
+ this._model && ((e = this._model) == null || e.moveToNextMatch());
144
256
  }
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;
257
+ moveToPreviousMatch() {
258
+ var e;
259
+ this._model && ((e = this._model) == null || e.moveToPreviousMatch());
149
260
  }
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
- });
261
+ replace() {
262
+ return !0;
196
263
  }
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 [];
264
+ replaceAll() {
265
+ return !0;
266
+ }
267
+ revealReplace() {
268
+ this._state.changeState({ replaceRevealed: !0 });
204
269
  }
205
- getMenuItem(e) {
206
- return this._menuItemMap.has(e) ? this._menuItemMap.get(e) : null;
270
+ disposeModel() {
271
+ var e;
272
+ (e = this._model) == null || e.dispose(), this._model = null;
273
+ }
274
+ start() {
275
+ if (this._providers.size === 0)
276
+ return !1;
277
+ this._model = this._injector.createInstance(T, this._state, this._providers);
278
+ const e = Q();
279
+ return e.revealed = !0, this._state.changeState(e), !0;
207
280
  }
208
- _getDisplayMenuItems(e) {
209
- const i = this._shortcutService.getShortcutDisplayOfCommand(e.id);
210
- return i ? {
211
- ...e,
212
- shortcut: i
213
- } : e;
281
+ end() {
282
+ return this._state.changeState({ revealed: !1, replaceRevealed: !1 }), !0;
214
283
  }
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]);
284
+ registerFindReplaceProvider(e) {
285
+ return this._providers.add(e), he(() => this._providers.delete(e));
221
286
  }
222
287
  };
223
- m = z([
224
- J(0, W)
225
- ], m);
226
- const Z = {
227
- type: B.OPERATION,
228
- id: "ui.operation.toggle-find-replace-dialog",
288
+ b = Y([
289
+ x(0, S(W)),
290
+ x(1, G),
291
+ x(2, B)
292
+ ], b);
293
+ const D = {
294
+ id: "ui.operation.open-find-dialog",
295
+ type: m.OPERATION,
296
+ handler: (t) => (t.get(f).start(), !0)
297
+ }, X = {
298
+ id: "ui.operation.open-replace-dialog",
299
+ type: m.OPERATION,
300
+ handler: (t) => (t.get(f).start(), !0)
301
+ }, qe = {
302
+ id: "ui.operation.toggle-replace-dialog",
303
+ type: m.OPERATION,
304
+ handler: (t) => (t.get(f), !0)
305
+ }, Z = {
306
+ id: "ui.operation.close-find-replace-dialog",
307
+ type: m.OPERATION,
229
308
  handler: (t) => !0
309
+ }, ee = {
310
+ type: m.OPERATION,
311
+ id: "ui.operation.go-to-next-match",
312
+ handler: (t) => (t.get(f).moveToNextMatch(), !0)
313
+ }, te = {
314
+ type: m.OPERATION,
315
+ id: "ui.operation.go-to-previous-match",
316
+ handler: (t) => (t.get(f).moveToPreviousMatch(), !0)
317
+ }, v = "FIND_REPLACE_ACTIVATED";
318
+ var ie = { exports: {} }, P = {};
319
+ /**
320
+ * @license React
321
+ * react-jsx-runtime.production.min.js
322
+ *
323
+ * Copyright (c) Facebook, Inc. and its affiliates.
324
+ *
325
+ * This source code is licensed under the MIT license found in the
326
+ * LICENSE file in the root directory of this source tree.
327
+ */
328
+ var Je = De, Ye = Symbol.for("react.element"), Qe = Symbol.for("react.fragment"), Xe = Object.prototype.hasOwnProperty, Ze = Je.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, et = { key: !0, ref: !0, __self: !0, __source: !0 };
329
+ function ne(t, e, n) {
330
+ var i, r = {}, o = null, a = null;
331
+ n !== void 0 && (o = "" + n), e.key !== void 0 && (o = "" + e.key), e.ref !== void 0 && (a = e.ref);
332
+ for (i in e)
333
+ Xe.call(e, i) && !et.hasOwnProperty(i) && (r[i] = e[i]);
334
+ if (t && t.defaultProps)
335
+ for (i in e = t.defaultProps, e)
336
+ r[i] === void 0 && (r[i] = e[i]);
337
+ return { $$typeof: Ye, type: t, key: o, ref: a, props: r, _owner: Ze.current };
338
+ }
339
+ P.Fragment = Qe;
340
+ P.jsx = ne;
341
+ P.jsxs = ne;
342
+ ie.exports = P;
343
+ var d = ie.exports;
344
+ const tt = "univer-find-replace-expand-container", w = {
345
+ findReplaceExpandContainer: tt
230
346
  };
231
- function q(t) {
347
+ function it() {
348
+ const t = y(f), e = y(F), n = y(xe), [i, r] = $(""), [o, a] = $(""), s = H(null), h = $e(t.state$, !0), { matchesCount: _, matchesPosition: g } = h, re = M(() => t.revealReplace(), [t]), oe = M(
349
+ (c) => t.changeFindString(c),
350
+ // FIXME@wzhudev: this throttle function has no leading and taling config hence has some problems
351
+ // throttle((findString: string) => findReplaceService.changeFindString(findString), FIND_THROTTLE_TIME),
352
+ [t]
353
+ ), ae = M(
354
+ (c) => {
355
+ r(c), oe(c);
356
+ },
357
+ [t]
358
+ ), N = M(
359
+ (c) => {
360
+ a(c);
361
+ },
362
+ [t]
363
+ );
364
+ Ne(() => {
365
+ let c;
366
+ return s.current && (c = n.registerContainer(s.current)), () => c == null ? void 0 : c.dispose();
367
+ }, [s.current]);
368
+ function se() {
369
+ return /* @__PURE__ */ d.jsxs(A, { children: [
370
+ /* @__PURE__ */ d.jsx(
371
+ Ae,
372
+ {
373
+ autoFocus: !0,
374
+ placeholder: e.t("univer.find-replace.dialog.find-placeholder"),
375
+ slot: /* @__PURE__ */ d.jsx(
376
+ Ue,
377
+ {
378
+ loop: !0,
379
+ value: g,
380
+ total: _,
381
+ onChange: (c) => {
382
+ g === _ && c === 1 ? t.moveToNextMatch() : g === 1 && c === _ || c < g ? t.moveToPreviousMatch() : t.moveToNextMatch();
383
+ }
384
+ }
385
+ ),
386
+ value: i,
387
+ onChange: (c) => ae(c)
388
+ }
389
+ ),
390
+ /* @__PURE__ */ d.jsx("div", { className: w.findReplaceExpandContainer, children: /* @__PURE__ */ d.jsx(I, { type: "text", size: "small", onClick: re, children: e.t("univer.find-replace.dialog.advanced-finding") }) })
391
+ ] });
392
+ }
393
+ function ce() {
394
+ return /* @__PURE__ */ d.jsxs(A, { children: [
395
+ /* @__PURE__ */ d.jsx(C, { label: e.t("univer.find-replace.dialog.find"), children: /* @__PURE__ */ d.jsx(
396
+ U,
397
+ {
398
+ placeholder: e.t("univer.find-replace.dialog.find-placeholder"),
399
+ autoFocus: !0,
400
+ value: i,
401
+ onChange: (c) => N(c)
402
+ }
403
+ ) }),
404
+ /* @__PURE__ */ d.jsx(C, { label: e.t("univer.find-replace.dialog.replace"), children: /* @__PURE__ */ d.jsx(
405
+ U,
406
+ {
407
+ placeholder: e.t("univer.find-replace.dialog.replace-placeholder"),
408
+ value: o,
409
+ onChange: (c) => N(c)
410
+ }
411
+ ) }),
412
+ /* @__PURE__ */ d.jsx(C, { label: e.t("univer.find-replace.dialog.find-range"), children: /* @__PURE__ */ d.jsx(we, { value: "123", onChange: () => {
413
+ } }) }),
414
+ /* @__PURE__ */ d.jsx(I, { type: "primary", children: e.t("univer.find-replace.dialog.find") }),
415
+ /* @__PURE__ */ d.jsx(I, { children: e.t("univer.find-replace.dialog.replace") }),
416
+ /* @__PURE__ */ d.jsx(I, { children: e.t("univer.find-replace.dialog.replace-all") })
417
+ ] });
418
+ }
419
+ return /* @__PURE__ */ d.jsx("div", { className: w.findReplaceDialogContainer, ref: s, children: h.replaceRevealed ? ce() : se() });
420
+ }
421
+ function nt(t) {
232
422
  return {
233
- id: Z.id,
423
+ id: D.id,
424
+ icon: "SearchIcon",
234
425
  tooltip: "toolbar.find-replace",
235
- group: g.TOOLBAR_OTHERS,
236
- type: A.BUTTON,
237
- positions: [S.TOOLBAR_START]
426
+ group: Re.TOOLBAR_OTHERS,
427
+ type: Me.BUTTON,
428
+ positions: [Ie.TOOLBAR_START],
429
+ hidden$: Oe(t, ue.SHEET)
238
430
  };
239
431
  }
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)));
432
+ const rt = {
433
+ id: D.id,
434
+ description: "shortcut.find-replace.open-find-dialog",
435
+ binding: R.F | j.CTRL_COMMAND,
436
+ group: "4_find-replace",
437
+ preconditions(t) {
438
+ return !t.getContextValue(v);
439
+ }
440
+ }, ot = {
441
+ id: X.id,
442
+ description: "shortcut.find-replace.open-replace-dialog",
443
+ binding: R.H | j.CTRL_COMMAND,
444
+ group: "4_find-replace",
445
+ preconditions(t) {
446
+ return !t.getContextValue(v);
447
+ }
448
+ }, at = {
449
+ id: Z.id,
450
+ description: "shortcut.find-replace.close-dialog",
451
+ binding: R.ESC,
452
+ group: "4_find-replace",
453
+ priority: 1e3,
454
+ preconditions(t) {
455
+ return !!t.getContextValue(v);
456
+ }
457
+ }, st = {
458
+ id: ee.id,
459
+ description: "shortcut.find-replace.go-to-next-find-match",
460
+ binding: R.ENTER,
461
+ group: "4_find-replace",
462
+ priority: 1e3,
463
+ preconditions(t) {
464
+ return !!t.getContextValue(v);
465
+ }
466
+ }, ct = {
467
+ id: te.id,
468
+ description: "shortcut.find-replace.go-to-previous-find-match",
469
+ binding: R.ENTER | j.SHIFT,
470
+ group: "4_find-replace",
471
+ priority: 1e3,
472
+ preconditions(t) {
473
+ return !!t.getContextValue(v);
474
+ }
475
+ };
476
+ var lt = Object.defineProperty, dt = Object.getOwnPropertyDescriptor, ht = (t, e, n, i) => {
477
+ for (var r = i > 1 ? void 0 : i ? dt(e, n) : e, o = t.length - 1, a; o >= 0; o--)
478
+ (a = t[o]) && (r = (i ? a(e, n, r) : a(r)) || r);
479
+ return i && r && lt(e, n, r), r;
480
+ }, p = (t, e) => (n, i) => e(n, i, t);
481
+ const L = "DESKTOP_FIND_REPLACE_DIALOG";
482
+ let O = class extends ve {
483
+ constructor(t, e, n, i, r, o, a, s, h, _) {
484
+ 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();
485
+ }
486
+ _initOperations() {
487
+ [
488
+ Z,
489
+ D,
490
+ X,
491
+ qe,
492
+ ee,
493
+ te
494
+ ].forEach((t) => {
495
+ this.disposeWithMe(this._commandService.registerCommand(t));
249
496
  });
250
497
  }
498
+ _initUI() {
499
+ [nt].forEach((t) => {
500
+ this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(t)));
501
+ }), this.disposeWithMe(this._componentManager.register("FindReplaceDialog", it)), this.disposeWithMe(this._componentManager.register("SearchIcon", ze)), this._findReplaceService.stateUpdates$.pipe(je(this.dispose$)).subscribe((t) => {
502
+ t.revealed === !0 ? this._openPanel() : t.revealed === !1 && this._closePanel();
503
+ });
504
+ }
505
+ _initShortcuts() {
506
+ [
507
+ ot,
508
+ rt,
509
+ at,
510
+ ct,
511
+ st
512
+ ].forEach((t) => {
513
+ this.disposeWithMe(this._shortcutService.registerShortcut(t));
514
+ });
515
+ }
516
+ _openPanel() {
517
+ this._dialogService.open({
518
+ id: L,
519
+ draggable: !0,
520
+ width: 350,
521
+ title: { title: this._localeService.t("univer.find-replace.dialog.title") },
522
+ children: { label: "FindReplaceDialog" },
523
+ onClose: () => this._closePanel()
524
+ }), this._contextService.setContextValue(v, !0);
525
+ }
526
+ _closePanel() {
527
+ this._dialogService.close(L), this._contextService.setContextValue(v, !1), this._focusService.forceFocus(), this._findReplaceService.end();
528
+ }
529
+ };
530
+ O = ht([
531
+ pe(fe.Rendered, O),
532
+ p(0, Ce),
533
+ p(1, ye),
534
+ p(2, _e),
535
+ p(3, f),
536
+ p(4, Te),
537
+ p(5, ge),
538
+ p(6, be),
539
+ p(7, S(F)),
540
+ p(8, S(Pe)),
541
+ p(9, S(W))
542
+ ], O);
543
+ const ut = {
544
+ univer: {
545
+ "find-replace": {
546
+ dialog: {
547
+ title: "查找",
548
+ find: "查找",
549
+ replace: "替换",
550
+ "replace-all": "替换全部",
551
+ "find-range": "查找范围",
552
+ "find-placeholder": "输入查找内容",
553
+ "advanced-finding": "替换 / 高级查找",
554
+ "replace-placeholder": "输入替换内容"
555
+ }
556
+ }
557
+ }
251
558
  };
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);
559
+ var pt = Object.defineProperty, ft = Object.getOwnPropertyDescriptor, vt = (t, e, n, i) => {
560
+ for (var r = i > 1 ? void 0 : i ? ft(e, n) : e, o = t.length - 1, a; o >= 0; o--)
561
+ (a = t[o]) && (r = (i ? a(e, n, r) : a(r)) || r);
562
+ return i && r && pt(e, n, r), r;
563
+ }, _t = (t, e) => (n, i) => e(n, i, t);
564
+ const gt = "FIND_REPLACE";
565
+ let V = class extends me {
566
+ constructor(t, e) {
567
+ super(gt), this._injector = t, this._localeService = e, this._localeService.load({
568
+ zhCN: ut
265
569
  });
266
570
  }
267
- }
571
+ onStarting(t) {
572
+ [[O], [f, { useClass: b }]].forEach(
573
+ (e) => {
574
+ t.add(e);
575
+ }
576
+ );
577
+ }
578
+ };
579
+ V = vt([
580
+ _t(1, S(F))
581
+ ], V);
268
582
  export {
269
- ae as UniverFindReplacePlugin
583
+ Ct as FindModel,
584
+ f as IFindReplaceService,
585
+ V as UniverFindReplacePlugin
270
586
  };