@univerjs/find-replace 0.2.4 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +2 -2
- package/lib/es/index.js +596 -570
- package/lib/types/controllers/find-replace.controller.d.ts +1 -2
- package/lib/types/controllers/find-replace.menu.d.ts +1 -1
- package/lib/types/plugin.d.ts +2 -3
- package/lib/types/services/find-replace.service.d.ts +2 -3
- package/lib/umd/index.js +2 -2
- package/package.json +15 -17
package/lib/es/index.js
CHANGED
|
@@ -1,92 +1,99 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
import { createIdentifier
|
|
6
|
-
import { IConfirmService
|
|
7
|
-
import { BehaviorSubject
|
|
8
|
-
import { RENDER_RAW_FORMULA_KEY
|
|
9
|
-
import
|
|
10
|
-
import { MessageType
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
for (var r in e) Object.prototype.hasOwnProperty.call(e, r) && (t[r] = e[r]);
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
|
|
3
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
5
|
+
import { Disposable, createIdentifier, Inject, Injector, IUniverInstanceService, toDisposable, IContextService, DisposableCollection, CommandType, LocaleService, useDependency, ICommandService, FOCUSING_SHEET, EDITOR_ACTIVATED, UniverInstanceType, RxDisposable, OnLifecycle, LifecycleStages, Plugin, Tools } from "@univerjs/core";
|
|
6
|
+
import { IConfirmService, IMessageService, useObservable, ILayoutService, KeyCode, MetaKeys, MenuGroup, MenuItemType, MenuPosition, getMenuHiddenObservable, ComponentManager, IMenuService, IShortcutService, IDialogService } from "@univerjs/ui";
|
|
7
|
+
import { BehaviorSubject, Subject, throttleTime, combineLatest, debounceTime, fromEvent, map, takeUntil } from "rxjs";
|
|
8
|
+
import { RENDER_RAW_FORMULA_KEY } from "@univerjs/engine-render";
|
|
9
|
+
import require$$0, { forwardRef, useRef, createElement, useCallback, Fragment, useEffect, useMemo, useImperativeHandle } from "react";
|
|
10
|
+
import { MessageType, InputWithSlot, Pager, Button, FormLayout, Input, Select, FormDualColumnLayout, Checkbox } from "@univerjs/design";
|
|
11
|
+
var __assign = function() {
|
|
12
|
+
return __assign = Object.assign || function(t) {
|
|
13
|
+
for (var s, i = 1, n2 = arguments.length; i < n2; i++) {
|
|
14
|
+
s = arguments[i];
|
|
15
|
+
for (var p2 in s) Object.prototype.hasOwnProperty.call(s, p2) && (t[p2] = s[p2]);
|
|
17
16
|
}
|
|
18
17
|
return t;
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
var
|
|
22
|
-
for (var
|
|
23
|
-
if (
|
|
24
|
-
for (var
|
|
25
|
-
e.indexOf(i
|
|
26
|
-
return
|
|
27
|
-
},
|
|
28
|
-
var
|
|
29
|
-
return
|
|
18
|
+
}, __assign.apply(this, arguments);
|
|
19
|
+
}, __rest = function(s, e) {
|
|
20
|
+
var t = {};
|
|
21
|
+
for (var p2 in s) Object.prototype.hasOwnProperty.call(s, p2) && e.indexOf(p2) < 0 && (t[p2] = s[p2]);
|
|
22
|
+
if (s != null && typeof Object.getOwnPropertySymbols == "function")
|
|
23
|
+
for (var i = 0, p2 = Object.getOwnPropertySymbols(s); i < p2.length; i++)
|
|
24
|
+
e.indexOf(p2[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p2[i]) && (t[p2[i]] = s[p2[i]]);
|
|
25
|
+
return t;
|
|
26
|
+
}, IconBase = forwardRef(function(props, ref) {
|
|
27
|
+
var icon = props.icon, id = props.id, className = props.className, extend = props.extend, restProps = __rest(props, ["icon", "id", "className", "extend"]), cls = "univerjs-icon univerjs-icon-".concat(id, " ").concat(className || "").trim(), idSuffix = useRef("_".concat(generateShortUuid()));
|
|
28
|
+
return render(icon, "".concat(id), { defIds: icon.defIds, idSuffix: idSuffix.current }, __assign({ ref, className: cls }, restProps), extend);
|
|
30
29
|
});
|
|
31
|
-
function
|
|
32
|
-
return
|
|
33
|
-
return
|
|
30
|
+
function render(node, id, runtimeProps, rootProps, extend) {
|
|
31
|
+
return createElement(node.tag, __assign(__assign({ key: id }, replaceRuntimeIdsAndExtInAttrs(node, runtimeProps, extend)), rootProps), (replaceRuntimeIdsInDefs(node, runtimeProps).children || []).map(function(child, index) {
|
|
32
|
+
return render(child, "".concat(id, "-").concat(node.tag, "-").concat(index), runtimeProps, void 0, extend);
|
|
34
33
|
}));
|
|
35
34
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
35
|
+
__name(render, "render");
|
|
36
|
+
function replaceRuntimeIdsAndExtInAttrs(node, runtimeProps, extend) {
|
|
37
|
+
var attrs = __assign({}, node.attrs);
|
|
38
|
+
extend != null && extend.colorChannel1 && attrs.fill === "colorChannel1" && (attrs.fill = extend.colorChannel1);
|
|
39
|
+
var defIds = runtimeProps.defIds;
|
|
40
|
+
return !defIds || defIds.length === 0 || (node.tag === "use" && attrs["xlink:href"] && (attrs["xlink:href"] = attrs["xlink:href"] + runtimeProps.idSuffix), Object.entries(attrs).forEach(function(_a5) {
|
|
41
|
+
var key = _a5[0], value = _a5[1];
|
|
42
|
+
typeof value == "string" && (attrs[key] = value.replace(/url\(#(.*)\)/, "url(#$1".concat(runtimeProps.idSuffix, ")")));
|
|
43
|
+
})), attrs;
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
__name(replaceRuntimeIdsAndExtInAttrs, "replaceRuntimeIdsAndExtInAttrs");
|
|
46
|
+
function replaceRuntimeIdsInDefs(node, runtimeProps) {
|
|
47
|
+
var _a5, defIds = runtimeProps.defIds;
|
|
48
|
+
return !defIds || defIds.length === 0 ? node : node.tag === "defs" && (!((_a5 = node.children) === null || _a5 === void 0) && _a5.length) ? __assign(__assign({}, node), { children: node.children.map(function(child) {
|
|
49
|
+
return typeof child.attrs.id == "string" && defIds && defIds.indexOf(child.attrs.id) > -1 ? __assign(__assign({}, child), { attrs: __assign(__assign({}, child.attrs), { id: child.attrs.id + runtimeProps.idSuffix }) }) : child;
|
|
50
|
+
}) }) : node;
|
|
50
51
|
}
|
|
51
|
-
|
|
52
|
+
__name(replaceRuntimeIdsInDefs, "replaceRuntimeIdsInDefs");
|
|
53
|
+
function generateShortUuid() {
|
|
52
54
|
return Math.random().toString(36).substring(2, 8);
|
|
53
55
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
__name(generateShortUuid, "generateShortUuid");
|
|
57
|
+
IconBase.displayName = "UniverIcon";
|
|
58
|
+
var element = { 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" } }] }] }, SearchSingle16 = forwardRef(function(props, ref) {
|
|
59
|
+
return createElement(IconBase, Object.assign({}, props, {
|
|
57
60
|
id: "search-single-16",
|
|
58
|
-
ref
|
|
59
|
-
icon:
|
|
61
|
+
ref,
|
|
62
|
+
icon: element
|
|
60
63
|
}));
|
|
61
64
|
});
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
var
|
|
65
|
-
for (var
|
|
66
|
-
(
|
|
67
|
-
return
|
|
68
|
-
},
|
|
69
|
-
class
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
65
|
+
SearchSingle16.displayName = "SearchSingle16";
|
|
66
|
+
const FIND_REPLACE_INPUT_FOCUS = "FIND_REPLACE_INPUT_FOCUS", FIND_REPLACE_DIALOG_FOCUS = "FIND_REPLACE_DIALOG_FOCUS", FIND_REPLACE_REPLACE_REVEALED = "FIND_REPLACE_REPLACE_REVEALED";
|
|
67
|
+
var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
68
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
69
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
70
|
+
return kind && result && __defProp$2(target, key, result), result;
|
|
71
|
+
}, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2");
|
|
72
|
+
const _FindModel = class _FindModel extends Disposable {
|
|
73
|
+
};
|
|
74
|
+
__name(_FindModel, "FindModel");
|
|
75
|
+
let FindModel = _FindModel;
|
|
76
|
+
const IFindReplaceService = createIdentifier("find-replace.service");
|
|
77
|
+
function shouldStateUpdateTriggerResearch(statusUpdate) {
|
|
78
|
+
return typeof statusUpdate.findString < "u" || typeof statusUpdate.inputtingFindString < "u" || typeof statusUpdate.findDirection < "u" || typeof statusUpdate.matchesTheWholeCell < "u" || typeof statusUpdate.caseSensitive < "u" || typeof statusUpdate.findScope < "u" || typeof statusUpdate.findBy < "u";
|
|
74
79
|
}
|
|
75
|
-
|
|
76
|
-
|
|
80
|
+
__name(shouldStateUpdateTriggerResearch, "shouldStateUpdateTriggerResearch");
|
|
81
|
+
var _a;
|
|
82
|
+
let FindReplaceModel = (_a = class extends Disposable {
|
|
83
|
+
constructor(_state, _providers, _univerInstanceService) {
|
|
77
84
|
super();
|
|
78
|
-
|
|
79
|
-
|
|
85
|
+
__publicField(this, "currentMatch$", new BehaviorSubject(null));
|
|
86
|
+
__publicField(this, "replaceables$", new BehaviorSubject([]));
|
|
80
87
|
/** All find models returned by providers. */
|
|
81
|
-
|
|
88
|
+
__publicField(this, "_findModels", []);
|
|
82
89
|
/** The find model that the current match is from. */
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
this._state =
|
|
87
|
-
this._state.stateUpdates$.pipe(
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
+
__publicField(this, "_matchingModel", null);
|
|
91
|
+
__publicField(this, "_matches", []);
|
|
92
|
+
__publicField(this, "_currentSearchingDisposables", null);
|
|
93
|
+
this._state = _state, this._providers = _providers, this._univerInstanceService = _univerInstanceService, this.disposeWithMe(
|
|
94
|
+
this._state.stateUpdates$.pipe(throttleTime(200, void 0, { leading: !0, trailing: !0 })).subscribe(async (stateUpdate) => {
|
|
95
|
+
const state = this._state.state;
|
|
96
|
+
shouldStateUpdateTriggerResearch(stateUpdate) && (state.findString !== "" && !state.replaceRevealed ? (await this._startSearching(), this._state.changeState({ findCompleted: !0 })) : stateUpdate.replaceRevealed !== !0 && this._stopSearching());
|
|
90
97
|
})
|
|
91
98
|
);
|
|
92
99
|
}
|
|
@@ -94,19 +101,19 @@ let K = class extends X {
|
|
|
94
101
|
return this._findModels.length > 0;
|
|
95
102
|
}
|
|
96
103
|
dispose() {
|
|
97
|
-
super.dispose(), this._stopSearching(), this.currentMatch$.complete(), this.replaceables$.complete(), this._state.changeState({ ...
|
|
104
|
+
super.dispose(), this._stopSearching(), this.currentMatch$.complete(), this.replaceables$.complete(), this._state.changeState({ ...createInitFindReplaceState(), revealed: !1 });
|
|
98
105
|
}
|
|
99
106
|
async start() {
|
|
100
107
|
if (!this._state.findString)
|
|
101
108
|
return { results: [] };
|
|
102
|
-
const
|
|
103
|
-
return this._state.changeState({ findCompleted: !0 }),
|
|
109
|
+
const complete = await this._startSearching();
|
|
110
|
+
return this._state.changeState({ findCompleted: !0 }), complete;
|
|
104
111
|
}
|
|
105
112
|
/** Call this method to start a `searching`. */
|
|
106
113
|
async _startSearching() {
|
|
107
114
|
if (!this._state.findString)
|
|
108
115
|
return { results: [] };
|
|
109
|
-
const
|
|
116
|
+
const providers = Array.from(this._providers), findModels = this._findModels = (await Promise.all(providers.map((provider) => provider.find({
|
|
110
117
|
findString: this._state.findString,
|
|
111
118
|
findDirection: this._state.findDirection,
|
|
112
119
|
findScope: this._state.findScope,
|
|
@@ -115,111 +122,111 @@ let K = class extends X {
|
|
|
115
122
|
caseSensitive: this._state.caseSensitive,
|
|
116
123
|
matchesTheWholeCell: this._state.matchesTheWholeCell
|
|
117
124
|
})))).flat();
|
|
118
|
-
this._subscribeToModelsChanges(
|
|
119
|
-
const
|
|
120
|
-
return this.replaceables$.next(
|
|
125
|
+
this._subscribeToModelsChanges(findModels);
|
|
126
|
+
const newMatches = this._matches = findModels.map((c) => c.getMatches()).flat();
|
|
127
|
+
return this.replaceables$.next(newMatches.filter((m2) => m2.replaceable)), newMatches.length ? (this._moveToInitialMatch(findModels), this._state.changeState({ matchesCount: newMatches.length }), { results: newMatches }) : (this._state.changeState({ matchesCount: 0, matchesPosition: 0 }), { results: [] });
|
|
121
128
|
}
|
|
122
129
|
/** Terminate the current searching session, when searching string is empty. */
|
|
123
130
|
_stopSearching() {
|
|
124
|
-
var
|
|
125
|
-
this._providers.forEach((
|
|
131
|
+
var _a5;
|
|
132
|
+
this._providers.forEach((provider) => provider.terminate()), this._findModels = [], this._matches = [], this._matchingModel = null, (_a5 = this._currentSearchingDisposables) == null || _a5.dispose(), this._currentSearchingDisposables = null, this.currentMatch$.next(null), this.replaceables$.next([]), this._state.changeState({
|
|
126
133
|
findCompleted: !1,
|
|
127
134
|
matchesCount: 0,
|
|
128
135
|
matchesPosition: 0
|
|
129
136
|
});
|
|
130
137
|
}
|
|
131
138
|
// When a document's content changes, we should reset all matches and try to move to the next match.
|
|
132
|
-
_subscribeToModelsChanges(
|
|
133
|
-
const
|
|
134
|
-
const
|
|
135
|
-
|
|
139
|
+
_subscribeToModelsChanges(models) {
|
|
140
|
+
const disposables = this._currentSearchingDisposables = new DisposableCollection(), matchesUpdateSubscription = combineLatest(models.map((model) => model.matchesUpdate$)).pipe(debounceTime(220)).subscribe(([...allMatches]) => {
|
|
141
|
+
const newMatches = this._matches = allMatches.flat();
|
|
142
|
+
newMatches.length ? (this._moveToInitialMatch(this._findModels, !0), this._state.changeState({ matchesCount: newMatches.length }), this.replaceables$.next(newMatches.filter((m2) => m2.replaceable))) : (this._state.changeState({ matchesCount: 0, matchesPosition: 0 }), this.replaceables$.next([]));
|
|
136
143
|
});
|
|
137
|
-
|
|
138
|
-
const
|
|
139
|
-
this._state.changeState({ matchesPosition:
|
|
140
|
-
})))),
|
|
144
|
+
models.forEach((model) => disposables.add(toDisposable(model.activelyChangingMatch$.subscribe((match) => {
|
|
145
|
+
const index = this._matches.findIndex((m2) => m2 === match);
|
|
146
|
+
this._state.changeState({ matchesPosition: index + 1 });
|
|
147
|
+
})))), disposables.add(toDisposable(matchesUpdateSubscription));
|
|
141
148
|
}
|
|
142
149
|
async replace() {
|
|
143
150
|
return this._matchingModel ? this._matchingModel.replace(this._state.replaceString) : !1;
|
|
144
151
|
}
|
|
145
152
|
async replaceAll() {
|
|
146
|
-
const
|
|
147
|
-
return
|
|
153
|
+
const result = await Promise.all(this._findModels.map((m2) => m2.replaceAll(this._state.replaceString))).then((results) => results.reduce((acc, cur) => (acc.success += cur.success, acc.failure += cur.failure, acc), { success: 0, failure: 0 }));
|
|
154
|
+
return result.failure === 0 && this._stopSearching(), result;
|
|
148
155
|
}
|
|
149
156
|
getCurrentMatch() {
|
|
150
157
|
return this._state.matchesPosition > 0 ? this._matches[this._state.matchesPosition - 1] : null;
|
|
151
158
|
}
|
|
152
|
-
_markMatch(
|
|
153
|
-
const
|
|
154
|
-
this.currentMatch$.next(
|
|
159
|
+
_markMatch(match) {
|
|
160
|
+
const index = this._matches.findIndex((value) => value === match);
|
|
161
|
+
this.currentMatch$.next(match), this._state.changeState({ matchesPosition: index + 1 });
|
|
155
162
|
}
|
|
156
163
|
moveToNextMatch() {
|
|
157
164
|
if (!this._matchingModel)
|
|
158
165
|
return;
|
|
159
|
-
const
|
|
160
|
-
if (
|
|
161
|
-
this._markMatch(
|
|
166
|
+
const loopInCurrentUnit = this._findModels.length === 1, nextMatch = this._matchingModel.moveToNextMatch({ loop: loopInCurrentUnit });
|
|
167
|
+
if (nextMatch)
|
|
168
|
+
this._markMatch(nextMatch);
|
|
162
169
|
else {
|
|
163
|
-
const
|
|
164
|
-
this._moveToNextUnitMatch(
|
|
170
|
+
const currentModelIndex = this._findModels.findIndex((m2) => m2 === this._matchingModel);
|
|
171
|
+
this._moveToNextUnitMatch(currentModelIndex);
|
|
165
172
|
}
|
|
166
173
|
}
|
|
167
|
-
_moveToNextUnitMatch(
|
|
168
|
-
const
|
|
169
|
-
for (let i = (
|
|
170
|
-
const
|
|
171
|
-
if (
|
|
172
|
-
this._matchingModel =
|
|
174
|
+
_moveToNextUnitMatch(startingIndex) {
|
|
175
|
+
const l2 = this._findModels.length;
|
|
176
|
+
for (let i = (startingIndex + 1) % l2; i !== startingIndex; ) {
|
|
177
|
+
const nextPositionModel = this._findModels[i], nextMatch = nextPositionModel.moveToNextMatch({ ignoreSelection: !0 });
|
|
178
|
+
if (nextMatch) {
|
|
179
|
+
this._matchingModel = nextPositionModel, this._markMatch(nextMatch);
|
|
173
180
|
return;
|
|
174
181
|
}
|
|
175
|
-
i = (i + 1) %
|
|
182
|
+
i = (i + 1) % l2;
|
|
176
183
|
}
|
|
177
184
|
if (this._matchingModel) {
|
|
178
|
-
const
|
|
179
|
-
|
|
185
|
+
const nextMatch = this._matchingModel.moveToNextMatch({ ignoreSelection: !0 });
|
|
186
|
+
nextMatch && this._markMatch(nextMatch);
|
|
180
187
|
}
|
|
181
188
|
}
|
|
182
189
|
moveToPreviousMatch() {
|
|
183
190
|
if (!this._matchingModel)
|
|
184
191
|
return;
|
|
185
|
-
const
|
|
186
|
-
if (
|
|
187
|
-
const
|
|
188
|
-
this.currentMatch$.next(
|
|
192
|
+
const loopInCurrentUnit = this._findModels.length === 1, nextMatch = this._matchingModel.moveToPreviousMatch({ loop: loopInCurrentUnit });
|
|
193
|
+
if (nextMatch) {
|
|
194
|
+
const index = this._matches.findIndex((value) => value === nextMatch);
|
|
195
|
+
this.currentMatch$.next(nextMatch), this._state.changeState({ matchesPosition: index + 1 });
|
|
189
196
|
} else {
|
|
190
|
-
const
|
|
191
|
-
for (let
|
|
192
|
-
const
|
|
193
|
-
if (
|
|
194
|
-
this._matchingModel =
|
|
197
|
+
const l2 = this._findModels.length, currentModelIndex = this._findModels.findIndex((m2) => m2 === this._matchingModel);
|
|
198
|
+
for (let i = (currentModelIndex - 1 + l2) % l2; i !== currentModelIndex; ) {
|
|
199
|
+
const nextPositionModel = this._findModels[i], nextMatch3 = nextPositionModel.moveToPreviousMatch({ ignoreSelection: !0 });
|
|
200
|
+
if (nextMatch3) {
|
|
201
|
+
this._matchingModel = nextPositionModel, this._markMatch(nextMatch3);
|
|
195
202
|
return;
|
|
196
203
|
}
|
|
197
|
-
|
|
204
|
+
i = (i - 1) % l2;
|
|
198
205
|
}
|
|
199
|
-
const
|
|
200
|
-
|
|
206
|
+
const nextMatch2 = this._matchingModel.moveToPreviousMatch({ ignoreSelection: !0 });
|
|
207
|
+
nextMatch2 && this._markMatch(nextMatch2);
|
|
201
208
|
}
|
|
202
209
|
}
|
|
203
|
-
_moveToInitialMatch(
|
|
204
|
-
var
|
|
205
|
-
const
|
|
206
|
-
if (!
|
|
210
|
+
_moveToInitialMatch(findModels, noFocus = !1) {
|
|
211
|
+
var _a5;
|
|
212
|
+
const focusedUnitId = (_a5 = this._univerInstanceService.getFocusedUnit()) == null ? void 0 : _a5.getUnitId();
|
|
213
|
+
if (!focusedUnitId)
|
|
207
214
|
return -1;
|
|
208
|
-
const
|
|
209
|
-
if (
|
|
210
|
-
this._matchingModel =
|
|
211
|
-
const
|
|
212
|
-
if (
|
|
213
|
-
return this._markMatch(
|
|
215
|
+
const i = findModels.findIndex((model) => model.unitId === focusedUnitId);
|
|
216
|
+
if (i !== -1) {
|
|
217
|
+
this._matchingModel = findModels[i];
|
|
218
|
+
const nextMatch = this._matchingModel.moveToNextMatch({ stayIfOnMatch: !0, noFocus });
|
|
219
|
+
if (nextMatch)
|
|
220
|
+
return this._markMatch(nextMatch), i;
|
|
214
221
|
}
|
|
215
|
-
return this._moveToNextUnitMatch(
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
],
|
|
221
|
-
var
|
|
222
|
-
function
|
|
222
|
+
return this._moveToNextUnitMatch(i), 0;
|
|
223
|
+
}
|
|
224
|
+
}, __name(_a, "FindReplaceModel"), _a);
|
|
225
|
+
FindReplaceModel = __decorateClass$2([
|
|
226
|
+
__decorateParam$2(2, IUniverInstanceService)
|
|
227
|
+
], FindReplaceModel);
|
|
228
|
+
var FindDirection = /* @__PURE__ */ ((FindDirection2) => (FindDirection2.ROW = "row", FindDirection2.COLUMN = "column", FindDirection2))(FindDirection || {}), FindBy = /* @__PURE__ */ ((FindBy2) => (FindBy2.VALUE = "value", FindBy2.FORMULA = "formula", FindBy2))(FindBy || {}), FindScope = /* @__PURE__ */ ((FindScope2) => (FindScope2.SUBUNIT = "subunit", FindScope2.UNIT = "unit", FindScope2))(FindScope || {});
|
|
229
|
+
function createInitFindReplaceState() {
|
|
223
230
|
return {
|
|
224
231
|
caseSensitive: !1,
|
|
225
232
|
findBy: "value",
|
|
@@ -236,25 +243,26 @@ function re() {
|
|
|
236
243
|
revealed: !0
|
|
237
244
|
};
|
|
238
245
|
}
|
|
239
|
-
|
|
246
|
+
__name(createInitFindReplaceState, "createInitFindReplaceState");
|
|
247
|
+
const _FindReplaceState = class _FindReplaceState {
|
|
240
248
|
constructor() {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
249
|
+
__publicField(this, "_stateUpdates$", new Subject());
|
|
250
|
+
__publicField(this, "stateUpdates$", this._stateUpdates$.asObservable());
|
|
251
|
+
__publicField(this, "_state$", new BehaviorSubject(createInitFindReplaceState()));
|
|
252
|
+
__publicField(this, "state$", this._state$.asObservable());
|
|
253
|
+
__publicField(this, "_findString", "");
|
|
254
|
+
__publicField(this, "_inputtingFindString", "");
|
|
255
|
+
__publicField(this, "_replaceString", "");
|
|
256
|
+
__publicField(this, "_revealed", !1);
|
|
257
|
+
__publicField(this, "_replaceRevealed", !1);
|
|
258
|
+
__publicField(this, "_matchesPosition", 0);
|
|
259
|
+
__publicField(this, "_matchesCount", 0);
|
|
260
|
+
__publicField(this, "_caseSensitive", !0);
|
|
261
|
+
__publicField(this, "_matchesTheWholeCell", !1);
|
|
262
|
+
__publicField(this, "_findDirection", "row");
|
|
263
|
+
__publicField(this, "_findScope", "subunit");
|
|
264
|
+
__publicField(this, "_findBy", "value");
|
|
265
|
+
__publicField(this, "_findCompleted", !1);
|
|
258
266
|
}
|
|
259
267
|
get state() {
|
|
260
268
|
return this._state$.getValue();
|
|
@@ -299,10 +307,10 @@ class Gt {
|
|
|
299
307
|
return this._findCompleted;
|
|
300
308
|
}
|
|
301
309
|
// eslint-disable-next-line max-lines-per-function, complexity
|
|
302
|
-
changeState(
|
|
303
|
-
let
|
|
304
|
-
const
|
|
305
|
-
typeof
|
|
310
|
+
changeState(changes) {
|
|
311
|
+
let changed = !1;
|
|
312
|
+
const changedState = {};
|
|
313
|
+
typeof changes.findString < "u" && changes.findString !== this._findString && (this._findString = changes.findString, changedState.findString = this._findString, changed = !0), typeof changes.revealed < "u" && changes.revealed !== this._revealed && (this._revealed = changes.revealed, changedState.revealed = changes.revealed, changed = !0), typeof changes.replaceRevealed < "u" && changes.replaceRevealed !== this._replaceRevealed && (this._replaceRevealed = changes.replaceRevealed, changedState.replaceRevealed = changes.replaceRevealed, changed = !0), typeof changes.replaceString < "u" && changes.replaceString !== this._replaceString && (this._replaceString = changes.replaceString, changedState.replaceString = changes.replaceString, changed = !0), typeof changes.matchesCount < "u" && changes.matchesCount !== this._matchesCount && (this._matchesCount = changes.matchesCount, changedState.matchesCount = changes.matchesCount, changed = !0), typeof changes.matchesPosition < "u" && changes.matchesPosition !== this._matchesPosition && (this._matchesPosition = changes.matchesPosition, changedState.matchesPosition = changes.matchesPosition, changed = !0), typeof changes.findBy < "u" && changes.findBy !== this._findBy && (this._findBy = changes.findBy, changedState.findBy = changes.findBy, changed = !0), typeof changes.findScope < "u" && changes.findScope !== this._findScope && (this._findScope = changes.findScope, changedState.findScope = changes.findScope, changed = !0), typeof changes.findDirection < "u" && changes.findDirection !== this._findDirection && (this._findDirection = changes.findDirection, changedState.findDirection = changes.findDirection, changed = !0), typeof changes.caseSensitive < "u" && changes.caseSensitive !== this._caseSensitive && (this._caseSensitive = changes.caseSensitive, changedState.caseSensitive = changes.caseSensitive, changed = !0), typeof changes.matchesTheWholeCell < "u" && changes.matchesTheWholeCell !== this._matchesTheWholeCell && (this._matchesTheWholeCell = changes.matchesTheWholeCell, changedState.matchesTheWholeCell = changes.matchesTheWholeCell, changed = !0), typeof changes.inputtingFindString < "u" && changes.inputtingFindString !== this._inputtingFindString && (this._inputtingFindString = changes.inputtingFindString, changedState.inputtingFindString = changes.inputtingFindString, changed = !0), typeof changes.findCompleted < "u" && changes.findCompleted !== this._findCompleted && (this._findCompleted = changes.findCompleted, changedState.findCompleted = changes.findCompleted, changed = !0), changed && (this._state$.next({
|
|
306
314
|
caseSensitive: this._caseSensitive,
|
|
307
315
|
findBy: this._findBy,
|
|
308
316
|
findCompleted: this._findCompleted,
|
|
@@ -315,22 +323,25 @@ class Gt {
|
|
|
315
323
|
matchesTheWholeCell: this._matchesTheWholeCell,
|
|
316
324
|
replaceRevealed: this._replaceRevealed,
|
|
317
325
|
revealed: this._revealed
|
|
318
|
-
}), this._stateUpdates$.next(
|
|
326
|
+
}), this._stateUpdates$.next(changedState));
|
|
319
327
|
}
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
|
|
328
|
+
};
|
|
329
|
+
__name(_FindReplaceState, "FindReplaceState");
|
|
330
|
+
let FindReplaceState = _FindReplaceState;
|
|
331
|
+
var _a2;
|
|
332
|
+
let FindReplaceService = (_a2 = class extends Disposable {
|
|
333
|
+
constructor(_injector, _contextService) {
|
|
323
334
|
super();
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
this._injector =
|
|
335
|
+
__publicField(this, "_providers", /* @__PURE__ */ new Set());
|
|
336
|
+
__publicField(this, "_state", new FindReplaceState());
|
|
337
|
+
__publicField(this, "_model");
|
|
338
|
+
__publicField(this, "_currentMatch$", new BehaviorSubject(null));
|
|
339
|
+
__publicField(this, "currentMatch$", this._currentMatch$.asObservable());
|
|
340
|
+
__publicField(this, "_replaceables$", new BehaviorSubject([]));
|
|
341
|
+
__publicField(this, "replaceables$", this._replaceables$.asObservable());
|
|
342
|
+
__publicField(this, "_focusSignal$", new Subject());
|
|
343
|
+
__publicField(this, "focusSignal$", this._focusSignal$.asObservable());
|
|
344
|
+
this._injector = _injector, this._contextService = _contextService;
|
|
334
345
|
}
|
|
335
346
|
get stateUpdates$() {
|
|
336
347
|
return this._state.stateUpdates$;
|
|
@@ -348,41 +359,41 @@ let Q = class extends X {
|
|
|
348
359
|
super.dispose(), this._currentMatch$.next(null), this._currentMatch$.complete(), this._replaceables$.next([]), this._replaceables$.complete(), this._focusSignal$.complete();
|
|
349
360
|
}
|
|
350
361
|
getCurrentMatch() {
|
|
351
|
-
var
|
|
352
|
-
return (
|
|
362
|
+
var _a5;
|
|
363
|
+
return (_a5 = this._model) == null ? void 0 : _a5.getCurrentMatch();
|
|
353
364
|
}
|
|
354
365
|
getFindString() {
|
|
355
366
|
return this._state.findString;
|
|
356
367
|
}
|
|
357
|
-
changeFindString(
|
|
358
|
-
this._state.changeState({ findString
|
|
368
|
+
changeFindString(findString) {
|
|
369
|
+
this._state.changeState({ findString });
|
|
359
370
|
}
|
|
360
371
|
focusFindInput() {
|
|
361
372
|
this._focusSignal$.next();
|
|
362
373
|
}
|
|
363
|
-
changeInputtingFindString(
|
|
364
|
-
|
|
374
|
+
changeInputtingFindString(value) {
|
|
375
|
+
value ? this._state.changeState({ inputtingFindString: value }) : this._state.changeState({ inputtingFindString: "", findString: "" });
|
|
365
376
|
}
|
|
366
|
-
changeReplaceString(
|
|
367
|
-
this._state.changeState({ replaceString
|
|
377
|
+
changeReplaceString(replaceString) {
|
|
378
|
+
this._state.changeState({ replaceString });
|
|
368
379
|
}
|
|
369
|
-
changeMatchesTheWholeCell(
|
|
370
|
-
this._state.changeState({ matchesTheWholeCell
|
|
380
|
+
changeMatchesTheWholeCell(matchesTheWholeCell) {
|
|
381
|
+
this._state.changeState({ matchesTheWholeCell });
|
|
371
382
|
}
|
|
372
|
-
changeCaseSensitive(
|
|
373
|
-
this._state.changeState({ caseSensitive
|
|
383
|
+
changeCaseSensitive(caseSensitive) {
|
|
384
|
+
this._state.changeState({ caseSensitive });
|
|
374
385
|
}
|
|
375
|
-
changeFindBy(
|
|
376
|
-
this._state.changeState({ findBy
|
|
377
|
-
|
|
386
|
+
changeFindBy(findBy) {
|
|
387
|
+
this._state.changeState({ findBy }), this._toggleDisplayRawFormula(
|
|
388
|
+
findBy === "formula"
|
|
378
389
|
/* FORMULA */
|
|
379
390
|
);
|
|
380
391
|
}
|
|
381
|
-
changeFindScope(
|
|
382
|
-
this._state.changeState({ findScope:
|
|
392
|
+
changeFindScope(scope) {
|
|
393
|
+
this._state.changeState({ findScope: scope });
|
|
383
394
|
}
|
|
384
|
-
changeFindDirection(
|
|
385
|
-
this._state.changeState({ findDirection:
|
|
395
|
+
changeFindDirection(direction) {
|
|
396
|
+
this._state.changeState({ findDirection: direction });
|
|
386
397
|
}
|
|
387
398
|
moveToNextMatch() {
|
|
388
399
|
this._model && (this._state.replaceRevealed && !this._model.searched ? (this._state.changeState({ findString: this._state.inputtingFindString }), this._model.start()) : this._model.moveToNextMatch(), this._focusSignal$.next());
|
|
@@ -401,59 +412,59 @@ let Q = class extends X {
|
|
|
401
412
|
revealReplace() {
|
|
402
413
|
this._state.changeState({ replaceRevealed: !0, inputtingFindString: this._state.findString }), this._toggleRevealReplace(!0);
|
|
403
414
|
}
|
|
404
|
-
start(
|
|
415
|
+
start(revealReplace = !1) {
|
|
405
416
|
if (this._providers.size === 0)
|
|
406
417
|
return !1;
|
|
407
|
-
this._model = this._injector.createInstance(
|
|
408
|
-
const
|
|
409
|
-
return
|
|
418
|
+
this._model = this._injector.createInstance(FindReplaceModel, this._state, this._providers), this._model.currentMatch$.subscribe((match) => this._currentMatch$.next(match)), this._model.replaceables$.subscribe((replaceables) => this._replaceables$.next(replaceables));
|
|
419
|
+
const newState = createInitFindReplaceState();
|
|
420
|
+
return revealReplace && (newState.replaceRevealed = !0), this._state.changeState(newState), this._toggleRevealReplace(revealReplace), !0;
|
|
410
421
|
}
|
|
411
422
|
find() {
|
|
412
|
-
var
|
|
413
|
-
(
|
|
423
|
+
var _a5;
|
|
424
|
+
(_a5 = this._model) == null || _a5.start();
|
|
414
425
|
}
|
|
415
426
|
terminate() {
|
|
416
|
-
var
|
|
417
|
-
(
|
|
427
|
+
var _a5;
|
|
428
|
+
(_a5 = this._model) == null || _a5.dispose(), this._model = null, this._toggleDisplayRawFormula(!1), this._toggleRevealReplace(!1);
|
|
418
429
|
}
|
|
419
|
-
registerFindReplaceProvider(
|
|
420
|
-
return this._providers.add(
|
|
430
|
+
registerFindReplaceProvider(provider) {
|
|
431
|
+
return this._providers.add(provider), toDisposable(() => this._providers.delete(provider));
|
|
421
432
|
}
|
|
422
|
-
_toggleRevealReplace(
|
|
423
|
-
this._contextService.setContextValue(
|
|
433
|
+
_toggleRevealReplace(revealReplace) {
|
|
434
|
+
this._contextService.setContextValue(FIND_REPLACE_REPLACE_REVEALED, revealReplace);
|
|
424
435
|
}
|
|
425
|
-
_toggleDisplayRawFormula(
|
|
426
|
-
this._contextService.setContextValue(
|
|
436
|
+
_toggleDisplayRawFormula(force) {
|
|
437
|
+
this._contextService.setContextValue(RENDER_RAW_FORMULA_KEY, force);
|
|
427
438
|
}
|
|
428
|
-
};
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
],
|
|
433
|
-
const
|
|
439
|
+
}, __name(_a2, "FindReplaceService"), _a2);
|
|
440
|
+
FindReplaceService = __decorateClass$2([
|
|
441
|
+
__decorateParam$2(0, Inject(Injector)),
|
|
442
|
+
__decorateParam$2(1, IContextService)
|
|
443
|
+
], FindReplaceService);
|
|
444
|
+
const OpenFindDialogOperation = {
|
|
434
445
|
id: "ui.operation.open-find-dialog",
|
|
435
|
-
type:
|
|
436
|
-
handler: (
|
|
437
|
-
const
|
|
438
|
-
return
|
|
439
|
-
}
|
|
440
|
-
},
|
|
446
|
+
type: CommandType.OPERATION,
|
|
447
|
+
handler: /* @__PURE__ */ __name((accessor) => {
|
|
448
|
+
const findReplaceService = accessor.get(IFindReplaceService);
|
|
449
|
+
return findReplaceService.revealed ? findReplaceService.focusFindInput() : findReplaceService.start(), !0;
|
|
450
|
+
}, "handler")
|
|
451
|
+
}, OpenReplaceDialogOperation = {
|
|
441
452
|
id: "ui.operation.open-replace-dialog",
|
|
442
|
-
type:
|
|
443
|
-
handler: (
|
|
444
|
-
const
|
|
445
|
-
return
|
|
446
|
-
}
|
|
447
|
-
},
|
|
448
|
-
type:
|
|
453
|
+
type: CommandType.OPERATION,
|
|
454
|
+
handler: /* @__PURE__ */ __name((accessor) => {
|
|
455
|
+
const findReplaceService = accessor.get(IFindReplaceService);
|
|
456
|
+
return findReplaceService.revealed ? findReplaceService.replaceRevealed ? findReplaceService.focusFindInput() : findReplaceService.revealReplace() : findReplaceService.start(!0), !0;
|
|
457
|
+
}, "handler")
|
|
458
|
+
}, GoToNextMatchOperation = {
|
|
459
|
+
type: CommandType.OPERATION,
|
|
449
460
|
id: "ui.operation.go-to-next-match",
|
|
450
|
-
handler: (
|
|
451
|
-
},
|
|
452
|
-
type:
|
|
461
|
+
handler: /* @__PURE__ */ __name((accessor) => (accessor.get(IFindReplaceService).moveToNextMatch(), !0), "handler")
|
|
462
|
+
}, GoToPreviousMatchOperation = {
|
|
463
|
+
type: CommandType.OPERATION,
|
|
453
464
|
id: "ui.operation.go-to-previous-match",
|
|
454
|
-
handler: (
|
|
465
|
+
handler: /* @__PURE__ */ __name((accessor) => (accessor.get(IFindReplaceService).moveToPreviousMatch(), !0), "handler")
|
|
455
466
|
};
|
|
456
|
-
var
|
|
467
|
+
var jsxRuntime = { exports: {} }, reactJsxRuntime_production_min = {};
|
|
457
468
|
/**
|
|
458
469
|
* @license React
|
|
459
470
|
* react-jsx-runtime.production.min.js
|
|
@@ -463,448 +474,463 @@ var Te = { exports: {} }, B = {};
|
|
|
463
474
|
* This source code is licensed under the MIT license found in the
|
|
464
475
|
* LICENSE file in the root directory of this source tree.
|
|
465
476
|
*/
|
|
466
|
-
var
|
|
467
|
-
function
|
|
468
|
-
var
|
|
469
|
-
|
|
470
|
-
for (
|
|
471
|
-
if (
|
|
472
|
-
return { $$typeof:
|
|
477
|
+
var f = require$$0, k = Symbol.for("react.element"), l = Symbol.for("react.fragment"), m = Object.prototype.hasOwnProperty, n = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, p = { key: !0, ref: !0, __self: !0, __source: !0 };
|
|
478
|
+
function q(c, a, g) {
|
|
479
|
+
var b, d = {}, e = null, h = null;
|
|
480
|
+
g !== void 0 && (e = "" + g), a.key !== void 0 && (e = "" + a.key), a.ref !== void 0 && (h = a.ref);
|
|
481
|
+
for (b in a) m.call(a, b) && !p.hasOwnProperty(b) && (d[b] = a[b]);
|
|
482
|
+
if (c && c.defaultProps) for (b in a = c.defaultProps, a) d[b] === void 0 && (d[b] = a[b]);
|
|
483
|
+
return { $$typeof: k, type: c, key: e, ref: h, props: d, _owner: n.current };
|
|
473
484
|
}
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
485
|
+
__name(q, "q");
|
|
486
|
+
reactJsxRuntime_production_min.Fragment = l;
|
|
487
|
+
reactJsxRuntime_production_min.jsx = q;
|
|
488
|
+
reactJsxRuntime_production_min.jsxs = q;
|
|
489
|
+
jsxRuntime.exports = reactJsxRuntime_production_min;
|
|
490
|
+
var jsxRuntimeExports = jsxRuntime.exports;
|
|
491
|
+
const ReplaceCurrentMatchCommand = {
|
|
480
492
|
id: "ui.command.replace-current-match",
|
|
481
|
-
type:
|
|
482
|
-
handler: (
|
|
483
|
-
},
|
|
493
|
+
type: CommandType.COMMAND,
|
|
494
|
+
handler: /* @__PURE__ */ __name((accessor) => accessor.get(IFindReplaceService).replace(), "handler")
|
|
495
|
+
}, CONFIRM_REPLACE_ALL_ID = "CONFIRM_REPLACE_ALL", ReplaceAllMatchesCommand = {
|
|
484
496
|
id: "ui.command.replace-all-matches",
|
|
485
|
-
type:
|
|
486
|
-
handler: async (
|
|
487
|
-
const
|
|
488
|
-
if (!await
|
|
489
|
-
id:
|
|
490
|
-
title: { title:
|
|
491
|
-
cancelText:
|
|
492
|
-
confirmText:
|
|
497
|
+
type: CommandType.COMMAND,
|
|
498
|
+
handler: /* @__PURE__ */ __name(async (accessor) => {
|
|
499
|
+
const confirmService = accessor.get(IConfirmService), localeService = accessor.get(LocaleService), messageService = accessor.get(IMessageService);
|
|
500
|
+
if (!await confirmService.confirm({
|
|
501
|
+
id: CONFIRM_REPLACE_ALL_ID,
|
|
502
|
+
title: { title: localeService.t("find-replace.replace.confirm.title") },
|
|
503
|
+
cancelText: localeService.t("button.cancel"),
|
|
504
|
+
confirmText: localeService.t("button.confirm")
|
|
493
505
|
}))
|
|
494
506
|
return !1;
|
|
495
|
-
const
|
|
496
|
-
return
|
|
497
|
-
type:
|
|
498
|
-
content:
|
|
499
|
-
}) :
|
|
500
|
-
type:
|
|
501
|
-
content:
|
|
502
|
-
}), !1) : (
|
|
503
|
-
type:
|
|
504
|
-
content:
|
|
507
|
+
const result = await accessor.get(IFindReplaceService).replaceAll(), { success, failure } = result;
|
|
508
|
+
return failure > 0 ? (success === 0 ? messageService.show({
|
|
509
|
+
type: MessageType.Error,
|
|
510
|
+
content: localeService.t("find-replace.replace.all-failure")
|
|
511
|
+
}) : messageService.show({
|
|
512
|
+
type: MessageType.Warning,
|
|
513
|
+
content: localeService.t("find-replace.replace.partial-success", `${success}`, `${failure}`)
|
|
514
|
+
}), !1) : (messageService.show({
|
|
515
|
+
type: MessageType.Success,
|
|
516
|
+
content: localeService.t("find-replace.replace.all-success", `${success}`)
|
|
505
517
|
}), !0);
|
|
506
|
-
}
|
|
518
|
+
}, "handler")
|
|
507
519
|
};
|
|
508
|
-
function
|
|
509
|
-
const { findCompleted:
|
|
510
|
-
return /* @__PURE__ */
|
|
511
|
-
|
|
520
|
+
function SearchInput(props) {
|
|
521
|
+
const { findCompleted: findComplete, localeService, matchesCount, matchesPosition, findString, findReplaceService, onChange, ...rest } = props, text = findComplete && matchesCount === 0 ? localeService.t("find-replace.dialog.no-result") : matchesCount === 0 ? " " : void 0;
|
|
522
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
523
|
+
InputWithSlot,
|
|
512
524
|
{
|
|
513
525
|
autoFocus: !0,
|
|
514
|
-
placeholder:
|
|
515
|
-
slot: /* @__PURE__ */
|
|
516
|
-
|
|
526
|
+
placeholder: localeService.t("find-replace.dialog.find-placeholder"),
|
|
527
|
+
slot: /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
528
|
+
Pager,
|
|
517
529
|
{
|
|
518
530
|
loop: !0,
|
|
519
|
-
text
|
|
520
|
-
value:
|
|
521
|
-
total:
|
|
522
|
-
onChange: (
|
|
523
|
-
|
|
524
|
-
}
|
|
531
|
+
text,
|
|
532
|
+
value: matchesPosition,
|
|
533
|
+
total: matchesCount,
|
|
534
|
+
onChange: /* @__PURE__ */ __name((newIndex) => {
|
|
535
|
+
matchesPosition === matchesCount && newIndex === 1 ? findReplaceService.moveToNextMatch() : matchesPosition === 1 && newIndex === matchesCount || newIndex < matchesPosition ? findReplaceService.moveToPreviousMatch() : findReplaceService.moveToNextMatch();
|
|
536
|
+
}, "onChange")
|
|
525
537
|
}
|
|
526
538
|
),
|
|
527
|
-
value:
|
|
528
|
-
onChange: (
|
|
529
|
-
...
|
|
539
|
+
value: findString,
|
|
540
|
+
onChange: /* @__PURE__ */ __name((value) => onChange == null ? void 0 : onChange(value), "onChange"),
|
|
541
|
+
...rest
|
|
530
542
|
}
|
|
531
543
|
);
|
|
532
544
|
}
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
545
|
+
__name(SearchInput, "SearchInput");
|
|
546
|
+
const findReplaceDialogContainer = "univer-find-replace-dialog-container", findReplaceExpandContainer = "univer-find-replace-expand-container", buttonText = "univer-button-text", findReplaceButtonsGroup = "univer-find-replace-buttons-group", findReplaceButtonsGroupRight = "univer-find-replace-buttons-group-right", styles = {
|
|
547
|
+
findReplaceDialogContainer,
|
|
548
|
+
findReplaceExpandContainer,
|
|
549
|
+
buttonText,
|
|
550
|
+
findReplaceButtonsGroup,
|
|
551
|
+
findReplaceButtonsGroupRight
|
|
539
552
|
};
|
|
540
|
-
function
|
|
541
|
-
const
|
|
542
|
-
var
|
|
543
|
-
(
|
|
544
|
-
}, []),
|
|
545
|
-
const
|
|
546
|
-
return Array.from(
|
|
553
|
+
function useFindInputFocus(findReplaceService, ref) {
|
|
554
|
+
const focus = useCallback(() => {
|
|
555
|
+
var _a5;
|
|
556
|
+
(_a5 = document.querySelector(".univer-find-input input")) == null || _a5.focus();
|
|
557
|
+
}, []), selectHasFocus = useCallback(() => {
|
|
558
|
+
const allInputs = document.querySelectorAll(".univer-find-replace-dialog-container .univer-select-selection-search-input");
|
|
559
|
+
return Array.from(allInputs).some((input) => input === document.activeElement);
|
|
547
560
|
}, []);
|
|
548
|
-
return
|
|
549
|
-
const
|
|
550
|
-
return () =>
|
|
551
|
-
}, [
|
|
561
|
+
return useImperativeHandle(ref, () => ({ focus, selectHasFocus })), useEffect(() => {
|
|
562
|
+
const subscription = findReplaceService.focusSignal$.subscribe(() => focus());
|
|
563
|
+
return () => subscription.unsubscribe();
|
|
564
|
+
}, [findReplaceService, focus]), { focus, selectHasFocus };
|
|
552
565
|
}
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
566
|
+
__name(useFindInputFocus, "useFindInputFocus");
|
|
567
|
+
const FindDialog = forwardRef(/* @__PURE__ */ __name(function(_props, ref) {
|
|
568
|
+
const localeService = useDependency(LocaleService), findReplaceService = useDependency(IFindReplaceService), commandService = useDependency(ICommandService), state = useObservable(findReplaceService.state$, void 0, !0), { findCompleted, findString, matchesCount, matchesPosition } = state, revealReplace = useCallback(() => {
|
|
569
|
+
commandService.executeCommand(OpenReplaceDialogOperation.id);
|
|
570
|
+
}, [commandService]), onFindStringChange = useCallback((findString2) => findReplaceService.changeFindString(findString2), [findReplaceService]);
|
|
571
|
+
return useFindInputFocus(findReplaceService, ref), /* @__PURE__ */ jsxRuntimeExports.jsxs(Fragment, { children: [
|
|
572
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
573
|
+
SearchInput,
|
|
560
574
|
{
|
|
561
|
-
findCompleted
|
|
575
|
+
findCompleted,
|
|
562
576
|
className: "univer-find-input",
|
|
563
|
-
matchesCount
|
|
564
|
-
matchesPosition
|
|
565
|
-
findReplaceService
|
|
566
|
-
localeService
|
|
567
|
-
findString
|
|
568
|
-
onChange:
|
|
577
|
+
matchesCount,
|
|
578
|
+
matchesPosition,
|
|
579
|
+
findReplaceService,
|
|
580
|
+
localeService,
|
|
581
|
+
findString,
|
|
582
|
+
onChange: onFindStringChange
|
|
569
583
|
}
|
|
570
584
|
),
|
|
571
|
-
/* @__PURE__ */
|
|
585
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.findReplaceExpandContainer, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { type: "text", size: "small", onClick: revealReplace, children: localeService.t("find-replace.dialog.advanced-finding") }) })
|
|
572
586
|
] });
|
|
573
|
-
}),
|
|
574
|
-
const
|
|
575
|
-
matchesCount
|
|
576
|
-
matchesPosition
|
|
577
|
-
findString
|
|
578
|
-
inputtingFindString
|
|
579
|
-
replaceString
|
|
580
|
-
caseSensitive
|
|
581
|
-
matchesTheWholeCell
|
|
582
|
-
findDirection
|
|
583
|
-
findScope
|
|
584
|
-
findBy
|
|
585
|
-
findCompleted
|
|
586
|
-
} =
|
|
587
|
-
(
|
|
588
|
-
[
|
|
589
|
-
),
|
|
590
|
-
(
|
|
591
|
-
[
|
|
592
|
-
), { focus
|
|
593
|
-
|
|
594
|
-
}, [
|
|
595
|
-
await
|
|
596
|
-
}, [
|
|
597
|
-
|
|
598
|
-
}, [
|
|
599
|
-
|
|
600
|
-
}, [
|
|
601
|
-
|
|
602
|
-
}, [
|
|
603
|
-
return
|
|
604
|
-
const
|
|
605
|
-
let
|
|
606
|
-
return
|
|
607
|
-
content:
|
|
608
|
-
type:
|
|
587
|
+
}, "FindDialogImpl")), ReplaceDialog = forwardRef(/* @__PURE__ */ __name(function(_props, ref) {
|
|
588
|
+
const findReplaceService = useDependency(IFindReplaceService), localeService = useDependency(LocaleService), commandService = useDependency(ICommandService), messageService = useDependency(IMessageService), currentMatch = useObservable(findReplaceService.currentMatch$, void 0, !0), replaceables = useObservable(findReplaceService.replaceables$, void 0, !0), state = useObservable(findReplaceService.state$, void 0, !0), {
|
|
589
|
+
matchesCount,
|
|
590
|
+
matchesPosition,
|
|
591
|
+
findString,
|
|
592
|
+
inputtingFindString,
|
|
593
|
+
replaceString,
|
|
594
|
+
caseSensitive,
|
|
595
|
+
matchesTheWholeCell,
|
|
596
|
+
findDirection,
|
|
597
|
+
findScope,
|
|
598
|
+
findBy,
|
|
599
|
+
findCompleted
|
|
600
|
+
} = state, findDisabled = inputtingFindString.length === 0, replaceDisabled = matchesCount === 0 || !(currentMatch != null && currentMatch.replaceable), replaceAllDisabled = replaceables.length === 0, onFindStringChange = useCallback(
|
|
601
|
+
(newValue) => findReplaceService.changeInputtingFindString(newValue),
|
|
602
|
+
[findReplaceService]
|
|
603
|
+
), onReplaceStringChange = useCallback(
|
|
604
|
+
(replaceString2) => findReplaceService.changeReplaceString(replaceString2),
|
|
605
|
+
[findReplaceService]
|
|
606
|
+
), { focus } = useFindInputFocus(findReplaceService, ref), onClickFindButton = useCallback(() => {
|
|
607
|
+
findString === inputtingFindString ? findReplaceService.moveToNextMatch() : (findReplaceService.changeFindString(inputtingFindString), findReplaceService.find());
|
|
608
|
+
}, [findString, inputtingFindString, findReplaceService]), onClickReplaceButton = useCallback(() => commandService.executeCommand(ReplaceCurrentMatchCommand.id), [commandService]), onClickReplaceAllButton = useCallback(async () => {
|
|
609
|
+
await commandService.executeCommand(ReplaceAllMatchesCommand.id), focus();
|
|
610
|
+
}, [commandService]), onChangeFindDirection = useCallback((findDirection2) => {
|
|
611
|
+
findReplaceService.changeFindDirection(findDirection2);
|
|
612
|
+
}, [findReplaceService]), onChangeFindScope = useCallback((findScope2) => {
|
|
613
|
+
findReplaceService.changeFindScope(findScope2);
|
|
614
|
+
}, [findReplaceService]), onChangeFindBy = useCallback((findBy2) => {
|
|
615
|
+
findReplaceService.changeFindBy(findBy2);
|
|
616
|
+
}, [findReplaceService]), findScopeOptions = useFindScopeOptions(localeService), findDirectionOptions = useFindDirectionOptions(localeService), findByOptions = useFindByOptions(localeService);
|
|
617
|
+
return useEffect(() => {
|
|
618
|
+
const shouldDisplayNoMatchInfo = findCompleted && matchesCount === 0;
|
|
619
|
+
let messageDisposable = null;
|
|
620
|
+
return shouldDisplayNoMatchInfo && (messageDisposable = messageService.show({
|
|
621
|
+
content: localeService.t("find-replace.dialog.no-match"),
|
|
622
|
+
type: MessageType.Warning,
|
|
609
623
|
duration: 5e3
|
|
610
|
-
})), () =>
|
|
611
|
-
}, [
|
|
612
|
-
/* @__PURE__ */
|
|
613
|
-
|
|
624
|
+
})), () => messageDisposable == null ? void 0 : messageDisposable.dispose();
|
|
625
|
+
}, [findCompleted, matchesCount, messageService, localeService]), /* @__PURE__ */ jsxRuntimeExports.jsxs(Fragment, { children: [
|
|
626
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(FormLayout, { label: localeService.t("find-replace.dialog.find"), children: /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
627
|
+
SearchInput,
|
|
614
628
|
{
|
|
615
|
-
findCompleted
|
|
629
|
+
findCompleted,
|
|
616
630
|
className: "univer-find-input",
|
|
617
|
-
matchesCount
|
|
618
|
-
matchesPosition
|
|
619
|
-
findReplaceService
|
|
620
|
-
localeService
|
|
621
|
-
findString:
|
|
622
|
-
onChange:
|
|
631
|
+
matchesCount,
|
|
632
|
+
matchesPosition,
|
|
633
|
+
findReplaceService,
|
|
634
|
+
localeService,
|
|
635
|
+
findString: inputtingFindString,
|
|
636
|
+
onChange: onFindStringChange
|
|
623
637
|
}
|
|
624
638
|
) }),
|
|
625
|
-
/* @__PURE__ */
|
|
626
|
-
|
|
639
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(FormLayout, { label: localeService.t("find-replace.dialog.replace"), children: /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
640
|
+
Input,
|
|
627
641
|
{
|
|
628
|
-
placeholder:
|
|
629
|
-
value:
|
|
630
|
-
onChange: (
|
|
642
|
+
placeholder: localeService.t("find-replace.dialog.replace-placeholder"),
|
|
643
|
+
value: replaceString,
|
|
644
|
+
onChange: /* @__PURE__ */ __name((value) => onReplaceStringChange(value), "onChange")
|
|
631
645
|
}
|
|
632
646
|
) }),
|
|
633
|
-
/* @__PURE__ */
|
|
634
|
-
/* @__PURE__ */
|
|
635
|
-
/* @__PURE__ */
|
|
636
|
-
/* @__PURE__ */
|
|
647
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(FormLayout, { label: localeService.t("find-replace.dialog.find-direction.title"), children: /* @__PURE__ */ jsxRuntimeExports.jsx(Select, { value: findDirection, options: findDirectionOptions, onChange: onChangeFindDirection }) }),
|
|
648
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(FormDualColumnLayout, { children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Fragment, { children: [
|
|
649
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(FormLayout, { label: localeService.t("find-replace.dialog.find-scope.title"), children: /* @__PURE__ */ jsxRuntimeExports.jsx(Select, { value: findScope, options: findScopeOptions, onChange: onChangeFindScope }) }),
|
|
650
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(FormLayout, { label: localeService.t("find-replace.dialog.find-by.title"), children: /* @__PURE__ */ jsxRuntimeExports.jsx(Select, { value: findBy, options: findByOptions, onChange: onChangeFindBy }) })
|
|
637
651
|
] }) }),
|
|
638
|
-
/* @__PURE__ */
|
|
639
|
-
/* @__PURE__ */
|
|
640
|
-
|
|
652
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(FormDualColumnLayout, { children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Fragment, { children: [
|
|
653
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(FormLayout, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
654
|
+
Checkbox,
|
|
641
655
|
{
|
|
642
|
-
checked:
|
|
643
|
-
onChange: (
|
|
644
|
-
|
|
645
|
-
},
|
|
646
|
-
children:
|
|
656
|
+
checked: caseSensitive,
|
|
657
|
+
onChange: /* @__PURE__ */ __name((checked) => {
|
|
658
|
+
findReplaceService.changeCaseSensitive(checked);
|
|
659
|
+
}, "onChange"),
|
|
660
|
+
children: localeService.t("find-replace.dialog.case-sensitive")
|
|
647
661
|
}
|
|
648
662
|
) }),
|
|
649
|
-
/* @__PURE__ */
|
|
650
|
-
|
|
663
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(FormLayout, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
664
|
+
Checkbox,
|
|
651
665
|
{
|
|
652
|
-
checked:
|
|
653
|
-
onChange: (
|
|
654
|
-
|
|
655
|
-
},
|
|
656
|
-
children:
|
|
666
|
+
checked: matchesTheWholeCell,
|
|
667
|
+
onChange: /* @__PURE__ */ __name((checked) => {
|
|
668
|
+
findReplaceService.changeMatchesTheWholeCell(checked);
|
|
669
|
+
}, "onChange"),
|
|
670
|
+
children: localeService.t("find-replace.dialog.match-the-whole-cell")
|
|
657
671
|
}
|
|
658
672
|
) })
|
|
659
673
|
] }) }),
|
|
660
|
-
/* @__PURE__ */
|
|
661
|
-
/* @__PURE__ */
|
|
662
|
-
/* @__PURE__ */
|
|
663
|
-
/* @__PURE__ */
|
|
664
|
-
/* @__PURE__ */
|
|
674
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.findReplaceButtonsGroup, children: [
|
|
675
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Button, { type: "primary", onClick: onClickFindButton, disabled: findDisabled, children: localeService.t("find-replace.dialog.find") }),
|
|
676
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: styles.findReplaceButtonsGroupRight, children: [
|
|
677
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Button, { disabled: replaceDisabled, onClick: onClickReplaceButton, children: localeService.t("find-replace.dialog.replace") }),
|
|
678
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Button, { disabled: replaceAllDisabled, onClick: onClickReplaceAllButton, children: localeService.t("find-replace.dialog.replace-all") })
|
|
665
679
|
] })
|
|
666
680
|
] })
|
|
667
681
|
] });
|
|
668
|
-
});
|
|
669
|
-
function
|
|
670
|
-
const
|
|
671
|
-
|
|
672
|
-
let
|
|
673
|
-
return
|
|
674
|
-
}, [
|
|
675
|
-
const
|
|
676
|
-
(
|
|
677
|
-
[
|
|
678
|
-
),
|
|
679
|
-
(
|
|
680
|
-
[
|
|
682
|
+
}, "ReplaceDIalogImpl"));
|
|
683
|
+
function FindReplaceDialog() {
|
|
684
|
+
const findReplaceService = useDependency(IFindReplaceService), layoutService = useDependency(ILayoutService), contextService = useDependency(IContextService), state = useObservable(findReplaceService.state$, void 0, !0), dialogContainerRef = useRef(null);
|
|
685
|
+
useEffect(() => {
|
|
686
|
+
let disposable;
|
|
687
|
+
return dialogContainerRef.current && (disposable = layoutService.registerContainerElement(dialogContainerRef.current)), () => disposable == null ? void 0 : disposable.dispose();
|
|
688
|
+
}, [layoutService]);
|
|
689
|
+
const focusRef = useRef(null), setDialogContainerFocus = useCallback(
|
|
690
|
+
(focused) => contextService.setContextValue(FIND_REPLACE_DIALOG_FOCUS, focused),
|
|
691
|
+
[contextService]
|
|
692
|
+
), setDialogInputFocus = useCallback(
|
|
693
|
+
(focused) => contextService.setContextValue(FIND_REPLACE_INPUT_FOCUS, focused),
|
|
694
|
+
[contextService]
|
|
681
695
|
);
|
|
682
|
-
return
|
|
683
|
-
var
|
|
684
|
-
const
|
|
685
|
-
var
|
|
686
|
-
|
|
696
|
+
return useEffect(() => {
|
|
697
|
+
var _a5;
|
|
698
|
+
const focusSubscription = fromEvent(document, "focusin").subscribe((event) => {
|
|
699
|
+
var _a6;
|
|
700
|
+
event.target && ((_a6 = dialogContainerRef.current) != null && _a6.contains(event.target)) ? setDialogContainerFocus(!0) : setDialogContainerFocus(!1), !focusRef.current || !focusRef.current.selectHasFocus() ? setDialogInputFocus(!0) : setDialogInputFocus(!1);
|
|
687
701
|
});
|
|
688
|
-
return (
|
|
689
|
-
|
|
702
|
+
return (_a5 = focusRef.current) == null || _a5.focus(), setDialogContainerFocus(!0), setDialogInputFocus(!0), () => {
|
|
703
|
+
focusSubscription.unsubscribe(), setDialogContainerFocus(!1);
|
|
690
704
|
};
|
|
691
|
-
}, [
|
|
705
|
+
}, [setDialogContainerFocus, setDialogInputFocus]), /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.findReplaceDialogContainer, ref: dialogContainerRef, children: state.replaceRevealed ? /* @__PURE__ */ jsxRuntimeExports.jsx(ReplaceDialog, { ref: focusRef }) : /* @__PURE__ */ jsxRuntimeExports.jsx(FindDialog, { ref: focusRef }) });
|
|
692
706
|
}
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
{ label:
|
|
698
|
-
|
|
707
|
+
__name(FindReplaceDialog, "FindReplaceDialog");
|
|
708
|
+
function useFindScopeOptions(localeService) {
|
|
709
|
+
const locale = localeService.getCurrentLocale();
|
|
710
|
+
return useMemo(() => [
|
|
711
|
+
{ label: localeService.t("find-replace.dialog.find-scope.current-sheet"), value: FindScope.SUBUNIT },
|
|
712
|
+
{ label: localeService.t("find-replace.dialog.find-scope.workbook"), value: FindScope.UNIT }
|
|
713
|
+
], [locale]);
|
|
699
714
|
}
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
{ label:
|
|
705
|
-
|
|
715
|
+
__name(useFindScopeOptions, "useFindScopeOptions");
|
|
716
|
+
function useFindDirectionOptions(localeService) {
|
|
717
|
+
const locale = localeService.getCurrentLocale();
|
|
718
|
+
return useMemo(() => [
|
|
719
|
+
{ label: localeService.t("find-replace.dialog.find-direction.row"), value: FindDirection.ROW },
|
|
720
|
+
{ label: localeService.t("find-replace.dialog.find-direction.column"), value: FindDirection.COLUMN }
|
|
721
|
+
], [locale]);
|
|
706
722
|
}
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
{ label:
|
|
712
|
-
|
|
723
|
+
__name(useFindDirectionOptions, "useFindDirectionOptions");
|
|
724
|
+
function useFindByOptions(localeService) {
|
|
725
|
+
const locale = localeService.getCurrentLocale();
|
|
726
|
+
return useMemo(() => [
|
|
727
|
+
{ label: localeService.t("find-replace.dialog.find-by.value"), value: FindBy.VALUE },
|
|
728
|
+
{ label: localeService.t("find-replace.dialog.find-by.formula"), value: FindBy.FORMULA }
|
|
729
|
+
], [locale]);
|
|
713
730
|
}
|
|
714
|
-
|
|
715
|
-
|
|
731
|
+
__name(useFindByOptions, "useFindByOptions");
|
|
732
|
+
function whenFindReplaceDialogFocused(contextService) {
|
|
733
|
+
return contextService.getContextValue(FIND_REPLACE_DIALOG_FOCUS);
|
|
716
734
|
}
|
|
717
|
-
|
|
718
|
-
|
|
735
|
+
__name(whenFindReplaceDialogFocused, "whenFindReplaceDialogFocused");
|
|
736
|
+
function whenReplaceRevealed(contextService) {
|
|
737
|
+
return contextService.getContextValue(FIND_REPLACE_REPLACE_REVEALED);
|
|
719
738
|
}
|
|
720
|
-
|
|
721
|
-
|
|
739
|
+
__name(whenReplaceRevealed, "whenReplaceRevealed");
|
|
740
|
+
function whenFindReplaceInputFocused(contextService) {
|
|
741
|
+
return contextService.getContextValue(FIND_REPLACE_INPUT_FOCUS);
|
|
722
742
|
}
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
743
|
+
__name(whenFindReplaceInputFocused, "whenFindReplaceInputFocused");
|
|
744
|
+
const FIND_REPLACE_SHORTCUT_GROUP = "7_find-replace-shortcuts";
|
|
745
|
+
function whenSheetFocused(contextService) {
|
|
746
|
+
return contextService.getContextValue(FOCUSING_SHEET);
|
|
726
747
|
}
|
|
727
|
-
|
|
728
|
-
|
|
748
|
+
__name(whenSheetFocused, "whenSheetFocused");
|
|
749
|
+
function whenEditorNotActivated(contextService) {
|
|
750
|
+
return !contextService.getContextValue(EDITOR_ACTIVATED);
|
|
729
751
|
}
|
|
730
|
-
|
|
731
|
-
|
|
752
|
+
__name(whenEditorNotActivated, "whenEditorNotActivated");
|
|
753
|
+
const OpenFindDialogShortcutItem = {
|
|
754
|
+
id: OpenFindDialogOperation.id,
|
|
732
755
|
description: "find-replace.shortcut.open-find-dialog",
|
|
733
|
-
binding:
|
|
734
|
-
group:
|
|
735
|
-
preconditions(
|
|
736
|
-
return !
|
|
756
|
+
binding: KeyCode.F | MetaKeys.CTRL_COMMAND,
|
|
757
|
+
group: FIND_REPLACE_SHORTCUT_GROUP,
|
|
758
|
+
preconditions(contextService) {
|
|
759
|
+
return !whenFindReplaceDialogFocused(contextService) && whenSheetFocused(contextService) && whenEditorNotActivated(contextService);
|
|
737
760
|
}
|
|
738
|
-
},
|
|
739
|
-
id:
|
|
761
|
+
}, MacOpenFindDialogShortcutItem = {
|
|
762
|
+
id: OpenFindDialogOperation.id,
|
|
740
763
|
description: "find-replace.shortcut.open-find-dialog",
|
|
741
|
-
binding:
|
|
742
|
-
mac:
|
|
743
|
-
preconditions(
|
|
744
|
-
return !
|
|
764
|
+
binding: KeyCode.F | MetaKeys.CTRL_COMMAND,
|
|
765
|
+
mac: KeyCode.F | MetaKeys.MAC_CTRL,
|
|
766
|
+
preconditions(contextService) {
|
|
767
|
+
return !whenFindReplaceDialogFocused(contextService) && whenSheetFocused(contextService) && whenEditorNotActivated(contextService);
|
|
745
768
|
}
|
|
746
|
-
},
|
|
747
|
-
id:
|
|
769
|
+
}, OpenReplaceDialogShortcutItem = {
|
|
770
|
+
id: OpenReplaceDialogOperation.id,
|
|
748
771
|
description: "find-replace.shortcut.open-replace-dialog",
|
|
749
|
-
binding:
|
|
750
|
-
mac:
|
|
751
|
-
group:
|
|
752
|
-
preconditions(
|
|
753
|
-
return
|
|
754
|
-
}
|
|
755
|
-
},
|
|
756
|
-
id:
|
|
772
|
+
binding: KeyCode.H | MetaKeys.CTRL_COMMAND,
|
|
773
|
+
mac: KeyCode.H | MetaKeys.MAC_CTRL,
|
|
774
|
+
group: FIND_REPLACE_SHORTCUT_GROUP,
|
|
775
|
+
preconditions(contextService) {
|
|
776
|
+
return whenSheetFocused(contextService) && whenEditorNotActivated(contextService) && (!whenFindReplaceDialogFocused(contextService) || !whenReplaceRevealed(contextService));
|
|
777
|
+
}
|
|
778
|
+
}, GoToNextFindMatchShortcutItem = {
|
|
779
|
+
id: GoToNextMatchOperation.id,
|
|
757
780
|
description: "find-replace.shortcut.go-to-next-match",
|
|
758
|
-
binding:
|
|
759
|
-
group:
|
|
781
|
+
binding: KeyCode.ENTER,
|
|
782
|
+
group: FIND_REPLACE_SHORTCUT_GROUP,
|
|
760
783
|
priority: 1e3,
|
|
761
|
-
preconditions(
|
|
762
|
-
return
|
|
784
|
+
preconditions(contextService) {
|
|
785
|
+
return whenFindReplaceInputFocused(contextService) && whenFindReplaceDialogFocused(contextService);
|
|
763
786
|
}
|
|
764
|
-
},
|
|
765
|
-
id:
|
|
787
|
+
}, GoToPreviousFindMatchShortcutItem = {
|
|
788
|
+
id: GoToPreviousMatchOperation.id,
|
|
766
789
|
description: "find-replace.shortcut.go-to-previous-match",
|
|
767
|
-
binding:
|
|
768
|
-
group:
|
|
790
|
+
binding: KeyCode.ENTER | MetaKeys.SHIFT,
|
|
791
|
+
group: FIND_REPLACE_SHORTCUT_GROUP,
|
|
769
792
|
priority: 1e3,
|
|
770
|
-
preconditions(
|
|
771
|
-
return
|
|
793
|
+
preconditions(contextService) {
|
|
794
|
+
return whenFindReplaceInputFocused(contextService) && whenFindReplaceDialogFocused(contextService);
|
|
772
795
|
}
|
|
773
796
|
};
|
|
774
|
-
function
|
|
775
|
-
const
|
|
797
|
+
function FindReplaceMenuItemFactory(accessor) {
|
|
798
|
+
const contextService = accessor.get(IContextService);
|
|
776
799
|
return {
|
|
777
|
-
id:
|
|
800
|
+
id: OpenFindDialogOperation.id,
|
|
778
801
|
icon: "SearchIcon",
|
|
779
802
|
tooltip: "find-replace.toolbar",
|
|
780
|
-
group:
|
|
781
|
-
type:
|
|
782
|
-
positions: [
|
|
783
|
-
hidden$:
|
|
784
|
-
disabled$:
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
]).pipe(
|
|
803
|
+
group: MenuGroup.TOOLBAR_OTHERS,
|
|
804
|
+
type: MenuItemType.BUTTON,
|
|
805
|
+
positions: [MenuPosition.TOOLBAR_START],
|
|
806
|
+
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
|
|
807
|
+
disabled$: combineLatest([
|
|
808
|
+
contextService.subscribeContextValue$(EDITOR_ACTIVATED),
|
|
809
|
+
contextService.subscribeContextValue$(FOCUSING_SHEET)
|
|
810
|
+
]).pipe(map(([editorActivated, focusingSheet]) => editorActivated || !focusingSheet))
|
|
788
811
|
};
|
|
789
812
|
}
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
813
|
+
__name(FindReplaceMenuItemFactory, "FindReplaceMenuItemFactory");
|
|
814
|
+
var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
815
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
816
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
817
|
+
return kind && result && __defProp$1(target, key, result), result;
|
|
818
|
+
}, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1");
|
|
819
|
+
const DefaultFindReplaceConfig = {}, FIND_REPLACE_DIALOG_ID = "DESKTOP_FIND_REPLACE_DIALOG", FIND_REPLACE_PANEL_WIDTH = 350, FIND_REPLACE_PANEL_RIGHT_PADDING = 20, FIND_REPLACE_PANEL_TOP_PADDING = -90;
|
|
820
|
+
var _a3;
|
|
821
|
+
let FindReplaceController = (_a3 = class extends RxDisposable {
|
|
822
|
+
constructor(_config, _univerInstanceService, _menuService, _shortcutService, _commandService, _findReplaceService, _dialogService, _layoutService, _localeService, _componentManager, _injector) {
|
|
823
|
+
super(), this._config = _config, this._univerInstanceService = _univerInstanceService, this._menuService = _menuService, this._shortcutService = _shortcutService, this._commandService = _commandService, this._findReplaceService = _findReplaceService, this._dialogService = _dialogService, this._layoutService = _layoutService, this._localeService = _localeService, this._componentManager = _componentManager, this._injector = _injector, this._initCommands(), this._initUI(), this._initShortcuts();
|
|
799
824
|
}
|
|
800
825
|
_initCommands() {
|
|
801
826
|
[
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
].forEach((
|
|
809
|
-
this.disposeWithMe(this._commandService.registerCommand(
|
|
827
|
+
OpenFindDialogOperation,
|
|
828
|
+
OpenReplaceDialogOperation,
|
|
829
|
+
GoToNextMatchOperation,
|
|
830
|
+
GoToPreviousMatchOperation,
|
|
831
|
+
ReplaceAllMatchesCommand,
|
|
832
|
+
ReplaceCurrentMatchCommand
|
|
833
|
+
].forEach((c) => {
|
|
834
|
+
this.disposeWithMe(this._commandService.registerCommand(c));
|
|
810
835
|
});
|
|
811
836
|
}
|
|
812
837
|
_initShortcuts() {
|
|
813
838
|
[
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
].forEach((
|
|
839
|
+
OpenReplaceDialogShortcutItem,
|
|
840
|
+
OpenFindDialogShortcutItem,
|
|
841
|
+
MacOpenFindDialogShortcutItem,
|
|
842
|
+
GoToPreviousFindMatchShortcutItem,
|
|
843
|
+
GoToNextFindMatchShortcutItem
|
|
844
|
+
].forEach((s) => this.disposeWithMe(this._shortcutService.registerShortcut(s)));
|
|
820
845
|
}
|
|
821
846
|
_initUI() {
|
|
822
|
-
const { menu
|
|
823
|
-
this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(
|
|
824
|
-
|
|
847
|
+
const { menu = {} } = this._config;
|
|
848
|
+
this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(FindReplaceMenuItemFactory), menu)), this.disposeWithMe(this._componentManager.register("FindReplaceDialog", FindReplaceDialog)), this.disposeWithMe(this._componentManager.register("SearchIcon", SearchSingle16)), this._findReplaceService.stateUpdates$.pipe(takeUntil(this.dispose$)).subscribe((newState) => {
|
|
849
|
+
newState.revealed === !0 && this._openPanel();
|
|
825
850
|
}), this.disposeWithMe(
|
|
826
|
-
this._univerInstanceService.focused$.pipe(
|
|
827
|
-
(!
|
|
851
|
+
this._univerInstanceService.focused$.pipe(takeUntil(this.dispose$)).subscribe((focused) => {
|
|
852
|
+
(!focused || !this._univerInstanceService.getUniverSheetInstance(focused)) && this.closePanel();
|
|
828
853
|
})
|
|
829
854
|
);
|
|
830
855
|
}
|
|
831
856
|
_openPanel() {
|
|
832
857
|
this._dialogService.open({
|
|
833
|
-
id:
|
|
858
|
+
id: FIND_REPLACE_DIALOG_ID,
|
|
834
859
|
draggable: !0,
|
|
835
|
-
width:
|
|
860
|
+
width: FIND_REPLACE_PANEL_WIDTH,
|
|
836
861
|
title: { title: this._localeService.t("find-replace.dialog.title") },
|
|
837
862
|
children: { label: "FindReplaceDialog" },
|
|
838
863
|
destroyOnClose: !0,
|
|
839
|
-
defaultPosition:
|
|
864
|
+
defaultPosition: getFindReplaceDialogDefaultPosition(),
|
|
840
865
|
preservePositionOnDestroy: !0,
|
|
841
|
-
onClose: () => this.closePanel()
|
|
866
|
+
onClose: /* @__PURE__ */ __name(() => this.closePanel(), "onClose")
|
|
842
867
|
});
|
|
843
868
|
}
|
|
844
869
|
closePanel() {
|
|
845
|
-
this._dialogService.close(
|
|
846
|
-
}
|
|
847
|
-
};
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
],
|
|
861
|
-
function
|
|
862
|
-
const { innerWidth
|
|
863
|
-
return { x: (
|
|
870
|
+
this._dialogService.close(FIND_REPLACE_DIALOG_ID), this._findReplaceService.terminate(), queueMicrotask(() => this._layoutService.focus());
|
|
871
|
+
}
|
|
872
|
+
}, __name(_a3, "FindReplaceController"), _a3);
|
|
873
|
+
FindReplaceController = __decorateClass$1([
|
|
874
|
+
OnLifecycle(LifecycleStages.Rendered, FindReplaceController),
|
|
875
|
+
__decorateParam$1(1, IUniverInstanceService),
|
|
876
|
+
__decorateParam$1(2, IMenuService),
|
|
877
|
+
__decorateParam$1(3, IShortcutService),
|
|
878
|
+
__decorateParam$1(4, ICommandService),
|
|
879
|
+
__decorateParam$1(5, IFindReplaceService),
|
|
880
|
+
__decorateParam$1(6, IDialogService),
|
|
881
|
+
__decorateParam$1(7, ILayoutService),
|
|
882
|
+
__decorateParam$1(8, Inject(LocaleService)),
|
|
883
|
+
__decorateParam$1(9, Inject(ComponentManager)),
|
|
884
|
+
__decorateParam$1(10, Inject(Injector))
|
|
885
|
+
], FindReplaceController);
|
|
886
|
+
function getFindReplaceDialogDefaultPosition() {
|
|
887
|
+
const { innerWidth } = window;
|
|
888
|
+
return { x: (innerWidth - FIND_REPLACE_PANEL_WIDTH) / 2 - FIND_REPLACE_PANEL_RIGHT_PADDING, y: FIND_REPLACE_PANEL_TOP_PADDING };
|
|
864
889
|
}
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
890
|
+
__name(getFindReplaceDialogDefaultPosition, "getFindReplaceDialogDefaultPosition");
|
|
891
|
+
var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
892
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
893
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
894
|
+
return kind && result && __defProp2(target, key, result), result;
|
|
895
|
+
}, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam");
|
|
896
|
+
const PLUGIN_NAME = "FIND_REPLACE_PLUGIN";
|
|
897
|
+
var _a4;
|
|
898
|
+
let UniverFindReplacePlugin = (_a4 = class extends Plugin {
|
|
899
|
+
constructor(_config = {}, _injector, _localeService) {
|
|
900
|
+
super(), this._config = _config, this._injector = _injector, this._localeService = _localeService, this._config = Tools.deepMerge({}, DefaultFindReplaceConfig, this._config);
|
|
901
|
+
}
|
|
902
|
+
onStarting() {
|
|
877
903
|
[
|
|
878
904
|
[
|
|
879
|
-
|
|
905
|
+
FindReplaceController,
|
|
880
906
|
{
|
|
881
|
-
useFactory: () => this._injector.createInstance(
|
|
907
|
+
useFactory: /* @__PURE__ */ __name(() => this._injector.createInstance(FindReplaceController, this._config), "useFactory")
|
|
882
908
|
}
|
|
883
909
|
],
|
|
884
|
-
[
|
|
910
|
+
[IFindReplaceService, { useClass: FindReplaceService }]
|
|
885
911
|
].forEach(
|
|
886
|
-
(
|
|
887
|
-
|
|
912
|
+
(d) => {
|
|
913
|
+
this._injector.add(d);
|
|
888
914
|
}
|
|
889
915
|
);
|
|
890
916
|
}
|
|
891
|
-
},
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
],
|
|
917
|
+
}, __name(_a4, "UniverFindReplacePlugin"), __publicField(_a4, "pluginName", PLUGIN_NAME), _a4);
|
|
918
|
+
UniverFindReplacePlugin = __decorateClass([
|
|
919
|
+
__decorateParam(1, Inject(Injector)),
|
|
920
|
+
__decorateParam(2, Inject(LocaleService))
|
|
921
|
+
], UniverFindReplacePlugin);
|
|
896
922
|
export {
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
923
|
+
FindBy,
|
|
924
|
+
FindDirection,
|
|
925
|
+
FindModel,
|
|
926
|
+
FindReplaceController,
|
|
927
|
+
FindScope,
|
|
928
|
+
GoToNextMatchOperation,
|
|
929
|
+
GoToPreviousMatchOperation,
|
|
930
|
+
IFindReplaceService,
|
|
931
|
+
OpenFindDialogOperation,
|
|
932
|
+
OpenReplaceDialogOperation,
|
|
933
|
+
ReplaceAllMatchesCommand,
|
|
934
|
+
ReplaceCurrentMatchCommand,
|
|
935
|
+
UniverFindReplacePlugin
|
|
910
936
|
};
|